@alvin0/ai-agent-sdk-protocol-anthropic-messages 0.1.0 → 0.1.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/dist/index.d.ts +26 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -48,6 +48,23 @@ type WireImageSource = {
|
|
|
48
48
|
type: 'url';
|
|
49
49
|
url: string;
|
|
50
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Document bytes as the Messages API accepts them.
|
|
53
|
+
*
|
|
54
|
+
* Unlike {@link WireImageSource}, this one DOES accept a Files API id, which is
|
|
55
|
+
* the recommended path for a PDF large enough to strain the 32 MB request cap.
|
|
56
|
+
*/
|
|
57
|
+
type WireDocumentSource = {
|
|
58
|
+
type: 'base64';
|
|
59
|
+
media_type: string;
|
|
60
|
+
data: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'url';
|
|
63
|
+
url: string;
|
|
64
|
+
} | {
|
|
65
|
+
type: 'file';
|
|
66
|
+
file_id: string;
|
|
67
|
+
};
|
|
51
68
|
/** A request-side content block. */
|
|
52
69
|
type WireRequestBlock = {
|
|
53
70
|
type: 'text';
|
|
@@ -56,6 +73,14 @@ type WireRequestBlock = {
|
|
|
56
73
|
} | {
|
|
57
74
|
type: 'image';
|
|
58
75
|
source: WireImageSource;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'document';
|
|
78
|
+
source: WireDocumentSource;
|
|
79
|
+
title?: string;
|
|
80
|
+
context?: string;
|
|
81
|
+
citations?: {
|
|
82
|
+
enabled: boolean;
|
|
83
|
+
};
|
|
59
84
|
} | {
|
|
60
85
|
type: 'tool_use';
|
|
61
86
|
id: string;
|
|
@@ -361,5 +386,5 @@ declare const anthropicMessagesProtocol: ProtocolDefinition<AnthropicDialect> &
|
|
|
361
386
|
*/
|
|
362
387
|
declare function translateAnthropicStream(events: AsyncIterable<ProtocolSseEvent>, displayName: string): AsyncGenerator<ProtocolStreamChunk>;
|
|
363
388
|
//#endregion
|
|
364
|
-
export { ANTHROPIC_MESSAGES_PROTOCOL_ID, ANTHROPIC_VERSION, type AnthropicDialect, type AnthropicMessagesProtocolDefinition, type AnthropicReasoningState, type AnthropicSerializeOptions, DEFAULT_THINKING_BUDGETS, type ProtocolDefinition, type ProtocolRequest, type ProtocolSseEvent, type ProtocolStreamChunk, type ThinkingBudgets, type WireCitation, type WireDelta, type WireErrorBody, type WireErrorResponse, type WireFunctionTool, type WireImageSource, type WireMessage, type WireOutputConfig, type WireRequest, type WireRequestBlock, type WireResponseBlock, type WireServerToolUseBlock, type WireStopReason, type WireStreamEvent, type WireThinking, type WireTool, type WireToolChoice, type WireToolResultContent, type WireUsage, type WireWebSearchTool, type WireWebSearchToolResultBlock, anthropicMessagesProtocol, serializeAnthropicRequest, translateAnthropicStream };
|
|
389
|
+
export { ANTHROPIC_MESSAGES_PROTOCOL_ID, ANTHROPIC_VERSION, type AnthropicDialect, type AnthropicMessagesProtocolDefinition, type AnthropicReasoningState, type AnthropicSerializeOptions, DEFAULT_THINKING_BUDGETS, type ProtocolDefinition, type ProtocolRequest, type ProtocolSseEvent, type ProtocolStreamChunk, type ThinkingBudgets, type WireCitation, type WireDelta, type WireDocumentSource, type WireErrorBody, type WireErrorResponse, type WireFunctionTool, type WireImageSource, type WireMessage, type WireOutputConfig, type WireRequest, type WireRequestBlock, type WireResponseBlock, type WireServerToolUseBlock, type WireStopReason, type WireStreamEvent, type WireThinking, type WireTool, type WireToolChoice, type WireToolResultContent, type WireUsage, type WireWebSearchTool, type WireWebSearchToolResultBlock, anthropicMessagesProtocol, serializeAnthropicRequest, translateAnthropicStream };
|
|
365
390
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/contract.ts","../src/wire.ts","../src/serialize.ts","../src/protocol.ts","../src/translate.ts"],"mappings":";;;;UAGiB;WACN,SAAS;WACT;;;UAIM;WACN;WACA;;;KAIC,sBACR,QAAQ;WAAwB;;WACrB;WAAwB,OAAO;;;UAG7B,mBAAmB;WACzB;WACA,gBAAgB;EACzB,aAAa,SAAS,iBAAiB,SAAS;EAChD,iBAAiB,SAAS,UAAU;EACpC,UAAU,SAAS,iBAAiB,SAAS,oBAAoB;EACjE,UACE,QAAQ,cAAc,mBACtB,SAAS,iBACT,sBACC,eAAe;;;;;;;;;;;;;;;KClBR;EACN;EAAgB;EAAoB;;EACpC;EAAa;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/contract.ts","../src/wire.ts","../src/serialize.ts","../src/protocol.ts","../src/translate.ts"],"mappings":";;;;UAGiB;WACN,SAAS;WACT;;;UAIM;WACN;WACA;;;KAIC,sBACR,QAAQ;WAAwB;;WACrB;WAAwB,OAAO;;;UAG7B,mBAAmB;WACzB;WACA,gBAAgB;EACzB,aAAa,SAAS,iBAAiB,SAAS;EAChD,iBAAiB,SAAS,UAAU;EACpC,UAAU,SAAS,iBAAiB,SAAS,oBAAoB;EACjE,UACE,QAAQ,cAAc,mBACtB,SAAS,iBACT,sBACC,eAAe;;;;;;;;;;;;;;;KClBR;EACN;EAAgB;EAAoB;;EACpC;EAAa;;;;;;;;KAQP;EACN;EAAgB;EAAoB;;EACpC;EAAa;;EACb;EAAc;;;KAGR;EACN;EAAc;EAAc,YAAY;;EACxC;EAAe,QAAQ;;EAEzB;EACA,QAAQ;EACR;EACA;EACA;IAAc;;;EAEZ;EAAkB;EAAY;EAAc;;EAE9C;EACA;EACA,SAAS;EACT;;;;;;;EAME;EAAkB;EAAkB;;EACpC;EAA2B;IAC7B,yBACA;UAEa;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;;UAGe;EACf;GACC;;;KAIS;EACN;EAAc;;EACd;EAAe,QAAQ;;;UAGZ;EACf;EAC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AQ,cAAc,mBACtB,SAAS,wBACT,wBACG,eAAe;;;cAIT,2BAA2B,mBAAmB,oBACvD;;;;;;;;;;;;;iBC8HmB,yBACrB,QAAQ,cAAc,mBACtB,sBACC,eAAe"}
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,27 @@ function imageSource(source) {
|
|
|
39
39
|
};
|
|
40
40
|
throw new ModelError("Anthropic image inputs support URL or base64 sources, not file ids", MODEL_ERROR_CODES.INVALID_REQUEST);
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Map a document source onto this API's tagged source object.
|
|
44
|
+
*
|
|
45
|
+
* All three variants are supported here, including the file id that
|
|
46
|
+
* {@link imageSource} has to reject.
|
|
47
|
+
*/
|
|
48
|
+
function documentSource(source) {
|
|
49
|
+
if (source.kind === "url") return {
|
|
50
|
+
type: "url",
|
|
51
|
+
url: source.url
|
|
52
|
+
};
|
|
53
|
+
if (source.kind === "file") return {
|
|
54
|
+
type: "file",
|
|
55
|
+
file_id: source.fileId
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
type: "base64",
|
|
59
|
+
media_type: source.mediaType,
|
|
60
|
+
data: source.data
|
|
61
|
+
};
|
|
62
|
+
}
|
|
42
63
|
/** Restrict tool-result content to the block types this API accepts there. */
|
|
43
64
|
function toolResultContent(blocks) {
|
|
44
65
|
const parts = [];
|
|
@@ -112,6 +133,16 @@ function requestBlocks(block) {
|
|
|
112
133
|
type: "image",
|
|
113
134
|
source: imageSource(block.source)
|
|
114
135
|
}];
|
|
136
|
+
case "document": {
|
|
137
|
+
const title = block.title ?? block.filename;
|
|
138
|
+
return [{
|
|
139
|
+
type: "document",
|
|
140
|
+
source: documentSource(block.source),
|
|
141
|
+
...title === void 0 ? {} : { title },
|
|
142
|
+
...block.context === void 0 ? {} : { context: block.context },
|
|
143
|
+
...block.citations === void 0 ? {} : { citations: { enabled: block.citations } }
|
|
144
|
+
}];
|
|
145
|
+
}
|
|
115
146
|
case "tool-call": return [{
|
|
116
147
|
type: "tool_use",
|
|
117
148
|
id: block.id,
|
|
@@ -272,7 +303,8 @@ function serializeAnthropicRequest(request, options) {
|
|
|
272
303
|
* blocks contiguously from zero in emission order, which is already exactly
|
|
273
304
|
* what our protocol wants, so no remapping is needed.
|
|
274
305
|
* - Usage arrives in TWO places: input counts on `message_start`, output counts on
|
|
275
|
-
* `message_delta`.
|
|
306
|
+
* `message_delta`. Cumulative snapshots are emitted as usage-progress; the
|
|
307
|
+
* final usage is emitted once at message_stop, before the finish.
|
|
276
308
|
* - `input_tokens` here already EXCLUDES cached tokens, so unlike the Responses
|
|
277
309
|
* translation nothing is subtracted. Getting this backwards would under-report
|
|
278
310
|
* input on every cached call.
|
|
@@ -434,9 +466,15 @@ async function* translateAnthropicStream(events, displayName) {
|
|
|
434
466
|
throw new ModelError(`${displayName} sent a malformed stream event`, MODEL_ERROR_CODES.MALFORMED_RESPONSE, { cause: error });
|
|
435
467
|
}
|
|
436
468
|
switch (event.type) {
|
|
437
|
-
case "message_start":
|
|
469
|
+
case "message_start": {
|
|
438
470
|
absorbUsage(usage, event.message.usage);
|
|
471
|
+
const progress = finalUsage(usage);
|
|
472
|
+
if (progress !== void 0) yield {
|
|
473
|
+
type: "usage-progress",
|
|
474
|
+
usage: progress
|
|
475
|
+
};
|
|
439
476
|
break;
|
|
477
|
+
}
|
|
440
478
|
case "content_block_start": {
|
|
441
479
|
if (event.content_block.type === "web_search_tool_result") {
|
|
442
480
|
const result = event.content_block;
|
|
@@ -541,10 +579,16 @@ async function* translateAnthropicStream(events, displayName) {
|
|
|
541
579
|
}
|
|
542
580
|
break;
|
|
543
581
|
}
|
|
544
|
-
case "message_delta":
|
|
582
|
+
case "message_delta": {
|
|
545
583
|
stop = event.delta.stop_reason;
|
|
546
584
|
absorbUsage(usage, event.usage);
|
|
585
|
+
const progress = finalUsage(usage);
|
|
586
|
+
if (progress !== void 0) yield {
|
|
587
|
+
type: "usage-progress",
|
|
588
|
+
usage: progress
|
|
589
|
+
};
|
|
547
590
|
break;
|
|
591
|
+
}
|
|
548
592
|
case "message_stop": {
|
|
549
593
|
for (const [index, entry] of open) {
|
|
550
594
|
if (entry.kind !== "native-tool-call" || entry.closed) continue;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/serialize.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["/**\n * Normalized request to Anthropic Messages API wire JSON.\n *\n * Two things here differ sharply from the Responses API and are easy to get wrong:\n *\n * 1. `tool_use.input` is a parsed OBJECT, not a JSON string. Our normalized block\n * keeps the raw string the model produced, so it is parsed on the way out.\n * 2. Consecutive same-role messages are MERGED. This is not cosmetic tidying —\n * when a model makes three parallel tool calls, we produce three separate\n * tool-result messages, and this API expects all three `tool_result` blocks in\n * ONE user message. Without merging, parallel tool use breaks.\n *\n * @module ai-agent-sdk/providers/anthropic/serialize\n */\n\nimport {\n isNativeToolSchema,\n type ModelOutputFormat,\n type ModelToolSchema,\n type NativeWebSearchTool,\n type ToolChoice,\n type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ContentBlock, ImageSource } from '@alvin0/ai-agent-sdk-core'\nimport type { Message } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type {\n WireImageSource,\n WireCitation,\n WireMessage,\n WireOutputConfig,\n WireRequest,\n WireRequestBlock,\n WireThinking,\n WireTool,\n WireToolChoice,\n WireToolResultContent,\n} from './wire.ts'\n\n/**\n * Adapter-private state kept on a {@link ReasoningBlock} so a thinking block can\n * be echoed back exactly.\n *\n * The signature is the load-bearing part: this API verifies it to confirm the\n * block is genuinely the model's own reasoning, and a thinking block sent back\n * without it is rejected.\n */\nexport interface AnthropicReasoningState {\n /** `thinking` for an ordinary block, `redacted_thinking` for an opaque one. */\n kind: 'thinking' | 'redacted_thinking'\n /** Cryptographic signature over the thinking content. */\n signature?: string\n /** Opaque payload of a redacted block. */\n data?: string\n}\n\n/** Read reasoning state back off a block, tolerating anything unexpected. */\nfunction reasoningStateOf(value: unknown): AnthropicReasoningState | undefined {\n if (typeof value !== 'object' || value === null) return undefined\n const state = value as AnthropicReasoningState\n if (state.kind !== 'thinking' && state.kind !== 'redacted_thinking') return undefined\n return {\n kind: state.kind,\n ...typeof state.signature === 'string' ? { signature: state.signature } : {},\n ...typeof state.data === 'string' ? { data: state.data } : {},\n }\n}\n\n/** Map an image source onto this API's tagged source object. */\nfunction imageSource(source: ImageSource): WireImageSource {\n if (source.kind === 'url') return { type: 'url', url: source.url }\n if (source.kind === 'base64') {\n return { type: 'base64', media_type: source.mediaType, data: source.data }\n }\n throw new ModelError(\n 'Anthropic image inputs support URL or base64 sources, not file ids',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n}\n\n/** Restrict tool-result content to the block types this API accepts there. */\nfunction toolResultContent(blocks: readonly ContentBlock[]): WireToolResultContent[] | string {\n const parts: WireToolResultContent[] = []\n let textOnly = true\n for (const block of blocks) {\n if (block.type === 'text') parts.push({ type: 'text', text: block.text })\n else if (block.type === 'image') {\n textOnly = false\n parts.push({ type: 'image', source: imageSource(block.source) })\n }\n // Anything else (a nested tool result, an extension block) has no\n // representation inside a tool result and is dropped rather than guessed at.\n }\n if (textOnly) {\n return parts.map(part => (part.type === 'text' ? part.text : '')).join('\\n')\n }\n return parts\n}\n\n/** Parse tool-call arguments into the object this API expects. */\nfunction toolInput(raw: string): unknown {\n if (raw.trim().length === 0) return {}\n try {\n return JSON.parse(raw) as unknown\n } catch {\n // The model emitted invalid JSON. Sending `{}` keeps the conversation\n // well-formed so the tool layer can report the problem back to the model,\n // which is recoverable; failing the request here is not.\n return {}\n }\n}\n\nfunction citationOf(value: unknown): WireCitation | undefined {\n if (typeof value !== 'object' || value === null) return undefined\n const citation = value as Record<string, unknown>\n return typeof citation.type === 'string' ? structuredClone(citation) as WireCitation : undefined\n}\n\nfunction nativeReplayBlocks(value: unknown): WireRequestBlock[] {\n if (typeof value !== 'object' || value === null) return []\n const state = value as Record<string, unknown>\n const values = [state.call, state.result]\n return values.flatMap((candidate): WireRequestBlock[] => {\n if (typeof candidate !== 'object' || candidate === null) return []\n const block = candidate as Record<string, unknown>\n if (block.type === 'server_tool_use'\n && typeof block.id === 'string'\n && typeof block.name === 'string') {\n return [{\n type: 'server_tool_use', id: block.id, name: block.name,\n input: structuredClone(block.input ?? {}),\n }]\n }\n if (block.type === 'web_search_tool_result' && typeof block.tool_use_id === 'string') {\n return [{\n type: 'web_search_tool_result', tool_use_id: block.tool_use_id,\n content: structuredClone(block.content),\n ...block.caller === undefined ? {} : { caller: structuredClone(block.caller) },\n }]\n }\n return []\n })\n}\n\n/** Convert one normalized block to zero or more wire blocks. */\nfunction requestBlocks(block: ContentBlock): WireRequestBlock[] {\n switch (block.type) {\n case 'text': {\n // Whitespace-only text is rejected by this API, so it is dropped.\n if (block.text.trim().length === 0) return []\n const citations = block.annotations?.flatMap((annotation): WireCitation[] => {\n if (annotation.type !== 'url-citation') return []\n const citation = citationOf(annotation.providerState)\n return citation === undefined ? [] : [citation]\n })\n return [{\n type: 'text', text: block.text,\n ...citations === undefined || citations.length === 0 ? {} : { citations },\n }]\n }\n case 'image':\n return [{ type: 'image', source: imageSource(block.source) }]\n case 'tool-call':\n return [{\n type: 'tool_use',\n id: block.id,\n name: block.name,\n input: toolInput(block.arguments),\n }]\n case 'tool-result':\n return [{\n type: 'tool_result',\n tool_use_id: block.toolCallId,\n content: toolResultContent(block.content),\n ...block.isError === true ? { is_error: true } : {},\n }]\n case 'native-tool-call':\n return nativeReplayBlocks(block.providerState)\n case 'reasoning': {\n const state = reasoningStateOf(block.providerState)\n if (state === undefined) {\n // No signature means this cannot be replayed as a thinking block. Dropping\n // it is correct: sending unsigned thinking is rejected outright.\n return []\n }\n if (state.kind === 'redacted_thinking') {\n return state.data === undefined ? [] : [{ type: 'redacted_thinking', data: state.data }]\n }\n return state.signature === undefined\n ? []\n : [{ type: 'thinking', thinking: block.text, signature: state.signature }]\n }\n default:\n return []\n }\n}\n\n/**\n * Build the message list, merging consecutive same-role messages.\n *\n * See the module note for why merging matters.\n */\nfunction messagesOf(messages: readonly Message[]): WireMessage[] {\n const result: WireMessage[] = []\n for (const message of messages) {\n if (message.role === 'system') continue // hoisted to the `system` field\n const role = message.role === 'assistant' ? 'assistant' : 'user'\n const blocks = message.content.flatMap(requestBlocks)\n if (blocks.length === 0) continue\n\n const previous = result.at(-1)\n if (previous !== undefined && previous.role === role) previous.content.push(...blocks)\n else result.push({ role, content: blocks })\n }\n return result\n}\n\n/** Collect the system prompt from the request plus any system-role messages. */\nfunction systemOf(request: ProtocolRequest): string | undefined {\n const fromMessages = request.options.messages\n .filter(message => message.role === 'system')\n .flatMap(message => message.content)\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n const all = request.options.system === undefined\n ? fromMessages\n : [request.options.system, ...fromMessages]\n const joined = all.join('\\n\\n')\n return joined.length === 0 ? undefined : joined\n}\n\n/** Map the neutral tool-choice vocabulary onto this API's. */\nfunction toolChoiceOf(choice: ToolChoice): WireToolChoice {\n if (choice === 'auto') return { type: 'auto' }\n if (choice === 'none') return { type: 'none' }\n // \"call some tool\" is spelled `any` here, not `required`.\n if (choice === 'required') return { type: 'any' }\n return { type: 'tool', name: choice.type === 'native' ? nativeToolName(choice.name) : choice.name }\n}\n\nfunction functionTool(tool: ToolSchema): WireTool {\n return { name: tool.name, description: tool.description, input_schema: tool.parameters }\n}\n\nfunction nativeToolName(name: string): string {\n if (name === 'web-search') return 'web_search'\n return name.replaceAll('-', '_')\n}\n\nfunction webSearchTool(tool: NativeWebSearchTool): WireTool {\n if (tool.allowedDomains !== undefined && tool.blockedDomains !== undefined) {\n throw new ModelError(\n 'Anthropic web search accepts allowedDomains or blockedDomains, not both',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n type: 'web_search_20250305',\n name: 'web_search',\n ...tool.maxUses === undefined ? {} : { max_uses: tool.maxUses },\n ...tool.allowedDomains === undefined ? {} : { allowed_domains: [...tool.allowedDomains] },\n ...tool.blockedDomains === undefined ? {} : { blocked_domains: [...tool.blockedDomains] },\n ...tool.userLocation === undefined ? {} : {\n user_location: { type: 'approximate', ...tool.userLocation },\n },\n }\n}\n\nfunction toolOf(tool: ModelToolSchema): WireTool {\n if (!isNativeToolSchema(tool)) return functionTool(tool)\n if (tool.name === 'web-search') return webSearchTool(tool)\n throw new ModelError(\n `Anthropic does not support the provider-native tool '${tool.name}'`,\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n}\n\n/** How a reasoning effort becomes a thinking token budget. */\nexport type ThinkingBudgets = Readonly<Record<string, number>>\n\n/** Options controlling how the request is built. */\nexport interface AnthropicSerializeOptions {\n /** Effort id to thinking-token budget. An absent or zero budget disables thinking. */\n budgets: ThinkingBudgets\n}\n\n/**\n * Resolve the `thinking` field for this request.\n *\n * The budget must leave room for a real answer, so it is capped below\n * `max_tokens` — this API requires `budget_tokens < max_tokens` and rejects the\n * request otherwise.\n */\nfunction thinkingOf(\n effort: string | undefined,\n maxTokens: number,\n budgets: ThinkingBudgets,\n): WireThinking | undefined {\n if (effort === undefined) return undefined\n const requested = budgets[effort]\n if (requested === undefined || requested <= 0) return { type: 'disabled' }\n // Leave at least a quarter of the budget for the visible answer.\n const capped = Math.min(requested, Math.floor(maxTokens * 0.75))\n // This API's own floor for extended thinking.\n return capped < 1_024 ? { type: 'disabled' } : { type: 'enabled', budget_tokens: capped }\n}\n\nfunction outputConfig(format: ModelOutputFormat | undefined): WireOutputConfig | undefined {\n if (format === undefined || format.type === 'text') return undefined\n return { format: { type: 'json_schema', schema: format.schema } }\n}\n\n/**\n * Build the Messages request body.\n * @param request - the resolved request, model, and connection.\n * @param options - thinking-budget mapping.\n * @returns the wire body, ready to serialize.\n */\nexport function serializeAnthropicRequest(\n request: ProtocolRequest,\n options: AnthropicSerializeOptions,\n): WireRequest {\n const { options: call } = request\n const system = systemOf(request)\n const tools = call.tools === undefined || call.tools.length === 0\n ? undefined\n : call.tools.map(toolOf)\n const thinking = thinkingOf(\n call.reasoningEffort === undefined ? undefined : String(call.reasoningEffort),\n request.maxTokens,\n options.budgets,\n )\n const thinkingEnabled = thinking?.type === 'enabled'\n const output = outputConfig(call.outputFormat)\n\n return {\n model: call.model,\n // Required by this API — unlike most others, omitting it is an error.\n max_tokens: request.maxTokens,\n messages: messagesOf(call.messages),\n ...system === undefined ? {} : { system },\n ...tools === undefined ? {} : { tools },\n ...call.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(call.toolChoice) },\n // Extended thinking is incompatible with sampling adjustments; sending both\n // is rejected, so the sampling knobs are dropped when thinking is on.\n ...!thinkingEnabled && call.temperature !== undefined\n ? { temperature: call.temperature }\n : {},\n ...!thinkingEnabled && call.topP !== undefined ? { top_p: call.topP } : {},\n ...call.stop === undefined || call.stop.length === 0\n ? {}\n : { stop_sequences: [...call.stop] },\n ...thinking === undefined ? {} : { thinking },\n ...output === undefined ? {} : { output_config: output },\n stream: true,\n }\n}\n","/**\n * Anthropic Messages API SSE events to the SDK's chunk protocol.\n *\n * Notable differences from the Responses translation:\n *\n * - Block indices come straight from the provider. This API numbers content\n * blocks contiguously from zero in emission order, which is already exactly\n * what our protocol wants, so no remapping is needed.\n * - Usage arrives in TWO places: input counts on `message_start`, output counts on\n * `message_delta`. They are accumulated and emitted once, before the finish.\n * - `input_tokens` here already EXCLUDES cached tokens, so unlike the Responses\n * translation nothing is subtracted. Getting this backwards would under-report\n * input on every cached call.\n *\n * @module ai-agent-sdk/providers/anthropic/translate\n */\n\nimport {\n CONTEXT_WINDOW_EXCEEDED_CODE,\n MODEL_ERROR_CODES,\n ModelError,\n QUOTA_EXCEEDED_CODE,\n isContextWindowExceededError,\n isQuotaExceededError,\n} from '@alvin0/ai-agent-sdk-core'\nimport { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport { isJsonValue, type JsonValue } from '@alvin0/ai-agent-sdk-core'\nimport type { ContentBlock, TextAnnotation } from '@alvin0/ai-agent-sdk-core'\nimport type { FinishReason, UsageCounters } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type { AnthropicReasoningState } from './serialize.ts'\nimport type {\n WireCitation,\n WireServerToolUseBlock,\n WireStopReason,\n WireStreamEvent,\n WireUsage,\n WireWebSearchToolResultBlock,\n} from './wire.ts'\n\n/** Which of our block types one wire block maps to. */\ntype BlockKind = 'text' | 'reasoning' | 'tool-call' | 'native-tool-call'\n\ninterface OpenBlock {\n readonly kind: BlockKind\n text: string\n args: string\n callId: string\n name: string\n signature: string | undefined\n redactedData: string | undefined\n annotations: TextAnnotation[]\n nativeCall: WireServerToolUseBlock | undefined\n nativeResult: WireWebSearchToolResultBlock | undefined\n closed: boolean\n}\n\nfunction blockKind(type: string | undefined): BlockKind | undefined {\n switch (type) {\n case 'text': return 'text'\n case 'thinking':\n case 'redacted_thinking': return 'reasoning'\n case 'tool_use': return 'tool-call'\n case 'server_tool_use': return 'native-tool-call'\n default: return undefined\n }\n}\n\n/** Accumulated token counts, filled from two different events. */\ninterface UsageAccumulator {\n input: unknown\n output: unknown\n cacheRead: unknown\n cacheWrite: unknown\n seen: boolean\n}\n\nfunction absorbUsage(target: UsageAccumulator, usage: WireUsage | undefined): void {\n if (typeof usage !== 'object' || usage === null) return\n if ('input_tokens' in usage) target.input = usage.input_tokens\n if ('output_tokens' in usage) target.output = usage.output_tokens\n if ('cache_read_input_tokens' in usage && usage.cache_read_input_tokens !== null) {\n target.cacheRead = usage.cache_read_input_tokens\n }\n if ('cache_creation_input_tokens' in usage && usage.cache_creation_input_tokens !== null) {\n target.cacheWrite = usage.cache_creation_input_tokens\n }\n target.seen = true\n}\n\nfunction finalUsage(accumulated: UsageAccumulator): UsageCounters | undefined {\n if (!accumulated.seen) return undefined\n const output: Record<string, unknown> = {\n ...accumulated.input === undefined ? {} : { inputTokens: accumulated.input },\n ...accumulated.output === undefined ? {} : { outputTokens: accumulated.output },\n // Cache omission/null is authoritative zero for this protocol. Invalid\n // present values are retained so the accounting boundary can record them.\n ...accumulated.cacheRead === undefined || accumulated.cacheRead === 0\n ? {} : { cacheReadTokens: accumulated.cacheRead },\n ...accumulated.cacheWrite === undefined || accumulated.cacheWrite === 0\n ? {} : { cacheWriteTokens: accumulated.cacheWrite },\n }\n const counters = [\n accumulated.input,\n accumulated.cacheRead ?? 0,\n accumulated.cacheWrite ?? 0,\n accumulated.output,\n ]\n if (counters.every(validUsageCounter)) {\n output.totalTokens = counters.reduce<number>((total, value) => total + value, 0)\n }\n return output as UsageCounters\n}\n\nfunction validUsageCounter(value: unknown): value is number {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0\n}\n\n/** Map this API's stop reason onto ours. */\nfunction finishReason(stop: WireStopReason | null | undefined): FinishReason {\n switch (stop) {\n case 'tool_use': return { kind: 'tool-calls' }\n case 'max_tokens': return { kind: 'max-tokens' }\n case 'refusal':\n return {\n kind: 'error',\n failure: {\n message: 'the model refused to answer',\n code: MODEL_ERROR_CODES.INVALID_REQUEST,\n },\n }\n // `end_turn`, `stop_sequence`, and `pause_turn` all mean the turn produced a\n // complete answer as far as a caller is concerned.\n default: return { kind: 'stop' }\n }\n}\n\n/** Build the authoritative block for a completed content block. */\nfunction closedBlock(open: OpenBlock): ContentBlock | undefined {\n switch (open.kind) {\n case 'text':\n return {\n type: 'text', text: open.text,\n ...open.annotations.length === 0 ? {} : { annotations: open.annotations },\n }\n case 'reasoning': {\n const state: AnthropicReasoningState = open.redactedData !== undefined\n ? { kind: 'redacted_thinking', data: open.redactedData }\n : {\n kind: 'thinking',\n ...open.signature === undefined ? {} : { signature: open.signature },\n }\n return { type: 'reasoning', text: open.text, providerState: state }\n }\n case 'tool-call':\n return {\n type: 'tool-call',\n id: ToolCallId(open.callId),\n name: open.name,\n arguments: open.args.length > 0 ? open.args : '{}',\n }\n case 'native-tool-call': {\n const parsed = parsedArguments(open.args, open.nativeCall?.input)\n const call: WireServerToolUseBlock = open.nativeCall ?? {\n type: 'server_tool_use', id: open.callId, name: 'web_search', input: parsed,\n }\n return {\n type: 'native-tool-call', id: open.callId,\n name: open.name === 'web_search' ? 'web-search' : open.name.replaceAll('_', '-'),\n arguments: parsed,\n content: [],\n providerState: {\n call: { ...call, input: parsed },\n ...open.nativeResult === undefined ? {} : { result: open.nativeResult },\n },\n }\n }\n default:\n return undefined\n }\n}\n\nfunction parsedArguments(raw: string, fallback?: unknown): JsonValue {\n if (raw.length === 0) return isJsonValue(fallback) ? fallback : {}\n try {\n const value: unknown = JSON.parse(raw)\n return isJsonValue(value) ? value : {}\n } catch {\n return {}\n }\n}\n\nfunction citationAnnotation(citation: WireCitation): TextAnnotation | undefined {\n if (citation.type !== 'web_search_result_location' || typeof citation.url !== 'string') {\n return undefined\n }\n return {\n type: 'url-citation', url: citation.url,\n ...typeof citation.title === 'string' ? { title: citation.title } : {},\n providerState: structuredClone(citation),\n }\n}\n\n/**\n * Translate one Messages SSE stream.\n *\n * Owns termination. There is no `[DONE]` sentinel: the stream ends on\n * `message_stop`, and a body that ends before that was truncated — a failure\n * rather than a short answer.\n * @param events - decoded SSE events.\n * @param displayName - provider name, used in diagnostics.\n * @returns the chunk stream.\n */\nexport async function* translateAnthropicStream(\n events: AsyncIterable<ProtocolSseEvent>,\n displayName: string,\n): AsyncGenerator<ProtocolStreamChunk> {\n const open = new Map<number, OpenBlock>()\n const usage: UsageAccumulator = {\n input: undefined, output: undefined, cacheRead: undefined, cacheWrite: undefined, seen: false,\n }\n let stop: WireStopReason | null | undefined\n let terminated = false\n let emittedBlocks = 0\n\n for await (const raw of events) {\n let event: WireStreamEvent\n try {\n event = JSON.parse(raw.data) as WireStreamEvent\n } catch (error: unknown) {\n throw new ModelError(\n `${displayName} sent a malformed stream event`,\n MODEL_ERROR_CODES.MALFORMED_RESPONSE,\n { cause: error },\n )\n }\n\n switch (event.type) {\n case 'message_start': {\n absorbUsage(usage, event.message.usage)\n break\n }\n\n case 'content_block_start': {\n if (event.content_block.type === 'web_search_tool_result') {\n const result = event.content_block\n const owner = [...open.values()].find(entry => entry.kind === 'native-tool-call'\n && entry.callId === result.tool_use_id)\n if (owner !== undefined) {\n owner.nativeResult = result\n const block = closedBlock(owner)\n if (block !== undefined && !owner.closed) {\n owner.closed = true\n yield {\n type: 'block-end',\n index: [...open.entries()].find(([, entry]) => entry === owner)?.[0] ?? event.index,\n block,\n }\n }\n }\n break\n }\n const kind = blockKind(event.content_block.type)\n if (kind === undefined) break\n const block = event.content_block\n const entry: OpenBlock = {\n kind,\n text: block.type === 'text'\n ? block.text\n : block.type === 'thinking' ? block.thinking : '',\n args: '',\n callId: block.type === 'tool_use' ? block.id : `block-${event.index}`,\n name: block.type === 'tool_use' || block.type === 'server_tool_use' ? block.name : '',\n signature: block.type === 'thinking' ? block.signature : undefined,\n redactedData: block.type === 'redacted_thinking' ? block.data : undefined,\n annotations: [],\n nativeCall: block.type === 'server_tool_use' ? block : undefined,\n nativeResult: undefined,\n closed: false,\n }\n if (block.type === 'server_tool_use') {\n entry.callId = block.id\n entry.args = ''\n }\n open.set(event.index, entry)\n emittedBlocks += 1\n yield { type: 'block-start', index: event.index, blockType: kind }\n break\n }\n\n case 'content_block_delta': {\n const entry = open.get(event.index)\n if (entry === undefined) break\n const delta = event.delta\n switch (delta.type) {\n case 'text_delta':\n entry.text += delta.text\n yield { type: 'text-delta', index: event.index, text: delta.text }\n break\n case 'thinking_delta':\n entry.text += delta.thinking\n yield { type: 'reasoning-delta', index: event.index, text: delta.thinking }\n break\n case 'signature_delta':\n // Arrives once, just before the block closes. It carries no visible\n // content, so it produces no chunk — only the state needed to replay\n // this thinking block on a later request.\n entry.signature = delta.signature\n break\n case 'input_json_delta':\n entry.args += delta.partial_json\n if (entry.kind === 'tool-call') {\n yield {\n type: 'tool-call-delta',\n index: event.index,\n id: ToolCallId(entry.callId),\n ...entry.name.length > 0 ? { name: entry.name } : {},\n argumentsDelta: delta.partial_json,\n }\n }\n break\n case 'citations_delta': {\n const annotation = citationAnnotation(delta.citation)\n if (annotation !== undefined) entry.annotations.push(annotation)\n break\n }\n default:\n break\n }\n break\n }\n\n case 'content_block_stop': {\n const entry = open.get(event.index)\n if (entry === undefined) break\n if (entry.kind === 'native-tool-call') break\n const block = closedBlock(entry)\n if (block !== undefined && !entry.closed) {\n entry.closed = true\n yield { type: 'block-end', index: event.index, block }\n }\n break\n }\n\n case 'message_delta': {\n stop = event.delta.stop_reason\n absorbUsage(usage, event.usage)\n break\n }\n\n case 'message_stop': {\n for (const [index, entry] of open) {\n if (entry.kind !== 'native-tool-call' || entry.closed) continue\n const block = closedBlock(entry)\n if (block !== undefined) yield { type: 'block-end', index, block }\n entry.closed = true\n }\n const mapped = finalUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n if (emittedBlocks === 0) {\n // A clean stop with no content at all. Reported as a failure rather\n // than an empty message, because an empty message ends the turn with\n // nothing for the caller to act on — and it is safe to retry.\n throw new ModelError(\n `${displayName} returned a response with no content`,\n 'EMPTY_RESPONSE',\n )\n }\n yield { type: 'finish', reason: finishReason(stop) }\n terminated = true\n return\n }\n\n case 'error': {\n const detail = [event.error.type, event.error.message]\n .filter((part): part is string => part !== undefined)\n .join(' ')\n throw new ModelError(\n event.error.message ?? `${displayName} reported a stream error`,\n // `overloaded_error` mid-stream is the common case and must stay\n // retryable, which the shared 5xx mapping gives us.\n event.error.type === 'overloaded_error'\n ? MODEL_ERROR_CODES.SERVER\n : anthropicStreamErrorCode(event.error.type, detail),\n )\n }\n\n // `ping` and any future event carry nothing this protocol needs.\n default:\n break\n }\n }\n\n if (!terminated) {\n throw new ModelError(\n `${displayName} stream ended before message_stop`,\n MODEL_ERROR_CODES.STREAM_CLOSED,\n )\n }\n}\n\nfunction anthropicStreamErrorCode(type: string | undefined, detail: string): string {\n if (type === 'authentication_error' || type === 'permission_error') {\n return MODEL_ERROR_CODES.AUTH\n }\n if (isQuotaExceededError(detail)) return QUOTA_EXCEEDED_CODE\n if (type === 'rate_limit_error') return MODEL_ERROR_CODES.RATE_LIMIT\n if (type === 'api_error') return MODEL_ERROR_CODES.SERVER\n if (isContextWindowExceededError(detail)) return CONTEXT_WINDOW_EXCEEDED_CODE\n return MODEL_ERROR_CODES.INVALID_REQUEST\n}\n","/**\n * The Anthropic Messages protocol, as a reusable {@link WireProtocol}.\n *\n * @module ai-agent-sdk/providers/protocols/anthropic-messages\n */\n\nimport type {\n ProtocolDefinition,\n ProtocolRequest,\n ProtocolSseEvent,\n ProtocolStreamChunk,\n} from './contract.ts'\nimport type { ModelTarget, ResolvedModelInfo } from '@alvin0/ai-agent-sdk-core/provider'\nimport { serializeAnthropicRequest, type ThinkingBudgets } from './serialize.ts'\nimport { translateAnthropicStream } from './translate.ts'\n\n/** Protocol id, usable as a stable string in configuration. */\nexport const ANTHROPIC_MESSAGES_PROTOCOL_ID = 'anthropic-messages'\n\n/**\n * The API version header value.\n *\n * Mandatory on every request. Stable across the entire lifetime of this API — new\n * capabilities arrive as opt-in beta headers rather than a version bump — which is\n * why it lives on the protocol instead of being restated by each endpoint.\n */\nexport const ANTHROPIC_VERSION = '2023-06-01'\n\n/**\n * Default reasoning efforts, expressed as thinking-token budgets.\n *\n * Budgets rather than an opaque level because that is what this API takes. The\n * SDK's effort ids are a neutral surface over a provider-specific knob, and\n * mapping them here is the whole reason `ReasoningEffortId` is opaque.\n */\nexport const DEFAULT_THINKING_BUDGETS: ThinkingBudgets = Object.freeze({\n off: 0,\n low: 2_048,\n medium: 8_192,\n high: 24_576,\n})\n\n/** Per-endpoint knobs of the Messages protocol. */\nexport interface AnthropicDialect {\n /** Effort id to thinking-token budget. */\n readonly budgets: ThinkingBudgets\n /** `anthropic-version` header value. */\n readonly version: string\n /** Opt-in beta features, sent as `anthropic-beta`. */\n readonly beta: readonly string[]\n}\n\nconst DEFAULT_DIALECT: AnthropicDialect = Object.freeze({\n budgets: DEFAULT_THINKING_BUDGETS,\n version: ANTHROPIC_VERSION,\n beta: Object.freeze([]),\n})\n\ninterface RuntimeProtocolRequest extends ProtocolRequest {\n readonly model: ResolvedModelInfo\n readonly connection: {\n readonly baseUrl: string\n readonly headers: Readonly<Record<string, string>>\n }\n}\n\n/** Marker-based runtime view, kept structurally independent from provider-http. */\nexport interface AnthropicMessagesProtocolDefinition {\n readonly kind: 'http-wire-protocol'\n readonly apiVersion: 1\n readonly id: string\n readonly defaultDialect: AnthropicDialect\n readonly exampleModel?: ModelTarget\n readonly endpointPath: (request: RuntimeProtocolRequest, dialect: AnthropicDialect) => string\n readonly protocolHeaders?: (dialect: AnthropicDialect) => Readonly<Record<string, string>>\n readonly serialize: (\n request: RuntimeProtocolRequest,\n dialect: AnthropicDialect,\n ) => Readonly<Record<string, unknown>>\n readonly translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: RuntimeProtocolRequest,\n displayName: string,\n ) => AsyncGenerator<ProtocolStreamChunk>\n}\n\n/** The Anthropic Messages wire protocol. */\nexport const anthropicMessagesProtocol: ProtocolDefinition<AnthropicDialect>\n & AnthropicMessagesProtocolDefinition = Object.freeze({\n kind: 'http-wire-protocol' as const,\n apiVersion: 1 as const,\n id: ANTHROPIC_MESSAGES_PROTOCOL_ID,\n defaultDialect: DEFAULT_DIALECT,\n endpointPath: () => '/v1/messages',\n protocolHeaders: (dialect: AnthropicDialect) => ({\n 'anthropic-version': dialect.version,\n ...dialect.beta.length === 0 ? {} : { 'anthropic-beta': dialect.beta.join(',') },\n }),\n serialize(request: ProtocolRequest, dialect: AnthropicDialect): Readonly<Record<string, unknown>> {\n const body: unknown = serializeAnthropicRequest(request, { budgets: dialect.budgets })\n return body as Readonly<Record<string, unknown>>\n },\n // Params are annotated because `Object.freeze` erases the contextual typing the\n // `WireProtocol` annotation would otherwise supply.\n translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n _request: ProtocolRequest,\n displayName: string,\n ): AsyncGenerator<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,OAAO;CACzC,IAAI,SAAS,oBAAoB,OAAO,kBAAkB;CAC1D,IAAI,SAAS,aAAa,OAAO,kBAAkB;CACnD,IAAI,6BAA6B,MAAM,GAAG,OAAO;CACjD,OAAO,kBAAkB;AAC3B;;;;;ACzYA,MAAa,iCAAiC;;;;;;;;AAS9C,MAAa,oBAAoB;;;;;;;;AASjC,MAAa,2BAA4C,OAAO,OAAO;CACrE,KAAK;CACL,KAAK;CACL,QAAQ;CACR,MAAM;AACR,CAAC;AAYD,MAAM,kBAAoC,OAAO,OAAO;CACtD,SAAS;CACT,SAAS;CACT,MAAM,OAAO,OAAO,CAAC,CAAC;AACxB,CAAC;;AA+BD,MAAa,4BAC6B,OAAO,OAAO;CACtD,MAAM;CACN,YAAY;CACZ,IAAI;CACJ,gBAAgB;CAChB,oBAAoB;CACpB,kBAAkB,aAA+B;EAC/C,qBAAqB,QAAQ;EAC7B,GAAG,QAAQ,KAAK,WAAW,IAAI,CAAC,IAAI,EAAE,kBAAkB,QAAQ,KAAK,KAAK,GAAG,EAAE;CACjF;CACA,UAAU,SAA0B,SAA8D;EAEhG,OADsB,0BAA0B,SAAS,EAAE,SAAS,QAAQ,QAAQ,CAC1E;CACZ;CAGA,YACE,QACA,UACA,gBACwC,yBAAyB,QAAQ,WAAW;AACxF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/serialize.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["/**\n * Normalized request to Anthropic Messages API wire JSON.\n *\n * Two things here differ sharply from the Responses API and are easy to get wrong:\n *\n * 1. `tool_use.input` is a parsed OBJECT, not a JSON string. Our normalized block\n * keeps the raw string the model produced, so it is parsed on the way out.\n * 2. Consecutive same-role messages are MERGED. This is not cosmetic tidying —\n * when a model makes three parallel tool calls, we produce three separate\n * tool-result messages, and this API expects all three `tool_result` blocks in\n * ONE user message. Without merging, parallel tool use breaks.\n *\n * @module ai-agent-sdk/providers/anthropic/serialize\n */\n\nimport {\n isNativeToolSchema,\n type ModelOutputFormat,\n type ModelToolSchema,\n type NativeWebSearchTool,\n type ToolChoice,\n type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ContentBlock, DocumentSource, ImageSource } from '@alvin0/ai-agent-sdk-core'\nimport type { Message } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type {\n WireDocumentSource,\n WireImageSource,\n WireCitation,\n WireMessage,\n WireOutputConfig,\n WireRequest,\n WireRequestBlock,\n WireThinking,\n WireTool,\n WireToolChoice,\n WireToolResultContent,\n} from './wire.ts'\n\n/**\n * Adapter-private state kept on a {@link ReasoningBlock} so a thinking block can\n * be echoed back exactly.\n *\n * The signature is the load-bearing part: this API verifies it to confirm the\n * block is genuinely the model's own reasoning, and a thinking block sent back\n * without it is rejected.\n */\nexport interface AnthropicReasoningState {\n /** `thinking` for an ordinary block, `redacted_thinking` for an opaque one. */\n kind: 'thinking' | 'redacted_thinking'\n /** Cryptographic signature over the thinking content. */\n signature?: string\n /** Opaque payload of a redacted block. */\n data?: string\n}\n\n/** Read reasoning state back off a block, tolerating anything unexpected. */\nfunction reasoningStateOf(value: unknown): AnthropicReasoningState | undefined {\n if (typeof value !== 'object' || value === null) return undefined\n const state = value as AnthropicReasoningState\n if (state.kind !== 'thinking' && state.kind !== 'redacted_thinking') return undefined\n return {\n kind: state.kind,\n ...typeof state.signature === 'string' ? { signature: state.signature } : {},\n ...typeof state.data === 'string' ? { data: state.data } : {},\n }\n}\n\n/** Map an image source onto this API's tagged source object. */\nfunction imageSource(source: ImageSource): WireImageSource {\n if (source.kind === 'url') return { type: 'url', url: source.url }\n if (source.kind === 'base64') {\n return { type: 'base64', media_type: source.mediaType, data: source.data }\n }\n throw new ModelError(\n 'Anthropic image inputs support URL or base64 sources, not file ids',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n}\n\n/**\n * Map a document source onto this API's tagged source object.\n *\n * All three variants are supported here, including the file id that\n * {@link imageSource} has to reject.\n */\nfunction documentSource(source: DocumentSource): WireDocumentSource {\n if (source.kind === 'url') return { type: 'url', url: source.url }\n if (source.kind === 'file') return { type: 'file', file_id: source.fileId }\n return { type: 'base64', media_type: source.mediaType, data: source.data }\n}\n\n/** Restrict tool-result content to the block types this API accepts there. */\nfunction toolResultContent(blocks: readonly ContentBlock[]): WireToolResultContent[] | string {\n const parts: WireToolResultContent[] = []\n let textOnly = true\n for (const block of blocks) {\n if (block.type === 'text') parts.push({ type: 'text', text: block.text })\n else if (block.type === 'image') {\n textOnly = false\n parts.push({ type: 'image', source: imageSource(block.source) })\n }\n // Anything else (a nested tool result, an extension block) has no\n // representation inside a tool result and is dropped rather than guessed at.\n }\n if (textOnly) {\n return parts.map(part => (part.type === 'text' ? part.text : '')).join('\\n')\n }\n return parts\n}\n\n/** Parse tool-call arguments into the object this API expects. */\nfunction toolInput(raw: string): unknown {\n if (raw.trim().length === 0) return {}\n try {\n return JSON.parse(raw) as unknown\n } catch {\n // The model emitted invalid JSON. Sending `{}` keeps the conversation\n // well-formed so the tool layer can report the problem back to the model,\n // which is recoverable; failing the request here is not.\n return {}\n }\n}\n\nfunction citationOf(value: unknown): WireCitation | undefined {\n if (typeof value !== 'object' || value === null) return undefined\n const citation = value as Record<string, unknown>\n return typeof citation.type === 'string' ? structuredClone(citation) as WireCitation : undefined\n}\n\nfunction nativeReplayBlocks(value: unknown): WireRequestBlock[] {\n if (typeof value !== 'object' || value === null) return []\n const state = value as Record<string, unknown>\n const values = [state.call, state.result]\n return values.flatMap((candidate): WireRequestBlock[] => {\n if (typeof candidate !== 'object' || candidate === null) return []\n const block = candidate as Record<string, unknown>\n if (block.type === 'server_tool_use'\n && typeof block.id === 'string'\n && typeof block.name === 'string') {\n return [{\n type: 'server_tool_use', id: block.id, name: block.name,\n input: structuredClone(block.input ?? {}),\n }]\n }\n if (block.type === 'web_search_tool_result' && typeof block.tool_use_id === 'string') {\n return [{\n type: 'web_search_tool_result', tool_use_id: block.tool_use_id,\n content: structuredClone(block.content),\n ...block.caller === undefined ? {} : { caller: structuredClone(block.caller) },\n }]\n }\n return []\n })\n}\n\n/** Convert one normalized block to zero or more wire blocks. */\nfunction requestBlocks(block: ContentBlock): WireRequestBlock[] {\n switch (block.type) {\n case 'text': {\n // Whitespace-only text is rejected by this API, so it is dropped.\n if (block.text.trim().length === 0) return []\n const citations = block.annotations?.flatMap((annotation): WireCitation[] => {\n if (annotation.type !== 'url-citation') return []\n const citation = citationOf(annotation.providerState)\n return citation === undefined ? [] : [citation]\n })\n return [{\n type: 'text', text: block.text,\n ...citations === undefined || citations.length === 0 ? {} : { citations },\n }]\n }\n case 'image':\n return [{ type: 'image', source: imageSource(block.source) }]\n case 'document': {\n // `title` is what a citation is attributed to, so the file name is a much\n // better fallback than leaving it unset.\n const title = block.title ?? block.filename\n return [{\n type: 'document',\n source: documentSource(block.source),\n ...title === undefined ? {} : { title },\n ...block.context === undefined ? {} : { context: block.context },\n ...block.citations === undefined ? {} : { citations: { enabled: block.citations } },\n }]\n }\n case 'tool-call':\n return [{\n type: 'tool_use',\n id: block.id,\n name: block.name,\n input: toolInput(block.arguments),\n }]\n case 'tool-result':\n return [{\n type: 'tool_result',\n tool_use_id: block.toolCallId,\n content: toolResultContent(block.content),\n ...block.isError === true ? { is_error: true } : {},\n }]\n case 'native-tool-call':\n return nativeReplayBlocks(block.providerState)\n case 'reasoning': {\n const state = reasoningStateOf(block.providerState)\n if (state === undefined) {\n // No signature means this cannot be replayed as a thinking block. Dropping\n // it is correct: sending unsigned thinking is rejected outright.\n return []\n }\n if (state.kind === 'redacted_thinking') {\n return state.data === undefined ? [] : [{ type: 'redacted_thinking', data: state.data }]\n }\n return state.signature === undefined\n ? []\n : [{ type: 'thinking', thinking: block.text, signature: state.signature }]\n }\n default:\n return []\n }\n}\n\n/**\n * Build the message list, merging consecutive same-role messages.\n *\n * See the module note for why merging matters.\n */\nfunction messagesOf(messages: readonly Message[]): WireMessage[] {\n const result: WireMessage[] = []\n for (const message of messages) {\n if (message.role === 'system') continue // hoisted to the `system` field\n const role = message.role === 'assistant' ? 'assistant' : 'user'\n const blocks = message.content.flatMap(requestBlocks)\n if (blocks.length === 0) continue\n\n const previous = result.at(-1)\n if (previous !== undefined && previous.role === role) previous.content.push(...blocks)\n else result.push({ role, content: blocks })\n }\n return result\n}\n\n/** Collect the system prompt from the request plus any system-role messages. */\nfunction systemOf(request: ProtocolRequest): string | undefined {\n const fromMessages = request.options.messages\n .filter(message => message.role === 'system')\n .flatMap(message => message.content)\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n const all = request.options.system === undefined\n ? fromMessages\n : [request.options.system, ...fromMessages]\n const joined = all.join('\\n\\n')\n return joined.length === 0 ? undefined : joined\n}\n\n/** Map the neutral tool-choice vocabulary onto this API's. */\nfunction toolChoiceOf(choice: ToolChoice): WireToolChoice {\n if (choice === 'auto') return { type: 'auto' }\n if (choice === 'none') return { type: 'none' }\n // \"call some tool\" is spelled `any` here, not `required`.\n if (choice === 'required') return { type: 'any' }\n return { type: 'tool', name: choice.type === 'native' ? nativeToolName(choice.name) : choice.name }\n}\n\nfunction functionTool(tool: ToolSchema): WireTool {\n return { name: tool.name, description: tool.description, input_schema: tool.parameters }\n}\n\nfunction nativeToolName(name: string): string {\n if (name === 'web-search') return 'web_search'\n return name.replaceAll('-', '_')\n}\n\nfunction webSearchTool(tool: NativeWebSearchTool): WireTool {\n if (tool.allowedDomains !== undefined && tool.blockedDomains !== undefined) {\n throw new ModelError(\n 'Anthropic web search accepts allowedDomains or blockedDomains, not both',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n type: 'web_search_20250305',\n name: 'web_search',\n ...tool.maxUses === undefined ? {} : { max_uses: tool.maxUses },\n ...tool.allowedDomains === undefined ? {} : { allowed_domains: [...tool.allowedDomains] },\n ...tool.blockedDomains === undefined ? {} : { blocked_domains: [...tool.blockedDomains] },\n ...tool.userLocation === undefined ? {} : {\n user_location: { type: 'approximate', ...tool.userLocation },\n },\n }\n}\n\nfunction toolOf(tool: ModelToolSchema): WireTool {\n if (!isNativeToolSchema(tool)) return functionTool(tool)\n if (tool.name === 'web-search') return webSearchTool(tool)\n throw new ModelError(\n `Anthropic does not support the provider-native tool '${tool.name}'`,\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n}\n\n/** How a reasoning effort becomes a thinking token budget. */\nexport type ThinkingBudgets = Readonly<Record<string, number>>\n\n/** Options controlling how the request is built. */\nexport interface AnthropicSerializeOptions {\n /** Effort id to thinking-token budget. An absent or zero budget disables thinking. */\n budgets: ThinkingBudgets\n}\n\n/**\n * Resolve the `thinking` field for this request.\n *\n * The budget must leave room for a real answer, so it is capped below\n * `max_tokens` — this API requires `budget_tokens < max_tokens` and rejects the\n * request otherwise.\n */\nfunction thinkingOf(\n effort: string | undefined,\n maxTokens: number,\n budgets: ThinkingBudgets,\n): WireThinking | undefined {\n if (effort === undefined) return undefined\n const requested = budgets[effort]\n if (requested === undefined || requested <= 0) return { type: 'disabled' }\n // Leave at least a quarter of the budget for the visible answer.\n const capped = Math.min(requested, Math.floor(maxTokens * 0.75))\n // This API's own floor for extended thinking.\n return capped < 1_024 ? { type: 'disabled' } : { type: 'enabled', budget_tokens: capped }\n}\n\nfunction outputConfig(format: ModelOutputFormat | undefined): WireOutputConfig | undefined {\n if (format === undefined || format.type === 'text') return undefined\n return { format: { type: 'json_schema', schema: format.schema } }\n}\n\n/**\n * Build the Messages request body.\n * @param request - the resolved request, model, and connection.\n * @param options - thinking-budget mapping.\n * @returns the wire body, ready to serialize.\n */\nexport function serializeAnthropicRequest(\n request: ProtocolRequest,\n options: AnthropicSerializeOptions,\n): WireRequest {\n const { options: call } = request\n const system = systemOf(request)\n const tools = call.tools === undefined || call.tools.length === 0\n ? undefined\n : call.tools.map(toolOf)\n const thinking = thinkingOf(\n call.reasoningEffort === undefined ? undefined : String(call.reasoningEffort),\n request.maxTokens,\n options.budgets,\n )\n const thinkingEnabled = thinking?.type === 'enabled'\n const output = outputConfig(call.outputFormat)\n\n return {\n model: call.model,\n // Required by this API — unlike most others, omitting it is an error.\n max_tokens: request.maxTokens,\n messages: messagesOf(call.messages),\n ...system === undefined ? {} : { system },\n ...tools === undefined ? {} : { tools },\n ...call.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(call.toolChoice) },\n // Extended thinking is incompatible with sampling adjustments; sending both\n // is rejected, so the sampling knobs are dropped when thinking is on.\n ...!thinkingEnabled && call.temperature !== undefined\n ? { temperature: call.temperature }\n : {},\n ...!thinkingEnabled && call.topP !== undefined ? { top_p: call.topP } : {},\n ...call.stop === undefined || call.stop.length === 0\n ? {}\n : { stop_sequences: [...call.stop] },\n ...thinking === undefined ? {} : { thinking },\n ...output === undefined ? {} : { output_config: output },\n stream: true,\n }\n}\n","/**\n * Anthropic Messages API SSE events to the SDK's chunk protocol.\n *\n * Notable differences from the Responses translation:\n *\n * - Block indices come straight from the provider. This API numbers content\n * blocks contiguously from zero in emission order, which is already exactly\n * what our protocol wants, so no remapping is needed.\n * - Usage arrives in TWO places: input counts on `message_start`, output counts on\n * `message_delta`. Cumulative snapshots are emitted as usage-progress; the\n * final usage is emitted once at message_stop, before the finish.\n * - `input_tokens` here already EXCLUDES cached tokens, so unlike the Responses\n * translation nothing is subtracted. Getting this backwards would under-report\n * input on every cached call.\n *\n * @module ai-agent-sdk/providers/anthropic/translate\n */\n\nimport {\n CONTEXT_WINDOW_EXCEEDED_CODE,\n MODEL_ERROR_CODES,\n ModelError,\n QUOTA_EXCEEDED_CODE,\n isContextWindowExceededError,\n isQuotaExceededError,\n} from '@alvin0/ai-agent-sdk-core'\nimport { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport { isJsonValue, type JsonValue } from '@alvin0/ai-agent-sdk-core'\nimport type { ContentBlock, TextAnnotation } from '@alvin0/ai-agent-sdk-core'\nimport type { FinishReason, UsageCounters } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type { AnthropicReasoningState } from './serialize.ts'\nimport type {\n WireCitation,\n WireServerToolUseBlock,\n WireStopReason,\n WireStreamEvent,\n WireUsage,\n WireWebSearchToolResultBlock,\n} from './wire.ts'\n\n/** Which of our block types one wire block maps to. */\ntype BlockKind = 'text' | 'reasoning' | 'tool-call' | 'native-tool-call'\n\ninterface OpenBlock {\n readonly kind: BlockKind\n text: string\n args: string\n callId: string\n name: string\n signature: string | undefined\n redactedData: string | undefined\n annotations: TextAnnotation[]\n nativeCall: WireServerToolUseBlock | undefined\n nativeResult: WireWebSearchToolResultBlock | undefined\n closed: boolean\n}\n\nfunction blockKind(type: string | undefined): BlockKind | undefined {\n switch (type) {\n case 'text': return 'text'\n case 'thinking':\n case 'redacted_thinking': return 'reasoning'\n case 'tool_use': return 'tool-call'\n case 'server_tool_use': return 'native-tool-call'\n default: return undefined\n }\n}\n\n/** Accumulated token counts, filled from two different events. */\ninterface UsageAccumulator {\n input: unknown\n output: unknown\n cacheRead: unknown\n cacheWrite: unknown\n seen: boolean\n}\n\nfunction absorbUsage(target: UsageAccumulator, usage: WireUsage | undefined): void {\n if (typeof usage !== 'object' || usage === null) return\n if ('input_tokens' in usage) target.input = usage.input_tokens\n if ('output_tokens' in usage) target.output = usage.output_tokens\n if ('cache_read_input_tokens' in usage && usage.cache_read_input_tokens !== null) {\n target.cacheRead = usage.cache_read_input_tokens\n }\n if ('cache_creation_input_tokens' in usage && usage.cache_creation_input_tokens !== null) {\n target.cacheWrite = usage.cache_creation_input_tokens\n }\n target.seen = true\n}\n\nfunction finalUsage(accumulated: UsageAccumulator): UsageCounters | undefined {\n if (!accumulated.seen) return undefined\n const output: Record<string, unknown> = {\n ...accumulated.input === undefined ? {} : { inputTokens: accumulated.input },\n ...accumulated.output === undefined ? {} : { outputTokens: accumulated.output },\n // Cache omission/null is authoritative zero for this protocol. Invalid\n // present values are retained so the accounting boundary can record them.\n ...accumulated.cacheRead === undefined || accumulated.cacheRead === 0\n ? {} : { cacheReadTokens: accumulated.cacheRead },\n ...accumulated.cacheWrite === undefined || accumulated.cacheWrite === 0\n ? {} : { cacheWriteTokens: accumulated.cacheWrite },\n }\n const counters = [\n accumulated.input,\n accumulated.cacheRead ?? 0,\n accumulated.cacheWrite ?? 0,\n accumulated.output,\n ]\n if (counters.every(validUsageCounter)) {\n output.totalTokens = counters.reduce<number>((total, value) => total + value, 0)\n }\n return output as UsageCounters\n}\n\nfunction validUsageCounter(value: unknown): value is number {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0\n}\n\n/** Map this API's stop reason onto ours. */\nfunction finishReason(stop: WireStopReason | null | undefined): FinishReason {\n switch (stop) {\n case 'tool_use': return { kind: 'tool-calls' }\n case 'max_tokens': return { kind: 'max-tokens' }\n case 'refusal':\n return {\n kind: 'error',\n failure: {\n message: 'the model refused to answer',\n code: MODEL_ERROR_CODES.INVALID_REQUEST,\n },\n }\n // `end_turn`, `stop_sequence`, and `pause_turn` all mean the turn produced a\n // complete answer as far as a caller is concerned.\n default: return { kind: 'stop' }\n }\n}\n\n/** Build the authoritative block for a completed content block. */\nfunction closedBlock(open: OpenBlock): ContentBlock | undefined {\n switch (open.kind) {\n case 'text':\n return {\n type: 'text', text: open.text,\n ...open.annotations.length === 0 ? {} : { annotations: open.annotations },\n }\n case 'reasoning': {\n const state: AnthropicReasoningState = open.redactedData !== undefined\n ? { kind: 'redacted_thinking', data: open.redactedData }\n : {\n kind: 'thinking',\n ...open.signature === undefined ? {} : { signature: open.signature },\n }\n return { type: 'reasoning', text: open.text, providerState: state }\n }\n case 'tool-call':\n return {\n type: 'tool-call',\n id: ToolCallId(open.callId),\n name: open.name,\n arguments: open.args.length > 0 ? open.args : '{}',\n }\n case 'native-tool-call': {\n const parsed = parsedArguments(open.args, open.nativeCall?.input)\n const call: WireServerToolUseBlock = open.nativeCall ?? {\n type: 'server_tool_use', id: open.callId, name: 'web_search', input: parsed,\n }\n return {\n type: 'native-tool-call', id: open.callId,\n name: open.name === 'web_search' ? 'web-search' : open.name.replaceAll('_', '-'),\n arguments: parsed,\n content: [],\n providerState: {\n call: { ...call, input: parsed },\n ...open.nativeResult === undefined ? {} : { result: open.nativeResult },\n },\n }\n }\n default:\n return undefined\n }\n}\n\nfunction parsedArguments(raw: string, fallback?: unknown): JsonValue {\n if (raw.length === 0) return isJsonValue(fallback) ? fallback : {}\n try {\n const value: unknown = JSON.parse(raw)\n return isJsonValue(value) ? value : {}\n } catch {\n return {}\n }\n}\n\nfunction citationAnnotation(citation: WireCitation): TextAnnotation | undefined {\n if (citation.type !== 'web_search_result_location' || typeof citation.url !== 'string') {\n return undefined\n }\n return {\n type: 'url-citation', url: citation.url,\n ...typeof citation.title === 'string' ? { title: citation.title } : {},\n providerState: structuredClone(citation),\n }\n}\n\n/**\n * Translate one Messages SSE stream.\n *\n * Owns termination. There is no `[DONE]` sentinel: the stream ends on\n * `message_stop`, and a body that ends before that was truncated — a failure\n * rather than a short answer.\n * @param events - decoded SSE events.\n * @param displayName - provider name, used in diagnostics.\n * @returns the chunk stream.\n */\nexport async function* translateAnthropicStream(\n events: AsyncIterable<ProtocolSseEvent>,\n displayName: string,\n): AsyncGenerator<ProtocolStreamChunk> {\n const open = new Map<number, OpenBlock>()\n const usage: UsageAccumulator = {\n input: undefined, output: undefined, cacheRead: undefined, cacheWrite: undefined, seen: false,\n }\n let stop: WireStopReason | null | undefined\n let terminated = false\n let emittedBlocks = 0\n\n for await (const raw of events) {\n let event: WireStreamEvent\n try {\n event = JSON.parse(raw.data) as WireStreamEvent\n } catch (error: unknown) {\n throw new ModelError(\n `${displayName} sent a malformed stream event`,\n MODEL_ERROR_CODES.MALFORMED_RESPONSE,\n { cause: error },\n )\n }\n\n switch (event.type) {\n case 'message_start': {\n absorbUsage(usage, event.message.usage)\n const progress = finalUsage(usage)\n if (progress !== undefined) yield { type: 'usage-progress', usage: progress }\n break\n }\n\n case 'content_block_start': {\n if (event.content_block.type === 'web_search_tool_result') {\n const result = event.content_block\n const owner = [...open.values()].find(entry => entry.kind === 'native-tool-call'\n && entry.callId === result.tool_use_id)\n if (owner !== undefined) {\n owner.nativeResult = result\n const block = closedBlock(owner)\n if (block !== undefined && !owner.closed) {\n owner.closed = true\n yield {\n type: 'block-end',\n index: [...open.entries()].find(([, entry]) => entry === owner)?.[0] ?? event.index,\n block,\n }\n }\n }\n break\n }\n const kind = blockKind(event.content_block.type)\n if (kind === undefined) break\n const block = event.content_block\n const entry: OpenBlock = {\n kind,\n text: block.type === 'text'\n ? block.text\n : block.type === 'thinking' ? block.thinking : '',\n args: '',\n callId: block.type === 'tool_use' ? block.id : `block-${event.index}`,\n name: block.type === 'tool_use' || block.type === 'server_tool_use' ? block.name : '',\n signature: block.type === 'thinking' ? block.signature : undefined,\n redactedData: block.type === 'redacted_thinking' ? block.data : undefined,\n annotations: [],\n nativeCall: block.type === 'server_tool_use' ? block : undefined,\n nativeResult: undefined,\n closed: false,\n }\n if (block.type === 'server_tool_use') {\n entry.callId = block.id\n entry.args = ''\n }\n open.set(event.index, entry)\n emittedBlocks += 1\n yield { type: 'block-start', index: event.index, blockType: kind }\n break\n }\n\n case 'content_block_delta': {\n const entry = open.get(event.index)\n if (entry === undefined) break\n const delta = event.delta\n switch (delta.type) {\n case 'text_delta':\n entry.text += delta.text\n yield { type: 'text-delta', index: event.index, text: delta.text }\n break\n case 'thinking_delta':\n entry.text += delta.thinking\n yield { type: 'reasoning-delta', index: event.index, text: delta.thinking }\n break\n case 'signature_delta':\n // Arrives once, just before the block closes. It carries no visible\n // content, so it produces no chunk — only the state needed to replay\n // this thinking block on a later request.\n entry.signature = delta.signature\n break\n case 'input_json_delta':\n entry.args += delta.partial_json\n if (entry.kind === 'tool-call') {\n yield {\n type: 'tool-call-delta',\n index: event.index,\n id: ToolCallId(entry.callId),\n ...entry.name.length > 0 ? { name: entry.name } : {},\n argumentsDelta: delta.partial_json,\n }\n }\n break\n case 'citations_delta': {\n const annotation = citationAnnotation(delta.citation)\n if (annotation !== undefined) entry.annotations.push(annotation)\n break\n }\n default:\n break\n }\n break\n }\n\n case 'content_block_stop': {\n const entry = open.get(event.index)\n if (entry === undefined) break\n if (entry.kind === 'native-tool-call') break\n const block = closedBlock(entry)\n if (block !== undefined && !entry.closed) {\n entry.closed = true\n yield { type: 'block-end', index: event.index, block }\n }\n break\n }\n\n case 'message_delta': {\n stop = event.delta.stop_reason\n absorbUsage(usage, event.usage)\n const progress = finalUsage(usage)\n if (progress !== undefined) yield { type: 'usage-progress', usage: progress }\n break\n }\n\n case 'message_stop': {\n for (const [index, entry] of open) {\n if (entry.kind !== 'native-tool-call' || entry.closed) continue\n const block = closedBlock(entry)\n if (block !== undefined) yield { type: 'block-end', index, block }\n entry.closed = true\n }\n const mapped = finalUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n if (emittedBlocks === 0) {\n // A clean stop with no content at all. Reported as a failure rather\n // than an empty message, because an empty message ends the turn with\n // nothing for the caller to act on — and it is safe to retry.\n throw new ModelError(\n `${displayName} returned a response with no content`,\n 'EMPTY_RESPONSE',\n )\n }\n yield { type: 'finish', reason: finishReason(stop) }\n terminated = true\n return\n }\n\n case 'error': {\n const detail = [event.error.type, event.error.message]\n .filter((part): part is string => part !== undefined)\n .join(' ')\n throw new ModelError(\n event.error.message ?? `${displayName} reported a stream error`,\n // `overloaded_error` mid-stream is the common case and must stay\n // retryable, which the shared 5xx mapping gives us.\n event.error.type === 'overloaded_error'\n ? MODEL_ERROR_CODES.SERVER\n : anthropicStreamErrorCode(event.error.type, detail),\n )\n }\n\n // `ping` and any future event carry nothing this protocol needs.\n default:\n break\n }\n }\n\n if (!terminated) {\n throw new ModelError(\n `${displayName} stream ended before message_stop`,\n MODEL_ERROR_CODES.STREAM_CLOSED,\n )\n }\n}\n\nfunction anthropicStreamErrorCode(type: string | undefined, detail: string): string {\n if (type === 'authentication_error' || type === 'permission_error') {\n return MODEL_ERROR_CODES.AUTH\n }\n if (isQuotaExceededError(detail)) return QUOTA_EXCEEDED_CODE\n if (type === 'rate_limit_error') return MODEL_ERROR_CODES.RATE_LIMIT\n if (type === 'api_error') return MODEL_ERROR_CODES.SERVER\n if (isContextWindowExceededError(detail)) return CONTEXT_WINDOW_EXCEEDED_CODE\n return MODEL_ERROR_CODES.INVALID_REQUEST\n}\n","/**\n * The Anthropic Messages protocol, as a reusable {@link WireProtocol}.\n *\n * @module ai-agent-sdk/providers/protocols/anthropic-messages\n */\n\nimport type {\n ProtocolDefinition,\n ProtocolRequest,\n ProtocolSseEvent,\n ProtocolStreamChunk,\n} from './contract.ts'\nimport type { ModelTarget, ResolvedModelInfo } from '@alvin0/ai-agent-sdk-core/provider'\nimport { serializeAnthropicRequest, type ThinkingBudgets } from './serialize.ts'\nimport { translateAnthropicStream } from './translate.ts'\n\n/** Protocol id, usable as a stable string in configuration. */\nexport const ANTHROPIC_MESSAGES_PROTOCOL_ID = 'anthropic-messages'\n\n/**\n * The API version header value.\n *\n * Mandatory on every request. Stable across the entire lifetime of this API — new\n * capabilities arrive as opt-in beta headers rather than a version bump — which is\n * why it lives on the protocol instead of being restated by each endpoint.\n */\nexport const ANTHROPIC_VERSION = '2023-06-01'\n\n/**\n * Default reasoning efforts, expressed as thinking-token budgets.\n *\n * Budgets rather than an opaque level because that is what this API takes. The\n * SDK's effort ids are a neutral surface over a provider-specific knob, and\n * mapping them here is the whole reason `ReasoningEffortId` is opaque.\n */\nexport const DEFAULT_THINKING_BUDGETS: ThinkingBudgets = Object.freeze({\n off: 0,\n low: 2_048,\n medium: 8_192,\n high: 24_576,\n})\n\n/** Per-endpoint knobs of the Messages protocol. */\nexport interface AnthropicDialect {\n /** Effort id to thinking-token budget. */\n readonly budgets: ThinkingBudgets\n /** `anthropic-version` header value. */\n readonly version: string\n /** Opt-in beta features, sent as `anthropic-beta`. */\n readonly beta: readonly string[]\n}\n\nconst DEFAULT_DIALECT: AnthropicDialect = Object.freeze({\n budgets: DEFAULT_THINKING_BUDGETS,\n version: ANTHROPIC_VERSION,\n beta: Object.freeze([]),\n})\n\ninterface RuntimeProtocolRequest extends ProtocolRequest {\n readonly model: ResolvedModelInfo\n readonly connection: {\n readonly baseUrl: string\n readonly headers: Readonly<Record<string, string>>\n }\n}\n\n/** Marker-based runtime view, kept structurally independent from provider-http. */\nexport interface AnthropicMessagesProtocolDefinition {\n readonly kind: 'http-wire-protocol'\n readonly apiVersion: 1\n readonly id: string\n readonly defaultDialect: AnthropicDialect\n readonly exampleModel?: ModelTarget\n readonly endpointPath: (request: RuntimeProtocolRequest, dialect: AnthropicDialect) => string\n readonly protocolHeaders?: (dialect: AnthropicDialect) => Readonly<Record<string, string>>\n readonly serialize: (\n request: RuntimeProtocolRequest,\n dialect: AnthropicDialect,\n ) => Readonly<Record<string, unknown>>\n readonly translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: RuntimeProtocolRequest,\n displayName: string,\n ) => AsyncGenerator<ProtocolStreamChunk>\n}\n\n/** The Anthropic Messages wire protocol. */\nexport const anthropicMessagesProtocol: ProtocolDefinition<AnthropicDialect>\n & AnthropicMessagesProtocolDefinition = Object.freeze({\n kind: 'http-wire-protocol' as const,\n apiVersion: 1 as const,\n id: ANTHROPIC_MESSAGES_PROTOCOL_ID,\n defaultDialect: DEFAULT_DIALECT,\n endpointPath: () => '/v1/messages',\n protocolHeaders: (dialect: AnthropicDialect) => ({\n 'anthropic-version': dialect.version,\n ...dialect.beta.length === 0 ? {} : { 'anthropic-beta': dialect.beta.join(',') },\n }),\n serialize(request: ProtocolRequest, dialect: AnthropicDialect): Readonly<Record<string, unknown>> {\n const body: unknown = serializeAnthropicRequest(request, { budgets: dialect.budgets })\n return body as Readonly<Record<string, unknown>>\n },\n // Params are annotated because `Object.freeze` erases the contextual typing the\n // `WireProtocol` annotation would otherwise supply.\n translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n _request: ProtocolRequest,\n displayName: string,\n ): AsyncGenerator<ProtocolStre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AAO;CACtD,MAAM;CACN,YAAY;CACZ,IAAI;CACJ,gBAAgB;CAChB,oBAAoB;CACpB,kBAAkB,aAA+B;EAC/C,qBAAqB,QAAQ;EAC7B,GAAG,QAAQ,KAAK,WAAW,IAAI,CAAC,IAAI,EAAE,kBAAkB,QAAQ,KAAK,KAAK,GAAG,EAAE;CACjF;CACA,UAAU,SAA0B,SAA8D;EAEhG,OADsB,0BAA0B,SAAS,EAAE,SAAS,QAAQ,QAAQ,CAC1E;CACZ;CAGA,YACE,QACA,UACA,gBACwC,yBAAyB,QAAQ,WAAW;AACxF,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"name": "alvin0 - chaulamdinhai",
|
|
5
5
|
"email": "chaulamdinhai@gmail.com"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.1",
|
|
8
8
|
"description": "Universal Anthropic Messages wire schema, serializer, translator, and dialect for ai-agent-sdk",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"provenance": true
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@alvin0/ai-agent-sdk-core": "^0.1.
|
|
41
|
+
"@alvin0/ai-agent-sdk-core": "^0.1.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@alvin0/ai-agent-sdk-core": "^0.1.
|
|
44
|
+
"@alvin0/ai-agent-sdk-core": "^0.1.1",
|
|
45
45
|
"@arethetypeswrong/cli": "0.18.5",
|
|
46
46
|
"playwright": "1.62.1",
|
|
47
47
|
"publint": "0.3.24",
|