@ai-sdk/anthropic 3.0.110 → 3.0.111
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 +8 -0
- package/dist/index.js +97 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -108
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +96 -107
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +96 -107
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/anthropic-messages-api.ts +26 -67
- package/src/anthropic-messages-language-model.ts +39 -32
- package/src/convert-to-anthropic-messages-prompt.ts +36 -20
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.111" : "0.0.0-test";
|
|
16
16
|
|
|
17
17
|
// src/anthropic-messages-language-model.ts
|
|
18
18
|
import {
|
|
@@ -66,6 +66,19 @@ var anthropicStopDetailsSchema = z2.object({
|
|
|
66
66
|
explanation: z2.string().nullish(),
|
|
67
67
|
recommended_model: z2.string().nullish()
|
|
68
68
|
});
|
|
69
|
+
var anthropicToolCallCallerSchema = z2.union([
|
|
70
|
+
z2.object({
|
|
71
|
+
type: z2.literal("code_execution_20250825"),
|
|
72
|
+
tool_id: z2.string()
|
|
73
|
+
}),
|
|
74
|
+
z2.object({
|
|
75
|
+
type: z2.literal("code_execution_20260120"),
|
|
76
|
+
tool_id: z2.string()
|
|
77
|
+
}),
|
|
78
|
+
z2.object({
|
|
79
|
+
type: z2.literal("direct")
|
|
80
|
+
})
|
|
81
|
+
]);
|
|
69
82
|
var anthropicMessagesResponseSchema = lazySchema2(
|
|
70
83
|
() => zodSchema2(
|
|
71
84
|
z2.object({
|
|
@@ -124,34 +137,14 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
124
137
|
name: z2.string(),
|
|
125
138
|
input: z2.unknown(),
|
|
126
139
|
// Programmatic tool calling: caller info when triggered from code execution
|
|
127
|
-
caller:
|
|
128
|
-
z2.object({
|
|
129
|
-
type: z2.literal("code_execution_20250825"),
|
|
130
|
-
tool_id: z2.string()
|
|
131
|
-
}),
|
|
132
|
-
z2.object({
|
|
133
|
-
type: z2.literal("code_execution_20260120"),
|
|
134
|
-
tool_id: z2.string()
|
|
135
|
-
}),
|
|
136
|
-
z2.object({
|
|
137
|
-
type: z2.literal("direct")
|
|
138
|
-
})
|
|
139
|
-
]).optional()
|
|
140
|
+
caller: anthropicToolCallCallerSchema.optional()
|
|
140
141
|
}),
|
|
141
142
|
z2.object({
|
|
142
143
|
type: z2.literal("server_tool_use"),
|
|
143
144
|
id: z2.string(),
|
|
144
145
|
name: z2.string(),
|
|
145
146
|
input: z2.record(z2.string(), z2.unknown()).nullish(),
|
|
146
|
-
caller:
|
|
147
|
-
z2.object({
|
|
148
|
-
type: z2.literal("code_execution_20260120"),
|
|
149
|
-
tool_id: z2.string()
|
|
150
|
-
}),
|
|
151
|
-
z2.object({
|
|
152
|
-
type: z2.literal("direct")
|
|
153
|
-
})
|
|
154
|
-
]).optional()
|
|
147
|
+
caller: anthropicToolCallCallerSchema.optional()
|
|
155
148
|
}),
|
|
156
149
|
z2.object({
|
|
157
150
|
type: z2.literal("mcp_tool_use"),
|
|
@@ -174,6 +167,7 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
174
167
|
z2.object({
|
|
175
168
|
type: z2.literal("web_fetch_tool_result"),
|
|
176
169
|
tool_use_id: z2.string(),
|
|
170
|
+
caller: anthropicToolCallCallerSchema.optional(),
|
|
177
171
|
content: z2.union([
|
|
178
172
|
z2.object({
|
|
179
173
|
type: z2.literal("web_fetch_result"),
|
|
@@ -206,6 +200,7 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
206
200
|
z2.object({
|
|
207
201
|
type: z2.literal("web_search_tool_result"),
|
|
208
202
|
tool_use_id: z2.string(),
|
|
203
|
+
caller: anthropicToolCallCallerSchema.optional(),
|
|
209
204
|
content: z2.union([
|
|
210
205
|
z2.array(
|
|
211
206
|
z2.object({
|
|
@@ -442,19 +437,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
442
437
|
id: z2.string(),
|
|
443
438
|
name: z2.string(),
|
|
444
439
|
input: z2.unknown(),
|
|
445
|
-
caller:
|
|
446
|
-
z2.object({
|
|
447
|
-
type: z2.literal("code_execution_20250825"),
|
|
448
|
-
tool_id: z2.string()
|
|
449
|
-
}),
|
|
450
|
-
z2.object({
|
|
451
|
-
type: z2.literal("code_execution_20260120"),
|
|
452
|
-
tool_id: z2.string()
|
|
453
|
-
}),
|
|
454
|
-
z2.object({
|
|
455
|
-
type: z2.literal("direct")
|
|
456
|
-
})
|
|
457
|
-
]).optional()
|
|
440
|
+
caller: anthropicToolCallCallerSchema.optional()
|
|
458
441
|
})
|
|
459
442
|
])
|
|
460
443
|
).nullish(),
|
|
@@ -484,19 +467,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
484
467
|
// Programmatic tool calling: input may be present directly for deferred tool calls
|
|
485
468
|
input: z2.record(z2.string(), z2.unknown()).optional(),
|
|
486
469
|
// Programmatic tool calling: caller info when triggered from code execution
|
|
487
|
-
caller:
|
|
488
|
-
z2.object({
|
|
489
|
-
type: z2.literal("code_execution_20250825"),
|
|
490
|
-
tool_id: z2.string()
|
|
491
|
-
}),
|
|
492
|
-
z2.object({
|
|
493
|
-
type: z2.literal("code_execution_20260120"),
|
|
494
|
-
tool_id: z2.string()
|
|
495
|
-
}),
|
|
496
|
-
z2.object({
|
|
497
|
-
type: z2.literal("direct")
|
|
498
|
-
})
|
|
499
|
-
]).optional()
|
|
470
|
+
caller: anthropicToolCallCallerSchema.optional()
|
|
500
471
|
}),
|
|
501
472
|
z2.object({
|
|
502
473
|
type: z2.literal("redacted_thinking"),
|
|
@@ -511,15 +482,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
511
482
|
id: z2.string(),
|
|
512
483
|
name: z2.string(),
|
|
513
484
|
input: z2.record(z2.string(), z2.unknown()).nullish(),
|
|
514
|
-
caller:
|
|
515
|
-
z2.object({
|
|
516
|
-
type: z2.literal("code_execution_20260120"),
|
|
517
|
-
tool_id: z2.string()
|
|
518
|
-
}),
|
|
519
|
-
z2.object({
|
|
520
|
-
type: z2.literal("direct")
|
|
521
|
-
})
|
|
522
|
-
]).optional()
|
|
485
|
+
caller: anthropicToolCallCallerSchema.optional()
|
|
523
486
|
}),
|
|
524
487
|
z2.object({
|
|
525
488
|
type: z2.literal("mcp_tool_use"),
|
|
@@ -542,6 +505,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
542
505
|
z2.object({
|
|
543
506
|
type: z2.literal("web_fetch_tool_result"),
|
|
544
507
|
tool_use_id: z2.string(),
|
|
508
|
+
caller: anthropicToolCallCallerSchema.optional(),
|
|
545
509
|
content: z2.union([
|
|
546
510
|
z2.object({
|
|
547
511
|
type: z2.literal("web_fetch_result"),
|
|
@@ -574,6 +538,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
574
538
|
z2.object({
|
|
575
539
|
type: z2.literal("web_search_tool_result"),
|
|
576
540
|
tool_use_id: z2.string(),
|
|
541
|
+
caller: anthropicToolCallCallerSchema.optional(),
|
|
577
542
|
content: z2.union([
|
|
578
543
|
z2.array(
|
|
579
544
|
z2.object({
|
|
@@ -2306,7 +2271,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2306
2271
|
cacheControlValidator,
|
|
2307
2272
|
toolNameMapping
|
|
2308
2273
|
}) {
|
|
2309
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u
|
|
2274
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2310
2275
|
const betas = /* @__PURE__ */ new Set();
|
|
2311
2276
|
const blocks = groupIntoBlocks(prompt);
|
|
2312
2277
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2711,6 +2676,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2711
2676
|
break;
|
|
2712
2677
|
}
|
|
2713
2678
|
case "tool-call": {
|
|
2679
|
+
const caller = getAnthropicCaller(part.providerOptions);
|
|
2714
2680
|
if (part.providerExecuted) {
|
|
2715
2681
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2716
2682
|
part.toolName
|
|
@@ -2745,6 +2711,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2745
2711
|
name: subtoolName,
|
|
2746
2712
|
// map back to subtool name
|
|
2747
2713
|
input,
|
|
2714
|
+
...caller && { caller },
|
|
2748
2715
|
cache_control: cacheControl
|
|
2749
2716
|
});
|
|
2750
2717
|
} else if (
|
|
@@ -2758,6 +2725,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2758
2725
|
id: part.toolCallId,
|
|
2759
2726
|
name: "code_execution",
|
|
2760
2727
|
input: inputWithoutType,
|
|
2728
|
+
...caller && { caller },
|
|
2761
2729
|
cache_control: cacheControl
|
|
2762
2730
|
});
|
|
2763
2731
|
} else {
|
|
@@ -2768,6 +2736,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2768
2736
|
id: part.toolCallId,
|
|
2769
2737
|
name: providerToolName,
|
|
2770
2738
|
input: part.input,
|
|
2739
|
+
...caller && { caller },
|
|
2771
2740
|
cache_control: cacheControl
|
|
2772
2741
|
});
|
|
2773
2742
|
} else if (providerToolName === "tool_search_tool_regex" || providerToolName === "tool_search_tool_bm25") {
|
|
@@ -2776,6 +2745,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2776
2745
|
id: part.toolCallId,
|
|
2777
2746
|
name: providerToolName,
|
|
2778
2747
|
input: part.input,
|
|
2748
|
+
...caller && { caller },
|
|
2779
2749
|
cache_control: cacheControl
|
|
2780
2750
|
});
|
|
2781
2751
|
} else if (providerToolName === "advisor") {
|
|
@@ -2784,6 +2754,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2784
2754
|
id: part.toolCallId,
|
|
2785
2755
|
name: "advisor",
|
|
2786
2756
|
input: {},
|
|
2757
|
+
...caller && { caller },
|
|
2787
2758
|
cache_control: cacheControl
|
|
2788
2759
|
});
|
|
2789
2760
|
} else {
|
|
@@ -2795,11 +2766,6 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2795
2766
|
}
|
|
2796
2767
|
break;
|
|
2797
2768
|
}
|
|
2798
|
-
const callerOptions = (_o = part.providerOptions) == null ? void 0 : _o.anthropic;
|
|
2799
|
-
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
|
|
2800
|
-
type: callerOptions.caller.type,
|
|
2801
|
-
tool_id: callerOptions.caller.toolId
|
|
2802
|
-
} : callerOptions.caller.type === "direct" ? { type: "direct" } : void 0 : void 0;
|
|
2803
2769
|
anthropicContent.push({
|
|
2804
2770
|
type: "tool_use",
|
|
2805
2771
|
id: part.toolCallId,
|
|
@@ -2814,6 +2780,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2814
2780
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2815
2781
|
part.toolName
|
|
2816
2782
|
);
|
|
2783
|
+
const caller = getAnthropicCaller(part.providerOptions);
|
|
2817
2784
|
if (mcpToolUseIds.has(part.toolCallId)) {
|
|
2818
2785
|
const output = part.output;
|
|
2819
2786
|
if (output.type !== "json" && output.type !== "error-json") {
|
|
@@ -2848,7 +2815,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2848
2815
|
tool_use_id: part.toolCallId,
|
|
2849
2816
|
content: {
|
|
2850
2817
|
type: "code_execution_tool_result_error",
|
|
2851
|
-
error_code: (
|
|
2818
|
+
error_code: (_o = errorInfo.errorCode) != null ? _o : "unknown"
|
|
2852
2819
|
},
|
|
2853
2820
|
cache_control: cacheControl
|
|
2854
2821
|
});
|
|
@@ -2859,7 +2826,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2859
2826
|
cache_control: cacheControl,
|
|
2860
2827
|
content: {
|
|
2861
2828
|
type: "bash_code_execution_tool_result_error",
|
|
2862
|
-
error_code: (
|
|
2829
|
+
error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
|
|
2863
2830
|
}
|
|
2864
2831
|
});
|
|
2865
2832
|
}
|
|
@@ -2892,7 +2859,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2892
2859
|
stdout: codeExecutionOutput.stdout,
|
|
2893
2860
|
stderr: codeExecutionOutput.stderr,
|
|
2894
2861
|
return_code: codeExecutionOutput.return_code,
|
|
2895
|
-
content: (
|
|
2862
|
+
content: (_q = codeExecutionOutput.content) != null ? _q : []
|
|
2896
2863
|
},
|
|
2897
2864
|
cache_control: cacheControl
|
|
2898
2865
|
});
|
|
@@ -2910,7 +2877,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2910
2877
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
2911
2878
|
stderr: codeExecutionOutput.stderr,
|
|
2912
2879
|
return_code: codeExecutionOutput.return_code,
|
|
2913
|
-
content: (
|
|
2880
|
+
content: (_r = codeExecutionOutput.content) != null ? _r : []
|
|
2914
2881
|
},
|
|
2915
2882
|
cache_control: cacheControl
|
|
2916
2883
|
});
|
|
@@ -2929,7 +2896,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2929
2896
|
stdout: codeExecutionOutput.stdout,
|
|
2930
2897
|
stderr: codeExecutionOutput.stderr,
|
|
2931
2898
|
return_code: codeExecutionOutput.return_code,
|
|
2932
|
-
content: (
|
|
2899
|
+
content: (_s = codeExecutionOutput.content) != null ? _s : []
|
|
2933
2900
|
},
|
|
2934
2901
|
cache_control: cacheControl
|
|
2935
2902
|
});
|
|
@@ -2967,8 +2934,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2967
2934
|
tool_use_id: part.toolCallId,
|
|
2968
2935
|
content: {
|
|
2969
2936
|
type: "web_fetch_tool_result_error",
|
|
2970
|
-
error_code: (
|
|
2937
|
+
error_code: (_t = (await extractErrorValue(output.value)).errorCode) != null ? _t : "unavailable"
|
|
2971
2938
|
},
|
|
2939
|
+
...caller && { caller },
|
|
2972
2940
|
cache_control: cacheControl
|
|
2973
2941
|
});
|
|
2974
2942
|
break;
|
|
@@ -3002,6 +2970,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
3002
2970
|
}
|
|
3003
2971
|
}
|
|
3004
2972
|
},
|
|
2973
|
+
...caller && { caller },
|
|
3005
2974
|
cache_control: cacheControl
|
|
3006
2975
|
});
|
|
3007
2976
|
break;
|
|
@@ -3014,8 +2983,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
3014
2983
|
tool_use_id: part.toolCallId,
|
|
3015
2984
|
content: {
|
|
3016
2985
|
type: "web_search_tool_result_error",
|
|
3017
|
-
error_code: (
|
|
2986
|
+
error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
|
|
3018
2987
|
},
|
|
2988
|
+
...caller && { caller },
|
|
3019
2989
|
cache_control: cacheControl
|
|
3020
2990
|
});
|
|
3021
2991
|
break;
|
|
@@ -3041,6 +3011,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
3041
3011
|
encrypted_content: result.encryptedContent,
|
|
3042
3012
|
type: result.type
|
|
3043
3013
|
})),
|
|
3014
|
+
...caller && { caller },
|
|
3044
3015
|
cache_control: cacheControl
|
|
3045
3016
|
});
|
|
3046
3017
|
break;
|
|
@@ -3212,6 +3183,17 @@ function moveToolUseBlocksToEnd(content) {
|
|
|
3212
3183
|
flushSegment();
|
|
3213
3184
|
return result;
|
|
3214
3185
|
}
|
|
3186
|
+
function getAnthropicCaller(providerOptions) {
|
|
3187
|
+
var _a;
|
|
3188
|
+
const caller = (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.caller;
|
|
3189
|
+
if (((caller == null ? void 0 : caller.type) === "code_execution_20250825" || (caller == null ? void 0 : caller.type) === "code_execution_20260120") && caller.toolId) {
|
|
3190
|
+
return {
|
|
3191
|
+
type: caller.type,
|
|
3192
|
+
tool_id: caller.toolId
|
|
3193
|
+
};
|
|
3194
|
+
}
|
|
3195
|
+
return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
|
|
3196
|
+
}
|
|
3215
3197
|
|
|
3216
3198
|
// src/map-anthropic-stop-reason.ts
|
|
3217
3199
|
function mapAnthropicStopReason({
|
|
@@ -3428,6 +3410,16 @@ function createCitationSource(citation, citationDocuments, generateId3) {
|
|
|
3428
3410
|
}
|
|
3429
3411
|
};
|
|
3430
3412
|
}
|
|
3413
|
+
function getAnthropicCallerInfo(caller) {
|
|
3414
|
+
return caller == null ? void 0 : {
|
|
3415
|
+
type: caller.type,
|
|
3416
|
+
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
3417
|
+
};
|
|
3418
|
+
}
|
|
3419
|
+
function getAnthropicCallerMetadata(caller) {
|
|
3420
|
+
const callerInfo = getAnthropicCallerInfo(caller);
|
|
3421
|
+
return callerInfo == null ? {} : { providerMetadata: { anthropic: { caller: callerInfo } } };
|
|
3422
|
+
}
|
|
3431
3423
|
var AnthropicMessagesLanguageModel = class {
|
|
3432
3424
|
constructor(modelId, config) {
|
|
3433
3425
|
this.specificationVersion = "v3";
|
|
@@ -4076,23 +4068,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4076
4068
|
text: JSON.stringify(part.input)
|
|
4077
4069
|
});
|
|
4078
4070
|
} else {
|
|
4079
|
-
const caller = part.caller;
|
|
4080
|
-
const callerInfo = caller ? {
|
|
4081
|
-
type: caller.type,
|
|
4082
|
-
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
4083
|
-
} : void 0;
|
|
4084
4071
|
content.push({
|
|
4085
4072
|
type: "tool-call",
|
|
4086
4073
|
toolCallId: part.id,
|
|
4087
4074
|
toolName: part.name,
|
|
4088
4075
|
input: JSON.stringify(part.input),
|
|
4089
|
-
...
|
|
4090
|
-
providerMetadata: {
|
|
4091
|
-
anthropic: {
|
|
4092
|
-
caller: callerInfo
|
|
4093
|
-
}
|
|
4094
|
-
}
|
|
4095
|
-
}
|
|
4076
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4096
4077
|
});
|
|
4097
4078
|
}
|
|
4098
4079
|
break;
|
|
@@ -4110,7 +4091,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4110
4091
|
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
4111
4092
|
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
4112
4093
|
// tool as dynamic.
|
|
4113
|
-
...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {}
|
|
4094
|
+
...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {},
|
|
4095
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4114
4096
|
});
|
|
4115
4097
|
} else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
|
|
4116
4098
|
const inputToSerialize = part.name === "code_execution" && part.input != null && typeof part.input === "object" && "code" in part.input && !("type" in part.input) ? { type: "programmatic-tool-call", ...part.input } : part.input;
|
|
@@ -4124,7 +4106,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4124
4106
|
// implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
|
|
4125
4107
|
// tool was not explicitly provided. We therefore bypass the general validation by marking the
|
|
4126
4108
|
// tool as dynamic.
|
|
4127
|
-
...markCodeExecutionDynamic && part.name === "code_execution" ? { dynamic: true } : {}
|
|
4109
|
+
...markCodeExecutionDynamic && part.name === "code_execution" ? { dynamic: true } : {},
|
|
4110
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4128
4111
|
});
|
|
4129
4112
|
} else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
|
|
4130
4113
|
serverToolCalls[part.id] = part.name;
|
|
@@ -4133,7 +4116,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4133
4116
|
toolCallId: part.id,
|
|
4134
4117
|
toolName: toolNameMapping.toCustomToolName(part.name),
|
|
4135
4118
|
input: JSON.stringify(part.input),
|
|
4136
|
-
providerExecuted: true
|
|
4119
|
+
providerExecuted: true,
|
|
4120
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4137
4121
|
});
|
|
4138
4122
|
} else if (part.name === "advisor") {
|
|
4139
4123
|
content.push({
|
|
@@ -4141,7 +4125,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4141
4125
|
toolCallId: part.id,
|
|
4142
4126
|
toolName: toolNameMapping.toCustomToolName("advisor"),
|
|
4143
4127
|
input: JSON.stringify(part.input),
|
|
4144
|
-
providerExecuted: true
|
|
4128
|
+
providerExecuted: true,
|
|
4129
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4145
4130
|
});
|
|
4146
4131
|
}
|
|
4147
4132
|
break;
|
|
@@ -4200,7 +4185,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4200
4185
|
data: part.content.content.source.data
|
|
4201
4186
|
}
|
|
4202
4187
|
}
|
|
4203
|
-
}
|
|
4188
|
+
},
|
|
4189
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4204
4190
|
});
|
|
4205
4191
|
} else if (part.content.type === "web_fetch_tool_result_error") {
|
|
4206
4192
|
content.push({
|
|
@@ -4211,7 +4197,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4211
4197
|
result: {
|
|
4212
4198
|
type: "web_fetch_tool_result_error",
|
|
4213
4199
|
errorCode: part.content.error_code
|
|
4214
|
-
}
|
|
4200
|
+
},
|
|
4201
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4215
4202
|
});
|
|
4216
4203
|
}
|
|
4217
4204
|
break;
|
|
@@ -4231,7 +4218,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4231
4218
|
encryptedContent: result.encrypted_content,
|
|
4232
4219
|
type: result.type
|
|
4233
4220
|
};
|
|
4234
|
-
})
|
|
4221
|
+
}),
|
|
4222
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4235
4223
|
});
|
|
4236
4224
|
for (const result of part.content) {
|
|
4237
4225
|
content.push({
|
|
@@ -4256,7 +4244,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4256
4244
|
result: {
|
|
4257
4245
|
type: "web_search_tool_result_error",
|
|
4258
4246
|
errorCode: part.content.error_code
|
|
4259
|
-
}
|
|
4247
|
+
},
|
|
4248
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4260
4249
|
});
|
|
4261
4250
|
}
|
|
4262
4251
|
break;
|
|
@@ -4617,11 +4606,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4617
4606
|
id: String(value.index)
|
|
4618
4607
|
});
|
|
4619
4608
|
} else {
|
|
4620
|
-
const
|
|
4621
|
-
const callerInfo = caller ? {
|
|
4622
|
-
type: caller.type,
|
|
4623
|
-
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
4624
|
-
} : void 0;
|
|
4609
|
+
const callerInfo = getAnthropicCallerInfo(part.caller);
|
|
4625
4610
|
const hasNonEmptyInput = part.input && Object.keys(part.input).length > 0;
|
|
4626
4611
|
const initialInput = hasNonEmptyInput ? JSON.stringify(part.input) : "";
|
|
4627
4612
|
contentBlocks[value.index] = {
|
|
@@ -4641,6 +4626,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4641
4626
|
return;
|
|
4642
4627
|
}
|
|
4643
4628
|
case "server_tool_use": {
|
|
4629
|
+
const callerInfo = getAnthropicCallerInfo(part.caller);
|
|
4644
4630
|
if ([
|
|
4645
4631
|
"web_fetch",
|
|
4646
4632
|
"web_search",
|
|
@@ -4668,7 +4654,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4668
4654
|
...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {},
|
|
4669
4655
|
firstDelta: finalInput.length === 0,
|
|
4670
4656
|
providerToolName,
|
|
4671
|
-
providerToolInputType
|
|
4657
|
+
providerToolInputType,
|
|
4658
|
+
...callerInfo && { caller: callerInfo }
|
|
4672
4659
|
};
|
|
4673
4660
|
controller.enqueue({
|
|
4674
4661
|
type: "tool-input-start",
|
|
@@ -4693,7 +4680,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4693
4680
|
input: "",
|
|
4694
4681
|
providerExecuted: true,
|
|
4695
4682
|
firstDelta: true,
|
|
4696
|
-
providerToolName: part.name
|
|
4683
|
+
providerToolName: part.name,
|
|
4684
|
+
...callerInfo && { caller: callerInfo }
|
|
4697
4685
|
};
|
|
4698
4686
|
controller.enqueue({
|
|
4699
4687
|
type: "tool-input-start",
|
|
@@ -4710,7 +4698,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4710
4698
|
input: "{}",
|
|
4711
4699
|
providerExecuted: true,
|
|
4712
4700
|
firstDelta: true,
|
|
4713
|
-
providerToolName: part.name
|
|
4701
|
+
providerToolName: part.name,
|
|
4702
|
+
...callerInfo && { caller: callerInfo }
|
|
4714
4703
|
};
|
|
4715
4704
|
controller.enqueue({
|
|
4716
4705
|
type: "tool-input-start",
|
|
@@ -4745,7 +4734,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4745
4734
|
data: part.content.content.source.data
|
|
4746
4735
|
}
|
|
4747
4736
|
}
|
|
4748
|
-
}
|
|
4737
|
+
},
|
|
4738
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4749
4739
|
});
|
|
4750
4740
|
} else if (part.content.type === "web_fetch_tool_result_error") {
|
|
4751
4741
|
controller.enqueue({
|
|
@@ -4756,7 +4746,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4756
4746
|
result: {
|
|
4757
4747
|
type: "web_fetch_tool_result_error",
|
|
4758
4748
|
errorCode: part.content.error_code
|
|
4759
|
-
}
|
|
4749
|
+
},
|
|
4750
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4760
4751
|
});
|
|
4761
4752
|
}
|
|
4762
4753
|
return;
|
|
@@ -4776,7 +4767,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4776
4767
|
encryptedContent: result.encrypted_content,
|
|
4777
4768
|
type: result.type
|
|
4778
4769
|
};
|
|
4779
|
-
})
|
|
4770
|
+
}),
|
|
4771
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4780
4772
|
});
|
|
4781
4773
|
for (const result of part.content) {
|
|
4782
4774
|
controller.enqueue({
|
|
@@ -4801,7 +4793,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4801
4793
|
result: {
|
|
4802
4794
|
type: "web_search_tool_result_error",
|
|
4803
4795
|
errorCode: part.content.error_code
|
|
4804
|
-
}
|
|
4796
|
+
},
|
|
4797
|
+
...getAnthropicCallerMetadata(part.caller)
|
|
4805
4798
|
});
|
|
4806
4799
|
}
|
|
4807
4800
|
return;
|
|
@@ -5201,11 +5194,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5201
5194
|
for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
|
|
5202
5195
|
const part = value.message.content[contentIndex];
|
|
5203
5196
|
if (part.type === "tool_use") {
|
|
5204
|
-
const
|
|
5205
|
-
const callerInfo = caller ? {
|
|
5206
|
-
type: caller.type,
|
|
5207
|
-
toolId: "tool_id" in caller ? caller.tool_id : void 0
|
|
5208
|
-
} : void 0;
|
|
5197
|
+
const callerInfo = getAnthropicCallerInfo(part.caller);
|
|
5209
5198
|
controller.enqueue({
|
|
5210
5199
|
type: "tool-input-start",
|
|
5211
5200
|
id: part.id,
|