{"version":3,"file":"openai-responses-shared-BmnSvdKL.mjs","names":["_exhaustive"],"sources":["../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js"],"sourcesContent":["import { calculateCost } from \"../models.js\";\nimport { shortHash } from \"../utils/hash.js\";\nimport { parseStreamingJson } from \"../utils/json-parse.js\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.js\";\nimport { appendGrammarToolInputJsonDelta, getGrammarToolInput, resolveGrammarConstrainedSampling, resolveJsonSchemaStrictSampling, } from \"./constrained-sampling.js\";\nimport { transformMessages } from \"./transform-messages.js\";\n// =============================================================================\n// Utilities\n// =============================================================================\nfunction encodeTextSignatureV1(id, phase) {\n    const payload = { v: 1, id };\n    if (phase)\n        payload.phase = phase;\n    return JSON.stringify(payload);\n}\nfunction parseTextSignature(signature) {\n    if (!signature)\n        return undefined;\n    if (signature.startsWith(\"{\")) {\n        try {\n            const parsed = JSON.parse(signature);\n            if (parsed.v === 1 && typeof parsed.id === \"string\") {\n                if (parsed.phase === \"commentary\" || parsed.phase === \"final_answer\") {\n                    return { id: parsed.id, phase: parsed.phase };\n                }\n                return { id: parsed.id };\n            }\n        }\n        catch {\n            // Fall through to legacy plain-string handling.\n        }\n    }\n    return { id: signature };\n}\nfunction convertToolResultOutput(model, content) {\n    const textResult = content\n        .filter((c) => c.type === \"text\")\n        .map((c) => c.text)\n        .join(\"\\n\");\n    const images = content.filter((c) => c.type === \"image\");\n    const hasText = textResult.length > 0;\n    if (images.length === 0 || !model.input.includes(\"image\")) {\n        return sanitizeSurrogates(hasText ? textResult : images.length > 0 ? \"(see attached image)\" : \"(no tool output)\");\n    }\n    const output = [];\n    if (hasText) {\n        output.push({ type: \"input_text\", text: sanitizeSurrogates(textResult) });\n    }\n    for (const image of images) {\n        output.push({\n            type: \"input_image\",\n            detail: \"auto\",\n            image_url: `data:${image.mimeType};base64,${image.data}`,\n        });\n    }\n    return output;\n}\n// =============================================================================\n// Message conversion\n// =============================================================================\nexport function convertResponsesMessages(model, context, allowedToolCallProviders, options) {\n    const messages = [];\n    const loadedToolNames = new Set();\n    const normalizeIdPart = (part) => {\n        const sanitized = part.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n        const normalized = sanitized.length > 64 ? sanitized.slice(0, 64) : sanitized;\n        return normalized.replace(/_+$/, \"\");\n    };\n    const buildForeignResponsesItemId = (itemId) => {\n        const normalized = `fc_${shortHash(itemId)}`;\n        return normalized.length > 64 ? normalized.slice(0, 64) : normalized;\n    };\n    const normalizeToolCallId = (id, _targetModel, source) => {\n        if (!allowedToolCallProviders.has(model.provider))\n            return normalizeIdPart(id);\n        if (!id.includes(\"|\"))\n            return normalizeIdPart(id);\n        const [callId, itemId] = id.split(\"|\");\n        const normalizedCallId = normalizeIdPart(callId);\n        const isForeignToolCall = source.provider !== model.provider || source.api !== model.api;\n        let normalizedItemId = isForeignToolCall ? buildForeignResponsesItemId(itemId) : normalizeIdPart(itemId);\n        // OpenAI Responses API requires item id to start with \"fc\"\n        if (!normalizedItemId.startsWith(\"fc_\")) {\n            normalizedItemId = normalizeIdPart(`fc_${normalizedItemId}`);\n        }\n        return `${normalizedCallId}|${normalizedItemId}`;\n    };\n    const transformedMessages = transformMessages(context.messages, model, normalizeToolCallId);\n    const includeSystemPrompt = options?.includeSystemPrompt ?? true;\n    if (includeSystemPrompt && context.systemPrompt) {\n        const compat = model.compat;\n        const role = model.reasoning && compat?.supportsDeveloperRole !== false ? \"developer\" : \"system\";\n        messages.push({\n            role,\n            content: sanitizeSurrogates(context.systemPrompt),\n        });\n    }\n    let msgIndex = 0;\n    for (const msg of transformedMessages) {\n        if (msg.role === \"user\") {\n            if (typeof msg.content === \"string\") {\n                messages.push({\n                    role: \"user\",\n                    content: [{ type: \"input_text\", text: sanitizeSurrogates(msg.content) }],\n                });\n            }\n            else {\n                const content = msg.content.map((item) => {\n                    if (item.type === \"text\") {\n                        return {\n                            type: \"input_text\",\n                            text: sanitizeSurrogates(item.text),\n                        };\n                    }\n                    return {\n                        type: \"input_image\",\n                        detail: \"auto\",\n                        image_url: `data:${item.mimeType};base64,${item.data}`,\n                    };\n                });\n                if (content.length === 0)\n                    continue;\n                messages.push({\n                    role: \"user\",\n                    content,\n                });\n            }\n        }\n        else if (msg.role === \"assistant\") {\n            const output = [];\n            const assistantMsg = msg;\n            const isDifferentModel = assistantMsg.model !== model.id &&\n                assistantMsg.provider === model.provider &&\n                assistantMsg.api === model.api;\n            let textBlockIndex = 0;\n            for (const block of msg.content) {\n                if (block.type === \"thinking\") {\n                    if (block.thinkingSignature) {\n                        const reasoningItem = JSON.parse(block.thinkingSignature);\n                        output.push(reasoningItem);\n                    }\n                }\n                else if (block.type === \"text\") {\n                    const textBlock = block;\n                    const parsedSignature = parseTextSignature(textBlock.textSignature);\n                    const fallbackMessageId = textBlockIndex === 0 ? `msg_pi_${msgIndex}` : `msg_pi_${msgIndex}_${textBlockIndex}`;\n                    textBlockIndex++;\n                    // OpenAI requires id to be max 64 characters\n                    let msgId = parsedSignature?.id;\n                    if (!msgId) {\n                        msgId = fallbackMessageId;\n                    }\n                    else if (msgId.length > 64) {\n                        msgId = `msg_${shortHash(msgId)}`;\n                    }\n                    output.push({\n                        type: \"message\",\n                        role: \"assistant\",\n                        content: [{ type: \"output_text\", text: sanitizeSurrogates(textBlock.text), annotations: [] }],\n                        status: \"completed\",\n                        id: msgId,\n                        phase: parsedSignature?.phase,\n                    });\n                }\n                else if (block.type === \"toolCall\") {\n                    const toolCall = block;\n                    const [callId, itemIdRaw] = toolCall.id.split(\"|\");\n                    const customInputProperty = options?.grammarToolInputProperties?.get(toolCall.name);\n                    let itemId = itemIdRaw;\n                    // For different-model messages, set id to undefined to avoid pairing validation.\n                    // OpenAI tracks which fc_xxx IDs were paired with rs_xxx reasoning items.\n                    // By omitting the id, we avoid triggering that validation (like cross-provider does).\n                    // When replaying custom-tool calls as a function_call, also drop non-fc_* ids such as\n                    // ctc_* custom-tool ids because function_call item ids must be fc_*.\n                    if ((isDifferentModel && itemId?.startsWith(\"fc_\")) ||\n                        (customInputProperty === undefined && !itemId?.startsWith(\"fc_\"))) {\n                        itemId = undefined;\n                    }\n                    if (customInputProperty !== undefined) {\n                        output.push({\n                            type: \"custom_tool_call\",\n                            id: itemId,\n                            call_id: callId,\n                            name: toolCall.name,\n                            input: sanitizeSurrogates(getGrammarToolInput(toolCall.name, toolCall.arguments, customInputProperty)),\n                        });\n                    }\n                    else {\n                        output.push({\n                            type: \"function_call\",\n                            id: itemId,\n                            call_id: callId,\n                            name: toolCall.name,\n                            arguments: JSON.stringify(toolCall.arguments),\n                        });\n                    }\n                }\n            }\n            if (output.length === 0)\n                continue;\n            messages.push(...output);\n        }\n        else if (msg.role === \"toolResult\") {\n            const [callId] = msg.toolCallId.split(\"|\");\n            const output = convertToolResultOutput(model, msg.content);\n            if (options?.grammarToolInputProperties?.has(msg.toolName)) {\n                messages.push({\n                    type: \"custom_tool_call_output\",\n                    call_id: callId,\n                    output,\n                });\n            }\n            else {\n                messages.push({\n                    type: \"function_call_output\",\n                    call_id: callId,\n                    output,\n                });\n            }\n            const deferredTools = [];\n            for (const name of msg.addedToolNames ?? []) {\n                const tool = options?.deferredTools?.get(name);\n                if (!tool || loadedToolNames.has(name))\n                    continue;\n                loadedToolNames.add(name);\n                deferredTools.push(tool);\n            }\n            if (deferredTools.length > 0) {\n                const names = deferredTools.map((tool) => tool.name);\n                const searchCallId = `pi_tool_load_${shortHash(`${msg.toolCallId}:${names.join(\",\")}`)}`;\n                messages.push({\n                    type: \"tool_search_call\",\n                    call_id: searchCallId,\n                    execution: \"client\",\n                    status: \"completed\",\n                    arguments: { query: names.join(\" \"), limit: names.length },\n                });\n                messages.push({\n                    type: \"tool_search_output\",\n                    call_id: searchCallId,\n                    execution: \"client\",\n                    status: \"completed\",\n                    tools: convertResponsesTools(deferredTools, {\n                        ...options?.toolOptions,\n                        deferLoading: true,\n                    }),\n                });\n            }\n        }\n        msgIndex++;\n    }\n    return messages;\n}\n// =============================================================================\n// Tool conversion\n// =============================================================================\nexport function convertResponsesTools(tools, options) {\n    const defaultStrict = options?.strict === undefined ? false : options.strict;\n    const supportsStrictMode = options?.supportsStrictMode ?? true;\n    const supportsOpenAIGrammarTools = options?.supportsOpenAIGrammarTools ?? false;\n    return tools.map((tool) => {\n        const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);\n        if (grammar) {\n            return {\n                type: \"custom\",\n                name: tool.name,\n                description: tool.description,\n                format: {\n                    type: \"grammar\",\n                    syntax: grammar.format,\n                    definition: grammar.definition,\n                },\n                ...(options?.deferLoading ? { defer_loading: true } : {}),\n            };\n        }\n        const constrainedStrict = resolveJsonSchemaStrictSampling(tool, supportsStrictMode);\n        const functionTool = {\n            type: \"function\",\n            name: tool.name,\n            description: tool.description,\n            parameters: tool.parameters, // TypeBox already generates JSON Schema\n            ...(options?.deferLoading ? { defer_loading: true } : {}),\n        };\n        if (supportsStrictMode) {\n            functionTool.strict = constrainedStrict ?? defaultStrict;\n        }\n        return functionTool;\n    });\n}\nfunction getCustomToolCallInput(block) {\n    const property = block.customInput?.property;\n    if (property === undefined)\n        return \"\";\n    const value = block.arguments[property];\n    return typeof value === \"string\" ? value : \"\";\n}\nfunction appendCustomToolCallInput(block, nextInput, close) {\n    const customInput = block.customInput;\n    if (!customInput)\n        return undefined;\n    const delta = appendGrammarToolInputJsonDelta(customInput.jsonBuffer, customInput.property, nextInput, close);\n    block.arguments = { [customInput.property]: nextInput };\n    return delta;\n}\nexport async function processResponsesStream(openaiStream, output, stream, model, options) {\n    let sawTerminalResponseEvent = false;\n    const outputSlots = new Map();\n    const reasoningBlocksById = new Map();\n    const applyMessagePhaseStopReason = (item) => {\n        if (item.type === \"message\" && item.phase === \"final_answer\") {\n            output.stopReason = \"stop\";\n        }\n    };\n    const getSlot = (outputIndex, type) => {\n        const slot = outputSlots.get(outputIndex);\n        return slot?.type === type ? slot : undefined;\n    };\n    const pushToolCallDelta = (slot, delta) => {\n        if (delta === undefined)\n            return;\n        stream.push({\n            type: \"toolcall_delta\",\n            contentIndex: slot.contentIndex,\n            delta,\n            partial: output,\n        });\n    };\n    const createSlot = (outputIndex, item) => {\n        if (item.type === \"reasoning\") {\n            const block = { type: \"thinking\", thinking: \"\" };\n            output.content.push(block);\n            const slot = {\n                type: \"thinking\",\n                block,\n                contentIndex: output.content.length - 1,\n            };\n            outputSlots.set(outputIndex, slot);\n            stream.push({ type: \"thinking_start\", contentIndex: slot.contentIndex, partial: output });\n            return slot;\n        }\n        if (item.type === \"message\") {\n            applyMessagePhaseStopReason(item);\n            const block = { type: \"text\", text: \"\" };\n            output.content.push(block);\n            const slot = { type: \"text\", block, contentIndex: output.content.length - 1 };\n            outputSlots.set(outputIndex, slot);\n            stream.push({ type: \"text_start\", contentIndex: slot.contentIndex, partial: output });\n            return slot;\n        }\n        if (item.type === \"function_call\") {\n            const block = {\n                type: \"toolCall\",\n                id: `${item.call_id}|${item.id}`,\n                name: item.name,\n                arguments: {},\n                partialJson: item.arguments || \"\",\n            };\n            output.content.push(block);\n            const slot = {\n                type: \"toolCall\",\n                block,\n                contentIndex: output.content.length - 1,\n            };\n            outputSlots.set(outputIndex, slot);\n            stream.push({ type: \"toolcall_start\", contentIndex: slot.contentIndex, partial: output });\n            return slot;\n        }\n        if (item.type === \"custom_tool_call\") {\n            const inputProperty = options?.grammarToolInputProperties?.get(item.name) ?? \"input\";\n            const input = item.input || \"\";\n            const block = {\n                type: \"toolCall\",\n                id: `${item.call_id}|${item.id}`,\n                name: item.name,\n                arguments: { [inputProperty]: input },\n                customInput: {\n                    property: inputProperty,\n                    jsonBuffer: { input: \"\", started: false, closed: false },\n                },\n            };\n            output.content.push(block);\n            const slot = {\n                type: \"toolCall\",\n                block,\n                contentIndex: output.content.length - 1,\n            };\n            outputSlots.set(outputIndex, slot);\n            stream.push({ type: \"toolcall_start\", contentIndex: slot.contentIndex, partial: output });\n            return slot;\n        }\n        return undefined;\n    };\n    const getOrCreateSlot = (outputIndex, item) => {\n        return outputSlots.get(outputIndex) ?? createSlot(outputIndex, item);\n    };\n    // Azure OpenAI can omit reasoning.encrypted_content from response.output_item.done\n    // and provide it only in response.completed.response.output. Backfill the\n    // persisted reasoning signature from the terminal response to keep store:false\n    // multi-turn replay stateless. See https://github.com/earendil-works/pi/issues/6409.\n    const backfillReasoningSignatures = (responseOutput) => {\n        for (const item of responseOutput) {\n            if (item.type !== \"reasoning\" || !item.encrypted_content)\n                continue;\n            const block = reasoningBlocksById.get(item.id);\n            if (!block?.thinkingSignature)\n                continue;\n            const storedItem = JSON.parse(block.thinkingSignature);\n            if (storedItem.encrypted_content)\n                continue;\n            block.thinkingSignature = JSON.stringify({\n                ...storedItem,\n                encrypted_content: item.encrypted_content,\n            });\n        }\n    };\n    const finalizeResponse = (response) => {\n        sawTerminalResponseEvent = true;\n        backfillReasoningSignatures(response.output ?? []);\n        if (response?.id) {\n            output.responseId = response.id;\n        }\n        if (response?.usage) {\n            const inputDetails = response.usage.input_tokens_details;\n            const cachedTokens = inputDetails?.cached_tokens || 0;\n            const cacheWriteTokens = inputDetails?.cache_write_tokens || 0;\n            output.usage = {\n                // OpenAI includes cached and cache-write tokens in input_tokens, so subtract both.\n                input: Math.max(0, (response.usage.input_tokens || 0) - cachedTokens - cacheWriteTokens),\n                output: response.usage.output_tokens || 0,\n                cacheRead: cachedTokens,\n                cacheWrite: cacheWriteTokens,\n                reasoning: response.usage.output_tokens_details?.reasoning_tokens || 0,\n                totalTokens: response.usage.total_tokens || 0,\n                cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n            };\n        }\n        calculateCost(model, output.usage);\n        if (options?.applyServiceTierPricing) {\n            const serviceTier = options.resolveServiceTier\n                ? options.resolveServiceTier(response?.service_tier, options.serviceTier)\n                : (response?.service_tier ?? options.serviceTier);\n            options.applyServiceTierPricing(output.usage, serviceTier);\n        }\n        // Map status to stop reason. For incomplete responses, retain the provider's\n        // specific reason so max-output truncation and content filtering stay distinct.\n        const status = response?.status;\n        const incompleteDetails = response?.incomplete_details;\n        const incompleteReason = typeof incompleteDetails?.reason === \"string\" ? incompleteDetails.reason : undefined;\n        output.rawStopReason = incompleteReason ? `${status}.${incompleteReason}` : status;\n        const mappedStop = mapStopReason(status, incompleteReason);\n        output.stopReason = mappedStop.stopReason;\n        output.errorMessage = mappedStop.errorMessage;\n        if (output.content.some((b) => b.type === \"toolCall\") && output.stopReason === \"stop\") {\n            output.stopReason = \"toolUse\";\n        }\n    };\n    for await (const event of openaiStream) {\n        if (event.type === \"response.created\") {\n            output.responseId = event.response.id;\n        }\n        else if (event.type === \"response.output_item.added\") {\n            createSlot(event.output_index, event.item);\n        }\n        else if (event.type === \"response.reasoning_summary_text.delta\") {\n            const slot = getSlot(event.output_index, \"thinking\");\n            if (!slot)\n                continue;\n            slot.block.thinking += event.delta;\n            stream.push({\n                type: \"thinking_delta\",\n                contentIndex: slot.contentIndex,\n                delta: event.delta,\n                partial: output,\n            });\n        }\n        else if (event.type === \"response.reasoning_summary_part.done\") {\n            const slot = getSlot(event.output_index, \"thinking\");\n            if (!slot)\n                continue;\n            slot.block.thinking += \"\\n\\n\";\n            stream.push({\n                type: \"thinking_delta\",\n                contentIndex: slot.contentIndex,\n                delta: \"\\n\\n\",\n                partial: output,\n            });\n        }\n        else if (event.type === \"response.reasoning_text.delta\") {\n            const slot = getSlot(event.output_index, \"thinking\");\n            if (!slot)\n                continue;\n            slot.block.thinking += event.delta;\n            stream.push({\n                type: \"thinking_delta\",\n                contentIndex: slot.contentIndex,\n                delta: event.delta,\n                partial: output,\n            });\n        }\n        else if (event.type === \"response.output_text.delta\") {\n            const slot = getSlot(event.output_index, \"text\");\n            if (!slot)\n                continue;\n            slot.block.text += event.delta;\n            stream.push({\n                type: \"text_delta\",\n                contentIndex: slot.contentIndex,\n                delta: event.delta,\n                partial: output,\n            });\n        }\n        else if (event.type === \"response.refusal.delta\") {\n            const slot = getSlot(event.output_index, \"text\");\n            if (!slot)\n                continue;\n            slot.block.text += event.delta;\n            stream.push({\n                type: \"text_delta\",\n                contentIndex: slot.contentIndex,\n                delta: event.delta,\n                partial: output,\n            });\n        }\n        else if (event.type === \"response.function_call_arguments.delta\") {\n            const slot = getSlot(event.output_index, \"toolCall\");\n            if (!slot || slot.block.partialJson === undefined)\n                continue;\n            slot.block.partialJson += event.delta;\n            slot.block.arguments = parseStreamingJson(slot.block.partialJson);\n            pushToolCallDelta(slot, event.delta);\n        }\n        else if (event.type === \"response.function_call_arguments.done\") {\n            const slot = getSlot(event.output_index, \"toolCall\");\n            if (!slot || slot.block.partialJson === undefined)\n                continue;\n            const previousPartialJson = slot.block.partialJson;\n            slot.block.partialJson = event.arguments;\n            slot.block.arguments = parseStreamingJson(slot.block.partialJson);\n            if (event.arguments.startsWith(previousPartialJson)) {\n                const delta = event.arguments.slice(previousPartialJson.length);\n                if (delta.length > 0)\n                    pushToolCallDelta(slot, delta);\n            }\n        }\n        else if (event.type === \"response.custom_tool_call_input.delta\") {\n            const slot = getSlot(event.output_index, \"toolCall\");\n            if (!slot || !slot.block.customInput)\n                continue;\n            pushToolCallDelta(slot, appendCustomToolCallInput(slot.block, getCustomToolCallInput(slot.block) + event.delta, false));\n        }\n        else if (event.type === \"response.custom_tool_call_input.done\") {\n            const slot = getSlot(event.output_index, \"toolCall\");\n            if (!slot || !slot.block.customInput)\n                continue;\n            pushToolCallDelta(slot, appendCustomToolCallInput(slot.block, event.input, true));\n        }\n        else if (event.type === \"response.output_item.done\") {\n            const item = event.item;\n            applyMessagePhaseStopReason(item);\n            const slot = getOrCreateSlot(event.output_index, item);\n            if (item.type === \"reasoning\" && slot?.type === \"thinking\") {\n                const summaryText = item.summary?.map((s) => s.text).join(\"\\n\\n\") || \"\";\n                const contentText = item.content?.map((c) => c.text).join(\"\\n\\n\") || \"\";\n                slot.block.thinking = summaryText || contentText || slot.block.thinking;\n                slot.block.thinkingSignature = JSON.stringify(item);\n                reasoningBlocksById.set(item.id, slot.block);\n                stream.push({\n                    type: \"thinking_end\",\n                    contentIndex: slot.contentIndex,\n                    content: slot.block.thinking,\n                    partial: output,\n                });\n                outputSlots.delete(event.output_index);\n            }\n            else if (item.type === \"message\" && slot?.type === \"text\") {\n                slot.block.text = item.content?.map((c) => (c.type === \"output_text\" ? c.text : c.refusal)).join(\"\") || \"\";\n                slot.block.textSignature = encodeTextSignatureV1(item.id, item.phase ?? undefined);\n                stream.push({\n                    type: \"text_end\",\n                    contentIndex: slot.contentIndex,\n                    content: slot.block.text,\n                    partial: output,\n                });\n                outputSlots.delete(event.output_index);\n            }\n            else if (item.type === \"function_call\" &&\n                slot?.type === \"toolCall\" &&\n                slot.block.partialJson !== undefined) {\n                slot.block.arguments = parseStreamingJson(item.arguments || slot.block.partialJson || \"{}\");\n                // Finalize in-place and strip the scratch buffer so replay only\n                // carries parsed arguments.\n                delete slot.block.partialJson;\n                stream.push({\n                    type: \"toolcall_end\",\n                    contentIndex: slot.contentIndex,\n                    toolCall: slot.block,\n                    partial: output,\n                });\n                outputSlots.delete(event.output_index);\n            }\n            else if (item.type === \"custom_tool_call\" && slot?.type === \"toolCall\" && slot.block.customInput) {\n                pushToolCallDelta(slot, appendCustomToolCallInput(slot.block, item.input ?? getCustomToolCallInput(slot.block), true));\n                delete slot.block.customInput;\n                stream.push({\n                    type: \"toolcall_end\",\n                    contentIndex: slot.contentIndex,\n                    toolCall: slot.block,\n                    partial: output,\n                });\n                outputSlots.delete(event.output_index);\n            }\n        }\n        else if (event.type === \"response.completed\" || event.type === \"response.incomplete\") {\n            finalizeResponse(event.response);\n        }\n        else if (event.type === \"error\") {\n            throw new Error(`Error Code ${event.code}: ${event.message}` || \"Unknown error\");\n        }\n        else if (event.type === \"response.failed\") {\n            sawTerminalResponseEvent = true;\n            output.rawStopReason = event.response?.status;\n            const error = event.response?.error;\n            const details = event.response?.incomplete_details;\n            const msg = error\n                ? `${error.code || \"unknown\"}: ${error.message || \"no message\"}`\n                : details?.reason\n                    ? `incomplete: ${details.reason}`\n                    : \"Unknown error (no error details in response)\";\n            throw new Error(msg);\n        }\n    }\n    if (!sawTerminalResponseEvent) {\n        throw new Error(\"OpenAI Responses stream ended before a terminal response event\");\n    }\n}\nfunction mapStopReason(status, incompleteReason) {\n    if (!status)\n        return { stopReason: \"stop\" };\n    switch (status) {\n        case \"completed\":\n            return { stopReason: \"stop\" };\n        case \"incomplete\":\n            if (incompleteReason === \"max_output_tokens\") {\n                return { stopReason: \"length\" };\n            }\n            return {\n                stopReason: \"error\",\n                errorMessage: incompleteReason\n                    ? `Response incomplete: ${incompleteReason}`\n                    : \"Response incomplete without a provider reason\",\n            };\n        case \"failed\":\n        case \"cancelled\":\n            return { stopReason: \"error\" };\n        // These two are wonky ...\n        case \"in_progress\":\n        case \"queued\":\n            return { stopReason: \"stop\" };\n        default: {\n            const _exhaustive = status;\n            throw new Error(`Unhandled stop reason: ${_exhaustive}`);\n        }\n    }\n}\n//# sourceMappingURL=openai-responses-shared.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;AASA,SAAS,sBAAsB,IAAI,OAAO;CACtC,MAAM,UAAU;EAAE,GAAG;EAAG;CAAG;CAC3B,IAAI,OACA,QAAQ,QAAQ;CACpB,OAAO,KAAK,UAAU,OAAO;AACjC;AACA,SAAS,mBAAmB,WAAW;CACnC,IAAI,CAAC,WACD,OAAO,KAAA;CACX,IAAI,UAAU,WAAW,GAAG,GACxB,IAAI;EACA,MAAM,SAAS,KAAK,MAAM,SAAS;EACnC,IAAI,OAAO,MAAM,KAAK,OAAO,OAAO,OAAO,UAAU;GACjD,IAAI,OAAO,UAAU,gBAAgB,OAAO,UAAU,gBAClD,OAAO;IAAE,IAAI,OAAO;IAAI,OAAO,OAAO;GAAM;GAEhD,OAAO,EAAE,IAAI,OAAO,GAAG;EAC3B;CACJ,QACM,CAEN;CAEJ,OAAO,EAAE,IAAI,UAAU;AAC3B;AACA,SAAS,wBAAwB,OAAO,SAAS;CAC7C,MAAM,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