@ai-sdk/anthropic 3.0.17 → 3.0.19

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 (78) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.js +57 -30
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +57 -30
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/internal/index.js +56 -29
  7. package/dist/internal/index.js.map +1 -1
  8. package/dist/internal/index.mjs +56 -29
  9. package/dist/internal/index.mjs.map +1 -1
  10. package/package.json +3 -2
  11. package/src/__fixtures__/anthropic-code-execution-20250825.1.chunks.txt +248 -0
  12. package/src/__fixtures__/anthropic-code-execution-20250825.1.json +70 -0
  13. package/src/__fixtures__/anthropic-code-execution-20250825.2.chunks.txt +984 -0
  14. package/src/__fixtures__/anthropic-code-execution-20250825.2.json +111 -0
  15. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.chunks.txt +691 -0
  16. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.json +1801 -0
  17. package/src/__fixtures__/anthropic-json-other-tool.1.chunks.txt +13 -0
  18. package/src/__fixtures__/anthropic-json-other-tool.1.json +26 -0
  19. package/src/__fixtures__/anthropic-json-output-format.1.chunks.txt +120 -0
  20. package/src/__fixtures__/anthropic-json-output-format.1.json +25 -0
  21. package/src/__fixtures__/anthropic-json-tool.1.chunks.txt +9 -0
  22. package/src/__fixtures__/anthropic-json-tool.1.json +37 -0
  23. package/src/__fixtures__/anthropic-json-tool.2.chunks.txt +14 -0
  24. package/src/__fixtures__/anthropic-mcp.1.chunks.txt +17 -0
  25. package/src/__fixtures__/anthropic-mcp.1.json +39 -0
  26. package/src/__fixtures__/anthropic-memory-20250818.1.json +28 -0
  27. package/src/__fixtures__/anthropic-message-delta-input-tokens.chunks.txt +8 -0
  28. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.chunks.txt +278 -0
  29. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.json +106 -0
  30. package/src/__fixtures__/anthropic-tool-no-args.chunks.txt +13 -0
  31. package/src/__fixtures__/anthropic-tool-no-args.json +31 -0
  32. package/src/__fixtures__/anthropic-tool-search-bm25.1.chunks.txt +47 -0
  33. package/src/__fixtures__/anthropic-tool-search-bm25.1.json +67 -0
  34. package/src/__fixtures__/anthropic-tool-search-regex.1.chunks.txt +51 -0
  35. package/src/__fixtures__/anthropic-tool-search-regex.1.json +65 -0
  36. package/src/__fixtures__/anthropic-web-fetch-tool.1.chunks.txt +64 -0
  37. package/src/__fixtures__/anthropic-web-fetch-tool.1.json +54 -0
  38. package/src/__fixtures__/anthropic-web-fetch-tool.2.json +56 -0
  39. package/src/__fixtures__/anthropic-web-fetch-tool.error.json +46 -0
  40. package/src/__fixtures__/anthropic-web-search-tool.1.chunks.txt +120 -0
  41. package/src/__fixtures__/anthropic-web-search-tool.1.json +181 -0
  42. package/src/__snapshots__/anthropic-messages-language-model.test.ts.snap +16719 -0
  43. package/src/anthropic-error.test.ts +42 -0
  44. package/src/anthropic-error.ts +26 -0
  45. package/src/anthropic-message-metadata.ts +105 -0
  46. package/src/anthropic-messages-api.ts +1188 -0
  47. package/src/anthropic-messages-language-model.test.ts +7170 -0
  48. package/src/anthropic-messages-language-model.ts +2067 -0
  49. package/src/anthropic-messages-options.ts +213 -0
  50. package/src/anthropic-prepare-tools.test.ts +1219 -0
  51. package/src/anthropic-prepare-tools.ts +341 -0
  52. package/src/anthropic-provider.test.ts +162 -0
  53. package/src/anthropic-provider.ts +152 -0
  54. package/src/anthropic-tools.ts +182 -0
  55. package/src/convert-anthropic-messages-usage.ts +32 -0
  56. package/src/convert-to-anthropic-messages-prompt.test.ts +2902 -0
  57. package/src/convert-to-anthropic-messages-prompt.ts +1050 -0
  58. package/src/forward-anthropic-container-id-from-last-step.ts +38 -0
  59. package/src/get-cache-control.ts +63 -0
  60. package/src/index.ts +10 -0
  61. package/src/internal/index.ts +4 -0
  62. package/src/map-anthropic-stop-reason.ts +28 -0
  63. package/src/tool/bash_20241022.ts +33 -0
  64. package/src/tool/bash_20250124.ts +33 -0
  65. package/src/tool/code-execution_20250522.ts +61 -0
  66. package/src/tool/code-execution_20250825.ts +281 -0
  67. package/src/tool/computer_20241022.ts +87 -0
  68. package/src/tool/computer_20250124.ts +130 -0
  69. package/src/tool/memory_20250818.ts +62 -0
  70. package/src/tool/text-editor_20241022.ts +63 -0
  71. package/src/tool/text-editor_20250124.ts +63 -0
  72. package/src/tool/text-editor_20250429.ts +64 -0
  73. package/src/tool/text-editor_20250728.ts +80 -0
  74. package/src/tool/tool-search-bm25_20251119.ts +98 -0
  75. package/src/tool/tool-search-regex_20251119.ts +110 -0
  76. package/src/tool/web-fetch-20250910.ts +145 -0
  77. package/src/tool/web-search_20250305.ts +136 -0
  78. package/src/version.ts +6 -0
@@ -0,0 +1,42 @@
1
+ import { safeValidateTypes } from '@ai-sdk/provider-utils';
2
+ import { anthropicErrorDataSchema } from './anthropic-error';
3
+ import { describe, it, expect } from 'vitest';
4
+
5
+ describe('anthropicError', () => {
6
+ describe('anthropicErrorDataSchema', () => {
7
+ it('should parse overloaded error', async () => {
8
+ const result = await safeValidateTypes({
9
+ value: {
10
+ type: 'error',
11
+ error: {
12
+ details: null,
13
+ type: 'overloaded_error',
14
+ message: 'Overloaded',
15
+ },
16
+ },
17
+ schema: anthropicErrorDataSchema,
18
+ });
19
+
20
+ expect(result).toMatchInlineSnapshot(`
21
+ {
22
+ "rawValue": {
23
+ "error": {
24
+ "details": null,
25
+ "message": "Overloaded",
26
+ "type": "overloaded_error",
27
+ },
28
+ "type": "error",
29
+ },
30
+ "success": true,
31
+ "value": {
32
+ "error": {
33
+ "message": "Overloaded",
34
+ "type": "overloaded_error",
35
+ },
36
+ "type": "error",
37
+ },
38
+ }
39
+ `);
40
+ });
41
+ });
42
+ });
@@ -0,0 +1,26 @@
1
+ import {
2
+ createJsonErrorResponseHandler,
3
+ InferSchema,
4
+ lazySchema,
5
+ zodSchema,
6
+ } from '@ai-sdk/provider-utils';
7
+ import { z } from 'zod/v4';
8
+
9
+ export const anthropicErrorDataSchema = lazySchema(() =>
10
+ zodSchema(
11
+ z.object({
12
+ type: z.literal('error'),
13
+ error: z.object({
14
+ type: z.string(),
15
+ message: z.string(),
16
+ }),
17
+ }),
18
+ ),
19
+ );
20
+
21
+ export type AnthropicErrorData = InferSchema<typeof anthropicErrorDataSchema>;
22
+
23
+ export const anthropicFailedResponseHandler = createJsonErrorResponseHandler({
24
+ errorSchema: anthropicErrorDataSchema,
25
+ errorToMessage: data => data.error.message,
26
+ });
@@ -0,0 +1,105 @@
1
+ import { JSONObject } from '@ai-sdk/provider';
2
+
3
+ export interface AnthropicMessageMetadata {
4
+ usage: JSONObject;
5
+ // TODO remove cacheCreationInputTokens in AI SDK 6
6
+ // (use value in usage object instead)
7
+ cacheCreationInputTokens: number | null;
8
+ stopSequence: string | null;
9
+
10
+ /**
11
+ * Information about the container used in this request.
12
+ *
13
+ * This will be non-null if a container tool (e.g., code execution) was used.
14
+ * Information about the container used in the request (for the code execution tool).
15
+ */
16
+ container: {
17
+ /**
18
+ * The time at which the container will expire (RFC3339 timestamp).
19
+ */
20
+ expiresAt: string;
21
+
22
+ /**
23
+ * Identifier for the container used in this request.
24
+ */
25
+ id: string;
26
+
27
+ /**
28
+ * Skills loaded in the container.
29
+ */
30
+ skills: Array<{
31
+ /**
32
+ * Type of skill: either 'anthropic' (built-in) or 'custom' (user-defined).
33
+ */
34
+ type: 'anthropic' | 'custom';
35
+
36
+ /**
37
+ * Skill ID (1-64 characters).
38
+ */
39
+ skillId: string;
40
+
41
+ /**
42
+ * Skill version or 'latest' for most recent version (1-64 characters).
43
+ */
44
+ version: string;
45
+ }> | null;
46
+ } | null;
47
+
48
+ /**
49
+ * Context management response.
50
+ *
51
+ * Information about context management strategies applied during the request.
52
+ */
53
+ contextManagement: {
54
+ /**
55
+ * List of context management edits that were applied.
56
+ * Each item in the array is a specific type of context management edit.
57
+ */
58
+ appliedEdits: Array<
59
+ /**
60
+ * Represents an edit where a certain number of tool uses and input tokens were cleared.
61
+ */
62
+ | {
63
+ /**
64
+ * The type of context management edit applied.
65
+ * Possible value: 'clear_tool_uses_20250919'
66
+ */
67
+ type: 'clear_tool_uses_20250919';
68
+
69
+ /**
70
+ * Number of tool uses that were cleared by this edit.
71
+ * Minimum: 0
72
+ */
73
+ clearedToolUses: number;
74
+
75
+ /**
76
+ * Number of input tokens cleared by this edit.
77
+ * Minimum: 0
78
+ */
79
+ clearedInputTokens: number;
80
+ }
81
+ /**
82
+ * Represents an edit where a certain number of thinking turns and input tokens were cleared.
83
+ */
84
+ | {
85
+ /**
86
+ * The type of context management edit applied.
87
+ * Possible value: 'clear_thinking_20251015'
88
+ */
89
+ type: 'clear_thinking_20251015';
90
+
91
+ /**
92
+ * Number of thinking turns that were cleared by this edit.
93
+ * Minimum: 0
94
+ */
95
+ clearedThinkingTurns: number;
96
+
97
+ /**
98
+ * Number of input tokens cleared by this edit.
99
+ * Minimum: 0
100
+ */
101
+ clearedInputTokens: number;
102
+ }
103
+ >;
104
+ } | null;
105
+ }