// engine/llm-providers/key-manager.ts — API key management.
// SPEC-083 AC-11
/**
 * Check if an API key environment variable is set and matches the expected pattern.
 * Never logs or returns the actual key value — only status.
 */
export function checkApiKey(envVarName, keyPattern) {
    if (!envVarName) {
        // Provider doesn't require an API key (e.g., Ollama)
        return 'configured';
    }
    const value = process.env[envVarName];
    if (!value) {
        return 'missing';
    }
    if (keyPattern && !new RegExp(keyPattern).test(value)) {
        return 'invalid_format';
    }
    return 'configured';
}
/**
 * Check API keys for multiple environment variable names (supports multiple keys per provider).
 * Returns 'configured' if at least one key is valid.
 */
export function checkMultipleKeys(envVarNames, keyPattern) {
    if (envVarNames.length === 0) {
        return 'configured';
    }
    const statuses = envVarNames.map((name) => checkApiKey(name, keyPattern));
    if (statuses.some((s) => s === 'configured')) {
        return 'configured';
    }
    if (statuses.some((s) => s === 'invalid_format')) {
        return 'invalid_format';
    }
    return 'missing';
}
/**
 * Get a summary of API key status for all providers.
 */
export function getKeyStatusSummary(providers) {
    return providers.map((p) => ({
        providerId: p.id,
        status: checkApiKey(p.apiKeyEnv, p.keyPattern),
    }));
}
//# sourceMappingURL=key-manager.js.map