@pikku/core 0.12.78 → 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 (341) hide show
  1. package/CHANGELOG.md +234 -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.d.ts +10 -0
  24. package/dist/services/in-memory-workflow-service.js +25 -0
  25. package/dist/services/local-content-request-handler.d.ts +21 -0
  26. package/dist/services/local-content-request-handler.js +72 -53
  27. package/dist/services/local-content.d.ts +6 -0
  28. package/dist/services/local-content.js +14 -1
  29. package/dist/services/workflow-service.d.ts +4 -2
  30. package/dist/testing/service-tests/agent-run-service-tests.d.ts +10 -0
  31. package/dist/testing/service-tests/agent-run-service-tests.js +72 -0
  32. package/dist/testing/service-tests/ai-storage-service-tests.d.ts +3 -0
  33. package/dist/testing/service-tests/ai-storage-service-tests.js +226 -0
  34. package/dist/testing/service-tests/channel-store-tests.d.ts +3 -0
  35. package/dist/testing/service-tests/channel-store-tests.js +72 -0
  36. package/dist/testing/service-tests/credential-service-tests.d.ts +3 -0
  37. package/dist/testing/service-tests/credential-service-tests.js +109 -0
  38. package/dist/testing/service-tests/deployment-service-tests.d.ts +3 -0
  39. package/dist/testing/service-tests/deployment-service-tests.js +21 -0
  40. package/dist/testing/service-tests/event-hub-store-tests.d.ts +3 -0
  41. package/dist/testing/service-tests/event-hub-store-tests.js +34 -0
  42. package/dist/testing/service-tests/secret-service-tests.d.ts +3 -0
  43. package/dist/testing/service-tests/secret-service-tests.js +80 -0
  44. package/dist/testing/service-tests/session-store-tests.d.ts +3 -0
  45. package/dist/testing/service-tests/session-store-tests.js +43 -0
  46. package/dist/testing/service-tests/workflow-run-service-tests.d.ts +3 -0
  47. package/dist/testing/service-tests/workflow-run-service-tests.js +42 -0
  48. package/dist/testing/service-tests/workflow-service-tests.d.ts +3 -0
  49. package/dist/testing/service-tests/workflow-service-tests.js +150 -0
  50. package/dist/testing/service-tests.d.ts +6 -0
  51. package/dist/testing/service-tests.js +26 -791
  52. package/dist/types/core.types.d.ts +11 -1
  53. package/dist/types/state.types.d.ts +1 -1
  54. package/dist/utils/node-host-resolver.d.ts +12 -0
  55. package/dist/utils/node-host-resolver.js +16 -0
  56. package/dist/utils/safe-fetch.d.ts +18 -0
  57. package/dist/utils/safe-fetch.js +167 -29
  58. package/dist/wirings/actor-flow/run-conversation.js +1 -6
  59. package/dist/wirings/ai-agent/agent-rpc.d.ts +15 -0
  60. package/dist/wirings/ai-agent/agent-rpc.js +53 -0
  61. package/dist/wirings/ai-agent/ai-agent-agui.js +1 -5
  62. package/dist/wirings/ai-agent/ai-agent-memory.js +3 -1
  63. package/dist/wirings/ai-agent/ai-agent-prepare.js +3 -9
  64. package/dist/wirings/ai-agent/ai-agent-runner.js +28 -107
  65. package/dist/wirings/ai-agent/ai-agent-stream.js +20 -61
  66. package/dist/wirings/ai-agent/ai-agent-turn.d.ts +56 -0
  67. package/dist/wirings/ai-agent/ai-agent-turn.js +81 -0
  68. package/dist/wirings/ai-agent/ai-agent.types.d.ts +1 -1
  69. package/dist/wirings/ai-agent/voice-input.js +1 -6
  70. package/dist/wirings/ai-agent/voice-output.js +2 -12
  71. package/dist/wirings/channel/channel-common.js +1 -0
  72. package/dist/wirings/channel/channel-handler.js +3 -5
  73. package/dist/wirings/channel/channel-rpc-service.d.ts +0 -6
  74. package/dist/wirings/channel/channel-rpc-service.js +0 -8
  75. package/dist/wirings/channel/channel-rpc.types.d.ts +6 -0
  76. package/dist/wirings/channel/channel-rpc.types.js +8 -0
  77. package/dist/wirings/channel/channel-runner.d.ts +1 -3
  78. package/dist/wirings/channel/channel-runner.js +16 -8
  79. package/dist/wirings/channel/channel.types.d.ts +2 -0
  80. package/dist/wirings/channel/pikku-abstract-channel-handler.js +1 -0
  81. package/dist/wirings/channel/serverless/serverless-channel-runner.js +3 -0
  82. package/dist/wirings/cli/channel/cli-channel-runner.js +2 -0
  83. package/dist/wirings/cli/cli-runner.js +4 -2
  84. package/dist/wirings/cli/cli.types.d.ts +0 -8
  85. package/dist/wirings/cli/command-parser.js +13 -0
  86. package/dist/wirings/gateway/gateway-runner.js +41 -5
  87. package/dist/wirings/http/http-routes.js +2 -0
  88. package/dist/wirings/http/http-runner.d.ts +0 -10
  89. package/dist/wirings/http/http-runner.js +6 -13
  90. package/dist/wirings/http/http.types.d.ts +0 -10
  91. package/dist/wirings/http/index.d.ts +1 -1
  92. package/dist/wirings/http/index.js +1 -1
  93. package/dist/wirings/mcp/mcp-runner.d.ts +0 -7
  94. package/dist/wirings/mcp/mcp-runner.js +0 -6
  95. package/dist/wirings/rpc/rpc-runner.d.ts +8 -51
  96. package/dist/wirings/rpc/rpc-runner.js +53 -86
  97. package/dist/wirings/rpc/rpc-types.d.ts +3 -0
  98. package/dist/wirings/secret/validate-secret-definitions.js +2 -0
  99. package/dist/wirings/trigger/pikku-trigger-service.d.ts +0 -4
  100. package/dist/wirings/trigger/trigger-runner.js +1 -0
  101. package/dist/wirings/virtual-user/run-virtual-user.js +11 -11
  102. package/dist/wirings/virtual-user/virtual-user-derive.js +4 -25
  103. package/dist/wirings/virtual-user/virtual-user-dispositions.js +1 -4
  104. package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +29 -2
  105. package/dist/wirings/workflow/feature.js +7 -4
  106. package/dist/wirings/workflow/graph/graph-runner.d.ts +1 -2
  107. package/dist/wirings/workflow/graph/graph-runner.js +8 -7
  108. package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +0 -4
  109. package/dist/wirings/workflow/index.d.ts +7 -2
  110. package/dist/wirings/workflow/index.js +5 -1
  111. package/dist/wirings/workflow/pikku-scenario-service.d.ts +17 -3
  112. package/dist/wirings/workflow/pikku-scenario-service.js +38 -10
  113. package/dist/wirings/workflow/pikku-workflow-service.d.ts +44 -111
  114. package/dist/wirings/workflow/pikku-workflow-service.js +86 -404
  115. package/dist/wirings/workflow/workflow-approval.d.ts +39 -0
  116. package/dist/wirings/workflow/workflow-approval.js +114 -0
  117. package/dist/wirings/workflow/workflow-constants.d.ts +26 -0
  118. package/dist/wirings/workflow/workflow-constants.js +35 -0
  119. package/dist/wirings/workflow/workflow-errors.d.ts +58 -0
  120. package/dist/wirings/workflow/workflow-errors.js +112 -0
  121. package/dist/wirings/workflow/workflow-meta-resolver.d.ts +11 -0
  122. package/dist/wirings/workflow/workflow-meta-resolver.js +31 -0
  123. package/dist/wirings/workflow/workflow-queue-routing.d.ts +8 -0
  124. package/dist/wirings/workflow/workflow-queue-routing.js +38 -0
  125. package/dist/wirings/workflow/workflow-queue-wiring.d.ts +20 -0
  126. package/dist/wirings/workflow/workflow-queue-wiring.js +79 -0
  127. package/dist/wirings/workflow/workflow-recovery.d.ts +68 -0
  128. package/dist/wirings/workflow/workflow-recovery.js +101 -0
  129. package/dist/wirings/workflow/workflow-run-engine.types.d.ts +54 -0
  130. package/dist/wirings/workflow/workflow-run-engine.types.js +1 -0
  131. package/dist/wirings/workflow/workflow-run-ownership.d.ts +16 -0
  132. package/dist/wirings/workflow/workflow-run-ownership.js +29 -0
  133. package/dist/wirings/workflow/workflow-suspend.d.ts +12 -0
  134. package/dist/wirings/workflow/workflow-suspend.js +33 -0
  135. package/dist/wirings/workflow/workflow.types.d.ts +7 -0
  136. package/knowledge/decisions/internals/a-non-streaming-agent-run-registers-with-airunstate-too.md +22 -0
  137. package/knowledge/decisions/internals/a-resumed-agent-turn-is-as-interruptible-as-the-first.md +20 -0
  138. package/knowledge/decisions/internals/a-scenario-step-template-is-offered-unfilled.md +21 -0
  139. package/knowledge/decisions/internals/a-virtual-user-decides-whether-to-trust-memory-once-per-turn.md +21 -0
  140. package/knowledge/decisions/internals/a-wall-clock-threshold-is-a-load-test-in-disguise.md +46 -0
  141. package/knowledge/decisions/internals/a-workflow-wire-is-built-from-the-run-not-from-the-rpc-service.md +45 -0
  142. package/knowledge/decisions/internals/agent-context-waits-for-a-tool-result-still-being-written.md +21 -0
  143. package/knowledge/decisions/internals/agent-speech-travels-as-a-custom-agui-event.md +22 -0
  144. package/knowledge/decisions/internals/an-agent-interrupt-is-not-a-failure.md +23 -0
  145. package/knowledge/decisions/internals/an-agent-run-owned-by-another-instance-says-so.md +25 -0
  146. package/knowledge/decisions/internals/an-agent-stream-send-must-return-the-inner-sends-promise.md +22 -0
  147. package/knowledge/decisions/internals/an-empty-text-part-is-omitted-from-an-agent-message.md +20 -0
  148. package/knowledge/decisions/internals/an-empty-transcript-is-not-recorded.md +22 -0
  149. package/knowledge/decisions/internals/an-unref-d-timer-cannot-be-awaited-under-node-test.md +66 -0
  150. package/knowledge/decisions/internals/channel-state-accessors-are-unsound-generics-that-every-implementation-asserts.md +33 -0
  151. package/knowledge/decisions/internals/gateway-listener-middleware-runs-without-an-rpc-on-the-wire.md +43 -0
  152. package/knowledge/decisions/internals/hot-reload-writes-into-the-function-map-captured-at-startup.md +26 -0
  153. package/knowledge/decisions/internals/index.md +38 -26
  154. package/knowledge/decisions/internals/only-exposed-functions-enter-a-virtual-user-catalogue.md +21 -0
  155. package/knowledge/decisions/internals/scenario-given-and-when-are-sugar-but-then-is-not.md +24 -0
  156. package/knowledge/decisions/internals/side-effects-are-an-allowlist-not-a-boolean.md +34 -0
  157. package/knowledge/decisions/internals/speech-synthesis-picks-a-voice-per-sentence-and-warns-once.md +24 -0
  158. package/knowledge/decisions/internals/the-actor-prompt-says-json-because-of-json-object-mode.md +22 -0
  159. package/knowledge/decisions/internals/the-agent-done-event-goes-through-the-middleware-and-is-awaited.md +26 -0
  160. package/knowledge/decisions/internals/the-api-report-pins-members-not-just-names.md +43 -0
  161. package/knowledge/decisions/internals/the-ecosystem-entry-point-carries-the-adapter-surface.md +58 -0
  162. package/knowledge/decisions/internals/the-middleware-resolution-cache-is-deliberately-unbounded.md +40 -0
  163. package/knowledge/decisions/internals/the-per-invocation-rpc-view-is-a-class.md +40 -0
  164. package/knowledge/decisions/internals/the-persona-runtime-is-exported-from-the-persona-entry-point.md +28 -0
  165. package/knowledge/decisions/internals/the-transcript-event-is-sent-ahead-of-the-run.md +25 -0
  166. package/knowledge/decisions/internals/the-virtual-user-catalogue-is-the-only-gate-on-what-may-be-called.md +21 -0
  167. package/knowledge/decisions/internals/the-worker-disposition-is-the-one-that-is-not-testing.md +22 -0
  168. package/knowledge/decisions/internals/thread-history-records-the-transcript-not-the-audio.md +25 -0
  169. package/knowledge/decisions/internals/virtual-user-step-order-comes-from-insertion-order.md +21 -0
  170. package/knowledge/decisions/internals/voice-output-speaks-unless-voice-input-explicitly-says-otherwise.md +24 -0
  171. package/knowledge/decisions/internals/wiring-registries-erase-the-generics-their-wire-functions-capture.md +35 -0
  172. package/knowledge/decisions/security/a-dropped-audit-write-is-always-logged.md +4 -2
  173. package/knowledge/decisions/security/a-graph-run-starts-at-an-entry-node-the-graph-declared.md +33 -0
  174. package/knowledge/decisions/security/a-permission-gets-a-wire-it-cannot-reply-on.md +33 -0
  175. package/knowledge/decisions/security/a-step-runs-the-function-the-workflow-dispatched-it-with.md +37 -0
  176. package/knowledge/decisions/security/a-virtual-user-is-never-offered-a-step-that-would-forge-its-own-oracle.md +28 -0
  177. package/knowledge/decisions/security/a-workflow-run-is-read-and-approved-by-its-owner.md +34 -0
  178. package/knowledge/decisions/security/an-agent-approval-is-claimed-before-the-tool-runs.md +33 -0
  179. package/knowledge/decisions/security/an-upload-is-counted-as-it-arrives-not-buffered-then-measured.md +24 -0
  180. package/knowledge/decisions/security/gateway-handlers-run-through-the-function-runner-gate.md +13 -3
  181. package/knowledge/decisions/security/index.md +7 -0
  182. package/knowledge/questions/channel-middleware-accepts-bare-factories-that-nothing-resolves.md +35 -0
  183. package/knowledge/questions/index.md +2 -1
  184. package/knowledge/questions/unauthorized-channel-replies-escape-the-declared-out-type.md +44 -0
  185. package/package.json +14 -3
  186. package/scripts/generate-api-report.d.mts +1 -0
  187. package/scripts/generate-api-report.mjs +89 -0
  188. package/scripts/generate-api-report.mts +218 -0
  189. package/src/api-report.test.ts +69 -0
  190. package/src/column-form.ts +1 -4
  191. package/src/crypto-utils.test.ts +15 -2
  192. package/src/dev/hot-reload.ts +2 -7
  193. package/src/ecosystem.ts +40 -0
  194. package/src/errors/error-handler.ts +5 -3
  195. package/src/errors/error.test.ts +4 -1
  196. package/src/function/function-runner.test.ts +1 -1
  197. package/src/function/function-runner.ts +28 -39
  198. package/src/function/functions.types.ts +15 -9
  199. package/src/handle-error.ts +1 -1
  200. package/src/index.ts +3 -22
  201. package/src/middleware/auth-cookie.test.ts +50 -0
  202. package/src/middleware/auth-cookie.ts +38 -2
  203. package/src/middleware/cors.ts +2 -1
  204. package/src/middleware/index.ts +1 -1
  205. package/src/middleware/remote-auth.test.ts +43 -0
  206. package/src/middleware/remote-auth.ts +17 -3
  207. package/src/middleware-runner.ts +4 -2
  208. package/src/no-any-casts.test.ts +57 -0
  209. package/src/permissions.test.ts +3 -1
  210. package/src/permissions.ts +22 -24
  211. package/src/pikku-state.ts +17 -6
  212. package/src/public-surface.json +578 -0
  213. package/src/public-surface.json.README +25 -0
  214. package/src/public-surface.test.ts +105 -0
  215. package/src/removed-legacy-exports.test.ts +62 -0
  216. package/src/schema.test.ts +78 -0
  217. package/src/schema.ts +36 -1
  218. package/src/services/ai-run-state-service.ts +7 -1
  219. package/src/services/audit-service.ts +2 -2
  220. package/src/services/in-memory-ai-run-state-service.ts +3 -2
  221. package/src/services/in-memory-workflow-service.ts +25 -0
  222. package/src/services/index.ts +1 -4
  223. package/src/services/local-content-request-handler.test.ts +43 -5
  224. package/src/services/local-content-request-handler.ts +103 -74
  225. package/src/services/local-content.ts +15 -1
  226. package/src/services/local-email-service.ts +5 -1
  227. package/src/services/system-role-guard.test.ts +4 -1
  228. package/src/services/workflow-service.ts +9 -2
  229. package/src/side-effects-are-declared.test.ts +84 -0
  230. package/src/source-files-stay-composable.test.ts +41 -0
  231. package/src/testing/service-tests/agent-run-service-tests.ts +98 -0
  232. package/src/testing/service-tests/ai-storage-service-tests.ts +286 -0
  233. package/src/testing/service-tests/channel-store-tests.ts +98 -0
  234. package/src/testing/service-tests/credential-service-tests.ts +143 -0
  235. package/src/testing/service-tests/deployment-service-tests.ts +33 -0
  236. package/src/testing/service-tests/event-hub-store-tests.ts +48 -0
  237. package/src/testing/service-tests/secret-service-tests.ts +105 -0
  238. package/src/testing/service-tests/session-store-tests.ts +62 -0
  239. package/src/testing/service-tests/workflow-run-service-tests.ts +59 -0
  240. package/src/testing/service-tests/workflow-service-tests.ts +308 -0
  241. package/src/testing/service-tests.ts +31 -1111
  242. package/src/types/core.types.ts +15 -1
  243. package/src/types/state.types.ts +1 -1
  244. package/src/utils/node-host-resolver.ts +20 -0
  245. package/src/utils/safe-fetch.test.ts +143 -1
  246. package/src/utils/safe-fetch.ts +200 -25
  247. package/src/wirings/actor-flow/run-conversation.ts +1 -6
  248. package/src/wirings/ai-agent/agent-rpc.ts +120 -0
  249. package/src/wirings/ai-agent/ai-agent-agui.ts +1 -5
  250. package/src/wirings/ai-agent/ai-agent-interrupt.test.ts +2 -1
  251. package/src/wirings/ai-agent/ai-agent-memory.ts +8 -1
  252. package/src/wirings/ai-agent/ai-agent-prepare.ts +10 -12
  253. package/src/wirings/ai-agent/ai-agent-resume-authorization.test.ts +1 -0
  254. package/src/wirings/ai-agent/ai-agent-runner.test.ts +82 -2
  255. package/src/wirings/ai-agent/ai-agent-runner.ts +49 -120
  256. package/src/wirings/ai-agent/ai-agent-stream.test.ts +2 -0
  257. package/src/wirings/ai-agent/ai-agent-stream.ts +36 -63
  258. package/src/wirings/ai-agent/ai-agent-thread-ownership.test.ts +1 -1
  259. package/src/wirings/ai-agent/ai-agent-turn.ts +121 -0
  260. package/src/wirings/ai-agent/ai-agent.types.ts +1 -1
  261. package/src/wirings/ai-agent/voice-input.ts +1 -6
  262. package/src/wirings/ai-agent/voice-output.ts +2 -12
  263. package/src/wirings/channel/channel-common.ts +5 -2
  264. package/src/wirings/channel/channel-handler-shapes.test.ts +72 -0
  265. package/src/wirings/channel/channel-handler.ts +7 -7
  266. package/src/wirings/channel/channel-rpc-service.ts +0 -14
  267. package/src/wirings/channel/channel-rpc.test.ts +25 -4
  268. package/src/wirings/channel/channel-rpc.types.ts +14 -0
  269. package/src/wirings/channel/channel-runner.ts +33 -20
  270. package/src/wirings/channel/channel.types.ts +2 -0
  271. package/src/wirings/channel/local/local-channel-runner.ts +1 -1
  272. package/src/wirings/channel/pikku-abstract-channel-handler.ts +2 -1
  273. package/src/wirings/channel/serverless/serverless-channel-runner.ts +6 -3
  274. package/src/wirings/cli/channel/cli-channel-runner.ts +3 -1
  275. package/src/wirings/cli/channel/cli-raw-client-runner.ts +4 -1
  276. package/src/wirings/cli/cli-runner.ts +7 -4
  277. package/src/wirings/cli/cli.types.ts +0 -39
  278. package/src/wirings/cli/command-parser.test.ts +19 -0
  279. package/src/wirings/cli/command-parser.ts +17 -1
  280. package/src/wirings/gateway/gateway-authorization.test.ts +131 -0
  281. package/src/wirings/gateway/gateway-channel-meta.test.ts +44 -0
  282. package/src/wirings/gateway/gateway-runner.ts +62 -22
  283. package/src/wirings/http/http-routes.ts +4 -1
  284. package/src/wirings/http/http-runner.ts +11 -26
  285. package/src/wirings/http/http.types.ts +0 -15
  286. package/src/wirings/http/index.ts +1 -7
  287. package/src/wirings/http/pikku-fetch-http-request.ts +2 -2
  288. package/src/wirings/http/web-request.ts +1 -1
  289. package/src/wirings/mcp/mcp-runner.ts +2 -16
  290. package/src/wirings/persona/persona-environments.test.ts +14 -3
  291. package/src/wirings/persona/persona.test.ts +13 -3
  292. package/src/wirings/persona/validate-personas.ts +5 -1
  293. package/src/wirings/queue/queue-runner.ts +1 -1
  294. package/src/wirings/rpc/addon-auth-tags.test.ts +1 -5
  295. package/src/wirings/rpc/rpc-runner.ts +58 -136
  296. package/src/wirings/rpc/rpc-types.ts +7 -0
  297. package/src/wirings/rpc/wire-addon.ts +3 -1
  298. package/src/wirings/secret/validate-secret-definitions.test.ts +69 -0
  299. package/src/wirings/secret/validate-secret-definitions.ts +2 -0
  300. package/src/wirings/trigger/pikku-trigger-service.ts +0 -5
  301. package/src/wirings/trigger/trigger-runner.ts +7 -5
  302. package/src/wirings/virtual-user/run-virtual-user.test.ts +18 -9
  303. package/src/wirings/virtual-user/run-virtual-user.ts +28 -15
  304. package/src/wirings/virtual-user/virtual-user-agents.test.ts +4 -1
  305. package/src/wirings/virtual-user/virtual-user-derive.ts +4 -25
  306. package/src/wirings/virtual-user/virtual-user-dispositions.test.ts +7 -2
  307. package/src/wirings/virtual-user/virtual-user-dispositions.ts +1 -4
  308. package/src/wirings/virtual-user/virtual-user-intents.test.ts +13 -3
  309. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +35 -2
  310. package/src/wirings/workflow/feature.ts +7 -4
  311. package/src/wirings/workflow/graph/graph-node.ts +1 -1
  312. package/src/wirings/workflow/graph/graph-runner.test.ts +4 -2
  313. package/src/wirings/workflow/graph/graph-runner.ts +13 -16
  314. package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -5
  315. package/src/wirings/workflow/index.ts +12 -4
  316. package/src/wirings/workflow/pikku-scenario-service.ts +54 -25
  317. package/src/wirings/workflow/pikku-workflow-service.test.ts +2 -2
  318. package/src/wirings/workflow/pikku-workflow-service.ts +208 -630
  319. package/src/wirings/workflow/scenario-hooks.test.ts +51 -0
  320. package/src/wirings/workflow/workflow-approval.ts +185 -0
  321. package/src/wirings/workflow/workflow-child-run-session.test.ts +89 -0
  322. package/src/wirings/workflow/workflow-constants.ts +47 -0
  323. package/src/wirings/workflow/workflow-dispatch-durability.test.ts +1 -1
  324. package/src/wirings/workflow/workflow-dispatch-relay.test.ts +128 -0
  325. package/src/wirings/workflow/workflow-errors.ts +128 -0
  326. package/src/wirings/workflow/workflow-inline-authority.test.ts +12 -6
  327. package/src/wirings/workflow/workflow-meta-resolver.ts +45 -0
  328. package/src/wirings/workflow/workflow-missing-meta.test.ts +92 -0
  329. package/src/wirings/workflow/workflow-queue-routing.ts +85 -0
  330. package/src/wirings/workflow/workflow-queue-wiring.ts +149 -0
  331. package/src/wirings/workflow/workflow-recovery.ts +162 -0
  332. package/src/wirings/workflow/workflow-retry-policy.test.ts +1 -1
  333. package/src/wirings/workflow/workflow-run-authority.test.ts +215 -0
  334. package/src/wirings/workflow/workflow-run-engine.types.ts +91 -0
  335. package/src/wirings/workflow/workflow-run-ownership.ts +36 -0
  336. package/src/wirings/workflow/workflow-suspend.ts +61 -0
  337. package/src/wirings/workflow/workflow.types.ts +7 -0
  338. package/src/wirings-stay-decoupled.test.ts +123 -0
  339. package/tsconfig.json +1 -1
  340. package/tsconfig.tsbuildinfo +1 -1
  341. package/src/internal.ts +0 -10
@@ -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);
@@ -14,19 +14,42 @@ const bridgeMiddlewareSession = async (wire) => {
14
14
  wire.session = session;
15
15
  }
16
16
  };
17
+ /**
18
+ * Metadata the inspector recorded for the function the gateway was wired with.
19
+ * The bootstrap loads every meta file before any wiring file, so this is
20
+ * already populated by the time a gateway wires itself. A gateway wired by
21
+ * hand rather than through codegen has no entry, and falls back to the
22
+ * sessionless default below.
23
+ */
24
+ const declaredHandlerMeta = (config) => {
25
+ const declaredFuncId = pikkuState(null, 'gateway', 'meta')[config.name]
26
+ ?.pikkuFuncId;
27
+ return declaredFuncId
28
+ ? pikkuState(null, 'function', 'meta')[declaredFuncId]
29
+ : undefined;
30
+ };
17
31
  // knowledge: decisions/security/gateway-handlers-run-through-the-function-runner-gate.md
18
32
  const registerGatewayHandler = (config) => {
19
33
  const funcId = gatewayHandlerFuncId(config.name);
20
34
  const funcMeta = pikkuState(null, 'function', 'meta');
35
+ const declared = declaredHandlerMeta(config);
21
36
  funcMeta[funcId] = {
37
+ ...declared,
22
38
  pikkuFuncId: funcId,
23
- inputSchemaName: null,
24
- outputSchemaName: null,
25
- sessionless: true,
39
+ inputSchemaName: declared?.inputSchemaName ?? null,
40
+ outputSchemaName: declared?.outputSchemaName ?? null,
41
+ sessionless: declared?.sessionless ?? true,
26
42
  };
27
43
  addFunction(funcId, config.func);
28
44
  return funcId;
29
45
  };
46
+ /**
47
+ * Tag middleware the inspector resolved for this gateway. It is keyed by
48
+ * gateway name rather than reachable from `config`, because `tags` is a
49
+ * compile-time input everywhere — nothing at runtime maps a tag to its
50
+ * middleware group.
51
+ */
52
+ const gatewayInheritedMiddleware = (config) => pikkuState(null, 'gateway', 'meta')[config.name]?.middleware;
30
53
  export const resolveGatewayAdapter = (config, services) => {
31
54
  let resolved = resolvedAdapters.get(config);
32
55
  if (!resolved) {
@@ -74,6 +97,9 @@ const wireWebhookGateway = (config) => {
74
97
  route,
75
98
  func: postHandler,
76
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.
77
103
  });
78
104
  // knowledge: decisions/internals/gateway-adapters-resolve-lazily-and-are-promise-cached.md
79
105
  if (typeof adapter === 'function' || adapter.verifyWebhook) {
@@ -100,6 +126,7 @@ const wireWebhookGateway = (config) => {
100
126
  const createWebhookPostHandler = (config) => {
101
127
  const { name, middleware: userMiddleware } = config;
102
128
  const handlerFuncId = registerGatewayHandler(config);
129
+ const inheritedMiddleware = gatewayInheritedMiddleware(config);
103
130
  return async (services, data, wire) => {
104
131
  const adapter = await resolveGatewayAdapter(config, services);
105
132
  if (adapter.verifyWebhook) {
@@ -126,7 +153,8 @@ const createWebhookPostHandler = (config) => {
126
153
  singletonServices: services,
127
154
  data: () => parsed,
128
155
  auth: config.auth,
129
- wire: wire,
156
+ inheritedMiddleware,
157
+ wire,
130
158
  });
131
159
  };
132
160
  const gatewayMiddleware = userMiddleware;
@@ -186,11 +214,15 @@ const wireWebsocketGateway = (config) => {
186
214
  name,
187
215
  route,
188
216
  gateway: true,
217
+ input: null,
189
218
  connect: { pikkuFuncId: connectFuncId },
219
+ disconnect: null,
190
220
  message: { pikkuFuncId: messageFuncId },
221
+ messageWirings: {},
191
222
  };
192
223
  const userMiddleware = config.middleware;
193
224
  const handlerFuncId = registerGatewayHandler(config);
225
+ const inheritedMiddleware = gatewayInheritedMiddleware(config);
194
226
  addFunction(connectFuncId, {
195
227
  auth: false,
196
228
  func: async (services, _data, wire) => {
@@ -227,7 +259,8 @@ const wireWebsocketGateway = (config) => {
227
259
  singletonServices: services,
228
260
  data: () => parsed,
229
261
  auth: config.auth,
230
- wire: wire,
262
+ inheritedMiddleware,
263
+ wire,
231
264
  });
232
265
  };
233
266
  const gatewayMiddleware = userMiddleware;
@@ -256,6 +289,7 @@ const wireListenerGateway = (config) => {
256
289
  export const createListenerMessageHandler = (name, config, singletonServices) => {
257
290
  const userMiddleware = config.middleware;
258
291
  const handlerFuncId = registerGatewayHandler(config);
292
+ const inheritedMiddleware = gatewayInheritedMiddleware(config);
259
293
  return async (rawData) => {
260
294
  const adapter = await resolveGatewayAdapter(config, singletonServices);
261
295
  const parsed = adapter.parse(rawData);
@@ -275,9 +309,11 @@ export const createListenerMessageHandler = (name, config, singletonServices) =>
275
309
  singletonServices,
276
310
  data: () => parsed,
277
311
  auth: config.auth,
312
+ inheritedMiddleware,
278
313
  wire,
279
314
  });
280
315
  };
316
+ // knowledge: decisions/internals/gateway-listener-middleware-runs-without-an-rpc-on-the-wire.md
281
317
  const result = userMiddleware?.length
282
318
  ? await runMiddleware(singletonServices, wire, userMiddleware, invoke)
283
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
  };
@@ -14,8 +14,6 @@ export declare class RemoteAddonRequestError extends PikkuError {
14
14
  readonly httpStatus: number;
15
15
  constructor(namespace: string, fnName: string, status: number, detail: string);
16
16
  }
17
- import type { AIAgentInput } from '../ai-agent/ai-agent.types.js';
18
- import type { StreamAIAgentOptions } from '../ai-agent/ai-agent-prepare.js';
19
17
  export declare const resolveNamespace: (namespacedFunction: string) => ResolvedFunction | null;
20
18
  export declare class ContextAwareRPCService {
21
19
  private services;
@@ -51,55 +49,14 @@ export declare class ContextAwareRPCService {
51
49
  }): Promise<{
52
50
  runId: string;
53
51
  }>;
54
- get agent(): {
55
- run: (agentName: string, input: AIAgentInput) => Promise<{
56
- status?: "suspended" | undefined;
57
- pendingApprovals?: {
58
- toolCallId: string;
59
- toolName: string;
60
- args: unknown;
61
- reason?: string;
62
- runId: string;
63
- }[] | undefined;
64
- runId: string;
65
- result: {};
66
- usage: {
67
- inputTokens: number;
68
- outputTokens: number;
69
- };
70
- }>;
71
- stream: (agentName: string, input: {
72
- message: string;
73
- threadId: string;
74
- resourceId: string;
75
- model?: string;
76
- temperature?: number;
77
- }, options?: StreamAIAgentOptions) => Promise<void>;
78
- resume: (runId: string, input: {
79
- toolCallId: string;
80
- approved: boolean;
81
- }, options?: StreamAIAgentOptions) => Promise<void>;
82
- interrupt: (runId: string, reason?: "speech" | "user" | "timeout") => Promise<import("../ai-agent/ai-agent-interrupt.js").AgentInterruptResult>;
83
- approve: (runId: string, approvals: {
84
- toolCallId: string;
85
- approved: boolean;
86
- }[], expectedAgentName?: string) => Promise<{
87
- status?: "suspended" | undefined;
88
- pendingApprovals?: {
89
- toolCallId: string;
90
- toolName: string;
91
- args: unknown;
92
- reason?: string;
93
- runId: string;
94
- }[] | undefined;
95
- runId: string;
96
- result: {};
97
- usage: {
98
- inputTokens: number;
99
- outputTokens: number;
100
- };
101
- }>;
102
- };
52
+ /**
53
+ * The agent facade, built on access.
54
+ *
55
+ * The implementation lives in `ai-agent/agent-rpc.ts` so the agent surface is
56
+ * one file rather than a wing of this one; a getter rather than a field so a
57
+ * request that never touches an agent never builds it.
58
+ */
59
+ get agent(): PikkuRPC['agent'];
103
60
  remote<In = any, Out = any>(funcName: string, data: In): Promise<Out>;
104
61
  }
105
62
  export declare class PikkuRPCService<Services extends CoreServices, TypedRPC = PikkuRPC> {