@pikku/inspector 0.12.60 → 0.12.62

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 (139) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/OPTIMIZATION-PLAN.md +19 -19
  3. package/dist/add/add-auth.js +1 -1
  4. package/dist/add/add-channel.d.ts +1 -1
  5. package/dist/add/add-cli.js +5 -0
  6. package/dist/add/add-functions.js +10 -1
  7. package/dist/add/add-http-route.js +18 -18
  8. package/dist/add/add-keyed-wiring.d.ts +2 -0
  9. package/dist/add/add-keyed-wiring.js +3 -1
  10. package/dist/add/add-personas.js +4 -1
  11. package/dist/add/add-secret.js +1 -0
  12. package/dist/add/add-variable.js +1 -0
  13. package/dist/add/add-wire-remote-addon.js +2 -1
  14. package/dist/add/add-workflow-graph.js +63 -6
  15. package/dist/add/add-workflow.d.ts +1 -1
  16. package/dist/error-codes.d.ts +3 -1
  17. package/dist/error-codes.js +3 -1
  18. package/dist/index.d.ts +4 -2
  19. package/dist/index.js +1 -0
  20. package/dist/inspector.js +12 -2
  21. package/dist/types.d.ts +25 -21
  22. package/dist/utils/annotate-http-route-auth.js +2 -1
  23. package/dist/utils/check-secret-sinks.js +2 -1
  24. package/dist/utils/compute-required-schemas.d.ts +1 -1
  25. package/dist/utils/contract-hashes.d.ts +2 -2
  26. package/dist/utils/contract-hashes.js +1 -1
  27. package/dist/utils/extract-function-name.js +1 -1
  28. package/dist/utils/extract-services.d.ts +1 -1
  29. package/dist/utils/extract-surface-usage.d.ts +29 -0
  30. package/dist/utils/extract-surface-usage.js +97 -0
  31. package/dist/utils/filter-inspector-state.js +53 -16
  32. package/dist/utils/filter-utils.d.ts +1 -1
  33. package/dist/utils/get-property-value.js +42 -3
  34. package/dist/utils/load-addon-functions-meta.js +31 -0
  35. package/dist/utils/middleware.d.ts +1 -1
  36. package/dist/utils/permissions.d.ts +1 -1
  37. package/dist/utils/post-process.d.ts +27 -7
  38. package/dist/utils/post-process.js +79 -14
  39. package/dist/utils/resolve-deploy-target.d.ts +1 -1
  40. package/dist/utils/resolve-function-meta.d.ts +1 -1
  41. package/dist/utils/resolve-function-types.d.ts +1 -1
  42. package/dist/utils/resolve-versions.js +1 -1
  43. package/dist/utils/schema-generator.d.ts +1 -1
  44. package/dist/utils/serialize-inspector-state.d.ts +2 -1
  45. package/dist/utils/serialize-inspector-state.js +2 -0
  46. package/dist/utils/serialize-openapi-json.d.ts +2 -2
  47. package/dist/utils/validate-auth-sessionless.js +2 -1
  48. package/dist/utils/workflow/derive-workflow-plan.d.ts +1 -1
  49. package/dist/utils/workflow/dsl/extract-dsl-workflow.d.ts +1 -1
  50. package/dist/utils/workflow/graph/convert-dsl-to-graph.d.ts +1 -1
  51. package/dist/utils/workflow/graph/finalize-workflows.js +1 -1
  52. package/dist/utils/workflow/graph/index.d.ts +2 -1
  53. package/dist/utils/workflow/graph/index.js +1 -1
  54. package/dist/utils/workflow/graph/serialize-workflow-graph.d.ts +6 -1
  55. package/dist/utils/workflow/graph/serialize-workflow-graph.js +26 -2
  56. package/dist/utils/workflow/graph/workflow-graph.types.d.ts +11 -2
  57. package/package.json +10 -10
  58. package/run-tests.sh +0 -0
  59. package/src/add/add-agent.ts +2 -4
  60. package/src/add/add-auth.ts +2 -2
  61. package/src/add/add-channel.ts +1 -4
  62. package/src/add/add-cli.ts +7 -1
  63. package/src/add/add-credential.ts +3 -6
  64. package/src/add/add-file-with-factory.ts +2 -6
  65. package/src/add/add-functions.ts +24 -31
  66. package/src/add/add-gateway.ts +1 -1
  67. package/src/add/add-http-route-ref.test.ts +149 -0
  68. package/src/add/add-http-route.ts +26 -29
  69. package/src/add/add-keyed-wiring.ts +8 -7
  70. package/src/add/add-permission.ts +1 -1
  71. package/src/add/add-personas.test.ts +26 -2
  72. package/src/add/add-personas.ts +4 -3
  73. package/src/add/add-scenario-step.test.ts +37 -2
  74. package/src/add/add-scope.test.ts +15 -15
  75. package/src/add/add-scope.ts +5 -9
  76. package/src/add/add-secret.ts +1 -0
  77. package/src/add/add-system-role.test.ts +4 -4
  78. package/src/add/add-system-role.ts +2 -4
  79. package/src/add/add-variable.ts +1 -0
  80. package/src/add/add-wire-remote-addon.ts +4 -1
  81. package/src/add/add-workflow-graph-foreach.test.ts +174 -0
  82. package/src/add/add-workflow-graph-input.test.ts +1 -1
  83. package/src/add/add-workflow-graph.ts +78 -6
  84. package/src/add/add-workflow-sleep-expression.test.ts +3 -4
  85. package/src/add/add-workflow.ts +1 -4
  86. package/src/add/addon-contracts.test.ts +1 -1
  87. package/src/add/config-value-metadata.test.ts +94 -0
  88. package/src/add/secret-sink-check.test.ts +4 -1
  89. package/src/error-codes.ts +3 -1
  90. package/src/index.ts +19 -5
  91. package/src/inspector.ts +19 -2
  92. package/src/types.ts +25 -28
  93. package/src/utils/annotate-http-route-auth.test.ts +5 -7
  94. package/src/utils/annotate-http-route-auth.ts +2 -1
  95. package/src/utils/check-secret-sinks.ts +4 -1
  96. package/src/utils/compute-required-schemas.ts +1 -1
  97. package/src/utils/contract-hashes.test.ts +1 -1
  98. package/src/utils/contract-hashes.ts +3 -3
  99. package/src/utils/extract-function-name.ts +1 -1
  100. package/src/utils/extract-services.ts +1 -2
  101. package/src/utils/extract-surface-usage.test.ts +147 -0
  102. package/src/utils/extract-surface-usage.ts +121 -0
  103. package/src/utils/filter-inspector-state.test.ts +138 -12
  104. package/src/utils/filter-inspector-state.ts +82 -21
  105. package/src/utils/filter-utils.ts +1 -1
  106. package/src/utils/get-property-value.ts +43 -5
  107. package/src/utils/load-addon-functions-meta.ts +40 -0
  108. package/src/utils/middleware.ts +1 -1
  109. package/src/utils/permissions.ts +1 -1
  110. package/src/utils/post-process.test.ts +59 -2
  111. package/src/utils/post-process.ts +88 -25
  112. package/src/utils/resolve-deploy-target.ts +1 -1
  113. package/src/utils/resolve-function-meta.ts +1 -4
  114. package/src/utils/resolve-function-types.ts +1 -1
  115. package/src/utils/resolve-versions.ts +2 -5
  116. package/src/utils/schema-generator.ts +3 -3
  117. package/src/utils/serialize-inspector-state.ts +4 -1
  118. package/src/utils/serialize-mcp-json.ts +1 -1
  119. package/src/utils/serialize-openapi-json.ts +2 -2
  120. package/src/utils/validate-auth-sessionless.ts +2 -1
  121. package/src/utils/validate-tags-resolve-to-middleware.test.ts +4 -1
  122. package/src/utils/workflow/derive-workflow-plan.test.ts +1 -1
  123. package/src/utils/workflow/derive-workflow-plan.ts +1 -1
  124. package/src/utils/workflow/dsl/extract-approval-policy.test.ts +1 -1
  125. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +2 -2
  126. package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +1 -1
  127. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +1 -4
  128. package/src/utils/workflow/graph/finalize-workflow-wires.ts +1 -1
  129. package/src/utils/workflow/graph/finalize-workflows.ts +2 -2
  130. package/src/utils/workflow/graph/index.ts +18 -1
  131. package/src/utils/workflow/graph/serialize-workflow-graph.ts +34 -3
  132. package/src/utils/workflow/graph/workflow-graph.types.ts +12 -2
  133. package/tsconfig.tsbuildinfo +1 -1
  134. package/dist/add/add-ai-agent.d.ts +0 -4
  135. package/dist/add/add-ai-agent.js +0 -442
  136. package/dist/add/add-ai-scorer.d.ts +0 -2
  137. package/dist/add/add-ai-scorer.js +0 -61
  138. package/dist/utils/secret-brokers.d.ts +0 -2
  139. package/dist/utils/secret-brokers.js +0 -9
@@ -1,4 +1,4 @@
1
- import { isRef } from '@pikku/core/ecosystem/workflow'
1
+ import { isRef, template } from '@pikku/core/workflow'
2
2
  import type {
3
3
  SerializedWorkflowGraph,
4
4
  SerializedGraphNode,
@@ -36,6 +36,26 @@ function serializeInputMapping(
36
36
  return result
37
37
  }
38
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
+
39
59
  /**
40
60
  * Convert next config from runtime format to serialized format
41
61
  * Runtime uses Record<string, string | string[]> for branching with graph.branch()
@@ -73,7 +93,9 @@ export function serializeWorkflowGraph(
73
93
  string,
74
94
  {
75
95
  func: { name?: string }
76
- input?: (ref: any) => Record<string, unknown>
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'
77
99
  next?: string | string[] | Record<string, string | string[]>
78
100
  onError?: string | string[]
79
101
  notes?: string
@@ -96,6 +118,8 @@ export function serializeWorkflowGraph(
96
118
  path,
97
119
  })
98
120
 
121
+ const createItemRef = (path?: string) => createRef('$item', path)
122
+
99
123
  // Track which nodes have incoming edges
100
124
  const hasIncomingEdge = new Set<string>()
101
125
 
@@ -124,7 +148,7 @@ export function serializeWorkflowGraph(
124
148
  // Evaluate input callback to get the mapping
125
149
  let input: Record<string, unknown | DataRef> = {}
126
150
  if (node.input) {
127
- const rawInput = node.input(createRef)
151
+ const rawInput = node.input(createRef, template, createItemRef)
128
152
  input = serializeInputMapping(rawInput)
129
153
  }
130
154
 
@@ -138,6 +162,13 @@ export function serializeWorkflowGraph(
138
162
  next: serializeNext(node.next),
139
163
  onError: node.onError,
140
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
+ }
141
172
  if (node.notes !== undefined) {
142
173
  funcNode.notes = node.notes
143
174
  }
@@ -115,8 +115,8 @@ import type {
115
115
  ContextVariable,
116
116
  WorkflowContext,
117
117
  WorkflowPlannedStep,
118
- } from '@pikku/core/ecosystem/workflow'
119
- import type { ScenarioStepPhase } from '@pikku/core/ecosystem/scenario'
118
+ } from '@pikku/core/workflow'
119
+ import type { ScenarioStepPhase } from '@pikku/core/scenario'
120
120
 
121
121
  export type { ContextVariable, WorkflowContext }
122
122
 
@@ -141,11 +141,21 @@ interface BaseNode {
141
141
  /**
142
142
  * Function node - calls an RPC
143
143
  */
144
+ /** How the per-item instances of a `forEach` node run */
145
+ export type ForEachMode = 'parallel' | 'sequential'
146
+
144
147
  export interface FunctionNode extends BaseNode {
145
148
  /** RPC function name */
146
149
  rpcName: string
147
150
  /** Input mapping - values can be literals or DataRefs */
148
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
149
159
  /** Output variable name for storing result */
150
160
  outputVar?: string
151
161
  /** Hash of nodeId + RPC input/output schemas for version detection */