@particle-academy/fancy-flow 0.10.0 → 0.10.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-6GGFEZH7.js → chunk-2DMBJN2O.js} +14 -5
- package/dist/chunk-2DMBJN2O.js.map +1 -0
- package/dist/index.cjs +11 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/schema/index.d.cts +17 -1
- package/dist/schema/index.d.ts +17 -1
- package/dist/schema.cjs +34 -3
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.js +2 -1
- package/package.json +1 -1
- package/dist/chunk-6GGFEZH7.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveNodePorts } from './chunk-TITD5W4Y.js';
|
|
1
2
|
import { getNodeKind, defaultConfigFor, validateConfig } from './chunk-CPSOC27D.js';
|
|
2
3
|
|
|
3
4
|
// src/schema/workflow-schema.ts
|
|
@@ -17,13 +18,17 @@ function exportWorkflow(graph, metadata, view) {
|
|
|
17
18
|
}
|
|
18
19
|
function toSchemaNode(n) {
|
|
19
20
|
const data = n.data ?? {};
|
|
21
|
+
const kindName = data.kind ?? n.type ?? "custom";
|
|
22
|
+
const ports = resolveNodePorts(n, getNodeKind(kindName) ?? void 0);
|
|
20
23
|
return {
|
|
21
24
|
id: n.id,
|
|
22
|
-
kind:
|
|
25
|
+
kind: kindName,
|
|
23
26
|
position: { x: n.position.x, y: n.position.y },
|
|
24
27
|
label: data.label,
|
|
25
28
|
description: data.description,
|
|
26
|
-
config: data.config
|
|
29
|
+
config: data.config,
|
|
30
|
+
inputs: ports.inputs,
|
|
31
|
+
outputs: ports.outputs
|
|
27
32
|
};
|
|
28
33
|
}
|
|
29
34
|
function toSchemaEdge(e) {
|
|
@@ -75,7 +80,11 @@ function importWorkflow(schema, options = {}) {
|
|
|
75
80
|
kind: n.kind,
|
|
76
81
|
label: n.label ?? kind?.label ?? n.kind,
|
|
77
82
|
description: n.description,
|
|
78
|
-
config
|
|
83
|
+
config,
|
|
84
|
+
// Carry serialized ports back onto the node so a round-trip is stable
|
|
85
|
+
// and an unknown kind still routes the way the document described.
|
|
86
|
+
...n.inputs ? { inputs: n.inputs } : {},
|
|
87
|
+
...n.outputs ? { outputs: n.outputs } : {}
|
|
79
88
|
}
|
|
80
89
|
};
|
|
81
90
|
});
|
|
@@ -106,5 +115,5 @@ function workflowToBlob(schema) {
|
|
|
106
115
|
}
|
|
107
116
|
|
|
108
117
|
export { WORKFLOW_SCHEMA_URL, WORKFLOW_SCHEMA_VERSION, exportWorkflow, importWorkflow, workflowToBlob };
|
|
109
|
-
//# sourceMappingURL=chunk-
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
118
|
+
//# sourceMappingURL=chunk-2DMBJN2O.js.map
|
|
119
|
+
//# sourceMappingURL=chunk-2DMBJN2O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/workflow-schema.ts"],"names":[],"mappings":";;;;AAKO,IAAM,uBAAA,GAA0B;AAChC,IAAM,mBAAA,GAAsB;AA4E5B,SAAS,cAAA,CACd,KAAA,EACA,QAAA,EACA,IAAA,EACgB;AAChB,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,mBAAA;AAAA,IACT,OAAA,EAAS,uBAAA;AAAA,IACT,QAAA,EAAU,WAAW,EAAE,GAAG,UAAU,SAAA,EAAW,IAAA,CAAK,GAAA,EAAI,EAAE,GAAI,MAAA;AAAA,IAC9D,KAAA,EAAO;AAAA,MACL,KAAA,EAAO,KAAA,CAAM,KAAA,CAAM,GAAA,CAAI,YAAY,CAAA;AAAA,MACnC,KAAA,EAAO,KAAA,CAAM,KAAA,CAAM,GAAA,CAAI,YAAY;AAAA,KACrC;AAAA,IACA;AAAA,GACF;AACF;AAEA,SAAS,aAAa,CAAA,EAAiC;AACrD,EAAA,MAAM,IAAA,GAAY,CAAA,CAAE,IAAA,IAAQ,EAAC;AAC7B,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eKind, validateConfig } from \"../registry/registry\";\nimport { resolveNodePorts } from \"../registry/ports\";\n\n/** Schema version. Bump on breaking shape changes; add migrations as needed. */\nexport const WORKFLOW_SCHEMA_VERSION = 1 as const;\nexport const WORKFLOW_SCHEMA_URL = \"https://particle.academy/schemas/workflow/v1.json\";\n\nexport type WorkflowSchema = {\n $schema: typeof WORKFLOW_SCHEMA_URL;\n version: typeof WORKFLOW_SCHEMA_VERSION;\n metadata?: WorkflowMetadata;\n graph: {\n nodes: WorkflowSchemaNode[];\n edges: WorkflowSchemaEdge[];\n };\n view?: {\n viewport?: { x: number; y: number; zoom: number };\n };\n};\n\nexport type WorkflowMetadata = {\n id?: string;\n name?: string;\n description?: string;\n createdAt?: number;\n updatedAt?: number;\n author?: string;\n tags?: string[];\n};\n\nexport type WorkflowSchemaNode = {\n id: string;\n /** Registry kind name (e.g. \"memory_store\"). */\n kind: string;\n position: { x: number; y: number };\n label?: string;\n description?: string;\n config?: Record<string, unknown>;\n /**\n * Resolved ports, written on export.\n *\n * A kind may derive its ports from config (`switch_case` cases,\n * `llm_branch` routes), and that derivation is a JavaScript function — a\n * runtime in another language cannot execute it. Without the resolved ports\n * in the document, the PHP twin sees no declared outputs and falls back to a\n * single `out`, so every branch edge in an exported flow silently stops\n * firing. Serializing them keeps the schema self-describing and preserves\n * the cross-runtime guarantee: same JSON in, same routing out.\n *\n * Optional and additive — a hand-written schema may omit them, and each\n * runtime then falls back to its own kind registry.\n */\n inputs?: PortDescriptor[];\n outputs?: PortDescriptor[];\n};\n\nexport type WorkflowSchemaEdge = {\n id: string;\n source: string;\n target: string;\n sourceHandle?: string;\n targetHandle?: string;\n label?: string;\n};\n\nexport type ImportIssue = {\n level: \"error\" | \"warning\";\n nodeId?: string;\n edgeId?: string;\n message: string;\n};\n\nexport type ImportResult = {\n graph: FlowGraph;\n issues: ImportIssue[];\n /** True when the import produced a usable graph (errors may have been\n * rewritten to warnings via `lenient: true`). */\n ok: boolean;\n};\n\n/** Snapshot the in-memory graph as a portable WorkflowSchema. */\nexport function exportWorkflow(\n graph: FlowGraph,\n metadata?: WorkflowMetadata,\n view?: WorkflowSchema[\"view\"],\n): WorkflowSchema {\n return {\n $schema: WORKFLOW_SCHEMA_URL,\n version: WORKFLOW_SCHEMA_VERSION,\n metadata: metadata ? { ...metadata, updatedAt: Date.now() } : undefined,\n graph: {\n nodes: graph.nodes.map(toSchemaNode),\n edges: graph.edges.map(toSchemaEdge),\n },\n view,\n };\n}\n\nfunction toSchemaNode(n: FlowNode): WorkflowSchemaNode {\n const data: any = n.data ?? {};\n const kindName = data.kind ?? n.type ?? \"custom\";\n // Resolve through the same helper the canvas and runtime use, so a\n // config-driven kind writes its ACTUAL ports into the document instead of\n // leaving another language's runtime to guess at them.\n const ports = resolveNodePorts(n, getNodeKind(kindName) ?? undefined);\n return {\n id: n.id,\n kind: kindName,\n position: { x: n.position.x, y: n.position.y },\n label: data.label,\n description: data.description,\n config: data.config,\n inputs: ports.inputs,\n outputs: ports.outputs,\n };\n}\n\nfunction toSchemaEdge(e: FlowEdge): WorkflowSchemaEdge {\n return {\n id: e.id,\n source: e.source,\n target: e.target,\n sourceHandle: e.sourceHandle ?? undefined,\n targetHandle: e.targetHandle ?? undefined,\n label: typeof e.label === \"string\" ? e.label : undefined,\n };\n}\n\nexport type ImportOptions = {\n /** When true, unknown kinds become warnings + a \"custom\" placeholder\n * instead of errors. Default false. */\n lenient?: boolean;\n};\n\n/**\n * Hydrate a schema into runtime FlowGraph + validate kinds/configs against\n * the registry. Reports issues for unknown kinds, missing required config,\n * and dangling edges.\n */\nexport function importWorkflow(schema: unknown, options: ImportOptions = {}): ImportResult {\n const issues: ImportIssue[] = [];\n const lenient = options.lenient === true;\n\n if (!schema || typeof schema !== \"object\") {\n return { ok: false, graph: { nodes: [], edges: [] }, issues: [{ level: \"error\", message: \"Schema is not an object.\" }] };\n }\n const s = schema as Partial<WorkflowSchema>;\n if (s.version !== WORKFLOW_SCHEMA_VERSION) {\n issues.push({\n level: lenient ? \"warning\" : \"error\",\n message: `Unsupported workflow schema version: ${s.version} (expected ${WORKFLOW_SCHEMA_VERSION})`,\n });\n if (!lenient) return { ok: false, graph: { nodes: [], edges: [] }, issues };\n }\n\n const rawNodes = s.graph?.nodes ?? [];\n const rawEdges = s.graph?.edges ?? [];\n\n const nodes: FlowNode[] = rawNodes.map((n) => {\n const kind = getNodeKind(n.kind);\n if (!kind) {\n issues.push({\n level: lenient ? \"warning\" : \"error\",\n nodeId: n.id,\n message: `Unknown kind \"${n.kind}\" — register it before importing.`,\n });\n }\n const config = n.config ?? (kind ? defaultConfigFor(kind) : {});\n if (kind) {\n for (const iss of validateConfig(kind, config)) {\n issues.push({ level: \"warning\", nodeId: n.id, message: `${iss.key}: ${iss.message}` });\n }\n }\n return {\n id: n.id,\n type: n.kind,\n position: { x: n.position?.x ?? 0, y: n.position?.y ?? 0 },\n data: {\n kind: n.kind,\n label: n.label ?? kind?.label ?? n.kind,\n description: n.description,\n config,\n // Carry serialized ports back onto the node so a round-trip is stable\n // and an unknown kind still routes the way the document described.\n ...(n.inputs ? { inputs: n.inputs } : {}),\n ...(n.outputs ? { outputs: n.outputs } : {}),\n } as any,\n };\n });\n\n const nodeIds = new Set(nodes.map((n) => n.id));\n const edges: FlowEdge[] = rawEdges\n .map((e) => {\n if (!nodeIds.has(e.source)) {\n issues.push({ level: \"warning\", edgeId: e.id, message: `Edge source \"${e.source}\" not found.` });\n return null;\n }\n if (!nodeIds.has(e.target)) {\n issues.push({ level: \"warning\", edgeId: e.id, message: `Edge target \"${e.target}\" not found.` });\n return null;\n }\n return {\n id: e.id,\n source: e.source,\n target: e.target,\n sourceHandle: e.sourceHandle,\n targetHandle: e.targetHandle,\n label: e.label,\n } as FlowEdge;\n })\n .filter((e): e is FlowEdge => e !== null);\n\n const ok = issues.every((i) => i.level !== \"error\");\n return { ok, graph: { nodes, edges }, issues };\n}\n\n/** Convenience: serialize a schema as a downloadable JSON Blob. */\nexport function workflowToBlob(schema: WorkflowSchema): Blob {\n return new Blob([JSON.stringify(schema, null, 2)], { type: \"application/json\" });\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -10667,13 +10667,17 @@ function exportWorkflow(graph, metadata, view) {
|
|
|
10667
10667
|
}
|
|
10668
10668
|
function toSchemaNode(n) {
|
|
10669
10669
|
const data = n.data ?? {};
|
|
10670
|
+
const kindName = data.kind ?? n.type ?? "custom";
|
|
10671
|
+
const ports = resolveNodePorts(n, getNodeKind(kindName) ?? void 0);
|
|
10670
10672
|
return {
|
|
10671
10673
|
id: n.id,
|
|
10672
|
-
kind:
|
|
10674
|
+
kind: kindName,
|
|
10673
10675
|
position: { x: n.position.x, y: n.position.y },
|
|
10674
10676
|
label: data.label,
|
|
10675
10677
|
description: data.description,
|
|
10676
|
-
config: data.config
|
|
10678
|
+
config: data.config,
|
|
10679
|
+
inputs: ports.inputs,
|
|
10680
|
+
outputs: ports.outputs
|
|
10677
10681
|
};
|
|
10678
10682
|
}
|
|
10679
10683
|
function toSchemaEdge(e) {
|
|
@@ -10725,7 +10729,11 @@ function importWorkflow(schema, options = {}) {
|
|
|
10725
10729
|
kind: n.kind,
|
|
10726
10730
|
label: n.label ?? kind?.label ?? n.kind,
|
|
10727
10731
|
description: n.description,
|
|
10728
|
-
config
|
|
10732
|
+
config,
|
|
10733
|
+
// Carry serialized ports back onto the node so a round-trip is stable
|
|
10734
|
+
// and an unknown kind still routes the way the document described.
|
|
10735
|
+
...n.inputs ? { inputs: n.inputs } : {},
|
|
10736
|
+
...n.outputs ? { outputs: n.outputs } : {}
|
|
10729
10737
|
}
|
|
10730
10738
|
};
|
|
10731
10739
|
});
|