@zvada/agent-server 0.3.22 → 0.3.24
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/CHANGELOG.md +295 -0
- package/README.md +14 -5
- package/dist/accounts/chatgpt.js +144 -0
- package/dist/accounts/check.js +71 -0
- package/dist/accounts/claude.js +80 -0
- package/dist/accounts/endpoint.js +104 -0
- package/dist/accounts/http.js +58 -0
- package/dist/accounts/index.js +9 -0
- package/dist/client/client.js +686 -0
- package/dist/client/connection.js +338 -0
- package/dist/client/history.js +49 -0
- package/dist/client/index.js +6 -0
- package/dist/client/listeners.js +19 -0
- package/dist/client/logins.js +92 -0
- package/dist/client/rpc.js +105 -0
- package/dist/client/streams.js +432 -0
- package/dist/client/transports.js +118 -0
- package/dist/client/turns.js +122 -0
- package/dist/core/agents/acp/acp-agent.js +425 -0
- package/dist/core/agents/acp/adapter.js +231 -0
- package/dist/core/agents/acp/client.js +222 -0
- package/dist/core/agents/acp/known-agents.js +57 -0
- package/dist/core/agents/acp/mappings.js +164 -0
- package/dist/core/agents/acp/requests.js +79 -0
- package/dist/core/agents/attachments.js +14 -0
- package/dist/core/agents/base.js +64 -0
- package/dist/core/agents/claude-code/adapter.js +474 -0
- package/dist/core/agents/claude-code/approvals.js +245 -0
- package/dist/core/agents/claude-code/claude-agent.js +319 -0
- package/dist/core/agents/claude-code/credentials.js +142 -0
- package/dist/core/agents/claude-code/events.js +11 -0
- package/dist/core/agents/claude-code/login.js +217 -0
- package/dist/core/agents/claude-code/mcp.js +181 -0
- package/dist/core/agents/claude-code/models.js +74 -0
- package/dist/core/agents/claude-code/options.js +240 -0
- package/dist/core/agents/claude-code/outcome.js +204 -0
- package/dist/core/agents/claude-code/results.js +58 -0
- package/dist/core/agents/claude-code/sdk-pair.js +59 -0
- package/dist/core/agents/claude-code/session.js +593 -0
- package/dist/core/agents/claude-code/spawn.js +125 -0
- package/dist/core/agents/claude-code/spend.js +118 -0
- package/dist/core/agents/claude-code/tools.js +131 -0
- package/dist/core/agents/claude-code/turn-usage.js +121 -0
- package/dist/core/agents/claude-code/turn.js +199 -0
- package/dist/core/agents/codex-app-server/adapter.js +463 -0
- package/dist/core/agents/codex-app-server/client.js +338 -0
- package/dist/core/agents/codex-app-server/codex-agent.js +294 -0
- package/dist/core/agents/codex-app-server/commands.js +184 -0
- package/dist/core/agents/codex-app-server/credentials.js +92 -0
- package/dist/core/agents/codex-app-server/effort.js +13 -0
- package/dist/core/agents/codex-app-server/events.js +18 -0
- package/dist/core/agents/codex-app-server/homes.js +118 -0
- package/dist/core/agents/codex-app-server/input.js +52 -0
- package/dist/core/agents/codex-app-server/items.js +307 -0
- package/dist/core/agents/codex-app-server/login.js +183 -0
- package/dist/core/agents/codex-app-server/mcp.js +323 -0
- package/dist/core/agents/codex-app-server/models.js +160 -0
- package/dist/core/agents/codex-app-server/options.js +155 -0
- package/dist/core/agents/codex-app-server/plan-approval.js +124 -0
- package/dist/core/agents/codex-app-server/protocol.js +38 -0
- package/dist/core/agents/codex-app-server/requests.js +250 -0
- package/dist/core/agents/codex-app-server/session.js +278 -0
- package/dist/core/agents/codex-app-server/subagents.js +260 -0
- package/dist/core/agents/codex-app-server/thread-settings.js +214 -0
- package/dist/core/agents/codex-app-server/turn-items.js +69 -0
- package/dist/core/agents/codex-app-server/turn.js +448 -0
- package/dist/core/agents/codex-app-server/user-login.js +78 -0
- package/dist/core/agents/config-fingerprint.js +10 -0
- package/dist/core/agents/credentials.js +71 -0
- package/dist/core/agents/diffs.js +27 -0
- package/dist/core/agents/elicitation.js +42 -0
- package/dist/core/agents/inherit-config.js +5 -0
- package/dist/core/agents/login.js +56 -0
- package/dist/core/agents/mcp-config.js +109 -0
- package/dist/core/agents/plan.js +6 -0
- package/dist/core/agents/process-pool.js +307 -0
- package/dist/core/agents/registry.js +49 -0
- package/dist/core/agents/scripted/adapter.js +86 -0
- package/dist/core/agents/scripted/mcp-call.js +74 -0
- package/dist/core/agents/scripted/scripted-agent.js +330 -0
- package/dist/core/agents/scripted/scripts.js +154 -0
- package/dist/core/agents/scripted/steps.js +87 -0
- package/dist/core/agents/session-agent.js +209 -0
- package/dist/core/agents/stderr-tail.js +71 -0
- package/dist/core/agents/thinking-levels.js +9 -0
- package/dist/core/agents/types.js +1 -0
- package/dist/core/diagnostics.js +23 -0
- package/dist/core/index.js +31 -0
- package/dist/core/presets.js +114 -0
- package/dist/core/processes/identity.js +91 -0
- package/dist/core/processes/lifeline.js +210 -0
- package/dist/core/processes/native-processes.js +299 -0
- package/dist/core/processes/process-table.js +163 -0
- package/dist/core/provision/cache-trust.js +121 -0
- package/dist/core/provision/cache-usage.js +61 -0
- package/dist/core/provision/checksums.js +22 -0
- package/dist/core/provision/extract.js +28 -0
- package/dist/core/provision/index.js +4 -0
- package/dist/core/provision/install-build.js +99 -0
- package/dist/core/provision/npm.js +316 -0
- package/dist/core/provision/pins.js +35 -0
- package/dist/core/provision/platform.js +65 -0
- package/dist/core/provision/provisioner.js +372 -0
- package/dist/core/provision/releases.js +68 -0
- package/dist/core/provision/tools.js +279 -0
- package/dist/core/proxy/anthropic-proxy.js +163 -0
- package/dist/core/proxy/api-key-store.js +30 -0
- package/dist/core/proxy/index.js +3 -0
- package/dist/core/proxy/loopback.js +86 -0
- package/dist/core/runtime/agent-runtime.js +434 -0
- package/dist/core/runtime/event-processor.js +379 -0
- package/dist/core/runtime/event-sink.js +65 -0
- package/dist/core/runtime/harness-clis.js +83 -0
- package/dist/core/runtime/harness-logins.js +313 -0
- package/dist/core/runtime/login-reads.js +71 -0
- package/dist/core/runtime/model-lists.js +160 -0
- package/dist/core/runtime/permission-policy.js +84 -0
- package/dist/core/runtime/request-broker.js +139 -0
- package/dist/core/runtime/steering.js +79 -0
- package/dist/core/runtime/turn-outcome.js +16 -0
- package/dist/core/runtime/turn.js +329 -0
- package/dist/core/utils/bounded.js +13 -0
- package/dist/core/utils/deadline.js +57 -0
- package/dist/core/utils/errors.js +176 -0
- package/dist/core/utils/is-record.js +4 -0
- package/dist/core/utils/loopback.js +11 -0
- package/dist/index.js +4 -0
- package/dist/operator/index.js +10 -0
- package/dist/operator/mcp.js +139 -0
- package/dist/operator/operator.js +499 -0
- package/dist/operator/render.js +408 -0
- package/dist/operator/view.js +35 -0
- package/dist/protocol/account.js +96 -0
- package/dist/protocol/async-queue.js +65 -0
- package/dist/protocol/auth.js +169 -0
- package/dist/protocol/canonical.js +18 -0
- package/dist/protocol/clis.js +63 -0
- package/dist/protocol/config.js +137 -0
- package/dist/protocol/conversation.js +231 -0
- package/dist/protocol/credentials.js +141 -0
- package/dist/protocol/errors.js +181 -0
- package/dist/protocol/execution.js +28 -0
- package/dist/protocol/factories.js +231 -0
- package/dist/protocol/guards.js +71 -0
- package/dist/protocol/harness.js +93 -0
- package/dist/protocol/history.js +201 -0
- package/dist/protocol/ids.js +37 -0
- package/dist/protocol/index.js +36 -0
- package/dist/protocol/lifecycle.js +562 -0
- package/dist/protocol/meta-keys.js +17 -0
- package/dist/protocol/meta.js +13 -0
- package/dist/protocol/model-catalog.js +223 -0
- package/dist/protocol/models.js +84 -0
- package/dist/protocol/part-input.js +94 -0
- package/dist/protocol/parts.js +166 -0
- package/dist/protocol/plan.js +31 -0
- package/dist/protocol/reduce.js +484 -0
- package/dist/protocol/selectors.js +136 -0
- package/dist/protocol/seq-cursor.js +37 -0
- package/dist/protocol/stop-reasons.js +41 -0
- package/dist/protocol/thinking.js +31 -0
- package/dist/protocol/time.js +21 -0
- package/dist/protocol/tokens.js +57 -0
- package/dist/protocol/tool-closure.js +70 -0
- package/dist/protocol/tool-state.js +153 -0
- package/dist/protocol/verify.js +467 -0
- package/dist/protocol/vocabulary.js +27 -0
- package/dist/protocol/wire-api.js +94 -0
- package/dist/protocol/wire.js +669 -0
- package/dist/server/acp/binding.js +251 -0
- package/dist/server/acp/session-records.js +53 -0
- package/dist/server/acp/translate.js +401 -0
- package/dist/server/agent-server.js +338 -0
- package/dist/server/bin.js +492 -0
- package/dist/server/feedback.js +216 -0
- package/dist/server/history.js +123 -0
- package/dist/server/index.js +8 -0
- package/dist/server/install.js +171 -0
- package/dist/server/open-parts.js +87 -0
- package/dist/server/routes.js +291 -0
- package/dist/server/secrets.js +19 -0
- package/dist/server/session-gate.js +54 -0
- package/dist/server/session-log.js +66 -0
- package/dist/server/session-store.js +243 -0
- package/dist/server/subscriptions.js +189 -0
- package/dist/server/transports.js +214 -0
- package/dist/server/wire-error.js +26 -0
- package/dist/sync/event-log.js +89 -0
- package/dist/sync/fit.js +202 -0
- package/dist/sync/history-reader.js +33 -0
- package/dist/sync/history-sqlite.js +281 -0
- package/dist/sync/history.js +163 -0
- package/dist/sync/index.js +5 -0
- package/dist/sync/journal-sqlite.js +316 -0
- package/dist/sync/journal.js +10 -0
- package/dist/sync/live-tails.js +85 -0
- package/dist/sync/node-sqlite.js +27 -0
- package/dist/sync/projection.js +32 -0
- package/dist/sync/recovery.js +117 -0
- package/dist/sync/retry.js +45 -0
- package/dist/sync/schema.js +73 -0
- package/dist/sync/sql.js +94 -0
- package/dist/sync/sqlite-file.js +31 -0
- package/dist/sync/sqlite.js +18 -0
- package/dist/sync/worker.js +212 -0
- package/dist/types/accounts/chatgpt.d.ts +1 -1
- package/dist/types/accounts/chatgpt.d.ts.map +1 -1
- package/dist/types/accounts/http.d.ts +2 -4
- package/dist/types/accounts/http.d.ts.map +1 -1
- package/dist/types/client/client.d.ts +37 -11
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/connection.d.ts +64 -13
- package/dist/types/client/connection.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/logins.d.ts +2 -1
- package/dist/types/client/logins.d.ts.map +1 -1
- package/dist/types/client/streams.d.ts +9 -3
- package/dist/types/client/streams.d.ts.map +1 -1
- package/dist/types/client/turns.d.ts +1 -1
- package/dist/types/client/turns.d.ts.map +1 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/acp/client.d.ts +12 -3
- package/dist/types/core/agents/acp/client.d.ts.map +1 -1
- package/dist/types/core/agents/acp/mappings.d.ts +8 -2
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
- package/dist/types/core/agents/base.d.ts +22 -8
- package/dist/types/core/agents/base.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +19 -5
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/events.d.ts +9 -1
- package/dist/types/core/agents/claude-code/events.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/login.d.ts +4 -1
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/mcp.d.ts +21 -7
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/models.d.ts +5 -1
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/options.d.ts +29 -10
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/outcome.d.ts +3 -5
- package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/results.d.ts +16 -0
- package/dist/types/core/agents/claude-code/results.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/sdk-pair.d.ts +13 -0
- package/dist/types/core/agents/claude-code/sdk-pair.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session.d.ts +58 -12
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/spend.d.ts +2 -1
- package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/tools.d.ts +26 -3
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/adapter.d.ts +2 -2
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/client.d.ts +12 -2
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +58 -13
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/homes.d.ts +25 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts +16 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +15 -30
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/options.d.ts +27 -4
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/session.d.ts +71 -40
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn.d.ts +31 -8
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
- package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +3 -1
- package/dist/types/core/agents/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/diffs.d.ts +9 -0
- package/dist/types/core/agents/diffs.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +3 -2
- package/dist/types/core/agents/elicitation.d.ts.map +1 -1
- package/dist/types/core/agents/login.d.ts +6 -0
- package/dist/types/core/agents/login.d.ts.map +1 -1
- package/dist/types/core/agents/mcp-config.d.ts +0 -4
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
- package/dist/types/core/agents/process-pool.d.ts +201 -0
- package/dist/types/core/agents/process-pool.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/adapter.d.ts +68 -0
- package/dist/types/core/agents/scripted/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/mcp-call.d.ts +56 -0
- package/dist/types/core/agents/scripted/mcp-call.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/scripted-agent.d.ts +73 -0
- package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/scripts.d.ts +29 -0
- package/dist/types/core/agents/scripted/scripts.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/steps.d.ts +132 -0
- package/dist/types/core/agents/scripted/steps.d.ts.map +1 -0
- package/dist/types/core/agents/session-agent.d.ts +49 -6
- package/dist/types/core/agents/session-agent.d.ts.map +1 -1
- package/dist/types/core/diagnostics.d.ts +4 -1
- package/dist/types/core/diagnostics.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +5 -0
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/presets.d.ts +32 -6
- package/dist/types/core/presets.d.ts.map +1 -1
- package/dist/types/core/processes/lifeline.d.ts +0 -20
- package/dist/types/core/processes/lifeline.d.ts.map +1 -1
- package/dist/types/core/provision/index.d.ts +2 -2
- package/dist/types/core/provision/index.d.ts.map +1 -1
- package/dist/types/core/provision/install-build.d.ts +2 -1
- package/dist/types/core/provision/install-build.d.ts.map +1 -1
- package/dist/types/core/provision/npm.d.ts +20 -8
- package/dist/types/core/provision/npm.d.ts.map +1 -1
- package/dist/types/core/provision/provisioner.d.ts +4 -1
- package/dist/types/core/provision/provisioner.d.ts.map +1 -1
- package/dist/types/core/provision/tools.d.ts +2 -1
- package/dist/types/core/provision/tools.d.ts.map +1 -1
- package/dist/types/core/runtime/agent-runtime.d.ts +16 -8
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/types/core/runtime/event-processor.d.ts +5 -1
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-clis.d.ts +9 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-logins.d.ts +33 -5
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
- package/dist/types/core/runtime/model-lists.d.ts +2 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
- package/dist/types/core/runtime/permission-policy.d.ts +5 -3
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
- package/dist/types/core/runtime/request-broker.d.ts +2 -1
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
- package/dist/types/core/runtime/turn.d.ts +12 -1
- package/dist/types/core/runtime/turn.d.ts.map +1 -1
- package/dist/types/core/utils/deadline.d.ts +6 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -1
- package/dist/types/core/utils/errors.d.ts +7 -1
- package/dist/types/core/utils/errors.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/render.d.ts +6 -4
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/protocol/auth.d.ts +54 -24
- package/dist/types/protocol/auth.d.ts.map +1 -1
- package/dist/types/protocol/clis.d.ts +14 -7
- package/dist/types/protocol/clis.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +2 -0
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +40 -3
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/credentials.d.ts +7 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -1
- package/dist/types/protocol/execution.d.ts +2 -1
- package/dist/types/protocol/execution.d.ts.map +1 -1
- package/dist/types/protocol/factories.d.ts +12 -2
- package/dist/types/protocol/factories.d.ts.map +1 -1
- package/dist/types/protocol/harness.d.ts +6 -2
- package/dist/types/protocol/harness.d.ts.map +1 -1
- package/dist/types/protocol/history.d.ts +19 -0
- package/dist/types/protocol/history.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +47 -8
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/model-catalog.d.ts.map +1 -1
- package/dist/types/protocol/models.d.ts +3 -0
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/parts.d.ts +14 -0
- package/dist/types/protocol/parts.d.ts.map +1 -1
- package/dist/types/protocol/tool-state.d.ts +12 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +129 -23
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +70 -10
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/dist/types/server/acp/binding.d.ts +6 -1
- package/dist/types/server/acp/binding.d.ts.map +1 -1
- package/dist/types/server/acp/translate.d.ts +33 -7
- package/dist/types/server/acp/translate.d.ts.map +1 -1
- package/dist/types/server/agent-server.d.ts +6 -0
- package/dist/types/server/agent-server.d.ts.map +1 -1
- package/dist/types/server/bin.d.ts +3 -0
- package/dist/types/server/bin.d.ts.map +1 -0
- package/dist/types/server/feedback.d.ts +2 -1
- package/dist/types/server/feedback.d.ts.map +1 -1
- package/dist/types/server/install.d.ts +11 -0
- package/dist/types/server/install.d.ts.map +1 -1
- package/dist/types/server/session-gate.d.ts +2 -1
- package/dist/types/server/session-gate.d.ts.map +1 -1
- package/dist/types/server/session-store.d.ts +1 -0
- package/dist/types/server/session-store.d.ts.map +1 -1
- package/dist/types/server/subscriptions.d.ts +2 -1
- package/dist/types/server/subscriptions.d.ts.map +1 -1
- package/dist/types/server/transports.d.ts +2 -1
- package/dist/types/server/transports.d.ts.map +1 -1
- package/dist/types/sync/fit.d.ts +8 -7
- package/dist/types/sync/fit.d.ts.map +1 -1
- package/dist/types/sync/history-sqlite.d.ts.map +1 -1
- package/dist/types/sync/index.d.ts +1 -0
- package/dist/types/sync/index.d.ts.map +1 -1
- package/dist/types/sync/journal-sqlite.d.ts +2 -1
- package/dist/types/sync/journal-sqlite.d.ts.map +1 -1
- package/dist/types/sync/journal.d.ts +11 -3
- package/dist/types/sync/journal.d.ts.map +1 -1
- package/dist/types/sync/node-sqlite.d.ts +4 -1
- package/dist/types/sync/node-sqlite.d.ts.map +1 -1
- package/dist/types/sync/projection.d.ts +6 -0
- package/dist/types/sync/projection.d.ts.map +1 -1
- package/dist/types/sync/recovery.d.ts +2 -1
- package/dist/types/sync/recovery.d.ts.map +1 -1
- package/dist/types/sync/schema.d.ts +10 -0
- package/dist/types/sync/schema.d.ts.map +1 -1
- package/dist/types/sync/sql.d.ts +2 -1
- package/dist/types/sync/sql.d.ts.map +1 -1
- package/docs/consuming.md +304 -28
- package/docs/deploy.md +64 -8
- package/docs/durable-sessions.md +35 -5
- package/docs/harnesses.md +398 -25
- package/package.json +48 -18
- package/src/accounts/chatgpt.ts +2 -2
- package/src/accounts/http.ts +2 -16
- package/src/client/client.ts +92 -31
- package/src/client/connection.ts +103 -22
- package/src/client/index.ts +1 -0
- package/src/client/logins.ts +1 -1
- package/src/client/streams.ts +12 -4
- package/src/client/turns.ts +1 -1
- package/src/core/agents/acp/acp-agent.ts +181 -52
- package/src/core/agents/acp/adapter.ts +9 -1
- package/src/core/agents/acp/client.ts +16 -4
- package/src/core/agents/acp/mappings.ts +27 -0
- package/src/core/agents/base.ts +25 -10
- package/src/core/agents/claude-code/adapter.ts +47 -17
- package/src/core/agents/claude-code/approvals.ts +11 -6
- package/src/core/agents/claude-code/claude-agent.ts +89 -32
- package/src/core/agents/claude-code/events.ts +11 -1
- package/src/core/agents/claude-code/login.ts +14 -2
- package/src/core/agents/claude-code/mcp.ts +31 -15
- package/src/core/agents/claude-code/models.ts +7 -2
- package/src/core/agents/claude-code/options.ts +30 -9
- package/src/core/agents/claude-code/outcome.ts +10 -2
- package/src/core/agents/claude-code/results.ts +73 -0
- package/src/core/agents/claude-code/sdk-pair.ts +66 -0
- package/src/core/agents/claude-code/session.ts +179 -37
- package/src/core/agents/claude-code/spend.ts +1 -1
- package/src/core/agents/claude-code/tools.ts +108 -12
- package/src/core/agents/codex-app-server/adapter.ts +37 -12
- package/src/core/agents/codex-app-server/client.ts +37 -8
- package/src/core/agents/codex-app-server/codex-agent.ts +115 -50
- package/src/core/agents/codex-app-server/commands.ts +2 -2
- package/src/core/agents/codex-app-server/credentials.ts +10 -5
- package/src/core/agents/codex-app-server/effort.ts +1 -1
- package/src/core/agents/codex-app-server/homes.ts +54 -3
- package/src/core/agents/codex-app-server/items.ts +219 -31
- package/src/core/agents/codex-app-server/login.ts +44 -2
- package/src/core/agents/codex-app-server/mcp.ts +47 -32
- package/src/core/agents/codex-app-server/models.ts +9 -8
- package/src/core/agents/codex-app-server/options.ts +69 -10
- package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
- package/src/core/agents/codex-app-server/protocol.ts +14 -4
- package/src/core/agents/codex-app-server/requests.ts +17 -8
- package/src/core/agents/codex-app-server/session.ts +160 -113
- package/src/core/agents/codex-app-server/subagents.ts +21 -14
- package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
- package/src/core/agents/codex-app-server/turn-items.ts +1 -1
- package/src/core/agents/codex-app-server/turn.ts +79 -32
- package/src/core/agents/codex-app-server/user-login.ts +107 -0
- package/src/core/agents/credentials.ts +5 -2
- package/src/core/agents/diffs.ts +25 -0
- package/src/core/agents/elicitation.ts +2 -2
- package/src/core/agents/login.ts +6 -0
- package/src/core/agents/mcp-config.ts +2 -2
- package/src/core/agents/process-pool.ts +458 -0
- package/src/core/agents/scripted/adapter.ts +142 -0
- package/src/core/agents/scripted/mcp-call.ts +134 -0
- package/src/core/agents/scripted/scripted-agent.ts +418 -0
- package/src/core/agents/scripted/scripts.ts +171 -0
- package/src/core/agents/scripted/steps.ts +127 -0
- package/src/core/agents/session-agent.ts +105 -8
- package/src/core/diagnostics.ts +9 -1
- package/src/core/index.ts +11 -0
- package/src/core/presets.ts +100 -14
- package/src/core/processes/lifeline.ts +99 -25
- package/src/core/provision/index.ts +1 -2
- package/src/core/provision/install-build.ts +4 -1
- package/src/core/provision/npm.ts +309 -97
- package/src/core/provision/provisioner.ts +22 -8
- package/src/core/provision/tools.ts +44 -19
- package/src/core/runtime/agent-runtime.ts +48 -18
- package/src/core/runtime/event-processor.ts +18 -2
- package/src/core/runtime/harness-clis.ts +36 -1
- package/src/core/runtime/harness-logins.ts +82 -31
- package/src/core/runtime/model-lists.ts +1 -1
- package/src/core/runtime/permission-policy.ts +4 -3
- package/src/core/runtime/request-broker.ts +1 -1
- package/src/core/runtime/turn.ts +51 -3
- package/src/core/utils/deadline.ts +23 -0
- package/src/core/utils/errors.ts +11 -4
- package/src/operator/operator.ts +8 -4
- package/src/operator/render.ts +46 -8
- package/src/protocol/auth.ts +30 -23
- package/src/protocol/clis.ts +12 -4
- package/src/protocol/credentials.ts +19 -0
- package/src/protocol/execution.ts +5 -0
- package/src/protocol/factories.ts +25 -3
- package/src/protocol/harness.ts +11 -1
- package/src/protocol/history.ts +20 -0
- package/src/protocol/lifecycle.ts +10 -1
- package/src/protocol/model-catalog.ts +19 -8
- package/src/protocol/parts.ts +12 -1
- package/src/protocol/tool-state.ts +14 -1
- package/src/protocol/wire.ts +14 -0
- package/src/server/acp/binding.ts +113 -23
- package/src/server/acp/translate.ts +161 -8
- package/src/server/agent-server.ts +10 -1
- package/src/server/bin.ts +108 -19
- package/src/server/feedback.ts +1 -1
- package/src/server/install.ts +82 -4
- package/src/server/session-gate.ts +1 -1
- package/src/server/session-store.ts +5 -1
- package/src/server/subscriptions.ts +1 -1
- package/src/server/transports.ts +20 -1
- package/src/sync/fit.ts +115 -28
- package/src/sync/history-sqlite.ts +6 -2
- package/src/sync/index.ts +1 -0
- package/src/sync/journal-sqlite.ts +20 -2
- package/src/sync/journal.ts +10 -2
- package/src/sync/node-sqlite.ts +19 -3
- package/src/sync/projection.ts +10 -0
- package/src/sync/recovery.ts +11 -4
- package/src/sync/schema.ts +7 -5
- package/src/sync/sql.ts +1 -1
- package/dist/types/core/agents/claude-code/session-pool.d.ts +0 -36
- package/dist/types/core/agents/claude-code/session-pool.d.ts.map +0 -1
- package/dist/types/core/agents/session-pool.d.ts +0 -41
- package/dist/types/core/agents/session-pool.d.ts.map +0 -1
- package/src/core/agents/claude-code/session-pool.ts +0 -136
- package/src/core/agents/session-pool.ts +0 -111
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,300 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
A bullet says what changed for someone who uses the package, in at most four
|
|
4
|
+
lines: what is now true, and what breaks or is new for them (the names of new
|
|
5
|
+
exports, fields, options and messages), with the LLP that holds the reasoning
|
|
6
|
+
and the measurements. Evidence lives in the LLP, not here. A release groups
|
|
7
|
+
its bullets under Breaking, Added, Changed and Fixed, breaking first. The
|
|
8
|
+
released sections below that predate this convention are kept as written.
|
|
9
|
+
|
|
10
|
+
## 0.3.24
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- The package runs on plain Node, no loader or bundler of yours: every export but
|
|
15
|
+
`./sync/sqlite` loads compiled JavaScript (`default`); Bun loads sources (`bun`).
|
|
16
|
+
The bin: `node node_modules/@zvada/agent-server/dist/server/bin.js`, `--journal`
|
|
17
|
+
on `node:sqlite`; `listen` and `--listen` stay Bun's and say so (LLP 0001, D24).
|
|
18
|
+
- A Claude `toolPolicy` is told an MCP call's `mcp: { server, tool }` in its context,
|
|
19
|
+
as the call's permission request would carry it (a server named with `__` resolves
|
|
20
|
+
to the attached one), so a policy no longer parses `mcp__<server>__<tool>`; none
|
|
21
|
+
for a tool that is no MCP tool (LLP 0002, An MCP tool names its server and tool).
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- `./sync/node-sqlite` loads `node:sqlite` when a journal opens, not on import, so
|
|
26
|
+
it imports under Bun and in a bundle that holds both adapters; a build that
|
|
27
|
+
stubbed or lazy-loaded `node:sqlite` for it can drop that (LLP 0001, D24).
|
|
28
|
+
- A warm Codex session on its home's own login follows a login changed outside the
|
|
29
|
+
engine (`codex login`, another app): once `auth.json` changed, the next turn
|
|
30
|
+
resumes its thread on a new app-server, or fails `auth` after a sign-out. No login
|
|
31
|
+
is read, so a token renewal costs a colder turn about every ten days (LLP 0011).
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- A hung Claude CLI no longer holds its session: a cancelled turn it has not ended
|
|
36
|
+
by `cancelGraceMs` (10 s) has its process ended, ends `cancelled`, and the next
|
|
37
|
+
turn resumes the conversation. Claude takes the registry's `cancelGraceMs`, and
|
|
38
|
+
answers `cancelled` once its turn ended within `cancelConfirmMs` (LLP 0001, D9).
|
|
39
|
+
- A Codex MCP consent the engine cannot link to one started call (none open, or two
|
|
40
|
+
of the tool and neither with its arguments) carries `mcp` with its server and the
|
|
41
|
+
tool its message names, so a product that consents by `mcp.server` no longer
|
|
42
|
+
refuses it (LLP 0002, An MCP tool names its server and tool).
|
|
43
|
+
|
|
44
|
+
## 0.3.23
|
|
45
|
+
|
|
46
|
+
### Breaking
|
|
47
|
+
|
|
48
|
+
- `createAgentRegistry` and `createAgentRuntime` take `idleTimeoutMs`,
|
|
49
|
+
`cancelGraceMs` and `credentials` at the top level only, for every harness;
|
|
50
|
+
under `claudeCode`, `codexAppServer` or `acp` they throw, naming the option.
|
|
51
|
+
An agent made directly still takes them (LLP 0016, decision 5).
|
|
52
|
+
- `inheritConfig`, `processes` and `resolveCliPath` under `claudeCode`,
|
|
53
|
+
`codexAppServer` or `acp`, and `processes` under `scripted`, throw too,
|
|
54
|
+
naming the option: the registry overrode them in silence. Set
|
|
55
|
+
`inheritConfig` at the top level (LLP 0016, decision 5).
|
|
56
|
+
- A journal of your own implements `SessionJournal.lastTurn(sessionId)`: the
|
|
57
|
+
admitted turn, else the latest ended one, as `LastTurn` (LLP 0003).
|
|
58
|
+
- A Codex permission request's `title` is no longer Codex's reason, which is
|
|
59
|
+
now `toolCall.reason`; `title` is `Allow tool: shell` (or `apply_patch`),
|
|
60
|
+
as on every harness. Show `toolCall.reason` where you showed `title` on
|
|
61
|
+
Codex (LLP 0002, A tool call says what it acts on).
|
|
62
|
+
- A server of another wire protocol version is a refusal: the client stops
|
|
63
|
+
redialing, and what waits fails with `ProtocolVersionMismatchError` (new, a
|
|
64
|
+
`ConnectionRefusedError`), `initialize()` too (was `WireRequestError`); check
|
|
65
|
+
`reason`: `ConnectionRefusal` gains `"protocol_mismatch"` (LLP 0001, D16).
|
|
66
|
+
- A read installs nothing. While a harness's CLI is not installed,
|
|
67
|
+
`auth/status` answers it `unknown` with no `methods` and `models/list` the
|
|
68
|
+
catalog (`source: "catalog"`), each with an `error`. Install at setup
|
|
69
|
+
(`prepareClis`) and read again on `ready` (LLP 0010, A read installs nothing).
|
|
70
|
+
- Below `inheritConfig: "all"`, Codex's apps and plugins are off
|
|
71
|
+
(`features.apps = false`, `-c features.plugins=false`): the ChatGPT
|
|
72
|
+
account's connectors no longer join such a turn. A product that wants them
|
|
73
|
+
runs at `all` (LLP 0017).
|
|
74
|
+
- Codex asks its questions in `default` mode too: every thread starts with
|
|
75
|
+
`default_mode_request_user_input`. A turn without `elicitation: true`
|
|
76
|
+
declines the question, where Codex told the model the tool was unavailable
|
|
77
|
+
(LLP 0001, D12; LLP 0017, Questions outside plan mode).
|
|
78
|
+
- On Codex an MCP tool's image comes as `content` on its tool part, and
|
|
79
|
+
`output` says `[image image/png]` where the base64 was. A picture Codex
|
|
80
|
+
makes is an `image_generation` tool part with `metadata.savedPath`, no bytes
|
|
81
|
+
(LLP 0017, Codex's own pictures and an MCP tool's picture).
|
|
82
|
+
- A durable server delivers what its journal kept: an image or file too large
|
|
83
|
+
for a record is a text marker with `_meta["agent-server/omittedBinary"]`
|
|
84
|
+
(`OMITTED_BINARY_META_KEY`, `OmittedBinary`, new root exports), live and on
|
|
85
|
+
replay alike. It was cut base64 (LLP 0003, One log, one write path).
|
|
86
|
+
|
|
87
|
+
### Added
|
|
88
|
+
|
|
89
|
+
- `cancelConfirmMs` on `createAgentRegistry` (and each agent's options): how
|
|
90
|
+
long a cancel waits for the agent to confirm it stopped before it answers
|
|
91
|
+
`unconfirmed`, 2 s by default, on Claude, Codex and ACP (LLP 0001, D9).
|
|
92
|
+
- `session/get` (`getSession`) answers `lastTurn`: the latest turn's
|
|
93
|
+
`turnId`, and once it ended its `stopReason` and `error`, so a client learns
|
|
94
|
+
a restart cut it off (`server_restart`) without its history (LLP 0003,
|
|
95
|
+
Commit before acknowledging).
|
|
96
|
+
- A tool call says what it acts on: `command` (a command's line) and `url` (a
|
|
97
|
+
fetch's address) on tool parts and on `permission.requested`'s `toolCall`,
|
|
98
|
+
with `reason` (why it asks) on the request; a failed tool keeps `metadata`
|
|
99
|
+
(`ToolStateFailed.metadata`). Draw from them, not `rawInput` (LLP 0002).
|
|
100
|
+
- On Codex a command names its line apart from Codex's shell (`command`),
|
|
101
|
+
and carries `metadata.exitCode`, failed or not; a file change shows each
|
|
102
|
+
hunk as a `diff` entry, located at its start line (`docs/harnesses.md`,
|
|
103
|
+
What a tool call says, per harness; LLP 0002).
|
|
104
|
+
- On Claude a `Bash` call names its `command`, a `WebFetch` its `url`, a
|
|
105
|
+
request its `reason` (the CLI's `decisionReason`); an `Edit`, `Write` or
|
|
106
|
+
`NotebookEdit` shows `diff` entries from the CLI's structured result, and a
|
|
107
|
+
failed `Bash` its `metadata.exitCode` (`docs/harnesses.md`; LLP 0002).
|
|
108
|
+
- An ACP agent's `diff` and `terminal` content reaches its tool part's
|
|
109
|
+
`content`, where it was dropped, and `agent-server --acp` sends a part's
|
|
110
|
+
`diff` entries to its client as ACP diffs (LLP 0002, Tool output has three
|
|
111
|
+
audiences).
|
|
112
|
+
- A scripted harness, `scripted`, plays steps instead of a model; a step's
|
|
113
|
+
`yield` gives back what it did (`ScriptStepOutcome`). `createAgentRuntime({
|
|
114
|
+
scripted: { turn } })`, `ScriptStep`, `scriptedQueue`, `scriptedFile`,
|
|
115
|
+
`scriptedBySession`, `--script`, `--script-position` (LLP 0001, D23).
|
|
116
|
+
- `agent-server --acp` takes `--model <id>` and `--thinking <level>`: every
|
|
117
|
+
turn the ACP binding runs uses them (`AcpBindingOptions.thinkingLevel`, new),
|
|
118
|
+
where it ran the harness's own default. They are the operator's; an ACP
|
|
119
|
+
client cannot change them (LLP 0016.001, Prepared features, measured).
|
|
120
|
+
- A turn says what it did not apply: `AgentCapabilities.ignoredSettings`
|
|
121
|
+
lists the `RunConfig` fields a harness never applies, and
|
|
122
|
+
`execution.notApplied` on `turn.started` (and `turn.ended`, with what the
|
|
123
|
+
harness found as it ran) names those the turn set (LLP 0001, D22).
|
|
124
|
+
- A call to an MCP tool names its server and tool: `mcp: { server, tool }`
|
|
125
|
+
(new `McpTool`, `McpToolSchema`) on tool parts and on
|
|
126
|
+
`permission.requested`'s `toolCall`, on Claude and Codex; ACP leaves it out.
|
|
127
|
+
`toolName` is unchanged: stop parsing its spellings (LLP 0002).
|
|
128
|
+
- `codexAppServer.builtInTools: { local, webSearch, imageGeneration }`
|
|
129
|
+
(operator only) turns Codex's own tools off; `bun run harness --
|
|
130
|
+
--scenario=codex-tools-off` checks it for free at a Codex pin bump (LLP 0017).
|
|
131
|
+
- `codexAppServer.userLogin` (operator only, off by default): a Codex turn in
|
|
132
|
+
its session's own home runs on the user's Codex login, held in memory only;
|
|
133
|
+
with none it fails `auth` before Codex starts. `claimsOf` is a protocol
|
|
134
|
+
export (LLP 0017, The person's own login in a home of the session's own).
|
|
135
|
+
- `HarnessCli.category` and `HarnessCliProgress.category`: an install
|
|
136
|
+
failure's error category (`network`, `auth`, `rate_limit`,
|
|
137
|
+
`invalid_request`, `internal`), on the failed turn too. `CliProvisionError`
|
|
138
|
+
takes an optional `category`. Wire protocol 6 stays (LLP 0010).
|
|
139
|
+
- `HarnessAuth.loginUnderWay`: the login `auth/login` answered, in every status
|
|
140
|
+
read and `auth/updated` until its end, and `auth/updated` tells it as it
|
|
141
|
+
starts. Wire protocol 6 stays (LLP 0011, The wire).
|
|
142
|
+
- The `claudeSdkMismatch` diagnostic: the Claude SDK that loaded and the CLI
|
|
143
|
+
build it drives are different releases. Said once per pair, through
|
|
144
|
+
`onDiagnostic` (`{sdkVersion, cliVersion, cliPath}`) and on stderr; the turn
|
|
145
|
+
runs (LLP 0010, Implementation).
|
|
146
|
+
- `JOURNAL_SCHEMA_VERSION` (6), exported from `@zvada/agent-server/sync`
|
|
147
|
+
without loading SQLite: name a journal file from it (LLP 0003).
|
|
148
|
+
- `AgentServer.maxBacklogBytes` reads a server's backlog bound (LLP 0008).
|
|
149
|
+
- What each permission mode does on Claude and Codex is measured: the
|
|
150
|
+
`permission-modes` harness scenario, and the table in `docs/harnesses.md`
|
|
151
|
+
(LLP 0015).
|
|
152
|
+
|
|
153
|
+
### Changed
|
|
154
|
+
|
|
155
|
+
- An ACP agent that offers modes is put in the turn's `permissionMode`
|
|
156
|
+
(`session/set_mode`, its own id; `default` when the turn names none); one
|
|
157
|
+
it lacks is `notApplied`. It ran in its own: `claude-agent-acp`'s `auto`
|
|
158
|
+
asked the product nothing (LLP 0001, D4).
|
|
159
|
+
- `agent-server --acp --harness codex-app-server` takes a client's stdio and
|
|
160
|
+
HTTP MCP servers, carried in the thread at `all`, and advertises
|
|
161
|
+
`mcpCapabilities.http`; it refused every one. SSE and `codex_apps` are
|
|
162
|
+
refused, named. In front of `scripted` it advertises HTTP (LLP 0001, D21).
|
|
163
|
+
- Codex's `cancelGraceMs` is only how long after a cancel its process is
|
|
164
|
+
ended; a failed turn's wait for its end is `cancelConfirmMs`. A Codex
|
|
165
|
+
cancel answers within `cancelConfirmMs`: one whose commands were slow to
|
|
166
|
+
stop is `unconfirmed` now, where it answered late (LLP 0016, decision 5).
|
|
167
|
+
- The operator tools show a waiting permission's `command`, `url` or files and
|
|
168
|
+
its `reason`, each a quoted line under its title, and a tool's line reads
|
|
169
|
+
the call's `command` or `url` first, so a Codex command reads without
|
|
170
|
+
Codex's shell; paths read relative to the session's `root` (LLP 0014).
|
|
171
|
+
- A fenced restart's `server_restart` message reads "Server restarted before
|
|
172
|
+
the turn settled. Its agent could not be confirmed stopped at restart
|
|
173
|
+
(<reason>).", with the tool clause an unfenced one has, where it said "check
|
|
174
|
+
it before continuing": `recoveryRequired` says that (LLP 0003).
|
|
175
|
+
- Every tool the pinned Claude CLI offers has a decided `kind`: `TaskStop` and
|
|
176
|
+
`Workflow` are `execute`, `Skill` is `read`, the task-list tools are
|
|
177
|
+
`think`; the rest stay `other`. A free live check names a tool a pin bump
|
|
178
|
+
adds without one (LLP 0002, A tool call says what it acts on).
|
|
179
|
+
- The model catalog (`CATALOG_MODELS`) is regenerated from Claude SDK 0.3.288
|
|
180
|
+
and Codex 0.160.0 and adds Codex's `gpt-6.1-terra`. Claude's rows depend on
|
|
181
|
+
its route, so a live list can still differ (LLP 0010, A read installs
|
|
182
|
+
nothing; `docs/harnesses.md`, Model lists).
|
|
183
|
+
- A model known to have no thinking control (an empty `thinking.levels`, such
|
|
184
|
+
as Haiku's) starts without a level, and `turn.ended.execution` has no
|
|
185
|
+
`appliedThinkingLevel`; `off` is still sent (LLP 0013, M17).
|
|
186
|
+
- `createCheckpoint` replaces its largest images and files with the same
|
|
187
|
+
markers until it fits `HISTORY_MAX_BYTES`, and durable input over the record
|
|
188
|
+
limit is refused with its size and the limit (LLP 0003).
|
|
189
|
+
- `agent-server install` names each version (the Claude SDK package's and
|
|
190
|
+
Claude Code's), and says an ACP agent has nothing to install (LLP 0010, P4).
|
|
191
|
+
- A CLI install's error no longer ends with a request to report friction over
|
|
192
|
+
Hivenet; integration errors keep it (LLP 0010).
|
|
193
|
+
- A Codex thread's config is sent as one nested object (LLP 0017, One nested
|
|
194
|
+
config).
|
|
195
|
+
- On Codex and ACP, `idleTimeoutMs: 0` never ends a session's process for
|
|
196
|
+
idleness, as on Claude; it ended it as soon as the turn left (LLP 0001, D10).
|
|
197
|
+
- A host resume (`invalidateMcpConnections`) no longer closes idle Codex
|
|
198
|
+
processes at once: each session's next turn replaces its process, as on
|
|
199
|
+
Claude, and now on ACP too (LLP 0001, D10).
|
|
200
|
+
- `terminateAll` on Codex and ACP settles once every process has exited, as on
|
|
201
|
+
Claude, so a runtime's shutdown waits for them (LLP 0001, D10).
|
|
202
|
+
- A login changed in a named store (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`)
|
|
203
|
+
restarts only that store's sessions; one in the default store still restarts
|
|
204
|
+
all of the harness's. New: `CliLogin.store`, `Agent.loginChanged(store?)`
|
|
205
|
+
(LLP 0011, A login change starts the next turn on a new CLI).
|
|
206
|
+
- Claude sessions run on the process pool Codex and ACP use; `onSessionEnd`
|
|
207
|
+
keeps its reasons. A cancel during a Claude start ends it at once and
|
|
208
|
+
answers without waiting for that CLI's exit (LLP 0001, D10; LLP 0016).
|
|
209
|
+
|
|
210
|
+
### Fixed
|
|
211
|
+
|
|
212
|
+
- Behind `agent-server --acp`, a prompt's `resource_link` (an editor's
|
|
213
|
+
@-mention of a file), which ACP v1 has every agent take, reaches the turn
|
|
214
|
+
as a Markdown link in its text; it was dropped (LLP 0016.001, Prepared
|
|
215
|
+
features, measured).
|
|
216
|
+
- The stock program's `acp` harness tells its agent its release in
|
|
217
|
+
`initialize` (`clientInfo.version`); it said `0.0.0`. Embedded, set
|
|
218
|
+
`acp.clientVersion` (LLP 0016.001, Prepared features, measured).
|
|
219
|
+
- Behind `agent-server --acp`, the agent's questions reach a client that
|
|
220
|
+
advertises form elicitation, as `elicitation/create` (one form field per
|
|
221
|
+
question), and MCP forms and URLs one that advertises their mode; the
|
|
222
|
+
agent was told no one could answer (LLP 0001, D12).
|
|
223
|
+
- Behind `agent-server --acp`, a permission request names its tool (`name`)
|
|
224
|
+
and carries its `locations`; a client read the tool's name from the
|
|
225
|
+
request's title ("Allow tool: Bash") and got no locations (LLP 0016.001,
|
|
226
|
+
Prepared features, measured).
|
|
227
|
+
- Input with a lone UTF-16 surrogate (text cut mid-emoji) runs on Codex: the
|
|
228
|
+
agent is given U+FFFD, the echo stays your input. Such a turn waited 30 s
|
|
229
|
+
and failed; an unanswered `turn/start` now says so, with its deadline
|
|
230
|
+
(LLP 0013, F12).
|
|
231
|
+
- A cancel while a warm Claude process changes model, permission mode or MCP
|
|
232
|
+
servers ends the turn `cancelled` and the process; Claude never answering
|
|
233
|
+
held the turn, though the cancel said `confirmed`. The next turn resumes on
|
|
234
|
+
a new process (LLP 0013, F13).
|
|
235
|
+
- A Claude turn that fails on an overloaded API (529 or 503) ends with error
|
|
236
|
+
category `overloaded`, read from its result's status; it was `internal`
|
|
237
|
+
(LLP 0002, Plan usage and retries).
|
|
238
|
+
- A cancel while a Codex turn is still starting answers `cancelled` once the
|
|
239
|
+
turn has ended; it answered `unconfirmed` at once, though the turn stopped
|
|
240
|
+
(LLP 0001, D9; LLP 0016.000, The cancel answer).
|
|
241
|
+
- A cancel while an ACP operator's `resolveLaunch` is pending ends the turn at
|
|
242
|
+
once; the turn waited for it, the cancel answered `unconfirmed` after 2 s,
|
|
243
|
+
and a later cancel still found the turn (LLP 0001, D9).
|
|
244
|
+
- A cancel while Claude or Codex asks the product's credential source ends the
|
|
245
|
+
turn `cancelled` at once, whether or not the source heeds its signal; the
|
|
246
|
+
turn waited for the source, and an answer after the cancel is dropped
|
|
247
|
+
(LLP 0016.000, The cancel answer).
|
|
248
|
+
- A durable restart that cuts off a scripted turn fences nothing, as on
|
|
249
|
+
Claude or Codex once the restart saw them stopped: it runs no process, and
|
|
250
|
+
`createAgentRegistry` now vouches for it (LLP 0007, What each harness does).
|
|
251
|
+
- `subscribeAll()` follows every session from the call, across redials, until
|
|
252
|
+
`unsubscribeAll()`; it rejects only when refused or closed (LLP 0008, What
|
|
253
|
+
requests do to subscriptions).
|
|
254
|
+
- A cut CLI download goes on from the bytes it has (`Range`), then fails as
|
|
255
|
+
`network` saying how far it got; "Integrity mismatch" is said only of a whole
|
|
256
|
+
file (LLP 0010, Implementation).
|
|
257
|
+
- `agent-server install --dir` creates missing folders at 0755 whatever the
|
|
258
|
+
umask (LLP 0010, P4).
|
|
259
|
+
- Under Node's ESM (tsx, an ESM bundle) the engine finds the Claude SDK
|
|
260
|
+
installed beside it (LLP 0010, P2).
|
|
261
|
+
- A connection that falls behind is told (`session/overflow`) or closed, never
|
|
262
|
+
left waiting: `listen` gives Bun 64 MiB of headroom above the bound (LLP 0008,
|
|
263
|
+
Backpressure and overflow).
|
|
264
|
+
- A turn cancelled while its CLI installs ends `cancelled` at once; the install
|
|
265
|
+
goes on (LLP 0010, A turn waits for its CLI until it is cancelled).
|
|
266
|
+
- Codex: a session whose `CODEX_HOME` was made again starts a new process
|
|
267
|
+
(LLP 0001, D21).
|
|
268
|
+
- A failed Codex turn ends at its own `turn/completed`, so the next turn is
|
|
269
|
+
its own (LLP 0013, F11).
|
|
270
|
+
- `session/close` and `session/release` of a Codex or ACP session answer once
|
|
271
|
+
its agent process has exited (LLP 0001, D10; LLP 0007).
|
|
272
|
+
- Under Bun, a CLI started just before its owner was SIGKILLed no longer
|
|
273
|
+
outlives it (LLP 0007, The lifeline).
|
|
274
|
+
- A Codex retry's recoverable `error` says which attempt it is, of how many
|
|
275
|
+
(`retry.attempt`, `retry.maxAttempts`), read from Codex's "Reconnecting...
|
|
276
|
+
2/5"; it was `retry: {}` (LLP 0002, Plan usage and retries).
|
|
277
|
+
- An ACP agent that can neither resume nor load a session is no longer ended
|
|
278
|
+
for being idle, so its next turn no longer fails with `SessionResumeError`;
|
|
279
|
+
it lives until release, close or shutdown (LLP 0001, D10).
|
|
280
|
+
- An ACP cancel answers `confirmed: true` only when the agent's prompt ended
|
|
281
|
+
within 2 s, and `confirmed: false` (`turn/cancel`: `unconfirmed`) otherwise;
|
|
282
|
+
it was always `true`. The turn still ends at the 10 s grace (LLP 0001, D9).
|
|
283
|
+
- An ACP agent that replaces an evicted or replaced one starts once that one
|
|
284
|
+
has exited, so two never hold one conversation; `session/release` waits for
|
|
285
|
+
it too (LLP 0001, D10).
|
|
286
|
+
- `--acp`: a `session/new` or `session/resume` with an MCP server of a
|
|
287
|
+
transport the binding cannot attach (ACP's `acp`) is refused with
|
|
288
|
+
`invalidParams` naming the server, where the server was dropped in silence
|
|
289
|
+
(LLP 0001, D15).
|
|
290
|
+
- A turn a restart cut off says "what its running tool did is unknown" only
|
|
291
|
+
when a tool that may have run was open; otherwise its `server_restart`
|
|
292
|
+
message ends "Its agent was stopped at restart." (LLP 0003).
|
|
293
|
+
|
|
294
|
+
Not in any release, so not removed: `codexAppServer.userMcpServers` and
|
|
295
|
+
`CodexUserMcpServers`, which `userLogin` replaced before they shipped
|
|
296
|
+
(LLP 0017).
|
|
297
|
+
|
|
3
298
|
## 0.3.22
|
|
4
299
|
|
|
5
300
|
- `@zvada/agent-server/operator`, new: eight tools a hosted assistant or a
|
package/README.md
CHANGED
|
@@ -54,6 +54,11 @@ bunx @zvada/agent-server --acp # act as an ACP v1 agent (Zed-spawnable
|
|
|
54
54
|
bunx @zvada/agent-server install # prefetch pinned claude/codex CLIs
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
Under Node, run the compiled bin:
|
|
58
|
+
`node node_modules/@zvada/agent-server/dist/server/bin.js --stdio` (or
|
|
59
|
+
`--dial`, `--acp`, `install`). `--listen` needs Bun, and `--journal` uses
|
|
60
|
+
`node:sqlite` there (Node >= 22.16).
|
|
61
|
+
|
|
57
62
|
A listener answers native clients only: a browser is refused unless
|
|
58
63
|
`--allow-origin <origin>` names its origin, since any page may open a
|
|
59
64
|
WebSocket to localhost. Beyond loopback (`--listen 0.0.0.0:4747`) it needs a
|
|
@@ -119,11 +124,15 @@ for await (const event of turn.events) conversation = reduceConversation(convers
|
|
|
119
124
|
|
|
120
125
|
## Notes
|
|
121
126
|
|
|
122
|
-
- Ships
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
- Ships its TypeScript sources, the JavaScript compiled from them, and
|
|
128
|
+
declarations. Bun loads the sources (the `bun` export condition); Node and
|
|
129
|
+
bundlers load the compiled `dist/` (`default`), with no loader or
|
|
130
|
+
transpiling of your own; a consumer's `tsc` reads `dist/types`, so its
|
|
131
|
+
compiler options, Bun's types and the SDKs of harnesses it does not run stay
|
|
132
|
+
out of its build (with `skipLibCheck`). Tested on Bun 1.3 and Node 22.16,
|
|
133
|
+
22.23 and 24.21. Bun only: `./sync/sqlite` (use `./sync/node-sqlite` under
|
|
134
|
+
Node) and `listen` (under Node serve over stdio, `dial`, or a WebSocket
|
|
135
|
+
server of your own; [deploy](docs/deploy.md#on-node)).
|
|
127
136
|
- The wire vocabulary tracks the
|
|
128
137
|
[Agent Client Protocol](https://agentclientprotocol.com) where concepts
|
|
129
138
|
overlap.
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { claimsOf } from "../protocol/credentials.js";
|
|
2
|
+
import { AccountError, call, isRecord, text } from "./http.js";
|
|
3
|
+
// The Codex CLI's own OAuth client, as the `codex` binary carries it, and its
|
|
4
|
+
// device sign-in (codex-rs `login/`). A public client: no secret, the same for
|
|
5
|
+
// every user. The issuer is fixed, so no caller-supplied address ever receives
|
|
6
|
+
// these credentials.
|
|
7
|
+
const ISSUER = "https://auth.openai.com";
|
|
8
|
+
const CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
9
|
+
/** How long a device code waits for its person. */
|
|
10
|
+
const DEVICE_CODE_LIFETIME_MS = 15 * 60_000;
|
|
11
|
+
/** A grant from what OpenAI's token endpoint answered: the account and plan are the id token's. */
|
|
12
|
+
function grantFrom(body, options, previous) {
|
|
13
|
+
const old = previous?.credential.type === "chatgpt" ? previous.credential : undefined;
|
|
14
|
+
const answer = isRecord(body) ? body : {};
|
|
15
|
+
// A renewal answered without a token renewed nothing, and may have spent the refresh token.
|
|
16
|
+
const accessToken = text(answer.access_token);
|
|
17
|
+
const refreshToken = text(answer.refresh_token) ?? previous?.refreshToken;
|
|
18
|
+
const idToken = text(answer.id_token);
|
|
19
|
+
if (!accessToken || !refreshToken) {
|
|
20
|
+
throw new AccountError("OpenAI returned an incomplete login. Sign in again.", true);
|
|
21
|
+
}
|
|
22
|
+
const identity = idToken ? claimsOf(idToken) : {};
|
|
23
|
+
const auth = isRecord(identity["https://api.openai.com/auth"])
|
|
24
|
+
? identity["https://api.openai.com/auth"]
|
|
25
|
+
: {};
|
|
26
|
+
const accountId = text(auth.chatgpt_account_id) ?? old?.accountId;
|
|
27
|
+
const expiry = claimsOf(accessToken).exp;
|
|
28
|
+
if (!accountId)
|
|
29
|
+
throw new AccountError("OpenAI returned no ChatGPT account. Sign in again.", true);
|
|
30
|
+
if (old && old.accountId !== accountId) {
|
|
31
|
+
throw new AccountError("The ChatGPT account changed. Sign in again.", true);
|
|
32
|
+
}
|
|
33
|
+
const plan = text(auth.chatgpt_plan_type) ?? old?.plan;
|
|
34
|
+
const email = text(identity.email) ?? previous?.email;
|
|
35
|
+
return {
|
|
36
|
+
harness: "codex-app-server",
|
|
37
|
+
credential: {
|
|
38
|
+
type: "chatgpt",
|
|
39
|
+
accessToken,
|
|
40
|
+
accountId,
|
|
41
|
+
...(plan && { plan }),
|
|
42
|
+
...(typeof expiry === "number" && { expiresAt: expiry * 1000 }),
|
|
43
|
+
},
|
|
44
|
+
refreshToken,
|
|
45
|
+
...(email && { email }),
|
|
46
|
+
...(plan && { plan }),
|
|
47
|
+
obtainedAt: (options.now ?? Date.now)(),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Start a ChatGPT sign-in with a device code, which a person enters on any
|
|
52
|
+
* device: what a hosted product offers, since Codex's browser sign-in calls
|
|
53
|
+
* back to `localhost` only. The account must allow device codes (ChatGPT
|
|
54
|
+
* settings, Security).
|
|
55
|
+
*/
|
|
56
|
+
export async function startChatGptLogin(options = {}) {
|
|
57
|
+
const answer = await call(`${ISSUER}/api/accounts/deviceauth/usercode`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: { "content-type": "application/json" },
|
|
60
|
+
body: JSON.stringify({ client_id: CLIENT_ID }),
|
|
61
|
+
}, options);
|
|
62
|
+
const body = isRecord(answer.body) ? answer.body : {};
|
|
63
|
+
const deviceAuthId = text(body.device_auth_id);
|
|
64
|
+
const userCode = text(body.user_code) ?? text(body.usercode);
|
|
65
|
+
if (!answer.ok || !deviceAuthId || !userCode) {
|
|
66
|
+
throw new AccountError("OpenAI did not start the sign-in. Allow device code sign-in in ChatGPT settings (Security), then try again.");
|
|
67
|
+
}
|
|
68
|
+
const interval = Number(body.interval);
|
|
69
|
+
return {
|
|
70
|
+
deviceAuthId,
|
|
71
|
+
userCode,
|
|
72
|
+
verificationUrl: `${ISSUER}/codex/device`,
|
|
73
|
+
intervalMs: Math.max(Number.isFinite(interval) ? interval : 5, 5) * 1000,
|
|
74
|
+
expiresAt: (options.now ?? Date.now)() + DEVICE_CODE_LIFETIME_MS,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Ask once whether the person approved: the grant once they did, `undefined`
|
|
79
|
+
* while they have not. Poll no faster than `intervalMs`. The approval's code is
|
|
80
|
+
* exchanged once, never retried: a lost answer means sign in again.
|
|
81
|
+
*/
|
|
82
|
+
export async function pollChatGptLogin(login, options = {}) {
|
|
83
|
+
if ((options.now ?? Date.now)() > login.expiresAt) {
|
|
84
|
+
throw new AccountError("The sign-in code expired. Start again.");
|
|
85
|
+
}
|
|
86
|
+
const answer = await call(`${ISSUER}/api/accounts/deviceauth/token`, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: { "content-type": "application/json" },
|
|
89
|
+
body: JSON.stringify({ device_auth_id: login.deviceAuthId, user_code: login.userCode }),
|
|
90
|
+
}, options).catch(() => undefined);
|
|
91
|
+
// Waiting, as Codex reads it (403, 404), and a failure worth asking again (429, 5xx).
|
|
92
|
+
if (!answer ||
|
|
93
|
+
answer.status === 403 ||
|
|
94
|
+
answer.status === 404 ||
|
|
95
|
+
answer.status === 429 ||
|
|
96
|
+
answer.status >= 500) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const body = isRecord(answer.body) ? answer.body : {};
|
|
100
|
+
const code = text(body.authorization_code);
|
|
101
|
+
const verifier = text(body.code_verifier);
|
|
102
|
+
if (!answer.ok || !code || !verifier)
|
|
103
|
+
throw new AccountError("OpenAI did not finish the sign-in. Start again.");
|
|
104
|
+
const token = await call(`${ISSUER}/oauth/token`, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
107
|
+
body: new URLSearchParams({
|
|
108
|
+
grant_type: "authorization_code",
|
|
109
|
+
client_id: CLIENT_ID,
|
|
110
|
+
code,
|
|
111
|
+
code_verifier: verifier,
|
|
112
|
+
redirect_uri: `${ISSUER}/deviceauth/callback`,
|
|
113
|
+
}).toString(),
|
|
114
|
+
}, options);
|
|
115
|
+
if (!token.ok)
|
|
116
|
+
throw new AccountError("OpenAI refused this sign-in. Start again.");
|
|
117
|
+
return grantFrom(token.body, options);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Renew a ChatGPT grant: the same account with fresh tokens, which the
|
|
121
|
+
* product stores in its place. One renewal at a time per grant: a renewal
|
|
122
|
+
* whose answer was lost may have happened, and is not tried again here.
|
|
123
|
+
*/
|
|
124
|
+
export async function refreshChatGptGrant(grant, options = {}) {
|
|
125
|
+
if (grant.credential.type !== "chatgpt" || !grant.refreshToken) {
|
|
126
|
+
throw new AccountError("This is not a ChatGPT grant that renews.");
|
|
127
|
+
}
|
|
128
|
+
const answer = await call(`${ISSUER}/oauth/token`, {
|
|
129
|
+
method: "POST",
|
|
130
|
+
headers: { "content-type": "application/json" },
|
|
131
|
+
body: JSON.stringify({
|
|
132
|
+
client_id: CLIENT_ID,
|
|
133
|
+
grant_type: "refresh_token",
|
|
134
|
+
refresh_token: grant.refreshToken,
|
|
135
|
+
}),
|
|
136
|
+
}, options);
|
|
137
|
+
if (!answer.ok) {
|
|
138
|
+
const refused = answer.status === 400 || answer.status === 401;
|
|
139
|
+
throw new AccountError(refused
|
|
140
|
+
? "The ChatGPT login expired or was revoked. Sign in again."
|
|
141
|
+
: "OpenAI did not renew the login. Try again.", refused);
|
|
142
|
+
}
|
|
143
|
+
return grantFrom(answer.body, options, grant);
|
|
144
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { credentialRunsOn, } from "../protocol/credentials.js";
|
|
2
|
+
import { AccountError, call } from "./http.js";
|
|
3
|
+
const ANTHROPIC_MODELS = "https://api.anthropic.com/v1/models?limit=1";
|
|
4
|
+
const OPENAI_MODELS = "https://api.openai.com/v1/models";
|
|
5
|
+
const ANTHROPIC_VERSION = "2023-06-01";
|
|
6
|
+
const OK = { ok: true };
|
|
7
|
+
/**
|
|
8
|
+
* Whether a credential works, by one cheap request to its provider (a model
|
|
9
|
+
* list): a key or token the provider refuses is `reconnect`. A ChatGPT token
|
|
10
|
+
* is checked by its expiry only, as no public request takes it, and a
|
|
11
|
+
* gateway's key (`baseUrl`) not at all.
|
|
12
|
+
*/
|
|
13
|
+
export async function checkCredential(harness, credential, options = {}) {
|
|
14
|
+
if (harness === "claude-code") {
|
|
15
|
+
const runs = credentialRunsOn(harness, credential);
|
|
16
|
+
return runs.ok ? checkClaude(runs.credential, options) : unrunnable(runs.error);
|
|
17
|
+
}
|
|
18
|
+
if (harness === "codex-app-server") {
|
|
19
|
+
const runs = credentialRunsOn(harness, credential);
|
|
20
|
+
return runs.ok ? checkCodex(runs.credential, options) : unrunnable(runs.error);
|
|
21
|
+
}
|
|
22
|
+
return unrunnable(`${harness} runs on no credential a product holds.`);
|
|
23
|
+
}
|
|
24
|
+
const unrunnable = (error) => ({ ok: false, error, reconnect: true });
|
|
25
|
+
function checkClaude(credential, options) {
|
|
26
|
+
if (credential.type === "oauth_token") {
|
|
27
|
+
return listModels(ANTHROPIC_MODELS, {
|
|
28
|
+
authorization: `Bearer ${credential.accessToken}`,
|
|
29
|
+
"anthropic-version": ANTHROPIC_VERSION,
|
|
30
|
+
"anthropic-beta": "oauth-2025-04-20",
|
|
31
|
+
}, options);
|
|
32
|
+
}
|
|
33
|
+
// A gateway's key: what a person pasted would point this server's
|
|
34
|
+
// requests anywhere, so a product trusts its gateways by its own list.
|
|
35
|
+
if (credential.baseUrl)
|
|
36
|
+
return OK;
|
|
37
|
+
return listModels(ANTHROPIC_MODELS, { "x-api-key": credential.apiKey, "anthropic-version": ANTHROPIC_VERSION }, options);
|
|
38
|
+
}
|
|
39
|
+
function checkCodex(credential, options) {
|
|
40
|
+
if (credential.type === "api_key") {
|
|
41
|
+
return listModels(OPENAI_MODELS, { authorization: `Bearer ${credential.apiKey}` }, options);
|
|
42
|
+
}
|
|
43
|
+
const expired = credential.expiresAt !== undefined && credential.expiresAt <= (options.now ?? Date.now)();
|
|
44
|
+
return expired
|
|
45
|
+
? { ok: false, error: "The ChatGPT token expired: renew it.", reconnect: false }
|
|
46
|
+
: OK;
|
|
47
|
+
}
|
|
48
|
+
/** One cheap request with the credential: a refusal is `reconnect`. */
|
|
49
|
+
async function listModels(url, headers, options) {
|
|
50
|
+
const answer = await call(url, { headers }, options);
|
|
51
|
+
if (answer.ok)
|
|
52
|
+
return OK;
|
|
53
|
+
const refused = answer.status === 401 || answer.status === 403;
|
|
54
|
+
return {
|
|
55
|
+
ok: false,
|
|
56
|
+
error: refused
|
|
57
|
+
? "The provider refused this credential."
|
|
58
|
+
: `The provider answered ${answer.status}.`,
|
|
59
|
+
reconnect: refused,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A key or token the person pasted (an API key, a `claude setup-token`
|
|
64
|
+
* token), checked: the grant to store, or why not.
|
|
65
|
+
*/
|
|
66
|
+
export async function pastedGrant(harness, credential, options = {}) {
|
|
67
|
+
const check = await checkCredential(harness, credential, options);
|
|
68
|
+
if (!check.ok)
|
|
69
|
+
throw new AccountError(check.error, check.reconnect);
|
|
70
|
+
return { harness, credential, obtainedAt: (options.now ?? Date.now)() };
|
|
71
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { pastedSignInCode } from "../protocol/credentials.js";
|
|
2
|
+
import { AccountError, call, challengeOf, isRecord, randomToken, text, } from "./http.js";
|
|
3
|
+
// What `claude setup-token` asks for (Claude Code 2.1.288): Claude Code's own
|
|
4
|
+
// OAuth client, as the `claude` binary carries it (public: no secret, the
|
|
5
|
+
// same for every user), the inference scope alone, a year, and the page that
|
|
6
|
+
// shows a code.
|
|
7
|
+
const CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
|
|
8
|
+
const AUTHORIZE_URL = "https://claude.com/cai/oauth/authorize";
|
|
9
|
+
const TOKEN_URL = "https://platform.claude.com/v1/oauth/token";
|
|
10
|
+
const CODE_PAGE = "https://platform.claude.com/oauth/code/callback";
|
|
11
|
+
const SCOPE = "user:inference";
|
|
12
|
+
const ONE_YEAR_S = 31_536_000;
|
|
13
|
+
/** Start a Claude sign-in whose code is pasted back: it works from any device. */
|
|
14
|
+
export async function startClaudeLogin() {
|
|
15
|
+
const verifier = randomToken();
|
|
16
|
+
const state = randomToken();
|
|
17
|
+
const url = new URL(AUTHORIZE_URL);
|
|
18
|
+
for (const [name, value] of Object.entries({
|
|
19
|
+
code: "true",
|
|
20
|
+
client_id: CLIENT_ID,
|
|
21
|
+
response_type: "code",
|
|
22
|
+
redirect_uri: CODE_PAGE,
|
|
23
|
+
scope: SCOPE,
|
|
24
|
+
code_challenge: await challengeOf(verifier),
|
|
25
|
+
code_challenge_method: "S256",
|
|
26
|
+
state,
|
|
27
|
+
})) {
|
|
28
|
+
url.searchParams.set(name, value);
|
|
29
|
+
}
|
|
30
|
+
return { url: url.toString(), state, verifier };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Finish a Claude sign-in with the code its page showed (`code#state`, the
|
|
34
|
+
* page's address, or the bare code): a one-year inference token, which needs
|
|
35
|
+
* no renewal. A code from another sign-in is refused before it is sent.
|
|
36
|
+
*/
|
|
37
|
+
export async function completeClaudeLogin(login, pasted, options = {}) {
|
|
38
|
+
let pastedCode;
|
|
39
|
+
try {
|
|
40
|
+
pastedCode = pastedSignInCode(pasted, login.state);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new AccountError(error.message);
|
|
44
|
+
}
|
|
45
|
+
const { code, state } = pastedCode;
|
|
46
|
+
const answer = await call(TOKEN_URL, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "content-type": "application/json" },
|
|
49
|
+
body: JSON.stringify({
|
|
50
|
+
grant_type: "authorization_code",
|
|
51
|
+
code,
|
|
52
|
+
redirect_uri: CODE_PAGE,
|
|
53
|
+
client_id: CLIENT_ID,
|
|
54
|
+
code_verifier: login.verifier,
|
|
55
|
+
state,
|
|
56
|
+
expires_in: ONE_YEAR_S,
|
|
57
|
+
}),
|
|
58
|
+
}, options);
|
|
59
|
+
const body = isRecord(answer.body) ? answer.body : {};
|
|
60
|
+
const accessToken = text(body.access_token);
|
|
61
|
+
if (!answer.ok || !accessToken) {
|
|
62
|
+
throw new AccountError(answer.status === 400 || answer.status === 401
|
|
63
|
+
? "Claude did not accept this code: sign in again, and paste the code the page shows."
|
|
64
|
+
: "Claude did not finish the sign-in. Try again.");
|
|
65
|
+
}
|
|
66
|
+
const now = (options.now ?? Date.now)();
|
|
67
|
+
const expiresIn = Number(body.expires_in);
|
|
68
|
+
const account = isRecord(body.account) ? body.account : {};
|
|
69
|
+
const email = text(account.email_address);
|
|
70
|
+
return {
|
|
71
|
+
harness: "claude-code",
|
|
72
|
+
credential: {
|
|
73
|
+
type: "oauth_token",
|
|
74
|
+
accessToken,
|
|
75
|
+
...(Number.isFinite(expiresIn) && { expiresAt: now + expiresIn * 1000 }),
|
|
76
|
+
},
|
|
77
|
+
...(email && { email }),
|
|
78
|
+
obtainedAt: now,
|
|
79
|
+
};
|
|
80
|
+
}
|