@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.
- package/README.md +13 -0
- package/dist/bin/install.js +53 -0
- package/dist/bin/install.js.map +1 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.js +20 -2
- package/dist/client.js.map +1 -1
- package/dist/healing.d.ts +9 -0
- package/dist/healing.js +104 -0
- package/dist/healing.js.map +1 -0
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/instructions.d.ts +6 -0
- package/dist/instructions.js +149 -0
- package/dist/instructions.js.map +1 -0
- package/dist/node-defaults.js +395 -46
- package/dist/node-defaults.js.map +1 -1
- package/dist/prompts.d.ts +2 -0
- package/dist/prompts.js +741 -0
- package/dist/prompts.js.map +1 -0
- package/dist/tools/custom-nodes.js +14 -9
- package/dist/tools/custom-nodes.js.map +1 -1
- package/dist/tools/flows.js +36 -35
- package/dist/tools/flows.js.map +1 -1
- package/dist/tools/nodes.js +17 -7
- package/dist/tools/nodes.js.map +1 -1
- package/dist/tools/preview.d.ts +3 -0
- package/dist/tools/preview.js +85 -0
- package/dist/tools/preview.js.map +1 -0
- package/dist/tools/reference.js +8 -5
- package/dist/tools/reference.js.map +1 -1
- package/dist/tools/runs.js +112 -1
- package/dist/tools/runs.js.map +1 -1
- package/dist/tools/variables.js +1 -1
- package/dist/tools/variables.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/validation/enums.d.ts +20 -0
- package/dist/validation/enums.js +36 -0
- package/dist/validation/enums.js.map +1 -0
- package/dist/validation/handles.d.ts +2 -0
- package/dist/validation/handles.js +88 -0
- package/dist/validation/handles.js.map +1 -0
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.js +47 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/nested-ids.d.ts +2 -0
- package/dist/validation/nested-ids.js +55 -0
- package/dist/validation/nested-ids.js.map +1 -0
- package/dist/validation/reachability.d.ts +2 -0
- package/dist/validation/reachability.js +62 -0
- package/dist/validation/reachability.js.map +1 -0
- package/dist/validation/references.d.ts +2 -0
- package/dist/validation/references.js +107 -0
- package/dist/validation/references.js.map +1 -0
- package/dist/validation/shape-rules.d.ts +7 -0
- package/dist/validation/shape-rules.js +284 -0
- package/dist/validation/shape-rules.js.map +1 -0
- package/dist/validation/shape.d.ts +2 -0
- package/dist/validation/shape.js +47 -0
- package/dist/validation/shape.js.map +1 -0
- package/dist/validation/structure.d.ts +2 -0
- package/dist/validation/structure.js +137 -0
- package/dist/validation/structure.js.map +1 -0
- package/dist/validation/syntax.d.ts +2 -0
- package/dist/validation/syntax.js +69 -0
- package/dist/validation/syntax.js.map +1 -0
- package/dist/validation/types.d.ts +49 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/types.js.map +1 -0
- package/package.json +15 -4
- package/skill/SKILL.md +116 -0
- package/skill/anti-patterns.md +207 -0
- package/skill/node-cheatsheet.md +37 -0
- package/skill/recipes.md +308 -0
- package/skill/version.txt +1 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const DOLLAR_RE = /\$\(\s*["']/;
|
|
2
|
+
const TEMPLATE_RE = /\{\{\s*[^}\s]+\s*\}\}/;
|
|
3
|
+
function scanStrings(obj, skipKeys, visitor, path = 'data') {
|
|
4
|
+
if (obj == null)
|
|
5
|
+
return;
|
|
6
|
+
if (typeof obj === 'string') {
|
|
7
|
+
visitor(obj, path);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(obj)) {
|
|
11
|
+
obj.forEach((v, i) => scanStrings(v, skipKeys, visitor, `${path}[${i}]`));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (typeof obj === 'object') {
|
|
15
|
+
for (const k of Object.keys(obj)) {
|
|
16
|
+
if (skipKeys.has(k))
|
|
17
|
+
continue;
|
|
18
|
+
scanStrings(obj[k], skipKeys, visitor, `${path}.${k}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function checkSyntax(flow) {
|
|
23
|
+
const out = [];
|
|
24
|
+
for (const node of flow.nodes || []) {
|
|
25
|
+
const data = node.data || {};
|
|
26
|
+
if (node.type === 'code') {
|
|
27
|
+
const code = data.code;
|
|
28
|
+
if (typeof code === 'string' && TEMPLATE_RE.test(code)) {
|
|
29
|
+
out.push({
|
|
30
|
+
severity: 'warning',
|
|
31
|
+
code: 'template_in_code',
|
|
32
|
+
node_id: node.id,
|
|
33
|
+
path: 'data.code',
|
|
34
|
+
message: 'Code body contains {{...}} templates. Code nodes do NOT expand templates — use $("nodeId") instead.',
|
|
35
|
+
fix_hint: 'Replace {{nodeId.field}} with $("nodeId").field in the code.'
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// Skip scanning the code field itself for $() — $() IS correct there
|
|
39
|
+
scanStrings(data, new Set(['code']), (s, p) => {
|
|
40
|
+
if (DOLLAR_RE.test(s)) {
|
|
41
|
+
out.push({
|
|
42
|
+
severity: 'error',
|
|
43
|
+
code: 'dollar_in_config',
|
|
44
|
+
node_id: node.id,
|
|
45
|
+
path: p,
|
|
46
|
+
message: '$("nodeId") syntax is only valid inside Code node code — not in config fields.',
|
|
47
|
+
fix_hint: 'Use {{nodeId.field}} template syntax in config fields.'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
scanStrings(data, new Set(), (s, p) => {
|
|
54
|
+
if (DOLLAR_RE.test(s)) {
|
|
55
|
+
out.push({
|
|
56
|
+
severity: 'error',
|
|
57
|
+
code: 'dollar_in_config',
|
|
58
|
+
node_id: node.id,
|
|
59
|
+
path: p,
|
|
60
|
+
message: '$("nodeId") syntax is only valid inside Code node code — not in config fields.',
|
|
61
|
+
fix_hint: 'Use {{nodeId.field}} template syntax in config fields.'
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|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,EAAE;wBAChB,IAAI,EAAE,CAAC;wBACP,OAAO,EAAE,gFAAgF;wBACzF,QAAQ,EAAE,wDAAwD;qBACnE,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** A single validation finding with enough detail to locate and fix it. */
|
|
2
|
+
export interface Diagnostic {
|
|
3
|
+
severity: 'error' | 'warning';
|
|
4
|
+
code: string;
|
|
5
|
+
message: string;
|
|
6
|
+
node_id?: string;
|
|
7
|
+
edge_id?: string;
|
|
8
|
+
path?: string;
|
|
9
|
+
fix_hint?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ValidationReport {
|
|
12
|
+
valid: boolean;
|
|
13
|
+
errors: Diagnostic[];
|
|
14
|
+
warnings: Diagnostic[];
|
|
15
|
+
stats: {
|
|
16
|
+
node_count: number;
|
|
17
|
+
edge_count: number;
|
|
18
|
+
errors_by_code: Record<string, number>;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** A flow-like object — we only rely on the shape used by the server. */
|
|
22
|
+
export interface ValidatedFlow {
|
|
23
|
+
id?: string;
|
|
24
|
+
name?: string;
|
|
25
|
+
nodes: Array<{
|
|
26
|
+
id: string;
|
|
27
|
+
type: string;
|
|
28
|
+
position?: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
32
|
+
data: Record<string, any>;
|
|
33
|
+
}>;
|
|
34
|
+
edges: Array<{
|
|
35
|
+
id: string;
|
|
36
|
+
source: string;
|
|
37
|
+
target: string;
|
|
38
|
+
sourceHandle?: string | null;
|
|
39
|
+
targetHandle?: string | null;
|
|
40
|
+
}>;
|
|
41
|
+
variables?: Array<{
|
|
42
|
+
id?: string;
|
|
43
|
+
name: string;
|
|
44
|
+
type: string;
|
|
45
|
+
isList?: boolean;
|
|
46
|
+
}>;
|
|
47
|
+
}
|
|
48
|
+
/** Signature every validation phase implements. */
|
|
49
|
+
export type ValidationPhase = (flow: ValidatedFlow) => Diagnostic[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/validation/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@addai/flows-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "MCP server for +AI Flows - manage flows, nodes, runs, and more via AI assistants",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "tsc",
|
|
14
14
|
"dev": "tsc --watch",
|
|
15
|
-
"start": "node dist/index.js"
|
|
15
|
+
"start": "node dist/index.js",
|
|
16
|
+
"test": "tsc -p tsconfig.test.json && node --test 'dist-test/test/**/*.test.js'",
|
|
17
|
+
"gen:cheatsheet": "tsc -p tsconfig.test.json --outDir dist-test && node dist-test/scripts/gen-cheatsheet.js"
|
|
16
18
|
},
|
|
17
19
|
"dependencies": {
|
|
18
20
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
@@ -25,7 +27,16 @@
|
|
|
25
27
|
"engines": {
|
|
26
28
|
"node": ">=18"
|
|
27
29
|
},
|
|
28
|
-
"keywords": [
|
|
30
|
+
"keywords": [
|
|
31
|
+
"mcp",
|
|
32
|
+
"ai-flows",
|
|
33
|
+
"addai",
|
|
34
|
+
"claude",
|
|
35
|
+
"model-context-protocol"
|
|
36
|
+
],
|
|
29
37
|
"license": "MIT",
|
|
30
|
-
"files": [
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"skill"
|
|
41
|
+
]
|
|
31
42
|
}
|
package/skill/SKILL.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: building-aiflows
|
|
3
|
+
description: Use when creating, modifying, or debugging +Ai Flows via the addai-flows MCP — enforces the discover→study→build→preview→validate→test workflow and prevents silent flow breakage
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Building +Ai Flows with the MCP
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
Any time you're about to call `mcp__addai-flows__create_flow`, `add_nodes`, `update_node`, `update_flow`, or `publish_flow`. Also use when debugging a flow that isn't producing the output you expect.
|
|
11
|
+
|
|
12
|
+
**If the user says "build me a flow that..." or "add a node for..." or "why is my flow broken", you are in scope.**
|
|
13
|
+
|
|
14
|
+
## The rigid workflow (do not skip steps)
|
|
15
|
+
|
|
16
|
+
Create a TodoWrite todo per numbered step below, complete in order, mark each done as you finish it.
|
|
17
|
+
|
|
18
|
+
### 1. Discover (once per session)
|
|
19
|
+
Call `list_node_types()` once. Scan the returned `types` array to see what's available. Note which categories are relevant to the flow you're building.
|
|
20
|
+
|
|
21
|
+
### 2. Study each node type you'll use
|
|
22
|
+
For EVERY unique node type you plan to add, call `get_node_type_info(node_type)` FIRST. Read carefully:
|
|
23
|
+
- `defaultData` — the exact fields you need to set
|
|
24
|
+
- `handles.source` — for branching nodes, the allowed `source_handle` values
|
|
25
|
+
- `outputShape` — the fields you can reference downstream via `{{nodeId.field}}`
|
|
26
|
+
- `tips` — gotchas the registry has seen before
|
|
27
|
+
|
|
28
|
+
If it's a `page` node, also call `list_page_elements` and `get_page_element_info(element_type)` for each form element you'll use.
|
|
29
|
+
|
|
30
|
+
### 3. Scaffold the flow
|
|
31
|
+
```
|
|
32
|
+
create_flow({ name, description, trigger_type }) → { id }
|
|
33
|
+
get_flow({ flow_id }) → capture the trigger node's id
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 4. Preview before you add
|
|
37
|
+
For the first batch of nodes, call `preview_flow(flow_id, nodes, edges)` — same signature as `add_nodes` but no save. Read the `validation` report. Fix any errors BEFORE calling `add_nodes`. Zero canvas churn while you iterate.
|
|
38
|
+
|
|
39
|
+
### 5. Add in small chunks
|
|
40
|
+
Use `add_nodes(flow_id, nodes, edges)` with `temp_id` for cross-references. **Every nested item needs an id** (the server auto-heals, but set them explicitly when you can):
|
|
41
|
+
- `if.conditions[].id`
|
|
42
|
+
- `switch.cases[].id` AND `switch.cases[].conditions[].id`
|
|
43
|
+
- `map.mappings[].id`
|
|
44
|
+
- `review.options[].id` AND `review.fields[].id`
|
|
45
|
+
- `page.elements[].id` AND `page.abandonments[].id`
|
|
46
|
+
- `splitTest.variants[].id`
|
|
47
|
+
|
|
48
|
+
Use the temp_id → real_id mapping from the response when adding more nodes that reference these.
|
|
49
|
+
|
|
50
|
+
### 6. Wire branching edges with correct handles
|
|
51
|
+
For any edge from a branching node, `source_handle` is **mandatory**:
|
|
52
|
+
|
|
53
|
+
| Type | Required source_handle values |
|
|
54
|
+
|------|-------------------------------|
|
|
55
|
+
| `if` | `"true"` or `"false"` |
|
|
56
|
+
| `switch` | each case's `outputLabel`, plus `"default"` if `hasDefault` |
|
|
57
|
+
| `loop` | `"loop"` (per iteration), `"done"` (after), `"fail"` (only if enableFailRoute) |
|
|
58
|
+
| `review` | option ids: `"option_0"`, `"option_1"`, ... |
|
|
59
|
+
| `page` | `"right"` (submission) or an abandonment id |
|
|
60
|
+
| `splitTest` | variant label strings: `"Variant A"`, `"Variant B"`, ... |
|
|
61
|
+
|
|
62
|
+
### 7. Validate
|
|
63
|
+
Call `validate_flow(flow_id)`. Read EVERY diagnostic. Fix every `severity: "error"` entry before moving on — each includes `node_id` and `path` pointing exactly at what to fix. Warnings are worth reading but not blocking.
|
|
64
|
+
|
|
65
|
+
### 8. Describe (sanity check)
|
|
66
|
+
Call `describe_flow(flow_id)` to see the graph shape in compact form. Confirm the trigger, node set, and edges with handles are what you intended.
|
|
67
|
+
|
|
68
|
+
### 9. Test
|
|
69
|
+
Call `test_flow(flow_id, input_data)` with a realistic payload matching the trigger's expected input. The tool polls until the run completes and returns every node's output.
|
|
70
|
+
|
|
71
|
+
Read each node's output:
|
|
72
|
+
- Did the expected number of nodes run?
|
|
73
|
+
- Does each node's output match its `outputShape` from step 2?
|
|
74
|
+
- If a node failed, its output contains an `error` field — use that + the node's config to diagnose.
|
|
75
|
+
|
|
76
|
+
### 10. Debug loop (if test fails)
|
|
77
|
+
- Failed node's output → compare against its `outputShape`
|
|
78
|
+
- Trace variable references: for each `{{nodeId.path}}`, confirm the upstream node ran and produced that path
|
|
79
|
+
- Fix with `update_node(flow_id, node_id, data)` — data is merged, not replaced
|
|
80
|
+
- Re-run step 7 (validate) then step 9 (test). Never skip straight back to publish.
|
|
81
|
+
|
|
82
|
+
### 11. Publish
|
|
83
|
+
Only after step 9 returns `status: "completed"` with every node succeeding, call `publish_flow(flow_id)`.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Red-flag thoughts (stop and course-correct)
|
|
88
|
+
|
|
89
|
+
| Thought | Reality |
|
|
90
|
+
|---------|---------|
|
|
91
|
+
| "I know this node type, skip `get_node_type_info`" | The registry has required fields and handle names you don't remember exactly. Call it. |
|
|
92
|
+
| "Simple flow, skip `validate_flow`" | Simple flows have silent handle mismatches and missing IDs. Validate every time. |
|
|
93
|
+
| "Tests take too long, user can test" | You own correctness. Test before claiming done. |
|
|
94
|
+
| "I'll use `{{trigger.body.x}}` in this code node, it's cleaner" | Code sandboxes don't expand templates. You'll get the literal string. Use `$("nodeId")`. |
|
|
95
|
+
| "preview_flow is redundant with add_nodes" | Preview catches errors without churning the canvas. Use it for the first batch at minimum. |
|
|
96
|
+
| "I'll fix the warnings later" | Warnings often point at real bugs (unknown variable, unreachable goal). Read them. |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Three-system variable cheat sheet
|
|
101
|
+
|
|
102
|
+
| Where | Syntax | Example |
|
|
103
|
+
|-------|--------|---------|
|
|
104
|
+
| **Config fields** (URL, body, headers, conditions, element defaults) | `{{nodeId.field}}` or `{{Variables.varName}}` | `url: "https://api.x/{{abc-123.body.id}}"` |
|
|
105
|
+
| **Code node `code`** | `$("nodeId")` — returns that node's full output object | `const t = $("abc-123"); return { id: t.body.id }` |
|
|
106
|
+
| **Custom node code** | `inputs.keyName` (pre-resolved), `secrets.keyName` | `const key = secrets.api_key` |
|
|
107
|
+
|
|
108
|
+
**Never mix:** `$()` in a config field is an error. `{{}}` in code is a warning (it's a literal string, won't resolve).
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## See also
|
|
113
|
+
|
|
114
|
+
- `recipes.md` — 8 copy-paste working patterns
|
|
115
|
+
- `anti-patterns.md` — the specific wrong/right examples for the four failure modes
|
|
116
|
+
- `node-cheatsheet.md` — one-row-per-type quick reference
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Anti-Patterns — Four Failure Modes
|
|
2
|
+
|
|
3
|
+
For each mode: a wrong example, why it breaks, the correct version.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Wrong config shape
|
|
8
|
+
|
|
9
|
+
**Wrong:**
|
|
10
|
+
```
|
|
11
|
+
add_nodes({
|
|
12
|
+
flow_id: "...",
|
|
13
|
+
nodes: [{
|
|
14
|
+
type: "httpRequest",
|
|
15
|
+
data: {
|
|
16
|
+
url: "https://api.example.com/data",
|
|
17
|
+
method: "get", // ← lowercase — will be healed but illegal if healing fails
|
|
18
|
+
bodyType: "JSON", // ← uppercase — illegal
|
|
19
|
+
body: "not json", // ← invalid JSON when bodyType is "json"
|
|
20
|
+
authentication: { type: "Bearer", token: "x" } // ← "Bearer" not in enum
|
|
21
|
+
}
|
|
22
|
+
}]
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Why it breaks:** the enum values `method`, `bodyType`, `authentication.type` are case-sensitive and constrained. `validate_flow` catches all three. The body will silently stringify "not json" and the downstream API call will fail.
|
|
27
|
+
|
|
28
|
+
**Right:**
|
|
29
|
+
```
|
|
30
|
+
// Step 2 of workflow: study first
|
|
31
|
+
get_node_type_info("httpRequest") // See exact enum values
|
|
32
|
+
|
|
33
|
+
// Step 5: correct shape
|
|
34
|
+
add_nodes({
|
|
35
|
+
flow_id: "...",
|
|
36
|
+
nodes: [{
|
|
37
|
+
type: "httpRequest",
|
|
38
|
+
data: {
|
|
39
|
+
url: "https://api.example.com/data",
|
|
40
|
+
method: "GET",
|
|
41
|
+
bodyType: "none",
|
|
42
|
+
authentication: { type: "bearer", token: "{{Variables.apiKey}}" }
|
|
43
|
+
}
|
|
44
|
+
}]
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 2. Missing IDs on nested items
|
|
51
|
+
|
|
52
|
+
**Wrong:**
|
|
53
|
+
```
|
|
54
|
+
add_nodes({
|
|
55
|
+
flow_id: "...",
|
|
56
|
+
nodes: [{
|
|
57
|
+
type: "if",
|
|
58
|
+
data: {
|
|
59
|
+
conditions: [
|
|
60
|
+
{ leftValue: "{{trigger.body.status}}", operator: "equals", rightValue: "active" }
|
|
61
|
+
// ← no id — UI evaluation order becomes non-deterministic, editor breaks
|
|
62
|
+
],
|
|
63
|
+
conditionLogic: "and"
|
|
64
|
+
}
|
|
65
|
+
}]
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Why it breaks:** conditions without `id` confuse the evaluation engine and the canvas editor can't render them. The server auto-heals now, but you'll see the `_healed` entry in the response — that's a hint your caller pattern is wrong.
|
|
70
|
+
|
|
71
|
+
**Right:**
|
|
72
|
+
```
|
|
73
|
+
add_nodes({
|
|
74
|
+
flow_id: "...",
|
|
75
|
+
nodes: [{
|
|
76
|
+
type: "if",
|
|
77
|
+
data: {
|
|
78
|
+
conditions: [{
|
|
79
|
+
id: crypto.randomUUID(),
|
|
80
|
+
leftValue: "{{trigger.body.status}}",
|
|
81
|
+
operator: "equals",
|
|
82
|
+
rightValue: "active",
|
|
83
|
+
dataType: "string"
|
|
84
|
+
}],
|
|
85
|
+
conditionLogic: "and"
|
|
86
|
+
}
|
|
87
|
+
}]
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Every nested item — conditions, cases (+ their conditions), mappings, options, elements, abandonments, variants, fields — needs an explicit `id`.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 3. Broken edge handles
|
|
96
|
+
|
|
97
|
+
**Wrong:**
|
|
98
|
+
```
|
|
99
|
+
add_nodes({
|
|
100
|
+
flow_id: "...",
|
|
101
|
+
nodes: [
|
|
102
|
+
{ type: "if", temp_id: "check" },
|
|
103
|
+
{ type: "goal", temp_id: "ok" },
|
|
104
|
+
{ type: "exit", temp_id: "fail" }
|
|
105
|
+
],
|
|
106
|
+
edges: [
|
|
107
|
+
{ source: "check", target: "ok" }, // ← no source_handle — error
|
|
108
|
+
{ source: "check", target: "fail" } // ← no source_handle — error
|
|
109
|
+
]
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Why it breaks:** `if` nodes branch on `true`/`false`. Without a `source_handle`, the engine doesn't know which branch this edge belongs to. `validate_flow` returns `missing_handle` for both.
|
|
114
|
+
|
|
115
|
+
**Right:**
|
|
116
|
+
```
|
|
117
|
+
add_nodes({
|
|
118
|
+
flow_id: "...",
|
|
119
|
+
nodes: [
|
|
120
|
+
{ type: "if", temp_id: "check", data: { conditions: [...], conditionLogic: "and" } },
|
|
121
|
+
{ type: "goal", temp_id: "ok", data: { goalName: "approved" } },
|
|
122
|
+
{ type: "exit", temp_id: "fail", data: { exitName: "rejected" } }
|
|
123
|
+
],
|
|
124
|
+
edges: [
|
|
125
|
+
{ source: "check", target: "ok", source_handle: "true" },
|
|
126
|
+
{ source: "check", target: "fail", source_handle: "false" }
|
|
127
|
+
]
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
For switch: `source_handle` must match a case's `outputLabel` (or `"default"`).
|
|
132
|
+
For loop: `"loop"`, `"done"`, or `"fail"` (only if `enableFailRoute: true`).
|
|
133
|
+
For review: the option's `id` (e.g. `"option_0"`).
|
|
134
|
+
For page: `"right"` or an abandonment id.
|
|
135
|
+
For splitTest: the variant's `label` string.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## 4. Bad variable references
|
|
140
|
+
|
|
141
|
+
**Wrong:**
|
|
142
|
+
```
|
|
143
|
+
add_nodes({
|
|
144
|
+
flow_id: "...",
|
|
145
|
+
nodes: [
|
|
146
|
+
{
|
|
147
|
+
type: "httpRequest",
|
|
148
|
+
temp_id: "api",
|
|
149
|
+
data: {
|
|
150
|
+
url: "https://api.x/$(\"trigger\").body.id", // ← $() in config field
|
|
151
|
+
method: "GET"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
type: "code",
|
|
156
|
+
temp_id: "process",
|
|
157
|
+
data: {
|
|
158
|
+
code: "return { result: \"{{trigger.body.id}}\" }", // ← {{}} in code body
|
|
159
|
+
mode: "runOnce"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
type: "httpRequest",
|
|
164
|
+
temp_id: "api2",
|
|
165
|
+
data: {
|
|
166
|
+
url: "https://api.x/{{ghostNodeId.data}}", // ← nodeId doesn't exist
|
|
167
|
+
method: "GET"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
})
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Why it breaks:**
|
|
175
|
+
- `$()` in a config field is a literal string — templates use `{{}}`. `validate_flow` flags `dollar_in_config`.
|
|
176
|
+
- `{{}}` in a code body is a literal string inside JS — code nodes resolve fields via `$("nodeId")`. `validate_flow` warns `template_in_code`.
|
|
177
|
+
- `ghostNodeId` references a node that doesn't exist. `validate_flow` errors `unknown_node_reference`.
|
|
178
|
+
|
|
179
|
+
**Right:**
|
|
180
|
+
```
|
|
181
|
+
add_nodes({
|
|
182
|
+
flow_id: "...",
|
|
183
|
+
nodes: [
|
|
184
|
+
{
|
|
185
|
+
type: "httpRequest",
|
|
186
|
+
temp_id: "api",
|
|
187
|
+
data: {
|
|
188
|
+
url: "https://api.x/{{trigger-real-id.body.id}}", // config: {{}}
|
|
189
|
+
method: "GET"
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
type: "code",
|
|
194
|
+
temp_id: "process",
|
|
195
|
+
data: {
|
|
196
|
+
code: `
|
|
197
|
+
const t = $("trigger-real-id"); // code: $()
|
|
198
|
+
return { result: t.body.id };
|
|
199
|
+
`,
|
|
200
|
+
mode: "runOnce"
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
})
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
For custom nodes, use `inputs.keyName` inside the code body (inputs are pre-resolved from `{{}}` by the engine).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Node Cheatsheet — Auto-Generated
|
|
2
|
+
|
|
3
|
+
> Generated from NODE_TYPES at build time. Do NOT edit by hand — changes will be overwritten.
|
|
4
|
+
|
|
5
|
+
| Type | Category | Required fields | Source handles | Key output fields | Gotcha |
|
|
6
|
+
|------|----------|-----------------|----------------|-------------------|--------|
|
|
7
|
+
| `trigger` | triggers | — | (default) | `body`, `headers`, `query`, `method` | The webhook URL is auto-generated after the flow is published |
|
|
8
|
+
| `scheduleTrigger` | triggers | — | (default) | `scheduledTime`, `scheduleType` | intervalUnit options: seconds, minutes, hours, days |
|
|
9
|
+
| `tablesSchedule` | triggers | — | (default) | `scheduledTime`, `databaseId`, `tableId` | — |
|
|
10
|
+
| `tableButton` | triggers | — | (default) | `row`, `rowId`, `tableId`, `columnId` | — |
|
|
11
|
+
| `tableActionTrigger` | triggers | — | (default) | `row`, `rowId`, `buttonId`, `databaseId` | — |
|
|
12
|
+
| `batchActionTrigger` | triggers | — | (default) | `row`, `rowId`, `actionId`, `databaseId` | — |
|
|
13
|
+
| `tableTrigger` | triggers | — | (default) | `event`, `row`, `oldRow`, `rowId` | — |
|
|
14
|
+
| `emailTrigger` | triggers | — | (default) | `from`, `to`, `subject`, `text` | — |
|
|
15
|
+
| `httpRequest` | processing | url, method | (default) | `status`, `body`, `headers`, `success` | URL supports {{nodeId.field}} templates, e.g. "https://api.example.com/users/... |
|
|
16
|
+
| `respondToWebhook` | processing | — | (default) | `success`, `statusCode`, `responseBody`, `skipped` | Must be used in a flow that starts with a Webhook Trigger |
|
|
17
|
+
| `code` | processing | code, mode | `right` | `<user-defined>` | Always return an object: return { result: data } |
|
|
18
|
+
| `map` | processing | mappings | (default) | `<outputName>`, `_metadata`, `transformMode` | inputExpression supports {{nodeId.field}} template syntax |
|
|
19
|
+
| `if` | logic | conditions, conditionLogic | `true`, `false` | `conditionMet`, `evaluatedConditions`, `logicOperator` | leftValue and rightValue support {{nodeId.field}} templates |
|
|
20
|
+
| `switch` | logic | cases | `<case.outputLabel>`, `default` | `matchedHandles`, `matchedCaseLabels`, `hasDefault`, `mode` | source_handle must match the case's outputLabel value (e.g. "case-0") |
|
|
21
|
+
| `wait` | logic | waitType | (default) | `type`, `duration`, `completedAt`, `pauseInDatabase` | durationUnit options: seconds, minutes, hours, days |
|
|
22
|
+
| `flow` | logic | flowId | (default) | `flowId`, `flowName`, `runId`, `waitedForCompletion` | body supports {{}} templates for passing dynamic data to the child flow |
|
|
23
|
+
| `goal` | logic | — | (default) | `goalName`, `isEndNode`, `endType`, `success` | Goal nodes have no output handles — they terminate the flow path |
|
|
24
|
+
| `exit` | logic | — | (default) | `exitName`, `isEndNode`, `endType`, `success` | Exit nodes have no output handles — they terminate the flow path |
|
|
25
|
+
| `review` | logic | options | `option_0`, `option_1`, `option_N` | `selectedOption`, `selectedOptionLabel`, `reviewData`, `respondedBy` | source_handle must match the option's id (e.g. "option_0" for Approve) |
|
|
26
|
+
| `page` | logic | — | `right`, `<abandonment.id>` | `submissionData`, `submittedDate`, `status`, `activeHandle` | Use source_handle "right" for the submission path |
|
|
27
|
+
| `loop` | logic | arraySources | `loop`, `done`, `fail` | `items`, `totalItems`, `currentItem`, `currentIndex` | arraySources uses {{nodeId.field}} syntax, e.g. ["{{httpRequestId.body.data}}"] |
|
|
28
|
+
| `subflow` | logic | — | (default) | — | Subflows are purely visual — they don't change execution behavior |
|
|
29
|
+
| `variable` | logic | action | (default) | `action`, `variableName`, `previousValue`, `newValue` | Reference variables in other node config fields as {{Variables.varName}} |
|
|
30
|
+
| `splitTest` | logic | variants | `Variant A`, `Variant B` | `selectedHandle`, `selectedLabel`, `selectedVariantId` | source_handle must match the variant's label string (e.g. "Variant A") |
|
|
31
|
+
| `customNode` | custom | — | (default) | `<defined by output_schema>` | Custom node code uses inputs.keyName, NOT $("nodeId") — $() is only for inlin... |
|
|
32
|
+
| `note` | utility | — | (default) | — | Notes are not connected to the flow — they are visual only |
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
For full per-type detail (defaultData, tips, guide), call `get_node_type_info(type)` at runtime.
|
|
37
|
+
For form element types, call `list_page_elements` and `get_page_element_info(element_type)`.
|