/** * BedrockProvider — wraps AWS Bedrock's Converse API as an `LLMProvider`. * * Pattern: Adapter (GoF) + Ports-and-Adapters (Cockburn 2005). * Role: Outer ring — translates `LLMRequest`/`LLMResponse` to/from * AWS Bedrock's model-agnostic Converse / ConverseStream APIs. * Works with ANY Bedrock-hosted model (Claude, Llama, Mistral, * Titan, Mixtral, ...) without format-specific code. * Emits: N/A. * * Requires: `npm install @aws-sdk/client-bedrock-runtime` * * The Converse API is model-agnostic — one adapter covers every * Bedrock-hosted model (Claude, Llama, Mistral, Titan, Mixtral, ...). * * Tool calling works on BOTH paths: `complete()` reads `toolUse` blocks * off the Converse response, and `stream()` accumulates ConverseStream * `contentBlockStart` / `contentBlockDelta` / `contentBlockStop` events * (keyed by `contentBlockIndex`, so parallel tool calls that interleave * are parsed correctly) and delivers them on the terminal chunk's * `response.toolCalls`. A parity test pins the two paths together. * * ─── Limitations ──────────────────────────────────────────────────── * * • Multi-modal NOT supported (text content only). * • Guardrail integration NOT exposed yet — pass via the SDK client * directly if needed. */ import type { LLMCallHooks, LLMChunk, LLMProvider, LLMRequest, LLMResponse } from '../types.js'; interface BedrockClient { send(command: unknown): Promise; } interface BedrockConverseCommand { modelId: string; messages: BedrockMessage[]; system?: Array<{ text: string; }>; toolConfig?: { tools: BedrockTool[]; }; inferenceConfig?: { maxTokens?: number; temperature?: number; stopSequences?: string[]; }; } interface BedrockMessage { role: 'user' | 'assistant'; content: BedrockContentBlock[]; } type BedrockContentBlock = { text: string; } | { toolUse: { toolUseId: string; name: string; input: Record; }; } | { toolResult: { toolUseId: string; content: Array<{ text: string; }>; status?: 'success' | 'error'; }; }; interface BedrockTool { toolSpec: { name: string; description: string; inputSchema: { json: Record; }; }; } /** * ConverseStream event shapes we consume. * * Note the asymmetry with the non-streaming API: `toolUse.input` is a * fully-formed OBJECT on a Converse response, but a JSON **string * fragment** on a ConverseStream delta. Fragments arrive across many * events and must be joined before parsing, and blocks are addressed by * `contentBlockIndex` because parallel tool calls interleave. */ export interface BedrockStreamEvent { contentBlockStart?: { contentBlockIndex?: number; start?: { toolUse?: { toolUseId?: string; name?: string; }; }; }; contentBlockDelta?: { contentBlockIndex?: number; delta?: { text?: string; toolUse?: { input?: string; }; }; }; contentBlockStop?: { contentBlockIndex?: number; }; messageStop?: { stopReason?: string; }; metadata?: { usage?: { inputTokens: number; outputTokens: number; }; }; } export interface BedrockProviderOptions { /** AWS region (e.g., 'us-east-1'). Defaults to AWS SDK auto-detect. */ readonly region?: string; /** * Default model id (e.g., `anthropic.claude-sonnet-4-5-20250929-v1:0`). * Used when `LLMRequest.model` is the shorthand `'bedrock'`. */ readonly defaultModel?: string; /** Default max tokens when not in the request. Default 4096. */ readonly defaultMaxTokens?: number; /** @internal Pre-built client for testing. */ readonly _client?: BedrockClient; /** * @internal Test override for the SDK's command constructors. Real * use goes through the dynamic `require('@aws-sdk/client-bedrock-runtime')`. */ readonly _commands?: { readonly Converse: new (input: BedrockConverseCommand) => unknown; readonly ConverseStream: new (input: BedrockConverseCommand) => unknown; }; } export declare function bedrock(options?: BedrockProviderOptions): LLMProvider; export declare class BedrockProvider implements LLMProvider { readonly name = "bedrock"; private readonly inner; constructor(options?: BedrockProviderOptions); complete(req: LLMRequest, hooks?: LLMCallHooks): Promise; stream(req: LLMRequest, hooks?: LLMCallHooks): AsyncIterable; } export {}; //# sourceMappingURL=BedrockProvider.d.ts.map