/** * AWS Bedrock Converse API transport. * * Implements {@link LlmTransport} using the Bedrock Converse API * (`ConverseCommand` + `ConverseStreamCommand`) for chat-format message * exchange. Supports all models available through Bedrock's Converse surface * (Claude, Nova, Mistral, Llama, etc.) without the model-specific invokeModel * differences. * * Key behaviors: * - AWS credential chain via `fromNodeProviderChain()` (env → ~/.aws/credentials → IAM → SSO) * - Cross-region fallback: retries on `AccessDeniedException`/throttle against * a configured fallback region list * - Guardrail integration: `guardrailConfig` from `request.meta` * - Tool use (function calling) via Converse `toolConfig` * * @module llm/transports/bedrock * @task T9317 * @epic T9261 (T-LLM-CRED-CENTRALIZATION Phase 5) */ import type { NormalizedDelta, TransportContext } from '@cleocode/contracts/llm/interfaces.js'; import type { LlmTransport, NormalizedResponse, TransportRequest } from '@cleocode/contracts/llm/normalized-response.js'; import type { ApiMode } from '@cleocode/contracts/llm/provider-id.js'; /** * Options accepted by {@link BedrockTransport}. * * AWS credentials are resolved via the standard `fromNodeProviderChain()` * (env vars → `~/.aws/credentials` → IAM instance metadata → SSO). * Explicit profile override available via `awsProfile`. * * `fallbackRegions` is the cross-region retry list. When the primary region * returns a denial or throttle, regions are tried in list order. */ export interface BedrockTransportOptions { /** AWS region (defaults to `AWS_REGION` then `AWS_DEFAULT_REGION` env vars). */ region?: string; /** Optional AWS credentials profile name (overrides default chain). */ awsProfile?: string; /** * Ordered list of fallback regions to try when the primary region returns * a model-not-supported or throttle error. */ fallbackRegions?: string[]; } /** * AWS Bedrock Converse API transport. * * Wraps `@aws-sdk/client-bedrock-runtime` and normalizes requests/responses * to/from the provider-neutral {@link LlmTransport} interface. Uses the * Converse API for a uniform chat-format surface across all Bedrock models. * * Credential resolution uses `fromNodeProviderChain()` which follows the * standard AWS credential chain: env vars → `~/.aws/credentials` (profile) * → ECS container metadata → EC2 instance profile → SSO. * * Cross-region fallback retries against `options.fallbackRegions` when the * primary region returns an `AccessDeniedException`, `ValidationException`, * `ResourceNotFoundException`, or `ThrottlingException`. This is the primary * mechanism for handling cross-region inference profiles. * * @example * ```ts * const transport = new BedrockTransport({ region: 'us-east-1' }); * const response = await transport.complete({ * model: 'anthropic.claude-3-5-sonnet-20241022-v2:0', * messages: [{ role: 'user', content: 'Hello' }], * maxTokens: 512, * }); * ``` */ export declare class BedrockTransport implements LlmTransport { /** Provider identifier — always `'bedrock'`. */ readonly provider: "bedrock"; /** * Wire protocol spoken by this transport — always `'bedrock_converse'`. * * @see ADR-072 §Type lock-in */ readonly apiMode: ApiMode; private readonly _primaryRegion; private readonly _fallbackRegions; private readonly _awsProfile; /** Lazily-constructed per-region client cache. */ private readonly _clients; /** * Create a `BedrockTransport`. * * @param options - AWS region, optional credential profile, and fallback region list. */ constructor(options?: BedrockTransportOptions); /** * Execute a single completion against the Bedrock Converse API. * * Supports: tool use (function calling), guardrail passthrough, * cross-region fallback, and AWS credential chain resolution. * * @param request - Provider-neutral request parameters. Guardrail config * can be passed via `(request as BedrockTransportRequest).guardrailConfig`. * @param _ctx - Transport context (unused by this transport currently). * @returns Normalized response including content, tool calls, usage, and raw SDK object. */ complete(request: TransportRequest, _ctx?: TransportContext): Promise; /** * Stream a completion against the Bedrock Converse Stream API. * * Yields text deltas as they arrive. Reasoning content (when present) goes * to `delta.reasoning`; visible text goes to `delta.text`. Tool-use content * blocks are dropped from streaming output (only available on the final * message stop event). The final delta carries `stopReason` and `usage`. * * @invariant stream tool-call yield contract — tool_use blocks are DROPPED * during streaming. Callers needing full tool call arguments MUST use * `complete()` for tool-call scenarios. * * @param request - Provider-neutral request parameters. * @param _ctx - Transport context (unused by this transport currently). * @returns An async iterable of normalized delta chunks. */ stream(request: TransportRequest, _ctx: TransportContext): AsyncIterable; /** * Return (or lazily create) a `BedrockRuntimeClient` for the given region. * * Clients are cached per region to avoid repeated credential resolution * overhead on cross-region fallback retries. * * @param region - AWS region string. */ private _getClient; /** * Build the Bedrock `ConverseRequest` from a provider-neutral `TransportRequest`. */ private _buildConverseInput; /** * Build the Bedrock `ConverseStreamRequest` from a provider-neutral `TransportRequest`. */ private _buildConverseStreamInput; /** * Normalize a raw `ConverseCommandOutput` into a {@link NormalizedResponse}. */ private _normalizeResponse; /** * Consume a Bedrock `ConverseStreamOutput` async iterable and yield * normalized deltas. * * @param stream - The async iterable from `ConverseStreamResponse.stream`. */ private _readStream; } //# sourceMappingURL=bedrock.d.ts.map