@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
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SDKAssistantMessage,
|
|
3
|
+
SDKMessage,
|
|
4
|
+
SDKPartialAssistantMessage,
|
|
5
|
+
SDKResultMessage,
|
|
6
|
+
} from "@anthropic-ai/claude-agent-sdk";
|
|
1
7
|
import {
|
|
2
|
-
DEFAULT_TOKEN_USAGE,
|
|
3
8
|
type ReasoningPart,
|
|
4
|
-
type StopReason,
|
|
5
9
|
type StreamContext,
|
|
6
10
|
type SubagentMetadata,
|
|
7
11
|
type TextPart,
|
|
8
|
-
type TokenUsage,
|
|
9
12
|
type ToolPart,
|
|
10
13
|
type ToolResultContent,
|
|
11
14
|
appendToolInput,
|
|
15
|
+
classifyError,
|
|
12
16
|
completeToolPart,
|
|
13
17
|
createPendingToolPart,
|
|
14
18
|
createReasoningPart,
|
|
@@ -17,8 +21,13 @@ import {
|
|
|
17
21
|
setToolMeta,
|
|
18
22
|
startToolPart,
|
|
19
23
|
} from "../../../protocol/index.ts";
|
|
20
|
-
import {
|
|
24
|
+
import { isRecord } from "../../utils/is-record.ts";
|
|
21
25
|
import type { AdapterEvent, EventTransformer, TransformResult } from "../types.ts";
|
|
26
|
+
import type { ClaudeQuerySettled, ClaudeRawEvent } from "./events.ts";
|
|
27
|
+
import { fromSdkPermissionMode } from "./options.ts";
|
|
28
|
+
import { ClaudeTurnOutcome, claudeErrorCategory } from "./outcome.ts";
|
|
29
|
+
import { claudeToolMeta, toolLocationsFromInput } from "./tools.ts";
|
|
30
|
+
import { ClaudeTurnUsage } from "./turn-usage.ts";
|
|
22
31
|
|
|
23
32
|
/**
|
|
24
33
|
* Parses raw Claude Code SDK messages into normalized AdapterEvents.
|
|
@@ -27,79 +36,17 @@ import type { AdapterEvent, EventTransformer, TransformResult } from "../types.t
|
|
|
27
36
|
* content_block_start opens a part, content_block_delta streams text/thinking/
|
|
28
37
|
* tool-input, content_block_stop finalizes it. Tool results arrive later as
|
|
29
38
|
* `user` messages and complete the matching tool part in place. The terminal
|
|
30
|
-
* `result` message
|
|
39
|
+
* `result` message says how the query ended, after the session's own word on
|
|
40
|
+
* what it spent (`agentServer/querySettled`). We rely on streaming for
|
|
31
41
|
* content, so the non-streaming `assistant` message is processed only as a
|
|
32
|
-
* fallback when partial messages were absent for it (e.g. some sub-agent
|
|
33
|
-
* — see `
|
|
42
|
+
* fallback when partial messages were absent for it (e.g. some sub-agent
|
|
43
|
+
* paths) — see `hasStreamed`. Accounting is `ClaudeTurnUsage`'s, how the turn
|
|
44
|
+
* ended `ClaudeTurnOutcome`'s.
|
|
34
45
|
*/
|
|
35
46
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
type: string;
|
|
40
|
-
index?: number;
|
|
41
|
-
content_block?: { type: string; id?: string; name?: string };
|
|
42
|
-
delta?: {
|
|
43
|
-
type?: string;
|
|
44
|
-
text?: string;
|
|
45
|
-
thinking?: string;
|
|
46
|
-
/** Withheld-thinking placeholder: running size of a thought whose text never streams. */
|
|
47
|
-
estimated_tokens?: number;
|
|
48
|
-
partial_json?: string;
|
|
49
|
-
stop_reason?: string;
|
|
50
|
-
};
|
|
51
|
-
usage?: { output_tokens?: number };
|
|
52
|
-
}
|
|
53
|
-
interface RawUsage {
|
|
54
|
-
input_tokens?: number;
|
|
55
|
-
output_tokens?: number;
|
|
56
|
-
cache_read_input_tokens?: number;
|
|
57
|
-
cache_creation_input_tokens?: number;
|
|
58
|
-
cache_creation?: {
|
|
59
|
-
ephemeral_5m_input_tokens?: number;
|
|
60
|
-
ephemeral_1h_input_tokens?: number;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
interface ContentBlock {
|
|
64
|
-
type: string;
|
|
65
|
-
text?: string;
|
|
66
|
-
thinking?: string;
|
|
67
|
-
id?: string;
|
|
68
|
-
name?: string;
|
|
69
|
-
input?: Record<string, unknown>;
|
|
70
|
-
tool_use_id?: string;
|
|
71
|
-
content?: unknown;
|
|
72
|
-
is_error?: boolean;
|
|
73
|
-
}
|
|
74
|
-
type ClaudeMessage =
|
|
75
|
-
| {
|
|
76
|
-
type: "system";
|
|
77
|
-
subtype?: string;
|
|
78
|
-
compact_metadata?: { trigger?: string; pre_tokens?: number; post_tokens?: number };
|
|
79
|
-
}
|
|
80
|
-
| { type: "stream_event"; event: StreamEvent; parent_tool_use_id?: string | null }
|
|
81
|
-
// Synthetic, appended by ClaudeCodeAgent when the turn's abort controller
|
|
82
|
-
// fired — disambiguates interrupt from execution failure (same SDK result).
|
|
83
|
-
| { type: "turn_interrupted" }
|
|
84
|
-
| {
|
|
85
|
-
type: "assistant";
|
|
86
|
-
message?: { content?: ContentBlock[]; usage?: RawUsage; model?: string };
|
|
87
|
-
parent_tool_use_id?: string | null;
|
|
88
|
-
}
|
|
89
|
-
| { type: "user"; message?: { content?: ContentBlock[] | string } }
|
|
90
|
-
| {
|
|
91
|
-
type: "result";
|
|
92
|
-
subtype?: string;
|
|
93
|
-
usage?: RawUsage;
|
|
94
|
-
modelUsage?: Record<string, { contextWindow?: number }>;
|
|
95
|
-
total_cost_usd?: number;
|
|
96
|
-
/** Per-turn delta from the generator tap; null means unreported. */
|
|
97
|
-
turn_cost_usd?: number | null;
|
|
98
|
-
stop_reason?: string | null;
|
|
99
|
-
is_error?: boolean;
|
|
100
|
-
/** On an `is_error` success, the API failure's text. */
|
|
101
|
-
result?: string;
|
|
102
|
-
};
|
|
47
|
+
type StreamEvent = SDKPartialAssistantMessage["event"];
|
|
48
|
+
type ContentBlock = SDKAssistantMessage["message"]["content"][number];
|
|
49
|
+
type SystemMessage = Extract<SDKMessage, { type: "system" }>;
|
|
103
50
|
|
|
104
51
|
type BlockKind = "text" | "reasoning" | "tool";
|
|
105
52
|
interface BlockEntry {
|
|
@@ -108,6 +55,9 @@ interface BlockEntry {
|
|
|
108
55
|
part: TextPart | ReasoningPart | ToolPart;
|
|
109
56
|
}
|
|
110
57
|
|
|
58
|
+
/** The model Claude Code names on a message it wrote itself, such as an API error. */
|
|
59
|
+
const SYNTHETIC_MODEL = "<synthetic>";
|
|
60
|
+
|
|
111
61
|
function safeParseJson(input: string): Record<string, unknown> {
|
|
112
62
|
if (!input.trim()) return {};
|
|
113
63
|
try {
|
|
@@ -118,37 +68,6 @@ function safeParseJson(input: string): Record<string, unknown> {
|
|
|
118
68
|
}
|
|
119
69
|
}
|
|
120
70
|
|
|
121
|
-
/** Map Anthropic stop reasons / result subtypes onto the normalized enum. */
|
|
122
|
-
function mapClaudeStopReason(
|
|
123
|
-
stopReason: string | null | undefined,
|
|
124
|
-
subtype: string | undefined,
|
|
125
|
-
): StopReason | undefined {
|
|
126
|
-
if (subtype === "error_max_turns") return "max_turn_requests";
|
|
127
|
-
switch (stopReason) {
|
|
128
|
-
case "end_turn":
|
|
129
|
-
case "stop_sequence":
|
|
130
|
-
case "tool_use":
|
|
131
|
-
case "pause_turn":
|
|
132
|
-
return "end_turn";
|
|
133
|
-
case "max_tokens":
|
|
134
|
-
return "max_tokens";
|
|
135
|
-
case "refusal":
|
|
136
|
-
return "refusal";
|
|
137
|
-
default:
|
|
138
|
-
return undefined;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** Context occupancy from an Anthropic usage block: full prompt + output. */
|
|
143
|
-
function contextTokens(usage: RawUsage): number {
|
|
144
|
-
return (
|
|
145
|
-
(usage.input_tokens ?? 0) +
|
|
146
|
-
(usage.cache_read_input_tokens ?? 0) +
|
|
147
|
-
(usage.cache_creation_input_tokens ?? 0) +
|
|
148
|
-
(usage.output_tokens ?? 0)
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
71
|
function stringifyToolResult(content: unknown): string {
|
|
153
72
|
if (typeof content === "string") return content;
|
|
154
73
|
if (Array.isArray(content)) {
|
|
@@ -162,8 +81,9 @@ function stringifyToolResult(content: unknown): string {
|
|
|
162
81
|
return JSON.stringify(content);
|
|
163
82
|
}
|
|
164
83
|
|
|
84
|
+
// @ref LLP 0002#tool-output-has-three-audiences — `content` is display-grade, `output` model-facing
|
|
165
85
|
/**
|
|
166
|
-
* The display-grade view of a tool_result's content blocks
|
|
86
|
+
* The display-grade view of a tool_result's content blocks: the
|
|
167
87
|
* flattened string stays the model-facing record, this preserves what
|
|
168
88
|
* flattening drops — images especially, which contribute "" to the string.
|
|
169
89
|
* Block shapes we can't express are skipped, never guessed.
|
|
@@ -198,7 +118,7 @@ function toolResultContent(content: unknown): ToolResultContent[] | undefined {
|
|
|
198
118
|
* non-streaming paths. `subagent_type` in the input identifies a spawn on any
|
|
199
119
|
* tool name; Claude's `Agent` (formerly `Task`) also counts before its
|
|
200
120
|
* input parses into anything useful (presence of `subagent` is what promotes
|
|
201
|
-
* the part to `kind: "task"`
|
|
121
|
+
* the part to `kind: "task"`).
|
|
202
122
|
*/
|
|
203
123
|
function subagentFromInput(
|
|
204
124
|
toolName: string,
|
|
@@ -223,6 +143,8 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
223
143
|
private blocks = new Map<number, BlockEntry>();
|
|
224
144
|
/** Tool parts by tool_use_id, so a later tool_result can complete them. */
|
|
225
145
|
private readonly toolPartsById = new Map<string, ToolPart>();
|
|
146
|
+
/** The input a still-streaming tool runs with, from its complete message (`completeToolInputs`). */
|
|
147
|
+
private readonly completeInputs = new Map<string, Record<string, unknown>>();
|
|
226
148
|
private currentParent?: string;
|
|
227
149
|
/**
|
|
228
150
|
* Set by ANY stream_event in this turn (the transformer is per-turn). When
|
|
@@ -233,78 +155,48 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
233
155
|
* first assistant) double-emits text when a message mixes text + tool_use.
|
|
234
156
|
*/
|
|
235
157
|
private hasStreamed = false;
|
|
236
|
-
|
|
237
|
-
private
|
|
238
|
-
private readonly
|
|
239
|
-
private
|
|
240
|
-
private finishReason?: string;
|
|
241
|
-
private cost?: number;
|
|
242
|
-
private error?: string;
|
|
243
|
-
private interrupted = false;
|
|
244
|
-
private execFailure = false;
|
|
245
|
-
private succeeded = false;
|
|
158
|
+
/** What the session said the coming result's query spent. */
|
|
159
|
+
private settled?: ClaudeQuerySettled;
|
|
160
|
+
private readonly usage = new ClaudeTurnUsage();
|
|
161
|
+
private readonly outcome = new ClaudeTurnOutcome();
|
|
246
162
|
|
|
247
163
|
constructor(ctx: { sessionId: string }) {
|
|
248
164
|
this.ctx = { sessionId: ctx.sessionId, messageId: "" };
|
|
249
165
|
}
|
|
250
166
|
|
|
251
167
|
process(raw: unknown): AdapterEvent[] {
|
|
252
|
-
|
|
253
|
-
|
|
168
|
+
// Registration is untyped (`AdapterFactory`); the Claude agent yields these.
|
|
169
|
+
const event = raw as ClaudeRawEvent;
|
|
170
|
+
switch (event.type) {
|
|
254
171
|
case "stream_event":
|
|
255
|
-
return this.handleStream(
|
|
172
|
+
return this.handleStream(event.event, event.parent_tool_use_id ?? undefined);
|
|
256
173
|
case "assistant":
|
|
257
|
-
return this.handleAssistant(
|
|
174
|
+
return this.handleAssistant(event);
|
|
258
175
|
case "user":
|
|
259
|
-
return this.handleToolResults(
|
|
176
|
+
return this.handleToolResults(event.message?.content);
|
|
177
|
+
case "agentServer/querySettled":
|
|
178
|
+
this.settled = event;
|
|
179
|
+
return [];
|
|
260
180
|
case "result":
|
|
261
|
-
return this.captureResult(
|
|
262
|
-
case "
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
this.
|
|
181
|
+
return this.captureResult(event);
|
|
182
|
+
case "agentServer/turnInterrupted":
|
|
183
|
+
// An interrupt WAS requested for this turn (it arrives after the
|
|
184
|
+
// result, so the outcome decides in finish()).
|
|
185
|
+
this.outcome.interrupt();
|
|
266
186
|
return [];
|
|
187
|
+
case "agentServer/steerRead":
|
|
188
|
+
return [{ kind: "steer-inserted", steerId: event.steerId }];
|
|
189
|
+
case "rate_limit_event":
|
|
190
|
+
return this.outcome.limits(event.rate_limit_info);
|
|
267
191
|
case "system":
|
|
268
|
-
|
|
269
|
-
const meta = msg.compact_metadata ?? {};
|
|
270
|
-
return [
|
|
271
|
-
{
|
|
272
|
-
kind: "compacted",
|
|
273
|
-
trigger: meta.trigger,
|
|
274
|
-
preTokens: meta.pre_tokens,
|
|
275
|
-
postTokens: meta.post_tokens,
|
|
276
|
-
},
|
|
277
|
-
];
|
|
278
|
-
}
|
|
279
|
-
return [];
|
|
192
|
+
return this.handleSystem(event);
|
|
280
193
|
default:
|
|
281
194
|
return [];
|
|
282
195
|
}
|
|
283
196
|
}
|
|
284
197
|
|
|
285
198
|
finish(): TransformResult {
|
|
286
|
-
|
|
287
|
-
// error_during_execution and the stop reason of the step it aborted (null
|
|
288
|
-
// while streaming, "tool_use" while a tool runs), or with no result when
|
|
289
|
-
// the process was stopped first. Without an interrupt, error_during_execution
|
|
290
|
-
// is a real failure (a silent "cancelled" here is how a bad resume id used
|
|
291
|
-
// to vanish without a trace).
|
|
292
|
-
const cancelled = this.interrupted && !this.succeeded;
|
|
293
|
-
const error = cancelled
|
|
294
|
-
? undefined
|
|
295
|
-
: (this.error ??
|
|
296
|
-
(this.execFailure
|
|
297
|
-
? "Claude turn failed during execution (error_during_execution — e.g. an invalid resumeSessionId fails this way)"
|
|
298
|
-
: undefined));
|
|
299
|
-
return {
|
|
300
|
-
usage: this.usage,
|
|
301
|
-
...(this.reportedModels.size && { reportedModels: [...this.reportedModels] }),
|
|
302
|
-
stopReason: this.stopReason,
|
|
303
|
-
finishReason: this.finishReason,
|
|
304
|
-
cost: this.cost,
|
|
305
|
-
error,
|
|
306
|
-
cancelled,
|
|
307
|
-
};
|
|
199
|
+
return { ...this.usage.summary(), ...this.outcome.finish() };
|
|
308
200
|
}
|
|
309
201
|
|
|
310
202
|
private ctxFor(): StreamContext {
|
|
@@ -314,45 +206,106 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
314
206
|
return { ...this.ctx, ...(this.currentParent ? { parentToolCallId: this.currentParent } : {}) };
|
|
315
207
|
}
|
|
316
208
|
|
|
209
|
+
private handleSystem(event: SystemMessage): AdapterEvent[] {
|
|
210
|
+
switch (event.subtype) {
|
|
211
|
+
case "init":
|
|
212
|
+
if (typeof event.model === "string") this.usage.requested(event.model);
|
|
213
|
+
return [];
|
|
214
|
+
case "api_retry": {
|
|
215
|
+
const message = `Claude API ${event.error_status ? `error ${event.error_status}` : "connection failed"}${event.error ? ` (${event.error})` : ""}`;
|
|
216
|
+
return [
|
|
217
|
+
{
|
|
218
|
+
kind: "retry",
|
|
219
|
+
category:
|
|
220
|
+
claudeErrorCategory(event.error, event.error_status) ?? classifyError(message),
|
|
221
|
+
message,
|
|
222
|
+
...(event.attempt !== undefined && { attempt: event.attempt }),
|
|
223
|
+
...(event.max_retries !== undefined && { maxAttempts: event.max_retries }),
|
|
224
|
+
...(event.retry_delay_ms !== undefined && { delayMs: event.retry_delay_ms }),
|
|
225
|
+
},
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
case "status": {
|
|
229
|
+
// Claude reports its mode when it changes: an approved plan, or
|
|
230
|
+
// Claude entering plan mode by itself.
|
|
231
|
+
const permissionMode = fromSdkPermissionMode(event.permissionMode);
|
|
232
|
+
return permissionMode ? [{ kind: "mode", permissionMode }] : [];
|
|
233
|
+
}
|
|
234
|
+
case "compact_boundary":
|
|
235
|
+
return [
|
|
236
|
+
{
|
|
237
|
+
kind: "compacted",
|
|
238
|
+
trigger: event.compact_metadata?.trigger,
|
|
239
|
+
preTokens: event.compact_metadata?.pre_tokens,
|
|
240
|
+
postTokens: event.compact_metadata?.post_tokens,
|
|
241
|
+
},
|
|
242
|
+
];
|
|
243
|
+
default:
|
|
244
|
+
return [];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
317
248
|
/**
|
|
318
249
|
* Fallback for messages delivered without streaming (notably some sub-agent
|
|
319
250
|
* paths). If the in-flight message already streamed, its parts are live —
|
|
320
251
|
* skip the duplicate. Otherwise emit its content blocks as finalized parts.
|
|
321
252
|
*/
|
|
322
|
-
private handleAssistant(msg:
|
|
323
|
-
|
|
324
|
-
//
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
253
|
+
private handleAssistant(msg: SDKAssistantMessage): AdapterEvent[] {
|
|
254
|
+
const parent = msg.parent_tool_use_id ?? undefined;
|
|
255
|
+
// The model that wrote it: none for Claude Code's own message.
|
|
256
|
+
const model = msg.message?.model !== SYNTHETIC_MODEL ? msg.message?.model : undefined;
|
|
257
|
+
// The turn's own failure, and its gauge: a sub-agent's are its own.
|
|
258
|
+
if (!parent && msg.error) this.outcome.requestFailed(msg.error);
|
|
259
|
+
const gauge = parent ? [] : this.usage.message(model, msg.message?.usage);
|
|
260
|
+
// Claude Code's own failure text (a sign-in or billing error) arrives as a
|
|
261
|
+
// synthetic assistant message: it is not the agent's reply, and the turn's
|
|
262
|
+
// error already carries it. Truncated output (`max_output_tokens`) is the
|
|
263
|
+
// model's own and stays.
|
|
264
|
+
if (msg.error && msg.message?.model === SYNTHETIC_MODEL) return gauge;
|
|
330
265
|
// Streaming already emitted this content live via stream_event deltas; the
|
|
331
266
|
// trailing complete snapshot would duplicate it. Skip — except sub-agent
|
|
332
|
-
// replies (parent_tool_use_id), which never stream and arrive only here
|
|
333
|
-
|
|
334
|
-
|
|
267
|
+
// replies (parent_tool_use_id), which never stream and arrive only here,
|
|
268
|
+
// and tool input the stream never carried.
|
|
269
|
+
if (this.hasStreamed && !parent)
|
|
270
|
+
return [...gauge, ...this.completeToolInputs(msg.message?.content)];
|
|
271
|
+
const parts = this.partsOf(msg.message?.content, parent);
|
|
272
|
+
// Nothing to show opens no message.
|
|
273
|
+
if (!parts.length) return gauge;
|
|
274
|
+
// Each message names the model that wrote it: a sub-agent's (its message
|
|
275
|
+
// nests under the tool call that spawned it), or a top-level message
|
|
276
|
+
// that arrived whole, which opens its own wire message.
|
|
277
|
+
const opening: AdapterEvent[] = parent
|
|
278
|
+
? model
|
|
279
|
+
? [{ kind: "model", model, parentToolCallId: parent }]
|
|
280
|
+
: []
|
|
281
|
+
: [{ kind: "message-start", role: "assistant", ...(model && { model }) }];
|
|
282
|
+
return [...gauge, ...opening, ...parts];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** A complete message's content blocks as finalized parts, under `parent`'s tool call. */
|
|
286
|
+
private partsOf(content: ContentBlock[] | undefined, parent: string | undefined): AdapterEvent[] {
|
|
335
287
|
if (!Array.isArray(content)) return [];
|
|
336
288
|
const prevParent = this.currentParent;
|
|
337
|
-
this.currentParent =
|
|
289
|
+
this.currentParent = parent;
|
|
338
290
|
const events: AdapterEvent[] = [];
|
|
339
291
|
for (const block of content) {
|
|
340
292
|
if (block.type === "text" && block.text) {
|
|
341
293
|
events.push({ kind: "part-open", part: createTextPart(this.ctxFor(), block.text, false) });
|
|
342
294
|
} else if (block.type === "thinking" || block.type === "redacted_thinking") {
|
|
295
|
+
const thinking = block.type === "thinking" ? block.thinking : "";
|
|
343
296
|
const redacted = block.type === "redacted_thinking";
|
|
344
297
|
// A redacted block carries no plaintext (its `data` is an encrypted
|
|
345
298
|
// blob), so emit it on the flag alone — the redaction is the signal.
|
|
346
|
-
if (!
|
|
299
|
+
if (!thinking && !redacted) continue;
|
|
347
300
|
// A complete block opens and closes at once: one stamp for both ends.
|
|
348
301
|
const now = Date.now();
|
|
349
|
-
const part = createReasoningPart(this.ctxFor(),
|
|
302
|
+
const part = createReasoningPart(this.ctxFor(), thinking, false);
|
|
350
303
|
part.time = { start: now, end: now };
|
|
351
304
|
if (redacted) part.providerMetadata = { redacted: true };
|
|
352
305
|
events.push({ kind: "part-open", part });
|
|
353
306
|
} else if (block.type === "tool_use" && block.id) {
|
|
354
307
|
const name = block.name ?? "tool";
|
|
355
|
-
const input = block.input
|
|
308
|
+
const input = isRecord(block.input) ? block.input : {};
|
|
356
309
|
const subagent = subagentFromInput(name, input);
|
|
357
310
|
const part = createToolPart(this.ctxFor(), block.id, name, input, {
|
|
358
311
|
...claudeToolMeta(name, input),
|
|
@@ -363,7 +316,7 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
363
316
|
}
|
|
364
317
|
}
|
|
365
318
|
this.currentParent = prevParent;
|
|
366
|
-
return
|
|
319
|
+
return events;
|
|
367
320
|
}
|
|
368
321
|
|
|
369
322
|
private handleStream(event: StreamEvent, parentToolCallId?: string): AdapterEvent[] {
|
|
@@ -376,7 +329,14 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
376
329
|
this.currentParent = parentToolCallId;
|
|
377
330
|
// Each top-level model message becomes a wire message. Sub-agent
|
|
378
331
|
// messages don't open one — their parts nest via parentToolCallId.
|
|
379
|
-
|
|
332
|
+
if (parentToolCallId) return [];
|
|
333
|
+
return [
|
|
334
|
+
{
|
|
335
|
+
kind: "message-start",
|
|
336
|
+
role: "assistant",
|
|
337
|
+
...(event.message?.model && { model: event.message.model }),
|
|
338
|
+
},
|
|
339
|
+
];
|
|
380
340
|
case "content_block_start":
|
|
381
341
|
return this.openBlock(event);
|
|
382
342
|
case "content_block_delta":
|
|
@@ -385,8 +345,8 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
385
345
|
return this.closeBlock(event);
|
|
386
346
|
case "message_delta":
|
|
387
347
|
if (typeof event.delta?.stop_reason === "string")
|
|
388
|
-
this.
|
|
389
|
-
if (event.usage?.output_tokens) this.usage.
|
|
348
|
+
this.outcome.messageStopped(event.delta.stop_reason);
|
|
349
|
+
if (event.usage?.output_tokens) this.usage.streamed(event.usage.output_tokens);
|
|
390
350
|
return [];
|
|
391
351
|
case "message_stop":
|
|
392
352
|
return parentToolCallId || this.currentParent ? [] : [{ kind: "message-end" }];
|
|
@@ -395,7 +355,7 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
395
355
|
}
|
|
396
356
|
}
|
|
397
357
|
|
|
398
|
-
private openBlock(event: StreamEvent): AdapterEvent[] {
|
|
358
|
+
private openBlock(event: Extract<StreamEvent, { type: "content_block_start" }>): AdapterEvent[] {
|
|
399
359
|
const index = event.index ?? 0;
|
|
400
360
|
const cb = event.content_block;
|
|
401
361
|
if (!cb) return [];
|
|
@@ -424,7 +384,7 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
424
384
|
return [];
|
|
425
385
|
}
|
|
426
386
|
|
|
427
|
-
private deltaBlock(event: StreamEvent): AdapterEvent[] {
|
|
387
|
+
private deltaBlock(event: Extract<StreamEvent, { type: "content_block_delta" }>): AdapterEvent[] {
|
|
428
388
|
const entry = this.blocks.get(event.index ?? 0);
|
|
429
389
|
const d = event.delta;
|
|
430
390
|
if (!entry || !d) return [];
|
|
@@ -462,7 +422,30 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
462
422
|
return [];
|
|
463
423
|
}
|
|
464
424
|
|
|
465
|
-
|
|
425
|
+
/**
|
|
426
|
+
* Claude Code can fill a tool's input after the model streamed it: the model
|
|
427
|
+
* calls ExitPlanMode with nothing, and the CLI adds the plan from its plan
|
|
428
|
+
* file (`plan`, `planFilePath`). The complete message holds the input the
|
|
429
|
+
* tool runs with. It usually arrives before its block's stop event (Claude
|
|
430
|
+
* Code 0.3.288), which then takes it; a tool already running takes it here.
|
|
431
|
+
*/
|
|
432
|
+
private completeToolInputs(content: ContentBlock[] | undefined): AdapterEvent[] {
|
|
433
|
+
const events: AdapterEvent[] = [];
|
|
434
|
+
for (const block of Array.isArray(content) ? content : []) {
|
|
435
|
+
if (block.type !== "tool_use" || !block.id || !isRecord(block.input)) continue;
|
|
436
|
+
const tool = this.toolPartsById.get(block.id);
|
|
437
|
+
// The message comes before its block's stop event: the stop takes it.
|
|
438
|
+
if (tool?.state.status === "pending") this.completeInputs.set(block.id, block.input);
|
|
439
|
+
if (tool?.state.status !== "in_progress") continue;
|
|
440
|
+
if (JSON.stringify(tool.state.input) === JSON.stringify(block.input)) continue;
|
|
441
|
+
tool.state = { ...tool.state, input: block.input };
|
|
442
|
+
setToolMeta(tool, claudeToolMeta(tool.toolName, block.input));
|
|
443
|
+
events.push({ kind: "part-update", part: tool });
|
|
444
|
+
}
|
|
445
|
+
return events;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
private closeBlock(event: Extract<StreamEvent, { type: "content_block_stop" }>): AdapterEvent[] {
|
|
466
449
|
const entry = this.blocks.get(event.index ?? 0);
|
|
467
450
|
if (!entry) return [];
|
|
468
451
|
if (entry.kind === "text" || entry.kind === "reasoning") {
|
|
@@ -476,7 +459,8 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
476
459
|
}
|
|
477
460
|
const tool = entry.part as ToolPart;
|
|
478
461
|
const partial = tool.state.status === "pending" ? tool.state.partialInput : "";
|
|
479
|
-
const input = safeParseJson(partial);
|
|
462
|
+
const input = this.completeInputs.get(tool.toolCallId) ?? safeParseJson(partial);
|
|
463
|
+
this.completeInputs.delete(tool.toolCallId);
|
|
480
464
|
startToolPart(tool, input);
|
|
481
465
|
// The streamed open carried no input, so subagent metadata can only be
|
|
482
466
|
// read now that the partial JSON has parsed.
|
|
@@ -488,7 +472,9 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
488
472
|
return [{ kind: "part-update", part: tool }];
|
|
489
473
|
}
|
|
490
474
|
|
|
491
|
-
private handleToolResults(
|
|
475
|
+
private handleToolResults(
|
|
476
|
+
content: Extract<SDKMessage, { type: "user" }>["message"]["content"] | undefined,
|
|
477
|
+
): AdapterEvent[] {
|
|
492
478
|
if (!Array.isArray(content)) return [];
|
|
493
479
|
const events: AdapterEvent[] = [];
|
|
494
480
|
for (const block of content) {
|
|
@@ -506,59 +492,12 @@ export class ClaudeCodeTransformer implements EventTransformer<unknown> {
|
|
|
506
492
|
return events;
|
|
507
493
|
}
|
|
508
494
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
output: msg.usage.output_tokens ?? this.usage.output,
|
|
516
|
-
cache: {
|
|
517
|
-
read: msg.usage.cache_read_input_tokens ?? 0,
|
|
518
|
-
write: msg.usage.cache_creation_input_tokens ?? 0,
|
|
519
|
-
...(creation?.ephemeral_5m_input_tokens !== undefined && {
|
|
520
|
-
writeEphemeral5m: creation.ephemeral_5m_input_tokens,
|
|
521
|
-
}),
|
|
522
|
-
...(creation?.ephemeral_1h_input_tokens !== undefined && {
|
|
523
|
-
writeEphemeral1h: creation.ephemeral_1h_input_tokens,
|
|
524
|
-
}),
|
|
525
|
-
},
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
this.cost = "turn_cost_usd" in msg ? (msg.turn_cost_usd ?? undefined) : msg.total_cost_usd;
|
|
529
|
-
this.finishReason = msg.stop_reason ?? msg.subtype ?? this.finishReason;
|
|
530
|
-
this.stopReason = mapClaudeStopReason(msg.stop_reason, msg.subtype);
|
|
531
|
-
if (msg.subtype && msg.subtype !== "success") {
|
|
532
|
-
if (msg.subtype === "error_during_execution" && msg.stop_reason === null) {
|
|
533
|
-
// Ambiguous shape: an interrupt AND an execution failure (e.g. a bad
|
|
534
|
-
// resume id) both surface this way. The agent's `turn_interrupted`
|
|
535
|
-
// marker (which arrives after this message) disambiguates in finish(),
|
|
536
|
-
// as it does for an interrupt that aborted a tool (stop reason "tool_use").
|
|
537
|
-
this.execFailure = true;
|
|
538
|
-
} else if (msg.subtype === "error_max_turns") {
|
|
539
|
-
// Hitting the turn budget is a stop condition, not a failure.
|
|
540
|
-
} else {
|
|
541
|
-
this.error = `Claude turn ended: ${msg.subtype}`;
|
|
542
|
-
}
|
|
543
|
-
} else if (msg.is_error) {
|
|
544
|
-
// A failed API call (a rejected key, an exhausted quota, an overloaded
|
|
545
|
-
// provider) ends the turn as a "success" whose text is the error. The
|
|
546
|
-
// text names the failure, so the runtime classifies it (401 -> auth).
|
|
547
|
-
this.error = msg.result || "Claude turn ended with an API error";
|
|
548
|
-
}
|
|
549
|
-
// Final authoritative gauge: the result knows the context-window size.
|
|
550
|
-
if (!msg.usage) return [];
|
|
551
|
-
const size = Object.values(msg.modelUsage ?? {})
|
|
552
|
-
.map((m) => m.contextWindow ?? 0)
|
|
553
|
-
.reduce((a, b) => Math.max(a, b), 0);
|
|
554
|
-
return [
|
|
555
|
-
{
|
|
556
|
-
kind: "usage",
|
|
557
|
-
used: contextTokens(msg.usage),
|
|
558
|
-
...(size > 0 && { size }),
|
|
559
|
-
...(this.cost !== undefined && { cost: this.cost }),
|
|
560
|
-
},
|
|
561
|
-
];
|
|
495
|
+
/** A query's result: the session's word on what it spent came just before. */
|
|
496
|
+
private captureResult(result: SDKResultMessage): AdapterEvent[] {
|
|
497
|
+
const settled = this.settled;
|
|
498
|
+
this.settled = undefined;
|
|
499
|
+
this.outcome.settle(result, settled?.steersPending === true);
|
|
500
|
+
return this.usage.settle(result, settled);
|
|
562
501
|
}
|
|
563
502
|
}
|
|
564
503
|
|