@pikku/inspector 0.11.0 → 0.11.2

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 (109) hide show
  1. package/CHANGELOG.md +32 -2
  2. package/dist/add/add-channel.js +11 -10
  3. package/dist/add/add-file-with-factory.js +10 -10
  4. package/dist/add/add-forge-credential.d.ts +8 -0
  5. package/dist/add/add-forge-credential.js +77 -0
  6. package/dist/add/add-forge-node.d.ts +7 -0
  7. package/dist/add/add-forge-node.js +77 -0
  8. package/dist/add/add-functions.js +158 -51
  9. package/dist/add/add-http-route.js +28 -4
  10. package/dist/add/add-mcp-prompt.js +6 -5
  11. package/dist/add/add-mcp-resource.js +6 -5
  12. package/dist/add/add-mcp-tool.js +6 -5
  13. package/dist/add/add-middleware.js +1 -1
  14. package/dist/add/add-permission.js +1 -1
  15. package/dist/add/add-queue-worker.js +6 -5
  16. package/dist/add/add-rpc-invocations.d.ts +3 -0
  17. package/dist/add/add-rpc-invocations.js +51 -25
  18. package/dist/add/add-schedule.js +5 -4
  19. package/dist/add/add-workflow-graph.d.ts +6 -0
  20. package/dist/add/add-workflow-graph.js +659 -0
  21. package/dist/add/add-workflow.d.ts +1 -1
  22. package/dist/add/add-workflow.js +191 -69
  23. package/dist/error-codes.d.ts +3 -0
  24. package/dist/error-codes.js +3 -0
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.js +3 -0
  27. package/dist/inspector.js +29 -9
  28. package/dist/types.d.ts +47 -8
  29. package/dist/utils/extract-function-name.js +7 -7
  30. package/dist/utils/extract-function-node.d.ts +10 -0
  31. package/dist/utils/extract-function-node.js +38 -0
  32. package/dist/utils/extract-node-value.d.ts +8 -0
  33. package/dist/utils/extract-node-value.js +24 -0
  34. package/dist/utils/extract-service-metadata.d.ts +19 -0
  35. package/dist/utils/extract-service-metadata.js +244 -0
  36. package/dist/utils/get-files-and-methods.d.ts +3 -3
  37. package/dist/utils/get-files-and-methods.js +3 -3
  38. package/dist/utils/get-property-value.d.ts +14 -6
  39. package/dist/utils/get-property-value.js +55 -43
  40. package/dist/utils/post-process.d.ts +9 -0
  41. package/dist/utils/post-process.js +30 -3
  42. package/dist/utils/serialize-inspector-state.d.ts +42 -6
  43. package/dist/utils/serialize-inspector-state.js +36 -10
  44. package/dist/utils/workflow/dsl/deserialize-dsl-workflow.d.ts +24 -0
  45. package/dist/utils/workflow/dsl/deserialize-dsl-workflow.js +898 -0
  46. package/dist/utils/workflow/dsl/extract-dsl-workflow.d.ts +17 -0
  47. package/dist/utils/workflow/dsl/extract-dsl-workflow.js +1284 -0
  48. package/dist/utils/workflow/dsl/index.d.ts +7 -0
  49. package/dist/utils/workflow/dsl/index.js +7 -0
  50. package/dist/utils/workflow/dsl/patterns.d.ts +60 -0
  51. package/dist/utils/workflow/dsl/patterns.js +218 -0
  52. package/dist/utils/workflow/dsl/validation.d.ts +30 -0
  53. package/dist/utils/workflow/dsl/validation.js +142 -0
  54. package/dist/utils/workflow/graph/convert-dsl-to-graph.d.ts +13 -0
  55. package/dist/utils/workflow/graph/convert-dsl-to-graph.js +316 -0
  56. package/dist/utils/workflow/graph/index.d.ts +6 -0
  57. package/dist/utils/workflow/graph/index.js +6 -0
  58. package/dist/utils/workflow/graph/serialize-workflow-graph.d.ts +43 -0
  59. package/dist/utils/workflow/graph/serialize-workflow-graph.js +152 -0
  60. package/dist/utils/workflow/graph/workflow-graph.types.d.ts +229 -0
  61. package/dist/utils/workflow/graph/workflow-graph.types.js +38 -0
  62. package/dist/utils/write-service-metadata.d.ts +13 -0
  63. package/dist/utils/write-service-metadata.js +37 -0
  64. package/dist/visit.js +8 -2
  65. package/package.json +16 -4
  66. package/src/add/add-channel.ts +37 -17
  67. package/src/add/add-file-with-factory.ts +10 -10
  68. package/src/add/add-forge-credential.ts +119 -0
  69. package/src/add/add-forge-node.ts +132 -0
  70. package/src/add/add-functions.ts +199 -69
  71. package/src/add/add-http-route.ts +34 -5
  72. package/src/add/add-mcp-prompt.ts +11 -7
  73. package/src/add/add-mcp-resource.ts +11 -7
  74. package/src/add/add-mcp-tool.ts +11 -7
  75. package/src/add/add-middleware.ts +1 -1
  76. package/src/add/add-permission.ts +1 -1
  77. package/src/add/add-queue-worker.ts +11 -12
  78. package/src/add/add-rpc-invocations.ts +61 -31
  79. package/src/add/add-schedule.ts +10 -5
  80. package/src/add/add-workflow-graph.ts +864 -0
  81. package/src/add/add-workflow.ts +212 -116
  82. package/src/error-codes.ts +3 -0
  83. package/src/index.ts +12 -0
  84. package/src/inspector.ts +36 -10
  85. package/src/types.ts +43 -9
  86. package/src/utils/extract-function-name.ts +7 -7
  87. package/src/utils/extract-function-node.ts +58 -0
  88. package/src/utils/extract-node-value.ts +31 -0
  89. package/src/utils/extract-service-metadata.ts +353 -0
  90. package/src/utils/filter-inspector-state.test.ts +3 -3
  91. package/src/utils/filter-utils.test.ts +45 -51
  92. package/src/utils/get-files-and-methods.ts +11 -11
  93. package/src/utils/get-property-value.ts +67 -53
  94. package/src/utils/permissions.test.ts +3 -3
  95. package/src/utils/post-process.ts +56 -3
  96. package/src/utils/serialize-inspector-state.ts +67 -19
  97. package/src/utils/test-data/inspector-state.json +9 -9
  98. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +1180 -0
  99. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +1608 -0
  100. package/src/utils/workflow/dsl/index.ts +11 -0
  101. package/src/utils/workflow/dsl/patterns.ts +279 -0
  102. package/src/utils/workflow/dsl/validation.ts +180 -0
  103. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +415 -0
  104. package/src/utils/workflow/graph/index.ts +6 -0
  105. package/src/utils/workflow/graph/serialize-workflow-graph.ts +223 -0
  106. package/src/utils/workflow/graph/workflow-graph.types.ts +280 -0
  107. package/src/utils/write-service-metadata.ts +51 -0
  108. package/src/visit.ts +9 -3
  109. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,316 @@
1
+ /**
2
+ * Check if a node is a terminal flow (no next step should follow)
3
+ */
4
+ function isTerminalFlow(node) {
5
+ if ('flow' in node) {
6
+ // Cancel and return are terminal flows - they end execution
7
+ return node.flow === 'cancel' || node.flow === 'return';
8
+ }
9
+ return false;
10
+ }
11
+ /**
12
+ * Convert InputSource to DataRef
13
+ */
14
+ function convertInputSource(source) {
15
+ if (source.from === 'literal') {
16
+ return source.value;
17
+ }
18
+ if (source.from === 'input') {
19
+ return { $ref: 'trigger', path: source.path };
20
+ }
21
+ if (source.from === 'outputVar') {
22
+ return { $ref: source.name, path: source.path };
23
+ }
24
+ if (source.from === 'item') {
25
+ return { $ref: '$item', path: source.path };
26
+ }
27
+ if (source.from === 'stateVar') {
28
+ return { $state: source.name, path: source.path };
29
+ }
30
+ if (source.from === 'template') {
31
+ return {
32
+ $template: {
33
+ parts: source.parts,
34
+ expressions: source.expressions?.map((expr) => convertInputSource(expr)),
35
+ },
36
+ };
37
+ }
38
+ return source.value;
39
+ }
40
+ /**
41
+ * Convert a single DSL step to graph node(s)
42
+ */
43
+ function convertStepToNode(step, index, steps, nodeIdPrefix = 'step') {
44
+ const nodeId = `${nodeIdPrefix}_${index}`;
45
+ const nextNodeId = index < steps.length - 1 ? `${nodeIdPrefix}_${index + 1}` : undefined;
46
+ switch (step.type) {
47
+ case 'rpc': {
48
+ const node = {
49
+ nodeId,
50
+ rpcName: step.rpcName,
51
+ stepName: step.stepName,
52
+ next: nextNodeId,
53
+ };
54
+ if (step.inputs) {
55
+ if (step.inputs === 'passthrough') {
56
+ // Entire data is passed through - store as reference to trigger
57
+ node.input = { $passthrough: { $ref: 'trigger' } };
58
+ }
59
+ else {
60
+ node.input = {};
61
+ for (const [key, source] of Object.entries(step.inputs)) {
62
+ node.input[key] = convertInputSource(source);
63
+ }
64
+ }
65
+ }
66
+ if (step.outputVar) {
67
+ node.outputVar = step.outputVar;
68
+ }
69
+ if (step.options) {
70
+ node.options = {
71
+ retries: step.options.retries,
72
+ retryDelay: step.options.retryDelay?.toString(),
73
+ };
74
+ }
75
+ return [node];
76
+ }
77
+ case 'sleep': {
78
+ const node = {
79
+ nodeId,
80
+ flow: 'sleep',
81
+ stepName: step.stepName,
82
+ duration: step.duration,
83
+ next: nextNodeId,
84
+ };
85
+ return [node];
86
+ }
87
+ case 'inline': {
88
+ const node = {
89
+ nodeId,
90
+ flow: 'inline',
91
+ stepName: step.stepName,
92
+ description: step.description,
93
+ next: nextNodeId,
94
+ };
95
+ return [node];
96
+ }
97
+ case 'branch': {
98
+ // Convert all branch conditions (if/else-if chain)
99
+ const branchNodes = [];
100
+ const branches = [];
101
+ for (let i = 0; i < step.branches.length; i++) {
102
+ const branchSteps = convertStepsToNodes(step.branches[i].steps, `${nodeId}_branch${i}`);
103
+ if (branchSteps.length > 0) {
104
+ branches.push({
105
+ condition: step.branches[i].condition,
106
+ entry: branchSteps[0].nodeId,
107
+ });
108
+ // Link last branch node back to next (unless terminal flow)
109
+ if (nextNodeId) {
110
+ const lastBranch = branchSteps[branchSteps.length - 1];
111
+ if (!lastBranch.next && !isTerminalFlow(lastBranch))
112
+ lastBranch.next = nextNodeId;
113
+ }
114
+ branchNodes.push(...branchSteps);
115
+ }
116
+ }
117
+ // Convert else branch
118
+ const elseNodes = step.elseSteps
119
+ ? convertStepsToNodes(step.elseSteps, `${nodeId}_else`)
120
+ : [];
121
+ if (elseNodes.length > 0 && nextNodeId) {
122
+ const lastElse = elseNodes[elseNodes.length - 1];
123
+ if (!lastElse.next && !isTerminalFlow(lastElse))
124
+ lastElse.next = nextNodeId;
125
+ }
126
+ const node = {
127
+ nodeId,
128
+ flow: 'branch',
129
+ branches,
130
+ elseEntry: elseNodes.length > 0 ? elseNodes[0].nodeId : undefined,
131
+ next: nextNodeId,
132
+ };
133
+ return [node, ...branchNodes, ...elseNodes];
134
+ }
135
+ case 'switch': {
136
+ const caseNodes = [];
137
+ const cases = [];
138
+ for (let i = 0; i < step.cases.length; i++) {
139
+ const caseSteps = convertStepsToNodes(step.cases[i].steps, `${nodeId}_case${i}`);
140
+ if (caseSteps.length > 0) {
141
+ cases.push({
142
+ value: step.cases[i].value,
143
+ expression: step.cases[i].expression,
144
+ entry: caseSteps[0].nodeId,
145
+ });
146
+ // Link last case node to next (unless terminal flow)
147
+ if (nextNodeId) {
148
+ const lastCase = caseSteps[caseSteps.length - 1];
149
+ if (!lastCase.next && !isTerminalFlow(lastCase))
150
+ lastCase.next = nextNodeId;
151
+ }
152
+ caseNodes.push(...caseSteps);
153
+ }
154
+ }
155
+ let defaultEntry;
156
+ if (step.defaultSteps) {
157
+ const defaultNodes = convertStepsToNodes(step.defaultSteps, `${nodeId}_default`);
158
+ if (defaultNodes.length > 0) {
159
+ defaultEntry = defaultNodes[0].nodeId;
160
+ // Link last default node to next (unless terminal flow)
161
+ if (nextNodeId) {
162
+ const lastDefault = defaultNodes[defaultNodes.length - 1];
163
+ if (!lastDefault.next && !isTerminalFlow(lastDefault))
164
+ lastDefault.next = nextNodeId;
165
+ }
166
+ caseNodes.push(...defaultNodes);
167
+ }
168
+ }
169
+ const node = {
170
+ nodeId,
171
+ flow: 'switch',
172
+ expression: step.expression,
173
+ cases,
174
+ defaultEntry,
175
+ next: nextNodeId,
176
+ };
177
+ return [node, ...caseNodes];
178
+ }
179
+ case 'parallel': {
180
+ // Convert children to nodes
181
+ const childNodes = [];
182
+ const childEntries = [];
183
+ for (let i = 0; i < step.children.length; i++) {
184
+ const childSteps = convertStepToNode(step.children[i], i, step.children, `${nodeId}_child`);
185
+ if (childSteps.length > 0) {
186
+ childEntries.push(childSteps[0].nodeId);
187
+ childNodes.push(...childSteps);
188
+ }
189
+ }
190
+ const node = {
191
+ nodeId,
192
+ flow: 'parallel',
193
+ children: childEntries,
194
+ next: nextNodeId,
195
+ };
196
+ return [node, ...childNodes];
197
+ }
198
+ case 'fanout': {
199
+ // Convert child step
200
+ const childNodes = convertStepToNode(step.child, 0, [step.child], `${nodeId}_item`);
201
+ const node = {
202
+ nodeId,
203
+ flow: 'fanout',
204
+ stepName: step.stepName,
205
+ sourceVar: step.sourceVar,
206
+ itemVar: step.itemVar,
207
+ mode: step.mode,
208
+ childEntry: childNodes.length > 0 ? childNodes[0].nodeId : undefined,
209
+ timeBetween: step.timeBetween,
210
+ next: nextNodeId,
211
+ };
212
+ return [node, ...childNodes];
213
+ }
214
+ case 'filter': {
215
+ const node = {
216
+ nodeId,
217
+ flow: 'filter',
218
+ sourceVar: step.sourceVar,
219
+ itemVar: step.itemVar,
220
+ condition: step.condition,
221
+ outputVar: step.outputVar,
222
+ next: nextNodeId,
223
+ };
224
+ return [node];
225
+ }
226
+ case 'arrayPredicate': {
227
+ const node = {
228
+ nodeId,
229
+ flow: 'arrayPredicate',
230
+ mode: step.mode,
231
+ sourceVar: step.sourceVar,
232
+ itemVar: step.itemVar,
233
+ condition: step.condition,
234
+ outputVar: step.outputVar,
235
+ next: nextNodeId,
236
+ };
237
+ return [node];
238
+ }
239
+ case 'return': {
240
+ const node = {
241
+ nodeId,
242
+ flow: 'return',
243
+ outputs: step.outputs,
244
+ };
245
+ return [node];
246
+ }
247
+ case 'cancel': {
248
+ const node = {
249
+ nodeId,
250
+ flow: 'cancel',
251
+ reason: step.reason,
252
+ };
253
+ return [node];
254
+ }
255
+ case 'set': {
256
+ const node = {
257
+ nodeId,
258
+ flow: 'set',
259
+ variable: step.variable,
260
+ value: step.value,
261
+ next: nextNodeId,
262
+ };
263
+ return [node];
264
+ }
265
+ default:
266
+ return [];
267
+ }
268
+ }
269
+ /**
270
+ * Convert array of steps to graph nodes
271
+ */
272
+ function convertStepsToNodes(steps, nodeIdPrefix = 'step') {
273
+ const allNodes = [];
274
+ for (let i = 0; i < steps.length; i++) {
275
+ const nodes = convertStepToNode(steps[i], i, steps, nodeIdPrefix);
276
+ allNodes.push(...nodes);
277
+ }
278
+ return allNodes;
279
+ }
280
+ /**
281
+ * Convert a DSL workflow to graph format
282
+ */
283
+ export function convertDslToGraph(workflowName, meta) {
284
+ const nodes = convertStepsToNodes(meta.steps);
285
+ const nodesRecord = {};
286
+ for (const node of nodes) {
287
+ nodesRecord[node.nodeId] = node;
288
+ }
289
+ // Find entry nodes (step_0 is always entry for sequential workflows)
290
+ const entryNodeIds = nodes.length > 0 ? ['step_0'] : [];
291
+ // Determine source type based on dsl flag:
292
+ // - dsl === true: pure DSL workflow, can be serialized
293
+ // - dsl === false: complex workflow with inline steps, not serializable
294
+ const source = meta.dsl === false ? 'complex' : 'dsl';
295
+ return {
296
+ name: workflowName,
297
+ pikkuFuncName: meta.pikkuFuncName,
298
+ source,
299
+ description: meta.description,
300
+ tags: meta.tags,
301
+ context: meta.context,
302
+ wires: {}, // DSL workflows don't have explicit wires in meta
303
+ nodes: nodesRecord,
304
+ entryNodeIds,
305
+ };
306
+ }
307
+ /**
308
+ * Convert all DSL workflows to graph format
309
+ */
310
+ export function convertAllDslToGraphs(workflowsMeta) {
311
+ const result = {};
312
+ for (const [name, meta] of Object.entries(workflowsMeta)) {
313
+ result[name] = convertDslToGraph(name, meta);
314
+ }
315
+ return result;
316
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Workflow graph serialization exports
3
+ */
4
+ export * from './workflow-graph.types.js';
5
+ export { serializeWorkflowGraph } from './serialize-workflow-graph.js';
6
+ export { convertDslToGraph } from './convert-dsl-to-graph.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Workflow graph serialization exports
3
+ */
4
+ export * from './workflow-graph.types.js';
5
+ export { serializeWorkflowGraph } from './serialize-workflow-graph.js';
6
+ export { convertDslToGraph } from './convert-dsl-to-graph.js';
@@ -0,0 +1,43 @@
1
+ import type { SerializedWorkflowGraph, DataRef, SerializedNext } from './workflow-graph.types.js';
2
+ /**
3
+ * Serialize a workflow graph definition (from runtime) to JSON format
4
+ *
5
+ * @param definition - The runtime definition (with callbacks evaluated)
6
+ * @param rpcNameLookup - Function to get RPC name from a node's func
7
+ */
8
+ export declare function serializeWorkflowGraph(definition: {
9
+ name: string;
10
+ wires: {
11
+ http?: {
12
+ route: string;
13
+ method: string;
14
+ };
15
+ queue?: string;
16
+ };
17
+ graph: Record<string, {
18
+ func: {
19
+ name?: string;
20
+ };
21
+ input?: (ref: any) => Record<string, unknown>;
22
+ next?: string | string[] | Record<string, string | string[]>;
23
+ onError?: string | string[];
24
+ }>;
25
+ }, options?: {
26
+ description?: string;
27
+ tags?: string[];
28
+ }): SerializedWorkflowGraph;
29
+ /**
30
+ * Deserialize a workflow graph from JSON to runtime format
31
+ * This re-hydrates the JSON so it can be executed
32
+ */
33
+ export declare function deserializeWorkflowGraph(serialized: SerializedWorkflowGraph): {
34
+ name: string;
35
+ wires: SerializedWorkflowGraph['wires'];
36
+ graph: Record<string, {
37
+ rpcName: string;
38
+ input: Record<string, unknown | DataRef>;
39
+ next?: SerializedNext;
40
+ onError?: string | string[];
41
+ }>;
42
+ entryNodeIds: string[];
43
+ };
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Convert a RefValue (from runtime) to DataRef (serialized)
3
+ */
4
+ function convertRef(ref) {
5
+ return {
6
+ $ref: ref.nodeId,
7
+ path: ref.path,
8
+ };
9
+ }
10
+ /**
11
+ * Check if a value is a runtime RefValue
12
+ */
13
+ function isRefValue(value) {
14
+ return (typeof value === 'object' &&
15
+ value !== null &&
16
+ '__isRef' in value &&
17
+ value.__isRef === true);
18
+ }
19
+ /**
20
+ * Convert input mapping from runtime format to serialized format
21
+ */
22
+ function serializeInputMapping(input) {
23
+ const result = {};
24
+ for (const [key, value] of Object.entries(input)) {
25
+ if (isRefValue(value)) {
26
+ result[key] = convertRef(value);
27
+ }
28
+ else {
29
+ result[key] = value;
30
+ }
31
+ }
32
+ return result;
33
+ }
34
+ /**
35
+ * Convert next config from runtime format to serialized format
36
+ * Runtime uses Record<string, string | string[]> for branching with graph.branch()
37
+ * Serialized uses { conditions: [...], default: ... } for UI-friendly branching
38
+ */
39
+ function serializeNext(next) {
40
+ if (!next)
41
+ return undefined;
42
+ if (typeof next === 'string')
43
+ return next;
44
+ if (Array.isArray(next))
45
+ return next;
46
+ // Record format - convert to conditions format
47
+ // For now, treat keys as branch identifiers (from graph.branch())
48
+ // UI can display these as condition labels
49
+ const conditions = Object.entries(next).map(([key, target]) => ({
50
+ expression: key, // The branch key becomes the expression
51
+ target,
52
+ }));
53
+ return { conditions };
54
+ }
55
+ /**
56
+ * Serialize a workflow graph definition (from runtime) to JSON format
57
+ *
58
+ * @param definition - The runtime definition (with callbacks evaluated)
59
+ * @param rpcNameLookup - Function to get RPC name from a node's func
60
+ */
61
+ export function serializeWorkflowGraph(definition, options) {
62
+ const nodes = {};
63
+ const entryNodeIds = [];
64
+ // Create a ref function that captures refs
65
+ const createRef = (nodeId, path) => ({
66
+ __isRef: true,
67
+ nodeId,
68
+ path,
69
+ });
70
+ // Track which nodes have incoming edges
71
+ const hasIncomingEdge = new Set();
72
+ // First pass: identify nodes with incoming edges
73
+ for (const [_nodeId, node] of Object.entries(definition.graph)) {
74
+ const next = node.next;
75
+ if (!next)
76
+ continue;
77
+ if (typeof next === 'string') {
78
+ hasIncomingEdge.add(next);
79
+ }
80
+ else if (Array.isArray(next)) {
81
+ next.forEach((n) => hasIncomingEdge.add(n));
82
+ }
83
+ else {
84
+ for (const targets of Object.values(next)) {
85
+ if (typeof targets === 'string') {
86
+ hasIncomingEdge.add(targets);
87
+ }
88
+ else {
89
+ targets.forEach((n) => hasIncomingEdge.add(n));
90
+ }
91
+ }
92
+ }
93
+ }
94
+ // Second pass: serialize nodes
95
+ for (const [nodeId, node] of Object.entries(definition.graph)) {
96
+ // Evaluate input callback to get the mapping
97
+ let input = {};
98
+ if (node.input) {
99
+ const rawInput = node.input(createRef);
100
+ input = serializeInputMapping(rawInput);
101
+ }
102
+ // Get RPC name from func
103
+ const rpcName = node.func?.name || 'unknown';
104
+ const funcNode = {
105
+ nodeId,
106
+ rpcName,
107
+ input,
108
+ next: serializeNext(node.next),
109
+ onError: node.onError,
110
+ };
111
+ nodes[nodeId] = funcNode;
112
+ // Entry nodes have no incoming edges
113
+ if (!hasIncomingEdge.has(nodeId)) {
114
+ entryNodeIds.push(nodeId);
115
+ }
116
+ }
117
+ return {
118
+ name: definition.name,
119
+ pikkuFuncName: definition.name, // For graph workflows, pikkuFuncName is the workflow name
120
+ source: 'graph',
121
+ description: options?.description,
122
+ tags: options?.tags,
123
+ wires: definition.wires,
124
+ nodes,
125
+ entryNodeIds,
126
+ };
127
+ }
128
+ /**
129
+ * Deserialize a workflow graph from JSON to runtime format
130
+ * This re-hydrates the JSON so it can be executed
131
+ */
132
+ export function deserializeWorkflowGraph(serialized) {
133
+ const graph = {};
134
+ for (const [nodeId, node] of Object.entries(serialized.nodes)) {
135
+ // Only include FunctionNode properties (nodes with rpcName)
136
+ if ('rpcName' in node) {
137
+ const funcNode = node;
138
+ graph[nodeId] = {
139
+ rpcName: funcNode.rpcName,
140
+ input: funcNode.input ?? {},
141
+ next: funcNode.next,
142
+ onError: funcNode.onError,
143
+ };
144
+ }
145
+ }
146
+ return {
147
+ name: serialized.name,
148
+ wires: serialized.wires,
149
+ graph,
150
+ entryNodeIds: serialized.entryNodeIds,
151
+ };
152
+ }