@nodetool-ai/kernel 0.8.8 → 0.8.9-bootstrap.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/.nodetool-build-stamp +1 -1
  2. package/dist/actor.d.ts +1 -479
  3. package/dist/actor.d.ts.map +1 -1
  4. package/dist/actor.js +1 -1911
  5. package/dist/actor.js.map +1 -1
  6. package/dist/correlation-analysis.d.ts +1 -103
  7. package/dist/correlation-analysis.d.ts.map +1 -1
  8. package/dist/correlation-analysis.js +1 -845
  9. package/dist/correlation-analysis.js.map +1 -1
  10. package/dist/durable-inbox.d.ts +1 -90
  11. package/dist/durable-inbox.d.ts.map +1 -1
  12. package/dist/durable-inbox.js +1 -210
  13. package/dist/durable-inbox.js.map +1 -1
  14. package/dist/dynamic-slots.d.ts +1 -72
  15. package/dist/dynamic-slots.d.ts.map +1 -1
  16. package/dist/dynamic-slots.js +1 -191
  17. package/dist/dynamic-slots.js.map +1 -1
  18. package/dist/edge-ids.d.ts +1 -10
  19. package/dist/edge-ids.d.ts.map +1 -1
  20. package/dist/edge-ids.js +1 -14
  21. package/dist/edge-ids.js.map +1 -1
  22. package/dist/graph-utils.d.ts +1 -71
  23. package/dist/graph-utils.d.ts.map +1 -1
  24. package/dist/graph-utils.js +1 -283
  25. package/dist/graph-utils.js.map +1 -1
  26. package/dist/graph.d.ts +1 -203
  27. package/dist/graph.d.ts.map +1 -1
  28. package/dist/graph.js +1 -867
  29. package/dist/graph.js.map +1 -1
  30. package/dist/inbox.d.ts +1 -264
  31. package/dist/inbox.d.ts.map +1 -1
  32. package/dist/inbox.js +1 -551
  33. package/dist/inbox.js.map +1 -1
  34. package/dist/index.d.ts +1 -19
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +1 -19
  37. package/dist/index.js.map +1 -1
  38. package/dist/io.d.ts +1 -188
  39. package/dist/io.d.ts.map +1 -1
  40. package/dist/io.js +1 -238
  41. package/dist/io.js.map +1 -1
  42. package/dist/loop.d.ts +1 -35
  43. package/dist/loop.d.ts.map +1 -1
  44. package/dist/loop.js +1 -165
  45. package/dist/loop.js.map +1 -1
  46. package/dist/message-stream.d.ts +1 -31
  47. package/dist/message-stream.d.ts.map +1 -1
  48. package/dist/message-stream.js +1 -63
  49. package/dist/message-stream.js.map +1 -1
  50. package/dist/predicates.d.ts +1 -7
  51. package/dist/predicates.d.ts.map +1 -1
  52. package/dist/predicates.js +1 -7
  53. package/dist/predicates.js.map +1 -1
  54. package/dist/run-state.d.ts +1 -64
  55. package/dist/run-state.d.ts.map +1 -1
  56. package/dist/run-state.js +1 -41
  57. package/dist/run-state.js.map +1 -1
  58. package/dist/runner.d.ts +1 -523
  59. package/dist/runner.d.ts.map +1 -1
  60. package/dist/runner.js +1 -2126
  61. package/dist/runner.js.map +1 -1
  62. package/dist/substitute-validator.d.ts +1 -43
  63. package/dist/substitute-validator.d.ts.map +1 -1
  64. package/dist/substitute-validator.js +1 -168
  65. package/dist/substitute-validator.js.map +1 -1
  66. package/dist/supervisor.d.ts +1 -147
  67. package/dist/supervisor.d.ts.map +1 -1
  68. package/dist/supervisor.js +1 -286
  69. package/dist/supervisor.js.map +1 -1
  70. package/dist/trigger-wakeup.d.ts +1 -122
  71. package/dist/trigger-wakeup.d.ts.map +1 -1
  72. package/dist/trigger-wakeup.js +1 -220
  73. package/dist/trigger-wakeup.js.map +1 -1
  74. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic-slots.js","sourceRoot":"","sources":["../src/dynamic-slots.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE5E;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,IAAiC;IAEjC,IAAI,CAAC,IAAI;Q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;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAsC,EACtC,KAAoC;IAEpC,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAChE,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"dynamic-slots.js","sourceRoot":"","sources":["../src/dynamic-slots.ts"],"names":[],"mappings":"AAAA,cAAc,2CAA2C,CAAC"}
@@ -1,11 +1,2 @@
1
- /**
2
- * Build a synthetic, deterministic source_edge_id for a graph edge that does
3
- * not carry a saved id.
4
- */
5
- export declare function syntheticEdgeId(sourceNodeId: string, sourceHandle: string, targetNodeId: string, targetHandle: string): string;
6
- /**
7
- * Build a synthetic source_edge_id for values pushed in via the runner's
8
- * external input API.
9
- */
10
- export declare function externalEdgeId(inputName: string, sourceHandle: string): string;
1
+ export * from "@nodetool-ai/execution-core/edge-ids";
11
2
  //# sourceMappingURL=edge-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"edge-ids.d.ts","sourceRoot":"","sources":["../src/edge-ids.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,MAAM,CAER"}
1
+ {"version":3,"file":"edge-ids.d.ts","sourceRoot":"","sources":["../src/edge-ids.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC"}
package/dist/edge-ids.js CHANGED
@@ -1,15 +1,2 @@
1
- /**
2
- * Build a synthetic, deterministic source_edge_id for a graph edge that does
3
- * not carry a saved id.
4
- */
5
- export function syntheticEdgeId(sourceNodeId, sourceHandle, targetNodeId, targetHandle) {
6
- return `${sourceNodeId}:${sourceHandle}->${targetNodeId}:${targetHandle}`;
7
- }
8
- /**
9
- * Build a synthetic source_edge_id for values pushed in via the runner's
10
- * external input API.
11
- */
12
- export function externalEdgeId(inputName, sourceHandle) {
13
- return `external:${inputName}:${sourceHandle}`;
14
- }
1
+ export * from "@nodetool-ai/execution-core/edge-ids";
15
2
  //# sourceMappingURL=edge-ids.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"edge-ids.js","sourceRoot":"","sources":["../src/edge-ids.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,YAAoB,EACpB,YAAoB,EACpB,YAAoB,EACpB,YAAoB;IAEpB,OAAO,GAAG,YAAY,IAAI,YAAY,KAAK,YAAY,IAAI,YAAY,EAAE,CAAC;AAC5E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,SAAiB,EACjB,YAAoB;IAEpB,OAAO,YAAY,SAAS,IAAI,YAAY,EAAE,CAAC;AACjD,CAAC"}
1
+ {"version":3,"file":"edge-ids.js","sourceRoot":"","sources":["../src/edge-ids.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC"}
@@ -1,72 +1,2 @@
1
- /**
2
- * Graph utilities for node and edge operations.
3
- *
4
- * Port of src/nodetool/workflows/graph_utils.py.
5
- */
6
- import type { Edge, GraphData, NodeDescriptor } from "@nodetool-ai/protocol";
7
- import { Graph } from "./graph.js";
8
- /**
9
- * Find a node by ID or throw.
10
- */
11
- export declare function findNodeOrThrow(graph: Graph, nodeId: string): NodeDescriptor;
12
- /**
13
- * Returns mapping of targetHandle -> source output type string.
14
- *
15
- * For each incoming edge to nodeId, looks up the source node's outputs
16
- * to find the type of the sourceHandle.
17
- */
18
- export declare function getNodeInputTypes(graph: Graph, nodeId: string): Record<string, string | undefined>;
19
- /**
20
- * BFS downstream subgraph starting from (nodeId, sourceHandle).
21
- *
22
- * Returns the initial edges from nodeId/sourceHandle, plus all
23
- * reachable downstream nodes and edges.
24
- */
25
- export declare function getDownstreamSubgraph(graph: Graph, nodeId: string, sourceHandle: string): {
26
- initialEdges: Edge[];
27
- nodes: NodeDescriptor[];
28
- edges: Edge[];
29
- };
30
- /**
31
- * Returns true if a node is marked as bypassed via ui_properties.bypassed.
32
- */
33
- export declare function isNodeBypassed(node: NodeDescriptor): boolean;
34
- /**
35
- * Look up the declared type string of a node's input (property) handle.
36
- *
37
- * Checks propertyTypes first (the authoritative map after graph load), then
38
- * a declared dynamic slot (`dynamic_inputs`), then falls back to a property
39
- * value carrying an explicit `type` field for
40
- * backwards compatibility with raw graph payloads. Plain string property
41
- * values are runtime data (saved literals), never type names — treating
42
- * them as types made bypass rewrites drop edges as "incompatible"
43
- * (mirrors Graph.validateEdgeTypes).
44
- */
45
- export declare function getInputTypeString(node: NodeDescriptor | undefined, handle: string): string | undefined;
46
- /**
47
- * Rewrite a graph to route around nodes marked with
48
- * `ui_properties.bypassed === true`.
49
- *
50
- * For each bypassed node and each of its outgoing data edges, we look for
51
- * an incoming data edge whose source output type is compatible with the
52
- * outgoing edge's target input type. If one is found, a new edge is
53
- * created directly from the upstream source to the downstream target,
54
- * preserving the downstream handle and any edge metadata (id, ui_properties,
55
- * edge_type). Outgoing edges with no type-compatible input are dropped.
56
- *
57
- * When multiple incoming edges would match an outgoing edge, preference is
58
- * given to an incoming edge whose targetHandle matches the outgoing edge's
59
- * sourceHandle (name match), falling back to the first type-compatible one.
60
- *
61
- * Chained bypassed nodes (A → B(bypassed) → C(bypassed) → D) are handled
62
- * by iterating until no further bypassed node can be rewritten — each
63
- * iteration replaces bypassed sources with their already-resolved upstream
64
- * source so that a chain collapses into a direct edge from the first
65
- * non-bypassed source to the first non-bypassed target.
66
- *
67
- * Control edges (edge_type === "control") touching a bypassed node are
68
- * dropped: bypassing intentionally removes the node from execution, so
69
- * control connections to/from it no longer have a meaningful target.
70
- */
71
- export declare function rewriteBypassedNodes(data: GraphData): GraphData;
1
+ export * from "@nodetool-ai/execution-core/graph-utils";
72
2
  //# sourceMappingURL=graph-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graph-utils.d.ts","sourceRoot":"","sources":["../src/graph-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE7E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAInC;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAM5E;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,sCAkBf;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM;;;;EA0DrB;AAMD;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAK5D;AAaD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,cAAc,GAAG,SAAS,EAChC,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,SAAS,CAkBpB;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,CA+G/D"}
1
+ {"version":3,"file":"graph-utils.d.ts","sourceRoot":"","sources":["../src/graph-utils.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC"}
@@ -1,284 +1,2 @@
1
- /**
2
- * Graph utilities for node and edge operations.
3
- *
4
- * Port of src/nodetool/workflows/graph_utils.py.
5
- */
6
- import { isControlEdge, TypeMetadata } from "@nodetool-ai/protocol";
7
- import { getDynamicSlotTypeString } from "./dynamic-slots.js";
8
- import { isObjectValue, isString } from "./predicates.js";
9
- /**
10
- * Find a node by ID or throw.
11
- */
12
- export function findNodeOrThrow(graph, nodeId) {
13
- const node = graph.findNode(nodeId);
14
- if (!node) {
15
- throw new Error(`Node with ID ${nodeId} does not exist`);
16
- }
17
- return node;
18
- }
19
- /**
20
- * Returns mapping of targetHandle -> source output type string.
21
- *
22
- * For each incoming edge to nodeId, looks up the source node's outputs
23
- * to find the type of the sourceHandle.
24
- */
25
- export function getNodeInputTypes(graph, nodeId) {
26
- const result = {};
27
- for (const edge of graph.findIncomingEdges(nodeId)) {
28
- const sourceNode = graph.findNode(edge.source);
29
- if (sourceNode &&
30
- sourceNode.outputs &&
31
- Object.hasOwn(sourceNode.outputs, edge.sourceHandle)) {
32
- result[edge.targetHandle] = sourceNode.outputs[edge.sourceHandle];
33
- }
34
- else {
35
- result[edge.targetHandle] = undefined;
36
- }
37
- }
38
- return result;
39
- }
40
- /**
41
- * BFS downstream subgraph starting from (nodeId, sourceHandle).
42
- *
43
- * Returns the initial edges from nodeId/sourceHandle, plus all
44
- * reachable downstream nodes and edges.
45
- */
46
- export function getDownstreamSubgraph(graph, nodeId, sourceHandle) {
47
- // Find initial edges from nodeId with matching sourceHandle
48
- const initialEdges = graph
49
- .findOutgoingEdges(nodeId)
50
- .filter((e) => e.sourceHandle === sourceHandle);
51
- const includedNodeIds = new Set();
52
- // Stryker disable next-line ArrayDeclaration: a non-empty seed is equivalent — a bogus Edge has no source/target in includedNodeIds and is dropped by the endpoint filter below
53
- const includedEdges = [];
54
- // Seed BFS with targets of initial edges
55
- // Stryker disable next-line ArrayDeclaration: a non-empty seed is equivalent — a bogus node id has no outgoing edges, so BFS adds nothing for it
56
- const queue = [];
57
- const enqueued = new Set();
58
- for (const e of initialEdges) {
59
- includedEdges.push(e);
60
- includedNodeIds.add(e.target);
61
- includedNodeIds.add(e.source);
62
- // Two initial edges can share a target (one output feeding two handles
63
- // of the same node); enqueueing it twice would duplicate all of its
64
- // outgoing edges in the result.
65
- if (!enqueued.has(e.target)) {
66
- enqueued.add(e.target);
67
- queue.push(e.target);
68
- }
69
- }
70
- // BFS over outgoing edges
71
- while (queue.length > 0) {
72
- const current = queue.shift();
73
- for (const edge of graph.findOutgoingEdges(current)) {
74
- includedEdges.push(edge);
75
- if (!includedNodeIds.has(edge.target)) {
76
- includedNodeIds.add(edge.target);
77
- queue.push(edge.target);
78
- }
79
- }
80
- }
81
- // Collect nodes, skipping any missing
82
- const nodes = [];
83
- for (const nid of includedNodeIds) {
84
- const node = graph.findNode(nid);
85
- if (node)
86
- nodes.push(node);
87
- }
88
- // Filter edges to those with both endpoints in included set. This is a
89
- // defensive no-op given the BFS above (every pushed edge's source is the
90
- // dequeued node and its target is added to the set), so its mutants are
91
- // equivalent — kept for safety against future changes to the BFS.
92
- // Stryker disable next-line MethodExpression: defensive no-op filter (see above)
93
- const filteredEdges = includedEdges.filter(
94
- // Stryker disable next-line ConditionalExpression,LogicalOperator: defensive no-op filter — both endpoints are always in the set
95
- (e) => includedNodeIds.has(e.source) && includedNodeIds.has(e.target));
96
- return { initialEdges, nodes, edges: filteredEdges };
97
- }
98
- // ---------------------------------------------------------------------------
99
- // Bypass rewriting
100
- // ---------------------------------------------------------------------------
101
- /**
102
- * Returns true if a node is marked as bypassed via ui_properties.bypassed.
103
- */
104
- export function isNodeBypassed(node) {
105
- const ui = node.ui_properties;
106
- // Stryker disable next-line ConditionalExpression: the `typeof ui !== "object"` operand is equivalent to drop — a truthy non-object (string/number) never throws on `.bypassed` and still yields `=== true → false`
107
- if (!isObjectValue(ui))
108
- return false;
109
- return ui.bypassed === true;
110
- }
111
- /**
112
- * Look up the declared type string of a node's output handle.
113
- */
114
- function getOutputTypeString(node, handle) {
115
- if (!node || !node.outputs)
116
- return undefined;
117
- return Object.hasOwn(node.outputs, handle) ? node.outputs[handle] : undefined;
118
- }
119
- /**
120
- * Look up the declared type string of a node's input (property) handle.
121
- *
122
- * Checks propertyTypes first (the authoritative map after graph load), then
123
- * a declared dynamic slot (`dynamic_inputs`), then falls back to a property
124
- * value carrying an explicit `type` field for
125
- * backwards compatibility with raw graph payloads. Plain string property
126
- * values are runtime data (saved literals), never type names — treating
127
- * them as types made bypass rewrites drop edges as "incompatible"
128
- * (mirrors Graph.validateEdgeTypes).
129
- */
130
- export function getInputTypeString(node, handle) {
131
- if (!node)
132
- return undefined;
133
- const fromPropertyTypes = node.propertyTypes?.[handle];
134
- if (fromPropertyTypes)
135
- return fromPropertyTypes;
136
- // A declared dynamic slot is typed; an undeclared one stays undefined so
137
- // typesCompatible() keeps treating it as `any`.
138
- const fromSlot = getDynamicSlotTypeString(node, handle);
139
- if (fromSlot)
140
- return fromSlot;
141
- const props = node.properties;
142
- if (props) {
143
- const val = props[handle];
144
- if (isObjectValue(val) && "type" in val) {
145
- const t = val.type;
146
- // Stryker disable next-line ConditionalExpression: forcing this true is equivalent — returning a non-string `t` vs undefined are indistinguishable downstream (typesCompatible treats both as compatible)
147
- if (isString(t))
148
- return t;
149
- }
150
- }
151
- return undefined;
152
- }
153
- /**
154
- * Return true when two type strings are compatible according to
155
- * TypeMetadata rules. Missing type info on either side is treated as
156
- * compatible ("any") so that bypass still works on dynamic nodes where
157
- * handle types are not statically declared.
158
- */
159
- function typesCompatible(sourceType, targetType) {
160
- // Stryker disable next-line ConditionalExpression,LogicalOperator: equivalent — removing/weakening this guard still returns true for a missing type, because TypeMetadata.fromString(undefined) throws and the catch below returns true
161
- if (!sourceType || !targetType)
162
- return true;
163
- try {
164
- const s = TypeMetadata.fromString(sourceType);
165
- const t = TypeMetadata.fromString(targetType);
166
- return s.isCompatibleWith(t);
167
- }
168
- catch {
169
- return true;
170
- }
171
- }
172
- /**
173
- * Rewrite a graph to route around nodes marked with
174
- * `ui_properties.bypassed === true`.
175
- *
176
- * For each bypassed node and each of its outgoing data edges, we look for
177
- * an incoming data edge whose source output type is compatible with the
178
- * outgoing edge's target input type. If one is found, a new edge is
179
- * created directly from the upstream source to the downstream target,
180
- * preserving the downstream handle and any edge metadata (id, ui_properties,
181
- * edge_type). Outgoing edges with no type-compatible input are dropped.
182
- *
183
- * When multiple incoming edges would match an outgoing edge, preference is
184
- * given to an incoming edge whose targetHandle matches the outgoing edge's
185
- * sourceHandle (name match), falling back to the first type-compatible one.
186
- *
187
- * Chained bypassed nodes (A → B(bypassed) → C(bypassed) → D) are handled
188
- * by iterating until no further bypassed node can be rewritten — each
189
- * iteration replaces bypassed sources with their already-resolved upstream
190
- * source so that a chain collapses into a direct edge from the first
191
- * non-bypassed source to the first non-bypassed target.
192
- *
193
- * Control edges (edge_type === "control") touching a bypassed node are
194
- * dropped: bypassing intentionally removes the node from execution, so
195
- * control connections to/from it no longer have a meaningful target.
196
- */
197
- export function rewriteBypassedNodes(data) {
198
- const bypassedIds = new Set(data.nodes.filter(isNodeBypassed).map((n) => n.id));
199
- if (bypassedIds.size === 0) {
200
- return data;
201
- }
202
- const nodeById = new Map(data.nodes.map((n) => [n.id, n]));
203
- let currentEdges = [...data.edges];
204
- const processed = new Set();
205
- // Iterate: process bypassed nodes whose bypassed predecessors have all
206
- // already been resolved. This guarantees a chain collapses in source→
207
- // target order.
208
- let didChange = true;
209
- while (didChange) {
210
- didChange = false;
211
- for (const bypassId of bypassedIds) {
212
- if (processed.has(bypassId))
213
- continue;
214
- const incoming = currentEdges.filter((e) => e.target === bypassId);
215
- // This skip only orders processing so a chain collapses in one tidy
216
- // pass; the outer `while (didChange)` re-processes, so out-of-order
217
- // visits still converge to the same final edge set (see the
218
- // "collapses ... out of dependency order" test). The mutants on this
219
- // condition therefore don't change observable output.
220
- // Stryker disable next-line MethodExpression,ArrowFunction,ConditionalExpression,BooleanLiteral: processing-order optimization — converges to the same final edges either way
221
- const hasUnprocessedBypassedUpstream = incoming.some((e) => bypassedIds.has(e.source) && !processed.has(e.source));
222
- // Stryker disable next-line ConditionalExpression: see above — skipping only reorders processing; the while-loop converges regardless
223
- if (hasUnprocessedBypassedUpstream)
224
- continue;
225
- const incomingData = incoming.filter((e) => !isControlEdge(e));
226
- const outgoing = currentEdges.filter((e) => e.source === bypassId);
227
- const outgoingData = outgoing.filter((e) => !isControlEdge(e));
228
- const reroutedEdges = [];
229
- for (const outEdge of outgoingData) {
230
- const bypassNode = nodeById.get(bypassId);
231
- const bypassOutputType = getOutputTypeString(bypassNode, outEdge.sourceHandle);
232
- const targetNode = nodeById.get(outEdge.target);
233
- const targetInputType = getInputTypeString(targetNode, outEdge.targetHandle);
234
- // Prefer an incoming edge whose target handle matches the
235
- // outgoing source handle (name-based pairing), then fall back to
236
- // the first incoming edge whose source output type is compatible
237
- // with the downstream target's input type.
238
- const candidatesCompatibleWithDownstream = [];
239
- const candidatesCompatibleWithBypassOutput = [];
240
- for (const inEdge of incomingData) {
241
- const sourceNode = nodeById.get(inEdge.source);
242
- const sourceOutputType = getOutputTypeString(sourceNode, inEdge.sourceHandle);
243
- if (!typesCompatible(sourceOutputType, targetInputType))
244
- continue;
245
- candidatesCompatibleWithDownstream.push(inEdge);
246
- if (typesCompatible(sourceOutputType, bypassOutputType)) {
247
- candidatesCompatibleWithBypassOutput.push(inEdge);
248
- }
249
- }
250
- const preferredCandidates = candidatesCompatibleWithBypassOutput.length > 0
251
- ? candidatesCompatibleWithBypassOutput
252
- : candidatesCompatibleWithDownstream;
253
- const candidates = [];
254
- for (const candidate of preferredCandidates) {
255
- if (candidate.targetHandle === outEdge.sourceHandle) {
256
- candidates.unshift(candidate);
257
- }
258
- else {
259
- candidates.push(candidate);
260
- }
261
- }
262
- const matched = candidates[0];
263
- if (!matched)
264
- continue;
265
- reroutedEdges.push({
266
- ...outEdge,
267
- source: matched.source,
268
- sourceHandle: matched.sourceHandle
269
- });
270
- }
271
- // Drop all edges touching the bypassed node and append the rerouted
272
- // ones. Control edges attached to the bypassed node are dropped
273
- // here — bypassing removes the node from execution entirely.
274
- currentEdges = currentEdges.filter((e) => e.source !== bypassId && e.target !== bypassId);
275
- currentEdges.push(...reroutedEdges);
276
- processed.add(bypassId);
277
- didChange = true;
278
- }
279
- }
280
- // Remove bypassed nodes themselves from the node list.
281
- const remainingNodes = data.nodes.filter((n) => !bypassedIds.has(n.id));
282
- return { nodes: remainingNodes, edges: currentEdges };
283
- }
1
+ export * from "@nodetool-ai/execution-core/graph-utils";
284
2
  //# sourceMappingURL=graph-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"graph-utils.js","sourceRoot":"","sources":["../src/graph-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE1D;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,MAAc;IAC1D,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,gBAAgB,MAAM,iBAAiB,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAY,EACZ,MAAc;IAEd,MAAM,MAAM,GAAuC,EAAE,CAAC;IAEtD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/C,IACE,UAAU;YACV,UAAU,CAAC,OAAO;YAClB,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,EACpD,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC,OAAO,C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AAO,CAAC,YAAY;iBACnC,CAAC,CAAC;YACL,CAAC;YAED,oEAAoE;YACpE,iEAAiE;YACjE,6DAA6D;YAC7D,YAAY,GAAG,YAAY,CAAC,MAAM,CAChC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,KAAK,QAAQ,CACtD,CAAC;YACF,YAAY,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC;YAEpC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC;IACH,CAAC;IAED,uDAAuD;IACvD,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAExE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;AACxD,CAAC"}
1
+ {"version":3,"file":"graph-utils.js","sourceRoot":"","sources":["../src/graph-utils.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC"}
package/dist/graph.d.ts CHANGED
@@ -1,204 +1,2 @@
1
- /**
2
- * Graph model and validation.
3
- *
4
- * Port of src/nodetool/workflows/graph.py:
5
- * - Node/edge lookup with O(1) indexing
6
- * - Edge type validation
7
- * - Control edge validation with cycle detection
8
- * - Topological sort (Kahn's algorithm)
9
- * - Streaming upstream computation
10
- */
11
- import type { Edge, NodeDescriptor, HydratedNodeDescriptor, GraphData, HydratedGraphData } from "@nodetool-ai/protocol";
12
- import { type DerivedDynamicSlots } from "./dynamic-slots.js";
13
- export interface GraphValidationIssue {
14
- nodeId?: string;
15
- nodeType?: string;
16
- property?: string;
17
- message: string;
18
- }
19
- export declare class GraphValidationError extends Error {
20
- readonly issues: GraphValidationIssue[];
21
- constructor(message: string, issues?: GraphValidationIssue[]);
22
- }
23
- export interface GraphFromDictOptions {
24
- skipErrors?: boolean;
25
- allowUndefinedProperties?: boolean;
26
- validateNodeType?: (nodeType: string) => boolean;
27
- }
28
- export interface ResolvedNodeType {
29
- nodeType: string;
30
- propertyTypes?: Record<string, string>;
31
- outputs?: Record<string, string>;
32
- supportsDynamicInputs?: boolean;
33
- descriptorDefaults?: Partial<NodeDescriptor>;
34
- /**
35
- * Flags only the individual node can answer, resolved from its saved
36
- * properties. `descriptorDefaults` carries one value per node *type*, which
37
- * cannot express a mode that lives in a node's own properties — a Code node
38
- * streams its inputs when its body says so. When present, the answer takes
39
- * the slot the matching `descriptorDefaults` flag holds, and the kernel stays
40
- * registry-agnostic: it calls a function it was handed, as it already does
41
- * for type resolution.
42
- */
43
- resolveInstanceFlags?: (node: {
44
- properties?: Record<string, unknown>;
45
- }) => {
46
- is_streaming_input?: boolean;
47
- };
48
- /**
49
- * Dynamic slots the individual node derives from its saved properties, such
50
- * as the Save nodes of a Comfy runner's `workflow`. Merged under the slots
51
- * saved on the node, so a graph built without the editor (over the API,
52
- * where nothing declared the slots) can still wire them.
53
- */
54
- resolveInstanceSlots?: (node: {
55
- properties?: Record<string, unknown>;
56
- }) => DerivedDynamicSlots | undefined;
57
- }
58
- export type NodeTypeResolver = ((nodeType: string) => Promise<ResolvedNodeType | null> | ResolvedNodeType | null) | {
59
- resolveNodeType: (nodeType: string) => Promise<ResolvedNodeType | null> | ResolvedNodeType | null;
60
- };
61
- export interface GraphLoadOptions extends Omit<GraphFromDictOptions, "validateNodeType"> {
62
- resolver: NodeTypeResolver;
63
- }
64
- /**
65
- * Mark a code-constructed graph as hydrated by defaulting absent behavior
66
- * flags to false. For graphs built in code (tests, DSL output) where the
67
- * author already set the flags that matter. NOT a substitute for registry
68
- * hydration of client/wire graphs — there an absent flag means "unknown",
69
- * not "off"; use `Graph.loadFromDict` or node-sdk's `hydrateGraphNodeFlags`.
70
- */
71
- export declare function withExplicitNodeFlags(graph: GraphData): HydratedGraphData;
72
- /** A Graph whose descriptors carry resolved behavior flags (see loadFromDict). */
73
- export interface HydratedGraph extends Graph {
74
- readonly nodes: ReadonlyArray<HydratedNodeDescriptor>;
75
- }
76
- export declare class Graph {
77
- readonly nodes: ReadonlyArray<NodeDescriptor>;
78
- readonly edges: ReadonlyArray<Edge>;
79
- /** O(1) node lookup by id */
80
- private _nodeIndex;
81
- /** Edges keyed by target node id */
82
- private _incomingEdges;
83
- /** Edges keyed by source node id */
84
- private _outgoingEdges;
85
- /** Edges keyed by `${source}:${sourceHandle}` for O(1) lookup */
86
- private _outgoingByHandle;
87
- /** Cache: nodes that have streaming upstream */
88
- private _streamingUpstream;
89
- constructor(data: GraphData);
90
- /**
91
- * Create a Graph from a plain object, validating the input shape.
92
- * Throws GraphValidationError if nodes or edges are missing or not arrays.
93
- */
94
- static fromDict(data: unknown, options?: GraphFromDictOptions): Graph;
95
- static loadFromDict(data: unknown, options: GraphLoadOptions): Promise<HydratedGraph>;
96
- private _buildIndices;
97
- /**
98
- * Return the node list with is_controlled set on every control-edge target.
99
- * In Python, BaseNode.is_controlled() is a runtime method that checks the
100
- * graph context; in TS we set the flag on the descriptor so the actor knows
101
- * to use _runControlled(). Node objects are caller-owned (the runner passes
102
- * `graphData.nodes` straight through), so a target lacking the flag is
103
- * replaced with a shallow copy — the original is left untouched. Every other
104
- * node keeps its identity.
105
- */
106
- private static _withControlledFlags;
107
- findNode(id: string): NodeDescriptor | undefined;
108
- /**
109
- * Return all edges where target == nodeId (incoming edges).
110
- */
111
- findIncomingEdges(nodeId: string): Edge[];
112
- /**
113
- * Return all edges where source == nodeId (outgoing edges).
114
- */
115
- findOutgoingEdges(nodeId: string): Edge[];
116
- /**
117
- * Return edges matching a specific (source, sourceHandle) pair. O(1) lookup.
118
- * Mirrors Python's find_edges(source, source_handle).
119
- */
120
- findEdges(source: string, sourceHandle: string): Edge[];
121
- /**
122
- * Return data (non-control) edges targeting a node.
123
- */
124
- findDataEdges(nodeId: string): Edge[];
125
- getControlEdges(): Edge[];
126
- getControlEdges(targetId: string): Edge[];
127
- getControllerNodes(): NodeDescriptor[];
128
- getControllerNodes(targetId: string): NodeDescriptor[];
129
- getControlledNodes(): NodeDescriptor[];
130
- getControlledNodes(sourceId: string): string[];
131
- /**
132
- * Return nodes that have no incoming data edges (source nodes).
133
- */
134
- inputNodes(): NodeDescriptor[];
135
- /**
136
- * Return nodes that have no outgoing data edges (sink nodes).
137
- */
138
- outputNodes(): NodeDescriptor[];
139
- /**
140
- * Check whether a node has streaming upstream (i.e. is downstream
141
- * of a streaming-output node via data edges).
142
- */
143
- hasStreamingUpstream(nodeId: string): boolean;
144
- private _computeStreamingUpstream;
145
- /**
146
- * Returns nodes grouped into execution levels.
147
- * Nodes in the same level have no inter-dependencies and can run
148
- * concurrently. Only data edges define the ordering.
149
- */
150
- topologicalSort(parentId?: string | null): NodeDescriptor[][];
151
- /**
152
- * Build a JSON Schema object from input nodes (type contains "Input").
153
- * Each input node contributes a property named after node.name (or node.id).
154
- */
155
- getInputSchema(): {
156
- properties: Record<string, unknown>;
157
- required: string[];
158
- };
159
- /**
160
- * Build a JSON Schema object from output nodes (`nodetool.output.*`).
161
- */
162
- getOutputSchema(): {
163
- properties: Record<string, unknown>;
164
- required: string[];
165
- };
166
- private _buildSchema;
167
- /**
168
- * Validate the graph structure.
169
- * Throws GraphValidationError on problems.
170
- */
171
- validate(): void;
172
- /**
173
- * Verify that every data edge's `sourceHandle` is a declared output of its
174
- * source node. Without this, an edge wired to a nonexistent output handle
175
- * passes validation and then silently never delivers a value at runtime
176
- * (`validateEdgeTypes` skips it for lack of a source type), leaving the
177
- * target node waiting forever.
178
- *
179
- * Only enforced when the source node declares a non-empty static `outputs`
180
- * map and does not produce dynamic outputs (whose handles aren't known
181
- * statically). Nodes without output metadata are left untouched.
182
- */
183
- validateDataEdgeSourceHandles(): void;
184
- /**
185
- * Verify that every edge references existing nodes.
186
- */
187
- validateEdgeEndpoints(): void;
188
- /**
189
- * Validate control edges:
190
- * - Source and target must exist.
191
- * - Target handle must be "__control__".
192
- * - No cycles in control edges.
193
- */
194
- validateControlEdges(): void;
195
- /**
196
- * Validate type compatibility between connected edge endpoints.
197
- * For each data edge, checks if the source output type is compatible
198
- * with the target input type. Compatible means: same type, one is "any",
199
- * or numeric widening (int -> float).
200
- */
201
- validateEdgeTypes(): void;
202
- private _checkCircularControl;
203
- }
1
+ export * from "@nodetool-ai/execution-core/graph";
204
2
  //# sourceMappingURL=graph.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAEV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACtB,SAAS,EACT,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAY/B,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,MAAM,EAAE,oBAAoB,EAAE,CAAC;IACxC,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,oBAAoB,EAAO,EAI/D;CACF;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CAClD;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,OAAO,CAAC,EAAE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