import { customProvider, wrapLanguageModel } from "ai";
import { getLogger } from "../../util/logger.js";
import { anthropicImpl } from "./impl/anthropic.js";
import { clarkImpl } from "./impl/clark.js";
import { jwtMiddleware } from "./utils.js";
export const createLLMProvider = (settings, getJwt, llmConfig, getAttributes) => {
    const providerType = llmConfig?.provider || "bedrock";
    const wrapDefaults = (model) => wrapLanguageModel({
        model,
        middleware: [jwtMiddleware(getJwt, getAttributes)],
    });
    getLogger().info(`Creating LLM provider: type=${providerType}`, {
        config: llmConfig || {},
    });
    let implFunc;
    switch (providerType) {
        case "bedrock":
        case "vertex":
            implFunc = clarkImpl;
            break;
        case "anthropic":
        default:
            implFunc = anthropicImpl;
            break;
    }
    const impl = implFunc(settings);
    const languageModels = {
        classifyPrompt: wrapDefaults(impl.classifyPrompt),
        explain: wrapDefaults(impl.explain),
        generateBroadEdit: wrapDefaults(impl.generateBroadEdit),
        summarizeMessages: wrapDefaults(impl.summarizeMessages),
        fast: wrapDefaults(impl.fast),
    };
    const sdkProvider = customProvider({
        languageModels,
    });
    const modelForTask = (modelId) => {
        return sdkProvider.languageModel(modelId);
    };
    return {
        name: providerType,
        modelForTask,
    };
};
//# sourceMappingURL=provider.js.map