@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/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.
|
|
@@ -935,7 +935,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
935
935
|
},
|
|
936
936
|
warnings: [...warnings, ...toolWarnings],
|
|
937
937
|
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas]),
|
|
938
|
-
jsonResponseTool
|
|
938
|
+
usesJsonResponseTool: jsonResponseTool != null
|
|
939
939
|
};
|
|
940
940
|
}
|
|
941
941
|
async getHeaders({
|
|
@@ -981,7 +981,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
981
981
|
}
|
|
982
982
|
async doGenerate(options) {
|
|
983
983
|
var _a, _b, _c, _d, _e;
|
|
984
|
-
const { args, warnings, betas,
|
|
984
|
+
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
985
985
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
986
986
|
const {
|
|
987
987
|
responseHeaders,
|
|
@@ -1002,7 +1002,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1002
1002
|
for (const part of response.content) {
|
|
1003
1003
|
switch (part.type) {
|
|
1004
1004
|
case "text": {
|
|
1005
|
-
if (
|
|
1005
|
+
if (!usesJsonResponseTool) {
|
|
1006
1006
|
content.push({ type: "text", text: part.text });
|
|
1007
1007
|
if (part.citations) {
|
|
1008
1008
|
for (const citation of part.citations) {
|
|
@@ -1044,7 +1044,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1044
1044
|
case "tool_use": {
|
|
1045
1045
|
content.push(
|
|
1046
1046
|
// when a json response tool is used, the tool call becomes the text:
|
|
1047
|
-
|
|
1047
|
+
usesJsonResponseTool ? {
|
|
1048
1048
|
type: "text",
|
|
1049
1049
|
text: JSON.stringify(part.input)
|
|
1050
1050
|
} : {
|
|
@@ -1121,7 +1121,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1121
1121
|
content,
|
|
1122
1122
|
finishReason: mapAnthropicStopReason({
|
|
1123
1123
|
finishReason: response.stop_reason,
|
|
1124
|
-
isJsonResponseFromTool:
|
|
1124
|
+
isJsonResponseFromTool: usesJsonResponseTool
|
|
1125
1125
|
}),
|
|
1126
1126
|
usage: {
|
|
1127
1127
|
inputTokens: response.usage.input_tokens,
|
|
@@ -1145,7 +1145,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1145
1145
|
};
|
|
1146
1146
|
}
|
|
1147
1147
|
async doStream(options) {
|
|
1148
|
-
const { args, warnings, betas,
|
|
1148
|
+
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
1149
1149
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
1150
1150
|
const body = { ...args, stream: true };
|
|
1151
1151
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
@@ -1223,14 +1223,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1223
1223
|
return;
|
|
1224
1224
|
}
|
|
1225
1225
|
case "tool_use": {
|
|
1226
|
-
contentBlocks[value.index] =
|
|
1226
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
1227
1227
|
type: "tool-call",
|
|
1228
1228
|
toolCallId: value.content_block.id,
|
|
1229
1229
|
toolName: value.content_block.name,
|
|
1230
1230
|
input: ""
|
|
1231
1231
|
};
|
|
1232
1232
|
controller.enqueue(
|
|
1233
|
-
|
|
1233
|
+
usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
|
|
1234
1234
|
type: "tool-input-start",
|
|
1235
1235
|
id: value.content_block.id,
|
|
1236
1236
|
toolName: value.content_block.name
|
|
@@ -1331,7 +1331,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1331
1331
|
break;
|
|
1332
1332
|
}
|
|
1333
1333
|
case "tool-call":
|
|
1334
|
-
if (
|
|
1334
|
+
if (!usesJsonResponseTool) {
|
|
1335
1335
|
controller.enqueue({
|
|
1336
1336
|
type: "tool-input-end",
|
|
1337
1337
|
id: contentBlock.toolCallId
|
|
@@ -1349,7 +1349,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1349
1349
|
const deltaType = value.delta.type;
|
|
1350
1350
|
switch (deltaType) {
|
|
1351
1351
|
case "text_delta": {
|
|
1352
|
-
if (
|
|
1352
|
+
if (usesJsonResponseTool) {
|
|
1353
1353
|
return;
|
|
1354
1354
|
}
|
|
1355
1355
|
controller.enqueue({
|
|
@@ -1385,16 +1385,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1385
1385
|
case "input_json_delta": {
|
|
1386
1386
|
const contentBlock = contentBlocks[value.index];
|
|
1387
1387
|
const delta = value.delta.partial_json;
|
|
1388
|
-
if (
|
|
1389
|
-
if ((contentBlock == null ? void 0 : contentBlock.type) !== "
|
|
1388
|
+
if (usesJsonResponseTool) {
|
|
1389
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
1390
1390
|
return;
|
|
1391
1391
|
}
|
|
1392
1392
|
controller.enqueue({
|
|
1393
|
-
type: "
|
|
1394
|
-
id:
|
|
1393
|
+
type: "text-delta",
|
|
1394
|
+
id: String(value.index),
|
|
1395
1395
|
delta
|
|
1396
1396
|
});
|
|
1397
|
-
contentBlock.input += delta;
|
|
1398
1397
|
} else {
|
|
1399
1398
|
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
1400
1399
|
return;
|
|
@@ -1404,6 +1403,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1404
1403
|
id: contentBlock.toolCallId,
|
|
1405
1404
|
delta
|
|
1406
1405
|
});
|
|
1406
|
+
contentBlock.input += delta;
|
|
1407
1407
|
}
|
|
1408
1408
|
return;
|
|
1409
1409
|
}
|
|
@@ -1445,7 +1445,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1445
1445
|
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
1446
1446
|
finishReason = mapAnthropicStopReason({
|
|
1447
1447
|
finishReason: value.delta.stop_reason,
|
|
1448
|
-
isJsonResponseFromTool:
|
|
1448
|
+
isJsonResponseFromTool: usesJsonResponseTool
|
|
1449
1449
|
});
|
|
1450
1450
|
return;
|
|
1451
1451
|
}
|
|
@@ -1505,7 +1505,7 @@ var anthropicMessagesResponseSchema = z4.object({
|
|
|
1505
1505
|
type: z4.literal("server_tool_use"),
|
|
1506
1506
|
id: z4.string(),
|
|
1507
1507
|
name: z4.string(),
|
|
1508
|
-
input: z4.record(z4.unknown()).nullish()
|
|
1508
|
+
input: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1509
1509
|
}),
|
|
1510
1510
|
z4.object({
|
|
1511
1511
|
type: z4.literal("web_search_tool_result"),
|
|
@@ -1578,7 +1578,7 @@ var anthropicMessagesChunkSchema = z4.discriminatedUnion("type", [
|
|
|
1578
1578
|
type: z4.literal("server_tool_use"),
|
|
1579
1579
|
id: z4.string(),
|
|
1580
1580
|
name: z4.string(),
|
|
1581
|
-
input: z4.record(z4.unknown()).nullish()
|
|
1581
|
+
input: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1582
1582
|
}),
|
|
1583
1583
|
z4.object({
|
|
1584
1584
|
type: z4.literal("web_search_tool_result"),
|