@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.mjs
CHANGED
|
@@ -1913,12 +1913,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1913
1913
|
setting: "responseFormat",
|
|
1914
1914
|
details: "JSON response format requires a schema. The response format is ignored."
|
|
1915
1915
|
});
|
|
1916
|
-
} else if (tools != null) {
|
|
1917
|
-
warnings.push({
|
|
1918
|
-
type: "unsupported-setting",
|
|
1919
|
-
setting: "tools",
|
|
1920
|
-
details: "JSON response format does not support tools. The provided tools are ignored."
|
|
1921
|
-
});
|
|
1922
1916
|
}
|
|
1923
1917
|
}
|
|
1924
1918
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
@@ -2049,8 +2043,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2049
2043
|
betas: toolsBetas
|
|
2050
2044
|
} = await prepareTools(
|
|
2051
2045
|
jsonResponseTool != null ? {
|
|
2052
|
-
tools: [jsonResponseTool],
|
|
2053
|
-
toolChoice: { type: "
|
|
2046
|
+
tools: [...tools != null ? tools : [], jsonResponseTool],
|
|
2047
|
+
toolChoice: { type: "required" },
|
|
2054
2048
|
disableParallelToolUse: true,
|
|
2055
2049
|
cacheControlValidator
|
|
2056
2050
|
} : {
|
|
@@ -2134,6 +2128,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2134
2128
|
});
|
|
2135
2129
|
const content = [];
|
|
2136
2130
|
const mcpToolCalls = {};
|
|
2131
|
+
let isJsonResponseFromTool = false;
|
|
2137
2132
|
for (const part of response.content) {
|
|
2138
2133
|
switch (part.type) {
|
|
2139
2134
|
case "text": {
|
|
@@ -2179,18 +2174,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2179
2174
|
break;
|
|
2180
2175
|
}
|
|
2181
2176
|
case "tool_use": {
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2177
|
+
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
2178
|
+
if (isJsonResponseTool) {
|
|
2179
|
+
isJsonResponseFromTool = true;
|
|
2180
|
+
content.push({
|
|
2185
2181
|
type: "text",
|
|
2186
2182
|
text: JSON.stringify(part.input)
|
|
2187
|
-
}
|
|
2183
|
+
});
|
|
2184
|
+
} else {
|
|
2185
|
+
content.push({
|
|
2188
2186
|
type: "tool-call",
|
|
2189
2187
|
toolCallId: part.id,
|
|
2190
2188
|
toolName: part.name,
|
|
2191
2189
|
input: JSON.stringify(part.input)
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2190
|
+
});
|
|
2191
|
+
}
|
|
2194
2192
|
break;
|
|
2195
2193
|
}
|
|
2196
2194
|
case "server_tool_use": {
|
|
@@ -2377,7 +2375,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2377
2375
|
content,
|
|
2378
2376
|
finishReason: mapAnthropicStopReason({
|
|
2379
2377
|
finishReason: response.stop_reason,
|
|
2380
|
-
isJsonResponseFromTool
|
|
2378
|
+
isJsonResponseFromTool
|
|
2381
2379
|
}),
|
|
2382
2380
|
usage: {
|
|
2383
2381
|
inputTokens: response.usage.input_tokens,
|
|
@@ -2438,6 +2436,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2438
2436
|
let cacheCreationInputTokens = null;
|
|
2439
2437
|
let stopSequence = null;
|
|
2440
2438
|
let container = null;
|
|
2439
|
+
let isJsonResponseFromTool = false;
|
|
2441
2440
|
let blockType = void 0;
|
|
2442
2441
|
const generateId2 = this.generateId;
|
|
2443
2442
|
return {
|
|
@@ -2466,6 +2465,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2466
2465
|
blockType = contentBlockType;
|
|
2467
2466
|
switch (contentBlockType) {
|
|
2468
2467
|
case "text": {
|
|
2468
|
+
if (usesJsonResponseTool) {
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2469
2471
|
contentBlocks[value.index] = { type: "text" };
|
|
2470
2472
|
controller.enqueue({
|
|
2471
2473
|
type: "text-start",
|
|
@@ -2495,20 +2497,28 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2495
2497
|
return;
|
|
2496
2498
|
}
|
|
2497
2499
|
case "tool_use": {
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2500
|
+
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
2501
|
+
if (isJsonResponseTool) {
|
|
2502
|
+
isJsonResponseFromTool = true;
|
|
2503
|
+
contentBlocks[value.index] = { type: "text" };
|
|
2504
|
+
controller.enqueue({
|
|
2505
|
+
type: "text-start",
|
|
2506
|
+
id: String(value.index)
|
|
2507
|
+
});
|
|
2508
|
+
} else {
|
|
2509
|
+
contentBlocks[value.index] = {
|
|
2510
|
+
type: "tool-call",
|
|
2511
|
+
toolCallId: part.id,
|
|
2512
|
+
toolName: part.name,
|
|
2513
|
+
input: "",
|
|
2514
|
+
firstDelta: true
|
|
2515
|
+
};
|
|
2516
|
+
controller.enqueue({
|
|
2507
2517
|
type: "tool-input-start",
|
|
2508
2518
|
id: part.id,
|
|
2509
2519
|
toolName: part.name
|
|
2510
|
-
}
|
|
2511
|
-
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2512
2522
|
return;
|
|
2513
2523
|
}
|
|
2514
2524
|
case "server_tool_use": {
|
|
@@ -2724,7 +2734,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2724
2734
|
break;
|
|
2725
2735
|
}
|
|
2726
2736
|
case "tool-call":
|
|
2727
|
-
|
|
2737
|
+
const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
|
|
2738
|
+
if (!isJsonResponseTool) {
|
|
2728
2739
|
controller.enqueue({
|
|
2729
2740
|
type: "tool-input-end",
|
|
2730
2741
|
id: contentBlock.toolCallId
|
|
@@ -2788,7 +2799,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2788
2799
|
if (delta.length === 0) {
|
|
2789
2800
|
return;
|
|
2790
2801
|
}
|
|
2791
|
-
if (
|
|
2802
|
+
if (isJsonResponseFromTool) {
|
|
2792
2803
|
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
2793
2804
|
return;
|
|
2794
2805
|
}
|
|
@@ -2853,7 +2864,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2853
2864
|
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
2854
2865
|
finishReason = mapAnthropicStopReason({
|
|
2855
2866
|
finishReason: value.delta.stop_reason,
|
|
2856
|
-
isJsonResponseFromTool
|
|
2867
|
+
isJsonResponseFromTool
|
|
2857
2868
|
});
|
|
2858
2869
|
stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
|
|
2859
2870
|
container = value.delta.container != null ? {
|