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,23 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AgentCodingToolAuthorizationSchema2,
|
|
3
|
-
ShellOutputSchema,
|
|
4
|
-
AgentSandboxRestrictionSchema2,
|
|
5
|
-
AgentSandboxGradeSchema2,
|
|
6
|
-
AGENT_CODING_TOOL_NAMES
|
|
7
|
-
} from "./index-4efxzrht.js";
|
|
8
1
|
import {
|
|
9
2
|
AgentRecordIdSchema2,
|
|
3
|
+
AgentStoreEventEnvelopeSchema2,
|
|
4
|
+
AppendAgentStoreEventSchema2,
|
|
5
|
+
ReadAgentStoreEventsSchema2,
|
|
6
|
+
AgentStoreEventPageSchema2,
|
|
10
7
|
AgentRecordVersionSchema2,
|
|
11
8
|
AgentTimestampSchema2,
|
|
12
9
|
AgentMessageSchema2,
|
|
13
10
|
runStateForTerminalReason2,
|
|
14
11
|
AgentRunSchema2,
|
|
15
12
|
AgentSnapshotSchema2
|
|
16
|
-
} from "./index-
|
|
13
|
+
} from "./index-bn2baakz.js";
|
|
17
14
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
AgentCodingToolAuthorizationSchema2,
|
|
16
|
+
ShellOutputSchema,
|
|
17
|
+
ArtifactReadInputSchema,
|
|
18
|
+
ArtifactReadOutputSchema,
|
|
19
|
+
ArtifactSearchInputSchema,
|
|
20
|
+
ArtifactSearchOutputSchema,
|
|
21
|
+
AgentSandboxRestrictionSchema2,
|
|
22
|
+
AgentSandboxGradeSchema2,
|
|
23
|
+
AGENT_CODING_TOOL_NAMES
|
|
24
|
+
} from "./index-wavv538x.js";
|
|
25
|
+
import {
|
|
26
|
+
AgentRuntimeHeadSchema2,
|
|
27
|
+
AgentStoredRunSchema2,
|
|
28
|
+
AgentAdmissionReceiptSchema2,
|
|
29
|
+
AgentSeedReceiptSchema2,
|
|
30
|
+
isActiveRunState,
|
|
31
|
+
emptyHead,
|
|
21
32
|
AgentRunViewSchema2,
|
|
22
33
|
AcceptInputAndAssignRunSchema2,
|
|
23
34
|
AcquireAgentRunSchema2,
|
|
@@ -35,32 +46,88 @@ import {
|
|
|
35
46
|
canonicalAgentJson2,
|
|
36
47
|
encodeAgentConversationArchive2,
|
|
37
48
|
decodeAgentConversationArchive2,
|
|
38
|
-
|
|
49
|
+
conversationOfRun,
|
|
39
50
|
ProviderJournalMessageSchema,
|
|
40
51
|
ProviderJournalRequestSchema,
|
|
41
|
-
ProviderJournalResponseSchema
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
ProviderJournalResponseSchema
|
|
53
|
+
} from "./index-9xr44d2g.js";
|
|
54
|
+
import {
|
|
55
|
+
PurgeInvocationPayloadsInputSchema2,
|
|
56
|
+
PurgeInvocationPayloadsResultSchema2,
|
|
57
|
+
InvocationStartedSchema,
|
|
58
|
+
InvocationRequestSchema,
|
|
59
|
+
InvocationResponseSchema,
|
|
60
|
+
InvocationFinishedSchema,
|
|
61
|
+
InvocationPayloadReceiptSchema,
|
|
62
|
+
isModelInvocationRecord,
|
|
63
|
+
assistantStatus
|
|
64
|
+
} from "./index-vgzhw2zk.js";
|
|
49
65
|
import {
|
|
50
66
|
StepEventPayloadSchema,
|
|
51
67
|
ParkEventPayloadSchema,
|
|
52
68
|
DeliveredEventPayloadSchema,
|
|
53
69
|
EffectEventPayloadSchema
|
|
54
70
|
} from "./index-snef22zr.js";
|
|
71
|
+
import {
|
|
72
|
+
assertPositiveSafeInteger
|
|
73
|
+
} from "./index-kzavdze2.js";
|
|
55
74
|
|
|
56
75
|
// src/agent-runtime/branch-contract.ts
|
|
76
|
+
import { z as z2 } from "zod";
|
|
77
|
+
|
|
78
|
+
// src/agent-runtime/branch-refusal.ts
|
|
57
79
|
import { z } from "zod";
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
80
|
+
var AgentBranchRefusalCodeSchema2 = z.enum([
|
|
81
|
+
"application-key-undeclared",
|
|
82
|
+
"application-key-source-identity",
|
|
83
|
+
"application-file-undeclared",
|
|
84
|
+
"artifact-authorization-missing",
|
|
85
|
+
"event-kind-unknown",
|
|
86
|
+
"integrity"
|
|
87
|
+
]);
|
|
88
|
+
var AgentBranchRefusalSchema2 = z.object({
|
|
89
|
+
code: AgentBranchRefusalCodeSchema2,
|
|
90
|
+
message: z.string().min(1),
|
|
91
|
+
seq: z.int().positive().optional(),
|
|
92
|
+
eventKind: z.string().min(1).optional(),
|
|
93
|
+
messageId: z.string().min(1).optional(),
|
|
94
|
+
toolName: z.string().min(1).optional(),
|
|
95
|
+
key: z.string().min(1).optional(),
|
|
96
|
+
path: z.string().optional(),
|
|
97
|
+
reference: z.string().min(1).optional()
|
|
98
|
+
}).strict();
|
|
99
|
+
var MAX_BRANCH_REFUSALS = 100;
|
|
100
|
+
function addressOf(refusal) {
|
|
101
|
+
const parts = [
|
|
102
|
+
refusal.seq !== undefined && `event ${refusal.seq}${refusal.eventKind ? ` ${refusal.eventKind}` : ""}`,
|
|
103
|
+
refusal.messageId !== undefined && `message ${refusal.messageId}`,
|
|
104
|
+
refusal.toolName !== undefined && `tool ${refusal.toolName}`
|
|
105
|
+
].filter((part) => typeof part === "string");
|
|
106
|
+
return parts.length > 0 ? ` (${parts.join(", ")})` : "";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
class AgentConversationBranchRefusedError2 extends TypeError {
|
|
110
|
+
refusals;
|
|
111
|
+
omittedRefusals;
|
|
112
|
+
constructor(refusals, omittedRefusals = 0) {
|
|
113
|
+
const [first] = refusals;
|
|
114
|
+
if (!first)
|
|
115
|
+
throw new TypeError("A branch refusal names at least one refusal");
|
|
116
|
+
const more = refusals.length - 1 + omittedRefusals;
|
|
117
|
+
super(`${first.message}${addressOf(first)}${more > 0 ? `; and ${more} more refusal${more === 1 ? "" : "s"}` : ""}`);
|
|
118
|
+
this.name = "AgentConversationBranchRefusedError";
|
|
119
|
+
this.refusals = refusals;
|
|
120
|
+
this.omittedRefusals = omittedRefusals;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/agent-runtime/branch-contract.ts
|
|
125
|
+
var Hash = z2.string().regex(/^[a-f0-9]{64}$/);
|
|
126
|
+
var BranchApplicationFileSchema = z2.object({
|
|
127
|
+
reference: z2.string().min(1),
|
|
128
|
+
destinationReference: z2.string().min(1)
|
|
62
129
|
}).strict();
|
|
63
|
-
var BranchApplicationFilesSchema =
|
|
130
|
+
var BranchApplicationFilesSchema = z2.array(BranchApplicationFileSchema).superRefine((files, ctx) => {
|
|
64
131
|
for (const field of ["reference", "destinationReference"]) {
|
|
65
132
|
const values = files.map((file) => file[field]);
|
|
66
133
|
if (new Set(values).size !== values.length)
|
|
@@ -70,57 +137,337 @@ var BranchApplicationFilesSchema = z.array(BranchApplicationFileSchema).superRef
|
|
|
70
137
|
});
|
|
71
138
|
}
|
|
72
139
|
});
|
|
73
|
-
var
|
|
140
|
+
var BRANCH_RUNTIME_REFERENCE_KEYS = [
|
|
141
|
+
"reference",
|
|
142
|
+
"conversationId",
|
|
143
|
+
"runId",
|
|
144
|
+
"messageId",
|
|
145
|
+
"callId",
|
|
146
|
+
"toolCallId",
|
|
147
|
+
"approvalId",
|
|
148
|
+
"operationId",
|
|
149
|
+
"artifactId"
|
|
150
|
+
];
|
|
151
|
+
var BranchApplicationKeySchema = z2.object({
|
|
152
|
+
key: z2.enum(BRANCH_RUNTIME_REFERENCE_KEYS),
|
|
153
|
+
sourceIdentity: z2.enum(["refuse", "retain", "rekey-spill"]).default("refuse")
|
|
154
|
+
}).strict();
|
|
155
|
+
var BranchApplicationKeysSchema = z2.array(BranchApplicationKeySchema).superRefine((keys, ctx) => {
|
|
156
|
+
const names = keys.map((entry) => entry.key);
|
|
157
|
+
if (new Set(names).size !== names.length)
|
|
158
|
+
ctx.addIssue({ code: "custom", message: "Branch application keys repeat a key" });
|
|
159
|
+
});
|
|
160
|
+
var BranchAgentConversationInputSchema2 = z2.object({
|
|
74
161
|
requestKey: AgentRecordIdSchema2,
|
|
75
162
|
destinationConversationId: AgentRecordIdSchema2,
|
|
76
|
-
source:
|
|
77
|
-
|
|
78
|
-
kind:
|
|
163
|
+
source: z2.discriminatedUnion("kind", [
|
|
164
|
+
z2.object({
|
|
165
|
+
kind: z2.literal("conversation"),
|
|
79
166
|
conversationId: AgentRecordIdSchema2,
|
|
80
167
|
throughRunId: AgentRecordIdSchema2.optional()
|
|
81
168
|
}).strict(),
|
|
82
|
-
|
|
83
|
-
kind:
|
|
84
|
-
bytes:
|
|
169
|
+
z2.object({
|
|
170
|
+
kind: z2.literal("archive"),
|
|
171
|
+
bytes: z2.custom((value) => value instanceof Uint8Array)
|
|
85
172
|
}).strict()
|
|
86
173
|
]),
|
|
87
174
|
artifactAuthorization: AgentCodingToolAuthorizationSchema2.optional(),
|
|
88
175
|
applicationFiles: BranchApplicationFilesSchema.optional(),
|
|
89
|
-
applicationKeys:
|
|
176
|
+
applicationKeys: BranchApplicationKeysSchema.optional()
|
|
90
177
|
}).strict();
|
|
91
|
-
var AgentConversationBranchReceiptSchema2 =
|
|
92
|
-
schemaVersion:
|
|
178
|
+
var AgentConversationBranchReceiptSchema2 = z2.object({
|
|
179
|
+
schemaVersion: z2.literal(1),
|
|
93
180
|
requestKey: AgentRecordIdSchema2,
|
|
94
181
|
fingerprint: Hash,
|
|
95
182
|
conversationId: AgentRecordIdSchema2,
|
|
96
183
|
sourceConversationId: AgentRecordIdSchema2,
|
|
97
|
-
sourceKind:
|
|
184
|
+
sourceKind: z2.enum(["conversation", "archive"]),
|
|
98
185
|
throughRunId: AgentRecordIdSchema2.optional(),
|
|
99
|
-
sourceSeq:
|
|
100
|
-
sourceVersion:
|
|
186
|
+
sourceSeq: z2.int().nonnegative(),
|
|
187
|
+
sourceVersion: z2.int().nonnegative(),
|
|
101
188
|
sourceDigest: Hash,
|
|
102
189
|
createdAt: AgentTimestampSchema2
|
|
103
190
|
}).strict();
|
|
104
|
-
var AgentConversationBranchResultSchema2 =
|
|
105
|
-
outcome:
|
|
191
|
+
var AgentConversationBranchResultSchema2 = z2.object({
|
|
192
|
+
outcome: z2.enum(["created", "duplicate"]),
|
|
106
193
|
receipt: AgentConversationBranchReceiptSchema2
|
|
107
194
|
}).strict();
|
|
195
|
+
var AgentConversationBranchPlanSchema2 = z2.object({
|
|
196
|
+
ready: z2.boolean(),
|
|
197
|
+
fingerprint: z2.string().regex(/^[a-f0-9]{64}$/),
|
|
198
|
+
sourceArchiveDigest: z2.string().regex(/^[a-f0-9]{64}$/),
|
|
199
|
+
refusals: z2.array(AgentBranchRefusalSchema2),
|
|
200
|
+
omittedRefusals: z2.int().nonnegative(),
|
|
201
|
+
applicationFiles: z2.array(z2.string().min(1)),
|
|
202
|
+
undeclaredKeys: z2.array(z2.string().min(1))
|
|
203
|
+
}).strict();
|
|
204
|
+
|
|
205
|
+
// src/agent-runtime/agent-tool.ts
|
|
206
|
+
function defineAgentToolDescriptor(descriptor) {
|
|
207
|
+
const identity = Object.freeze({
|
|
208
|
+
...descriptor.identity,
|
|
209
|
+
...descriptor.identity.meta !== undefined && {
|
|
210
|
+
meta: Object.freeze({ ...descriptor.identity.meta })
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const expose = Object.freeze(["AGENT"]);
|
|
214
|
+
return Object.freeze({
|
|
215
|
+
...descriptor,
|
|
216
|
+
identity,
|
|
217
|
+
expose
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function bindAgentTool(descriptor, handler) {
|
|
221
|
+
return {
|
|
222
|
+
name: descriptor.name,
|
|
223
|
+
description: descriptor.description,
|
|
224
|
+
identity: {
|
|
225
|
+
...descriptor.identity,
|
|
226
|
+
...descriptor.identity.meta !== undefined && {
|
|
227
|
+
meta: { ...descriptor.identity.meta }
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
input: descriptor.input,
|
|
231
|
+
output: descriptor.output,
|
|
232
|
+
expose: descriptor.expose,
|
|
233
|
+
handler: (context) => handler(context)
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/agent-runtime/children-contract.ts
|
|
238
|
+
import { z as z4 } from "zod";
|
|
239
|
+
|
|
240
|
+
// src/agent-runtime/sql-rows.ts
|
|
241
|
+
import { z as z3 } from "zod";
|
|
242
|
+
var SqlIntegerSchema = z3.union([z3.number(), z3.bigint(), z3.string().regex(/^-?\d+$/)]).transform(Number).pipe(z3.int());
|
|
243
|
+
var SqlFlagSchema = SqlIntegerSchema.pipe(z3.union([z3.literal(0), z3.literal(1)]));
|
|
244
|
+
var HeadRowSchema = z3.object({
|
|
245
|
+
version: SqlIntegerSchema.pipe(z3.int().nonnegative())
|
|
246
|
+
});
|
|
247
|
+
var RunRowSchema = z3.object({
|
|
248
|
+
payload: z3.string(),
|
|
249
|
+
terminal_assistant_payload: z3.string().nullable()
|
|
250
|
+
});
|
|
251
|
+
var MessageRowSchema = z3.object({ payload: z3.string() });
|
|
252
|
+
var PositionedMessageRowSchema = z3.object({
|
|
253
|
+
position: SqlIntegerSchema.pipe(z3.int().nonnegative())
|
|
254
|
+
});
|
|
255
|
+
var CountRowSchema = z3.object({
|
|
256
|
+
count: SqlIntegerSchema.pipe(z3.int().nonnegative())
|
|
257
|
+
});
|
|
258
|
+
var FlagSchema = SqlFlagSchema;
|
|
259
|
+
var EventRowSchema = z3.object({
|
|
260
|
+
event_id: z3.string(),
|
|
261
|
+
conversation_id: z3.string(),
|
|
262
|
+
seq: SqlIntegerSchema.pipe(z3.int().positive()),
|
|
263
|
+
schema_version: SqlIntegerSchema.pipe(z3.int().positive()),
|
|
264
|
+
kind: z3.string(),
|
|
265
|
+
occurred_at: z3.string(),
|
|
266
|
+
ignorable: SqlFlagSchema,
|
|
267
|
+
payload: z3.string()
|
|
268
|
+
});
|
|
269
|
+
var EVENT_COLUMNS = "event_id, conversation_id, seq, schema_version, kind, occurred_at, ignorable, payload";
|
|
270
|
+
function parseJson(value) {
|
|
271
|
+
return JSON.parse(value);
|
|
272
|
+
}
|
|
273
|
+
function encodeJson(value) {
|
|
274
|
+
return JSON.stringify(value);
|
|
275
|
+
}
|
|
276
|
+
function missing(value) {
|
|
277
|
+
return value === null || value === undefined;
|
|
278
|
+
}
|
|
279
|
+
function placeholders(count) {
|
|
280
|
+
return Array.from({ length: count }, () => "?").join(", ");
|
|
281
|
+
}
|
|
282
|
+
function parseRunRow(value) {
|
|
283
|
+
const row = RunRowSchema.parse(value);
|
|
284
|
+
return AgentStoredRunSchema2.parse({
|
|
285
|
+
schemaVersion: 1,
|
|
286
|
+
run: AgentRunSchema2.parse(parseJson(row.payload)),
|
|
287
|
+
...row.terminal_assistant_payload === null ? {} : {
|
|
288
|
+
terminalAssistant: AgentMessageSchema2.parse(parseJson(row.terminal_assistant_payload))
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function parseEventRow(value) {
|
|
293
|
+
const row = EventRowSchema.parse(value);
|
|
294
|
+
return AgentStoreEventEnvelopeSchema2.parse({
|
|
295
|
+
schemaVersion: row.schema_version,
|
|
296
|
+
eventId: row.event_id,
|
|
297
|
+
conversationId: row.conversation_id,
|
|
298
|
+
seq: row.seq,
|
|
299
|
+
kind: row.kind,
|
|
300
|
+
occurredAt: row.occurred_at,
|
|
301
|
+
payload: parseJson(row.payload),
|
|
302
|
+
...row.ignorable === 1 && { ignorable: true }
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
async function nextEventSeqByMaximum(dialect, session, conversationId) {
|
|
306
|
+
const row = await session.get(`SELECT COALESCE(MAX(seq), 0) AS count FROM ${dialect.tables.events} WHERE conversation_id = ?`, [conversationId]);
|
|
307
|
+
return CountRowSchema.parse(row).count + 1;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/agent-runtime/children-contract.ts
|
|
311
|
+
var AgentChildBudgetSchema2 = z4.object({
|
|
312
|
+
usd: z4.number().positive().optional(),
|
|
313
|
+
tokens: z4.int().positive().optional(),
|
|
314
|
+
milliseconds: z4.int().positive().optional()
|
|
315
|
+
}).strict();
|
|
316
|
+
var AgentChildStateSchema2 = z4.enum([
|
|
317
|
+
"spawned",
|
|
318
|
+
"running",
|
|
319
|
+
"finished",
|
|
320
|
+
"stopped",
|
|
321
|
+
"lost"
|
|
322
|
+
]);
|
|
323
|
+
var ChildUsageMetricsSchema = z4.object({
|
|
324
|
+
tokens: z4.int().nonnegative(),
|
|
325
|
+
usd: z4.number().nonnegative(),
|
|
326
|
+
milliseconds: z4.int().nonnegative()
|
|
327
|
+
}).strict();
|
|
328
|
+
var AgentChildRecordSchema2 = z4.object({
|
|
329
|
+
parentConversationId: z4.string().min(1),
|
|
330
|
+
childConversationId: z4.string().min(1),
|
|
331
|
+
seedUptoSeq: z4.int().nonnegative(),
|
|
332
|
+
state: AgentChildStateSchema2,
|
|
333
|
+
budget: AgentChildBudgetSchema2,
|
|
334
|
+
usage: ChildUsageMetricsSchema,
|
|
335
|
+
resultReference: z4.string().optional(),
|
|
336
|
+
createdAt: z4.string(),
|
|
337
|
+
updatedAt: z4.string()
|
|
338
|
+
}).strict();
|
|
339
|
+
var AgentChildBlockingKindSchema2 = z4.enum(["approval", "input"]);
|
|
340
|
+
var AgentChildBlockingSourceSchema2 = z4.object({
|
|
341
|
+
approvalId: z4.string().min(1),
|
|
342
|
+
callId: z4.string().min(1),
|
|
343
|
+
toolName: z4.string().min(1),
|
|
344
|
+
input: z4.json(),
|
|
345
|
+
kind: AgentChildBlockingKindSchema2.default("approval"),
|
|
346
|
+
batchId: z4.string().min(1).optional()
|
|
347
|
+
}).strict();
|
|
348
|
+
var AgentChildBlockingEventSchema2 = z4.object({
|
|
349
|
+
parentConversationId: z4.string().min(1),
|
|
350
|
+
childConversationId: z4.string().min(1),
|
|
351
|
+
kind: AgentChildBlockingKindSchema2,
|
|
352
|
+
approvalId: z4.string().min(1),
|
|
353
|
+
childApprovalId: z4.string().min(1),
|
|
354
|
+
callId: z4.string().min(1),
|
|
355
|
+
toolName: z4.string().min(1),
|
|
356
|
+
input: z4.json(),
|
|
357
|
+
batchId: z4.string().min(1),
|
|
358
|
+
presentedAt: z4.string()
|
|
359
|
+
}).strict();
|
|
360
|
+
var ChildBlockingDecisionSchema = z4.union([
|
|
361
|
+
z4.object({
|
|
362
|
+
approvalId: z4.string().min(1),
|
|
363
|
+
approved: z4.boolean(),
|
|
364
|
+
reason: z4.string().optional()
|
|
365
|
+
}).strict(),
|
|
366
|
+
z4.object({ approvalId: z4.string().min(1), value: z4.json() }).strict()
|
|
367
|
+
]);
|
|
368
|
+
var ChildSpawnedEventPayloadSchema = z4.object({
|
|
369
|
+
childConversationId: z4.string().min(1),
|
|
370
|
+
seedUptoSeq: z4.int().nonnegative(),
|
|
371
|
+
budget: AgentChildBudgetSchema2
|
|
372
|
+
}).strict();
|
|
373
|
+
var ChildTransitionStateEventPayloadSchema = z4.object({
|
|
374
|
+
childConversationId: z4.string().min(1).optional(),
|
|
375
|
+
parentConversationId: z4.string().min(1).optional(),
|
|
376
|
+
state: AgentChildStateSchema2,
|
|
377
|
+
resultReference: z4.string().min(1).optional(),
|
|
378
|
+
reason: z4.string().optional(),
|
|
379
|
+
policyName: z4.string().min(1).optional(),
|
|
380
|
+
enforced: z4.boolean().optional(),
|
|
381
|
+
stopDurationMs: z4.number().nonnegative().optional(),
|
|
382
|
+
usage: ChildUsageMetricsSchema.optional(),
|
|
383
|
+
overrun: ChildUsageMetricsSchema.optional()
|
|
384
|
+
}).strict().refine((value) => value.childConversationId !== undefined || value.parentConversationId !== undefined, { message: "Child state event requires childConversationId or parentConversationId" });
|
|
385
|
+
var ChildMessageSentEventPayloadSchema = z4.object({
|
|
386
|
+
childConversationId: z4.string().min(1),
|
|
387
|
+
action: z4.literal("message-sent")
|
|
388
|
+
}).strict();
|
|
389
|
+
var ChildBlockingPresentedEventPayloadSchema = z4.object({
|
|
390
|
+
action: z4.literal("blocking-presented"),
|
|
391
|
+
childConversationId: z4.string().min(1),
|
|
392
|
+
approvalId: z4.string().min(1),
|
|
393
|
+
childApprovalId: z4.string().min(1),
|
|
394
|
+
kind: AgentChildBlockingKindSchema2,
|
|
395
|
+
callId: z4.string().min(1),
|
|
396
|
+
toolName: z4.string().min(1),
|
|
397
|
+
input: z4.json(),
|
|
398
|
+
batchId: z4.string().min(1),
|
|
399
|
+
presentedAt: z4.string()
|
|
400
|
+
}).strict();
|
|
401
|
+
var ChildBlockingResolvedApprovalEventPayloadSchema = z4.object({
|
|
402
|
+
action: z4.literal("blocking-resolved"),
|
|
403
|
+
childConversationId: z4.string().min(1),
|
|
404
|
+
approvalId: z4.string().min(1),
|
|
405
|
+
batchId: z4.string().min(1),
|
|
406
|
+
approved: z4.boolean()
|
|
407
|
+
}).strict();
|
|
408
|
+
var ChildBlockingResolvedInputEventPayloadSchema = z4.object({
|
|
409
|
+
action: z4.literal("blocking-resolved"),
|
|
410
|
+
childConversationId: z4.string().min(1),
|
|
411
|
+
approvalId: z4.string().min(1),
|
|
412
|
+
batchId: z4.string().min(1),
|
|
413
|
+
kind: z4.literal("input")
|
|
414
|
+
}).strict();
|
|
415
|
+
var ChildStateEventPayloadSchema = z4.union([
|
|
416
|
+
ChildTransitionStateEventPayloadSchema,
|
|
417
|
+
ChildMessageSentEventPayloadSchema,
|
|
418
|
+
ChildBlockingPresentedEventPayloadSchema,
|
|
419
|
+
ChildBlockingResolvedApprovalEventPayloadSchema,
|
|
420
|
+
ChildBlockingResolvedInputEventPayloadSchema
|
|
421
|
+
]);
|
|
422
|
+
var ChildRowSchema = z4.object({
|
|
423
|
+
parent_conversation_id: z4.string(),
|
|
424
|
+
child_conversation_id: z4.string(),
|
|
425
|
+
seed_upto_seq: SqlIntegerSchema.pipe(z4.int().nonnegative()),
|
|
426
|
+
state: AgentChildStateSchema2,
|
|
427
|
+
budget_payload: z4.string(),
|
|
428
|
+
usage_payload: z4.string(),
|
|
429
|
+
result_reference: z4.string().nullable(),
|
|
430
|
+
created_at: z4.string(),
|
|
431
|
+
updated_at: z4.string()
|
|
432
|
+
});
|
|
433
|
+
function parseChild(raw) {
|
|
434
|
+
const row = ChildRowSchema.parse(raw);
|
|
435
|
+
return AgentChildRecordSchema2.parse({
|
|
436
|
+
parentConversationId: row.parent_conversation_id,
|
|
437
|
+
childConversationId: row.child_conversation_id,
|
|
438
|
+
seedUptoSeq: row.seed_upto_seq,
|
|
439
|
+
state: row.state,
|
|
440
|
+
budget: JSON.parse(row.budget_payload),
|
|
441
|
+
usage: JSON.parse(row.usage_payload),
|
|
442
|
+
...row.result_reference && { resultReference: row.result_reference },
|
|
443
|
+
createdAt: row.created_at,
|
|
444
|
+
updatedAt: row.updated_at
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
function usageNumbers(usage) {
|
|
448
|
+
const inputTokens = usage.inputTokens.value;
|
|
449
|
+
const outputTokens = usage.outputTokens.value;
|
|
450
|
+
return {
|
|
451
|
+
...inputTokens !== undefined && outputTokens !== undefined ? { tokens: inputTokens + outputTokens } : {},
|
|
452
|
+
...usage.cost?.currency === "USD" && usage.cost.value !== undefined ? { usd: usage.cost.value } : {}
|
|
453
|
+
};
|
|
454
|
+
}
|
|
108
455
|
|
|
109
456
|
// src/agent-runtime/purge.ts
|
|
110
|
-
import { z as
|
|
111
|
-
var AgentConversationPurgeInputSchema2 =
|
|
457
|
+
import { z as z5 } from "zod";
|
|
458
|
+
var AgentConversationPurgeInputSchema2 = z5.strictObject({
|
|
112
459
|
conversationId: AgentRecordIdSchema2,
|
|
113
460
|
expectedVersion: AgentRecordVersionSchema2.optional()
|
|
114
461
|
});
|
|
115
|
-
var AgentConversationPurgeResultSchema2 =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
outcome:
|
|
121
|
-
runIds:
|
|
462
|
+
var AgentConversationPurgeResultSchema2 = z5.discriminatedUnion("outcome", [
|
|
463
|
+
z5.strictObject({ outcome: z5.literal("purged") }),
|
|
464
|
+
z5.strictObject({ outcome: z5.literal("already_purged") }),
|
|
465
|
+
z5.strictObject({ outcome: z5.literal("unsupported") }),
|
|
466
|
+
z5.strictObject({
|
|
467
|
+
outcome: z5.literal("active"),
|
|
468
|
+
runIds: z5.array(AgentRecordIdSchema2).min(1)
|
|
122
469
|
}),
|
|
123
|
-
|
|
470
|
+
z5.strictObject({ outcome: z5.literal("conflict"), actualVersion: AgentRecordVersionSchema2 })
|
|
124
471
|
]);
|
|
125
472
|
|
|
126
473
|
class AgentConversationPurgedError2 extends Error {
|
|
@@ -136,15 +483,664 @@ async function purgeAgentConversation2(store, input) {
|
|
|
136
483
|
return AgentConversationPurgeResultSchema2.parse(await store.purgeConversation(parsed));
|
|
137
484
|
}
|
|
138
485
|
|
|
486
|
+
// src/agent-runtime/deferred-tool-types.ts
|
|
487
|
+
import { z as z6 } from "zod";
|
|
488
|
+
var DeferredAgentToolSearchInputSchema2 = z6.object({
|
|
489
|
+
query: z6.string().min(1).describe("An exact tool name, or words describing the tool. Matched as one phrase first, then word by word."),
|
|
490
|
+
reason: z6.enum(["inactive_call"]).optional().describe("Written by the runtime. Leave it out.")
|
|
491
|
+
});
|
|
492
|
+
var DeferredAgentToolMatchSchema2 = z6.object({
|
|
493
|
+
name: z6.string(),
|
|
494
|
+
description: z6.string()
|
|
495
|
+
});
|
|
496
|
+
var DeferredAgentToolReceiptSchema2 = z6.object({
|
|
497
|
+
schemaVersion: z6.literal(1),
|
|
498
|
+
kind: z6.literal("stitchkit.deferred-tool-selection"),
|
|
499
|
+
status: z6.enum(["SELECTED", "SEARCH_REQUIRED", "NO_MATCH", "SELECTION_REFUSED"]),
|
|
500
|
+
runId: z6.string(),
|
|
501
|
+
surfaceKey: z6.string(),
|
|
502
|
+
selected: z6.array(z6.string()),
|
|
503
|
+
matches: z6.array(DeferredAgentToolMatchSchema2),
|
|
504
|
+
truncated: z6.boolean()
|
|
505
|
+
}).superRefine((receipt, context) => {
|
|
506
|
+
const selected = receipt.status === "SELECTED" || receipt.status === "SEARCH_REQUIRED";
|
|
507
|
+
if (selected !== receipt.selected.length > 0) {
|
|
508
|
+
context.addIssue({
|
|
509
|
+
code: "custom",
|
|
510
|
+
path: ["selected"],
|
|
511
|
+
message: `${receipt.status} receipt has inconsistent selected tools`
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// src/agent-runtime/event-search.ts
|
|
517
|
+
import { z as z9 } from "zod";
|
|
518
|
+
|
|
519
|
+
// src/agent-runtime/event-search-postgres.ts
|
|
520
|
+
import { z as z8 } from "zod";
|
|
521
|
+
|
|
522
|
+
// src/agent-runtime/event-search-terms.ts
|
|
523
|
+
import { z as z7 } from "zod";
|
|
524
|
+
var MAX_SEARCH_TERMS = 64;
|
|
525
|
+
function extractSearchTerms(query) {
|
|
526
|
+
const terms = query.split(/\s+/u).filter((term) => /[\p{L}\p{N}]/u.test(term));
|
|
527
|
+
if (terms.length === 0)
|
|
528
|
+
throw new TypeError("Event search query must contain searchable terms");
|
|
529
|
+
if (terms.length > MAX_SEARCH_TERMS) {
|
|
530
|
+
throw new TypeError(`Event search query has ${terms.length} terms, at most ${MAX_SEARCH_TERMS} are searched`);
|
|
531
|
+
}
|
|
532
|
+
return terms;
|
|
533
|
+
}
|
|
534
|
+
var SearchRowSchema = z7.object({
|
|
535
|
+
conversation_id: z7.string(),
|
|
536
|
+
event_seq: SqlIntegerSchema.pipe(z7.int().positive()),
|
|
537
|
+
occurred_at: z7.string(),
|
|
538
|
+
snippet: z7.string()
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
// src/agent-runtime/sql-session.ts
|
|
542
|
+
function agentSqlTables(prefix) {
|
|
543
|
+
return {
|
|
544
|
+
meta: `${prefix}_meta`,
|
|
545
|
+
heads: `${prefix}_heads`,
|
|
546
|
+
runs: `${prefix}_runs`,
|
|
547
|
+
admissions: `${prefix}_admissions`,
|
|
548
|
+
messages: `${prefix}_messages`,
|
|
549
|
+
seeds: `${prefix}_seeds`,
|
|
550
|
+
events: `${prefix}_events`,
|
|
551
|
+
eventSeq: `${prefix}_event_seq`,
|
|
552
|
+
projections: `${prefix}_projections`,
|
|
553
|
+
spills: `${prefix}_spills`,
|
|
554
|
+
schedules: `${prefix}_schedules`,
|
|
555
|
+
children: `${prefix}_children`,
|
|
556
|
+
purged: `${prefix}_purged`,
|
|
557
|
+
eventSearch: `${prefix}_event_search`,
|
|
558
|
+
eventSearchState: `${prefix}_event_search_state`
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
function toNumberedPlaceholders(sql) {
|
|
562
|
+
let out = "";
|
|
563
|
+
let index = 0;
|
|
564
|
+
let quote;
|
|
565
|
+
for (const char of sql) {
|
|
566
|
+
if (quote !== undefined) {
|
|
567
|
+
if (char === quote)
|
|
568
|
+
quote = undefined;
|
|
569
|
+
out += char;
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
if (char === "'" || char === '"') {
|
|
573
|
+
quote = char;
|
|
574
|
+
out += char;
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (char === "?") {
|
|
578
|
+
index += 1;
|
|
579
|
+
out += `$${index}`;
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
out += char;
|
|
583
|
+
}
|
|
584
|
+
return out;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// src/agent-runtime/postgres-transactions.ts
|
|
588
|
+
var RETRYABLE = new Set(["40001", "40P01"]);
|
|
589
|
+
var MAX_ERROR_DEPTH = 6;
|
|
590
|
+
function* postgresErrorNodes(error, depth = 0, visited = new Set) {
|
|
591
|
+
if (depth >= MAX_ERROR_DEPTH || typeof error !== "object" || error === null)
|
|
592
|
+
return;
|
|
593
|
+
if (visited.has(error))
|
|
594
|
+
return;
|
|
595
|
+
visited.add(error);
|
|
596
|
+
yield error;
|
|
597
|
+
const meta = Reflect.get(error, "meta");
|
|
598
|
+
if (typeof meta === "object" && meta !== null) {
|
|
599
|
+
yield* postgresErrorNodes(Reflect.get(meta, "driverAdapterError"), depth + 1, visited);
|
|
600
|
+
yield* postgresErrorNodes(meta, depth + 1, visited);
|
|
601
|
+
}
|
|
602
|
+
yield* postgresErrorNodes(Reflect.get(error, "cause"), depth + 1, visited);
|
|
603
|
+
}
|
|
604
|
+
function nodeSqlState(node) {
|
|
605
|
+
for (const key of ["errno", "code", "originalCode", "sqlState"]) {
|
|
606
|
+
const field = Reflect.get(node, key);
|
|
607
|
+
if (typeof field === "string" && /^[0-9A-Z]{5}$/.test(field) && !/^P\d{4}$/.test(field)) {
|
|
608
|
+
return field;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
function p2010SqlState(node) {
|
|
614
|
+
if (Reflect.get(node, "code") !== "P2010")
|
|
615
|
+
return;
|
|
616
|
+
const message = Reflect.get(node, "message");
|
|
617
|
+
if (typeof message !== "string")
|
|
618
|
+
return;
|
|
619
|
+
const backticked = /Code:\s*`([0-9A-Z]{5})`/.exec(message);
|
|
620
|
+
if (backticked?.[1] !== undefined && !/^P\d{4}$/.test(backticked[1])) {
|
|
621
|
+
return backticked[1];
|
|
622
|
+
}
|
|
623
|
+
const retryable = /\b(40001|40P01)\b/.exec(message);
|
|
624
|
+
return retryable?.[1];
|
|
625
|
+
}
|
|
626
|
+
function postgresErrorState(error) {
|
|
627
|
+
let fromMessage;
|
|
628
|
+
for (const node of postgresErrorNodes(error)) {
|
|
629
|
+
const direct = nodeSqlState(node);
|
|
630
|
+
if (direct !== undefined)
|
|
631
|
+
return direct;
|
|
632
|
+
fromMessage ??= p2010SqlState(node);
|
|
633
|
+
}
|
|
634
|
+
return fromMessage;
|
|
635
|
+
}
|
|
636
|
+
function isRetryablePostgresConflict(error) {
|
|
637
|
+
const state = postgresErrorState(error);
|
|
638
|
+
if (state !== undefined && RETRYABLE.has(state))
|
|
639
|
+
return true;
|
|
640
|
+
for (const node of postgresErrorNodes(error)) {
|
|
641
|
+
if (Reflect.get(node, "code") === "P2034")
|
|
642
|
+
return true;
|
|
643
|
+
if (Reflect.get(node, "kind") === "TransactionWriteConflict")
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
648
|
+
var POSTGRES_ISOLATION = {
|
|
649
|
+
write: "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE",
|
|
650
|
+
read: "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY"
|
|
651
|
+
};
|
|
652
|
+
function postgresSession(query, tx) {
|
|
653
|
+
const texts = new Map;
|
|
654
|
+
const text = (sql) => {
|
|
655
|
+
let numbered = texts.get(sql);
|
|
656
|
+
if (numbered === undefined) {
|
|
657
|
+
numbered = toNumberedPlaceholders(sql);
|
|
658
|
+
texts.set(sql, numbered);
|
|
659
|
+
}
|
|
660
|
+
return numbered;
|
|
661
|
+
};
|
|
662
|
+
return {
|
|
663
|
+
all: (sql, parameters = []) => query(tx, text(sql), parameters),
|
|
664
|
+
get: async (sql, parameters = []) => (await query(tx, text(sql), parameters))[0],
|
|
665
|
+
run: async (sql, parameters = []) => {
|
|
666
|
+
await query(tx, text(sql), parameters);
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
function backoff(attempt) {
|
|
671
|
+
const ceiling = Math.min(200, 2 ** attempt);
|
|
672
|
+
return new Promise((resolve) => setTimeout(resolve, Math.random() * ceiling));
|
|
673
|
+
}
|
|
674
|
+
async function setPostgresTransactionIsolation(session, statement) {
|
|
675
|
+
try {
|
|
676
|
+
await session.run(statement);
|
|
677
|
+
} catch (error) {
|
|
678
|
+
if (postgresErrorState(error) === "25001") {
|
|
679
|
+
throw new Error("The Postgres agent store opens its own transactions: `transaction` must start a new one, with no statement run in it before the store's", { cause: error });
|
|
680
|
+
}
|
|
681
|
+
throw error;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
async function runPostgresTransaction(runner, access, work) {
|
|
685
|
+
for (let attempt = 1;; attempt += 1) {
|
|
686
|
+
try {
|
|
687
|
+
return await runner.transaction(async (tx) => {
|
|
688
|
+
const session = postgresSession(runner.query, tx);
|
|
689
|
+
await setPostgresTransactionIsolation(session, runner.isolation[access]);
|
|
690
|
+
return work(session);
|
|
691
|
+
});
|
|
692
|
+
} catch (error) {
|
|
693
|
+
if (attempt >= runner.maxAttempts || !runner.isRetryable(error))
|
|
694
|
+
throw error;
|
|
695
|
+
await backoff(attempt);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// src/agent-runtime/event-search-postgres.ts
|
|
701
|
+
var BATCH = 500;
|
|
702
|
+
var EventRowSchema2 = z8.object({
|
|
703
|
+
seq: SqlIntegerSchema.pipe(z8.int().positive()),
|
|
704
|
+
occurred_at: z8.string(),
|
|
705
|
+
payload: z8.string()
|
|
706
|
+
});
|
|
707
|
+
var BehindRowSchema = z8.object({
|
|
708
|
+
conversation_id: z8.string(),
|
|
709
|
+
last_seq: SqlIntegerSchema,
|
|
710
|
+
indexed_seq: SqlIntegerSchema
|
|
711
|
+
});
|
|
712
|
+
var MetaRowSchema = z8.object({ value: z8.string() });
|
|
713
|
+
var IndexedRowSchema = z8.object({ indexed_seq: SqlIntegerSchema });
|
|
714
|
+
var CountSchema = z8.object({ count: SqlIntegerSchema });
|
|
715
|
+
function positive(name, value, fallback) {
|
|
716
|
+
assertPositiveSafeInteger(`Event search: ${name}`, value);
|
|
717
|
+
return value ?? fallback;
|
|
718
|
+
}
|
|
719
|
+
async function refuseOtherDiacriticsSettings(session, metaTable, diacritics) {
|
|
720
|
+
if (diacritics === "unaccent") {
|
|
721
|
+
const present = await session.get("SELECT 1 AS present FROM pg_extension WHERE extname = 'unaccent'");
|
|
722
|
+
if (present === undefined) {
|
|
723
|
+
throw new TypeError("Event search: diacritics 'unaccent' needs Postgres's unaccent extension (CREATE EXTENSION unaccent)");
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
const row = await session.get(`SELECT value FROM ${metaTable} WHERE key = 'event_search_diacritics'`);
|
|
727
|
+
if (row === undefined)
|
|
728
|
+
return false;
|
|
729
|
+
const recorded = MetaRowSchema.parse(row).value;
|
|
730
|
+
if (recorded !== diacritics) {
|
|
731
|
+
throw new TypeError(`Event search: the index was built with diacritics '${recorded}', this search asks for '${diacritics}'`);
|
|
732
|
+
}
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
function postgresEventSearchBackend(host, config = {}) {
|
|
736
|
+
const diacritics = config.diacritics ?? "preserve";
|
|
737
|
+
if (diacritics !== "preserve" && diacritics !== "unaccent") {
|
|
738
|
+
throw new TypeError("Event search: diacritics must be 'preserve' or 'unaccent'");
|
|
739
|
+
}
|
|
740
|
+
const maxIndexedChars = positive("maxIndexedChars", config.maxIndexedChars, 65536);
|
|
741
|
+
const maxSyncEvents = positive("maxSyncEvents", config.maxSyncEvents, 1e4);
|
|
742
|
+
const index = host.tables.eventSearch;
|
|
743
|
+
const state = host.tables.eventSearchState;
|
|
744
|
+
const fold = (expression) => diacritics === "unaccent" ? `unaccent(${expression})` : expression;
|
|
745
|
+
const refuseOtherSettings = (session) => refuseOtherDiacriticsSettings(session, host.tables.meta, diacritics);
|
|
746
|
+
const indexOne = async (session, conversationId, event) => {
|
|
747
|
+
for (let chars = maxIndexedChars;; chars = Math.floor(chars / 2)) {
|
|
748
|
+
await session.run("SAVEPOINT stitchkit_event_search");
|
|
749
|
+
try {
|
|
750
|
+
await session.run(`INSERT INTO ${index} (conversation_id, seq, occurred_at, body, document)
|
|
751
|
+
VALUES (?, ?, ?, left(?, ?), to_tsvector('simple', ${fold("left(?, ?)")}))
|
|
752
|
+
ON CONFLICT (conversation_id, seq) DO NOTHING`, [
|
|
753
|
+
conversationId,
|
|
754
|
+
event.seq,
|
|
755
|
+
event.occurred_at,
|
|
756
|
+
event.payload,
|
|
757
|
+
chars,
|
|
758
|
+
event.payload,
|
|
759
|
+
chars
|
|
760
|
+
]);
|
|
761
|
+
await session.run("RELEASE SAVEPOINT stitchkit_event_search");
|
|
762
|
+
return;
|
|
763
|
+
} catch (error) {
|
|
764
|
+
try {
|
|
765
|
+
await session.run("ROLLBACK TO SAVEPOINT stitchkit_event_search");
|
|
766
|
+
} catch (rollbackError) {
|
|
767
|
+
throw new AggregateError([error, rollbackError], "Event search could not index an event, and its savepoint rollback failed too", { cause: error });
|
|
768
|
+
}
|
|
769
|
+
if (postgresErrorState(error) !== "54000" || chars === 0)
|
|
770
|
+
throw error;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
const catchUp = (conversationId, budget) => host.transaction(conversationId, async (scope) => {
|
|
775
|
+
if (!await refuseOtherSettings(scope)) {
|
|
776
|
+
await scope.run(`INSERT INTO ${host.tables.meta} (key, value) VALUES ('event_search_diacritics', ?)
|
|
777
|
+
ON CONFLICT (key) DO NOTHING`, [diacritics]);
|
|
778
|
+
await refuseOtherSettings(scope);
|
|
779
|
+
}
|
|
780
|
+
const done = await scope.get(`SELECT indexed_seq FROM ${state} WHERE conversation_id = ?`, [conversationId]);
|
|
781
|
+
const from = done === undefined ? 0 : IndexedRowSchema.parse(done).indexed_seq;
|
|
782
|
+
const events = (await scope.all(`SELECT seq, occurred_at, payload FROM ${host.tables.events}
|
|
783
|
+
WHERE conversation_id = ? AND seq > ? ORDER BY seq LIMIT ?`, [conversationId, from, Math.min(budget, BATCH)])).map((row) => EventRowSchema2.parse(row));
|
|
784
|
+
for (const event of events)
|
|
785
|
+
await indexOne(scope, conversationId, event);
|
|
786
|
+
const last = events.at(-1);
|
|
787
|
+
if (last !== undefined) {
|
|
788
|
+
await scope.run(`INSERT INTO ${state} (conversation_id, indexed_seq) VALUES (?, ?)
|
|
789
|
+
ON CONFLICT (conversation_id) DO UPDATE SET indexed_seq = excluded.indexed_seq`, [conversationId, last.seq]);
|
|
790
|
+
}
|
|
791
|
+
return events.length;
|
|
792
|
+
}).catch((error) => {
|
|
793
|
+
if (error instanceof AgentConversationPurgedError2)
|
|
794
|
+
return 0;
|
|
795
|
+
throw error;
|
|
796
|
+
});
|
|
797
|
+
const behind = (target) => host.read(async (session) => (await session.all(`SELECT q.conversation_id, q.last_seq, COALESCE(s.indexed_seq, 0) AS indexed_seq
|
|
798
|
+
FROM ${host.tables.eventSeq} q LEFT JOIN ${state} s USING (conversation_id)
|
|
799
|
+
WHERE q.last_seq > COALESCE(s.indexed_seq, 0)
|
|
800
|
+
${target === undefined ? "" : "AND q.conversation_id = ?"}
|
|
801
|
+
ORDER BY q.conversation_id`, target === undefined ? [] : [target])).map((row) => BehindRowSchema.parse(row)));
|
|
802
|
+
const sync = async (target) => {
|
|
803
|
+
let budget = maxSyncEvents;
|
|
804
|
+
const initial = await behind(target);
|
|
805
|
+
if (initial.length === 0)
|
|
806
|
+
return;
|
|
807
|
+
const watermarks = new Map(initial.map((row) => [row.conversation_id, row.last_seq]));
|
|
808
|
+
for (const conversation of initial) {
|
|
809
|
+
let pending = conversation.last_seq - conversation.indexed_seq;
|
|
810
|
+
while (pending > 0 && budget > 0) {
|
|
811
|
+
const indexed = await catchUp(conversation.conversation_id, budget);
|
|
812
|
+
if (indexed === 0)
|
|
813
|
+
break;
|
|
814
|
+
pending -= indexed;
|
|
815
|
+
budget -= indexed;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
const left = (await behind(target)).reduce((sum, row) => {
|
|
819
|
+
const watermark = watermarks.get(row.conversation_id);
|
|
820
|
+
if (watermark === undefined)
|
|
821
|
+
return sum;
|
|
822
|
+
return sum + Math.max(0, watermark - row.indexed_seq);
|
|
823
|
+
}, 0);
|
|
824
|
+
if (left > 0) {
|
|
825
|
+
throw new TypeError(`Event search: the index is ${left} events behind after indexing ${maxSyncEvents - budget}; search again to continue`);
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
return {
|
|
829
|
+
async prepare(request) {
|
|
830
|
+
await host.read(async (session) => {
|
|
831
|
+
await refuseOtherSettings(session);
|
|
832
|
+
for (const term of request.terms) {
|
|
833
|
+
const row = await session.get(`SELECT numnode(phraseto_tsquery('simple', ${fold("?")})) AS count`, [term]);
|
|
834
|
+
if (CountSchema.parse(row).count === 0) {
|
|
835
|
+
throw new TypeError("Event search query must contain searchable terms");
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
await sync(request.target);
|
|
840
|
+
},
|
|
841
|
+
async candidates(request) {
|
|
842
|
+
return host.read(async (session) => {
|
|
843
|
+
const query = request.terms.map(() => `phraseto_tsquery('simple', ${fold("?")})`).join(" && ");
|
|
844
|
+
const values = [...request.terms];
|
|
845
|
+
if (request.target)
|
|
846
|
+
values.push(request.target);
|
|
847
|
+
if (request.since)
|
|
848
|
+
values.push(request.since);
|
|
849
|
+
const rows = await session.all(`SELECT s.conversation_id, s.seq AS event_seq, s.occurred_at,
|
|
850
|
+
ts_headline('simple', ${fold("s.body")}, q.query,
|
|
851
|
+
'StartSel=[, StopSel=], MaxWords=24, MinWords=8, MaxFragments=2, FragmentDelimiter=" … "') AS snippet
|
|
852
|
+
FROM ${index} s, (SELECT ${query} AS query) q
|
|
853
|
+
WHERE s.document @@ q.query
|
|
854
|
+
${request.target ? "AND s.conversation_id = ?" : ""}
|
|
855
|
+
${request.since ? "AND s.occurred_at::timestamptz >= ?::timestamptz" : ""}
|
|
856
|
+
ORDER BY ts_rank_cd(s.document, q.query) DESC, s.occurred_at DESC, s.seq
|
|
857
|
+
LIMIT ? OFFSET ?`, [...values, request.limit, request.offset]);
|
|
858
|
+
return rows.map((row) => SearchRowSchema.parse(row));
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// src/agent-runtime/event-search.ts
|
|
865
|
+
var AgentEventSearchResultSchema2 = z9.object({
|
|
866
|
+
conversationId: z9.string().min(1),
|
|
867
|
+
seq: z9.int().positive(),
|
|
868
|
+
occurredAt: z9.string(),
|
|
869
|
+
snippet: z9.string()
|
|
870
|
+
}).strict();
|
|
871
|
+
function sqliteBackend(host) {
|
|
872
|
+
const fts = `${host.tables.events}_fts`;
|
|
873
|
+
return {
|
|
874
|
+
async candidates(request) {
|
|
875
|
+
const values = [
|
|
876
|
+
request.terms.map((term) => `"${term.replaceAll('"', '""')}"`).join(" AND ")
|
|
877
|
+
];
|
|
878
|
+
if (request.target)
|
|
879
|
+
values.push(request.target);
|
|
880
|
+
if (request.since)
|
|
881
|
+
values.push(request.since);
|
|
882
|
+
const rows = await host.read((session) => session.all(`SELECT f.conversation_id, f.event_seq, f.occurred_at,
|
|
883
|
+
snippet(${fts}, 3, '[', ']', ' … ', 24) AS snippet
|
|
884
|
+
FROM ${fts} AS f
|
|
885
|
+
WHERE ${fts} MATCH ?
|
|
886
|
+
${request.target ? "AND f.conversation_id = ?" : ""}
|
|
887
|
+
${request.since ? "AND f.occurred_at >= ?" : ""}
|
|
888
|
+
ORDER BY bm25(${fts}), f.occurred_at DESC, f.rowid
|
|
889
|
+
LIMIT ? OFFSET ?`, [...values, request.limit, request.offset]));
|
|
890
|
+
return rows.map((row) => SearchRowSchema.parse(row));
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
function createAgentEventSearch2(input) {
|
|
895
|
+
const { host } = input;
|
|
896
|
+
if (host.dialect === "sqlite" && input.postgres !== undefined) {
|
|
897
|
+
throw new TypeError("Event search: `postgres` options apply to the Postgres store only");
|
|
898
|
+
}
|
|
899
|
+
const backend = host.dialect === "sqlite" ? sqliteBackend(host) : postgresEventSearchBackend(host, input.postgres);
|
|
900
|
+
return async (request) => {
|
|
901
|
+
if (request.query.trim().length === 0)
|
|
902
|
+
throw new TypeError("Event search query must not be empty");
|
|
903
|
+
const terms = extractSearchTerms(request.query);
|
|
904
|
+
if (request.limit !== undefined) {
|
|
905
|
+
assertPositiveSafeInteger("Event search limit", request.limit, TypeError);
|
|
906
|
+
}
|
|
907
|
+
const limit = Math.min(request.limit ?? 20, 200);
|
|
908
|
+
const target = request.conversationId ?? (input.authorizeConversation ? undefined : request.requestingConversationId);
|
|
909
|
+
const since = request.since ? z9.iso.datetime({ offset: true }).parse(request.since) : undefined;
|
|
910
|
+
await backend.prepare?.({ terms, ...target !== undefined && { target } });
|
|
911
|
+
const page = limit * 4;
|
|
912
|
+
const candidatesFrom = (offset) => backend.candidates({
|
|
913
|
+
terms,
|
|
914
|
+
...target !== undefined && { target },
|
|
915
|
+
...since !== undefined && { since },
|
|
916
|
+
limit: page,
|
|
917
|
+
offset
|
|
918
|
+
});
|
|
919
|
+
const authorization = new Map;
|
|
920
|
+
const results = [];
|
|
921
|
+
let offset = 0;
|
|
922
|
+
let candidates = await candidatesFrom(offset);
|
|
923
|
+
while (candidates.length > 0 && results.length < limit) {
|
|
924
|
+
for (const row of candidates) {
|
|
925
|
+
if (row.conversation_id !== request.requestingConversationId) {
|
|
926
|
+
let allowed = authorization.get(row.conversation_id);
|
|
927
|
+
if (allowed === undefined) {
|
|
928
|
+
allowed = input.authorizeConversation ? await input.authorizeConversation({
|
|
929
|
+
requestingConversationId: request.requestingConversationId,
|
|
930
|
+
targetConversationId: row.conversation_id
|
|
931
|
+
}) : false;
|
|
932
|
+
authorization.set(row.conversation_id, allowed);
|
|
933
|
+
}
|
|
934
|
+
if (!allowed)
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
results.push(AgentEventSearchResultSchema2.parse({
|
|
938
|
+
conversationId: row.conversation_id,
|
|
939
|
+
seq: row.event_seq,
|
|
940
|
+
occurredAt: row.occurred_at,
|
|
941
|
+
snippet: row.snippet
|
|
942
|
+
}));
|
|
943
|
+
if (results.length === limit)
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
offset += page;
|
|
947
|
+
candidates = results.length < limit ? await candidatesFrom(offset) : [];
|
|
948
|
+
}
|
|
949
|
+
return results;
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// src/agent-runtime/event-search-tools.ts
|
|
954
|
+
import { z as z10 } from "zod";
|
|
955
|
+
var AGENT_EVENT_SEARCH_TOOL_NAMES = {
|
|
956
|
+
search: "session_search",
|
|
957
|
+
trace: "session_trace",
|
|
958
|
+
event: "session_event"
|
|
959
|
+
};
|
|
960
|
+
var EventAddressSchema = z10.object({ conversationId: z10.string(), seq: z10.int().positive() }).strict();
|
|
961
|
+
var EventOutputSchema = z10.object({
|
|
962
|
+
conversationId: z10.string(),
|
|
963
|
+
seq: z10.int().positive(),
|
|
964
|
+
kind: z10.string(),
|
|
965
|
+
occurredAt: z10.string(),
|
|
966
|
+
payload: z10.json()
|
|
967
|
+
}).strict();
|
|
968
|
+
var SearchInputSchema = z10.object({
|
|
969
|
+
query: z10.string().min(1),
|
|
970
|
+
conversationId: z10.string().min(1).optional(),
|
|
971
|
+
since: z10.iso.datetime({ offset: true }).optional(),
|
|
972
|
+
limit: z10.int().positive().max(200).optional()
|
|
973
|
+
}).strict();
|
|
974
|
+
var SearchOutputSchema = z10.object({ results: z10.array(AgentEventSearchResultSchema2) }).strict();
|
|
975
|
+
var TraceInputSchema = z10.object({
|
|
976
|
+
fromSeq: z10.int().positive().optional(),
|
|
977
|
+
toSeq: z10.int().positive().optional(),
|
|
978
|
+
limit: z10.int().positive().max(1000).default(100)
|
|
979
|
+
}).strict();
|
|
980
|
+
var TraceOutputSchema = z10.object({ events: z10.array(EventOutputSchema), nextSeq: z10.number().optional() }).strict();
|
|
981
|
+
var SEARCH_DESCRIPTOR = defineAgentToolDescriptor({
|
|
982
|
+
name: AGENT_EVENT_SEARCH_TOOL_NAMES.search,
|
|
983
|
+
description: "Search authorized durable conversation events and return exact addresses.",
|
|
984
|
+
identity: { serviceName: "agent-events", action: "search", method: "POST" },
|
|
985
|
+
input: SearchInputSchema,
|
|
986
|
+
output: SearchOutputSchema,
|
|
987
|
+
expose: ["AGENT"]
|
|
988
|
+
});
|
|
989
|
+
var TRACE_DESCRIPTOR = defineAgentToolDescriptor({
|
|
990
|
+
name: AGENT_EVENT_SEARCH_TOOL_NAMES.trace,
|
|
991
|
+
description: "Read a bounded contiguous slice of this conversation event trace.",
|
|
992
|
+
identity: { serviceName: "agent-events", action: "trace", method: "GET" },
|
|
993
|
+
input: TraceInputSchema,
|
|
994
|
+
output: TraceOutputSchema,
|
|
995
|
+
expose: ["AGENT"]
|
|
996
|
+
});
|
|
997
|
+
var EVENT_DESCRIPTOR = defineAgentToolDescriptor({
|
|
998
|
+
name: AGENT_EVENT_SEARCH_TOOL_NAMES.event,
|
|
999
|
+
description: "Read one durable event by exact conversation and sequence address.",
|
|
1000
|
+
identity: { serviceName: "agent-events", action: "read", method: "GET" },
|
|
1001
|
+
input: EventAddressSchema,
|
|
1002
|
+
output: EventOutputSchema,
|
|
1003
|
+
expose: ["AGENT"]
|
|
1004
|
+
});
|
|
1005
|
+
var AGENT_EVENT_SEARCH_TOOL_DESCRIPTORS2 = Object.freeze([
|
|
1006
|
+
SEARCH_DESCRIPTOR,
|
|
1007
|
+
TRACE_DESCRIPTOR,
|
|
1008
|
+
EVENT_DESCRIPTOR
|
|
1009
|
+
]);
|
|
1010
|
+
var AGENT_EVENT_SEARCH_TOOL_SCHEMAS = {
|
|
1011
|
+
[SEARCH_DESCRIPTOR.name]: {
|
|
1012
|
+
input: SEARCH_DESCRIPTOR.input,
|
|
1013
|
+
output: SEARCH_DESCRIPTOR.output
|
|
1014
|
+
},
|
|
1015
|
+
[TRACE_DESCRIPTOR.name]: {
|
|
1016
|
+
input: TRACE_DESCRIPTOR.input,
|
|
1017
|
+
output: TRACE_DESCRIPTOR.output
|
|
1018
|
+
},
|
|
1019
|
+
[EVENT_DESCRIPTOR.name]: {
|
|
1020
|
+
input: EVENT_DESCRIPTOR.input,
|
|
1021
|
+
output: EVENT_DESCRIPTOR.output
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
function createAgentEventSearchTools2(config) {
|
|
1025
|
+
const input = {
|
|
1026
|
+
...config,
|
|
1027
|
+
conversationId: conversationOfRun(config.run, "createAgentEventSearchTools")
|
|
1028
|
+
};
|
|
1029
|
+
const readExact = async (address) => {
|
|
1030
|
+
if (address.conversationId !== input.conversationId) {
|
|
1031
|
+
const allowed = await input.authorizeConversation?.({
|
|
1032
|
+
requestingConversationId: input.conversationId,
|
|
1033
|
+
targetConversationId: address.conversationId
|
|
1034
|
+
});
|
|
1035
|
+
if (!allowed)
|
|
1036
|
+
throw new TypeError("Event address is outside the authorized conversation");
|
|
1037
|
+
}
|
|
1038
|
+
const page = await input.store.readEvents({
|
|
1039
|
+
conversationId: address.conversationId,
|
|
1040
|
+
fromSeq: address.seq,
|
|
1041
|
+
toSeq: address.seq,
|
|
1042
|
+
limit: 1
|
|
1043
|
+
});
|
|
1044
|
+
const event = page.items[0];
|
|
1045
|
+
if (!event || event.seq !== address.seq)
|
|
1046
|
+
throw new TypeError("Unknown event address");
|
|
1047
|
+
return {
|
|
1048
|
+
conversationId: event.conversationId,
|
|
1049
|
+
seq: event.seq,
|
|
1050
|
+
kind: event.kind,
|
|
1051
|
+
occurredAt: event.occurredAt,
|
|
1052
|
+
payload: event.payload
|
|
1053
|
+
};
|
|
1054
|
+
};
|
|
1055
|
+
return [
|
|
1056
|
+
bindAgentTool(SEARCH_DESCRIPTOR, async ({ input: request }) => ({
|
|
1057
|
+
results: [
|
|
1058
|
+
...await input.search({
|
|
1059
|
+
requestingConversationId: input.conversationId,
|
|
1060
|
+
...request
|
|
1061
|
+
})
|
|
1062
|
+
]
|
|
1063
|
+
})),
|
|
1064
|
+
bindAgentTool(TRACE_DESCRIPTOR, async ({ input: request }) => {
|
|
1065
|
+
const page = await input.store.readEvents({
|
|
1066
|
+
conversationId: input.conversationId,
|
|
1067
|
+
...request
|
|
1068
|
+
});
|
|
1069
|
+
return {
|
|
1070
|
+
events: page.items.map((event) => ({
|
|
1071
|
+
conversationId: event.conversationId,
|
|
1072
|
+
seq: event.seq,
|
|
1073
|
+
kind: event.kind,
|
|
1074
|
+
occurredAt: event.occurredAt,
|
|
1075
|
+
payload: event.payload
|
|
1076
|
+
})),
|
|
1077
|
+
...page.nextSeq !== undefined && { nextSeq: page.nextSeq }
|
|
1078
|
+
};
|
|
1079
|
+
}),
|
|
1080
|
+
bindAgentTool(EVENT_DESCRIPTOR, ({ input: request }) => readExact(request))
|
|
1081
|
+
];
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// src/agent-runtime/store-capabilities.ts
|
|
1085
|
+
import { z as z11 } from "zod";
|
|
1086
|
+
var AgentStoreOptionalCapabilitySchema = z11.enum(["archive", "historyRestore"]);
|
|
1087
|
+
var AgentRuntimeStoreCapabilitiesSchema = z11.strictObject({
|
|
1088
|
+
archive: z11.boolean(),
|
|
1089
|
+
historyRestore: z11.boolean(),
|
|
1090
|
+
purge: z11.boolean()
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
class AgentStoreUnsupportedCapabilityError2 extends TypeError {
|
|
1094
|
+
capability;
|
|
1095
|
+
constructor(capability, need) {
|
|
1096
|
+
super(`The agent store driver does not implement ${capability === "archive" ? "archive" : "history.restore"}: ${need}`);
|
|
1097
|
+
this.name = "AgentStoreUnsupportedCapabilityError";
|
|
1098
|
+
this.capability = capability;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
function driverCapabilities(driver) {
|
|
1102
|
+
const archive = driver.archive;
|
|
1103
|
+
if (archive !== undefined && (typeof archive.export !== "function" || typeof archive.import !== "function"))
|
|
1104
|
+
throw new TypeError("An agent store driver archive needs both export and import");
|
|
1105
|
+
if (driver.history.restore !== undefined && typeof driver.history.restore !== "function")
|
|
1106
|
+
throw new TypeError("An agent store driver history.restore must be a function");
|
|
1107
|
+
return Object.freeze(AgentRuntimeStoreCapabilitiesSchema.parse({
|
|
1108
|
+
archive: archive !== undefined,
|
|
1109
|
+
historyRestore: driver.history.restore !== undefined,
|
|
1110
|
+
purge: driver.conversations !== undefined
|
|
1111
|
+
}));
|
|
1112
|
+
}
|
|
1113
|
+
function assertSourceCapabilities(driver, source) {
|
|
1114
|
+
if (!driver.archive && source.spills > 0)
|
|
1115
|
+
throw new AgentStoreUnsupportedCapabilityError2("archive", "the source carries spills");
|
|
1116
|
+
if (!driver.archive && source.projections > 0)
|
|
1117
|
+
throw new AgentStoreUnsupportedCapabilityError2("archive", "the source carries companion projections");
|
|
1118
|
+
if (!driver.history.restore && source.compacted > 0)
|
|
1119
|
+
throw new AgentStoreUnsupportedCapabilityError2("historyRestore", "the source baseline carries compacted history");
|
|
1120
|
+
}
|
|
1121
|
+
|
|
139
1122
|
// src/agent-runtime/store-create.ts
|
|
140
|
-
import { z as
|
|
1123
|
+
import { z as z25 } from "zod";
|
|
141
1124
|
|
|
142
1125
|
// src/agent-runtime/store-archive.ts
|
|
143
|
-
import { z as
|
|
1126
|
+
import { z as z14 } from "zod";
|
|
1127
|
+
|
|
1128
|
+
// src/agent-runtime/archive-projection.ts
|
|
1129
|
+
import { z as z12 } from "zod";
|
|
1130
|
+
var ArchiveProjectionSchema = z12.object({
|
|
1131
|
+
name: z12.string(),
|
|
1132
|
+
version: z12.int().positive(),
|
|
1133
|
+
uptoSeq: z12.int().nonnegative(),
|
|
1134
|
+
value: z12.json(),
|
|
1135
|
+
updatedAt: z12.string()
|
|
1136
|
+
}).strict();
|
|
1137
|
+
function isRuntimeSnapshotEntry(entry) {
|
|
1138
|
+
return typeof entry === "object" && entry !== null && !Array.isArray(entry) && Reflect.get(entry, "archiveType") === "runtime-snapshot" && "snapshot" in entry;
|
|
1139
|
+
}
|
|
144
1140
|
|
|
145
1141
|
// src/agent-runtime/branch-replay.ts
|
|
146
1142
|
import { createHash as createHash2 } from "node:crypto";
|
|
147
|
-
import { z as
|
|
1143
|
+
import { z as z13 } from "zod";
|
|
148
1144
|
|
|
149
1145
|
// src/agent-runtime/store-reducer.ts
|
|
150
1146
|
import { createHash } from "node:crypto";
|
|
@@ -594,9 +1590,16 @@ function reduceTerminal(current, run, input) {
|
|
|
594
1590
|
// src/agent-runtime/store-reducer.ts
|
|
595
1591
|
function transitionRecord(operation, reduced) {
|
|
596
1592
|
if (operation.type === "recover" && operation.input.action === "abandon") {
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
1593
|
+
const record = reduced?.runRecords?.find((candidate) => candidate.run.id === operation.input.runId);
|
|
1594
|
+
const assistant = record?.terminalAssistant;
|
|
1595
|
+
const usage = record?.run.usage;
|
|
1596
|
+
if (assistant || usage) {
|
|
1597
|
+
return {
|
|
1598
|
+
...operation,
|
|
1599
|
+
...assistant && { assistant },
|
|
1600
|
+
...usage && { usage }
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
600
1603
|
}
|
|
601
1604
|
if (operation.type !== "checkpoint")
|
|
602
1605
|
return operation;
|
|
@@ -646,14 +1649,14 @@ function operationConversationId(operation) {
|
|
|
646
1649
|
}
|
|
647
1650
|
|
|
648
1651
|
// src/agent-runtime/branch-replay.ts
|
|
649
|
-
var BranchBaselineSchema =
|
|
650
|
-
migratedAt:
|
|
651
|
-
asOf:
|
|
1652
|
+
var BranchBaselineSchema = z13.object({
|
|
1653
|
+
migratedAt: z13.iso.datetime({ offset: true }),
|
|
1654
|
+
asOf: z13.iso.datetime({ offset: true }).optional(),
|
|
652
1655
|
head: AgentRuntimeHeadSchema2,
|
|
653
|
-
messages:
|
|
654
|
-
compacted:
|
|
655
|
-
runs:
|
|
656
|
-
admissions:
|
|
1656
|
+
messages: z13.array(AgentMessageSchema2),
|
|
1657
|
+
compacted: z13.array(z13.string().min(1)).optional(),
|
|
1658
|
+
runs: z13.array(AgentStoredRunSchema2),
|
|
1659
|
+
admissions: z13.array(AgentAdmissionReceiptSchema2)
|
|
657
1660
|
}).strict();
|
|
658
1661
|
function branchTransition(event) {
|
|
659
1662
|
const checkpoint = AgentStoreCheckpointRecordSchema.safeParse(event.payload);
|
|
@@ -866,6 +1869,8 @@ async function persistRuntimeReplay(driver, tx, replay) {
|
|
|
866
1869
|
messages: baseline.messages,
|
|
867
1870
|
compactedMessageIds: baseline.compacted ?? []
|
|
868
1871
|
});
|
|
1872
|
+
else if (baseline.compacted?.length)
|
|
1873
|
+
throw new AgentStoreUnsupportedCapabilityError2("historyRestore", "the baseline carries compacted history");
|
|
869
1874
|
else
|
|
870
1875
|
for (const message of baseline.messages)
|
|
871
1876
|
await driver.history.apply(tx, { type: "admit", input: message });
|
|
@@ -892,6 +1897,17 @@ function exportConversation(driver, conversationId) {
|
|
|
892
1897
|
}
|
|
893
1898
|
async function importConversation(driver, bytes) {
|
|
894
1899
|
const archive = decodeAgentConversationArchive2(bytes);
|
|
1900
|
+
const snapshotEntry = archive.projections.find(isRuntimeSnapshotEntry);
|
|
1901
|
+
const snapshot = snapshotEntry === undefined ? undefined : AgentSnapshotSchema2.parse(snapshotEntry.snapshot);
|
|
1902
|
+
if (snapshot && snapshot.conversationId !== archive.conversationId) {
|
|
1903
|
+
throw new TypeError("Conversation archive snapshot belongs to another conversation");
|
|
1904
|
+
}
|
|
1905
|
+
const replay = snapshot && replayBranchEvents(archive.conversationId, archive.events, snapshot);
|
|
1906
|
+
assertSourceCapabilities(driver, {
|
|
1907
|
+
spills: archive.spills.length,
|
|
1908
|
+
projections: archive.projections.filter((entry) => !isRuntimeSnapshotEntry(entry)).length,
|
|
1909
|
+
compacted: replay?.baseline?.compacted?.length ?? 0
|
|
1910
|
+
});
|
|
895
1911
|
return driver.transaction(async (transaction) => {
|
|
896
1912
|
const existing = await driver.events.list(transaction, {
|
|
897
1913
|
conversationId: archive.conversationId,
|
|
@@ -914,12 +1930,7 @@ async function importConversation(driver, bytes) {
|
|
|
914
1930
|
throw new TypeError("Conversation archive event sequence is not contiguous");
|
|
915
1931
|
}
|
|
916
1932
|
}
|
|
917
|
-
|
|
918
|
-
if (snapshotEntry && typeof snapshotEntry === "object" && !Array.isArray(snapshotEntry)) {
|
|
919
|
-
const snapshot = AgentSnapshotSchema2.parse(snapshotEntry.snapshot);
|
|
920
|
-
if (snapshot.conversationId !== archive.conversationId) {
|
|
921
|
-
throw new TypeError("Conversation archive snapshot belongs to another conversation");
|
|
922
|
-
}
|
|
1933
|
+
if (snapshot && replay) {
|
|
923
1934
|
if (snapshot.version > 0 || snapshot.messages.length > 0 || snapshot.runs.length > 0) {
|
|
924
1935
|
const outcome = await driver.head.compareAndSwap(transaction, {
|
|
925
1936
|
conversationId: snapshot.conversationId,
|
|
@@ -934,7 +1945,6 @@ async function importConversation(driver, bytes) {
|
|
|
934
1945
|
throw new TypeError("Conversation archive snapshot target is not empty");
|
|
935
1946
|
}
|
|
936
1947
|
}
|
|
937
|
-
const replay = replayBranchEvents(archive.conversationId, archive.events, snapshot);
|
|
938
1948
|
await persistRuntimeReplay(driver, transaction, replay);
|
|
939
1949
|
for (const run of snapshot.runs) {
|
|
940
1950
|
const terminalAssistant = snapshot.messages.find((message) => message.id === run.assistantMessageId);
|
|
@@ -979,7 +1989,7 @@ async function exportConversationIn(driver, transaction, conversationId) {
|
|
|
979
1989
|
conversationId,
|
|
980
1990
|
events,
|
|
981
1991
|
projections: [
|
|
982
|
-
{ archiveType: "runtime-snapshot", snapshot:
|
|
1992
|
+
{ archiveType: "runtime-snapshot", snapshot: z14.json().parse(snapshot) },
|
|
983
1993
|
...durable.projections
|
|
984
1994
|
],
|
|
985
1995
|
spills: durable.spills
|
|
@@ -988,94 +1998,183 @@ async function exportConversationIn(driver, transaction, conversationId) {
|
|
|
988
1998
|
|
|
989
1999
|
// src/agent-runtime/store-branch.ts
|
|
990
2000
|
import { createHash as createHash7 } from "node:crypto";
|
|
991
|
-
import { z as
|
|
2001
|
+
import { z as z23 } from "zod";
|
|
992
2002
|
|
|
993
2003
|
// src/agent-runtime/branch-events.ts
|
|
994
|
-
import { z as
|
|
2004
|
+
import { z as z20 } from "zod";
|
|
995
2005
|
|
|
996
2006
|
// src/agent-runtime/branch-messages.ts
|
|
997
|
-
import { z as
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
for (const key of [
|
|
1003
|
-
"reference",
|
|
1004
|
-
"conversationId",
|
|
1005
|
-
"runId",
|
|
1006
|
-
"messageId",
|
|
1007
|
-
"callId",
|
|
1008
|
-
"toolCallId",
|
|
1009
|
-
"approvalId",
|
|
1010
|
-
"operationId",
|
|
1011
|
-
"artifactId"
|
|
1012
|
-
]) {
|
|
1013
|
-
if (!(key in value))
|
|
1014
|
-
continue;
|
|
1015
|
-
const entry = value[key];
|
|
1016
|
-
if (!ids.isApplicationKey(key))
|
|
1017
|
-
throw new TypeError(`Branch cannot rekey an opaque payload containing ${key}; declare it in applicationKeys if it is application data`);
|
|
1018
|
-
if (typeof entry === "string" && ids.isSourceIdentity(entry))
|
|
1019
|
-
throw new TypeError(`Branch cannot carry a source identity under the application key ${key}`);
|
|
1020
|
-
}
|
|
1021
|
-
for (const entry of Object.values(value))
|
|
1022
|
-
branchOpaqueJson(ids, entry);
|
|
1023
|
-
}
|
|
1024
|
-
return value;
|
|
1025
|
-
}
|
|
1026
|
-
var ArtifactReadSchema = z5.object({
|
|
1027
|
-
reference: z5.string(),
|
|
1028
|
-
offset: z5.int().nonnegative(),
|
|
1029
|
-
maxBytes: z5.int().positive().optional()
|
|
1030
|
-
}).strict();
|
|
1031
|
-
var ArtifactSearchSchema = z5.object({
|
|
1032
|
-
reference: z5.string(),
|
|
1033
|
-
query: z5.string(),
|
|
1034
|
-
maxMatches: z5.int().positive().optional()
|
|
1035
|
-
}).strict();
|
|
1036
|
-
var ArtifactReadResultSchema = z5.object({
|
|
1037
|
-
reference: z5.string(),
|
|
1038
|
-
offset: z5.int().nonnegative(),
|
|
1039
|
-
text: z5.string(),
|
|
1040
|
-
bytes: z5.int().nonnegative(),
|
|
1041
|
-
totalBytes: z5.int().nonnegative().optional()
|
|
1042
|
-
}).strict();
|
|
1043
|
-
var ArtifactSearchResultSchema = z5.object({
|
|
1044
|
-
reference: z5.string(),
|
|
1045
|
-
matches: z5.array(z5.object({ line: z5.int().positive(), text: z5.string() }).strict())
|
|
1046
|
-
}).strict();
|
|
1047
|
-
function branchToolJson(ids, name, value, output) {
|
|
2007
|
+
import { z as z16 } from "zod";
|
|
2008
|
+
|
|
2009
|
+
// src/agent-runtime/branch-runtime-tools.ts
|
|
2010
|
+
import { z as z15 } from "zod";
|
|
2011
|
+
function codingToolRecord(ids, name, value, output) {
|
|
1048
2012
|
if (name === AGENT_CODING_TOOL_NAMES.readOutput || name === AGENT_CODING_TOOL_NAMES.searchOutput) {
|
|
1049
|
-
const
|
|
1050
|
-
|
|
2013
|
+
const schema = output ? name === AGENT_CODING_TOOL_NAMES.readOutput ? ArtifactReadOutputSchema : ArtifactSearchOutputSchema : name === AGENT_CODING_TOOL_NAMES.readOutput ? ArtifactReadInputSchema : ArtifactSearchInputSchema;
|
|
2014
|
+
const parsed = schema.safeParse(value);
|
|
2015
|
+
if (!parsed.success)
|
|
2016
|
+
return;
|
|
2017
|
+
return { ...parsed.data, reference: ids.reference("spill", parsed.data.reference) };
|
|
1051
2018
|
}
|
|
1052
2019
|
if (output && name === AGENT_CODING_TOOL_NAMES.runCommand) {
|
|
1053
|
-
const parsed = ShellOutputSchema.
|
|
2020
|
+
const parsed = ShellOutputSchema.safeParse(value);
|
|
2021
|
+
if (!parsed.success)
|
|
2022
|
+
return;
|
|
1054
2023
|
return {
|
|
1055
|
-
...parsed,
|
|
1056
|
-
...parsed.artifact && {
|
|
2024
|
+
...parsed.data,
|
|
2025
|
+
...parsed.data.artifact && {
|
|
1057
2026
|
artifact: {
|
|
1058
|
-
...parsed.artifact,
|
|
1059
|
-
reference: ids.reference("spill", parsed.artifact.reference)
|
|
2027
|
+
...parsed.data.artifact,
|
|
2028
|
+
reference: ids.reference("spill", parsed.data.artifact.reference)
|
|
1060
2029
|
}
|
|
1061
2030
|
}
|
|
1062
2031
|
};
|
|
1063
2032
|
}
|
|
1064
|
-
return
|
|
2033
|
+
return;
|
|
2034
|
+
}
|
|
2035
|
+
function selectionReceipt(ids, value) {
|
|
2036
|
+
const receipt = DeferredAgentToolReceiptSchema2.safeParse(value);
|
|
2037
|
+
if (!receipt.success || canonicalAgentJson2(receipt.data) !== canonicalAgentJson2(value))
|
|
2038
|
+
return;
|
|
2039
|
+
if (!ids.sourceIdentitiesOf(receipt.data.runId).has("run"))
|
|
2040
|
+
return;
|
|
2041
|
+
return { ...receipt.data, runId: ids.reference("run", receipt.data.runId) };
|
|
2042
|
+
}
|
|
2043
|
+
var PayloadEventSchema = z15.object({ kind: z15.literal("provider/payload"), payload: z15.json() }).passthrough();
|
|
2044
|
+
var PayloadObservationSchema = z15.object({
|
|
2045
|
+
kind: z15.literal("runtime/branch-observation"),
|
|
2046
|
+
payload: z15.object({ sourceKind: z15.literal("provider/payload"), payload: z15.json() })
|
|
2047
|
+
}).passthrough();
|
|
2048
|
+
function withoutPayloadBody(event) {
|
|
2049
|
+
const stripped = (payload) => {
|
|
2050
|
+
const receipt = InvocationPayloadReceiptSchema.safeParse(payload);
|
|
2051
|
+
if (!receipt.success)
|
|
2052
|
+
return payload;
|
|
2053
|
+
const { iv: _iv, tag: _tag, ciphertext: _body, ...rest } = receipt.data;
|
|
2054
|
+
return rest;
|
|
2055
|
+
};
|
|
2056
|
+
const raw = PayloadEventSchema.safeParse(event);
|
|
2057
|
+
if (raw.success)
|
|
2058
|
+
return { ...raw.data, payload: stripped(raw.data.payload) };
|
|
2059
|
+
const observed = PayloadObservationSchema.safeParse(event);
|
|
2060
|
+
if (observed.success)
|
|
2061
|
+
return {
|
|
2062
|
+
...observed.data,
|
|
2063
|
+
payload: { ...observed.data.payload, payload: stripped(observed.data.payload.payload) }
|
|
2064
|
+
};
|
|
2065
|
+
return event;
|
|
2066
|
+
}
|
|
2067
|
+
function eventSearchSchemas(name) {
|
|
2068
|
+
return Object.entries(AGENT_EVENT_SEARCH_TOOL_SCHEMAS).find(([tool]) => tool === name)?.[1];
|
|
2069
|
+
}
|
|
2070
|
+
function eventSearchRecord(name, value, output) {
|
|
2071
|
+
const schemas = eventSearchSchemas(name);
|
|
2072
|
+
if (!schemas)
|
|
2073
|
+
return;
|
|
2074
|
+
if (!output) {
|
|
2075
|
+
const keys = Object.keys(schemas.input.shape);
|
|
2076
|
+
const isInput = value !== null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).every((key) => keys.includes(key));
|
|
2077
|
+
return isInput ? value : undefined;
|
|
2078
|
+
}
|
|
2079
|
+
if (!schemas.output.safeParse(value).success)
|
|
2080
|
+
return;
|
|
2081
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
2082
|
+
return value;
|
|
2083
|
+
const events = value.events;
|
|
2084
|
+
if (Array.isArray(events))
|
|
2085
|
+
return { ...value, events: events.map(withoutPayloadBody) };
|
|
2086
|
+
return withoutPayloadBody(value);
|
|
2087
|
+
}
|
|
2088
|
+
function branchRuntimeToolRecord(ids, name, value, output) {
|
|
2089
|
+
return codingToolRecord(ids, name, value, output) ?? (output ? selectionReceipt(ids, value) : undefined) ?? eventSearchRecord(name, value, output);
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
// src/agent-runtime/branch-messages.ts
|
|
2093
|
+
var RETAINABLE = new Set(["conversation", "run", "message"]);
|
|
2094
|
+
var RUNTIME_REFERENCE_KEYS = new Set(BRANCH_RUNTIME_REFERENCE_KEYS);
|
|
2095
|
+
function branchOpaqueJson(ids, value, path = "") {
|
|
2096
|
+
if (Array.isArray(value)) {
|
|
2097
|
+
return value.map((entry, index) => branchOpaqueJson(ids, entry, `${path}[${index}]`));
|
|
2098
|
+
}
|
|
2099
|
+
if (value !== null && typeof value === "object") {
|
|
2100
|
+
return branchOpaqueRecord(ids, value, path);
|
|
2101
|
+
}
|
|
2102
|
+
return value;
|
|
2103
|
+
}
|
|
2104
|
+
function branchOpaqueRecord(ids, value, path = "") {
|
|
2105
|
+
const out = {};
|
|
2106
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
2107
|
+
const at = path ? `${path}.${key}` : key;
|
|
2108
|
+
if (!RUNTIME_REFERENCE_KEYS.has(key)) {
|
|
2109
|
+
out[key] = branchOpaqueJson(ids, entry, at);
|
|
2110
|
+
continue;
|
|
2111
|
+
}
|
|
2112
|
+
const mode = ids.applicationKey(key);
|
|
2113
|
+
if (mode === undefined) {
|
|
2114
|
+
ids.refuse({
|
|
2115
|
+
code: "application-key-undeclared",
|
|
2116
|
+
message: `Branch cannot rekey an opaque payload containing ${key} at ${at}; declare it in applicationKeys if it is application data`,
|
|
2117
|
+
key,
|
|
2118
|
+
path: at
|
|
2119
|
+
});
|
|
2120
|
+
out[key] = branchOpaqueJson(ids, entry, at);
|
|
2121
|
+
continue;
|
|
2122
|
+
}
|
|
2123
|
+
if (mode === "rekey-spill") {
|
|
2124
|
+
if (typeof entry === "string") {
|
|
2125
|
+
const kinds = ids.sourceIdentitiesOf(entry);
|
|
2126
|
+
if (kinds.size === 1 && kinds.has("spill")) {
|
|
2127
|
+
out[key] = ids.reference("spill", entry);
|
|
2128
|
+
} else {
|
|
2129
|
+
ids.refuse({
|
|
2130
|
+
code: "application-key-source-identity",
|
|
2131
|
+
message: `Branch cannot rekey non-spill or foreign value under the application key ${key} at ${at}`,
|
|
2132
|
+
key,
|
|
2133
|
+
path: at
|
|
2134
|
+
});
|
|
2135
|
+
out[key] = entry;
|
|
2136
|
+
}
|
|
2137
|
+
} else {
|
|
2138
|
+
out[key] = branchOpaqueJson(ids, entry, at);
|
|
2139
|
+
}
|
|
2140
|
+
continue;
|
|
2141
|
+
}
|
|
2142
|
+
if (typeof entry === "string") {
|
|
2143
|
+
for (const kind of ids.sourceIdentitiesOf(entry)) {
|
|
2144
|
+
if (mode === "retain" && RETAINABLE.has(kind))
|
|
2145
|
+
continue;
|
|
2146
|
+
ids.refuse({
|
|
2147
|
+
code: "application-key-source-identity",
|
|
2148
|
+
message: mode === "retain" ? `Branch cannot carry a source ${kind} under the application key ${key} at ${at}` : `Branch cannot carry a source identity under the application key ${key} at ${at}`,
|
|
2149
|
+
key,
|
|
2150
|
+
path: at
|
|
2151
|
+
});
|
|
2152
|
+
break;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
out[key] = branchOpaqueJson(ids, entry, at);
|
|
2156
|
+
}
|
|
2157
|
+
return out;
|
|
2158
|
+
}
|
|
2159
|
+
function branchToolJson(ids, name, value, output) {
|
|
2160
|
+
return branchRuntimeToolRecord(ids, name, value, output) ?? branchOpaqueJson(ids, value);
|
|
1065
2161
|
}
|
|
1066
2162
|
function branchPart(ids, part) {
|
|
2163
|
+
return "toolName" in part && typeof part.toolName === "string" ? ids.within({ toolName: part.toolName }, () => branchPartAt(ids, part)) : branchPartAt(ids, part);
|
|
2164
|
+
}
|
|
2165
|
+
function branchPartAt(ids, part) {
|
|
1067
2166
|
switch (part.type) {
|
|
1068
2167
|
case "file":
|
|
1069
2168
|
return { ...part, reference: ids.fileReference(part.reference) };
|
|
1070
|
-
case "tool-call":
|
|
1071
|
-
if (part.provider)
|
|
1072
|
-
branchOpaqueJson(ids, part.provider.data);
|
|
2169
|
+
case "tool-call":
|
|
1073
2170
|
return {
|
|
1074
2171
|
...part,
|
|
2172
|
+
...part.provider && {
|
|
2173
|
+
provider: { ...part.provider, data: branchOpaqueRecord(ids, part.provider.data) }
|
|
2174
|
+
},
|
|
1075
2175
|
callId: ids.reference("call", part.callId),
|
|
1076
2176
|
input: branchToolJson(ids, part.toolName, part.input, false)
|
|
1077
2177
|
};
|
|
1078
|
-
}
|
|
1079
2178
|
case "tool-result":
|
|
1080
2179
|
return {
|
|
1081
2180
|
...part,
|
|
@@ -1095,9 +2194,10 @@ function branchPart(ids, part) {
|
|
|
1095
2194
|
case "provider":
|
|
1096
2195
|
throw new TypeError("Branch cannot rekey an opaque provider part");
|
|
1097
2196
|
case "reasoning":
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
2197
|
+
return part.provider ? {
|
|
2198
|
+
...part,
|
|
2199
|
+
provider: { ...part.provider, data: branchOpaqueRecord(ids, part.provider.data) }
|
|
2200
|
+
} : part;
|
|
1101
2201
|
default:
|
|
1102
2202
|
return part;
|
|
1103
2203
|
}
|
|
@@ -1105,16 +2205,16 @@ function branchPart(ids, part) {
|
|
|
1105
2205
|
function branchMessage(ids, sourceConversationId, message) {
|
|
1106
2206
|
if (message.conversationId !== sourceConversationId)
|
|
1107
2207
|
throw new TypeError("Branch message belongs to another conversation");
|
|
1108
|
-
return {
|
|
2208
|
+
return ids.within({ messageId: message.id }, () => ({
|
|
1109
2209
|
...message,
|
|
1110
2210
|
id: ids.reference("message", message.id),
|
|
1111
2211
|
conversationId: ids.conversationId,
|
|
1112
2212
|
...message.runId && { runId: ids.reference("run", message.runId) },
|
|
1113
2213
|
parts: message.parts.map((part) => branchPart(ids, part)),
|
|
1114
2214
|
...message.metadata && {
|
|
1115
|
-
metadata:
|
|
2215
|
+
metadata: z16.record(z16.string(), z16.json()).parse(branchOpaqueJson(ids, message.metadata))
|
|
1116
2216
|
}
|
|
1117
|
-
};
|
|
2217
|
+
}));
|
|
1118
2218
|
}
|
|
1119
2219
|
function branchRun(ids, sourceConversationId, run, settled) {
|
|
1120
2220
|
if (run.conversationId !== sourceConversationId)
|
|
@@ -1141,137 +2241,263 @@ function branchRun(ids, sourceConversationId, run, settled) {
|
|
|
1141
2241
|
}
|
|
1142
2242
|
|
|
1143
2243
|
// src/agent-runtime/branch-observations.ts
|
|
1144
|
-
import { z as
|
|
1145
|
-
var Id =
|
|
1146
|
-
var Hash2 =
|
|
1147
|
-
var State =
|
|
2244
|
+
import { z as z17 } from "zod";
|
|
2245
|
+
var Id = z17.string().min(1);
|
|
2246
|
+
var Hash2 = z17.string().regex(/^[a-f0-9]{64}$/);
|
|
2247
|
+
var State = z17.object({
|
|
1148
2248
|
name: Id,
|
|
1149
|
-
version:
|
|
1150
|
-
value:
|
|
1151
|
-
actor:
|
|
2249
|
+
version: z17.int().positive(),
|
|
2250
|
+
value: z17.json(),
|
|
2251
|
+
actor: z17.enum(["agent", "human", "system"])
|
|
1152
2252
|
}).strict();
|
|
1153
|
-
var Retry =
|
|
1154
|
-
attempt:
|
|
1155
|
-
delayMs:
|
|
1156
|
-
reason:
|
|
2253
|
+
var Retry = z17.object({
|
|
2254
|
+
attempt: z17.int().positive(),
|
|
2255
|
+
delayMs: z17.number().nonnegative().optional(),
|
|
2256
|
+
reason: z17.string().optional()
|
|
1157
2257
|
}).strict();
|
|
1158
|
-
var
|
|
1159
|
-
var Schedule =
|
|
2258
|
+
var SpillEventPayloadSchema = z17.object({ reference: Id, bytes: z17.int().nonnegative(), sha256: Hash2.optional() }).strict();
|
|
2259
|
+
var Schedule = z17.object({
|
|
1160
2260
|
id: Id,
|
|
1161
|
-
kind:
|
|
1162
|
-
nextAt:
|
|
1163
|
-
occurrence:
|
|
1164
|
-
lateByMs:
|
|
1165
|
-
state:
|
|
1166
|
-
message:
|
|
1167
|
-
attempts:
|
|
1168
|
-
retryAt:
|
|
1169
|
-
terminal:
|
|
1170
|
-
skipped:
|
|
2261
|
+
kind: z17.enum(["at", "after", "every"]).optional(),
|
|
2262
|
+
nextAt: z17.string().nullable().optional(),
|
|
2263
|
+
occurrence: z17.int().nonnegative().optional(),
|
|
2264
|
+
lateByMs: z17.number().nonnegative().optional(),
|
|
2265
|
+
state: z17.string().optional(),
|
|
2266
|
+
message: z17.string().optional(),
|
|
2267
|
+
attempts: z17.int().nonnegative().optional(),
|
|
2268
|
+
retryAt: z17.string().nullable().optional(),
|
|
2269
|
+
terminal: z17.boolean().optional(),
|
|
2270
|
+
skipped: z17.boolean().optional()
|
|
1171
2271
|
}).strict();
|
|
1172
|
-
var
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
2272
|
+
var Rejection = z17.object({ approvalId: Id, callId: Id, toolName: Id, reason: z17.string() }).strict();
|
|
2273
|
+
function durability(ids, raw, kind) {
|
|
2274
|
+
const value = kind === "durability/step" ? StepEventPayloadSchema.parse(raw) : kind === "durability/park" ? ParkEventPayloadSchema.parse(raw) : kind === "durability/event" ? DeliveredEventPayloadSchema.parse(raw) : EffectEventPayloadSchema.parse(raw);
|
|
2275
|
+
if (canonicalAgentJson2(value) !== canonicalAgentJson2(raw))
|
|
2276
|
+
throw new TypeError("Branch cannot rekey opaque durability payload");
|
|
2277
|
+
const encoded = "encoded" in value ? JSON.stringify(branchOpaqueJson(ids, z17.json().parse(JSON.parse(value.encoded)))) : undefined;
|
|
2278
|
+
return {
|
|
2279
|
+
...value,
|
|
2280
|
+
...encoded !== undefined && { encoded },
|
|
2281
|
+
runId: ids.reference("run", value.runId),
|
|
2282
|
+
..."id" in value && { id: ids.define("key", value.id) }
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
function spill(ids, raw) {
|
|
2286
|
+
const value = SpillEventPayloadSchema.parse(raw);
|
|
2287
|
+
return { ...value, reference: ids.reference("spill", value.reference) };
|
|
2288
|
+
}
|
|
2289
|
+
function schedule(ids, raw) {
|
|
2290
|
+
const value = Schedule.parse(raw);
|
|
2291
|
+
return { ...value, id: ids.define("schedule", value.id) };
|
|
2292
|
+
}
|
|
2293
|
+
function rekeyChildConversation(ids, conversationId) {
|
|
2294
|
+
return conversationId === ids.sourceConversationId ? ids.conversationId : ids.define("child", conversationId);
|
|
2295
|
+
}
|
|
2296
|
+
function childSpawned(ids, raw) {
|
|
2297
|
+
const value = ChildSpawnedEventPayloadSchema.parse(raw);
|
|
2298
|
+
return {
|
|
2299
|
+
...value,
|
|
2300
|
+
childConversationId: rekeyChildConversation(ids, value.childConversationId)
|
|
2301
|
+
};
|
|
2302
|
+
}
|
|
2303
|
+
function childState(ids, raw) {
|
|
2304
|
+
const value = ChildStateEventPayloadSchema.parse(raw);
|
|
2305
|
+
if ("action" in value) {
|
|
2306
|
+
if (value.action === "blocking-presented") {
|
|
2307
|
+
return {
|
|
2308
|
+
...value,
|
|
2309
|
+
input: branchOpaqueJson(ids, value.input),
|
|
2310
|
+
childConversationId: rekeyChildConversation(ids, value.childConversationId),
|
|
2311
|
+
approvalId: ids.define("approval", value.approvalId),
|
|
2312
|
+
childApprovalId: ids.define("approval", value.childApprovalId),
|
|
2313
|
+
callId: ids.define("call", value.callId),
|
|
2314
|
+
batchId: ids.define("key", value.batchId)
|
|
2315
|
+
};
|
|
2316
|
+
}
|
|
2317
|
+
if (value.action === "blocking-resolved") {
|
|
2318
|
+
return {
|
|
2319
|
+
...value,
|
|
2320
|
+
childConversationId: rekeyChildConversation(ids, value.childConversationId),
|
|
2321
|
+
approvalId: ids.define("approval", value.approvalId),
|
|
2322
|
+
batchId: ids.define("key", value.batchId)
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
1199
2325
|
return {
|
|
1200
2326
|
...value,
|
|
1201
|
-
|
|
1202
|
-
..."id" in value && { id: ids.define("key", value.id) }
|
|
2327
|
+
childConversationId: rekeyChildConversation(ids, value.childConversationId)
|
|
1203
2328
|
};
|
|
1204
2329
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
2330
|
+
return {
|
|
2331
|
+
...value,
|
|
2332
|
+
...value.childConversationId && {
|
|
2333
|
+
childConversationId: rekeyChildConversation(ids, value.childConversationId)
|
|
2334
|
+
},
|
|
2335
|
+
...value.parentConversationId && {
|
|
2336
|
+
parentConversationId: rekeyChildConversation(ids, value.parentConversationId)
|
|
2337
|
+
},
|
|
2338
|
+
...value.resultReference && {
|
|
2339
|
+
resultReference: ids.reference("spill", value.resultReference)
|
|
2340
|
+
}
|
|
2341
|
+
};
|
|
2342
|
+
}
|
|
2343
|
+
function invocation(ids, value, inherited) {
|
|
2344
|
+
if (inherited)
|
|
1214
2345
|
return value;
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
2346
|
+
if (value.conversationId !== ids.sourceConversationId)
|
|
2347
|
+
throw new TypeError("Branch invocation record belongs to another conversation");
|
|
2348
|
+
if (value.runId !== undefined)
|
|
2349
|
+
ids.reference("run", value.runId);
|
|
2350
|
+
return value;
|
|
2351
|
+
}
|
|
2352
|
+
function invocationPayload(ids, raw, inherited) {
|
|
2353
|
+
const {
|
|
2354
|
+
iv: _iv,
|
|
2355
|
+
tag: _tag,
|
|
2356
|
+
ciphertext: _body,
|
|
2357
|
+
...receipt
|
|
2358
|
+
} = InvocationPayloadReceiptSchema.parse(raw);
|
|
2359
|
+
return invocation(ids, receipt, inherited);
|
|
2360
|
+
}
|
|
2361
|
+
var retry = (_ids, raw) => Retry.parse(raw);
|
|
2362
|
+
var OBSERVATION_RULES = {
|
|
2363
|
+
"durability/step": durability,
|
|
2364
|
+
"durability/park": durability,
|
|
2365
|
+
"durability/event": durability,
|
|
2366
|
+
"durability/effect": durability,
|
|
2367
|
+
"sandbox/probed": (_ids, raw) => z17.object({
|
|
2368
|
+
result: AgentSandboxGradeSchema2,
|
|
2369
|
+
required: z17.array(AgentSandboxRestrictionSchema2),
|
|
2370
|
+
missing: z17.array(AgentSandboxRestrictionSchema2)
|
|
2371
|
+
}).strict().parse(raw),
|
|
2372
|
+
"state/set": (ids, raw) => {
|
|
2373
|
+
const value = State.parse(raw);
|
|
2374
|
+
return { ...value, value: branchOpaqueJson(ids, value.value) };
|
|
2375
|
+
},
|
|
2376
|
+
"retry/scheduled": retry,
|
|
2377
|
+
"retry/started": retry,
|
|
2378
|
+
"spill/created": spill,
|
|
2379
|
+
"spill/deleted": spill,
|
|
2380
|
+
"schedule/set": schedule,
|
|
2381
|
+
"schedule/fired": schedule,
|
|
2382
|
+
"schedule/cancelled": schedule,
|
|
2383
|
+
"schedule/late": schedule,
|
|
2384
|
+
"schedule/failed": schedule,
|
|
2385
|
+
"child/spawned": childSpawned,
|
|
2386
|
+
"child/state": childState,
|
|
2387
|
+
"approval/response-rejected": (ids, raw) => {
|
|
1252
2388
|
const value = Rejection.parse(raw);
|
|
1253
2389
|
return {
|
|
1254
2390
|
...value,
|
|
1255
2391
|
approvalId: ids.reference("approval", value.approvalId),
|
|
1256
2392
|
callId: ids.reference("call", value.callId)
|
|
1257
2393
|
};
|
|
2394
|
+
},
|
|
2395
|
+
"invocation/started": (ids, raw, _kind, inherited) => invocation(ids, InvocationStartedSchema.parse(raw), inherited),
|
|
2396
|
+
"invocation/finished": (ids, raw, _kind, inherited) => invocation(ids, InvocationFinishedSchema.parse(raw), inherited),
|
|
2397
|
+
"provider/request": (ids, raw, _kind, inherited) => invocation(ids, InvocationRequestSchema.parse(raw), inherited),
|
|
2398
|
+
"provider/response": (ids, raw, _kind, inherited) => invocation(ids, InvocationResponseSchema.parse(raw), inherited),
|
|
2399
|
+
"provider/payload": (ids, raw, _kind, inherited) => invocationPayload(ids, raw, inherited)
|
|
2400
|
+
};
|
|
2401
|
+
function isObservedKind(kind) {
|
|
2402
|
+
return Object.hasOwn(OBSERVATION_RULES, kind);
|
|
2403
|
+
}
|
|
2404
|
+
function branchObservation(ids, kind, raw, inherited = false) {
|
|
2405
|
+
if (!isObservedKind(kind)) {
|
|
2406
|
+
ids.refuse({
|
|
2407
|
+
code: "event-kind-unknown",
|
|
2408
|
+
message: `Branch cannot rekey opaque event kind ${kind}`
|
|
2409
|
+
});
|
|
2410
|
+
return raw;
|
|
1258
2411
|
}
|
|
1259
|
-
|
|
2412
|
+
return OBSERVATION_RULES[kind](ids, raw, kind, inherited);
|
|
1260
2413
|
}
|
|
1261
|
-
var
|
|
2414
|
+
var Defines = z17.object({
|
|
2415
|
+
id: Id.optional(),
|
|
2416
|
+
childConversationId: Id.optional(),
|
|
2417
|
+
parentConversationId: Id.optional(),
|
|
2418
|
+
approvalId: Id.optional(),
|
|
2419
|
+
childApprovalId: Id.optional(),
|
|
2420
|
+
callId: Id.optional(),
|
|
2421
|
+
batchId: Id.optional()
|
|
2422
|
+
}).passthrough();
|
|
2423
|
+
function collectObservationDefinitions(ids, kind, raw) {
|
|
2424
|
+
const value = Defines.safeParse(raw);
|
|
2425
|
+
if (!value.success)
|
|
2426
|
+
return;
|
|
2427
|
+
const {
|
|
2428
|
+
id,
|
|
2429
|
+
childConversationId,
|
|
2430
|
+
parentConversationId,
|
|
2431
|
+
approvalId,
|
|
2432
|
+
childApprovalId,
|
|
2433
|
+
callId,
|
|
2434
|
+
batchId
|
|
2435
|
+
} = value.data;
|
|
2436
|
+
if (kind.startsWith("durability/") && id)
|
|
2437
|
+
ids.define("key", id);
|
|
2438
|
+
if (kind.startsWith("schedule/") && id)
|
|
2439
|
+
ids.define("schedule", id);
|
|
2440
|
+
if (!kind.startsWith("child/"))
|
|
2441
|
+
return;
|
|
2442
|
+
for (const child of [childConversationId, parentConversationId])
|
|
2443
|
+
if (child && child !== ids.sourceConversationId)
|
|
2444
|
+
ids.define("child", child);
|
|
2445
|
+
if (approvalId)
|
|
2446
|
+
ids.define("approval", approvalId);
|
|
2447
|
+
if (childApprovalId)
|
|
2448
|
+
ids.define("approval", childApprovalId);
|
|
2449
|
+
if (callId)
|
|
2450
|
+
ids.define("call", callId);
|
|
2451
|
+
if (batchId)
|
|
2452
|
+
ids.define("key", batchId);
|
|
2453
|
+
}
|
|
2454
|
+
var BranchObservationSchema = z17.object({ sourceKind: Id, payload: z17.json() }).strict();
|
|
1262
2455
|
|
|
1263
2456
|
// src/agent-runtime/branch-provider.ts
|
|
1264
2457
|
import { createHash as createHash3 } from "node:crypto";
|
|
2458
|
+
import { z as z18 } from "zod";
|
|
2459
|
+
var ProviderOptionsRecordSchema = z18.record(z18.string(), z18.record(z18.string(), z18.json()));
|
|
2460
|
+
var ReferenceRecordSchema = z18.record(z18.string(), z18.string()).refine((value) => !("type" in value), "Provider reference cannot contain a file discriminator");
|
|
1265
2461
|
function hash(value) {
|
|
1266
2462
|
return createHash3("sha256").update(canonicalAgentJson2(value)).digest("hex");
|
|
1267
2463
|
}
|
|
1268
|
-
function
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
2464
|
+
function rekeyProviderOptions(ids, options) {
|
|
2465
|
+
return ProviderOptionsRecordSchema.parse(branchOpaqueJson(ids, options));
|
|
2466
|
+
}
|
|
2467
|
+
function rekeyReference(ids, value) {
|
|
2468
|
+
return ReferenceRecordSchema.parse(branchOpaqueJson(ids, value));
|
|
2469
|
+
}
|
|
2470
|
+
function rekeyContentFileData(ids, value) {
|
|
2471
|
+
if (value.type === "reference") {
|
|
2472
|
+
return { ...value, reference: rekeyReference(ids, value.reference) };
|
|
2473
|
+
}
|
|
2474
|
+
return value;
|
|
2475
|
+
}
|
|
2476
|
+
function isBinaryMarker(value) {
|
|
2477
|
+
return "binary" in value && value.binary === true;
|
|
2478
|
+
}
|
|
2479
|
+
function rekeyFilePartData(ids, value) {
|
|
2480
|
+
if (typeof value === "string")
|
|
2481
|
+
return value;
|
|
2482
|
+
if (isBinaryMarker(value))
|
|
2483
|
+
return value;
|
|
2484
|
+
if ("type" in value) {
|
|
2485
|
+
if (value.type === "reference" && "reference" in value && typeof value.reference === "object" && value.reference !== null) {
|
|
2486
|
+
return { type: "reference", reference: rekeyReference(ids, value.reference) };
|
|
2487
|
+
}
|
|
2488
|
+
return value;
|
|
2489
|
+
}
|
|
2490
|
+
return rekeyReference(ids, value);
|
|
2491
|
+
}
|
|
2492
|
+
function rekeyImagePartData(ids, value) {
|
|
2493
|
+
if (typeof value === "string")
|
|
2494
|
+
return value;
|
|
2495
|
+
if (isBinaryMarker(value))
|
|
2496
|
+
return value;
|
|
2497
|
+
return rekeyReference(ids, value);
|
|
2498
|
+
}
|
|
2499
|
+
function rekeyReasoningFileData(_ids, value) {
|
|
2500
|
+
return value;
|
|
1275
2501
|
}
|
|
1276
2502
|
|
|
1277
2503
|
class BranchProvider {
|
|
@@ -1285,62 +2511,11 @@ class BranchProvider {
|
|
|
1285
2511
|
const value = ProviderJournalMessageSchema.parse(raw);
|
|
1286
2512
|
if (hash(value.message) !== value.sha256)
|
|
1287
2513
|
throw new TypeError("Branch provider message digest is inconsistent");
|
|
1288
|
-
|
|
1289
|
-
branchOpaqueJson(this.ids, value.message.providerOptions);
|
|
2514
|
+
const rekeyedMessageOptions = value.message.providerOptions ? rekeyProviderOptions(this.ids, value.message.providerOptions) : undefined;
|
|
1290
2515
|
const message = {
|
|
1291
2516
|
...value.message,
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
branchOpaqueJson(this.ids, part.providerOptions);
|
|
1295
|
-
if (part.type === "file" || part.type === "reasoning-file")
|
|
1296
|
-
checkFileData(this.ids, part.data);
|
|
1297
|
-
if (part.type === "image")
|
|
1298
|
-
checkFileData(this.ids, part.image);
|
|
1299
|
-
if (part.type === "tool-call")
|
|
1300
|
-
return {
|
|
1301
|
-
...part,
|
|
1302
|
-
toolCallId: this.ids.reference("call", part.toolCallId),
|
|
1303
|
-
input: branchToolJson(this.ids, part.toolName, part.input, false)
|
|
1304
|
-
};
|
|
1305
|
-
if (part.type === "tool-result") {
|
|
1306
|
-
if ("providerOptions" in part.output && part.output.providerOptions)
|
|
1307
|
-
branchOpaqueJson(this.ids, part.output.providerOptions);
|
|
1308
|
-
if (part.output.type === "error-json")
|
|
1309
|
-
branchOpaqueJson(this.ids, part.output.value);
|
|
1310
|
-
if (part.output.type === "content")
|
|
1311
|
-
for (const item of part.output.value) {
|
|
1312
|
-
if (item.providerOptions)
|
|
1313
|
-
branchOpaqueJson(this.ids, item.providerOptions);
|
|
1314
|
-
if (item.type === "file")
|
|
1315
|
-
checkFileData(this.ids, item.data);
|
|
1316
|
-
if ("providerReference" in item)
|
|
1317
|
-
branchOpaqueJson(this.ids, item.providerReference);
|
|
1318
|
-
if ("fileId" in item && typeof item.fileId !== "string")
|
|
1319
|
-
branchOpaqueJson(this.ids, item.fileId);
|
|
1320
|
-
}
|
|
1321
|
-
return {
|
|
1322
|
-
...part,
|
|
1323
|
-
toolCallId: this.ids.reference("call", part.toolCallId),
|
|
1324
|
-
output: part.output.type === "json" ? {
|
|
1325
|
-
...part.output,
|
|
1326
|
-
value: branchToolJson(this.ids, part.toolName, part.output.value, true)
|
|
1327
|
-
} : part.output
|
|
1328
|
-
};
|
|
1329
|
-
}
|
|
1330
|
-
if (part.type === "tool-approval-request")
|
|
1331
|
-
return {
|
|
1332
|
-
type: part.type,
|
|
1333
|
-
approvalId: this.ids.reference("approval", part.approvalId),
|
|
1334
|
-
toolCallId: this.ids.reference("call", part.toolCallId),
|
|
1335
|
-
...part.reason !== undefined && { reason: part.reason }
|
|
1336
|
-
};
|
|
1337
|
-
if (part.type === "tool-approval-response")
|
|
1338
|
-
return {
|
|
1339
|
-
...part,
|
|
1340
|
-
approvalId: this.ids.reference("approval", part.approvalId)
|
|
1341
|
-
};
|
|
1342
|
-
return part;
|
|
1343
|
-
})
|
|
2517
|
+
...rekeyedMessageOptions !== undefined && { providerOptions: rekeyedMessageOptions },
|
|
2518
|
+
content: typeof value.message.content === "string" ? value.message.content : value.message.content.map((part) => this.rekeyPart(part))
|
|
1344
2519
|
};
|
|
1345
2520
|
const sha256 = hash(message);
|
|
1346
2521
|
this.digests.set(value.sha256, sha256);
|
|
@@ -1367,10 +2542,92 @@ class BranchProvider {
|
|
|
1367
2542
|
const value = ProviderJournalResponseSchema.parse(raw);
|
|
1368
2543
|
return { ...value, runId: this.ids.reference("run", value.runId) };
|
|
1369
2544
|
}
|
|
2545
|
+
rekeyPart(part) {
|
|
2546
|
+
const providerOptions = "providerOptions" in part && part.providerOptions !== undefined ? rekeyProviderOptions(this.ids, part.providerOptions) : undefined;
|
|
2547
|
+
const base = providerOptions !== undefined ? { ...part, providerOptions } : part;
|
|
2548
|
+
if (base.type === "file") {
|
|
2549
|
+
return { ...base, data: rekeyFilePartData(this.ids, base.data) };
|
|
2550
|
+
}
|
|
2551
|
+
if (base.type === "reasoning-file") {
|
|
2552
|
+
return { ...base, data: rekeyReasoningFileData(this.ids, base.data) };
|
|
2553
|
+
}
|
|
2554
|
+
if (base.type === "image") {
|
|
2555
|
+
return { ...base, image: rekeyImagePartData(this.ids, base.image) };
|
|
2556
|
+
}
|
|
2557
|
+
if (base.type === "tool-call") {
|
|
2558
|
+
return {
|
|
2559
|
+
...base,
|
|
2560
|
+
toolCallId: this.ids.reference("call", base.toolCallId),
|
|
2561
|
+
input: branchToolJson(this.ids, base.toolName, base.input, false)
|
|
2562
|
+
};
|
|
2563
|
+
}
|
|
2564
|
+
if (base.type === "tool-result") {
|
|
2565
|
+
return {
|
|
2566
|
+
...base,
|
|
2567
|
+
toolCallId: this.ids.reference("call", base.toolCallId),
|
|
2568
|
+
output: this.rekeyToolResultOutput(base.toolName, base.output)
|
|
2569
|
+
};
|
|
2570
|
+
}
|
|
2571
|
+
if (base.type === "tool-approval-request") {
|
|
2572
|
+
return {
|
|
2573
|
+
type: base.type,
|
|
2574
|
+
approvalId: this.ids.reference("approval", base.approvalId),
|
|
2575
|
+
toolCallId: this.ids.reference("call", base.toolCallId),
|
|
2576
|
+
...base.reason !== undefined && { reason: base.reason }
|
|
2577
|
+
};
|
|
2578
|
+
}
|
|
2579
|
+
if (base.type === "tool-approval-response") {
|
|
2580
|
+
return {
|
|
2581
|
+
...base,
|
|
2582
|
+
approvalId: this.ids.reference("approval", base.approvalId)
|
|
2583
|
+
};
|
|
2584
|
+
}
|
|
2585
|
+
return base;
|
|
2586
|
+
}
|
|
2587
|
+
rekeyToolResultOutput(toolName, output) {
|
|
2588
|
+
const providerOptions = "providerOptions" in output && output.providerOptions !== undefined ? rekeyProviderOptions(this.ids, output.providerOptions) : undefined;
|
|
2589
|
+
if (output.type === "json") {
|
|
2590
|
+
return {
|
|
2591
|
+
...output,
|
|
2592
|
+
...providerOptions !== undefined && { providerOptions },
|
|
2593
|
+
value: branchToolJson(this.ids, toolName, output.value, true)
|
|
2594
|
+
};
|
|
2595
|
+
}
|
|
2596
|
+
if (output.type === "error-json") {
|
|
2597
|
+
return {
|
|
2598
|
+
...output,
|
|
2599
|
+
...providerOptions !== undefined && { providerOptions },
|
|
2600
|
+
value: branchOpaqueJson(this.ids, output.value)
|
|
2601
|
+
};
|
|
2602
|
+
}
|
|
2603
|
+
if (output.type === "content") {
|
|
2604
|
+
return {
|
|
2605
|
+
...output,
|
|
2606
|
+
value: output.value.map((item) => {
|
|
2607
|
+
const itemOptions = item.providerOptions !== undefined ? rekeyProviderOptions(this.ids, item.providerOptions) : undefined;
|
|
2608
|
+
const next = itemOptions !== undefined ? { ...item, providerOptions: itemOptions } : item;
|
|
2609
|
+
if (next.type === "file") {
|
|
2610
|
+
return { ...next, data: rekeyContentFileData(this.ids, next.data) };
|
|
2611
|
+
}
|
|
2612
|
+
if (next.type === "file-reference" || next.type === "image-file-reference") {
|
|
2613
|
+
return {
|
|
2614
|
+
...next,
|
|
2615
|
+
providerReference: rekeyReference(this.ids, next.providerReference)
|
|
2616
|
+
};
|
|
2617
|
+
}
|
|
2618
|
+
if ((next.type === "file-id" || next.type === "image-file-id") && typeof next.fileId !== "string") {
|
|
2619
|
+
return { ...next, fileId: rekeyReference(this.ids, next.fileId) };
|
|
2620
|
+
}
|
|
2621
|
+
return next;
|
|
2622
|
+
})
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
return providerOptions !== undefined ? { ...output, providerOptions } : output;
|
|
2626
|
+
}
|
|
1370
2627
|
}
|
|
1371
2628
|
|
|
1372
2629
|
// src/agent-runtime/branch-transitions.ts
|
|
1373
|
-
import { z as
|
|
2630
|
+
import { z as z19 } from "zod";
|
|
1374
2631
|
function rekeyBranchTransition(ids, source, operation) {
|
|
1375
2632
|
const message = (value) => branchMessage(ids, source, value);
|
|
1376
2633
|
const input = operation.input;
|
|
@@ -1420,6 +2677,7 @@ function rekeyBranchTransition(ids, source, operation) {
|
|
|
1420
2677
|
return AgentStoreTransitionSchema2.parse({
|
|
1421
2678
|
type: operation.type,
|
|
1422
2679
|
...operation.type === "recover" && operation.assistant && { assistant: message(operation.assistant) },
|
|
2680
|
+
...operation.type === "recover" && operation.usage && { usage: operation.usage },
|
|
1423
2681
|
input: {
|
|
1424
2682
|
...common,
|
|
1425
2683
|
...operation.type === "checkpoint" || operation.type === "terminal" ? { assistant: message(operation.input.assistant) } : {},
|
|
@@ -1441,30 +2699,38 @@ function rekeyBranchTransition(ids, source, operation) {
|
|
|
1441
2699
|
}
|
|
1442
2700
|
}
|
|
1443
2701
|
function branchJson(value) {
|
|
1444
|
-
return
|
|
2702
|
+
return z19.json().parse(value);
|
|
1445
2703
|
}
|
|
1446
2704
|
|
|
1447
2705
|
// src/agent-runtime/branch-events.ts
|
|
1448
|
-
var Hash3 =
|
|
2706
|
+
var Hash3 = z20.string().regex(/^[a-f0-9]{64}$/);
|
|
1449
2707
|
function rekeyBranchEvents(ids, source, events, retainedMessages = new Map) {
|
|
1450
|
-
|
|
1451
|
-
const
|
|
1452
|
-
|
|
2708
|
+
try {
|
|
2709
|
+
const hydrated = events.map((event) => atEvent(ids, event, () => {
|
|
2710
|
+
const assistant = retainedMessages.get(event.eventId);
|
|
2711
|
+
if (!assistant)
|
|
2712
|
+
return event;
|
|
2713
|
+
ids.collectMessage(assistant);
|
|
2714
|
+
const operation = event.kind === "runtime/transition" ? branchTransition(event) : undefined;
|
|
2715
|
+
if (operation?.type === "recover" && operation.input.action === "abandon" && !operation.assistant)
|
|
2716
|
+
return { ...event, payload: branchJson({ ...operation, assistant }) };
|
|
1453
2717
|
return event;
|
|
1454
|
-
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
2718
|
+
}));
|
|
2719
|
+
for (const event of hydrated)
|
|
2720
|
+
atEvent(ids, event, () => collectBranchEvent(ids, event));
|
|
2721
|
+
for (const event of hydrated) {
|
|
2722
|
+
const assistant = retainedMessages.get(event.eventId);
|
|
2723
|
+
if (assistant)
|
|
2724
|
+
atEvent(ids, event, () => branchMessage(ids, source, assistant));
|
|
2725
|
+
}
|
|
2726
|
+
const provider = new BranchProvider(ids);
|
|
2727
|
+
return hydrated.map((event) => atEvent(ids, event, () => rekeyBranchEvent(ids, source, event, provider)));
|
|
2728
|
+
} catch (error) {
|
|
2729
|
+
throw ids.integrityError(error);
|
|
1465
2730
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
2731
|
+
}
|
|
2732
|
+
function atEvent(ids, event, work) {
|
|
2733
|
+
return ids.within({ seq: event.seq, eventKind: event.kind }, work);
|
|
1468
2734
|
}
|
|
1469
2735
|
function collectBranchEvent(ids, event) {
|
|
1470
2736
|
ids.define("event", event.eventId);
|
|
@@ -1480,7 +2746,16 @@ function collectBranchEvent(ids, event) {
|
|
|
1480
2746
|
ids.collectRun(record.run);
|
|
1481
2747
|
for (const message of baseline.messages)
|
|
1482
2748
|
ids.collectMessage(message);
|
|
2749
|
+
for (const receipt of baseline.admissions)
|
|
2750
|
+
ids.define("key", receipt.idempotencyKey);
|
|
1483
2751
|
}
|
|
2752
|
+
if (event.kind === "runtime/branched")
|
|
2753
|
+
ids.define("key", AgentConversationBranchReceiptSchema2.parse(event.payload).requestKey);
|
|
2754
|
+
if (event.kind === "runtime/branch-observation") {
|
|
2755
|
+
const observation = BranchObservationSchema.parse(event.payload);
|
|
2756
|
+
collectObservationDefinitions(ids, observation.sourceKind, observation.payload);
|
|
2757
|
+
} else
|
|
2758
|
+
collectObservationDefinitions(ids, event.kind, event.payload);
|
|
1484
2759
|
}
|
|
1485
2760
|
function rekeyBranchEvent(ids, source, event, provider) {
|
|
1486
2761
|
const envelope = {
|
|
@@ -1492,14 +2767,14 @@ function rekeyBranchEvent(ids, source, event, provider) {
|
|
|
1492
2767
|
if (event.kind === "runtime/transition") {
|
|
1493
2768
|
const operation = branchTransition(event);
|
|
1494
2769
|
const rekeyed = rekeyBranchTransition(ids, source, operation);
|
|
1495
|
-
const raw =
|
|
1496
|
-
type:
|
|
1497
|
-
input:
|
|
1498
|
-
assistant:
|
|
2770
|
+
const raw = z20.object({
|
|
2771
|
+
type: z20.string(),
|
|
2772
|
+
input: z20.object({
|
|
2773
|
+
assistant: z20.object({
|
|
1499
2774
|
sha256: Hash3.optional(),
|
|
1500
2775
|
sourceSha256: Hash3.optional(),
|
|
1501
|
-
bytes:
|
|
1502
|
-
parts:
|
|
2776
|
+
bytes: z20.int(),
|
|
2777
|
+
parts: z20.int()
|
|
1503
2778
|
}).passthrough()
|
|
1504
2779
|
}).passthrough()
|
|
1505
2780
|
}).passthrough().safeParse(event.payload);
|
|
@@ -1566,7 +2841,7 @@ function rekeyBranchEvent(ids, source, event, provider) {
|
|
|
1566
2841
|
})
|
|
1567
2842
|
};
|
|
1568
2843
|
}
|
|
1569
|
-
if (event.kind === "provider/message" || event.kind === "provider/request" || event.kind === "provider/response")
|
|
2844
|
+
if (event.kind === "provider/message" || (event.kind === "provider/request" || event.kind === "provider/response") && !isModelInvocationRecord(event.payload))
|
|
1570
2845
|
return { ...envelope, payload: branchJson(provider.rekey(event.kind, event.payload)) };
|
|
1571
2846
|
const observation = event.kind === "runtime/branch-observation" ? BranchObservationSchema.parse(event.payload) : { sourceKind: event.kind, payload: event.payload };
|
|
1572
2847
|
return {
|
|
@@ -1574,22 +2849,27 @@ function rekeyBranchEvent(ids, source, event, provider) {
|
|
|
1574
2849
|
kind: "runtime/branch-observation",
|
|
1575
2850
|
payload: branchJson({
|
|
1576
2851
|
sourceKind: observation.sourceKind,
|
|
1577
|
-
payload: branchObservation(ids, observation.sourceKind, observation.payload)
|
|
2852
|
+
payload: branchObservation(ids, observation.sourceKind, observation.payload, event.kind === "runtime/branch-observation")
|
|
1578
2853
|
})
|
|
1579
2854
|
};
|
|
1580
2855
|
}
|
|
1581
2856
|
|
|
1582
2857
|
// src/agent-runtime/branch-identities.ts
|
|
1583
2858
|
import { createHash as createHash4 } from "node:crypto";
|
|
2859
|
+
var raisedAt = new WeakMap;
|
|
1584
2860
|
|
|
1585
2861
|
class BranchIdentities {
|
|
1586
2862
|
conversationId;
|
|
1587
2863
|
requestKey;
|
|
1588
2864
|
sourceConversationId;
|
|
1589
2865
|
definitions = new Map;
|
|
2866
|
+
found = [];
|
|
2867
|
+
omitted = 0;
|
|
2868
|
+
address = {};
|
|
2869
|
+
files = new Set;
|
|
1590
2870
|
references = new Map;
|
|
1591
2871
|
applicationFiles = new Map;
|
|
1592
|
-
applicationKeys = new
|
|
2872
|
+
applicationKeys = new Map;
|
|
1593
2873
|
constructor(conversationId, requestKey, sourceConversationId) {
|
|
1594
2874
|
this.conversationId = conversationId;
|
|
1595
2875
|
this.requestKey = requestKey;
|
|
@@ -1602,6 +2882,45 @@ class BranchIdentities {
|
|
|
1602
2882
|
this.definitions.set(kind, values);
|
|
1603
2883
|
return target;
|
|
1604
2884
|
}
|
|
2885
|
+
defineExpiredSpill(source) {
|
|
2886
|
+
return this.define("spill", source);
|
|
2887
|
+
}
|
|
2888
|
+
within(address, work) {
|
|
2889
|
+
const outer = this.address;
|
|
2890
|
+
this.address = { ...outer, ...address };
|
|
2891
|
+
try {
|
|
2892
|
+
return work();
|
|
2893
|
+
} catch (error) {
|
|
2894
|
+
if (typeof error === "object" && error !== null && !raisedAt.has(error))
|
|
2895
|
+
raisedAt.set(error, this.address);
|
|
2896
|
+
throw error;
|
|
2897
|
+
} finally {
|
|
2898
|
+
this.address = outer;
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
refuse(refusal) {
|
|
2902
|
+
if (this.found.length >= MAX_BRANCH_REFUSALS) {
|
|
2903
|
+
this.omitted += 1;
|
|
2904
|
+
return;
|
|
2905
|
+
}
|
|
2906
|
+
this.found.push({ ...this.address, ...refusal });
|
|
2907
|
+
}
|
|
2908
|
+
refusedError() {
|
|
2909
|
+
return this.found.length > 0 ? new AgentConversationBranchRefusedError2(this.found, this.omitted) : undefined;
|
|
2910
|
+
}
|
|
2911
|
+
integrityError(error) {
|
|
2912
|
+
if (error instanceof AgentConversationBranchRefusedError2)
|
|
2913
|
+
return error;
|
|
2914
|
+
if (!(error instanceof Error))
|
|
2915
|
+
return error;
|
|
2916
|
+
if (error.name !== "TypeError" && error.name !== "ZodError")
|
|
2917
|
+
return error;
|
|
2918
|
+
const at = raisedAt.get(error) ?? this.address;
|
|
2919
|
+
return new AgentConversationBranchRefusedError2([...this.found, { ...at, code: "integrity", message: error.message }], this.omitted);
|
|
2920
|
+
}
|
|
2921
|
+
applicationFileReferences() {
|
|
2922
|
+
return [...this.files].sort();
|
|
2923
|
+
}
|
|
1605
2924
|
reference(kind, source) {
|
|
1606
2925
|
const target = this.definitions.get(kind)?.get(source);
|
|
1607
2926
|
if (!target)
|
|
@@ -1619,26 +2938,36 @@ class BranchIdentities {
|
|
|
1619
2938
|
}
|
|
1620
2939
|
}
|
|
1621
2940
|
declareApplicationKeys(keys) {
|
|
1622
|
-
for (const key of keys)
|
|
1623
|
-
this.applicationKeys.
|
|
2941
|
+
for (const { key, sourceIdentity } of keys)
|
|
2942
|
+
this.applicationKeys.set(key, sourceIdentity);
|
|
1624
2943
|
}
|
|
1625
|
-
|
|
1626
|
-
return this.applicationKeys.
|
|
2944
|
+
applicationKey(key) {
|
|
2945
|
+
return this.applicationKeys.get(key);
|
|
1627
2946
|
}
|
|
1628
|
-
|
|
2947
|
+
sourceIdentitiesOf(value) {
|
|
2948
|
+
const kinds = new Set;
|
|
1629
2949
|
if (value === this.sourceConversationId)
|
|
1630
|
-
|
|
1631
|
-
for (const values of this.definitions
|
|
2950
|
+
kinds.add("conversation");
|
|
2951
|
+
for (const [kind, values] of this.definitions)
|
|
1632
2952
|
if (values.has(value))
|
|
1633
|
-
|
|
1634
|
-
|
|
2953
|
+
kinds.add(kind);
|
|
2954
|
+
if (this.applicationFiles.has(value))
|
|
2955
|
+
kinds.add("file");
|
|
2956
|
+
return kinds;
|
|
1635
2957
|
}
|
|
1636
2958
|
fileReference(source) {
|
|
1637
2959
|
if (this.definitions.get("spill")?.has(source))
|
|
1638
2960
|
return this.reference("spill", source);
|
|
2961
|
+
this.files.add(source);
|
|
1639
2962
|
const target = this.applicationFiles.get(source);
|
|
1640
|
-
if (target === undefined)
|
|
1641
|
-
|
|
2963
|
+
if (target === undefined) {
|
|
2964
|
+
this.refuse({
|
|
2965
|
+
code: "application-file-undeclared",
|
|
2966
|
+
message: "Branch contains a foreign or missing file reference; declare it in applicationFiles if the application owns it",
|
|
2967
|
+
reference: source
|
|
2968
|
+
});
|
|
2969
|
+
return source;
|
|
2970
|
+
}
|
|
1642
2971
|
return target;
|
|
1643
2972
|
}
|
|
1644
2973
|
referenced(kind) {
|
|
@@ -1655,13 +2984,19 @@ class BranchIdentities {
|
|
|
1655
2984
|
}
|
|
1656
2985
|
collectRun(run) {
|
|
1657
2986
|
this.define("run", run.id);
|
|
2987
|
+
if (run.ownerId)
|
|
2988
|
+
this.define("owner", run.ownerId);
|
|
1658
2989
|
this.define("message", run.assistantMessageId);
|
|
1659
2990
|
if (run.lastOperation)
|
|
1660
2991
|
this.define("operation", run.lastOperation.operationId);
|
|
1661
2992
|
}
|
|
1662
2993
|
collectOperation(operation) {
|
|
2994
|
+
const input = operation.input;
|
|
2995
|
+
if ("ownerId" in input && typeof input.ownerId === "string")
|
|
2996
|
+
this.define("owner", input.ownerId);
|
|
1663
2997
|
switch (operation.type) {
|
|
1664
2998
|
case "accept":
|
|
2999
|
+
this.define("key", operation.input.idempotencyKey);
|
|
1665
3000
|
this.collectRun(operation.input.run);
|
|
1666
3001
|
this.collectMessage(operation.input.input);
|
|
1667
3002
|
break;
|
|
@@ -1677,6 +3012,7 @@ class BranchIdentities {
|
|
|
1677
3012
|
this.collectMessage(operation.input.summary);
|
|
1678
3013
|
break;
|
|
1679
3014
|
case "seed":
|
|
3015
|
+
this.define("key", operation.input.seedKey);
|
|
1680
3016
|
for (const message of operation.input.inputs)
|
|
1681
3017
|
this.collectMessage(message);
|
|
1682
3018
|
break;
|
|
@@ -1689,32 +3025,22 @@ class BranchIdentities {
|
|
|
1689
3025
|
|
|
1690
3026
|
// src/agent-runtime/branch-source.ts
|
|
1691
3027
|
import { createHash as createHash6 } from "node:crypto";
|
|
1692
|
-
import { z as
|
|
1693
|
-
|
|
1694
|
-
// src/agent-runtime/archive-projection.ts
|
|
1695
|
-
import { z as z9 } from "zod";
|
|
1696
|
-
var ArchiveProjectionSchema = z9.object({
|
|
1697
|
-
name: z9.string(),
|
|
1698
|
-
version: z9.int().positive(),
|
|
1699
|
-
uptoSeq: z9.int().nonnegative(),
|
|
1700
|
-
value: z9.json(),
|
|
1701
|
-
updatedAt: z9.string()
|
|
1702
|
-
}).strict();
|
|
3028
|
+
import { z as z22 } from "zod";
|
|
1703
3029
|
|
|
1704
3030
|
// src/agent-runtime/archive-spill.ts
|
|
1705
3031
|
import { createHash as createHash5 } from "node:crypto";
|
|
1706
|
-
import { z as
|
|
1707
|
-
var ArchiveSpillSchema =
|
|
1708
|
-
reference:
|
|
1709
|
-
runId:
|
|
1710
|
-
toolCallId:
|
|
1711
|
-
mediaType:
|
|
1712
|
-
bytes:
|
|
1713
|
-
sha256:
|
|
1714
|
-
createdAt:
|
|
1715
|
-
expiresAt:
|
|
3032
|
+
import { z as z21 } from "zod";
|
|
3033
|
+
var ArchiveSpillSchema = z21.object({
|
|
3034
|
+
reference: z21.string().min(1),
|
|
3035
|
+
runId: z21.string().min(1).optional(),
|
|
3036
|
+
toolCallId: z21.string().min(1).optional(),
|
|
3037
|
+
mediaType: z21.string().min(1),
|
|
3038
|
+
bytes: z21.int().nonnegative(),
|
|
3039
|
+
sha256: z21.string().regex(/^[a-f0-9]{64}$/),
|
|
3040
|
+
createdAt: z21.iso.datetime({ offset: true }),
|
|
3041
|
+
expiresAt: z21.iso.datetime({ offset: true }).optional(),
|
|
1716
3042
|
authorization: AgentCodingToolAuthorizationSchema2.optional(),
|
|
1717
|
-
base64:
|
|
3043
|
+
base64: z21.string()
|
|
1718
3044
|
}).strict().superRefine((spill, ctx) => {
|
|
1719
3045
|
const bytes = Buffer.from(spill.base64, "base64");
|
|
1720
3046
|
if (bytes.toString("base64") !== spill.base64 || bytes.byteLength !== spill.bytes || createHash5("sha256").update(bytes).digest("hex") !== spill.sha256) {
|
|
@@ -1726,7 +3052,7 @@ var ArchiveSpillSchema = z10.object({
|
|
|
1726
3052
|
});
|
|
1727
3053
|
|
|
1728
3054
|
// src/agent-runtime/branch-source.ts
|
|
1729
|
-
var SnapshotProjection =
|
|
3055
|
+
var SnapshotProjection = z22.object({ archiveType: z22.literal("runtime-snapshot"), snapshot: AgentSnapshotSchema2 }).strict();
|
|
1730
3056
|
function branchHash(value) {
|
|
1731
3057
|
return createHash6("sha256").update(canonicalAgentJson2(value)).digest("hex");
|
|
1732
3058
|
}
|
|
@@ -1743,13 +3069,13 @@ function boundary(events, throughRunId) {
|
|
|
1743
3069
|
for (const event of events) {
|
|
1744
3070
|
if (event.kind !== "runtime/transition")
|
|
1745
3071
|
continue;
|
|
1746
|
-
const candidate =
|
|
1747
|
-
type:
|
|
1748
|
-
input:
|
|
1749
|
-
runId:
|
|
1750
|
-
reason:
|
|
1751
|
-
action:
|
|
1752
|
-
absorb:
|
|
3072
|
+
const candidate = z22.object({
|
|
3073
|
+
type: z22.string(),
|
|
3074
|
+
input: z22.object({
|
|
3075
|
+
runId: z22.string().optional(),
|
|
3076
|
+
reason: z22.string().optional(),
|
|
3077
|
+
action: z22.string().optional(),
|
|
3078
|
+
absorb: z22.array(z22.object({ runId: z22.string() })).optional()
|
|
1753
3079
|
})
|
|
1754
3080
|
}).safeParse(event.payload);
|
|
1755
3081
|
if (!candidate.success)
|
|
@@ -1760,6 +3086,83 @@ function boundary(events, throughRunId) {
|
|
|
1760
3086
|
}
|
|
1761
3087
|
throw new TypeError("Branch boundary run has no exact settled event");
|
|
1762
3088
|
}
|
|
3089
|
+
function integrityRefusal(message, address) {
|
|
3090
|
+
return new AgentConversationBranchRefusedError2([
|
|
3091
|
+
{ ...address ?? {}, code: "integrity", message }
|
|
3092
|
+
]);
|
|
3093
|
+
}
|
|
3094
|
+
function collectExpiredSpills(events, liveSpills) {
|
|
3095
|
+
const created = new Map;
|
|
3096
|
+
const deleted = new Map;
|
|
3097
|
+
for (const event of events) {
|
|
3098
|
+
let sourceKind = event.kind;
|
|
3099
|
+
let payload = event.payload;
|
|
3100
|
+
if (event.kind === "runtime/branch-observation") {
|
|
3101
|
+
const obs = BranchObservationSchema.safeParse(event.payload);
|
|
3102
|
+
if (!obs.success)
|
|
3103
|
+
continue;
|
|
3104
|
+
sourceKind = obs.data.sourceKind;
|
|
3105
|
+
payload = obs.data.payload;
|
|
3106
|
+
}
|
|
3107
|
+
if (sourceKind !== "spill/created" && sourceKind !== "spill/deleted")
|
|
3108
|
+
continue;
|
|
3109
|
+
const parsed = SpillEventPayloadSchema.safeParse(payload);
|
|
3110
|
+
if (!parsed.success) {
|
|
3111
|
+
throw integrityRefusal(`Branch archive has malformed ${sourceKind} payload`, {
|
|
3112
|
+
seq: event.seq,
|
|
3113
|
+
eventKind: event.kind
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
const { reference, bytes, sha256 } = parsed.data;
|
|
3117
|
+
if (sourceKind === "spill/created") {
|
|
3118
|
+
if (created.has(reference)) {
|
|
3119
|
+
throw integrityRefusal("Branch archive has duplicate spill/created event", {
|
|
3120
|
+
seq: event.seq,
|
|
3121
|
+
eventKind: event.kind
|
|
3122
|
+
});
|
|
3123
|
+
}
|
|
3124
|
+
created.set(reference, { seq: event.seq, bytes, ...sha256 ? { sha256 } : {} });
|
|
3125
|
+
} else {
|
|
3126
|
+
if (deleted.has(reference)) {
|
|
3127
|
+
throw integrityRefusal("Branch archive has duplicate spill/deleted event", {
|
|
3128
|
+
seq: event.seq,
|
|
3129
|
+
eventKind: event.kind
|
|
3130
|
+
});
|
|
3131
|
+
}
|
|
3132
|
+
const origin = created.get(reference);
|
|
3133
|
+
if (!origin || event.seq <= origin.seq) {
|
|
3134
|
+
throw integrityRefusal("Branch archive has spill/deleted without prior spill/created", {
|
|
3135
|
+
seq: event.seq,
|
|
3136
|
+
eventKind: event.kind
|
|
3137
|
+
});
|
|
3138
|
+
}
|
|
3139
|
+
if (origin.bytes !== bytes || origin.sha256 !== undefined && sha256 !== undefined && origin.sha256 !== sha256) {
|
|
3140
|
+
throw integrityRefusal("Branch archive spill/deleted disagrees with spill/created", {
|
|
3141
|
+
seq: event.seq,
|
|
3142
|
+
eventKind: event.kind
|
|
3143
|
+
});
|
|
3144
|
+
}
|
|
3145
|
+
deleted.set(reference, {
|
|
3146
|
+
seq: event.seq,
|
|
3147
|
+
bytes,
|
|
3148
|
+
...sha256 !== undefined ? { sha256 } : origin.sha256 !== undefined ? { sha256: origin.sha256 } : {}
|
|
3149
|
+
});
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
const liveSet = new Set(liveSpills.map((spill) => spill.reference));
|
|
3153
|
+
for (const [ref, meta] of deleted) {
|
|
3154
|
+
if (liveSet.has(ref)) {
|
|
3155
|
+
throw integrityRefusal("Branch archive has both a live spill and spill/deleted", {
|
|
3156
|
+
seq: meta.seq,
|
|
3157
|
+
eventKind: "spill/deleted"
|
|
3158
|
+
});
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
return {
|
|
3162
|
+
expiredSpills: [...deleted.keys()].sort(),
|
|
3163
|
+
deletedMeta: deleted
|
|
3164
|
+
};
|
|
3165
|
+
}
|
|
1763
3166
|
function prepareBranchSource(bytes, {
|
|
1764
3167
|
source,
|
|
1765
3168
|
applicationFiles = [],
|
|
@@ -1772,7 +3175,7 @@ function prepareBranchSource(bytes, {
|
|
|
1772
3175
|
if (event.seq !== index + 1)
|
|
1773
3176
|
throw new TypeError("Branch source event sequence is incomplete");
|
|
1774
3177
|
}
|
|
1775
|
-
const projections = archive.projections.map((value) =>
|
|
3178
|
+
const projections = archive.projections.map((value) => z22.union([SnapshotProjection, ArchiveProjectionSchema]).parse(value));
|
|
1776
3179
|
if (projections.some((value, index) => canonicalAgentJson2(value) !== canonicalAgentJson2(archive.projections[index])))
|
|
1777
3180
|
throw new TypeError("Branch archive snapshot contains an unknown opaque field");
|
|
1778
3181
|
const snapshots = projections.filter((value) => ("archiveType" in value));
|
|
@@ -1792,10 +3195,13 @@ function prepareBranchSource(bytes, {
|
|
|
1792
3195
|
const allSpills = archive.spills.map((value) => ArchiveSpillSchema.parse(value));
|
|
1793
3196
|
if (new Set(allSpills.map((spill) => spill.reference)).size !== allSpills.length)
|
|
1794
3197
|
throw new TypeError("Branch archive has duplicate spill identities");
|
|
3198
|
+
const { expiredSpills: allExpiredSpills, deletedMeta } = collectExpiredSpills(archive.events, allSpills);
|
|
1795
3199
|
const full = replayBranchEvents(archive.conversationId, archive.events, expected);
|
|
1796
3200
|
const validationIds = new BranchIdentities("branch-validation", "branch-validation", archive.conversationId);
|
|
1797
3201
|
for (const spill of allSpills)
|
|
1798
3202
|
validationIds.define("spill", spill.reference);
|
|
3203
|
+
for (const expired of allExpiredSpills)
|
|
3204
|
+
validationIds.defineExpiredSpill(expired);
|
|
1799
3205
|
validationIds.declareApplicationFiles(applicationFiles);
|
|
1800
3206
|
validationIds.declareApplicationKeys(applicationKeys);
|
|
1801
3207
|
rekeyBranchEvents(validationIds, archive.conversationId, archive.events, full.retainedMessages);
|
|
@@ -1805,6 +3211,7 @@ function prepareBranchSource(bytes, {
|
|
|
1805
3211
|
if (spill.toolCallId)
|
|
1806
3212
|
validationIds.reference("call", spill.toolCallId);
|
|
1807
3213
|
}
|
|
3214
|
+
const refused = validationIds.refusedError();
|
|
1808
3215
|
if (canonicalAgentJson2(visibleSnapshot(full.snapshot)) !== canonicalAgentJson2(visibleSnapshot(expected)))
|
|
1809
3216
|
throw new TypeError("Branch archive snapshot disagrees with its event log");
|
|
1810
3217
|
const seq = boundary(archive.events, source.kind === "conversation" ? source.throughRunId : undefined);
|
|
@@ -1817,22 +3224,41 @@ function prepareBranchSource(bytes, {
|
|
|
1817
3224
|
const selectedIds = new BranchIdentities("branch-validation", "branch-validation", archive.conversationId);
|
|
1818
3225
|
for (const spill of allSpills)
|
|
1819
3226
|
selectedIds.define("spill", spill.reference);
|
|
3227
|
+
for (const expired of allExpiredSpills)
|
|
3228
|
+
selectedIds.defineExpiredSpill(expired);
|
|
1820
3229
|
selectedIds.declareApplicationFiles(applicationFiles);
|
|
1821
3230
|
selectedIds.declareApplicationKeys(applicationKeys);
|
|
1822
3231
|
rekeyBranchEvents(selectedIds, archive.conversationId, events, replay.retainedMessages);
|
|
1823
3232
|
const references = selectedIds.referenced("spill");
|
|
1824
3233
|
const spills = allSpills.filter((spill) => references.has(spill.reference));
|
|
1825
|
-
|
|
1826
|
-
|
|
3234
|
+
const expiredSpills = allExpiredSpills.filter((ref) => references.has(ref));
|
|
3235
|
+
if (spills.length + expiredSpills.length !== references.size)
|
|
3236
|
+
throw integrityRefusal("Branch source is missing a referenced spill");
|
|
3237
|
+
const tailDeletedSpills = [];
|
|
3238
|
+
for (const ref of expiredSpills) {
|
|
3239
|
+
const meta = deletedMeta.get(ref);
|
|
3240
|
+
if (meta && meta.seq > seq) {
|
|
3241
|
+
tailDeletedSpills.push({
|
|
3242
|
+
reference: ref,
|
|
3243
|
+
bytes: meta.bytes,
|
|
3244
|
+
...meta.sha256 !== undefined && { sha256: meta.sha256 }
|
|
3245
|
+
});
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
1827
3248
|
return {
|
|
1828
3249
|
conversationId: archive.conversationId,
|
|
1829
3250
|
events,
|
|
1830
3251
|
spills,
|
|
3252
|
+
expiredSpills,
|
|
3253
|
+
tailDeletedSpills,
|
|
1831
3254
|
replay,
|
|
3255
|
+
...refused && { refused },
|
|
3256
|
+
applicationFiles: validationIds.applicationFileReferences(),
|
|
1832
3257
|
digest: branchHash({
|
|
1833
3258
|
conversationId: archive.conversationId,
|
|
1834
3259
|
events,
|
|
1835
3260
|
spills,
|
|
3261
|
+
expiredSpills,
|
|
1836
3262
|
snapshot: replay.snapshot
|
|
1837
3263
|
})
|
|
1838
3264
|
};
|
|
@@ -1849,7 +3275,7 @@ async function destinationEvents(driver, tx, conversationId) {
|
|
|
1849
3275
|
} while (fromSeq !== undefined);
|
|
1850
3276
|
return events;
|
|
1851
3277
|
}
|
|
1852
|
-
|
|
3278
|
+
function branchRequest(raw) {
|
|
1853
3279
|
const parsed = BranchAgentConversationInputSchema2.parse(raw);
|
|
1854
3280
|
const input = {
|
|
1855
3281
|
...parsed,
|
|
@@ -1861,13 +3287,78 @@ async function branchConversation(driver, raw) {
|
|
|
1861
3287
|
applicationFiles: input.applicationFiles.toSorted((left, right) => left.reference.localeCompare(right.reference))
|
|
1862
3288
|
},
|
|
1863
3289
|
...input.applicationKeys && {
|
|
1864
|
-
applicationKeys:
|
|
3290
|
+
applicationKeys: input.applicationKeys.toSorted((left, right) => left.key.localeCompare(right.key))
|
|
1865
3291
|
},
|
|
1866
3292
|
source: input.source.kind === "archive" ? {
|
|
1867
3293
|
kind: "archive",
|
|
1868
3294
|
digest: createHash7("sha256").update(input.source.bytes).digest("hex")
|
|
1869
3295
|
} : input.source
|
|
1870
3296
|
});
|
|
3297
|
+
return { input, fingerprint };
|
|
3298
|
+
}
|
|
3299
|
+
async function sourceBytes(driver, tx, input) {
|
|
3300
|
+
if (input.source.kind === "archive")
|
|
3301
|
+
return input.source.bytes;
|
|
3302
|
+
if (await driver.conversations?.isPurged(tx, input.source.conversationId))
|
|
3303
|
+
throw new AgentConversationPurgedError2;
|
|
3304
|
+
if (!await driver.head.load(tx, input.source.conversationId) && (await driver.events.list(tx, { conversationId: input.source.conversationId, limit: 1 })).items.length === 0)
|
|
3305
|
+
throw new TypeError("Branch source conversation was not found");
|
|
3306
|
+
return exportConversationIn(driver, tx, input.source.conversationId);
|
|
3307
|
+
}
|
|
3308
|
+
function assertBranchDriverCapabilities(driver, source) {
|
|
3309
|
+
assertSourceCapabilities(driver, {
|
|
3310
|
+
spills: source.spills.length,
|
|
3311
|
+
projections: 0,
|
|
3312
|
+
compacted: source.replay.baseline?.compacted?.length ?? 0
|
|
3313
|
+
});
|
|
3314
|
+
}
|
|
3315
|
+
function requestRefusal(input, source) {
|
|
3316
|
+
const missingAuthorization = source.spills.length > 0 && !input.artifactAuthorization;
|
|
3317
|
+
if (!source.refused && !missingAuthorization)
|
|
3318
|
+
return;
|
|
3319
|
+
return new AgentConversationBranchRefusedError2([
|
|
3320
|
+
...source.refused?.refusals ?? [],
|
|
3321
|
+
...missingAuthorization ? [
|
|
3322
|
+
{
|
|
3323
|
+
code: "artifact-authorization-missing",
|
|
3324
|
+
message: "Branch spills require fresh destination artifact authorization"
|
|
3325
|
+
}
|
|
3326
|
+
] : []
|
|
3327
|
+
], source.refused?.omittedRefusals ?? 0);
|
|
3328
|
+
}
|
|
3329
|
+
async function planConversationBranch(driver, raw) {
|
|
3330
|
+
const { input, fingerprint } = branchRequest(raw);
|
|
3331
|
+
return driver.transaction(async (tx) => {
|
|
3332
|
+
const bytes = await sourceBytes(driver, tx, input);
|
|
3333
|
+
const sourceArchiveDigest = createHash7("sha256").update(bytes).digest("hex");
|
|
3334
|
+
let source;
|
|
3335
|
+
try {
|
|
3336
|
+
source = prepareBranchSource(bytes, input);
|
|
3337
|
+
} catch (error) {
|
|
3338
|
+
if (!(error instanceof AgentConversationBranchRefusedError2))
|
|
3339
|
+
throw error;
|
|
3340
|
+
return planOf(fingerprint, sourceArchiveDigest, error, []);
|
|
3341
|
+
}
|
|
3342
|
+
assertBranchDriverCapabilities(driver, source);
|
|
3343
|
+
return planOf(fingerprint, sourceArchiveDigest, requestRefusal(input, source), source.applicationFiles);
|
|
3344
|
+
}, { access: "read" });
|
|
3345
|
+
}
|
|
3346
|
+
function planOf(fingerprint, sourceArchiveDigest, refused, applicationFiles) {
|
|
3347
|
+
const refusals = refused?.refusals ?? [];
|
|
3348
|
+
return AgentConversationBranchPlanSchema2.parse({
|
|
3349
|
+
ready: refusals.length === 0,
|
|
3350
|
+
fingerprint,
|
|
3351
|
+
sourceArchiveDigest,
|
|
3352
|
+
refusals,
|
|
3353
|
+
omittedRefusals: refused?.omittedRefusals ?? 0,
|
|
3354
|
+
applicationFiles,
|
|
3355
|
+
undeclaredKeys: [
|
|
3356
|
+
...new Set(refusals.flatMap((refusal) => refusal.code === "application-key-undeclared" && refusal.key ? [refusal.key] : []))
|
|
3357
|
+
].sort()
|
|
3358
|
+
});
|
|
3359
|
+
}
|
|
3360
|
+
async function branchConversation(driver, raw) {
|
|
3361
|
+
const { input, fingerprint } = branchRequest(raw);
|
|
1871
3362
|
return driver.transaction(async (tx) => {
|
|
1872
3363
|
if (await driver.conversations?.isPurged(tx, input.destinationConversationId))
|
|
1873
3364
|
throw new AgentConversationPurgedError2;
|
|
@@ -1881,25 +3372,26 @@ async function branchConversation(driver, raw) {
|
|
|
1881
3372
|
}
|
|
1882
3373
|
if (driver.conversations?.isEmpty && !await driver.conversations.isEmpty(tx, input.destinationConversationId) || existing.length > 0 || await driver.head.load(tx, input.destinationConversationId) || (await driver.history.load(tx, input.destinationConversationId)).length > 0)
|
|
1883
3374
|
throw new TypeError("Branch destination must be empty");
|
|
1884
|
-
|
|
1885
|
-
throw new AgentConversationPurgedError2;
|
|
1886
|
-
if (input.source.kind === "conversation" && !await driver.head.load(tx, input.source.conversationId) && (await driver.events.list(tx, { conversationId: input.source.conversationId, limit: 1 })).items.length === 0)
|
|
1887
|
-
throw new TypeError("Branch source conversation was not found");
|
|
1888
|
-
const bytes = input.source.kind === "archive" ? input.source.bytes : await exportConversationIn(driver, tx, input.source.conversationId);
|
|
3375
|
+
const bytes = await sourceBytes(driver, tx, input);
|
|
1889
3376
|
const source = prepareBranchSource(bytes, input);
|
|
1890
3377
|
if (source.conversationId === input.destinationConversationId)
|
|
1891
3378
|
throw new TypeError("Branch requires a new conversation identity");
|
|
1892
|
-
|
|
1893
|
-
|
|
3379
|
+
assertBranchDriverCapabilities(driver, source);
|
|
3380
|
+
const refused = requestRefusal(input, source);
|
|
3381
|
+
if (refused)
|
|
3382
|
+
throw refused;
|
|
1894
3383
|
const ids = new BranchIdentities(input.destinationConversationId, input.requestKey, source.conversationId);
|
|
1895
3384
|
for (const spill of source.spills)
|
|
1896
3385
|
ids.define("spill", spill.reference);
|
|
3386
|
+
for (const expired of source.expiredSpills)
|
|
3387
|
+
ids.defineExpiredSpill(expired);
|
|
1897
3388
|
ids.declareApplicationFiles(input.applicationFiles ?? []);
|
|
1898
3389
|
ids.declareApplicationKeys(input.applicationKeys ?? []);
|
|
1899
3390
|
const events = rekeyBranchEvents(ids, source.conversationId, source.events, source.replay.retainedMessages);
|
|
3391
|
+
const late = ids.refusedError();
|
|
3392
|
+
if (late)
|
|
3393
|
+
throw late;
|
|
1900
3394
|
const replay = replayBranchEvents(input.destinationConversationId, events);
|
|
1901
|
-
if (replay.baseline?.compacted?.length && !driver.history.restore)
|
|
1902
|
-
throw new TypeError("Branch baseline requires inactive history restoration support");
|
|
1903
3395
|
const spills = source.spills.map(({ authorization: _sourceAuthority, ...spill }) => ({
|
|
1904
3396
|
...spill,
|
|
1905
3397
|
reference: ids.reference("spill", spill.reference),
|
|
@@ -1948,18 +3440,32 @@ async function branchConversation(driver, raw) {
|
|
|
1948
3440
|
if (appended.seq !== event.seq)
|
|
1949
3441
|
throw new TypeError("Branch event sequence changed");
|
|
1950
3442
|
}
|
|
3443
|
+
for (const tail of source.tailDeletedSpills) {
|
|
3444
|
+
await driver.events.append(tx, agentStoreEventDraft({
|
|
3445
|
+
conversationId: input.destinationConversationId,
|
|
3446
|
+
kind: "runtime/branch-observation",
|
|
3447
|
+
payload: {
|
|
3448
|
+
sourceKind: "spill/deleted",
|
|
3449
|
+
payload: {
|
|
3450
|
+
reference: ids.reference("spill", tail.reference),
|
|
3451
|
+
bytes: tail.bytes,
|
|
3452
|
+
...tail.sha256 !== undefined && { sha256: tail.sha256 }
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
}));
|
|
3456
|
+
}
|
|
1951
3457
|
await driver.archive?.import(tx, {
|
|
1952
3458
|
format: "stitchkit.agent-conversation",
|
|
1953
3459
|
formatVersion: 1,
|
|
1954
3460
|
conversationId: input.destinationConversationId,
|
|
1955
3461
|
events: [],
|
|
1956
3462
|
projections: [],
|
|
1957
|
-
spills:
|
|
3463
|
+
spills: z23.array(z23.json()).parse(spills)
|
|
1958
3464
|
});
|
|
1959
3465
|
await driver.events.append(tx, agentStoreEventDraft({
|
|
1960
3466
|
conversationId: input.destinationConversationId,
|
|
1961
3467
|
kind: "runtime/branched",
|
|
1962
|
-
payload:
|
|
3468
|
+
payload: z23.json().parse(receipt)
|
|
1963
3469
|
}));
|
|
1964
3470
|
return { outcome: "created", receipt };
|
|
1965
3471
|
});
|
|
@@ -1972,23 +3478,6 @@ function eventOnceId(conversationId, kind, key) {
|
|
|
1972
3478
|
throw new TypeError("Event admission key must not be empty");
|
|
1973
3479
|
return createHash8("sha256").update(JSON.stringify([conversationId, kind, key])).digest("hex");
|
|
1974
3480
|
}
|
|
1975
|
-
async function findEvent(driver, transaction, conversationId, eventId) {
|
|
1976
|
-
if (driver.events.find)
|
|
1977
|
-
return driver.events.find(transaction, { conversationId, eventId });
|
|
1978
|
-
let fromSeq;
|
|
1979
|
-
do {
|
|
1980
|
-
const page = await driver.events.list(transaction, {
|
|
1981
|
-
conversationId,
|
|
1982
|
-
fromSeq,
|
|
1983
|
-
limit: 1e4
|
|
1984
|
-
});
|
|
1985
|
-
const found = page.items.find((event) => event.eventId === eventId);
|
|
1986
|
-
if (found)
|
|
1987
|
-
return found;
|
|
1988
|
-
fromSeq = page.nextSeq;
|
|
1989
|
-
} while (fromSeq !== undefined);
|
|
1990
|
-
return;
|
|
1991
|
-
}
|
|
1992
3481
|
function appendEventOnce(driver, input, key) {
|
|
1993
3482
|
const parsed = AppendAgentStoreEventSchema2.parse(input);
|
|
1994
3483
|
const eventId = eventOnceId(parsed.conversationId, parsed.kind, key);
|
|
@@ -1996,7 +3485,10 @@ function appendEventOnce(driver, input, key) {
|
|
|
1996
3485
|
if (await driver.conversations?.isPurged(transaction, parsed.conversationId)) {
|
|
1997
3486
|
throw new AgentConversationPurgedError2;
|
|
1998
3487
|
}
|
|
1999
|
-
const previous = await
|
|
3488
|
+
const previous = await driver.events.find(transaction, {
|
|
3489
|
+
conversationId: parsed.conversationId,
|
|
3490
|
+
eventId
|
|
3491
|
+
});
|
|
2000
3492
|
if (previous)
|
|
2001
3493
|
return { outcome: "duplicate", event: previous };
|
|
2002
3494
|
const event = await driver.events.append(transaction, {
|
|
@@ -2008,11 +3500,11 @@ function appendEventOnce(driver, input, key) {
|
|
|
2008
3500
|
}
|
|
2009
3501
|
function findEventOnce(driver, input) {
|
|
2010
3502
|
const eventId = eventOnceId(input.conversationId, input.kind, input.key);
|
|
2011
|
-
return driver.transaction((transaction) =>
|
|
3503
|
+
return driver.transaction((transaction) => driver.events.find(transaction, { conversationId: input.conversationId, eventId }), { access: "read" });
|
|
2012
3504
|
}
|
|
2013
3505
|
|
|
2014
3506
|
// src/agent-runtime/store-mutate.ts
|
|
2015
|
-
import { z as
|
|
3507
|
+
import { z as z24 } from "zod";
|
|
2016
3508
|
function validateAdmissionReceipt(receipt, record, conversationId) {
|
|
2017
3509
|
const input = receipt.input;
|
|
2018
3510
|
const run = record.run;
|
|
@@ -2055,7 +3547,7 @@ async function settledSeed(driver, transaction, read, input) {
|
|
|
2055
3547
|
return { outcome: "applied", snapshot: current };
|
|
2056
3548
|
let collisions = 0;
|
|
2057
3549
|
for (const message of input.inputs) {
|
|
2058
|
-
if (current.messages.some((candidate) => candidate.id === message.id) ||
|
|
3550
|
+
if (current.messages.some((candidate) => candidate.id === message.id) || await driver.history.hasMessage(transaction, {
|
|
2059
3551
|
conversationId,
|
|
2060
3552
|
messageId: message.id
|
|
2061
3553
|
}))
|
|
@@ -2159,7 +3651,7 @@ async function persistApplied(driver, transaction, read, operation, reduced) {
|
|
|
2159
3651
|
await driver.events.append(transaction, agentStoreEventDraft({
|
|
2160
3652
|
conversationId,
|
|
2161
3653
|
kind: "runtime/transition",
|
|
2162
|
-
payload:
|
|
3654
|
+
payload: z24.json().parse(transitionRecord(operation, reduced))
|
|
2163
3655
|
}));
|
|
2164
3656
|
return { outcome: "applied", snapshot: reduced.snapshot };
|
|
2165
3657
|
}
|
|
@@ -2208,14 +3700,17 @@ function createStoreConversationPurge(driver, conversations) {
|
|
|
2208
3700
|
}
|
|
2209
3701
|
|
|
2210
3702
|
// src/agent-runtime/store-create.ts
|
|
2211
|
-
var AgentRecoverableScanInputSchema =
|
|
2212
|
-
cursor:
|
|
2213
|
-
limit:
|
|
3703
|
+
var AgentRecoverableScanInputSchema = z25.object({
|
|
3704
|
+
cursor: z25.string().min(1).optional(),
|
|
3705
|
+
limit: z25.number().int().min(1).max(1000)
|
|
2214
3706
|
});
|
|
2215
3707
|
function createAgentRuntimeStore2(driver) {
|
|
3708
|
+
const capabilities = driverCapabilities(driver);
|
|
2216
3709
|
const mutate = (operation) => mutateStore(driver, operation);
|
|
2217
3710
|
return {
|
|
3711
|
+
capabilities,
|
|
2218
3712
|
branchConversation: (input) => branchConversation(driver, input),
|
|
3713
|
+
planConversationBranch: (input) => planConversationBranch(driver, input),
|
|
2219
3714
|
loadSnapshot: (conversationId) => loadSnapshot(driver, conversationId),
|
|
2220
3715
|
loadRun: (input) => loadRun(driver, input),
|
|
2221
3716
|
listActiveRuns: (conversationId) => listActiveRuns(driver, conversationId),
|
|
@@ -2228,6 +3723,25 @@ function createAgentRuntimeStore2(driver) {
|
|
|
2228
3723
|
...driver.conversations && {
|
|
2229
3724
|
purgeConversation: createStoreConversationPurge(driver, driver.conversations)
|
|
2230
3725
|
},
|
|
3726
|
+
...driver.events.redactExpiredPayloads && {
|
|
3727
|
+
async purgeExpiredPayloads(rawInput) {
|
|
3728
|
+
const parsed = PurgeInvocationPayloadsInputSchema2.parse(rawInput);
|
|
3729
|
+
const redact = driver.events.redactExpiredPayloads;
|
|
3730
|
+
if (!redact)
|
|
3731
|
+
throw new TypeError("Agent runtime store does not support payload purge");
|
|
3732
|
+
const before = new Date(Date.parse(parsed.before)).toISOString();
|
|
3733
|
+
const expiredAt = new Date().toISOString();
|
|
3734
|
+
const result = await driver.transaction((tx) => redact(tx, {
|
|
3735
|
+
before,
|
|
3736
|
+
expiredAt,
|
|
3737
|
+
...parsed.conversationId !== undefined && {
|
|
3738
|
+
conversationId: parsed.conversationId
|
|
3739
|
+
},
|
|
3740
|
+
limit: parsed.limit ?? 1000
|
|
3741
|
+
}));
|
|
3742
|
+
return PurgeInvocationPayloadsResultSchema2.parse(result);
|
|
3743
|
+
}
|
|
3744
|
+
},
|
|
2231
3745
|
acceptInputAndAssignRun: (input) => mutate({
|
|
2232
3746
|
type: "accept",
|
|
2233
3747
|
input: AcceptInputAndAssignRunSchema2.parse(input)
|
|
@@ -2262,4 +3776,4 @@ function createAgentRuntimeStore2(driver) {
|
|
|
2262
3776
|
};
|
|
2263
3777
|
}
|
|
2264
3778
|
|
|
2265
|
-
export { BranchAgentConversationInputSchema2, AgentConversationBranchReceiptSchema2, AgentConversationBranchResultSchema2, AgentConversationPurgeInputSchema2, AgentConversationPurgeResultSchema2, AgentConversationPurgedError2, purgeAgentConversation2,
|
|
3779
|
+
export { AgentBranchRefusalCodeSchema2, AgentBranchRefusalSchema2, AgentConversationBranchRefusedError2, BranchAgentConversationInputSchema2, AgentConversationBranchReceiptSchema2, AgentConversationBranchResultSchema2, AgentConversationBranchPlanSchema2, defineAgentToolDescriptor, bindAgentTool, SqlIntegerSchema, HeadRowSchema, MessageRowSchema, PositionedMessageRowSchema, CountRowSchema, FlagSchema, EVENT_COLUMNS, parseJson, encodeJson, missing, placeholders, parseRunRow, parseEventRow, nextEventSeqByMaximum, AgentChildBudgetSchema2, AgentChildStateSchema2, AgentChildRecordSchema2, AgentChildBlockingKindSchema2, AgentChildBlockingSourceSchema2, AgentChildBlockingEventSchema2, ChildBlockingDecisionSchema, ChildSpawnedEventPayloadSchema, ChildStateEventPayloadSchema, parseChild, usageNumbers, AgentConversationPurgeInputSchema2, AgentConversationPurgeResultSchema2, AgentConversationPurgedError2, purgeAgentConversation2, DeferredAgentToolSearchInputSchema2, DeferredAgentToolMatchSchema2, DeferredAgentToolReceiptSchema2, agentSqlTables, isRetryablePostgresConflict, POSTGRES_ISOLATION, postgresSession, setPostgresTransactionIsolation, runPostgresTransaction, AgentEventSearchResultSchema2, createAgentEventSearch2, AGENT_EVENT_SEARCH_TOOL_DESCRIPTORS2, createAgentEventSearchTools2, AgentStoreUnsupportedCapabilityError2, ArchiveProjectionSchema, isRuntimeSnapshotEntry, replaceMessage, appendEventIn, ArchiveSpillSchema, createAgentRuntimeStore2 };
|