@ai-sdk/anthropic 3.0.0-beta.43 → 3.0.0-beta.44

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
@@ -11,7 +11,7 @@ import {
11
11
  } from "@ai-sdk/provider-utils";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = true ? "3.0.0-beta.43" : "0.0.0-test";
14
+ var VERSION = true ? "3.0.0-beta.44" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
@@ -1928,12 +1928,6 @@ var AnthropicMessagesLanguageModel = class {
1928
1928
  setting: "responseFormat",
1929
1929
  details: "JSON response format requires a schema. The response format is ignored."
1930
1930
  });
1931
- } else if (tools != null) {
1932
- warnings.push({
1933
- type: "unsupported-setting",
1934
- setting: "tools",
1935
- details: "JSON response format does not support tools. The provided tools are ignored."
1936
- });
1937
1931
  }
1938
1932
  }
1939
1933
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
@@ -2064,8 +2058,8 @@ var AnthropicMessagesLanguageModel = class {
2064
2058
  betas: toolsBetas
2065
2059
  } = await prepareTools(
2066
2060
  jsonResponseTool != null ? {
2067
- tools: [jsonResponseTool],
2068
- toolChoice: { type: "tool", toolName: jsonResponseTool.name },
2061
+ tools: [...tools != null ? tools : [], jsonResponseTool],
2062
+ toolChoice: { type: "required" },
2069
2063
  disableParallelToolUse: true,
2070
2064
  cacheControlValidator
2071
2065
  } : {
@@ -2149,6 +2143,7 @@ var AnthropicMessagesLanguageModel = class {
2149
2143
  });
2150
2144
  const content = [];
2151
2145
  const mcpToolCalls = {};
2146
+ let isJsonResponseFromTool = false;
2152
2147
  for (const part of response.content) {
2153
2148
  switch (part.type) {
2154
2149
  case "text": {
@@ -2194,18 +2189,21 @@ var AnthropicMessagesLanguageModel = class {
2194
2189
  break;
2195
2190
  }
2196
2191
  case "tool_use": {
2197
- content.push(
2198
- // when a json response tool is used, the tool call becomes the text:
2199
- usesJsonResponseTool ? {
2192
+ const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2193
+ if (isJsonResponseTool) {
2194
+ isJsonResponseFromTool = true;
2195
+ content.push({
2200
2196
  type: "text",
2201
2197
  text: JSON.stringify(part.input)
2202
- } : {
2198
+ });
2199
+ } else {
2200
+ content.push({
2203
2201
  type: "tool-call",
2204
2202
  toolCallId: part.id,
2205
2203
  toolName: part.name,
2206
2204
  input: JSON.stringify(part.input)
2207
- }
2208
- );
2205
+ });
2206
+ }
2209
2207
  break;
2210
2208
  }
2211
2209
  case "server_tool_use": {
@@ -2392,7 +2390,7 @@ var AnthropicMessagesLanguageModel = class {
2392
2390
  content,
2393
2391
  finishReason: mapAnthropicStopReason({
2394
2392
  finishReason: response.stop_reason,
2395
- isJsonResponseFromTool: usesJsonResponseTool
2393
+ isJsonResponseFromTool
2396
2394
  }),
2397
2395
  usage: {
2398
2396
  inputTokens: response.usage.input_tokens,
@@ -2453,6 +2451,7 @@ var AnthropicMessagesLanguageModel = class {
2453
2451
  let cacheCreationInputTokens = null;
2454
2452
  let stopSequence = null;
2455
2453
  let container = null;
2454
+ let isJsonResponseFromTool = false;
2456
2455
  let blockType = void 0;
2457
2456
  const generateId3 = this.generateId;
2458
2457
  return {
@@ -2481,6 +2480,9 @@ var AnthropicMessagesLanguageModel = class {
2481
2480
  blockType = contentBlockType;
2482
2481
  switch (contentBlockType) {
2483
2482
  case "text": {
2483
+ if (usesJsonResponseTool) {
2484
+ return;
2485
+ }
2484
2486
  contentBlocks[value.index] = { type: "text" };
2485
2487
  controller.enqueue({
2486
2488
  type: "text-start",
@@ -2510,20 +2512,28 @@ var AnthropicMessagesLanguageModel = class {
2510
2512
  return;
2511
2513
  }
2512
2514
  case "tool_use": {
2513
- contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
2514
- type: "tool-call",
2515
- toolCallId: part.id,
2516
- toolName: part.name,
2517
- input: "",
2518
- firstDelta: true
2519
- };
2520
- controller.enqueue(
2521
- usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
2515
+ const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2516
+ if (isJsonResponseTool) {
2517
+ isJsonResponseFromTool = true;
2518
+ contentBlocks[value.index] = { type: "text" };
2519
+ controller.enqueue({
2520
+ type: "text-start",
2521
+ id: String(value.index)
2522
+ });
2523
+ } else {
2524
+ contentBlocks[value.index] = {
2525
+ type: "tool-call",
2526
+ toolCallId: part.id,
2527
+ toolName: part.name,
2528
+ input: "",
2529
+ firstDelta: true
2530
+ };
2531
+ controller.enqueue({
2522
2532
  type: "tool-input-start",
2523
2533
  id: part.id,
2524
2534
  toolName: part.name
2525
- }
2526
- );
2535
+ });
2536
+ }
2527
2537
  return;
2528
2538
  }
2529
2539
  case "server_tool_use": {
@@ -2739,7 +2749,8 @@ var AnthropicMessagesLanguageModel = class {
2739
2749
  break;
2740
2750
  }
2741
2751
  case "tool-call":
2742
- if (!usesJsonResponseTool) {
2752
+ const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
2753
+ if (!isJsonResponseTool) {
2743
2754
  controller.enqueue({
2744
2755
  type: "tool-input-end",
2745
2756
  id: contentBlock.toolCallId
@@ -2803,7 +2814,7 @@ var AnthropicMessagesLanguageModel = class {
2803
2814
  if (delta.length === 0) {
2804
2815
  return;
2805
2816
  }
2806
- if (usesJsonResponseTool) {
2817
+ if (isJsonResponseFromTool) {
2807
2818
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
2808
2819
  return;
2809
2820
  }
@@ -2868,7 +2879,7 @@ var AnthropicMessagesLanguageModel = class {
2868
2879
  usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
2869
2880
  finishReason = mapAnthropicStopReason({
2870
2881
  finishReason: value.delta.stop_reason,
2871
- isJsonResponseFromTool: usesJsonResponseTool
2882
+ isJsonResponseFromTool
2872
2883
  });
2873
2884
  stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
2874
2885
  container = value.delta.container != null ? {