@fairyhunter13/ai-anthropic 3.0.58-fork.12 → 3.0.58-fork.14
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 +87 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -43
- 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 +87 -43
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +87 -43
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/anthropic-messages-language-model.ts +1066 -882
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
|
}
|
|
@@ -3696,11 +3728,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3696
3728
|
toolCallId: part.tool_use_id,
|
|
3697
3729
|
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
3698
3730
|
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
|
-
}
|
|
3731
|
+
result: "STOP: code_execution is disabled. Do NOT wrap web_search or web_fetch in Python code. Call web_search and web_fetch as DIRECT tool calls \u2014 they are standalone tools, not Python functions."
|
|
3704
3732
|
});
|
|
3705
3733
|
break;
|
|
3706
3734
|
}
|
|
@@ -3753,11 +3781,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3753
3781
|
toolCallId: part.tool_use_id,
|
|
3754
3782
|
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
3755
3783
|
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
|
-
}
|
|
3784
|
+
result: "STOP: code_execution is disabled. Do NOT wrap web_search or web_fetch in Python code. Call web_search and web_fetch as DIRECT tool calls \u2014 they are standalone tools, not Python functions."
|
|
3761
3785
|
});
|
|
3762
3786
|
break;
|
|
3763
3787
|
}
|
|
@@ -3773,8 +3797,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3773
3797
|
case "tool_search_tool_result": {
|
|
3774
3798
|
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
3775
3799
|
if (providerToolName == null) {
|
|
3776
|
-
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3777
|
-
|
|
3800
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
3801
|
+
"tool_search_tool_bm25"
|
|
3802
|
+
);
|
|
3803
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
3804
|
+
"tool_search_tool_regex"
|
|
3805
|
+
);
|
|
3778
3806
|
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
3779
3807
|
providerToolName = "tool_search_tool_bm25";
|
|
3780
3808
|
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
@@ -3847,7 +3875,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3847
3875
|
version: skill.version
|
|
3848
3876
|
}))) != null ? _d2 : null
|
|
3849
3877
|
} : null,
|
|
3850
|
-
contextManagement: (_e2 = mapAnthropicResponseContextManagement(
|
|
3878
|
+
contextManagement: (_e2 = mapAnthropicResponseContextManagement(
|
|
3879
|
+
response.context_management
|
|
3880
|
+
)) != null ? _e2 : null
|
|
3851
3881
|
};
|
|
3852
3882
|
const providerMetadata = {
|
|
3853
3883
|
anthropic: anthropicMetadata
|
|
@@ -3874,15 +3904,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3874
3904
|
stream: true,
|
|
3875
3905
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
3876
3906
|
});
|
|
3877
|
-
const citationDocuments = [
|
|
3878
|
-
|
|
3907
|
+
const citationDocuments = [
|
|
3908
|
+
...this.extractCitationDocuments(options.prompt)
|
|
3909
|
+
];
|
|
3910
|
+
const markCodeExecutionDynamic = hasWebTool20260209WithoutCodeExecution(
|
|
3911
|
+
body.tools
|
|
3912
|
+
);
|
|
3879
3913
|
const url = this.buildRequestUrl(true);
|
|
3880
3914
|
const { responseHeaders, value: response } = await (0, import_provider_utils15.postJsonToApi)({
|
|
3881
3915
|
url,
|
|
3882
3916
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
3883
3917
|
body: this.transformRequestBody(body, betas),
|
|
3884
3918
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
3885
|
-
successfulResponseHandler: (0, import_provider_utils15.createEventSourceResponseHandler)(
|
|
3919
|
+
successfulResponseHandler: (0, import_provider_utils15.createEventSourceResponseHandler)(
|
|
3920
|
+
anthropicMessagesChunkSchema
|
|
3921
|
+
),
|
|
3886
3922
|
abortSignal: options.abortSignal,
|
|
3887
3923
|
fetch: this.config.fetch
|
|
3888
3924
|
});
|
|
@@ -4043,7 +4079,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4043
4079
|
});
|
|
4044
4080
|
} else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
|
|
4045
4081
|
serverToolCalls[part.id] = part.name;
|
|
4046
|
-
const customToolName = toolNameMapping.toCustomToolName(
|
|
4082
|
+
const customToolName = toolNameMapping.toCustomToolName(
|
|
4083
|
+
part.name
|
|
4084
|
+
);
|
|
4047
4085
|
contentBlocks[value.index] = {
|
|
4048
4086
|
type: "tool-call",
|
|
4049
4087
|
toolCallId: part.id,
|
|
@@ -4155,11 +4193,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4155
4193
|
toolCallId: part.tool_use_id,
|
|
4156
4194
|
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
4157
4195
|
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
|
-
}
|
|
4196
|
+
result: "STOP: code_execution is disabled. Do NOT wrap web_search or web_fetch in Python code. Call web_search and web_fetch as DIRECT tool calls \u2014 they are standalone tools, not Python functions."
|
|
4163
4197
|
});
|
|
4164
4198
|
return;
|
|
4165
4199
|
}
|
|
@@ -4212,11 +4246,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4212
4246
|
toolCallId: part.tool_use_id,
|
|
4213
4247
|
toolName: toolNameMapping.toCustomToolName("code_execution"),
|
|
4214
4248
|
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
|
-
}
|
|
4249
|
+
result: "STOP: code_execution is disabled. Do NOT wrap web_search or web_fetch in Python code. Call web_search and web_fetch as DIRECT tool calls \u2014 they are standalone tools, not Python functions."
|
|
4220
4250
|
});
|
|
4221
4251
|
return;
|
|
4222
4252
|
}
|
|
@@ -4232,8 +4262,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4232
4262
|
case "tool_search_tool_result": {
|
|
4233
4263
|
let providerToolName = serverToolCalls[part.tool_use_id];
|
|
4234
4264
|
if (providerToolName == null) {
|
|
4235
|
-
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
4236
|
-
|
|
4265
|
+
const bm25CustomName = toolNameMapping.toCustomToolName(
|
|
4266
|
+
"tool_search_tool_bm25"
|
|
4267
|
+
);
|
|
4268
|
+
const regexCustomName = toolNameMapping.toCustomToolName(
|
|
4269
|
+
"tool_search_tool_regex"
|
|
4270
|
+
);
|
|
4237
4271
|
if (bm25CustomName !== "tool_search_tool_bm25") {
|
|
4238
4272
|
providerToolName = "tool_search_tool_bm25";
|
|
4239
4273
|
} else if (regexCustomName !== "tool_search_tool_regex") {
|
|
@@ -4298,7 +4332,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4298
4332
|
}
|
|
4299
4333
|
default: {
|
|
4300
4334
|
const _exhaustiveCheck = contentBlockType;
|
|
4301
|
-
throw new Error(
|
|
4335
|
+
throw new Error(
|
|
4336
|
+
`Unsupported content block type: ${_exhaustiveCheck}`
|
|
4337
|
+
);
|
|
4302
4338
|
}
|
|
4303
4339
|
}
|
|
4304
4340
|
}
|
|
@@ -4444,7 +4480,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4444
4480
|
}
|
|
4445
4481
|
case "citations_delta": {
|
|
4446
4482
|
const citation = value.delta.citation;
|
|
4447
|
-
const source = createCitationSource(
|
|
4483
|
+
const source = createCitationSource(
|
|
4484
|
+
citation,
|
|
4485
|
+
citationDocuments,
|
|
4486
|
+
generateId3
|
|
4487
|
+
);
|
|
4448
4488
|
if (source) {
|
|
4449
4489
|
controller.enqueue(source);
|
|
4450
4490
|
}
|
|
@@ -4452,7 +4492,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4452
4492
|
}
|
|
4453
4493
|
default: {
|
|
4454
4494
|
const _exhaustiveCheck = deltaType;
|
|
4455
|
-
throw new Error(
|
|
4495
|
+
throw new Error(
|
|
4496
|
+
`Unsupported delta type: ${_exhaustiveCheck}`
|
|
4497
|
+
);
|
|
4456
4498
|
}
|
|
4457
4499
|
}
|
|
4458
4500
|
}
|
|
@@ -4560,7 +4602,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4560
4602
|
}))) != null ? _n : null
|
|
4561
4603
|
} : null;
|
|
4562
4604
|
if (value.context_management) {
|
|
4563
|
-
contextManagement = mapAnthropicResponseContextManagement(
|
|
4605
|
+
contextManagement = mapAnthropicResponseContextManagement(
|
|
4606
|
+
value.context_management
|
|
4607
|
+
);
|
|
4564
4608
|
}
|
|
4565
4609
|
rawUsage = {
|
|
4566
4610
|
...rawUsage,
|