import { BaseTextAdapter, StructuredOutputOptions, StructuredOutputResult } from '@tanstack/ai/adapters'; import { ResolvedBedrockAuth } from '../utils/auth.js'; import { BedrockRuntimeClient, BedrockRuntimeClientConfig, ConverseCommandInput, ConverseCommandOutput, ConverseStreamCommandInput, ConverseStreamOutput } from '@aws-sdk/client-bedrock-runtime'; import { Modality, AdapterYieldChunk, TextOptions } from '@tanstack/ai'; import { BedrockClientConfig } from '../utils/client.js'; import { BedrockMessageMetadataByModality } from '../message-types.js'; import { BedrockConverseModels, ResolveConverseProviderOptions, ResolveInputModalities } from '../model-meta.js'; import type * as BedrockRuntime from '@aws-sdk/client-bedrock-runtime'; /** Config for the Converse adapter — same client config as the chat adapter. */ export interface BedrockConverseConfig extends BedrockClientConfig { } /** * Bedrock Converse text adapter. Wires the Converse translation modules (message * converter, tool converter, stream processor, structured-output forced-tool * builder) onto `@tanstack/ai`'s `BaseTextAdapter` and the * `@aws-sdk/client-bedrock-runtime` `BedrockRuntimeClient`. * * The success-path AG-UI lifecycle (`RUN_STARTED`..`RUN_FINISHED`) is owned by * `processConverseStream`; this adapter only owns the catch/`RUN_ERROR` path, * mirroring openai-base's `chatStream`. * * The actual SDK calls live behind two protected seams (`sendStream` / `send`) * so tests can subclass and inject canned Converse SDK shapes without a real * AWS request. */ export declare class BedrockConverseTextAdapter = ResolveConverseProviderOptions, TInputModalities extends ReadonlyArray = ResolveInputModalities> extends BaseTextAdapter { readonly kind: "text"; readonly name: "bedrock-converse"; private clientPromise?; private readonly clientConfig; constructor(config: BedrockConverseConfig, model: TModel); /** * Dynamically import `@aws-sdk/client-bedrock-runtime`. The specifier is held * in a variable (not a string literal) so bundler dep scanners (e.g. Vite/ * esbuild optimizeDeps) cannot statically discover the AWS SDK and try to * pre-bundle it for the browser — it would fail on the SDK's Node-only * `fromTokenFile` export chain. The SDK is Node/server-only and is only * reached on a real request. `typeof import(...)` is a type-only reference * (erased at emit) so the imported members keep full typing. */ protected importBedrockRuntime(): Promise; /** * Lazily construct the `BedrockRuntimeClient`. The dynamic import keeps * `@aws-sdk/client-bedrock-runtime` out of the static/browser graph and * defers `resolveBedrockAuth` until a real request is made. */ protected getClient(): Promise; /** * Map resolved auth + endpoint to a `BedrockRuntimeClientConfig`. * * Recent `@aws-sdk/client-bedrock-runtime` exposes a first-class `token` * config field for Bedrock API-key bearer auth. But the client's default * auth-scheme order is SigV4 first, then bearer — so passing `token` alone is * not enough: the SDK still resolves SigV4 and throws "Could not load * credentials from any providers". Pinning `authSchemePreference` to the * bearer scheme makes the API key actually get used. SigV4 uses the AWS * credential provider chain and the default scheme order. */ protected buildClientConfig(resolved: ResolvedBedrockAuth, region: string, endpoint: string | undefined): BedrockRuntimeClientConfig; protected sendStream(input: ConverseStreamCommandInput): Promise>; protected send(input: ConverseCommandInput): Promise; chatStream(options: TextOptions): AsyncIterable; /** * Structured output via the forced-tool strategy. Converse has no native * json_schema response_format, so we force a single tool whose input schema * is the requested output schema and read the model's `toolUse.input` back as * the structured result. */ structuredOutput(options: StructuredOutputOptions): Promise>; /** * Streaming structured output. Same forced-tool strategy as * `structuredOutput`, but streamed: the forced tool's `toolUse.input` JSON * fragments are accumulated from the Converse stream and a terminal * `CUSTOM 'structured-output.complete'` event carries `{ object, raw }`, * mirroring openai-base's `structuredOutputStream` contract exactly. */ structuredOutputStream(options: StructuredOutputOptions): AsyncIterable; /** * Converse sends `tools` and a forced structured-output tool via two separate * mechanisms, never together. Declaring `false` makes the engine run the * agent loop without `outputSchema` and finalize via `structuredOutput` / * `structuredOutputStream`. */ supportsCombinedToolsAndSchema(): boolean; /** * Translate `TextOptions` into a `ConverseCommandInput`. Shared by chatStream, * structuredOutput, and structuredOutputStream (the latter two override * `toolConfig` with the forced structured tool afterwards). */ protected buildInput(options: TextOptions): ConverseCommandInput; } /** Converse adapter with an explicit API key (low-level; mirrors createBedrockChat). */ export declare function createBedrockConverse(model: TModel, apiKey: string, config?: Omit): BedrockConverseTextAdapter;