{"version":3,"file":"google-vertex-BgGRE4WU.mjs","names":[],"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/google-vertex.js"],"sourcesContent":["import { GoogleGenAI, ResourceScope, ThinkingLevel, } from \"@google/genai\";\nimport { calculateCost, clampThinkingLevel } from \"../models.js\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.js\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.js\";\nimport { providerHeadersToRecord } from \"../utils/headers.js\";\nimport { getProviderEnvValue } from \"../utils/provider-env.js\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.js\";\nimport { convertMessages, convertTools, isThinkingPart, mapStopReason, resolveGoogleFunctionCallingMode, retainThoughtSignature, retryGoogleRequest, supportsGoogleStrictToolSampling, } from \"./google-shared.js\";\nimport { buildBaseOptions } from \"./simple-options.js\";\nconst API_VERSION = \"v1\";\nconst GCP_VERTEX_CREDENTIALS_MARKER = \"gcp-vertex-credentials\";\nconst THINKING_LEVEL_MAP = {\n    THINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,\n    MINIMAL: ThinkingLevel.MINIMAL,\n    LOW: ThinkingLevel.LOW,\n    MEDIUM: ThinkingLevel.MEDIUM,\n    HIGH: ThinkingLevel.HIGH,\n};\n// Counter for generating unique tool call IDs\nlet toolCallCounter = 0;\nexport const stream = (model, context, options) => {\n    const stream = new AssistantMessageEventStream();\n    (async () => {\n        const output = {\n            role: \"assistant\",\n            content: [],\n            api: \"google-vertex\",\n            provider: model.provider,\n            model: model.id,\n            usage: {\n                input: 0,\n                output: 0,\n                cacheRead: 0,\n                cacheWrite: 0,\n                totalTokens: 0,\n                cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n            },\n            stopReason: \"pending\",\n            timestamp: Date.now(),\n        };\n        try {\n            if (options?.fetch && options.fetch !== globalThis.fetch) {\n                throw new Error(\"Custom fetch is not supported by the Google Vertex adapter\");\n            }\n            const apiKey = resolveApiKey(options);\n            // Create the client using either a Vertex API key, if provided, or ADC with project and location\n            const client = apiKey\n                ? createClientWithApiKey(model, apiKey, options?.headers)\n                : createClient(model, resolveProject(options), resolveLocation(options), options?.headers, options?.env);\n            let params = buildParams(model, context, options);\n            const nextParams = await options?.onPayload?.(params, model);\n            if (nextParams !== undefined) {\n                params = nextParams;\n            }\n            const googleStream = await retryGoogleRequest(() => client.models.generateContentStream(params), options);\n            stream.push({ type: \"start\", partial: output });\n            let currentBlock = null;\n            const blocks = output.content;\n            const blockIndex = () => blocks.length - 1;\n            for await (const chunk of googleStream) {\n                // Vertex uses the same @google/genai GenerateContentResponse type as Gemini.\n                // responseId is documented there as an output-only identifier for each response.\n                output.responseId ||= chunk.responseId;\n                const candidate = chunk.candidates?.[0];\n                if (candidate?.content?.parts) {\n                    for (const part of candidate.content.parts) {\n                        if (part.text !== undefined) {\n                            const isThinking = isThinkingPart(part);\n                            if (!currentBlock ||\n                                (isThinking && currentBlock.type !== \"thinking\") ||\n                                (!isThinking && currentBlock.type !== \"text\")) {\n                                if (currentBlock) {\n                                    if (currentBlock.type === \"text\") {\n                                        stream.push({\n                                            type: \"text_end\",\n                                            contentIndex: blocks.length - 1,\n                                            content: currentBlock.text,\n                                            partial: output,\n                                        });\n                                    }\n                                    else {\n                                        stream.push({\n                                            type: \"thinking_end\",\n                                            contentIndex: blockIndex(),\n                                            content: currentBlock.thinking,\n                                            partial: output,\n                                        });\n                                    }\n                                }\n                                if (isThinking) {\n                                    currentBlock = { type: \"thinking\", thinking: \"\", thinkingSignature: undefined };\n                                    output.content.push(currentBlock);\n                                    stream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n                                }\n                                else {\n                                    currentBlock = { type: \"text\", text: \"\" };\n                                    output.content.push(currentBlock);\n                                    stream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n                                }\n                            }\n                            if (currentBlock.type === \"thinking\") {\n                                currentBlock.thinking += part.text;\n                                currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);\n                                stream.push({\n                                    type: \"thinking_delta\",\n                                    contentIndex: blockIndex(),\n                                    delta: part.text,\n                                    partial: output,\n                                });\n                            }\n                            else {\n                                currentBlock.text += part.text;\n                                currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);\n                                stream.push({\n                                    type: \"text_delta\",\n                                    contentIndex: blockIndex(),\n                                    delta: part.text,\n                                    partial: output,\n                                });\n                            }\n                        }\n                        if (part.functionCall) {\n                            if (currentBlock) {\n                                if (currentBlock.type === \"text\") {\n                                    stream.push({\n                                        type: \"text_end\",\n                                        contentIndex: blockIndex(),\n                                        content: currentBlock.text,\n                                        partial: output,\n                                    });\n                                }\n                                else {\n                                    stream.push({\n                                        type: \"thinking_end\",\n                                        contentIndex: blockIndex(),\n                                        content: currentBlock.thinking,\n                                        partial: output,\n                                    });\n                                }\n                                currentBlock = null;\n                            }\n                            const providedId = part.functionCall.id;\n                            const needsNewId = !providedId || output.content.some((b) => b.type === \"toolCall\" && b.id === providedId);\n                            const toolCallId = needsNewId\n                                ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`\n                                : providedId;\n                            const toolCall = {\n                                type: \"toolCall\",\n                                id: toolCallId,\n                                name: part.functionCall.name || \"\",\n                                arguments: part.functionCall.args ?? {},\n                                ...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),\n                            };\n                            output.content.push(toolCall);\n                            stream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n                            stream.push({\n                                type: \"toolcall_delta\",\n                                contentIndex: blockIndex(),\n                                delta: JSON.stringify(toolCall.arguments),\n                                partial: output,\n                            });\n                            stream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n                        }\n                    }\n                }\n                if (candidate?.finishReason) {\n                    output.rawStopReason = candidate.finishReason;\n                    output.stopReason = mapStopReason(candidate.finishReason);\n                    if (output.content.some((b) => b.type === \"toolCall\")) {\n                        output.stopReason = \"toolUse\";\n                    }\n                }\n                if (chunk.usageMetadata) {\n                    output.usage = {\n                        input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),\n                        output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),\n                        cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,\n                        cacheWrite: 0,\n                        reasoning: chunk.usageMetadata.thoughtsTokenCount || 0,\n                        totalTokens: chunk.usageMetadata.totalTokenCount || 0,\n                        cost: {\n                            input: 0,\n                            output: 0,\n                            cacheRead: 0,\n                            cacheWrite: 0,\n                            total: 0,\n                        },\n                    };\n                    calculateCost(model, output.usage);\n                }\n            }\n            if (currentBlock) {\n                if (currentBlock.type === \"text\") {\n                    stream.push({\n                        type: \"text_end\",\n                        contentIndex: blockIndex(),\n                        content: currentBlock.text,\n                        partial: output,\n                    });\n                }\n                else {\n                    stream.push({\n                        type: \"thinking_end\",\n                        contentIndex: blockIndex(),\n                        content: currentBlock.thinking,\n                        partial: output,\n                    });\n                }\n            }\n            if (options?.signal?.aborted) {\n                throw new Error(\"Request was aborted\");\n            }\n            if (output.stopReason === \"pending\") {\n                throw new Error(\"Google Vertex stream ended without a finish reason\");\n            }\n            if (output.stopReason === \"aborted\" || output.stopReason === \"error\") {\n                const errorMessage = output.rawStopReason\n                    ? `Provider stopped with: ${output.rawStopReason}`\n                    : \"An unknown error occurred\";\n                throw new Error(errorMessage);\n            }\n            stream.push({ type: \"done\", reason: output.stopReason, message: output });\n            stream.end();\n        }\n        catch (error) {\n            // Remove internal index property used during streaming\n            for (const block of output.content) {\n                if (\"index\" in block) {\n                    delete block.index;\n                }\n            }\n            output.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n            output.errorMessage = formatProviderError(normalizeProviderError(error));\n            stream.push({ type: \"error\", reason: output.stopReason, error: output });\n            stream.end();\n        }\n    })();\n    return stream;\n};\nexport const streamSimple = (model, context, options) => {\n    const base = buildBaseOptions(model, context, options, undefined);\n    if (!options?.reasoning) {\n        return stream(model, context, {\n            ...base,\n            thinking: { enabled: false },\n        });\n    }\n    const clampedReasoning = clampThinkingLevel(model, options.reasoning);\n    const effort = (clampedReasoning === \"off\" ? \"high\" : clampedReasoning);\n    const geminiModel = model;\n    if (isGemini3ProModel(geminiModel) || isGemini3FlashModel(geminiModel)) {\n        return stream(model, context, {\n            ...base,\n            thinking: {\n                enabled: true,\n                level: getGemini3ThinkingLevel(effort, geminiModel),\n            },\n        });\n    }\n    return stream(model, context, {\n        ...base,\n        thinking: {\n            enabled: true,\n            budgetTokens: getGoogleBudget(geminiModel, effort, options.thinkingBudgets),\n        },\n    });\n};\nfunction createClient(model, project, location, optionsHeaders, env) {\n    const googleAuthOptions = buildGoogleAuthOptions(env);\n    return new GoogleGenAI({\n        vertexai: true,\n        project,\n        location,\n        apiVersion: API_VERSION,\n        ...(googleAuthOptions ? { googleAuthOptions } : {}),\n        httpOptions: buildHttpOptions(model, optionsHeaders),\n    });\n}\nfunction createClientWithApiKey(model, apiKey, optionsHeaders) {\n    return new GoogleGenAI({\n        vertexai: true,\n        apiKey,\n        apiVersion: API_VERSION,\n        httpOptions: buildHttpOptions(model, optionsHeaders),\n    });\n}\nfunction buildHttpOptions(model, optionsHeaders) {\n    const httpOptions = {};\n    const baseUrl = resolveCustomBaseUrl(model.baseUrl);\n    if (baseUrl) {\n        httpOptions.baseUrl = baseUrl;\n        httpOptions.baseUrlResourceScope = ResourceScope.COLLECTION;\n        if (baseUrlIncludesApiVersion(baseUrl)) {\n            httpOptions.apiVersion = \"\";\n        }\n    }\n    const headers = providerHeadersToRecord({ ...model.headers, ...optionsHeaders });\n    if (headers) {\n        httpOptions.headers = headers;\n    }\n    return Object.keys(httpOptions).length > 0 ? httpOptions : undefined;\n}\nfunction resolveCustomBaseUrl(baseUrl) {\n    const trimmed = baseUrl.trim();\n    if (!trimmed || trimmed.includes(\"{location}\")) {\n        return undefined;\n    }\n    return trimmed;\n}\nfunction baseUrlIncludesApiVersion(baseUrl) {\n    try {\n        const url = new URL(baseUrl);\n        return url.pathname.split(\"/\").some((part) => /^v\\d+(?:beta\\d*)?$/.test(part));\n    }\n    catch {\n        return /(?:^|\\/)v\\d+(?:beta\\d*)?(?:\\/|$)/.test(baseUrl);\n    }\n}\nfunction buildGoogleAuthOptions(env) {\n    const keyFilename = getProviderEnvValue(\"GOOGLE_APPLICATION_CREDENTIALS\", env);\n    return keyFilename ? { keyFilename } : undefined;\n}\nfunction resolveApiKey(options) {\n    const apiKey = options?.apiKey?.trim();\n    if (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {\n        return undefined;\n    }\n    return apiKey;\n}\nfunction isPlaceholderApiKey(apiKey) {\n    return /^<[^>]+>$/.test(apiKey);\n}\nfunction resolveProject(options) {\n    const project = options?.project ||\n        getProviderEnvValue(\"GOOGLE_CLOUD_PROJECT\", options?.env) ||\n        getProviderEnvValue(\"GCLOUD_PROJECT\", options?.env);\n    if (!project) {\n        throw new Error(\"Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.\");\n    }\n    return project;\n}\nfunction resolveLocation(options) {\n    const location = options?.location || getProviderEnvValue(\"GOOGLE_CLOUD_LOCATION\", options?.env);\n    if (!location) {\n        throw new Error(\"Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.\");\n    }\n    return location;\n}\nfunction buildParams(model, context, options = {}) {\n    const contents = convertMessages(model, context);\n    const generationConfig = {};\n    if (options.temperature !== undefined) {\n        generationConfig.temperature = options.temperature;\n    }\n    if (options.maxTokens !== undefined) {\n        generationConfig.maxOutputTokens = options.maxTokens;\n    }\n    const functionCallingMode = context.tools?.length\n        ? resolveGoogleFunctionCallingMode(context.tools, options.toolChoice, supportsGoogleStrictToolSampling(model.id))\n        : undefined;\n    const config = {\n        ...(Object.keys(generationConfig).length > 0 && generationConfig),\n        ...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),\n        ...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),\n        ...(functionCallingMode !== undefined && {\n            toolConfig: { functionCallingConfig: { mode: functionCallingMode } },\n        }),\n    };\n    if (options.thinking?.enabled && model.reasoning) {\n        const thinkingConfig = { includeThoughts: true };\n        if (options.thinking.level !== undefined) {\n            thinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];\n        }\n        else if (options.thinking.budgetTokens !== undefined) {\n            thinkingConfig.thinkingBudget = options.thinking.budgetTokens;\n        }\n        config.thinkingConfig = thinkingConfig;\n    }\n    else if (model.reasoning && options.thinking && !options.thinking.enabled) {\n        config.thinkingConfig = getDisabledThinkingConfig(model);\n    }\n    if (options.signal) {\n        if (options.signal.aborted) {\n            throw new Error(\"Request aborted\");\n        }\n        config.abortSignal = options.signal;\n    }\n    const params = {\n        model: model.id,\n        contents,\n        config,\n    };\n    return params;\n}\nfunction isGemini3ProModel(model) {\n    return /gemini-3(?:\\.\\d+)?-pro/.test(model.id.toLowerCase());\n}\nfunction isGemini3FlashModel(model) {\n    const id = model.id.toLowerCase();\n    return /gemini-3(?:\\.\\d+)?-flash/.test(id) || id === \"gemini-flash-latest\" || id === \"gemini-flash-lite-latest\";\n}\nfunction getDisabledThinkingConfig(model) {\n    // Google docs: Gemini 3.1 Pro cannot disable thinking, and Gemini 3 Flash / Flash-Lite\n    // do not support full thinking-off either. For Gemini 3 models, use the lowest supported\n    // thinkingLevel without includeThoughts so hidden thinking remains invisible to pi.\n    const geminiModel = model;\n    if (isGemini3ProModel(geminiModel)) {\n        return { thinkingLevel: ThinkingLevel.LOW };\n    }\n    if (isGemini3FlashModel(geminiModel)) {\n        return { thinkingLevel: ThinkingLevel.MINIMAL };\n    }\n    // Gemini 2.x supports disabling via thinkingBudget = 0.\n    return { thinkingBudget: 0 };\n}\nfunction getGemini3ThinkingLevel(effort, model) {\n    if (isGemini3ProModel(model)) {\n        switch (effort) {\n            case \"minimal\":\n            case \"low\":\n                return \"LOW\";\n            case \"medium\":\n            case \"high\":\n                return \"HIGH\";\n        }\n    }\n    switch (effort) {\n        case \"minimal\":\n            return \"MINIMAL\";\n        case \"low\":\n            return \"LOW\";\n        case \"medium\":\n            return \"MEDIUM\";\n        case \"high\":\n            return \"HIGH\";\n    }\n}\nfunction getGoogleBudget(model, effort, customBudgets) {\n    if (customBudgets?.[effort] !== undefined) {\n        return customBudgets[effort];\n    }\n    if (model.id.includes(\"2.5-pro\")) {\n        const budgets = {\n            minimal: 128,\n            low: 2048,\n            medium: 8192,\n            high: 32768,\n        };\n        return budgets[effort];\n    }\n    if (model.id.includes(\"2.5-flash\")) {\n        const budgets = {\n            minimal: 128,\n            low: 2048,\n            medium: 8192,\n            high: 24576,\n        };\n        return budgets[effort];\n    }\n    return -1;\n}\n//# sourceMappingURL=google-vertex.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;;;;AASA,MAAM,cAAc;AACpB,MAAM,gCAAgC;AACtC,MAAM,qBAAqB;CACvB,4BAA4B,cAAc;CAC1C,SAAS,cAAc;CACvB,KAAK,cAAc;CACnB,QAAQ,cAAc;CACtB,MAAM,cAAc;AACxB;AAEA,IAAI,kBAAkB;AACtB,MAAa,UAAU,OAAO,SAAS,YAAY;CAC/C,MAAM,SAAS,IAAI,4BAA4B;CAC/C,CAAC,YAAY;EACT,MAAM,SAAS;GACX,MAAM;GACN,SAAS,CAAC;GACV,KAAK;GACL,UAAU,MAAM;GAChB,OAAO,MAAM;GACb,OAAO;IACH,OAAO;IACP,QAAQ;IACR,WAAW;IACX,YAAY;IACZ,aAAa;IACb,MAAM;KAAE,OAAO;KAAG,QAAQ;KAAG,WAAW;KAAG,YAAY;KAAG,OAAO;IAAE;GACvE;GACA,YAAY;GACZ,WAAW,KAAK,IAAI;EACxB;EACA,IAAI;GACA,IAAI,SAAS,SAAS,QAAQ,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