@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.
@@ -2126,6 +2126,7 @@ import {
2126
2126
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
2127
2127
  } from "@ai-sdk/provider";
2128
2128
  import {
2129
+ stringifyWithBigIntAndCycles,
2129
2130
  convertBase64ToUint8Array,
2130
2131
  convertToBase64,
2131
2132
  parseProviderOptions,
@@ -2840,7 +2841,7 @@ async function convertToAnthropicMessagesPrompt({
2840
2841
  case "json":
2841
2842
  case "error-json":
2842
2843
  default:
2843
- contentValue = JSON.stringify(output.value);
2844
+ contentValue = stringifyWithBigIntAndCycles(output.value);
2844
2845
  break;
2845
2846
  }
2846
2847
  const toolsetName = getAnthropicToolsetName({
@@ -3078,7 +3079,7 @@ async function convertToAnthropicMessagesPrompt({
3078
3079
  type: "tool_use",
3079
3080
  id: part.toolCallId,
3080
3081
  name: part.toolName,
3081
- input: part.input,
3082
+ input: parseToolCallInput(part.input),
3082
3083
  ...caller && { caller },
3083
3084
  cache_control: cacheControl
3084
3085
  });
@@ -3563,6 +3564,18 @@ function getAnthropicCaller(providerOptions) {
3563
3564
  }
3564
3565
  return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
3565
3566
  }
3567
+ function parseToolCallInput(input) {
3568
+ if (typeof input === "string") {
3569
+ try {
3570
+ const parsed = secureJsonParse(input);
3571
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
3572
+ return parsed;
3573
+ }
3574
+ } catch (e) {
3575
+ }
3576
+ }
3577
+ return input;
3578
+ }
3566
3579
 
3567
3580
  // src/map-anthropic-stop-reason.ts
3568
3581
  function mapAnthropicStopReason({
@@ -4155,9 +4168,10 @@ var AnthropicMessagesLanguageModel = class {
4155
4168
  }
4156
4169
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
4157
4170
  const supportsStructuredOutput = ((_b = this.config.supportsNativeStructuredOutput) != null ? _b : true) && modelSupportsStructuredOutput;
4171
+ const supportsResponseSchema = (responseFormat == null ? void 0 : responseFormat.type) !== "json" || responseFormat.schema == null || supportsNativeStructuredOutputSchema(responseFormat.schema);
4158
4172
  const supportsStrictTools = ((_c = this.config.supportsStrictTools) != null ? _c : true) && modelSupportsStructuredOutput;
4159
4173
  const structureOutputMode = (_d = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _d : "auto";
4160
- let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
4174
+ let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput && supportsResponseSchema;
4161
4175
  if (!useStructuredOutput && rejectsForcedToolUse && modelSupportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && supportsNativeStructuredOutputSchema(responseFormat.schema)) {
4162
4176
  warnings.push({
4163
4177
  type: "unsupported",
@@ -4530,7 +4544,12 @@ var AnthropicMessagesLanguageModel = class {
4530
4544
  betas: toolsBetas
4531
4545
  } = await prepareTools(
4532
4546
  jsonResponseTool != null ? {
4533
- tools: [...tools != null ? tools : [], jsonResponseTool],
4547
+ tools: [
4548
+ ...(tools != null ? tools : []).filter(
4549
+ (tool) => (toolChoice == null ? void 0 : toolChoice.type) !== "none" && ((toolChoice == null ? void 0 : toolChoice.type) !== "tool" || tool.name === toolChoice.toolName)
4550
+ ),
4551
+ jsonResponseTool
4552
+ ],
4534
4553
  toolChoice: { type: "required" },
4535
4554
  disableParallelToolUse: true,
4536
4555
  cacheControlValidator,
@@ -6988,6 +7007,7 @@ export {
6988
7007
  anthropicTools,
6989
7008
  getModelCapabilities,
6990
7009
  prepareTools,
6991
- sanitizeJsonSchema
7010
+ sanitizeJsonSchema,
7011
+ supportsNativeStructuredOutputSchema
6992
7012
  };
6993
7013
  //# sourceMappingURL=index.mjs.map