@zvada/agent-server 0.3.18 → 0.3.20
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 +1041 -1
- package/README.md +40 -40
- 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 +45 -28
- 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 +155 -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
package/src/server/install.ts
CHANGED
|
@@ -1,23 +1,48 @@
|
|
|
1
|
+
import { chmod, readdir, realpath, rm } from "node:fs/promises";
|
|
2
|
+
import { join, relative, sep } from "node:path";
|
|
1
3
|
import {
|
|
2
4
|
CLI_TOOLS,
|
|
3
5
|
CliProvisioner,
|
|
4
6
|
type CliTool,
|
|
7
|
+
type PlatformInfo,
|
|
5
8
|
type ProvisionOptions,
|
|
6
9
|
type ResolvedCli,
|
|
7
10
|
toolForHarness,
|
|
8
11
|
} from "../core/index.ts";
|
|
12
|
+
import { openToAll } from "../core/provision/install-build.ts";
|
|
13
|
+
import { detectPlatform, parsePlatform, platformName } from "../core/provision/platform.ts";
|
|
14
|
+
import { CLI_TOOL_SPECS } from "../core/provision/tools.ts";
|
|
9
15
|
import type { AgentHarness } from "../protocol/index.ts";
|
|
10
16
|
|
|
11
17
|
export interface InstallOptions {
|
|
12
18
|
/** Restrict to the CLIs these harnesses need. Defaults to every tool. */
|
|
13
19
|
harnesses?: AgentHarness[];
|
|
20
|
+
/**
|
|
21
|
+
* The platforms to install for, as the cache names them (`darwin-arm64`,
|
|
22
|
+
* `linux-x64-musl`, …): an app bundle or an image for other machines.
|
|
23
|
+
* Defaults to this machine's.
|
|
24
|
+
*/
|
|
25
|
+
platforms?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Install into this folder, in the cache's layout and readable by every
|
|
28
|
+
* user, for `provision.bundleDirs` / `$AGENT_SERVER_BUNDLE_DIR`, instead of
|
|
29
|
+
* the managed cache.
|
|
30
|
+
*/
|
|
31
|
+
dir?: string;
|
|
32
|
+
/** Then remove the cached builds no process used for 14 days. */
|
|
33
|
+
prune?: boolean;
|
|
14
34
|
provision?: ProvisionOptions;
|
|
15
35
|
/** Injectable provisioner boundary for tests. */
|
|
16
|
-
createProvisioner?: (
|
|
36
|
+
createProvisioner?: (
|
|
37
|
+
options: ProvisionOptions,
|
|
38
|
+
platform: PlatformInfo,
|
|
39
|
+
) => Pick<CliProvisioner, "install" | "prune">;
|
|
17
40
|
}
|
|
18
41
|
|
|
19
42
|
export interface InstallResult {
|
|
20
43
|
tool: CliTool;
|
|
44
|
+
/** The platform it was installed for. */
|
|
45
|
+
platform: string;
|
|
21
46
|
cli: ResolvedCli;
|
|
22
47
|
}
|
|
23
48
|
|
|
@@ -31,21 +56,95 @@ export function toolsFor(harnesses: AgentHarness[] | undefined): CliTool[] {
|
|
|
31
56
|
return CLI_TOOLS.filter((tool) => needed.has(tool));
|
|
32
57
|
}
|
|
33
58
|
|
|
59
|
+
/** The platforms named, each one some CLI is published for, or what is wrong. */
|
|
60
|
+
export function platformsFor(names: readonly string[]): PlatformInfo[] {
|
|
61
|
+
const known = [...new Set(CLI_TOOLS.flatMap((tool) => CLI_TOOL_SPECS[tool].platforms))];
|
|
62
|
+
if (!names.length) throw new Error(`no platform named: use one or more of ${known.join(", ")}`);
|
|
63
|
+
return names.map((name) => {
|
|
64
|
+
if (!known.includes(name))
|
|
65
|
+
throw new Error(`unknown platform ${name}: use one of ${known.join(", ")}`);
|
|
66
|
+
return parsePlatform(name);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** What a folder `install --dir` writes holds: the tools' builds and the install's records. */
|
|
71
|
+
const STAGED = new Set<string>([...CLI_TOOLS, ".tmp", ".used"]);
|
|
72
|
+
|
|
73
|
+
/** A `--dir` must be new, empty, or one `install --dir` wrote: staging opens what it writes to every user. */
|
|
74
|
+
async function stageable(dir: string): Promise<void> {
|
|
75
|
+
const entries = await readdir(dir).catch(() => [] as string[]);
|
|
76
|
+
const foreign = entries.find((entry) => !STAGED.has(entry));
|
|
77
|
+
if (foreign)
|
|
78
|
+
throw new Error(
|
|
79
|
+
`${dir} holds ${foreign}, which install --dir did not write: stage into an empty folder`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** `<tool>/<entry>` of the build whose binary is `path`, which must be one in `dir`. */
|
|
84
|
+
function stagedBuild(dir: string, path: string): string {
|
|
85
|
+
const [tool, entry] = relative(dir, path).split(sep);
|
|
86
|
+
if (!tool || !entry || !(CLI_TOOLS as readonly string[]).includes(tool))
|
|
87
|
+
throw new Error(`${path} is not a build in ${dir}`);
|
|
88
|
+
return join(tool, entry);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The builds just staged, readable and runnable by every user, and the
|
|
93
|
+
* folder without the install's records: an owner-only tree baked into an
|
|
94
|
+
* image and run as another user fails with `Permission denied`.
|
|
95
|
+
*/
|
|
96
|
+
async function publish(dir: string, staged: readonly string[]): Promise<void> {
|
|
97
|
+
for (const record of [".tmp", ".used"])
|
|
98
|
+
await rm(join(dir, record), { recursive: true, force: true });
|
|
99
|
+
await chmod(dir, 0o755);
|
|
100
|
+
for (const tool of new Set(staged.map((build) => build.split(sep)[0] as string)))
|
|
101
|
+
await chmod(join(dir, tool), 0o755);
|
|
102
|
+
// A build staged before by an older agent-server may not be open yet.
|
|
103
|
+
for (const build of new Set(staged)) await openToAll(join(dir, build));
|
|
104
|
+
}
|
|
105
|
+
|
|
34
106
|
/**
|
|
35
107
|
* Prefetch the pinned CLI builds into the managed cache — the cold-start
|
|
36
108
|
* eraser: run it while building a container/sandbox image and runtime turns
|
|
37
|
-
* never download.
|
|
38
|
-
*
|
|
109
|
+
* never download. Or stage them for other platforms into a folder an app or
|
|
110
|
+
* an image ships (`dir`). Downloads run in parallel; failures reject with the
|
|
111
|
+
* first error after all settle (so one flaky download doesn't hide the others).
|
|
39
112
|
*/
|
|
40
113
|
export async function runInstall(options: InstallOptions = {}): Promise<InstallResult[]> {
|
|
41
|
-
const provision =
|
|
42
|
-
|
|
114
|
+
const provision: ProvisionOptions = {
|
|
115
|
+
...options.provision,
|
|
116
|
+
...(options.dir && { mode: "pinned", cacheDir: options.dir }),
|
|
117
|
+
};
|
|
118
|
+
const platforms = options.platforms ? platformsFor(options.platforms) : [detectPlatform()];
|
|
119
|
+
if (options.dir) await stageable(options.dir);
|
|
120
|
+
const create =
|
|
121
|
+
options.createProvisioner ??
|
|
122
|
+
((provisionOptions: ProvisionOptions, platform: PlatformInfo) =>
|
|
123
|
+
new CliProvisioner(provisionOptions, { platform }));
|
|
43
124
|
const tools = toolsFor(options.harnesses);
|
|
44
|
-
const
|
|
125
|
+
const provisioners = platforms.map((platform) => ({
|
|
126
|
+
platform: platformName(platform),
|
|
127
|
+
provisioner: create(provision, platform),
|
|
128
|
+
}));
|
|
129
|
+
const jobs = provisioners.flatMap(({ platform, provisioner }) =>
|
|
130
|
+
tools.map((tool) => ({ tool, platform, provisioner })),
|
|
131
|
+
);
|
|
132
|
+
const settled = await Promise.allSettled(jobs.map((job) => job.provisioner.install(job.tool)));
|
|
45
133
|
const failure = settled.find((result) => result.status === "rejected");
|
|
46
134
|
if (failure) throw failure.reason;
|
|
47
|
-
|
|
48
|
-
tool:
|
|
135
|
+
const results = settled.map((result, i) => ({
|
|
136
|
+
tool: (jobs[i] as (typeof jobs)[number]).tool,
|
|
137
|
+
platform: (jobs[i] as (typeof jobs)[number]).platform,
|
|
49
138
|
cli: (result as PromiseFulfilledResult<ResolvedCli>).value,
|
|
50
139
|
}));
|
|
140
|
+
if (options.prune) for (const { provisioner } of provisioners) await provisioner.prune();
|
|
141
|
+
if (options.dir) {
|
|
142
|
+
// The install names its binaries by the folder's real path (macOS's /tmp is /private/tmp).
|
|
143
|
+
const dir = await realpath(options.dir);
|
|
144
|
+
await publish(
|
|
145
|
+
dir,
|
|
146
|
+
results.map(({ cli }) => stagedBuild(dir, cli.path)),
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return results;
|
|
51
150
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type MessagePartDeltaEvent,
|
|
3
|
+
type MessagePartEvent,
|
|
4
|
+
type Part,
|
|
5
|
+
type WireEventEnvelope,
|
|
6
|
+
extendPart,
|
|
7
|
+
isLiveOnlyEvent,
|
|
8
|
+
} from "../protocol/index.ts";
|
|
9
|
+
|
|
10
|
+
/** A part with content beyond its last kept snapshot: text or reasoning streaming, a tool pending. */
|
|
11
|
+
function isOpen(part: Part): boolean {
|
|
12
|
+
if (part.type === "text" || part.type === "reasoning") return part.state === "streaming";
|
|
13
|
+
return part.type === "tool" && part.state.status === "pending";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// @ref LLP 0008#open-parts-in-memory — what a subscription's open-part frames carry
|
|
17
|
+
/**
|
|
18
|
+
* What the server keeps in memory of each session as it streams, from the
|
|
19
|
+
* frames it delivers: a kept event as its store kept it (what replay and
|
|
20
|
+
* history return, a journal's possibly cut down), and every delta. It holds
|
|
21
|
+
* the session's open parts, each a streaming part's last kept snapshot with
|
|
22
|
+
* every delta since applied (what a client that subscribes mid-part receives
|
|
23
|
+
* at once, instead of the deltas it missed), and where its latest turn
|
|
24
|
+
* started. Updated in the same synchronous call that delivers the frame, so a
|
|
25
|
+
* subscription lands either before a delta (and receives it live) or after it
|
|
26
|
+
* (and finds it here), never both. Whatever the store, volatile or a journal.
|
|
27
|
+
*/
|
|
28
|
+
export class OpenParts {
|
|
29
|
+
private readonly sessions = new Map<string, Map<string, MessagePartEvent>>();
|
|
30
|
+
/** The turn each session ran last, by the seq of its `turn.started`. */
|
|
31
|
+
private readonly started = new Map<string, { turnId: string; seq: number }>();
|
|
32
|
+
|
|
33
|
+
/** A frame the server delivers. */
|
|
34
|
+
delivered(envelope: WireEventEnvelope): void {
|
|
35
|
+
const { sessionId, seq, event } = envelope;
|
|
36
|
+
if (isLiveOnlyEvent(event)) {
|
|
37
|
+
this.extend(event);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const open = this.sessions.get(sessionId);
|
|
41
|
+
switch (event.type) {
|
|
42
|
+
case "message.part": {
|
|
43
|
+
const { part } = event;
|
|
44
|
+
if (isOpen(part)) {
|
|
45
|
+
const parts = open ?? new Map<string, MessagePartEvent>();
|
|
46
|
+
parts.set(part.id, event);
|
|
47
|
+
this.sessions.set(sessionId, parts);
|
|
48
|
+
} else this.close(sessionId, part.id);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
case "turn.started":
|
|
52
|
+
this.started.set(sessionId, { turnId: event.turnId, seq });
|
|
53
|
+
return;
|
|
54
|
+
case "turn.ended":
|
|
55
|
+
for (const [partId, entry] of open ?? [])
|
|
56
|
+
if (entry.turnId === event.turnId) this.close(sessionId, partId);
|
|
57
|
+
return;
|
|
58
|
+
case "session.ended":
|
|
59
|
+
this.sessions.delete(sessionId);
|
|
60
|
+
this.started.delete(sessionId);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The session's open parts, in the order they opened, as live frames at `headSeq`. */
|
|
66
|
+
of(sessionId: string, headSeq: number): WireEventEnvelope[] {
|
|
67
|
+
return [...(this.sessions.get(sessionId)?.values() ?? [])].map((event) => ({
|
|
68
|
+
sessionId,
|
|
69
|
+
seq: headSeq,
|
|
70
|
+
live: true,
|
|
71
|
+
event,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The seq of the turn's `turn.started`, while it is the session's latest turn. */
|
|
76
|
+
startedSeq(sessionId: string, turnId: string): number | undefined {
|
|
77
|
+
const started = this.started.get(sessionId);
|
|
78
|
+
return started?.turnId === turnId ? started.seq : undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A delta: its part gains what it streamed, dated by it. */
|
|
82
|
+
private extend(event: MessagePartDeltaEvent): void {
|
|
83
|
+
const parts = this.sessions.get(event.sessionId);
|
|
84
|
+
const entry = parts?.get(event.partId);
|
|
85
|
+
const part = entry && extendPart(entry.part, event.delta);
|
|
86
|
+
if (parts && entry && part)
|
|
87
|
+
parts.set(event.partId, { ...entry, part, timestamp: event.timestamp });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private close(sessionId: string, partId: string): void {
|
|
91
|
+
const parts = this.sessions.get(sessionId);
|
|
92
|
+
if (!parts?.delete(partId)) return;
|
|
93
|
+
if (parts.size === 0) this.sessions.delete(sessionId);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import type { AgentRuntime, RunSummary } from "../core/index.ts";
|
|
2
|
+
import {
|
|
3
|
+
type AgentCapabilities,
|
|
4
|
+
type AgentHarness,
|
|
5
|
+
type HistoryMethod,
|
|
6
|
+
type InitializeResult,
|
|
7
|
+
type RunRequest,
|
|
8
|
+
type SessionSubscribeResult,
|
|
9
|
+
type TurnEndedEvent,
|
|
10
|
+
WIRE_METHODS,
|
|
11
|
+
WIRE_PROTOCOL_VERSION,
|
|
12
|
+
type WireEventEnvelope,
|
|
13
|
+
type WireParsedParams,
|
|
14
|
+
WireRefusal,
|
|
15
|
+
type WireRequestMethod,
|
|
16
|
+
type WireResult,
|
|
17
|
+
type WireTransport,
|
|
18
|
+
generateUUIDv7,
|
|
19
|
+
} from "../protocol/index.ts";
|
|
20
|
+
import type { OpenParts } from "./open-parts.ts";
|
|
21
|
+
import type { SessionGate } from "./session-gate.ts";
|
|
22
|
+
import type { JournalSessionStore, SessionLogStore } from "./session-store.ts";
|
|
23
|
+
import type { SubscriptionScope, Subscriptions } from "./subscriptions.ts";
|
|
24
|
+
|
|
25
|
+
/** What a request's handler may ask of the connection it came on. */
|
|
26
|
+
export interface RouteContext {
|
|
27
|
+
transport: WireTransport;
|
|
28
|
+
/** Run `then` once the response is sent, or failed to send: work that must not precede it. */
|
|
29
|
+
afterResponse(then: () => void): void;
|
|
30
|
+
}
|
|
31
|
+
type Answer<M extends WireRequestMethod> = WireResult<M> | Promise<WireResult<M>>;
|
|
32
|
+
/**
|
|
33
|
+
* A request's handler, given its params as `WIRE_API` parses them: what it
|
|
34
|
+
* returns is the response; what it throws, the error response.
|
|
35
|
+
*/
|
|
36
|
+
export type Route<M extends WireRequestMethod> = (
|
|
37
|
+
params: WireParsedParams<M>,
|
|
38
|
+
context: RouteContext,
|
|
39
|
+
) => Answer<M>;
|
|
40
|
+
/** A handler that reads its own params: one that must refuse a caller before it reads what it sent. */
|
|
41
|
+
export interface UnparsedRoute<M extends WireRequestMethod> {
|
|
42
|
+
readonly unparsed: (params: unknown, context: RouteContext) => Answer<M>;
|
|
43
|
+
}
|
|
44
|
+
/** One handler per method: a method without one does not compile. */
|
|
45
|
+
export type Routes<Methods extends WireRequestMethod> = {
|
|
46
|
+
readonly [M in Methods]: Route<M> | UnparsedRoute<M>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** The methods only a server with a journal answers. */
|
|
50
|
+
type DurableMethod =
|
|
51
|
+
| typeof WIRE_METHODS.turnGet
|
|
52
|
+
| typeof WIRE_METHODS.sessionGet
|
|
53
|
+
| typeof WIRE_METHODS.sessionConfirmStopped
|
|
54
|
+
| typeof WIRE_METHODS.sessionRelease;
|
|
55
|
+
/** What every server answers (a server serving history answers `history/*` too). */
|
|
56
|
+
type ExecutionMethod = Exclude<WireRequestMethod, DurableMethod | HistoryMethod>;
|
|
57
|
+
|
|
58
|
+
/** What the routes run on: the server's runtime, session logs and turns. */
|
|
59
|
+
export interface RouteHost {
|
|
60
|
+
readonly runtime: AgentRuntime;
|
|
61
|
+
readonly store: SessionLogStore;
|
|
62
|
+
/** Each session's open parts and latest turn start, as the server delivered them. */
|
|
63
|
+
readonly openParts: OpenParts;
|
|
64
|
+
readonly gate: SessionGate;
|
|
65
|
+
/** Which connections receive which sessions. */
|
|
66
|
+
readonly subscriptions: Subscriptions;
|
|
67
|
+
/** The `initialize` result's fixed fields. */
|
|
68
|
+
readonly identity: Pick<InitializeResult, "server" | "instanceId" | "historyId">;
|
|
69
|
+
/** False once the server stopped taking turns. */
|
|
70
|
+
accepting(): boolean;
|
|
71
|
+
/** Run an admitted turn: its events go to its log and every transport. */
|
|
72
|
+
executeTurn(request: RunRequest): void;
|
|
73
|
+
broadcast(envelope: WireEventEnvelope): void;
|
|
74
|
+
/** Cancel every turn, and wait until each one's `turn.ended` was broadcast. */
|
|
75
|
+
drainTurns(): Promise<void>;
|
|
76
|
+
shutdown(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function assertHarness(runtime: AgentRuntime, harness: AgentHarness): void {
|
|
80
|
+
if (!runtime.harnesses.includes(harness))
|
|
81
|
+
throw new WireRefusal("harnessNotAvailable", `harness not available: ${harness}`, {
|
|
82
|
+
available: runtime.harnesses,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A settled turn's end, from the summary the runtime converges a retry on. */
|
|
87
|
+
function endedOf(summary: RunSummary): TurnEndedEvent {
|
|
88
|
+
return {
|
|
89
|
+
type: "turn.ended",
|
|
90
|
+
sessionId: summary.sessionId,
|
|
91
|
+
turnId: summary.turnId,
|
|
92
|
+
stopReason: summary.stopReason,
|
|
93
|
+
finishReason: summary.finishReason,
|
|
94
|
+
tokens: summary.usage,
|
|
95
|
+
cost: summary.cost,
|
|
96
|
+
execution: summary.execution,
|
|
97
|
+
error: summary.error,
|
|
98
|
+
...(summary.undeliveredSteers?.length && { undeliveredSteers: summary.undeliveredSteers }),
|
|
99
|
+
timestamp: Date.now(),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The routes every server has, one per method: a method without one does not compile. */
|
|
104
|
+
export function executionRoutes(host: RouteHost): Routes<ExecutionMethod> {
|
|
105
|
+
const { runtime, store, openParts, gate, subscriptions } = host;
|
|
106
|
+
/** A retried start the runtime converges on: a volatile store holds no receipts, only its log. */
|
|
107
|
+
const converged = (request: RunRequest): { terminal?: TurnEndedEvent } | undefined => {
|
|
108
|
+
const admission = runtime.admission(request);
|
|
109
|
+
if (admission.status === "new") return undefined;
|
|
110
|
+
// Its `turn.ended` may be out before the runtime settles it.
|
|
111
|
+
const terminal =
|
|
112
|
+
store.terminal(request.sessionId, request.turnId) ??
|
|
113
|
+
(admission.status === "completed" ? endedOf(admission.summary) : undefined);
|
|
114
|
+
return terminal ? { terminal } : {};
|
|
115
|
+
};
|
|
116
|
+
/** Where a subscription to the session starts now, with the turn it runs. */
|
|
117
|
+
const pointOf = (sessionId: string): SessionSubscribeResult | undefined => {
|
|
118
|
+
const point = store.point(sessionId);
|
|
119
|
+
if (!point) return undefined;
|
|
120
|
+
const active = gate.activeTurn(sessionId);
|
|
121
|
+
const startedSeq = active && openParts.startedSeq(sessionId, active.turnId);
|
|
122
|
+
return {
|
|
123
|
+
...point,
|
|
124
|
+
...(active && {
|
|
125
|
+
activeTurn: { turnId: active.turnId, ...(startedSeq !== undefined && { startedSeq }) },
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
// @ref LLP 0008#ordering-joining-without-a-gap-or-a-duplicate — read, register, answer, send: one synchronous block
|
|
130
|
+
/**
|
|
131
|
+
* Subscribe the connection at `headSeq`, the point its answer marks; the
|
|
132
|
+
* session's open parts follow the answer. All of it before any other frame
|
|
133
|
+
* can be sent, so each of the session's frames reaches the connection once:
|
|
134
|
+
* kept events up to the point by replay, after it pushed, deltas before it
|
|
135
|
+
* folded into an open part, after it pushed.
|
|
136
|
+
*/
|
|
137
|
+
const subscribeAt = (
|
|
138
|
+
context: RouteContext,
|
|
139
|
+
sessionId: string,
|
|
140
|
+
headSeq: number,
|
|
141
|
+
scope: SubscriptionScope,
|
|
142
|
+
) => {
|
|
143
|
+
subscriptions.subscribe(context.transport, sessionId, headSeq, scope);
|
|
144
|
+
const open = openParts.of(sessionId, headSeq);
|
|
145
|
+
if (open.length) context.afterResponse(() => subscriptions.sendTo(context.transport, open));
|
|
146
|
+
};
|
|
147
|
+
const runs = (sessionId: string, turnId: string) => gate.activeTurn(sessionId)?.turnId === turnId;
|
|
148
|
+
return {
|
|
149
|
+
[WIRE_METHODS.initialize]: ({ protocolVersion }) => {
|
|
150
|
+
if (protocolVersion !== WIRE_PROTOCOL_VERSION)
|
|
151
|
+
throw new WireRefusal(
|
|
152
|
+
"protocolVersionMismatch",
|
|
153
|
+
`unsupported protocol version: ${protocolVersion}`,
|
|
154
|
+
{ supported: [WIRE_PROTOCOL_VERSION] },
|
|
155
|
+
);
|
|
156
|
+
const harnesses: Record<string, AgentCapabilities> = {};
|
|
157
|
+
for (const harness of runtime.harnesses) harnesses[harness] = runtime.capabilities(harness);
|
|
158
|
+
return { protocolVersion: WIRE_PROTOCOL_VERSION, ...host.identity, harnesses };
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
[WIRE_METHODS.turnStart]: (parsed, context) => {
|
|
162
|
+
if (!host.accepting()) throw new WireRefusal("shuttingDown", "server is shutting down");
|
|
163
|
+
const { config, input } = parsed;
|
|
164
|
+
assertHarness(runtime, config.harness);
|
|
165
|
+
const sessionId = parsed.sessionId ?? generateUUIDv7();
|
|
166
|
+
const turnId = parsed.turnId ?? generateUUIDv7();
|
|
167
|
+
// Refused in this order: a session closing, then a retry (which
|
|
168
|
+
// converges instead), another harness, a running turn.
|
|
169
|
+
gate.assertOpen(sessionId);
|
|
170
|
+
// The caller wants the turn's stream (unless it says otherwise), until
|
|
171
|
+
// the turn ends. Never refused: the cap bounds what a connection
|
|
172
|
+
// watches, not the turns it runs.
|
|
173
|
+
const subscribe = parsed.subscribe !== false;
|
|
174
|
+
// Idempotent admission: a retried start (same turnId, identical
|
|
175
|
+
// input) converges — ack again, never run twice, and subscribe its
|
|
176
|
+
// caller to the turn while it runs. A durable store remembers every
|
|
177
|
+
// turn it admitted, the runtime only its recent ones. The same turnId
|
|
178
|
+
// with different input is a caller bug → turnConflict.
|
|
179
|
+
const request = { sessionId, turnId, input, config };
|
|
180
|
+
const duplicate = store.duplicateOf(request) ?? converged(request);
|
|
181
|
+
if (duplicate) {
|
|
182
|
+
const headSeq = store.point(sessionId)?.headSeq;
|
|
183
|
+
if (subscribe && headSeq !== undefined && runs(sessionId, turnId))
|
|
184
|
+
subscribeAt(context, sessionId, headSeq, { turnId });
|
|
185
|
+
const startedSeq = duplicate.terminal ? undefined : openParts.startedSeq(sessionId, turnId);
|
|
186
|
+
return {
|
|
187
|
+
sessionId,
|
|
188
|
+
turnId,
|
|
189
|
+
deduplicated: true,
|
|
190
|
+
headSeq: headSeq ?? 0,
|
|
191
|
+
...(startedSeq !== undefined && { startedSeq }),
|
|
192
|
+
...(duplicate.terminal && { terminal: duplicate.terminal }),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const bound = store.harnessOf(sessionId);
|
|
196
|
+
if (bound && bound !== config.harness)
|
|
197
|
+
throw new WireRefusal("invalidParams", `session ${sessionId} is bound to harness ${bound}`);
|
|
198
|
+
gate.assertIdle(sessionId);
|
|
199
|
+
store.open(request);
|
|
200
|
+
gate.begin(sessionId, { turnId, harness: config.harness });
|
|
201
|
+
// The point before the turn's first event: its caller downloads no history.
|
|
202
|
+
const headSeq = store.point(sessionId)?.headSeq ?? 0;
|
|
203
|
+
if (subscribe) subscriptions.subscribe(context.transport, sessionId, headSeq, { turnId });
|
|
204
|
+
// Quick-ack before the first event can possibly be emitted. The turn
|
|
205
|
+
// runs (and releases its session) even if the requester is gone.
|
|
206
|
+
context.afterResponse(() => host.executeTurn(request));
|
|
207
|
+
return { sessionId, turnId, headSeq };
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
[WIRE_METHODS.turnCancel]: async ({ sessionId, turnId }) => {
|
|
211
|
+
const active = gate.activeTurn(sessionId);
|
|
212
|
+
if (!active) return { outcome: "no_active_turn" };
|
|
213
|
+
// Turn-stamped cancel for a turn that is no longer the active one —
|
|
214
|
+
// refuse to kill its successor; report who IS active instead.
|
|
215
|
+
if (turnId && turnId !== active.turnId)
|
|
216
|
+
return { outcome: "no_active_turn", activeTurnId: active.turnId };
|
|
217
|
+
const { confirmed, hadTurn } = await runtime.cancel(active.harness, sessionId);
|
|
218
|
+
// An unacknowledged interrupt is NOT a cancel: the agent may still be
|
|
219
|
+
// running and `turn.ended` stays the source of truth. `hadTurn: false`
|
|
220
|
+
// while the server tracks an active turn is the pre-first-yield window
|
|
221
|
+
// (between the turn/start quick-ack and the harness registering its
|
|
222
|
+
// abortable turn) — the abort landed on nothing and the turn may run
|
|
223
|
+
// to completion, so it must report `unconfirmed`, never a clean cancel.
|
|
224
|
+
return {
|
|
225
|
+
outcome: confirmed && hadTurn ? "cancelled" : "unconfirmed",
|
|
226
|
+
turnId: active.turnId,
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
// @ref LLP 0001#d13--input-while-a-turn-runs-steers-it — the runtime decides
|
|
231
|
+
[WIRE_METHODS.turnSteer]: ({ sessionId, turnId, steerId, input }) =>
|
|
232
|
+
runtime.steer(sessionId, { turnId, steerId: steerId ?? generateUUIDv7(), input }),
|
|
233
|
+
|
|
234
|
+
[WIRE_METHODS.sessionClose]: async ({ sessionId }) => {
|
|
235
|
+
gate.assertIdle(sessionId);
|
|
236
|
+
const harness = store.closing(sessionId);
|
|
237
|
+
if (!harness) return { closed: false };
|
|
238
|
+
return gate.whileClosing(sessionId, "closing", async () => {
|
|
239
|
+
await runtime.closeSession(harness, sessionId);
|
|
240
|
+
// The terminal fact for CONNECTED subscribers: they learn the
|
|
241
|
+
// session is over from the stream, not from the RPC result (which
|
|
242
|
+
// only the closer sees). Appending it retires the session.
|
|
243
|
+
host.broadcast(
|
|
244
|
+
store.append(sessionId, {
|
|
245
|
+
type: "session.ended",
|
|
246
|
+
sessionId,
|
|
247
|
+
reason: "closed",
|
|
248
|
+
timestamp: Date.now(),
|
|
249
|
+
}),
|
|
250
|
+
);
|
|
251
|
+
return { closed: true };
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
[WIRE_METHODS.permissionRespond]: ({ sessionId, requestId, outcome }) => ({
|
|
256
|
+
accepted: runtime.respondPermission(sessionId, requestId, outcome),
|
|
257
|
+
}),
|
|
258
|
+
|
|
259
|
+
[WIRE_METHODS.elicitationRespond]: ({ sessionId, requestId, outcome }) => ({
|
|
260
|
+
accepted: runtime.respondElicitation(sessionId, requestId, outcome),
|
|
261
|
+
}),
|
|
262
|
+
|
|
263
|
+
[WIRE_METHODS.sessionSubscribe]: ({ sessionId, turnId }, context) => {
|
|
264
|
+
const point = pointOf(sessionId);
|
|
265
|
+
if (!point) throw new WireRefusal("unknownSession", `unknown session: ${sessionId}`);
|
|
266
|
+
// A turn that is not running subscribes nothing: its events, its end
|
|
267
|
+
// included, are kept up to the point (the answer's `activeTurn` tells).
|
|
268
|
+
if (turnId === undefined) subscribeAt(context, sessionId, point.headSeq, "watch");
|
|
269
|
+
else if (runs(sessionId, turnId)) subscribeAt(context, sessionId, point.headSeq, { turnId });
|
|
270
|
+
return point;
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
[WIRE_METHODS.sessionUnsubscribe]: ({ sessionId }, { transport }) => ({
|
|
274
|
+
unsubscribed: subscriptions.unsubscribe(transport, sessionId),
|
|
275
|
+
}),
|
|
276
|
+
|
|
277
|
+
[WIRE_METHODS.sessionSubscribeAll]: (_params, context) => {
|
|
278
|
+
subscriptions.subscribeAll(context.transport);
|
|
279
|
+
const sessions = gate.running().flatMap((sessionId) => {
|
|
280
|
+
const point = pointOf(sessionId);
|
|
281
|
+
return point ? [{ sessionId, ...point }] : [];
|
|
282
|
+
});
|
|
283
|
+
const open = sessions.flatMap(({ sessionId, headSeq }) => openParts.of(sessionId, headSeq));
|
|
284
|
+
if (open.length) context.afterResponse(() => subscriptions.sendTo(context.transport, open));
|
|
285
|
+
return { sessions };
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
[WIRE_METHODS.sessionUnsubscribeAll]: (_params, { transport }) => ({
|
|
289
|
+
unsubscribed: subscriptions.unsubscribeAll(transport),
|
|
290
|
+
}),
|
|
291
|
+
|
|
292
|
+
[WIRE_METHODS.eventsReplay]: ({ sessionId, fromSeq }) => {
|
|
293
|
+
const replayed = store.replay(sessionId, fromSeq);
|
|
294
|
+
if (!replayed) throw new WireRefusal("unknownSession", `unknown session: ${sessionId}`);
|
|
295
|
+
return replayed;
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
[WIRE_METHODS.modelsList]: (parsed) => {
|
|
299
|
+
assertHarness(runtime, parsed.harness);
|
|
300
|
+
return runtime.models(parsed);
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
[WIRE_METHODS.clisList]: async ({ harnesses }) => {
|
|
304
|
+
for (const harness of harnesses ?? []) assertHarness(runtime, harness);
|
|
305
|
+
return { clis: await runtime.listClis(harnesses) };
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
// @ref LLP 0001#d9--the-wire-is-quick-ack-json-rpc-requests-flow-one-way — an install outlasts any request's deadline
|
|
309
|
+
[WIRE_METHODS.clisPrepare]: async ({ harnesses }) => {
|
|
310
|
+
for (const harness of harnesses ?? []) assertHarness(runtime, harness);
|
|
311
|
+
// Started, and answered at once: what is not ready yet is `installing`,
|
|
312
|
+
// and `clis/progress` and `clis/list` say how it ends.
|
|
313
|
+
void runtime.prepareClis(harnesses).catch(() => {});
|
|
314
|
+
return { clis: await runtime.listClis(harnesses) };
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
[WIRE_METHODS.authStatus]: async ({ harnesses, env }) => {
|
|
318
|
+
for (const harness of harnesses ?? []) assertHarness(runtime, harness);
|
|
319
|
+
return { auth: await runtime.authStatus(harnesses, env) };
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
// @ref LLP 0011#the-wire — answered once the CLI says where to sign in; `auth/updated` says how it ended
|
|
323
|
+
[WIRE_METHODS.authLogin]: (params) => {
|
|
324
|
+
assertHarness(runtime, params.harness);
|
|
325
|
+
return runtime.login(params);
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
[WIRE_METHODS.authComplete]: ({ loginId, code }) => runtime.completeLogin(loginId, code),
|
|
329
|
+
|
|
330
|
+
[WIRE_METHODS.authCancel]: ({ loginId }) => ({ outcome: runtime.cancelLogin(loginId) }),
|
|
331
|
+
|
|
332
|
+
[WIRE_METHODS.authLogout]: ({ harness, env }) => {
|
|
333
|
+
assertHarness(runtime, harness);
|
|
334
|
+
return runtime.logout(harness, env);
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
[WIRE_METHODS.shutdown]: async (_params, { afterResponse }) => {
|
|
338
|
+
// Answer once the turns drained, so the client that asked hears their
|
|
339
|
+
// turn.ended (cancelled) before the answer, then close. A drain that
|
|
340
|
+
// throws still gets its one answer: shutting down reports nothing more.
|
|
341
|
+
await host.drainTurns().catch(() => {});
|
|
342
|
+
afterResponse(() => void host.shutdown().catch(() => {}));
|
|
343
|
+
return {};
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* The routes only a server with a journal has: a volatile session has no
|
|
350
|
+
* receipt, no fence to lift and no journal to ask its next turn for a
|
|
351
|
+
* conversation it let go (`session/close` frees it), so a volatile server
|
|
352
|
+
* answers these `methodNotFound`.
|
|
353
|
+
*/
|
|
354
|
+
export function durableRoutes(
|
|
355
|
+
store: JournalSessionStore,
|
|
356
|
+
{ runtime, gate }: Pick<RouteHost, "runtime" | "gate">,
|
|
357
|
+
): Routes<DurableMethod> {
|
|
358
|
+
return {
|
|
359
|
+
[WIRE_METHODS.turnGet]: ({ sessionId, turnId }) => {
|
|
360
|
+
const receipt = store.receipt(sessionId, turnId);
|
|
361
|
+
if (receipt) return receipt;
|
|
362
|
+
throw store.session(sessionId)
|
|
363
|
+
? new WireRefusal("unknownTurn", `unknown turn: ${turnId}`)
|
|
364
|
+
: new WireRefusal("unknownSession", `unknown session: ${sessionId}`);
|
|
365
|
+
},
|
|
366
|
+
|
|
367
|
+
[WIRE_METHODS.sessionGet]: ({ sessionId }) => {
|
|
368
|
+
const session = store.session(sessionId);
|
|
369
|
+
if (!session) throw new WireRefusal("unknownSession", `unknown session: ${sessionId}`);
|
|
370
|
+
return session;
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
[WIRE_METHODS.sessionConfirmStopped]: ({ sessionId, expectedHeadSeq }) => ({
|
|
374
|
+
recovered: store.confirmStopped(sessionId, expectedHeadSeq),
|
|
375
|
+
}),
|
|
376
|
+
|
|
377
|
+
// @ref LLP 0003#releasing-without-closing — free the agent, keep the session
|
|
378
|
+
[WIRE_METHODS.sessionRelease]: async ({ sessionId }) => {
|
|
379
|
+
gate.assertIdle(sessionId);
|
|
380
|
+
const harness = store.harnessOf(sessionId);
|
|
381
|
+
if (!harness) return { released: false };
|
|
382
|
+
return gate.whileClosing(sessionId, "releasing", async () => {
|
|
383
|
+
// First, so no turn admitted later runs without naming its
|
|
384
|
+
// conversation: the runtime is about to forget which one it was.
|
|
385
|
+
store.releaseNative(sessionId);
|
|
386
|
+
await runtime.closeSession(harness, sessionId);
|
|
387
|
+
return { released: true };
|
|
388
|
+
});
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** The secrets the server reads from its environment: what a listener, `--dial` and `--credentials-url` present. */
|
|
2
|
+
const SERVER_SECRETS = [
|
|
3
|
+
"AGENT_SERVER_TOKEN",
|
|
4
|
+
"AGENT_SERVER_DIAL_TOKEN",
|
|
5
|
+
"AGENT_SERVER_CREDENTIALS_TOKEN",
|
|
6
|
+
] as const;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Take this server's secrets out of its environment, answering them: every
|
|
10
|
+
* CLI the server starts inherits the environment, and the tools those run
|
|
11
|
+
* with it, so a secret left there is one an agent can read. An empty one
|
|
12
|
+
* stays empty, for its user to refuse.
|
|
13
|
+
*/
|
|
14
|
+
export function takeSecrets(
|
|
15
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
16
|
+
): Record<(typeof SERVER_SECRETS)[number], string | undefined> {
|
|
17
|
+
return Object.fromEntries(
|
|
18
|
+
SERVER_SECRETS.map((name) => {
|
|
19
|
+
const value = env[name]?.trim();
|
|
20
|
+
delete env[name];
|
|
21
|
+
return [name, value];
|
|
22
|
+
}),
|
|
23
|
+
) as Record<(typeof SERVER_SECRETS)[number], string | undefined>;
|
|
24
|
+
}
|