@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ThinkingLevel, clampThinkingLevel } from "../../../protocol/index.ts";
|
|
2
2
|
|
|
3
3
|
/** Codex reasoning-effort string for a level (matches the `ReasoningEffort` enum). */
|
|
4
|
-
|
|
4
|
+
type CodexReasoningEffort =
|
|
5
5
|
| "none"
|
|
6
6
|
| "minimal"
|
|
7
7
|
| "low"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, realpathSync } from "node:fs";
|
|
1
|
+
import { closeSync, existsSync, openSync, realpathSync, statSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { isAbsolute, resolve } from "node:path";
|
|
4
4
|
import { InvalidRequestError } from "../../utils/errors.ts";
|
|
@@ -8,10 +8,12 @@ import type { InheritConfig } from "../inherit-config.ts";
|
|
|
8
8
|
/**
|
|
9
9
|
* Which logical session owns each `CODEX_HOME` its turns name. A turn that
|
|
10
10
|
* names one claims it for its session, which keeps it until it is released,
|
|
11
|
-
* through process eviction and failed preparation: one session to a home
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* the user's configuration.
|
|
11
|
+
* through process eviction and failed preparation: one session to a home,
|
|
12
|
+
* since the engine writes the turn's MCP servers there. Below
|
|
13
|
+
* `inheritConfig: "all"` every turn must name one: the user's own home holds
|
|
14
|
+
* the user's configuration. At `all` a turn that names none runs in the
|
|
15
|
+
* process's, the user's own, which is never claimed, nor written to: its
|
|
16
|
+
* MCP servers go in its thread's config instead (`mcp.ts`).
|
|
15
17
|
*/
|
|
16
18
|
export class CodexHomes {
|
|
17
19
|
private readonly owners = new Map<string, string>();
|
|
@@ -19,7 +21,7 @@ export class CodexHomes {
|
|
|
19
21
|
constructor(private readonly level: InheritConfig = "all") {}
|
|
20
22
|
|
|
21
23
|
/** Whether the turn runs in a home of its session's own, which it claims. */
|
|
22
|
-
claim(options: AgentExecuteOptions
|
|
24
|
+
claim(options: AgentExecuteOptions): boolean {
|
|
23
25
|
const home = options.env?.CODEX_HOME;
|
|
24
26
|
// @ref LLP 0001#d17--a-turn-inherits-what-the-operator-chooses-all-the-projects-or-none — every turn's home, below `all`
|
|
25
27
|
const needs =
|
|
@@ -28,22 +30,27 @@ export class CodexHomes {
|
|
|
28
30
|
const refused = (message: string) =>
|
|
29
31
|
new InvalidRequestError([{ path: "env.CODEX_HOME", message }]);
|
|
30
32
|
if (!home) {
|
|
31
|
-
if (this.level === "all"
|
|
33
|
+
if (this.level === "all") return false;
|
|
32
34
|
throw refused(
|
|
33
35
|
`${needs} requires a session-specific one (an existing absolute folder no other session uses)`,
|
|
34
36
|
);
|
|
35
37
|
}
|
|
36
38
|
if (!isAbsolute(home)) throw refused("must be an absolute path");
|
|
37
39
|
const shared = resolve(process.env.CODEX_HOME ?? `${homedir()}/.codex`);
|
|
38
|
-
|
|
40
|
+
// A home a turn names is written to. At `all` a turn runs in the user's
|
|
41
|
+
// by naming none.
|
|
42
|
+
const isShared = () =>
|
|
43
|
+
refused(
|
|
44
|
+
`${needs} cannot use the user's shared one${this.level === "all" ? " as a session's home; leave it out to run there" : ""}`,
|
|
45
|
+
);
|
|
46
|
+
if (resolve(home) === shared) throw isShared();
|
|
39
47
|
let path: string;
|
|
40
48
|
try {
|
|
41
49
|
path = realpathSync(home);
|
|
42
50
|
} catch {
|
|
43
51
|
throw refused(`${home} must be an existing folder`);
|
|
44
52
|
}
|
|
45
|
-
if (existsSync(shared) && path === realpathSync(shared))
|
|
46
|
-
throw refused(`${needs} cannot use the user's shared one`);
|
|
53
|
+
if (existsSync(shared) && path === realpathSync(shared)) throw isShared();
|
|
47
54
|
const owner = this.owners.get(path);
|
|
48
55
|
if (owner && owner !== options.sessionId) {
|
|
49
56
|
throw refused(
|
|
@@ -62,3 +69,45 @@ export class CodexHomes {
|
|
|
62
69
|
this.owners.clear();
|
|
63
70
|
}
|
|
64
71
|
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Which folder a `CODEX_HOME` is now (its device and inode), `"gone"` when
|
|
75
|
+
* there is none; nothing when the turn names no home. A process keeps the
|
|
76
|
+
* files it opened in the home it started in, so a home removed or replaced
|
|
77
|
+
* under it is another home: the conversation it writes is in deleted files,
|
|
78
|
+
* and the `config.toml` it reads is not the one there. The comparison holds
|
|
79
|
+
* only while the session holds its home open (`holdHome`): on ext4 a removed
|
|
80
|
+
* folder's inode number goes to the next folder made, at once, unless a
|
|
81
|
+
* handle on the old one is open (measured under Node 22 and Bun 1.3.14), so
|
|
82
|
+
* `rm -rf home; mkdir home` would otherwise read as the same folder.
|
|
83
|
+
*/
|
|
84
|
+
export function homeIdentity(home: string | undefined): string | undefined {
|
|
85
|
+
if (!home) return undefined;
|
|
86
|
+
try {
|
|
87
|
+
const { dev, ino } = statSync(home);
|
|
88
|
+
return `${dev}:${ino}`;
|
|
89
|
+
} catch {
|
|
90
|
+
return "gone";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Hold the folder a `CODEX_HOME` is now open, keeping its inode number its
|
|
96
|
+
* own (`homeIdentity`), until the answer is called; calling it again does
|
|
97
|
+
* nothing. A turn that names no home, or a home that cannot be opened (no
|
|
98
|
+
* folder, a platform that does not open directories), holds nothing.
|
|
99
|
+
*/
|
|
100
|
+
export function holdHome(home: string | undefined): () => void {
|
|
101
|
+
if (!home) return () => {};
|
|
102
|
+
let fd: number | undefined;
|
|
103
|
+
try {
|
|
104
|
+
fd = openSync(home, "r");
|
|
105
|
+
} catch {
|
|
106
|
+
return () => {};
|
|
107
|
+
}
|
|
108
|
+
return () => {
|
|
109
|
+
if (fd === undefined) return;
|
|
110
|
+
closeSync(fd);
|
|
111
|
+
fd = undefined;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ToolKind,
|
|
3
|
+
ToolLocation,
|
|
4
|
+
ToolMeta,
|
|
5
|
+
ToolResultContent,
|
|
6
|
+
} from "../../../protocol/index.ts";
|
|
7
|
+
import { isRecord } from "../../utils/is-record.ts";
|
|
8
|
+
import { hunkDiff } from "../diffs.ts";
|
|
2
9
|
import type { CodexFileChange, CodexItem } from "./protocol.ts";
|
|
3
10
|
|
|
4
11
|
/** Codex tools are already normalized names; kinds are fixed per item type. */
|
|
@@ -7,6 +14,7 @@ export const CODEX_TOOL_KINDS = {
|
|
|
7
14
|
apply_patch: "edit",
|
|
8
15
|
web_search: "fetch",
|
|
9
16
|
mcp: "other",
|
|
17
|
+
image_generation: "other",
|
|
10
18
|
/** The plan Codex proposes in Plan mode, put to the user like Claude's ExitPlanMode. */
|
|
11
19
|
plan: "switch_mode",
|
|
12
20
|
} as const satisfies Record<string, ToolKind>;
|
|
@@ -19,8 +27,15 @@ export const CODEX_TOOL_KINDS = {
|
|
|
19
27
|
export interface CodexToolDescriptor {
|
|
20
28
|
toolName(item: CodexItem): string;
|
|
21
29
|
input(item: CodexItem): Record<string, unknown>;
|
|
30
|
+
/** Codex says this tool's input only once it is done: its completed item sets it again. */
|
|
31
|
+
inputAtCompletion?: true;
|
|
22
32
|
meta(item: CodexItem): ToolMeta;
|
|
23
|
-
result(item: CodexItem): {
|
|
33
|
+
result(item: CodexItem): {
|
|
34
|
+
output: string;
|
|
35
|
+
isError: boolean;
|
|
36
|
+
content?: ToolResultContent[];
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
};
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
function pickCodexError(err: CodexItem["error"]): string {
|
|
@@ -28,24 +43,53 @@ function pickCodexError(err: CodexItem["error"]): string {
|
|
|
28
43
|
return typeof err === "string" ? err : (err.message ?? "");
|
|
29
44
|
}
|
|
30
45
|
|
|
31
|
-
/**
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
/** Base64 a block carries (an image's or audio's `data`, an embedded resource's `blob`). */
|
|
47
|
+
function carriesBytes(block: Record<string, unknown>): boolean {
|
|
48
|
+
const resource = isRecord(block.resource) ? block.resource : {};
|
|
49
|
+
return typeof block.data === "string" || typeof resource.blob === "string";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A block's MIME type, its own or its embedded resource's. */
|
|
53
|
+
function blockMimeType(block: Record<string, unknown>): string | undefined {
|
|
54
|
+
const resource = isRecord(block.resource) ? block.resource : {};
|
|
55
|
+
const mimeType = block.mimeType ?? resource.mimeType;
|
|
56
|
+
return typeof mimeType === "string" ? mimeType : undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* One MCP content block, as the stream shows it: what `output` says of it,
|
|
61
|
+
* and its `content` entry. Text is text and an image an image; another
|
|
62
|
+
* block is the text `output` has for it. No block's bytes are ever text: a
|
|
63
|
+
* placeholder naming its type (and MIME type) stands for them.
|
|
64
|
+
*/
|
|
65
|
+
function mcpBlock(block: unknown): { shown: string; entry: ToolResultContent } {
|
|
66
|
+
if (isRecord(block) && block.type === "text" && typeof block.text === "string")
|
|
67
|
+
return { shown: block.text, entry: { type: "text", text: block.text } };
|
|
68
|
+
let shown = JSON.stringify(block);
|
|
69
|
+
if (isRecord(block) && carriesBytes(block)) {
|
|
70
|
+
const mimeType = blockMimeType(block);
|
|
71
|
+
shown = `[${String(block.type ?? "binary")}${mimeType ? ` ${mimeType}` : ""}]`;
|
|
72
|
+
if (block.type === "image" && typeof block.data === "string" && mimeType)
|
|
73
|
+
return { shown, entry: { type: "image", data: block.data, mimeType } };
|
|
47
74
|
}
|
|
48
|
-
return
|
|
75
|
+
return { shown, entry: { type: "text", text: shown } };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// @ref LLP 0002#tool-output-has-three-audiences — `content` is display-grade, `output` model-facing
|
|
79
|
+
/**
|
|
80
|
+
* An MCP tool's result: its blocks as `output` shows them, joined. A result
|
|
81
|
+
* with an image also has `content`, every block in order, as Claude's tool
|
|
82
|
+
* results do; one without has nothing `output` does not say.
|
|
83
|
+
*/
|
|
84
|
+
function mcpResult(result: unknown): { output: string; content?: ToolResultContent[] } {
|
|
85
|
+
const blocks = isRecord(result) && "content" in result ? result.content : result;
|
|
86
|
+
if (blocks == null) return { output: "" };
|
|
87
|
+
if (typeof blocks === "string") return { output: blocks };
|
|
88
|
+
if (!Array.isArray(blocks)) return { output: JSON.stringify(blocks) };
|
|
89
|
+
const read = blocks.map(mcpBlock);
|
|
90
|
+
const output = read.map(({ shown }) => shown).join("");
|
|
91
|
+
if (!read.some(({ entry }) => entry.type === "image")) return { output };
|
|
92
|
+
return { output, content: read.map(({ entry }) => entry) };
|
|
49
93
|
}
|
|
50
94
|
|
|
51
95
|
const failed = (item: CodexItem) => item.status === "failed";
|
|
@@ -64,11 +108,125 @@ function describeChange(change: CodexFileChange): string {
|
|
|
64
108
|
return `${kind ?? "change"} ${change.path}${to ? ` -> ${to}` : ""}`;
|
|
65
109
|
}
|
|
66
110
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
111
|
+
/** A shell Codex runs a command in, `-lc` and its one argument, the line. */
|
|
112
|
+
const SHELL_WRAPPER = /^(?:\S*\/)?(?:ba|z)?sh -lc (.+)$/s;
|
|
113
|
+
/** Characters a word may hold unquoted and mean only themselves. */
|
|
114
|
+
const PLAIN = /[A-Za-z0-9_@%+=:,./-]/;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The one shell word `text` is, unquoted as the shell would; undefined when
|
|
118
|
+
* it is several words, unterminated, or would expand (an unquoted special
|
|
119
|
+
* character, a `$` or a backquote inside double quotes).
|
|
120
|
+
*/
|
|
121
|
+
function shellWord(text: string): string | undefined {
|
|
122
|
+
let word = "";
|
|
123
|
+
let i = 0;
|
|
124
|
+
while (i < text.length) {
|
|
125
|
+
const c = text[i] as string;
|
|
126
|
+
if (c === "'") {
|
|
127
|
+
const end = text.indexOf("'", i + 1);
|
|
128
|
+
if (end < 0) return undefined;
|
|
129
|
+
word += text.slice(i + 1, end);
|
|
130
|
+
i = end + 1;
|
|
131
|
+
} else if (c === '"') {
|
|
132
|
+
i++;
|
|
133
|
+
for (;;) {
|
|
134
|
+
const d = text[i];
|
|
135
|
+
if (d === undefined || d === "$" || d === "`") return undefined;
|
|
136
|
+
if (d === '"') break;
|
|
137
|
+
if (d === "\\" && '"\\$`'.includes(text[i + 1] ?? "")) {
|
|
138
|
+
word += text[i + 1];
|
|
139
|
+
i += 2;
|
|
140
|
+
} else {
|
|
141
|
+
word += d;
|
|
142
|
+
i++;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
i++;
|
|
146
|
+
} else if (PLAIN.test(c)) {
|
|
147
|
+
word += c;
|
|
148
|
+
i++;
|
|
149
|
+
} else return undefined;
|
|
150
|
+
}
|
|
151
|
+
return word;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// @ref LLP 0002#a-tool-call-says-what-it-acts-on — the line, apart from the shell Codex adds
|
|
155
|
+
/**
|
|
156
|
+
* The line a Codex command runs: Codex wraps it in a shell
|
|
157
|
+
* (`/bin/zsh -lc '<line>'`, quoted as Codex quotes it), and the line is that
|
|
158
|
+
* shell's one argument, unquoted. Codex's `commandActions` are not it: they
|
|
159
|
+
* keep only the pieces Codex recognizes (`cd sub && cat c.txt` is one read of
|
|
160
|
+
* `cat c.txt`) and normalize their quoting. A command of any other shape is
|
|
161
|
+
* as Codex reports it; one that is not a string, nothing.
|
|
162
|
+
*/
|
|
163
|
+
export function codexCommandLine(command: unknown): string | undefined {
|
|
164
|
+
if (typeof command !== "string" || !command) return undefined;
|
|
165
|
+
const quoted = SHELL_WRAPPER.exec(command)?.[1];
|
|
166
|
+
return (quoted !== undefined && shellWord(quoted)) || command;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** A change's kind (`add`, `delete`, `update`), and where an update moves the file. */
|
|
170
|
+
function changeKind(change: CodexFileChange): { kind?: string; movedTo?: string } {
|
|
171
|
+
if (typeof change.kind === "string") return { kind: change.kind };
|
|
172
|
+
return { kind: change.kind?.type, movedTo: change.kind?.move_path ?? undefined };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* An update's unified diff as hunks: each `@@` header's start line in the
|
|
177
|
+
* new file, and the lines under it. A move's diff ends with Codex's own
|
|
178
|
+
* `Moved to:` trailer, which is no line of the file.
|
|
179
|
+
*/
|
|
180
|
+
function updateHunks(diff: string, movedTo?: string): Array<{ line?: number; lines: string[] }> {
|
|
181
|
+
const trailer = movedTo !== undefined ? `\n\nMoved to: ${movedTo}` : undefined;
|
|
182
|
+
const body = trailer && diff.endsWith(trailer) ? diff.slice(0, -trailer.length) : diff;
|
|
183
|
+
const hunks: Array<{ line?: number; lines: string[] }> = [];
|
|
184
|
+
for (const line of body.replace(/\n$/, "").split("\n")) {
|
|
185
|
+
if (line.startsWith("@@")) {
|
|
186
|
+
const start = /^@@ -\d+(?:,\d+)? \+(\d+)/.exec(line)?.[1];
|
|
187
|
+
hunks.push({ ...(start !== undefined && { line: Number(start) }), lines: [] });
|
|
188
|
+
} else hunks.at(-1)?.lines.push(line);
|
|
189
|
+
}
|
|
190
|
+
return hunks;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* What a file change shows: a `diff` entry per hunk of an update, at the
|
|
195
|
+
* file it leaves (a move's destination); an add's content as `newText`; a
|
|
196
|
+
* delete's as `oldText`, its `newText` empty. Its locations are each hunk's
|
|
197
|
+
* start in the new file, a move's source too, and an add's or a delete's
|
|
198
|
+
* path alone.
|
|
199
|
+
*/
|
|
200
|
+
export function codexChangeView(changes: CodexFileChange[] | undefined): {
|
|
201
|
+
content: ToolResultContent[];
|
|
202
|
+
locations: ToolLocation[];
|
|
203
|
+
} {
|
|
204
|
+
const content: ToolResultContent[] = [];
|
|
205
|
+
const locations: ToolLocation[] = [];
|
|
206
|
+
for (const change of changes ?? []) {
|
|
207
|
+
const { kind, movedTo } = changeKind(change);
|
|
208
|
+
const diff = change.diff ?? "";
|
|
209
|
+
if (kind === "add" || kind === "delete") {
|
|
210
|
+
locations.push({ path: change.path });
|
|
211
|
+
if (change.diff !== undefined)
|
|
212
|
+
content.push(
|
|
213
|
+
kind === "add"
|
|
214
|
+
? { type: "diff", path: change.path, newText: diff }
|
|
215
|
+
: { type: "diff", path: change.path, oldText: diff, newText: "" },
|
|
216
|
+
);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const path = movedTo ?? change.path;
|
|
220
|
+
if (movedTo) locations.push({ path: change.path });
|
|
221
|
+
const hunks = updateHunks(diff, movedTo);
|
|
222
|
+
if (!hunks.length) locations.push({ path });
|
|
223
|
+
for (const hunk of hunks) {
|
|
224
|
+
locations.push({ path, ...(hunk.line !== undefined && { line: hunk.line }) });
|
|
225
|
+
const entry = hunkDiff(path, hunk.lines);
|
|
226
|
+
if (entry) content.push(entry);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return { content, locations };
|
|
72
230
|
}
|
|
73
231
|
|
|
74
232
|
const CODEX_TOOL_ITEMS: Record<string, CodexToolDescriptor> = {
|
|
@@ -96,13 +254,17 @@ const CODEX_TOOL_ITEMS: Record<string, CodexToolDescriptor> = {
|
|
|
96
254
|
commandExecution: {
|
|
97
255
|
toolName: () => "shell",
|
|
98
256
|
input: (item) => ({ command: item.command ?? "" }),
|
|
99
|
-
meta: () =>
|
|
257
|
+
meta: (item) => {
|
|
258
|
+
const command = codexCommandLine(item.command);
|
|
259
|
+
return { kind: CODEX_TOOL_KINDS.shell, ...(command && { command }) };
|
|
260
|
+
},
|
|
100
261
|
result: (item) =>
|
|
101
262
|
item.status === "declined"
|
|
102
263
|
? { output: CODEX_COMMAND_DECLINED, isError: true }
|
|
103
264
|
: {
|
|
104
265
|
output: item.aggregatedOutput ?? "",
|
|
105
266
|
isError: failed(item) || (item.exitCode ?? 0) !== 0,
|
|
267
|
+
...(typeof item.exitCode === "number" && { metadata: { exitCode: item.exitCode } }),
|
|
106
268
|
},
|
|
107
269
|
},
|
|
108
270
|
fileChange: {
|
|
@@ -110,28 +272,54 @@ const CODEX_TOOL_ITEMS: Record<string, CodexToolDescriptor> = {
|
|
|
110
272
|
input: (item) => ({ changes: item.changes ?? [] }),
|
|
111
273
|
meta: (item) => ({
|
|
112
274
|
kind: CODEX_TOOL_KINDS.apply_patch,
|
|
113
|
-
locations:
|
|
275
|
+
locations: codexChangeView(item.changes).locations,
|
|
114
276
|
}),
|
|
277
|
+
// A failed or declined change shows no diff: `completeToolPart` keeps none.
|
|
115
278
|
result: (item) =>
|
|
116
279
|
item.status === "declined"
|
|
117
280
|
? { output: CODEX_CHANGE_DECLINED, isError: true }
|
|
118
281
|
: {
|
|
119
282
|
output: (item.changes ?? []).map(describeChange).join("\n"),
|
|
120
283
|
isError: failed(item),
|
|
284
|
+
content: codexChangeView(item.changes).content,
|
|
121
285
|
},
|
|
122
286
|
},
|
|
123
287
|
mcpToolCall: {
|
|
124
288
|
toolName: (item) => `${item.server ?? "mcp"}.${item.tool ?? "tool"}`,
|
|
125
289
|
input: (item) => ({ arguments: item.arguments }),
|
|
126
|
-
meta: () => ({
|
|
290
|
+
meta: (item) => ({
|
|
291
|
+
kind: CODEX_TOOL_KINDS.mcp,
|
|
292
|
+
// Codex names both on the item: never read out of `toolName`.
|
|
293
|
+
...(item.server !== undefined &&
|
|
294
|
+
item.tool !== undefined && { mcp: { server: item.server, tool: item.tool } }),
|
|
295
|
+
}),
|
|
127
296
|
result: (item) => {
|
|
128
297
|
const err = pickCodexError(item.error);
|
|
129
|
-
return {
|
|
130
|
-
|
|
131
|
-
isError: failed(item) || Boolean(err),
|
|
132
|
-
};
|
|
298
|
+
if (err) return { output: err, isError: true };
|
|
299
|
+
return { ...mcpResult(item.result), isError: failed(item) };
|
|
133
300
|
},
|
|
134
301
|
},
|
|
302
|
+
// @ref LLP 0017#codexs-own-pictures-and-an-mcp-tools-picture — a picture Codex makes itself, without its bytes
|
|
303
|
+
imageGeneration: {
|
|
304
|
+
toolName: () => "image_generation",
|
|
305
|
+
// The prompt Codex wrote, when it gives one, comes with the picture.
|
|
306
|
+
input: (item) => (item.revisedPrompt ? { prompt: item.revisedPrompt } : {}),
|
|
307
|
+
inputAtCompletion: true,
|
|
308
|
+
meta: () => ({ kind: CODEX_TOOL_KINDS.image_generation }),
|
|
309
|
+
// Megabytes of base64 stay out of the stream, the journal and every
|
|
310
|
+
// checkpoint: the picture is the file Codex saved.
|
|
311
|
+
result: (item) =>
|
|
312
|
+
item.failure || failed(item)
|
|
313
|
+
? {
|
|
314
|
+
output: `Image generation failed${item.failure?.type ? `: ${item.failure.type}` : ""}`,
|
|
315
|
+
isError: true,
|
|
316
|
+
}
|
|
317
|
+
: {
|
|
318
|
+
output: "Generated an image.",
|
|
319
|
+
...(item.savedPath && { metadata: { savedPath: item.savedPath } }),
|
|
320
|
+
isError: false,
|
|
321
|
+
},
|
|
322
|
+
},
|
|
135
323
|
webSearch: {
|
|
136
324
|
toolName: () => "web_search",
|
|
137
325
|
input: (item) => ({ query: item.query ?? "" }),
|
|
@@ -31,7 +31,7 @@ const LOGINS: readonly (AuthMethod & { type: string })[] = [
|
|
|
31
31
|
},
|
|
32
32
|
];
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
interface CodexCliLoginOptions {
|
|
35
35
|
/**
|
|
36
36
|
* A new app-server, not yet initialized, for a turn's `env`: its
|
|
37
37
|
* `CODEX_HOME` is the store a login lands in.
|
|
@@ -78,10 +78,22 @@ export function codexLoginStatus(read: CodexAccountRead): LoginStatus {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/** The variable that picks Codex's login store, its home. */
|
|
82
|
+
const STORE_VARIABLE = "CODEX_HOME";
|
|
83
|
+
|
|
84
|
+
/** The login store a turn or a login with this `env` uses: its `CODEX_HOME`, empty when unset. */
|
|
85
|
+
export function codexLoginStore(env: Record<string, string> | undefined): string {
|
|
86
|
+
return env?.[STORE_VARIABLE] ?? "";
|
|
87
|
+
}
|
|
88
|
+
|
|
81
89
|
/** Codex's login, through its app-server: `account/read`, `account/login/start`, `account/logout`. */
|
|
82
90
|
export class CodexCliLogin implements CliLogin {
|
|
83
91
|
constructor(private readonly options: CodexCliLoginOptions) {}
|
|
84
92
|
|
|
93
|
+
store(env: Record<string, string> | undefined): string {
|
|
94
|
+
return codexLoginStore(env);
|
|
95
|
+
}
|
|
96
|
+
|
|
85
97
|
/** Initialize a new app-server, run `use` on it, and end it. */
|
|
86
98
|
private async with<T>(
|
|
87
99
|
options: LoginOptions,
|
|
@@ -105,7 +117,7 @@ export class CodexCliLogin implements CliLogin {
|
|
|
105
117
|
terminalMethod(
|
|
106
118
|
[await this.options.cliPath(), "login"],
|
|
107
119
|
{ ...process.env, ...options.env },
|
|
108
|
-
|
|
120
|
+
STORE_VARIABLE,
|
|
109
121
|
),
|
|
110
122
|
];
|
|
111
123
|
}
|