@zvada/agent-server 0.3.18 → 0.3.19
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/AGENTS.md +11 -26
- package/CHANGELOG.md +1005 -1
- package/README.md +35 -39
- package/dist/types/accounts/chatgpt.d.ts +34 -0
- package/dist/types/accounts/chatgpt.d.ts.map +1 -0
- package/dist/types/accounts/check.d.ts +24 -0
- package/dist/types/accounts/check.d.ts.map +1 -0
- package/dist/types/accounts/claude.d.ts +21 -0
- package/dist/types/accounts/claude.d.ts.map +1 -0
- package/dist/types/accounts/endpoint.d.ts +50 -0
- package/dist/types/accounts/endpoint.d.ts.map +1 -0
- package/dist/types/accounts/http.d.ts +38 -0
- package/dist/types/accounts/http.d.ts.map +1 -0
- package/dist/types/accounts/index.d.ts +6 -0
- package/dist/types/accounts/index.d.ts.map +1 -0
- package/dist/types/client/client.d.ts +272 -0
- package/dist/types/client/client.d.ts.map +1 -0
- package/dist/types/client/connection.d.ts +160 -0
- package/dist/types/client/connection.d.ts.map +1 -0
- package/dist/types/client/history.d.ts +8 -0
- package/dist/types/client/history.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +5 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/listeners.d.ts +8 -0
- package/dist/types/client/listeners.d.ts.map +1 -0
- package/dist/types/client/logins.d.ts +35 -0
- package/dist/types/client/logins.d.ts.map +1 -0
- package/dist/types/client/rpc.d.ts +46 -0
- package/dist/types/client/rpc.d.ts.map +1 -0
- package/dist/types/client/streams.d.ts +150 -0
- package/dist/types/client/streams.d.ts.map +1 -0
- package/dist/types/client/transports.d.ts +35 -0
- package/dist/types/client/transports.d.ts.map +1 -0
- package/dist/types/client/turns.d.ts +81 -0
- package/dist/types/client/turns.d.ts.map +1 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts +68 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -0
- package/dist/types/core/agents/acp/adapter.d.ts +39 -0
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/acp/client.d.ts +90 -0
- package/dist/types/core/agents/acp/client.d.ts.map +1 -0
- package/dist/types/core/agents/acp/known-agents.d.ts +35 -0
- package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -0
- package/dist/types/core/agents/acp/mappings.d.ts +46 -0
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -0
- package/dist/types/core/agents/acp/requests.d.ts +26 -0
- package/dist/types/core/agents/acp/requests.d.ts.map +1 -0
- package/dist/types/core/agents/attachments.d.ts +11 -0
- package/dist/types/core/agents/attachments.d.ts.map +1 -0
- package/dist/types/core/agents/base.d.ts +227 -0
- package/dist/types/core/agents/base.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts +58 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts +26 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +70 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts +54 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/events.d.ts +42 -0
- package/dist/types/core/agents/claude-code/events.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/login.d.ts +61 -0
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts +52 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/models.d.ts +30 -0
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/options.d.ts +183 -0
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts +50 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts +36 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session.d.ts +148 -0
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts +29 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spend.d.ts +58 -0
- package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/tools.d.ts +4 -0
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts +52 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn.d.ts +121 -0
- package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts +59 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts +116 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +113 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts +66 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +49 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts +12 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts +45 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts +20 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts +26 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts +31 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts +38 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +62 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts +67 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts +40 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +19 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +99 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts +42 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts +96 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +53 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +87 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +33 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts +163 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -0
- package/dist/types/core/agents/config-fingerprint.d.ts +5 -0
- package/dist/types/core/agents/config-fingerprint.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +28 -0
- package/dist/types/core/agents/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +37 -0
- package/dist/types/core/agents/elicitation.d.ts.map +1 -0
- package/dist/types/core/agents/inherit-config.d.ts +18 -0
- package/dist/types/core/agents/inherit-config.d.ts.map +1 -0
- package/dist/types/core/agents/login.d.ts +67 -0
- package/dist/types/core/agents/login.d.ts.map +1 -0
- package/dist/types/core/agents/mcp-config.d.ts +57 -0
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -0
- package/dist/types/core/agents/plan.d.ts +16 -0
- package/dist/types/core/agents/plan.d.ts.map +1 -0
- package/dist/types/core/agents/registry.d.ts +30 -0
- package/dist/types/core/agents/registry.d.ts.map +1 -0
- package/dist/types/core/agents/session-agent.d.ts +48 -0
- package/dist/types/core/agents/session-agent.d.ts.map +1 -0
- package/dist/types/core/agents/session-pool.d.ts +41 -0
- package/dist/types/core/agents/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/stderr-tail.d.ts +28 -0
- package/dist/types/core/agents/stderr-tail.d.ts.map +1 -0
- package/dist/types/core/agents/thinking-levels.d.ts +4 -0
- package/dist/types/core/agents/thinking-levels.d.ts.map +1 -0
- package/dist/types/core/agents/types.d.ts +124 -0
- package/dist/types/core/agents/types.d.ts.map +1 -0
- package/dist/types/core/diagnostics.d.ts +36 -0
- package/dist/types/core/diagnostics.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +29 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/presets.d.ts +80 -0
- package/dist/types/core/presets.d.ts.map +1 -0
- package/dist/types/core/processes/identity.d.ts +31 -0
- package/dist/types/core/processes/identity.d.ts.map +1 -0
- package/dist/types/core/processes/lifeline.d.ts +47 -0
- package/dist/types/core/processes/lifeline.d.ts.map +1 -0
- package/dist/types/core/processes/native-processes.d.ts +130 -0
- package/dist/types/core/processes/native-processes.d.ts.map +1 -0
- package/dist/types/core/processes/process-table.d.ts +43 -0
- package/dist/types/core/processes/process-table.d.ts.map +1 -0
- package/dist/types/core/provision/cache-trust.d.ts +13 -0
- package/dist/types/core/provision/cache-trust.d.ts.map +1 -0
- package/dist/types/core/provision/cache-usage.d.ts +14 -0
- package/dist/types/core/provision/cache-usage.d.ts.map +1 -0
- package/dist/types/core/provision/checksums.d.ts +46 -0
- package/dist/types/core/provision/checksums.d.ts.map +1 -0
- package/dist/types/core/provision/extract.d.ts +7 -0
- package/dist/types/core/provision/extract.d.ts.map +1 -0
- package/dist/types/core/provision/index.d.ts +5 -0
- package/dist/types/core/provision/index.d.ts.map +1 -0
- package/dist/types/core/provision/install-build.d.ts +36 -0
- package/dist/types/core/provision/install-build.d.ts.map +1 -0
- package/dist/types/core/provision/npm.d.ts +40 -0
- package/dist/types/core/provision/npm.d.ts.map +1 -0
- package/dist/types/core/provision/pins.d.ts +24 -0
- package/dist/types/core/provision/pins.d.ts.map +1 -0
- package/dist/types/core/provision/platform.d.ts +28 -0
- package/dist/types/core/provision/platform.d.ts.map +1 -0
- package/dist/types/core/provision/provisioner.d.ts +189 -0
- package/dist/types/core/provision/provisioner.d.ts.map +1 -0
- package/dist/types/core/provision/releases.d.ts +8 -0
- package/dist/types/core/provision/releases.d.ts.map +1 -0
- package/dist/types/core/provision/tools.d.ts +81 -0
- package/dist/types/core/provision/tools.d.ts.map +1 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts +52 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts.map +1 -0
- package/dist/types/core/proxy/api-key-store.d.ts +37 -0
- package/dist/types/core/proxy/api-key-store.d.ts.map +1 -0
- package/dist/types/core/proxy/index.d.ts +3 -0
- package/dist/types/core/proxy/index.d.ts.map +1 -0
- package/dist/types/core/proxy/loopback.d.ts +14 -0
- package/dist/types/core/proxy/loopback.d.ts.map +1 -0
- package/dist/types/core/runtime/agent-runtime.d.ts +181 -0
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -0
- package/dist/types/core/runtime/event-processor.d.ts +87 -0
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -0
- package/dist/types/core/runtime/event-sink.d.ts +44 -0
- package/dist/types/core/runtime/event-sink.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-clis.d.ts +10 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-logins.d.ts +68 -0
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -0
- package/dist/types/core/runtime/login-reads.d.ts +28 -0
- package/dist/types/core/runtime/login-reads.d.ts.map +1 -0
- package/dist/types/core/runtime/model-lists.d.ts +37 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -0
- package/dist/types/core/runtime/permission-policy.d.ts +61 -0
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -0
- package/dist/types/core/runtime/request-broker.d.ts +49 -0
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -0
- package/dist/types/core/runtime/steering.d.ts +38 -0
- package/dist/types/core/runtime/steering.d.ts.map +1 -0
- package/dist/types/core/runtime/turn-outcome.d.ts +21 -0
- package/dist/types/core/runtime/turn-outcome.d.ts.map +1 -0
- package/dist/types/core/runtime/turn.d.ts +121 -0
- package/dist/types/core/runtime/turn.d.ts.map +1 -0
- package/dist/types/core/utils/bounded.d.ts +6 -0
- package/dist/types/core/utils/bounded.d.ts.map +1 -0
- package/dist/types/core/utils/deadline.d.ts +14 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -0
- package/dist/types/core/utils/errors.d.ts +104 -0
- package/dist/types/core/utils/errors.d.ts.map +1 -0
- package/dist/types/core/utils/is-record.d.ts +3 -0
- package/dist/types/core/utils/is-record.d.ts.map +1 -0
- package/dist/types/core/utils/loopback.d.ts +6 -0
- package/dist/types/core/utils/loopback.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/protocol/account.d.ts +26 -0
- package/dist/types/protocol/account.d.ts.map +1 -0
- package/dist/types/protocol/async-queue.d.ts +21 -0
- package/dist/types/protocol/async-queue.d.ts.map +1 -0
- package/dist/types/protocol/auth.d.ts +228 -0
- package/dist/types/protocol/auth.d.ts.map +1 -0
- package/dist/types/protocol/canonical.d.ts +9 -0
- package/dist/types/protocol/canonical.d.ts.map +1 -0
- package/dist/types/protocol/clis.d.ts +74 -0
- package/dist/types/protocol/clis.d.ts.map +1 -0
- package/dist/types/protocol/config.d.ts +200 -0
- package/dist/types/protocol/config.d.ts.map +1 -0
- package/dist/types/protocol/conversation.d.ts +942 -0
- package/dist/types/protocol/conversation.d.ts.map +1 -0
- package/dist/types/protocol/credentials.d.ts +145 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -0
- package/dist/types/protocol/errors.d.ts +36 -0
- package/dist/types/protocol/errors.d.ts.map +1 -0
- package/dist/types/protocol/execution.d.ts +28 -0
- package/dist/types/protocol/execution.d.ts.map +1 -0
- package/dist/types/protocol/factories.d.ts +94 -0
- package/dist/types/protocol/factories.d.ts.map +1 -0
- package/dist/types/protocol/guards.d.ts +55 -0
- package/dist/types/protocol/guards.d.ts.map +1 -0
- package/dist/types/protocol/harness.d.ts +70 -0
- package/dist/types/protocol/harness.d.ts.map +1 -0
- package/dist/types/protocol/history.d.ts +318 -0
- package/dist/types/protocol/history.d.ts.map +1 -0
- package/dist/types/protocol/ids.d.ts +9 -0
- package/dist/types/protocol/ids.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +35 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/protocol/lifecycle.d.ts +1190 -0
- package/dist/types/protocol/lifecycle.d.ts.map +1 -0
- package/dist/types/protocol/meta-keys.d.ts +17 -0
- package/dist/types/protocol/meta-keys.d.ts.map +1 -0
- package/dist/types/protocol/meta.d.ts +13 -0
- package/dist/types/protocol/meta.d.ts.map +1 -0
- package/dist/types/protocol/model-catalog.d.ts +11 -0
- package/dist/types/protocol/model-catalog.d.ts.map +1 -0
- package/dist/types/protocol/models.d.ts +107 -0
- package/dist/types/protocol/models.d.ts.map +1 -0
- package/dist/types/protocol/part-input.d.ts +101 -0
- package/dist/types/protocol/part-input.d.ts.map +1 -0
- package/dist/types/protocol/parts.d.ts +357 -0
- package/dist/types/protocol/parts.d.ts.map +1 -0
- package/dist/types/protocol/reduce.d.ts +26 -0
- package/dist/types/protocol/reduce.d.ts.map +1 -0
- package/dist/types/protocol/selectors.d.ts +64 -0
- package/dist/types/protocol/selectors.d.ts.map +1 -0
- package/dist/types/protocol/seq-cursor.d.ts +66 -0
- package/dist/types/protocol/seq-cursor.d.ts.map +1 -0
- package/dist/types/protocol/stop-reasons.d.ts +33 -0
- package/dist/types/protocol/stop-reasons.d.ts.map +1 -0
- package/dist/types/protocol/thinking.d.ts +28 -0
- package/dist/types/protocol/thinking.d.ts.map +1 -0
- package/dist/types/protocol/time.d.ts +21 -0
- package/dist/types/protocol/time.d.ts.map +1 -0
- package/dist/types/protocol/tokens.d.ts +29 -0
- package/dist/types/protocol/tokens.d.ts.map +1 -0
- package/dist/types/protocol/tool-closure.d.ts +25 -0
- package/dist/types/protocol/tool-closure.d.ts.map +1 -0
- package/dist/types/protocol/tool-state.d.ts +209 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -0
- package/dist/types/protocol/verify.d.ts +52 -0
- package/dist/types/protocol/verify.d.ts.map +1 -0
- package/dist/types/protocol/vocabulary.d.ts +19 -0
- package/dist/types/protocol/vocabulary.d.ts.map +1 -0
- package/dist/types/protocol/wire-api.d.ts +1983 -0
- package/dist/types/protocol/wire-api.d.ts.map +1 -0
- package/dist/types/protocol/wire.d.ts +1758 -0
- package/dist/types/protocol/wire.d.ts.map +1 -0
- package/dist/types/server/acp/binding.d.ts +33 -0
- package/dist/types/server/acp/binding.d.ts.map +1 -0
- package/dist/types/server/acp/session-records.d.ts +17 -0
- package/dist/types/server/acp/session-records.d.ts.map +1 -0
- package/dist/types/server/acp/translate.d.ts +48 -0
- package/dist/types/server/acp/translate.d.ts.map +1 -0
- package/dist/types/server/agent-server.d.ts +121 -0
- package/dist/types/server/agent-server.d.ts.map +1 -0
- package/dist/types/server/feedback.d.ts +37 -0
- package/dist/types/server/feedback.d.ts.map +1 -0
- package/dist/types/server/history.d.ts +15 -0
- package/dist/types/server/history.d.ts.map +1 -0
- package/dist/types/server/index.d.ts +7 -0
- package/dist/types/server/index.d.ts.map +1 -0
- package/dist/types/server/install.d.ts +42 -0
- package/dist/types/server/install.d.ts.map +1 -0
- package/dist/types/server/open-parts.d.ts +27 -0
- package/dist/types/server/open-parts.d.ts.map +1 -0
- package/dist/types/server/routes.d.ts +61 -0
- package/dist/types/server/routes.d.ts.map +1 -0
- package/dist/types/server/secrets.d.ts +11 -0
- package/dist/types/server/secrets.d.ts.map +1 -0
- package/dist/types/server/session-gate.d.ts +32 -0
- package/dist/types/server/session-gate.d.ts.map +1 -0
- package/dist/types/server/session-log.d.ts +39 -0
- package/dist/types/server/session-log.d.ts.map +1 -0
- package/dist/types/server/session-store.d.ts +119 -0
- package/dist/types/server/session-store.d.ts.map +1 -0
- package/dist/types/server/subscriptions.d.ts +74 -0
- package/dist/types/server/subscriptions.d.ts.map +1 -0
- package/dist/types/server/transports.d.ts +74 -0
- package/dist/types/server/transports.d.ts.map +1 -0
- package/dist/types/server/wire-error.d.ts +9 -0
- package/dist/types/server/wire-error.d.ts.map +1 -0
- package/dist/types/sync/event-log.d.ts +45 -0
- package/dist/types/sync/event-log.d.ts.map +1 -0
- package/dist/types/sync/fit.d.ts +40 -0
- package/dist/types/sync/fit.d.ts.map +1 -0
- package/dist/types/sync/history-reader.d.ts +8 -0
- package/dist/types/sync/history-reader.d.ts.map +1 -0
- package/dist/types/sync/history-sqlite.d.ts +37 -0
- package/dist/types/sync/history-sqlite.d.ts.map +1 -0
- package/dist/types/sync/history.d.ts +70 -0
- package/dist/types/sync/history.d.ts.map +1 -0
- package/dist/types/sync/index.d.ts +4 -0
- package/dist/types/sync/index.d.ts.map +1 -0
- package/dist/types/sync/journal-sqlite.d.ts +51 -0
- package/dist/types/sync/journal-sqlite.d.ts.map +1 -0
- package/dist/types/sync/journal.d.ts +107 -0
- package/dist/types/sync/journal.d.ts.map +1 -0
- package/dist/types/sync/live-tails.d.ts +30 -0
- package/dist/types/sync/live-tails.d.ts.map +1 -0
- package/dist/types/sync/node-sqlite.d.ts +7 -0
- package/dist/types/sync/node-sqlite.d.ts.map +1 -0
- package/dist/types/sync/projection.d.ts +10 -0
- package/dist/types/sync/projection.d.ts.map +1 -0
- package/dist/types/sync/recovery.d.ts +25 -0
- package/dist/types/sync/recovery.d.ts.map +1 -0
- package/dist/types/sync/retry.d.ts +25 -0
- package/dist/types/sync/retry.d.ts.map +1 -0
- package/dist/types/sync/schema.d.ts +4 -0
- package/dist/types/sync/schema.d.ts.map +1 -0
- package/dist/types/sync/sql.d.ts +38 -0
- package/dist/types/sync/sql.d.ts.map +1 -0
- package/dist/types/sync/sqlite-file.d.ts +9 -0
- package/dist/types/sync/sqlite-file.d.ts.map +1 -0
- package/dist/types/sync/sqlite.d.ts +6 -0
- package/dist/types/sync/sqlite.d.ts.map +1 -0
- package/dist/types/sync/worker.d.ts +63 -0
- package/dist/types/sync/worker.d.ts.map +1 -0
- package/docs/consuming.md +452 -53
- package/docs/deploy.md +218 -47
- package/docs/{sync-experiment.md → durable-sessions.md} +77 -72
- package/docs/feedback.md +116 -0
- package/docs/harnesses.md +212 -88
- package/docs/sync-history.md +29 -13
- package/docs/sync-integration.md +52 -66
- package/package.json +43 -25
- package/src/accounts/chatgpt.ts +194 -0
- package/src/accounts/check.ts +112 -0
- package/src/accounts/claude.ts +111 -0
- package/src/accounts/endpoint.ts +151 -0
- package/src/accounts/http.ts +97 -0
- package/src/accounts/index.ts +19 -0
- package/src/client/client.ts +604 -670
- package/src/client/connection.ts +371 -0
- package/src/client/history.ts +29 -52
- package/src/client/index.ts +11 -2
- package/src/client/listeners.ts +20 -0
- package/src/client/logins.ts +105 -0
- package/src/client/rpc.ts +144 -0
- package/src/client/streams.ts +488 -0
- package/src/client/transports.ts +62 -8
- package/src/client/turns.ts +171 -0
- package/src/core/agents/acp/acp-agent.ts +94 -118
- package/src/core/agents/acp/adapter.ts +20 -9
- package/src/core/agents/acp/client.ts +125 -47
- package/src/core/agents/acp/known-agents.ts +36 -4
- package/src/core/agents/acp/mappings.ts +64 -18
- package/src/core/agents/acp/requests.ts +125 -0
- package/src/core/agents/attachments.ts +18 -0
- package/src/core/agents/base.ts +120 -42
- package/src/core/agents/claude-code/adapter.ts +177 -238
- package/src/core/agents/claude-code/approvals.ts +270 -0
- package/src/core/agents/claude-code/claude-agent.ts +175 -158
- package/src/core/agents/claude-code/credentials.ts +171 -0
- package/src/core/agents/claude-code/events.ts +55 -0
- package/src/core/agents/claude-code/login.ts +269 -0
- package/src/core/agents/claude-code/mcp.ts +206 -0
- package/src/core/agents/claude-code/models.ts +15 -9
- package/src/core/agents/claude-code/options.ts +326 -39
- package/src/core/agents/claude-code/outcome.ts +209 -0
- package/src/core/agents/claude-code/session-pool.ts +136 -0
- package/src/core/agents/claude-code/session.ts +513 -0
- package/src/core/agents/claude-code/spawn.ts +144 -0
- package/src/core/agents/claude-code/spend.ts +160 -0
- package/src/core/agents/claude-code/tools.ts +47 -0
- package/src/core/agents/claude-code/turn-usage.ts +135 -0
- package/src/core/agents/claude-code/turn.ts +232 -0
- package/src/core/agents/codex-app-server/adapter.ts +314 -117
- package/src/core/agents/codex-app-server/client.ts +186 -84
- package/src/core/agents/codex-app-server/codex-agent.ts +343 -0
- package/src/core/agents/codex-app-server/commands.ts +228 -0
- package/src/core/agents/codex-app-server/credentials.ts +126 -0
- package/src/core/agents/codex-app-server/effort.ts +29 -0
- package/src/core/agents/codex-app-server/events.ts +47 -0
- package/src/core/agents/codex-app-server/homes.ts +64 -0
- package/src/core/agents/codex-app-server/input.ts +60 -0
- package/src/core/agents/codex-app-server/items.ts +149 -0
- package/src/core/agents/codex-app-server/login.ts +180 -0
- package/src/core/agents/codex-app-server/mcp.ts +182 -37
- package/src/core/agents/codex-app-server/models.ts +99 -46
- package/src/core/agents/codex-app-server/options.ts +146 -0
- package/src/core/agents/codex-app-server/plan-approval.ts +135 -0
- package/src/core/agents/codex-app-server/protocol.ts +117 -0
- package/src/core/agents/codex-app-server/requests.ts +332 -0
- package/src/core/agents/codex-app-server/session.ts +285 -0
- package/src/core/agents/codex-app-server/subagents.ts +108 -42
- package/src/core/agents/codex-app-server/thread-settings.ts +279 -0
- package/src/core/agents/codex-app-server/turn-items.ts +88 -0
- package/src/core/agents/codex-app-server/turn.ts +463 -0
- package/src/core/agents/config-fingerprint.ts +7 -14
- package/src/core/agents/credentials.ts +98 -0
- package/src/core/agents/elicitation.ts +75 -0
- package/src/core/agents/inherit-config.ts +21 -0
- package/src/core/agents/login.ts +116 -0
- package/src/core/agents/mcp-config.ts +112 -8
- package/src/core/agents/plan.ts +25 -0
- package/src/core/agents/registry.ts +21 -4
- package/src/core/agents/session-agent.ts +96 -4
- package/src/core/agents/{session-store.ts → session-pool.ts} +11 -5
- package/src/core/agents/stderr-tail.ts +75 -0
- package/src/core/agents/types.ts +40 -5
- package/src/core/index.ts +58 -48
- package/src/core/presets.ts +100 -39
- package/src/core/processes/identity.ts +113 -0
- package/src/core/processes/lifeline.ts +170 -0
- package/src/core/processes/native-processes.ts +379 -0
- package/src/core/processes/process-table.ts +174 -0
- package/src/core/provision/cache-trust.ts +121 -0
- package/src/core/provision/cache-usage.ts +69 -0
- package/src/core/provision/checksums.ts +64 -0
- package/src/core/provision/extract.ts +11 -2
- package/src/core/provision/index.ts +4 -1
- package/src/core/provision/install-build.ts +136 -0
- package/src/core/provision/npm.ts +112 -17
- package/src/core/provision/pins.ts +9 -33
- package/src/core/provision/platform.ts +12 -1
- package/src/core/provision/provisioner.ts +329 -397
- package/src/core/provision/releases.ts +86 -0
- package/src/core/provision/tools.ts +329 -0
- package/src/core/proxy/anthropic-proxy.ts +55 -25
- package/src/core/proxy/api-key-store.ts +2 -12
- package/src/core/proxy/loopback.ts +106 -0
- package/src/core/runtime/agent-runtime.ts +327 -498
- package/src/core/runtime/event-processor.ts +197 -70
- package/src/core/runtime/harness-clis.ts +61 -0
- package/src/core/runtime/harness-logins.ts +328 -0
- package/src/core/runtime/login-reads.ts +78 -0
- package/src/core/runtime/model-lists.ts +33 -48
- package/src/core/runtime/permission-policy.ts +113 -0
- package/src/core/runtime/request-broker.ts +204 -0
- package/src/core/runtime/steering.ts +112 -0
- package/src/core/runtime/turn-outcome.ts +30 -0
- package/src/core/runtime/turn.ts +360 -0
- package/src/core/utils/bounded.ts +12 -0
- package/src/core/utils/deadline.ts +38 -0
- package/src/core/utils/errors.ts +113 -21
- package/src/core/utils/is-record.ts +4 -0
- package/src/core/utils/loopback.ts +10 -0
- package/src/protocol/account.ts +104 -0
- package/src/protocol/auth.ts +199 -0
- package/src/protocol/canonical.ts +16 -0
- package/src/protocol/clis.ts +69 -0
- package/src/protocol/config.ts +60 -6
- package/src/protocol/conversation.ts +272 -0
- package/src/protocol/credentials.ts +145 -0
- package/src/protocol/errors.ts +78 -20
- package/src/protocol/execution.ts +5 -2
- package/src/protocol/factories.ts +55 -7
- package/src/protocol/guards.ts +55 -2
- package/src/protocol/harness.ts +56 -6
- package/src/protocol/history.ts +72 -64
- package/src/protocol/ids.ts +0 -12
- package/src/protocol/index.ts +9 -0
- package/src/protocol/lifecycle.ts +250 -79
- package/src/protocol/meta-keys.ts +17 -0
- package/src/protocol/meta.ts +3 -3
- package/src/protocol/models.ts +2 -43
- package/src/protocol/part-input.ts +2 -1
- package/src/protocol/parts.ts +12 -3
- package/src/protocol/reduce.ts +302 -413
- package/src/protocol/selectors.ts +1 -20
- package/src/protocol/seq-cursor.ts +14 -0
- package/src/protocol/stop-reasons.ts +1 -1
- package/src/protocol/thinking.ts +1 -30
- package/src/protocol/time.ts +2 -2
- package/src/protocol/tool-closure.ts +93 -0
- package/src/protocol/tool-state.ts +19 -4
- package/src/protocol/verify.ts +222 -92
- package/src/protocol/vocabulary.ts +21 -5
- package/src/protocol/wire-api.ts +232 -0
- package/src/protocol/wire.ts +351 -64
- package/src/server/acp/binding.ts +63 -103
- package/src/server/acp/session-records.ts +53 -0
- package/src/server/acp/translate.ts +129 -20
- package/src/server/agent-server.ts +223 -387
- package/src/server/bin.ts +280 -78
- package/src/server/feedback.ts +204 -14
- package/src/server/history.ts +116 -122
- package/src/server/index.ts +3 -8
- package/src/server/install.ts +107 -8
- package/src/server/open-parts.ts +95 -0
- package/src/server/routes.ts +391 -0
- package/src/server/secrets.ts +24 -0
- package/src/server/session-gate.ts +69 -0
- package/src/server/session-log.ts +14 -2
- package/src/server/session-store.ts +136 -72
- package/src/server/subscriptions.ts +232 -0
- package/src/server/transports.ts +125 -25
- package/src/server/wire-error.ts +31 -45
- package/src/sync/event-log.ts +31 -3
- package/src/sync/fit.ts +27 -11
- package/src/sync/history-reader.ts +10 -5
- package/src/sync/history-sqlite.ts +37 -42
- package/src/sync/history.ts +9 -15
- package/src/sync/index.ts +17 -5
- package/src/sync/journal-sqlite.ts +162 -76
- package/src/sync/journal.ts +91 -32
- package/src/sync/live-tails.ts +107 -0
- package/src/sync/projection.ts +35 -0
- package/src/sync/recovery.ts +80 -51
- package/src/sync/schema.ts +27 -6
- package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
- package/docs/rfds/0002-native-subagents.md +0 -197
- package/src/client/request.ts +0 -19
- package/src/core/agents/claude-code/generator-session.ts +0 -572
- package/src/core/agents/claude-code/session-manager.ts +0 -166
- package/src/core/agents/codex-app-server/codex-app-server-agent.ts +0 -962
- package/src/core/agents/codex-items.ts +0 -149
- package/src/core/agents/codex-sdk/adapter.ts +0 -237
- package/src/core/agents/codex-sdk/codex-sdk-agent.ts +0 -330
- package/src/core/agents/tool-meta.ts +0 -68
|
@@ -1,56 +1,50 @@
|
|
|
1
|
+
import { type AgentRuntime, EventSinkError, callbackSink } from "../core/index.ts";
|
|
1
2
|
import {
|
|
2
|
-
type AgentRuntime,
|
|
3
|
-
EventSinkError,
|
|
4
|
-
TurnConflictError,
|
|
5
|
-
callbackSink,
|
|
6
|
-
} from "../core/index.ts";
|
|
7
|
-
import {
|
|
8
|
-
type AgentCapabilities,
|
|
9
|
-
type AgentHarness,
|
|
10
|
-
EventsReplayParamsSchema,
|
|
11
|
-
InitializeParamsSchema,
|
|
12
|
-
type InitializeResult,
|
|
13
3
|
type JsonRpcId,
|
|
14
|
-
|
|
15
|
-
PermissionRespondParamsSchema,
|
|
4
|
+
type LifecycleEvent,
|
|
16
5
|
type RunRequest,
|
|
17
|
-
|
|
18
|
-
SessionConfirmStoppedParamsSchema,
|
|
19
|
-
SessionGetParamsSchema,
|
|
20
|
-
TurnCancelParamsSchema,
|
|
21
|
-
type TurnCancelResult,
|
|
22
|
-
TurnGetParamsSchema,
|
|
23
|
-
TurnStartParamsSchema,
|
|
6
|
+
WIRE_API,
|
|
24
7
|
WIRE_ERROR_CODES,
|
|
25
8
|
WIRE_METHODS,
|
|
26
|
-
WIRE_PROTOCOL_VERSION,
|
|
27
9
|
type WireEventEnvelope,
|
|
28
10
|
type WireImplementationInfo,
|
|
11
|
+
WireRefusal,
|
|
12
|
+
type WireRequestMethod,
|
|
29
13
|
type WireTransport,
|
|
30
|
-
classifyError,
|
|
31
14
|
decodeWireMessage,
|
|
32
15
|
encodeErrorResponse,
|
|
33
|
-
encodeNotification,
|
|
34
16
|
encodeResponse,
|
|
17
|
+
errorInfo,
|
|
35
18
|
generateUUIDv7,
|
|
19
|
+
isLiveOnlyEvent,
|
|
20
|
+
isWireRequestMethod,
|
|
36
21
|
} from "../protocol/index.ts";
|
|
37
|
-
import type { SessionJournal } from "../sync/journal.ts";
|
|
38
|
-
import { type HistoryHost,
|
|
39
|
-
import {
|
|
22
|
+
import type { ClaimOptions, SessionJournal } from "../sync/journal.ts";
|
|
23
|
+
import { type HistoryHost, historyRoutes } from "./history.ts";
|
|
24
|
+
import { OpenParts } from "./open-parts.ts";
|
|
25
|
+
import {
|
|
26
|
+
type RouteContext,
|
|
27
|
+
type RouteHost,
|
|
28
|
+
type Routes,
|
|
29
|
+
durableRoutes,
|
|
30
|
+
executionRoutes,
|
|
31
|
+
} from "./routes.ts";
|
|
32
|
+
import { SessionGate } from "./session-gate.ts";
|
|
33
|
+
import { JournalSessionStore, MemorySessionStore, type SessionLogStore } from "./session-store.ts";
|
|
40
34
|
import {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} from "./wire-error.ts";
|
|
35
|
+
DEFAULT_MAX_BACKLOG_BYTES,
|
|
36
|
+
DEFAULT_MAX_SUBSCRIPTIONS,
|
|
37
|
+
Subscriptions,
|
|
38
|
+
} from "./subscriptions.ts";
|
|
39
|
+
import { parseParams, wireErrorOf } from "./wire-error.ts";
|
|
47
40
|
|
|
48
41
|
export interface AgentServerOptions {
|
|
49
42
|
/**
|
|
50
43
|
* Durable sessions: every admission and event is committed to this journal
|
|
51
44
|
* before it is acknowledged or delivered, and sessions survive a restart.
|
|
52
45
|
* The server takes execution ownership (one owner per journal); the host
|
|
53
|
-
* opens the journal and closes it after shutdown.
|
|
46
|
+
* opens the journal and closes it after shutdown. Open the server with
|
|
47
|
+
* `AgentServer.open`, which stops what a previous owner left running first.
|
|
54
48
|
*/
|
|
55
49
|
journal?: SessionJournal;
|
|
56
50
|
/**
|
|
@@ -63,6 +57,20 @@ export interface AgentServerOptions {
|
|
|
63
57
|
history?: HistoryHost;
|
|
64
58
|
/** Replay ring-buffer size per session (envelopes). Volatile sessions only. */
|
|
65
59
|
bufferSize?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Sessions one connection may ask to watch (`session/subscribe`;
|
|
62
|
+
* `session/subscribeAll` counts once), past which it is refused
|
|
63
|
+
* `subscriptionLimit`. The sessions its own turns subscribe it to do not
|
|
64
|
+
* count. Default 256.
|
|
65
|
+
*/
|
|
66
|
+
maxSubscriptions?: number;
|
|
67
|
+
/**
|
|
68
|
+
* How far behind (in bytes its transport has yet to write) a connection may
|
|
69
|
+
* fall before the server stops streaming it the session it fell behind on,
|
|
70
|
+
* with `session/overflow`. Default 16 MiB. Only a transport that reports
|
|
71
|
+
* `bufferedAmount` is bounded.
|
|
72
|
+
*/
|
|
73
|
+
maxBacklogBytes?: number;
|
|
66
74
|
/** Reported in the `initialize` result. */
|
|
67
75
|
info?: WireImplementationInfo;
|
|
68
76
|
/** Called once a `shutdown` request has been acked and the runtime drained. */
|
|
@@ -70,47 +78,114 @@ export interface AgentServerOptions {
|
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
/**
|
|
73
|
-
* The wire binding
|
|
81
|
+
* The wire binding: serves the engine over JSON-RPC 2.0 on any
|
|
74
82
|
* number of attached transports. Requests flow client -> server only; every
|
|
75
83
|
* lifecycle event is stamped with a per-session monotonic `seq`, buffered for
|
|
76
|
-
* `events/replay`, and
|
|
77
|
-
*
|
|
78
|
-
*
|
|
84
|
+
* `events/replay`, and sent as an `event` notification to the connections
|
|
85
|
+
* subscribed to its session (`session/subscribe`; `turn/start` subscribes its
|
|
86
|
+
* caller) — token deltas with the seq of the last kept event, never buffered.
|
|
87
|
+
* `turn/start` is quick-ack: the response only accepts the turn; completion is
|
|
88
|
+
* the `turn.ended` event. One active turn per session.
|
|
79
89
|
*/
|
|
80
90
|
export class AgentServer {
|
|
81
|
-
|
|
91
|
+
/** The attached connections, and the sessions each receives. */
|
|
92
|
+
private readonly subscriptions: Subscriptions;
|
|
82
93
|
/** The ONE persistence decision: everything else asks the store. */
|
|
83
|
-
private readonly store:
|
|
84
|
-
|
|
85
|
-
private readonly
|
|
94
|
+
private readonly store: SessionLogStore;
|
|
95
|
+
/** Each session's open parts and latest turn start, from the frames this server delivers. */
|
|
96
|
+
private readonly openParts = new OpenParts();
|
|
97
|
+
private readonly gate = new SessionGate();
|
|
98
|
+
/** Every method this server answers: being durable, or serving history, is having their routes. */
|
|
99
|
+
private readonly routes: Partial<Routes<WireRequestMethod>>;
|
|
86
100
|
private readonly observers = new Set<(envelope: WireEventEnvelope) => void>();
|
|
87
|
-
/**
|
|
88
|
-
* One id per server PROCESS, handed out in `initialize`. Within a process,
|
|
89
|
-
* session logs never restart (the store keeps seq monotonic across
|
|
90
|
-
* close/reopen of an id), so a client that sees this id change across a
|
|
91
|
-
* reconnect knows — as a stated fact, not an inference — that every log it
|
|
92
|
-
* tracked belongs to a dead process. Unless `historyId` says they outlive it.
|
|
93
|
-
*/
|
|
94
|
-
private readonly instanceId = generateUUIDv7();
|
|
95
101
|
private shuttingDown = false;
|
|
96
102
|
private shutdownPromise: Promise<void> | undefined;
|
|
103
|
+
private turnsDrained: Promise<void> | undefined;
|
|
104
|
+
/** Stops writing the runtime's native process records into the journal. */
|
|
105
|
+
private readonly unrecord: () => void;
|
|
106
|
+
private readonly unprogress: () => void;
|
|
107
|
+
private readonly unauth: () => void;
|
|
108
|
+
|
|
109
|
+
// @ref LLP 0007#records-and-the-restart-sweep — sweep before claiming, so the claim fences only what is unverified
|
|
110
|
+
/**
|
|
111
|
+
* A server whose restart sweep ran before it took the journal: each native
|
|
112
|
+
* process a previous owner recorded is verified (boot, start time,
|
|
113
|
+
* executable) and, while it is still that process, stopped with its tool
|
|
114
|
+
* sessions. The claim then fences only the sessions whose agent could not
|
|
115
|
+
* be confirmed stopped. Without a journal it is the constructor.
|
|
116
|
+
*/
|
|
117
|
+
static async open(runtime: AgentRuntime, options: AgentServerOptions = {}): Promise<AgentServer> {
|
|
118
|
+
return new AgentServer(runtime, options, await sweep(runtime, options.journal));
|
|
119
|
+
}
|
|
97
120
|
|
|
121
|
+
/**
|
|
122
|
+
* `swept`: what the restart sweep found of the journal's records
|
|
123
|
+
* (`AgentServer.open` passes it). Without it, every session a restart cut
|
|
124
|
+
* off is fenced until the host confirms its agent stopped.
|
|
125
|
+
*/
|
|
98
126
|
constructor(
|
|
99
127
|
private readonly runtime: AgentRuntime,
|
|
100
128
|
private readonly options: AgentServerOptions = {},
|
|
129
|
+
swept?: ClaimOptions,
|
|
101
130
|
) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
131
|
+
const journal =
|
|
132
|
+
options.journal &&
|
|
133
|
+
new JournalSessionStore(options.journal, (error) => this.failStop(error), swept);
|
|
134
|
+
this.store = journal ?? new MemorySessionStore(options.bufferSize);
|
|
135
|
+
this.subscriptions = new Subscriptions({
|
|
136
|
+
maxSubscriptions: options.maxSubscriptions ?? DEFAULT_MAX_SUBSCRIPTIONS,
|
|
137
|
+
maxBacklogBytes: options.maxBacklogBytes ?? DEFAULT_MAX_BACKLOG_BYTES,
|
|
138
|
+
});
|
|
139
|
+
// Each native process a session's turn starts is in the journal before it gets work.
|
|
140
|
+
this.unrecord = journal
|
|
141
|
+
? runtime.onNativeProcess((event) => journal.recordNative(event))
|
|
142
|
+
: () => {};
|
|
143
|
+
// Every connection hears a CLI being installed: whoever caused it,
|
|
144
|
+
// every turn of that harness waits on it.
|
|
145
|
+
this.unprogress = runtime.onCliProgress((progress) =>
|
|
146
|
+
this.subscriptions.notifyAll(WIRE_METHODS.clisProgress, progress),
|
|
147
|
+
);
|
|
148
|
+
// Every connection hears a harness's login change and a login's end:
|
|
149
|
+
// whoever logged in, every turn of that harness runs with it.
|
|
150
|
+
this.unauth = runtime.onAuthUpdated((update) =>
|
|
151
|
+
this.subscriptions.notifyAll(WIRE_METHODS.authUpdated, update),
|
|
152
|
+
);
|
|
153
|
+
const host: RouteHost = {
|
|
154
|
+
runtime,
|
|
155
|
+
store: this.store,
|
|
156
|
+
openParts: this.openParts,
|
|
157
|
+
gate: this.gate,
|
|
158
|
+
subscriptions: this.subscriptions,
|
|
159
|
+
identity: {
|
|
160
|
+
server: options.info ?? { name: "agent-server" },
|
|
161
|
+
// One id per server PROCESS. Within a process, session logs never
|
|
162
|
+
// restart (the store keeps seq monotonic across close/reopen of an
|
|
163
|
+
// id), so a client that sees this id change across a reconnect knows
|
|
164
|
+
// — as a stated fact, not an inference — that every log it tracked
|
|
165
|
+
// belongs to a dead process. Unless `historyId` says they outlive it.
|
|
166
|
+
instanceId: generateUUIDv7(),
|
|
167
|
+
...(options.journal && { historyId: options.journal.sourceId }),
|
|
168
|
+
},
|
|
169
|
+
accepting: () => !this.shuttingDown,
|
|
170
|
+
executeTurn: (request) => void this.executeTurn(request),
|
|
171
|
+
broadcast: (envelope) => this.broadcast(envelope),
|
|
172
|
+
drainTurns: () => this.drainTurns(),
|
|
173
|
+
shutdown: () => this.shutdown(),
|
|
174
|
+
};
|
|
175
|
+
this.routes = {
|
|
176
|
+
...executionRoutes(host),
|
|
177
|
+
...(journal && durableRoutes(journal, host)),
|
|
178
|
+
...(options.history && historyRoutes(options.history)),
|
|
179
|
+
};
|
|
105
180
|
}
|
|
106
181
|
|
|
107
|
-
/** Serve the wire on a transport; returns a detach function. */
|
|
182
|
+
/** Serve the wire on a transport; returns a detach function, which drops its subscriptions. */
|
|
108
183
|
attach(transport: WireTransport): () => void {
|
|
109
|
-
this.
|
|
184
|
+
this.subscriptions.attach(transport);
|
|
110
185
|
const offLine = transport.onLine((line) => void this.handleLine(transport, line));
|
|
111
186
|
const detach = () => {
|
|
112
187
|
offLine();
|
|
113
|
-
this.
|
|
188
|
+
this.subscriptions.detach(transport);
|
|
114
189
|
};
|
|
115
190
|
transport.onClose(detach);
|
|
116
191
|
return detach;
|
|
@@ -119,11 +194,13 @@ export class AgentServer {
|
|
|
119
194
|
/**
|
|
120
195
|
* Observe every broadcast envelope in-process; returns an unsubscribe.
|
|
121
196
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
197
|
+
* Every session's envelopes, subscribed or not — the same sequenced
|
|
198
|
+
* envelopes subscribed transports receive, already appended to the session
|
|
199
|
+
* log (a token delta, which no log keeps, carries the last kept seq) — a
|
|
200
|
+
* host that embeds the server (to keep its own session bookkeeping, mirror
|
|
201
|
+
* events into a DB, trigger follow-up work) gets them as decoded objects
|
|
202
|
+
* instead of attaching a fake transport and parsing its own wire back out
|
|
203
|
+
* of NDJSON.
|
|
127
204
|
*
|
|
128
205
|
* Synchronous and isolated: an observer that throws is swallowed, exactly
|
|
129
206
|
* like a faulty transport or a failing sink — an event is a fact that
|
|
@@ -142,17 +219,23 @@ export class AgentServer {
|
|
|
142
219
|
return this.shutdownPromise;
|
|
143
220
|
}
|
|
144
221
|
|
|
145
|
-
|
|
222
|
+
/** Cancel all turns and terminate harnesses: their turn.ended are broadcast. */
|
|
223
|
+
private drainTurns(): Promise<void> {
|
|
146
224
|
this.shuttingDown = true;
|
|
225
|
+
this.turnsDrained ??= this.runtime.shutdown();
|
|
226
|
+
return this.turnsDrained;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private async drain(): Promise<void> {
|
|
147
230
|
// Drain first so cancelled turns still broadcast their turn.ended.
|
|
148
231
|
// The drain (and each transport's close) is a library extension point
|
|
149
232
|
// that may throw; the finally still closes every transport and runs the
|
|
150
233
|
// host hook even then — every other external call in this file is
|
|
151
234
|
// defended the same way (broadcast/observers/sink/handleLine).
|
|
152
235
|
try {
|
|
153
|
-
await this.
|
|
236
|
+
await this.drainTurns();
|
|
154
237
|
} finally {
|
|
155
|
-
for (const transport of
|
|
238
|
+
for (const transport of this.subscriptions.transports()) {
|
|
156
239
|
try {
|
|
157
240
|
transport.close();
|
|
158
241
|
} catch {
|
|
@@ -160,7 +243,10 @@ export class AgentServer {
|
|
|
160
243
|
// host's shutdown hook — same isolation broadcast uses for send.
|
|
161
244
|
}
|
|
162
245
|
}
|
|
163
|
-
this.
|
|
246
|
+
this.unrecord();
|
|
247
|
+
this.unprogress();
|
|
248
|
+
this.unauth();
|
|
249
|
+
this.store.relinquish();
|
|
164
250
|
this.options.onShutdown?.();
|
|
165
251
|
}
|
|
166
252
|
}
|
|
@@ -204,309 +290,46 @@ export class AgentServer {
|
|
|
204
290
|
method: string,
|
|
205
291
|
params: unknown,
|
|
206
292
|
): Promise<void> {
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
{ supported: [WIRE_PROTOCOL_VERSION] },
|
|
223
|
-
),
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
const harnesses: Record<string, AgentCapabilities> = {};
|
|
227
|
-
for (const harness of this.runtime.harnesses) {
|
|
228
|
-
harnesses[harness] = this.runtime.capabilities(harness);
|
|
229
|
-
}
|
|
230
|
-
const result: InitializeResult = {
|
|
231
|
-
protocolVersion: WIRE_PROTOCOL_VERSION,
|
|
232
|
-
server: this.options.info ?? { name: "agent-server" },
|
|
233
|
-
instanceId: this.instanceId,
|
|
234
|
-
...(this.store.historyId && { historyId: this.store.historyId }),
|
|
235
|
-
harnesses,
|
|
236
|
-
};
|
|
237
|
-
return transport.send(encodeResponse(id, result));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
case WIRE_METHODS.turnStart: {
|
|
241
|
-
const parsed = TurnStartParamsSchema.safeParse(params);
|
|
242
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
243
|
-
if (this.shuttingDown) {
|
|
244
|
-
return transport.send(
|
|
245
|
-
encodeErrorResponse(id, WIRE_ERROR_CODES.shuttingDown, "server is shutting down"),
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
const { config, input } = parsed.data;
|
|
249
|
-
if (!this.runtime.harnesses.includes(config.harness)) {
|
|
250
|
-
return transport.send(
|
|
251
|
-
encodeErrorResponse(
|
|
252
|
-
id,
|
|
253
|
-
WIRE_ERROR_CODES.harnessNotAvailable,
|
|
254
|
-
`harness not available: ${config.harness}`,
|
|
255
|
-
{ available: this.runtime.harnesses },
|
|
256
|
-
),
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
const sessionId = parsed.data.sessionId ?? generateUUIDv7();
|
|
260
|
-
const turnId = parsed.data.turnId ?? generateUUIDv7();
|
|
261
|
-
if (this.closingSessions.has(sessionId)) {
|
|
262
|
-
return transport.send(
|
|
263
|
-
encodeErrorResponse(
|
|
264
|
-
id,
|
|
265
|
-
WIRE_ERROR_CODES.sessionClosing,
|
|
266
|
-
`session ${sessionId} is closing`,
|
|
267
|
-
),
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
// Idempotent admission: a retried start (same turnId, identical
|
|
271
|
-
// input) converges — ack again, never run twice; `events/replay`
|
|
272
|
-
// serves anything the retryer missed. A durable store remembers
|
|
273
|
-
// every turn it admitted, the runtime only its recent ones. The
|
|
274
|
-
// same turnId with different input is a caller bug → turnConflict.
|
|
275
|
-
const request = { sessionId, turnId, input, config };
|
|
276
|
-
try {
|
|
277
|
-
const duplicate =
|
|
278
|
-
this.store.duplicateOf(request) ??
|
|
279
|
-
(this.runtime.admission(request).status === "new" ? undefined : {});
|
|
280
|
-
if (duplicate) {
|
|
281
|
-
return transport.send(
|
|
282
|
-
encodeResponse(id, { sessionId, turnId, deduplicated: true, ...duplicate }),
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
} catch (err) {
|
|
286
|
-
if (err instanceof TurnConflictError) {
|
|
287
|
-
return transport.send(
|
|
288
|
-
encodeErrorResponse(id, WIRE_ERROR_CODES.turnConflict, err.message, { turnId }),
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
throw err;
|
|
292
|
-
}
|
|
293
|
-
const bound = this.store.harnessOf(sessionId);
|
|
294
|
-
if (bound && bound !== config.harness) {
|
|
295
|
-
return transport.send(
|
|
296
|
-
encodeErrorResponse(
|
|
297
|
-
id,
|
|
298
|
-
WIRE_ERROR_CODES.invalidParams,
|
|
299
|
-
`session ${sessionId} is bound to harness ${bound}`,
|
|
300
|
-
),
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
if (this.activeTurns.has(sessionId)) {
|
|
304
|
-
return transport.send(
|
|
305
|
-
encodeErrorResponse(
|
|
306
|
-
id,
|
|
307
|
-
WIRE_ERROR_CODES.turnActive,
|
|
308
|
-
`session ${sessionId} already has an active turn`,
|
|
309
|
-
{ turnId: this.activeTurns.get(sessionId)?.turnId },
|
|
310
|
-
),
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
this.store.open(request);
|
|
314
|
-
this.activeTurns.set(sessionId, { turnId, harness: config.harness });
|
|
315
|
-
// Quick-ack before the first event can possibly be emitted. The turn
|
|
316
|
-
// runs (and releases its session) even if the requester is gone.
|
|
317
|
-
try {
|
|
318
|
-
transport.send(encodeResponse(id, { sessionId, turnId }));
|
|
319
|
-
} finally {
|
|
320
|
-
void this.executeTurn(request);
|
|
321
|
-
}
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
case WIRE_METHODS.turnCancel: {
|
|
326
|
-
const parsed = TurnCancelParamsSchema.safeParse(params);
|
|
327
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
328
|
-
const active = this.activeTurns.get(parsed.data.sessionId);
|
|
329
|
-
if (!active) {
|
|
330
|
-
return transport.send(
|
|
331
|
-
encodeResponse(id, { outcome: "no_active_turn" } satisfies TurnCancelResult),
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
if (parsed.data.turnId && parsed.data.turnId !== active.turnId) {
|
|
335
|
-
// Turn-stamped cancel for a turn that is no longer the active one —
|
|
336
|
-
// refuse to kill its successor; report who IS active instead.
|
|
337
|
-
return transport.send(
|
|
338
|
-
encodeResponse(id, {
|
|
339
|
-
outcome: "no_active_turn",
|
|
340
|
-
activeTurnId: active.turnId,
|
|
341
|
-
} satisfies TurnCancelResult),
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
const { confirmed, hadTurn } = await this.runtime.cancel(
|
|
345
|
-
active.harness,
|
|
346
|
-
parsed.data.sessionId,
|
|
347
|
-
);
|
|
348
|
-
// An unacknowledged interrupt is NOT a cancel: the agent may still be
|
|
349
|
-
// running and `turn.ended` stays the source of truth. `hadTurn: false`
|
|
350
|
-
// while the server tracks an active turn is the pre-first-yield window
|
|
351
|
-
// (between the turn/start quick-ack and the harness registering its
|
|
352
|
-
// abortable turn) — the abort landed on nothing and the turn may run
|
|
353
|
-
// to completion, so it must report `unconfirmed`, never a clean cancel.
|
|
354
|
-
return transport.send(
|
|
355
|
-
encodeResponse(id, {
|
|
356
|
-
outcome: confirmed && hadTurn ? "cancelled" : "unconfirmed",
|
|
357
|
-
turnId: active.turnId,
|
|
358
|
-
} satisfies TurnCancelResult),
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
case WIRE_METHODS.sessionClose: {
|
|
363
|
-
const parsed = SessionCloseParamsSchema.safeParse(params);
|
|
364
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
365
|
-
const { sessionId } = parsed.data;
|
|
366
|
-
if (this.closingSessions.has(sessionId)) {
|
|
367
|
-
return transport.send(
|
|
368
|
-
encodeErrorResponse(
|
|
369
|
-
id,
|
|
370
|
-
WIRE_ERROR_CODES.sessionClosing,
|
|
371
|
-
`session ${sessionId} is closing`,
|
|
372
|
-
),
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
const active = this.activeTurns.get(sessionId);
|
|
376
|
-
if (active) {
|
|
377
|
-
return transport.send(
|
|
378
|
-
encodeErrorResponse(
|
|
379
|
-
id,
|
|
380
|
-
WIRE_ERROR_CODES.turnActive,
|
|
381
|
-
`session ${sessionId} has an active turn`,
|
|
382
|
-
{ turnId: active.turnId },
|
|
383
|
-
),
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
const harness = this.store.closing(sessionId);
|
|
387
|
-
if (!harness) return transport.send(encodeResponse(id, { closed: false }));
|
|
388
|
-
this.closingSessions.add(sessionId);
|
|
389
|
-
try {
|
|
390
|
-
await this.runtime.closeSession(harness, sessionId);
|
|
391
|
-
// The terminal fact for CONNECTED subscribers (spec §6.1): they
|
|
392
|
-
// learn the session is over from the stream, not from the RPC
|
|
393
|
-
// result (which only the closer sees). Appending it retires the
|
|
394
|
-
// session (see SessionStore.append).
|
|
395
|
-
this.broadcast(
|
|
396
|
-
this.store.append(sessionId, {
|
|
397
|
-
type: "session.ended",
|
|
398
|
-
sessionId,
|
|
399
|
-
reason: "released",
|
|
400
|
-
timestamp: Date.now(),
|
|
401
|
-
}),
|
|
402
|
-
);
|
|
403
|
-
return transport.send(encodeResponse(id, { closed: true }));
|
|
404
|
-
} finally {
|
|
405
|
-
this.closingSessions.delete(sessionId);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
case WIRE_METHODS.permissionRespond: {
|
|
410
|
-
const parsed = PermissionRespondParamsSchema.safeParse(params);
|
|
411
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
412
|
-
const accepted = this.runtime.respondPermission(
|
|
413
|
-
parsed.data.sessionId,
|
|
414
|
-
parsed.data.requestId,
|
|
415
|
-
parsed.data.outcome,
|
|
416
|
-
);
|
|
417
|
-
return transport.send(encodeResponse(id, { accepted }));
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
case WIRE_METHODS.eventsReplay: {
|
|
421
|
-
const parsed = EventsReplayParamsSchema.safeParse(params);
|
|
422
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
423
|
-
const replayed = this.store.replay(parsed.data.sessionId, parsed.data.fromSeq);
|
|
424
|
-
if (!replayed) {
|
|
425
|
-
return transport.send(
|
|
426
|
-
encodeErrorResponse(
|
|
427
|
-
id,
|
|
428
|
-
WIRE_ERROR_CODES.unknownSession,
|
|
429
|
-
`unknown session: ${parsed.data.sessionId}`,
|
|
430
|
-
),
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
|
-
return transport.send(encodeResponse(id, replayed));
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
case WIRE_METHODS.turnGet: {
|
|
437
|
-
if (!this.store.receipt) break;
|
|
438
|
-
const { sessionId, turnId } = parseParams(TurnGetParamsSchema, params);
|
|
439
|
-
const receipt = this.store.receipt(sessionId, turnId);
|
|
440
|
-
if (!receipt)
|
|
441
|
-
throw new WireError(WIRE_ERROR_CODES.unknownSession, `unknown turn: ${turnId}`);
|
|
442
|
-
return transport.send(encodeResponse(id, receipt));
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
case WIRE_METHODS.sessionGet: {
|
|
446
|
-
if (!this.store.session) break;
|
|
447
|
-
const { sessionId } = parseParams(SessionGetParamsSchema, params);
|
|
448
|
-
const session = this.store.session(sessionId);
|
|
449
|
-
if (!session)
|
|
450
|
-
throw new WireError(WIRE_ERROR_CODES.unknownSession, `unknown session: ${sessionId}`);
|
|
451
|
-
return transport.send(encodeResponse(id, session));
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
case WIRE_METHODS.sessionConfirmStopped: {
|
|
455
|
-
if (!this.store.confirmStopped) break;
|
|
456
|
-
const { sessionId, expectedHeadSeq } = parseParams(
|
|
457
|
-
SessionConfirmStoppedParamsSchema,
|
|
458
|
-
params,
|
|
459
|
-
);
|
|
460
|
-
const recovered = this.store.confirmStopped(sessionId, expectedHeadSeq);
|
|
461
|
-
return transport.send(encodeResponse(id, { recovered }));
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
case WIRE_METHODS.modelsList: {
|
|
465
|
-
const parsed = ModelsListParamsSchema.safeParse(params);
|
|
466
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
467
|
-
if (!this.runtime.harnesses.includes(parsed.data.harness)) {
|
|
468
|
-
return transport.send(
|
|
469
|
-
encodeErrorResponse(
|
|
470
|
-
id,
|
|
471
|
-
WIRE_ERROR_CODES.harnessNotAvailable,
|
|
472
|
-
`harness not available: ${parsed.data.harness}`,
|
|
473
|
-
{ available: this.runtime.harnesses },
|
|
474
|
-
),
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
return transport.send(encodeResponse(id, await this.runtime.models(parsed.data)));
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
case WIRE_METHODS.shutdown: {
|
|
481
|
-
transport.send(encodeResponse(id, {}));
|
|
482
|
-
// The success ack is already committed on the wire; a throw out of
|
|
483
|
-
// shutdown() must not reach handleLine's catch and emit a second
|
|
484
|
-
// response for this id (a JSON-RPC 2.0 violation).
|
|
485
|
-
await this.shutdown().catch(() => {});
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
293
|
+
if (!isWireRequestMethod(method))
|
|
294
|
+
throw new WireRefusal("methodNotFound", `unknown method: ${method}`);
|
|
295
|
+
const after: Array<() => void> = [];
|
|
296
|
+
const afterResponse = (then: () => void) => {
|
|
297
|
+
after.push(then);
|
|
298
|
+
};
|
|
299
|
+
try {
|
|
300
|
+
const answer = this.answer(method, params, { transport, afterResponse });
|
|
301
|
+
// @ref LLP 0008#ordering-joining-without-a-gap-or-a-duplicate — a synchronous route is answered in the same breath
|
|
302
|
+
// No await for a route that answered synchronously: a frame sent
|
|
303
|
+
// between its registration and its answer would precede the point
|
|
304
|
+
// the answer marks.
|
|
305
|
+
transport.send(encodeResponse(id, answer instanceof Promise ? await answer : answer));
|
|
306
|
+
} finally {
|
|
307
|
+
for (const then of after) then();
|
|
488
308
|
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** A request's answer from its route, its params parsed by `WIRE_API` unless the route reads its own. */
|
|
312
|
+
private answer<M extends WireRequestMethod>(method: M, params: unknown, context: RouteContext) {
|
|
313
|
+
const route = this.routes[method];
|
|
489
314
|
// Unknown here, or durable-only on a volatile server.
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
);
|
|
315
|
+
if (!route) throw new WireRefusal("methodNotFound", `unknown method: ${method}`);
|
|
316
|
+
if ("unparsed" in route) return route.unparsed(params, context);
|
|
317
|
+
return route(parseParams(WIRE_API[method].params, params ?? {}), context);
|
|
493
318
|
}
|
|
494
319
|
|
|
495
320
|
private async executeTurn(request: RunRequest): Promise<void> {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const releaseTurn = () => {
|
|
500
|
-
if (this.activeTurns.get(request.sessionId)?.turnId === request.turnId) {
|
|
501
|
-
this.activeTurns.delete(request.sessionId);
|
|
502
|
-
}
|
|
503
|
-
};
|
|
321
|
+
const { sessionId, turnId } = request;
|
|
322
|
+
/** The runtime emitted the turn's `turn.started`. */
|
|
323
|
+
let started = false;
|
|
504
324
|
const sink = callbackSink((event) => {
|
|
505
|
-
const envelope =
|
|
325
|
+
const envelope = isLiveOnlyEvent(event)
|
|
326
|
+
? this.store.live(sessionId, event)
|
|
327
|
+
: this.store.append(sessionId, event);
|
|
328
|
+
if (event.type === "turn.started") started = true;
|
|
506
329
|
// Once turn.ended is on the wire the session is idle — clear the busy
|
|
507
330
|
// mark here (not when run() settles) so clients acting on the event
|
|
508
331
|
// never race the bookkeeping.
|
|
509
|
-
if (event.type === "turn.ended")
|
|
332
|
+
if (event.type === "turn.ended") this.gate.settle(sessionId, turnId);
|
|
510
333
|
this.broadcast(envelope);
|
|
511
334
|
});
|
|
512
335
|
try {
|
|
@@ -515,31 +338,38 @@ export class AgentServer {
|
|
|
515
338
|
// The store could not commit: deliver nothing it did not record, not
|
|
516
339
|
// even a turn.ended. Its fault already stops the server.
|
|
517
340
|
if (err instanceof EventSinkError) return;
|
|
341
|
+
// @ref LLP 0002#ordering-and-delivery — no turn.ended without its turn.started
|
|
518
342
|
// runtime.run reports errors via events; a throw means it died before
|
|
519
|
-
// emitting turn.ended — synthesize one so clients are never left
|
|
520
|
-
|
|
343
|
+
// emitting turn.ended — synthesize one so clients are never left
|
|
344
|
+
// hanging. One it refused before starting (it was shutting down, the
|
|
345
|
+
// harness could not be set up) emitted nothing: its start goes first.
|
|
346
|
+
const timestamp = Date.now();
|
|
347
|
+
const synthesized: LifecycleEvent[] = [];
|
|
348
|
+
if (!started) synthesized.push({ type: "turn.started", sessionId, turnId, timestamp });
|
|
349
|
+
synthesized.push({
|
|
350
|
+
type: "turn.ended",
|
|
351
|
+
sessionId,
|
|
352
|
+
turnId,
|
|
353
|
+
stopReason: "error",
|
|
354
|
+
error: errorInfo(err),
|
|
355
|
+
timestamp,
|
|
356
|
+
});
|
|
521
357
|
try {
|
|
522
|
-
this.broadcast(
|
|
523
|
-
this.store.append(request.sessionId, {
|
|
524
|
-
type: "turn.ended",
|
|
525
|
-
sessionId: request.sessionId,
|
|
526
|
-
turnId: request.turnId,
|
|
527
|
-
stopReason: "error",
|
|
528
|
-
error: { category: classifyError(err), message },
|
|
529
|
-
timestamp: Date.now(),
|
|
530
|
-
}),
|
|
531
|
-
);
|
|
358
|
+
for (const event of synthesized) this.broadcast(this.store.append(sessionId, event));
|
|
532
359
|
} catch {
|
|
533
360
|
// A store that cannot commit it has failed, and stops the server.
|
|
534
361
|
}
|
|
535
362
|
} finally {
|
|
536
|
-
|
|
363
|
+
this.gate.settle(sessionId, turnId);
|
|
537
364
|
}
|
|
538
365
|
}
|
|
539
366
|
|
|
540
367
|
private broadcast(envelope: WireEventEnvelope): void {
|
|
368
|
+
// @ref LLP 0008#open-parts-in-memory — kept as delivered, in the breath that delivers it
|
|
369
|
+
// What the store returned, as it stored it, before any connection hears it.
|
|
370
|
+
this.openParts.delivered(envelope);
|
|
541
371
|
// In-process observers first: they see the same envelope, in the same
|
|
542
|
-
// order, whether or not any transport is attached.
|
|
372
|
+
// order, whether or not any transport is attached or subscribed.
|
|
543
373
|
for (const observer of [...this.observers]) {
|
|
544
374
|
try {
|
|
545
375
|
observer(envelope);
|
|
@@ -547,22 +377,28 @@ export class AgentServer {
|
|
|
547
377
|
// An observer's failure is its own; the event is already logged.
|
|
548
378
|
}
|
|
549
379
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
} catch {
|
|
555
|
-
// One faulty transport must not starve the others; the event is
|
|
556
|
-
// already in the session log, so the client heals via replay. The
|
|
557
|
-
// one exception is `session.ended` from `session/close`, whose log
|
|
558
|
-
// is retired in the same breath — a client that missed it learns the
|
|
559
|
-
// session is over from `unknownSession` on replay instead.
|
|
560
|
-
}
|
|
561
|
-
}
|
|
380
|
+
// A transport that fails a send heals via replay; `session.ended` retires
|
|
381
|
+
// the log in the same breath, so one that missed it learns the session
|
|
382
|
+
// is over from `unknownSession` instead.
|
|
383
|
+
this.subscriptions.deliver(envelope);
|
|
562
384
|
}
|
|
385
|
+
}
|
|
563
386
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Verify and stop what the journal's records name, before anything claims it:
|
|
389
|
+
* record ids by what became of them. Undefined without a journal.
|
|
390
|
+
*/
|
|
391
|
+
async function sweep(
|
|
392
|
+
runtime: AgentRuntime,
|
|
393
|
+
journal: SessionJournal | undefined,
|
|
394
|
+
): Promise<ClaimOptions | undefined> {
|
|
395
|
+
if (!journal) return undefined;
|
|
396
|
+
const records = journal.nativeProcesses();
|
|
397
|
+
const stopped = new Set<number>();
|
|
398
|
+
const notStopped = new Set<number>();
|
|
399
|
+
for (const [record, outcome] of await runtime.stopOrphans(records)) {
|
|
400
|
+
if (outcome === "gone" || outcome === "stopped") stopped.add(record.id);
|
|
401
|
+
else if (outcome === "not_stopped") notStopped.add(record.id);
|
|
567
402
|
}
|
|
403
|
+
return { stopped, notStopped, recorded: runtime.recordedHarnesses() };
|
|
568
404
|
}
|