import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
export class ApiKeyResolver {
    async resolveAnthropicKey(projectPath) {
        const envKey = process.env.PLANU_ANTHROPIC_API_KEY ?? process.env.ANTHROPIC_API_KEY;
        if (envKey?.trim()) {
            return envKey.trim();
        }
        for (const file of [
            join(projectPath, 'src/config/api-keys.json'),
            join(projectPath, '.planu/api-keys.json'),
        ]) {
            const key = await readKeyFile(file);
            if (key) {
                return key;
            }
        }
        return undefined;
    }
}
async function readKeyFile(path) {
    try {
        const parsed = JSON.parse(await readFile(path, 'utf-8'));
        const key = parsed.anthropic?.apiKey;
        return key?.trim() ? key.trim() : undefined;
    }
    catch {
        return undefined;
    }
}
//# sourceMappingURL=api-key-resolver.js.map