stitchkit 0.126.0 → 0.128.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 +1767 -0
- package/README.md +12 -4
- package/dist/agent-executor/acp/scenarios.d.ts +4 -0
- package/dist/agent-executor/acp/scenarios.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-connect.d.ts +97 -0
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-driver.d.ts +37 -0
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-map.d.ts +41 -0
- package/dist/agent-executor/acp/v1-map.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-protocol.d.ts +270 -0
- package/dist/agent-executor/acp/v1-protocol.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-session.d.ts +30 -0
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-turn.d.ts +25 -0
- package/dist/agent-executor/acp/v1-turn.d.ts.map +1 -0
- package/dist/agent-executor/claude/classify.d.ts +54 -0
- package/dist/agent-executor/claude/classify.d.ts.map +1 -0
- package/dist/agent-executor/claude/cli-driver.d.ts +31 -0
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -0
- package/dist/agent-executor/claude/limits.d.ts +8 -0
- package/dist/agent-executor/claude/limits.d.ts.map +1 -0
- package/dist/agent-executor/claude/protocol.d.ts +206 -0
- package/dist/agent-executor/claude/protocol.d.ts.map +1 -0
- package/dist/agent-executor/claude/scenarios.d.ts +4 -0
- package/dist/agent-executor/claude/scenarios.d.ts.map +1 -0
- package/dist/agent-executor/claude/session.d.ts +23 -0
- package/dist/agent-executor/claude/session.d.ts.map +1 -0
- package/dist/agent-executor/claude/transcript.d.ts +36 -0
- package/dist/agent-executor/claude/transcript.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/driver.d.ts +35 -0
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/session.d.ts +10 -0
- package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -0
- package/dist/agent-executor/codex/classify.d.ts +28 -0
- package/dist/agent-executor/codex/classify.d.ts.map +1 -0
- package/dist/agent-executor/codex/driver.d.ts +27 -0
- package/dist/agent-executor/codex/driver.d.ts.map +1 -0
- package/dist/agent-executor/codex/limits.d.ts +4 -0
- package/dist/agent-executor/codex/limits.d.ts.map +1 -0
- package/dist/agent-executor/codex/protocol.d.ts +176 -0
- package/dist/agent-executor/codex/protocol.d.ts.map +1 -0
- package/dist/agent-executor/codex/scenarios.d.ts +4 -0
- package/dist/agent-executor/codex/scenarios.d.ts.map +1 -0
- package/dist/agent-executor/codex/session.d.ts +43 -0
- package/dist/agent-executor/codex/session.d.ts.map +1 -0
- package/dist/agent-executor/contract.d.ts +454 -0
- package/dist/agent-executor/contract.d.ts.map +1 -0
- package/dist/agent-executor/dispatch.d.ts +41 -0
- package/dist/agent-executor/dispatch.d.ts.map +1 -0
- package/dist/agent-executor/engine-process.d.ts +45 -0
- package/dist/agent-executor/engine-process.d.ts.map +1 -0
- package/dist/agent-executor/engine-requests.d.ts +63 -0
- package/dist/agent-executor/engine-requests.d.ts.map +1 -0
- package/dist/agent-executor/engine.d.ts +64 -0
- package/dist/agent-executor/engine.d.ts.map +1 -0
- package/dist/agent-executor/executor-contract.d.ts +387 -0
- package/dist/agent-executor/executor-contract.d.ts.map +1 -0
- package/dist/agent-executor/executor-machine.d.ts +50 -0
- package/dist/agent-executor/executor-machine.d.ts.map +1 -0
- package/dist/agent-executor/hello.d.ts +235 -0
- package/dist/agent-executor/hello.d.ts.map +1 -0
- package/dist/agent-executor/image-input.d.ts +71 -0
- package/dist/agent-executor/image-input.d.ts.map +1 -0
- package/dist/agent-executor/json-rpc-peer.d.ts +48 -0
- package/dist/agent-executor/json-rpc-peer.d.ts.map +1 -0
- package/dist/agent-executor/leases.d.ts +159 -0
- package/dist/agent-executor/leases.d.ts.map +1 -0
- package/dist/agent-executor/plan-limits.d.ts +25 -0
- package/dist/agent-executor/plan-limits.d.ts.map +1 -0
- package/dist/agent-executor/profile.d.ts +52 -0
- package/dist/agent-executor/profile.d.ts.map +1 -0
- package/dist/agent-executor/projection.d.ts +14 -0
- package/dist/agent-executor/projection.d.ts.map +1 -0
- package/dist/agent-executor/session-primitives.d.ts +69 -0
- package/dist/agent-executor/session-primitives.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance.d.ts +55 -0
- package/dist/agent-executor/testing/conformance.d.ts.map +1 -0
- package/dist/agent-executor/testing/fake-claude-engine.d.ts +18 -0
- package/dist/agent-executor/testing/fake-claude-engine.d.ts.map +1 -0
- package/dist/agent-executor/testing/fake-engine.d.ts +52 -0
- package/dist/agent-executor/testing/fake-engine.d.ts.map +1 -0
- package/dist/agent-executor/turn-phases.d.ts +10 -0
- package/dist/agent-executor/turn-phases.d.ts.map +1 -0
- package/dist/agent-executor/vocabulary.d.ts +353 -0
- package/dist/agent-executor/vocabulary.d.ts.map +1 -0
- package/dist/agent-parts/parts.d.ts +160 -0
- package/dist/agent-parts/parts.d.ts.map +1 -0
- package/dist/agent-runtime/agent-tool.d.ts +22 -8
- package/dist/agent-runtime/agent-tool.d.ts.map +1 -1
- package/dist/agent-runtime/archive-projection.d.ts +5 -0
- package/dist/agent-runtime/archive-projection.d.ts.map +1 -1
- package/dist/agent-runtime/branch-contract.d.ts +60 -2
- package/dist/agent-runtime/branch-contract.d.ts.map +1 -1
- package/dist/agent-runtime/branch-events.d.ts +7 -0
- package/dist/agent-runtime/branch-events.d.ts.map +1 -1
- package/dist/agent-runtime/branch-identities.d.ts +43 -6
- package/dist/agent-runtime/branch-identities.d.ts.map +1 -1
- package/dist/agent-runtime/branch-messages.d.ts +11 -29
- package/dist/agent-runtime/branch-messages.d.ts.map +1 -1
- package/dist/agent-runtime/branch-observations.d.ts +153 -30
- package/dist/agent-runtime/branch-observations.d.ts.map +1 -1
- package/dist/agent-runtime/branch-provider.d.ts +43 -56
- package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
- package/dist/agent-runtime/branch-refusal.d.ts +60 -0
- package/dist/agent-runtime/branch-refusal.d.ts.map +1 -0
- package/dist/agent-runtime/branch-runtime-tools.d.ts +14 -0
- package/dist/agent-runtime/branch-runtime-tools.d.ts.map +1 -0
- package/dist/agent-runtime/branch-source.d.ts +19 -2
- package/dist/agent-runtime/branch-source.d.ts.map +1 -1
- package/dist/agent-runtime/branch-transitions.d.ts.map +1 -1
- package/dist/agent-runtime/browser-control-contract.d.ts +2 -2
- package/dist/agent-runtime/browser-controller.d.ts.map +1 -1
- package/dist/agent-runtime/child-blocking.d.ts +17 -6
- package/dist/agent-runtime/child-blocking.d.ts.map +1 -1
- package/dist/agent-runtime/child-budget-policy.d.ts +4 -9
- package/dist/agent-runtime/child-budget-policy.d.ts.map +1 -1
- package/dist/agent-runtime/child-tools.d.ts +82 -7
- package/dist/agent-runtime/child-tools.d.ts.map +1 -1
- package/dist/agent-runtime/children-contract.d.ts +84 -3
- package/dist/agent-runtime/children-contract.d.ts.map +1 -1
- package/dist/agent-runtime/children-control.d.ts +23 -2
- package/dist/agent-runtime/children-control.d.ts.map +1 -1
- package/dist/agent-runtime/children-spawn.d.ts +9 -0
- package/dist/agent-runtime/children-spawn.d.ts.map +1 -1
- package/dist/agent-runtime/children-state.d.ts +121 -19
- package/dist/agent-runtime/children-state.d.ts.map +1 -1
- package/dist/agent-runtime/children-usage.d.ts +10 -1
- package/dist/agent-runtime/children-usage.d.ts.map +1 -1
- package/dist/agent-runtime/children.d.ts +3 -3
- package/dist/agent-runtime/children.d.ts.map +1 -1
- package/dist/agent-runtime/{sandbox-coding.d.ts → coding-sandbox.d.ts} +2 -9
- package/dist/agent-runtime/coding-sandbox.d.ts.map +1 -0
- package/dist/agent-runtime/coding-shell-process.d.ts +2 -0
- package/dist/agent-runtime/coding-shell-process.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts +32 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-shell.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tools.d.ts.map +1 -1
- package/dist/agent-runtime/compaction.d.ts.map +1 -1
- package/dist/agent-runtime/companion-host.d.ts +38 -0
- package/dist/agent-runtime/companion-host.d.ts.map +1 -0
- package/dist/agent-runtime/context-issue.d.ts +5 -0
- package/dist/agent-runtime/context-issue.d.ts.map +1 -0
- package/dist/agent-runtime/control-schema.d.ts +2 -2
- package/dist/agent-runtime/control-schema.d.ts.map +1 -1
- package/dist/agent-runtime/conversations.d.ts.map +1 -1
- package/dist/agent-runtime/coordinator.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tool-types.d.ts +17 -5
- package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tools-internal.d.ts +2 -0
- 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-durability.d.ts +8 -0
- package/dist/agent-runtime/event-durability.d.ts.map +1 -0
- package/dist/agent-runtime/event-schema.d.ts +13 -5
- package/dist/agent-runtime/event-schema.d.ts.map +1 -1
- package/dist/agent-runtime/event-search-postgres.d.ts +38 -0
- package/dist/agent-runtime/event-search-postgres.d.ts.map +1 -0
- package/dist/agent-runtime/event-search-terms.d.ts +37 -0
- package/dist/agent-runtime/event-search-terms.d.ts.map +1 -0
- package/dist/agent-runtime/event-search-tools.d.ts +141 -4
- package/dist/agent-runtime/event-search-tools.d.ts.map +1 -1
- package/dist/agent-runtime/event-search.d.ts +16 -3
- package/dist/agent-runtime/event-search.d.ts.map +1 -1
- package/dist/agent-runtime/fault-bench.d.ts.map +1 -1
- package/dist/agent-runtime/harness-control.d.ts +8 -0
- package/dist/agent-runtime/harness-control.d.ts.map +1 -1
- package/dist/agent-runtime/harness-realtime.d.ts +0 -2
- package/dist/agent-runtime/harness-realtime.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-attempt.d.ts +1 -1
- package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-payload.d.ts +12 -0
- package/dist/agent-runtime/invocation-payload.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-read.d.ts +6 -3
- package/dist/agent-runtime/invocation-read.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-schema.d.ts +70 -5
- package/dist/agent-runtime/invocation-schema.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-spend.d.ts +9 -0
- package/dist/agent-runtime/invocation-spend.d.ts.map +1 -0
- package/dist/agent-runtime/invocations.d.ts +20 -9
- package/dist/agent-runtime/invocations.d.ts.map +1 -1
- package/dist/agent-runtime/managed-tools.d.ts +2 -2
- package/dist/agent-runtime/managed-tools.d.ts.map +1 -1
- package/dist/agent-runtime/observability.d.ts +42 -4
- package/dist/agent-runtime/observability.d.ts.map +1 -1
- package/dist/agent-runtime/openrouter-admission.d.ts +81 -0
- package/dist/agent-runtime/openrouter-admission.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-catalog.d.ts +83 -0
- package/dist/agent-runtime/openrouter-catalog.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-models.d.ts +66 -0
- package/dist/agent-runtime/openrouter-models.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-options.d.ts +106 -0
- package/dist/agent-runtime/openrouter-options.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-route.d.ts +50 -0
- package/dist/agent-runtime/openrouter-route.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter-spend.d.ts +24 -0
- package/dist/agent-runtime/openrouter-spend.d.ts.map +1 -0
- package/dist/agent-runtime/openrouter.d.ts +23 -2
- package/dist/agent-runtime/openrouter.d.ts.map +1 -1
- package/dist/agent-runtime/owned-provider-stream.d.ts.map +1 -1
- package/dist/agent-runtime/postgres-schema.d.ts +34 -0
- package/dist/agent-runtime/postgres-schema.d.ts.map +1 -0
- package/dist/agent-runtime/postgres-transactions.d.ts +54 -0
- package/dist/agent-runtime/postgres-transactions.d.ts.map +1 -0
- package/dist/agent-runtime/postgres.d.ts +72 -0
- package/dist/agent-runtime/postgres.d.ts.map +1 -0
- package/dist/agent-runtime/projections.d.ts +57 -17
- package/dist/agent-runtime/projections.d.ts.map +1 -1
- package/dist/agent-runtime/provider-journal.d.ts +57 -0
- package/dist/agent-runtime/provider-journal.d.ts.map +1 -1
- package/dist/agent-runtime/purge.d.ts.map +1 -1
- package/dist/agent-runtime/retry-policy.d.ts +6 -0
- package/dist/agent-runtime/retry-policy.d.ts.map +1 -1
- package/dist/agent-runtime/run-acquisition.d.ts.map +1 -1
- package/dist/agent-runtime/run-execution-state.d.ts +26 -2
- package/dist/agent-runtime/run-execution-state.d.ts.map +1 -1
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime/run-failure.d.ts.map +1 -1
- package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
- package/dist/agent-runtime/run-provider-ledger.d.ts +2 -0
- package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -1
- package/dist/agent-runtime/run-step-barriers.d.ts +72 -0
- package/dist/agent-runtime/run-step-barriers.d.ts.map +1 -0
- package/dist/agent-runtime/run-step-spend.d.ts +319 -0
- package/dist/agent-runtime/run-step-spend.d.ts.map +1 -0
- package/dist/agent-runtime/run-stream-parts.d.ts +2 -0
- package/dist/agent-runtime/run-stream-parts.d.ts.map +1 -1
- package/dist/agent-runtime/{tool-progress.d.ts → run-tool-progress.d.ts} +1 -1
- package/dist/agent-runtime/run-tool-progress.d.ts.map +1 -0
- package/dist/agent-runtime/run-turn-preparation.d.ts +3 -1
- package/dist/agent-runtime/run-turn-preparation.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-admission-gate.d.ts +0 -14
- package/dist/agent-runtime/runtime-admission-gate.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-internals.d.ts +6 -0
- package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-state.d.ts.map +1 -1
- package/dist/agent-runtime/runtime.d.ts +31 -2
- package/dist/agent-runtime/runtime.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox-binding.d.ts +10 -0
- package/dist/agent-runtime/sandbox-binding.d.ts.map +1 -0
- package/dist/agent-runtime/sandbox-bubblewrap-storage.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox-contract.d.ts +1 -1
- package/dist/agent-runtime/sandbox-contract.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox.d.ts +5 -0
- package/dist/agent-runtime/sandbox.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-contract.d.ts +3 -2
- package/dist/agent-runtime/schedule-contract.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-dispatch.d.ts +3 -2
- package/dist/agent-runtime/schedule-dispatch.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-records.d.ts +6 -6
- package/dist/agent-runtime/schedule-records.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-tools.d.ts +49 -8
- package/dist/agent-runtime/schedule-tools.d.ts.map +1 -1
- package/dist/agent-runtime/schedules.d.ts +13 -3
- package/dist/agent-runtime/schedules.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-invocation-payload.d.ts +48 -0
- package/dist/agent-runtime/schemas-invocation-payload.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-message.d.ts +118 -0
- package/dist/agent-runtime/schemas-message.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-provider.d.ts +8 -0
- package/dist/agent-runtime/schemas-provider.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-records.d.ts +5 -0
- package/dist/agent-runtime/schemas-records.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-run.d.ts +487 -0
- package/dist/agent-runtime/schemas-run.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-usage.d.ts +129 -0
- package/dist/agent-runtime/schemas-usage.d.ts.map +1 -0
- package/dist/agent-runtime/schemas.d.ts +11 -886
- package/dist/agent-runtime/schemas.d.ts.map +1 -1
- package/dist/agent-runtime/spill.d.ts +9 -7
- package/dist/agent-runtime/spill.d.ts.map +1 -1
- package/dist/agent-runtime/sql-events.d.ts +6 -0
- package/dist/agent-runtime/sql-events.d.ts.map +1 -0
- package/dist/agent-runtime/sql-history.d.ts +8 -0
- package/dist/agent-runtime/sql-history.d.ts.map +1 -0
- package/dist/agent-runtime/sql-ledger.d.ts +5 -0
- package/dist/agent-runtime/sql-ledger.d.ts.map +1 -0
- package/dist/agent-runtime/sql-purge.d.ts +13 -0
- package/dist/agent-runtime/sql-purge.d.ts.map +1 -0
- package/dist/agent-runtime/sql-reads.d.ts +16 -0
- package/dist/agent-runtime/sql-reads.d.ts.map +1 -0
- package/dist/agent-runtime/{sqlite-rows.d.ts → sql-rows.d.ts} +24 -10
- package/dist/agent-runtime/sql-rows.d.ts.map +1 -0
- package/dist/agent-runtime/sql-session.d.ts +82 -0
- package/dist/agent-runtime/sql-session.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-bun.d.ts +1 -1
- package/dist/agent-runtime/sqlite-bun.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-node.d.ts +1 -1
- package/dist/agent-runtime/sqlite-node.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-purge.d.ts +2 -3
- package/dist/agent-runtime/sqlite-purge.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-schema.d.ts +1 -1
- package/dist/agent-runtime/sqlite-schema.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-transactions.d.ts +10 -6
- package/dist/agent-runtime/sqlite-transactions.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite.d.ts +10 -29
- package/dist/agent-runtime/sqlite.d.ts.map +1 -1
- package/dist/agent-runtime/state-tools.d.ts +63 -4
- package/dist/agent-runtime/state-tools.d.ts.map +1 -1
- package/dist/agent-runtime/store-archive.d.ts.map +1 -1
- package/dist/agent-runtime/store-branch.d.ts +6 -1
- package/dist/agent-runtime/store-branch.d.ts.map +1 -1
- package/dist/agent-runtime/store-capabilities.d.ts +42 -0
- package/dist/agent-runtime/store-capabilities.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-branch.d.ts +5 -2
- package/dist/agent-runtime/store-conformance-branch.d.ts.map +1 -1
- package/dist/agent-runtime/store-conformance-capabilities.d.ts +6 -0
- package/dist/agent-runtime/store-conformance-capabilities.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-event-once.d.ts +12 -0
- package/dist/agent-runtime/store-conformance-event-once.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-seed.d.ts +8 -0
- package/dist/agent-runtime/store-conformance-seed.d.ts.map +1 -0
- package/dist/agent-runtime/store-conformance-support.d.ts +10 -10
- package/dist/agent-runtime/store-conformance.d.ts +31 -8
- package/dist/agent-runtime/store-conformance.d.ts.map +1 -1
- package/dist/agent-runtime/store-create.d.ts +1 -1
- package/dist/agent-runtime/store-create.d.ts.map +1 -1
- package/dist/agent-runtime/store-driver-contract.d.ts +27 -8
- package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
- package/dist/agent-runtime/store-event-once.d.ts.map +1 -1
- package/dist/agent-runtime/store-events.d.ts +114 -0
- package/dist/agent-runtime/store-events.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory-archive.d.ts +2 -0
- package/dist/agent-runtime/store-memory-archive.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory-events.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory.d.ts +2 -2
- package/dist/agent-runtime/store-memory.d.ts.map +1 -1
- package/dist/agent-runtime/store-mutate.d.ts.map +1 -1
- package/dist/agent-runtime/store-reduce-shared.d.ts +2 -1
- package/dist/agent-runtime/store-reduce-shared.d.ts.map +1 -1
- package/dist/agent-runtime/store-reducer.d.ts.map +1 -1
- package/dist/agent-runtime/store-replay.d.ts.map +1 -1
- package/dist/agent-runtime/store.d.ts +22 -2
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/agent-runtime/terminal-commit.d.ts +10 -10
- package/dist/application/admission-run.d.ts.map +1 -1
- package/dist/application/admission.d.ts.map +1 -1
- package/dist/application/change-subscription.d.ts.map +1 -1
- package/dist/application/decisions.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-lock-format.d.ts +9 -0
- package/dist/application/diagnostic-journal-lock-format.d.ts.map +1 -0
- package/dist/application/diagnostic-journal-manager.d.ts.map +1 -1
- package/dist/application/directory-inbox-delivery.d.ts.map +1 -1
- package/dist/application/grammy-update-admission.d.ts.map +1 -1
- package/dist/application/health.d.ts.map +1 -1
- package/dist/application/kernel-admission.d.ts.map +1 -1
- package/dist/application/kernel-contract.d.ts.map +1 -1
- package/dist/application/kernel-restart.d.ts.map +1 -1
- package/dist/application/kernel-rollback.d.ts.map +1 -1
- package/dist/application/kernel-shutdown.d.ts.map +1 -1
- package/dist/application/kernel-state.d.ts.map +1 -1
- package/dist/application/notification-outbox-state.d.ts.map +1 -1
- package/dist/application/notification-outbox.d.ts +1 -1
- package/dist/application/notification-outbox.d.ts.map +1 -1
- package/dist/application/revision-signal.d.ts.map +1 -1
- package/dist/application/schedule-run.d.ts.map +1 -1
- package/dist/application/schedule.d.ts.map +1 -1
- package/dist/application/sqlite-migrations.d.ts +104 -0
- package/dist/application/sqlite-migrations.d.ts.map +1 -0
- package/dist/application/watch-hub-core.d.ts.map +1 -1
- package/dist/browser/bridge-errors.d.ts +24 -0
- package/dist/browser/bridge-errors.d.ts.map +1 -0
- package/dist/browser/bridge-fetch.d.ts +30 -0
- package/dist/browser/bridge-fetch.d.ts.map +1 -0
- package/dist/browser/bridge-inbound.d.ts +28 -0
- package/dist/browser/bridge-inbound.d.ts.map +1 -0
- package/dist/browser/cancellation.d.ts +10 -2
- package/dist/browser/cancellation.d.ts.map +1 -1
- package/dist/browser/chunked-upload.d.ts +1 -1
- package/dist/browser/chunked-upload.d.ts.map +1 -1
- package/dist/browser/client-call-arguments.d.ts +31 -0
- package/dist/browser/client-call-arguments.d.ts.map +1 -0
- package/dist/browser/client-executors.d.ts +6 -0
- package/dist/browser/client-executors.d.ts.map +1 -1
- package/dist/browser/client.d.ts +9 -0
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/http.d.ts +17 -2
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/realtime-client.d.ts +0 -5
- package/dist/browser/realtime-client.d.ts.map +1 -1
- package/dist/browser/session-credentials-storage.d.ts +48 -0
- package/dist/browser/session-credentials-storage.d.ts.map +1 -0
- package/dist/browser/session-credentials.d.ts +26 -5
- package/dist/browser/session-credentials.d.ts.map +1 -1
- package/dist/browser/session-refresh-policy.d.ts +124 -0
- package/dist/browser/session-refresh-policy.d.ts.map +1 -0
- package/dist/browser/session-refresh-timer.d.ts +30 -0
- package/dist/browser/session-refresh-timer.d.ts.map +1 -0
- package/dist/browser/session.d.ts.map +1 -1
- package/dist/browser/socket-io-connection.d.ts.map +1 -1
- package/dist/browser/socket-io-explicit-peer.d.ts +0 -1
- package/dist/browser/socket-io-explicit-peer.d.ts.map +1 -1
- package/dist/browser/stream.d.ts +1 -1
- package/dist/browser/stream.d.ts.map +1 -1
- package/dist/browser/upload-progress.d.ts +3 -0
- package/dist/browser/upload-progress.d.ts.map +1 -1
- package/dist/contract/bridge-envelope.d.ts +155 -0
- package/dist/contract/bridge-envelope.d.ts.map +1 -0
- package/dist/contract/define-validation.d.ts +2 -0
- package/dist/contract/define-validation.d.ts.map +1 -1
- package/dist/contract/define.d.ts +3 -0
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors.d.ts +4 -4
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/normalize.d.ts +3 -1
- package/dist/contract/normalize.d.ts.map +1 -1
- package/dist/contract/operation-effect.d.ts +29 -0
- package/dist/contract/operation-effect.d.ts.map +1 -0
- package/dist/contract/runtime-context.d.ts +2 -0
- package/dist/contract/runtime-context.d.ts.map +1 -1
- package/dist/contract/tool-options.d.ts +7 -0
- package/dist/contract/tool-options.d.ts.map +1 -1
- package/dist/declaration/command.d.ts +26 -0
- package/dist/declaration/command.d.ts.map +1 -0
- package/dist/declaration/declaration.d.ts +10 -25
- package/dist/declaration/declaration.d.ts.map +1 -1
- package/dist/declaration/machine-names.d.ts +11 -0
- package/dist/declaration/machine-names.d.ts.map +1 -0
- package/dist/durability/effect.d.ts.map +1 -1
- package/dist/durability/engine.d.ts.map +1 -1
- package/dist/durability/events.d.ts +5 -8
- package/dist/durability/events.d.ts.map +1 -1
- package/dist/durability/parks.d.ts +0 -5
- package/dist/durability/parks.d.ts.map +1 -1
- package/dist/durability/scheduler.d.ts +5 -0
- package/dist/durability/scheduler.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.d.ts +4 -0
- package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/acp.js +921 -0
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts +2 -0
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/claude-sdk.js +325 -0
- package/dist/entrypoints/agent-executor/claude.d.ts +5 -0
- package/dist/entrypoints/agent-executor/claude.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/claude.js +422 -0
- package/dist/entrypoints/agent-executor/codex.d.ts +4 -0
- package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/codex.js +858 -0
- package/dist/entrypoints/agent-executor/testing.d.ts +4 -0
- package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/testing.js +375 -0
- package/dist/entrypoints/agent-executor.d.ts +15 -0
- package/dist/entrypoints/agent-executor.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor.js +455 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts +1 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +60 -30
- package/dist/entrypoints/agent-runtime/coding-tools.js +9 -12
- package/dist/entrypoints/agent-runtime/harness.js +34 -22
- package/dist/entrypoints/agent-runtime/openrouter.d.ts +6 -0
- package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/openrouter.js +675 -45
- package/dist/entrypoints/agent-runtime/postgres.d.ts +4 -0
- package/dist/entrypoints/agent-runtime/postgres.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/postgres.js +335 -0
- package/dist/entrypoints/agent-runtime/realtime.js +46 -49
- package/dist/entrypoints/agent-runtime/sandbox.d.ts +3 -1
- package/dist/entrypoints/agent-runtime/sandbox.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/sandbox.js +74 -67
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +18 -18
- package/dist/entrypoints/agent-runtime/sqlite/node.js +18 -18
- 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 +394 -95
- package/dist/entrypoints/agent-runtime.d.ts +26 -16
- package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime.js +1439 -1198
- package/dist/entrypoints/application/diagnostic-journal.js +16 -11
- package/dist/entrypoints/application/directory-inbox.js +20 -14
- package/dist/entrypoints/application/grammy.js +11 -8
- package/dist/entrypoints/application/opentelemetry.js +3 -3
- package/dist/entrypoints/application.d.ts +4 -2
- package/dist/entrypoints/application.d.ts.map +1 -1
- package/dist/entrypoints/application.js +409 -108
- package/dist/entrypoints/bin/upgrade-cli.d.ts +0 -12
- package/dist/entrypoints/bin/upgrade-cli.d.ts.map +1 -1
- package/dist/entrypoints/bin/upgrade-cli.js +11 -7
- package/dist/entrypoints/cli/publish.js +10 -9
- package/dist/entrypoints/cli.d.ts +10 -3
- package/dist/entrypoints/cli.d.ts.map +1 -1
- package/dist/entrypoints/cli.js +92 -29
- package/dist/entrypoints/contract.d.ts +2 -1
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +13 -7
- package/dist/entrypoints/declaration.d.ts +2 -0
- package/dist/entrypoints/declaration.d.ts.map +1 -1
- package/dist/entrypoints/declaration.js +54 -44
- package/dist/entrypoints/files/packaging.js +8 -5
- package/dist/entrypoints/files.d.ts +5 -0
- package/dist/entrypoints/files.d.ts.map +1 -1
- package/dist/entrypoints/files.js +259 -47
- package/dist/entrypoints/geo.js +9 -4
- package/dist/entrypoints/google.js +14 -13
- package/dist/entrypoints/handler.d.ts +12 -0
- package/dist/entrypoints/handler.d.ts.map +1 -0
- package/dist/entrypoints/handler.js +350 -0
- package/dist/entrypoints/http.d.ts +4 -0
- package/dist/entrypoints/http.d.ts.map +1 -1
- package/dist/entrypoints/http.js +411 -5
- package/dist/entrypoints/index.d.ts +2 -0
- package/dist/entrypoints/index.d.ts.map +1 -1
- package/dist/entrypoints/index.js +664 -91
- package/dist/entrypoints/live.js +22 -12
- package/dist/entrypoints/node.d.ts +2 -1
- package/dist/entrypoints/node.d.ts.map +1 -1
- package/dist/entrypoints/node.js +34 -25
- package/dist/entrypoints/observability.d.ts +2 -0
- package/dist/entrypoints/observability.d.ts.map +1 -1
- package/dist/entrypoints/observability.js +205 -131
- package/dist/entrypoints/primitives.js +152 -14
- package/dist/entrypoints/process/owner-loss.js +2 -2
- package/dist/entrypoints/process.js +18 -92
- package/dist/entrypoints/react.js +6 -5
- package/dist/entrypoints/realtime.d.ts +1 -0
- package/dist/entrypoints/realtime.d.ts.map +1 -1
- package/dist/entrypoints/realtime.js +6 -3
- package/dist/entrypoints/release.js +4 -0
- package/dist/entrypoints/remote.js +7 -6
- package/dist/entrypoints/server.d.ts +3 -1
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +295 -194
- package/dist/entrypoints/service-host/macos.d.ts +16 -0
- package/dist/entrypoints/service-host/macos.d.ts.map +1 -0
- package/dist/entrypoints/service-host/macos.js +1998 -0
- package/dist/entrypoints/service-host.d.ts +26 -0
- package/dist/entrypoints/service-host.d.ts.map +1 -0
- package/dist/entrypoints/service-host.js +3155 -0
- package/dist/entrypoints/spend/testing.d.ts +2 -0
- package/dist/entrypoints/spend/testing.d.ts.map +1 -0
- package/dist/entrypoints/spend/testing.js +442 -0
- package/dist/entrypoints/spend.d.ts +8 -0
- package/dist/entrypoints/spend.d.ts.map +1 -0
- package/dist/entrypoints/spend.js +593 -0
- package/dist/entrypoints/sync/postgres.d.ts +12 -0
- package/dist/entrypoints/sync/postgres.d.ts.map +1 -0
- package/dist/entrypoints/sync/postgres.js +737 -0
- package/dist/entrypoints/sync.d.ts +12 -0
- package/dist/entrypoints/sync.d.ts.map +1 -0
- package/dist/entrypoints/sync.js +782 -0
- package/dist/entrypoints/telegram/grammy.js +5 -5
- package/dist/entrypoints/telegram/html.d.ts +2 -0
- package/dist/entrypoints/telegram/html.d.ts.map +1 -1
- package/dist/entrypoints/telegram/html.js +839 -2
- package/dist/entrypoints/telegram/screens.js +13 -15
- package/dist/entrypoints/telegram.d.ts +1 -1
- package/dist/entrypoints/telegram.d.ts.map +1 -1
- package/dist/entrypoints/telegram.js +286 -76
- package/dist/entrypoints/testing.js +33 -41
- package/dist/entrypoints/tools/agent.js +13 -9
- package/dist/entrypoints/tools/connections.js +664 -63
- package/dist/entrypoints/tools/contract.d.ts +2 -2
- package/dist/entrypoints/tools/contract.js +4 -1
- package/dist/entrypoints/tools/invoker.js +10 -7
- package/dist/entrypoints/tools/mcp.js +17 -13
- package/dist/entrypoints/tools/toolkit.js +22 -18
- package/dist/entrypoints/tools.d.ts +4 -2
- package/dist/entrypoints/tools.d.ts.map +1 -1
- package/dist/entrypoints/tools.js +105 -90
- package/dist/entrypoints/tracking/contract.js +2 -1
- package/dist/entrypoints/tracking/performance.js +4 -0
- package/dist/entrypoints/tracking.js +6 -1
- package/dist/entrypoints/voice.js +3 -3
- package/dist/entrypoints/xlsx.js +1 -1
- package/dist/files/boundary.d.ts.map +1 -1
- package/dist/files/chunk-spool.d.ts +27 -0
- package/dist/files/chunk-spool.d.ts.map +1 -1
- package/dist/files/directory-appearance.d.ts +55 -0
- package/dist/files/directory-appearance.d.ts.map +1 -0
- package/dist/files/file-io.d.ts.map +1 -1
- package/dist/files/file-stamp.d.ts +35 -0
- package/dist/files/file-stamp.d.ts.map +1 -0
- package/dist/files/json-file-reading.d.ts +37 -0
- package/dist/files/json-file-reading.d.ts.map +1 -0
- package/dist/files/native-packaging.d.ts.map +1 -1
- package/dist/files/polled-json.d.ts +121 -0
- package/dist/files/polled-json.d.ts.map +1 -0
- package/dist/files/regular-file.d.ts +135 -0
- package/dist/files/regular-file.d.ts.map +1 -0
- package/dist/geo/index.d.ts +2 -1
- package/dist/geo/index.d.ts.map +1 -1
- package/dist/geo/resolver.d.ts.map +1 -1
- package/dist/geo/types.d.ts +0 -1
- package/dist/geo/types.d.ts.map +1 -1
- package/dist/google/google.d.ts +6 -0
- package/dist/google/google.d.ts.map +1 -1
- package/dist/{index-w0eqdhyd.js → index-09f7w2qq.js} +6 -1
- package/dist/index-0gqs8ght.js +558 -0
- package/dist/{index-t05a2ry4.js → index-0p0s5hrj.js} +8 -14
- package/dist/{index-1c945ten.js → index-0r15pkjq.js} +1 -1
- package/dist/{index-v1swr26p.js → index-0tyt97nk.js} +2 -2
- package/dist/{index-332d0m9g.js → index-0x4mnwg5.js} +4 -0
- package/dist/index-118aebbg.js +48 -0
- package/dist/index-13dnv6d0.js +296 -0
- package/dist/index-1q0n6zek.js +184 -0
- package/dist/index-1qwrczr1.js +405 -0
- package/dist/index-27hck3z2.js +307 -0
- package/dist/index-2c5w2d1d.js +107 -0
- package/dist/{index-fvd6pvw3.js → index-2nwvn7m2.js} +2 -2
- package/dist/index-2rf33y2h.js +77 -0
- package/dist/index-360j58vb.js +63 -0
- package/dist/{index-tt30h7mr.js → index-39n02e0q.js} +1 -1
- package/dist/{index-mfntvj58.js → index-3dq8466w.js} +1 -1
- package/dist/index-3tnwtz38.js +725 -0
- package/dist/{index-x2d51zay.js → index-3ypvpkwr.js} +309 -345
- package/dist/index-4gk6k3zc.js +248 -0
- package/dist/{index-kxff9e9w.js → index-4j8efqr3.js} +5 -4
- package/dist/index-4qvyhn23.js +40 -0
- package/dist/index-4ynw5ktx.js +78 -0
- package/dist/index-5awtbyns.js +19 -0
- package/dist/{index-nz06qw5a.js → index-5jyjb4s0.js} +1 -1
- package/dist/{index-7zksb1ty.js → index-5ptwb6ka.js} +1 -1
- package/dist/{index-w3nv6kr8.js → index-5q0qpw3v.js} +54 -9
- package/dist/{index-mm89hd8v.js → index-5t4fpdct.js} +1 -1
- package/dist/index-5v5vg85s.js +108 -0
- package/dist/{index-0v9xb8pz.js → index-5y7j383h.js} +5 -5
- package/dist/{index-bqzgaj57.js → index-673drwkn.js} +198 -61
- package/dist/{index-v62cpkx3.js → index-6g85s734.js} +1 -1
- package/dist/{index-sqc6ezrb.js → index-6kec3b14.js} +17 -4
- package/dist/{index-cvjddnvd.js → index-6wp4dn9d.js} +17 -8
- package/dist/{index-kqnd6a85.js → index-7416mhyh.js} +1 -1
- package/dist/{index-m0wsfmrc.js → index-7csn6pva.js} +37 -24
- package/dist/{index-dqpesdck.js → index-7grgs8cx.js} +25 -5
- package/dist/{index-jjvr9f15.js → index-7kfcb576.js} +129 -39
- package/dist/{index-ss67fxhj.js → index-877e9y8r.js} +7 -7
- package/dist/{index-aw6kx2e6.js → index-8gmmdz7k.js} +1 -1
- package/dist/index-8x22nprv.js +1461 -0
- package/dist/{index-rz3z13e9.js → index-97q9kykw.js} +1 -1
- package/dist/index-97rp94ff.js +8 -0
- package/dist/{index-0w0hxp7n.js → index-9pv126eh.js} +3 -9
- package/dist/{index-egg0yp2j.js → index-9xr44d2g.js} +86 -210
- package/dist/{index-b2sey031.js → index-9y0afd5f.js} +24 -23
- package/dist/{index-nmaqxdx7.js → index-ac5rj3d4.js} +203 -90
- package/dist/{index-wqzw3qg9.js → index-agy5fqgf.js} +32 -13
- package/dist/{index-ndjzbt2v.js → index-akf0xkrm.js} +4 -3
- package/dist/index-akfgymyr.js +8 -0
- package/dist/index-apv5xfef.js +13 -0
- package/dist/index-bh4pmtr9.js +317 -0
- package/dist/{index-fa53vygr.js → index-bmaz3jzy.js} +3 -3
- package/dist/{index-8kzct1d6.js → index-bn2baakz.js} +143 -143
- package/dist/{index-m8ddk770.js → index-brhhaygm.js} +1 -1
- package/dist/index-bz3gn6cs.js +407 -0
- package/dist/index-c5gp2gh6.js +51 -0
- package/dist/index-cbhxhma2.js +90 -0
- package/dist/index-cfnmvcq8.js +11 -0
- package/dist/index-cv9b7fz2.js +42 -0
- package/dist/index-d4svrknj.js +156 -0
- package/dist/{index-1szhrfsf.js → index-d54npte7.js} +7 -5
- package/dist/{index-ne4j9998.js → index-e06z0tkb.js} +123 -94
- package/dist/index-emgrmavr.js +1193 -0
- package/dist/{index-99nnsz39.js → index-en8e5zsj.js} +15 -135
- package/dist/{index-20hn8pbh.js → index-fmzg39a8.js} +1 -1
- package/dist/{index-ft2wvst5.js → index-g3e57qj6.js} +1928 -414
- package/dist/index-g56ht6qf.js +98 -0
- package/dist/{index-7cn66qdk.js → index-gf92hc87.js} +15 -7
- package/dist/{index-f56ct5gb.js → index-gj1rjf78.js} +4 -3
- package/dist/{index-g6a3na27.js → index-gnjgkecx.js} +7 -3
- package/dist/index-gzny6zsw.js +487 -0
- package/dist/{index-n6hvd1r2.js → index-hj1zq7mh.js} +26 -13
- package/dist/index-hy4653g4.js +345 -0
- package/dist/{index-t8jz0e20.js → index-j903yhp4.js} +30 -38
- package/dist/{index-9ypczvpj.js → index-jb4m241t.js} +2 -0
- package/dist/{index-wt6rw7rf.js → index-jfecdk1e.js} +29 -21
- package/dist/{index-cjzaj7ev.js → index-jxtg307y.js} +23 -21
- package/dist/{index-3ymcmpa9.js → index-ke02kxsr.js} +33 -163
- package/dist/{index-bz9cmnqq.js → index-kt6dh1n6.js} +4 -4
- package/dist/index-ky3ardqn.js +80 -0
- package/dist/index-kyejf658.js +14 -0
- package/dist/{index-zyc64nbh.js → index-kynwa08q.js} +52 -47
- package/dist/index-kzavdze2.js +15 -0
- package/dist/{index-48acz7z0.js → index-m18xm96h.js} +93 -46
- package/dist/{index-m200b8hs.js → index-mbd92r1w.js} +5 -3
- package/dist/index-mxt0wfjy.js +58 -0
- package/dist/{index-9cxxfkhb.js → index-n20tybgk.js} +14 -9
- package/dist/{index-1v3k5zgx.js → index-n7f89hjw.js} +610 -1168
- package/dist/index-ngwf1s3c.js +51 -0
- package/dist/{index-zfncctjp.js → index-nk0cy9g1.js} +5 -4
- package/dist/{index-hs76yzt7.js → index-paff5y0r.js} +17 -11
- package/dist/index-pn5b11ce.js +40 -0
- package/dist/{index-qaet40b2.js → index-prf6ayhf.js} +5 -7
- package/dist/{index-hkxgennw.js → index-ps3djm8d.js} +7 -1
- package/dist/index-pwskmywy.js +195 -0
- package/dist/{index-3bzk2645.js → index-r9kq5ark.js} +1 -1
- package/dist/{index-hkw233vx.js → index-rbd2rq3z.js} +2 -2
- package/dist/{index-r0xr7y4m.js → index-rhb33thr.js} +138 -33
- package/dist/{index-kffm4r8w.js → index-rj32hkkp.js} +2 -2
- package/dist/index-rptj3qnc.js +96 -0
- package/dist/{index-hqsbtvta.js → index-rpyn7geq.js} +11 -3
- package/dist/{index-x2rvpbtj.js → index-rxnyygke.js} +151 -17
- package/dist/index-rzeezh79.js +508 -0
- package/dist/index-s2e3h616.js +351 -0
- package/dist/{index-m9hb9wnk.js → index-sfzfd2m2.js} +2 -2
- package/dist/{index-sqkttz7z.js → index-sv5svtq7.js} +1 -1
- package/dist/{index-srs8hj9c.js → index-sx3g49y2.js} +5 -1
- package/dist/{index-9mjrnqxs.js → index-t1a2jrg7.js} +21 -91
- package/dist/index-t7wa7k12.js +221 -0
- package/dist/{index-a6w6mwda.js → index-tazm4dxf.js} +1 -1
- package/dist/{index-b51tzcgh.js → index-tf70nm22.js} +2 -2
- package/dist/index-ttexdtjj.js +28 -0
- package/dist/{index-btjwc7xr.js → index-v1mxss62.js} +15 -14
- package/dist/{index-103dp7fz.js → index-v37b2cd6.js} +1956 -3151
- package/dist/{index-0ndz5r8z.js → index-v59pxmf1.js} +17 -9
- package/dist/{index-rfkh44ss.js → index-vgytj9wp.js} +1 -1
- package/dist/index-vgzhw2zk.js +304 -0
- package/dist/index-vmbxj75t.js +177 -0
- package/dist/{index-tnnmekgb.js → index-wa6h4tz6.js} +3 -3
- package/dist/{index-pa9bhefy.js → index-waa6t4zx.js} +83 -10
- package/dist/{index-4efxzrht.js → index-wavv538x.js} +211 -196
- package/dist/index-werjqesf.js +43 -0
- package/dist/{index-7qyv50r4.js → index-wv8dqy7q.js} +2 -2
- package/dist/index-wz392jyz.js +10 -0
- package/dist/{index-1d7s7da0.js → index-x6sp5vpa.js} +36 -5
- package/dist/index-xgae0bn7.js +37 -0
- package/dist/index-xmr47znh.js +160 -0
- package/dist/{index-ftk3838x.js → index-xq4s9mka.js} +7 -2
- package/dist/{index-ww3gss55.js → index-xrgn784x.js} +1 -1
- package/dist/{index-fpwbskp2.js → index-xtby8rj3.js} +1 -1
- package/dist/index-xv9jb84s.js +929 -0
- package/dist/{index-v7rbjatr.js → index-y065r8g5.js} +1881 -1156
- package/dist/{index-yex7eg1v.js → index-y7sy1xdp.js} +6 -2
- package/dist/{index-a7ebd769.js → index-zwgwyvdt.js} +3 -3
- package/dist/internal/abort-error.d.ts +9 -0
- package/dist/internal/abort-error.d.ts.map +1 -0
- package/dist/internal/abort-race.d.ts +47 -4
- package/dist/internal/abort-race.d.ts.map +1 -1
- package/dist/internal/atomic-file.d.ts +19 -0
- package/dist/internal/atomic-file.d.ts.map +1 -1
- package/dist/internal/backoff.d.ts.map +1 -1
- package/dist/internal/bounded-body.d.ts +37 -1
- package/dist/internal/bounded-body.d.ts.map +1 -1
- package/dist/internal/bounded-file-confirm.d.ts +32 -0
- package/dist/internal/bounded-file-confirm.d.ts.map +1 -0
- package/dist/internal/bounded-file-read.d.ts +34 -15
- package/dist/internal/bounded-file-read.d.ts.map +1 -1
- package/dist/internal/bun-command.d.ts +11 -0
- package/dist/internal/bun-command.d.ts.map +1 -1
- package/dist/internal/channel.d.ts.map +1 -1
- package/dist/internal/darwin-binding-error.d.ts.map +1 -1
- package/dist/internal/darwin-binding.d.ts +10 -0
- package/dist/internal/darwin-binding.d.ts.map +1 -1
- package/dist/internal/deadline.d.ts +22 -2
- package/dist/internal/deadline.d.ts.map +1 -1
- package/dist/internal/exclusive-lock-owner.d.ts +20 -1
- package/dist/internal/exclusive-lock-owner.d.ts.map +1 -1
- package/dist/internal/exclusive-lock-read.d.ts +2 -0
- package/dist/internal/exclusive-lock-read.d.ts.map +1 -1
- package/dist/internal/exclusive-lock.d.ts +26 -0
- package/dist/internal/exclusive-lock.d.ts.map +1 -1
- package/dist/internal/file-observation.d.ts +53 -0
- package/dist/internal/file-observation.d.ts.map +1 -1
- package/dist/internal/json-response.d.ts +10 -0
- package/dist/internal/json-response.d.ts.map +1 -0
- package/dist/internal/open-descriptors.d.ts +5 -0
- package/dist/internal/open-descriptors.d.ts.map +1 -1
- package/dist/internal/optional-peer.d.ts.map +1 -1
- package/dist/internal/pinned-http.d.ts.map +1 -1
- package/dist/internal/positive-integer.d.ts +14 -6
- package/dist/internal/positive-integer.d.ts.map +1 -1
- package/dist/internal/postgres-query.d.ts +16 -0
- package/dist/internal/postgres-query.d.ts.map +1 -0
- package/dist/internal/process-identity.d.ts +21 -1
- package/dist/internal/process-identity.d.ts.map +1 -1
- package/dist/internal/process-instance.d.ts +14 -0
- package/dist/internal/process-instance.d.ts.map +1 -1
- package/dist/internal/request.d.ts +4 -0
- package/dist/internal/request.d.ts.map +1 -1
- package/dist/internal/secret-equal.d.ts +11 -0
- package/dist/internal/secret-equal.d.ts.map +1 -0
- package/dist/internal/secure-fetch.d.ts.map +1 -1
- package/dist/internal/sqlite.d.ts +8 -0
- package/dist/internal/sqlite.d.ts.map +1 -1
- package/dist/internal/timers.d.ts +20 -0
- package/dist/internal/timers.d.ts.map +1 -1
- package/dist/internal/typed.d.ts +11 -0
- package/dist/internal/typed.d.ts.map +1 -1
- package/dist/internal/unix-client-error.d.ts +21 -0
- package/dist/internal/unix-client-error.d.ts.map +1 -0
- package/dist/internal/unix-socket-lock.d.ts +23 -0
- package/dist/internal/unix-socket-lock.d.ts.map +1 -0
- package/dist/internal/unix-socket.d.ts +62 -0
- package/dist/internal/unix-socket.d.ts.map +1 -1
- package/dist/internal/upgrade-affects.d.ts +3 -3
- package/dist/internal/upgrade-affects.d.ts.map +1 -1
- package/dist/internal/upgrade-plan.d.ts.map +1 -1
- package/dist/json-schema/dialect.d.ts +0 -6
- package/dist/json-schema/dialect.d.ts.map +1 -1
- package/dist/json-schema/keywords.d.ts +116 -0
- package/dist/json-schema/keywords.d.ts.map +1 -0
- package/dist/json-schema/string-format.d.ts.map +1 -1
- package/dist/live/events.d.ts.map +1 -1
- package/dist/live/watch-client.d.ts.map +1 -1
- package/dist/observability/bounded-logger.d.ts +3 -0
- package/dist/observability/bounded-logger.d.ts.map +1 -1
- package/dist/observability/bounded-sink.d.ts.map +1 -1
- package/dist/observability/context.d.ts +12 -2
- package/dist/observability/context.d.ts.map +1 -1
- package/dist/observability/event-loop-delay.d.ts +62 -0
- package/dist/observability/event-loop-delay.d.ts.map +1 -0
- package/dist/observability/json-logger.d.ts.map +1 -1
- package/dist/observability/log-repeat.d.ts +44 -0
- package/dist/observability/log-repeat.d.ts.map +1 -0
- package/dist/observability/spool-core.d.ts +95 -0
- package/dist/observability/spool-core.d.ts.map +1 -0
- package/dist/observability/spool-file.d.ts +46 -0
- package/dist/observability/spool-file.d.ts.map +1 -0
- package/dist/observability/spool.d.ts +14 -8
- package/dist/observability/spool.d.ts.map +1 -1
- package/dist/observability/trace.d.ts.map +1 -1
- package/dist/observability/work.d.ts.map +1 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/order-key.d.ts +37 -0
- package/dist/primitives/order-key.d.ts.map +1 -0
- package/dist/process/bun-child.d.ts.map +1 -1
- package/dist/process/command-owner.d.ts.map +1 -1
- package/dist/process/contract.d.ts +4 -3
- package/dist/process/contract.d.ts.map +1 -1
- package/dist/process/group-presence.d.ts.map +1 -1
- package/dist/process/group.d.ts +5 -1
- package/dist/process/group.d.ts.map +1 -1
- package/dist/process/launch.d.ts +5 -3
- package/dist/process/launch.d.ts.map +1 -1
- package/dist/process/owner-loss-guard.d.ts.map +1 -1
- package/dist/react/cache-bridge.d.ts.map +1 -1
- package/dist/release/watcher.d.ts.map +1 -1
- package/dist/server/bridge-host.d.ts +51 -0
- package/dist/server/bridge-host.d.ts.map +1 -0
- package/dist/server/bun.d.ts +4 -4
- package/dist/server/bun.d.ts.map +1 -1
- package/dist/server/context-contribution.d.ts.map +1 -1
- package/dist/server/contract-method.d.ts.map +1 -1
- package/dist/server/create.d.ts +1 -0
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/endpoint-dispatch.d.ts.map +1 -1
- package/dist/server/endpoint-response.d.ts.map +1 -1
- package/dist/server/error-dispatch.d.ts +2 -0
- package/dist/server/error-dispatch.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +2 -0
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/server/handler-state.d.ts +13 -2
- package/dist/server/handler-state.d.ts.map +1 -1
- package/dist/server/implement.d.ts +1 -0
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/local-host.d.ts +47 -0
- package/dist/server/local-host.d.ts.map +1 -0
- package/dist/server/logger.d.ts +20 -3
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/logging.d.ts +2 -1
- package/dist/server/logging.d.ts.map +1 -1
- package/dist/server/middleware/cors.d.ts +1 -0
- package/dist/server/middleware/cors.d.ts.map +1 -1
- package/dist/server/middleware/signed-link.d.ts +42 -0
- package/dist/server/middleware/signed-link.d.ts.map +1 -0
- package/dist/server/multipart-reader.d.ts +3 -1
- package/dist/server/multipart-reader.d.ts.map +1 -1
- package/dist/server/multipart.d.ts.map +1 -1
- package/dist/server/oauth/cimd.d.ts.map +1 -1
- package/dist/server/oauth/endpoints.d.ts.map +1 -1
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/protocol-outcome.d.ts +17 -0
- package/dist/server/protocol-outcome.d.ts.map +1 -0
- package/dist/server/raw.d.ts.map +1 -1
- package/dist/server/request-completion.d.ts +3 -1
- package/dist/server/request-completion.d.ts.map +1 -1
- package/dist/server/shutdown.d.ts.map +1 -1
- package/dist/server/socket-io-config.d.ts +1 -1
- package/dist/server/socket-io-config.d.ts.map +1 -1
- package/dist/server/streaming-route.d.ts.map +1 -1
- package/dist/server/types.d.ts +13 -10
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/unix-client-body.d.ts +4 -1
- package/dist/server/unix-client-body.d.ts.map +1 -1
- package/dist/server/unix-client-bun.d.ts.map +1 -1
- package/dist/server/unix-client.d.ts +8 -1
- package/dist/server/unix-client.d.ts.map +1 -1
- package/dist/service-host/artifact-activation.d.ts +58 -0
- package/dist/service-host/artifact-activation.d.ts.map +1 -0
- package/dist/service-host/artifact-manifest.d.ts +68 -0
- package/dist/service-host/artifact-manifest.d.ts.map +1 -0
- package/dist/service-host/artifact.d.ts +43 -0
- package/dist/service-host/artifact.d.ts.map +1 -0
- package/dist/service-host/config-reloader-contract.d.ts +66 -0
- package/dist/service-host/config-reloader-contract.d.ts.map +1 -0
- package/dist/service-host/config-reloader-helpers.d.ts +32 -0
- package/dist/service-host/config-reloader-helpers.d.ts.map +1 -0
- package/dist/service-host/config-reloader-source.d.ts +47 -0
- package/dist/service-host/config-reloader-source.d.ts.map +1 -0
- package/dist/service-host/config-reloader.d.ts +6 -0
- package/dist/service-host/config-reloader.d.ts.map +1 -0
- package/dist/service-host/host-adapter.d.ts +72 -0
- package/dist/service-host/host-adapter.d.ts.map +1 -0
- package/dist/service-host/identity-unix-socket.d.ts +101 -0
- package/dist/service-host/identity-unix-socket.d.ts.map +1 -0
- package/dist/service-host/identity.d.ts +117 -0
- package/dist/service-host/identity.d.ts.map +1 -0
- package/dist/service-host/launchd-plist.d.ts +77 -0
- package/dist/service-host/launchd-plist.d.ts.map +1 -0
- package/dist/service-host/launchd-render.d.ts +91 -0
- package/dist/service-host/launchd-render.d.ts.map +1 -0
- package/dist/service-host/launchd.d.ts +82 -0
- package/dist/service-host/launchd.d.ts.map +1 -0
- package/dist/service-host/macos/bundle-plist.d.ts +50 -0
- package/dist/service-host/macos/bundle-plist.d.ts.map +1 -0
- package/dist/service-host/macos/bundle.d.ts +66 -0
- package/dist/service-host/macos/bundle.d.ts.map +1 -0
- package/dist/service-host/macos/codesign.d.ts +95 -0
- package/dist/service-host/macos/codesign.d.ts.map +1 -0
- package/dist/service-host/macos/icon.d.ts +93 -0
- package/dist/service-host/macos/icon.d.ts.map +1 -0
- package/dist/service-host/macos/launch-services.d.ts +88 -0
- package/dist/service-host/macos/launch-services.d.ts.map +1 -0
- package/dist/service-host/macos/launcher.d.ts +59 -0
- package/dist/service-host/macos/launcher.d.ts.map +1 -0
- package/dist/service-host/macos/responsibility.d.ts +90 -0
- package/dist/service-host/macos/responsibility.d.ts.map +1 -0
- package/dist/service-host/macos/runner.d.ts +69 -0
- package/dist/service-host/macos/runner.d.ts.map +1 -0
- package/dist/service-host/plist-xml.d.ts +48 -0
- package/dist/service-host/plist-xml.d.ts.map +1 -0
- package/dist/service-host/process-evidence.d.ts +17 -0
- package/dist/service-host/process-evidence.d.ts.map +1 -0
- package/dist/service-host/systemd-inspect.d.ts +128 -0
- package/dist/service-host/systemd-inspect.d.ts.map +1 -0
- package/dist/service-host/systemd-links.d.ts +23 -0
- package/dist/service-host/systemd-links.d.ts.map +1 -0
- package/dist/service-host/systemd-render-shared.d.ts +64 -0
- package/dist/service-host/systemd-render-shared.d.ts.map +1 -0
- package/dist/service-host/systemd-render.d.ts +98 -0
- package/dist/service-host/systemd-render.d.ts.map +1 -0
- package/dist/service-host/systemd-timer-render.d.ts +31 -0
- package/dist/service-host/systemd-timer-render.d.ts.map +1 -0
- package/dist/service-host/systemd-timer-rollback.d.ts +26 -0
- package/dist/service-host/systemd-timer-rollback.d.ts.map +1 -0
- package/dist/service-host/systemd-timer.d.ts +82 -0
- package/dist/service-host/systemd-timer.d.ts.map +1 -0
- package/dist/service-host/systemd-unit-ops.d.ts +26 -0
- package/dist/service-host/systemd-unit-ops.d.ts.map +1 -0
- package/dist/service-host/systemd.d.ts +50 -0
- package/dist/service-host/systemd.d.ts.map +1 -0
- package/dist/spend/attribution.d.ts +17 -0
- package/dist/spend/attribution.d.ts.map +1 -0
- package/dist/spend/coverage-guard.d.ts +60 -0
- package/dist/spend/coverage-guard.d.ts.map +1 -0
- package/dist/spend/coverage-lexer.d.ts +20 -0
- package/dist/spend/coverage-lexer.d.ts.map +1 -0
- package/dist/spend/facts.d.ts +23 -0
- package/dist/spend/facts.d.ts.map +1 -0
- package/dist/spend/gateway-stream.d.ts +25 -0
- package/dist/spend/gateway-stream.d.ts.map +1 -0
- package/dist/spend/gateway.d.ts +64 -0
- package/dist/spend/gateway.d.ts.map +1 -0
- package/dist/spend/receipt-merge.d.ts +13 -0
- package/dist/spend/receipt-merge.d.ts.map +1 -0
- package/dist/spend/receipt-spool.d.ts +35 -0
- package/dist/spend/receipt-spool.d.ts.map +1 -0
- package/dist/spend/reconcile.d.ts +45 -0
- package/dist/spend/reconcile.d.ts.map +1 -0
- package/dist/spend/schemas.d.ts +249 -0
- package/dist/spend/schemas.d.ts.map +1 -0
- package/dist/sync/outbox.d.ts +131 -0
- package/dist/sync/outbox.d.ts.map +1 -0
- package/dist/sync/overlay.d.ts +59 -0
- package/dist/sync/overlay.d.ts.map +1 -0
- package/dist/sync/protocol.d.ts +132 -0
- package/dist/sync/protocol.d.ts.map +1 -0
- package/dist/sync/server-store-check.d.ts +10 -0
- package/dist/sync/server-store-check.d.ts.map +1 -0
- package/dist/sync/server-store-memory.d.ts +14 -0
- package/dist/sync/server-store-memory.d.ts.map +1 -0
- package/dist/sync/server-store-postgres.d.ts +25 -0
- package/dist/sync/server-store-postgres.d.ts.map +1 -0
- package/dist/sync/server-store.d.ts +139 -0
- package/dist/sync/server-store.d.ts.map +1 -0
- package/dist/sync/session-machine.d.ts +79 -0
- package/dist/sync/session-machine.d.ts.map +1 -0
- package/dist/sync/session-snapshot.d.ts +19 -0
- package/dist/sync/session-snapshot.d.ts.map +1 -0
- package/dist/sync/session-steps.d.ts +15 -0
- package/dist/sync/session-steps.d.ts.map +1 -0
- package/dist/sync/session.d.ts +142 -0
- package/dist/sync/session.d.ts.map +1 -0
- package/dist/sync/tombstones.d.ts +53 -0
- package/dist/sync/tombstones.d.ts.map +1 -0
- package/dist/telegram/bot-api.d.ts.map +1 -1
- package/dist/telegram/broadcast-failure.d.ts.map +1 -1
- package/dist/telegram/budget-transformer.d.ts.map +1 -1
- package/dist/telegram/crypto.d.ts +2 -10
- package/dist/telegram/crypto.d.ts.map +1 -1
- package/dist/telegram/html/markdown-inline.d.ts +19 -0
- package/dist/telegram/html/markdown-inline.d.ts.map +1 -0
- package/dist/telegram/html/markdown-lines.d.ts +51 -0
- package/dist/telegram/html/markdown-lines.d.ts.map +1 -0
- package/dist/telegram/html/markdown-split.d.ts +49 -0
- package/dist/telegram/html/markdown-split.d.ts.map +1 -0
- package/dist/telegram/html/markdown.d.ts +14 -0
- package/dist/telegram/html/markdown.d.ts.map +1 -0
- package/dist/telegram/html/nodes.d.ts +26 -4
- package/dist/telegram/html/nodes.d.ts.map +1 -1
- package/dist/telegram/html/parse.d.ts.map +1 -1
- package/dist/telegram/html/render.d.ts.map +1 -1
- package/dist/telegram/init-data.d.ts.map +1 -1
- package/dist/telegram/local-files.d.ts.map +1 -1
- package/dist/telegram/operator-channel.d.ts +15 -2
- package/dist/telegram/operator-channel.d.ts.map +1 -1
- package/dist/telegram/outbound-budget.d.ts.map +1 -1
- package/dist/telegram/outbound-cost.d.ts +9 -1
- package/dist/telegram/outbound-cost.d.ts.map +1 -1
- package/dist/telegram/outbound-queue.d.ts +2 -1
- package/dist/telegram/outbound-queue.d.ts.map +1 -1
- package/dist/telegram/screens/outcome.d.ts.map +1 -1
- package/dist/telegram/send-failure.d.ts.map +1 -1
- package/dist/telegram/transport-connect.d.ts.map +1 -1
- package/dist/telegram/transport.d.ts.map +1 -1
- package/dist/telegram/update-intake.d.ts.map +1 -1
- package/dist/telegram/update-store-postgres.d.ts +2 -2
- package/dist/telegram/update-store-postgres.d.ts.map +1 -1
- package/dist/telegram/webhook.d.ts.map +1 -1
- package/dist/testing/managed-resource-conformance.d.ts.map +1 -1
- package/dist/testing/surface-conformance.d.ts.map +1 -1
- package/dist/testing/surface-manifest.d.ts +2 -0
- package/dist/testing/surface-manifest.d.ts.map +1 -1
- package/dist/tools/access.d.ts +63 -0
- package/dist/tools/access.d.ts.map +1 -0
- package/dist/tools/agent.d.ts +14 -6
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/args-classify.d.ts +154 -0
- package/dist/tools/cli/args-classify.d.ts.map +1 -0
- package/dist/tools/cli/args-fields.d.ts +14 -7
- package/dist/tools/cli/args-fields.d.ts.map +1 -1
- package/dist/tools/cli/args-json.d.ts +1 -1
- package/dist/tools/cli/args-json.d.ts.map +1 -1
- package/dist/tools/cli/args-route.d.ts +4 -48
- package/dist/tools/cli/args-route.d.ts.map +1 -1
- package/dist/tools/cli/args-scan.d.ts +75 -0
- package/dist/tools/cli/args-scan.d.ts.map +1 -0
- package/dist/tools/cli/args-tokens.d.ts +2 -1
- package/dist/tools/cli/args-tokens.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts +37 -19
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/checkpoint.d.ts.map +1 -1
- package/dist/tools/cli/command-shape.d.ts +5 -0
- package/dist/tools/cli/command-shape.d.ts.map +1 -1
- package/dist/tools/cli/command.d.ts +57 -2
- package/dist/tools/cli/command.d.ts.map +1 -1
- package/dist/tools/cli/config.d.ts +15 -58
- package/dist/tools/cli/config.d.ts.map +1 -1
- package/dist/tools/cli/create-cli.d.ts +7 -3
- package/dist/tools/cli/create-cli.d.ts.map +1 -1
- package/dist/tools/cli/format.d.ts.map +1 -1
- package/dist/tools/cli/help.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +71 -20
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/io.d.ts.map +1 -1
- package/dist/tools/cli/managed-surface.d.ts.map +1 -1
- package/dist/tools/cli/notices.d.ts.map +1 -1
- package/dist/tools/cli/policy.d.ts +66 -10
- package/dist/tools/cli/policy.d.ts.map +1 -1
- package/dist/tools/cli/prepare.d.ts +5 -4
- package/dist/tools/cli/prepare.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/run-native.d.ts.map +1 -1
- package/dist/tools/cli/run-stream.d.ts.map +1 -1
- package/dist/tools/cli/runner.d.ts +28 -0
- package/dist/tools/cli/runner.d.ts.map +1 -0
- package/dist/tools/cli/session.d.ts +12 -6
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/cli/stream-surface.d.ts.map +1 -1
- package/dist/tools/cli/stream.d.ts.map +1 -1
- package/dist/tools/cli/unavailable.d.ts +2 -0
- package/dist/tools/cli/unavailable.d.ts.map +1 -1
- package/dist/tools/cli/unix-outcome.d.ts +8 -0
- package/dist/tools/cli/unix-outcome.d.ts.map +1 -0
- package/dist/tools/cli/update.d.ts.map +1 -1
- package/dist/tools/cli/view-columns.d.ts +18 -0
- package/dist/tools/cli/view-columns.d.ts.map +1 -0
- package/dist/tools/cli/view.d.ts.map +1 -1
- package/dist/tools/connections/define.d.ts.map +1 -1
- package/dist/tools/connections/foreign-schema-join.d.ts +28 -0
- package/dist/tools/connections/foreign-schema-join.d.ts.map +1 -0
- package/dist/tools/connections/foreign-schema.d.ts +9 -0
- package/dist/tools/connections/foreign-schema.d.ts.map +1 -0
- package/dist/tools/connections/limits.d.ts +1 -1
- package/dist/tools/connections/limits.d.ts.map +1 -1
- package/dist/tools/connections/mcp-client.d.ts.map +1 -1
- package/dist/tools/connections/mcp.d.ts.map +1 -1
- package/dist/tools/connections/openapi.d.ts.map +1 -1
- package/dist/tools/connections/runtime.d.ts +18 -6
- package/dist/tools/connections/runtime.d.ts.map +1 -1
- package/dist/tools/connections/sse-session.d.ts.map +1 -1
- package/dist/tools/connections/types.d.ts +12 -2
- package/dist/tools/connections/types.d.ts.map +1 -1
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/internal/expose.d.ts +6 -0
- package/dist/tools/internal/expose.d.ts.map +1 -0
- package/dist/tools/internal/json-projection.d.ts +17 -0
- package/dist/tools/internal/json-projection.d.ts.map +1 -0
- package/dist/tools/internal/surface-projector.d.ts +18 -4
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +10 -2
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/lifecycle.d.ts +8 -2
- package/dist/tools/lifecycle.d.ts.map +1 -1
- package/dist/tools/list-names.d.ts +3 -4
- package/dist/tools/list-names.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +4 -3
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +26 -14
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/prepare.d.ts +2 -0
- package/dist/tools/mcp/prepare.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +2 -1
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/dist/tools/mcp/stdio.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +7 -2
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/native-definition.d.ts +1 -1
- package/dist/tools/native-definition.d.ts.map +1 -1
- package/dist/tools/operations/async-operation-runtime-tools.d.ts +2 -2
- package/dist/tools/operations/async-operation-runtime-tools.d.ts.map +1 -1
- package/dist/tools/operations/async-operation-runtime-types.d.ts +1 -1
- package/dist/tools/operations/async-operation-runtime-types.d.ts.map +1 -1
- package/dist/tools/operations/define-wait-tool.d.ts.map +1 -1
- package/dist/tools/operations/mount-wait.d.ts.map +1 -1
- package/dist/tools/operations/wait-core.d.ts.map +1 -1
- package/dist/tools/read-operation.d.ts +6 -4
- package/dist/tools/read-operation.d.ts.map +1 -1
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/runtime-tool-declaration.d.ts +4 -1
- package/dist/tools/runtime-tool-declaration.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts +6 -1
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/schema/coerce.d.ts.map +1 -1
- package/dist/tools/schema/inline-references.d.ts +7 -0
- package/dist/tools/schema/inline-references.d.ts.map +1 -0
- package/dist/tools/schema/json-schema-origin.d.ts +1 -1
- package/dist/tools/schema/json-schema-origin.d.ts.map +1 -1
- package/dist/tools/schema/presentation.d.ts +6 -0
- package/dist/tools/schema/presentation.d.ts.map +1 -1
- package/dist/tools/schema/schema.d.ts +2 -0
- package/dist/tools/schema/schema.d.ts.map +1 -1
- package/dist/tools/schema/untyped-properties.d.ts.map +1 -1
- package/dist/tools/surface.d.ts.map +1 -1
- package/dist/tools/toolkit.d.ts +6 -3
- package/dist/tools/toolkit.d.ts.map +1 -1
- package/dist/tools/transfer/define-download-tool.d.ts.map +1 -1
- package/dist/tools/transfer/define-upload-tool.d.ts.map +1 -1
- package/dist/tools/transfer/define-view-file-tool.d.ts +2 -1
- package/dist/tools/transfer/define-view-file-tool.d.ts.map +1 -1
- package/dist/tools/transfer/mount-download.d.ts.map +1 -1
- package/dist/tools/transfer/view-file-contract.d.ts +2 -2
- package/dist/tools/transfer/view-file.d.ts +1 -2
- package/dist/tools/transfer/view-file.d.ts.map +1 -1
- package/dist/tracking/client.d.ts +0 -13
- package/dist/tracking/client.d.ts.map +1 -1
- package/dist/tracking/delivery.d.ts.map +1 -1
- package/dist/tracking/performance/collector.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +55 -0
- package/llms/agent-executor-claude-sdk.txt +31 -0
- package/llms/agent-executor-claude.txt +29 -0
- package/llms/agent-executor-codex.txt +25 -0
- package/llms/agent-executor-testing.txt +26 -0
- package/llms/agent-executor.txt +40 -0
- package/llms/agent-runtime-harness.txt +68 -5
- package/llms/agent-runtime-openrouter.txt +8 -2
- package/llms/agent-runtime-postgres.txt +30 -0
- package/llms/agent-runtime-react.txt +1 -1
- package/llms/agent-runtime-realtime.txt +1 -1
- package/llms/agent-runtime-sandbox.txt +5 -2
- package/llms/agent-runtime-sqlite-bun.txt +2 -2
- package/llms/agent-runtime-sqlite-node.txt +2 -2
- package/llms/agent-runtime-testing.txt +2 -1
- package/llms/agent-runtime.2.txt +450 -501
- package/llms/agent-runtime.3.txt +229 -267
- package/llms/agent-runtime.4.txt +39 -246
- package/llms/agent-runtime.5.txt +1 -1
- package/llms/agent-runtime.txt +551 -2
- package/llms/application-diagnostic-journal.txt +2 -0
- package/llms/application.2.txt +3 -0
- package/llms/application.3.txt +21 -4
- package/llms/application.txt +4 -1
- package/llms/cli.2.txt +259 -99
- package/llms/cli.3.txt +90 -0
- package/llms/cli.txt +96 -184
- package/llms/contract.txt +7 -6
- package/llms/declaration.txt +3 -3
- package/llms/files.txt +11 -0
- package/llms/handler.txt +25 -0
- package/llms/http.txt +18 -1
- package/llms/node.txt +5 -4
- package/llms/observability.2.txt +105 -0
- package/llms/observability.txt +14 -90
- package/llms/primitives.txt +27 -0
- package/llms/process.2.txt +2 -2
- package/llms/process.txt +10 -9
- package/llms/realtime.txt +11 -0
- package/llms/server.2.txt +355 -0
- package/llms/server.4.txt +45 -6
- package/llms/server.5.txt +8 -3
- package/llms/server.txt +143 -256
- package/llms/service-host-macos.txt +53 -0
- package/llms/service-host.txt +69 -0
- package/llms/spend-testing.txt +21 -0
- package/llms/spend.txt +173 -0
- package/llms/stitchkit.2.txt +368 -42
- package/llms/stitchkit.3.txt +164 -13
- package/llms/stitchkit.txt +99 -417
- package/llms/sync-postgres.txt +31 -0
- package/llms/sync.txt +396 -0
- package/llms/telegram-html.txt +4 -1
- package/llms/telegram.2.txt +4 -4
- package/llms/telegram.txt +105 -14
- package/llms/testing.txt +4 -3
- package/llms/tools-connections.txt +4 -4
- package/llms/tools.2.txt +78 -17
- package/llms/tools.3.txt +14 -9
- package/llms/tools.txt +85 -78
- package/llms/upgrading-0.127.0.txt +1059 -0
- package/llms/upgrading-0.128.0.txt +147 -0
- package/llms/upgrading.txt +2 -0
- package/llms-full.txt +3727 -542
- package/llms.txt +44 -27
- package/native/darwin-arm64.node +0 -0
- package/native/darwin-x64.node +0 -0
- package/native-assets.json +4 -4
- package/package.json +67 -9
- package/dist/agent-runtime/sandbox-coding.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-events.d.ts +0 -5
- package/dist/agent-runtime/sqlite-events.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-history.d.ts +0 -7
- package/dist/agent-runtime/sqlite-history.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-ledger.d.ts +0 -7
- package/dist/agent-runtime/sqlite-ledger.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-reads.d.ts +0 -14
- package/dist/agent-runtime/sqlite-reads.d.ts.map +0 -1
- package/dist/agent-runtime/sqlite-rows.d.ts.map +0 -1
- package/dist/agent-runtime/tool-progress.d.ts.map +0 -1
- package/dist/entrypoints/application/schemas.d.ts +0 -15
- package/dist/entrypoints/application/schemas.d.ts.map +0 -1
- package/dist/entrypoints/application/schemas.js +0 -27
- package/dist/index-0s4xebbg.js +0 -8
- package/dist/index-57ppvpw0.js +0 -1150
- package/dist/index-5dmk54h9.js +0 -256
- package/dist/index-8x0q6yfb.js +0 -247
- package/dist/index-a3z56mtn.js +0 -48
- package/dist/index-a5qr2rj6.js +0 -26
- package/dist/index-b0kddvzw.js +0 -35
- package/dist/index-drcjjhy1.js +0 -40
- package/dist/index-eemvahkc.js +0 -21
- package/dist/index-gfk7nrht.js +0 -0
- package/dist/index-jp2qd9jb.js +0 -108
- package/dist/index-nx6eazt0.js +0 -160
- package/dist/index-wxadzdb7.js +0 -55
- package/dist/internal/until-aborted.d.ts +0 -9
- package/dist/internal/until-aborted.d.ts.map +0 -1
- package/dist/server/unix-client-error.d.ts +0 -9
- package/dist/server/unix-client-error.d.ts.map +0 -1
- package/llms/application-schemas.txt +0 -42
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AgentSandboxRestrictionSchema2,
|
|
3
|
-
AgentSandboxGradeSchema2,
|
|
4
|
-
probeAgentProcessSandbox2,
|
|
5
|
-
missingSandboxRestrictions2,
|
|
6
|
-
recordAgentSandboxProbe2,
|
|
7
|
-
refuseUnknownSpillReference
|
|
8
|
-
} from "../index-4efxzrht.js";
|
|
9
1
|
import {
|
|
10
2
|
AgentRecordIdSchema2,
|
|
3
|
+
AgentStoreEventKindSchema2,
|
|
4
|
+
AgentStoreEventEnvelopeSchema2,
|
|
5
|
+
AppendAgentStoreEventSchema2,
|
|
6
|
+
ReadAgentStoreEventsSchema2,
|
|
7
|
+
AgentStoreEventPageSchema2,
|
|
11
8
|
AgentRecordVersionSchema2,
|
|
12
9
|
AgentTimestampSchema2,
|
|
13
10
|
AgentJsonObjectSchema2,
|
|
14
|
-
AgentProviderEnvelopeSchema2,
|
|
15
|
-
AgentProviderResponseSchema2,
|
|
16
|
-
AgentTextPartSchema2,
|
|
17
|
-
AgentReasoningPartSchema2,
|
|
18
|
-
AgentFilePartSchema2,
|
|
19
|
-
AgentSourcePartSchema2,
|
|
20
|
-
AgentToolCallPartSchema2,
|
|
21
|
-
AgentToolResultPartSchema2,
|
|
22
|
-
AgentToolApprovalRequestPartSchema2,
|
|
23
|
-
AgentToolApprovalResponsePartSchema2,
|
|
24
|
-
AgentOpaquePartSchema2,
|
|
25
|
-
AgentControlPartSchema2,
|
|
26
|
-
AgentMessagePartSchema2,
|
|
27
11
|
AgentMessageRoleSchema2,
|
|
28
12
|
AgentMessageStatusSchema2,
|
|
29
13
|
AgentMessageSchema2,
|
|
30
14
|
AgentAssistantPlaceholderSchema2,
|
|
15
|
+
AgentProvenanceSchema2,
|
|
16
|
+
AgentUsageValueSchema2,
|
|
17
|
+
AgentCostValueSchema2,
|
|
18
|
+
AgentUsageSchema2,
|
|
31
19
|
AgentRunStateSchema2,
|
|
32
20
|
AgentRunQueuePrioritySchema2,
|
|
33
21
|
AgentRunOperationKindSchema2,
|
|
@@ -35,30 +23,74 @@ import {
|
|
|
35
23
|
AgentRunOperationSchema2,
|
|
36
24
|
AgentTerminalReasonSchema2,
|
|
37
25
|
runStateForTerminalReason2,
|
|
38
|
-
AgentProvenanceSchema2,
|
|
39
|
-
AgentUsageValueSchema2,
|
|
40
|
-
AgentCostValueSchema2,
|
|
41
|
-
AgentUsageSchema2,
|
|
42
26
|
AgentRunSchema2,
|
|
43
27
|
AgentSnapshotSchema2,
|
|
44
28
|
AgentRunMetricsSchema2
|
|
45
|
-
} from "../index-
|
|
29
|
+
} from "../index-bn2baakz.js";
|
|
46
30
|
import {
|
|
31
|
+
AgentBranchRefusalCodeSchema2,
|
|
32
|
+
AgentBranchRefusalSchema2,
|
|
33
|
+
AgentConversationBranchRefusedError2,
|
|
47
34
|
BranchAgentConversationInputSchema2,
|
|
48
35
|
AgentConversationBranchReceiptSchema2,
|
|
49
36
|
AgentConversationBranchResultSchema2,
|
|
37
|
+
AgentConversationBranchPlanSchema2,
|
|
38
|
+
defineAgentToolDescriptor,
|
|
39
|
+
bindAgentTool,
|
|
40
|
+
SqlIntegerSchema,
|
|
41
|
+
AgentChildBudgetSchema2,
|
|
42
|
+
AgentChildStateSchema2,
|
|
43
|
+
AgentChildRecordSchema2,
|
|
44
|
+
AgentChildBlockingKindSchema2,
|
|
45
|
+
AgentChildBlockingSourceSchema2,
|
|
46
|
+
AgentChildBlockingEventSchema2,
|
|
47
|
+
ChildBlockingDecisionSchema,
|
|
48
|
+
ChildSpawnedEventPayloadSchema,
|
|
49
|
+
ChildStateEventPayloadSchema,
|
|
50
|
+
parseChild,
|
|
51
|
+
usageNumbers,
|
|
50
52
|
AgentConversationPurgeInputSchema2,
|
|
51
53
|
AgentConversationPurgeResultSchema2,
|
|
52
54
|
AgentConversationPurgedError2,
|
|
53
55
|
purgeAgentConversation2,
|
|
56
|
+
DeferredAgentToolSearchInputSchema2,
|
|
57
|
+
DeferredAgentToolMatchSchema2,
|
|
58
|
+
DeferredAgentToolReceiptSchema2,
|
|
59
|
+
AgentEventSearchResultSchema2,
|
|
60
|
+
createAgentEventSearch2,
|
|
61
|
+
AGENT_EVENT_SEARCH_TOOL_DESCRIPTORS2,
|
|
62
|
+
createAgentEventSearchTools2,
|
|
63
|
+
AgentStoreUnsupportedCapabilityError2,
|
|
54
64
|
createAgentRuntimeStore2
|
|
55
|
-
} from "../index-
|
|
65
|
+
} from "../index-g3e57qj6.js";
|
|
56
66
|
import {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
AgentCodingToolAuthorizationSchema2,
|
|
68
|
+
refuseUnknownSpillReference
|
|
69
|
+
} from "../index-wavv538x.js";
|
|
70
|
+
import {
|
|
71
|
+
AgentProviderEnvelopeSchema2,
|
|
72
|
+
AgentTextPartSchema2,
|
|
73
|
+
AgentReasoningPartSchema2,
|
|
74
|
+
AgentFilePartSchema2,
|
|
75
|
+
AgentSourcePartSchema2,
|
|
76
|
+
AgentToolCallPartSchema2,
|
|
77
|
+
AgentToolResultPartSchema2,
|
|
78
|
+
AgentToolApprovalRequestPartSchema2,
|
|
79
|
+
AgentToolApprovalResponsePartSchema2,
|
|
80
|
+
AgentOpaquePartSchema2,
|
|
81
|
+
AgentControlPartSchema2,
|
|
82
|
+
AgentMessagePartSchema2
|
|
83
|
+
} from "../index-2rf33y2h.js";
|
|
84
|
+
import {
|
|
85
|
+
AgentProviderResponseSchema2
|
|
86
|
+
} from "../index-97rp94ff.js";
|
|
87
|
+
import {
|
|
88
|
+
AgentRuntimeHeadSchema2,
|
|
89
|
+
AgentStoredRunSchema2,
|
|
90
|
+
AgentAdmissionReceiptSchema2,
|
|
91
|
+
AgentSeedReceiptSchema2,
|
|
92
|
+
AgentHistoryMutationSchema2,
|
|
93
|
+
ACTIVE_AGENT_RUN_STATES2,
|
|
62
94
|
AgentStoreConflictSchema2,
|
|
63
95
|
AgentStoreNotFoundSchema2,
|
|
64
96
|
AgentStoreAppliedSchema2,
|
|
@@ -83,67 +115,25 @@ import {
|
|
|
83
115
|
AgentConversationArchiveSchema2,
|
|
84
116
|
encodeAgentConversationArchive2,
|
|
85
117
|
decodeAgentConversationArchive2,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
AgentStoredRunSchema2,
|
|
90
|
-
AgentAdmissionReceiptSchema2,
|
|
91
|
-
AgentSeedReceiptSchema2,
|
|
92
|
-
AgentHistoryMutationSchema2,
|
|
93
|
-
ACTIVE_AGENT_RUN_STATES2
|
|
94
|
-
} from "../index-egg0yp2j.js";
|
|
95
|
-
import"../index-m8ddk770.js";
|
|
118
|
+
conversationOfRun
|
|
119
|
+
} from "../index-9xr44d2g.js";
|
|
120
|
+
import"../index-brhhaygm.js";
|
|
96
121
|
import {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
normalizeSdkUsage,
|
|
100
|
-
AgentContextOverflowError2,
|
|
101
|
-
createAgentSessionCoordinator2,
|
|
102
|
-
registerDeferredToolRepair,
|
|
103
|
-
registerDeferredToolCatalog,
|
|
104
|
-
deferredToolCatalog,
|
|
105
|
-
repairedSearchCall,
|
|
106
|
-
projectAgentHistoryDetailed2,
|
|
107
|
-
projectAgentHistory2,
|
|
122
|
+
PurgeInvocationPayloadsInputSchema2,
|
|
123
|
+
PurgeInvocationPayloadsResultSchema2,
|
|
108
124
|
ModelInvocationTraceSchema2,
|
|
109
125
|
CompletionInvocationInputSchema2,
|
|
126
|
+
InvocationPayloadOmissionReasonSchema2,
|
|
127
|
+
InvocationResponseSchema,
|
|
110
128
|
ModelInvocationRecordSchema2,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
composeAgentPrompt2,
|
|
117
|
-
AgentProviderStreamCutError2,
|
|
118
|
-
classifyProviderFailure2,
|
|
119
|
-
isToolResultFailure2,
|
|
120
|
-
recordAgentRetryDecision2,
|
|
121
|
-
defineStateSlot2,
|
|
122
|
-
createAgentStateSlotStore2,
|
|
123
|
-
renderAgentStateSlots2,
|
|
124
|
-
agentGoalStateSlot2,
|
|
125
|
-
agentTodoStateSlot2,
|
|
126
|
-
createAgentRuntime2
|
|
127
|
-
} from "../index-1v3k5zgx.js";
|
|
128
|
-
import {
|
|
129
|
-
AgentConversationSummarySchema2,
|
|
130
|
-
AgentConversationPageSchema2,
|
|
131
|
-
AgentConversationMessagePageSchema2
|
|
132
|
-
} from "../index-kqnd6a85.js";
|
|
133
|
-
import"../index-ndjzbt2v.js";
|
|
134
|
-
import"../index-dsa676h8.js";
|
|
135
|
-
import"../index-t8jz0e20.js";
|
|
136
|
-
import"../index-5dmk54h9.js";
|
|
137
|
-
import"../index-x2d51zay.js";
|
|
138
|
-
import"../index-x2rvpbtj.js";
|
|
139
|
-
import"../index-yt1gg11x.js";
|
|
140
|
-
import"../index-7cn66qdk.js";
|
|
141
|
-
import {
|
|
142
|
-
mountAgent2
|
|
143
|
-
} from "../index-n6hvd1r2.js";
|
|
129
|
+
ModelInvocationPayloadReadSchema2,
|
|
130
|
+
isModelInvocationRecord,
|
|
131
|
+
isAssistantHistoryEvidence2,
|
|
132
|
+
isCompleteAgentHistoryTurn
|
|
133
|
+
} from "../index-vgzhw2zk.js";
|
|
144
134
|
import {
|
|
145
135
|
createBoundedSinkManager
|
|
146
|
-
} from "../index-
|
|
136
|
+
} from "../index-prf6ayhf.js";
|
|
147
137
|
import {
|
|
148
138
|
AgentAdmissionEventSchema2,
|
|
149
139
|
AgentTransientDeltaEventSchema2,
|
|
@@ -161,8 +151,19 @@ import {
|
|
|
161
151
|
AgentRuntimeEventCursorSchema2,
|
|
162
152
|
advanceAgentRuntimeEventCursor2,
|
|
163
153
|
agentDurableEventId2
|
|
164
|
-
} from "../index-
|
|
154
|
+
} from "../index-paff5y0r.js";
|
|
165
155
|
import {
|
|
156
|
+
AgentRuntimeConflictError2,
|
|
157
|
+
AgentRunUnsettledError2,
|
|
158
|
+
addUsage,
|
|
159
|
+
statedUsage,
|
|
160
|
+
unknownUsage,
|
|
161
|
+
AgentStepSpendPhaseSchema2,
|
|
162
|
+
AgentStepSpendProviderSchema,
|
|
163
|
+
AgentStepSpendSchema2,
|
|
164
|
+
normalizeStepUsage,
|
|
165
|
+
InvocationPayloadTooLargeError2,
|
|
166
|
+
currentModelInvocationAttempt2,
|
|
166
167
|
AgentModelCapabilitySchema2,
|
|
167
168
|
AgentModelDescriptorSchema2,
|
|
168
169
|
AgentModelRegistrySnapshotSchema2,
|
|
@@ -178,7 +179,57 @@ import {
|
|
|
178
179
|
createMemoryAgentModelSelectionStore2,
|
|
179
180
|
defineModelRegistry2,
|
|
180
181
|
validateAgentModelSnapshot2
|
|
181
|
-
} from "../index-
|
|
182
|
+
} from "../index-emgrmavr.js";
|
|
183
|
+
import {
|
|
184
|
+
AgentConversationSummarySchema2,
|
|
185
|
+
AgentConversationPageSchema2,
|
|
186
|
+
AgentConversationMessagePageSchema2
|
|
187
|
+
} from "../index-7416mhyh.js";
|
|
188
|
+
import"../index-akf0xkrm.js";
|
|
189
|
+
import"../index-dsa676h8.js";
|
|
190
|
+
import"../index-27hck3z2.js";
|
|
191
|
+
import"../index-ngwf1s3c.js";
|
|
192
|
+
import"../index-360j58vb.js";
|
|
193
|
+
import"../index-j903yhp4.js";
|
|
194
|
+
import {
|
|
195
|
+
resolveToolAccess
|
|
196
|
+
} from "../index-rxnyygke.js";
|
|
197
|
+
import"../index-yt1gg11x.js";
|
|
198
|
+
import"../index-3ypvpkwr.js";
|
|
199
|
+
import"../index-gf92hc87.js";
|
|
200
|
+
import"../index-werjqesf.js";
|
|
201
|
+
import {
|
|
202
|
+
mountAgent2
|
|
203
|
+
} from "../index-hj1zq7mh.js";
|
|
204
|
+
import {
|
|
205
|
+
AgentContextOverflowError2,
|
|
206
|
+
createAgentSessionCoordinator2,
|
|
207
|
+
registerDeferredToolRepair,
|
|
208
|
+
registerDeferredToolCatalog,
|
|
209
|
+
deferredToolCatalog,
|
|
210
|
+
repairedSearchCall,
|
|
211
|
+
projectAgentHistoryDetailed2,
|
|
212
|
+
projectAgentHistory2,
|
|
213
|
+
createModelInvocationLedger2,
|
|
214
|
+
createAgentToolFenceLifecycle2,
|
|
215
|
+
AgentTokenCountSchema2,
|
|
216
|
+
selectAgentHistory2,
|
|
217
|
+
composeAgentPrompt2,
|
|
218
|
+
AgentProviderStreamCutError2,
|
|
219
|
+
classifyProviderFailure2,
|
|
220
|
+
isToolResultFailure2,
|
|
221
|
+
recordAgentRetryDecision2,
|
|
222
|
+
AgentStepBarrierError2,
|
|
223
|
+
createToolDependencyResolver2,
|
|
224
|
+
defineStateSlot2,
|
|
225
|
+
createAgentStateSlotStore2,
|
|
226
|
+
renderAgentStateSlots2,
|
|
227
|
+
agentGoalStateSlot2,
|
|
228
|
+
agentTodoStateSlot2,
|
|
229
|
+
createAgentRuntime2
|
|
230
|
+
} from "../index-n7f89hjw.js";
|
|
231
|
+
import"../index-m38ej7e5.js";
|
|
232
|
+
import"../index-d4svrknj.js";
|
|
182
233
|
import {
|
|
183
234
|
DURABILITY_STEP_EVENT_KIND2,
|
|
184
235
|
StepResultDecodeError2,
|
|
@@ -187,409 +238,458 @@ import {
|
|
|
187
238
|
ParkRecordDecodeError2,
|
|
188
239
|
ParkAbortedError2
|
|
189
240
|
} from "../index-snef22zr.js";
|
|
190
|
-
import"../index-
|
|
191
|
-
import"../index-
|
|
192
|
-
import"../index-
|
|
193
|
-
import"../index-
|
|
241
|
+
import"../index-kynwa08q.js";
|
|
242
|
+
import"../index-6kec3b14.js";
|
|
243
|
+
import"../index-v59pxmf1.js";
|
|
244
|
+
import"../index-7kfcb576.js";
|
|
194
245
|
import {
|
|
195
246
|
createMemoryAgentRuntimeStore2
|
|
196
|
-
} from "../index-
|
|
247
|
+
} from "../index-waa6t4zx.js";
|
|
197
248
|
import {
|
|
198
249
|
createAgentRuntimeEventSink2
|
|
199
|
-
} from "../index-
|
|
200
|
-
import"../index-
|
|
201
|
-
import"../index-
|
|
202
|
-
import"../index-
|
|
250
|
+
} from "../index-wv8dqy7q.js";
|
|
251
|
+
import"../index-rj32hkkp.js";
|
|
252
|
+
import"../index-bmaz3jzy.js";
|
|
253
|
+
import"../index-xrgn784x.js";
|
|
203
254
|
import {
|
|
204
255
|
buildToolManifest2
|
|
205
|
-
} from "../index-
|
|
206
|
-
import"../index-
|
|
256
|
+
} from "../index-c5gp2gh6.js";
|
|
257
|
+
import"../index-pn5b11ce.js";
|
|
258
|
+
import"../index-wa6h4tz6.js";
|
|
259
|
+
import"../index-jb4m241t.js";
|
|
260
|
+
import"../index-4j8efqr3.js";
|
|
207
261
|
import {
|
|
208
262
|
defineRuntimeTool2,
|
|
209
263
|
executableAgentRuntimeTools
|
|
210
|
-
} from "../index-
|
|
264
|
+
} from "../index-7csn6pva.js";
|
|
265
|
+
import"../index-hy4653g4.js";
|
|
211
266
|
import {
|
|
212
|
-
|
|
213
|
-
|
|
267
|
+
createTraceContext2,
|
|
268
|
+
childSpan2
|
|
269
|
+
} from "../index-y7sy1xdp.js";
|
|
214
270
|
import {
|
|
215
271
|
assertPositiveSafeInteger
|
|
216
|
-
} from "../index-
|
|
272
|
+
} from "../index-kzavdze2.js";
|
|
217
273
|
import {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
274
|
+
withDeadline
|
|
275
|
+
} from "../index-agy5fqgf.js";
|
|
276
|
+
import {
|
|
277
|
+
scheduleAt
|
|
278
|
+
} from "../index-mxt0wfjy.js";
|
|
279
|
+
import {
|
|
280
|
+
abortReason
|
|
281
|
+
} from "../index-rptj3qnc.js";
|
|
221
282
|
// src/agent-runtime/child-tools.ts
|
|
222
|
-
import { z as
|
|
283
|
+
import { z as z3 } from "zod";
|
|
223
284
|
|
|
224
|
-
// src/agent-runtime/
|
|
225
|
-
|
|
285
|
+
// src/agent-runtime/children-state.ts
|
|
286
|
+
import { z } from "zod";
|
|
287
|
+
function createChildManagerState(config) {
|
|
288
|
+
if (typeof config.remainingBudget !== "function")
|
|
289
|
+
throw new TypeError("createAgentChildManager requires remainingBudget");
|
|
290
|
+
if (config.maxActiveChildren === undefined)
|
|
291
|
+
throw new TypeError("createAgentChildManager requires maxActiveChildren");
|
|
292
|
+
assertPositiveSafeInteger("maxActiveChildren", config.maxActiveChildren);
|
|
226
293
|
return {
|
|
227
|
-
|
|
228
|
-
|
|
294
|
+
config,
|
|
295
|
+
host: config.host,
|
|
296
|
+
store: config.store,
|
|
297
|
+
now: config.now ?? (() => new Date),
|
|
298
|
+
handles: new Map,
|
|
299
|
+
settlements: new Map,
|
|
300
|
+
spawning: new Map
|
|
229
301
|
};
|
|
230
302
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
resultReference: z.string().optional(),
|
|
258
|
-
createdAt: z.string(),
|
|
259
|
-
updatedAt: z.string()
|
|
260
|
-
}).strict();
|
|
261
|
-
var AgentChildBlockingKindSchema = z.enum(["approval", "input"]);
|
|
262
|
-
var AgentChildBlockingSourceSchema = z.object({
|
|
263
|
-
approvalId: z.string().min(1),
|
|
264
|
-
callId: z.string().min(1),
|
|
265
|
-
toolName: z.string().min(1),
|
|
266
|
-
input: z.json(),
|
|
267
|
-
kind: AgentChildBlockingKindSchema.default("approval"),
|
|
268
|
-
batchId: z.string().min(1).optional()
|
|
269
|
-
}).strict();
|
|
270
|
-
var AgentChildBlockingEventSchema = z.object({
|
|
271
|
-
parentConversationId: z.string().min(1),
|
|
272
|
-
childConversationId: z.string().min(1),
|
|
273
|
-
kind: AgentChildBlockingKindSchema,
|
|
274
|
-
approvalId: z.string().min(1),
|
|
275
|
-
childApprovalId: z.string().min(1),
|
|
276
|
-
callId: z.string().min(1),
|
|
277
|
-
toolName: z.string().min(1),
|
|
278
|
-
input: z.json(),
|
|
279
|
-
batchId: z.string().min(1),
|
|
280
|
-
presentedAt: z.string()
|
|
281
|
-
}).strict();
|
|
282
|
-
var ChildBlockingDecisionSchema = z.union([
|
|
283
|
-
z.object({
|
|
284
|
-
approvalId: z.string().min(1),
|
|
285
|
-
approved: z.boolean(),
|
|
286
|
-
reason: z.string().optional()
|
|
287
|
-
}).strict(),
|
|
288
|
-
z.object({ approvalId: z.string().min(1), value: z.json() }).strict()
|
|
289
|
-
]);
|
|
290
|
-
var ChildRowSchema = z.object({
|
|
291
|
-
parent_conversation_id: z.string(),
|
|
292
|
-
child_conversation_id: z.string(),
|
|
293
|
-
seed_upto_seq: z.int().nonnegative(),
|
|
294
|
-
state: AgentChildStateSchema,
|
|
295
|
-
budget_payload: z.string(),
|
|
296
|
-
usage_payload: z.string(),
|
|
297
|
-
result_reference: z.string().nullable(),
|
|
298
|
-
created_at: z.string(),
|
|
299
|
-
updated_at: z.string()
|
|
300
|
-
});
|
|
301
|
-
function parseChild(raw) {
|
|
302
|
-
const row = ChildRowSchema.parse(raw);
|
|
303
|
-
return AgentChildRecordSchema.parse({
|
|
304
|
-
parentConversationId: row.parent_conversation_id,
|
|
305
|
-
childConversationId: row.child_conversation_id,
|
|
306
|
-
seedUptoSeq: row.seed_upto_seq,
|
|
307
|
-
state: row.state,
|
|
308
|
-
budget: JSON.parse(row.budget_payload),
|
|
309
|
-
usage: JSON.parse(row.usage_payload),
|
|
310
|
-
...row.result_reference && { resultReference: row.result_reference },
|
|
311
|
-
createdAt: row.created_at,
|
|
312
|
-
updatedAt: row.updated_at
|
|
303
|
+
var CHILD_HOST_BOUND_MS = 1e4;
|
|
304
|
+
async function bounded(work, fallback) {
|
|
305
|
+
const outcome = await withDeadline(Promise.resolve(work), CHILD_HOST_BOUND_MS);
|
|
306
|
+
return outcome.settled ? outcome.value : fallback;
|
|
307
|
+
}
|
|
308
|
+
async function askChildHost(what, work, onUnanswered) {
|
|
309
|
+
const answer = Promise.resolve().then(work);
|
|
310
|
+
const outcome = await withDeadline(answer.then((value) => ({ answered: true, value }), (cause) => ({ answered: false, cause })), CHILD_HOST_BOUND_MS);
|
|
311
|
+
if (!outcome.settled) {
|
|
312
|
+
onUnanswered?.(answer);
|
|
313
|
+
throw new Error(`The child host did not answer ${what} within ${CHILD_HOST_BOUND_MS} ms`);
|
|
314
|
+
}
|
|
315
|
+
if (!outcome.value.answered)
|
|
316
|
+
throw outcome.value.cause;
|
|
317
|
+
return outcome.value.value;
|
|
318
|
+
}
|
|
319
|
+
var stopsInFlight = new WeakMap;
|
|
320
|
+
function stopHandle(handle, policy) {
|
|
321
|
+
const inFlight = stopsInFlight.get(handle);
|
|
322
|
+
if (inFlight)
|
|
323
|
+
return inFlight;
|
|
324
|
+
const delivery = deliverStop(handle, policy);
|
|
325
|
+
stopsInFlight.set(handle, delivery);
|
|
326
|
+
delivery.finally(() => {
|
|
327
|
+
if (stopsInFlight.get(handle) === delivery)
|
|
328
|
+
stopsInFlight.delete(handle);
|
|
313
329
|
});
|
|
330
|
+
return delivery;
|
|
314
331
|
}
|
|
315
|
-
function
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
332
|
+
function deliverStop(handle, policy) {
|
|
333
|
+
return bounded(Promise.resolve().then(() => handle.stopPolicy(policy)).then(() => ({ stopped: true }), (cause) => ({ stopped: false, reason: "stop-failed", cause })), {
|
|
334
|
+
stopped: false,
|
|
335
|
+
reason: "stop-timeout",
|
|
336
|
+
cause: new Error(`The child host did not answer the stop within ${CHILD_HOST_BOUND_MS} ms`)
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async function writeWithPurgeFallback(write) {
|
|
340
|
+
try {
|
|
341
|
+
return await write("both");
|
|
342
|
+
} catch (error) {
|
|
343
|
+
if (!(error instanceof AgentConversationPurgedError2))
|
|
344
|
+
throw error;
|
|
345
|
+
let wrote = false;
|
|
346
|
+
for (const side of ["parent", "child"]) {
|
|
347
|
+
try {
|
|
348
|
+
wrote = await write(side) || wrote;
|
|
349
|
+
} catch (inner) {
|
|
350
|
+
if (!(inner instanceof AgentConversationPurgedError2))
|
|
351
|
+
throw inner;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return wrote;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
var CHILD_COLUMNS = `parent_conversation_id, child_conversation_id, seed_upto_seq, state,
|
|
358
|
+
budget_payload, usage_payload, result_reference, created_at, updated_at`;
|
|
359
|
+
function listChildren(state, parentConversationId) {
|
|
360
|
+
return state.host.read(async (session) => (await session.all(`SELECT ${CHILD_COLUMNS} FROM ${state.host.tables.children}
|
|
361
|
+
WHERE parent_conversation_id = ? ORDER BY created_at, child_conversation_id`, [parentConversationId])).map(parseChild));
|
|
362
|
+
}
|
|
363
|
+
var LIVE_CHILD_STATES = ["spawned", "running"];
|
|
364
|
+
var StateRowSchema = z.object({ state: AgentChildStateSchema2 });
|
|
365
|
+
function transitionChild(state, record, next, options) {
|
|
366
|
+
const { from, absent, resultReference, details = {} } = options;
|
|
367
|
+
const updatedAt = state.now().toISOString();
|
|
368
|
+
const payload = ChildStateEventPayloadSchema.parse({
|
|
369
|
+
childConversationId: record.childConversationId,
|
|
370
|
+
state: next,
|
|
371
|
+
...resultReference && { resultReference },
|
|
372
|
+
...details
|
|
373
|
+
});
|
|
374
|
+
const childPayload = ChildStateEventPayloadSchema.parse({
|
|
375
|
+
parentConversationId: record.parentConversationId,
|
|
376
|
+
state: next,
|
|
377
|
+
...resultReference && { resultReference },
|
|
378
|
+
...details
|
|
379
|
+
});
|
|
380
|
+
const table = state.host.tables.children;
|
|
381
|
+
const write = (audience) => state.host.transaction(audience === "child" ? record.childConversationId : record.parentConversationId, async (scope) => {
|
|
382
|
+
const row = await scope.get(`SELECT state FROM ${table} WHERE child_conversation_id = ?`, [record.childConversationId]);
|
|
383
|
+
if (row === undefined) {
|
|
384
|
+
if (absent === "skip")
|
|
385
|
+
return false;
|
|
386
|
+
} else {
|
|
387
|
+
if (!from.includes(StateRowSchema.parse(row).state))
|
|
388
|
+
return false;
|
|
389
|
+
await scope.run(`UPDATE ${table} SET state = ?, result_reference = ?, updated_at = ?
|
|
390
|
+
WHERE child_conversation_id = ? AND state IN (${from.map(() => "?").join(", ")})`, [next, resultReference ?? null, updatedAt, record.childConversationId, ...from]);
|
|
391
|
+
}
|
|
392
|
+
if (audience === "both" || audience === "parent") {
|
|
393
|
+
await scope.appendEvent({
|
|
394
|
+
conversationId: record.parentConversationId,
|
|
395
|
+
kind: "child/state",
|
|
396
|
+
occurredAt: updatedAt,
|
|
397
|
+
payload
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
if (audience === "both" || audience === "child") {
|
|
401
|
+
await scope.appendEvent({
|
|
402
|
+
conversationId: record.childConversationId,
|
|
403
|
+
kind: "child/state",
|
|
404
|
+
occurredAt: updatedAt,
|
|
405
|
+
payload: childPayload
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
return true;
|
|
409
|
+
});
|
|
410
|
+
return writeWithPurgeFallback(write);
|
|
411
|
+
}
|
|
412
|
+
async function activeChild(state, parentConversationId, childConversationId) {
|
|
413
|
+
const child = (await listChildren(state, parentConversationId)).find((record) => record.childConversationId === childConversationId);
|
|
414
|
+
if (!child)
|
|
415
|
+
throw new TypeError("Unknown child conversation for this parent");
|
|
416
|
+
if (child.state !== "running" && child.state !== "spawned") {
|
|
417
|
+
throw new TypeError("Child conversation is not active");
|
|
418
|
+
}
|
|
419
|
+
const handle = state.handles.get(childConversationId);
|
|
420
|
+
if (!handle)
|
|
421
|
+
throw new TypeError("Child host handle is unavailable");
|
|
422
|
+
return { child, handle };
|
|
322
423
|
}
|
|
323
424
|
|
|
324
425
|
// src/agent-runtime/child-blocking.ts
|
|
325
|
-
function
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
426
|
+
function askChild(bounded, handle, blockingEvents) {
|
|
427
|
+
return bounded(Promise.resolve().then(() => blockingEvents.call(handle)).then((reported) => ({
|
|
428
|
+
answered: true,
|
|
429
|
+
sources: reported.map((source) => AgentChildBlockingSourceSchema2.parse(source))
|
|
430
|
+
})).catch((cause) => ({
|
|
431
|
+
answered: false,
|
|
432
|
+
reason: "failed",
|
|
433
|
+
cause
|
|
434
|
+
})), { answered: false, reason: "timeout" });
|
|
435
|
+
}
|
|
436
|
+
function childScopedBlockingId(childConversationId, childApprovalId) {
|
|
437
|
+
return `${encodeURIComponent(childConversationId)}:${encodeURIComponent(childApprovalId)}`;
|
|
438
|
+
}
|
|
439
|
+
function createParentQueues() {
|
|
440
|
+
const queues = new Map;
|
|
441
|
+
return (parentConversationId, work) => {
|
|
442
|
+
const run = (queues.get(parentConversationId) ?? Promise.resolve()).then(work);
|
|
443
|
+
const tail = run.then(() => {
|
|
333
444
|
return;
|
|
334
445
|
}, () => {
|
|
335
446
|
return;
|
|
336
447
|
});
|
|
448
|
+
queues.set(parentConversationId, tail);
|
|
449
|
+
tail.then(() => {
|
|
450
|
+
if (queues.get(parentConversationId) === tail)
|
|
451
|
+
queues.delete(parentConversationId);
|
|
452
|
+
});
|
|
337
453
|
return run;
|
|
338
454
|
};
|
|
339
|
-
|
|
455
|
+
}
|
|
456
|
+
async function presentBlocking(store, parentConversationId, record, source, presentedAt) {
|
|
457
|
+
const approvalId = childScopedBlockingId(record.childConversationId, source.approvalId);
|
|
458
|
+
const batchId = source.batchId ? `${record.childConversationId}:${source.batchId}` : approvalId;
|
|
459
|
+
const event = AgentChildBlockingEventSchema2.parse({
|
|
460
|
+
parentConversationId,
|
|
461
|
+
childConversationId: record.childConversationId,
|
|
462
|
+
kind: source.kind,
|
|
463
|
+
approvalId,
|
|
464
|
+
childApprovalId: source.approvalId,
|
|
465
|
+
callId: source.callId,
|
|
466
|
+
toolName: source.toolName,
|
|
467
|
+
input: source.input,
|
|
468
|
+
batchId,
|
|
469
|
+
presentedAt
|
|
470
|
+
});
|
|
471
|
+
await store.appendEvent({
|
|
472
|
+
conversationId: parentConversationId,
|
|
473
|
+
kind: "child/state",
|
|
474
|
+
occurredAt: presentedAt,
|
|
475
|
+
payload: ChildStateEventPayloadSchema.parse({
|
|
476
|
+
action: "blocking-presented",
|
|
477
|
+
childConversationId: event.childConversationId,
|
|
478
|
+
approvalId: event.approvalId,
|
|
479
|
+
childApprovalId: event.childApprovalId,
|
|
480
|
+
kind: event.kind,
|
|
481
|
+
callId: event.callId,
|
|
482
|
+
toolName: event.toolName,
|
|
483
|
+
input: event.input,
|
|
484
|
+
batchId: event.batchId,
|
|
485
|
+
presentedAt
|
|
486
|
+
})
|
|
487
|
+
});
|
|
488
|
+
return { event, batchId };
|
|
489
|
+
}
|
|
490
|
+
function createChildBlockingRelay(input) {
|
|
491
|
+
const { store, now, handles, listChildren, activeChild, bounded } = input;
|
|
492
|
+
const presentedBlocking = new Map;
|
|
493
|
+
const retiredBlocking = new Map;
|
|
494
|
+
const answersWithHost = new Map;
|
|
495
|
+
const serializeBlocking = createParentQueues();
|
|
340
496
|
const retireChildBlocking = (childConversationId) => {
|
|
341
497
|
for (const [id, entry] of presentedBlocking) {
|
|
342
|
-
if (entry.event.childConversationId === childConversationId)
|
|
498
|
+
if (entry.event.childConversationId === childConversationId)
|
|
343
499
|
presentedBlocking.delete(id);
|
|
344
|
-
|
|
345
|
-
|
|
500
|
+
}
|
|
501
|
+
retiredBlocking.delete(childConversationId);
|
|
502
|
+
for (const [id, child] of answersWithHost) {
|
|
503
|
+
if (child === childConversationId)
|
|
504
|
+
answersWithHost.delete(id);
|
|
346
505
|
}
|
|
347
506
|
};
|
|
507
|
+
const isRetired = (childConversationId, id) => retiredBlocking.get(childConversationId)?.has(id) ?? false;
|
|
348
508
|
const listChildBlockingInner = async (parentConversationId) => {
|
|
349
|
-
const live = listChildren(parentConversationId).filter((record) => record.state === "spawned" || record.state === "running");
|
|
509
|
+
const live = (await listChildren(parentConversationId)).filter((record) => record.state === "spawned" || record.state === "running");
|
|
510
|
+
const unavailable = [];
|
|
350
511
|
for (const record of live) {
|
|
351
512
|
const handle = handles.get(record.childConversationId);
|
|
352
513
|
if (!handle?.blockingEvents)
|
|
353
514
|
continue;
|
|
354
|
-
const
|
|
355
|
-
|
|
515
|
+
const report = await askChild(bounded, handle, handle.blockingEvents);
|
|
516
|
+
if (!report.answered) {
|
|
517
|
+
const { childConversationId } = record;
|
|
518
|
+
unavailable.push(report.reason === "timeout" ? { childConversationId, reason: "timeout" } : { childConversationId, reason: "failed", cause: report.cause });
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
const fresh = report.sources.filter((source) => {
|
|
356
522
|
const id = childScopedBlockingId(record.childConversationId, source.approvalId);
|
|
357
|
-
return !presentedBlocking.has(id) && !
|
|
523
|
+
return !presentedBlocking.has(id) && !isRetired(record.childConversationId, id);
|
|
358
524
|
});
|
|
359
525
|
if (fresh.length === 0)
|
|
360
526
|
continue;
|
|
361
527
|
const presentedAt = now().toISOString();
|
|
362
528
|
for (const source of fresh) {
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
const event = AgentChildBlockingEventSchema.parse({
|
|
366
|
-
parentConversationId,
|
|
367
|
-
childConversationId: record.childConversationId,
|
|
368
|
-
kind: source.kind,
|
|
369
|
-
approvalId,
|
|
370
|
-
childApprovalId: source.approvalId,
|
|
371
|
-
callId: source.callId,
|
|
372
|
-
toolName: source.toolName,
|
|
373
|
-
input: source.input,
|
|
374
|
-
batchId,
|
|
375
|
-
presentedAt
|
|
376
|
-
});
|
|
377
|
-
await store.appendEvent({
|
|
378
|
-
conversationId: parentConversationId,
|
|
379
|
-
kind: "child/state",
|
|
380
|
-
occurredAt: presentedAt,
|
|
381
|
-
payload: {
|
|
382
|
-
action: "blocking-presented",
|
|
383
|
-
childConversationId: event.childConversationId,
|
|
384
|
-
approvalId: event.approvalId,
|
|
385
|
-
childApprovalId: event.childApprovalId,
|
|
386
|
-
kind: event.kind,
|
|
387
|
-
callId: event.callId,
|
|
388
|
-
toolName: event.toolName,
|
|
389
|
-
input: event.input,
|
|
390
|
-
batchId: event.batchId,
|
|
391
|
-
presentedAt
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
presentedBlocking.set(approvalId, { event, batchId });
|
|
529
|
+
const entry = await presentBlocking(store, parentConversationId, record, source, presentedAt);
|
|
530
|
+
presentedBlocking.set(entry.event.approvalId, entry);
|
|
395
531
|
}
|
|
396
532
|
}
|
|
397
|
-
|
|
533
|
+
const pending = [...presentedBlocking.values()].map((entry) => entry.event).filter((event) => event.parentConversationId === parentConversationId);
|
|
534
|
+
return { pending, unavailable };
|
|
398
535
|
};
|
|
399
|
-
const listChildBlocking = (parentConversationId) => serializeBlocking(() => listChildBlockingInner(parentConversationId));
|
|
536
|
+
const listChildBlocking = (parentConversationId) => serializeBlocking(parentConversationId, () => listChildBlockingInner(parentConversationId));
|
|
400
537
|
const respondToChildBlockingInner = async (parentConversationId, decision) => {
|
|
401
538
|
const entry = presentedBlocking.get(decision.approvalId);
|
|
402
539
|
if (!entry || entry.event.parentConversationId !== parentConversationId) {
|
|
403
540
|
throw new TypeError("Child blocking request is missing, stale or already answered");
|
|
404
541
|
}
|
|
405
|
-
const { handle } = activeChild(parentConversationId, entry.event.childConversationId);
|
|
406
|
-
|
|
542
|
+
const { handle } = await activeChild(parentConversationId, entry.event.childConversationId);
|
|
543
|
+
const respond = handle.respondToBlocking;
|
|
544
|
+
if (!respond) {
|
|
407
545
|
throw new TypeError("Child host cannot answer blocking requests");
|
|
408
546
|
}
|
|
409
547
|
const parsed = ChildBlockingDecisionSchema.parse(decision);
|
|
410
548
|
if (entry.event.kind === "input" !== "value" in parsed)
|
|
411
549
|
throw new TypeError("Child response kind does not match the pending request");
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
550
|
+
if (answersWithHost.has(decision.approvalId))
|
|
551
|
+
throw new TypeError("The child host has not answered the first response to this request: an earlier answer is still with the child host");
|
|
552
|
+
await askChildHost("the blocking response", () => respond.call(handle, { ...parsed, approvalId: entry.event.childApprovalId }), (answer) => {
|
|
553
|
+
answersWithHost.set(decision.approvalId, entry.event.childConversationId);
|
|
554
|
+
answer.then(() => serializeBlocking(parentConversationId, async () => {
|
|
555
|
+
if (presentedBlocking.get(decision.approvalId) === entry)
|
|
556
|
+
await recordAnswered(parentConversationId, decision.approvalId, entry, parsed);
|
|
557
|
+
}), () => {
|
|
558
|
+
return;
|
|
559
|
+
}).catch(() => {
|
|
560
|
+
return;
|
|
561
|
+
}).finally(() => answersWithHost.delete(decision.approvalId));
|
|
562
|
+
});
|
|
563
|
+
await recordAnswered(parentConversationId, decision.approvalId, entry, parsed);
|
|
564
|
+
};
|
|
565
|
+
const recordAnswered = async (parentConversationId, approvalId, entry, parsed) => {
|
|
566
|
+
presentedBlocking.delete(approvalId);
|
|
567
|
+
const childConversationId = entry.event.childConversationId;
|
|
568
|
+
const retired = retiredBlocking.get(childConversationId) ?? new Set;
|
|
569
|
+
retired.add(approvalId);
|
|
570
|
+
retiredBlocking.set(childConversationId, retired);
|
|
415
571
|
await store.appendEvent({
|
|
416
572
|
conversationId: parentConversationId,
|
|
417
573
|
kind: "child/state",
|
|
418
|
-
payload: {
|
|
574
|
+
payload: ChildStateEventPayloadSchema.parse({
|
|
419
575
|
action: "blocking-resolved",
|
|
420
576
|
childConversationId: entry.event.childConversationId,
|
|
421
577
|
approvalId: entry.event.approvalId,
|
|
422
578
|
batchId: entry.batchId,
|
|
423
579
|
..."approved" in parsed ? { approved: parsed.approved } : { kind: "input" }
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
};
|
|
427
|
-
const respondToChildBlocking = (parentConversationId, decision) => serializeBlocking(() => respondToChildBlockingInner(parentConversationId, decision));
|
|
428
|
-
return {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
config,
|
|
435
|
-
database: config.sqlite.database,
|
|
436
|
-
store: config.sqlite.store,
|
|
437
|
-
now: config.now ?? (() => new Date),
|
|
438
|
-
handles: new Map,
|
|
439
|
-
settlements: new Map
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
function currentState(state, childConversationId) {
|
|
443
|
-
const raw = state.database.prepare("SELECT state FROM stitchkit_agent_runtime_children WHERE child_conversation_id = ?").get(childConversationId);
|
|
444
|
-
return raw === null || raw === undefined ? undefined : AgentChildStateSchema.parse(raw.state);
|
|
445
|
-
}
|
|
446
|
-
function isLive(state, childConversationId) {
|
|
447
|
-
const current = currentState(state, childConversationId);
|
|
448
|
-
return current === "spawned" || current === "running";
|
|
449
|
-
}
|
|
450
|
-
function settleable(state, childConversationId) {
|
|
451
|
-
const current = currentState(state, childConversationId);
|
|
452
|
-
return current === undefined || current === "spawned" || current === "running";
|
|
453
|
-
}
|
|
454
|
-
var STOP_BOUND_MS = 1e4;
|
|
455
|
-
async function bounded(work, fallback) {
|
|
456
|
-
let timer;
|
|
457
|
-
try {
|
|
458
|
-
return await Promise.race([
|
|
459
|
-
Promise.resolve(work),
|
|
460
|
-
new Promise((resolve) => {
|
|
461
|
-
timer = setTimeout(() => resolve(fallback), STOP_BOUND_MS);
|
|
462
|
-
})
|
|
463
|
-
]);
|
|
464
|
-
} finally {
|
|
465
|
-
if (timer)
|
|
466
|
-
clearTimeout(timer);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
function listChildren(state, parentConversationId) {
|
|
470
|
-
return state.database.prepare(`
|
|
471
|
-
SELECT parent_conversation_id, child_conversation_id, seed_upto_seq, state,
|
|
472
|
-
budget_payload, usage_payload, result_reference, created_at, updated_at
|
|
473
|
-
FROM stitchkit_agent_runtime_children
|
|
474
|
-
WHERE parent_conversation_id = ? ORDER BY created_at, child_conversation_id
|
|
475
|
-
`).all(parentConversationId).map(parseChild);
|
|
476
|
-
}
|
|
477
|
-
async function updateState(state, record, next, resultReference, details = {}) {
|
|
478
|
-
const updatedAt = state.now().toISOString();
|
|
479
|
-
const payload = {
|
|
480
|
-
childConversationId: record.childConversationId,
|
|
481
|
-
state: next,
|
|
482
|
-
...resultReference && { resultReference },
|
|
483
|
-
...details
|
|
484
|
-
};
|
|
485
|
-
const childPayload = {
|
|
486
|
-
parentConversationId: record.parentConversationId,
|
|
487
|
-
state: next,
|
|
488
|
-
...resultReference && { resultReference },
|
|
489
|
-
...details
|
|
490
|
-
};
|
|
491
|
-
const write = (audience) => state.config.sqlite.transaction(async (scope) => {
|
|
492
|
-
scope.database.prepare(`
|
|
493
|
-
UPDATE stitchkit_agent_runtime_children
|
|
494
|
-
SET state = ?, result_reference = ?, updated_at = ? WHERE child_conversation_id = ?
|
|
495
|
-
`).run(next, resultReference ?? null, updatedAt, record.childConversationId);
|
|
496
|
-
if (audience === "both") {
|
|
497
|
-
await scope.appendEvent({
|
|
498
|
-
conversationId: record.parentConversationId,
|
|
499
|
-
kind: "child/state",
|
|
500
|
-
occurredAt: updatedAt,
|
|
501
|
-
payload
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
if (audience !== "row") {
|
|
505
|
-
await scope.appendEvent({
|
|
506
|
-
conversationId: record.childConversationId,
|
|
507
|
-
kind: "child/state",
|
|
508
|
-
occurredAt: updatedAt,
|
|
509
|
-
payload: childPayload
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
try {
|
|
514
|
-
await write("both");
|
|
515
|
-
} catch (error) {
|
|
516
|
-
if (!(error instanceof AgentConversationPurgedError2))
|
|
517
|
-
throw error;
|
|
518
|
-
try {
|
|
519
|
-
await write("child");
|
|
520
|
-
} catch (inner) {
|
|
521
|
-
if (!(inner instanceof AgentConversationPurgedError2))
|
|
522
|
-
throw inner;
|
|
523
|
-
await write("row");
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
function activeChild(state, parentConversationId, childConversationId) {
|
|
528
|
-
const child = listChildren(state, parentConversationId).find((record) => record.childConversationId === childConversationId);
|
|
529
|
-
if (!child)
|
|
530
|
-
throw new TypeError("Unknown child conversation for this parent");
|
|
531
|
-
if (child.state !== "running" && child.state !== "spawned") {
|
|
532
|
-
throw new TypeError("Child conversation is not active");
|
|
533
|
-
}
|
|
534
|
-
const handle = state.handles.get(childConversationId);
|
|
535
|
-
if (!handle)
|
|
536
|
-
throw new TypeError("Child host handle is unavailable");
|
|
537
|
-
return { child, handle };
|
|
580
|
+
})
|
|
581
|
+
});
|
|
582
|
+
};
|
|
583
|
+
const respondToChildBlocking = (parentConversationId, decision) => serializeBlocking(parentConversationId, () => respondToChildBlockingInner(parentConversationId, decision));
|
|
584
|
+
return {
|
|
585
|
+
retireChildBlocking,
|
|
586
|
+
listChildBlocking,
|
|
587
|
+
respondToChildBlocking,
|
|
588
|
+
retained: { presented: presentedBlocking, retired: retiredBlocking }
|
|
589
|
+
};
|
|
538
590
|
}
|
|
539
591
|
|
|
540
592
|
// src/agent-runtime/children-control.ts
|
|
593
|
+
function isReachable(handle) {
|
|
594
|
+
const probe = handle.reachable;
|
|
595
|
+
if (!probe)
|
|
596
|
+
return Promise.resolve(true);
|
|
597
|
+
return bounded(Promise.resolve().then(() => probe.call(handle)).then((value) => Boolean(value), () => false), false);
|
|
598
|
+
}
|
|
599
|
+
function requestPendingStops(state, parentConversationId) {
|
|
600
|
+
const pending = [...state.spawning.values()].filter((spawn) => spawn.parentConversationId === parentConversationId);
|
|
601
|
+
for (const spawn of pending)
|
|
602
|
+
spawn.stopRequested = true;
|
|
603
|
+
return pending;
|
|
604
|
+
}
|
|
541
605
|
async function stopChildren(state, retireChildBlocking, parentConversationId) {
|
|
542
|
-
|
|
543
|
-
await
|
|
606
|
+
requestPendingStops(state, parentConversationId);
|
|
607
|
+
const records = (await listChildren(state, parentConversationId)).filter((record) => record.state === "spawned" || record.state === "running");
|
|
608
|
+
const pending = requestPendingStops(state, parentConversationId);
|
|
609
|
+
const registered = records.filter((record) => !state.spawning.has(record.childConversationId));
|
|
610
|
+
await Promise.all([
|
|
611
|
+
...registered.map((record) => stopChild(state, retireChildBlocking, record)),
|
|
612
|
+
...pending.map((spawn) => bounded(spawn.done, undefined))
|
|
613
|
+
]);
|
|
544
614
|
}
|
|
545
615
|
async function stopChild(state, retireChildBlocking, record) {
|
|
546
616
|
const startedAt = performance.now();
|
|
547
617
|
const handle = state.handles.get(record.childConversationId);
|
|
548
|
-
const reachable = handle ?
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
await updateState(state, record, "lost", undefined, {
|
|
552
|
-
stopDurationMs: Math.max(0, performance.now() - startedAt)
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
retireChildBlocking(record.childConversationId);
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
await bounded(Promise.resolve(handle?.stopPolicy("parent-stopped")).then(() => true), false);
|
|
559
|
-
if (!isLive(state, record.childConversationId))
|
|
560
|
-
return;
|
|
561
|
-
await updateState(state, record, "stopped", undefined, {
|
|
618
|
+
const reachable = handle ? await isReachable(handle) : false;
|
|
619
|
+
const outcome = handle && reachable ? await stopHandle(handle, "parent-stopped") : { stopped: false, reason: "unreachable" };
|
|
620
|
+
await recordStop(state, retireChildBlocking, record, outcome, {
|
|
562
621
|
stopDurationMs: Math.max(0, performance.now() - startedAt)
|
|
563
622
|
});
|
|
564
|
-
retireChildBlocking(record.childConversationId);
|
|
565
623
|
}
|
|
624
|
+
async function recordStop(state, retireChildBlocking, record, outcome, details) {
|
|
625
|
+
const { childConversationId } = record;
|
|
626
|
+
const settlement = state.settlements.get(childConversationId);
|
|
627
|
+
if (settlement?.arrived)
|
|
628
|
+
await Promise.allSettled([settlement.settled]);
|
|
629
|
+
await transitionChild(state, record, outcome.stopped ? "stopped" : "lost", {
|
|
630
|
+
from: LIVE_CHILD_STATES,
|
|
631
|
+
absent: "skip",
|
|
632
|
+
details: { ...details, ...!outcome.stopped && { reason: outcome.reason } }
|
|
633
|
+
});
|
|
634
|
+
settlement?.endedByStop();
|
|
635
|
+
if (state.settlements.get(childConversationId) === settlement)
|
|
636
|
+
state.settlements.delete(childConversationId);
|
|
637
|
+
state.handles.delete(childConversationId);
|
|
638
|
+
retireChildBlocking(childConversationId);
|
|
639
|
+
}
|
|
640
|
+
var messagesWithHost = new WeakMap;
|
|
566
641
|
async function sendMessage(state, parentConversationId, childConversationId, message) {
|
|
567
|
-
const { handle } = activeChild(state, parentConversationId, childConversationId);
|
|
568
|
-
|
|
642
|
+
const { handle } = await activeChild(state, parentConversationId, childConversationId);
|
|
643
|
+
const send = handle.sendMessage;
|
|
644
|
+
if (!send)
|
|
569
645
|
throw new TypeError("Child host does not support messages");
|
|
570
|
-
|
|
571
|
-
|
|
646
|
+
if ((messagesWithHost.get(handle) ?? 0) > 0)
|
|
647
|
+
throw new TypeError("The child host has not answered an earlier message to this child: an earlier message is still with the child host");
|
|
648
|
+
const journal = () => state.store.appendEvent({
|
|
572
649
|
conversationId: parentConversationId,
|
|
573
650
|
kind: "child/state",
|
|
574
|
-
payload: {
|
|
651
|
+
payload: ChildStateEventPayloadSchema.parse({
|
|
652
|
+
childConversationId,
|
|
653
|
+
action: "message-sent"
|
|
654
|
+
})
|
|
655
|
+
});
|
|
656
|
+
await askChildHost("the message", () => send.call(handle, message), (answer) => {
|
|
657
|
+
messagesWithHost.set(handle, (messagesWithHost.get(handle) ?? 0) + 1);
|
|
658
|
+
answer.then(journal, () => {
|
|
659
|
+
return;
|
|
660
|
+
}).catch(() => {
|
|
661
|
+
return;
|
|
662
|
+
}).finally(() => {
|
|
663
|
+
const left = (messagesWithHost.get(handle) ?? 1) - 1;
|
|
664
|
+
if (left > 0)
|
|
665
|
+
messagesWithHost.set(handle, left);
|
|
666
|
+
else
|
|
667
|
+
messagesWithHost.delete(handle);
|
|
668
|
+
});
|
|
575
669
|
});
|
|
670
|
+
await journal();
|
|
576
671
|
}
|
|
577
672
|
async function interruptChild(state, retireChildBlocking, parentConversationId, childConversationId) {
|
|
578
|
-
const { child, handle } = activeChild(state, parentConversationId, childConversationId);
|
|
673
|
+
const { child, handle } = await activeChild(state, parentConversationId, childConversationId);
|
|
579
674
|
const startedAt = performance.now();
|
|
580
|
-
await handle
|
|
581
|
-
await
|
|
675
|
+
const outcome = await stopHandle(handle, "parent-interrupt");
|
|
676
|
+
await recordStop(state, retireChildBlocking, child, outcome, {
|
|
582
677
|
policyName: "parent-interrupt",
|
|
583
678
|
stopDurationMs: Math.max(0, performance.now() - startedAt)
|
|
584
679
|
});
|
|
585
|
-
retireChildBlocking(childConversationId);
|
|
586
680
|
}
|
|
587
681
|
|
|
588
682
|
// src/agent-runtime/children-spawn.ts
|
|
589
683
|
import { randomUUID } from "node:crypto";
|
|
684
|
+
import { z as z2 } from "zod";
|
|
685
|
+
var RemainingBudgetSchema = z2.object({
|
|
686
|
+
usd: z2.number().nonnegative().optional(),
|
|
687
|
+
tokens: z2.int().nonnegative().optional(),
|
|
688
|
+
milliseconds: z2.int().nonnegative().optional()
|
|
689
|
+
}).strict();
|
|
590
690
|
async function grantedBudget(state, request) {
|
|
591
|
-
const requestedBudget =
|
|
592
|
-
const remaining =
|
|
691
|
+
const requestedBudget = AgentChildBudgetSchema2.parse(request.budget);
|
|
692
|
+
const remaining = RemainingBudgetSchema.parse(await state.config.remainingBudget(request.parentConversationId));
|
|
593
693
|
const bounded = (requested, available) => {
|
|
594
694
|
if (requested === undefined)
|
|
595
695
|
return available;
|
|
@@ -597,15 +697,28 @@ async function grantedBudget(state, request) {
|
|
|
597
697
|
return requested;
|
|
598
698
|
return Math.min(requested, available);
|
|
599
699
|
};
|
|
600
|
-
const usd = bounded(requestedBudget.usd, remaining
|
|
601
|
-
const tokens = bounded(requestedBudget.tokens, remaining
|
|
602
|
-
const milliseconds = bounded(requestedBudget.milliseconds, remaining
|
|
603
|
-
|
|
700
|
+
const usd = bounded(requestedBudget.usd, remaining.usd);
|
|
701
|
+
const tokens = bounded(requestedBudget.tokens, remaining.tokens);
|
|
702
|
+
const milliseconds = bounded(requestedBudget.milliseconds, remaining.milliseconds);
|
|
703
|
+
const granted = { usd, tokens, milliseconds };
|
|
704
|
+
const spent = Object.entries(granted).filter(([, value]) => value === 0);
|
|
705
|
+
if (spent.length > 0)
|
|
706
|
+
throw new TypeError(`The parent has no child budget left in ${spent.map(([name]) => name).join(", ")}`);
|
|
707
|
+
if (usd === undefined && tokens === undefined && milliseconds === undefined)
|
|
708
|
+
throw new TypeError("A child budget names at least one limit; the parent remainder and the request name none");
|
|
709
|
+
return AgentChildBudgetSchema2.parse({
|
|
604
710
|
...usd !== undefined && { usd },
|
|
605
711
|
...tokens !== undefined && { tokens },
|
|
606
712
|
...milliseconds !== undefined && { milliseconds }
|
|
607
713
|
});
|
|
608
714
|
}
|
|
715
|
+
var ActiveRowSchema = z2.object({ active: SqlIntegerSchema });
|
|
716
|
+
async function refuseOverLimit(state, session, parentConversationId) {
|
|
717
|
+
const { active } = ActiveRowSchema.parse(await session.get(`SELECT COUNT(*) AS active FROM ${state.host.tables.children}
|
|
718
|
+
WHERE parent_conversation_id = ? AND state IN ('spawned', 'running')`, [parentConversationId]));
|
|
719
|
+
if (active >= state.config.maxActiveChildren)
|
|
720
|
+
throw new TypeError(`The parent already has ${active} active children, the limit is ${state.config.maxActiveChildren}`);
|
|
721
|
+
}
|
|
609
722
|
async function readSeedEvents(state, request) {
|
|
610
723
|
const events = [];
|
|
611
724
|
let cursor = 1;
|
|
@@ -625,70 +738,112 @@ async function readSeedEvents(state, request) {
|
|
|
625
738
|
}
|
|
626
739
|
async function persistSpawn(state, record, handle) {
|
|
627
740
|
const { childConversationId, createdAt } = record;
|
|
741
|
+
let inserted = false;
|
|
628
742
|
try {
|
|
629
|
-
await state.
|
|
630
|
-
scope.
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
743
|
+
await state.host.transaction(record.parentConversationId, async (scope) => {
|
|
744
|
+
await refuseOverLimit(state, scope, record.parentConversationId);
|
|
745
|
+
await scope.run(`INSERT INTO ${state.host.tables.children} (
|
|
746
|
+
parent_conversation_id, child_conversation_id, seed_upto_seq, state,
|
|
747
|
+
budget_payload, usage_payload, result_reference, created_at, updated_at
|
|
748
|
+
) VALUES (?, ?, ?, ?, ?, ?, NULL, ?, ?)`, [
|
|
749
|
+
record.parentConversationId,
|
|
750
|
+
record.childConversationId,
|
|
751
|
+
record.seedUptoSeq,
|
|
752
|
+
record.state,
|
|
753
|
+
JSON.stringify(record.budget),
|
|
754
|
+
JSON.stringify(record.usage),
|
|
755
|
+
createdAt,
|
|
756
|
+
createdAt
|
|
757
|
+
]);
|
|
636
758
|
await scope.appendEvent({
|
|
637
759
|
conversationId: record.parentConversationId,
|
|
638
760
|
kind: "child/spawned",
|
|
639
761
|
occurredAt: createdAt,
|
|
640
|
-
payload: {
|
|
762
|
+
payload: ChildSpawnedEventPayloadSchema.parse({
|
|
641
763
|
childConversationId,
|
|
642
764
|
seedUptoSeq: record.seedUptoSeq,
|
|
643
765
|
budget: record.budget
|
|
644
|
-
}
|
|
766
|
+
})
|
|
645
767
|
});
|
|
646
768
|
});
|
|
647
|
-
|
|
769
|
+
inserted = true;
|
|
770
|
+
await transitionChild(state, record, "running", { from: ["spawned"], absent: "skip" });
|
|
648
771
|
} catch (cause) {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
772
|
+
const failures = [];
|
|
773
|
+
const stop = await stopHandle(handle, "spawn-persistence-failed");
|
|
774
|
+
if (!stop.stopped)
|
|
775
|
+
failures.push(stop.cause);
|
|
776
|
+
if (inserted) {
|
|
777
|
+
try {
|
|
778
|
+
await transitionChild(state, record, "lost", {
|
|
779
|
+
from: LIVE_CHILD_STATES,
|
|
780
|
+
absent: "skip",
|
|
781
|
+
details: { reason: "spawn-persistence-failed" }
|
|
658
782
|
});
|
|
659
|
-
|
|
660
|
-
|
|
783
|
+
} catch (cleanup) {
|
|
784
|
+
failures.push(cleanup);
|
|
785
|
+
}
|
|
661
786
|
}
|
|
787
|
+
if (failures.length > 0)
|
|
788
|
+
throw new AggregateError([cause, ...failures], `Child ${childConversationId} could not be recorded, and its cleanup failed too`, { cause });
|
|
662
789
|
throw cause;
|
|
663
790
|
}
|
|
664
791
|
}
|
|
665
792
|
function watchSettlement(state, record, handle, retireChildBlocking) {
|
|
666
793
|
const { childConversationId } = record;
|
|
667
794
|
state.handles.set(childConversationId, handle);
|
|
668
|
-
const
|
|
795
|
+
const settle = async (next, resultReference) => {
|
|
796
|
+
entry.arrived = true;
|
|
669
797
|
state.handles.delete(childConversationId);
|
|
670
798
|
retireChildBlocking(childConversationId);
|
|
671
|
-
|
|
672
|
-
|
|
799
|
+
await transitionChild(state, record, next, {
|
|
800
|
+
from: LIVE_CHILD_STATES,
|
|
801
|
+
absent: "record",
|
|
802
|
+
...resultReference !== undefined && { resultReference }
|
|
803
|
+
});
|
|
804
|
+
};
|
|
805
|
+
const settled = handle.result.then((result) => settle("finished", result.resultReference), () => settle("stopped")).finally(() => {
|
|
806
|
+
if (state.settlements.get(childConversationId) === entry) {
|
|
807
|
+
state.settlements.delete(childConversationId);
|
|
673
808
|
}
|
|
674
|
-
}, async () => {
|
|
675
|
-
state.handles.delete(childConversationId);
|
|
676
|
-
retireChildBlocking(childConversationId);
|
|
677
|
-
if (settleable(state, childConversationId))
|
|
678
|
-
await updateState(state, record, "stopped");
|
|
679
809
|
});
|
|
680
|
-
|
|
681
|
-
|
|
810
|
+
const stopped = Promise.withResolvers();
|
|
811
|
+
const entry = {
|
|
812
|
+
settled,
|
|
813
|
+
ended: Promise.race([settled, stopped.promise]),
|
|
814
|
+
endedByStop: () => stopped.resolve(),
|
|
815
|
+
arrived: false
|
|
816
|
+
};
|
|
817
|
+
state.settlements.set(childConversationId, entry);
|
|
818
|
+
settled.catch(() => {
|
|
682
819
|
return;
|
|
683
820
|
});
|
|
684
821
|
}
|
|
685
822
|
async function spawnChild(state, retireChildBlocking, request) {
|
|
823
|
+
const childConversationId = request.childConversationId ?? randomUUID();
|
|
824
|
+
if (state.spawning.has(childConversationId))
|
|
825
|
+
throw new TypeError(`Child ${childConversationId} is already being spawned`);
|
|
826
|
+
const done = Promise.withResolvers();
|
|
827
|
+
const pending = {
|
|
828
|
+
parentConversationId: request.parentConversationId,
|
|
829
|
+
stopRequested: false,
|
|
830
|
+
done: done.promise
|
|
831
|
+
};
|
|
832
|
+
state.spawning.set(childConversationId, pending);
|
|
833
|
+
try {
|
|
834
|
+
await state.host.read((session) => refuseOverLimit(state, session, request.parentConversationId));
|
|
835
|
+
return await spawnAdmitted(state, retireChildBlocking, request, childConversationId, pending);
|
|
836
|
+
} finally {
|
|
837
|
+
state.spawning.delete(childConversationId);
|
|
838
|
+
done.resolve();
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
async function spawnAdmitted(state, retireChildBlocking, request, childConversationId, pending) {
|
|
686
842
|
const budget = await grantedBudget(state, request);
|
|
687
843
|
const events = await readSeedEvents(state, request);
|
|
688
844
|
const seedUptoSeq = events.at(-1)?.seq ?? 0;
|
|
689
|
-
const childConversationId = request.childConversationId ?? randomUUID();
|
|
690
845
|
const createdAt = state.now().toISOString();
|
|
691
|
-
const record =
|
|
846
|
+
const record = AgentChildRecordSchema2.parse({
|
|
692
847
|
parentConversationId: request.parentConversationId,
|
|
693
848
|
childConversationId,
|
|
694
849
|
seedUptoSeq,
|
|
@@ -706,6 +861,8 @@ async function spawnChild(state, retireChildBlocking, request) {
|
|
|
706
861
|
projections: [],
|
|
707
862
|
spills: []
|
|
708
863
|
});
|
|
864
|
+
if (pending.stopRequested)
|
|
865
|
+
throw new Error(`The parent ${record.parentConversationId} was stopped before child ${childConversationId} started; no child was spawned`);
|
|
709
866
|
const handle = await state.config.spawn({
|
|
710
867
|
parentConversationId: record.parentConversationId,
|
|
711
868
|
childConversationId,
|
|
@@ -718,67 +875,148 @@ async function spawnChild(state, retireChildBlocking, request) {
|
|
|
718
875
|
});
|
|
719
876
|
await persistSpawn(state, record, handle);
|
|
720
877
|
watchSettlement(state, record, handle, retireChildBlocking);
|
|
721
|
-
|
|
878
|
+
const running = {
|
|
879
|
+
...record,
|
|
880
|
+
state: "running",
|
|
881
|
+
updatedAt: state.now().toISOString()
|
|
882
|
+
};
|
|
883
|
+
if (!pending.stopRequested)
|
|
884
|
+
return running;
|
|
885
|
+
await stopChild(state, retireChildBlocking, running);
|
|
886
|
+
const stopped = (await listChildren(state, record.parentConversationId)).find((child) => child.childConversationId === childConversationId);
|
|
887
|
+
if (!stopped)
|
|
888
|
+
throw new TypeError(`Child ${childConversationId} was stopped and its record is gone`);
|
|
889
|
+
return stopped;
|
|
722
890
|
}
|
|
723
891
|
|
|
724
892
|
// src/agent-runtime/children-usage.ts
|
|
725
|
-
|
|
726
|
-
const { database, handles, now } = state;
|
|
727
|
-
const raw = database.prepare(`
|
|
728
|
-
SELECT parent_conversation_id, child_conversation_id, seed_upto_seq, state,
|
|
729
|
-
budget_payload, usage_payload, result_reference, created_at, updated_at
|
|
730
|
-
FROM stitchkit_agent_runtime_children WHERE child_conversation_id = ?
|
|
731
|
-
`).get(request.childConversationId);
|
|
732
|
-
if (raw === null || raw === undefined)
|
|
733
|
-
throw new TypeError("Unknown child conversation");
|
|
734
|
-
const record = parseChild(raw);
|
|
735
|
-
const measured = usageNumbers(request.usage);
|
|
736
|
-
if (record.budget.tokens !== undefined && measured.tokens === undefined) {
|
|
737
|
-
throw new TypeError("Cannot enforce child token budget without measured token usage");
|
|
738
|
-
}
|
|
739
|
-
if (record.budget.usd !== undefined && measured.usd === undefined) {
|
|
740
|
-
throw new TypeError("Cannot enforce child USD budget without USD usage");
|
|
741
|
-
}
|
|
893
|
+
function accumulate(record, measured, elapsedMs) {
|
|
742
894
|
const usage = {
|
|
743
895
|
tokens: record.usage.tokens + (measured.tokens ?? 0),
|
|
744
896
|
usd: record.usage.usd + (measured.usd ?? 0),
|
|
745
|
-
milliseconds: record.usage.milliseconds +
|
|
897
|
+
milliseconds: record.usage.milliseconds + elapsedMs
|
|
746
898
|
};
|
|
747
|
-
const updatedAt = now().toISOString();
|
|
748
899
|
const overrun = {
|
|
749
900
|
tokens: Math.max(0, usage.tokens - (record.budget.tokens ?? Number.POSITIVE_INFINITY)),
|
|
750
901
|
usd: Math.max(0, usage.usd - (record.budget.usd ?? Number.POSITIVE_INFINITY)),
|
|
751
902
|
milliseconds: Math.max(0, usage.milliseconds - (record.budget.milliseconds ?? Number.POSITIVE_INFINITY))
|
|
752
903
|
};
|
|
753
904
|
const stop = record.budget.tokens !== undefined && usage.tokens >= record.budget.tokens || record.budget.usd !== undefined && usage.usd >= record.budget.usd || record.budget.milliseconds !== undefined && usage.milliseconds >= record.budget.milliseconds;
|
|
905
|
+
return { usage, overrun, stop };
|
|
906
|
+
}
|
|
907
|
+
async function recordStepUsage(state, retireChildBlocking, request) {
|
|
908
|
+
const { host, handles, now } = state;
|
|
909
|
+
const select = `SELECT ${CHILD_COLUMNS} FROM ${host.tables.children} WHERE child_conversation_id = ?`;
|
|
910
|
+
const raw = await host.read((session) => session.get(select, [request.childConversationId]));
|
|
911
|
+
if (raw === undefined)
|
|
912
|
+
throw new TypeError("Unknown child conversation");
|
|
913
|
+
const before = parseChild(raw);
|
|
914
|
+
const measured = usageNumbers(request.usage);
|
|
915
|
+
if (before.budget.tokens !== undefined && measured.tokens === undefined) {
|
|
916
|
+
throw new TypeError("Cannot enforce child token budget without measured token usage");
|
|
917
|
+
}
|
|
918
|
+
if (before.budget.usd !== undefined && measured.usd === undefined) {
|
|
919
|
+
throw new TypeError("Cannot enforce child USD budget without USD usage");
|
|
920
|
+
}
|
|
921
|
+
const planned = accumulate(before, measured, request.elapsedMs);
|
|
754
922
|
const handle = handles.get(request.childConversationId);
|
|
755
923
|
let enforced = false;
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
...stop && { policyName: "child-budget", enforced }
|
|
924
|
+
let attemptedStop = false;
|
|
925
|
+
let stopDurationMs = 0;
|
|
926
|
+
const deliverStop = async (target) => {
|
|
927
|
+
attemptedStop = true;
|
|
928
|
+
const startedAt = performance.now();
|
|
929
|
+
const delivered = (await stopHandle(target, "child-budget")).stopped;
|
|
930
|
+
stopDurationMs = Math.max(0, performance.now() - startedAt);
|
|
931
|
+
return delivered;
|
|
765
932
|
};
|
|
766
|
-
|
|
767
|
-
|
|
933
|
+
if (planned.stop && handle)
|
|
934
|
+
enforced = await deliverStop(handle);
|
|
935
|
+
const updatedAt = now().toISOString();
|
|
936
|
+
const result = await host.transaction(before.parentConversationId, async (scope) => {
|
|
937
|
+
const current = await scope.get(select, [request.childConversationId]);
|
|
938
|
+
if (current === undefined)
|
|
939
|
+
throw new TypeError("Unknown child conversation");
|
|
940
|
+
const row = parseChild(current);
|
|
941
|
+
const { usage, overrun, stop } = accumulate(row, measured, request.elapsedMs);
|
|
942
|
+
const delivered = stop && enforced;
|
|
943
|
+
await scope.run(`UPDATE ${host.tables.children} SET usage_payload = ?, updated_at = ? WHERE child_conversation_id = ?`, [JSON.stringify(usage), updatedAt, request.childConversationId]);
|
|
944
|
+
const payload = ChildStateEventPayloadSchema.parse({
|
|
945
|
+
childConversationId: before.childConversationId,
|
|
946
|
+
state: row.state,
|
|
947
|
+
usage,
|
|
948
|
+
overrun,
|
|
949
|
+
...stop && { policyName: "child-budget", enforced: delivered }
|
|
950
|
+
});
|
|
951
|
+
const childPayload = ChildStateEventPayloadSchema.parse({
|
|
952
|
+
parentConversationId: before.parentConversationId,
|
|
953
|
+
...payload
|
|
954
|
+
});
|
|
768
955
|
await scope.appendEvent({
|
|
769
|
-
conversationId:
|
|
956
|
+
conversationId: before.parentConversationId,
|
|
770
957
|
kind: "child/state",
|
|
771
958
|
occurredAt: updatedAt,
|
|
772
959
|
payload
|
|
773
960
|
});
|
|
774
961
|
await scope.appendEvent({
|
|
775
|
-
conversationId:
|
|
962
|
+
conversationId: before.childConversationId,
|
|
776
963
|
kind: "child/state",
|
|
777
964
|
occurredAt: updatedAt,
|
|
778
|
-
payload:
|
|
965
|
+
payload: childPayload
|
|
779
966
|
});
|
|
967
|
+
return { stop, enforced: delivered, usage, overrun, state: row.state };
|
|
968
|
+
});
|
|
969
|
+
let finalEnforced = result.enforced;
|
|
970
|
+
const postHandle = handles.get(request.childConversationId);
|
|
971
|
+
if (result.stop && !attemptedStop && postHandle) {
|
|
972
|
+
finalEnforced = await deliverStop(postHandle);
|
|
973
|
+
if (finalEnforced) {
|
|
974
|
+
await recordBudgetEnforced(state, before, result);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
if (finalEnforced) {
|
|
978
|
+
await recordStop(state, retireChildBlocking, before, { stopped: true }, { policyName: "child-budget", stopDurationMs });
|
|
979
|
+
}
|
|
980
|
+
return {
|
|
981
|
+
stop: result.stop,
|
|
982
|
+
enforced: finalEnforced,
|
|
983
|
+
...result.stop && { policyName: "child-budget" },
|
|
984
|
+
overrun: result.overrun
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
async function recordBudgetEnforced(state, record, recorded) {
|
|
988
|
+
const occurredAt = state.now().toISOString();
|
|
989
|
+
const payload = ChildStateEventPayloadSchema.parse({
|
|
990
|
+
childConversationId: record.childConversationId,
|
|
991
|
+
state: recorded.state,
|
|
992
|
+
usage: recorded.usage,
|
|
993
|
+
overrun: recorded.overrun,
|
|
994
|
+
policyName: "child-budget",
|
|
995
|
+
enforced: true
|
|
780
996
|
});
|
|
781
|
-
|
|
997
|
+
const childPayload = ChildStateEventPayloadSchema.parse({
|
|
998
|
+
parentConversationId: record.parentConversationId,
|
|
999
|
+
...payload
|
|
1000
|
+
});
|
|
1001
|
+
await writeWithPurgeFallback((audience) => state.host.transaction(audience === "child" ? record.childConversationId : record.parentConversationId, async (scope) => {
|
|
1002
|
+
if (audience === "both" || audience === "parent") {
|
|
1003
|
+
await scope.appendEvent({
|
|
1004
|
+
conversationId: record.parentConversationId,
|
|
1005
|
+
kind: "child/state",
|
|
1006
|
+
occurredAt,
|
|
1007
|
+
payload
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
if (audience === "both" || audience === "child") {
|
|
1011
|
+
await scope.appendEvent({
|
|
1012
|
+
conversationId: record.childConversationId,
|
|
1013
|
+
kind: "child/state",
|
|
1014
|
+
occurredAt,
|
|
1015
|
+
payload: childPayload
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
return true;
|
|
1019
|
+
}));
|
|
782
1020
|
}
|
|
783
1021
|
// src/agent-runtime/child-budget-policy.ts
|
|
784
1022
|
function agentChildBudgetStopPolicy(input) {
|
|
@@ -786,18 +1024,17 @@ function agentChildBudgetStopPolicy(input) {
|
|
|
786
1024
|
let lastBoundary = performance.now();
|
|
787
1025
|
return {
|
|
788
1026
|
name: "child-budget",
|
|
789
|
-
when: async ({ steps }) => {
|
|
1027
|
+
when: async ({ steps, selectedModel }) => {
|
|
790
1028
|
const step = steps.at(-1);
|
|
791
1029
|
if (!step || steps.length <= stepsSeen)
|
|
792
1030
|
return false;
|
|
793
1031
|
stepsSeen = steps.length;
|
|
794
|
-
const elapsedMs = Math.max(0, performance.now() - lastBoundary);
|
|
1032
|
+
const elapsedMs = Math.round(Math.max(0, performance.now() - lastBoundary));
|
|
795
1033
|
lastBoundary = performance.now();
|
|
796
|
-
const usage =
|
|
797
|
-
const cost = input.cost?.({ usage: step.usage });
|
|
1034
|
+
const usage = normalizeStepUsage(selectedModel, step.usage, step.providerMetadata);
|
|
798
1035
|
const boundary = await input.manager.recordStepUsage({
|
|
799
1036
|
childConversationId: input.childConversationId,
|
|
800
|
-
usage
|
|
1037
|
+
usage,
|
|
801
1038
|
elapsedMs
|
|
802
1039
|
});
|
|
803
1040
|
return boundary.stop;
|
|
@@ -806,7 +1043,7 @@ function agentChildBudgetStopPolicy(input) {
|
|
|
806
1043
|
}
|
|
807
1044
|
|
|
808
1045
|
// src/agent-runtime/children.ts
|
|
809
|
-
function
|
|
1046
|
+
function createAgentChildManager(input) {
|
|
810
1047
|
const state = createChildManagerState(input);
|
|
811
1048
|
const list = (parentConversationId) => listChildren(state, parentConversationId);
|
|
812
1049
|
const { retireChildBlocking, listChildBlocking, respondToChildBlocking } = createChildBlockingRelay({
|
|
@@ -820,12 +1057,12 @@ function createSqliteAgentChildManager(input) {
|
|
|
820
1057
|
return {
|
|
821
1058
|
spawnChild: (request) => spawnChild(state, retireChildBlocking, request),
|
|
822
1059
|
listChildren: list,
|
|
823
|
-
recordStepUsage: (request) => recordStepUsage(state, request),
|
|
1060
|
+
recordStepUsage: (request) => recordStepUsage(state, retireChildBlocking, request),
|
|
824
1061
|
stopChildren: (parentConversationId) => stopChildren(state, retireChildBlocking, parentConversationId),
|
|
825
1062
|
sendMessage: (parentConversationId, childConversationId, message) => sendMessage(state, parentConversationId, childConversationId, message),
|
|
826
1063
|
interruptChild: (parentConversationId, childConversationId) => interruptChild(state, retireChildBlocking, parentConversationId, childConversationId),
|
|
827
1064
|
waitChild: async (childConversationId) => {
|
|
828
|
-
await state.settlements.get(childConversationId);
|
|
1065
|
+
await state.settlements.get(childConversationId)?.ended;
|
|
829
1066
|
},
|
|
830
1067
|
listChildBlocking,
|
|
831
1068
|
respondToChildBlocking
|
|
@@ -833,94 +1070,105 @@ function createSqliteAgentChildManager(input) {
|
|
|
833
1070
|
}
|
|
834
1071
|
|
|
835
1072
|
// src/agent-runtime/child-tools.ts
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
1073
|
+
var ChildSpawnInputSchema = z3.object({
|
|
1074
|
+
childInput: z3.json(),
|
|
1075
|
+
budget: AgentChildBudgetSchema2,
|
|
1076
|
+
seedUptoSeq: z3.int().positive().optional()
|
|
1077
|
+
}).strict();
|
|
1078
|
+
var ChildSpawnOutputSchema = z3.object({
|
|
1079
|
+
childConversationId: z3.string(),
|
|
1080
|
+
state: z3.string(),
|
|
1081
|
+
resultReference: z3.string().optional()
|
|
1082
|
+
});
|
|
1083
|
+
var SUBAGENT_DESCRIPTOR = defineAgentToolDescriptor({
|
|
1084
|
+
name: "subagent",
|
|
1085
|
+
description: "Run a child conversation seeded from the current durable parent history.",
|
|
1086
|
+
identity: { serviceName: "agent-children", action: "spawn", method: "POST" },
|
|
1087
|
+
input: ChildSpawnInputSchema,
|
|
1088
|
+
output: ChildSpawnOutputSchema,
|
|
1089
|
+
expose: ["AGENT"]
|
|
1090
|
+
});
|
|
1091
|
+
var SUBAGENT_FORK_DESCRIPTOR = defineAgentToolDescriptor({
|
|
1092
|
+
name: "subagent_fork",
|
|
1093
|
+
description: "Run a child conversation seeded from the parent through one exact event sequence.",
|
|
1094
|
+
identity: { serviceName: "agent-children", action: "fork", method: "POST" },
|
|
1095
|
+
input: ChildSpawnInputSchema,
|
|
1096
|
+
output: ChildSpawnOutputSchema,
|
|
1097
|
+
expose: ["AGENT"]
|
|
1098
|
+
});
|
|
1099
|
+
var LIST_AGENTS_DESCRIPTOR = defineAgentToolDescriptor({
|
|
1100
|
+
name: "list_agents",
|
|
1101
|
+
description: "List the durable child graph of this conversation.",
|
|
1102
|
+
identity: { serviceName: "agent-children", action: "list", method: "GET" },
|
|
1103
|
+
input: z3.object({}).strict(),
|
|
1104
|
+
output: z3.object({ children: z3.array(AgentChildRecordSchema2) }),
|
|
1105
|
+
expose: ["AGENT"]
|
|
1106
|
+
});
|
|
1107
|
+
var SEND_MESSAGE_DESCRIPTOR = defineAgentToolDescriptor({
|
|
1108
|
+
name: "send_message",
|
|
1109
|
+
description: "Send one follow-up input to an active child conversation.",
|
|
1110
|
+
identity: { serviceName: "agent-children", action: "message", method: "POST" },
|
|
1111
|
+
input: z3.object({
|
|
1112
|
+
childConversationId: z3.string().min(1),
|
|
1113
|
+
input: z3.json()
|
|
1114
|
+
}).strict(),
|
|
1115
|
+
output: z3.object({ sent: z3.literal(true) }),
|
|
1116
|
+
expose: ["AGENT"]
|
|
1117
|
+
});
|
|
1118
|
+
var INTERRUPT_AGENT_DESCRIPTOR = defineAgentToolDescriptor({
|
|
1119
|
+
name: "interrupt_agent",
|
|
1120
|
+
description: "Stop one active child conversation at a durable policy boundary.",
|
|
1121
|
+
identity: { serviceName: "agent-children", action: "interrupt", method: "POST" },
|
|
1122
|
+
input: z3.object({ childConversationId: z3.string().min(1) }).strict(),
|
|
1123
|
+
output: z3.object({ interrupted: z3.literal(true) }),
|
|
1124
|
+
expose: ["AGENT"]
|
|
1125
|
+
});
|
|
1126
|
+
var AGENT_CHILD_TOOL_DESCRIPTORS = Object.freeze([
|
|
1127
|
+
SUBAGENT_DESCRIPTOR,
|
|
1128
|
+
SUBAGENT_FORK_DESCRIPTOR,
|
|
1129
|
+
LIST_AGENTS_DESCRIPTOR,
|
|
1130
|
+
SEND_MESSAGE_DESCRIPTOR,
|
|
1131
|
+
INTERRUPT_AGENT_DESCRIPTOR
|
|
1132
|
+
]);
|
|
1133
|
+
function childTool({ manager, run }, conversationId, fork) {
|
|
1134
|
+
return bindAgentTool(fork ? SUBAGENT_FORK_DESCRIPTOR : SUBAGENT_DESCRIPTOR, async ({ input }) => {
|
|
1135
|
+
if (fork && input.seedUptoSeq === undefined) {
|
|
1136
|
+
throw new TypeError("subagent_fork requires seedUptoSeq");
|
|
876
1137
|
}
|
|
1138
|
+
run.signal.throwIfAborted();
|
|
1139
|
+
const child = await manager.spawnChild({
|
|
1140
|
+
parentConversationId: conversationId,
|
|
1141
|
+
childInput: input.childInput,
|
|
1142
|
+
budget: input.budget,
|
|
1143
|
+
...input.seedUptoSeq !== undefined && { seedUptoSeq: input.seedUptoSeq }
|
|
1144
|
+
});
|
|
1145
|
+
await manager.waitChild(child.childConversationId);
|
|
1146
|
+
const finished = (await manager.listChildren(conversationId)).find((record) => record.childConversationId === child.childConversationId);
|
|
1147
|
+
if (!finished)
|
|
1148
|
+
throw new Error("Child record disappeared after settlement");
|
|
1149
|
+
return {
|
|
1150
|
+
childConversationId: finished.childConversationId,
|
|
1151
|
+
state: finished.state,
|
|
1152
|
+
...finished.resultReference && { resultReference: finished.resultReference }
|
|
1153
|
+
};
|
|
877
1154
|
});
|
|
878
1155
|
}
|
|
879
|
-
function createAgentChildTools(
|
|
1156
|
+
function createAgentChildTools(config) {
|
|
1157
|
+
const { manager } = config;
|
|
1158
|
+
const conversationId = conversationOfRun(config.run, "createAgentChildTools");
|
|
880
1159
|
return [
|
|
881
|
-
childTool(
|
|
882
|
-
childTool(
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
transports: ["AGENT"],
|
|
890
|
-
handler: ({ input }) => ({
|
|
891
|
-
children: [...manager.listChildren(input.parentConversationId)]
|
|
892
|
-
})
|
|
893
|
-
}),
|
|
894
|
-
defineAgentTool({
|
|
895
|
-
name: "send_message",
|
|
896
|
-
description: "Send one follow-up input to an active child conversation.",
|
|
897
|
-
identity: { serviceName: "agent-children", action: "message", method: "POST" },
|
|
898
|
-
input: z2.object({
|
|
899
|
-
parentConversationId: z2.string().min(1),
|
|
900
|
-
childConversationId: z2.string().min(1),
|
|
901
|
-
input: z2.json()
|
|
902
|
-
}).strict(),
|
|
903
|
-
output: z2.object({ sent: z2.literal(true) }),
|
|
904
|
-
transports: ["AGENT"],
|
|
905
|
-
handler: async ({ input }) => {
|
|
906
|
-
await manager.sendMessage(input.parentConversationId, input.childConversationId, input.input);
|
|
907
|
-
return { sent: true };
|
|
908
|
-
}
|
|
1160
|
+
childTool(config, conversationId, false),
|
|
1161
|
+
childTool(config, conversationId, true),
|
|
1162
|
+
bindAgentTool(LIST_AGENTS_DESCRIPTOR, async () => ({
|
|
1163
|
+
children: [...await manager.listChildren(conversationId)]
|
|
1164
|
+
})),
|
|
1165
|
+
bindAgentTool(SEND_MESSAGE_DESCRIPTOR, async ({ input }) => {
|
|
1166
|
+
await manager.sendMessage(conversationId, input.childConversationId, input.input);
|
|
1167
|
+
return { sent: true };
|
|
909
1168
|
}),
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
identity: { serviceName: "agent-children", action: "interrupt", method: "POST" },
|
|
914
|
-
input: z2.object({
|
|
915
|
-
parentConversationId: z2.string().min(1),
|
|
916
|
-
childConversationId: z2.string().min(1)
|
|
917
|
-
}).strict(),
|
|
918
|
-
output: z2.object({ interrupted: z2.literal(true) }),
|
|
919
|
-
transports: ["AGENT"],
|
|
920
|
-
handler: async ({ input }) => {
|
|
921
|
-
await manager.interruptChild(input.parentConversationId, input.childConversationId);
|
|
922
|
-
return { interrupted: true };
|
|
923
|
-
}
|
|
1169
|
+
bindAgentTool(INTERRUPT_AGENT_DESCRIPTOR, async ({ input }) => {
|
|
1170
|
+
await manager.interruptChild(conversationId, input.childConversationId);
|
|
1171
|
+
return { interrupted: true };
|
|
924
1172
|
})
|
|
925
1173
|
];
|
|
926
1174
|
}
|
|
@@ -999,7 +1247,7 @@ function structuredCompaction(config) {
|
|
|
999
1247
|
});
|
|
1000
1248
|
const summary = config.schema.parse(rawSummary);
|
|
1001
1249
|
if (input.signal.aborted)
|
|
1002
|
-
throw input.signal
|
|
1250
|
+
throw abortReason(input.signal);
|
|
1003
1251
|
const summaryMessage = config.createSummaryMessage({
|
|
1004
1252
|
conversationId: input.conversationId,
|
|
1005
1253
|
summary,
|
|
@@ -1024,36 +1272,6 @@ function structuredCompaction(config) {
|
|
|
1024
1272
|
return { outcome: "conflict", snapshot: lastSnapshot, attempts: maxAttempts };
|
|
1025
1273
|
};
|
|
1026
1274
|
}
|
|
1027
|
-
// src/agent-runtime/deferred-tool-types.ts
|
|
1028
|
-
import { z as z3 } from "zod";
|
|
1029
|
-
var DeferredAgentToolSearchInputSchema = z3.object({
|
|
1030
|
-
query: z3.string().min(1).describe("An exact tool name, or words describing the tool. Matched as one phrase first, then word by word."),
|
|
1031
|
-
reason: z3.enum(["inactive_call"]).optional().describe("Written by the runtime. Leave it out.")
|
|
1032
|
-
});
|
|
1033
|
-
var DeferredAgentToolMatchSchema = z3.object({
|
|
1034
|
-
name: z3.string(),
|
|
1035
|
-
description: z3.string()
|
|
1036
|
-
});
|
|
1037
|
-
var DeferredAgentToolReceiptSchema = z3.object({
|
|
1038
|
-
schemaVersion: z3.literal(1),
|
|
1039
|
-
kind: z3.literal("stitchkit.deferred-tool-selection"),
|
|
1040
|
-
status: z3.enum(["SELECTED", "SEARCH_REQUIRED", "NO_MATCH", "SELECTION_REFUSED"]),
|
|
1041
|
-
runId: z3.string(),
|
|
1042
|
-
surfaceKey: z3.string(),
|
|
1043
|
-
selected: z3.array(z3.string()),
|
|
1044
|
-
matches: z3.array(DeferredAgentToolMatchSchema),
|
|
1045
|
-
truncated: z3.boolean()
|
|
1046
|
-
}).superRefine((receipt, context) => {
|
|
1047
|
-
const selected = receipt.status === "SELECTED" || receipt.status === "SEARCH_REQUIRED";
|
|
1048
|
-
if (selected !== receipt.selected.length > 0) {
|
|
1049
|
-
context.addIssue({
|
|
1050
|
-
code: "custom",
|
|
1051
|
-
path: ["selected"],
|
|
1052
|
-
message: `${receipt.status} receipt has inconsistent selected tools`
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
});
|
|
1056
|
-
|
|
1057
1275
|
// src/agent-runtime/deferred-tool-selection.ts
|
|
1058
1276
|
var encoder = new TextEncoder;
|
|
1059
1277
|
function utf8Bytes(value) {
|
|
@@ -1122,7 +1340,7 @@ function latestSelection(messages, searchName, runId, surface, maxSelectedTools)
|
|
|
1122
1340
|
continue;
|
|
1123
1341
|
if (part.output.type !== "json")
|
|
1124
1342
|
continue;
|
|
1125
|
-
const parsed =
|
|
1343
|
+
const parsed = DeferredAgentToolReceiptSchema2.safeParse(part.output.value);
|
|
1126
1344
|
if (!parsed.success || parsed.data.runId !== runId || parsed.data.surfaceKey !== surface.key)
|
|
1127
1345
|
continue;
|
|
1128
1346
|
const known = uniqueKnown(parsed.data.selected, surface);
|
|
@@ -1149,9 +1367,9 @@ function placeholderDeferredSearch(name) {
|
|
|
1149
1367
|
name,
|
|
1150
1368
|
description,
|
|
1151
1369
|
identity: { serviceName: "agent-runtime", action: "deferred-tool-search", method: "POST" },
|
|
1152
|
-
input:
|
|
1153
|
-
output:
|
|
1154
|
-
|
|
1370
|
+
input: DeferredAgentToolSearchInputSchema2,
|
|
1371
|
+
output: DeferredAgentToolReceiptSchema2,
|
|
1372
|
+
expose: ["AGENT"],
|
|
1155
1373
|
handler: () => ({
|
|
1156
1374
|
schemaVersion: 1,
|
|
1157
1375
|
kind: "stitchkit.deferred-tool-selection",
|
|
@@ -1169,9 +1387,9 @@ function createDeferredSearchTool(config, runContext, surface) {
|
|
|
1169
1387
|
name: config.search.name,
|
|
1170
1388
|
description,
|
|
1171
1389
|
identity: { serviceName: "agent-runtime", action: "deferred-tool-search", method: "POST" },
|
|
1172
|
-
input:
|
|
1173
|
-
output:
|
|
1174
|
-
|
|
1390
|
+
input: DeferredAgentToolSearchInputSchema2,
|
|
1391
|
+
output: DeferredAgentToolReceiptSchema2,
|
|
1392
|
+
expose: ["AGENT"],
|
|
1175
1393
|
handler: async ({ input }) => {
|
|
1176
1394
|
const queryOversized = utf8Bytes(input.query) > config.search.maxQueryBytes;
|
|
1177
1395
|
const inactiveCall = input.reason === "inactive_call" && surface.byName.has(input.query);
|
|
@@ -1266,14 +1484,33 @@ function resolveSurface(config, surfaces, runContext) {
|
|
|
1266
1484
|
throw new Error(`Unknown deferred Agent tool surface "${key}"`);
|
|
1267
1485
|
return surface;
|
|
1268
1486
|
}
|
|
1269
|
-
|
|
1487
|
+
var PROJECTION_KEYS = ["extend", "flattenUnionInput", "inputRecursionDepth"];
|
|
1488
|
+
function surfaceProjection(config) {
|
|
1489
|
+
return {
|
|
1490
|
+
...config.extend !== undefined && { extend: config.extend },
|
|
1491
|
+
...config.flattenUnionInput !== undefined && {
|
|
1492
|
+
flattenUnionInput: config.flattenUnionInput
|
|
1493
|
+
},
|
|
1494
|
+
...config.inputRecursionDepth !== undefined && {
|
|
1495
|
+
inputRecursionDepth: config.inputRecursionDepth
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
function refuseMountProjection(mountConfig) {
|
|
1500
|
+
for (const key of PROJECTION_KEYS) {
|
|
1501
|
+
if (key in mountConfig)
|
|
1502
|
+
throw new TypeError(`createDeferredAgentToolSurface.mount: ${key} belongs to createDeferredAgentToolSurface, where maxSchemaBytes measures the schemas it shapes`);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
function resolveAllSurfaces(config, projection) {
|
|
1270
1506
|
const placeholderSearch = placeholderDeferredSearch(config.search.name);
|
|
1271
1507
|
const surfaces = new Map;
|
|
1272
1508
|
for (const [key, definition] of Object.entries(configuredSurfaces(config))) {
|
|
1273
1509
|
const runtimeTools = executableAgentRuntimeTools(definition.runtimeTools ?? []);
|
|
1274
1510
|
const fullManifest = buildToolManifest2({
|
|
1275
|
-
...definition,
|
|
1511
|
+
...definition.services && { services: definition.services },
|
|
1276
1512
|
runtimeTools: [...runtimeTools, placeholderSearch],
|
|
1513
|
+
...projection,
|
|
1277
1514
|
transport: "AGENT"
|
|
1278
1515
|
});
|
|
1279
1516
|
const searchEntry = fullManifest.find((entry) => entry.name === config.search.name);
|
|
@@ -1339,10 +1576,13 @@ function createDeferredAgentToolSurface(config) {
|
|
|
1339
1576
|
positive("activation.maxSelectedTools", config.activation.maxSelectedTools);
|
|
1340
1577
|
positive("activation.maxActiveTools", config.activation.maxActiveTools);
|
|
1341
1578
|
positive("activation.maxSchemaBytes", config.activation.maxSchemaBytes);
|
|
1342
|
-
const
|
|
1579
|
+
const projection = surfaceProjection(config);
|
|
1580
|
+
const surfaces = resolveAllSurfaces(config, projection);
|
|
1343
1581
|
assertConstructionBudgets(config, surfaces);
|
|
1344
1582
|
return {
|
|
1345
|
-
mount(runContext, mountConfig
|
|
1583
|
+
mount(runContext, mountConfig) {
|
|
1584
|
+
resolveToolAccess("createDeferredAgentToolSurface.mount", mountConfig);
|
|
1585
|
+
refuseMountProjection(mountConfig);
|
|
1346
1586
|
const surface = resolveSurface(config, surfaces, runContext);
|
|
1347
1587
|
const runtimeTools = [
|
|
1348
1588
|
...executableAgentRuntimeTools(surface.definition.runtimeTools ?? []),
|
|
@@ -1350,6 +1590,7 @@ function createDeferredAgentToolSurface(config) {
|
|
|
1350
1590
|
];
|
|
1351
1591
|
const tools = mountAgent2([...surface.definition.services ?? []], {
|
|
1352
1592
|
...mountConfig,
|
|
1593
|
+
...projection,
|
|
1353
1594
|
runtimeTools
|
|
1354
1595
|
});
|
|
1355
1596
|
registerDeferredToolCatalog(tools, config.search.name, new Set(surface.byName.keys()));
|
|
@@ -1399,213 +1640,75 @@ function createDeferredAgentToolSurface(config) {
|
|
|
1399
1640
|
}
|
|
1400
1641
|
};
|
|
1401
1642
|
}
|
|
1402
|
-
// src/agent-runtime/
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
occurred_at: z4.string(),
|
|
1414
|
-
snippet: z4.string()
|
|
1415
|
-
});
|
|
1416
|
-
function literalFtsQuery(query) {
|
|
1417
|
-
const terms = query.split(/\s+/u).filter((term) => /[\p{L}\p{N}]/u.test(term));
|
|
1418
|
-
if (terms.length === 0)
|
|
1419
|
-
throw new TypeError("Event search query must contain searchable terms");
|
|
1420
|
-
return terms.map((term) => `"${term.replaceAll('"', '""')}"`).join(" AND ");
|
|
1421
|
-
}
|
|
1422
|
-
function createSqliteAgentEventSearch(input) {
|
|
1423
|
-
return async (request) => {
|
|
1424
|
-
if (request.query.trim().length === 0)
|
|
1425
|
-
throw new TypeError("Event search query must not be empty");
|
|
1426
|
-
const limit = Math.min(request.limit ?? 20, 200);
|
|
1427
|
-
const target = request.conversationId ?? (input.authorizeConversation ? undefined : request.requestingConversationId);
|
|
1428
|
-
const values = [literalFtsQuery(request.query)];
|
|
1429
|
-
const targetClause = target ? "AND f.conversation_id = ?" : "";
|
|
1430
|
-
if (target)
|
|
1431
|
-
values.push(target);
|
|
1432
|
-
const sinceClause = request.since ? "AND f.occurred_at >= ?" : "";
|
|
1433
|
-
if (request.since)
|
|
1434
|
-
values.push(z4.iso.datetime({ offset: true }).parse(request.since));
|
|
1435
|
-
const page = limit * 4;
|
|
1436
|
-
const candidatesFrom = (offset) => input.database.prepare(`
|
|
1437
|
-
SELECT f.conversation_id, f.event_seq, f.occurred_at,
|
|
1438
|
-
snippet(stitchkit_agent_runtime_events_fts, 3, '[', ']', ' … ', 24) AS snippet
|
|
1439
|
-
FROM stitchkit_agent_runtime_events_fts AS f
|
|
1440
|
-
WHERE stitchkit_agent_runtime_events_fts MATCH ? ${targetClause} ${sinceClause}
|
|
1441
|
-
ORDER BY bm25(stitchkit_agent_runtime_events_fts), f.occurred_at DESC, f.rowid
|
|
1442
|
-
LIMIT ? OFFSET ?
|
|
1443
|
-
`).all(...values, page, offset).map((row) => SearchRowSchema.parse(row));
|
|
1444
|
-
const authorization = new Map;
|
|
1445
|
-
const results = [];
|
|
1446
|
-
let offset = 0;
|
|
1447
|
-
let candidates = candidatesFrom(offset);
|
|
1448
|
-
while (candidates.length > 0 && results.length < limit) {
|
|
1449
|
-
for (const row of candidates) {
|
|
1450
|
-
if (row.conversation_id !== request.requestingConversationId) {
|
|
1451
|
-
let allowed = authorization.get(row.conversation_id);
|
|
1452
|
-
if (allowed === undefined) {
|
|
1453
|
-
allowed = input.authorizeConversation ? await input.authorizeConversation({
|
|
1454
|
-
requestingConversationId: request.requestingConversationId,
|
|
1455
|
-
targetConversationId: row.conversation_id
|
|
1456
|
-
}) : false;
|
|
1457
|
-
authorization.set(row.conversation_id, allowed);
|
|
1458
|
-
}
|
|
1459
|
-
if (!allowed)
|
|
1460
|
-
continue;
|
|
1461
|
-
}
|
|
1462
|
-
results.push(AgentEventSearchResultSchema.parse({
|
|
1463
|
-
conversationId: row.conversation_id,
|
|
1464
|
-
seq: row.event_seq,
|
|
1465
|
-
occurredAt: row.occurred_at,
|
|
1466
|
-
snippet: row.snippet
|
|
1467
|
-
}));
|
|
1468
|
-
if (results.length === limit)
|
|
1469
|
-
break;
|
|
1470
|
-
}
|
|
1471
|
-
offset += page;
|
|
1472
|
-
candidates = results.length < limit ? candidatesFrom(offset) : [];
|
|
1473
|
-
}
|
|
1474
|
-
return results;
|
|
1475
|
-
};
|
|
1476
|
-
}
|
|
1477
|
-
// src/agent-runtime/event-search-tools.ts
|
|
1478
|
-
import { z as z5 } from "zod";
|
|
1479
|
-
function createAgentEventSearchTools(input) {
|
|
1480
|
-
const EventAddressSchema = z5.object({ conversationId: z5.string(), seq: z5.int().positive() }).strict();
|
|
1481
|
-
const EventOutputSchema = z5.object({
|
|
1482
|
-
conversationId: z5.string(),
|
|
1483
|
-
seq: z5.int().positive(),
|
|
1484
|
-
kind: z5.string(),
|
|
1485
|
-
occurredAt: z5.string(),
|
|
1486
|
-
payload: z5.json()
|
|
1487
|
-
}).strict();
|
|
1488
|
-
const readExact = async (address) => {
|
|
1489
|
-
if (address.conversationId !== input.conversationId) {
|
|
1490
|
-
const allowed = await input.authorizeConversation?.({
|
|
1491
|
-
requestingConversationId: input.conversationId,
|
|
1492
|
-
targetConversationId: address.conversationId
|
|
1493
|
-
});
|
|
1494
|
-
if (!allowed)
|
|
1495
|
-
throw new TypeError("Event address is outside the authorized conversation");
|
|
1496
|
-
}
|
|
1497
|
-
const page = await input.store.readEvents({
|
|
1498
|
-
conversationId: address.conversationId,
|
|
1499
|
-
fromSeq: address.seq,
|
|
1500
|
-
toSeq: address.seq,
|
|
1501
|
-
limit: 1
|
|
1502
|
-
});
|
|
1503
|
-
const event = page.items[0];
|
|
1504
|
-
if (!event || event.seq !== address.seq)
|
|
1505
|
-
throw new TypeError("Unknown event address");
|
|
1506
|
-
return {
|
|
1507
|
-
conversationId: event.conversationId,
|
|
1508
|
-
seq: event.seq,
|
|
1509
|
-
kind: event.kind,
|
|
1510
|
-
occurredAt: event.occurredAt,
|
|
1511
|
-
payload: event.payload
|
|
1512
|
-
};
|
|
1643
|
+
// src/agent-runtime/invocation-spend.ts
|
|
1644
|
+
function modelInvocationSpendAttribution() {
|
|
1645
|
+
const attempt = currentModelInvocationAttempt2();
|
|
1646
|
+
if (!attempt)
|
|
1647
|
+
return;
|
|
1648
|
+
return {
|
|
1649
|
+
conversationId: attempt.conversationId,
|
|
1650
|
+
invocationId: attempt.invocationId,
|
|
1651
|
+
invocationAttemptId: attempt.attemptId,
|
|
1652
|
+
step: attempt.step,
|
|
1653
|
+
...attempt.runId !== undefined && { runId: attempt.runId }
|
|
1513
1654
|
};
|
|
1514
|
-
return [
|
|
1515
|
-
defineAgentTool({
|
|
1516
|
-
name: "session_search",
|
|
1517
|
-
description: "Search authorized durable conversation events and return exact addresses.",
|
|
1518
|
-
identity: { serviceName: "agent-events", action: "search", method: "POST" },
|
|
1519
|
-
input: z5.object({
|
|
1520
|
-
query: z5.string().min(1),
|
|
1521
|
-
conversationId: z5.string().min(1).optional(),
|
|
1522
|
-
since: z5.iso.datetime({ offset: true }).optional(),
|
|
1523
|
-
limit: z5.int().positive().max(200).optional()
|
|
1524
|
-
}).strict(),
|
|
1525
|
-
output: z5.object({ results: z5.array(AgentEventSearchResultSchema) }).strict(),
|
|
1526
|
-
transports: ["AGENT"],
|
|
1527
|
-
handler: async ({ input: request }) => ({
|
|
1528
|
-
results: [
|
|
1529
|
-
...await input.search({
|
|
1530
|
-
requestingConversationId: input.conversationId,
|
|
1531
|
-
...request
|
|
1532
|
-
})
|
|
1533
|
-
]
|
|
1534
|
-
})
|
|
1535
|
-
}),
|
|
1536
|
-
defineAgentTool({
|
|
1537
|
-
name: "session_trace",
|
|
1538
|
-
description: "Read a bounded contiguous slice of this conversation event trace.",
|
|
1539
|
-
identity: { serviceName: "agent-events", action: "trace", method: "GET" },
|
|
1540
|
-
input: z5.object({
|
|
1541
|
-
fromSeq: z5.int().positive().optional(),
|
|
1542
|
-
toSeq: z5.int().positive().optional(),
|
|
1543
|
-
limit: z5.int().positive().max(1000).default(100)
|
|
1544
|
-
}).strict(),
|
|
1545
|
-
output: z5.object({ events: z5.array(EventOutputSchema), nextSeq: z5.number().optional() }),
|
|
1546
|
-
transports: ["AGENT"],
|
|
1547
|
-
handler: async ({ input: request }) => {
|
|
1548
|
-
const page = await input.store.readEvents({
|
|
1549
|
-
conversationId: input.conversationId,
|
|
1550
|
-
...request
|
|
1551
|
-
});
|
|
1552
|
-
return {
|
|
1553
|
-
events: page.items.map((event) => ({
|
|
1554
|
-
conversationId: event.conversationId,
|
|
1555
|
-
seq: event.seq,
|
|
1556
|
-
kind: event.kind,
|
|
1557
|
-
occurredAt: event.occurredAt,
|
|
1558
|
-
payload: event.payload
|
|
1559
|
-
})),
|
|
1560
|
-
...page.nextSeq !== undefined && { nextSeq: page.nextSeq }
|
|
1561
|
-
};
|
|
1562
|
-
}
|
|
1563
|
-
}),
|
|
1564
|
-
defineAgentTool({
|
|
1565
|
-
name: "session_event",
|
|
1566
|
-
description: "Read one durable event by exact conversation and sequence address.",
|
|
1567
|
-
identity: { serviceName: "agent-events", action: "read", method: "GET" },
|
|
1568
|
-
input: EventAddressSchema,
|
|
1569
|
-
output: EventOutputSchema,
|
|
1570
|
-
transports: ["AGENT"],
|
|
1571
|
-
handler: ({ input: request }) => readExact(request)
|
|
1572
|
-
})
|
|
1573
|
-
];
|
|
1574
1655
|
}
|
|
1575
1656
|
// src/agent-runtime/observability.ts
|
|
1576
|
-
import { z as
|
|
1577
|
-
var AgentRunEventBaseSchema =
|
|
1578
|
-
schemaVersion:
|
|
1657
|
+
import { z as z4 } from "zod";
|
|
1658
|
+
var AgentRunEventBaseSchema = z4.object({
|
|
1659
|
+
schemaVersion: z4.literal(1),
|
|
1579
1660
|
eventId: AgentRecordIdSchema2,
|
|
1580
1661
|
conversationId: AgentRecordIdSchema2,
|
|
1581
1662
|
runId: AgentRecordIdSchema2,
|
|
1582
|
-
traceId:
|
|
1583
|
-
spanId:
|
|
1584
|
-
parentSpanId:
|
|
1663
|
+
traceId: z4.string().min(1),
|
|
1664
|
+
spanId: z4.string().min(1),
|
|
1665
|
+
parentSpanId: z4.string().min(1).optional(),
|
|
1585
1666
|
state: AgentRunStateSchema2,
|
|
1586
|
-
modelId:
|
|
1587
|
-
durationMs:
|
|
1667
|
+
modelId: z4.string().min(1).optional(),
|
|
1668
|
+
durationMs: z4.number().nonnegative().optional(),
|
|
1588
1669
|
emittedAt: AgentTimestampSchema2
|
|
1589
1670
|
});
|
|
1590
1671
|
var AgentRunStartedEventSchema = AgentRunEventBaseSchema.extend({
|
|
1591
|
-
type:
|
|
1592
|
-
queueWaitMs:
|
|
1672
|
+
type: z4.literal("run-started"),
|
|
1673
|
+
queueWaitMs: z4.number().nonnegative().optional()
|
|
1593
1674
|
});
|
|
1594
1675
|
var AgentStepFinishedEventSchema = AgentRunEventBaseSchema.extend({
|
|
1595
|
-
type:
|
|
1596
|
-
step:
|
|
1597
|
-
|
|
1676
|
+
type: z4.literal("step-finished"),
|
|
1677
|
+
step: z4.int().nonnegative(),
|
|
1678
|
+
attempt: z4.int().nonnegative(),
|
|
1679
|
+
phase: AgentStepSpendPhaseSchema2,
|
|
1680
|
+
provider: AgentStepSpendProviderSchema.optional(),
|
|
1681
|
+
ttftMs: z4.number().nonnegative().optional(),
|
|
1598
1682
|
usage: AgentUsageSchema2,
|
|
1599
|
-
response: AgentProviderResponseSchema2
|
|
1683
|
+
response: AgentProviderResponseSchema2.optional(),
|
|
1684
|
+
spendHookError: z4.strictObject({
|
|
1685
|
+
code: z4.enum(["hook_error", "hook_timeout"]),
|
|
1686
|
+
cause: z4.unknown().optional(),
|
|
1687
|
+
reportFailed: z4.literal(true).optional(),
|
|
1688
|
+
reportError: z4.unknown().optional()
|
|
1689
|
+
}).optional()
|
|
1690
|
+
}).check((ctx) => {
|
|
1691
|
+
const event = ctx.value;
|
|
1692
|
+
const answered = event.phase !== "compaction";
|
|
1693
|
+
for (const field of ["modelId", "provider", "response"]) {
|
|
1694
|
+
if (event[field] !== undefined === answered)
|
|
1695
|
+
continue;
|
|
1696
|
+
ctx.issues.push({
|
|
1697
|
+
code: "custom",
|
|
1698
|
+
input: event[field],
|
|
1699
|
+
path: [field],
|
|
1700
|
+
message: answered ? `A ${event.phase} spend names its ${field}` : `A compaction has no ${field}`
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1600
1703
|
});
|
|
1601
1704
|
var AgentRunTerminalEventSchema = AgentRunEventBaseSchema.extend({
|
|
1602
|
-
type:
|
|
1705
|
+
type: z4.literal("run-terminal"),
|
|
1603
1706
|
terminalReason: AgentTerminalReasonSchema2,
|
|
1604
|
-
ttftMs:
|
|
1605
|
-
internalCause:
|
|
1707
|
+
ttftMs: z4.number().nonnegative().optional(),
|
|
1708
|
+
internalCause: z4.unknown().optional(),
|
|
1606
1709
|
usage: AgentUsageSchema2
|
|
1607
1710
|
});
|
|
1608
|
-
var AgentRunEventSchema =
|
|
1711
|
+
var AgentRunEventSchema = z4.discriminatedUnion("type", [
|
|
1609
1712
|
AgentRunStartedEventSchema,
|
|
1610
1713
|
AgentStepFinishedEventSchema,
|
|
1611
1714
|
AgentRunTerminalEventSchema
|
|
@@ -1643,9 +1746,19 @@ function createAgentObservability(config) {
|
|
|
1643
1746
|
manager.submit(() => {
|
|
1644
1747
|
if (config.includeInternalCause)
|
|
1645
1748
|
return parsed;
|
|
1646
|
-
if (parsed.type
|
|
1647
|
-
return parsed;
|
|
1648
|
-
|
|
1749
|
+
if (parsed.type === "run-terminal") {
|
|
1750
|
+
return AgentRunTerminalEventSchema.omit({ internalCause: true }).parse(parsed);
|
|
1751
|
+
}
|
|
1752
|
+
if (parsed.type === "step-finished" && parsed.spendHookError !== undefined) {
|
|
1753
|
+
return AgentStepFinishedEventSchema.parse({
|
|
1754
|
+
...parsed,
|
|
1755
|
+
spendHookError: {
|
|
1756
|
+
code: parsed.spendHookError.code,
|
|
1757
|
+
...parsed.spendHookError.reportFailed && { reportFailed: true }
|
|
1758
|
+
}
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
return parsed;
|
|
1649
1762
|
});
|
|
1650
1763
|
},
|
|
1651
1764
|
flush: (bound) => manager.flush(bound),
|
|
@@ -1654,7 +1767,7 @@ function createAgentObservability(config) {
|
|
|
1654
1767
|
};
|
|
1655
1768
|
}
|
|
1656
1769
|
// src/agent-runtime/projections.ts
|
|
1657
|
-
import { z as
|
|
1770
|
+
import { z as z5 } from "zod";
|
|
1658
1771
|
function defineAgentProjection(definition) {
|
|
1659
1772
|
if (definition.name.length === 0)
|
|
1660
1773
|
throw new TypeError("Projection name must not be empty");
|
|
@@ -1674,26 +1787,23 @@ function createAgentProjectionRegistry(definitions) {
|
|
|
1674
1787
|
}
|
|
1675
1788
|
return registry;
|
|
1676
1789
|
}
|
|
1677
|
-
var ProjectionRowSchema =
|
|
1678
|
-
conversation_id:
|
|
1679
|
-
version:
|
|
1680
|
-
upto_seq:
|
|
1681
|
-
payload:
|
|
1682
|
-
updated_at:
|
|
1790
|
+
var ProjectionRowSchema = z5.object({
|
|
1791
|
+
conversation_id: z5.string().optional(),
|
|
1792
|
+
version: SqlIntegerSchema.pipe(z5.int().positive()),
|
|
1793
|
+
upto_seq: SqlIntegerSchema.pipe(z5.int().nonnegative()),
|
|
1794
|
+
payload: z5.string(),
|
|
1795
|
+
updated_at: z5.string()
|
|
1683
1796
|
});
|
|
1684
1797
|
function projectionPayload(value) {
|
|
1685
1798
|
return JSON.parse(value);
|
|
1686
1799
|
}
|
|
1687
|
-
function
|
|
1688
|
-
const
|
|
1689
|
-
const
|
|
1690
|
-
const load = (conversationId, definition) => {
|
|
1691
|
-
const raw =
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
WHERE conversation_id = ? AND name = ?
|
|
1695
|
-
`).get(conversationId, definition.name);
|
|
1696
|
-
if (raw === null || raw === undefined)
|
|
1800
|
+
function createAgentProjectionStore(input) {
|
|
1801
|
+
const { host, store } = input;
|
|
1802
|
+
const projections = host.tables.projections;
|
|
1803
|
+
const load = async (conversationId, definition) => {
|
|
1804
|
+
const raw = await host.read((session) => session.get(`SELECT version, upto_seq, payload, updated_at FROM ${projections}
|
|
1805
|
+
WHERE conversation_id = ? AND name = ?`, [conversationId, definition.name]));
|
|
1806
|
+
if (raw === undefined)
|
|
1697
1807
|
return;
|
|
1698
1808
|
const row = ProjectionRowSchema.parse(raw);
|
|
1699
1809
|
if (row.version !== definition.version)
|
|
@@ -1707,7 +1817,7 @@ function createSqliteAgentProjectionStore(input) {
|
|
|
1707
1817
|
};
|
|
1708
1818
|
};
|
|
1709
1819
|
const advance = async (conversationId, definition) => {
|
|
1710
|
-
const current = load(conversationId, definition);
|
|
1820
|
+
const current = await load(conversationId, definition);
|
|
1711
1821
|
let value = current?.value ?? definition.initial();
|
|
1712
1822
|
let uptoSeq = current?.uptoSeq ?? 0;
|
|
1713
1823
|
let cursor = uptoSeq + 1;
|
|
@@ -1727,25 +1837,29 @@ function createSqliteAgentProjectionStore(input) {
|
|
|
1727
1837
|
break;
|
|
1728
1838
|
cursor = page.nextSeq;
|
|
1729
1839
|
}
|
|
1730
|
-
await
|
|
1731
|
-
scope.
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1840
|
+
await host.transaction(conversationId, async (scope) => {
|
|
1841
|
+
await scope.run(`INSERT INTO ${projections}
|
|
1842
|
+
(conversation_id, name, version, upto_seq, payload, updated_at)
|
|
1843
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
1844
|
+
ON CONFLICT (conversation_id, name) DO UPDATE SET
|
|
1845
|
+
version = excluded.version,
|
|
1846
|
+
upto_seq = excluded.upto_seq,
|
|
1847
|
+
payload = excluded.payload,
|
|
1848
|
+
updated_at = excluded.updated_at
|
|
1849
|
+
WHERE ${projections}.version <> excluded.version
|
|
1850
|
+
OR excluded.upto_seq >= ${projections}.upto_seq`, [
|
|
1851
|
+
conversationId,
|
|
1852
|
+
definition.name,
|
|
1853
|
+
definition.version,
|
|
1854
|
+
uptoSeq,
|
|
1855
|
+
JSON.stringify(value),
|
|
1856
|
+
updatedAt
|
|
1857
|
+
]);
|
|
1741
1858
|
});
|
|
1742
1859
|
return { name: definition.name, version: definition.version, uptoSeq, updatedAt, value };
|
|
1743
1860
|
};
|
|
1744
|
-
const list = (definition) =>
|
|
1745
|
-
|
|
1746
|
-
FROM stitchkit_agent_runtime_projections
|
|
1747
|
-
WHERE name = ? AND version = ? ORDER BY updated_at DESC, conversation_id
|
|
1748
|
-
`).all(definition.name, definition.version).map((raw) => {
|
|
1861
|
+
const list = async (definition) => (await host.read((session) => session.all(`SELECT conversation_id, version, upto_seq, payload, updated_at FROM ${projections}
|
|
1862
|
+
WHERE name = ? AND version = ? ORDER BY updated_at DESC, conversation_id`, [definition.name, definition.version]))).map((raw) => {
|
|
1749
1863
|
const row = ProjectionRowSchema.parse(raw);
|
|
1750
1864
|
if (!row.conversation_id)
|
|
1751
1865
|
throw new TypeError("Projection list row has no conversation id");
|
|
@@ -1762,10 +1876,10 @@ function createSqliteAgentProjectionStore(input) {
|
|
|
1762
1876
|
});
|
|
1763
1877
|
return { load, advance, list };
|
|
1764
1878
|
}
|
|
1765
|
-
var ConversationCardSchema =
|
|
1766
|
-
eventCount:
|
|
1767
|
-
lastKind:
|
|
1768
|
-
lastOccurredAt:
|
|
1879
|
+
var ConversationCardSchema = z5.object({
|
|
1880
|
+
eventCount: z5.int().nonnegative(),
|
|
1881
|
+
lastKind: z5.string().optional(),
|
|
1882
|
+
lastOccurredAt: z5.string().optional()
|
|
1769
1883
|
});
|
|
1770
1884
|
var agentConversationCardProjection = defineAgentProjection({
|
|
1771
1885
|
name: "conversation-card",
|
|
@@ -1778,7 +1892,7 @@ var agentConversationCardProjection = defineAgentProjection({
|
|
|
1778
1892
|
lastOccurredAt: event.occurredAt
|
|
1779
1893
|
})
|
|
1780
1894
|
});
|
|
1781
|
-
var StateSlotsProjectionSchema =
|
|
1895
|
+
var StateSlotsProjectionSchema = z5.record(z5.string(), z5.json());
|
|
1782
1896
|
var agentStateSlotsProjection = defineAgentProjection({
|
|
1783
1897
|
name: "state-slots",
|
|
1784
1898
|
version: 1,
|
|
@@ -1787,15 +1901,15 @@ var agentStateSlotsProjection = defineAgentProjection({
|
|
|
1787
1901
|
fold: (state, event) => {
|
|
1788
1902
|
if (event.kind !== "state/set")
|
|
1789
1903
|
return state;
|
|
1790
|
-
const payload =
|
|
1904
|
+
const payload = z5.looseObject({ name: z5.string().min(1), value: z5.json() }).parse(event.payload);
|
|
1791
1905
|
return { ...state, [payload.name]: payload.value };
|
|
1792
1906
|
}
|
|
1793
1907
|
});
|
|
1794
|
-
var ScheduleSummarySchema =
|
|
1795
|
-
scheduled:
|
|
1796
|
-
fired:
|
|
1797
|
-
cancelled:
|
|
1798
|
-
late:
|
|
1908
|
+
var ScheduleSummarySchema = z5.object({
|
|
1909
|
+
scheduled: z5.int().nonnegative(),
|
|
1910
|
+
fired: z5.int().nonnegative(),
|
|
1911
|
+
cancelled: z5.int().nonnegative(),
|
|
1912
|
+
late: z5.int().nonnegative()
|
|
1799
1913
|
});
|
|
1800
1914
|
var agentScheduleSummaryProjection = defineAgentProjection({
|
|
1801
1915
|
name: "schedule-summary",
|
|
@@ -1814,12 +1928,12 @@ var agentScheduleSummaryProjection = defineAgentProjection({
|
|
|
1814
1928
|
return state;
|
|
1815
1929
|
}
|
|
1816
1930
|
});
|
|
1817
|
-
var RuntimeSummarySchema =
|
|
1818
|
-
eventCount:
|
|
1819
|
-
lastSeq:
|
|
1820
|
-
lastKind:
|
|
1821
|
-
lastOccurredAt:
|
|
1822
|
-
lastModelId:
|
|
1931
|
+
var RuntimeSummarySchema = z5.object({
|
|
1932
|
+
eventCount: z5.int().nonnegative(),
|
|
1933
|
+
lastSeq: z5.int().nonnegative(),
|
|
1934
|
+
lastKind: z5.string().optional(),
|
|
1935
|
+
lastOccurredAt: z5.string().optional(),
|
|
1936
|
+
lastModelId: z5.string().optional()
|
|
1823
1937
|
}).strict();
|
|
1824
1938
|
var agentSummaryProjection = defineAgentProjection({
|
|
1825
1939
|
name: "summary",
|
|
@@ -1827,10 +1941,10 @@ var agentSummaryProjection = defineAgentProjection({
|
|
|
1827
1941
|
schema: RuntimeSummarySchema,
|
|
1828
1942
|
initial: () => ({ eventCount: 0, lastSeq: 0 }),
|
|
1829
1943
|
fold: (state, event) => {
|
|
1830
|
-
const request = event.kind === "provider/request" ?
|
|
1831
|
-
modelId:
|
|
1832
|
-
sent:
|
|
1833
|
-
}).
|
|
1944
|
+
const request = event.kind === "provider/request" ? z5.looseObject({
|
|
1945
|
+
modelId: z5.string().optional(),
|
|
1946
|
+
sent: z5.looseObject({ modelId: z5.string() }).optional()
|
|
1947
|
+
}).transform((payload) => ({ modelId: payload.modelId ?? payload.sent?.modelId })).safeParse(event.payload) : undefined;
|
|
1834
1948
|
return {
|
|
1835
1949
|
eventCount: state.eventCount + 1,
|
|
1836
1950
|
lastSeq: event.seq,
|
|
@@ -1840,40 +1954,78 @@ var agentSummaryProjection = defineAgentProjection({
|
|
|
1840
1954
|
};
|
|
1841
1955
|
}
|
|
1842
1956
|
});
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1957
|
+
function hasMeasuredUsage(usage) {
|
|
1958
|
+
if (!usage)
|
|
1959
|
+
return false;
|
|
1960
|
+
return usage.inputTokens.value !== undefined || usage.outputTokens.value !== undefined || usage.reasoningTokens?.value !== undefined || usage.cacheReadTokens?.value !== undefined || usage.cacheWriteTokens?.value !== undefined || usage.cost?.value !== undefined;
|
|
1961
|
+
}
|
|
1962
|
+
var TerminalUsageTransitionSchema = z5.looseObject({
|
|
1963
|
+
type: z5.literal("terminal"),
|
|
1964
|
+
input: z5.looseObject({
|
|
1965
|
+
reason: AgentTerminalReasonSchema2.optional(),
|
|
1966
|
+
usage: AgentUsageSchema2.optional(),
|
|
1967
|
+
assistant: z5.looseObject({ parts: z5.array(z5.unknown()) }).optional()
|
|
1968
|
+
})
|
|
1969
|
+
});
|
|
1970
|
+
var RecoverUsageTransitionSchema = z5.looseObject({
|
|
1971
|
+
type: z5.literal("recover"),
|
|
1972
|
+
input: z5.looseObject({ action: z5.literal("abandon") }),
|
|
1973
|
+
usage: AgentUsageSchema2.optional()
|
|
1974
|
+
});
|
|
1975
|
+
function eventUsage(event) {
|
|
1976
|
+
if (event.kind === "runtime/transition") {
|
|
1977
|
+
const terminal = TerminalUsageTransitionSchema.safeParse(event.payload);
|
|
1978
|
+
if (terminal.success) {
|
|
1979
|
+
const { assistant, reason, usage } = terminal.data.input;
|
|
1980
|
+
const answered = reason === undefined || runStateForTerminalReason2(reason) === "completed" || assistant === undefined || assistant.parts.length > 0;
|
|
1981
|
+
if (!answered && !hasMeasuredUsage(usage))
|
|
1982
|
+
return;
|
|
1983
|
+
return statedUsage(usage);
|
|
1984
|
+
}
|
|
1985
|
+
const abandoned = RecoverUsageTransitionSchema.safeParse(event.payload);
|
|
1986
|
+
if (abandoned.success && hasMeasuredUsage(abandoned.data.usage)) {
|
|
1987
|
+
return statedUsage(abandoned.data.usage);
|
|
1988
|
+
}
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
if (event.kind === "provider/response" && isModelInvocationRecord(event.payload)) {
|
|
1992
|
+
const parsed = InvocationResponseSchema.safeParse(event.payload);
|
|
1993
|
+
if (!parsed.success || parsed.data.runId !== undefined)
|
|
1994
|
+
return;
|
|
1995
|
+
if (parsed.data.status !== "succeeded" && !hasMeasuredUsage(parsed.data.usage)) {
|
|
1996
|
+
return;
|
|
1997
|
+
}
|
|
1998
|
+
return parsed.data.usage;
|
|
1999
|
+
}
|
|
2000
|
+
return;
|
|
2001
|
+
}
|
|
2002
|
+
var RuntimeUsageSchema = z5.strictObject({
|
|
2003
|
+
records: z5.int().nonnegative(),
|
|
2004
|
+
usage: AgentUsageSchema2
|
|
2005
|
+
});
|
|
1849
2006
|
var agentUsageProjection = defineAgentProjection({
|
|
1850
2007
|
name: "usage",
|
|
1851
|
-
version:
|
|
2008
|
+
version: 2,
|
|
1852
2009
|
schema: RuntimeUsageSchema,
|
|
1853
|
-
initial: () => ({
|
|
2010
|
+
initial: () => ({
|
|
2011
|
+
records: 0,
|
|
2012
|
+
usage: unknownUsage()
|
|
2013
|
+
}),
|
|
1854
2014
|
fold: (state, event) => {
|
|
1855
|
-
const
|
|
1856
|
-
|
|
1857
|
-
outputTokens: z7.number().nonnegative().optional(),
|
|
1858
|
-
cost: z7.number().nonnegative().optional(),
|
|
1859
|
-
source: z7.string().min(1).optional()
|
|
1860
|
-
}).passthrough().safeParse(event.payload);
|
|
1861
|
-
if (!parsed.success)
|
|
2015
|
+
const usage = eventUsage(event);
|
|
2016
|
+
if (!usage)
|
|
1862
2017
|
return state;
|
|
1863
|
-
const source = parsed.data.source;
|
|
1864
2018
|
return {
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
cost: state.cost + (parsed.data.cost ?? 0),
|
|
1868
|
-
sources: source && !state.sources.includes(source) ? [...state.sources, source] : state.sources
|
|
2019
|
+
records: state.records + 1,
|
|
2020
|
+
usage: statedUsage(addUsage(state.records === 0 ? undefined : state.usage, usage))
|
|
1869
2021
|
};
|
|
1870
2022
|
}
|
|
1871
2023
|
});
|
|
1872
|
-
var RuntimeOutlineSchema =
|
|
1873
|
-
requests:
|
|
1874
|
-
seq:
|
|
1875
|
-
occurredAt:
|
|
1876
|
-
runId:
|
|
2024
|
+
var RuntimeOutlineSchema = z5.object({
|
|
2025
|
+
requests: z5.array(z5.object({
|
|
2026
|
+
seq: z5.int().positive(),
|
|
2027
|
+
occurredAt: z5.string(),
|
|
2028
|
+
runId: z5.string().optional()
|
|
1877
2029
|
}).strict())
|
|
1878
2030
|
}).strict();
|
|
1879
2031
|
var agentOutlineProjection = defineAgentProjection({
|
|
@@ -1884,7 +2036,7 @@ var agentOutlineProjection = defineAgentProjection({
|
|
|
1884
2036
|
fold: (state, event) => {
|
|
1885
2037
|
if (event.kind !== "provider/request")
|
|
1886
2038
|
return state;
|
|
1887
|
-
const payload =
|
|
2039
|
+
const payload = z5.looseObject({ runId: z5.string().optional() }).parse(event.payload);
|
|
1888
2040
|
return {
|
|
1889
2041
|
requests: [
|
|
1890
2042
|
...state.requests,
|
|
@@ -1925,38 +2077,38 @@ function defineAgentProtocol(config) {
|
|
|
1925
2077
|
};
|
|
1926
2078
|
}
|
|
1927
2079
|
// src/agent-runtime/schedule-contract.ts
|
|
1928
|
-
import { z as
|
|
1929
|
-
var AgentScheduleSchema =
|
|
1930
|
-
id:
|
|
1931
|
-
conversationId:
|
|
1932
|
-
kind:
|
|
1933
|
-
nextAt:
|
|
1934
|
-
intervalMs:
|
|
1935
|
-
timeZone:
|
|
1936
|
-
input:
|
|
1937
|
-
state:
|
|
1938
|
-
occurrence:
|
|
1939
|
-
attempts:
|
|
1940
|
-
retryAt:
|
|
1941
|
-
lastError:
|
|
1942
|
-
createdAt:
|
|
1943
|
-
updatedAt:
|
|
2080
|
+
import { z as z6 } from "zod";
|
|
2081
|
+
var AgentScheduleSchema = z6.object({
|
|
2082
|
+
id: z6.string().min(1),
|
|
2083
|
+
conversationId: z6.string().min(1),
|
|
2084
|
+
kind: z6.enum(["at", "after", "every"]),
|
|
2085
|
+
nextAt: z6.iso.datetime({ offset: true }),
|
|
2086
|
+
intervalMs: z6.int().positive().optional(),
|
|
2087
|
+
timeZone: z6.string().min(1).optional(),
|
|
2088
|
+
input: z6.json(),
|
|
2089
|
+
state: z6.enum(["scheduled", "cancelled", "completed", "failed"]),
|
|
2090
|
+
occurrence: z6.int().nonnegative(),
|
|
2091
|
+
attempts: z6.int().nonnegative().optional(),
|
|
2092
|
+
retryAt: z6.iso.datetime({ offset: true }).optional(),
|
|
2093
|
+
lastError: z6.string().optional(),
|
|
2094
|
+
createdAt: z6.iso.datetime({ offset: true }),
|
|
2095
|
+
updatedAt: z6.iso.datetime({ offset: true })
|
|
1944
2096
|
}).strict();
|
|
1945
|
-
var ScheduleRowSchema =
|
|
1946
|
-
id:
|
|
1947
|
-
conversation_id:
|
|
1948
|
-
kind:
|
|
1949
|
-
next_at:
|
|
1950
|
-
interval_ms:
|
|
1951
|
-
time_zone:
|
|
1952
|
-
input_payload:
|
|
1953
|
-
state:
|
|
1954
|
-
occurrence:
|
|
1955
|
-
attempts:
|
|
1956
|
-
retry_at:
|
|
1957
|
-
last_error:
|
|
1958
|
-
created_at:
|
|
1959
|
-
updated_at:
|
|
2097
|
+
var ScheduleRowSchema = z6.object({
|
|
2098
|
+
id: z6.string(),
|
|
2099
|
+
conversation_id: z6.string(),
|
|
2100
|
+
kind: z6.enum(["at", "after", "every"]),
|
|
2101
|
+
next_at: z6.string(),
|
|
2102
|
+
interval_ms: SqlIntegerSchema.pipe(z6.int().positive()).nullable(),
|
|
2103
|
+
time_zone: z6.string().nullable(),
|
|
2104
|
+
input_payload: z6.string(),
|
|
2105
|
+
state: z6.enum(["scheduled", "cancelled", "completed", "failed"]),
|
|
2106
|
+
occurrence: SqlIntegerSchema.pipe(z6.int().nonnegative()),
|
|
2107
|
+
attempts: SqlIntegerSchema.pipe(z6.int().nonnegative()),
|
|
2108
|
+
retry_at: z6.string().nullable(),
|
|
2109
|
+
last_error: z6.string().nullable(),
|
|
2110
|
+
created_at: z6.string(),
|
|
2111
|
+
updated_at: z6.string()
|
|
1960
2112
|
});
|
|
1961
2113
|
function parseSchedule(raw) {
|
|
1962
2114
|
const row = ScheduleRowSchema.parse(raw);
|
|
@@ -1977,89 +2129,94 @@ function parseSchedule(raw) {
|
|
|
1977
2129
|
updatedAt: row.updated_at
|
|
1978
2130
|
});
|
|
1979
2131
|
}
|
|
1980
|
-
var AgentScheduleDeliveryOutcomeSchema =
|
|
1981
|
-
|
|
1982
|
-
|
|
2132
|
+
var AgentScheduleDeliveryOutcomeSchema = z6.discriminatedUnion("status", [
|
|
2133
|
+
z6.object({ status: z6.literal("retry"), reason: z6.string().min(1) }).strict(),
|
|
2134
|
+
z6.object({ status: z6.literal("terminal"), reason: z6.string().min(1) }).strict()
|
|
1983
2135
|
]);
|
|
1984
2136
|
// src/agent-runtime/schedule-tools.ts
|
|
1985
|
-
import { z as
|
|
1986
|
-
var ScheduledOutputSchema =
|
|
1987
|
-
var
|
|
1988
|
-
|
|
2137
|
+
import { z as z7 } from "zod";
|
|
2138
|
+
var ScheduledOutputSchema = z7.object({ scheduleId: z7.string(), nextAt: z7.string() }).strict();
|
|
2139
|
+
var SCHEDULE_AFTER_DESCRIPTOR = defineAgentToolDescriptor({
|
|
2140
|
+
name: "schedule_after",
|
|
2141
|
+
description: "Schedule durable input after a relative delay.",
|
|
2142
|
+
identity: { serviceName: "agent-schedules", action: "after", method: "POST" },
|
|
2143
|
+
input: z7.object({
|
|
2144
|
+
input: z7.json(),
|
|
2145
|
+
afterMs: z7.int().positive()
|
|
2146
|
+
}).strict(),
|
|
2147
|
+
output: ScheduledOutputSchema,
|
|
2148
|
+
expose: ["AGENT"]
|
|
2149
|
+
});
|
|
2150
|
+
var SCHEDULE_AT_DESCRIPTOR = defineAgentToolDescriptor({
|
|
2151
|
+
name: "schedule_at",
|
|
2152
|
+
description: "Schedule durable input at an absolute timestamp with an explicit offset.",
|
|
2153
|
+
identity: { serviceName: "agent-schedules", action: "at", method: "POST" },
|
|
2154
|
+
input: z7.object({ input: z7.json(), at: z7.string().min(1) }).strict(),
|
|
2155
|
+
output: ScheduledOutputSchema,
|
|
2156
|
+
expose: ["AGENT"]
|
|
2157
|
+
});
|
|
2158
|
+
var SCHEDULE_EVERY_DESCRIPTOR = defineAgentToolDescriptor({
|
|
2159
|
+
name: "schedule_every",
|
|
2160
|
+
description: "Schedule recurring durable input in an explicit conversation timezone.",
|
|
2161
|
+
identity: { serviceName: "agent-schedules", action: "every", method: "POST" },
|
|
2162
|
+
input: z7.object({
|
|
2163
|
+
input: z7.json(),
|
|
2164
|
+
everyMs: z7.int().positive(),
|
|
2165
|
+
timeZone: z7.string().min(1)
|
|
2166
|
+
}).strict(),
|
|
2167
|
+
output: ScheduledOutputSchema,
|
|
2168
|
+
expose: ["AGENT"]
|
|
2169
|
+
});
|
|
2170
|
+
var SCHEDULE_LIST_DESCRIPTOR = defineAgentToolDescriptor({
|
|
2171
|
+
name: "schedule_list",
|
|
2172
|
+
description: "List the durable schedules of this conversation.",
|
|
2173
|
+
identity: { serviceName: "agent-schedules", action: "list", method: "GET" },
|
|
2174
|
+
input: z7.object({}).strict(),
|
|
2175
|
+
output: z7.object({ schedules: z7.array(z7.json()) }).strict(),
|
|
2176
|
+
expose: ["AGENT"]
|
|
2177
|
+
});
|
|
2178
|
+
var SCHEDULE_CANCEL_DESCRIPTOR = defineAgentToolDescriptor({
|
|
2179
|
+
name: "schedule_cancel",
|
|
2180
|
+
description: "Cancel one durable deferred-input schedule.",
|
|
2181
|
+
identity: { serviceName: "agent-schedules", action: "cancel", method: "POST" },
|
|
2182
|
+
input: z7.object({ scheduleId: z7.string().min(1) }).strict(),
|
|
2183
|
+
output: z7.object({ cancelled: z7.boolean() }).strict(),
|
|
2184
|
+
expose: ["AGENT"]
|
|
2185
|
+
});
|
|
2186
|
+
var AGENT_SCHEDULE_TOOL_DESCRIPTORS = Object.freeze([
|
|
2187
|
+
SCHEDULE_AFTER_DESCRIPTOR,
|
|
2188
|
+
SCHEDULE_AT_DESCRIPTOR,
|
|
2189
|
+
SCHEDULE_EVERY_DESCRIPTOR,
|
|
2190
|
+
SCHEDULE_LIST_DESCRIPTOR,
|
|
2191
|
+
SCHEDULE_CANCEL_DESCRIPTOR
|
|
2192
|
+
]);
|
|
2193
|
+
function createAgentScheduleTools({ service, run }) {
|
|
2194
|
+
const conversationId = conversationOfRun(run, "createAgentScheduleTools");
|
|
1989
2195
|
const schedule = async (request) => {
|
|
1990
|
-
const result = await service.scheduleInput(request);
|
|
2196
|
+
const result = await service.scheduleInput({ ...request, conversationId });
|
|
1991
2197
|
return { scheduleId: result.id, nextAt: result.nextAt };
|
|
1992
2198
|
};
|
|
1993
2199
|
return [
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
output: ScheduledOutputSchema,
|
|
2004
|
-
transports: ["AGENT"],
|
|
2005
|
-
handler: ({ input }) => schedule(input)
|
|
2006
|
-
}),
|
|
2007
|
-
defineAgentTool({
|
|
2008
|
-
name: "schedule_at",
|
|
2009
|
-
description: "Schedule durable input at an absolute timestamp with an explicit offset.",
|
|
2010
|
-
identity: { serviceName: "agent-schedules", action: "at", method: "POST" },
|
|
2011
|
-
input: z9.object({ conversationId: z9.string().min(1), input: z9.json(), at: z9.string().min(1) }).strict(),
|
|
2012
|
-
output: ScheduledOutputSchema,
|
|
2013
|
-
transports: ["AGENT"],
|
|
2014
|
-
handler: ({ input }) => schedule(input)
|
|
2015
|
-
}),
|
|
2016
|
-
defineAgentTool({
|
|
2017
|
-
name: "schedule_every",
|
|
2018
|
-
description: "Schedule recurring durable input in an explicit conversation timezone.",
|
|
2019
|
-
identity: { serviceName: "agent-schedules", action: "every", method: "POST" },
|
|
2020
|
-
input: z9.object({
|
|
2021
|
-
conversationId: z9.string().min(1),
|
|
2022
|
-
input: z9.json(),
|
|
2023
|
-
everyMs: z9.int().positive(),
|
|
2024
|
-
timeZone: z9.string().min(1)
|
|
2025
|
-
}).strict(),
|
|
2026
|
-
output: ScheduledOutputSchema,
|
|
2027
|
-
transports: ["AGENT"],
|
|
2028
|
-
handler: ({ input }) => schedule(input)
|
|
2029
|
-
}),
|
|
2030
|
-
defineAgentTool({
|
|
2031
|
-
name: "schedule_list",
|
|
2032
|
-
description: "List durable schedules for one conversation.",
|
|
2033
|
-
identity: { serviceName: "agent-schedules", action: "list", method: "GET" },
|
|
2034
|
-
input: ConversationInputSchema,
|
|
2035
|
-
output: z9.object({ schedules: z9.array(z9.json()) }).strict(),
|
|
2036
|
-
transports: ["AGENT"],
|
|
2037
|
-
handler: ({ input }) => ({
|
|
2038
|
-
schedules: [...service.listSchedules(input.conversationId)]
|
|
2039
|
-
})
|
|
2040
|
-
}),
|
|
2041
|
-
defineAgentTool({
|
|
2042
|
-
name: "schedule_cancel",
|
|
2043
|
-
description: "Cancel one durable deferred-input schedule.",
|
|
2044
|
-
identity: { serviceName: "agent-schedules", action: "cancel", method: "POST" },
|
|
2045
|
-
input: z9.object({ conversationId: z9.string().min(1), scheduleId: z9.string().min(1) }).strict(),
|
|
2046
|
-
output: z9.object({ cancelled: z9.boolean() }).strict(),
|
|
2047
|
-
transports: ["AGENT"],
|
|
2048
|
-
handler: async ({ input }) => ({
|
|
2049
|
-
cancelled: await service.cancelSchedule(input.conversationId, input.scheduleId)
|
|
2050
|
-
})
|
|
2051
|
-
})
|
|
2200
|
+
bindAgentTool(SCHEDULE_AFTER_DESCRIPTOR, ({ input }) => schedule(input)),
|
|
2201
|
+
bindAgentTool(SCHEDULE_AT_DESCRIPTOR, ({ input }) => schedule(input)),
|
|
2202
|
+
bindAgentTool(SCHEDULE_EVERY_DESCRIPTOR, ({ input }) => schedule(input)),
|
|
2203
|
+
bindAgentTool(SCHEDULE_LIST_DESCRIPTOR, async () => ({
|
|
2204
|
+
schedules: [...await service.listSchedules(conversationId)]
|
|
2205
|
+
})),
|
|
2206
|
+
bindAgentTool(SCHEDULE_CANCEL_DESCRIPTOR, async ({ input }) => ({
|
|
2207
|
+
cancelled: await service.cancelSchedule(conversationId, input.scheduleId)
|
|
2208
|
+
}))
|
|
2052
2209
|
];
|
|
2053
2210
|
}
|
|
2054
2211
|
// src/agent-runtime/schedules.ts
|
|
2055
|
-
import { z as
|
|
2212
|
+
import { z as z9 } from "zod";
|
|
2056
2213
|
|
|
2057
2214
|
// src/agent-runtime/schedule-dispatch.ts
|
|
2058
2215
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
2059
2216
|
|
|
2060
2217
|
// src/agent-runtime/schedule-records.ts
|
|
2061
2218
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
2062
|
-
import { z as
|
|
2219
|
+
import { z as z8 } from "zod";
|
|
2063
2220
|
function newSchedule(request, observedAt) {
|
|
2064
2221
|
const modes = [
|
|
2065
2222
|
request.at !== undefined,
|
|
@@ -2082,7 +2239,7 @@ function newSchedule(request, observedAt) {
|
|
|
2082
2239
|
const intervalMs = request.everyMs;
|
|
2083
2240
|
const delay = request.afterMs ?? request.everyMs;
|
|
2084
2241
|
assertPositiveSafeInteger("Schedule delay", delay);
|
|
2085
|
-
const nextAt = request.at ? new Date(
|
|
2242
|
+
const nextAt = request.at ? new Date(z8.iso.datetime({ offset: true }).parse(request.at)).toISOString() : new Date(observedAt.getTime() + (delay ?? 0)).toISOString();
|
|
2086
2243
|
const schedule = AgentScheduleSchema.parse({
|
|
2087
2244
|
id: randomUUID2(),
|
|
2088
2245
|
conversationId: request.conversationId,
|
|
@@ -2090,7 +2247,7 @@ function newSchedule(request, observedAt) {
|
|
|
2090
2247
|
nextAt,
|
|
2091
2248
|
...intervalMs !== undefined && { intervalMs },
|
|
2092
2249
|
...request.timeZone && { timeZone: request.timeZone },
|
|
2093
|
-
input:
|
|
2250
|
+
input: z8.json().parse(request.input),
|
|
2094
2251
|
state: "scheduled",
|
|
2095
2252
|
occurrence: 0,
|
|
2096
2253
|
createdAt: observedAt.toISOString(),
|
|
@@ -2098,14 +2255,30 @@ function newSchedule(request, observedAt) {
|
|
|
2098
2255
|
});
|
|
2099
2256
|
return schedule;
|
|
2100
2257
|
}
|
|
2101
|
-
async function insertSchedule(
|
|
2102
|
-
await
|
|
2103
|
-
|
|
2104
|
-
|
|
2258
|
+
async function insertSchedule(host, schedule, maxActivePerConversation) {
|
|
2259
|
+
await host.transaction(schedule.conversationId, async (scope) => {
|
|
2260
|
+
const active = z8.object({ active: SqlIntegerSchema }).parse(await scope.get(`
|
|
2261
|
+
SELECT COUNT(*) AS active FROM ${host.tables.schedules}
|
|
2262
|
+
WHERE conversation_id = ? AND state = 'scheduled'
|
|
2263
|
+
`, [schedule.conversationId])).active;
|
|
2264
|
+
if (active >= maxActivePerConversation)
|
|
2265
|
+
throw new TypeError(`The conversation already holds ${active} active schedules, the limit is ${maxActivePerConversation}`);
|
|
2266
|
+
await scope.run(`
|
|
2267
|
+
INSERT INTO ${host.tables.schedules} (
|
|
2105
2268
|
id, conversation_id, kind, next_at, interval_ms, time_zone,
|
|
2106
2269
|
input_payload, state, occurrence, created_at, updated_at
|
|
2107
2270
|
) VALUES (?, ?, ?, ?, ?, ?, ?, 'scheduled', 0, ?, ?)
|
|
2108
|
-
|
|
2271
|
+
`, [
|
|
2272
|
+
schedule.id,
|
|
2273
|
+
schedule.conversationId,
|
|
2274
|
+
schedule.kind,
|
|
2275
|
+
schedule.nextAt,
|
|
2276
|
+
schedule.intervalMs ?? null,
|
|
2277
|
+
schedule.timeZone ?? null,
|
|
2278
|
+
JSON.stringify(schedule.input),
|
|
2279
|
+
schedule.createdAt,
|
|
2280
|
+
schedule.updatedAt
|
|
2281
|
+
]);
|
|
2109
2282
|
await scope.appendEvent({
|
|
2110
2283
|
conversationId: schedule.conversationId,
|
|
2111
2284
|
kind: "schedule/set",
|
|
@@ -2117,12 +2290,12 @@ async function insertSchedule(sqlite, schedule) {
|
|
|
2117
2290
|
function holdsClaim(raw, firing, at) {
|
|
2118
2291
|
if (raw === null || raw === undefined)
|
|
2119
2292
|
return false;
|
|
2120
|
-
const row =
|
|
2121
|
-
state:
|
|
2122
|
-
claim_owner:
|
|
2123
|
-
claim_until:
|
|
2124
|
-
occurrence:
|
|
2125
|
-
next_at:
|
|
2293
|
+
const row = z8.object({
|
|
2294
|
+
state: z8.string(),
|
|
2295
|
+
claim_owner: z8.string().nullable(),
|
|
2296
|
+
claim_until: z8.string().nullable(),
|
|
2297
|
+
occurrence: SqlIntegerSchema,
|
|
2298
|
+
next_at: z8.string()
|
|
2126
2299
|
}).parse(raw);
|
|
2127
2300
|
return row.state === "scheduled" && row.claim_owner === firing.owner && row.claim_until !== null && row.claim_until > at && row.occurrence === firing.schedule.occurrence && row.next_at === firing.schedule.nextAt;
|
|
2128
2301
|
}
|
|
@@ -2132,27 +2305,27 @@ function nextSlot(schedule, observedAt, intervalMs) {
|
|
|
2132
2305
|
const slots = Math.max(1, Math.floor((observedAt.getTime() - due) / intervalMs) + 1);
|
|
2133
2306
|
return new Date(due + slots * intervalMs).toISOString();
|
|
2134
2307
|
}
|
|
2135
|
-
async function recordDispatchFailure(
|
|
2308
|
+
async function recordDispatchFailure(host, firing, reason, maxAttempts, explicitlyTerminal = false) {
|
|
2136
2309
|
const { schedule, occurrence } = firing;
|
|
2137
2310
|
const characters = Array.from(reason);
|
|
2138
2311
|
const message = characters.length > MAX_FAILURE_REASON ? `${characters.slice(0, MAX_FAILURE_REASON).join("")}…` : reason;
|
|
2139
|
-
await
|
|
2312
|
+
await host.transaction(schedule.conversationId, async (scope) => {
|
|
2140
2313
|
const at = firing.now().toISOString();
|
|
2141
|
-
const raw = scope.
|
|
2314
|
+
const raw = await scope.get(`
|
|
2142
2315
|
SELECT state, claim_owner, claim_until, occurrence, next_at
|
|
2143
|
-
FROM
|
|
2144
|
-
|
|
2316
|
+
FROM ${host.tables.schedules} WHERE id = ?
|
|
2317
|
+
`, [schedule.id]);
|
|
2145
2318
|
if (!holdsClaim(raw, firing, at))
|
|
2146
2319
|
return;
|
|
2147
2320
|
const attempts = Math.min((schedule.attempts ?? 0) + 1, Number.MAX_SAFE_INTEGER);
|
|
2148
2321
|
const exhausted = !explicitlyTerminal && attempts >= maxAttempts;
|
|
2149
2322
|
if (exhausted && schedule.kind === "every" && schedule.intervalMs) {
|
|
2150
2323
|
const nextAt = nextSlot(schedule, firing.now(), schedule.intervalMs);
|
|
2151
|
-
scope.
|
|
2152
|
-
UPDATE
|
|
2324
|
+
await scope.run(`
|
|
2325
|
+
UPDATE ${host.tables.schedules}
|
|
2153
2326
|
SET state = 'scheduled', occurrence = ?, next_at = ?, retry_at = NULL, attempts = 0,
|
|
2154
2327
|
last_error = ?, claim_owner = NULL, claim_until = NULL, updated_at = ? WHERE id = ?
|
|
2155
|
-
|
|
2328
|
+
`, [occurrence, nextAt, message, at, schedule.id]);
|
|
2156
2329
|
await scope.appendEvent({
|
|
2157
2330
|
conversationId: schedule.conversationId,
|
|
2158
2331
|
kind: "schedule/failed",
|
|
@@ -2172,11 +2345,11 @@ async function recordDispatchFailure(sqlite, firing, reason, maxAttempts, explic
|
|
|
2172
2345
|
}
|
|
2173
2346
|
const terminal = explicitlyTerminal || exhausted;
|
|
2174
2347
|
const retryAt = terminal ? null : new Date(new Date(at).getTime() + Math.min(60000, 1000 * 2 ** Math.min(attempts - 1, 6))).toISOString();
|
|
2175
|
-
scope.
|
|
2176
|
-
UPDATE
|
|
2348
|
+
await scope.run(`
|
|
2349
|
+
UPDATE ${host.tables.schedules}
|
|
2177
2350
|
SET state = ?, retry_at = ?, attempts = ?, last_error = ?,
|
|
2178
2351
|
claim_owner = NULL, claim_until = NULL, updated_at = ? WHERE id = ?
|
|
2179
|
-
|
|
2352
|
+
`, [terminal ? "failed" : "scheduled", retryAt, attempts, message, at, schedule.id]);
|
|
2180
2353
|
await scope.appendEvent({
|
|
2181
2354
|
conversationId: schedule.conversationId,
|
|
2182
2355
|
kind: "schedule/failed",
|
|
@@ -2185,25 +2358,25 @@ async function recordDispatchFailure(sqlite, firing, reason, maxAttempts, explic
|
|
|
2185
2358
|
});
|
|
2186
2359
|
});
|
|
2187
2360
|
}
|
|
2188
|
-
async function settleFiring(
|
|
2361
|
+
async function settleFiring(host, firing, lateByMs) {
|
|
2189
2362
|
const { schedule, occurrence } = firing;
|
|
2190
2363
|
const state = schedule.kind === "every" ? "scheduled" : "completed";
|
|
2191
|
-
await
|
|
2364
|
+
await host.transaction(schedule.conversationId, async (scope) => {
|
|
2192
2365
|
const observedAt = firing.now();
|
|
2193
2366
|
const at = observedAt.toISOString();
|
|
2194
2367
|
const nextAt = schedule.kind === "every" && schedule.intervalMs ? nextSlot(schedule, observedAt, schedule.intervalMs) : schedule.nextAt;
|
|
2195
|
-
const raw = scope.
|
|
2368
|
+
const raw = await scope.get(`
|
|
2196
2369
|
SELECT state, claim_owner, claim_until, occurrence, next_at
|
|
2197
|
-
FROM
|
|
2198
|
-
|
|
2370
|
+
FROM ${host.tables.schedules} WHERE id = ?
|
|
2371
|
+
`, [schedule.id]);
|
|
2199
2372
|
if (!holdsClaim(raw, firing, at))
|
|
2200
2373
|
return;
|
|
2201
|
-
scope.
|
|
2202
|
-
UPDATE
|
|
2374
|
+
await scope.run(`
|
|
2375
|
+
UPDATE ${host.tables.schedules}
|
|
2203
2376
|
SET state = ?, occurrence = ?, next_at = ?, updated_at = ?,
|
|
2204
2377
|
claim_owner = NULL, claim_until = NULL, retry_at = NULL, attempts = 0, last_error = NULL
|
|
2205
2378
|
WHERE id = ?
|
|
2206
|
-
|
|
2379
|
+
`, [state, occurrence, nextAt, at, schedule.id]);
|
|
2207
2380
|
if (lateByMs > 0) {
|
|
2208
2381
|
await scope.appendEvent({
|
|
2209
2382
|
conversationId: schedule.conversationId,
|
|
@@ -2220,26 +2393,30 @@ async function settleFiring(sqlite, firing, lateByMs) {
|
|
|
2220
2393
|
});
|
|
2221
2394
|
});
|
|
2222
2395
|
}
|
|
2223
|
-
function claimSchedule(
|
|
2224
|
-
return
|
|
2396
|
+
function claimSchedule(host, owner, schedule, now) {
|
|
2397
|
+
return host.transaction(schedule.conversationId, async (scope) => {
|
|
2225
2398
|
const observedAt = now();
|
|
2226
2399
|
const at = observedAt.toISOString();
|
|
2227
2400
|
const until = new Date(observedAt.getTime() + 60000).toISOString();
|
|
2228
|
-
const raw = scope.
|
|
2229
|
-
SELECT occurrence, next_at, attempts FROM
|
|
2401
|
+
const raw = await scope.get(`
|
|
2402
|
+
SELECT occurrence, next_at, attempts FROM ${host.tables.schedules}
|
|
2230
2403
|
WHERE id = ? AND state = 'scheduled' AND eligible_at <= ?
|
|
2231
|
-
|
|
2404
|
+
`, [schedule.id, at]);
|
|
2232
2405
|
if (raw === null || raw === undefined)
|
|
2233
2406
|
return false;
|
|
2234
|
-
const row =
|
|
2407
|
+
const row = z8.object({
|
|
2408
|
+
occurrence: SqlIntegerSchema,
|
|
2409
|
+
next_at: z8.string(),
|
|
2410
|
+
attempts: SqlIntegerSchema
|
|
2411
|
+
}).parse(raw);
|
|
2235
2412
|
if (row.attempts !== (schedule.attempts ?? 0))
|
|
2236
2413
|
return false;
|
|
2237
2414
|
if (row.occurrence !== schedule.occurrence || row.next_at !== schedule.nextAt)
|
|
2238
2415
|
return false;
|
|
2239
|
-
scope.
|
|
2240
|
-
UPDATE
|
|
2416
|
+
await scope.run(`
|
|
2417
|
+
UPDATE ${host.tables.schedules}
|
|
2241
2418
|
SET claim_owner = ?, claim_until = ?, updated_at = ? WHERE id = ?
|
|
2242
|
-
|
|
2419
|
+
`, [owner, until, at, schedule.id]);
|
|
2243
2420
|
return true;
|
|
2244
2421
|
});
|
|
2245
2422
|
}
|
|
@@ -2249,7 +2426,7 @@ async function dispatchSchedule(context, schedule) {
|
|
|
2249
2426
|
if (context.signal.aborted)
|
|
2250
2427
|
return;
|
|
2251
2428
|
const owner = randomUUID3();
|
|
2252
|
-
if (!await claimSchedule(context.
|
|
2429
|
+
if (!await claimSchedule(context.host, owner, schedule, context.now))
|
|
2253
2430
|
return;
|
|
2254
2431
|
const observedAt = context.now();
|
|
2255
2432
|
const occurrence = schedule.occurrence + 1;
|
|
@@ -2282,13 +2459,13 @@ async function dispatchSchedule(context, schedule) {
|
|
|
2282
2459
|
const firing = { schedule, occurrence, now: context.now, owner };
|
|
2283
2460
|
const failure = AgentScheduleDeliveryOutcomeSchema.safeParse(outcome);
|
|
2284
2461
|
if (!failure.success) {
|
|
2285
|
-
await settleFiring(context.
|
|
2462
|
+
await settleFiring(context.host, firing, lateByMs);
|
|
2286
2463
|
} else {
|
|
2287
|
-
await recordDispatchFailure(context.
|
|
2464
|
+
await recordDispatchFailure(context.host, firing, failure.data.reason, context.maxAttempts, failure.data.status === "terminal");
|
|
2288
2465
|
}
|
|
2289
2466
|
} catch (error) {
|
|
2290
2467
|
if (!context.signal.aborted) {
|
|
2291
|
-
await recordDispatchFailure(context.
|
|
2468
|
+
await recordDispatchFailure(context.host, { schedule, occurrence, now: context.now, owner }, error instanceof Error ? error.message : String(error), context.maxAttempts);
|
|
2292
2469
|
}
|
|
2293
2470
|
} finally {
|
|
2294
2471
|
context.clearTimer(timer);
|
|
@@ -2297,17 +2474,40 @@ async function dispatchSchedule(context, schedule) {
|
|
|
2297
2474
|
}
|
|
2298
2475
|
|
|
2299
2476
|
// src/agent-runtime/schedules.ts
|
|
2477
|
+
function serviceClock(now, setTimer, clearTimer) {
|
|
2478
|
+
return {
|
|
2479
|
+
now: () => now().getTime(),
|
|
2480
|
+
schedule(callback, delayMs) {
|
|
2481
|
+
const handle = setTimer(callback, delayMs);
|
|
2482
|
+
return { cancel: () => clearTimer(handle) };
|
|
2483
|
+
}
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2300
2486
|
function createAgentScheduleService(input) {
|
|
2301
|
-
const
|
|
2487
|
+
for (const name of ["maxActivePerConversation", "minIntervalMs"]) {
|
|
2488
|
+
if (input[name] === undefined)
|
|
2489
|
+
throw new TypeError(`createAgentScheduleService requires ${name}`);
|
|
2490
|
+
assertPositiveSafeInteger(name, input[name]);
|
|
2491
|
+
}
|
|
2492
|
+
const limits = {
|
|
2493
|
+
maxActivePerConversation: input.maxActivePerConversation,
|
|
2494
|
+
minIntervalMs: input.minIntervalMs
|
|
2495
|
+
};
|
|
2496
|
+
const maxAttempts = z9.number().int().min(1).parse(input.maxAttempts ?? 1000);
|
|
2302
2497
|
const now = input.now ?? (() => new Date);
|
|
2303
|
-
const
|
|
2498
|
+
const host = input.host;
|
|
2304
2499
|
const setTimer = input.setTimer ?? ((callback, delay) => setTimeout(callback, delay));
|
|
2305
2500
|
const clearTimer = input.clearTimer ?? clearTimeout;
|
|
2306
2501
|
const onError = input.onError ?? ((error) => {
|
|
2307
2502
|
console.error("[stitchkit] agent schedule tick failed", error);
|
|
2308
2503
|
});
|
|
2309
2504
|
const lifecycle = new AbortController;
|
|
2505
|
+
const clock = serviceClock(now, setTimer, clearTimer);
|
|
2310
2506
|
let timer;
|
|
2507
|
+
const cancelTimer = () => {
|
|
2508
|
+
timer?.cancel();
|
|
2509
|
+
timer = undefined;
|
|
2510
|
+
};
|
|
2311
2511
|
let ticking;
|
|
2312
2512
|
let recoveryAt = 0;
|
|
2313
2513
|
let storageFailures = 0;
|
|
@@ -2316,47 +2516,49 @@ function createAgentScheduleService(input) {
|
|
|
2316
2516
|
recoveryAt = now().getTime() + Math.min(60000, 1000 * 2 ** Math.min(storageFailures - 1, 6));
|
|
2317
2517
|
onError(error);
|
|
2318
2518
|
};
|
|
2319
|
-
const listSchedules = (conversationId) =>
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
if (
|
|
2325
|
-
|
|
2326
|
-
|
|
2519
|
+
const listSchedules = (conversationId) => host.read(async (session) => (await session.all(`SELECT * FROM ${host.tables.schedules} WHERE conversation_id = ? ORDER BY created_at, id`, [conversationId])).map(parseSchedule));
|
|
2520
|
+
let armGeneration = 0;
|
|
2521
|
+
const nextDueAt = () => host.read(async (session) => {
|
|
2522
|
+
const raw = await session.get(`SELECT eligible_at FROM ${host.tables.schedules}
|
|
2523
|
+
WHERE state = 'scheduled' ORDER BY eligible_at, id LIMIT 1`);
|
|
2524
|
+
if (raw === undefined)
|
|
2525
|
+
return;
|
|
2526
|
+
return new Date(z9.object({ eligible_at: z9.string() }).parse(raw).eligible_at).getTime();
|
|
2527
|
+
});
|
|
2528
|
+
const arm = async () => {
|
|
2529
|
+
cancelTimer();
|
|
2327
2530
|
if (lifecycle.signal.aborted || ticking)
|
|
2328
2531
|
return;
|
|
2532
|
+
const generation = ++armGeneration;
|
|
2329
2533
|
let dueAt;
|
|
2330
2534
|
if (recoveryAt > now().getTime()) {
|
|
2331
2535
|
dueAt = recoveryAt;
|
|
2332
2536
|
} else {
|
|
2333
2537
|
try {
|
|
2334
|
-
const
|
|
2335
|
-
|
|
2336
|
-
WHERE state = 'scheduled' ORDER BY eligible_at, id LIMIT 1
|
|
2337
|
-
`).get();
|
|
2338
|
-
if (raw === null || raw === undefined)
|
|
2538
|
+
const next = await nextDueAt();
|
|
2539
|
+
if (next === undefined)
|
|
2339
2540
|
return;
|
|
2340
|
-
dueAt =
|
|
2541
|
+
dueAt = next;
|
|
2341
2542
|
} catch (error) {
|
|
2342
2543
|
reportStorageFailure(error);
|
|
2343
2544
|
dueAt = recoveryAt;
|
|
2344
2545
|
}
|
|
2345
2546
|
}
|
|
2346
|
-
|
|
2547
|
+
if (generation !== armGeneration || lifecycle.signal.aborted || ticking)
|
|
2548
|
+
return;
|
|
2549
|
+
cancelTimer();
|
|
2550
|
+
timer = scheduleAt(clock, dueAt, () => {
|
|
2347
2551
|
timer = undefined;
|
|
2348
2552
|
tick();
|
|
2349
|
-
}
|
|
2553
|
+
});
|
|
2350
2554
|
};
|
|
2351
2555
|
const runTick = async () => {
|
|
2352
2556
|
if (lifecycle.signal.aborted || now().getTime() < recoveryAt)
|
|
2353
2557
|
return;
|
|
2354
|
-
const due =
|
|
2355
|
-
|
|
2356
|
-
WHERE state = 'scheduled' AND eligible_at <= ? ORDER BY eligible_at, id LIMIT 32
|
|
2357
|
-
`).all(now().toISOString()).map(parseSchedule);
|
|
2558
|
+
const due = await host.read(async (session) => (await session.all(`SELECT * FROM ${host.tables.schedules}
|
|
2559
|
+
WHERE state = 'scheduled' AND eligible_at <= ? ORDER BY eligible_at, id LIMIT 32`, [now().toISOString()])).map(parseSchedule));
|
|
2358
2560
|
const results = await Promise.allSettled(due.map((schedule) => dispatchSchedule({
|
|
2359
|
-
|
|
2561
|
+
host,
|
|
2360
2562
|
dispatch: input.dispatch,
|
|
2361
2563
|
now,
|
|
2362
2564
|
setTimer,
|
|
@@ -2373,36 +2575,39 @@ function createAgentScheduleService(input) {
|
|
|
2373
2575
|
const tick = () => {
|
|
2374
2576
|
if (ticking)
|
|
2375
2577
|
return ticking;
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2578
|
+
cancelTimer();
|
|
2579
|
+
const current = (async () => {
|
|
2580
|
+
try {
|
|
2581
|
+
await runTick();
|
|
2582
|
+
} catch (error) {
|
|
2583
|
+
reportStorageFailure(error);
|
|
2584
|
+
} finally {
|
|
2585
|
+
ticking = undefined;
|
|
2586
|
+
}
|
|
2587
|
+
await arm();
|
|
2588
|
+
})();
|
|
2589
|
+
ticking = current;
|
|
2590
|
+
return current;
|
|
2384
2591
|
};
|
|
2385
2592
|
const scheduleInput = async (request) => {
|
|
2386
2593
|
const schedule = newSchedule(request, now());
|
|
2387
|
-
|
|
2388
|
-
|
|
2594
|
+
if (schedule.intervalMs !== undefined && schedule.intervalMs < limits.minIntervalMs)
|
|
2595
|
+
throw new TypeError(`A repeating schedule fires at most every ${limits.minIntervalMs} ms, received everyMs ${schedule.intervalMs}`);
|
|
2596
|
+
await insertSchedule(host, schedule, limits.maxActivePerConversation);
|
|
2597
|
+
await arm();
|
|
2389
2598
|
return schedule;
|
|
2390
2599
|
};
|
|
2391
2600
|
const cancelSchedule = async (conversationId, id) => {
|
|
2392
2601
|
const observedAt = now().toISOString();
|
|
2393
|
-
const changed = await
|
|
2394
|
-
const raw = scope.
|
|
2395
|
-
|
|
2396
|
-
`).get(id, conversationId);
|
|
2397
|
-
if (raw === null || raw === undefined)
|
|
2602
|
+
const changed = await host.transaction(conversationId, async (scope) => {
|
|
2603
|
+
const raw = await scope.get(`SELECT state FROM ${host.tables.schedules} WHERE id = ? AND conversation_id = ?`, [id, conversationId]);
|
|
2604
|
+
if (raw === undefined)
|
|
2398
2605
|
return false;
|
|
2399
|
-
if (
|
|
2606
|
+
if (z9.object({ state: z9.string() }).parse(raw).state !== "scheduled")
|
|
2400
2607
|
return false;
|
|
2401
|
-
scope.
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
WHERE id = ? AND conversation_id = ?
|
|
2405
|
-
`).run(observedAt, id, conversationId);
|
|
2608
|
+
await scope.run(`UPDATE ${host.tables.schedules}
|
|
2609
|
+
SET state = 'cancelled', updated_at = ?, claim_owner = NULL, claim_until = NULL
|
|
2610
|
+
WHERE id = ? AND conversation_id = ?`, [observedAt, id, conversationId]);
|
|
2406
2611
|
await scope.appendEvent({
|
|
2407
2612
|
conversationId,
|
|
2408
2613
|
kind: "schedule/cancelled",
|
|
@@ -2412,7 +2617,7 @@ function createAgentScheduleService(input) {
|
|
|
2412
2617
|
return true;
|
|
2413
2618
|
});
|
|
2414
2619
|
if (changed)
|
|
2415
|
-
arm();
|
|
2620
|
+
await arm();
|
|
2416
2621
|
return changed;
|
|
2417
2622
|
};
|
|
2418
2623
|
return {
|
|
@@ -2423,56 +2628,63 @@ function createAgentScheduleService(input) {
|
|
|
2423
2628
|
start: arm,
|
|
2424
2629
|
close() {
|
|
2425
2630
|
lifecycle.abort();
|
|
2426
|
-
|
|
2427
|
-
clearTimer(timer);
|
|
2428
|
-
timer = undefined;
|
|
2631
|
+
cancelTimer();
|
|
2429
2632
|
}
|
|
2430
2633
|
};
|
|
2431
2634
|
}
|
|
2432
2635
|
// src/agent-runtime/spill.ts
|
|
2433
2636
|
import { createHash, randomUUID as randomUUID4 } from "node:crypto";
|
|
2434
|
-
import { z as
|
|
2435
|
-
var SpillRowSchema =
|
|
2436
|
-
payload:
|
|
2437
|
-
bytes:
|
|
2438
|
-
authorization_payload:
|
|
2637
|
+
import { z as z10 } from "zod";
|
|
2638
|
+
var SpillRowSchema = z10.object({
|
|
2639
|
+
payload: z10.instanceof(Uint8Array),
|
|
2640
|
+
bytes: SqlIntegerSchema.pipe(z10.int().nonnegative()),
|
|
2641
|
+
authorization_payload: z10.string().nullable()
|
|
2439
2642
|
});
|
|
2440
|
-
var SpillMetadataRowSchema =
|
|
2441
|
-
reference_id:
|
|
2442
|
-
bytes:
|
|
2443
|
-
created_at:
|
|
2643
|
+
var SpillMetadataRowSchema = z10.object({
|
|
2644
|
+
reference_id: z10.string(),
|
|
2645
|
+
bytes: SqlIntegerSchema.pipe(z10.int().nonnegative()),
|
|
2646
|
+
created_at: z10.string()
|
|
2444
2647
|
});
|
|
2445
2648
|
function decodeAuthorization(value) {
|
|
2446
2649
|
if (value === null)
|
|
2447
2650
|
return;
|
|
2448
|
-
return JSON.parse(value);
|
|
2651
|
+
return AgentCodingToolAuthorizationSchema2.parse(JSON.parse(value));
|
|
2449
2652
|
}
|
|
2450
|
-
function
|
|
2653
|
+
function createAgentSpillStore(input) {
|
|
2451
2654
|
const now = input.now ?? (() => new Date);
|
|
2452
|
-
const
|
|
2453
|
-
const
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
`).get(reference, input.conversationId);
|
|
2459
|
-
if (raw === null || raw === undefined)
|
|
2655
|
+
const { host } = input;
|
|
2656
|
+
const spills = host.tables.spills;
|
|
2657
|
+
const rowFor = async (reference) => {
|
|
2658
|
+
const raw = await host.read((session) => session.get(`SELECT payload, bytes, authorization_payload FROM ${spills}
|
|
2659
|
+
WHERE reference_id = ? AND conversation_id = ?`, [reference, input.conversationId]));
|
|
2660
|
+
if (raw === undefined)
|
|
2460
2661
|
refuseUnknownSpillReference(reference);
|
|
2461
2662
|
return SpillRowSchema.parse(raw);
|
|
2462
2663
|
};
|
|
2463
|
-
const authorization = (reference) => decodeAuthorization(rowFor(reference).authorization_payload);
|
|
2664
|
+
const authorization = async (reference) => decodeAuthorization((await rowFor(reference)).authorization_payload);
|
|
2464
2665
|
const write = async (request) => {
|
|
2666
|
+
const spillAuthorization = request.authorization === undefined ? undefined : AgentCodingToolAuthorizationSchema2.parse(request.authorization);
|
|
2465
2667
|
const reference = randomUUID4();
|
|
2466
2668
|
const createdAt = now();
|
|
2467
2669
|
const expiresAt = input.retentionMs ? new Date(createdAt.getTime() + input.retentionMs).toISOString() : null;
|
|
2468
2670
|
const sha256 = createHash("sha256").update(request.data).digest("hex");
|
|
2469
|
-
await
|
|
2470
|
-
scope.
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2671
|
+
await host.transaction(input.conversationId, async (scope) => {
|
|
2672
|
+
await scope.run(`INSERT INTO ${spills} (
|
|
2673
|
+
reference_id, conversation_id, run_id, tool_call_id, media_type,
|
|
2674
|
+
bytes, sha256, created_at, expires_at, payload, authorization_payload
|
|
2675
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
2676
|
+
reference,
|
|
2677
|
+
input.conversationId,
|
|
2678
|
+
input.runId ?? null,
|
|
2679
|
+
request.toolCallId ?? null,
|
|
2680
|
+
request.mediaType,
|
|
2681
|
+
request.data.byteLength,
|
|
2682
|
+
sha256,
|
|
2683
|
+
createdAt.toISOString(),
|
|
2684
|
+
expiresAt,
|
|
2685
|
+
request.data,
|
|
2686
|
+
spillAuthorization !== undefined ? JSON.stringify(spillAuthorization) : null
|
|
2687
|
+
]);
|
|
2476
2688
|
await scope.appendEvent({
|
|
2477
2689
|
conversationId: input.conversationId,
|
|
2478
2690
|
kind: "spill/created",
|
|
@@ -2483,17 +2695,16 @@ function createSqliteAgentSpillStore(input) {
|
|
|
2483
2695
|
return { reference };
|
|
2484
2696
|
};
|
|
2485
2697
|
const read = async (request) => {
|
|
2486
|
-
const row = rowFor(request.reference);
|
|
2698
|
+
const row = await rowFor(request.reference);
|
|
2699
|
+
const rowAuthorization = decodeAuthorization(row.authorization_payload);
|
|
2487
2700
|
return {
|
|
2488
2701
|
data: row.payload.slice(request.offset, request.offset + request.maxBytes),
|
|
2489
2702
|
totalBytes: row.bytes,
|
|
2490
|
-
...
|
|
2491
|
-
authorization: decodeAuthorization(row.authorization_payload)
|
|
2492
|
-
}
|
|
2703
|
+
...rowAuthorization !== undefined && { authorization: rowAuthorization }
|
|
2493
2704
|
};
|
|
2494
2705
|
};
|
|
2495
|
-
const search = (request) => {
|
|
2496
|
-
const row = rowFor(request.reference);
|
|
2706
|
+
const search = async (request) => {
|
|
2707
|
+
const row = await rowFor(request.reference);
|
|
2497
2708
|
const matches = [];
|
|
2498
2709
|
new TextDecoder("utf-8", { fatal: true }).decode(row.payload).split(`
|
|
2499
2710
|
`).forEach((text, index) => {
|
|
@@ -2504,39 +2715,92 @@ function createSqliteAgentSpillStore(input) {
|
|
|
2504
2715
|
return matches;
|
|
2505
2716
|
};
|
|
2506
2717
|
const cleanup = async () => {
|
|
2507
|
-
const expired =
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
ORDER BY created_at, reference_id
|
|
2512
|
-
`).all(input.conversationId, now().toISOString()).map((row) => SpillMetadataRowSchema.parse(row));
|
|
2718
|
+
const expired = (await host.read((session) => session.all(`SELECT reference_id, bytes, created_at FROM ${spills}
|
|
2719
|
+
WHERE conversation_id = ? AND expires_at IS NOT NULL AND expires_at <= ?
|
|
2720
|
+
ORDER BY created_at, reference_id`, [input.conversationId, now().toISOString()]))).map((row) => SpillMetadataRowSchema.parse(row));
|
|
2721
|
+
let deleted = 0;
|
|
2513
2722
|
let bytes = 0;
|
|
2514
2723
|
for (const spill of expired) {
|
|
2515
|
-
await
|
|
2516
|
-
scope.
|
|
2724
|
+
const removed = await host.transaction(input.conversationId, async (scope) => {
|
|
2725
|
+
const existing = await scope.get(`SELECT reference_id FROM ${spills} WHERE reference_id = ? AND conversation_id = ?`, [spill.reference_id, input.conversationId]);
|
|
2726
|
+
if (existing === undefined)
|
|
2727
|
+
return false;
|
|
2728
|
+
await scope.run(`DELETE FROM ${spills} WHERE reference_id = ? AND conversation_id = ?`, [spill.reference_id, input.conversationId]);
|
|
2517
2729
|
await scope.appendEvent({
|
|
2518
2730
|
conversationId: input.conversationId,
|
|
2519
2731
|
kind: "spill/deleted",
|
|
2520
2732
|
payload: { reference: spill.reference_id, bytes: spill.bytes }
|
|
2521
2733
|
});
|
|
2734
|
+
return true;
|
|
2522
2735
|
});
|
|
2523
|
-
|
|
2736
|
+
if (removed) {
|
|
2737
|
+
deleted += 1;
|
|
2738
|
+
bytes += spill.bytes;
|
|
2739
|
+
}
|
|
2524
2740
|
}
|
|
2525
|
-
return { deleted
|
|
2741
|
+
return { deleted, bytes };
|
|
2526
2742
|
};
|
|
2527
2743
|
return { authorization, write, read, search, cleanup };
|
|
2528
2744
|
}
|
|
2529
2745
|
// src/agent-runtime/state-tools.ts
|
|
2530
|
-
import { z as
|
|
2531
|
-
var GoalSchema =
|
|
2532
|
-
objective:
|
|
2533
|
-
status:
|
|
2746
|
+
import { z as z11 } from "zod";
|
|
2747
|
+
var GoalSchema = z11.object({
|
|
2748
|
+
objective: z11.string().min(1),
|
|
2749
|
+
status: z11.enum(["active", "complete", "blocked"])
|
|
2534
2750
|
}).strict();
|
|
2535
|
-
var TodoItemSchema =
|
|
2536
|
-
step:
|
|
2537
|
-
status:
|
|
2751
|
+
var TodoItemSchema = z11.object({
|
|
2752
|
+
step: z11.string().min(1),
|
|
2753
|
+
status: z11.enum(["pending", "in_progress", "completed"])
|
|
2538
2754
|
}).strict();
|
|
2539
|
-
|
|
2755
|
+
var TodoOutputSchema = z11.object({ items: z11.array(TodoItemSchema) }).strict();
|
|
2756
|
+
var CREATE_GOAL_DESCRIPTOR = defineAgentToolDescriptor({
|
|
2757
|
+
name: "create_goal",
|
|
2758
|
+
description: "Create the durable objective for this conversation.",
|
|
2759
|
+
identity: { serviceName: "agent-state", action: "create-goal", method: "POST" },
|
|
2760
|
+
input: z11.object({ objective: z11.string().min(1) }).strict(),
|
|
2761
|
+
output: GoalSchema,
|
|
2762
|
+
expose: ["AGENT"]
|
|
2763
|
+
});
|
|
2764
|
+
var UPDATE_GOAL_DESCRIPTOR = defineAgentToolDescriptor({
|
|
2765
|
+
name: "update_goal",
|
|
2766
|
+
description: "Update the durable objective or lifecycle status.",
|
|
2767
|
+
identity: { serviceName: "agent-state", action: "update-goal", method: "POST" },
|
|
2768
|
+
input: z11.object({
|
|
2769
|
+
objective: z11.string().min(1).optional(),
|
|
2770
|
+
status: z11.enum(["active", "complete", "blocked"]).optional()
|
|
2771
|
+
}).strict().refine((request) => request.objective !== undefined || request.status !== undefined, {
|
|
2772
|
+
message: "At least one goal field must be supplied"
|
|
2773
|
+
}),
|
|
2774
|
+
output: GoalSchema,
|
|
2775
|
+
expose: ["AGENT"]
|
|
2776
|
+
});
|
|
2777
|
+
var GET_GOAL_DESCRIPTOR = defineAgentToolDescriptor({
|
|
2778
|
+
name: "get_goal",
|
|
2779
|
+
description: "Read the durable objective for this conversation.",
|
|
2780
|
+
identity: { serviceName: "agent-state", action: "get-goal", method: "GET" },
|
|
2781
|
+
input: z11.object({}).strict(),
|
|
2782
|
+
output: z11.object({ goal: GoalSchema.optional() }).strict(),
|
|
2783
|
+
expose: ["AGENT"]
|
|
2784
|
+
});
|
|
2785
|
+
var TODO_WRITE_DESCRIPTOR = defineAgentToolDescriptor({
|
|
2786
|
+
name: "todo_write",
|
|
2787
|
+
description: "Replace the durable ordered work plan for this conversation.",
|
|
2788
|
+
identity: { serviceName: "agent-state", action: "write-todo", method: "POST" },
|
|
2789
|
+
input: TodoOutputSchema,
|
|
2790
|
+
output: TodoOutputSchema,
|
|
2791
|
+
expose: ["AGENT"]
|
|
2792
|
+
});
|
|
2793
|
+
var AGENT_STATE_TOOL_DESCRIPTORS = Object.freeze([
|
|
2794
|
+
CREATE_GOAL_DESCRIPTOR,
|
|
2795
|
+
UPDATE_GOAL_DESCRIPTOR,
|
|
2796
|
+
GET_GOAL_DESCRIPTOR,
|
|
2797
|
+
TODO_WRITE_DESCRIPTOR
|
|
2798
|
+
]);
|
|
2799
|
+
function createAgentStateTools(config) {
|
|
2800
|
+
const input = {
|
|
2801
|
+
state: config.state,
|
|
2802
|
+
conversationId: conversationOfRun(config.run, "createAgentStateTools")
|
|
2803
|
+
};
|
|
2540
2804
|
const writeGoal = async (value) => {
|
|
2541
2805
|
const stored = await input.state.set({
|
|
2542
2806
|
conversationId: input.conversationId,
|
|
@@ -2547,90 +2811,61 @@ function createAgentStateTools(input) {
|
|
|
2547
2811
|
return GoalSchema.parse(stored.value);
|
|
2548
2812
|
};
|
|
2549
2813
|
return [
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
identity: { serviceName: "agent-state", action: "create-goal", method: "POST" },
|
|
2554
|
-
input: z13.object({ objective: z13.string().min(1) }).strict(),
|
|
2555
|
-
output: GoalSchema,
|
|
2556
|
-
transports: ["AGENT"],
|
|
2557
|
-
handler: async ({ input: request }) => {
|
|
2558
|
-
if (await input.state.get(input.conversationId, "goal")) {
|
|
2559
|
-
throw new TypeError("A durable goal already exists for this conversation");
|
|
2560
|
-
}
|
|
2561
|
-
return writeGoal({ objective: request.objective, status: "active" });
|
|
2814
|
+
bindAgentTool(CREATE_GOAL_DESCRIPTOR, async ({ input: request }) => {
|
|
2815
|
+
if (await input.state.get(input.conversationId, "goal")) {
|
|
2816
|
+
throw new TypeError("A durable goal already exists for this conversation");
|
|
2562
2817
|
}
|
|
2818
|
+
return writeGoal({ objective: request.objective, status: "active" });
|
|
2563
2819
|
}),
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
status: z13.enum(["active", "complete", "blocked"]).optional()
|
|
2571
|
-
}).strict().refine((request) => request.objective !== undefined || request.status !== undefined, {
|
|
2572
|
-
message: "At least one goal field must be supplied"
|
|
2573
|
-
}),
|
|
2574
|
-
output: GoalSchema,
|
|
2575
|
-
transports: ["AGENT"],
|
|
2576
|
-
handler: async ({ input: request }) => {
|
|
2577
|
-
const current = await input.state.get(input.conversationId, "goal");
|
|
2578
|
-
if (!current)
|
|
2579
|
-
throw new TypeError("No durable goal exists for this conversation");
|
|
2580
|
-
const goal = GoalSchema.parse(current.value);
|
|
2581
|
-
return writeGoal({ ...goal, ...request });
|
|
2582
|
-
}
|
|
2820
|
+
bindAgentTool(UPDATE_GOAL_DESCRIPTOR, async ({ input: request }) => {
|
|
2821
|
+
const current = await input.state.get(input.conversationId, "goal");
|
|
2822
|
+
if (!current)
|
|
2823
|
+
throw new TypeError("No durable goal exists for this conversation");
|
|
2824
|
+
const goal = GoalSchema.parse(current.value);
|
|
2825
|
+
return writeGoal({ ...goal, ...request });
|
|
2583
2826
|
}),
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
identity: { serviceName: "agent-state", action: "get-goal", method: "GET" },
|
|
2588
|
-
input: z13.object({}).strict(),
|
|
2589
|
-
output: z13.object({ goal: GoalSchema.optional() }).strict(),
|
|
2590
|
-
transports: ["AGENT"],
|
|
2591
|
-
handler: async () => {
|
|
2592
|
-
const current = await input.state.get(input.conversationId, "goal");
|
|
2593
|
-
return { ...current && { goal: GoalSchema.parse(current.value) } };
|
|
2594
|
-
}
|
|
2827
|
+
bindAgentTool(GET_GOAL_DESCRIPTOR, async () => {
|
|
2828
|
+
const current = await input.state.get(input.conversationId, "goal");
|
|
2829
|
+
return { ...current && { goal: GoalSchema.parse(current.value) } };
|
|
2595
2830
|
}),
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
const stored = await input.state.set({
|
|
2605
|
-
conversationId: input.conversationId,
|
|
2606
|
-
name: "todo",
|
|
2607
|
-
value: request,
|
|
2608
|
-
actor: "agent"
|
|
2609
|
-
});
|
|
2610
|
-
return z13.object({ items: z13.array(TodoItemSchema) }).strict().parse(stored.value);
|
|
2611
|
-
}
|
|
2831
|
+
bindAgentTool(TODO_WRITE_DESCRIPTOR, async ({ input: request }) => {
|
|
2832
|
+
const stored = await input.state.set({
|
|
2833
|
+
conversationId: input.conversationId,
|
|
2834
|
+
name: "todo",
|
|
2835
|
+
value: request,
|
|
2836
|
+
actor: "agent"
|
|
2837
|
+
});
|
|
2838
|
+
return TodoOutputSchema.parse(stored.value);
|
|
2612
2839
|
})
|
|
2613
2840
|
];
|
|
2614
2841
|
}
|
|
2615
2842
|
export {
|
|
2616
2843
|
ACTIVE_AGENT_RUN_STATES2 as ACTIVE_AGENT_RUN_STATES,
|
|
2844
|
+
AGENT_CHILD_TOOL_DESCRIPTORS,
|
|
2845
|
+
AGENT_EVENT_SEARCH_TOOL_DESCRIPTORS2 as AGENT_EVENT_SEARCH_TOOL_DESCRIPTORS,
|
|
2846
|
+
AGENT_SCHEDULE_TOOL_DESCRIPTORS,
|
|
2847
|
+
AGENT_STATE_TOOL_DESCRIPTORS,
|
|
2617
2848
|
AcceptInputAndAssignRunSchema2 as AcceptInputAndAssignRunSchema,
|
|
2618
2849
|
AcquireAgentRunSchema2 as AcquireAgentRunSchema,
|
|
2619
2850
|
AgentAdmissionEventSchema2 as AgentAdmissionEventSchema,
|
|
2620
2851
|
AgentAdmissionReceiptSchema2 as AgentAdmissionReceiptSchema,
|
|
2621
2852
|
AgentAssistantPlaceholderSchema2 as AgentAssistantPlaceholderSchema,
|
|
2622
2853
|
AgentAttemptResetEventSchema2 as AgentAttemptResetEventSchema,
|
|
2854
|
+
AgentBranchRefusalCodeSchema2 as AgentBranchRefusalCodeSchema,
|
|
2855
|
+
AgentBranchRefusalSchema2 as AgentBranchRefusalSchema,
|
|
2623
2856
|
AgentCheckpointEventSchema2 as AgentCheckpointEventSchema,
|
|
2624
|
-
AgentChildBlockingEventSchema,
|
|
2625
|
-
AgentChildBlockingKindSchema,
|
|
2626
|
-
AgentChildBlockingSourceSchema,
|
|
2627
|
-
AgentChildBudgetSchema,
|
|
2628
|
-
AgentChildRecordSchema,
|
|
2629
|
-
AgentChildStateSchema,
|
|
2857
|
+
AgentChildBlockingEventSchema2 as AgentChildBlockingEventSchema,
|
|
2858
|
+
AgentChildBlockingKindSchema2 as AgentChildBlockingKindSchema,
|
|
2859
|
+
AgentChildBlockingSourceSchema2 as AgentChildBlockingSourceSchema,
|
|
2860
|
+
AgentChildBudgetSchema2 as AgentChildBudgetSchema,
|
|
2861
|
+
AgentChildRecordSchema2 as AgentChildRecordSchema,
|
|
2862
|
+
AgentChildStateSchema2 as AgentChildStateSchema,
|
|
2630
2863
|
AgentContextOverflowError2 as AgentContextOverflowError,
|
|
2631
2864
|
AgentControlPartSchema2 as AgentControlPartSchema,
|
|
2632
2865
|
AgentConversationArchiveSchema2 as AgentConversationArchiveSchema,
|
|
2866
|
+
AgentConversationBranchPlanSchema2 as AgentConversationBranchPlanSchema,
|
|
2633
2867
|
AgentConversationBranchReceiptSchema2 as AgentConversationBranchReceiptSchema,
|
|
2868
|
+
AgentConversationBranchRefusedError2 as AgentConversationBranchRefusedError,
|
|
2634
2869
|
AgentConversationBranchResultSchema2 as AgentConversationBranchResultSchema,
|
|
2635
2870
|
AgentConversationMessagePageSchema2 as AgentConversationMessagePageSchema,
|
|
2636
2871
|
AgentConversationPageSchema2 as AgentConversationPageSchema,
|
|
@@ -2639,7 +2874,7 @@ export {
|
|
|
2639
2874
|
AgentConversationPurgedError2 as AgentConversationPurgedError,
|
|
2640
2875
|
AgentConversationSummarySchema2 as AgentConversationSummarySchema,
|
|
2641
2876
|
AgentCostValueSchema2 as AgentCostValueSchema,
|
|
2642
|
-
AgentEventSearchResultSchema,
|
|
2877
|
+
AgentEventSearchResultSchema2 as AgentEventSearchResultSchema,
|
|
2643
2878
|
AgentFilePartSchema2 as AgentFilePartSchema,
|
|
2644
2879
|
AgentHistoryMutationSchema2 as AgentHistoryMutationSchema,
|
|
2645
2880
|
AgentJsonObjectSchema2 as AgentJsonObjectSchema,
|
|
@@ -2689,14 +2924,15 @@ export {
|
|
|
2689
2924
|
AgentRuntimeEventCursorSchema2 as AgentRuntimeEventCursorSchema,
|
|
2690
2925
|
AgentRuntimeEventSchema2 as AgentRuntimeEventSchema,
|
|
2691
2926
|
AgentRuntimeHeadSchema2 as AgentRuntimeHeadSchema,
|
|
2692
|
-
AgentSandboxGradeSchema2 as AgentSandboxGradeSchema,
|
|
2693
|
-
AgentSandboxRestrictionSchema2 as AgentSandboxRestrictionSchema,
|
|
2694
2927
|
AgentScheduleDeliveryOutcomeSchema,
|
|
2695
2928
|
AgentScheduleSchema,
|
|
2696
2929
|
AgentSeedReceiptSchema2 as AgentSeedReceiptSchema,
|
|
2697
2930
|
AgentSnapshotSchema2 as AgentSnapshotSchema,
|
|
2698
2931
|
AgentSourcePartSchema2 as AgentSourcePartSchema,
|
|
2932
|
+
AgentStepBarrierError2 as AgentStepBarrierError,
|
|
2699
2933
|
AgentStepFinishedEventSchema,
|
|
2934
|
+
AgentStepSpendPhaseSchema2 as AgentStepSpendPhaseSchema,
|
|
2935
|
+
AgentStepSpendSchema2 as AgentStepSpendSchema,
|
|
2700
2936
|
AgentStoreAppliedSchema2 as AgentStoreAppliedSchema,
|
|
2701
2937
|
AgentStoreConflictSchema2 as AgentStoreConflictSchema,
|
|
2702
2938
|
AgentStoreDuplicateSchema2 as AgentStoreDuplicateSchema,
|
|
@@ -2707,6 +2943,7 @@ export {
|
|
|
2707
2943
|
AgentStoreNotFoundSchema2 as AgentStoreNotFoundSchema,
|
|
2708
2944
|
AgentStoreTransitionRecordSchema2 as AgentStoreTransitionRecordSchema,
|
|
2709
2945
|
AgentStoreTransitionSchema2 as AgentStoreTransitionSchema,
|
|
2946
|
+
AgentStoreUnsupportedCapabilityError2 as AgentStoreUnsupportedCapabilityError,
|
|
2710
2947
|
AgentStoredRunSchema2 as AgentStoredRunSchema,
|
|
2711
2948
|
AgentTerminalEventSchema2 as AgentTerminalEventSchema,
|
|
2712
2949
|
AgentTerminalReasonSchema2 as AgentTerminalReasonSchema,
|
|
@@ -2728,13 +2965,18 @@ export {
|
|
|
2728
2965
|
CommitRunTerminalSchema2 as CommitRunTerminalSchema,
|
|
2729
2966
|
CompletionInvocationInputSchema2 as CompletionInvocationInputSchema,
|
|
2730
2967
|
DURABILITY_STEP_EVENT_KIND2 as DURABILITY_STEP_EVENT_KIND,
|
|
2731
|
-
DeferredAgentToolMatchSchema,
|
|
2732
|
-
DeferredAgentToolReceiptSchema,
|
|
2733
|
-
DeferredAgentToolSearchInputSchema,
|
|
2968
|
+
DeferredAgentToolMatchSchema2 as DeferredAgentToolMatchSchema,
|
|
2969
|
+
DeferredAgentToolReceiptSchema2 as DeferredAgentToolReceiptSchema,
|
|
2970
|
+
DeferredAgentToolSearchInputSchema2 as DeferredAgentToolSearchInputSchema,
|
|
2971
|
+
InvocationPayloadOmissionReasonSchema2 as InvocationPayloadOmissionReasonSchema,
|
|
2972
|
+
InvocationPayloadTooLargeError2 as InvocationPayloadTooLargeError,
|
|
2973
|
+
ModelInvocationPayloadReadSchema2 as ModelInvocationPayloadReadSchema,
|
|
2734
2974
|
ModelInvocationRecordSchema2 as ModelInvocationRecordSchema,
|
|
2735
2975
|
ModelInvocationTraceSchema2 as ModelInvocationTraceSchema,
|
|
2736
2976
|
ParkAbortedError2 as ParkAbortedError,
|
|
2737
2977
|
ParkRecordDecodeError2 as ParkRecordDecodeError,
|
|
2978
|
+
PurgeInvocationPayloadsInputSchema2 as PurgeInvocationPayloadsInputSchema,
|
|
2979
|
+
PurgeInvocationPayloadsResultSchema2 as PurgeInvocationPayloadsResultSchema,
|
|
2738
2980
|
ReadAgentStoreEventsSchema2 as ReadAgentStoreEventsSchema,
|
|
2739
2981
|
RecordRunOperationSchema2 as RecordRunOperationSchema,
|
|
2740
2982
|
RecoverAgentRunSchema2 as RecoverAgentRunSchema,
|
|
@@ -2758,16 +3000,20 @@ export {
|
|
|
2758
3000
|
canonicalAgentJson2 as canonicalAgentJson,
|
|
2759
3001
|
classifyProviderFailure2 as classifyProviderFailure,
|
|
2760
3002
|
composeAgentPrompt2 as composeAgentPrompt,
|
|
3003
|
+
createAgentChildManager,
|
|
2761
3004
|
createAgentChildTools,
|
|
2762
|
-
|
|
3005
|
+
createAgentEventSearch2 as createAgentEventSearch,
|
|
3006
|
+
createAgentEventSearchTools2 as createAgentEventSearchTools,
|
|
2763
3007
|
createAgentObservability,
|
|
2764
3008
|
createAgentProjectionRegistry,
|
|
3009
|
+
createAgentProjectionStore,
|
|
2765
3010
|
createAgentRuntime2 as createAgentRuntime,
|
|
2766
3011
|
createAgentRuntimeEventSink2 as createAgentRuntimeEventSink,
|
|
2767
3012
|
createAgentRuntimeStore2 as createAgentRuntimeStore,
|
|
2768
3013
|
createAgentScheduleService,
|
|
2769
3014
|
createAgentScheduleTools,
|
|
2770
3015
|
createAgentSessionCoordinator2 as createAgentSessionCoordinator,
|
|
3016
|
+
createAgentSpillStore,
|
|
2771
3017
|
createAgentStateSlotStore2 as createAgentStateSlotStore,
|
|
2772
3018
|
createAgentStateTools,
|
|
2773
3019
|
createAgentToolFenceLifecycle2 as createAgentToolFenceLifecycle,
|
|
@@ -2775,10 +3021,7 @@ export {
|
|
|
2775
3021
|
createMemoryAgentModelSelectionStore2 as createMemoryAgentModelSelectionStore,
|
|
2776
3022
|
createMemoryAgentRuntimeStore2 as createMemoryAgentRuntimeStore,
|
|
2777
3023
|
createModelInvocationLedger2 as createModelInvocationLedger,
|
|
2778
|
-
|
|
2779
|
-
createSqliteAgentEventSearch,
|
|
2780
|
-
createSqliteAgentProjectionStore,
|
|
2781
|
-
createSqliteAgentSpillStore,
|
|
3024
|
+
createToolDependencyResolver2 as createToolDependencyResolver,
|
|
2782
3025
|
currentModelInvocationAttempt2 as currentModelInvocationAttempt,
|
|
2783
3026
|
decodeAgentConversationArchive2 as decodeAgentConversationArchive,
|
|
2784
3027
|
decodeAgentStoreEvent2 as decodeAgentStoreEvent,
|
|
@@ -2790,13 +3033,11 @@ export {
|
|
|
2790
3033
|
hasAgentTerminalOutput,
|
|
2791
3034
|
isAssistantHistoryEvidence2 as isAssistantHistoryEvidence,
|
|
2792
3035
|
isToolResultFailure2 as isToolResultFailure,
|
|
2793
|
-
|
|
2794
|
-
probeAgentProcessSandbox2 as probeAgentProcessSandbox,
|
|
3036
|
+
modelInvocationSpendAttribution,
|
|
2795
3037
|
projectAgentHistory2 as projectAgentHistory,
|
|
2796
3038
|
projectAgentHistoryDetailed2 as projectAgentHistoryDetailed,
|
|
2797
3039
|
purgeAgentConversation2 as purgeAgentConversation,
|
|
2798
3040
|
recordAgentRetryDecision2 as recordAgentRetryDecision,
|
|
2799
|
-
recordAgentSandboxProbe2 as recordAgentSandboxProbe,
|
|
2800
3041
|
renderAgentStateSlots2 as renderAgentStateSlots,
|
|
2801
3042
|
runStateForTerminalReason2 as runStateForTerminalReason,
|
|
2802
3043
|
searchAgentModelCatalog2 as searchAgentModelCatalog,
|