// src/backends/models.ts
var FALLBACK_MODELS = {
  claude: [
    "claude-sonnet-4-6",
    "claude-opus-4-6",
    "claude-haiku-4-5"
  ],
  opencode: [
    "anthropic/claude-sonnet-4-6",
    "anthropic/claude-opus-4-6",
    "openai/gpt-5.4",
    "openai/gpt-5.4-mini"
  ],
  codex: [
    "gpt-5.4-mini",
    "gpt-5.4",
    "gpt-5.3-codex",
    "codex-mini-latest",
    "codex-latest"
  ],
  gemini: [
    "gemini-3.1-pro-preview",
    "gemini-3.1-flash-preview",
    "gemini-2.5-pro",
    "gemini-2.5-flash",
    "gemini-2.0-flash",
    "gemini-2.0-pro"
  ],
  factory: [
    "claude-sonnet-4-6",
    "claude-opus-4-6",
    "gpt-5.4",
    "gemini-3.1-pro-preview"
  ],
  pi: [
    "anthropic/claude-sonnet-4-6",
    "anthropic/claude-opus-4-6",
    "openai/gpt-5.4",
    "google/gemini-2.5-flash"
  ]
};
var MODELS = FALLBACK_MODELS;
function inferEngineFromModel(model) {
  const base = model.replace(/^(anthropic|openai|google)\//, "");
  if (base.startsWith("gemini-")) return "gemini";
  if (base.startsWith("gpt-") || base.startsWith("o1-") || base.startsWith("o3-") || base.startsWith("o4-") || base.startsWith("codex-") || base.startsWith("chatgpt-")) return "codex";
  if (base.startsWith("claude-")) return "claude";
  return null;
}
function isValidModelForEngine(engine, model) {
  const allowed = FALLBACK_MODELS[engine];
  if (!allowed) return true;
  if (allowed.includes(model)) return true;
  const engineProviderMap = {
    claude: ["claude-"],
    gemini: ["gemini-"],
    codex: ["gpt-", "o1-", "o3-", "o4-", "codex-", "chatgpt-"]
  };
  const cloudPrefixes = ["claude-", "gpt-", "o1-", "o3-", "o4-", "codex-", "chatgpt-", "gemini-"];
  const isLocal = !model.includes("/") && !cloudPrefixes.some((p) => model.startsWith(p));
  if (isLocal) return true;
  const requiredPrefixes = engineProviderMap[engine];
  if (requiredPrefixes) {
    const modelBase = model.replace(/^(anthropic|openai|google)\//, "");
    const matchesAny = requiredPrefixes.some((p) => modelBase.startsWith(p));
    if (!matchesAny) return false;
  }
  return true;
}

export {
  FALLBACK_MODELS,
  MODELS,
  inferEngineFromModel,
  isValidModelForEngine
};
