@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,280 @@
1
+ /**
2
+ * Serialized types for workflow graphs
3
+ * These are extracted by the inspector and stored as JSON
4
+ * Can be created from code (wireWorkflow) or UI
5
+ */
6
+
7
+ /**
8
+ * Reference to data from another node or trigger
9
+ */
10
+ export interface DataRef {
11
+ /** Source: 'trigger' for trigger input, or node ID for node output */
12
+ $ref: string
13
+ /** Optional path into the data (dot notation: 'body.orderId') */
14
+ path?: string
15
+ }
16
+
17
+ /**
18
+ * Check if value is a DataRef
19
+ */
20
+ export const isDataRef = (value: unknown): value is DataRef =>
21
+ typeof value === 'object' &&
22
+ value !== null &&
23
+ '$ref' in value &&
24
+ typeof (value as DataRef).$ref === 'string'
25
+
26
+ /**
27
+ * Reference to a context/state variable
28
+ */
29
+ export interface StateRef {
30
+ /** Context variable name */
31
+ $state: string
32
+ /** Optional path into the value (dot notation for nested objects) */
33
+ path?: string
34
+ }
35
+
36
+ /**
37
+ * Check if value is a StateRef
38
+ */
39
+ export const isStateRef = (value: unknown): value is StateRef =>
40
+ typeof value === 'object' &&
41
+ value !== null &&
42
+ '$state' in value &&
43
+ typeof (value as StateRef).$state === 'string'
44
+
45
+ /**
46
+ * Helper functions for building input mappings
47
+ */
48
+ export const ref = (nodeId: string, path?: string): DataRef => ({
49
+ $ref: nodeId,
50
+ path,
51
+ })
52
+ export const state = (name: string, path?: string): StateRef => ({
53
+ $state: name,
54
+ path,
55
+ })
56
+
57
+ /**
58
+ * Condition for branching
59
+ */
60
+ export interface BranchCondition {
61
+ /** Expression to evaluate (uses node output references) */
62
+ expression: string
63
+ /** Target node(s) if condition is true */
64
+ target: string | string[]
65
+ }
66
+
67
+ /**
68
+ * Next node configuration
69
+ */
70
+ export type SerializedNext =
71
+ | string // Single next node
72
+ | string[] // Parallel execution
73
+ | {
74
+ /** Conditions evaluated in order, first match wins */
75
+ conditions: BranchCondition[]
76
+ /** Default target if no conditions match */
77
+ default?: string | string[]
78
+ }
79
+
80
+ /**
81
+ * Node execution options
82
+ */
83
+ export interface NodeOptions {
84
+ /** Number of retry attempts on failure */
85
+ retries?: number
86
+ /** Delay between retries (e.g., '1s', '5s') */
87
+ retryDelay?: string
88
+ /** Timeout for node execution (e.g., '30s', '5m') */
89
+ timeout?: string
90
+ /** If true, execute via queue (async). Default: false (inline) */
91
+ async?: boolean
92
+ }
93
+
94
+ /**
95
+ * Flow node types for control flow (no RPC call)
96
+ */
97
+ export type FlowType =
98
+ | 'sleep'
99
+ | 'branch'
100
+ | 'parallel'
101
+ | 'fanout'
102
+ | 'inline'
103
+ | 'switch'
104
+ | 'filter'
105
+ | 'arrayPredicate'
106
+ | 'return'
107
+ | 'cancel'
108
+ | 'set'
109
+
110
+ // Import and re-export context types from core
111
+ import type { ContextVariable, WorkflowContext } from '@pikku/core/workflow'
112
+
113
+ export type { ContextVariable, WorkflowContext }
114
+
115
+ /**
116
+ * Base node properties shared by all node types
117
+ */
118
+ interface BaseNode {
119
+ /** Node ID */
120
+ nodeId: string
121
+ /** Step name/description */
122
+ stepName?: string
123
+ /** Next node(s) - simple, parallel, or conditional */
124
+ next?: SerializedNext
125
+ /** Error routing - node(s) to execute on error */
126
+ onError?: string | string[]
127
+ /** Execution options */
128
+ options?: NodeOptions
129
+ }
130
+
131
+ /**
132
+ * Function node - calls an RPC
133
+ */
134
+ export interface FunctionNode extends BaseNode {
135
+ /** RPC function name */
136
+ rpcName: string
137
+ /** Input mapping - values can be literals or DataRefs */
138
+ input?: Record<string, unknown | DataRef>
139
+ /** Output variable name for storing result */
140
+ outputVar?: string
141
+ }
142
+
143
+ /**
144
+ * Flow node - control flow only, no RPC call
145
+ */
146
+ export interface FlowNode extends BaseNode {
147
+ /** Flow type */
148
+ flow: FlowType
149
+ /** Flow-specific properties */
150
+ [key: string]: unknown
151
+ }
152
+
153
+ /**
154
+ * Serialized graph node - either a function node or flow node
155
+ */
156
+ export type SerializedGraphNode = FunctionNode | FlowNode
157
+
158
+ /**
159
+ * Type guard for function nodes
160
+ */
161
+ export const isFunctionNode = (
162
+ node: SerializedGraphNode
163
+ ): node is FunctionNode => 'rpcName' in node
164
+
165
+ /**
166
+ * Type guard for flow nodes
167
+ */
168
+ export const isFlowNode = (node: SerializedGraphNode): node is FlowNode =>
169
+ 'flow' in node
170
+
171
+ /**
172
+ * HTTP wire configuration with startNode
173
+ */
174
+ export interface HttpWire {
175
+ route: string
176
+ method: 'get' | 'post' | 'put' | 'patch' | 'delete'
177
+ startNode: string
178
+ }
179
+
180
+ /**
181
+ * Channel wire configuration
182
+ */
183
+ export interface ChannelWire {
184
+ name: string
185
+ onConnect?: string
186
+ onDisconnect?: string
187
+ onMessage?: string
188
+ }
189
+
190
+ /**
191
+ * Queue wire configuration
192
+ */
193
+ export interface QueueWire {
194
+ name: string
195
+ startNode: string
196
+ }
197
+
198
+ /**
199
+ * CLI wire configuration
200
+ */
201
+ export interface CliWire {
202
+ command: string
203
+ startNode: string
204
+ }
205
+
206
+ /**
207
+ * MCP wire configurations
208
+ */
209
+ export interface McpWires {
210
+ tool?: Array<{ name: string; startNode: string }>
211
+ prompt?: Array<{ name: string; startNode: string }>
212
+ resource?: Array<{ uri: string; startNode: string }>
213
+ }
214
+
215
+ /**
216
+ * Schedule wire configuration
217
+ */
218
+ export interface ScheduleWire {
219
+ cron?: string
220
+ interval?: string
221
+ startNode: string
222
+ }
223
+
224
+ /**
225
+ * Trigger wire configuration
226
+ */
227
+ export interface TriggerWire {
228
+ name: string
229
+ startNode: string
230
+ }
231
+
232
+ /**
233
+ * All wire configurations for workflows
234
+ */
235
+ export interface WorkflowWiresConfig {
236
+ http?: HttpWire[]
237
+ channel?: ChannelWire[]
238
+ queue?: QueueWire[]
239
+ cli?: CliWire[]
240
+ mcp?: McpWires
241
+ schedule?: ScheduleWire[]
242
+ trigger?: TriggerWire[]
243
+ }
244
+
245
+ /**
246
+ * Workflow source type
247
+ * - 'dsl': Pure DSL workflow (pikkuWorkflowFunc) - can be round-tripped to code
248
+ * - 'complex': Complex workflow (pikkuWorkflowComplexFunc) - contains inline steps, not serializable
249
+ * - 'graph': Graph-based workflow (pikkuWorkflowGraph)
250
+ */
251
+ export type WorkflowSourceType = 'dsl' | 'complex' | 'graph'
252
+
253
+ /**
254
+ * Serialized workflow graph - the canonical JSON format
255
+ */
256
+ export interface SerializedWorkflowGraph {
257
+ /** Workflow name */
258
+ name: string
259
+ /** Pikku function name (for runtime registration) */
260
+ pikkuFuncName: string
261
+ /** Source type: 'dsl' for pikkuWorkflowFunc, 'graph' for pikkuWorkflowGraph */
262
+ source: WorkflowSourceType
263
+ /** Optional description */
264
+ description?: string
265
+ /** Tags for organization */
266
+ tags?: string[]
267
+ /** Workflow context/state variables (from Zod schema) */
268
+ context?: WorkflowContext
269
+ /** Wires - how the workflow is triggered */
270
+ wires: WorkflowWiresConfig
271
+ /** Serialized nodes */
272
+ nodes: Record<string, SerializedGraphNode>
273
+ /** Entry node(s) - first nodes to execute */
274
+ entryNodeIds: string[]
275
+ }
276
+
277
+ /**
278
+ * All workflow graphs (serialized)
279
+ */
280
+ export type SerializedWorkflowGraphs = Record<string, SerializedWorkflowGraph>
@@ -0,0 +1,51 @@
1
+ import * as fs from 'fs'
2
+ import * as path from 'path'
3
+ import { ServiceMetadata } from './extract-service-metadata.js'
4
+
5
+ /**
6
+ * Write service metadata to a JSON file in .pikku/services directory
7
+ */
8
+ export function writeServiceMetadata(
9
+ serviceMeta: ServiceMetadata,
10
+ outDir: string
11
+ ): void {
12
+ const servicesDir = path.join(outDir, 'services')
13
+
14
+ if (!fs.existsSync(servicesDir)) {
15
+ fs.mkdirSync(servicesDir, { recursive: true })
16
+ }
17
+
18
+ const fileName = `${serviceMeta.name}.gen.json`
19
+ const filePath = path.join(servicesDir, fileName)
20
+
21
+ const jsonContent = JSON.stringify(serviceMeta, null, 2)
22
+ fs.writeFileSync(filePath, jsonContent, 'utf-8')
23
+ }
24
+
25
+ /**
26
+ * Write all service metadata files
27
+ */
28
+ export function writeAllServiceMetadata(
29
+ servicesMetadata: ServiceMetadata[],
30
+ outDir: string
31
+ ): void {
32
+ for (const serviceMeta of servicesMetadata) {
33
+ writeServiceMetadata(serviceMeta, outDir)
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Clean up services directory (remove old service JSON files)
39
+ */
40
+ export function cleanServicesDirectory(outDir: string): void {
41
+ const servicesDir = path.join(outDir, 'services')
42
+
43
+ if (fs.existsSync(servicesDir)) {
44
+ const files = fs.readdirSync(servicesDir)
45
+ for (const file of files) {
46
+ if (file.endsWith('.gen.json')) {
47
+ fs.unlinkSync(path.join(servicesDir, file))
48
+ }
49
+ }
50
+ }
51
+ }
package/src/visit.ts CHANGED
@@ -15,6 +15,9 @@ import { addRPCInvocations } from './add/add-rpc-invocations.js'
15
15
  import { addMiddleware } from './add/add-middleware.js'
16
16
  import { addPermission } from './add/add-permission.js'
17
17
  import { addCLI, addCLIRenderers } from './add/add-cli.js'
18
+ import { addForgeNode } from './add/add-forge-node.js'
19
+ import { addForgeCredential } from './add/add-forge-credential.js'
20
+ import { addWorkflowGraph } from './add/add-workflow-graph.js'
18
21
 
19
22
  export const visitSetup = (
20
23
  logger: InspectorLogger,
@@ -34,7 +37,7 @@ export const visitSetup = (
34
37
  addFileExtendsCoreType(
35
38
  node,
36
39
  checker,
37
- state.sessionServicesTypeImportMap,
40
+ state.wireServicesTypeImportMap,
38
41
  'CoreServices',
39
42
  state
40
43
  )
@@ -65,8 +68,8 @@ export const visitSetup = (
65
68
  addFileWithFactory(
66
69
  node,
67
70
  checker,
68
- state.sessionServicesFactories,
69
- 'CreateSessionServices',
71
+ state.wireServicesFactories,
72
+ 'CreateWireServices',
70
73
  state
71
74
  )
72
75
 
@@ -99,6 +102,9 @@ export const visitRoutes = (
99
102
  addMCPResource(logger, node, checker, state, options)
100
103
  addMCPTool(logger, node, checker, state, options)
101
104
  addMCPPrompt(logger, node, checker, state, options)
105
+ addForgeNode(logger, node, checker, state, options)
106
+ addForgeCredential(logger, node, checker, state, options)
107
+ addWorkflowGraph(logger, node, checker, state, options)
102
108
 
103
109
  ts.forEachChild(node, (child) =>
104
110
  visitRoutes(logger, checker, child, state, options)