@fairyhunter13/ai-anthropic 3.0.58-fork.1
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.
- package/CHANGELOG.md +2521 -0
- package/LICENSE +13 -0
- package/README.md +43 -0
- package/dist/index.d.mts +1099 -0
- package/dist/index.d.ts +1099 -0
- package/dist/index.js +5222 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5298 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal/index.d.mts +960 -0
- package/dist/internal/index.d.ts +960 -0
- package/dist/internal/index.js +5122 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/internal/index.mjs +5190 -0
- package/dist/internal/index.mjs.map +1 -0
- package/docs/05-anthropic.mdx +1321 -0
- package/internal.d.ts +1 -0
- package/package.json +83 -0
- package/src/anthropic-error.ts +26 -0
- package/src/anthropic-message-metadata.ts +143 -0
- package/src/anthropic-messages-api.ts +1348 -0
- package/src/anthropic-messages-language-model.ts +2407 -0
- package/src/anthropic-messages-options.ts +267 -0
- package/src/anthropic-prepare-tools.ts +404 -0
- package/src/anthropic-provider.ts +177 -0
- package/src/anthropic-tools.ts +238 -0
- package/src/convert-anthropic-messages-usage.ts +73 -0
- package/src/convert-to-anthropic-messages-prompt.ts +1144 -0
- package/src/forward-anthropic-container-id-from-last-step.ts +38 -0
- package/src/get-cache-control.ts +63 -0
- package/src/index.ts +17 -0
- package/src/internal/index.ts +4 -0
- package/src/map-anthropic-stop-reason.ts +30 -0
- package/src/tool/bash_20241022.ts +33 -0
- package/src/tool/bash_20250124.ts +33 -0
- package/src/tool/code-execution_20250522.ts +61 -0
- package/src/tool/code-execution_20250825.ts +281 -0
- package/src/tool/code-execution_20260120.ts +315 -0
- package/src/tool/computer_20241022.ts +87 -0
- package/src/tool/computer_20250124.ts +130 -0
- package/src/tool/computer_20251124.ts +151 -0
- package/src/tool/memory_20250818.ts +62 -0
- package/src/tool/text-editor_20241022.ts +69 -0
- package/src/tool/text-editor_20250124.ts +69 -0
- package/src/tool/text-editor_20250429.ts +70 -0
- package/src/tool/text-editor_20250728.ts +86 -0
- package/src/tool/tool-search-bm25_20251119.ts +99 -0
- package/src/tool/tool-search-regex_20251119.ts +111 -0
- package/src/tool/web-fetch-20250910.ts +145 -0
- package/src/tool/web-fetch-20260209.ts +145 -0
- package/src/tool/web-search_20250305.ts +136 -0
- package/src/tool/web-search_20260209.ts +136 -0
- package/src/version.ts +6 -0
|
@@ -0,0 +1,267 @@
|
|
|
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-haiku-20240307'
|
|
6
|
+
| 'claude-haiku-4-5-20251001'
|
|
7
|
+
| 'claude-haiku-4-5'
|
|
8
|
+
| 'claude-opus-4-0'
|
|
9
|
+
| 'claude-opus-4-20250514'
|
|
10
|
+
| 'claude-opus-4-1-20250805'
|
|
11
|
+
| 'claude-opus-4-1'
|
|
12
|
+
| 'claude-opus-4-5'
|
|
13
|
+
| 'claude-opus-4-5-20251101'
|
|
14
|
+
| 'claude-sonnet-4-0'
|
|
15
|
+
| 'claude-sonnet-4-20250514'
|
|
16
|
+
| 'claude-sonnet-4-5-20250929'
|
|
17
|
+
| 'claude-sonnet-4-5'
|
|
18
|
+
| 'claude-sonnet-4-6'
|
|
19
|
+
| 'claude-opus-4-6'
|
|
20
|
+
| (string & {});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Anthropic file part provider options for document-specific features.
|
|
24
|
+
* These options apply to individual file parts (documents).
|
|
25
|
+
*/
|
|
26
|
+
export const anthropicFilePartProviderOptions = z.object({
|
|
27
|
+
/**
|
|
28
|
+
* Citation configuration for this document.
|
|
29
|
+
* When enabled, this document will generate citations in the response.
|
|
30
|
+
*/
|
|
31
|
+
citations: z
|
|
32
|
+
.object({
|
|
33
|
+
/**
|
|
34
|
+
* Enable citations for this document
|
|
35
|
+
*/
|
|
36
|
+
enabled: z.boolean(),
|
|
37
|
+
})
|
|
38
|
+
.optional(),
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Custom title for the document.
|
|
42
|
+
* If not provided, the filename will be used.
|
|
43
|
+
*/
|
|
44
|
+
title: z.string().optional(),
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Context about the document that will be passed to the model
|
|
48
|
+
* but not used towards cited content.
|
|
49
|
+
* Useful for storing document metadata as text or stringified JSON.
|
|
50
|
+
*/
|
|
51
|
+
context: z.string().optional(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export type AnthropicFilePartProviderOptions = z.infer<
|
|
55
|
+
typeof anthropicFilePartProviderOptions
|
|
56
|
+
>;
|
|
57
|
+
|
|
58
|
+
export const anthropicLanguageModelOptions = z.object({
|
|
59
|
+
/**
|
|
60
|
+
* Whether to send reasoning to the model.
|
|
61
|
+
*
|
|
62
|
+
* This allows you to deactivate reasoning inputs for models that do not support them.
|
|
63
|
+
*/
|
|
64
|
+
sendReasoning: z.boolean().optional(),
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Determines how structured outputs are generated.
|
|
68
|
+
*
|
|
69
|
+
* - `outputFormat`: Use the `output_config.format` parameter to specify the structured output format.
|
|
70
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format.
|
|
71
|
+
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default).
|
|
72
|
+
*/
|
|
73
|
+
structuredOutputMode: z.enum(['outputFormat', 'jsonTool', 'auto']).optional(),
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Configuration for enabling Claude's extended thinking.
|
|
77
|
+
*
|
|
78
|
+
* When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
|
|
79
|
+
* Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
|
|
80
|
+
*/
|
|
81
|
+
thinking: z
|
|
82
|
+
.discriminatedUnion('type', [
|
|
83
|
+
z.object({
|
|
84
|
+
/** for Sonnet 4.6, Opus 4.6, and newer models */
|
|
85
|
+
type: z.literal('adaptive'),
|
|
86
|
+
/**
|
|
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
|
|
90
|
+
*/
|
|
91
|
+
display: z.enum(['omitted', 'summarized']).optional(),
|
|
92
|
+
}),
|
|
93
|
+
z.object({
|
|
94
|
+
/** for models before Opus 4.6, except Sonnet 4.6 still supports it */
|
|
95
|
+
type: z.literal('enabled'),
|
|
96
|
+
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
|
+
}),
|
|
104
|
+
z.object({
|
|
105
|
+
type: z.literal('disabled'),
|
|
106
|
+
}),
|
|
107
|
+
])
|
|
108
|
+
.optional(),
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether to disable parallel function calling during tool use. Default is false.
|
|
112
|
+
* When set to true, Claude will use at most one tool per response.
|
|
113
|
+
*/
|
|
114
|
+
disableParallelToolUse: z.boolean().optional(),
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Cache control settings for this message.
|
|
118
|
+
* See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
|
|
119
|
+
*/
|
|
120
|
+
cacheControl: z
|
|
121
|
+
.object({
|
|
122
|
+
type: z.literal('ephemeral'),
|
|
123
|
+
ttl: z.union([z.literal('5m'), z.literal('1h')]).optional(),
|
|
124
|
+
})
|
|
125
|
+
.optional(),
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* MCP servers to be utilized in this request.
|
|
129
|
+
*/
|
|
130
|
+
mcpServers: z
|
|
131
|
+
.array(
|
|
132
|
+
z.object({
|
|
133
|
+
type: z.literal('url'),
|
|
134
|
+
name: z.string(),
|
|
135
|
+
url: z.string(),
|
|
136
|
+
authorizationToken: z.string().nullish(),
|
|
137
|
+
toolConfiguration: z
|
|
138
|
+
.object({
|
|
139
|
+
enabled: z.boolean().nullish(),
|
|
140
|
+
allowedTools: z.array(z.string()).nullish(),
|
|
141
|
+
})
|
|
142
|
+
.nullish(),
|
|
143
|
+
}),
|
|
144
|
+
)
|
|
145
|
+
.optional(),
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Agent Skills configuration. Skills enable Claude to perform specialized tasks
|
|
149
|
+
* like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
|
|
150
|
+
* Requires code execution tool to be enabled.
|
|
151
|
+
*/
|
|
152
|
+
container: z
|
|
153
|
+
.object({
|
|
154
|
+
id: z.string().optional(),
|
|
155
|
+
skills: z
|
|
156
|
+
.array(
|
|
157
|
+
z.object({
|
|
158
|
+
type: z.union([z.literal('anthropic'), z.literal('custom')]),
|
|
159
|
+
skillId: z.string(),
|
|
160
|
+
version: z.string().optional(),
|
|
161
|
+
}),
|
|
162
|
+
)
|
|
163
|
+
.optional(),
|
|
164
|
+
})
|
|
165
|
+
.optional(),
|
|
166
|
+
|
|
167
|
+
/**
|
|
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.
|
|
172
|
+
*
|
|
173
|
+
* @default true
|
|
174
|
+
*/
|
|
175
|
+
toolStreaming: z.boolean().optional(),
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @default 'high'
|
|
179
|
+
*/
|
|
180
|
+
effort: z.enum(['low', 'medium', 'high', 'max']).optional(),
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Enable fast mode for faster inference (2.5x faster output token speeds).
|
|
184
|
+
* Only supported with claude-opus-4-6.
|
|
185
|
+
*/
|
|
186
|
+
speed: z.enum(['fast', 'standard']).optional(),
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A set of beta features to enable.
|
|
190
|
+
* Allow a provider to receive the full `betas` set if it needs it.
|
|
191
|
+
*/
|
|
192
|
+
anthropicBeta: z.array(z.string()).optional(),
|
|
193
|
+
|
|
194
|
+
/**
|
|
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 '{"'
|
|
200
|
+
*/
|
|
201
|
+
prefill: z.string().optional(),
|
|
202
|
+
|
|
203
|
+
contextManagement: z
|
|
204
|
+
.object({
|
|
205
|
+
edits: z.array(
|
|
206
|
+
z.discriminatedUnion('type', [
|
|
207
|
+
z.object({
|
|
208
|
+
type: z.literal('clear_tool_uses_20250919'),
|
|
209
|
+
trigger: z
|
|
210
|
+
.discriminatedUnion('type', [
|
|
211
|
+
z.object({
|
|
212
|
+
type: z.literal('input_tokens'),
|
|
213
|
+
value: z.number(),
|
|
214
|
+
}),
|
|
215
|
+
z.object({
|
|
216
|
+
type: z.literal('tool_uses'),
|
|
217
|
+
value: z.number(),
|
|
218
|
+
}),
|
|
219
|
+
])
|
|
220
|
+
.optional(),
|
|
221
|
+
keep: z
|
|
222
|
+
.object({
|
|
223
|
+
type: z.literal('tool_uses'),
|
|
224
|
+
value: z.number(),
|
|
225
|
+
})
|
|
226
|
+
.optional(),
|
|
227
|
+
clearAtLeast: z
|
|
228
|
+
.object({
|
|
229
|
+
type: z.literal('input_tokens'),
|
|
230
|
+
value: z.number(),
|
|
231
|
+
})
|
|
232
|
+
.optional(),
|
|
233
|
+
clearToolInputs: z.boolean().optional(),
|
|
234
|
+
excludeTools: z.array(z.string()).optional(),
|
|
235
|
+
}),
|
|
236
|
+
z.object({
|
|
237
|
+
type: z.literal('clear_thinking_20251015'),
|
|
238
|
+
keep: z
|
|
239
|
+
.union([
|
|
240
|
+
z.literal('all'),
|
|
241
|
+
z.object({
|
|
242
|
+
type: z.literal('thinking_turns'),
|
|
243
|
+
value: z.number(),
|
|
244
|
+
}),
|
|
245
|
+
])
|
|
246
|
+
.optional(),
|
|
247
|
+
}),
|
|
248
|
+
z.object({
|
|
249
|
+
type: z.literal('compact_20260112'),
|
|
250
|
+
trigger: z
|
|
251
|
+
.object({
|
|
252
|
+
type: z.literal('input_tokens'),
|
|
253
|
+
value: z.number(),
|
|
254
|
+
})
|
|
255
|
+
.optional(),
|
|
256
|
+
pauseAfterCompaction: z.boolean().optional(),
|
|
257
|
+
instructions: z.string().optional(),
|
|
258
|
+
}),
|
|
259
|
+
]),
|
|
260
|
+
),
|
|
261
|
+
})
|
|
262
|
+
.optional(),
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
export type AnthropicLanguageModelOptions = z.infer<
|
|
266
|
+
typeof anthropicLanguageModelOptions
|
|
267
|
+
>;
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LanguageModelV3CallOptions,
|
|
3
|
+
SharedV3Warning,
|
|
4
|
+
UnsupportedFunctionalityError,
|
|
5
|
+
} from '@ai-sdk/provider';
|
|
6
|
+
import { AnthropicTool, AnthropicToolChoice } from './anthropic-messages-api';
|
|
7
|
+
import { CacheControlValidator } from './get-cache-control';
|
|
8
|
+
import { textEditor_20250728ArgsSchema } from './tool/text-editor_20250728';
|
|
9
|
+
import { webSearch_20260209ArgsSchema } from './tool/web-search_20260209';
|
|
10
|
+
import { webSearch_20250305ArgsSchema } from './tool/web-search_20250305';
|
|
11
|
+
import { webFetch_20260209ArgsSchema } from './tool/web-fetch-20260209';
|
|
12
|
+
import { webFetch_20250910ArgsSchema } from './tool/web-fetch-20250910';
|
|
13
|
+
import { validateTypes } from '@ai-sdk/provider-utils';
|
|
14
|
+
|
|
15
|
+
export interface AnthropicToolOptions {
|
|
16
|
+
deferLoading?: boolean;
|
|
17
|
+
allowedCallers?: Array<
|
|
18
|
+
'direct' | 'code_execution_20250825' | 'code_execution_20260120'
|
|
19
|
+
>;
|
|
20
|
+
eagerInputStreaming?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function prepareTools({
|
|
24
|
+
tools,
|
|
25
|
+
toolChoice,
|
|
26
|
+
disableParallelToolUse,
|
|
27
|
+
cacheControlValidator,
|
|
28
|
+
supportsStructuredOutput,
|
|
29
|
+
}: {
|
|
30
|
+
tools: LanguageModelV3CallOptions['tools'];
|
|
31
|
+
toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
|
|
32
|
+
disableParallelToolUse?: boolean;
|
|
33
|
+
cacheControlValidator?: CacheControlValidator;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether the model supports structured output.
|
|
37
|
+
*/
|
|
38
|
+
supportsStructuredOutput: boolean;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
tools: Array<AnthropicTool> | undefined;
|
|
41
|
+
toolChoice: AnthropicToolChoice | undefined;
|
|
42
|
+
toolWarnings: SharedV3Warning[];
|
|
43
|
+
betas: Set<string>;
|
|
44
|
+
}> {
|
|
45
|
+
// when the tools array is empty, change it to undefined to prevent errors:
|
|
46
|
+
tools = tools?.length ? tools : undefined;
|
|
47
|
+
|
|
48
|
+
const toolWarnings: SharedV3Warning[] = [];
|
|
49
|
+
const betas = new Set<string>();
|
|
50
|
+
const validator = cacheControlValidator || new CacheControlValidator();
|
|
51
|
+
|
|
52
|
+
if (tools == null) {
|
|
53
|
+
return { tools: undefined, toolChoice: undefined, toolWarnings, betas };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const anthropicTools: AnthropicTool[] = [];
|
|
57
|
+
|
|
58
|
+
for (const tool of tools) {
|
|
59
|
+
switch (tool.type) {
|
|
60
|
+
case 'function': {
|
|
61
|
+
const cacheControl = validator.getCacheControl(tool.providerOptions, {
|
|
62
|
+
type: 'tool definition',
|
|
63
|
+
canCache: true,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Read Anthropic-specific provider options
|
|
67
|
+
const anthropicOptions = tool.providerOptions?.anthropic as
|
|
68
|
+
| AnthropicToolOptions
|
|
69
|
+
| undefined;
|
|
70
|
+
// eager_input_streaming is only supported on custom (function) tools
|
|
71
|
+
const eagerInputStreaming = anthropicOptions?.eagerInputStreaming;
|
|
72
|
+
const deferLoading = anthropicOptions?.deferLoading;
|
|
73
|
+
const allowedCallers = anthropicOptions?.allowedCallers;
|
|
74
|
+
|
|
75
|
+
anthropicTools.push({
|
|
76
|
+
name: tool.name,
|
|
77
|
+
description: tool.description,
|
|
78
|
+
input_schema: tool.inputSchema,
|
|
79
|
+
cache_control: cacheControl,
|
|
80
|
+
...(eagerInputStreaming ? { eager_input_streaming: true } : {}),
|
|
81
|
+
...(supportsStructuredOutput === true && tool.strict != null
|
|
82
|
+
? { strict: tool.strict }
|
|
83
|
+
: {}),
|
|
84
|
+
...(deferLoading != null ? { defer_loading: deferLoading } : {}),
|
|
85
|
+
...(allowedCallers != null
|
|
86
|
+
? { allowed_callers: allowedCallers }
|
|
87
|
+
: {}),
|
|
88
|
+
...(tool.inputExamples != null
|
|
89
|
+
? {
|
|
90
|
+
input_examples: tool.inputExamples.map(
|
|
91
|
+
example => example.input,
|
|
92
|
+
),
|
|
93
|
+
}
|
|
94
|
+
: {}),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (supportsStructuredOutput === true) {
|
|
98
|
+
betas.add('structured-outputs-2025-11-13');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (tool.inputExamples != null || allowedCallers != null) {
|
|
102
|
+
betas.add('advanced-tool-use-2025-11-20');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
case 'provider': {
|
|
109
|
+
// Note: Provider-defined tools don't currently support providerOptions in the SDK,
|
|
110
|
+
// so cache_control cannot be set on them. The Anthropic API supports caching all tools,
|
|
111
|
+
// but the SDK would need to be updated to expose providerOptions on provider-defined tools.
|
|
112
|
+
switch (tool.id) {
|
|
113
|
+
case 'anthropic.code_execution_20250522': {
|
|
114
|
+
betas.add('code-execution-2025-05-22');
|
|
115
|
+
anthropicTools.push({
|
|
116
|
+
type: 'code_execution_20250522',
|
|
117
|
+
name: 'code_execution',
|
|
118
|
+
cache_control: undefined,
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 'anthropic.code_execution_20250825': {
|
|
123
|
+
betas.add('code-execution-2025-08-25');
|
|
124
|
+
anthropicTools.push({
|
|
125
|
+
type: 'code_execution_20250825',
|
|
126
|
+
name: 'code_execution',
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case 'anthropic.code_execution_20260120': {
|
|
131
|
+
anthropicTools.push({
|
|
132
|
+
type: 'code_execution_20260120',
|
|
133
|
+
name: 'code_execution',
|
|
134
|
+
});
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case 'anthropic.computer_20250124': {
|
|
138
|
+
betas.add('computer-use-2025-01-24');
|
|
139
|
+
anthropicTools.push({
|
|
140
|
+
name: 'computer',
|
|
141
|
+
type: 'computer_20250124',
|
|
142
|
+
display_width_px: tool.args.displayWidthPx as number,
|
|
143
|
+
display_height_px: tool.args.displayHeightPx as number,
|
|
144
|
+
display_number: tool.args.displayNumber as number,
|
|
145
|
+
cache_control: undefined,
|
|
146
|
+
});
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case 'anthropic.computer_20251124': {
|
|
150
|
+
betas.add('computer-use-2025-11-24');
|
|
151
|
+
anthropicTools.push({
|
|
152
|
+
name: 'computer',
|
|
153
|
+
type: 'computer_20251124',
|
|
154
|
+
display_width_px: tool.args.displayWidthPx as number,
|
|
155
|
+
display_height_px: tool.args.displayHeightPx as number,
|
|
156
|
+
display_number: tool.args.displayNumber as number,
|
|
157
|
+
enable_zoom: tool.args.enableZoom as boolean,
|
|
158
|
+
cache_control: undefined,
|
|
159
|
+
});
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case 'anthropic.computer_20241022': {
|
|
163
|
+
betas.add('computer-use-2024-10-22');
|
|
164
|
+
anthropicTools.push({
|
|
165
|
+
name: 'computer',
|
|
166
|
+
type: 'computer_20241022',
|
|
167
|
+
display_width_px: tool.args.displayWidthPx as number,
|
|
168
|
+
display_height_px: tool.args.displayHeightPx as number,
|
|
169
|
+
display_number: tool.args.displayNumber as number,
|
|
170
|
+
cache_control: undefined,
|
|
171
|
+
});
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'anthropic.text_editor_20250124': {
|
|
175
|
+
betas.add('computer-use-2025-01-24');
|
|
176
|
+
anthropicTools.push({
|
|
177
|
+
name: 'str_replace_editor',
|
|
178
|
+
type: 'text_editor_20250124',
|
|
179
|
+
cache_control: undefined,
|
|
180
|
+
});
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case 'anthropic.text_editor_20241022': {
|
|
184
|
+
betas.add('computer-use-2024-10-22');
|
|
185
|
+
anthropicTools.push({
|
|
186
|
+
name: 'str_replace_editor',
|
|
187
|
+
type: 'text_editor_20241022',
|
|
188
|
+
cache_control: undefined,
|
|
189
|
+
});
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case 'anthropic.text_editor_20250429': {
|
|
193
|
+
betas.add('computer-use-2025-01-24');
|
|
194
|
+
anthropicTools.push({
|
|
195
|
+
name: 'str_replace_based_edit_tool',
|
|
196
|
+
type: 'text_editor_20250429',
|
|
197
|
+
cache_control: undefined,
|
|
198
|
+
});
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case 'anthropic.text_editor_20250728': {
|
|
202
|
+
const args = await validateTypes({
|
|
203
|
+
value: tool.args,
|
|
204
|
+
schema: textEditor_20250728ArgsSchema,
|
|
205
|
+
});
|
|
206
|
+
anthropicTools.push({
|
|
207
|
+
name: 'str_replace_based_edit_tool',
|
|
208
|
+
type: 'text_editor_20250728',
|
|
209
|
+
max_characters: args.maxCharacters,
|
|
210
|
+
cache_control: undefined,
|
|
211
|
+
});
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case 'anthropic.bash_20250124': {
|
|
215
|
+
betas.add('computer-use-2025-01-24');
|
|
216
|
+
anthropicTools.push({
|
|
217
|
+
name: 'bash',
|
|
218
|
+
type: 'bash_20250124',
|
|
219
|
+
cache_control: undefined,
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case 'anthropic.bash_20241022': {
|
|
224
|
+
betas.add('computer-use-2024-10-22');
|
|
225
|
+
anthropicTools.push({
|
|
226
|
+
name: 'bash',
|
|
227
|
+
type: 'bash_20241022',
|
|
228
|
+
cache_control: undefined,
|
|
229
|
+
});
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case 'anthropic.memory_20250818': {
|
|
233
|
+
betas.add('context-management-2025-06-27');
|
|
234
|
+
anthropicTools.push({
|
|
235
|
+
name: 'memory',
|
|
236
|
+
type: 'memory_20250818',
|
|
237
|
+
});
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case 'anthropic.web_fetch_20250910': {
|
|
241
|
+
betas.add('web-fetch-2025-09-10');
|
|
242
|
+
const args = await validateTypes({
|
|
243
|
+
value: tool.args,
|
|
244
|
+
schema: webFetch_20250910ArgsSchema,
|
|
245
|
+
});
|
|
246
|
+
anthropicTools.push({
|
|
247
|
+
type: 'web_fetch_20250910',
|
|
248
|
+
name: 'web_fetch',
|
|
249
|
+
max_uses: args.maxUses,
|
|
250
|
+
allowed_domains: args.allowedDomains,
|
|
251
|
+
blocked_domains: args.blockedDomains,
|
|
252
|
+
citations: args.citations,
|
|
253
|
+
max_content_tokens: args.maxContentTokens,
|
|
254
|
+
cache_control: undefined,
|
|
255
|
+
});
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case 'anthropic.web_fetch_20260209': {
|
|
259
|
+
betas.add('code-execution-web-tools-2026-02-09');
|
|
260
|
+
const args = await validateTypes({
|
|
261
|
+
value: tool.args,
|
|
262
|
+
schema: webFetch_20260209ArgsSchema,
|
|
263
|
+
});
|
|
264
|
+
anthropicTools.push({
|
|
265
|
+
type: 'web_fetch_20260209',
|
|
266
|
+
name: 'web_fetch',
|
|
267
|
+
max_uses: args.maxUses,
|
|
268
|
+
allowed_domains: args.allowedDomains,
|
|
269
|
+
blocked_domains: args.blockedDomains,
|
|
270
|
+
citations: args.citations,
|
|
271
|
+
max_content_tokens: args.maxContentTokens,
|
|
272
|
+
cache_control: undefined,
|
|
273
|
+
});
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case 'anthropic.web_search_20250305': {
|
|
277
|
+
const args = await validateTypes({
|
|
278
|
+
value: tool.args,
|
|
279
|
+
schema: webSearch_20250305ArgsSchema,
|
|
280
|
+
});
|
|
281
|
+
anthropicTools.push({
|
|
282
|
+
type: 'web_search_20250305',
|
|
283
|
+
name: 'web_search',
|
|
284
|
+
max_uses: args.maxUses,
|
|
285
|
+
allowed_domains: args.allowedDomains,
|
|
286
|
+
blocked_domains: args.blockedDomains,
|
|
287
|
+
user_location: args.userLocation,
|
|
288
|
+
cache_control: undefined,
|
|
289
|
+
});
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case 'anthropic.web_search_20260209': {
|
|
293
|
+
betas.add('code-execution-web-tools-2026-02-09');
|
|
294
|
+
const args = await validateTypes({
|
|
295
|
+
value: tool.args,
|
|
296
|
+
schema: webSearch_20260209ArgsSchema,
|
|
297
|
+
});
|
|
298
|
+
anthropicTools.push({
|
|
299
|
+
type: 'web_search_20260209',
|
|
300
|
+
name: 'web_search',
|
|
301
|
+
max_uses: args.maxUses,
|
|
302
|
+
allowed_domains: args.allowedDomains,
|
|
303
|
+
blocked_domains: args.blockedDomains,
|
|
304
|
+
user_location: args.userLocation,
|
|
305
|
+
cache_control: undefined,
|
|
306
|
+
});
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
case 'anthropic.tool_search_regex_20251119': {
|
|
311
|
+
betas.add('advanced-tool-use-2025-11-20');
|
|
312
|
+
anthropicTools.push({
|
|
313
|
+
type: 'tool_search_tool_regex_20251119',
|
|
314
|
+
name: 'tool_search_tool_regex',
|
|
315
|
+
});
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
case 'anthropic.tool_search_bm25_20251119': {
|
|
320
|
+
betas.add('advanced-tool-use-2025-11-20');
|
|
321
|
+
anthropicTools.push({
|
|
322
|
+
type: 'tool_search_tool_bm25_20251119',
|
|
323
|
+
name: 'tool_search_tool_bm25',
|
|
324
|
+
});
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
default: {
|
|
329
|
+
toolWarnings.push({
|
|
330
|
+
type: 'unsupported',
|
|
331
|
+
feature: `provider-defined tool ${tool.id}`,
|
|
332
|
+
});
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
default: {
|
|
340
|
+
toolWarnings.push({
|
|
341
|
+
type: 'unsupported',
|
|
342
|
+
feature: `tool ${tool}`,
|
|
343
|
+
});
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (toolChoice == null) {
|
|
350
|
+
return {
|
|
351
|
+
tools: anthropicTools,
|
|
352
|
+
toolChoice: disableParallelToolUse
|
|
353
|
+
? { type: 'auto', disable_parallel_tool_use: disableParallelToolUse }
|
|
354
|
+
: undefined,
|
|
355
|
+
toolWarnings,
|
|
356
|
+
betas,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const type = toolChoice.type;
|
|
361
|
+
|
|
362
|
+
switch (type) {
|
|
363
|
+
case 'auto':
|
|
364
|
+
return {
|
|
365
|
+
tools: anthropicTools,
|
|
366
|
+
toolChoice: {
|
|
367
|
+
type: 'auto',
|
|
368
|
+
disable_parallel_tool_use: disableParallelToolUse,
|
|
369
|
+
},
|
|
370
|
+
toolWarnings,
|
|
371
|
+
betas,
|
|
372
|
+
};
|
|
373
|
+
case 'required':
|
|
374
|
+
return {
|
|
375
|
+
tools: anthropicTools,
|
|
376
|
+
toolChoice: {
|
|
377
|
+
type: 'any',
|
|
378
|
+
disable_parallel_tool_use: disableParallelToolUse,
|
|
379
|
+
},
|
|
380
|
+
toolWarnings,
|
|
381
|
+
betas,
|
|
382
|
+
};
|
|
383
|
+
case 'none':
|
|
384
|
+
// Anthropic does not support 'none' tool choice, so we remove the tools:
|
|
385
|
+
return { tools: undefined, toolChoice: undefined, toolWarnings, betas };
|
|
386
|
+
case 'tool':
|
|
387
|
+
return {
|
|
388
|
+
tools: anthropicTools,
|
|
389
|
+
toolChoice: {
|
|
390
|
+
type: 'tool',
|
|
391
|
+
name: toolChoice.toolName,
|
|
392
|
+
disable_parallel_tool_use: disableParallelToolUse,
|
|
393
|
+
},
|
|
394
|
+
toolWarnings,
|
|
395
|
+
betas,
|
|
396
|
+
};
|
|
397
|
+
default: {
|
|
398
|
+
const _exhaustiveCheck: never = type;
|
|
399
|
+
throw new UnsupportedFunctionalityError({
|
|
400
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|