export const OPENAI_SMOKE_SECRET_PATTERNS = [
    {
        label: "openai api key",
        pattern: /\bsk-[A-Za-z0-9_-]{16,}\b/u,
    },
    {
        label: "openai api key",
        pattern: /\bsk-proj-[A-Za-z0-9_-]+\b/u,
    },
    {
        label: "openai api key setting",
        pattern: /\bOPENAI_API_KEY\b/u,
    },
];
export function findSmokeLeaks(value, patterns, exactSecrets = []) {
    const text = stringifyForLeakScan(value);
    const findings = new Set();
    for (const pattern of patterns) {
        if (pattern.pattern.test(text))
            findings.add(pattern.label);
    }
    for (const secret of exactSecrets) {
        if (secret && text.includes(secret))
            findings.add("configured secret value");
    }
    return [...findings];
}
export function sanitizeSmokeError(error) {
    if (error instanceof Error)
        return sanitizeDiagnostic(error.message);
    return sanitizeDiagnostic(String(error));
}
export function sanitizeDiagnostic(value) {
    return value
        .replace(/\bsk-proj-[A-Za-z0-9_-]+\b/gu, "[redacted]")
        .replace(/\bsk-[A-Za-z0-9_-]{16,}\b/gu, "[redacted]")
        .replace(/\bOPENAI_API_KEY\b/gu, "[redacted-setting]")
        .slice(0, 500);
}
export function stringifyForLeakScan(value) {
    if (typeof value === "string")
        return value;
    try {
        return JSON.stringify(value);
    }
    catch {
        return String(value);
    }
}
export function writeSmokeJson(result, stdout) {
    stdout(`${JSON.stringify(result, null, 2)}\n`);
}
export function readFlag(value) {
    return value === "1" || value?.toLowerCase() === "true";
}
export function nonEmptyEnv(env, name) {
    const value = env[name]?.trim();
    return value && value.length > 0 ? value : undefined;
}
