@ai-sdk/amazon-bedrock 3.0.141 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 3.0.143
4
+
5
+ ### Patch Changes
6
+
7
+ - 0a069bd: Enable native structured output for supported Claude 5 models on Bedrock. In automatic mode, Bedrock and Anthropic now fall back for schemas that native structured output cannot represent: recursive references, open objects, or more than ten optional properties. Anthropic uses the JSON response tool; Bedrock Converse uses the JSON tool or JSON instructions for models that reject forced tool use. The JSON-tool fallback excludes disabled and unselected application tools. Explicit `outputFormat` selection remains unchanged.
8
+ - 0a069bd: Default to disabling parallel tool use for named Anthropic tool choices on models that support forced tools. Preserve the complete function tool catalog and prompt cache compatibility. An explicit `providerOptions.anthropic.disableParallelToolUse: false` keeps parallel calls enabled.
9
+ - 0a069bd: fix(amazon-bedrock): parse JSON string tool inputs and safely serialize BigInt and cycles in tool outputs
10
+ - Updated dependencies [0a069bd]
11
+ - Updated dependencies [0a069bd]
12
+ - Updated dependencies [0a069bd]
13
+ - Updated dependencies [0a069bd]
14
+ - Updated dependencies [0a069bd]
15
+ - Updated dependencies [0a069bd]
16
+ - @ai-sdk/anthropic@2.0.112
17
+ - @ai-sdk/provider-utils@3.0.44
18
+
19
+ ## 3.0.142
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [a1a772f]
24
+ - @ai-sdk/provider-utils@3.0.43
25
+ - @ai-sdk/anthropic@2.0.111
26
+
3
27
  ## 3.0.141
4
28
 
5
29
  ### Patch Changes
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
35
35
  var import_aws4fetch = require("aws4fetch");
36
36
 
37
37
  // src/version.ts
38
- var VERSION = true ? "3.0.141" : "0.0.0-test";
38
+ var VERSION = true ? "3.0.143" : "0.0.0-test";
39
39
 
40
40
  // src/bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
@@ -23,7 +23,7 @@ import {
23
23
  import { AwsV4Signer } from "aws4fetch";
24
24
 
25
25
  // src/version.ts
26
- var VERSION = true ? "3.0.141" : "0.0.0-test";
26
+ var VERSION = true ? "3.0.143" : "0.0.0-test";
27
27
 
28
28
  // src/bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch = globalThis.fetch) {
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
30
30
  var import_provider_utils13 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "3.0.141" : "0.0.0-test";
33
+ var VERSION = true ? "3.0.143" : "0.0.0-test";
34
34
 
35
35
  // src/bedrock-provider.ts
36
36
  var import_internal3 = require("@ai-sdk/anthropic/internal");
@@ -142,6 +142,11 @@ function isAnthropicModel({
142
142
  }) {
143
143
  return modelFamily === "anthropic" || modelId.includes("anthropic") || modelId.includes(":application-inference-profile/") && reasoningBudgetTokens != null;
144
144
  }
145
+ function supportsClaude5NativeStructuredOutput(modelId) {
146
+ return /claude-(?:(?:opus|sonnet)-5(?:-5)?|haiku-5-5)(?:-\d{8})?(?:-v\d+)?(?=[:.]|$)/.test(
147
+ modelId
148
+ );
149
+ }
145
150
 
146
151
  // src/bedrock-error.ts
147
152
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
@@ -304,6 +309,7 @@ async function prepareTools({
304
309
  reasoningBudgetTokens
305
310
  });
306
311
  const functionTools = supportedTools.filter((t) => t.type === "function");
312
+ const disableParallelToolUseForRequest = disableParallelToolUse != null ? disableParallelToolUse : isAnthropicModel2 && (toolChoice == null ? void 0 : toolChoice.type) === "tool" && !(0, import_internal.getModelCapabilities)(modelId).rejectsForcedToolUse ? true : void 0;
307
313
  let additionalTools = void 0;
308
314
  const bedrockTools = [];
309
315
  const usingAnthropicTools = isAnthropicModel2 && providerDefinedTools.length > 0;
@@ -322,7 +328,7 @@ async function prepareTools({
322
328
  } = await (0, import_internal.prepareTools)({
323
329
  tools: providerDefinedTools,
324
330
  toolChoice,
325
- disableParallelToolUse
331
+ disableParallelToolUse: disableParallelToolUseForRequest
326
332
  });
327
333
  toolWarnings.push(...anthropicToolWarnings);
328
334
  anthropicBetas.forEach((beta) => betas.add(beta));
@@ -366,7 +372,7 @@ async function prepareTools({
366
372
  }
367
373
  });
368
374
  }
369
- if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
375
+ if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUseForRequest && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
370
376
  additionalTools = {
371
377
  tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
372
378
  type: "tool",
@@ -574,7 +580,7 @@ async function convertToBedrockChatMessages(prompt) {
574
580
  case "error-json":
575
581
  default:
576
582
  toolResultContent = [
577
- { text: JSON.stringify(output.value) }
583
+ { text: (0, import_provider_utils6.stringifyWithBigIntAndCycles)(output.value) }
578
584
  ];
579
585
  break;
580
586
  }
@@ -705,6 +711,15 @@ async function convertToBedrockChatMessages(prompt) {
705
711
  return { system, messages };
706
712
  }
707
713
  function toBedrockToolInput(input) {
714
+ if (typeof input === "string") {
715
+ try {
716
+ const parsed = (0, import_provider_utils6.secureJsonParse)(input);
717
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
718
+ return parsed;
719
+ }
720
+ } catch (e) {
721
+ }
722
+ }
708
723
  return typeof input === "object" && input !== null && !Array.isArray(input) ? input : { rawInvalidInput: input };
709
724
  }
710
725
  function getBedrockImageFormat(mimeType) {
@@ -914,8 +929,8 @@ var BedrockChatLanguageModel = class {
914
929
  bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
915
930
  }
916
931
  }
917
- const modelSupportsNativeStructuredOutput = this.config.modelFamily === "anthropic" || supportsNativeStructuredOutput(this.modelId) && isThinkingRequested;
918
- const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
932
+ const modelSupportsNativeStructuredOutput = this.config.modelFamily === "anthropic" || supportsClaude5NativeStructuredOutput(this.modelId) || supportsNativeStructuredOutput(this.modelId) && isThinkingRequested;
933
+ const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput && (0, import_internal2.supportsNativeStructuredOutputSchema)(responseFormat.schema));
919
934
  const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && rejectsForcedToolUse;
920
935
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
921
936
  type: "function",
@@ -924,7 +939,12 @@ var BedrockChatLanguageModel = class {
924
939
  inputSchema: responseFormat.schema
925
940
  } : void 0;
926
941
  const { toolConfig, additionalTools, toolWarnings, betas } = await prepareTools({
927
- tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
942
+ tools: jsonResponseTool ? [
943
+ ...(tools != null ? tools : []).filter(
944
+ (tool) => (toolChoice == null ? void 0 : toolChoice.type) !== "none" && ((toolChoice == null ? void 0 : toolChoice.type) !== "tool" || tool.name === toolChoice.toolName)
945
+ ),
946
+ jsonResponseTool
947
+ ] : tools,
928
948
  toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
929
949
  modelId: this.modelId,
930
950
  modelFamily: this.config.modelFamily,