@fairyhunter13/ai-anthropic 3.0.58-fork.10 → 3.0.58-fork.11

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 CHANGED
@@ -2981,11 +2981,7 @@ var AnthropicMessagesLanguageModel = class {
2981
2981
  schema: anthropicLanguageModelOptions
2982
2982
  }) : null;
2983
2983
  const usedCustomProviderKey = customProviderOptions != null;
2984
- const anthropicOptions = Object.assign(
2985
- {},
2986
- canonicalOptions != null ? canonicalOptions : {},
2987
- customProviderOptions != null ? customProviderOptions : {}
2988
- );
2984
+ const anthropicOptions = Object.assign({}, canonicalOptions != null ? canonicalOptions : {}, customProviderOptions != null ? customProviderOptions : {});
2989
2985
  const {
2990
2986
  maxOutputTokens: maxOutputTokensForModel,
2991
2987
  supportsStructuredOutput: modelSupportsStructuredOutput,
@@ -3051,6 +3047,7 @@ var AnthropicMessagesLanguageModel = class {
3051
3047
  if (anthropicOptions == null ? void 0 : anthropicOptions.prefill) {
3052
3048
  const lastMessage = messagesPrompt.messages[messagesPrompt.messages.length - 1];
3053
3049
  if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant") {
3050
+ ;
3054
3051
  lastMessage.content.push({
3055
3052
  type: "text",
3056
3053
  text: anthropicOptions.prefill.trim(),
@@ -3326,12 +3323,7 @@ var AnthropicMessagesLanguageModel = class {
3326
3323
  // do not send when not streaming
3327
3324
  },
3328
3325
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
3329
- betas: /* @__PURE__ */ new Set([
3330
- ...betas,
3331
- ...toolsBetas,
3332
- ...userSuppliedBetas,
3333
- ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
3334
- ]),
3326
+ betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas, ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []]),
3335
3327
  usesJsonResponseTool: jsonResponseTool != null,
3336
3328
  toolNameMapping,
3337
3329
  providerOptionsName,
@@ -3354,10 +3346,7 @@ var AnthropicMessagesLanguageModel = class {
3354
3346
  const configBetaHeader = (_a = configHeaders["anthropic-beta"]) != null ? _a : "";
3355
3347
  const requestBetaHeader = (_b = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b : "";
3356
3348
  return new Set(
3357
- [
3358
- ...configBetaHeader.toLowerCase().split(","),
3359
- ...requestBetaHeader.toLowerCase().split(",")
3360
- ].map((beta) => beta.trim()).filter((beta) => beta !== "")
3349
+ [...configBetaHeader.toLowerCase().split(","), ...requestBetaHeader.toLowerCase().split(",")].map((beta) => beta.trim()).filter((beta) => beta !== "")
3361
3350
  );
3362
3351
  }
3363
3352
  buildRequestUrl(isStreaming) {
@@ -3393,25 +3382,13 @@ var AnthropicMessagesLanguageModel = class {
3393
3382
  }
3394
3383
  async doGenerate(options) {
3395
3384
  var _a, _b, _c, _d, _e, _f, _g;
3396
- const {
3397
- args,
3398
- warnings,
3399
- betas,
3400
- usesJsonResponseTool,
3401
- toolNameMapping,
3402
- providerOptionsName,
3403
- usedCustomProviderKey
3404
- } = await this.getArgs({
3385
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
3405
3386
  ...options,
3406
3387
  stream: false,
3407
3388
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
3408
3389
  });
3409
- const citationDocuments = [
3410
- ...this.extractCitationDocuments(options.prompt)
3411
- ];
3412
- const markCodeExecutionDynamic = hasWebTool20260209WithoutCodeExecution(
3413
- args.tools
3414
- );
3390
+ const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
3391
+ const markCodeExecutionDynamic = hasWebTool20260209WithoutCodeExecution(args.tools);
3415
3392
  const {
3416
3393
  responseHeaders,
3417
3394
  value: response,
@@ -3421,9 +3398,7 @@ var AnthropicMessagesLanguageModel = class {
3421
3398
  headers: await this.getHeaders({ betas, headers: options.headers }),
3422
3399
  body: this.transformRequestBody(args, betas),
3423
3400
  failedResponseHandler: anthropicFailedResponseHandler,
3424
- successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(
3425
- anthropicMessagesResponseSchema
3426
- ),
3401
+ successfulResponseHandler: (0, import_provider_utils15.createJsonResponseHandler)(anthropicMessagesResponseSchema),
3427
3402
  abortSignal: options.abortSignal,
3428
3403
  fetch: this.config.fetch
3429
3404
  });
@@ -3438,11 +3413,7 @@ var AnthropicMessagesLanguageModel = class {
3438
3413
  content.push({ type: "text", text: part.text });
3439
3414
  if (part.citations) {
3440
3415
  for (const citation of part.citations) {
3441
- const source = createCitationSource(
3442
- citation,
3443
- citationDocuments,
3444
- this.generateId
3445
- );
3416
+ const source = createCitationSource(citation, citationDocuments, this.generateId);
3446
3417
  if (source) {
3447
3418
  content.push(source);
3448
3419
  }
@@ -3667,6 +3638,20 @@ var AnthropicMessagesLanguageModel = class {
3667
3638
  }
3668
3639
  // code execution 20250522:
3669
3640
  case "code_execution_tool_result": {
3641
+ if (markCodeExecutionDynamic) {
3642
+ content.push({
3643
+ type: "tool-result",
3644
+ toolCallId: part.tool_use_id,
3645
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3646
+ isError: true,
3647
+ result: {
3648
+ type: "code_execution_tool_result_error",
3649
+ errorCode: "disabled",
3650
+ message: "code_execution is not available. Use web_search and web_fetch as direct tool calls \u2014 they are NOT Python functions."
3651
+ }
3652
+ });
3653
+ break;
3654
+ }
3670
3655
  if (part.content.type === "code_execution_result") {
3671
3656
  content.push({
3672
3657
  type: "tool-result",
@@ -3710,6 +3695,20 @@ var AnthropicMessagesLanguageModel = class {
3710
3695
  // code execution 20250825:
3711
3696
  case "bash_code_execution_tool_result":
3712
3697
  case "text_editor_code_execution_tool_result": {
3698
+ if (markCodeExecutionDynamic) {
3699
+ content.push({
3700
+ type: "tool-result",
3701
+ toolCallId: part.tool_use_id,
3702
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
3703
+ isError: true,
3704
+ result: {
3705
+ type: "code_execution_tool_result_error",
3706
+ errorCode: "disabled",
3707
+ message: "code_execution is not available. Use web_search and web_fetch as direct tool calls \u2014 they are NOT Python functions."
3708
+ }
3709
+ });
3710
+ break;
3711
+ }
3713
3712
  content.push({
3714
3713
  type: "tool-result",
3715
3714
  toolCallId: part.tool_use_id,
@@ -3722,12 +3721,8 @@ var AnthropicMessagesLanguageModel = class {
3722
3721
  case "tool_search_tool_result": {
3723
3722
  let providerToolName = serverToolCalls[part.tool_use_id];
3724
3723
  if (providerToolName == null) {
3725
- const bm25CustomName = toolNameMapping.toCustomToolName(
3726
- "tool_search_tool_bm25"
3727
- );
3728
- const regexCustomName = toolNameMapping.toCustomToolName(
3729
- "tool_search_tool_regex"
3730
- );
3724
+ const bm25CustomName = toolNameMapping.toCustomToolName("tool_search_tool_bm25");
3725
+ const regexCustomName = toolNameMapping.toCustomToolName("tool_search_tool_regex");
3731
3726
  if (bm25CustomName !== "tool_search_tool_bm25") {
3732
3727
  providerToolName = "tool_search_tool_bm25";
3733
3728
  } else if (regexCustomName !== "tool_search_tool_regex") {
@@ -3800,9 +3795,7 @@ var AnthropicMessagesLanguageModel = class {
3800
3795
  version: skill.version
3801
3796
  }))) != null ? _d2 : null
3802
3797
  } : null,
3803
- contextManagement: (_e2 = mapAnthropicResponseContextManagement(
3804
- response.context_management
3805
- )) != null ? _e2 : null
3798
+ contextManagement: (_e2 = mapAnthropicResponseContextManagement(response.context_management)) != null ? _e2 : null
3806
3799
  };
3807
3800
  const providerMetadata = {
3808
3801
  anthropic: anthropicMetadata
@@ -3829,21 +3822,15 @@ var AnthropicMessagesLanguageModel = class {
3829
3822
  stream: true,
3830
3823
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
3831
3824
  });
3832
- const citationDocuments = [
3833
- ...this.extractCitationDocuments(options.prompt)
3834
- ];
3835
- const markCodeExecutionDynamic = hasWebTool20260209WithoutCodeExecution(
3836
- body.tools
3837
- );
3825
+ const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
3826
+ const markCodeExecutionDynamic = hasWebTool20260209WithoutCodeExecution(body.tools);
3838
3827
  const url = this.buildRequestUrl(true);
3839
3828
  const { responseHeaders, value: response } = await (0, import_provider_utils15.postJsonToApi)({
3840
3829
  url,
3841
3830
  headers: await this.getHeaders({ betas, headers: options.headers }),
3842
3831
  body: this.transformRequestBody(body, betas),
3843
3832
  failedResponseHandler: anthropicFailedResponseHandler,
3844
- successfulResponseHandler: (0, import_provider_utils15.createEventSourceResponseHandler)(
3845
- anthropicMessagesChunkSchema
3846
- ),
3833
+ successfulResponseHandler: (0, import_provider_utils15.createEventSourceResponseHandler)(anthropicMessagesChunkSchema),
3847
3834
  abortSignal: options.abortSignal,
3848
3835
  fetch: this.config.fetch
3849
3836
  });
@@ -4004,9 +3991,7 @@ var AnthropicMessagesLanguageModel = class {
4004
3991
  });
4005
3992
  } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
4006
3993
  serverToolCalls[part.id] = part.name;
4007
- const customToolName = toolNameMapping.toCustomToolName(
4008
- part.name
4009
- );
3994
+ const customToolName = toolNameMapping.toCustomToolName(part.name);
4010
3995
  contentBlocks[value.index] = {
4011
3996
  type: "tool-call",
4012
3997
  toolCallId: part.id,
@@ -4112,6 +4097,20 @@ var AnthropicMessagesLanguageModel = class {
4112
4097
  }
4113
4098
  // code execution 20250522:
4114
4099
  case "code_execution_tool_result": {
4100
+ if (markCodeExecutionDynamic) {
4101
+ controller.enqueue({
4102
+ type: "tool-result",
4103
+ toolCallId: part.tool_use_id,
4104
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
4105
+ isError: true,
4106
+ result: {
4107
+ type: "code_execution_tool_result_error",
4108
+ errorCode: "disabled",
4109
+ message: "code_execution is not available. Use web_search and web_fetch as direct tool calls \u2014 they are NOT Python functions."
4110
+ }
4111
+ });
4112
+ return;
4113
+ }
4115
4114
  if (part.content.type === "code_execution_result") {
4116
4115
  controller.enqueue({
4117
4116
  type: "tool-result",
@@ -4155,6 +4154,20 @@ var AnthropicMessagesLanguageModel = class {
4155
4154
  // code execution 20250825:
4156
4155
  case "bash_code_execution_tool_result":
4157
4156
  case "text_editor_code_execution_tool_result": {
4157
+ if (markCodeExecutionDynamic) {
4158
+ controller.enqueue({
4159
+ type: "tool-result",
4160
+ toolCallId: part.tool_use_id,
4161
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
4162
+ isError: true,
4163
+ result: {
4164
+ type: "code_execution_tool_result_error",
4165
+ errorCode: "disabled",
4166
+ message: "code_execution is not available. Use web_search and web_fetch as direct tool calls \u2014 they are NOT Python functions."
4167
+ }
4168
+ });
4169
+ return;
4170
+ }
4158
4171
  controller.enqueue({
4159
4172
  type: "tool-result",
4160
4173
  toolCallId: part.tool_use_id,
@@ -4167,12 +4180,8 @@ var AnthropicMessagesLanguageModel = class {
4167
4180
  case "tool_search_tool_result": {
4168
4181
  let providerToolName = serverToolCalls[part.tool_use_id];
4169
4182
  if (providerToolName == null) {
4170
- const bm25CustomName = toolNameMapping.toCustomToolName(
4171
- "tool_search_tool_bm25"
4172
- );
4173
- const regexCustomName = toolNameMapping.toCustomToolName(
4174
- "tool_search_tool_regex"
4175
- );
4183
+ const bm25CustomName = toolNameMapping.toCustomToolName("tool_search_tool_bm25");
4184
+ const regexCustomName = toolNameMapping.toCustomToolName("tool_search_tool_regex");
4176
4185
  if (bm25CustomName !== "tool_search_tool_bm25") {
4177
4186
  providerToolName = "tool_search_tool_bm25";
4178
4187
  } else if (regexCustomName !== "tool_search_tool_regex") {
@@ -4237,9 +4246,7 @@ var AnthropicMessagesLanguageModel = class {
4237
4246
  }
4238
4247
  default: {
4239
4248
  const _exhaustiveCheck = contentBlockType;
4240
- throw new Error(
4241
- `Unsupported content block type: ${_exhaustiveCheck}`
4242
- );
4249
+ throw new Error(`Unsupported content block type: ${_exhaustiveCheck}`);
4243
4250
  }
4244
4251
  }
4245
4252
  }
@@ -4385,11 +4392,7 @@ var AnthropicMessagesLanguageModel = class {
4385
4392
  }
4386
4393
  case "citations_delta": {
4387
4394
  const citation = value.delta.citation;
4388
- const source = createCitationSource(
4389
- citation,
4390
- citationDocuments,
4391
- generateId3
4392
- );
4395
+ const source = createCitationSource(citation, citationDocuments, generateId3);
4393
4396
  if (source) {
4394
4397
  controller.enqueue(source);
4395
4398
  }
@@ -4397,9 +4400,7 @@ var AnthropicMessagesLanguageModel = class {
4397
4400
  }
4398
4401
  default: {
4399
4402
  const _exhaustiveCheck = deltaType;
4400
- throw new Error(
4401
- `Unsupported delta type: ${_exhaustiveCheck}`
4402
- );
4403
+ throw new Error(`Unsupported delta type: ${_exhaustiveCheck}`);
4403
4404
  }
4404
4405
  }
4405
4406
  }
@@ -4507,9 +4508,7 @@ var AnthropicMessagesLanguageModel = class {
4507
4508
  }))) != null ? _n : null
4508
4509
  } : null;
4509
4510
  if (value.context_management) {
4510
- contextManagement = mapAnthropicResponseContextManagement(
4511
- value.context_management
4512
- );
4511
+ contextManagement = mapAnthropicResponseContextManagement(value.context_management);
4513
4512
  }
4514
4513
  rawUsage = {
4515
4514
  ...rawUsage,