@pikku/core 0.12.79 → 0.12.80

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 (330) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/dist/dev/hot-reload.js +1 -6
  3. package/dist/ecosystem.d.ts +27 -0
  4. package/dist/ecosystem.js +26 -0
  5. package/dist/errors/error-handler.js +4 -2
  6. package/dist/function/function-runner.js +20 -42
  7. package/dist/function/functions.types.d.ts +9 -5
  8. package/dist/index.d.ts +4 -9
  9. package/dist/index.js +3 -8
  10. package/dist/middleware/auth-cookie.d.ts +0 -4
  11. package/dist/middleware/auth-cookie.js +38 -2
  12. package/dist/middleware/cors.js +1 -0
  13. package/dist/middleware/index.d.ts +1 -1
  14. package/dist/middleware/index.js +1 -1
  15. package/dist/middleware/remote-auth.js +14 -3
  16. package/dist/permissions.d.ts +8 -10
  17. package/dist/permissions.js +0 -11
  18. package/dist/pikku-state.js +12 -5
  19. package/dist/schema.js +35 -1
  20. package/dist/services/ai-run-state-service.d.ts +7 -1
  21. package/dist/services/in-memory-ai-run-state-service.d.ts +1 -1
  22. package/dist/services/in-memory-ai-run-state-service.js +2 -1
  23. package/dist/services/in-memory-workflow-service.js +2 -0
  24. package/dist/services/local-content-request-handler.d.ts +21 -0
  25. package/dist/services/local-content-request-handler.js +72 -53
  26. package/dist/services/local-content.d.ts +6 -0
  27. package/dist/services/local-content.js +14 -1
  28. package/dist/services/workflow-service.d.ts +4 -2
  29. package/dist/testing/service-tests/agent-run-service-tests.d.ts +10 -0
  30. package/dist/testing/service-tests/agent-run-service-tests.js +72 -0
  31. package/dist/testing/service-tests/ai-storage-service-tests.d.ts +3 -0
  32. package/dist/testing/service-tests/ai-storage-service-tests.js +226 -0
  33. package/dist/testing/service-tests/channel-store-tests.d.ts +3 -0
  34. package/dist/testing/service-tests/channel-store-tests.js +72 -0
  35. package/dist/testing/service-tests/credential-service-tests.d.ts +3 -0
  36. package/dist/testing/service-tests/credential-service-tests.js +109 -0
  37. package/dist/testing/service-tests/deployment-service-tests.d.ts +3 -0
  38. package/dist/testing/service-tests/deployment-service-tests.js +21 -0
  39. package/dist/testing/service-tests/event-hub-store-tests.d.ts +3 -0
  40. package/dist/testing/service-tests/event-hub-store-tests.js +34 -0
  41. package/dist/testing/service-tests/secret-service-tests.d.ts +3 -0
  42. package/dist/testing/service-tests/secret-service-tests.js +80 -0
  43. package/dist/testing/service-tests/session-store-tests.d.ts +3 -0
  44. package/dist/testing/service-tests/session-store-tests.js +43 -0
  45. package/dist/testing/service-tests/workflow-run-service-tests.d.ts +3 -0
  46. package/dist/testing/service-tests/workflow-run-service-tests.js +42 -0
  47. package/dist/testing/service-tests/workflow-service-tests.d.ts +3 -0
  48. package/dist/testing/service-tests/workflow-service-tests.js +150 -0
  49. package/dist/testing/service-tests.d.ts +6 -0
  50. package/dist/testing/service-tests.js +26 -791
  51. package/dist/types/core.types.d.ts +11 -1
  52. package/dist/types/state.types.d.ts +1 -1
  53. package/dist/wirings/actor-flow/run-conversation.js +1 -6
  54. package/dist/wirings/ai-agent/agent-rpc.d.ts +15 -0
  55. package/dist/wirings/ai-agent/agent-rpc.js +53 -0
  56. package/dist/wirings/ai-agent/ai-agent-agui.js +1 -5
  57. package/dist/wirings/ai-agent/ai-agent-memory.js +3 -1
  58. package/dist/wirings/ai-agent/ai-agent-prepare.js +3 -9
  59. package/dist/wirings/ai-agent/ai-agent-runner.js +28 -107
  60. package/dist/wirings/ai-agent/ai-agent-stream.js +20 -61
  61. package/dist/wirings/ai-agent/ai-agent-turn.d.ts +56 -0
  62. package/dist/wirings/ai-agent/ai-agent-turn.js +81 -0
  63. package/dist/wirings/ai-agent/ai-agent.types.d.ts +1 -1
  64. package/dist/wirings/ai-agent/voice-input.js +1 -6
  65. package/dist/wirings/ai-agent/voice-output.js +2 -12
  66. package/dist/wirings/channel/channel-common.js +1 -0
  67. package/dist/wirings/channel/channel-handler.js +3 -5
  68. package/dist/wirings/channel/channel-rpc-service.d.ts +0 -6
  69. package/dist/wirings/channel/channel-rpc-service.js +0 -8
  70. package/dist/wirings/channel/channel-rpc.types.d.ts +6 -0
  71. package/dist/wirings/channel/channel-rpc.types.js +8 -0
  72. package/dist/wirings/channel/channel-runner.d.ts +1 -3
  73. package/dist/wirings/channel/channel-runner.js +16 -8
  74. package/dist/wirings/channel/channel.types.d.ts +2 -0
  75. package/dist/wirings/channel/pikku-abstract-channel-handler.js +1 -0
  76. package/dist/wirings/channel/serverless/serverless-channel-runner.js +3 -0
  77. package/dist/wirings/cli/channel/cli-channel-runner.js +2 -0
  78. package/dist/wirings/cli/cli-runner.js +4 -2
  79. package/dist/wirings/cli/cli.types.d.ts +0 -8
  80. package/dist/wirings/cli/command-parser.js +13 -0
  81. package/dist/wirings/gateway/gateway-runner.js +9 -2
  82. package/dist/wirings/http/http-routes.js +2 -0
  83. package/dist/wirings/http/http-runner.d.ts +0 -10
  84. package/dist/wirings/http/http-runner.js +6 -13
  85. package/dist/wirings/http/http.types.d.ts +0 -10
  86. package/dist/wirings/http/index.d.ts +1 -1
  87. package/dist/wirings/http/index.js +1 -1
  88. package/dist/wirings/mcp/mcp-runner.d.ts +0 -7
  89. package/dist/wirings/mcp/mcp-runner.js +0 -6
  90. package/dist/wirings/rpc/rpc-runner.d.ts +8 -51
  91. package/dist/wirings/rpc/rpc-runner.js +53 -86
  92. package/dist/wirings/rpc/rpc-types.d.ts +3 -0
  93. package/dist/wirings/secret/validate-secret-definitions.js +2 -2
  94. package/dist/wirings/trigger/pikku-trigger-service.d.ts +0 -4
  95. package/dist/wirings/trigger/trigger-runner.js +1 -0
  96. package/dist/wirings/virtual-user/run-virtual-user.js +11 -11
  97. package/dist/wirings/virtual-user/virtual-user-derive.js +4 -25
  98. package/dist/wirings/virtual-user/virtual-user-dispositions.js +1 -4
  99. package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +29 -2
  100. package/dist/wirings/workflow/feature.js +7 -4
  101. package/dist/wirings/workflow/graph/graph-runner.d.ts +1 -2
  102. package/dist/wirings/workflow/graph/graph-runner.js +8 -7
  103. package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +0 -4
  104. package/dist/wirings/workflow/index.d.ts +7 -2
  105. package/dist/wirings/workflow/index.js +5 -1
  106. package/dist/wirings/workflow/pikku-scenario-service.d.ts +17 -3
  107. package/dist/wirings/workflow/pikku-scenario-service.js +38 -10
  108. package/dist/wirings/workflow/pikku-workflow-service.d.ts +28 -147
  109. package/dist/wirings/workflow/pikku-workflow-service.js +71 -493
  110. package/dist/wirings/workflow/workflow-approval.d.ts +39 -0
  111. package/dist/wirings/workflow/workflow-approval.js +114 -0
  112. package/dist/wirings/workflow/workflow-constants.d.ts +26 -0
  113. package/dist/wirings/workflow/workflow-constants.js +35 -0
  114. package/dist/wirings/workflow/workflow-errors.d.ts +58 -0
  115. package/dist/wirings/workflow/workflow-errors.js +112 -0
  116. package/dist/wirings/workflow/workflow-meta-resolver.d.ts +11 -0
  117. package/dist/wirings/workflow/workflow-meta-resolver.js +31 -0
  118. package/dist/wirings/workflow/workflow-queue-routing.d.ts +8 -0
  119. package/dist/wirings/workflow/workflow-queue-routing.js +38 -0
  120. package/dist/wirings/workflow/workflow-queue-wiring.d.ts +20 -0
  121. package/dist/wirings/workflow/workflow-queue-wiring.js +79 -0
  122. package/dist/wirings/workflow/workflow-recovery.d.ts +68 -0
  123. package/dist/wirings/workflow/workflow-recovery.js +101 -0
  124. package/dist/wirings/workflow/workflow-run-engine.types.d.ts +54 -0
  125. package/dist/wirings/workflow/workflow-run-engine.types.js +1 -0
  126. package/dist/wirings/workflow/workflow-run-ownership.d.ts +16 -0
  127. package/dist/wirings/workflow/workflow-run-ownership.js +29 -0
  128. package/dist/wirings/workflow/workflow-suspend.d.ts +12 -0
  129. package/dist/wirings/workflow/workflow-suspend.js +33 -0
  130. package/dist/wirings/workflow/workflow.types.d.ts +7 -0
  131. package/knowledge/decisions/internals/a-non-streaming-agent-run-registers-with-airunstate-too.md +22 -0
  132. package/knowledge/decisions/internals/a-resumed-agent-turn-is-as-interruptible-as-the-first.md +20 -0
  133. package/knowledge/decisions/internals/a-scenario-step-template-is-offered-unfilled.md +21 -0
  134. package/knowledge/decisions/internals/a-virtual-user-decides-whether-to-trust-memory-once-per-turn.md +21 -0
  135. package/knowledge/decisions/internals/a-wall-clock-threshold-is-a-load-test-in-disguise.md +46 -0
  136. package/knowledge/decisions/internals/a-workflow-wire-is-built-from-the-run-not-from-the-rpc-service.md +45 -0
  137. package/knowledge/decisions/internals/agent-context-waits-for-a-tool-result-still-being-written.md +21 -0
  138. package/knowledge/decisions/internals/agent-speech-travels-as-a-custom-agui-event.md +22 -0
  139. package/knowledge/decisions/internals/an-agent-interrupt-is-not-a-failure.md +23 -0
  140. package/knowledge/decisions/internals/an-agent-run-owned-by-another-instance-says-so.md +25 -0
  141. package/knowledge/decisions/internals/an-agent-stream-send-must-return-the-inner-sends-promise.md +22 -0
  142. package/knowledge/decisions/internals/an-empty-text-part-is-omitted-from-an-agent-message.md +20 -0
  143. package/knowledge/decisions/internals/an-empty-transcript-is-not-recorded.md +22 -0
  144. package/knowledge/decisions/internals/an-unref-d-timer-cannot-be-awaited-under-node-test.md +66 -0
  145. package/knowledge/decisions/internals/channel-state-accessors-are-unsound-generics-that-every-implementation-asserts.md +33 -0
  146. package/knowledge/decisions/internals/gateway-listener-middleware-runs-without-an-rpc-on-the-wire.md +43 -0
  147. package/knowledge/decisions/internals/hot-reload-writes-into-the-function-map-captured-at-startup.md +26 -0
  148. package/knowledge/decisions/internals/index.md +38 -26
  149. package/knowledge/decisions/internals/only-exposed-functions-enter-a-virtual-user-catalogue.md +21 -0
  150. package/knowledge/decisions/internals/scenario-given-and-when-are-sugar-but-then-is-not.md +24 -0
  151. package/knowledge/decisions/internals/side-effects-are-an-allowlist-not-a-boolean.md +34 -0
  152. package/knowledge/decisions/internals/speech-synthesis-picks-a-voice-per-sentence-and-warns-once.md +24 -0
  153. package/knowledge/decisions/internals/the-actor-prompt-says-json-because-of-json-object-mode.md +22 -0
  154. package/knowledge/decisions/internals/the-agent-done-event-goes-through-the-middleware-and-is-awaited.md +26 -0
  155. package/knowledge/decisions/internals/the-api-report-pins-members-not-just-names.md +43 -0
  156. package/knowledge/decisions/internals/the-ecosystem-entry-point-carries-the-adapter-surface.md +58 -0
  157. package/knowledge/decisions/internals/the-middleware-resolution-cache-is-deliberately-unbounded.md +40 -0
  158. package/knowledge/decisions/internals/the-per-invocation-rpc-view-is-a-class.md +40 -0
  159. package/knowledge/decisions/internals/the-persona-runtime-is-exported-from-the-persona-entry-point.md +28 -0
  160. package/knowledge/decisions/internals/the-transcript-event-is-sent-ahead-of-the-run.md +25 -0
  161. package/knowledge/decisions/internals/the-virtual-user-catalogue-is-the-only-gate-on-what-may-be-called.md +21 -0
  162. package/knowledge/decisions/internals/the-worker-disposition-is-the-one-that-is-not-testing.md +22 -0
  163. package/knowledge/decisions/internals/thread-history-records-the-transcript-not-the-audio.md +25 -0
  164. package/knowledge/decisions/internals/virtual-user-step-order-comes-from-insertion-order.md +21 -0
  165. package/knowledge/decisions/internals/voice-output-speaks-unless-voice-input-explicitly-says-otherwise.md +24 -0
  166. package/knowledge/decisions/internals/wiring-registries-erase-the-generics-their-wire-functions-capture.md +35 -0
  167. package/knowledge/decisions/security/a-dropped-audit-write-is-always-logged.md +4 -2
  168. package/knowledge/decisions/security/a-graph-run-starts-at-an-entry-node-the-graph-declared.md +33 -0
  169. package/knowledge/decisions/security/a-permission-gets-a-wire-it-cannot-reply-on.md +33 -0
  170. package/knowledge/decisions/security/a-step-runs-the-function-the-workflow-dispatched-it-with.md +37 -0
  171. package/knowledge/decisions/security/a-virtual-user-is-never-offered-a-step-that-would-forge-its-own-oracle.md +28 -0
  172. package/knowledge/decisions/security/a-workflow-run-is-read-and-approved-by-its-owner.md +34 -0
  173. package/knowledge/decisions/security/an-agent-approval-is-claimed-before-the-tool-runs.md +33 -0
  174. package/knowledge/decisions/security/an-upload-is-counted-as-it-arrives-not-buffered-then-measured.md +24 -0
  175. package/knowledge/decisions/security/index.md +7 -0
  176. package/knowledge/questions/channel-middleware-accepts-bare-factories-that-nothing-resolves.md +35 -0
  177. package/knowledge/questions/index.md +2 -1
  178. package/knowledge/questions/unauthorized-channel-replies-escape-the-declared-out-type.md +44 -0
  179. package/package.json +13 -3
  180. package/scripts/generate-api-report.d.mts +1 -0
  181. package/scripts/generate-api-report.mjs +89 -0
  182. package/scripts/generate-api-report.mts +218 -0
  183. package/src/api-report.test.ts +69 -0
  184. package/src/column-form.ts +1 -4
  185. package/src/crypto-utils.test.ts +15 -2
  186. package/src/dev/hot-reload.ts +2 -7
  187. package/src/ecosystem.ts +40 -0
  188. package/src/errors/error-handler.ts +5 -3
  189. package/src/errors/error.test.ts +4 -1
  190. package/src/function/function-runner.test.ts +1 -1
  191. package/src/function/function-runner.ts +28 -39
  192. package/src/function/functions.types.ts +15 -9
  193. package/src/handle-error.ts +1 -1
  194. package/src/index.ts +3 -22
  195. package/src/middleware/auth-cookie.test.ts +50 -0
  196. package/src/middleware/auth-cookie.ts +38 -2
  197. package/src/middleware/cors.ts +2 -1
  198. package/src/middleware/index.ts +1 -1
  199. package/src/middleware/remote-auth.test.ts +43 -0
  200. package/src/middleware/remote-auth.ts +17 -3
  201. package/src/middleware-runner.ts +4 -2
  202. package/src/no-any-casts.test.ts +57 -0
  203. package/src/permissions.test.ts +3 -1
  204. package/src/permissions.ts +22 -24
  205. package/src/pikku-state.ts +17 -6
  206. package/src/public-surface.json +578 -0
  207. package/src/public-surface.json.README +25 -0
  208. package/src/public-surface.test.ts +105 -0
  209. package/src/removed-legacy-exports.test.ts +62 -0
  210. package/src/schema.test.ts +78 -0
  211. package/src/schema.ts +36 -1
  212. package/src/services/ai-run-state-service.ts +7 -1
  213. package/src/services/audit-service.ts +2 -2
  214. package/src/services/in-memory-ai-run-state-service.ts +3 -2
  215. package/src/services/in-memory-workflow-service.ts +2 -0
  216. package/src/services/index.ts +1 -4
  217. package/src/services/local-content-request-handler.test.ts +43 -5
  218. package/src/services/local-content-request-handler.ts +103 -74
  219. package/src/services/local-content.ts +15 -1
  220. package/src/services/local-email-service.ts +5 -1
  221. package/src/services/system-role-guard.test.ts +4 -1
  222. package/src/services/workflow-service.ts +9 -2
  223. package/src/side-effects-are-declared.test.ts +84 -0
  224. package/src/source-files-stay-composable.test.ts +41 -0
  225. package/src/testing/service-tests/agent-run-service-tests.ts +98 -0
  226. package/src/testing/service-tests/ai-storage-service-tests.ts +286 -0
  227. package/src/testing/service-tests/channel-store-tests.ts +98 -0
  228. package/src/testing/service-tests/credential-service-tests.ts +143 -0
  229. package/src/testing/service-tests/deployment-service-tests.ts +33 -0
  230. package/src/testing/service-tests/event-hub-store-tests.ts +48 -0
  231. package/src/testing/service-tests/secret-service-tests.ts +105 -0
  232. package/src/testing/service-tests/session-store-tests.ts +62 -0
  233. package/src/testing/service-tests/workflow-run-service-tests.ts +59 -0
  234. package/src/testing/service-tests/workflow-service-tests.ts +308 -0
  235. package/src/testing/service-tests.ts +31 -1111
  236. package/src/types/core.types.ts +15 -1
  237. package/src/types/state.types.ts +1 -1
  238. package/src/wirings/actor-flow/run-conversation.ts +1 -6
  239. package/src/wirings/ai-agent/agent-rpc.ts +120 -0
  240. package/src/wirings/ai-agent/ai-agent-agui.ts +1 -5
  241. package/src/wirings/ai-agent/ai-agent-interrupt.test.ts +2 -1
  242. package/src/wirings/ai-agent/ai-agent-memory.ts +8 -1
  243. package/src/wirings/ai-agent/ai-agent-prepare.ts +10 -12
  244. package/src/wirings/ai-agent/ai-agent-resume-authorization.test.ts +1 -0
  245. package/src/wirings/ai-agent/ai-agent-runner.test.ts +82 -2
  246. package/src/wirings/ai-agent/ai-agent-runner.ts +49 -120
  247. package/src/wirings/ai-agent/ai-agent-stream.test.ts +2 -0
  248. package/src/wirings/ai-agent/ai-agent-stream.ts +36 -63
  249. package/src/wirings/ai-agent/ai-agent-thread-ownership.test.ts +1 -1
  250. package/src/wirings/ai-agent/ai-agent-turn.ts +121 -0
  251. package/src/wirings/ai-agent/ai-agent.types.ts +1 -1
  252. package/src/wirings/ai-agent/voice-input.ts +1 -6
  253. package/src/wirings/ai-agent/voice-output.ts +2 -12
  254. package/src/wirings/channel/channel-common.ts +5 -2
  255. package/src/wirings/channel/channel-handler-shapes.test.ts +72 -0
  256. package/src/wirings/channel/channel-handler.ts +7 -7
  257. package/src/wirings/channel/channel-rpc-service.ts +0 -14
  258. package/src/wirings/channel/channel-rpc.test.ts +25 -4
  259. package/src/wirings/channel/channel-rpc.types.ts +14 -0
  260. package/src/wirings/channel/channel-runner.ts +33 -20
  261. package/src/wirings/channel/channel.types.ts +2 -0
  262. package/src/wirings/channel/local/local-channel-runner.ts +1 -1
  263. package/src/wirings/channel/pikku-abstract-channel-handler.ts +2 -1
  264. package/src/wirings/channel/serverless/serverless-channel-runner.ts +6 -3
  265. package/src/wirings/cli/channel/cli-channel-runner.ts +3 -1
  266. package/src/wirings/cli/channel/cli-raw-client-runner.ts +4 -1
  267. package/src/wirings/cli/cli-runner.ts +7 -4
  268. package/src/wirings/cli/cli.types.ts +0 -39
  269. package/src/wirings/cli/command-parser.test.ts +19 -0
  270. package/src/wirings/cli/command-parser.ts +17 -1
  271. package/src/wirings/gateway/gateway-channel-meta.test.ts +44 -0
  272. package/src/wirings/gateway/gateway-runner.ts +27 -19
  273. package/src/wirings/http/http-routes.ts +4 -1
  274. package/src/wirings/http/http-runner.ts +11 -26
  275. package/src/wirings/http/http.types.ts +0 -15
  276. package/src/wirings/http/index.ts +1 -7
  277. package/src/wirings/http/pikku-fetch-http-request.ts +2 -2
  278. package/src/wirings/http/web-request.ts +1 -1
  279. package/src/wirings/mcp/mcp-runner.ts +2 -16
  280. package/src/wirings/persona/persona-environments.test.ts +14 -3
  281. package/src/wirings/persona/persona.test.ts +13 -3
  282. package/src/wirings/persona/validate-personas.ts +5 -1
  283. package/src/wirings/queue/queue-runner.ts +1 -1
  284. package/src/wirings/rpc/addon-auth-tags.test.ts +1 -5
  285. package/src/wirings/rpc/rpc-runner.ts +58 -136
  286. package/src/wirings/rpc/rpc-types.ts +7 -0
  287. package/src/wirings/rpc/wire-addon.ts +3 -1
  288. package/src/wirings/secret/validate-secret-definitions.test.ts +22 -0
  289. package/src/wirings/secret/validate-secret-definitions.ts +2 -2
  290. package/src/wirings/trigger/pikku-trigger-service.ts +0 -5
  291. package/src/wirings/trigger/trigger-runner.ts +7 -5
  292. package/src/wirings/virtual-user/run-virtual-user.test.ts +18 -9
  293. package/src/wirings/virtual-user/run-virtual-user.ts +28 -15
  294. package/src/wirings/virtual-user/virtual-user-agents.test.ts +4 -1
  295. package/src/wirings/virtual-user/virtual-user-derive.ts +4 -25
  296. package/src/wirings/virtual-user/virtual-user-dispositions.test.ts +7 -2
  297. package/src/wirings/virtual-user/virtual-user-dispositions.ts +1 -4
  298. package/src/wirings/virtual-user/virtual-user-intents.test.ts +13 -3
  299. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +35 -2
  300. package/src/wirings/workflow/feature.ts +7 -4
  301. package/src/wirings/workflow/graph/graph-node.ts +1 -1
  302. package/src/wirings/workflow/graph/graph-runner.test.ts +4 -2
  303. package/src/wirings/workflow/graph/graph-runner.ts +13 -16
  304. package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -5
  305. package/src/wirings/workflow/index.ts +12 -4
  306. package/src/wirings/workflow/pikku-scenario-service.ts +54 -25
  307. package/src/wirings/workflow/pikku-workflow-service.test.ts +2 -2
  308. package/src/wirings/workflow/pikku-workflow-service.ts +190 -743
  309. package/src/wirings/workflow/scenario-hooks.test.ts +51 -0
  310. package/src/wirings/workflow/workflow-approval.ts +185 -0
  311. package/src/wirings/workflow/workflow-child-run-session.test.ts +89 -0
  312. package/src/wirings/workflow/workflow-constants.ts +47 -0
  313. package/src/wirings/workflow/workflow-dispatch-durability.test.ts +1 -1
  314. package/src/wirings/workflow/workflow-errors.ts +128 -0
  315. package/src/wirings/workflow/workflow-inline-authority.test.ts +12 -6
  316. package/src/wirings/workflow/workflow-meta-resolver.ts +45 -0
  317. package/src/wirings/workflow/workflow-missing-meta.test.ts +92 -0
  318. package/src/wirings/workflow/workflow-queue-routing.ts +85 -0
  319. package/src/wirings/workflow/workflow-queue-wiring.ts +149 -0
  320. package/src/wirings/workflow/workflow-recovery.ts +162 -0
  321. package/src/wirings/workflow/workflow-retry-policy.test.ts +1 -1
  322. package/src/wirings/workflow/workflow-run-authority.test.ts +215 -0
  323. package/src/wirings/workflow/workflow-run-engine.types.ts +91 -0
  324. package/src/wirings/workflow/workflow-run-ownership.ts +36 -0
  325. package/src/wirings/workflow/workflow-suspend.ts +61 -0
  326. package/src/wirings/workflow/workflow.types.ts +7 -0
  327. package/src/wirings-stay-decoupled.test.ts +123 -0
  328. package/tsconfig.json +1 -1
  329. package/tsconfig.tsbuildinfo +1 -1
  330. package/src/internal.ts +0 -10
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Run every `modifyInput` hook in order, threading each result into the next.
3
+ *
4
+ * Shared by the four places a turn starts — first turn and resume, on both the
5
+ * streaming and non-streaming paths. `sharedNotes` is one bag per run that the
6
+ * caller keeps, because hooks use it to pass things forward (`voiceInput`
7
+ * leaves the transcript there for `voiceOutput`).
8
+ */
9
+ export const applyInputMiddleware = async (aiMiddlewares, singletonServices, input, sharedNotes) => {
10
+ let { messages, instructions } = input;
11
+ for (const mw of aiMiddlewares) {
12
+ if (!mw.modifyInput)
13
+ continue;
14
+ const result = await mw.modifyInput(singletonServices, {
15
+ messages,
16
+ instructions,
17
+ shared: sharedNotes,
18
+ });
19
+ messages = result.messages;
20
+ instructions = result.instructions;
21
+ }
22
+ return { messages, instructions };
23
+ };
24
+ /**
25
+ * Notify every `afterStep` hook. The payload is the step verbatim plus its
26
+ * ordinal — a hook that wants the run's totals accumulates them itself.
27
+ */
28
+ export const notifyAfterStep = async (aiMiddlewares, singletonServices, stepNumber, stepResult) => {
29
+ for (const mw of aiMiddlewares) {
30
+ if (!mw.afterStep)
31
+ continue;
32
+ await mw.afterStep(singletonServices, {
33
+ stepNumber,
34
+ text: stepResult.text,
35
+ toolCalls: stepResult.toolCalls,
36
+ toolResults: stepResult.toolResults,
37
+ usage: stepResult.usage,
38
+ finishReason: stepResult.finishReason,
39
+ });
40
+ }
41
+ };
42
+ /**
43
+ * The step shape kept on the run: each tool call paired with its result.
44
+ *
45
+ * A result is stringified unless it already is a string, because this is what
46
+ * gets persisted and read back as history — an object there is unreadable.
47
+ */
48
+ export const toAccumulatedStep = (stepResult) => ({
49
+ usage: stepResult.usage,
50
+ toolCalls: stepResult.toolCalls.map((tc) => {
51
+ const tr = stepResult.toolResults.find((r) => r.toolCallId === tc.toolCallId);
52
+ return {
53
+ name: tc.toolName,
54
+ args: tc.args,
55
+ result: typeof tr?.result === 'string'
56
+ ? tr.result
57
+ : JSON.stringify(tr?.result ?? ''),
58
+ };
59
+ }),
60
+ });
61
+ /**
62
+ * Fill in each approval's human-readable reason from the tool's own
63
+ * `approvalDescriptionFn`, where it did not supply one.
64
+ *
65
+ * A description that throws is swallowed: the approval still has to be raised,
66
+ * and a gate that disappears because its label failed to render is the worst
67
+ * available outcome.
68
+ */
69
+ export const describeApprovals = async (approvals, tools) => {
70
+ for (const approval of approvals) {
71
+ if (approval.reason)
72
+ continue;
73
+ const toolDef = tools.find((t) => t.name === approval.toolName);
74
+ if (!toolDef?.approvalDescriptionFn)
75
+ continue;
76
+ try {
77
+ approval.reason = await toolDef.approvalDescriptionFn(approval.args);
78
+ }
79
+ catch { }
80
+ }
81
+ };
@@ -400,7 +400,7 @@ export type AIStreamEvent = {
400
400
  toolName: string;
401
401
  args: unknown;
402
402
  reason?: string;
403
- runId?: string;
403
+ runId: string;
404
404
  agent?: string;
405
405
  session?: string;
406
406
  } | {
@@ -135,12 +135,7 @@ export const voiceInput = (config) => pikkuAIMiddleware({
135
135
  // to send, and a message with no content is not a question.
136
136
  if (updatedContent.length === 0)
137
137
  throw new NoSpeechDetectedError();
138
- // Only when something was actually heard. A turn can carry audio that all
139
- // reads as non-speech and still have content — an image with a silent
140
- // caption clip — which leaves nothing above to throw. Recording `''` here
141
- // would send a transcript event saying the user said nothing, and a client
142
- // that tells "not transcribed yet" from "transcribed" by the key being
143
- // absent would render the turn as an empty bubble rather than a pending one.
138
+ // knowledge: decisions/internals/an-empty-transcript-is-not-recorded.md
144
139
  if (heard.length > 0) {
145
140
  shared[SPOKEN_TRANSCRIPT] = heard.join(' ');
146
141
  }
@@ -105,11 +105,7 @@ export const voiceOutput = (config) => pikkuAIMiddleware({
105
105
  const { aiAgentRunner, logger } = services;
106
106
  if (!aiAgentRunner?.generateSpeech)
107
107
  return event;
108
- // Only an explicit `false` silences the reply. `voiceInput` sets this on
109
- // every turn it handles, so `false` means a real user really typed; the
110
- // key being absent means nothing reported either way — no voice input is
111
- // wired — and that caller's replies are spoken exactly as they were before
112
- // this option existed.
108
+ // knowledge: decisions/internals/voice-output-speaks-unless-voice-input-explicitly-says-otherwise.md
113
109
  if (!config?.always && shared[SPOKEN_TURN] === false)
114
110
  return event;
115
111
  /**
@@ -124,13 +120,7 @@ export const voiceOutput = (config) => pikkuAIMiddleware({
124
120
  if (!config?.model) {
125
121
  throw new Error('voiceOutput requires a speech model (e.g. openai/tts-1)');
126
122
  }
127
- // Checked per sentence but announced once per reply: a bilingual answer
128
- // should still speak the half it can, and repeating the notice for
129
- // every sentence of a long one would bury the reply itself.
130
- //
131
- // Per sentence is also what makes the voice right. A reply that answers
132
- // in English and then quotes a Chinese title is two sentences in two
133
- // scripts, and each is synthesized in the voice its own script needs.
123
+ // knowledge: decisions/internals/speech-synthesis-picks-a-voice-per-sentence-and-warns-once.md
134
124
  let voice = config.voice;
135
125
  if (config.speakableScripts) {
136
126
  const unspeakable = unspeakableScripts(text, config.speakableScripts);
@@ -12,6 +12,7 @@ export const runChannelLifecycleWithMiddleware = async ({ channelConfig, meta, l
12
12
  });
13
13
  const allChannelMiddleware = combineChannelMiddleware('channel', `${channelConfig.name}:${lifecycleType}:cm`, {
14
14
  wireInheritedChannelMiddleware: channelMiddlewareMeta,
15
+ // knowledge: questions/channel-middleware-accepts-bare-factories-that-nothing-resolves.md
15
16
  wireChannelMiddleware: channelConfig.channelMiddleware,
16
17
  });
17
18
  let wire = {
@@ -46,7 +46,7 @@ export const processMessageHandlers = (services, channelConfig, channelHandler,
46
46
  ? `route '${routingProperty}:${routerValue}'`
47
47
  : 'the default message route';
48
48
  logger.error(`Channel ${channelConfig.name} with id ${channelHandler.getChannel().channelId} requires a session for ${routeMessage}. No session is attached to this websocket connection. Ensure auth middleware establishes a session during websocket upgrade, and configure sessionStore when the runtime needs persisted sessions.`);
49
- // TODO: Send error message back breaks typescript, but should be implemented somehow
49
+ // knowledge: questions/unauthorized-channel-replies-escape-the-declared-out-type.md
50
50
  channelHandler.getChannel().send(`Unauthorized for ${routeMessage}`);
51
51
  return;
52
52
  }
@@ -55,10 +55,7 @@ export const processMessageHandlers = (services, channelConfig, channelHandler,
55
55
  const pikkuFuncId = routeMeta.pikkuFuncId;
56
56
  // Get wire middleware: channel-level middleware + message-specific middleware
57
57
  const channelWireMiddleware = channelConfig.middleware || [];
58
- // Check if onMessage is a wrapper object vs direct function config:
59
- // - Direct config: onMessage.func is a plain Function
60
- // - Wrapper: onMessage.func is a CorePikkuFunctionConfig (has onMessage.func.func)
61
- // - Simple wrapper: onMessage has both func (plain Function) and middleware properties
58
+ // knowledge: decisions/internals/channel-message-handlers-accept-three-config-shapes.md
62
59
  const isWrapper = onMessage &&
63
60
  typeof onMessage === 'object' &&
64
61
  'func' in onMessage &&
@@ -83,6 +80,7 @@ export const processMessageHandlers = (services, channelConfig, channelHandler,
83
80
  inheritedMiddleware,
84
81
  wireMiddleware,
85
82
  inheritedChannelMiddleware: channelMeta?.channelMiddleware,
83
+ // knowledge: questions/channel-middleware-accepts-bare-factories-that-nothing-resolves.md
86
84
  wireChannelMiddleware: wireChannelMiddleware,
87
85
  coerceDataFromSchema: true,
88
86
  tags: channelConfig.tags,
@@ -1,12 +1,6 @@
1
1
  import type { DeploymentService } from '../../services/deployment-service.js';
2
2
  import { ChannelRPCRegistry } from './channel-rpc-registry.js';
3
3
  import { type ChannelRPCValidator } from './channel-rpc.types.js';
4
- /**
5
- * `remote` for channels that only ever flow one way — a server-sent stream, an
6
- * agent's output, a local CLI. Nothing is listening for a request on them, so
7
- * the call is refused rather than waiting out a timeout.
8
- */
9
- export declare const unsupportedChannelRemote: (funcName: string) => Promise<never>;
10
4
  /**
11
5
  * A `DeploymentService` whose transport is an open channel rather than an
12
6
  * address, so a server-side function can call back into a peer that has no
@@ -1,13 +1,5 @@
1
1
  import { ChannelRPCRegistry } from './channel-rpc-registry.js';
2
2
  import { CHANNEL_RPC_REQUEST, CHANNEL_RPC_RESPONSE, ChannelRPCError, isChannelRPCPending, isChannelRPCResponse, } from './channel-rpc.types.js';
3
- /**
4
- * `remote` for channels that only ever flow one way — a server-sent stream, an
5
- * agent's output, a local CLI. Nothing is listening for a request on them, so
6
- * the call is refused rather than waiting out a timeout.
7
- */
8
- export const unsupportedChannelRemote = async (funcName) => {
9
- throw new ChannelRPCError(`Cannot call "${funcName}" remotely: this channel has no peer that answers`, 'unsupported');
10
- };
11
3
  /**
12
4
  * A `DeploymentService` whose transport is an open channel rather than an
13
5
  * address, so a server-side function can call back into a peer that has no
@@ -88,3 +88,9 @@ export type ApprovalRequester = (request: {
88
88
  }) => Promise<boolean> | boolean;
89
89
  /** Checks one end of a call — arguments going out, or the answer coming back. */
90
90
  export type ChannelRPCValidator = (funcName: string, value: unknown) => Promise<void> | void;
91
+ /**
92
+ * `remote` for wires with no peer that answers — a server-sent stream, an
93
+ * agent's output, a local CLI. Nothing is listening for a request on them, so
94
+ * the call is refused rather than waiting out a timeout.
95
+ */
96
+ export declare const unsupportedChannelRemote: (funcName: string) => Promise<never>;
@@ -48,3 +48,11 @@ export const isCapabilityDef = (capability) => typeof capability === 'object' &&
48
48
  export const resolveCapability = (capability) => isCapabilityDef(capability)
49
49
  ? capability
50
50
  : { execute: capability, needsApproval: true };
51
+ /**
52
+ * `remote` for wires with no peer that answers — a server-sent stream, an
53
+ * agent's output, a local CLI. Nothing is listening for a request on them, so
54
+ * the call is refused rather than waiting out a timeout.
55
+ */
56
+ export const unsupportedChannelRemote = async (funcName) => {
57
+ throw new ChannelRPCError(`Cannot call "${funcName}" remotely: this channel has no peer that answers`, 'unsupported');
58
+ };
@@ -1,8 +1,6 @@
1
- import type { CorePikkuPermission } from '../../function/functions.types.js';
2
1
  import type { SessionService } from '../../services/user-session-service.js';
3
- import type { CorePikkuMiddleware } from '../../types/core.types.js';
4
2
  import type { ChannelMeta, CoreChannel, RunChannelOptions, RunChannelParams } from './channel.types.js';
5
- export declare const wireChannel: <In, Channel extends string, PikkuPermission extends CorePikkuPermission<In>, PikkuMiddleware extends CorePikkuMiddleware, ChannelFunction>(channel: CoreChannel<In, Channel, PikkuPermission, PikkuMiddleware, ChannelFunction>) => void;
3
+ export declare const wireChannel: <In, Channel extends string, ChannelConnect, ChannelDisconnect, ChannelFunctionMessage>(channel: CoreChannel<In, Channel, ChannelConnect, ChannelDisconnect, ChannelFunctionMessage>) => void;
6
4
  export declare const openChannel: ({ route, coerceDataFromSchema, request, }: Pick<CoreChannel<unknown, string>, "route"> & RunChannelParams<unknown> & {
7
5
  userSession: SessionService<any>;
8
6
  } & RunChannelOptions) => Promise<{
@@ -3,6 +3,18 @@ import { addFunction } from '../../function/function-runner.js';
3
3
  import { pikkuState, getSingletonServices } from '../../pikku-state.js';
4
4
  import { coerceTopLevelDataFromSchema, validateSchema } from '../../schema.js';
5
5
  import { httpRouter } from '../http/routers/http-router.js';
6
+ /**
7
+ * The config to register for a channel handler: the handler itself when it is a
8
+ * direct function config, or its inner `func` when it is a wrapper.
9
+ *
10
+ * knowledge: decisions/internals/channel-message-handlers-accept-three-config-shapes.md
11
+ */
12
+ const registeredHandler = (handler) => {
13
+ const candidate = handler;
14
+ return typeof candidate.func === 'function'
15
+ ? handler
16
+ : candidate.func;
17
+ };
6
18
  export const wireChannel = (channel) => {
7
19
  const channelsMeta = pikkuState(null, 'channel', 'meta');
8
20
  const channelMeta = channelsMeta[channel.name];
@@ -11,15 +23,13 @@ export const wireChannel = (channel) => {
11
23
  return;
12
24
  }
13
25
  if (channel.onConnect && channelMeta.connect) {
14
- addFunction(channelMeta.connect.pikkuFuncId, channel.onConnect);
26
+ addFunction(channelMeta.connect.pikkuFuncId, registeredHandler(channel.onConnect));
15
27
  }
16
28
  if (channel.onDisconnect && channelMeta.disconnect) {
17
- addFunction(channelMeta.disconnect.pikkuFuncId, channel.onDisconnect);
29
+ addFunction(channelMeta.disconnect.pikkuFuncId, registeredHandler(channel.onDisconnect));
18
30
  }
19
31
  if (channel.onMessage && channelMeta.message?.pikkuFuncId) {
20
- addFunction(channelMeta.message.pikkuFuncId, channel.onMessage.func instanceof Function
21
- ? channel.onMessage
22
- : channel.onMessage.func);
32
+ addFunction(channelMeta.message.pikkuFuncId, registeredHandler(channel.onMessage));
23
33
  }
24
34
  if (channel.onMessageWiring && channelMeta.messageWirings) {
25
35
  Object.entries(channel.onMessageWiring).forEach(([channelKey, wirings]) => {
@@ -30,9 +40,7 @@ export const wireChannel = (channel) => {
30
40
  const wiringMeta = channelWirings[wiringKey];
31
41
  if (!wiringMeta)
32
42
  return;
33
- addFunction(wiringMeta.pikkuFuncId, handler.func instanceof Function
34
- ? handler
35
- : handler.func);
43
+ addFunction(wiringMeta.pikkuFuncId, registeredHandler(handler));
36
44
  });
37
45
  });
38
46
  }
@@ -37,6 +37,8 @@ export interface ChannelMeta {
37
37
  message: ChannelMessageMeta | null;
38
38
  messageWirings: Record<string, Record<string, ChannelMessageMeta>>;
39
39
  binary?: boolean | null;
40
+ /** Set when the channel was wired by a gateway rather than declared directly. */
41
+ gateway?: boolean;
40
42
  summary?: string;
41
43
  description?: string;
42
44
  errors?: string[];
@@ -22,6 +22,7 @@ export class PikkuAbstractChannelHandler {
22
22
  setState: (s) => {
23
23
  channelState = s;
24
24
  },
25
+ // knowledge: decisions/internals/channel-state-accessors-are-unsound-generics-that-every-implementation-asserts.md
25
26
  getState: () => channelState,
26
27
  clearState: () => {
27
28
  channelState = undefined;
@@ -55,6 +55,7 @@ export const runChannelConnect = async ({ channelId, channelObject, request, res
55
55
  channelName: channelConfig.name,
56
56
  });
57
57
  channel.setState = (state) => channelStore.setState(channelId, state);
58
+ // knowledge: decisions/internals/channel-state-accessors-are-unsound-generics-that-every-implementation-asserts.md
58
59
  channel.getState = () => channelStore.getState(channelId);
59
60
  channel.clearState = () => channelStore.clearState(channelId);
60
61
  const wire = {
@@ -116,6 +117,7 @@ export const runChannelDisconnect = async ({ channelId, channelStore, channelHan
116
117
  channelName,
117
118
  });
118
119
  channel.setState = (state) => channelStore.setState(channelId, state);
120
+ // knowledge: decisions/internals/channel-state-accessors-are-unsound-generics-that-every-implementation-asserts.md
119
121
  channel.getState = () => channelStore.getState(channelId);
120
122
  channel.clearState = () => channelStore.clearState(channelId);
121
123
  const userSession = new PikkuSessionService(singletonServices.sessionStore);
@@ -171,6 +173,7 @@ export const runChannelMessage = async ({ channelId, channelStore, channelHandle
171
173
  channelName,
172
174
  });
173
175
  channel.setState = (state) => channelStore.setState(channelId, state);
176
+ // knowledge: decisions/internals/channel-state-accessors-are-unsound-generics-that-every-implementation-asserts.md
174
177
  channel.getState = () => channelStore.getState(channelId);
175
178
  channel.clearState = () => channelStore.clearState(channelId);
176
179
  const userSession = new PikkuSessionService(singletonServices.sessionStore);
@@ -50,6 +50,8 @@ export async function executeCLIViaChannel({ programName, pikkuWS, args = proces
50
50
  resolve(undefined);
51
51
  return;
52
52
  }
53
+ // A CLI channel response is rendered off-process: there are no services
54
+ // to hand the renderer, and every CLI renderer ignores the argument.
53
55
  renderer(null, response, undefined);
54
56
  };
55
57
  commandRoute.subscribe(commandId, responseHandler);
@@ -2,7 +2,7 @@ import { NotFoundError } from '../../errors/errors.js';
2
2
  import { isExpectedError } from '../../errors/error-handler.js';
3
3
  import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
4
4
  import { pikkuState } from '../../pikku-state.js';
5
- import { unsupportedChannelRemote } from '../channel/channel-rpc.js';
5
+ import { unsupportedChannelRemote } from '../channel/channel-rpc.types.js';
6
6
  import { PikkuSessionService, createMiddlewareSessionWireProps, } from '../../services/user-session-service.js';
7
7
  import { LocalVariablesService } from '../../services/local-variables.js';
8
8
  import { generateCommandHelp, parseCLIArguments } from './command-parser.js';
@@ -186,6 +186,7 @@ export async function runCLICommand({ program, commandPath, data, singletonServi
186
186
  setState: (s) => {
187
187
  cliState = s;
188
188
  },
189
+ // knowledge: decisions/internals/channel-state-accessors-are-unsound-generics-that-every-implementation-asserts.md
189
190
  getState: () => cliState,
190
191
  clearState: () => {
191
192
  cliState = undefined;
@@ -230,7 +231,8 @@ export async function runCLICommand({ program, commandPath, data, singletonServi
230
231
  // caller, and emitting it here too would deliver it twice.
231
232
  if (result !== undefined && !onOutput) {
232
233
  const commandRenderer = programData?.renderers[commandId];
233
- const jsonMode = data.json === true || data.output === 'json';
234
+ const jsonMode = data.json === true ||
235
+ data.output === 'json';
234
236
  const finalRenderer = jsonMode && commandRenderer !== undefined
235
237
  ? defaultJSONRenderer
236
238
  : (commandRenderer ?? programData?.defaultRenderer);
@@ -135,10 +135,6 @@ type AllParamsValid<Params extends readonly any[], Input> = Params extends reado
135
135
  * Validate that all parameter names are valid keys of the function input
136
136
  */
137
137
  export type ValidateParameters<Params extends string, Input> = AllParamsValid<ExtractParameterNames<Params>, Input> extends true ? Params : never;
138
- /**
139
- * Extract output type from a Pikku function config type
140
- */
141
- export type ExtractFunctionOutput<Func> = Func extends CorePikkuFunctionConfig<infer FuncType, any, any> ? FuncType extends CorePikkuFunction<any, infer Output, any, any, any> | CorePikkuFunctionSessionless<any, infer Output, any, any, any> ? Output : never : never;
142
138
  /**
143
139
  * CLI command configuration that infers options from function input type.
144
140
  * This is a helper type for creating type-safe CLI commands.
@@ -184,10 +180,6 @@ export interface CoreCLICommand<In, Out, PikkuFunctionConfig extends CorePikkuFu
184
180
  * Shorthand command definition (just a function)
185
181
  */
186
182
  export type CLICommandShorthand<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any, any> | CorePikkuFunctionSessionless<In, Out, any, any, any>>> = PikkuFunctionConfig;
187
- /**
188
- * Command definition (either full or shorthand)
189
- */
190
- export type CLICommandDefinition<In, Out, PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunction<In, Out, any, any, any> | CorePikkuFunctionSessionless<In, Out, any, any, any>>, PikkuPermission extends CorePikkuPermission<any, any, any>, PikkuMiddleware extends CorePikkuMiddleware, Options = any, Subcommands extends Record<string, CoreCLICommandConfig<any, any, any>> = Record<string, CoreCLICommandConfig<any, any, any>>> = CoreCLICommand<In, Out, PikkuFunctionConfig, PikkuPermission, PikkuMiddleware, Options, Subcommands> | CLICommandShorthand<In, Out, PikkuFunctionConfig>;
191
183
  /**
192
184
  * CLI wiring configuration
193
185
  */
@@ -49,6 +49,14 @@ function warnUnknownOption(typed, availableOptions, result) {
49
49
  result.warnings.push(`Unknown option: --${typed} (ignored)` +
50
50
  (suggestion ? ` Did you mean --${suggestion}?` : ''));
51
51
  }
52
+ /**
53
+ * A real short-flag cluster is a handful of characters (`-abc`). Anything past
54
+ * this is treated as a single malformed token rather than scanned per
55
+ * character — the parser runs over untrusted CLI-channel frames, and a
56
+ * multi-megabyte `-aaaa…` would otherwise be O(length) work that also pushed
57
+ * one error per character.
58
+ */
59
+ const MAX_SHORT_FLAG_CLUSTER = 64;
52
60
  export function parseCLIArguments(args, programName, allMeta) {
53
61
  const result = {
54
62
  program: programName,
@@ -176,6 +184,11 @@ export function parseCLIArguments(args, programName, allMeta) {
176
184
  }
177
185
  }
178
186
  else if (arg.startsWith('-') && arg.length > 1) {
187
+ if (arg.length > MAX_SHORT_FLAG_CLUSTER) {
188
+ result.errors.push(`Unknown option: ${arg.slice(0, MAX_SHORT_FLAG_CLUSTER)}… (too long)`);
189
+ currentIndex++;
190
+ continue;
191
+ }
179
192
  for (let i = 1; i < arg.length; i++) {
180
193
  const shortFlag = arg[i];
181
194
  const longOption = findLongOption(shortFlag, availableOptions);
@@ -97,6 +97,9 @@ const wireWebhookGateway = (config) => {
97
97
  route,
98
98
  func: postHandler,
99
99
  auth: false,
100
+ // A gateway handler takes (services, data, wire) rather than a pikku
101
+ // function's shape, so it never matches CorePikkuFunctionConfig. It is only
102
+ // ever invoked through runPikkuFunc, which is what makes that safe.
100
103
  });
101
104
  // knowledge: decisions/internals/gateway-adapters-resolve-lazily-and-are-promise-cached.md
102
105
  if (typeof adapter === 'function' || adapter.verifyWebhook) {
@@ -151,7 +154,7 @@ const createWebhookPostHandler = (config) => {
151
154
  data: () => parsed,
152
155
  auth: config.auth,
153
156
  inheritedMiddleware,
154
- wire: wire,
157
+ wire,
155
158
  });
156
159
  };
157
160
  const gatewayMiddleware = userMiddleware;
@@ -211,8 +214,11 @@ const wireWebsocketGateway = (config) => {
211
214
  name,
212
215
  route,
213
216
  gateway: true,
217
+ input: null,
214
218
  connect: { pikkuFuncId: connectFuncId },
219
+ disconnect: null,
215
220
  message: { pikkuFuncId: messageFuncId },
221
+ messageWirings: {},
216
222
  };
217
223
  const userMiddleware = config.middleware;
218
224
  const handlerFuncId = registerGatewayHandler(config);
@@ -254,7 +260,7 @@ const wireWebsocketGateway = (config) => {
254
260
  data: () => parsed,
255
261
  auth: config.auth,
256
262
  inheritedMiddleware,
257
- wire: wire,
263
+ wire,
258
264
  });
259
265
  };
260
266
  const gatewayMiddleware = userMiddleware;
@@ -307,6 +313,7 @@ export const createListenerMessageHandler = (name, config, singletonServices) =>
307
313
  wire,
308
314
  });
309
315
  };
316
+ // knowledge: decisions/internals/gateway-listener-middleware-runs-without-an-rpc-on-the-wire.md
310
317
  const result = userMiddleware?.length
311
318
  ? await runMiddleware(singletonServices, wire, userMiddleware, invoke)
312
319
  : await invoke();
@@ -54,6 +54,8 @@ function registerRoute(route, groupConfig) {
54
54
  timeout: route.timeout,
55
55
  headers: route.headers,
56
56
  sse: route.sse,
57
+ // `CoreHTTPFunctionWiring` is discriminated by `method`, and a group builds
58
+ // its routes from a method chosen at runtime — no arm can be narrowed to.
57
59
  });
58
60
  }
59
61
  function isRouteConfig(value) {
@@ -3,16 +3,6 @@ import type { CorePikkuFunction, CorePikkuFunctionSessionless, CorePikkuPermissi
3
3
  import type { CorePikkuMiddleware, CorePikkuMiddlewareGroup } from '../../types/core.types.js';
4
4
  import { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
5
5
  export declare const addHTTPMiddleware: <PikkuMiddleware extends CorePikkuMiddleware>(pattern: string, middleware: CorePikkuMiddlewareGroup, packageName?: string | null) => CorePikkuMiddlewareGroup;
6
- /**
7
- * @deprecated HTTP-route-level permissions were removed in #972 — permissions
8
- * are now function-scoped only (declare them on the function via
9
- * `pikkuFunc({ permissions })`). This throwing stub exists solely so the pinned
10
- * bootstrap CLI (which still generates an `addHTTPPermission` wrapper) can
11
- * resolve the import at build time; it is never called. Delete once
12
- * `PIKKU_CLI_VERSION` in the CLI build is bumped past the release that removes
13
- * HTTP-route permissions.
14
- */
15
- export declare const addHTTPPermission: (_pattern: string, _permissions: Record<string, CorePikkuPermission | CorePikkuPermission[]> | CorePikkuPermission[]) => never;
16
6
  export declare const wireHTTP: <In, Out, Route extends string, PikkuFunction extends CorePikkuFunction<In, Out> = CorePikkuFunction<In, Out>, PikkuFunctionSessionless extends CorePikkuFunctionSessionless<In, Out> = CorePikkuFunctionSessionless<In, Out>, PikkuPermissionGroup extends CorePikkuPermission<In> = CorePikkuPermission<In>, PikkuMiddleware extends CorePikkuMiddleware = CorePikkuMiddleware>(httpWiring: CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermissionGroup, PikkuMiddleware>) => void;
17
7
  export declare const createHTTPWire: (request: PikkuHTTPRequest | undefined, response: PikkuHTTPResponse | undefined) => PikkuHTTP | undefined;
18
8
  export declare const fetch: <In, Out>(request: Request, params?: RunHTTPWiringOptions) => Promise<Response>;
@@ -8,7 +8,9 @@ import { isProduction } from '../../env.js';
8
8
  import { pikkuState } from '../../pikku-state.js';
9
9
  import { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
10
10
  import { PikkuFetchHTTPRequest } from './pikku-fetch-http-request.js';
11
- import { unsupportedChannelRemote } from '../channel/channel-rpc.js';
11
+ // The leaf module, not the channel-rpc barrel: http needs one refusal
12
+ // function, and the barrel drags in 4,932 lines of channel RPC runtime.
13
+ import { unsupportedChannelRemote } from '../channel/channel-rpc.types.js';
12
14
  import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
13
15
  import { applyWebResponse } from './web-request.js';
14
16
  import { httpRouter } from './routers/http-router.js';
@@ -32,18 +34,6 @@ export const addHTTPMiddleware = (pattern, middleware, packageName = null) => {
32
34
  : middleware;
33
35
  return middleware;
34
36
  };
35
- /**
36
- * @deprecated HTTP-route-level permissions were removed in #972 — permissions
37
- * are now function-scoped only (declare them on the function via
38
- * `pikkuFunc({ permissions })`). This throwing stub exists solely so the pinned
39
- * bootstrap CLI (which still generates an `addHTTPPermission` wrapper) can
40
- * resolve the import at build time; it is never called. Delete once
41
- * `PIKKU_CLI_VERSION` in the CLI build is bumped past the release that removes
42
- * HTTP-route permissions.
43
- */
44
- export const addHTTPPermission = (_pattern, _permissions) => {
45
- throw new Error('addHTTPPermission was removed in #972 — HTTP-route-level permissions no longer exist. Declare permissions on the function definition instead: pikkuFunc({ permissions }).');
46
- };
47
37
  export const wireHTTP = (httpWiring) => {
48
38
  const httpMeta = pikkuState(null, 'http', 'meta');
49
39
  const routeMeta = httpMeta[httpWiring.method][httpWiring.route];
@@ -60,6 +50,7 @@ export const wireHTTP = (httpWiring) => {
60
50
  }
61
51
  pikkuState(null, 'http', 'routes')
62
52
  .get(httpWiring.method)
53
+ // knowledge: decisions/internals/wiring-registries-erase-the-generics-their-wire-functions-capture.md
63
54
  ?.set(httpWiring.route, httpWiring);
64
55
  };
65
56
  const getMatchingRoute = (requestType, requestPath) => {
@@ -144,6 +135,7 @@ const executeRoute = async (services, matchedRoute, http, options) => {
144
135
  setState: (s) => {
145
136
  sseState = s;
146
137
  },
138
+ // knowledge: decisions/internals/channel-state-accessors-are-unsound-generics-that-every-implementation-asserts.md
147
139
  getState: () => sseState,
148
140
  clearState: () => {
149
141
  sseState = undefined;
@@ -272,6 +264,7 @@ export const fetchData = async (request, response, { skipUserSession = false, re
272
264
  if (globalMiddleware) {
273
265
  await runMiddleware(singletonServices, wire, globalMiddleware);
274
266
  }
267
+ // 204 carries no body, and `json` has no no-content overload.
275
268
  response.status(204).json(undefined);
276
269
  return;
277
270
  }
@@ -39,7 +39,6 @@ export interface PikkuHTTP<In = unknown> {
39
39
  request?: PikkuHTTPRequest<In>;
40
40
  response?: PikkuHTTPResponse;
41
41
  }
42
- export type RequestHeaders = Record<string, string | string[] | undefined> | ((headerName: string) => string | string[] | undefined);
43
42
  export type PikkuQuery<T = Record<string, string | undefined>> = Record<string, string | T | null | Array<T | null>>;
44
43
  export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction extends CorePikkuFunction<In, Out, any, any, any> = CorePikkuFunction<In, Out>, PikkuFunctionSessionless extends CorePikkuFunctionSessionless<In, Out, any, any, any> = CorePikkuFunctionSessionless<In, Out>, PikkuPermission extends CorePikkuPermission<In, any, any> = CorePikkuPermission<In, any, any>, PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<any, any>> = (CoreHTTPFunction & {
45
44
  route: R;
@@ -114,15 +113,6 @@ export type HTTPWiringMeta = CommonWireMeta & {
114
113
  groupBasePath?: string;
115
114
  };
116
115
  export type HTTPWiringsMeta = Record<HTTPMethod, Record<string, HTTPWiringMeta>>;
117
- export type HTTPFunctionsMeta = Array<{
118
- name: string;
119
- inputs: string[] | null;
120
- outputs: string[] | null;
121
- }>;
122
- export type HTTPWiringMiddleware = {
123
- route: string;
124
- middleware: CorePikkuMiddleware[];
125
- };
126
116
  export interface PikkuHTTPRequest<In = unknown> {
127
117
  method(): HTTPMethod;
128
118
  path(): string;
@@ -2,7 +2,7 @@ export { PikkuFetchHTTPRequest, DEFAULT_MAX_BODY_SIZE, } from './pikku-fetch-htt
2
2
  export type { PikkuFetchHTTPRequestOptions } from './pikku-fetch-http-request.js';
3
3
  export { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
4
4
  export { logRoutes } from './log-http-routes.js';
5
- export { fetch, fetchData, wireHTTP, addHTTPMiddleware, addHTTPPermission, } from './http-runner.js';
5
+ export { fetch, fetchData, wireHTTP, addHTTPMiddleware } from './http-runner.js';
6
6
  export { wireHTTPRoutes, defineHTTPRoutes } from './http-routes.js';
7
7
  export { toWebRequest, applyWebResponse } from './web-request.js';
8
8
  export type { AssertHTTPWiringParams, CoreHTTPFunctionWiring, HTTPMethod, HTTPRouteBaseConfig, HTTPRouteContract, HTTPRouteMap, HTTPWiringsMeta, PikkuHTTPRequest, PikkuHTTPResponse, PikkuQuery, RunHTTPWiringOptions, } from './http.types.js';
@@ -1,6 +1,6 @@
1
1
  export { PikkuFetchHTTPRequest, DEFAULT_MAX_BODY_SIZE, } from './pikku-fetch-http-request.js';
2
2
  export { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
3
3
  export { logRoutes } from './log-http-routes.js';
4
- export { fetch, fetchData, wireHTTP, addHTTPMiddleware, addHTTPPermission, } from './http-runner.js';
4
+ export { fetch, fetchData, wireHTTP, addHTTPMiddleware } from './http-runner.js';
5
5
  export { wireHTTPRoutes, defineHTTPRoutes } from './http-routes.js';
6
6
  export { toWebRequest, applyWebResponse } from './web-request.js';
@@ -9,18 +9,11 @@ export type RunMCPEndpointParams<Tools extends string = any> = {
9
9
  /** Defaults to enabled outside production. */
10
10
  exposeErrors?: boolean;
11
11
  };
12
- export type JsonRpcError = {
13
- code: number;
14
- message: string;
15
- data?: any;
16
- };
17
12
  export declare const wireMCPResource: <PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>> = CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>>>(mcpResource: CoreMCPResource<PikkuFunctionConfig>) => void;
18
13
  export declare const wireMCPPrompt: <PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>> = CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>>>(mcpPrompt: CoreMCPPrompt<PikkuFunctionConfig>) => void;
19
14
  export declare function runMCPResource(request: JsonRpcRequest, params: RunMCPEndpointParams, uri: string): Promise<JsonRpcResponse>;
20
15
  export declare function runMCPTool(request: JsonRpcRequest, params: RunMCPEndpointParams, name: string): Promise<JsonRpcResponse>;
21
16
  export declare function runMCPPrompt(request: JsonRpcRequest, params: RunMCPEndpointParams, name: string): Promise<JsonRpcResponse>;
22
- export declare const getMCPResources: () => Map<string, CoreMCPResource>;
23
17
  export declare const getMCPResourcesMeta: () => import("./mcp.types.js").MCPResourceMeta;
24
18
  export declare const getMCPToolsMeta: () => import("./mcp.types.js").MCPToolMeta;
25
- export declare const getMCPPrompts: () => Map<string, CoreMCPPrompt>;
26
19
  export declare const getMCPPromptsMeta: () => import("./mcp.types.js").MCPPromptMeta;
@@ -165,18 +165,12 @@ async function runMCPPikkuFunc(request, type, name, mcp, pikkuFuncId, { mcp: mcp
165
165
  }
166
166
  }
167
167
  }
168
- export const getMCPResources = () => {
169
- return pikkuState(null, 'mcp', 'resources');
170
- };
171
168
  export const getMCPResourcesMeta = () => {
172
169
  return pikkuState(null, 'mcp', 'resourcesMeta');
173
170
  };
174
171
  export const getMCPToolsMeta = () => {
175
172
  return pikkuState(null, 'mcp', 'toolsMeta');
176
173
  };
177
- export const getMCPPrompts = () => {
178
- return pikkuState(null, 'mcp', 'prompts');
179
- };
180
174
  export const getMCPPromptsMeta = () => {
181
175
  return pikkuState(null, 'mcp', 'promptsMeta');
182
176
  };