/** * Translation helpers for the native Bedrock Converse battery. * * @module @nhtio/adk/batteries/llm/bedrock_converse/helpers * * @remarks * Every function is injectable via {@link BedrockConverseAdapterOptions.helpers} and has a * `default*` alias. Wire-agnostic renderers are re-exported unchanged from `../chat_common/helpers`; * only genuinely Converse-shaped logic lives here. */ import { renderTrustedContent, renderUntrustedContent } from "../chat_common/helpers"; import type { SpooledArtifact } from "../../../common"; import type { Tool, ArtifactTool, Media, ToolCall, Tokenizable } from "../../../common"; import type { ConverseContentBlock, ConverseImageBlock, ConverseMessage, ConverseRequest, ConverseRequestBuildInput, ConverseToolSpec, JsonSchema, UnsupportedMediaPolicy } from "./types"; export { descriptionToChatCompletionsJsonSchema, defaultDescriptionToChatCompletionsJsonSchema, renderUntrustedContent, defaultRenderUntrustedContent, renderTrustedContent, defaultRenderTrustedContent, renderStandingInstructions, defaultRenderStandingInstructions, renderMemories, defaultRenderMemories, renderRetrievables, defaultRenderRetrievables, renderRetrievableSafetyDirective, defaultRenderRetrievableSafetyDirective, renderFirstPartyRetrievables, defaultRenderFirstPartyRetrievables, renderThirdPartyPublicRetrievables, defaultRenderThirdPartyPublicRetrievables, renderThirdPartyPrivateRetrievables, defaultRenderThirdPartyPrivateRetrievables, renderThought, defaultRenderThought, filterThoughts, defaultFilterThoughts, renderChatCompletionsSystemPrompt, defaultRenderChatCompletionsSystemPrompt, renderArtifactHandleBody, defaultRenderArtifactHandleBody, renderRetrievableHandleBody, defaultRenderRetrievableHandleBody, } from "../chat_common/helpers"; /** Default context-bucket order for the system blocks; matches the other chat batteries. */ export declare const DEFAULT_CONVERSE_BUCKET_ORDER: readonly [ "standingInstructions", "memories", "retrievables", "timeline" ]; /** Recursively strip schema keywords Converse rejects. */ export declare const sanitizeConverseSchema: (schema: unknown) => JsonSchema; /** Default implementation; alias of {@link sanitizeConverseSchema}. */ export declare const defaultSanitizeConverseSchema: (schema: unknown) => JsonSchema; /** * Converse rejects a `toolUseId` outside `[A-Za-z0-9_-]{1,64}`. * * @remarks * ADK ids are UUIDv6, which is already in-charset, but a caller-supplied id may not be — and the * rejection names neither the field nor the offending character. */ export declare const sanitizeToolUseId: (id: string) => string; /** Default implementation; alias of {@link sanitizeToolUseId}. */ export declare const defaultSanitizeToolUseId: (id: string) => string; /** ADK tools → native `toolConfig.tools`. */ export declare const toolsToConverseTools: (tools: Iterable) => ConverseToolSpec[]; /** Default implementation; alias of {@link toolsToConverseTools}. */ export declare const defaultToolsToConverseTools: (tools: Iterable) => ConverseToolSpec[]; /** Render one tool result into `toolResult.content[]`. */ export declare const renderConverseToolResult: (input: { toolCall: ToolCall; results: Tokenizable | SpooledArtifact | SpooledArtifact[] | Media | Media[]; tool: Tool | ArtifactTool | undefined; renderUntrustedContent: typeof renderUntrustedContent; renderTrustedContent: typeof renderTrustedContent; unsupportedMediaPolicy: UnsupportedMediaPolicy | undefined; warn?: (message: string) => void; }) => Promise; }>>; /** Default implementation; alias of {@link renderConverseToolResult}. */ export declare const defaultRenderConverseToolResult: (input: { toolCall: ToolCall; results: Tokenizable | SpooledArtifact | SpooledArtifact[] | Media | Media[]; tool: Tool | ArtifactTool | undefined; renderUntrustedContent: typeof renderUntrustedContent; renderTrustedContent: typeof renderTrustedContent; unsupportedMediaPolicy: UnsupportedMediaPolicy | undefined; warn?: (message: string) => void; }) => Promise; }>>; /** Decode an ADK Media into a Converse image block. */ export declare const mediaToConverseImage: (media: Media) => Promise; /** Default implementation; alias of {@link mediaToConverseImage}. */ export declare const defaultMediaToConverseImage: (media: Media) => Promise; /** * Apply Converse's strict `user` ↔ `assistant` alternation to an already-ordered turn list. * * @remarks * Exported and separately testable because it is the single most consequential transformation in * this battery, and the one a gateway would otherwise perform invisibly. * * - `'merge'` concatenates consecutive same-role turns' content blocks. Lossless: the same blocks * in the same order, in one turn — exactly what Converse would have accepted had the caller * written it that way. * - `'filler'` inserts a placeholder opposite-role turn. LOSSIER — it fabricates model output that * never existed — and offered only for callers who need positional stability across turns. * - `'reject'` returns the list untouched so Converse's own error surfaces. Use this when * AUDITING: a repair applied before dispatch is invisible in the response, which makes a * gateway's fix indistinguishable from a vendor's tolerance. */ export declare const enforceConverseAlternation: (messages: ConverseMessage[], policy?: "merge" | "filler" | "reject") => ConverseMessage[]; /** Default implementation; alias of {@link enforceConverseAlternation}. */ export declare const defaultEnforceConverseAlternation: (messages: ConverseMessage[], policy?: "merge" | "filler" | "reject") => ConverseMessage[]; /** * Assemble the native Converse request from ADK turn state. THE ordering seam. * * @remarks * The translation that makes this battery different from pointing `openai_chat_completions` at a * Converse-backed gateway: * * - System text becomes a top-level `system[]`, never a turn. * - A `ToolCall` becomes an `assistant` turn with a `{toolUse}` block, then a **`user`** turn with * a `{toolResult}` block — Converse has no `tool` role. * - Blocks accumulate on the CURRENT turn where possible, so prose and a tool call emitted in the * same assistant turn stay in one turn (the shape Converse is designed around). * - Alternation is applied last, under {@link ConverseRequestBuildInput.alternationPolicy}. * - Timeline order is `createdAt`, matching the ordering guard's view, so what the guard validated * is what gets dispatched. */ export declare const buildConverseRequest: (input: ConverseRequestBuildInput) => Promise; /** Default implementation; alias of {@link buildConverseRequest}. */ export declare const defaultBuildConverseRequest: (input: ConverseRequestBuildInput) => Promise; /** * Extract text, reasoning, and tool uses from a Converse response. * * @remarks * `reasoningContent` blocks are NOT concatenated into visible text — doing so leaks the model's * scratchpad into the answer. */ export declare const extractConverseGeneration: (response: ConverseResponseLike | undefined) => { text: string; reasoning: string; toolUses: Array<{ toolUseId: string; name: string; input: Record; }>; stopReason: string | undefined; }; /** Structural minimum `extractConverseGeneration` needs, so tests can pass a literal. */ interface ConverseResponseLike { output?: { message?: { content?: ConverseContentBlock[]; }; }; stopReason?: string; } /** Default implementation; alias of {@link extractConverseGeneration}. */ export declare const defaultExtractConverseGeneration: (response: ConverseResponseLike | undefined) => { text: string; reasoning: string; toolUses: Array<{ toolUseId: string; name: string; input: Record; }>; stopReason: string | undefined; };