@ai-sdk/anthropic 3.0.77 → 3.0.78
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 +25 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -19
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +24 -18
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +24 -18
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/convert-to-anthropic-messages-prompt.ts +16 -3
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "@ai-sdk/provider-utils";
|
|
13
13
|
|
|
14
14
|
// src/version.ts
|
|
15
|
-
var VERSION = true ? "3.0.
|
|
15
|
+
var VERSION = true ? "3.0.78" : "0.0.0-test";
|
|
16
16
|
|
|
17
17
|
// src/anthropic-messages-language-model.ts
|
|
18
18
|
import {
|
|
@@ -2211,7 +2211,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2211
2211
|
cacheControlValidator,
|
|
2212
2212
|
toolNameMapping
|
|
2213
2213
|
}) {
|
|
2214
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2214
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2215
2215
|
const betas = /* @__PURE__ */ new Set();
|
|
2216
2216
|
const blocks = groupIntoBlocks(prompt);
|
|
2217
2217
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2363,15 +2363,21 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2363
2363
|
if (part.type === "tool-approval-response") {
|
|
2364
2364
|
continue;
|
|
2365
2365
|
}
|
|
2366
|
+
const output = part.output;
|
|
2367
|
+
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_d = output.value.find(
|
|
2368
|
+
(contentPart) => contentPart.providerOptions != null
|
|
2369
|
+
)) == null ? void 0 : _d.providerOptions : void 0;
|
|
2366
2370
|
const isLastPart = i2 === content.length - 1;
|
|
2367
|
-
const cacheControl = (
|
|
2371
|
+
const cacheControl = (_f = (_e = validator.getCacheControl(part.providerOptions, {
|
|
2368
2372
|
type: "tool result part",
|
|
2369
2373
|
canCache: true
|
|
2370
|
-
})) != null ?
|
|
2374
|
+
})) != null ? _e : validator.getCacheControl(outputProviderOptions, {
|
|
2375
|
+
type: "tool result output",
|
|
2376
|
+
canCache: true
|
|
2377
|
+
})) != null ? _f : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2371
2378
|
type: "tool result message",
|
|
2372
2379
|
canCache: true
|
|
2373
2380
|
}) : void 0;
|
|
2374
|
-
const output = part.output;
|
|
2375
2381
|
let contentValue;
|
|
2376
2382
|
switch (output.type) {
|
|
2377
2383
|
case "content":
|
|
@@ -2458,7 +2464,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2458
2464
|
contentValue = output.value;
|
|
2459
2465
|
break;
|
|
2460
2466
|
case "execution-denied":
|
|
2461
|
-
contentValue = (
|
|
2467
|
+
contentValue = (_g = output.reason) != null ? _g : "Tool execution denied.";
|
|
2462
2468
|
break;
|
|
2463
2469
|
case "json":
|
|
2464
2470
|
case "error-json":
|
|
@@ -2495,16 +2501,16 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2495
2501
|
for (let k = 0; k < content.length; k++) {
|
|
2496
2502
|
const part = content[k];
|
|
2497
2503
|
const isLastContentPart = k === content.length - 1;
|
|
2498
|
-
const cacheControl = (
|
|
2504
|
+
const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
|
|
2499
2505
|
type: "assistant message part",
|
|
2500
2506
|
canCache: true
|
|
2501
|
-
})) != null ?
|
|
2507
|
+
})) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
2502
2508
|
type: "assistant message",
|
|
2503
2509
|
canCache: true
|
|
2504
2510
|
}) : void 0;
|
|
2505
2511
|
switch (part.type) {
|
|
2506
2512
|
case "text": {
|
|
2507
|
-
const textMetadata = (
|
|
2513
|
+
const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
|
|
2508
2514
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
2509
2515
|
anthropicContent.push({
|
|
2510
2516
|
type: "compaction",
|
|
@@ -2577,10 +2583,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2577
2583
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2578
2584
|
part.toolName
|
|
2579
2585
|
);
|
|
2580
|
-
const isMcpToolUse = ((
|
|
2586
|
+
const isMcpToolUse = ((_k = (_j = part.providerOptions) == null ? void 0 : _j.anthropic) == null ? void 0 : _k.type) === "mcp-tool-use";
|
|
2581
2587
|
if (isMcpToolUse) {
|
|
2582
2588
|
mcpToolUseIds.add(part.toolCallId);
|
|
2583
|
-
const serverName = (
|
|
2589
|
+
const serverName = (_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.serverName;
|
|
2584
2590
|
if (serverName == null || typeof serverName !== "string") {
|
|
2585
2591
|
warnings.push({
|
|
2586
2592
|
type: "other",
|
|
@@ -2656,7 +2662,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2656
2662
|
}
|
|
2657
2663
|
break;
|
|
2658
2664
|
}
|
|
2659
|
-
const callerOptions = (
|
|
2665
|
+
const callerOptions = (_n = part.providerOptions) == null ? void 0 : _n.anthropic;
|
|
2660
2666
|
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
|
|
2661
2667
|
type: callerOptions.caller.type,
|
|
2662
2668
|
tool_id: callerOptions.caller.toolId
|
|
@@ -2709,7 +2715,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2709
2715
|
tool_use_id: part.toolCallId,
|
|
2710
2716
|
content: {
|
|
2711
2717
|
type: "code_execution_tool_result_error",
|
|
2712
|
-
error_code: (
|
|
2718
|
+
error_code: (_o = errorInfo.errorCode) != null ? _o : "unknown"
|
|
2713
2719
|
},
|
|
2714
2720
|
cache_control: cacheControl
|
|
2715
2721
|
});
|
|
@@ -2720,7 +2726,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2720
2726
|
cache_control: cacheControl,
|
|
2721
2727
|
content: {
|
|
2722
2728
|
type: "bash_code_execution_tool_result_error",
|
|
2723
|
-
error_code: (
|
|
2729
|
+
error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
|
|
2724
2730
|
}
|
|
2725
2731
|
});
|
|
2726
2732
|
}
|
|
@@ -2753,7 +2759,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2753
2759
|
stdout: codeExecutionOutput.stdout,
|
|
2754
2760
|
stderr: codeExecutionOutput.stderr,
|
|
2755
2761
|
return_code: codeExecutionOutput.return_code,
|
|
2756
|
-
content: (
|
|
2762
|
+
content: (_q = codeExecutionOutput.content) != null ? _q : []
|
|
2757
2763
|
},
|
|
2758
2764
|
cache_control: cacheControl
|
|
2759
2765
|
});
|
|
@@ -2771,7 +2777,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2771
2777
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
2772
2778
|
stderr: codeExecutionOutput.stderr,
|
|
2773
2779
|
return_code: codeExecutionOutput.return_code,
|
|
2774
|
-
content: (
|
|
2780
|
+
content: (_r = codeExecutionOutput.content) != null ? _r : []
|
|
2775
2781
|
},
|
|
2776
2782
|
cache_control: cacheControl
|
|
2777
2783
|
});
|
|
@@ -2790,7 +2796,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2790
2796
|
stdout: codeExecutionOutput.stdout,
|
|
2791
2797
|
stderr: codeExecutionOutput.stderr,
|
|
2792
2798
|
return_code: codeExecutionOutput.return_code,
|
|
2793
|
-
content: (
|
|
2799
|
+
content: (_s = codeExecutionOutput.content) != null ? _s : []
|
|
2794
2800
|
},
|
|
2795
2801
|
cache_control: cacheControl
|
|
2796
2802
|
});
|
|
@@ -2823,7 +2829,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2823
2829
|
errorValue = output.value;
|
|
2824
2830
|
}
|
|
2825
2831
|
} catch (e) {
|
|
2826
|
-
const extractedErrorCode = (
|
|
2832
|
+
const extractedErrorCode = (_t = output.value) == null ? void 0 : _t.errorCode;
|
|
2827
2833
|
errorValue = {
|
|
2828
2834
|
errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
|
|
2829
2835
|
};
|
|
@@ -2833,7 +2839,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2833
2839
|
tool_use_id: part.toolCallId,
|
|
2834
2840
|
content: {
|
|
2835
2841
|
type: "web_fetch_tool_result_error",
|
|
2836
|
-
error_code: (
|
|
2842
|
+
error_code: (_u = errorValue.errorCode) != null ? _u : "unavailable"
|
|
2837
2843
|
},
|
|
2838
2844
|
cache_control: cacheControl
|
|
2839
2845
|
});
|