@zvada/agent-server 0.3.17 → 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 +1060 -0
- package/README.md +50 -26
- 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 +460 -54
- package/docs/deploy.md +218 -47
- package/docs/durable-sessions.md +195 -0
- package/docs/feedback.md +116 -0
- package/docs/harnesses.md +219 -87
- package/docs/sync-history.md +197 -0
- package/docs/sync-integration.md +119 -0
- package/package.json +53 -23
- 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 +641 -602
- package/src/client/connection.ts +371 -0
- package/src/client/history.ts +65 -0
- 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 +60 -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 +11 -34
- 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 +340 -481
- package/src/core/runtime/event-processor.ts +207 -75
- package/src/core/runtime/event-sink.ts +45 -2
- 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 +57 -57
- 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 +275 -0
- package/src/protocol/ids.ts +4 -17
- package/src/protocol/index.ts +10 -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 +425 -57
- 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 +275 -366
- package/src/server/bin.ts +295 -72
- package/src/server/feedback.ts +204 -14
- package/src/server/history.ts +160 -0
- package/src/server/index.ts +4 -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 +289 -0
- package/src/server/subscriptions.ts +232 -0
- package/src/server/transports.ts +125 -25
- package/src/server/wire-error.ts +38 -0
- package/src/sync/event-log.ts +160 -0
- package/src/sync/fit.ts +140 -0
- package/src/sync/history-reader.ts +57 -0
- package/src/sync/history-sqlite.ts +339 -0
- package/src/sync/history.ts +220 -0
- package/src/sync/index.ts +18 -0
- package/src/sync/journal-sqlite.ts +439 -0
- package/src/sync/journal.ts +132 -0
- package/src/sync/live-tails.ts +107 -0
- package/src/sync/node-sqlite.ts +20 -0
- package/src/sync/projection.ts +35 -0
- package/src/sync/recovery.ts +141 -0
- package/src/sync/retry.ts +49 -0
- package/src/sync/schema.ts +77 -0
- package/src/sync/sql.ts +106 -0
- package/src/sync/sqlite-file.ts +38 -0
- package/src/sync/sqlite.ts +21 -0
- package/src/sync/worker.ts +259 -0
- package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
- package/docs/rfds/0002-native-subagents.md +0 -197
- 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,41 +1,76 @@
|
|
|
1
|
-
import { type AgentRuntime,
|
|
1
|
+
import { type AgentRuntime, EventSinkError, callbackSink } from "../core/index.ts";
|
|
2
2
|
import {
|
|
3
|
-
type AgentCapabilities,
|
|
4
|
-
type AgentHarness,
|
|
5
|
-
EventsReplayParamsSchema,
|
|
6
|
-
InitializeParamsSchema,
|
|
7
|
-
type InitializeResult,
|
|
8
3
|
type JsonRpcId,
|
|
9
|
-
|
|
10
|
-
PermissionRespondParamsSchema,
|
|
4
|
+
type LifecycleEvent,
|
|
11
5
|
type RunRequest,
|
|
12
|
-
|
|
13
|
-
TurnCancelParamsSchema,
|
|
14
|
-
type TurnCancelResult,
|
|
15
|
-
TurnStartParamsSchema,
|
|
6
|
+
WIRE_API,
|
|
16
7
|
WIRE_ERROR_CODES,
|
|
17
8
|
WIRE_METHODS,
|
|
18
|
-
WIRE_PROTOCOL_VERSION,
|
|
19
9
|
type WireEventEnvelope,
|
|
20
10
|
type WireImplementationInfo,
|
|
11
|
+
WireRefusal,
|
|
12
|
+
type WireRequestMethod,
|
|
21
13
|
type WireTransport,
|
|
22
|
-
classifyError,
|
|
23
14
|
decodeWireMessage,
|
|
24
15
|
encodeErrorResponse,
|
|
25
|
-
encodeNotification,
|
|
26
16
|
encodeResponse,
|
|
17
|
+
errorInfo,
|
|
27
18
|
generateUUIDv7,
|
|
19
|
+
isLiveOnlyEvent,
|
|
20
|
+
isWireRequestMethod,
|
|
28
21
|
} from "../protocol/index.ts";
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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";
|
|
34
|
+
import {
|
|
35
|
+
DEFAULT_MAX_BACKLOG_BYTES,
|
|
36
|
+
DEFAULT_MAX_SUBSCRIPTIONS,
|
|
37
|
+
Subscriptions,
|
|
38
|
+
} from "./subscriptions.ts";
|
|
39
|
+
import { parseParams, wireErrorOf } from "./wire-error.ts";
|
|
35
40
|
|
|
36
41
|
export interface AgentServerOptions {
|
|
37
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Durable sessions: every admission and event is committed to this journal
|
|
44
|
+
* before it is acknowledged or delivered, and sessions survive a restart.
|
|
45
|
+
* The server takes execution ownership (one owner per journal); the host
|
|
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.
|
|
48
|
+
*/
|
|
49
|
+
journal?: SessionJournal;
|
|
50
|
+
/**
|
|
51
|
+
* The journal failed to write. The server then stops (as `shutdown`), and
|
|
52
|
+
* restart recovery decides what the turns it cut off did. Called once,
|
|
53
|
+
* before `onShutdown`.
|
|
54
|
+
*/
|
|
55
|
+
onJournalError?: (error: unknown) => void;
|
|
56
|
+
/** Opt-in `history/*` methods. The host supplies the store and its access control. */
|
|
57
|
+
history?: HistoryHost;
|
|
58
|
+
/** Replay ring-buffer size per session (envelopes). Volatile sessions only. */
|
|
38
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;
|
|
39
74
|
/** Reported in the `initialize` result. */
|
|
40
75
|
info?: WireImplementationInfo;
|
|
41
76
|
/** Called once a `shutdown` request has been acked and the runtime drained. */
|
|
@@ -43,46 +78,114 @@ export interface AgentServerOptions {
|
|
|
43
78
|
}
|
|
44
79
|
|
|
45
80
|
/**
|
|
46
|
-
* The wire binding
|
|
81
|
+
* The wire binding: serves the engine over JSON-RPC 2.0 on any
|
|
47
82
|
* number of attached transports. Requests flow client -> server only; every
|
|
48
83
|
* lifecycle event is stamped with a per-session monotonic `seq`, buffered for
|
|
49
|
-
* `events/replay`, and
|
|
50
|
-
*
|
|
51
|
-
*
|
|
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.
|
|
52
89
|
*/
|
|
53
90
|
export class AgentServer {
|
|
54
|
-
|
|
55
|
-
private readonly
|
|
56
|
-
|
|
57
|
-
private readonly
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
private readonly
|
|
91
|
+
/** The attached connections, and the sessions each receives. */
|
|
92
|
+
private readonly subscriptions: Subscriptions;
|
|
93
|
+
/** The ONE persistence decision: everything else asks the store. */
|
|
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>>;
|
|
63
100
|
private readonly observers = new Set<(envelope: WireEventEnvelope) => void>();
|
|
101
|
+
private shuttingDown = false;
|
|
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
|
|
64
110
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
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.
|
|
70
116
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
117
|
+
static async open(runtime: AgentRuntime, options: AgentServerOptions = {}): Promise<AgentServer> {
|
|
118
|
+
return new AgentServer(runtime, options, await sweep(runtime, options.journal));
|
|
119
|
+
}
|
|
73
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
|
+
*/
|
|
74
126
|
constructor(
|
|
75
127
|
private readonly runtime: AgentRuntime,
|
|
76
128
|
private readonly options: AgentServerOptions = {},
|
|
77
|
-
|
|
129
|
+
swept?: ClaimOptions,
|
|
130
|
+
) {
|
|
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
|
+
};
|
|
180
|
+
}
|
|
78
181
|
|
|
79
|
-
/** 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. */
|
|
80
183
|
attach(transport: WireTransport): () => void {
|
|
81
|
-
this.
|
|
184
|
+
this.subscriptions.attach(transport);
|
|
82
185
|
const offLine = transport.onLine((line) => void this.handleLine(transport, line));
|
|
83
186
|
const detach = () => {
|
|
84
187
|
offLine();
|
|
85
|
-
this.
|
|
188
|
+
this.subscriptions.detach(transport);
|
|
86
189
|
};
|
|
87
190
|
transport.onClose(detach);
|
|
88
191
|
return detach;
|
|
@@ -91,11 +194,13 @@ export class AgentServer {
|
|
|
91
194
|
/**
|
|
92
195
|
* Observe every broadcast envelope in-process; returns an unsubscribe.
|
|
93
196
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
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.
|
|
99
204
|
*
|
|
100
205
|
* Synchronous and isolated: an observer that throws is swallowed, exactly
|
|
101
206
|
* like a faulty transport or a failing sink — an event is a fact that
|
|
@@ -107,19 +212,30 @@ export class AgentServer {
|
|
|
107
212
|
return () => this.observers.delete(observer);
|
|
108
213
|
}
|
|
109
214
|
|
|
110
|
-
/** Cancel all turns, terminate harnesses, and close every transport.
|
|
111
|
-
|
|
112
|
-
|
|
215
|
+
/** Cancel all turns, terminate harnesses, and close every transport. Every
|
|
216
|
+
* caller waits for the same drain. */
|
|
217
|
+
shutdown(): Promise<void> {
|
|
218
|
+
this.shutdownPromise ??= this.drain();
|
|
219
|
+
return this.shutdownPromise;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Cancel all turns and terminate harnesses: their turn.ended are broadcast. */
|
|
223
|
+
private drainTurns(): Promise<void> {
|
|
113
224
|
this.shuttingDown = true;
|
|
225
|
+
this.turnsDrained ??= this.runtime.shutdown();
|
|
226
|
+
return this.turnsDrained;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private async drain(): Promise<void> {
|
|
114
230
|
// Drain first so cancelled turns still broadcast their turn.ended.
|
|
115
231
|
// The drain (and each transport's close) is a library extension point
|
|
116
232
|
// that may throw; the finally still closes every transport and runs the
|
|
117
233
|
// host hook even then — every other external call in this file is
|
|
118
234
|
// defended the same way (broadcast/observers/sink/handleLine).
|
|
119
235
|
try {
|
|
120
|
-
await this.
|
|
236
|
+
await this.drainTurns();
|
|
121
237
|
} finally {
|
|
122
|
-
for (const transport of
|
|
238
|
+
for (const transport of this.subscriptions.transports()) {
|
|
123
239
|
try {
|
|
124
240
|
transport.close();
|
|
125
241
|
} catch {
|
|
@@ -127,10 +243,24 @@ export class AgentServer {
|
|
|
127
243
|
// host's shutdown hook — same isolation broadcast uses for send.
|
|
128
244
|
}
|
|
129
245
|
}
|
|
246
|
+
this.unrecord();
|
|
247
|
+
this.unprogress();
|
|
248
|
+
this.unauth();
|
|
249
|
+
this.store.relinquish();
|
|
130
250
|
this.options.onShutdown?.();
|
|
131
251
|
}
|
|
132
252
|
}
|
|
133
253
|
|
|
254
|
+
/** The journal failed to write: stop, delivering nothing it did not commit. */
|
|
255
|
+
private failStop(error: unknown): void {
|
|
256
|
+
try {
|
|
257
|
+
this.options.onJournalError?.(error);
|
|
258
|
+
} catch {
|
|
259
|
+
// The host's hook must not keep the server running.
|
|
260
|
+
}
|
|
261
|
+
void this.shutdown().catch(() => {});
|
|
262
|
+
}
|
|
263
|
+
|
|
134
264
|
private async handleLine(transport: WireTransport, line: string): Promise<void> {
|
|
135
265
|
if (!line.trim()) return;
|
|
136
266
|
const msg = decodeWireMessage(line);
|
|
@@ -145,8 +275,12 @@ export class AgentServer {
|
|
|
145
275
|
try {
|
|
146
276
|
await this.handleRequest(transport, msg.id, msg.method, msg.params);
|
|
147
277
|
} catch (err) {
|
|
148
|
-
const
|
|
149
|
-
|
|
278
|
+
const { code, message, data } = wireErrorOf(err);
|
|
279
|
+
try {
|
|
280
|
+
transport.send(encodeErrorResponse(msg.id, code, message, data));
|
|
281
|
+
} catch {
|
|
282
|
+
// The requester is gone; nothing else is owed this response.
|
|
283
|
+
}
|
|
150
284
|
}
|
|
151
285
|
}
|
|
152
286
|
|
|
@@ -156,311 +290,86 @@ export class AgentServer {
|
|
|
156
290
|
method: string,
|
|
157
291
|
params: unknown,
|
|
158
292
|
): Promise<void> {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
for (const harness of this.runtime.harnesses) {
|
|
175
|
-
harnesses[harness] = this.runtime.capabilities(harness);
|
|
176
|
-
}
|
|
177
|
-
const result: InitializeResult = {
|
|
178
|
-
protocolVersion: WIRE_PROTOCOL_VERSION,
|
|
179
|
-
server: this.options.info ?? { name: "agent-server" },
|
|
180
|
-
instanceId: this.instanceId,
|
|
181
|
-
harnesses,
|
|
182
|
-
};
|
|
183
|
-
return transport.send(encodeResponse(id, result));
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
case WIRE_METHODS.turnStart: {
|
|
187
|
-
const parsed = TurnStartParamsSchema.safeParse(params);
|
|
188
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
189
|
-
if (this.shuttingDown) {
|
|
190
|
-
return transport.send(
|
|
191
|
-
encodeErrorResponse(id, WIRE_ERROR_CODES.shuttingDown, "server is shutting down"),
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
const { config, input } = parsed.data;
|
|
195
|
-
if (!this.runtime.harnesses.includes(config.harness)) {
|
|
196
|
-
return transport.send(
|
|
197
|
-
encodeErrorResponse(
|
|
198
|
-
id,
|
|
199
|
-
WIRE_ERROR_CODES.harnessNotAvailable,
|
|
200
|
-
`harness not available: ${config.harness}`,
|
|
201
|
-
{ available: this.runtime.harnesses },
|
|
202
|
-
),
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
const sessionId = parsed.data.sessionId ?? generateUUIDv7();
|
|
206
|
-
const turnId = parsed.data.turnId ?? generateUUIDv7();
|
|
207
|
-
if (this.closingSessions.has(sessionId)) {
|
|
208
|
-
return transport.send(
|
|
209
|
-
encodeErrorResponse(
|
|
210
|
-
id,
|
|
211
|
-
WIRE_ERROR_CODES.sessionClosing,
|
|
212
|
-
`session ${sessionId} is closing`,
|
|
213
|
-
),
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
const existing = this.sessions.get(sessionId);
|
|
217
|
-
if (existing && existing.harness !== config.harness) {
|
|
218
|
-
return transport.send(
|
|
219
|
-
encodeErrorResponse(
|
|
220
|
-
id,
|
|
221
|
-
WIRE_ERROR_CODES.invalidParams,
|
|
222
|
-
`session ${sessionId} is bound to harness ${existing.harness}`,
|
|
223
|
-
),
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
// Idempotent admission, delegated to the runtime: a retried start
|
|
227
|
-
// (same turnId, identical input) converges — ack again, never run
|
|
228
|
-
// twice; `events/replay` serves anything the retryer missed. The
|
|
229
|
-
// same turnId with different input is a caller bug → turnConflict.
|
|
230
|
-
const request = { sessionId, turnId, input, config };
|
|
231
|
-
try {
|
|
232
|
-
if (this.runtime.admission(request).status !== "new") {
|
|
233
|
-
return transport.send(encodeResponse(id, { sessionId, turnId, deduplicated: true }));
|
|
234
|
-
}
|
|
235
|
-
} catch (err) {
|
|
236
|
-
if (err instanceof TurnConflictError) {
|
|
237
|
-
return transport.send(
|
|
238
|
-
encodeErrorResponse(id, WIRE_ERROR_CODES.turnConflict, err.message, { turnId }),
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
throw err;
|
|
242
|
-
}
|
|
243
|
-
if (this.activeTurns.has(sessionId)) {
|
|
244
|
-
return transport.send(
|
|
245
|
-
encodeErrorResponse(
|
|
246
|
-
id,
|
|
247
|
-
WIRE_ERROR_CODES.turnActive,
|
|
248
|
-
`session ${sessionId} already has an active turn`,
|
|
249
|
-
{ turnId: this.activeTurns.get(sessionId)?.turnId },
|
|
250
|
-
),
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
const log =
|
|
254
|
-
existing ??
|
|
255
|
-
new SessionLog(
|
|
256
|
-
sessionId,
|
|
257
|
-
config.harness,
|
|
258
|
-
this.options.bufferSize ?? DEFAULT_BUFFER_SIZE,
|
|
259
|
-
(this.retiredSeqs.get(sessionId) ?? 0) + 1,
|
|
260
|
-
);
|
|
261
|
-
this.retiredSeqs.delete(sessionId);
|
|
262
|
-
this.sessions.set(sessionId, log);
|
|
263
|
-
this.activeTurns.set(sessionId, { turnId, harness: config.harness });
|
|
264
|
-
// Quick-ack before the first event can possibly be emitted.
|
|
265
|
-
transport.send(encodeResponse(id, { sessionId, turnId }));
|
|
266
|
-
void this.executeTurn({ sessionId, turnId, input, config }, log);
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
case WIRE_METHODS.turnCancel: {
|
|
271
|
-
const parsed = TurnCancelParamsSchema.safeParse(params);
|
|
272
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
273
|
-
const active = this.activeTurns.get(parsed.data.sessionId);
|
|
274
|
-
if (!active) {
|
|
275
|
-
return transport.send(
|
|
276
|
-
encodeResponse(id, { outcome: "no_active_turn" } satisfies TurnCancelResult),
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
if (parsed.data.turnId && parsed.data.turnId !== active.turnId) {
|
|
280
|
-
// Turn-stamped cancel for a turn that is no longer the active one —
|
|
281
|
-
// refuse to kill its successor; report who IS active instead.
|
|
282
|
-
return transport.send(
|
|
283
|
-
encodeResponse(id, {
|
|
284
|
-
outcome: "no_active_turn",
|
|
285
|
-
activeTurnId: active.turnId,
|
|
286
|
-
} satisfies TurnCancelResult),
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
const { confirmed, hadTurn } = await this.runtime.cancel(
|
|
290
|
-
active.harness,
|
|
291
|
-
parsed.data.sessionId,
|
|
292
|
-
);
|
|
293
|
-
// An unacknowledged interrupt is NOT a cancel: the agent may still be
|
|
294
|
-
// running and `turn.ended` stays the source of truth. `hadTurn: false`
|
|
295
|
-
// while the server tracks an active turn is the pre-first-yield window
|
|
296
|
-
// (between the turn/start quick-ack and the harness registering its
|
|
297
|
-
// abortable turn) — the abort landed on nothing and the turn may run
|
|
298
|
-
// to completion, so it must report `unconfirmed`, never a clean cancel.
|
|
299
|
-
return transport.send(
|
|
300
|
-
encodeResponse(id, {
|
|
301
|
-
outcome: confirmed && hadTurn ? "cancelled" : "unconfirmed",
|
|
302
|
-
turnId: active.turnId,
|
|
303
|
-
} satisfies TurnCancelResult),
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
case WIRE_METHODS.sessionClose: {
|
|
308
|
-
const parsed = SessionCloseParamsSchema.safeParse(params);
|
|
309
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
310
|
-
const { sessionId } = parsed.data;
|
|
311
|
-
if (this.closingSessions.has(sessionId)) {
|
|
312
|
-
return transport.send(
|
|
313
|
-
encodeErrorResponse(
|
|
314
|
-
id,
|
|
315
|
-
WIRE_ERROR_CODES.sessionClosing,
|
|
316
|
-
`session ${sessionId} is closing`,
|
|
317
|
-
),
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
const active = this.activeTurns.get(sessionId);
|
|
321
|
-
if (active) {
|
|
322
|
-
return transport.send(
|
|
323
|
-
encodeErrorResponse(
|
|
324
|
-
id,
|
|
325
|
-
WIRE_ERROR_CODES.turnActive,
|
|
326
|
-
`session ${sessionId} has an active turn`,
|
|
327
|
-
{ turnId: active.turnId },
|
|
328
|
-
),
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
const log = this.sessions.get(sessionId);
|
|
332
|
-
if (!log) return transport.send(encodeResponse(id, { closed: false }));
|
|
333
|
-
this.closingSessions.add(sessionId);
|
|
334
|
-
try {
|
|
335
|
-
await this.runtime.closeSession(log.harness, sessionId);
|
|
336
|
-
// The terminal fact for CONNECTED subscribers (spec §6.1): they
|
|
337
|
-
// learn the session is over from the stream, not from the RPC
|
|
338
|
-
// result (which only the closer sees). It is deliberately NOT
|
|
339
|
-
// replayable — the log is retired on the next line, so a
|
|
340
|
-
// subscriber that was detached gets `unknownSession` from
|
|
341
|
-
// `events/replay`, and that answer IS its terminal signal (the
|
|
342
|
-
// session is gone; nothing more will ever be appended).
|
|
343
|
-
this.broadcast(
|
|
344
|
-
log.append({
|
|
345
|
-
type: "session.ended",
|
|
346
|
-
sessionId,
|
|
347
|
-
reason: "released",
|
|
348
|
-
timestamp: Date.now(),
|
|
349
|
-
}),
|
|
350
|
-
);
|
|
351
|
-
if (log.latestSeq !== null) this.retiredSeqs.set(sessionId, log.latestSeq);
|
|
352
|
-
if (this.sessions.get(sessionId) === log) this.sessions.delete(sessionId);
|
|
353
|
-
return transport.send(encodeResponse(id, { closed: true }));
|
|
354
|
-
} finally {
|
|
355
|
-
this.closingSessions.delete(sessionId);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
case WIRE_METHODS.permissionRespond: {
|
|
360
|
-
const parsed = PermissionRespondParamsSchema.safeParse(params);
|
|
361
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
362
|
-
const accepted = this.runtime.respondPermission(
|
|
363
|
-
parsed.data.sessionId,
|
|
364
|
-
parsed.data.requestId,
|
|
365
|
-
parsed.data.outcome,
|
|
366
|
-
);
|
|
367
|
-
return transport.send(encodeResponse(id, { accepted }));
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
case WIRE_METHODS.eventsReplay: {
|
|
371
|
-
const parsed = EventsReplayParamsSchema.safeParse(params);
|
|
372
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
373
|
-
const log = this.sessions.get(parsed.data.sessionId);
|
|
374
|
-
if (!log) {
|
|
375
|
-
return transport.send(
|
|
376
|
-
encodeErrorResponse(
|
|
377
|
-
id,
|
|
378
|
-
WIRE_ERROR_CODES.unknownSession,
|
|
379
|
-
`unknown session: ${parsed.data.sessionId}`,
|
|
380
|
-
),
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
return transport.send(
|
|
384
|
-
encodeResponse(id, {
|
|
385
|
-
events: log.replay(parsed.data.fromSeq),
|
|
386
|
-
firstAvailableSeq: log.firstAvailableSeq,
|
|
387
|
-
latestSeq: log.latestSeq,
|
|
388
|
-
}),
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
case WIRE_METHODS.modelsList: {
|
|
393
|
-
const parsed = ModelsListParamsSchema.safeParse(params);
|
|
394
|
-
if (!parsed.success) return this.invalidParams(transport, id, parsed.error);
|
|
395
|
-
if (!this.runtime.harnesses.includes(parsed.data.harness)) {
|
|
396
|
-
return transport.send(
|
|
397
|
-
encodeErrorResponse(
|
|
398
|
-
id,
|
|
399
|
-
WIRE_ERROR_CODES.harnessNotAvailable,
|
|
400
|
-
`harness not available: ${parsed.data.harness}`,
|
|
401
|
-
{ available: this.runtime.harnesses },
|
|
402
|
-
),
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
return transport.send(encodeResponse(id, await this.runtime.models(parsed.data)));
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
case WIRE_METHODS.shutdown: {
|
|
409
|
-
transport.send(encodeResponse(id, {}));
|
|
410
|
-
// The success ack is already committed on the wire; a throw out of
|
|
411
|
-
// shutdown() must not reach handleLine's catch and emit a second
|
|
412
|
-
// response for this id (a JSON-RPC 2.0 violation).
|
|
413
|
-
await this.shutdown().catch(() => {});
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
default:
|
|
418
|
-
return transport.send(
|
|
419
|
-
encodeErrorResponse(id, WIRE_ERROR_CODES.methodNotFound, `unknown method: ${method}`),
|
|
420
|
-
);
|
|
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();
|
|
421
308
|
}
|
|
422
309
|
}
|
|
423
310
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
//
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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];
|
|
314
|
+
// Unknown here, or durable-only on a volatile server.
|
|
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);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private async executeTurn(request: RunRequest): Promise<void> {
|
|
321
|
+
const { sessionId, turnId } = request;
|
|
322
|
+
/** The runtime emitted the turn's `turn.started`. */
|
|
323
|
+
let started = false;
|
|
433
324
|
const sink = callbackSink((event) => {
|
|
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;
|
|
434
329
|
// Once turn.ended is on the wire the session is idle — clear the busy
|
|
435
330
|
// mark here (not when run() settles) so clients acting on the event
|
|
436
331
|
// never race the bookkeeping.
|
|
437
|
-
if (event.type === "turn.ended")
|
|
438
|
-
this.broadcast(
|
|
332
|
+
if (event.type === "turn.ended") this.gate.settle(sessionId, turnId);
|
|
333
|
+
this.broadcast(envelope);
|
|
439
334
|
});
|
|
440
335
|
try {
|
|
441
336
|
await this.runtime.run(request, sink);
|
|
442
337
|
} catch (err) {
|
|
338
|
+
// The store could not commit: deliver nothing it did not record, not
|
|
339
|
+
// even a turn.ended. Its fault already stops the server.
|
|
340
|
+
if (err instanceof EventSinkError) return;
|
|
341
|
+
// @ref LLP 0002#ordering-and-delivery — no turn.ended without its turn.started
|
|
443
342
|
// runtime.run reports errors via events; a throw means it died before
|
|
444
|
-
// emitting turn.ended — synthesize one so clients are never left
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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
|
+
});
|
|
357
|
+
try {
|
|
358
|
+
for (const event of synthesized) this.broadcast(this.store.append(sessionId, event));
|
|
359
|
+
} catch {
|
|
360
|
+
// A store that cannot commit it has failed, and stops the server.
|
|
361
|
+
}
|
|
456
362
|
} finally {
|
|
457
|
-
|
|
363
|
+
this.gate.settle(sessionId, turnId);
|
|
458
364
|
}
|
|
459
365
|
}
|
|
460
366
|
|
|
461
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);
|
|
462
371
|
// In-process observers first: they see the same envelope, in the same
|
|
463
|
-
// order, whether or not any transport is attached.
|
|
372
|
+
// order, whether or not any transport is attached or subscribed.
|
|
464
373
|
for (const observer of [...this.observers]) {
|
|
465
374
|
try {
|
|
466
375
|
observer(envelope);
|
|
@@ -468,28 +377,28 @@ export class AgentServer {
|
|
|
468
377
|
// An observer's failure is its own; the event is already logged.
|
|
469
378
|
}
|
|
470
379
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
} catch {
|
|
476
|
-
// One faulty transport must not starve the others; the event is
|
|
477
|
-
// already in the session log, so the client heals via replay. The
|
|
478
|
-
// one exception is `session.ended` from `session/close`, whose log
|
|
479
|
-
// is retired in the same breath — a client that missed it learns the
|
|
480
|
-
// session is over from `unknownSession` on replay instead.
|
|
481
|
-
}
|
|
482
|
-
}
|
|
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);
|
|
483
384
|
}
|
|
385
|
+
}
|
|
484
386
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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);
|
|
494
402
|
}
|
|
403
|
+
return { stopped, notStopped, recorded: runtime.recordedHarnesses() };
|
|
495
404
|
}
|