@addai/flows-mcp 0.3.0 → 1.0.0-rc.1
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/dist/bin/install.js +3 -0
- package/dist/bin/install.js.map +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +1 -0
- package/dist/client.js.map +1 -1
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/instructions.js +8 -0
- package/dist/instructions.js.map +1 -1
- package/dist/layout.d.ts +26 -0
- package/dist/layout.js +54 -0
- package/dist/layout.js.map +1 -0
- package/dist/node-defaults.d.ts +1 -0
- package/dist/node-defaults.js +311 -0
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-eligibility.d.ts +10 -0
- package/dist/plugin-eligibility.js +21 -0
- package/dist/plugin-eligibility.js.map +1 -0
- package/dist/tools/custom-nodes.js +1 -4
- package/dist/tools/custom-nodes.js.map +1 -1
- package/dist/tools/discover.d.ts +9 -0
- package/dist/tools/discover.js +56 -0
- package/dist/tools/discover.js.map +1 -0
- package/dist/tools/edits.d.ts +12 -0
- package/dist/tools/edits.js +66 -0
- package/dist/tools/edits.js.map +1 -0
- package/dist/tools/flows.js +23 -7
- package/dist/tools/flows.js.map +1 -1
- package/dist/tools/nodes.js +33 -9
- package/dist/tools/nodes.js.map +1 -1
- package/dist/tools/preview.js +1 -6
- package/dist/tools/preview.js.map +1 -1
- package/dist/tools/reference.js +9 -1
- package/dist/tools/reference.js.map +1 -1
- package/dist/tools/test.d.ts +10 -0
- package/dist/tools/test.js +51 -0
- package/dist/tools/test.js.map +1 -0
- package/dist/tools/validate.d.ts +9 -0
- package/dist/tools/validate.js +50 -0
- package/dist/tools/validate.js.map +1 -0
- package/dist/tools/workspaces.d.ts +1 -1
- package/dist/tools/workspaces.js +4 -5
- package/dist/tools/workspaces.js.map +1 -1
- package/dist/types.d.ts +15 -0
- package/dist/v2-client.d.ts +65 -0
- package/dist/v2-client.js +179 -0
- package/dist/v2-client.js.map +1 -0
- package/dist/validation/index.js +3 -1
- package/dist/validation/index.js.map +1 -1
- package/dist/validation/plugins.d.ts +13 -0
- package/dist/validation/plugins.js +200 -0
- package/dist/validation/plugins.js.map +1 -0
- package/dist/validation/structure.js +3 -0
- package/dist/validation/structure.js.map +1 -1
- package/dist/validation/types.d.ts +2 -0
- package/package.json +1 -1
- package/skill/SKILL.md +64 -102
- package/skill/anti-patterns.md +106 -176
- package/skill/flow-semantics.md +142 -0
- package/skill/recipes.md +158 -267
- package/skill/version.txt +1 -1
- package/skill/node-cheatsheet.md +0 -37
package/skill/SKILL.md
CHANGED
|
@@ -1,116 +1,78 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: building-aiflows
|
|
3
|
-
description:
|
|
3
|
+
description: Build, test, and publish +Ai Flows automations. Use whenever the user wants to create or modify a flow. Loaded automatically when the @addai/flows-mcp MCP server is connected.
|
|
4
|
+
version: 2.0.0
|
|
4
5
|
---
|
|
5
6
|
|
|
6
|
-
# Building +Ai Flows
|
|
7
|
+
# Building +Ai Flows
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
You have access to the +Ai Flows MCP server. This skill teaches you how to use it to build production-quality flows.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
## Mental model
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
A flow is a **directed graph**: nodes connected by edges. Execution starts at a trigger node and follows edges until it reaches a terminator (goal or exit) or fails.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
- **Nodes** do work — trigger an event, make an HTTP call, branch on a condition, send an email.
|
|
16
|
+
- **Edges** define order. Most nodes have one outgoing edge. **Branching nodes** (`if`, `switch`, `loop`, `review`, `splitTest`, `aiSwitch`) have multiple, distinguished by `sourceHandle`.
|
|
17
|
+
- **Variables** carry values between nodes via three distinct templating systems (see `flow-semantics.md`).
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
## The rigid workflow
|
|
17
20
|
|
|
18
|
-
|
|
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.
|
|
21
|
+
You MUST follow this loop. Each step has a named tool.
|
|
20
22
|
|
|
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
23
|
```
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
1. DISCOVER → list_node_types, describe_node_type, list_custom_nodes, describe_custom_node
|
|
25
|
+
2. DESIGN → propose_flow (NL → draft) [optional]
|
|
26
|
+
3. BUILD → create_flow, add_nodes, connect_nodes, set_variable
|
|
27
|
+
4. VALIDATE → validate_flow ← MUST PASS BEFORE TESTING
|
|
28
|
+
5. TEST → test_node (per uncertain node), test_flow / dry_run (end-to-end)
|
|
29
|
+
6. DEBUG → diagnose_run, replay_run, tail_logs [if test fails]
|
|
30
|
+
7. PUBLISH → pre_publish_check, then publish_flow / canary_publish
|
|
34
31
|
```
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
- `
|
|
42
|
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
|
54
|
-
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
| `
|
|
59
|
-
|
|
|
60
|
-
| `
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
|
33
|
+
**You have not finished if you did not validate and test before publishing.**
|
|
34
|
+
|
|
35
|
+
## Five rules you must not break
|
|
36
|
+
|
|
37
|
+
1. **Never guess a node's config schema.** Call `describe_node_type(type)` first if you have not used this type in this session.
|
|
38
|
+
2. **Never assign random node positions.** Pass no `position` to `add_nodes` — it auto-places horizontally. Or call `autolayout` after.
|
|
39
|
+
3. **Never reuse `{{}}` syntax inside a code node.** Code nodes use `$("nodeId")`. Custom node code uses `inputs.x`. See `flow-semantics.md`.
|
|
40
|
+
4. **Never insert a `customNode` without `customVersionId`.** Custom nodes do not auto-update on publish — explicit version pinning is required.
|
|
41
|
+
5. **Never publish without `pre_publish_check`.** Even if validation passes.
|
|
42
|
+
|
|
43
|
+
## Tool-by-step quick reference
|
|
44
|
+
|
|
45
|
+
| Step | Tool | Purpose |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| Discover types | `list_node_types`, `describe_node_type` | What's available, what each node needs |
|
|
48
|
+
| Discover custom | `list_custom_nodes`, `describe_custom_node` | Workspace-specific reusable nodes |
|
|
49
|
+
| Discover layout | `get_layout_config` | Canonical h_spacing / v_spacing constants |
|
|
50
|
+
| Create flow | `create_flow` | New empty flow with trigger node |
|
|
51
|
+
| Add nodes | `add_nodes` | Insert nodes + edges; auto-positions horizontally |
|
|
52
|
+
| Connect | `connect_nodes`, `disconnect_nodes` | Atomic edge ops |
|
|
53
|
+
| Variables | `set_variable`, `list_variables`, `delete_variable` | Atomic per-name; no full flow rewrite |
|
|
54
|
+
| Lay out | `autolayout` | One-call horizontal cleanup |
|
|
55
|
+
| Validate | `validate_flow` | Server-authoritative; errors[] and warnings[] |
|
|
56
|
+
| Test node | `test_node` | Run one node in isolation |
|
|
57
|
+
| Test code | `test_custom_node_code` | Verify custom node code before save |
|
|
58
|
+
| Test flow | `test_flow`, `dry_run` | End-to-end; dry_run suppresses side effects |
|
|
59
|
+
| Debug | `diagnose_run`, `replay_run` (Phase 2), `tail_logs` (Phase 2) | One-call diagnostics; re-execute |
|
|
60
|
+
| Pre-publish | `pre_publish_check` (Phase 2) | Gate: validation + snapshot tests + secret scan |
|
|
61
|
+
| Publish | `publish_flow`, `canary_publish` (Phase 2) | Production rollout |
|
|
62
|
+
| Undo | `undo_last_operation` | Session-scoped stack |
|
|
63
|
+
| Safety | `confirm_intent` | Two-step destructive ops |
|
|
64
|
+
|
|
65
|
+
## How to handle uncertainty
|
|
66
|
+
|
|
67
|
+
If you don't know:
|
|
68
|
+
- **What a node does** → `describe_node_type(type)`. Don't guess.
|
|
69
|
+
- **What fields a custom node needs** → `describe_custom_node(custom_node_id)`. The schema is authoritative.
|
|
70
|
+
- **What a template reference will resolve to** → test the upstream node with `test_node` first.
|
|
71
|
+
- **Whether your config is valid** → `validate_flow`.
|
|
72
|
+
- **Why a run failed** → `diagnose_run(run_id)` (Phase 2). For now: `get_run` + `list_node_logs` + `get_node_output`.
|
|
73
|
+
|
|
74
|
+
Asking the human costs you a turn. The tools above usually answer the question faster than the human would.
|
|
75
|
+
|
|
76
|
+
## Now go
|
|
77
|
+
|
|
78
|
+
Start with `list_node_types`. Then read `flow-semantics.md` for variable systems and edge handles. Then read `recipes.md` for patterns. Then read `anti-patterns.md` to know what NOT to do.
|
package/skill/anti-patterns.md
CHANGED
|
@@ -1,207 +1,137 @@
|
|
|
1
|
-
# Anti-
|
|
1
|
+
# Anti-patterns
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Specific mistakes Claude (and humans) make repeatedly. Each has a fix.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## AP1 — Vertical-stacked flows
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**Mistake:** Assigning incrementing `y` values to each new node and leaving `x` at `0`. The result: a flow that reads top-to-bottom like a debug log.
|
|
8
8
|
|
|
9
|
-
**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
```
|
|
9
|
+
**Why it's wrong:**
|
|
10
|
+
- Unreadable on a wide canvas (most of the canvas is empty space).
|
|
11
|
+
- Violates team convention (P9: horizontal is default).
|
|
12
|
+
- `validate_flow` will issue `LAYOUT_VERTICAL_DRIFT` warnings.
|
|
13
|
+
|
|
14
|
+
**Do instead:**
|
|
15
|
+
- Pass NO `position` to `add_nodes`. It auto-places horizontally.
|
|
16
|
+
- If positions got messy during a refactor, call `autolayout({flow_id})`.
|
|
25
17
|
|
|
26
|
-
|
|
18
|
+
## AP2 — `{{}}` inside a code node
|
|
27
19
|
|
|
28
|
-
**
|
|
20
|
+
**Mistake:**
|
|
21
|
+
```javascript
|
|
22
|
+
const email = "{{trigger.body.email}}"; // ← does NOT resolve
|
|
29
23
|
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
})
|
|
24
|
+
|
|
25
|
+
**Why it's wrong:** `{{}}` syntax is only resolved in node *config fields*. Code nodes run in a JavaScript sandbox where `{{}}` is a literal string.
|
|
26
|
+
|
|
27
|
+
**Do instead:**
|
|
28
|
+
```javascript
|
|
29
|
+
const email = $("trigger").body.email;
|
|
46
30
|
```
|
|
47
31
|
|
|
48
|
-
|
|
32
|
+
## AP3 — `$()` inside custom node code
|
|
49
33
|
|
|
50
|
-
|
|
34
|
+
**Mistake:** Using `$("nodeId")` inside a custom node's `code`.
|
|
51
35
|
|
|
52
|
-
**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
})
|
|
36
|
+
**Why it's wrong:** Custom nodes run in a separate sandbox. They don't have access to other nodes' outputs — only the declared `inputs` and `secrets`.
|
|
37
|
+
|
|
38
|
+
**Do instead:**
|
|
39
|
+
```javascript
|
|
40
|
+
const url = inputs.endpoint; // declared in input_schema
|
|
41
|
+
const token = secrets.API_TOKEN; // declared in secret_requirements
|
|
67
42
|
```
|
|
68
43
|
|
|
69
|
-
|
|
44
|
+
## AP4 — Forgetting `customVersionId`
|
|
45
|
+
|
|
46
|
+
**Mistake:** Inserting a `customNode` with only `customNodeId`, expecting it to use "the latest version."
|
|
70
47
|
|
|
71
|
-
**
|
|
48
|
+
**Why it's wrong:** Custom node versions do not auto-update on publish (deliberate design decision). A flow without `customVersionId` will fail at runtime — there is no implicit latest.
|
|
49
|
+
|
|
50
|
+
**Do instead:** Always pin:
|
|
72
51
|
```
|
|
73
|
-
|
|
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
|
-
})
|
|
52
|
+
{type: "customNode", data: {customNodeId: "cn_x", customVersionId: "v_abc"}}
|
|
89
53
|
```
|
|
90
54
|
|
|
91
|
-
|
|
55
|
+
To upgrade later, edit `customVersionId` deliberately and validate.
|
|
92
56
|
|
|
93
|
-
|
|
57
|
+
## AP5 — Wrong `sourceHandle` on branching nodes
|
|
94
58
|
|
|
95
|
-
|
|
59
|
+
**Mistake:** Adding an edge from an `if` node without `sourceHandle`, or using `"yes"`/`"no"` instead of `"true"`/`"false"`.
|
|
96
60
|
|
|
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
|
-
```
|
|
61
|
+
**Why it's wrong:** Branching nodes require specific handle values. Wrong handle → edge ignored at runtime → mysterious "the flow just stopped."
|
|
112
62
|
|
|
113
|
-
**
|
|
63
|
+
**Do instead:** Look up handles per node type:
|
|
114
64
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
```
|
|
65
|
+
| Node type | Valid handles |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `if` | `"true"`, `"false"` |
|
|
68
|
+
| `switch` | case `outputLabel`s, or `"default"` |
|
|
69
|
+
| `loop` | `"loop"`, `"done"`, `"fail"` |
|
|
70
|
+
| `review` | `"option_0"`, `"option_1"`, … |
|
|
130
71
|
|
|
131
|
-
|
|
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.
|
|
72
|
+
Or just call `describe_node_type(type)` and read `source_handles`.
|
|
136
73
|
|
|
137
|
-
|
|
74
|
+
## AP6 — `set_variable` inside a `loop`
|
|
138
75
|
|
|
139
|
-
|
|
76
|
+
**Mistake:** Calling `set_variable` from within a loop iteration to accumulate state.
|
|
140
77
|
|
|
141
|
-
**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
```
|
|
78
|
+
**Why it's wrong:** Variables are flow-scoped and shared across concurrent iterations. Race condition; values overwrite each other unpredictably.
|
|
79
|
+
|
|
80
|
+
**Do instead:** Use the `code` node's return value to push items onto an array stored as variable, OR use a state store (`set_state`, Phase 3). For now: collect via code node after the `loop` `done` handle.
|
|
81
|
+
|
|
82
|
+
## AP7 — Recursion via `claudeCode`
|
|
83
|
+
|
|
84
|
+
**Mistake:** A flow's `claudeCode` node dispatches work to a paired Claude Code agent. That agent happens to be using *this* MCP — and starts building a flow that itself has a `claudeCode` node.
|
|
85
|
+
|
|
86
|
+
**Why it's wrong:** Infinite recursion. Resource exhaustion. Possible runaway billing.
|
|
173
87
|
|
|
174
|
-
**
|
|
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`.
|
|
88
|
+
**Do instead:** When using `claudeCode`, restrict its prompt to tasks that do **not** modify flows. Better: scope the paired Claude Code agent's MCPs to exclude `addai-flows`.
|
|
178
89
|
|
|
179
|
-
|
|
90
|
+
## AP8 — Publishing without `pre_publish_check`
|
|
91
|
+
|
|
92
|
+
**Mistake:** Calling `publish_flow` directly because validation passed.
|
|
93
|
+
|
|
94
|
+
**Why it's wrong:** Validation is necessary but not sufficient. The flow may have inline secrets, deprecated nodes, failing snapshot tests, or unbacked Vault references. All of those will pass `validate_flow` but should still block publish.
|
|
95
|
+
|
|
96
|
+
**Do instead:**
|
|
180
97
|
```
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
})
|
|
98
|
+
pre_publish_check(flow_id) # → ready or blocked with reasons
|
|
99
|
+
publish_flow(flow_id) # only if check returned ready
|
|
205
100
|
```
|
|
206
101
|
|
|
207
|
-
|
|
102
|
+
(`pre_publish_check` is Phase 2 — until then, run validate_flow + manual inspection for inline secrets in code nodes.)
|
|
103
|
+
|
|
104
|
+
## AP9 — Polling instead of streaming
|
|
105
|
+
|
|
106
|
+
**Mistake:** Wrapping `test_flow` in a manual loop because you want to watch progress.
|
|
107
|
+
|
|
108
|
+
**Why it's wrong:** `test_flow` already polls internally. Wrapping it again multiplies the poll rate and wastes tokens.
|
|
109
|
+
|
|
110
|
+
**Do instead:** Use `test_flow_stream` (Phase 2 — SSE-based progress events). For Phase 1, `test_flow` is fine; don't add an outer loop.
|
|
111
|
+
|
|
112
|
+
## AP10 — Saving fixtures with PII
|
|
113
|
+
|
|
114
|
+
**Mistake:** `save_fixture(name, payload)` where the payload contains real user emails / phone numbers / card numbers.
|
|
115
|
+
|
|
116
|
+
**Why it's wrong:** Fixtures get reused in tests, shared in logs, possibly exported. Real PII in test data is a compliance leak.
|
|
117
|
+
|
|
118
|
+
**Do instead:**
|
|
119
|
+
- The MCP applies `data_masking_default=true` to fixtures by default — but only on display, not on save.
|
|
120
|
+
- Run the payload through `detect_pii(flow_id)` (Phase 2) before saving, or manually sanitize.
|
|
121
|
+
- Replace real values with synthetic ones (`user@example.com`, `+1 555 000 0000`).
|
|
122
|
+
|
|
123
|
+
## AP11 — Vertical drift from "I'll just add one more node"
|
|
124
|
+
|
|
125
|
+
**Mistake:** Repeatedly adding nodes downstream without thinking about the canvas. Result: a flow that has technically horizontal positions but is *narrower than tall* because branches stacked deeply.
|
|
126
|
+
|
|
127
|
+
**Why it's wrong:** `validate_flow` raises `LAYOUT_VERTICAL_DRIFT` when `height > 1.2 × width` with < 3 active branches. Looks weird; harder for the human to read.
|
|
128
|
+
|
|
129
|
+
**Do instead:** After significant additions, run `autolayout(flow_id)`. It's idempotent — safe to call any time.
|
|
130
|
+
|
|
131
|
+
## AP12 — Hand-rolling validation
|
|
132
|
+
|
|
133
|
+
**Mistake:** Writing your own checks ("does this flow have a trigger?") inside Claude's response instead of calling `validate_flow`.
|
|
134
|
+
|
|
135
|
+
**Why it's wrong:** Your hand-rolled check will drift from the real validator. It will miss rules that the server checks (template syntax, custom-node version pinning, schema version compatibility). Worse, it gives a false sense of correctness.
|
|
136
|
+
|
|
137
|
+
**Do instead:** Always `validate_flow`. The server is authoritative.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Flow semantics
|
|
2
|
+
|
|
3
|
+
The durable reference. Mechanics that do not change between releases. Catalog data (specific node types and their config schemas) is **not** here — fetch it via `describe_node_type` / `describe_page_element` / `describe_custom_node`.
|
|
4
|
+
|
|
5
|
+
## Graph model
|
|
6
|
+
|
|
7
|
+
A flow is `{ nodes[], edges[], variables[], end_conditions }`.
|
|
8
|
+
|
|
9
|
+
- **Node:** `{ id, type, data, position: {x, y} }`. The `data` shape depends on `type` (look up via `describe_node_type`).
|
|
10
|
+
- **Edge:** `{ id, source, target, sourceHandle?, targetHandle? }`. `sourceHandle` is required for branching nodes (see below).
|
|
11
|
+
- **Variables:** `[{ name, value, type }]`. Flow-scoped; reachable via `{{Variables.name}}`.
|
|
12
|
+
- **End conditions:** `{ goals: [{ id, label, nodeId }], exits: [{ id, label, nodeId }] }`. Tracks named termination points for analytics.
|
|
13
|
+
|
|
14
|
+
## The three variable systems
|
|
15
|
+
|
|
16
|
+
This is the most common source of confusion. Each context resolves variables differently. Mixing them up silently fails or produces `undefined`.
|
|
17
|
+
|
|
18
|
+
### 1. Config fields — `{{nodeId.field}}`
|
|
19
|
+
|
|
20
|
+
Used in any node's `data` fields that accept templates (URL, body, condition values, etc.). The engine resolves before the node executes.
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
{{trigger.body.email}} # field from trigger output
|
|
24
|
+
{{http1.body.user.id}} # nested via dot
|
|
25
|
+
{{loop1.items[0]}} # array index
|
|
26
|
+
{{Variables.apiBase}} # flow variable
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Code node sandbox — `$("nodeId")`
|
|
30
|
+
|
|
31
|
+
Used **only** inside `code` nodes. The runner injects globals; `{{}}` syntax does **not** work here.
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const email = $("trigger").body.email;
|
|
35
|
+
const items = $("http1").body.items;
|
|
36
|
+
return { count: items.length, email };
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
In `runForEachItem` mode you also get `item` (current element) and `index`.
|
|
40
|
+
|
|
41
|
+
### 3. Custom node sandbox — `inputs.x` / `secrets.x`
|
|
42
|
+
|
|
43
|
+
Used **only** inside custom node code. Inputs and secrets are pre-resolved by the engine before the function runs.
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
// custom node code
|
|
47
|
+
const url = inputs.endpoint; // declared in input_schema
|
|
48
|
+
const token = secrets.API_TOKEN; // declared in secret_requirements
|
|
49
|
+
return { ok: true, status: 200 };
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Do not use `$()` inside custom node code. Do not use `{{}}` inside custom node code.
|
|
53
|
+
|
|
54
|
+
## Edge handles per branching node
|
|
55
|
+
|
|
56
|
+
Branching nodes require a `sourceHandle` on every outgoing edge.
|
|
57
|
+
|
|
58
|
+
| Node type | Valid `sourceHandle` values |
|
|
59
|
+
|---|---|
|
|
60
|
+
| `if` | `"true"`, `"false"` |
|
|
61
|
+
| `switch` | Each case's `outputLabel` value, or `"default"` |
|
|
62
|
+
| `loop` | `"loop"` (per-iteration), `"done"` (after all), `"fail"` (errors, if enableFailRoute) |
|
|
63
|
+
| `review` | `"option_0"`, `"option_1"`, … (one per option) |
|
|
64
|
+
| `page` | `"right"` (submission), or an abandonment ID per element |
|
|
65
|
+
| `splitTest` | Each variant's `label` |
|
|
66
|
+
| `aiSwitch` / `claudeSwitch` | Each route's `outputLabel`, or `"default"` |
|
|
67
|
+
|
|
68
|
+
Non-branching nodes (most node types) need no `sourceHandle` — leave it `null` or omit it.
|
|
69
|
+
|
|
70
|
+
## Goals and exits
|
|
71
|
+
|
|
72
|
+
Both terminate a run. The difference is semantic:
|
|
73
|
+
- `goal` — successful termination ("user signed up", "order processed"). Recorded as `status: "goal"`.
|
|
74
|
+
- `exit` — alternative termination ("user declined", "timeout reached"). Recorded as `status: "exit"`.
|
|
75
|
+
|
|
76
|
+
A flow can have multiple of each. Reaching any one terminates *that path* through the graph. Used for outcome breakdowns (`get_outcome_breakdown`).
|
|
77
|
+
|
|
78
|
+
## Run lifecycle
|
|
79
|
+
|
|
80
|
+
States: `running`, `completed`, `failed`, `cancelled`, `waiting`, `paused`, `error`, `goal`, `exit`.
|
|
81
|
+
|
|
82
|
+
- `running` — currently executing.
|
|
83
|
+
- `waiting` — paused at an async node, will resume.
|
|
84
|
+
- `paused` — paused for review or page submission.
|
|
85
|
+
- `completed` — all paths finished without hitting a goal/exit (rare; usually flows have terminators).
|
|
86
|
+
- `goal` / `exit` — reached a terminator node.
|
|
87
|
+
- `failed` / `error` — unhandled error.
|
|
88
|
+
- `cancelled` — explicit cancellation via `manage_run`.
|
|
89
|
+
|
|
90
|
+
## Pause and resume
|
|
91
|
+
|
|
92
|
+
Some node types pause execution. The resume server polls Supabase for waiting runs and resumes them with millisecond precision.
|
|
93
|
+
|
|
94
|
+
**Async pausers:**
|
|
95
|
+
- `wait` (when duration > 30s)
|
|
96
|
+
- `page` (waits for form submission)
|
|
97
|
+
- `review` (waits for human approval)
|
|
98
|
+
- `claudeCode` (waits for paired Claude Code agent response)
|
|
99
|
+
- `redirect` (waits for user to follow link)
|
|
100
|
+
|
|
101
|
+
Short waits (≤ 30s) are in-memory; longer waits persist. Either way, the run resumes automatically.
|
|
102
|
+
|
|
103
|
+
## Sandbox boundaries
|
|
104
|
+
|
|
105
|
+
| Sandbox | Globals available | Variable syntax |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| **Code node** | `$("nodeId")`, `console.log`, `fetch` (some URLs blocked), `item`/`index` in forEach mode | `$()` |
|
|
108
|
+
| **Custom node** | `inputs.x`, `secrets.x`, `fetch` (restricted to declared domains), `console.log` | `inputs` / `secrets` |
|
|
109
|
+
| **Config field** | (resolved by engine before node runs) | `{{}}` |
|
|
110
|
+
|
|
111
|
+
Don't cross sandboxes. Cross-sandbox confusion is the #1 source of "why is this undefined."
|
|
112
|
+
|
|
113
|
+
## Layout rules (P9 — horizontal by default)
|
|
114
|
+
|
|
115
|
+
Every node has a `position: {x, y}`. The canonical convention:
|
|
116
|
+
|
|
117
|
+
- **Trigger** at `x ≈ 0`.
|
|
118
|
+
- Each downstream node `x = previous.x + h_spacing` (default `280`).
|
|
119
|
+
- Branching node's branches: same `x`, different `y`. Each branch gets a lane at `y = branching.y + (lane_index - center) × v_spacing` (default `160`).
|
|
120
|
+
- Loops: loop body lanes above, `done` continues right at center.
|
|
121
|
+
- **Goals and exits** on the **rightmost** `x` in the flow.
|
|
122
|
+
|
|
123
|
+
You almost never need to assign positions yourself — pass no `position` to `add_nodes` and the MCP places nodes correctly. If positions get messy after refactoring, call `autolayout(flow_id)`.
|
|
124
|
+
|
|
125
|
+
Constants: `get_layout_config()` returns the canonical values for `h_spacing`, `v_spacing`, and per-node-type widths.
|
|
126
|
+
|
|
127
|
+
## Custom node versioning
|
|
128
|
+
|
|
129
|
+
Custom nodes are versioned. **Versions do not auto-update on publish.** When inserting a `customNode` node, you must provide:
|
|
130
|
+
- `customNodeId` — which custom node
|
|
131
|
+
- `customVersionId` — which exact version (pin to specific version)
|
|
132
|
+
|
|
133
|
+
If you don't pin, the flow is broken. There is no implicit "use latest" — that would silently break flows on every custom-node publish.
|
|
134
|
+
|
|
135
|
+
To upgrade a flow's custom node version, edit the `customVersionId` deliberately and validate.
|
|
136
|
+
|
|
137
|
+
## Trace IDs
|
|
138
|
+
|
|
139
|
+
Every MCP tool error includes a `trace_id` field. When a tool fails:
|
|
140
|
+
- Report the trace_id to the user — they can quote it to support.
|
|
141
|
+
- Don't paper over the error with a generic retry.
|
|
142
|
+
- Use `diagnose_run` (Phase 2) to get the full failure context.
|