@anvia/anthropic 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Indra Zulfi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @anvia/anthropic
2
+
3
+ Anthropic provider adapter for Anvia.
4
+
5
+ Use this package when you want Anvia agents, extractors, or pipelines to run on Claude models through Anthropic's SDK, or through an Anthropic-compatible API endpoint.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pnpm add @anvia/anthropic @anvia/core
11
+ ```
12
+
13
+ In this monorepo, the package is available through the workspace:
14
+
15
+ ```sh
16
+ pnpm --filter @anvia/anthropic build
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import { AgentBuilder } from "@anvia/core";
23
+ import { AnthropicClient } from "@anvia/anthropic";
24
+
25
+ const client = new AnthropicClient({
26
+ apiKey,
27
+ });
28
+
29
+ const model = client.completionModel("claude-sonnet-4-20250514");
30
+
31
+ const agent = new AgentBuilder("assistant", model)
32
+ .instructions("Answer clearly and concisely.")
33
+ .build();
34
+
35
+ const response = await agent.prompt("Summarize Anvia in one sentence.").send();
36
+
37
+ console.log(response.output);
38
+ ```
39
+
40
+ ## Anthropic-Compatible APIs
41
+
42
+ For APIs that expose an Anthropic-compatible surface, pass a custom `baseUrl`:
43
+
44
+ ```ts
45
+ import { AnthropicClient } from "@anvia/anthropic";
46
+
47
+ const client = new AnthropicClient({
48
+ apiKey,
49
+ baseUrl,
50
+ });
51
+
52
+ const model = client.completionModel("provider/model-name");
53
+ ```
54
+
55
+ ## Exports
56
+
57
+ - `AnthropicClient`
58
+ - `AnthropicCompletionModel`
59
+ - `anthropic`
60
+
61
+ ## Development
62
+
63
+ ```sh
64
+ pnpm --filter @anvia/anthropic typecheck
65
+ pnpm --filter @anvia/anthropic test
66
+ pnpm --filter @anvia/anthropic build
67
+ ```
@@ -0,0 +1,34 @@
1
+ import Anthropic$1, { Anthropic } from '@anthropic-ai/sdk';
2
+ import { StreamingCompletionModel, CompletionModelCapabilities, CompletionRequest, CompletionResponse, CompletionStreamEvent } from '@anvia/core/completion';
3
+
4
+ declare class AnthropicCompletionModel implements StreamingCompletionModel {
5
+ private readonly client;
6
+ readonly defaultModel: string;
7
+ readonly provider = "anthropic";
8
+ readonly capabilities: CompletionModelCapabilities;
9
+ constructor(client: Anthropic, defaultModel?: string);
10
+ completion(request: CompletionRequest): Promise<CompletionResponse>;
11
+ streamCompletion(request: CompletionRequest): AsyncIterable<CompletionStreamEvent>;
12
+ }
13
+
14
+ type AnthropicClientOptions = {
15
+ apiKey?: string | undefined;
16
+ baseUrl?: string | undefined;
17
+ client?: Anthropic$1 | undefined;
18
+ };
19
+ declare class AnthropicClient {
20
+ readonly client: Anthropic$1;
21
+ constructor(options?: AnthropicClientOptions);
22
+ completionModel(model?: string): AnthropicCompletionModel;
23
+ }
24
+
25
+ type index_AnthropicClient = AnthropicClient;
26
+ declare const index_AnthropicClient: typeof AnthropicClient;
27
+ type index_AnthropicClientOptions = AnthropicClientOptions;
28
+ type index_AnthropicCompletionModel = AnthropicCompletionModel;
29
+ declare const index_AnthropicCompletionModel: typeof AnthropicCompletionModel;
30
+ declare namespace index {
31
+ export { index_AnthropicClient as AnthropicClient, type index_AnthropicClientOptions as AnthropicClientOptions, index_AnthropicCompletionModel as AnthropicCompletionModel };
32
+ }
33
+
34
+ export { AnthropicClient, type AnthropicClientOptions, AnthropicCompletionModel, index as anthropic };
package/dist/index.js ADDED
@@ -0,0 +1,440 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/anthropic/index.ts
8
+ var anthropic_exports = {};
9
+ __export(anthropic_exports, {
10
+ AnthropicClient: () => AnthropicClient,
11
+ AnthropicCompletionModel: () => AnthropicCompletionModel
12
+ });
13
+
14
+ // src/anthropic/client.ts
15
+ import Anthropic from "@anthropic-ai/sdk";
16
+
17
+ // src/anthropic/completion.ts
18
+ import {
19
+ AssistantContent,
20
+ assertCompletionRequestSupported,
21
+ Usage
22
+ } from "@anvia/core/completion";
23
+
24
+ // src/request-messages.ts
25
+ import {
26
+ Message,
27
+ normalizeDocuments
28
+ } from "@anvia/core/completion";
29
+ function orderedRequestMessages(request, options = {}) {
30
+ const messages = [];
31
+ if (options.includeInstructionsAsSystem === true && request.instructions !== void 0) {
32
+ messages.push(Message.system(request.instructions));
33
+ }
34
+ messages.push(...request.chatHistory.filter((message) => message.role === "system"));
35
+ const documents = normalizeDocuments(request.documents);
36
+ if (documents !== void 0) {
37
+ messages.push(documents);
38
+ }
39
+ messages.push(...request.chatHistory.filter((message) => message.role !== "system"));
40
+ return messages;
41
+ }
42
+
43
+ // src/utils.ts
44
+ function isPlainObject(value) {
45
+ return typeof value === "object" && value !== null && !Array.isArray(value);
46
+ }
47
+ function numberFrom(value) {
48
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
49
+ }
50
+ function stringFrom(value) {
51
+ return typeof value === "string" ? value : void 0;
52
+ }
53
+
54
+ // src/anthropic/completion.ts
55
+ var DEFAULT_MAX_TOKENS = 1024;
56
+ var AnthropicCompletionModel = class {
57
+ constructor(client, defaultModel = "claude-sonnet-4-20250514") {
58
+ this.client = client;
59
+ this.defaultModel = defaultModel;
60
+ }
61
+ client;
62
+ defaultModel;
63
+ provider = "anthropic";
64
+ capabilities = {
65
+ streaming: true,
66
+ tools: true,
67
+ toolChoice: true,
68
+ imageInput: true,
69
+ documentInput: true,
70
+ outputSchema: false,
71
+ reasoning: true
72
+ };
73
+ async completion(request) {
74
+ assertCompletionRequestSupported(this, request);
75
+ const params = toAnthropicMessagesParams(this.defaultModel, request);
76
+ const response = await this.client.messages.create(params);
77
+ return fromAnthropicMessage(response);
78
+ }
79
+ async *streamCompletion(request) {
80
+ assertCompletionRequestSupported(this, request, { streaming: true });
81
+ const params = { ...toAnthropicMessagesParams(this.defaultModel, request), stream: true };
82
+ const stream = await this.client.messages.create(params);
83
+ const toolIdsByIndex = /* @__PURE__ */ new Map();
84
+ for await (const event of stream) {
85
+ if (isPlainObject(event) && event.type === "content_block_start") {
86
+ const index = numberFrom(event.index);
87
+ const block = isPlainObject(event.content_block) ? event.content_block : {};
88
+ const id = stringFrom(block.id);
89
+ if (id !== void 0) {
90
+ toolIdsByIndex.set(index, id);
91
+ }
92
+ }
93
+ for (const mapped of fromAnthropicStreamEvent(event)) {
94
+ if (mapped.type === "tool_call_delta" && mapped.id.startsWith("tool_")) {
95
+ const index = Number(mapped.id.slice("tool_".length));
96
+ yield { ...mapped, id: toolIdsByIndex.get(index) ?? mapped.id };
97
+ } else {
98
+ yield mapped;
99
+ }
100
+ }
101
+ }
102
+ }
103
+ };
104
+ function toAnthropicMessagesParams(defaultModel, request) {
105
+ const messages = requestMessages(request);
106
+ const system = systemFromMessages(request, messages);
107
+ const params = {
108
+ model: request.model ?? defaultModel,
109
+ max_tokens: request.maxTokens ?? DEFAULT_MAX_TOKENS,
110
+ messages: messages.flatMap(messageToAnthropicMessages)
111
+ };
112
+ if (system !== void 0) {
113
+ params.system = system;
114
+ }
115
+ if (request.tools.length > 0) {
116
+ params.tools = request.tools.map(toolDefinitionToAnthropic);
117
+ }
118
+ if (request.temperature !== void 0) {
119
+ params.temperature = request.temperature;
120
+ }
121
+ if (request.toolChoice !== void 0) {
122
+ params.tool_choice = toolChoiceToAnthropic(request.toolChoice);
123
+ }
124
+ if (request.additionalParams !== void 0 && isPlainObject(request.additionalParams)) {
125
+ Object.assign(params, request.additionalParams);
126
+ }
127
+ return params;
128
+ }
129
+ function requestMessages(request) {
130
+ return orderedRequestMessages(request);
131
+ }
132
+ function systemFromMessages(request, messages) {
133
+ const systemMessages = messages.flatMap(
134
+ (message) => message.role === "system" ? [message.content] : []
135
+ );
136
+ if (request.instructions !== void 0) {
137
+ systemMessages.unshift(request.instructions);
138
+ }
139
+ return systemMessages.length === 0 ? void 0 : systemMessages.join("\n\n");
140
+ }
141
+ function fromAnthropicMessage(response) {
142
+ const raw = response;
143
+ const content = Array.isArray(raw.content) ? raw.content : [];
144
+ const choice = [];
145
+ for (const block of content) {
146
+ if (!isPlainObject(block)) {
147
+ continue;
148
+ }
149
+ if (block.type === "text" && typeof block.text === "string") {
150
+ choice.push(AssistantContent.text(block.text));
151
+ }
152
+ if (block.type === "thinking" && typeof block.thinking === "string") {
153
+ const text = typeof block.signature === "string" ? { type: "text", text: block.thinking, signature: block.signature } : { type: "text", text: block.thinking };
154
+ choice.push(AssistantContent.reasoningFromContent([text]));
155
+ }
156
+ if (block.type === "redacted_thinking" && typeof block.data === "string") {
157
+ choice.push(AssistantContent.reasoningRedacted(block.data));
158
+ }
159
+ if (block.type === "tool_use") {
160
+ const id = typeof block.id === "string" ? block.id : crypto.randomUUID();
161
+ const name = typeof block.name === "string" ? block.name : "";
162
+ choice.push(AssistantContent.toolCall(id, name, toJsonValue(block.input)));
163
+ }
164
+ }
165
+ const usageSource = isPlainObject(raw.usage) ? raw.usage : {};
166
+ const result = {
167
+ choice,
168
+ usage: {
169
+ ...Usage.empty(),
170
+ inputTokens: numberFrom(usageSource.input_tokens),
171
+ outputTokens: numberFrom(usageSource.output_tokens),
172
+ totalTokens: numberFrom(usageSource.input_tokens) + numberFrom(usageSource.output_tokens),
173
+ cachedInputTokens: numberFrom(usageSource.cache_read_input_tokens),
174
+ cacheCreationInputTokens: numberFrom(usageSource.cache_creation_input_tokens)
175
+ },
176
+ rawResponse: response
177
+ };
178
+ if (typeof raw.id === "string") {
179
+ result.messageId = raw.id;
180
+ }
181
+ return result;
182
+ }
183
+ function fromAnthropicStreamEvent(event) {
184
+ if (!isPlainObject(event) || typeof event.type !== "string") {
185
+ return [];
186
+ }
187
+ if (event.type === "message_start" && isPlainObject(event.message)) {
188
+ const id = stringFrom(event.message.id);
189
+ return id === void 0 ? [] : [{ type: "message_id", id }];
190
+ }
191
+ if (event.type === "content_block_start" && isPlainObject(event.content_block)) {
192
+ const block = event.content_block;
193
+ if (block.type === "tool_use") {
194
+ return [
195
+ toolCallDelta(stringFrom(block.id) ?? `tool_${numberFrom(event.index)}`, {
196
+ name: stringFrom(block.name)
197
+ })
198
+ ];
199
+ }
200
+ if (block.type === "redacted_thinking" && typeof block.data === "string") {
201
+ return [
202
+ {
203
+ type: "reasoning_delta",
204
+ delta: block.data,
205
+ id: `thinking_${numberFrom(event.index)}`,
206
+ contentType: "redacted"
207
+ }
208
+ ];
209
+ }
210
+ return [];
211
+ }
212
+ if (event.type === "content_block_delta" && isPlainObject(event.delta)) {
213
+ const delta = event.delta;
214
+ if (delta.type === "text_delta" && typeof delta.text === "string") {
215
+ return [{ type: "text_delta", delta: delta.text }];
216
+ }
217
+ if (delta.type === "thinking_delta" && typeof delta.thinking === "string") {
218
+ return [
219
+ {
220
+ type: "reasoning_delta",
221
+ delta: delta.thinking,
222
+ id: `thinking_${numberFrom(event.index)}`,
223
+ contentType: "text"
224
+ }
225
+ ];
226
+ }
227
+ if (delta.type === "signature_delta" && typeof delta.signature === "string") {
228
+ return [
229
+ {
230
+ type: "reasoning_delta",
231
+ delta: "",
232
+ id: `thinking_${numberFrom(event.index)}`,
233
+ contentType: "text",
234
+ signature: delta.signature
235
+ }
236
+ ];
237
+ }
238
+ if (delta.type === "input_json_delta" && typeof delta.partial_json === "string") {
239
+ return [
240
+ toolCallDelta(`tool_${numberFrom(event.index)}`, { argumentsDelta: delta.partial_json })
241
+ ];
242
+ }
243
+ }
244
+ if (event.type === "message_stop" && isPlainObject(event.message)) {
245
+ return [{ type: "final", response: fromAnthropicMessage(event.message) }];
246
+ }
247
+ if (event.type === "error") {
248
+ return [{ type: "error", error: event.error ?? event }];
249
+ }
250
+ return [];
251
+ }
252
+ function messageToAnthropicMessages(message) {
253
+ if (message.role === "system") {
254
+ return [];
255
+ }
256
+ if (message.role === "user") {
257
+ return [
258
+ {
259
+ role: "user",
260
+ content: message.content.map(userContentToAnthropicBlock)
261
+ }
262
+ ];
263
+ }
264
+ if (message.role === "tool") {
265
+ return [
266
+ {
267
+ role: "user",
268
+ content: message.content.map(toolContentToAnthropicBlock)
269
+ }
270
+ ];
271
+ }
272
+ return [
273
+ {
274
+ role: "assistant",
275
+ content: message.content.flatMap((content) => {
276
+ if (content.type === "text") {
277
+ return [{ type: "text", text: content.text }];
278
+ }
279
+ if (content.type === "tool_call") {
280
+ return [
281
+ {
282
+ type: "tool_use",
283
+ id: content.callId ?? content.id,
284
+ name: content.function.name,
285
+ input: content.function.arguments ?? {}
286
+ }
287
+ ];
288
+ }
289
+ if (content.type === "reasoning" && content.content !== void 0) {
290
+ return content.content.flatMap(reasoningContentToAnthropicBlocks);
291
+ }
292
+ if (content.type === "image") {
293
+ throw new Error("Anthropic Messages does not support image content in assistant history");
294
+ }
295
+ return [];
296
+ })
297
+ }
298
+ ];
299
+ }
300
+ function toolContentToAnthropicBlock(content) {
301
+ return {
302
+ type: "tool_result",
303
+ tool_use_id: content.callId ?? content.id,
304
+ content: content.content.map((item) => item.type === "text" ? item.text : item.data).join("\n")
305
+ };
306
+ }
307
+ function reasoningContentToAnthropicBlocks(content) {
308
+ if (content.type === "text" || content.type === "summary") {
309
+ const block = {
310
+ type: "thinking",
311
+ thinking: content.text
312
+ };
313
+ if (content.type === "text" && content.signature !== void 0) {
314
+ block.signature = content.signature;
315
+ }
316
+ return [block];
317
+ }
318
+ if (content.type === "redacted") {
319
+ return [{ type: "redacted_thinking", data: content.data }];
320
+ }
321
+ return [];
322
+ }
323
+ function userContentToAnthropicBlock(content) {
324
+ if (content.type === "text") {
325
+ return { type: "text", text: content.text };
326
+ }
327
+ if (content.type === "image") {
328
+ return imageToAnthropicBlock(content);
329
+ }
330
+ if (content.type === "document") {
331
+ return documentToAnthropicBlock(content);
332
+ }
333
+ throw new Error("Tool results must be mapped before user content blocks");
334
+ }
335
+ function imageToAnthropicBlock(image) {
336
+ if (image.source.type === "url") {
337
+ return {
338
+ type: "image",
339
+ source: {
340
+ type: "url",
341
+ url: image.source.url
342
+ }
343
+ };
344
+ }
345
+ return {
346
+ type: "image",
347
+ source: {
348
+ type: "base64",
349
+ media_type: image.source.mediaType,
350
+ data: image.source.data
351
+ }
352
+ };
353
+ }
354
+ function documentToAnthropicBlock(document) {
355
+ if (document.source.type === "text") {
356
+ return { type: "text", text: document.source.text };
357
+ }
358
+ if (document.source.mediaType !== "application/pdf") {
359
+ throw new Error("Anthropic Messages only supports PDF document attachments");
360
+ }
361
+ if (document.source.type === "url") {
362
+ return {
363
+ type: "document",
364
+ source: {
365
+ type: "url",
366
+ url: document.source.url
367
+ }
368
+ };
369
+ }
370
+ return {
371
+ type: "document",
372
+ source: {
373
+ type: "base64",
374
+ media_type: document.source.mediaType,
375
+ data: document.source.data
376
+ }
377
+ };
378
+ }
379
+ function toolDefinitionToAnthropic(tool) {
380
+ return {
381
+ name: tool.name,
382
+ description: tool.description,
383
+ input_schema: tool.parameters
384
+ };
385
+ }
386
+ function toolChoiceToAnthropic(toolChoice) {
387
+ if (toolChoice === "auto") {
388
+ return { type: "auto" };
389
+ }
390
+ if (toolChoice === "required") {
391
+ return { type: "any" };
392
+ }
393
+ if (toolChoice === "none") {
394
+ return { type: "none" };
395
+ }
396
+ return {
397
+ type: "tool",
398
+ name: toolChoice.name
399
+ };
400
+ }
401
+ function toJsonValue(value) {
402
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || Array.isArray(value) || isPlainObject(value)) {
403
+ return value;
404
+ }
405
+ return String(value);
406
+ }
407
+ function toolCallDelta(id, values) {
408
+ const event = { type: "tool_call_delta", id };
409
+ if (values.name !== void 0) event.name = values.name;
410
+ if (values.argumentsDelta !== void 0) event.argumentsDelta = values.argumentsDelta;
411
+ return event;
412
+ }
413
+
414
+ // src/anthropic/client.ts
415
+ var AnthropicClient = class {
416
+ client;
417
+ constructor(options = {}) {
418
+ this.client = options.client ?? new Anthropic({
419
+ apiKey: requireApiKey(options.apiKey),
420
+ baseURL: options.baseUrl
421
+ });
422
+ }
423
+ completionModel(model = "claude-sonnet-4-20250514") {
424
+ return new AnthropicCompletionModel(this.client, model);
425
+ }
426
+ };
427
+ function requireApiKey(apiKey) {
428
+ if (apiKey === void 0 || apiKey.length === 0) {
429
+ throw new Error(
430
+ "Missing Anthropic credentials. Pass apiKey when constructing AnthropicClient."
431
+ );
432
+ }
433
+ return apiKey;
434
+ }
435
+ export {
436
+ AnthropicClient,
437
+ AnthropicCompletionModel,
438
+ anthropic_exports as anthropic
439
+ };
440
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/anthropic/index.ts","../src/anthropic/client.ts","../src/anthropic/completion.ts","../src/request-messages.ts","../src/utils.ts"],"sourcesContent":["export { AnthropicClient, type AnthropicClientOptions } from \"./client\";\nexport { AnthropicCompletionModel } from \"./completion\";\n","import Anthropic from \"@anthropic-ai/sdk\";\nimport { AnthropicCompletionModel } from \"./completion\";\n\nexport type AnthropicClientOptions = {\n apiKey?: string | undefined;\n baseUrl?: string | undefined;\n client?: Anthropic | undefined;\n};\n\nexport class AnthropicClient {\n readonly client: Anthropic;\n\n constructor(options: AnthropicClientOptions = {}) {\n this.client =\n options.client ??\n new Anthropic({\n apiKey: requireApiKey(options.apiKey),\n baseURL: options.baseUrl,\n });\n }\n\n completionModel(model = \"claude-sonnet-4-20250514\"): AnthropicCompletionModel {\n return new AnthropicCompletionModel(this.client, model);\n }\n}\n\nfunction requireApiKey(apiKey: string | undefined): string {\n if (apiKey === undefined || apiKey.length === 0) {\n throw new Error(\n \"Missing Anthropic credentials. Pass apiKey when constructing AnthropicClient.\",\n );\n }\n\n return apiKey;\n}\n","import type { Anthropic } from \"@anthropic-ai/sdk\";\nimport {\n AssistantContent,\n type AssistantContent as AssistantContentType,\n assertCompletionRequestSupported,\n type CompletionModelCapabilities,\n type CompletionRequest,\n type CompletionResponse,\n type CompletionStreamEvent,\n type DocumentContent,\n type ImageContent,\n type JsonValue,\n type Message as MessageType,\n type ReasoningContent,\n type StreamingCompletionModel,\n type ToolChoice,\n type ToolContent,\n type ToolDefinition,\n Usage,\n type UserContent,\n} from \"@anvia/core/completion\";\nimport { orderedRequestMessages } from \"../request-messages\";\nimport { isPlainObject, numberFrom, stringFrom } from \"../utils\";\n\ntype AnthropicCreateParams = Record<string, unknown>;\ntype AnthropicMessage = Record<string, unknown>;\ntype AnthropicContentBlock = Record<string, unknown>;\n\nconst DEFAULT_MAX_TOKENS = 1024;\n\nexport class AnthropicCompletionModel implements StreamingCompletionModel {\n readonly provider = \"anthropic\";\n readonly capabilities: CompletionModelCapabilities = {\n streaming: true,\n tools: true,\n toolChoice: true,\n imageInput: true,\n documentInput: true,\n outputSchema: false,\n reasoning: true,\n };\n\n constructor(\n private readonly client: Anthropic,\n readonly defaultModel = \"claude-sonnet-4-20250514\",\n ) {}\n\n async completion(request: CompletionRequest): Promise<CompletionResponse> {\n assertCompletionRequestSupported(this, request);\n const params = toAnthropicMessagesParams(this.defaultModel, request);\n const response = await this.client.messages.create(params as never);\n return fromAnthropicMessage(response);\n }\n\n async *streamCompletion(request: CompletionRequest): AsyncIterable<CompletionStreamEvent> {\n assertCompletionRequestSupported(this, request, { streaming: true });\n const params = { ...toAnthropicMessagesParams(this.defaultModel, request), stream: true };\n const stream = await this.client.messages.create(params as never);\n const toolIdsByIndex = new Map<number, string>();\n for await (const event of stream as unknown as AsyncIterable<unknown>) {\n if (isPlainObject(event) && event.type === \"content_block_start\") {\n const index = numberFrom(event.index);\n const block = isPlainObject(event.content_block) ? event.content_block : {};\n const id = stringFrom(block.id);\n if (id !== undefined) {\n toolIdsByIndex.set(index, id);\n }\n }\n for (const mapped of fromAnthropicStreamEvent(event)) {\n if (mapped.type === \"tool_call_delta\" && mapped.id.startsWith(\"tool_\")) {\n const index = Number(mapped.id.slice(\"tool_\".length));\n yield { ...mapped, id: toolIdsByIndex.get(index) ?? mapped.id };\n } else {\n yield mapped;\n }\n }\n }\n }\n}\n\nexport function toAnthropicMessagesParams(\n defaultModel: string,\n request: CompletionRequest,\n): AnthropicCreateParams {\n const messages = requestMessages(request);\n const system = systemFromMessages(request, messages);\n const params: AnthropicCreateParams = {\n model: request.model ?? defaultModel,\n max_tokens: request.maxTokens ?? DEFAULT_MAX_TOKENS,\n messages: messages.flatMap(messageToAnthropicMessages),\n };\n\n if (system !== undefined) {\n params.system = system;\n }\n\n if (request.tools.length > 0) {\n params.tools = request.tools.map(toolDefinitionToAnthropic);\n }\n\n if (request.temperature !== undefined) {\n params.temperature = request.temperature;\n }\n\n if (request.toolChoice !== undefined) {\n params.tool_choice = toolChoiceToAnthropic(request.toolChoice);\n }\n\n if (request.additionalParams !== undefined && isPlainObject(request.additionalParams)) {\n Object.assign(params, request.additionalParams);\n }\n\n return params;\n}\n\nfunction requestMessages(request: CompletionRequest): MessageType[] {\n return orderedRequestMessages(request);\n}\n\nfunction systemFromMessages(\n request: CompletionRequest,\n messages: MessageType[],\n): string | undefined {\n const systemMessages = messages.flatMap((message) =>\n message.role === \"system\" ? [message.content] : [],\n );\n if (request.instructions !== undefined) {\n systemMessages.unshift(request.instructions);\n }\n return systemMessages.length === 0 ? undefined : systemMessages.join(\"\\n\\n\");\n}\n\nexport function fromAnthropicMessage(response: unknown): CompletionResponse {\n const raw = response as Record<string, unknown>;\n const content = Array.isArray(raw.content) ? raw.content : [];\n const choice: AssistantContentType[] = [];\n\n for (const block of content) {\n if (!isPlainObject(block)) {\n continue;\n }\n\n if (block.type === \"text\" && typeof block.text === \"string\") {\n choice.push(AssistantContent.text(block.text));\n }\n\n if (block.type === \"thinking\" && typeof block.thinking === \"string\") {\n const text: Extract<ReasoningContent, { type: \"text\" }> =\n typeof block.signature === \"string\"\n ? { type: \"text\", text: block.thinking, signature: block.signature }\n : { type: \"text\", text: block.thinking };\n choice.push(AssistantContent.reasoningFromContent([text]));\n }\n\n if (block.type === \"redacted_thinking\" && typeof block.data === \"string\") {\n choice.push(AssistantContent.reasoningRedacted(block.data));\n }\n\n if (block.type === \"tool_use\") {\n const id = typeof block.id === \"string\" ? block.id : crypto.randomUUID();\n const name = typeof block.name === \"string\" ? block.name : \"\";\n choice.push(AssistantContent.toolCall(id, name, toJsonValue(block.input)));\n }\n }\n\n const usageSource = isPlainObject(raw.usage) ? raw.usage : {};\n const result: CompletionResponse = {\n choice,\n usage: {\n ...Usage.empty(),\n inputTokens: numberFrom(usageSource.input_tokens),\n outputTokens: numberFrom(usageSource.output_tokens),\n totalTokens: numberFrom(usageSource.input_tokens) + numberFrom(usageSource.output_tokens),\n cachedInputTokens: numberFrom(usageSource.cache_read_input_tokens),\n cacheCreationInputTokens: numberFrom(usageSource.cache_creation_input_tokens),\n },\n rawResponse: response,\n };\n\n if (typeof raw.id === \"string\") {\n result.messageId = raw.id;\n }\n\n return result;\n}\n\nexport function fromAnthropicStreamEvent(event: unknown): CompletionStreamEvent[] {\n if (!isPlainObject(event) || typeof event.type !== \"string\") {\n return [];\n }\n\n if (event.type === \"message_start\" && isPlainObject(event.message)) {\n const id = stringFrom(event.message.id);\n return id === undefined ? [] : [{ type: \"message_id\", id }];\n }\n\n if (event.type === \"content_block_start\" && isPlainObject(event.content_block)) {\n const block = event.content_block;\n if (block.type === \"tool_use\") {\n return [\n toolCallDelta(stringFrom(block.id) ?? `tool_${numberFrom(event.index)}`, {\n name: stringFrom(block.name),\n }),\n ];\n }\n if (block.type === \"redacted_thinking\" && typeof block.data === \"string\") {\n return [\n {\n type: \"reasoning_delta\",\n delta: block.data,\n id: `thinking_${numberFrom(event.index)}`,\n contentType: \"redacted\",\n },\n ];\n }\n return [];\n }\n\n if (event.type === \"content_block_delta\" && isPlainObject(event.delta)) {\n const delta = event.delta;\n if (delta.type === \"text_delta\" && typeof delta.text === \"string\") {\n return [{ type: \"text_delta\", delta: delta.text }];\n }\n\n if (delta.type === \"thinking_delta\" && typeof delta.thinking === \"string\") {\n return [\n {\n type: \"reasoning_delta\",\n delta: delta.thinking,\n id: `thinking_${numberFrom(event.index)}`,\n contentType: \"text\",\n },\n ];\n }\n\n if (delta.type === \"signature_delta\" && typeof delta.signature === \"string\") {\n return [\n {\n type: \"reasoning_delta\",\n delta: \"\",\n id: `thinking_${numberFrom(event.index)}`,\n contentType: \"text\",\n signature: delta.signature,\n },\n ];\n }\n\n if (delta.type === \"input_json_delta\" && typeof delta.partial_json === \"string\") {\n return [\n toolCallDelta(`tool_${numberFrom(event.index)}`, { argumentsDelta: delta.partial_json }),\n ];\n }\n }\n\n if (event.type === \"message_stop\" && isPlainObject(event.message)) {\n return [{ type: \"final\", response: fromAnthropicMessage(event.message) }];\n }\n\n if (event.type === \"error\") {\n return [{ type: \"error\", error: event.error ?? event }];\n }\n\n return [];\n}\n\nfunction messageToAnthropicMessages(message: MessageType): AnthropicMessage[] {\n if (message.role === \"system\") {\n return [];\n }\n\n if (message.role === \"user\") {\n return [\n {\n role: \"user\",\n content: message.content.map(userContentToAnthropicBlock),\n },\n ];\n }\n\n if (message.role === \"tool\") {\n return [\n {\n role: \"user\",\n content: message.content.map(toolContentToAnthropicBlock),\n },\n ];\n }\n\n return [\n {\n role: \"assistant\",\n content: message.content.flatMap((content): AnthropicContentBlock[] => {\n if (content.type === \"text\") {\n return [{ type: \"text\", text: content.text }];\n }\n\n if (content.type === \"tool_call\") {\n return [\n {\n type: \"tool_use\",\n id: content.callId ?? content.id,\n name: content.function.name,\n input: content.function.arguments ?? {},\n },\n ];\n }\n\n if (content.type === \"reasoning\" && content.content !== undefined) {\n return content.content.flatMap(reasoningContentToAnthropicBlocks);\n }\n\n if (content.type === \"image\") {\n throw new Error(\"Anthropic Messages does not support image content in assistant history\");\n }\n\n return [];\n }),\n },\n ];\n}\n\nfunction toolContentToAnthropicBlock(content: ToolContent): AnthropicContentBlock {\n return {\n type: \"tool_result\",\n tool_use_id: content.callId ?? content.id,\n content: content.content\n .map((item) => (item.type === \"text\" ? item.text : item.data))\n .join(\"\\n\"),\n };\n}\n\nfunction reasoningContentToAnthropicBlocks(content: ReasoningContent): AnthropicContentBlock[] {\n if (content.type === \"text\" || content.type === \"summary\") {\n const block: AnthropicContentBlock = {\n type: \"thinking\",\n thinking: content.text,\n };\n if (content.type === \"text\" && content.signature !== undefined) {\n block.signature = content.signature;\n }\n return [block];\n }\n\n if (content.type === \"redacted\") {\n return [{ type: \"redacted_thinking\", data: content.data }];\n }\n\n return [];\n}\n\nfunction userContentToAnthropicBlock(content: UserContent): AnthropicContentBlock {\n if (content.type === \"text\") {\n return { type: \"text\", text: content.text };\n }\n\n if (content.type === \"image\") {\n return imageToAnthropicBlock(content);\n }\n\n if (content.type === \"document\") {\n return documentToAnthropicBlock(content);\n }\n\n throw new Error(\"Tool results must be mapped before user content blocks\");\n}\n\nfunction imageToAnthropicBlock(image: ImageContent): AnthropicContentBlock {\n if (image.source.type === \"url\") {\n return {\n type: \"image\",\n source: {\n type: \"url\",\n url: image.source.url,\n },\n };\n }\n\n return {\n type: \"image\",\n source: {\n type: \"base64\",\n media_type: image.source.mediaType,\n data: image.source.data,\n },\n };\n}\n\nfunction documentToAnthropicBlock(document: DocumentContent): AnthropicContentBlock {\n if (document.source.type === \"text\") {\n return { type: \"text\", text: document.source.text };\n }\n\n if (document.source.mediaType !== \"application/pdf\") {\n throw new Error(\"Anthropic Messages only supports PDF document attachments\");\n }\n\n if (document.source.type === \"url\") {\n return {\n type: \"document\",\n source: {\n type: \"url\",\n url: document.source.url,\n },\n };\n }\n\n return {\n type: \"document\",\n source: {\n type: \"base64\",\n media_type: document.source.mediaType,\n data: document.source.data,\n },\n };\n}\n\nfunction toolDefinitionToAnthropic(tool: ToolDefinition): AnthropicContentBlock {\n return {\n name: tool.name,\n description: tool.description,\n input_schema: tool.parameters,\n };\n}\n\nfunction toolChoiceToAnthropic(toolChoice: ToolChoice): unknown {\n if (toolChoice === \"auto\") {\n return { type: \"auto\" };\n }\n\n if (toolChoice === \"required\") {\n return { type: \"any\" };\n }\n\n if (toolChoice === \"none\") {\n return { type: \"none\" };\n }\n\n return {\n type: \"tool\",\n name: toolChoice.name,\n };\n}\n\nfunction toJsonValue(value: unknown): JsonValue {\n if (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n Array.isArray(value) ||\n isPlainObject(value)\n ) {\n return value as JsonValue;\n }\n\n return String(value);\n}\n\nfunction toolCallDelta(\n id: string,\n values: { name?: string | undefined; argumentsDelta?: string | undefined },\n): CompletionStreamEvent {\n const event: CompletionStreamEvent = { type: \"tool_call_delta\", id };\n if (values.name !== undefined) event.name = values.name;\n if (values.argumentsDelta !== undefined) event.argumentsDelta = values.argumentsDelta;\n return event;\n}\n\nexport const anthropicMessageHelpers = {\n messageToAnthropicMessages,\n toolDefinitionToAnthropic,\n};\n","import {\n type CompletionRequest,\n Message,\n type Message as MessageType,\n normalizeDocuments,\n} from \"@anvia/core/completion\";\n\nexport type OrderedRequestMessagesOptions = {\n includeInstructionsAsSystem?: boolean;\n};\n\nexport function orderedRequestMessages(\n request: CompletionRequest,\n options: OrderedRequestMessagesOptions = {},\n): MessageType[] {\n const messages: MessageType[] = [];\n if (options.includeInstructionsAsSystem === true && request.instructions !== undefined) {\n messages.push(Message.system(request.instructions));\n }\n messages.push(...request.chatHistory.filter((message) => message.role === \"system\"));\n const documents = normalizeDocuments(request.documents);\n if (documents !== undefined) {\n messages.push(documents);\n }\n messages.push(...request.chatHistory.filter((message) => message.role !== \"system\"));\n return messages;\n}\n","import type { JsonObject, JsonValue } from \"@anvia/core/completion\";\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport function numberFrom(value: unknown): number {\n return typeof value === \"number\" && Number.isFinite(value) ? value : 0;\n}\n\nexport function stringFrom(value: unknown): string | undefined {\n return typeof value === \"string\" ? value : undefined;\n}\n\nexport function parseJsonValue(text: string): JsonValue {\n try {\n return JSON.parse(text) as JsonValue;\n } catch {\n return text;\n }\n}\n\nexport function schemaName(schema: JsonObject): string {\n return typeof schema.title === \"string\" ? schema.title : \"response_schema\";\n}\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,OAAO,eAAe;;;ACCtB;AAAA,EACE;AAAA,EAEA;AAAA,EAcA;AAAA,OAEK;;;ACpBP;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AAMA,SAAS,uBACd,SACA,UAAyC,CAAC,GAC3B;AACf,QAAM,WAA0B,CAAC;AACjC,MAAI,QAAQ,gCAAgC,QAAQ,QAAQ,iBAAiB,QAAW;AACtF,aAAS,KAAK,QAAQ,OAAO,QAAQ,YAAY,CAAC;AAAA,EACpD;AACA,WAAS,KAAK,GAAG,QAAQ,YAAY,OAAO,CAAC,YAAY,QAAQ,SAAS,QAAQ,CAAC;AACnF,QAAM,YAAY,mBAAmB,QAAQ,SAAS;AACtD,MAAI,cAAc,QAAW;AAC3B,aA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AM,iBAAiB,OAAO;AACvE,SAAO;AACT;;;ADzcO,IAAM,kBAAN,MAAsB;AAAA,EAClB;AAAA,EAET,YAAY,UAAkC,CAAC,GAAG;AAChD,SAAK,SACH,QAAQ,UACR,IAAI,UAAU;AAAA,MACZ,QAAQ,cAAc,QAAQ,MAAM;AAAA,MACpC,SAAS,QAAQ;AAAA,IACnB,CAAC;AAAA,EACL;AAAA,EAEA,gBAAgB,QAAQ,4BAAsD;AAC5E,WAAO,IAAI,yBAAyB,KAAK,QAAQ,KAAK;AAAA,EACxD;AACF;AAEA,SAAS,cAAc,QAAoC;AACzD,MAAI,WAAW,UAAa,OAAO,WAAW,GAAG;AAC/C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@anvia/anthropic",
3
+ "version": "0.1.0",
4
+ "description": "Anthropic provider adapter for Anvia.",
5
+ "author": "anvia",
6
+ "maintainer": "Indra Zulfi",
7
+ "license": "MIT",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "dependencies": {
21
+ "@anthropic-ai/sdk": "^0.92.0",
22
+ "@anvia/core": "0.1.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^24.9.1",
26
+ "tsup": "^8.5.0",
27
+ "typescript": "^5.9.3",
28
+ "vitest": "^4.0.8"
29
+ },
30
+ "scripts": {
31
+ "build": "tsup src/index.ts --format esm --dts --sourcemap --clean",
32
+ "test": "vitest run",
33
+ "typecheck": "tsc --noEmit"
34
+ }
35
+ }