@ai-sdk/amazon-bedrock 3.1.0-beta.9 → 4.0.0-beta.100

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,14 +26,9 @@ __export(src_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(src_exports);
28
28
 
29
- // src/bedrock-provider.ts
30
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
31
-
32
- // src/version.ts
33
- var VERSION = true ? "3.1.0-beta.9" : "0.0.0-test";
34
-
35
29
  // src/bedrock-provider.ts
36
30
  var import_internal2 = require("@ai-sdk/anthropic/internal");
31
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
37
32
 
38
33
  // src/bedrock-chat-language-model.ts
39
34
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
@@ -75,6 +70,18 @@ var BEDROCK_DOCUMENT_MIME_TYPES = {
75
70
 
76
71
  // src/bedrock-chat-options.ts
77
72
  var import_v4 = require("zod/v4");
73
+ var bedrockFilePartProviderOptions = import_v4.z.object({
74
+ /**
75
+ * Citation configuration for this document.
76
+ * When enabled, this document will generate citations in the response.
77
+ */
78
+ citations: import_v4.z.object({
79
+ /**
80
+ * Enable citations for this document
81
+ */
82
+ enabled: import_v4.z.boolean()
83
+ }).optional()
84
+ });
78
85
  var bedrockProviderOptions = import_v4.z.object({
79
86
  /**
80
87
  * Additional inference parameters that the model supports,
@@ -84,8 +91,13 @@ var bedrockProviderOptions = import_v4.z.object({
84
91
  additionalModelRequestFields: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
85
92
  reasoningConfig: import_v4.z.object({
86
93
  type: import_v4.z.union([import_v4.z.literal("enabled"), import_v4.z.literal("disabled")]).optional(),
87
- budgetTokens: import_v4.z.number().optional()
88
- }).optional()
94
+ budgetTokens: import_v4.z.number().optional(),
95
+ maxReasoningEffort: import_v4.z.enum(["low", "medium", "high"]).optional()
96
+ }).optional(),
97
+ /**
98
+ * Anthropic beta features to enable
99
+ */
100
+ anthropicBeta: import_v4.z.array(import_v4.z.string()).optional()
89
101
  });
90
102
 
91
103
  // src/bedrock-error.ts
@@ -95,6 +107,45 @@ var BedrockErrorSchema = import_v42.z.object({
95
107
  type: import_v42.z.string().nullish()
96
108
  });
97
109
 
110
+ // src/convert-bedrock-usage.ts
111
+ function convertBedrockUsage(usage) {
112
+ var _a, _b;
113
+ if (usage == null) {
114
+ return {
115
+ inputTokens: {
116
+ total: void 0,
117
+ noCache: void 0,
118
+ cacheRead: void 0,
119
+ cacheWrite: void 0
120
+ },
121
+ outputTokens: {
122
+ total: void 0,
123
+ text: void 0,
124
+ reasoning: void 0
125
+ },
126
+ raw: void 0
127
+ };
128
+ }
129
+ const inputTokens = usage.inputTokens;
130
+ const outputTokens = usage.outputTokens;
131
+ const cacheReadTokens = (_a = usage.cacheReadInputTokens) != null ? _a : 0;
132
+ const cacheWriteTokens = (_b = usage.cacheWriteInputTokens) != null ? _b : 0;
133
+ return {
134
+ inputTokens: {
135
+ total: inputTokens,
136
+ noCache: inputTokens - cacheReadTokens,
137
+ cacheRead: cacheReadTokens,
138
+ cacheWrite: cacheWriteTokens
139
+ },
140
+ outputTokens: {
141
+ total: outputTokens,
142
+ text: outputTokens,
143
+ reasoning: void 0
144
+ },
145
+ raw: usage
146
+ };
147
+ }
148
+
98
149
  // src/bedrock-event-stream-response-handler.ts
99
150
  var import_provider = require("@ai-sdk/provider");
100
151
  var import_provider_utils = require("@ai-sdk/provider-utils");
@@ -170,11 +221,12 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
170
221
  var import_provider2 = require("@ai-sdk/provider");
171
222
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
172
223
  var import_internal = require("@ai-sdk/anthropic/internal");
173
- function prepareTools({
224
+ async function prepareTools({
174
225
  tools,
175
226
  toolChoice,
176
227
  modelId
177
228
  }) {
229
+ var _a;
178
230
  const toolWarnings = [];
179
231
  const betas = /* @__PURE__ */ new Set();
180
232
  if (tools == null || tools.length === 0) {
@@ -186,10 +238,10 @@ function prepareTools({
186
238
  };
187
239
  }
188
240
  const supportedTools = tools.filter((tool) => {
189
- if (tool.type === "provider-defined" && tool.id === "anthropic.web_search_20250305") {
241
+ if (tool.type === "provider" && tool.id === "anthropic.web_search_20250305") {
190
242
  toolWarnings.push({
191
- type: "unsupported-tool",
192
- tool,
243
+ type: "unsupported",
244
+ feature: "web_search_20250305 tool",
193
245
  details: "The web_search_20250305 tool is not supported on Amazon Bedrock."
194
246
  });
195
247
  return false;
@@ -205,18 +257,16 @@ function prepareTools({
205
257
  };
206
258
  }
207
259
  const isAnthropicModel = modelId.includes("anthropic.");
208
- const providerDefinedTools = supportedTools.filter(
209
- (t) => t.type === "provider-defined"
210
- );
260
+ const ProviderTools = supportedTools.filter((t) => t.type === "provider");
211
261
  const functionTools = supportedTools.filter((t) => t.type === "function");
212
262
  let additionalTools = void 0;
213
263
  const bedrockTools = [];
214
- const usingAnthropicTools = isAnthropicModel && providerDefinedTools.length > 0;
264
+ const usingAnthropicTools = isAnthropicModel && ProviderTools.length > 0;
215
265
  if (usingAnthropicTools) {
216
266
  if (functionTools.length > 0) {
217
267
  toolWarnings.push({
218
- type: "unsupported-setting",
219
- setting: "tools",
268
+ type: "unsupported",
269
+ feature: "mixing Anthropic provider-defined tools and standard function tools",
220
270
  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."
221
271
  });
222
272
  }
@@ -224,9 +274,10 @@ function prepareTools({
224
274
  toolChoice: preparedAnthropicToolChoice,
225
275
  toolWarnings: anthropicToolWarnings,
226
276
  betas: anthropicBetas
227
- } = (0, import_internal.prepareTools)({
228
- tools: providerDefinedTools,
229
- toolChoice
277
+ } = await (0, import_internal.prepareTools)({
278
+ tools: ProviderTools,
279
+ toolChoice,
280
+ supportsStructuredOutput: false
230
281
  });
231
282
  toolWarnings.push(...anthropicToolWarnings);
232
283
  anthropicBetas.forEach((beta) => betas.add(beta));
@@ -235,7 +286,7 @@ function prepareTools({
235
286
  tool_choice: preparedAnthropicToolChoice
236
287
  };
237
288
  }
238
- for (const tool of providerDefinedTools) {
289
+ for (const tool of ProviderTools) {
239
290
  const toolFactory = Object.values(import_internal.anthropicTools).find((factory) => {
240
291
  const instance = factory({});
241
292
  return instance.id === tool.id;
@@ -246,24 +297,24 @@ function prepareTools({
246
297
  toolSpec: {
247
298
  name: tool.name,
248
299
  inputSchema: {
249
- json: (0, import_provider_utils2.asSchema)(fullToolDefinition.inputSchema).jsonSchema
300
+ json: await (0, import_provider_utils2.asSchema)(fullToolDefinition.inputSchema).jsonSchema
250
301
  }
251
302
  }
252
303
  });
253
304
  } else {
254
- toolWarnings.push({ type: "unsupported-tool", tool });
305
+ toolWarnings.push({ type: "unsupported", feature: "tool ${tool.id}" });
255
306
  }
256
307
  }
257
308
  } else {
258
- for (const tool of providerDefinedTools) {
259
- toolWarnings.push({ type: "unsupported-tool", tool });
309
+ for (const tool of ProviderTools) {
310
+ toolWarnings.push({ type: "unsupported", feature: `tool ${tool.id}` });
260
311
  }
261
312
  }
262
313
  for (const tool of functionTools) {
263
314
  bedrockTools.push({
264
315
  toolSpec: {
265
316
  name: tool.name,
266
- description: tool.description,
317
+ ...((_a = tool.description) == null ? void 0 : _a.trim()) !== "" ? { description: tool.description } : {},
267
318
  inputSchema: {
268
319
  json: tool.inputSchema
269
320
  }
@@ -311,7 +362,17 @@ function getCachePoint(providerMetadata) {
311
362
  var _a;
312
363
  return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
313
364
  }
365
+ async function shouldEnableCitations(providerMetadata) {
366
+ var _a, _b;
367
+ const bedrockOptions = await (0, import_provider_utils3.parseProviderOptions)({
368
+ provider: "bedrock",
369
+ providerOptions: providerMetadata,
370
+ schema: bedrockFilePartProviderOptions
371
+ });
372
+ return (_b = (_a = bedrockOptions == null ? void 0 : bedrockOptions.citations) == null ? void 0 : _a.enabled) != null ? _b : false;
373
+ }
314
374
  async function convertToBedrockChatMessages(prompt) {
375
+ var _a, _b;
315
376
  const blocks = groupIntoBlocks(prompt);
316
377
  let system = [];
317
378
  const messages = [];
@@ -371,11 +432,17 @@ async function convertToBedrockChatMessages(prompt) {
371
432
  message: "File mime type is required in user message part content"
372
433
  });
373
434
  }
435
+ const enableCitations = await shouldEnableCitations(
436
+ part.providerOptions
437
+ );
374
438
  bedrockContent.push({
375
439
  document: {
376
440
  format: getBedrockDocumentFormat(part.mediaType),
377
- name: generateDocumentName(),
378
- source: { bytes: (0, import_provider_utils3.convertToBase64)(part.data) }
441
+ name: (_a = part.filename) != null ? _a : generateDocumentName(),
442
+ source: { bytes: (0, import_provider_utils3.convertToBase64)(part.data) },
443
+ ...enableCitations && {
444
+ citations: { enabled: true }
445
+ }
379
446
  }
380
447
  });
381
448
  }
@@ -395,7 +462,7 @@ async function convertToBedrockChatMessages(prompt) {
395
462
  switch (contentPart.type) {
396
463
  case "text":
397
464
  return { text: contentPart.text };
398
- case "media":
465
+ case "image-data":
399
466
  if (!contentPart.mediaType.startsWith("image/")) {
400
467
  throw new import_provider3.UnsupportedFunctionalityError({
401
468
  functionality: `media type: ${contentPart.mediaType}`
@@ -410,6 +477,11 @@ async function convertToBedrockChatMessages(prompt) {
410
477
  source: { bytes: contentPart.data }
411
478
  }
412
479
  };
480
+ default: {
481
+ throw new import_provider3.UnsupportedFunctionalityError({
482
+ functionality: `unsupported tool content part type: ${contentPart.type}`
483
+ });
484
+ }
413
485
  }
414
486
  });
415
487
  break;
@@ -418,6 +490,11 @@ async function convertToBedrockChatMessages(prompt) {
418
490
  case "error-text":
419
491
  toolResultContent = [{ text: output.value }];
420
492
  break;
493
+ case "execution-denied":
494
+ toolResultContent = [
495
+ { text: (_b = output.reason) != null ? _b : "Tool execution denied." }
496
+ ];
497
+ break;
421
498
  case "json":
422
499
  case "error-json":
423
500
  default:
@@ -616,7 +693,7 @@ function groupIntoBlocks(prompt) {
616
693
  }
617
694
 
618
695
  // src/map-bedrock-finish-reason.ts
619
- function mapBedrockFinishReason(finishReason) {
696
+ function mapBedrockFinishReason(finishReason, isJsonResponseFromTool) {
620
697
  switch (finishReason) {
621
698
  case "stop_sequence":
622
699
  case "end_turn":
@@ -627,7 +704,7 @@ function mapBedrockFinishReason(finishReason) {
627
704
  case "guardrail_intervened":
628
705
  return "content-filter";
629
706
  case "tool_use":
630
- return "tool-calls";
707
+ return isJsonResponseFromTool ? "stop" : "tool-calls";
631
708
  default:
632
709
  return "unknown";
633
710
  }
@@ -659,7 +736,7 @@ var BedrockChatLanguageModel = class {
659
736
  toolChoice,
660
737
  providerOptions
661
738
  }) {
662
- var _a, _b, _c, _d, _e, _f;
739
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
663
740
  const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
664
741
  provider: "bedrock",
665
742
  providerOptions,
@@ -668,46 +745,53 @@ var BedrockChatLanguageModel = class {
668
745
  const warnings = [];
669
746
  if (frequencyPenalty != null) {
670
747
  warnings.push({
671
- type: "unsupported-setting",
672
- setting: "frequencyPenalty"
748
+ type: "unsupported",
749
+ feature: "frequencyPenalty"
673
750
  });
674
751
  }
675
752
  if (presencePenalty != null) {
676
753
  warnings.push({
677
- type: "unsupported-setting",
678
- setting: "presencePenalty"
754
+ type: "unsupported",
755
+ feature: "presencePenalty"
679
756
  });
680
757
  }
681
758
  if (seed != null) {
682
759
  warnings.push({
683
- type: "unsupported-setting",
684
- setting: "seed"
760
+ type: "unsupported",
761
+ feature: "seed"
685
762
  });
686
763
  }
764
+ if (temperature != null && temperature > 1) {
765
+ warnings.push({
766
+ type: "unsupported",
767
+ feature: "temperature",
768
+ details: `${temperature} exceeds bedrock maximum of 1.0. clamped to 1.0`
769
+ });
770
+ temperature = 1;
771
+ } else if (temperature != null && temperature < 0) {
772
+ warnings.push({
773
+ type: "unsupported",
774
+ feature: "temperature",
775
+ details: `${temperature} is below bedrock minimum of 0. clamped to 0`
776
+ });
777
+ temperature = 0;
778
+ }
687
779
  if (responseFormat != null && responseFormat.type !== "text" && responseFormat.type !== "json") {
688
780
  warnings.push({
689
- type: "unsupported-setting",
690
- setting: "responseFormat",
781
+ type: "unsupported",
782
+ feature: "responseFormat",
691
783
  details: "Only text and json response formats are supported."
692
784
  });
693
785
  }
694
- if (tools != null && (responseFormat == null ? void 0 : responseFormat.type) === "json") {
695
- if (tools.length > 0) {
696
- warnings.push({
697
- type: "other",
698
- message: "JSON response format does not support tools. The provided tools are ignored."
699
- });
700
- }
701
- }
702
786
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
703
787
  type: "function",
704
788
  name: "json",
705
789
  description: "Respond with a JSON object.",
706
790
  inputSchema: responseFormat.schema
707
791
  } : void 0;
708
- const { toolConfig, additionalTools, toolWarnings, betas } = prepareTools({
709
- tools: jsonResponseTool ? [jsonResponseTool, ...tools != null ? tools : []] : tools,
710
- toolChoice: jsonResponseTool != null ? { type: "tool", toolName: jsonResponseTool.name } : toolChoice,
792
+ const { toolConfig, additionalTools, toolWarnings, betas } = await prepareTools({
793
+ tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
794
+ toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
711
795
  modelId: this.modelId
712
796
  });
713
797
  warnings.push(...toolWarnings);
@@ -717,8 +801,18 @@ var BedrockChatLanguageModel = class {
717
801
  ...additionalTools
718
802
  };
719
803
  }
720
- const isThinking = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled";
721
- const thinkingBudget = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.budgetTokens;
804
+ if (betas.size > 0 || bedrockOptions.anthropicBeta) {
805
+ const existingBetas = (_b = bedrockOptions.anthropicBeta) != null ? _b : [];
806
+ const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
807
+ bedrockOptions.additionalModelRequestFields = {
808
+ ...bedrockOptions.additionalModelRequestFields,
809
+ anthropic_beta: mergedBetas
810
+ };
811
+ }
812
+ const isAnthropicModel = this.modelId.includes("anthropic");
813
+ const isThinkingRequested = ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "enabled";
814
+ const thinkingBudget = (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.budgetTokens;
815
+ const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingRequested;
722
816
  const inferenceConfig = {
723
817
  ...maxOutputTokens != null && { maxTokens: maxOutputTokens },
724
818
  ...temperature != null && { temperature },
@@ -726,7 +820,7 @@ var BedrockChatLanguageModel = class {
726
820
  ...topK != null && { topK },
727
821
  ...stopSequences != null && { stopSequences }
728
822
  };
729
- if (isThinking && thinkingBudget != null) {
823
+ if (isAnthropicThinkingEnabled && thinkingBudget != null) {
730
824
  if (inferenceConfig.maxTokens != null) {
731
825
  inferenceConfig.maxTokens += thinkingBudget;
732
826
  } else {
@@ -735,36 +829,60 @@ var BedrockChatLanguageModel = class {
735
829
  bedrockOptions.additionalModelRequestFields = {
736
830
  ...bedrockOptions.additionalModelRequestFields,
737
831
  thinking: {
738
- type: (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type,
832
+ type: (_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type,
739
833
  budget_tokens: thinkingBudget
740
834
  }
741
835
  };
836
+ } else if (!isAnthropicModel && thinkingBudget != null) {
837
+ warnings.push({
838
+ type: "unsupported",
839
+ feature: "budgetTokens",
840
+ details: "budgetTokens applies only to Anthropic models on Bedrock and will be ignored for this model."
841
+ });
842
+ }
843
+ const maxReasoningEffort = (_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.maxReasoningEffort;
844
+ if (maxReasoningEffort != null && !isAnthropicModel) {
845
+ bedrockOptions.additionalModelRequestFields = {
846
+ ...bedrockOptions.additionalModelRequestFields,
847
+ reasoningConfig: {
848
+ ...((_g = bedrockOptions.reasoningConfig) == null ? void 0 : _g.type) != null && {
849
+ type: bedrockOptions.reasoningConfig.type
850
+ },
851
+ maxReasoningEffort
852
+ }
853
+ };
854
+ } else if (maxReasoningEffort != null && isAnthropicModel) {
855
+ warnings.push({
856
+ type: "unsupported",
857
+ feature: "maxReasoningEffort",
858
+ details: "maxReasoningEffort applies only to Amazon Nova models on Bedrock and will be ignored for this model."
859
+ });
742
860
  }
743
- if (isThinking && inferenceConfig.temperature != null) {
861
+ if (isAnthropicThinkingEnabled && inferenceConfig.temperature != null) {
744
862
  delete inferenceConfig.temperature;
745
863
  warnings.push({
746
- type: "unsupported-setting",
747
- setting: "temperature",
864
+ type: "unsupported",
865
+ feature: "temperature",
748
866
  details: "temperature is not supported when thinking is enabled"
749
867
  });
750
868
  }
751
- if (isThinking && inferenceConfig.topP != null) {
869
+ if (isAnthropicThinkingEnabled && inferenceConfig.topP != null) {
752
870
  delete inferenceConfig.topP;
753
871
  warnings.push({
754
- type: "unsupported-setting",
755
- setting: "topP",
872
+ type: "unsupported",
873
+ feature: "topP",
756
874
  details: "topP is not supported when thinking is enabled"
757
875
  });
758
876
  }
759
- if (isThinking && inferenceConfig.topK != null) {
877
+ if (isAnthropicThinkingEnabled && inferenceConfig.topK != null) {
760
878
  delete inferenceConfig.topK;
761
879
  warnings.push({
762
- type: "unsupported-setting",
763
- setting: "topK",
880
+ type: "unsupported",
881
+ feature: "topK",
764
882
  details: "topK is not supported when thinking is enabled"
765
883
  });
766
884
  }
767
- const hasAnyTools = ((_f = (_e = toolConfig.tools) == null ? void 0 : _e.length) != null ? _f : 0) > 0 || additionalTools;
885
+ const hasAnyTools = ((_i = (_h = toolConfig.tools) == null ? void 0 : _h.length) != null ? _i : 0) > 0 || additionalTools;
768
886
  let filteredPrompt = prompt;
769
887
  if (!hasAnyTools) {
770
888
  const hasToolContent = prompt.some(
@@ -784,14 +902,18 @@ var BedrockChatLanguageModel = class {
784
902
  (message) => message.role === "system" || message.content.length > 0
785
903
  );
786
904
  warnings.push({
787
- type: "unsupported-setting",
788
- setting: "toolContent",
905
+ type: "unsupported",
906
+ feature: "toolContent",
789
907
  details: "Tool calls and results removed from conversation because Bedrock does not support tool content without active tools."
790
908
  });
791
909
  }
792
910
  }
793
911
  const { system, messages } = await convertToBedrockChatMessages(filteredPrompt);
794
- const { reasoningConfig: _, ...filteredBedrockOptions } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
912
+ const {
913
+ reasoningConfig: _,
914
+ additionalModelRequestFields: __,
915
+ ...filteredBedrockOptions
916
+ } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
795
917
  return {
796
918
  command: {
797
919
  system,
@@ -809,27 +931,21 @@ var BedrockChatLanguageModel = class {
809
931
  };
810
932
  }
811
933
  async getHeaders({
812
- betas,
813
934
  headers
814
935
  }) {
815
- return (0, import_provider_utils4.combineHeaders)(
816
- await (0, import_provider_utils4.resolve)(this.config.headers),
817
- betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
818
- headers
819
- );
936
+ return (0, import_provider_utils4.combineHeaders)(await (0, import_provider_utils4.resolve)(this.config.headers), headers);
820
937
  }
821
938
  async doGenerate(options) {
822
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
939
+ var _a, _b, _c, _d, _e, _f, _g, _h;
823
940
  const {
824
941
  command: args,
825
942
  warnings,
826
- usesJsonResponseTool,
827
- betas
943
+ usesJsonResponseTool
828
944
  } = await this.getArgs(options);
829
945
  const url = `${this.getUrl(this.modelId)}/converse`;
830
946
  const { value: response, responseHeaders } = await (0, import_provider_utils4.postJsonToApi)({
831
947
  url,
832
- headers: await this.getHeaders({ betas, headers: options.headers }),
948
+ headers: await this.getHeaders({ headers: options.headers }),
833
949
  body: args,
834
950
  failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
835
951
  errorSchema: BedrockErrorSchema,
@@ -845,11 +961,10 @@ var BedrockChatLanguageModel = class {
845
961
  fetch: this.config.fetch
846
962
  });
847
963
  const content = [];
964
+ let isJsonResponseFromTool = false;
848
965
  for (const part of response.output.message.content) {
849
966
  if (part.text) {
850
- if (!usesJsonResponseTool) {
851
- content.push({ type: "text", text: part.text });
852
- }
967
+ content.push({ type: "text", text: part.text });
853
968
  }
854
969
  if (part.reasoningContent) {
855
970
  if ("reasoningText" in part.reasoningContent) {
@@ -878,21 +993,24 @@ var BedrockChatLanguageModel = class {
878
993
  }
879
994
  }
880
995
  if (part.toolUse) {
881
- content.push(
882
- // when a json response tool is used, the tool call becomes the text:
883
- usesJsonResponseTool ? {
996
+ const isJsonResponseTool = usesJsonResponseTool && part.toolUse.name === "json";
997
+ if (isJsonResponseTool) {
998
+ isJsonResponseFromTool = true;
999
+ content.push({
884
1000
  type: "text",
885
1001
  text: JSON.stringify(part.toolUse.input)
886
- } : {
1002
+ });
1003
+ } else {
1004
+ content.push({
887
1005
  type: "tool-call",
888
1006
  toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
889
1007
  toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
890
- input: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
891
- }
892
- );
1008
+ input: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : {})
1009
+ });
1010
+ }
893
1011
  }
894
1012
  }
895
- const providerMetadata = response.trace || response.usage || usesJsonResponseTool ? {
1013
+ const providerMetadata = response.trace || response.usage || isJsonResponseFromTool ? {
896
1014
  bedrock: {
897
1015
  ...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
898
1016
  ...((_h = response.usage) == null ? void 0 : _h.cacheWriteInputTokens) != null && {
@@ -900,20 +1018,16 @@ var BedrockChatLanguageModel = class {
900
1018
  cacheWriteInputTokens: response.usage.cacheWriteInputTokens
901
1019
  }
902
1020
  },
903
- ...usesJsonResponseTool && { isJsonResponseFromTool: true }
1021
+ ...isJsonResponseFromTool && { isJsonResponseFromTool: true }
904
1022
  }
905
1023
  } : void 0;
906
1024
  return {
907
1025
  content,
908
1026
  finishReason: mapBedrockFinishReason(
909
- response.stopReason
1027
+ response.stopReason,
1028
+ isJsonResponseFromTool
910
1029
  ),
911
- usage: {
912
- inputTokens: (_i = response.usage) == null ? void 0 : _i.inputTokens,
913
- outputTokens: (_j = response.usage) == null ? void 0 : _j.outputTokens,
914
- totalTokens: ((_k = response.usage) == null ? void 0 : _k.inputTokens) + ((_l = response.usage) == null ? void 0 : _l.outputTokens),
915
- cachedInputTokens: (_n = (_m = response.usage) == null ? void 0 : _m.cacheReadInputTokens) != null ? _n : void 0
916
- },
1030
+ usage: convertBedrockUsage(response.usage),
917
1031
  response: {
918
1032
  // TODO add id, timestamp, etc
919
1033
  headers: responseHeaders
@@ -926,13 +1040,12 @@ var BedrockChatLanguageModel = class {
926
1040
  const {
927
1041
  command: args,
928
1042
  warnings,
929
- usesJsonResponseTool,
930
- betas
1043
+ usesJsonResponseTool
931
1044
  } = await this.getArgs(options);
932
1045
  const url = `${this.getUrl(this.modelId)}/converse-stream`;
933
1046
  const { value: response, responseHeaders } = await (0, import_provider_utils4.postJsonToApi)({
934
1047
  url,
935
- headers: await this.getHeaders({ betas, headers: options.headers }),
1048
+ headers: await this.getHeaders({ headers: options.headers }),
936
1049
  body: args,
937
1050
  failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
938
1051
  errorSchema: BedrockErrorSchema,
@@ -943,12 +1056,9 @@ var BedrockChatLanguageModel = class {
943
1056
  fetch: this.config.fetch
944
1057
  });
945
1058
  let finishReason = "unknown";
946
- const usage = {
947
- inputTokens: void 0,
948
- outputTokens: void 0,
949
- totalTokens: void 0
950
- };
1059
+ let usage = void 0;
951
1060
  let providerMetadata = void 0;
1061
+ let isJsonResponseFromTool = false;
952
1062
  const contentBlocks = {};
953
1063
  return {
954
1064
  stream: response.pipeThrough(
@@ -957,7 +1067,7 @@ var BedrockChatLanguageModel = class {
957
1067
  controller.enqueue({ type: "stream-start", warnings });
958
1068
  },
959
1069
  transform(chunk, controller) {
960
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1070
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
961
1071
  function enqueueError(bedrockError) {
962
1072
  finishReason = "error";
963
1073
  controller.enqueue({ type: "error", error: bedrockError });
@@ -988,15 +1098,15 @@ var BedrockChatLanguageModel = class {
988
1098
  }
989
1099
  if (value.messageStop) {
990
1100
  finishReason = mapBedrockFinishReason(
991
- value.messageStop.stopReason
1101
+ value.messageStop.stopReason,
1102
+ isJsonResponseFromTool
992
1103
  );
993
1104
  }
994
1105
  if (value.metadata) {
995
- usage.inputTokens = (_b = (_a = value.metadata.usage) == null ? void 0 : _a.inputTokens) != null ? _b : usage.inputTokens;
996
- usage.outputTokens = (_d = (_c = value.metadata.usage) == null ? void 0 : _c.outputTokens) != null ? _d : usage.outputTokens;
997
- usage.totalTokens = ((_e = usage.inputTokens) != null ? _e : 0) + ((_f = usage.outputTokens) != null ? _f : 0);
998
- usage.cachedInputTokens = (_h = (_g = value.metadata.usage) == null ? void 0 : _g.cacheReadInputTokens) != null ? _h : usage.cachedInputTokens;
999
- const cacheUsage = ((_i = value.metadata.usage) == null ? void 0 : _i.cacheWriteInputTokens) != null ? {
1106
+ if (value.metadata.usage) {
1107
+ usage = value.metadata.usage;
1108
+ }
1109
+ const cacheUsage = ((_a = value.metadata.usage) == null ? void 0 : _a.cacheWriteInputTokens) != null ? {
1000
1110
  usage: {
1001
1111
  cacheWriteInputTokens: value.metadata.usage.cacheWriteInputTokens
1002
1112
  }
@@ -1004,19 +1114,16 @@ var BedrockChatLanguageModel = class {
1004
1114
  const trace = value.metadata.trace ? {
1005
1115
  trace: value.metadata.trace
1006
1116
  } : void 0;
1007
- if (cacheUsage || trace || usesJsonResponseTool) {
1117
+ if (cacheUsage || trace) {
1008
1118
  providerMetadata = {
1009
1119
  bedrock: {
1010
1120
  ...cacheUsage,
1011
- ...trace,
1012
- ...usesJsonResponseTool && {
1013
- isJsonResponseFromTool: true
1014
- }
1121
+ ...trace
1015
1122
  }
1016
1123
  };
1017
1124
  }
1018
1125
  }
1019
- if (((_j = value.contentBlockStart) == null ? void 0 : _j.contentBlockIndex) != null && !((_l = (_k = value.contentBlockStart) == null ? void 0 : _k.start) == null ? void 0 : _l.toolUse)) {
1126
+ if (((_b = value.contentBlockStart) == null ? void 0 : _b.contentBlockIndex) != null && !((_d = (_c = value.contentBlockStart) == null ? void 0 : _c.start) == null ? void 0 : _d.toolUse)) {
1020
1127
  const blockIndex = value.contentBlockStart.contentBlockIndex;
1021
1128
  contentBlocks[blockIndex] = { type: "text" };
1022
1129
  controller.enqueue({
@@ -1024,26 +1131,22 @@ var BedrockChatLanguageModel = class {
1024
1131
  id: String(blockIndex)
1025
1132
  });
1026
1133
  }
1027
- if (((_m = value.contentBlockDelta) == null ? void 0 : _m.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
1134
+ if (((_e = value.contentBlockDelta) == null ? void 0 : _e.delta) && "text" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.text) {
1028
1135
  const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
1029
1136
  if (contentBlocks[blockIndex] == null) {
1030
1137
  contentBlocks[blockIndex] = { type: "text" };
1031
- if (!usesJsonResponseTool) {
1032
- controller.enqueue({
1033
- type: "text-start",
1034
- id: String(blockIndex)
1035
- });
1036
- }
1037
- }
1038
- if (!usesJsonResponseTool) {
1039
1138
  controller.enqueue({
1040
- type: "text-delta",
1041
- id: String(blockIndex),
1042
- delta: value.contentBlockDelta.delta.text
1139
+ type: "text-start",
1140
+ id: String(blockIndex)
1043
1141
  });
1044
1142
  }
1143
+ controller.enqueue({
1144
+ type: "text-delta",
1145
+ id: String(blockIndex),
1146
+ delta: value.contentBlockDelta.delta.text
1147
+ });
1045
1148
  }
1046
- if (((_n = value.contentBlockStop) == null ? void 0 : _n.contentBlockIndex) != null) {
1149
+ if (((_f = value.contentBlockStop) == null ? void 0 : _f.contentBlockIndex) != null) {
1047
1150
  const blockIndex = value.contentBlockStop.contentBlockIndex;
1048
1151
  const contentBlock = contentBlocks[blockIndex];
1049
1152
  if (contentBlock != null) {
@@ -1053,14 +1156,13 @@ var BedrockChatLanguageModel = class {
1053
1156
  id: String(blockIndex)
1054
1157
  });
1055
1158
  } else if (contentBlock.type === "text") {
1056
- if (!usesJsonResponseTool) {
1057
- controller.enqueue({
1058
- type: "text-end",
1059
- id: String(blockIndex)
1060
- });
1061
- }
1159
+ controller.enqueue({
1160
+ type: "text-end",
1161
+ id: String(blockIndex)
1162
+ });
1062
1163
  } else if (contentBlock.type === "tool-call") {
1063
- if (usesJsonResponseTool) {
1164
+ if (contentBlock.isJsonResponseTool) {
1165
+ isJsonResponseFromTool = true;
1064
1166
  controller.enqueue({
1065
1167
  type: "text-start",
1066
1168
  id: String(blockIndex)
@@ -1083,14 +1185,14 @@ var BedrockChatLanguageModel = class {
1083
1185
  type: "tool-call",
1084
1186
  toolCallId: contentBlock.toolCallId,
1085
1187
  toolName: contentBlock.toolName,
1086
- input: contentBlock.jsonText
1188
+ input: contentBlock.jsonText === "" ? "{}" : contentBlock.jsonText
1087
1189
  });
1088
1190
  }
1089
1191
  }
1090
1192
  delete contentBlocks[blockIndex];
1091
1193
  }
1092
1194
  }
1093
- if (((_o = value.contentBlockDelta) == null ? void 0 : _o.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
1195
+ if (((_g = value.contentBlockDelta) == null ? void 0 : _g.delta) && "reasoningContent" in value.contentBlockDelta.delta && value.contentBlockDelta.delta.reasoningContent) {
1094
1196
  const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
1095
1197
  const reasoningContent = value.contentBlockDelta.delta.reasoningContent;
1096
1198
  if ("text" in reasoningContent && reasoningContent.text) {
@@ -1131,16 +1233,18 @@ var BedrockChatLanguageModel = class {
1131
1233
  }
1132
1234
  }
1133
1235
  const contentBlockStart = value.contentBlockStart;
1134
- if (((_p = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _p.toolUse) != null) {
1236
+ if (((_h = contentBlockStart == null ? void 0 : contentBlockStart.start) == null ? void 0 : _h.toolUse) != null) {
1135
1237
  const toolUse = contentBlockStart.start.toolUse;
1136
1238
  const blockIndex = contentBlockStart.contentBlockIndex;
1239
+ const isJsonResponseTool = usesJsonResponseTool && toolUse.name === "json";
1137
1240
  contentBlocks[blockIndex] = {
1138
1241
  type: "tool-call",
1139
1242
  toolCallId: toolUse.toolUseId,
1140
1243
  toolName: toolUse.name,
1141
- jsonText: ""
1244
+ jsonText: "",
1245
+ isJsonResponseTool
1142
1246
  };
1143
- if (!usesJsonResponseTool) {
1247
+ if (!isJsonResponseTool) {
1144
1248
  controller.enqueue({
1145
1249
  type: "tool-input-start",
1146
1250
  id: toolUse.toolUseId,
@@ -1153,8 +1257,8 @@ var BedrockChatLanguageModel = class {
1153
1257
  const blockIndex = contentBlockDelta.contentBlockIndex;
1154
1258
  const contentBlock = contentBlocks[blockIndex];
1155
1259
  if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
1156
- const delta = (_q = contentBlockDelta.delta.toolUse.input) != null ? _q : "";
1157
- if (!usesJsonResponseTool) {
1260
+ const delta = (_i = contentBlockDelta.delta.toolUse.input) != null ? _i : "";
1261
+ if (!contentBlock.isJsonResponseTool) {
1158
1262
  controller.enqueue({
1159
1263
  type: "tool-input-delta",
1160
1264
  id: contentBlock.toolCallId,
@@ -1166,10 +1270,24 @@ var BedrockChatLanguageModel = class {
1166
1270
  }
1167
1271
  },
1168
1272
  flush(controller) {
1273
+ if (isJsonResponseFromTool) {
1274
+ if (providerMetadata) {
1275
+ providerMetadata.bedrock = {
1276
+ ...providerMetadata.bedrock,
1277
+ isJsonResponseFromTool: true
1278
+ };
1279
+ } else {
1280
+ providerMetadata = {
1281
+ bedrock: {
1282
+ isJsonResponseFromTool: true
1283
+ }
1284
+ };
1285
+ }
1286
+ }
1169
1287
  controller.enqueue({
1170
1288
  type: "finish",
1171
1289
  finishReason,
1172
- usage,
1290
+ usage: convertBedrockUsage(usage),
1173
1291
  ...providerMetadata && { providerMetadata }
1174
1292
  });
1175
1293
  }
@@ -1361,6 +1479,7 @@ var BedrockEmbeddingModel = class {
1361
1479
  abortSignal
1362
1480
  });
1363
1481
  return {
1482
+ warnings: [],
1364
1483
  embeddings: [response.embedding],
1365
1484
  usage: { tokens: response.inputTextTokenCount }
1366
1485
  };
@@ -1431,8 +1550,8 @@ var BedrockImageModel = class {
1431
1550
  };
1432
1551
  if (aspectRatio != void 0) {
1433
1552
  warnings.push({
1434
- type: "unsupported-setting",
1435
- setting: "aspectRatio",
1553
+ type: "unsupported",
1554
+ feature: "aspectRatio",
1436
1555
  details: "This model does not support aspect ratio. Use `size` instead."
1437
1556
  });
1438
1557
  }
@@ -1468,38 +1587,21 @@ var bedrockImageResponseSchema = import_v46.z.object({
1468
1587
  images: import_v46.z.array(import_v46.z.string())
1469
1588
  });
1470
1589
 
1471
- // src/headers-utils.ts
1472
- function extractHeaders(headers) {
1473
- let originalHeaders = {};
1474
- if (headers) {
1475
- if (headers instanceof Headers) {
1476
- originalHeaders = convertHeadersToRecord(headers);
1477
- } else if (Array.isArray(headers)) {
1478
- for (const [k, v] of headers) {
1479
- originalHeaders[k.toLowerCase()] = v;
1480
- }
1481
- } else {
1482
- originalHeaders = Object.fromEntries(
1483
- Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v])
1484
- );
1485
- }
1486
- }
1487
- return originalHeaders;
1488
- }
1489
- function convertHeadersToRecord(headers) {
1490
- return Object.fromEntries([...headers]);
1491
- }
1492
-
1493
1590
  // src/bedrock-sigv4-fetch.ts
1494
1591
  var import_provider_utils7 = require("@ai-sdk/provider-utils");
1495
1592
  var import_aws4fetch = require("aws4fetch");
1593
+
1594
+ // src/version.ts
1595
+ var VERSION = true ? "4.0.0-beta.100" : "0.0.0-test";
1596
+
1597
+ // src/bedrock-sigv4-fetch.ts
1496
1598
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
1497
1599
  return async (input, init) => {
1498
1600
  var _a, _b;
1499
1601
  const request = input instanceof Request ? input : void 0;
1500
1602
  const originalHeaders = (0, import_provider_utils7.combineHeaders)(
1501
- extractHeaders(request == null ? void 0 : request.headers),
1502
- extractHeaders(init == null ? void 0 : init.headers)
1603
+ (0, import_provider_utils7.normalizeHeaders)(request == null ? void 0 : request.headers),
1604
+ (0, import_provider_utils7.normalizeHeaders)(init == null ? void 0 : init.headers)
1503
1605
  );
1504
1606
  const headersWithUserAgent = (0, import_provider_utils7.withUserAgentSuffix)(
1505
1607
  originalHeaders,
@@ -1535,7 +1637,7 @@ function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
1535
1637
  service: "bedrock"
1536
1638
  });
1537
1639
  const signingResult = await signer.sign();
1538
- const signedHeaders = convertHeadersToRecord(signingResult.headers);
1640
+ const signedHeaders = (0, import_provider_utils7.normalizeHeaders)(signingResult.headers);
1539
1641
  const combinedHeaders = (0, import_provider_utils7.combineHeaders)(headersWithUserAgent, signedHeaders);
1540
1642
  return fetch(input, {
1541
1643
  ...init,
@@ -1557,7 +1659,7 @@ function prepareBodyString(body) {
1557
1659
  }
1558
1660
  function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
1559
1661
  return async (input, init) => {
1560
- const originalHeaders = extractHeaders(init == null ? void 0 : init.headers);
1662
+ const originalHeaders = (0, import_provider_utils7.normalizeHeaders)(init == null ? void 0 : init.headers);
1561
1663
  const headersWithUserAgent = (0, import_provider_utils7.withUserAgentSuffix)(
1562
1664
  originalHeaders,
1563
1665
  `ai-sdk/amazon-bedrock/${VERSION}`,
@@ -1573,15 +1675,132 @@ function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
1573
1675
  };
1574
1676
  }
1575
1677
 
1678
+ // src/reranking/bedrock-reranking-model.ts
1679
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
1680
+
1681
+ // src/reranking/bedrock-reranking-api.ts
1682
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
1683
+ var import_v47 = require("zod/v4");
1684
+ var bedrockRerankingResponseSchema = (0, import_provider_utils8.lazySchema)(
1685
+ () => (0, import_provider_utils8.zodSchema)(
1686
+ import_v47.z.object({
1687
+ results: import_v47.z.array(
1688
+ import_v47.z.object({
1689
+ index: import_v47.z.number(),
1690
+ relevanceScore: import_v47.z.number()
1691
+ })
1692
+ ),
1693
+ nextToken: import_v47.z.string().optional()
1694
+ })
1695
+ )
1696
+ );
1697
+
1698
+ // src/reranking/bedrock-reranking-options.ts
1699
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
1700
+ var import_v48 = require("zod/v4");
1701
+ var bedrockRerankingOptionsSchema = (0, import_provider_utils9.lazySchema)(
1702
+ () => (0, import_provider_utils9.zodSchema)(
1703
+ import_v48.z.object({
1704
+ /**
1705
+ * If the total number of results was greater than could fit in a response, a token is returned in the nextToken field. You can enter that token in this field to return the next batch of results.
1706
+ */
1707
+ nextToken: import_v48.z.string().optional(),
1708
+ /**
1709
+ * Additional model request fields to pass to the model.
1710
+ */
1711
+ additionalModelRequestFields: import_v48.z.record(import_v48.z.string(), import_v48.z.any()).optional()
1712
+ })
1713
+ )
1714
+ );
1715
+
1716
+ // src/reranking/bedrock-reranking-model.ts
1717
+ var BedrockRerankingModel = class {
1718
+ constructor(modelId, config) {
1719
+ this.modelId = modelId;
1720
+ this.config = config;
1721
+ this.specificationVersion = "v3";
1722
+ this.provider = "amazon-bedrock";
1723
+ }
1724
+ async doRerank({
1725
+ documents,
1726
+ headers,
1727
+ query,
1728
+ topN,
1729
+ abortSignal,
1730
+ providerOptions
1731
+ }) {
1732
+ const bedrockOptions = await (0, import_provider_utils10.parseProviderOptions)({
1733
+ provider: "bedrock",
1734
+ providerOptions,
1735
+ schema: bedrockRerankingOptionsSchema
1736
+ });
1737
+ const {
1738
+ value: response,
1739
+ responseHeaders,
1740
+ rawValue
1741
+ } = await (0, import_provider_utils10.postJsonToApi)({
1742
+ url: `${this.config.baseUrl()}/rerank`,
1743
+ headers: await (0, import_provider_utils10.resolve)(
1744
+ (0, import_provider_utils10.combineHeaders)(await (0, import_provider_utils10.resolve)(this.config.headers), headers)
1745
+ ),
1746
+ body: {
1747
+ nextToken: bedrockOptions == null ? void 0 : bedrockOptions.nextToken,
1748
+ queries: [
1749
+ {
1750
+ textQuery: { text: query },
1751
+ type: "TEXT"
1752
+ }
1753
+ ],
1754
+ rerankingConfiguration: {
1755
+ bedrockRerankingConfiguration: {
1756
+ modelConfiguration: {
1757
+ modelArn: `arn:aws:bedrock:${this.config.region}::foundation-model/${this.modelId}`,
1758
+ additionalModelRequestFields: bedrockOptions == null ? void 0 : bedrockOptions.additionalModelRequestFields
1759
+ },
1760
+ numberOfResults: topN
1761
+ },
1762
+ type: "BEDROCK_RERANKING_MODEL"
1763
+ },
1764
+ sources: documents.values.map((value) => ({
1765
+ type: "INLINE",
1766
+ inlineDocumentSource: documents.type === "text" ? {
1767
+ type: "TEXT",
1768
+ textDocument: { text: value }
1769
+ } : {
1770
+ type: "JSON",
1771
+ jsonDocument: value
1772
+ }
1773
+ }))
1774
+ },
1775
+ failedResponseHandler: (0, import_provider_utils10.createJsonErrorResponseHandler)({
1776
+ errorSchema: BedrockErrorSchema,
1777
+ errorToMessage: (error) => `${error.type}: ${error.message}`
1778
+ }),
1779
+ successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
1780
+ bedrockRerankingResponseSchema
1781
+ ),
1782
+ fetch: this.config.fetch,
1783
+ abortSignal
1784
+ });
1785
+ return {
1786
+ ranking: response.results,
1787
+ response: {
1788
+ headers: responseHeaders,
1789
+ body: rawValue
1790
+ }
1791
+ };
1792
+ }
1793
+ };
1794
+
1576
1795
  // src/bedrock-provider.ts
1577
1796
  function createAmazonBedrock(options = {}) {
1578
- const rawApiKey = (0, import_provider_utils8.loadOptionalSetting)({
1797
+ const rawApiKey = (0, import_provider_utils11.loadOptionalSetting)({
1579
1798
  settingValue: options.apiKey,
1580
1799
  environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
1581
1800
  });
1582
1801
  const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
1583
1802
  const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
1584
- const region = (0, import_provider_utils8.loadSetting)({
1803
+ const region = (0, import_provider_utils11.loadSetting)({
1585
1804
  settingValue: options.region,
1586
1805
  settingName: "region",
1587
1806
  environmentVariableName: "AWS_REGION",
@@ -1603,19 +1822,19 @@ function createAmazonBedrock(options = {}) {
1603
1822
  try {
1604
1823
  return {
1605
1824
  region,
1606
- accessKeyId: (0, import_provider_utils8.loadSetting)({
1825
+ accessKeyId: (0, import_provider_utils11.loadSetting)({
1607
1826
  settingValue: options.accessKeyId,
1608
1827
  settingName: "accessKeyId",
1609
1828
  environmentVariableName: "AWS_ACCESS_KEY_ID",
1610
1829
  description: "AWS access key ID"
1611
1830
  }),
1612
- secretAccessKey: (0, import_provider_utils8.loadSetting)({
1831
+ secretAccessKey: (0, import_provider_utils11.loadSetting)({
1613
1832
  settingValue: options.secretAccessKey,
1614
1833
  settingName: "secretAccessKey",
1615
1834
  environmentVariableName: "AWS_SECRET_ACCESS_KEY",
1616
1835
  description: "AWS secret access key"
1617
1836
  }),
1618
- sessionToken: (0, import_provider_utils8.loadOptionalSetting)({
1837
+ sessionToken: (0, import_provider_utils11.loadOptionalSetting)({
1619
1838
  settingValue: options.sessionToken,
1620
1839
  environmentVariableName: "AWS_SESSION_TOKEN"
1621
1840
  })
@@ -1641,10 +1860,15 @@ Original error: ${errorMessage}`
1641
1860
  throw error;
1642
1861
  }
1643
1862
  }, options.fetch);
1644
- const getBaseUrl = () => {
1863
+ const getHeaders = () => {
1864
+ var _a;
1865
+ const baseHeaders = (_a = options.headers) != null ? _a : {};
1866
+ return (0, import_provider_utils11.withUserAgentSuffix)(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
1867
+ };
1868
+ const getBedrockRuntimeBaseUrl = () => {
1645
1869
  var _a, _b;
1646
- return (_b = (0, import_provider_utils8.withoutTrailingSlash)(
1647
- (_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${(0, import_provider_utils8.loadSetting)({
1870
+ return (_b = (0, import_provider_utils11.withoutTrailingSlash)(
1871
+ (_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${(0, import_provider_utils11.loadSetting)({
1648
1872
  settingValue: options.region,
1649
1873
  settingName: "region",
1650
1874
  environmentVariableName: "AWS_REGION",
@@ -1652,16 +1876,22 @@ Original error: ${errorMessage}`
1652
1876
  })}.amazonaws.com`
1653
1877
  )) != null ? _b : `https://bedrock-runtime.us-east-1.amazonaws.com`;
1654
1878
  };
1655
- const getHeaders = () => {
1656
- var _a;
1657
- const baseHeaders = (_a = options.headers) != null ? _a : {};
1658
- return (0, import_provider_utils8.withUserAgentSuffix)(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
1879
+ const getBedrockAgentRuntimeBaseUrl = () => {
1880
+ var _a, _b;
1881
+ return (_b = (0, import_provider_utils11.withoutTrailingSlash)(
1882
+ (_a = options.baseURL) != null ? _a : `https://bedrock-agent-runtime.${(0, import_provider_utils11.loadSetting)({
1883
+ settingValue: options.region,
1884
+ settingName: "region",
1885
+ environmentVariableName: "AWS_REGION",
1886
+ description: "AWS region"
1887
+ })}.amazonaws.com`
1888
+ )) != null ? _b : `https://bedrock-agent-runtime.us-west-2.amazonaws.com`;
1659
1889
  };
1660
1890
  const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
1661
- baseUrl: getBaseUrl,
1891
+ baseUrl: getBedrockRuntimeBaseUrl,
1662
1892
  headers: getHeaders,
1663
1893
  fetch: fetchFunction,
1664
- generateId: import_provider_utils8.generateId
1894
+ generateId: import_provider_utils11.generateId
1665
1895
  });
1666
1896
  const provider = function(modelId) {
1667
1897
  if (new.target) {
@@ -1672,21 +1902,36 @@ Original error: ${errorMessage}`
1672
1902
  return createChatModel(modelId);
1673
1903
  };
1674
1904
  const createEmbeddingModel = (modelId) => new BedrockEmbeddingModel(modelId, {
1675
- baseUrl: getBaseUrl,
1905
+ baseUrl: getBedrockRuntimeBaseUrl,
1676
1906
  headers: getHeaders,
1677
1907
  fetch: fetchFunction
1678
1908
  });
1679
1909
  const createImageModel = (modelId) => new BedrockImageModel(modelId, {
1680
- baseUrl: getBaseUrl,
1910
+ baseUrl: getBedrockRuntimeBaseUrl,
1911
+ headers: getHeaders,
1912
+ fetch: fetchFunction
1913
+ });
1914
+ const createRerankingModel = (modelId) => new BedrockRerankingModel(modelId, {
1915
+ baseUrl: getBedrockAgentRuntimeBaseUrl,
1916
+ region: (0, import_provider_utils11.loadSetting)({
1917
+ settingValue: options.region,
1918
+ settingName: "region",
1919
+ environmentVariableName: "AWS_REGION",
1920
+ description: "AWS region"
1921
+ }),
1681
1922
  headers: getHeaders,
1682
1923
  fetch: fetchFunction
1683
1924
  });
1925
+ provider.specificationVersion = "v3";
1684
1926
  provider.languageModel = createChatModel;
1685
1927
  provider.embedding = createEmbeddingModel;
1928
+ provider.embeddingModel = createEmbeddingModel;
1686
1929
  provider.textEmbedding = createEmbeddingModel;
1687
1930
  provider.textEmbeddingModel = createEmbeddingModel;
1688
1931
  provider.image = createImageModel;
1689
1932
  provider.imageModel = createImageModel;
1933
+ provider.reranking = createRerankingModel;
1934
+ provider.rerankingModel = createRerankingModel;
1690
1935
  provider.tools = import_internal2.anthropicTools;
1691
1936
  return provider;
1692
1937
  }