import { _ as parseStrictFiniteNumber, l as asPositiveSafeInteger } from "./number-coercion-CJQ8TR--.js";
import { t as createSubsystemLogger } from "./subsystem-DE1xogkX.js";
import "./number-runtime-DBLVDypr.js";
import "./runtime-env-BIbsgQm4.js";
import "./string-coerce-runtime-6HjB7EiL.js";
import { a as getCachedLiveProviderModelRows, t as LiveModelCatalogHttpError } from "./provider-catalog-live-runtime-BiYwtjiT.js";
//#region extensions/vercel-ai-gateway/models.ts
const VERCEL_AI_GATEWAY_PROVIDER_ID = "vercel-ai-gateway";
const VERCEL_AI_GATEWAY_BASE_URL = "https://ai-gateway.vercel.sh";
const VERCEL_AI_GATEWAY_DEFAULT_MODEL_ID = "anthropic/claude-opus-4.6";
const VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF = `${VERCEL_AI_GATEWAY_PROVIDER_ID}/${VERCEL_AI_GATEWAY_DEFAULT_MODEL_ID}`;
const VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW = 2e5;
const VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS = 128e3;
const VERCEL_AI_GATEWAY_DEFAULT_COST = {
	input: 0,
	output: 0,
	cacheRead: 0,
	cacheWrite: 0
};
const log = createSubsystemLogger("agents/vercel-ai-gateway");
const VERCEL_AI_GATEWAY_DISCOVERY_CACHE_TTL_MS = 6e4;
const VERCEL_AI_GATEWAY_DISCOVERY_TIMEOUT_MS = 5e3;
const STATIC_VERCEL_AI_GATEWAY_MODEL_CATALOG = [
	{
		id: "anthropic/claude-opus-4.6",
		name: "Claude Opus 4.6",
		reasoning: true,
		input: ["text", "image"],
		contextWindow: 1e6,
		maxTokens: 128e3,
		cost: {
			input: 5,
			output: 25,
			cacheRead: .5,
			cacheWrite: 6.25
		}
	},
	{
		id: "openai/gpt-5.4",
		name: "GPT 5.4",
		reasoning: true,
		input: ["text", "image"],
		contextWindow: 2e5,
		maxTokens: 128e3,
		cost: {
			input: 2.5,
			output: 15,
			cacheRead: .25
		}
	},
	{
		id: "openai/gpt-5.4-pro",
		name: "GPT 5.4 Pro",
		reasoning: true,
		input: ["text", "image"],
		contextWindow: 2e5,
		maxTokens: 128e3,
		cost: {
			input: 30,
			output: 180,
			cacheRead: 0
		}
	},
	{
		id: "moonshotai/kimi-k2.6",
		name: "Kimi K2.6",
		reasoning: true,
		input: ["text", "image"],
		contextWindow: 262144,
		maxTokens: 262144,
		cost: {
			input: .95,
			output: 4,
			cacheRead: .16
		}
	}
];
function toPerMillionCost(value) {
	const numeric = typeof value === "number" ? value : typeof value === "string" ? parseStrictFiniteNumber(value) : void 0;
	if (numeric === void 0 || numeric < 0) return 0;
	return numeric * 1e6;
}
function normalizeCost(pricing) {
	return {
		input: toPerMillionCost(pricing?.input),
		output: toPerMillionCost(pricing?.output),
		cacheRead: toPerMillionCost(pricing?.input_cache_read),
		cacheWrite: toPerMillionCost(pricing?.input_cache_write)
	};
}
function buildStaticModelDefinition(model) {
	return {
		id: model.id,
		name: model.name,
		reasoning: model.reasoning,
		input: model.input,
		contextWindow: model.contextWindow,
		maxTokens: model.maxTokens,
		cost: {
			...VERCEL_AI_GATEWAY_DEFAULT_COST,
			...model.cost
		}
	};
}
function getStaticFallbackModel(id) {
	const fallback = STATIC_VERCEL_AI_GATEWAY_MODEL_CATALOG.find((model) => model.id === id);
	return fallback ? buildStaticModelDefinition(fallback) : void 0;
}
function getStaticVercelAiGatewayModelCatalog() {
	return STATIC_VERCEL_AI_GATEWAY_MODEL_CATALOG.map(buildStaticModelDefinition);
}
function buildDiscoveredModelDefinition(model) {
	const id = typeof model.id === "string" ? model.id.trim() : "";
	if (!id) return null;
	const fallback = getStaticFallbackModel(id);
	const contextWindow = asPositiveSafeInteger(model.context_window) ?? fallback?.contextWindow ?? 2e5;
	const maxTokens = asPositiveSafeInteger(model.max_tokens) ?? fallback?.maxTokens ?? 128e3;
	const normalizedCost = normalizeCost(model.pricing);
	return {
		id,
		name: (typeof model.name === "string" ? model.name.trim() : "") || fallback?.name || id,
		reasoning: Array.isArray(model.tags) && model.tags.includes("reasoning") ? true : fallback?.reasoning ?? false,
		input: Array.isArray(model.tags) ? model.tags.includes("vision") ? ["text", "image"] : ["text"] : fallback?.input ?? ["text"],
		contextWindow,
		maxTokens,
		cost: normalizedCost.input > 0 || normalizedCost.output > 0 || normalizedCost.cacheRead > 0 || normalizedCost.cacheWrite > 0 ? normalizedCost : fallback?.cost ?? VERCEL_AI_GATEWAY_DEFAULT_COST
	};
}
function asVercelGatewayModelShape(value) {
	if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("Vercel AI Gateway model list: malformed JSON response");
	return value;
}
async function discoverVercelAiGatewayModels() {
	if (process.env.VITEST || false) return getStaticVercelAiGatewayModelCatalog();
	try {
		const discovered = (await getCachedLiveProviderModelRows({
			providerId: VERCEL_AI_GATEWAY_PROVIDER_ID,
			endpoint: `${VERCEL_AI_GATEWAY_BASE_URL}/v1/models`,
			timeoutMs: VERCEL_AI_GATEWAY_DISCOVERY_TIMEOUT_MS,
			ttlMs: VERCEL_AI_GATEWAY_DISCOVERY_CACHE_TTL_MS,
			auditContext: "vercel-ai-gateway.models"
		})).map(asVercelGatewayModelShape).map(buildDiscoveredModelDefinition).filter((entry) => entry !== null);
		return discovered.length > 0 ? discovered : getStaticVercelAiGatewayModelCatalog();
	} catch (error) {
		if (error instanceof LiveModelCatalogHttpError) {
			log.warn(`Failed to discover Vercel AI Gateway models: HTTP ${error.status}`);
			return getStaticVercelAiGatewayModelCatalog();
		}
		log.warn(`Failed to discover Vercel AI Gateway models: ${String(error)}`);
		return getStaticVercelAiGatewayModelCatalog();
	}
}
//#endregion
export { VERCEL_AI_GATEWAY_DEFAULT_MODEL_ID as a, discoverVercelAiGatewayModels as c, VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS as i, getStaticVercelAiGatewayModelCatalog as l, VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW as n, VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF as o, VERCEL_AI_GATEWAY_DEFAULT_COST as r, VERCEL_AI_GATEWAY_PROVIDER_ID as s, VERCEL_AI_GATEWAY_BASE_URL as t };
