@fairyhunter13/ai-anthropic 3.0.58-fork.8 → 3.0.74-fork

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 (55) hide show
  1. package/CHANGELOG.md +277 -0
  2. package/README.md +2 -0
  3. package/dist/index.d.ts +156 -67
  4. package/dist/index.js +2190 -1471
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +167 -58
  7. package/dist/internal/index.js +1950 -1458
  8. package/dist/internal/index.js.map +1 -1
  9. package/docs/05-anthropic.mdx +116 -13
  10. package/package.json +15 -12
  11. package/src/{anthropic-messages-api.ts → anthropic-api.ts} +46 -15
  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} +80 -41
  15. package/src/{anthropic-messages-language-model.ts → anthropic-language-model.ts} +221 -138
  16. package/src/anthropic-message-metadata.ts +2 -1
  17. package/src/anthropic-prepare-tools.ts +68 -26
  18. package/src/anthropic-provider.ts +42 -13
  19. package/src/anthropic-tools.ts +18 -0
  20. package/src/{convert-anthropic-messages-usage.ts → convert-anthropic-usage.ts} +4 -4
  21. package/src/{convert-to-anthropic-messages-prompt.ts → convert-to-anthropic-prompt.ts} +233 -180
  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 +9 -3
  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/bash_20241022.ts +2 -2
  31. package/src/tool/bash_20250124.ts +2 -2
  32. package/src/tool/code-execution_20250522.ts +2 -2
  33. package/src/tool/code-execution_20250825.ts +2 -2
  34. package/src/tool/code-execution_20260120.ts +2 -2
  35. package/src/tool/computer_20241022.ts +2 -2
  36. package/src/tool/computer_20250124.ts +2 -2
  37. package/src/tool/computer_20251124.ts +2 -2
  38. package/src/tool/memory_20250818.ts +2 -2
  39. package/src/tool/text-editor_20241022.ts +2 -2
  40. package/src/tool/text-editor_20250124.ts +2 -2
  41. package/src/tool/text-editor_20250429.ts +2 -2
  42. package/src/tool/text-editor_20250728.ts +6 -3
  43. package/src/tool/tool-search-bm25_20251119.ts +2 -2
  44. package/src/tool/tool-search-regex_20251119.ts +2 -2
  45. package/src/tool/web-fetch-20250910.ts +2 -2
  46. package/src/tool/web-fetch-20260209.ts +2 -2
  47. package/src/tool/web-fetch-20260309.ts +181 -0
  48. package/src/tool/web-search_20250305.ts +2 -2
  49. package/src/tool/web-search_20260209.ts +19 -2
  50. package/dist/index.d.mts +0 -1105
  51. package/dist/index.mjs +0 -5394
  52. package/dist/index.mjs.map +0 -1
  53. package/dist/internal/index.d.mts +0 -981
  54. package/dist/internal/index.mjs +0 -5287
  55. package/dist/internal/index.mjs.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod/v4';
2
2
 
3
3
  // https://docs.claude.com/en/docs/about-claude/models/overview
4
- export type AnthropicMessagesModelId =
4
+ export type AnthropicModelId =
5
5
  | 'claude-3-haiku-20240307'
6
6
  | 'claude-haiku-4-5-20251001'
7
7
  | 'claude-haiku-4-5'
@@ -17,6 +17,7 @@ export type AnthropicMessagesModelId =
17
17
  | 'claude-sonnet-4-5'
18
18
  | 'claude-sonnet-4-6'
19
19
  | 'claude-opus-4-6'
20
+ | 'claude-opus-4-7'
20
21
  | (string & {});
21
22
 
22
23
  /**
@@ -84,9 +85,9 @@ export const anthropicLanguageModelOptions = z.object({
84
85
  /** for Sonnet 4.6, Opus 4.6, and newer models */
85
86
  type: z.literal('adaptive'),
86
87
  /**
87
- * Controls thinking output visibility.
88
- * - 'omitted': thinking happens but output is not returned (faster TTFT)
89
- * - 'summarized': a summary of the thinking is returned
88
+ * Controls whether thinking content is included in the response.
89
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
90
+ * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
90
91
  */
91
92
  display: z.enum(['omitted', 'summarized']).optional(),
92
93
  }),
@@ -94,12 +95,6 @@ export const anthropicLanguageModelOptions = z.object({
94
95
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
95
96
  type: z.literal('enabled'),
96
97
  budgetTokens: z.number().optional(),
97
- /**
98
- * Controls thinking output visibility.
99
- * - 'omitted': thinking happens but output is not returned (faster TTFT)
100
- * - 'summarized': a summary of the thinking is returned
101
- */
102
- display: z.enum(['omitted', 'summarized']).optional(),
103
98
  }),
104
99
  z.object({
105
100
  type: z.literal('disabled'),
@@ -124,6 +119,23 @@ export const anthropicLanguageModelOptions = z.object({
124
119
  })
125
120
  .optional(),
126
121
 
122
+ /**
123
+ * Metadata to include with the request.
124
+ *
125
+ * See https://platform.claude.com/docs/en/api/messages/create for details.
126
+ */
127
+ metadata: z
128
+ .object({
129
+ /**
130
+ * An external identifier for the user associated with the request.
131
+ *
132
+ * Should be a UUID, hash value, or other opaque identifier.
133
+ * Must not contain PII (name, email, phone number, etc.).
134
+ */
135
+ userId: z.string().optional(),
136
+ })
137
+ .optional(),
138
+
127
139
  /**
128
140
  * MCP servers to be utilized in this request.
129
141
  */
@@ -154,21 +166,29 @@ export const anthropicLanguageModelOptions = z.object({
154
166
  id: z.string().optional(),
155
167
  skills: z
156
168
  .array(
157
- z.object({
158
- type: z.union([z.literal('anthropic'), z.literal('custom')]),
159
- skillId: z.string(),
160
- version: z.string().optional(),
161
- }),
169
+ z.discriminatedUnion('type', [
170
+ z.object({
171
+ type: z.literal('anthropic'),
172
+ skillId: z.string(),
173
+ version: z.string().optional(),
174
+ }),
175
+ z.object({
176
+ type: z.literal('custom'),
177
+ providerReference: z.record(z.string(), z.string()),
178
+ version: z.string().optional(),
179
+ }),
180
+ ]),
162
181
  )
163
182
  .optional(),
164
183
  })
165
184
  .optional(),
166
185
 
167
186
  /**
168
- * Whether to enable tool streaming (and structured output streaming).
169
- *
170
- * When set to false, the model will return all tool calls and results
171
- * at once after a delay.
187
+ * Whether to enable fine-grained (eager) streaming of tool call inputs
188
+ * and structured outputs for every function tool in the request. When
189
+ * true (the default), each function tool receives a default of
190
+ * `eager_input_streaming: true` unless it explicitly sets
191
+ * `providerOptions.anthropic.eagerInputStreaming`.
172
192
  *
173
193
  * @default true
174
194
  */
@@ -177,7 +197,22 @@ export const anthropicLanguageModelOptions = z.object({
177
197
  /**
178
198
  * @default 'high'
179
199
  */
180
- effort: z.enum(['low', 'medium', 'high', 'max']).optional(),
200
+ effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
201
+
202
+ /**
203
+ * Task budget for agentic turns. Informs the model of the total token budget
204
+ * available for the current task, allowing it to prioritize work and wind down
205
+ * gracefully as the budget is consumed.
206
+ *
207
+ * Advisory only — does not enforce a hard token limit.
208
+ */
209
+ taskBudget: z
210
+ .object({
211
+ type: z.literal('tokens'),
212
+ total: z.number().int().min(20000),
213
+ remaining: z.number().int().min(0).optional(),
214
+ })
215
+ .optional(),
181
216
 
182
217
  /**
183
218
  * Enable fast mode for faster inference (2.5x faster output token speeds).
@@ -186,37 +221,41 @@ export const anthropicLanguageModelOptions = z.object({
186
221
  speed: z.enum(['fast', 'standard']).optional(),
187
222
 
188
223
  /**
189
- * A set of beta features to enable.
190
- * Allow a provider to receive the full `betas` set if it needs it.
224
+ * Advisor tool configuration. When enabled, Claude consults a cheaper
225
+ * advisor model before generating its response, improving tool-use
226
+ * accuracy and reducing cost on complex agentic tasks.
227
+ *
228
+ * Requires the `advisor-tool-2026-03-01` beta header (added automatically).
191
229
  */
192
- anthropicBeta: z.array(z.string()).optional(),
230
+ advisor: z
231
+ .object({
232
+ /** The model ID for the advisor (e.g. "claude-haiku-4-5"). */
233
+ model: z.string(),
234
+ })
235
+ .optional(),
193
236
 
194
237
  /**
195
- * Assistant prefill text. When set, this text is appended as a partial
196
- * assistant message at the end of the prompt, guiding the model's output.
197
- * The model will continue generating from where the prefill ends.
198
- *
199
- * Example: Setting prefill to '{"' will make the model start its response with '{"'
238
+ * Enable 300K output tokens per response (vs default ~8K/32K caps).
239
+ * When true, the `output-300k-2026-03-24` beta header is sent automatically
240
+ * and max_tokens capping is raised to 300,000.
200
241
  */
201
- prefill: z.string().optional(),
242
+ output300k: z.boolean().optional(),
202
243
 
203
244
  /**
204
- * Request metadata. Use `user_id` to track per-user usage for abuse detection
205
- * and rate limit apportioning. Should be a UUID or similar opaque identifier.
206
- * See https://docs.anthropic.com/en/api/messages
245
+ * Controls where model inference runs for this request.
246
+ *
247
+ * - `"global"`: Inference may run in any available geography (default).
248
+ * - `"us"`: Inference runs only in US-based infrastructure.
249
+ *
250
+ * See https://platform.claude.com/docs/en/build-with-claude/data-residency
207
251
  */
208
- metadata: z
209
- .object({
210
- userId: z.string().optional(),
211
- })
212
- .optional(),
252
+ inferenceGeo: z.enum(['us', 'global']).optional(),
213
253
 
214
254
  /**
215
- * Service tier selection.
216
- * - 'auto': Allow Anthropic to pick standard or priority based on availability.
217
- * See https://docs.anthropic.com/en/api/messages
255
+ * A set of beta features to enable.
256
+ * Allow a provider to receive the full `betas` set if it needs it.
218
257
  */
219
- serviceTier: z.enum(['auto']).optional(),
258
+ anthropicBeta: z.array(z.string()).optional(),
220
259
 
221
260
  contextManagement: z
222
261
  .object({