@ai-sdk/anthropic 3.0.0-beta.93 → 3.0.0-beta.95

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.
@@ -36,29 +36,6 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
36
36
  errorToMessage: (data) => data.error.message
37
37
  });
38
38
 
39
- // src/convert-anthropic-messages-usage.ts
40
- function convertAnthropicMessagesUsage(usage) {
41
- var _a, _b;
42
- const inputTokens = usage.input_tokens;
43
- const outputTokens = usage.output_tokens;
44
- const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
45
- const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
46
- return {
47
- inputTokens: {
48
- total: inputTokens + cacheCreationTokens + cacheReadTokens,
49
- noCache: inputTokens,
50
- cacheRead: cacheReadTokens,
51
- cacheWrite: cacheCreationTokens
52
- },
53
- outputTokens: {
54
- total: outputTokens,
55
- text: void 0,
56
- reasoning: void 0
57
- },
58
- raw: usage
59
- };
60
- }
61
-
62
39
  // src/anthropic-messages-api.ts
63
40
  import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
64
41
  import { z as z2 } from "zod/v4";
@@ -1328,6 +1305,29 @@ async function prepareTools({
1328
1305
  }
1329
1306
  }
1330
1307
 
1308
+ // src/convert-anthropic-messages-usage.ts
1309
+ function convertAnthropicMessagesUsage(usage) {
1310
+ var _a, _b;
1311
+ const inputTokens = usage.input_tokens;
1312
+ const outputTokens = usage.output_tokens;
1313
+ const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
1314
+ const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
1315
+ return {
1316
+ inputTokens: {
1317
+ total: inputTokens + cacheCreationTokens + cacheReadTokens,
1318
+ noCache: inputTokens,
1319
+ cacheRead: cacheReadTokens,
1320
+ cacheWrite: cacheCreationTokens
1321
+ },
1322
+ outputTokens: {
1323
+ total: outputTokens,
1324
+ text: void 0,
1325
+ reasoning: void 0
1326
+ },
1327
+ raw: usage
1328
+ };
1329
+ }
1330
+
1331
1331
  // src/convert-to-anthropic-messages-prompt.ts
1332
1332
  import {
1333
1333
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
@@ -2284,11 +2284,10 @@ function mapAnthropicStopReason({
2284
2284
  case "tool_use":
2285
2285
  return isJsonResponseFromTool ? "stop" : "tool-calls";
2286
2286
  case "max_tokens":
2287
- return "length";
2288
2287
  case "model_context_window_exceeded":
2289
2288
  return "length";
2290
2289
  default:
2291
- return "unknown";
2290
+ return "other";
2292
2291
  }
2293
2292
  }
2294
2293
 
@@ -2704,7 +2703,7 @@ var AnthropicMessagesLanguageModel = class {
2704
2703
  });
2705
2704
  }
2706
2705
  async doGenerate(options) {
2707
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2706
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2708
2707
  const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2709
2708
  ...options,
2710
2709
  stream: false,
@@ -3013,15 +3012,18 @@ var AnthropicMessagesLanguageModel = class {
3013
3012
  }
3014
3013
  return {
3015
3014
  content,
3016
- finishReason: mapAnthropicStopReason({
3017
- finishReason: response.stop_reason,
3018
- isJsonResponseFromTool
3019
- }),
3015
+ finishReason: {
3016
+ unified: mapAnthropicStopReason({
3017
+ finishReason: response.stop_reason,
3018
+ isJsonResponseFromTool
3019
+ }),
3020
+ raw: (_c = response.stop_reason) != null ? _c : void 0
3021
+ },
3020
3022
  usage: convertAnthropicMessagesUsage(response.usage),
3021
3023
  request: { body: args },
3022
3024
  response: {
3023
- id: (_c = response.id) != null ? _c : void 0,
3024
- modelId: (_d = response.model) != null ? _d : void 0,
3025
+ id: (_d = response.id) != null ? _d : void 0,
3026
+ modelId: (_e = response.model) != null ? _e : void 0,
3025
3027
  headers: responseHeaders,
3026
3028
  body: rawResponse
3027
3029
  },
@@ -3029,20 +3031,20 @@ var AnthropicMessagesLanguageModel = class {
3029
3031
  providerMetadata: {
3030
3032
  anthropic: {
3031
3033
  usage: response.usage,
3032
- cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
3033
- stopSequence: (_f = response.stop_sequence) != null ? _f : null,
3034
+ cacheCreationInputTokens: (_f = response.usage.cache_creation_input_tokens) != null ? _f : null,
3035
+ stopSequence: (_g = response.stop_sequence) != null ? _g : null,
3034
3036
  container: response.container ? {
3035
3037
  expiresAt: response.container.expires_at,
3036
3038
  id: response.container.id,
3037
- skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
3039
+ skills: (_i = (_h = response.container.skills) == null ? void 0 : _h.map((skill) => ({
3038
3040
  type: skill.type,
3039
3041
  skillId: skill.skill_id,
3040
3042
  version: skill.version
3041
- }))) != null ? _h : null
3043
+ }))) != null ? _i : null
3042
3044
  } : null,
3043
- contextManagement: (_i = mapAnthropicResponseContextManagement(
3045
+ contextManagement: (_j = mapAnthropicResponseContextManagement(
3044
3046
  response.context_management
3045
- )) != null ? _i : null
3047
+ )) != null ? _j : null
3046
3048
  }
3047
3049
  }
3048
3050
  };
@@ -3073,7 +3075,10 @@ var AnthropicMessagesLanguageModel = class {
3073
3075
  abortSignal: options.abortSignal,
3074
3076
  fetch: this.config.fetch
3075
3077
  });
3076
- let finishReason = "unknown";
3078
+ let finishReason = {
3079
+ unified: "other",
3080
+ raw: void 0
3081
+ };
3077
3082
  const usage = {
3078
3083
  input_tokens: 0,
3079
3084
  output_tokens: 0,
@@ -3096,7 +3101,7 @@ var AnthropicMessagesLanguageModel = class {
3096
3101
  controller.enqueue({ type: "stream-start", warnings });
3097
3102
  },
3098
3103
  transform(chunk, controller) {
3099
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3104
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
3100
3105
  if (options.includeRawChunks) {
3101
3106
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
3102
3107
  }
@@ -3579,10 +3584,13 @@ var AnthropicMessagesLanguageModel = class {
3579
3584
  };
3580
3585
  }
3581
3586
  if (value.message.stop_reason != null) {
3582
- finishReason = mapAnthropicStopReason({
3583
- finishReason: value.message.stop_reason,
3584
- isJsonResponseFromTool
3585
- });
3587
+ finishReason = {
3588
+ unified: mapAnthropicStopReason({
3589
+ finishReason: value.message.stop_reason,
3590
+ isJsonResponseFromTool
3591
+ }),
3592
+ raw: value.message.stop_reason
3593
+ };
3586
3594
  }
3587
3595
  controller.enqueue({
3588
3596
  type: "response-metadata",
@@ -3633,19 +3641,22 @@ var AnthropicMessagesLanguageModel = class {
3633
3641
  }
3634
3642
  case "message_delta": {
3635
3643
  usage.output_tokens = value.usage.output_tokens;
3636
- finishReason = mapAnthropicStopReason({
3637
- finishReason: value.delta.stop_reason,
3638
- isJsonResponseFromTool
3639
- });
3640
- stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
3644
+ finishReason = {
3645
+ unified: mapAnthropicStopReason({
3646
+ finishReason: value.delta.stop_reason,
3647
+ isJsonResponseFromTool
3648
+ }),
3649
+ raw: (_i = value.delta.stop_reason) != null ? _i : void 0
3650
+ };
3651
+ stopSequence = (_j = value.delta.stop_sequence) != null ? _j : null;
3641
3652
  container = value.delta.container != null ? {
3642
3653
  expiresAt: value.delta.container.expires_at,
3643
3654
  id: value.delta.container.id,
3644
- skills: (_k = (_j = value.delta.container.skills) == null ? void 0 : _j.map((skill) => ({
3655
+ skills: (_l = (_k = value.delta.container.skills) == null ? void 0 : _k.map((skill) => ({
3645
3656
  type: skill.type,
3646
3657
  skillId: skill.skill_id,
3647
3658
  version: skill.version
3648
- }))) != null ? _k : null
3659
+ }))) != null ? _l : null
3649
3660
  } : null;
3650
3661
  if (value.delta.context_management) {
3651
3662
  contextManagement = mapAnthropicResponseContextManagement(