@bian-womp/spark-graph 0.2.28 → 0.2.30
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/lib/cjs/index.cjs +23 -8
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/runtime/GraphRuntime.d.ts +2 -28
- package/lib/cjs/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/lib/esm/index.js +23 -8
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/runtime/GraphRuntime.d.ts +2 -28
- package/lib/esm/src/runtime/GraphRuntime.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RuntimeValue, RuntimeInvalidate, RuntimeError, RuntimeStats, ResolvedHandles, GraphDefinition
|
|
1
|
+
import type { RuntimeValue, RuntimeInvalidate, RuntimeError, RuntimeStats, ResolvedHandles, GraphDefinition } from "@bian-womp/spark-protocol";
|
|
2
2
|
import type { RuntimeNodeStats } from "../core/types";
|
|
3
3
|
import { Registry } from "../builder/Registry";
|
|
4
4
|
export type RuntimeEventListener<K extends RuntimeEventName> = (e: RuntimeEventMap[K]) => void;
|
|
@@ -50,33 +50,7 @@ export declare class GraphRuntime {
|
|
|
50
50
|
} | undefined;
|
|
51
51
|
getEnvironment(): Record<string, unknown>;
|
|
52
52
|
setEnvironment(env: Record<string, unknown>): void;
|
|
53
|
-
getGraphDef():
|
|
54
|
-
nodes: {
|
|
55
|
-
nodeId: string;
|
|
56
|
-
typeId: string;
|
|
57
|
-
params: {
|
|
58
|
-
[x: string]: unknown;
|
|
59
|
-
policy?: Partial<ExecutionPolicy>;
|
|
60
|
-
} | undefined;
|
|
61
|
-
resolvedHandles: {
|
|
62
|
-
inputs: Record<string, import("@bian-womp/spark-protocol").InputHandleDescriptor>;
|
|
63
|
-
outputs: Record<string, import("@bian-womp/spark-protocol").DataTypeId | import("@bian-womp/spark-protocol").DataTypeId[]>;
|
|
64
|
-
inputDefaults: Record<string, unknown>;
|
|
65
|
-
} | undefined;
|
|
66
|
-
}[];
|
|
67
|
-
edges: {
|
|
68
|
-
id: string;
|
|
69
|
-
source: {
|
|
70
|
-
nodeId: string;
|
|
71
|
-
handle: string;
|
|
72
|
-
};
|
|
73
|
-
target: {
|
|
74
|
-
nodeId: string;
|
|
75
|
-
handle: string;
|
|
76
|
-
};
|
|
77
|
-
typeId: string | undefined;
|
|
78
|
-
}[];
|
|
79
|
-
};
|
|
53
|
+
getGraphDef(): GraphDefinition;
|
|
80
54
|
whenIdle(): Promise<void>;
|
|
81
55
|
pause(): void;
|
|
82
56
|
resume(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphRuntime.d.ts","sourceRoot":"","sources":["../../../../src/runtime/GraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,eAAe,
|
|
1
|
+
{"version":3,"file":"GraphRuntime.d.ts","sourceRoot":"","sources":["../../../../src/runtime/GraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,eAAe,EAIhB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAIV,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAQvB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,IAAI,CAC7D,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,KAClB,IAAI,CAAC;AAUV,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,YAAY,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1E,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,YAAY,CAAC;IACpB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,KAAK,EAAE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AAA;KAAE,GAC1B,IAAI;IAsEP,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAqRtD,OAAO,CAAC,wBAAwB;YAWlB,uBAAuB;CA0DtC"}
|
package/lib/esm/index.js
CHANGED
|
@@ -982,7 +982,7 @@ class GraphRuntime {
|
|
|
982
982
|
return def.edges.map((e) => {
|
|
983
983
|
const srcNode = def.nodes.find((n) => n.nodeId === e.source.nodeId);
|
|
984
984
|
const dstNode = def.nodes.find((n) => n.nodeId === e.target.nodeId);
|
|
985
|
-
let effectiveTypeId = e.typeId;
|
|
985
|
+
let effectiveTypeId = e.typeId; // Start with original
|
|
986
986
|
let srcDeclared;
|
|
987
987
|
let dstDeclared;
|
|
988
988
|
if (srcNode) {
|
|
@@ -991,6 +991,7 @@ class GraphRuntime {
|
|
|
991
991
|
srcDeclared = resolved.outputs[e.source.handle];
|
|
992
992
|
}
|
|
993
993
|
if (!effectiveTypeId) {
|
|
994
|
+
// Infer if not explicitly set
|
|
994
995
|
effectiveTypeId = Array.isArray(srcDeclared)
|
|
995
996
|
? srcDeclared[0]
|
|
996
997
|
: srcDeclared;
|
|
@@ -1005,7 +1006,8 @@ class GraphRuntime {
|
|
|
1005
1006
|
id: e.id,
|
|
1006
1007
|
source: { ...e.source },
|
|
1007
1008
|
target: { ...e.target },
|
|
1008
|
-
typeId:
|
|
1009
|
+
typeId: e.typeId, // Preserve original (may be undefined)
|
|
1010
|
+
effectiveTypeId: effectiveTypeId ?? "untyped", // Always present
|
|
1009
1011
|
convert,
|
|
1010
1012
|
convertAsync,
|
|
1011
1013
|
srcUnionTypes: Array.isArray(srcDeclared)
|
|
@@ -1029,18 +1031,18 @@ class GraphRuntime {
|
|
|
1029
1031
|
this.resolvedByNode.set(nodeId, handles);
|
|
1030
1032
|
// Recompute edge converter/type for edges where this node is source or target
|
|
1031
1033
|
for (const e of this.edges) {
|
|
1032
|
-
let srcDeclared = e.
|
|
1034
|
+
let srcDeclared = e.effectiveTypeId; // Use effectiveTypeId as fallback
|
|
1033
1035
|
let dstDeclared = e.dstDeclared;
|
|
1034
1036
|
if (e.source.nodeId === nodeId) {
|
|
1035
1037
|
const resolved = this.resolvedByNode.get(nodeId);
|
|
1036
1038
|
srcDeclared = resolved
|
|
1037
1039
|
? resolved.outputs[e.source.handle]
|
|
1038
1040
|
: srcDeclared;
|
|
1039
|
-
//
|
|
1041
|
+
// Update effectiveTypeId if original wasn't explicit
|
|
1040
1042
|
if (!e.typeId) {
|
|
1041
|
-
e.
|
|
1042
|
-
? srcDeclared?.[0]
|
|
1043
|
-
: srcDeclared;
|
|
1043
|
+
e.effectiveTypeId = Array.isArray(srcDeclared)
|
|
1044
|
+
? srcDeclared?.[0] ?? "untyped"
|
|
1045
|
+
: srcDeclared ?? "untyped";
|
|
1044
1046
|
}
|
|
1045
1047
|
}
|
|
1046
1048
|
if (e.target.nodeId === nodeId) {
|
|
@@ -1163,10 +1165,23 @@ class GraphRuntime {
|
|
|
1163
1165
|
getGraphDef() {
|
|
1164
1166
|
const nodes = Array.from(this.nodes.values()).map((n) => {
|
|
1165
1167
|
const resolved = this.resolvedByNode.get(n.nodeId);
|
|
1168
|
+
// Collect user-provided inputs (inputs without inbound edges)
|
|
1169
|
+
const initialInputs = {};
|
|
1170
|
+
for (const [handle, value] of Object.entries(n.inputs)) {
|
|
1171
|
+
const hasInbound = this.edges.some((e) => e.target.nodeId === n.nodeId && e.target.handle === handle);
|
|
1172
|
+
if (!hasInbound && value !== undefined) {
|
|
1173
|
+
// Clone to avoid shared references
|
|
1174
|
+
initialInputs[handle] =
|
|
1175
|
+
typeof structuredClone === "function"
|
|
1176
|
+
? structuredClone(value)
|
|
1177
|
+
: JSON.parse(JSON.stringify(value));
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1166
1180
|
return {
|
|
1167
1181
|
nodeId: n.nodeId,
|
|
1168
1182
|
typeId: n.typeId,
|
|
1169
1183
|
params: n.params ? { ...n.params } : undefined,
|
|
1184
|
+
initialInputs: Object.keys(initialInputs).length > 0 ? initialInputs : undefined,
|
|
1170
1185
|
resolvedHandles: resolved ? { ...resolved } : undefined,
|
|
1171
1186
|
};
|
|
1172
1187
|
});
|
|
@@ -1174,7 +1189,7 @@ class GraphRuntime {
|
|
|
1174
1189
|
id: e.id,
|
|
1175
1190
|
source: { nodeId: e.source.nodeId, handle: e.source.handle },
|
|
1176
1191
|
target: { nodeId: e.target.nodeId, handle: e.target.handle },
|
|
1177
|
-
typeId: e.typeId
|
|
1192
|
+
typeId: e.typeId, // Only export original typeId (may be undefined)
|
|
1178
1193
|
}));
|
|
1179
1194
|
return { nodes, edges };
|
|
1180
1195
|
}
|