@ai-sdk/anthropic 3.0.26 → 3.0.28

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.
@@ -1337,7 +1337,7 @@ function convertAnthropicMessagesUsage(usage) {
1337
1337
  },
1338
1338
  outputTokens: {
1339
1339
  total: outputTokens,
1340
- text: void 0,
1340
+ text: outputTokens,
1341
1341
  reasoning: void 0
1342
1342
  },
1343
1343
  raw: usage
@@ -2404,6 +2404,15 @@ var AnthropicMessagesLanguageModel = class {
2404
2404
  get provider() {
2405
2405
  return this.config.provider;
2406
2406
  }
2407
+ /**
2408
+ * Extracts the dynamic provider name from the config.provider string.
2409
+ * e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
2410
+ */
2411
+ get providerOptionsName() {
2412
+ const provider = this.config.provider;
2413
+ const dotIndex = provider.indexOf(".");
2414
+ return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
2415
+ }
2407
2416
  get supportedUrls() {
2408
2417
  var _a, _b, _c;
2409
2418
  return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
@@ -2460,11 +2469,23 @@ var AnthropicMessagesLanguageModel = class {
2460
2469
  });
2461
2470
  }
2462
2471
  }
2463
- const anthropicOptions = await parseProviderOptions2({
2472
+ const providerOptionsName = this.providerOptionsName;
2473
+ const canonicalOptions = await parseProviderOptions2({
2464
2474
  provider: "anthropic",
2465
2475
  providerOptions,
2466
2476
  schema: anthropicProviderOptions
2467
2477
  });
2478
+ const customProviderOptions = providerOptionsName !== "anthropic" ? await parseProviderOptions2({
2479
+ provider: providerOptionsName,
2480
+ providerOptions,
2481
+ schema: anthropicProviderOptions
2482
+ }) : null;
2483
+ const usedCustomProviderKey = customProviderOptions != null;
2484
+ const anthropicOptions = Object.assign(
2485
+ {},
2486
+ canonicalOptions != null ? canonicalOptions : {},
2487
+ customProviderOptions != null ? customProviderOptions : {}
2488
+ );
2468
2489
  const {
2469
2490
  maxOutputTokens: maxOutputTokensForModel,
2470
2491
  supportsStructuredOutput: modelSupportsStructuredOutput,
@@ -2724,7 +2745,9 @@ var AnthropicMessagesLanguageModel = class {
2724
2745
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2725
2746
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2726
2747
  usesJsonResponseTool: jsonResponseTool != null,
2727
- toolNameMapping
2748
+ toolNameMapping,
2749
+ providerOptionsName,
2750
+ usedCustomProviderKey
2728
2751
  };
2729
2752
  }
2730
2753
  async getHeaders({
@@ -2781,8 +2804,16 @@ var AnthropicMessagesLanguageModel = class {
2781
2804
  });
2782
2805
  }
2783
2806
  async doGenerate(options) {
2784
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2785
- const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2807
+ var _a, _b, _c, _d, _e, _f;
2808
+ const {
2809
+ args,
2810
+ warnings,
2811
+ betas,
2812
+ usesJsonResponseTool,
2813
+ toolNameMapping,
2814
+ providerOptionsName,
2815
+ usedCustomProviderKey
2816
+ } = await this.getArgs({
2786
2817
  ...options,
2787
2818
  stream: false,
2788
2819
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -3130,25 +3161,33 @@ var AnthropicMessagesLanguageModel = class {
3130
3161
  body: rawResponse
3131
3162
  },
3132
3163
  warnings,
3133
- providerMetadata: {
3134
- anthropic: {
3164
+ providerMetadata: (() => {
3165
+ var _a2, _b2, _c2, _d2, _e2;
3166
+ const anthropicMetadata = {
3135
3167
  usage: response.usage,
3136
- cacheCreationInputTokens: (_g = response.usage.cache_creation_input_tokens) != null ? _g : null,
3137
- stopSequence: (_h = response.stop_sequence) != null ? _h : null,
3168
+ cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
3169
+ stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
3138
3170
  container: response.container ? {
3139
3171
  expiresAt: response.container.expires_at,
3140
3172
  id: response.container.id,
3141
- skills: (_j = (_i = response.container.skills) == null ? void 0 : _i.map((skill) => ({
3173
+ skills: (_d2 = (_c2 = response.container.skills) == null ? void 0 : _c2.map((skill) => ({
3142
3174
  type: skill.type,
3143
3175
  skillId: skill.skill_id,
3144
3176
  version: skill.version
3145
- }))) != null ? _j : null
3177
+ }))) != null ? _d2 : null
3146
3178
  } : null,
3147
- contextManagement: (_k = mapAnthropicResponseContextManagement(
3179
+ contextManagement: (_e2 = mapAnthropicResponseContextManagement(
3148
3180
  response.context_management
3149
- )) != null ? _k : null
3181
+ )) != null ? _e2 : null
3182
+ };
3183
+ const providerMetadata = {
3184
+ anthropic: anthropicMetadata
3185
+ };
3186
+ if (usedCustomProviderKey && providerOptionsName !== "anthropic") {
3187
+ providerMetadata[providerOptionsName] = anthropicMetadata;
3150
3188
  }
3151
- }
3189
+ return providerMetadata;
3190
+ })()
3152
3191
  };
3153
3192
  }
3154
3193
  async doStream(options) {
@@ -3158,7 +3197,9 @@ var AnthropicMessagesLanguageModel = class {
3158
3197
  warnings,
3159
3198
  betas,
3160
3199
  usesJsonResponseTool,
3161
- toolNameMapping
3200
+ toolNameMapping,
3201
+ providerOptionsName,
3202
+ usedCustomProviderKey
3162
3203
  } = await this.getArgs({
3163
3204
  ...options,
3164
3205
  stream: true,
@@ -3799,19 +3840,24 @@ var AnthropicMessagesLanguageModel = class {
3799
3840
  return;
3800
3841
  }
3801
3842
  case "message_stop": {
3843
+ const anthropicMetadata = {
3844
+ usage: rawUsage != null ? rawUsage : null,
3845
+ cacheCreationInputTokens,
3846
+ stopSequence,
3847
+ container,
3848
+ contextManagement
3849
+ };
3850
+ const providerMetadata = {
3851
+ anthropic: anthropicMetadata
3852
+ };
3853
+ if (usedCustomProviderKey && providerOptionsName !== "anthropic") {
3854
+ providerMetadata[providerOptionsName] = anthropicMetadata;
3855
+ }
3802
3856
  controller.enqueue({
3803
3857
  type: "finish",
3804
3858
  finishReason,
3805
3859
  usage: convertAnthropicMessagesUsage(usage),
3806
- providerMetadata: {
3807
- anthropic: {
3808
- usage: rawUsage != null ? rawUsage : null,
3809
- cacheCreationInputTokens,
3810
- stopSequence,
3811
- container,
3812
- contextManagement
3813
- }
3814
- }
3860
+ providerMetadata
3815
3861
  });
3816
3862
  return;
3817
3863
  }