/**
 * Test-connection probe for Voyage AI embeddings API.
 *
 * Makes a small real embedding call against
 *   POST https://api.voyageai.com/v1/embeddings
 * with the configured model (voyage-3) and a fixed test input. Returns
 * `ok: true` on HTTP 200, `ok: false` on auth / network / other errors.
 *
 * The probe never echoes the upstream error body — only a generic
 * canned phrase and the HTTP status code (no headers, no payload).
 */
const VOYAGE_URL = 'https://api.voyageai.com/v1/embeddings';
const VOYAGE_MODEL = 'voyage-3';
const PROBE_INPUT = 'studiograph probe';
export async function probeVoyage(apiKey) {
    const started = Date.now();
    if (!apiKey || typeof apiKey !== 'string' || apiKey.length === 0) {
        return { ok: false, message: 'No API key provided', durationMs: Date.now() - started };
    }
    try {
        const res = await fetch(VOYAGE_URL, {
            method: 'POST',
            headers: {
                'Authorization': `Bearer ${apiKey}`,
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ input: PROBE_INPUT, model: VOYAGE_MODEL }),
        });
        const durationMs = Date.now() - started;
        if (res.ok) {
            return { ok: true, durationMs };
        }
        if (res.status === 401 || res.status === 403) {
            return { ok: false, message: 'API key rejected', durationMs };
        }
        if (res.status === 429) {
            return { ok: false, message: 'Rate limited (try again shortly)', durationMs };
        }
        if (res.status >= 500) {
            return { ok: false, message: `Upstream ${res.status}`, durationMs };
        }
        return { ok: false, message: `HTTP ${res.status}`, durationMs };
    }
    catch (err) {
        return {
            ok: false,
            message: err instanceof Error && err.message ? err.message.slice(0, 100) : 'Network error',
            durationMs: Date.now() - started,
        };
    }
}
//# sourceMappingURL=voyage.js.map