@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/internal/index.mjs
CHANGED
|
@@ -2195,7 +2195,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2195
2195
|
cacheControlValidator,
|
|
2196
2196
|
toolNameMapping
|
|
2197
2197
|
}) {
|
|
2198
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2198
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2199
2199
|
const betas = /* @__PURE__ */ new Set();
|
|
2200
2200
|
const blocks = groupIntoBlocks(prompt);
|
|
2201
2201
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2347,15 +2347,21 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2347
2347
|
if (part.type === "tool-approval-response") {
|
|
2348
2348
|
continue;
|
|
2349
2349
|
}
|
|
2350
|
+
const output = part.output;
|
|
2351
|
+
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_d = output.value.find(
|
|
2352
|
+
(contentPart) => contentPart.providerOptions != null
|
|
2353
|
+
)) == null ? void 0 : _d.providerOptions : void 0;
|
|
2350
2354
|
const isLastPart = i2 === content.length - 1;
|
|
2351
|
-
const cacheControl = (
|
|
2355
|
+
const cacheControl = (_f = (_e = validator.getCacheControl(part.providerOptions, {
|
|
2352
2356
|
type: "tool result part",
|
|
2353
2357
|
canCache: true
|
|
2354
|
-
})) != null ?
|
|
2358
|
+
})) != null ? _e : validator.getCacheControl(outputProviderOptions, {
|
|
2359
|
+
type: "tool result output",
|
|
2360
|
+
canCache: true
|
|
2361
|
+
})) != null ? _f : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2355
2362
|
type: "tool result message",
|
|
2356
2363
|
canCache: true
|
|
2357
2364
|
}) : void 0;
|
|
2358
|
-
const output = part.output;
|
|
2359
2365
|
let contentValue;
|
|
2360
2366
|
switch (output.type) {
|
|
2361
2367
|
case "content":
|
|
@@ -2442,7 +2448,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2442
2448
|
contentValue = output.value;
|
|
2443
2449
|
break;
|
|
2444
2450
|
case "execution-denied":
|
|
2445
|
-
contentValue = (
|
|
2451
|
+
contentValue = (_g = output.reason) != null ? _g : "Tool execution denied.";
|
|
2446
2452
|
break;
|
|
2447
2453
|
case "json":
|
|
2448
2454
|
case "error-json":
|
|
@@ -2479,16 +2485,16 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2479
2485
|
for (let k = 0; k < content.length; k++) {
|
|
2480
2486
|
const part = content[k];
|
|
2481
2487
|
const isLastContentPart = k === content.length - 1;
|
|
2482
|
-
const cacheControl = (
|
|
2488
|
+
const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
|
|
2483
2489
|
type: "assistant message part",
|
|
2484
2490
|
canCache: true
|
|
2485
|
-
})) != null ?
|
|
2491
|
+
})) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
2486
2492
|
type: "assistant message",
|
|
2487
2493
|
canCache: true
|
|
2488
2494
|
}) : void 0;
|
|
2489
2495
|
switch (part.type) {
|
|
2490
2496
|
case "text": {
|
|
2491
|
-
const textMetadata = (
|
|
2497
|
+
const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
|
|
2492
2498
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
2493
2499
|
anthropicContent.push({
|
|
2494
2500
|
type: "compaction",
|
|
@@ -2561,10 +2567,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2561
2567
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2562
2568
|
part.toolName
|
|
2563
2569
|
);
|
|
2564
|
-
const isMcpToolUse = ((
|
|
2570
|
+
const isMcpToolUse = ((_k = (_j = part.providerOptions) == null ? void 0 : _j.anthropic) == null ? void 0 : _k.type) === "mcp-tool-use";
|
|
2565
2571
|
if (isMcpToolUse) {
|
|
2566
2572
|
mcpToolUseIds.add(part.toolCallId);
|
|
2567
|
-
const serverName = (
|
|
2573
|
+
const serverName = (_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.serverName;
|
|
2568
2574
|
if (serverName == null || typeof serverName !== "string") {
|
|
2569
2575
|
warnings.push({
|
|
2570
2576
|
type: "other",
|
|
@@ -2640,7 +2646,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2640
2646
|
}
|
|
2641
2647
|
break;
|
|
2642
2648
|
}
|
|
2643
|
-
const callerOptions = (
|
|
2649
|
+
const callerOptions = (_n = part.providerOptions) == null ? void 0 : _n.anthropic;
|
|
2644
2650
|
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
|
|
2645
2651
|
type: callerOptions.caller.type,
|
|
2646
2652
|
tool_id: callerOptions.caller.toolId
|
|
@@ -2693,7 +2699,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2693
2699
|
tool_use_id: part.toolCallId,
|
|
2694
2700
|
content: {
|
|
2695
2701
|
type: "code_execution_tool_result_error",
|
|
2696
|
-
error_code: (
|
|
2702
|
+
error_code: (_o = errorInfo.errorCode) != null ? _o : "unknown"
|
|
2697
2703
|
},
|
|
2698
2704
|
cache_control: cacheControl
|
|
2699
2705
|
});
|
|
@@ -2704,7 +2710,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2704
2710
|
cache_control: cacheControl,
|
|
2705
2711
|
content: {
|
|
2706
2712
|
type: "bash_code_execution_tool_result_error",
|
|
2707
|
-
error_code: (
|
|
2713
|
+
error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
|
|
2708
2714
|
}
|
|
2709
2715
|
});
|
|
2710
2716
|
}
|
|
@@ -2737,7 +2743,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2737
2743
|
stdout: codeExecutionOutput.stdout,
|
|
2738
2744
|
stderr: codeExecutionOutput.stderr,
|
|
2739
2745
|
return_code: codeExecutionOutput.return_code,
|
|
2740
|
-
content: (
|
|
2746
|
+
content: (_q = codeExecutionOutput.content) != null ? _q : []
|
|
2741
2747
|
},
|
|
2742
2748
|
cache_control: cacheControl
|
|
2743
2749
|
});
|
|
@@ -2755,7 +2761,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2755
2761
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
2756
2762
|
stderr: codeExecutionOutput.stderr,
|
|
2757
2763
|
return_code: codeExecutionOutput.return_code,
|
|
2758
|
-
content: (
|
|
2764
|
+
content: (_r = codeExecutionOutput.content) != null ? _r : []
|
|
2759
2765
|
},
|
|
2760
2766
|
cache_control: cacheControl
|
|
2761
2767
|
});
|
|
@@ -2774,7 +2780,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2774
2780
|
stdout: codeExecutionOutput.stdout,
|
|
2775
2781
|
stderr: codeExecutionOutput.stderr,
|
|
2776
2782
|
return_code: codeExecutionOutput.return_code,
|
|
2777
|
-
content: (
|
|
2783
|
+
content: (_s = codeExecutionOutput.content) != null ? _s : []
|
|
2778
2784
|
},
|
|
2779
2785
|
cache_control: cacheControl
|
|
2780
2786
|
});
|
|
@@ -2807,7 +2813,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2807
2813
|
errorValue = output.value;
|
|
2808
2814
|
}
|
|
2809
2815
|
} catch (e) {
|
|
2810
|
-
const extractedErrorCode = (
|
|
2816
|
+
const extractedErrorCode = (_t = output.value) == null ? void 0 : _t.errorCode;
|
|
2811
2817
|
errorValue = {
|
|
2812
2818
|
errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
|
|
2813
2819
|
};
|
|
@@ -2817,7 +2823,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2817
2823
|
tool_use_id: part.toolCallId,
|
|
2818
2824
|
content: {
|
|
2819
2825
|
type: "web_fetch_tool_result_error",
|
|
2820
|
-
error_code: (
|
|
2826
|
+
error_code: (_u = errorValue.errorCode) != null ? _u : "unavailable"
|
|
2821
2827
|
},
|
|
2822
2828
|
cache_control: cacheControl
|
|
2823
2829
|
});
|