/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import type { CountTokensResponse, GenerateContentParameters, CountTokensParameters, EmbedContentResponse, EmbedContentParameters } from '@google/genai'; import { GenerateContentResponse } from '@google/genai'; import type { ContentGenerator } from './contentGenerator.js'; import type { LlmRole } from '../telemetry/llmRole.js'; /** * BedrockContentGenerator implements ContentGenerator interface for AWS Bedrock. */ export declare class BedrockContentGenerator implements ContentGenerator { private client; private model; private region; /** * Accumulator for streaming tool calls. * Bedrock sends tool input as JSON fragments across multiple contentBlockDelta events. * We accumulate the fragments and emit complete functionCall when contentBlockStop arrives. */ private streamingToolUses; constructor(config: { model: string; region?: string; }); private detectCredentialSource; /** * Build inference config with mutually exclusive temperature/topP. * Bedrock forbids sending both for Claude models. * When both are present, prefer temperature (more commonly configured). */ private buildInferenceConfig; generateContent(request: GenerateContentParameters, _userPromptId: string, _role?: LlmRole): Promise; generateContentStream(request: GenerateContentParameters, _userPromptId: string, _role?: LlmRole): Promise>; countTokens(request: CountTokensParameters): Promise; embedContent(_request: EmbedContentParameters): Promise; /** * Generator function to process streaming response from Bedrock. * Handles text chunks and accumulates tool calls until complete. */ private streamGenerator; /** * Convert Gemini request to Bedrock Converse format. */ private convertToBedrockMessages; /** * Type guard to check if value is Content or Content[] */ private isContentOrArray; /** * Convert system instruction to Bedrock format. */ private convertSystemInstruction; /** * Convert Bedrock response to Gemini format. */ private convertToGeminiFormat; /** * Convert Bedrock StopReason to Gemini FinishReason. */ private convertStopReason; /** * Convert Gemini Tools to Bedrock ToolConfiguration format. */ private convertToolsToBedrockFormat; /** * Sanitize JSON schema for Bedrock compatibility. * Bedrock has stricter requirements than Gemini: * - Root level must have type: "object" * - No nullable types (type: ["string", "null"]) * - No additionalProperties */ private sanitizeJsonSchema; /** * Enhance error with user-friendly messages. */ private enhanceError; }