@addai/flows-mcp 1.1.0 → 1.2.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.
@@ -1,142 +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.
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.