@ai-sdk/anthropic 3.0.25 → 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.
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.25" : "0.0.0-test";
15
+ var VERSION = true ? "3.0.27" : "0.0.0-test";
16
16
 
17
17
  // src/anthropic-messages-language-model.ts
18
18
  import {
@@ -2420,6 +2420,15 @@ var AnthropicMessagesLanguageModel = class {
2420
2420
  get provider() {
2421
2421
  return this.config.provider;
2422
2422
  }
2423
+ /**
2424
+ * Extracts the dynamic provider name from the config.provider string.
2425
+ * e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
2426
+ */
2427
+ get providerOptionsName() {
2428
+ const provider = this.config.provider;
2429
+ const dotIndex = provider.indexOf(".");
2430
+ return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
2431
+ }
2423
2432
  get supportedUrls() {
2424
2433
  var _a, _b, _c;
2425
2434
  return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
@@ -2476,11 +2485,23 @@ var AnthropicMessagesLanguageModel = class {
2476
2485
  });
2477
2486
  }
2478
2487
  }
2479
- const anthropicOptions = await parseProviderOptions2({
2488
+ const providerOptionsName = this.providerOptionsName;
2489
+ const canonicalOptions = await parseProviderOptions2({
2480
2490
  provider: "anthropic",
2481
2491
  providerOptions,
2482
2492
  schema: anthropicProviderOptions
2483
2493
  });
2494
+ const customProviderOptions = providerOptionsName !== "anthropic" ? await parseProviderOptions2({
2495
+ provider: providerOptionsName,
2496
+ providerOptions,
2497
+ schema: anthropicProviderOptions
2498
+ }) : null;
2499
+ const usedCustomProviderKey = customProviderOptions != null;
2500
+ const anthropicOptions = Object.assign(
2501
+ {},
2502
+ canonicalOptions != null ? canonicalOptions : {},
2503
+ customProviderOptions != null ? customProviderOptions : {}
2504
+ );
2484
2505
  const {
2485
2506
  maxOutputTokens: maxOutputTokensForModel,
2486
2507
  supportsStructuredOutput: modelSupportsStructuredOutput,
@@ -2740,7 +2761,9 @@ var AnthropicMessagesLanguageModel = class {
2740
2761
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2741
2762
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2742
2763
  usesJsonResponseTool: jsonResponseTool != null,
2743
- toolNameMapping
2764
+ toolNameMapping,
2765
+ providerOptionsName,
2766
+ usedCustomProviderKey
2744
2767
  };
2745
2768
  }
2746
2769
  async getHeaders({
@@ -2797,8 +2820,16 @@ var AnthropicMessagesLanguageModel = class {
2797
2820
  });
2798
2821
  }
2799
2822
  async doGenerate(options) {
2800
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2801
- const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2823
+ var _a, _b, _c, _d, _e, _f;
2824
+ const {
2825
+ args,
2826
+ warnings,
2827
+ betas,
2828
+ usesJsonResponseTool,
2829
+ toolNameMapping,
2830
+ providerOptionsName,
2831
+ usedCustomProviderKey
2832
+ } = await this.getArgs({
2802
2833
  ...options,
2803
2834
  stream: false,
2804
2835
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -3146,25 +3177,33 @@ var AnthropicMessagesLanguageModel = class {
3146
3177
  body: rawResponse
3147
3178
  },
3148
3179
  warnings,
3149
- providerMetadata: {
3150
- anthropic: {
3180
+ providerMetadata: (() => {
3181
+ var _a2, _b2, _c2, _d2, _e2;
3182
+ const anthropicMetadata = {
3151
3183
  usage: response.usage,
3152
- cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
3153
- stopSequence: (_h = response.stop_sequence) != null ? _h : null,
3184
+ cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
3185
+ stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
3154
3186
  container: response.container ? {
3155
3187
  expiresAt: response.container.expires_at,
3156
3188
  id: response.container.id,
3157
- skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
3189
+ skills: (_d2 = (_c2 = response.container.skills) == null ? void 0 : _c2.map((skill) => ({
3158
3190
  type: skill.type,
3159
3191
  skillId: skill.skill_id,
3160
3192
  version: skill.version
3161
- }))) != null ? _j : null
3193
+ }))) != null ? _d2 : null
3162
3194
  } : null,
3163
- contextManagement: (_k = mapAnthropicResponseContextManagement(
3195
+ contextManagement: (_e2 = mapAnthropicResponseContextManagement(
3164
3196
  response.context_management
3165
- )) != null ? _k : null
3197
+ )) != null ? _e2 : null
3198
+ };
3199
+ const providerMetadata = {
3200
+ anthropic: anthropicMetadata
3201
+ };
3202
+ if (usedCustomProviderKey && providerOptionsName !== "anthropic") {
3203
+ providerMetadata[providerOptionsName] = anthropicMetadata;
3166
3204
  }
3167
- }
3205
+ return providerMetadata;
3206
+ })()
3168
3207
  };
3169
3208
  }
3170
3209
  async doStream(options) {
@@ -3174,7 +3213,9 @@ var AnthropicMessagesLanguageModel = class {
3174
3213
  warnings,
3175
3214
  betas,
3176
3215
  usesJsonResponseTool,
3177
- toolNameMapping
3216
+ toolNameMapping,
3217
+ providerOptionsName,
3218
+ usedCustomProviderKey
3178
3219
  } = await this.getArgs({
3179
3220
  ...options,
3180
3221
  stream: true,
@@ -3815,19 +3856,24 @@ var AnthropicMessagesLanguageModel = class {
3815
3856
  return;
3816
3857
  }
3817
3858
  case "message_stop": {
3859
+ const anthropicMetadata = {
3860
+ usage: rawUsage != null ? rawUsage : null,
3861
+ cacheCreationInputTokens,
3862
+ stopSequence,
3863
+ container,
3864
+ contextManagement
3865
+ };
3866
+ const providerMetadata = {
3867
+ anthropic: anthropicMetadata
3868
+ };
3869
+ if (usedCustomProviderKey && providerOptionsName !== "anthropic") {
3870
+ providerMetadata[providerOptionsName] = anthropicMetadata;
3871
+ }
3818
3872
  controller.enqueue({
3819
3873
  type: "finish",
3820
3874
  finishReason,
3821
3875
  usage: convertAnthropicMessagesUsage(usage),
3822
- providerMetadata: {
3823
- anthropic: {
3824
- usage: rawUsage != null ? rawUsage : null,
3825
- cacheCreationInputTokens,
3826
- stopSequence,
3827
- container,
3828
- contextManagement
3829
- }
3830
- }
3876
+ providerMetadata
3831
3877
  });
3832
3878
  return;
3833
3879
  }