@ai-sdk/anthropic 2.0.0-beta.2 → 2.0.0-beta.3

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
@@ -21,11 +21,11 @@ import {
21
21
  postJsonToApi,
22
22
  resolve
23
23
  } from "@ai-sdk/provider-utils";
24
- import { z as z4 } from "zod";
24
+ import { z as z4 } from "zod/v4";
25
25
 
26
26
  // src/anthropic-error.ts
27
27
  import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
28
- import { z } from "zod";
28
+ import { z } from "zod/v4";
29
29
  var anthropicErrorDataSchema = z.object({
30
30
  type: z.literal("error"),
31
31
  error: z.object({
@@ -39,7 +39,7 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
39
39
  });
40
40
 
41
41
  // src/anthropic-messages-options.ts
42
- import { z as z2 } from "zod";
42
+ import { z as z2 } from "zod/v4";
43
43
  var anthropicFilePartProviderOptions = z2.object({
44
44
  /**
45
45
  * Citation configuration for this document.
@@ -934,8 +934,12 @@ var AnthropicMessagesLanguageModel = class {
934
934
  tool_choice: anthropicToolChoice
935
935
  },
936
936
  warnings: [...warnings, ...toolWarnings],
937
- betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas]),
938
- jsonResponseTool
937
+ betas: /* @__PURE__ */ new Set([
938
+ "fine-grained-tool-streaming-2025-05-14",
939
+ ...messagesBetas,
940
+ ...toolsBetas
941
+ ]),
942
+ usesJsonResponseTool: jsonResponseTool != null
939
943
  };
940
944
  }
941
945
  async getHeaders({
@@ -981,7 +985,7 @@ var AnthropicMessagesLanguageModel = class {
981
985
  }
982
986
  async doGenerate(options) {
983
987
  var _a, _b, _c, _d, _e;
984
- const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
988
+ const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
985
989
  const citationDocuments = this.extractCitationDocuments(options.prompt);
986
990
  const {
987
991
  responseHeaders,
@@ -1002,7 +1006,7 @@ var AnthropicMessagesLanguageModel = class {
1002
1006
  for (const part of response.content) {
1003
1007
  switch (part.type) {
1004
1008
  case "text": {
1005
- if (jsonResponseTool == null) {
1009
+ if (!usesJsonResponseTool) {
1006
1010
  content.push({ type: "text", text: part.text });
1007
1011
  if (part.citations) {
1008
1012
  for (const citation of part.citations) {
@@ -1044,7 +1048,7 @@ var AnthropicMessagesLanguageModel = class {
1044
1048
  case "tool_use": {
1045
1049
  content.push(
1046
1050
  // when a json response tool is used, the tool call becomes the text:
1047
- jsonResponseTool != null ? {
1051
+ usesJsonResponseTool ? {
1048
1052
  type: "text",
1049
1053
  text: JSON.stringify(part.input)
1050
1054
  } : {
@@ -1121,7 +1125,7 @@ var AnthropicMessagesLanguageModel = class {
1121
1125
  content,
1122
1126
  finishReason: mapAnthropicStopReason({
1123
1127
  finishReason: response.stop_reason,
1124
- isJsonResponseFromTool: jsonResponseTool != null
1128
+ isJsonResponseFromTool: usesJsonResponseTool
1125
1129
  }),
1126
1130
  usage: {
1127
1131
  inputTokens: response.usage.input_tokens,
@@ -1145,7 +1149,7 @@ var AnthropicMessagesLanguageModel = class {
1145
1149
  };
1146
1150
  }
1147
1151
  async doStream(options) {
1148
- const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
1152
+ const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
1149
1153
  const citationDocuments = this.extractCitationDocuments(options.prompt);
1150
1154
  const body = { ...args, stream: true };
1151
1155
  const { responseHeaders, value: response } = await postJsonToApi({
@@ -1223,14 +1227,14 @@ var AnthropicMessagesLanguageModel = class {
1223
1227
  return;
1224
1228
  }
1225
1229
  case "tool_use": {
1226
- contentBlocks[value.index] = jsonResponseTool != null ? { type: "text" } : {
1230
+ contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
1227
1231
  type: "tool-call",
1228
1232
  toolCallId: value.content_block.id,
1229
1233
  toolName: value.content_block.name,
1230
1234
  input: ""
1231
1235
  };
1232
1236
  controller.enqueue(
1233
- jsonResponseTool != null ? { type: "text-start", id: String(value.index) } : {
1237
+ usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
1234
1238
  type: "tool-input-start",
1235
1239
  id: value.content_block.id,
1236
1240
  toolName: value.content_block.name
@@ -1331,7 +1335,7 @@ var AnthropicMessagesLanguageModel = class {
1331
1335
  break;
1332
1336
  }
1333
1337
  case "tool-call":
1334
- if (jsonResponseTool == null) {
1338
+ if (!usesJsonResponseTool) {
1335
1339
  controller.enqueue({
1336
1340
  type: "tool-input-end",
1337
1341
  id: contentBlock.toolCallId
@@ -1349,7 +1353,7 @@ var AnthropicMessagesLanguageModel = class {
1349
1353
  const deltaType = value.delta.type;
1350
1354
  switch (deltaType) {
1351
1355
  case "text_delta": {
1352
- if (jsonResponseTool != null) {
1356
+ if (usesJsonResponseTool) {
1353
1357
  return;
1354
1358
  }
1355
1359
  controller.enqueue({
@@ -1385,16 +1389,15 @@ var AnthropicMessagesLanguageModel = class {
1385
1389
  case "input_json_delta": {
1386
1390
  const contentBlock = contentBlocks[value.index];
1387
1391
  const delta = value.delta.partial_json;
1388
- if (jsonResponseTool == null) {
1389
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
1392
+ if (usesJsonResponseTool) {
1393
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
1390
1394
  return;
1391
1395
  }
1392
1396
  controller.enqueue({
1393
- type: "tool-input-delta",
1394
- id: contentBlock.toolCallId,
1397
+ type: "text-delta",
1398
+ id: String(value.index),
1395
1399
  delta
1396
1400
  });
1397
- contentBlock.input += delta;
1398
1401
  } else {
1399
1402
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
1400
1403
  return;
@@ -1404,6 +1407,7 @@ var AnthropicMessagesLanguageModel = class {
1404
1407
  id: contentBlock.toolCallId,
1405
1408
  delta
1406
1409
  });
1410
+ contentBlock.input += delta;
1407
1411
  }
1408
1412
  return;
1409
1413
  }
@@ -1445,7 +1449,7 @@ var AnthropicMessagesLanguageModel = class {
1445
1449
  usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
1446
1450
  finishReason = mapAnthropicStopReason({
1447
1451
  finishReason: value.delta.stop_reason,
1448
- isJsonResponseFromTool: jsonResponseTool != null
1452
+ isJsonResponseFromTool: usesJsonResponseTool
1449
1453
  });
1450
1454
  return;
1451
1455
  }
@@ -1505,7 +1509,7 @@ var anthropicMessagesResponseSchema = z4.object({
1505
1509
  type: z4.literal("server_tool_use"),
1506
1510
  id: z4.string(),
1507
1511
  name: z4.string(),
1508
- input: z4.record(z4.unknown()).nullish()
1512
+ input: z4.record(z4.string(), z4.unknown()).nullish()
1509
1513
  }),
1510
1514
  z4.object({
1511
1515
  type: z4.literal("web_search_tool_result"),
@@ -1578,7 +1582,7 @@ var anthropicMessagesChunkSchema = z4.discriminatedUnion("type", [
1578
1582
  type: z4.literal("server_tool_use"),
1579
1583
  id: z4.string(),
1580
1584
  name: z4.string(),
1581
- input: z4.record(z4.unknown()).nullish()
1585
+ input: z4.record(z4.string(), z4.unknown()).nullish()
1582
1586
  }),
1583
1587
  z4.object({
1584
1588
  type: z4.literal("web_search_tool_result"),