@pikku/core 0.12.82 → 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 +101 -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 +9 -10
- package/dist/services/index.js +3 -3
- package/dist/services/meta-service.d.ts +5 -4
- 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 +12 -11
- package/dist/types/core.types.js +1 -1
- package/dist/types/state.types.d.ts +11 -6
- 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/ai-agent-prepare.js +2 -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/addon-runner.d.ts +4 -0
- package/dist/wirings/rpc/addon-runner.js +14 -2
- package/dist/wirings/rpc/rpc-runner.d.ts +1 -1
- package/dist/wirings/rpc/rpc-runner.js +4 -2
- package/dist/wirings/rpc/rpc-types.d.ts +5 -1
- package/dist/wirings/rpc/wire-addon.d.ts +12 -0
- package/dist/wirings/rpc/wire-addon.js +4 -0
- 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/feature.d.ts +2 -1
- package/dist/wirings/workflow/index.d.ts +3 -14
- package/dist/wirings/workflow/index.js +0 -8
- package/dist/wirings/workflow/pikku-scenario-service.d.ts +10 -0
- package/dist/wirings/workflow/pikku-scenario-service.js +9 -0
- package/dist/wirings/workflow/run-timeline.d.ts +1 -2
- package/dist/wirings/workflow/scenario.types.d.ts +37 -0
- package/dist/wirings/workflow/scenario.types.js +1 -0
- package/dist/wirings/workflow/workflow.types.d.ts +2 -37
- 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 -4
- 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 +183 -91
- 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 +13 -24
- package/src/services/meta-service.ts +5 -7
- 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 +13 -13
- package/src/types/state.types.ts +11 -10
- 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} +54 -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/addon-runner.ts +31 -3
- package/src/wirings/rpc/addon-secrets.test.ts +130 -0
- package/src/wirings/rpc/rpc-runner.ts +4 -2
- package/src/wirings/rpc/rpc-types.ts +5 -1
- package/src/wirings/rpc/wire-addon.ts +16 -0
- 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/feature.ts +2 -5
- package/src/wirings/workflow/index.ts +1 -49
- package/src/wirings/workflow/pikku-scenario-service.ts +21 -1
- package/src/wirings/workflow/run-timeline.ts +1 -1
- package/src/wirings/workflow/scenario.types.ts +63 -0
- package/src/wirings/workflow/workflow.types.ts +1 -54
- 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,625 @@
|
|
|
1
|
+
import type { CorePermissionGroup, CorePikkuPermission } from '../../function/functions.types.js';
|
|
2
|
+
import type { CorePikkuMiddleware, MiddlewareMetadata, PermissionMetadata } from '../../types/core.types.js';
|
|
3
|
+
import type { AIProviderOptions } from '../../services/agent-runner-service.js';
|
|
4
|
+
import type { PikkuChannel } from '../channel/channel.types.js';
|
|
5
|
+
import type { CorePikkuChannelMiddleware } from '../channel/channel.types.js';
|
|
6
|
+
import type { ApprovalPolicy } from '../channel/channel-rpc.js';
|
|
7
|
+
export interface AgentThread {
|
|
8
|
+
id: string;
|
|
9
|
+
resourceId: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
updatedAt: Date;
|
|
14
|
+
}
|
|
15
|
+
export type AgentContentPart = {
|
|
16
|
+
type: 'text';
|
|
17
|
+
text: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'image';
|
|
20
|
+
data?: string;
|
|
21
|
+
url?: string;
|
|
22
|
+
mediaType?: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: 'file';
|
|
25
|
+
data?: string;
|
|
26
|
+
url?: string;
|
|
27
|
+
mediaType: string;
|
|
28
|
+
filename?: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'data';
|
|
31
|
+
name: string;
|
|
32
|
+
data: unknown;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'generative-ui';
|
|
35
|
+
spec: unknown;
|
|
36
|
+
};
|
|
37
|
+
export interface AgentToolCall {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
args: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
export interface AgentToolResult {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
result: string;
|
|
46
|
+
/**
|
|
47
|
+
* Set when the tool threw rather than returned. Carried separately from
|
|
48
|
+
* `result`, which is a rendered string by the time it is persisted — a tool
|
|
49
|
+
* may legitimately return text beginning `Error:`, so the prefix cannot be
|
|
50
|
+
* read as a failure signal.
|
|
51
|
+
*/
|
|
52
|
+
error?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface AgentMessage {
|
|
55
|
+
id: string;
|
|
56
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
57
|
+
content?: string | AgentContentPart[];
|
|
58
|
+
toolCalls?: AgentToolCall[];
|
|
59
|
+
toolResults?: AgentToolResult[];
|
|
60
|
+
reasoningContent?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Set on an assistant message whose generation was cut short by
|
|
63
|
+
* an interrupt — the text is a mid-sentence fragment, not a reply.
|
|
64
|
+
* Carried into the next turn's context so the model can see it said only
|
|
65
|
+
* this much before being talked over, and decide for itself whether to
|
|
66
|
+
* resume, restate or move on. Storage that drops unknown fields loses the
|
|
67
|
+
* marker but keeps the fragment, which degrades to a truncated reply.
|
|
68
|
+
*/
|
|
69
|
+
interrupted?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Set on a tool message whose result arrived after the run was interrupted,
|
|
72
|
+
* so the model never got to describe it. The work happened; only the reply
|
|
73
|
+
* about it was lost. It is ordinary thread context on the next turn — the
|
|
74
|
+
* model raises it unprompted ("that deploy did go through") rather than the
|
|
75
|
+
* result being silently dropped or replayed as a fresh tool call.
|
|
76
|
+
*/
|
|
77
|
+
undelivered?: boolean;
|
|
78
|
+
createdAt: Date;
|
|
79
|
+
}
|
|
80
|
+
export interface AgentStep {
|
|
81
|
+
usage: {
|
|
82
|
+
inputTokens: number;
|
|
83
|
+
outputTokens: number;
|
|
84
|
+
};
|
|
85
|
+
toolCalls?: {
|
|
86
|
+
name: string;
|
|
87
|
+
args: Record<string, unknown>;
|
|
88
|
+
result: string;
|
|
89
|
+
/** The failure message, when the tool threw rather than returned. */
|
|
90
|
+
error?: string;
|
|
91
|
+
}[];
|
|
92
|
+
}
|
|
93
|
+
export interface AgentInputAttachment {
|
|
94
|
+
type: 'image' | 'file';
|
|
95
|
+
data?: string;
|
|
96
|
+
url?: string;
|
|
97
|
+
mediaType?: string;
|
|
98
|
+
filename?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface AgentInput {
|
|
101
|
+
message: string;
|
|
102
|
+
threadId: string;
|
|
103
|
+
resourceId: string;
|
|
104
|
+
attachments?: AgentInputAttachment[];
|
|
105
|
+
model?: string;
|
|
106
|
+
temperature?: number;
|
|
107
|
+
/** Structured context injected into the system instructions for this request.
|
|
108
|
+
* Use to provide upfront state (e.g. current org/project/branch/deployment)
|
|
109
|
+
* so the agent can call tools without asking the user for identifiers. */
|
|
110
|
+
context?: string;
|
|
111
|
+
}
|
|
112
|
+
export interface AgentOutput {
|
|
113
|
+
runId: string;
|
|
114
|
+
text: string;
|
|
115
|
+
object?: unknown;
|
|
116
|
+
threadId: string;
|
|
117
|
+
steps: AgentStep[];
|
|
118
|
+
usage: {
|
|
119
|
+
inputTokens: number;
|
|
120
|
+
outputTokens: number;
|
|
121
|
+
};
|
|
122
|
+
status?: 'completed' | 'suspended';
|
|
123
|
+
pendingApprovals?: Array<{
|
|
124
|
+
toolCallId: string;
|
|
125
|
+
toolName: string;
|
|
126
|
+
args: unknown;
|
|
127
|
+
reason?: string;
|
|
128
|
+
runId: string;
|
|
129
|
+
}>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* How an agent's threads/runs are owned and partitioned.
|
|
133
|
+
* - `'user'` (default): owner is the authenticated `session.userId`; the caller's
|
|
134
|
+
* `resourceId` becomes a sub-partition within that user (`userId:resourceId`).
|
|
135
|
+
* - `'org'`: owner is the authenticated `session.orgId` (`orgId:resourceId`), so
|
|
136
|
+
* threads are shared across everyone in the org. Requires a session with an org
|
|
137
|
+
* (e.g. Better Auth's `organization` plugin) — otherwise access is denied.
|
|
138
|
+
*
|
|
139
|
+
* The trusted principal is always the prefix, so a client-supplied `resourceId`
|
|
140
|
+
* can sub-divide within the caller's own boundary but can never widen access to
|
|
141
|
+
* another user's or org's threads.
|
|
142
|
+
*/
|
|
143
|
+
export type SessionScope = 'user' | 'org';
|
|
144
|
+
/**
|
|
145
|
+
* `ApprovalPolicy` is shared with channel capabilities, but `Partial` here:
|
|
146
|
+
* absent `needsApproval` means "do not ask", which is safe because a tool is
|
|
147
|
+
* written by whoever runs the server it executes on. A capability runs on
|
|
148
|
+
* someone else's machine, so it requires the field instead.
|
|
149
|
+
*/
|
|
150
|
+
export interface AgentToolDef extends Partial<ApprovalPolicy> {
|
|
151
|
+
name: string;
|
|
152
|
+
description: string;
|
|
153
|
+
inputSchema: Record<string, unknown>;
|
|
154
|
+
execute: (input: unknown) => Promise<unknown>;
|
|
155
|
+
/**
|
|
156
|
+
* Mirrors the pikku function's `readonly` flag. A read that gets interrupted
|
|
157
|
+
* is discarded rather than reported: nothing changed, and by the next turn
|
|
158
|
+
* the data may be stale anyway — re-reading is cheaper than explaining a
|
|
159
|
+
* result the user never asked to hear about.
|
|
160
|
+
*/
|
|
161
|
+
readonly?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Set only by the framework on sub-agent delegating tools. Such a tool may
|
|
164
|
+
* legitimately return an `__approvalRequired` marker to forward a nested
|
|
165
|
+
* sub-agent approval. The marker is honored ONLY from a tool with this flag —
|
|
166
|
+
* a plain tool's output (which an attacker may influence) can never forge an
|
|
167
|
+
* approval request. See `checkForApprovals`.
|
|
168
|
+
*/
|
|
169
|
+
forwardsApproval?: boolean;
|
|
170
|
+
}
|
|
171
|
+
export interface PikkuAgentMiddlewareHooks<State extends Record<string, unknown> = Record<string, unknown>, Services = any> {
|
|
172
|
+
modifyInput?: (services: Services, ctx: {
|
|
173
|
+
messages: AgentMessage[];
|
|
174
|
+
instructions: string;
|
|
175
|
+
/**
|
|
176
|
+
* Notes about this run that every middleware can read and write, as
|
|
177
|
+
* opposed to {@link modifyOutputStream}'s `state`, which is private to
|
|
178
|
+
* one middleware.
|
|
179
|
+
*
|
|
180
|
+
* It exists because middlewares transform the turn for each other, and
|
|
181
|
+
* the transformation can destroy what a later one needed to know. Voice
|
|
182
|
+
* is the case in point: `voiceInput` replaces the user's audio with its
|
|
183
|
+
* transcript, so by the time anything downstream looks, the turn is
|
|
184
|
+
* indistinguishable from one that was typed — and whether it was typed is
|
|
185
|
+
* exactly what `voiceOutput` needs in order to decide whether to answer
|
|
186
|
+
* aloud. Only the middleware that consumed the audio can still say so.
|
|
187
|
+
*
|
|
188
|
+
* Namespace what you put here (`voice:spokenTurn`); it is one bag for
|
|
189
|
+
* everybody. Cleared between runs.
|
|
190
|
+
*/
|
|
191
|
+
shared: Record<string, unknown>;
|
|
192
|
+
}) => Promise<{
|
|
193
|
+
messages: AgentMessage[];
|
|
194
|
+
instructions: string;
|
|
195
|
+
}> | {
|
|
196
|
+
messages: AgentMessage[];
|
|
197
|
+
instructions: string;
|
|
198
|
+
};
|
|
199
|
+
modifyOutputStream?: (services: Services, ctx: {
|
|
200
|
+
event: AgentStreamEvent;
|
|
201
|
+
allEvents: readonly AgentStreamEvent[];
|
|
202
|
+
/** Private to this middleware, for this run. Cross-middleware facts go in `shared`. */
|
|
203
|
+
state: State;
|
|
204
|
+
/** Per-run notes shared with every middleware — see {@link modifyInput}. */
|
|
205
|
+
shared: Record<string, unknown>;
|
|
206
|
+
/**
|
|
207
|
+
* Push an event into the stream *after* this call has returned.
|
|
208
|
+
*
|
|
209
|
+
* Returning events blocks the stream until the hook resolves, which is
|
|
210
|
+
* right for anything derived from the event and wrong for anything slow.
|
|
211
|
+
* Speech is the motivating case: awaiting a text-to-speech call before
|
|
212
|
+
* returning the text delta stalls the reader at every full stop and
|
|
213
|
+
* serialises synthesis behind playback. Return the text immediately,
|
|
214
|
+
* start the slow work, and `emit` its result when it lands.
|
|
215
|
+
*
|
|
216
|
+
* Ordering among emitted events is the caller's problem — chain them if
|
|
217
|
+
* it matters — and a hook that emits must make sure anything still
|
|
218
|
+
* outstanding has landed before it lets `done` through.
|
|
219
|
+
*/
|
|
220
|
+
emit: (event: AgentStreamEvent) => Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Aborts when the run is interrupted. Pass it to any provider call the
|
|
223
|
+
* hook makes: work started for a reply the user has already talked over
|
|
224
|
+
* is billed but never heard.
|
|
225
|
+
*/
|
|
226
|
+
signal?: AbortSignal;
|
|
227
|
+
}) => Promise<AgentStreamEvent | AgentStreamEvent[] | null> | AgentStreamEvent | AgentStreamEvent[] | null;
|
|
228
|
+
/**
|
|
229
|
+
* The last chance to rewrite what the run produced, before it is persisted
|
|
230
|
+
* and returned.
|
|
231
|
+
*
|
|
232
|
+
* It does **not** run on a streamed run: there the text has already reached
|
|
233
|
+
* the client and each step is flushed to storage as it goes, so nothing could
|
|
234
|
+
* act on what this returned. Use {@link modifyOutputStream} to rewrite a
|
|
235
|
+
* streamed reply — a middleware that implements only this one is warned about
|
|
236
|
+
* when an agent it is attached to streams.
|
|
237
|
+
*
|
|
238
|
+
* `toolCalls` is here so a redaction pass covers the whole run record rather
|
|
239
|
+
* than just the visible answer: the tool arguments and results are persisted
|
|
240
|
+
* and handed to anything that grades the run, and scrubbing the reply alone
|
|
241
|
+
* leaves them untouched.
|
|
242
|
+
*/
|
|
243
|
+
modifyOutput?: (services: Services, ctx: {
|
|
244
|
+
text: string;
|
|
245
|
+
messages: AgentMessage[];
|
|
246
|
+
usage: {
|
|
247
|
+
inputTokens: number;
|
|
248
|
+
outputTokens: number;
|
|
249
|
+
};
|
|
250
|
+
toolCalls: NonNullable<AgentStep['toolCalls']>;
|
|
251
|
+
}) => Promise<{
|
|
252
|
+
text: string;
|
|
253
|
+
messages: AgentMessage[];
|
|
254
|
+
toolCalls?: NonNullable<AgentStep['toolCalls']>;
|
|
255
|
+
}> | {
|
|
256
|
+
text: string;
|
|
257
|
+
messages: AgentMessage[];
|
|
258
|
+
toolCalls?: NonNullable<AgentStep['toolCalls']>;
|
|
259
|
+
};
|
|
260
|
+
beforeToolCall?: (services: Services, ctx: {
|
|
261
|
+
toolName: string;
|
|
262
|
+
toolCallId: string;
|
|
263
|
+
args: Record<string, unknown>;
|
|
264
|
+
}) => Promise<{
|
|
265
|
+
args: Record<string, unknown>;
|
|
266
|
+
} | void> | {
|
|
267
|
+
args: Record<string, unknown>;
|
|
268
|
+
} | void;
|
|
269
|
+
afterToolCall?: (services: Services, ctx: {
|
|
270
|
+
toolName: string;
|
|
271
|
+
toolCallId: string;
|
|
272
|
+
args: Record<string, unknown>;
|
|
273
|
+
result: unknown;
|
|
274
|
+
durationMs: number;
|
|
275
|
+
}) => Promise<{
|
|
276
|
+
result: unknown;
|
|
277
|
+
} | void> | {
|
|
278
|
+
result: unknown;
|
|
279
|
+
} | void;
|
|
280
|
+
afterStep?: (services: Services, ctx: {
|
|
281
|
+
stepNumber: number;
|
|
282
|
+
text: string;
|
|
283
|
+
toolCalls: {
|
|
284
|
+
toolCallId: string;
|
|
285
|
+
toolName: string;
|
|
286
|
+
args: unknown;
|
|
287
|
+
}[];
|
|
288
|
+
toolResults: {
|
|
289
|
+
toolCallId: string;
|
|
290
|
+
toolName: string;
|
|
291
|
+
result: unknown;
|
|
292
|
+
/** Set when the tool threw rather than returned. */
|
|
293
|
+
error?: string;
|
|
294
|
+
}[];
|
|
295
|
+
usage: {
|
|
296
|
+
inputTokens: number;
|
|
297
|
+
outputTokens: number;
|
|
298
|
+
};
|
|
299
|
+
finishReason: string;
|
|
300
|
+
}) => Promise<void> | void;
|
|
301
|
+
onError?: (services: Services, ctx: {
|
|
302
|
+
error: Error;
|
|
303
|
+
stepNumber: number;
|
|
304
|
+
messages: AgentMessage[];
|
|
305
|
+
}) => Promise<void> | void;
|
|
306
|
+
}
|
|
307
|
+
export type AgentMemoryConfig = {
|
|
308
|
+
storage?: string;
|
|
309
|
+
vector?: string;
|
|
310
|
+
embedder?: string;
|
|
311
|
+
lastMessages?: number;
|
|
312
|
+
workingMemory?: unknown;
|
|
313
|
+
};
|
|
314
|
+
export type CoreAgent<PikkuPermission = CorePikkuPermission<any, any>, PikkuMiddleware = CorePikkuMiddleware<any>, Scope extends string = string, Scorer extends string = string> = {
|
|
315
|
+
name: string;
|
|
316
|
+
description: string;
|
|
317
|
+
summary?: string;
|
|
318
|
+
errors?: string[];
|
|
319
|
+
/**
|
|
320
|
+
* The three fields below are the system prompt. `buildInstructions` joins
|
|
321
|
+
* whichever are set with a blank line, always in this order — role, then
|
|
322
|
+
* personality, then goal — and appends the tool-usage rules if the agent has
|
|
323
|
+
* tools. Nothing checks them against each other: the split is there to keep a
|
|
324
|
+
* prompt legible, and text put in the wrong one still reaches the model.
|
|
325
|
+
*
|
|
326
|
+
* Who the agent is. 'You are a support engineer triaging inbound bugs.'
|
|
327
|
+
*/
|
|
328
|
+
role?: string;
|
|
329
|
+
/** How it should sound: tone, vocabulary, how much it says at a time. */
|
|
330
|
+
personality?: string;
|
|
331
|
+
/** What it is for — the only one of the three that is required. */
|
|
332
|
+
goal: string;
|
|
333
|
+
model: string;
|
|
334
|
+
temperature?: number;
|
|
335
|
+
/** Ownership/partitioning of this agent's threads and runs. Defaults to `'user'`. */
|
|
336
|
+
sessionScope?: SessionScope;
|
|
337
|
+
tools?: unknown[];
|
|
338
|
+
agents?: unknown[];
|
|
339
|
+
workflows?: unknown[];
|
|
340
|
+
/**
|
|
341
|
+
* Grades this agent's finished runs on live traffic, named by the generated
|
|
342
|
+
* `ScorerName` union rather than by `ref()` — a scorer is not a function, so
|
|
343
|
+
* there is nothing in the function map for a ref to resolve against.
|
|
344
|
+
*
|
|
345
|
+
* A reference-based judge listed here is never sampled: live traffic has no
|
|
346
|
+
* answer key. Scenarios name scorers directly and may grade with scorers an
|
|
347
|
+
* agent does not ship with.
|
|
348
|
+
*/
|
|
349
|
+
scorers?: Scorer[];
|
|
350
|
+
agentMode?: 'delegate' | 'supervise';
|
|
351
|
+
memory?: AgentMemoryConfig;
|
|
352
|
+
maxSteps?: number;
|
|
353
|
+
toolChoice?: 'auto' | 'required' | 'none';
|
|
354
|
+
/**
|
|
355
|
+
* Per-provider model settings, keyed by provider id and passed through
|
|
356
|
+
* untouched — for anything only one vendor offers, which the fields above
|
|
357
|
+
* deliberately do not try to unify.
|
|
358
|
+
*
|
|
359
|
+
* `{ openai: { reasoningEffort: 'minimal' } }` is the one that matters for
|
|
360
|
+
* voice: on gpt-5-mini it measured 0.9s to first token against 2.5s at the
|
|
361
|
+
* default, and a spoken reply is waited through rather than skimmed.
|
|
362
|
+
*/
|
|
363
|
+
providerOptions?: AIProviderOptions;
|
|
364
|
+
input?: unknown;
|
|
365
|
+
output?: unknown;
|
|
366
|
+
tags?: string[];
|
|
367
|
+
prepareStep?: (ctx: {
|
|
368
|
+
stepNumber: number;
|
|
369
|
+
messages: AgentMessage[];
|
|
370
|
+
tools: AgentToolDef[];
|
|
371
|
+
toolChoice: 'auto' | 'required' | 'none';
|
|
372
|
+
model: string;
|
|
373
|
+
stop: () => void;
|
|
374
|
+
}) => void | Promise<void>;
|
|
375
|
+
middleware?: PikkuMiddleware[];
|
|
376
|
+
channelMiddleware?: CorePikkuChannelMiddleware<any, any>[];
|
|
377
|
+
agentMiddleware?: PikkuAgentMiddlewareHooks<any, any>[];
|
|
378
|
+
/**
|
|
379
|
+
* Whether a session is required to run this agent. Defaults to `false`, since
|
|
380
|
+
* agents are commonly invoked from an already-authenticated `pikkuFunc` or
|
|
381
|
+
* from genuinely sessionless contexts (crons, queue workers). Set `true` to
|
|
382
|
+
* require a session at the agent itself. `scopes` and `permissions` are
|
|
383
|
+
* enforced either way.
|
|
384
|
+
*/
|
|
385
|
+
auth?: boolean;
|
|
386
|
+
/**
|
|
387
|
+
* Scopes the session must hold to run this agent. All of them are required
|
|
388
|
+
* (AND), and they are checked before `permissions` — unlike permissions,
|
|
389
|
+
* which OR together, a scope can only narrow access.
|
|
390
|
+
*
|
|
391
|
+
* Narrowed to the generated `ScopeId` union in a project's own
|
|
392
|
+
* `pikku-types.gen.ts`, so an undeclared scope is a compile error.
|
|
393
|
+
*/
|
|
394
|
+
scopes?: Scope[];
|
|
395
|
+
permissions?: CorePermissionGroup<PikkuPermission>;
|
|
396
|
+
};
|
|
397
|
+
export type AgentStreamEvent = {
|
|
398
|
+
type: 'step-start';
|
|
399
|
+
stepNumber: number;
|
|
400
|
+
agent?: string;
|
|
401
|
+
session?: string;
|
|
402
|
+
} | {
|
|
403
|
+
type: 'text-delta';
|
|
404
|
+
text: string;
|
|
405
|
+
agent?: string;
|
|
406
|
+
session?: string;
|
|
407
|
+
} | {
|
|
408
|
+
type: 'reasoning-delta';
|
|
409
|
+
text: string;
|
|
410
|
+
agent?: string;
|
|
411
|
+
session?: string;
|
|
412
|
+
} | {
|
|
413
|
+
type: 'tool-call';
|
|
414
|
+
toolCallId: string;
|
|
415
|
+
toolName: string;
|
|
416
|
+
args: unknown;
|
|
417
|
+
agent?: string;
|
|
418
|
+
session?: string;
|
|
419
|
+
} | {
|
|
420
|
+
type: 'tool-result';
|
|
421
|
+
toolCallId: string;
|
|
422
|
+
toolName: string;
|
|
423
|
+
result: unknown;
|
|
424
|
+
/**
|
|
425
|
+
* The failure message, set when the tool threw rather than returned.
|
|
426
|
+
* Carried explicitly because a tool may legitimately return text that
|
|
427
|
+
* reads like an error, so `result` cannot be matched on to tell.
|
|
428
|
+
*/
|
|
429
|
+
error?: string;
|
|
430
|
+
agent?: string;
|
|
431
|
+
session?: string;
|
|
432
|
+
} | {
|
|
433
|
+
type: 'agent-call';
|
|
434
|
+
agentName: string;
|
|
435
|
+
session: string;
|
|
436
|
+
input: unknown;
|
|
437
|
+
} | {
|
|
438
|
+
type: 'agent-result';
|
|
439
|
+
agentName: string;
|
|
440
|
+
session: string;
|
|
441
|
+
result: unknown;
|
|
442
|
+
} | {
|
|
443
|
+
type: 'approval-request';
|
|
444
|
+
toolCallId: string;
|
|
445
|
+
toolName: string;
|
|
446
|
+
args: unknown;
|
|
447
|
+
reason?: string;
|
|
448
|
+
runId: string;
|
|
449
|
+
agent?: string;
|
|
450
|
+
session?: string;
|
|
451
|
+
} | {
|
|
452
|
+
type: 'credential-request';
|
|
453
|
+
toolCallId: string;
|
|
454
|
+
toolName: string;
|
|
455
|
+
args: unknown;
|
|
456
|
+
credentialName: string;
|
|
457
|
+
credentialType: 'oauth2' | 'apikey';
|
|
458
|
+
connectUrl?: string;
|
|
459
|
+
runId: string;
|
|
460
|
+
agent?: string;
|
|
461
|
+
session?: string;
|
|
462
|
+
} | {
|
|
463
|
+
type: 'usage';
|
|
464
|
+
tokens: {
|
|
465
|
+
input: number;
|
|
466
|
+
output: number;
|
|
467
|
+
};
|
|
468
|
+
model: string;
|
|
469
|
+
agent?: string;
|
|
470
|
+
session?: string;
|
|
471
|
+
} | {
|
|
472
|
+
type: 'error';
|
|
473
|
+
message: string;
|
|
474
|
+
agent?: string;
|
|
475
|
+
session?: string;
|
|
476
|
+
} | {
|
|
477
|
+
type: 'audio-delta';
|
|
478
|
+
data: string;
|
|
479
|
+
format: string;
|
|
480
|
+
/**
|
|
481
|
+
* The sentence this audio says.
|
|
482
|
+
*
|
|
483
|
+
* Carried alongside the bytes because a client that gets talked over has
|
|
484
|
+
* to tell the model what the user actually heard, and playback position
|
|
485
|
+
* is the only place that is knowable. Without it a barge-in can stop the
|
|
486
|
+
* sound but not report it, and the next turn is answered as though the
|
|
487
|
+
* whole reply had landed.
|
|
488
|
+
*/
|
|
489
|
+
text?: string;
|
|
490
|
+
agent?: string;
|
|
491
|
+
session?: string;
|
|
492
|
+
} | {
|
|
493
|
+
type: 'audio-done';
|
|
494
|
+
agent?: string;
|
|
495
|
+
session?: string;
|
|
496
|
+
} | {
|
|
497
|
+
/**
|
|
498
|
+
* What the user was heard to say, sent once at the start of a spoken
|
|
499
|
+
* turn. Only the server knows this — the client sent audio — and a chat
|
|
500
|
+
* surface needs it to show the user's own message.
|
|
501
|
+
*/
|
|
502
|
+
type: 'transcript';
|
|
503
|
+
text: string;
|
|
504
|
+
agent?: string;
|
|
505
|
+
session?: string;
|
|
506
|
+
} | {
|
|
507
|
+
type: 'data';
|
|
508
|
+
name: string;
|
|
509
|
+
data: unknown;
|
|
510
|
+
agent?: string;
|
|
511
|
+
session?: string;
|
|
512
|
+
} | {
|
|
513
|
+
type: 'generative-ui';
|
|
514
|
+
spec: unknown;
|
|
515
|
+
agent?: string;
|
|
516
|
+
session?: string;
|
|
517
|
+
} | {
|
|
518
|
+
type: 'suspended';
|
|
519
|
+
reason: 'rpc-missing';
|
|
520
|
+
missingRpcs: string[];
|
|
521
|
+
} | {
|
|
522
|
+
type: 'interrupted';
|
|
523
|
+
runId: string;
|
|
524
|
+
/** The truncated assistant text at the moment generation stopped. */
|
|
525
|
+
text: string;
|
|
526
|
+
reason: 'speech' | 'user' | 'timeout';
|
|
527
|
+
agent?: string;
|
|
528
|
+
session?: string;
|
|
529
|
+
} | {
|
|
530
|
+
type: 'done';
|
|
531
|
+
};
|
|
532
|
+
export interface AgentStreamChannel extends PikkuChannel<unknown, AgentStreamEvent> {
|
|
533
|
+
}
|
|
534
|
+
export type PendingApproval = {
|
|
535
|
+
type: 'tool-call';
|
|
536
|
+
toolCallId: string;
|
|
537
|
+
toolName: string;
|
|
538
|
+
args: unknown;
|
|
539
|
+
} | {
|
|
540
|
+
type: 'agent-call';
|
|
541
|
+
toolCallId: string;
|
|
542
|
+
agentName: string;
|
|
543
|
+
agentRunId: string;
|
|
544
|
+
displayToolName: string;
|
|
545
|
+
displayArgs: unknown;
|
|
546
|
+
} | {
|
|
547
|
+
type: 'credential-request';
|
|
548
|
+
toolCallId: string;
|
|
549
|
+
toolName: string;
|
|
550
|
+
args: unknown;
|
|
551
|
+
credentialName: string;
|
|
552
|
+
credentialType: 'oauth2' | 'apikey';
|
|
553
|
+
connectUrl?: string;
|
|
554
|
+
};
|
|
555
|
+
export interface AgentRunState {
|
|
556
|
+
runId: string;
|
|
557
|
+
agentName: string;
|
|
558
|
+
threadId: string;
|
|
559
|
+
resourceId: string;
|
|
560
|
+
status: 'running' | 'suspended' | 'completed' | 'failed' | 'interrupted';
|
|
561
|
+
errorMessage?: string;
|
|
562
|
+
suspendReason?: 'approval' | 'credential' | 'rpc-missing';
|
|
563
|
+
missingRpcs?: string[];
|
|
564
|
+
pendingApprovals?: PendingApproval[];
|
|
565
|
+
usage: {
|
|
566
|
+
inputTokens: number;
|
|
567
|
+
outputTokens: number;
|
|
568
|
+
model: string;
|
|
569
|
+
};
|
|
570
|
+
createdAt: Date;
|
|
571
|
+
updatedAt: Date;
|
|
572
|
+
}
|
|
573
|
+
export interface AgentRunRow {
|
|
574
|
+
runId: string;
|
|
575
|
+
agentName: string;
|
|
576
|
+
threadId: string;
|
|
577
|
+
resourceId: string;
|
|
578
|
+
status: string;
|
|
579
|
+
errorMessage?: string;
|
|
580
|
+
suspendReason?: string;
|
|
581
|
+
missingRpcs?: string[];
|
|
582
|
+
usageInputTokens: number;
|
|
583
|
+
usageOutputTokens: number;
|
|
584
|
+
usageModel: string;
|
|
585
|
+
createdAt: Date;
|
|
586
|
+
updatedAt: Date;
|
|
587
|
+
}
|
|
588
|
+
export interface AgentRunService {
|
|
589
|
+
listThreads(options?: {
|
|
590
|
+
agentName?: string;
|
|
591
|
+
resourceId?: string;
|
|
592
|
+
/**
|
|
593
|
+
* Restrict results to threads owned by one of these session principals. A
|
|
594
|
+
* thread matches when its `resourceId` is the principal itself or one of its
|
|
595
|
+
* `principal:` sub-partitions, mirroring the composition
|
|
596
|
+
* `resolveOwnerResourceId` writes.
|
|
597
|
+
*
|
|
598
|
+
* Unlike `resourceId`, which is an optional exact-match filter, this is an
|
|
599
|
+
* authorization constraint: an empty array matches nothing. Callers exposing
|
|
600
|
+
* threads over the wire must derive it from the session, never from input.
|
|
601
|
+
*/
|
|
602
|
+
owners?: string[];
|
|
603
|
+
limit?: number;
|
|
604
|
+
offset?: number;
|
|
605
|
+
}): Promise<AgentThread[]>;
|
|
606
|
+
getThread(threadId: string): Promise<AgentThread | null>;
|
|
607
|
+
getThreadMessages(threadId: string): Promise<AgentMessage[]>;
|
|
608
|
+
getThreadRuns(threadId: string): Promise<AgentRunRow[]>;
|
|
609
|
+
deleteThread(threadId: string): Promise<boolean>;
|
|
610
|
+
getDistinctAgentNames(): Promise<string[]>;
|
|
611
|
+
}
|
|
612
|
+
export type AgentsMeta = Record<string, Omit<CoreAgent, 'input' | 'output' | 'tools' | 'agents' | 'workflows' | 'middleware' | 'channelMiddleware' | 'agentMiddleware' | 'permissions'> & {
|
|
613
|
+
tools?: string[];
|
|
614
|
+
agents?: string[];
|
|
615
|
+
workflows?: string[];
|
|
616
|
+
inputSchema: string | null;
|
|
617
|
+
outputSchema: string | null;
|
|
618
|
+
workingMemorySchema: string | null;
|
|
619
|
+
middleware?: MiddlewareMetadata[];
|
|
620
|
+
channelMiddleware?: MiddlewareMetadata[];
|
|
621
|
+
agentMiddleware?: MiddlewareMetadata[];
|
|
622
|
+
permissions?: PermissionMetadata[];
|
|
623
|
+
sourceFile?: string;
|
|
624
|
+
exportedName?: string;
|
|
625
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { agent, agentStream, agentResume, agentApprove, agentInterrupt, } from './agent-helpers.js';
|
|
2
|
+
export { wrapChannelWithAGUI } from './agent-agui.js';
|
|
3
|
+
export { runAgent, resumeAgentSync } from './agent-runner.js';
|
|
4
|
+
export { resolveModelAlias } from './agent-model-config.js';
|
|
5
|
+
export { streamAgent, resumeAgent, interruptAgent } from './agent-stream.js';
|
|
6
|
+
export { voiceInput, NoSpeechDetectedError, SPOKEN_TURN, SPOKEN_TRANSCRIPT, } from './voice-input.js';
|
|
7
|
+
export { voiceOutput, unspeakableScripts, voiceForText, type SpeakableScripts, } from './voice-output.js';
|
|
8
|
+
export { AgentInterruptedError, signalRunInterrupt } from './agent-interrupt.js';
|
|
9
|
+
export type { AgentInterruption, AgentInterruptResult, InterruptibleRunHandle, } from './agent-interrupt.js';
|
|
10
|
+
export { type RunAgentParams, type StreamAgentOptions, ToolApprovalRequired, ToolCredentialRequired, canAccessThread, isOwnedByPrincipal, threadOwnerConstraint, } from './agent-prepare.js';
|
|
11
|
+
export { addAgent } from './agent-registry.js';
|
|
12
|
+
export type { AgentInput, AgentsMeta, AgentMemoryConfig, AgentStep, AgentContentPart, AgentRunRow, AgentRunService, AgentRunState, AgentMessage, AgentStreamChannel, AgentStreamEvent, AgentThread, CoreAgent, PendingApproval, PikkuAgentMiddlewareHooks, } from './agent.types.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { agent, agentStream, agentResume, agentApprove, agentInterrupt, } from './agent-helpers.js';
|
|
2
|
+
export { wrapChannelWithAGUI } from './agent-agui.js';
|
|
3
|
+
export { runAgent, resumeAgentSync } from './agent-runner.js';
|
|
4
|
+
export { resolveModelAlias } from './agent-model-config.js';
|
|
5
|
+
export { streamAgent, resumeAgent, interruptAgent } from './agent-stream.js';
|
|
6
|
+
export { voiceInput, NoSpeechDetectedError, SPOKEN_TURN, SPOKEN_TRANSCRIPT, } from './voice-input.js';
|
|
7
|
+
export { voiceOutput, unspeakableScripts, voiceForText, } from './voice-output.js';
|
|
8
|
+
export { AgentInterruptedError, signalRunInterrupt } from './agent-interrupt.js';
|
|
9
|
+
export { ToolApprovalRequired, ToolCredentialRequired, canAccessThread, isOwnedByPrincipal, threadOwnerConstraint, } from './agent-prepare.js';
|
|
10
|
+
export { addAgent } from './agent-registry.js';
|