/**
 * AWS Bedrock Provider
 *
 * Unified provider for all Bedrock-hosted models using the Converse API.
 * Supports: Claude, DeepSeek, Titan, Mistral, Llama, and other Bedrock models.
 *
 * @example
 * ```ts
 * // Using API Key (recommended)
 * const bedrock = new BedrockProvider({
 *   region: "us-east-1",
 *   apiKey: process.env.AWS_BEARER_TOKEN_BEDROCK
 * });
 *
 * // Using SigV4 (IAM credentials)
 * const bedrock = new BedrockProvider({
 *   region: "us-east-1",
 *   accessKeyId: process.env.AWS_ACCESS_KEY_ID,
 *   secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
 * });
 *
 * const response = await bedrock.chat({
 *   model: "anthropic.claude-3-5-haiku-20241022-v1:0",
 *   messages: [{ role: "user", content: "Hello!" }]
 * });
 * ```
 */
import { BaseProvider } from "../BaseProvider.js";
import { getBedrockEndpoint } from "./config.js";
import { BedrockChat } from "./Chat.js";
import { BedrockModels } from "./Models.js";
import { BedrockStreaming } from "./Streaming.js";
import { BedrockEmbeddings } from "./Embeddings.js";
import { BedrockImage } from "./Image.js";
import { BedrockModeration } from "./Moderation.js";
import { Capabilities } from "./Capabilities.js";
export class BedrockProvider extends BaseProvider {
    config;
    chatHandler;
    modelsHandler;
    streamingHandler;
    embeddingsHandler;
    imageHandler;
    moderationHandler;
    capabilities = {
        supportsVision: (model) => Capabilities.supportsVision(model),
        supportsTools: (model) => Capabilities.supportsTools(model),
        supportsStructuredOutput: (model) => Capabilities.supportsJsonMode(model),
        supportsEmbeddings: (model) => Capabilities.supportsEmbeddings(model),
        supportsImageGeneration: (model) => Capabilities.supportsImageGeneration(model),
        supportsTranscription: (_model) => false,
        supportsModeration: (_model) => !!(this.config.guardrailIdentifier && this.config.guardrailVersion),
        supportsReasoning: (model) => Capabilities.supportsExtendedThinking(model),
        supportsDeveloperRole: (_model) => true,
        getContextWindow: (model) => Capabilities.getContextWindow(model)
    };
    constructor(config) {
        super();
        this.config = config;
        this.chatHandler = new BedrockChat(config);
        this.modelsHandler = new BedrockModels(config);
        this.streamingHandler = new BedrockStreaming(config);
        this.embeddingsHandler = new BedrockEmbeddings(config);
        this.imageHandler = new BedrockImage(config);
        this.moderationHandler = new BedrockModeration(config);
    }
    apiBase() {
        return getBedrockEndpoint(this.config.region);
    }
    headers() {
        // Headers are built dynamically based on auth mode
        // This method is primarily for SigV4 signing, which happens at the HTTP client level.
        // For API Key auth, the key is passed in the Authorization header directly.
        // For now, we return a default Content-Type.
        return {
            "Content-Type": "application/json"
        };
    }
    providerName() {
        return "bedrock";
    }
    async chat(request) {
        return this.chatHandler.execute(request);
    }
    async *stream(request) {
        yield* this.streamingHandler.execute(request);
    }
    async listModels() {
        return this.modelsHandler.execute();
    }
    async embed(request) {
        return this.embeddingsHandler.execute(request);
    }
    async paint(request) {
        return this.imageHandler.execute(request);
    }
    async moderate(request) {
        return this.moderationHandler.execute(request);
    }
    defaultModel(feature) {
        if (feature === "embeddings") {
            return "amazon.titan-embed-text-v2:0";
        }
        // Amazon Nova Lite is available by default and cost-effective
        return "amazon.nova-lite-v1:0";
    }
}
