@warlock.js/ai-bedrock 5.31.0 → 5.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/cjs/index.cjs +5 -3
- package/cjs/index.cjs.map +1 -1
- package/esm/config.type.d.mts +3 -5
- package/esm/config.type.d.mts.map +1 -1
- package/esm/known-pricing.d.mts +4 -6
- package/esm/known-pricing.d.mts.map +1 -1
- package/esm/model.mjs +3 -1
- package/esm/model.mjs.map +1 -1
- package/esm/provider-options.d.mts +2 -2
- package/esm/provider-options.d.mts.map +1 -1
- package/esm/provider-options.mjs +1 -1
- package/esm/provider-options.mjs.map +1 -1
- package/esm/sdk.d.mts +1 -3
- package/esm/sdk.d.mts.map +1 -1
- package/esm/utils/index.mjs +1 -1
- package/esm/utils/wrap-bedrock-error.mjs +1 -1
- package/esm/utils/wrap-bedrock-error.mjs.map +1 -1
- package/llms-full.txt +17 -0
- package/package.json +3 -3
- package/skills/setup-bedrock/SKILL.md +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@ All notable changes to `@warlock.js/ai-bedrock` are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
|
|
6
6
|
|
|
7
|
+
## 5.32.0 - 2026-10-18
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- Pin the package development compiler to TypeScript 7.0.2 and use explicit Node types and source roots with supported module resolution.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Verified that native token counting preserves the shared unsupported-count signal for `countInputTokens` estimation while authentication errors propagate.
|
|
16
|
+
- Clarify that Converse TokenUsage exposes no hosted-search request counter; system-tool blocks cannot establish request fees and no count is fabricated.
|
|
17
|
+
|
|
7
18
|
## 5.31.0 - 2026-10-18
|
|
8
19
|
|
|
9
20
|
### Fixed
|
package/cjs/index.cjs
CHANGED
|
@@ -253,7 +253,7 @@ function toJsonSchema(input) {
|
|
|
253
253
|
|
|
254
254
|
//#endregion
|
|
255
255
|
//#region ../../packages/ai-bedrock/src/utils/wrap-bedrock-error.ts
|
|
256
|
-
const TIMEOUT_NAMES = new Set([
|
|
256
|
+
const TIMEOUT_NAMES = /* @__PURE__ */ new Set([
|
|
257
257
|
"ModelTimeoutException",
|
|
258
258
|
"TimeoutError",
|
|
259
259
|
"RequestTimeout",
|
|
@@ -484,7 +484,7 @@ var BedrockEmbedder = class {
|
|
|
484
484
|
|
|
485
485
|
//#endregion
|
|
486
486
|
//#region ../../packages/ai-bedrock/src/provider-options.ts
|
|
487
|
-
const RESERVED_FIELDS = new Set([
|
|
487
|
+
const RESERVED_FIELDS = /* @__PURE__ */ new Set([
|
|
488
488
|
"modelId",
|
|
489
489
|
"messages",
|
|
490
490
|
"system",
|
|
@@ -1234,7 +1234,9 @@ var BedrockModel = class {
|
|
|
1234
1234
|
* the non-cached input tokens" (AWS prompt-caching guide), so the usage
|
|
1235
1235
|
* is marked `inputIncludesCache: false`. Bedrock's Converse `TokenUsage`
|
|
1236
1236
|
* carries no reasoning-token channel, so `Usage.reasoningTokens` is
|
|
1237
|
-
* intentionally left unset here.
|
|
1237
|
+
* intentionally left unset here. The installed SDK 3.1121.0 TokenUsage also
|
|
1238
|
+
* has no hosted-tool request counter; do not infer one from tool blocks.
|
|
1239
|
+
* https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_TokenUsage.html
|
|
1238
1240
|
*/
|
|
1239
1241
|
extractUsage(raw) {
|
|
1240
1242
|
if (!raw) return {
|
package/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["isRecord","InvalidRequestError","AIError","ProviderTimeoutError","ProviderAuthError","QuotaExceededError","ProviderRateLimitError","ProviderOverloadedError","ContextLengthExceededError","InvalidRequestError","ProviderError","LOG_MODULE","log","InvokeModelCommand","InvalidRequestError","log","ConverseCommand","CountTokensCommand","InvalidRequestError","ConverseStreamCommand","BedrockRuntimeClient","InvalidRequestError"],"sources":["../../../../../../../packages/ai-bedrock/src/utils/map-stop-reason.ts","../../../../../../../packages/ai-bedrock/src/utils/reasoning-blocks.ts","../../../../../../../packages/ai-bedrock/src/utils/to-bedrock-messages.ts","../../../../../../../packages/ai-bedrock/src/utils/to-bedrock-tools.ts","../../../../../../../packages/ai-bedrock/src/utils/wrap-bedrock-error.ts","../../../../../../../packages/ai-bedrock/src/embedder.ts","../../../../../../../packages/ai-bedrock/src/provider-options.ts","../../../../../../../packages/ai-bedrock/src/known-capabilities.ts","../../../../../../../packages/ai-bedrock/src/known-pricing.ts","../../../../../../../packages/ai-bedrock/src/known-vision-models.ts","../../../../../../../packages/ai-bedrock/src/model.ts","../../../../../../../packages/ai-bedrock/src/sdk.ts"],"sourcesContent":["import type { FinishReason } from \"@warlock.js/ai\";\n\nconst stopReasonMap: Record<string, FinishReason> = {\n end_turn: \"stop\",\n stop_sequence: \"stop\",\n max_tokens: \"length\",\n tool_use: \"tool_calls\",\n};\n\n/**\n * Map Bedrock Converse's `stopReason` to the normalized `FinishReason`\n * union.\n *\n * `end_turn` / `stop_sequence` are natural stops. `max_tokens` maps to\n * `length`. `tool_use` maps to `tool_calls`. Everything else —\n * `content_filtered`, `guardrail_intervened`, `malformed_tool_use`,\n * `malformed_model_output`, `model_context_window_exceeded`, `null`,\n * or any future value — falls through to `\"error\"`: none produced a\n * clean terminal answer, so the agent must not treat them as success.\n *\n * @example\n * mapStopReason(\"end_turn\"); // \"stop\"\n * mapStopReason(\"tool_use\"); // \"tool_calls\"\n * mapStopReason(\"guardrail_intervened\"); // \"error\"\n * mapStopReason(undefined); // \"error\"\n */\nexport function mapStopReason(raw: string | null | undefined): FinishReason {\n return stopReasonMap[raw ?? \"\"] ?? \"error\";\n}\n","import type { ContentBlock } from \"@aws-sdk/client-bedrock-runtime\";\n\n/**\n * JSON-safe representation of a Bedrock Converse reasoning block retained in\n * tool-call provider metadata. Binary redacted reasoning is base64 encoded so\n * it survives message-history persistence unchanged.\n */\nexport type BedrockReasoningBlock =\n | { type: \"reasoning\"; text: string; signature?: string }\n | { type: \"redacted\"; data: string };\n\n/** Convert a Converse reasoning content block to persistence-safe metadata. */\nexport function toReasoningMetadata(block: ContentBlock): BedrockReasoningBlock | undefined {\n const reasoning = block.reasoningContent;\n\n if (!reasoning) {\n return undefined;\n }\n\n if (reasoning.reasoningText) {\n const { text, signature } = reasoning.reasoningText;\n\n if (typeof text !== \"string\") {\n return undefined;\n }\n\n return { type: \"reasoning\", text, ...(typeof signature === \"string\" ? { signature } : {}) };\n }\n\n if (reasoning.redactedContent instanceof Uint8Array) {\n return { type: \"redacted\", data: Buffer.from(reasoning.redactedContent).toString(\"base64\") };\n }\n\n return undefined;\n}\n\n/** Restore one persistence-safe metadata entry to a Converse reasoning block. */\nexport function fromReasoningMetadata(value: unknown): ContentBlock | undefined {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return undefined;\n }\n\n if (value.type === \"reasoning\" && typeof value.text === \"string\") {\n return {\n reasoningContent: {\n reasoningText: {\n text: value.text,\n ...(typeof value.signature === \"string\" ? { signature: value.signature } : {}),\n },\n },\n };\n }\n\n if (value.type === \"redacted\" && typeof value.data === \"string\" && isBase64(value.data)) {\n return {\n reasoningContent: { redactedContent: new Uint8Array(Buffer.from(value.data, \"base64\")) },\n };\n }\n\n return undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\n/** Require canonical base64, avoiding Buffer's permissive decoding of garbage. */\nfunction isBase64(value: string): boolean {\n if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {\n return false;\n }\n\n return Buffer.from(value, \"base64\").toString(\"base64\") === value;\n}\n","import { InvalidRequestError, type ContentPart, type Message } from \"@warlock.js/ai\";\nimport type {\n ContentBlock,\n ImageFormat,\n Message as BedrockMessage,\n SystemContentBlock,\n} from \"@aws-sdk/client-bedrock-runtime\";\nimport { fromReasoningMetadata } from \"./reasoning-blocks\";\n\n/**\n * Result of splitting a vendor-neutral `Message[]` for the Bedrock\n * Converse API: system prompts hoist to a separate `SystemContentBlock[]`\n * (Converse has no `\"system\"` role inside `messages`), and the\n * remaining turns map to Bedrock `Message[]`.\n */\nexport type BedrockMessages = {\n system: SystemContentBlock[] | undefined;\n messages: BedrockMessage[];\n};\n\nconst MEDIA_TYPE_TO_FORMAT: Record<string, ImageFormat> = {\n \"image/jpeg\": \"jpeg\",\n \"image/png\": \"png\",\n \"image/gif\": \"gif\",\n \"image/webp\": \"webp\",\n};\n\n/**\n * Convert vendor-neutral `Message[]` into Bedrock Converse's request\n * shape.\n *\n * Converse differs from the OpenAI Chat protocol in three ways this\n * function absorbs:\n *\n * 1. **No `system` role.** System messages become a separate\n * `SystemContentBlock[]` (one `{ text }` block each).\n * 2. **Tool results are `user` turns.** A neutral `tool` message\n * becomes a `user` message carrying a single `toolResult` block.\n * 3. **Tool calls are `toolUse` content blocks.** An assistant message\n * with `toolCalls` becomes an `assistant` message: an optional\n * leading `text` block followed by one `toolUse` block per call.\n *\n * @example\n * const { system, messages } = toBedrockMessages([\n * { role: \"system\", content: \"Be concise.\" },\n * { role: \"user\", content: \"Hi\" },\n * ]);\n */\nexport function toBedrockMessages(messages: Message[]): BedrockMessages {\n const system: SystemContentBlock[] = [];\n const mapped: BedrockMessage[] = [];\n\n for (const message of messages) {\n if (message.role === \"system\") {\n system.push({ text: stringifyContent(message.content) });\n\n continue;\n }\n\n if (message.role === \"tool\") {\n mapped.push({\n role: \"user\",\n content: [\n {\n toolResult: {\n toolUseId: message.toolCallId ?? \"\",\n content: [{ text: stringifyContent(message.content) }],\n },\n },\n ],\n });\n\n continue;\n }\n\n if (message.role === \"assistant\" && message.toolCalls && message.toolCalls.length > 0) {\n const blocks: ContentBlock[] = [];\n const text = stringifyContent(message.content);\n const reasoningBlocks = getReasoningBlocks(message.toolCalls);\n\n blocks.push(...reasoningBlocks);\n\n if (text) {\n blocks.push({ text });\n }\n\n for (const toolCall of message.toolCalls) {\n blocks.push({\n toolUse: {\n toolUseId: toolCall.id,\n name: toolCall.name,\n input: toolCall.input ?? {},\n },\n } as ContentBlock);\n }\n\n mapped.push({ role: \"assistant\", content: blocks });\n\n continue;\n }\n\n if (message.role === \"user\" && Array.isArray(message.content)) {\n mapped.push({\n role: \"user\",\n content: message.content.map(toBedrockContentBlock),\n });\n\n continue;\n }\n\n mapped.push({\n role: message.role === \"assistant\" ? \"assistant\" : \"user\",\n content: [{ text: stringifyContent(message.content) }],\n });\n }\n\n return {\n system: system.length > 0 ? system : undefined,\n messages: mergeAdjacentTurns(mapped),\n };\n}\n\n/** Converse requires alternating turns; preserve every content block in order. */\nfunction mergeAdjacentTurns(messages: BedrockMessage[]): BedrockMessage[] {\n const merged: BedrockMessage[] = [];\n for (const message of messages) {\n const previous = merged[merged.length - 1];\n if (previous && previous.role === message.role) {\n previous.content!.push(...(message.content ?? []));\n } else {\n merged.push({ ...message, content: [...(message.content ?? [])] });\n }\n }\n return merged;\n}\n\n/**\n * Recover opaque Converse reasoning blocks retained on a prior tool call.\n * Bedrock requires them to be replayed before the assistant's text and\n * tool-use blocks on the follow-up request.\n */\nfunction getReasoningBlocks(toolCalls: NonNullable<Message[\"toolCalls\"]>): ContentBlock[] {\n for (const toolCall of toolCalls) {\n const bedrock = toolCall.providerMetadata?.bedrock;\n\n if (!isRecord(bedrock) || !Array.isArray(bedrock.reasoningBlocks)) {\n continue;\n }\n\n return bedrock.reasoningBlocks\n .map(fromReasoningMetadata)\n .filter((block): block is ContentBlock => block !== undefined);\n }\n\n return [];\n}\n\n/** Narrow an opaque metadata value to an object without altering its contents. */\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Multipart content is only meaningful on user messages — for any other\n * role collapse a `ContentPart[]` to its concatenated text. Plain\n * strings pass through unchanged.\n */\nfunction stringifyContent(content: string | ContentPart[]): string {\n if (typeof content === \"string\") {\n return content;\n }\n\n return content\n .filter((part): part is { type: \"text\"; text: string } => part.type === \"text\")\n .map((part) => part.text)\n .join(\"\");\n}\n\n/**\n * Map a resolved `ContentPart` to a Bedrock `ContentBlock`. Bedrock's\n * `ImageSource` only accepts raw bytes or an S3 location — there is no\n * remote-URL source. A neutral `{ url }` image therefore cannot be\n * sent and surfaces a typed `InvalidRequestError` upfront rather than\n * a downstream Bedrock validation fault. The agent has already\n * resolved attachments, so this never fetches or reads anything.\n */\nfunction toBedrockContentBlock(part: ContentPart): ContentBlock {\n if (part.type === \"text\") {\n return { text: part.text };\n }\n\n if (\"url\" in part.source) {\n throw new InvalidRequestError(\n \"Bedrock Converse does not support remote-URL sources; supply base64 bytes instead.\",\n );\n }\n\n // PDF → Bedrock `document` content block (A2). Converse accepts a\n // document block with raw bytes; the agent gates this on the model's\n // `pdf` capability before it reaches here.\n if (part.type === \"pdf\") {\n return {\n document: {\n format: \"pdf\",\n name: \"attachment\",\n source: { bytes: Buffer.from(part.source.base64, \"base64\") },\n },\n } as unknown as ContentBlock;\n }\n\n // Bedrock Converse has no audio content block (capability stays false).\n if (part.type === \"audio\") {\n throw new InvalidRequestError(\"Bedrock Converse does not support audio attachments.\");\n }\n\n const format = MEDIA_TYPE_TO_FORMAT[part.source.mediaType];\n\n if (!format) {\n throw new InvalidRequestError(\n `Unsupported image media type for Bedrock: \"${part.source.mediaType}\" (expected image/jpeg, image/png, image/gif, or image/webp).`,\n );\n }\n\n return {\n image: {\n format,\n source: { bytes: Buffer.from(part.source.base64, \"base64\") },\n },\n };\n}\n","import { extractJsonSchema, type ToolConfig } from \"@warlock.js/ai\";\nimport type { Tool, ToolConfiguration, ToolInputSchema } from \"@aws-sdk/client-bedrock-runtime\";\n\n/**\n * Convert vendor-neutral `ToolConfig[]` into Bedrock Converse's\n * `ToolConfiguration`. Each tool becomes a `toolSpec` with a JSON\n * `inputSchema`. Bedrock requires the schema root to be an object —\n * a non-object extraction degrades to a parameterless object schema\n * so registration never fails.\n *\n * Returns `undefined` when there are no tools so the caller can omit\n * `toolConfig` from the request entirely (Bedrock rejects an empty\n * `tools` array).\n *\n * @example\n * const toolConfig = toBedrockToolConfig([weatherTool]);\n * await client.send(new ConverseCommand({ modelId, messages, toolConfig }));\n */\nexport function toBedrockToolConfig(\n tools: ToolConfig<unknown, unknown>[] | undefined,\n): ToolConfiguration | undefined {\n if (!tools || tools.length === 0) {\n return undefined;\n }\n\n return {\n tools: tools.map((tool): Tool => ({\n toolSpec: {\n name: tool.name,\n description: tool.description,\n inputSchema: { json: toJsonSchema(tool.input) } as ToolInputSchema,\n },\n })),\n };\n}\n\n/**\n * Resolve a tool's input schema to a JSON-Schema object. Bedrock's\n * `ToolInputSchema.json` requires an object root; anything else (or a\n * failed extraction) degrades to a parameterless object so the tool\n * still registers.\n */\nfunction toJsonSchema(input: ToolConfig<unknown, unknown>[\"input\"]): Record<string, unknown> {\n const schema = extractJsonSchema(input);\n\n if (schema && schema.type === \"object\") {\n return schema;\n }\n\n return { type: \"object\" };\n}\n","import {\n AIError,\n ContextLengthExceededError,\n InvalidRequestError,\n ProviderAuthError,\n ProviderError,\n ProviderOverloadedError,\n ProviderRateLimitError,\n ProviderTimeoutError,\n QuotaExceededError,\n} from \"@warlock.js/ai\";\n\n/**\n * Raw-error fields the wrapper reads off an AWS SDK exception. Every\n * Bedrock error is a Smithy `__BaseException` with a stable `name`\n * (`\"ThrottlingException\"`, `\"ValidationException\"`, …) and a\n * `$metadata` carrying `httpStatusCode` + `requestId`. We duck-type\n * because retries and proxies sometimes flatten the prototype chain.\n */\ntype BedrockErrorShape = {\n name?: string;\n message?: string;\n httpStatusCode?: number;\n requestId?: string;\n code?: string;\n};\n\nconst TIMEOUT_NAMES = new Set([\n \"ModelTimeoutException\",\n \"TimeoutError\",\n \"RequestTimeout\",\n \"RequestTimeoutException\",\n]);\n\n/**\n * Wrap any thrown value caught inside the Bedrock adapter into the\n * appropriate `@warlock.js/ai` `AIError` subclass.\n *\n * **Dispatch strategy.** AWS errors carry no provider machine `code`;\n * the stable identifier is the Smithy exception `name`. Dispatch keys\n * on `name`, falls back to `$metadata.httpStatusCode` when the name is\n * missing (flattened/proxied errors). `ValidationException` is split:\n * the \"input is too long / exceeds context window\" phrasing maps to\n * `ContextLengthExceededError`, everything else to\n * `InvalidRequestError`.\n *\n * `AIError` instances pass through unchanged so `catch/throw wrap(e)`\n * pipelines never double-wrap.\n *\n * @example\n * try {\n * return await this.client.send(new ConverseCommand(...));\n * } catch (thrown) {\n * throw wrapBedrockError(thrown);\n * }\n */\nexport function wrapBedrockError(thrown: unknown): AIError {\n if (thrown instanceof AIError) {\n return thrown;\n }\n\n const shape = toShape(thrown);\n const context = buildContext(shape);\n const message = shape.message ?? (thrown instanceof Error ? thrown.message : String(thrown));\n\n if (isTimeout(shape)) {\n return new ProviderTimeoutError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"AccessDeniedException\" || shape.httpStatusCode === 403) {\n return new ProviderAuthError(message, { cause: thrown, context });\n }\n\n if (shape.httpStatusCode === 401) {\n return new ProviderAuthError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ServiceQuotaExceededException\") {\n return new QuotaExceededError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ThrottlingException\" || shape.httpStatusCode === 429) {\n return new ProviderRateLimitError(message, { cause: thrown, context });\n }\n\n // Converse `ServiceUnavailableException` (503): the service is\n // temporarily unable to serve the request — retry later.\n // https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html\n if (shape.name === \"ServiceUnavailableException\" || shape.httpStatusCode === 503) {\n return new ProviderOverloadedError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ValidationException\") {\n if (/too long|context window|maximum context|exceeds the maximum/i.test(message)) {\n return new ContextLengthExceededError(message, { cause: thrown, context });\n }\n\n return new InvalidRequestError(message, { cause: thrown, context });\n }\n\n if (\n shape.name === \"ResourceNotFoundException\" ||\n shape.name === \"ConflictException\" ||\n isClientStatus(shape.httpStatusCode)\n ) {\n return new InvalidRequestError(message, { cause: thrown, context });\n }\n\n return new ProviderError(message, { cause: thrown, context });\n}\n\n/**\n * Read the raw error shape without depending on `instanceof`. AWS\n * exceptions expose `$metadata`; plain/proxied errors may carry\n * `status` / `code` instead.\n */\nfunction toShape(thrown: unknown): BedrockErrorShape {\n if (typeof thrown !== \"object\" || thrown === null) {\n return {};\n }\n\n const raw = thrown as Record<string, unknown>;\n const metadata = raw.$metadata as { httpStatusCode?: number; requestId?: string } | undefined;\n\n return {\n name: typeof raw.name === \"string\" ? raw.name : undefined,\n message: typeof raw.message === \"string\" ? raw.message : undefined,\n httpStatusCode:\n metadata && typeof metadata.httpStatusCode === \"number\"\n ? metadata.httpStatusCode\n : typeof raw.status === \"number\"\n ? (raw.status as number)\n : undefined,\n requestId: metadata && typeof metadata.requestId === \"string\" ? metadata.requestId : undefined,\n code: typeof raw.code === \"string\" ? raw.code : undefined,\n };\n}\n\n/**\n * Decide whether the error is a timeout. Bedrock surfaces\n * `ModelTimeoutException`; the AWS transport layer surfaces\n * `TimeoutError` / `ETIMEDOUT` / `ECONNABORTED`.\n */\nfunction isTimeout(shape: BedrockErrorShape): boolean {\n if (shape.name && TIMEOUT_NAMES.has(shape.name)) {\n return true;\n }\n\n return shape.code === \"ETIMEDOUT\" || shape.code === \"ECONNABORTED\";\n}\n\n/** True for HTTP 4xx — a client-side request problem, not a server fault. */\nfunction isClientStatus(status: number | undefined): boolean {\n return typeof status === \"number\" && status >= 400 && status < 500;\n}\n\n/**\n * Attach the raw diagnostic fields to `error.context`. The Smithy\n * exception `name` is the closest thing Bedrock has to a stable error\n * code, so it lands on `context.code`.\n */\nfunction buildContext(shape: BedrockErrorShape): Record<string, unknown> {\n const context: Record<string, unknown> = {};\n\n if (shape.httpStatusCode !== undefined) {\n context.status = shape.httpStatusCode;\n }\n\n if (shape.name) {\n context.code = shape.name;\n }\n\n if (shape.requestId) {\n context.requestId = shape.requestId;\n }\n\n return context;\n}\n","import {\n type EmbeddingBatchResult,\n type EmbeddingResult,\n type EmbeddingUsage,\n type EmbedderContract,\n} from \"@warlock.js/ai\";\nimport { log, type Logger } from \"@warlock.js/logger\";\nimport { InvokeModelCommand, type BedrockRuntimeClient } from \"@aws-sdk/client-bedrock-runtime\";\nimport type { BedrockEmbedderConfig } from \"./config.type\";\nimport { wrapBedrockError } from \"./utils\";\n\nconst LOG_MODULE = \"ai.bedrock\";\n\n/** Shape of the Amazon Titan Text Embeddings response body. */\ntype TitanEmbeddingResponse = {\n embedding: number[];\n inputTextTokenCount: number;\n};\n\n/**\n * Bedrock-backed implementation of `EmbedderContract`, targeting the\n * Amazon Titan Text Embeddings family\n * (`amazon.titan-embed-text-v2:0` / v1) via `InvokeModel`.\n *\n * **Role.** Converts text into floating-point vectors. Standalone\n * primitive — unrelated to Converse / tools / the agent loop.\n *\n * **Single-input only upstream.** Titan's `InvokeModel` body accepts\n * one `inputText` per call — there is no batch endpoint. `embedMany`\n * therefore issues one request per input sequentially and aggregates\n * token usage. This is a deliberate, documented trade-off: a real\n * batch API does not exist for Titan on Bedrock, so the alternative\n * (failing `embedMany`) would be worse. Cohere embeddings on Bedrock\n * *do* batch but use an incompatible body shape — out of scope; use\n * the OpenAI adapter or a future Cohere adapter when batch throughput\n * matters.\n *\n * **Dimensions.** When no `dimensions` override is given,\n * `this.dimensions` starts at `0` and is populated from the first\n * response's vector length, then cached. Passing `dimensions` forwards\n * Titan v2's truncation hint (256 / 512 / 1024) and sets the initial\n * value immediately.\n *\n * @example\n * const embedder = new BedrockEmbedder(client, { name: \"amazon.titan-embed-text-v2:0\" });\n * const { vector } = await embedder.embed(\"Hello world\");\n * const { vectors } = await embedder.embedMany([\"doc 1\", \"doc 2\"]);\n */\nexport class BedrockEmbedder implements EmbedderContract {\n public readonly name: string;\n public readonly provider: string;\n public dimensions: number;\n\n private readonly client: BedrockRuntimeClient;\n private readonly configuredDimensions: number | undefined;\n private readonly logger: Logger = log;\n\n public constructor(\n client: BedrockRuntimeClient,\n config: BedrockEmbedderConfig,\n provider: string = \"bedrock\",\n ) {\n this.client = client;\n this.name = config.name;\n this.provider = provider;\n this.configuredDimensions = config.dimensions;\n this.dimensions = config.dimensions ?? 0;\n }\n\n public async embed(input: string): Promise<EmbeddingResult> {\n const { vector, tokens } = await this.invoke(input);\n\n return {\n vector,\n dimensions: this.dimensions,\n usage: { promptTokens: tokens, totalTokens: tokens },\n };\n }\n\n public async embedMany(inputs: string[]): Promise<EmbeddingBatchResult> {\n const vectors: number[][] = [];\n let tokens = 0;\n\n for (const input of inputs) {\n const result = await this.invoke(input);\n\n vectors.push(result.vector);\n tokens += result.tokens;\n }\n\n const usage: EmbeddingUsage = { promptTokens: tokens, totalTokens: tokens };\n\n return { vectors, dimensions: this.dimensions, usage };\n }\n\n /**\n * Issue a single Titan `InvokeModel` embedding request: encode the\n * JSON body, send, wrap provider errors, decode the response, and\n * cache `dimensions` on the first successful call.\n */\n private async invoke(input: string): Promise<{ vector: number[]; tokens: number }> {\n this.logger.debug(LOG_MODULE, \"embedder.request\", \"InvokeModel embeddings\", {\n model: this.name,\n });\n\n const body = JSON.stringify({\n inputText: input,\n ...(this.configuredDimensions !== undefined ? { dimensions: this.configuredDimensions } : {}),\n });\n\n let raw;\n\n try {\n raw = await this.client.send(\n new InvokeModelCommand({\n modelId: this.name,\n contentType: \"application/json\",\n accept: \"application/json\",\n body: new TextEncoder().encode(body),\n }),\n );\n } catch (thrown) {\n const wrapped = wrapBedrockError(thrown);\n\n this.logger.error(LOG_MODULE, \"embedder.error\", wrapped.message, {\n code: wrapped.code,\n context: wrapped.context,\n });\n\n throw wrapped;\n }\n\n const decoded = JSON.parse(new TextDecoder().decode(raw.body)) as TitanEmbeddingResponse;\n\n if (this.dimensions === 0) {\n this.dimensions = decoded.embedding.length;\n }\n\n this.logger.debug(LOG_MODULE, \"embedder.response\", \"InvokeModel embeddings returned\", {\n dimensions: decoded.embedding.length,\n tokens: decoded.inputTextTokenCount,\n });\n\n return { vector: decoded.embedding, tokens: decoded.inputTextTokenCount };\n }\n}\n","import { InvalidRequestError, type ModelCallOptions } from \"@warlock.js/ai\";\n\n/** Adapter-only fields merged after the neutral request parameters. */\nexport type BedrockCallOptions = { body?: Record<string, unknown> };\n\nconst RESERVED_FIELDS = new Set([\"modelId\", \"messages\", \"system\", \"toolConfig\"]);\n\nexport function mergeProviderBody<T extends object>(\n built: T,\n options: ModelCallOptions | undefined,\n): T {\n const provider = options?.providerOptions?.bedrock as BedrockCallOptions | undefined;\n const body = provider?.body ?? {};\n const reserved = Object.keys(body).filter((key) => RESERVED_FIELDS.has(key));\n if (reserved.length > 0) {\n throw new InvalidRequestError(\n `providerOptions.bedrock.body cannot set ${reserved.join(\", \")}: use the call's messages, tools and model options.`,\n { context: { fields: reserved } },\n );\n }\n const defaults = built as Record<string, unknown>;\n const overrides = Object.fromEntries(\n Object.entries(body).map(([key, value]) => {\n const previous = defaults[key];\n return [\n key,\n isPlainObject(previous) && isPlainObject(value) ? { ...previous, ...value } : value,\n ];\n }),\n );\n return { ...built, ...overrides };\n}\n\n/** Merge only plain objects; arrays, null and provider scalar values replace the field. */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== \"object\") return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n","/**\n * Cost-truth capability inference for Bedrock Converse model ids.\n *\n * Bedrock model ids are provider-prefixed and version-suffixed\n * (`anthropic.claude-3-7-sonnet-20250219-v1:0`, `us.amazon.nova-pro-v1:0`),\n * so — exactly like `known-vision-models.ts` — a lowercase substring scan\n * is the only robust check across cross-region inference-profile prefixes\n * (`us.`, `eu.`, `apac.`) and date/version tags.\n *\n * Each predicate answers a single `ModelCapabilities` flag the agent reads\n * to decide whether to forward a cost-truth option (`reasoning`,\n * `cacheControl`) or up-front-reject an attachment (`pdf`). Unknown ids\n * default to `false` so an unsupported request fails fast with a clear\n * capability error instead of an opaque Bedrock `ValidationException`.\n * Every inference is overridable per-model via `bedrock.model({ name, … })`.\n */\n\n/**\n * Families that expose Anthropic-style extended thinking on Bedrock\n * Converse via `additionalModelRequestFields.thinking`. Only Claude 3.7\n * and the Claude 4 line (Sonnet / Opus / Haiku) support a configurable\n * thinking budget; earlier Claude, Nova, Llama, Mistral and Cohere do\n * not, so they are intentionally absent.\n */\nconst REASONING_CAPABLE_SUBSTRINGS = [\n \"claude-3-7\",\n \"claude-sonnet-4\",\n \"claude-opus-4\",\n \"claude-haiku-4\",\n];\n\n/**\n * Families that honor Converse `cachePoint` prompt-cache breakpoints.\n * Anthropic Claude 3.5+ / 3.7 / 4 / 5 and the Amazon Nova line support\n * cache points; text-only legacy families do not. Per the \"Supported\n * models\" table of https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html\n * (checked 2026-10-17).\n */\nconst PROMPT_CACHING_CAPABLE_SUBSTRINGS = [\n \"claude-3-5\",\n \"claude-3-7\",\n \"claude-sonnet-4\",\n \"claude-opus-4\",\n \"claude-haiku-4\",\n \"claude-sonnet-5\",\n \"claude-opus-5\",\n \"claude-haiku-5\",\n \"claude-fable-5\",\n \"claude-mythos-5\",\n \"nova-2-lite\",\n \"nova-lite\",\n \"nova-pro\",\n \"nova-premier\",\n \"nova-micro\",\n];\n\n/**\n * Families that accept Converse `document` content blocks (PDF / docx /\n * txt input). The multimodal Claude 3+ and Nova families support\n * document blocks; the substring set mirrors the vision-capable list\n * minus the image-only Llama entries (Llama on Bedrock takes images but\n * not document blocks via Converse).\n */\nconst PDF_CAPABLE_SUBSTRINGS = [\n \"claude-3\",\n \"claude-sonnet-4\",\n \"claude-opus-4\",\n \"claude-haiku-4\",\n \"nova-lite\",\n \"nova-pro\",\n \"nova-premier\",\n];\n\nfunction matchesAny(modelId: string, fragments: string[]): boolean {\n const normalized = modelId.toLowerCase();\n\n return fragments.some((fragment) => normalized.includes(fragment));\n}\n\n/**\n * Infer whether a Bedrock model id exposes extended-thinking / reasoning\n * (Claude 3.7 + Claude 4). When true the adapter forwards\n * `ModelCallOptions.reasoning` as Converse\n * `additionalModelRequestFields.thinking`.\n *\n * @example\n * inferReasoningCapability(\"anthropic.claude-3-7-sonnet-20250219-v1:0\"); // → true\n * inferReasoningCapability(\"us.amazon.nova-pro-v1:0\"); // → false\n */\nexport function inferReasoningCapability(modelId: string): boolean {\n return matchesAny(modelId, REASONING_CAPABLE_SUBSTRINGS);\n}\n\n/**\n * Infer whether a Bedrock model id honors Converse `cachePoint`\n * breakpoints (Claude 3.5+ / Nova). When true the adapter both maps\n * `ModelCallOptions.cacheControl` write breakpoints to cache points and\n * reports `Usage.cachedTokens` / `Usage.cacheWriteTokens`.\n *\n * @example\n * inferPromptCachingCapability(\"us.amazon.nova-pro-v1:0\"); // → true\n * inferPromptCachingCapability(\"meta.llama3-1-8b-instruct-v1:0\"); // → false\n */\nexport function inferPromptCachingCapability(modelId: string): boolean {\n return matchesAny(modelId, PROMPT_CACHING_CAPABLE_SUBSTRINGS);\n}\n\n/**\n * Infer whether a Bedrock model id accepts Converse `document` content\n * blocks (PDF / document input — Claude 3+ / Nova). When false the agent\n * rejects a PDF attachment up front instead of dropping it at the wire.\n *\n * @example\n * inferPdfCapability(\"anthropic.claude-3-5-sonnet-20240620-v1:0\"); // → true\n * inferPdfCapability(\"meta.llama3-2-90b-instruct-v1:0\"); // → false\n */\nexport function inferPdfCapability(modelId: string): boolean {\n return matchesAny(modelId, PDF_CAPABLE_SUBSTRINGS);\n}\n\n/**\n * Claude on Bedrock accepts a `cachePoint` in `system`, `messages` and\n * `tools`; Amazon Nova accepts one only in `system` and `messages`\n * (https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html,\n * \"Fields that accept prompt cache checkpoints\", checked 2026-10-17).\n * Unknown families get no tool cache point.\n *\n * @example\n * supportsToolCachePoint(\"global.anthropic.claude-sonnet-4-6\"); // true\n * supportsToolCachePoint(\"amazon.nova-pro-v1:0\"); // false\n */\nexport function supportsToolCachePoint(modelId: string): boolean {\n return modelId.toLowerCase().includes(\"anthropic.claude\");\n}\n\n/** Claude families whose cache points accept the 1-hour TTL. */\nconst ONE_HOUR_TTL_PATTERN =\n /anthropic\\.claude-(?:(?:opus|sonnet|haiku|fable|mythos)-5|opus-4-[5-9]|sonnet-4-[5-9]|haiku-4-5)/;\n\n/**\n * Claude models whose Converse `cachePoint` accepts `ttl: \"1h\"`: Claude\n * Haiku 4.5, the 4.5+ Sonnet / Opus line and every Claude 5 family. Any\n * other model gets no `ttl` field (the 5-minute default), since AWS\n * warns that sending it to a 5-minute-only model \"can result in a\n * ValidationException\" (same page, checked 2026-10-17).\n *\n * @example\n * supportsOneHourCacheTtl(\"anthropic.claude-haiku-4-5-20251001-v1:0\"); // true\n * supportsOneHourCacheTtl(\"anthropic.claude-3-7-sonnet-20250219-v1:0\"); // false\n */\nexport function supportsOneHourCacheTtl(modelId: string): boolean {\n return ONE_HOUR_TTL_PATTERN.test(modelId.toLowerCase());\n}\n","import type { ModelPricing } from \"@warlock.js/ai\";\n\n/**\n * Bedrock on-demand list prices for Anthropic Claude, USD per 1,000,000\n * tokens, keyed by Bedrock model id (without an inference-profile\n * prefix). `cacheWrite` is the 5-minute write rate, `cacheWrite1h` the\n * 1-hour write rate, `cachedInput` the cache-read rate.\n *\n * Source: https://aws.amazon.com/bedrock/pricing/ — the page's own price\n * feed for \"US East (N. Virginia)\", fetched 2026-10-17 (Sonnet 5.5 cache\n * reads already at the rate effective 2026-10-07). Model ids from\n * https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html.\n *\n * Two tables, because AWS prices them differently:\n * - {@link BEDROCK_GLOBAL_PRICING} — `global.` cross-Region inference\n * profiles.\n * - {@link BEDROCK_US_PRICING} — `us.` geographic profiles (the\n * \"Geo / In-region\" rates, 10% above global for these models).\n *\n * In-Region ids without a profile prefix, other geographies (`eu.`,\n * `apac.`, …), Claude Haiku 5.5 and non-Claude models stay unpriced —\n * their rates vary by Region or were not verified — so pass `pricing`\n * yourself for them.\n */\nexport const BEDROCK_GLOBAL_PRICING: Readonly<Record<string, ModelPricing>> = {\n \"anthropic.claude-sonnet-5-5\": claude(2, 10, 0.1),\n \"anthropic.claude-opus-5-5\": claude(4, 20, 0.2),\n \"anthropic.claude-fable-5-1\": claude(10, 50, 0.25),\n \"anthropic.claude-opus-5\": claude(5, 25, 0.5),\n \"anthropic.claude-sonnet-5\": claude(2, 10, 0.2),\n \"anthropic.claude-fable-5\": claude(10, 50, 1),\n \"anthropic.claude-opus-4-8\": claude(5, 25, 0.5),\n \"anthropic.claude-opus-4-7\": claude(5, 25, 0.5),\n \"anthropic.claude-opus-4-6-v1\": claude(5, 25, 0.5),\n \"anthropic.claude-sonnet-4-6\": claude(3, 15, 0.3),\n \"anthropic.claude-opus-4-5-20251101-v1:0\": claude(5, 25, 0.5),\n \"anthropic.claude-sonnet-4-5-20250929-v1:0\": claude(3, 15, 0.3),\n \"anthropic.claude-haiku-4-5-20251001-v1:0\": claude(1, 5, 0.1),\n};\n\n/** `us.` geographic-profile prices — see {@link BEDROCK_GLOBAL_PRICING}. */\nexport const BEDROCK_US_PRICING: Readonly<Record<string, ModelPricing>> = {\n \"anthropic.claude-sonnet-5-5\": claude(2.2, 11, 0.11),\n \"anthropic.claude-opus-5-5\": claude(4.4, 22, 0.22),\n \"anthropic.claude-fable-5-1\": claude(11, 55, 0.275),\n \"anthropic.claude-opus-5\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-sonnet-5\": claude(2.2, 11, 0.22),\n \"anthropic.claude-fable-5\": claude(11, 55, 1.1),\n \"anthropic.claude-opus-4-8\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-opus-4-7\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-opus-4-6-v1\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-sonnet-4-6\": claude(3.3, 16.5, 0.33),\n \"anthropic.claude-opus-4-5-20251101-v1:0\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-sonnet-4-5-20250929-v1:0\": claude(3.3, 16.5, 0.33),\n \"anthropic.claude-haiku-4-5-20251001-v1:0\": claude(1.1, 5.5, 0.11),\n};\n\n/**\n * Look up the built-in price for a Bedrock model id or inference-profile\n * id: `global.<model>` reads {@link BEDROCK_GLOBAL_PRICING}, `us.<model>`\n * reads {@link BEDROCK_US_PRICING}; anything else is `undefined`.\n *\n * @example\n * bedrockPricingFor(\"global.anthropic.claude-sonnet-4-6\"); // { input: 3, output: 15, … }\n * bedrockPricingFor(\"anthropic.claude-sonnet-4-6\"); // undefined — in-Region rates vary\n */\nexport function bedrockPricingFor(modelId: string): ModelPricing | undefined {\n if (modelId.startsWith(\"global.\")) {\n return BEDROCK_GLOBAL_PRICING[modelId.slice(\"global.\".length)];\n }\n\n if (modelId.startsWith(\"us.\")) {\n return BEDROCK_US_PRICING[modelId.slice(\"us.\".length)];\n }\n\n return undefined;\n}\n\n/**\n * Fill the Claude cache-write rates (5-minute 1.25x, 1-hour 2x the input\n * rate — the ratio of every Claude row in the tables above) into a\n * caller-supplied entry for a Claude model that omits them. Non-Claude\n * models are returned unchanged.\n */\nexport function withClaudeCacheWriteRates(\n modelId: string,\n pricing: ModelPricing | undefined,\n): ModelPricing | undefined {\n if (!pricing || !modelId.toLowerCase().includes(\"anthropic.claude\")) {\n return pricing;\n }\n\n if (pricing.cacheWrite !== undefined && pricing.cacheWrite1h !== undefined) {\n return pricing;\n }\n\n return {\n ...pricing,\n cacheWrite: pricing.cacheWrite ?? pricing.cachedOutput ?? round(pricing.input * 1.25),\n cacheWrite1h: pricing.cacheWrite1h ?? round(pricing.input * 2),\n };\n}\n\nfunction claude(input: number, output: number, cachedInput: number): ModelPricing {\n return {\n input,\n output,\n cachedInput,\n cacheWrite: round(input * 1.25),\n cacheWrite1h: round(input * 2),\n };\n}\n\n/** Trim binary floating-point noise (2.2 * 1.25 = 2.7500000000000004). */\nfunction round(value: number): number {\n return Math.round(value * 1e9) / 1e9;\n}\n","/**\n * Substrings that identify Bedrock model ids whose family accepts image\n * input on the Converse API.\n *\n * Bedrock model ids are provider-prefixed and version-suffixed\n * (`anthropic.claude-3-5-sonnet-20240620-v1:0`, `us.amazon.nova-pro-v1:0`,\n * `meta.llama3-2-90b-instruct-v1:0`), so a substring match is the only\n * robust check across the cross-region inference-profile prefixes\n * (`us.`, `eu.`, `apac.`) and date/version tags.\n *\n * Multimodal families covered: Anthropic Claude 3 / 3.5 / 3.7 / 4,\n * Amazon Nova Lite/Pro/Premier, Meta Llama 3.2 (11B/90B) and Llama 4.\n * Text-only families (Llama 3/3.1, Titan Text, Mistral 7B, Cohere\n * Command) are intentionally absent. Override per-model via\n * `bedrock.model({ name, vision: true | false })`.\n */\nconst VISION_CAPABLE_SUBSTRINGS = [\n \"claude-3\",\n \"claude-sonnet-4\",\n \"claude-opus-4\",\n \"claude-haiku-4\",\n \"nova-lite\",\n \"nova-pro\",\n \"nova-premier\",\n \"llama3-2-11b\",\n \"llama3-2-90b\",\n \"llama4\",\n];\n\n/**\n * Infer whether a Bedrock model id supports vision based on the known\n * multimodal-family substrings. Unknown ids default to `false` so that\n * passing an image attachment to an unsupported model surfaces a clear,\n * agent-side capability error instead of an opaque Bedrock validation\n * fault.\n *\n * @example\n * inferVisionCapability(\"anthropic.claude-3-5-sonnet-20240620-v1:0\"); // → true\n * inferVisionCapability(\"us.amazon.nova-pro-v1:0\"); // → true\n * inferVisionCapability(\"meta.llama3-1-8b-instruct-v1:0\"); // → false\n * inferVisionCapability(\"amazon.titan-text-express-v1\"); // → false\n */\nexport function inferVisionCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return VISION_CAPABLE_SUBSTRINGS.some((fragment) => normalized.includes(fragment));\n}\n","import {\n attachCost,\n InvalidRequestError,\n resolveStreamChunks,\n safeJsonParse,\n selectProviderTools,\n type Message,\n type ModelCallOptions,\n type ModelCapabilities,\n type ModelContract,\n type ModelPricing,\n type ModelResponse,\n type ModelStreamChunk,\n type ModelToolCallRequest,\n type Usage,\n} from \"@warlock.js/ai\";\nimport { log, type Logger } from \"@warlock.js/logger\";\nimport {\n CountTokensCommand,\n ConverseCommand,\n ConverseStreamCommand,\n type Tool,\n type BedrockRuntimeClient,\n type ContentBlock,\n type ConverseRequest,\n type TokenUsage,\n} from \"@aws-sdk/client-bedrock-runtime\";\nimport { mergeProviderBody } from \"./provider-options\";\nimport type { BedrockModelConfig } from \"./config.type\";\nimport {\n inferPdfCapability,\n inferPromptCachingCapability,\n inferReasoningCapability,\n supportsOneHourCacheTtl,\n supportsToolCachePoint,\n} from \"./known-capabilities\";\nimport { bedrockPricingFor, withClaudeCacheWriteRates } from \"./known-pricing\";\nimport { inferVisionCapability } from \"./known-vision-models\";\nimport { toReasoningMetadata, type BedrockReasoningBlock } from \"./utils/reasoning-blocks\";\nimport { mapStopReason, toBedrockMessages, toBedrockToolConfig, wrapBedrockError } from \"./utils\";\n\n/** A Converse cache point as this adapter emits it. */\ntype BedrockCachePoint = { type: \"default\"; ttl?: \"1h\" };\n\nconst LOG_MODULE = \"ai.bedrock\";\n\n/** `provider` value of `ai.providerTool()` entries this adapter sends verbatim. */\nconst BEDROCK_WIRE_FORMAT = \"bedrock\";\n\n/** Converse `ToolUseBlock.type` of a tool use run by Bedrock itself (SDK `ToolUseType`). */\nconst SERVER_TOOL_USE = \"server_tool_use\";\n\n/** Default output allowance added to a thinking budget when maxTokens is unset. */\nconst DEFAULT_MAX_TOKENS = 4096;\nconst MIN_THINKING_BUDGET = 1024;\n\n/**\n * Conventional extended-thinking token budgets for the neutral\n * `reasoning.effort` levels, used when the caller asks for an effort\n * tier without naming an explicit `reasoning.maxTokens` budget. Mirrors\n * the low / medium / high spread other reasoning adapters expose so the\n * vendor-neutral option behaves consistently across providers.\n */\nconst EFFORT_THINKING_BUDGET: Record<string, number | undefined> = {\n minimal: 1024,\n low: 1024,\n medium: 4096,\n high: 16384,\n xhigh: 24000,\n max: 32000,\n};\n\n/**\n * Bedrock-backed implementation of `ModelContract`.\n *\n * **Role.** The provider-facing bridge between the vendor-neutral\n * `@warlock.js/ai` agent runtime and AWS Bedrock's Converse /\n * ConverseStream API. Converse is the model-agnostic surface — one\n * wire mapping covers every Bedrock-hosted family (Anthropic Claude,\n * Amazon Nova, Meta Llama, Mistral, Cohere) instead of per-family\n * `InvokeModel` body shapes.\n *\n * **Responsibility.**\n * - Owns: a long-lived `BedrockRuntimeClient` + frozen `ModelConfig`\n * (modelId, temperature, maxTokens) used as per-call defaults.\n * - Owns: translating vendor-neutral `Message[]` / `ToolConfig[]` into\n * Converse shapes (system hoisting, `toolUse` / `toolResult` blocks,\n * image bytes) on the way out, and Converse's content-block response\n * (text, tool calls, stop reason, token usage) back into the neutral\n * shapes on the way in.\n * - Does NOT own: dispatching tools, looping, history, retries — those\n * are agent concerns. The model is a per-call protocol adapter.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across calls\"): the AWS client is heavy to construct and reused for\n * the SDK's lifetime.\n *\n * @example\n * import { BedrockRuntimeClient } from \"@aws-sdk/client-bedrock-runtime\";\n * const client = new BedrockRuntimeClient({ region: \"us-east-1\" });\n * const model = new BedrockModel(client, {\n * name: \"anthropic.claude-sonnet-4-5-20250929-v1:0\",\n * });\n *\n * const myAgent = agent({ model, tools: [searchTool] });\n * const result = await myAgent.execute(\"Summarize today's news.\");\n */\nexport class BedrockModel implements ModelContract {\n public readonly name: string;\n public readonly provider: string;\n public readonly capabilities: ModelCapabilities;\n public readonly pricing?: ModelPricing;\n\n private readonly client: BedrockRuntimeClient;\n private readonly config: BedrockModelConfig;\n private readonly logger: Logger = log;\n\n public constructor(\n client: BedrockRuntimeClient,\n config: BedrockModelConfig,\n provider: string = \"bedrock\",\n ) {\n this.client = client;\n this.config = config;\n this.name = config.name;\n this.provider = provider;\n // Explicit pricing wins over the built-in `global.` / `us.` profile\n // prices; Claude entries get the 1.25x / 2x cache-write rates filled.\n this.pricing = withClaudeCacheWriteRates(\n config.name,\n config.pricing ?? bedrockPricingFor(config.name),\n );\n this.capabilities = {\n structuredOutput: config.structuredOutput ?? true,\n vision: config.vision ?? inferVisionCapability(config.name),\n reasoning: config.reasoning ?? inferReasoningCapability(config.name),\n promptCaching: config.promptCaching ?? inferPromptCachingCapability(config.name),\n pdf: config.pdf ?? inferPdfCapability(config.name),\n audio: config.audio ?? false,\n };\n }\n\n /**\n * Single-shot completion via the Converse API. Sends the full\n * message list, waits for the terminal response, and reshapes it\n * into a vendor-neutral `ModelResponse`. Per-call `options` override\n * the instance defaults for this call only.\n */\n public async complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse> {\n this.logger.debug(LOG_MODULE, \"request\", \"Starting Converse call\", {\n model: this.name,\n messageCount: messages.length,\n streaming: false,\n toolCount: options?.tools?.length ?? 0,\n });\n\n let response;\n\n try {\n response = await this.client.send(\n new ConverseCommand(this.buildRequest(messages, options)),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n const blocks = response.output?.message?.content ?? [];\n const finishReason = mapStopReason(response.stopReason);\n const usage = attachCost(this.extractUsage(response.usage), this.pricing);\n const toolCalls = this.extractToolCalls(blocks);\n\n this.logger.debug(LOG_MODULE, \"response\", \"Converse call succeeded\", { finishReason, usage });\n\n return {\n content: this.extractText(blocks),\n finishReason,\n usage,\n toolCalls,\n };\n }\n\n /** Count native input tokens from the same Converse conversation and tool configuration. */\n public async countTokens(messages: Message[], options?: ModelCallOptions): Promise<number> {\n const request = this.buildRequest(messages, options);\n try {\n const response = await this.client.send(\n new CountTokensCommand({\n modelId: request.modelId,\n input: {\n converse: {\n messages: request.messages,\n system: request.system,\n toolConfig: request.toolConfig,\n additionalModelRequestFields: request.additionalModelRequestFields,\n },\n },\n }),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n if (response.inputTokens === undefined)\n throw new InvalidRequestError(\"Bedrock countTokens returned no inputTokens.\");\n return response.inputTokens;\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n }\n\n /**\n * Incremental streaming completion via ConverseStream. Yields neutral\n * `ModelStreamChunk`s — `delta` for text, `tool-call` once a\n * `toolUse` block's accumulated input JSON is complete, and a\n * terminal `done` with the final finish reason + usage totals.\n *\n * With `options.streamChunks` it also yields `reasoning` for each\n * `reasoningContent.text` delta and `tool-args` for each client\n * `toolUse.input` delta. Usage arrives once, in the final `metadata`\n * event, so no `usage` chunk is emitted. A system tool's\n * `server_tool_use` block never becomes a `tool-call`.\n */\n public async *stream(\n messages: Message[],\n options?: ModelCallOptions,\n ): AsyncIterable<ModelStreamChunk> {\n this.logger.debug(LOG_MODULE, \"request\", \"Starting ConverseStream call\", {\n model: this.name,\n messageCount: messages.length,\n streaming: true,\n toolCount: options?.tools?.length ?? 0,\n });\n\n let response;\n\n try {\n response = await this.client.send(\n new ConverseStreamCommand(this.buildRequest(messages, options)),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n let rawStopReason: string | undefined;\n let usage: Usage = { input: 0, output: 0, total: 0 };\n const want = resolveStreamChunks(options);\n const toolBlocks = new Map<number, { id: string; name: string; json: string }>();\n const reasoningBlocks = new Map<\n number,\n { text?: string; signature?: string; redactedContent?: Uint8Array }\n >();\n const completedReasoningBlocks: BedrockReasoningBlock[] = [];\n\n try {\n for await (const event of response.stream ?? []) {\n if (event.contentBlockStart?.start?.toolUse) {\n const start = event.contentBlockStart.start.toolUse;\n\n // A system tool's `server_tool_use` runs on Bedrock's side.\n if (start.type === SERVER_TOOL_USE) {\n continue;\n }\n\n toolBlocks.set(event.contentBlockStart.contentBlockIndex ?? 0, {\n id: start.toolUseId ?? \"\",\n name: start.name ?? \"\",\n json: \"\",\n });\n\n continue;\n }\n\n if (event.contentBlockDelta?.delta) {\n const delta = event.contentBlockDelta.delta;\n\n if (delta.text) {\n yield { type: \"delta\", content: delta.text };\n } else if (delta.toolUse) {\n const accumulator = toolBlocks.get(event.contentBlockDelta.contentBlockIndex ?? 0);\n\n if (accumulator) {\n accumulator.json += delta.toolUse.input ?? \"\";\n\n if (want.toolArgs && delta.toolUse.input) {\n yield {\n type: \"tool-args\",\n callId: accumulator.id,\n name: accumulator.name,\n delta: delta.toolUse.input,\n };\n }\n }\n } else if (delta.reasoningContent) {\n const index = event.contentBlockDelta.contentBlockIndex ?? 0;\n const accumulator = reasoningBlocks.get(index) ?? {};\n\n if (delta.reasoningContent.text !== undefined) {\n accumulator.text = (accumulator.text ?? \"\") + delta.reasoningContent.text;\n\n if (want.reasoning && delta.reasoningContent.text !== \"\") {\n yield { type: \"reasoning\", delta: delta.reasoningContent.text };\n }\n }\n\n if (delta.reasoningContent.signature !== undefined) {\n accumulator.signature = delta.reasoningContent.signature;\n }\n\n if (delta.reasoningContent.redactedContent !== undefined) {\n accumulator.redactedContent = delta.reasoningContent.redactedContent;\n }\n\n reasoningBlocks.set(index, accumulator);\n }\n\n continue;\n }\n\n if (event.contentBlockStop) {\n const index = event.contentBlockStop.contentBlockIndex ?? 0;\n const accumulator = toolBlocks.get(index);\n\n if (accumulator) {\n yield {\n type: \"tool-call\",\n id: accumulator.id,\n name: accumulator.name,\n input: safeJsonParse<Record<string, unknown>>(accumulator.json, {}),\n ...(completedReasoningBlocks.length > 0\n ? { providerMetadata: { bedrock: { reasoningBlocks: completedReasoningBlocks } } }\n : {}),\n };\n\n toolBlocks.delete(index);\n }\n\n const reasoningAccumulator = reasoningBlocks.get(index);\n\n if (reasoningAccumulator) {\n const reasoningBlock = this.toReasoningMetadata(reasoningAccumulator);\n\n if (reasoningBlock) {\n completedReasoningBlocks.push(reasoningBlock);\n }\n reasoningBlocks.delete(index);\n }\n\n continue;\n }\n\n if (event.messageStop) {\n rawStopReason = event.messageStop.stopReason;\n }\n\n if (event.metadata?.usage) {\n usage = this.extractUsage(event.metadata.usage);\n }\n }\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n const finishReason = mapStopReason(rawStopReason);\n\n attachCost(usage, this.pricing);\n\n this.logger.debug(LOG_MODULE, \"response\", \"ConverseStream call succeeded\", {\n finishReason,\n usage,\n });\n\n yield { type: \"done\", finishReason, usage };\n }\n\n /**\n * Assemble the Converse request shared by `complete()` and\n * `stream()` (both command shapes take the same input). Hoists the\n * system prompt, maps inference params, and conditionally attaches\n * tools and native structured output.\n */\n private buildRequest(\n messages: Message[],\n options: ModelCallOptions | undefined,\n ): ConverseRequest {\n const { system, messages: bedrockMessages } = toBedrockMessages(messages);\n const thinkingBudget = this.resolveThinkingBudget(options?.reasoning);\n const configuredMaxTokens = options?.maxTokens ?? this.config.maxTokens;\n const maxTokens = this.resolveMaxTokens(configuredMaxTokens, thinkingBudget);\n const temperature = options?.temperature ?? this.config.temperature;\n const cachePoint = this.resolveCachePoint(options?.cacheControl);\n const cachedMessages = this.applyCacheBreakpoints(bedrockMessages, cachePoint);\n const cachedSystem = system && cachePoint ? [...system, { cachePoint }] : system;\n\n return mergeProviderBody<ConverseRequest>(\n {\n modelId: this.name,\n messages: cachedMessages,\n ...(cachedSystem ? { system: cachedSystem } : {}),\n inferenceConfig: {\n ...(maxTokens !== undefined ? { maxTokens } : {}),\n ...(temperature !== undefined ? { temperature } : {}),\n },\n ...this.buildToolConfig(options, cachePoint),\n ...this.buildOutputConfig(options?.responseSchema),\n ...this.buildReasoningConfig(thinkingBudget),\n },\n options,\n );\n }\n\n /**\n * Resolve the Converse `cachePoint` to place for this call, or\n * `undefined` when no cache point applies (the model is not\n * `promptCaching`-capable or no `cacheControl` breakpoint was asked\n * for). Bedrock only honors `type: \"default\"`; the neutral\n * `breakpoints` count is a presence hint.\n *\n * The lifetime is the per-call `cacheControl.ttl`, else the model's\n * `promptCacheTtl`. `ttl: \"1h\"` is sent only to models that accept it\n * ({@link supportsOneHourCacheTtl}); any other model gets the 5-minute\n * default, because AWS rejects the field there.\n */\n private resolveCachePoint(\n cacheControl: ModelCallOptions[\"cacheControl\"],\n ): BedrockCachePoint | undefined {\n const breakpoints = cacheControl?.breakpoints ?? 0;\n\n if (!this.capabilities.promptCaching || breakpoints <= 0) {\n return undefined;\n }\n\n const ttl = cacheControl?.ttl ?? this.config.promptCacheTtl;\n\n return ttl === \"1h\" && supportsOneHourCacheTtl(this.name)\n ? { type: \"default\", ttl: \"1h\" }\n : { type: \"default\" };\n }\n\n /**\n * Append the call's `cachePoint` to the LAST message. Together with the\n * `system` and `tools` cache points (see `buildRequest` /\n * `buildToolConfig`) this caches every stable segment of the prefix —\n * Bedrock processes them in `tools` → `system` → `messages` order, at\n * most three of the four checkpoints it allows — so later calls reusing\n * the prefix bill it at the cache-read rate (`Usage.cachedTokens`).\n */\n private applyCacheBreakpoints(\n messages: ConverseRequest[\"messages\"],\n cachePoint: BedrockCachePoint | undefined,\n ): ConverseRequest[\"messages\"] {\n if (!cachePoint || !messages || messages.length === 0) {\n return messages;\n }\n\n const last = messages.length - 1;\n const lastMessage = messages[last];\n\n if (!lastMessage) {\n return messages;\n }\n\n return [\n ...messages.slice(0, last),\n {\n ...lastMessage,\n content: [...(lastMessage.content ?? []), { cachePoint }],\n },\n ];\n }\n\n /**\n * Translate the neutral `reasoning` option into Claude-on-Bedrock's\n * extended-thinking control, carried in Converse's escape hatch\n * `additionalModelRequestFields.thinking`. Emitted only when the model\n * is `reasoning`-capable and a budget can be resolved — `maxTokens`\n * (explicit thinking budget) wins, otherwise `effort` maps to a\n * conventional token budget so callers can opt in without picking a\n * number. Returns an empty object (no-op) for non-reasoning models or\n * when no reasoning option was supplied, so unsupported params never\n * reach the wire.\n */\n private resolveThinkingBudget(reasoning: ModelCallOptions[\"reasoning\"]): number | undefined {\n if (!this.capabilities.reasoning || !reasoning || reasoning.effort === \"none\") {\n return undefined;\n }\n\n const budgetTokens = reasoning.maxTokens ?? EFFORT_THINKING_BUDGET[reasoning.effort ?? \"\"];\n\n if (budgetTokens !== undefined && budgetTokens < MIN_THINKING_BUDGET) {\n throw new Error(`thinking budget (${budgetTokens}) must be at least ${MIN_THINKING_BUDGET}`);\n }\n\n return budgetTokens;\n }\n\n /** Resolve Bedrock's output ceiling while reserving room for extended thinking. */\n private resolveMaxTokens(\n maxTokens: number | undefined,\n thinkingBudget: number | undefined,\n ): number | undefined {\n if (thinkingBudget === undefined) {\n return maxTokens;\n }\n\n if (maxTokens === undefined) {\n return thinkingBudget + DEFAULT_MAX_TOKENS;\n }\n\n if (maxTokens <= thinkingBudget) {\n throw new Error(\n `maxTokens (${maxTokens}) must be greater than thinking budget (${thinkingBudget})`,\n );\n }\n\n return maxTokens;\n }\n\n private buildReasoningConfig(\n budgetTokens: number | undefined,\n ): Pick<ConverseRequest, \"additionalModelRequestFields\"> {\n if (budgetTokens === undefined) {\n return {};\n }\n\n return {\n additionalModelRequestFields: {\n thinking: { type: \"enabled\", budget_tokens: budgetTokens },\n },\n };\n }\n\n /**\n * Spread-friendly tool fragment. Returns an empty object when no\n * tools were supplied (Bedrock rejects an empty `tools` array). With a\n * cache point, a trailing `{ cachePoint }` caches every tool definition\n * — Claude only, since Nova accepts no cache point in `tools`.\n */\n private buildToolConfig(\n options: ModelCallOptions | undefined,\n cachePoint: BedrockCachePoint | undefined,\n ): Pick<ConverseRequest, \"toolConfig\"> {\n const { tools, definitions } = selectProviderTools(options, {\n accepts: [BEDROCK_WIRE_FORMAT, this.provider],\n module: LOG_MODULE,\n model: this.name,\n logger: this.logger,\n });\n const toolConfig = toBedrockToolConfig(tools);\n // Provider-defined entries are whole Converse `Tool` members, e.g.\n // `{ systemTool: { name: \"nova_grounding\" } }` (Nova web grounding).\n const providerDefined = definitions as unknown as Tool[];\n\n const allTools = [...(toolConfig?.tools ?? []), ...providerDefined];\n\n if (allTools.length === 0) {\n return toolConfig ? { toolConfig } : {};\n }\n\n // The cache point goes last, so every tool definition is cached.\n const withCachePoint =\n cachePoint && supportsToolCachePoint(this.name) ? [...allTools, { cachePoint }] : allTools;\n\n return { toolConfig: { ...toolConfig, tools: withCachePoint } };\n }\n\n /**\n * Translate the neutral `responseSchema` into Converse's native\n * `outputConfig.textFormat` (JSON-schema structured output). Bedrock\n * requires the schema as a stringified JSON document and only\n * accepts an object root. Emitted only when the model is\n * `structuredOutput`-capable and the schema is an object — otherwise\n * the agent's soft system-prompt hint + client-side `validate()`\n * carry shape (same degradation philosophy as the OpenAI adapter).\n */\n private buildOutputConfig(\n responseSchema: Record<string, unknown> | undefined,\n ): Pick<ConverseRequest, \"outputConfig\"> {\n if (!responseSchema || !this.capabilities.structuredOutput) {\n return {};\n }\n\n if (responseSchema.type !== \"object\" || typeof responseSchema.properties !== \"object\") {\n return {};\n }\n\n return {\n outputConfig: {\n textFormat: {\n type: \"json_schema\",\n structure: {\n jsonSchema: { name: \"response\", schema: JSON.stringify(responseSchema) },\n },\n },\n },\n };\n }\n\n /**\n * Concatenate every `text` content block into the single neutral\n * `content` string. `toolUse` and other block types are surfaced\n * separately via `extractToolCalls`.\n */\n private extractText(blocks: ContentBlock[]): string {\n return blocks\n .map((block) => (\"text\" in block && typeof block.text === \"string\" ? block.text : \"\"))\n .join(\"\");\n }\n\n /**\n * Reshape Converse `toolUse` content blocks into the neutral\n * `ModelToolCallRequest[]`. Returns `undefined` when no tools were\n * requested so callers can branch on presence.\n */\n private extractToolCalls(blocks: ContentBlock[]): ModelToolCallRequest[] | undefined {\n const toolCalls: ModelToolCallRequest[] = [];\n const reasoningBlocks = blocks\n .map(toReasoningMetadata)\n .filter((block): block is BedrockReasoningBlock => block !== undefined);\n\n for (const block of blocks) {\n // `server_tool_use` blocks are run by Bedrock (system tools such as\n // Nova grounding); only client tool uses are dispatched.\n if (\"toolUse\" in block && block.toolUse && block.toolUse.type !== SERVER_TOOL_USE) {\n toolCalls.push({\n id: block.toolUse.toolUseId ?? \"\",\n name: block.toolUse.name ?? \"\",\n input: (block.toolUse.input ?? {}) as Record<string, unknown>,\n ...(reasoningBlocks.length > 0\n ? { providerMetadata: { bedrock: { reasoningBlocks } } }\n : {}),\n });\n }\n }\n\n return toolCalls.length > 0 ? toolCalls : undefined;\n }\n\n /** Encode accumulated stream deltas as persistence-safe reasoning metadata. */\n private toReasoningMetadata(block: {\n text?: string;\n signature?: string;\n redactedContent?: Uint8Array;\n }): BedrockReasoningBlock | undefined {\n if (block.redactedContent !== undefined) {\n return toReasoningMetadata({ reasoningContent: { redactedContent: block.redactedContent } });\n }\n\n return toReasoningMetadata({\n reasoningContent: {\n reasoningText: {\n text: block.text ?? \"\",\n ...(block.signature ? { signature: block.signature } : {}),\n },\n },\n });\n }\n\n /**\n * Normalize Converse's `TokenUsage` into the neutral `Usage` shape.\n * Bedrock supplies a pre-summed `totalTokens`; cache-read and\n * cache-write tokens are surfaced as `cachedTokens` /\n * `cacheWriteTokens` only when non-zero, and the 1-hour share of the\n * writes (`cacheDetails` entries with `ttl: \"1h\"`) as\n * `cacheWrite1hTokens`. With caching, `inputTokens` \"represents only\n * the non-cached input tokens\" (AWS prompt-caching guide), so the usage\n * is marked `inputIncludesCache: false`. Bedrock's Converse `TokenUsage`\n * carries no reasoning-token channel, so `Usage.reasoningTokens` is\n * intentionally left unset here.\n */\n private extractUsage(raw: TokenUsage | undefined): Usage {\n if (!raw) {\n return { input: 0, output: 0, total: 0 };\n }\n\n const input = raw.inputTokens ?? 0;\n const output = raw.outputTokens ?? 0;\n const cached = raw.cacheReadInputTokens;\n const cacheWrite = raw.cacheWriteInputTokens;\n const cacheWrite1h = (raw.cacheDetails ?? [])\n .filter((detail) => detail.ttl === \"1h\")\n .reduce((sum, detail) => sum + (detail.inputTokens ?? 0), 0);\n\n return {\n input,\n output,\n total: raw.totalTokens ?? input + output,\n inputIncludesCache: false,\n ...(cached && cached > 0 ? { cachedTokens: cached } : {}),\n ...(cacheWrite && cacheWrite > 0 ? { cacheWriteTokens: cacheWrite } : {}),\n ...(cacheWrite && cacheWrite > 0 && cacheWrite1h > 0\n ? { cacheWrite1hTokens: Math.min(cacheWrite1h, cacheWrite) }\n : {}),\n };\n }\n\n /**\n * Wrap a thrown provider error into the typed `AIError` hierarchy\n * and emit the standard error log line before it propagates. Shared\n * by every catch site so the log shape stays identical.\n */\n private logAndWrap(thrown: unknown) {\n const wrapped = wrapBedrockError(thrown);\n\n this.logger.error(LOG_MODULE, \"error\", wrapped.message, {\n code: wrapped.code,\n context: wrapped.context,\n });\n\n return wrapped;\n }\n}\n","import { BedrockRuntimeClient } from \"@aws-sdk/client-bedrock-runtime\";\nimport type {\n EmbedderContract,\n ModelContract,\n ModelPricing,\n SDKAdapterContract,\n} from \"@warlock.js/ai\";\nimport { approximateTokenCount, InvalidRequestError } from \"@warlock.js/ai\";\nimport type { BedrockEmbedderConfig, BedrockModelConfig, BedrockSDKConfig } from \"./config.type\";\nimport { BedrockEmbedder } from \"./embedder\";\nimport { BedrockModel } from \"./model\";\n\n/**\n * AWS Bedrock-backed implementation of `SDKAdapterContract`.\n *\n * **Role.** The package entry point for any Bedrock-hosted model via\n * the Converse API. A single `BedrockSDK` holds one live\n * `BedrockRuntimeClient`, shared by every `ModelContract` and\n * `EmbedderContract` it produces. Construct one SDK per AWS\n * account/region and reuse it everywhere.\n *\n * **Responsibility.**\n * - Owns: a long-lived `BedrockRuntimeClient` (region, credential\n * chain) and its lifetime. Factory for `BedrockModel` /\n * `BedrockEmbedder` instances sharing that client.\n * - Does NOT own: anything per-call — those live in `BedrockModel` /\n * `BedrockEmbedder` and the agent runtime.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across many calls\"): the AWS client is heavy to construct and\n * designed for reuse; keeping it on `this` aligns with the\n * `new BedrockRuntimeClient(...)` upstream convention.\n *\n * @example\n * const bedrock = new BedrockSDK({ region: \"us-east-1\" });\n * const model = bedrock.model({ name: \"anthropic.claude-sonnet-4-5-20250929-v1:0\" });\n * const embedder = bedrock.embedder({ name: \"amazon.titan-embed-text-v2:0\" });\n *\n * @example\n * // Amazon Bedrock API key (bearer auth) instead of the AWS credential chain\n * const bedrock = new BedrockSDK({ apiKey: process.env.BEDROCK_API_KEY!, region: \"us-east-1\" });\n */\nexport class BedrockSDK implements SDKAdapterContract {\n private readonly client: BedrockRuntimeClient;\n private readonly provider: string;\n private readonly pricing?: Record<string, ModelPricing>;\n\n public constructor(config: BedrockSDKConfig) {\n const { provider, pricing, apiKey, ...clientConfig } = config;\n\n this.client = new BedrockRuntimeClient(\n apiKey === undefined ? clientConfig : withApiKey(clientConfig, apiKey),\n );\n this.provider = provider ?? \"bedrock\";\n this.pricing = pricing;\n }\n\n /**\n * Build a `BedrockModel` bound to this SDK's client. Each call\n * returns a fresh instance; all instances share the underlying AWS\n * client so connection pools, credential refresh, and retry config\n * stay unified. The SDK's `provider` label is forwarded.\n *\n * Pricing resolution: per-model `config.pricing` wins; otherwise the\n * SDK-level registry entry keyed by `config.name`; otherwise\n * `undefined` (no cost computed).\n */\n public model(config: BedrockModelConfig): ModelContract {\n const resolvedPricing = config.pricing ?? this.pricing?.[config.name];\n const resolvedConfig: BedrockModelConfig =\n resolvedPricing === config.pricing ? config : { ...config, pricing: resolvedPricing };\n\n return new BedrockModel(this.client, resolvedConfig, this.provider);\n }\n\n /**\n * Rough token-count estimate. Uses the character-heuristic\n * (`approximateTokenCount`) from the core package — Bedrock has no\n * offline tokenizer and the per-model tokenizers differ; good enough\n * for budgeting and quota guards, not for billing.\n */\n public async count(text: string, _model?: string): Promise<number> {\n return approximateTokenCount(text);\n }\n\n /**\n * Build a `BedrockEmbedder` (Amazon Titan Text Embeddings) bound to\n * this SDK's client.\n *\n * @example\n * const embedder = bedrock.embedder({ name: \"amazon.titan-embed-text-v2:0\" });\n * const { vector } = await embedder.embed(\"Hello world\");\n */\n public embedder(config: BedrockEmbedderConfig): EmbedderContract {\n return new BedrockEmbedder(this.client, config, this.provider);\n }\n}\n\n/**\n * Configure the runtime client for an Amazon Bedrock API key.\n *\n * Bedrock API keys are bearer tokens: the request carries\n * `Authorization: Bearer <key>` instead of a SigV4 signature (AWS docs,\n * \"Use an Amazon Bedrock API key\",\n * https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys-use.html,\n * checked 2026-10-17). The installed `@aws-sdk/client-bedrock-runtime`\n * supports this natively: its auth scheme provider offers\n * `smithy.api#httpBearerAuth` beside SigV4, fed by the client's `token`\n * option, and `authSchemePreference: [\"httpBearerAuth\"]` selects it ahead\n * of SigV4, so the AWS credential chain is never consulted.\n *\n * Fails closed on an empty key, and on a key combined with `credentials`\n * or `token` — two credentials for one client leave which one signs the\n * request ambiguous.\n */\nfunction withApiKey(\n clientConfig: Omit<BedrockSDKConfig, \"provider\" | \"pricing\" | \"apiKey\">,\n apiKey: string,\n): Omit<BedrockSDKConfig, \"provider\" | \"pricing\" | \"apiKey\"> {\n if (typeof apiKey !== \"string\" || apiKey.trim() === \"\") {\n throw new InvalidRequestError(\"BedrockSDK: `apiKey` must be a non-empty string.\");\n }\n\n const conflicting = ([\"credentials\", \"token\"] as const).filter(\n (field) => clientConfig[field] !== undefined,\n );\n\n if (conflicting.length > 0) {\n throw new InvalidRequestError(\n `BedrockSDK: pass either \\`apiKey\\` or ${conflicting.map((field) => `\\`${field}\\``).join(\" / \")}, not both.`,\n { context: { fields: conflicting } },\n );\n }\n\n return {\n ...clientConfig,\n token: { token: apiKey },\n authSchemePreference: [\"httpBearerAuth\"],\n };\n}\n"],"mappings":";;;;;;AAEA,MAAM,gBAA8C;CAClD,UAAU;CACV,eAAe;CACf,YAAY;CACZ,UAAU;AACZ;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,cAAc,KAA8C;CAC1E,OAAO,cAAc,OAAO,OAAO;AACrC;;;;;AChBA,SAAgB,oBAAoB,OAAwD;CAC1F,MAAM,YAAY,MAAM;CAExB,IAAI,CAAC,WACH;CAGF,IAAI,UAAU,eAAe;EAC3B,MAAM,EAAE,MAAM,cAAc,UAAU;EAEtC,IAAI,OAAO,SAAS,UAClB;EAGF,OAAO;GAAE,MAAM;GAAa;GAAM,GAAI,OAAO,cAAc,WAAW,EAAE,UAAU,IAAI,CAAC;EAAG;CA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derTimeoutError","ProviderAuthError","QuotaExceededError","ProviderRateLimitError","ProviderOverloadedError","ContextLengthExceededError","InvalidRequestError","ProviderError","LOG_MODULE","log","InvokeModelCommand","InvalidRequestError","log","ConverseCommand","attachCost","CountTokensCommand","InvalidRequestError","ConverseStreamCommand","resolveStreamChunks","safeJsonParse","selectProviderTools","BedrockRuntimeClient","approximateTokenCount","InvalidRequestError"],"sources":["../../../../../../../packages/ai-bedrock/src/utils/map-stop-reason.ts","../../../../../../../packages/ai-bedrock/src/utils/reasoning-blocks.ts","../../../../../../../packages/ai-bedrock/src/utils/to-bedrock-messages.ts","../../../../../../../packages/ai-bedrock/src/utils/to-bedrock-tools.ts","../../../../../../../packages/ai-bedrock/src/utils/wrap-bedrock-error.ts","../../../../../../../packages/ai-bedrock/src/embedder.ts","../../../../../../../packages/ai-bedrock/src/provider-options.ts","../../../../../../../packages/ai-bedrock/src/known-capabilities.ts","../../../../../../../packages/ai-bedrock/src/known-pricing.ts","../../../../../../../packages/ai-bedrock/src/known-vision-models.ts","../../../../../../../packages/ai-bedrock/src/model.ts","../../../../../../../packages/ai-bedrock/src/sdk.ts"],"sourcesContent":["import type { FinishReason } from \"@warlock.js/ai\";\n\nconst stopReasonMap: Record<string, FinishReason> = {\n end_turn: \"stop\",\n stop_sequence: \"stop\",\n max_tokens: \"length\",\n tool_use: \"tool_calls\",\n};\n\n/**\n * Map Bedrock Converse's `stopReason` to the normalized `FinishReason`\n * union.\n *\n * `end_turn` / `stop_sequence` are natural stops. `max_tokens` maps to\n * `length`. `tool_use` maps to `tool_calls`. Everything else —\n * `content_filtered`, `guardrail_intervened`, `malformed_tool_use`,\n * `malformed_model_output`, `model_context_window_exceeded`, `null`,\n * or any future value — falls through to `\"error\"`: none produced a\n * clean terminal answer, so the agent must not treat them as success.\n *\n * @example\n * mapStopReason(\"end_turn\"); // \"stop\"\n * mapStopReason(\"tool_use\"); // \"tool_calls\"\n * mapStopReason(\"guardrail_intervened\"); // \"error\"\n * mapStopReason(undefined); // \"error\"\n */\nexport function mapStopReason(raw: string | null | undefined): FinishReason {\n return stopReasonMap[raw ?? \"\"] ?? \"error\";\n}\n","import type { ContentBlock } from \"@aws-sdk/client-bedrock-runtime\";\n\n/**\n * JSON-safe representation of a Bedrock Converse reasoning block retained in\n * tool-call provider metadata. Binary redacted reasoning is base64 encoded so\n * it survives message-history persistence unchanged.\n */\nexport type BedrockReasoningBlock =\n | { type: \"reasoning\"; text: string; signature?: string }\n | { type: \"redacted\"; data: string };\n\n/** Convert a Converse reasoning content block to persistence-safe metadata. */\nexport function toReasoningMetadata(block: ContentBlock): BedrockReasoningBlock | undefined {\n const reasoning = block.reasoningContent;\n\n if (!reasoning) {\n return undefined;\n }\n\n if (reasoning.reasoningText) {\n const { text, signature } = reasoning.reasoningText;\n\n if (typeof text !== \"string\") {\n return undefined;\n }\n\n return { type: \"reasoning\", text, ...(typeof signature === \"string\" ? { signature } : {}) };\n }\n\n if (reasoning.redactedContent instanceof Uint8Array) {\n return { type: \"redacted\", data: Buffer.from(reasoning.redactedContent).toString(\"base64\") };\n }\n\n return undefined;\n}\n\n/** Restore one persistence-safe metadata entry to a Converse reasoning block. */\nexport function fromReasoningMetadata(value: unknown): ContentBlock | undefined {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return undefined;\n }\n\n if (value.type === \"reasoning\" && typeof value.text === \"string\") {\n return {\n reasoningContent: {\n reasoningText: {\n text: value.text,\n ...(typeof value.signature === \"string\" ? { signature: value.signature } : {}),\n },\n },\n };\n }\n\n if (value.type === \"redacted\" && typeof value.data === \"string\" && isBase64(value.data)) {\n return {\n reasoningContent: { redactedContent: new Uint8Array(Buffer.from(value.data, \"base64\")) },\n };\n }\n\n return undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\n/** Require canonical base64, avoiding Buffer's permissive decoding of garbage. */\nfunction isBase64(value: string): boolean {\n if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {\n return false;\n }\n\n return Buffer.from(value, \"base64\").toString(\"base64\") === value;\n}\n","import { InvalidRequestError, type ContentPart, type Message } from \"@warlock.js/ai\";\nimport type {\n ContentBlock,\n ImageFormat,\n Message as BedrockMessage,\n SystemContentBlock,\n} from \"@aws-sdk/client-bedrock-runtime\";\nimport { fromReasoningMetadata } from \"./reasoning-blocks\";\n\n/**\n * Result of splitting a vendor-neutral `Message[]` for the Bedrock\n * Converse API: system prompts hoist to a separate `SystemContentBlock[]`\n * (Converse has no `\"system\"` role inside `messages`), and the\n * remaining turns map to Bedrock `Message[]`.\n */\nexport type BedrockMessages = {\n system: SystemContentBlock[] | undefined;\n messages: BedrockMessage[];\n};\n\nconst MEDIA_TYPE_TO_FORMAT: Record<string, ImageFormat> = {\n \"image/jpeg\": \"jpeg\",\n \"image/png\": \"png\",\n \"image/gif\": \"gif\",\n \"image/webp\": \"webp\",\n};\n\n/**\n * Convert vendor-neutral `Message[]` into Bedrock Converse's request\n * shape.\n *\n * Converse differs from the OpenAI Chat protocol in three ways this\n * function absorbs:\n *\n * 1. **No `system` role.** System messages become a separate\n * `SystemContentBlock[]` (one `{ text }` block each).\n * 2. **Tool results are `user` turns.** A neutral `tool` message\n * becomes a `user` message carrying a single `toolResult` block.\n * 3. **Tool calls are `toolUse` content blocks.** An assistant message\n * with `toolCalls` becomes an `assistant` message: an optional\n * leading `text` block followed by one `toolUse` block per call.\n *\n * @example\n * const { system, messages } = toBedrockMessages([\n * { role: \"system\", content: \"Be concise.\" },\n * { role: \"user\", content: \"Hi\" },\n * ]);\n */\nexport function toBedrockMessages(messages: Message[]): BedrockMessages {\n const system: SystemContentBlock[] = [];\n const mapped: BedrockMessage[] = [];\n\n for (const message of messages) {\n if (message.role === \"system\") {\n system.push({ text: stringifyContent(message.content) });\n\n continue;\n }\n\n if (message.role === \"tool\") {\n mapped.push({\n role: \"user\",\n content: [\n {\n toolResult: {\n toolUseId: message.toolCallId ?? \"\",\n content: [{ text: stringifyContent(message.content) }],\n },\n },\n ],\n });\n\n continue;\n }\n\n if (message.role === \"assistant\" && message.toolCalls && message.toolCalls.length > 0) {\n const blocks: ContentBlock[] = [];\n const text = stringifyContent(message.content);\n const reasoningBlocks = getReasoningBlocks(message.toolCalls);\n\n blocks.push(...reasoningBlocks);\n\n if (text) {\n blocks.push({ text });\n }\n\n for (const toolCall of message.toolCalls) {\n blocks.push({\n toolUse: {\n toolUseId: toolCall.id,\n name: toolCall.name,\n input: toolCall.input ?? {},\n },\n } as ContentBlock);\n }\n\n mapped.push({ role: \"assistant\", content: blocks });\n\n continue;\n }\n\n if (message.role === \"user\" && Array.isArray(message.content)) {\n mapped.push({\n role: \"user\",\n content: message.content.map(toBedrockContentBlock),\n });\n\n continue;\n }\n\n mapped.push({\n role: message.role === \"assistant\" ? \"assistant\" : \"user\",\n content: [{ text: stringifyContent(message.content) }],\n });\n }\n\n return {\n system: system.length > 0 ? system : undefined,\n messages: mergeAdjacentTurns(mapped),\n };\n}\n\n/** Converse requires alternating turns; preserve every content block in order. */\nfunction mergeAdjacentTurns(messages: BedrockMessage[]): BedrockMessage[] {\n const merged: BedrockMessage[] = [];\n for (const message of messages) {\n const previous = merged[merged.length - 1];\n if (previous && previous.role === message.role) {\n previous.content!.push(...(message.content ?? []));\n } else {\n merged.push({ ...message, content: [...(message.content ?? [])] });\n }\n }\n return merged;\n}\n\n/**\n * Recover opaque Converse reasoning blocks retained on a prior tool call.\n * Bedrock requires them to be replayed before the assistant's text and\n * tool-use blocks on the follow-up request.\n */\nfunction getReasoningBlocks(toolCalls: NonNullable<Message[\"toolCalls\"]>): ContentBlock[] {\n for (const toolCall of toolCalls) {\n const bedrock = toolCall.providerMetadata?.bedrock;\n\n if (!isRecord(bedrock) || !Array.isArray(bedrock.reasoningBlocks)) {\n continue;\n }\n\n return bedrock.reasoningBlocks\n .map(fromReasoningMetadata)\n .filter((block): block is ContentBlock => block !== undefined);\n }\n\n return [];\n}\n\n/** Narrow an opaque metadata value to an object without altering its contents. */\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Multipart content is only meaningful on user messages — for any other\n * role collapse a `ContentPart[]` to its concatenated text. Plain\n * strings pass through unchanged.\n */\nfunction stringifyContent(content: string | ContentPart[]): string {\n if (typeof content === \"string\") {\n return content;\n }\n\n return content\n .filter((part): part is { type: \"text\"; text: string } => part.type === \"text\")\n .map((part) => part.text)\n .join(\"\");\n}\n\n/**\n * Map a resolved `ContentPart` to a Bedrock `ContentBlock`. Bedrock's\n * `ImageSource` only accepts raw bytes or an S3 location — there is no\n * remote-URL source. A neutral `{ url }` image therefore cannot be\n * sent and surfaces a typed `InvalidRequestError` upfront rather than\n * a downstream Bedrock validation fault. The agent has already\n * resolved attachments, so this never fetches or reads anything.\n */\nfunction toBedrockContentBlock(part: ContentPart): ContentBlock {\n if (part.type === \"text\") {\n return { text: part.text };\n }\n\n if (\"url\" in part.source) {\n throw new InvalidRequestError(\n \"Bedrock Converse does not support remote-URL sources; supply base64 bytes instead.\",\n );\n }\n\n // PDF → Bedrock `document` content block (A2). Converse accepts a\n // document block with raw bytes; the agent gates this on the model's\n // `pdf` capability before it reaches here.\n if (part.type === \"pdf\") {\n return {\n document: {\n format: \"pdf\",\n name: \"attachment\",\n source: { bytes: Buffer.from(part.source.base64, \"base64\") },\n },\n } as unknown as ContentBlock;\n }\n\n // Bedrock Converse has no audio content block (capability stays false).\n if (part.type === \"audio\") {\n throw new InvalidRequestError(\"Bedrock Converse does not support audio attachments.\");\n }\n\n const format = MEDIA_TYPE_TO_FORMAT[part.source.mediaType];\n\n if (!format) {\n throw new InvalidRequestError(\n `Unsupported image media type for Bedrock: \"${part.source.mediaType}\" (expected image/jpeg, image/png, image/gif, or image/webp).`,\n );\n }\n\n return {\n image: {\n format,\n source: { bytes: Buffer.from(part.source.base64, \"base64\") },\n },\n };\n}\n","import { extractJsonSchema, type ToolConfig } from \"@warlock.js/ai\";\nimport type { Tool, ToolConfiguration, ToolInputSchema } from \"@aws-sdk/client-bedrock-runtime\";\n\n/**\n * Convert vendor-neutral `ToolConfig[]` into Bedrock Converse's\n * `ToolConfiguration`. Each tool becomes a `toolSpec` with a JSON\n * `inputSchema`. Bedrock requires the schema root to be an object —\n * a non-object extraction degrades to a parameterless object schema\n * so registration never fails.\n *\n * Returns `undefined` when there are no tools so the caller can omit\n * `toolConfig` from the request entirely (Bedrock rejects an empty\n * `tools` array).\n *\n * @example\n * const toolConfig = toBedrockToolConfig([weatherTool]);\n * await client.send(new ConverseCommand({ modelId, messages, toolConfig }));\n */\nexport function toBedrockToolConfig(\n tools: ToolConfig<unknown, unknown>[] | undefined,\n): ToolConfiguration | undefined {\n if (!tools || tools.length === 0) {\n return undefined;\n }\n\n return {\n tools: tools.map((tool): Tool => ({\n toolSpec: {\n name: tool.name,\n description: tool.description,\n inputSchema: { json: toJsonSchema(tool.input) } as ToolInputSchema,\n },\n })),\n };\n}\n\n/**\n * Resolve a tool's input schema to a JSON-Schema object. Bedrock's\n * `ToolInputSchema.json` requires an object root; anything else (or a\n * failed extraction) degrades to a parameterless object so the tool\n * still registers.\n */\nfunction toJsonSchema(input: ToolConfig<unknown, unknown>[\"input\"]): Record<string, unknown> {\n const schema = extractJsonSchema(input);\n\n if (schema && schema.type === \"object\") {\n return schema;\n }\n\n return { type: \"object\" };\n}\n","import {\n AIError,\n ContextLengthExceededError,\n InvalidRequestError,\n ProviderAuthError,\n ProviderError,\n ProviderOverloadedError,\n ProviderRateLimitError,\n ProviderTimeoutError,\n QuotaExceededError,\n} from \"@warlock.js/ai\";\n\n/**\n * Raw-error fields the wrapper reads off an AWS SDK exception. Every\n * Bedrock error is a Smithy `__BaseException` with a stable `name`\n * (`\"ThrottlingException\"`, `\"ValidationException\"`, …) and a\n * `$metadata` carrying `httpStatusCode` + `requestId`. We duck-type\n * because retries and proxies sometimes flatten the prototype chain.\n */\ntype BedrockErrorShape = {\n name?: string;\n message?: string;\n httpStatusCode?: number;\n requestId?: string;\n code?: string;\n};\n\nconst TIMEOUT_NAMES = new Set([\n \"ModelTimeoutException\",\n \"TimeoutError\",\n \"RequestTimeout\",\n \"RequestTimeoutException\",\n]);\n\n/**\n * Wrap any thrown value caught inside the Bedrock adapter into the\n * appropriate `@warlock.js/ai` `AIError` subclass.\n *\n * **Dispatch strategy.** AWS errors carry no provider machine `code`;\n * the stable identifier is the Smithy exception `name`. Dispatch keys\n * on `name`, falls back to `$metadata.httpStatusCode` when the name is\n * missing (flattened/proxied errors). `ValidationException` is split:\n * the \"input is too long / exceeds context window\" phrasing maps to\n * `ContextLengthExceededError`, everything else to\n * `InvalidRequestError`.\n *\n * `AIError` instances pass through unchanged so `catch/throw wrap(e)`\n * pipelines never double-wrap.\n *\n * @example\n * try {\n * return await this.client.send(new ConverseCommand(...));\n * } catch (thrown) {\n * throw wrapBedrockError(thrown);\n * }\n */\nexport function wrapBedrockError(thrown: unknown): AIError {\n if (thrown instanceof AIError) {\n return thrown;\n }\n\n const shape = toShape(thrown);\n const context = buildContext(shape);\n const message = shape.message ?? (thrown instanceof Error ? thrown.message : String(thrown));\n\n if (isTimeout(shape)) {\n return new ProviderTimeoutError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"AccessDeniedException\" || shape.httpStatusCode === 403) {\n return new ProviderAuthError(message, { cause: thrown, context });\n }\n\n if (shape.httpStatusCode === 401) {\n return new ProviderAuthError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ServiceQuotaExceededException\") {\n return new QuotaExceededError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ThrottlingException\" || shape.httpStatusCode === 429) {\n return new ProviderRateLimitError(message, { cause: thrown, context });\n }\n\n // Converse `ServiceUnavailableException` (503): the service is\n // temporarily unable to serve the request — retry later.\n // https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html\n if (shape.name === \"ServiceUnavailableException\" || shape.httpStatusCode === 503) {\n return new ProviderOverloadedError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ValidationException\") {\n if (/too long|context window|maximum context|exceeds the maximum/i.test(message)) {\n return new ContextLengthExceededError(message, { cause: thrown, context });\n }\n\n return new InvalidRequestError(message, { cause: thrown, context });\n }\n\n if (\n shape.name === \"ResourceNotFoundException\" ||\n shape.name === \"ConflictException\" ||\n isClientStatus(shape.httpStatusCode)\n ) {\n return new InvalidRequestError(message, { cause: thrown, context });\n }\n\n return new ProviderError(message, { cause: thrown, context });\n}\n\n/**\n * Read the raw error shape without depending on `instanceof`. AWS\n * exceptions expose `$metadata`; plain/proxied errors may carry\n * `status` / `code` instead.\n */\nfunction toShape(thrown: unknown): BedrockErrorShape {\n if (typeof thrown !== \"object\" || thrown === null) {\n return {};\n }\n\n const raw = thrown as Record<string, unknown>;\n const metadata = raw.$metadata as { httpStatusCode?: number; requestId?: string } | undefined;\n\n return {\n name: typeof raw.name === \"string\" ? raw.name : undefined,\n message: typeof raw.message === \"string\" ? raw.message : undefined,\n httpStatusCode:\n metadata && typeof metadata.httpStatusCode === \"number\"\n ? metadata.httpStatusCode\n : typeof raw.status === \"number\"\n ? (raw.status as number)\n : undefined,\n requestId: metadata && typeof metadata.requestId === \"string\" ? metadata.requestId : undefined,\n code: typeof raw.code === \"string\" ? raw.code : undefined,\n };\n}\n\n/**\n * Decide whether the error is a timeout. Bedrock surfaces\n * `ModelTimeoutException`; the AWS transport layer surfaces\n * `TimeoutError` / `ETIMEDOUT` / `ECONNABORTED`.\n */\nfunction isTimeout(shape: BedrockErrorShape): boolean {\n if (shape.name && TIMEOUT_NAMES.has(shape.name)) {\n return true;\n }\n\n return shape.code === \"ETIMEDOUT\" || shape.code === \"ECONNABORTED\";\n}\n\n/** True for HTTP 4xx — a client-side request problem, not a server fault. */\nfunction isClientStatus(status: number | undefined): boolean {\n return typeof status === \"number\" && status >= 400 && status < 500;\n}\n\n/**\n * Attach the raw diagnostic fields to `error.context`. The Smithy\n * exception `name` is the closest thing Bedrock has to a stable error\n * code, so it lands on `context.code`.\n */\nfunction buildContext(shape: BedrockErrorShape): Record<string, unknown> {\n const context: Record<string, unknown> = {};\n\n if (shape.httpStatusCode !== undefined) {\n context.status = shape.httpStatusCode;\n }\n\n if (shape.name) {\n context.code = shape.name;\n }\n\n if (shape.requestId) {\n context.requestId = shape.requestId;\n }\n\n return context;\n}\n","import {\n type EmbeddingBatchResult,\n type EmbeddingResult,\n type EmbeddingUsage,\n type EmbedderContract,\n} from \"@warlock.js/ai\";\nimport { log, type Logger } from \"@warlock.js/logger\";\nimport { InvokeModelCommand, type BedrockRuntimeClient } from \"@aws-sdk/client-bedrock-runtime\";\nimport type { BedrockEmbedderConfig } from \"./config.type\";\nimport { wrapBedrockError } from \"./utils\";\n\nconst LOG_MODULE = \"ai.bedrock\";\n\n/** Shape of the Amazon Titan Text Embeddings response body. */\ntype TitanEmbeddingResponse = {\n embedding: number[];\n inputTextTokenCount: number;\n};\n\n/**\n * Bedrock-backed implementation of `EmbedderContract`, targeting the\n * Amazon Titan Text Embeddings family\n * (`amazon.titan-embed-text-v2:0` / v1) via `InvokeModel`.\n *\n * **Role.** Converts text into floating-point vectors. Standalone\n * primitive — unrelated to Converse / tools / the agent loop.\n *\n * **Single-input only upstream.** Titan's `InvokeModel` body accepts\n * one `inputText` per call — there is no batch endpoint. `embedMany`\n * therefore issues one request per input sequentially and aggregates\n * token usage. This is a deliberate, documented trade-off: a real\n * batch API does not exist for Titan on Bedrock, so the alternative\n * (failing `embedMany`) would be worse. Cohere embeddings on Bedrock\n * *do* batch but use an incompatible body shape — out of scope; use\n * the OpenAI adapter or a future Cohere adapter when batch throughput\n * matters.\n *\n * **Dimensions.** When no `dimensions` override is given,\n * `this.dimensions` starts at `0` and is populated from the first\n * response's vector length, then cached. Passing `dimensions` forwards\n * Titan v2's truncation hint (256 / 512 / 1024) and sets the initial\n * value immediately.\n *\n * @example\n * const embedder = new BedrockEmbedder(client, { name: \"amazon.titan-embed-text-v2:0\" });\n * const { vector } = await embedder.embed(\"Hello world\");\n * const { vectors } = await embedder.embedMany([\"doc 1\", \"doc 2\"]);\n */\nexport class BedrockEmbedder implements EmbedderContract {\n public readonly name: string;\n public readonly provider: string;\n public dimensions: number;\n\n private readonly client: BedrockRuntimeClient;\n private readonly configuredDimensions: number | undefined;\n private readonly logger: Logger = log;\n\n public constructor(\n client: BedrockRuntimeClient,\n config: BedrockEmbedderConfig,\n provider: string = \"bedrock\",\n ) {\n this.client = client;\n this.name = config.name;\n this.provider = provider;\n this.configuredDimensions = config.dimensions;\n this.dimensions = config.dimensions ?? 0;\n }\n\n public async embed(input: string): Promise<EmbeddingResult> {\n const { vector, tokens } = await this.invoke(input);\n\n return {\n vector,\n dimensions: this.dimensions,\n usage: { promptTokens: tokens, totalTokens: tokens },\n };\n }\n\n public async embedMany(inputs: string[]): Promise<EmbeddingBatchResult> {\n const vectors: number[][] = [];\n let tokens = 0;\n\n for (const input of inputs) {\n const result = await this.invoke(input);\n\n vectors.push(result.vector);\n tokens += result.tokens;\n }\n\n const usage: EmbeddingUsage = { promptTokens: tokens, totalTokens: tokens };\n\n return { vectors, dimensions: this.dimensions, usage };\n }\n\n /**\n * Issue a single Titan `InvokeModel` embedding request: encode the\n * JSON body, send, wrap provider errors, decode the response, and\n * cache `dimensions` on the first successful call.\n */\n private async invoke(input: string): Promise<{ vector: number[]; tokens: number }> {\n this.logger.debug(LOG_MODULE, \"embedder.request\", \"InvokeModel embeddings\", {\n model: this.name,\n });\n\n const body = JSON.stringify({\n inputText: input,\n ...(this.configuredDimensions !== undefined ? { dimensions: this.configuredDimensions } : {}),\n });\n\n let raw;\n\n try {\n raw = await this.client.send(\n new InvokeModelCommand({\n modelId: this.name,\n contentType: \"application/json\",\n accept: \"application/json\",\n body: new TextEncoder().encode(body),\n }),\n );\n } catch (thrown) {\n const wrapped = wrapBedrockError(thrown);\n\n this.logger.error(LOG_MODULE, \"embedder.error\", wrapped.message, {\n code: wrapped.code,\n context: wrapped.context,\n });\n\n throw wrapped;\n }\n\n const decoded = JSON.parse(new TextDecoder().decode(raw.body)) as TitanEmbeddingResponse;\n\n if (this.dimensions === 0) {\n this.dimensions = decoded.embedding.length;\n }\n\n this.logger.debug(LOG_MODULE, \"embedder.response\", \"InvokeModel embeddings returned\", {\n dimensions: decoded.embedding.length,\n tokens: decoded.inputTextTokenCount,\n });\n\n return { vector: decoded.embedding, tokens: decoded.inputTextTokenCount };\n }\n}\n","import { InvalidRequestError, type ModelCallOptions } from \"@warlock.js/ai\";\n\n/** Adapter-only fields merged after the neutral request parameters. */\nexport type BedrockCallOptions = { body?: Record<string, unknown> };\n\nconst RESERVED_FIELDS = new Set([\"modelId\", \"messages\", \"system\", \"toolConfig\"]);\n\nexport function mergeProviderBody<T extends object>(\n built: T,\n options: ModelCallOptions | undefined,\n): T {\n const provider = options?.providerOptions?.bedrock as BedrockCallOptions | undefined;\n const body = provider?.body ?? {};\n const reserved = Object.keys(body).filter((key) => RESERVED_FIELDS.has(key));\n if (reserved.length > 0) {\n throw new InvalidRequestError(\n `providerOptions.bedrock.body cannot set ${reserved.join(\", \")}: use the call's messages, tools and model options.`,\n { context: { fields: reserved } },\n );\n }\n const defaults = built as Record<string, unknown>;\n const overrides = Object.fromEntries(\n Object.entries(body).map(([key, value]) => {\n const previous = defaults[key];\n return [\n key,\n isPlainObject(previous) && isPlainObject(value) ? { ...previous, ...value } : value,\n ];\n }),\n );\n return { ...built, ...overrides };\n}\n\n/** Merge only plain objects; arrays, null and provider scalar values replace the field. */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== \"object\") return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n","/**\n * Cost-truth capability inference for Bedrock Converse model ids.\n *\n * Bedrock model ids are provider-prefixed and version-suffixed\n * (`anthropic.claude-3-7-sonnet-20250219-v1:0`, `us.amazon.nova-pro-v1:0`),\n * so — exactly like `known-vision-models.ts` — a lowercase substring scan\n * is the only robust check across cross-region inference-profile prefixes\n * (`us.`, `eu.`, `apac.`) and date/version tags.\n *\n * Each predicate answers a single `ModelCapabilities` flag the agent reads\n * to decide whether to forward a cost-truth option (`reasoning`,\n * `cacheControl`) or up-front-reject an attachment (`pdf`). Unknown ids\n * default to `false` so an unsupported request fails fast with a clear\n * capability error instead of an opaque Bedrock `ValidationException`.\n * Every inference is overridable per-model via `bedrock.model({ name, … })`.\n */\n\n/**\n * Families that expose Anthropic-style extended thinking on Bedrock\n * Converse via `additionalModelRequestFields.thinking`. Only Claude 3.7\n * and the Claude 4 line (Sonnet / Opus / Haiku) support a configurable\n * thinking budget; earlier Claude, Nova, Llama, Mistral and Cohere do\n * not, so they are intentionally absent.\n */\nconst REASONING_CAPABLE_SUBSTRINGS = [\n \"claude-3-7\",\n \"claude-sonnet-4\",\n \"claude-opus-4\",\n \"claude-haiku-4\",\n];\n\n/**\n * Families that honor Converse `cachePoint` prompt-cache breakpoints.\n * Anthropic Claude 3.5+ / 3.7 / 4 / 5 and the Amazon Nova line support\n * cache points; text-only legacy families do not. Per the \"Supported\n * models\" table of https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html\n * (checked 2026-10-17).\n */\nconst PROMPT_CACHING_CAPABLE_SUBSTRINGS = [\n \"claude-3-5\",\n \"claude-3-7\",\n \"claude-sonnet-4\",\n \"claude-opus-4\",\n \"claude-haiku-4\",\n \"claude-sonnet-5\",\n \"claude-opus-5\",\n \"claude-haiku-5\",\n \"claude-fable-5\",\n \"claude-mythos-5\",\n \"nova-2-lite\",\n \"nova-lite\",\n \"nova-pro\",\n \"nova-premier\",\n \"nova-micro\",\n];\n\n/**\n * Families that accept Converse `document` content blocks (PDF / docx /\n * txt input). The multimodal Claude 3+ and Nova families support\n * document blocks; the substring set mirrors the vision-capable list\n * minus the image-only Llama entries (Llama on Bedrock takes images but\n * not document blocks via Converse).\n */\nconst PDF_CAPABLE_SUBSTRINGS = [\n \"claude-3\",\n \"claude-sonnet-4\",\n \"claude-opus-4\",\n \"claude-haiku-4\",\n \"nova-lite\",\n \"nova-pro\",\n \"nova-premier\",\n];\n\nfunction matchesAny(modelId: string, fragments: string[]): boolean {\n const normalized = modelId.toLowerCase();\n\n return fragments.some((fragment) => normalized.includes(fragment));\n}\n\n/**\n * Infer whether a Bedrock model id exposes extended-thinking / reasoning\n * (Claude 3.7 + Claude 4). When true the adapter forwards\n * `ModelCallOptions.reasoning` as Converse\n * `additionalModelRequestFields.thinking`.\n *\n * @example\n * inferReasoningCapability(\"anthropic.claude-3-7-sonnet-20250219-v1:0\"); // → true\n * inferReasoningCapability(\"us.amazon.nova-pro-v1:0\"); // → false\n */\nexport function inferReasoningCapability(modelId: string): boolean {\n return matchesAny(modelId, REASONING_CAPABLE_SUBSTRINGS);\n}\n\n/**\n * Infer whether a Bedrock model id honors Converse `cachePoint`\n * breakpoints (Claude 3.5+ / Nova). When true the adapter both maps\n * `ModelCallOptions.cacheControl` write breakpoints to cache points and\n * reports `Usage.cachedTokens` / `Usage.cacheWriteTokens`.\n *\n * @example\n * inferPromptCachingCapability(\"us.amazon.nova-pro-v1:0\"); // → true\n * inferPromptCachingCapability(\"meta.llama3-1-8b-instruct-v1:0\"); // → false\n */\nexport function inferPromptCachingCapability(modelId: string): boolean {\n return matchesAny(modelId, PROMPT_CACHING_CAPABLE_SUBSTRINGS);\n}\n\n/**\n * Infer whether a Bedrock model id accepts Converse `document` content\n * blocks (PDF / document input — Claude 3+ / Nova). When false the agent\n * rejects a PDF attachment up front instead of dropping it at the wire.\n *\n * @example\n * inferPdfCapability(\"anthropic.claude-3-5-sonnet-20240620-v1:0\"); // → true\n * inferPdfCapability(\"meta.llama3-2-90b-instruct-v1:0\"); // → false\n */\nexport function inferPdfCapability(modelId: string): boolean {\n return matchesAny(modelId, PDF_CAPABLE_SUBSTRINGS);\n}\n\n/**\n * Claude on Bedrock accepts a `cachePoint` in `system`, `messages` and\n * `tools`; Amazon Nova accepts one only in `system` and `messages`\n * (https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html,\n * \"Fields that accept prompt cache checkpoints\", checked 2026-10-17).\n * Unknown families get no tool cache point.\n *\n * @example\n * supportsToolCachePoint(\"global.anthropic.claude-sonnet-4-6\"); // true\n * supportsToolCachePoint(\"amazon.nova-pro-v1:0\"); // false\n */\nexport function supportsToolCachePoint(modelId: string): boolean {\n return modelId.toLowerCase().includes(\"anthropic.claude\");\n}\n\n/** Claude families whose cache points accept the 1-hour TTL. */\nconst ONE_HOUR_TTL_PATTERN =\n /anthropic\\.claude-(?:(?:opus|sonnet|haiku|fable|mythos)-5|opus-4-[5-9]|sonnet-4-[5-9]|haiku-4-5)/;\n\n/**\n * Claude models whose Converse `cachePoint` accepts `ttl: \"1h\"`: Claude\n * Haiku 4.5, the 4.5+ Sonnet / Opus line and every Claude 5 family. Any\n * other model gets no `ttl` field (the 5-minute default), since AWS\n * warns that sending it to a 5-minute-only model \"can result in a\n * ValidationException\" (same page, checked 2026-10-17).\n *\n * @example\n * supportsOneHourCacheTtl(\"anthropic.claude-haiku-4-5-20251001-v1:0\"); // true\n * supportsOneHourCacheTtl(\"anthropic.claude-3-7-sonnet-20250219-v1:0\"); // false\n */\nexport function supportsOneHourCacheTtl(modelId: string): boolean {\n return ONE_HOUR_TTL_PATTERN.test(modelId.toLowerCase());\n}\n","import type { ModelPricing } from \"@warlock.js/ai\";\n\n/**\n * Bedrock on-demand list prices for Anthropic Claude, USD per 1,000,000\n * tokens, keyed by Bedrock model id (without an inference-profile\n * prefix). `cacheWrite` is the 5-minute write rate, `cacheWrite1h` the\n * 1-hour write rate, `cachedInput` the cache-read rate.\n *\n * Source: https://aws.amazon.com/bedrock/pricing/ — the page's own price\n * feed for \"US East (N. Virginia)\", fetched 2026-10-17 (Sonnet 5.5 cache\n * reads already at the rate effective 2026-10-07). Model ids from\n * https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html.\n *\n * Two tables, because AWS prices them differently:\n * - {@link BEDROCK_GLOBAL_PRICING} — `global.` cross-Region inference\n * profiles.\n * - {@link BEDROCK_US_PRICING} — `us.` geographic profiles (the\n * \"Geo / In-region\" rates, 10% above global for these models).\n *\n * In-Region ids without a profile prefix, other geographies (`eu.`,\n * `apac.`, …), Claude Haiku 5.5 and non-Claude models stay unpriced —\n * their rates vary by Region or were not verified — so pass `pricing`\n * yourself for them.\n */\nexport const BEDROCK_GLOBAL_PRICING: Readonly<Record<string, ModelPricing>> = {\n \"anthropic.claude-sonnet-5-5\": claude(2, 10, 0.1),\n \"anthropic.claude-opus-5-5\": claude(4, 20, 0.2),\n \"anthropic.claude-fable-5-1\": claude(10, 50, 0.25),\n \"anthropic.claude-opus-5\": claude(5, 25, 0.5),\n \"anthropic.claude-sonnet-5\": claude(2, 10, 0.2),\n \"anthropic.claude-fable-5\": claude(10, 50, 1),\n \"anthropic.claude-opus-4-8\": claude(5, 25, 0.5),\n \"anthropic.claude-opus-4-7\": claude(5, 25, 0.5),\n \"anthropic.claude-opus-4-6-v1\": claude(5, 25, 0.5),\n \"anthropic.claude-sonnet-4-6\": claude(3, 15, 0.3),\n \"anthropic.claude-opus-4-5-20251101-v1:0\": claude(5, 25, 0.5),\n \"anthropic.claude-sonnet-4-5-20250929-v1:0\": claude(3, 15, 0.3),\n \"anthropic.claude-haiku-4-5-20251001-v1:0\": claude(1, 5, 0.1),\n};\n\n/** `us.` geographic-profile prices — see {@link BEDROCK_GLOBAL_PRICING}. */\nexport const BEDROCK_US_PRICING: Readonly<Record<string, ModelPricing>> = {\n \"anthropic.claude-sonnet-5-5\": claude(2.2, 11, 0.11),\n \"anthropic.claude-opus-5-5\": claude(4.4, 22, 0.22),\n \"anthropic.claude-fable-5-1\": claude(11, 55, 0.275),\n \"anthropic.claude-opus-5\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-sonnet-5\": claude(2.2, 11, 0.22),\n \"anthropic.claude-fable-5\": claude(11, 55, 1.1),\n \"anthropic.claude-opus-4-8\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-opus-4-7\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-opus-4-6-v1\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-sonnet-4-6\": claude(3.3, 16.5, 0.33),\n \"anthropic.claude-opus-4-5-20251101-v1:0\": claude(5.5, 27.5, 0.55),\n \"anthropic.claude-sonnet-4-5-20250929-v1:0\": claude(3.3, 16.5, 0.33),\n \"anthropic.claude-haiku-4-5-20251001-v1:0\": claude(1.1, 5.5, 0.11),\n};\n\n/**\n * Look up the built-in price for a Bedrock model id or inference-profile\n * id: `global.<model>` reads {@link BEDROCK_GLOBAL_PRICING}, `us.<model>`\n * reads {@link BEDROCK_US_PRICING}; anything else is `undefined`.\n *\n * @example\n * bedrockPricingFor(\"global.anthropic.claude-sonnet-4-6\"); // { input: 3, output: 15, … }\n * bedrockPricingFor(\"anthropic.claude-sonnet-4-6\"); // undefined — in-Region rates vary\n */\nexport function bedrockPricingFor(modelId: string): ModelPricing | undefined {\n if (modelId.startsWith(\"global.\")) {\n return BEDROCK_GLOBAL_PRICING[modelId.slice(\"global.\".length)];\n }\n\n if (modelId.startsWith(\"us.\")) {\n return BEDROCK_US_PRICING[modelId.slice(\"us.\".length)];\n }\n\n return undefined;\n}\n\n/**\n * Fill the Claude cache-write rates (5-minute 1.25x, 1-hour 2x the input\n * rate — the ratio of every Claude row in the tables above) into a\n * caller-supplied entry for a Claude model that omits them. Non-Claude\n * models are returned unchanged.\n */\nexport function withClaudeCacheWriteRates(\n modelId: string,\n pricing: ModelPricing | undefined,\n): ModelPricing | undefined {\n if (!pricing || !modelId.toLowerCase().includes(\"anthropic.claude\")) {\n return pricing;\n }\n\n if (pricing.cacheWrite !== undefined && pricing.cacheWrite1h !== undefined) {\n return pricing;\n }\n\n return {\n ...pricing,\n cacheWrite: pricing.cacheWrite ?? pricing.cachedOutput ?? round(pricing.input * 1.25),\n cacheWrite1h: pricing.cacheWrite1h ?? round(pricing.input * 2),\n };\n}\n\nfunction claude(input: number, output: number, cachedInput: number): ModelPricing {\n return {\n input,\n output,\n cachedInput,\n cacheWrite: round(input * 1.25),\n cacheWrite1h: round(input * 2),\n };\n}\n\n/** Trim binary floating-point noise (2.2 * 1.25 = 2.7500000000000004). */\nfunction round(value: number): number {\n return Math.round(value * 1e9) / 1e9;\n}\n","/**\n * Substrings that identify Bedrock model ids whose family accepts image\n * input on the Converse API.\n *\n * Bedrock model ids are provider-prefixed and version-suffixed\n * (`anthropic.claude-3-5-sonnet-20240620-v1:0`, `us.amazon.nova-pro-v1:0`,\n * `meta.llama3-2-90b-instruct-v1:0`), so a substring match is the only\n * robust check across the cross-region inference-profile prefixes\n * (`us.`, `eu.`, `apac.`) and date/version tags.\n *\n * Multimodal families covered: Anthropic Claude 3 / 3.5 / 3.7 / 4,\n * Amazon Nova Lite/Pro/Premier, Meta Llama 3.2 (11B/90B) and Llama 4.\n * Text-only families (Llama 3/3.1, Titan Text, Mistral 7B, Cohere\n * Command) are intentionally absent. Override per-model via\n * `bedrock.model({ name, vision: true | false })`.\n */\nconst VISION_CAPABLE_SUBSTRINGS = [\n \"claude-3\",\n \"claude-sonnet-4\",\n \"claude-opus-4\",\n \"claude-haiku-4\",\n \"nova-lite\",\n \"nova-pro\",\n \"nova-premier\",\n \"llama3-2-11b\",\n \"llama3-2-90b\",\n \"llama4\",\n];\n\n/**\n * Infer whether a Bedrock model id supports vision based on the known\n * multimodal-family substrings. Unknown ids default to `false` so that\n * passing an image attachment to an unsupported model surfaces a clear,\n * agent-side capability error instead of an opaque Bedrock validation\n * fault.\n *\n * @example\n * inferVisionCapability(\"anthropic.claude-3-5-sonnet-20240620-v1:0\"); // → true\n * inferVisionCapability(\"us.amazon.nova-pro-v1:0\"); // → true\n * inferVisionCapability(\"meta.llama3-1-8b-instruct-v1:0\"); // → false\n * inferVisionCapability(\"amazon.titan-text-express-v1\"); // → false\n */\nexport function inferVisionCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return VISION_CAPABLE_SUBSTRINGS.some((fragment) => normalized.includes(fragment));\n}\n","import {\n attachCost,\n InvalidRequestError,\n resolveStreamChunks,\n safeJsonParse,\n selectProviderTools,\n type Message,\n type ModelCallOptions,\n type ModelCapabilities,\n type ModelContract,\n type ModelPricing,\n type ModelResponse,\n type ModelStreamChunk,\n type ModelToolCallRequest,\n type Usage,\n} from \"@warlock.js/ai\";\nimport { log, type Logger } from \"@warlock.js/logger\";\nimport {\n CountTokensCommand,\n ConverseCommand,\n ConverseStreamCommand,\n type Tool,\n type BedrockRuntimeClient,\n type ContentBlock,\n type ConverseRequest,\n type TokenUsage,\n} from \"@aws-sdk/client-bedrock-runtime\";\nimport { mergeProviderBody } from \"./provider-options\";\nimport type { BedrockModelConfig } from \"./config.type\";\nimport {\n inferPdfCapability,\n inferPromptCachingCapability,\n inferReasoningCapability,\n supportsOneHourCacheTtl,\n supportsToolCachePoint,\n} from \"./known-capabilities\";\nimport { bedrockPricingFor, withClaudeCacheWriteRates } from \"./known-pricing\";\nimport { inferVisionCapability } from \"./known-vision-models\";\nimport { toReasoningMetadata, type BedrockReasoningBlock } from \"./utils/reasoning-blocks\";\nimport { mapStopReason, toBedrockMessages, toBedrockToolConfig, wrapBedrockError } from \"./utils\";\n\n/** A Converse cache point as this adapter emits it. */\ntype BedrockCachePoint = { type: \"default\"; ttl?: \"1h\" };\n\nconst LOG_MODULE = \"ai.bedrock\";\n\n/** `provider` value of `ai.providerTool()` entries this adapter sends verbatim. */\nconst BEDROCK_WIRE_FORMAT = \"bedrock\";\n\n/** Converse `ToolUseBlock.type` of a tool use run by Bedrock itself (SDK `ToolUseType`). */\nconst SERVER_TOOL_USE = \"server_tool_use\";\n\n/** Default output allowance added to a thinking budget when maxTokens is unset. */\nconst DEFAULT_MAX_TOKENS = 4096;\nconst MIN_THINKING_BUDGET = 1024;\n\n/**\n * Conventional extended-thinking token budgets for the neutral\n * `reasoning.effort` levels, used when the caller asks for an effort\n * tier without naming an explicit `reasoning.maxTokens` budget. Mirrors\n * the low / medium / high spread other reasoning adapters expose so the\n * vendor-neutral option behaves consistently across providers.\n */\nconst EFFORT_THINKING_BUDGET: Record<string, number | undefined> = {\n minimal: 1024,\n low: 1024,\n medium: 4096,\n high: 16384,\n xhigh: 24000,\n max: 32000,\n};\n\n/**\n * Bedrock-backed implementation of `ModelContract`.\n *\n * **Role.** The provider-facing bridge between the vendor-neutral\n * `@warlock.js/ai` agent runtime and AWS Bedrock's Converse /\n * ConverseStream API. Converse is the model-agnostic surface — one\n * wire mapping covers every Bedrock-hosted family (Anthropic Claude,\n * Amazon Nova, Meta Llama, Mistral, Cohere) instead of per-family\n * `InvokeModel` body shapes.\n *\n * **Responsibility.**\n * - Owns: a long-lived `BedrockRuntimeClient` + frozen `ModelConfig`\n * (modelId, temperature, maxTokens) used as per-call defaults.\n * - Owns: translating vendor-neutral `Message[]` / `ToolConfig[]` into\n * Converse shapes (system hoisting, `toolUse` / `toolResult` blocks,\n * image bytes) on the way out, and Converse's content-block response\n * (text, tool calls, stop reason, token usage) back into the neutral\n * shapes on the way in.\n * - Does NOT own: dispatching tools, looping, history, retries — those\n * are agent concerns. The model is a per-call protocol adapter.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across calls\"): the AWS client is heavy to construct and reused for\n * the SDK's lifetime.\n *\n * @example\n * import { BedrockRuntimeClient } from \"@aws-sdk/client-bedrock-runtime\";\n * const client = new BedrockRuntimeClient({ region: \"us-east-1\" });\n * const model = new BedrockModel(client, {\n * name: \"anthropic.claude-sonnet-4-5-20250929-v1:0\",\n * });\n *\n * const myAgent = agent({ model, tools: [searchTool] });\n * const result = await myAgent.execute(\"Summarize today's news.\");\n */\nexport class BedrockModel implements ModelContract {\n public readonly name: string;\n public readonly provider: string;\n public readonly capabilities: ModelCapabilities;\n public readonly pricing?: ModelPricing;\n\n private readonly client: BedrockRuntimeClient;\n private readonly config: BedrockModelConfig;\n private readonly logger: Logger = log;\n\n public constructor(\n client: BedrockRuntimeClient,\n config: BedrockModelConfig,\n provider: string = \"bedrock\",\n ) {\n this.client = client;\n this.config = config;\n this.name = config.name;\n this.provider = provider;\n // Explicit pricing wins over the built-in `global.` / `us.` profile\n // prices; Claude entries get the 1.25x / 2x cache-write rates filled.\n this.pricing = withClaudeCacheWriteRates(\n config.name,\n config.pricing ?? bedrockPricingFor(config.name),\n );\n this.capabilities = {\n structuredOutput: config.structuredOutput ?? true,\n vision: config.vision ?? inferVisionCapability(config.name),\n reasoning: config.reasoning ?? inferReasoningCapability(config.name),\n promptCaching: config.promptCaching ?? inferPromptCachingCapability(config.name),\n pdf: config.pdf ?? inferPdfCapability(config.name),\n audio: config.audio ?? false,\n };\n }\n\n /**\n * Single-shot completion via the Converse API. Sends the full\n * message list, waits for the terminal response, and reshapes it\n * into a vendor-neutral `ModelResponse`. Per-call `options` override\n * the instance defaults for this call only.\n */\n public async complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse> {\n this.logger.debug(LOG_MODULE, \"request\", \"Starting Converse call\", {\n model: this.name,\n messageCount: messages.length,\n streaming: false,\n toolCount: options?.tools?.length ?? 0,\n });\n\n let response;\n\n try {\n response = await this.client.send(\n new ConverseCommand(this.buildRequest(messages, options)),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n const blocks = response.output?.message?.content ?? [];\n const finishReason = mapStopReason(response.stopReason);\n const usage = attachCost(this.extractUsage(response.usage), this.pricing);\n const toolCalls = this.extractToolCalls(blocks);\n\n this.logger.debug(LOG_MODULE, \"response\", \"Converse call succeeded\", { finishReason, usage });\n\n return {\n content: this.extractText(blocks),\n finishReason,\n usage,\n toolCalls,\n };\n }\n\n /** Count native input tokens from the same Converse conversation and tool configuration. */\n public async countTokens(messages: Message[], options?: ModelCallOptions): Promise<number> {\n const request = this.buildRequest(messages, options);\n try {\n const response = await this.client.send(\n new CountTokensCommand({\n modelId: request.modelId,\n input: {\n converse: {\n messages: request.messages,\n system: request.system,\n toolConfig: request.toolConfig,\n additionalModelRequestFields: request.additionalModelRequestFields,\n },\n },\n }),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n if (response.inputTokens === undefined)\n throw new InvalidRequestError(\"Bedrock countTokens returned no inputTokens.\");\n return response.inputTokens;\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n }\n\n /**\n * Incremental streaming completion via ConverseStream. Yields neutral\n * `ModelStreamChunk`s — `delta` for text, `tool-call` once a\n * `toolUse` block's accumulated input JSON is complete, and a\n * terminal `done` with the final finish reason + usage totals.\n *\n * With `options.streamChunks` it also yields `reasoning` for each\n * `reasoningContent.text` delta and `tool-args` for each client\n * `toolUse.input` delta. Usage arrives once, in the final `metadata`\n * event, so no `usage` chunk is emitted. A system tool's\n * `server_tool_use` block never becomes a `tool-call`.\n */\n public async *stream(\n messages: Message[],\n options?: ModelCallOptions,\n ): AsyncIterable<ModelStreamChunk> {\n this.logger.debug(LOG_MODULE, \"request\", \"Starting ConverseStream call\", {\n model: this.name,\n messageCount: messages.length,\n streaming: true,\n toolCount: options?.tools?.length ?? 0,\n });\n\n let response;\n\n try {\n response = await this.client.send(\n new ConverseStreamCommand(this.buildRequest(messages, options)),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n let rawStopReason: string | undefined;\n let usage: Usage = { input: 0, output: 0, total: 0 };\n const want = resolveStreamChunks(options);\n const toolBlocks = new Map<number, { id: string; name: string; json: string }>();\n const reasoningBlocks = new Map<\n number,\n { text?: string; signature?: string; redactedContent?: Uint8Array }\n >();\n const completedReasoningBlocks: BedrockReasoningBlock[] = [];\n\n try {\n for await (const event of response.stream ?? []) {\n if (event.contentBlockStart?.start?.toolUse) {\n const start = event.contentBlockStart.start.toolUse;\n\n // A system tool's `server_tool_use` runs on Bedrock's side.\n if (start.type === SERVER_TOOL_USE) {\n continue;\n }\n\n toolBlocks.set(event.contentBlockStart.contentBlockIndex ?? 0, {\n id: start.toolUseId ?? \"\",\n name: start.name ?? \"\",\n json: \"\",\n });\n\n continue;\n }\n\n if (event.contentBlockDelta?.delta) {\n const delta = event.contentBlockDelta.delta;\n\n if (delta.text) {\n yield { type: \"delta\", content: delta.text };\n } else if (delta.toolUse) {\n const accumulator = toolBlocks.get(event.contentBlockDelta.contentBlockIndex ?? 0);\n\n if (accumulator) {\n accumulator.json += delta.toolUse.input ?? \"\";\n\n if (want.toolArgs && delta.toolUse.input) {\n yield {\n type: \"tool-args\",\n callId: accumulator.id,\n name: accumulator.name,\n delta: delta.toolUse.input,\n };\n }\n }\n } else if (delta.reasoningContent) {\n const index = event.contentBlockDelta.contentBlockIndex ?? 0;\n const accumulator = reasoningBlocks.get(index) ?? {};\n\n if (delta.reasoningContent.text !== undefined) {\n accumulator.text = (accumulator.text ?? \"\") + delta.reasoningContent.text;\n\n if (want.reasoning && delta.reasoningContent.text !== \"\") {\n yield { type: \"reasoning\", delta: delta.reasoningContent.text };\n }\n }\n\n if (delta.reasoningContent.signature !== undefined) {\n accumulator.signature = delta.reasoningContent.signature;\n }\n\n if (delta.reasoningContent.redactedContent !== undefined) {\n accumulator.redactedContent = delta.reasoningContent.redactedContent;\n }\n\n reasoningBlocks.set(index, accumulator);\n }\n\n continue;\n }\n\n if (event.contentBlockStop) {\n const index = event.contentBlockStop.contentBlockIndex ?? 0;\n const accumulator = toolBlocks.get(index);\n\n if (accumulator) {\n yield {\n type: \"tool-call\",\n id: accumulator.id,\n name: accumulator.name,\n input: safeJsonParse<Record<string, unknown>>(accumulator.json, {}),\n ...(completedReasoningBlocks.length > 0\n ? { providerMetadata: { bedrock: { reasoningBlocks: completedReasoningBlocks } } }\n : {}),\n };\n\n toolBlocks.delete(index);\n }\n\n const reasoningAccumulator = reasoningBlocks.get(index);\n\n if (reasoningAccumulator) {\n const reasoningBlock = this.toReasoningMetadata(reasoningAccumulator);\n\n if (reasoningBlock) {\n completedReasoningBlocks.push(reasoningBlock);\n }\n reasoningBlocks.delete(index);\n }\n\n continue;\n }\n\n if (event.messageStop) {\n rawStopReason = event.messageStop.stopReason;\n }\n\n if (event.metadata?.usage) {\n usage = this.extractUsage(event.metadata.usage);\n }\n }\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n const finishReason = mapStopReason(rawStopReason);\n\n attachCost(usage, this.pricing);\n\n this.logger.debug(LOG_MODULE, \"response\", \"ConverseStream call succeeded\", {\n finishReason,\n usage,\n });\n\n yield { type: \"done\", finishReason, usage };\n }\n\n /**\n * Assemble the Converse request shared by `complete()` and\n * `stream()` (both command shapes take the same input). Hoists the\n * system prompt, maps inference params, and conditionally attaches\n * tools and native structured output.\n */\n private buildRequest(\n messages: Message[],\n options: ModelCallOptions | undefined,\n ): ConverseRequest {\n const { system, messages: bedrockMessages } = toBedrockMessages(messages);\n const thinkingBudget = this.resolveThinkingBudget(options?.reasoning);\n const configuredMaxTokens = options?.maxTokens ?? this.config.maxTokens;\n const maxTokens = this.resolveMaxTokens(configuredMaxTokens, thinkingBudget);\n const temperature = options?.temperature ?? this.config.temperature;\n const cachePoint = this.resolveCachePoint(options?.cacheControl);\n const cachedMessages = this.applyCacheBreakpoints(bedrockMessages, cachePoint);\n const cachedSystem = system && cachePoint ? [...system, { cachePoint }] : system;\n\n return mergeProviderBody<ConverseRequest>(\n {\n modelId: this.name,\n messages: cachedMessages,\n ...(cachedSystem ? { system: cachedSystem } : {}),\n inferenceConfig: {\n ...(maxTokens !== undefined ? { maxTokens } : {}),\n ...(temperature !== undefined ? { temperature } : {}),\n },\n ...this.buildToolConfig(options, cachePoint),\n ...this.buildOutputConfig(options?.responseSchema),\n ...this.buildReasoningConfig(thinkingBudget),\n },\n options,\n );\n }\n\n /**\n * Resolve the Converse `cachePoint` to place for this call, or\n * `undefined` when no cache point applies (the model is not\n * `promptCaching`-capable or no `cacheControl` breakpoint was asked\n * for). Bedrock only honors `type: \"default\"`; the neutral\n * `breakpoints` count is a presence hint.\n *\n * The lifetime is the per-call `cacheControl.ttl`, else the model's\n * `promptCacheTtl`. `ttl: \"1h\"` is sent only to models that accept it\n * ({@link supportsOneHourCacheTtl}); any other model gets the 5-minute\n * default, because AWS rejects the field there.\n */\n private resolveCachePoint(\n cacheControl: ModelCallOptions[\"cacheControl\"],\n ): BedrockCachePoint | undefined {\n const breakpoints = cacheControl?.breakpoints ?? 0;\n\n if (!this.capabilities.promptCaching || breakpoints <= 0) {\n return undefined;\n }\n\n const ttl = cacheControl?.ttl ?? this.config.promptCacheTtl;\n\n return ttl === \"1h\" && supportsOneHourCacheTtl(this.name)\n ? { type: \"default\", ttl: \"1h\" }\n : { type: \"default\" };\n }\n\n /**\n * Append the call's `cachePoint` to the LAST message. Together with the\n * `system` and `tools` cache points (see `buildRequest` /\n * `buildToolConfig`) this caches every stable segment of the prefix —\n * Bedrock processes them in `tools` → `system` → `messages` order, at\n * most three of the four checkpoints it allows — so later calls reusing\n * the prefix bill it at the cache-read rate (`Usage.cachedTokens`).\n */\n private applyCacheBreakpoints(\n messages: ConverseRequest[\"messages\"],\n cachePoint: BedrockCachePoint | undefined,\n ): ConverseRequest[\"messages\"] {\n if (!cachePoint || !messages || messages.length === 0) {\n return messages;\n }\n\n const last = messages.length - 1;\n const lastMessage = messages[last];\n\n if (!lastMessage) {\n return messages;\n }\n\n return [\n ...messages.slice(0, last),\n {\n ...lastMessage,\n content: [...(lastMessage.content ?? []), { cachePoint }],\n },\n ];\n }\n\n /**\n * Translate the neutral `reasoning` option into Claude-on-Bedrock's\n * extended-thinking control, carried in Converse's escape hatch\n * `additionalModelRequestFields.thinking`. Emitted only when the model\n * is `reasoning`-capable and a budget can be resolved — `maxTokens`\n * (explicit thinking budget) wins, otherwise `effort` maps to a\n * conventional token budget so callers can opt in without picking a\n * number. Returns an empty object (no-op) for non-reasoning models or\n * when no reasoning option was supplied, so unsupported params never\n * reach the wire.\n */\n private resolveThinkingBudget(reasoning: ModelCallOptions[\"reasoning\"]): number | undefined {\n if (!this.capabilities.reasoning || !reasoning || reasoning.effort === \"none\") {\n return undefined;\n }\n\n const budgetTokens = reasoning.maxTokens ?? EFFORT_THINKING_BUDGET[reasoning.effort ?? \"\"];\n\n if (budgetTokens !== undefined && budgetTokens < MIN_THINKING_BUDGET) {\n throw new Error(`thinking budget (${budgetTokens}) must be at least ${MIN_THINKING_BUDGET}`);\n }\n\n return budgetTokens;\n }\n\n /** Resolve Bedrock's output ceiling while reserving room for extended thinking. */\n private resolveMaxTokens(\n maxTokens: number | undefined,\n thinkingBudget: number | undefined,\n ): number | undefined {\n if (thinkingBudget === undefined) {\n return maxTokens;\n }\n\n if (maxTokens === undefined) {\n return thinkingBudget + DEFAULT_MAX_TOKENS;\n }\n\n if (maxTokens <= thinkingBudget) {\n throw new Error(\n `maxTokens (${maxTokens}) must be greater than thinking budget (${thinkingBudget})`,\n );\n }\n\n return maxTokens;\n }\n\n private buildReasoningConfig(\n budgetTokens: number | undefined,\n ): Pick<ConverseRequest, \"additionalModelRequestFields\"> {\n if (budgetTokens === undefined) {\n return {};\n }\n\n return {\n additionalModelRequestFields: {\n thinking: { type: \"enabled\", budget_tokens: budgetTokens },\n },\n };\n }\n\n /**\n * Spread-friendly tool fragment. Returns an empty object when no\n * tools were supplied (Bedrock rejects an empty `tools` array). With a\n * cache point, a trailing `{ cachePoint }` caches every tool definition\n * — Claude only, since Nova accepts no cache point in `tools`.\n */\n private buildToolConfig(\n options: ModelCallOptions | undefined,\n cachePoint: BedrockCachePoint | undefined,\n ): Pick<ConverseRequest, \"toolConfig\"> {\n const { tools, definitions } = selectProviderTools(options, {\n accepts: [BEDROCK_WIRE_FORMAT, this.provider],\n module: LOG_MODULE,\n model: this.name,\n logger: this.logger,\n });\n const toolConfig = toBedrockToolConfig(tools);\n // Provider-defined entries are whole Converse `Tool` members, e.g.\n // `{ systemTool: { name: \"nova_grounding\" } }` (Nova web grounding).\n const providerDefined = definitions as unknown as Tool[];\n\n const allTools = [...(toolConfig?.tools ?? []), ...providerDefined];\n\n if (allTools.length === 0) {\n return toolConfig ? { toolConfig } : {};\n }\n\n // The cache point goes last, so every tool definition is cached.\n const withCachePoint =\n cachePoint && supportsToolCachePoint(this.name) ? [...allTools, { cachePoint }] : allTools;\n\n return { toolConfig: { ...toolConfig, tools: withCachePoint } };\n }\n\n /**\n * Translate the neutral `responseSchema` into Converse's native\n * `outputConfig.textFormat` (JSON-schema structured output). Bedrock\n * requires the schema as a stringified JSON document and only\n * accepts an object root. Emitted only when the model is\n * `structuredOutput`-capable and the schema is an object — otherwise\n * the agent's soft system-prompt hint + client-side `validate()`\n * carry shape (same degradation philosophy as the OpenAI adapter).\n */\n private buildOutputConfig(\n responseSchema: Record<string, unknown> | undefined,\n ): Pick<ConverseRequest, \"outputConfig\"> {\n if (!responseSchema || !this.capabilities.structuredOutput) {\n return {};\n }\n\n if (responseSchema.type !== \"object\" || typeof responseSchema.properties !== \"object\") {\n return {};\n }\n\n return {\n outputConfig: {\n textFormat: {\n type: \"json_schema\",\n structure: {\n jsonSchema: { name: \"response\", schema: JSON.stringify(responseSchema) },\n },\n },\n },\n };\n }\n\n /**\n * Concatenate every `text` content block into the single neutral\n * `content` string. `toolUse` and other block types are surfaced\n * separately via `extractToolCalls`.\n */\n private extractText(blocks: ContentBlock[]): string {\n return blocks\n .map((block) => (\"text\" in block && typeof block.text === \"string\" ? block.text : \"\"))\n .join(\"\");\n }\n\n /**\n * Reshape Converse `toolUse` content blocks into the neutral\n * `ModelToolCallRequest[]`. Returns `undefined` when no tools were\n * requested so callers can branch on presence.\n */\n private extractToolCalls(blocks: ContentBlock[]): ModelToolCallRequest[] | undefined {\n const toolCalls: ModelToolCallRequest[] = [];\n const reasoningBlocks = blocks\n .map(toReasoningMetadata)\n .filter((block): block is BedrockReasoningBlock => block !== undefined);\n\n for (const block of blocks) {\n // `server_tool_use` blocks are run by Bedrock (system tools such as\n // Nova grounding); only client tool uses are dispatched.\n if (\"toolUse\" in block && block.toolUse && block.toolUse.type !== SERVER_TOOL_USE) {\n toolCalls.push({\n id: block.toolUse.toolUseId ?? \"\",\n name: block.toolUse.name ?? \"\",\n input: (block.toolUse.input ?? {}) as Record<string, unknown>,\n ...(reasoningBlocks.length > 0\n ? { providerMetadata: { bedrock: { reasoningBlocks } } }\n : {}),\n });\n }\n }\n\n return toolCalls.length > 0 ? toolCalls : undefined;\n }\n\n /** Encode accumulated stream deltas as persistence-safe reasoning metadata. */\n private toReasoningMetadata(block: {\n text?: string;\n signature?: string;\n redactedContent?: Uint8Array;\n }): BedrockReasoningBlock | undefined {\n if (block.redactedContent !== undefined) {\n return toReasoningMetadata({ reasoningContent: { redactedContent: block.redactedContent } });\n }\n\n return toReasoningMetadata({\n reasoningContent: {\n reasoningText: {\n text: block.text ?? \"\",\n ...(block.signature ? { signature: block.signature } : {}),\n },\n },\n });\n }\n\n /**\n * Normalize Converse's `TokenUsage` into the neutral `Usage` shape.\n * Bedrock supplies a pre-summed `totalTokens`; cache-read and\n * cache-write tokens are surfaced as `cachedTokens` /\n * `cacheWriteTokens` only when non-zero, and the 1-hour share of the\n * writes (`cacheDetails` entries with `ttl: \"1h\"`) as\n * `cacheWrite1hTokens`. With caching, `inputTokens` \"represents only\n * the non-cached input tokens\" (AWS prompt-caching guide), so the usage\n * is marked `inputIncludesCache: false`. Bedrock's Converse `TokenUsage`\n * carries no reasoning-token channel, so `Usage.reasoningTokens` is\n * intentionally left unset here. The installed SDK 3.1121.0 TokenUsage also\n * has no hosted-tool request counter; do not infer one from tool blocks.\n * https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_TokenUsage.html\n */\n private extractUsage(raw: TokenUsage | undefined): Usage {\n if (!raw) {\n return { input: 0, output: 0, total: 0 };\n }\n\n const input = raw.inputTokens ?? 0;\n const output = raw.outputTokens ?? 0;\n const cached = raw.cacheReadInputTokens;\n const cacheWrite = raw.cacheWriteInputTokens;\n const cacheWrite1h = (raw.cacheDetails ?? [])\n .filter((detail) => detail.ttl === \"1h\")\n .reduce((sum, detail) => sum + (detail.inputTokens ?? 0), 0);\n\n return {\n input,\n output,\n total: raw.totalTokens ?? input + output,\n inputIncludesCache: false,\n ...(cached && cached > 0 ? { cachedTokens: cached } : {}),\n ...(cacheWrite && cacheWrite > 0 ? { cacheWriteTokens: cacheWrite } : {}),\n ...(cacheWrite && cacheWrite > 0 && cacheWrite1h > 0\n ? { cacheWrite1hTokens: Math.min(cacheWrite1h, cacheWrite) }\n : {}),\n };\n }\n\n /**\n * Wrap a thrown provider error into the typed `AIError` hierarchy\n * and emit the standard error log line before it propagates. Shared\n * by every catch site so the log shape stays identical.\n */\n private logAndWrap(thrown: unknown) {\n const wrapped = wrapBedrockError(thrown);\n\n this.logger.error(LOG_MODULE, \"error\", wrapped.message, {\n code: wrapped.code,\n context: wrapped.context,\n });\n\n return wrapped;\n }\n}\n","import { BedrockRuntimeClient } from \"@aws-sdk/client-bedrock-runtime\";\nimport type {\n EmbedderContract,\n ModelContract,\n ModelPricing,\n SDKAdapterContract,\n} from \"@warlock.js/ai\";\nimport { approximateTokenCount, InvalidRequestError } from \"@warlock.js/ai\";\nimport type { BedrockEmbedderConfig, BedrockModelConfig, BedrockSDKConfig } from \"./config.type\";\nimport { BedrockEmbedder } from \"./embedder\";\nimport { BedrockModel } from \"./model\";\n\n/**\n * AWS Bedrock-backed implementation of `SDKAdapterContract`.\n *\n * **Role.** The package entry point for any Bedrock-hosted model via\n * the Converse API. A single `BedrockSDK` holds one live\n * `BedrockRuntimeClient`, shared by every `ModelContract` and\n * `EmbedderContract` it produces. Construct one SDK per AWS\n * account/region and reuse it everywhere.\n *\n * **Responsibility.**\n * - Owns: a long-lived `BedrockRuntimeClient` (region, credential\n * chain) and its lifetime. Factory for `BedrockModel` /\n * `BedrockEmbedder` instances sharing that client.\n * - Does NOT own: anything per-call — those live in `BedrockModel` /\n * `BedrockEmbedder` and the agent runtime.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across many calls\"): the AWS client is heavy to construct and\n * designed for reuse; keeping it on `this` aligns with the\n * `new BedrockRuntimeClient(...)` upstream convention.\n *\n * @example\n * const bedrock = new BedrockSDK({ region: \"us-east-1\" });\n * const model = bedrock.model({ name: \"anthropic.claude-sonnet-4-5-20250929-v1:0\" });\n * const embedder = bedrock.embedder({ name: \"amazon.titan-embed-text-v2:0\" });\n *\n * @example\n * // Amazon Bedrock API key (bearer auth) instead of the AWS credential chain\n * const bedrock = new BedrockSDK({ apiKey: process.env.BEDROCK_API_KEY!, region: \"us-east-1\" });\n */\nexport class BedrockSDK implements SDKAdapterContract {\n private readonly client: BedrockRuntimeClient;\n private readonly provider: string;\n private readonly pricing?: Record<string, ModelPricing>;\n\n public constructor(config: BedrockSDKConfig) {\n const { provider, pricing, apiKey, ...clientConfig } = config;\n\n this.client = new BedrockRuntimeClient(\n apiKey === undefined ? clientConfig : withApiKey(clientConfig, apiKey),\n );\n this.provider = provider ?? \"bedrock\";\n this.pricing = pricing;\n }\n\n /**\n * Build a `BedrockModel` bound to this SDK's client. Each call\n * returns a fresh instance; all instances share the underlying AWS\n * client so connection pools, credential refresh, and retry config\n * stay unified. The SDK's `provider` label is forwarded.\n *\n * Pricing resolution: per-model `config.pricing` wins; otherwise the\n * SDK-level registry entry keyed by `config.name`; otherwise\n * `undefined` (no cost computed).\n */\n public model(config: BedrockModelConfig): ModelContract {\n const resolvedPricing = config.pricing ?? this.pricing?.[config.name];\n const resolvedConfig: BedrockModelConfig =\n resolvedPricing === config.pricing ? config : { ...config, pricing: resolvedPricing };\n\n return new BedrockModel(this.client, resolvedConfig, this.provider);\n }\n\n /**\n * Rough token-count estimate. Uses the character-heuristic\n * (`approximateTokenCount`) from the core package — Bedrock has no\n * offline tokenizer and the per-model tokenizers differ; good enough\n * for budgeting and quota guards, not for billing.\n */\n public async count(text: string, _model?: string): Promise<number> {\n return approximateTokenCount(text);\n }\n\n /**\n * Build a `BedrockEmbedder` (Amazon Titan Text Embeddings) bound to\n * this SDK's client.\n *\n * @example\n * const embedder = bedrock.embedder({ name: \"amazon.titan-embed-text-v2:0\" });\n * const { vector } = await embedder.embed(\"Hello world\");\n */\n public embedder(config: BedrockEmbedderConfig): EmbedderContract {\n return new BedrockEmbedder(this.client, config, this.provider);\n }\n}\n\n/**\n * Configure the runtime client for an Amazon Bedrock API key.\n *\n * Bedrock API keys are bearer tokens: the request carries\n * `Authorization: Bearer <key>` instead of a SigV4 signature (AWS docs,\n * \"Use an Amazon Bedrock API key\",\n * https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys-use.html,\n * checked 2026-10-17). The installed `@aws-sdk/client-bedrock-runtime`\n * supports this natively: its auth scheme provider offers\n * `smithy.api#httpBearerAuth` beside SigV4, fed by the client's `token`\n * option, and `authSchemePreference: [\"httpBearerAuth\"]` selects it ahead\n * of SigV4, so the AWS credential chain is never consulted.\n *\n * Fails closed on an empty key, and on a key combined with `credentials`\n * or `token` — two credentials for one client leave which one signs the\n * request ambiguous.\n */\nfunction withApiKey(\n clientConfig: Omit<BedrockSDKConfig, \"provider\" | \"pricing\" | \"apiKey\">,\n apiKey: string,\n): Omit<BedrockSDKConfig, \"provider\" | \"pricing\" | \"apiKey\"> {\n if (typeof apiKey !== \"string\" || apiKey.trim() === \"\") {\n throw new InvalidRequestError(\"BedrockSDK: `apiKey` must be a non-empty string.\");\n }\n\n const conflicting = ([\"credentials\", \"token\"] as const).filter(\n (field) => clientConfig[field] !== undefined,\n );\n\n if (conflicting.length > 0) {\n throw new InvalidRequestError(\n `BedrockSDK: pass either \\`apiKey\\` or ${conflicting.map((field) => `\\`${field}\\``).join(\" / \")}, not both.`,\n { context: { fields: conflicting } },\n );\n }\n\n return {\n ...clientConfig,\n token: { token: apiKey },\n authSchemePreference: [\"httpBearerAuth\"],\n };\n}\n"],"mappings":";;;;;;AAEA,MAAM,gBAA8C;CAClD,UAAU;CACV,eAAe;CACf,YAAY;CACZ,UAAU;AACZ;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,cAAc,KAA8C;CAC1E,OAAO,cAAc,OAAO,OAAO;AACrC;;;;;AChBA,SAAgB,oBAAoB,OAAwD;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YAAY,KAAK,UAAU,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,KAAK,EAAE,cAChG,EAAE,SAAS,EAAE,QAAQ,YAAY,EAAE,CACrC;CAGF,OAAO;EACL,GAAG;EACH,OAAO,EAAE,OAAO,OAAO;EACvB,sBAAsB,CAAC,gBAAgB;CACzC;AACF"}
|
package/esm/config.type.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BedrockRuntimeClientConfig } from "@aws-sdk/client-bedrock-runtime";
|
|
2
2
|
import { EmbedderConfig, ModelConfig, ModelPricing } from "@warlock.js/ai";
|
|
3
|
-
|
|
4
3
|
//#region ../../packages/ai-bedrock/src/config.type.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Configuration for the AWS Bedrock SDK adapter.
|
|
@@ -41,7 +40,7 @@ import { EmbedderConfig, ModelConfig, ModelPricing } from "@warlock.js/ai";
|
|
|
41
40
|
* },
|
|
42
41
|
* });
|
|
43
42
|
*/
|
|
44
|
-
type BedrockSDKConfig = BedrockRuntimeClientConfig & {
|
|
43
|
+
export type BedrockSDKConfig = BedrockRuntimeClientConfig & {
|
|
45
44
|
provider?: string;
|
|
46
45
|
/**
|
|
47
46
|
* An Amazon Bedrock API key. Sent as `Authorization: Bearer <apiKey>`
|
|
@@ -70,7 +69,7 @@ type BedrockSDKConfig = BedrockRuntimeClientConfig & {
|
|
|
70
69
|
* bedrock.model({ name: "anthropic.claude-sonnet-4-5-20250929-v1:0" });
|
|
71
70
|
* bedrock.model({ name: "meta.llama3-1-8b-instruct-v1:0", vision: false });
|
|
72
71
|
*/
|
|
73
|
-
type BedrockModelConfig = ModelConfig & {
|
|
72
|
+
export type BedrockModelConfig = ModelConfig & {
|
|
74
73
|
/**
|
|
75
74
|
* Override the auto-inferred vision capability. When omitted, the
|
|
76
75
|
* adapter checks the model id against the known multimodal families
|
|
@@ -139,7 +138,6 @@ type BedrockModelConfig = ModelConfig & {
|
|
|
139
138
|
* bedrock.embedder({ name: "amazon.titan-embed-text-v2:0" });
|
|
140
139
|
* bedrock.embedder({ name: "amazon.titan-embed-text-v2:0", dimensions: 256 });
|
|
141
140
|
*/
|
|
142
|
-
type BedrockEmbedderConfig = EmbedderConfig;
|
|
141
|
+
export type BedrockEmbedderConfig = EmbedderConfig;
|
|
143
142
|
//#endregion
|
|
144
|
-
export { BedrockEmbedderConfig, BedrockModelConfig, BedrockSDKConfig };
|
|
145
143
|
//# sourceMappingURL=config.type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/config.type.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/config.type.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA0CY,mBAAmB;EAC7B;;;;;;;;;EASA;;;;;;;EAOA,UAAU,eAAe;;;;;;;;;;;;YAaf,qBAAqB;;;;;;;EAO/B;;;;;;;;;EASA;;;;;;;;EAQA;;;;;;;;EAQA;;;;;;;;;;EAUA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;;;;;;YAcU,wBAAwB"}
|
package/esm/known-pricing.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ModelPricing } from "@warlock.js/ai";
|
|
2
|
-
|
|
3
2
|
//#region ../../packages/ai-bedrock/src/known-pricing.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Bedrock on-demand list prices for Anthropic Claude, USD per 1,000,000
|
|
@@ -23,9 +22,9 @@ import { ModelPricing } from "@warlock.js/ai";
|
|
|
23
22
|
* their rates vary by Region or were not verified — so pass `pricing`
|
|
24
23
|
* yourself for them.
|
|
25
24
|
*/
|
|
26
|
-
declare const BEDROCK_GLOBAL_PRICING: Readonly<Record<string, ModelPricing>>;
|
|
25
|
+
export declare const BEDROCK_GLOBAL_PRICING: Readonly<Record<string, ModelPricing>>;
|
|
27
26
|
/** `us.` geographic-profile prices — see {@link BEDROCK_GLOBAL_PRICING}. */
|
|
28
|
-
declare const BEDROCK_US_PRICING: Readonly<Record<string, ModelPricing>>;
|
|
27
|
+
export declare const BEDROCK_US_PRICING: Readonly<Record<string, ModelPricing>>;
|
|
29
28
|
/**
|
|
30
29
|
* Look up the built-in price for a Bedrock model id or inference-profile
|
|
31
30
|
* id: `global.<model>` reads {@link BEDROCK_GLOBAL_PRICING}, `us.<model>`
|
|
@@ -35,14 +34,13 @@ declare const BEDROCK_US_PRICING: Readonly<Record<string, ModelPricing>>;
|
|
|
35
34
|
* bedrockPricingFor("global.anthropic.claude-sonnet-4-6"); // { input: 3, output: 15, … }
|
|
36
35
|
* bedrockPricingFor("anthropic.claude-sonnet-4-6"); // undefined — in-Region rates vary
|
|
37
36
|
*/
|
|
38
|
-
declare function bedrockPricingFor(modelId: string): ModelPricing | undefined;
|
|
37
|
+
export declare function bedrockPricingFor(modelId: string): ModelPricing | undefined;
|
|
39
38
|
/**
|
|
40
39
|
* Fill the Claude cache-write rates (5-minute 1.25x, 1-hour 2x the input
|
|
41
40
|
* rate — the ratio of every Claude row in the tables above) into a
|
|
42
41
|
* caller-supplied entry for a Claude model that omits them. Non-Claude
|
|
43
42
|
* models are returned unchanged.
|
|
44
43
|
*/
|
|
45
|
-
declare function withClaudeCacheWriteRates(modelId: string, pricing: ModelPricing | undefined): ModelPricing | undefined;
|
|
44
|
+
export declare function withClaudeCacheWriteRates(modelId: string, pricing: ModelPricing | undefined): ModelPricing | undefined;
|
|
46
45
|
//#endregion
|
|
47
|
-
export { BEDROCK_GLOBAL_PRICING, BEDROCK_US_PRICING, bedrockPricingFor, withClaudeCacheWriteRates };
|
|
48
46
|
//# sourceMappingURL=known-pricing.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"known-pricing.d.mts","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/known-pricing.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"known-pricing.d.mts","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/known-pricing.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;qBAwBa,wBAAwB,SAAS,eAAe;;qBAiBhD,oBAAoB,SAAS,eAAe;;;;;;;;;;wBAyBzC,kBAAkB,kBAAkB;;;;;;;wBAkBpC,0BACd,iBACA,SAAS,2BACR"}
|
package/esm/model.mjs
CHANGED
|
@@ -442,7 +442,9 @@ var BedrockModel = class {
|
|
|
442
442
|
* the non-cached input tokens" (AWS prompt-caching guide), so the usage
|
|
443
443
|
* is marked `inputIncludesCache: false`. Bedrock's Converse `TokenUsage`
|
|
444
444
|
* carries no reasoning-token channel, so `Usage.reasoningTokens` is
|
|
445
|
-
* intentionally left unset here.
|
|
445
|
+
* intentionally left unset here. The installed SDK 3.1121.0 TokenUsage also
|
|
446
|
+
* has no hosted-tool request counter; do not infer one from tool blocks.
|
|
447
|
+
* https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_TokenUsage.html
|
|
446
448
|
*/
|
|
447
449
|
extractUsage(raw) {
|
|
448
450
|
if (!raw) return {
|
package/esm/model.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.mjs","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/model.ts"],"sourcesContent":["import {\n attachCost,\n InvalidRequestError,\n resolveStreamChunks,\n safeJsonParse,\n selectProviderTools,\n type Message,\n type ModelCallOptions,\n type ModelCapabilities,\n type ModelContract,\n type ModelPricing,\n type ModelResponse,\n type ModelStreamChunk,\n type ModelToolCallRequest,\n type Usage,\n} from \"@warlock.js/ai\";\nimport { log, type Logger } from \"@warlock.js/logger\";\nimport {\n CountTokensCommand,\n ConverseCommand,\n ConverseStreamCommand,\n type Tool,\n type BedrockRuntimeClient,\n type ContentBlock,\n type ConverseRequest,\n type TokenUsage,\n} from \"@aws-sdk/client-bedrock-runtime\";\nimport { mergeProviderBody } from \"./provider-options\";\nimport type { BedrockModelConfig } from \"./config.type\";\nimport {\n inferPdfCapability,\n inferPromptCachingCapability,\n inferReasoningCapability,\n supportsOneHourCacheTtl,\n supportsToolCachePoint,\n} from \"./known-capabilities\";\nimport { bedrockPricingFor, withClaudeCacheWriteRates } from \"./known-pricing\";\nimport { inferVisionCapability } from \"./known-vision-models\";\nimport { toReasoningMetadata, type BedrockReasoningBlock } from \"./utils/reasoning-blocks\";\nimport { mapStopReason, toBedrockMessages, toBedrockToolConfig, wrapBedrockError } from \"./utils\";\n\n/** A Converse cache point as this adapter emits it. */\ntype BedrockCachePoint = { type: \"default\"; ttl?: \"1h\" };\n\nconst LOG_MODULE = \"ai.bedrock\";\n\n/** `provider` value of `ai.providerTool()` entries this adapter sends verbatim. */\nconst BEDROCK_WIRE_FORMAT = \"bedrock\";\n\n/** Converse `ToolUseBlock.type` of a tool use run by Bedrock itself (SDK `ToolUseType`). */\nconst SERVER_TOOL_USE = \"server_tool_use\";\n\n/** Default output allowance added to a thinking budget when maxTokens is unset. */\nconst DEFAULT_MAX_TOKENS = 4096;\nconst MIN_THINKING_BUDGET = 1024;\n\n/**\n * Conventional extended-thinking token budgets for the neutral\n * `reasoning.effort` levels, used when the caller asks for an effort\n * tier without naming an explicit `reasoning.maxTokens` budget. Mirrors\n * the low / medium / high spread other reasoning adapters expose so the\n * vendor-neutral option behaves consistently across providers.\n */\nconst EFFORT_THINKING_BUDGET: Record<string, number | undefined> = {\n minimal: 1024,\n low: 1024,\n medium: 4096,\n high: 16384,\n xhigh: 24000,\n max: 32000,\n};\n\n/**\n * Bedrock-backed implementation of `ModelContract`.\n *\n * **Role.** The provider-facing bridge between the vendor-neutral\n * `@warlock.js/ai` agent runtime and AWS Bedrock's Converse /\n * ConverseStream API. Converse is the model-agnostic surface — one\n * wire mapping covers every Bedrock-hosted family (Anthropic Claude,\n * Amazon Nova, Meta Llama, Mistral, Cohere) instead of per-family\n * `InvokeModel` body shapes.\n *\n * **Responsibility.**\n * - Owns: a long-lived `BedrockRuntimeClient` + frozen `ModelConfig`\n * (modelId, temperature, maxTokens) used as per-call defaults.\n * - Owns: translating vendor-neutral `Message[]` / `ToolConfig[]` into\n * Converse shapes (system hoisting, `toolUse` / `toolResult` blocks,\n * image bytes) on the way out, and Converse's content-block response\n * (text, tool calls, stop reason, token usage) back into the neutral\n * shapes on the way in.\n * - Does NOT own: dispatching tools, looping, history, retries — those\n * are agent concerns. The model is a per-call protocol adapter.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across calls\"): the AWS client is heavy to construct and reused for\n * the SDK's lifetime.\n *\n * @example\n * import { BedrockRuntimeClient } from \"@aws-sdk/client-bedrock-runtime\";\n * const client = new BedrockRuntimeClient({ region: \"us-east-1\" });\n * const model = new BedrockModel(client, {\n * name: \"anthropic.claude-sonnet-4-5-20250929-v1:0\",\n * });\n *\n * const myAgent = agent({ model, tools: [searchTool] });\n * const result = await myAgent.execute(\"Summarize today's news.\");\n */\nexport class BedrockModel implements ModelContract {\n public readonly name: string;\n public readonly provider: string;\n public readonly capabilities: ModelCapabilities;\n public readonly pricing?: ModelPricing;\n\n private readonly client: BedrockRuntimeClient;\n private readonly config: BedrockModelConfig;\n private readonly logger: Logger = log;\n\n public constructor(\n client: BedrockRuntimeClient,\n config: BedrockModelConfig,\n provider: string = \"bedrock\",\n ) {\n this.client = client;\n this.config = config;\n this.name = config.name;\n this.provider = provider;\n // Explicit pricing wins over the built-in `global.` / `us.` profile\n // prices; Claude entries get the 1.25x / 2x cache-write rates filled.\n this.pricing = withClaudeCacheWriteRates(\n config.name,\n config.pricing ?? bedrockPricingFor(config.name),\n );\n this.capabilities = {\n structuredOutput: config.structuredOutput ?? true,\n vision: config.vision ?? inferVisionCapability(config.name),\n reasoning: config.reasoning ?? inferReasoningCapability(config.name),\n promptCaching: config.promptCaching ?? inferPromptCachingCapability(config.name),\n pdf: config.pdf ?? inferPdfCapability(config.name),\n audio: config.audio ?? false,\n };\n }\n\n /**\n * Single-shot completion via the Converse API. Sends the full\n * message list, waits for the terminal response, and reshapes it\n * into a vendor-neutral `ModelResponse`. Per-call `options` override\n * the instance defaults for this call only.\n */\n public async complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse> {\n this.logger.debug(LOG_MODULE, \"request\", \"Starting Converse call\", {\n model: this.name,\n messageCount: messages.length,\n streaming: false,\n toolCount: options?.tools?.length ?? 0,\n });\n\n let response;\n\n try {\n response = await this.client.send(\n new ConverseCommand(this.buildRequest(messages, options)),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n const blocks = response.output?.message?.content ?? [];\n const finishReason = mapStopReason(response.stopReason);\n const usage = attachCost(this.extractUsage(response.usage), this.pricing);\n const toolCalls = this.extractToolCalls(blocks);\n\n this.logger.debug(LOG_MODULE, \"response\", \"Converse call succeeded\", { finishReason, usage });\n\n return {\n content: this.extractText(blocks),\n finishReason,\n usage,\n toolCalls,\n };\n }\n\n /** Count native input tokens from the same Converse conversation and tool configuration. */\n public async countTokens(messages: Message[], options?: ModelCallOptions): Promise<number> {\n const request = this.buildRequest(messages, options);\n try {\n const response = await this.client.send(\n new CountTokensCommand({\n modelId: request.modelId,\n input: {\n converse: {\n messages: request.messages,\n system: request.system,\n toolConfig: request.toolConfig,\n additionalModelRequestFields: request.additionalModelRequestFields,\n },\n },\n }),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n if (response.inputTokens === undefined)\n throw new InvalidRequestError(\"Bedrock countTokens returned no inputTokens.\");\n return response.inputTokens;\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n }\n\n /**\n * Incremental streaming completion via ConverseStream. Yields neutral\n * `ModelStreamChunk`s — `delta` for text, `tool-call` once a\n * `toolUse` block's accumulated input JSON is complete, and a\n * terminal `done` with the final finish reason + usage totals.\n *\n * With `options.streamChunks` it also yields `reasoning` for each\n * `reasoningContent.text` delta and `tool-args` for each client\n * `toolUse.input` delta. Usage arrives once, in the final `metadata`\n * event, so no `usage` chunk is emitted. A system tool's\n * `server_tool_use` block never becomes a `tool-call`.\n */\n public async *stream(\n messages: Message[],\n options?: ModelCallOptions,\n ): AsyncIterable<ModelStreamChunk> {\n this.logger.debug(LOG_MODULE, \"request\", \"Starting ConverseStream call\", {\n model: this.name,\n messageCount: messages.length,\n streaming: true,\n toolCount: options?.tools?.length ?? 0,\n });\n\n let response;\n\n try {\n response = await this.client.send(\n new ConverseStreamCommand(this.buildRequest(messages, options)),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n let rawStopReason: string | undefined;\n let usage: Usage = { input: 0, output: 0, total: 0 };\n const want = resolveStreamChunks(options);\n const toolBlocks = new Map<number, { id: string; name: string; json: string }>();\n const reasoningBlocks = new Map<\n number,\n { text?: string; signature?: string; redactedContent?: Uint8Array }\n >();\n const completedReasoningBlocks: BedrockReasoningBlock[] = [];\n\n try {\n for await (const event of response.stream ?? []) {\n if (event.contentBlockStart?.start?.toolUse) {\n const start = event.contentBlockStart.start.toolUse;\n\n // A system tool's `server_tool_use` runs on Bedrock's side.\n if (start.type === SERVER_TOOL_USE) {\n continue;\n }\n\n toolBlocks.set(event.contentBlockStart.contentBlockIndex ?? 0, {\n id: start.toolUseId ?? \"\",\n name: start.name ?? \"\",\n json: \"\",\n });\n\n continue;\n }\n\n if (event.contentBlockDelta?.delta) {\n const delta = event.contentBlockDelta.delta;\n\n if (delta.text) {\n yield { type: \"delta\", content: delta.text };\n } else if (delta.toolUse) {\n const accumulator = toolBlocks.get(event.contentBlockDelta.contentBlockIndex ?? 0);\n\n if (accumulator) {\n accumulator.json += delta.toolUse.input ?? \"\";\n\n if (want.toolArgs && delta.toolUse.input) {\n yield {\n type: \"tool-args\",\n callId: accumulator.id,\n name: accumulator.name,\n delta: delta.toolUse.input,\n };\n }\n }\n } else if (delta.reasoningContent) {\n const index = event.contentBlockDelta.contentBlockIndex ?? 0;\n const accumulator = reasoningBlocks.get(index) ?? {};\n\n if (delta.reasoningContent.text !== undefined) {\n accumulator.text = (accumulator.text ?? \"\") + delta.reasoningContent.text;\n\n if (want.reasoning && delta.reasoningContent.text !== \"\") {\n yield { type: \"reasoning\", delta: delta.reasoningContent.text };\n }\n }\n\n if (delta.reasoningContent.signature !== undefined) {\n accumulator.signature = delta.reasoningContent.signature;\n }\n\n if (delta.reasoningContent.redactedContent !== undefined) {\n accumulator.redactedContent = delta.reasoningContent.redactedContent;\n }\n\n reasoningBlocks.set(index, accumulator);\n }\n\n continue;\n }\n\n if (event.contentBlockStop) {\n const index = event.contentBlockStop.contentBlockIndex ?? 0;\n const accumulator = toolBlocks.get(index);\n\n if (accumulator) {\n yield {\n type: \"tool-call\",\n id: accumulator.id,\n name: accumulator.name,\n input: safeJsonParse<Record<string, unknown>>(accumulator.json, {}),\n ...(completedReasoningBlocks.length > 0\n ? { providerMetadata: { bedrock: { reasoningBlocks: completedReasoningBlocks } } }\n : {}),\n };\n\n toolBlocks.delete(index);\n }\n\n const reasoningAccumulator = reasoningBlocks.get(index);\n\n if (reasoningAccumulator) {\n const reasoningBlock = this.toReasoningMetadata(reasoningAccumulator);\n\n if (reasoningBlock) {\n completedReasoningBlocks.push(reasoningBlock);\n }\n reasoningBlocks.delete(index);\n }\n\n continue;\n }\n\n if (event.messageStop) {\n rawStopReason = event.messageStop.stopReason;\n }\n\n if (event.metadata?.usage) {\n usage = this.extractUsage(event.metadata.usage);\n }\n }\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n const finishReason = mapStopReason(rawStopReason);\n\n attachCost(usage, this.pricing);\n\n this.logger.debug(LOG_MODULE, \"response\", \"ConverseStream call succeeded\", {\n finishReason,\n usage,\n });\n\n yield { type: \"done\", finishReason, usage };\n }\n\n /**\n * Assemble the Converse request shared by `complete()` and\n * `stream()` (both command shapes take the same input). Hoists the\n * system prompt, maps inference params, and conditionally attaches\n * tools and native structured output.\n */\n private buildRequest(\n messages: Message[],\n options: ModelCallOptions | undefined,\n ): ConverseRequest {\n const { system, messages: bedrockMessages } = toBedrockMessages(messages);\n const thinkingBudget = this.resolveThinkingBudget(options?.reasoning);\n const configuredMaxTokens = options?.maxTokens ?? this.config.maxTokens;\n const maxTokens = this.resolveMaxTokens(configuredMaxTokens, thinkingBudget);\n const temperature = options?.temperature ?? this.config.temperature;\n const cachePoint = this.resolveCachePoint(options?.cacheControl);\n const cachedMessages = this.applyCacheBreakpoints(bedrockMessages, cachePoint);\n const cachedSystem = system && cachePoint ? [...system, { cachePoint }] : system;\n\n return mergeProviderBody<ConverseRequest>(\n {\n modelId: this.name,\n messages: cachedMessages,\n ...(cachedSystem ? { system: cachedSystem } : {}),\n inferenceConfig: {\n ...(maxTokens !== undefined ? { maxTokens } : {}),\n ...(temperature !== undefined ? { temperature } : {}),\n },\n ...this.buildToolConfig(options, cachePoint),\n ...this.buildOutputConfig(options?.responseSchema),\n ...this.buildReasoningConfig(thinkingBudget),\n },\n options,\n );\n }\n\n /**\n * Resolve the Converse `cachePoint` to place for this call, or\n * `undefined` when no cache point applies (the model is not\n * `promptCaching`-capable or no `cacheControl` breakpoint was asked\n * for). Bedrock only honors `type: \"default\"`; the neutral\n * `breakpoints` count is a presence hint.\n *\n * The lifetime is the per-call `cacheControl.ttl`, else the model's\n * `promptCacheTtl`. `ttl: \"1h\"` is sent only to models that accept it\n * ({@link supportsOneHourCacheTtl}); any other model gets the 5-minute\n * default, because AWS rejects the field there.\n */\n private resolveCachePoint(\n cacheControl: ModelCallOptions[\"cacheControl\"],\n ): BedrockCachePoint | undefined {\n const breakpoints = cacheControl?.breakpoints ?? 0;\n\n if (!this.capabilities.promptCaching || breakpoints <= 0) {\n return undefined;\n }\n\n const ttl = cacheControl?.ttl ?? this.config.promptCacheTtl;\n\n return ttl === \"1h\" && supportsOneHourCacheTtl(this.name)\n ? { type: \"default\", ttl: \"1h\" }\n : { type: \"default\" };\n }\n\n /**\n * Append the call's `cachePoint` to the LAST message. Together with the\n * `system` and `tools` cache points (see `buildRequest` /\n * `buildToolConfig`) this caches every stable segment of the prefix —\n * Bedrock processes them in `tools` → `system` → `messages` order, at\n * most three of the four checkpoints it allows — so later calls reusing\n * the prefix bill it at the cache-read rate (`Usage.cachedTokens`).\n */\n private applyCacheBreakpoints(\n messages: ConverseRequest[\"messages\"],\n cachePoint: BedrockCachePoint | undefined,\n ): ConverseRequest[\"messages\"] {\n if (!cachePoint || !messages || messages.length === 0) {\n return messages;\n }\n\n const last = messages.length - 1;\n const lastMessage = messages[last];\n\n if (!lastMessage) {\n return messages;\n }\n\n return [\n ...messages.slice(0, last),\n {\n ...lastMessage,\n content: [...(lastMessage.content ?? []), { cachePoint }],\n },\n ];\n }\n\n /**\n * Translate the neutral `reasoning` option into Claude-on-Bedrock's\n * extended-thinking control, carried in Converse's escape hatch\n * `additionalModelRequestFields.thinking`. Emitted only when the model\n * is `reasoning`-capable and a budget can be resolved — `maxTokens`\n * (explicit thinking budget) wins, otherwise `effort` maps to a\n * conventional token budget so callers can opt in without picking a\n * number. Returns an empty object (no-op) for non-reasoning models or\n * when no reasoning option was supplied, so unsupported params never\n * reach the wire.\n */\n private resolveThinkingBudget(reasoning: ModelCallOptions[\"reasoning\"]): number | undefined {\n if (!this.capabilities.reasoning || !reasoning || reasoning.effort === \"none\") {\n return undefined;\n }\n\n const budgetTokens = reasoning.maxTokens ?? EFFORT_THINKING_BUDGET[reasoning.effort ?? \"\"];\n\n if (budgetTokens !== undefined && budgetTokens < MIN_THINKING_BUDGET) {\n throw new Error(`thinking budget (${budgetTokens}) must be at least ${MIN_THINKING_BUDGET}`);\n }\n\n return budgetTokens;\n }\n\n /** Resolve Bedrock's output ceiling while reserving room for extended thinking. */\n private resolveMaxTokens(\n maxTokens: number | undefined,\n thinkingBudget: number | undefined,\n ): number | undefined {\n if (thinkingBudget === undefined) {\n return maxTokens;\n }\n\n if (maxTokens === undefined) {\n return thinkingBudget + DEFAULT_MAX_TOKENS;\n }\n\n if (maxTokens <= thinkingBudget) {\n throw new Error(\n `maxTokens (${maxTokens}) must be greater than thinking budget (${thinkingBudget})`,\n );\n }\n\n return maxTokens;\n }\n\n private buildReasoningConfig(\n budgetTokens: number | undefined,\n ): Pick<ConverseRequest, \"additionalModelRequestFields\"> {\n if (budgetTokens === undefined) {\n return {};\n }\n\n return {\n additionalModelRequestFields: {\n thinking: { type: \"enabled\", budget_tokens: budgetTokens },\n },\n };\n }\n\n /**\n * Spread-friendly tool fragment. Returns an empty object when no\n * tools were supplied (Bedrock rejects an empty `tools` array). With a\n * cache point, a trailing `{ cachePoint }` caches every tool definition\n * — Claude only, since Nova accepts no cache point in `tools`.\n */\n private buildToolConfig(\n options: ModelCallOptions | undefined,\n cachePoint: BedrockCachePoint | undefined,\n ): Pick<ConverseRequest, \"toolConfig\"> {\n const { tools, definitions } = selectProviderTools(options, {\n accepts: [BEDROCK_WIRE_FORMAT, this.provider],\n module: LOG_MODULE,\n model: this.name,\n logger: this.logger,\n });\n const toolConfig = toBedrockToolConfig(tools);\n // Provider-defined entries are whole Converse `Tool` members, e.g.\n // `{ systemTool: { name: \"nova_grounding\" } }` (Nova web grounding).\n const providerDefined = definitions as unknown as Tool[];\n\n const allTools = [...(toolConfig?.tools ?? []), ...providerDefined];\n\n if (allTools.length === 0) {\n return toolConfig ? { toolConfig } : {};\n }\n\n // The cache point goes last, so every tool definition is cached.\n const withCachePoint =\n cachePoint && supportsToolCachePoint(this.name) ? [...allTools, { cachePoint }] : allTools;\n\n return { toolConfig: { ...toolConfig, tools: withCachePoint } };\n }\n\n /**\n * Translate the neutral `responseSchema` into Converse's native\n * `outputConfig.textFormat` (JSON-schema structured output). Bedrock\n * requires the schema as a stringified JSON document and only\n * accepts an object root. Emitted only when the model is\n * `structuredOutput`-capable and the schema is an object — otherwise\n * the agent's soft system-prompt hint + client-side `validate()`\n * carry shape (same degradation philosophy as the OpenAI adapter).\n */\n private buildOutputConfig(\n responseSchema: Record<string, unknown> | undefined,\n ): Pick<ConverseRequest, \"outputConfig\"> {\n if (!responseSchema || !this.capabilities.structuredOutput) {\n return {};\n }\n\n if (responseSchema.type !== \"object\" || typeof responseSchema.properties !== \"object\") {\n return {};\n }\n\n return {\n outputConfig: {\n textFormat: {\n type: \"json_schema\",\n structure: {\n jsonSchema: { name: \"response\", schema: JSON.stringify(responseSchema) },\n },\n },\n },\n };\n }\n\n /**\n * Concatenate every `text` content block into the single neutral\n * `content` string. `toolUse` and other block types are surfaced\n * separately via `extractToolCalls`.\n */\n private extractText(blocks: ContentBlock[]): string {\n return blocks\n .map((block) => (\"text\" in block && typeof block.text === \"string\" ? block.text : \"\"))\n .join(\"\");\n }\n\n /**\n * Reshape Converse `toolUse` content blocks into the neutral\n * `ModelToolCallRequest[]`. Returns `undefined` when no tools were\n * requested so callers can branch on presence.\n */\n private extractToolCalls(blocks: ContentBlock[]): ModelToolCallRequest[] | undefined {\n const toolCalls: ModelToolCallRequest[] = [];\n const reasoningBlocks = blocks\n .map(toReasoningMetadata)\n .filter((block): block is BedrockReasoningBlock => block !== undefined);\n\n for (const block of blocks) {\n // `server_tool_use` blocks are run by Bedrock (system tools such as\n // Nova grounding); only client tool uses are dispatched.\n if (\"toolUse\" in block && block.toolUse && block.toolUse.type !== SERVER_TOOL_USE) {\n toolCalls.push({\n id: block.toolUse.toolUseId ?? \"\",\n name: block.toolUse.name ?? \"\",\n input: (block.toolUse.input ?? {}) as Record<string, unknown>,\n ...(reasoningBlocks.length > 0\n ? { providerMetadata: { bedrock: { reasoningBlocks } } }\n : {}),\n });\n }\n }\n\n return toolCalls.length > 0 ? toolCalls : undefined;\n }\n\n /** Encode accumulated stream deltas as persistence-safe reasoning metadata. */\n private toReasoningMetadata(block: {\n text?: string;\n signature?: string;\n redactedContent?: Uint8Array;\n }): BedrockReasoningBlock | undefined {\n if (block.redactedContent !== undefined) {\n return toReasoningMetadata({ reasoningContent: { redactedContent: block.redactedContent } });\n }\n\n return toReasoningMetadata({\n reasoningContent: {\n reasoningText: {\n text: block.text ?? \"\",\n ...(block.signature ? { signature: block.signature } : {}),\n },\n },\n });\n }\n\n /**\n * Normalize Converse's `TokenUsage` into the neutral `Usage` shape.\n * Bedrock supplies a pre-summed `totalTokens`; cache-read and\n * cache-write tokens are surfaced as `cachedTokens` /\n * `cacheWriteTokens` only when non-zero, and the 1-hour share of the\n * writes (`cacheDetails` entries with `ttl: \"1h\"`) as\n * `cacheWrite1hTokens`. With caching, `inputTokens` \"represents only\n * the non-cached input tokens\" (AWS prompt-caching guide), so the usage\n * is marked `inputIncludesCache: false`. Bedrock's Converse `TokenUsage`\n * carries no reasoning-token channel, so `Usage.reasoningTokens` is\n * intentionally left unset here.\n */\n private extractUsage(raw: TokenUsage | undefined): Usage {\n if (!raw) {\n return { input: 0, output: 0, total: 0 };\n }\n\n const input = raw.inputTokens ?? 0;\n const output = raw.outputTokens ?? 0;\n const cached = raw.cacheReadInputTokens;\n const cacheWrite = raw.cacheWriteInputTokens;\n const cacheWrite1h = (raw.cacheDetails ?? [])\n .filter((detail) => detail.ttl === \"1h\")\n .reduce((sum, detail) => sum + (detail.inputTokens ?? 0), 0);\n\n return {\n input,\n output,\n total: raw.totalTokens ?? input + output,\n inputIncludesCache: false,\n ...(cached && cached > 0 ? { cachedTokens: cached } : {}),\n ...(cacheWrite && cacheWrite > 0 ? { cacheWriteTokens: cacheWrite } : {}),\n ...(cacheWrite && cacheWrite > 0 && cacheWrite1h > 0\n ? { cacheWrite1hTokens: Math.min(cacheWrite1h, cacheWrite) }\n : {}),\n };\n }\n\n /**\n * Wrap a thrown provider error into the typed `AIError` hierarchy\n * and emit the standard error log line before it propagates. Shared\n * by every catch site so the log shape stays identical.\n */\n private logAndWrap(thrown: unknown) {\n const wrapped = wrapBedrockError(thrown);\n\n this.logger.error(LOG_MODULE, \"error\", wrapped.message, {\n code: wrapped.code,\n context: wrapped.context,\n });\n\n return wrapped;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4CA,MAAM,aAAa;;AAGnB,MAAM,sBAAsB;;AA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,IAAI;EACvB,MAAM,gBAAgB,IAAI,gBAAgB,CAAC,EAAC,CACzC,QAAQ,WAAW,OAAO,QAAQ,IAAI,CAAC,CACvC,QAAQ,KAAK,WAAW,OAAO,OAAO,eAAe,IAAI,CAAC;EAE7D,OAAO;GACL;GACA;GACA,OAAO,IAAI,eAAe,QAAQ;GAClC,oBAAoB;GACpB,GAAI,UAAU,SAAS,IAAI,EAAE,cAAc,OAAO,IAAI,CAAC;GACvD,GAAI,cAAc,aAAa,IAAI,EAAE,kBAAkB,WAAW,IAAI,CAAC;GACvE,GAAI,cAAc,aAAa,KAAK,eAAe,IAC/C,EAAE,oBAAoB,KAAK,IAAI,cAAc,UAAU,EAAE,IACzD,CAAC;EACP;CACF;;;;;;CAOA,AAAQ,WAAW,QAAiB;EAClC,MAAM,UAAU,iBAAiB,MAAM;EAEvC,KAAK,OAAO,MAAM,YAAY,SAAS,QAAQ,SAAS;GACtD,MAAM,QAAQ;GACd,SAAS,QAAQ;EACnB,CAAC;EAED,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"model.mjs","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/model.ts"],"sourcesContent":["import {\n attachCost,\n InvalidRequestError,\n resolveStreamChunks,\n safeJsonParse,\n selectProviderTools,\n type Message,\n type ModelCallOptions,\n type ModelCapabilities,\n type ModelContract,\n type ModelPricing,\n type ModelResponse,\n type ModelStreamChunk,\n type ModelToolCallRequest,\n type Usage,\n} from \"@warlock.js/ai\";\nimport { log, type Logger } from \"@warlock.js/logger\";\nimport {\n CountTokensCommand,\n ConverseCommand,\n ConverseStreamCommand,\n type Tool,\n type BedrockRuntimeClient,\n type ContentBlock,\n type ConverseRequest,\n type TokenUsage,\n} from \"@aws-sdk/client-bedrock-runtime\";\nimport { mergeProviderBody } from \"./provider-options\";\nimport type { BedrockModelConfig } from \"./config.type\";\nimport {\n inferPdfCapability,\n inferPromptCachingCapability,\n inferReasoningCapability,\n supportsOneHourCacheTtl,\n supportsToolCachePoint,\n} from \"./known-capabilities\";\nimport { bedrockPricingFor, withClaudeCacheWriteRates } from \"./known-pricing\";\nimport { inferVisionCapability } from \"./known-vision-models\";\nimport { toReasoningMetadata, type BedrockReasoningBlock } from \"./utils/reasoning-blocks\";\nimport { mapStopReason, toBedrockMessages, toBedrockToolConfig, wrapBedrockError } from \"./utils\";\n\n/** A Converse cache point as this adapter emits it. */\ntype BedrockCachePoint = { type: \"default\"; ttl?: \"1h\" };\n\nconst LOG_MODULE = \"ai.bedrock\";\n\n/** `provider` value of `ai.providerTool()` entries this adapter sends verbatim. */\nconst BEDROCK_WIRE_FORMAT = \"bedrock\";\n\n/** Converse `ToolUseBlock.type` of a tool use run by Bedrock itself (SDK `ToolUseType`). */\nconst SERVER_TOOL_USE = \"server_tool_use\";\n\n/** Default output allowance added to a thinking budget when maxTokens is unset. */\nconst DEFAULT_MAX_TOKENS = 4096;\nconst MIN_THINKING_BUDGET = 1024;\n\n/**\n * Conventional extended-thinking token budgets for the neutral\n * `reasoning.effort` levels, used when the caller asks for an effort\n * tier without naming an explicit `reasoning.maxTokens` budget. Mirrors\n * the low / medium / high spread other reasoning adapters expose so the\n * vendor-neutral option behaves consistently across providers.\n */\nconst EFFORT_THINKING_BUDGET: Record<string, number | undefined> = {\n minimal: 1024,\n low: 1024,\n medium: 4096,\n high: 16384,\n xhigh: 24000,\n max: 32000,\n};\n\n/**\n * Bedrock-backed implementation of `ModelContract`.\n *\n * **Role.** The provider-facing bridge between the vendor-neutral\n * `@warlock.js/ai` agent runtime and AWS Bedrock's Converse /\n * ConverseStream API. Converse is the model-agnostic surface — one\n * wire mapping covers every Bedrock-hosted family (Anthropic Claude,\n * Amazon Nova, Meta Llama, Mistral, Cohere) instead of per-family\n * `InvokeModel` body shapes.\n *\n * **Responsibility.**\n * - Owns: a long-lived `BedrockRuntimeClient` + frozen `ModelConfig`\n * (modelId, temperature, maxTokens) used as per-call defaults.\n * - Owns: translating vendor-neutral `Message[]` / `ToolConfig[]` into\n * Converse shapes (system hoisting, `toolUse` / `toolResult` blocks,\n * image bytes) on the way out, and Converse's content-block response\n * (text, tool calls, stop reason, token usage) back into the neutral\n * shapes on the way in.\n * - Does NOT own: dispatching tools, looping, history, retries — those\n * are agent concerns. The model is a per-call protocol adapter.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across calls\"): the AWS client is heavy to construct and reused for\n * the SDK's lifetime.\n *\n * @example\n * import { BedrockRuntimeClient } from \"@aws-sdk/client-bedrock-runtime\";\n * const client = new BedrockRuntimeClient({ region: \"us-east-1\" });\n * const model = new BedrockModel(client, {\n * name: \"anthropic.claude-sonnet-4-5-20250929-v1:0\",\n * });\n *\n * const myAgent = agent({ model, tools: [searchTool] });\n * const result = await myAgent.execute(\"Summarize today's news.\");\n */\nexport class BedrockModel implements ModelContract {\n public readonly name: string;\n public readonly provider: string;\n public readonly capabilities: ModelCapabilities;\n public readonly pricing?: ModelPricing;\n\n private readonly client: BedrockRuntimeClient;\n private readonly config: BedrockModelConfig;\n private readonly logger: Logger = log;\n\n public constructor(\n client: BedrockRuntimeClient,\n config: BedrockModelConfig,\n provider: string = \"bedrock\",\n ) {\n this.client = client;\n this.config = config;\n this.name = config.name;\n this.provider = provider;\n // Explicit pricing wins over the built-in `global.` / `us.` profile\n // prices; Claude entries get the 1.25x / 2x cache-write rates filled.\n this.pricing = withClaudeCacheWriteRates(\n config.name,\n config.pricing ?? bedrockPricingFor(config.name),\n );\n this.capabilities = {\n structuredOutput: config.structuredOutput ?? true,\n vision: config.vision ?? inferVisionCapability(config.name),\n reasoning: config.reasoning ?? inferReasoningCapability(config.name),\n promptCaching: config.promptCaching ?? inferPromptCachingCapability(config.name),\n pdf: config.pdf ?? inferPdfCapability(config.name),\n audio: config.audio ?? false,\n };\n }\n\n /**\n * Single-shot completion via the Converse API. Sends the full\n * message list, waits for the terminal response, and reshapes it\n * into a vendor-neutral `ModelResponse`. Per-call `options` override\n * the instance defaults for this call only.\n */\n public async complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse> {\n this.logger.debug(LOG_MODULE, \"request\", \"Starting Converse call\", {\n model: this.name,\n messageCount: messages.length,\n streaming: false,\n toolCount: options?.tools?.length ?? 0,\n });\n\n let response;\n\n try {\n response = await this.client.send(\n new ConverseCommand(this.buildRequest(messages, options)),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n const blocks = response.output?.message?.content ?? [];\n const finishReason = mapStopReason(response.stopReason);\n const usage = attachCost(this.extractUsage(response.usage), this.pricing);\n const toolCalls = this.extractToolCalls(blocks);\n\n this.logger.debug(LOG_MODULE, \"response\", \"Converse call succeeded\", { finishReason, usage });\n\n return {\n content: this.extractText(blocks),\n finishReason,\n usage,\n toolCalls,\n };\n }\n\n /** Count native input tokens from the same Converse conversation and tool configuration. */\n public async countTokens(messages: Message[], options?: ModelCallOptions): Promise<number> {\n const request = this.buildRequest(messages, options);\n try {\n const response = await this.client.send(\n new CountTokensCommand({\n modelId: request.modelId,\n input: {\n converse: {\n messages: request.messages,\n system: request.system,\n toolConfig: request.toolConfig,\n additionalModelRequestFields: request.additionalModelRequestFields,\n },\n },\n }),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n if (response.inputTokens === undefined)\n throw new InvalidRequestError(\"Bedrock countTokens returned no inputTokens.\");\n return response.inputTokens;\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n }\n\n /**\n * Incremental streaming completion via ConverseStream. Yields neutral\n * `ModelStreamChunk`s — `delta` for text, `tool-call` once a\n * `toolUse` block's accumulated input JSON is complete, and a\n * terminal `done` with the final finish reason + usage totals.\n *\n * With `options.streamChunks` it also yields `reasoning` for each\n * `reasoningContent.text` delta and `tool-args` for each client\n * `toolUse.input` delta. Usage arrives once, in the final `metadata`\n * event, so no `usage` chunk is emitted. A system tool's\n * `server_tool_use` block never becomes a `tool-call`.\n */\n public async *stream(\n messages: Message[],\n options?: ModelCallOptions,\n ): AsyncIterable<ModelStreamChunk> {\n this.logger.debug(LOG_MODULE, \"request\", \"Starting ConverseStream call\", {\n model: this.name,\n messageCount: messages.length,\n streaming: true,\n toolCount: options?.tools?.length ?? 0,\n });\n\n let response;\n\n try {\n response = await this.client.send(\n new ConverseStreamCommand(this.buildRequest(messages, options)),\n options?.signal ? { abortSignal: options.signal } : undefined,\n );\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n let rawStopReason: string | undefined;\n let usage: Usage = { input: 0, output: 0, total: 0 };\n const want = resolveStreamChunks(options);\n const toolBlocks = new Map<number, { id: string; name: string; json: string }>();\n const reasoningBlocks = new Map<\n number,\n { text?: string; signature?: string; redactedContent?: Uint8Array }\n >();\n const completedReasoningBlocks: BedrockReasoningBlock[] = [];\n\n try {\n for await (const event of response.stream ?? []) {\n if (event.contentBlockStart?.start?.toolUse) {\n const start = event.contentBlockStart.start.toolUse;\n\n // A system tool's `server_tool_use` runs on Bedrock's side.\n if (start.type === SERVER_TOOL_USE) {\n continue;\n }\n\n toolBlocks.set(event.contentBlockStart.contentBlockIndex ?? 0, {\n id: start.toolUseId ?? \"\",\n name: start.name ?? \"\",\n json: \"\",\n });\n\n continue;\n }\n\n if (event.contentBlockDelta?.delta) {\n const delta = event.contentBlockDelta.delta;\n\n if (delta.text) {\n yield { type: \"delta\", content: delta.text };\n } else if (delta.toolUse) {\n const accumulator = toolBlocks.get(event.contentBlockDelta.contentBlockIndex ?? 0);\n\n if (accumulator) {\n accumulator.json += delta.toolUse.input ?? \"\";\n\n if (want.toolArgs && delta.toolUse.input) {\n yield {\n type: \"tool-args\",\n callId: accumulator.id,\n name: accumulator.name,\n delta: delta.toolUse.input,\n };\n }\n }\n } else if (delta.reasoningContent) {\n const index = event.contentBlockDelta.contentBlockIndex ?? 0;\n const accumulator = reasoningBlocks.get(index) ?? {};\n\n if (delta.reasoningContent.text !== undefined) {\n accumulator.text = (accumulator.text ?? \"\") + delta.reasoningContent.text;\n\n if (want.reasoning && delta.reasoningContent.text !== \"\") {\n yield { type: \"reasoning\", delta: delta.reasoningContent.text };\n }\n }\n\n if (delta.reasoningContent.signature !== undefined) {\n accumulator.signature = delta.reasoningContent.signature;\n }\n\n if (delta.reasoningContent.redactedContent !== undefined) {\n accumulator.redactedContent = delta.reasoningContent.redactedContent;\n }\n\n reasoningBlocks.set(index, accumulator);\n }\n\n continue;\n }\n\n if (event.contentBlockStop) {\n const index = event.contentBlockStop.contentBlockIndex ?? 0;\n const accumulator = toolBlocks.get(index);\n\n if (accumulator) {\n yield {\n type: \"tool-call\",\n id: accumulator.id,\n name: accumulator.name,\n input: safeJsonParse<Record<string, unknown>>(accumulator.json, {}),\n ...(completedReasoningBlocks.length > 0\n ? { providerMetadata: { bedrock: { reasoningBlocks: completedReasoningBlocks } } }\n : {}),\n };\n\n toolBlocks.delete(index);\n }\n\n const reasoningAccumulator = reasoningBlocks.get(index);\n\n if (reasoningAccumulator) {\n const reasoningBlock = this.toReasoningMetadata(reasoningAccumulator);\n\n if (reasoningBlock) {\n completedReasoningBlocks.push(reasoningBlock);\n }\n reasoningBlocks.delete(index);\n }\n\n continue;\n }\n\n if (event.messageStop) {\n rawStopReason = event.messageStop.stopReason;\n }\n\n if (event.metadata?.usage) {\n usage = this.extractUsage(event.metadata.usage);\n }\n }\n } catch (thrown) {\n throw this.logAndWrap(thrown);\n }\n\n const finishReason = mapStopReason(rawStopReason);\n\n attachCost(usage, this.pricing);\n\n this.logger.debug(LOG_MODULE, \"response\", \"ConverseStream call succeeded\", {\n finishReason,\n usage,\n });\n\n yield { type: \"done\", finishReason, usage };\n }\n\n /**\n * Assemble the Converse request shared by `complete()` and\n * `stream()` (both command shapes take the same input). Hoists the\n * system prompt, maps inference params, and conditionally attaches\n * tools and native structured output.\n */\n private buildRequest(\n messages: Message[],\n options: ModelCallOptions | undefined,\n ): ConverseRequest {\n const { system, messages: bedrockMessages } = toBedrockMessages(messages);\n const thinkingBudget = this.resolveThinkingBudget(options?.reasoning);\n const configuredMaxTokens = options?.maxTokens ?? this.config.maxTokens;\n const maxTokens = this.resolveMaxTokens(configuredMaxTokens, thinkingBudget);\n const temperature = options?.temperature ?? this.config.temperature;\n const cachePoint = this.resolveCachePoint(options?.cacheControl);\n const cachedMessages = this.applyCacheBreakpoints(bedrockMessages, cachePoint);\n const cachedSystem = system && cachePoint ? [...system, { cachePoint }] : system;\n\n return mergeProviderBody<ConverseRequest>(\n {\n modelId: this.name,\n messages: cachedMessages,\n ...(cachedSystem ? { system: cachedSystem } : {}),\n inferenceConfig: {\n ...(maxTokens !== undefined ? { maxTokens } : {}),\n ...(temperature !== undefined ? { temperature } : {}),\n },\n ...this.buildToolConfig(options, cachePoint),\n ...this.buildOutputConfig(options?.responseSchema),\n ...this.buildReasoningConfig(thinkingBudget),\n },\n options,\n );\n }\n\n /**\n * Resolve the Converse `cachePoint` to place for this call, or\n * `undefined` when no cache point applies (the model is not\n * `promptCaching`-capable or no `cacheControl` breakpoint was asked\n * for). Bedrock only honors `type: \"default\"`; the neutral\n * `breakpoints` count is a presence hint.\n *\n * The lifetime is the per-call `cacheControl.ttl`, else the model's\n * `promptCacheTtl`. `ttl: \"1h\"` is sent only to models that accept it\n * ({@link supportsOneHourCacheTtl}); any other model gets the 5-minute\n * default, because AWS rejects the field there.\n */\n private resolveCachePoint(\n cacheControl: ModelCallOptions[\"cacheControl\"],\n ): BedrockCachePoint | undefined {\n const breakpoints = cacheControl?.breakpoints ?? 0;\n\n if (!this.capabilities.promptCaching || breakpoints <= 0) {\n return undefined;\n }\n\n const ttl = cacheControl?.ttl ?? this.config.promptCacheTtl;\n\n return ttl === \"1h\" && supportsOneHourCacheTtl(this.name)\n ? { type: \"default\", ttl: \"1h\" }\n : { type: \"default\" };\n }\n\n /**\n * Append the call's `cachePoint` to the LAST message. Together with the\n * `system` and `tools` cache points (see `buildRequest` /\n * `buildToolConfig`) this caches every stable segment of the prefix —\n * Bedrock processes them in `tools` → `system` → `messages` order, at\n * most three of the four checkpoints it allows — so later calls reusing\n * the prefix bill it at the cache-read rate (`Usage.cachedTokens`).\n */\n private applyCacheBreakpoints(\n messages: ConverseRequest[\"messages\"],\n cachePoint: BedrockCachePoint | undefined,\n ): ConverseRequest[\"messages\"] {\n if (!cachePoint || !messages || messages.length === 0) {\n return messages;\n }\n\n const last = messages.length - 1;\n const lastMessage = messages[last];\n\n if (!lastMessage) {\n return messages;\n }\n\n return [\n ...messages.slice(0, last),\n {\n ...lastMessage,\n content: [...(lastMessage.content ?? []), { cachePoint }],\n },\n ];\n }\n\n /**\n * Translate the neutral `reasoning` option into Claude-on-Bedrock's\n * extended-thinking control, carried in Converse's escape hatch\n * `additionalModelRequestFields.thinking`. Emitted only when the model\n * is `reasoning`-capable and a budget can be resolved — `maxTokens`\n * (explicit thinking budget) wins, otherwise `effort` maps to a\n * conventional token budget so callers can opt in without picking a\n * number. Returns an empty object (no-op) for non-reasoning models or\n * when no reasoning option was supplied, so unsupported params never\n * reach the wire.\n */\n private resolveThinkingBudget(reasoning: ModelCallOptions[\"reasoning\"]): number | undefined {\n if (!this.capabilities.reasoning || !reasoning || reasoning.effort === \"none\") {\n return undefined;\n }\n\n const budgetTokens = reasoning.maxTokens ?? EFFORT_THINKING_BUDGET[reasoning.effort ?? \"\"];\n\n if (budgetTokens !== undefined && budgetTokens < MIN_THINKING_BUDGET) {\n throw new Error(`thinking budget (${budgetTokens}) must be at least ${MIN_THINKING_BUDGET}`);\n }\n\n return budgetTokens;\n }\n\n /** Resolve Bedrock's output ceiling while reserving room for extended thinking. */\n private resolveMaxTokens(\n maxTokens: number | undefined,\n thinkingBudget: number | undefined,\n ): number | undefined {\n if (thinkingBudget === undefined) {\n return maxTokens;\n }\n\n if (maxTokens === undefined) {\n return thinkingBudget + DEFAULT_MAX_TOKENS;\n }\n\n if (maxTokens <= thinkingBudget) {\n throw new Error(\n `maxTokens (${maxTokens}) must be greater than thinking budget (${thinkingBudget})`,\n );\n }\n\n return maxTokens;\n }\n\n private buildReasoningConfig(\n budgetTokens: number | undefined,\n ): Pick<ConverseRequest, \"additionalModelRequestFields\"> {\n if (budgetTokens === undefined) {\n return {};\n }\n\n return {\n additionalModelRequestFields: {\n thinking: { type: \"enabled\", budget_tokens: budgetTokens },\n },\n };\n }\n\n /**\n * Spread-friendly tool fragment. Returns an empty object when no\n * tools were supplied (Bedrock rejects an empty `tools` array). With a\n * cache point, a trailing `{ cachePoint }` caches every tool definition\n * — Claude only, since Nova accepts no cache point in `tools`.\n */\n private buildToolConfig(\n options: ModelCallOptions | undefined,\n cachePoint: BedrockCachePoint | undefined,\n ): Pick<ConverseRequest, \"toolConfig\"> {\n const { tools, definitions } = selectProviderTools(options, {\n accepts: [BEDROCK_WIRE_FORMAT, this.provider],\n module: LOG_MODULE,\n model: this.name,\n logger: this.logger,\n });\n const toolConfig = toBedrockToolConfig(tools);\n // Provider-defined entries are whole Converse `Tool` members, e.g.\n // `{ systemTool: { name: \"nova_grounding\" } }` (Nova web grounding).\n const providerDefined = definitions as unknown as Tool[];\n\n const allTools = [...(toolConfig?.tools ?? []), ...providerDefined];\n\n if (allTools.length === 0) {\n return toolConfig ? { toolConfig } : {};\n }\n\n // The cache point goes last, so every tool definition is cached.\n const withCachePoint =\n cachePoint && supportsToolCachePoint(this.name) ? [...allTools, { cachePoint }] : allTools;\n\n return { toolConfig: { ...toolConfig, tools: withCachePoint } };\n }\n\n /**\n * Translate the neutral `responseSchema` into Converse's native\n * `outputConfig.textFormat` (JSON-schema structured output). Bedrock\n * requires the schema as a stringified JSON document and only\n * accepts an object root. Emitted only when the model is\n * `structuredOutput`-capable and the schema is an object — otherwise\n * the agent's soft system-prompt hint + client-side `validate()`\n * carry shape (same degradation philosophy as the OpenAI adapter).\n */\n private buildOutputConfig(\n responseSchema: Record<string, unknown> | undefined,\n ): Pick<ConverseRequest, \"outputConfig\"> {\n if (!responseSchema || !this.capabilities.structuredOutput) {\n return {};\n }\n\n if (responseSchema.type !== \"object\" || typeof responseSchema.properties !== \"object\") {\n return {};\n }\n\n return {\n outputConfig: {\n textFormat: {\n type: \"json_schema\",\n structure: {\n jsonSchema: { name: \"response\", schema: JSON.stringify(responseSchema) },\n },\n },\n },\n };\n }\n\n /**\n * Concatenate every `text` content block into the single neutral\n * `content` string. `toolUse` and other block types are surfaced\n * separately via `extractToolCalls`.\n */\n private extractText(blocks: ContentBlock[]): string {\n return blocks\n .map((block) => (\"text\" in block && typeof block.text === \"string\" ? block.text : \"\"))\n .join(\"\");\n }\n\n /**\n * Reshape Converse `toolUse` content blocks into the neutral\n * `ModelToolCallRequest[]`. Returns `undefined` when no tools were\n * requested so callers can branch on presence.\n */\n private extractToolCalls(blocks: ContentBlock[]): ModelToolCallRequest[] | undefined {\n const toolCalls: ModelToolCallRequest[] = [];\n const reasoningBlocks = blocks\n .map(toReasoningMetadata)\n .filter((block): block is BedrockReasoningBlock => block !== undefined);\n\n for (const block of blocks) {\n // `server_tool_use` blocks are run by Bedrock (system tools such as\n // Nova grounding); only client tool uses are dispatched.\n if (\"toolUse\" in block && block.toolUse && block.toolUse.type !== SERVER_TOOL_USE) {\n toolCalls.push({\n id: block.toolUse.toolUseId ?? \"\",\n name: block.toolUse.name ?? \"\",\n input: (block.toolUse.input ?? {}) as Record<string, unknown>,\n ...(reasoningBlocks.length > 0\n ? { providerMetadata: { bedrock: { reasoningBlocks } } }\n : {}),\n });\n }\n }\n\n return toolCalls.length > 0 ? toolCalls : undefined;\n }\n\n /** Encode accumulated stream deltas as persistence-safe reasoning metadata. */\n private toReasoningMetadata(block: {\n text?: string;\n signature?: string;\n redactedContent?: Uint8Array;\n }): BedrockReasoningBlock | undefined {\n if (block.redactedContent !== undefined) {\n return toReasoningMetadata({ reasoningContent: { redactedContent: block.redactedContent } });\n }\n\n return toReasoningMetadata({\n reasoningContent: {\n reasoningText: {\n text: block.text ?? \"\",\n ...(block.signature ? { signature: block.signature } : {}),\n },\n },\n });\n }\n\n /**\n * Normalize Converse's `TokenUsage` into the neutral `Usage` shape.\n * Bedrock supplies a pre-summed `totalTokens`; cache-read and\n * cache-write tokens are surfaced as `cachedTokens` /\n * `cacheWriteTokens` only when non-zero, and the 1-hour share of the\n * writes (`cacheDetails` entries with `ttl: \"1h\"`) as\n * `cacheWrite1hTokens`. With caching, `inputTokens` \"represents only\n * the non-cached input tokens\" (AWS prompt-caching guide), so the usage\n * is marked `inputIncludesCache: false`. Bedrock's Converse `TokenUsage`\n * carries no reasoning-token channel, so `Usage.reasoningTokens` is\n * intentionally left unset here. The installed SDK 3.1121.0 TokenUsage also\n * has no hosted-tool request counter; do not infer one from tool blocks.\n * https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_TokenUsage.html\n */\n private extractUsage(raw: TokenUsage | undefined): Usage {\n if (!raw) {\n return { input: 0, output: 0, total: 0 };\n }\n\n const input = raw.inputTokens ?? 0;\n const output = raw.outputTokens ?? 0;\n const cached = raw.cacheReadInputTokens;\n const cacheWrite = raw.cacheWriteInputTokens;\n const cacheWrite1h = (raw.cacheDetails ?? [])\n .filter((detail) => detail.ttl === \"1h\")\n .reduce((sum, detail) => sum + (detail.inputTokens ?? 0), 0);\n\n return {\n input,\n output,\n total: raw.totalTokens ?? input + output,\n inputIncludesCache: false,\n ...(cached && cached > 0 ? { cachedTokens: cached } : {}),\n ...(cacheWrite && cacheWrite > 0 ? { cacheWriteTokens: cacheWrite } : {}),\n ...(cacheWrite && cacheWrite > 0 && cacheWrite1h > 0\n ? { cacheWrite1hTokens: Math.min(cacheWrite1h, cacheWrite) }\n : {}),\n };\n }\n\n /**\n * Wrap a thrown provider error into the typed `AIError` hierarchy\n * and emit the standard error log line before it propagates. Shared\n * by every catch site so the log shape stays identical.\n */\n private logAndWrap(thrown: unknown) {\n const wrapped = wrapBedrockError(thrown);\n\n this.logger.error(LOG_MODULE, \"error\", wrapped.message, {\n code: wrapped.code,\n context: wrapped.context,\n });\n\n return wrapped;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4CA,MAAM,aAAa;;AAGnB,MAAM,sBAAsB;;AA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AAa,IAAI;EACvB,MAAM,gBAAgB,IAAI,gBAAgB,CAAC,EAAC,CACzC,QAAQ,WAAW,OAAO,QAAQ,IAAI,CAAC,CACvC,QAAQ,KAAK,WAAW,OAAO,OAAO,eAAe,IAAI,CAAC;EAE7D,OAAO;GACL;GACA;GACA,OAAO,IAAI,eAAe,QAAQ;GAClC,oBAAoB;GACpB,GAAI,UAAU,SAAS,IAAI,EAAE,cAAc,OAAO,IAAI,CAAC;GACvD,GAAI,cAAc,aAAa,IAAI,EAAE,kBAAkB,WAAW,IAAI,CAAC;GACvE,GAAI,cAAc,aAAa,KAAK,eAAe,IAC/C,EAAE,oBAAoB,KAAK,IAAI,cAAc,UAAU,EAAE,IACzD,CAAC;EACP;CACF;;;;;;CAOA,AAAQ,WAAW,QAAiB;EAClC,MAAM,UAAU,iBAAiB,MAAM;EAEvC,KAAK,OAAO,MAAM,YAAY,SAAS,QAAQ,SAAS;GACtD,MAAM,QAAQ;GACd,SAAS,QAAQ;EACnB,CAAC;EAED,OAAO;CACT;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import "@warlock.js/ai";
|
|
1
2
|
//#region ../../packages/ai-bedrock/src/provider-options.d.ts
|
|
2
3
|
/** Adapter-only fields merged after the neutral request parameters. */
|
|
3
|
-
type BedrockCallOptions = {
|
|
4
|
+
export type BedrockCallOptions = {
|
|
4
5
|
body?: Record<string, unknown>;
|
|
5
6
|
};
|
|
6
7
|
//#endregion
|
|
7
|
-
export { BedrockCallOptions };
|
|
8
8
|
//# sourceMappingURL=provider-options.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-options.d.mts","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/provider-options.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider-options.d.mts","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/provider-options.ts"],"mappings":";;;YAGY;EAAuB,OAAO"}
|
package/esm/provider-options.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-options.mjs","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/provider-options.ts"],"sourcesContent":["import { InvalidRequestError, type ModelCallOptions } from \"@warlock.js/ai\";\n\n/** Adapter-only fields merged after the neutral request parameters. */\nexport type BedrockCallOptions = { body?: Record<string, unknown> };\n\nconst RESERVED_FIELDS = new Set([\"modelId\", \"messages\", \"system\", \"toolConfig\"]);\n\nexport function mergeProviderBody<T extends object>(\n built: T,\n options: ModelCallOptions | undefined,\n): T {\n const provider = options?.providerOptions?.bedrock as BedrockCallOptions | undefined;\n const body = provider?.body ?? {};\n const reserved = Object.keys(body).filter((key) => RESERVED_FIELDS.has(key));\n if (reserved.length > 0) {\n throw new InvalidRequestError(\n `providerOptions.bedrock.body cannot set ${reserved.join(\", \")}: use the call's messages, tools and model options.`,\n { context: { fields: reserved } },\n );\n }\n const defaults = built as Record<string, unknown>;\n const overrides = Object.fromEntries(\n Object.entries(body).map(([key, value]) => {\n const previous = defaults[key];\n return [\n key,\n isPlainObject(previous) && isPlainObject(value) ? { ...previous, ...value } : value,\n ];\n }),\n );\n return { ...built, ...overrides };\n}\n\n/** Merge only plain objects; arrays, null and provider scalar values replace the field. */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== \"object\") return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n"],"mappings":";;;AAKA,MAAM,
|
|
1
|
+
{"version":3,"file":"provider-options.mjs","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/provider-options.ts"],"sourcesContent":["import { InvalidRequestError, type ModelCallOptions } from \"@warlock.js/ai\";\n\n/** Adapter-only fields merged after the neutral request parameters. */\nexport type BedrockCallOptions = { body?: Record<string, unknown> };\n\nconst RESERVED_FIELDS = new Set([\"modelId\", \"messages\", \"system\", \"toolConfig\"]);\n\nexport function mergeProviderBody<T extends object>(\n built: T,\n options: ModelCallOptions | undefined,\n): T {\n const provider = options?.providerOptions?.bedrock as BedrockCallOptions | undefined;\n const body = provider?.body ?? {};\n const reserved = Object.keys(body).filter((key) => RESERVED_FIELDS.has(key));\n if (reserved.length > 0) {\n throw new InvalidRequestError(\n `providerOptions.bedrock.body cannot set ${reserved.join(\", \")}: use the call's messages, tools and model options.`,\n { context: { fields: reserved } },\n );\n }\n const defaults = built as Record<string, unknown>;\n const overrides = Object.fromEntries(\n Object.entries(body).map(([key, value]) => {\n const previous = defaults[key];\n return [\n key,\n isPlainObject(previous) && isPlainObject(value) ? { ...previous, ...value } : value,\n ];\n }),\n );\n return { ...built, ...overrides };\n}\n\n/** Merge only plain objects; arrays, null and provider scalar values replace the field. */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== \"object\") return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n"],"mappings":";;;AAKA,MAAM,kCAAkB,IAAI,IAAI;CAAC;CAAW;CAAY;CAAU;AAAY,CAAC;AAE/E,SAAgB,kBACd,OACA,SACG;CAEH,MAAM,QADW,SAAS,iBAAiB,QACtB,EAAE,QAAQ,CAAC;CAChC,MAAM,WAAW,OAAO,KAAK,IAAI,CAAC,CAAC,QAAQ,QAAQ,gBAAgB,IAAI,GAAG,CAAC;CAC3E,IAAI,SAAS,SAAS,GACpB,MAAM,IAAI,oBACR,2CAA2C,SAAS,KAAK,IAAI,EAAE,sDAC/D,EAAE,SAAS,EAAE,QAAQ,SAAS,EAAE,CAClC;CAEF,MAAM,WAAW;CACjB,MAAM,YAAY,OAAO,YACvB,OAAO,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW;EACzC,MAAM,WAAW,SAAS;EAC1B,OAAO,CACL,KACA,cAAc,QAAQ,KAAK,cAAc,KAAK,IAAI;GAAE,GAAG;GAAU,GAAG;EAAM,IAAI,KAChF;CACF,CAAC,CACH;CACA,OAAO;EAAE,GAAG;EAAO,GAAG;CAAU;AAClC;;AAGA,SAAS,cAAc,OAAkD;CACvE,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO;CACxD,MAAM,YAAY,OAAO,eAAe,KAAK;CAC7C,OAAO,cAAc,OAAO,aAAa,cAAc;AACzD"}
|
package/esm/sdk.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BedrockEmbedderConfig, BedrockModelConfig, BedrockSDKConfig } from "./config.type.mjs";
|
|
2
2
|
import { EmbedderContract, ModelContract, SDKAdapterContract } from "@warlock.js/ai";
|
|
3
|
-
|
|
4
3
|
//#region ../../packages/ai-bedrock/src/sdk.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* AWS Bedrock-backed implementation of `SDKAdapterContract`.
|
|
@@ -32,7 +31,7 @@ import { EmbedderContract, ModelContract, SDKAdapterContract } from "@warlock.js
|
|
|
32
31
|
* // Amazon Bedrock API key (bearer auth) instead of the AWS credential chain
|
|
33
32
|
* const bedrock = new BedrockSDK({ apiKey: process.env.BEDROCK_API_KEY!, region: "us-east-1" });
|
|
34
33
|
*/
|
|
35
|
-
declare class BedrockSDK implements SDKAdapterContract {
|
|
34
|
+
export declare class BedrockSDK implements SDKAdapterContract {
|
|
36
35
|
private readonly client;
|
|
37
36
|
private readonly provider;
|
|
38
37
|
private readonly pricing?;
|
|
@@ -66,5 +65,4 @@ declare class BedrockSDK implements SDKAdapterContract {
|
|
|
66
65
|
embedder(config: BedrockEmbedderConfig): EmbedderContract;
|
|
67
66
|
}
|
|
68
67
|
//#endregion
|
|
69
|
-
export { BedrockSDK };
|
|
70
68
|
//# sourceMappingURL=sdk.d.mts.map
|
package/esm/sdk.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.mts","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/sdk.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sdk.d.mts","names":[],"sources":["../../../../../../../packages/ai-bedrock/src/sdk.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA0Ca,sBAAsB;mBAChB;mBACA;mBACA;EAEjB,YAAmB,QAAQ;;;;;;;;;;;EAoBpB,MAAM,QAAQ,qBAAqB;;;;;;;EAc7B,MAAM,cAAc,kBAAkB;;;;;;;;;EAY5C,SAAS,QAAQ,wBAAwB"}
|
package/esm/utils/index.mjs
CHANGED
|
@@ -3,4 +3,4 @@ import { toBedrockMessages } from "./to-bedrock-messages.mjs";
|
|
|
3
3
|
import { toBedrockToolConfig } from "./to-bedrock-tools.mjs";
|
|
4
4
|
import { wrapBedrockError } from "./wrap-bedrock-error.mjs";
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { mapStopReason, toBedrockMessages, toBedrockToolConfig, wrapBedrockError };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AIError, ContextLengthExceededError, InvalidRequestError, ProviderAuthError, ProviderError, ProviderOverloadedError, ProviderRateLimitError, ProviderTimeoutError, QuotaExceededError } from "@warlock.js/ai";
|
|
2
2
|
|
|
3
3
|
//#region ../../packages/ai-bedrock/src/utils/wrap-bedrock-error.ts
|
|
4
|
-
const TIMEOUT_NAMES = new Set([
|
|
4
|
+
const TIMEOUT_NAMES = /* @__PURE__ */ new Set([
|
|
5
5
|
"ModelTimeoutException",
|
|
6
6
|
"TimeoutError",
|
|
7
7
|
"RequestTimeout",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap-bedrock-error.mjs","names":[],"sources":["../../../../../../../../packages/ai-bedrock/src/utils/wrap-bedrock-error.ts"],"sourcesContent":["import {\n AIError,\n ContextLengthExceededError,\n InvalidRequestError,\n ProviderAuthError,\n ProviderError,\n ProviderOverloadedError,\n ProviderRateLimitError,\n ProviderTimeoutError,\n QuotaExceededError,\n} from \"@warlock.js/ai\";\n\n/**\n * Raw-error fields the wrapper reads off an AWS SDK exception. Every\n * Bedrock error is a Smithy `__BaseException` with a stable `name`\n * (`\"ThrottlingException\"`, `\"ValidationException\"`, …) and a\n * `$metadata` carrying `httpStatusCode` + `requestId`. We duck-type\n * because retries and proxies sometimes flatten the prototype chain.\n */\ntype BedrockErrorShape = {\n name?: string;\n message?: string;\n httpStatusCode?: number;\n requestId?: string;\n code?: string;\n};\n\nconst TIMEOUT_NAMES = new Set([\n \"ModelTimeoutException\",\n \"TimeoutError\",\n \"RequestTimeout\",\n \"RequestTimeoutException\",\n]);\n\n/**\n * Wrap any thrown value caught inside the Bedrock adapter into the\n * appropriate `@warlock.js/ai` `AIError` subclass.\n *\n * **Dispatch strategy.** AWS errors carry no provider machine `code`;\n * the stable identifier is the Smithy exception `name`. Dispatch keys\n * on `name`, falls back to `$metadata.httpStatusCode` when the name is\n * missing (flattened/proxied errors). `ValidationException` is split:\n * the \"input is too long / exceeds context window\" phrasing maps to\n * `ContextLengthExceededError`, everything else to\n * `InvalidRequestError`.\n *\n * `AIError` instances pass through unchanged so `catch/throw wrap(e)`\n * pipelines never double-wrap.\n *\n * @example\n * try {\n * return await this.client.send(new ConverseCommand(...));\n * } catch (thrown) {\n * throw wrapBedrockError(thrown);\n * }\n */\nexport function wrapBedrockError(thrown: unknown): AIError {\n if (thrown instanceof AIError) {\n return thrown;\n }\n\n const shape = toShape(thrown);\n const context = buildContext(shape);\n const message = shape.message ?? (thrown instanceof Error ? thrown.message : String(thrown));\n\n if (isTimeout(shape)) {\n return new ProviderTimeoutError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"AccessDeniedException\" || shape.httpStatusCode === 403) {\n return new ProviderAuthError(message, { cause: thrown, context });\n }\n\n if (shape.httpStatusCode === 401) {\n return new ProviderAuthError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ServiceQuotaExceededException\") {\n return new QuotaExceededError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ThrottlingException\" || shape.httpStatusCode === 429) {\n return new ProviderRateLimitError(message, { cause: thrown, context });\n }\n\n // Converse `ServiceUnavailableException` (503): the service is\n // temporarily unable to serve the request — retry later.\n // https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html\n if (shape.name === \"ServiceUnavailableException\" || shape.httpStatusCode === 503) {\n return new ProviderOverloadedError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ValidationException\") {\n if (/too long|context window|maximum context|exceeds the maximum/i.test(message)) {\n return new ContextLengthExceededError(message, { cause: thrown, context });\n }\n\n return new InvalidRequestError(message, { cause: thrown, context });\n }\n\n if (\n shape.name === \"ResourceNotFoundException\" ||\n shape.name === \"ConflictException\" ||\n isClientStatus(shape.httpStatusCode)\n ) {\n return new InvalidRequestError(message, { cause: thrown, context });\n }\n\n return new ProviderError(message, { cause: thrown, context });\n}\n\n/**\n * Read the raw error shape without depending on `instanceof`. AWS\n * exceptions expose `$metadata`; plain/proxied errors may carry\n * `status` / `code` instead.\n */\nfunction toShape(thrown: unknown): BedrockErrorShape {\n if (typeof thrown !== \"object\" || thrown === null) {\n return {};\n }\n\n const raw = thrown as Record<string, unknown>;\n const metadata = raw.$metadata as { httpStatusCode?: number; requestId?: string } | undefined;\n\n return {\n name: typeof raw.name === \"string\" ? raw.name : undefined,\n message: typeof raw.message === \"string\" ? raw.message : undefined,\n httpStatusCode:\n metadata && typeof metadata.httpStatusCode === \"number\"\n ? metadata.httpStatusCode\n : typeof raw.status === \"number\"\n ? (raw.status as number)\n : undefined,\n requestId: metadata && typeof metadata.requestId === \"string\" ? metadata.requestId : undefined,\n code: typeof raw.code === \"string\" ? raw.code : undefined,\n };\n}\n\n/**\n * Decide whether the error is a timeout. Bedrock surfaces\n * `ModelTimeoutException`; the AWS transport layer surfaces\n * `TimeoutError` / `ETIMEDOUT` / `ECONNABORTED`.\n */\nfunction isTimeout(shape: BedrockErrorShape): boolean {\n if (shape.name && TIMEOUT_NAMES.has(shape.name)) {\n return true;\n }\n\n return shape.code === \"ETIMEDOUT\" || shape.code === \"ECONNABORTED\";\n}\n\n/** True for HTTP 4xx — a client-side request problem, not a server fault. */\nfunction isClientStatus(status: number | undefined): boolean {\n return typeof status === \"number\" && status >= 400 && status < 500;\n}\n\n/**\n * Attach the raw diagnostic fields to `error.context`. The Smithy\n * exception `name` is the closest thing Bedrock has to a stable error\n * code, so it lands on `context.code`.\n */\nfunction buildContext(shape: BedrockErrorShape): Record<string, unknown> {\n const context: Record<string, unknown> = {};\n\n if (shape.httpStatusCode !== undefined) {\n context.status = shape.httpStatusCode;\n }\n\n if (shape.name) {\n context.code = shape.name;\n }\n\n if (shape.requestId) {\n context.requestId = shape.requestId;\n }\n\n return context;\n}\n"],"mappings":";;;AA2BA,MAAM,
|
|
1
|
+
{"version":3,"file":"wrap-bedrock-error.mjs","names":[],"sources":["../../../../../../../../packages/ai-bedrock/src/utils/wrap-bedrock-error.ts"],"sourcesContent":["import {\n AIError,\n ContextLengthExceededError,\n InvalidRequestError,\n ProviderAuthError,\n ProviderError,\n ProviderOverloadedError,\n ProviderRateLimitError,\n ProviderTimeoutError,\n QuotaExceededError,\n} from \"@warlock.js/ai\";\n\n/**\n * Raw-error fields the wrapper reads off an AWS SDK exception. Every\n * Bedrock error is a Smithy `__BaseException` with a stable `name`\n * (`\"ThrottlingException\"`, `\"ValidationException\"`, …) and a\n * `$metadata` carrying `httpStatusCode` + `requestId`. We duck-type\n * because retries and proxies sometimes flatten the prototype chain.\n */\ntype BedrockErrorShape = {\n name?: string;\n message?: string;\n httpStatusCode?: number;\n requestId?: string;\n code?: string;\n};\n\nconst TIMEOUT_NAMES = new Set([\n \"ModelTimeoutException\",\n \"TimeoutError\",\n \"RequestTimeout\",\n \"RequestTimeoutException\",\n]);\n\n/**\n * Wrap any thrown value caught inside the Bedrock adapter into the\n * appropriate `@warlock.js/ai` `AIError` subclass.\n *\n * **Dispatch strategy.** AWS errors carry no provider machine `code`;\n * the stable identifier is the Smithy exception `name`. Dispatch keys\n * on `name`, falls back to `$metadata.httpStatusCode` when the name is\n * missing (flattened/proxied errors). `ValidationException` is split:\n * the \"input is too long / exceeds context window\" phrasing maps to\n * `ContextLengthExceededError`, everything else to\n * `InvalidRequestError`.\n *\n * `AIError` instances pass through unchanged so `catch/throw wrap(e)`\n * pipelines never double-wrap.\n *\n * @example\n * try {\n * return await this.client.send(new ConverseCommand(...));\n * } catch (thrown) {\n * throw wrapBedrockError(thrown);\n * }\n */\nexport function wrapBedrockError(thrown: unknown): AIError {\n if (thrown instanceof AIError) {\n return thrown;\n }\n\n const shape = toShape(thrown);\n const context = buildContext(shape);\n const message = shape.message ?? (thrown instanceof Error ? thrown.message : String(thrown));\n\n if (isTimeout(shape)) {\n return new ProviderTimeoutError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"AccessDeniedException\" || shape.httpStatusCode === 403) {\n return new ProviderAuthError(message, { cause: thrown, context });\n }\n\n if (shape.httpStatusCode === 401) {\n return new ProviderAuthError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ServiceQuotaExceededException\") {\n return new QuotaExceededError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ThrottlingException\" || shape.httpStatusCode === 429) {\n return new ProviderRateLimitError(message, { cause: thrown, context });\n }\n\n // Converse `ServiceUnavailableException` (503): the service is\n // temporarily unable to serve the request — retry later.\n // https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html\n if (shape.name === \"ServiceUnavailableException\" || shape.httpStatusCode === 503) {\n return new ProviderOverloadedError(message, { cause: thrown, context });\n }\n\n if (shape.name === \"ValidationException\") {\n if (/too long|context window|maximum context|exceeds the maximum/i.test(message)) {\n return new ContextLengthExceededError(message, { cause: thrown, context });\n }\n\n return new InvalidRequestError(message, { cause: thrown, context });\n }\n\n if (\n shape.name === \"ResourceNotFoundException\" ||\n shape.name === \"ConflictException\" ||\n isClientStatus(shape.httpStatusCode)\n ) {\n return new InvalidRequestError(message, { cause: thrown, context });\n }\n\n return new ProviderError(message, { cause: thrown, context });\n}\n\n/**\n * Read the raw error shape without depending on `instanceof`. AWS\n * exceptions expose `$metadata`; plain/proxied errors may carry\n * `status` / `code` instead.\n */\nfunction toShape(thrown: unknown): BedrockErrorShape {\n if (typeof thrown !== \"object\" || thrown === null) {\n return {};\n }\n\n const raw = thrown as Record<string, unknown>;\n const metadata = raw.$metadata as { httpStatusCode?: number; requestId?: string } | undefined;\n\n return {\n name: typeof raw.name === \"string\" ? raw.name : undefined,\n message: typeof raw.message === \"string\" ? raw.message : undefined,\n httpStatusCode:\n metadata && typeof metadata.httpStatusCode === \"number\"\n ? metadata.httpStatusCode\n : typeof raw.status === \"number\"\n ? (raw.status as number)\n : undefined,\n requestId: metadata && typeof metadata.requestId === \"string\" ? metadata.requestId : undefined,\n code: typeof raw.code === \"string\" ? raw.code : undefined,\n };\n}\n\n/**\n * Decide whether the error is a timeout. Bedrock surfaces\n * `ModelTimeoutException`; the AWS transport layer surfaces\n * `TimeoutError` / `ETIMEDOUT` / `ECONNABORTED`.\n */\nfunction isTimeout(shape: BedrockErrorShape): boolean {\n if (shape.name && TIMEOUT_NAMES.has(shape.name)) {\n return true;\n }\n\n return shape.code === \"ETIMEDOUT\" || shape.code === \"ECONNABORTED\";\n}\n\n/** True for HTTP 4xx — a client-side request problem, not a server fault. */\nfunction isClientStatus(status: number | undefined): boolean {\n return typeof status === \"number\" && status >= 400 && status < 500;\n}\n\n/**\n * Attach the raw diagnostic fields to `error.context`. The Smithy\n * exception `name` is the closest thing Bedrock has to a stable error\n * code, so it lands on `context.code`.\n */\nfunction buildContext(shape: BedrockErrorShape): Record<string, unknown> {\n const context: Record<string, unknown> = {};\n\n if (shape.httpStatusCode !== undefined) {\n context.status = shape.httpStatusCode;\n }\n\n if (shape.name) {\n context.code = shape.name;\n }\n\n if (shape.requestId) {\n context.requestId = shape.requestId;\n }\n\n return context;\n}\n"],"mappings":";;;AA2BA,MAAM,gCAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;AAwBD,SAAgB,iBAAiB,QAA0B;CACzD,IAAI,kBAAkB,SACpB,OAAO;CAGT,MAAM,QAAQ,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AAM,MAAM;CACZ,MAAM,WAAW,IAAI;CAErB,OAAO;EACL,MAAM,OAAO,IAAI,SAAS,WAAW,IAAI,OAAO;EAChD,SAAS,OAAO,IAAI,YAAY,WAAW,IAAI,UAAU;EACzD,gBACE,YAAY,OAAO,SAAS,mBAAmB,WAC3C,SAAS,iBACT,OAAO,IAAI,WAAW,WACnB,IAAI,SACL;EACR,WAAW,YAAY,OAAO,SAAS,cAAc,WAAW,SAAS,YAAY;EACrF,MAAM,OAAO,IAAI,SAAS,WAAW,IAAI,OAAO;CAClD;AACF;;;;;;AAOA,SAAS,UAAU,OAAmC;CACpD,IAAI,MAAM,QAAQ,cAAc,IAAI,MAAM,IAAI,GAC5C,OAAO;CAGT,OAAO,MAAM,SAAS,eAAe,MAAM,SAAS;AACtD;;AAGA,SAAS,eAAe,QAAqC;CAC3D,OAAO,OAAO,WAAW,YAAY,UAAU,OAAO,SAAS;AACjE;;;;;;AAOA,SAAS,aAAa,OAAmD;CACvE,MAAM,UAAmC,CAAC;CAE1C,IAAI,MAAM,mBAAmB,QAC3B,QAAQ,SAAS,MAAM;CAGzB,IAAI,MAAM,MACR,QAAQ,OAAO,MAAM;CAGvB,IAAI,MAAM,WACR,QAAQ,YAAY,MAAM;CAG5B,OAAO;AACT"}
|
package/llms-full.txt
CHANGED
|
@@ -280,6 +280,13 @@ Converse messages, system blocks, tool configuration and
|
|
|
280
280
|
Availability depends on the model and region; provider failures use the adapter's
|
|
281
281
|
normal typed errors. `sdk.count(text)` remains a separate offline estimate.
|
|
282
282
|
|
|
283
|
+
For budget preflight, `countInputTokens(model, messages, { tools })` from
|
|
284
|
+
`@warlock.js/ai` returns `{ tokens, source }`. It estimates only when native
|
|
285
|
+
counting is absent or explicitly throws `InvalidRequestError` with
|
|
286
|
+
`reason: "count-unsupported"`; this adapter preserves that signal. System and
|
|
287
|
+
tools are supported natively. Ordinary validation, auth, network and rate-limit
|
|
288
|
+
errors propagate. See the cost/budget guide for reserve mode.
|
|
289
|
+
|
|
283
290
|
```ts
|
|
284
291
|
if (model.countTokens) {
|
|
285
292
|
const inputTokens = await model.countTokens(messages, options);
|
|
@@ -309,4 +316,14 @@ as user context when it replaces the first non-system turn.
|
|
|
309
316
|
Adjacent-turn normalization preserves empty histories and separate system prompts
|
|
310
317
|
without inserting synthetic conversation turns.
|
|
311
318
|
|
|
319
|
+
## Hosted-search accounting limit
|
|
320
|
+
|
|
321
|
+
Bedrock Converse's [TokenUsage schema](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_TokenUsage.html)
|
|
322
|
+
and the installed SDK expose token/cache counts, with no hosted-tool request
|
|
323
|
+
counter (verified 2026-10-18). `usage.serverToolUse` therefore remains absent;
|
|
324
|
+
no count or search fee is inferred from `server_tool_use` system-tool blocks.
|
|
325
|
+
Hosted system tools continue to stay outside function dispatch. Direct
|
|
326
|
+
Anthropic counters are not assumed to exist on Converse. Supply fees only when
|
|
327
|
+
your own verified metering establishes the billing unit.
|
|
328
|
+
|
|
312
329
|
|
package/package.json
CHANGED
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"directory": "packages/ai-bedrock"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@warlock.js/ai": "5.
|
|
18
|
+
"@warlock.js/ai": "5.32.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@aws-sdk/client-bedrock-runtime": "^3.1048.0",
|
|
22
|
-
"@warlock.js/logger": "5.
|
|
22
|
+
"@warlock.js/logger": "5.32.0"
|
|
23
23
|
},
|
|
24
|
-
"version": "5.
|
|
24
|
+
"version": "5.32.0",
|
|
25
25
|
"main": "./cjs/index.cjs",
|
|
26
26
|
"module": "./esm/index.mjs",
|
|
27
27
|
"types": "./esm/index.d.mts",
|
|
@@ -272,6 +272,13 @@ Converse messages, system blocks, tool configuration and
|
|
|
272
272
|
Availability depends on the model and region; provider failures use the adapter's
|
|
273
273
|
normal typed errors. `sdk.count(text)` remains a separate offline estimate.
|
|
274
274
|
|
|
275
|
+
For budget preflight, `countInputTokens(model, messages, { tools })` from
|
|
276
|
+
`@warlock.js/ai` returns `{ tokens, source }`. It estimates only when native
|
|
277
|
+
counting is absent or explicitly throws `InvalidRequestError` with
|
|
278
|
+
`reason: "count-unsupported"`; this adapter preserves that signal. System and
|
|
279
|
+
tools are supported natively. Ordinary validation, auth, network and rate-limit
|
|
280
|
+
errors propagate. See the cost/budget guide for reserve mode.
|
|
281
|
+
|
|
275
282
|
```ts
|
|
276
283
|
if (model.countTokens) {
|
|
277
284
|
const inputTokens = await model.countTokens(messages, options);
|
|
@@ -300,3 +307,13 @@ as user context when it replaces the first non-system turn.
|
|
|
300
307
|
|
|
301
308
|
Adjacent-turn normalization preserves empty histories and separate system prompts
|
|
302
309
|
without inserting synthetic conversation turns.
|
|
310
|
+
|
|
311
|
+
## Hosted-search accounting limit
|
|
312
|
+
|
|
313
|
+
Bedrock Converse's [TokenUsage schema](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_TokenUsage.html)
|
|
314
|
+
and the installed SDK expose token/cache counts, with no hosted-tool request
|
|
315
|
+
counter (verified 2026-10-18). `usage.serverToolUse` therefore remains absent;
|
|
316
|
+
no count or search fee is inferred from `server_tool_use` system-tool blocks.
|
|
317
|
+
Hosted system tools continue to stay outside function dispatch. Direct
|
|
318
|
+
Anthropic counters are not assumed to exist on Converse. Supply fees only when
|
|
319
|
+
your own verified metering establishes the billing unit.
|