@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.
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/actor.d.ts +1 -479
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +1 -1911
- package/dist/actor.js.map +1 -1
- package/dist/correlation-analysis.d.ts +1 -103
- package/dist/correlation-analysis.d.ts.map +1 -1
- package/dist/correlation-analysis.js +1 -845
- package/dist/correlation-analysis.js.map +1 -1
- package/dist/durable-inbox.d.ts +1 -90
- package/dist/durable-inbox.d.ts.map +1 -1
- package/dist/durable-inbox.js +1 -210
- package/dist/durable-inbox.js.map +1 -1
- package/dist/dynamic-slots.d.ts +1 -72
- package/dist/dynamic-slots.d.ts.map +1 -1
- package/dist/dynamic-slots.js +1 -191
- package/dist/dynamic-slots.js.map +1 -1
- package/dist/edge-ids.d.ts +1 -10
- package/dist/edge-ids.d.ts.map +1 -1
- package/dist/edge-ids.js +1 -14
- package/dist/edge-ids.js.map +1 -1
- package/dist/graph-utils.d.ts +1 -71
- package/dist/graph-utils.d.ts.map +1 -1
- package/dist/graph-utils.js +1 -283
- package/dist/graph-utils.js.map +1 -1
- package/dist/graph.d.ts +1 -203
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +1 -867
- package/dist/graph.js.map +1 -1
- package/dist/inbox.d.ts +1 -264
- package/dist/inbox.d.ts.map +1 -1
- package/dist/inbox.js +1 -551
- package/dist/inbox.js.map +1 -1
- package/dist/index.d.ts +1 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -19
- package/dist/index.js.map +1 -1
- package/dist/io.d.ts +1 -188
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +1 -238
- package/dist/io.js.map +1 -1
- package/dist/loop.d.ts +1 -35
- package/dist/loop.d.ts.map +1 -1
- package/dist/loop.js +1 -165
- package/dist/loop.js.map +1 -1
- package/dist/message-stream.d.ts +1 -31
- package/dist/message-stream.d.ts.map +1 -1
- package/dist/message-stream.js +1 -63
- package/dist/message-stream.js.map +1 -1
- package/dist/predicates.d.ts +1 -7
- package/dist/predicates.d.ts.map +1 -1
- package/dist/predicates.js +1 -7
- package/dist/predicates.js.map +1 -1
- package/dist/run-state.d.ts +1 -64
- package/dist/run-state.d.ts.map +1 -1
- package/dist/run-state.js +1 -41
- package/dist/run-state.js.map +1 -1
- package/dist/runner.d.ts +1 -523
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +1 -2126
- package/dist/runner.js.map +1 -1
- package/dist/substitute-validator.d.ts +1 -43
- package/dist/substitute-validator.d.ts.map +1 -1
- package/dist/substitute-validator.js +1 -168
- package/dist/substitute-validator.js.map +1 -1
- package/dist/supervisor.d.ts +1 -147
- package/dist/supervisor.d.ts.map +1 -1
- package/dist/supervisor.js +1 -286
- package/dist/supervisor.js.map +1 -1
- package/dist/trigger-wakeup.d.ts +1 -122
- package/dist/trigger-wakeup.d.ts.map +1 -1
- package/dist/trigger-wakeup.js +1 -220
- package/dist/trigger-wakeup.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-slots.js","sourceRoot":"","sources":["../src/dynamic-slots.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dynamic-slots.js","sourceRoot":"","sources":["../src/dynamic-slots.ts"],"names":[],"mappings":"AAAA,cAAc,2CAA2C,CAAC"}
|
package/dist/edge-ids.d.ts
CHANGED
|
@@ -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
|
package/dist/edge-ids.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-ids.d.ts","sourceRoot":"","sources":["../src/edge-ids.ts"],"names":[],"mappings":"AAAA
|
|
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
|
package/dist/edge-ids.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-ids.js","sourceRoot":"","sources":["../src/edge-ids.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"edge-ids.js","sourceRoot":"","sources":["../src/edge-ids.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC"}
|
package/dist/graph-utils.d.ts
CHANGED
|
@@ -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
|
|
1
|
+
{"version":3,"file":"graph-utils.d.ts","sourceRoot":"","sources":["../src/graph-utils.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC"}
|
package/dist/graph-utils.js
CHANGED
|
@@ -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
|
package/dist/graph-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-utils.js","sourceRoot":"","sources":["../src/graph-utils.ts"],"names":[],"mappings":"AAAA
|
|
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
|
package/dist/graph.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC"}
|