@ai-sdk/anthropic 4.0.0-beta.5 → 4.0.0-beta.67

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +500 -4
  2. package/README.md +2 -0
  3. package/dist/index.d.ts +265 -68
  4. package/dist/index.js +2636 -1427
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +234 -62
  7. package/dist/internal/index.js +2605 -1413
  8. package/dist/internal/index.js.map +1 -1
  9. package/docs/05-anthropic.mdx +303 -20
  10. package/package.json +16 -17
  11. package/src/{anthropic-messages-api.ts → anthropic-api.ts} +158 -17
  12. package/src/anthropic-error.ts +1 -1
  13. package/src/anthropic-files.ts +95 -0
  14. package/src/{anthropic-messages-options.ts → anthropic-language-model-options.ts} +104 -11
  15. package/src/{anthropic-messages-language-model.ts → anthropic-language-model.ts} +494 -96
  16. package/src/anthropic-message-metadata.ts +69 -9
  17. package/src/anthropic-prepare-tools.ts +31 -7
  18. package/src/anthropic-provider.ts +42 -13
  19. package/src/anthropic-tools.ts +31 -0
  20. package/src/convert-anthropic-usage.ts +109 -0
  21. package/src/{convert-to-anthropic-messages-prompt.ts → convert-to-anthropic-prompt.ts} +376 -198
  22. package/src/forward-anthropic-container-id-from-last-step.ts +2 -2
  23. package/src/get-cache-control.ts +5 -2
  24. package/src/index.ts +1 -1
  25. package/src/internal/index.ts +13 -2
  26. package/src/map-anthropic-stop-reason.ts +1 -1
  27. package/src/sanitize-json-schema.ts +203 -0
  28. package/src/skills/anthropic-skills-api.ts +44 -0
  29. package/src/skills/anthropic-skills.ts +132 -0
  30. package/src/tool/advisor_20260301.ts +128 -0
  31. package/src/tool/bash_20241022.ts +84 -13
  32. package/src/tool/bash_20250124.ts +84 -13
  33. package/src/tool/code-execution_20250522.ts +2 -2
  34. package/src/tool/code-execution_20250825.ts +2 -2
  35. package/src/tool/code-execution_20260120.ts +2 -2
  36. package/src/tool/computer_20241022.ts +2 -2
  37. package/src/tool/computer_20250124.ts +2 -2
  38. package/src/tool/computer_20251124.ts +2 -2
  39. package/src/tool/memory_20250818.ts +2 -2
  40. package/src/tool/text-editor_20241022.ts +2 -2
  41. package/src/tool/text-editor_20250124.ts +2 -2
  42. package/src/tool/text-editor_20250429.ts +2 -2
  43. package/src/tool/text-editor_20250728.ts +6 -3
  44. package/src/tool/tool-search-bm25_20251119.ts +2 -2
  45. package/src/tool/tool-search-regex_20251119.ts +2 -2
  46. package/src/tool/web-fetch-20250910.ts +2 -2
  47. package/src/tool/web-fetch-20260209.ts +2 -2
  48. package/src/tool/web-search_20250305.ts +2 -2
  49. package/src/tool/web-search_20260209.ts +2 -2
  50. package/dist/index.d.mts +0 -1090
  51. package/dist/index.mjs +0 -5244
  52. package/dist/index.mjs.map +0 -1
  53. package/dist/internal/index.d.mts +0 -969
  54. package/dist/internal/index.mjs +0 -5136
  55. package/dist/internal/index.mjs.map +0 -1
  56. package/src/convert-anthropic-messages-usage.ts +0 -73
@@ -1,73 +0,0 @@
1
- import { JSONObject, LanguageModelV4Usage } from '@ai-sdk/provider';
2
-
3
- /**
4
- * Represents a single iteration in the usage breakdown.
5
- * When compaction occurs, the API returns an iterations array showing
6
- * usage for each sampling iteration (compaction + message).
7
- */
8
- export type AnthropicUsageIteration = {
9
- type: 'compaction' | 'message';
10
- input_tokens: number;
11
- output_tokens: number;
12
- };
13
-
14
- export type AnthropicMessagesUsage = {
15
- input_tokens: number;
16
- output_tokens: number;
17
- cache_creation_input_tokens?: number | null;
18
- cache_read_input_tokens?: number | null;
19
- /**
20
- * When compaction is triggered, this array contains usage for each
21
- * sampling iteration. The top-level input_tokens and output_tokens
22
- * do NOT include compaction iteration usage - to get total tokens
23
- * consumed and billed, sum across all entries in this array.
24
- */
25
- iterations?: AnthropicUsageIteration[] | null;
26
- };
27
-
28
- export function convertAnthropicMessagesUsage({
29
- usage,
30
- rawUsage,
31
- }: {
32
- usage: AnthropicMessagesUsage;
33
- rawUsage?: JSONObject;
34
- }): LanguageModelV4Usage {
35
- const cacheCreationTokens = usage.cache_creation_input_tokens ?? 0;
36
- const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
37
-
38
- // When iterations is present (compaction occurred), sum across all iterations
39
- // to get the true total tokens consumed/billed. The top-level input_tokens
40
- // and output_tokens exclude compaction iteration usage.
41
- let inputTokens: number;
42
- let outputTokens: number;
43
-
44
- if (usage.iterations && usage.iterations.length > 0) {
45
- const totals = usage.iterations.reduce(
46
- (acc, iter) => ({
47
- input: acc.input + iter.input_tokens,
48
- output: acc.output + iter.output_tokens,
49
- }),
50
- { input: 0, output: 0 },
51
- );
52
- inputTokens = totals.input;
53
- outputTokens = totals.output;
54
- } else {
55
- inputTokens = usage.input_tokens;
56
- outputTokens = usage.output_tokens;
57
- }
58
-
59
- return {
60
- inputTokens: {
61
- total: inputTokens + cacheCreationTokens + cacheReadTokens,
62
- noCache: inputTokens,
63
- cacheRead: cacheReadTokens,
64
- cacheWrite: cacheCreationTokens,
65
- },
66
- outputTokens: {
67
- total: outputTokens,
68
- text: undefined,
69
- reasoning: undefined,
70
- },
71
- raw: rawUsage ?? usage,
72
- };
73
- }