@agentproto/adapter-claude-sdk 0.5.11 → 0.6.1

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/dist/index.mjs CHANGED
@@ -203,6 +203,18 @@ var claudeSdk = defineAgentCli({
203
203
  type: "boolean",
204
204
  description: "Enable extended thinking (SDK options.thinking = { type: 'enabled' }). Required by thinking-gated gateway models such as Moonshot's kimi-k2.7-code, which reject a request without it. Off by default \u2014 native Claude models choose their own thinking behaviour.",
205
205
  bin_args_append_when_true: ["--thinking"]
206
+ },
207
+ {
208
+ id: "idle_timeout_ms",
209
+ // Injected into the child env as CLAUDE_SDK_IDLE_TIMEOUT_MS — overrides
210
+ // the generation-stall watchdog (default 90s, see options.ts). Some
211
+ // gateway models (heavy hidden "thinking" before the visible reply, a
212
+ // slower upstream, or a large system-prompt/tool-result context) can
213
+ // legitimately need longer than the default before their first
214
+ // generation chunk after a tool round-trip.
215
+ type: "string",
216
+ description: "Override the generation-stall watchdog in ms (default 90000). Raise for a gateway model that is slow but healthy, not wedged. Injected as CLAUDE_SDK_IDLE_TIMEOUT_MS in the child env.",
217
+ env: { CLAUDE_SDK_IDLE_TIMEOUT_MS: "{value}" }
206
218
  }
207
219
  ],
208
220
  tags: ["anthropic", "claude", "claude-agent-sdk", "agentproto", "acp", "first-party"]
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAqCA,IAAM,yBAAA,mBAA4B,IAAI,GAAA,CAAY,EAAE,CAAA;AACpD,IAAM,0BAA0B,kBAAA,CAAmB,WAAW,EAC3D,MAAA,CAAO,CAAA,EAAA,KAAM,CAAC,yBAAA,CAA0B,GAAA,CAAI,EAAE,CAAC,EAC/C,GAAA,CAAI,CAAA,EAAA,MAAO,EAAE,EAAA,EAAI,QAAA,EAAU,aAAqB,CAAE,CAAA;AAMrD,IAAM,WAAW,aAAA,CAAc,IAAI,IAAI,WAAA,EAAa,MAAA,C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AA,MACE,EAAA,EAAI,OAAA;AAAA;AAAA;AAAA;AAAA,MAIJ,IAAA,EAAM,QAAA;AAAA,MACN,WAAA,EACE,mRAAA;AAAA,MAIF,iBAAA,EAAmB,CAAC,SAAA,EAAW,SAAS;AAAA,KAC1C;AAAA,IACA;AAAA,MACE,EAAA,EAAI,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAKJ,IAAA,EAAM,QAAA;AAAA,MACN,WAAA,EACE,sVAAA;AAAA,MAKF,GAAA,EAAK,EAAE,kBAAA,EAAoB,SAAA;AAAU,KACvC;AAAA,IACA;AAAA,MACE,EAAA,EAAI,YAAA;AAAA;AAAA;AAAA;AAAA,MAIJ,IAAA,EAAM,QAAA;AAAA,MACN,WAAA,EACE,wUAAA;AAAA,MAKF,GAAA,EAAK,EAAE,oBAAA,EAAsB,SAAA;AAAU,KACzC;AAAA,IACA;AAAA,MACE,EAAA,EAAI,UAAA;AAAA;AAAA;AAAA;AAAA,MAIJ,IAAA,EAAM,SAAA;AAAA,MACN,WAAA,EACE,wQAAA;AAAA,MAIF,yBAAA,EAA2B,CAAC,YAAY;AAAA;AAC1C,GACF;AAAA,EACA,MAAM,CAAC,WAAA,EAAa,UAAU,kBAAA,EAAoB,YAAA,EAAc,OAAO,aAAa;AACtF,CAAC;AAEM,SAAS,gBAAA,GAAoC;AAClD,EAAA,OAAO,sBAAsB,SAAS,CAAA;AACxC","file":"index.mjs","sourcesContent":["/**\n * @agentproto/adapter-claude-sdk — first-party adapter that runs Claude Code's\n * agent harness as a LIBRARY.\n *\n * Unlike `@agentproto/adapter-claude-code` (which wraps the third-party\n * `@agentclientprotocol/claude-agent-acp` bridge), this adapter drives the\n * Claude Agent SDK's headless `query()` directly behind an AIP-44 ACP server\n * (see ./acp-host.ts), shipped as a CLI bin (`agentproto-claude-sdk acp`). The\n * daemon spawns it like any other arm; a user can launch it standalone.\n *\n * Driving the SDK directly buys us clean model pinning (`options.model`, no\n * spawn-arg rejection — issue #186), native usage telemetry (a `usage_update`\n * per turn — #186 P3), and a custom `base_url` (`ANTHROPIC_BASE_URL`) that\n * points the same Anthropic-native harness at real Anthropic, Bedrock/Vertex/\n * Azure, or an Anthropic-compatible gateway.\n *\n * import { claudeSdk, claudeSdkRuntime } from \"@agentproto/adapter-claude-sdk\"\n */\n\nimport { fileURLToPath } from \"node:url\"\nimport {\n createAgentCliRuntime,\n defineAgentCli,\n type AgentCliHandle,\n type AgentCliRuntime,\n} from \"@agentproto/driver-agent-cli\"\nimport { listNativeModelIds } from \"@agentproto/model-catalog/llm\"\nimport { DEFAULT_MODEL } from \"./options.js\"\n\n// Native-Anthropic model menu, derived from the catalog's own synced\n// `/v1/models` listing (see `listNativeModelIds`) rather than a hand-typed\n// id array — a hand-typed list silently drops a newly-published id (e.g.\n// Anthropic shipping `claude-opus-4-9`) until someone notices and opens a\n// PR. Nothing is known to need hiding today, so the denylist starts empty\n// — it exists purely as the one sanctioned manual override (a specific id\n// we've vetted and want OFF this adapter), never as a stand-in for a\n// hand-typed allowlist.\nconst NATIVE_ANTHROPIC_DENYLIST = new Set<string>([])\nconst NATIVE_ANTHROPIC_MODELS = listNativeModelIds(\"anthropic\")\n .filter(id => !NATIVE_ANTHROPIC_DENYLIST.has(id))\n .map(id => ({ id, provider: \"anthropic\" as const }))\n\n// Self-locating: the built handle spawns `node <this-dist>/cli.mjs acp`.\n// import.meta.url resolves into dist/ at runtime, where cli.mjs sits next to\n// index.mjs — so the same build works whether the daemon spawns it (resolved\n// from node_modules) or a user runs the published bin.\nconst cliEntry = fileURLToPath(new URL(\"./cli.mjs\", import.meta.url))\n\nexport const claudeSdk: AgentCliHandle = defineAgentCli({\n name: \"claude-sdk\",\n id: \"claude-sdk\",\n description:\n \"First-party agentproto adapter — Claude Code's agent harness run as a \" +\n \"library via the Claude Agent SDK's headless query(), behind an AIP-44 ACP \" +\n \"server. 100% Anthropic-native I/O: clean model pinning (options.model), \" +\n \"native per-turn usage (tokens + cost), and a custom base_url \" +\n \"(ANTHROPIC_BASE_URL) to front real Anthropic, Bedrock/Vertex/Azure, or an \" +\n \"Anthropic-compatible gateway. Spawned as `node cli.mjs acp` over stdio \" +\n \"JSON-RPC, or launched standalone via `agentproto-claude-sdk acp`.\",\n version: \"0.1.0\",\n bin: \"node\",\n bin_args: [cliEntry, \"acp\"],\n install: [\n {\n method: \"npm\",\n package: \"@agentproto/adapter-claude-sdk\",\n global: true,\n },\n ],\n // No external runtime to probe — the SDK's harness runs in the spawned node\n // process. A node version gate is enough to mark the arm ready.\n version_check: {\n cmd: \"node --version\",\n parse: \"(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\",\n range: \">=20.9.0\",\n timeout_ms: 5000,\n },\n auth: {\n ref: \"./claude-sdk.ACP.md\",\n // Auth is read from the spawn env by the SDK. Either an Anthropic key/token\n // (direct or via an Anthropic-compatible gateway), or the cloud-provider\n // toggles below.\n state: {\n env: [\n \"ANTHROPIC_API_KEY\",\n \"ANTHROPIC_AUTH_TOKEN\",\n \"CLAUDE_CODE_USE_BEDROCK\",\n \"CLAUDE_CODE_USE_VERTEX\",\n \"CLAUDE_CODE_USE_FOUNDRY\",\n ],\n },\n },\n // Billing-auth (opt-in — authEnforce defaults to \"when-configured\", so an\n // unconfigured spawn stays ambient/unchanged). provider \"anthropic\" ⇒\n // api-key mode SETS ANTHROPIC_API_KEY. Unlike the claude-code CLI wrapper,\n // the SDK's subscription/bearer var is ANTHROPIC_AUTH_TOKEN (see\n // options.ts / cli.ts) — so that's this adapter's authSubscription.setEnv,\n // with the CLI's CLAUDE_CODE_OAUTH_TOKEN scrubbed as the sibling credential.\n provider: \"anthropic\",\n // A model's route is an independent choice here: gateway routing is\n // injected at runtime via `base_url`, so the same model can go\n // direct-Anthropic or via any gateway → free route selection.\n routeSelection: \"free\",\n authSubscription: {\n setEnv: \"ANTHROPIC_AUTH_TOKEN\",\n conflictEnv: [\"CLAUDE_CODE_OAUTH_TOKEN\"],\n },\n // How this adapter receives a GATEWAY-routed bearer credential (D4) —\n // ANTHROPIC_AUTH_TOKEN, the SAME var as the `auth_token` option below\n // (env: { ANTHROPIC_AUTH_TOKEN: \"{value}\" }) and the one the Claude Agent\n // SDK actually sends as `Authorization: Bearer`. Distinct from a gateway\n // preset's own `keyEnv` (OPENROUTER_API_KEY, MOONSHOT_API_KEY, …) — that's\n // merely where the operator's providers.json stores the key; the runtime's\n // resolveAuthSpec now injects the resolved credential HERE for a gateway\n // route instead, so it lands in a var the SDK actually reads.\n gatewayAuth: { setEnv: \"ANTHROPIC_AUTH_TOKEN\" },\n sandbox:\n \"In-process: the SDK harness runs inside the spawned node process, scoped \" +\n \"to the daemon's cwd. Tool-permission handling defaults to \" +\n \"bypassPermissions (override via CLAUDE_SDK_PERMISSION_MODE); the daemon \" +\n \"owns the surrounding sandbox.\",\n protocol: \"acp\",\n acp: \"./claude-sdk.ACP.md\",\n session: {\n mode: \"persistent\",\n idle_timeout_ms: 1_800_000,\n context_carryover: true,\n },\n models: {\n // A cheap Claude by default — this is the budget first-party arm.\n default: DEFAULT_MODEL,\n // Curated model menu. `provider` states who serves/bills the model; the\n // runtime resolver supplies the matching ANTHROPIC_BASE_URL + credential\n // for gateway providers. This adapter no longer hard-codes gateway URLs\n // or modes — it declares routes/capabilities and consumes runtime-injected\n // ANTHROPIC_BASE_URL + ANTHROPIC_AUTH_TOKEN. The `model` option remains\n // free-form, so any gateway id works even if it is not listed here.\n allowed: [\n // Native Anthropic — every id the catalog's own `/v1/models` sync\n // currently carries for this provider (see NATIVE_ANTHROPIC_MODELS\n // above), not a hand-typed subset.\n ...NATIVE_ANTHROPIC_MODELS,\n // Gateway providers — routing is resolved by the runtime. OpenRouter ids\n // carry the `@openrouter` route-identity suffix so the catalog join pins\n // the gateway route (a bare 2-segment id resolves to the dead direct\n // vendor route instead).\n { id: \"kimi-k3\", provider: \"moonshot\" },\n { id: \"kimi-k2.7-code\", provider: \"moonshot\" },\n { id: \"z-ai/glm-5.2@openrouter\", provider: \"openrouter\" },\n { id: \"deepseek/deepseek-v4-pro@openrouter\", provider: \"openrouter\" },\n { id: \"moonshotai/kimi-k2@openrouter\", provider: \"openrouter\" },\n { id: \"x-ai/grok-4.5@openrouter\", provider: \"openrouter\" },\n { id: \"x-ai/grok-4.20@openrouter\", provider: \"openrouter\" },\n { id: \"x-ai/grok-4.3@openrouter\", provider: \"openrouter\" },\n { id: \"google/gemini-3.1-pro-preview@openrouter\", provider: \"openrouter\" },\n { id: \"google/gemini-3.5-flash@openrouter\", provider: \"openrouter\" },\n { id: \"google/gemini-2.5-flash@openrouter\", provider: \"openrouter\" },\n { id: \"google/gemini-2.5-pro@openrouter\", provider: \"openrouter\" },\n { id: \"moonshotai/kimi-k2.7-code@openrouter\", provider: \"openrouter\" },\n // OpenAI gpt-5.6 series via OpenRouter — reachable via ANTHROPIC_BASE_URL\n // + ANTHROPIC_AUTH_TOKEN (the gatewayAuth setEnv above) like the other\n // gateway rows. The `@openrouter` suffix pins the catalog join to the\n // OpenRouter gateway (the bare id would resolve to the direct-OpenAI\n // route, which the SDK's Anthropic surface can't speak). Real,\n // already-priced OpenRouter chat models, not invented specialist ids.\n { id: \"openai/gpt-5.6-luna@openrouter\", provider: \"openrouter\" },\n { id: \"openai/gpt-5.6-sol@openrouter\", provider: \"openrouter\" },\n // Requesty — route resolved from the catalog `@route`. Verified\n // runnable: a spawn on sference/thinkingcap-qwen3.6-27b@requesty is\n // accepted and produces the same route/profile/key-fingerprint\n // descriptor as the claude-code spawn on the same model.\n { id: \"sference/thinkingcap-qwen3.6-27b@requesty\", provider: \"requesty\" },\n { id: \"sference/glm-5.2@requesty\", provider: \"requesty\" },\n // Local llm-endpoint proxy — the `@llm-endpoint` suffix pins the catalog\n // join to the runtime-registered custom route (Anthropic surface at\n // localhost:18090). A SMALL curated set from the proxy's own `default`\n // pack (packages/llm-endpoint/src/packs.ts); the vendor prefix is the\n // proxy's transparent-provider name so the boundary-stripped\n // `vendor/product` upstream id transparently routes.\n { id: \"moonshot/kimi-k3@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"moonshot/kimi-k2.7-code@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"moonshot/kimi-k2.6@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"zai/glm-5.2@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"openai/gpt-4.1@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"openai/gpt-4o-mini@llm-endpoint\", provider: \"llm-endpoint\" },\n ],\n env: {\n anthropic: \"ANTHROPIC_API_KEY\",\n },\n },\n capabilities: {\n streaming: true,\n // Claude Code's built-in tools (Read/Edit/Bash/…) and any injected MCP\n // tools run inside the harness and are relayed to the host as ACP\n // tool_call / tool_call_update updates (see acp-host.ts + message-map.ts).\n tool_calls: true,\n sub_agents: true,\n file_io: true,\n multimodal: false,\n // Turns resume via the SDK session store (options.resume), keyed by the\n // pinned session id.\n resumable: true,\n bidirectional: true,\n },\n // Operation modes. Only the native \"default\" profile remains as a manifest\n // mode — gateway routing is now resolved by the runtime and injected via\n // ANTHROPIC_BASE_URL + ANTHROPIC_AUTH_TOKEN. The adapter declares the\n // providers/models it can consume, but it no longer hard-codes gateway URLs.\n modes: [\n {\n id: \"default\",\n description:\n \"Native Anthropic — the real Anthropic API (or whatever \" +\n \"ANTHROPIC_BASE_URL / cloud toggles the environment or runtime \" +\n \"resolver already sets). Uses the native Claude models in `allowed`.\",\n },\n ],\n options: [\n {\n id: \"model\",\n // string (not enum) so any model id works without a code change — native\n // Claude ids, or a gateway id when a gateway mode is selected. Applied as\n // a `--model <id>` spawn arg → SDK options.model.\n type: \"string\" as const,\n description:\n \"Model id → SDK options.model, applied as a `--model` arg at spawn. \" +\n \"Native Claude (e.g. 'claude-opus-4-8', 'claude-sonnet-5') in the \" +\n \"default mode, or any gateway id when base_url is set (e.g. \" +\n \"'kimi-k2.7-code', 'z-ai/glm-5.2@openrouter'). Omit for the adapter's default.\",\n bin_args_template: [\"--model\", \"{value}\"],\n },\n {\n id: \"base_url\",\n // Injected into the child env as ANTHROPIC_BASE_URL — keeps the harness\n // Anthropic-native while fronting real Anthropic, a cloud provider, or an\n // Anthropic-compatible gateway (LiteLLM / claude-code-router). When set,\n // buildQueryOptions also pins every model tier to `model` (gateway mode).\n type: \"string\" as const,\n description:\n \"Custom Anthropic base URL. Injected as ANTHROPIC_BASE_URL in the \" +\n \"child env — front real Anthropic, Bedrock/Vertex/Azure, or an \" +\n \"Anthropic-compatible gateway. When set, every internal model tier \" +\n \"(opus/sonnet/haiku/small-fast) is pinned to `model` so a single-model \" +\n \"gateway never gets an unservable tier. Omit to use the default endpoint.\",\n env: { ANTHROPIC_BASE_URL: \"{value}\" },\n },\n {\n id: \"auth_token\",\n // Injected into the child env as ANTHROPIC_AUTH_TOKEN — the SDK sends it\n // as `Authorization: Bearer <token>`, which Anthropic-compatible gateways\n // (Moonshot, OpenRouter) accept. Pair with base_url for a per-spawn key.\n type: \"string\" as const,\n description:\n \"Bearer token for the Anthropic API or a compatible gateway. Injected \" +\n \"as ANTHROPIC_AUTH_TOKEN in the child env (sent as `Authorization: \" +\n \"Bearer`). Pair with base_url to target a gateway (e.g. Moonshot, \" +\n \"OpenRouter) with a per-spawn key instead of the ambient \" +\n \"ANTHROPIC_API_KEY. Omit to use ANTHROPIC_API_KEY from the environment.\",\n env: { ANTHROPIC_AUTH_TOKEN: \"{value}\" },\n },\n {\n id: \"thinking\",\n // Bare flag → cli.ts parses `--thinking` → SDK options.thinking =\n // { type: \"enabled\" }. Needed by thinking-gated gateway models such as\n // kimi-k2.7-code, which reject a request that omits `thinking`.\n type: \"boolean\" as const,\n description:\n \"Enable extended thinking (SDK options.thinking = { type: 'enabled' }). \" +\n \"Required by thinking-gated gateway models such as Moonshot's \" +\n \"kimi-k2.7-code, which reject a request without it. Off by default — \" +\n \"native Claude models choose their own thinking behaviour.\",\n bin_args_append_when_true: [\"--thinking\"],\n },\n ],\n tags: [\"anthropic\", \"claude\", \"claude-agent-sdk\", \"agentproto\", \"acp\", \"first-party\"],\n})\n\nexport function claudeSdkRuntime(): AgentCliRuntime {\n return createAgentCliRuntime(claudeSdk)\n}\n\nexport {\n ClaudeSdkAcpAgent,\n promptText,\n type QueryFn,\n} from \"./acp-host.js\"\nexport {\n buildQueryOptions,\n mapAcpMcpServers,\n DEFAULT_MODEL,\n UnroutedGatewayModelError,\n type ClaudeSdkConfig,\n} from \"./options.js\"\nexport {\n sdkMessageToUpdates,\n assistantMessageUpdates,\n userMessageUpdates,\n resultUsageUpdate,\n systemInitSessionId,\n toolKindForClaudeTool,\n toolCallTitle,\n type UsageSessionUpdate,\n} from \"./message-map.js\"\nexport { runAcpOverStdio } from \"./run.js\"\nexport type { AgentCliHandle, AgentCliRuntime }\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAqCA,IAAM,yBAAA,mBAA4B,IAAI,GAAA,CAAY,EAAE,CAAA;AACpD,IAAM,0BAA0B,kBAAA,CAAmB,WAAW,EAC3D,MAAA,CAAO,CAAA,EAAA,KAAM,CAAC,yBAAA,CAA0B,GAAA,CAAI,EAAE,CAAC,EAC/C,GAAA,CAAI,CAAA,EAAA,MAAO,EAAE,EAAA,EAAI,QAAA,EAAU,aAAqB,CAAE,CAAA;AAMrD,IAAM,WAAW,aAAA,CAAc,IAAI,IAAI,WAAA,EAAa,MAAA,CAAA,IAAA,CAAY,GAAG,CAAC,CAAA;AAE7D,IAAM,YAA4B,cAAA,CAAe;AAAA,EACtD,IAAA,EAAM,YAAA;AAAA,EACN,EAAA,EAAI,YAAA;AAAA,EACJ,WAAA,EACE,8eAAA;AAAA,EAOF,OAAA,EAAS,OAAA;AAAA,EACT,GAAA,EAAK,MAAA;AAAA,EACL,QAAA,EAAU,CAAC,QAAA,EAAU,KAAK,CAAA;AAAA,EAC1B,OAAA,EAAS;AAAA,IACP;AAAA,MACE,MAAA,EAAQ,KAAA;AAAA,MACR,OAAA,EAAS,gCAAA;AAAA,MACT,MAAA,EAAQ;AAAA;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AAAA;AAAA;AAAA;AAAA,MAIJ,IAAA,EAAM,QAAA;AAAA,MACN,WAAA,EACE,wUAAA;AAAA,MAKF,GAAA,EAAK,EAAE,oBAAA,EAAsB,SAAA;AAAU,KACzC;AAAA,IACA;AAAA,MACE,EAAA,EAAI,UAAA;AAAA;AAAA;AAAA;AAAA,MAIJ,IAAA,EAAM,SAAA;AAAA,MACN,WAAA,EACE,wQAAA;AAAA,MAIF,yBAAA,EAA2B,CAAC,YAAY;AAAA,KAC1C;AAAA,IACA;AAAA,MACE,EAAA,EAAI,iBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOJ,IAAA,EAAM,QAAA;AAAA,MACN,WAAA,EACE,wLAAA;AAAA,MAGF,GAAA,EAAK,EAAE,0BAAA,EAA4B,SAAA;AAAU;AAC/C,GACF;AAAA,EACA,MAAM,CAAC,WAAA,EAAa,UAAU,kBAAA,EAAoB,YAAA,EAAc,OAAO,aAAa;AACtF,CAAC;AAEM,SAAS,gBAAA,GAAoC;AAClD,EAAA,OAAO,sBAAsB,SAAS,CAAA;AACxC","file":"index.mjs","sourcesContent":["/**\n * @agentproto/adapter-claude-sdk — first-party adapter that runs Claude Code's\n * agent harness as a LIBRARY.\n *\n * Unlike `@agentproto/adapter-claude-code` (which wraps the third-party\n * `@agentclientprotocol/claude-agent-acp` bridge), this adapter drives the\n * Claude Agent SDK's headless `query()` directly behind an AIP-44 ACP server\n * (see ./acp-host.ts), shipped as a CLI bin (`agentproto-claude-sdk acp`). The\n * daemon spawns it like any other arm; a user can launch it standalone.\n *\n * Driving the SDK directly buys us clean model pinning (`options.model`, no\n * spawn-arg rejection — issue #186), native usage telemetry (a `usage_update`\n * per turn — #186 P3), and a custom `base_url` (`ANTHROPIC_BASE_URL`) that\n * points the same Anthropic-native harness at real Anthropic, Bedrock/Vertex/\n * Azure, or an Anthropic-compatible gateway.\n *\n * import { claudeSdk, claudeSdkRuntime } from \"@agentproto/adapter-claude-sdk\"\n */\n\nimport { fileURLToPath } from \"node:url\"\nimport {\n createAgentCliRuntime,\n defineAgentCli,\n type AgentCliHandle,\n type AgentCliRuntime,\n} from \"@agentproto/driver-agent-cli\"\nimport { listNativeModelIds } from \"@agentproto/model-catalog/llm\"\nimport { DEFAULT_MODEL } from \"./options.js\"\n\n// Native-Anthropic model menu, derived from the catalog's own synced\n// `/v1/models` listing (see `listNativeModelIds`) rather than a hand-typed\n// id array — a hand-typed list silently drops a newly-published id (e.g.\n// Anthropic shipping `claude-opus-4-9`) until someone notices and opens a\n// PR. Nothing is known to need hiding today, so the denylist starts empty\n// — it exists purely as the one sanctioned manual override (a specific id\n// we've vetted and want OFF this adapter), never as a stand-in for a\n// hand-typed allowlist.\nconst NATIVE_ANTHROPIC_DENYLIST = new Set<string>([])\nconst NATIVE_ANTHROPIC_MODELS = listNativeModelIds(\"anthropic\")\n .filter(id => !NATIVE_ANTHROPIC_DENYLIST.has(id))\n .map(id => ({ id, provider: \"anthropic\" as const }))\n\n// Self-locating: the built handle spawns `node <this-dist>/cli.mjs acp`.\n// import.meta.url resolves into dist/ at runtime, where cli.mjs sits next to\n// index.mjs — so the same build works whether the daemon spawns it (resolved\n// from node_modules) or a user runs the published bin.\nconst cliEntry = fileURLToPath(new URL(\"./cli.mjs\", import.meta.url))\n\nexport const claudeSdk: AgentCliHandle = defineAgentCli({\n name: \"claude-sdk\",\n id: \"claude-sdk\",\n description:\n \"First-party agentproto adapter — Claude Code's agent harness run as a \" +\n \"library via the Claude Agent SDK's headless query(), behind an AIP-44 ACP \" +\n \"server. 100% Anthropic-native I/O: clean model pinning (options.model), \" +\n \"native per-turn usage (tokens + cost), and a custom base_url \" +\n \"(ANTHROPIC_BASE_URL) to front real Anthropic, Bedrock/Vertex/Azure, or an \" +\n \"Anthropic-compatible gateway. Spawned as `node cli.mjs acp` over stdio \" +\n \"JSON-RPC, or launched standalone via `agentproto-claude-sdk acp`.\",\n version: \"0.1.0\",\n bin: \"node\",\n bin_args: [cliEntry, \"acp\"],\n install: [\n {\n method: \"npm\",\n package: \"@agentproto/adapter-claude-sdk\",\n global: true,\n },\n ],\n // No external runtime to probe — the SDK's harness runs in the spawned node\n // process. A node version gate is enough to mark the arm ready.\n version_check: {\n cmd: \"node --version\",\n parse: \"(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\",\n range: \">=20.9.0\",\n timeout_ms: 5000,\n },\n auth: {\n ref: \"./claude-sdk.ACP.md\",\n // Auth is read from the spawn env by the SDK. Either an Anthropic key/token\n // (direct or via an Anthropic-compatible gateway), or the cloud-provider\n // toggles below.\n state: {\n env: [\n \"ANTHROPIC_API_KEY\",\n \"ANTHROPIC_AUTH_TOKEN\",\n \"CLAUDE_CODE_USE_BEDROCK\",\n \"CLAUDE_CODE_USE_VERTEX\",\n \"CLAUDE_CODE_USE_FOUNDRY\",\n ],\n },\n },\n // Billing-auth (opt-in — authEnforce defaults to \"when-configured\", so an\n // unconfigured spawn stays ambient/unchanged). provider \"anthropic\" ⇒\n // api-key mode SETS ANTHROPIC_API_KEY. Unlike the claude-code CLI wrapper,\n // the SDK's subscription/bearer var is ANTHROPIC_AUTH_TOKEN (see\n // options.ts / cli.ts) — so that's this adapter's authSubscription.setEnv,\n // with the CLI's CLAUDE_CODE_OAUTH_TOKEN scrubbed as the sibling credential.\n provider: \"anthropic\",\n // A model's route is an independent choice here: gateway routing is\n // injected at runtime via `base_url`, so the same model can go\n // direct-Anthropic or via any gateway → free route selection.\n routeSelection: \"free\",\n authSubscription: {\n setEnv: \"ANTHROPIC_AUTH_TOKEN\",\n conflictEnv: [\"CLAUDE_CODE_OAUTH_TOKEN\"],\n },\n // How this adapter receives a GATEWAY-routed bearer credential (D4) —\n // ANTHROPIC_AUTH_TOKEN, the SAME var as the `auth_token` option below\n // (env: { ANTHROPIC_AUTH_TOKEN: \"{value}\" }) and the one the Claude Agent\n // SDK actually sends as `Authorization: Bearer`. Distinct from a gateway\n // preset's own `keyEnv` (OPENROUTER_API_KEY, MOONSHOT_API_KEY, …) — that's\n // merely where the operator's providers.json stores the key; the runtime's\n // resolveAuthSpec now injects the resolved credential HERE for a gateway\n // route instead, so it lands in a var the SDK actually reads.\n gatewayAuth: { setEnv: \"ANTHROPIC_AUTH_TOKEN\" },\n sandbox:\n \"In-process: the SDK harness runs inside the spawned node process, scoped \" +\n \"to the daemon's cwd. Tool-permission handling defaults to \" +\n \"bypassPermissions (override via CLAUDE_SDK_PERMISSION_MODE); the daemon \" +\n \"owns the surrounding sandbox.\",\n protocol: \"acp\",\n acp: \"./claude-sdk.ACP.md\",\n session: {\n mode: \"persistent\",\n idle_timeout_ms: 1_800_000,\n context_carryover: true,\n },\n models: {\n // A cheap Claude by default — this is the budget first-party arm.\n default: DEFAULT_MODEL,\n // Curated model menu. `provider` states who serves/bills the model; the\n // runtime resolver supplies the matching ANTHROPIC_BASE_URL + credential\n // for gateway providers. This adapter no longer hard-codes gateway URLs\n // or modes — it declares routes/capabilities and consumes runtime-injected\n // ANTHROPIC_BASE_URL + ANTHROPIC_AUTH_TOKEN. The `model` option remains\n // free-form, so any gateway id works even if it is not listed here.\n allowed: [\n // Native Anthropic — every id the catalog's own `/v1/models` sync\n // currently carries for this provider (see NATIVE_ANTHROPIC_MODELS\n // above), not a hand-typed subset.\n ...NATIVE_ANTHROPIC_MODELS,\n // Gateway providers — routing is resolved by the runtime. OpenRouter ids\n // carry the `@openrouter` route-identity suffix so the catalog join pins\n // the gateway route (a bare 2-segment id resolves to the dead direct\n // vendor route instead).\n { id: \"kimi-k3\", provider: \"moonshot\" },\n { id: \"kimi-k2.7-code\", provider: \"moonshot\" },\n { id: \"z-ai/glm-5.2@openrouter\", provider: \"openrouter\" },\n { id: \"deepseek/deepseek-v4-pro@openrouter\", provider: \"openrouter\" },\n { id: \"moonshotai/kimi-k2@openrouter\", provider: \"openrouter\" },\n { id: \"x-ai/grok-4.5@openrouter\", provider: \"openrouter\" },\n { id: \"x-ai/grok-4.20@openrouter\", provider: \"openrouter\" },\n { id: \"x-ai/grok-4.3@openrouter\", provider: \"openrouter\" },\n { id: \"google/gemini-3.1-pro-preview@openrouter\", provider: \"openrouter\" },\n { id: \"google/gemini-3.5-flash@openrouter\", provider: \"openrouter\" },\n { id: \"google/gemini-2.5-flash@openrouter\", provider: \"openrouter\" },\n { id: \"google/gemini-2.5-pro@openrouter\", provider: \"openrouter\" },\n { id: \"moonshotai/kimi-k2.7-code@openrouter\", provider: \"openrouter\" },\n // OpenAI gpt-5.6 series via OpenRouter — reachable via ANTHROPIC_BASE_URL\n // + ANTHROPIC_AUTH_TOKEN (the gatewayAuth setEnv above) like the other\n // gateway rows. The `@openrouter` suffix pins the catalog join to the\n // OpenRouter gateway (the bare id would resolve to the direct-OpenAI\n // route, which the SDK's Anthropic surface can't speak). Real,\n // already-priced OpenRouter chat models, not invented specialist ids.\n { id: \"openai/gpt-5.6-luna@openrouter\", provider: \"openrouter\" },\n { id: \"openai/gpt-5.6-sol@openrouter\", provider: \"openrouter\" },\n // Requesty — route resolved from the catalog `@route`. Verified\n // runnable: a spawn on sference/thinkingcap-qwen3.6-27b@requesty is\n // accepted and produces the same route/profile/key-fingerprint\n // descriptor as the claude-code spawn on the same model.\n { id: \"sference/thinkingcap-qwen3.6-27b@requesty\", provider: \"requesty\" },\n { id: \"sference/glm-5.2@requesty\", provider: \"requesty\" },\n // Local llm-endpoint proxy — the `@llm-endpoint` suffix pins the catalog\n // join to the runtime-registered custom route (Anthropic surface at\n // localhost:18090). A SMALL curated set from the proxy's own `default`\n // pack (packages/llm-endpoint/src/packs.ts); the vendor prefix is the\n // proxy's transparent-provider name so the boundary-stripped\n // `vendor/product` upstream id transparently routes.\n { id: \"moonshot/kimi-k3@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"moonshot/kimi-k2.7-code@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"moonshot/kimi-k2.6@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"zai/glm-5.2@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"openai/gpt-4.1@llm-endpoint\", provider: \"llm-endpoint\" },\n { id: \"openai/gpt-4o-mini@llm-endpoint\", provider: \"llm-endpoint\" },\n ],\n env: {\n anthropic: \"ANTHROPIC_API_KEY\",\n },\n },\n capabilities: {\n streaming: true,\n // Claude Code's built-in tools (Read/Edit/Bash/…) and any injected MCP\n // tools run inside the harness and are relayed to the host as ACP\n // tool_call / tool_call_update updates (see acp-host.ts + message-map.ts).\n tool_calls: true,\n sub_agents: true,\n file_io: true,\n multimodal: false,\n // Turns resume via the SDK session store (options.resume), keyed by the\n // pinned session id.\n resumable: true,\n bidirectional: true,\n },\n // Operation modes. Only the native \"default\" profile remains as a manifest\n // mode — gateway routing is now resolved by the runtime and injected via\n // ANTHROPIC_BASE_URL + ANTHROPIC_AUTH_TOKEN. The adapter declares the\n // providers/models it can consume, but it no longer hard-codes gateway URLs.\n modes: [\n {\n id: \"default\",\n description:\n \"Native Anthropic — the real Anthropic API (or whatever \" +\n \"ANTHROPIC_BASE_URL / cloud toggles the environment or runtime \" +\n \"resolver already sets). Uses the native Claude models in `allowed`.\",\n },\n ],\n options: [\n {\n id: \"model\",\n // string (not enum) so any model id works without a code change — native\n // Claude ids, or a gateway id when a gateway mode is selected. Applied as\n // a `--model <id>` spawn arg → SDK options.model.\n type: \"string\" as const,\n description:\n \"Model id → SDK options.model, applied as a `--model` arg at spawn. \" +\n \"Native Claude (e.g. 'claude-opus-4-8', 'claude-sonnet-5') in the \" +\n \"default mode, or any gateway id when base_url is set (e.g. \" +\n \"'kimi-k2.7-code', 'z-ai/glm-5.2@openrouter'). Omit for the adapter's default.\",\n bin_args_template: [\"--model\", \"{value}\"],\n },\n {\n id: \"base_url\",\n // Injected into the child env as ANTHROPIC_BASE_URL — keeps the harness\n // Anthropic-native while fronting real Anthropic, a cloud provider, or an\n // Anthropic-compatible gateway (LiteLLM / claude-code-router). When set,\n // buildQueryOptions also pins every model tier to `model` (gateway mode).\n type: \"string\" as const,\n description:\n \"Custom Anthropic base URL. Injected as ANTHROPIC_BASE_URL in the \" +\n \"child env — front real Anthropic, Bedrock/Vertex/Azure, or an \" +\n \"Anthropic-compatible gateway. When set, every internal model tier \" +\n \"(opus/sonnet/haiku/small-fast) is pinned to `model` so a single-model \" +\n \"gateway never gets an unservable tier. Omit to use the default endpoint.\",\n env: { ANTHROPIC_BASE_URL: \"{value}\" },\n },\n {\n id: \"auth_token\",\n // Injected into the child env as ANTHROPIC_AUTH_TOKEN — the SDK sends it\n // as `Authorization: Bearer <token>`, which Anthropic-compatible gateways\n // (Moonshot, OpenRouter) accept. Pair with base_url for a per-spawn key.\n type: \"string\" as const,\n description:\n \"Bearer token for the Anthropic API or a compatible gateway. Injected \" +\n \"as ANTHROPIC_AUTH_TOKEN in the child env (sent as `Authorization: \" +\n \"Bearer`). Pair with base_url to target a gateway (e.g. Moonshot, \" +\n \"OpenRouter) with a per-spawn key instead of the ambient \" +\n \"ANTHROPIC_API_KEY. Omit to use ANTHROPIC_API_KEY from the environment.\",\n env: { ANTHROPIC_AUTH_TOKEN: \"{value}\" },\n },\n {\n id: \"thinking\",\n // Bare flag → cli.ts parses `--thinking` → SDK options.thinking =\n // { type: \"enabled\" }. Needed by thinking-gated gateway models such as\n // kimi-k2.7-code, which reject a request that omits `thinking`.\n type: \"boolean\" as const,\n description:\n \"Enable extended thinking (SDK options.thinking = { type: 'enabled' }). \" +\n \"Required by thinking-gated gateway models such as Moonshot's \" +\n \"kimi-k2.7-code, which reject a request without it. Off by default — \" +\n \"native Claude models choose their own thinking behaviour.\",\n bin_args_append_when_true: [\"--thinking\"],\n },\n {\n id: \"idle_timeout_ms\",\n // Injected into the child env as CLAUDE_SDK_IDLE_TIMEOUT_MS — overrides\n // the generation-stall watchdog (default 90s, see options.ts). Some\n // gateway models (heavy hidden \"thinking\" before the visible reply, a\n // slower upstream, or a large system-prompt/tool-result context) can\n // legitimately need longer than the default before their first\n // generation chunk after a tool round-trip.\n type: \"string\" as const,\n description:\n \"Override the generation-stall watchdog in ms (default 90000). Raise \" +\n \"for a gateway model that is slow but healthy, not wedged. Injected \" +\n \"as CLAUDE_SDK_IDLE_TIMEOUT_MS in the child env.\",\n env: { CLAUDE_SDK_IDLE_TIMEOUT_MS: \"{value}\" },\n },\n ],\n tags: [\"anthropic\", \"claude\", \"claude-agent-sdk\", \"agentproto\", \"acp\", \"first-party\"],\n})\n\nexport function claudeSdkRuntime(): AgentCliRuntime {\n return createAgentCliRuntime(claudeSdk)\n}\n\nexport {\n ClaudeSdkAcpAgent,\n promptText,\n type QueryFn,\n} from \"./acp-host.js\"\nexport {\n buildQueryOptions,\n mapAcpMcpServers,\n DEFAULT_MODEL,\n UnroutedGatewayModelError,\n type ClaudeSdkConfig,\n} from \"./options.js\"\nexport {\n sdkMessageToUpdates,\n assistantMessageUpdates,\n userMessageUpdates,\n resultUsageUpdate,\n systemInitSessionId,\n toolKindForClaudeTool,\n toolCallTitle,\n type UsageSessionUpdate,\n} from \"./message-map.js\"\nexport { runAcpOverStdio } from \"./run.js\"\nexport type { AgentCliHandle, AgentCliRuntime }\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentproto/adapter-claude-sdk",
3
- "version": "0.5.11",
3
+ "version": "0.6.1",
4
4
  "description": "@agentproto/adapter-claude-sdk — first-party agentproto adapter that runs Claude Code's agent harness as a library via the Claude Agent SDK headless query(), behind an AIP-44 ACP server. 100% Anthropic-native I/O; clean model pinning + base_url; native usage telemetry.",
5
5
  "keywords": [
6
6
  "agentproto",
@@ -47,17 +47,17 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@agentclientprotocol/sdk": "^0.21.0",
51
- "@anthropic-ai/claude-agent-sdk": "^0.3.251",
52
- "@agentproto/driver-agent-cli": "2.4.1",
53
- "@agentproto/model-catalog": "0.9.2",
54
- "@agentproto/provider-presets": "0.6.1"
50
+ "@agentclientprotocol/sdk": "^0.21.1",
51
+ "@anthropic-ai/claude-agent-sdk": "^0.3.263",
52
+ "@agentproto/model-catalog": "0.9.4",
53
+ "@agentproto/driver-agent-cli": "2.4.2",
54
+ "@agentproto/provider-presets": "0.6.2"
55
55
  },
56
56
  "devDependencies": {
57
- "@types/node": "^25.6.2",
57
+ "@types/node": "^25.9.5",
58
58
  "tsup": "^8.5.1",
59
59
  "typescript": "^5.9.3",
60
- "vitest": "^3.2.4",
60
+ "vitest": "^3.2.7",
61
61
  "@agentproto/tooling": "0.1.0"
62
62
  },
63
63
  "scripts": {