@alvin0/ai-agent-sdk-protocol-anthropic-messages 0.1.11 → 0.1.13

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.js CHANGED
@@ -183,6 +183,7 @@ function nativeToolName(name) {
183
183
  return name.replaceAll("-", "_");
184
184
  }
185
185
  function webSearchTool(tool) {
186
+ if (tool.searchContentTypes?.includes("image") === true) throw new ModelError("Anthropic web search does not return images", MODEL_ERROR_CODES.INVALID_REQUEST);
186
187
  if (tool.allowedDomains !== void 0 && tool.blockedDomains !== void 0) throw new ModelError("Anthropic web search accepts allowedDomains or blockedDomains, not both", MODEL_ERROR_CODES.INVALID_REQUEST);
187
188
  return {
188
189
  type: "web_search_20250305",
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/serialize-types.ts","../src/request-blocks.ts","../src/serialize-options.ts","../src/serialize.ts","../src/stream-blocks.ts","../src/stream-usage.ts","../src/stream-events.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["/**\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\n/** How a reasoning effort becomes a thinking token budget, for `reasoningFormat: 'thinking-budget'`. */\nexport type ThinkingBudgets = Readonly<Record<string, number>>\n\n/** Which field carries reasoning effort on the wire. */\nexport type AnthropicReasoningFormat = 'output-config' | 'thinking-budget'\n\n/** Options controlling how the request is built. */\nexport interface AnthropicSerializeOptions {\n /**\n * `'output-config'` (default, current models): effort is pass-through —\n * sent verbatim as `output_config.effort`, exactly what the caller gave.\n * `'thinking-budget'` (older models, or a gateway that only understands a\n * token budget): effort is looked up in `budgets` and converted to\n * `thinking.budget_tokens` instead — the SDK does the conversion because the\n * endpoint has no `effort` field to receive the raw string at all.\n */\n reasoningFormat?: AnthropicReasoningFormat\n /** Effort id to thinking-token budget; only consulted under `'thinking-budget'`. */\n budgets: ThinkingBudgets\n /**\n * Extended-thinking mode, sent only when set — omission means \"say nothing\",\n * which is this API's own way of leaving the model's default behavior alone.\n * Ignored under `'thinking-budget'`, which derives `thinking` from the effort instead.\n */\n thinking?: 'adaptive' | 'disabled'\n /**\n * Mark the stable prefix of one request as a cache breakpoint: the system\n * prompt, the last tool definition (if any), and every message but the\n * newest — up to 3 of this API's 4-breakpoint ceiling, leaving one spare.\n * A conversation resending its whole history on every turn (this API is\n * stateless) pays full price for that history without this; with it, a\n * later turn reads the unchanged prefix at a steep discount instead of\n * paying to reprocess it.\n *\n * Off by default: not every account or Anthropic-COMPATIBLE gateway\n * behind this same adapter understands `cache_control`, and a route that\n * doesn't should not silently be asked to. See `dialectOf()` in\n * `provider-anthropic/src/adapter.ts` for the live-discovered fallback\n * that turns this off automatically, permanently, the first time a\n * gateway rejects it.\n */\n promptCaching?: boolean\n /** Cache breakpoint lifetime. Defaults to this API's own default (5 minutes). */\n promptCachingTtl?: '5m' | '1h'\n}\n\n/**\n * Last-resort `max_tokens`, used only when neither the caller, the model, nor\n * the route names one. This API rejects a request that omits the field\n * entirely, unlike most others — see {@link serializeAnthropicRequest}.\n */\nexport const DEFAULT_MAX_TOKENS = 8_192\n\n","import { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ContentBlock, DocumentSource, ImageSource } from '@alvin0/ai-agent-sdk-core'\nimport type {\n WireDocumentSource, WireImageSource, WireCitation, WireRequestBlock, WireToolResultContent,\n} from './wire.ts'\nimport type { AnthropicReasoningState } from './serialize-types.ts'\n\nexport function 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\nexport function 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\nexport function 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\nexport function 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\nexport function 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\nexport function 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\nexport function 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\nexport function requestBlocks(block: ContentBlock): WireRequestBlock[] {\n switch (block.type) {\n case 'text': return textBlocks(block)\n case 'image':\n return [{ type: 'image', source: imageSource(block.source) }]\n case 'document': return documentBlocks(block)\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': return reasoningBlocks(block)\n default:\n return []\n }\n}\n\nfunction textBlocks(block: Extract<ContentBlock, { type: 'text' }>): WireRequestBlock[] {\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\n\nfunction documentBlocks(block: Extract<ContentBlock, { type: 'document' }>): WireRequestBlock[] {\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\n\nfunction reasoningBlocks(block: Extract<ContentBlock, { type: 'reasoning' }>): WireRequestBlock[] {\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","import {\n isNativeToolSchema, type ModelOutputFormat, type ModelToolSchema, type NativeWebSearchTool,\n type ToolChoice, type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type { WireCacheControl, WireOutputConfig, WireThinking, WireTool, WireToolChoice } from './wire.ts'\nimport type { ThinkingBudgets, AnthropicSerializeOptions, AnthropicReasoningFormat } from './serialize-types.ts'\n\nexport function 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\nexport function functionTool(tool: ToolSchema): WireTool {\n return { name: tool.name, description: tool.description, input_schema: tool.parameters }\n}\n\nexport function nativeToolName(name: string): string {\n if (name === 'web-search') return 'web_search'\n return name.replaceAll('-', '_')\n}\n\nexport function 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\nexport function 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\nexport function thinkingFromBudget(\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\nexport function outputConfig(\n format: ModelOutputFormat | undefined,\n effort: string | undefined,\n): WireOutputConfig | undefined {\n const formatPart = format === undefined || format.type === 'text'\n ? undefined\n : { type: 'json_schema' as const, schema: format.schema }\n if (formatPart === undefined && effort === undefined) return undefined\n return {\n ...(formatPart === undefined ? {} : { format: formatPart }),\n ...(effort === undefined ? {} : { effort }),\n }\n}\n\nexport function cacheControlOf(options: AnthropicSerializeOptions): WireCacheControl | undefined {\n if (options.promptCaching !== true) return undefined\n return { type: 'ephemeral', ...(options.promptCachingTtl === undefined ? {} : { ttl: options.promptCachingTtl }) }\n}\n\nexport function toolsOf(request: ProtocolRequest, cacheControl: WireCacheControl | undefined): WireTool[] | undefined {\n const tools = request.options.tools\n if (tools === undefined || tools.length === 0) return undefined\n const result = tools.map(toolOf)\n if (cacheControl !== undefined) {\n const lastTool = result.at(-1)\n if (lastTool !== undefined) lastTool.cache_control = cacheControl\n }\n return result\n}\n\nexport function reasoningOptions(\n request: ProtocolRequest, options: AnthropicSerializeOptions, maxTokens: number,\n) {\n const reasoningFormat = options.reasoningFormat ?? 'output-config'\n const effort = request.options.reasoningEffort === undefined ? undefined : String(request.options.reasoningEffort)\n const thinking = thinkingOf(reasoningFormat, { options, effort, maxTokens })\n const output = outputConfig(request.options.outputFormat, reasoningFormat === 'output-config' ? effort : undefined)\n return {\n ...thinking === undefined ? {} : { thinking },\n ...output === undefined ? {} : { output_config: output },\n }\n}\n\nfunction thinkingOf(\n format: AnthropicReasoningFormat,\n context: { options: AnthropicSerializeOptions; effort: string | undefined; maxTokens: number },\n): WireThinking | undefined {\n const { options, effort, maxTokens } = context\n if (format === 'thinking-budget') return thinkingFromBudget(effort, maxTokens, options.budgets)\n if (options.thinking === undefined) return undefined\n return options.thinking === 'adaptive' ? { type: 'adaptive' } : { type: 'disabled' }\n}\n\nexport function samplingOptions(request: ProtocolRequest) {\n const call = request.options\n return {\n ...call.temperature === undefined ? {} : { temperature: call.temperature },\n ...call.topP === undefined ? {} : { top_p: call.topP },\n ...call.stop === undefined || call.stop.length === 0 ? {} : { stop_sequences: [...call.stop] },\n }\n}\n","/**\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 type { ContentBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { Message } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type { WireCacheControl, WireMessage, WireRequest, WireSystemBlock } from './wire.ts'\nexport { DEFAULT_MAX_TOKENS } from './serialize-types.ts'\nexport type { AnthropicReasoningState, ThinkingBudgets, AnthropicReasoningFormat, AnthropicSerializeOptions }\n from './serialize-types.ts'\nimport { DEFAULT_MAX_TOKENS, type AnthropicSerializeOptions } from './serialize-types.ts'\nimport { requestBlocks } from './request-blocks.ts'\nimport { cacheControlOf, toolsOf, toolChoiceOf, samplingOptions, reasoningOptions } from './serialize-options.ts'\n\nfunction messagesOf(\n messages: readonly Message[],\n cacheControl: WireCacheControl | undefined,\n): 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 markMessageCache(result, cacheControl)\n return result\n}\n\nfunction markMessageCache(messages: WireMessage[], cacheControl: WireCacheControl | undefined): void {\n if (cacheControl !== undefined && messages.length >= 2) {\n const boundary = messages[messages.length - 2]\n const lastBlock = boundary?.content.at(-1)\n if (lastBlock !== undefined) lastBlock.cache_control = cacheControl\n }\n}\n\n\nfunction systemOf(\n request: ProtocolRequest,\n cacheControl: WireCacheControl | undefined,\n): string | WireSystemBlock[] | 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 if (joined.length === 0) return undefined\n if (cacheControl === undefined) return joined\n return [{ type: 'text', text: joined, cache_control: cacheControl }]\n}\n\nexport function serializeAnthropicRequest(\n request: ProtocolRequest, options: AnthropicSerializeOptions,\n): WireRequest {\n const { options: call } = request\n const cacheControl = cacheControlOf(options)\n const system = systemOf(request, cacheControl)\n const tools = toolsOf(request, cacheControl)\n const maxTokens = request.maxTokens ?? DEFAULT_MAX_TOKENS\n return {\n model: call.model, max_tokens: maxTokens,\n messages: messagesOf(call.messages, cacheControl),\n ...system === undefined ? {} : { system },\n ...tools === undefined ? {} : { tools },\n ...call.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(call.toolChoice) },\n ...samplingOptions(request),\n ...reasoningOptions(request, options, maxTokens),\n stream: true,\n }\n}\n","import { 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 { AnthropicReasoningState } from './serialize.ts'\nimport type { WireCitation, WireServerToolUseBlock, WireWebSearchToolResultBlock } from './wire.ts'\n\nexport type BlockKind = 'text' | 'reasoning' | 'tool-call' | 'native-tool-call'\n\nexport interface 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\nexport function 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\nexport function 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': return closedReasoning(open)\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': return closedNativeTool(open)\n default:\n return undefined\n }\n}\n\nexport function 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\nexport function 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\nfunction closedReasoning(open: OpenBlock): ContentBlock {\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\nfunction closedNativeTool(open: OpenBlock): ContentBlock {\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","import { MODEL_ERROR_CODES } from '@alvin0/ai-agent-sdk-core'\nimport type { FinishReason, UsageCounters } from '@alvin0/ai-agent-sdk-core'\nimport type { WireStopReason, WireUsage } from './wire.ts'\n\nexport interface UsageAccumulator {\n input: unknown\n output: unknown\n cacheRead: unknown\n cacheWrite: unknown\n seen: boolean\n}\n\nexport function 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\nexport function 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 ...omittedCacheCounter(accumulated.cacheRead)\n ? {} : { cacheReadTokens: accumulated.cacheRead },\n ...omittedCacheCounter(accumulated.cacheWrite)\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\nexport function validUsageCounter(value: unknown): value is number {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0\n}\n\nexport function 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\nfunction omittedCacheCounter(value: unknown): boolean { return value === undefined || value === 0 }\n","import {\n CONTEXT_WINDOW_EXCEEDED_CODE, MODEL_ERROR_CODES, ModelError, QUOTA_EXCEEDED_CODE,\n isContextWindowExceededError, isQuotaExceededError,\n} from '@alvin0/ai-agent-sdk-core'\nimport { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolStreamChunk } from './contract.ts'\nimport type { WireStopReason, WireStreamEvent } from './wire.ts'\nimport { blockKind, closedBlock, citationAnnotation, type OpenBlock } from './stream-blocks.ts'\nimport { absorbUsage, finalUsage, finishReason, type UsageAccumulator } from './stream-usage.ts'\n\nexport interface StreamState {\n open: Map<number, OpenBlock>\n usage: UsageAccumulator\n stop: WireStopReason | null | undefined\n emittedBlocks: number\n}\n\nexport function* translateEvent(\n state: StreamState, event: WireStreamEvent, displayName: string,\n): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'message_start': yield* messageStart(state, event); return\n case 'content_block_start': yield* contentStart(state, event); return\n case 'content_block_delta': yield* contentDelta(state, event); return\n case 'content_block_stop': yield* contentStop(state, event); return\n case 'message_delta': yield* messageDelta(state, event); return\n case 'message_stop': yield* messageStop(state, displayName); return\n case 'error': yield* streamError(event, displayName); return\n default: return\n }\n}\n\nfunction* messageStart(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'message_start' }>,\n): Generator<ProtocolStreamChunk> {\n absorbUsage(state.usage, event.message.usage)\n const progress = finalUsage(state.usage)\n if (progress !== undefined) yield { type: 'usage-progress', usage: progress }\n}\n\nfunction* contentStart(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'content_block_start' }>,\n): Generator<ProtocolStreamChunk> {\n if (event.content_block.type === 'web_search_tool_result') {\n yield* webSearchResult(state, event)\n return\n }\n const kind = blockKind(event.content_block.type)\n if (kind === undefined) return\n const block = event.content_block\n const entry: OpenBlock = {\n kind,\n text: initialText(block),\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 state.open.set(event.index, entry)\n state.emittedBlocks += 1\n yield { type: 'block-start', index: event.index, blockType: kind }\n}\n\nfunction* contentDelta(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'content_block_delta' }>,\n): Generator<ProtocolStreamChunk> {\n const entry = state.open.get(event.index)\n if (entry === undefined) return\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 return\n case 'thinking_delta':\n entry.text += delta.thinking\n yield { type: 'reasoning-delta', index: event.index, text: delta.thinking }\n return\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 return\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 return\n case 'citations_delta': {\n const annotation = citationAnnotation(delta.citation)\n if (annotation !== undefined) entry.annotations.push(annotation)\n return\n }\n default:\n return\n }\n}\n\nfunction* contentStop(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'content_block_stop' }>,\n): Generator<ProtocolStreamChunk> {\n const entry = state.open.get(event.index)\n if (entry === undefined) return\n if (entry.kind === 'native-tool-call') return\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}\n\nfunction* messageDelta(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'message_delta' }>,\n): Generator<ProtocolStreamChunk> {\n state.stop = event.delta.stop_reason\n absorbUsage(state.usage, event.usage)\n const progress = finalUsage(state.usage)\n if (progress !== undefined) yield { type: 'usage-progress', usage: progress }\n}\n\nfunction* messageStop(\n state: StreamState, displayName: string,\n): Generator<ProtocolStreamChunk> {\n for (const [index, entry] of state.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(state.usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n if (state.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(state.stop) }\n}\n\nfunction* streamError(\n event: Extract<WireStreamEvent, { type: 'error' }>, displayName: string,\n): Generator<ProtocolStreamChunk> {\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\nfunction initialText(block: Extract<WireStreamEvent, { type: 'content_block_start' }>['content_block']): string {\n if (block.type === 'text') return block.text\n if (block.type === 'thinking') return block.thinking\n return ''\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\nfunction* webSearchResult(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'content_block_start' }>,\n): Generator<ProtocolStreamChunk> {\n if (event.content_block.type !== 'web_search_tool_result') return\n const result = event.content_block\n const owner = [...state.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: [...state.open.entries()].find(([, entry]) => entry === owner)?.[0] ?? event.index,\n block,\n }\n }\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 { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type { WireStreamEvent } from './wire.ts'\nimport { translateEvent, type StreamState } from './stream-events.ts'\n\nexport async function* translateAnthropicStream(\n events: AsyncIterable<ProtocolSseEvent>, displayName: string,\n): AsyncGenerator<ProtocolStreamChunk> {\n const state: StreamState = {\n open: new Map(), emittedBlocks: 0, stop: undefined,\n usage: { input: undefined, output: undefined, cacheRead: undefined, cacheWrite: undefined, seen: false },\n }\n for await (const raw of events) {\n const event = parseEvent(raw, displayName)\n yield* translateEvent(state, event, displayName)\n if (event.type === 'message_stop') return\n }\n throw new ModelError(\n `${displayName} stream ended before message_stop`,\n MODEL_ERROR_CODES.STREAM_CLOSED,\n )\n}\n\nfunction parseEvent(raw: ProtocolSseEvent, displayName: string): WireStreamEvent {\n try { return 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, { cause: error },\n )\n }\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 AnthropicReasoningFormat, 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 /**\n * Which field carries reasoning effort. `'output-config'` (default) is pure\n * pass-through — the caller's effort string reaches `output_config.effort`\n * unchanged, current GA behavior. `'thinking-budget'` is for an older model\n * or a gateway that only understands a token budget: the SDK converts effort\n * to `thinking.budget_tokens` using `budgets` instead of sending it raw.\n */\n readonly reasoningFormat: AnthropicReasoningFormat\n /** Effort id to thinking-token budget; only consulted under `'thinking-budget'`. */\n readonly budgets: ThinkingBudgets\n /**\n * Extended-thinking mode, sent only when set. Independent of effort under\n * `'output-config'` — omission leaves the model's own default thinking\n * behavior alone rather than the SDK guessing one.\n */\n readonly thinking?: 'adaptive' | 'disabled'\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 * Marks the stable prefix (system, tools, everything but the newest\n * message) as a cache breakpoint. See `AnthropicSerializeOptions`'s doc\n * comment in `serialize.ts` for why, and off by default for the same\n * \"not every gateway understands this\" reason `reasoningFormat` is opt-in.\n */\n readonly promptCaching: boolean\n /** Cache breakpoint lifetime; unset defers to this API's own default. */\n readonly promptCachingTtl?: '5m' | '1h'\n}\n\nconst DEFAULT_DIALECT: AnthropicDialect = Object.freeze({\n reasoningFormat: 'output-config' as const,\n budgets: DEFAULT_THINKING_BUDGETS,\n version: ANTHROPIC_VERSION,\n beta: Object.freeze([]),\n promptCaching: false,\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, {\n reasoningFormat: dialect.reasoningFormat,\n budgets: dialect.budgets,\n ...(dialect.thinking === undefined ? {} : { thinking: dialect.thinking }),\n promptCaching: dialect.promptCaching,\n ...(dialect.promptCachingTtl === undefined ? {} : { promptCachingTtl: dialect.promptCachingTtl }),\n })\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<ProtocolStreamChunk> => translateAnthropicStream(events, displayName),\n})\n\nexport type { ThinkingBudgets }\n"],"mappings":";;;;;;;;AAqEA,MAAa,qBAAqB;;;;AC9DlC,SAAgB,iBAAiB,OAAqD;CACpF,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,QAAQ;CACd,IAAI,MAAM,SAAS,cAAc,MAAM,SAAS,qBAAqB,OAAO;CAC5E,OAAO;EACL,MAAM,MAAM;EACZ,GAAG,OAAO,MAAM,cAAc,WAAW,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;EAC3E,GAAG,OAAO,MAAM,SAAS,WAAW,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;CAC9D;AACF;AAEA,SAAgB,YAAY,QAAsC;CAChE,IAAI,OAAO,SAAS,OAAO,OAAO;EAAE,MAAM;EAAO,KAAK,OAAO;CAAI;CACjE,IAAI,OAAO,SAAS,UAClB,OAAO;EAAE,MAAM;EAAU,YAAY,OAAO;EAAW,MAAM,OAAO;CAAK;CAE3E,MAAM,IAAI,WACR,sEACA,kBAAkB,eACpB;AACF;AAEA,SAAgB,eAAe,Q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":[],"sources":["../src/serialize-types.ts","../src/request-blocks.ts","../src/serialize-options.ts","../src/serialize.ts","../src/stream-blocks.ts","../src/stream-usage.ts","../src/stream-events.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["/**\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\n/** How a reasoning effort becomes a thinking token budget, for `reasoningFormat: 'thinking-budget'`. */\nexport type ThinkingBudgets = Readonly<Record<string, number>>\n\n/** Which field carries reasoning effort on the wire. */\nexport type AnthropicReasoningFormat = 'output-config' | 'thinking-budget'\n\n/** Options controlling how the request is built. */\nexport interface AnthropicSerializeOptions {\n /**\n * `'output-config'` (default, current models): effort is pass-through —\n * sent verbatim as `output_config.effort`, exactly what the caller gave.\n * `'thinking-budget'` (older models, or a gateway that only understands a\n * token budget): effort is looked up in `budgets` and converted to\n * `thinking.budget_tokens` instead — the SDK does the conversion because the\n * endpoint has no `effort` field to receive the raw string at all.\n */\n reasoningFormat?: AnthropicReasoningFormat\n /** Effort id to thinking-token budget; only consulted under `'thinking-budget'`. */\n budgets: ThinkingBudgets\n /**\n * Extended-thinking mode, sent only when set — omission means \"say nothing\",\n * which is this API's own way of leaving the model's default behavior alone.\n * Ignored under `'thinking-budget'`, which derives `thinking` from the effort instead.\n */\n thinking?: 'adaptive' | 'disabled'\n /**\n * Mark the stable prefix of one request as a cache breakpoint: the system\n * prompt, the last tool definition (if any), and every message but the\n * newest — up to 3 of this API's 4-breakpoint ceiling, leaving one spare.\n * A conversation resending its whole history on every turn (this API is\n * stateless) pays full price for that history without this; with it, a\n * later turn reads the unchanged prefix at a steep discount instead of\n * paying to reprocess it.\n *\n * Off by default: not every account or Anthropic-COMPATIBLE gateway\n * behind this same adapter understands `cache_control`, and a route that\n * doesn't should not silently be asked to. See `dialectOf()` in\n * `provider-anthropic/src/adapter.ts` for the live-discovered fallback\n * that turns this off automatically, permanently, the first time a\n * gateway rejects it.\n */\n promptCaching?: boolean\n /** Cache breakpoint lifetime. Defaults to this API's own default (5 minutes). */\n promptCachingTtl?: '5m' | '1h'\n}\n\n/**\n * Last-resort `max_tokens`, used only when neither the caller, the model, nor\n * the route names one. This API rejects a request that omits the field\n * entirely, unlike most others — see {@link serializeAnthropicRequest}.\n */\nexport const DEFAULT_MAX_TOKENS = 8_192\n\n","import { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ContentBlock, DocumentSource, ImageSource } from '@alvin0/ai-agent-sdk-core'\nimport type {\n WireDocumentSource, WireImageSource, WireCitation, WireRequestBlock, WireToolResultContent,\n} from './wire.ts'\nimport type { AnthropicReasoningState } from './serialize-types.ts'\n\nexport function 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\nexport function 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\nexport function 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\nexport function 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\nexport function 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\nexport function 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\nexport function 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\nexport function requestBlocks(block: ContentBlock): WireRequestBlock[] {\n switch (block.type) {\n case 'text': return textBlocks(block)\n case 'image':\n return [{ type: 'image', source: imageSource(block.source) }]\n case 'document': return documentBlocks(block)\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': return reasoningBlocks(block)\n default:\n return []\n }\n}\n\nfunction textBlocks(block: Extract<ContentBlock, { type: 'text' }>): WireRequestBlock[] {\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\n\nfunction documentBlocks(block: Extract<ContentBlock, { type: 'document' }>): WireRequestBlock[] {\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\n\nfunction reasoningBlocks(block: Extract<ContentBlock, { type: 'reasoning' }>): WireRequestBlock[] {\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","import {\n isNativeToolSchema, type ModelOutputFormat, type ModelToolSchema, type NativeWebSearchTool,\n type ToolChoice, type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type { WireCacheControl, WireOutputConfig, WireThinking, WireTool, WireToolChoice } from './wire.ts'\nimport type { ThinkingBudgets, AnthropicSerializeOptions, AnthropicReasoningFormat } from './serialize-types.ts'\n\nexport function 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\nexport function functionTool(tool: ToolSchema): WireTool {\n return { name: tool.name, description: tool.description, input_schema: tool.parameters }\n}\n\nexport function nativeToolName(name: string): string {\n if (name === 'web-search') return 'web_search'\n return name.replaceAll('-', '_')\n}\n\nexport function webSearchTool(tool: NativeWebSearchTool): WireTool {\n if (tool.searchContentTypes?.includes('image') === true) {\n throw new ModelError('Anthropic web search does not return images', MODEL_ERROR_CODES.INVALID_REQUEST)\n }\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\nexport function 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\nexport function thinkingFromBudget(\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\nexport function outputConfig(\n format: ModelOutputFormat | undefined,\n effort: string | undefined,\n): WireOutputConfig | undefined {\n const formatPart = format === undefined || format.type === 'text'\n ? undefined\n : { type: 'json_schema' as const, schema: format.schema }\n if (formatPart === undefined && effort === undefined) return undefined\n return {\n ...(formatPart === undefined ? {} : { format: formatPart }),\n ...(effort === undefined ? {} : { effort }),\n }\n}\n\nexport function cacheControlOf(options: AnthropicSerializeOptions): WireCacheControl | undefined {\n if (options.promptCaching !== true) return undefined\n return { type: 'ephemeral', ...(options.promptCachingTtl === undefined ? {} : { ttl: options.promptCachingTtl }) }\n}\n\nexport function toolsOf(request: ProtocolRequest, cacheControl: WireCacheControl | undefined): WireTool[] | undefined {\n const tools = request.options.tools\n if (tools === undefined || tools.length === 0) return undefined\n const result = tools.map(toolOf)\n if (cacheControl !== undefined) {\n const lastTool = result.at(-1)\n if (lastTool !== undefined) lastTool.cache_control = cacheControl\n }\n return result\n}\n\nexport function reasoningOptions(\n request: ProtocolRequest, options: AnthropicSerializeOptions, maxTokens: number,\n) {\n const reasoningFormat = options.reasoningFormat ?? 'output-config'\n const effort = request.options.reasoningEffort === undefined ? undefined : String(request.options.reasoningEffort)\n const thinking = thinkingOf(reasoningFormat, { options, effort, maxTokens })\n const output = outputConfig(request.options.outputFormat, reasoningFormat === 'output-config' ? effort : undefined)\n return {\n ...thinking === undefined ? {} : { thinking },\n ...output === undefined ? {} : { output_config: output },\n }\n}\n\nfunction thinkingOf(\n format: AnthropicReasoningFormat,\n context: { options: AnthropicSerializeOptions; effort: string | undefined; maxTokens: number },\n): WireThinking | undefined {\n const { options, effort, maxTokens } = context\n if (format === 'thinking-budget') return thinkingFromBudget(effort, maxTokens, options.budgets)\n if (options.thinking === undefined) return undefined\n return options.thinking === 'adaptive' ? { type: 'adaptive' } : { type: 'disabled' }\n}\n\nexport function samplingOptions(request: ProtocolRequest) {\n const call = request.options\n return {\n ...call.temperature === undefined ? {} : { temperature: call.temperature },\n ...call.topP === undefined ? {} : { top_p: call.topP },\n ...call.stop === undefined || call.stop.length === 0 ? {} : { stop_sequences: [...call.stop] },\n }\n}\n","/**\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 type { ContentBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { Message } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type { WireCacheControl, WireMessage, WireRequest, WireSystemBlock } from './wire.ts'\nexport { DEFAULT_MAX_TOKENS } from './serialize-types.ts'\nexport type { AnthropicReasoningState, ThinkingBudgets, AnthropicReasoningFormat, AnthropicSerializeOptions }\n from './serialize-types.ts'\nimport { DEFAULT_MAX_TOKENS, type AnthropicSerializeOptions } from './serialize-types.ts'\nimport { requestBlocks } from './request-blocks.ts'\nimport { cacheControlOf, toolsOf, toolChoiceOf, samplingOptions, reasoningOptions } from './serialize-options.ts'\n\nfunction messagesOf(\n messages: readonly Message[],\n cacheControl: WireCacheControl | undefined,\n): 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 markMessageCache(result, cacheControl)\n return result\n}\n\nfunction markMessageCache(messages: WireMessage[], cacheControl: WireCacheControl | undefined): void {\n if (cacheControl !== undefined && messages.length >= 2) {\n const boundary = messages[messages.length - 2]\n const lastBlock = boundary?.content.at(-1)\n if (lastBlock !== undefined) lastBlock.cache_control = cacheControl\n }\n}\n\n\nfunction systemOf(\n request: ProtocolRequest,\n cacheControl: WireCacheControl | undefined,\n): string | WireSystemBlock[] | 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 if (joined.length === 0) return undefined\n if (cacheControl === undefined) return joined\n return [{ type: 'text', text: joined, cache_control: cacheControl }]\n}\n\nexport function serializeAnthropicRequest(\n request: ProtocolRequest, options: AnthropicSerializeOptions,\n): WireRequest {\n const { options: call } = request\n const cacheControl = cacheControlOf(options)\n const system = systemOf(request, cacheControl)\n const tools = toolsOf(request, cacheControl)\n const maxTokens = request.maxTokens ?? DEFAULT_MAX_TOKENS\n return {\n model: call.model, max_tokens: maxTokens,\n messages: messagesOf(call.messages, cacheControl),\n ...system === undefined ? {} : { system },\n ...tools === undefined ? {} : { tools },\n ...call.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(call.toolChoice) },\n ...samplingOptions(request),\n ...reasoningOptions(request, options, maxTokens),\n stream: true,\n }\n}\n","import { 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 { AnthropicReasoningState } from './serialize.ts'\nimport type { WireCitation, WireServerToolUseBlock, WireWebSearchToolResultBlock } from './wire.ts'\n\nexport type BlockKind = 'text' | 'reasoning' | 'tool-call' | 'native-tool-call'\n\nexport interface 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\nexport function 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\nexport function 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': return closedReasoning(open)\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': return closedNativeTool(open)\n default:\n return undefined\n }\n}\n\nexport function 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\nexport function 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\nfunction closedReasoning(open: OpenBlock): ContentBlock {\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\nfunction closedNativeTool(open: OpenBlock): ContentBlock {\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","import { MODEL_ERROR_CODES } from '@alvin0/ai-agent-sdk-core'\nimport type { FinishReason, UsageCounters } from '@alvin0/ai-agent-sdk-core'\nimport type { WireStopReason, WireUsage } from './wire.ts'\n\nexport interface UsageAccumulator {\n input: unknown\n output: unknown\n cacheRead: unknown\n cacheWrite: unknown\n seen: boolean\n}\n\nexport function 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\nexport function 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 ...omittedCacheCounter(accumulated.cacheRead)\n ? {} : { cacheReadTokens: accumulated.cacheRead },\n ...omittedCacheCounter(accumulated.cacheWrite)\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\nexport function validUsageCounter(value: unknown): value is number {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0\n}\n\nexport function 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\nfunction omittedCacheCounter(value: unknown): boolean { return value === undefined || value === 0 }\n","import {\n CONTEXT_WINDOW_EXCEEDED_CODE, MODEL_ERROR_CODES, ModelError, QUOTA_EXCEEDED_CODE,\n isContextWindowExceededError, isQuotaExceededError,\n} from '@alvin0/ai-agent-sdk-core'\nimport { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolStreamChunk } from './contract.ts'\nimport type { WireStopReason, WireStreamEvent } from './wire.ts'\nimport { blockKind, closedBlock, citationAnnotation, type OpenBlock } from './stream-blocks.ts'\nimport { absorbUsage, finalUsage, finishReason, type UsageAccumulator } from './stream-usage.ts'\n\nexport interface StreamState {\n open: Map<number, OpenBlock>\n usage: UsageAccumulator\n stop: WireStopReason | null | undefined\n emittedBlocks: number\n}\n\nexport function* translateEvent(\n state: StreamState, event: WireStreamEvent, displayName: string,\n): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'message_start': yield* messageStart(state, event); return\n case 'content_block_start': yield* contentStart(state, event); return\n case 'content_block_delta': yield* contentDelta(state, event); return\n case 'content_block_stop': yield* contentStop(state, event); return\n case 'message_delta': yield* messageDelta(state, event); return\n case 'message_stop': yield* messageStop(state, displayName); return\n case 'error': yield* streamError(event, displayName); return\n default: return\n }\n}\n\nfunction* messageStart(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'message_start' }>,\n): Generator<ProtocolStreamChunk> {\n absorbUsage(state.usage, event.message.usage)\n const progress = finalUsage(state.usage)\n if (progress !== undefined) yield { type: 'usage-progress', usage: progress }\n}\n\nfunction* contentStart(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'content_block_start' }>,\n): Generator<ProtocolStreamChunk> {\n if (event.content_block.type === 'web_search_tool_result') {\n yield* webSearchResult(state, event)\n return\n }\n const kind = blockKind(event.content_block.type)\n if (kind === undefined) return\n const block = event.content_block\n const entry: OpenBlock = {\n kind,\n text: initialText(block),\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 state.open.set(event.index, entry)\n state.emittedBlocks += 1\n yield { type: 'block-start', index: event.index, blockType: kind }\n}\n\nfunction* contentDelta(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'content_block_delta' }>,\n): Generator<ProtocolStreamChunk> {\n const entry = state.open.get(event.index)\n if (entry === undefined) return\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 return\n case 'thinking_delta':\n entry.text += delta.thinking\n yield { type: 'reasoning-delta', index: event.index, text: delta.thinking }\n return\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 return\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 return\n case 'citations_delta': {\n const annotation = citationAnnotation(delta.citation)\n if (annotation !== undefined) entry.annotations.push(annotation)\n return\n }\n default:\n return\n }\n}\n\nfunction* contentStop(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'content_block_stop' }>,\n): Generator<ProtocolStreamChunk> {\n const entry = state.open.get(event.index)\n if (entry === undefined) return\n if (entry.kind === 'native-tool-call') return\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}\n\nfunction* messageDelta(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'message_delta' }>,\n): Generator<ProtocolStreamChunk> {\n state.stop = event.delta.stop_reason\n absorbUsage(state.usage, event.usage)\n const progress = finalUsage(state.usage)\n if (progress !== undefined) yield { type: 'usage-progress', usage: progress }\n}\n\nfunction* messageStop(\n state: StreamState, displayName: string,\n): Generator<ProtocolStreamChunk> {\n for (const [index, entry] of state.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(state.usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n if (state.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(state.stop) }\n}\n\nfunction* streamError(\n event: Extract<WireStreamEvent, { type: 'error' }>, displayName: string,\n): Generator<ProtocolStreamChunk> {\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\nfunction initialText(block: Extract<WireStreamEvent, { type: 'content_block_start' }>['content_block']): string {\n if (block.type === 'text') return block.text\n if (block.type === 'thinking') return block.thinking\n return ''\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\nfunction* webSearchResult(\n state: StreamState, event: Extract<WireStreamEvent, { type: 'content_block_start' }>,\n): Generator<ProtocolStreamChunk> {\n if (event.content_block.type !== 'web_search_tool_result') return\n const result = event.content_block\n const owner = [...state.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: [...state.open.entries()].find(([, entry]) => entry === owner)?.[0] ?? event.index,\n block,\n }\n }\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 { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type { WireStreamEvent } from './wire.ts'\nimport { translateEvent, type StreamState } from './stream-events.ts'\n\nexport async function* translateAnthropicStream(\n events: AsyncIterable<ProtocolSseEvent>, displayName: string,\n): AsyncGenerator<ProtocolStreamChunk> {\n const state: StreamState = {\n open: new Map(), emittedBlocks: 0, stop: undefined,\n usage: { input: undefined, output: undefined, cacheRead: undefined, cacheWrite: undefined, seen: false },\n }\n for await (const raw of events) {\n const event = parseEvent(raw, displayName)\n yield* translateEvent(state, event, displayName)\n if (event.type === 'message_stop') return\n }\n throw new ModelError(\n `${displayName} stream ended before message_stop`,\n MODEL_ERROR_CODES.STREAM_CLOSED,\n )\n}\n\nfunction parseEvent(raw: ProtocolSseEvent, displayName: string): WireStreamEvent {\n try { return 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, { cause: error },\n )\n }\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 AnthropicReasoningFormat, 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 /**\n * Which field carries reasoning effort. `'output-config'` (default) is pure\n * pass-through — the caller's effort string reaches `output_config.effort`\n * unchanged, current GA behavior. `'thinking-budget'` is for an older model\n * or a gateway that only understands a token budget: the SDK converts effort\n * to `thinking.budget_tokens` using `budgets` instead of sending it raw.\n */\n readonly reasoningFormat: AnthropicReasoningFormat\n /** Effort id to thinking-token budget; only consulted under `'thinking-budget'`. */\n readonly budgets: ThinkingBudgets\n /**\n * Extended-thinking mode, sent only when set. Independent of effort under\n * `'output-config'` — omission leaves the model's own default thinking\n * behavior alone rather than the SDK guessing one.\n */\n readonly thinking?: 'adaptive' | 'disabled'\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 * Marks the stable prefix (system, tools, everything but the newest\n * message) as a cache breakpoint. See `AnthropicSerializeOptions`'s doc\n * comment in `serialize.ts` for why, and off by default for the same\n * \"not every gateway understands this\" reason `reasoningFormat` is opt-in.\n */\n readonly promptCaching: boolean\n /** Cache breakpoint lifetime; unset defers to this API's own default. */\n readonly promptCachingTtl?: '5m' | '1h'\n}\n\nconst DEFAULT_DIALECT: AnthropicDialect = Object.freeze({\n reasoningFormat: 'output-config' as const,\n budgets: DEFAULT_THINKING_BUDGETS,\n version: ANTHROPIC_VERSION,\n beta: Object.freeze([]),\n promptCaching: false,\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, {\n reasoningFormat: dialect.reasoningFormat,\n budgets: dialect.budgets,\n ...(dialect.thinking === undefined ? {} : { thinking: dialect.thinking }),\n promptCaching: dialect.promptCaching,\n ...(dialect.promptCachingTtl === undefined ? {} : { promptCachingTtl: dialect.promptCachingTtl }),\n })\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<ProtocolStreamChunk> => translateAnthropicStream(events, displayName),\n})\n\nexport type { ThinkingBudgets }\n"],"mappings":";;;;;;;;AAqEA,MAAa,qBAAqB;;;;AC9DlC,SAAgB,iBAAiB,OAAqD;CACpF,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,QAAQ;CACd,IAAI,MAAM,SAAS,cAAc,MAAM,SAAS,qBAAqB,OAAO;CAC5E,OAAO;EACL,MAAM,MAAM;EACZ,GAAG,OAAO,MAAM,cAAc,WAAW,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;EAC3E,GAAG,OAAO,MAAM,SAAS,WAAW,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;CAC9D;AACF;AAEA,SAAgB,YAAY,QAAsC;CAChE,IAAI,OAAO,SAAS,OAAO,OAAO;EAAE,MAAM;EAAO,KAAK,OAAO;CAAI;CACjE,IAAI,OAAO,SAAS,UAClB,OAAO;EAAE,MAAM;EAAU,YAAY,OAAO;EAAW,MAAM,OAAO;CAAK;CAE3E,MAAM,IAAI,WACR,sEACA,kBAAkB,eACpB;AACF;AAEA,SAAgB,eAAe,QAA4C;CACzE,IAAI,OAAO,SAAS,OAAO,OAAO;EAAE,MAAM;EAAO,KAAK,OAAO;CAAI;CACjE,IAAI,OAAO,SAAS,QAAQ,OAAO;EAAE,MAAM;EAAQ,SAAS,OAAO;CAAO;CAC1E,OAAO;EAAE,MAAM;EAAU,YAAY,OAAO;EAAW,MAAM,OAAO;CAAK;AAC3E;AAEA,SAAgB,kBAAkB,QAAmE;CACnG,MAAM,QAAiC,CAAC;CACxC,IAAI,WAAW;CACf,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,SAAS,QAAQ,MAAM,KAAK;EAAE,MAAM;EAAQ,MAAM,MAAM;CAAK,CAAC;MACnE,IAAI,MAAM,SAAS,SAAS;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AChCA,MAAa,iCAAiC;;;;;;;;AAS9C,MAAa,oBAAoB;;;;;;;;AASjC,MAAa,2BAA4C,OAAO,OAAO;CACrE,KAAK;CACL,KAAK;CACL,QAAQ;CACR,MAAM;AACR,CAAC;AAmCD,MAAM,kBAAoC,OAAO,OAAO;CACtD,iBAAiB;CACjB,SAAS;CACT,SAAS;CACT,MAAM,OAAO,OAAO,CAAC,CAAC;CACtB,eAAe;AACjB,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;EAQhG,OAPsB,0BAA0B,SAAS;GACvD,iBAAiB,QAAQ;GACzB,SAAS,QAAQ;GACjB,GAAI,QAAQ,aAAa,SAAY,CAAC,IAAI,EAAE,UAAU,QAAQ,SAAS;GACvE,eAAe,QAAQ;GACvB,GAAI,QAAQ,qBAAqB,SAAY,CAAC,IAAI,EAAE,kBAAkB,QAAQ,iBAAiB;EACjG,CACU;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.11",
7
+ "version": "0.1.13",
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.11"
41
+ "@alvin0/ai-agent-sdk-core": "^0.1.13"
42
42
  },
43
43
  "devDependencies": {
44
- "@alvin0/ai-agent-sdk-core": "^0.1.11",
44
+ "@alvin0/ai-agent-sdk-core": "^0.1.13",
45
45
  "@arethetypeswrong/cli": "0.18.5",
46
46
  "playwright": "1.62.1",
47
47
  "publint": "0.3.24",