@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
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto'
|
|
2
2
|
import type { CoreSingletonServices } from '../../types/core.types.js'
|
|
3
3
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from './
|
|
10
|
-
import type {
|
|
4
|
+
CoreAgent,
|
|
5
|
+
AgentMemoryConfig,
|
|
6
|
+
AgentInput,
|
|
7
|
+
AgentStep,
|
|
8
|
+
AgentMessage,
|
|
9
|
+
} from './agent.types.js'
|
|
10
|
+
import type { AgentStorageService } from '../../services/agent-storage-service.js'
|
|
11
11
|
import type { Logger } from '../../services/logger.js'
|
|
12
12
|
import type { SchemaService } from '../../services/schema-service.js'
|
|
13
|
-
import type {
|
|
13
|
+
import type { PikkuAgentMiddlewareHooks } from './agent.types.js'
|
|
14
14
|
|
|
15
15
|
export function resolveMemoryServices(
|
|
16
|
-
agent:
|
|
16
|
+
agent: CoreAgent,
|
|
17
17
|
singletonServices: CoreSingletonServices
|
|
18
18
|
): {
|
|
19
|
-
storage:
|
|
19
|
+
storage: AgentStorageService | undefined
|
|
20
20
|
} {
|
|
21
21
|
const memoryConfig = agent.memory
|
|
22
22
|
const storage = memoryConfig?.storage
|
|
@@ -25,16 +25,16 @@ export function resolveMemoryServices(
|
|
|
25
25
|
(
|
|
26
26
|
singletonServices as unknown as Record<
|
|
27
27
|
string,
|
|
28
|
-
|
|
28
|
+
AgentStorageService | undefined
|
|
29
29
|
>
|
|
30
30
|
)[memoryConfig.storage]
|
|
31
|
-
: singletonServices.
|
|
31
|
+
: singletonServices.agentStorage
|
|
32
32
|
return { storage }
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function isWorkingMemoryEnabled(
|
|
36
|
-
memoryConfig:
|
|
37
|
-
storage:
|
|
36
|
+
memoryConfig: AgentMemoryConfig | undefined,
|
|
37
|
+
storage: AgentStorageService | undefined
|
|
38
38
|
): boolean {
|
|
39
39
|
return !!memoryConfig?.workingMemory && !!storage
|
|
40
40
|
}
|
|
@@ -107,12 +107,12 @@ export function buildWorkingMemoryPrompt(
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
export async function loadContextMessages(
|
|
110
|
-
memoryConfig:
|
|
111
|
-
storage:
|
|
112
|
-
input:
|
|
110
|
+
memoryConfig: AgentMemoryConfig | undefined,
|
|
111
|
+
storage: AgentStorageService | undefined,
|
|
112
|
+
input: AgentInput,
|
|
113
113
|
workingMemoryJsonSchema?: Record<string, unknown>
|
|
114
|
-
): Promise<
|
|
115
|
-
const contextMessages:
|
|
114
|
+
): Promise<AgentMessage[]> {
|
|
115
|
+
const contextMessages: AgentMessage[] = []
|
|
116
116
|
|
|
117
117
|
const workingMemoryStorage = isWorkingMemoryEnabled(memoryConfig, storage)
|
|
118
118
|
? storage
|
|
@@ -136,15 +136,15 @@ export async function loadContextMessages(
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
export async function saveMessages(
|
|
139
|
-
storage:
|
|
139
|
+
storage: AgentStorageService | undefined,
|
|
140
140
|
threadId: string,
|
|
141
141
|
resourceId: string,
|
|
142
|
-
memoryConfig:
|
|
143
|
-
userMessage:
|
|
142
|
+
memoryConfig: AgentMemoryConfig | undefined,
|
|
143
|
+
userMessage: AgentMessage | null | undefined,
|
|
144
144
|
result: {
|
|
145
145
|
text: string
|
|
146
146
|
uiSpec?: unknown
|
|
147
|
-
steps: Pick<
|
|
147
|
+
steps: Pick<AgentStep, 'toolCalls'>[]
|
|
148
148
|
}
|
|
149
149
|
): Promise<string> {
|
|
150
150
|
const responseText = memoryConfig?.workingMemory
|
|
@@ -152,7 +152,7 @@ export async function saveMessages(
|
|
|
152
152
|
: result.text
|
|
153
153
|
|
|
154
154
|
if (storage) {
|
|
155
|
-
const newMessages:
|
|
155
|
+
const newMessages: AgentMessage[] = userMessage ? [userMessage] : []
|
|
156
156
|
|
|
157
157
|
for (const step of result.steps) {
|
|
158
158
|
if (step.toolCalls?.length) {
|
|
@@ -205,13 +205,13 @@ export async function saveMessages(
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
export function trimMessages(
|
|
208
|
-
messages:
|
|
208
|
+
messages: AgentMessage[],
|
|
209
209
|
maxTokenBudget: number = 100000
|
|
210
|
-
):
|
|
210
|
+
): AgentMessage[] {
|
|
211
211
|
const sanitized = sanitizeToolMessages(messages)
|
|
212
212
|
|
|
213
213
|
let estimatedTokens = 0
|
|
214
|
-
const result:
|
|
214
|
+
const result: AgentMessage[] = []
|
|
215
215
|
|
|
216
216
|
for (let i = sanitized.length - 1; i >= 0; i--) {
|
|
217
217
|
const msg = sanitized[i]
|
|
@@ -239,8 +239,8 @@ export function trimMessages(
|
|
|
239
239
|
return result
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
function sanitizeToolMessages(messages:
|
|
243
|
-
const result:
|
|
242
|
+
function sanitizeToolMessages(messages: AgentMessage[]): AgentMessage[] {
|
|
243
|
+
const result: AgentMessage[] = []
|
|
244
244
|
|
|
245
245
|
for (let i = 0; i < messages.length; i++) {
|
|
246
246
|
const msg = messages[i]
|
|
@@ -281,7 +281,7 @@ function sanitizeToolMessages(messages: AIMessage[]): AIMessage[] {
|
|
|
281
281
|
)
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
function estimateTokens(msg:
|
|
284
|
+
function estimateTokens(msg: AgentMessage): number {
|
|
285
285
|
let chars = 0
|
|
286
286
|
if (msg.content) {
|
|
287
287
|
if (typeof msg.content === 'string') {
|
|
@@ -368,7 +368,7 @@ export function stripWorkingMemoryForStreaming(text: string): string {
|
|
|
368
368
|
|
|
369
369
|
async function persistWorkingMemory(
|
|
370
370
|
options: {
|
|
371
|
-
storage?:
|
|
371
|
+
storage?: AgentStorageService
|
|
372
372
|
threadId: string
|
|
373
373
|
workingMemorySchemaName?: string | null
|
|
374
374
|
logger?: Logger
|
|
@@ -400,12 +400,12 @@ async function persistWorkingMemory(
|
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
export function createWorkingMemoryMiddleware(options: {
|
|
403
|
-
storage?:
|
|
403
|
+
storage?: AgentStorageService
|
|
404
404
|
threadId: string
|
|
405
405
|
workingMemorySchemaName?: string | null
|
|
406
406
|
logger?: Logger
|
|
407
407
|
schemaService?: SchemaService
|
|
408
|
-
}):
|
|
408
|
+
}): PikkuAgentMiddlewareHooks<{
|
|
409
409
|
rawText?: string
|
|
410
410
|
emittedVisibleText?: string
|
|
411
411
|
}> {
|
|
@@ -459,15 +459,15 @@ export function createWorkingMemoryMiddleware(options: {
|
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
export function getWorkingMemoryMiddleware(
|
|
462
|
-
memoryConfig:
|
|
463
|
-
storage:
|
|
462
|
+
memoryConfig: AgentMemoryConfig | undefined,
|
|
463
|
+
storage: AgentStorageService | undefined,
|
|
464
464
|
options: {
|
|
465
465
|
threadId: string
|
|
466
466
|
workingMemorySchemaName?: string | null
|
|
467
467
|
logger?: Logger
|
|
468
468
|
schemaService?: SchemaService
|
|
469
469
|
}
|
|
470
|
-
):
|
|
470
|
+
): PikkuAgentMiddlewareHooks[] {
|
|
471
471
|
if (!isWorkingMemoryEnabled(memoryConfig, storage)) return []
|
|
472
472
|
|
|
473
473
|
return [
|
package/src/wirings/{ai-agent/ai-agent-model-config.test.ts → agent/agent-model-config.test.ts}
RENAMED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { describe, test, beforeEach, afterEach } from 'node:test'
|
|
2
2
|
import assert from 'node:assert'
|
|
3
|
-
import {
|
|
4
|
-
resolveModelAlias,
|
|
5
|
-
resolveModelConfig,
|
|
6
|
-
} from './ai-agent-model-config.js'
|
|
3
|
+
import { resolveModelAlias, resolveModelConfig } from './agent-model-config.js'
|
|
7
4
|
import { pikkuState, resetPikkuState } from '../../pikku-state.js'
|
|
8
5
|
|
|
9
6
|
const setAliases = (aliases: Record<string, string>) =>
|
|
@@ -81,7 +78,7 @@ describe('resolveModelAlias', () => {
|
|
|
81
78
|
test('an env override splits on the first colon only', () => {
|
|
82
79
|
// A model id may itself contain a colon — `ollama/qwen2.5:7b` is the shape
|
|
83
80
|
// the runner's own error message cites. It stays provider-qualified so the
|
|
84
|
-
// resolved value is one `
|
|
81
|
+
// resolved value is one `VercelAgentRunner.parseModel` would accept; a
|
|
85
82
|
// bare `bedrock:nova-lite:1` would pass here and fail the moment anything
|
|
86
83
|
// tried to use it.
|
|
87
84
|
process.env.PIKKU_MODEL_ALIASES = 'cheap:ollama/qwen2.5:7b'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// knowledge: decisions/internals/
|
|
1
|
+
// knowledge: decisions/internals/agent-model-config-stays-a-single-resolution-seam.md
|
|
2
2
|
import { pikkuState } from '../../pikku-state.js'
|
|
3
3
|
|
|
4
4
|
const isProviderQualified = (model: string) => model.includes('/')
|
|
@@ -18,22 +18,22 @@ import {
|
|
|
18
18
|
resolveOwnerResourceId,
|
|
19
19
|
sessionPrincipals,
|
|
20
20
|
threadOwnerConstraint,
|
|
21
|
-
} from './
|
|
21
|
+
} from './agent-prepare.js'
|
|
22
22
|
import { ForbiddenError, MissingCredentialError } from '../../errors/errors.js'
|
|
23
23
|
import { pikkuAuth } from '../../function/functions.types.js'
|
|
24
24
|
import type {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} from './
|
|
25
|
+
AgentStreamChannel,
|
|
26
|
+
AgentStreamEvent,
|
|
27
|
+
CoreAgent,
|
|
28
|
+
PikkuAgentMiddlewareHooks,
|
|
29
|
+
} from './agent.types.js'
|
|
30
30
|
|
|
31
31
|
beforeEach(() => {
|
|
32
32
|
resetPikkuState()
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
const addAgent = (agentName: string, overrides: Partial<
|
|
36
|
-
const agent:
|
|
35
|
+
const addAgent = (agentName: string, overrides: Partial<CoreAgent> = {}) => {
|
|
36
|
+
const agent: CoreAgent = {
|
|
37
37
|
name: agentName,
|
|
38
38
|
description: `${agentName} description`,
|
|
39
39
|
goal: `${agentName} goal`,
|
|
@@ -51,7 +51,7 @@ const addAgent = (agentName: string, overrides: Partial<CoreAIAgent> = {}) => {
|
|
|
51
51
|
} as any
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
describe('
|
|
54
|
+
describe('agent-prepare', () => {
|
|
55
55
|
test('getAddonCredentialRequirements returns deduplicated wire oauth credentials', () => {
|
|
56
56
|
pikkuState(null, 'addons', 'packages').set('github', {
|
|
57
57
|
package: '@test/github-addon',
|
|
@@ -88,7 +88,7 @@ describe('ai-agent-prepare', () => {
|
|
|
88
88
|
test('resolveAgent resolves root and addon agents and rejects missing names', () => {
|
|
89
89
|
addAgent('root-agent')
|
|
90
90
|
|
|
91
|
-
const addonAgent:
|
|
91
|
+
const addonAgent: CoreAgent = {
|
|
92
92
|
name: 'addon-agent',
|
|
93
93
|
description: 'addon',
|
|
94
94
|
goal: 'addon goal',
|
|
@@ -164,13 +164,13 @@ describe('ai-agent-prepare', () => {
|
|
|
164
164
|
})
|
|
165
165
|
|
|
166
166
|
test('createScopedChannel forwards stream events, captures approvals, and suppresses done', () => {
|
|
167
|
-
const events:
|
|
167
|
+
const events: AgentStreamEvent[] = []
|
|
168
168
|
const channel = createScopedChannel(
|
|
169
169
|
{
|
|
170
170
|
channelId: 'root',
|
|
171
171
|
openingData: undefined,
|
|
172
172
|
state: 'open',
|
|
173
|
-
send: (event:
|
|
173
|
+
send: (event: AgentStreamEvent) => {
|
|
174
174
|
events.push(event)
|
|
175
175
|
},
|
|
176
176
|
sendBinary: () => {},
|
|
@@ -178,12 +178,12 @@ describe('ai-agent-prepare', () => {
|
|
|
178
178
|
setState: () => {},
|
|
179
179
|
getState: () => 'open',
|
|
180
180
|
clearState: () => {},
|
|
181
|
-
} as
|
|
181
|
+
} as AgentStreamChannel,
|
|
182
182
|
'sub-agent',
|
|
183
183
|
'session-1'
|
|
184
184
|
)
|
|
185
185
|
|
|
186
|
-
channel.send({ type: 'text-delta', text: 'hello' } as
|
|
186
|
+
channel.send({ type: 'text-delta', text: 'hello' } as AgentStreamEvent)
|
|
187
187
|
channel.send({
|
|
188
188
|
type: 'approval-request',
|
|
189
189
|
toolCallId: 'tc-1',
|
|
@@ -191,8 +191,8 @@ describe('ai-agent-prepare', () => {
|
|
|
191
191
|
args: { x: 1 },
|
|
192
192
|
reason: 'Delete todo "x"',
|
|
193
193
|
runId: 'run-1',
|
|
194
|
-
} as
|
|
195
|
-
channel.send({ type: 'done' } as
|
|
194
|
+
} as AgentStreamEvent)
|
|
195
|
+
channel.send({ type: 'done' } as AgentStreamEvent)
|
|
196
196
|
|
|
197
197
|
assert.equal(events.length, 1)
|
|
198
198
|
assert.equal(events[0].type, 'text-delta')
|
|
@@ -232,7 +232,7 @@ describe('ai-agent-prepare', () => {
|
|
|
232
232
|
|
|
233
233
|
const beforeCalls: unknown[] = []
|
|
234
234
|
const afterCalls: unknown[] = []
|
|
235
|
-
const middlewares:
|
|
235
|
+
const middlewares: PikkuAgentMiddlewareHooks[] = [
|
|
236
236
|
{
|
|
237
237
|
beforeToolCall: async (_services, ctx) => {
|
|
238
238
|
beforeCalls.push(ctx)
|
|
@@ -333,7 +333,7 @@ describe('ai-agent-prepare', () => {
|
|
|
333
333
|
)
|
|
334
334
|
})
|
|
335
335
|
|
|
336
|
-
test('buildToolDefs logs a tool execute() failure even without
|
|
336
|
+
test('buildToolDefs logs a tool execute() failure even without agentMiddleware hooks, then rethrows', async () => {
|
|
337
337
|
addAgent('ops-agent')
|
|
338
338
|
pikkuState(null, 'agent', 'agentsMeta')['ops-agent'] = {
|
|
339
339
|
...pikkuState(null, 'agent', 'agentsMeta')['ops-agent'],
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { PikkuRawWire, CoreUserSession } from '../../types/core.types.js'
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
CoreAgent,
|
|
4
|
+
AgentInput,
|
|
5
|
+
AgentToolDef,
|
|
6
|
+
AgentContentPart,
|
|
7
|
+
AgentMessage,
|
|
8
|
+
AgentStreamChannel,
|
|
9
|
+
AgentStreamEvent,
|
|
10
|
+
PikkuAgentMiddlewareHooks,
|
|
11
11
|
SessionScope,
|
|
12
|
-
} from './
|
|
13
|
-
import type {
|
|
12
|
+
} from './agent.types.js'
|
|
13
|
+
import type { AgentRunnerParams } from '../../services/agent-runner-service.js'
|
|
14
14
|
import { PikkuError } from '../../errors/error-handler.js'
|
|
15
15
|
import {
|
|
16
16
|
checkAuthPermissions,
|
|
@@ -23,10 +23,10 @@ import { verifyScopes } from '../../scopes.js'
|
|
|
23
23
|
import { pikkuState, getSingletonServices } from '../../pikku-state.js'
|
|
24
24
|
import { createMiddlewareSessionWireProps } from '../../services/user-session-service.js'
|
|
25
25
|
import type { SessionService } from '../../services/user-session-service.js'
|
|
26
|
-
import { randomUUID } from './
|
|
27
|
-
import { awaitPendingInterruptNote } from './
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
26
|
+
import { randomUUID } from './agent-utils.js'
|
|
27
|
+
import { awaitPendingInterruptNote } from './agent-interrupt.js'
|
|
28
|
+
import { streamAgent } from './agent-stream.js'
|
|
29
|
+
import { runAgent } from './agent-runner.js'
|
|
30
30
|
import {
|
|
31
31
|
resolveNamespace,
|
|
32
32
|
ContextAwareRPCService,
|
|
@@ -36,10 +36,10 @@ import {
|
|
|
36
36
|
resolveMemoryServices,
|
|
37
37
|
loadContextMessages,
|
|
38
38
|
trimMessages,
|
|
39
|
-
} from './
|
|
40
|
-
import { resolveModelConfig } from './
|
|
39
|
+
} from './agent-memory.js'
|
|
40
|
+
import { resolveModelConfig } from './agent-model-config.js'
|
|
41
41
|
|
|
42
|
-
export type
|
|
42
|
+
export type RunAgentParams = {
|
|
43
43
|
sessionService?: SessionService<CoreUserSession>
|
|
44
44
|
/** Credential accessor for the current request — used to read per-user overrides (e.g. AI_API_KEY). */
|
|
45
45
|
getCredential?: <T = unknown>(name: string) => T | null | Promise<T | null>
|
|
@@ -48,7 +48,7 @@ export type RunAIAgentParams = {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export function resolveSessionPrincipal(
|
|
51
|
-
params:
|
|
51
|
+
params: RunAgentParams,
|
|
52
52
|
sessionScope: SessionScope | undefined
|
|
53
53
|
): string | undefined {
|
|
54
54
|
const session = params.sessionService?.get()
|
|
@@ -64,7 +64,7 @@ export function resolveSessionPrincipal(
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export function resolveOwnerResourceId(
|
|
67
|
-
params:
|
|
67
|
+
params: RunAgentParams,
|
|
68
68
|
sessionScope: SessionScope | undefined,
|
|
69
69
|
requestedResourceId: string
|
|
70
70
|
): string {
|
|
@@ -85,7 +85,7 @@ export function resolveOwnerResourceId(
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export function assertResourcePrincipalOwner(
|
|
88
|
-
params:
|
|
88
|
+
params: RunAgentParams,
|
|
89
89
|
sessionScope: SessionScope | undefined,
|
|
90
90
|
storedResourceId: string,
|
|
91
91
|
kind: 'thread' | 'run'
|
|
@@ -145,7 +145,7 @@ export function canAccessThread(
|
|
|
145
145
|
)
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
export type
|
|
148
|
+
export type StreamAgentOptions = {
|
|
149
149
|
requiresToolApproval?: 'all' | 'explicit' | false
|
|
150
150
|
onRunCreated?: (runId: string) => void
|
|
151
151
|
}
|
|
@@ -258,14 +258,14 @@ export function getAddonCredentialRequirements(
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
export type StreamContext = {
|
|
261
|
-
channel:
|
|
262
|
-
options?:
|
|
261
|
+
channel: AgentStreamChannel
|
|
262
|
+
options?: StreamAgentOptions
|
|
263
263
|
delegateState?: { delegated: boolean }
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
export const resolveAgent = (
|
|
267
267
|
agentName: string
|
|
268
|
-
): { agent:
|
|
268
|
+
): { agent: CoreAgent; packageName: string | null; resolvedName: string } => {
|
|
269
269
|
if (!agentName) {
|
|
270
270
|
console.error(
|
|
271
271
|
'[resolveAgent] agentName is undefined/null! Stack:',
|
|
@@ -302,8 +302,8 @@ export const resolveAgent = (
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
export async function assertAgentAuthorized(
|
|
305
|
-
agent:
|
|
306
|
-
params:
|
|
305
|
+
agent: CoreAgent,
|
|
306
|
+
params: RunAgentParams,
|
|
307
307
|
packageName: string | null
|
|
308
308
|
): Promise<void> {
|
|
309
309
|
const session = params.sessionService
|
|
@@ -363,7 +363,7 @@ export async function buildInstructions(
|
|
|
363
363
|
return instructions
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
export type ScopedChannel =
|
|
366
|
+
export type ScopedChannel = AgentStreamChannel & {
|
|
367
367
|
approvals: Array<{
|
|
368
368
|
toolCallId: string
|
|
369
369
|
toolName: string
|
|
@@ -374,7 +374,7 @@ export type ScopedChannel = AIStreamChannel & {
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
export function createScopedChannel(
|
|
377
|
-
parent:
|
|
377
|
+
parent: AgentStreamChannel,
|
|
378
378
|
agentName: string,
|
|
379
379
|
session: string
|
|
380
380
|
): ScopedChannel {
|
|
@@ -391,7 +391,7 @@ export function createScopedChannel(
|
|
|
391
391
|
},
|
|
392
392
|
close: () => {},
|
|
393
393
|
sendBinary: (data) => parent.sendBinary(data),
|
|
394
|
-
send: (event:
|
|
394
|
+
send: (event: AgentStreamEvent) => {
|
|
395
395
|
if (event.type === 'done') return
|
|
396
396
|
if (event.type === 'approval-request') {
|
|
397
397
|
capturedApprovals.push({
|
|
@@ -412,7 +412,7 @@ export function createScopedChannel(
|
|
|
412
412
|
event.type === 'usage' ||
|
|
413
413
|
event.type === 'error'
|
|
414
414
|
) {
|
|
415
|
-
parent.send({ ...event, agent: agentName, session } as
|
|
415
|
+
parent.send({ ...event, agent: agentName, session } as AgentStreamEvent)
|
|
416
416
|
} else {
|
|
417
417
|
parent.send(event)
|
|
418
418
|
}
|
|
@@ -434,18 +434,18 @@ export function buildSubAgentRunInput(
|
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
export async function buildToolDefs(
|
|
437
|
-
params:
|
|
437
|
+
params: RunAgentParams,
|
|
438
438
|
agentSessionMap: Map<string, string>,
|
|
439
439
|
resourceId: string,
|
|
440
440
|
agentName: string,
|
|
441
441
|
packageName: string | null,
|
|
442
442
|
streamContext?: StreamContext,
|
|
443
|
-
|
|
443
|
+
agentMiddlewares?: PikkuAgentMiddlewareHooks[],
|
|
444
444
|
agentMode?: 'delegate' | 'supervise',
|
|
445
445
|
parentContext?: string
|
|
446
|
-
): Promise<{ tools:
|
|
446
|
+
): Promise<{ tools: AgentToolDef[]; missingRpcs: string[] }> {
|
|
447
447
|
const singletonServices = getSingletonServices()
|
|
448
|
-
const tools:
|
|
448
|
+
const tools: AgentToolDef[] = []
|
|
449
449
|
const missingRpcs: string[] = []
|
|
450
450
|
const approvalPolicy =
|
|
451
451
|
streamContext?.options?.requiresToolApproval ?? 'explicit'
|
|
@@ -678,7 +678,7 @@ export async function buildToolDefs(
|
|
|
678
678
|
? subChannel
|
|
679
679
|
: {
|
|
680
680
|
...subChannel,
|
|
681
|
-
send: (event:
|
|
681
|
+
send: (event: AgentStreamEvent) => {
|
|
682
682
|
if (
|
|
683
683
|
event.type === 'text-delta' ||
|
|
684
684
|
event.type === 'reasoning-delta'
|
|
@@ -687,7 +687,7 @@ export async function buildToolDefs(
|
|
|
687
687
|
subChannel.send(event)
|
|
688
688
|
},
|
|
689
689
|
}
|
|
690
|
-
const resultText = await
|
|
690
|
+
const resultText = await streamAgent(
|
|
691
691
|
subAgentName,
|
|
692
692
|
buildSubAgentRunInput(
|
|
693
693
|
message,
|
|
@@ -719,7 +719,7 @@ export async function buildToolDefs(
|
|
|
719
719
|
return resultText
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
-
const result = await
|
|
722
|
+
const result = await runAgent(
|
|
723
723
|
subAgentName,
|
|
724
724
|
buildSubAgentRunInput(message, threadId, resourceId, parentContext),
|
|
725
725
|
params,
|
|
@@ -830,7 +830,7 @@ export async function buildToolDefs(
|
|
|
830
830
|
}
|
|
831
831
|
}
|
|
832
832
|
|
|
833
|
-
const hasToolHooks =
|
|
833
|
+
const hasToolHooks = agentMiddlewares?.some(
|
|
834
834
|
(mw) => mw.beforeToolCall || mw.afterToolCall
|
|
835
835
|
)
|
|
836
836
|
if (hasToolHooks) {
|
|
@@ -840,7 +840,7 @@ export async function buildToolDefs(
|
|
|
840
840
|
const toolCallId = randomUUID()
|
|
841
841
|
let args = (toolInput ?? {}) as Record<string, unknown>
|
|
842
842
|
|
|
843
|
-
for (const mw of
|
|
843
|
+
for (const mw of agentMiddlewares!) {
|
|
844
844
|
if (mw.beforeToolCall) {
|
|
845
845
|
const beforeResult = await mw.beforeToolCall(singletonServices, {
|
|
846
846
|
toolName: tool.name,
|
|
@@ -865,8 +865,8 @@ export async function buildToolDefs(
|
|
|
865
865
|
}
|
|
866
866
|
const durationMs = Date.now() - startTime
|
|
867
867
|
|
|
868
|
-
for (let i =
|
|
869
|
-
const mw =
|
|
868
|
+
for (let i = agentMiddlewares!.length - 1; i >= 0; i--) {
|
|
869
|
+
const mw = agentMiddlewares![i]
|
|
870
870
|
if (mw.afterToolCall) {
|
|
871
871
|
const afterResult = await mw.afterToolCall(singletonServices, {
|
|
872
872
|
toolName: tool.name,
|
|
@@ -892,8 +892,8 @@ export async function buildToolDefs(
|
|
|
892
892
|
|
|
893
893
|
export async function prepareAgentRun(
|
|
894
894
|
agentName: string,
|
|
895
|
-
input:
|
|
896
|
-
params:
|
|
895
|
+
input: AgentInput,
|
|
896
|
+
params: RunAgentParams,
|
|
897
897
|
agentSessionMap: Map<string, string>,
|
|
898
898
|
streamContext?: StreamContext
|
|
899
899
|
) {
|
|
@@ -902,7 +902,7 @@ export async function prepareAgentRun(
|
|
|
902
902
|
|
|
903
903
|
await assertAgentAuthorized(agent, params, packageName)
|
|
904
904
|
|
|
905
|
-
let agentRunner = singletonServices.
|
|
905
|
+
let agentRunner = singletonServices.agentRunner
|
|
906
906
|
if (!agentRunner) {
|
|
907
907
|
throw new AIProviderNotConfiguredError()
|
|
908
908
|
}
|
|
@@ -946,7 +946,7 @@ export async function prepareAgentRun(
|
|
|
946
946
|
}
|
|
947
947
|
}
|
|
948
948
|
|
|
949
|
-
let messages:
|
|
949
|
+
let messages: AgentMessage[] = []
|
|
950
950
|
if (storage) {
|
|
951
951
|
// knowledge: decisions/internals/agent-context-waits-for-a-tool-result-still-being-written.md
|
|
952
952
|
await awaitPendingInterruptNote(threadId)
|
|
@@ -962,7 +962,7 @@ export async function prepareAgentRun(
|
|
|
962
962
|
workingMemoryJsonSchema
|
|
963
963
|
)
|
|
964
964
|
|
|
965
|
-
const userContent:
|
|
965
|
+
const userContent: AgentMessage['content'] = input.attachments?.length
|
|
966
966
|
? [
|
|
967
967
|
// knowledge: decisions/internals/an-empty-text-part-is-omitted-from-an-agent-message.md
|
|
968
968
|
...(input.message
|
|
@@ -976,12 +976,12 @@ export async function prepareAgentRun(
|
|
|
976
976
|
url: a.url,
|
|
977
977
|
mediaType: a.mediaType,
|
|
978
978
|
...(a.filename ? { filename: a.filename } : {}),
|
|
979
|
-
}) as
|
|
979
|
+
}) as AgentContentPart
|
|
980
980
|
),
|
|
981
981
|
]
|
|
982
982
|
: input.message
|
|
983
983
|
|
|
984
|
-
const userMessage:
|
|
984
|
+
const userMessage: AgentMessage = {
|
|
985
985
|
id: randomUUID(),
|
|
986
986
|
role: 'user',
|
|
987
987
|
content: userContent,
|
|
@@ -991,7 +991,8 @@ export async function prepareAgentRun(
|
|
|
991
991
|
const allMessages = [...contextMessages, ...messages, userMessage]
|
|
992
992
|
const trimmedMessages = trimMessages(allMessages)
|
|
993
993
|
|
|
994
|
-
const
|
|
994
|
+
const agentMiddlewares: PikkuAgentMiddlewareHooks[] =
|
|
995
|
+
agent.agentMiddleware ?? []
|
|
995
996
|
|
|
996
997
|
const { tools, missingRpcs } = await buildToolDefs(
|
|
997
998
|
params,
|
|
@@ -1000,7 +1001,7 @@ export async function prepareAgentRun(
|
|
|
1000
1001
|
resolvedName,
|
|
1001
1002
|
packageName,
|
|
1002
1003
|
streamContext,
|
|
1003
|
-
|
|
1004
|
+
agentMiddlewares,
|
|
1004
1005
|
agent.agentMode,
|
|
1005
1006
|
input.context
|
|
1006
1007
|
)
|
|
@@ -1024,7 +1025,7 @@ export async function prepareAgentRun(
|
|
|
1024
1025
|
|
|
1025
1026
|
const maxSteps = resolved.maxSteps ?? 10
|
|
1026
1027
|
|
|
1027
|
-
const runnerParams:
|
|
1028
|
+
const runnerParams: AgentRunnerParams = {
|
|
1028
1029
|
model: resolved.model,
|
|
1029
1030
|
temperature: resolved.temperature,
|
|
1030
1031
|
instructions,
|