// src/gateway-models.ts
var DEFAULT_GATEWAY_MODEL = "claude-opus-4-6";
var BLOCKED_MODELS = /* @__PURE__ */ new Set(["gpt-5-mini", "openai/gpt-5-mini"]);
var CACHE_TTL = 10 * 60 * 1e3;
var gatewayModelsCache = null;
async function fetchGatewayModels(options) {
  const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
  if (!gatewayUrl) {
    return [];
  }
  if (gatewayModelsCache && gatewayModelsCache.url === gatewayUrl && Date.now() < gatewayModelsCache.expiry) {
    return gatewayModelsCache.models;
  }
  const modelsUrl = `${gatewayUrl}/v1/models`;
  try {
    const response = await fetch(modelsUrl);
    if (!response.ok) {
      return [];
    }
    const data = await response.json();
    const models = (data.data ?? []).filter((m) => !BLOCKED_MODELS.has(m.id));
    gatewayModelsCache = {
      models,
      expiry: Date.now() + CACHE_TTL,
      url: gatewayUrl
    };
    return models;
  } catch {
    return [];
  }
}
function isAnthropicModel(model) {
  if (model.owned_by) {
    return model.owned_by === "anthropic";
  }
  return model.id.startsWith("claude-") || model.id.startsWith("anthropic/");
}
var arrayModelsCache = null;
async function fetchArrayModels(options) {
  const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
  if (!gatewayUrl) {
    return [];
  }
  if (arrayModelsCache && arrayModelsCache.url === gatewayUrl && Date.now() < arrayModelsCache.expiry) {
    return arrayModelsCache.models;
  }
  try {
    const base = new URL(gatewayUrl);
    base.pathname = "/array/v1/models";
    base.search = "";
    base.hash = "";
    const response = await fetch(base.toString());
    if (!response.ok) {
      return [];
    }
    const data = await response.json();
    const models = Array.isArray(data) ? data : data.data ?? data.models ?? [];
    const results = [];
    for (const model of models) {
      const id = model?.id ? String(model.id) : "";
      if (!id) continue;
      results.push({ id, owned_by: model?.owned_by });
    }
    arrayModelsCache = {
      models: results,
      expiry: Date.now() + CACHE_TTL,
      url: gatewayUrl
    };
    return results;
  } catch {
    return [];
  }
}
var PROVIDER_NAMES = {
  anthropic: "Anthropic",
  openai: "OpenAI",
  "google-vertex": "Gemini"
};
function getProviderName(ownedBy) {
  return PROVIDER_NAMES[ownedBy] ?? ownedBy;
}
var PROVIDER_PREFIXES = ["anthropic/", "openai/", "google-vertex/"];
function formatGatewayModelName(model) {
  let cleanId = model.id;
  for (const prefix of PROVIDER_PREFIXES) {
    if (cleanId.startsWith(prefix)) {
      cleanId = cleanId.slice(prefix.length);
      break;
    }
  }
  cleanId = cleanId.replace(/(\d)-(\d)/g, "$1.$2");
  const words = cleanId.split(/[-_]/).map((word) => {
    if (word.match(/^[0-9.]+$/)) return word;
    return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
  });
  return words.join(" ");
}
export {
  BLOCKED_MODELS,
  DEFAULT_GATEWAY_MODEL,
  fetchArrayModels,
  fetchGatewayModels,
  formatGatewayModelName,
  getProviderName,
  isAnthropicModel
};
//# sourceMappingURL=gateway-models.js.map