@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.
- package/CHANGELOG.md +234 -0
- package/dist/dev/hot-reload.js +1 -6
- package/dist/ecosystem.d.ts +27 -0
- package/dist/ecosystem.js +26 -0
- package/dist/errors/error-handler.js +4 -2
- package/dist/function/function-runner.js +20 -42
- package/dist/function/functions.types.d.ts +9 -5
- package/dist/index.d.ts +4 -9
- package/dist/index.js +3 -8
- package/dist/middleware/auth-cookie.d.ts +0 -4
- package/dist/middleware/auth-cookie.js +38 -2
- package/dist/middleware/cors.js +1 -0
- package/dist/middleware/index.d.ts +1 -1
- package/dist/middleware/index.js +1 -1
- package/dist/middleware/remote-auth.js +14 -3
- package/dist/permissions.d.ts +8 -10
- package/dist/permissions.js +0 -11
- package/dist/pikku-state.js +12 -5
- package/dist/schema.js +35 -1
- package/dist/services/ai-run-state-service.d.ts +7 -1
- package/dist/services/in-memory-ai-run-state-service.d.ts +1 -1
- package/dist/services/in-memory-ai-run-state-service.js +2 -1
- package/dist/services/in-memory-workflow-service.d.ts +10 -0
- package/dist/services/in-memory-workflow-service.js +25 -0
- package/dist/services/local-content-request-handler.d.ts +21 -0
- package/dist/services/local-content-request-handler.js +72 -53
- package/dist/services/local-content.d.ts +6 -0
- package/dist/services/local-content.js +14 -1
- package/dist/services/workflow-service.d.ts +4 -2
- package/dist/testing/service-tests/agent-run-service-tests.d.ts +10 -0
- package/dist/testing/service-tests/agent-run-service-tests.js +72 -0
- package/dist/testing/service-tests/ai-storage-service-tests.d.ts +3 -0
- package/dist/testing/service-tests/ai-storage-service-tests.js +226 -0
- package/dist/testing/service-tests/channel-store-tests.d.ts +3 -0
- package/dist/testing/service-tests/channel-store-tests.js +72 -0
- package/dist/testing/service-tests/credential-service-tests.d.ts +3 -0
- package/dist/testing/service-tests/credential-service-tests.js +109 -0
- package/dist/testing/service-tests/deployment-service-tests.d.ts +3 -0
- package/dist/testing/service-tests/deployment-service-tests.js +21 -0
- package/dist/testing/service-tests/event-hub-store-tests.d.ts +3 -0
- package/dist/testing/service-tests/event-hub-store-tests.js +34 -0
- package/dist/testing/service-tests/secret-service-tests.d.ts +3 -0
- package/dist/testing/service-tests/secret-service-tests.js +80 -0
- package/dist/testing/service-tests/session-store-tests.d.ts +3 -0
- package/dist/testing/service-tests/session-store-tests.js +43 -0
- package/dist/testing/service-tests/workflow-run-service-tests.d.ts +3 -0
- package/dist/testing/service-tests/workflow-run-service-tests.js +42 -0
- package/dist/testing/service-tests/workflow-service-tests.d.ts +3 -0
- package/dist/testing/service-tests/workflow-service-tests.js +150 -0
- package/dist/testing/service-tests.d.ts +6 -0
- package/dist/testing/service-tests.js +26 -791
- package/dist/types/core.types.d.ts +11 -1
- package/dist/types/state.types.d.ts +1 -1
- package/dist/utils/node-host-resolver.d.ts +12 -0
- package/dist/utils/node-host-resolver.js +16 -0
- package/dist/utils/safe-fetch.d.ts +18 -0
- package/dist/utils/safe-fetch.js +167 -29
- package/dist/wirings/actor-flow/run-conversation.js +1 -6
- package/dist/wirings/ai-agent/agent-rpc.d.ts +15 -0
- package/dist/wirings/ai-agent/agent-rpc.js +53 -0
- package/dist/wirings/ai-agent/ai-agent-agui.js +1 -5
- package/dist/wirings/ai-agent/ai-agent-memory.js +3 -1
- package/dist/wirings/ai-agent/ai-agent-prepare.js +3 -9
- package/dist/wirings/ai-agent/ai-agent-runner.js +28 -107
- package/dist/wirings/ai-agent/ai-agent-stream.js +20 -61
- package/dist/wirings/ai-agent/ai-agent-turn.d.ts +56 -0
- package/dist/wirings/ai-agent/ai-agent-turn.js +81 -0
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +1 -1
- package/dist/wirings/ai-agent/voice-input.js +1 -6
- package/dist/wirings/ai-agent/voice-output.js +2 -12
- package/dist/wirings/channel/channel-common.js +1 -0
- package/dist/wirings/channel/channel-handler.js +3 -5
- package/dist/wirings/channel/channel-rpc-service.d.ts +0 -6
- package/dist/wirings/channel/channel-rpc-service.js +0 -8
- package/dist/wirings/channel/channel-rpc.types.d.ts +6 -0
- package/dist/wirings/channel/channel-rpc.types.js +8 -0
- package/dist/wirings/channel/channel-runner.d.ts +1 -3
- package/dist/wirings/channel/channel-runner.js +16 -8
- package/dist/wirings/channel/channel.types.d.ts +2 -0
- package/dist/wirings/channel/pikku-abstract-channel-handler.js +1 -0
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +3 -0
- package/dist/wirings/cli/channel/cli-channel-runner.js +2 -0
- package/dist/wirings/cli/cli-runner.js +4 -2
- package/dist/wirings/cli/cli.types.d.ts +0 -8
- package/dist/wirings/cli/command-parser.js +13 -0
- package/dist/wirings/gateway/gateway-runner.js +41 -5
- package/dist/wirings/http/http-routes.js +2 -0
- package/dist/wirings/http/http-runner.d.ts +0 -10
- package/dist/wirings/http/http-runner.js +6 -13
- package/dist/wirings/http/http.types.d.ts +0 -10
- package/dist/wirings/http/index.d.ts +1 -1
- package/dist/wirings/http/index.js +1 -1
- package/dist/wirings/mcp/mcp-runner.d.ts +0 -7
- package/dist/wirings/mcp/mcp-runner.js +0 -6
- package/dist/wirings/rpc/rpc-runner.d.ts +8 -51
- package/dist/wirings/rpc/rpc-runner.js +53 -86
- package/dist/wirings/rpc/rpc-types.d.ts +3 -0
- package/dist/wirings/secret/validate-secret-definitions.js +2 -0
- package/dist/wirings/trigger/pikku-trigger-service.d.ts +0 -4
- package/dist/wirings/trigger/trigger-runner.js +1 -0
- package/dist/wirings/virtual-user/run-virtual-user.js +11 -11
- package/dist/wirings/virtual-user/virtual-user-derive.js +4 -25
- package/dist/wirings/virtual-user/virtual-user-dispositions.js +1 -4
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +29 -2
- package/dist/wirings/workflow/feature.js +7 -4
- package/dist/wirings/workflow/graph/graph-runner.d.ts +1 -2
- package/dist/wirings/workflow/graph/graph-runner.js +8 -7
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +0 -4
- package/dist/wirings/workflow/index.d.ts +7 -2
- package/dist/wirings/workflow/index.js +5 -1
- package/dist/wirings/workflow/pikku-scenario-service.d.ts +17 -3
- package/dist/wirings/workflow/pikku-scenario-service.js +38 -10
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +44 -111
- package/dist/wirings/workflow/pikku-workflow-service.js +86 -404
- package/dist/wirings/workflow/workflow-approval.d.ts +39 -0
- package/dist/wirings/workflow/workflow-approval.js +114 -0
- package/dist/wirings/workflow/workflow-constants.d.ts +26 -0
- package/dist/wirings/workflow/workflow-constants.js +35 -0
- package/dist/wirings/workflow/workflow-errors.d.ts +58 -0
- package/dist/wirings/workflow/workflow-errors.js +112 -0
- package/dist/wirings/workflow/workflow-meta-resolver.d.ts +11 -0
- package/dist/wirings/workflow/workflow-meta-resolver.js +31 -0
- package/dist/wirings/workflow/workflow-queue-routing.d.ts +8 -0
- package/dist/wirings/workflow/workflow-queue-routing.js +38 -0
- package/dist/wirings/workflow/workflow-queue-wiring.d.ts +20 -0
- package/dist/wirings/workflow/workflow-queue-wiring.js +79 -0
- package/dist/wirings/workflow/workflow-recovery.d.ts +68 -0
- package/dist/wirings/workflow/workflow-recovery.js +101 -0
- package/dist/wirings/workflow/workflow-run-engine.types.d.ts +54 -0
- package/dist/wirings/workflow/workflow-run-engine.types.js +1 -0
- package/dist/wirings/workflow/workflow-run-ownership.d.ts +16 -0
- package/dist/wirings/workflow/workflow-run-ownership.js +29 -0
- package/dist/wirings/workflow/workflow-suspend.d.ts +12 -0
- package/dist/wirings/workflow/workflow-suspend.js +33 -0
- package/dist/wirings/workflow/workflow.types.d.ts +7 -0
- package/knowledge/decisions/internals/a-non-streaming-agent-run-registers-with-airunstate-too.md +22 -0
- package/knowledge/decisions/internals/a-resumed-agent-turn-is-as-interruptible-as-the-first.md +20 -0
- package/knowledge/decisions/internals/a-scenario-step-template-is-offered-unfilled.md +21 -0
- package/knowledge/decisions/internals/a-virtual-user-decides-whether-to-trust-memory-once-per-turn.md +21 -0
- package/knowledge/decisions/internals/a-wall-clock-threshold-is-a-load-test-in-disguise.md +46 -0
- package/knowledge/decisions/internals/a-workflow-wire-is-built-from-the-run-not-from-the-rpc-service.md +45 -0
- package/knowledge/decisions/internals/agent-context-waits-for-a-tool-result-still-being-written.md +21 -0
- package/knowledge/decisions/internals/agent-speech-travels-as-a-custom-agui-event.md +22 -0
- package/knowledge/decisions/internals/an-agent-interrupt-is-not-a-failure.md +23 -0
- package/knowledge/decisions/internals/an-agent-run-owned-by-another-instance-says-so.md +25 -0
- package/knowledge/decisions/internals/an-agent-stream-send-must-return-the-inner-sends-promise.md +22 -0
- package/knowledge/decisions/internals/an-empty-text-part-is-omitted-from-an-agent-message.md +20 -0
- package/knowledge/decisions/internals/an-empty-transcript-is-not-recorded.md +22 -0
- package/knowledge/decisions/internals/an-unref-d-timer-cannot-be-awaited-under-node-test.md +66 -0
- package/knowledge/decisions/internals/channel-state-accessors-are-unsound-generics-that-every-implementation-asserts.md +33 -0
- package/knowledge/decisions/internals/gateway-listener-middleware-runs-without-an-rpc-on-the-wire.md +43 -0
- package/knowledge/decisions/internals/hot-reload-writes-into-the-function-map-captured-at-startup.md +26 -0
- package/knowledge/decisions/internals/index.md +38 -26
- package/knowledge/decisions/internals/only-exposed-functions-enter-a-virtual-user-catalogue.md +21 -0
- package/knowledge/decisions/internals/scenario-given-and-when-are-sugar-but-then-is-not.md +24 -0
- package/knowledge/decisions/internals/side-effects-are-an-allowlist-not-a-boolean.md +34 -0
- package/knowledge/decisions/internals/speech-synthesis-picks-a-voice-per-sentence-and-warns-once.md +24 -0
- package/knowledge/decisions/internals/the-actor-prompt-says-json-because-of-json-object-mode.md +22 -0
- package/knowledge/decisions/internals/the-agent-done-event-goes-through-the-middleware-and-is-awaited.md +26 -0
- package/knowledge/decisions/internals/the-api-report-pins-members-not-just-names.md +43 -0
- package/knowledge/decisions/internals/the-ecosystem-entry-point-carries-the-adapter-surface.md +58 -0
- package/knowledge/decisions/internals/the-middleware-resolution-cache-is-deliberately-unbounded.md +40 -0
- package/knowledge/decisions/internals/the-per-invocation-rpc-view-is-a-class.md +40 -0
- package/knowledge/decisions/internals/the-persona-runtime-is-exported-from-the-persona-entry-point.md +28 -0
- package/knowledge/decisions/internals/the-transcript-event-is-sent-ahead-of-the-run.md +25 -0
- package/knowledge/decisions/internals/the-virtual-user-catalogue-is-the-only-gate-on-what-may-be-called.md +21 -0
- package/knowledge/decisions/internals/the-worker-disposition-is-the-one-that-is-not-testing.md +22 -0
- package/knowledge/decisions/internals/thread-history-records-the-transcript-not-the-audio.md +25 -0
- package/knowledge/decisions/internals/virtual-user-step-order-comes-from-insertion-order.md +21 -0
- package/knowledge/decisions/internals/voice-output-speaks-unless-voice-input-explicitly-says-otherwise.md +24 -0
- package/knowledge/decisions/internals/wiring-registries-erase-the-generics-their-wire-functions-capture.md +35 -0
- package/knowledge/decisions/security/a-dropped-audit-write-is-always-logged.md +4 -2
- package/knowledge/decisions/security/a-graph-run-starts-at-an-entry-node-the-graph-declared.md +33 -0
- package/knowledge/decisions/security/a-permission-gets-a-wire-it-cannot-reply-on.md +33 -0
- package/knowledge/decisions/security/a-step-runs-the-function-the-workflow-dispatched-it-with.md +37 -0
- package/knowledge/decisions/security/a-virtual-user-is-never-offered-a-step-that-would-forge-its-own-oracle.md +28 -0
- package/knowledge/decisions/security/a-workflow-run-is-read-and-approved-by-its-owner.md +34 -0
- package/knowledge/decisions/security/an-agent-approval-is-claimed-before-the-tool-runs.md +33 -0
- package/knowledge/decisions/security/an-upload-is-counted-as-it-arrives-not-buffered-then-measured.md +24 -0
- package/knowledge/decisions/security/gateway-handlers-run-through-the-function-runner-gate.md +13 -3
- package/knowledge/decisions/security/index.md +7 -0
- package/knowledge/questions/channel-middleware-accepts-bare-factories-that-nothing-resolves.md +35 -0
- package/knowledge/questions/index.md +2 -1
- package/knowledge/questions/unauthorized-channel-replies-escape-the-declared-out-type.md +44 -0
- package/package.json +14 -3
- package/scripts/generate-api-report.d.mts +1 -0
- package/scripts/generate-api-report.mjs +89 -0
- package/scripts/generate-api-report.mts +218 -0
- package/src/api-report.test.ts +69 -0
- package/src/column-form.ts +1 -4
- package/src/crypto-utils.test.ts +15 -2
- package/src/dev/hot-reload.ts +2 -7
- package/src/ecosystem.ts +40 -0
- package/src/errors/error-handler.ts +5 -3
- package/src/errors/error.test.ts +4 -1
- package/src/function/function-runner.test.ts +1 -1
- package/src/function/function-runner.ts +28 -39
- package/src/function/functions.types.ts +15 -9
- package/src/handle-error.ts +1 -1
- package/src/index.ts +3 -22
- package/src/middleware/auth-cookie.test.ts +50 -0
- package/src/middleware/auth-cookie.ts +38 -2
- package/src/middleware/cors.ts +2 -1
- package/src/middleware/index.ts +1 -1
- package/src/middleware/remote-auth.test.ts +43 -0
- package/src/middleware/remote-auth.ts +17 -3
- package/src/middleware-runner.ts +4 -2
- package/src/no-any-casts.test.ts +57 -0
- package/src/permissions.test.ts +3 -1
- package/src/permissions.ts +22 -24
- package/src/pikku-state.ts +17 -6
- package/src/public-surface.json +578 -0
- package/src/public-surface.json.README +25 -0
- package/src/public-surface.test.ts +105 -0
- package/src/removed-legacy-exports.test.ts +62 -0
- package/src/schema.test.ts +78 -0
- package/src/schema.ts +36 -1
- package/src/services/ai-run-state-service.ts +7 -1
- package/src/services/audit-service.ts +2 -2
- package/src/services/in-memory-ai-run-state-service.ts +3 -2
- package/src/services/in-memory-workflow-service.ts +25 -0
- package/src/services/index.ts +1 -4
- package/src/services/local-content-request-handler.test.ts +43 -5
- package/src/services/local-content-request-handler.ts +103 -74
- package/src/services/local-content.ts +15 -1
- package/src/services/local-email-service.ts +5 -1
- package/src/services/system-role-guard.test.ts +4 -1
- package/src/services/workflow-service.ts +9 -2
- package/src/side-effects-are-declared.test.ts +84 -0
- package/src/source-files-stay-composable.test.ts +41 -0
- package/src/testing/service-tests/agent-run-service-tests.ts +98 -0
- package/src/testing/service-tests/ai-storage-service-tests.ts +286 -0
- package/src/testing/service-tests/channel-store-tests.ts +98 -0
- package/src/testing/service-tests/credential-service-tests.ts +143 -0
- package/src/testing/service-tests/deployment-service-tests.ts +33 -0
- package/src/testing/service-tests/event-hub-store-tests.ts +48 -0
- package/src/testing/service-tests/secret-service-tests.ts +105 -0
- package/src/testing/service-tests/session-store-tests.ts +62 -0
- package/src/testing/service-tests/workflow-run-service-tests.ts +59 -0
- package/src/testing/service-tests/workflow-service-tests.ts +308 -0
- package/src/testing/service-tests.ts +31 -1111
- package/src/types/core.types.ts +15 -1
- package/src/types/state.types.ts +1 -1
- package/src/utils/node-host-resolver.ts +20 -0
- package/src/utils/safe-fetch.test.ts +143 -1
- package/src/utils/safe-fetch.ts +200 -25
- package/src/wirings/actor-flow/run-conversation.ts +1 -6
- package/src/wirings/ai-agent/agent-rpc.ts +120 -0
- package/src/wirings/ai-agent/ai-agent-agui.ts +1 -5
- package/src/wirings/ai-agent/ai-agent-interrupt.test.ts +2 -1
- package/src/wirings/ai-agent/ai-agent-memory.ts +8 -1
- package/src/wirings/ai-agent/ai-agent-prepare.ts +10 -12
- package/src/wirings/ai-agent/ai-agent-resume-authorization.test.ts +1 -0
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +82 -2
- package/src/wirings/ai-agent/ai-agent-runner.ts +49 -120
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +2 -0
- package/src/wirings/ai-agent/ai-agent-stream.ts +36 -63
- package/src/wirings/ai-agent/ai-agent-thread-ownership.test.ts +1 -1
- package/src/wirings/ai-agent/ai-agent-turn.ts +121 -0
- package/src/wirings/ai-agent/ai-agent.types.ts +1 -1
- package/src/wirings/ai-agent/voice-input.ts +1 -6
- package/src/wirings/ai-agent/voice-output.ts +2 -12
- package/src/wirings/channel/channel-common.ts +5 -2
- package/src/wirings/channel/channel-handler-shapes.test.ts +72 -0
- package/src/wirings/channel/channel-handler.ts +7 -7
- package/src/wirings/channel/channel-rpc-service.ts +0 -14
- package/src/wirings/channel/channel-rpc.test.ts +25 -4
- package/src/wirings/channel/channel-rpc.types.ts +14 -0
- package/src/wirings/channel/channel-runner.ts +33 -20
- package/src/wirings/channel/channel.types.ts +2 -0
- package/src/wirings/channel/local/local-channel-runner.ts +1 -1
- package/src/wirings/channel/pikku-abstract-channel-handler.ts +2 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +6 -3
- package/src/wirings/cli/channel/cli-channel-runner.ts +3 -1
- package/src/wirings/cli/channel/cli-raw-client-runner.ts +4 -1
- package/src/wirings/cli/cli-runner.ts +7 -4
- package/src/wirings/cli/cli.types.ts +0 -39
- package/src/wirings/cli/command-parser.test.ts +19 -0
- package/src/wirings/cli/command-parser.ts +17 -1
- package/src/wirings/gateway/gateway-authorization.test.ts +131 -0
- package/src/wirings/gateway/gateway-channel-meta.test.ts +44 -0
- package/src/wirings/gateway/gateway-runner.ts +62 -22
- package/src/wirings/http/http-routes.ts +4 -1
- package/src/wirings/http/http-runner.ts +11 -26
- package/src/wirings/http/http.types.ts +0 -15
- package/src/wirings/http/index.ts +1 -7
- package/src/wirings/http/pikku-fetch-http-request.ts +2 -2
- package/src/wirings/http/web-request.ts +1 -1
- package/src/wirings/mcp/mcp-runner.ts +2 -16
- package/src/wirings/persona/persona-environments.test.ts +14 -3
- package/src/wirings/persona/persona.test.ts +13 -3
- package/src/wirings/persona/validate-personas.ts +5 -1
- package/src/wirings/queue/queue-runner.ts +1 -1
- package/src/wirings/rpc/addon-auth-tags.test.ts +1 -5
- package/src/wirings/rpc/rpc-runner.ts +58 -136
- package/src/wirings/rpc/rpc-types.ts +7 -0
- package/src/wirings/rpc/wire-addon.ts +3 -1
- package/src/wirings/secret/validate-secret-definitions.test.ts +69 -0
- package/src/wirings/secret/validate-secret-definitions.ts +2 -0
- package/src/wirings/trigger/pikku-trigger-service.ts +0 -5
- package/src/wirings/trigger/trigger-runner.ts +7 -5
- package/src/wirings/virtual-user/run-virtual-user.test.ts +18 -9
- package/src/wirings/virtual-user/run-virtual-user.ts +28 -15
- package/src/wirings/virtual-user/virtual-user-agents.test.ts +4 -1
- package/src/wirings/virtual-user/virtual-user-derive.ts +4 -25
- package/src/wirings/virtual-user/virtual-user-dispositions.test.ts +7 -2
- package/src/wirings/virtual-user/virtual-user-dispositions.ts +1 -4
- package/src/wirings/virtual-user/virtual-user-intents.test.ts +13 -3
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +35 -2
- package/src/wirings/workflow/feature.ts +7 -4
- package/src/wirings/workflow/graph/graph-node.ts +1 -1
- package/src/wirings/workflow/graph/graph-runner.test.ts +4 -2
- package/src/wirings/workflow/graph/graph-runner.ts +13 -16
- package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -5
- package/src/wirings/workflow/index.ts +12 -4
- package/src/wirings/workflow/pikku-scenario-service.ts +54 -25
- package/src/wirings/workflow/pikku-workflow-service.test.ts +2 -2
- package/src/wirings/workflow/pikku-workflow-service.ts +208 -630
- package/src/wirings/workflow/scenario-hooks.test.ts +51 -0
- package/src/wirings/workflow/workflow-approval.ts +185 -0
- package/src/wirings/workflow/workflow-child-run-session.test.ts +89 -0
- package/src/wirings/workflow/workflow-constants.ts +47 -0
- package/src/wirings/workflow/workflow-dispatch-durability.test.ts +1 -1
- package/src/wirings/workflow/workflow-dispatch-relay.test.ts +128 -0
- package/src/wirings/workflow/workflow-errors.ts +128 -0
- package/src/wirings/workflow/workflow-inline-authority.test.ts +12 -6
- package/src/wirings/workflow/workflow-meta-resolver.ts +45 -0
- package/src/wirings/workflow/workflow-missing-meta.test.ts +92 -0
- package/src/wirings/workflow/workflow-queue-routing.ts +85 -0
- package/src/wirings/workflow/workflow-queue-wiring.ts +149 -0
- package/src/wirings/workflow/workflow-recovery.ts +162 -0
- package/src/wirings/workflow/workflow-retry-policy.test.ts +1 -1
- package/src/wirings/workflow/workflow-run-authority.test.ts +215 -0
- package/src/wirings/workflow/workflow-run-engine.types.ts +91 -0
- package/src/wirings/workflow/workflow-run-ownership.ts +36 -0
- package/src/wirings/workflow/workflow-suspend.ts +61 -0
- package/src/wirings/workflow/workflow.types.ts +7 -0
- package/src/wirings-stay-decoupled.test.ts +123 -0
- package/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- 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
|
|
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
|
|
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 ||
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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> {
|