"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const LLMProvider_js_1 = require("../../lib/v3/llm/LLMProvider.js");
const sdkErrors_js_1 = require("../../lib/v3/types/public/sdkErrors.js");
// Mock client options with fake API keys for testing
const mockClientOptions = { apiKey: "test-api-key-for-testing" };
(0, vitest_1.describe)("Model format deprecation", () => {
    (0, vitest_1.describe)("UnsupportedModelError", () => {
        (0, vitest_1.it)("includes guidance to use provider/model format for unknown model names", () => {
            const error = new sdkErrors_js_1.UnsupportedModelError([
                "gpt-4o",
                "claude-3-5-sonnet-latest",
            ]);
            // Should mention the new format
            (0, vitest_1.expect)(error.message).toContain("provider/model");
            // Should include link to docs
            (0, vitest_1.expect)(error.message).toContain("https://docs.stagehand.dev/v3/configuration/models");
        });
        (0, vitest_1.it)("includes example of provider/model format", () => {
            const error = new sdkErrors_js_1.UnsupportedModelError(["gpt-4o"]);
            // Should provide examples like openai/gpt-4o
            (0, vitest_1.expect)(error.message).toContain("openai/gpt-4o");
            (0, vitest_1.expect)(error.message).toContain("anthropic/claude-sonnet-4");
        });
        (0, vitest_1.it)("works with feature parameter", () => {
            const error = new sdkErrors_js_1.UnsupportedModelError(["gpt-4o"], "extract");
            (0, vitest_1.expect)(error.message).toContain("extract");
            (0, vitest_1.expect)(error.message).toContain("provider/model");
            (0, vitest_1.expect)(error.message).toContain("https://docs.stagehand.dev/v3/configuration/models");
        });
    });
    (0, vitest_1.describe)("LLMProvider.getClient deprecation warning", () => {
        (0, vitest_1.it)("logs deprecation warning for legacy model names", () => {
            const logs = [];
            const logger = (line) => logs.push(line);
            const provider = new LLMProvider_js_1.LLMProvider(logger);
            // Using a legacy model name like "gpt-4o" instead of "openai/gpt-4o"
            // Should not throw, but should log a deprecation warning
            const client = provider.getClient("gpt-4o", mockClientOptions);
            // Should return a client (not throw)
            (0, vitest_1.expect)(client).toBeDefined();
            // Should have logged a deprecation warning at level 0
            const deprecationWarning = logs.find((log) => log.message.toLowerCase().includes("deprecated") ||
                log.message.toLowerCase().includes("deprecation"));
            (0, vitest_1.expect)(deprecationWarning).toBeDefined();
            (0, vitest_1.expect)(deprecationWarning.level).toBe(0);
        });
        (0, vitest_1.it)("deprecation warning mentions provider/model format", () => {
            const logs = [];
            const logger = (line) => logs.push(line);
            const provider = new LLMProvider_js_1.LLMProvider(logger);
            provider.getClient("gpt-4o", mockClientOptions);
            const deprecationWarning = logs.find((log) => log.message.toLowerCase().includes("deprecated") ||
                log.message.toLowerCase().includes("deprecation"));
            (0, vitest_1.expect)(deprecationWarning).toBeDefined();
            const message = deprecationWarning.message;
            // Should mention the provider/model format
            (0, vitest_1.expect)(message).toContain("provider/model");
            // Should give an example
            (0, vitest_1.expect)(message).toContain("openai/gpt-5");
        });
        (0, vitest_1.it)("returns OpenAIClient for legacy OpenAI model names", () => {
            const logs = [];
            const logger = (line) => logs.push(line);
            const provider = new LLMProvider_js_1.LLMProvider(logger);
            const client = provider.getClient("gpt-4o", mockClientOptions);
            // Should return a client
            (0, vitest_1.expect)(client).toBeDefined();
            // The client should be an OpenAIClient (check constructor name)
            (0, vitest_1.expect)(client.constructor.name).toBe("OpenAIClient");
        });
        (0, vitest_1.it)("returns AnthropicClient for legacy Anthropic model names", () => {
            const logs = [];
            const logger = (line) => logs.push(line);
            const provider = new LLMProvider_js_1.LLMProvider(logger);
            const client = provider.getClient("claude-3-5-sonnet-latest", mockClientOptions);
            // Should return a client
            (0, vitest_1.expect)(client).toBeDefined();
            // The client should be an AnthropicClient
            (0, vitest_1.expect)(client.constructor.name).toBe("AnthropicClient");
        });
    });
    (0, vitest_1.describe)("LLMProvider.getClient error handling", () => {
        (0, vitest_1.it)("throws UnsupportedModelError for unknown model without slash", () => {
            const logs = [];
            const logger = (line) => logs.push(line);
            const provider = new LLMProvider_js_1.LLMProvider(logger);
            // Unknown model without slash should throw UnsupportedModelError
            (0, vitest_1.expect)(() => {
                provider.getClient("some-unknown-model", mockClientOptions);
            }).toThrow(sdkErrors_js_1.UnsupportedModelError);
        });
        (0, vitest_1.it)("UnsupportedModelError includes provider/model format guidance", () => {
            const logs = [];
            const logger = (line) => logs.push(line);
            const provider = new LLMProvider_js_1.LLMProvider(logger);
            try {
                provider.getClient("some-unknown-model", mockClientOptions);
            }
            catch (error) {
                (0, vitest_1.expect)(error.message).toContain("provider/model");
            }
        });
        (0, vitest_1.it)("throws UnsupportedAISDKModelProviderError for invalid provider in provider/model format", () => {
            const logs = [];
            const logger = (line) => logs.push(line);
            const provider = new LLMProvider_js_1.LLMProvider(logger);
            // Invalid provider but correct format
            (0, vitest_1.expect)(() => {
                provider.getClient("invalid-provider/some-model", mockClientOptions);
            }).toThrow(sdkErrors_js_1.UnsupportedAISDKModelProviderError);
        });
        (0, vitest_1.it)("UnsupportedAISDKModelProviderError lists valid providers", () => {
            const logs = [];
            const logger = (line) => logs.push(line);
            const provider = new LLMProvider_js_1.LLMProvider(logger);
            try {
                provider.getClient("invalid-provider/some-model", mockClientOptions);
            }
            catch (error) {
                const message = error.message;
                // Should list valid providers
                (0, vitest_1.expect)(message).toContain("openai");
                (0, vitest_1.expect)(message).toContain("anthropic");
                (0, vitest_1.expect)(message).toContain("google");
            }
        });
    });
    (0, vitest_1.describe)("new provider/model format", () => {
        (0, vitest_1.it)("does not log deprecation warning for provider/model format", () => {
            const logs = [];
            const logger = (line) => logs.push(line);
            const provider = new LLMProvider_js_1.LLMProvider(logger);
            // Using the new format
            const client = provider.getClient("openai/gpt-4o", mockClientOptions);
            (0, vitest_1.expect)(client).toBeDefined();
            // Should NOT have a deprecation warning
            const deprecationWarning = logs.find((log) => log.message.toLowerCase().includes("deprecated") ||
                log.message.toLowerCase().includes("deprecation"));
            (0, vitest_1.expect)(deprecationWarning).toBeUndefined();
        });
    });
});
//# sourceMappingURL=model-deprecation.test.js.map