@n8n/expression-runtime 0.14.2 → 0.16.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 (91) hide show
  1. package/dist/bundle/runtime.esm.js +17 -17
  2. package/dist/bundle/runtime.esm.js.map +4 -4
  3. package/dist/bundle/runtime.iife.js +17 -17
  4. package/dist/bundle/runtime.iife.js.map +4 -4
  5. package/dist/cjs/bridge/bridge-messages.d.ts +594 -0
  6. package/dist/cjs/bridge/bridge-messages.d.ts.map +1 -0
  7. package/dist/cjs/bridge/bridge-messages.js +263 -0
  8. package/dist/cjs/bridge/bridge-messages.js.map +1 -0
  9. package/dist/cjs/bridge/isolated-vm-bridge.d.ts +134 -11
  10. package/dist/cjs/bridge/isolated-vm-bridge.d.ts.map +1 -1
  11. package/dist/cjs/bridge/isolated-vm-bridge.js +225 -50
  12. package/dist/cjs/bridge/isolated-vm-bridge.js.map +1 -1
  13. package/dist/cjs/build.tsbuildinfo +1 -1
  14. package/dist/cjs/extensions/extend.d.ts +5 -0
  15. package/dist/cjs/extensions/extend.d.ts.map +1 -1
  16. package/dist/cjs/extensions/extend.js +14 -14
  17. package/dist/cjs/extensions/extend.js.map +1 -1
  18. package/dist/cjs/pool/idle-scaling-pool.js +2 -2
  19. package/dist/cjs/pool/idle-scaling-pool.js.map +1 -1
  20. package/dist/cjs/runtime/context.d.ts +43 -4
  21. package/dist/cjs/runtime/context.d.ts.map +1 -1
  22. package/dist/cjs/runtime/context.js +179 -25
  23. package/dist/cjs/runtime/context.js.map +1 -1
  24. package/dist/cjs/runtime/index.d.ts +3 -3
  25. package/dist/cjs/runtime/index.d.ts.map +1 -1
  26. package/dist/cjs/runtime/index.js.map +1 -1
  27. package/dist/cjs/runtime/jmespath.d.ts +5 -3
  28. package/dist/cjs/runtime/jmespath.d.ts.map +1 -1
  29. package/dist/cjs/runtime/jmespath.js +5 -3
  30. package/dist/cjs/runtime/jmespath.js.map +1 -1
  31. package/dist/cjs/runtime/lazy-proxy.d.ts +7 -5
  32. package/dist/cjs/runtime/lazy-proxy.d.ts.map +1 -1
  33. package/dist/cjs/runtime/lazy-proxy.js +8 -16
  34. package/dist/cjs/runtime/lazy-proxy.js.map +1 -1
  35. package/dist/cjs/runtime/safe-globals.d.ts.map +1 -1
  36. package/dist/cjs/runtime/safe-globals.js +8 -3
  37. package/dist/cjs/runtime/safe-globals.js.map +1 -1
  38. package/dist/cjs/runtime/utils.d.ts +16 -0
  39. package/dist/cjs/runtime/utils.d.ts.map +1 -0
  40. package/dist/cjs/runtime/utils.js +31 -0
  41. package/dist/cjs/runtime/utils.js.map +1 -0
  42. package/dist/cjs/types/bridge.d.ts +2 -1
  43. package/dist/cjs/types/bridge.d.ts.map +1 -1
  44. package/dist/cjs/types/bridge.js.map +1 -1
  45. package/dist/cjs/types/evaluator.d.ts +86 -4
  46. package/dist/cjs/types/evaluator.d.ts.map +1 -1
  47. package/dist/cjs/types/evaluator.js.map +1 -1
  48. package/dist/esm/bridge/bridge-messages.d.ts +594 -0
  49. package/dist/esm/bridge/bridge-messages.d.ts.map +1 -0
  50. package/dist/esm/bridge/bridge-messages.js +250 -0
  51. package/dist/esm/bridge/bridge-messages.js.map +1 -0
  52. package/dist/esm/bridge/isolated-vm-bridge.d.ts +134 -11
  53. package/dist/esm/bridge/isolated-vm-bridge.d.ts.map +1 -1
  54. package/dist/esm/bridge/isolated-vm-bridge.js +224 -49
  55. package/dist/esm/bridge/isolated-vm-bridge.js.map +1 -1
  56. package/dist/esm/build.tsbuildinfo +1 -1
  57. package/dist/esm/extensions/extend.d.ts +5 -0
  58. package/dist/esm/extensions/extend.d.ts.map +1 -1
  59. package/dist/esm/extensions/extend.js +12 -12
  60. package/dist/esm/extensions/extend.js.map +1 -1
  61. package/dist/esm/pool/idle-scaling-pool.js +2 -2
  62. package/dist/esm/pool/idle-scaling-pool.js.map +1 -1
  63. package/dist/esm/runtime/context.d.ts +43 -4
  64. package/dist/esm/runtime/context.d.ts.map +1 -1
  65. package/dist/esm/runtime/context.js +178 -24
  66. package/dist/esm/runtime/context.js.map +1 -1
  67. package/dist/esm/runtime/index.d.ts +3 -3
  68. package/dist/esm/runtime/index.d.ts.map +1 -1
  69. package/dist/esm/runtime/index.js.map +1 -1
  70. package/dist/esm/runtime/jmespath.d.ts +5 -3
  71. package/dist/esm/runtime/jmespath.d.ts.map +1 -1
  72. package/dist/esm/runtime/jmespath.js +5 -3
  73. package/dist/esm/runtime/jmespath.js.map +1 -1
  74. package/dist/esm/runtime/lazy-proxy.d.ts +7 -5
  75. package/dist/esm/runtime/lazy-proxy.d.ts.map +1 -1
  76. package/dist/esm/runtime/lazy-proxy.js +8 -16
  77. package/dist/esm/runtime/lazy-proxy.js.map +1 -1
  78. package/dist/esm/runtime/safe-globals.d.ts.map +1 -1
  79. package/dist/esm/runtime/safe-globals.js +8 -3
  80. package/dist/esm/runtime/safe-globals.js.map +1 -1
  81. package/dist/esm/runtime/utils.d.ts +16 -0
  82. package/dist/esm/runtime/utils.d.ts.map +1 -0
  83. package/dist/esm/runtime/utils.js +18 -0
  84. package/dist/esm/runtime/utils.js.map +1 -0
  85. package/dist/esm/types/bridge.d.ts +2 -1
  86. package/dist/esm/types/bridge.d.ts.map +1 -1
  87. package/dist/esm/types/bridge.js.map +1 -1
  88. package/dist/esm/types/evaluator.d.ts +86 -4
  89. package/dist/esm/types/evaluator.d.ts.map +1 -1
  90. package/dist/esm/types/evaluator.js.map +1 -1
  91. package/package.json +6 -5
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Schemas for messages the in-isolate runtime sends to the host via the
3
+ * `callHost` typed-RPC dispatcher.
4
+ *
5
+ * The isolate is an untrusted source: anything that crosses the bridge must
6
+ * be validated for shape and types at the boundary. We do that with zod
7
+ * rather than relying on TypeScript discriminated unions, because TS types
8
+ * are erased at runtime and contribute zero security.
9
+ *
10
+ * Each operation has its own schema. The dispatcher entry validates the
11
+ * envelope against the discriminated union, throws on any deviation
12
+ * (unknown `type`, missing/typo'd fields, wrong field types), and then
13
+ * delegates to a handler that operates on the parsed (statically narrowed)
14
+ * message.
15
+ *
16
+ * Each additional typed RPC lands as a new schema here plus a new `case`
17
+ * in the bridge's dispatcher switch.
18
+ */
19
+ import { z } from 'zod';
20
+ /**
21
+ * `$('NodeName').first(branchIndex?, runIndex?)` — fetch the first item of
22
+ * a named node's most recent execution data.
23
+ */
24
+ export const getNodeFirstMessage = z
25
+ .object({
26
+ type: z.literal('getNodeFirst'),
27
+ nodeName: z.string(),
28
+ branchIndex: z.number().int().nonnegative().optional(),
29
+ runIndex: z.number().int().nonnegative().optional(),
30
+ })
31
+ .strict();
32
+ /**
33
+ * `$('NodeName').last(branchIndex?, runIndex?)` — fetch the last item of
34
+ * a named node's most recent execution data.
35
+ */
36
+ export const getNodeLastMessage = z
37
+ .object({
38
+ type: z.literal('getNodeLast'),
39
+ nodeName: z.string(),
40
+ branchIndex: z.number().int().nonnegative().optional(),
41
+ runIndex: z.number().int().nonnegative().optional(),
42
+ })
43
+ .strict();
44
+ /**
45
+ * `$('NodeName').all(branchIndex?, runIndex?)` — fetch every item of a
46
+ * named node's most recent execution data as an array.
47
+ */
48
+ export const getNodeAllMessage = z
49
+ .object({
50
+ type: z.literal('getNodeAll'),
51
+ nodeName: z.string(),
52
+ branchIndex: z.number().int().nonnegative().optional(),
53
+ runIndex: z.number().int().nonnegative().optional(),
54
+ })
55
+ .strict();
56
+ /**
57
+ * `$input.first()` — fetch the first item of the current node's input.
58
+ * Host enforces zero arguments; the schema has no fields besides `type`.
59
+ */
60
+ export const getInputFirstMessage = z.object({ type: z.literal('getInputFirst') }).strict();
61
+ /**
62
+ * `$input.last()` — fetch the last item of the current node's input.
63
+ */
64
+ export const getInputLastMessage = z.object({ type: z.literal('getInputLast') }).strict();
65
+ /**
66
+ * `$input.all()` — fetch every item of the current node's input.
67
+ */
68
+ export const getInputAllMessage = z.object({ type: z.literal('getInputAll') }).strict();
69
+ /**
70
+ * `$items(nodeName?, outputIndex?, runIndex?)` — fetch the execution data of
71
+ * a node by name (or the current node's input if `nodeName` is omitted).
72
+ *
73
+ * `runIndex` accepts negative values: the host uses `-1` as a sentinel for
74
+ * "latest run" (see `WorkflowDataProxy.$items` —
75
+ * `runIndex === undefined ? -1 : runIndex`). The schema uses
76
+ * `z.number().int()` without `.nonnegative()` so expressions can pass `-1`
77
+ * explicitly if they need to.
78
+ */
79
+ export const getItemsMessage = z
80
+ .object({
81
+ type: z.literal('getItems'),
82
+ nodeName: z.string().optional(),
83
+ outputIndex: z.number().int().nonnegative().optional(),
84
+ runIndex: z.number().int().optional(),
85
+ })
86
+ .strict();
87
+ /**
88
+ * `$fromAI(name, description?, type?, defaultValue?)` — the AI-builder
89
+ * placeholder accessor (aliases: `$fromAi`, `$fromai`).
90
+ *
91
+ * Two deliberate looseness points in this schema, both to preserve host
92
+ * contract / parity:
93
+ *
94
+ * 1. `name` is `z.string().optional()` (not required) so a call missing
95
+ * the argument or passing an empty string reaches the host, which
96
+ * throws the user-friendly `ExpressionError("Add a key, e.g. $fromAI('placeholder_name')")`.
97
+ * Requiring it here would replace that error with a generic zod
98
+ * message. The host also validates the regex `[a-zA-Z0-9_-]{0,64}`;
99
+ * we don't pre-empt that either.
100
+ * 2. `defaultValue` is `z.unknown()` because the host accepts any value
101
+ * as the fallback return (`handleFromAi` returns it directly via
102
+ * `??`). Structured-clone at the bridge boundary still prevents
103
+ * functions and other non-cloneable values from crossing.
104
+ *
105
+ * `description` and `type` are forwarded even though the host currently
106
+ * ignores them (`_description`, `_type`), so the protocol matches the
107
+ * documented call signature.
108
+ */
109
+ export const fromAiMessage = z
110
+ .object({
111
+ type: z.literal('fromAi'),
112
+ name: z.string().optional(),
113
+ description: z.string().optional(),
114
+ valueType: z.string().optional(),
115
+ // `z.unknown()` already accepts `undefined`, so no `.optional()` needed.
116
+ defaultValue: z.unknown(),
117
+ })
118
+ .strict();
119
+ /**
120
+ * `$('NodeName').pairedItem(itemIndex?)` / `.itemMatching(itemIndex)` /
121
+ * `.item` — resolve the paired item for a referenced node.
122
+ *
123
+ * All three host-side surface forms share one internal resolver
124
+ * (`pairedItemMethod` in `WorkflowDataProxy`), but the resolver closes
125
+ * over the literal property name the bridge accessed on the host proxy
126
+ * — so the error message and getter-vs-method form depend on *which*
127
+ * property the bridge reads. Three separate discriminators, each
128
+ * mapping a handler to a fixed literal property name, are the only way
129
+ * to preserve the host's friendly errors (e.g. "Missing item index for
130
+ * .itemMatching()") and the `.item` getter semantics without
131
+ * duplicating logic in-isolate.
132
+ *
133
+ * `itemIndex` is optional on all three at the schema level; the host
134
+ * throws the appropriate `ExpressionError` when it's missing for
135
+ * `.itemMatching()`, and applies the current-itemIndex default for
136
+ * `.pairedItem` and `.item`.
137
+ */
138
+ export const getNodePairedItemMessage = z
139
+ .object({
140
+ type: z.literal('getNodePairedItem'),
141
+ nodeName: z.string(),
142
+ itemIndex: z.number().int().nonnegative().optional(),
143
+ })
144
+ .strict();
145
+ /**
146
+ * `itemIndex` is `.optional()` even though `.itemMatching()` requires it
147
+ * at the host. The host's `pairedItemMethod` closure throws the friendly
148
+ * `"Missing item index for .itemMatching()"` error when the field is
149
+ * absent — keeping the schema permissive lets that host error surface
150
+ * verbatim instead of being replaced by a generic zod parse failure.
151
+ */
152
+ export const getNodeItemMatchingMessage = z
153
+ .object({
154
+ type: z.literal('getNodeItemMatching'),
155
+ nodeName: z.string(),
156
+ itemIndex: z.number().int().nonnegative().optional(),
157
+ })
158
+ .strict();
159
+ export const getNodeItemMessage = z
160
+ .object({
161
+ type: z.literal('getNodeItem'),
162
+ nodeName: z.string(),
163
+ })
164
+ .strict();
165
+ /**
166
+ * `$evaluateExpression(expression, itemIndex?)` — evaluate a nested
167
+ * expression string at runtime against the same execution context.
168
+ *
169
+ * The host recursively invokes the expression engine on the `expression`
170
+ * string — under the VM engine this re-enters the bridge with a fresh
171
+ * evaluation. `itemIndex` is optional and defaults to the current item;
172
+ * the schema mirrors the existing "nonnegative int" constraint used by
173
+ * the node-data RPCs.
174
+ */
175
+ export const evaluateExpressionMessage = z
176
+ .object({
177
+ type: z.literal('evaluateExpression'),
178
+ expression: z.string(),
179
+ itemIndex: z.number().int().nonnegative().optional(),
180
+ })
181
+ .strict();
182
+ /**
183
+ * `ISourceData` — the source record that accompanies a paired-item
184
+ * traversal step. Mirrors the host interface used by
185
+ * `WorkflowDataProxy.getPairedItem`.
186
+ */
187
+ const sourceDataSchema = z
188
+ .object({
189
+ previousNode: z.string(),
190
+ previousNodeOutput: z.number().int().nonnegative().optional(),
191
+ previousNodeRun: z.number().int().nonnegative().optional(),
192
+ })
193
+ .strict();
194
+ /**
195
+ * `IPairedItemData` — one paired-item record. `sourceOverwrite` lets a
196
+ * node override the upstream source while the helper walks the ancestry
197
+ * chain; the field is optional and recurses through the same schema.
198
+ */
199
+ const pairedItemDataSchema = z
200
+ .object({
201
+ item: z.number().int().nonnegative(),
202
+ input: z.number().int().nonnegative().optional(),
203
+ sourceOverwrite: sourceDataSchema.optional(),
204
+ })
205
+ .strict();
206
+ /**
207
+ * `$getPairedItem(destinationNodeName, incomingSourceData, initialPairedItem)` —
208
+ * traverse the paired-item ancestry chain back to the named upstream node
209
+ * and return the matching execution item.
210
+ *
211
+ * Two host-side fields are deliberately omitted from the schema:
212
+ * - `usedMethodName` defaults to `$getPairedItem` on the host; the isolate
213
+ * has no reason to spoof a different method name in the error path.
214
+ * - `nodeBeforeLast` is an internal recursion argument; only the host
215
+ * itself sets it during the recursive walk.
216
+ *
217
+ * `incomingSourceData` is nullable because the host's signature accepts
218
+ * `ISourceData | null` (and throws a paired-item-not-found error when null).
219
+ */
220
+ export const getPairedItemMessage = z
221
+ .object({
222
+ type: z.literal('getPairedItem'),
223
+ destinationNodeName: z.string(),
224
+ incomingSourceData: sourceDataSchema.nullable(),
225
+ initialPairedItem: pairedItemDataSchema,
226
+ })
227
+ .strict();
228
+ /**
229
+ * The full set of messages the bridge will accept. Discriminator is `type`.
230
+ *
231
+ * Use `.strict()` on each member so unknown fields are rejected rather than
232
+ * silently ignored — this catches typos in the runtime stubs and keeps the
233
+ * protocol surface tight.
234
+ */
235
+ export const bridgeMessageSchema = z.discriminatedUnion('type', [
236
+ getNodeFirstMessage,
237
+ getNodeLastMessage,
238
+ getNodeAllMessage,
239
+ getInputFirstMessage,
240
+ getInputLastMessage,
241
+ getInputAllMessage,
242
+ getItemsMessage,
243
+ fromAiMessage,
244
+ getNodePairedItemMessage,
245
+ getNodeItemMatchingMessage,
246
+ getNodeItemMessage,
247
+ evaluateExpressionMessage,
248
+ getPairedItemMessage,
249
+ ]);
250
+ //# sourceMappingURL=bridge-messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge-messages.js","sourceRoot":"","sources":["../../../src/bridge/bridge-messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KAClC,MAAM,CAAC;IACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE;IACtD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE;CACnD,CAAC;KACD,MAAM,EAAE,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KACjC,MAAM,CAAC;IACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAC9B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,QAA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;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KACnC,MAAM,CAAC;IACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC;IAChC,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE;IAC/B,kBAAkB,EAAE,gBAAgB,CAAC,QAAQ,EAAE;IAC/C,iBAAiB,EAAE,oBAAoB;CACvC,CAAC;KACD,MAAM,EAAE,CAAC;AAEX;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC/D,mBAAmB;IACnB,kBAAkB;IAClB,iBAAiB;IACjB,oBAAoB;IACpB,mBAAmB;IACnB,kBAAkB;IAClB,eAAe;IACf,aAAa;IACb,wBAAwB;IACxB,0BAA0B;IAC1B,kBAAkB;IAClB,yBAAyB;IACzB,oBAAoB;CACpB,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { RuntimeBridge, BridgeConfig, ExecuteOptions } from '../types';
1
+ import type { RuntimeBridge, BridgeConfig, ExecuteOptions, WorkflowData } from '../types';
2
2
  /**
3
3
  * IsolatedVmBridge - Runtime bridge using isolated-vm for secure expression evaluation.
4
4
  *
@@ -81,7 +81,13 @@ export declare class IsolatedVmBridge implements RuntimeBridge {
81
81
  * Create an ivm.Reference callback for getting value/metadata at a path.
82
82
  *
83
83
  * Used by createDeepLazyProxy when accessing properties. Returns metadata
84
- * markers for functions, arrays, and objects, or the primitive value directly.
84
+ * markers for arrays and objects, or the primitive value directly.
85
+ *
86
+ * Function-typed values are returned as `undefined` — every callable on
87
+ * the host data surface (`$('Foo').first()`, `$items()`, `$fromAI()`,
88
+ * `$evaluateExpression()`, `$getPairedItem()`) is wired in-isolate via
89
+ * the typed-RPC dispatcher (`callHost`). No expression form should
90
+ * reach a function through this path.
85
91
  *
86
92
  * @param data - Current workflow data to use for callback responses
87
93
  * @private
@@ -97,23 +103,140 @@ export declare class IsolatedVmBridge implements RuntimeBridge {
97
103
  */
98
104
  private createGetArrayElementRef;
99
105
  /**
100
- * Create an ivm.Reference callback for calling functions at a path.
106
+ * Create the single typed-RPC dispatcher.
101
107
  *
102
- * Used when expressions invoke functions from workflow data.
108
+ * The isolate sends one envelope per typed RPC invocation:
109
+ * `callHost({ type: 'getNodeFirst', nodeName, branchIndex?, runIndex? })`
110
+ *
111
+ * Inputs cross a trust boundary, so the dispatcher parses every envelope
112
+ * with the host-side zod schema (`bridgeMessageSchema`) before any
113
+ * dispatch happens. Anything that deviates from the declared shape —
114
+ * unknown `type`, missing required fields, extra unexpected fields,
115
+ * wrong field types — fails the parse and an error sentinel is returned
116
+ * to the caller.
117
+ *
118
+ * After parsing, `switch (msg.type)` dispatches to a private handler with
119
+ * a fully narrowed message type. The operation set is exactly the cases
120
+ * in this switch; the `type` field selects a static branch in source,
121
+ * not a property lookup on a runtime object.
122
+ *
123
+ * @param data - Current workflow data
124
+ * @private
125
+ */
126
+ private createCallHostRef;
127
+ /**
128
+ * Handlers for the `$('Foo').{first,last,all}` typed RPCs.
129
+ *
130
+ * Each handler reads a fixed literal property name off the host-side node
131
+ * proxy — the isolate cannot influence which property is dereferenced.
132
+ * Eliminating `data.$` as a host-callable entirely would require reaching
133
+ * the `WorkflowDataProxy` internals (e.g. `getNodeExecutionOrPinnedData`)
134
+ * rather than the public `$()` API; that's a follow-up.
135
+ *
136
+ * `data.$` is a host-wired function (`WorkflowDataProxy`'s `$`). If it
137
+ * ever isn't, optional chaining short-circuits to `undefined` — the same
138
+ * observable result the runtime's `E()` handler produces from any thrown
139
+ * error here.
140
+ *
141
+ * @private
142
+ */
143
+ private handleGetNodeFirst;
144
+ private handleGetNodeLast;
145
+ private handleGetNodeAll;
146
+ /**
147
+ * Handlers for the `$input.{first,last,all}` typed RPCs.
148
+ *
149
+ * Each reads a fixed literal property name off `data.$input` (the host's
150
+ * `WorkflowDataProxy` input proxy). The host enforces zero arguments on
151
+ * these methods — the schemas have no fields besides `type`, so the
152
+ * isolate cannot pass anything that would trigger the "should have no
153
+ * arguments" error path on the host side.
154
+ *
155
+ * @private
156
+ */
157
+ private handleGetInputFirst;
158
+ private handleGetInputLast;
159
+ private handleGetInputAll;
160
+ /**
161
+ * Handler for `$items(nodeName?, outputIndex?, runIndex?)` — the
162
+ * global accessor for a node's execution data. Reads the literal
163
+ * `$items` property off `data` (host-wired by `WorkflowDataProxy`)
164
+ * and forwards the validated args verbatim. The host applies its own
165
+ * defaults when fields are `undefined`.
166
+ *
167
+ * @private
168
+ */
169
+ private handleGetItems;
170
+ /**
171
+ * Handler for `$fromAI(name, description?, type?, defaultValue?)` and its
172
+ * `$fromAi` / `$fromai` aliases. Reads the literal `$fromAI` property
173
+ * off `data` (host-wired) and forwards the args. The host validates
174
+ * `name` (required + regex) and applies its own resolution / fallback
175
+ * logic, so empty / invalid names surface as the host's structured
176
+ * `ExpressionError` rather than a generic zod parse error.
177
+ *
178
+ * Note: `msg.valueType` maps to the host's third positional parameter
179
+ * (`_type` in `WorkflowDataProxy.handleFromAi`). The bridge protocol
180
+ * renames it to avoid collision with the `type` discriminator on the
181
+ * envelope — the host parameter currently goes unused, but if it ever
182
+ * gains a name (`type`), this mapping should stay explicit.
183
+ *
184
+ * @private
185
+ */
186
+ private handleFromAi;
187
+ /**
188
+ * Handlers for the `$('Foo').pairedItem(itemIndex?)` / `.itemMatching(...)` /
189
+ * `.item` cluster. Three separate typed RPCs, each reading exactly one
190
+ * literal property off the host node proxy.
191
+ *
192
+ * The split is load-bearing: the host's `pairedItemMethod` closure
193
+ * captures which property name the proxy `get` trap saw, and uses
194
+ * that to pick the right error message (e.g. "Missing item index for
195
+ * .itemMatching()") and to decide between method-call vs getter
196
+ * semantics for `.item`. Reading the matching property here lets
197
+ * those host-side branches fire exactly as they do in the legacy
198
+ * engine; no in-isolate validation needed.
199
+ *
200
+ * @private
201
+ */
202
+ private handleGetNodePairedItem;
203
+ private handleGetNodeItemMatching;
204
+ private handleGetNodeItem;
205
+ /**
206
+ * Handler for `$evaluateExpression(expression, itemIndex?)`. Forwards
207
+ * the string to the host's nested-evaluation helper, which re-enters
208
+ * the expression engine on the inner expression. Under the VM engine
209
+ * this round-trips through the bridge again on a fresh evaluation
210
+ * cycle, which is the same shape the legacy engine supports.
211
+ *
212
+ * @private
213
+ */
214
+ private handleEvaluateExpression;
215
+ /**
216
+ * Handler for `$getPairedItem(destinationNodeName, incomingSourceData,
217
+ * initialPairedItem)`. Forwards directly to the host binding, which
218
+ * walks the paired-item ancestry chain back to the named upstream node
219
+ * and returns the matching execution item.
220
+ *
221
+ * The two trailing host parameters — `usedMethodName` and
222
+ * `nodeBeforeLast` — are deliberately not part of the wire protocol:
223
+ * the host's default for `usedMethodName` is already `$getPairedItem`,
224
+ * and `nodeBeforeLast` is an internal recursion argument the host sets
225
+ * during traversal.
103
226
  *
104
- * @param data - Current workflow data to use for callback responses
105
227
  * @private
106
228
  */
107
- private createCallFunctionAtPathRef;
229
+ private handleGetPairedItem;
108
230
  /**
109
231
  * Execute JavaScript code in the isolated context.
110
232
  *
111
233
  * Flow:
112
- * 1. Create three ivm.Reference callbacks scoped to the current data
113
- * 2. Use evalClosureSync to run the code in a closure where $0/$1/$2
114
- * are the callback references no global mutable state
234
+ * 1. Create three ivm.Reference callbacks scoped to the current data:
235
+ * `getValueAtPath`, `getArrayElement`, `callHost`.
236
+ * 2. Use evalClosureSync to run the code in a closure where `$0`/`$1`/`$2`
237
+ * are the callback references — no global mutable state.
115
238
  * 3. buildContext() inside the isolate creates a fresh evaluation context
116
- * from the closure-scoped references
239
+ * from the closure-scoped references.
117
240
  *
118
241
  * Each call gets its own closure, so nested and concurrent evaluations
119
242
  * cannot interfere with each other.
@@ -123,7 +246,7 @@ export declare class IsolatedVmBridge implements RuntimeBridge {
123
246
  * @returns Result of the expression
124
247
  * @throws {Error} If bridge not initialized or execution fails
125
248
  */
126
- execute(code: string, data: Record<string, unknown>, options?: ExecuteOptions): unknown;
249
+ execute(code: string, data: WorkflowData, options?: ExecuteOptions): unknown;
127
250
  /**
128
251
  * Reconstruct an error from serialized isolate data.
129
252
  *
@@ -1 +1 @@
1
- {"version":3,"file":"isolated-vm-bridge.d.ts","sourceRoot":"","sources":["../../../src/bridge/isolated-vm-bridge.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AA0E5E;;;;;;;;;;GAUG;AACH,qBAAa,gBAAiB,YAAW,aAAa;IACrD,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,MAAM,CAAmC;gBAErC,MAAM,GAAE,YAAiB;IAYrC;;;;;;;;;;OAUG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA8BjC;;;;;;;;;;;OAWG;YACW,mBAAmB;IAgCjC;;;;;;;;OAQG;YACW,iBAAiB;IA4B/B;;;;;;;;;;;;;;;;;;;;;;OAsBG;YACW,kBAAkB;IAwBhC;;;;;;;;OAQG;IACH,OAAO,CAAC,uBAAuB;IAgE/B;;;;;;;OAOG;IACH,OAAO,CAAC,wBAAwB;IAyDhC;;;;;;;OAOG;IACH,OAAO,CAAC,2BAA2B;IAkCnC;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO;IAsFvF;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAexB;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB9B;;;;OAIG;IACH,UAAU,IAAI,OAAO;CAGrB"}
1
+ {"version":3,"file":"isolated-vm-bridge.d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