@ai-sdk/amazon-bedrock 3.0.142 → 3.0.143

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.mjs CHANGED
@@ -7,15 +7,16 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "3.0.142" : "0.0.0-test";
10
+ var VERSION = true ? "3.0.143" : "0.0.0-test";
11
11
 
12
12
  // src/bedrock-provider.ts
13
13
  import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
14
14
 
15
15
  // src/bedrock-chat-language-model.ts
16
16
  import {
17
- getModelCapabilities,
18
- sanitizeJsonSchema
17
+ getModelCapabilities as getModelCapabilities2,
18
+ sanitizeJsonSchema,
19
+ supportsNativeStructuredOutputSchema
19
20
  } from "@ai-sdk/anthropic/internal";
20
21
  import {
21
22
  lazySchema as lazySchema4,
@@ -135,6 +136,11 @@ function isAnthropicModel({
135
136
  }) {
136
137
  return modelFamily === "anthropic" || modelId.includes("anthropic") || modelId.includes(":application-inference-profile/") && reasoningBudgetTokens != null;
137
138
  }
139
+ function supportsClaude5NativeStructuredOutput(modelId) {
140
+ return /claude-(?:(?:opus|sonnet)-5(?:-5)?|haiku-5-5)(?:-\d{8})?(?:-v\d+)?(?=[:.]|$)/.test(
141
+ modelId
142
+ );
143
+ }
138
144
 
139
145
  // src/bedrock-error.ts
140
146
  import {
@@ -261,6 +267,7 @@ import {
261
267
  import { asSchema } from "@ai-sdk/provider-utils";
262
268
  import {
263
269
  anthropicTools,
270
+ getModelCapabilities,
264
271
  prepareTools as prepareAnthropicTools
265
272
  } from "@ai-sdk/anthropic/internal";
266
273
  async function prepareTools({
@@ -310,6 +317,7 @@ async function prepareTools({
310
317
  reasoningBudgetTokens
311
318
  });
312
319
  const functionTools = supportedTools.filter((t) => t.type === "function");
320
+ const disableParallelToolUseForRequest = disableParallelToolUse != null ? disableParallelToolUse : isAnthropicModel2 && (toolChoice == null ? void 0 : toolChoice.type) === "tool" && !getModelCapabilities(modelId).rejectsForcedToolUse ? true : void 0;
313
321
  let additionalTools = void 0;
314
322
  const bedrockTools = [];
315
323
  const usingAnthropicTools = isAnthropicModel2 && providerDefinedTools.length > 0;
@@ -328,7 +336,7 @@ async function prepareTools({
328
336
  } = await prepareAnthropicTools({
329
337
  tools: providerDefinedTools,
330
338
  toolChoice,
331
- disableParallelToolUse
339
+ disableParallelToolUse: disableParallelToolUseForRequest
332
340
  });
333
341
  toolWarnings.push(...anthropicToolWarnings);
334
342
  anthropicBetas.forEach((beta) => betas.add(beta));
@@ -372,7 +380,7 @@ async function prepareTools({
372
380
  }
373
381
  });
374
382
  }
375
- if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
383
+ if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUseForRequest && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
376
384
  additionalTools = {
377
385
  tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
378
386
  type: "tool",
@@ -419,7 +427,12 @@ async function prepareTools({
419
427
  import {
420
428
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
421
429
  } from "@ai-sdk/provider";
422
- import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
430
+ import {
431
+ stringifyWithBigIntAndCycles,
432
+ secureJsonParse,
433
+ convertToBase64,
434
+ parseProviderOptions
435
+ } from "@ai-sdk/provider-utils";
423
436
 
424
437
  // src/bedrock-reasoning-metadata.ts
425
438
  import {
@@ -585,7 +598,7 @@ async function convertToBedrockChatMessages(prompt) {
585
598
  case "error-json":
586
599
  default:
587
600
  toolResultContent = [
588
- { text: JSON.stringify(output.value) }
601
+ { text: stringifyWithBigIntAndCycles(output.value) }
589
602
  ];
590
603
  break;
591
604
  }
@@ -716,6 +729,15 @@ async function convertToBedrockChatMessages(prompt) {
716
729
  return { system, messages };
717
730
  }
718
731
  function toBedrockToolInput(input) {
732
+ if (typeof input === "string") {
733
+ try {
734
+ const parsed = secureJsonParse(input);
735
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
736
+ return parsed;
737
+ }
738
+ } catch (e) {
739
+ }
740
+ }
719
741
  return typeof input === "object" && input !== null && !Array.isArray(input) ? input : { rawInvalidInput: input };
720
742
  }
721
743
  function getBedrockImageFormat(mimeType) {
@@ -907,7 +929,7 @@ var BedrockChatLanguageModel = class {
907
929
  const isOpenAIModel = openAIModelId != null;
908
930
  const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
909
931
  const isThinkingRequested = ((_e = bedrockOptions.reasoningConfig) == null ? void 0 : _e.type) === "enabled" || ((_f = bedrockOptions.reasoningConfig) == null ? void 0 : _f.type) === "adaptive";
910
- const { rejectsForcedToolUse } = getModelCapabilities(this.modelId);
932
+ const { rejectsForcedToolUse } = getModelCapabilities2(this.modelId);
911
933
  const structuredOutputMode = (_h = (_g = bedrockOptions.structuredOutputMode) != null ? _g : anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _h : "auto";
912
934
  if (structuredOutputMode === "jsonTool") {
913
935
  const additionalModelRequestFields = {
@@ -925,8 +947,8 @@ var BedrockChatLanguageModel = class {
925
947
  bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
926
948
  }
927
949
  }
928
- const modelSupportsNativeStructuredOutput = this.config.modelFamily === "anthropic" || supportsNativeStructuredOutput(this.modelId) && isThinkingRequested;
929
- const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
950
+ const modelSupportsNativeStructuredOutput = this.config.modelFamily === "anthropic" || supportsClaude5NativeStructuredOutput(this.modelId) || supportsNativeStructuredOutput(this.modelId) && isThinkingRequested;
951
+ const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput && supportsNativeStructuredOutputSchema(responseFormat.schema));
930
952
  const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && rejectsForcedToolUse;
931
953
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
932
954
  type: "function",
@@ -935,7 +957,12 @@ var BedrockChatLanguageModel = class {
935
957
  inputSchema: responseFormat.schema
936
958
  } : void 0;
937
959
  const { toolConfig, additionalTools, toolWarnings, betas } = await prepareTools({
938
- tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
960
+ tools: jsonResponseTool ? [
961
+ ...(tools != null ? tools : []).filter(
962
+ (tool) => (toolChoice == null ? void 0 : toolChoice.type) !== "none" && ((toolChoice == null ? void 0 : toolChoice.type) !== "tool" || tool.name === toolChoice.toolName)
963
+ ),
964
+ jsonResponseTool
965
+ ] : tools,
939
966
  toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
940
967
  modelId: this.modelId,
941
968
  modelFamily: this.config.modelFamily,