@zvada/agent-server 0.3.21 → 0.3.23
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 +332 -0
- package/README.md +2 -1
- 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 +66 -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 +4 -3
- 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 +16 -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 +10 -4
- 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 +50 -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 +21 -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 +61 -14
- 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 +26 -5
- 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 +4 -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 +45 -20
- 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 +32 -5
- 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 +70 -33
- 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 +37 -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/plan.d.ts +2 -13
- package/dist/types/core/agents/plan.d.ts.map +1 -1
- package/dist/types/core/agents/process-pool.d.ts +193 -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 +6 -1
- 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 +18 -9
- 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 +14 -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 +15 -1
- package/dist/types/core/utils/errors.d.ts.map +1 -1
- package/dist/types/operator/index.d.ts +11 -0
- package/dist/types/operator/index.d.ts.map +1 -0
- package/dist/types/operator/mcp.d.ts +33 -0
- package/dist/types/operator/mcp.d.ts.map +1 -0
- package/dist/types/operator/operator.d.ts +206 -0
- package/dist/types/operator/operator.d.ts.map +1 -0
- package/dist/types/operator/render.d.ts +89 -0
- package/dist/types/operator/render.d.ts.map +1 -0
- package/dist/types/operator/view.d.ts +44 -0
- package/dist/types/operator/view.d.ts.map +1 -0
- 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/plan.d.ts +20 -0
- package/dist/types/protocol/plan.d.ts.map +1 -0
- 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/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.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/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/dist/types/sync/worker.d.ts.map +1 -1
- package/docs/consuming.md +464 -40
- package/docs/deploy.md +36 -8
- package/docs/durable-sessions.md +35 -5
- package/docs/harnesses.md +396 -30
- package/package.json +11 -1
- 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 +113 -22
- package/src/client/index.ts +1 -0
- package/src/client/logins.ts +24 -15
- 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 +6 -5
- package/src/core/agents/claude-code/claude-agent.ts +60 -30
- 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 +11 -3
- 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 +166 -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 +69 -10
- package/src/core/agents/codex-app-server/codex-agent.ts +141 -55
- 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 +59 -10
- package/src/core/agents/codex-app-server/items.ts +219 -31
- package/src/core/agents/codex-app-server/login.ts +14 -2
- package/src/core/agents/codex-app-server/mcp.ts +142 -26
- package/src/core/agents/codex-app-server/models.ts +9 -8
- package/src/core/agents/codex-app-server/options.ts +79 -11
- 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 +14 -6
- package/src/core/agents/codex-app-server/session.ts +156 -81
- 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 +96 -35
- 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/plan.ts +3 -19
- package/src/core/agents/process-pool.ts +432 -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 +12 -0
- package/src/core/presets.ts +99 -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 +70 -34
- 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 +53 -3
- package/src/core/utils/deadline.ts +23 -0
- package/src/core/utils/errors.ts +24 -4
- package/src/operator/index.ts +40 -0
- package/src/operator/mcp.ts +171 -0
- package/src/operator/operator.ts +782 -0
- package/src/operator/render.ts +473 -0
- package/src/operator/view.ts +82 -0
- 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/plan.ts +35 -0
- package/src/protocol/tool-state.ts +14 -1
- package/src/protocol/wire.ts +14 -0
- package/src/server/acp/binding.ts +113 -22
- package/src/server/acp/translate.ts +161 -8
- package/src/server/agent-server.ts +10 -1
- package/src/server/bin.ts +83 -9
- 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 +14 -0
- 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/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/src/sync/worker.ts +4 -0
- 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
|
@@ -83,6 +83,25 @@ export async function tokenDigest(token: string): Promise<string> {
|
|
|
83
83
|
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* A JWT's claims, read, not verified: only ever of a token its issuer just
|
|
88
|
+
* answered over TLS, or the CLI that holds it. `{}` for anything else.
|
|
89
|
+
*/
|
|
90
|
+
export function claimsOf(jwt: string): Record<string, unknown> {
|
|
91
|
+
try {
|
|
92
|
+
const payload = (jwt.split(".")[1] ?? "").replace(/-/g, "+").replace(/_/g, "/");
|
|
93
|
+
const binary = atob(payload.padEnd(Math.ceil(payload.length / 4) * 4, "="));
|
|
94
|
+
// UTF-8, so an email in another script reads as it was written.
|
|
95
|
+
const text = new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0)));
|
|
96
|
+
const parsed: unknown = JSON.parse(text);
|
|
97
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
|
|
98
|
+
? (parsed as Record<string, unknown>)
|
|
99
|
+
: {};
|
|
100
|
+
} catch {
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
86
105
|
/**
|
|
87
106
|
* What a product stores for an account it holds: who it is (`AccountInfo`),
|
|
88
107
|
* the credential a turn gets, and what renews it (a ChatGPT login's refresh
|
|
@@ -21,5 +21,10 @@ export const TurnExecutionSchema = z.object({
|
|
|
21
21
|
* those its stream named, else the model Codex reported for the thread. Excludes
|
|
22
22
|
* subagents. Absence means unreported, never a fallback to the requested alias. */
|
|
23
23
|
reportedModels: z.array(z.string()).optional(),
|
|
24
|
+
/** The `RunConfig` fields this turn set that the harness did not apply: those it
|
|
25
|
+
* never applies (`AgentCapabilities.ignoredSettings`) on `turn.started`, and on
|
|
26
|
+
* `turn.ended` with them those it found it could not apply as it ran (an ACP agent
|
|
27
|
+
* that takes no extra directories). Absent when it applied everything the turn set. */
|
|
28
|
+
notApplied: z.array(z.string()).optional(),
|
|
24
29
|
});
|
|
25
30
|
export type TurnExecution = z.infer<typeof TurnExecutionSchema>;
|
|
@@ -3,7 +3,7 @@ import type { Delta } from "./lifecycle.ts";
|
|
|
3
3
|
import { META_KEYS } from "./meta-keys.ts";
|
|
4
4
|
import type { AgentInput } from "./part-input.ts";
|
|
5
5
|
import type { Part, ReasoningPart, SubagentMetadata, TextPart, ToolPart } from "./parts.ts";
|
|
6
|
-
import type { ToolKind, ToolLocation, ToolResultContent } from "./tool-state.ts";
|
|
6
|
+
import type { McpTool, ToolKind, ToolLocation, ToolResultContent } from "./tool-state.ts";
|
|
7
7
|
|
|
8
8
|
/** Context an adapter threads through while building parts for one message. */
|
|
9
9
|
export interface StreamContext {
|
|
@@ -15,7 +15,13 @@ export interface StreamContext {
|
|
|
15
15
|
/** Optional normalized metadata for a tool part (see ToolPart). */
|
|
16
16
|
export interface ToolMeta {
|
|
17
17
|
kind?: ToolKind;
|
|
18
|
+
/** A call to an MCP tool, when the harness knows its server and tool. */
|
|
19
|
+
mcp?: McpTool;
|
|
18
20
|
title?: string;
|
|
21
|
+
/** A command's line as the agent wrote it, apart from any wrapper the harness adds. */
|
|
22
|
+
command?: string;
|
|
23
|
+
/** A fetch's address. */
|
|
24
|
+
url?: string;
|
|
19
25
|
locations?: ToolLocation[];
|
|
20
26
|
/** Present when this tool spawns a subagent (implies kind "task"). */
|
|
21
27
|
subagent?: SubagentMetadata;
|
|
@@ -59,7 +65,10 @@ function toolBase(ctx: StreamContext, toolCallId: string, toolName: string, meta
|
|
|
59
65
|
toolCallId,
|
|
60
66
|
toolName,
|
|
61
67
|
...(meta?.subagent ? { kind: "task" as const } : meta?.kind ? { kind: meta.kind } : {}),
|
|
68
|
+
...(meta?.mcp && { mcp: { ...meta.mcp } }),
|
|
62
69
|
...(meta?.title && { title: meta.title }),
|
|
70
|
+
...(meta?.command && { command: meta.command }),
|
|
71
|
+
...(meta?.url && { url: meta.url }),
|
|
63
72
|
...(meta?.locations?.length && { locations: meta.locations }),
|
|
64
73
|
...(meta?.subagent && { subagent: meta.subagent }),
|
|
65
74
|
};
|
|
@@ -134,11 +143,18 @@ export function setToolMeta(part: ToolPart, meta: ToolMeta): void {
|
|
|
134
143
|
} else if (meta.kind) {
|
|
135
144
|
part.kind = meta.kind;
|
|
136
145
|
}
|
|
146
|
+
if (meta.mcp) part.mcp = { ...meta.mcp };
|
|
137
147
|
if (meta.title) part.title = meta.title;
|
|
148
|
+
if (meta.command) part.command = meta.command;
|
|
149
|
+
if (meta.url) part.url = meta.url;
|
|
138
150
|
if (meta.locations?.length) part.locations = meta.locations;
|
|
139
151
|
}
|
|
140
152
|
|
|
141
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Mutates a tool part into its terminal `completed`/`failed` state. A failure
|
|
155
|
+
* keeps its `metadata` (a command's exit code) and drops its `content`: what
|
|
156
|
+
* a failed call would have shown did not happen.
|
|
157
|
+
*/
|
|
142
158
|
export function completeToolPart(
|
|
143
159
|
part: ToolPart,
|
|
144
160
|
result: {
|
|
@@ -154,7 +170,13 @@ export function completeToolPart(
|
|
|
154
170
|
const start = part.state.status === "in_progress" ? part.state.time.start : Date.now();
|
|
155
171
|
const input = "input" in part.state ? part.state.input : {};
|
|
156
172
|
part.state = result.isError
|
|
157
|
-
? {
|
|
173
|
+
? {
|
|
174
|
+
status: "failed",
|
|
175
|
+
input,
|
|
176
|
+
error: result.output,
|
|
177
|
+
...(result.metadata && { metadata: result.metadata }),
|
|
178
|
+
time: { start, end: Date.now() },
|
|
179
|
+
}
|
|
158
180
|
: {
|
|
159
181
|
status: "completed",
|
|
160
182
|
input,
|
package/src/protocol/harness.ts
CHANGED
|
@@ -8,8 +8,10 @@ import { openVocabulary } from "./vocabulary.ts";
|
|
|
8
8
|
* - `acp` — any Agent Client Protocol v1 agent subprocess (`gemini --acp`,
|
|
9
9
|
* `claude-code-acp`, `codex-acp`, ACP registry agents); the launch
|
|
10
10
|
* command is operator-configured, never taken from the wire
|
|
11
|
+
* - `scripted` — a script the operator gives plays the agent (a product's
|
|
12
|
+
* free test double); registered only with its script
|
|
11
13
|
*/
|
|
12
|
-
export const AGENT_HARNESSES = ["claude-code", "codex-app-server", "acp"] as const;
|
|
14
|
+
export const AGENT_HARNESSES = ["claude-code", "codex-app-server", "acp", "scripted"] as const;
|
|
13
15
|
export type AgentHarness = (typeof AGENT_HARNESSES)[number];
|
|
14
16
|
export const AgentHarnessSchema = z.enum(AGENT_HARNESSES);
|
|
15
17
|
|
|
@@ -98,5 +100,13 @@ export const AgentCapabilitiesSchema = z.object({
|
|
|
98
100
|
* its next step, inside the same turn.
|
|
99
101
|
*/
|
|
100
102
|
steering: z.boolean().optional(),
|
|
103
|
+
/**
|
|
104
|
+
* The `RunConfig` fields this harness never applies: a turn that sets one
|
|
105
|
+
* runs without it, and says so (`turn.started.execution.notApplied`). A
|
|
106
|
+
* setting applied with another meaning is not listed, nor one the harness
|
|
107
|
+
* refuses (the turn fails). Always present from this engine; absent from
|
|
108
|
+
* an older one, which says nothing either way.
|
|
109
|
+
*/
|
|
110
|
+
ignoredSettings: z.array(z.string()).optional(),
|
|
101
111
|
});
|
|
102
112
|
export type AgentCapabilities = z.infer<typeof AgentCapabilitiesSchema>;
|
package/src/protocol/history.ts
CHANGED
|
@@ -26,6 +26,26 @@ export const HISTORY_MAX_RECORDS = 256;
|
|
|
26
26
|
export const HISTORY_WAIT_TIMEOUT_MS = 15_000;
|
|
27
27
|
export const HISTORY_MAX_BYTES = 8 * 1024 * 1024;
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The `_meta` key on what a durable store kept in place of a binary it could
|
|
31
|
+
* not keep whole: an image or file whose base64 `data` would not fit an
|
|
32
|
+
* event's record or a checkpoint. The entry is text, so every reader renders
|
|
33
|
+
* it as it is: a tool result's `content` image becomes a `text` entry, an
|
|
34
|
+
* image or file part a `text` part at the same address. Under this key it
|
|
35
|
+
* says what was there (`OmittedBinary`). Every client receives this entry,
|
|
36
|
+
* live and on replay alike: the stream delivers what the store kept.
|
|
37
|
+
*/
|
|
38
|
+
export const OMITTED_BINARY_META_KEY = "agent-server/omittedBinary";
|
|
39
|
+
/** What an entry under `OMITTED_BINARY_META_KEY` stands for. */
|
|
40
|
+
export interface OmittedBinary {
|
|
41
|
+
/** The entry it replaced: a tool result's or part's `image`, or a `file` part. */
|
|
42
|
+
type: "image" | "file";
|
|
43
|
+
mimeType: string;
|
|
44
|
+
/** The binary's size, decoded from its base64. */
|
|
45
|
+
bytes: number;
|
|
46
|
+
filename?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
29
49
|
const id = z.string().min(1).max(512);
|
|
30
50
|
const seq = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
31
51
|
/** A history: the store that writes it (`sourceId`) and its session. */
|
|
@@ -8,7 +8,7 @@ import { MetaSchema } from "./meta.ts";
|
|
|
8
8
|
import { type Part, PartSchema, type UnknownPart, decodePart } from "./parts.ts";
|
|
9
9
|
import { EpochMsSchema } from "./time.ts";
|
|
10
10
|
import { TokenUsageSchema } from "./tokens.ts";
|
|
11
|
-
import { ToolKindSchema, ToolLocationSchema } from "./tool-state.ts";
|
|
11
|
+
import { McpToolSchema, ToolKindSchema, ToolLocationSchema } from "./tool-state.ts";
|
|
12
12
|
import { openVocabulary } from "./vocabulary.ts";
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -374,8 +374,17 @@ export const PermissionToolCallSchema = z.object({
|
|
|
374
374
|
toolCallId: z.string().optional(),
|
|
375
375
|
toolName: z.string(),
|
|
376
376
|
kind: ToolKindSchema.optional(),
|
|
377
|
+
/** A call to an MCP tool: its server and tool, as on its tool part. */
|
|
378
|
+
mcp: McpToolSchema.optional(),
|
|
379
|
+
/** The label the engine or the agent gives the call, on every harness. */
|
|
377
380
|
title: z.string().optional(),
|
|
381
|
+
/** A command's line, as on its tool part. */
|
|
382
|
+
command: z.string().optional(),
|
|
383
|
+
/** A fetch's address, as on its tool part. */
|
|
384
|
+
url: z.string().optional(),
|
|
378
385
|
locations: z.array(ToolLocationSchema).optional(),
|
|
386
|
+
/** Why this call needs the person, in the harness's or the model's words, when it says. */
|
|
387
|
+
reason: z.string().optional(),
|
|
379
388
|
rawInput: z.record(z.string(), z.unknown()).optional(),
|
|
380
389
|
});
|
|
381
390
|
export type PermissionToolCall = z.infer<typeof PermissionToolCallSchema>;
|
|
@@ -35,21 +35,21 @@ export const GENERATED_MODEL_CATALOG: {
|
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
|
-
id: "
|
|
38
|
+
id: "sonnet",
|
|
39
39
|
harness: "claude-code",
|
|
40
|
-
label: "
|
|
41
|
-
description: "
|
|
42
|
-
resolvedId: "claude-
|
|
40
|
+
label: "Sonnet 5.5",
|
|
41
|
+
description: "Most efficient for simpler tasks",
|
|
42
|
+
resolvedId: "claude-sonnet-5-5",
|
|
43
43
|
thinking: {
|
|
44
44
|
levels: ["low", "medium", "high", "xhigh", "max"],
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
|
-
id: "
|
|
48
|
+
id: "fable",
|
|
49
49
|
harness: "claude-code",
|
|
50
|
-
label: "
|
|
51
|
-
description: "Most
|
|
52
|
-
resolvedId: "claude-
|
|
50
|
+
label: "Fable 5.1",
|
|
51
|
+
description: "Most capable for your hardest and longest-running tasks",
|
|
52
|
+
resolvedId: "claude-fable-5-1",
|
|
53
53
|
thinking: {
|
|
54
54
|
levels: ["low", "medium", "high", "xhigh", "max"],
|
|
55
55
|
},
|
|
@@ -150,6 +150,17 @@ export const GENERATED_MODEL_CATALOG: {
|
|
|
150
150
|
},
|
|
151
151
|
images: true,
|
|
152
152
|
},
|
|
153
|
+
{
|
|
154
|
+
id: "gpt-6.1-terra",
|
|
155
|
+
harness: "codex-app-server",
|
|
156
|
+
label: "GPT-6.1 Terra",
|
|
157
|
+
description: "GPT-6.1 Terra Codex model.",
|
|
158
|
+
thinking: {
|
|
159
|
+
levels: ["low", "medium", "high", "xhigh", "max", "ultra"],
|
|
160
|
+
default: "low",
|
|
161
|
+
},
|
|
162
|
+
images: true,
|
|
163
|
+
},
|
|
153
164
|
{
|
|
154
165
|
id: "gpt-6-sol",
|
|
155
166
|
harness: "codex-app-server",
|
package/src/protocol/parts.ts
CHANGED
|
@@ -2,7 +2,12 @@ import { z } from "zod";
|
|
|
2
2
|
import { isKnownPartType } from "./guards.ts";
|
|
3
3
|
import { MetaSchema } from "./meta.ts";
|
|
4
4
|
import { OpenTimeSpanSchema } from "./time.ts";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
McpToolSchema,
|
|
7
|
+
ToolKindSchema,
|
|
8
|
+
ToolLocationSchema,
|
|
9
|
+
ToolStateSchema,
|
|
10
|
+
} from "./tool-state.ts";
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* A Part is the atomic unit of message content, normalized across harnesses.
|
|
@@ -71,8 +76,14 @@ export const ToolPartSchema = PartBase.extend({
|
|
|
71
76
|
toolName: z.string(),
|
|
72
77
|
/** Normalized classification of what the call does (ACP ToolKind + `task`). */
|
|
73
78
|
kind: ToolKindSchema.optional(),
|
|
79
|
+
/** A call to an MCP tool: its server and tool, when the harness knows both. `toolName` stays the harness's own. */
|
|
80
|
+
mcp: McpToolSchema.optional(),
|
|
74
81
|
/** Human-readable label when the harness provides one. */
|
|
75
82
|
title: z.string().optional(),
|
|
83
|
+
/** A command's line as the agent wrote it, apart from any wrapper the harness adds. `state.input` stays the harness's own. */
|
|
84
|
+
command: z.string().optional(),
|
|
85
|
+
/** A fetch's address. */
|
|
86
|
+
url: z.string().optional(),
|
|
76
87
|
/** Files this call touches, for follow-along UIs. */
|
|
77
88
|
locations: z.array(ToolLocationSchema).optional(),
|
|
78
89
|
/** Present when this tool spawned a subagent (implies kind "task"). */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PermissionOption } from "./lifecycle.ts";
|
|
2
|
+
|
|
3
|
+
/** The ids of a plan's options: each is the permission mode the session goes on in. */
|
|
4
|
+
export const PLAN_OPTION_IDS = {
|
|
5
|
+
acceptEdits: "accept_edits",
|
|
6
|
+
approve: "default",
|
|
7
|
+
keepPlanning: "plan",
|
|
8
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
// @ref LLP 0001#d4--permission-requests-are-first-class-protocol — a plan's approval picks the mode
|
|
11
|
+
/**
|
|
12
|
+
* How a user answers an agent's plan: go on in a mode, or keep planning. Each
|
|
13
|
+
* option's id is the permission mode the session goes on in. These are Claude
|
|
14
|
+
* Code's own choices; Codex's TUI asks the same ("implement this plan" / "stay
|
|
15
|
+
* in Plan mode"). Auto-accepting edits is a standing choice for the edits to
|
|
16
|
+
* come (`allow_always`, as claude-agent-acp marks it), so an approver that
|
|
17
|
+
* takes the one-time approval implements asking for each edit. No standing
|
|
18
|
+
* rule answers a later plan: the broker keeps none for a harness's options.
|
|
19
|
+
*/
|
|
20
|
+
export const PLAN_OPTIONS: PermissionOption[] = [
|
|
21
|
+
{
|
|
22
|
+
optionId: PLAN_OPTION_IDS.acceptEdits,
|
|
23
|
+
name: "Yes, and auto-accept edits",
|
|
24
|
+
kind: "allow_always",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
optionId: PLAN_OPTION_IDS.approve,
|
|
28
|
+
name: "Yes, and manually approve edits",
|
|
29
|
+
kind: "allow_once",
|
|
30
|
+
},
|
|
31
|
+
{ optionId: PLAN_OPTION_IDS.keepPlanning, name: "No, keep planning", kind: "reject_once" },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/** What a plan's approval asks. */
|
|
35
|
+
export const PLAN_TITLE = "Implement this plan?";
|
|
@@ -60,6 +60,17 @@ export const ToolLocationSchema = z.object({
|
|
|
60
60
|
});
|
|
61
61
|
export type ToolLocation = z.infer<typeof ToolLocationSchema>;
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The MCP server and tool a call is to, as names, on every harness that
|
|
65
|
+
* knows both: what a product reads instead of each harness's spelling of
|
|
66
|
+
* `toolName` (`mcp__docs__search` on Claude, `docs.search` on Codex).
|
|
67
|
+
*/
|
|
68
|
+
export const McpToolSchema = z.object({
|
|
69
|
+
server: z.string(),
|
|
70
|
+
tool: z.string(),
|
|
71
|
+
});
|
|
72
|
+
export type McpTool = z.infer<typeof McpToolSchema>;
|
|
73
|
+
|
|
63
74
|
/**
|
|
64
75
|
* Structured, display-grade tool output. Three-audience doctrine:
|
|
65
76
|
* `ToolStateCompleted.output` (string) is the MODEL-facing factual record and
|
|
@@ -116,7 +127,7 @@ export const ToolStateCompletedSchema = z.object({
|
|
|
116
127
|
output: z.string(),
|
|
117
128
|
/** Display-grade structured output, when expressible (diffs, images, terminals). */
|
|
118
129
|
content: z.array(ToolResultContentSchema).optional(),
|
|
119
|
-
/** Machine channel: harness-native extras (
|
|
130
|
+
/** Machine channel: harness-native extras (a command's `exitCode`, …). */
|
|
120
131
|
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
121
132
|
title: z.string().optional(),
|
|
122
133
|
time: TimeSpanSchema,
|
|
@@ -141,6 +152,8 @@ export const ToolStateFailedSchema = z.object({
|
|
|
141
152
|
error: z.string(),
|
|
142
153
|
/** Set when the engine closed the tool, absent when the harness reported the failure. */
|
|
143
154
|
closure: ToolClosureSchema.optional(),
|
|
155
|
+
/** Machine channel, as on a completed tool: a failed command's `exitCode`. */
|
|
156
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
144
157
|
time: TimeSpanSchema,
|
|
145
158
|
_meta: MetaSchema,
|
|
146
159
|
});
|
package/src/protocol/wire.ts
CHANGED
|
@@ -480,6 +480,18 @@ export const RECOVERY_REASONS = ["not_owned", "not_verified", "not_stopped"] as
|
|
|
480
480
|
export const RecoveryReasonSchema = z.enum(RECOVERY_REASONS);
|
|
481
481
|
export type RecoveryReason = z.infer<typeof RecoveryReasonSchema>;
|
|
482
482
|
|
|
483
|
+
/**
|
|
484
|
+
* A session's latest turn: `stopReason` and `error` as its `turn.ended` said,
|
|
485
|
+
* both absent while it runs. One a restart cut off ended `error`, category
|
|
486
|
+
* `server_restart`.
|
|
487
|
+
*/
|
|
488
|
+
export const LastTurnSchema = TurnEndedEventSchema.pick({
|
|
489
|
+
turnId: true,
|
|
490
|
+
stopReason: true,
|
|
491
|
+
error: true,
|
|
492
|
+
}).partial({ stopReason: true });
|
|
493
|
+
export type LastTurn = z.infer<typeof LastTurnSchema>;
|
|
494
|
+
|
|
483
495
|
export const DurableSessionSchema = z.object({
|
|
484
496
|
sessionId: z.string(),
|
|
485
497
|
harness: AgentHarnessSchema,
|
|
@@ -494,6 +506,8 @@ export const DurableSessionSchema = z.object({
|
|
|
494
506
|
recoveryRequired: z.boolean(),
|
|
495
507
|
/** Why, while `recoveryRequired` is set. */
|
|
496
508
|
recoveryReason: RecoveryReasonSchema.optional(),
|
|
509
|
+
/** Its latest turn, once it has admitted one (`session/get` only). */
|
|
510
|
+
lastTurn: LastTurnSchema.optional(),
|
|
497
511
|
});
|
|
498
512
|
export type DurableSession = z.infer<typeof DurableSessionSchema>;
|
|
499
513
|
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import { Readable, Writable } from "node:stream";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
AgentApp,
|
|
4
|
+
AgentConnection,
|
|
5
|
+
ElicitationCapabilities,
|
|
6
|
+
McpCapabilities,
|
|
7
|
+
McpServer,
|
|
8
|
+
} from "@agentclientprotocol/sdk";
|
|
3
9
|
import type { AgentRuntime, EventSink } from "../../core/index.ts";
|
|
4
10
|
import { generateUUIDv7 } from "../../core/index.ts";
|
|
5
11
|
import type {
|
|
6
12
|
AgentHarness,
|
|
13
|
+
ElicitationOutcome,
|
|
7
14
|
LifecycleEvent,
|
|
8
15
|
PermissionMode,
|
|
9
16
|
PermissionOutcome,
|
|
17
|
+
ThinkingLevel,
|
|
10
18
|
} from "../../protocol/index.ts";
|
|
11
19
|
import { SessionRecords } from "./session-records.ts";
|
|
12
20
|
import {
|
|
13
21
|
AcpUpdateTranslator,
|
|
22
|
+
fromAcpElicitation,
|
|
14
23
|
fromAcpMcpServers,
|
|
15
24
|
fromPromptBlocks,
|
|
25
|
+
toAcpElicitation,
|
|
16
26
|
toAcpPermissionRequest,
|
|
17
27
|
toAcpPromptResponse,
|
|
18
28
|
} from "./translate.ts";
|
|
@@ -24,7 +34,12 @@ export interface AcpBindingOptions {
|
|
|
24
34
|
runtime: AgentRuntime;
|
|
25
35
|
/** The harness this ACP agent fronts (operator-chosen at launch). */
|
|
26
36
|
harness: AgentHarness;
|
|
37
|
+
/**
|
|
38
|
+
* The model and thinking level every turn runs at: the operator's, never an
|
|
39
|
+
* ACP client's. Absent: the harness's own default.
|
|
40
|
+
*/
|
|
27
41
|
model?: string;
|
|
42
|
+
thinkingLevel?: ThinkingLevel;
|
|
28
43
|
/** Defaults to `default` so tool approvals flow to the ACP client. */
|
|
29
44
|
permissionMode?: PermissionMode;
|
|
30
45
|
name?: string;
|
|
@@ -45,6 +60,19 @@ interface BoundSession {
|
|
|
45
60
|
permissionMode: PermissionMode;
|
|
46
61
|
}
|
|
47
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The MCP transports beside stdio the fronted harness attaches, as the
|
|
65
|
+
* binding advertises them. The `acp` harness has none: the agent behind it
|
|
66
|
+
* decides what it takes, and this binding cannot ask.
|
|
67
|
+
*/
|
|
68
|
+
const MCP_TRANSPORTS: Partial<Record<AgentHarness, McpCapabilities>> = {
|
|
69
|
+
"claude-code": { http: true, sse: true },
|
|
70
|
+
// Codex takes Streamable HTTP, never legacy SSE.
|
|
71
|
+
"codex-app-server": { http: true },
|
|
72
|
+
// Its `call` step speaks HTTP alone.
|
|
73
|
+
scripted: { http: true },
|
|
74
|
+
};
|
|
75
|
+
|
|
48
76
|
/** What each permission mode is called in an ACP client's mode picker. */
|
|
49
77
|
const MODE_NAMES: Record<PermissionMode, string> = {
|
|
50
78
|
default: "Default",
|
|
@@ -69,18 +97,34 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
|
|
|
69
97
|
const acp = await import("@agentclientprotocol/sdk");
|
|
70
98
|
const { runtime, harness } = options;
|
|
71
99
|
const sessions = new Map<string, BoundSession>();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
100
|
+
/** A session's MCP servers as the engine takes them, or the request refused. */
|
|
101
|
+
const mcpServersOf = (servers: McpServer[] | undefined) => {
|
|
102
|
+
try {
|
|
103
|
+
const taken = fromAcpMcpServers(servers);
|
|
104
|
+
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — what Codex cannot attach is refused at admission
|
|
105
|
+
// A Codex turn that names no home carries its servers in its thread,
|
|
106
|
+
// so they pass on; what Codex would fail the turn over is refused here.
|
|
107
|
+
if (harness === "codex-app-server")
|
|
108
|
+
for (const [name, server] of Object.entries(taken ?? {})) {
|
|
109
|
+
if (server.type === "sse")
|
|
110
|
+
throw new Error(
|
|
111
|
+
`MCP server "${name}" uses the sse transport, which Codex does not attach (it takes stdio and http)`,
|
|
112
|
+
);
|
|
113
|
+
if (name === "codex_apps")
|
|
114
|
+
throw new Error("MCP server name codex_apps is reserved by Codex");
|
|
115
|
+
}
|
|
116
|
+
return taken;
|
|
117
|
+
} catch (error) {
|
|
76
118
|
throw acp.RequestError.invalidParams(
|
|
77
119
|
undefined,
|
|
78
|
-
|
|
120
|
+
error instanceof Error ? error.message : String(error),
|
|
79
121
|
);
|
|
80
122
|
}
|
|
81
123
|
};
|
|
82
124
|
|
|
83
125
|
const records = new SessionRecords(options.sessionDir, harness);
|
|
126
|
+
/** What the client said at `initialize` it can ask the person: none until it says. */
|
|
127
|
+
let elicitation: ElicitationCapabilities | null | undefined;
|
|
84
128
|
|
|
85
129
|
const requireSession = (sessionId: string): BoundSession => {
|
|
86
130
|
const session = sessions.get(sessionId);
|
|
@@ -100,30 +144,33 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
|
|
|
100
144
|
|
|
101
145
|
return acp
|
|
102
146
|
.agent({ name: options.name ?? "agent-server" })
|
|
103
|
-
.onRequest("initialize", (ctx) =>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
147
|
+
.onRequest("initialize", (ctx) => {
|
|
148
|
+
elicitation = ctx.params.clientCapabilities?.elicitation;
|
|
149
|
+
return {
|
|
150
|
+
protocolVersion: Math.min(ctx.params.protocolVersion, PROTOCOL_VERSION),
|
|
151
|
+
agentInfo: { name: options.name ?? "agent-server", version: options.version ?? "0.0.0" },
|
|
152
|
+
agentCapabilities: {
|
|
153
|
+
promptCapabilities: { image: true },
|
|
154
|
+
// Clients send HTTP/SSE servers only to agents that advertise them.
|
|
155
|
+
...(MCP_TRANSPORTS[harness] && { mcpCapabilities: MCP_TRANSPORTS[harness] }),
|
|
156
|
+
sessionCapabilities: { resume: {}, close: {} },
|
|
157
|
+
},
|
|
158
|
+
authMethods: [],
|
|
159
|
+
};
|
|
160
|
+
})
|
|
114
161
|
.onRequest("session/new", (ctx) => {
|
|
115
|
-
|
|
162
|
+
const mcpServers = mcpServersOf(ctx.params.mcpServers);
|
|
116
163
|
const sessionId = generateUUIDv7();
|
|
117
164
|
const session: BoundSession = {
|
|
118
165
|
cwd: ctx.params.cwd,
|
|
119
|
-
mcpServers
|
|
166
|
+
mcpServers,
|
|
120
167
|
permissionMode: startMode,
|
|
121
168
|
};
|
|
122
169
|
sessions.set(sessionId, session);
|
|
123
170
|
return { sessionId, modes: modes(session) };
|
|
124
171
|
})
|
|
125
172
|
.onRequest("session/resume", async (ctx) => {
|
|
126
|
-
|
|
173
|
+
const mcpServers = mcpServersOf(ctx.params.mcpServers);
|
|
127
174
|
let session = sessions.get(ctx.params.sessionId);
|
|
128
175
|
if (!session) {
|
|
129
176
|
const resumeSessionId = await records.recall(ctx.params.sessionId);
|
|
@@ -132,7 +179,7 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
|
|
|
132
179
|
sessions.set(ctx.params.sessionId, session);
|
|
133
180
|
}
|
|
134
181
|
session.cwd = ctx.params.cwd;
|
|
135
|
-
if (ctx.params.mcpServers) session.mcpServers =
|
|
182
|
+
if (ctx.params.mcpServers) session.mcpServers = mcpServers;
|
|
136
183
|
return { modes: modes(session) };
|
|
137
184
|
})
|
|
138
185
|
.onRequest("session/set_mode", (ctx) => {
|
|
@@ -157,6 +204,8 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
|
|
|
157
204
|
.onRequest("session/prompt", async (ctx) => {
|
|
158
205
|
const session = requireSession(ctx.params.sessionId);
|
|
159
206
|
const translator = new AcpUpdateTranslator();
|
|
207
|
+
/** The questions asked of the client and not yet answered, by request id. */
|
|
208
|
+
const asked = new Map<string, AbortController>();
|
|
160
209
|
const sink: EventSink = {
|
|
161
210
|
emit: async (event: LifecycleEvent) => {
|
|
162
211
|
if (event.type === "permission.requested") {
|
|
@@ -174,6 +223,39 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
|
|
|
174
223
|
runtime.respondPermission(ctx.params.sessionId, event.requestId, outcome);
|
|
175
224
|
return;
|
|
176
225
|
}
|
|
226
|
+
if (event.type === "elicitation.requested") {
|
|
227
|
+
// Asked of the client in a mode it said it takes; any other is declined.
|
|
228
|
+
const request = toAcpElicitation(ctx.params.sessionId, event, elicitation);
|
|
229
|
+
if (!request) {
|
|
230
|
+
runtime.respondElicitation(ctx.params.sessionId, event.requestId, {
|
|
231
|
+
action: "decline",
|
|
232
|
+
});
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
// Sent in order, its answer not awaited here: the person may take
|
|
236
|
+
// as long as they like, and the turn's cancel and end must not
|
|
237
|
+
// wait behind them.
|
|
238
|
+
const abort = new AbortController();
|
|
239
|
+
asked.set(event.requestId, abort);
|
|
240
|
+
// Answered by other means first (a cancel, the turn's end): a reply is too late.
|
|
241
|
+
const open = () => asked.get(event.requestId) === abort;
|
|
242
|
+
void ctx.client
|
|
243
|
+
.request("elicitation/create", request, { cancellationSignal: abort.signal })
|
|
244
|
+
.then((response) => (open() ? fromAcpElicitation(event, response) : undefined))
|
|
245
|
+
// A failed request, or a reply that does not read, is a cancel.
|
|
246
|
+
.catch((): ElicitationOutcome => ({ action: "cancel" }))
|
|
247
|
+
.then((outcome) => {
|
|
248
|
+
if (!outcome || !open()) return;
|
|
249
|
+
asked.delete(event.requestId);
|
|
250
|
+
runtime.respondElicitation(ctx.params.sessionId, event.requestId, outcome);
|
|
251
|
+
});
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (event.type === "elicitation.resolved") {
|
|
255
|
+
// The broker answered it without the client: the question is withdrawn.
|
|
256
|
+
asked.get(event.requestId)?.abort();
|
|
257
|
+
asked.delete(event.requestId);
|
|
258
|
+
}
|
|
177
259
|
if (event.type === "session.mode") {
|
|
178
260
|
// The agent switched modes (an approved plan, or Claude planning by
|
|
179
261
|
// itself): the session goes on in it, and the client hears so.
|
|
@@ -194,7 +276,7 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
|
|
|
194
276
|
}
|
|
195
277
|
},
|
|
196
278
|
};
|
|
197
|
-
const
|
|
279
|
+
const run = runtime.run(
|
|
198
280
|
{
|
|
199
281
|
sessionId: ctx.params.sessionId,
|
|
200
282
|
turnId: generateUUIDv7(),
|
|
@@ -203,13 +285,22 @@ export async function createAcpAgentApp(options: AcpBindingOptions): Promise<Age
|
|
|
203
285
|
harness,
|
|
204
286
|
cwd: session.cwd,
|
|
205
287
|
model: options.model,
|
|
288
|
+
thinkingLevel: options.thinkingLevel,
|
|
206
289
|
permissionMode: session.permissionMode,
|
|
290
|
+
// A client that takes a form or a URL is asked what it takes; any
|
|
291
|
+
// other request is declined (`toAcpElicitation`).
|
|
292
|
+
elicitation: Boolean(elicitation?.form || elicitation?.url),
|
|
207
293
|
mcpServers: session.mcpServers,
|
|
208
294
|
resumeSessionId: session.resumeSessionId,
|
|
209
295
|
},
|
|
210
296
|
},
|
|
211
297
|
sink,
|
|
212
298
|
);
|
|
299
|
+
// The turn's end answers every question still open; none outlives it.
|
|
300
|
+
const summary = await run.finally(() => {
|
|
301
|
+
for (const abort of asked.values()) abort.abort();
|
|
302
|
+
asked.clear();
|
|
303
|
+
});
|
|
213
304
|
if (summary.nativeSessionId) {
|
|
214
305
|
session.resumeSessionId = undefined;
|
|
215
306
|
await records.remember(ctx.params.sessionId, summary.nativeSessionId);
|