@ai-sdk/anthropic 3.0.26 → 3.0.27

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.
@@ -26,6 +26,11 @@ declare class AnthropicMessagesLanguageModel implements LanguageModelV3 {
26
26
  constructor(modelId: AnthropicMessagesModelId, config: AnthropicMessagesConfig);
27
27
  supportsUrl(url: URL): boolean;
28
28
  get provider(): string;
29
+ /**
30
+ * Extracts the dynamic provider name from the config.provider string.
31
+ * e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
32
+ */
33
+ private get providerOptionsName();
29
34
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
30
35
  private getArgs;
31
36
  private getHeaders;
@@ -26,6 +26,11 @@ declare class AnthropicMessagesLanguageModel implements LanguageModelV3 {
26
26
  constructor(modelId: AnthropicMessagesModelId, config: AnthropicMessagesConfig);
27
27
  supportsUrl(url: URL): boolean;
28
28
  get provider(): string;
29
+ /**
30
+ * Extracts the dynamic provider name from the config.provider string.
31
+ * e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
32
+ */
33
+ private get providerOptionsName();
29
34
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
30
35
  private getArgs;
31
36
  private getHeaders;
@@ -2388,6 +2388,15 @@ var AnthropicMessagesLanguageModel = class {
2388
2388
  get provider() {
2389
2389
  return this.config.provider;
2390
2390
  }
2391
+ /**
2392
+ * Extracts the dynamic provider name from the config.provider string.
2393
+ * e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
2394
+ */
2395
+ get providerOptionsName() {
2396
+ const provider = this.config.provider;
2397
+ const dotIndex = provider.indexOf(".");
2398
+ return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
2399
+ }
2391
2400
  get supportedUrls() {
2392
2401
  var _a, _b, _c;
2393
2402
  return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
@@ -2444,11 +2453,23 @@ var AnthropicMessagesLanguageModel = class {
2444
2453
  });
2445
2454
  }
2446
2455
  }
2447
- const anthropicOptions = await (0, import_provider_utils12.parseProviderOptions)({
2456
+ const providerOptionsName = this.providerOptionsName;
2457
+ const canonicalOptions = await (0, import_provider_utils12.parseProviderOptions)({
2448
2458
  provider: "anthropic",
2449
2459
  providerOptions,
2450
2460
  schema: anthropicProviderOptions
2451
2461
  });
2462
+ const customProviderOptions = providerOptionsName !== "anthropic" ? await (0, import_provider_utils12.parseProviderOptions)({
2463
+ provider: providerOptionsName,
2464
+ providerOptions,
2465
+ schema: anthropicProviderOptions
2466
+ }) : null;
2467
+ const usedCustomProviderKey = customProviderOptions != null;
2468
+ const anthropicOptions = Object.assign(
2469
+ {},
2470
+ canonicalOptions != null ? canonicalOptions : {},
2471
+ customProviderOptions != null ? customProviderOptions : {}
2472
+ );
2452
2473
  const {
2453
2474
  maxOutputTokens: maxOutputTokensForModel,
2454
2475
  supportsStructuredOutput: modelSupportsStructuredOutput,
@@ -2708,7 +2729,9 @@ var AnthropicMessagesLanguageModel = class {
2708
2729
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2709
2730
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2710
2731
  usesJsonResponseTool: jsonResponseTool != null,
2711
- toolNameMapping
2732
+ toolNameMapping,
2733
+ providerOptionsName,
2734
+ usedCustomProviderKey
2712
2735
  };
2713
2736
  }
2714
2737
  async getHeaders({
@@ -2765,8 +2788,16 @@ var AnthropicMessagesLanguageModel = class {
2765
2788
  });
2766
2789
  }
2767
2790
  async doGenerate(options) {
2768
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2769
- const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2791
+ var _a, _b, _c, _d, _e, _f;
2792
+ const {
2793
+ args,
2794
+ warnings,
2795
+ betas,
2796
+ usesJsonResponseTool,
2797
+ toolNameMapping,
2798
+ providerOptionsName,
2799
+ usedCustomProviderKey
2800
+ } = await this.getArgs({
2770
2801
  ...options,
2771
2802
  stream: false,
2772
2803
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -3114,25 +3145,33 @@ var AnthropicMessagesLanguageModel = class {
3114
3145
  body: rawResponse
3115
3146
  },
3116
3147
  warnings,
3117
- providerMetadata: {
3118
- anthropic: {
3148
+ providerMetadata: (() => {
3149
+ var _a2, _b2, _c2, _d2, _e2;
3150
+ const anthropicMetadata = {
3119
3151
  usage: response.usage,
3120
- cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
3121
- stopSequence: (_h = response.stop_sequence) != null ? _h : null,
3152
+ cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
3153
+ stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
3122
3154
  container: response.container ? {
3123
3155
  expiresAt: response.container.expires_at,
3124
3156
  id: response.container.id,
3125
- skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
3157
+ skills: (_d2 = (_c2 = response.container.skills) == null ? void 0 : _c2.map((skill) => ({
3126
3158
  type: skill.type,
3127
3159
  skillId: skill.skill_id,
3128
3160
  version: skill.version
3129
- }))) != null ? _j : null
3161
+ }))) != null ? _d2 : null
3130
3162
  } : null,
3131
- contextManagement: (_k = mapAnthropicResponseContextManagement(
3163
+ contextManagement: (_e2 = mapAnthropicResponseContextManagement(
3132
3164
  response.context_management
3133
- )) != null ? _k : null
3165
+ )) != null ? _e2 : null
3166
+ };
3167
+ const providerMetadata = {
3168
+ anthropic: anthropicMetadata
3169
+ };
3170
+ if (usedCustomProviderKey && providerOptionsName !== "anthropic") {
3171
+ providerMetadata[providerOptionsName] = anthropicMetadata;
3134
3172
  }
3135
- }
3173
+ return providerMetadata;
3174
+ })()
3136
3175
  };
3137
3176
  }
3138
3177
  async doStream(options) {
@@ -3142,7 +3181,9 @@ var AnthropicMessagesLanguageModel = class {
3142
3181
  warnings,
3143
3182
  betas,
3144
3183
  usesJsonResponseTool,
3145
- toolNameMapping
3184
+ toolNameMapping,
3185
+ providerOptionsName,
3186
+ usedCustomProviderKey
3146
3187
  } = await this.getArgs({
3147
3188
  ...options,
3148
3189
  stream: true,
@@ -3783,19 +3824,24 @@ var AnthropicMessagesLanguageModel = class {
3783
3824
  return;
3784
3825
  }
3785
3826
  case "message_stop": {
3827
+ const anthropicMetadata = {
3828
+ usage: rawUsage != null ? rawUsage : null,
3829
+ cacheCreationInputTokens,
3830
+ stopSequence,
3831
+ container,
3832
+ contextManagement
3833
+ };
3834
+ const providerMetadata = {
3835
+ anthropic: anthropicMetadata
3836
+ };
3837
+ if (usedCustomProviderKey && providerOptionsName !== "anthropic") {
3838
+ providerMetadata[providerOptionsName] = anthropicMetadata;
3839
+ }
3786
3840
  controller.enqueue({
3787
3841
  type: "finish",
3788
3842
  finishReason,
3789
3843
  usage: convertAnthropicMessagesUsage(usage),
3790
- providerMetadata: {
3791
- anthropic: {
3792
- usage: rawUsage != null ? rawUsage : null,
3793
- cacheCreationInputTokens,
3794
- stopSequence,
3795
- container,
3796
- contextManagement
3797
- }
3798
- }
3844
+ providerMetadata
3799
3845
  });
3800
3846
  return;
3801
3847
  }