import { anthropic, createAnthropic } from "@ai-sdk/anthropic";
import { createProviderUsageStats, decideWithAiSdk, generateTextWithProviderResilience, resolveProviderOptions, } from "./provider-core.js";
import { mapConversationMessagesToAiSdk } from "./provider-message-mapping.js";
import { getProviderCapabilities } from "./provider-metadata.js";
export class AnthropicSdkProvider {
    capabilities;
    config;
    constructor(config) {
        this.config = config;
        this.capabilities = getProviderCapabilities(config);
    }
    async generate(input) {
        const providerInstance = createAnthropicProvider(this.config);
        const messages = await mapConversationMessagesToAiSdk(input.messages, input.toolNameBindings ?? []);
        const result = await generateTextWithProviderResilience(this.config, {
            model: providerInstance(this.config.model),
            messages,
            ...(typeof this.config.maxOutputTokens === "number"
                ? { maxOutputTokens: this.config.maxOutputTokens }
                : {}),
            providerOptions: resolveProviderOptions(this.config, {
                cacheControl: input.cacheControl,
            }),
            system: input.systemPrompt ?? this.config.systemPrompt,
        }, input.stream);
        return {
            provider: this.config.kind,
            model: this.config.model,
            reasoningText: result.reasoningText,
            text: result.text,
            usage: createProviderUsageStats(result.totalUsage),
        };
    }
    async decide(input) {
        return decideWithAiSdk(this.config, input, (modelId) => createAnthropicProvider(this.config)(modelId));
    }
}
function createAnthropicProvider(config) {
    return config.apiKey || config.baseURL
        ? createAnthropic({
            apiKey: config.apiKey,
            baseURL: config.baseURL,
        })
        : anthropic;
}
//# sourceMappingURL=anthropic-provider.js.map