@namzu/anthropic 0.2.0 → 1.0.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/CHANGELOG.md +64 -0
- package/dist/__tests__/anthropic.test.js +80 -2
- package/dist/__tests__/anthropic.test.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +237 -92
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +20 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/anthropic.test.ts +88 -2
- package/src/client.ts +244 -85
- package/src/types.ts +20 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 229ff8b: **Auto-pick Claude Code's macOS Keychain OAuth token; OAuth-aware Anthropic provider; tighter picker UX.**
|
|
8
|
+
|
|
9
|
+
Hotfix landing two coupled pieces — namzu now starts cleanly on a host where claude-code is already signed in, without asking the user to export anything.
|
|
10
|
+
|
|
11
|
+
**Credentials side (`@namzu/cli`):**
|
|
12
|
+
|
|
13
|
+
- New: macOS Keychain reader. Reads the `Claude Code-credentials` generic-password entry from the login Keychain and extracts the `claudeAiOauth.accessToken` JSON field. Pattern ported from Nous Research's hermes-agent (`agent/anthropic_adapter.py:_read_claude_code_credentials_from_keychain`). Non-throwing — every failure path (non-Darwin, security command missing, entry absent, payload malformed) returns null so the discoverer treats it as "no source" rather than crashing.
|
|
14
|
+
- Discoverer extended: after env vars and clawtool `secrets.toml`, anthropic also accepts the Keychain credential. Detection source is reported as `keychain · Claude Code-credentials` in the picker, so the user can see where their token came from.
|
|
15
|
+
- Token-shape detector: `isAnthropicOAuthToken(value)` identifies OAuth tokens by prefix (`cc-`, `sk-ant-oat`, `eyJ`) vs console API keys (`sk-ant-api`). Drives the apiKey-vs-authToken decision when constructing the Anthropic provider.
|
|
16
|
+
|
|
17
|
+
**Provider side (`@namzu/anthropic`):**
|
|
18
|
+
|
|
19
|
+
- `AnthropicConfig.apiKey` is now optional, mutually exclusive with the new `authToken` field. Exactly one must be set; the constructor throws if neither is.
|
|
20
|
+
- When `authToken` is supplied, the underlying `@anthropic-ai/sdk` client is constructed with `authToken: <token>` (Bearer auth) and the `anthropic-beta: oauth-2025-04-20` header is injected so Anthropic's OAuth routes accept the request. User-supplied `defaultHeaders` merge on top.
|
|
21
|
+
- API-key path unchanged — existing `apiKey` callers see no behavior change.
|
|
22
|
+
|
|
23
|
+
**Picker UX:**
|
|
24
|
+
|
|
25
|
+
- Width capped at 72 chars; previously stretched to the full terminal and looked uncomfortable on wide screens.
|
|
26
|
+
- Empty-state copy tightened — concrete `export ANTHROPIC_API_KEY=…` lines instead of a long paragraph; explicit mention that on macOS a signed-in claude-code is auto-detected via the Keychain.
|
|
27
|
+
- Source labels condensed (`env · ANTHROPIC_API_KEY`, `keychain · Claude Code-credentials`, `clawtool · [work]`, `local · localhost:11434/api/tags`).
|
|
28
|
+
|
|
29
|
+
**Tests:** 5 new keychain unit cases (token-shape detection) plus existing discover tests updated to opt out of host-ambient sources (`skipKeychain: true`) so the suite stays hermetic on any laptop. Total 165/165 (was 160).
|
|
30
|
+
|
|
31
|
+
**Live verification:** on this machine, `namzu` now auto-detects the Claude Code OAuth credential from the Keychain, picker shows `Anthropic (Claude) keychain · Claude Code-credentials ← current` after first pick, and `provider.chatStream()` constructs through the Bearer-auth path with the required beta header.
|
|
32
|
+
|
|
33
|
+
- 52af97e: **Paste images into the conversation (vision input).**
|
|
34
|
+
|
|
35
|
+
A user message can now carry image attachments. `@namzu/sdk` adds an optional `attachments` field to user messages (`ImageAttachment { data, mediaType }`, additive — text messages are unchanged), and the Anthropic provider sends them as image content blocks so the model can see them. In the CLI, press `Ctrl+V` to paste an image from the clipboard — it shows as an `⎘ Image #N` chip in the composer and is sent to the model as vision input when you submit.
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- 2cf78ed: **Complete the Claude Code OAuth identity so tokens actually authorize.**
|
|
40
|
+
|
|
41
|
+
A valid (non-expired) Claude Code OAuth token was still rejected with `401 Invalid authentication credentials` because Anthropic authorizes OAuth-scoped tokens only when the request carries the full Claude Code identity, not just Bearer auth. When `authToken` is set, the provider now sends:
|
|
42
|
+
|
|
43
|
+
- `anthropic-beta: claude-code-20250219,oauth-2025-04-20` (both flags, was only the second).
|
|
44
|
+
- `user-agent: claude-cli/<version> (external, cli)` — version detected from the installed `claude` binary, with a static fallback (Anthropic validates the version server-side).
|
|
45
|
+
- A leading system block `"You are Claude Code, Anthropic's official CLI for Claude."` — required as the first `system` element on OAuth requests.
|
|
46
|
+
|
|
47
|
+
All three apply only on the `authToken` path; the `apiKey` (console key, `x-api-key`) path is unchanged. Verified end-to-end against the live Anthropic API.
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [542f057]
|
|
50
|
+
- Updated dependencies [df09910]
|
|
51
|
+
- Updated dependencies [140bcc0]
|
|
52
|
+
- Updated dependencies [ea21863]
|
|
53
|
+
- Updated dependencies [38c4b62]
|
|
54
|
+
- Updated dependencies [265150b]
|
|
55
|
+
- Updated dependencies [a1c6694]
|
|
56
|
+
- Updated dependencies [52af97e]
|
|
57
|
+
- Updated dependencies [a71422a]
|
|
58
|
+
- Updated dependencies [d6b5bc1]
|
|
59
|
+
- Updated dependencies [8fd9349]
|
|
60
|
+
- Updated dependencies [63e44f7]
|
|
61
|
+
- Updated dependencies [63b4885]
|
|
62
|
+
- Updated dependencies [38c4b62]
|
|
63
|
+
- Updated dependencies [6b74cd0]
|
|
64
|
+
- Updated dependencies [d86b161]
|
|
65
|
+
- @namzu/sdk@1.0.0
|
|
66
|
+
|
|
3
67
|
## 0.2.0
|
|
4
68
|
|
|
5
69
|
### Minor Changes
|
|
@@ -48,8 +48,12 @@ describe('@namzu/anthropic', () => {
|
|
|
48
48
|
expect(provider.id).toBe('anthropic');
|
|
49
49
|
expect(provider.name).toBe('Anthropic');
|
|
50
50
|
});
|
|
51
|
-
it('throws when constructed without an apiKey', () => {
|
|
52
|
-
expect(() => new AnthropicProvider({})).toThrow(/apiKey
|
|
51
|
+
it('throws when constructed without an apiKey or authToken', () => {
|
|
52
|
+
expect(() => new AnthropicProvider({})).toThrow(/apiKey.*or.*authToken.*required/);
|
|
53
|
+
});
|
|
54
|
+
it('accepts an authToken instead of an apiKey (OAuth path)', () => {
|
|
55
|
+
const provider = new AnthropicProvider({ authToken: 'cc-oauth-token' });
|
|
56
|
+
expect(provider.id).toBe('anthropic');
|
|
53
57
|
});
|
|
54
58
|
it('creates via ProviderRegistry.create with the registered type', () => {
|
|
55
59
|
registerAnthropic();
|
|
@@ -61,6 +65,80 @@ describe('@namzu/anthropic', () => {
|
|
|
61
65
|
expect(provider.id).toBe('anthropic');
|
|
62
66
|
expect(capabilities).toEqual(ANTHROPIC_CAPABILITIES);
|
|
63
67
|
});
|
|
68
|
+
it('does not enforce a provider-local stream idle timeout by default', async () => {
|
|
69
|
+
const provider = new AnthropicProvider({
|
|
70
|
+
apiKey: 'test-key',
|
|
71
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
72
|
+
});
|
|
73
|
+
provider.client = {
|
|
74
|
+
messages: {
|
|
75
|
+
create: async () => delayedAnthropicStream(10),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const chunks = [];
|
|
79
|
+
for await (const chunk of provider.chatStream({
|
|
80
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
81
|
+
messages: [{ role: 'user', content: 'hello' }],
|
|
82
|
+
maxTokens: 100,
|
|
83
|
+
})) {
|
|
84
|
+
chunks.push(chunk);
|
|
85
|
+
}
|
|
86
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
87
|
+
});
|
|
88
|
+
it('supports an opt-in stream idle timeout for deployments that need it', async () => {
|
|
89
|
+
const provider = new AnthropicProvider({
|
|
90
|
+
apiKey: 'test-key',
|
|
91
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
92
|
+
streamIdleTimeoutMs: 1,
|
|
93
|
+
});
|
|
94
|
+
provider.client = {
|
|
95
|
+
messages: {
|
|
96
|
+
create: async () => delayedAnthropicStream(20),
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
const drain = async () => {
|
|
100
|
+
for await (const _chunk of provider.chatStream({
|
|
101
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
102
|
+
messages: [{ role: 'user', content: 'hello' }],
|
|
103
|
+
maxTokens: 100,
|
|
104
|
+
})) {
|
|
105
|
+
// Drain the stream.
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
await expect(drain()).rejects.toThrow(/stream idle/);
|
|
109
|
+
});
|
|
64
110
|
});
|
|
65
111
|
});
|
|
112
|
+
async function* delayedAnthropicStream(delayMs) {
|
|
113
|
+
yield {
|
|
114
|
+
type: 'message_start',
|
|
115
|
+
message: {
|
|
116
|
+
id: 'msg_test',
|
|
117
|
+
usage: { input_tokens: 1, output_tokens: 0 },
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
121
|
+
yield {
|
|
122
|
+
type: 'content_block_start',
|
|
123
|
+
index: 0,
|
|
124
|
+
content_block: { type: 'text' },
|
|
125
|
+
};
|
|
126
|
+
yield {
|
|
127
|
+
type: 'content_block_delta',
|
|
128
|
+
index: 0,
|
|
129
|
+
delta: { type: 'text_delta', text: 'ok' },
|
|
130
|
+
};
|
|
131
|
+
yield {
|
|
132
|
+
type: 'content_block_stop',
|
|
133
|
+
index: 0,
|
|
134
|
+
};
|
|
135
|
+
yield {
|
|
136
|
+
type: 'message_delta',
|
|
137
|
+
delta: { stop_reason: 'end_turn' },
|
|
138
|
+
usage: { output_tokens: 1 },
|
|
139
|
+
};
|
|
140
|
+
yield {
|
|
141
|
+
type: 'message_stop',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
66
144
|
//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,CAAC,CAAA;AAEF,KAAK,SAAS,CAAC,CAAC,sBAAsB,CAAC,OAAe;IACrD,MAAM;QACL,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE;YACR,EAAE,EAAE,UAAU;YACd,KAAK,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE;SAC5C;KACD,CAAA;IACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAC5D,MAAM;QACL,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,CAAC;QACR,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;KAC/B,CAAA;IACD,MAAM;QACL,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE;KACzC,CAAA;IACD,MAAM;QACL,IAAI,EAAE,oBAAoB;QAC1B,KAAK,EAAE,CAAC;KACR,CAAA;IACD,MAAM;QACL,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE;QAClC,KAAK,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE;KAC3B,CAAA;IACD,MAAM;QACL,IAAI,EAAE,cAAc;KACpB,CAAA;AACF,CAAC"}
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,oBAAoB,EAEpB,WAAW,EACX,SAAS,EACT,WAAW,EAGX,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAkRjD,qBAAa,iBAAkB,YAAW,WAAW;IACpD,QAAQ,CAAC,EAAE,eAAc;IACzB,QAAQ,CAAC,IAAI,eAAc;IAE3B,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,eAAe;IA8BnC,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,iBAAiB;IAmCzB;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAOV,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa,CAAC,WAAW,CAAC;IAyKrE,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IA+BxC,OAAO,CAAC,WAAW;IAmCb,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAMrC"}
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
-
|
|
3
|
+
// Floor for `max_tokens` when neither the request nor the provider
|
|
4
|
+
// config supplied one. Anthropic's API requires the field, so we cannot
|
|
5
|
+
// truly omit it — but 4096 (the original SDK example default) is far
|
|
6
|
+
// below what Sonnet 4.6 / Opus 4.7 natively emit, and would silently
|
|
7
|
+
// clip 20k-word documents. 64k is the canonical "long output" budget
|
|
8
|
+
// these models advertise; the model still stops at its own native
|
|
9
|
+
// ceiling, so passing 64k just means "don't bound below the model".
|
|
10
|
+
const DEFAULT_MAX_TOKENS = 64_000;
|
|
3
11
|
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
12
|
+
const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 0;
|
|
13
|
+
// Claude Code OAuth tokens are scoped to Claude Code usage. Anthropic
|
|
14
|
+
// authorizes them only when three signals are all present, else 401:
|
|
15
|
+
// 1. the OAuth beta headers,
|
|
16
|
+
// 2. a `claude-cli/<version>` user-agent (version validated server-side),
|
|
17
|
+
// 3. a system prompt whose first block is the Claude Code identity line.
|
|
18
|
+
const OAUTH_BETAS = 'claude-code-20250219,oauth-2025-04-20';
|
|
19
|
+
const CLAUDE_CODE_SYSTEM_PREFIX = "You are Claude Code, Anthropic's official CLI for Claude.";
|
|
20
|
+
const CLAUDE_CODE_VERSION_FALLBACK = '2.1.74';
|
|
21
|
+
let claudeCodeVersionCache = null;
|
|
22
|
+
function detectClaudeCodeVersion() {
|
|
23
|
+
if (claudeCodeVersionCache !== null)
|
|
24
|
+
return claudeCodeVersionCache;
|
|
25
|
+
for (const bin of ['claude', 'claude-code']) {
|
|
26
|
+
try {
|
|
27
|
+
const out = execFileSync(bin, ['--version'], {
|
|
28
|
+
encoding: 'utf8',
|
|
29
|
+
timeout: 5_000,
|
|
30
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
31
|
+
})
|
|
32
|
+
.trim()
|
|
33
|
+
.split(/\s+/)[0];
|
|
34
|
+
if (out && /^\d/.test(out)) {
|
|
35
|
+
claudeCodeVersionCache = out;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// try next binary
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
claudeCodeVersionCache = CLAUDE_CODE_VERSION_FALLBACK;
|
|
44
|
+
return CLAUDE_CODE_VERSION_FALLBACK;
|
|
45
|
+
}
|
|
4
46
|
function extractSystem(messages) {
|
|
5
47
|
const parts = [];
|
|
6
48
|
for (const msg of messages) {
|
|
@@ -56,6 +98,22 @@ function toAnthropicMessages(messages) {
|
|
|
56
98
|
continue;
|
|
57
99
|
}
|
|
58
100
|
const content = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);
|
|
101
|
+
// User message with image attachments → multimodal content blocks
|
|
102
|
+
// (text first, then each image as a base64 image block).
|
|
103
|
+
const attachments = msg.attachments;
|
|
104
|
+
if (msg.role === 'user' && attachments && attachments.length > 0) {
|
|
105
|
+
const blocks = [];
|
|
106
|
+
if (content.length > 0)
|
|
107
|
+
blocks.push({ type: 'text', text: content });
|
|
108
|
+
for (const att of attachments) {
|
|
109
|
+
blocks.push({
|
|
110
|
+
type: 'image',
|
|
111
|
+
source: { type: 'base64', media_type: att.mediaType, data: att.data },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
out.push({ role: 'user', content: blocks });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
59
117
|
out.push({
|
|
60
118
|
role: msg.role === 'assistant' ? 'assistant' : 'user',
|
|
61
119
|
content,
|
|
@@ -133,18 +191,33 @@ export class AnthropicProvider {
|
|
|
133
191
|
client;
|
|
134
192
|
config;
|
|
135
193
|
constructor(config) {
|
|
136
|
-
if (!config.apiKey) {
|
|
137
|
-
throw new Error('AnthropicProvider: apiKey is required');
|
|
194
|
+
if (!config.apiKey && !config.authToken) {
|
|
195
|
+
throw new Error('AnthropicProvider: either `apiKey` or `authToken` is required');
|
|
138
196
|
}
|
|
139
197
|
this.config = config;
|
|
140
198
|
const clientOpts = {
|
|
141
|
-
apiKey: config.apiKey,
|
|
142
199
|
timeout: config.timeout ?? DEFAULT_TIMEOUT_MS,
|
|
143
200
|
};
|
|
201
|
+
if (config.authToken) {
|
|
202
|
+
clientOpts.authToken = config.authToken;
|
|
203
|
+
// OAuth routes require both beta flags + a Claude Code user-agent;
|
|
204
|
+
// without them Anthropic rejects subscription / Claude Code OAuth
|
|
205
|
+
// tokens (intermittent 401/500). The system-prompt identity block
|
|
206
|
+
// is added per-request in buildCreateParams.
|
|
207
|
+
const headers = {
|
|
208
|
+
'anthropic-beta': OAUTH_BETAS,
|
|
209
|
+
'user-agent': `claude-cli/${detectClaudeCodeVersion()} (external, cli)`,
|
|
210
|
+
...(config.defaultHeaders ?? {}),
|
|
211
|
+
};
|
|
212
|
+
clientOpts.defaultHeaders = headers;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
clientOpts.apiKey = config.apiKey;
|
|
216
|
+
if (config.defaultHeaders)
|
|
217
|
+
clientOpts.defaultHeaders = config.defaultHeaders;
|
|
218
|
+
}
|
|
144
219
|
if (config.baseURL)
|
|
145
220
|
clientOpts.baseURL = config.baseURL;
|
|
146
|
-
if (config.defaultHeaders)
|
|
147
|
-
clientOpts.defaultHeaders = config.defaultHeaders;
|
|
148
221
|
this.client = new Anthropic(clientOpts);
|
|
149
222
|
}
|
|
150
223
|
resolveModel(params) {
|
|
@@ -165,8 +238,16 @@ export class AnthropicProvider {
|
|
|
165
238
|
max_tokens: params.maxTokens ?? this.config.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
166
239
|
stream,
|
|
167
240
|
};
|
|
168
|
-
if (
|
|
241
|
+
if (this.config.authToken) {
|
|
242
|
+
// OAuth: the first system block must be the Claude Code identity
|
|
243
|
+
// line or Anthropic rejects the request. Emit the block-array form
|
|
244
|
+
// with the identity prefix first.
|
|
245
|
+
const ccBlock = { type: 'text', text: CLAUDE_CODE_SYSTEM_PREFIX };
|
|
246
|
+
body.system = system ? [ccBlock, { type: 'text', text: system }] : [ccBlock];
|
|
247
|
+
}
|
|
248
|
+
else if (system) {
|
|
169
249
|
body.system = system;
|
|
250
|
+
}
|
|
170
251
|
if (tools)
|
|
171
252
|
body.tools = tools;
|
|
172
253
|
if (toolChoice)
|
|
@@ -198,101 +279,165 @@ export class AnthropicProvider {
|
|
|
198
279
|
// Track active tool-use blocks by content_block index so input_json_delta
|
|
199
280
|
// fragments can reference the right tool call.
|
|
200
281
|
const activeTools = new Map();
|
|
201
|
-
|
|
282
|
+
// Anthropic Messages API streams over SSE. Do not impose a
|
|
283
|
+
// provider-local 90s idle cutoff by default: long reasoning or
|
|
284
|
+
// long tool-argument generation can legitimately pause between
|
|
285
|
+
// SSE events, and cutting it here turns a healthy Messages API
|
|
286
|
+
// run into a false "tool input truncated" failure. Deployments
|
|
287
|
+
// that still need a per-event watchdog can opt in via
|
|
288
|
+
// `streamIdleTimeoutMs`; otherwise the request timeout and caller
|
|
289
|
+
// AbortSignal own lifecycle cancellation.
|
|
290
|
+
const streamIdleTimeoutMs = this.config.streamIdleTimeoutMs ?? DEFAULT_STREAM_IDLE_TIMEOUT_MS;
|
|
291
|
+
const iter = stream[Symbol.asyncIterator]();
|
|
292
|
+
const nextWithIdleTimeout = async () => {
|
|
293
|
+
if (!Number.isFinite(streamIdleTimeoutMs) || streamIdleTimeoutMs <= 0) {
|
|
294
|
+
return iter.next();
|
|
295
|
+
}
|
|
296
|
+
let timer;
|
|
202
297
|
try {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
298
|
+
return await Promise.race([
|
|
299
|
+
iter.next(),
|
|
300
|
+
new Promise((_, reject) => {
|
|
301
|
+
timer = setTimeout(() => {
|
|
302
|
+
reject(new Error(`Anthropic stream idle for ${Math.round(streamIdleTimeoutMs / 1000)}s — aborting so the run lifecycle can emit run_failed.`));
|
|
303
|
+
}, streamIdleTimeoutMs);
|
|
304
|
+
}),
|
|
305
|
+
]);
|
|
306
|
+
}
|
|
307
|
+
finally {
|
|
308
|
+
if (timer !== undefined)
|
|
309
|
+
clearTimeout(timer);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
try {
|
|
313
|
+
for (;;) {
|
|
314
|
+
const result = await nextWithIdleTimeout();
|
|
315
|
+
if (result.done)
|
|
316
|
+
break;
|
|
317
|
+
const event = result.value;
|
|
318
|
+
try {
|
|
319
|
+
switch (event.type) {
|
|
320
|
+
case 'message_start': {
|
|
321
|
+
if (event.message?.id)
|
|
322
|
+
messageId = event.message.id;
|
|
323
|
+
if (event.message?.usage) {
|
|
324
|
+
yield {
|
|
325
|
+
id: messageId,
|
|
326
|
+
delta: {},
|
|
327
|
+
usage: parseUsage(event.message.usage),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
break;
|
|
213
331
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
332
|
+
case 'content_block_start': {
|
|
333
|
+
const idx = event.index ?? 0;
|
|
334
|
+
const block = event.content_block;
|
|
335
|
+
if (block?.type === 'tool_use') {
|
|
336
|
+
const toolId = block.id ?? `tool-${Date.now()}`;
|
|
337
|
+
activeTools.set(idx, { id: toolId, name: block.name ?? '' });
|
|
338
|
+
yield {
|
|
339
|
+
id: messageId,
|
|
340
|
+
delta: {
|
|
341
|
+
toolCalls: [
|
|
342
|
+
{
|
|
343
|
+
index: idx,
|
|
344
|
+
id: toolId,
|
|
345
|
+
type: 'function',
|
|
346
|
+
function: { name: block.name ?? '' },
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
235
353
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
354
|
+
case 'content_block_delta': {
|
|
355
|
+
const idx = event.index ?? 0;
|
|
356
|
+
const delta = event.delta;
|
|
357
|
+
if (delta?.type === 'text_delta' && delta.text) {
|
|
358
|
+
yield { id: messageId, delta: { content: delta.text } };
|
|
359
|
+
}
|
|
360
|
+
else if (delta?.type === 'input_json_delta' && delta.partial_json !== undefined) {
|
|
361
|
+
const active = activeTools.get(idx);
|
|
362
|
+
yield {
|
|
363
|
+
id: messageId,
|
|
364
|
+
delta: {
|
|
365
|
+
toolCalls: [
|
|
366
|
+
{
|
|
367
|
+
index: idx,
|
|
368
|
+
id: active?.id,
|
|
369
|
+
function: { arguments: delta.partial_json },
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
break;
|
|
243
376
|
}
|
|
244
|
-
|
|
377
|
+
case 'content_block_stop': {
|
|
378
|
+
// For tool_use blocks we MUST emit a `toolCallEnd`
|
|
379
|
+
// signal so the consumer-side aggregator (sdk
|
|
380
|
+
// runtime/query/iteration) can flush the buffered
|
|
381
|
+
// `argsBuf` and JSON.parse it into the tool input.
|
|
382
|
+
// Without this signal the executor sees an empty
|
|
383
|
+
// `arguments` string and rejects the call with
|
|
384
|
+
// `Error: Invalid JSON in tool arguments for "<tool>"`
|
|
385
|
+
// — exactly the failure the live cowork test
|
|
386
|
+
// surfaced (Bash + Write both blank-input failed).
|
|
387
|
+
const idx = event.index ?? 0;
|
|
245
388
|
const active = activeTools.get(idx);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
{
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
case 'content_block_stop':
|
|
262
|
-
// Aggregation is consumer-side — nothing to emit.
|
|
263
|
-
break;
|
|
264
|
-
case 'message_delta': {
|
|
265
|
-
if (event.delta?.stop_reason) {
|
|
266
|
-
yield {
|
|
267
|
-
id: messageId,
|
|
268
|
-
delta: {},
|
|
269
|
-
finishReason: mapStopReason(event.delta.stop_reason),
|
|
270
|
-
usage: event.usage ? parseUsage(event.usage) : undefined,
|
|
271
|
-
};
|
|
389
|
+
if (active) {
|
|
390
|
+
yield {
|
|
391
|
+
id: messageId,
|
|
392
|
+
delta: {
|
|
393
|
+
toolCallEnd: { index: idx, id: active.id },
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
activeTools.delete(idx);
|
|
397
|
+
}
|
|
398
|
+
break;
|
|
272
399
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
400
|
+
case 'message_delta': {
|
|
401
|
+
if (event.delta?.stop_reason) {
|
|
402
|
+
yield {
|
|
403
|
+
id: messageId,
|
|
404
|
+
delta: {},
|
|
405
|
+
finishReason: mapStopReason(event.delta.stop_reason),
|
|
406
|
+
usage: event.usage ? parseUsage(event.usage) : undefined,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
else if (event.usage) {
|
|
410
|
+
yield {
|
|
411
|
+
id: messageId,
|
|
412
|
+
delta: {},
|
|
413
|
+
usage: parseUsage(event.usage),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
break;
|
|
279
417
|
}
|
|
280
|
-
|
|
418
|
+
case 'message_stop':
|
|
419
|
+
return;
|
|
420
|
+
default:
|
|
421
|
+
// Ignore unknown / ping / opaque events.
|
|
422
|
+
break;
|
|
281
423
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
424
|
+
}
|
|
425
|
+
catch (parseErr) {
|
|
426
|
+
yield {
|
|
427
|
+
id: messageId,
|
|
428
|
+
delta: {},
|
|
429
|
+
error: `Stream event error: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`,
|
|
430
|
+
};
|
|
287
431
|
}
|
|
288
432
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
433
|
+
}
|
|
434
|
+
finally {
|
|
435
|
+
// Always release the underlying HTTP/2 connection — both on
|
|
436
|
+
// idle-timeout rejection (bubbling up) and on normal stream
|
|
437
|
+
// end (`message_stop` returned out of the loop). Leaving
|
|
438
|
+
// the SSE connection open until OS-level timeout was the
|
|
439
|
+
// gap Codex called out.
|
|
440
|
+
await iter.return?.().catch(() => undefined);
|
|
296
441
|
}
|
|
297
442
|
}
|
|
298
443
|
async listModels() {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":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tB,eAAe,EAAE,MAAM;gBACvB,UAAU,EAAE,GAAG;gBACf,WAAW,EAAE,IAAI;gBACjB,eAAe,EAAE,IAAI;gBACrB,iBAAiB,EAAE,IAAI;aACvB;YACD;gBACC,EAAE,EAAE,0BAA0B;gBAC9B,IAAI,EAAE,iBAAiB;gBACvB,aAAa,EAAE,OAAO;gBACtB,eAAe,EAAE,MAAM;gBACvB,UAAU,EAAE,IAAI;gBAChB,WAAW,EAAE,IAAI;gBACjB,eAAe,EAAE,IAAI;gBACrB,iBAAiB,EAAE,IAAI;aACvB;YACD;gBACC,EAAE,EAAE,2BAA2B;gBAC/B,IAAI,EAAE,kBAAkB;gBACxB,aAAa,EAAE,OAAO;gBACtB,eAAe,EAAE,MAAM;gBACvB,UAAU,EAAE,GAAG;gBACf,WAAW,EAAE,GAAG;gBAChB,eAAe,EAAE,IAAI;gBACrB,iBAAiB,EAAE,IAAI;aACvB;SACD,CAAA;IACF,CAAC;IAED,KAAK,CAAC,WAAW;QAChB,oEAAoE;QACpE,uEAAuE;QACvE,iEAAiE;QACjE,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC3D,CAAC;CACD"}
|
package/dist/types.d.ts
CHANGED
|
@@ -7,17 +7,35 @@
|
|
|
7
7
|
* `AnthropicConfig` with the `type: 'anthropic'` discriminator.
|
|
8
8
|
*/
|
|
9
9
|
export interface AnthropicConfig {
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Console API key (`sk-ant-api-*`). Mutually exclusive with `authToken`.
|
|
12
|
+
* Exactly one of `apiKey` / `authToken` must be set.
|
|
13
|
+
*/
|
|
14
|
+
apiKey?: string;
|
|
11
15
|
/** Default model. Can be overridden per-call. */
|
|
12
16
|
model?: string;
|
|
13
17
|
/** Override base URL (e.g. for AWS Bedrock Anthropic or Google Vertex endpoints — though use @namzu/bedrock for those). */
|
|
14
18
|
baseURL?: string;
|
|
15
19
|
/** Request timeout in ms. */
|
|
16
20
|
timeout?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Optional per-event stream idle watchdog in ms. Disabled by default.
|
|
23
|
+
* Use only for deployments that need to fail a stalled SSE connection
|
|
24
|
+
* independently from the request timeout.
|
|
25
|
+
*/
|
|
26
|
+
streamIdleTimeoutMs?: number;
|
|
17
27
|
/** Custom headers appended to every request. */
|
|
18
28
|
defaultHeaders?: Record<string, string>;
|
|
19
|
-
/** Default max_tokens (Anthropic requires this field). Default:
|
|
29
|
+
/** Default max_tokens (Anthropic requires this field). Default: 64000. */
|
|
20
30
|
maxTokens?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Bearer-style OAuth access token (mutually exclusive with `apiKey`).
|
|
33
|
+
* Use when the credential is an Anthropic OAuth or Claude Code OAuth
|
|
34
|
+
* token rather than an `sk-ant-api-*` console key. The underlying SDK
|
|
35
|
+
* routes the value as `Authorization: Bearer <token>` instead of
|
|
36
|
+
* `x-api-key`.
|
|
37
|
+
*/
|
|
38
|
+
authToken?: string;
|
|
21
39
|
}
|
|
22
40
|
export interface AnthropicProviderConfig extends AnthropicConfig {
|
|
23
41
|
type: 'anthropic';
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,eAAe;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2HAA2H;IAC3H,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC/D,IAAI,EAAE,WAAW,CAAA;CACjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namzu/anthropic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Anthropic LLM provider for @namzu/sdk via the official @anthropic-ai/sdk. Messages API with streaming, tool-use, and extended thinking support.",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"@anthropic-ai/sdk": "^0.89.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@namzu/sdk": ">=
|
|
40
|
+
"@namzu/sdk": ">=1.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@biomejs/biome": "^1.9.4",
|
|
44
44
|
"@types/node": "^22.19.17",
|
|
45
45
|
"typescript": "^5.5.0",
|
|
46
46
|
"vitest": "^2.0.0",
|
|
47
|
-
"@namzu/sdk": "^0.
|
|
47
|
+
"@namzu/sdk": "^1.0.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsc --build",
|
|
@@ -56,8 +56,13 @@ describe('@namzu/anthropic', () => {
|
|
|
56
56
|
expect(provider.name).toBe('Anthropic')
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
-
it('throws when constructed without an apiKey', () => {
|
|
60
|
-
expect(() => new AnthropicProvider({} as any)).toThrow(/apiKey
|
|
59
|
+
it('throws when constructed without an apiKey or authToken', () => {
|
|
60
|
+
expect(() => new AnthropicProvider({} as any)).toThrow(/apiKey.*or.*authToken.*required/)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('accepts an authToken instead of an apiKey (OAuth path)', () => {
|
|
64
|
+
const provider = new AnthropicProvider({ authToken: 'cc-oauth-token' })
|
|
65
|
+
expect(provider.id).toBe('anthropic')
|
|
61
66
|
})
|
|
62
67
|
|
|
63
68
|
it('creates via ProviderRegistry.create with the registered type', () => {
|
|
@@ -70,5 +75,86 @@ describe('@namzu/anthropic', () => {
|
|
|
70
75
|
expect(provider.id).toBe('anthropic')
|
|
71
76
|
expect(capabilities).toEqual(ANTHROPIC_CAPABILITIES)
|
|
72
77
|
})
|
|
78
|
+
|
|
79
|
+
it('does not enforce a provider-local stream idle timeout by default', async () => {
|
|
80
|
+
const provider = new AnthropicProvider({
|
|
81
|
+
apiKey: 'test-key',
|
|
82
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
83
|
+
})
|
|
84
|
+
;(provider as any).client = {
|
|
85
|
+
messages: {
|
|
86
|
+
create: async () => delayedAnthropicStream(10),
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const chunks = []
|
|
91
|
+
for await (const chunk of provider.chatStream({
|
|
92
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
93
|
+
messages: [{ role: 'user', content: 'hello' }],
|
|
94
|
+
maxTokens: 100,
|
|
95
|
+
})) {
|
|
96
|
+
chunks.push(chunk)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
expect(chunks.length).toBeGreaterThan(0)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('supports an opt-in stream idle timeout for deployments that need it', async () => {
|
|
103
|
+
const provider = new AnthropicProvider({
|
|
104
|
+
apiKey: 'test-key',
|
|
105
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
106
|
+
streamIdleTimeoutMs: 1,
|
|
107
|
+
})
|
|
108
|
+
;(provider as any).client = {
|
|
109
|
+
messages: {
|
|
110
|
+
create: async () => delayedAnthropicStream(20),
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const drain = async () => {
|
|
115
|
+
for await (const _chunk of provider.chatStream({
|
|
116
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
117
|
+
messages: [{ role: 'user', content: 'hello' }],
|
|
118
|
+
maxTokens: 100,
|
|
119
|
+
})) {
|
|
120
|
+
// Drain the stream.
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
await expect(drain()).rejects.toThrow(/stream idle/)
|
|
125
|
+
})
|
|
73
126
|
})
|
|
74
127
|
})
|
|
128
|
+
|
|
129
|
+
async function* delayedAnthropicStream(delayMs: number) {
|
|
130
|
+
yield {
|
|
131
|
+
type: 'message_start',
|
|
132
|
+
message: {
|
|
133
|
+
id: 'msg_test',
|
|
134
|
+
usage: { input_tokens: 1, output_tokens: 0 },
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs))
|
|
138
|
+
yield {
|
|
139
|
+
type: 'content_block_start',
|
|
140
|
+
index: 0,
|
|
141
|
+
content_block: { type: 'text' },
|
|
142
|
+
}
|
|
143
|
+
yield {
|
|
144
|
+
type: 'content_block_delta',
|
|
145
|
+
index: 0,
|
|
146
|
+
delta: { type: 'text_delta', text: 'ok' },
|
|
147
|
+
}
|
|
148
|
+
yield {
|
|
149
|
+
type: 'content_block_stop',
|
|
150
|
+
index: 0,
|
|
151
|
+
}
|
|
152
|
+
yield {
|
|
153
|
+
type: 'message_delta',
|
|
154
|
+
delta: { stop_reason: 'end_turn' },
|
|
155
|
+
usage: { output_tokens: 1 },
|
|
156
|
+
}
|
|
157
|
+
yield {
|
|
158
|
+
type: 'message_stop',
|
|
159
|
+
}
|
|
160
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process'
|
|
1
2
|
import Anthropic from '@anthropic-ai/sdk'
|
|
2
3
|
import type {
|
|
3
4
|
ChatCompletionParams,
|
|
@@ -10,8 +11,49 @@ import type {
|
|
|
10
11
|
} from '@namzu/sdk'
|
|
11
12
|
import type { AnthropicConfig } from './types.js'
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
// Floor for `max_tokens` when neither the request nor the provider
|
|
15
|
+
// config supplied one. Anthropic's API requires the field, so we cannot
|
|
16
|
+
// truly omit it — but 4096 (the original SDK example default) is far
|
|
17
|
+
// below what Sonnet 4.6 / Opus 4.7 natively emit, and would silently
|
|
18
|
+
// clip 20k-word documents. 64k is the canonical "long output" budget
|
|
19
|
+
// these models advertise; the model still stops at its own native
|
|
20
|
+
// ceiling, so passing 64k just means "don't bound below the model".
|
|
21
|
+
const DEFAULT_MAX_TOKENS = 64_000
|
|
14
22
|
const DEFAULT_TIMEOUT_MS = 120_000
|
|
23
|
+
const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 0
|
|
24
|
+
|
|
25
|
+
// Claude Code OAuth tokens are scoped to Claude Code usage. Anthropic
|
|
26
|
+
// authorizes them only when three signals are all present, else 401:
|
|
27
|
+
// 1. the OAuth beta headers,
|
|
28
|
+
// 2. a `claude-cli/<version>` user-agent (version validated server-side),
|
|
29
|
+
// 3. a system prompt whose first block is the Claude Code identity line.
|
|
30
|
+
const OAUTH_BETAS = 'claude-code-20250219,oauth-2025-04-20'
|
|
31
|
+
const CLAUDE_CODE_SYSTEM_PREFIX = "You are Claude Code, Anthropic's official CLI for Claude."
|
|
32
|
+
const CLAUDE_CODE_VERSION_FALLBACK = '2.1.74'
|
|
33
|
+
|
|
34
|
+
let claudeCodeVersionCache: string | null = null
|
|
35
|
+
function detectClaudeCodeVersion(): string {
|
|
36
|
+
if (claudeCodeVersionCache !== null) return claudeCodeVersionCache
|
|
37
|
+
for (const bin of ['claude', 'claude-code']) {
|
|
38
|
+
try {
|
|
39
|
+
const out = execFileSync(bin, ['--version'], {
|
|
40
|
+
encoding: 'utf8',
|
|
41
|
+
timeout: 5_000,
|
|
42
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
43
|
+
})
|
|
44
|
+
.trim()
|
|
45
|
+
.split(/\s+/)[0]
|
|
46
|
+
if (out && /^\d/.test(out)) {
|
|
47
|
+
claudeCodeVersionCache = out
|
|
48
|
+
return out
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
// try next binary
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
claudeCodeVersionCache = CLAUDE_CODE_VERSION_FALLBACK
|
|
55
|
+
return CLAUDE_CODE_VERSION_FALLBACK
|
|
56
|
+
}
|
|
15
57
|
|
|
16
58
|
// --------------------------------------------------------------------------------------
|
|
17
59
|
// Message translation: @namzu/sdk → Anthropic Messages API
|
|
@@ -35,7 +77,22 @@ interface AnthropicToolResultBlock {
|
|
|
35
77
|
content: string
|
|
36
78
|
}
|
|
37
79
|
|
|
38
|
-
|
|
80
|
+
interface AnthropicImageBlock {
|
|
81
|
+
type: 'image'
|
|
82
|
+
source: { type: 'base64'; media_type: string; data: string }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Shape of an SDK `ImageAttachment` (read structurally to avoid coupling). */
|
|
86
|
+
interface AttachmentLike {
|
|
87
|
+
readonly data: string
|
|
88
|
+
readonly mediaType: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
type AnthropicContentBlock =
|
|
92
|
+
| AnthropicTextBlock
|
|
93
|
+
| AnthropicToolUseBlock
|
|
94
|
+
| AnthropicToolResultBlock
|
|
95
|
+
| AnthropicImageBlock
|
|
39
96
|
|
|
40
97
|
interface AnthropicMessageParam {
|
|
41
98
|
role: 'user' | 'assistant'
|
|
@@ -103,6 +160,21 @@ function toAnthropicMessages(messages: ChatCompletionParams['messages']): Anthro
|
|
|
103
160
|
}
|
|
104
161
|
|
|
105
162
|
const content = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content)
|
|
163
|
+
// User message with image attachments → multimodal content blocks
|
|
164
|
+
// (text first, then each image as a base64 image block).
|
|
165
|
+
const attachments = (msg as { attachments?: readonly AttachmentLike[] }).attachments
|
|
166
|
+
if (msg.role === 'user' && attachments && attachments.length > 0) {
|
|
167
|
+
const blocks: AnthropicContentBlock[] = []
|
|
168
|
+
if (content.length > 0) blocks.push({ type: 'text', text: content })
|
|
169
|
+
for (const att of attachments) {
|
|
170
|
+
blocks.push({
|
|
171
|
+
type: 'image',
|
|
172
|
+
source: { type: 'base64', media_type: att.mediaType, data: att.data },
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
out.push({ role: 'user', content: blocks })
|
|
176
|
+
continue
|
|
177
|
+
}
|
|
106
178
|
out.push({
|
|
107
179
|
role: msg.role === 'assistant' ? 'assistant' : 'user',
|
|
108
180
|
content,
|
|
@@ -219,17 +291,31 @@ export class AnthropicProvider implements LLMProvider {
|
|
|
219
291
|
private config: AnthropicConfig
|
|
220
292
|
|
|
221
293
|
constructor(config: AnthropicConfig) {
|
|
222
|
-
if (!config.apiKey) {
|
|
223
|
-
throw new Error('AnthropicProvider: apiKey is required')
|
|
294
|
+
if (!config.apiKey && !config.authToken) {
|
|
295
|
+
throw new Error('AnthropicProvider: either `apiKey` or `authToken` is required')
|
|
224
296
|
}
|
|
225
297
|
this.config = config
|
|
226
298
|
|
|
227
299
|
const clientOpts: Record<string, unknown> = {
|
|
228
|
-
apiKey: config.apiKey,
|
|
229
300
|
timeout: config.timeout ?? DEFAULT_TIMEOUT_MS,
|
|
230
301
|
}
|
|
302
|
+
if (config.authToken) {
|
|
303
|
+
clientOpts.authToken = config.authToken
|
|
304
|
+
// OAuth routes require both beta flags + a Claude Code user-agent;
|
|
305
|
+
// without them Anthropic rejects subscription / Claude Code OAuth
|
|
306
|
+
// tokens (intermittent 401/500). The system-prompt identity block
|
|
307
|
+
// is added per-request in buildCreateParams.
|
|
308
|
+
const headers: Record<string, string> = {
|
|
309
|
+
'anthropic-beta': OAUTH_BETAS,
|
|
310
|
+
'user-agent': `claude-cli/${detectClaudeCodeVersion()} (external, cli)`,
|
|
311
|
+
...(config.defaultHeaders ?? {}),
|
|
312
|
+
}
|
|
313
|
+
clientOpts.defaultHeaders = headers
|
|
314
|
+
} else {
|
|
315
|
+
clientOpts.apiKey = config.apiKey
|
|
316
|
+
if (config.defaultHeaders) clientOpts.defaultHeaders = config.defaultHeaders
|
|
317
|
+
}
|
|
231
318
|
if (config.baseURL) clientOpts.baseURL = config.baseURL
|
|
232
|
-
if (config.defaultHeaders) clientOpts.defaultHeaders = config.defaultHeaders
|
|
233
319
|
|
|
234
320
|
this.client = new Anthropic(clientOpts)
|
|
235
321
|
}
|
|
@@ -260,7 +346,15 @@ export class AnthropicProvider implements LLMProvider {
|
|
|
260
346
|
stream,
|
|
261
347
|
}
|
|
262
348
|
|
|
263
|
-
if (
|
|
349
|
+
if (this.config.authToken) {
|
|
350
|
+
// OAuth: the first system block must be the Claude Code identity
|
|
351
|
+
// line or Anthropic rejects the request. Emit the block-array form
|
|
352
|
+
// with the identity prefix first.
|
|
353
|
+
const ccBlock = { type: 'text' as const, text: CLAUDE_CODE_SYSTEM_PREFIX }
|
|
354
|
+
body.system = system ? [ccBlock, { type: 'text' as const, text: system }] : [ccBlock]
|
|
355
|
+
} else if (system) {
|
|
356
|
+
body.system = system
|
|
357
|
+
}
|
|
264
358
|
if (tools) body.tools = tools
|
|
265
359
|
if (toolChoice) body.tool_choice = toolChoice
|
|
266
360
|
if (params.temperature !== undefined) body.temperature = params.temperature
|
|
@@ -294,97 +388,162 @@ export class AnthropicProvider implements LLMProvider {
|
|
|
294
388
|
// fragments can reference the right tool call.
|
|
295
389
|
const activeTools = new Map<number, { id: string; name: string }>()
|
|
296
390
|
|
|
297
|
-
|
|
391
|
+
// Anthropic Messages API streams over SSE. Do not impose a
|
|
392
|
+
// provider-local 90s idle cutoff by default: long reasoning or
|
|
393
|
+
// long tool-argument generation can legitimately pause between
|
|
394
|
+
// SSE events, and cutting it here turns a healthy Messages API
|
|
395
|
+
// run into a false "tool input truncated" failure. Deployments
|
|
396
|
+
// that still need a per-event watchdog can opt in via
|
|
397
|
+
// `streamIdleTimeoutMs`; otherwise the request timeout and caller
|
|
398
|
+
// AbortSignal own lifecycle cancellation.
|
|
399
|
+
const streamIdleTimeoutMs = this.config.streamIdleTimeoutMs ?? DEFAULT_STREAM_IDLE_TIMEOUT_MS
|
|
400
|
+
const iter = (stream as AsyncIterable<StreamEvent>)[Symbol.asyncIterator]()
|
|
401
|
+
const nextWithIdleTimeout = async (): Promise<IteratorResult<StreamEvent>> => {
|
|
402
|
+
if (!Number.isFinite(streamIdleTimeoutMs) || streamIdleTimeoutMs <= 0) {
|
|
403
|
+
return iter.next()
|
|
404
|
+
}
|
|
405
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
298
406
|
try {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
407
|
+
return await Promise.race([
|
|
408
|
+
iter.next(),
|
|
409
|
+
new Promise<IteratorResult<StreamEvent>>((_, reject) => {
|
|
410
|
+
timer = setTimeout(() => {
|
|
411
|
+
reject(
|
|
412
|
+
new Error(
|
|
413
|
+
`Anthropic stream idle for ${Math.round(streamIdleTimeoutMs / 1000)}s — aborting so the run lifecycle can emit run_failed.`,
|
|
414
|
+
),
|
|
415
|
+
)
|
|
416
|
+
}, streamIdleTimeoutMs)
|
|
417
|
+
}),
|
|
418
|
+
])
|
|
419
|
+
} finally {
|
|
420
|
+
if (timer !== undefined) clearTimeout(timer)
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
try {
|
|
425
|
+
for (;;) {
|
|
426
|
+
const result = await nextWithIdleTimeout()
|
|
427
|
+
if (result.done) break
|
|
428
|
+
const event = result.value
|
|
429
|
+
try {
|
|
430
|
+
switch (event.type) {
|
|
431
|
+
case 'message_start': {
|
|
432
|
+
if (event.message?.id) messageId = event.message.id
|
|
433
|
+
if (event.message?.usage) {
|
|
434
|
+
yield {
|
|
435
|
+
id: messageId,
|
|
436
|
+
delta: {},
|
|
437
|
+
usage: parseUsage(event.message.usage),
|
|
438
|
+
}
|
|
307
439
|
}
|
|
440
|
+
break
|
|
308
441
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
},
|
|
442
|
+
case 'content_block_start': {
|
|
443
|
+
const idx = event.index ?? 0
|
|
444
|
+
const block = event.content_block
|
|
445
|
+
if (block?.type === 'tool_use') {
|
|
446
|
+
const toolId = block.id ?? `tool-${Date.now()}`
|
|
447
|
+
activeTools.set(idx, { id: toolId, name: block.name ?? '' })
|
|
448
|
+
yield {
|
|
449
|
+
id: messageId,
|
|
450
|
+
delta: {
|
|
451
|
+
toolCalls: [
|
|
452
|
+
{
|
|
453
|
+
index: idx,
|
|
454
|
+
id: toolId,
|
|
455
|
+
type: 'function',
|
|
456
|
+
function: { name: block.name ?? '' },
|
|
457
|
+
},
|
|
458
|
+
],
|
|
459
|
+
},
|
|
460
|
+
}
|
|
329
461
|
}
|
|
462
|
+
break
|
|
330
463
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
},
|
|
464
|
+
case 'content_block_delta': {
|
|
465
|
+
const idx = event.index ?? 0
|
|
466
|
+
const delta = event.delta
|
|
467
|
+
if (delta?.type === 'text_delta' && delta.text) {
|
|
468
|
+
yield { id: messageId, delta: { content: delta.text } }
|
|
469
|
+
} else if (delta?.type === 'input_json_delta' && delta.partial_json !== undefined) {
|
|
470
|
+
const active = activeTools.get(idx)
|
|
471
|
+
yield {
|
|
472
|
+
id: messageId,
|
|
473
|
+
delta: {
|
|
474
|
+
toolCalls: [
|
|
475
|
+
{
|
|
476
|
+
index: idx,
|
|
477
|
+
id: active?.id,
|
|
478
|
+
function: { arguments: delta.partial_json },
|
|
479
|
+
},
|
|
480
|
+
],
|
|
481
|
+
},
|
|
482
|
+
}
|
|
351
483
|
}
|
|
484
|
+
break
|
|
352
485
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
486
|
+
case 'content_block_stop': {
|
|
487
|
+
// For tool_use blocks we MUST emit a `toolCallEnd`
|
|
488
|
+
// signal so the consumer-side aggregator (sdk
|
|
489
|
+
// runtime/query/iteration) can flush the buffered
|
|
490
|
+
// `argsBuf` and JSON.parse it into the tool input.
|
|
491
|
+
// Without this signal the executor sees an empty
|
|
492
|
+
// `arguments` string and rejects the call with
|
|
493
|
+
// `Error: Invalid JSON in tool arguments for "<tool>"`
|
|
494
|
+
// — exactly the failure the live cowork test
|
|
495
|
+
// surfaced (Bash + Write both blank-input failed).
|
|
496
|
+
const idx = event.index ?? 0
|
|
497
|
+
const active = activeTools.get(idx)
|
|
498
|
+
if (active) {
|
|
499
|
+
yield {
|
|
500
|
+
id: messageId,
|
|
501
|
+
delta: {
|
|
502
|
+
toolCallEnd: { index: idx, id: active.id },
|
|
503
|
+
},
|
|
504
|
+
}
|
|
505
|
+
activeTools.delete(idx)
|
|
365
506
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
507
|
+
break
|
|
508
|
+
}
|
|
509
|
+
case 'message_delta': {
|
|
510
|
+
if (event.delta?.stop_reason) {
|
|
511
|
+
yield {
|
|
512
|
+
id: messageId,
|
|
513
|
+
delta: {},
|
|
514
|
+
finishReason: mapStopReason(event.delta.stop_reason),
|
|
515
|
+
usage: event.usage ? parseUsage(event.usage) : undefined,
|
|
516
|
+
}
|
|
517
|
+
} else if (event.usage) {
|
|
518
|
+
yield {
|
|
519
|
+
id: messageId,
|
|
520
|
+
delta: {},
|
|
521
|
+
usage: parseUsage(event.usage),
|
|
522
|
+
}
|
|
371
523
|
}
|
|
524
|
+
break
|
|
372
525
|
}
|
|
373
|
-
|
|
526
|
+
case 'message_stop':
|
|
527
|
+
return
|
|
528
|
+
default:
|
|
529
|
+
// Ignore unknown / ping / opaque events.
|
|
530
|
+
break
|
|
531
|
+
}
|
|
532
|
+
} catch (parseErr) {
|
|
533
|
+
yield {
|
|
534
|
+
id: messageId,
|
|
535
|
+
delta: {},
|
|
536
|
+
error: `Stream event error: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`,
|
|
374
537
|
}
|
|
375
|
-
case 'message_stop':
|
|
376
|
-
return
|
|
377
|
-
default:
|
|
378
|
-
// Ignore unknown / ping / opaque events.
|
|
379
|
-
break
|
|
380
|
-
}
|
|
381
|
-
} catch (parseErr) {
|
|
382
|
-
yield {
|
|
383
|
-
id: messageId,
|
|
384
|
-
delta: {},
|
|
385
|
-
error: `Stream event error: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`,
|
|
386
538
|
}
|
|
387
539
|
}
|
|
540
|
+
} finally {
|
|
541
|
+
// Always release the underlying HTTP/2 connection — both on
|
|
542
|
+
// idle-timeout rejection (bubbling up) and on normal stream
|
|
543
|
+
// end (`message_stop` returned out of the loop). Leaving
|
|
544
|
+
// the SSE connection open until OS-level timeout was the
|
|
545
|
+
// gap Codex called out.
|
|
546
|
+
await iter.return?.().catch(() => undefined)
|
|
388
547
|
}
|
|
389
548
|
}
|
|
390
549
|
|
package/src/types.ts
CHANGED
|
@@ -8,17 +8,35 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export interface AnthropicConfig {
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Console API key (`sk-ant-api-*`). Mutually exclusive with `authToken`.
|
|
13
|
+
* Exactly one of `apiKey` / `authToken` must be set.
|
|
14
|
+
*/
|
|
15
|
+
apiKey?: string
|
|
12
16
|
/** Default model. Can be overridden per-call. */
|
|
13
17
|
model?: string
|
|
14
18
|
/** Override base URL (e.g. for AWS Bedrock Anthropic or Google Vertex endpoints — though use @namzu/bedrock for those). */
|
|
15
19
|
baseURL?: string
|
|
16
20
|
/** Request timeout in ms. */
|
|
17
21
|
timeout?: number
|
|
22
|
+
/**
|
|
23
|
+
* Optional per-event stream idle watchdog in ms. Disabled by default.
|
|
24
|
+
* Use only for deployments that need to fail a stalled SSE connection
|
|
25
|
+
* independently from the request timeout.
|
|
26
|
+
*/
|
|
27
|
+
streamIdleTimeoutMs?: number
|
|
18
28
|
/** Custom headers appended to every request. */
|
|
19
29
|
defaultHeaders?: Record<string, string>
|
|
20
|
-
/** Default max_tokens (Anthropic requires this field). Default:
|
|
30
|
+
/** Default max_tokens (Anthropic requires this field). Default: 64000. */
|
|
21
31
|
maxTokens?: number
|
|
32
|
+
/**
|
|
33
|
+
* Bearer-style OAuth access token (mutually exclusive with `apiKey`).
|
|
34
|
+
* Use when the credential is an Anthropic OAuth or Claude Code OAuth
|
|
35
|
+
* token rather than an `sk-ant-api-*` console key. The underlying SDK
|
|
36
|
+
* routes the value as `Authorization: Bearer <token>` instead of
|
|
37
|
+
* `x-api-key`.
|
|
38
|
+
*/
|
|
39
|
+
authToken?: string
|
|
22
40
|
}
|
|
23
41
|
|
|
24
42
|
export interface AnthropicProviderConfig extends AnthropicConfig {
|