@unstable-dev/unmeshed-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/dist/auth.d.ts +6 -0
- package/dist/auth.js +11 -0
- package/dist/client.d.ts +46 -0
- package/dist/client.js +97 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.js +31 -0
- package/dist/get-docs.d.ts +8 -0
- package/dist/get-docs.js +64 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +35 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +203 -0
- package/knowledge/README.md +16 -0
- package/knowledge/SKILL.md +359 -0
- package/knowledge/assets/patterns.md +637 -0
- package/knowledge/execution/debugging-guide.md +18 -0
- package/knowledge/execution/process-run.schema.md +24 -0
- package/knowledge/execution/step-run.schema.md +21 -0
- package/knowledge/process-definition.schema.md +36 -0
- package/knowledge/references/integrations.md +914 -0
- package/knowledge/references/steps-knowledge.md +834 -0
- package/knowledge/step-definition.schema.md +140 -0
- package/knowledge/step-output-paths.md +45 -0
- package/knowledge/steps/DECISION_ENGINE.md +248 -0
- package/knowledge/steps/DEPENDSON.md +296 -0
- package/knowledge/steps/EXIT.md +220 -0
- package/knowledge/steps/FAIL.md +198 -0
- package/knowledge/steps/FLOW_GATEWAY.md +405 -0
- package/knowledge/steps/FOREACH.md +250 -0
- package/knowledge/steps/HTTP.md +183 -0
- package/knowledge/steps/JAVASCRIPT.md +192 -0
- package/knowledge/steps/JQ.md +189 -0
- package/knowledge/steps/LIST.md +279 -0
- package/knowledge/steps/NOOP.md +165 -0
- package/knowledge/steps/PARALLEL.md +366 -0
- package/knowledge/steps/PYTHON.md +206 -0
- package/knowledge/steps/SEND_RESPONSE.md +301 -0
- package/knowledge/steps/SQLITE.md +301 -0
- package/knowledge/steps/SUB_PROCESS.md +296 -0
- package/knowledge/steps/SWITCH.md +369 -0
- package/knowledge/steps/UPDATE_STEP.md +257 -0
- package/knowledge/steps/WAIT.md +218 -0
- package/knowledge/steps/WHILE.md +328 -0
- package/knowledge/steps/WORKER.md +233 -0
- package/knowledge/system-prompt.md +274 -0
- package/package.json +39 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# ForEach Step Schema
|
|
2
|
+
|
|
3
|
+
`FOREACH` is a container step that iterates over an array and runs its child
|
|
4
|
+
steps for each item. Use it when the workflow needs to perform the same work for
|
|
5
|
+
each element in a list.
|
|
6
|
+
|
|
7
|
+
Each iteration exposes loop variables for child step inputs:
|
|
8
|
+
- `{{foreach.index }}`: zero-based iteration index.
|
|
9
|
+
- `{{foreach.value }}`: current item value.
|
|
10
|
+
|
|
11
|
+
## Definition Input Schema
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"inputArray": [1, 2, 3],
|
|
16
|
+
"concurrency": 1
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Required/observed:
|
|
21
|
+
- `inputArray`: array of items to iterate over.
|
|
22
|
+
- `concurrency`: number of iterations that may run concurrently.
|
|
23
|
+
|
|
24
|
+
The children array of a FOREACH step accepts exactly one direct child step.
|
|
25
|
+
If multiple operations are required for each iteration, wrap them inside a single child LIST step.
|
|
26
|
+
Defining more than one direct child under FOREACH.children is invalid. For Complex Logic Always use `SUB_PROCESS`
|
|
27
|
+
as a Child.
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"type": "FOREACH",
|
|
32
|
+
"ref": "foreach_1",
|
|
33
|
+
"children": [
|
|
34
|
+
{
|
|
35
|
+
"type": "HTTP",
|
|
36
|
+
"ref": "http_1"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"input": {
|
|
40
|
+
"inputArray": [1, 2, 3],
|
|
41
|
+
"concurrency": 1
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Runtime Output Schema
|
|
47
|
+
|
|
48
|
+
The FOREACH container's own step output is usually an empty object:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Each child step produces output for each iteration under an indexed ref. For a
|
|
55
|
+
child HTTP step with ref `http_1`, outputs are accessed like:
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
steps["http_1[0]"].output
|
|
59
|
+
steps["http_1[1]"].output
|
|
60
|
+
steps["http_1[2]"].output
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Native HTTP child output keeps the HTTP output shape per iteration:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"response": {
|
|
68
|
+
"counter": 1,
|
|
69
|
+
"randomId": "..."
|
|
70
|
+
},
|
|
71
|
+
"statusCode": 200
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Output Access Paths
|
|
76
|
+
|
|
77
|
+
Use inside child input templates:
|
|
78
|
+
- `{{foreach.index }}` for the current zero-based index.
|
|
79
|
+
- `{{foreach.value }}` for the current item value.
|
|
80
|
+
|
|
81
|
+
Use after FOREACH completes:
|
|
82
|
+
- `steps["<child_ref>[0]"].output` for the first iteration child output.
|
|
83
|
+
- `steps["<child_ref>[1]"].output` for the second iteration child output.
|
|
84
|
+
- `steps["<http_child_ref>[0]"].output.response` for native HTTP response body from iteration 0.
|
|
85
|
+
- `steps["<javascript_child_ref>[0]"].output.result` for JavaScript result from iteration 0.
|
|
86
|
+
- `steps["<python_child_ref>[0]"].output.result` for Python result from iteration 0.
|
|
87
|
+
|
|
88
|
+
Do not use after the loop:
|
|
89
|
+
- `steps.<foreach_ref>.output.result`
|
|
90
|
+
- `steps.<foreach_ref>.output.response`
|
|
91
|
+
- `steps.<foreach_ref>.output.<child_ref>`
|
|
92
|
+
- `steps.<child_ref>.output` when reading iteration output after FOREACH; use indexed refs instead.
|
|
93
|
+
|
|
94
|
+
## Generation Rules
|
|
95
|
+
|
|
96
|
+
- Use uppercase step type: `"FOREACH"`.
|
|
97
|
+
- Put loop body steps in `children`.
|
|
98
|
+
- Provide `input.inputArray`.
|
|
99
|
+
- Provide `input.concurrency`.
|
|
100
|
+
- Use `concurrency: 1` when order/rate limiting matters.
|
|
101
|
+
- Increase `concurrency` only when iterations are independent and safe to run concurrently.
|
|
102
|
+
- Use `{{foreach.index }}` and `{{foreach.value }}` in child step inputs when the current item/index is needed.
|
|
103
|
+
- Child `ref` values must be unique across the whole workflow definition.
|
|
104
|
+
- After the loop, collect child results using indexed refs like `steps["http_1[0]"].output`.
|
|
105
|
+
- If each iteration needs multiple sequential steps, put a `LIST` as the FOREACH child/body.
|
|
106
|
+
|
|
107
|
+
## Debugging Rules
|
|
108
|
+
|
|
109
|
+
When debugging a FOREACH:
|
|
110
|
+
- Inspect `input.inputArray` to confirm the expected items.
|
|
111
|
+
- Inspect `input.concurrency` to understand scheduling/concurrency behavior.
|
|
112
|
+
- Inspect child step records for each iteration.
|
|
113
|
+
- Use indexed refs to reason about per-iteration child outputs.
|
|
114
|
+
- If only some iterations failed, identify the failing index and current `foreach.value`.
|
|
115
|
+
- Do not stop at the FOREACH container's own `output: {}`; inspect iteration child outputs.
|
|
116
|
+
|
|
117
|
+
Common failures:
|
|
118
|
+
- Missing or non-array `inputArray`.
|
|
119
|
+
- Referencing `foreach.value` outside a FOREACH child input/script context.
|
|
120
|
+
- Reading post-loop results from `steps.http_1.output` instead of `steps["http_1[0]"].output`.
|
|
121
|
+
- Setting concurrency too high for rate-limited external APIs.
|
|
122
|
+
- Assuming results are a single aggregated array when they are exposed as indexed child refs.
|
|
123
|
+
- Child refs collide with refs elsewhere in the workflow.
|
|
124
|
+
|
|
125
|
+
## Minimal Process Definition Example
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"orgId": 1,
|
|
130
|
+
"namespace": "default",
|
|
131
|
+
"name": "kebab-case-name",
|
|
132
|
+
"version": 1,
|
|
133
|
+
"type": "API_ORCHESTRATION",
|
|
134
|
+
"description": "Call an HTTP endpoint for each input item.",
|
|
135
|
+
"configuration": null,
|
|
136
|
+
"steps": [
|
|
137
|
+
{
|
|
138
|
+
"orgId": 1,
|
|
139
|
+
"namespace": "default",
|
|
140
|
+
"name": "foreach",
|
|
141
|
+
"type": "FOREACH",
|
|
142
|
+
"ref": "foreach_1",
|
|
143
|
+
"optional": false,
|
|
144
|
+
"createdBy": "system",
|
|
145
|
+
"updatedBy": "system",
|
|
146
|
+
"description": null,
|
|
147
|
+
"label": null,
|
|
148
|
+
"created": 1700000000000,
|
|
149
|
+
"updated": 1700000000000,
|
|
150
|
+
"configuration": {
|
|
151
|
+
"errorPolicyName": null,
|
|
152
|
+
"useCache": false,
|
|
153
|
+
"cacheKey": null,
|
|
154
|
+
"cacheTimeoutSeconds": 0,
|
|
155
|
+
"stream": false,
|
|
156
|
+
"streamAllStatuses": false,
|
|
157
|
+
"preExecutionScript": null,
|
|
158
|
+
"constructInputFromScript": false,
|
|
159
|
+
"scriptLanguage": null,
|
|
160
|
+
"jqTransformer": null,
|
|
161
|
+
"rateLimitMaxRequests": 0,
|
|
162
|
+
"rateLimitWindowSeconds": 0
|
|
163
|
+
},
|
|
164
|
+
"children": [
|
|
165
|
+
{
|
|
166
|
+
"orgId": 1,
|
|
167
|
+
"namespace": "default",
|
|
168
|
+
"name": "http",
|
|
169
|
+
"type": "HTTP",
|
|
170
|
+
"ref": "http_1",
|
|
171
|
+
"optional": false,
|
|
172
|
+
"createdBy": "system",
|
|
173
|
+
"updatedBy": "system",
|
|
174
|
+
"description": null,
|
|
175
|
+
"label": null,
|
|
176
|
+
"created": 1700000000000,
|
|
177
|
+
"updated": 1700000000000,
|
|
178
|
+
"configuration": {
|
|
179
|
+
"errorPolicyName": null,
|
|
180
|
+
"useCache": false,
|
|
181
|
+
"cacheKey": null,
|
|
182
|
+
"cacheTimeoutSeconds": 0,
|
|
183
|
+
"stream": false,
|
|
184
|
+
"streamAllStatuses": false,
|
|
185
|
+
"preExecutionScript": null,
|
|
186
|
+
"constructInputFromScript": false,
|
|
187
|
+
"scriptLanguage": null,
|
|
188
|
+
"jqTransformer": null,
|
|
189
|
+
"rateLimitMaxRequests": 0,
|
|
190
|
+
"rateLimitWindowSeconds": 0
|
|
191
|
+
},
|
|
192
|
+
"children": [],
|
|
193
|
+
"input": {
|
|
194
|
+
"method": "GET",
|
|
195
|
+
"url": "http://localhost:8080/api/test/get",
|
|
196
|
+
"headers": {
|
|
197
|
+
"Content-Type": "application/json",
|
|
198
|
+
"Accept": "application/json",
|
|
199
|
+
"Authorization": "Bearer {{secrets.test_token}}"
|
|
200
|
+
},
|
|
201
|
+
"params": {
|
|
202
|
+
"sampleKey": "sampleValue",
|
|
203
|
+
"index": "{{foreach.index }}",
|
|
204
|
+
"value": "{{foreach.value }}"
|
|
205
|
+
},
|
|
206
|
+
"repeatUntilEnabled": null,
|
|
207
|
+
"repeatUntilCondition": {
|
|
208
|
+
"script": "(steps, context) => {\n return steps.__self.output.response.counter === 100;\n}"
|
|
209
|
+
},
|
|
210
|
+
"repeatIntervalSeconds": null,
|
|
211
|
+
"maxRepeatCount": null,
|
|
212
|
+
"includeFullResponseString": false,
|
|
213
|
+
"noEncode": false,
|
|
214
|
+
"extraLongTimeouts": false
|
|
215
|
+
},
|
|
216
|
+
"output": null
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
"input": {
|
|
220
|
+
"inputArray": [1, 2, 3],
|
|
221
|
+
"concurrency": 1
|
|
222
|
+
},
|
|
223
|
+
"output": null
|
|
224
|
+
}
|
|
225
|
+
],
|
|
226
|
+
"defaultInput": null,
|
|
227
|
+
"defaultOutput": null,
|
|
228
|
+
"outputMapping": null,
|
|
229
|
+
"signature": null,
|
|
230
|
+
"metadata": null,
|
|
231
|
+
"tags": null,
|
|
232
|
+
"dependencies": null,
|
|
233
|
+
"dependents": null
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Example: Collect FOREACH Results
|
|
238
|
+
|
|
239
|
+
Use indexed child refs in a later JavaScript step:
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
(steps, context) => {
|
|
243
|
+
const outputs = [];
|
|
244
|
+
for (let i = 0; i < 3; i += 1) {
|
|
245
|
+
outputs.push(steps[`http_1[${i}]`].output.response);
|
|
246
|
+
}
|
|
247
|
+
return { outputs };
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# HTTP Step Schema
|
|
2
|
+
|
|
3
|
+
Native `HTTP` steps call REST endpoints directly from a process definition.
|
|
4
|
+
Use `HTTP` when the workflow needs a direct request with standard method, URL,
|
|
5
|
+
headers, query params, optional JSON body, and optional polling.
|
|
6
|
+
|
|
7
|
+
This is different from an `INTEGRATION` step whose `input.type` may be `http`.
|
|
8
|
+
Native HTTP step type is uppercase: `"type": "HTTP"`.
|
|
9
|
+
|
|
10
|
+
## Definition Input Schema
|
|
11
|
+
|
|
12
|
+
GET request:
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"method": "GET",
|
|
17
|
+
"url": "https://api.example.com/resource",
|
|
18
|
+
"headers": {
|
|
19
|
+
"Accept": "application/json"
|
|
20
|
+
},
|
|
21
|
+
"params": {},
|
|
22
|
+
"repeatUntilEnabled": null,
|
|
23
|
+
"repeatUntilCondition": { "script": "(steps, context) => { return false; }" },
|
|
24
|
+
"repeatIntervalSeconds": null,
|
|
25
|
+
"maxRepeatCount": null,
|
|
26
|
+
"includeFullResponseString": false,
|
|
27
|
+
"noEncode": false,
|
|
28
|
+
"extraLongTimeouts": false
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
POST, PUT, PATCH, or DELETE request with JSON body:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"method": "POST",
|
|
37
|
+
"url": "https://api.example.com/resource",
|
|
38
|
+
"headers": {
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
"Accept": "application/json"
|
|
41
|
+
},
|
|
42
|
+
"params": {},
|
|
43
|
+
"body": {
|
|
44
|
+
"type": "json",
|
|
45
|
+
"content": {
|
|
46
|
+
"field": "value"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"repeatUntilEnabled": null,
|
|
50
|
+
"repeatUntilCondition": { "script": "(steps, context) => { return false; }" },
|
|
51
|
+
"repeatIntervalSeconds": null,
|
|
52
|
+
"maxRepeatCount": null,
|
|
53
|
+
"includeFullResponseString": false,
|
|
54
|
+
"noEncode": false,
|
|
55
|
+
"extraLongTimeouts": false
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Runtime Output Schema
|
|
60
|
+
|
|
61
|
+
Native HTTP stores the parsed response body in `output.response`.
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"response": {},
|
|
66
|
+
"statusCode": 200
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
If the endpoint returns an array, `response` is the array:
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"response": [
|
|
75
|
+
{ "id": 1 },
|
|
76
|
+
{ "id": 2 }
|
|
77
|
+
],
|
|
78
|
+
"statusCode": 200
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Output Access Paths
|
|
83
|
+
|
|
84
|
+
Use:
|
|
85
|
+
- `steps.<ref>.output.response` for the full parsed response body.
|
|
86
|
+
- `steps.<ref>.output.response.<field>` for object response fields.
|
|
87
|
+
- `steps.<ref>.output.response.length` for array response count.
|
|
88
|
+
- `steps.<ref>.output.statusCode` for HTTP status code.
|
|
89
|
+
|
|
90
|
+
Do not use:
|
|
91
|
+
- `steps.<ref>.output.result`
|
|
92
|
+
- `steps.<ref>.output.results`
|
|
93
|
+
- `steps.<ref>.output.status`
|
|
94
|
+
|
|
95
|
+
## Generation Rules
|
|
96
|
+
|
|
97
|
+
- Use uppercase step type: `"HTTP"`.
|
|
98
|
+
- Use `params: {}` even when there are no query parameters.
|
|
99
|
+
- Omit `body` for normal GET requests.
|
|
100
|
+
- Use `body: { "type": "json", "content": { ... } }` for JSON request bodies.
|
|
101
|
+
- Use `{{variables.<name>}}` for environment-specific URLs or config.
|
|
102
|
+
- Use `{{secrets.<name>}}` for tokens, API keys, and credentials.
|
|
103
|
+
- Never hardcode credentials.
|
|
104
|
+
- For non-polling requests, set `repeatUntilEnabled`, `repeatIntervalSeconds`, and `maxRepeatCount` to `null`.
|
|
105
|
+
- If `repeatUntilEnabled` is `true`, provide a safe `repeatUntilCondition.script` using optional chaining.
|
|
106
|
+
- When `configuration.jqTransformer` is set, the HTTP output is replaced with `output.transformed`. The pre-JQ-transform output is omitted by default; set input `includePreJqTransformOutput: true` only when the raw step output should also be stored as `output.preJqTransformOutput`.
|
|
107
|
+
|
|
108
|
+
## Debugging Rules
|
|
109
|
+
|
|
110
|
+
When a later step fails after an HTTP step:
|
|
111
|
+
- Inspect `steps.<http_ref>.output.response` first.
|
|
112
|
+
- Check whether the response is an object or array.
|
|
113
|
+
- Check `steps.<http_ref>.output.statusCode`.
|
|
114
|
+
- If a script reads `steps.<http_ref>.output.result`, explain that native HTTP uses `output.response`.
|
|
115
|
+
- If the HTTP step failed, summarize the status code and response body if available.
|
|
116
|
+
|
|
117
|
+
Common failures:
|
|
118
|
+
- JavaScript step reads `output.result` instead of `output.response`.
|
|
119
|
+
- Script assumes response is an array but endpoint returned an object.
|
|
120
|
+
- Script assumes response is an object but endpoint returned an array.
|
|
121
|
+
- Missing `Content-Type: application/json` for JSON body requests.
|
|
122
|
+
- Token was hardcoded instead of using `{{secrets.<name>}}`.
|
|
123
|
+
|
|
124
|
+
## Minimal Example: Count Posts
|
|
125
|
+
|
|
126
|
+
HTTP step:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"orgId": 1,
|
|
131
|
+
"namespace": "default",
|
|
132
|
+
"name": "fetch_posts",
|
|
133
|
+
"type": "HTTP",
|
|
134
|
+
"ref": "fetch_posts_1",
|
|
135
|
+
"optional": false,
|
|
136
|
+
"createdBy": "system",
|
|
137
|
+
"updatedBy": "system",
|
|
138
|
+
"description": "Fetch posts from JSONPlaceholder.",
|
|
139
|
+
"label": null,
|
|
140
|
+
"created": 1700000000000,
|
|
141
|
+
"updated": 1700000000000,
|
|
142
|
+
"configuration": {
|
|
143
|
+
"errorPolicyName": null,
|
|
144
|
+
"useCache": false,
|
|
145
|
+
"cacheKey": null,
|
|
146
|
+
"cacheTimeoutSeconds": 0,
|
|
147
|
+
"stream": false,
|
|
148
|
+
"streamAllStatuses": false,
|
|
149
|
+
"preExecutionScript": null,
|
|
150
|
+
"constructInputFromScript": false,
|
|
151
|
+
"scriptLanguage": null,
|
|
152
|
+
"jqTransformer": null,
|
|
153
|
+
"rateLimitMaxRequests": 0,
|
|
154
|
+
"rateLimitWindowSeconds": 0
|
|
155
|
+
},
|
|
156
|
+
"children": [],
|
|
157
|
+
"input": {
|
|
158
|
+
"method": "GET",
|
|
159
|
+
"url": "https://jsonplaceholder.typicode.com/posts",
|
|
160
|
+
"headers": {
|
|
161
|
+
"Accept": "application/json"
|
|
162
|
+
},
|
|
163
|
+
"params": {},
|
|
164
|
+
"repeatUntilEnabled": null,
|
|
165
|
+
"repeatUntilCondition": { "script": "(steps, context) => { return false; }" },
|
|
166
|
+
"repeatIntervalSeconds": null,
|
|
167
|
+
"maxRepeatCount": null,
|
|
168
|
+
"includeFullResponseString": false,
|
|
169
|
+
"noEncode": false,
|
|
170
|
+
"extraLongTimeouts": false
|
|
171
|
+
},
|
|
172
|
+
"output": null
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
JavaScript step after it:
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
(steps, context) => {
|
|
180
|
+
const posts = steps.fetch_posts_1.output.response || [];
|
|
181
|
+
return { count: Array.isArray(posts) ? posts.length : 0 };
|
|
182
|
+
}
|
|
183
|
+
```
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# JavaScript Step Schema
|
|
2
|
+
|
|
3
|
+
`JAVASCRIPT` steps run inline JavaScript inside a process definition. Use them
|
|
4
|
+
for data mapping, transformation, validation, assertions, branching helpers,
|
|
5
|
+
and small deterministic calculations.
|
|
6
|
+
|
|
7
|
+
JavaScript steps receive two default inputs:
|
|
8
|
+
- `steps`: runtime data for the current step and previously executed steps.
|
|
9
|
+
- `context`: runtime process context, including process id, input, state, and metadata.
|
|
10
|
+
|
|
11
|
+
## Definition Input Schema
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"script": "// (steps, context) will be provided as default inputs \n(steps, context) => {\n return {\n \"processId\": context.id,\n \"currentStepId\": steps.__self.id\n };\n}"
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Runtime Output Schema
|
|
20
|
+
|
|
21
|
+
The JavaScript function's returned value is stored in `output.result`.
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"result": {
|
|
26
|
+
"processId": 28800004,
|
|
27
|
+
"currentStepId": {
|
|
28
|
+
"ref": "javascript_1",
|
|
29
|
+
"processId": 28800004,
|
|
30
|
+
"id": 28800006
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"logs": []
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Process-level output for a single JavaScript-step workflow can mirror the
|
|
38
|
+
JavaScript step output:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"result": {
|
|
43
|
+
"processId": 28800004
|
|
44
|
+
},
|
|
45
|
+
"logs": []
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Output Access Paths
|
|
50
|
+
|
|
51
|
+
Use:
|
|
52
|
+
- `steps.<ref>.output.result` for the complete returned value.
|
|
53
|
+
- `steps.<ref>.output.result.<field>` for returned object fields.
|
|
54
|
+
- `steps.<ref>.output.logs` for captured logs.
|
|
55
|
+
- `steps.__self.id` inside the running script for the current step id object.
|
|
56
|
+
- `context.id` inside the running script for the process id.
|
|
57
|
+
- `context.input.<field>` inside the running script for process input.
|
|
58
|
+
|
|
59
|
+
Do not use:
|
|
60
|
+
- `steps.<ref>.output.response`
|
|
61
|
+
- `steps.<ref>.output.results`
|
|
62
|
+
- `steps.<ref>.output.<field>` for returned object fields
|
|
63
|
+
|
|
64
|
+
## Generation Rules
|
|
65
|
+
|
|
66
|
+
- Use uppercase step type: `"JAVASCRIPT"`.
|
|
67
|
+
- Put executable code in `input.script`.
|
|
68
|
+
- The script must be an arrow function or function-like JavaScript body that accepts `(steps, context)`.
|
|
69
|
+
- The script should explicitly `return` the value that later steps need.
|
|
70
|
+
- Prefer returning an object, even for one value, so later references are stable.
|
|
71
|
+
- Keep scripts deterministic and side-effect free.
|
|
72
|
+
- Use JavaScript optional chaining when reading uncertain upstream outputs.
|
|
73
|
+
- Read native HTTP responses from `steps.<http_ref>.output.response`, not `output.result`.
|
|
74
|
+
- Read JavaScript or Python results from `steps.<ref>.output.result`.
|
|
75
|
+
- Do not hardcode secrets or credentials in scripts.
|
|
76
|
+
|
|
77
|
+
## Debugging Rules
|
|
78
|
+
|
|
79
|
+
When a JavaScript step fails:
|
|
80
|
+
- Inspect the step record's `input.script`.
|
|
81
|
+
- Inspect the previous step outputs referenced by the script.
|
|
82
|
+
- Verify output paths against each referenced step type.
|
|
83
|
+
- If the script reads an HTTP step with `output.result`, explain that native HTTP uses `output.response`.
|
|
84
|
+
- If the script returns nothing, explain that `output.result` will be missing or null.
|
|
85
|
+
- If process output is unexpected, compare process-level `output` with the JavaScript step's `stepRecords[].output`.
|
|
86
|
+
|
|
87
|
+
Common failures:
|
|
88
|
+
- Missing `return`.
|
|
89
|
+
- Referencing native HTTP output as `steps.<http_ref>.output.result`.
|
|
90
|
+
- Assuming an upstream value is an array without checking `Array.isArray`.
|
|
91
|
+
- Returning a primitive when later steps expect object fields.
|
|
92
|
+
- Syntax errors from trailing commas in environments that do not support them.
|
|
93
|
+
- Accessing `steps.<ref>.output.result.<field>` when the previous JavaScript step returned a primitive.
|
|
94
|
+
|
|
95
|
+
## Minimal Process Definition Example
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"orgId": 1,
|
|
100
|
+
"namespace": "default",
|
|
101
|
+
"name": "kebab-case-name",
|
|
102
|
+
"version": 1,
|
|
103
|
+
"type": "API_ORCHESTRATION",
|
|
104
|
+
"description": "Return process and current step ids.",
|
|
105
|
+
"configuration": null,
|
|
106
|
+
"steps": [
|
|
107
|
+
{
|
|
108
|
+
"orgId": 1,
|
|
109
|
+
"namespace": "default",
|
|
110
|
+
"name": "javascript",
|
|
111
|
+
"type": "JAVASCRIPT",
|
|
112
|
+
"ref": "javascript_1",
|
|
113
|
+
"optional": false,
|
|
114
|
+
"createdBy": "system",
|
|
115
|
+
"updatedBy": "system",
|
|
116
|
+
"description": null,
|
|
117
|
+
"label": null,
|
|
118
|
+
"created": 1700000000000,
|
|
119
|
+
"updated": 1700000000000,
|
|
120
|
+
"configuration": {
|
|
121
|
+
"errorPolicyName": null,
|
|
122
|
+
"useCache": false,
|
|
123
|
+
"cacheKey": null,
|
|
124
|
+
"cacheTimeoutSeconds": 0,
|
|
125
|
+
"stream": false,
|
|
126
|
+
"streamAllStatuses": false,
|
|
127
|
+
"preExecutionScript": null,
|
|
128
|
+
"constructInputFromScript": false,
|
|
129
|
+
"scriptLanguage": null,
|
|
130
|
+
"jqTransformer": null,
|
|
131
|
+
"rateLimitMaxRequests": 0,
|
|
132
|
+
"rateLimitWindowSeconds": 0
|
|
133
|
+
},
|
|
134
|
+
"children": [],
|
|
135
|
+
"input": {
|
|
136
|
+
"script": "// (steps, context) will be provided as default inputs \n(steps, context) => {\n return {\n \"processId\": context.id,\n \"currentStepId\": steps.__self.id\n };\n}"
|
|
137
|
+
},
|
|
138
|
+
"output": null
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
"defaultInput": null,
|
|
142
|
+
"defaultOutput": null,
|
|
143
|
+
"outputMapping": null,
|
|
144
|
+
"signature": null,
|
|
145
|
+
"metadata": null,
|
|
146
|
+
"tags": null,
|
|
147
|
+
"dependencies": null,
|
|
148
|
+
"dependents": null
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Minimal Executed Step Example
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"id": 28800006,
|
|
157
|
+
"processId": 28800004,
|
|
158
|
+
"ref": "javascript_1",
|
|
159
|
+
"namespace": "default",
|
|
160
|
+
"name": "javascript",
|
|
161
|
+
"type": "JAVASCRIPT",
|
|
162
|
+
"status": "COMPLETED",
|
|
163
|
+
"input": {
|
|
164
|
+
"script": "// (steps, context) will be provided as default inputs \n(steps, context) => {\n return {\n \"processId\": context.id,\n \"currentStepId\": steps.__self.id\n };\n}",
|
|
165
|
+
"__currentExecutionStartTime": 1778182609428
|
|
166
|
+
},
|
|
167
|
+
"output": {
|
|
168
|
+
"result": {
|
|
169
|
+
"currentStepId": {
|
|
170
|
+
"ref": "javascript_1",
|
|
171
|
+
"processId": 28800004,
|
|
172
|
+
"id": 28800006
|
|
173
|
+
},
|
|
174
|
+
"processId": 28800004
|
|
175
|
+
},
|
|
176
|
+
"logs": []
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Example: Count Native HTTP Response Array
|
|
182
|
+
|
|
183
|
+
Use this when a previous native `HTTP` step with ref `fetch_posts_1` returns an
|
|
184
|
+
array response body:
|
|
185
|
+
|
|
186
|
+
```javascript
|
|
187
|
+
(steps, context) => {
|
|
188
|
+
const posts = steps.fetch_posts_1.output.response || [];
|
|
189
|
+
return { count: Array.isArray(posts) ? posts.length : 0 };
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|