@addai/flows-mcp 0.2.0 → 0.3.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.
Files changed (74) hide show
  1. package/README.md +13 -0
  2. package/dist/bin/install.js +53 -0
  3. package/dist/bin/install.js.map +1 -1
  4. package/dist/client.d.ts +2 -0
  5. package/dist/client.js +20 -2
  6. package/dist/client.js.map +1 -1
  7. package/dist/healing.d.ts +9 -0
  8. package/dist/healing.js +104 -0
  9. package/dist/healing.js.map +1 -0
  10. package/dist/index.js +6 -4
  11. package/dist/index.js.map +1 -1
  12. package/dist/instructions.d.ts +6 -0
  13. package/dist/instructions.js +149 -0
  14. package/dist/instructions.js.map +1 -0
  15. package/dist/node-defaults.js +395 -46
  16. package/dist/node-defaults.js.map +1 -1
  17. package/dist/prompts.d.ts +2 -0
  18. package/dist/prompts.js +741 -0
  19. package/dist/prompts.js.map +1 -0
  20. package/dist/tools/custom-nodes.js +14 -9
  21. package/dist/tools/custom-nodes.js.map +1 -1
  22. package/dist/tools/flows.js +36 -35
  23. package/dist/tools/flows.js.map +1 -1
  24. package/dist/tools/nodes.js +17 -7
  25. package/dist/tools/nodes.js.map +1 -1
  26. package/dist/tools/preview.d.ts +3 -0
  27. package/dist/tools/preview.js +85 -0
  28. package/dist/tools/preview.js.map +1 -0
  29. package/dist/tools/reference.js +8 -5
  30. package/dist/tools/reference.js.map +1 -1
  31. package/dist/tools/runs.js +112 -1
  32. package/dist/tools/runs.js.map +1 -1
  33. package/dist/tools/variables.js +1 -1
  34. package/dist/tools/variables.js.map +1 -1
  35. package/dist/types.d.ts +13 -0
  36. package/dist/validation/enums.d.ts +20 -0
  37. package/dist/validation/enums.js +36 -0
  38. package/dist/validation/enums.js.map +1 -0
  39. package/dist/validation/handles.d.ts +2 -0
  40. package/dist/validation/handles.js +88 -0
  41. package/dist/validation/handles.js.map +1 -0
  42. package/dist/validation/index.d.ts +3 -0
  43. package/dist/validation/index.js +47 -0
  44. package/dist/validation/index.js.map +1 -0
  45. package/dist/validation/nested-ids.d.ts +2 -0
  46. package/dist/validation/nested-ids.js +55 -0
  47. package/dist/validation/nested-ids.js.map +1 -0
  48. package/dist/validation/reachability.d.ts +2 -0
  49. package/dist/validation/reachability.js +62 -0
  50. package/dist/validation/reachability.js.map +1 -0
  51. package/dist/validation/references.d.ts +2 -0
  52. package/dist/validation/references.js +107 -0
  53. package/dist/validation/references.js.map +1 -0
  54. package/dist/validation/shape-rules.d.ts +7 -0
  55. package/dist/validation/shape-rules.js +284 -0
  56. package/dist/validation/shape-rules.js.map +1 -0
  57. package/dist/validation/shape.d.ts +2 -0
  58. package/dist/validation/shape.js +47 -0
  59. package/dist/validation/shape.js.map +1 -0
  60. package/dist/validation/structure.d.ts +2 -0
  61. package/dist/validation/structure.js +137 -0
  62. package/dist/validation/structure.js.map +1 -0
  63. package/dist/validation/syntax.d.ts +2 -0
  64. package/dist/validation/syntax.js +69 -0
  65. package/dist/validation/syntax.js.map +1 -0
  66. package/dist/validation/types.d.ts +49 -0
  67. package/dist/validation/types.js +2 -0
  68. package/dist/validation/types.js.map +1 -0
  69. package/package.json +15 -4
  70. package/skill/SKILL.md +116 -0
  71. package/skill/anti-patterns.md +207 -0
  72. package/skill/node-cheatsheet.md +37 -0
  73. package/skill/recipes.md +308 -0
  74. package/skill/version.txt +1 -0
@@ -0,0 +1,741 @@
1
+ export function registerPrompts(server) {
2
+ server.prompt('flow-guide', 'Complete reference for building +Ai Flows. Covers every node type, variable syntax, form elements, conditions, handles, and common patterns. Load this before building or modifying flows.', async () => ({
3
+ messages: [{
4
+ role: 'user',
5
+ content: {
6
+ type: 'text',
7
+ text: FLOW_GUIDE
8
+ }
9
+ }]
10
+ }));
11
+ }
12
+ const FLOW_GUIDE = `
13
+ # +Ai Flows — Complete Builder Reference
14
+
15
+ ## MCP Tools Overview
16
+
17
+ | Tool | Purpose |
18
+ |------|---------|
19
+ | \`list_flows\` | List all flows in workspace |
20
+ | \`get_flow\` | Get full flow (nodes, edges, variables) |
21
+ | \`create_flow\` | Create new flow with trigger type |
22
+ | \`update_flow\` | Save full flow state |
23
+ | \`delete_flow\` / \`duplicate_flow\` | Delete or clone |
24
+ | \`add_nodes\` | Add nodes + edges in one call |
25
+ | \`update_node\` | Update node data (merged with existing) |
26
+ | \`remove_nodes\` | Remove nodes + connected edges |
27
+ | \`connect_nodes\` / \`disconnect_nodes\` | Manage edges |
28
+ | \`validate_flow\` | Check for errors before publishing |
29
+ | \`publish_flow\` | Publish as production version |
30
+ | \`run_flow\` | Start a production run |
31
+ | \`test_flow\` | Test a flow, wait for completion, return all node outputs |
32
+ | \`list_runs\` / \`get_run\` / \`get_node_output\` | Inspect runs |
33
+ | \`manage_run\` | Cancel/pause/unpause/delete runs |
34
+ | \`set_variable\` / \`list_variables\` / \`delete_variable\` | Flow variables |
35
+ | \`list_node_types\` / \`get_node_type_info\` | Node reference |
36
+ | \`list_page_elements\` / \`get_page_element_info\` | Form elements |
37
+ | \`list_custom_nodes\` / \`create_custom_node\` | Custom nodes |
38
+ | \`create_version\` / \`list_versions\` / \`revert_to_version\` | Versioning |
39
+ | \`create_split_test\` / \`start_split_test\` / \`stop_split_test\` | A/B testing |
40
+ | \`get_flow_stats\` / \`get_runs_stats\` / \`get_outcome_breakdown\` | Analytics |
41
+
42
+ ---
43
+
44
+ ## Variable Syntax — Three Distinct Systems
45
+
46
+ ### 1. Config Fields (node data: URL, body, conditions, element defaults, etc.)
47
+
48
+ Template syntax resolved at runtime:
49
+
50
+ \`\`\`
51
+ {{nodeId.fieldName}} → Field from upstream node output
52
+ {{nodeId.nested.path}} → Dot notation for nested data
53
+ {{nodeId.array[0]}} → Array index access
54
+ {{nodeId.array[#]}} → Shorthand for [0]
55
+ {{Variables.myVar}} → Flow variable value
56
+ \`\`\`
57
+
58
+ ### 2. Code Nodes (inline JavaScript sandbox)
59
+
60
+ \`\`\`javascript
61
+ // Access upstream node outputs by node ID
62
+ const data = $("abc-123-node-id");
63
+ const name = $("trigger-id").body.name;
64
+
65
+ // Logging
66
+ console.log("Debug:", data);
67
+
68
+ // HTTP requests (localhost/private IPs blocked)
69
+ const response = await fetch("https://api.example.com/data");
70
+ const json = await response.json();
71
+
72
+ // MUST return an object — keys become node output fields
73
+ return {
74
+ result: json,
75
+ count: json.items.length
76
+ };
77
+ \`\`\`
78
+
79
+ In \`runForEachItem\` mode: \`item\` (current array element) and \`index\` (current position) are available.
80
+
81
+ **NEVER use \`{{}}\` template syntax in code. NEVER use \`$input\`.**
82
+
83
+ ### 3. Custom Node Code (separate sandbox)
84
+
85
+ \`\`\`javascript
86
+ // Inputs pre-resolved from input_schema ({{}} templates already resolved)
87
+ const url = inputs.api_url;
88
+ const apiKey = secrets.api_key;
89
+
90
+ const response = await fetch(url, {
91
+ headers: { 'Authorization': \\\`Bearer \\\${apiKey}\\\` }
92
+ });
93
+
94
+ // MUST return object matching output_schema keys
95
+ return {
96
+ data: await response.json(),
97
+ status: response.status
98
+ };
99
+ \`\`\`
100
+
101
+ **NEVER use \`$("nodeId")\` in custom node code. Use \`inputs.keyName\` instead.**
102
+
103
+ ---
104
+
105
+ ## Edge Handles — Connecting Branching Nodes
106
+
107
+ Most nodes have a single default output (no \`source_handle\` needed). Branching nodes require specific handles:
108
+
109
+ | Node Type | Source Handles | Notes |
110
+ |-----------|---------------|-------|
111
+ | \`if\` | \`"true"\`, \`"false"\` | Based on condition evaluation |
112
+ | \`switch\` | Case \`outputLabel\` values, \`"default"\` | outputLabel defined per case |
113
+ | \`loop\` | \`"loop"\`, \`"done"\`, \`"fail"\` | "fail" only if \`enableFailRoute: true\` |
114
+ | \`review\` | \`"option_0"\`, \`"option_1"\`, ... | One handle per review option |
115
+ | \`page\` | \`"right"\` (submission), abandonment IDs | Abandonment handles from \`abandonments\` array |
116
+ | \`splitTest\` | Variant labels: \`"Variant A"\`, \`"Variant B"\` | Match the variant label strings |
117
+
118
+ ---
119
+
120
+ ## All Node Types — Complete Reference
121
+
122
+ ### Trigger Nodes
123
+
124
+ Every flow must start with one trigger node.
125
+
126
+ #### Webhook Trigger (\`trigger\`)
127
+ - Starts flow on HTTP request
128
+ - Output: \`{ body, headers, query, method, url }\`
129
+ - Downstream: \`{{triggerId.body.fieldName}}\`
130
+
131
+ #### Schedule Trigger (\`scheduleTrigger\`)
132
+ - Runs on interval or cron
133
+ - Data: \`scheduleType: "interval"|"cron"\`, \`intervalValue\`, \`intervalUnit\` (seconds/minutes/hours/days), \`cronExpression\`, \`timezone\`
134
+ - Output: \`{ scheduledTime, scheduleType }\`
135
+
136
+ #### Email Trigger (\`emailTrigger\`)
137
+ - Starts flow on email receipt
138
+ - Output: \`{ from, to, subject, text, html, attachments }\`
139
+
140
+ #### Start Form (page node with \`data.isStartForm: true\`)
141
+ - Public form URL triggers flow. Implemented as a regular page node
142
+ with \`data.isStartForm: true\` (not a separate node type — the
143
+ legacy \`startForm\` type was removed in the start-form refactor).
144
+ - Data: \`elements\` array (form fields), \`pageStyle\`, \`formSlug\` (defaults to node id)
145
+ - Public URL: \`/form/<flowId>/<slugOrNodeId>\`
146
+ - Cannot have incoming edges. Mutually exclusive with isGoal/isExit.
147
+ - Output (superset): \`{ formData: { "<elementId>": value }, submissionData: { "Element Label": value }, urlParams, fingerprint, submittedAt, pageUrl, sessionToken }\`
148
+ - Downstream: \`{{pageNodeId.submissionData.Email}}\` (label-keyed) or \`{{pageNodeId.formData.<elementId>}}\` (id-keyed raw)
149
+
150
+ #### Table Triggers (\`tableTrigger\`, \`tableButton\`, \`tableActionTrigger\`, \`batchActionTrigger\`, \`tablesSchedule\`)
151
+ - Fire on +Ai Table events (INSERT/UPDATE/DELETE, button clicks, batch actions, schedules)
152
+ - Output includes: \`row\`, \`rowId\`, \`tableId\`, \`databaseId\`, event-specific fields
153
+
154
+ ### Processing Nodes
155
+
156
+ #### HTTP Request (\`httpRequest\`)
157
+ - Makes external API calls
158
+ - Key data fields:
159
+ - \`url\`: string (supports \`{{}}\` templates)
160
+ - \`method\`: GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS
161
+ - \`headers\`: \`[{key, value, enabled: true}]\`
162
+ - \`queryParams\`: \`[{key, value, enabled: true}]\`
163
+ - \`bodyType\`: none|json|text|xml|form|file
164
+ - \`body\`: string (for json/text/xml — supports \`{{}}\`)
165
+ - \`formFields\`: \`[{key, value, type: "text"|"file", enabled}]\` (for form)
166
+ - \`fileBody\`: variable reference (for file), \`fileContentType\`: MIME type
167
+ - \`authentication\`: \`{type: "none"|"bearer"|"basic"|"apikey", token?, username?, password?, apiKeyHeader?, apiKeyValue?}\`
168
+ - \`timeout\`: ms (default 30000), \`retries\`: 0-10
169
+ - \`storeHeaders\`: boolean, \`onError\`: "stop"|"continue"
170
+ - Output: \`{ status, body, headers?, success, error? }\`
171
+
172
+ #### Code (\`code\`)
173
+ - Inline JavaScript sandbox
174
+ - Data: \`mode: "runOnce"|"runForEachItem"\`, \`code\`, \`itemsPath\` (for runForEachItem), \`onError: "stop"|"continue"\`
175
+ - Globals: \`$("nodeId")\`, \`console\`, \`fetch()\`
176
+ - runForEachItem: \`item\`, \`index\` available
177
+ - Output: whatever the code returns (spread into output)
178
+
179
+ #### Respond to Webhook (\`respondToWebhook\`)
180
+ - Sends HTTP response to webhook caller
181
+ - Data: \`statusCode\`, \`responseBody\` (string, supports \`{{}}\`), \`bodyType: "json"|"text"|"html"\`, \`headers: [{key, value}]\`
182
+ - Only works in Webhook Trigger flows
183
+
184
+ #### Map Data (\`map\`)
185
+ - Transforms data fields
186
+ - Data: \`mappings\` array, \`transformMode: "standard"|"batch"|"merge"|"restructure"\`
187
+ - Each mapping: \`{id, inputExpression: "{{nodeId.field}}", outputName: "key", transformType, enabled, description}\`
188
+ - Transform types (17): direct, toString, toNumber, toBoolean, toJson, stringify, lowercase, uppercase, trim, length, split (delimiter), join (separator), extract (pattern), replace (find+replaceWith), template (template), calculate (expression), custom (customCode)
189
+ - Output: \`{ [outputName]: transformedValue, _metadata: {successfulMappings, failedMappings, totalMappings} }\`
190
+
191
+ ### Logic Nodes
192
+
193
+ #### If Condition (\`if\`)
194
+ - Binary branching
195
+ - Data: \`conditions\` array, \`conditionLogic: "and"|"or"\`
196
+ - Each condition: \`{id, leftValue: "{{nodeId.field}}", operator, rightValue, dataType, range?, expression?}\`
197
+ - Operators (23): equals, not_equals, greater_than, greater_than_or_equal, less_than, less_than_or_equal, contains, not_contains, starts_with, ends_with, matches_regex, is_empty, is_not_empty, is_null, is_not_null, is_true, is_false, in_array, not_in_array, array_contains, array_length, between, custom_expression
198
+ - dataType: auto, string, number, boolean, array, object, date
199
+ - \`between\` operator: add \`range: {min, max}\`. \`custom_expression\`: add \`expression\`
200
+ - Handles: \`"true"\`, \`"false"\`
201
+ - Output: \`{ conditionMet, evaluatedConditions, logicOperator }\`
202
+
203
+ #### Switch (\`switch\`)
204
+ - Multi-path branching
205
+ - Data: \`cases\` array, \`mode: "first"|"all"\`, \`hasDefault: true\`
206
+ - Each case: \`{id: "case_<ts>", label, outputLabel: "case-0", conditions: [...], logicOperator: "AND"|"OR", enabled: true}\`
207
+ - Same condition format as If node
208
+ - Handles: \`"<outputLabel>"\` per case + \`"default"\`
209
+ - Output: \`{ matchedHandles, matchedCaseLabels, hasDefault, mode }\`
210
+
211
+ #### Loop (\`loop\`)
212
+ - Iterates over arrays
213
+ - Data: \`arraySources: ["{{nodeId.field}}"]\`, \`enableFailRoute: false\`
214
+ - During iteration, downstream nodes access: \`{{loopId.currentItem}}\`, \`{{loopId.currentIndex}}\`, \`{{loopId.totalItems}}\`
215
+ - Handles: \`"loop"\` (per item), \`"done"\` (after all), \`"fail"\` (on error if enableFailRoute)
216
+ - Output: \`{ items, totalItems, currentItem, currentIndex }\`
217
+
218
+ #### Wait (\`wait\`)
219
+ - Pauses execution
220
+ - Data: \`waitType: "duration"|"until"\`, \`duration\`, \`durationUnit: "seconds"|"minutes"|"hours"|"days"\`
221
+ - Waits >30s persist to database and auto-resume
222
+
223
+ #### Flow (\`flow\`)
224
+ - Executes another flow as sub-flow
225
+ - Data: \`flowId\`, \`flowName\`, \`waitForCompletion: true\`, \`body: "{}"\` (JSON string, supports \`{{}}\`)
226
+ - Output: \`{ flowId, flowName, runId, waitedForCompletion, status, success, outputs }\`
227
+
228
+ #### Variable (\`variable\`)
229
+ - Manages flow variables
230
+ - **Create**: \`action: "create"\`, \`variables: [{name, type, defaultValue, isList, deduplicate}]\`
231
+ - **Update**: \`action: "update"\`, \`variableName\`, \`operator\`, \`value\` (supports \`{{}}\`)
232
+ - **Delete**: \`action: "delete"\`, \`variableName\`
233
+ - Types: string, number, boolean, object
234
+ - String operators: set, concat, append
235
+ - Number operators: set, add, subtract, multiply, divide
236
+ - List operators (isList: true): set, push, pop, shift, unshift, concat, unique, reverse, sort
237
+ - Variables accessed as \`{{Variables.varName}}\` in config fields
238
+
239
+ #### Review (\`review\`)
240
+ - Human approval gate
241
+ - Data: \`title\`, \`description\`, \`fields: [{id, label, value: "{{nodeId.field}}"}]\`, \`options: [{id: "option_0", label: "Approve", color: "green"}]\`
242
+ - Colors: green, red, blue, yellow, orange, purple, gray
243
+ - Handles: \`"option_0"\`, \`"option_1"\`, etc.
244
+ - Output: \`{ selectedOption, selectedOptionLabel, reviewData: {label: value}, respondedBy, respondedDate }\`
245
+
246
+ #### Page (\`page\`)
247
+ - Public form page, pauses flow until submission
248
+ - Data: \`elements\` array, \`abandonments: [{id, name, delay, delayUnit}]\`, \`pageStyle\`, \`loadingConfig\`
249
+ - Elements: see Form Elements section below
250
+ - Handles: \`"right"\` (submitted), abandonment IDs
251
+ - Output: \`{ submissionData: {"Element Label": value}, submittedDate, status, activeHandle }\`
252
+ - Downstream: \`{{pageId.submissionData.Email}}\`
253
+
254
+ #### Split Test (\`splitTest\`)
255
+ - A/B traffic routing
256
+ - Data: \`variants: [{id: "v_0", label: "Variant A", percentage: 50}, ...]\` (must sum to 100)
257
+ - Handles: variant labels \`"Variant A"\`, \`"Variant B"\`
258
+ - Output: \`{ selectedHandle, selectedLabel, selectedVariantId }\`
259
+
260
+ #### Goal (\`goal\`) / Exit (\`exit\`)
261
+ - Terminal nodes (no output handles)
262
+ - Goal = success outcome, Exit = alternative outcome
263
+ - Data: \`goalName\` / \`exitName\` (for analytics)
264
+
265
+ #### Subflow (\`subflow\`)
266
+ - Visual grouping only — no execution effect
267
+
268
+ #### Note (\`note\`)
269
+ - Canvas annotation — not connected to flow
270
+
271
+ #### Custom Node (\`customNode\`)
272
+ - Uses published custom node definition
273
+ - Data: \`customNodeId\`, \`customVersionId\`, \`onError: "stop"|"continue"\`, plus input values matching input_schema keys
274
+ - Input values support \`{{nodeId.field}}\` templates (resolved before code runs)
275
+ - Code receives: \`inputs.keyName\`, \`secrets.keyName\`, \`fetch()\`
276
+ - Output: keys from output_schema
277
+
278
+ ---
279
+
280
+ ## Form Elements Reference
281
+
282
+ Used in \`page\` nodes' \`elements\` array (this includes pages with \`data.isStartForm: true\` — the legacy \`startForm\` type was removed in the refactor). Each element needs:
283
+
284
+ \`\`\`javascript
285
+ {
286
+ id: crypto.randomUUID(), // unique ID
287
+ type: "shortText", // element type
288
+ label: "Field Name", // display label AND the key in submissionData
289
+ // ...type-specific config
290
+ }
291
+ \`\`\`
292
+
293
+ ### Input Elements (produce submission data)
294
+
295
+ | Type | Description | Key Config |
296
+ |------|-------------|------------|
297
+ | \`shortText\` | Single-line text | \`placeholder\`, \`required\`, \`defaultValue\`, \`helpText\`, \`width\` |
298
+ | \`longText\` | Multi-line textarea | \`placeholder\`, \`required\`, \`defaultValue\`, \`rows: 4\` |
299
+ | \`email\` | Email input | \`placeholder\`, \`required\`, \`defaultValue\` |
300
+ | \`url\` | URL input | \`placeholder\`, \`required\`, \`defaultValue\` |
301
+ | \`number\` | Numeric input | \`placeholder\`, \`required\`, \`min\`, \`max\`, \`step\` |
302
+ | \`date\` | Date picker | \`placeholder\`, \`required\`, \`includeTime: false\` |
303
+ | \`dateOfBirth\` | Day/Month/Year | \`required\` |
304
+ | \`dropdown\` | Select from options | \`required\`, \`options: [{id, label, value}]\`, \`allowMultiple\` |
305
+ | \`multipleChoice\` | Radio/checkbox | \`required\`, \`options: [{id, label, value}]\`, \`allowMultiple\` |
306
+ | \`fileUpload\` | File upload | \`required\`, \`accept\` (MIME), \`maxSize\` (MB), \`maxFiles\` |
307
+ | \`signature\` | Signature pad | \`required\` |
308
+ | \`audioRecorder\` | Audio recording | \`required\`, \`maxDuration: 120\`, \`audioFormat: "webm"\` |
309
+ | \`button\` | Submit/action button | \`buttonText\`, \`buttonColor\`, \`buttonAlign\`, \`buttonAction: "submit"|"link"|"stop"|"restart"\`, \`buttonLink\` |
310
+
311
+ ### Display Elements (no submission data)
312
+
313
+ | Type | Description | Key Config |
314
+ |------|-------------|------------|
315
+ | \`textBlock\` | Formatted text/markdown | \`content\` |
316
+ | \`image\` | Display image | \`src\` (URL or \`{{}}\`), \`alt\`, \`maxHeight\` |
317
+ | \`file\` | Downloadable file | \`src\`, \`fileName\` |
318
+ | \`video\` | Embedded video | \`src\`, \`autoplay\` |
319
+ | \`embed\` | External content | \`url\`, \`height\` |
320
+
321
+ ### Layout: \`columns\` — \`{columns: [], gap: "1rem"}\`
322
+ ### Width: \`"full"\` | \`"twoThirds"\` | \`"half"\` | \`"third"\`
323
+
324
+ ### Form Styling
325
+
326
+ \`\`\`javascript
327
+ // pageStyle (on node.data)
328
+ { backgroundColor: '#ffffff', backgroundImage: '', maxWidth: '640px', padding: '2rem',
329
+ showProgressBar: true, submitButtonText: 'Continue', submitButtonColor: '#3b82f6' }
330
+
331
+ // loadingConfig (Page node only)
332
+ { enabled: true, text: 'Processing...', subtext: 'Please wait', animation: 'spinner', backgroundColor: '#ffffff' }
333
+ \`\`\`
334
+
335
+ ---
336
+
337
+ ## Custom Node Schemas
338
+
339
+ ### Input Schema
340
+ \`\`\`json
341
+ [{
342
+ "key": "fieldName",
343
+ "label": "Display Label",
344
+ "type": "string | number | boolean | object | array | select | code | textarea",
345
+ "required": true,
346
+ "default": "",
347
+ "description": "Help text in editor",
348
+ "options": [{ "label": "Option", "value": "val" }],
349
+ "condition": { "field": "otherKey", "value": "someValue", "operator": "equals" }
350
+ }]
351
+ \`\`\`
352
+
353
+ ### Output Schema
354
+ \`\`\`json
355
+ [{ "key": "fieldName", "label": "Display Label", "type": "string", "description": "What this outputs" }]
356
+ \`\`\`
357
+
358
+ ---
359
+
360
+ ## Concrete Examples — Actual Tool Calls
361
+
362
+ ### Example 1: Build a Webhook → If → HTTP Request flow
363
+
364
+ **Step 1: Create the flow**
365
+ \`\`\`
366
+ create_flow({ name: "Order Processor", description: "Process incoming orders", trigger_type: "trigger" })
367
+ → Returns: { id: "flow-abc-123" }
368
+ \`\`\`
369
+
370
+ **Step 2: Get the flow to find the trigger node ID**
371
+ \`\`\`
372
+ get_flow({ flow_id: "flow-abc-123" })
373
+ → Returns flow with nodes: [{ id: "trigger-node-id", type: "trigger", ... }]
374
+ \`\`\`
375
+
376
+ **Step 3: Add all nodes + edges in one call using temp_id**
377
+ \`\`\`
378
+ add_nodes({
379
+ flow_id: "flow-abc-123",
380
+ nodes: [
381
+ {
382
+ type: "if",
383
+ temp_id: "my-if",
384
+ data: {
385
+ label: "Check Order Value",
386
+ conditions: [{
387
+ id: "cond-1",
388
+ leftValue: "{{trigger-node-id.body.total}}",
389
+ operator: "greater_than",
390
+ rightValue: "100",
391
+ dataType: "number"
392
+ }],
393
+ conditionLogic: "and"
394
+ }
395
+ },
396
+ {
397
+ type: "httpRequest",
398
+ temp_id: "my-api",
399
+ data: {
400
+ label: "Send to Fulfillment",
401
+ url: "https://api.example.com/fulfill",
402
+ method: "POST",
403
+ bodyType: "json",
404
+ body: "{\\"orderId\\": \\"{{trigger-node-id.body.id}}\\", \\"total\\": \\"{{trigger-node-id.body.total}}\\"}",
405
+ headers: [{ key: "Authorization", value: "Bearer {{Variables.apiKey}}", enabled: true }]
406
+ }
407
+ },
408
+ {
409
+ type: "goal",
410
+ temp_id: "my-goal",
411
+ data: { label: "Fulfilled", goalName: "Order Fulfilled" }
412
+ },
413
+ {
414
+ type: "exit",
415
+ temp_id: "my-exit",
416
+ data: { label: "Low Value", exitName: "Below Threshold" }
417
+ }
418
+ ],
419
+ edges: [
420
+ { source: "trigger-node-id", target: "my-if" },
421
+ { source: "my-if", target: "my-api", source_handle: "true" },
422
+ { source: "my-if", target: "my-exit", source_handle: "false" },
423
+ { source: "my-api", target: "my-goal" }
424
+ ]
425
+ })
426
+ \`\`\`
427
+
428
+ ### Example 2: Page node with form elements
429
+
430
+ \`\`\`
431
+ add_nodes({
432
+ flow_id: "flow-abc-123",
433
+ nodes: [{
434
+ type: "page",
435
+ temp_id: "my-page",
436
+ data: {
437
+ label: "Contact Form",
438
+ elements: [
439
+ {
440
+ id: "elem-1",
441
+ type: "textBlock",
442
+ content: "Please fill in your details below"
443
+ },
444
+ {
445
+ id: "elem-2",
446
+ type: "shortText",
447
+ label: "Full Name",
448
+ placeholder: "Enter your name",
449
+ required: true,
450
+ width: "half"
451
+ },
452
+ {
453
+ id: "elem-3",
454
+ type: "email",
455
+ label: "Email",
456
+ placeholder: "your@email.com",
457
+ required: true,
458
+ width: "half"
459
+ },
460
+ {
461
+ id: "elem-4",
462
+ type: "dropdown",
463
+ label: "Department",
464
+ required: true,
465
+ options: [
466
+ { id: "opt-1", label: "Sales", value: "sales" },
467
+ { id: "opt-2", label: "Support", value: "support" },
468
+ { id: "opt-3", label: "Billing", value: "billing" }
469
+ ],
470
+ width: "full"
471
+ },
472
+ {
473
+ id: "elem-5",
474
+ type: "longText",
475
+ label: "Message",
476
+ placeholder: "How can we help?",
477
+ required: false,
478
+ rows: 4,
479
+ width: "full"
480
+ }
481
+ ],
482
+ pageStyle: {
483
+ backgroundColor: "#f9fafb",
484
+ maxWidth: "640px",
485
+ padding: "2rem",
486
+ showProgressBar: false,
487
+ submitButtonText: "Submit",
488
+ submitButtonColor: "#3b82f6"
489
+ }
490
+ }
491
+ }],
492
+ edges: [{ source: "previous-node-id", target: "my-page" }]
493
+ })
494
+ \`\`\`
495
+
496
+ After submission, downstream nodes access: \`{{my-page-real-id.submissionData.Full Name}}\`, \`{{my-page-real-id.submissionData.Email}}\`, \`{{my-page-real-id.submissionData.Department}}\`, \`{{my-page-real-id.submissionData.Message}}\`
497
+
498
+ ### Example 3: Switch with multiple cases
499
+
500
+ \`\`\`
501
+ update_node({
502
+ flow_id: "flow-abc-123",
503
+ node_id: "switch-node-id",
504
+ data: {
505
+ label: "Route by Department",
506
+ mode: "first",
507
+ hasDefault: true,
508
+ cases: [
509
+ {
510
+ id: "case_1",
511
+ label: "Sales",
512
+ outputLabel: "case-0",
513
+ conditions: [{
514
+ id: "c1",
515
+ leftValue: "{{page-node-id.submissionData.Department}}",
516
+ operator: "equals",
517
+ rightValue: "sales",
518
+ dataType: "string"
519
+ }],
520
+ logicOperator: "AND",
521
+ enabled: true
522
+ },
523
+ {
524
+ id: "case_2",
525
+ label: "Support",
526
+ outputLabel: "case-1",
527
+ conditions: [{
528
+ id: "c2",
529
+ leftValue: "{{page-node-id.submissionData.Department}}",
530
+ operator: "equals",
531
+ rightValue: "support",
532
+ dataType: "string"
533
+ }],
534
+ logicOperator: "AND",
535
+ enabled: true
536
+ }
537
+ ]
538
+ }
539
+ })
540
+
541
+ // Then connect edges:
542
+ connect_nodes({ flow_id: "...", source: "switch-node-id", target: "sales-handler-id", source_handle: "case-0" })
543
+ connect_nodes({ flow_id: "...", source: "switch-node-id", target: "support-handler-id", source_handle: "case-1" })
544
+ connect_nodes({ flow_id: "...", source: "switch-node-id", target: "default-handler-id", source_handle: "default" })
545
+ \`\`\`
546
+
547
+ ### Example 4: Code node accessing upstream data
548
+
549
+ \`\`\`
550
+ update_node({
551
+ flow_id: "flow-abc-123",
552
+ node_id: "code-node-id",
553
+ data: {
554
+ label: "Process Data",
555
+ mode: "runOnce",
556
+ code: \`
557
+ // Get the HTTP response from upstream node
558
+ const apiData = $("http-request-node-id");
559
+
560
+ // Get the trigger input
561
+ const trigger = $("trigger-node-id");
562
+
563
+ // Process the data
564
+ const filtered = apiData.body.items.filter(item => item.active);
565
+
566
+ // MUST return an object
567
+ return {
568
+ items: filtered,
569
+ count: filtered.length,
570
+ requestedBy: trigger.body.userId
571
+ };
572
+ \`
573
+ }
574
+ })
575
+ \`\`\`
576
+
577
+ Downstream nodes access: \`{{code-node-id.items}}\`, \`{{code-node-id.count}}\`, \`{{code-node-id.requestedBy}}\`
578
+
579
+ ### Example 5: Loop with array processing
580
+
581
+ \`\`\`
582
+ add_nodes({
583
+ flow_id: "flow-abc-123",
584
+ nodes: [
585
+ {
586
+ type: "loop",
587
+ temp_id: "my-loop",
588
+ data: {
589
+ label: "Process Each User",
590
+ arraySources: ["{{http-node-id.body.users}}"],
591
+ enableFailRoute: false
592
+ }
593
+ },
594
+ {
595
+ type: "httpRequest",
596
+ temp_id: "loop-api",
597
+ data: {
598
+ label: "Update User",
599
+ url: "https://api.example.com/users/{{my-loop.currentItem.id}}",
600
+ method: "PUT",
601
+ bodyType: "json",
602
+ body: "{\\"status\\": \\"processed\\"}"
603
+ }
604
+ },
605
+ {
606
+ type: "goal",
607
+ temp_id: "done-goal",
608
+ data: { label: "All Done", goalName: "Batch Complete" }
609
+ }
610
+ ],
611
+ edges: [
612
+ { source: "http-node-id", target: "my-loop" },
613
+ { source: "my-loop", target: "loop-api", source_handle: "loop" },
614
+ { source: "my-loop", target: "done-goal", source_handle: "done" }
615
+ ]
616
+ })
617
+ \`\`\`
618
+
619
+ Note: Inside the loop body, access current item via \`{{loop-real-id.currentItem}}\` and \`{{loop-real-id.currentIndex}}\`.
620
+
621
+ ### Example 6: Review node with context fields
622
+
623
+ \`\`\`
624
+ add_nodes({
625
+ flow_id: "flow-abc-123",
626
+ nodes: [{
627
+ type: "review",
628
+ temp_id: "my-review",
629
+ data: {
630
+ label: "Manager Approval",
631
+ title: "Expense Approval Required",
632
+ description: "Please review this expense report",
633
+ fields: [
634
+ { id: "f1", label: "Employee", value: "{{trigger-id.body.employeeName}}" },
635
+ { id: "f2", label: "Amount", value: "{{trigger-id.body.amount}}" },
636
+ { id: "f3", label: "Category", value: "{{trigger-id.body.category}}" }
637
+ ],
638
+ options: [
639
+ { id: "option_0", label: "Approve", color: "green" },
640
+ { id: "option_1", label: "Reject", color: "red" },
641
+ { id: "option_2", label: "Request Info", color: "yellow" }
642
+ ]
643
+ }
644
+ }],
645
+ edges: [
646
+ { source: "previous-node-id", target: "my-review" }
647
+ ]
648
+ })
649
+
650
+ // Connect each option to a different path:
651
+ connect_nodes({ flow_id: "...", source: "review-real-id", target: "approve-node", source_handle: "option_0" })
652
+ connect_nodes({ flow_id: "...", source: "review-real-id", target: "reject-node", source_handle: "option_1" })
653
+ connect_nodes({ flow_id: "...", source: "review-real-id", target: "info-node", source_handle: "option_2" })
654
+ \`\`\`
655
+
656
+ ### Example 7: Variables — create, update, and reference
657
+
658
+ \`\`\`
659
+ // Create flow variables
660
+ set_variable({ flow_id: "...", name: "totalProcessed", type: "number", default_value: "0" })
661
+ set_variable({ flow_id: "...", name: "results", type: "string", default_value: "", is_list: true })
662
+
663
+ // Add a Variable node to update during flow
664
+ add_nodes({
665
+ flow_id: "...",
666
+ nodes: [{
667
+ type: "variable",
668
+ temp_id: "my-var",
669
+ data: {
670
+ label: "Increment Counter",
671
+ action: "update",
672
+ variableName: "totalProcessed",
673
+ operator: "add",
674
+ value: "1"
675
+ }
676
+ }]
677
+ })
678
+
679
+ // Reference variables in other nodes via {{Variables.totalProcessed}}
680
+ \`\`\`
681
+
682
+ ### Example 8: update_flow — saving full flow state
683
+
684
+ \`\`\`
685
+ update_flow({
686
+ flow_id: "flow-abc-123",
687
+ name: "My Flow",
688
+ description: "Updated description",
689
+ nodes: [...], // Full nodes array from get_flow
690
+ edges: [...], // Full edges array from get_flow
691
+ end_conditions: {
692
+ goals: [{ id: "g1", label: "Converted", nodeId: "goal-node-id" }],
693
+ exits: [{ id: "e1", label: "Dropped Off", nodeId: "exit-node-id" }]
694
+ }
695
+ })
696
+ \`\`\`
697
+
698
+ ---
699
+
700
+ ## Recommended Workflow Tools
701
+
702
+ - \`preview_flow\` — dry-run add_nodes with full validation, no save
703
+ - \`validate_flow\` — 7-phase validation returning structured diagnostics with node_id + path
704
+ - \`describe_flow\` — compact graph summary (token-efficient vs get_flow)
705
+
706
+ All three are additive and backward compatible. Use preview_flow → validate_flow → test_flow in that order before publish.
707
+
708
+ ## Auto-Heal
709
+
710
+ \`add_nodes\` and \`update_node\` auto-inject missing UUIDs on nested items (conditions, cases, mappings, options, elements, abandonments, variants, review fields) and normalize method/bodyType casing. The response's \`_healed\` array lists what was patched — use it to fix your authoring patterns.
711
+
712
+ ---
713
+
714
+ ## Building Flows Step-by-Step
715
+
716
+ 1. \`create_flow(name, description, trigger_type)\` — creates flow with trigger node
717
+ 2. \`get_flow(flow_id)\` — get trigger node ID
718
+ 3. \`add_nodes(flow_id, nodes, edges)\` — add processing nodes with \`temp_id\` + edges
719
+ 4. \`update_node(flow_id, node_id, data)\` — configure conditions, mappings, forms
720
+ 5. \`set_variable(flow_id, name, type, defaultValue)\` — set up variables if needed
721
+ 6. \`validate_flow(flow_id)\` — check for errors
722
+ 7. \`test_flow(flow_id, input_data)\` — test the flow, wait for completion, get all node outputs
723
+ 8. \`publish_flow(flow_id)\` — publish to production
724
+ 9. \`run_flow(flow_id, input_data)\` — trigger a production run
725
+
726
+ ---
727
+
728
+ ## Key Rules
729
+
730
+ 1. **Every flow needs exactly one trigger node** — auto-created by \`create_flow\`
731
+ 2. **Use \`temp_id\` in \`add_nodes\`** to reference new nodes in edges before IDs are assigned
732
+ 3. **Config fields use \`{{nodeId.field}}\`** — Code nodes use \`$("nodeId")\`
733
+ 4. **Custom nodes use \`inputs.keyName\`** — NOT \`$("nodeId")\`
734
+ 5. **Form submission data keyed by LABEL** — \`{{pageId.submissionData.Email}}\` not element UUID
735
+ 6. **Branching nodes need \`source_handle\`** — if (true/false), switch (outputLabel/default), loop (loop/done/fail), review (option_N), page (right), splitTest (variant labels)
736
+ 7. **Always \`validate_flow\` before \`publish_flow\`**
737
+ 8. **Variables accessed as \`{{Variables.varName}}\`**
738
+ 9. **Code must \`return { key: value }\`** — returned keys become node output fields
739
+ 10. **Use \`get_node_type_info(type)\`** for detailed guides on any specific node type
740
+ `.trim();
741
+ //# sourceMappingURL=prompts.js.map