@agentproto/adapter-claude-sdk 0.2.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/LICENSE +21 -0
- package/README.md +98 -0
- package/claude-sdk.ACP.md +87 -0
- package/dist/chunk-DW2G2NIH.mjs +430 -0
- package/dist/chunk-DW2G2NIH.mjs.map +1 -0
- package/dist/cli.mjs +64 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.ts +263 -0
- package/dist/index.mjs +190 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +70 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { DEFAULT_MODEL } from './chunk-DW2G2NIH.mjs';
|
|
2
|
+
export { ClaudeSdkAcpAgent, DEFAULT_MODEL, assistantMessageUpdates, buildQueryOptions, mapAcpMcpServers, promptText, resultUsageUpdate, runAcpOverStdio, sdkMessageToUpdates, systemInitSessionId, toolCallTitle, toolKindForClaudeTool, userMessageUpdates } from './chunk-DW2G2NIH.mjs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { defineAgentCli, createAgentCliRuntime } from '@agentproto/driver-agent-cli';
|
|
5
|
+
import { ANTHROPIC_GATEWAY_PRESETS } from '@agentproto/provider-presets';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @agentproto/adapter-claude-sdk v0.1.0-alpha
|
|
9
|
+
* First-party agentproto adapter: Claude Agent SDK headless query() -> ACP server.
|
|
10
|
+
*/
|
|
11
|
+
var cliEntry = fileURLToPath(new URL("./cli.mjs", import.meta.url));
|
|
12
|
+
var claudeSdk = defineAgentCli({
|
|
13
|
+
name: "claude-sdk",
|
|
14
|
+
id: "claude-sdk",
|
|
15
|
+
description: "First-party agentproto adapter \u2014 Claude Code's agent harness run as a library via the Claude Agent SDK's headless query(), behind an AIP-44 ACP server. 100% Anthropic-native I/O: clean model pinning (options.model), native per-turn usage (tokens + cost), and a custom base_url (ANTHROPIC_BASE_URL) to front real Anthropic, Bedrock/Vertex/Azure, or an Anthropic-compatible gateway. Spawned as `node cli.mjs acp` over stdio JSON-RPC, or launched standalone via `agentproto-claude-sdk acp`.",
|
|
16
|
+
version: "0.1.0",
|
|
17
|
+
bin: "node",
|
|
18
|
+
bin_args: [cliEntry, "acp"],
|
|
19
|
+
install: [
|
|
20
|
+
{
|
|
21
|
+
method: "npm",
|
|
22
|
+
package: "@agentproto/adapter-claude-sdk",
|
|
23
|
+
global: true
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
// No external runtime to probe — the SDK's harness runs in the spawned node
|
|
27
|
+
// process. A node version gate is enough to mark the arm ready.
|
|
28
|
+
version_check: {
|
|
29
|
+
cmd: "node --version",
|
|
30
|
+
parse: "(\\d+\\.\\d+\\.\\d+)",
|
|
31
|
+
range: ">=20.9.0",
|
|
32
|
+
timeout_ms: 5e3
|
|
33
|
+
},
|
|
34
|
+
auth: {
|
|
35
|
+
ref: "./claude-sdk.ACP.md",
|
|
36
|
+
// Auth is read from the spawn env by the SDK. Either an Anthropic key/token
|
|
37
|
+
// (direct or via an Anthropic-compatible gateway), or the cloud-provider
|
|
38
|
+
// toggles below.
|
|
39
|
+
state: {
|
|
40
|
+
env: [
|
|
41
|
+
"ANTHROPIC_API_KEY",
|
|
42
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
43
|
+
"CLAUDE_CODE_USE_BEDROCK",
|
|
44
|
+
"CLAUDE_CODE_USE_VERTEX",
|
|
45
|
+
"CLAUDE_CODE_USE_FOUNDRY"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
sandbox: "In-process: the SDK harness runs inside the spawned node process, scoped to the daemon's cwd. Tool-permission handling defaults to bypassPermissions (override via CLAUDE_SDK_PERMISSION_MODE); the daemon owns the surrounding sandbox.",
|
|
50
|
+
protocol: "acp",
|
|
51
|
+
acp: "./claude-sdk.ACP.md",
|
|
52
|
+
session: {
|
|
53
|
+
mode: "persistent",
|
|
54
|
+
idle_timeout_ms: 18e5,
|
|
55
|
+
context_carryover: true
|
|
56
|
+
},
|
|
57
|
+
models: {
|
|
58
|
+
// A cheap Claude by default — this is the budget first-party arm.
|
|
59
|
+
default: DEFAULT_MODEL,
|
|
60
|
+
// Native Anthropic models work out of the box (mode: default). The gateway
|
|
61
|
+
// models below only route when the matching mode is selected
|
|
62
|
+
// (mode: moonshot / openrouter) — that mode pre-wires ANTHROPIC_BASE_URL.
|
|
63
|
+
// The `model` option stays free-form, so any gateway id works even if it
|
|
64
|
+
// isn't listed here.
|
|
65
|
+
allowed: [
|
|
66
|
+
// Native Anthropic — mode: default
|
|
67
|
+
"claude-haiku-4-5-20251001",
|
|
68
|
+
"claude-sonnet-5",
|
|
69
|
+
"claude-opus-4-8",
|
|
70
|
+
"claude-fable-5",
|
|
71
|
+
// Moonshot (Kimi) — mode: moonshot
|
|
72
|
+
"kimi-k2.7-code",
|
|
73
|
+
// OpenRouter — mode: openrouter
|
|
74
|
+
"z-ai/glm-5.2",
|
|
75
|
+
"deepseek/deepseek-v4-pro",
|
|
76
|
+
"moonshotai/kimi-k2"
|
|
77
|
+
],
|
|
78
|
+
env: {
|
|
79
|
+
anthropic: "ANTHROPIC_API_KEY"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
capabilities: {
|
|
83
|
+
streaming: true,
|
|
84
|
+
// Claude Code's built-in tools (Read/Edit/Bash/…) and any injected MCP
|
|
85
|
+
// tools run inside the harness and are relayed to the host as ACP
|
|
86
|
+
// tool_call / tool_call_update updates (see acp-host.ts + message-map.ts).
|
|
87
|
+
tool_calls: true,
|
|
88
|
+
sub_agents: true,
|
|
89
|
+
file_io: true,
|
|
90
|
+
multimodal: false,
|
|
91
|
+
// Turns resume via the SDK session store (options.resume), keyed by the
|
|
92
|
+
// pinned session id.
|
|
93
|
+
resumable: true,
|
|
94
|
+
bidirectional: true
|
|
95
|
+
},
|
|
96
|
+
// Gateway presets. The base_url/auth_token/thinking options already let a
|
|
97
|
+
// caller front any Anthropic-compatible gateway by hand; these modes just
|
|
98
|
+
// pre-wire the endpoint (and, for Moonshot, the model + --thinking) so the
|
|
99
|
+
// caller only has to supply the key. The `model` option still overrides.
|
|
100
|
+
modes: [
|
|
101
|
+
{
|
|
102
|
+
id: "default",
|
|
103
|
+
description: "Native Anthropic \u2014 the real Anthropic API (or whatever ANTHROPIC_BASE_URL / cloud toggles the environment already sets). Uses the native Claude models in `allowed`."
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: ANTHROPIC_GATEWAY_PRESETS.moonshot.id,
|
|
107
|
+
description: "Moonshot (Kimi) gateway. Pre-wires ANTHROPIC_BASE_URL to Moonshot's Anthropic-compatible endpoint, defaults the model to kimi-k2.7-code, and enables --thinking (Kimi rejects a request without it). Supply the Moonshot key via the `auth_token` option (or ANTHROPIC_AUTH_TOKEN); override `model` for another Moonshot model.",
|
|
108
|
+
env: {
|
|
109
|
+
ANTHROPIC_BASE_URL: ANTHROPIC_GATEWAY_PRESETS.moonshot.baseUrl,
|
|
110
|
+
// cli.ts reads CLAUDE_SDK_MODEL as the model fallback (a `--model`
|
|
111
|
+
// option still wins), so the mode ships a working default model.
|
|
112
|
+
CLAUDE_SDK_MODEL: ANTHROPIC_GATEWAY_PRESETS.moonshot.defaultModel,
|
|
113
|
+
// Declares this gateway's conventional credential source.
|
|
114
|
+
// buildQueryOptions resolves the bearer from this env when no explicit
|
|
115
|
+
// auth_token / ANTHROPIC_AUTH_TOKEN is set, and always scrubs the
|
|
116
|
+
// ambient ANTHROPIC_API_KEY so it never reaches a non-Anthropic host.
|
|
117
|
+
CLAUDE_SDK_GATEWAY_KEY_ENV: ANTHROPIC_GATEWAY_PRESETS.moonshot.keyEnv
|
|
118
|
+
},
|
|
119
|
+
bin_args_append: ["--thinking"]
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: ANTHROPIC_GATEWAY_PRESETS.openrouter.id,
|
|
123
|
+
description: "OpenRouter gateway. Pre-wires ANTHROPIC_BASE_URL to OpenRouter's Anthropic-compatible endpoint. Pick a model via the `model` option (e.g. 'z-ai/glm-5.2', 'deepseek/deepseek-v4-pro', 'moonshotai/kimi-k2') and supply the OpenRouter key via `auth_token` (or ANTHROPIC_AUTH_TOKEN).",
|
|
124
|
+
env: {
|
|
125
|
+
ANTHROPIC_BASE_URL: ANTHROPIC_GATEWAY_PRESETS.openrouter.baseUrl,
|
|
126
|
+
// Conventional credential source for this gateway (see moonshot above).
|
|
127
|
+
CLAUDE_SDK_GATEWAY_KEY_ENV: ANTHROPIC_GATEWAY_PRESETS.openrouter.keyEnv
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: ANTHROPIC_GATEWAY_PRESETS.deepseek.id,
|
|
132
|
+
description: "DeepSeek gateway. Pre-wires ANTHROPIC_BASE_URL to DeepSeek's Anthropic-compatible endpoint and defaults the model to deepseek-v4-pro. Supply the DeepSeek key via the `auth_token` option (or ANTHROPIC_AUTH_TOKEN); override `model` for deepseek-v4-flash. Thinking is opt-in (DeepSeek accepts requests without it, unlike Kimi).",
|
|
133
|
+
env: {
|
|
134
|
+
ANTHROPIC_BASE_URL: ANTHROPIC_GATEWAY_PRESETS.deepseek.baseUrl,
|
|
135
|
+
// cli.ts reads CLAUDE_SDK_MODEL as the model fallback (a `--model`
|
|
136
|
+
// option still wins), so the mode ships a working default model.
|
|
137
|
+
CLAUDE_SDK_MODEL: ANTHROPIC_GATEWAY_PRESETS.deepseek.defaultModel,
|
|
138
|
+
// Conventional credential source for this gateway (see moonshot above).
|
|
139
|
+
CLAUDE_SDK_GATEWAY_KEY_ENV: ANTHROPIC_GATEWAY_PRESETS.deepseek.keyEnv
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
options: [
|
|
144
|
+
{
|
|
145
|
+
id: "model",
|
|
146
|
+
// string (not enum) so any model id works without a code change — native
|
|
147
|
+
// Claude ids, or a gateway id when a gateway mode is selected. Applied as
|
|
148
|
+
// a `--model <id>` spawn arg → SDK options.model.
|
|
149
|
+
type: "string",
|
|
150
|
+
description: "Model id \u2192 SDK options.model, applied as a `--model` arg at spawn. Native Claude (e.g. 'claude-opus-4-8', 'claude-sonnet-5') in the default mode, or a gateway id when mode is moonshot/openrouter (e.g. 'kimi-k2.7-code', 'z-ai/glm-5.2'). Omit for the mode's default.",
|
|
151
|
+
bin_args_template: ["--model", "{value}"]
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "base_url",
|
|
155
|
+
// Injected into the child env as ANTHROPIC_BASE_URL — keeps the harness
|
|
156
|
+
// Anthropic-native while fronting real Anthropic, a cloud provider, or an
|
|
157
|
+
// Anthropic-compatible gateway (LiteLLM / claude-code-router). When set,
|
|
158
|
+
// buildQueryOptions also pins every model tier to `model` (gateway mode).
|
|
159
|
+
type: "string",
|
|
160
|
+
description: "Custom Anthropic base URL. Injected as ANTHROPIC_BASE_URL in the child env \u2014 front real Anthropic, Bedrock/Vertex/Azure, or an Anthropic-compatible gateway. When set, every internal model tier (opus/sonnet/haiku/small-fast) is pinned to `model` so a single-model gateway never gets an unservable tier. Omit to use the default endpoint.",
|
|
161
|
+
env: { ANTHROPIC_BASE_URL: "{value}" }
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: "auth_token",
|
|
165
|
+
// Injected into the child env as ANTHROPIC_AUTH_TOKEN — the SDK sends it
|
|
166
|
+
// as `Authorization: Bearer <token>`, which Anthropic-compatible gateways
|
|
167
|
+
// (Moonshot, OpenRouter) accept. Pair with base_url for a per-spawn key.
|
|
168
|
+
type: "string",
|
|
169
|
+
description: "Bearer token for the Anthropic API or a compatible gateway. Injected as ANTHROPIC_AUTH_TOKEN in the child env (sent as `Authorization: Bearer`). Pair with base_url to target a gateway (e.g. Moonshot, OpenRouter) with a per-spawn key instead of the ambient ANTHROPIC_API_KEY. Omit to use ANTHROPIC_API_KEY from the environment.",
|
|
170
|
+
env: { ANTHROPIC_AUTH_TOKEN: "{value}" }
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: "thinking",
|
|
174
|
+
// Bare flag → cli.ts parses `--thinking` → SDK options.thinking =
|
|
175
|
+
// { type: "enabled" }. Needed by thinking-gated gateway models such as
|
|
176
|
+
// kimi-k2.7-code, which reject a request that omits `thinking`.
|
|
177
|
+
type: "boolean",
|
|
178
|
+
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.",
|
|
179
|
+
bin_args_append_when_true: ["--thinking"]
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
tags: ["anthropic", "claude", "claude-agent-sdk", "agentproto", "acp", "first-party"]
|
|
183
|
+
});
|
|
184
|
+
function claudeSdkRuntime() {
|
|
185
|
+
return createAgentCliRuntime(claudeSdk);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export { claudeSdk, claudeSdkRuntime };
|
|
189
|
+
//# sourceMappingURL=index.mjs.map
|
|
190
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAiCA,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,MAC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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 { ANTHROPIC_GATEWAY_PRESETS } from \"@agentproto/provider-presets\"\nimport { DEFAULT_MODEL } from \"./options.js\"\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 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 // Native Anthropic models work out of the box (mode: default). The gateway\n // models below only route when the matching mode is selected\n // (mode: moonshot / openrouter) — that mode pre-wires ANTHROPIC_BASE_URL.\n // The `model` option stays free-form, so any gateway id works even if it\n // isn't listed here.\n allowed: [\n // Native Anthropic — mode: default\n \"claude-haiku-4-5-20251001\",\n \"claude-sonnet-5\",\n \"claude-opus-4-8\",\n \"claude-fable-5\",\n // Moonshot (Kimi) — mode: moonshot\n \"kimi-k2.7-code\",\n // OpenRouter — mode: openrouter\n \"z-ai/glm-5.2\",\n \"deepseek/deepseek-v4-pro\",\n \"moonshotai/kimi-k2\",\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 // Gateway presets. The base_url/auth_token/thinking options already let a\n // caller front any Anthropic-compatible gateway by hand; these modes just\n // pre-wire the endpoint (and, for Moonshot, the model + --thinking) so the\n // caller only has to supply the key. The `model` option still overrides.\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 already sets). \" +\n \"Uses the native Claude models in `allowed`.\",\n },\n {\n id: ANTHROPIC_GATEWAY_PRESETS.moonshot.id,\n description:\n \"Moonshot (Kimi) gateway. Pre-wires ANTHROPIC_BASE_URL to Moonshot's \" +\n \"Anthropic-compatible endpoint, defaults the model to kimi-k2.7-code, \" +\n \"and enables --thinking (Kimi rejects a request without it). Supply the \" +\n \"Moonshot key via the `auth_token` option (or ANTHROPIC_AUTH_TOKEN); \" +\n \"override `model` for another Moonshot model.\",\n env: {\n ANTHROPIC_BASE_URL: ANTHROPIC_GATEWAY_PRESETS.moonshot.baseUrl,\n // cli.ts reads CLAUDE_SDK_MODEL as the model fallback (a `--model`\n // option still wins), so the mode ships a working default model.\n CLAUDE_SDK_MODEL: ANTHROPIC_GATEWAY_PRESETS.moonshot.defaultModel,\n // Declares this gateway's conventional credential source.\n // buildQueryOptions resolves the bearer from this env when no explicit\n // auth_token / ANTHROPIC_AUTH_TOKEN is set, and always scrubs the\n // ambient ANTHROPIC_API_KEY so it never reaches a non-Anthropic host.\n CLAUDE_SDK_GATEWAY_KEY_ENV: ANTHROPIC_GATEWAY_PRESETS.moonshot.keyEnv,\n },\n bin_args_append: [\"--thinking\"],\n },\n {\n id: ANTHROPIC_GATEWAY_PRESETS.openrouter.id,\n description:\n \"OpenRouter gateway. Pre-wires ANTHROPIC_BASE_URL to OpenRouter's \" +\n \"Anthropic-compatible endpoint. Pick a model via the `model` option \" +\n \"(e.g. 'z-ai/glm-5.2', 'deepseek/deepseek-v4-pro', 'moonshotai/kimi-k2') \" +\n \"and supply the OpenRouter key via `auth_token` (or ANTHROPIC_AUTH_TOKEN).\",\n env: {\n ANTHROPIC_BASE_URL: ANTHROPIC_GATEWAY_PRESETS.openrouter.baseUrl,\n // Conventional credential source for this gateway (see moonshot above).\n CLAUDE_SDK_GATEWAY_KEY_ENV: ANTHROPIC_GATEWAY_PRESETS.openrouter.keyEnv,\n },\n },\n {\n id: ANTHROPIC_GATEWAY_PRESETS.deepseek.id,\n description:\n \"DeepSeek gateway. Pre-wires ANTHROPIC_BASE_URL to DeepSeek's \" +\n \"Anthropic-compatible endpoint and defaults the model to \" +\n \"deepseek-v4-pro. Supply the DeepSeek key via the `auth_token` option \" +\n \"(or ANTHROPIC_AUTH_TOKEN); override `model` for deepseek-v4-flash. \" +\n \"Thinking is opt-in (DeepSeek accepts requests without it, unlike Kimi).\",\n env: {\n ANTHROPIC_BASE_URL: ANTHROPIC_GATEWAY_PRESETS.deepseek.baseUrl,\n // cli.ts reads CLAUDE_SDK_MODEL as the model fallback (a `--model`\n // option still wins), so the mode ships a working default model.\n CLAUDE_SDK_MODEL: ANTHROPIC_GATEWAY_PRESETS.deepseek.defaultModel,\n // Conventional credential source for this gateway (see moonshot above).\n CLAUDE_SDK_GATEWAY_KEY_ENV: ANTHROPIC_GATEWAY_PRESETS.deepseek.keyEnv,\n },\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 a gateway id when mode is moonshot/openrouter \" +\n \"(e.g. 'kimi-k2.7-code', 'z-ai/glm-5.2'). Omit for the mode'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 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
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentproto/adapter-claude-sdk",
|
|
3
|
+
"version": "0.2.0",
|
|
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
|
+
"keywords": [
|
|
6
|
+
"agentproto",
|
|
7
|
+
"aip-42",
|
|
8
|
+
"aip-44",
|
|
9
|
+
"aip-45",
|
|
10
|
+
"anthropic",
|
|
11
|
+
"claude",
|
|
12
|
+
"claude-agent-sdk",
|
|
13
|
+
"acp",
|
|
14
|
+
"agent-cli",
|
|
15
|
+
"adapter"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://agentproto.sh/docs/aip-45",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/agentproto/ts",
|
|
21
|
+
"directory": "adapters/claude-sdk"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "dist/index.mjs",
|
|
26
|
+
"module": "dist/index.mjs",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"bin": {
|
|
29
|
+
"agentproto-claude-sdk": "dist/cli.mjs"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.mjs",
|
|
35
|
+
"default": "./dist/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./claude-sdk.ACP.md": "./claude-sdk.ACP.md",
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"claude-sdk.ACP.md",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@agentclientprotocol/sdk": "^0.21.0",
|
|
51
|
+
"@anthropic-ai/claude-agent-sdk": "^0.3.200",
|
|
52
|
+
"@agentproto/driver-agent-cli": "0.4.0",
|
|
53
|
+
"@agentproto/provider-presets": "0.2.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^25.6.2",
|
|
57
|
+
"tsup": "^8.5.1",
|
|
58
|
+
"typescript": "^5.9.3",
|
|
59
|
+
"vitest": "^3.2.4",
|
|
60
|
+
"@agentproto/tooling": "0.1.0-alpha.0"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"dev": "tsup --watch",
|
|
64
|
+
"build": "tsup",
|
|
65
|
+
"clean": "rm -rf dist",
|
|
66
|
+
"check-types": "tsc --noEmit",
|
|
67
|
+
"test": "vitest run --passWithNoTests",
|
|
68
|
+
"test:watch": "vitest"
|
|
69
|
+
}
|
|
70
|
+
}
|