@pikku/core 0.12.83 → 0.12.84
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 +68 -0
- package/README.md +1 -1
- package/dist/ecosystem/agent-scorer.d.ts +12 -0
- package/dist/ecosystem/agent-scorer.js +5 -0
- package/dist/ecosystem/agent.d.ts +18 -0
- package/dist/ecosystem/agent.js +6 -0
- package/dist/ecosystem/ai-agent.d.ts +18 -0
- package/dist/ecosystem/ai-agent.js +6 -0
- package/dist/ecosystem/ai-scorer.d.ts +12 -0
- package/dist/ecosystem/ai-scorer.js +5 -0
- package/dist/ecosystem/channel/local.d.ts +1 -0
- package/dist/ecosystem/channel/local.js +1 -0
- package/dist/ecosystem/channel.d.ts +12 -0
- package/dist/ecosystem/channel.js +4 -0
- package/dist/ecosystem/cli/channel.d.ts +16 -0
- package/dist/ecosystem/cli/channel.js +2 -0
- package/dist/ecosystem/cli.d.ts +9 -0
- package/dist/ecosystem/cli.js +2 -0
- package/dist/ecosystem/credential.d.ts +9 -0
- package/dist/ecosystem/credential.js +1 -0
- package/dist/ecosystem/dev.d.ts +8 -0
- package/dist/ecosystem/dev.js +1 -0
- package/dist/ecosystem/function.d.ts +13 -0
- package/dist/ecosystem/function.js +2 -0
- package/dist/ecosystem/gateway.d.ts +1 -0
- package/dist/ecosystem/gateway.js +1 -0
- package/dist/ecosystem/hmac.d.ts +1 -0
- package/dist/ecosystem/hmac.js +1 -0
- package/dist/ecosystem/http.d.ts +11 -0
- package/dist/ecosystem/http.js +3 -0
- package/dist/ecosystem/mcp.d.ts +3 -0
- package/dist/ecosystem/mcp.js +2 -0
- package/dist/ecosystem/middleware.d.ts +17 -0
- package/dist/ecosystem/middleware.js +6 -0
- package/dist/ecosystem/node-host-resolver.d.ts +1 -0
- package/dist/ecosystem/node-host-resolver.js +1 -0
- package/dist/ecosystem/node.d.ts +1 -0
- package/dist/ecosystem/node.js +1 -0
- package/dist/ecosystem/oauth2.d.ts +1 -0
- package/dist/ecosystem/oauth2.js +1 -0
- package/dist/ecosystem/persona.d.ts +15 -0
- package/dist/ecosystem/persona.js +4 -0
- package/dist/ecosystem/queue.d.ts +11 -0
- package/dist/ecosystem/queue.js +2 -0
- package/dist/ecosystem/remote.d.ts +8 -0
- package/dist/ecosystem/remote.js +1 -0
- package/dist/ecosystem/role.d.ts +3 -0
- package/dist/ecosystem/role.js +2 -0
- package/dist/ecosystem/rpc.d.ts +4 -0
- package/dist/ecosystem/rpc.js +2 -0
- package/dist/ecosystem/safe-fetch.d.ts +7 -0
- package/dist/ecosystem/safe-fetch.js +1 -0
- package/dist/ecosystem/scenario.d.ts +15 -0
- package/dist/ecosystem/scenario.js +4 -0
- package/dist/ecosystem/scheduler.d.ts +2 -0
- package/dist/ecosystem/scheduler.js +1 -0
- package/dist/ecosystem/schema.d.ts +1 -0
- package/dist/ecosystem/schema.js +1 -0
- package/dist/ecosystem/scope.d.ts +3 -0
- package/dist/ecosystem/scope.js +2 -0
- package/dist/ecosystem/secret.d.ts +9 -0
- package/dist/ecosystem/secret.js +1 -0
- package/dist/ecosystem/services/istanbul-coverage.d.ts +1 -0
- package/dist/ecosystem/services/istanbul-coverage.js +1 -0
- package/dist/ecosystem/services/local-content-request-handler.d.ts +9 -0
- package/dist/ecosystem/services/local-content-request-handler.js +1 -0
- package/dist/ecosystem/services/local-content.d.ts +1 -0
- package/dist/ecosystem/services/local-content.js +1 -0
- package/dist/ecosystem/services/v8-coverage.d.ts +1 -0
- package/dist/ecosystem/services/v8-coverage.js +1 -0
- package/dist/ecosystem/services.d.ts +28 -0
- package/dist/ecosystem/services.js +6 -0
- package/dist/ecosystem/testing.d.ts +7 -0
- package/dist/ecosystem/testing.js +1 -0
- package/dist/ecosystem/trigger.d.ts +1 -0
- package/dist/ecosystem/trigger.js +1 -0
- package/dist/ecosystem/types.d.ts +9 -0
- package/dist/ecosystem/types.js +5 -0
- package/dist/ecosystem/variable.d.ts +8 -0
- package/dist/ecosystem/variable.js +1 -0
- package/dist/ecosystem/virtual-user.d.ts +21 -0
- package/dist/ecosystem/virtual-user.js +5 -0
- package/dist/ecosystem/workflow.d.ts +18 -0
- package/dist/ecosystem/workflow.js +4 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +3 -3
- package/dist/middleware/auth-apikey.d.ts +1 -1
- package/dist/middleware/auth-bearer.d.ts +1 -1
- package/dist/middleware/auth-cookie.d.ts +1 -1
- package/dist/middleware/cors.d.ts +1 -1
- package/dist/middleware/remote-auth.d.ts +1 -1
- package/dist/middleware/telemetry.d.ts +2 -2
- package/dist/services/agent-run-state-service.d.ts +29 -0
- package/dist/services/agent-run-state-service.js +1 -0
- package/dist/services/agent-runner-service.d.ts +220 -0
- package/dist/services/agent-runner-service.js +1 -0
- package/dist/services/agent-storage-service.d.ts +18 -0
- package/dist/services/agent-storage-service.js +1 -0
- package/dist/services/http-personas.d.ts +1 -1
- package/dist/services/http-personas.js +3 -3
- package/dist/services/in-memory-agent-run-state-service.d.ts +19 -0
- package/dist/services/in-memory-agent-run-state-service.js +54 -0
- package/dist/services/index.d.ts +4 -4
- package/dist/services/index.js +1 -1
- package/dist/services/meta-service.d.ts +3 -3
- package/dist/testing/service-tests/agent-run-service-tests.d.ts +1 -1
- package/dist/testing/service-tests/agent-run-service-tests.js +3 -3
- package/dist/testing/service-tests/agent-storage-service-tests.d.ts +3 -0
- package/dist/testing/service-tests/agent-storage-service-tests.js +302 -0
- package/dist/testing/service-tests.d.ts +4 -4
- package/dist/testing/service-tests.js +4 -4
- package/dist/types/core.types.d.ts +10 -10
- package/dist/types/core.types.js +1 -1
- package/dist/types/state.types.d.ts +5 -5
- package/dist/wirings/actor-flow/run-conversation.d.ts +2 -2
- package/dist/wirings/agent/agent-agui.d.ts +79 -0
- package/dist/wirings/agent/agent-agui.js +327 -0
- package/dist/wirings/agent/agent-finalize.d.ts +58 -0
- package/dist/wirings/agent/agent-finalize.js +138 -0
- package/dist/wirings/agent/agent-helpers.d.ts +35 -0
- package/dist/wirings/agent/agent-helpers.js +47 -0
- package/dist/wirings/agent/agent-interrupt.d.ts +153 -0
- package/dist/wirings/agent/agent-interrupt.js +257 -0
- package/dist/wirings/agent/agent-memory.d.ts +42 -0
- package/dist/wirings/agent/agent-memory.js +333 -0
- package/dist/wirings/agent/agent-model-config.d.ts +16 -0
- package/dist/wirings/agent/agent-model-config.js +51 -0
- package/dist/wirings/agent/agent-prepare.d.ts +117 -0
- package/dist/wirings/agent/agent-prepare.js +728 -0
- package/dist/wirings/agent/agent-registry.d.ts +16 -0
- package/dist/wirings/agent/agent-registry.js +51 -0
- package/dist/wirings/agent/agent-rpc.d.ts +15 -0
- package/dist/wirings/agent/agent-rpc.js +53 -0
- package/dist/wirings/agent/agent-runner.d.ts +7 -0
- package/dist/wirings/agent/agent-runner.js +580 -0
- package/dist/wirings/agent/agent-stream.d.ts +41 -0
- package/dist/wirings/agent/agent-stream.js +1029 -0
- package/dist/wirings/agent/agent-turn.d.ts +57 -0
- package/dist/wirings/agent/agent-turn.js +82 -0
- package/dist/wirings/agent/agent-utils.d.ts +1 -0
- package/dist/wirings/agent/agent-utils.js +1 -0
- package/dist/wirings/agent/agent.types.d.ts +625 -0
- package/dist/wirings/agent/agent.types.js +1 -0
- package/dist/wirings/agent/index.d.ts +12 -0
- package/dist/wirings/agent/index.js +10 -0
- package/dist/wirings/agent/voice-input.d.ts +69 -0
- package/dist/wirings/agent/voice-input.js +150 -0
- package/dist/wirings/agent/voice-output.d.ts +85 -0
- package/dist/wirings/agent/voice-output.js +196 -0
- package/dist/wirings/agent-scorer/agent-scorer-grade.d.ts +26 -0
- package/dist/wirings/agent-scorer/agent-scorer-grade.js +33 -0
- package/dist/wirings/agent-scorer/agent-scorer-judge.d.ts +17 -0
- package/dist/wirings/agent-scorer/agent-scorer-judge.js +92 -0
- package/dist/wirings/agent-scorer/agent-scorer-live.d.ts +15 -0
- package/dist/wirings/agent-scorer/agent-scorer-live.js +38 -0
- package/dist/wirings/agent-scorer/agent-scorer-registry.d.ts +18 -0
- package/dist/wirings/agent-scorer/agent-scorer-registry.js +46 -0
- package/dist/wirings/agent-scorer/agent-scorer-sampling.d.ts +8 -0
- package/dist/wirings/agent-scorer/agent-scorer-sampling.js +31 -0
- package/dist/wirings/agent-scorer/agent-scorer-snapshots.d.ts +10 -0
- package/dist/wirings/agent-scorer/agent-scorer-snapshots.js +40 -0
- package/dist/wirings/agent-scorer/agent-scorer-worker.d.ts +15 -0
- package/dist/wirings/agent-scorer/agent-scorer-worker.js +60 -0
- package/dist/wirings/agent-scorer/agent-scorer.d.ts +39 -0
- package/dist/wirings/agent-scorer/agent-scorer.js +40 -0
- package/dist/wirings/agent-scorer/agent-scorer.types.d.ts +90 -0
- package/dist/wirings/agent-scorer/agent-scorer.types.js +4 -0
- package/dist/wirings/agent-scorer/index.d.ts +6 -0
- package/dist/wirings/agent-scorer/index.js +5 -0
- package/dist/wirings/ai-agent/voice-output.d.ts +1 -2
- package/dist/wirings/channel/channel-rpc.types.d.ts +2 -2
- package/dist/wirings/rpc/rpc-runner.d.ts +1 -1
- package/dist/wirings/rpc/rpc-runner.js +2 -2
- package/dist/wirings/rpc/rpc-types.d.ts +1 -1
- package/dist/wirings/virtual-user/prepare-virtual-user-run.js +1 -1
- package/dist/wirings/virtual-user/virtual-user-agents.d.ts +1 -1
- package/dist/wirings/workflow/run-timeline.d.ts +1 -2
- package/knowledge/decisions/internals/{a-non-streaming-agent-run-registers-with-airunstate-too.md → a-non-streaming-agent-run-registers-with-agentrunstate-too.md} +6 -6
- package/knowledge/decisions/internals/a-resumed-agent-turn-is-as-interruptible-as-the-first.md +1 -1
- package/knowledge/decisions/internals/actor-flow-drives-the-target-through-a-transport-seam.md +1 -1
- package/knowledge/decisions/internals/{ai-agent-agui-bridge-obeys-the-client-ordering-contract.md → agent-agui-bridge-obeys-the-client-ordering-contract.md} +5 -5
- package/knowledge/decisions/internals/{ai-agent-audio-chunks-carry-the-format-the-provider-returned.md → agent-audio-chunks-carry-the-format-the-provider-returned.md} +2 -2
- package/knowledge/decisions/internals/agent-context-waits-for-a-tool-result-still-being-written.md +1 -1
- package/knowledge/decisions/internals/{ai-agent-credential-suspensions-hide-the-tool-result.md → agent-credential-suspensions-hide-the-tool-result.md} +2 -2
- package/knowledge/decisions/internals/{ai-agent-delegate-and-supervise-hide-different-text.md → agent-delegate-and-supervise-hide-different-text.md} +4 -4
- package/knowledge/decisions/internals/{ai-agent-llm-tool-arguments-have-nulls-stripped.md → agent-llm-tool-arguments-have-nulls-stripped.md} +3 -3
- package/knowledge/decisions/internals/{ai-agent-model-config-stays-a-single-resolution-seam.md → agent-model-config-stays-a-single-resolution-seam.md} +3 -3
- package/knowledge/decisions/internals/{ai-agent-onerror-hooks-cannot-change-the-failure.md → agent-onerror-hooks-cannot-change-the-failure.md} +6 -6
- package/knowledge/decisions/internals/{ai-agent-runner-methods-must-keep-their-receiver.md → agent-runner-methods-must-keep-their-receiver.md} +4 -4
- package/knowledge/decisions/internals/agent-speech-travels-as-a-custom-agui-event.md +1 -1
- package/knowledge/decisions/internals/{ai-agent-stream-persistence-is-best-effort.md → agent-stream-persistence-is-best-effort.md} +4 -4
- package/knowledge/decisions/internals/{ai-agent-sub-agents-inherit-the-parent-context-block.md → agent-sub-agents-inherit-the-parent-context-block.md} +3 -3
- package/knowledge/decisions/internals/{ai-agent-tool-execute-failures-are-logged-unconditionally.md → agent-tool-execute-failures-are-logged-unconditionally.md} +3 -3
- package/knowledge/decisions/internals/{ai-agent-voice-input-transcribes-audio-parts-in-place.md → agent-voice-input-transcribes-audio-parts-in-place.md} +2 -2
- package/knowledge/decisions/internals/{ai-agent-working-memory-is-persisted-only-when-valid.md → agent-working-memory-is-persisted-only-when-valid.md} +2 -2
- package/knowledge/decisions/internals/an-agent-interrupt-is-not-a-failure.md +2 -2
- package/knowledge/decisions/internals/an-agent-run-owned-by-another-instance-says-so.md +3 -3
- package/knowledge/decisions/internals/an-agent-stream-send-must-return-the-inner-sends-promise.md +2 -2
- package/knowledge/decisions/internals/an-empty-text-part-is-omitted-from-an-agent-message.md +1 -1
- package/knowledge/decisions/internals/an-empty-transcript-is-not-recorded.md +1 -1
- package/knowledge/decisions/internals/speech-synthesis-picks-a-voice-per-sentence-and-warns-once.md +1 -1
- package/knowledge/decisions/internals/the-agent-done-event-goes-through-the-middleware-and-is-awaited.md +1 -1
- package/knowledge/decisions/internals/the-embedding-model-is-pinned-per-service-and-doc-query-embedding-is-split.md +1 -1
- package/knowledge/decisions/internals/the-per-invocation-rpc-view-is-a-class.md +5 -5
- package/knowledge/decisions/internals/the-transcript-event-is-sent-ahead-of-the-run.md +2 -2
- package/knowledge/decisions/internals/thread-history-records-the-transcript-not-the-audio.md +2 -2
- package/knowledge/decisions/internals/voice-output-speaks-unless-voice-input-explicitly-says-otherwise.md +1 -1
- package/knowledge/decisions/security/{ai-agent-approval-forwarding-requires-a-symbol-brand.md → agent-approval-forwarding-requires-a-symbol-brand.md} +3 -3
- package/knowledge/decisions/security/{ai-agent-credential-requests-are-symbol-branded.md → agent-credential-requests-are-symbol-branded.md} +4 -4
- package/knowledge/decisions/security/{ai-agent-gate-requires-a-session-only-when-auth-is-true.md → agent-gate-requires-a-session-only-when-auth-is-true.md} +3 -3
- package/knowledge/decisions/security/{ai-agent-ownership-failures-never-echo-the-resource.md → agent-ownership-failures-never-echo-the-resource.md} +2 -2
- package/knowledge/decisions/security/{ai-agent-resume-re-runs-the-authorization-gate.md → agent-resume-re-runs-the-authorization-gate.md} +4 -4
- package/knowledge/decisions/security/{ai-agent-sessionless-deployments-have-no-thread-ownership.md → agent-sessionless-deployments-have-no-thread-ownership.md} +5 -5
- package/knowledge/decisions/security/{ai-agent-thread-ownership-composes-the-session-principal.md → agent-thread-ownership-composes-the-session-principal.md} +2 -2
- package/knowledge/decisions/security/{ai-agent-tool-filtering-reads-the-live-function-config.md → agent-tool-filtering-reads-the-live-function-config.md} +2 -2
- package/knowledge/decisions/security/an-agent-approval-is-claimed-before-the-tool-runs.md +3 -3
- package/knowledge/decisions/security/an-empty-owners-constraint-matches-nothing.md +3 -3
- package/knowledge/decisions/security/console-addon-privileged-functions-gate-themselves.md +20 -13
- package/knowledge/decisions/security/index.md +1 -2
- package/package.json +4 -3
- package/scripts/generate-api-report.mts +32 -8
- package/src/agent-naming.test.ts +68 -0
- package/src/ecosystem/agent-scorer.ts +24 -0
- package/src/ecosystem/agent.ts +42 -0
- package/src/ecosystem/channel/local.ts +1 -0
- package/src/ecosystem/channel.ts +22 -0
- package/src/ecosystem/cli/channel.ts +25 -0
- package/src/ecosystem/cli.ts +21 -0
- package/src/ecosystem/credential.ts +10 -0
- package/src/ecosystem/dev.ts +12 -0
- package/src/ecosystem/function.ts +28 -0
- package/src/ecosystem/gateway.ts +4 -0
- package/src/ecosystem/hmac.ts +1 -0
- package/src/ecosystem/http.ts +22 -0
- package/src/ecosystem/mcp.ts +17 -0
- package/src/ecosystem/middleware.ts +27 -0
- package/src/ecosystem/node-host-resolver.ts +1 -0
- package/src/ecosystem/node.ts +5 -0
- package/src/ecosystem/oauth2.ts +4 -0
- package/src/ecosystem/persona.ts +30 -0
- package/src/ecosystem/queue.ts +23 -0
- package/src/ecosystem/remote.ts +9 -0
- package/src/ecosystem/role.ts +13 -0
- package/src/ecosystem/rpc.ts +7 -0
- package/src/ecosystem/safe-fetch.ts +8 -0
- package/src/ecosystem/scenario.ts +32 -0
- package/src/ecosystem/scheduler.ts +5 -0
- package/src/ecosystem/schema.ts +1 -0
- package/src/ecosystem/scope.ts +14 -0
- package/src/ecosystem/secret.ts +15 -0
- package/src/ecosystem/services/istanbul-coverage.ts +1 -0
- package/src/ecosystem/services/local-content-request-handler.ts +16 -0
- package/src/ecosystem/services/local-content.ts +1 -0
- package/src/ecosystem/services/v8-coverage.ts +1 -0
- package/src/ecosystem/services.ts +82 -0
- package/src/ecosystem/testing.ts +8 -0
- package/src/ecosystem/trigger.ts +7 -0
- package/src/ecosystem/types.ts +34 -0
- package/src/ecosystem/variable.ts +14 -0
- package/src/ecosystem/virtual-user.ts +48 -0
- package/src/ecosystem/workflow.ts +68 -0
- package/src/index.ts +8 -19
- package/src/pikku-state.ts +3 -3
- package/src/public-surface.json +173 -68
- package/src/public-surface.json.README +20 -2
- package/src/public-surface.test.ts +31 -3
- package/src/services/{ai-run-state-service.ts → agent-run-state-service.ts} +5 -5
- package/src/services/{ai-agent-runner-service.ts → agent-runner-service.ts} +18 -18
- package/src/services/{ai-storage-service.ts → agent-storage-service.ts} +7 -7
- package/src/services/http-personas-converse.test.ts +3 -3
- package/src/services/http-personas.ts +4 -4
- package/src/services/{in-memory-ai-run-state-service.ts → in-memory-agent-run-state-service.ts} +7 -7
- package/src/services/index.ts +9 -9
- package/src/services/meta-service.ts +3 -3
- package/src/testing/service-tests/agent-run-service-tests.ts +4 -4
- package/src/testing/service-tests/{ai-storage-service-tests.ts → agent-storage-service-tests.ts} +8 -8
- package/src/testing/service-tests.ts +10 -8
- package/src/types/core.types.ts +12 -12
- package/src/types/state.types.ts +6 -9
- package/src/wirings/actor-flow/run-conversation.test.ts +2 -2
- package/src/wirings/actor-flow/run-conversation.ts +7 -9
- package/src/wirings/{ai-agent/ai-agent-agui.test.ts → agent/agent-agui.test.ts} +126 -105
- package/src/wirings/{ai-agent/ai-agent-agui.ts → agent/agent-agui.ts} +7 -7
- package/src/wirings/{ai-agent/ai-agent-authorization.test.ts → agent/agent-authorization.test.ts} +6 -6
- package/src/wirings/{ai-agent/ai-agent-finalize.test.ts → agent/agent-finalize.test.ts} +17 -16
- package/src/wirings/{ai-agent/ai-agent-finalize.ts → agent/agent-finalize.ts} +22 -22
- package/src/wirings/{ai-agent/ai-agent-helpers.test.ts → agent/agent-helpers.test.ts} +1 -1
- package/src/wirings/{ai-agent/ai-agent-helpers.ts → agent/agent-helpers.ts} +1 -1
- package/src/wirings/{ai-agent/ai-agent-interrupt.test.ts → agent/agent-interrupt.test.ts} +67 -77
- package/src/wirings/{ai-agent/ai-agent-interrupt.ts → agent/agent-interrupt.ts} +5 -5
- package/src/wirings/{ai-agent/ai-agent-memory.test.ts → agent/agent-memory.test.ts} +12 -12
- package/src/wirings/{ai-agent/ai-agent-memory.ts → agent/agent-memory.ts} +36 -36
- package/src/wirings/{ai-agent/ai-agent-model-config.test.ts → agent/agent-model-config.test.ts} +2 -5
- package/src/wirings/{ai-agent/ai-agent-model-config.ts → agent/agent-model-config.ts} +1 -1
- package/src/wirings/{ai-agent/ai-agent-prepare.test.ts → agent/agent-prepare.test.ts} +18 -18
- package/src/wirings/{ai-agent/ai-agent-prepare.ts → agent/agent-prepare.ts} +52 -51
- package/src/wirings/{ai-agent/ai-agent-registry.test.ts → agent/agent-registry.test.ts} +49 -43
- package/src/wirings/{ai-agent/ai-agent-registry.ts → agent/agent-registry.ts} +14 -14
- package/src/wirings/{ai-agent/ai-agent-resume-authorization.test.ts → agent/agent-resume-authorization.test.ts} +18 -18
- package/src/wirings/{ai-agent → agent}/agent-rpc.ts +16 -20
- package/src/wirings/{ai-agent/ai-agent-runner.test.ts → agent/agent-runner.test.ts} +105 -106
- package/src/wirings/{ai-agent/ai-agent-runner.ts → agent/agent-runner.ts} +90 -80
- package/src/wirings/{ai-agent/ai-agent-stream-output-hooks.test.ts → agent/agent-stream-output-hooks.test.ts} +25 -25
- package/src/wirings/{ai-agent/ai-agent-stream.test.ts → agent/agent-stream.test.ts} +147 -143
- package/src/wirings/{ai-agent/ai-agent-stream.ts → agent/agent-stream.ts} +147 -146
- package/src/wirings/{ai-agent/ai-agent-thread-ownership.test.ts → agent/agent-thread-ownership.test.ts} +24 -28
- package/src/wirings/{ai-agent/ai-agent-turn.test.ts → agent/agent-turn.test.ts} +3 -5
- package/src/wirings/{ai-agent/ai-agent-turn.ts → agent/agent-turn.ts} +7 -7
- package/src/wirings/{ai-agent/ai-agent.types.ts → agent/agent.types.ts} +51 -48
- package/src/wirings/agent/index.ts +56 -0
- package/src/wirings/{ai-agent → agent}/voice-input.test.ts +15 -15
- package/src/wirings/{ai-agent → agent}/voice-input.ts +11 -11
- package/src/wirings/{ai-agent → agent}/voice-output.test.ts +23 -23
- package/src/wirings/{ai-agent → agent}/voice-output.ts +11 -11
- package/src/wirings/{ai-scorer/ai-scorer-grade.test.ts → agent-scorer/agent-scorer-grade.test.ts} +8 -8
- package/src/wirings/{ai-scorer/ai-scorer-grade.ts → agent-scorer/agent-scorer-grade.ts} +9 -9
- package/src/wirings/{ai-scorer/ai-scorer-judge.test.ts → agent-scorer/agent-scorer-judge.test.ts} +11 -14
- package/src/wirings/{ai-scorer/ai-scorer-judge.ts → agent-scorer/agent-scorer-judge.ts} +11 -11
- package/src/wirings/{ai-scorer/ai-scorer-live.test.ts → agent-scorer/agent-scorer-live.test.ts} +11 -11
- package/src/wirings/{ai-scorer/ai-scorer-live.ts → agent-scorer/agent-scorer-live.ts} +3 -3
- package/src/wirings/{ai-scorer/ai-scorer-registry.ts → agent-scorer/agent-scorer-registry.ts} +11 -8
- package/src/wirings/{ai-scorer/ai-scorer-sampling.test.ts → agent-scorer/agent-scorer-sampling.test.ts} +1 -1
- package/src/wirings/{ai-scorer/ai-scorer-snapshots.test.ts → agent-scorer/agent-scorer-snapshots.test.ts} +2 -2
- package/src/wirings/{ai-scorer/ai-scorer-snapshots.ts → agent-scorer/agent-scorer-snapshots.ts} +1 -1
- package/src/wirings/{ai-scorer/ai-scorer-worker.test.ts → agent-scorer/agent-scorer-worker.test.ts} +15 -15
- package/src/wirings/{ai-scorer/ai-scorer-worker.ts → agent-scorer/agent-scorer-worker.ts} +9 -7
- package/src/wirings/{ai-scorer/ai-scorer.ts → agent-scorer/agent-scorer.ts} +7 -7
- package/src/wirings/{ai-scorer/ai-scorer.types.ts → agent-scorer/agent-scorer.types.ts} +6 -6
- package/src/wirings/agent-scorer/index.ts +22 -0
- package/src/wirings/channel/channel-rpc.types.ts +2 -2
- package/src/wirings/rpc/rpc-runner.ts +2 -2
- package/src/wirings/rpc/rpc-types.ts +1 -1
- package/src/wirings/virtual-user/prepare-virtual-user-run.ts +1 -1
- package/src/wirings/virtual-user/run-virtual-user.test.ts +2 -2
- package/src/wirings/virtual-user/run-virtual-user.ts +3 -3
- package/src/wirings/virtual-user/virtual-user-agents.ts +1 -1
- package/src/wirings/workflow/run-timeline.ts +1 -1
- package/src/wirings-stay-decoupled.test.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/src/wirings/ai-agent/index.ts +0 -65
- package/src/wirings/ai-scorer/index.ts +0 -24
- /package/src/wirings/{ai-agent/ai-agent-utils.ts → agent/agent-utils.ts} +0 -0
- /package/src/wirings/{ai-scorer/ai-scorer-sampling.ts → agent-scorer/agent-scorer-sampling.ts} +0 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
export function resolveMemoryServices(agent, singletonServices) {
|
|
3
|
+
const memoryConfig = agent.memory;
|
|
4
|
+
const storage = memoryConfig?.storage
|
|
5
|
+
? // The service is named by string in agent config, so the lookup cannot be
|
|
6
|
+
// checked — only the shape it is required to have.
|
|
7
|
+
singletonServices[memoryConfig.storage]
|
|
8
|
+
: singletonServices.agentStorage;
|
|
9
|
+
return { storage };
|
|
10
|
+
}
|
|
11
|
+
export function isWorkingMemoryEnabled(memoryConfig, storage) {
|
|
12
|
+
return !!memoryConfig?.workingMemory && !!storage;
|
|
13
|
+
}
|
|
14
|
+
export function deepMergeWorkingMemory(existing, updates) {
|
|
15
|
+
const result = { ...existing };
|
|
16
|
+
for (const key of Object.keys(updates)) {
|
|
17
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const value = updates[key];
|
|
21
|
+
if (value === null) {
|
|
22
|
+
delete result[key];
|
|
23
|
+
}
|
|
24
|
+
else if (typeof value === 'object' &&
|
|
25
|
+
!Array.isArray(value) &&
|
|
26
|
+
typeof result[key] === 'object' &&
|
|
27
|
+
result[key] !== null &&
|
|
28
|
+
!Array.isArray(result[key])) {
|
|
29
|
+
result[key] = deepMergeWorkingMemory(result[key], value);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
result[key] = value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
export function buildWorkingMemoryPrompt(currentState, jsonSchema) {
|
|
38
|
+
const parts = [];
|
|
39
|
+
if (jsonSchema?.properties) {
|
|
40
|
+
const props = jsonSchema.properties;
|
|
41
|
+
const fieldLines = Object.entries(props).map(([name, def]) => {
|
|
42
|
+
const type = def.type ?? 'unknown';
|
|
43
|
+
const desc = def.description ? ` - ${def.description}` : '';
|
|
44
|
+
return ` - ${name} (${type})${desc}`;
|
|
45
|
+
});
|
|
46
|
+
if (fieldLines.length > 0) {
|
|
47
|
+
parts.push(`Working memory fields:\n${fieldLines.join('\n')}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (currentState && Object.keys(currentState).length > 0) {
|
|
51
|
+
parts.push(`Current working memory:\n${JSON.stringify(currentState)}`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
parts.push('Current working memory: (empty)');
|
|
55
|
+
}
|
|
56
|
+
parts.push('When you learn new information, output a partial JSON update in <working_memory> tags. ' +
|
|
57
|
+
'Only include durable facts you have actually derived or the user has confirmed. ' +
|
|
58
|
+
'Do not output templates, placeholders, or narration. ' +
|
|
59
|
+
'Only include changed fields. Leave unknown fields untouched. Set a field to null to delete it.');
|
|
60
|
+
return parts.join('\n\n');
|
|
61
|
+
}
|
|
62
|
+
export async function loadContextMessages(memoryConfig, storage, input, workingMemoryJsonSchema) {
|
|
63
|
+
const contextMessages = [];
|
|
64
|
+
const workingMemoryStorage = isWorkingMemoryEnabled(memoryConfig, storage)
|
|
65
|
+
? storage
|
|
66
|
+
: undefined;
|
|
67
|
+
if (workingMemoryStorage) {
|
|
68
|
+
const workingMem = await workingMemoryStorage.getWorkingMemory(input.threadId, 'thread');
|
|
69
|
+
const prompt = buildWorkingMemoryPrompt(workingMem, workingMemoryJsonSchema);
|
|
70
|
+
contextMessages.push({
|
|
71
|
+
id: `wm-${randomUUID()}`,
|
|
72
|
+
role: 'system',
|
|
73
|
+
content: prompt,
|
|
74
|
+
createdAt: new Date(),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return contextMessages;
|
|
78
|
+
}
|
|
79
|
+
export async function saveMessages(storage, threadId, resourceId, memoryConfig, userMessage, result) {
|
|
80
|
+
const responseText = memoryConfig?.workingMemory
|
|
81
|
+
? extractWorkingMemory(result.text).cleanedText
|
|
82
|
+
: result.text;
|
|
83
|
+
if (storage) {
|
|
84
|
+
const newMessages = userMessage ? [userMessage] : [];
|
|
85
|
+
for (const step of result.steps) {
|
|
86
|
+
if (step.toolCalls?.length) {
|
|
87
|
+
const toolCallIds = step.toolCalls.map(() => randomUUID());
|
|
88
|
+
newMessages.push({
|
|
89
|
+
id: randomUUID(),
|
|
90
|
+
role: 'assistant',
|
|
91
|
+
toolCalls: step.toolCalls.map((tc, i) => ({
|
|
92
|
+
id: toolCallIds[i],
|
|
93
|
+
name: tc.name,
|
|
94
|
+
args: tc.args,
|
|
95
|
+
})),
|
|
96
|
+
createdAt: new Date(),
|
|
97
|
+
});
|
|
98
|
+
newMessages.push({
|
|
99
|
+
id: randomUUID(),
|
|
100
|
+
role: 'tool',
|
|
101
|
+
toolResults: step.toolCalls.map((tc, i) => ({
|
|
102
|
+
id: toolCallIds[i],
|
|
103
|
+
name: tc.name,
|
|
104
|
+
result: tc.result,
|
|
105
|
+
...(tc.error ? { error: tc.error } : {}),
|
|
106
|
+
})),
|
|
107
|
+
createdAt: new Date(),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const assistantContent = result.uiSpec != null
|
|
112
|
+
? [
|
|
113
|
+
...(responseText
|
|
114
|
+
? [{ type: 'text', text: responseText }]
|
|
115
|
+
: []),
|
|
116
|
+
{ type: 'generative-ui', spec: result.uiSpec },
|
|
117
|
+
]
|
|
118
|
+
: responseText;
|
|
119
|
+
newMessages.push({
|
|
120
|
+
id: randomUUID(),
|
|
121
|
+
role: 'assistant',
|
|
122
|
+
content: assistantContent || undefined,
|
|
123
|
+
createdAt: new Date(),
|
|
124
|
+
});
|
|
125
|
+
await storage.saveMessages(threadId, newMessages);
|
|
126
|
+
}
|
|
127
|
+
return responseText;
|
|
128
|
+
}
|
|
129
|
+
export function trimMessages(messages, maxTokenBudget = 100000) {
|
|
130
|
+
const sanitized = sanitizeToolMessages(messages);
|
|
131
|
+
let estimatedTokens = 0;
|
|
132
|
+
const result = [];
|
|
133
|
+
for (let i = sanitized.length - 1; i >= 0; i--) {
|
|
134
|
+
const msg = sanitized[i];
|
|
135
|
+
const msgTokens = estimateTokens(msg);
|
|
136
|
+
if (estimatedTokens + msgTokens > maxTokenBudget && result.length > 0) {
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
estimatedTokens += msgTokens;
|
|
140
|
+
result.unshift(msg);
|
|
141
|
+
}
|
|
142
|
+
if (result.length > 0 &&
|
|
143
|
+
result[0].role !== 'user' &&
|
|
144
|
+
result[0].role !== 'system') {
|
|
145
|
+
const firstUserIdx = result.findIndex((m) => m.role === 'user' || m.role === 'system');
|
|
146
|
+
if (firstUserIdx > 0) {
|
|
147
|
+
return result.slice(firstUserIdx);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function sanitizeToolMessages(messages) {
|
|
153
|
+
const result = [];
|
|
154
|
+
for (let i = 0; i < messages.length; i++) {
|
|
155
|
+
const msg = messages[i];
|
|
156
|
+
if (msg.role === 'assistant' && msg.toolCalls?.length) {
|
|
157
|
+
const next = messages[i + 1];
|
|
158
|
+
if (!next || next.role !== 'tool' || !next.toolResults?.length) {
|
|
159
|
+
if (msg.content) {
|
|
160
|
+
result.push({ ...msg, toolCalls: undefined });
|
|
161
|
+
}
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const toolCallIds = new Set(msg.toolCalls.map((tc) => tc.id));
|
|
165
|
+
const resultIds = new Set(next.toolResults.map((tr) => tr.id));
|
|
166
|
+
const allMatched = [...toolCallIds].every((id) => resultIds.has(id));
|
|
167
|
+
if (!allMatched) {
|
|
168
|
+
if (msg.content) {
|
|
169
|
+
result.push({ ...msg, toolCalls: undefined });
|
|
170
|
+
}
|
|
171
|
+
result.push({
|
|
172
|
+
...next,
|
|
173
|
+
toolResults: next.toolResults.filter((tr) => !toolCallIds.has(tr.id)) ||
|
|
174
|
+
undefined,
|
|
175
|
+
});
|
|
176
|
+
i++;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
result.push(msg);
|
|
181
|
+
}
|
|
182
|
+
return result.filter((m) => m.role !== 'tool' || (m.toolResults && m.toolResults.length > 0));
|
|
183
|
+
}
|
|
184
|
+
function estimateTokens(msg) {
|
|
185
|
+
let chars = 0;
|
|
186
|
+
if (msg.content) {
|
|
187
|
+
if (typeof msg.content === 'string') {
|
|
188
|
+
chars += msg.content.length;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
for (const part of msg.content) {
|
|
192
|
+
if (part.type === 'text')
|
|
193
|
+
chars += part.text.length;
|
|
194
|
+
else
|
|
195
|
+
chars += 1000;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (msg.toolCalls)
|
|
200
|
+
chars += JSON.stringify(msg.toolCalls).length;
|
|
201
|
+
if (msg.toolResults)
|
|
202
|
+
chars += JSON.stringify(msg.toolResults).length;
|
|
203
|
+
return Math.ceil(chars / 4);
|
|
204
|
+
}
|
|
205
|
+
export function parseWorkingMemory(text) {
|
|
206
|
+
const match = text.match(/<working_memory>([\s\S]*?)<\/working_memory>/);
|
|
207
|
+
if (!match)
|
|
208
|
+
return null;
|
|
209
|
+
try {
|
|
210
|
+
return JSON.parse(match[1].trim());
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
export function stripWorkingMemoryTags(text) {
|
|
217
|
+
return text.replace(/<working_memory>[\s\S]*?<\/working_memory>/g, '').trim();
|
|
218
|
+
}
|
|
219
|
+
export function extractWorkingMemory(text) {
|
|
220
|
+
const workingMemory = parseWorkingMemory(text);
|
|
221
|
+
return {
|
|
222
|
+
workingMemory,
|
|
223
|
+
cleanedText: workingMemory ? stripWorkingMemoryTags(text) : text,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function getPendingWorkingMemoryPrefixLength(text) {
|
|
227
|
+
const prefixes = ['<working_memory>', '</working_memory>'];
|
|
228
|
+
const lastLt = text.lastIndexOf('<');
|
|
229
|
+
if (lastLt === -1)
|
|
230
|
+
return 0;
|
|
231
|
+
const suffix = text.slice(lastLt);
|
|
232
|
+
for (const prefix of prefixes) {
|
|
233
|
+
if (prefix.startsWith(suffix)) {
|
|
234
|
+
return suffix.length;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return 0;
|
|
238
|
+
}
|
|
239
|
+
export function stripWorkingMemoryForStreaming(text) {
|
|
240
|
+
let output = '';
|
|
241
|
+
let cursor = 0;
|
|
242
|
+
while (cursor < text.length) {
|
|
243
|
+
const openIndex = text.indexOf('<working_memory>', cursor);
|
|
244
|
+
if (openIndex === -1) {
|
|
245
|
+
const tail = text.slice(cursor);
|
|
246
|
+
const pendingPrefixLength = getPendingWorkingMemoryPrefixLength(tail);
|
|
247
|
+
output +=
|
|
248
|
+
pendingPrefixLength > 0 ? tail.slice(0, -pendingPrefixLength) : tail;
|
|
249
|
+
return output;
|
|
250
|
+
}
|
|
251
|
+
output += text.slice(cursor, openIndex);
|
|
252
|
+
const closeIndex = text.indexOf('</working_memory>', openIndex);
|
|
253
|
+
if (closeIndex === -1) {
|
|
254
|
+
return output;
|
|
255
|
+
}
|
|
256
|
+
cursor = closeIndex + '</working_memory>'.length;
|
|
257
|
+
}
|
|
258
|
+
return output;
|
|
259
|
+
}
|
|
260
|
+
async function persistWorkingMemory(options, workingMemory) {
|
|
261
|
+
if (!options.storage)
|
|
262
|
+
return;
|
|
263
|
+
const existing = (await options.storage.getWorkingMemory(options.threadId, 'thread')) ?? {};
|
|
264
|
+
const merged = deepMergeWorkingMemory(existing, workingMemory);
|
|
265
|
+
if (options.schemaService && options.workingMemorySchemaName) {
|
|
266
|
+
try {
|
|
267
|
+
await options.schemaService.validateSchema(options.workingMemorySchemaName, merged);
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
270
|
+
options.logger?.warn(`Working memory validation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
await options.storage.saveWorkingMemory(options.threadId, 'thread', merged);
|
|
275
|
+
}
|
|
276
|
+
export function createWorkingMemoryMiddleware(options) {
|
|
277
|
+
return {
|
|
278
|
+
modifyOutputStream: async (_services, { event, state }) => {
|
|
279
|
+
// A streamed step ends at its `usage` event, or at `done` for a model
|
|
280
|
+
// that reports no usage. That is the last moment the unstripped text is
|
|
281
|
+
// still reachable: it lives only in `state.rawText`, because the strip
|
|
282
|
+
// below runs before anything downstream — including the channel that
|
|
283
|
+
// accumulates what `modifyOutput` would later be handed.
|
|
284
|
+
if (event.type === 'usage' || event.type === 'done') {
|
|
285
|
+
const { workingMemory } = extractWorkingMemory(state.rawText ?? '');
|
|
286
|
+
state.rawText = '';
|
|
287
|
+
state.emittedVisibleText = '';
|
|
288
|
+
if (workingMemory) {
|
|
289
|
+
await persistWorkingMemory(options, workingMemory);
|
|
290
|
+
}
|
|
291
|
+
return event;
|
|
292
|
+
}
|
|
293
|
+
if (event.type !== 'text-delta')
|
|
294
|
+
return event;
|
|
295
|
+
const rawText = `${state.rawText ?? ''}${event.text}`;
|
|
296
|
+
state.rawText = rawText;
|
|
297
|
+
const visibleText = stripWorkingMemoryForStreaming(rawText);
|
|
298
|
+
const emittedVisibleText = state.emittedVisibleText ?? '';
|
|
299
|
+
if (!visibleText.startsWith(emittedVisibleText)) {
|
|
300
|
+
state.emittedVisibleText = visibleText;
|
|
301
|
+
return { ...event, text: visibleText };
|
|
302
|
+
}
|
|
303
|
+
const delta = visibleText.slice(emittedVisibleText.length);
|
|
304
|
+
state.emittedVisibleText = visibleText;
|
|
305
|
+
if (!delta)
|
|
306
|
+
return null;
|
|
307
|
+
return { ...event, text: delta };
|
|
308
|
+
},
|
|
309
|
+
modifyOutput: async (_services, { text, messages }) => {
|
|
310
|
+
const { workingMemory, cleanedText } = extractWorkingMemory(text);
|
|
311
|
+
if (workingMemory) {
|
|
312
|
+
await persistWorkingMemory(options, workingMemory);
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
text: cleanedText,
|
|
316
|
+
messages,
|
|
317
|
+
};
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
export function getWorkingMemoryMiddleware(memoryConfig, storage, options) {
|
|
322
|
+
if (!isWorkingMemoryEnabled(memoryConfig, storage))
|
|
323
|
+
return [];
|
|
324
|
+
return [
|
|
325
|
+
createWorkingMemoryMiddleware({
|
|
326
|
+
storage,
|
|
327
|
+
threadId: options.threadId,
|
|
328
|
+
workingMemorySchemaName: options.workingMemorySchemaName,
|
|
329
|
+
logger: options.logger,
|
|
330
|
+
schemaService: options.schemaService,
|
|
331
|
+
}),
|
|
332
|
+
];
|
|
333
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a model name to a concrete `provider/model`. Aliases come from the
|
|
3
|
+
* `models` table in pikku.config.json; a name containing `/` is already
|
|
4
|
+
* concrete. Read from the main package, not the calling addon's — which model
|
|
5
|
+
* a tier points at is the hosting app's decision.
|
|
6
|
+
*/
|
|
7
|
+
export declare const resolveModelAlias: (model: string) => string;
|
|
8
|
+
export declare function resolveModelConfig(_agentName: string, agent: {
|
|
9
|
+
model: string;
|
|
10
|
+
temperature?: number;
|
|
11
|
+
maxSteps?: number;
|
|
12
|
+
}): {
|
|
13
|
+
model: string;
|
|
14
|
+
temperature?: number;
|
|
15
|
+
maxSteps?: number;
|
|
16
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// knowledge: decisions/internals/agent-model-config-stays-a-single-resolution-seam.md
|
|
2
|
+
import { pikkuState } from '../../pikku-state.js';
|
|
3
|
+
const isProviderQualified = (model) => model.includes('/');
|
|
4
|
+
/** `PIKKU_MODEL_ALIASES=cheap:openai/gpt-5-mini,tool:anthropic/claude-sonnet-5` */
|
|
5
|
+
const envAliases = () => {
|
|
6
|
+
const raw = process.env.PIKKU_MODEL_ALIASES;
|
|
7
|
+
if (!raw)
|
|
8
|
+
return {};
|
|
9
|
+
const aliases = {};
|
|
10
|
+
for (const entry of raw.split(',')) {
|
|
11
|
+
// First colon only — a model id may contain its own.
|
|
12
|
+
const separator = entry.indexOf(':');
|
|
13
|
+
if (separator === -1)
|
|
14
|
+
continue;
|
|
15
|
+
const alias = entry.slice(0, separator).trim();
|
|
16
|
+
const model = entry.slice(separator + 1).trim();
|
|
17
|
+
if (alias && model)
|
|
18
|
+
aliases[alias] = model;
|
|
19
|
+
}
|
|
20
|
+
return aliases;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Resolves a model name to a concrete `provider/model`. Aliases come from the
|
|
24
|
+
* `models` table in pikku.config.json; a name containing `/` is already
|
|
25
|
+
* concrete. Read from the main package, not the calling addon's — which model
|
|
26
|
+
* a tier points at is the hosting app's decision.
|
|
27
|
+
*/
|
|
28
|
+
export const resolveModelAlias = (model) => {
|
|
29
|
+
if (isProviderQualified(model))
|
|
30
|
+
return model;
|
|
31
|
+
const generated = pikkuState(null, 'agent', 'modelAliases');
|
|
32
|
+
const override = envAliases()[model];
|
|
33
|
+
const resolved = override ?? generated[model];
|
|
34
|
+
if (!resolved) {
|
|
35
|
+
const known = Object.keys({ ...generated, ...envAliases() }).sort();
|
|
36
|
+
throw new Error(`Unknown model alias '${model}'. ` +
|
|
37
|
+
(known.length
|
|
38
|
+
? `Known aliases: ${known.join(', ')}. `
|
|
39
|
+
: `No aliases are configured. `) +
|
|
40
|
+
`Add it to the "models" table in pikku.config.json, or name a ` +
|
|
41
|
+
`provider-qualified model such as 'openai/gpt-5-mini'.`);
|
|
42
|
+
}
|
|
43
|
+
return resolved;
|
|
44
|
+
};
|
|
45
|
+
export function resolveModelConfig(_agentName, agent) {
|
|
46
|
+
return {
|
|
47
|
+
model: resolveModelAlias(agent.model),
|
|
48
|
+
temperature: agent.temperature,
|
|
49
|
+
maxSteps: agent.maxSteps,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { CoreUserSession } from '../../types/core.types.js';
|
|
2
|
+
import type { CoreAgent, AgentInput, AgentToolDef, AgentMessage, AgentStreamChannel, PikkuAgentMiddlewareHooks, SessionScope } from './agent.types.js';
|
|
3
|
+
import type { AgentRunnerParams } from '../../services/agent-runner-service.js';
|
|
4
|
+
import { PikkuError } from '../../errors/error-handler.js';
|
|
5
|
+
import type { SessionService } from '../../services/user-session-service.js';
|
|
6
|
+
export type RunAgentParams = {
|
|
7
|
+
sessionService?: SessionService<CoreUserSession>;
|
|
8
|
+
/** Credential accessor for the current request — used to read per-user overrides (e.g. AI_API_KEY). */
|
|
9
|
+
getCredential?: <T = unknown>(name: string) => T | null | Promise<T | null>;
|
|
10
|
+
/** Ephemeral owner identity minted for a sessionless request; never client-supplied, never reused across requests. */
|
|
11
|
+
anonymousOwnerResourceId?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function resolveSessionPrincipal(params: RunAgentParams, sessionScope: SessionScope | undefined): string | undefined;
|
|
14
|
+
export declare function resolveOwnerResourceId(params: RunAgentParams, sessionScope: SessionScope | undefined, requestedResourceId: string): string;
|
|
15
|
+
export declare function assertResourcePrincipalOwner(params: RunAgentParams, sessionScope: SessionScope | undefined, storedResourceId: string, kind: 'thread' | 'run'): void;
|
|
16
|
+
export declare function agentSessionScope(agentName: string): SessionScope;
|
|
17
|
+
export declare function assertResourceOwner(ownerResourceId: string, storedResourceId: string, kind: 'thread' | 'run'): void;
|
|
18
|
+
export declare function sessionPrincipals(session: {
|
|
19
|
+
userId?: string;
|
|
20
|
+
orgId?: string;
|
|
21
|
+
} | undefined): string[];
|
|
22
|
+
export declare function isOwnedByPrincipal(storedResourceId: string, principal: string): boolean;
|
|
23
|
+
export declare function threadOwnerConstraint(session: {
|
|
24
|
+
userId?: string;
|
|
25
|
+
orgId?: string;
|
|
26
|
+
} | undefined): string[];
|
|
27
|
+
export declare function canAccessThread(storedResourceId: string, session: {
|
|
28
|
+
userId?: string;
|
|
29
|
+
orgId?: string;
|
|
30
|
+
} | undefined): boolean;
|
|
31
|
+
export type StreamAgentOptions = {
|
|
32
|
+
requiresToolApproval?: 'all' | 'explicit' | false;
|
|
33
|
+
onRunCreated?: (runId: string) => void;
|
|
34
|
+
};
|
|
35
|
+
export declare const APPROVAL_REQUIRED: unique symbol;
|
|
36
|
+
/**
|
|
37
|
+
* In-process brand proving a credential request was produced by pikku itself and
|
|
38
|
+
* not by tool output an attacker can influence. Never serialized — a value that
|
|
39
|
+
* has crossed a JSON boundary has lost the brand and is treated as untrusted.
|
|
40
|
+
*/
|
|
41
|
+
export declare const CREDENTIAL_REQUIRED: unique symbol;
|
|
42
|
+
export declare class ToolApprovalRequired extends PikkuError {
|
|
43
|
+
readonly toolCallId: string;
|
|
44
|
+
readonly toolName: string;
|
|
45
|
+
readonly args: unknown;
|
|
46
|
+
reason?: string;
|
|
47
|
+
readonly displayToolName?: string;
|
|
48
|
+
readonly displayArgs?: unknown;
|
|
49
|
+
readonly agentRunId?: string;
|
|
50
|
+
constructor(toolCallId: string, toolName: string, args: unknown, reason?: string, displayToolName?: string, displayArgs?: unknown, agentRunId?: string);
|
|
51
|
+
}
|
|
52
|
+
export declare class ToolCredentialRequired extends PikkuError {
|
|
53
|
+
readonly toolCallId: string;
|
|
54
|
+
readonly toolName: string;
|
|
55
|
+
readonly args: unknown;
|
|
56
|
+
readonly credentialName: string;
|
|
57
|
+
readonly credentialType: 'oauth2' | 'apikey';
|
|
58
|
+
readonly connectUrl?: string;
|
|
59
|
+
constructor(toolCallId: string, toolName: string, args: unknown, credentialName: string, credentialType: 'oauth2' | 'apikey', connectUrl?: string);
|
|
60
|
+
}
|
|
61
|
+
export interface AddonCredentialRequirement {
|
|
62
|
+
credentialName: string;
|
|
63
|
+
displayName: string;
|
|
64
|
+
addonNamespace: string;
|
|
65
|
+
type: 'wire';
|
|
66
|
+
oauth2: boolean;
|
|
67
|
+
}
|
|
68
|
+
export declare function getAddonCredentialRequirements(toolNames: string[]): AddonCredentialRequirement[];
|
|
69
|
+
export type StreamContext = {
|
|
70
|
+
channel: AgentStreamChannel;
|
|
71
|
+
options?: StreamAgentOptions;
|
|
72
|
+
delegateState?: {
|
|
73
|
+
delegated: boolean;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export declare const resolveAgent: (agentName: string) => {
|
|
77
|
+
agent: CoreAgent;
|
|
78
|
+
packageName: string | null;
|
|
79
|
+
resolvedName: string;
|
|
80
|
+
};
|
|
81
|
+
export declare function assertAgentAuthorized(agent: CoreAgent, params: RunAgentParams, packageName: string | null): Promise<void>;
|
|
82
|
+
export declare function buildInstructions(agentName: string, packageName: string | null): Promise<string>;
|
|
83
|
+
export type ScopedChannel = AgentStreamChannel & {
|
|
84
|
+
approvals: Array<{
|
|
85
|
+
toolCallId: string;
|
|
86
|
+
toolName: string;
|
|
87
|
+
args: unknown;
|
|
88
|
+
reason?: string;
|
|
89
|
+
runId: string;
|
|
90
|
+
}>;
|
|
91
|
+
};
|
|
92
|
+
export declare function createScopedChannel(parent: AgentStreamChannel, agentName: string, session: string): ScopedChannel;
|
|
93
|
+
export declare function buildSubAgentRunInput(message: string, threadId: string, resourceId: string, parentContext?: string): {
|
|
94
|
+
message: string;
|
|
95
|
+
threadId: string;
|
|
96
|
+
resourceId: string;
|
|
97
|
+
context?: string;
|
|
98
|
+
};
|
|
99
|
+
export declare function buildToolDefs(params: RunAgentParams, agentSessionMap: Map<string, string>, resourceId: string, agentName: string, packageName: string | null, streamContext?: StreamContext, agentMiddlewares?: PikkuAgentMiddlewareHooks[], agentMode?: 'delegate' | 'supervise', parentContext?: string): Promise<{
|
|
100
|
+
tools: AgentToolDef[];
|
|
101
|
+
missingRpcs: string[];
|
|
102
|
+
}>;
|
|
103
|
+
export declare function prepareAgentRun(agentName: string, input: AgentInput, params: RunAgentParams, agentSessionMap: Map<string, string>, streamContext?: StreamContext): Promise<{
|
|
104
|
+
agent: CoreAgent;
|
|
105
|
+
packageName: string | null;
|
|
106
|
+
resolvedName: string;
|
|
107
|
+
agentRunner: import("../../services/agent-runner-service.js").AgentRunnerService;
|
|
108
|
+
storage: import("../../index.js").AgentStorageService | undefined;
|
|
109
|
+
memoryConfig: import("./agent.types.js").AgentMemoryConfig | undefined;
|
|
110
|
+
threadId: string;
|
|
111
|
+
userMessage: AgentMessage;
|
|
112
|
+
runnerParams: AgentRunnerParams;
|
|
113
|
+
maxSteps: number;
|
|
114
|
+
missingRpcs: string[];
|
|
115
|
+
workingMemoryJsonSchema: any;
|
|
116
|
+
workingMemorySchemaName: string | null;
|
|
117
|
+
}>;
|