@agentproto/adapter-claude-sdk 0.6.2 → 0.7.0

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/README.md CHANGED
@@ -62,16 +62,45 @@ tier the harness might internally request — `ANTHROPIC_MODEL`,
62
62
  Native Anthropic (no `base_url`) leaves tier routing untouched.
63
63
 
64
64
  The runtime resolver injects the correct `ANTHROPIC_BASE_URL` and credential for
65
- registered gateway providers (Moonshot, OpenRouter, Requesty, DeepSeek,
66
- `llm-endpoint`, etc.), so the adapter no longer hard-codes gateway URLs or modes.
67
- You can still override manually with `base_url` + `auth_token` for a gateway that
68
- is not yet in the catalog.
65
+ registered gateway providers (Moonshot, OpenRouter, Requesty, OpenCode Go,
66
+ OpenCode Zen, DeepSeek, `llm-endpoint`, etc.), so the adapter no longer
67
+ hard-codes gateway URLs or modes. You can still override manually with
68
+ `base_url` + `auth_token` for a gateway that is not yet in the catalog.
69
69
 
70
70
  Note the Anthropic-flavored base URLs carry no `/v1`: the SDK appends
71
71
  `/v1/messages` itself, so a `/v1` in the preset yields `…/v1/v1/messages` → 404.
72
72
  Verify a gateway by POSTing to `<base_url>/v1/messages` — NOT by curling the
73
73
  endpoint you think it serves.
74
74
 
75
+ ### OpenCode Go / OpenCode Zen
76
+
77
+ Two separate OpenCode billing rails, both Anthropic-compatible and both keyed
78
+ on `OPENCODE_API_KEY` (opencode's own convention — same env NAME, two different
79
+ secrets, so the per-spawn auth profile's endpoint is what picks the rail):
80
+
81
+ | Route | Preset base URL | What the Anthropic surface serves |
82
+ |-------|-----------------|-----------------------------------|
83
+ | `opencode-go` | `https://opencode.ai/zen/go` | 4 of 36 ids: `minimax-m2.5`, `minimax-m2.7`, `minimax-m3`, `qwen3.8-flash` |
84
+ | `opencode` (Zen) | `https://opencode.ai/zen` | 20 of 102 ids — the entire Claude family (`claude-opus-5`, `claude-sonnet-5`, `claude-sonnet-4-6`, `claude-fable-5`/`-5-1`, `claude-haiku-4-5`, …) plus `qwen3.5/3.6-plus` and the `minimax-*-free` variants |
85
+
86
+ Zen is the valuable one here: it drives this very harness on real Claude models
87
+ against a Zen balance.
88
+
89
+ Model ids for these two carry **no `@route` suffix** — the route IS the id's
90
+ leading segment (`opencode/claude-sonnet-4-6`, `opencode-go/minimax-m3`),
91
+ matching opencode's own config spelling. Each endpoint also serves OpenAI
92
+ chat/completions-, OpenAI Responses- and (Zen only) Gemini-flavored models
93
+ behind the same base URL; those are unreachable from an Anthropic client and are
94
+ deliberately absent from this adapter's menu — run them through the `opencode`
95
+ adapter instead. The menu is derived from the catalog's generated per-model
96
+ surface discriminator (`listOpencodeAnthropicModelRefs`), never hand-typed.
97
+
98
+ Not verified live: no OpenCode key was available when this shipped, so unlike
99
+ the Moonshot / OpenRouter / Requesty rows above, these base URLs come from
100
+ models.dev's published endpoints (`https://opencode.ai/zen/go/v1`,
101
+ `https://opencode.ai/zen/v1`) minus the `/v1` the client appends, not from a
102
+ successful `claude -p` run.
103
+
75
104
  ### Extended thinking
76
105
 
77
106
  Some gateway models are thinking-gated — `kimi-k2.7-code` rejects any request
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { DEFAULT_MODEL } from './chunk-TT4O3BGM.mjs';
2
2
  export { ClaudeSdkAcpAgent, DEFAULT_MODEL, UnroutedGatewayModelError, assistantMessageUpdates, buildQueryOptions, mapAcpMcpServers, promptText, resultUsageUpdate, runAcpOverStdio, sdkMessageToUpdates, systemInitSessionId, toolCallTitle, toolKindForClaudeTool, userMessageUpdates } from './chunk-TT4O3BGM.mjs';
3
3
  import { fileURLToPath } from 'url';
4
4
  import { defineAgentCli, createAgentCliRuntime } from '@agentproto/driver-agent-cli';
5
- import { listNativeModelIds } from '@agentproto/model-catalog/llm';
5
+ import { listNativeModelIds, listOpencodeAnthropicModelRefs } from '@agentproto/model-catalog/llm';
6
6
 
7
7
  /**
8
8
  * @agentproto/adapter-claude-sdk v0.1.0-alpha
@@ -10,6 +10,16 @@ import { listNativeModelIds } from '@agentproto/model-catalog/llm';
10
10
  */
11
11
  var NATIVE_ANTHROPIC_DENYLIST = /* @__PURE__ */ new Set([]);
12
12
  var NATIVE_ANTHROPIC_MODELS = listNativeModelIds("anthropic").filter((id) => !NATIVE_ANTHROPIC_DENYLIST.has(id)).map((id) => ({ id, provider: "anthropic" }));
13
+ var OPENCODE_ANTHROPIC_MODELS = [
14
+ ...listOpencodeAnthropicModelRefs("opencode-go").map((id) => ({
15
+ id,
16
+ provider: "opencode-go"
17
+ })),
18
+ ...listOpencodeAnthropicModelRefs("opencode").map((id) => ({
19
+ id,
20
+ provider: "opencode"
21
+ }))
22
+ ];
13
23
  var cliEntry = fileURLToPath(new URL("./cli.mjs", import.meta.url));
14
24
  var claudeSdk = defineAgentCli({
15
25
  name: "claude-sdk",
@@ -125,6 +135,8 @@ var claudeSdk = defineAgentCli({
125
135
  // descriptor as the claude-code spawn on the same model.
126
136
  { id: "sference/thinkingcap-qwen3.6-27b@requesty", provider: "requesty" },
127
137
  { id: "sference/glm-5.2@requesty", provider: "requesty" },
138
+ // OpenCode Go + OpenCode Zen — see OPENCODE_ANTHROPIC_MODELS above.
139
+ ...OPENCODE_ANTHROPIC_MODELS,
128
140
  // Local llm-endpoint proxy — the `@llm-endpoint` suffix pins the catalog
129
141
  // join to the runtime-registered custom route (Anthropic surface at
130
142
  // localhost:18090). A SMALL curated set from the proxy's own `default`
@@ -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,CAA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AA,EACA,OAAA,EAAS;AAAA,IACP;AAAA,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,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"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAwCA,IAAM,yBAAA,mBAA4B,IAAI,GAAA,CAAY,EAAE,CAAA;AACpD,IAAM,0BAA0B,kBAAA,CAA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AA;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 {\n listNativeModelIds,\n listOpencodeAnthropicModelRefs,\n} 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// OpenCode Go / OpenCode Zen, via their Anthropic-compatible gateway presets\n// (`opencode-go` / `opencode`). Same derivation as claude-code's: each\n// endpoint serves three wire surfaces behind one base URL and only the\n// `/v1/messages` subset is reachable from the SDK, so the menu comes from the\n// catalog's generated per-model surface discriminator, never a hand-typed\n// list. Zen's Anthropic subset is the whole Claude family, which is what makes\n// this route worth having: the SDK's own harness on real Claude models against\n// a Zen balance. No `@route` suffix — for these endpoints the route IS the\n// id's leading segment.\nconst OPENCODE_ANTHROPIC_MODELS = [\n ...listOpencodeAnthropicModelRefs(\"opencode-go\").map(id => ({\n id,\n provider: \"opencode-go\" as const,\n })),\n ...listOpencodeAnthropicModelRefs(\"opencode\").map(id => ({\n id,\n provider: \"opencode\" as const,\n })),\n]\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 // OpenCode Go + OpenCode Zen — see OPENCODE_ANTHROPIC_MODELS above.\n ...OPENCODE_ANTHROPIC_MODELS,\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.6.2",
3
+ "version": "0.7.0",
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",
@@ -48,10 +48,10 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@agentclientprotocol/sdk": "^0.21.1",
51
- "@anthropic-ai/claude-agent-sdk": "^0.3.263",
52
- "@agentproto/driver-agent-cli": "2.4.3",
53
- "@agentproto/model-catalog": "0.9.4",
54
- "@agentproto/provider-presets": "0.6.2"
51
+ "@anthropic-ai/claude-agent-sdk": "^0.3.270",
52
+ "@agentproto/driver-agent-cli": "2.4.4",
53
+ "@agentproto/model-catalog": "0.10.0",
54
+ "@agentproto/provider-presets": "0.7.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/node": "^25.9.5",