@alvin0/ai-agent-sdk-protocol-responses 0.1.14 → 0.1.15
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 +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -467,7 +467,7 @@ function mapUsage(usage) {
|
|
|
467
467
|
...omittedCounter(cacheWrite) ? {} : { cacheWriteTokens: cacheWrite },
|
|
468
468
|
...omittedCounter(reasoning) ? {} : { reasoningTokens: reasoning }
|
|
469
469
|
};
|
|
470
|
-
if (rawInput !== void 0) normalized.inputTokens = disjointInput(rawInput, cacheRead);
|
|
470
|
+
if (rawInput !== void 0) normalized.inputTokens = disjointInput(rawInput, cacheRead, cacheWrite);
|
|
471
471
|
return normalized;
|
|
472
472
|
}
|
|
473
473
|
function recordOrUndefined(value) {
|
|
@@ -476,8 +476,8 @@ function recordOrUndefined(value) {
|
|
|
476
476
|
function omittedCounter(value) {
|
|
477
477
|
return value === void 0 || value === 0;
|
|
478
478
|
}
|
|
479
|
-
function disjointInput(rawInput, cacheRead) {
|
|
480
|
-
return typeof rawInput === "number" && (cacheRead === void 0 || typeof cacheRead === "number") ? rawInput - (cacheRead ?? 0) : rawInput;
|
|
479
|
+
function disjointInput(rawInput, cacheRead, cacheWrite) {
|
|
480
|
+
return typeof rawInput === "number" && (cacheRead === void 0 || typeof cacheRead === "number") && (cacheWrite === void 0 || typeof cacheWrite === "number") ? rawInput - (cacheRead ?? 0) - (cacheWrite ?? 0) : rawInput;
|
|
481
481
|
}
|
|
482
482
|
function reasoningCounter(source) {
|
|
483
483
|
return recordOrUndefined(source.output_tokens_details)?.reasoning_tokens;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["textAnnotations"],"sources":["../src/request-content.ts","../src/request-messages.ts","../src/serialize-options.ts","../src/serialize.ts","../src/stream-items.ts","../src/stream-usage.ts","../src/stream-errors.ts","../src/stream-events.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["import type {\n ContentBlock, DocumentBlock, ImageBlock, NativeToolCallBlock, TextBlock,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { WireContentPart, WireInputItem } from './wire.ts'\nimport type { ResponsesReasoningState } from './serialize-types.ts'\n\nconst DEFAULT_DOCUMENT_FILENAME = 'document.pdf'\n\nexport function reasoningStateOf(value: unknown): ResponsesReasoningState {\n if (typeof value !== 'object' || value === null) return {}\n const state = value as ResponsesReasoningState\n return {\n ...typeof state.id === 'string' ? { id: state.id } : {},\n ...typeof state.encryptedContent === 'string'\n ? { encryptedContent: state.encryptedContent }\n : {},\n ...Array.isArray(state.summary) ? { summary: state.summary } : {},\n }\n}\n\nexport function textAnnotations(block: TextBlock) {\n return block.annotations?.flatMap(annotation => annotation.type === 'url-citation'\n ? [{\n type: 'url_citation' as const,\n url: annotation.url,\n ...annotation.title === undefined ? {} : { title: annotation.title },\n ...annotation.startIndex === undefined ? {} : { start_index: annotation.startIndex },\n ...annotation.endIndex === undefined ? {} : { end_index: annotation.endIndex },\n }]\n : [])\n}\n\nexport function imagePart(block: ImageBlock): WireContentPart {\n const detail = block.detail\n if (block.source.kind === 'file') {\n return { type: 'input_image', file_id: block.source.fileId, ...detail === undefined ? {} : { detail } }\n }\n const image_url = block.source.kind === 'url'\n ? block.source.url\n : `data:${block.source.mediaType};base64,${block.source.data}`\n return { type: 'input_image', image_url, ...detail === undefined ? {} : { detail } }\n}\n\nexport function documentPart(block: DocumentBlock): WireContentPart {\n if (block.source.kind === 'file') return { type: 'input_file', file_id: block.source.fileId }\n if (block.source.kind === 'url') return { type: 'input_file', file_url: block.source.url }\n return {\n type: 'input_file',\n // The API reads the file type from the extension here, so a name is required\n // rather than optional; a neutral default beats a rejected request.\n filename: block.filename ?? DEFAULT_DOCUMENT_FILENAME,\n file_data: `data:${block.source.mediaType};base64,${block.source.data}`,\n }\n}\n\nexport function contentPart(block: ContentBlock, role: 'user' | 'assistant'): WireContentPart | undefined {\n if (block.type === 'text') {\n // An assistant turn's own text must come back as `output_text`; sending it as\n // `input_text` would present the model's prior words as if the user said them.\n if (role !== 'assistant') return { type: 'input_text', text: block.text }\n const annotations = textAnnotations(block)\n return {\n type: 'output_text', text: block.text,\n ...annotations === undefined ? {} : { annotations },\n }\n }\n if (block.type === 'image') return imagePart(block)\n if (block.type === 'document') return documentPart(block)\n return undefined\n}\n\nexport function toolResultOutput(blocks: readonly ContentBlock[]): string | WireContentPart[] {\n const hasBinary = blocks.some(block => block.type === 'image' || block.type === 'document')\n if (!hasBinary) {\n // The common case. A plain string keeps the payload small and is what the\n // API documents first.\n return blocks\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n .join('\\n')\n }\n return blocks\n .map(block => contentPart(block, 'user'))\n .filter((part): part is WireContentPart => part !== undefined)\n}\n\nexport function nativeReplayItem(block: NativeToolCallBlock): WireInputItem | undefined {\n const value = block.providerState\n if (typeof value !== 'object' || value === null) return undefined\n const item = value as Record<string, unknown>\n if (item.type === 'web_search_call') {\n return {\n type: 'web_search_call',\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...item.action === undefined ? {} : { action: structuredClone(item.action) },\n }\n }\n if (item.type === 'image_generation_call') return imageReplayItem(item, generatedImage(block))\n return undefined\n}\n\n/** The generated image, as base64; histories recorded before it moved there keep it in the item. */\nfunction generatedImage(block: NativeToolCallBlock): string | undefined {\n const image = block.content.find(content => content.type === 'image' && content.source.kind === 'base64')\n return image?.type === 'image' && image.source.kind === 'base64' ? image.source.data : undefined\n}\n\nfunction imageReplayItem(item: Record<string, unknown>, image: string | undefined): WireInputItem {\n const result = image ?? item.result\n return {\n type: 'image_generation_call',\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...typeof result === 'string' || result === null ? { result } : {},\n }\n}\n","import type { ContentBlock, TextBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { Message } from '@alvin0/ai-agent-sdk-core'\nimport type { WireContentPart, WireInputItem } from './wire.ts'\nimport type { ResponsesReasoningState } from './serialize-types.ts'\nimport { contentPart, reasoningStateOf, toolResultOutput, nativeReplayItem } from './request-content.ts'\n\ninterface MessageState {\n role: 'user' | 'assistant'\n parts: WireContentPart[]\n phase: TextBlock['phase']\n items: WireInputItem[]\n dialectMessagePhase: boolean\n}\n\n/** Flush content at standalone-item boundaries to preserve conversation order. */\nexport function appendMessage(message: Message, items: WireInputItem[], dialectMessagePhase: boolean): void {\n const state: MessageState = {\n role: message.role === 'assistant' ? 'assistant' : 'user', parts: [], phase: undefined,\n items, dialectMessagePhase,\n }\n for (const block of message.content) {\n if (block.type === 'text' || block.type === 'image' || block.type === 'document') appendContent(block, state)\n else appendControl(block, state)\n }\n flushMessage(state)\n}\n\nfunction flushMessage(state: MessageState): void {\n if (state.parts.length === 0) return\n state.items.push({\n type: 'message', role: state.role, content: state.parts,\n ...state.role === 'assistant' && state.dialectMessagePhase && state.phase !== undefined\n ? { phase: state.phase === 'final-answer' ? 'final_answer' as const : state.phase } : {},\n })\n state.parts = []\n state.phase = undefined\n}\n\nfunction appendContent(block: ContentBlock, state: MessageState): void {\n if (block.type === 'text' && block.phase !== undefined && state.phase !== undefined && state.phase !== block.phase) {\n flushMessage(state)\n }\n if (block.type === 'text' && block.phase !== undefined) state.phase = block.phase\n const part = contentPart(block, state.role)\n if (part !== undefined) state.parts.push(part)\n}\n\nfunction appendControl(block: ContentBlock, state: MessageState): void {\n switch (block.type) {\n case 'reasoning':\n flushMessage(state)\n appendReasoning(block, state.items)\n return\n case 'tool-call':\n flushMessage(state)\n state.items.push({ type: 'function_call', call_id: block.id, name: block.name,\n arguments: block.arguments.length > 0 ? block.arguments : '{}' })\n return\n case 'tool-result':\n flushMessage(state)\n state.items.push({ type: 'function_call_output', call_id: block.toolCallId,\n output: toolResultOutput(block.content) })\n return\n case 'native-tool-call': {\n flushMessage(state)\n const replay = nativeReplayItem(block)\n if (replay !== undefined) state.items.push(replay)\n return\n }\n default: return\n }\n}\n\nfunction appendReasoning(block: Extract<ContentBlock, { type: 'reasoning' }>, items: WireInputItem[]): void {\n const state = reasoningStateOf(block.providerState)\n // Unfinished reasoning has no replay identity and cannot be sent back.\n if (state.id === undefined && state.encryptedContent === undefined) return\n const summary = reasoningSummary(state, block.text)\n items.push({\n type: 'reasoning',\n ...state.id === undefined ? {} : { id: state.id },\n summary: summary.map(text => ({ type: 'summary_text' as const, text })),\n ...state.encryptedContent === undefined ? {} : { encrypted_content: state.encryptedContent },\n })\n}\n\nfunction reasoningSummary(state: ResponsesReasoningState, text: string): readonly string[] {\n if (state.summary !== undefined && state.summary.length > 0) return state.summary\n return text.length > 0 ? [text] : []\n}\n","import type { ProtocolRequest } from './contract.ts'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport {\n isNativeToolSchema, type ModelOutputFormat, type ModelToolSchema, type NativeImageGenerationTool,\n type NativeWebSearchTool, type ToolChoice, type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ResponsesDialect, WireTool, WireToolChoice, WireTextControls } from './wire.ts'\n\nexport function toolChoiceOf(choice: ToolChoice): WireToolChoice {\n if (typeof choice === 'string') return choice\n if (choice.type === 'native') return { type: nativeWireType(choice.name) }\n return { type: 'function', name: choice.name }\n}\n\nexport function functionTool(tool: ToolSchema): WireTool {\n return {\n type: 'function',\n name: tool.name,\n description: tool.description,\n // Strict mode imposes real JSON-Schema restrictions (no optional fields\n // without null, `additionalProperties: false` required). Opting a caller's\n // schema in silently would turn a working tool into a request rejection.\n strict: false,\n parameters: tool.parameters,\n }\n}\n\nexport function nativeWireType(name: string): string {\n if (name === 'web-search') return 'web_search'\n if (name === 'image-generation') return 'image_generation'\n return name.replaceAll('-', '_')\n}\n\nexport function webSearchTool(tool: NativeWebSearchTool): WireTool {\n if (tool.blockedDomains !== undefined) {\n throw new ModelError(\n 'OpenAI Responses web search does not support blockedDomains; use allowedDomains',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n if (tool.maxUses !== undefined) {\n throw new ModelError(\n 'OpenAI Responses web search does not support maxUses',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n type: 'web_search',\n ...tool.searchContextSize === undefined ? {} : { search_context_size: tool.searchContextSize },\n ...tool.allowedDomains === undefined ? {} : { filters: { allowed_domains: [...tool.allowedDomains] } },\n ...tool.userLocation === undefined ? {} : {\n user_location: { type: 'approximate', ...tool.userLocation },\n },\n ...tool.searchContentTypes === undefined ? {} : { search_content_types: [...tool.searchContentTypes] },\n }\n}\n\nexport function imageGenerationTool(tool: NativeImageGenerationTool): WireTool {\n return {\n type: 'image_generation',\n ...tool.size === undefined ? {} : { size: tool.size },\n ...tool.quality === undefined ? {} : { quality: tool.quality },\n ...tool.format === undefined ? {} : { output_format: tool.format },\n ...tool.background === undefined ? {} : { background: tool.background },\n ...tool.partialImages === undefined ? {} : { partial_images: tool.partialImages },\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 return imageGenerationTool(tool)\n}\n\nexport function textControls(\n format: ModelOutputFormat | undefined,\n dialect: ResponsesDialect,\n): WireTextControls | undefined {\n if (format === undefined) return undefined\n if (format.type === 'text') {\n return dialect.structuredOutputs ? { format: { type: 'text' } } : undefined\n }\n if (!dialect.structuredOutputs) {\n throw new ModelError(\n 'This Responses endpoint does not support JSON Schema output',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n format: {\n type: 'json_schema',\n name: format.name,\n schema: format.schema,\n strict: true,\n },\n }\n}\n\nexport function toolsOptions(request: ProtocolRequest) {\n const options = request.options\n const tools = options.tools === undefined || options.tools.length === 0 ? undefined : options.tools.map(toolOf)\n return {\n ...tools === undefined ? {} : { tools, parallel_tool_calls: true },\n ...options.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(options.toolChoice) },\n }\n}\n\nexport function reasoningOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const effort = request.options.reasoningEffort\n if (effort === undefined && dialect.reasoningSummary === undefined) return {}\n return { reasoning: {\n ...effort === undefined ? {} : { effort: String(effort) },\n ...dialect.reasoningSummary === undefined ? {} : { summary: dialect.reasoningSummary },\n } }\n}\n\nexport function dialectOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const text = textControls(request.options.outputFormat, dialect)\n return {\n ...text === undefined ? {} : { text },\n ...dialect.store === undefined ? {} : { store: dialect.store },\n ...dialect.include.length === 0 ? {} : { include: [...dialect.include] },\n ...dialect.promptCacheKey === undefined ? {} : { prompt_cache_key: dialect.promptCacheKey },\n ...dialect.maxOutputTokens && request.maxTokens !== undefined ? { max_output_tokens: request.maxTokens } : {},\n }\n}\n\nexport function samplingOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const options = request.options\n return {\n ...dialect.sampling && options.temperature !== undefined ? { temperature: options.temperature } : {},\n ...dialect.sampling && options.topP !== undefined ? { top_p: options.topP } : {},\n }\n}\n","/**\n * Normalized request to Responses API wire JSON.\n *\n * The interesting work is flattening. Our conversation is a list of messages,\n * each holding an ordered list of content blocks; the wire wants a FLAT list of\n * items where a tool result and a tool call are peers of a message rather than\n * parts of one. So one assistant message that reasoned, spoke, and called two\n * tools expands to four items, and their relative order must be preserved\n * because the model reads it as its own prior turn.\n *\n * @module ai-agent-sdk/providers/responses/serialize\n */\n\nimport type { ProtocolRequest } from './contract.ts'\nimport type { ContentBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { ResponsesDialect, WireInputItem, WireRequest } from './wire.ts'\nexport type { ResponsesReasoningState } from './serialize-types.ts'\nimport { appendMessage } from './request-messages.ts'\nimport { toolsOptions, reasoningOptions, dialectOptions, samplingOptions } from './serialize-options.ts'\n\nfunction instructionsOf(request: ProtocolRequest): string {\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 return all.join('\\n\\n')\n}\n\nexport function serializeResponsesRequest(request: ProtocolRequest, dialect: ResponsesDialect): WireRequest {\n const input: WireInputItem[] = []\n for (const message of request.options.messages) {\n if (message.role === 'system') continue\n appendMessage(message, input, dialect.messagePhase === true)\n }\n const instructions = instructionsOf(request)\n return {\n model: request.options.model,\n ...instructions.length === 0 ? {} : { instructions },\n input,\n ...toolsOptions(request),\n ...reasoningOptions(request, dialect),\n ...dialectOptions(request, dialect),\n ...samplingOptions(request, dialect),\n stream: true,\n }\n}\n","import { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport { isJsonValue } from '@alvin0/ai-agent-sdk-core'\nimport type {\n AssistantTextPhase, ContentBlock, ImageMediaType, ReasoningKind, TextAnnotation,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type { ResponsesReasoningState } from './serialize.ts'\nimport type { WireOutputItem } from './wire.ts'\n\nexport type ItemKind = 'text' | 'reasoning' | 'tool-call' | 'native-tool-call'\n\nexport interface OpenItem {\n readonly index: number\n readonly kind: ItemKind\n text: string\n args: string\n callId: string\n name: string\n nativeName: string\n /** Last `summary_index` seen, so a new paragraph gets a separator. */\n summaryIndex: number | undefined\n phase: AssistantTextPhase | undefined\n /**\n * Which reasoning stream filled `text`; `mixed` when both did, which leaves\n * the block unlabelled. The done item's summary still overrides it.\n */\n reasoningKind: ReasoningKind | 'mixed' | undefined\n}\n\nexport function textPhase(value: string | undefined): AssistantTextPhase | undefined {\n if (value === 'commentary') return 'commentary'\n if (value === 'final_answer') return 'final-answer'\n return undefined\n}\n\nexport function itemKind(type: string | undefined): ItemKind | undefined {\n switch (type) {\n case 'message': return 'text'\n case 'reasoning': return 'reasoning'\n case 'function_call': return 'tool-call'\n case 'web_search_call': return 'native-tool-call'\n case 'image_generation_call': return 'native-tool-call'\n default: return undefined\n }\n}\n\nexport function nativeName(type: string | undefined): string {\n if (type === 'web_search_call') return 'web-search'\n if (type === 'image_generation_call') return 'image-generation'\n return type?.replace(/_call$/, '').replaceAll('_', '-') ?? 'native-tool'\n}\n\nexport function textAnnotations(item: WireOutputItem): TextAnnotation[] {\n if (!Array.isArray(item.content)) return []\n return item.content.flatMap((part) => {\n if (typeof part !== 'object' || part === null) return []\n const annotations = (part as Record<string, unknown>).annotations\n if (!Array.isArray(annotations)) return []\n return annotations.flatMap((annotation): TextAnnotation[] => {\n if (typeof annotation !== 'object' || annotation === null) return []\n const record = annotation as Record<string, unknown>\n if (record.type !== 'url_citation' || typeof record.url !== 'string') return []\n return [{\n type: 'url-citation',\n url: record.url,\n ...typeof record.title === 'string' ? { title: record.title } : {},\n ...typeof record.start_index === 'number' ? { startIndex: record.start_index } : {},\n ...typeof record.end_index === 'number' ? { endIndex: record.end_index } : {},\n }]\n })\n })\n}\n\nexport function itemText(item: WireOutputItem): string {\n const content = item.content\n if (!Array.isArray(content)) return ''\n return content\n .map((part) => {\n if (typeof part !== 'object' || part === null) return ''\n const record = part as Record<string, unknown>\n return typeof record.text === 'string' ? record.text : ''\n })\n .join('')\n}\n\nexport function itemSummary(item: WireOutputItem): string[] {\n const summary = item.summary\n if (!Array.isArray(summary)) return []\n return summary\n .map((part) => {\n if (typeof part !== 'object' || part === null) return ''\n const record = part as Record<string, unknown>\n return typeof record.text === 'string' ? record.text : ''\n })\n .filter(text => text.length > 0)\n}\n\nexport function doneBlock(\n item: WireOutputItem, open: OpenItem, imageMediaType: ImageMediaType,\n): ContentBlock | undefined {\n switch (open.kind) {\n case 'text': return doneText(item, open)\n case 'reasoning': return doneReasoning(item, open)\n case 'tool-call': return doneTool(item, open)\n case 'native-tool-call': return doneNative(item, open, imageMediaType)\n default: return undefined\n }\n}\n\nfunction doneText(item: WireOutputItem, open: OpenItem): ContentBlock {\n const text = itemText(item)\n const phase = textPhase(item.phase) ?? open.phase\n return {\n type: 'text',\n text: text.length > 0 ? text : open.text,\n ...phase === undefined ? {} : { phase },\n ...textAnnotations(item).length === 0 ? {} : { annotations: textAnnotations(item) },\n }\n}\n\nfunction doneReasoning(item: WireOutputItem, open: OpenItem): ContentBlock {\n const summary = itemSummary(item)\n const state: ResponsesReasoningState = {\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.encrypted_content === 'string'\n ? { encryptedContent: item.encrypted_content }\n : {},\n ...summary.length > 0 ? { summary } : {},\n }\n const streamed = open.reasoningKind === 'mixed' ? undefined : open.reasoningKind\n const kind = summary.length > 0 ? 'summary' : streamed\n return {\n type: 'reasoning',\n text: summary.length > 0 ? summary.join('\\n\\n') : open.text,\n ...kind === undefined ? {} : { kind },\n providerState: state,\n }\n}\n\nfunction doneTool(item: WireOutputItem, open: OpenItem): ContentBlock {\n const args = typeof item.arguments === 'string' && item.arguments.length > 0\n ? item.arguments\n : open.args\n return {\n type: 'tool-call',\n id: ToolCallId(item.call_id ?? open.callId),\n name: item.name ?? open.name,\n arguments: args.length > 0 ? args : '{}',\n }\n}\n\nfunction doneNative(item: WireOutputItem, open: OpenItem, imageMediaType: ImageMediaType): ContentBlock {\n const content: ContentBlock[] = open.nativeName === 'image-generation'\n && typeof item.result === 'string' && item.result.length > 0\n ? [{\n type: 'image',\n source: { kind: 'base64', mediaType: imageMediaType, data: item.result },\n }]\n : []\n return {\n type: 'native-tool-call',\n id: item.id ?? open.callId,\n name: open.nativeName,\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...isJsonValue(item.action) ? { arguments: item.action } : {},\n content,\n // The image is kept once, as public content; replay reads it back from there.\n providerState: content.length > 0 ? withoutResult(item) : item,\n }\n}\n\nfunction withoutResult(item: WireOutputItem): WireOutputItem {\n const { result: _result, ...rest } = item\n return rest\n}\n\n\nexport function kindToBlockType(kind: ItemKind): 'text' | 'reasoning' | 'tool-call' | 'native-tool-call' {\n return kind\n}\n\nexport function requestedImageMediaType(request: ProtocolRequest | undefined): ImageMediaType {\n const tool = request?.options.tools?.find(candidate => 'type' in candidate\n && candidate.type === 'native'\n && candidate.name === 'image-generation')\n if (tool === undefined || !('format' in tool)) return 'image/png'\n if (tool.format === 'jpeg') return 'image/jpeg'\n if (tool.format === 'webp') return 'image/webp'\n return 'image/png'\n}","import type { UsageCounters } from '@alvin0/ai-agent-sdk-core'\nimport type { WireUsage } from './wire.ts'\n\nexport function mapUsage(usage: WireUsage): UsageCounters | undefined {\n const source = usage as unknown as Record<string, unknown>\n const details = recordOrUndefined(source.input_tokens_details)\n const rawInput = source.input_tokens\n const outputTokens = source.output_tokens\n const cacheRead = details?.cached_tokens\n const cacheWrite = details?.cache_write_tokens\n const reasoning = reasoningCounter(source)\n const totalTokens = source.total_tokens\n const hasAny = [rawInput, outputTokens, cacheRead, cacheWrite, reasoning, totalTokens]\n .some(value => value !== undefined)\n if (!hasAny) return undefined\n\n const normalized: Record<string, unknown> = {\n ...outputTokens === undefined ? {} : { outputTokens },\n ...totalTokens === undefined ? {} : { totalTokens },\n // Omitted cache details are authoritative zero for Responses. Present\n // malformed values are retained for the accounting validator.\n ...omittedCounter(cacheRead) ? {} : { cacheReadTokens: cacheRead },\n ...omittedCounter(cacheWrite) ? {} : { cacheWriteTokens: cacheWrite },\n ...omittedCounter(reasoning) ? {} : { reasoningTokens: reasoning },\n }\n if (rawInput !== undefined) {\n normalized.inputTokens = disjointInput(rawInput, cacheRead)\n }\n return normalized as UsageCounters\n}\n\nfunction recordOrUndefined(value: unknown): Record<string, unknown> | undefined {\n return typeof value === 'object' && value !== null ? value as Record<string, unknown> : undefined\n}\n\nfunction omittedCounter(value: unknown): boolean { return value === undefined || value === 0 }\n\nfunction disjointInput(rawInput: unknown, cacheRead: unknown): unknown {\n return typeof rawInput === 'number' && (cacheRead === undefined || typeof cacheRead === 'number')\n ? rawInput - (cacheRead ?? 0) : rawInput\n}\n\nfunction reasoningCounter(source: Record<string, unknown>): unknown {\n return recordOrUndefined(source.output_tokens_details)?.reasoning_tokens\n}\n","import { CONTEXT_WINDOW_EXCEEDED_CODE, QUOTA_EXCEEDED_CODE } from '@alvin0/ai-agent-sdk-core'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { WireResponse } from './wire.ts'\n\nconst TERMINAL_ERROR_CODES: Readonly<Record<string, string>> = Object.freeze({\n context_length_exceeded: CONTEXT_WINDOW_EXCEEDED_CODE,\n insufficient_quota: QUOTA_EXCEEDED_CODE,\n invalid_prompt: MODEL_ERROR_CODES.INVALID_REQUEST,\n bio_policy: MODEL_ERROR_CODES.INVALID_REQUEST,\n cyber_policy: MODEL_ERROR_CODES.INVALID_REQUEST,\n misalignment_policy_violation: MODEL_ERROR_CODES.INVALID_REQUEST,\n rate_limit_exceeded: MODEL_ERROR_CODES.RATE_LIMIT,\n})\n\n\nexport function failedError(response: WireResponse | undefined, displayName: string): ModelError {\n const error = response?.error ?? undefined\n const code = error?.code ?? error?.type\n const message = error?.message ?? `${displayName} reported a failed response${failureContext(response, code)}`\n const mapped = code === undefined ? undefined : TERMINAL_ERROR_CODES[code]\n return new ModelError(\n message,\n // An unrecognized failure defaults to SERVER, which IS in the retryable set:\n // the request produced nothing, so repeating it is safe and often works.\n mapped ?? MODEL_ERROR_CODES.SERVER,\n {},\n )\n}\n\nfunction failureContext(response: WireResponse | undefined, code: string | undefined): string {\n const facts = [\n code === undefined ? 'no error detail' : `code ${code}`,\n ...typeof response?.id === 'string' && /^[\\w.:-]{1,128}$/.test(response.id) ? [`response ${response.id}`] : [],\n ...typeof response?.status === 'string' && /^[\\w-]{1,32}$/.test(response.status)\n ? [`status ${response.status}`] : [],\n ]\n return ` (${facts.join(', ')})`\n}","import type { WireOutputItem } from './wire.ts'\nimport type { ItemKind } from './stream-items.ts'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport type { ImageMediaType } from '@alvin0/ai-agent-sdk-core'\nimport type { FinishReason } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolStreamChunk } from './contract.ts'\nimport type { WireErrorBody, WireStreamEvent } from './wire.ts'\nimport { textPhase, itemKind, nativeName, kindToBlockType, doneBlock, type OpenItem } from './stream-items.ts'\nimport { mapUsage } from './stream-usage.ts'\nimport { failedError } from './stream-errors.ts'\n\nexport interface StreamState {\n open: Map<string, OpenItem>\n nextIndex: number\n sawToolCall: boolean\n imageMediaType: ImageMediaType\n}\n\nexport function* translateEvent(\n state: StreamState, event: WireStreamEvent, displayName: string,\n): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'response.output_item.added': yield* itemAdded(state, event); return\n case 'response.output_item.done': yield* itemDone(state, event); return\n case 'response.completed': yield* completed(state, event); return\n case 'response.incomplete': yield* incomplete(event, displayName); return\n case 'response.failed': yield* failed(event, displayName); return\n case 'error': yield* inlineError(event, displayName); return\n default: yield* deltaEvent(state, event); return\n }\n}\n\nfunction* itemAdded(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const item = event.item\n const id = item?.id ?? event.item_id\n const kind = itemKind(item?.type)\n if (item === undefined || id === undefined || kind === undefined) return\n if (state.open.has(id)) return\n const entry = createOpenItem(state, item, { id, kind })\n state.open.set(id, entry)\n if (kind === 'tool-call') state.sawToolCall = true\n yield { type: 'block-start', index: entry.index, blockType: kindToBlockType(kind) }\n}\n\nfunction* textDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.text += event.delta\n yield {\n type: 'text-delta', index: entry.index, text: event.delta,\n ...entry.phase === undefined ? {} : { phase: entry.phase },\n }\n}\n\nfunction* summaryDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n // A new summary paragraph starts; separate it from the previous one so the\n // assembled text does not run two thoughts together.\n const separator = entry.summaryIndex !== undefined\n && event.summary_index !== undefined\n && event.summary_index !== entry.summaryIndex\n ? '\\n\\n'\n : ''\n entry.summaryIndex = event.summary_index\n const text = `${separator}${event.delta}`\n entry.text += text\n entry.reasoningKind = mergeKind(entry.reasoningKind, 'summary')\n yield { type: 'reasoning-delta', index: entry.index, text, kind: 'summary' }\n}\n\nfunction* reasoningDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.text += event.delta\n entry.reasoningKind = mergeKind(entry.reasoningKind, 'content')\n yield { type: 'reasoning-delta', index: entry.index, text: event.delta, kind: 'content' }\n}\n\nfunction mergeKind(current: OpenItem['reasoningKind'], next: 'summary' | 'content'): OpenItem['reasoningKind'] {\n return current === undefined || current === next ? next : 'mixed'\n}\n\nfunction* toolDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.args += event.delta\n yield {\n type: 'tool-call-delta',\n index: entry.index,\n id: ToolCallId(entry.callId),\n ...entry.name.length > 0 ? { name: entry.name } : {},\n argumentsDelta: event.delta,\n }\n}\n\nfunction* partialImage(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const itemId = event.item_id\n const entry = itemId === undefined ? undefined : state.open.get(itemId)\n if (itemId === undefined || entry === undefined || event.partial_image_b64 === undefined) return\n yield {\n type: 'image-delta',\n index: entry.index,\n itemId,\n data: event.partial_image_b64,\n mediaType: state.imageMediaType,\n ...event.partial_image_index === undefined\n ? {}\n : { partialIndex: event.partial_image_index },\n }\n}\n\nfunction* itemDone(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const item = event.item\n const id = item?.id ?? event.item_id\n const entry = id === undefined ? undefined : state.open.get(id)\n if (item === undefined || entry === undefined) return\n const block = doneBlock(item, entry, state.imageMediaType)\n if (block !== undefined) yield { type: 'block-end', index: entry.index, block }\n}\n\nfunction* completed(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n // This API has no explicit stop reason. Tool calls in the output ARE the\n // signal that the turn expects results back, which is what an agent loop\n // branches on.\n const reason: FinishReason = state.sawToolCall ? { kind: 'tool-calls' } : { kind: 'stop' }\n yield { type: 'finish', reason }\n}\n\nfunction* incomplete(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n const why = event.response?.incomplete_details?.reason\n if (why === 'max_output_tokens') {\n yield { type: 'finish', reason: { kind: 'max-tokens' } }\n return\n }\n throw new ModelError(\n `${displayName} returned an incomplete response (${why ?? 'unknown reason'})`,\n MODEL_ERROR_CODES.SERVER,\n )\n}\n\nfunction* failed(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n // A failed generation can still be billed. Preserve the provider's\n // counters before the transport records the failure and retry admission.\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n throw failedError(event.response, displayName)\n}\n\nfunction* inlineError(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n // A top-level error event carries its fields inline rather than under a\n // `response` object, so it is reshaped to reuse the same classifier.\n const inline: WireErrorBody = {\n ...event.code === undefined ? {} : { code: event.code },\n ...event.message === undefined ? {} : { message: event.message },\n }\n throw failedError({ error: inline }, displayName)\n}\n\nfunction* deltaEvent(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'response.output_text.delta': yield* textDelta(state, event); return\n case 'response.reasoning_summary_text.delta': yield* summaryDelta(state, event); return\n case 'response.reasoning_text.delta': yield* reasoningDelta(state, event); return\n case 'response.function_call_arguments.delta': yield* toolDelta(state, event); return\n case 'response.image_generation_call.partial_image': yield* partialImage(state, event); return\n default: return\n }\n}\n\nfunction createOpenItem(\n state: StreamState, item: WireOutputItem, identity: { id: string; kind: ItemKind },\n): OpenItem {\n const { id, kind } = identity\n return {\n index: state.nextIndex++,\n kind,\n text: '',\n args: '',\n callId: item.call_id ?? id,\n name: item.name ?? '',\n nativeName: nativeName(item.type),\n summaryIndex: undefined,\n phase: textPhase(item.phase),\n reasoningKind: undefined,\n }\n}\n","/**\n * Responses API SSE events to the SDK's chunk protocol.\n *\n * Two design notes worth reading before changing anything here.\n *\n * First, block correlation is keyed on `item_id`, not on the provider's\n * `output_index`. Item ids are stable and present on every delta event, whereas\n * index fields vary by event type, so keying on the id and assigning our OWN\n * indices in first-seen order is both simpler and closer to what our protocol\n * promises.\n *\n * Second, reasoning state is carried on the reasoning BLOCK\n * (`ReasoningBlock.providerState`) rather than in the stream's `replayState`\n * envelope. The envelope has to stay positionally aligned with emitted blocks and\n * is discarded whole when it drifts; attaching the state to the block it belongs\n * to cannot drift, and it survives assembly for free.\n *\n * @module ai-agent-sdk/providers/responses/translate\n */\n\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest, ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type { WireStreamEvent } from './wire.ts'\nimport { requestedImageMediaType } from './stream-items.ts'\nimport { translateEvent, type StreamState } from './stream-events.ts'\n\nexport async function* translateResponsesStream(\n events: AsyncIterable<ProtocolSseEvent>, displayName: string, request?: ProtocolRequest,\n): AsyncGenerator<ProtocolStreamChunk> {\n const state: StreamState = {\n open: new Map(), nextIndex: 0, sawToolCall: false, imageMediaType: requestedImageMediaType(request),\n }\n for await (const raw of events) {\n const event = parseEvent(raw, displayName)\n yield* translateEvent(state, event, displayName)\n if (event.type === 'response.completed' || event.type === 'response.incomplete') return\n }\n throw new ModelError(\n `${displayName} stream ended before the response completed`,\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 OpenAI Responses protocol, as a reusable {@link WireProtocol}.\n *\n * Spoken by `api.openai.com`, by the ChatGPT-backed Codex endpoint, and by a\n * growing number of compatible gateways. None of them needs its own translation\n * code — they differ only in the dialect knobs below.\n *\n * @module ai-agent-sdk/providers/protocols/openai-responses\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 { serializeResponsesRequest } from './serialize.ts'\nimport { translateResponsesStream } from './translate.ts'\nimport type { ResponsesDialect } from './wire.ts'\n\n/** Protocol id, usable as a stable string in configuration. */\nexport const OPENAI_RESPONSES_PROTOCOL_ID = 'openai-responses'\n\n/**\n * Conservative defaults.\n *\n * `store: false` because retaining prompts server-side should be an explicit\n * decision, not something an SDK turns on for you. `include` carries\n * `reasoning.encrypted_content` because without it a reasoning model loses its\n * chain of thought between a tool call and the tool's result.\n */\nconst DEFAULT_DIALECT: ResponsesDialect = Object.freeze({\n sampling: true,\n maxOutputTokens: true,\n structuredOutputs: true,\n store: false,\n include: Object.freeze(['reasoning.encrypted_content']),\n reasoningSummary: 'auto',\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 ResponsesProtocolDefinition {\n readonly kind: 'http-wire-protocol'\n readonly apiVersion: 1\n readonly id: string\n readonly defaultDialect: ResponsesDialect\n readonly exampleModel?: ModelTarget\n readonly endpointPath: (request: RuntimeProtocolRequest, dialect: ResponsesDialect) => string\n readonly protocolHeaders?: (dialect: ResponsesDialect) => Readonly<Record<string, string>>\n readonly serialize: (\n request: RuntimeProtocolRequest,\n dialect: ResponsesDialect,\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 OpenAI Responses wire protocol. */\nexport const openAiResponsesProtocol: ProtocolDefinition<ResponsesDialect>\n & ResponsesProtocolDefinition = Object.freeze({\n kind: 'http-wire-protocol' as const,\n apiVersion: 1 as const,\n id: OPENAI_RESPONSES_PROTOCOL_ID,\n defaultDialect: DEFAULT_DIALECT,\n endpointPath: () => '/responses',\n serialize(request: ProtocolRequest, dialect: ResponsesDialect): Readonly<Record<string, unknown>> {\n return serializeResponsesRequest(request, dialect) as unknown 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> => translateResponsesStream(events, displayName, request),\n})\n\nexport type { ResponsesDialect }\n"],"mappings":";;;AAMA,MAAM,4BAA4B;AAElC,SAAgB,iBAAiB,OAAyC;CACxE,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,CAAC;CACzD,MAAM,QAAQ;CACd,OAAO;EACL,GAAG,OAAO,MAAM,OAAO,WAAW,EAAE,IAAI,MAAM,GAAG,IAAI,CAAC;EACtD,GAAG,OAAO,MAAM,qBAAqB,WACjC,EAAE,kBAAkB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;EAChC,cAAc;EACd,OAAO,UAAU,KAAK,KAAK;EAC3B,eAAe;CACjB;AACF;;;;;;;;;;;;;;;;;;;;;;;ACxKA,gBAAuB,yBACrB,QAAyC,aAAqB,SACzB;CACrC,MAAM,QAAqB;EACzB,sBAAM,IAAI,IAAI;EAAG,WAAW;EAAG,aAAa;EAAO,gBAAgB,wBAAwB,OAAO;CACpG;CACA,WAAW,MAAM,OAAO,QAAQ;EAC9B,MAAM,QAAQ,WAAW,KAAK,WAAW;EACzC,OAAO,eAAe,OAAO,OAAO,WAAW;EAC/C,IAAI,MAAM,SAAS,wBAAwB,MAAM,SAAS,uBAAuB;CACnF;CACA,MAAM,IAAI,WACR,GAAG,YAAY,8CACf,kBAAkB,aACpB;AACF;AAEA,SAAS,WAAW,KAAuB,aAAsC;CAC/E,IAAI;EAAE,OAAO,KAAK,MAAM,IAAI,IAAI;CAAqB,SAC9C,OAAgB;EACrB,MAAM,IAAI,WACR,GAAG,YAAY,iCACf,kBAAkB,oBAAoB,EAAE,OAAO,MAAM,CACvD;CACF;AACF;;;;;AC7BA,MAAa,+BAA+B;;;;;;;;;AAU5C,MAAM,kBAAoC,OAAO,OAAO;CACtD,UAAU;CACV,iBAAiB;CACjB,mBAAmB;CACnB,OAAO;CACP,SAAS,OAAO,OAAO,CAAC,6BAA6B,CAAC;CACtD,kBAAkB;AACpB,CAAC;;AA+BD,MAAa,0BACqB,OAAO,OAAO;CAC9C,MAAM;CACN,YAAY;CACZ,IAAI;CACJ,gBAAgB;CAChB,oBAAoB;CACpB,UAAU,SAA0B,SAA8D;EAChG,OAAO,0BAA0B,SAAS,OAAO;CACnD;CAGA,YACE,QACA,SACA,gBACwC,yBAAyB,QAAQ,aAAa,OAAO;AACjG,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["textAnnotations"],"sources":["../src/request-content.ts","../src/request-messages.ts","../src/serialize-options.ts","../src/serialize.ts","../src/stream-items.ts","../src/stream-usage.ts","../src/stream-errors.ts","../src/stream-events.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["import type {\n ContentBlock, DocumentBlock, ImageBlock, NativeToolCallBlock, TextBlock,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { WireContentPart, WireInputItem } from './wire.ts'\nimport type { ResponsesReasoningState } from './serialize-types.ts'\n\nconst DEFAULT_DOCUMENT_FILENAME = 'document.pdf'\n\nexport function reasoningStateOf(value: unknown): ResponsesReasoningState {\n if (typeof value !== 'object' || value === null) return {}\n const state = value as ResponsesReasoningState\n return {\n ...typeof state.id === 'string' ? { id: state.id } : {},\n ...typeof state.encryptedContent === 'string'\n ? { encryptedContent: state.encryptedContent }\n : {},\n ...Array.isArray(state.summary) ? { summary: state.summary } : {},\n }\n}\n\nexport function textAnnotations(block: TextBlock) {\n return block.annotations?.flatMap(annotation => annotation.type === 'url-citation'\n ? [{\n type: 'url_citation' as const,\n url: annotation.url,\n ...annotation.title === undefined ? {} : { title: annotation.title },\n ...annotation.startIndex === undefined ? {} : { start_index: annotation.startIndex },\n ...annotation.endIndex === undefined ? {} : { end_index: annotation.endIndex },\n }]\n : [])\n}\n\nexport function imagePart(block: ImageBlock): WireContentPart {\n const detail = block.detail\n if (block.source.kind === 'file') {\n return { type: 'input_image', file_id: block.source.fileId, ...detail === undefined ? {} : { detail } }\n }\n const image_url = block.source.kind === 'url'\n ? block.source.url\n : `data:${block.source.mediaType};base64,${block.source.data}`\n return { type: 'input_image', image_url, ...detail === undefined ? {} : { detail } }\n}\n\nexport function documentPart(block: DocumentBlock): WireContentPart {\n if (block.source.kind === 'file') return { type: 'input_file', file_id: block.source.fileId }\n if (block.source.kind === 'url') return { type: 'input_file', file_url: block.source.url }\n return {\n type: 'input_file',\n // The API reads the file type from the extension here, so a name is required\n // rather than optional; a neutral default beats a rejected request.\n filename: block.filename ?? DEFAULT_DOCUMENT_FILENAME,\n file_data: `data:${block.source.mediaType};base64,${block.source.data}`,\n }\n}\n\nexport function contentPart(block: ContentBlock, role: 'user' | 'assistant'): WireContentPart | undefined {\n if (block.type === 'text') {\n // An assistant turn's own text must come back as `output_text`; sending it as\n // `input_text` would present the model's prior words as if the user said them.\n if (role !== 'assistant') return { type: 'input_text', text: block.text }\n const annotations = textAnnotations(block)\n return {\n type: 'output_text', text: block.text,\n ...annotations === undefined ? {} : { annotations },\n }\n }\n if (block.type === 'image') return imagePart(block)\n if (block.type === 'document') return documentPart(block)\n return undefined\n}\n\nexport function toolResultOutput(blocks: readonly ContentBlock[]): string | WireContentPart[] {\n const hasBinary = blocks.some(block => block.type === 'image' || block.type === 'document')\n if (!hasBinary) {\n // The common case. A plain string keeps the payload small and is what the\n // API documents first.\n return blocks\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n .join('\\n')\n }\n return blocks\n .map(block => contentPart(block, 'user'))\n .filter((part): part is WireContentPart => part !== undefined)\n}\n\nexport function nativeReplayItem(block: NativeToolCallBlock): WireInputItem | undefined {\n const value = block.providerState\n if (typeof value !== 'object' || value === null) return undefined\n const item = value as Record<string, unknown>\n if (item.type === 'web_search_call') {\n return {\n type: 'web_search_call',\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...item.action === undefined ? {} : { action: structuredClone(item.action) },\n }\n }\n if (item.type === 'image_generation_call') return imageReplayItem(item, generatedImage(block))\n return undefined\n}\n\n/** The generated image, as base64; histories recorded before it moved there keep it in the item. */\nfunction generatedImage(block: NativeToolCallBlock): string | undefined {\n const image = block.content.find(content => content.type === 'image' && content.source.kind === 'base64')\n return image?.type === 'image' && image.source.kind === 'base64' ? image.source.data : undefined\n}\n\nfunction imageReplayItem(item: Record<string, unknown>, image: string | undefined): WireInputItem {\n const result = image ?? item.result\n return {\n type: 'image_generation_call',\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...typeof result === 'string' || result === null ? { result } : {},\n }\n}\n","import type { ContentBlock, TextBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { Message } from '@alvin0/ai-agent-sdk-core'\nimport type { WireContentPart, WireInputItem } from './wire.ts'\nimport type { ResponsesReasoningState } from './serialize-types.ts'\nimport { contentPart, reasoningStateOf, toolResultOutput, nativeReplayItem } from './request-content.ts'\n\ninterface MessageState {\n role: 'user' | 'assistant'\n parts: WireContentPart[]\n phase: TextBlock['phase']\n items: WireInputItem[]\n dialectMessagePhase: boolean\n}\n\n/** Flush content at standalone-item boundaries to preserve conversation order. */\nexport function appendMessage(message: Message, items: WireInputItem[], dialectMessagePhase: boolean): void {\n const state: MessageState = {\n role: message.role === 'assistant' ? 'assistant' : 'user', parts: [], phase: undefined,\n items, dialectMessagePhase,\n }\n for (const block of message.content) {\n if (block.type === 'text' || block.type === 'image' || block.type === 'document') appendContent(block, state)\n else appendControl(block, state)\n }\n flushMessage(state)\n}\n\nfunction flushMessage(state: MessageState): void {\n if (state.parts.length === 0) return\n state.items.push({\n type: 'message', role: state.role, content: state.parts,\n ...state.role === 'assistant' && state.dialectMessagePhase && state.phase !== undefined\n ? { phase: state.phase === 'final-answer' ? 'final_answer' as const : state.phase } : {},\n })\n state.parts = []\n state.phase = undefined\n}\n\nfunction appendContent(block: ContentBlock, state: MessageState): void {\n if (block.type === 'text' && block.phase !== undefined && state.phase !== undefined && state.phase !== block.phase) {\n flushMessage(state)\n }\n if (block.type === 'text' && block.phase !== undefined) state.phase = block.phase\n const part = contentPart(block, state.role)\n if (part !== undefined) state.parts.push(part)\n}\n\nfunction appendControl(block: ContentBlock, state: MessageState): void {\n switch (block.type) {\n case 'reasoning':\n flushMessage(state)\n appendReasoning(block, state.items)\n return\n case 'tool-call':\n flushMessage(state)\n state.items.push({ type: 'function_call', call_id: block.id, name: block.name,\n arguments: block.arguments.length > 0 ? block.arguments : '{}' })\n return\n case 'tool-result':\n flushMessage(state)\n state.items.push({ type: 'function_call_output', call_id: block.toolCallId,\n output: toolResultOutput(block.content) })\n return\n case 'native-tool-call': {\n flushMessage(state)\n const replay = nativeReplayItem(block)\n if (replay !== undefined) state.items.push(replay)\n return\n }\n default: return\n }\n}\n\nfunction appendReasoning(block: Extract<ContentBlock, { type: 'reasoning' }>, items: WireInputItem[]): void {\n const state = reasoningStateOf(block.providerState)\n // Unfinished reasoning has no replay identity and cannot be sent back.\n if (state.id === undefined && state.encryptedContent === undefined) return\n const summary = reasoningSummary(state, block.text)\n items.push({\n type: 'reasoning',\n ...state.id === undefined ? {} : { id: state.id },\n summary: summary.map(text => ({ type: 'summary_text' as const, text })),\n ...state.encryptedContent === undefined ? {} : { encrypted_content: state.encryptedContent },\n })\n}\n\nfunction reasoningSummary(state: ResponsesReasoningState, text: string): readonly string[] {\n if (state.summary !== undefined && state.summary.length > 0) return state.summary\n return text.length > 0 ? [text] : []\n}\n","import type { ProtocolRequest } from './contract.ts'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport {\n isNativeToolSchema, type ModelOutputFormat, type ModelToolSchema, type NativeImageGenerationTool,\n type NativeWebSearchTool, type ToolChoice, type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ResponsesDialect, WireTool, WireToolChoice, WireTextControls } from './wire.ts'\n\nexport function toolChoiceOf(choice: ToolChoice): WireToolChoice {\n if (typeof choice === 'string') return choice\n if (choice.type === 'native') return { type: nativeWireType(choice.name) }\n return { type: 'function', name: choice.name }\n}\n\nexport function functionTool(tool: ToolSchema): WireTool {\n return {\n type: 'function',\n name: tool.name,\n description: tool.description,\n // Strict mode imposes real JSON-Schema restrictions (no optional fields\n // without null, `additionalProperties: false` required). Opting a caller's\n // schema in silently would turn a working tool into a request rejection.\n strict: false,\n parameters: tool.parameters,\n }\n}\n\nexport function nativeWireType(name: string): string {\n if (name === 'web-search') return 'web_search'\n if (name === 'image-generation') return 'image_generation'\n return name.replaceAll('-', '_')\n}\n\nexport function webSearchTool(tool: NativeWebSearchTool): WireTool {\n if (tool.blockedDomains !== undefined) {\n throw new ModelError(\n 'OpenAI Responses web search does not support blockedDomains; use allowedDomains',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n if (tool.maxUses !== undefined) {\n throw new ModelError(\n 'OpenAI Responses web search does not support maxUses',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n type: 'web_search',\n ...tool.searchContextSize === undefined ? {} : { search_context_size: tool.searchContextSize },\n ...tool.allowedDomains === undefined ? {} : { filters: { allowed_domains: [...tool.allowedDomains] } },\n ...tool.userLocation === undefined ? {} : {\n user_location: { type: 'approximate', ...tool.userLocation },\n },\n ...tool.searchContentTypes === undefined ? {} : { search_content_types: [...tool.searchContentTypes] },\n }\n}\n\nexport function imageGenerationTool(tool: NativeImageGenerationTool): WireTool {\n return {\n type: 'image_generation',\n ...tool.size === undefined ? {} : { size: tool.size },\n ...tool.quality === undefined ? {} : { quality: tool.quality },\n ...tool.format === undefined ? {} : { output_format: tool.format },\n ...tool.background === undefined ? {} : { background: tool.background },\n ...tool.partialImages === undefined ? {} : { partial_images: tool.partialImages },\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 return imageGenerationTool(tool)\n}\n\nexport function textControls(\n format: ModelOutputFormat | undefined,\n dialect: ResponsesDialect,\n): WireTextControls | undefined {\n if (format === undefined) return undefined\n if (format.type === 'text') {\n return dialect.structuredOutputs ? { format: { type: 'text' } } : undefined\n }\n if (!dialect.structuredOutputs) {\n throw new ModelError(\n 'This Responses endpoint does not support JSON Schema output',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n format: {\n type: 'json_schema',\n name: format.name,\n schema: format.schema,\n strict: true,\n },\n }\n}\n\nexport function toolsOptions(request: ProtocolRequest) {\n const options = request.options\n const tools = options.tools === undefined || options.tools.length === 0 ? undefined : options.tools.map(toolOf)\n return {\n ...tools === undefined ? {} : { tools, parallel_tool_calls: true },\n ...options.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(options.toolChoice) },\n }\n}\n\nexport function reasoningOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const effort = request.options.reasoningEffort\n if (effort === undefined && dialect.reasoningSummary === undefined) return {}\n return { reasoning: {\n ...effort === undefined ? {} : { effort: String(effort) },\n ...dialect.reasoningSummary === undefined ? {} : { summary: dialect.reasoningSummary },\n } }\n}\n\nexport function dialectOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const text = textControls(request.options.outputFormat, dialect)\n return {\n ...text === undefined ? {} : { text },\n ...dialect.store === undefined ? {} : { store: dialect.store },\n ...dialect.include.length === 0 ? {} : { include: [...dialect.include] },\n ...dialect.promptCacheKey === undefined ? {} : { prompt_cache_key: dialect.promptCacheKey },\n ...dialect.maxOutputTokens && request.maxTokens !== undefined ? { max_output_tokens: request.maxTokens } : {},\n }\n}\n\nexport function samplingOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const options = request.options\n return {\n ...dialect.sampling && options.temperature !== undefined ? { temperature: options.temperature } : {},\n ...dialect.sampling && options.topP !== undefined ? { top_p: options.topP } : {},\n }\n}\n","/**\n * Normalized request to Responses API wire JSON.\n *\n * The interesting work is flattening. Our conversation is a list of messages,\n * each holding an ordered list of content blocks; the wire wants a FLAT list of\n * items where a tool result and a tool call are peers of a message rather than\n * parts of one. So one assistant message that reasoned, spoke, and called two\n * tools expands to four items, and their relative order must be preserved\n * because the model reads it as its own prior turn.\n *\n * @module ai-agent-sdk/providers/responses/serialize\n */\n\nimport type { ProtocolRequest } from './contract.ts'\nimport type { ContentBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { ResponsesDialect, WireInputItem, WireRequest } from './wire.ts'\nexport type { ResponsesReasoningState } from './serialize-types.ts'\nimport { appendMessage } from './request-messages.ts'\nimport { toolsOptions, reasoningOptions, dialectOptions, samplingOptions } from './serialize-options.ts'\n\nfunction instructionsOf(request: ProtocolRequest): string {\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 return all.join('\\n\\n')\n}\n\nexport function serializeResponsesRequest(request: ProtocolRequest, dialect: ResponsesDialect): WireRequest {\n const input: WireInputItem[] = []\n for (const message of request.options.messages) {\n if (message.role === 'system') continue\n appendMessage(message, input, dialect.messagePhase === true)\n }\n const instructions = instructionsOf(request)\n return {\n model: request.options.model,\n ...instructions.length === 0 ? {} : { instructions },\n input,\n ...toolsOptions(request),\n ...reasoningOptions(request, dialect),\n ...dialectOptions(request, dialect),\n ...samplingOptions(request, dialect),\n stream: true,\n }\n}\n","import { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport { isJsonValue } from '@alvin0/ai-agent-sdk-core'\nimport type {\n AssistantTextPhase, ContentBlock, ImageMediaType, ReasoningKind, TextAnnotation,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type { ResponsesReasoningState } from './serialize.ts'\nimport type { WireOutputItem } from './wire.ts'\n\nexport type ItemKind = 'text' | 'reasoning' | 'tool-call' | 'native-tool-call'\n\nexport interface OpenItem {\n readonly index: number\n readonly kind: ItemKind\n text: string\n args: string\n callId: string\n name: string\n nativeName: string\n /** Last `summary_index` seen, so a new paragraph gets a separator. */\n summaryIndex: number | undefined\n phase: AssistantTextPhase | undefined\n /**\n * Which reasoning stream filled `text`; `mixed` when both did, which leaves\n * the block unlabelled. The done item's summary still overrides it.\n */\n reasoningKind: ReasoningKind | 'mixed' | undefined\n}\n\nexport function textPhase(value: string | undefined): AssistantTextPhase | undefined {\n if (value === 'commentary') return 'commentary'\n if (value === 'final_answer') return 'final-answer'\n return undefined\n}\n\nexport function itemKind(type: string | undefined): ItemKind | undefined {\n switch (type) {\n case 'message': return 'text'\n case 'reasoning': return 'reasoning'\n case 'function_call': return 'tool-call'\n case 'web_search_call': return 'native-tool-call'\n case 'image_generation_call': return 'native-tool-call'\n default: return undefined\n }\n}\n\nexport function nativeName(type: string | undefined): string {\n if (type === 'web_search_call') return 'web-search'\n if (type === 'image_generation_call') return 'image-generation'\n return type?.replace(/_call$/, '').replaceAll('_', '-') ?? 'native-tool'\n}\n\nexport function textAnnotations(item: WireOutputItem): TextAnnotation[] {\n if (!Array.isArray(item.content)) return []\n return item.content.flatMap((part) => {\n if (typeof part !== 'object' || part === null) return []\n const annotations = (part as Record<string, unknown>).annotations\n if (!Array.isArray(annotations)) return []\n return annotations.flatMap((annotation): TextAnnotation[] => {\n if (typeof annotation !== 'object' || annotation === null) return []\n const record = annotation as Record<string, unknown>\n if (record.type !== 'url_citation' || typeof record.url !== 'string') return []\n return [{\n type: 'url-citation',\n url: record.url,\n ...typeof record.title === 'string' ? { title: record.title } : {},\n ...typeof record.start_index === 'number' ? { startIndex: record.start_index } : {},\n ...typeof record.end_index === 'number' ? { endIndex: record.end_index } : {},\n }]\n })\n })\n}\n\nexport function itemText(item: WireOutputItem): string {\n const content = item.content\n if (!Array.isArray(content)) return ''\n return content\n .map((part) => {\n if (typeof part !== 'object' || part === null) return ''\n const record = part as Record<string, unknown>\n return typeof record.text === 'string' ? record.text : ''\n })\n .join('')\n}\n\nexport function itemSummary(item: WireOutputItem): string[] {\n const summary = item.summary\n if (!Array.isArray(summary)) return []\n return summary\n .map((part) => {\n if (typeof part !== 'object' || part === null) return ''\n const record = part as Record<string, unknown>\n return typeof record.text === 'string' ? record.text : ''\n })\n .filter(text => text.length > 0)\n}\n\nexport function doneBlock(\n item: WireOutputItem, open: OpenItem, imageMediaType: ImageMediaType,\n): ContentBlock | undefined {\n switch (open.kind) {\n case 'text': return doneText(item, open)\n case 'reasoning': return doneReasoning(item, open)\n case 'tool-call': return doneTool(item, open)\n case 'native-tool-call': return doneNative(item, open, imageMediaType)\n default: return undefined\n }\n}\n\nfunction doneText(item: WireOutputItem, open: OpenItem): ContentBlock {\n const text = itemText(item)\n const phase = textPhase(item.phase) ?? open.phase\n return {\n type: 'text',\n text: text.length > 0 ? text : open.text,\n ...phase === undefined ? {} : { phase },\n ...textAnnotations(item).length === 0 ? {} : { annotations: textAnnotations(item) },\n }\n}\n\nfunction doneReasoning(item: WireOutputItem, open: OpenItem): ContentBlock {\n const summary = itemSummary(item)\n const state: ResponsesReasoningState = {\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.encrypted_content === 'string'\n ? { encryptedContent: item.encrypted_content }\n : {},\n ...summary.length > 0 ? { summary } : {},\n }\n const streamed = open.reasoningKind === 'mixed' ? undefined : open.reasoningKind\n const kind = summary.length > 0 ? 'summary' : streamed\n return {\n type: 'reasoning',\n text: summary.length > 0 ? summary.join('\\n\\n') : open.text,\n ...kind === undefined ? {} : { kind },\n providerState: state,\n }\n}\n\nfunction doneTool(item: WireOutputItem, open: OpenItem): ContentBlock {\n const args = typeof item.arguments === 'string' && item.arguments.length > 0\n ? item.arguments\n : open.args\n return {\n type: 'tool-call',\n id: ToolCallId(item.call_id ?? open.callId),\n name: item.name ?? open.name,\n arguments: args.length > 0 ? args : '{}',\n }\n}\n\nfunction doneNative(item: WireOutputItem, open: OpenItem, imageMediaType: ImageMediaType): ContentBlock {\n const content: ContentBlock[] = open.nativeName === 'image-generation'\n && typeof item.result === 'string' && item.result.length > 0\n ? [{\n type: 'image',\n source: { kind: 'base64', mediaType: imageMediaType, data: item.result },\n }]\n : []\n return {\n type: 'native-tool-call',\n id: item.id ?? open.callId,\n name: open.nativeName,\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...isJsonValue(item.action) ? { arguments: item.action } : {},\n content,\n // The image is kept once, as public content; replay reads it back from there.\n providerState: content.length > 0 ? withoutResult(item) : item,\n }\n}\n\nfunction withoutResult(item: WireOutputItem): WireOutputItem {\n const { result: _result, ...rest } = item\n return rest\n}\n\n\nexport function kindToBlockType(kind: ItemKind): 'text' | 'reasoning' | 'tool-call' | 'native-tool-call' {\n return kind\n}\n\nexport function requestedImageMediaType(request: ProtocolRequest | undefined): ImageMediaType {\n const tool = request?.options.tools?.find(candidate => 'type' in candidate\n && candidate.type === 'native'\n && candidate.name === 'image-generation')\n if (tool === undefined || !('format' in tool)) return 'image/png'\n if (tool.format === 'jpeg') return 'image/jpeg'\n if (tool.format === 'webp') return 'image/webp'\n return 'image/png'\n}","import type { UsageCounters } from '@alvin0/ai-agent-sdk-core'\nimport type { WireUsage } from './wire.ts'\n\nexport function mapUsage(usage: WireUsage): UsageCounters | undefined {\n const source = usage as unknown as Record<string, unknown>\n const details = recordOrUndefined(source.input_tokens_details)\n const rawInput = source.input_tokens\n const outputTokens = source.output_tokens\n const cacheRead = details?.cached_tokens\n const cacheWrite = details?.cache_write_tokens\n const reasoning = reasoningCounter(source)\n const totalTokens = source.total_tokens\n const hasAny = [rawInput, outputTokens, cacheRead, cacheWrite, reasoning, totalTokens]\n .some(value => value !== undefined)\n if (!hasAny) return undefined\n\n const normalized: Record<string, unknown> = {\n ...outputTokens === undefined ? {} : { outputTokens },\n ...totalTokens === undefined ? {} : { totalTokens },\n // Omitted cache details are authoritative zero for Responses. Present\n // malformed values are retained for the accounting validator.\n ...omittedCounter(cacheRead) ? {} : { cacheReadTokens: cacheRead },\n ...omittedCounter(cacheWrite) ? {} : { cacheWriteTokens: cacheWrite },\n ...omittedCounter(reasoning) ? {} : { reasoningTokens: reasoning },\n }\n if (rawInput !== undefined) {\n normalized.inputTokens = disjointInput(rawInput, cacheRead, cacheWrite)\n }\n return normalized as UsageCounters\n}\n\nfunction recordOrUndefined(value: unknown): Record<string, unknown> | undefined {\n return typeof value === 'object' && value !== null ? value as Record<string, unknown> : undefined\n}\n\nfunction omittedCounter(value: unknown): boolean { return value === undefined || value === 0 }\n\nfunction disjointInput(rawInput: unknown, cacheRead: unknown, cacheWrite: unknown): unknown {\n // Responses includes both cache buckets in input_tokens. The SDK accounts\n // for them separately; do not count cache writes twice or clamp invalid data.\n return typeof rawInput === 'number' && (cacheRead === undefined || typeof cacheRead === 'number')\n && (cacheWrite === undefined || typeof cacheWrite === 'number')\n ? rawInput - (cacheRead ?? 0) - (cacheWrite ?? 0) : rawInput\n}\n\nfunction reasoningCounter(source: Record<string, unknown>): unknown {\n return recordOrUndefined(source.output_tokens_details)?.reasoning_tokens\n}\n","import { CONTEXT_WINDOW_EXCEEDED_CODE, QUOTA_EXCEEDED_CODE } from '@alvin0/ai-agent-sdk-core'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { WireResponse } from './wire.ts'\n\nconst TERMINAL_ERROR_CODES: Readonly<Record<string, string>> = Object.freeze({\n context_length_exceeded: CONTEXT_WINDOW_EXCEEDED_CODE,\n insufficient_quota: QUOTA_EXCEEDED_CODE,\n invalid_prompt: MODEL_ERROR_CODES.INVALID_REQUEST,\n bio_policy: MODEL_ERROR_CODES.INVALID_REQUEST,\n cyber_policy: MODEL_ERROR_CODES.INVALID_REQUEST,\n misalignment_policy_violation: MODEL_ERROR_CODES.INVALID_REQUEST,\n rate_limit_exceeded: MODEL_ERROR_CODES.RATE_LIMIT,\n})\n\n\nexport function failedError(response: WireResponse | undefined, displayName: string): ModelError {\n const error = response?.error ?? undefined\n const code = error?.code ?? error?.type\n const message = error?.message ?? `${displayName} reported a failed response${failureContext(response, code)}`\n const mapped = code === undefined ? undefined : TERMINAL_ERROR_CODES[code]\n return new ModelError(\n message,\n // An unrecognized failure defaults to SERVER, which IS in the retryable set:\n // the request produced nothing, so repeating it is safe and often works.\n mapped ?? MODEL_ERROR_CODES.SERVER,\n {},\n )\n}\n\nfunction failureContext(response: WireResponse | undefined, code: string | undefined): string {\n const facts = [\n code === undefined ? 'no error detail' : `code ${code}`,\n ...typeof response?.id === 'string' && /^[\\w.:-]{1,128}$/.test(response.id) ? [`response ${response.id}`] : [],\n ...typeof response?.status === 'string' && /^[\\w-]{1,32}$/.test(response.status)\n ? [`status ${response.status}`] : [],\n ]\n return ` (${facts.join(', ')})`\n}","import type { WireOutputItem } from './wire.ts'\nimport type { ItemKind } from './stream-items.ts'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport type { ImageMediaType } from '@alvin0/ai-agent-sdk-core'\nimport type { FinishReason } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolStreamChunk } from './contract.ts'\nimport type { WireErrorBody, WireStreamEvent } from './wire.ts'\nimport { textPhase, itemKind, nativeName, kindToBlockType, doneBlock, type OpenItem } from './stream-items.ts'\nimport { mapUsage } from './stream-usage.ts'\nimport { failedError } from './stream-errors.ts'\n\nexport interface StreamState {\n open: Map<string, OpenItem>\n nextIndex: number\n sawToolCall: boolean\n imageMediaType: ImageMediaType\n}\n\nexport function* translateEvent(\n state: StreamState, event: WireStreamEvent, displayName: string,\n): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'response.output_item.added': yield* itemAdded(state, event); return\n case 'response.output_item.done': yield* itemDone(state, event); return\n case 'response.completed': yield* completed(state, event); return\n case 'response.incomplete': yield* incomplete(event, displayName); return\n case 'response.failed': yield* failed(event, displayName); return\n case 'error': yield* inlineError(event, displayName); return\n default: yield* deltaEvent(state, event); return\n }\n}\n\nfunction* itemAdded(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const item = event.item\n const id = item?.id ?? event.item_id\n const kind = itemKind(item?.type)\n if (item === undefined || id === undefined || kind === undefined) return\n if (state.open.has(id)) return\n const entry = createOpenItem(state, item, { id, kind })\n state.open.set(id, entry)\n if (kind === 'tool-call') state.sawToolCall = true\n yield { type: 'block-start', index: entry.index, blockType: kindToBlockType(kind) }\n}\n\nfunction* textDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.text += event.delta\n yield {\n type: 'text-delta', index: entry.index, text: event.delta,\n ...entry.phase === undefined ? {} : { phase: entry.phase },\n }\n}\n\nfunction* summaryDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n // A new summary paragraph starts; separate it from the previous one so the\n // assembled text does not run two thoughts together.\n const separator = entry.summaryIndex !== undefined\n && event.summary_index !== undefined\n && event.summary_index !== entry.summaryIndex\n ? '\\n\\n'\n : ''\n entry.summaryIndex = event.summary_index\n const text = `${separator}${event.delta}`\n entry.text += text\n entry.reasoningKind = mergeKind(entry.reasoningKind, 'summary')\n yield { type: 'reasoning-delta', index: entry.index, text, kind: 'summary' }\n}\n\nfunction* reasoningDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.text += event.delta\n entry.reasoningKind = mergeKind(entry.reasoningKind, 'content')\n yield { type: 'reasoning-delta', index: entry.index, text: event.delta, kind: 'content' }\n}\n\nfunction mergeKind(current: OpenItem['reasoningKind'], next: 'summary' | 'content'): OpenItem['reasoningKind'] {\n return current === undefined || current === next ? next : 'mixed'\n}\n\nfunction* toolDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.args += event.delta\n yield {\n type: 'tool-call-delta',\n index: entry.index,\n id: ToolCallId(entry.callId),\n ...entry.name.length > 0 ? { name: entry.name } : {},\n argumentsDelta: event.delta,\n }\n}\n\nfunction* partialImage(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const itemId = event.item_id\n const entry = itemId === undefined ? undefined : state.open.get(itemId)\n if (itemId === undefined || entry === undefined || event.partial_image_b64 === undefined) return\n yield {\n type: 'image-delta',\n index: entry.index,\n itemId,\n data: event.partial_image_b64,\n mediaType: state.imageMediaType,\n ...event.partial_image_index === undefined\n ? {}\n : { partialIndex: event.partial_image_index },\n }\n}\n\nfunction* itemDone(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const item = event.item\n const id = item?.id ?? event.item_id\n const entry = id === undefined ? undefined : state.open.get(id)\n if (item === undefined || entry === undefined) return\n const block = doneBlock(item, entry, state.imageMediaType)\n if (block !== undefined) yield { type: 'block-end', index: entry.index, block }\n}\n\nfunction* completed(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n // This API has no explicit stop reason. Tool calls in the output ARE the\n // signal that the turn expects results back, which is what an agent loop\n // branches on.\n const reason: FinishReason = state.sawToolCall ? { kind: 'tool-calls' } : { kind: 'stop' }\n yield { type: 'finish', reason }\n}\n\nfunction* incomplete(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n const why = event.response?.incomplete_details?.reason\n if (why === 'max_output_tokens') {\n yield { type: 'finish', reason: { kind: 'max-tokens' } }\n return\n }\n throw new ModelError(\n `${displayName} returned an incomplete response (${why ?? 'unknown reason'})`,\n MODEL_ERROR_CODES.SERVER,\n )\n}\n\nfunction* failed(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n // A failed generation can still be billed. Preserve the provider's\n // counters before the transport records the failure and retry admission.\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n throw failedError(event.response, displayName)\n}\n\nfunction* inlineError(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n // A top-level error event carries its fields inline rather than under a\n // `response` object, so it is reshaped to reuse the same classifier.\n const inline: WireErrorBody = {\n ...event.code === undefined ? {} : { code: event.code },\n ...event.message === undefined ? {} : { message: event.message },\n }\n throw failedError({ error: inline }, displayName)\n}\n\nfunction* deltaEvent(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'response.output_text.delta': yield* textDelta(state, event); return\n case 'response.reasoning_summary_text.delta': yield* summaryDelta(state, event); return\n case 'response.reasoning_text.delta': yield* reasoningDelta(state, event); return\n case 'response.function_call_arguments.delta': yield* toolDelta(state, event); return\n case 'response.image_generation_call.partial_image': yield* partialImage(state, event); return\n default: return\n }\n}\n\nfunction createOpenItem(\n state: StreamState, item: WireOutputItem, identity: { id: string; kind: ItemKind },\n): OpenItem {\n const { id, kind } = identity\n return {\n index: state.nextIndex++,\n kind,\n text: '',\n args: '',\n callId: item.call_id ?? id,\n name: item.name ?? '',\n nativeName: nativeName(item.type),\n summaryIndex: undefined,\n phase: textPhase(item.phase),\n reasoningKind: undefined,\n }\n}\n","/**\n * Responses API SSE events to the SDK's chunk protocol.\n *\n * Two design notes worth reading before changing anything here.\n *\n * First, block correlation is keyed on `item_id`, not on the provider's\n * `output_index`. Item ids are stable and present on every delta event, whereas\n * index fields vary by event type, so keying on the id and assigning our OWN\n * indices in first-seen order is both simpler and closer to what our protocol\n * promises.\n *\n * Second, reasoning state is carried on the reasoning BLOCK\n * (`ReasoningBlock.providerState`) rather than in the stream's `replayState`\n * envelope. The envelope has to stay positionally aligned with emitted blocks and\n * is discarded whole when it drifts; attaching the state to the block it belongs\n * to cannot drift, and it survives assembly for free.\n *\n * @module ai-agent-sdk/providers/responses/translate\n */\n\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest, ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type { WireStreamEvent } from './wire.ts'\nimport { requestedImageMediaType } from './stream-items.ts'\nimport { translateEvent, type StreamState } from './stream-events.ts'\n\nexport async function* translateResponsesStream(\n events: AsyncIterable<ProtocolSseEvent>, displayName: string, request?: ProtocolRequest,\n): AsyncGenerator<ProtocolStreamChunk> {\n const state: StreamState = {\n open: new Map(), nextIndex: 0, sawToolCall: false, imageMediaType: requestedImageMediaType(request),\n }\n for await (const raw of events) {\n const event = parseEvent(raw, displayName)\n yield* translateEvent(state, event, displayName)\n if (event.type === 'response.completed' || event.type === 'response.incomplete') return\n }\n throw new ModelError(\n `${displayName} stream ended before the response completed`,\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 OpenAI Responses protocol, as a reusable {@link WireProtocol}.\n *\n * Spoken by `api.openai.com`, by the ChatGPT-backed Codex endpoint, and by a\n * growing number of compatible gateways. None of them needs its own translation\n * code — they differ only in the dialect knobs below.\n *\n * @module ai-agent-sdk/providers/protocols/openai-responses\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 { serializeResponsesRequest } from './serialize.ts'\nimport { translateResponsesStream } from './translate.ts'\nimport type { ResponsesDialect } from './wire.ts'\n\n/** Protocol id, usable as a stable string in configuration. */\nexport const OPENAI_RESPONSES_PROTOCOL_ID = 'openai-responses'\n\n/**\n * Conservative defaults.\n *\n * `store: false` because retaining prompts server-side should be an explicit\n * decision, not something an SDK turns on for you. `include` carries\n * `reasoning.encrypted_content` because without it a reasoning model loses its\n * chain of thought between a tool call and the tool's result.\n */\nconst DEFAULT_DIALECT: ResponsesDialect = Object.freeze({\n sampling: true,\n maxOutputTokens: true,\n structuredOutputs: true,\n store: false,\n include: Object.freeze(['reasoning.encrypted_content']),\n reasoningSummary: 'auto',\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 ResponsesProtocolDefinition {\n readonly kind: 'http-wire-protocol'\n readonly apiVersion: 1\n readonly id: string\n readonly defaultDialect: ResponsesDialect\n readonly exampleModel?: ModelTarget\n readonly endpointPath: (request: RuntimeProtocolRequest, dialect: ResponsesDialect) => string\n readonly protocolHeaders?: (dialect: ResponsesDialect) => Readonly<Record<string, string>>\n readonly serialize: (\n request: RuntimeProtocolRequest,\n dialect: ResponsesDialect,\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 OpenAI Responses wire protocol. */\nexport const openAiResponsesProtocol: ProtocolDefinition<ResponsesDialect>\n & ResponsesProtocolDefinition = Object.freeze({\n kind: 'http-wire-protocol' as const,\n apiVersion: 1 as const,\n id: OPENAI_RESPONSES_PROTOCOL_ID,\n defaultDialect: DEFAULT_DIALECT,\n endpointPath: () => '/responses',\n serialize(request: ProtocolRequest, dialect: ResponsesDialect): Readonly<Record<string, unknown>> {\n return serializeResponsesRequest(request, dialect) as unknown 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> => translateResponsesStream(events, displayName, request),\n})\n\nexport type { ResponsesDialect }\n"],"mappings":";;;AAMA,MAAM,4BAA4B;AAElC,SAAgB,iBAAiB,OAAyC;CACxE,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,CAAC;CACzD,MAAM,QAAQ;CACd,OAAO;EACL,GAA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OAAO;AACjG,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.15",
|
|
8
8
|
"description": "Universal OpenAI Responses and Codex 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.15"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@alvin0/ai-agent-sdk-core": "^0.1.
|
|
44
|
+
"@alvin0/ai-agent-sdk-core": "^0.1.15",
|
|
45
45
|
"@arethetypeswrong/cli": "0.18.5",
|
|
46
46
|
"playwright": "1.62.1",
|
|
47
47
|
"publint": "0.3.24",
|