@ai-sdk/anthropic 3.0.18 → 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 (72) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/index.js +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/package.json +3 -2
  5. package/src/__fixtures__/anthropic-code-execution-20250825.1.chunks.txt +248 -0
  6. package/src/__fixtures__/anthropic-code-execution-20250825.1.json +70 -0
  7. package/src/__fixtures__/anthropic-code-execution-20250825.2.chunks.txt +984 -0
  8. package/src/__fixtures__/anthropic-code-execution-20250825.2.json +111 -0
  9. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.chunks.txt +691 -0
  10. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.json +1801 -0
  11. package/src/__fixtures__/anthropic-json-other-tool.1.chunks.txt +13 -0
  12. package/src/__fixtures__/anthropic-json-other-tool.1.json +26 -0
  13. package/src/__fixtures__/anthropic-json-output-format.1.chunks.txt +120 -0
  14. package/src/__fixtures__/anthropic-json-output-format.1.json +25 -0
  15. package/src/__fixtures__/anthropic-json-tool.1.chunks.txt +9 -0
  16. package/src/__fixtures__/anthropic-json-tool.1.json +37 -0
  17. package/src/__fixtures__/anthropic-json-tool.2.chunks.txt +14 -0
  18. package/src/__fixtures__/anthropic-mcp.1.chunks.txt +17 -0
  19. package/src/__fixtures__/anthropic-mcp.1.json +39 -0
  20. package/src/__fixtures__/anthropic-memory-20250818.1.json +28 -0
  21. package/src/__fixtures__/anthropic-message-delta-input-tokens.chunks.txt +8 -0
  22. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.chunks.txt +278 -0
  23. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.json +106 -0
  24. package/src/__fixtures__/anthropic-tool-no-args.chunks.txt +13 -0
  25. package/src/__fixtures__/anthropic-tool-no-args.json +31 -0
  26. package/src/__fixtures__/anthropic-tool-search-bm25.1.chunks.txt +47 -0
  27. package/src/__fixtures__/anthropic-tool-search-bm25.1.json +67 -0
  28. package/src/__fixtures__/anthropic-tool-search-regex.1.chunks.txt +51 -0
  29. package/src/__fixtures__/anthropic-tool-search-regex.1.json +65 -0
  30. package/src/__fixtures__/anthropic-web-fetch-tool.1.chunks.txt +64 -0
  31. package/src/__fixtures__/anthropic-web-fetch-tool.1.json +54 -0
  32. package/src/__fixtures__/anthropic-web-fetch-tool.2.json +56 -0
  33. package/src/__fixtures__/anthropic-web-fetch-tool.error.json +46 -0
  34. package/src/__fixtures__/anthropic-web-search-tool.1.chunks.txt +120 -0
  35. package/src/__fixtures__/anthropic-web-search-tool.1.json +181 -0
  36. package/src/__snapshots__/anthropic-messages-language-model.test.ts.snap +16719 -0
  37. package/src/anthropic-error.test.ts +42 -0
  38. package/src/anthropic-error.ts +26 -0
  39. package/src/anthropic-message-metadata.ts +105 -0
  40. package/src/anthropic-messages-api.ts +1188 -0
  41. package/src/anthropic-messages-language-model.test.ts +7170 -0
  42. package/src/anthropic-messages-language-model.ts +2067 -0
  43. package/src/anthropic-messages-options.ts +213 -0
  44. package/src/anthropic-prepare-tools.test.ts +1219 -0
  45. package/src/anthropic-prepare-tools.ts +341 -0
  46. package/src/anthropic-provider.test.ts +162 -0
  47. package/src/anthropic-provider.ts +152 -0
  48. package/src/anthropic-tools.ts +182 -0
  49. package/src/convert-anthropic-messages-usage.ts +32 -0
  50. package/src/convert-to-anthropic-messages-prompt.test.ts +2902 -0
  51. package/src/convert-to-anthropic-messages-prompt.ts +1050 -0
  52. package/src/forward-anthropic-container-id-from-last-step.ts +38 -0
  53. package/src/get-cache-control.ts +63 -0
  54. package/src/index.ts +10 -0
  55. package/src/internal/index.ts +4 -0
  56. package/src/map-anthropic-stop-reason.ts +28 -0
  57. package/src/tool/bash_20241022.ts +33 -0
  58. package/src/tool/bash_20250124.ts +33 -0
  59. package/src/tool/code-execution_20250522.ts +61 -0
  60. package/src/tool/code-execution_20250825.ts +281 -0
  61. package/src/tool/computer_20241022.ts +87 -0
  62. package/src/tool/computer_20250124.ts +130 -0
  63. package/src/tool/memory_20250818.ts +62 -0
  64. package/src/tool/text-editor_20241022.ts +63 -0
  65. package/src/tool/text-editor_20250124.ts +63 -0
  66. package/src/tool/text-editor_20250429.ts +64 -0
  67. package/src/tool/text-editor_20250728.ts +80 -0
  68. package/src/tool/tool-search-bm25_20251119.ts +98 -0
  69. package/src/tool/tool-search-regex_20251119.ts +110 -0
  70. package/src/tool/web-fetch-20250910.ts +145 -0
  71. package/src/tool/web-search_20250305.ts +136 -0
  72. package/src/version.ts +6 -0
@@ -0,0 +1,213 @@
1
+ import { z } from 'zod/v4';
2
+
3
+ // https://docs.claude.com/en/docs/about-claude/models/overview
4
+ export type AnthropicMessagesModelId =
5
+ | 'claude-3-5-haiku-20241022'
6
+ | 'claude-3-5-haiku-latest'
7
+ | 'claude-3-7-sonnet-20250219'
8
+ | 'claude-3-7-sonnet-latest'
9
+ | 'claude-3-haiku-20240307'
10
+ | 'claude-haiku-4-5-20251001'
11
+ | 'claude-haiku-4-5'
12
+ | 'claude-opus-4-0'
13
+ | 'claude-opus-4-1-20250805'
14
+ | 'claude-opus-4-1'
15
+ | 'claude-opus-4-20250514'
16
+ | 'claude-opus-4-5'
17
+ | 'claude-opus-4-5-20251101'
18
+ | 'claude-sonnet-4-0'
19
+ | 'claude-sonnet-4-20250514'
20
+ | 'claude-sonnet-4-5-20250929'
21
+ | 'claude-sonnet-4-5'
22
+ | (string & {});
23
+
24
+ /**
25
+ * Anthropic file part provider options for document-specific features.
26
+ * These options apply to individual file parts (documents).
27
+ */
28
+ export const anthropicFilePartProviderOptions = z.object({
29
+ /**
30
+ * Citation configuration for this document.
31
+ * When enabled, this document will generate citations in the response.
32
+ */
33
+ citations: z
34
+ .object({
35
+ /**
36
+ * Enable citations for this document
37
+ */
38
+ enabled: z.boolean(),
39
+ })
40
+ .optional(),
41
+
42
+ /**
43
+ * Custom title for the document.
44
+ * If not provided, the filename will be used.
45
+ */
46
+ title: z.string().optional(),
47
+
48
+ /**
49
+ * Context about the document that will be passed to the model
50
+ * but not used towards cited content.
51
+ * Useful for storing document metadata as text or stringified JSON.
52
+ */
53
+ context: z.string().optional(),
54
+ });
55
+
56
+ export type AnthropicFilePartProviderOptions = z.infer<
57
+ typeof anthropicFilePartProviderOptions
58
+ >;
59
+
60
+ export const anthropicProviderOptions = z.object({
61
+ /**
62
+ * Whether to send reasoning to the model.
63
+ *
64
+ * This allows you to deactivate reasoning inputs for models that do not support them.
65
+ */
66
+ sendReasoning: z.boolean().optional(),
67
+
68
+ /**
69
+ * Determines how structured outputs are generated.
70
+ *
71
+ * - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
72
+ * - `jsonTool`: Use a special 'json' tool to specify the structured output format.
73
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default).
74
+ */
75
+ structuredOutputMode: z.enum(['outputFormat', 'jsonTool', 'auto']).optional(),
76
+
77
+ /**
78
+ * Configuration for enabling Claude's extended thinking.
79
+ *
80
+ * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
81
+ * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
82
+ */
83
+ thinking: z
84
+ .object({
85
+ type: z.union([z.literal('enabled'), z.literal('disabled')]),
86
+ budgetTokens: z.number().optional(),
87
+ })
88
+ .optional(),
89
+
90
+ /**
91
+ * Whether to disable parallel function calling during tool use. Default is false.
92
+ * When set to true, Claude will use at most one tool per response.
93
+ */
94
+ disableParallelToolUse: z.boolean().optional(),
95
+
96
+ /**
97
+ * Cache control settings for this message.
98
+ * See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
99
+ */
100
+ cacheControl: z
101
+ .object({
102
+ type: z.literal('ephemeral'),
103
+ ttl: z.union([z.literal('5m'), z.literal('1h')]).optional(),
104
+ })
105
+ .optional(),
106
+
107
+ /**
108
+ * MCP servers to be utilized in this request.
109
+ */
110
+ mcpServers: z
111
+ .array(
112
+ z.object({
113
+ type: z.literal('url'),
114
+ name: z.string(),
115
+ url: z.string(),
116
+ authorizationToken: z.string().nullish(),
117
+ toolConfiguration: z
118
+ .object({
119
+ enabled: z.boolean().nullish(),
120
+ allowedTools: z.array(z.string()).nullish(),
121
+ })
122
+ .nullish(),
123
+ }),
124
+ )
125
+ .optional(),
126
+
127
+ /**
128
+ * Agent Skills configuration. Skills enable Claude to perform specialized tasks
129
+ * like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
130
+ * Requires code execution tool to be enabled.
131
+ */
132
+ container: z
133
+ .object({
134
+ id: z.string().optional(),
135
+ skills: z
136
+ .array(
137
+ z.object({
138
+ type: z.union([z.literal('anthropic'), z.literal('custom')]),
139
+ skillId: z.string(),
140
+ version: z.string().optional(),
141
+ }),
142
+ )
143
+ .optional(),
144
+ })
145
+ .optional(),
146
+
147
+ /**
148
+ * Whether to enable tool streaming (and structured output streaming).
149
+ *
150
+ * When set to false, the model will return all tool calls and results
151
+ * at once after a delay.
152
+ *
153
+ * @default true
154
+ */
155
+ toolStreaming: z.boolean().optional(),
156
+
157
+ /**
158
+ * @default 'high'
159
+ */
160
+ effort: z.enum(['low', 'medium', 'high']).optional(),
161
+
162
+ contextManagement: z
163
+ .object({
164
+ edits: z.array(
165
+ z.discriminatedUnion('type', [
166
+ z.object({
167
+ type: z.literal('clear_tool_uses_20250919'),
168
+ trigger: z
169
+ .discriminatedUnion('type', [
170
+ z.object({
171
+ type: z.literal('input_tokens'),
172
+ value: z.number(),
173
+ }),
174
+ z.object({
175
+ type: z.literal('tool_uses'),
176
+ value: z.number(),
177
+ }),
178
+ ])
179
+ .optional(),
180
+ keep: z
181
+ .object({
182
+ type: z.literal('tool_uses'),
183
+ value: z.number(),
184
+ })
185
+ .optional(),
186
+ clearAtLeast: z
187
+ .object({
188
+ type: z.literal('input_tokens'),
189
+ value: z.number(),
190
+ })
191
+ .optional(),
192
+ clearToolInputs: z.boolean().optional(),
193
+ excludeTools: z.array(z.string()).optional(),
194
+ }),
195
+ z.object({
196
+ type: z.literal('clear_thinking_20251015'),
197
+ keep: z
198
+ .union([
199
+ z.literal('all'),
200
+ z.object({
201
+ type: z.literal('thinking_turns'),
202
+ value: z.number(),
203
+ }),
204
+ ])
205
+ .optional(),
206
+ }),
207
+ ]),
208
+ ),
209
+ })
210
+ .optional(),
211
+ });
212
+
213
+ export type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;