"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const clients_1 = require("../../../src/clients");
const openai_1 = require("../../../src/clients/pricing/openai");
const anthropic_1 = require("../../../src/clients/pricing/anthropic");
const google_1 = require("../../../src/clients/pricing/google");
const xai_1 = require("../../../src/clients/pricing/xai");
const OUTPUT_FILE = path.join(__dirname, "completions.json");
const PROMPT = "Say hello in 5 words.";
function openaiEntries(models) {
    return models.map((model) => ({ provider: "openai", model, envKey: "OPENAI_KEY" }));
}
function anthropicEntries(models) {
    return models.map((model) => ({ provider: "anthropic", model, envKey: "ANTHROPIC_API_KEY" }));
}
function googleEntries(models) {
    return models.map((model) => ({ provider: "google", model, envKey: "GEMINI_API_KEY" }));
}
function xaiEntries(models) {
    return models.map((model) => ({ provider: "xai", model, envKey: "XAI_API_KEY" }));
}
const TEST_MODELS = [
    ...openaiEntries([...new Set([...openai_1.OpenAiChatModels, ...openai_1.OpenAiReasoningModels, ...openai_1.OpenAiResponsesOnlyModels])]),
    ...anthropicEntries(anthropic_1.AnthropicTextModels),
    ...googleEntries(google_1.GoogleTextModels),
    ...xaiEntries(xai_1.XaiTextModels),
];
function loadResults() {
    if (fs.existsSync(OUTPUT_FILE)) {
        try {
            return JSON.parse(fs.readFileSync(OUTPUT_FILE, "utf-8"));
        }
        catch {
            return {};
        }
    }
    return {};
}
function saveResults(results) {
    fs.writeFileSync(OUTPUT_FILE, JSON.stringify(results, null, 2), "utf-8");
}
function recordKey(provider, model) {
    return `${provider}::${model}`;
}
describe("Text Completions – multi-provider model verification", () => {
    let client;
    let results;
    beforeAll(() => {
        client = new clients_1.AIClient();
        results = loadResults();
    });
    afterAll(() => {
        saveResults(results);
        console.log(`\n📄 Results saved to: ${OUTPUT_FILE}`);
        console.log(`   Total records: ${Object.keys(results).length}`);
    });
    for (const { provider, model, envKey } of TEST_MODELS) {
        const key = recordKey(provider, model);
        test(`${provider} / ${model}`, async () => {
            if (results[key]) {
                const rec = results[key];
                console.log(`⏭  Skipping (already tested on ${rec.testedAt})`);
                console.log(`   Response : "${rec.response}"`);
                console.log(`   Cost     : $${rec.usd_cost?.toFixed(8) ?? "unknown"}`);
                console.log(`   Duration : ${rec.durationMs != null ? rec.durationMs + "ms" : "unknown"}`);
                expect(rec.response).toBeTruthy();
                return;
            }
            if (!process.env[envKey]) {
                console.log(`⏭  Skipping: ${envKey} not set`);
                return;
            }
            const startMs = Date.now();
            const response = await client.createCompletion(provider, {
                model,
                messages: [{ role: "user", content: PROMPT }],
                max_tokens: 2000,
                reasoning_effort: "low",
            });
            const durationMs = Date.now() - startMs;
            const text = response.choices[0]?.message?.content ?? "";
            expect(text).toBeTruthy();
            const record = {
                provider,
                model,
                prompt: PROMPT,
                response: text,
                usage: response.usage ?? {},
                durationMs,
                usd_cost: response.usd_cost,
                testedAt: new Date().toISOString(),
            };
            results[key] = record;
            saveResults(results);
            console.log(`✅ ${provider} / ${model}`);
            console.log(`   Response : "${text}"`);
            console.log(`   Tokens   : ${JSON.stringify(response.usage)}`);
            console.log(`   Cost     : $${response.usd_cost?.toFixed(8) ?? "unknown"}`);
            console.log(`   Duration : ${durationMs}ms`);
        }, 60_000);
    }
});
//# sourceMappingURL=completions.test.js.map