@zvada/agent-server 0.3.18 → 0.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +11 -26
- package/CHANGELOG.md +1041 -1
- package/README.md +40 -40
- package/dist/types/accounts/chatgpt.d.ts +34 -0
- package/dist/types/accounts/chatgpt.d.ts.map +1 -0
- package/dist/types/accounts/check.d.ts +24 -0
- package/dist/types/accounts/check.d.ts.map +1 -0
- package/dist/types/accounts/claude.d.ts +21 -0
- package/dist/types/accounts/claude.d.ts.map +1 -0
- package/dist/types/accounts/endpoint.d.ts +50 -0
- package/dist/types/accounts/endpoint.d.ts.map +1 -0
- package/dist/types/accounts/http.d.ts +38 -0
- package/dist/types/accounts/http.d.ts.map +1 -0
- package/dist/types/accounts/index.d.ts +6 -0
- package/dist/types/accounts/index.d.ts.map +1 -0
- package/dist/types/client/client.d.ts +272 -0
- package/dist/types/client/client.d.ts.map +1 -0
- package/dist/types/client/connection.d.ts +160 -0
- package/dist/types/client/connection.d.ts.map +1 -0
- package/dist/types/client/history.d.ts +8 -0
- package/dist/types/client/history.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +5 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/listeners.d.ts +8 -0
- package/dist/types/client/listeners.d.ts.map +1 -0
- package/dist/types/client/logins.d.ts +35 -0
- package/dist/types/client/logins.d.ts.map +1 -0
- package/dist/types/client/rpc.d.ts +46 -0
- package/dist/types/client/rpc.d.ts.map +1 -0
- package/dist/types/client/streams.d.ts +150 -0
- package/dist/types/client/streams.d.ts.map +1 -0
- package/dist/types/client/transports.d.ts +35 -0
- package/dist/types/client/transports.d.ts.map +1 -0
- package/dist/types/client/turns.d.ts +81 -0
- package/dist/types/client/turns.d.ts.map +1 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts +68 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -0
- package/dist/types/core/agents/acp/adapter.d.ts +39 -0
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/acp/client.d.ts +90 -0
- package/dist/types/core/agents/acp/client.d.ts.map +1 -0
- package/dist/types/core/agents/acp/known-agents.d.ts +35 -0
- package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -0
- package/dist/types/core/agents/acp/mappings.d.ts +46 -0
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -0
- package/dist/types/core/agents/acp/requests.d.ts +26 -0
- package/dist/types/core/agents/acp/requests.d.ts.map +1 -0
- package/dist/types/core/agents/attachments.d.ts +11 -0
- package/dist/types/core/agents/attachments.d.ts.map +1 -0
- package/dist/types/core/agents/base.d.ts +227 -0
- package/dist/types/core/agents/base.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts +58 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts +26 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +70 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts +54 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/events.d.ts +42 -0
- package/dist/types/core/agents/claude-code/events.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/login.d.ts +61 -0
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts +52 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/models.d.ts +30 -0
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/options.d.ts +183 -0
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts +50 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts +36 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session.d.ts +148 -0
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts +29 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spend.d.ts +58 -0
- package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/tools.d.ts +4 -0
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts +52 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn.d.ts +121 -0
- package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts +59 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts +116 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +113 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts +66 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +49 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts +12 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts +45 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts +20 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts +26 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts +31 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts +38 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +62 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts +67 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts +40 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +19 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +99 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts +42 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts +96 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +53 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +87 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +33 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts +163 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -0
- package/dist/types/core/agents/config-fingerprint.d.ts +5 -0
- package/dist/types/core/agents/config-fingerprint.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +28 -0
- package/dist/types/core/agents/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +37 -0
- package/dist/types/core/agents/elicitation.d.ts.map +1 -0
- package/dist/types/core/agents/inherit-config.d.ts +18 -0
- package/dist/types/core/agents/inherit-config.d.ts.map +1 -0
- package/dist/types/core/agents/login.d.ts +67 -0
- package/dist/types/core/agents/login.d.ts.map +1 -0
- package/dist/types/core/agents/mcp-config.d.ts +57 -0
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -0
- package/dist/types/core/agents/plan.d.ts +16 -0
- package/dist/types/core/agents/plan.d.ts.map +1 -0
- package/dist/types/core/agents/registry.d.ts +30 -0
- package/dist/types/core/agents/registry.d.ts.map +1 -0
- package/dist/types/core/agents/session-agent.d.ts +48 -0
- package/dist/types/core/agents/session-agent.d.ts.map +1 -0
- package/dist/types/core/agents/session-pool.d.ts +41 -0
- package/dist/types/core/agents/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/stderr-tail.d.ts +28 -0
- package/dist/types/core/agents/stderr-tail.d.ts.map +1 -0
- package/dist/types/core/agents/thinking-levels.d.ts +4 -0
- package/dist/types/core/agents/thinking-levels.d.ts.map +1 -0
- package/dist/types/core/agents/types.d.ts +124 -0
- package/dist/types/core/agents/types.d.ts.map +1 -0
- package/dist/types/core/diagnostics.d.ts +36 -0
- package/dist/types/core/diagnostics.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +29 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/presets.d.ts +80 -0
- package/dist/types/core/presets.d.ts.map +1 -0
- package/dist/types/core/processes/identity.d.ts +31 -0
- package/dist/types/core/processes/identity.d.ts.map +1 -0
- package/dist/types/core/processes/lifeline.d.ts +47 -0
- package/dist/types/core/processes/lifeline.d.ts.map +1 -0
- package/dist/types/core/processes/native-processes.d.ts +130 -0
- package/dist/types/core/processes/native-processes.d.ts.map +1 -0
- package/dist/types/core/processes/process-table.d.ts +43 -0
- package/dist/types/core/processes/process-table.d.ts.map +1 -0
- package/dist/types/core/provision/cache-trust.d.ts +13 -0
- package/dist/types/core/provision/cache-trust.d.ts.map +1 -0
- package/dist/types/core/provision/cache-usage.d.ts +14 -0
- package/dist/types/core/provision/cache-usage.d.ts.map +1 -0
- package/dist/types/core/provision/checksums.d.ts +46 -0
- package/dist/types/core/provision/checksums.d.ts.map +1 -0
- package/dist/types/core/provision/extract.d.ts +7 -0
- package/dist/types/core/provision/extract.d.ts.map +1 -0
- package/dist/types/core/provision/index.d.ts +5 -0
- package/dist/types/core/provision/index.d.ts.map +1 -0
- package/dist/types/core/provision/install-build.d.ts +36 -0
- package/dist/types/core/provision/install-build.d.ts.map +1 -0
- package/dist/types/core/provision/npm.d.ts +40 -0
- package/dist/types/core/provision/npm.d.ts.map +1 -0
- package/dist/types/core/provision/pins.d.ts +24 -0
- package/dist/types/core/provision/pins.d.ts.map +1 -0
- package/dist/types/core/provision/platform.d.ts +28 -0
- package/dist/types/core/provision/platform.d.ts.map +1 -0
- package/dist/types/core/provision/provisioner.d.ts +189 -0
- package/dist/types/core/provision/provisioner.d.ts.map +1 -0
- package/dist/types/core/provision/releases.d.ts +8 -0
- package/dist/types/core/provision/releases.d.ts.map +1 -0
- package/dist/types/core/provision/tools.d.ts +81 -0
- package/dist/types/core/provision/tools.d.ts.map +1 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts +52 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts.map +1 -0
- package/dist/types/core/proxy/api-key-store.d.ts +37 -0
- package/dist/types/core/proxy/api-key-store.d.ts.map +1 -0
- package/dist/types/core/proxy/index.d.ts +3 -0
- package/dist/types/core/proxy/index.d.ts.map +1 -0
- package/dist/types/core/proxy/loopback.d.ts +14 -0
- package/dist/types/core/proxy/loopback.d.ts.map +1 -0
- package/dist/types/core/runtime/agent-runtime.d.ts +181 -0
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -0
- package/dist/types/core/runtime/event-processor.d.ts +87 -0
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -0
- package/dist/types/core/runtime/event-sink.d.ts +44 -0
- package/dist/types/core/runtime/event-sink.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-clis.d.ts +10 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-logins.d.ts +68 -0
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -0
- package/dist/types/core/runtime/login-reads.d.ts +28 -0
- package/dist/types/core/runtime/login-reads.d.ts.map +1 -0
- package/dist/types/core/runtime/model-lists.d.ts +37 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -0
- package/dist/types/core/runtime/permission-policy.d.ts +61 -0
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -0
- package/dist/types/core/runtime/request-broker.d.ts +49 -0
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -0
- package/dist/types/core/runtime/steering.d.ts +38 -0
- package/dist/types/core/runtime/steering.d.ts.map +1 -0
- package/dist/types/core/runtime/turn-outcome.d.ts +21 -0
- package/dist/types/core/runtime/turn-outcome.d.ts.map +1 -0
- package/dist/types/core/runtime/turn.d.ts +121 -0
- package/dist/types/core/runtime/turn.d.ts.map +1 -0
- package/dist/types/core/utils/bounded.d.ts +6 -0
- package/dist/types/core/utils/bounded.d.ts.map +1 -0
- package/dist/types/core/utils/deadline.d.ts +14 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -0
- package/dist/types/core/utils/errors.d.ts +104 -0
- package/dist/types/core/utils/errors.d.ts.map +1 -0
- package/dist/types/core/utils/is-record.d.ts +3 -0
- package/dist/types/core/utils/is-record.d.ts.map +1 -0
- package/dist/types/core/utils/loopback.d.ts +6 -0
- package/dist/types/core/utils/loopback.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/protocol/account.d.ts +26 -0
- package/dist/types/protocol/account.d.ts.map +1 -0
- package/dist/types/protocol/async-queue.d.ts +21 -0
- package/dist/types/protocol/async-queue.d.ts.map +1 -0
- package/dist/types/protocol/auth.d.ts +228 -0
- package/dist/types/protocol/auth.d.ts.map +1 -0
- package/dist/types/protocol/canonical.d.ts +9 -0
- package/dist/types/protocol/canonical.d.ts.map +1 -0
- package/dist/types/protocol/clis.d.ts +74 -0
- package/dist/types/protocol/clis.d.ts.map +1 -0
- package/dist/types/protocol/config.d.ts +200 -0
- package/dist/types/protocol/config.d.ts.map +1 -0
- package/dist/types/protocol/conversation.d.ts +942 -0
- package/dist/types/protocol/conversation.d.ts.map +1 -0
- package/dist/types/protocol/credentials.d.ts +145 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -0
- package/dist/types/protocol/errors.d.ts +36 -0
- package/dist/types/protocol/errors.d.ts.map +1 -0
- package/dist/types/protocol/execution.d.ts +28 -0
- package/dist/types/protocol/execution.d.ts.map +1 -0
- package/dist/types/protocol/factories.d.ts +94 -0
- package/dist/types/protocol/factories.d.ts.map +1 -0
- package/dist/types/protocol/guards.d.ts +55 -0
- package/dist/types/protocol/guards.d.ts.map +1 -0
- package/dist/types/protocol/harness.d.ts +70 -0
- package/dist/types/protocol/harness.d.ts.map +1 -0
- package/dist/types/protocol/history.d.ts +318 -0
- package/dist/types/protocol/history.d.ts.map +1 -0
- package/dist/types/protocol/ids.d.ts +9 -0
- package/dist/types/protocol/ids.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +35 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/protocol/lifecycle.d.ts +1190 -0
- package/dist/types/protocol/lifecycle.d.ts.map +1 -0
- package/dist/types/protocol/meta-keys.d.ts +17 -0
- package/dist/types/protocol/meta-keys.d.ts.map +1 -0
- package/dist/types/protocol/meta.d.ts +13 -0
- package/dist/types/protocol/meta.d.ts.map +1 -0
- package/dist/types/protocol/model-catalog.d.ts +11 -0
- package/dist/types/protocol/model-catalog.d.ts.map +1 -0
- package/dist/types/protocol/models.d.ts +107 -0
- package/dist/types/protocol/models.d.ts.map +1 -0
- package/dist/types/protocol/part-input.d.ts +101 -0
- package/dist/types/protocol/part-input.d.ts.map +1 -0
- package/dist/types/protocol/parts.d.ts +357 -0
- package/dist/types/protocol/parts.d.ts.map +1 -0
- package/dist/types/protocol/reduce.d.ts +26 -0
- package/dist/types/protocol/reduce.d.ts.map +1 -0
- package/dist/types/protocol/selectors.d.ts +64 -0
- package/dist/types/protocol/selectors.d.ts.map +1 -0
- package/dist/types/protocol/seq-cursor.d.ts +66 -0
- package/dist/types/protocol/seq-cursor.d.ts.map +1 -0
- package/dist/types/protocol/stop-reasons.d.ts +33 -0
- package/dist/types/protocol/stop-reasons.d.ts.map +1 -0
- package/dist/types/protocol/thinking.d.ts +28 -0
- package/dist/types/protocol/thinking.d.ts.map +1 -0
- package/dist/types/protocol/time.d.ts +21 -0
- package/dist/types/protocol/time.d.ts.map +1 -0
- package/dist/types/protocol/tokens.d.ts +29 -0
- package/dist/types/protocol/tokens.d.ts.map +1 -0
- package/dist/types/protocol/tool-closure.d.ts +25 -0
- package/dist/types/protocol/tool-closure.d.ts.map +1 -0
- package/dist/types/protocol/tool-state.d.ts +209 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -0
- package/dist/types/protocol/verify.d.ts +52 -0
- package/dist/types/protocol/verify.d.ts.map +1 -0
- package/dist/types/protocol/vocabulary.d.ts +19 -0
- package/dist/types/protocol/vocabulary.d.ts.map +1 -0
- package/dist/types/protocol/wire-api.d.ts +1983 -0
- package/dist/types/protocol/wire-api.d.ts.map +1 -0
- package/dist/types/protocol/wire.d.ts +1758 -0
- package/dist/types/protocol/wire.d.ts.map +1 -0
- package/dist/types/server/acp/binding.d.ts +33 -0
- package/dist/types/server/acp/binding.d.ts.map +1 -0
- package/dist/types/server/acp/session-records.d.ts +17 -0
- package/dist/types/server/acp/session-records.d.ts.map +1 -0
- package/dist/types/server/acp/translate.d.ts +48 -0
- package/dist/types/server/acp/translate.d.ts.map +1 -0
- package/dist/types/server/agent-server.d.ts +121 -0
- package/dist/types/server/agent-server.d.ts.map +1 -0
- package/dist/types/server/feedback.d.ts +37 -0
- package/dist/types/server/feedback.d.ts.map +1 -0
- package/dist/types/server/history.d.ts +15 -0
- package/dist/types/server/history.d.ts.map +1 -0
- package/dist/types/server/index.d.ts +7 -0
- package/dist/types/server/index.d.ts.map +1 -0
- package/dist/types/server/install.d.ts +42 -0
- package/dist/types/server/install.d.ts.map +1 -0
- package/dist/types/server/open-parts.d.ts +27 -0
- package/dist/types/server/open-parts.d.ts.map +1 -0
- package/dist/types/server/routes.d.ts +61 -0
- package/dist/types/server/routes.d.ts.map +1 -0
- package/dist/types/server/secrets.d.ts +11 -0
- package/dist/types/server/secrets.d.ts.map +1 -0
- package/dist/types/server/session-gate.d.ts +32 -0
- package/dist/types/server/session-gate.d.ts.map +1 -0
- package/dist/types/server/session-log.d.ts +39 -0
- package/dist/types/server/session-log.d.ts.map +1 -0
- package/dist/types/server/session-store.d.ts +119 -0
- package/dist/types/server/session-store.d.ts.map +1 -0
- package/dist/types/server/subscriptions.d.ts +74 -0
- package/dist/types/server/subscriptions.d.ts.map +1 -0
- package/dist/types/server/transports.d.ts +74 -0
- package/dist/types/server/transports.d.ts.map +1 -0
- package/dist/types/server/wire-error.d.ts +9 -0
- package/dist/types/server/wire-error.d.ts.map +1 -0
- package/dist/types/sync/event-log.d.ts +45 -0
- package/dist/types/sync/event-log.d.ts.map +1 -0
- package/dist/types/sync/fit.d.ts +40 -0
- package/dist/types/sync/fit.d.ts.map +1 -0
- package/dist/types/sync/history-reader.d.ts +8 -0
- package/dist/types/sync/history-reader.d.ts.map +1 -0
- package/dist/types/sync/history-sqlite.d.ts +37 -0
- package/dist/types/sync/history-sqlite.d.ts.map +1 -0
- package/dist/types/sync/history.d.ts +70 -0
- package/dist/types/sync/history.d.ts.map +1 -0
- package/dist/types/sync/index.d.ts +4 -0
- package/dist/types/sync/index.d.ts.map +1 -0
- package/dist/types/sync/journal-sqlite.d.ts +51 -0
- package/dist/types/sync/journal-sqlite.d.ts.map +1 -0
- package/dist/types/sync/journal.d.ts +107 -0
- package/dist/types/sync/journal.d.ts.map +1 -0
- package/dist/types/sync/live-tails.d.ts +30 -0
- package/dist/types/sync/live-tails.d.ts.map +1 -0
- package/dist/types/sync/node-sqlite.d.ts +7 -0
- package/dist/types/sync/node-sqlite.d.ts.map +1 -0
- package/dist/types/sync/projection.d.ts +10 -0
- package/dist/types/sync/projection.d.ts.map +1 -0
- package/dist/types/sync/recovery.d.ts +25 -0
- package/dist/types/sync/recovery.d.ts.map +1 -0
- package/dist/types/sync/retry.d.ts +25 -0
- package/dist/types/sync/retry.d.ts.map +1 -0
- package/dist/types/sync/schema.d.ts +4 -0
- package/dist/types/sync/schema.d.ts.map +1 -0
- package/dist/types/sync/sql.d.ts +38 -0
- package/dist/types/sync/sql.d.ts.map +1 -0
- package/dist/types/sync/sqlite-file.d.ts +9 -0
- package/dist/types/sync/sqlite-file.d.ts.map +1 -0
- package/dist/types/sync/sqlite.d.ts +6 -0
- package/dist/types/sync/sqlite.d.ts.map +1 -0
- package/dist/types/sync/worker.d.ts +63 -0
- package/dist/types/sync/worker.d.ts.map +1 -0
- package/docs/consuming.md +452 -53
- package/docs/deploy.md +218 -47
- package/docs/{sync-experiment.md → durable-sessions.md} +77 -72
- package/docs/feedback.md +116 -0
- package/docs/harnesses.md +212 -88
- package/docs/sync-history.md +29 -13
- package/docs/sync-integration.md +52 -66
- package/package.json +45 -28
- package/src/accounts/chatgpt.ts +194 -0
- package/src/accounts/check.ts +112 -0
- package/src/accounts/claude.ts +111 -0
- package/src/accounts/endpoint.ts +151 -0
- package/src/accounts/http.ts +97 -0
- package/src/accounts/index.ts +19 -0
- package/src/client/client.ts +604 -670
- package/src/client/connection.ts +371 -0
- package/src/client/history.ts +29 -52
- package/src/client/index.ts +11 -2
- package/src/client/listeners.ts +20 -0
- package/src/client/logins.ts +105 -0
- package/src/client/rpc.ts +155 -0
- package/src/client/streams.ts +488 -0
- package/src/client/transports.ts +62 -8
- package/src/client/turns.ts +171 -0
- package/src/core/agents/acp/acp-agent.ts +94 -118
- package/src/core/agents/acp/adapter.ts +20 -9
- package/src/core/agents/acp/client.ts +125 -47
- package/src/core/agents/acp/known-agents.ts +36 -4
- package/src/core/agents/acp/mappings.ts +64 -18
- package/src/core/agents/acp/requests.ts +125 -0
- package/src/core/agents/attachments.ts +18 -0
- package/src/core/agents/base.ts +120 -42
- package/src/core/agents/claude-code/adapter.ts +177 -238
- package/src/core/agents/claude-code/approvals.ts +270 -0
- package/src/core/agents/claude-code/claude-agent.ts +175 -158
- package/src/core/agents/claude-code/credentials.ts +171 -0
- package/src/core/agents/claude-code/events.ts +55 -0
- package/src/core/agents/claude-code/login.ts +269 -0
- package/src/core/agents/claude-code/mcp.ts +206 -0
- package/src/core/agents/claude-code/models.ts +15 -9
- package/src/core/agents/claude-code/options.ts +326 -39
- package/src/core/agents/claude-code/outcome.ts +209 -0
- package/src/core/agents/claude-code/session-pool.ts +136 -0
- package/src/core/agents/claude-code/session.ts +513 -0
- package/src/core/agents/claude-code/spawn.ts +144 -0
- package/src/core/agents/claude-code/spend.ts +160 -0
- package/src/core/agents/claude-code/tools.ts +47 -0
- package/src/core/agents/claude-code/turn-usage.ts +135 -0
- package/src/core/agents/claude-code/turn.ts +232 -0
- package/src/core/agents/codex-app-server/adapter.ts +314 -117
- package/src/core/agents/codex-app-server/client.ts +186 -84
- package/src/core/agents/codex-app-server/codex-agent.ts +343 -0
- package/src/core/agents/codex-app-server/commands.ts +228 -0
- package/src/core/agents/codex-app-server/credentials.ts +126 -0
- package/src/core/agents/codex-app-server/effort.ts +29 -0
- package/src/core/agents/codex-app-server/events.ts +47 -0
- package/src/core/agents/codex-app-server/homes.ts +64 -0
- package/src/core/agents/codex-app-server/input.ts +60 -0
- package/src/core/agents/codex-app-server/items.ts +149 -0
- package/src/core/agents/codex-app-server/login.ts +180 -0
- package/src/core/agents/codex-app-server/mcp.ts +182 -37
- package/src/core/agents/codex-app-server/models.ts +99 -46
- package/src/core/agents/codex-app-server/options.ts +146 -0
- package/src/core/agents/codex-app-server/plan-approval.ts +135 -0
- package/src/core/agents/codex-app-server/protocol.ts +117 -0
- package/src/core/agents/codex-app-server/requests.ts +332 -0
- package/src/core/agents/codex-app-server/session.ts +285 -0
- package/src/core/agents/codex-app-server/subagents.ts +108 -42
- package/src/core/agents/codex-app-server/thread-settings.ts +279 -0
- package/src/core/agents/codex-app-server/turn-items.ts +88 -0
- package/src/core/agents/codex-app-server/turn.ts +463 -0
- package/src/core/agents/config-fingerprint.ts +7 -14
- package/src/core/agents/credentials.ts +98 -0
- package/src/core/agents/elicitation.ts +75 -0
- package/src/core/agents/inherit-config.ts +21 -0
- package/src/core/agents/login.ts +116 -0
- package/src/core/agents/mcp-config.ts +112 -8
- package/src/core/agents/plan.ts +25 -0
- package/src/core/agents/registry.ts +21 -4
- package/src/core/agents/session-agent.ts +96 -4
- package/src/core/agents/{session-store.ts → session-pool.ts} +11 -5
- package/src/core/agents/stderr-tail.ts +75 -0
- package/src/core/agents/types.ts +40 -5
- package/src/core/index.ts +58 -48
- package/src/core/presets.ts +100 -39
- package/src/core/processes/identity.ts +113 -0
- package/src/core/processes/lifeline.ts +170 -0
- package/src/core/processes/native-processes.ts +379 -0
- package/src/core/processes/process-table.ts +174 -0
- package/src/core/provision/cache-trust.ts +121 -0
- package/src/core/provision/cache-usage.ts +69 -0
- package/src/core/provision/checksums.ts +64 -0
- package/src/core/provision/extract.ts +11 -2
- package/src/core/provision/index.ts +4 -1
- package/src/core/provision/install-build.ts +136 -0
- package/src/core/provision/npm.ts +112 -17
- package/src/core/provision/pins.ts +9 -33
- package/src/core/provision/platform.ts +12 -1
- package/src/core/provision/provisioner.ts +329 -397
- package/src/core/provision/releases.ts +86 -0
- package/src/core/provision/tools.ts +329 -0
- package/src/core/proxy/anthropic-proxy.ts +55 -25
- package/src/core/proxy/api-key-store.ts +2 -12
- package/src/core/proxy/loopback.ts +106 -0
- package/src/core/runtime/agent-runtime.ts +327 -498
- package/src/core/runtime/event-processor.ts +197 -70
- package/src/core/runtime/harness-clis.ts +61 -0
- package/src/core/runtime/harness-logins.ts +328 -0
- package/src/core/runtime/login-reads.ts +78 -0
- package/src/core/runtime/model-lists.ts +33 -48
- package/src/core/runtime/permission-policy.ts +113 -0
- package/src/core/runtime/request-broker.ts +204 -0
- package/src/core/runtime/steering.ts +112 -0
- package/src/core/runtime/turn-outcome.ts +30 -0
- package/src/core/runtime/turn.ts +360 -0
- package/src/core/utils/bounded.ts +12 -0
- package/src/core/utils/deadline.ts +38 -0
- package/src/core/utils/errors.ts +113 -21
- package/src/core/utils/is-record.ts +4 -0
- package/src/core/utils/loopback.ts +10 -0
- package/src/protocol/account.ts +104 -0
- package/src/protocol/auth.ts +199 -0
- package/src/protocol/canonical.ts +16 -0
- package/src/protocol/clis.ts +69 -0
- package/src/protocol/config.ts +60 -6
- package/src/protocol/conversation.ts +272 -0
- package/src/protocol/credentials.ts +145 -0
- package/src/protocol/errors.ts +78 -20
- package/src/protocol/execution.ts +5 -2
- package/src/protocol/factories.ts +55 -7
- package/src/protocol/guards.ts +55 -2
- package/src/protocol/harness.ts +56 -6
- package/src/protocol/history.ts +72 -64
- package/src/protocol/ids.ts +0 -12
- package/src/protocol/index.ts +9 -0
- package/src/protocol/lifecycle.ts +250 -79
- package/src/protocol/meta-keys.ts +17 -0
- package/src/protocol/meta.ts +3 -3
- package/src/protocol/models.ts +2 -43
- package/src/protocol/part-input.ts +2 -1
- package/src/protocol/parts.ts +12 -3
- package/src/protocol/reduce.ts +302 -413
- package/src/protocol/selectors.ts +1 -20
- package/src/protocol/seq-cursor.ts +14 -0
- package/src/protocol/stop-reasons.ts +1 -1
- package/src/protocol/thinking.ts +1 -30
- package/src/protocol/time.ts +2 -2
- package/src/protocol/tool-closure.ts +93 -0
- package/src/protocol/tool-state.ts +19 -4
- package/src/protocol/verify.ts +222 -92
- package/src/protocol/vocabulary.ts +21 -5
- package/src/protocol/wire-api.ts +232 -0
- package/src/protocol/wire.ts +351 -64
- package/src/server/acp/binding.ts +63 -103
- package/src/server/acp/session-records.ts +53 -0
- package/src/server/acp/translate.ts +129 -20
- package/src/server/agent-server.ts +223 -387
- package/src/server/bin.ts +280 -78
- package/src/server/feedback.ts +204 -14
- package/src/server/history.ts +116 -122
- package/src/server/index.ts +3 -8
- package/src/server/install.ts +107 -8
- package/src/server/open-parts.ts +95 -0
- package/src/server/routes.ts +391 -0
- package/src/server/secrets.ts +24 -0
- package/src/server/session-gate.ts +69 -0
- package/src/server/session-log.ts +14 -2
- package/src/server/session-store.ts +136 -72
- package/src/server/subscriptions.ts +232 -0
- package/src/server/transports.ts +125 -25
- package/src/server/wire-error.ts +31 -45
- package/src/sync/event-log.ts +31 -3
- package/src/sync/fit.ts +27 -11
- package/src/sync/history-reader.ts +10 -5
- package/src/sync/history-sqlite.ts +37 -42
- package/src/sync/history.ts +9 -15
- package/src/sync/index.ts +17 -5
- package/src/sync/journal-sqlite.ts +162 -76
- package/src/sync/journal.ts +91 -32
- package/src/sync/live-tails.ts +107 -0
- package/src/sync/projection.ts +35 -0
- package/src/sync/recovery.ts +80 -51
- package/src/sync/schema.ts +27 -6
- package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
- package/docs/rfds/0002-native-subagents.md +0 -197
- package/src/client/request.ts +0 -19
- package/src/core/agents/claude-code/generator-session.ts +0 -572
- package/src/core/agents/claude-code/session-manager.ts +0 -166
- package/src/core/agents/codex-app-server/codex-app-server-agent.ts +0 -962
- package/src/core/agents/codex-items.ts +0 -149
- package/src/core/agents/codex-sdk/adapter.ts +0 -237
- package/src/core/agents/codex-sdk/codex-sdk-agent.ts +0 -330
- package/src/core/agents/tool-meta.ts +0 -68
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Generated by `bun run releases:refresh`. Do not edit: bump a pin in
|
|
2
|
+
// core/provision/pins.ts, then regenerate.
|
|
3
|
+
import type { CliReleases } from "./checksums.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The pinned CLIs' builds, by platform: each npm tarball's integrity, and for
|
|
7
|
+
* Claude the binary's sha256 from Anthropic's signed release manifest (its
|
|
8
|
+
* signature verified when this file was generated).
|
|
9
|
+
*/
|
|
10
|
+
export const CLI_RELEASES: CliReleases = {
|
|
11
|
+
claude: {
|
|
12
|
+
version: "0.3.288",
|
|
13
|
+
cli: "2.1.288",
|
|
14
|
+
builds: {
|
|
15
|
+
"darwin-arm64": {
|
|
16
|
+
integrity:
|
|
17
|
+
"sha512-85niGScWj8sr7yqOjSfqINaKv/zB47T45o4NBq1BmpaKRYFK7grtK24LA6C7cjx1Pznp+WT68mo373fbbwFW0A==",
|
|
18
|
+
sha256: "bbe93063f7a0879a1021b2891e5c9354e5b3b98433e32efe6750f7710afed750",
|
|
19
|
+
},
|
|
20
|
+
"darwin-x64": {
|
|
21
|
+
integrity:
|
|
22
|
+
"sha512-hY8MQtgAi+cRedFb+qSqZzAYXIfjC+ZiXtCxKCs4OqWbqrdVZ0GKcEv4nB6MfQGs/Qr4U24cDNuO2lskBbZAWA==",
|
|
23
|
+
sha256: "946acab03a55b60e2016e30964c48b96ef6673cb5da684383f4835da410eede0",
|
|
24
|
+
},
|
|
25
|
+
"linux-arm64": {
|
|
26
|
+
integrity:
|
|
27
|
+
"sha512-CCj0xau64T+Ia+X2wZgjYFSUIWfNJRWIGFbT8+jKiCzQggaBo6OSZ8hAYyME3h13JYrgpyrUTzB5YiwKaw8ZFg==",
|
|
28
|
+
sha256: "359ab6a058fcde9741dff54979a212fd134cdf8e8cfc2f8de02bc350b9e2b9d5",
|
|
29
|
+
},
|
|
30
|
+
"linux-x64": {
|
|
31
|
+
integrity:
|
|
32
|
+
"sha512-Y5M496UZKttScbzptA45NI+CMHYONnskw0aq3rJ6s+gE6L6Jy8F8UoKt0lQO11R5xTY65TIeCasjQf/bLavuNg==",
|
|
33
|
+
sha256: "0298068b686e7fdbaf9402a7a587bb7f49c0b0e084de09f69145a0719207640c",
|
|
34
|
+
},
|
|
35
|
+
"linux-arm64-musl": {
|
|
36
|
+
integrity:
|
|
37
|
+
"sha512-66MD4hzNTqrTL5MN21bSfxm/fhbnM+ERsmWHGEsJojxAWY5DXCUlDkaAYM0rxDpdvLMVt9PpRVIiWDptaiFPxA==",
|
|
38
|
+
sha256: "6b9816b225b303dacc17acc9d83016055274498effdbce6227e62d5dbaa762b9",
|
|
39
|
+
},
|
|
40
|
+
"linux-x64-musl": {
|
|
41
|
+
integrity:
|
|
42
|
+
"sha512-g3HDERLfEamirfp+MJDVl1fT8YYQMILUH65jPzl+SzKLeBu26WmAXAoZFmU4dasEmKZkEnBdL0ZQy3qnDy5EXg==",
|
|
43
|
+
sha256: "b4334268a2ce06bf984dab2d6925cc5afe9d2344fa427fc362e266da0d57a894",
|
|
44
|
+
},
|
|
45
|
+
"win32-arm64": {
|
|
46
|
+
integrity:
|
|
47
|
+
"sha512-ijVSU5Vl1L1SlEm1djPNEekxHm9FS5GOitz8kL8KLdYDspMA97bgFM4gy/+riA3qn4ERepJkjdDLE+oYMTO+UA==",
|
|
48
|
+
sha256: "5015d2b92866232b85384ac6e5eef4ff155418a92123503e52714c29186af8c6",
|
|
49
|
+
},
|
|
50
|
+
"win32-x64": {
|
|
51
|
+
integrity:
|
|
52
|
+
"sha512-zh4yfGduDEBKUqb3BPtq/cLYwHoScqm7X5fJhmkSs0BJiSJGlb38j6FXWDvoPfe+OXNjE5onNx5HlAnDzsQzrA==",
|
|
53
|
+
sha256: "84304f7d4b0cd0ebcbe8318695a260151b48991a6659c3366fdd5da290c0ab91",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
codex: {
|
|
58
|
+
version: "0.160.0",
|
|
59
|
+
builds: {
|
|
60
|
+
"darwin-arm64": {
|
|
61
|
+
integrity:
|
|
62
|
+
"sha512-aefV6cqZA2REZgR//4McyXlp7zLcTti4CI2v3j9IVgNndPBv2kCeNEcz07qeelXcwOdSFPUKb6roA48vZmDgrQ==",
|
|
63
|
+
},
|
|
64
|
+
"darwin-x64": {
|
|
65
|
+
integrity:
|
|
66
|
+
"sha512-ir7cdsPrb9VkqNqpTECoTiomv04xws/FQ968mHQzuL+2J5Da0Dkh2Qlxp7sguDDZJab4YpYmNjQvBVMXbTeQaQ==",
|
|
67
|
+
},
|
|
68
|
+
"linux-arm64": {
|
|
69
|
+
integrity:
|
|
70
|
+
"sha512-VnVdsS06YlDsL8OwaJjQ3xdqdJNG4i+eBJBV3LytddknzSaF/urijLzVg3ptkwvoj8C7Gn7iWpVE+y8WEaPiCg==",
|
|
71
|
+
},
|
|
72
|
+
"linux-x64": {
|
|
73
|
+
integrity:
|
|
74
|
+
"sha512-KI/73OqGrHmR18s7ya7E1NqV6rT0y3lxr0s8S1qR2m6zU6QRF/HlR529jALLh5vjdUnsRT4Ahoxt0axb4kY99g==",
|
|
75
|
+
},
|
|
76
|
+
"win32-arm64": {
|
|
77
|
+
integrity:
|
|
78
|
+
"sha512-tTvK9ZIGuj9WnYaYOAnfjJVSfPV7dKqWtDHqUPLf0Hadp6SgynTxx7S7iMXRieFeXVOI2XH76KxEHSOTOnz3zw==",
|
|
79
|
+
},
|
|
80
|
+
"win32-x64": {
|
|
81
|
+
integrity:
|
|
82
|
+
"sha512-/gCFcuOmGlQkgGivWCtY8BNEDixh70Pue0HZOk9S8bj2vUIE1GLD9zcNB/KqqDJmn0S+lIttauLpzQnw6HOCHA==",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Stats,
|
|
3
|
+
existsSync,
|
|
4
|
+
lstatSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
readdirSync,
|
|
7
|
+
realpathSync,
|
|
8
|
+
} from "node:fs";
|
|
9
|
+
import { readdir } from "node:fs/promises";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
11
|
+
import type { AgentHarness } from "../../protocol/index.ts";
|
|
12
|
+
import { CliNotFoundError, CliProvisionError } from "../utils/errors.ts";
|
|
13
|
+
import type { LocalBuild } from "./checksums.ts";
|
|
14
|
+
import { DEFAULT_PINS } from "./pins.ts";
|
|
15
|
+
import {
|
|
16
|
+
type PlatformInfo,
|
|
17
|
+
claudePackageSuffix,
|
|
18
|
+
codexPackageSuffix,
|
|
19
|
+
findOnPath,
|
|
20
|
+
} from "./platform.ts";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The managed CLIs. Each native harness maps onto exactly one of these; the
|
|
24
|
+
* `acp` harness maps onto none (its agent binaries are arbitrary third-party
|
|
25
|
+
* commands the operator supplies, not something we pin or download).
|
|
26
|
+
*/
|
|
27
|
+
export const CLI_TOOLS = ["claude", "codex"] as const;
|
|
28
|
+
export type CliTool = (typeof CLI_TOOLS)[number];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Which managed CLI a harness runs on — `undefined` for unmanaged harnesses
|
|
32
|
+
* (`acp`). Exhaustive by construction: adding a harness fails to compile here
|
|
33
|
+
* until someone decides whether it is provisioner-managed.
|
|
34
|
+
*/
|
|
35
|
+
const TOOL_FOR_HARNESS: Record<AgentHarness, CliTool | undefined> = {
|
|
36
|
+
"claude-code": "claude",
|
|
37
|
+
"codex-app-server": "codex",
|
|
38
|
+
acp: undefined,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export function toolForHarness(harness: AgentHarness): CliTool | undefined {
|
|
42
|
+
return TOOL_FOR_HARNESS[harness];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What to download for one tool on one platform. */
|
|
46
|
+
export interface ToolPackage {
|
|
47
|
+
name: string;
|
|
48
|
+
/** Exact version string the registry knows (codex encodes the platform here). */
|
|
49
|
+
registryVersion: string;
|
|
50
|
+
/** The platform part of the cache directory's name. */
|
|
51
|
+
suffix: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Where a host install is looked for. */
|
|
55
|
+
export interface HostMachine {
|
|
56
|
+
platform: PlatformInfo;
|
|
57
|
+
env: Record<string, string | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* Whether a binary on `PATH` counts (`system` mode): elsewhere it is no
|
|
60
|
+
* build anyone chose for this engine, and may be another app's private copy.
|
|
61
|
+
*/
|
|
62
|
+
searchPath: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** What the provisioner knows of one managed CLI. */
|
|
66
|
+
export interface CliToolSpec {
|
|
67
|
+
/** The variable an operator points at the binary to run instead (never the wire's). */
|
|
68
|
+
readonly overrideEnv: string;
|
|
69
|
+
/** Where the binary sits in an installed tree; the first regular file wins. */
|
|
70
|
+
readonly binaries: readonly string[];
|
|
71
|
+
/** The platforms the vendor publishes a build for, as the cache names them. */
|
|
72
|
+
readonly platforms: readonly string[];
|
|
73
|
+
/** The registry package carrying this platform's build of `version`. */
|
|
74
|
+
package(platform: PlatformInfo, version: string): ToolPackage;
|
|
75
|
+
/** The version to download when no pin is set. */
|
|
76
|
+
defaultVersion(): string;
|
|
77
|
+
/** Why the default may not be the build that runs, when this machine cannot tell (said once). */
|
|
78
|
+
defaultVersionNote?(): string | undefined;
|
|
79
|
+
/** An install already on this machine, if any. */
|
|
80
|
+
hostInstall(host: HostMachine): { path: string; version?: string } | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* This platform's binary at `version` as a source on this machine knows
|
|
83
|
+
* it, for a version the release table does not pin: the installed Claude
|
|
84
|
+
* SDK's manifest names its own CLI's sha256.
|
|
85
|
+
*/
|
|
86
|
+
localBuild?(suffix: string, version: string): LocalBuild | undefined;
|
|
87
|
+
/** The directory of an extracted tarball that becomes the install. */
|
|
88
|
+
payload(extractedRoot: string): Promise<string>;
|
|
89
|
+
/**
|
|
90
|
+
* What `system` mode fails with when the host has none; absent, the
|
|
91
|
+
* harness's own resolution speaks (the Claude SDK finds its sibling
|
|
92
|
+
* platform package and has the clearest failure message).
|
|
93
|
+
*/
|
|
94
|
+
notOnHost?(): Error;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The first regular file of `binaries` under `dir` (lstat: a symlink could redirect the spawn). */
|
|
98
|
+
export function binaryIn(dir: string, binaries: readonly string[]): string | undefined {
|
|
99
|
+
for (const candidate of binaries) {
|
|
100
|
+
const path = join(dir, candidate);
|
|
101
|
+
let stat: Stats;
|
|
102
|
+
try {
|
|
103
|
+
stat = lstatSync(path);
|
|
104
|
+
} catch {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (stat.isFile()) return path;
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Locate an installed package by walking `node_modules` upward from `fromDir`,
|
|
114
|
+
* returning its real directory. Deliberately not `require.resolve`: these
|
|
115
|
+
* packages don't export `./package.json`, so exports maps would veto
|
|
116
|
+
* perfectly good installs.
|
|
117
|
+
* The realpath matters under isolated stores (bun): a package's own deps are
|
|
118
|
+
* siblings of its *store* location, not of the symlink consumers see.
|
|
119
|
+
*/
|
|
120
|
+
function findPackageDir(name: string, fromDir: string): string | undefined {
|
|
121
|
+
let dir = fromDir;
|
|
122
|
+
while (true) {
|
|
123
|
+
const candidate = join(dir, "node_modules", ...name.split("/"));
|
|
124
|
+
if (existsSync(join(candidate, "package.json"))) {
|
|
125
|
+
try {
|
|
126
|
+
return realpathSync(candidate);
|
|
127
|
+
} catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const parent = dirname(dir);
|
|
132
|
+
if (parent === dir) return undefined;
|
|
133
|
+
dir = parent;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Where this package lives on disk — the walk anchor: this module's folder,
|
|
139
|
+
* or a bundle's when bundled (Bun defines `__dirname` in ESM too), and
|
|
140
|
+
* `undefined` in an ESM bundle under Node, where nothing on disk says. The
|
|
141
|
+
* walk never starts from the working folder, whose project may hold another
|
|
142
|
+
* Claude SDK than the one that runs. A compiled binary sees the path it was
|
|
143
|
+
* built at, which misses on any other machine, so pins take over. NOTE: this
|
|
144
|
+
* must not mention `import.meta` — consumers bundle these sources to CJS,
|
|
145
|
+
* where that token is a parse error (and older bundlers don't rewrite it).
|
|
146
|
+
*/
|
|
147
|
+
function moduleDir(): string | undefined {
|
|
148
|
+
// CJS bundle output: anchor at the bundle location.
|
|
149
|
+
if (typeof __dirname !== "undefined") return __dirname;
|
|
150
|
+
try {
|
|
151
|
+
// Bun/ESM: resolve our own manifest through the module graph (Bun
|
|
152
|
+
// provides `require` in ESM; "./package.json" is an explicit export).
|
|
153
|
+
return dirname(require.resolve("@zvada/agent-server/package.json"));
|
|
154
|
+
} catch {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Inside a binary compiled with `bun build --compile`, whose modules live in `$bunfs`. */
|
|
160
|
+
function inCompiledBinary(): boolean {
|
|
161
|
+
const main = (globalThis as { Bun?: { main?: string } }).Bun?.main ?? "";
|
|
162
|
+
return main.startsWith("/$bunfs/") || /^[A-Za-z]:[\\/]~BUN[\\/]/.test(main);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** A package manifest's `version`, if it has one. */
|
|
166
|
+
function versionOf(packageDir: string): string | undefined {
|
|
167
|
+
return (
|
|
168
|
+
JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8")) as { version?: string }
|
|
169
|
+
).version;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The installed Claude SDK, when resolvable on disk. Its version drives both
|
|
174
|
+
* host resolution and the download pin, so the JS ↔ native-CLI pair can
|
|
175
|
+
* never skew. Unresolvable inside compiled binaries — pins take over there.
|
|
176
|
+
*/
|
|
177
|
+
export function claudeSdkOnDisk(): { dir: string; version?: string } | undefined {
|
|
178
|
+
const from = moduleDir();
|
|
179
|
+
if (!from) return undefined;
|
|
180
|
+
try {
|
|
181
|
+
const dir = findPackageDir("@anthropic-ai/claude-agent-sdk", from);
|
|
182
|
+
return dir ? { dir, version: versionOf(dir) } : undefined;
|
|
183
|
+
} catch {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** This platform's entry in the SDK's manifest of its CLI: the binary's name and sha256. */
|
|
189
|
+
function claudeManifestBuild(
|
|
190
|
+
sdkDir: string,
|
|
191
|
+
suffix: string,
|
|
192
|
+
): { binary?: string; checksum?: string } | undefined {
|
|
193
|
+
try {
|
|
194
|
+
const manifest = JSON.parse(readFileSync(join(sdkDir, "manifest.json"), "utf8")) as {
|
|
195
|
+
platforms?: Record<string, { binary?: string; checksum?: string }>;
|
|
196
|
+
};
|
|
197
|
+
return manifest.platforms?.[suffix];
|
|
198
|
+
} catch {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const CODEX_BINARIES = [join("bin", "codex"), join("bin", "codex.exe")];
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The managed CLIs, one entry each: a new tool fails to compile until it says
|
|
207
|
+
* where its builds come from, where its binary sits and how to find one
|
|
208
|
+
* installed.
|
|
209
|
+
*/
|
|
210
|
+
export const CLI_TOOL_SPECS: Record<CliTool, CliToolSpec> = {
|
|
211
|
+
claude: {
|
|
212
|
+
overrideEnv: "CLAUDE_CLI_PATH",
|
|
213
|
+
binaries: ["claude", "claude.exe"],
|
|
214
|
+
platforms: [
|
|
215
|
+
"darwin-arm64",
|
|
216
|
+
"darwin-x64",
|
|
217
|
+
"linux-arm64",
|
|
218
|
+
"linux-x64",
|
|
219
|
+
"linux-arm64-musl",
|
|
220
|
+
"linux-x64-musl",
|
|
221
|
+
"win32-arm64",
|
|
222
|
+
"win32-x64",
|
|
223
|
+
],
|
|
224
|
+
// The platform packages carry the native CLI matched to the SDK JS.
|
|
225
|
+
package: (platform, version) => {
|
|
226
|
+
const suffix = claudePackageSuffix(platform);
|
|
227
|
+
return { name: `@anthropic-ai/claude-agent-sdk-${suffix}`, registryVersion: version, suffix };
|
|
228
|
+
},
|
|
229
|
+
// The on-disk SDK's version (the pair that actually runs) over the
|
|
230
|
+
// release default, which only decides inside compiled binaries. Even
|
|
231
|
+
// `pinned` follows it: "deterministic" means the tested JS ↔ CLI
|
|
232
|
+
// *pair*, and downloading the release-default CLI under a newer
|
|
233
|
+
// installed SDK would manufacture exactly the skew this module exists
|
|
234
|
+
// to prevent. Operators who want byte-identical fleets pin explicitly
|
|
235
|
+
// (and align the SDK).
|
|
236
|
+
defaultVersion: () => claudeSdkOnDisk()?.version ?? DEFAULT_PINS.claude,
|
|
237
|
+
// @ref LLP 0010#p2--claudes-build-follows-the-sdk-that-runs — a bundled SDK's version is the host's to say
|
|
238
|
+
// The compiled agent-server binary bundles the SDK it pins, so only
|
|
239
|
+
// another product's bundle runs an SDK nothing here can name.
|
|
240
|
+
defaultVersionNote: () =>
|
|
241
|
+
claudeSdkOnDisk() || inCompiledBinary()
|
|
242
|
+
? undefined
|
|
243
|
+
: `claude: no Claude SDK on disk, so this runs the CLI of agent-server's pin ${DEFAULT_PINS.claude}; a product that bundles the SDK sets provision.pins.claude to its version`,
|
|
244
|
+
// The platform package beside the installed Claude SDK: the build that
|
|
245
|
+
// SDK would spawn itself.
|
|
246
|
+
hostInstall: ({ platform }) => {
|
|
247
|
+
const sdk = claudeSdkOnDisk();
|
|
248
|
+
if (!sdk) return undefined;
|
|
249
|
+
const suffix = claudePackageSuffix(platform);
|
|
250
|
+
const platformDir = findPackageDir(`@anthropic-ai/claude-agent-sdk-${suffix}`, sdk.dir);
|
|
251
|
+
if (!platformDir) return undefined;
|
|
252
|
+
const path = join(platformDir, claudeManifestBuild(sdk.dir, suffix)?.binary ?? "claude");
|
|
253
|
+
return existsSync(path) ? { path, version: sdk.version } : undefined;
|
|
254
|
+
},
|
|
255
|
+
payload: async (extractedRoot) => {
|
|
256
|
+
const dir = join(extractedRoot, "package");
|
|
257
|
+
if (existsSync(dir)) return dir;
|
|
258
|
+
throw new CliProvisionError("claude tarball has no package/ directory");
|
|
259
|
+
},
|
|
260
|
+
// The SDK on disk names its own CLI's checksum, for a version this
|
|
261
|
+
// release did not pin (a consumer's lockfile moved the SDK).
|
|
262
|
+
localBuild: (suffix, version) => {
|
|
263
|
+
const sdk = claudeSdkOnDisk();
|
|
264
|
+
const sha256 =
|
|
265
|
+
sdk?.version === version ? claudeManifestBuild(sdk.dir, suffix)?.checksum : undefined;
|
|
266
|
+
return sha256 ? { sha256, vouchedBy: "the installed Claude SDK's manifest" } : undefined;
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
codex: {
|
|
270
|
+
overrideEnv: "CODEX_CLI_PATH",
|
|
271
|
+
binaries: CODEX_BINARIES,
|
|
272
|
+
// Its linux builds are static, so there is no musl variant.
|
|
273
|
+
platforms: [
|
|
274
|
+
"darwin-arm64",
|
|
275
|
+
"darwin-x64",
|
|
276
|
+
"linux-arm64",
|
|
277
|
+
"linux-x64",
|
|
278
|
+
"win32-arm64",
|
|
279
|
+
"win32-x64",
|
|
280
|
+
],
|
|
281
|
+
// Codex publishes its platform builds as version suffixes of one package.
|
|
282
|
+
package: (platform, version) => {
|
|
283
|
+
const suffix = codexPackageSuffix(platform);
|
|
284
|
+
return { name: "@openai/codex", registryVersion: `${version}-${suffix}`, suffix };
|
|
285
|
+
},
|
|
286
|
+
defaultVersion: () => DEFAULT_PINS.codex,
|
|
287
|
+
// @ref LLP 0001#d18--the-engine-installs-the-clis-it-runs-pinned-builds-checked-before-a-turn — a lockfile's build, or in `system` the operator's PATH
|
|
288
|
+
// An installed `@openai/codex` package's build (its platform dependency
|
|
289
|
+
// ships `vendor/<target>/bin/codex`), so a lockfile can pin the CLI the
|
|
290
|
+
// app-server harness runs; then, in `system` mode, a `codex` on PATH.
|
|
291
|
+
hostInstall: ({ platform, env, searchPath }) => {
|
|
292
|
+
try {
|
|
293
|
+
const from = moduleDir();
|
|
294
|
+
const codexDir = from && findPackageDir("@openai/codex", from);
|
|
295
|
+
const suffix = codexPackageSuffix(platform);
|
|
296
|
+
const platformDir = codexDir && findPackageDir(`@openai/codex-${suffix}`, codexDir);
|
|
297
|
+
if (platformDir) {
|
|
298
|
+
const vendor = join(platformDir, "vendor");
|
|
299
|
+
for (const entry of readdirSync(vendor)) {
|
|
300
|
+
const path = binaryIn(join(vendor, entry), CODEX_BINARIES);
|
|
301
|
+
const version = path && versionOf(platformDir)?.replace(`-${suffix}`, "");
|
|
302
|
+
if (path) return { path, ...(version ? { version } : {}) };
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} catch {
|
|
306
|
+
// No readable vendored build.
|
|
307
|
+
}
|
|
308
|
+
const path = searchPath ? findOnPath("codex", env, platform.platform) : undefined;
|
|
309
|
+
return path ? { path } : undefined;
|
|
310
|
+
},
|
|
311
|
+
// Codex vendors per-target trees: package/vendor/<rust-triple>/bin/codex.
|
|
312
|
+
// Install the whole tree — the CLI expects its vendored rg/zsh siblings.
|
|
313
|
+
payload: async (extractedRoot) => {
|
|
314
|
+
const vendor = join(extractedRoot, "package", "vendor");
|
|
315
|
+
const entries = existsSync(vendor) ? await readdir(vendor) : [];
|
|
316
|
+
for (const entry of entries) {
|
|
317
|
+
const dir = join(vendor, entry);
|
|
318
|
+
if (binaryIn(dir, CODEX_BINARIES)) return dir;
|
|
319
|
+
}
|
|
320
|
+
throw new CliProvisionError("codex tarball has no vendor/<target>/bin/codex");
|
|
321
|
+
},
|
|
322
|
+
// A bare spawn would just ENOENT.
|
|
323
|
+
notOnHost: () =>
|
|
324
|
+
new CliNotFoundError(
|
|
325
|
+
"codex",
|
|
326
|
+
'install it, set $CODEX_CLI_PATH, or use provision mode "auto"',
|
|
327
|
+
),
|
|
328
|
+
},
|
|
329
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DiagnosticHandler, emitDiagnostic } from "../diagnostics.ts";
|
|
2
|
-
import { type ApiKeyStore, apiKeyStore } from "./api-key-store.ts";
|
|
2
|
+
import { type ApiKeyEntry, type ApiKeyStore, apiKeyStore } from "./api-key-store.ts";
|
|
3
3
|
|
|
4
4
|
/** Placeholder key handed to the agent subprocess; swapped for the real one here. */
|
|
5
5
|
export const PROXY_PLACEHOLDER_KEY = "sk-proxy-managed";
|
|
@@ -39,8 +39,27 @@ export interface AnthropicProxyOptions {
|
|
|
39
39
|
fetch?: FetchLike;
|
|
40
40
|
/** Notified on upstream 401/403 — the STORED key is bad, not the placeholder. */
|
|
41
41
|
onDiagnostic?: DiagnosticHandler;
|
|
42
|
+
/**
|
|
43
|
+
* Asked when the upstream refuses a session's credential (401): answer a
|
|
44
|
+
* fresher one, and the request is sent once more with it. Its body is then
|
|
45
|
+
* read before the first send, to be sent twice.
|
|
46
|
+
*/
|
|
47
|
+
renew?: (sessionId: string, rejected: ApiKeyEntry) => Promise<ApiKeyEntry | undefined>;
|
|
42
48
|
}
|
|
43
49
|
|
|
50
|
+
/** Headers that belong to one connection, never forwarded. */
|
|
51
|
+
const HOP_BY_HOP = [
|
|
52
|
+
"host",
|
|
53
|
+
"content-length",
|
|
54
|
+
"connection",
|
|
55
|
+
"keep-alive",
|
|
56
|
+
"proxy-connection",
|
|
57
|
+
"transfer-encoding",
|
|
58
|
+
"te",
|
|
59
|
+
"trailer",
|
|
60
|
+
"upgrade",
|
|
61
|
+
];
|
|
62
|
+
|
|
44
63
|
/**
|
|
45
64
|
* A framework-agnostic, Web-standard `(Request) => Promise<Response>` handler
|
|
46
65
|
* implementing the BYOK Anthropic proxy. Mount it in any server (Bun, Hono,
|
|
@@ -87,34 +106,45 @@ export function createAnthropicProxy(
|
|
|
87
106
|
);
|
|
88
107
|
}
|
|
89
108
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
// A body sent twice (a renewed credential's retry) is read first.
|
|
110
|
+
const body = options.renew && request.body ? await request.arrayBuffer() : request.body;
|
|
111
|
+
const forward = (credential: ApiKeyEntry): Promise<Response> => {
|
|
112
|
+
const headers = new Headers(request.headers);
|
|
113
|
+
// This hop's, not the upstream's: Node's fetch refuses some outright.
|
|
114
|
+
for (const name of HOP_BY_HOP) headers.delete(name);
|
|
115
|
+
if (credential.kind === "oauth") {
|
|
116
|
+
// Subscription token: bearer auth + the OAuth capability. The
|
|
117
|
+
// x-api-key the CLI sent carries only the placeholder — it must go,
|
|
118
|
+
// or the upstream sees two conflicting credentials.
|
|
119
|
+
headers.delete("x-api-key");
|
|
120
|
+
headers.set("authorization", `Bearer ${credential.apiKey}`);
|
|
121
|
+
appendAnthropicBeta(headers, ANTHROPIC_OAUTH_BETA);
|
|
122
|
+
} else {
|
|
123
|
+
headers.set("x-api-key", credential.apiKey);
|
|
124
|
+
headers.delete("authorization");
|
|
125
|
+
}
|
|
126
|
+
const init: RequestInit & { duplex?: "half" } = {
|
|
127
|
+
method: request.method,
|
|
128
|
+
headers,
|
|
129
|
+
body,
|
|
130
|
+
redirect: "manual",
|
|
131
|
+
// The CLI going away stops the request upstream.
|
|
132
|
+
signal: request.signal,
|
|
133
|
+
};
|
|
134
|
+
// Required when forwarding a streaming request body on fetch.
|
|
135
|
+
if (body instanceof ReadableStream) init.duplex = "half";
|
|
136
|
+
const doFetch: FetchLike = options.fetch ?? (globalThis.fetch as FetchLike);
|
|
137
|
+
return doFetch(`${credential.upstreamBaseUrl}${subPath}${url.search}`, init);
|
|
110
138
|
};
|
|
111
|
-
// Required when forwarding a streaming request body on fetch.
|
|
112
|
-
if (request.body) init.duplex = "half";
|
|
113
139
|
|
|
114
|
-
const doFetch: FetchLike = options.fetch ?? (globalThis.fetch as FetchLike);
|
|
115
140
|
let upstream: Response;
|
|
116
141
|
try {
|
|
117
|
-
upstream = await
|
|
142
|
+
upstream = await forward(entry);
|
|
143
|
+
const renewed = upstream.status === 401 && (await options.renew?.(sessionId, entry));
|
|
144
|
+
if (renewed && renewed.apiKey !== entry.apiKey) {
|
|
145
|
+
await upstream.body?.cancel();
|
|
146
|
+
upstream = await forward(renewed);
|
|
147
|
+
}
|
|
118
148
|
} catch (error) {
|
|
119
149
|
// An unreachable upstream must surface as a structured API error the
|
|
120
150
|
// agent can classify, not a host-framework 500 with an opaque body.
|
|
@@ -23,7 +23,7 @@ export interface ApiKeyStoreSetOptions {
|
|
|
23
23
|
* In-memory map of proxy-session → real credentials. The agent subprocess is
|
|
24
24
|
* given a placeholder key and pointed at the local proxy; the proxy swaps in the
|
|
25
25
|
* real credential from this store before forwarding upstream, so it never lives
|
|
26
|
-
* in the subprocess environment.
|
|
26
|
+
* in the subprocess environment.
|
|
27
27
|
* That no-exfiltration property is exactly why subscription OAuth tokens ride
|
|
28
28
|
* the same store instead of the child env: the child keeps the placeholder
|
|
29
29
|
* either way, only the upstream header shape differs.
|
|
@@ -31,17 +31,7 @@ export interface ApiKeyStoreSetOptions {
|
|
|
31
31
|
export class ApiKeyStore {
|
|
32
32
|
private readonly entries = new Map<string, ApiKeyEntry>();
|
|
33
33
|
|
|
34
|
-
set(
|
|
35
|
-
sessionId: string,
|
|
36
|
-
apiKey: string,
|
|
37
|
-
// A plain string third argument (the base URL) remains supported: the
|
|
38
|
-
// pre-kind signature every existing sidecar call site uses.
|
|
39
|
-
optionsOrBaseUrl: string | ApiKeyStoreSetOptions = {},
|
|
40
|
-
): void {
|
|
41
|
-
const options =
|
|
42
|
-
typeof optionsOrBaseUrl === "string"
|
|
43
|
-
? { upstreamBaseUrl: optionsOrBaseUrl }
|
|
44
|
-
: optionsOrBaseUrl;
|
|
34
|
+
set(sessionId: string, apiKey: string, options: ApiKeyStoreSetOptions = {}): void {
|
|
45
35
|
this.entries.set(sessionId, {
|
|
46
36
|
apiKey,
|
|
47
37
|
upstreamBaseUrl: options.upstreamBaseUrl ?? "https://api.anthropic.com",
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type IncomingMessage, type ServerResponse, createServer } from "node:http";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
|
|
4
|
+
/** A Web-standard handler served on loopback. */
|
|
5
|
+
export interface Loopback {
|
|
6
|
+
/** `http://127.0.0.1:<port>`, the port the OS chose. */
|
|
7
|
+
readonly url: string;
|
|
8
|
+
close(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function bridge(
|
|
12
|
+
handle: (request: Request) => Promise<Response>,
|
|
13
|
+
req: IncomingMessage,
|
|
14
|
+
res: ServerResponse,
|
|
15
|
+
): Promise<void> {
|
|
16
|
+
// The CLI going away stops what its request started upstream.
|
|
17
|
+
const gone = new AbortController();
|
|
18
|
+
res.once("close", () => gone.abort());
|
|
19
|
+
const body =
|
|
20
|
+
req.method === "GET" || req.method === "HEAD"
|
|
21
|
+
? undefined
|
|
22
|
+
: (Readable.toWeb(req) as unknown as ReadableStream<Uint8Array>);
|
|
23
|
+
const headers = new Headers();
|
|
24
|
+
for (const [name, value] of Object.entries(req.headers)) {
|
|
25
|
+
if (typeof value === "string") headers.set(name, value);
|
|
26
|
+
else if (value) for (const each of value) headers.append(name, each);
|
|
27
|
+
}
|
|
28
|
+
const request = new Request(`http://127.0.0.1${req.url ?? "/"}`, {
|
|
29
|
+
method: req.method,
|
|
30
|
+
headers,
|
|
31
|
+
body,
|
|
32
|
+
signal: gone.signal,
|
|
33
|
+
...(body && { duplex: "half" }),
|
|
34
|
+
} as RequestInit);
|
|
35
|
+
const response = await handle(request);
|
|
36
|
+
res.writeHead(response.status, Object.fromEntries(response.headers));
|
|
37
|
+
if (!response.body) {
|
|
38
|
+
res.end();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
for await (const chunk of response.body as unknown as AsyncIterable<Uint8Array>) {
|
|
42
|
+
if (gone.signal.aborted) break;
|
|
43
|
+
res.write(chunk);
|
|
44
|
+
}
|
|
45
|
+
res.end();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** What of `Bun.serve` this uses, without Bun's types (Node consumers type-check this). */
|
|
49
|
+
interface BunRuntime {
|
|
50
|
+
serve(options: {
|
|
51
|
+
port: number;
|
|
52
|
+
hostname: string;
|
|
53
|
+
idleTimeout: number;
|
|
54
|
+
fetch(request: Request): Promise<Response>;
|
|
55
|
+
}): { readonly port: number; stop(closeActiveConnections?: boolean): unknown; unref(): void };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Serve `handle` on 127.0.0.1, on a port of its own: with `Bun.serve` under
|
|
60
|
+
* Bun, whose `node:http` says nothing of a client that left once its request
|
|
61
|
+
* body was read (a stopped turn's request would run on upstream), and with
|
|
62
|
+
* `node:http` under Node.
|
|
63
|
+
*/
|
|
64
|
+
export function serveLoopback(handle: (request: Request) => Promise<Response>): Promise<Loopback> {
|
|
65
|
+
const bun = (globalThis as { Bun?: BunRuntime }).Bun;
|
|
66
|
+
if (bun) {
|
|
67
|
+
const server = bun.serve({
|
|
68
|
+
port: 0,
|
|
69
|
+
hostname: "127.0.0.1",
|
|
70
|
+
// A model can think longer than any idle limit between the events it streams.
|
|
71
|
+
idleTimeout: 0,
|
|
72
|
+
fetch: (request) => handle(request).catch(() => new Response(null, { status: 502 })),
|
|
73
|
+
});
|
|
74
|
+
// Nothing on it keeps the process alive.
|
|
75
|
+
server.unref();
|
|
76
|
+
return Promise.resolve({
|
|
77
|
+
url: `http://127.0.0.1:${server.port}`,
|
|
78
|
+
// Not waited for: with a client still connected, Bun's stop can take its time.
|
|
79
|
+
close: async () => {
|
|
80
|
+
server.stop(true);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const server = createServer((req, res) => {
|
|
85
|
+
bridge(handle, req, res).catch(() => {
|
|
86
|
+
if (!res.headersSent) res.writeHead(502);
|
|
87
|
+
res.end();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
server.once("error", reject);
|
|
92
|
+
server.listen(0, "127.0.0.1", () => {
|
|
93
|
+
const { port } = server.address() as { port: number };
|
|
94
|
+
// Nothing on it keeps the process alive.
|
|
95
|
+
server.unref();
|
|
96
|
+
resolve({
|
|
97
|
+
url: `http://127.0.0.1:${port}`,
|
|
98
|
+
close: () =>
|
|
99
|
+
new Promise<void>((done) => {
|
|
100
|
+
server.closeAllConnections();
|
|
101
|
+
server.close(() => done());
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|