export function getProviderConfigFromEnv(env = process.env) {
    const kind = env.BEST_AGENT_PROVIDER_KIND;
    const model = env.BEST_AGENT_PROVIDER_MODEL;
    if (kind && model) {
        return {
            kind,
            model,
            apiKey: resolveProviderApiKey(env, kind),
            baseURL: resolveProviderBaseUrl(env, kind),
            compatibilityMode: resolveProviderCompatibilityMode(env, kind),
            systemPrompt: env.BEST_AGENT_PROVIDER_SYSTEM_PROMPT,
            timeoutMs: resolveProviderTimeoutMs(env),
        };
    }
    const inferredProviders = [
        "openai",
        "xai",
        "deepseek",
        "moonshotai",
        "aihubmix",
        "zenmux",
        "customProvider",
    ];
    for (const inferredKind of inferredProviders) {
        const inferredModel = resolveDefaultProviderModel(env, inferredKind);
        if (!inferredModel) {
            continue;
        }
        return {
            kind: inferredKind,
            model: inferredModel,
            apiKey: resolveProviderApiKey(env, inferredKind),
            baseURL: resolveProviderBaseUrl(env, inferredKind),
            compatibilityMode: resolveProviderCompatibilityMode(env, inferredKind),
            systemPrompt: env.BEST_AGENT_PROVIDER_SYSTEM_PROMPT,
            timeoutMs: resolveProviderTimeoutMs(env),
        };
    }
    return undefined;
}
function resolveProviderApiKey(env, kind) {
    const explicit = env.BEST_AGENT_PROVIDER_API_KEY;
    if (explicit) {
        return explicit;
    }
    switch (kind) {
        case "openai":
        case "openai-responses":
            return env.OPENAI_API_KEY;
        case "anthropic":
            return env.ANTHROPIC_API_KEY;
        case "google":
            return env.GOOGLE_GENERATIVE_AI_API_KEY;
        case "xai":
        case "xai-responses":
            return env.XAI_API_KEY;
        case "deepseek":
            return env.DEEPSEEK_API_KEY;
        case "moonshotai":
            return env.MOONSHOTAI_API_KEY;
        case "aihubmix":
        case "aihubmix-responses":
            return env.AIHUBMIX_API_KEY;
        case "zenmux":
            return env.ZENMUX_API_KEY;
        case "customProvider":
            return env.CUSTOM_PROVIDER_API_KEY;
    }
}
function resolveProviderBaseUrl(env, kind) {
    const explicit = env.BEST_AGENT_PROVIDER_BASE_URL;
    if (explicit) {
        return explicit;
    }
    switch (kind) {
        case "openai":
        case "openai-responses":
            return env.OPENAI_BASE_URL;
        case "xai":
        case "xai-responses":
            return env.XAI_BASE_URL;
        case "deepseek":
            return env.DEEPSEEK_BASE_URL;
        case "moonshotai":
            return env.MOONSHOTAI_BASE_URL;
        case "aihubmix":
        case "aihubmix-responses":
            return env.AIHUBMIX_BASE_URL;
        case "zenmux":
            return env.ZENMUX_BASE_URL;
        case "customProvider":
            return env.CUSTOM_PROVIDER_BASE_URL;
    }
}
function resolveProviderCompatibilityMode(env, kind) {
    const explicit = env.BEST_AGENT_PROVIDER_COMPATIBILITY_MODE;
    if (explicit) {
        return explicit;
    }
    switch (kind) {
        case "openai":
        case "openai-responses":
            return env.OPENAI_COMPATIBILITY_MODE;
        default:
            return undefined;
    }
}
function resolveProviderTimeoutMs(env) {
    const value = env.BEST_AGENT_PROVIDER_TIMEOUT_MS;
    if (!value) {
        return undefined;
    }
    const parsed = Number(value);
    return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
}
function resolveDefaultProviderModel(env, kind) {
    switch (kind) {
        case "openai":
            return env.OPENAI_MODEL;
        case "xai":
            return env.XAI_MODEL;
        case "deepseek":
            return env.DEEPSEEK_MODEL;
        case "moonshotai":
            return env.MOONSHOTAI_MODEL;
        case "aihubmix":
            return env.AIHUBMIX_MODEL;
        case "zenmux":
            return env.ZENMUX_MODEL;
        case "customProvider":
            return env.CUSTOM_PROVIDER_MODEL;
        default:
            return undefined;
    }
}
//# sourceMappingURL=provider-config-env.js.map