@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/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
31
31
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/version.ts
|
|
34
|
-
var VERSION = true ? "3.0.0-beta.
|
|
34
|
+
var VERSION = true ? "3.0.0-beta.44" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -1909,12 +1909,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1909
1909
|
setting: "responseFormat",
|
|
1910
1910
|
details: "JSON response format requires a schema. The response format is ignored."
|
|
1911
1911
|
});
|
|
1912
|
-
} else if (tools != null) {
|
|
1913
|
-
warnings.push({
|
|
1914
|
-
type: "unsupported-setting",
|
|
1915
|
-
setting: "tools",
|
|
1916
|
-
details: "JSON response format does not support tools. The provided tools are ignored."
|
|
1917
|
-
});
|
|
1918
1912
|
}
|
|
1919
1913
|
}
|
|
1920
1914
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
@@ -2045,8 +2039,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2045
2039
|
betas: toolsBetas
|
|
2046
2040
|
} = await prepareTools(
|
|
2047
2041
|
jsonResponseTool != null ? {
|
|
2048
|
-
tools: [jsonResponseTool],
|
|
2049
|
-
toolChoice: { type: "
|
|
2042
|
+
tools: [...tools != null ? tools : [], jsonResponseTool],
|
|
2043
|
+
toolChoice: { type: "required" },
|
|
2050
2044
|
disableParallelToolUse: true,
|
|
2051
2045
|
cacheControlValidator
|
|
2052
2046
|
} : {
|
|
@@ -2130,6 +2124,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2130
2124
|
});
|
|
2131
2125
|
const content = [];
|
|
2132
2126
|
const mcpToolCalls = {};
|
|
2127
|
+
let isJsonResponseFromTool = false;
|
|
2133
2128
|
for (const part of response.content) {
|
|
2134
2129
|
switch (part.type) {
|
|
2135
2130
|
case "text": {
|
|
@@ -2175,18 +2170,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2175
2170
|
break;
|
|
2176
2171
|
}
|
|
2177
2172
|
case "tool_use": {
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2173
|
+
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
2174
|
+
if (isJsonResponseTool) {
|
|
2175
|
+
isJsonResponseFromTool = true;
|
|
2176
|
+
content.push({
|
|
2181
2177
|
type: "text",
|
|
2182
2178
|
text: JSON.stringify(part.input)
|
|
2183
|
-
}
|
|
2179
|
+
});
|
|
2180
|
+
} else {
|
|
2181
|
+
content.push({
|
|
2184
2182
|
type: "tool-call",
|
|
2185
2183
|
toolCallId: part.id,
|
|
2186
2184
|
toolName: part.name,
|
|
2187
2185
|
input: JSON.stringify(part.input)
|
|
2188
|
-
}
|
|
2189
|
-
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2190
2188
|
break;
|
|
2191
2189
|
}
|
|
2192
2190
|
case "server_tool_use": {
|
|
@@ -2373,7 +2371,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2373
2371
|
content,
|
|
2374
2372
|
finishReason: mapAnthropicStopReason({
|
|
2375
2373
|
finishReason: response.stop_reason,
|
|
2376
|
-
isJsonResponseFromTool
|
|
2374
|
+
isJsonResponseFromTool
|
|
2377
2375
|
}),
|
|
2378
2376
|
usage: {
|
|
2379
2377
|
inputTokens: response.usage.input_tokens,
|
|
@@ -2434,6 +2432,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2434
2432
|
let cacheCreationInputTokens = null;
|
|
2435
2433
|
let stopSequence = null;
|
|
2436
2434
|
let container = null;
|
|
2435
|
+
let isJsonResponseFromTool = false;
|
|
2437
2436
|
let blockType = void 0;
|
|
2438
2437
|
const generateId3 = this.generateId;
|
|
2439
2438
|
return {
|
|
@@ -2462,6 +2461,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2462
2461
|
blockType = contentBlockType;
|
|
2463
2462
|
switch (contentBlockType) {
|
|
2464
2463
|
case "text": {
|
|
2464
|
+
if (usesJsonResponseTool) {
|
|
2465
|
+
return;
|
|
2466
|
+
}
|
|
2465
2467
|
contentBlocks[value.index] = { type: "text" };
|
|
2466
2468
|
controller.enqueue({
|
|
2467
2469
|
type: "text-start",
|
|
@@ -2491,20 +2493,28 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2491
2493
|
return;
|
|
2492
2494
|
}
|
|
2493
2495
|
case "tool_use": {
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2496
|
+
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
2497
|
+
if (isJsonResponseTool) {
|
|
2498
|
+
isJsonResponseFromTool = true;
|
|
2499
|
+
contentBlocks[value.index] = { type: "text" };
|
|
2500
|
+
controller.enqueue({
|
|
2501
|
+
type: "text-start",
|
|
2502
|
+
id: String(value.index)
|
|
2503
|
+
});
|
|
2504
|
+
} else {
|
|
2505
|
+
contentBlocks[value.index] = {
|
|
2506
|
+
type: "tool-call",
|
|
2507
|
+
toolCallId: part.id,
|
|
2508
|
+
toolName: part.name,
|
|
2509
|
+
input: "",
|
|
2510
|
+
firstDelta: true
|
|
2511
|
+
};
|
|
2512
|
+
controller.enqueue({
|
|
2503
2513
|
type: "tool-input-start",
|
|
2504
2514
|
id: part.id,
|
|
2505
2515
|
toolName: part.name
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2516
|
+
});
|
|
2517
|
+
}
|
|
2508
2518
|
return;
|
|
2509
2519
|
}
|
|
2510
2520
|
case "server_tool_use": {
|
|
@@ -2720,7 +2730,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2720
2730
|
break;
|
|
2721
2731
|
}
|
|
2722
2732
|
case "tool-call":
|
|
2723
|
-
|
|
2733
|
+
const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
|
|
2734
|
+
if (!isJsonResponseTool) {
|
|
2724
2735
|
controller.enqueue({
|
|
2725
2736
|
type: "tool-input-end",
|
|
2726
2737
|
id: contentBlock.toolCallId
|
|
@@ -2784,7 +2795,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2784
2795
|
if (delta.length === 0) {
|
|
2785
2796
|
return;
|
|
2786
2797
|
}
|
|
2787
|
-
if (
|
|
2798
|
+
if (isJsonResponseFromTool) {
|
|
2788
2799
|
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
2789
2800
|
return;
|
|
2790
2801
|
}
|
|
@@ -2849,7 +2860,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2849
2860
|
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
2850
2861
|
finishReason = mapAnthropicStopReason({
|
|
2851
2862
|
finishReason: value.delta.stop_reason,
|
|
2852
|
-
isJsonResponseFromTool
|
|
2863
|
+
isJsonResponseFromTool
|
|
2853
2864
|
});
|
|
2854
2865
|
stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
|
|
2855
2866
|
container = value.delta.container != null ? {
|