{"version":3,"file":"simple-options-B_GO8FDE.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/models.js","../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/constrained-sampling.js","../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/utils/sanitize-unicode.js","../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/transform-messages.js","../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/utils/estimate.js","../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/simple-options.js"],"sourcesContent":["import { lazyStream } from \"./api/lazy.js\";\nimport { defaultProviderAuthContext as defaultAuthContext } from \"./auth/context.js\";\nimport { InMemoryCredentialStore } from \"./auth/credential-store.js\";\nimport { ModelsError, resolveProviderAuth } from \"./auth/resolve.js\";\nimport { InMemoryModelsStore } from \"./models-store.js\";\nimport { operationSignal, raceWithAbortSignal } from \"./utils/abort.js\";\nexport { ModelsError } from \"./auth/resolve.js\";\nfunction mergeHeaders(base, override) {\n    if (!base && !override)\n        return undefined;\n    const merged = { ...base };\n    for (const [name, value] of Object.entries(override ?? {})) {\n        const lowerName = name.toLowerCase();\n        for (const existingName of Object.keys(merged)) {\n            if (existingName.toLowerCase() === lowerName)\n                delete merged[existingName];\n        }\n        merged[name] = value;\n    }\n    return merged;\n}\nclass ModelsImpl {\n    providers = new Map();\n    credentials;\n    modelsStore;\n    authContext;\n    refreshGenerations = new Map();\n    refreshControllers = new Map();\n    publicationChains = new Map();\n    constructor(options) {\n        this.credentials = options?.credentials ?? new InMemoryCredentialStore();\n        this.modelsStore = options?.modelsStore ?? new InMemoryModelsStore();\n        this.authContext = options?.authContext ?? defaultAuthContext();\n    }\n    setProvider(provider) {\n        this.supersedeProviderRefresh(provider.id);\n        this.providers.set(provider.id, provider);\n    }\n    deleteProvider(id) {\n        this.supersedeProviderRefresh(id);\n        this.providers.delete(id);\n    }\n    clearProviders() {\n        for (const id of new Set([...this.providers.keys(), ...this.refreshControllers.keys()])) {\n            this.supersedeProviderRefresh(id);\n        }\n        this.providers.clear();\n    }\n    getProviders() {\n        return Array.from(this.providers.values());\n    }\n    getProvider(id) {\n        return this.providers.get(id);\n    }\n    getModels(provider) {\n        if (provider !== undefined) {\n            const entry = this.providers.get(provider);\n            if (!entry)\n                return [];\n            try {\n                return entry.getModels();\n            }\n            catch {\n                return [];\n            }\n        }\n        const models = [];\n        for (const entry of this.providers.values()) {\n            try {\n                models.push(...entry.getModels());\n            }\n            catch {\n                // Best-effort: ill-behaved providers yield no models.\n            }\n        }\n        return models;\n    }\n    getModel(provider, id) {\n        return this.getModels(provider).find((model) => model.id === id);\n    }\n    supersedeProviderRefresh(providerId) {\n        const generation = (this.refreshGenerations.get(providerId) ?? 0) + 1;\n        this.refreshGenerations.set(providerId, generation);\n        const previous = this.refreshControllers.get(providerId);\n        if (previous) {\n            this.refreshControllers.delete(providerId);\n            previous.abort();\n        }\n        return generation;\n    }\n    beginProviderRefresh(providerId) {\n        const generation = this.supersedeProviderRefresh(providerId);\n        const controller = new AbortController();\n        this.refreshControllers.set(providerId, controller);\n        return { generation, controller };\n    }\n    publishProviderModels(providerId, generation, signal, publication) {\n        const previous = this.publicationChains.get(providerId) ?? Promise.resolve();\n        const queued = (async () => {\n            await previous.catch(() => { });\n            if (signal.aborted || this.refreshGenerations.get(providerId) !== generation)\n                return false;\n            if (publication.persist === null) {\n                await this.modelsStore.delete(providerId, { signal });\n            }\n            else if (publication.persist !== undefined) {\n                await this.modelsStore.write(providerId, structuredClone(publication.persist), { signal });\n            }\n            if (signal.aborted || this.refreshGenerations.get(providerId) !== generation)\n                return false;\n            publication.update?.();\n            return true;\n        })();\n        const tail = queued.catch(() => { });\n        this.publicationChains.set(providerId, tail);\n        void tail.then(() => {\n            if (this.publicationChains.get(providerId) === tail)\n                this.publicationChains.delete(providerId);\n        });\n        return raceWithAbortSignal(queued, signal);\n    }\n    async runProviderRefreshPhase(provider, credential, allowNetwork, force, generation, signal) {\n        const stored = await this.modelsStore.read(provider.id, { signal });\n        await provider.refreshModels({\n            credential,\n            stored: stored ? structuredClone(stored) : undefined,\n            publish: (publication) => this.publishProviderModels(provider.id, generation, signal, publication),\n            allowNetwork,\n            force: allowNetwork ? force : undefined,\n            signal,\n        });\n    }\n    async refresh(options = {}) {\n        const allowNetwork = options.allowNetwork ?? true;\n        const callerSignal = operationSignal(options.signal);\n        const errors = new Map();\n        if (callerSignal.aborted)\n            return { aborted: true, errors };\n        const selected = options.providers ? new Set(options.providers) : undefined;\n        const refreshable = Array.from(this.providers.values()).filter((provider) => provider.refreshModels !== undefined && (!selected || selected.has(provider.id)));\n        const refresh = Promise.all(refreshable.map(async (provider) => {\n            const { generation, controller } = this.beginProviderRefresh(provider.id);\n            const signal = AbortSignal.any([callerSignal, controller.signal]);\n            const operation = (async () => {\n                let storedCredential;\n                let credentialError;\n                try {\n                    storedCredential = await this.readCredential(provider.id, signal);\n                }\n                catch (error) {\n                    credentialError = error;\n                }\n                // Restore cached provider state before auth resolution or network access.\n                await this.runProviderRefreshPhase(provider, storedCredential, false, undefined, generation, signal);\n                if (credentialError !== undefined)\n                    throw credentialError;\n                if (!allowNetwork || signal.aborted)\n                    return;\n                const credential = await this.resolveRefreshCredential(provider, storedCredential, signal);\n                if (!credential)\n                    return;\n                await this.runProviderRefreshPhase(provider, credential, true, options.force, generation, signal);\n            })();\n            try {\n                await raceWithAbortSignal(operation, signal);\n            }\n            catch (error) {\n                if (!signal.aborted) {\n                    errors.set(provider.id, error instanceof Error\n                        ? error\n                        : new ModelsError(\"model_source\", `Model refresh failed for ${provider.id}`, { cause: error }));\n                }\n            }\n            finally {\n                if (this.refreshControllers.get(provider.id) === controller) {\n                    this.refreshControllers.delete(provider.id);\n                }\n            }\n        }));\n        try {\n            await raceWithAbortSignal(refresh, callerSignal);\n        }\n        catch (error) {\n            if (!callerSignal.aborted)\n                throw error;\n        }\n        return { aborted: callerSignal.aborted, errors: new Map(errors) };\n    }\n    async resolveRefreshCredential(provider, stored, signal) {\n        if (stored?.type === \"oauth\") {\n            const oauth = provider.auth.oauth;\n            if (!oauth)\n                return undefined;\n            if (Date.now() < stored.expires)\n                return stored;\n            if (signal.aborted)\n                return undefined;\n            const post = await this.credentials.modify(provider.id, async (current) => {\n                if (current?.type !== \"oauth\" || Date.now() < current.expires)\n                    return undefined;\n                return oauth.refresh(current, signal);\n            }, { signal });\n            return post?.type === \"oauth\" ? post : undefined;\n        }\n        const apiKey = provider.auth.apiKey;\n        if (!apiKey)\n            return undefined;\n        const credential = stored?.type === \"api_key\" ? stored : undefined;\n        const result = await apiKey.resolve({ ctx: this.authContext, credential, signal });\n        if (!result)\n            return undefined;\n        return { type: \"api_key\", key: result.auth.apiKey, env: result.env };\n    }\n    async readCredential(providerId, signal) {\n        try {\n            return await this.credentials.read(providerId, { signal });\n        }\n        catch (error) {\n            throw new ModelsError(\"auth\", `Credential store read failed for ${providerId}`, { cause: error });\n        }\n    }\n    async checkProviderAuth(provider, credential, signal) {\n        if (credential?.type === \"oauth\") {\n            return provider.auth.oauth ? { source: \"OAuth\", type: \"oauth\" } : undefined;\n        }\n        const apiKey = provider.auth.apiKey;\n        if (!apiKey)\n            return undefined;\n        if (apiKey.check) {\n            try {\n                return await apiKey.check({\n                    ctx: this.authContext,\n                    credential: credential?.type === \"api_key\" ? credential : undefined,\n                    signal,\n                });\n            }\n            catch (error) {\n                throw new ModelsError(\"auth\", `API key auth check failed for provider ${provider.id}`, { cause: error });\n            }\n        }\n        const resolution = await resolveProviderAuth(provider, this.credentials, this.authContext, { signal });\n        return resolution ? { source: resolution.source, type: \"api_key\" } : undefined;\n    }\n    checkAuth(providerId, options) {\n        const signal = operationSignal(options?.signal);\n        const check = (async () => {\n            signal.throwIfAborted();\n            const provider = this.providers.get(providerId);\n            if (!provider)\n                return undefined;\n            return this.checkProviderAuth(provider, await this.readCredential(providerId, signal), signal);\n        })();\n        return raceWithAbortSignal(check, signal);\n    }\n    getAvailable(providerId, options) {\n        const signal = operationSignal(options?.signal);\n        const available = (async () => {\n            signal.throwIfAborted();\n            const providers = providerId\n                ? [this.providers.get(providerId)].filter((entry) => entry !== undefined)\n                : this.getProviders();\n            const checks = await Promise.all(providers.map(async (provider) => {\n                const credential = await this.readCredential(provider.id, signal);\n                return { provider, credential, auth: await this.checkProviderAuth(provider, credential, signal) };\n            }));\n            return checks.flatMap(({ provider, credential, auth }) => {\n                if (!auth)\n                    return [];\n                const models = provider.getModels();\n                return provider.filterModels?.(models, credential) ?? models;\n            });\n        })();\n        return raceWithAbortSignal(available, signal);\n    }\n    async getAuth(providerOrModel, overrides) {\n        const signal = operationSignal(overrides?.signal);\n        const providerId = typeof providerOrModel === \"string\" ? providerOrModel : providerOrModel.provider;\n        const provider = this.providers.get(providerId);\n        if (!provider)\n            return undefined;\n        const result = await resolveProviderAuth(provider, this.credentials, this.authContext, { ...overrides, signal });\n        if (!result || typeof providerOrModel === \"string\" || !providerOrModel.headers)\n            return result;\n        return {\n            ...result,\n            auth: {\n                ...result.auth,\n                headers: mergeHeaders(result.auth.headers, providerOrModel.headers),\n            },\n        };\n    }\n    async login(providerId, type, interaction) {\n        const signal = operationSignal(interaction.signal);\n        signal.throwIfAborted();\n        const provider = this.providers.get(providerId);\n        if (!provider)\n            throw new ModelsError(\"provider\", `Unknown provider: ${providerId}`);\n        const method = type === \"oauth\" ? provider.auth.oauth : provider.auth.apiKey;\n        if (!method?.login) {\n            throw new ModelsError(\"auth\", `${provider.name} does not support ${type} login`);\n        }\n        const loginOperation = method.login({ ...interaction, signal });\n        const credential = await raceWithAbortSignal(loginOperation, signal);\n        let mutationStarted = false;\n        let markMutationStarted;\n        const started = new Promise((resolve) => {\n            markMutationStarted = resolve;\n        });\n        const mutation = this.credentials.modify(providerId, async () => {\n            mutationStarted = true;\n            markMutationStarted?.();\n            return credential;\n        }, { signal });\n        void mutation.catch(() => { });\n        try {\n            await new Promise((resolve, reject) => {\n                const onAbort = () => {\n                    if (!mutationStarted)\n                        reject(signal.reason);\n                };\n                signal.addEventListener(\"abort\", onAbort, { once: true });\n                void Promise.race([started, mutation]).then(() => {\n                    signal.removeEventListener(\"abort\", onAbort);\n                    resolve();\n                }, (error) => {\n                    signal.removeEventListener(\"abort\", onAbort);\n                    reject(error);\n                });\n                if (signal.aborted)\n                    onAbort();\n            });\n            await mutation;\n        }\n        catch (error) {\n            signal.throwIfAborted();\n            throw new ModelsError(\"auth\", `Credential store modify failed for ${providerId}`, { cause: error });\n        }\n        return credential;\n    }\n    async logout(providerId, options) {\n        const signal = operationSignal(options?.signal);\n        signal.throwIfAborted();\n        try {\n            await this.credentials.delete(providerId, { signal });\n        }\n        catch (error) {\n            signal.throwIfAborted();\n            throw new ModelsError(\"auth\", `Credential store delete failed for ${providerId}`, { cause: error });\n        }\n    }\n    requireProvider(model) {\n        const provider = this.providers.get(model.provider);\n        if (!provider) {\n            throw new ModelsError(\"provider\", `Unknown provider: ${model.provider}`);\n        }\n        return provider;\n    }\n    async applyAuth(model, options) {\n        this.requireProvider(model);\n        const resolution = await this.getAuth(model, {\n            apiKey: options?.apiKey,\n            env: options?.env,\n            signal: options?.signal,\n        });\n        if (!resolution) {\n            throw new ModelsError(\"auth\", `Provider is not configured: ${model.provider}`);\n        }\n        const auth = resolution.auth;\n        // Explicit request options win per-field; the Models-only transform runs last.\n        const apiKey = options?.apiKey ?? auth.apiKey;\n        let headers = mergeHeaders(auth.headers, options?.headers);\n        if (options?.transformHeaders)\n            headers = await options.transformHeaders(headers ?? {});\n        const env = resolution.env || options?.env ? { ...(resolution.env ?? {}), ...(options?.env ?? {}) } : undefined;\n        const requestModel = auth.baseUrl ? { ...model, baseUrl: auth.baseUrl } : model;\n        const { transformHeaders: _transformHeaders, ...providerOptions } = options ?? {};\n        const requestOptions = { ...providerOptions, apiKey, headers, env };\n        return { requestModel, requestOptions };\n    }\n    stream(model, context, options) {\n        return lazyStream(model, async () => {\n            const provider = this.requireProvider(model);\n            const { requestModel, requestOptions } = await this.applyAuth(model, options);\n            return provider.stream(requestModel, context, requestOptions);\n        });\n    }\n    async complete(model, context, options) {\n        return this.stream(model, context, options).result();\n    }\n    streamSimple(model, context, options) {\n        return lazyStream(model, async () => {\n            const provider = this.requireProvider(model);\n            const { requestModel, requestOptions } = await this.applyAuth(model, options);\n            return provider.streamSimple(requestModel, context, requestOptions);\n        });\n    }\n    async completeSimple(model, context, options) {\n        return this.streamSimple(model, context, options).result();\n    }\n    async fetchDeferred(model, handle, options) {\n        return lazyStream(model, async () => {\n            const provider = this.requireProvider(model);\n            if (!provider.fetchDeferred) {\n                throw new ModelsError(\"provider\", `Provider ${model.provider} does not support deferred responses`);\n            }\n            const { requestModel, requestOptions } = await this.applyAuth(model, options);\n            return provider.fetchDeferred(requestModel, handle, requestOptions);\n        }).result();\n    }\n    async cancelDeferred(model, handle, options) {\n        const provider = this.requireProvider(model);\n        if (!provider.cancelDeferred) {\n            throw new ModelsError(\"provider\", `Provider ${model.provider} does not support deferred responses`);\n        }\n        const { requestModel, requestOptions } = await this.applyAuth(model, options);\n        await provider.cancelDeferred(requestModel, handle, requestOptions);\n    }\n}\nexport function createModels(options) {\n    return new ModelsImpl(options);\n}\n/**\n * Builds a provider from parts. Built-in provider factories and models.json\n * custom providers both go through this. A single `api` streams all models;\n * an `api` map dispatches on `model.api`, and a model whose api has no entry\n * produces a stream error.\n */\nexport function createProvider(input) {\n    const baselineModels = input.models;\n    let dynamicModels = [];\n    const fetchModels = input.fetchModels;\n    const currentModels = () => {\n        const merged = [...baselineModels];\n        for (const model of dynamicModels) {\n            const index = merged.findIndex((entry) => entry.id === model.id);\n            if (index >= 0)\n                merged[index] = model;\n            else\n                merged.push(model);\n        }\n        return merged;\n    };\n    const single = typeof input.api.stream === \"function\" ? input.api : undefined;\n    const byApi = single ? undefined : input.api;\n    const apiFor = (model) => single ?? byApi?.[model.api];\n    const dispatch = (model, run) => {\n        const streams = apiFor(model);\n        if (!streams) {\n            return lazyStream(model, async () => {\n                throw new ModelsError(\"stream\", `Provider ${input.id} has no API implementation for \"${model.api}\"`);\n            });\n        }\n        return run(streams);\n    };\n    const provider = {\n        id: input.id,\n        name: input.name ?? input.id,\n        baseUrl: input.baseUrl,\n        headers: input.headers,\n        auth: input.auth,\n        getModels: currentModels,\n        refreshModels: fetchModels\n            ? async (context) => {\n                if (context.stored) {\n                    const restored = context.stored.models\n                        .filter((model) => model.provider === input.id)\n                        .map((model) => model);\n                    if (!(await context.publish({\n                        update: () => {\n                            dynamicModels = restored;\n                        },\n                    }))) {\n                        return;\n                    }\n                }\n                if (!context.allowNetwork || context.signal.aborted)\n                    return;\n                const refreshed = await fetchModels(context);\n                if (context.signal.aborted)\n                    return;\n                await context.publish({\n                    persist: { models: refreshed, checkedAt: Date.now() },\n                    update: () => {\n                        dynamicModels = refreshed;\n                    },\n                });\n            }\n            : undefined,\n        filterModels: input.filterModels,\n        stream: (model, context, options) => dispatch(model, (streams) => streams.stream(model, context, options)),\n        streamSimple: (model, context, options) => dispatch(model, (streams) => streams.streamSimple(model, context, options)),\n    };\n    const streams = single ? [single] : Object.values(byApi ?? {}).filter((entry) => entry !== undefined);\n    if (streams.some((entry) => entry.fetchDeferred !== undefined)) {\n        provider.fetchDeferred = (model, handle, options) => lazyStream(model, async () => {\n            const implementation = apiFor(model);\n            if (!implementation?.fetchDeferred) {\n                throw new ModelsError(\"provider\", `Provider ${input.id} does not support deferred responses for \"${model.api}\"`);\n            }\n            return implementation.fetchDeferred(model, handle, options);\n        });\n    }\n    if (streams.some((entry) => entry.cancelDeferred !== undefined)) {\n        provider.cancelDeferred = async (model, handle, options) => {\n            const implementation = apiFor(model);\n            if (!implementation?.cancelDeferred) {\n                throw new ModelsError(\"provider\", `Provider ${input.id} cannot cancel deferred responses for \"${model.api}\"`);\n            }\n            await implementation.cancelDeferred(model, handle, options);\n        };\n    }\n    return provider;\n}\n/**\n * Runtime-checked narrowing for dynamically looked-up models:\n *\n * ```ts\n * const model = models.getModel(\"anthropic\", \"claude-opus-4-7\");\n * if (model && hasApi(model, \"anthropic-messages\")) {\n *   // model: Model<\"anthropic-messages\">, stream options fully typed\n * }\n * ```\n */\nexport function hasApi(model, api) {\n    return model.api === api;\n}\nexport function calculateCost(model, usage) {\n    const inputTokens = usage.input + usage.cacheRead + usage.cacheWrite;\n    let rates = model.cost;\n    let matchedThreshold = -1;\n    for (const tier of model.cost.tiers ?? []) {\n        if (inputTokens > tier.inputTokensAbove && tier.inputTokensAbove > matchedThreshold) {\n            rates = tier;\n            matchedThreshold = tier.inputTokensAbove;\n        }\n    }\n    // Anthropic charges 2x base input for 1h cache writes.\n    const longWrite = usage.cacheWrite1h ?? 0;\n    const shortWrite = usage.cacheWrite - longWrite;\n    usage.cost.input = (rates.input / 1000000) * usage.input;\n    usage.cost.output = (rates.output / 1000000) * usage.output;\n    usage.cost.cacheRead = (rates.cacheRead / 1000000) * usage.cacheRead;\n    usage.cost.cacheWrite = (rates.cacheWrite * shortWrite + rates.input * 2 * longWrite) / 1000000;\n    usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;\n    return usage.cost;\n}\nconst EXTENDED_THINKING_LEVELS = [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"];\nexport function getSupportedThinkingLevels(model) {\n    if (!model.reasoning)\n        return [\"off\"];\n    return EXTENDED_THINKING_LEVELS.filter((level) => {\n        const mapped = model.thinkingLevelMap?.[level];\n        if (mapped === null)\n            return false;\n        if (level === \"xhigh\" || level === \"max\")\n            return mapped !== undefined;\n        return true;\n    });\n}\nexport function clampThinkingLevel(model, level) {\n    const availableLevels = getSupportedThinkingLevels(model);\n    if (availableLevels.includes(level))\n        return level;\n    const requestedIndex = EXTENDED_THINKING_LEVELS.indexOf(level);\n    if (requestedIndex === -1)\n        return availableLevels[0] ?? \"off\";\n    for (let i = requestedIndex; i < EXTENDED_THINKING_LEVELS.length; i++) {\n        const candidate = EXTENDED_THINKING_LEVELS[i];\n        if (availableLevels.includes(candidate))\n            return candidate;\n    }\n    for (let i = requestedIndex - 1; i >= 0; i--) {\n        const candidate = EXTENDED_THINKING_LEVELS[i];\n        if (availableLevels.includes(candidate))\n            return candidate;\n    }\n    return availableLevels[0] ?? \"off\";\n}\n/**\n * Check if two models are equal by comparing both their id and provider.\n * Returns false if either model is null or undefined.\n */\nexport function modelsAreEqual(a, b) {\n    if (!a || !b)\n        return false;\n    return a.id === b.id && a.provider === b.provider;\n}\n//# sourceMappingURL=models.js.map","export function getGrammarToolInput(toolName, arguments_, inputProperty) {\n    const input = arguments_[inputProperty];\n    if (typeof input !== \"string\") {\n        throw new Error(`Grammar tool call \"${toolName}\" requires argument \"${inputProperty}\" to be a string.`);\n    }\n    return input;\n}\nexport function appendGrammarToolInputJsonDelta(buffer, inputProperty, nextInput, close) {\n    if (buffer.closed) {\n        if (close && nextInput === buffer.input)\n            return undefined;\n        throw new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n    }\n    if (!nextInput.startsWith(buffer.input)) {\n        throw new Error(`grammar tool input for property \"${inputProperty}\" changed non-monotonically`);\n    }\n    const inputDelta = nextInput.slice(buffer.input.length);\n    if (!close && inputDelta.length === 0)\n        return undefined;\n    let delta = \"\";\n    if (!buffer.started) {\n        delta += `{${JSON.stringify(inputProperty)}:\"`;\n        buffer.started = true;\n    }\n    delta += JSON.stringify(inputDelta).slice(1, -1);\n    buffer.input = nextInput;\n    if (close) {\n        delta += '\"}';\n        buffer.closed = true;\n    }\n    return delta;\n}\nfunction inferGrammarInputProperty(tool) {\n    const schema = tool.parameters;\n    if (schema.type !== \"object\") {\n        throw new Error(\"grammar constrained sampling requires an object parameter schema\");\n    }\n    if (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== \"string\") {\n        throw new Error(\"grammar constrained sampling requires exactly one required string property\");\n    }\n    const inputProperty = schema.required[0];\n    if (!schema.properties?.[inputProperty]) {\n        throw new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);\n    }\n    if (schema.properties[inputProperty]?.type !== \"string\") {\n        throw new Error(`grammar constrained sampling property ${inputProperty} must have type string`);\n    }\n    return inputProperty;\n}\nexport function resolveJsonSchemaStrictSampling(tool, supportsStrictMode) {\n    const config = tool.constrainedSampling;\n    if (!config || config.type !== \"json_schema\") {\n        return undefined;\n    }\n    if (supportsStrictMode) {\n        return true;\n    }\n    if (config.strict === \"require\") {\n        throw new Error(`Tool \"${tool.name}\" requires JSON-schema constrained sampling, but strict tools are unsupported.`);\n    }\n    return undefined;\n}\nexport function resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools) {\n    const config = tool.constrainedSampling;\n    if (!config || config.type !== \"grammar\") {\n        return undefined;\n    }\n    if (!supportsOpenAIGrammarTools) {\n        return undefined;\n    }\n    const larkDefinition = config.variants.openai_lark;\n    const regexDefinition = config.variants.openai_regex;\n    const hasLarkDefinition = typeof larkDefinition === \"string\" && larkDefinition.trim().length > 0;\n    const hasRegexDefinition = typeof regexDefinition === \"string\" && regexDefinition.trim().length > 0;\n    if (!hasLarkDefinition && !hasRegexDefinition) {\n        throw new Error(`Tool \"${tool.name}\" cannot use grammar constrained sampling: no supported grammar variant was provided.`);\n    }\n    try {\n        return {\n            format: hasLarkDefinition ? \"lark\" : \"regex\",\n            definition: hasLarkDefinition ? larkDefinition : regexDefinition,\n            inputProperty: inferGrammarInputProperty(tool),\n        };\n    }\n    catch (error) {\n        const message = error instanceof Error ? error.message : String(error);\n        throw new Error(`Tool \"${tool.name}\" cannot use grammar constrained sampling: ${message}.`);\n    }\n}\nexport function createGrammarToolInputProperties(tools, supportsOpenAIGrammarTools) {\n    const properties = new Map();\n    for (const tool of tools ?? []) {\n        const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);\n        if (grammar) {\n            properties.set(tool.name, grammar.inputProperty);\n        }\n    }\n    return properties;\n}\n//# sourceMappingURL=constrained-sampling.js.map","/**\n * Removes unpaired Unicode surrogate characters from a string.\n *\n * Unpaired surrogates (high surrogates 0xD800-0xDBFF without matching low surrogates 0xDC00-0xDFFF,\n * or vice versa) cause JSON serialization errors in many API providers.\n *\n * Valid emoji and other characters outside the Basic Multilingual Plane use properly paired\n * surrogates and will NOT be affected by this function.\n *\n * @param text - The text to sanitize\n * @returns The sanitized text with unpaired surrogates removed\n *\n * @example\n * // Valid emoji (properly paired surrogates) are preserved\n * sanitizeSurrogates(\"Hello 🙈 World\") // => \"Hello 🙈 World\"\n *\n * // Unpaired high surrogate is removed\n * const unpaired = String.fromCharCode(0xD83D); // high surrogate without low\n * sanitizeSurrogates(`Text ${unpaired} here`) // => \"Text  here\"\n */\nexport function sanitizeSurrogates(text) {\n    // Replace unpaired high surrogates (0xD800-0xDBFF not followed by low surrogate)\n    // Replace unpaired low surrogates (0xDC00-0xDFFF not preceded by high surrogate)\n    return text.replace(/[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/g, \"\");\n}\n//# sourceMappingURL=sanitize-unicode.js.map","const NON_VISION_USER_IMAGE_PLACEHOLDER = \"(image omitted: model does not support images)\";\nconst NON_VISION_TOOL_IMAGE_PLACEHOLDER = \"(tool image omitted: model does not support images)\";\nfunction replaceImagesWithPlaceholder(content, placeholder) {\n    const result = [];\n    let previousWasPlaceholder = false;\n    for (const block of content) {\n        if (block.type === \"image\") {\n            if (!previousWasPlaceholder) {\n                result.push({ type: \"text\", text: placeholder });\n            }\n            previousWasPlaceholder = true;\n            continue;\n        }\n        result.push(block);\n        previousWasPlaceholder = block.text === placeholder;\n    }\n    return result;\n}\nfunction downgradeUnsupportedImages(messages, model) {\n    if (model.input.includes(\"image\")) {\n        return messages;\n    }\n    return messages.map((msg) => {\n        if (msg.role === \"user\" && Array.isArray(msg.content)) {\n            return {\n                ...msg,\n                content: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER),\n            };\n        }\n        if (msg.role === \"toolResult\") {\n            return {\n                ...msg,\n                content: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER),\n            };\n        }\n        return msg;\n    });\n}\n/**\n * Normalize tool call ID for cross-provider compatibility.\n * OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.\n * Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).\n */\nexport function transformMessages(messages, model, normalizeToolCallId) {\n    // Build a map of original tool call IDs to normalized IDs\n    const toolCallIdMap = new Map();\n    // Normalize null/undefined content from untyped callers (custom tools, hand-built\n    // histories, old session files) so downstream code can rely on the type contract.\n    const normalizedMessages = messages.map((msg) => (msg.content == null ? { ...msg, content: [] } : msg));\n    const imageAwareMessages = downgradeUnsupportedImages(normalizedMessages, model);\n    // First pass: transform messages (unsupported image downgrade, thinking blocks, tool call ID normalization)\n    const transformed = imageAwareMessages.map((msg) => {\n        // User messages pass through unchanged\n        if (msg.role === \"user\") {\n            return msg;\n        }\n        // Handle toolResult messages - normalize toolCallId if we have a mapping\n        if (msg.role === \"toolResult\") {\n            const normalizedId = toolCallIdMap.get(msg.toolCallId);\n            if (normalizedId && normalizedId !== msg.toolCallId) {\n                return { ...msg, toolCallId: normalizedId };\n            }\n            return msg;\n        }\n        // Assistant messages need transformation check\n        if (msg.role === \"assistant\") {\n            const assistantMsg = msg;\n            const isSameModel = assistantMsg.provider === model.provider &&\n                assistantMsg.api === model.api &&\n                assistantMsg.model === model.id;\n            const transformedContent = assistantMsg.content.flatMap((block) => {\n                if (block.type === \"thinking\") {\n                    // Redacted thinking is opaque encrypted content, only valid for the same model.\n                    // Drop it for cross-model to avoid API errors.\n                    if (block.redacted) {\n                        return isSameModel ? block : [];\n                    }\n                    // For same model: keep thinking blocks with signatures (needed for replay)\n                    // even if the thinking text is empty (OpenAI encrypted reasoning)\n                    if (isSameModel && block.thinkingSignature)\n                        return block;\n                    // Skip empty thinking blocks, convert others to plain text\n                    if (!block.thinking || block.thinking.trim() === \"\")\n                        return [];\n                    if (isSameModel)\n                        return block;\n                    return {\n                        type: \"text\",\n                        text: block.thinking,\n                    };\n                }\n                if (block.type === \"text\") {\n                    if (isSameModel)\n                        return block;\n                    return {\n                        type: \"text\",\n                        text: block.text,\n                    };\n                }\n                if (block.type === \"toolCall\") {\n                    const toolCall = block;\n                    let normalizedToolCall = toolCall;\n                    if (!isSameModel && toolCall.thoughtSignature) {\n                        normalizedToolCall = { ...toolCall };\n                        delete normalizedToolCall.thoughtSignature;\n                    }\n                    if (!isSameModel && normalizeToolCallId) {\n                        const normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);\n                        if (normalizedId !== toolCall.id) {\n                            toolCallIdMap.set(toolCall.id, normalizedId);\n                            normalizedToolCall = { ...normalizedToolCall, id: normalizedId };\n                        }\n                    }\n                    return normalizedToolCall;\n                }\n                return block;\n            });\n            return {\n                ...assistantMsg,\n                content: transformedContent,\n            };\n        }\n        return msg;\n    });\n    // Second pass: insert synthetic empty tool results for orphaned tool calls\n    // This preserves thinking signatures and satisfies API requirements\n    const result = [];\n    let pendingToolCalls = [];\n    let existingToolResultIds = new Set();\n    const insertSyntheticToolResults = () => {\n        if (pendingToolCalls.length > 0) {\n            for (const tc of pendingToolCalls) {\n                if (!existingToolResultIds.has(tc.id)) {\n                    result.push({\n                        role: \"toolResult\",\n                        toolCallId: tc.id,\n                        toolName: tc.name,\n                        content: [{ type: \"text\", text: \"No result provided\" }],\n                        isError: true,\n                        timestamp: Date.now(),\n                    });\n                }\n            }\n            pendingToolCalls = [];\n            existingToolResultIds = new Set();\n        }\n    };\n    for (let i = 0; i < transformed.length; i++) {\n        const msg = transformed[i];\n        if (msg.role === \"assistant\") {\n            // If we have pending orphaned tool calls from a previous assistant, insert synthetic results now\n            insertSyntheticToolResults();\n            // Skip errored/aborted assistant messages entirely.\n            // These are incomplete turns that shouldn't be replayed:\n            // - May have partial content (reasoning without message, incomplete tool calls)\n            // - Replaying them can cause API errors (e.g., OpenAI \"reasoning without following item\")\n            // - The model should retry from the last valid state\n            const assistantMsg = msg;\n            if (assistantMsg.stopReason === \"error\" || assistantMsg.stopReason === \"aborted\") {\n                continue;\n            }\n            // Track tool calls from this assistant message\n            const toolCalls = assistantMsg.content.filter((b) => b.type === \"toolCall\");\n            if (toolCalls.length > 0) {\n                pendingToolCalls = toolCalls;\n                existingToolResultIds = new Set();\n            }\n            result.push(msg);\n        }\n        else if (msg.role === \"toolResult\") {\n            existingToolResultIds.add(msg.toolCallId);\n            result.push(msg);\n        }\n        else if (msg.role === \"user\") {\n            // User message interrupts tool flow - insert synthetic results for orphaned calls\n            insertSyntheticToolResults();\n            result.push(msg);\n        }\n        else {\n            result.push(msg);\n        }\n    }\n    // If the conversation ends with unresolved tool calls, synthesize results now.\n    insertSyntheticToolResults();\n    return result;\n}\n//# sourceMappingURL=transform-messages.js.map","const CHARS_PER_TOKEN = 4;\nconst ESTIMATED_IMAGE_CHARS = 4800;\nexport function calculateContextTokens(usage) {\n    return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;\n}\nfunction safeJsonStringify(value) {\n    try {\n        return JSON.stringify(value) ?? \"undefined\";\n    }\n    catch {\n        return \"[unserializable]\";\n    }\n}\nfunction estimateTextAndImageContentChars(content) {\n    if (typeof content === \"string\")\n        return content.length;\n    let chars = 0;\n    for (const block of content)\n        chars += block.type === \"text\" ? block.text.length : ESTIMATED_IMAGE_CHARS;\n    return chars;\n}\nexport function estimateTextTokens(text) {\n    return Math.ceil(text.length / CHARS_PER_TOKEN);\n}\nexport function estimateTextAndImageContentTokens(content) {\n    return Math.ceil(estimateTextAndImageContentChars(content) / CHARS_PER_TOKEN);\n}\nexport function estimateMessageTokens(message) {\n    let chars = 0;\n    if (message.role === \"user\")\n        return estimateTextAndImageContentTokens(message.content);\n    if (message.role === \"toolResult\")\n        return estimateTextAndImageContentTokens(message.content);\n    for (const block of message.content) {\n        if (block.type === \"text\") {\n            chars += block.text.length;\n        }\n        else if (block.type === \"thinking\") {\n            chars += block.thinking.length;\n        }\n        else {\n            chars += block.name.length + safeJsonStringify(block.arguments).length;\n        }\n    }\n    return Math.ceil(chars / CHARS_PER_TOKEN);\n}\nfunction getLastAssistantUsageInfo(messages) {\n    let latestPrefixTimestamp = Number.NEGATIVE_INFINITY;\n    let usageInfo;\n    for (let i = 0; i < messages.length; i++) {\n        const message = messages[i];\n        if (message.role === \"assistant\") {\n            const assistant = message;\n            // A newer prefix message was inserted after this response (for example, a\n            // compaction summary), so its usage cannot describe the current prefix.\n            const usageAppliesToPrefix = assistant.timestamp >= latestPrefixTimestamp;\n            if (usageAppliesToPrefix &&\n                assistant.stopReason !== \"aborted\" &&\n                assistant.stopReason !== \"error\" &&\n                calculateContextTokens(assistant.usage) > 0) {\n                usageInfo = { usage: assistant.usage, index: i };\n            }\n        }\n        latestPrefixTimestamp = Math.max(latestPrefixTimestamp, message.timestamp);\n    }\n    return usageInfo;\n}\nfunction estimateMessages(messages) {\n    const usageInfo = getLastAssistantUsageInfo(messages);\n    if (usageInfo) {\n        const usageTokens = calculateContextTokens(usageInfo.usage);\n        let trailingTokens = 0;\n        for (let i = usageInfo.index + 1; i < messages.length; i++) {\n            trailingTokens += estimateMessageTokens(messages[i]);\n        }\n        return { tokens: usageTokens + trailingTokens, usageTokens, trailingTokens, lastUsageIndex: usageInfo.index };\n    }\n    let tokens = 0;\n    for (const message of messages)\n        tokens += estimateMessageTokens(message);\n    return { tokens, usageTokens: 0, trailingTokens: tokens, lastUsageIndex: null };\n}\nfunction estimateToolsTokens(tools) {\n    if (!tools || tools.length === 0)\n        return 0;\n    return estimateTextTokens(safeJsonStringify(tools));\n}\nfunction isMessageArray(value) {\n    return Array.isArray(value);\n}\nexport function estimateContextTokens(context) {\n    if (isMessageArray(context))\n        return estimateMessages(context);\n    const estimate = estimateMessages(context.messages);\n    if (estimate.lastUsageIndex !== null) {\n        const addedNames = new Set(context.messages\n            .slice(estimate.lastUsageIndex + 1)\n            .filter((message) => message.role === \"toolResult\")\n            .flatMap((message) => message.addedToolNames ?? []));\n        const addedToolTokens = estimateToolsTokens(context.tools?.filter((tool) => addedNames.has(tool.name)));\n        return {\n            tokens: estimate.tokens + addedToolTokens,\n            usageTokens: estimate.usageTokens,\n            trailingTokens: estimate.trailingTokens + addedToolTokens,\n            lastUsageIndex: estimate.lastUsageIndex,\n        };\n    }\n    const prefixTokens = (context.systemPrompt ? estimateTextTokens(context.systemPrompt) : 0) + estimateToolsTokens(context.tools);\n    return {\n        tokens: estimate.tokens + prefixTokens,\n        usageTokens: estimate.usageTokens,\n        trailingTokens: estimate.trailingTokens + prefixTokens,\n        lastUsageIndex: estimate.lastUsageIndex,\n    };\n}\n//# sourceMappingURL=estimate.js.map","import { estimateContextTokens } from \"../utils/estimate.js\";\nconst CONTEXT_SAFETY_TOKENS = 4096;\nconst MIN_MAX_TOKENS = 1;\nexport function clampMaxTokensToContext(model, context, maxTokens) {\n    if (model.contextWindow <= 0)\n        return Math.max(MIN_MAX_TOKENS, maxTokens);\n    const available = model.contextWindow - estimateContextTokens(context).tokens - CONTEXT_SAFETY_TOKENS;\n    return Math.min(maxTokens, Math.max(MIN_MAX_TOKENS, available));\n}\nexport function buildBaseOptions(model, context, options, apiKey) {\n    const samplingParams = model.samplingParams || options?.samplingParams\n        ? { ...model.samplingParams, ...options?.samplingParams }\n        : undefined;\n    return {\n        temperature: options?.temperature,\n        samplingParams,\n        maxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),\n        signal: options?.signal,\n        telemetryContext: options?.telemetryContext,\n        apiKey: apiKey || options?.apiKey,\n        fetch: options?.fetch,\n        transport: options?.transport,\n        cacheRetention: options?.cacheRetention,\n        sessionId: options?.sessionId,\n        headers: options?.headers,\n        onPayload: options?.onPayload,\n        onResponse: options?.onResponse,\n        timeoutMs: options?.timeoutMs,\n        websocketConnectTimeoutMs: options?.websocketConnectTimeoutMs,\n        maxRetries: options?.maxRetries,\n        maxRetryDelayMs: options?.maxRetryDelayMs,\n        metadata: options?.metadata,\n        env: options?.env,\n    };\n}\n/** Tokens always left for the answer when a thinking budget shares the response ceiling. */\nexport const MIN_ANSWER_TOKENS = 1024;\nexport function clampReasoning(effort) {\n    return effort === \"xhigh\" || effort === \"max\" ? \"high\" : effort;\n}\nexport function adjustMaxTokensForThinking(\n// Undefined means no explicit caller cap. Use the model cap and fit thinking inside it.\nbaseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {\n    const defaultBudgets = {\n        minimal: 1024,\n        low: 2048,\n        medium: 8192,\n        high: 16384,\n    };\n    const budgets = { ...defaultBudgets, ...customBudgets };\n    const level = clampReasoning(reasoningLevel);\n    let thinkingBudget = budgets[level];\n    const maxTokens = baseMaxTokens === undefined ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);\n    if (maxTokens <= thinkingBudget) {\n        thinkingBudget = Math.max(0, maxTokens - MIN_ANSWER_TOKENS);\n    }\n    return { maxTokens, thinkingBudget };\n}\n//# sourceMappingURL=simple-options.js.map"],"x_google_ignoreList":[0,1,2,3,4,5],"mappings":";;AA8gBA,SAAgB,cAAc,OAAO,OAAO;CACxC,MAAM,cAAc,MAAM,QAAQ,MAAM,YAAY,MAAM;CAC1D,IAAI,QAAQ,MAAM;CAClB,IAAI,mBAAmB;CACvB,KAAK,MAAM,QAAQ,MAAM,KAAK,SAAS,CAAC,GACpC,IAAI,cAAc,KAAK,oBAAoB,KAAK,mBAAmB,kBAAkB;EACjF,QAAQ;EACR,mBAAmB,KAAK;CAC5B;CAGJ,MAAM,YAAY,MAAM,gBAAgB;CACxC,MAAM,aAAa,MAAM,aAAa;CACtC,M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