@particle-academy/fancy-flow 0.3.1 → 0.4.1
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/{chunk-GJSFZR6J.js → chunk-2BZ6OE5H.js} +168 -109
- package/dist/chunk-2BZ6OE5H.js.map +1 -0
- package/dist/{chunk-4YBSEMF2.js → chunk-35OXF6W3.js} +3 -3
- package/dist/{chunk-4YBSEMF2.js.map → chunk-35OXF6W3.js.map} +1 -1
- package/dist/chunk-4PZQRN5Y.js +114 -0
- package/dist/chunk-4PZQRN5Y.js.map +1 -0
- package/dist/chunk-DW66NGU5.js +138 -0
- package/dist/chunk-DW66NGU5.js.map +1 -0
- package/dist/{chunk-OZPQAUZD.js → engine.cjs} +4 -111
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +35 -0
- package/dist/engine.d.ts +35 -0
- package/dist/engine.js +3 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.cjs +169 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +19 -19
- package/dist/index.d.ts +19 -19
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/registry/index.d.cts +2 -3
- package/dist/registry/index.d.ts +2 -3
- package/dist/registry.cjs +165 -106
- package/dist/registry.cjs.map +1 -1
- package/dist/registry.js +2 -2
- package/dist/runtime/index.d.cts +4 -32
- package/dist/runtime/index.d.ts +4 -32
- package/dist/runtime.cjs +166 -107
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.js +3 -2
- package/dist/schema/index.d.cts +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/styles.css +563 -0
- package/dist/styles.css.map +1 -1
- package/dist/{types-Ch4sAvum.d.cts → types-TemTtb04.d.cts} +1 -1
- package/dist/{types-Ch4sAvum.d.ts → types-TemTtb04.d.ts} +1 -1
- package/package.json +46 -9
- package/dist/chunk-GJSFZR6J.js.map +0 -1
- package/dist/chunk-OZPQAUZD.js.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { useState, useRef, useCallback } from 'react';
|
|
1
|
+
'use strict';
|
|
3
2
|
|
|
4
3
|
// src/runtime/run-flow.ts
|
|
5
4
|
async function runFlow(graph, executors, onEvent = () => {
|
|
@@ -135,113 +134,7 @@ function activatedPorts(node, result) {
|
|
|
135
134
|
const declared = node.data.outputs?.map((p) => p.id) ?? ["out"];
|
|
136
135
|
return { ports: declared, value: result };
|
|
137
136
|
}
|
|
138
|
-
function useFlowRun({ maxFeed = 200 } = {}) {
|
|
139
|
-
const [statuses, setStatuses] = useState({});
|
|
140
|
-
const [statusText, setStatusText] = useState({});
|
|
141
|
-
const [feed, setFeed] = useState([]);
|
|
142
|
-
const [running, setRunning] = useState(false);
|
|
143
|
-
const [lastResult, setLastResult] = useState(null);
|
|
144
|
-
const abortRef = useRef(null);
|
|
145
|
-
const handleEvent = useCallback(
|
|
146
|
-
(e) => {
|
|
147
|
-
switch (e.type) {
|
|
148
|
-
case "node-status":
|
|
149
|
-
setStatuses((s) => ({ ...s, [e.nodeId]: e.status }));
|
|
150
|
-
setStatusText((t) => ({ ...t, [e.nodeId]: e.text }));
|
|
151
|
-
appendFeed({ level: "status", text: `${e.nodeId} \u2192 ${e.status}${e.text ? ` (${e.text})` : ""}`, nodeId: e.nodeId });
|
|
152
|
-
break;
|
|
153
|
-
case "node-output":
|
|
154
|
-
appendFeed({ level: "info", text: `${e.nodeId}.${e.portId} = ${preview(e.value)}`, nodeId: e.nodeId, detail: e.value });
|
|
155
|
-
break;
|
|
156
|
-
case "log":
|
|
157
|
-
appendFeed({ level: e.level, text: e.message, nodeId: e.nodeId, detail: e.detail });
|
|
158
|
-
break;
|
|
159
|
-
case "run-start":
|
|
160
|
-
appendFeed({ level: "info", text: "\u25B6 run started" });
|
|
161
|
-
break;
|
|
162
|
-
case "run-end":
|
|
163
|
-
appendFeed({ level: e.ok ? "info" : "error", text: e.ok ? "\u2713 run complete" : "\u2717 run failed" });
|
|
164
|
-
break;
|
|
165
|
-
case "run-error":
|
|
166
|
-
appendFeed({ level: "error", text: e.error });
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
function appendFeed(partial) {
|
|
170
|
-
setFeed((f) => {
|
|
171
|
-
const entry = { id: `${Date.now()}_${f.length}`, at: Date.now(), ...partial };
|
|
172
|
-
const next = [...f, entry];
|
|
173
|
-
return next.length > maxFeed ? next.slice(next.length - maxFeed) : next;
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
[maxFeed]
|
|
178
|
-
);
|
|
179
|
-
const run = useCallback(
|
|
180
|
-
async (graph, executors, options = {}) => {
|
|
181
|
-
if (running) {
|
|
182
|
-
return { ok: false, outputs: {}, error: "another run is already in progress" };
|
|
183
|
-
}
|
|
184
|
-
const controller = new AbortController();
|
|
185
|
-
abortRef.current = controller;
|
|
186
|
-
const idleStatuses = {};
|
|
187
|
-
for (const n of graph.nodes) idleStatuses[n.id] = "idle";
|
|
188
|
-
setStatuses(idleStatuses);
|
|
189
|
-
setStatusText({});
|
|
190
|
-
setRunning(true);
|
|
191
|
-
try {
|
|
192
|
-
const result = await runFlow(graph, executors, handleEvent, { ...options, signal: controller.signal });
|
|
193
|
-
setLastResult(result);
|
|
194
|
-
return result;
|
|
195
|
-
} finally {
|
|
196
|
-
setRunning(false);
|
|
197
|
-
abortRef.current = null;
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
[handleEvent, running]
|
|
201
|
-
);
|
|
202
|
-
const cancel = useCallback(() => abortRef.current?.abort(), []);
|
|
203
|
-
const reset = useCallback(() => {
|
|
204
|
-
setStatuses({});
|
|
205
|
-
setStatusText({});
|
|
206
|
-
setFeed([]);
|
|
207
|
-
setLastResult(null);
|
|
208
|
-
}, []);
|
|
209
|
-
return { statuses, statusText, feed, running, lastResult, run, cancel, reset };
|
|
210
|
-
}
|
|
211
|
-
function applyStatusesToNodes(nodes, statuses, statusText) {
|
|
212
|
-
return nodes.map((n) => ({
|
|
213
|
-
...n,
|
|
214
|
-
data: {
|
|
215
|
-
...n.data,
|
|
216
|
-
status: statuses[n.id] ?? n.data?.status ?? "idle",
|
|
217
|
-
statusText: statusText[n.id] ?? n.data?.statusText
|
|
218
|
-
}
|
|
219
|
-
}));
|
|
220
|
-
}
|
|
221
|
-
function preview(v) {
|
|
222
|
-
try {
|
|
223
|
-
const s = JSON.stringify(v);
|
|
224
|
-
return s && s.length > 60 ? s.slice(0, 57) + "\u2026" : s ?? String(v);
|
|
225
|
-
} catch {
|
|
226
|
-
return String(v);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function useFlowState(initial) {
|
|
230
|
-
const [nodes, setNodes] = useState(initial.nodes);
|
|
231
|
-
const [edges, setEdges] = useState(initial.edges);
|
|
232
|
-
const onNodesChange = useCallback((changes) => {
|
|
233
|
-
setNodes((ns) => applyNodeChanges(changes, ns));
|
|
234
|
-
}, []);
|
|
235
|
-
const onEdgesChange = useCallback((changes) => {
|
|
236
|
-
setEdges((es) => applyEdgeChanges(changes, es));
|
|
237
|
-
}, []);
|
|
238
|
-
const onConnect = useCallback((connection) => {
|
|
239
|
-
setEdges((es) => addEdge(connection, es));
|
|
240
|
-
}, []);
|
|
241
|
-
const toGraph = useCallback(() => ({ nodes, edges }), [nodes, edges]);
|
|
242
|
-
return { nodes, edges, setNodes, setEdges, onNodesChange, onEdgesChange, onConnect, toGraph };
|
|
243
|
-
}
|
|
244
137
|
|
|
245
|
-
|
|
246
|
-
//# sourceMappingURL=
|
|
247
|
-
//# sourceMappingURL=
|
|
138
|
+
exports.runFlow = runFlow;
|
|
139
|
+
//# sourceMappingURL=engine.cjs.map
|
|
140
|
+
//# sourceMappingURL=engine.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/run-flow.ts"],"names":[],"mappings":";;;AAuCA,eAAsB,OAAA,CACpB,KAA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IAAA,CAAK,IAAA,CAAK,OAAA,EAAS,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,EAAE,CAAA,IAAK,CAAC,KAAK,CAAA;AAC9D,EAAA,OAAO,EAAE,KAAA,EAAO,QAAA,EAAU,KAAA,EAAO,MAAA,EAAO;AAC1C","file":"engine.cjs","sourcesContent":["import type {\n ExecutorRegistry,\n FlowEdge,\n FlowGraph,\n FlowNode,\n NodeExecutor,\n RunEvent,\n} from \"../types\";\n\nexport type RunOptions = {\n /** Stop the run after this many ms. Default: no timeout. */\n timeoutMs?: number;\n /** Abort signal — host can cancel the run. */\n signal?: AbortSignal;\n /** Initial inputs supplied to entry-point nodes (no incoming edges). */\n initialInputs?: Record<string, Record<string, unknown>>;\n};\n\nexport type RunResult = {\n ok: boolean;\n /** Outputs collected per node, keyed by node id. */\n outputs: Record<string, unknown>;\n /** Error captured if any node threw. */\n error?: string;\n};\n\n/**\n * runFlow — topological execution of a FlowGraph against an ExecutorRegistry.\n *\n * Each node runs once, when all upstream nodes have produced outputs on the\n * connected ports. Decision nodes (or any executor that returns `{ branch:\n * 'true' }`) can short-circuit specific output ports — only edges leaving\n * an \"active\" port propagate to downstream nodes.\n *\n * Cycles are detected and abort the run with an error.\n *\n * The `onEvent` callback receives a stream of `RunEvent`s — wire it to a\n * status feed, log panel, or store.\n */\nexport async function runFlow(\n graph: FlowGraph,\n executors: ExecutorRegistry,\n onEvent: (event: RunEvent) => void = () => {},\n options: RunOptions = {},\n): Promise<RunResult> {\n const { signal, initialInputs = {}, timeoutMs } = options;\n const outputs: Record<string, unknown> = {};\n const portValues = new Map<string, unknown>(); // key: `${nodeId}:${portId}`\n const completed = new Set<string>();\n const errors: string[] = [];\n\n // Topological order via Kahn's algorithm. We allow nodes to run as soon\n // as their incoming edges' source ports have produced values, so the\n // order here is just a deterministic baseline used for cycle detection.\n const order = topoSort(graph);\n if (order === null) {\n const msg = \"Cycle detected in flow graph — aborting.\";\n onEvent({ type: \"run-error\", error: msg });\n return { ok: false, outputs, error: msg };\n }\n\n const incomingByNode = indexIncoming(graph.edges);\n const timer = timeoutMs ? setTimeout(() => errors.push(`Run timed out after ${timeoutMs}ms`), timeoutMs) : null;\n\n onEvent({ type: \"run-start\" });\n\n try {\n for (const node of order) {\n if (signal?.aborted) throw new Error(\"aborted\");\n if (errors.length) break;\n\n const incoming = incomingByNode.get(node.id) ?? [];\n\n // Skip nodes whose upstream wasn't activated (e.g. a Decision routed\n // to a different branch).\n if (incoming.length > 0) {\n const allActive = incoming.every((e) => portValues.has(`${e.source}:${e.sourceHandle ?? \"out\"}`));\n if (!allActive) {\n onEvent({ type: \"node-status\", nodeId: node.id, status: \"idle\", text: \"skipped\" });\n continue;\n }\n }\n\n // Note nodes are annotations — never executed.\n if (node.type === \"note\") {\n onEvent({ type: \"node-status\", nodeId: node.id, status: \"idle\", text: \"annotation\" });\n continue;\n }\n\n onEvent({ type: \"node-status\", nodeId: node.id, status: \"running\" });\n\n const inputs = collectInputs(node, incoming, portValues, initialInputs);\n const exec = pickExecutor(executors, node);\n if (!exec) {\n const msg = `No executor registered for kind=${node.type}`;\n errors.push(msg);\n onEvent({ type: \"node-status\", nodeId: node.id, status: \"error\", text: msg });\n onEvent({ type: \"log\", nodeId: node.id, level: \"error\", message: msg });\n break;\n }\n\n try {\n const result = await Promise.resolve(\n exec({\n node,\n inputs,\n abort: (reason) => { throw new Error(reason ?? \"aborted\"); },\n emit: onEvent,\n }),\n );\n outputs[node.id] = result;\n\n // Decide which output ports were activated. Three conventions:\n // 1) If result is `{ __port: \"out\", value: x }`, only that port emits.\n // 2) If result has `branch: <portId>`, only that port emits (decision sugar).\n // 3) Otherwise, the value is published on every declared output port.\n const activated = activatedPorts(node, result);\n for (const portId of activated.ports) {\n portValues.set(`${node.id}:${portId}`, activated.value);\n onEvent({ type: \"node-output\", nodeId: node.id, portId, value: activated.value });\n }\n completed.add(node.id);\n onEvent({ type: \"node-status\", nodeId: node.id, status: \"done\" });\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n errors.push(msg);\n onEvent({ type: \"node-status\", nodeId: node.id, status: \"error\", text: msg });\n onEvent({ type: \"log\", nodeId: node.id, level: \"error\", message: msg });\n break;\n }\n }\n } finally {\n if (timer) clearTimeout(timer);\n }\n\n const ok = errors.length === 0;\n onEvent({ type: \"run-end\", ok });\n return ok ? { ok, outputs } : { ok, outputs, error: errors[0] };\n}\n\nfunction indexIncoming(edges: FlowEdge[]): Map<string, FlowEdge[]> {\n const map = new Map<string, FlowEdge[]>();\n for (const e of edges) {\n const list = map.get(e.target) ?? [];\n list.push(e);\n map.set(e.target, list);\n }\n return map;\n}\n\nfunction topoSort(graph: FlowGraph): FlowNode[] | null {\n const inDegree = new Map<string, number>();\n for (const n of graph.nodes) inDegree.set(n.id, 0);\n for (const e of graph.edges) inDegree.set(e.target, (inDegree.get(e.target) ?? 0) + 1);\n const queue: string[] = [];\n for (const [id, d] of inDegree) if (d === 0) queue.push(id);\n const ordered: string[] = [];\n while (queue.length) {\n const id = queue.shift()!;\n ordered.push(id);\n for (const e of graph.edges) {\n if (e.source !== id) continue;\n const next = (inDegree.get(e.target) ?? 0) - 1;\n inDegree.set(e.target, next);\n if (next === 0) queue.push(e.target);\n }\n }\n if (ordered.length !== graph.nodes.length) return null;\n const byId = new Map(graph.nodes.map((n) => [n.id, n]));\n return ordered.map((id) => byId.get(id)!).filter(Boolean);\n}\n\nfunction collectInputs(\n node: FlowNode,\n incoming: FlowEdge[],\n portValues: Map<string, unknown>,\n initial: Record<string, Record<string, unknown>>,\n): Record<string, unknown> {\n const inputs: Record<string, unknown> = { ...(initial[node.id] ?? {}) };\n for (const e of incoming) {\n const portId = e.targetHandle ?? \"in\";\n const val = portValues.get(`${e.source}:${e.sourceHandle ?? \"out\"}`);\n inputs[portId] = val;\n }\n return inputs;\n}\n\nfunction pickExecutor(\n executors: ExecutorRegistry,\n node: FlowNode,\n): NodeExecutor | undefined {\n if (executors[node.id]) return executors[node.id];\n if (node.type && executors[node.type]) return executors[node.type];\n return executors[\"*\"];\n}\n\nfunction activatedPorts(node: FlowNode, result: unknown): { ports: string[]; value: unknown } {\n if (result && typeof result === \"object\") {\n const r = result as Record<string, unknown>;\n if (typeof r.__port === \"string\") {\n return { ports: [r.__port], value: r.value };\n }\n if (typeof r.branch === \"string\") {\n return { ports: [r.branch], value: r.value ?? r };\n }\n }\n const declared = node.data.outputs?.map((p) => p.id) ?? [\"out\"];\n return { ports: declared, value: result };\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { a as FlowGraph, E as ExecutorRegistry, R as RunEvent } from './types-TemTtb04.cjs';
|
|
2
|
+
export { A as ActionNodeData, B as BaseNodeData, D as DecisionNodeData, b as FlowEdge, F as FlowNode, c as FlowNodeData, d as FlowNodeKind, N as NodeExecutor, e as NodeRunStatus, f as NoteNodeData, O as OutputNodeData, P as PortDescriptor, S as SubgraphNodeData, T as TriggerNodeData } from './types-TemTtb04.cjs';
|
|
3
|
+
import '@xyflow/react';
|
|
4
|
+
|
|
5
|
+
type RunOptions = {
|
|
6
|
+
/** Stop the run after this many ms. Default: no timeout. */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
/** Abort signal — host can cancel the run. */
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
/** Initial inputs supplied to entry-point nodes (no incoming edges). */
|
|
11
|
+
initialInputs?: Record<string, Record<string, unknown>>;
|
|
12
|
+
};
|
|
13
|
+
type RunResult = {
|
|
14
|
+
ok: boolean;
|
|
15
|
+
/** Outputs collected per node, keyed by node id. */
|
|
16
|
+
outputs: Record<string, unknown>;
|
|
17
|
+
/** Error captured if any node threw. */
|
|
18
|
+
error?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* runFlow — topological execution of a FlowGraph against an ExecutorRegistry.
|
|
22
|
+
*
|
|
23
|
+
* Each node runs once, when all upstream nodes have produced outputs on the
|
|
24
|
+
* connected ports. Decision nodes (or any executor that returns `{ branch:
|
|
25
|
+
* 'true' }`) can short-circuit specific output ports — only edges leaving
|
|
26
|
+
* an "active" port propagate to downstream nodes.
|
|
27
|
+
*
|
|
28
|
+
* Cycles are detected and abort the run with an error.
|
|
29
|
+
*
|
|
30
|
+
* The `onEvent` callback receives a stream of `RunEvent`s — wire it to a
|
|
31
|
+
* status feed, log panel, or store.
|
|
32
|
+
*/
|
|
33
|
+
declare function runFlow(graph: FlowGraph, executors: ExecutorRegistry, onEvent?: (event: RunEvent) => void, options?: RunOptions): Promise<RunResult>;
|
|
34
|
+
|
|
35
|
+
export { ExecutorRegistry, FlowGraph, RunEvent, type RunOptions, type RunResult, runFlow };
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { a as FlowGraph, E as ExecutorRegistry, R as RunEvent } from './types-TemTtb04.js';
|
|
2
|
+
export { A as ActionNodeData, B as BaseNodeData, D as DecisionNodeData, b as FlowEdge, F as FlowNode, c as FlowNodeData, d as FlowNodeKind, N as NodeExecutor, e as NodeRunStatus, f as NoteNodeData, O as OutputNodeData, P as PortDescriptor, S as SubgraphNodeData, T as TriggerNodeData } from './types-TemTtb04.js';
|
|
3
|
+
import '@xyflow/react';
|
|
4
|
+
|
|
5
|
+
type RunOptions = {
|
|
6
|
+
/** Stop the run after this many ms. Default: no timeout. */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
/** Abort signal — host can cancel the run. */
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
/** Initial inputs supplied to entry-point nodes (no incoming edges). */
|
|
11
|
+
initialInputs?: Record<string, Record<string, unknown>>;
|
|
12
|
+
};
|
|
13
|
+
type RunResult = {
|
|
14
|
+
ok: boolean;
|
|
15
|
+
/** Outputs collected per node, keyed by node id. */
|
|
16
|
+
outputs: Record<string, unknown>;
|
|
17
|
+
/** Error captured if any node threw. */
|
|
18
|
+
error?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* runFlow — topological execution of a FlowGraph against an ExecutorRegistry.
|
|
22
|
+
*
|
|
23
|
+
* Each node runs once, when all upstream nodes have produced outputs on the
|
|
24
|
+
* connected ports. Decision nodes (or any executor that returns `{ branch:
|
|
25
|
+
* 'true' }`) can short-circuit specific output ports — only edges leaving
|
|
26
|
+
* an "active" port propagate to downstream nodes.
|
|
27
|
+
*
|
|
28
|
+
* Cycles are detected and abort the run with an error.
|
|
29
|
+
*
|
|
30
|
+
* The `onEvent` callback receives a stream of `RunEvent`s — wire it to a
|
|
31
|
+
* status feed, log panel, or store.
|
|
32
|
+
*/
|
|
33
|
+
declare function runFlow(graph: FlowGraph, executors: ExecutorRegistry, onEvent?: (event: RunEvent) => void, options?: RunOptions): Promise<RunResult>;
|
|
34
|
+
|
|
35
|
+
export { ExecutorRegistry, FlowGraph, RunEvent, type RunOptions, type RunResult, runFlow };
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"engine.js"}
|