@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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +4 -22
- package/dist/index.d.ts +4 -22
- package/dist/index.js +254 -250
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -22
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +254 -250
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +26 -22
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.mjs
CHANGED
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
postJsonToApi,
|
|
12
12
|
resolve
|
|
13
13
|
} from "@ai-sdk/provider-utils";
|
|
14
|
-
import { z as z4 } from "zod";
|
|
14
|
+
import { z as z4 } from "zod/v4";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-error.ts
|
|
17
17
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
18
|
-
import { z } from "zod";
|
|
18
|
+
import { z } from "zod/v4";
|
|
19
19
|
var anthropicErrorDataSchema = z.object({
|
|
20
20
|
type: z.literal("error"),
|
|
21
21
|
error: z.object({
|
|
@@ -29,7 +29,7 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
// src/anthropic-messages-options.ts
|
|
32
|
-
import { z as z2 } from "zod";
|
|
32
|
+
import { z as z2 } from "zod/v4";
|
|
33
33
|
var anthropicFilePartProviderOptions = z2.object({
|
|
34
34
|
/**
|
|
35
35
|
* Citation configuration for this document.
|
|
@@ -924,8 +924,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
924
924
|
tool_choice: anthropicToolChoice
|
|
925
925
|
},
|
|
926
926
|
warnings: [...warnings, ...toolWarnings],
|
|
927
|
-
betas: /* @__PURE__ */ new Set([
|
|
928
|
-
|
|
927
|
+
betas: /* @__PURE__ */ new Set([
|
|
928
|
+
"fine-grained-tool-streaming-2025-05-14",
|
|
929
|
+
...messagesBetas,
|
|
930
|
+
...toolsBetas
|
|
931
|
+
]),
|
|
932
|
+
usesJsonResponseTool: jsonResponseTool != null
|
|
929
933
|
};
|
|
930
934
|
}
|
|
931
935
|
async getHeaders({
|
|
@@ -971,7 +975,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
971
975
|
}
|
|
972
976
|
async doGenerate(options) {
|
|
973
977
|
var _a, _b, _c, _d, _e;
|
|
974
|
-
const { args, warnings, betas,
|
|
978
|
+
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
975
979
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
976
980
|
const {
|
|
977
981
|
responseHeaders,
|
|
@@ -992,7 +996,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
992
996
|
for (const part of response.content) {
|
|
993
997
|
switch (part.type) {
|
|
994
998
|
case "text": {
|
|
995
|
-
if (
|
|
999
|
+
if (!usesJsonResponseTool) {
|
|
996
1000
|
content.push({ type: "text", text: part.text });
|
|
997
1001
|
if (part.citations) {
|
|
998
1002
|
for (const citation of part.citations) {
|
|
@@ -1034,7 +1038,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1034
1038
|
case "tool_use": {
|
|
1035
1039
|
content.push(
|
|
1036
1040
|
// when a json response tool is used, the tool call becomes the text:
|
|
1037
|
-
|
|
1041
|
+
usesJsonResponseTool ? {
|
|
1038
1042
|
type: "text",
|
|
1039
1043
|
text: JSON.stringify(part.input)
|
|
1040
1044
|
} : {
|
|
@@ -1111,7 +1115,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1111
1115
|
content,
|
|
1112
1116
|
finishReason: mapAnthropicStopReason({
|
|
1113
1117
|
finishReason: response.stop_reason,
|
|
1114
|
-
isJsonResponseFromTool:
|
|
1118
|
+
isJsonResponseFromTool: usesJsonResponseTool
|
|
1115
1119
|
}),
|
|
1116
1120
|
usage: {
|
|
1117
1121
|
inputTokens: response.usage.input_tokens,
|
|
@@ -1135,7 +1139,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1135
1139
|
};
|
|
1136
1140
|
}
|
|
1137
1141
|
async doStream(options) {
|
|
1138
|
-
const { args, warnings, betas,
|
|
1142
|
+
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
1139
1143
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
1140
1144
|
const body = { ...args, stream: true };
|
|
1141
1145
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
@@ -1213,14 +1217,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1213
1217
|
return;
|
|
1214
1218
|
}
|
|
1215
1219
|
case "tool_use": {
|
|
1216
|
-
contentBlocks[value.index] =
|
|
1220
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
1217
1221
|
type: "tool-call",
|
|
1218
1222
|
toolCallId: value.content_block.id,
|
|
1219
1223
|
toolName: value.content_block.name,
|
|
1220
1224
|
input: ""
|
|
1221
1225
|
};
|
|
1222
1226
|
controller.enqueue(
|
|
1223
|
-
|
|
1227
|
+
usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
|
|
1224
1228
|
type: "tool-input-start",
|
|
1225
1229
|
id: value.content_block.id,
|
|
1226
1230
|
toolName: value.content_block.name
|
|
@@ -1321,7 +1325,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1321
1325
|
break;
|
|
1322
1326
|
}
|
|
1323
1327
|
case "tool-call":
|
|
1324
|
-
if (
|
|
1328
|
+
if (!usesJsonResponseTool) {
|
|
1325
1329
|
controller.enqueue({
|
|
1326
1330
|
type: "tool-input-end",
|
|
1327
1331
|
id: contentBlock.toolCallId
|
|
@@ -1339,7 +1343,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1339
1343
|
const deltaType = value.delta.type;
|
|
1340
1344
|
switch (deltaType) {
|
|
1341
1345
|
case "text_delta": {
|
|
1342
|
-
if (
|
|
1346
|
+
if (usesJsonResponseTool) {
|
|
1343
1347
|
return;
|
|
1344
1348
|
}
|
|
1345
1349
|
controller.enqueue({
|
|
@@ -1375,16 +1379,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1375
1379
|
case "input_json_delta": {
|
|
1376
1380
|
const contentBlock = contentBlocks[value.index];
|
|
1377
1381
|
const delta = value.delta.partial_json;
|
|
1378
|
-
if (
|
|
1379
|
-
if ((contentBlock == null ? void 0 : contentBlock.type) !== "
|
|
1382
|
+
if (usesJsonResponseTool) {
|
|
1383
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
1380
1384
|
return;
|
|
1381
1385
|
}
|
|
1382
1386
|
controller.enqueue({
|
|
1383
|
-
type: "
|
|
1384
|
-
id:
|
|
1387
|
+
type: "text-delta",
|
|
1388
|
+
id: String(value.index),
|
|
1385
1389
|
delta
|
|
1386
1390
|
});
|
|
1387
|
-
contentBlock.input += delta;
|
|
1388
1391
|
} else {
|
|
1389
1392
|
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
1390
1393
|
return;
|
|
@@ -1394,6 +1397,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1394
1397
|
id: contentBlock.toolCallId,
|
|
1395
1398
|
delta
|
|
1396
1399
|
});
|
|
1400
|
+
contentBlock.input += delta;
|
|
1397
1401
|
}
|
|
1398
1402
|
return;
|
|
1399
1403
|
}
|
|
@@ -1435,7 +1439,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1435
1439
|
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
1436
1440
|
finishReason = mapAnthropicStopReason({
|
|
1437
1441
|
finishReason: value.delta.stop_reason,
|
|
1438
|
-
isJsonResponseFromTool:
|
|
1442
|
+
isJsonResponseFromTool: usesJsonResponseTool
|
|
1439
1443
|
});
|
|
1440
1444
|
return;
|
|
1441
1445
|
}
|
|
@@ -1495,7 +1499,7 @@ var anthropicMessagesResponseSchema = z4.object({
|
|
|
1495
1499
|
type: z4.literal("server_tool_use"),
|
|
1496
1500
|
id: z4.string(),
|
|
1497
1501
|
name: z4.string(),
|
|
1498
|
-
input: z4.record(z4.unknown()).nullish()
|
|
1502
|
+
input: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1499
1503
|
}),
|
|
1500
1504
|
z4.object({
|
|
1501
1505
|
type: z4.literal("web_search_tool_result"),
|
|
@@ -1568,7 +1572,7 @@ var anthropicMessagesChunkSchema = z4.discriminatedUnion("type", [
|
|
|
1568
1572
|
type: z4.literal("server_tool_use"),
|
|
1569
1573
|
id: z4.string(),
|
|
1570
1574
|
name: z4.string(),
|
|
1571
|
-
input: z4.record(z4.unknown()).nullish()
|
|
1575
|
+
input: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1572
1576
|
}),
|
|
1573
1577
|
z4.object({
|
|
1574
1578
|
type: z4.literal("web_search_tool_result"),
|