@pikku/inspector 0.12.75 → 0.12.82

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 (223) hide show
  1. package/CHANGELOG.md +357 -0
  2. package/dist/add/add-analytics.d.ts +9 -0
  3. package/dist/add/add-analytics.js +178 -0
  4. package/dist/add/add-auth.js +0 -54
  5. package/dist/add/add-feature-flag.d.ts +2 -0
  6. package/dist/add/add-feature-flag.js +162 -0
  7. package/dist/add/add-middleware.js +66 -42
  8. package/dist/add/add-wire-addon.js +7 -4
  9. package/dist/add/add-wire-remote-addon.js +1 -0
  10. package/dist/error-codes.d.ts +1 -0
  11. package/dist/error-codes.js +1 -0
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +3 -1
  14. package/dist/inspector.js +5 -0
  15. package/dist/surface/collect-surface.d.ts +58 -0
  16. package/dist/surface/collect-surface.js +613 -0
  17. package/dist/types.d.ts +36 -12
  18. package/dist/utils/filter-inspector-state.js +14 -0
  19. package/dist/utils/load-addon-functions-meta.js +24 -11
  20. package/dist/utils/post-process.js +15 -0
  21. package/dist/utils/read-module-specifiers.d.ts +8 -0
  22. package/dist/utils/read-module-specifiers.js +23 -0
  23. package/dist/utils/read-tsconfig-out-dir.d.ts +5 -0
  24. package/dist/utils/read-tsconfig-out-dir.js +12 -0
  25. package/dist/utils/resolve-deploy-target.d.ts +7 -0
  26. package/dist/utils/resolve-deploy-target.js +15 -7
  27. package/dist/utils/serialize-inspector-state.d.ts +6 -0
  28. package/dist/utils/serialize-inspector-state.js +10 -0
  29. package/dist/visit.js +4 -0
  30. package/package.json +16 -6
  31. package/run-tests.sh +21 -6
  32. package/src/add/add-addon-bans.ts +0 -85
  33. package/src/add/add-agent-scorer.test.ts +0 -197
  34. package/src/add/add-agent-scorer.ts +0 -83
  35. package/src/add/add-agent.test.ts +0 -87
  36. package/src/add/add-agent.ts +0 -638
  37. package/src/add/add-approval-description.ts +0 -76
  38. package/src/add/add-auth.test.ts +0 -791
  39. package/src/add/add-auth.ts +0 -424
  40. package/src/add/add-channel.ts +0 -778
  41. package/src/add/add-cli-renderers.test.ts +0 -74
  42. package/src/add/add-cli.ts +0 -1006
  43. package/src/add/add-credential.ts +0 -186
  44. package/src/add/add-feature.test.ts +0 -306
  45. package/src/add/add-feature.ts +0 -253
  46. package/src/add/add-file-extends-core-type.ts +0 -66
  47. package/src/add/add-file-with-config.ts +0 -45
  48. package/src/add/add-file-with-factory.test.ts +0 -134
  49. package/src/add/add-file-with-factory.ts +0 -288
  50. package/src/add/add-functions.test.ts +0 -743
  51. package/src/add/add-functions.ts +0 -1548
  52. package/src/add/add-gateway.ts +0 -143
  53. package/src/add/add-http-route-ref.test.ts +0 -149
  54. package/src/add/add-http-route.ts +0 -530
  55. package/src/add/add-http-routes.ts +0 -471
  56. package/src/add/add-keyed-wiring.ts +0 -180
  57. package/src/add/add-mcp-prompt.ts +0 -157
  58. package/src/add/add-mcp-resource.ts +0 -175
  59. package/src/add/add-middleware.test.ts +0 -196
  60. package/src/add/add-middleware.ts +0 -879
  61. package/src/add/add-permission-auth.test.ts +0 -59
  62. package/src/add/add-permission.ts +0 -311
  63. package/src/add/add-personas.test.ts +0 -406
  64. package/src/add/add-personas.ts +0 -287
  65. package/src/add/add-queue-worker.ts +0 -117
  66. package/src/add/add-rpc-invocations.test.ts +0 -287
  67. package/src/add/add-rpc-invocations.ts +0 -221
  68. package/src/add/add-scenario-step.test.ts +0 -509
  69. package/src/add/add-schedule.ts +0 -120
  70. package/src/add/add-scope.test.ts +0 -419
  71. package/src/add/add-scope.ts +0 -221
  72. package/src/add/add-secret.ts +0 -10
  73. package/src/add/add-subject-scenario-steps.test.ts +0 -161
  74. package/src/add/add-system-role.test.ts +0 -297
  75. package/src/add/add-system-role.ts +0 -162
  76. package/src/add/add-trigger.ts +0 -165
  77. package/src/add/add-variable.ts +0 -10
  78. package/src/add/add-wire-addon.test.ts +0 -185
  79. package/src/add/add-wire-addon.ts +0 -146
  80. package/src/add/add-wire-remote-addon.ts +0 -80
  81. package/src/add/add-workflow-edge-cases.test.ts +0 -201
  82. package/src/add/add-workflow-fanout.test.ts +0 -166
  83. package/src/add/add-workflow-graph-foreach.test.ts +0 -174
  84. package/src/add/add-workflow-graph-input.test.ts +0 -94
  85. package/src/add/add-workflow-graph-notes.test.ts +0 -74
  86. package/src/add/add-workflow-graph.ts +0 -644
  87. package/src/add/add-workflow-on-error.test.ts +0 -118
  88. package/src/add/add-workflow-return-switch.test.ts +0 -121
  89. package/src/add/add-workflow-silent-drops.test.ts +0 -261
  90. package/src/add/add-workflow-sleep-expression.test.ts +0 -96
  91. package/src/add/add-workflow.test.ts +0 -155
  92. package/src/add/add-workflow.ts +0 -482
  93. package/src/add/addon-bans.test.ts +0 -121
  94. package/src/add/addon-contracts.test.ts +0 -221
  95. package/src/add/allow-escape-hatches.test.ts +0 -144
  96. package/src/add/audit-meta.test.ts +0 -75
  97. package/src/add/classified-sink-check.test.ts +0 -347
  98. package/src/add/config-value-metadata.test.ts +0 -263
  99. package/src/add/dynamic-import-check.test.ts +0 -119
  100. package/src/add/expect-eventually-scenario-only.test.ts +0 -108
  101. package/src/add/function-body-span.test.ts +0 -96
  102. package/src/add/inline-wiring-function.test.ts +0 -104
  103. package/src/add/pii-check.test.ts +0 -258
  104. package/src/add/rpc-type-cast.test.ts +0 -123
  105. package/src/add/scenario-instrumentation.test.ts +0 -89
  106. package/src/add/scenario-instrumentation.ts +0 -42
  107. package/src/add/scenario-marker.test.ts +0 -89
  108. package/src/add/scenario-not-extractable.test.ts +0 -159
  109. package/src/add/scenario-services.test.ts +0 -103
  110. package/src/add/scenario-skip.test.ts +0 -83
  111. package/src/add/validate-workflow-graph-addons.test.ts +0 -102
  112. package/src/add/wire-name-literal.test.ts +0 -117
  113. package/src/error-codes-emitted.test.ts +0 -76
  114. package/src/error-codes.ts +0 -145
  115. package/src/index.ts +0 -66
  116. package/src/inspector.ts +0 -575
  117. package/src/schema-generator.ts +0 -1
  118. package/src/source-file-cache.ts +0 -73
  119. package/src/tsconfig-paths.test.ts +0 -90
  120. package/src/types-map.ts +0 -141
  121. package/src/types.ts +0 -775
  122. package/src/utils/annotate-http-route-auth.test.ts +0 -161
  123. package/src/utils/annotate-http-route-auth.ts +0 -53
  124. package/src/utils/check-classified-sinks.ts +0 -215
  125. package/src/utils/check-pii-output.ts +0 -120
  126. package/src/utils/compute-diagnostics.test.ts +0 -106
  127. package/src/utils/compute-required-schemas.ts +0 -48
  128. package/src/utils/contract-hashes.test.ts +0 -553
  129. package/src/utils/contract-hashes.ts +0 -387
  130. package/src/utils/custom-types-generator.test.ts +0 -124
  131. package/src/utils/custom-types-generator.ts +0 -150
  132. package/src/utils/detect-schema-vendor.test.ts +0 -123
  133. package/src/utils/detect-schema-vendor.ts +0 -120
  134. package/src/utils/does-type-extend-core-type.ts +0 -53
  135. package/src/utils/ensure-function-metadata.ts +0 -385
  136. package/src/utils/extract-function-name.ts +0 -612
  137. package/src/utils/extract-function-node.ts +0 -70
  138. package/src/utils/extract-node-value.test.ts +0 -117
  139. package/src/utils/extract-node-value.ts +0 -172
  140. package/src/utils/extract-secret-usage.test.ts +0 -81
  141. package/src/utils/extract-secret-usage.ts +0 -73
  142. package/src/utils/extract-services.ts +0 -70
  143. package/src/utils/extract-surface-usage.test.ts +0 -147
  144. package/src/utils/extract-surface-usage.ts +0 -121
  145. package/src/utils/filter-inspector-state.test.ts +0 -2232
  146. package/src/utils/filter-inspector-state.ts +0 -1298
  147. package/src/utils/filter-utils.test.ts +0 -843
  148. package/src/utils/filter-utils.ts +0 -161
  149. package/src/utils/find-root-dir.ts +0 -68
  150. package/src/utils/find-zod-transform.test.ts +0 -70
  151. package/src/utils/find-zod-transform.ts +0 -103
  152. package/src/utils/get-exported-variable-name.ts +0 -48
  153. package/src/utils/get-files-and-methods.ts +0 -157
  154. package/src/utils/get-property-value.test.ts +0 -141
  155. package/src/utils/get-property-value.ts +0 -331
  156. package/src/utils/hash.ts +0 -26
  157. package/src/utils/literal-properties.ts +0 -97
  158. package/src/utils/load-addon-functions-meta.test.ts +0 -157
  159. package/src/utils/load-addon-functions-meta.ts +0 -508
  160. package/src/utils/load-addon-scopes.test.ts +0 -138
  161. package/src/utils/middleware.test.ts +0 -204
  162. package/src/utils/middleware.ts +0 -303
  163. package/src/utils/nested-project-filter.test.ts +0 -53
  164. package/src/utils/nested-project-filter.ts +0 -28
  165. package/src/utils/permissions-shorthand.test.ts +0 -79
  166. package/src/utils/permissions.test.ts +0 -125
  167. package/src/utils/permissions.ts +0 -129
  168. package/src/utils/post-process.test.ts +0 -1094
  169. package/src/utils/post-process.ts +0 -1604
  170. package/src/utils/resolve-addon-package.ts +0 -106
  171. package/src/utils/resolve-core-type.test.ts +0 -142
  172. package/src/utils/resolve-core-type.ts +0 -35
  173. package/src/utils/resolve-deploy-target.test.ts +0 -135
  174. package/src/utils/resolve-deploy-target.ts +0 -65
  175. package/src/utils/resolve-function-meta.ts +0 -25
  176. package/src/utils/resolve-function-types.ts +0 -42
  177. package/src/utils/resolve-identifier.ts +0 -46
  178. package/src/utils/resolve-ref-contract.ts +0 -71
  179. package/src/utils/resolve-versions.test.ts +0 -499
  180. package/src/utils/resolve-versions.ts +0 -228
  181. package/src/utils/schema-cache.test.ts +0 -124
  182. package/src/utils/schema-generator.test.ts +0 -272
  183. package/src/utils/schema-generator.ts +0 -780
  184. package/src/utils/secret-alias-services.test.ts +0 -146
  185. package/src/utils/secret-alias-services.ts +0 -58
  186. package/src/utils/serialize-inspector-state.ts +0 -742
  187. package/src/utils/serialize-mcp-json.ts +0 -150
  188. package/src/utils/serialize-middleware-groups-meta.ts +0 -36
  189. package/src/utils/serialize-openapi-json.ts +0 -277
  190. package/src/utils/serialize-permissions-groups-meta.ts +0 -7
  191. package/src/utils/single-declaration.ts +0 -57
  192. package/src/utils/type-utils.ts +0 -145
  193. package/src/utils/validate-auth-sessionless.ts +0 -30
  194. package/src/utils/validate-exposed-functions-gated.test.ts +0 -230
  195. package/src/utils/validate-exposed-functions-gated.ts +0 -103
  196. package/src/utils/validate-tags-resolve-to-middleware.test.ts +0 -108
  197. package/src/utils/validate-tags-resolve-to-middleware.ts +0 -48
  198. package/src/utils/workflow/derive-workflow-plan.test.ts +0 -178
  199. package/src/utils/workflow/derive-workflow-plan.ts +0 -117
  200. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +0 -1465
  201. package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +0 -71
  202. package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +0 -99
  203. package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +0 -161
  204. package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +0 -121
  205. package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +0 -116
  206. package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +0 -145
  207. package/src/utils/workflow/dsl/extract-approval-policy.test.ts +0 -71
  208. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +0 -2254
  209. package/src/utils/workflow/dsl/index.ts +0 -11
  210. package/src/utils/workflow/dsl/patterns.ts +0 -440
  211. package/src/utils/workflow/dsl/validation.ts +0 -203
  212. package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +0 -35
  213. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +0 -543
  214. package/src/utils/workflow/graph/fanout-node-identity.test.ts +0 -105
  215. package/src/utils/workflow/graph/finalize-workflow-wires.ts +0 -310
  216. package/src/utils/workflow/graph/finalize-workflows.test.ts +0 -50
  217. package/src/utils/workflow/graph/finalize-workflows.ts +0 -130
  218. package/src/utils/workflow/graph/index.ts +0 -28
  219. package/src/utils/workflow/graph/serialize-workflow-graph.ts +0 -240
  220. package/src/utils/workflow/graph/workflow-graph.types.ts +0 -281
  221. package/src/visit.ts +0 -181
  222. package/tsconfig.json +0 -19
  223. package/tsconfig.tsbuildinfo +0 -1
@@ -1,240 +0,0 @@
1
- import { isRef, template } from '@pikku/core/workflow'
2
- import type {
3
- SerializedWorkflowGraph,
4
- SerializedGraphNode,
5
- FunctionNode,
6
- DataRef,
7
- SerializedNext,
8
- } from './workflow-graph.types.js'
9
-
10
- /**
11
- * Convert a RefValue (from runtime) to DataRef (serialized)
12
- */
13
- function convertRef(ref: { nodeId: string; path?: string }): DataRef {
14
- return {
15
- $ref: ref.nodeId,
16
- path: ref.path,
17
- }
18
- }
19
-
20
- /**
21
- * Convert input mapping from runtime format to serialized format
22
- */
23
- function serializeInputMapping(
24
- input: Record<string, unknown>
25
- ): Record<string, unknown | DataRef> {
26
- const result: Record<string, unknown | DataRef> = {}
27
-
28
- for (const [key, value] of Object.entries(input)) {
29
- if (isRef(value)) {
30
- result[key] = convertRef(value)
31
- } else {
32
- result[key] = value
33
- }
34
- }
35
-
36
- return result
37
- }
38
-
39
- /**
40
- * Convert a `forEach` source — a bare node id, a ref, or a `(ref) => ref(...)`
41
- * callback — to the serialized DataRef form
42
- */
43
- function serializeForEach(
44
- forEach: unknown,
45
- createRef: (nodeId: string, path?: string) => { nodeId: string; path?: string }
46
- ): DataRef | undefined {
47
- if (forEach === undefined) return undefined
48
- if (typeof forEach === 'string') return { $ref: forEach }
49
- if (typeof forEach === 'function') {
50
- return serializeForEach(
51
- (forEach as (ref: unknown) => unknown)(createRef),
52
- createRef
53
- )
54
- }
55
- if (isRef(forEach)) return convertRef(forEach)
56
- return undefined
57
- }
58
-
59
- /**
60
- * Convert next config from runtime format to serialized format
61
- * Runtime uses Record<string, string | string[]> for branching with graph.branch()
62
- * Serialized uses { conditions: [...], default: ... } for UI-friendly branching
63
- */
64
- function serializeNext(
65
- next: string | string[] | Record<string, string | string[]> | undefined
66
- ): SerializedNext | undefined {
67
- if (!next) return undefined
68
-
69
- if (typeof next === 'string') return next
70
- if (Array.isArray(next)) return next
71
-
72
- // Record format - convert to conditions format
73
- // For now, treat keys as branch identifiers (from graph.branch())
74
- // UI can display these as condition labels
75
- const conditions = Object.entries(next).map(([key, target]) => ({
76
- expression: key, // The branch key becomes the expression
77
- target,
78
- }))
79
-
80
- return { conditions }
81
- }
82
-
83
- /**
84
- * Serialize a workflow graph definition (from runtime) to JSON format
85
- *
86
- * @param definition - The runtime definition (with callbacks evaluated)
87
- * @param rpcNameLookup - Function to get RPC name from a node's func
88
- */
89
- export function serializeWorkflowGraph(
90
- definition: {
91
- name: string
92
- graph: Record<
93
- string,
94
- {
95
- func: { name?: string }
96
- input?: (ref: any, template?: any, $item?: any) => Record<string, unknown>
97
- forEach?: string | { nodeId: string; path?: string } | ((ref: any) => unknown)
98
- mode?: 'parallel' | 'sequential'
99
- next?: string | string[] | Record<string, string | string[]>
100
- onError?: string | string[]
101
- notes?: string
102
- }
103
- >
104
- },
105
- options?: {
106
- description?: string
107
- tags?: string[]
108
- notes?: string[]
109
- }
110
- ): SerializedWorkflowGraph {
111
- const nodes: Record<string, SerializedGraphNode> = {}
112
- const entryNodeIds: string[] = []
113
-
114
- // Create a ref function that captures refs
115
- const createRef = (nodeId: string, path?: string) => ({
116
- __isRef: true as const,
117
- nodeId,
118
- path,
119
- })
120
-
121
- const createItemRef = (path?: string) => createRef('$item', path)
122
-
123
- // Track which nodes have incoming edges
124
- const hasIncomingEdge = new Set<string>()
125
-
126
- // First pass: identify nodes with incoming edges
127
- for (const [_nodeId, node] of Object.entries(definition.graph)) {
128
- const next = node.next
129
- if (!next) continue
130
-
131
- if (typeof next === 'string') {
132
- hasIncomingEdge.add(next)
133
- } else if (Array.isArray(next)) {
134
- next.forEach((n) => hasIncomingEdge.add(n))
135
- } else {
136
- for (const targets of Object.values(next)) {
137
- if (typeof targets === 'string') {
138
- hasIncomingEdge.add(targets)
139
- } else {
140
- targets.forEach((n) => hasIncomingEdge.add(n))
141
- }
142
- }
143
- }
144
- }
145
-
146
- // Second pass: serialize nodes
147
- for (const [nodeId, node] of Object.entries(definition.graph)) {
148
- // Evaluate input callback to get the mapping
149
- let input: Record<string, unknown | DataRef> = {}
150
- if (node.input) {
151
- const rawInput = node.input(createRef, template, createItemRef)
152
- input = serializeInputMapping(rawInput)
153
- }
154
-
155
- // Get RPC name from func
156
- const rpcName = node.func?.name || 'unknown'
157
-
158
- const funcNode: FunctionNode = {
159
- nodeId,
160
- rpcName,
161
- input,
162
- next: serializeNext(node.next),
163
- onError: node.onError,
164
- }
165
- const forEach = serializeForEach(node.forEach, createRef)
166
- if (forEach) {
167
- funcNode.forEach = forEach
168
- if (node.mode !== undefined) {
169
- funcNode.mode = node.mode
170
- }
171
- }
172
- if (node.notes !== undefined) {
173
- funcNode.notes = node.notes
174
- }
175
- nodes[nodeId] = funcNode
176
-
177
- // Entry nodes have no incoming edges
178
- if (!hasIncomingEdge.has(nodeId)) {
179
- entryNodeIds.push(nodeId)
180
- }
181
- }
182
-
183
- return {
184
- name: definition.name,
185
- pikkuFuncId: definition.name, // For graph workflows, pikkuFuncId is the workflow name
186
- source: 'graph' as const,
187
- description: options?.description,
188
- tags: options?.tags,
189
- notes: options?.notes,
190
- nodes,
191
- entryNodeIds,
192
- }
193
- }
194
-
195
- /**
196
- * Deserialize a workflow graph from JSON to runtime format
197
- * This re-hydrates the JSON so it can be executed
198
- */
199
- export function deserializeWorkflowGraph(serialized: SerializedWorkflowGraph): {
200
- name: string
201
- graph: Record<
202
- string,
203
- {
204
- rpcName: string
205
- input: Record<string, unknown | DataRef>
206
- next?: SerializedNext
207
- onError?: string | string[]
208
- }
209
- >
210
- entryNodeIds: string[]
211
- } {
212
- const graph: Record<
213
- string,
214
- {
215
- rpcName: string
216
- input: Record<string, unknown | DataRef>
217
- next?: SerializedNext
218
- onError?: string | string[]
219
- }
220
- > = {}
221
-
222
- for (const [nodeId, node] of Object.entries(serialized.nodes)) {
223
- // Only include FunctionNode properties (nodes with rpcName)
224
- if ('rpcName' in node) {
225
- const funcNode = node as FunctionNode
226
- graph[nodeId] = {
227
- rpcName: funcNode.rpcName,
228
- input: funcNode.input ?? {},
229
- next: funcNode.next,
230
- onError: funcNode.onError,
231
- }
232
- }
233
- }
234
-
235
- return {
236
- name: serialized.name,
237
- graph,
238
- entryNodeIds: serialized.entryNodeIds,
239
- }
240
- }
@@ -1,281 +0,0 @@
1
- /**
2
- * Serialized types for workflow graphs
3
- * These are extracted by the inspector and stored as JSON
4
- * Can be created from code (pikkuWorkflowGraph) 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
- // Key-based branching: the running node picks a key via `graph.branch(key)`,
80
- // routing to `next[key]`. Keys are branch/output identifiers, not predicates.
81
- | Record<string, string | string[]>
82
-
83
- /**
84
- * Node execution options
85
- */
86
- export interface NodeOptions {
87
- /** Number of retry attempts on failure */
88
- retries?: number
89
- /** Delay between retries (e.g., '1s', '5s', or a number of milliseconds) */
90
- retryDelay?: string | number
91
- /** Timeout for node execution (e.g., '30s', '5m') */
92
- timeout?: string
93
- }
94
-
95
- /**
96
- * Flow node types for control flow (no RPC call)
97
- */
98
- export type FlowType =
99
- | 'sleep'
100
- | 'suspend'
101
- | 'approval'
102
- | 'branch'
103
- | 'parallel'
104
- | 'fanout'
105
- | 'inline'
106
- | 'switch'
107
- | 'filter'
108
- | 'arrayPredicate'
109
- | 'return'
110
- | 'cancel'
111
- | 'set'
112
-
113
- // Import and re-export context types from core
114
- import type {
115
- ContextVariable,
116
- WorkflowContext,
117
- WorkflowPlannedStep,
118
- } from '@pikku/core/workflow'
119
- import type { ScenarioStepPhase } from '@pikku/core/scenario'
120
-
121
- export type { ContextVariable, WorkflowContext }
122
-
123
- /**
124
- * Base node properties shared by all node types
125
- */
126
- interface BaseNode {
127
- /** Node ID */
128
- nodeId: string
129
- /** Step name/description */
130
- stepName?: string
131
- /** Next node(s) - simple, parallel, or conditional */
132
- next?: SerializedNext
133
- /** Error routing - node(s) to execute on error */
134
- onError?: string | string[]
135
- /** Execution options */
136
- options?: NodeOptions
137
- /** Free-text node documentation. Non-semantic — excluded from graphHash. */
138
- notes?: string
139
- }
140
-
141
- /**
142
- * Function node - calls an RPC
143
- */
144
- /** How the per-item instances of a `forEach` node run */
145
- export type ForEachMode = 'parallel' | 'sequential'
146
-
147
- export interface FunctionNode extends BaseNode {
148
- /** RPC function name */
149
- rpcName: string
150
- /** Input mapping - values can be literals or DataRefs */
151
- input?: Record<string, unknown | DataRef>
152
- /**
153
- * Run this node once per element of the referenced array. The node's own
154
- * result becomes the ordered array of per-item results.
155
- */
156
- forEach?: DataRef
157
- /** How the per-item instances run. Defaults to 'parallel'. */
158
- mode?: ForEachMode
159
- /** Output variable name for storing result */
160
- outputVar?: string
161
- /** Hash of nodeId + RPC input/output schemas for version detection */
162
- stepHash?: string
163
- /** Scenario actor name this step runs as (workflow.do {actor: actors.x}) */
164
- actor?: string
165
- /** True for workflow.expectEventually polling steps (scenarios) */
166
- expectEventually?: boolean
167
- /** Gherkin-style phase for a declared scenario step (scenario.given/when/then) */
168
- scenarioStepPhase?: ScenarioStepPhase
169
- }
170
-
171
- /**
172
- * Flow node - control flow only, no RPC call
173
- */
174
- export interface FlowNode extends BaseNode {
175
- /** Flow type */
176
- flow: FlowType
177
- /** Flow-specific properties */
178
- [key: string]: unknown
179
- }
180
-
181
- /**
182
- * Serialized graph node - either a function node or flow node
183
- */
184
- export type SerializedGraphNode = FunctionNode | FlowNode
185
-
186
- /**
187
- * Type guard for function nodes
188
- */
189
- export const isFunctionNode = (
190
- node: SerializedGraphNode
191
- ): node is FunctionNode => 'rpcName' in node
192
-
193
- /**
194
- * Type guard for flow nodes
195
- */
196
- export const isFlowNode = (node: SerializedGraphNode): node is FlowNode =>
197
- 'flow' in node
198
-
199
- /**
200
- * Workflow source type
201
- * - 'dsl': Pure DSL workflow (pikkuWorkflowFunc) - can be round-tripped to code
202
- * - 'complex': Complex workflow (pikkuWorkflowComplexFunc) - contains inline steps, not serializable
203
- * - 'graph': Graph-based workflow (pikkuWorkflowGraph)
204
- * - 'scenario': Scenario (pikkuScenario) - complex workflow whose steps run as actors
205
- */
206
- export type WorkflowSourceType = 'dsl' | 'complex' | 'graph' | 'scenario'
207
-
208
- /**
209
- * Serialized workflow graph - the canonical JSON format
210
- */
211
- export interface SerializedWorkflowGraph {
212
- /** Workflow name */
213
- name: string
214
- /** Pikku function name (for runtime registration) */
215
- pikkuFuncId: string
216
- /** Source type: 'dsl' for pikkuWorkflowFunc, 'graph' for pikkuWorkflowGraph */
217
- source: WorkflowSourceType
218
- /** Optional short display name */
219
- title?: string
220
- /** Optional description */
221
- description?: string
222
- /** Tags for organization */
223
- tags?: string[]
224
- /** Actor names a scenario's steps run as */
225
- actors?: string[]
226
- /** Why a scenario is held out of a default run, stated where it is declared */
227
- skip?: string
228
- /** If true, workflow always executes inline without queues */
229
- inline?: boolean
230
- /** Workflow context/state variables (from Zod schema) */
231
- context?: WorkflowContext
232
- /** Serialized nodes */
233
- nodes: Record<string, SerializedGraphNode>
234
- /** Graph-level free-text notes (e.g. imported sticky notes). Non-semantic — excluded from graphHash. */
235
- notes?: string[]
236
- /** Entry node(s) - first nodes to execute */
237
- entryNodeIds: string[]
238
- /** Hash of graph topology (nodes, edges, input mappings) */
239
- graphHash?: string
240
- /**
241
- * True when the exact executed step sequence is known up front: a loopless
242
- * DSL workflow with no branches/switches. Lets a UI render the run as a fixed
243
- * pipeline. Loops (fanout) → omitted; branchy-but-loopless → false.
244
- */
245
- deterministic?: boolean
246
- /**
247
- * Every named step the workflow can run, in source order — so a frontend can
248
- * render the step skeleton before the run starts. Populated for any loopless
249
- * DSL workflow (a branchy one lists all possible steps); omitted when the step
250
- * count is runtime-dependent (any fanout).
251
- */
252
- plannedSteps?: WorkflowPlannedStep[]
253
- /** Wire entry points (HTTP, channel, queue, etc.) that trigger this workflow */
254
- wires?: WorkflowWires
255
- }
256
-
257
- export interface WorkflowWires {
258
- http?: Array<{ route: string; method: string; startNode: string }>
259
- channel?: Array<{
260
- name: string
261
- route: string
262
- onConnect?: string
263
- onMessage?: string
264
- onDisconnect?: string
265
- onMessageRoute?: Record<string, string>
266
- }>
267
- queue?: Array<{ name: string; startNode: string }>
268
- cli?: Array<{ command: string; startNode: string }>
269
- mcp?: {
270
- tool?: Array<{ name: string; startNode: string }>
271
- prompt?: Array<{ name: string; startNode: string }>
272
- resource?: Array<{ uri: string; startNode: string }>
273
- }
274
- schedule?: Array<{ cron: string; startNode: string }>
275
- trigger?: Array<{ name: string; startNode: string }>
276
- }
277
-
278
- /**
279
- * All workflow graphs (serialized)
280
- */
281
- export type SerializedWorkflowGraphs = Record<string, SerializedWorkflowGraph>
package/src/visit.ts DELETED
@@ -1,181 +0,0 @@
1
- import * as ts from 'typescript'
2
- import { addFileWithFactory } from './add/add-file-with-factory.js'
3
- import { addFileExtendsCoreType } from './add/add-file-extends-core-type.js'
4
- import { addHTTPRoute } from './add/add-http-route.js'
5
- import { addHTTPRoutes } from './add/add-http-routes.js'
6
- import { checkAddonBans } from './add/add-addon-bans.js'
7
- import { addSchedule } from './add/add-schedule.js'
8
- import { addTrigger } from './add/add-trigger.js'
9
- import { addQueueWorker } from './add/add-queue-worker.js'
10
- import { addWorkflow } from './add/add-workflow.js'
11
- import { addMCPResource } from './add/add-mcp-resource.js'
12
- import { addMCPPrompt } from './add/add-mcp-prompt.js'
13
- import type {
14
- InspectorState,
15
- InspectorLogger,
16
- InspectorOptions,
17
- } from './types.js'
18
- import { addFunctions } from './add/add-functions.js'
19
- import { addChannel } from './add/add-channel.js'
20
- import { addGateway } from './add/add-gateway.js'
21
- import { addRPCInvocations } from './add/add-rpc-invocations.js'
22
- import { addWireAddon } from './add/add-wire-addon.js'
23
- import { addWireRemoteAddon } from './add/add-wire-remote-addon.js'
24
- import { addMiddleware } from './add/add-middleware.js'
25
- import { addPermission } from './add/add-permission.js'
26
- import { addCLI, addCLIRenderers } from './add/add-cli.js'
27
- import { addAuth } from './add/add-auth.js'
28
- import { addSecret } from './add/add-secret.js'
29
- import { addCredential } from './add/add-credential.js'
30
- import { addScope } from './add/add-scope.js'
31
- import { addSystemRole } from './add/add-system-role.js'
32
- import { addPersonas } from './add/add-personas.js'
33
- import { addVariable } from './add/add-variable.js'
34
- import { addWorkflowGraph } from './add/add-workflow-graph.js'
35
- import { addFeature } from './add/add-feature.js'
36
- import { addAgent } from './add/add-agent.js'
37
- import { addAgentScorer } from './add/add-agent-scorer.js'
38
- import { addApprovalDescription } from './add/add-approval-description.js'
39
-
40
- export const visitSetup = (
41
- logger: InspectorLogger,
42
- checker: ts.TypeChecker,
43
- node: ts.Node,
44
- state: InspectorState,
45
- options: InspectorOptions
46
- ) => {
47
- addFileExtendsCoreType(
48
- node,
49
- checker,
50
- state.singletonServicesTypeImportMap,
51
- 'CoreSingletonServices',
52
- state
53
- )
54
-
55
- addFileExtendsCoreType(
56
- node,
57
- checker,
58
- state.wireServicesTypeImportMap,
59
- 'CoreServices',
60
- state
61
- )
62
-
63
- addFileExtendsCoreType(
64
- node,
65
- checker,
66
- state.userSessionTypeImportMap,
67
- 'CoreUserSession',
68
- state
69
- )
70
-
71
- addFileExtendsCoreType(
72
- node,
73
- checker,
74
- state.configTypeImportMap,
75
- 'CoreConfig',
76
- state
77
- )
78
-
79
- addFileWithFactory(
80
- node,
81
- checker,
82
- state.singletonServicesFactories,
83
- 'CreateSingletonServices',
84
- state
85
- )
86
-
87
- addFileWithFactory(
88
- node,
89
- checker,
90
- state.wireServicesFactories,
91
- 'CreateWireServices',
92
- state
93
- )
94
-
95
- addFileWithFactory(node, checker, state.configFactories, 'CreateConfig')
96
- addFileWithFactory(
97
- node,
98
- checker,
99
- state.serverLifecycleFactories,
100
- 'ServerLifecycle'
101
- )
102
-
103
- addRPCInvocations(node, state, logger)
104
- addWireAddon(node, state, logger)
105
- addWireRemoteAddon(node, state, logger)
106
- addMiddleware(logger, node, checker, state, options)
107
- addPermission(logger, node, checker, state, options)
108
- addApprovalDescription(logger, node, checker, state, options)
109
- addWorkflow(logger, node, checker, state, options)
110
-
111
- ts.forEachChild(node, (child) =>
112
- visitSetup(logger, checker, child, state, options)
113
- )
114
- }
115
-
116
- // Register every pikku function before transports/wirings are resolved, so that
117
- // resolution (e.g. a channel handler referencing a function defined in another
118
- // file) is independent of source-file traversal order. Runs between visitSetup
119
- // and visitRoutes.
120
- export const visitFunctions = (
121
- logger: InspectorLogger,
122
- checker: ts.TypeChecker,
123
- node: ts.Node,
124
- state: InspectorState,
125
- options: InspectorOptions
126
- ) => {
127
- const nextOptions = ts.isSourceFile(node)
128
- ? { ...options, sourceFile: node }
129
- : options
130
-
131
- addFunctions(logger, node, checker, state, nextOptions)
132
-
133
- ts.forEachChild(node, (child) =>
134
- visitFunctions(logger, checker, child, state, nextOptions)
135
- )
136
- }
137
-
138
- export const visitRoutes = (
139
- logger: InspectorLogger,
140
- checker: ts.TypeChecker,
141
- node: ts.Node,
142
- state: InspectorState,
143
- options: InspectorOptions
144
- ) => {
145
- const nextOptions = ts.isSourceFile(node)
146
- ? { ...options, sourceFile: node }
147
- : options
148
-
149
- checkAddonBans(logger, node, checker, state, nextOptions)
150
-
151
- // NOTE: addFunctions runs in its own earlier pass (visitFunctions) so that
152
- // every function is registered before any wiring (channels, CLI, etc.)
153
- // resolves it — wiring resolution must not depend on source-file order.
154
- addAuth(logger, node, checker, state, nextOptions)
155
- addSecret(logger, node, checker, state, nextOptions)
156
- addCredential(logger, node, checker, state, nextOptions)
157
- addScope(logger, node, checker, state, nextOptions)
158
- addSystemRole(logger, node, checker, state, nextOptions)
159
- addPersonas(logger, node, checker, state, nextOptions)
160
- addVariable(logger, node, checker, state, nextOptions)
161
-
162
- addHTTPRoute(logger, node, checker, state, nextOptions)
163
- addHTTPRoutes(logger, node, checker, state, nextOptions)
164
- addSchedule(logger, node, checker, state, nextOptions)
165
- addTrigger(logger, node, checker, state, nextOptions)
166
- addQueueWorker(logger, node, checker, state, nextOptions)
167
- addChannel(logger, node, checker, state, nextOptions)
168
- addGateway(logger, node, checker, state, nextOptions)
169
- addCLI(logger, node, checker, state, nextOptions)
170
- addCLIRenderers(logger, node, checker, state, nextOptions)
171
- addMCPResource(logger, node, checker, state, nextOptions)
172
- addMCPPrompt(logger, node, checker, state, nextOptions)
173
- addWorkflowGraph(logger, node, checker, state, nextOptions)
174
- addFeature(logger, node, checker, state, nextOptions)
175
- addAgent(logger, node, checker, state, nextOptions)
176
- addAgentScorer(logger, node, checker, state, nextOptions)
177
-
178
- ts.forEachChild(node, (child) =>
179
- visitRoutes(logger, checker, child, state, nextOptions)
180
- )
181
- }