@ai-sdk/amazon-bedrock 3.0.0-canary.8 → 3.0.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/dist/index.js CHANGED
@@ -26,11 +26,12 @@ __export(src_exports, {
26
26
  module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // src/bedrock-provider.ts
29
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
29
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
30
+ var import_internal2 = require("@ai-sdk/anthropic/internal");
30
31
 
31
32
  // src/bedrock-chat-language-model.ts
32
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
33
- var import_zod3 = require("zod");
33
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
34
+ var import_v43 = require("zod/v4");
34
35
 
35
36
  // src/bedrock-api-types.ts
36
37
  var BEDROCK_CACHE_POINT = {
@@ -48,27 +49,44 @@ var BEDROCK_STOP_REASONS = [
48
49
  "tool-calls",
49
50
  "tool_use"
50
51
  ];
52
+ var BEDROCK_IMAGE_MIME_TYPES = {
53
+ "image/jpeg": "jpeg",
54
+ "image/png": "png",
55
+ "image/gif": "gif",
56
+ "image/webp": "webp"
57
+ };
58
+ var BEDROCK_DOCUMENT_MIME_TYPES = {
59
+ "application/pdf": "pdf",
60
+ "text/csv": "csv",
61
+ "application/msword": "doc",
62
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
63
+ "application/vnd.ms-excel": "xls",
64
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
65
+ "text/html": "html",
66
+ "text/plain": "txt",
67
+ "text/markdown": "md"
68
+ };
51
69
 
52
70
  // src/bedrock-chat-options.ts
53
- var import_zod = require("zod");
54
- var bedrockProviderOptions = import_zod.z.object({
71
+ var import_v4 = require("zod/v4");
72
+ var bedrockProviderOptions = import_v4.z.object({
55
73
  /**
56
74
  * Additional inference parameters that the model supports,
57
75
  * beyond the base set of inference parameters that Converse
58
76
  * supports in the inferenceConfig field
59
77
  */
60
- additionalModelRequestFields: import_zod.z.record(import_zod.z.any()).optional(),
61
- reasoningConfig: import_zod.z.object({
62
- type: import_zod.z.union([import_zod.z.literal("enabled"), import_zod.z.literal("disabled")]).nullish(),
63
- budgetTokens: import_zod.z.number().nullish()
64
- }).nullish()
78
+ additionalModelRequestFields: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
79
+ reasoningConfig: import_v4.z.object({
80
+ type: import_v4.z.union([import_v4.z.literal("enabled"), import_v4.z.literal("disabled")]).optional(),
81
+ budgetTokens: import_v4.z.number().optional()
82
+ }).optional()
65
83
  });
66
84
 
67
85
  // src/bedrock-error.ts
68
- var import_zod2 = require("zod");
69
- var BedrockErrorSchema = import_zod2.z.object({
70
- message: import_zod2.z.string(),
71
- type: import_zod2.z.string().nullish()
86
+ var import_v42 = require("zod/v4");
87
+ var BedrockErrorSchema = import_v42.z.object({
88
+ message: import_v42.z.string(),
89
+ type: import_v42.z.string().nullish()
72
90
  });
73
91
 
74
92
  // src/bedrock-event-stream-response-handler.ts
@@ -88,7 +106,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
88
106
  responseHeaders,
89
107
  value: response.body.pipeThrough(
90
108
  new TransformStream({
91
- transform(chunk, controller) {
109
+ async transform(chunk, controller) {
92
110
  var _a, _b;
93
111
  const newBuffer = new Uint8Array(buffer.length + chunk.length);
94
112
  newBuffer.set(buffer);
@@ -109,7 +127,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
109
127
  buffer = buffer.slice(totalLength);
110
128
  if (((_a = decoded.headers[":message-type"]) == null ? void 0 : _a.value) === "event") {
111
129
  const data = textDecoder.decode(decoded.body);
112
- const parsedDataResult = (0, import_provider_utils.safeParseJSON)({ text: data });
130
+ const parsedDataResult = await (0, import_provider_utils.safeParseJSON)({ text: data });
113
131
  if (!parsedDataResult.success) {
114
132
  controller.enqueue(parsedDataResult);
115
133
  break;
@@ -118,7 +136,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
118
136
  let wrappedData = {
119
137
  [(_b = decoded.headers[":event-type"]) == null ? void 0 : _b.value]: parsedDataResult.value
120
138
  };
121
- const validatedWrappedData = (0, import_provider_utils.safeValidateTypes)({
139
+ const validatedWrappedData = await (0, import_provider_utils.safeValidateTypes)({
122
140
  value: wrappedData,
123
141
  schema: chunkSchema
124
142
  });
@@ -144,87 +162,155 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
144
162
 
145
163
  // src/bedrock-prepare-tools.ts
146
164
  var import_provider2 = require("@ai-sdk/provider");
165
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
166
+ var import_internal = require("@ai-sdk/anthropic/internal");
147
167
  function prepareTools({
148
168
  tools,
149
- toolChoice
169
+ toolChoice,
170
+ modelId
150
171
  }) {
151
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
152
- if (tools == null) {
172
+ const toolWarnings = [];
173
+ const betas = /* @__PURE__ */ new Set();
174
+ if (tools == null || tools.length === 0) {
153
175
  return {
154
- toolConfig: { tools: void 0, toolChoice: void 0 },
155
- toolWarnings: []
176
+ toolConfig: {},
177
+ additionalTools: void 0,
178
+ betas,
179
+ toolWarnings
156
180
  };
157
181
  }
158
- const toolWarnings = [];
159
- const bedrockTools = [];
160
- for (const tool of tools) {
161
- if (tool.type === "provider-defined") {
162
- toolWarnings.push({ type: "unsupported-tool", tool });
163
- } else {
164
- bedrockTools.push({
165
- toolSpec: {
166
- name: tool.name,
167
- description: tool.description,
168
- inputSchema: {
169
- json: tool.parameters
170
- }
171
- }
182
+ const supportedTools = tools.filter((tool) => {
183
+ if (tool.type === "provider-defined" && tool.id === "anthropic.web_search_20250305") {
184
+ toolWarnings.push({
185
+ type: "unsupported-tool",
186
+ tool,
187
+ details: "The web_search_20250305 tool is not supported on Amazon Bedrock."
172
188
  });
189
+ return false;
173
190
  }
174
- }
175
- if (toolChoice == null) {
191
+ return true;
192
+ });
193
+ if (supportedTools.length === 0) {
176
194
  return {
177
- toolConfig: { tools: bedrockTools, toolChoice: void 0 },
195
+ toolConfig: {},
196
+ additionalTools: void 0,
197
+ betas,
178
198
  toolWarnings
179
199
  };
180
200
  }
181
- const type = toolChoice.type;
182
- switch (type) {
183
- case "auto":
184
- return {
185
- toolConfig: { tools: bedrockTools, toolChoice: { auto: {} } },
186
- toolWarnings
187
- };
188
- case "required":
189
- return {
190
- toolConfig: { tools: bedrockTools, toolChoice: { any: {} } },
191
- toolWarnings
192
- };
193
- case "none":
194
- return {
195
- toolConfig: { tools: void 0, toolChoice: void 0 },
196
- toolWarnings
197
- };
198
- case "tool":
199
- return {
200
- toolConfig: {
201
- tools: bedrockTools,
202
- toolChoice: { tool: { name: toolChoice.toolName } }
203
- },
204
- toolWarnings
201
+ const isAnthropicModel = modelId.includes("anthropic.");
202
+ const providerDefinedTools = supportedTools.filter(
203
+ (t) => t.type === "provider-defined"
204
+ );
205
+ const functionTools = supportedTools.filter((t) => t.type === "function");
206
+ let additionalTools = void 0;
207
+ const bedrockTools = [];
208
+ const usingAnthropicTools = isAnthropicModel && providerDefinedTools.length > 0;
209
+ if (usingAnthropicTools) {
210
+ if (functionTools.length > 0) {
211
+ toolWarnings.push({
212
+ type: "unsupported-setting",
213
+ setting: "tools",
214
+ details: "Mixed Anthropic provider-defined tools and standard function tools are not supported in a single call to Bedrock. Only Anthropic tools will be used."
215
+ });
216
+ }
217
+ const {
218
+ toolChoice: preparedAnthropicToolChoice,
219
+ toolWarnings: anthropicToolWarnings,
220
+ betas: anthropicBetas
221
+ } = (0, import_internal.prepareTools)({
222
+ tools: providerDefinedTools,
223
+ toolChoice
224
+ });
225
+ toolWarnings.push(...anthropicToolWarnings);
226
+ anthropicBetas.forEach((beta) => betas.add(beta));
227
+ if (preparedAnthropicToolChoice) {
228
+ additionalTools = {
229
+ tool_choice: preparedAnthropicToolChoice
205
230
  };
206
- default: {
207
- const _exhaustiveCheck = type;
208
- throw new import_provider2.UnsupportedFunctionalityError({
209
- functionality: `tool choice type: ${_exhaustiveCheck}`
231
+ }
232
+ for (const tool of providerDefinedTools) {
233
+ const toolFactory = Object.values(import_internal.anthropicTools).find((factory) => {
234
+ const instance = factory({});
235
+ return instance.id === tool.id;
210
236
  });
237
+ if (toolFactory != null) {
238
+ const fullToolDefinition = toolFactory({});
239
+ bedrockTools.push({
240
+ toolSpec: {
241
+ name: tool.name,
242
+ inputSchema: {
243
+ json: (0, import_provider_utils2.asSchema)(fullToolDefinition.inputSchema).jsonSchema
244
+ }
245
+ }
246
+ });
247
+ } else {
248
+ toolWarnings.push({ type: "unsupported-tool", tool });
249
+ }
211
250
  }
251
+ } else {
252
+ for (const tool of providerDefinedTools) {
253
+ toolWarnings.push({ type: "unsupported-tool", tool });
254
+ }
255
+ }
256
+ for (const tool of functionTools) {
257
+ bedrockTools.push({
258
+ toolSpec: {
259
+ name: tool.name,
260
+ description: tool.description,
261
+ inputSchema: {
262
+ json: tool.inputSchema
263
+ }
264
+ }
265
+ });
212
266
  }
267
+ let bedrockToolChoice = void 0;
268
+ if (!usingAnthropicTools && bedrockTools.length > 0 && toolChoice) {
269
+ const type = toolChoice.type;
270
+ switch (type) {
271
+ case "auto":
272
+ bedrockToolChoice = { auto: {} };
273
+ break;
274
+ case "required":
275
+ bedrockToolChoice = { any: {} };
276
+ break;
277
+ case "none":
278
+ bedrockTools.length = 0;
279
+ bedrockToolChoice = void 0;
280
+ break;
281
+ case "tool":
282
+ bedrockToolChoice = { tool: { name: toolChoice.toolName } };
283
+ break;
284
+ default: {
285
+ const _exhaustiveCheck = type;
286
+ throw new import_provider2.UnsupportedFunctionalityError({
287
+ functionality: `tool choice type: ${_exhaustiveCheck}`
288
+ });
289
+ }
290
+ }
291
+ }
292
+ const toolConfig = bedrockTools.length > 0 ? { tools: bedrockTools, toolChoice: bedrockToolChoice } : {};
293
+ return {
294
+ toolConfig,
295
+ additionalTools,
296
+ betas,
297
+ toolWarnings
298
+ };
213
299
  }
214
300
 
215
301
  // src/convert-to-bedrock-chat-messages.ts
216
302
  var import_provider3 = require("@ai-sdk/provider");
217
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
218
- var generateFileId = (0, import_provider_utils2.createIdGenerator)({ prefix: "file", size: 16 });
303
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
219
304
  function getCachePoint(providerMetadata) {
220
305
  var _a;
221
306
  return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
222
307
  }
223
- function convertToBedrockChatMessages(prompt) {
224
- var _a, _b, _c, _d;
308
+ async function convertToBedrockChatMessages(prompt) {
225
309
  const blocks = groupIntoBlocks(prompt);
226
310
  let system = [];
227
311
  const messages = [];
312
+ let documentCounter = 0;
313
+ const generateDocumentName = () => `document-${++documentCounter}`;
228
314
  for (let i = 0; i < blocks.length; i++) {
229
315
  const block = blocks[i];
230
316
  const isLastBlock = i === blocks.length - 1;
@@ -266,21 +352,24 @@ function convertToBedrockChatMessages(prompt) {
266
352
  });
267
353
  }
268
354
  if (part.mediaType.startsWith("image/")) {
269
- const bedrockImageFormat = part.mediaType === "image/*" ? void 0 : (_b = (_a = part.mediaType) == null ? void 0 : _a.split("/")) == null ? void 0 : _b[1];
270
355
  bedrockContent.push({
271
356
  image: {
272
- format: bedrockImageFormat,
273
- source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
357
+ format: getBedrockImageFormat(part.mediaType),
358
+ source: { bytes: (0, import_provider_utils3.convertToBase64)(part.data) }
274
359
  }
275
360
  });
276
361
  } else {
362
+ if (!part.mediaType) {
363
+ throw new import_provider3.UnsupportedFunctionalityError({
364
+ functionality: "file without mime type",
365
+ message: "File mime type is required in user message part content"
366
+ });
367
+ }
277
368
  bedrockContent.push({
278
369
  document: {
279
- format: (_d = (_c = part.mediaType) == null ? void 0 : _c.split(
280
- "/"
281
- )) == null ? void 0 : _d[1],
282
- name: generateFileId(),
283
- source: { bytes: (0, import_provider_utils2.convertToBase64)(part.data) }
370
+ format: getBedrockDocumentFormat(part.mediaType),
371
+ name: generateDocumentName(),
372
+ source: { bytes: (0, import_provider_utils3.convertToBase64)(part.data) }
284
373
  }
285
374
  });
286
375
  }
@@ -291,36 +380,46 @@ function convertToBedrockChatMessages(prompt) {
291
380
  break;
292
381
  }
293
382
  case "tool": {
294
- for (let i2 = 0; i2 < content.length; i2++) {
295
- const part = content[i2];
296
- const toolResultContent = part.content != void 0 ? part.content.map((part2) => {
297
- switch (part2.type) {
298
- case "text":
299
- return {
300
- text: part2.text
301
- };
302
- case "image":
303
- if (!part2.mediaType) {
304
- throw new Error(
305
- "Image mime type is required in tool result part content"
306
- );
307
- }
308
- const format = part2.mediaType.split("/")[1];
309
- if (!isBedrockImageFormat(format)) {
310
- throw new Error(
311
- `Unsupported image format: ${format}`
312
- );
313
- }
314
- return {
315
- image: {
316
- format,
317
- source: {
318
- bytes: part2.data
383
+ for (const part of content) {
384
+ let toolResultContent;
385
+ const output = part.output;
386
+ switch (output.type) {
387
+ case "content": {
388
+ toolResultContent = output.value.map((contentPart) => {
389
+ switch (contentPart.type) {
390
+ case "text":
391
+ return { text: contentPart.text };
392
+ case "media":
393
+ if (!contentPart.mediaType.startsWith("image/")) {
394
+ throw new import_provider3.UnsupportedFunctionalityError({
395
+ functionality: `media type: ${contentPart.mediaType}`
396
+ });
319
397
  }
320
- }
321
- };
398
+ const format = getBedrockImageFormat(
399
+ contentPart.mediaType
400
+ );
401
+ return {
402
+ image: {
403
+ format,
404
+ source: { bytes: contentPart.data }
405
+ }
406
+ };
407
+ }
408
+ });
409
+ break;
322
410
  }
323
- }) : [{ text: JSON.stringify(part.result) }];
411
+ case "text":
412
+ case "error-text":
413
+ toolResultContent = [{ text: output.value }];
414
+ break;
415
+ case "json":
416
+ case "error-json":
417
+ default:
418
+ toolResultContent = [
419
+ { text: JSON.stringify(output.value) }
420
+ ];
421
+ break;
422
+ }
324
423
  bedrockContent.push({
325
424
  toolResult: {
326
425
  toolUseId: part.toolCallId,
@@ -369,32 +468,39 @@ function convertToBedrockChatMessages(prompt) {
369
468
  break;
370
469
  }
371
470
  case "reasoning": {
372
- bedrockContent.push({
373
- reasoningContent: {
374
- reasoningText: {
375
- // trim the last text part if it's the last message in the block
376
- // because Bedrock does not allow trailing whitespace
377
- // in pre-filled assistant responses
378
- text: trimIfLast(
379
- isLastBlock,
380
- isLastMessage,
381
- isLastContentPart,
382
- part.text
383
- ),
384
- signature: part.signature
385
- }
386
- }
471
+ const reasoningMetadata = await (0, import_provider_utils3.parseProviderOptions)({
472
+ provider: "bedrock",
473
+ providerOptions: part.providerOptions,
474
+ schema: bedrockReasoningMetadataSchema
387
475
  });
388
- break;
389
- }
390
- case "redacted-reasoning": {
391
- bedrockContent.push({
392
- reasoningContent: {
393
- redactedReasoning: {
394
- data: part.data
395
- }
476
+ if (reasoningMetadata != null) {
477
+ if (reasoningMetadata.signature != null) {
478
+ bedrockContent.push({
479
+ reasoningContent: {
480
+ reasoningText: {
481
+ // trim the last text part if it's the last message in the block
482
+ // because Bedrock does not allow trailing whitespace
483
+ // in pre-filled assistant responses
484
+ text: trimIfLast(
485
+ isLastBlock,
486
+ isLastMessage,
487
+ isLastContentPart,
488
+ part.text
489
+ ),
490
+ signature: reasoningMetadata.signature
491
+ }
492
+ }
493
+ });
494
+ } else if (reasoningMetadata.redactedData != null) {
495
+ bedrockContent.push({
496
+ reasoningContent: {
497
+ redactedReasoning: {
498
+ data: reasoningMetadata.redactedData
499
+ }
500
+ }
501
+ });
396
502
  }
397
- });
503
+ }
398
504
  break;
399
505
  }
400
506
  case "tool-call": {
@@ -402,7 +508,7 @@ function convertToBedrockChatMessages(prompt) {
402
508
  toolUse: {
403
509
  toolUseId: part.toolCallId,
404
510
  name: part.toolName,
405
- input: part.args
511
+ input: part.input
406
512
  }
407
513
  });
408
514
  break;
@@ -424,8 +530,31 @@ function convertToBedrockChatMessages(prompt) {
424
530
  }
425
531
  return { system, messages };
426
532
  }
427
- function isBedrockImageFormat(format) {
428
- return ["jpeg", "png", "gif"].includes(format);
533
+ function getBedrockImageFormat(mimeType) {
534
+ if (!mimeType) {
535
+ throw new import_provider3.UnsupportedFunctionalityError({
536
+ functionality: "image without mime type",
537
+ message: "Image mime type is required in user message part content"
538
+ });
539
+ }
540
+ const format = BEDROCK_IMAGE_MIME_TYPES[mimeType];
541
+ if (!format) {
542
+ throw new import_provider3.UnsupportedFunctionalityError({
543
+ functionality: `image mime type: ${mimeType}`,
544
+ message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(", ")}`
545
+ });
546
+ }
547
+ return format;
548
+ }
549
+ function getBedrockDocumentFormat(mimeType) {
550
+ const format = BEDROCK_DOCUMENT_MIME_TYPES[mimeType];
551
+ if (!format) {
552
+ throw new import_provider3.UnsupportedFunctionalityError({
553
+ functionality: `file mime type: ${mimeType}`,
554
+ message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(", ")}`
555
+ });
556
+ }
557
+ return format;
429
558
  }
430
559
  function trimIfLast(isLastBlock, isLastMessage, isLastContentPart, text) {
431
560
  return isLastBlock && isLastMessage && isLastContentPart ? text.trim() : text;
@@ -502,10 +631,11 @@ var BedrockChatLanguageModel = class {
502
631
  this.config = config;
503
632
  this.specificationVersion = "v2";
504
633
  this.provider = "amazon-bedrock";
505
- this.defaultObjectGenerationMode = "tool";
506
- this.supportsImageUrls = false;
634
+ this.supportedUrls = {
635
+ // no supported urls for bedrock
636
+ };
507
637
  }
508
- getArgs({
638
+ async getArgs({
509
639
  prompt,
510
640
  maxOutputTokens,
511
641
  temperature,
@@ -520,8 +650,8 @@ var BedrockChatLanguageModel = class {
520
650
  toolChoice,
521
651
  providerOptions
522
652
  }) {
523
- var _a, _b, _c, _d, _e;
524
- const bedrockOptions = (_a = (0, import_provider_utils3.parseProviderOptions)({
653
+ var _a, _b, _c, _d, _e, _f;
654
+ const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
525
655
  provider: "bedrock",
526
656
  providerOptions,
527
657
  schema: bedrockProviderOptions
@@ -551,14 +681,39 @@ var BedrockChatLanguageModel = class {
551
681
  setting: "topK"
552
682
  });
553
683
  }
554
- if (responseFormat != null && responseFormat.type !== "text") {
684
+ if (responseFormat != null && responseFormat.type !== "text" && responseFormat.type !== "json") {
555
685
  warnings.push({
556
686
  type: "unsupported-setting",
557
687
  setting: "responseFormat",
558
- details: "JSON response format is not supported."
688
+ details: "Only text and json response formats are supported."
559
689
  });
560
690
  }
561
- const { system, messages } = convertToBedrockChatMessages(prompt);
691
+ if (tools != null && (responseFormat == null ? void 0 : responseFormat.type) === "json") {
692
+ if (tools.length > 0) {
693
+ warnings.push({
694
+ type: "other",
695
+ message: "JSON response format does not support tools. The provided tools are ignored."
696
+ });
697
+ }
698
+ }
699
+ const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
700
+ type: "function",
701
+ name: "json",
702
+ description: "Respond with a JSON object.",
703
+ inputSchema: responseFormat.schema
704
+ } : void 0;
705
+ const { toolConfig, additionalTools, toolWarnings, betas } = prepareTools({
706
+ tools: jsonResponseTool ? [jsonResponseTool, ...tools != null ? tools : []] : tools,
707
+ toolChoice: jsonResponseTool != null ? { type: "tool", toolName: jsonResponseTool.name } : toolChoice,
708
+ modelId: this.modelId
709
+ });
710
+ warnings.push(...toolWarnings);
711
+ if (additionalTools) {
712
+ bedrockOptions.additionalModelRequestFields = {
713
+ ...bedrockOptions.additionalModelRequestFields,
714
+ ...additionalTools
715
+ };
716
+ }
562
717
  const isThinking = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled";
563
718
  const thinkingBudget = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.budgetTokens;
564
719
  const inferenceConfig = {
@@ -575,7 +730,7 @@ var BedrockChatLanguageModel = class {
575
730
  }
576
731
  bedrockOptions.additionalModelRequestFields = {
577
732
  ...bedrockOptions.additionalModelRequestFields,
578
- reasoningConfig: {
733
+ thinking: {
579
734
  type: (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type,
580
735
  budget_tokens: thinkingBudget
581
736
  }
@@ -597,7 +752,34 @@ var BedrockChatLanguageModel = class {
597
752
  details: "topP is not supported when thinking is enabled"
598
753
  });
599
754
  }
600
- const { toolConfig, toolWarnings } = prepareTools({ tools, toolChoice });
755
+ const hasAnyTools = ((_f = (_e = toolConfig.tools) == null ? void 0 : _e.length) != null ? _f : 0) > 0 || additionalTools;
756
+ let filteredPrompt = prompt;
757
+ if (!hasAnyTools) {
758
+ const hasToolContent = prompt.some(
759
+ (message) => "content" in message && Array.isArray(message.content) && message.content.some(
760
+ (part) => part.type === "tool-call" || part.type === "tool-result"
761
+ )
762
+ );
763
+ if (hasToolContent) {
764
+ filteredPrompt = prompt.map(
765
+ (message) => message.role === "system" ? message : {
766
+ ...message,
767
+ content: message.content.filter(
768
+ (part) => part.type !== "tool-call" && part.type !== "tool-result"
769
+ )
770
+ }
771
+ ).filter(
772
+ (message) => message.role === "system" || message.content.length > 0
773
+ );
774
+ warnings.push({
775
+ type: "unsupported-setting",
776
+ setting: "toolContent",
777
+ details: "Tool calls and results removed from conversation because Bedrock does not support tool content without active tools."
778
+ });
779
+ }
780
+ }
781
+ const { system, messages } = await convertToBedrockChatMessages(filteredPrompt);
782
+ const { reasoningConfig: _, ...filteredBedrockOptions } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
601
783
  return {
602
784
  command: {
603
785
  system,
@@ -606,31 +788,45 @@ var BedrockChatLanguageModel = class {
606
788
  ...Object.keys(inferenceConfig).length > 0 && {
607
789
  inferenceConfig
608
790
  },
609
- ...providerOptions == null ? void 0 : providerOptions.bedrock,
610
- ...((_e = toolConfig.tools) == null ? void 0 : _e.length) ? { toolConfig } : {}
791
+ ...filteredBedrockOptions,
792
+ ...toolConfig.tools !== void 0 && toolConfig.tools.length > 0 ? { toolConfig } : {}
611
793
  },
612
- warnings: [...warnings, ...toolWarnings]
794
+ warnings,
795
+ usesJsonResponseTool: jsonResponseTool != null,
796
+ betas
613
797
  };
614
798
  }
799
+ async getHeaders({
800
+ betas,
801
+ headers
802
+ }) {
803
+ return (0, import_provider_utils4.combineHeaders)(
804
+ await (0, import_provider_utils4.resolve)(this.config.headers),
805
+ betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
806
+ headers
807
+ );
808
+ }
615
809
  async doGenerate(options) {
616
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
617
- const { command: args, warnings } = this.getArgs(options);
810
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
811
+ const {
812
+ command: args,
813
+ warnings,
814
+ usesJsonResponseTool,
815
+ betas
816
+ } = await this.getArgs(options);
618
817
  const url = `${this.getUrl(this.modelId)}/converse`;
619
- const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
818
+ const { value: response, responseHeaders } = await (0, import_provider_utils4.postJsonToApi)({
620
819
  url,
621
- headers: (0, import_provider_utils3.combineHeaders)(
622
- await (0, import_provider_utils3.resolve)(this.config.headers),
623
- options.headers
624
- ),
820
+ headers: await this.getHeaders({ betas, headers: options.headers }),
625
821
  body: args,
626
- failedResponseHandler: (0, import_provider_utils3.createJsonErrorResponseHandler)({
822
+ failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
627
823
  errorSchema: BedrockErrorSchema,
628
824
  errorToMessage: (error) => {
629
825
  var _a2;
630
826
  return `${(_a2 = error.message) != null ? _a2 : "Unknown error"}`;
631
827
  }
632
828
  }),
633
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
829
+ successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
634
830
  BedrockResponseSchema
635
831
  ),
636
832
  abortSignal: options.abortSignal,
@@ -639,49 +835,60 @@ var BedrockChatLanguageModel = class {
639
835
  const content = [];
640
836
  for (const part of response.output.message.content) {
641
837
  if (part.text) {
642
- content.push({ type: "text", text: part.text });
838
+ if (!usesJsonResponseTool) {
839
+ content.push({ type: "text", text: part.text });
840
+ }
643
841
  }
644
842
  if (part.reasoningContent) {
645
843
  if ("reasoningText" in part.reasoningContent) {
646
- content.push({
844
+ const reasoning = {
647
845
  type: "reasoning",
648
- reasoningType: "text",
649
846
  text: part.reasoningContent.reasoningText.text
650
- });
847
+ };
651
848
  if (part.reasoningContent.reasoningText.signature) {
652
- content.push({
653
- type: "reasoning",
654
- reasoningType: "signature",
655
- signature: part.reasoningContent.reasoningText.signature
656
- });
849
+ reasoning.providerMetadata = {
850
+ bedrock: {
851
+ signature: part.reasoningContent.reasoningText.signature
852
+ }
853
+ };
657
854
  }
855
+ content.push(reasoning);
658
856
  } else if ("redactedReasoning" in part.reasoningContent) {
659
857
  content.push({
660
858
  type: "reasoning",
661
- reasoningType: "redacted",
662
- data: (_a = part.reasoningContent.redactedReasoning.data) != null ? _a : ""
859
+ text: "",
860
+ providerMetadata: {
861
+ bedrock: {
862
+ redactedData: (_a = part.reasoningContent.redactedReasoning.data) != null ? _a : ""
863
+ }
864
+ }
663
865
  });
664
866
  }
665
867
  }
666
868
  if (part.toolUse) {
667
- content.push({
668
- type: "tool-call",
669
- toolCallType: "function",
670
- toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
671
- toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
672
- args: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
673
- });
869
+ content.push(
870
+ // when a json response tool is used, the tool call becomes the text:
871
+ usesJsonResponseTool ? {
872
+ type: "text",
873
+ text: JSON.stringify(part.toolUse.input)
874
+ } : {
875
+ type: "tool-call",
876
+ toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
877
+ toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
878
+ input: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
879
+ }
880
+ );
674
881
  }
675
882
  }
676
- const providerMetadata = response.trace || response.usage ? {
883
+ const providerMetadata = response.trace || response.usage || usesJsonResponseTool ? {
677
884
  bedrock: {
678
885
  ...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
679
- ...response.usage && {
886
+ ...((_h = response.usage) == null ? void 0 : _h.cacheWriteInputTokens) != null && {
680
887
  usage: {
681
- cacheReadInputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.cacheReadInputTokens) != null ? _i : Number.NaN,
682
- cacheWriteInputTokens: (_k = (_j = response.usage) == null ? void 0 : _j.cacheWriteInputTokens) != null ? _k : Number.NaN
888
+ cacheWriteInputTokens: response.usage.cacheWriteInputTokens
683
889
  }
684
- }
890
+ },
891
+ ...usesJsonResponseTool && { isJsonResponseFromTool: true }
685
892
  }
686
893
  } : void 0;
687
894
  return {
@@ -690,8 +897,10 @@ var BedrockChatLanguageModel = class {
690
897
  response.stopReason
691
898
  ),
692
899
  usage: {
693
- inputTokens: (_l = response.usage) == null ? void 0 : _l.inputTokens,
694
- outputTokens: (_m = response.usage) == null ? void 0 : _m.outputTokens
900
+ inputTokens: (_i = response.usage) == null ? void 0 : _i.inputTokens,
901
+ outputTokens: (_j = response.usage) == null ? void 0 : _j.outputTokens,
902
+ totalTokens: ((_k = response.usage) == null ? void 0 : _k.inputTokens) + ((_l = response.usage) == null ? void 0 : _l.outputTokens),
903
+ cachedInputTokens: (_n = (_m = response.usage) == null ? void 0 : _m.cacheReadInputTokens) != null ? _n : void 0
695
904
  },
696
905
  response: {
697
906
  // TODO add id, timestamp, etc
@@ -702,16 +911,18 @@ var BedrockChatLanguageModel = class {
702
911
  };
703
912
  }
704
913
  async doStream(options) {
705
- const { command: args, warnings } = this.getArgs(options);
914
+ const {
915
+ command: args,
916
+ warnings,
917
+ usesJsonResponseTool,
918
+ betas
919
+ } = await this.getArgs(options);
706
920
  const url = `${this.getUrl(this.modelId)}/converse-stream`;
707
- const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
921
+ const { value: response, responseHeaders } = await (0, import_provider_utils4.postJsonToApi)({
708
922
  url,
709
- headers: (0, import_provider_utils3.combineHeaders)(
710
- await (0, import_provider_utils3.resolve)(this.config.headers),
711
- options.headers
712
- ),
923
+ headers: await this.getHeaders({ betas, headers: options.headers }),
713
924
  body: args,
714
- failedResponseHandler: (0, import_provider_utils3.createJsonErrorResponseHandler)({
925
+ failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
715
926
  errorSchema: BedrockErrorSchema,
716
927
  errorToMessage: (error) => `${error.type}: ${error.message}`
717
928
  }),
@@ -722,10 +933,11 @@ var BedrockChatLanguageModel = class {
722
933
  let finishReason = "unknown";
723
934
  const usage = {
724
935
  inputTokens: void 0,
725
- outputTokens: void 0
936
+ outputTokens: void 0,
937
+ totalTokens: void 0
726
938
  };
727
939
  let providerMetadata = void 0;
728
- const toolCallContentBlocks = {};
940
+ const contentBlocks = {};
729
941
  return {
730
942
  stream: response.pipeThrough(
731
943
  new TransformStream({
@@ -733,11 +945,14 @@ var BedrockChatLanguageModel = class {
733
945
  controller.enqueue({ type: "stream-start", warnings });
734
946
  },
735
947
  transform(chunk, controller) {
736
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
948
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
737
949
  function enqueueError(bedrockError) {
738
950
  finishReason = "error";
739
951
  controller.enqueue({ type: "error", error: bedrockError });
740
952
  }
953
+ if (options.includeRawChunks) {
954
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
955
+ }
741
956
  if (!chunk.success) {
742
957
  enqueueError(chunk.error);
743
958
  return;
@@ -767,87 +982,174 @@ var BedrockChatLanguageModel = class {
767
982
  if (value.metadata) {
768
983
  usage.inputTokens = (_b = (_a = value.metadata.usage) == null ? void 0 : _a.inputTokens) != null ? _b : usage.inputTokens;
769
984
  usage.outputTokens = (_d = (_c = value.metadata.usage) == null ? void 0 : _c.outputTokens) != null ? _d : usage.outputTokens;
770
- const cacheUsage = ((_e = value.metadata.usage) == null ? void 0 : _e.cacheReadInputTokens) != null || ((_f = value.metadata.usage) == null ? void 0 : _f.cacheWriteInputTokens) != null ? {
985
+ usage.totalTokens = ((_e = usage.inputTokens) != null ? _e : 0) + ((_f = usage.outputTokens) != null ? _f : 0);
986
+ usage.cachedInputTokens = (_h = (_g = value.metadata.usage) == null ? void 0 : _g.cacheReadInputTokens) != null ? _h : usage.cachedInputTokens;
987
+ const cacheUsage = ((_i = value.metadata.usage) == null ? void 0 : _i.cacheWriteInputTokens) != null ? {
771
988
  usage: {
772
- cacheReadInputTokens: (_h = (_g = value.metadata.usage) == null ? void 0 : _g.cacheReadInputTokens) != null ? _h : Number.NaN,
773
- cacheWriteInputTokens: (_j = (_i = value.metadata.usage) == null ? void 0 : _i.cacheWriteInputTokens) != null ? _j : Number.NaN
989
+ cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
774
990
  }
775
991
  } : void 0;
776
992
  const trace = value.metadata.trace ? {
777
993
  trace: value.metadata.trace
778
994
  } : void 0;
779
- if (cacheUsage || trace) {
995
+ if (cacheUsage || trace || usesJsonResponseTool) {
780
996
  providerMetadata = {
781
997
  bedrock: {
782
998
  ...cacheUsage,
783
- ...trace
999
+ ...trace,
1000
+ ...usesJsonResponseTool && {
1001
+ isJsonResponseFromTool: true
1002
+ }
784
1003
  }
785
1004
  };
786
1005
  }
787
1006
  }
788
- if (((_k = value.contentBlockDelta) == null ? void 0 : _k.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
1007
+ if (((_j = value.contentBlockStart) == null ? void 0 : _j.contentBlockIndex) != null && !((_l = (_k = value.contentBlockStart) == null ? void 0 : _k.start) == null ? void 0 : _l.toolUse)) {
1008
+ const blockIndex = value.contentBlockStart.contentBlockIndex;
1009
+ contentBlocks[blockIndex] = { type: "text" };
789
1010
  controller.enqueue({
790
- type: "text",
791
- text: value.contentBlockDelta.delta.text
1011
+ type: "text-start",
1012
+ id: String(blockIndex)
792
1013
  });
793
1014
  }
794
- if (((_l = value.contentBlockDelta) == null ? void 0 : _l.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
1015
+ if (((_m = value.contentBlockDelta) == null ? void 0 : _m.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
1016
+ const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
1017
+ if (contentBlocks[blockIndex] == null) {
1018
+ contentBlocks[blockIndex] = { type: "text" };
1019
+ if (!usesJsonResponseTool) {
1020
+ controller.enqueue({
1021
+ type: "text-start",
1022
+ id: String(blockIndex)
1023
+ });
1024
+ }
1025
+ }
1026
+ if (!usesJsonResponseTool) {
1027
+ controller.enqueue({
1028
+ type: "text-delta",
1029
+ id: String(blockIndex),
1030
+ delta: value.contentBlockDelta.delta.text
1031
+ });
1032
+ }
1033
+ }
1034
+ if (((_n = value.contentBlockStop) == null ? void 0 : _n.contentBlockIndex) != null) {
1035
+ const blockIndex = value.contentBlockStop.contentBlockIndex;
1036
+ const contentBlock = contentBlocks[blockIndex];
1037
+ if (contentBlock != null) {
1038
+ if (contentBlock.type === "reasoning") {
1039
+ controller.enqueue({
1040
+ type: "reasoning-end",
1041
+ id: String(blockIndex)
1042
+ });
1043
+ } else if (contentBlock.type === "text") {
1044
+ if (!usesJsonResponseTool) {
1045
+ controller.enqueue({
1046
+ type: "text-end",
1047
+ id: String(blockIndex)
1048
+ });
1049
+ }
1050
+ } else if (contentBlock.type === "tool-call") {
1051
+ if (usesJsonResponseTool) {
1052
+ controller.enqueue({
1053
+ type: "text-start",
1054
+ id: String(blockIndex)
1055
+ });
1056
+ controller.enqueue({
1057
+ type: "text-delta",
1058
+ id: String(blockIndex),
1059
+ delta: contentBlock.jsonText
1060
+ });
1061
+ controller.enqueue({
1062
+ type: "text-end",
1063
+ id: String(blockIndex)
1064
+ });
1065
+ } else {
1066
+ controller.enqueue({
1067
+ type: "tool-input-end",
1068
+ id: contentBlock.toolCallId
1069
+ });
1070
+ controller.enqueue({
1071
+ type: "tool-call",
1072
+ toolCallId: contentBlock.toolCallId,
1073
+ toolName: contentBlock.toolName,
1074
+ input: contentBlock.jsonText
1075
+ });
1076
+ }
1077
+ }
1078
+ delete contentBlocks[blockIndex];
1079
+ }
1080
+ }
1081
+ if (((_o = value.contentBlockDelta) == null ? void 0 : _o.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
1082
+ const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
795
1083
  const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
796
1084
  if ("text" in reasoningContent && reasoningContent.text) {
1085
+ if (contentBlocks[blockIndex] == null) {
1086
+ contentBlocks[blockIndex] = { type: "reasoning" };
1087
+ controller.enqueue({
1088
+ type: "reasoning-start",
1089
+ id: String(blockIndex)
1090
+ });
1091
+ }
797
1092
  controller.enqueue({
798
- type: "reasoning",
799
- reasoningType: "text",
800
- text: reasoningContent.text
1093
+ type: "reasoning-delta",
1094
+ id: String(blockIndex),
1095
+ delta: reasoningContent.text
801
1096
  });
802
1097
  } else if ("signature" in reasoningContent && reasoningContent.signature) {
803
1098
  controller.enqueue({
804
- type: "reasoning",
805
- reasoningType: "signature",
806
- signature: reasoningContent.signature
1099
+ type: "reasoning-delta",
1100
+ id: String(blockIndex),
1101
+ delta: "",
1102
+ providerMetadata: {
1103
+ bedrock: {
1104
+ signature: reasoningContent.signature
1105
+ }
1106
+ }
807
1107
  });
808
1108
  } else if ("data" in reasoningContent && reasoningContent.data) {
809
1109
  controller.enqueue({
810
- type: "reasoning",
811
- reasoningType: "redacted",
812
- data: reasoningContent.data
1110
+ type: "reasoning-delta",
1111
+ id: String(blockIndex),
1112
+ delta: "",
1113
+ providerMetadata: {
1114
+ bedrock: {
1115
+ redactedData: reasoningContent.data
1116
+ }
1117
+ }
813
1118
  });
814
1119
  }
815
1120
  }
816
1121
  const contentBlockStart = value.contentBlockStart;
817
- if (((_m = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _m.toolUse) != null) {
1122
+ if (((_p = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _p.toolUse) != null) {
818
1123
  const toolUse = contentBlockStart.start.toolUse;
819
- toolCallContentBlocks[contentBlockStart.contentBlockIndex] = {
1124
+ const blockIndex = contentBlockStart.contentBlockIndex;
1125
+ contentBlocks[blockIndex] = {
1126
+ type: "tool-call",
820
1127
  toolCallId: toolUse.toolUseId,
821
1128
  toolName: toolUse.name,
822
1129
  jsonText: ""
823
1130
  };
1131
+ if (!usesJsonResponseTool) {
1132
+ controller.enqueue({
1133
+ type: "tool-input-start",
1134
+ id: toolUse.toolUseId,
1135
+ toolName: toolUse.name
1136
+ });
1137
+ }
824
1138
  }
825
1139
  const contentBlockDelta = value.contentBlockDelta;
826
1140
  if ((contentBlockDelta == null ? void 0 : contentBlockDelta.delta) && "toolUse" in contentBlockDelta.delta && contentBlockDelta.delta.toolUse) {
827
- const contentBlock = toolCallContentBlocks[contentBlockDelta.contentBlockIndex];
828
- const delta = (_n = contentBlockDelta.delta.toolUse.input) != null ? _n : "";
829
- controller.enqueue({
830
- type: "tool-call-delta",
831
- toolCallType: "function",
832
- toolCallId: contentBlock.toolCallId,
833
- toolName: contentBlock.toolName,
834
- argsTextDelta: delta
835
- });
836
- contentBlock.jsonText += delta;
837
- }
838
- const contentBlockStop = value.contentBlockStop;
839
- if (contentBlockStop != null) {
840
- const index = contentBlockStop.contentBlockIndex;
841
- const contentBlock = toolCallContentBlocks[index];
842
- if (contentBlock != null) {
843
- controller.enqueue({
844
- type: "tool-call",
845
- toolCallType: "function",
846
- toolCallId: contentBlock.toolCallId,
847
- toolName: contentBlock.toolName,
848
- args: contentBlock.jsonText
849
- });
850
- delete toolCallContentBlocks[index];
1141
+ const blockIndex = contentBlockDelta.contentBlockIndex;
1142
+ const contentBlock = contentBlocks[blockIndex];
1143
+ if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
1144
+ const delta = (_q = contentBlockDelta.delta.toolUse.input) != null ? _q : "";
1145
+ if (!usesJsonResponseTool) {
1146
+ controller.enqueue({
1147
+ type: "tool-input-delta",
1148
+ id: contentBlock.toolCallId,
1149
+ delta
1150
+ });
1151
+ }
1152
+ contentBlock.jsonText += delta;
851
1153
  }
852
1154
  }
853
1155
  },
@@ -870,113 +1172,134 @@ var BedrockChatLanguageModel = class {
870
1172
  return `${this.config.baseUrl()}/model/${encodedModelId}`;
871
1173
  }
872
1174
  };
873
- var BedrockStopReasonSchema = import_zod3.z.union([
874
- import_zod3.z.enum(BEDROCK_STOP_REASONS),
875
- import_zod3.z.string()
1175
+ var BedrockStopReasonSchema = import_v43.z.union([
1176
+ import_v43.z.enum(BEDROCK_STOP_REASONS),
1177
+ import_v43.z.string()
876
1178
  ]);
877
- var BedrockToolUseSchema = import_zod3.z.object({
878
- toolUseId: import_zod3.z.string(),
879
- name: import_zod3.z.string(),
880
- input: import_zod3.z.unknown()
1179
+ var BedrockToolUseSchema = import_v43.z.object({
1180
+ toolUseId: import_v43.z.string(),
1181
+ name: import_v43.z.string(),
1182
+ input: import_v43.z.unknown()
881
1183
  });
882
- var BedrockReasoningTextSchema = import_zod3.z.object({
883
- signature: import_zod3.z.string().nullish(),
884
- text: import_zod3.z.string()
1184
+ var BedrockReasoningTextSchema = import_v43.z.object({
1185
+ signature: import_v43.z.string().nullish(),
1186
+ text: import_v43.z.string()
885
1187
  });
886
- var BedrockRedactedReasoningSchema = import_zod3.z.object({
887
- data: import_zod3.z.string()
1188
+ var BedrockRedactedReasoningSchema = import_v43.z.object({
1189
+ data: import_v43.z.string()
888
1190
  });
889
- var BedrockResponseSchema = import_zod3.z.object({
890
- metrics: import_zod3.z.object({
891
- latencyMs: import_zod3.z.number()
1191
+ var BedrockResponseSchema = import_v43.z.object({
1192
+ metrics: import_v43.z.object({
1193
+ latencyMs: import_v43.z.number()
892
1194
  }).nullish(),
893
- output: import_zod3.z.object({
894
- message: import_zod3.z.object({
895
- content: import_zod3.z.array(
896
- import_zod3.z.object({
897
- text: import_zod3.z.string().nullish(),
1195
+ output: import_v43.z.object({
1196
+ message: import_v43.z.object({
1197
+ content: import_v43.z.array(
1198
+ import_v43.z.object({
1199
+ text: import_v43.z.string().nullish(),
898
1200
  toolUse: BedrockToolUseSchema.nullish(),
899
- reasoningContent: import_zod3.z.union([
900
- import_zod3.z.object({
1201
+ reasoningContent: import_v43.z.union([
1202
+ import_v43.z.object({
901
1203
  reasoningText: BedrockReasoningTextSchema
902
1204
  }),
903
- import_zod3.z.object({
1205
+ import_v43.z.object({
904
1206
  redactedReasoning: BedrockRedactedReasoningSchema
905
1207
  })
906
1208
  ]).nullish()
907
1209
  })
908
1210
  ),
909
- role: import_zod3.z.string()
1211
+ role: import_v43.z.string()
910
1212
  })
911
1213
  }),
912
1214
  stopReason: BedrockStopReasonSchema,
913
- trace: import_zod3.z.unknown().nullish(),
914
- usage: import_zod3.z.object({
915
- inputTokens: import_zod3.z.number(),
916
- outputTokens: import_zod3.z.number(),
917
- totalTokens: import_zod3.z.number(),
918
- cacheReadInputTokens: import_zod3.z.number().nullish(),
919
- cacheWriteInputTokens: import_zod3.z.number().nullish()
1215
+ trace: import_v43.z.unknown().nullish(),
1216
+ usage: import_v43.z.object({
1217
+ inputTokens: import_v43.z.number(),
1218
+ outputTokens: import_v43.z.number(),
1219
+ totalTokens: import_v43.z.number(),
1220
+ cacheReadInputTokens: import_v43.z.number().nullish(),
1221
+ cacheWriteInputTokens: import_v43.z.number().nullish()
920
1222
  })
921
1223
  });
922
- var BedrockStreamSchema = import_zod3.z.object({
923
- contentBlockDelta: import_zod3.z.object({
924
- contentBlockIndex: import_zod3.z.number(),
925
- delta: import_zod3.z.union([
926
- import_zod3.z.object({ text: import_zod3.z.string() }),
927
- import_zod3.z.object({ toolUse: import_zod3.z.object({ input: import_zod3.z.string() }) }),
928
- import_zod3.z.object({
929
- reasoningContent: import_zod3.z.object({ text: import_zod3.z.string() })
1224
+ var BedrockStreamSchema = import_v43.z.object({
1225
+ contentBlockDelta: import_v43.z.object({
1226
+ contentBlockIndex: import_v43.z.number(),
1227
+ delta: import_v43.z.union([
1228
+ import_v43.z.object({ text: import_v43.z.string() }),
1229
+ import_v43.z.object({ toolUse: import_v43.z.object({ input: import_v43.z.string() }) }),
1230
+ import_v43.z.object({
1231
+ reasoningContent: import_v43.z.object({ text: import_v43.z.string() })
930
1232
  }),
931
- import_zod3.z.object({
932
- reasoningContent: import_zod3.z.object({
933
- signature: import_zod3.z.string()
1233
+ import_v43.z.object({
1234
+ reasoningContent: import_v43.z.object({
1235
+ signature: import_v43.z.string()
934
1236
  })
935
1237
  }),
936
- import_zod3.z.object({
937
- reasoningContent: import_zod3.z.object({ data: import_zod3.z.string() })
1238
+ import_v43.z.object({
1239
+ reasoningContent: import_v43.z.object({ data: import_v43.z.string() })
938
1240
  })
939
1241
  ]).nullish()
940
1242
  }).nullish(),
941
- contentBlockStart: import_zod3.z.object({
942
- contentBlockIndex: import_zod3.z.number(),
943
- start: import_zod3.z.object({
1243
+ contentBlockStart: import_v43.z.object({
1244
+ contentBlockIndex: import_v43.z.number(),
1245
+ start: import_v43.z.object({
944
1246
  toolUse: BedrockToolUseSchema.nullish()
945
1247
  }).nullish()
946
1248
  }).nullish(),
947
- contentBlockStop: import_zod3.z.object({
948
- contentBlockIndex: import_zod3.z.number()
1249
+ contentBlockStop: import_v43.z.object({
1250
+ contentBlockIndex: import_v43.z.number()
949
1251
  }).nullish(),
950
- internalServerException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
951
- messageStop: import_zod3.z.object({
952
- additionalModelResponseFields: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
1252
+ internalServerException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
1253
+ messageStop: import_v43.z.object({
1254
+ additionalModelResponseFields: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
953
1255
  stopReason: BedrockStopReasonSchema
954
1256
  }).nullish(),
955
- metadata: import_zod3.z.object({
956
- trace: import_zod3.z.unknown().nullish(),
957
- usage: import_zod3.z.object({
958
- cacheReadInputTokens: import_zod3.z.number().nullish(),
959
- cacheWriteInputTokens: import_zod3.z.number().nullish(),
960
- inputTokens: import_zod3.z.number(),
961
- outputTokens: import_zod3.z.number()
1257
+ metadata: import_v43.z.object({
1258
+ trace: import_v43.z.unknown().nullish(),
1259
+ usage: import_v43.z.object({
1260
+ cacheReadInputTokens: import_v43.z.number().nullish(),
1261
+ cacheWriteInputTokens: import_v43.z.number().nullish(),
1262
+ inputTokens: import_v43.z.number(),
1263
+ outputTokens: import_v43.z.number()
962
1264
  }).nullish()
963
1265
  }).nullish(),
964
- modelStreamErrorException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
965
- throttlingException: import_zod3.z.record(import_zod3.z.unknown()).nullish(),
966
- validationException: import_zod3.z.record(import_zod3.z.unknown()).nullish()
1266
+ modelStreamErrorException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
1267
+ throttlingException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish(),
1268
+ validationException: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).nullish()
1269
+ });
1270
+ var bedrockReasoningMetadataSchema = import_v43.z.object({
1271
+ signature: import_v43.z.string().optional(),
1272
+ redactedData: import_v43.z.string().optional()
967
1273
  });
968
1274
 
969
1275
  // src/bedrock-embedding-model.ts
970
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
971
- var import_zod4 = require("zod");
1276
+ var import_provider4 = require("@ai-sdk/provider");
1277
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
1278
+
1279
+ // src/bedrock-embedding-options.ts
1280
+ var import_v44 = require("zod/v4");
1281
+ var bedrockEmbeddingProviderOptions = import_v44.z.object({
1282
+ /**
1283
+ The number of dimensions the resulting output embeddings should have (defaults to 1024).
1284
+ Only supported in amazon.titan-embed-text-v2:0.
1285
+ */
1286
+ dimensions: import_v44.z.union([import_v44.z.literal(1024), import_v44.z.literal(512), import_v44.z.literal(256)]).optional(),
1287
+ /**
1288
+ Flag indicating whether or not to normalize the output embeddings. Defaults to true
1289
+ Only supported in amazon.titan-embed-text-v2:0.
1290
+ */
1291
+ normalize: import_v44.z.boolean().optional()
1292
+ });
1293
+
1294
+ // src/bedrock-embedding-model.ts
1295
+ var import_v45 = require("zod/v4");
972
1296
  var BedrockEmbeddingModel = class {
973
- constructor(modelId, settings, config) {
1297
+ constructor(modelId, config) {
974
1298
  this.modelId = modelId;
975
- this.settings = settings;
976
1299
  this.config = config;
977
1300
  this.specificationVersion = "v2";
978
1301
  this.provider = "amazon-bedrock";
979
- this.maxEmbeddingsPerCall = void 0;
1302
+ this.maxEmbeddingsPerCall = 1;
980
1303
  this.supportsParallelCalls = true;
981
1304
  }
982
1305
  getUrl(modelId) {
@@ -986,54 +1309,58 @@ var BedrockEmbeddingModel = class {
986
1309
  async doEmbed({
987
1310
  values,
988
1311
  headers,
989
- abortSignal
1312
+ abortSignal,
1313
+ providerOptions
990
1314
  }) {
991
- const embedSingleText = async (inputText) => {
992
- const args = {
993
- inputText,
994
- dimensions: this.settings.dimensions,
995
- normalize: this.settings.normalize
996
- };
997
- const url = this.getUrl(this.modelId);
998
- const { value: response } = await (0, import_provider_utils4.postJsonToApi)({
999
- url,
1000
- headers: await (0, import_provider_utils4.resolve)(
1001
- (0, import_provider_utils4.combineHeaders)(await (0, import_provider_utils4.resolve)(this.config.headers), headers)
1002
- ),
1003
- body: args,
1004
- failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
1005
- errorSchema: BedrockErrorSchema,
1006
- errorToMessage: (error) => `${error.type}: ${error.message}`
1007
- }),
1008
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
1009
- BedrockEmbeddingResponseSchema
1010
- ),
1011
- fetch: this.config.fetch,
1012
- abortSignal
1315
+ var _a;
1316
+ if (values.length > this.maxEmbeddingsPerCall) {
1317
+ throw new import_provider4.TooManyEmbeddingValuesForCallError({
1318
+ provider: this.provider,
1319
+ modelId: this.modelId,
1320
+ maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
1321
+ values
1013
1322
  });
1014
- return {
1015
- embedding: response.embedding,
1016
- inputTextTokenCount: response.inputTextTokenCount
1017
- };
1323
+ }
1324
+ const bedrockOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
1325
+ provider: "bedrock",
1326
+ providerOptions,
1327
+ schema: bedrockEmbeddingProviderOptions
1328
+ })) != null ? _a : {};
1329
+ const args = {
1330
+ inputText: values[0],
1331
+ dimensions: bedrockOptions.dimensions,
1332
+ normalize: bedrockOptions.normalize
1333
+ };
1334
+ const url = this.getUrl(this.modelId);
1335
+ const { value: response } = await (0, import_provider_utils5.postJsonToApi)({
1336
+ url,
1337
+ headers: await (0, import_provider_utils5.resolve)(
1338
+ (0, import_provider_utils5.combineHeaders)(await (0, import_provider_utils5.resolve)(this.config.headers), headers)
1339
+ ),
1340
+ body: args,
1341
+ failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
1342
+ errorSchema: BedrockErrorSchema,
1343
+ errorToMessage: (error) => `${error.type}: ${error.message}`
1344
+ }),
1345
+ successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
1346
+ BedrockEmbeddingResponseSchema
1347
+ ),
1348
+ fetch: this.config.fetch,
1349
+ abortSignal
1350
+ });
1351
+ return {
1352
+ embeddings: [response.embedding],
1353
+ usage: { tokens: response.inputTextTokenCount }
1018
1354
  };
1019
- const responses = await Promise.all(values.map(embedSingleText));
1020
- return responses.reduce(
1021
- (accumulated, response) => {
1022
- accumulated.embeddings.push(response.embedding);
1023
- accumulated.usage.tokens += response.inputTextTokenCount;
1024
- return accumulated;
1025
- },
1026
- { embeddings: [], usage: { tokens: 0 } }
1027
- );
1028
1355
  }
1029
1356
  };
1030
- var BedrockEmbeddingResponseSchema = import_zod4.z.object({
1031
- embedding: import_zod4.z.array(import_zod4.z.number()),
1032
- inputTextTokenCount: import_zod4.z.number()
1357
+ var BedrockEmbeddingResponseSchema = import_v45.z.object({
1358
+ embedding: import_v45.z.array(import_v45.z.number()),
1359
+ inputTextTokenCount: import_v45.z.number()
1033
1360
  });
1034
1361
 
1035
1362
  // src/bedrock-image-model.ts
1036
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1363
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1037
1364
 
1038
1365
  // src/bedrock-image-settings.ts
1039
1366
  var modelMaxImagesPerCall = {
@@ -1041,18 +1368,17 @@ var modelMaxImagesPerCall = {
1041
1368
  };
1042
1369
 
1043
1370
  // src/bedrock-image-model.ts
1044
- var import_zod5 = require("zod");
1371
+ var import_v46 = require("zod/v4");
1045
1372
  var BedrockImageModel = class {
1046
- constructor(modelId, settings, config) {
1373
+ constructor(modelId, config) {
1047
1374
  this.modelId = modelId;
1048
- this.settings = settings;
1049
1375
  this.config = config;
1050
- this.specificationVersion = "v1";
1376
+ this.specificationVersion = "v2";
1051
1377
  this.provider = "amazon-bedrock";
1052
1378
  }
1053
1379
  get maxImagesPerCall() {
1054
- var _a, _b;
1055
- return (_b = (_a = this.settings.maxImagesPerCall) != null ? _a : modelMaxImagesPerCall[this.modelId]) != null ? _b : 1;
1380
+ var _a;
1381
+ return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
1056
1382
  }
1057
1383
  getUrl(modelId) {
1058
1384
  const encodedModelId = encodeURIComponent(modelId);
@@ -1068,7 +1394,7 @@ var BedrockImageModel = class {
1068
1394
  headers,
1069
1395
  abortSignal
1070
1396
  }) {
1071
- var _a, _b, _c, _d, _e, _f;
1397
+ var _a, _b, _c, _d, _e, _f, _g;
1072
1398
  const warnings = [];
1073
1399
  const [width, height] = size ? size.split("x").map(Number) : [];
1074
1400
  const args = {
@@ -1077,6 +1403,9 @@ var BedrockImageModel = class {
1077
1403
  text: prompt,
1078
1404
  ...((_a = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _a.negativeText) ? {
1079
1405
  negativeText: providerOptions.bedrock.negativeText
1406
+ } : {},
1407
+ ...((_b = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _b.style) ? {
1408
+ style: providerOptions.bedrock.style
1080
1409
  } : {}
1081
1410
  },
1082
1411
  imageGenerationConfig: {
@@ -1084,8 +1413,8 @@ var BedrockImageModel = class {
1084
1413
  ...height ? { height } : {},
1085
1414
  ...seed ? { seed } : {},
1086
1415
  ...n ? { numberOfImages: n } : {},
1087
- ...((_b = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _b.quality) ? { quality: providerOptions.bedrock.quality } : {},
1088
- ...((_c = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _c.cfgScale) ? { cfgScale: providerOptions.bedrock.cfgScale } : {}
1416
+ ...((_c = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _c.quality) ? { quality: providerOptions.bedrock.quality } : {},
1417
+ ...((_d = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _d.cfgScale) ? { cfgScale: providerOptions.bedrock.cfgScale } : {}
1089
1418
  }
1090
1419
  };
1091
1420
  if (aspectRatio != void 0) {
@@ -1095,18 +1424,18 @@ var BedrockImageModel = class {
1095
1424
  details: "This model does not support aspect ratio. Use `size` instead."
1096
1425
  });
1097
1426
  }
1098
- const currentDate = (_f = (_e = (_d = this.config._internal) == null ? void 0 : _d.currentDate) == null ? void 0 : _e.call(_d)) != null ? _f : /* @__PURE__ */ new Date();
1099
- const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
1427
+ const currentDate = (_g = (_f = (_e = this.config._internal) == null ? void 0 : _e.currentDate) == null ? void 0 : _f.call(_e)) != null ? _g : /* @__PURE__ */ new Date();
1428
+ const { value: response, responseHeaders } = await (0, import_provider_utils6.postJsonToApi)({
1100
1429
  url: this.getUrl(this.modelId),
1101
- headers: await (0, import_provider_utils5.resolve)(
1102
- (0, import_provider_utils5.combineHeaders)(await (0, import_provider_utils5.resolve)(this.config.headers), headers)
1430
+ headers: await (0, import_provider_utils6.resolve)(
1431
+ (0, import_provider_utils6.combineHeaders)(await (0, import_provider_utils6.resolve)(this.config.headers), headers)
1103
1432
  ),
1104
1433
  body: args,
1105
- failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
1434
+ failedResponseHandler: (0, import_provider_utils6.createJsonErrorResponseHandler)({
1106
1435
  errorSchema: BedrockErrorSchema,
1107
1436
  errorToMessage: (error) => `${error.type}: ${error.message}`
1108
1437
  }),
1109
- successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
1438
+ successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
1110
1439
  bedrockImageResponseSchema
1111
1440
  ),
1112
1441
  abortSignal,
@@ -1123,8 +1452,8 @@ var BedrockImageModel = class {
1123
1452
  };
1124
1453
  }
1125
1454
  };
1126
- var bedrockImageResponseSchema = import_zod5.z.object({
1127
- images: import_zod5.z.array(import_zod5.z.string())
1455
+ var bedrockImageResponseSchema = import_v46.z.object({
1456
+ images: import_v46.z.array(import_v46.z.string())
1128
1457
  });
1129
1458
 
1130
1459
  // src/headers-utils.ts
@@ -1146,15 +1475,11 @@ function extractHeaders(headers) {
1146
1475
  return originalHeaders;
1147
1476
  }
1148
1477
  function convertHeadersToRecord(headers) {
1149
- const record = {};
1150
- headers.forEach((value, key) => {
1151
- record[key.toLowerCase()] = value;
1152
- });
1153
- return record;
1478
+ return Object.fromEntries([...headers]);
1154
1479
  }
1155
1480
 
1156
1481
  // src/bedrock-sigv4-fetch.ts
1157
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1482
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1158
1483
  var import_aws4fetch = require("aws4fetch");
1159
1484
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
1160
1485
  return async (input, init) => {
@@ -1169,7 +1494,7 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
1169
1494
  const signer = new import_aws4fetch.AwsV4Signer({
1170
1495
  url,
1171
1496
  method: "POST",
1172
- headers: Object.entries((0, import_provider_utils6.removeUndefinedEntries)(originalHeaders)),
1497
+ headers: Object.entries((0, import_provider_utils7.removeUndefinedEntries)(originalHeaders)),
1173
1498
  body,
1174
1499
  region: credentials.region,
1175
1500
  accessKeyId: credentials.accessKeyId,
@@ -1182,8 +1507,8 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
1182
1507
  return fetch(input, {
1183
1508
  ...init,
1184
1509
  body,
1185
- headers: (0, import_provider_utils6.removeUndefinedEntries)(
1186
- (0, import_provider_utils6.combineHeaders)(originalHeaders, signedHeaders)
1510
+ headers: (0, import_provider_utils7.removeUndefinedEntries)(
1511
+ (0, import_provider_utils7.combineHeaders)(originalHeaders, signedHeaders)
1187
1512
  )
1188
1513
  });
1189
1514
  };
@@ -1199,46 +1524,92 @@ function prepareBodyString(body) {
1199
1524
  return JSON.stringify(body);
1200
1525
  }
1201
1526
  }
1527
+ function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
1528
+ return async (input, init) => {
1529
+ const originalHeaders = extractHeaders(init == null ? void 0 : init.headers);
1530
+ return fetch(input, {
1531
+ ...init,
1532
+ headers: (0, import_provider_utils7.removeUndefinedEntries)(
1533
+ (0, import_provider_utils7.combineHeaders)(originalHeaders, {
1534
+ Authorization: `Bearer ${apiKey}`
1535
+ })
1536
+ )
1537
+ });
1538
+ };
1539
+ }
1202
1540
 
1203
1541
  // src/bedrock-provider.ts
1204
1542
  function createAmazonBedrock(options = {}) {
1205
- const sigv4Fetch = createSigV4FetchFunction(async () => {
1206
- const region = (0, import_provider_utils7.loadSetting)({
1543
+ const rawApiKey = (0, import_provider_utils8.loadOptionalSetting)({
1544
+ settingValue: options.apiKey,
1545
+ environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
1546
+ });
1547
+ const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
1548
+ const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
1549
+ const region = (0, import_provider_utils8.loadSetting)({
1207
1550
  settingValue: options.region,
1208
1551
  settingName: "region",
1209
1552
  environmentVariableName: "AWS_REGION",
1210
1553
  description: "AWS region"
1211
1554
  });
1212
1555
  if (options.credentialProvider) {
1556
+ try {
1557
+ return {
1558
+ ...await options.credentialProvider(),
1559
+ region
1560
+ };
1561
+ } catch (error) {
1562
+ const errorMessage = error instanceof Error ? error.message : String(error);
1563
+ throw new Error(
1564
+ `AWS credential provider failed: ${errorMessage}. Please ensure your credential provider returns valid AWS credentials with accessKeyId and secretAccessKey properties.`
1565
+ );
1566
+ }
1567
+ }
1568
+ try {
1213
1569
  return {
1214
- ...await options.credentialProvider(),
1215
- region
1570
+ region,
1571
+ accessKeyId: (0, import_provider_utils8.loadSetting)({
1572
+ settingValue: options.accessKeyId,
1573
+ settingName: "accessKeyId",
1574
+ environmentVariableName: "AWS_ACCESS_KEY_ID",
1575
+ description: "AWS access key ID"
1576
+ }),
1577
+ secretAccessKey: (0, import_provider_utils8.loadSetting)({
1578
+ settingValue: options.secretAccessKey,
1579
+ settingName: "secretAccessKey",
1580
+ environmentVariableName: "AWS_SECRET_ACCESS_KEY",
1581
+ description: "AWS secret access key"
1582
+ }),
1583
+ sessionToken: (0, import_provider_utils8.loadOptionalSetting)({
1584
+ settingValue: options.sessionToken,
1585
+ environmentVariableName: "AWS_SESSION_TOKEN"
1586
+ })
1216
1587
  };
1588
+ } catch (error) {
1589
+ const errorMessage = error instanceof Error ? error.message : String(error);
1590
+ if (errorMessage.includes("AWS_ACCESS_KEY_ID") || errorMessage.includes("accessKeyId")) {
1591
+ throw new Error(
1592
+ `AWS SigV4 authentication requires AWS credentials. Please provide either:
1593
+ 1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
1594
+ 2. Provide accessKeyId and secretAccessKey in options
1595
+ 3. Use a credentialProvider function
1596
+ 4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option
1597
+ Original error: ${errorMessage}`
1598
+ );
1599
+ }
1600
+ if (errorMessage.includes("AWS_SECRET_ACCESS_KEY") || errorMessage.includes("secretAccessKey")) {
1601
+ throw new Error(
1602
+ `AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Please ensure both credentials are provided.
1603
+ Original error: ${errorMessage}`
1604
+ );
1605
+ }
1606
+ throw error;
1217
1607
  }
1218
- return {
1219
- region,
1220
- accessKeyId: (0, import_provider_utils7.loadSetting)({
1221
- settingValue: options.accessKeyId,
1222
- settingName: "accessKeyId",
1223
- environmentVariableName: "AWS_ACCESS_KEY_ID",
1224
- description: "AWS access key ID"
1225
- }),
1226
- secretAccessKey: (0, import_provider_utils7.loadSetting)({
1227
- settingValue: options.secretAccessKey,
1228
- settingName: "secretAccessKey",
1229
- environmentVariableName: "AWS_SECRET_ACCESS_KEY",
1230
- description: "AWS secret access key"
1231
- }),
1232
- sessionToken: (0, import_provider_utils7.loadOptionalSetting)({
1233
- settingValue: options.sessionToken,
1234
- environmentVariableName: "AWS_SESSION_TOKEN"
1235
- })
1236
- };
1237
1608
  }, options.fetch);
1238
1609
  const getBaseUrl = () => {
1239
1610
  var _a, _b;
1240
- return (_b = (0, import_provider_utils7.withoutTrailingSlash)(
1241
- (_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${(0, import_provider_utils7.loadSetting)({
1611
+ return (_b = (0, import_provider_utils8.withoutTrailingSlash)(
1612
+ (_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${(0, import_provider_utils8.loadSetting)({
1242
1613
  settingValue: options.region,
1243
1614
  settingName: "region",
1244
1615
  environmentVariableName: "AWS_REGION",
@@ -1251,8 +1622,8 @@ function createAmazonBedrock(options = {}) {
1251
1622
  return new BedrockChatLanguageModel(modelId, {
1252
1623
  baseUrl: getBaseUrl,
1253
1624
  headers: (_a = options.headers) != null ? _a : {},
1254
- fetch: sigv4Fetch,
1255
- generateId: import_provider_utils7.generateId
1625
+ fetch: fetchFunction,
1626
+ generateId: import_provider_utils8.generateId
1256
1627
  });
1257
1628
  };
1258
1629
  const provider = function(modelId) {
@@ -1263,20 +1634,20 @@ function createAmazonBedrock(options = {}) {
1263
1634
  }
1264
1635
  return createChatModel(modelId);
1265
1636
  };
1266
- const createEmbeddingModel = (modelId, settings = {}) => {
1637
+ const createEmbeddingModel = (modelId) => {
1267
1638
  var _a;
1268
- return new BedrockEmbeddingModel(modelId, settings, {
1639
+ return new BedrockEmbeddingModel(modelId, {
1269
1640
  baseUrl: getBaseUrl,
1270
1641
  headers: (_a = options.headers) != null ? _a : {},
1271
- fetch: sigv4Fetch
1642
+ fetch: fetchFunction
1272
1643
  });
1273
1644
  };
1274
- const createImageModel = (modelId, settings = {}) => {
1645
+ const createImageModel = (modelId) => {
1275
1646
  var _a;
1276
- return new BedrockImageModel(modelId, settings, {
1647
+ return new BedrockImageModel(modelId, {
1277
1648
  baseUrl: getBaseUrl,
1278
1649
  headers: (_a = options.headers) != null ? _a : {},
1279
- fetch: sigv4Fetch
1650
+ fetch: fetchFunction
1280
1651
  });
1281
1652
  };
1282
1653
  provider.languageModel = createChatModel;
@@ -1285,6 +1656,7 @@ function createAmazonBedrock(options = {}) {
1285
1656
  provider.textEmbeddingModel = createEmbeddingModel;
1286
1657
  provider.image = createImageModel;
1287
1658
  provider.imageModel = createImageModel;
1659
+ provider.tools = import_internal2.anthropicTools;
1288
1660
  return provider;
1289
1661
  }
1290
1662
  var bedrock = createAmazonBedrock();