@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,54 +1,81 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
McpSetServersResult,
|
|
3
|
+
SDKResultError,
|
|
4
|
+
SDKUserMessage,
|
|
5
|
+
} from "@anthropic-ai/claude-agent-sdk";
|
|
3
6
|
import type {
|
|
4
7
|
AgentCapabilities,
|
|
5
8
|
AgentInput,
|
|
6
9
|
McpServerConfig,
|
|
7
10
|
ModelDescriptor,
|
|
8
11
|
} from "../../../protocol/index.ts";
|
|
9
|
-
import {
|
|
12
|
+
import { emitDiagnostic } from "../../diagnostics.ts";
|
|
13
|
+
import { type NativeProcesses, sharedNativeProcesses } from "../../processes/native-processes.ts";
|
|
14
|
+
import { onAbort } from "../../utils/deadline.ts";
|
|
10
15
|
import { SessionResumeError } from "../../utils/errors.ts";
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
CancelResult,
|
|
14
|
-
ListModelsOptions,
|
|
15
|
-
RawAgentEvent,
|
|
16
|
-
} from "../base.ts";
|
|
16
|
+
import { UnsupportedAttachmentError, attachedText, isTextMedia } from "../attachments.ts";
|
|
17
|
+
import type { AgentExecuteOptions, CancelResult, ListModelsOptions } from "../base.ts";
|
|
17
18
|
import { SessionAgent } from "../session-agent.ts";
|
|
18
|
-
import type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
ClaudeSessionEndReason,
|
|
22
|
-
ClaudeSessionExtras,
|
|
23
|
-
ClaudeToolPolicy,
|
|
24
|
-
} from "./generator-session.ts";
|
|
19
|
+
import { ClaudeCredentials, type ClaudeDelivery, ON_PLACEHOLDER } from "./credentials.ts";
|
|
20
|
+
import type { ClaudeRawEvent } from "./events.ts";
|
|
21
|
+
import { ClaudeCliLogin } from "./login.ts";
|
|
25
22
|
import { claudeModelDescriptors, fitClaudeThinking, readClaudeModels } from "./models.ts";
|
|
26
|
-
import type
|
|
27
|
-
import {
|
|
23
|
+
import { type ClaudeCodeAgentOptions, claudeSessionConfig } from "./options.ts";
|
|
24
|
+
import { ClaudeSessionPool } from "./session-pool.ts";
|
|
25
|
+
import type { ClaudeSession } from "./session.ts";
|
|
28
26
|
|
|
29
27
|
type ClaudeContent = SDKUserMessage["message"]["content"];
|
|
30
28
|
|
|
31
29
|
const CAPABILITIES: AgentCapabilities = {
|
|
32
30
|
multiTurn: true,
|
|
33
31
|
sessionResume: true,
|
|
34
|
-
modelSwitch: "
|
|
32
|
+
modelSwitch: "in_session",
|
|
35
33
|
thinkingLevels: true,
|
|
36
34
|
images: true,
|
|
35
|
+
// What `toClaudeContent` sends: PDFs as base64 documents, text as text ones.
|
|
36
|
+
files: ["text", "pdf"],
|
|
37
37
|
mcpServers: true,
|
|
38
38
|
permissionRequests: true,
|
|
39
|
+
// A denial tells Claude what the user said (`approvals.ts`).
|
|
40
|
+
rejectionMessages: true,
|
|
39
41
|
turnScopedSubagents: true,
|
|
42
|
+
steering: true,
|
|
40
43
|
};
|
|
41
44
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Our normalized input as Claude message content. The API takes images as data
|
|
47
|
+
* or web URLs and documents as PDF data, plain text or a URL; any other
|
|
48
|
+
* attachment fails the turn instead of reaching Claude unreadable.
|
|
49
|
+
*/
|
|
50
|
+
export function toClaudeContent(input: AgentInput): ClaudeContent {
|
|
44
51
|
if (typeof input === "string") return input;
|
|
45
52
|
const blocks = input.map((part) => {
|
|
46
53
|
if (part.type === "text") return { type: "text", text: part.text };
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
// `file` inputs (PDFs, text) are document blocks, not images.
|
|
55
|
+
const type = part.type === "file" ? "document" : "image";
|
|
56
|
+
if (part.url !== undefined) {
|
|
57
|
+
if (!/^https?:\/\//i.test(part.url)) {
|
|
58
|
+
throw new UnsupportedAttachmentError(
|
|
59
|
+
`Claude takes attachments as data or http(s) URLs, not ${part.url}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return { type, source: { type: "url", url: part.url } };
|
|
63
|
+
}
|
|
64
|
+
const data = part.data ?? "";
|
|
65
|
+
if (part.type === "image") {
|
|
66
|
+
return { type, source: { type: "base64", media_type: part.mimeType, data } };
|
|
67
|
+
}
|
|
68
|
+
const title = part.filename ? { title: part.filename } : {};
|
|
69
|
+
if (part.mimeType === "application/pdf") {
|
|
70
|
+
return { type, source: { type: "base64", media_type: part.mimeType, data }, ...title };
|
|
71
|
+
}
|
|
72
|
+
if (isTextMedia(part.mimeType)) {
|
|
73
|
+
const text = attachedText(data);
|
|
74
|
+
return { type, source: { type: "text", media_type: "text/plain", data: text }, ...title };
|
|
75
|
+
}
|
|
76
|
+
throw new UnsupportedAttachmentError(
|
|
77
|
+
`Claude cannot take ${part.mimeType} file attachments; send text, a PDF or an image`,
|
|
78
|
+
);
|
|
52
79
|
});
|
|
53
80
|
// Kept cast: the SDK's block sources require literal media_type unions
|
|
54
81
|
// ("image/jpeg" | ... and "application/pdf") while our PartInput carries an
|
|
@@ -62,78 +89,14 @@ function toClaudeContent(input: AgentInput): ClaudeContent {
|
|
|
62
89
|
* interrupt produces the same result message — callers must also check that no
|
|
63
90
|
* interrupt was requested.)
|
|
64
91
|
*/
|
|
65
|
-
export function claudeResumeFailed(event:
|
|
66
|
-
const msg = event as { type?: string; subtype?: string; stop_reason?: unknown };
|
|
92
|
+
export function claudeResumeFailed(event: ClaudeRawEvent): event is SDKResultError {
|
|
67
93
|
return (
|
|
68
|
-
|
|
94
|
+
event.type === "result" &&
|
|
95
|
+
event.subtype === "error_during_execution" &&
|
|
96
|
+
event.stop_reason === null
|
|
69
97
|
);
|
|
70
98
|
}
|
|
71
99
|
|
|
72
|
-
function sessionConfigFrom(
|
|
73
|
-
options: AgentExecuteOptions,
|
|
74
|
-
cliPath: string | undefined,
|
|
75
|
-
): ClaudeSessionConfig {
|
|
76
|
-
return {
|
|
77
|
-
cwd: options.cwd,
|
|
78
|
-
additionalDirectories: options.additionalDirectories,
|
|
79
|
-
model: options.model,
|
|
80
|
-
thinkingLevel: options.thinkingLevel,
|
|
81
|
-
permissionMode: options.permissionMode,
|
|
82
|
-
maxTurns: options.maxTurns,
|
|
83
|
-
subagentMode: options.subagentMode,
|
|
84
|
-
systemPromptAppend: options.systemPromptAppend,
|
|
85
|
-
resumeSessionId: options.resumeSessionId,
|
|
86
|
-
resumeSessionAt: options.resumeSessionAt,
|
|
87
|
-
mcpServers: options.mcpServers,
|
|
88
|
-
env: options.env,
|
|
89
|
-
apiKey: options.apiKey,
|
|
90
|
-
disableTools: options.disableTools === true,
|
|
91
|
-
cliPath,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export interface ClaudeCodeAgentOptions {
|
|
96
|
-
/**
|
|
97
|
-
* Resolve the `claude` binary to spawn (typically the provisioner's,
|
|
98
|
-
* memoized). `undefined` defers to the SDK's own platform-package
|
|
99
|
-
* resolution. Operator-level only — never sourced from the wire.
|
|
100
|
-
*/
|
|
101
|
-
resolveCliPath?: () => Promise<string | undefined>;
|
|
102
|
-
/**
|
|
103
|
-
* In-process MCP servers to attach to every session (the SDK's
|
|
104
|
-
* `createSdkMcpServer` output). Called once per session spawn. Operator
|
|
105
|
-
* embed-tier only — never wire-sourced; instances win name conflicts with
|
|
106
|
-
* wire-configured servers.
|
|
107
|
-
*/
|
|
108
|
-
sdkMcpServers?: ClaudeSessionExtras["sdkMcpServers"];
|
|
109
|
-
/**
|
|
110
|
-
* Pre-broker tool policy (SDK PermissionResult or undefined = fall through
|
|
111
|
-
* to the interactive broker). Operator embed-tier only.
|
|
112
|
-
*/
|
|
113
|
-
toolPolicy?: ClaudeToolPolicy;
|
|
114
|
-
/** SDK lifecycle hooks factory (decision-capable). Operator embed-tier only. */
|
|
115
|
-
hooks?: ClaudeHooksFactory;
|
|
116
|
-
/**
|
|
117
|
-
* Called exactly once when a live session's subprocess ends, with why:
|
|
118
|
-
* `idle` (idle-timeout eviction), `replaced` (config change or host resume
|
|
119
|
-
* required a new process), `released` (explicit release/close), `shutdown`
|
|
120
|
-
* (terminateAll). The seam for host-managed per-session resources — BYOK
|
|
121
|
-
* proxy keys, recorders — instead of re-deriving termination from side
|
|
122
|
-
* effects. NOTE: `replaced` sessions usually respawn immediately with
|
|
123
|
-
* context preserved; drop only resources bound to the dead subprocess.
|
|
124
|
-
*/
|
|
125
|
-
onSessionEnd?: (sessionId: string, reason: ClaudeSessionEndReason) => void;
|
|
126
|
-
/** Operational diagnostics (interrupt timeouts). */
|
|
127
|
-
onDiagnostic?: DiagnosticHandler;
|
|
128
|
-
/**
|
|
129
|
-
* Raw SDK option overrides merged over the engine's options at session
|
|
130
|
-
* spawn (embedder escape hatch for SDK surface the engine does not model:
|
|
131
|
-
* disallowedTools, forwardSubagentText, extraArgs, ...). Operator
|
|
132
|
-
* embed-tier only — never wire-sourced.
|
|
133
|
-
*/
|
|
134
|
-
sdkOptions?: ClaudeSessionExtras["sdkOptions"];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
100
|
/**
|
|
138
101
|
* Claude Code harness. Reuses a warm `query()` per logical session for fast
|
|
139
102
|
* in-session multi-turn and model hot-swap; falls back to SDK `resume` when a
|
|
@@ -142,28 +105,45 @@ export interface ClaudeCodeAgentOptions {
|
|
|
142
105
|
export class ClaudeCodeAgent extends SessionAgent {
|
|
143
106
|
readonly harness = "claude-code" as const;
|
|
144
107
|
readonly capabilities = CAPABILITIES;
|
|
145
|
-
|
|
108
|
+
/** Its CLIs start here: the runtime's, or this OS process's own when it was made without one. */
|
|
109
|
+
readonly processes: NativeProcesses;
|
|
110
|
+
readonly login: ClaudeCliLogin;
|
|
111
|
+
private readonly pool: ClaudeSessionPool;
|
|
112
|
+
private readonly credentials?: ClaudeCredentials;
|
|
146
113
|
|
|
147
114
|
constructor(private readonly agentOptions: ClaudeCodeAgentOptions = {}) {
|
|
148
115
|
super();
|
|
149
|
-
this.
|
|
116
|
+
this.processes = agentOptions.processes ?? sharedNativeProcesses();
|
|
117
|
+
this.pool = new ClaudeSessionPool({ ...agentOptions, processes: this.processes });
|
|
118
|
+
this.login = new ClaudeCliLogin({
|
|
119
|
+
resolveCliPath: agentOptions.resolveCliPath,
|
|
120
|
+
processes: this.processes,
|
|
121
|
+
inheritConfig: agentOptions.inheritConfig,
|
|
122
|
+
});
|
|
123
|
+
if (agentOptions.credentials)
|
|
124
|
+
this.credentials = new ClaudeCredentials(agentOptions.credentials);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Options on a credential the product holds, when it holds one. */
|
|
128
|
+
private withDelivery<T extends { apiKey?: string; env?: Record<string, string> }>(
|
|
129
|
+
options: T,
|
|
130
|
+
delivery: ClaudeDelivery | undefined,
|
|
131
|
+
): T {
|
|
132
|
+
return delivery
|
|
133
|
+
? { ...options, apiKey: delivery.apiKey, env: { ...options.env, ...delivery.env } }
|
|
134
|
+
: options;
|
|
150
135
|
}
|
|
151
136
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
sdkMcpServers: this.agentOptions.sdkMcpServers,
|
|
155
|
-
toolPolicy: this.agentOptions.toolPolicy,
|
|
156
|
-
hooks: this.agentOptions.hooks,
|
|
157
|
-
sdkOptions: this.agentOptions.sdkOptions,
|
|
158
|
-
};
|
|
137
|
+
loginChanged(): void {
|
|
138
|
+
this.pool.loginChanged();
|
|
159
139
|
}
|
|
160
140
|
|
|
161
141
|
protected override async *executeTurn(
|
|
162
142
|
input: AgentInput,
|
|
163
143
|
options: AgentExecuteOptions,
|
|
164
144
|
controller: AbortController,
|
|
165
|
-
): AsyncIterableIterator<
|
|
166
|
-
let unconfirmedSession:
|
|
145
|
+
): AsyncIterableIterator<ClaudeRawEvent> {
|
|
146
|
+
let unconfirmedSession: ClaudeSession | undefined;
|
|
167
147
|
let removeInterrupt: (() => void) | undefined;
|
|
168
148
|
try {
|
|
169
149
|
controller.signal.throwIfAborted();
|
|
@@ -171,10 +151,18 @@ export class ClaudeCodeAgent extends SessionAgent {
|
|
|
171
151
|
const content = toClaudeContent(input);
|
|
172
152
|
controller.signal.throwIfAborted();
|
|
173
153
|
const thinking = fitClaudeThinking(options.thinkingLevel, options.modelThinking);
|
|
174
|
-
const
|
|
154
|
+
const turnOptions = this.withDelivery(
|
|
155
|
+
options,
|
|
156
|
+
await this.credentials?.forTurn(options.sessionId, options.turnId, controller.signal),
|
|
157
|
+
);
|
|
158
|
+
controller.signal.throwIfAborted();
|
|
159
|
+
const { session, spawned } = await this.pool.getOrCreate(
|
|
175
160
|
options.sessionId,
|
|
176
|
-
|
|
177
|
-
|
|
161
|
+
claudeSessionConfig(
|
|
162
|
+
{ ...turnOptions, thinkingLevel: thinking.send },
|
|
163
|
+
cliPath,
|
|
164
|
+
this.agentOptions.inheritConfig,
|
|
165
|
+
),
|
|
178
166
|
);
|
|
179
167
|
if (thinking.applied && !session.operatorThinking)
|
|
180
168
|
options.onExecution?.({ thinkingLevel: thinking.applied });
|
|
@@ -182,6 +170,10 @@ export class ClaudeCodeAgent extends SessionAgent {
|
|
|
182
170
|
if (spawned) unconfirmedSession = session;
|
|
183
171
|
// A cancel during connection repair must never submit the prompt.
|
|
184
172
|
controller.signal.throwIfAborted();
|
|
173
|
+
// The turn goes on without a server it does not require, and says so.
|
|
174
|
+
await session.mcp.unavailable.announce(options.onWarning);
|
|
175
|
+
// A cancel while it said so must never submit the prompt either.
|
|
176
|
+
controller.signal.throwIfAborted();
|
|
185
177
|
let reported = false;
|
|
186
178
|
const report = (id: string) => {
|
|
187
179
|
if (reported) return;
|
|
@@ -191,67 +183,90 @@ export class ClaudeCodeAgent extends SessionAgent {
|
|
|
191
183
|
};
|
|
192
184
|
// A resume is only confirmed once the backend produces output.
|
|
193
185
|
if (!attemptedResume && session.currentSessionId) report(session.currentSessionId);
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const msg = event as {
|
|
205
|
-
type?: string;
|
|
206
|
-
session_id?: string;
|
|
207
|
-
subtype?: string;
|
|
208
|
-
errors?: string[];
|
|
209
|
-
};
|
|
210
|
-
if (msg.type === "assistant" || msg.type === "stream_event") sawOutput = true;
|
|
211
|
-
if (
|
|
212
|
-
attemptedResume &&
|
|
213
|
-
!sawOutput &&
|
|
214
|
-
!controller.signal.aborted &&
|
|
215
|
-
claudeResumeFailed(event)
|
|
216
|
-
) {
|
|
217
|
-
const reason = msg.errors?.join("; ") || "Claude failed before loading the conversation";
|
|
218
|
-
throw new SessionResumeError(session.currentConfig.resumeSessionId!, reason, {
|
|
219
|
-
cause: new Error(reason),
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
if (msg.session_id && (!attemptedResume || sawOutput || msg.subtype === "success"))
|
|
223
|
-
report(msg.session_id);
|
|
224
|
-
yield event as RawAgentEvent;
|
|
225
|
-
}
|
|
226
|
-
if (attemptedResume && unconfirmedSession && !controller.signal.aborted) {
|
|
227
|
-
throw new SessionResumeError(
|
|
228
|
-
session.currentConfig.resumeSessionId!,
|
|
229
|
-
"Claude ended before confirming the conversation was loaded",
|
|
186
|
+
const turn = session.sendMessage(content, {
|
|
187
|
+
turnId: options.turnId,
|
|
188
|
+
permissions: options.onPermissionRequest,
|
|
189
|
+
elicitation: options.onElicitationRequest,
|
|
190
|
+
});
|
|
191
|
+
try {
|
|
192
|
+
await this.openSteering(options, (request) =>
|
|
193
|
+
session.steer(toClaudeContent(request.input), request.steerId)
|
|
194
|
+
? "steered"
|
|
195
|
+
: "no_active_turn",
|
|
230
196
|
);
|
|
197
|
+
removeInterrupt = onAbort(controller.signal, () => void session.interruptTurn());
|
|
198
|
+
let sawOutput = false;
|
|
199
|
+
for await (const event of turn.events) {
|
|
200
|
+
if (event.type === "assistant" || event.type === "stream_event") sawOutput = true;
|
|
201
|
+
if (
|
|
202
|
+
attemptedResume &&
|
|
203
|
+
!sawOutput &&
|
|
204
|
+
!controller.signal.aborted &&
|
|
205
|
+
claudeResumeFailed(event)
|
|
206
|
+
) {
|
|
207
|
+
const reason =
|
|
208
|
+
event.errors?.join("; ") || "Claude failed before loading the conversation";
|
|
209
|
+
throw new SessionResumeError(session.currentConfig.resumeSessionId!, reason, {
|
|
210
|
+
cause: new Error(reason),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const nativeId = "session_id" in event ? event.session_id : undefined;
|
|
214
|
+
const succeeded = event.type === "result" && event.subtype === "success";
|
|
215
|
+
if (nativeId && (!attemptedResume || sawOutput || succeeded)) report(nativeId);
|
|
216
|
+
yield event;
|
|
217
|
+
}
|
|
218
|
+
if (attemptedResume && unconfirmedSession && !controller.signal.aborted) {
|
|
219
|
+
throw new SessionResumeError(
|
|
220
|
+
session.currentConfig.resumeSessionId!,
|
|
221
|
+
"Claude ended before confirming the conversation was loaded",
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
// Ground truth for the adapter: an interrupted turn and a turn that
|
|
225
|
+
// failed during execution (e.g. a bad resume id) end with the SAME
|
|
226
|
+
// result shape (error_during_execution, null stop_reason). Only the
|
|
227
|
+
// agent knows whether an interrupt was actually requested.
|
|
228
|
+
if (controller.signal.aborted || turn.cancelled)
|
|
229
|
+
yield { type: "agentServer/turnInterrupted" };
|
|
230
|
+
} finally {
|
|
231
|
+
// @ref LLP 0001#d10--built-in-turns-own-their-logical-session-through-cleanup — through the native turn's end
|
|
232
|
+
// The reservation ends when this generator does: a turn the runtime
|
|
233
|
+
// stopped reading (a transformer or a sink that failed) is stopped
|
|
234
|
+
// first, so the next turn never meets it running and a cancel still
|
|
235
|
+
// reaches it meanwhile.
|
|
236
|
+
await session.stopTurn(turn);
|
|
231
237
|
}
|
|
232
|
-
|
|
233
|
-
// Ground truth for the adapter: an interrupted turn and a turn that
|
|
234
|
-
// failed during execution (e.g. a bad resume id) end with the SAME
|
|
235
|
-
// result shape (error_during_execution, null stop_reason). Only the
|
|
236
|
-
// agent knows whether an interrupt was actually requested.
|
|
237
|
-
if (controller.signal.aborted) yield { type: "turn_interrupted" };
|
|
238
238
|
} catch (error) {
|
|
239
239
|
if (!controller.signal.aborted) throw error;
|
|
240
|
-
yield { type: "
|
|
240
|
+
yield { type: "agentServer/turnInterrupted" };
|
|
241
241
|
} finally {
|
|
242
242
|
removeInterrupt?.();
|
|
243
|
+
// The product's credential is held while a turn runs, and no longer.
|
|
244
|
+
this.credentials?.endTurn(options.sessionId);
|
|
243
245
|
// A cancelled/failed preparation must not leave an unconfirmed query
|
|
244
246
|
// looking like a healthy warm conversation on the next attempt.
|
|
245
247
|
await unconfirmedSession?.terminate();
|
|
246
248
|
}
|
|
247
249
|
}
|
|
248
250
|
|
|
251
|
+
protected override checkSteerInput(input: AgentInput): void {
|
|
252
|
+
toClaudeContent(input);
|
|
253
|
+
}
|
|
254
|
+
|
|
249
255
|
/** The models this login offers in `options.cwd`, from the Claude Code CLI. */
|
|
250
|
-
async listModels(
|
|
256
|
+
async listModels(listing: ListModelsOptions): Promise<ModelDescriptor[]> {
|
|
251
257
|
const cliPath = await this.agentOptions.resolveCliPath?.();
|
|
258
|
+
// On a product's credentials the CLI holds the placeholder, which alone decides its list.
|
|
259
|
+
const options = this.withDelivery(listing, this.credentials && ON_PLACEHOLDER);
|
|
252
260
|
options.signal?.throwIfAborted();
|
|
253
261
|
const models = await readClaudeModels(
|
|
254
|
-
{
|
|
262
|
+
{
|
|
263
|
+
cwd: options.cwd,
|
|
264
|
+
env: options.env,
|
|
265
|
+
apiKey: options.apiKey,
|
|
266
|
+
cliPath,
|
|
267
|
+
inheritConfig: this.agentOptions.inheritConfig,
|
|
268
|
+
},
|
|
269
|
+
this.processes,
|
|
255
270
|
options.signal,
|
|
256
271
|
);
|
|
257
272
|
return claudeModelDescriptors(models);
|
|
@@ -266,12 +281,12 @@ export class ClaudeCodeAgent extends SessionAgent {
|
|
|
266
281
|
sessionId: string,
|
|
267
282
|
servers: Record<string, McpServerConfig>,
|
|
268
283
|
): Promise<McpSetServersResult | undefined> {
|
|
269
|
-
return this.
|
|
284
|
+
return this.pool.setMcpServers(sessionId, servers);
|
|
270
285
|
}
|
|
271
286
|
|
|
272
287
|
/** Resume saved history in a fresh subprocess on the next turn after host suspension. */
|
|
273
288
|
invalidateMcpConnections(): void {
|
|
274
|
-
this.
|
|
289
|
+
this.pool.invalidateMcpConnections();
|
|
275
290
|
}
|
|
276
291
|
|
|
277
292
|
override async cancel(sessionId: string): Promise<CancelResult> {
|
|
@@ -281,7 +296,7 @@ export class ClaudeCodeAgent extends SessionAgent {
|
|
|
281
296
|
// could surface a clean user cancel as `error`/`end_turn`). The SDK
|
|
282
297
|
// interrupt then stops the underlying turn; its round-trip is what
|
|
283
298
|
// confirms the cancel.
|
|
284
|
-
const session = this.
|
|
299
|
+
const session = this.pool.get(sessionId);
|
|
285
300
|
const base = await super.cancel(sessionId);
|
|
286
301
|
if (!session || !base.hadTurn) return base;
|
|
287
302
|
const interrupted = await session.interruptTurn();
|
|
@@ -297,11 +312,13 @@ export class ClaudeCodeAgent extends SessionAgent {
|
|
|
297
312
|
|
|
298
313
|
override async release(sessionId: string): Promise<void> {
|
|
299
314
|
await super.release(sessionId);
|
|
300
|
-
await this.
|
|
315
|
+
await this.pool.terminate(sessionId);
|
|
316
|
+
this.credentials?.release(sessionId);
|
|
301
317
|
}
|
|
302
318
|
|
|
303
319
|
override async terminateAll(): Promise<void> {
|
|
304
320
|
await super.terminateAll();
|
|
305
|
-
await this.
|
|
321
|
+
await this.pool.terminateAll();
|
|
322
|
+
await this.credentials?.close();
|
|
306
323
|
}
|
|
307
324
|
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ClaudeCredential,
|
|
3
|
+
type CredentialRequest,
|
|
4
|
+
tokenDigest,
|
|
5
|
+
} from "../../../protocol/index.ts";
|
|
6
|
+
import {
|
|
7
|
+
type FetchLike,
|
|
8
|
+
PROXY_PLACEHOLDER_KEY,
|
|
9
|
+
createAnthropicProxy,
|
|
10
|
+
} from "../../proxy/anthropic-proxy.ts";
|
|
11
|
+
import { type ApiKeyEntry, ApiKeyStore } from "../../proxy/api-key-store.ts";
|
|
12
|
+
import { type Loopback, serveLoopback } from "../../proxy/loopback.ts";
|
|
13
|
+
import { type CredentialSource, credentialFor } from "../credentials.ts";
|
|
14
|
+
|
|
15
|
+
/** Claude Code's ask of the product's credential source. */
|
|
16
|
+
type ClaudeRequest = CredentialRequest & { harness: "claude-code" };
|
|
17
|
+
|
|
18
|
+
/** What Claude Code starts with to run on a credential the product holds. */
|
|
19
|
+
export interface ClaudeDelivery {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
env: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The flags by which Claude Code picks another provider (Claude Code 2.1.288),
|
|
26
|
+
* each of which the server's or a turn's env could set: any would win over
|
|
27
|
+
* the placeholder. An empty one is off.
|
|
28
|
+
*/
|
|
29
|
+
const PROVIDER_FLAGS = [
|
|
30
|
+
"CLAUDE_CODE_USE_BEDROCK",
|
|
31
|
+
"CLAUDE_CODE_USE_VERTEX",
|
|
32
|
+
"CLAUDE_CODE_USE_FOUNDRY",
|
|
33
|
+
"CLAUDE_CODE_USE_ANTHROPIC_AWS",
|
|
34
|
+
"CLAUDE_CODE_USE_ANTHROPIC_GOOGLE_CLOUD",
|
|
35
|
+
"CLAUDE_CODE_USE_MANTLE",
|
|
36
|
+
"CLAUDE_CODE_USE_GATEWAY",
|
|
37
|
+
] as const;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* What Claude Code holds behind the proxy, whoever's credential is there: a
|
|
41
|
+
* placeholder key, over what a turn's own env says (a product that blanks
|
|
42
|
+
* `ANTHROPIC_API_KEY`), and nothing that outranks it. Its model list depends
|
|
43
|
+
* on this alone: the CLI lists by the kind of credential it holds, asking the
|
|
44
|
+
* API nothing (Claude Code 2.1.288), so a listing needs no credential.
|
|
45
|
+
*/
|
|
46
|
+
export const ON_PLACEHOLDER: ClaudeDelivery = {
|
|
47
|
+
apiKey: PROXY_PLACEHOLDER_KEY,
|
|
48
|
+
env: {
|
|
49
|
+
ANTHROPIC_API_KEY: PROXY_PLACEHOLDER_KEY,
|
|
50
|
+
ANTHROPIC_AUTH_TOKEN: "",
|
|
51
|
+
CLAUDE_CODE_OAUTH_TOKEN: "",
|
|
52
|
+
...Object.fromEntries(PROVIDER_FLAGS.map((flag) => [flag, ""])),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// @ref LLP 0012#what-the-engine-holds-for-the-third — the token never enters the CLI's environment
|
|
57
|
+
/**
|
|
58
|
+
* Claude Code on credentials the product holds: each goes to the engine's
|
|
59
|
+
* own Anthropic proxy on loopback, and the CLI gets a placeholder key and the
|
|
60
|
+
* proxy's address, so what its tools can read holds no credential. A session
|
|
61
|
+
* keeps one address across its turns, as its CLI keeps the one it started
|
|
62
|
+
* with, and the credential behind it is held only while a turn runs. A
|
|
63
|
+
* credential refused upstream is asked for again, once, and the request sent
|
|
64
|
+
* with the fresher one.
|
|
65
|
+
*/
|
|
66
|
+
export class ClaudeCredentials {
|
|
67
|
+
private readonly store = new ApiKeyStore();
|
|
68
|
+
/** Each session's address: unguessable, since anything on this machine reaches loopback. */
|
|
69
|
+
private readonly addresses = new Map<string, string>();
|
|
70
|
+
/** Whose credential each address holds now: a renewal is kept only while it does. */
|
|
71
|
+
private readonly holders = new Map<string, ClaudeRequest>();
|
|
72
|
+
private loopback?: Promise<Loopback>;
|
|
73
|
+
|
|
74
|
+
constructor(
|
|
75
|
+
private readonly source: CredentialSource,
|
|
76
|
+
/** How the proxy reaches Anthropic (a test's stand-in). */
|
|
77
|
+
private readonly fetch?: FetchLike,
|
|
78
|
+
) {}
|
|
79
|
+
|
|
80
|
+
/** Hold the turn's credential until `endTurn`: none runs the turn on the CLI's own login. */
|
|
81
|
+
async forTurn(
|
|
82
|
+
sessionId: string,
|
|
83
|
+
turnId: string | undefined,
|
|
84
|
+
signal: AbortSignal,
|
|
85
|
+
): Promise<ClaudeDelivery | undefined> {
|
|
86
|
+
const request = { harness: "claude-code" as const, sessionId, ...(turnId && { turnId }) };
|
|
87
|
+
const credential = await credentialFor(this.source, request, signal);
|
|
88
|
+
if (!credential) return undefined;
|
|
89
|
+
const proxyId = this.addresses.get(sessionId) ?? crypto.randomUUID();
|
|
90
|
+
this.addresses.set(sessionId, proxyId);
|
|
91
|
+
this.hold(proxyId, request, credential);
|
|
92
|
+
return this.delivery(proxyId);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The turn ended: the session's address holds nothing until its next turn. */
|
|
96
|
+
endTurn(sessionId: string): void {
|
|
97
|
+
const proxyId = this.addresses.get(sessionId);
|
|
98
|
+
if (proxyId) this.drop(proxyId);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Forget the session: its address answers no more. */
|
|
102
|
+
release(sessionId: string): void {
|
|
103
|
+
this.endTurn(sessionId);
|
|
104
|
+
this.addresses.delete(sessionId);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async close(): Promise<void> {
|
|
108
|
+
this.store.clear();
|
|
109
|
+
this.holders.clear();
|
|
110
|
+
this.addresses.clear();
|
|
111
|
+
const loopback = this.loopback;
|
|
112
|
+
this.loopback = undefined;
|
|
113
|
+
await (await loopback?.catch(() => undefined))?.close();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private hold(proxyId: string, holder: ClaudeRequest, credential: ClaudeCredential): void {
|
|
117
|
+
this.holders.set(proxyId, holder);
|
|
118
|
+
this.put(proxyId, credential);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private drop(proxyId: string): void {
|
|
122
|
+
this.store.delete(proxyId);
|
|
123
|
+
this.holders.delete(proxyId);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private put(proxyId: string, credential: ClaudeCredential): ApiKeyEntry | undefined {
|
|
127
|
+
if (credential.type === "api_key") {
|
|
128
|
+
const baseUrl = credential.baseUrl?.replace(/\/+$/, "");
|
|
129
|
+
this.store.set(proxyId, credential.apiKey, { ...(baseUrl && { upstreamBaseUrl: baseUrl }) });
|
|
130
|
+
} else {
|
|
131
|
+
this.store.set(proxyId, credential.accessToken, { kind: "oauth" });
|
|
132
|
+
}
|
|
133
|
+
return this.store.get(proxyId);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The placeholder, and the session's address on the proxy. */
|
|
137
|
+
private async delivery(proxyId: string): Promise<ClaudeDelivery> {
|
|
138
|
+
const { url } = await this.serve();
|
|
139
|
+
return {
|
|
140
|
+
apiKey: ON_PLACEHOLDER.apiKey,
|
|
141
|
+
env: { ...ON_PLACEHOLDER.env, ANTHROPIC_BASE_URL: `${url}/proxy/anthropic/${proxyId}` },
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private serve(): Promise<Loopback> {
|
|
146
|
+
this.loopback ??= serveLoopback(
|
|
147
|
+
createAnthropicProxy({
|
|
148
|
+
store: this.store,
|
|
149
|
+
...(this.fetch && { fetch: this.fetch }),
|
|
150
|
+
renew: (proxyId, rejected) => this.renew(proxyId, rejected),
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
// A start that failed is tried again by the next turn.
|
|
154
|
+
this.loopback.catch(() => {
|
|
155
|
+
this.loopback = undefined;
|
|
156
|
+
});
|
|
157
|
+
return this.loopback;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Upstream refused an address's credential: a fresher one, kept only while the same holder has it. */
|
|
161
|
+
private async renew(proxyId: string, rejected: ApiKeyEntry): Promise<ApiKeyEntry | undefined> {
|
|
162
|
+
const holder = this.holders.get(proxyId);
|
|
163
|
+
if (!holder) return undefined;
|
|
164
|
+
const fresher = await credentialFor(this.source, {
|
|
165
|
+
...holder,
|
|
166
|
+
rejectedSha256: await tokenDigest(rejected.apiKey),
|
|
167
|
+
}).catch(() => undefined);
|
|
168
|
+
if (!fresher || this.holders.get(proxyId) !== holder) return undefined;
|
|
169
|
+
return this.put(proxyId, fresher);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { SDKMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import type { ClaudeQuerySpend } from "./spend.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a Claude turn yields: the SDK's messages, unmodified, and the engine's
|
|
6
|
+
* own events, named as the Codex harness names its own (`agentServer/…`).
|
|
7
|
+
* This is what a consumer sees under `includeRaw`.
|
|
8
|
+
*
|
|
9
|
+
* The SDK's types describe its own version, and the CLI that runs can be
|
|
10
|
+
* another (an operator's `$CLAUDE_CLI_PATH`), so readers still tolerate a
|
|
11
|
+
* field an older CLI leaves out.
|
|
12
|
+
*/
|
|
13
|
+
export type ClaudeRawEvent =
|
|
14
|
+
| SDKMessage
|
|
15
|
+
| ClaudeTurnInterrupted
|
|
16
|
+
| ClaudeSteerRead
|
|
17
|
+
| ClaudeQuerySettled;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The turn was asked to stop. An interrupted query and one that failed end on
|
|
21
|
+
* the same result (`error_during_execution`, the stop reason of the step it
|
|
22
|
+
* aborted), so only this tells them apart. It comes after that result.
|
|
23
|
+
*/
|
|
24
|
+
export interface ClaudeTurnInterrupted {
|
|
25
|
+
type: "agentServer/turnInterrupted";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Claude read a steer here: it replayed the steer's message, or a frame named it consumed. */
|
|
29
|
+
export interface ClaudeSteerRead {
|
|
30
|
+
type: "agentServer/steerRead";
|
|
31
|
+
steerId: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* What the query whose result comes next spent. Claude reports running totals
|
|
36
|
+
* for its conversation, and only the session knows the baseline, so it says
|
|
37
|
+
* the query's share here, just before the native `result`.
|
|
38
|
+
*/
|
|
39
|
+
export interface ClaudeQuerySettled extends ClaudeQuerySpend {
|
|
40
|
+
type: "agentServer/querySettled";
|
|
41
|
+
/** Claude has steers it has not read and runs them as its next query, still this turn. */
|
|
42
|
+
steersPending: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The message Claude Code took, from its `command_lifecycle` "started" frame,
|
|
47
|
+
* which the SDK does not type. A query beginning does not say so: Claude also
|
|
48
|
+
* begins queries of its own.
|
|
49
|
+
*/
|
|
50
|
+
export function commandStarted(event: SDKMessage): string | undefined {
|
|
51
|
+
const frame = event as { type: string; state?: string; command_uuid?: string };
|
|
52
|
+
return frame.type === "command_lifecycle" && frame.state === "started"
|
|
53
|
+
? frame.command_uuid
|
|
54
|
+
: undefined;
|
|
55
|
+
}
|