@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/CHANGELOG.md +6 -0
- package/dist/index.js +41 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -30
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +40 -29
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +40 -29
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -1902,12 +1902,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1902
1902
|
setting: "responseFormat",
|
|
1903
1903
|
details: "JSON response format requires a schema. The response format is ignored."
|
|
1904
1904
|
});
|
|
1905
|
-
} else if (tools != null) {
|
|
1906
|
-
warnings.push({
|
|
1907
|
-
type: "unsupported-setting",
|
|
1908
|
-
setting: "tools",
|
|
1909
|
-
details: "JSON response format does not support tools. The provided tools are ignored."
|
|
1910
|
-
});
|
|
1911
1905
|
}
|
|
1912
1906
|
}
|
|
1913
1907
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
@@ -2038,8 +2032,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2038
2032
|
betas: toolsBetas
|
|
2039
2033
|
} = await prepareTools(
|
|
2040
2034
|
jsonResponseTool != null ? {
|
|
2041
|
-
tools: [jsonResponseTool],
|
|
2042
|
-
toolChoice: { type: "
|
|
2035
|
+
tools: [...tools != null ? tools : [], jsonResponseTool],
|
|
2036
|
+
toolChoice: { type: "required" },
|
|
2043
2037
|
disableParallelToolUse: true,
|
|
2044
2038
|
cacheControlValidator
|
|
2045
2039
|
} : {
|
|
@@ -2123,6 +2117,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2123
2117
|
});
|
|
2124
2118
|
const content = [];
|
|
2125
2119
|
const mcpToolCalls = {};
|
|
2120
|
+
let isJsonResponseFromTool = false;
|
|
2126
2121
|
for (const part of response.content) {
|
|
2127
2122
|
switch (part.type) {
|
|
2128
2123
|
case "text": {
|
|
@@ -2168,18 +2163,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2168
2163
|
break;
|
|
2169
2164
|
}
|
|
2170
2165
|
case "tool_use": {
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2166
|
+
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
2167
|
+
if (isJsonResponseTool) {
|
|
2168
|
+
isJsonResponseFromTool = true;
|
|
2169
|
+
content.push({
|
|
2174
2170
|
type: "text",
|
|
2175
2171
|
text: JSON.stringify(part.input)
|
|
2176
|
-
}
|
|
2172
|
+
});
|
|
2173
|
+
} else {
|
|
2174
|
+
content.push({
|
|
2177
2175
|
type: "tool-call",
|
|
2178
2176
|
toolCallId: part.id,
|
|
2179
2177
|
toolName: part.name,
|
|
2180
2178
|
input: JSON.stringify(part.input)
|
|
2181
|
-
}
|
|
2182
|
-
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2183
2181
|
break;
|
|
2184
2182
|
}
|
|
2185
2183
|
case "server_tool_use": {
|
|
@@ -2366,7 +2364,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2366
2364
|
content,
|
|
2367
2365
|
finishReason: mapAnthropicStopReason({
|
|
2368
2366
|
finishReason: response.stop_reason,
|
|
2369
|
-
isJsonResponseFromTool
|
|
2367
|
+
isJsonResponseFromTool
|
|
2370
2368
|
}),
|
|
2371
2369
|
usage: {
|
|
2372
2370
|
inputTokens: response.usage.input_tokens,
|
|
@@ -2427,6 +2425,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2427
2425
|
let cacheCreationInputTokens = null;
|
|
2428
2426
|
let stopSequence = null;
|
|
2429
2427
|
let container = null;
|
|
2428
|
+
let isJsonResponseFromTool = false;
|
|
2430
2429
|
let blockType = void 0;
|
|
2431
2430
|
const generateId2 = this.generateId;
|
|
2432
2431
|
return {
|
|
@@ -2455,6 +2454,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2455
2454
|
blockType = contentBlockType;
|
|
2456
2455
|
switch (contentBlockType) {
|
|
2457
2456
|
case "text": {
|
|
2457
|
+
if (usesJsonResponseTool) {
|
|
2458
|
+
return;
|
|
2459
|
+
}
|
|
2458
2460
|
contentBlocks[value.index] = { type: "text" };
|
|
2459
2461
|
controller.enqueue({
|
|
2460
2462
|
type: "text-start",
|
|
@@ -2484,20 +2486,28 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2484
2486
|
return;
|
|
2485
2487
|
}
|
|
2486
2488
|
case "tool_use": {
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2489
|
+
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
2490
|
+
if (isJsonResponseTool) {
|
|
2491
|
+
isJsonResponseFromTool = true;
|
|
2492
|
+
contentBlocks[value.index] = { type: "text" };
|
|
2493
|
+
controller.enqueue({
|
|
2494
|
+
type: "text-start",
|
|
2495
|
+
id: String(value.index)
|
|
2496
|
+
});
|
|
2497
|
+
} else {
|
|
2498
|
+
contentBlocks[value.index] = {
|
|
2499
|
+
type: "tool-call",
|
|
2500
|
+
toolCallId: part.id,
|
|
2501
|
+
toolName: part.name,
|
|
2502
|
+
input: "",
|
|
2503
|
+
firstDelta: true
|
|
2504
|
+
};
|
|
2505
|
+
controller.enqueue({
|
|
2496
2506
|
type: "tool-input-start",
|
|
2497
2507
|
id: part.id,
|
|
2498
2508
|
toolName: part.name
|
|
2499
|
-
}
|
|
2500
|
-
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2501
2511
|
return;
|
|
2502
2512
|
}
|
|
2503
2513
|
case "server_tool_use": {
|
|
@@ -2713,7 +2723,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2713
2723
|
break;
|
|
2714
2724
|
}
|
|
2715
2725
|
case "tool-call":
|
|
2716
|
-
|
|
2726
|
+
const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
|
|
2727
|
+
if (!isJsonResponseTool) {
|
|
2717
2728
|
controller.enqueue({
|
|
2718
2729
|
type: "tool-input-end",
|
|
2719
2730
|
id: contentBlock.toolCallId
|
|
@@ -2777,7 +2788,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2777
2788
|
if (delta.length === 0) {
|
|
2778
2789
|
return;
|
|
2779
2790
|
}
|
|
2780
|
-
if (
|
|
2791
|
+
if (isJsonResponseFromTool) {
|
|
2781
2792
|
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
2782
2793
|
return;
|
|
2783
2794
|
}
|
|
@@ -2842,7 +2853,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2842
2853
|
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
2843
2854
|
finishReason = mapAnthropicStopReason({
|
|
2844
2855
|
finishReason: value.delta.stop_reason,
|
|
2845
|
-
isJsonResponseFromTool
|
|
2856
|
+
isJsonResponseFromTool
|
|
2846
2857
|
});
|
|
2847
2858
|
stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
|
|
2848
2859
|
container = value.delta.container != null ? {
|