@ai-sdk/anthropic 3.0.137 → 3.0.138

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
@@ -12,7 +12,7 @@ import {
12
12
  } from "@ai-sdk/provider-utils";
13
13
 
14
14
  // src/version.ts
15
- var VERSION = true ? "3.0.137" : "0.0.0-test";
15
+ var VERSION = true ? "3.0.138" : "0.0.0-test";
16
16
 
17
17
  // src/anthropic-messages-language-model.ts
18
18
  import {
@@ -2142,6 +2142,7 @@ import {
2142
2142
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
2143
2143
  } from "@ai-sdk/provider";
2144
2144
  import {
2145
+ stringifyWithBigIntAndCycles,
2145
2146
  convertBase64ToUint8Array,
2146
2147
  convertToBase64,
2147
2148
  parseProviderOptions,
@@ -2856,7 +2857,7 @@ async function convertToAnthropicMessagesPrompt({
2856
2857
  case "json":
2857
2858
  case "error-json":
2858
2859
  default:
2859
- contentValue = JSON.stringify(output.value);
2860
+ contentValue = stringifyWithBigIntAndCycles(output.value);
2860
2861
  break;
2861
2862
  }
2862
2863
  const toolsetName = getAnthropicToolsetName({
@@ -3094,7 +3095,7 @@ async function convertToAnthropicMessagesPrompt({
3094
3095
  type: "tool_use",
3095
3096
  id: part.toolCallId,
3096
3097
  name: part.toolName,
3097
- input: part.input,
3098
+ input: parseToolCallInput(part.input),
3098
3099
  ...caller && { caller },
3099
3100
  cache_control: cacheControl
3100
3101
  });
@@ -3579,6 +3580,18 @@ function getAnthropicCaller(providerOptions) {
3579
3580
  }
3580
3581
  return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
3581
3582
  }
3583
+ function parseToolCallInput(input) {
3584
+ if (typeof input === "string") {
3585
+ try {
3586
+ const parsed = secureJsonParse(input);
3587
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
3588
+ return parsed;
3589
+ }
3590
+ } catch (e) {
3591
+ }
3592
+ }
3593
+ return input;
3594
+ }
3582
3595
 
3583
3596
  // src/map-anthropic-stop-reason.ts
3584
3597
  function mapAnthropicStopReason({
@@ -4171,9 +4184,10 @@ var AnthropicMessagesLanguageModel = class {
4171
4184
  }
4172
4185
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
4173
4186
  const supportsStructuredOutput = ((_b = this.config.supportsNativeStructuredOutput) != null ? _b : true) && modelSupportsStructuredOutput;
4187
+ const supportsResponseSchema = (responseFormat == null ? void 0 : responseFormat.type) !== "json" || responseFormat.schema == null || supportsNativeStructuredOutputSchema(responseFormat.schema);
4174
4188
  const supportsStrictTools = ((_c = this.config.supportsStrictTools) != null ? _c : true) && modelSupportsStructuredOutput;
4175
4189
  const structureOutputMode = (_d = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _d : "auto";
4176
- let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
4190
+ let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput && supportsResponseSchema;
4177
4191
  if (!useStructuredOutput && rejectsForcedToolUse && modelSupportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && supportsNativeStructuredOutputSchema(responseFormat.schema)) {
4178
4192
  warnings.push({
4179
4193
  type: "unsupported",
@@ -4546,7 +4560,12 @@ var AnthropicMessagesLanguageModel = class {
4546
4560
  betas: toolsBetas
4547
4561
  } = await prepareTools(
4548
4562
  jsonResponseTool != null ? {
4549
- tools: [...tools != null ? tools : [], jsonResponseTool],
4563
+ tools: [
4564
+ ...(tools != null ? tools : []).filter(
4565
+ (tool) => (toolChoice == null ? void 0 : toolChoice.type) !== "none" && ((toolChoice == null ? void 0 : toolChoice.type) !== "tool" || tool.name === toolChoice.toolName)
4566
+ ),
4567
+ jsonResponseTool
4568
+ ],
4550
4569
  toolChoice: { type: "required" },
4551
4570
  disableParallelToolUse: true,
4552
4571
  cacheControlValidator,