const PROVIDER_ORDER = ["anthropic", "openai", "gemini", "groq"];
const PROVIDER_ENV = {
  anthropic: "ANTHROPIC_API_KEY",
  openai: "OPENAI_API_KEY",
  gemini: "GOOGLE_API_KEY",
  groq: "GROQ_API_KEY"
};
function selectProvider(env) {
  const override = env.WIGOLO_LLM_PROVIDER;
  if (override && PROVIDER_ORDER.includes(override)) {
    const p = override;
    if (env[PROVIDER_ENV[p]]) return p;
  }
  for (const p of PROVIDER_ORDER) {
    if (env[PROVIDER_ENV[p]]) return p;
  }
  return null;
}
async function selectProviderWithKeyStore(env, opts) {
  const { resolveProviderKey } = await import("../../../security/key-store.js");
  const raw = env.WIGOLO_LLM_PROVIDER;
  if (raw && (raw.startsWith("http://") || raw.startsWith("https://"))) {
    return null;
  }
  if (raw && PROVIDER_ORDER.includes(raw)) {
    const p = raw;
    const key = await resolveProviderKey(p, opts);
    if (key) return { provider: p, key };
  }
  for (const p of PROVIDER_ORDER) {
    const key = await resolveProviderKey(p, opts);
    if (key) return { provider: p, key };
  }
  return null;
}
function providerEnvVar(p) {
  return PROVIDER_ENV[p];
}
function allProviders() {
  return PROVIDER_ORDER;
}
export {
  allProviders,
  providerEnvVar,
  selectProvider,
  selectProviderWithKeyStore
};
//# sourceMappingURL=select.js.map