@namzu/anthropic 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/LICENSE.md +110 -0
- package/README.md +106 -0
- package/dist/__tests__/anthropic.test.d.ts +2 -0
- package/dist/__tests__/anthropic.test.d.ts.map +1 -0
- package/dist/__tests__/anthropic.test.js +66 -0
- package/dist/__tests__/anthropic.test.js.map +1 -0
- package/dist/client.d.ts +24 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +408 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -0
- package/src/__tests__/anthropic.test.ts +74 -0
- package/src/client.ts +531 -0
- package/src/index.ts +32 -0
- package/src/types.ts +26 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
const DEFAULT_MAX_TOKENS = 4096;
|
|
3
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
4
|
+
function extractSystem(messages) {
|
|
5
|
+
const parts = [];
|
|
6
|
+
for (const msg of messages) {
|
|
7
|
+
if (msg.role === 'system' && typeof msg.content === 'string') {
|
|
8
|
+
parts.push(msg.content);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return parts.length > 0 ? parts.join('\n\n') : undefined;
|
|
12
|
+
}
|
|
13
|
+
function toAnthropicMessages(messages) {
|
|
14
|
+
const out = [];
|
|
15
|
+
let pendingToolResults = [];
|
|
16
|
+
const flushToolResults = () => {
|
|
17
|
+
if (pendingToolResults.length > 0) {
|
|
18
|
+
out.push({ role: 'user', content: pendingToolResults });
|
|
19
|
+
pendingToolResults = [];
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
for (const msg of messages) {
|
|
23
|
+
if (msg.role === 'system')
|
|
24
|
+
continue;
|
|
25
|
+
if (msg.role === 'tool') {
|
|
26
|
+
const toolMsg = msg;
|
|
27
|
+
pendingToolResults.push({
|
|
28
|
+
type: 'tool_result',
|
|
29
|
+
tool_use_id: toolMsg.toolCallId ?? 'unknown',
|
|
30
|
+
content: typeof toolMsg.content === 'string' ? toolMsg.content : JSON.stringify(toolMsg.content),
|
|
31
|
+
});
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
flushToolResults();
|
|
35
|
+
if (msg.role === 'assistant' && 'toolCalls' in msg && msg.toolCalls) {
|
|
36
|
+
const blocks = [];
|
|
37
|
+
if (msg.content && typeof msg.content === 'string') {
|
|
38
|
+
blocks.push({ type: 'text', text: msg.content });
|
|
39
|
+
}
|
|
40
|
+
for (const tc of msg.toolCalls) {
|
|
41
|
+
let parsedInput = {};
|
|
42
|
+
try {
|
|
43
|
+
parsedInput = JSON.parse(tc.function.arguments || '{}');
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
parsedInput = {};
|
|
47
|
+
}
|
|
48
|
+
blocks.push({
|
|
49
|
+
type: 'tool_use',
|
|
50
|
+
id: tc.id,
|
|
51
|
+
name: tc.function.name,
|
|
52
|
+
input: parsedInput,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
out.push({ role: 'assistant', content: blocks });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const content = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);
|
|
59
|
+
out.push({
|
|
60
|
+
role: msg.role === 'assistant' ? 'assistant' : 'user',
|
|
61
|
+
content,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
flushToolResults();
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
function toAnthropicTools(params) {
|
|
68
|
+
if (!params.tools || params.tools.length === 0)
|
|
69
|
+
return undefined;
|
|
70
|
+
return params.tools.map((t) => ({
|
|
71
|
+
name: t.function.name,
|
|
72
|
+
description: t.function.description ?? '',
|
|
73
|
+
input_schema: t.function.parameters ?? { type: 'object' },
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
function toAnthropicToolChoice(tc) {
|
|
77
|
+
if (tc === undefined)
|
|
78
|
+
return undefined;
|
|
79
|
+
if (tc === 'auto')
|
|
80
|
+
return { type: 'auto' };
|
|
81
|
+
if (tc === 'required')
|
|
82
|
+
return { type: 'any' };
|
|
83
|
+
// 'none' — Anthropic has no direct equivalent. Map to auto (omitting tools at call-site
|
|
84
|
+
// is the proper way to forbid tool use); we leave it as auto here for safety.
|
|
85
|
+
if (tc === 'none')
|
|
86
|
+
return { type: 'auto' };
|
|
87
|
+
if (typeof tc === 'object' && tc.type === 'function') {
|
|
88
|
+
return { type: 'tool', name: tc.function.name };
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
function emptyUsage() {
|
|
93
|
+
return {
|
|
94
|
+
promptTokens: 0,
|
|
95
|
+
completionTokens: 0,
|
|
96
|
+
totalTokens: 0,
|
|
97
|
+
cachedTokens: 0,
|
|
98
|
+
cacheWriteTokens: 0,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function parseUsage(raw) {
|
|
102
|
+
if (!raw)
|
|
103
|
+
return emptyUsage();
|
|
104
|
+
const input = raw.input_tokens ?? 0;
|
|
105
|
+
const output = raw.output_tokens ?? 0;
|
|
106
|
+
return {
|
|
107
|
+
promptTokens: input,
|
|
108
|
+
completionTokens: output,
|
|
109
|
+
totalTokens: input + output,
|
|
110
|
+
cachedTokens: raw.cache_read_input_tokens ?? 0,
|
|
111
|
+
cacheWriteTokens: raw.cache_creation_input_tokens ?? 0,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function mapStopReason(reason) {
|
|
115
|
+
switch (reason) {
|
|
116
|
+
case 'end_turn':
|
|
117
|
+
case 'stop_sequence':
|
|
118
|
+
return 'stop';
|
|
119
|
+
case 'tool_use':
|
|
120
|
+
return 'tool_calls';
|
|
121
|
+
case 'max_tokens':
|
|
122
|
+
return 'length';
|
|
123
|
+
default:
|
|
124
|
+
return 'stop';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function extractResponseContent(content) {
|
|
128
|
+
if (!content || content.length === 0)
|
|
129
|
+
return { text: null, toolCalls: undefined };
|
|
130
|
+
let text = null;
|
|
131
|
+
const toolCalls = [];
|
|
132
|
+
for (const block of content) {
|
|
133
|
+
if (block.type === 'text' && typeof block.text === 'string') {
|
|
134
|
+
text = (text ?? '') + block.text;
|
|
135
|
+
}
|
|
136
|
+
else if (block.type === 'tool_use') {
|
|
137
|
+
toolCalls.push({
|
|
138
|
+
id: block.id ?? `tool-${Date.now()}`,
|
|
139
|
+
type: 'function',
|
|
140
|
+
function: {
|
|
141
|
+
name: block.name ?? '',
|
|
142
|
+
arguments: JSON.stringify(block.input ?? {}),
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
text,
|
|
149
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// --------------------------------------------------------------------------------------
|
|
153
|
+
// AnthropicProvider
|
|
154
|
+
// --------------------------------------------------------------------------------------
|
|
155
|
+
export class AnthropicProvider {
|
|
156
|
+
id = 'anthropic';
|
|
157
|
+
name = 'Anthropic';
|
|
158
|
+
client;
|
|
159
|
+
config;
|
|
160
|
+
constructor(config) {
|
|
161
|
+
if (!config.apiKey) {
|
|
162
|
+
throw new Error('AnthropicProvider: apiKey is required');
|
|
163
|
+
}
|
|
164
|
+
this.config = config;
|
|
165
|
+
const clientOpts = {
|
|
166
|
+
apiKey: config.apiKey,
|
|
167
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT_MS,
|
|
168
|
+
};
|
|
169
|
+
if (config.baseURL)
|
|
170
|
+
clientOpts.baseURL = config.baseURL;
|
|
171
|
+
if (config.defaultHeaders)
|
|
172
|
+
clientOpts.defaultHeaders = config.defaultHeaders;
|
|
173
|
+
this.client = new Anthropic(clientOpts);
|
|
174
|
+
}
|
|
175
|
+
resolveModel(params) {
|
|
176
|
+
const model = params.model || this.config.model;
|
|
177
|
+
if (!model) {
|
|
178
|
+
throw new Error('AnthropicProvider: no model specified. Pass `model` on the chat params or set a default via config.');
|
|
179
|
+
}
|
|
180
|
+
return model;
|
|
181
|
+
}
|
|
182
|
+
buildCreateParams(params, stream) {
|
|
183
|
+
const system = extractSystem(params.messages);
|
|
184
|
+
const messages = toAnthropicMessages(params.messages);
|
|
185
|
+
const tools = toAnthropicTools(params);
|
|
186
|
+
const toolChoice = toAnthropicToolChoice(params.toolChoice);
|
|
187
|
+
const body = {
|
|
188
|
+
model: this.resolveModel(params),
|
|
189
|
+
messages,
|
|
190
|
+
max_tokens: params.maxTokens ?? this.config.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
191
|
+
stream,
|
|
192
|
+
};
|
|
193
|
+
if (system)
|
|
194
|
+
body.system = system;
|
|
195
|
+
if (tools)
|
|
196
|
+
body.tools = tools;
|
|
197
|
+
if (toolChoice)
|
|
198
|
+
body.tool_choice = toolChoice;
|
|
199
|
+
if (params.temperature !== undefined)
|
|
200
|
+
body.temperature = params.temperature;
|
|
201
|
+
if (params.topP !== undefined)
|
|
202
|
+
body.top_p = params.topP;
|
|
203
|
+
if (params.topK !== undefined)
|
|
204
|
+
body.top_k = params.topK;
|
|
205
|
+
if (params.stop)
|
|
206
|
+
body.stop_sequences = params.stop;
|
|
207
|
+
return body;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The SDK's `messages.create` is overloaded on the `stream` flag. We build
|
|
211
|
+
* the request as an untyped object bag and narrow the response shape ourselves.
|
|
212
|
+
* Casting via `unknown` keeps us out of `any` territory while acknowledging
|
|
213
|
+
* that the translation layer bridges two type worlds.
|
|
214
|
+
*/
|
|
215
|
+
createRaw(body) {
|
|
216
|
+
const create = this.client.messages.create;
|
|
217
|
+
return create.call(this.client.messages, body);
|
|
218
|
+
}
|
|
219
|
+
async chat(params) {
|
|
220
|
+
const createParams = this.buildCreateParams(params, false);
|
|
221
|
+
const response = (await this.createRaw(createParams));
|
|
222
|
+
const { text, toolCalls } = extractResponseContent(response.content);
|
|
223
|
+
return {
|
|
224
|
+
id: response.id ?? `anthropic-${Date.now()}`,
|
|
225
|
+
model: response.model ?? this.resolveModel(params),
|
|
226
|
+
message: {
|
|
227
|
+
role: 'assistant',
|
|
228
|
+
content: text,
|
|
229
|
+
toolCalls,
|
|
230
|
+
},
|
|
231
|
+
finishReason: mapStopReason(response.stop_reason),
|
|
232
|
+
usage: parseUsage(response.usage),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
async *chatStream(params) {
|
|
236
|
+
const createParams = this.buildCreateParams(params, true);
|
|
237
|
+
const stream = (await this.createRaw(createParams));
|
|
238
|
+
let messageId = '';
|
|
239
|
+
// Track active tool-use blocks by content_block index so input_json_delta
|
|
240
|
+
// fragments can reference the right tool call.
|
|
241
|
+
const activeTools = new Map();
|
|
242
|
+
for await (const event of stream) {
|
|
243
|
+
try {
|
|
244
|
+
switch (event.type) {
|
|
245
|
+
case 'message_start': {
|
|
246
|
+
if (event.message?.id)
|
|
247
|
+
messageId = event.message.id;
|
|
248
|
+
if (event.message?.usage) {
|
|
249
|
+
yield {
|
|
250
|
+
id: messageId,
|
|
251
|
+
delta: {},
|
|
252
|
+
usage: parseUsage(event.message.usage),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case 'content_block_start': {
|
|
258
|
+
const idx = event.index ?? 0;
|
|
259
|
+
const block = event.content_block;
|
|
260
|
+
if (block?.type === 'tool_use') {
|
|
261
|
+
const toolId = block.id ?? `tool-${Date.now()}`;
|
|
262
|
+
activeTools.set(idx, { id: toolId, name: block.name ?? '' });
|
|
263
|
+
yield {
|
|
264
|
+
id: messageId,
|
|
265
|
+
delta: {
|
|
266
|
+
toolCalls: [
|
|
267
|
+
{
|
|
268
|
+
index: idx,
|
|
269
|
+
id: toolId,
|
|
270
|
+
type: 'function',
|
|
271
|
+
function: { name: block.name ?? '' },
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
case 'content_block_delta': {
|
|
280
|
+
const idx = event.index ?? 0;
|
|
281
|
+
const delta = event.delta;
|
|
282
|
+
if (delta?.type === 'text_delta' && delta.text) {
|
|
283
|
+
yield { id: messageId, delta: { content: delta.text } };
|
|
284
|
+
}
|
|
285
|
+
else if (delta?.type === 'input_json_delta' && delta.partial_json !== undefined) {
|
|
286
|
+
const active = activeTools.get(idx);
|
|
287
|
+
yield {
|
|
288
|
+
id: messageId,
|
|
289
|
+
delta: {
|
|
290
|
+
toolCalls: [
|
|
291
|
+
{
|
|
292
|
+
index: idx,
|
|
293
|
+
id: active?.id,
|
|
294
|
+
function: { arguments: delta.partial_json },
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
case 'content_block_stop':
|
|
303
|
+
// Aggregation is consumer-side — nothing to emit.
|
|
304
|
+
break;
|
|
305
|
+
case 'message_delta': {
|
|
306
|
+
if (event.delta?.stop_reason) {
|
|
307
|
+
yield {
|
|
308
|
+
id: messageId,
|
|
309
|
+
delta: {},
|
|
310
|
+
finishReason: mapStopReason(event.delta.stop_reason),
|
|
311
|
+
usage: event.usage ? parseUsage(event.usage) : undefined,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
else if (event.usage) {
|
|
315
|
+
yield {
|
|
316
|
+
id: messageId,
|
|
317
|
+
delta: {},
|
|
318
|
+
usage: parseUsage(event.usage),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
case 'message_stop':
|
|
324
|
+
return;
|
|
325
|
+
default:
|
|
326
|
+
// Ignore unknown / ping / opaque events.
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
catch (parseErr) {
|
|
331
|
+
yield {
|
|
332
|
+
id: messageId,
|
|
333
|
+
delta: {},
|
|
334
|
+
error: `Stream event error: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
async listModels() {
|
|
340
|
+
try {
|
|
341
|
+
// Models API shipped in SDK ~0.32+. Feature-detect via unknown cast so we
|
|
342
|
+
// don't depend on the SDK's surface-level shape in a version-brittle way.
|
|
343
|
+
const clientLike = this.client;
|
|
344
|
+
const listFn = clientLike.models?.list;
|
|
345
|
+
if (typeof listFn !== 'function') {
|
|
346
|
+
return this.knownModels();
|
|
347
|
+
}
|
|
348
|
+
const page = (await listFn({ limit: 100 }));
|
|
349
|
+
const data = page?.data ?? [];
|
|
350
|
+
if (data.length === 0)
|
|
351
|
+
return this.knownModels();
|
|
352
|
+
return data.map((m) => ({
|
|
353
|
+
id: m.id ?? '',
|
|
354
|
+
name: m.display_name ?? m.id ?? '',
|
|
355
|
+
contextWindow: 0,
|
|
356
|
+
maxOutputTokens: 0,
|
|
357
|
+
inputPrice: 0,
|
|
358
|
+
outputPrice: 0,
|
|
359
|
+
supportsToolUse: true,
|
|
360
|
+
supportsStreaming: true,
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
catch {
|
|
364
|
+
return this.knownModels();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
knownModels() {
|
|
368
|
+
return [
|
|
369
|
+
{
|
|
370
|
+
id: 'claude-sonnet-4-5-20250929',
|
|
371
|
+
name: 'Claude Sonnet 4.5',
|
|
372
|
+
contextWindow: 200_000,
|
|
373
|
+
maxOutputTokens: 64_000,
|
|
374
|
+
inputPrice: 3.0,
|
|
375
|
+
outputPrice: 15.0,
|
|
376
|
+
supportsToolUse: true,
|
|
377
|
+
supportsStreaming: true,
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
id: 'claude-opus-4-1-20250805',
|
|
381
|
+
name: 'Claude Opus 4.1',
|
|
382
|
+
contextWindow: 200_000,
|
|
383
|
+
maxOutputTokens: 32_000,
|
|
384
|
+
inputPrice: 15.0,
|
|
385
|
+
outputPrice: 75.0,
|
|
386
|
+
supportsToolUse: true,
|
|
387
|
+
supportsStreaming: true,
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
id: 'claude-haiku-4-5-20251001',
|
|
391
|
+
name: 'Claude Haiku 4.5',
|
|
392
|
+
contextWindow: 200_000,
|
|
393
|
+
maxOutputTokens: 64_000,
|
|
394
|
+
inputPrice: 1.0,
|
|
395
|
+
outputPrice: 5.0,
|
|
396
|
+
supportsToolUse: true,
|
|
397
|
+
supportsStreaming: true,
|
|
398
|
+
},
|
|
399
|
+
];
|
|
400
|
+
}
|
|
401
|
+
async healthCheck() {
|
|
402
|
+
// The client constructor validates the apiKey shape lazily. A no-op
|
|
403
|
+
// check is sufficient here — a real request costs tokens. Callers that
|
|
404
|
+
// want network-level verification should call `chat()` directly.
|
|
405
|
+
return Boolean(this.client) && Boolean(this.config.apiKey);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAA;AAYzC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAC/B,MAAM,kBAAkB,GAAG,OAAO,CAAA;AA+BlC,SAAS,aAAa,CAAC,QAA0C;IAChE,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1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AAuE;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/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ProviderCapabilities, type RegisterOptions } from '@namzu/sdk';
|
|
2
|
+
import type { AnthropicProviderConfig } from './types.js';
|
|
3
|
+
declare module '@namzu/sdk' {
|
|
4
|
+
interface ProviderConfigRegistry {
|
|
5
|
+
anthropic: AnthropicProviderConfig;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare const ANTHROPIC_CAPABILITIES: ProviderCapabilities;
|
|
9
|
+
/**
|
|
10
|
+
* Register `AnthropicProvider` under the `'anthropic'` type in `@namzu/sdk`'s
|
|
11
|
+
* `ProviderRegistry`. Call once at app startup before
|
|
12
|
+
* `ProviderRegistry.create({ type: 'anthropic', ... })`.
|
|
13
|
+
*
|
|
14
|
+
* Throws `DuplicateProviderError` if `'anthropic'` is already registered.
|
|
15
|
+
* Pass `{ replace: true }` to override.
|
|
16
|
+
*/
|
|
17
|
+
export declare function registerAnthropic(options?: RegisterOptions): void;
|
|
18
|
+
export { AnthropicProvider } from './client.js';
|
|
19
|
+
export type { AnthropicConfig, AnthropicProviderConfig } from './types.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAoB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AAE9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAIzD,OAAO,QAAQ,YAAY,CAAC;IAC3B,UAAU,sBAAsB;QAC/B,SAAS,EAAE,uBAAuB,CAAA;KAClC;CACD;AAED,eAAO,MAAM,sBAAsB,EAAE,oBAIpC,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAEjE;AAED,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,YAAY,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ProviderRegistry } from '@namzu/sdk';
|
|
2
|
+
import { AnthropicProvider } from './client.js';
|
|
3
|
+
export const ANTHROPIC_CAPABILITIES = {
|
|
4
|
+
supportsTools: true,
|
|
5
|
+
supportsStreaming: true,
|
|
6
|
+
supportsFunctionCalling: true,
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Register `AnthropicProvider` under the `'anthropic'` type in `@namzu/sdk`'s
|
|
10
|
+
* `ProviderRegistry`. Call once at app startup before
|
|
11
|
+
* `ProviderRegistry.create({ type: 'anthropic', ... })`.
|
|
12
|
+
*
|
|
13
|
+
* Throws `DuplicateProviderError` if `'anthropic'` is already registered.
|
|
14
|
+
* Pass `{ replace: true }` to override.
|
|
15
|
+
*/
|
|
16
|
+
export function registerAnthropic(options) {
|
|
17
|
+
ProviderRegistry.register('anthropic', AnthropicProvider, ANTHROPIC_CAPABILITIES, options);
|
|
18
|
+
}
|
|
19
|
+
export { AnthropicProvider } from './client.js';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,gBAAgB,EAAwB,MAAM,YAAY,CAAA;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAW/C,MAAM,CAAC,MAAM,sBAAsB,GAAyB;IAC3D,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;IACvB,uBAAuB,EAAE,IAAI;CAC7B,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAyB;IAC1D,gBAAgB,CAAC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,OAAO,CAAC,CAAA;AAC3F,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic-specific provider config shapes.
|
|
3
|
+
*
|
|
4
|
+
* `AnthropicConfig` is the constructor input for `AnthropicProvider`.
|
|
5
|
+
* `AnthropicProviderConfig` is the shape the consumer passes to
|
|
6
|
+
* `ProviderRegistry.create({ type: 'anthropic', ... })` — it extends
|
|
7
|
+
* `AnthropicConfig` with the `type: 'anthropic'` discriminator.
|
|
8
|
+
*/
|
|
9
|
+
export interface AnthropicConfig {
|
|
10
|
+
apiKey: string;
|
|
11
|
+
/** Default model. Can be overridden per-call. */
|
|
12
|
+
model?: string;
|
|
13
|
+
/** Override base URL (e.g. for AWS Bedrock Anthropic or Google Vertex endpoints — though use @namzu/bedrock for those). */
|
|
14
|
+
baseURL?: string;
|
|
15
|
+
/** Request timeout in ms. */
|
|
16
|
+
timeout?: number;
|
|
17
|
+
/** Custom headers appended to every request. */
|
|
18
|
+
defaultHeaders?: Record<string, string>;
|
|
19
|
+
/** Default max_tokens (Anthropic requires this field). Default: 4096. */
|
|
20
|
+
maxTokens?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface AnthropicProviderConfig extends AnthropicConfig {
|
|
23
|
+
type: 'anthropic';
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;IACd,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2HAA2H;IAC3H,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC/D,IAAI,EAAE,WAAW,CAAA;CACjB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic-specific provider config shapes.
|
|
3
|
+
*
|
|
4
|
+
* `AnthropicConfig` is the constructor input for `AnthropicProvider`.
|
|
5
|
+
* `AnthropicProviderConfig` is the shape the consumer passes to
|
|
6
|
+
* `ProviderRegistry.create({ type: 'anthropic', ... })` — it extends
|
|
7
|
+
* `AnthropicConfig` with the `type: 'anthropic'` discriminator.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@namzu/anthropic",
|
|
3
|
+
"version": "0.0.1",
|
|
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
|
+
"license": "FSL-1.1-MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"homepage": "https://github.com/cogitave/namzu#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/cogitave/namzu.git",
|
|
11
|
+
"directory": "packages/providers/anthropic"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/cogitave/namzu/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"src",
|
|
27
|
+
"LICENSE.md",
|
|
28
|
+
"README.md",
|
|
29
|
+
"CHANGELOG.md"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"provenance": false
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@anthropic-ai/sdk": "^0.89.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@namzu/sdk": "^1 || ^0.1.6"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@biomejs/biome": "^1.9.4",
|
|
44
|
+
"@types/node": "^22.19.17",
|
|
45
|
+
"typescript": "^5.5.0",
|
|
46
|
+
"vitest": "^2.0.0",
|
|
47
|
+
"@namzu/sdk": "^0.1.8"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc --build",
|
|
51
|
+
"dev": "tsc --build --watch",
|
|
52
|
+
"lint": "biome check src/",
|
|
53
|
+
"lint:fix": "biome check --write src/",
|
|
54
|
+
"format": "biome format --write src/",
|
|
55
|
+
"test": "vitest run --passWithNoTests",
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
57
|
+
"verify": "bash scripts/verify.sh",
|
|
58
|
+
"release:patch": "bash scripts/release.sh patch",
|
|
59
|
+
"release:minor": "bash scripts/release.sh minor",
|
|
60
|
+
"release:major": "bash scripts/release.sh major",
|
|
61
|
+
"release:rc": "bash scripts/release.sh rc",
|
|
62
|
+
"release:beta": "bash scripts/release.sh beta",
|
|
63
|
+
"release:stable": "bash scripts/release.sh stable",
|
|
64
|
+
"release:dry": "bash scripts/release.sh patch --dry-run"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { DuplicateProviderError, ProviderRegistry } from '@namzu/sdk'
|
|
2
|
+
import { beforeEach, describe, expect, it } from 'vitest'
|
|
3
|
+
import { AnthropicProvider } from '../client.js'
|
|
4
|
+
import { ANTHROPIC_CAPABILITIES, registerAnthropic } from '../index.js'
|
|
5
|
+
|
|
6
|
+
// Ensure a clean slate between tests. The sdk pre-registers 'mock' on import
|
|
7
|
+
// via its sideEffects whitelist; we only need to clear 'anthropic' to make
|
|
8
|
+
// re-registration deterministic across tests.
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
if (ProviderRegistry.isSupported('anthropic')) {
|
|
11
|
+
ProviderRegistry.unregister('anthropic')
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe('@namzu/anthropic', () => {
|
|
16
|
+
describe('registerAnthropic()', () => {
|
|
17
|
+
it("adds 'anthropic' to the ProviderRegistry", () => {
|
|
18
|
+
expect(ProviderRegistry.isSupported('anthropic')).toBe(false)
|
|
19
|
+
registerAnthropic()
|
|
20
|
+
expect(ProviderRegistry.isSupported('anthropic')).toBe(true)
|
|
21
|
+
expect(ProviderRegistry.listTypes()).toContain('anthropic')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('throws DuplicateProviderError when called twice without options', () => {
|
|
25
|
+
registerAnthropic()
|
|
26
|
+
expect(() => registerAnthropic()).toThrowError(DuplicateProviderError)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('allows re-registration when { replace: true } is passed', () => {
|
|
30
|
+
registerAnthropic()
|
|
31
|
+
expect(() => registerAnthropic({ replace: true })).not.toThrow()
|
|
32
|
+
expect(ProviderRegistry.isSupported('anthropic')).toBe(true)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('exposes capabilities through the registry after registration', () => {
|
|
36
|
+
registerAnthropic()
|
|
37
|
+
const caps = ProviderRegistry.getCapabilities('anthropic')
|
|
38
|
+
expect(caps).toEqual(ANTHROPIC_CAPABILITIES)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('ANTHROPIC_CAPABILITIES', () => {
|
|
43
|
+
it('declares the expected capability flags', () => {
|
|
44
|
+
expect(ANTHROPIC_CAPABILITIES).toEqual({
|
|
45
|
+
supportsTools: true,
|
|
46
|
+
supportsStreaming: true,
|
|
47
|
+
supportsFunctionCalling: true,
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('AnthropicProvider', () => {
|
|
53
|
+
it('constructs with an apiKey and exposes provider identity', () => {
|
|
54
|
+
const provider = new AnthropicProvider({ apiKey: 'test-key' })
|
|
55
|
+
expect(provider.id).toBe('anthropic')
|
|
56
|
+
expect(provider.name).toBe('Anthropic')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('throws when constructed without an apiKey', () => {
|
|
60
|
+
expect(() => new AnthropicProvider({} as any)).toThrow(/apiKey is required/)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('creates via ProviderRegistry.create with the registered type', () => {
|
|
64
|
+
registerAnthropic()
|
|
65
|
+
const { provider, capabilities } = ProviderRegistry.create({
|
|
66
|
+
type: 'anthropic',
|
|
67
|
+
apiKey: 'test-key',
|
|
68
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
69
|
+
})
|
|
70
|
+
expect(provider.id).toBe('anthropic')
|
|
71
|
+
expect(capabilities).toEqual(ANTHROPIC_CAPABILITIES)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
})
|