@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.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -2
- package/src/__fixtures__/anthropic-code-execution-20250825.1.chunks.txt +248 -0
- package/src/__fixtures__/anthropic-code-execution-20250825.1.json +70 -0
- package/src/__fixtures__/anthropic-code-execution-20250825.2.chunks.txt +984 -0
- package/src/__fixtures__/anthropic-code-execution-20250825.2.json +111 -0
- package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.chunks.txt +691 -0
- package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.json +1801 -0
- package/src/__fixtures__/anthropic-json-other-tool.1.chunks.txt +13 -0
- package/src/__fixtures__/anthropic-json-other-tool.1.json +26 -0
- package/src/__fixtures__/anthropic-json-output-format.1.chunks.txt +120 -0
- package/src/__fixtures__/anthropic-json-output-format.1.json +25 -0
- package/src/__fixtures__/anthropic-json-tool.1.chunks.txt +9 -0
- package/src/__fixtures__/anthropic-json-tool.1.json +37 -0
- package/src/__fixtures__/anthropic-json-tool.2.chunks.txt +14 -0
- package/src/__fixtures__/anthropic-mcp.1.chunks.txt +17 -0
- package/src/__fixtures__/anthropic-mcp.1.json +39 -0
- package/src/__fixtures__/anthropic-memory-20250818.1.json +28 -0
- package/src/__fixtures__/anthropic-message-delta-input-tokens.chunks.txt +8 -0
- package/src/__fixtures__/anthropic-programmatic-tool-calling.1.chunks.txt +278 -0
- package/src/__fixtures__/anthropic-programmatic-tool-calling.1.json +106 -0
- package/src/__fixtures__/anthropic-tool-no-args.chunks.txt +13 -0
- package/src/__fixtures__/anthropic-tool-no-args.json +31 -0
- package/src/__fixtures__/anthropic-tool-search-bm25.1.chunks.txt +47 -0
- package/src/__fixtures__/anthropic-tool-search-bm25.1.json +67 -0
- package/src/__fixtures__/anthropic-tool-search-regex.1.chunks.txt +51 -0
- package/src/__fixtures__/anthropic-tool-search-regex.1.json +65 -0
- package/src/__fixtures__/anthropic-web-fetch-tool.1.chunks.txt +64 -0
- package/src/__fixtures__/anthropic-web-fetch-tool.1.json +54 -0
- package/src/__fixtures__/anthropic-web-fetch-tool.2.json +56 -0
- package/src/__fixtures__/anthropic-web-fetch-tool.error.json +46 -0
- package/src/__fixtures__/anthropic-web-search-tool.1.chunks.txt +120 -0
- package/src/__fixtures__/anthropic-web-search-tool.1.json +181 -0
- package/src/__snapshots__/anthropic-messages-language-model.test.ts.snap +16719 -0
- package/src/anthropic-error.test.ts +42 -0
- package/src/anthropic-error.ts +26 -0
- package/src/anthropic-message-metadata.ts +105 -0
- package/src/anthropic-messages-api.ts +1188 -0
- package/src/anthropic-messages-language-model.test.ts +7170 -0
- package/src/anthropic-messages-language-model.ts +2067 -0
- package/src/anthropic-messages-options.ts +213 -0
- package/src/anthropic-prepare-tools.test.ts +1219 -0
- package/src/anthropic-prepare-tools.ts +341 -0
- package/src/anthropic-provider.test.ts +162 -0
- package/src/anthropic-provider.ts +152 -0
- package/src/anthropic-tools.ts +182 -0
- package/src/convert-anthropic-messages-usage.ts +32 -0
- package/src/convert-to-anthropic-messages-prompt.test.ts +2902 -0
- package/src/convert-to-anthropic-messages-prompt.ts +1050 -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 +10 -0
- package/src/internal/index.ts +4 -0
- package/src/map-anthropic-stop-reason.ts +28 -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/computer_20241022.ts +87 -0
- package/src/tool/computer_20250124.ts +130 -0
- package/src/tool/memory_20250818.ts +62 -0
- package/src/tool/text-editor_20241022.ts +63 -0
- package/src/tool/text-editor_20250124.ts +63 -0
- package/src/tool/text-editor_20250429.ts +64 -0
- package/src/tool/text-editor_20250728.ts +80 -0
- package/src/tool/tool-search-bm25_20251119.ts +98 -0
- package/src/tool/tool-search-regex_20251119.ts +110 -0
- package/src/tool/web-fetch-20250910.ts +145 -0
- package/src/tool/web-search_20250305.ts +136 -0
- package/src/version.ts +6 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { bash_20241022 } from './tool/bash_20241022';
|
|
2
|
+
import { bash_20250124 } from './tool/bash_20250124';
|
|
3
|
+
import { codeExecution_20250522 } from './tool/code-execution_20250522';
|
|
4
|
+
import { codeExecution_20250825 } from './tool/code-execution_20250825';
|
|
5
|
+
import { computer_20241022 } from './tool/computer_20241022';
|
|
6
|
+
import { computer_20250124 } from './tool/computer_20250124';
|
|
7
|
+
import { memory_20250818 } from './tool/memory_20250818';
|
|
8
|
+
import { textEditor_20241022 } from './tool/text-editor_20241022';
|
|
9
|
+
import { textEditor_20250124 } from './tool/text-editor_20250124';
|
|
10
|
+
import { textEditor_20250429 } from './tool/text-editor_20250429';
|
|
11
|
+
import { textEditor_20250728 } from './tool/text-editor_20250728';
|
|
12
|
+
import { toolSearchBm25_20251119 } from './tool/tool-search-bm25_20251119';
|
|
13
|
+
import { toolSearchRegex_20251119 } from './tool/tool-search-regex_20251119';
|
|
14
|
+
import { webFetch_20250910 } from './tool/web-fetch-20250910';
|
|
15
|
+
import { webSearch_20250305 } from './tool/web-search_20250305';
|
|
16
|
+
|
|
17
|
+
export const anthropicTools = {
|
|
18
|
+
/**
|
|
19
|
+
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
20
|
+
* allowing system operations, script execution, and command-line automation.
|
|
21
|
+
*
|
|
22
|
+
* Image results are supported.
|
|
23
|
+
*/
|
|
24
|
+
bash_20241022,
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
28
|
+
* allowing system operations, script execution, and command-line automation.
|
|
29
|
+
*
|
|
30
|
+
* Image results are supported.
|
|
31
|
+
*/
|
|
32
|
+
bash_20250124,
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Claude can analyze data, create visualizations, perform complex calculations,
|
|
36
|
+
* run system commands, create and edit files, and process uploaded files directly within
|
|
37
|
+
* the API conversation.
|
|
38
|
+
*
|
|
39
|
+
* The code execution tool allows Claude to run Bash commands and manipulate files,
|
|
40
|
+
* including writing code, in a secure, sandboxed environment.
|
|
41
|
+
*/
|
|
42
|
+
codeExecution_20250522,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Claude can analyze data, create visualizations, perform complex calculations,
|
|
46
|
+
* run system commands, create and edit files, and process uploaded files directly within
|
|
47
|
+
* the API conversation.
|
|
48
|
+
*
|
|
49
|
+
* The code execution tool allows Claude to run both Python and Bash commands and manipulate files,
|
|
50
|
+
* including writing code, in a secure, sandboxed environment.
|
|
51
|
+
*
|
|
52
|
+
* This is the latest version with enhanced Bash support and file operations.
|
|
53
|
+
*/
|
|
54
|
+
codeExecution_20250825,
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Claude can interact with computer environments through the computer use tool, which
|
|
58
|
+
* provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
|
|
59
|
+
*
|
|
60
|
+
* Image results are supported.
|
|
61
|
+
*
|
|
62
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
63
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
64
|
+
* @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
|
|
65
|
+
*/
|
|
66
|
+
computer_20241022,
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Claude can interact with computer environments through the computer use tool, which
|
|
70
|
+
* provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
|
|
71
|
+
*
|
|
72
|
+
* Image results are supported.
|
|
73
|
+
*
|
|
74
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
75
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
76
|
+
* @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
|
|
77
|
+
*/
|
|
78
|
+
computer_20250124,
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The memory tool enables Claude to store and retrieve information across conversations through a memory file directory.
|
|
82
|
+
* Claude can create, read, update, and delete files that persist between sessions,
|
|
83
|
+
* allowing it to build knowledge over time without keeping everything in the context window.
|
|
84
|
+
* The memory tool operates client-side—you control where and how the data is stored through your own infrastructure.
|
|
85
|
+
*
|
|
86
|
+
* Supported models: Claude Sonnet 4.5, Claude Sonnet 4, Claude Opus 4.1, Claude Opus 4.
|
|
87
|
+
*/
|
|
88
|
+
memory_20250818,
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
92
|
+
* helping you debug, fix, and improve your code or other text documents. This allows Claude
|
|
93
|
+
* to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
|
|
94
|
+
*
|
|
95
|
+
* Supported models: Claude Sonnet 3.5
|
|
96
|
+
*/
|
|
97
|
+
textEditor_20241022,
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
101
|
+
* helping you debug, fix, and improve your code or other text documents. This allows Claude
|
|
102
|
+
* to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
|
|
103
|
+
*
|
|
104
|
+
* Supported models: Claude Sonnet 3.7
|
|
105
|
+
*/
|
|
106
|
+
textEditor_20250124,
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
110
|
+
* helping you debug, fix, and improve your code or other text documents. This allows Claude
|
|
111
|
+
* to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
|
|
112
|
+
*
|
|
113
|
+
* Note: This version does not support the "undo_edit" command.
|
|
114
|
+
*
|
|
115
|
+
* @deprecated Use textEditor_20250728 instead
|
|
116
|
+
*/
|
|
117
|
+
textEditor_20250429,
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
121
|
+
* helping you debug, fix, and improve your code or other text documents. This allows Claude
|
|
122
|
+
* to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
|
|
123
|
+
*
|
|
124
|
+
* Note: This version does not support the "undo_edit" command and adds optional max_characters parameter.
|
|
125
|
+
*
|
|
126
|
+
* Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1
|
|
127
|
+
*
|
|
128
|
+
* @param maxCharacters - Optional maximum number of characters to view in the file
|
|
129
|
+
*/
|
|
130
|
+
textEditor_20250728,
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates a web fetch tool that gives Claude direct access to real-time web content.
|
|
134
|
+
*
|
|
135
|
+
* @param maxUses - The max_uses parameter limits the number of web fetches performed
|
|
136
|
+
* @param allowedDomains - Only fetch from these domains
|
|
137
|
+
* @param blockedDomains - Never fetch from these domains
|
|
138
|
+
* @param citations - Unlike web search where citations are always enabled, citations are optional for web fetch. Set "citations": {"enabled": true} to enable Claude to cite specific passages from fetched documents.
|
|
139
|
+
* @param maxContentTokens - The max_content_tokens parameter limits the amount of content that will be included in the context.
|
|
140
|
+
*/
|
|
141
|
+
webFetch_20250910,
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
145
|
+
*
|
|
146
|
+
* @param maxUses - Maximum number of web searches Claude can perform during the conversation.
|
|
147
|
+
* @param allowedDomains - Optional list of domains that Claude is allowed to search.
|
|
148
|
+
* @param blockedDomains - Optional list of domains that Claude should avoid when searching.
|
|
149
|
+
* @param userLocation - Optional user location information to provide geographically relevant search results.
|
|
150
|
+
*/
|
|
151
|
+
webSearch_20250305,
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Creates a tool search tool that uses regex patterns to find tools.
|
|
155
|
+
*
|
|
156
|
+
* The tool search tool enables Claude to work with hundreds or thousands of tools
|
|
157
|
+
* by dynamically discovering and loading them on-demand. Instead of loading all
|
|
158
|
+
* tool definitions into the context window upfront, Claude searches your tool
|
|
159
|
+
* catalog and loads only the tools it needs.
|
|
160
|
+
*
|
|
161
|
+
* Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools
|
|
162
|
+
* to mark them for deferred loading.
|
|
163
|
+
*
|
|
164
|
+
* Supported models: Claude Opus 4.5, Claude Sonnet 4.5
|
|
165
|
+
*/
|
|
166
|
+
toolSearchRegex_20251119,
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Creates a tool search tool that uses BM25 (natural language) to find tools.
|
|
170
|
+
*
|
|
171
|
+
* The tool search tool enables Claude to work with hundreds or thousands of tools
|
|
172
|
+
* by dynamically discovering and loading them on-demand. Instead of loading all
|
|
173
|
+
* tool definitions into the context window upfront, Claude searches your tool
|
|
174
|
+
* catalog and loads only the tools it needs.
|
|
175
|
+
*
|
|
176
|
+
* Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools
|
|
177
|
+
* to mark them for deferred loading.
|
|
178
|
+
*
|
|
179
|
+
* Supported models: Claude Opus 4.5, Claude Sonnet 4.5
|
|
180
|
+
*/
|
|
181
|
+
toolSearchBm25_20251119,
|
|
182
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { LanguageModelV3Usage } from '@ai-sdk/provider';
|
|
2
|
+
|
|
3
|
+
export type AnthropicMessagesUsage = {
|
|
4
|
+
input_tokens: number;
|
|
5
|
+
output_tokens: number;
|
|
6
|
+
cache_creation_input_tokens?: number | null;
|
|
7
|
+
cache_read_input_tokens?: number | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function convertAnthropicMessagesUsage(
|
|
11
|
+
usage: AnthropicMessagesUsage,
|
|
12
|
+
): LanguageModelV3Usage {
|
|
13
|
+
const inputTokens = usage.input_tokens;
|
|
14
|
+
const outputTokens = usage.output_tokens;
|
|
15
|
+
const cacheCreationTokens = usage.cache_creation_input_tokens ?? 0;
|
|
16
|
+
const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
inputTokens: {
|
|
20
|
+
total: inputTokens + cacheCreationTokens + cacheReadTokens,
|
|
21
|
+
noCache: inputTokens,
|
|
22
|
+
cacheRead: cacheReadTokens,
|
|
23
|
+
cacheWrite: cacheCreationTokens,
|
|
24
|
+
},
|
|
25
|
+
outputTokens: {
|
|
26
|
+
total: outputTokens,
|
|
27
|
+
text: undefined,
|
|
28
|
+
reasoning: undefined,
|
|
29
|
+
},
|
|
30
|
+
raw: usage,
|
|
31
|
+
};
|
|
32
|
+
}
|