stitchkit 0.133.2 → 0.134.0
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 +115 -0
- package/README.md +14 -11
- package/dist/agent-executor/acp/v1-connect.d.ts +3 -0
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-map.d.ts +13 -3
- package/dist/agent-executor/acp/v1-map.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-protocol.d.ts +59 -0
- package/dist/agent-executor/acp/v1-protocol.d.ts.map +1 -1
- package/dist/agent-executor/codex/connect.d.ts +2 -0
- package/dist/agent-executor/codex/connect.d.ts.map +1 -1
- package/dist/agent-executor/codex/driver.d.ts +3 -0
- package/dist/agent-executor/codex/driver.d.ts.map +1 -1
- package/dist/agent-executor/contract.d.ts +42 -0
- package/dist/agent-executor/contract.d.ts.map +1 -1
- package/dist/agent-executor/engine-process.d.ts +20 -0
- package/dist/agent-executor/engine-process.d.ts.map +1 -1
- package/dist/agent-executor/executor-contract.d.ts +42 -0
- package/dist/agent-executor/executor-contract.d.ts.map +1 -1
- package/dist/agent-executor/handoff-schemas.d.ts +30 -0
- package/dist/agent-executor/handoff-schemas.d.ts.map +1 -1
- package/dist/agent-executor/projection.d.ts.map +1 -1
- package/dist/agent-executor/session-primitives.d.ts +4 -1
- package/dist/agent-executor/session-primitives.d.ts.map +1 -1
- package/dist/agent-executor/vocabulary.d.ts +100 -0
- package/dist/agent-executor/vocabulary.d.ts.map +1 -1
- package/dist/agent-parts/model.d.ts +1559 -0
- package/dist/agent-parts/model.d.ts.map +1 -0
- package/dist/agent-parts/parts.d.ts +21 -0
- package/dist/agent-parts/parts.d.ts.map +1 -1
- package/dist/agent-runtime/ai-sdk-convert.d.ts +15 -0
- package/dist/agent-runtime/ai-sdk-convert.d.ts.map +1 -0
- package/dist/agent-runtime/ai-sdk.d.ts +31 -0
- package/dist/agent-runtime/ai-sdk.d.ts.map +1 -0
- package/dist/agent-runtime/anthropic-media.d.ts +11 -0
- package/dist/agent-runtime/anthropic-media.d.ts.map +1 -0
- package/dist/agent-runtime/anthropic-messages.d.ts +24 -0
- package/dist/agent-runtime/anthropic-messages.d.ts.map +1 -0
- package/dist/agent-runtime/anthropic-options.d.ts +79 -0
- package/dist/agent-runtime/anthropic-options.d.ts.map +1 -0
- package/dist/agent-runtime/anthropic-response.d.ts +19 -0
- package/dist/agent-runtime/anthropic-response.d.ts.map +1 -0
- package/dist/agent-runtime/anthropic-sse.d.ts +4 -0
- package/dist/agent-runtime/anthropic-sse.d.ts.map +1 -0
- package/dist/agent-runtime/anthropic.d.ts +27 -0
- package/dist/agent-runtime/anthropic.d.ts.map +1 -0
- package/dist/agent-runtime/branch-observations.d.ts +25 -25
- package/dist/agent-runtime/branch-provider.d.ts +86 -0
- package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
- package/dist/agent-runtime/branch-replay.d.ts +30 -0
- package/dist/agent-runtime/branch-replay.d.ts.map +1 -1
- package/dist/agent-runtime/browser-control-contract.d.ts +204 -0
- package/dist/agent-runtime/browser-control-contract.d.ts.map +1 -1
- package/dist/agent-runtime/browser-controller-view.d.ts +44 -0
- package/dist/agent-runtime/browser-controller-view.d.ts.map +1 -0
- package/dist/agent-runtime/browser-controller.d.ts +12 -8
- package/dist/agent-runtime/browser-controller.d.ts.map +1 -1
- package/dist/agent-runtime/child-budget-policy.d.ts +2 -3
- package/dist/agent-runtime/child-budget-policy.d.ts.map +1 -1
- package/dist/agent-runtime/compaction.d.ts +27 -10
- package/dist/agent-runtime/compaction.d.ts.map +1 -1
- package/dist/agent-runtime/control-interaction-schema.d.ts +157 -0
- package/dist/agent-runtime/control-interaction-schema.d.ts.map +1 -0
- package/dist/agent-runtime/control-schema.d.ts +183 -27
- package/dist/agent-runtime/control-schema.d.ts.map +1 -1
- package/dist/agent-runtime/control-view.d.ts +64 -0
- package/dist/agent-runtime/control-view.d.ts.map +1 -0
- package/dist/agent-runtime/conversations.d.ts +10 -0
- package/dist/agent-runtime/conversations.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tool-selection.d.ts +2 -2
- package/dist/agent-runtime/deferred-tool-selection.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tool-types.d.ts +2 -2
- package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tools-internal.d.ts +8 -11
- package/dist/agent-runtime/deferred-tools-internal.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tools.d.ts.map +1 -1
- package/dist/agent-runtime/event-schema.d.ts +80 -0
- package/dist/agent-runtime/event-schema.d.ts.map +1 -1
- package/dist/agent-runtime/harness-contract.d.ts +2 -2
- package/dist/agent-runtime/harness-contract.d.ts.map +1 -1
- package/dist/agent-runtime/harness-control.d.ts.map +1 -1
- package/dist/agent-runtime/harness-realtime.d.ts.map +1 -1
- package/dist/agent-runtime/harness.d.ts +2 -2
- package/dist/agent-runtime/harness.d.ts.map +1 -1
- package/dist/agent-runtime/history.d.ts +25 -16
- package/dist/agent-runtime/history.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-attempt.d.ts +7 -3
- package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-payload.d.ts +13 -7
- package/dist/agent-runtime/invocation-payload.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-stream.d.ts +20 -0
- package/dist/agent-runtime/invocation-stream.d.ts.map +1 -0
- package/dist/agent-runtime/invocations.d.ts +2 -2
- package/dist/agent-runtime/invocations.d.ts.map +1 -1
- package/dist/agent-runtime/models-driver-step.d.ts +212 -0
- package/dist/agent-runtime/models-driver-step.d.ts.map +1 -0
- package/dist/agent-runtime/models-driver-telemetry.d.ts +42 -0
- package/dist/agent-runtime/models-driver-telemetry.d.ts.map +1 -0
- package/dist/agent-runtime/models-driver.d.ts +235 -0
- package/dist/agent-runtime/models-driver.d.ts.map +1 -0
- package/dist/agent-runtime/models.d.ts +3 -26
- package/dist/agent-runtime/models.d.ts.map +1 -1
- package/dist/agent-runtime/observability.d.ts +64 -0
- package/dist/agent-runtime/observability.d.ts.map +1 -1
- package/dist/agent-runtime/openai-messages.d.ts +11 -0
- package/dist/agent-runtime/openai-messages.d.ts.map +1 -0
- package/dist/agent-runtime/openai-options.d.ts +91 -0
- package/dist/agent-runtime/openai-options.d.ts.map +1 -0
- package/dist/agent-runtime/openai-response.d.ts +77 -0
- package/dist/agent-runtime/openai-response.d.ts.map +1 -0
- package/dist/agent-runtime/openai-sse-state.d.ts +54 -0
- package/dist/agent-runtime/openai-sse-state.d.ts.map +1 -0
- package/dist/agent-runtime/openai-sse.d.ts +4 -0
- package/dist/agent-runtime/openai-sse.d.ts.map +1 -0
- package/dist/agent-runtime/openai.d.ts +31 -0
- package/dist/agent-runtime/openai.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-admission.d.ts +3 -0
- package/dist/agent-runtime/openrouter-admission.d.ts.map +1 -1
- package/dist/agent-runtime/openrouter-benchmarks.d.ts +17 -0
- package/dist/agent-runtime/openrouter-benchmarks.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-catalog-cache.d.ts +70 -0
- package/dist/agent-runtime/openrouter-catalog-cache.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-catalog-query.d.ts +57 -0
- package/dist/agent-runtime/openrouter-catalog-query.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-catalog.d.ts +189 -14
- package/dist/agent-runtime/openrouter-catalog.d.ts.map +1 -1
- package/dist/agent-runtime/openrouter-models.d.ts +168 -31
- package/dist/agent-runtime/openrouter-models.d.ts.map +1 -1
- package/dist/agent-runtime/openrouter-options.d.ts +45 -15
- package/dist/agent-runtime/openrouter-options.d.ts.map +1 -1
- package/dist/agent-runtime/openrouter-response.d.ts +22 -0
- package/dist/agent-runtime/openrouter-response.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter.d.ts +21 -24
- package/dist/agent-runtime/openrouter.d.ts.map +1 -1
- package/dist/agent-runtime/owned-provider-stream.d.ts +4 -4
- package/dist/agent-runtime/owned-provider-stream.d.ts.map +1 -1
- package/dist/agent-runtime/prompt.d.ts +3 -3
- package/dist/agent-runtime/prompt.d.ts.map +1 -1
- package/dist/agent-runtime/protocol.d.ts +28 -3
- package/dist/agent-runtime/protocol.d.ts.map +1 -1
- package/dist/agent-runtime/provider-cache.d.ts +30 -0
- package/dist/agent-runtime/provider-cache.d.ts.map +1 -0
- package/dist/agent-runtime/provider-content.d.ts +147 -0
- package/dist/agent-runtime/provider-content.d.ts.map +1 -1
- package/dist/agent-runtime/provider-failure.d.ts +51 -26
- package/dist/agent-runtime/provider-failure.d.ts.map +1 -1
- package/dist/agent-runtime/provider-history.d.ts +13 -0
- package/dist/agent-runtime/provider-history.d.ts.map +1 -0
- package/dist/agent-runtime/provider-http.d.ts +68 -0
- package/dist/agent-runtime/provider-http.d.ts.map +1 -0
- package/dist/agent-runtime/provider-journal.d.ts +149 -0
- package/dist/agent-runtime/provider-journal.d.ts.map +1 -1
- package/dist/agent-runtime/provider-json-schema-strip.d.ts +8 -0
- package/dist/agent-runtime/provider-json-schema-strip.d.ts.map +1 -0
- package/dist/agent-runtime/provider-json-schema.d.ts +28 -0
- package/dist/agent-runtime/provider-json-schema.d.ts.map +1 -0
- package/dist/agent-runtime/provider-media.d.ts +49 -0
- package/dist/agent-runtime/provider-media.d.ts.map +1 -0
- package/dist/agent-runtime/provider-openai-chat-helpers.d.ts +27 -0
- package/dist/agent-runtime/provider-openai-chat-helpers.d.ts.map +1 -0
- package/dist/agent-runtime/provider-openai-chat-sse.d.ts +25 -0
- package/dist/agent-runtime/provider-openai-chat-sse.d.ts.map +1 -0
- package/dist/agent-runtime/provider-openai-chat.d.ts +27 -0
- package/dist/agent-runtime/provider-openai-chat.d.ts.map +1 -0
- package/dist/agent-runtime/provider-origin.d.ts +3 -12
- package/dist/agent-runtime/provider-origin.d.ts.map +1 -1
- package/dist/agent-runtime/provider-sse.d.ts +30 -0
- package/dist/agent-runtime/provider-sse.d.ts.map +1 -0
- package/dist/agent-runtime/provider-stream-parts.d.ts +5 -0
- package/dist/agent-runtime/provider-stream-parts.d.ts.map +1 -0
- package/dist/agent-runtime/provider-stream-segments.d.ts +63 -0
- package/dist/agent-runtime/provider-stream-segments.d.ts.map +1 -0
- package/dist/agent-runtime/provider-usage.d.ts +24 -0
- package/dist/agent-runtime/provider-usage.d.ts.map +1 -0
- package/dist/agent-runtime/retry-policy.d.ts +19 -3
- package/dist/agent-runtime/retry-policy.d.ts.map +1 -1
- package/dist/agent-runtime/run-acquisition.d.ts +4 -4
- package/dist/agent-runtime/run-acquisition.d.ts.map +1 -1
- package/dist/agent-runtime/run-approval.d.ts +82 -0
- package/dist/agent-runtime/run-approval.d.ts.map +1 -0
- package/dist/agent-runtime/run-complete-retry.d.ts +24 -0
- package/dist/agent-runtime/run-complete-retry.d.ts.map +1 -0
- package/dist/agent-runtime/run-complete-stream.d.ts +9 -0
- package/dist/agent-runtime/run-complete-stream.d.ts.map +1 -0
- package/dist/agent-runtime/run-complete-tools.d.ts +21 -0
- package/dist/agent-runtime/run-complete-tools.d.ts.map +1 -0
- package/dist/agent-runtime/run-complete-types.d.ts +168 -0
- package/dist/agent-runtime/run-complete-types.d.ts.map +1 -0
- package/dist/agent-runtime/run-complete.d.ts +25 -0
- package/dist/agent-runtime/run-complete.d.ts.map +1 -0
- package/dist/agent-runtime/run-driver-compose.d.ts +21 -0
- package/dist/agent-runtime/run-driver-compose.d.ts.map +1 -0
- package/dist/agent-runtime/run-execution-state.d.ts +23 -10
- package/dist/agent-runtime/run-execution-state.d.ts.map +1 -1
- package/dist/agent-runtime/run-execution.d.ts +2 -2
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime/run-failure.d.ts +2 -2
- package/dist/agent-runtime/run-failure.d.ts.map +1 -1
- package/dist/agent-runtime/run-history-parts.d.ts +14 -0
- package/dist/agent-runtime/run-history-parts.d.ts.map +1 -0
- package/dist/agent-runtime/run-loop-events.d.ts +126 -0
- package/dist/agent-runtime/run-loop-events.d.ts.map +1 -0
- package/dist/agent-runtime/run-model-attempts.d.ts +2 -2
- package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
- package/dist/agent-runtime/run-model-messages.d.ts +9 -0
- package/dist/agent-runtime/run-model-messages.d.ts.map +1 -0
- package/dist/agent-runtime/run-model-step.d.ts +43 -0
- package/dist/agent-runtime/run-model-step.d.ts.map +1 -0
- package/dist/agent-runtime/run-model-stream.d.ts +27 -0
- package/dist/agent-runtime/run-model-stream.d.ts.map +1 -0
- package/dist/agent-runtime/run-operation-lifecycle.d.ts +8 -4
- package/dist/agent-runtime/run-operation-lifecycle.d.ts.map +1 -1
- package/dist/agent-runtime/run-prompt-history.d.ts +8 -13
- package/dist/agent-runtime/run-prompt-history.d.ts.map +1 -1
- package/dist/agent-runtime/run-provider-ledger.d.ts +7 -4
- package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -1
- package/dist/agent-runtime/run-step-barriers.d.ts +58 -16
- package/dist/agent-runtime/run-step-barriers.d.ts.map +1 -1
- package/dist/agent-runtime/run-step-helpers.d.ts +49 -0
- package/dist/agent-runtime/run-step-helpers.d.ts.map +1 -0
- package/dist/agent-runtime/run-step-prepare.d.ts +34 -0
- package/dist/agent-runtime/run-step-prepare.d.ts.map +1 -0
- package/dist/agent-runtime/run-step-spend.d.ts +85 -10
- package/dist/agent-runtime/run-step-spend.d.ts.map +1 -1
- package/dist/agent-runtime/run-stream-parts.d.ts +13 -9
- package/dist/agent-runtime/run-stream-parts.d.ts.map +1 -1
- package/dist/agent-runtime/run-stream-recorded.d.ts +8 -0
- package/dist/agent-runtime/run-stream-recorded.d.ts.map +1 -0
- package/dist/agent-runtime/run-stream-step-text.d.ts +29 -0
- package/dist/agent-runtime/run-stream-step-text.d.ts.map +1 -0
- package/dist/agent-runtime/run-terminal.d.ts +3 -3
- package/dist/agent-runtime/run-terminal.d.ts.map +1 -1
- package/dist/agent-runtime/run-tool-approval-flow.d.ts +36 -0
- package/dist/agent-runtime/run-tool-approval-flow.d.ts.map +1 -0
- package/dist/agent-runtime/run-tool-approval-records.d.ts +24 -0
- package/dist/agent-runtime/run-tool-approval-records.d.ts.map +1 -0
- package/dist/agent-runtime/run-tool-call.d.ts +73 -0
- package/dist/agent-runtime/run-tool-call.d.ts.map +1 -0
- package/dist/agent-runtime/run-tool-errors.d.ts +29 -0
- package/dist/agent-runtime/run-tool-errors.d.ts.map +1 -0
- package/dist/agent-runtime/run-tool-executor.d.ts +34 -0
- package/dist/agent-runtime/run-tool-executor.d.ts.map +1 -0
- package/dist/agent-runtime/run-tool-progress.d.ts +2 -2
- package/dist/agent-runtime/run-tool-progress.d.ts.map +1 -1
- package/dist/agent-runtime/run-turn-preparation.d.ts +7 -6
- package/dist/agent-runtime/run-turn-preparation.d.ts.map +1 -1
- package/dist/agent-runtime/run-unacquired.d.ts +2 -2
- package/dist/agent-runtime/run-unacquired.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-control.d.ts +4 -4
- package/dist/agent-runtime/runtime-control.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-internals.d.ts +35 -44
- package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-recovery.d.ts +3 -3
- package/dist/agent-runtime/runtime-recovery.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-state.d.ts +3 -3
- package/dist/agent-runtime/runtime-state.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-submit.d.ts +2 -2
- package/dist/agent-runtime/runtime-submit.d.ts.map +1 -1
- package/dist/agent-runtime/runtime.d.ts +51 -16
- package/dist/agent-runtime/runtime.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox-process-linux.d.ts +8 -0
- package/dist/agent-runtime/sandbox-process-linux.d.ts.map +1 -0
- package/dist/agent-runtime/sandbox-process-macos.d.ts +21 -0
- package/dist/agent-runtime/sandbox-process-macos.d.ts.map +1 -0
- package/dist/agent-runtime/sandbox-process-spec.d.ts +114 -0
- package/dist/agent-runtime/sandbox-process-spec.d.ts.map +1 -0
- package/dist/agent-runtime/sandbox-process-wrapper.d.ts +19 -0
- package/dist/agent-runtime/sandbox-process-wrapper.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-message.d.ts +10 -0
- package/dist/agent-runtime/schemas-message.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-provider.d.ts +2 -0
- package/dist/agent-runtime/schemas-provider.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-run.d.ts +10 -0
- package/dist/agent-runtime/schemas-run.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-usage-state.d.ts +6 -0
- package/dist/agent-runtime/schemas-usage-state.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-usage.d.ts +8 -0
- package/dist/agent-runtime/schemas-usage.d.ts.map +1 -1
- package/dist/agent-runtime/sql-rows.d.ts +20 -10
- package/dist/agent-runtime/sql-rows.d.ts.map +1 -1
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts +40 -20
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts.map +1 -1
- package/dist/agent-runtime/store-conformance-support.d.ts +20 -10
- package/dist/agent-runtime/store-conformance-support.d.ts.map +1 -1
- package/dist/agent-runtime/store-driver-contract.d.ts +70 -0
- package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
- package/dist/agent-runtime/store-events.d.ts +120 -0
- package/dist/agent-runtime/store-events.d.ts.map +1 -1
- package/dist/agent-runtime/store.d.ts +140 -0
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/agent-runtime/terminal-commit.d.ts +10 -0
- package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
- package/dist/agent-runtime/testing.d.ts +20 -0
- package/dist/agent-runtime/testing.d.ts.map +1 -1
- package/dist/browser/client-call-arguments.d.ts.map +1 -1
- package/dist/browser/client-executors.d.ts.map +1 -1
- package/dist/browser/client-url.d.ts.map +1 -1
- package/dist/browser/client.d.ts +6 -0
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/device-presence-client.d.ts +42 -0
- package/dist/browser/device-presence-client.d.ts.map +1 -0
- package/dist/browser/device-presence-ops.d.ts +47 -0
- package/dist/browser/device-presence-ops.d.ts.map +1 -0
- package/dist/browser/device-presence-relay-adapter.d.ts +37 -0
- package/dist/browser/device-presence-relay-adapter.d.ts.map +1 -0
- package/dist/browser/http-fetch.d.ts +7 -2
- package/dist/browser/http-fetch.d.ts.map +1 -1
- package/dist/browser/http-helpers.d.ts +15 -0
- package/dist/browser/http-helpers.d.ts.map +1 -0
- package/dist/browser/http.d.ts +8 -0
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/contract/client-types.d.ts +8 -0
- package/dist/contract/client-types.d.ts.map +1 -1
- package/dist/contract/runtime-context.d.ts +13 -1
- package/dist/contract/runtime-context.d.ts.map +1 -1
- package/dist/device-relay/agent-handlers.d.ts +45 -0
- package/dist/device-relay/agent-handlers.d.ts.map +1 -0
- package/dist/device-relay/agent.d.ts +80 -0
- package/dist/device-relay/agent.d.ts.map +1 -0
- package/dist/device-relay/broker.d.ts +49 -0
- package/dist/device-relay/broker.d.ts.map +1 -0
- package/dist/device-relay/contract.d.ts +614 -0
- package/dist/device-relay/contract.d.ts.map +1 -0
- package/dist/device-relay/encoding.d.ts +30 -0
- package/dist/device-relay/encoding.d.ts.map +1 -0
- package/dist/device-relay/hub-connection.d.ts +43 -0
- package/dist/device-relay/hub-connection.d.ts.map +1 -0
- package/dist/device-relay/hub-dispatch.d.ts +19 -0
- package/dist/device-relay/hub-dispatch.d.ts.map +1 -0
- package/dist/device-relay/hub-handshake.d.ts +20 -0
- package/dist/device-relay/hub-handshake.d.ts.map +1 -0
- package/dist/device-relay/hub-shared-streams.d.ts +24 -0
- package/dist/device-relay/hub-shared-streams.d.ts.map +1 -0
- package/dist/device-relay/hub-streams.d.ts +57 -0
- package/dist/device-relay/hub-streams.d.ts.map +1 -0
- package/dist/device-relay/hub.d.ts +117 -0
- package/dist/device-relay/hub.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/acp.d.ts +1 -1
- package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +183 -29
- package/dist/entrypoints/agent-executor/claude-sdk.js +15 -15
- package/dist/entrypoints/agent-executor/claude.js +13 -15
- package/dist/entrypoints/agent-executor/codex.js +88 -48
- package/dist/entrypoints/agent-executor/testing/claude-sdk.js +5 -5
- package/dist/entrypoints/agent-executor/testing.js +31 -30
- package/dist/entrypoints/agent-executor.d.ts +2 -2
- package/dist/entrypoints/agent-executor.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor.js +23 -17
- package/dist/entrypoints/agent-runtime/ai-sdk.d.ts +9 -0
- package/dist/entrypoints/agent-runtime/ai-sdk.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/ai-sdk.js +821 -0
- package/dist/entrypoints/agent-runtime/anthropic.d.ts +4 -0
- package/dist/entrypoints/agent-runtime/anthropic.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/anthropic.js +1260 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts +4 -1
- package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +449 -50
- package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
- package/dist/entrypoints/agent-runtime/harness.js +24 -19
- package/dist/entrypoints/agent-runtime/openai.d.ts +4 -0
- package/dist/entrypoints/agent-runtime/openai.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/openai.js +1246 -0
- package/dist/entrypoints/agent-runtime/openrouter.d.ts +5 -2
- package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/openrouter.js +2355 -371
- package/dist/entrypoints/agent-runtime/postgres.js +12 -10
- package/dist/entrypoints/agent-runtime/realtime.js +11 -10
- package/dist/entrypoints/agent-runtime/sandbox.d.ts +3 -0
- package/dist/entrypoints/agent-runtime/sandbox.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/sandbox.js +530 -7
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +13 -11
- package/dist/entrypoints/agent-runtime/sqlite/node.js +13 -11
- package/dist/entrypoints/agent-runtime/testing.d.ts +1 -1
- package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/testing.js +56 -15
- package/dist/entrypoints/agent-runtime.d.ts +14 -6
- package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime.js +1412 -115
- package/dist/entrypoints/application/diagnostic-journal.js +6 -6
- package/dist/entrypoints/application/directory-inbox.js +6 -6
- package/dist/entrypoints/application/opentelemetry.js +3 -3
- package/dist/entrypoints/application.js +17 -17
- package/dist/entrypoints/cli/publish.js +8 -8
- package/dist/entrypoints/cli.js +14 -15
- package/dist/entrypoints/contract.d.ts +1 -0
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +13 -9
- package/dist/entrypoints/device-relay.d.ts +10 -0
- package/dist/entrypoints/device-relay.d.ts.map +1 -0
- package/dist/entrypoints/device-relay.js +2517 -0
- package/dist/entrypoints/files/packaging.js +3 -3
- package/dist/entrypoints/files.js +11 -11
- package/dist/entrypoints/geo.js +5 -5
- package/dist/entrypoints/google.js +1 -1
- package/dist/entrypoints/handler.js +6 -6
- package/dist/entrypoints/http.js +9 -9
- package/dist/entrypoints/index.js +21 -17
- package/dist/entrypoints/live.js +4 -4
- package/dist/entrypoints/node.js +13 -13
- package/dist/entrypoints/observability.js +9 -9
- package/dist/entrypoints/process/bootstrap.js +1 -1
- package/dist/entrypoints/process.js +5 -5
- package/dist/entrypoints/react.js +4 -4
- package/dist/entrypoints/realtime.d.ts +3 -0
- package/dist/entrypoints/realtime.d.ts.map +1 -1
- package/dist/entrypoints/realtime.js +413 -4
- package/dist/entrypoints/release.js +1 -1
- package/dist/entrypoints/remote.js +10 -10
- package/dist/entrypoints/server.d.ts +1 -0
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +546 -40
- package/dist/entrypoints/service-host/macos.js +10 -10
- package/dist/entrypoints/service-host/work.js +7 -7
- package/dist/entrypoints/service-host.js +15 -15
- package/dist/entrypoints/spend.js +3 -3
- package/dist/entrypoints/sync.js +4 -4
- package/dist/entrypoints/telegram/screens.js +6 -6
- package/dist/entrypoints/telegram.js +20 -20
- package/dist/entrypoints/testing.js +14 -14
- package/dist/entrypoints/tools/agent.d.ts +2 -1
- package/dist/entrypoints/tools/agent.d.ts.map +1 -1
- package/dist/entrypoints/tools/agent.js +8 -7
- package/dist/entrypoints/tools/connections.js +5 -5
- package/dist/entrypoints/tools/invoker.js +3 -4
- package/dist/entrypoints/tools/mcp.js +8 -9
- package/dist/entrypoints/tools/toolkit.js +32 -13
- package/dist/entrypoints/tools.d.ts +3 -1
- package/dist/entrypoints/tools.d.ts.map +1 -1
- package/dist/entrypoints/tools.js +37 -35
- package/dist/entrypoints/tracking/contract.js +1 -1
- package/dist/entrypoints/tracking/performance.js +4 -4
- package/dist/entrypoints/tracking.js +3 -3
- package/dist/{index-09f7w2qq.js → index-02kdtrcd.js} +1 -1
- package/dist/{index-y53cqwke.js → index-033tyx59.js} +1 -1
- package/dist/{index-9ft4n9j1.js → index-05b65gj4.js} +2 -2
- package/dist/{index-d04w81fz.js → index-0sxj3y45.js} +1 -1
- package/dist/{index-dm6nxkn1.js → index-18pf56dq.js} +4 -6
- package/dist/index-1gmgwfn3.js +439 -0
- package/dist/index-23wn8sgf.js +47 -0
- package/dist/{index-tqjamnax.js → index-27srek2g.js} +15 -13
- package/dist/{index-2nwvn7m2.js → index-29v1p1f4.js} +2 -2
- package/dist/index-36dmtzjr.js +194 -0
- package/dist/{index-ycr4pk0z.js → index-42n9jycn.js} +3 -3
- package/dist/{index-ke02kxsr.js → index-43k180c2.js} +1 -1
- package/dist/{index-pbekeqzm.js → index-5c4m8zdf.js} +2 -2
- package/dist/{index-qggqqja2.js → index-5dxgx3yj.js} +1 -1
- package/dist/{index-x5ayy5bn.js → index-5gdexvke.js} +3 -1
- package/dist/{index-t1a2jrg7.js → index-5xsxvk2x.js} +1 -1
- package/dist/{index-mbd92r1w.js → index-654rhe5d.js} +1 -1
- package/dist/{index-2dzc7mv9.js → index-67pnt4bh.js} +1 -1
- package/dist/index-6kpwkpgx.js +415 -0
- package/dist/{index-s43tr4my.js → index-6kwdfb9m.js} +18 -3
- package/dist/{index-1qwd54n3.js → index-6nzzj7qr.js} +1 -1
- package/dist/{index-rkjfzs0a.js → index-6p5pshcd.js} +2 -2
- package/dist/{index-118aebbg.js → index-6t4c98gr.js} +1 -1
- package/dist/{index-pws5c3x6.js → index-6xw1wf4m.js} +51 -32
- package/dist/{index-kwsr7j5k.js → index-6yb4stq3.js} +1 -1
- package/dist/{index-8jf4bt7v.js → index-76yhxa41.js} +8 -8
- package/dist/{index-7416mhyh.js → index-79vqbjcz.js} +1 -1
- package/dist/{index-13wmzpa6.js → index-7an2fs5h.js} +1 -1
- package/dist/index-7qza24g1.js +14 -0
- package/dist/{index-gtaaxe9d.js → index-8cek82ar.js} +1 -1
- package/dist/index-9f60gnfn.js +393 -0
- package/dist/{index-stpy56r3.js → index-aacwkve4.js} +209 -10
- package/dist/{index-rpyn7geq.js → index-ac3rfec5.js} +2 -2
- package/dist/{index-d2drhb9c.js → index-b0mh2t9x.js} +2 -2
- package/dist/index-b23s6e2c.js +158 -0
- package/dist/{index-an7vcmwf.js → index-bvpevwt6.js} +5 -5
- package/dist/{index-msxf2r8x.js → index-by8w2461.js} +1 -1
- package/dist/{index-8t9dr41h.js → index-c0yym4a0.js} +4 -4
- package/dist/{index-wddcfbng.js → index-c7fj4yw9.js} +1 -1
- package/dist/{index-tf70nm22.js → index-cb4nnvfr.js} +8 -6
- package/dist/{index-205456mf.js → index-d3s070eh.js} +2 -2
- package/dist/{index-apf5g7y9.js → index-dz6tstcp.js} +2 -2
- package/dist/{index-agy5fqgf.js → index-e1y74yra.js} +15 -8
- package/dist/index-edtg4tak.js +55 -0
- package/dist/{index-pq6g1k9t.js → index-ek9w11r0.js} +2 -2
- package/dist/{index-x46y9z26.js → index-epyj7ptp.js} +7 -5
- package/dist/{index-6kmjcm81.js → index-er483f3w.js} +93 -4
- package/dist/{index-827bgv33.js → index-f16b7rze.js} +1 -1
- package/dist/{index-gbhj370g.js → index-fec05c9k.js} +21 -21
- package/dist/{index-9wdrwx3b.js → index-fjac2w5e.js} +20 -22
- package/dist/{index-6918kxbf.js → index-fthw8dwa.js} +1 -0
- package/dist/{index-2mz8hj58.js → index-g04hszcm.js} +1 -1
- package/dist/{index-rw8ze745.js → index-ga6avd48.js} +1 -1
- package/dist/{index-paff5y0r.js → index-grhhsrd5.js} +9 -7
- package/dist/{index-mxt0wfjy.js → index-h20qcyh5.js} +5 -2
- package/dist/index-j3r7r1mh.js +150 -0
- package/dist/{index-vgytj9wp.js → index-jmaw365j.js} +1 -1
- package/dist/{index-cjytermm.js → index-jzdbkanz.js} +3 -3
- package/dist/index-k137ezb6.js +79 -0
- package/dist/{index-tazm4dxf.js → index-kdw0n92g.js} +1 -1
- package/dist/{index-wh70tmpd.js → index-ke6jtxkd.js} +1 -1
- package/dist/index-kgj8j7bv.js +83 -0
- package/dist/{index-9kpxz49v.js → index-kgkevngs.js} +1 -1
- package/dist/{index-hab790s6.js → index-kp1j7cc8.js} +4 -4
- package/dist/{index-jcge9tx3.js → index-krekhmp7.js} +142 -123
- package/dist/{index-3y2tzhr8.js → index-ky79wwgs.js} +4 -4
- package/dist/{index-39rmc00v.js → index-mfe9a266.js} +1 -1
- package/dist/{index-qpzyahe3.js → index-mgr0mdqp.js} +5 -2
- package/dist/{index-n20tybgk.js → index-mh3jdb25.js} +2 -2
- package/dist/{index-g5fgeb6v.js → index-mkmep637.js} +1 -1
- package/dist/{index-02r5sq9p.js → index-mrng24wq.js} +19 -21
- package/dist/index-mx2gya05.js +465 -0
- package/dist/{index-8yt3rwe7.js → index-n2t87ggz.js} +5 -5
- package/dist/index-nfeafbzh.js +7379 -0
- package/dist/{index-j0ef04jw.js → index-nfm15ej7.js} +4 -4
- package/dist/index-pd9e8rz4.js +193 -0
- package/dist/{index-zwgwyvdt.js → index-pdcbjd6a.js} +1 -1
- package/dist/{index-q427q23r.js → index-pjjh91vw.js} +2 -2
- package/dist/{index-gnjgkecx.js → index-q46b16xz.js} +1 -1
- package/dist/{index-9xr44d2g.js → index-qv5v6w9c.js} +330 -106
- package/dist/{index-tmv3ez1h.js → index-qymek778.js} +69 -12
- package/dist/{index-yrr3n391.js → index-ry8m2mhg.js} +2 -2
- package/dist/{index-93n6jwy0.js → index-s0n0nnz5.js} +3 -3
- package/dist/{index-1p8q0yrt.js → index-t5zp1jjj.js} +5 -7
- package/dist/{index-2rf33y2h.js → index-tav72wz5.js} +4 -2
- package/dist/{index-jpecjm30.js → index-tgehj4bp.js} +1 -1
- package/dist/{index-ma26mfnt.js → index-v5hmyef8.js} +1 -1
- package/dist/index-vebzvse6.js +230 -0
- package/dist/index-vv0hxrmy.js +295 -0
- package/dist/index-vxm0ya3f.js +707 -0
- package/dist/{index-t3qcac2a.js → index-w3s79kcb.js} +1 -1
- package/dist/{index-r97ppg0g.js → index-x1r7kxzd.js} +1 -1
- package/dist/{index-kynwa08q.js → index-xrsryvd2.js} +2 -2
- package/dist/{index-3mcbr8sx.js → index-xtxxt87z.js} +1 -1
- package/dist/index-zk839vzf.js +231 -0
- package/dist/{index-9c76vfxf.js → index-zyyerdny.js} +4 -4
- package/dist/internal/base64.d.ts +9 -0
- package/dist/internal/base64.d.ts.map +1 -0
- package/dist/internal/deadline-budget.d.ts +57 -0
- package/dist/internal/deadline-budget.d.ts.map +1 -0
- package/dist/internal/deadline.d.ts.map +1 -1
- package/dist/internal/timers.d.ts +2 -0
- package/dist/internal/timers.d.ts.map +1 -1
- package/dist/realtime/device-presence-contract.d.ts +194 -0
- package/dist/realtime/device-presence-contract.d.ts.map +1 -0
- package/dist/server/context-contribution.d.ts.map +1 -1
- package/dist/server/contract-method.d.ts.map +1 -1
- package/dist/server/device-presence-handlers.d.ts +54 -0
- package/dist/server/device-presence-handlers.d.ts.map +1 -0
- package/dist/server/device-presence-registry.d.ts +35 -0
- package/dist/server/device-presence-registry.d.ts.map +1 -0
- package/dist/server/device-presence.d.ts +45 -0
- package/dist/server/device-presence.d.ts.map +1 -0
- package/dist/server/endpoint-dispatch.d.ts.map +1 -1
- package/dist/server/middleware/cors.d.ts +3 -1
- package/dist/server/middleware/cors.d.ts.map +1 -1
- package/dist/server/types.d.ts +4 -11
- package/dist/server/types.d.ts.map +1 -1
- package/dist/service-host/systemd-render-shared.d.ts.map +1 -1
- package/dist/tools/agent-messages.d.ts +6 -0
- package/dist/tools/agent-messages.d.ts.map +1 -0
- package/dist/tools/agent-tool-error.d.ts +2 -2
- package/dist/tools/agent-tools.d.ts +153 -0
- package/dist/tools/agent-tools.d.ts.map +1 -0
- package/dist/tools/agent.d.ts +6 -56
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts +3 -4
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/toolkit.d.ts +3 -1
- package/dist/tools/toolkit.d.ts.map +1 -1
- package/dist/tools/transfer/define-view-file-tool.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +2 -2
- package/llms/agent-executor-codex.txt +1 -1
- package/llms/agent-executor.txt +7 -3
- package/llms/agent-runtime-ai-sdk.txt +26 -0
- package/llms/agent-runtime-anthropic.txt +33 -0
- package/llms/agent-runtime-browser.txt +22 -8
- package/llms/agent-runtime-harness.txt +2 -2
- package/llms/agent-runtime-openai.txt +31 -0
- package/llms/agent-runtime-openrouter.txt +17 -7
- package/llms/agent-runtime-sandbox.txt +53 -1
- package/llms/agent-runtime-testing.txt +4 -2
- package/llms/agent-runtime.2.txt +158 -271
- package/llms/agent-runtime.3.txt +289 -243
- package/llms/agent-runtime.4.txt +273 -216
- package/llms/agent-runtime.5.txt +209 -2
- package/llms/agent-runtime.txt +238 -181
- package/llms/contract.txt +2 -1
- package/llms/device-relay.txt +34 -0
- package/llms/realtime.txt +20 -0
- package/llms/server.2.txt +125 -1
- package/llms/server.3.txt +111 -122
- package/llms/server.4.txt +1 -1
- package/llms/server.5.txt +3 -1
- package/llms/server.txt +31 -1
- package/llms/spend.txt +11 -6
- package/llms/stitchkit.2.txt +21 -43
- package/llms/stitchkit.3.txt +43 -0
- package/llms/stitchkit.txt +93 -84
- package/llms/tools-agent.txt +7 -5
- package/llms/tools-toolkit.txt +1 -1
- package/llms/tools.4.txt +7 -2
- package/llms/{upgrading-0.128.0-0.133.0.txt → upgrading-0.128.0-0.134.0.txt} +173 -3
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +981 -210
- package/llms.txt +21 -17
- package/package.json +18 -7
- package/dist/index-0p0s5hrj.js +0 -249
- package/dist/index-1dn2wjq6.js +0 -135
- package/dist/index-1psbyyhj.js +0 -21
- package/dist/index-34k82crg.js +0 -3961
- package/dist/index-5n3a8hd8.js +0 -102
- package/dist/index-97rp94ff.js +0 -8
- package/dist/index-bn2baakz.js +0 -336
- package/dist/index-eh71zr32.js +0 -14
- package/dist/index-emgrmavr.js +0 -1193
- package/dist/index-fzd477xk.js +0 -135
- package/dist/index-vgzhw2zk.js +0 -304
- package/dist/internal/ai-sdk-typed.d.ts +0 -14
- package/dist/internal/ai-sdk-typed.d.ts.map +0 -1
- package/dist/tools/runtime-call-context.d.ts +0 -15
- package/dist/tools/runtime-call-context.d.ts.map +0 -1
- package/dist/{index-vmbxj75t.js → index-jwtmw39p.js} +0 -0
- package/dist/{index-877e9y8r.js → index-sk03xe0n.js} +3 -3
- package/dist/{index-21cfxc4z.js → index-vh4291qh.js} +3 -3
package/dist/index-emgrmavr.js
DELETED
|
@@ -1,1193 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AgentRecordIdSchema2,
|
|
3
|
-
AgentJsonObjectSchema2,
|
|
4
|
-
AgentMessageSchema2,
|
|
5
|
-
AgentUsageSchema2
|
|
6
|
-
} from "./index-bn2baakz.js";
|
|
7
|
-
import {
|
|
8
|
-
AgentMessagePartSchema2
|
|
9
|
-
} from "./index-2rf33y2h.js";
|
|
10
|
-
import {
|
|
11
|
-
AgentProviderResponseSchema2
|
|
12
|
-
} from "./index-97rp94ff.js";
|
|
13
|
-
import {
|
|
14
|
-
InvocationPayloadSchema,
|
|
15
|
-
ModelInvocationTraceSchema2,
|
|
16
|
-
assistantStatus
|
|
17
|
-
} from "./index-vgzhw2zk.js";
|
|
18
|
-
import {
|
|
19
|
-
agentDurableEventId2
|
|
20
|
-
} from "./index-paff5y0r.js";
|
|
21
|
-
import {
|
|
22
|
-
serializeCanonicalJson
|
|
23
|
-
} from "./index-fmzg39a8.js";
|
|
24
|
-
import {
|
|
25
|
-
withDeadline
|
|
26
|
-
} from "./index-agy5fqgf.js";
|
|
27
|
-
import {
|
|
28
|
-
linkAbortSignals
|
|
29
|
-
} from "./index-rptj3qnc.js";
|
|
30
|
-
|
|
31
|
-
// src/agent-runtime/run-step-spend.ts
|
|
32
|
-
import { z as z2 } from "zod";
|
|
33
|
-
|
|
34
|
-
// src/agent-runtime/runtime-internals.ts
|
|
35
|
-
import { z } from "zod";
|
|
36
|
-
|
|
37
|
-
// src/agent-runtime/run-store-retry.ts
|
|
38
|
-
var STORE_RETRY_DELAYS_MS = [25, 100, 400];
|
|
39
|
-
function storeRetryDelay(failures) {
|
|
40
|
-
return STORE_RETRY_DELAYS_MS[failures];
|
|
41
|
-
}
|
|
42
|
-
async function withStoreRetries(work) {
|
|
43
|
-
for (let failures = 0;; failures += 1) {
|
|
44
|
-
try {
|
|
45
|
-
return await work();
|
|
46
|
-
} catch (error) {
|
|
47
|
-
const delay = storeRetryDelay(failures);
|
|
48
|
-
if (delay === undefined)
|
|
49
|
-
throw error;
|
|
50
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/agent-runtime/terminal-commit.ts
|
|
56
|
-
class AgentRuntimeConflictError2 extends Error {
|
|
57
|
-
constructor(operation) {
|
|
58
|
-
super(`Agent runtime store conflict during ${operation}`);
|
|
59
|
-
this.name = "AgentRuntimeConflictError";
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
class AgentRunUnsettledError2 extends Error {
|
|
64
|
-
run;
|
|
65
|
-
ownerId;
|
|
66
|
-
constructor(run, ownerId, cause) {
|
|
67
|
-
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
68
|
-
super(`Agent run ${run.id} is still ${run.state} with no executor: ${reason}`, { cause });
|
|
69
|
-
this.name = "AgentRunUnsettledError";
|
|
70
|
-
this.run = run;
|
|
71
|
-
this.ownerId = ownerId;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function appliedSnapshot(result, operation) {
|
|
75
|
-
if (result.outcome === "applied" || result.outcome === "duplicate")
|
|
76
|
-
return result.snapshot;
|
|
77
|
-
throw new AgentRuntimeConflictError2(operation);
|
|
78
|
-
}
|
|
79
|
-
function viewOfSnapshot(snapshot, runId, retainedAssistant) {
|
|
80
|
-
const run = snapshot.runs.find((candidate) => candidate.id === runId);
|
|
81
|
-
const assistant = snapshot.messages.find((message) => message.id === run?.assistantMessageId) ?? retainedAssistant;
|
|
82
|
-
return {
|
|
83
|
-
snapshotVersion: snapshot.version,
|
|
84
|
-
conversationId: snapshot.conversationId,
|
|
85
|
-
...run && { run },
|
|
86
|
-
...assistant && { assistant }
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function terminalOfSnapshot(snapshot, runId) {
|
|
90
|
-
return canonicalTerminal(viewOfSnapshot(snapshot, runId));
|
|
91
|
-
}
|
|
92
|
-
function terminalOfRunView(view, conversationId) {
|
|
93
|
-
return canonicalTerminal(viewOfRun(view, conversationId));
|
|
94
|
-
}
|
|
95
|
-
function viewOfRun(view, conversationId) {
|
|
96
|
-
return {
|
|
97
|
-
snapshotVersion: view.snapshotVersion,
|
|
98
|
-
conversationId,
|
|
99
|
-
run: view.run,
|
|
100
|
-
...view.assistant && { assistant: view.assistant }
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function canonicalTerminal(view) {
|
|
104
|
-
const { run, assistant } = view;
|
|
105
|
-
if (!run?.terminalReason)
|
|
106
|
-
return;
|
|
107
|
-
if (view.conversationId !== run.conversationId || !assistant || assistant.id !== run.assistantMessageId || assistant.conversationId !== run.conversationId || assistant.runId !== run.id || assistant.role !== "assistant" || assistant.status !== assistantStatus(run.terminalReason)) {
|
|
108
|
-
throw new AgentRuntimeConflictError2("terminal result projection");
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
snapshotVersion: view.snapshotVersion,
|
|
112
|
-
run,
|
|
113
|
-
assistant,
|
|
114
|
-
reason: run.terminalReason,
|
|
115
|
-
committedByCaller: false,
|
|
116
|
-
...run.terminalPolicyName && { policyName: run.terminalPolicyName },
|
|
117
|
-
...run.usage && { usage: run.usage }
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function interruptedCandidate(candidate, run, now) {
|
|
121
|
-
const reason = candidate.reason === "superseded" ? "superseded" : "interrupted";
|
|
122
|
-
const hasInterruptControl = candidate.assistant.parts.some((part) => part.type === "control" && part.reason === "run-interrupted");
|
|
123
|
-
const parts = hasInterruptControl ? candidate.assistant.parts : [
|
|
124
|
-
...candidate.assistant.parts,
|
|
125
|
-
AgentMessagePartSchema2.parse({ type: "control", reason: "run-interrupted" })
|
|
126
|
-
];
|
|
127
|
-
return {
|
|
128
|
-
...candidate.usage && { usage: candidate.usage },
|
|
129
|
-
run,
|
|
130
|
-
assistant: AgentMessageSchema2.parse({
|
|
131
|
-
...candidate.assistant,
|
|
132
|
-
status: assistantStatus(reason),
|
|
133
|
-
parts,
|
|
134
|
-
updatedAt: now().toISOString()
|
|
135
|
-
}),
|
|
136
|
-
reason
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
function canRetryTerminal(current, previous, runtimeEpoch) {
|
|
140
|
-
return (current.state === "running" || current.state === "interrupt_requested") && current.ownerId === runtimeEpoch && current.fencingToken === previous.fencingToken;
|
|
141
|
-
}
|
|
142
|
-
var TERMINAL_COMMIT_ATTEMPTS = 32;
|
|
143
|
-
async function attemptTerminalCommit(input, candidate) {
|
|
144
|
-
const committed = await input.store.commitRunTerminal({
|
|
145
|
-
conversationId: candidate.run.conversationId,
|
|
146
|
-
runId: candidate.run.id,
|
|
147
|
-
expectedRevision: candidate.run.revision,
|
|
148
|
-
ownerId: input.runtimeEpoch,
|
|
149
|
-
...candidate.run.fencingToken !== undefined && {
|
|
150
|
-
fencingToken: candidate.run.fencingToken
|
|
151
|
-
},
|
|
152
|
-
assistant: candidate.assistant,
|
|
153
|
-
reason: candidate.reason,
|
|
154
|
-
...candidate.policyName && { policyName: candidate.policyName },
|
|
155
|
-
...candidate.usage && { usage: candidate.usage },
|
|
156
|
-
...candidate.absorb?.length && { absorb: candidate.absorb }
|
|
157
|
-
});
|
|
158
|
-
if (committed.outcome === "applied") {
|
|
159
|
-
const terminal = canonicalTerminal(viewOfSnapshot(committed.snapshot, candidate.run.id));
|
|
160
|
-
if (!terminal)
|
|
161
|
-
throw new AgentRuntimeConflictError2("terminal result projection");
|
|
162
|
-
const absorbed = committed.snapshot.runs.filter((run) => run.absorbedIntoRunId === candidate.run.id);
|
|
163
|
-
return {
|
|
164
|
-
settled: {
|
|
165
|
-
...terminal,
|
|
166
|
-
committedByCaller: true,
|
|
167
|
-
...absorbed.length > 0 && { absorbed }
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
if (committed.outcome === "duplicate") {
|
|
172
|
-
const terminal = canonicalTerminal(viewOfSnapshot(committed.snapshot, candidate.run.id, committed.assistant));
|
|
173
|
-
if (!terminal)
|
|
174
|
-
throw new AgentRuntimeConflictError2("terminal result projection");
|
|
175
|
-
return { settled: terminal };
|
|
176
|
-
}
|
|
177
|
-
if (committed.outcome !== "conflict") {
|
|
178
|
-
throw new AgentRuntimeConflictError2("terminal commit");
|
|
179
|
-
}
|
|
180
|
-
const latest = await input.store.loadRun({
|
|
181
|
-
conversationId: candidate.run.conversationId,
|
|
182
|
-
runId: candidate.run.id
|
|
183
|
-
});
|
|
184
|
-
const terminal = latest ? canonicalTerminal(viewOfRun(latest, candidate.run.conversationId)) : undefined;
|
|
185
|
-
if (terminal)
|
|
186
|
-
return { settled: terminal };
|
|
187
|
-
const current = latest?.run;
|
|
188
|
-
if (!current || !canRetryTerminal(current, candidate.run, input.runtimeEpoch)) {
|
|
189
|
-
throw new AgentRuntimeConflictError2("terminal commit");
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
candidate: current.state === "interrupt_requested" ? interruptedCandidate(candidate, current, input.now) : { ...candidate, run: current }
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
async function absorbedBy(store, candidate) {
|
|
196
|
-
const views = await Promise.all((candidate.absorb ?? []).map(({ runId }) => store.loadRun({ conversationId: candidate.run.conversationId, runId }).catch(() => {
|
|
197
|
-
return;
|
|
198
|
-
})));
|
|
199
|
-
return views.flatMap((view) => view?.run.absorbedIntoRunId === candidate.run.id ? [view.run] : []);
|
|
200
|
-
}
|
|
201
|
-
async function commitAgentRunTerminal(input) {
|
|
202
|
-
let candidate = input.candidate;
|
|
203
|
-
let storeFailures = 0;
|
|
204
|
-
for (let attempt = 0;attempt < TERMINAL_COMMIT_ATTEMPTS; attempt += 1) {
|
|
205
|
-
try {
|
|
206
|
-
const round = await attemptTerminalCommit(input, candidate);
|
|
207
|
-
if (!round.settled) {
|
|
208
|
-
candidate = round.candidate;
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
const owned = storeFailures > 0 && round.settled.run.ownerId === input.runtimeEpoch && round.settled.run.fencingToken === candidate.run.fencingToken;
|
|
212
|
-
if (!owned)
|
|
213
|
-
return round.settled;
|
|
214
|
-
const absorbed = await absorbedBy(input.store, candidate);
|
|
215
|
-
return {
|
|
216
|
-
...round.settled,
|
|
217
|
-
committedByCaller: true,
|
|
218
|
-
...absorbed.length > 0 && { absorbed }
|
|
219
|
-
};
|
|
220
|
-
} catch (error) {
|
|
221
|
-
if (error instanceof AgentRuntimeConflictError2)
|
|
222
|
-
throw error;
|
|
223
|
-
const delay = storeRetryDelay(storeFailures);
|
|
224
|
-
if (delay === undefined)
|
|
225
|
-
throw error;
|
|
226
|
-
storeFailures += 1;
|
|
227
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
throw new AgentRuntimeConflictError2("terminal commit");
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// src/agent-runtime/runtime-internals.ts
|
|
234
|
-
function findRun(runs, runId) {
|
|
235
|
-
const run = runs.find((candidate) => candidate.id === runId);
|
|
236
|
-
if (!run)
|
|
237
|
-
throw new AgentRuntimeConflictError2("run lookup");
|
|
238
|
-
return run;
|
|
239
|
-
}
|
|
240
|
-
function jsonValue(value) {
|
|
241
|
-
const parsed = z.json().safeParse(value);
|
|
242
|
-
return parsed.success ? parsed.data : { message: "Non-JSON tool output omitted" };
|
|
243
|
-
}
|
|
244
|
-
function providerEnvelope(value) {
|
|
245
|
-
const parsed = AgentJsonObjectSchema2.safeParse(value);
|
|
246
|
-
if (!parsed.success)
|
|
247
|
-
return;
|
|
248
|
-
return { schemaVersion: 1, provider: "ai-sdk", data: parsed.data };
|
|
249
|
-
}
|
|
250
|
-
function providerResponseIdentity(id, provider) {
|
|
251
|
-
return AgentProviderResponseSchema2.parse({
|
|
252
|
-
id,
|
|
253
|
-
...typeof provider === "string" && provider.length > 0 ? { provider } : {}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
function appendText(parts, text) {
|
|
257
|
-
const previous = parts.at(-1);
|
|
258
|
-
if (previous?.type === "text") {
|
|
259
|
-
const next = AgentMessagePartSchema2.parse({ ...previous, text: previous.text + text });
|
|
260
|
-
parts.splice(parts.length - 1, 1, next);
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
parts.push(AgentMessagePartSchema2.parse({ type: "text", text }));
|
|
264
|
-
}
|
|
265
|
-
function abortTerminalReason(signal) {
|
|
266
|
-
if (signal.reason === "shutdown")
|
|
267
|
-
return "shutdown";
|
|
268
|
-
if (signal.reason === "timeout")
|
|
269
|
-
return "timeout";
|
|
270
|
-
if (signal.reason === "supersede")
|
|
271
|
-
return "superseded";
|
|
272
|
-
return "interrupted";
|
|
273
|
-
}
|
|
274
|
-
function addUsage(total, step) {
|
|
275
|
-
const sum = (left, right) => {
|
|
276
|
-
if (left?.value === undefined && right?.value === undefined) {
|
|
277
|
-
return { provenance: "unavailable" };
|
|
278
|
-
}
|
|
279
|
-
if (left?.value === undefined)
|
|
280
|
-
return { ...right, provenance: "computed" };
|
|
281
|
-
if (right?.value === undefined)
|
|
282
|
-
return { ...left, provenance: "computed" };
|
|
283
|
-
return { value: left.value + right.value, provenance: "computed" };
|
|
284
|
-
};
|
|
285
|
-
const sumCost = (left, right) => {
|
|
286
|
-
if (left?.value === undefined || right?.value === undefined) {
|
|
287
|
-
return { provenance: "unavailable" };
|
|
288
|
-
}
|
|
289
|
-
if (left.currency !== right.currency)
|
|
290
|
-
return { provenance: "unavailable" };
|
|
291
|
-
return {
|
|
292
|
-
value: left.value + right.value,
|
|
293
|
-
...left.currency && { currency: left.currency },
|
|
294
|
-
provenance: "computed"
|
|
295
|
-
};
|
|
296
|
-
};
|
|
297
|
-
if (!total)
|
|
298
|
-
return step;
|
|
299
|
-
const cost = sumCost(total.cost, step.cost);
|
|
300
|
-
return {
|
|
301
|
-
inputTokens: sum(total.inputTokens, step.inputTokens),
|
|
302
|
-
outputTokens: sum(total.outputTokens, step.outputTokens),
|
|
303
|
-
reasoningTokens: sum(total.reasoningTokens, step.reasoningTokens),
|
|
304
|
-
cacheReadTokens: sum(total.cacheReadTokens, step.cacheReadTokens),
|
|
305
|
-
cacheWriteTokens: sum(total.cacheWriteTokens, step.cacheWriteTokens),
|
|
306
|
-
...cost && { cost }
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
function mergeModelTotals(sdkTotal, accumulated) {
|
|
310
|
-
const pick = (total, ours) => {
|
|
311
|
-
if (ours?.provenance === "unavailable")
|
|
312
|
-
return ours;
|
|
313
|
-
return total?.value !== undefined ? { value: total.value, provenance: "computed" } : ours ?? { provenance: "unavailable" };
|
|
314
|
-
};
|
|
315
|
-
return {
|
|
316
|
-
inputTokens: pick(sdkTotal.inputTokens, accumulated?.inputTokens),
|
|
317
|
-
outputTokens: pick(sdkTotal.outputTokens, accumulated?.outputTokens),
|
|
318
|
-
reasoningTokens: pick(sdkTotal.reasoningTokens, accumulated?.reasoningTokens),
|
|
319
|
-
cacheReadTokens: pick(sdkTotal.cacheReadTokens, accumulated?.cacheReadTokens),
|
|
320
|
-
cacheWriteTokens: pick(sdkTotal.cacheWriteTokens, accumulated?.cacheWriteTokens),
|
|
321
|
-
cost: accumulated?.cost ?? { provenance: "unavailable" }
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
function statedUsage(usage) {
|
|
325
|
-
const stated = (value) => value ?? { provenance: "unavailable" };
|
|
326
|
-
if (!usage)
|
|
327
|
-
return unknownUsage();
|
|
328
|
-
return {
|
|
329
|
-
inputTokens: stated(usage.inputTokens),
|
|
330
|
-
outputTokens: stated(usage.outputTokens),
|
|
331
|
-
reasoningTokens: stated(usage.reasoningTokens),
|
|
332
|
-
cacheReadTokens: stated(usage.cacheReadTokens),
|
|
333
|
-
cacheWriteTokens: stated(usage.cacheWriteTokens),
|
|
334
|
-
cost: stated(usage.cost)
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
function unknownUsage() {
|
|
338
|
-
const nothing = { provenance: "unavailable" };
|
|
339
|
-
return {
|
|
340
|
-
inputTokens: nothing,
|
|
341
|
-
outputTokens: nothing,
|
|
342
|
-
reasoningTokens: nothing,
|
|
343
|
-
cacheReadTokens: nothing,
|
|
344
|
-
cacheWriteTokens: nothing,
|
|
345
|
-
cost: nothing
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
function normalizeSdkUsage(value) {
|
|
349
|
-
const reported = (tokens) => tokens === undefined || !Number.isSafeInteger(tokens) || tokens < 0 ? { provenance: "unavailable" } : { value: tokens, provenance: "provider-reported" };
|
|
350
|
-
return {
|
|
351
|
-
inputTokens: reported(value.inputTokens),
|
|
352
|
-
outputTokens: reported(value.outputTokens),
|
|
353
|
-
reasoningTokens: reported(value.outputTokenDetails.reasoningTokens),
|
|
354
|
-
cacheReadTokens: reported(value.inputTokenDetails.cacheReadTokens),
|
|
355
|
-
cacheWriteTokens: reported(value.inputTokenDetails.cacheWriteTokens)
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
function createIdleDeadline(parent, timeoutMs) {
|
|
359
|
-
if (timeoutMs === undefined) {
|
|
360
|
-
const noop = () => {
|
|
361
|
-
return;
|
|
362
|
-
};
|
|
363
|
-
return {
|
|
364
|
-
signal: parent,
|
|
365
|
-
touch: noop,
|
|
366
|
-
start: noop,
|
|
367
|
-
stop: noop,
|
|
368
|
-
suspend: noop,
|
|
369
|
-
resume: noop,
|
|
370
|
-
dispose: noop,
|
|
371
|
-
release: noop
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
const controller = new AbortController;
|
|
375
|
-
const link = linkAbortSignals(parent, controller.signal);
|
|
376
|
-
let timer;
|
|
377
|
-
let active = false;
|
|
378
|
-
let suspended = 0;
|
|
379
|
-
const clear = () => {
|
|
380
|
-
if (timer !== undefined)
|
|
381
|
-
clearTimeout(timer);
|
|
382
|
-
timer = undefined;
|
|
383
|
-
};
|
|
384
|
-
const touch = () => {
|
|
385
|
-
clear();
|
|
386
|
-
if (!active || suspended > 0 || controller.signal.aborted)
|
|
387
|
-
return;
|
|
388
|
-
timer = setTimeout(() => controller.abort("timeout"), timeoutMs);
|
|
389
|
-
};
|
|
390
|
-
return {
|
|
391
|
-
signal: link.signal,
|
|
392
|
-
touch,
|
|
393
|
-
start() {
|
|
394
|
-
active = true;
|
|
395
|
-
touch();
|
|
396
|
-
},
|
|
397
|
-
stop() {
|
|
398
|
-
active = false;
|
|
399
|
-
clear();
|
|
400
|
-
},
|
|
401
|
-
suspend() {
|
|
402
|
-
suspended += 1;
|
|
403
|
-
clear();
|
|
404
|
-
},
|
|
405
|
-
resume() {
|
|
406
|
-
suspended = Math.max(0, suspended - 1);
|
|
407
|
-
touch();
|
|
408
|
-
},
|
|
409
|
-
dispose() {
|
|
410
|
-
active = false;
|
|
411
|
-
clear();
|
|
412
|
-
},
|
|
413
|
-
release: link.release
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// src/agent-runtime/run-execution-state.ts
|
|
418
|
-
function adoptSnapshot(state, next) {
|
|
419
|
-
state.snapshot = next;
|
|
420
|
-
state.observedVersion = next.version;
|
|
421
|
-
state.run = findRun(next.runs, state.run.id);
|
|
422
|
-
}
|
|
423
|
-
function transientSequence(state) {
|
|
424
|
-
state.sequence += 1;
|
|
425
|
-
return state.sequence;
|
|
426
|
-
}
|
|
427
|
-
function billedUsage(state) {
|
|
428
|
-
return state.abandonedUsage && state.modelUsage ? addUsage(state.abandonedUsage, state.modelUsage) : state.abandonedUsage ?? state.modelUsage;
|
|
429
|
-
}
|
|
430
|
-
function runUsage(state) {
|
|
431
|
-
const billed = billedUsage(state);
|
|
432
|
-
return state.nonModelUsage && billed ? addUsage(state.nonModelUsage, billed) : billed ?? state.nonModelUsage;
|
|
433
|
-
}
|
|
434
|
-
function updateReasoning(state, text, metadata) {
|
|
435
|
-
const { parts } = state;
|
|
436
|
-
const provider = providerEnvelope(metadata);
|
|
437
|
-
if (state.reasoningPartIndex === undefined) {
|
|
438
|
-
state.reasoningPartIndex = parts.length;
|
|
439
|
-
parts.push(AgentMessagePartSchema2.parse({
|
|
440
|
-
type: "reasoning",
|
|
441
|
-
text,
|
|
442
|
-
...provider && { provider }
|
|
443
|
-
}));
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
const current = parts[state.reasoningPartIndex];
|
|
447
|
-
if (current?.type !== "reasoning") {
|
|
448
|
-
throw new AgentRuntimeConflictError2("reasoning accumulator");
|
|
449
|
-
}
|
|
450
|
-
parts.splice(state.reasoningPartIndex, 1, AgentMessagePartSchema2.parse({
|
|
451
|
-
...current,
|
|
452
|
-
text: current.text + text,
|
|
453
|
-
...provider && { provider }
|
|
454
|
-
}));
|
|
455
|
-
}
|
|
456
|
-
function checkpoint(execution, toolStatus) {
|
|
457
|
-
const { config, runtimeEpoch, publish, now } = execution.dependencies;
|
|
458
|
-
const { state } = execution;
|
|
459
|
-
return execution.serialize(async () => {
|
|
460
|
-
state.assistant = AgentMessageSchema2.parse({
|
|
461
|
-
...state.assistant,
|
|
462
|
-
parts: state.parts,
|
|
463
|
-
updatedAt: now().toISOString()
|
|
464
|
-
});
|
|
465
|
-
const run = state.run;
|
|
466
|
-
adoptSnapshot(state, appliedSnapshot(await config.store.checkpointRunAssistant({
|
|
467
|
-
conversationId: run.conversationId,
|
|
468
|
-
runId: run.id,
|
|
469
|
-
expectedRevision: run.revision,
|
|
470
|
-
ownerId: runtimeEpoch,
|
|
471
|
-
...run.fencingToken !== undefined && { fencingToken: run.fencingToken },
|
|
472
|
-
assistant: state.assistant,
|
|
473
|
-
usage: statedUsage(state.usage)
|
|
474
|
-
}), "assistant checkpoint"));
|
|
475
|
-
const checkpointMetrics = {
|
|
476
|
-
partial: true,
|
|
477
|
-
durationMs: performance.now() - execution.runStartedAt,
|
|
478
|
-
usage: statedUsage(state.usage),
|
|
479
|
-
...state.firstOutputAt !== undefined && {
|
|
480
|
-
ttftMs: state.firstOutputAt - execution.runStartedAt
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
await publish({
|
|
484
|
-
type: "assistant-checkpoint",
|
|
485
|
-
eventId: agentDurableEventId2("assistant-checkpoint", state.run.id, state.observedVersion),
|
|
486
|
-
conversationId: state.run.conversationId,
|
|
487
|
-
runId: state.run.id,
|
|
488
|
-
snapshotVersion: state.observedVersion,
|
|
489
|
-
message: state.assistant,
|
|
490
|
-
metrics: checkpointMetrics,
|
|
491
|
-
emittedAt: now().toISOString()
|
|
492
|
-
});
|
|
493
|
-
if (toolStatus)
|
|
494
|
-
await publish({
|
|
495
|
-
type: "tool-status",
|
|
496
|
-
eventId: agentDurableEventId2("tool-status", state.run.id, state.observedVersion, `${toolStatus.callId}:${toolStatus.status}`),
|
|
497
|
-
conversationId: state.run.conversationId,
|
|
498
|
-
runId: state.run.id,
|
|
499
|
-
snapshotVersion: state.observedVersion,
|
|
500
|
-
...toolStatus,
|
|
501
|
-
emittedAt: now().toISOString()
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
// src/agent-runtime/run-step-spend.ts
|
|
507
|
-
var DEFAULT_STEP_SPEND_TIMEOUT_MS = 5000;
|
|
508
|
-
var AgentStepSpendPhaseSchema2 = z2.enum(["step", "abandoned-attempt", "compaction"]);
|
|
509
|
-
var AgentStepSpendProviderSchema = z2.strictObject({
|
|
510
|
-
key: z2.string().min(1),
|
|
511
|
-
upstream: z2.string().min(1).optional()
|
|
512
|
-
});
|
|
513
|
-
var StepSpendBaseShape = {
|
|
514
|
-
conversationId: AgentRecordIdSchema2,
|
|
515
|
-
runId: AgentRecordIdSchema2,
|
|
516
|
-
step: z2.int().nonnegative(),
|
|
517
|
-
attempt: z2.int().nonnegative(),
|
|
518
|
-
usage: AgentUsageSchema2,
|
|
519
|
-
trace: ModelInvocationTraceSchema2.optional()
|
|
520
|
-
};
|
|
521
|
-
var ModelStepSpendShape = {
|
|
522
|
-
...StepSpendBaseShape,
|
|
523
|
-
model: z2.string().min(1),
|
|
524
|
-
provider: AgentStepSpendProviderSchema,
|
|
525
|
-
response: AgentProviderResponseSchema2
|
|
526
|
-
};
|
|
527
|
-
var AgentStepSpendSchema2 = z2.discriminatedUnion("phase", [
|
|
528
|
-
z2.strictObject({ ...ModelStepSpendShape, phase: z2.literal("step") }),
|
|
529
|
-
z2.strictObject({ ...ModelStepSpendShape, phase: z2.literal("abandoned-attempt") }),
|
|
530
|
-
z2.strictObject({ ...StepSpendBaseShape, phase: z2.literal("compaction") })
|
|
531
|
-
]);
|
|
532
|
-
function normalizeStepUsage(selectedModel, usage, providerMetadata) {
|
|
533
|
-
return selectedModel?.normalizeUsage?.({
|
|
534
|
-
usage,
|
|
535
|
-
providerMetadata
|
|
536
|
-
}) ?? normalizeSdkUsage(usage);
|
|
537
|
-
}
|
|
538
|
-
async function callStepSpendHook(name, timeoutMs, call) {
|
|
539
|
-
let pending;
|
|
540
|
-
try {
|
|
541
|
-
pending = Promise.resolve(call());
|
|
542
|
-
} catch (error) {
|
|
543
|
-
return { code: "hook_error", cause: error };
|
|
544
|
-
}
|
|
545
|
-
try {
|
|
546
|
-
if ((await withDeadline(pending, timeoutMs)).settled)
|
|
547
|
-
return;
|
|
548
|
-
} catch (error) {
|
|
549
|
-
return { code: "hook_error", cause: error };
|
|
550
|
-
}
|
|
551
|
-
pending.catch(() => {
|
|
552
|
-
return;
|
|
553
|
-
});
|
|
554
|
-
return {
|
|
555
|
-
code: "hook_timeout",
|
|
556
|
-
cause: new Error(`Agent ${name} hook timed out after ${timeoutMs}ms`)
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
async function recordStepSpend(execution, input) {
|
|
560
|
-
const { config, generateId, now } = execution.dependencies;
|
|
561
|
-
const { state, trace } = execution;
|
|
562
|
-
const base = {
|
|
563
|
-
conversationId: state.run.conversationId,
|
|
564
|
-
runId: state.run.id,
|
|
565
|
-
step: state.step,
|
|
566
|
-
attempt: input.attempt,
|
|
567
|
-
...execution.invocationTrace !== undefined && { trace: execution.invocationTrace }
|
|
568
|
-
};
|
|
569
|
-
let spend;
|
|
570
|
-
if (input.phase === "compaction") {
|
|
571
|
-
const usage = statedUsage(input.usage);
|
|
572
|
-
state.nonModelUsage = addUsage(state.nonModelUsage, usage);
|
|
573
|
-
spend = AgentStepSpendSchema2.parse({ ...base, phase: input.phase, usage });
|
|
574
|
-
} else {
|
|
575
|
-
const usage = statedUsage(normalizeStepUsage(input.selectedModel, input.part.usage, input.part.providerMetadata));
|
|
576
|
-
const response = await input.ledger.recordResponse({
|
|
577
|
-
id: input.part.response.id,
|
|
578
|
-
providerMetadata: input.part.providerMetadata,
|
|
579
|
-
stepNumber: state.step,
|
|
580
|
-
attempt: input.attempt,
|
|
581
|
-
usage
|
|
582
|
-
});
|
|
583
|
-
if (input.phase === "step") {
|
|
584
|
-
state.lastPromptTokens = usage.inputTokens;
|
|
585
|
-
state.modelUsage = addUsage(state.modelUsage, usage);
|
|
586
|
-
} else {
|
|
587
|
-
state.abandonedUsage = state.abandonedUsage ? addUsage(state.abandonedUsage, usage) : usage;
|
|
588
|
-
}
|
|
589
|
-
spend = AgentStepSpendSchema2.parse({
|
|
590
|
-
...base,
|
|
591
|
-
phase: input.phase,
|
|
592
|
-
model: input.selectedModel.descriptor.modelId,
|
|
593
|
-
provider: {
|
|
594
|
-
key: input.selectedModel.descriptor.provider,
|
|
595
|
-
...response.provider !== undefined && { upstream: response.provider }
|
|
596
|
-
},
|
|
597
|
-
response,
|
|
598
|
-
usage
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
state.usage = runUsage(state);
|
|
602
|
-
const { stepSpendTimeoutMs } = execution.dependencies;
|
|
603
|
-
const hook = config.onStepSpend;
|
|
604
|
-
const runtimeContext = execution.runtimeContext;
|
|
605
|
-
let spendHookError = hook && runtimeContext ? await callStepSpendHook("onStepSpend", stepSpendTimeoutMs, () => hook({ ...runtimeContext, ...spend })) : undefined;
|
|
606
|
-
const report = config.onStepSpendError;
|
|
607
|
-
if (spendHookError !== undefined && report !== undefined) {
|
|
608
|
-
const error = spendHookError.cause;
|
|
609
|
-
const reportFailure = await callStepSpendHook("onStepSpendError", stepSpendTimeoutMs, () => report({ spend, error }));
|
|
610
|
-
if (reportFailure !== undefined)
|
|
611
|
-
spendHookError = {
|
|
612
|
-
...spendHookError,
|
|
613
|
-
reportFailed: true,
|
|
614
|
-
reportError: reportFailure.cause
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
const stepTrace = trace ? config.observe?.rootTrace(trace) : undefined;
|
|
618
|
-
config.observe?.emit({
|
|
619
|
-
schemaVersion: 1,
|
|
620
|
-
eventId: generateId(),
|
|
621
|
-
type: "step-finished",
|
|
622
|
-
conversationId: spend.conversationId,
|
|
623
|
-
runId: spend.runId,
|
|
624
|
-
traceId: stepTrace?.traceId ?? trace?.traceId ?? generateId(),
|
|
625
|
-
spanId: stepTrace?.spanId ?? generateId(),
|
|
626
|
-
...stepTrace?.parentSpanId && { parentSpanId: stepTrace.parentSpanId },
|
|
627
|
-
state: state.run.state,
|
|
628
|
-
step: spend.step,
|
|
629
|
-
attempt: spend.attempt,
|
|
630
|
-
phase: spend.phase,
|
|
631
|
-
...spend.phase !== "compaction" && {
|
|
632
|
-
modelId: spend.model,
|
|
633
|
-
provider: spend.provider,
|
|
634
|
-
response: spend.response
|
|
635
|
-
},
|
|
636
|
-
usage: spend.usage,
|
|
637
|
-
...spendHookError !== undefined && { spendHookError },
|
|
638
|
-
emittedAt: now().toISOString()
|
|
639
|
-
});
|
|
640
|
-
return spend;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
// src/agent-runtime/invocation-attempt.ts
|
|
644
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
645
|
-
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
646
|
-
import { wrapLanguageModel } from "ai";
|
|
647
|
-
|
|
648
|
-
// src/agent-runtime/invocation-failure.ts
|
|
649
|
-
class InvocationReceiptError extends Error {
|
|
650
|
-
constructor(cause) {
|
|
651
|
-
super("Model invocation receipt could not be recorded", { cause });
|
|
652
|
-
this.name = "InvocationReceiptError";
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
async function invocationAudit(work) {
|
|
656
|
-
try {
|
|
657
|
-
return await work();
|
|
658
|
-
} catch (error) {
|
|
659
|
-
throw error instanceof InvocationReceiptError ? error : new InvocationReceiptError(error);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// src/agent-runtime/invocation-payload.ts
|
|
664
|
-
import {
|
|
665
|
-
createCipheriv,
|
|
666
|
-
createDecipheriv,
|
|
667
|
-
createHash,
|
|
668
|
-
randomBytes,
|
|
669
|
-
randomUUID
|
|
670
|
-
} from "node:crypto";
|
|
671
|
-
import { z as z3 } from "zod";
|
|
672
|
-
function invocationJson(value) {
|
|
673
|
-
const errors = new WeakSet;
|
|
674
|
-
return z3.json().parse(JSON.parse(JSON.stringify(value, (_key, item) => {
|
|
675
|
-
if (item instanceof Uint8Array)
|
|
676
|
-
return { base64: Buffer.from(item).toString("base64") };
|
|
677
|
-
if (item instanceof ArrayBuffer)
|
|
678
|
-
return { base64: Buffer.from(item).toString("base64") };
|
|
679
|
-
if (item instanceof Error) {
|
|
680
|
-
if (errors.has(item))
|
|
681
|
-
return { name: item.name, message: item.message };
|
|
682
|
-
errors.add(item);
|
|
683
|
-
return { name: item.name, message: item.message, cause: item.cause };
|
|
684
|
-
}
|
|
685
|
-
return item;
|
|
686
|
-
})));
|
|
687
|
-
}
|
|
688
|
-
function invocationHash(value) {
|
|
689
|
-
return createHash("sha256").update(serializeCanonicalJson(invocationJson(value))).digest("hex");
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
class InvocationPayloadTooLargeError2 extends RangeError {
|
|
693
|
-
bytes;
|
|
694
|
-
maxBytes;
|
|
695
|
-
sha256;
|
|
696
|
-
constructor(bytes, maxBytes, sha256) {
|
|
697
|
-
super(`Invocation payload (${bytes} bytes) exceeds maxPayloadBytes (${maxBytes})`);
|
|
698
|
-
this.name = "InvocationPayloadTooLargeError";
|
|
699
|
-
this.bytes = bytes;
|
|
700
|
-
this.maxBytes = maxBytes;
|
|
701
|
-
this.sha256 = sha256;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
function createInvocationPayloads(store, key, maxBytes) {
|
|
705
|
-
if (key.byteLength !== 32)
|
|
706
|
-
throw new TypeError("Invocation payload key must contain 32 bytes");
|
|
707
|
-
const encryptionKey = Uint8Array.from(key);
|
|
708
|
-
return {
|
|
709
|
-
maxBytes,
|
|
710
|
-
async write(identity, value) {
|
|
711
|
-
const data = Buffer.from(serializeCanonicalJson(invocationJson(value)));
|
|
712
|
-
const sha256 = createHash("sha256").update(data).digest("hex");
|
|
713
|
-
if (data.byteLength > maxBytes) {
|
|
714
|
-
throw new InvocationPayloadTooLargeError2(data.byteLength, maxBytes, sha256);
|
|
715
|
-
}
|
|
716
|
-
const artifactId = randomUUID();
|
|
717
|
-
const iv = randomBytes(12);
|
|
718
|
-
const cipher = createCipheriv("aes-256-gcm", encryptionKey, iv);
|
|
719
|
-
cipher.setAAD(Buffer.from(JSON.stringify([identity.conversationId, identity.invocationId, artifactId])));
|
|
720
|
-
const ciphertext = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
721
|
-
const { conversationId } = identity;
|
|
722
|
-
if (!store.appendEventOnce)
|
|
723
|
-
throw new TypeError("Invocation payloads require atomic store.appendEventOnce");
|
|
724
|
-
await store.appendEventOnce({
|
|
725
|
-
conversationId,
|
|
726
|
-
kind: "provider/payload",
|
|
727
|
-
payload: {
|
|
728
|
-
...identity,
|
|
729
|
-
artifactId,
|
|
730
|
-
sha256,
|
|
731
|
-
bytes: data.byteLength,
|
|
732
|
-
iv: iv.toString("base64"),
|
|
733
|
-
tag: cipher.getAuthTag().toString("base64"),
|
|
734
|
-
ciphertext: ciphertext.toString("base64")
|
|
735
|
-
}
|
|
736
|
-
}, artifactId);
|
|
737
|
-
return { artifactId, sha256 };
|
|
738
|
-
},
|
|
739
|
-
decrypt(conversationId, value) {
|
|
740
|
-
const payload = InvocationPayloadSchema.parse(value);
|
|
741
|
-
if (payload.bytes > maxBytes || payload.ciphertext.length > Math.ceil(maxBytes / 3) * 4) {
|
|
742
|
-
throw new RangeError("Invocation payload exceeds maxPayloadBytes");
|
|
743
|
-
}
|
|
744
|
-
const decipher = createDecipheriv("aes-256-gcm", encryptionKey, Buffer.from(payload.iv, "base64"));
|
|
745
|
-
decipher.setAAD(Buffer.from(JSON.stringify([conversationId, payload.invocationId, payload.artifactId])));
|
|
746
|
-
decipher.setAuthTag(Buffer.from(payload.tag, "base64"));
|
|
747
|
-
const data = Buffer.concat([
|
|
748
|
-
decipher.update(Buffer.from(payload.ciphertext, "base64")),
|
|
749
|
-
decipher.final()
|
|
750
|
-
]);
|
|
751
|
-
if (data.length !== payload.bytes || createHash("sha256").update(data).digest("hex") !== payload.sha256) {
|
|
752
|
-
throw new Error("Invocation payload integrity mismatch");
|
|
753
|
-
}
|
|
754
|
-
return z3.json().parse(JSON.parse(data.toString("utf8")));
|
|
755
|
-
}
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
// src/agent-runtime/provider-origin.ts
|
|
760
|
-
import {
|
|
761
|
-
InvalidToolApprovalError,
|
|
762
|
-
InvalidToolApprovalSignatureError,
|
|
763
|
-
ToolCallNotFoundForApprovalError
|
|
764
|
-
} from "ai";
|
|
765
|
-
var providerOrigin = new WeakSet;
|
|
766
|
-
function isOwnInputRefusal(error) {
|
|
767
|
-
return InvalidToolApprovalSignatureError.isInstance(error) || InvalidToolApprovalError.isInstance(error) || ToolCallNotFoundForApprovalError.isInstance(error);
|
|
768
|
-
}
|
|
769
|
-
function markProviderOrigin(error) {
|
|
770
|
-
if (typeof error === "object" && error !== null)
|
|
771
|
-
providerOrigin.add(error);
|
|
772
|
-
return error;
|
|
773
|
-
}
|
|
774
|
-
function hasProviderOrigin(error) {
|
|
775
|
-
return typeof error === "object" && error !== null && providerOrigin.has(error);
|
|
776
|
-
}
|
|
777
|
-
function markProviderStream(stream) {
|
|
778
|
-
const reader = stream.getReader();
|
|
779
|
-
return new ReadableStream({
|
|
780
|
-
async pull(controller) {
|
|
781
|
-
let read;
|
|
782
|
-
try {
|
|
783
|
-
read = await reader.read();
|
|
784
|
-
} catch (error) {
|
|
785
|
-
controller.error(isOwnInputRefusal(error) ? error : markProviderOrigin(error));
|
|
786
|
-
return;
|
|
787
|
-
}
|
|
788
|
-
if (read.done)
|
|
789
|
-
controller.close();
|
|
790
|
-
else
|
|
791
|
-
controller.enqueue(read.value);
|
|
792
|
-
},
|
|
793
|
-
cancel(reason) {
|
|
794
|
-
return reader.cancel(reason);
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// src/agent-runtime/invocation-attempt.ts
|
|
800
|
-
var currentAttempt = new AsyncLocalStorage;
|
|
801
|
-
function currentModelInvocationAttempt2() {
|
|
802
|
-
const value = currentAttempt.getStore();
|
|
803
|
-
return value && { ...value };
|
|
804
|
-
}
|
|
805
|
-
function wrapInvocationModel(writer, selected, step, model = selected.model) {
|
|
806
|
-
if (typeof model === "string")
|
|
807
|
-
throw new TypeError("Invocation receipts require a resolved model object");
|
|
808
|
-
const begin = async (params) => invocationAudit(async () => {
|
|
809
|
-
const context = { ...writer.identity, step, attemptId: randomUUID2() };
|
|
810
|
-
const { headers: _headers, abortSignal: _signal, ...payload } = params;
|
|
811
|
-
let artifact;
|
|
812
|
-
let omittedSha256;
|
|
813
|
-
try {
|
|
814
|
-
artifact = await writer.payloads.write(writer.identity, payload);
|
|
815
|
-
} catch (error) {
|
|
816
|
-
if (!(error instanceof InvocationPayloadTooLargeError2))
|
|
817
|
-
throw error;
|
|
818
|
-
writer.receiptErrors.push(error);
|
|
819
|
-
omittedSha256 = error.sha256;
|
|
820
|
-
}
|
|
821
|
-
await writer.append({
|
|
822
|
-
...writer.identity,
|
|
823
|
-
type: "provider/request",
|
|
824
|
-
attemptId: context.attemptId,
|
|
825
|
-
step,
|
|
826
|
-
executingProcess: writer.process,
|
|
827
|
-
requested: {
|
|
828
|
-
modelId: selected.descriptor.modelId,
|
|
829
|
-
provider: selected.descriptor.provider
|
|
830
|
-
},
|
|
831
|
-
sent: {
|
|
832
|
-
modelId: model.modelId,
|
|
833
|
-
provider: model.provider,
|
|
834
|
-
payloadSha256: artifact ? artifact.sha256 : omittedSha256 ?? "",
|
|
835
|
-
...artifact ? { artifactId: artifact.artifactId } : { payloadOmitted: "max-payload-bytes" },
|
|
836
|
-
tools: params.tools?.length ?? 0
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
try {
|
|
840
|
-
await writer.onAttempt?.({ ...context });
|
|
841
|
-
} catch (error) {
|
|
842
|
-
await finish(context, "failed", { phase: "transport-audit", error });
|
|
843
|
-
throw error;
|
|
844
|
-
}
|
|
845
|
-
return context;
|
|
846
|
-
});
|
|
847
|
-
const finish = (...args) => recordResponse(...args).catch((error) => {
|
|
848
|
-
writer.receiptErrors.push(error);
|
|
849
|
-
});
|
|
850
|
-
const recordResponse = async (context, status, payload, usage, response, providerMetadata) => invocationAudit(async () => {
|
|
851
|
-
let artifact;
|
|
852
|
-
let omittedSha256;
|
|
853
|
-
try {
|
|
854
|
-
artifact = await writer.payloads.write(writer.identity, boundedEvidence(payload, Math.floor(writer.payloads.maxBytes / 2)));
|
|
855
|
-
} catch (error) {
|
|
856
|
-
if (!(error instanceof InvocationPayloadTooLargeError2))
|
|
857
|
-
throw error;
|
|
858
|
-
writer.receiptErrors.push(error);
|
|
859
|
-
omittedSha256 = error.sha256;
|
|
860
|
-
}
|
|
861
|
-
await writer.append({
|
|
862
|
-
...writer.identity,
|
|
863
|
-
type: "provider/response",
|
|
864
|
-
attemptId: context.attemptId,
|
|
865
|
-
step,
|
|
866
|
-
status,
|
|
867
|
-
effective: {
|
|
868
|
-
provider: selected.resolveResponseProvider?.({ providerMetadata }) ?? null,
|
|
869
|
-
modelId: response?.modelId ?? null,
|
|
870
|
-
responseId: response?.id ?? null
|
|
871
|
-
},
|
|
872
|
-
usage: reportedUsage(selected, usage, providerMetadata),
|
|
873
|
-
...artifact ? { artifactId: artifact.artifactId } : { payloadOmitted: "max-payload-bytes" },
|
|
874
|
-
payloadSha256: artifact ? artifact.sha256 : omittedSha256 ?? ""
|
|
875
|
-
});
|
|
876
|
-
});
|
|
877
|
-
return wrapLanguageModel({
|
|
878
|
-
model,
|
|
879
|
-
middleware: {
|
|
880
|
-
specificationVersion: "v4",
|
|
881
|
-
async wrapGenerate({ doGenerate, params }) {
|
|
882
|
-
const context = await begin(params);
|
|
883
|
-
let result;
|
|
884
|
-
try {
|
|
885
|
-
result = await currentAttempt.run(context, doGenerate);
|
|
886
|
-
} catch (error) {
|
|
887
|
-
await finish(context, params.abortSignal?.aborted ? "cancelled" : "failed", {
|
|
888
|
-
error
|
|
889
|
-
});
|
|
890
|
-
throw markProviderOrigin(error);
|
|
891
|
-
}
|
|
892
|
-
await finish(context, result.finishReason.unified === "error" ? "failed" : "succeeded", {
|
|
893
|
-
content: result.content,
|
|
894
|
-
usage: result.usage,
|
|
895
|
-
response: result.response,
|
|
896
|
-
providerMetadata: result.providerMetadata
|
|
897
|
-
}, result.usage, result.response, result.providerMetadata);
|
|
898
|
-
if (result.finishReason.unified === "error") {
|
|
899
|
-
throw markProviderOrigin(new Error("Provider returned an error finish reason"));
|
|
900
|
-
}
|
|
901
|
-
return result;
|
|
902
|
-
},
|
|
903
|
-
async wrapStream({ doStream, params }) {
|
|
904
|
-
const context = await begin(params);
|
|
905
|
-
let result;
|
|
906
|
-
try {
|
|
907
|
-
result = await currentAttempt.run(context, doStream);
|
|
908
|
-
} catch (error) {
|
|
909
|
-
await finish(context, params.abortSignal?.aborted ? "cancelled" : "failed", {
|
|
910
|
-
error
|
|
911
|
-
});
|
|
912
|
-
throw markProviderOrigin(error);
|
|
913
|
-
}
|
|
914
|
-
return wrapInvocationStreamResult(result, {
|
|
915
|
-
context,
|
|
916
|
-
abortSignal: params.abortSignal,
|
|
917
|
-
maxEvidenceBytes: Math.floor(writer.payloads.maxBytes / 2),
|
|
918
|
-
finish
|
|
919
|
-
});
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
function wrapInvocationStreamResult(result, options) {
|
|
925
|
-
const { context, abortSignal, maxEvidenceBytes, finish } = options;
|
|
926
|
-
const reader = result.stream.getReader();
|
|
927
|
-
let ended = false;
|
|
928
|
-
let failed = false;
|
|
929
|
-
let response;
|
|
930
|
-
const evidence = streamEvidence(maxEvidenceBytes);
|
|
931
|
-
const end = async (status, value, usage, metadata) => {
|
|
932
|
-
if (ended)
|
|
933
|
-
return;
|
|
934
|
-
ended = true;
|
|
935
|
-
await finish(context, status, evidence.payload(value), usage, response, metadata);
|
|
936
|
-
};
|
|
937
|
-
return {
|
|
938
|
-
...result,
|
|
939
|
-
stream: new ReadableStream({
|
|
940
|
-
async pull(controller) {
|
|
941
|
-
let next;
|
|
942
|
-
try {
|
|
943
|
-
next = await currentAttempt.run(context, () => reader.read());
|
|
944
|
-
} catch (error) {
|
|
945
|
-
await end(abortSignal?.aborted ? "cancelled" : "failed", { error });
|
|
946
|
-
controller.error(markProviderOrigin(error));
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
if (next.done) {
|
|
950
|
-
await end("failed", { reason: "stream-ended-without-finish" });
|
|
951
|
-
controller.close();
|
|
952
|
-
return;
|
|
953
|
-
}
|
|
954
|
-
const part = next.value;
|
|
955
|
-
if (part.type === "response-metadata")
|
|
956
|
-
response = part;
|
|
957
|
-
if (part.type === "finish") {
|
|
958
|
-
await end(failed || part.finishReason.unified === "error" ? "failed" : "succeeded", part, part.usage, part.providerMetadata);
|
|
959
|
-
} else {
|
|
960
|
-
if (part.type === "error")
|
|
961
|
-
failed = true;
|
|
962
|
-
evidence.record(part);
|
|
963
|
-
}
|
|
964
|
-
controller.enqueue(part);
|
|
965
|
-
},
|
|
966
|
-
async cancel(reason) {
|
|
967
|
-
try {
|
|
968
|
-
await currentAttempt.run(context, () => reader.cancel(reason));
|
|
969
|
-
} finally {
|
|
970
|
-
await end("cancelled", { reason: "consumer-cancelled" });
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
})
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
function boundedEvidence(payload, limit) {
|
|
977
|
-
const serialized = JSON.stringify(invocationJson(payload));
|
|
978
|
-
const bytes = Buffer.byteLength(serialized);
|
|
979
|
-
if (bytes <= limit)
|
|
980
|
-
return payload;
|
|
981
|
-
return {
|
|
982
|
-
truncated: { bytes, sha256: createHash2("sha256").update(serialized).digest("hex") }
|
|
983
|
-
};
|
|
984
|
-
}
|
|
985
|
-
function streamEvidence(limit) {
|
|
986
|
-
const output = [];
|
|
987
|
-
const whole = createHash2("sha256");
|
|
988
|
-
let bytes = 0;
|
|
989
|
-
let parts = 0;
|
|
990
|
-
let truncated = false;
|
|
991
|
-
return {
|
|
992
|
-
record(part) {
|
|
993
|
-
const json = invocationJson(part);
|
|
994
|
-
const serialized = JSON.stringify(json);
|
|
995
|
-
whole.update(serialized).update(`
|
|
996
|
-
`);
|
|
997
|
-
parts += 1;
|
|
998
|
-
const size = Buffer.byteLength(serialized);
|
|
999
|
-
if (!truncated && bytes + size > limit)
|
|
1000
|
-
truncated = true;
|
|
1001
|
-
if (truncated)
|
|
1002
|
-
return;
|
|
1003
|
-
bytes += size;
|
|
1004
|
-
output.push(json);
|
|
1005
|
-
},
|
|
1006
|
-
payload(terminal) {
|
|
1007
|
-
return {
|
|
1008
|
-
output,
|
|
1009
|
-
terminal,
|
|
1010
|
-
...truncated && { truncated: { parts, sha256: whole.digest("hex") } }
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
};
|
|
1014
|
-
}
|
|
1015
|
-
function reportedUsage(selected, value, providerMetadata) {
|
|
1016
|
-
const usage = {
|
|
1017
|
-
inputTokens: value?.inputTokens.total,
|
|
1018
|
-
outputTokens: value?.outputTokens.total,
|
|
1019
|
-
totalTokens: undefined,
|
|
1020
|
-
inputTokenDetails: {
|
|
1021
|
-
noCacheTokens: value?.inputTokens.noCache,
|
|
1022
|
-
cacheReadTokens: value?.inputTokens.cacheRead,
|
|
1023
|
-
cacheWriteTokens: value?.inputTokens.cacheWrite
|
|
1024
|
-
},
|
|
1025
|
-
outputTokenDetails: {
|
|
1026
|
-
textTokens: value?.outputTokens.text,
|
|
1027
|
-
reasoningTokens: value?.outputTokens.reasoning
|
|
1028
|
-
},
|
|
1029
|
-
...value?.raw && { raw: value.raw }
|
|
1030
|
-
};
|
|
1031
|
-
return normalizeStepUsage(selected, usage, providerMetadata);
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
// src/agent-runtime/models.ts
|
|
1035
|
-
import { z as z4 } from "zod";
|
|
1036
|
-
var AgentModelCapabilitySchema2 = z4.enum(["tools", "vision", "reasoning", "files"]);
|
|
1037
|
-
var AgentModelDescriptorSchema2 = z4.object({
|
|
1038
|
-
provider: z4.string().min(1),
|
|
1039
|
-
modelId: z4.string().min(1),
|
|
1040
|
-
contextWindow: z4.int().positive(),
|
|
1041
|
-
capabilities: z4.array(AgentModelCapabilitySchema2),
|
|
1042
|
-
observedAt: z4.iso.datetime({ offset: true }).optional(),
|
|
1043
|
-
source: z4.string().min(1).optional(),
|
|
1044
|
-
availability: z4.enum(["available", "unavailable"]).optional()
|
|
1045
|
-
});
|
|
1046
|
-
var AgentModelRegistrySnapshotSchema2 = z4.object({
|
|
1047
|
-
schemaVersion: z4.literal(1),
|
|
1048
|
-
source: z4.string().min(1),
|
|
1049
|
-
observedAt: z4.iso.datetime({ offset: true }),
|
|
1050
|
-
models: z4.record(z4.string().min(1), AgentModelDescriptorSchema2)
|
|
1051
|
-
});
|
|
1052
|
-
var AgentModelPriceSchema2 = z4.object({
|
|
1053
|
-
currency: z4.string().length(3),
|
|
1054
|
-
inputPerToken: z4.string().regex(/^\d+(?:\.\d+)?$/).optional(),
|
|
1055
|
-
outputPerToken: z4.string().regex(/^\d+(?:\.\d+)?$/).optional()
|
|
1056
|
-
}).strict();
|
|
1057
|
-
var AgentModelMetricSchema2 = z4.object({
|
|
1058
|
-
metric: z4.string().min(1),
|
|
1059
|
-
value: z4.number(),
|
|
1060
|
-
unit: z4.enum(["index", "elo", "percent", "milliseconds"]),
|
|
1061
|
-
source: z4.string().min(1),
|
|
1062
|
-
observedAt: z4.iso.datetime({ offset: true })
|
|
1063
|
-
}).strict();
|
|
1064
|
-
var AgentModelPopularitySchema2 = z4.object({
|
|
1065
|
-
rank: z4.int().positive(),
|
|
1066
|
-
window: z4.literal("week"),
|
|
1067
|
-
source: z4.string().min(1),
|
|
1068
|
-
observedAt: z4.iso.datetime({ offset: true })
|
|
1069
|
-
}).strict();
|
|
1070
|
-
var AgentModelCatalogEntrySchema2 = z4.object({
|
|
1071
|
-
id: z4.string().min(1),
|
|
1072
|
-
name: z4.string().min(1),
|
|
1073
|
-
descriptor: AgentModelDescriptorSchema2,
|
|
1074
|
-
description: z4.string().optional(),
|
|
1075
|
-
price: AgentModelPriceSchema2.optional(),
|
|
1076
|
-
popularity: AgentModelPopularitySchema2.optional(),
|
|
1077
|
-
metrics: z4.array(AgentModelMetricSchema2)
|
|
1078
|
-
}).strict();
|
|
1079
|
-
var AgentModelCatalogSchema2 = z4.object({
|
|
1080
|
-
schemaVersion: z4.literal(1),
|
|
1081
|
-
source: z4.string().min(1),
|
|
1082
|
-
observedAt: z4.iso.datetime({ offset: true }),
|
|
1083
|
-
completeness: z4.enum(["complete", "partial"]),
|
|
1084
|
-
models: z4.array(AgentModelCatalogEntrySchema2),
|
|
1085
|
-
diagnostics: z4.array(z4.string())
|
|
1086
|
-
}).strict();
|
|
1087
|
-
var AgentModelSelectionSchema2 = z4.object({
|
|
1088
|
-
modelId: z4.string().min(1),
|
|
1089
|
-
selectedAt: z4.iso.datetime({ offset: true })
|
|
1090
|
-
}).strict();
|
|
1091
|
-
var AgentModelSearchInputSchema2 = z4.object({ query: z4.string().max(256).default(""), limit: z4.int().positive().max(200) }).strict();
|
|
1092
|
-
var AgentModelSearchResultSchema2 = z4.object({
|
|
1093
|
-
models: z4.array(AgentModelCatalogEntrySchema2),
|
|
1094
|
-
total: z4.int().nonnegative(),
|
|
1095
|
-
truncated: z4.boolean()
|
|
1096
|
-
}).strict();
|
|
1097
|
-
function searchAgentModelCatalog2(catalog, rawInput) {
|
|
1098
|
-
const input = AgentModelSearchInputSchema2.parse(rawInput);
|
|
1099
|
-
const terms = input.query.toLocaleLowerCase().trim().split(/\s+/).filter(Boolean);
|
|
1100
|
-
const matches = catalog.models.filter((model) => {
|
|
1101
|
-
const searchable = `${model.id}
|
|
1102
|
-
${model.name}
|
|
1103
|
-
${model.description ?? ""}`.toLocaleLowerCase();
|
|
1104
|
-
return terms.every((term) => searchable.includes(term));
|
|
1105
|
-
});
|
|
1106
|
-
return AgentModelSearchResultSchema2.parse({
|
|
1107
|
-
models: matches.slice(0, input.limit),
|
|
1108
|
-
total: matches.length,
|
|
1109
|
-
truncated: matches.length > input.limit
|
|
1110
|
-
});
|
|
1111
|
-
}
|
|
1112
|
-
function createMemoryAgentModelSelectionStore2() {
|
|
1113
|
-
const selections = new Map;
|
|
1114
|
-
return {
|
|
1115
|
-
load: (conversationId) => selections.get(conversationId),
|
|
1116
|
-
save(conversationId, rawSelection) {
|
|
1117
|
-
selections.set(conversationId, AgentModelSelectionSchema2.parse(rawSelection));
|
|
1118
|
-
}
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
function defineModelRegistry2(config) {
|
|
1122
|
-
const descriptors = new Map;
|
|
1123
|
-
for (const key in config.models) {
|
|
1124
|
-
const declaration = config.models[key];
|
|
1125
|
-
if (declaration)
|
|
1126
|
-
descriptors.set(key, AgentModelDescriptorSchema2.parse(declaration));
|
|
1127
|
-
}
|
|
1128
|
-
const descriptor = (key) => {
|
|
1129
|
-
const found = descriptors.get(key);
|
|
1130
|
-
if (!found)
|
|
1131
|
-
throw new Error(`Unknown agent model: ${key}`);
|
|
1132
|
-
return found;
|
|
1133
|
-
};
|
|
1134
|
-
const supports = (key, capabilities) => {
|
|
1135
|
-
const available = new Set(descriptor(key).capabilities);
|
|
1136
|
-
return capabilities.every((capability) => available.has(capability));
|
|
1137
|
-
};
|
|
1138
|
-
const preflight = (key, required = []) => {
|
|
1139
|
-
const selected = descriptor(key);
|
|
1140
|
-
if (selected.availability === "unavailable") {
|
|
1141
|
-
throw new Error(`Agent model ${key} is unavailable`);
|
|
1142
|
-
}
|
|
1143
|
-
if (!supports(key, required)) {
|
|
1144
|
-
throw new Error(`Agent model ${key} does not satisfy required capabilities`);
|
|
1145
|
-
}
|
|
1146
|
-
if (!config.providers[selected.provider]) {
|
|
1147
|
-
throw new Error(`Unknown agent model provider: ${selected.provider}`);
|
|
1148
|
-
}
|
|
1149
|
-
return selected;
|
|
1150
|
-
};
|
|
1151
|
-
return {
|
|
1152
|
-
keys: () => [...descriptors.keys()],
|
|
1153
|
-
descriptor,
|
|
1154
|
-
supports,
|
|
1155
|
-
preflight,
|
|
1156
|
-
resolve(key, required = []) {
|
|
1157
|
-
const selected = preflight(key, required);
|
|
1158
|
-
const provider = config.providers[selected.provider];
|
|
1159
|
-
if (!provider)
|
|
1160
|
-
throw new Error(`Unknown agent model provider: ${selected.provider}`);
|
|
1161
|
-
return {
|
|
1162
|
-
descriptor: selected,
|
|
1163
|
-
model: provider.create(selected.modelId),
|
|
1164
|
-
...provider.normalizeUsage && { normalizeUsage: provider.normalizeUsage },
|
|
1165
|
-
...provider.resolveResponseProvider && {
|
|
1166
|
-
resolveResponseProvider: provider.resolveResponseProvider
|
|
1167
|
-
}
|
|
1168
|
-
};
|
|
1169
|
-
},
|
|
1170
|
-
snapshot(input) {
|
|
1171
|
-
return AgentModelRegistrySnapshotSchema2.parse({
|
|
1172
|
-
schemaVersion: 1,
|
|
1173
|
-
source: input.source,
|
|
1174
|
-
observedAt: input.observedAt,
|
|
1175
|
-
models: Object.fromEntries(descriptors.entries())
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
function validateAgentModelSnapshot2(input, policy) {
|
|
1181
|
-
if (!Number.isSafeInteger(policy.maxAgeMs) || policy.maxAgeMs < 0) {
|
|
1182
|
-
throw new TypeError("maxAgeMs must be a non-negative safe integer");
|
|
1183
|
-
}
|
|
1184
|
-
const snapshot = AgentModelRegistrySnapshotSchema2.parse(input);
|
|
1185
|
-
const now = policy.now?.() ?? new Date;
|
|
1186
|
-
const age = now.getTime() - new Date(snapshot.observedAt).getTime();
|
|
1187
|
-
if (age < 0 || age > policy.maxAgeMs) {
|
|
1188
|
-
throw new Error(`Agent model snapshot from ${snapshot.source} is stale`);
|
|
1189
|
-
}
|
|
1190
|
-
return snapshot;
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
export { withStoreRetries, AgentRuntimeConflictError2, AgentRunUnsettledError2, appliedSnapshot, terminalOfSnapshot, terminalOfRunView, commitAgentRunTerminal, findRun, jsonValue, providerEnvelope, providerResponseIdentity, appendText, abortTerminalReason, addUsage, mergeModelTotals, statedUsage, unknownUsage, normalizeSdkUsage, createIdleDeadline, adoptSnapshot, transientSequence, runUsage, updateReasoning, checkpoint, DEFAULT_STEP_SPEND_TIMEOUT_MS, AgentStepSpendPhaseSchema2, AgentStepSpendProviderSchema, AgentStepSpendSchema2, normalizeStepUsage, recordStepSpend, InvocationReceiptError, invocationHash, InvocationPayloadTooLargeError2, createInvocationPayloads, isOwnInputRefusal, markProviderOrigin, hasProviderOrigin, markProviderStream, currentModelInvocationAttempt2, wrapInvocationModel, AgentModelCapabilitySchema2, AgentModelDescriptorSchema2, AgentModelRegistrySnapshotSchema2, AgentModelPriceSchema2, AgentModelMetricSchema2, AgentModelPopularitySchema2, AgentModelCatalogEntrySchema2, AgentModelCatalogSchema2, AgentModelSelectionSchema2, AgentModelSearchInputSchema2, AgentModelSearchResultSchema2, searchAgentModelCatalog2, createMemoryAgentModelSelectionStore2, defineModelRegistry2, validateAgentModelSnapshot2 };
|