@ai-sdk/anthropic 2.0.0-beta.2 → 2.0.0-beta.4
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 +19 -0
- package/dist/index.d.mts +5 -23
- package/dist/index.d.ts +5 -23
- package/dist/index.js +249 -249
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -21
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +249 -249
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +21 -21
- 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.
|
|
@@ -925,7 +925,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
925
925
|
},
|
|
926
926
|
warnings: [...warnings, ...toolWarnings],
|
|
927
927
|
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas]),
|
|
928
|
-
jsonResponseTool
|
|
928
|
+
usesJsonResponseTool: jsonResponseTool != null
|
|
929
929
|
};
|
|
930
930
|
}
|
|
931
931
|
async getHeaders({
|
|
@@ -971,7 +971,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
971
971
|
}
|
|
972
972
|
async doGenerate(options) {
|
|
973
973
|
var _a, _b, _c, _d, _e;
|
|
974
|
-
const { args, warnings, betas,
|
|
974
|
+
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
975
975
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
976
976
|
const {
|
|
977
977
|
responseHeaders,
|
|
@@ -992,7 +992,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
992
992
|
for (const part of response.content) {
|
|
993
993
|
switch (part.type) {
|
|
994
994
|
case "text": {
|
|
995
|
-
if (
|
|
995
|
+
if (!usesJsonResponseTool) {
|
|
996
996
|
content.push({ type: "text", text: part.text });
|
|
997
997
|
if (part.citations) {
|
|
998
998
|
for (const citation of part.citations) {
|
|
@@ -1034,7 +1034,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1034
1034
|
case "tool_use": {
|
|
1035
1035
|
content.push(
|
|
1036
1036
|
// when a json response tool is used, the tool call becomes the text:
|
|
1037
|
-
|
|
1037
|
+
usesJsonResponseTool ? {
|
|
1038
1038
|
type: "text",
|
|
1039
1039
|
text: JSON.stringify(part.input)
|
|
1040
1040
|
} : {
|
|
@@ -1111,7 +1111,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1111
1111
|
content,
|
|
1112
1112
|
finishReason: mapAnthropicStopReason({
|
|
1113
1113
|
finishReason: response.stop_reason,
|
|
1114
|
-
isJsonResponseFromTool:
|
|
1114
|
+
isJsonResponseFromTool: usesJsonResponseTool
|
|
1115
1115
|
}),
|
|
1116
1116
|
usage: {
|
|
1117
1117
|
inputTokens: response.usage.input_tokens,
|
|
@@ -1135,7 +1135,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1135
1135
|
};
|
|
1136
1136
|
}
|
|
1137
1137
|
async doStream(options) {
|
|
1138
|
-
const { args, warnings, betas,
|
|
1138
|
+
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
1139
1139
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
1140
1140
|
const body = { ...args, stream: true };
|
|
1141
1141
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
@@ -1213,14 +1213,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1213
1213
|
return;
|
|
1214
1214
|
}
|
|
1215
1215
|
case "tool_use": {
|
|
1216
|
-
contentBlocks[value.index] =
|
|
1216
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
1217
1217
|
type: "tool-call",
|
|
1218
1218
|
toolCallId: value.content_block.id,
|
|
1219
1219
|
toolName: value.content_block.name,
|
|
1220
1220
|
input: ""
|
|
1221
1221
|
};
|
|
1222
1222
|
controller.enqueue(
|
|
1223
|
-
|
|
1223
|
+
usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
|
|
1224
1224
|
type: "tool-input-start",
|
|
1225
1225
|
id: value.content_block.id,
|
|
1226
1226
|
toolName: value.content_block.name
|
|
@@ -1321,7 +1321,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1321
1321
|
break;
|
|
1322
1322
|
}
|
|
1323
1323
|
case "tool-call":
|
|
1324
|
-
if (
|
|
1324
|
+
if (!usesJsonResponseTool) {
|
|
1325
1325
|
controller.enqueue({
|
|
1326
1326
|
type: "tool-input-end",
|
|
1327
1327
|
id: contentBlock.toolCallId
|
|
@@ -1339,7 +1339,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1339
1339
|
const deltaType = value.delta.type;
|
|
1340
1340
|
switch (deltaType) {
|
|
1341
1341
|
case "text_delta": {
|
|
1342
|
-
if (
|
|
1342
|
+
if (usesJsonResponseTool) {
|
|
1343
1343
|
return;
|
|
1344
1344
|
}
|
|
1345
1345
|
controller.enqueue({
|
|
@@ -1375,16 +1375,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1375
1375
|
case "input_json_delta": {
|
|
1376
1376
|
const contentBlock = contentBlocks[value.index];
|
|
1377
1377
|
const delta = value.delta.partial_json;
|
|
1378
|
-
if (
|
|
1379
|
-
if ((contentBlock == null ? void 0 : contentBlock.type) !== "
|
|
1378
|
+
if (usesJsonResponseTool) {
|
|
1379
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
1380
1380
|
return;
|
|
1381
1381
|
}
|
|
1382
1382
|
controller.enqueue({
|
|
1383
|
-
type: "
|
|
1384
|
-
id:
|
|
1383
|
+
type: "text-delta",
|
|
1384
|
+
id: String(value.index),
|
|
1385
1385
|
delta
|
|
1386
1386
|
});
|
|
1387
|
-
contentBlock.input += delta;
|
|
1388
1387
|
} else {
|
|
1389
1388
|
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
1390
1389
|
return;
|
|
@@ -1394,6 +1393,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1394
1393
|
id: contentBlock.toolCallId,
|
|
1395
1394
|
delta
|
|
1396
1395
|
});
|
|
1396
|
+
contentBlock.input += delta;
|
|
1397
1397
|
}
|
|
1398
1398
|
return;
|
|
1399
1399
|
}
|
|
@@ -1435,7 +1435,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1435
1435
|
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
1436
1436
|
finishReason = mapAnthropicStopReason({
|
|
1437
1437
|
finishReason: value.delta.stop_reason,
|
|
1438
|
-
isJsonResponseFromTool:
|
|
1438
|
+
isJsonResponseFromTool: usesJsonResponseTool
|
|
1439
1439
|
});
|
|
1440
1440
|
return;
|
|
1441
1441
|
}
|
|
@@ -1495,7 +1495,7 @@ var anthropicMessagesResponseSchema = z4.object({
|
|
|
1495
1495
|
type: z4.literal("server_tool_use"),
|
|
1496
1496
|
id: z4.string(),
|
|
1497
1497
|
name: z4.string(),
|
|
1498
|
-
input: z4.record(z4.unknown()).nullish()
|
|
1498
|
+
input: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1499
1499
|
}),
|
|
1500
1500
|
z4.object({
|
|
1501
1501
|
type: z4.literal("web_search_tool_result"),
|
|
@@ -1568,7 +1568,7 @@ var anthropicMessagesChunkSchema = z4.discriminatedUnion("type", [
|
|
|
1568
1568
|
type: z4.literal("server_tool_use"),
|
|
1569
1569
|
id: z4.string(),
|
|
1570
1570
|
name: z4.string(),
|
|
1571
|
-
input: z4.record(z4.unknown()).nullish()
|
|
1571
|
+
input: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1572
1572
|
}),
|
|
1573
1573
|
z4.object({
|
|
1574
1574
|
type: z4.literal("web_search_tool_result"),
|