@fairyhunter13/ai-anthropic 3.0.58-fork.12 → 3.0.58-fork.13
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/dist/index.js +83 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -79
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +83 -79
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +83 -79
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/anthropic-messages-language-model.ts +1037 -902
package/dist/index.js
CHANGED
|
@@ -2895,7 +2895,10 @@ function mapReasoningToProviderBudget({
|
|
|
2895
2895
|
});
|
|
2896
2896
|
return void 0;
|
|
2897
2897
|
}
|
|
2898
|
-
return Math.min(
|
|
2898
|
+
return Math.min(
|
|
2899
|
+
maxReasoningBudget,
|
|
2900
|
+
Math.max(minReasoningBudget, Math.round(maxOutputTokens * pct))
|
|
2901
|
+
);
|
|
2899
2902
|
}
|
|
2900
2903
|
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
2901
2904
|
var _a;
|
|
@@ -3033,7 +3036,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3033
3036
|
schema: anthropicLanguageModelOptions
|
|
3034
3037
|
}) : null;
|
|
3035
3038
|
const usedCustomProviderKey = customProviderOptions != null;
|
|
3036
|
-
const anthropicOptions = Object.assign(
|
|
3039
|
+
const anthropicOptions = Object.assign(
|
|
3040
|
+
{},
|
|
3041
|
+
canonicalOptions != null ? canonicalOptions : {},
|
|
3042
|
+
customProviderOptions != null ? customProviderOptions : {}
|
|
3043
|
+
);
|
|
3037
3044
|
const {
|
|
3038
3045
|
maxOutputTokens: maxOutputTokensForModel,
|
|
3039
3046
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
@@ -3099,7 +3106,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3099
3106
|
if (anthropicOptions == null ? void 0 : anthropicOptions.prefill) {
|
|
3100
3107
|
const lastMessage = messagesPrompt.messages[messagesPrompt.messages.length - 1];
|
|
3101
3108
|
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant") {
|
|
3102
|
-
;
|
|
3103
3109
|
lastMessage.content.push({
|
|
3104
3110
|
type: "text",
|
|
3105
3111
|
text: anthropicOptions.prefill.trim(),
|
|
@@ -3375,7 +3381,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3375
3381
|
// do not send when not streaming
|
|
3376
3382
|
},
|
|
3377
3383
|
warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
|
|
3378
|
-
betas: /* @__PURE__ */ new Set([
|
|
3384
|
+
betas: /* @__PURE__ */ new Set([
|
|
3385
|
+
...betas,
|
|
3386
|
+
...toolsBetas,
|
|
3387
|
+
...userSuppliedBetas,
|
|
3388
|
+
...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
|
|
3389
|
+
]),
|
|
3379
3390
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3380
3391
|
toolNameMapping,
|
|
3381
3392
|
providerOptionsName,
|
|
@@ -3398,7 +3409,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3398
3409
|
const configBetaHeader = (_a = configHeaders["anthropic-beta"]) != null ? _a : "";
|
|
3399
3410
|
const requestBetaHeader = (_b = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b : "";
|
|
3400
3411
|
return new Set(
|
|
3401
|
-
[
|
|
3412
|
+
[
|
|
3413
|
+
...configBetaHeader.toLowerCase().split(","),
|
|
3414
|
+
...requestBetaHeader.toLowerCase().split(",")
|
|
3415
|
+
].map((beta) => beta.trim()).filter((beta) => beta !== "")
|
|
3402
3416
|
);
|
|
3403
3417
|
}
|
|
3404
3418
|
buildRequestUrl(isStreaming) {
|
|
@@ -3434,13 +3448,25 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3434
3448
|
}
|
|
3435
3449
|
async doGenerate(options) {
|
|
3436
3450
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
3437
|
-
const {
|
|
3451
|
+
const {
|
|
3452
|
+
args,
|
|
3453
|
+
warnings,
|
|
3454
|
+
betas,
|
|
3455
|
+
usesJsonResponseTool,
|
|
3456
|
+
toolNameMapping,
|
|
3457
|
+
providerOptionsName,
|
|
3458
|
+
usedCustomProviderKey
|
|
3459
|
+
} = await this.getArgs({
|
|
3438
3460
|
...options,
|
|
3439
3461
|
stream: false,
|
|
3440
3462
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
3441
3463
|
});
|
|
3442
|
-
const citationDocuments = [
|
|
3443
|
-
|
|
3464
|
+
const citationDocuments = [
|
|
3465
|
+
...this.extractCitationDocuments(options.prompt)
|
|
3466
|
+
];
|
|
3467
|
+
const markCodeExecutionDynamic = hasWebTool20260209WithoutCodeExecution(
|
|
3468
|
+
args.tools
|
|
3469
|
+
);
|
|
3444
3470
|
const {
|
|
3445
3471
|
responseHeaders,
|
|
3446
3472
|
value: response,
|
|
@@ -3450,7 +3476,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3450
3476
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
3451
3477
|
body: this.transformRequestBody(args, betas),
|
|
3452
3478
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
3453
|
-
successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(
|
|
3479
|
+
successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(
|
|
3480
|
+
anthropicMessagesResponseSchema
|
|
3481
|
+
),
|
|
3454
3482
|
abortSignal: options.abortSignal,
|
|
3455
3483
|
fetch: this.config.fetch
|
|
3456
3484
|
});
|
|
@@ -3465,7 +3493,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3465
3493
|
content.push({ type: "text", text: part.text });
|
|
3466
3494
|
if (part.citations) {
|
|
3467
3495
|
for (const citation of part.citations) {
|
|
3468
|
-
const source = createCitationSource(
|
|
3496
|
+
const source = createCitationSource(
|
|
3497
|
+
citation,
|
|
3498
|
+
citationDocuments,
|
|
3499
|
+
this.generateId
|
|
3500
|
+
);
|
|
3469
3501
|
if (source) {
|
|
3470
3502
|
content.push(source);
|
|
3471
3503
|
}
|
|
@@ -3690,20 +3722,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3690
3722
|
}
|
|
3691
3723
|
// code execution 20250522:
|
|
3692
3724
|
case "code_execution_tool_result": {
|
|
3693
|
-
if (markCodeExecutionDynamic) {
|
|
3694
|
-
content.push({
|
|
3695
|
-
type: "tool-result",
|
|
3696
|
-
toolCallId: part.tool_use_id,
|
|
3697
|
-
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
3698
|
-
isError: true,
|
|
3699
|
-
result: {
|
|
3700
|
-
type: "code_execution_tool_result_error",
|
|
3701
|
-
errorCode: "disabled",
|
|
3702
|
-
message: "code_execution is not available. Use web_search and web_fetch as direct tool calls \u2014 they are NOT Python functions."
|
|
3703
|
-
}
|
|
3704
|
-
});
|
|
3705
|
-
break;
|
|
3706
|
-
}
|
|
3707
3725
|
if (part.content.type === "code_execution_result") {
|
|
3708
3726
|
content.push({
|
|
3709
3727
|
type: "tool-result",
|
|
@@ -3747,20 +3765,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3747
3765
|
// code execution 20250825:
|
|
3748
3766
|
case "bash_code_execution_tool_result":
|
|
3749
3767
|
case "text_editor_code_execution_tool_result": {
|
|
3750
|
-
if (markCodeExecutionDynamic) {
|
|
3751
|
-
content.push({
|
|
3752
|
-
type: "tool-result",
|
|
3753
|
-
toolCallId: part.tool_use_id,
|
|
3754
|
-
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
3755
|
-
isError: true,
|
|
3756
|
-
result: {
|
|
3757
|
-
type: "code_execution_tool_result_error",
|
|
3758
|
-
errorCode: "disabled",
|
|
3759
|
-
message: "code_execution is not available. Use web_search and web_fetch as direct tool calls \u2014 they are NOT Python functions."
|
|
3760
|
-
}
|
|
3761
|
-
});
|
|
3762
|
-
break;
|
|
3763
|
-
}
|
|
3764
3768
|
content.push({
|
|
3765
3769
|
type: "tool-result",
|
|
3766
3770
|
toolCallId: part.tool_use_id,
|
|
@@ -3773,8 +3777,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3773
3777
|
case "tool_search_tool_result": {
|
|
3774
3778
|
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3775
3779
|
if (providerToolName == null) {
|
|
3776
|
-
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3777
|
-
|
|
3780
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3781
|
+
"tool_search_tool_bm25"
|
|
3782
|
+
);
|
|
3783
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3784
|
+
"tool_search_tool_regex"
|
|
3785
|
+
);
|
|
3778
3786
|
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3779
3787
|
providerToolName = "tool_search_tool_bm25";
|
|
3780
3788
|
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
@@ -3847,7 +3855,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3847
3855
|
version: skill.version
|
|
3848
3856
|
}))) != null ? _d2 : null
|
|
3849
3857
|
} : null,
|
|
3850
|
-
contextManagement: (_e2 = mapAnthropicResponseContextManagement(
|
|
3858
|
+
contextManagement: (_e2 = mapAnthropicResponseContextManagement(
|
|
3859
|
+
response.context_management
|
|
3860
|
+
)) != null ? _e2 : null
|
|
3851
3861
|
};
|
|
3852
3862
|
const providerMetadata = {
|
|
3853
3863
|
anthropic: anthropicMetadata
|
|
@@ -3874,15 +3884,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3874
3884
|
stream: true,
|
|
3875
3885
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
3876
3886
|
});
|
|
3877
|
-
const citationDocuments = [
|
|
3878
|
-
|
|
3887
|
+
const citationDocuments = [
|
|
3888
|
+
...this.extractCitationDocuments(options.prompt)
|
|
3889
|
+
];
|
|
3890
|
+
const markCodeExecutionDynamic = hasWebTool20260209WithoutCodeExecution(
|
|
3891
|
+
body.tools
|
|
3892
|
+
);
|
|
3879
3893
|
const url = this.buildRequestUrl(true);
|
|
3880
3894
|
const { responseHeaders, value: response } = await (0, import_provider_utils15.postJsonToApi)({
|
|
3881
3895
|
url,
|
|
3882
3896
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
3883
3897
|
body: this.transformRequestBody(body, betas),
|
|
3884
3898
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
3885
|
-
successfulResponseHandler: (0, import_provider_utils15.createEventSourceResponseHandler)(
|
|
3899
|
+
successfulResponseHandler: (0, import_provider_utils15.createEventSourceResponseHandler)(
|
|
3900
|
+
anthropicMessagesChunkSchema
|
|
3901
|
+
),
|
|
3886
3902
|
abortSignal: options.abortSignal,
|
|
3887
3903
|
fetch: this.config.fetch
|
|
3888
3904
|
});
|
|
@@ -4043,7 +4059,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4043
4059
|
});
|
|
4044
4060
|
} else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
|
|
4045
4061
|
serverToolCalls[part.id] = part.name;
|
|
4046
|
-
const customToolName = toolNameMapping.toCustomToolName(
|
|
4062
|
+
const customToolName = toolNameMapping.toCustomToolName(
|
|
4063
|
+
part.name
|
|
4064
|
+
);
|
|
4047
4065
|
contentBlocks[value.index] = {
|
|
4048
4066
|
type: "tool-call",
|
|
4049
4067
|
toolCallId: part.id,
|
|
@@ -4149,20 +4167,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4149
4167
|
}
|
|
4150
4168
|
// code execution 20250522:
|
|
4151
4169
|
case "code_execution_tool_result": {
|
|
4152
|
-
if (markCodeExecutionDynamic) {
|
|
4153
|
-
controller.enqueue({
|
|
4154
|
-
type: "tool-result",
|
|
4155
|
-
toolCallId: part.tool_use_id,
|
|
4156
|
-
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
4157
|
-
isError: true,
|
|
4158
|
-
result: {
|
|
4159
|
-
type: "code_execution_tool_result_error",
|
|
4160
|
-
errorCode: "disabled",
|
|
4161
|
-
message: "code_execution is not available. Use web_search and web_fetch as direct tool calls \u2014 they are NOT Python functions."
|
|
4162
|
-
}
|
|
4163
|
-
});
|
|
4164
|
-
return;
|
|
4165
|
-
}
|
|
4166
4170
|
if (part.content.type === "code_execution_result") {
|
|
4167
4171
|
controller.enqueue({
|
|
4168
4172
|
type: "tool-result",
|
|
@@ -4206,20 +4210,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4206
4210
|
// code execution 20250825:
|
|
4207
4211
|
case "bash_code_execution_tool_result":
|
|
4208
4212
|
case "text_editor_code_execution_tool_result": {
|
|
4209
|
-
if (markCodeExecutionDynamic) {
|
|
4210
|
-
controller.enqueue({
|
|
4211
|
-
type: "tool-result",
|
|
4212
|
-
toolCallId: part.tool_use_id,
|
|
4213
|
-
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
4214
|
-
isError: true,
|
|
4215
|
-
result: {
|
|
4216
|
-
type: "code_execution_tool_result_error",
|
|
4217
|
-
errorCode: "disabled",
|
|
4218
|
-
message: "code_execution is not available. Use web_search and web_fetch as direct tool calls \u2014 they are NOT Python functions."
|
|
4219
|
-
}
|
|
4220
|
-
});
|
|
4221
|
-
return;
|
|
4222
|
-
}
|
|
4223
4213
|
controller.enqueue({
|
|
4224
4214
|
type: "tool-result",
|
|
4225
4215
|
toolCallId: part.tool_use_id,
|
|
@@ -4232,8 +4222,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4232
4222
|
case "tool_search_tool_result": {
|
|
4233
4223
|
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
4234
4224
|
if (providerToolName == null) {
|
|
4235
|
-
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
4236
|
-
|
|
4225
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
4226
|
+
"tool_search_tool_bm25"
|
|
4227
|
+
);
|
|
4228
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
4229
|
+
"tool_search_tool_regex"
|
|
4230
|
+
);
|
|
4237
4231
|
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
4238
4232
|
providerToolName = "tool_search_tool_bm25";
|
|
4239
4233
|
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
@@ -4298,7 +4292,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4298
4292
|
}
|
|
4299
4293
|
default: {
|
|
4300
4294
|
const _exhaustiveCheck = contentBlockType;
|
|
4301
|
-
throw new Error(
|
|
4295
|
+
throw new Error(
|
|
4296
|
+
`Unsupported content block type: ${_exhaustiveCheck}`
|
|
4297
|
+
);
|
|
4302
4298
|
}
|
|
4303
4299
|
}
|
|
4304
4300
|
}
|
|
@@ -4444,7 +4440,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4444
4440
|
}
|
|
4445
4441
|
case "citations_delta": {
|
|
4446
4442
|
const citation = value.delta.citation;
|
|
4447
|
-
const source = createCitationSource(
|
|
4443
|
+
const source = createCitationSource(
|
|
4444
|
+
citation,
|
|
4445
|
+
citationDocuments,
|
|
4446
|
+
generateId3
|
|
4447
|
+
);
|
|
4448
4448
|
if (source) {
|
|
4449
4449
|
controller.enqueue(source);
|
|
4450
4450
|
}
|
|
@@ -4452,7 +4452,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4452
4452
|
}
|
|
4453
4453
|
default: {
|
|
4454
4454
|
const _exhaustiveCheck = deltaType;
|
|
4455
|
-
throw new Error(
|
|
4455
|
+
throw new Error(
|
|
4456
|
+
`Unsupported delta type: ${_exhaustiveCheck}`
|
|
4457
|
+
);
|
|
4456
4458
|
}
|
|
4457
4459
|
}
|
|
4458
4460
|
}
|
|
@@ -4560,7 +4562,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4560
4562
|
}))) != null ? _n : null
|
|
4561
4563
|
} : null;
|
|
4562
4564
|
if (value.context_management) {
|
|
4563
|
-
contextManagement = mapAnthropicResponseContextManagement(
|
|
4565
|
+
contextManagement = mapAnthropicResponseContextManagement(
|
|
4566
|
+
value.context_management
|
|
4567
|
+
);
|
|
4564
4568
|
}
|
|
4565
4569
|
rawUsage = {
|
|
4566
4570
|
...rawUsage,
|