kortique commited on
Commit
c417d52
·
1 Parent(s): e100caa

add node-script

Browse files
docs/advanced-development/node-script.mdx CHANGED
@@ -1,7 +1,89 @@
1
- ---
2
- sidebar_position: 4
3
- ---
4
 
5
- # Node's script
6
 
7
- Will be soon here...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Node-Script
 
 
2
 
3
+ The **Script tab** is designed for placing JavaScript code that handles the programmatic logic of your node. This is where you define what your node actually does - whether it's processing text, calling APIs, transforming data, or performing calculations.
4
 
5
+ ![Script tab interface](../img/script_tab.jpg)
6
+
7
+ ## Code Structure
8
+
9
+ All Piper nodes follow a specific JavaScript structure:
10
+
11
+ ```javascript
12
+ export async function run({ inputs }) {
13
+ const { FatalError, NextNode } = DEFINITIONS;
14
+
15
+ // Your custom code here
16
+
17
+ return NextNode.from({
18
+ outputs: {
19
+ // Your results
20
+ }
21
+ });
22
+ }
23
+ ```
24
+
25
+ This structure ensures your node can properly receive data from previous nodes and pass results to the next ones in your pipeline.
26
+
27
+ ## Execution Types
28
+
29
+ Choose the appropriate execution type based on how long your node needs to run:
30
+
31
+
32
+ | Type | Timeout | Description |
33
+ |------------|-------------|---------------------|
34
+ | Rapid | 0-20 sec | Quick operations |
35
+ | Regular | 21-60 sec | Standard processing |
36
+ | Deferred | 60-120 sec | Complex operations |
37
+ | Protracted | 120-300 sec | Heavy processing tasks |
38
+
39
+
40
+ ## Saving Changes
41
+
42
+ Always save your script modifications by clicking the **Save** button at the bottom of the interface. Any changes you make to the code must be saved before they take effect.
43
+
44
+ The Script tab is the core of your node's functionality - it's where you transform inputs into outputs using JavaScript code.
45
+
46
+ --- ru ---
47
+
48
+ # Node-Script
49
+
50
+ Вкладка **Script** предназначена для размещения кода JavaScript, отвечающего за программную логику ноды. Здесь вы определяете, что именно делает ваша нода - обрабатывает ли она текст, вызывает API, трансформирует данные или выполняет вычисления.
51
+
52
+ ![Интерфейс вкладки Script](../img/script_tab.jpg)
53
+
54
+ ## Структура кода
55
+
56
+ Все ноды Piper следуют определенной структуре JavaScript:
57
+
58
+ ```javascript
59
+ export async function run({ inputs }) {
60
+ const { FatalError, NextNode } = DEFINITIONS;
61
+
62
+ // Ваш код здесь
63
+
64
+ return NextNode.from({
65
+ outputs: {
66
+ // Ваши результаты
67
+ }
68
+ });
69
+ }
70
+ ```
71
+
72
+ Эта структура гарантирует, что ваша нода может правильно получать данные от предыдущих нод и передавать результаты следующим в вашем пайплайне.
73
+
74
+ ## Типы выполнения
75
+
76
+ Выберите подходящий тип выполнения в зависимости от того, сколько времени требуется вашей ноде для работы:
77
+
78
+ | Тип | Время | Описание |
79
+ |------------|-------------|-----------------------|
80
+ | Rapid | 0-20 sec | Быстрые операции |
81
+ | Regular | 21-60 sec | Стандартная обработка |
82
+ | Deferred | 60-120 sec | Сложные операции |
83
+ | Protracted | 120-300 sec | Тяжелые задачи обработки |
84
+
85
+ ## Сохранение изменений
86
+
87
+ Всегда сохраняйте изменения в скрипте, нажимая кнопку **Save** внизу интерфейса. Любые изменения в коде следует сохранять по нажатию клавиши Save внизу интерфейса.
88
+
89
+ Вкладка Script - это ядро функциональности вашей ноды, где вы преобразуете входные данные в выходные с помощью кода JavaScript.