@effect/ai-anthropic 0.16.2 → 0.17.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/AnthropicTool/package.json +6 -0
- package/dist/cjs/AnthropicClient.js +285 -192
- package/dist/cjs/AnthropicClient.js.map +1 -1
- package/dist/cjs/AnthropicLanguageModel.js +1036 -311
- package/dist/cjs/AnthropicLanguageModel.js.map +1 -1
- package/dist/cjs/AnthropicTokenizer.js +8 -6
- package/dist/cjs/AnthropicTokenizer.js.map +1 -1
- package/dist/cjs/AnthropicTool.js +461 -0
- package/dist/cjs/AnthropicTool.js.map +1 -0
- package/dist/cjs/Generated.js +3507 -1230
- package/dist/cjs/Generated.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/internal/utilities.js +11 -5
- package/dist/cjs/internal/utilities.js.map +1 -1
- package/dist/dts/AnthropicClient.d.ts +675 -17
- package/dist/dts/AnthropicClient.d.ts.map +1 -1
- package/dist/dts/AnthropicLanguageModel.d.ts +217 -26
- package/dist/dts/AnthropicLanguageModel.d.ts.map +1 -1
- package/dist/dts/AnthropicTokenizer.d.ts +1 -1
- package/dist/dts/AnthropicTokenizer.d.ts.map +1 -1
- package/dist/dts/AnthropicTool.d.ts +523 -0
- package/dist/dts/AnthropicTool.d.ts.map +1 -0
- package/dist/dts/Generated.d.ts +7863 -3496
- package/dist/dts/Generated.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/AnthropicClient.js +268 -190
- package/dist/esm/AnthropicClient.js.map +1 -1
- package/dist/esm/AnthropicLanguageModel.js +1032 -306
- package/dist/esm/AnthropicLanguageModel.js.map +1 -1
- package/dist/esm/AnthropicTokenizer.js +8 -6
- package/dist/esm/AnthropicTokenizer.js.map +1 -1
- package/dist/esm/AnthropicTool.js +452 -0
- package/dist/esm/AnthropicTool.js.map +1 -0
- package/dist/esm/Generated.js +3492 -1063
- package/dist/esm/Generated.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/utilities.js +10 -4
- package/dist/esm/internal/utilities.js.map +1 -1
- package/package.json +11 -3
- package/src/AnthropicClient.ts +710 -372
- package/src/AnthropicLanguageModel.ts +1416 -345
- package/src/AnthropicTokenizer.ts +14 -23
- package/src/AnthropicTool.ts +553 -0
- package/src/Generated.ts +4165 -1681
- package/src/index.ts +5 -0
- package/src/internal/utilities.ts +15 -7
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
4
|
import { getTokenizer } from "@anthropic-ai/tokenizer"
|
|
5
|
-
import
|
|
6
|
-
import type * as
|
|
5
|
+
import * as AiError from "@effect/ai/AiError"
|
|
6
|
+
import type * as Prompt from "@effect/ai/Prompt"
|
|
7
7
|
import * as Tokenizer from "@effect/ai/Tokenizer"
|
|
8
8
|
import * as Arr from "effect/Array"
|
|
9
9
|
import * as Effect from "effect/Effect"
|
|
@@ -15,34 +15,25 @@ import * as Option from "effect/Option"
|
|
|
15
15
|
* @category Constructors
|
|
16
16
|
*/
|
|
17
17
|
export const make = Tokenizer.make({
|
|
18
|
-
tokenize(
|
|
18
|
+
tokenize(prompt) {
|
|
19
19
|
return Effect.try({
|
|
20
20
|
try: () => {
|
|
21
21
|
const tokenizer = getTokenizer()
|
|
22
|
-
const text = Arr.flatMap(
|
|
22
|
+
const text = Arr.flatMap(prompt.content, (message) =>
|
|
23
23
|
Arr.filterMap(
|
|
24
|
-
message.
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
24
|
+
message.content as Array<
|
|
25
|
+
| Prompt.AssistantMessagePart
|
|
26
|
+
| Prompt.ToolMessagePart
|
|
27
|
+
| Prompt.UserMessagePart
|
|
28
28
|
>,
|
|
29
29
|
(part) => {
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
part._tag === "ImagePart" ||
|
|
34
|
-
part._tag === "ImageUrlPart" ||
|
|
35
|
-
part._tag === "ReasoningPart" ||
|
|
36
|
-
part._tag === "RedactedReasoningPart"
|
|
37
|
-
) return Option.none()
|
|
30
|
+
if (part.type === "file" || part.type === "reasoning") {
|
|
31
|
+
return Option.none()
|
|
32
|
+
}
|
|
38
33
|
return Option.some(
|
|
39
|
-
part.
|
|
34
|
+
part.type === "text"
|
|
40
35
|
? part.text
|
|
41
|
-
: JSON.stringify(
|
|
42
|
-
part._tag === "ToolCallPart"
|
|
43
|
-
? part.params :
|
|
44
|
-
part.result
|
|
45
|
-
)
|
|
36
|
+
: JSON.stringify(part.type === "tool-call" ? part.params : part.result)
|
|
46
37
|
)
|
|
47
38
|
}
|
|
48
39
|
)).join("")
|
|
@@ -51,7 +42,7 @@ export const make = Tokenizer.make({
|
|
|
51
42
|
return Array.from(encoded)
|
|
52
43
|
},
|
|
53
44
|
catch: (cause) =>
|
|
54
|
-
new AiError({
|
|
45
|
+
new AiError.UnknownError({
|
|
55
46
|
module: "AnthropicTokenizer",
|
|
56
47
|
method: "tokenize",
|
|
57
48
|
description: "Could not tokenize",
|
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Tool from "@effect/ai/Tool"
|
|
5
|
+
import * as Schema from "effect/Schema"
|
|
6
|
+
import * as Struct from "effect/Struct"
|
|
7
|
+
import * as Generated from "./Generated.js"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
* @category Schemas
|
|
12
|
+
*/
|
|
13
|
+
export const ProviderDefinedTools: Schema.Union<[
|
|
14
|
+
typeof Generated.BetaBashTool20241022,
|
|
15
|
+
typeof Generated.BetaBashTool20250124,
|
|
16
|
+
typeof Generated.BetaCodeExecutionTool20250522,
|
|
17
|
+
typeof Generated.BetaComputerUseTool20241022,
|
|
18
|
+
typeof Generated.BetaComputerUseTool20250124,
|
|
19
|
+
typeof Generated.BetaTextEditor20241022,
|
|
20
|
+
typeof Generated.BetaTextEditor20250124,
|
|
21
|
+
typeof Generated.BetaTextEditor20250429,
|
|
22
|
+
typeof Generated.BetaTextEditor20250728,
|
|
23
|
+
typeof Generated.BetaWebSearchTool20250305
|
|
24
|
+
]> = Schema.Union(
|
|
25
|
+
Generated.BetaBashTool20241022,
|
|
26
|
+
Generated.BetaBashTool20250124,
|
|
27
|
+
Generated.BetaCodeExecutionTool20250522,
|
|
28
|
+
Generated.BetaComputerUseTool20241022,
|
|
29
|
+
Generated.BetaComputerUseTool20250124,
|
|
30
|
+
Generated.BetaTextEditor20241022,
|
|
31
|
+
Generated.BetaTextEditor20250124,
|
|
32
|
+
Generated.BetaTextEditor20250429,
|
|
33
|
+
Generated.BetaTextEditor20250728,
|
|
34
|
+
Generated.BetaWebSearchTool20250305
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @since 1.0.0
|
|
39
|
+
* @category Schemas
|
|
40
|
+
*/
|
|
41
|
+
export type ProviderDefinedTools = typeof ProviderDefinedTools.Type
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
* @category Tools
|
|
46
|
+
*/
|
|
47
|
+
export const Bash_20241022 = Tool.providerDefined({
|
|
48
|
+
id: "anthropic.bash_20241022",
|
|
49
|
+
toolkitName: "AnthropicBash",
|
|
50
|
+
providerName: "bash",
|
|
51
|
+
args: {},
|
|
52
|
+
requiresHandler: true,
|
|
53
|
+
success: Schema.String,
|
|
54
|
+
parameters: {
|
|
55
|
+
/**
|
|
56
|
+
* The Bash command to run.
|
|
57
|
+
*/
|
|
58
|
+
command: Schema.NonEmptyString,
|
|
59
|
+
/**
|
|
60
|
+
* If `true`, restart the Bash session.
|
|
61
|
+
*/
|
|
62
|
+
restart: Schema.optional(Schema.Boolean)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
* @category Tools
|
|
69
|
+
*/
|
|
70
|
+
export const Bash_20250124 = Tool.providerDefined({
|
|
71
|
+
id: "anthropic.bash_20250124",
|
|
72
|
+
toolkitName: "AnthropicBash",
|
|
73
|
+
providerName: "bash",
|
|
74
|
+
args: {},
|
|
75
|
+
requiresHandler: true,
|
|
76
|
+
success: Schema.String,
|
|
77
|
+
parameters: {
|
|
78
|
+
/**
|
|
79
|
+
* The Bash command to run.
|
|
80
|
+
*/
|
|
81
|
+
command: Schema.NonEmptyString,
|
|
82
|
+
/**
|
|
83
|
+
* If `true`, restart the Bash session.
|
|
84
|
+
*/
|
|
85
|
+
restart: Schema.optional(Schema.Boolean)
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @since 1.0.0
|
|
91
|
+
* @category Tools
|
|
92
|
+
*/
|
|
93
|
+
export const CodeExecution_20250522 = Tool.providerDefined({
|
|
94
|
+
id: "anthropic.code_execution_20250522",
|
|
95
|
+
toolkitName: "AnthropicCodeExecution",
|
|
96
|
+
providerName: "code_execution",
|
|
97
|
+
args: Struct.omit(Generated.BetaCodeExecutionTool20250522.fields, "name", "type"),
|
|
98
|
+
success: Generated.BetaResponseCodeExecutionResultBlock,
|
|
99
|
+
failure: Generated.BetaResponseCodeExecutionToolResultError
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @since 1.0.0
|
|
104
|
+
* @category Tools
|
|
105
|
+
*/
|
|
106
|
+
export const CodeExecution_20250825 = Tool.providerDefined({
|
|
107
|
+
id: "anthropic.code_execution_20250825",
|
|
108
|
+
toolkitName: "AnthropicCodeExecution",
|
|
109
|
+
providerName: "code_execution",
|
|
110
|
+
args: Struct.omit(Generated.BetaCodeExecutionTool20250825.fields, "name", "type"),
|
|
111
|
+
success: Schema.Union(
|
|
112
|
+
Generated.BetaResponseBashCodeExecutionResultBlock,
|
|
113
|
+
Generated.BetaResponseTextEditorCodeExecutionViewResultBlock,
|
|
114
|
+
Generated.BetaResponseTextEditorCodeExecutionCreateResultBlock,
|
|
115
|
+
Generated.BetaResponseTextEditorCodeExecutionStrReplaceResultBlock
|
|
116
|
+
),
|
|
117
|
+
failure: Schema.Union(
|
|
118
|
+
Generated.BetaResponseCodeExecutionToolResultError,
|
|
119
|
+
Generated.BetaResponseTextEditorCodeExecutionToolResultError
|
|
120
|
+
)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @since 1.0.0
|
|
125
|
+
* @category Models
|
|
126
|
+
*/
|
|
127
|
+
export const Coordinate = Schema.Tuple(Schema.Number, Schema.Number)
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Allow Claude to interact with computer environments through the computer use
|
|
131
|
+
* tool, which provides screenshot capabilities and mouse/keyboard control for
|
|
132
|
+
* autonomous desktop interaction.
|
|
133
|
+
*
|
|
134
|
+
* @since 1.0.0
|
|
135
|
+
* @category Tools
|
|
136
|
+
*/
|
|
137
|
+
export const ComputerUse_20241022 = Tool.providerDefined({
|
|
138
|
+
id: "anthropic.computer_use_20241022",
|
|
139
|
+
toolkitName: "AnthropicComputerUse",
|
|
140
|
+
providerName: "computer",
|
|
141
|
+
args: Struct.omit(Generated.BetaComputerUseTool20241022.fields, "name", "type"),
|
|
142
|
+
requiresHandler: true,
|
|
143
|
+
success: Schema.String,
|
|
144
|
+
parameters: {
|
|
145
|
+
/**
|
|
146
|
+
* The action to perform. The available actions are:
|
|
147
|
+
* - `screenshot`: Take a screenshot of the screen.
|
|
148
|
+
* - `left_click`: Click the left mouse button at the specified (x, y) pixel
|
|
149
|
+
* coordinate on the screen. You can also include a key combination to
|
|
150
|
+
* hold down while clicking using the `text` parameter.
|
|
151
|
+
* - `type`: Type a string of text on the keyboard.
|
|
152
|
+
* - `key`: Press a key or key-combination on the keyboard.
|
|
153
|
+
* - This supports xdotool's `key` syntax.
|
|
154
|
+
* - Examples: "a", "Return", "alt+Tab", "ctrl+s", "Up", "KP_0" (for the
|
|
155
|
+
* numpad 0 key).
|
|
156
|
+
* - `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on
|
|
157
|
+
* the screen.
|
|
158
|
+
*/
|
|
159
|
+
action: Schema.Literal(
|
|
160
|
+
"screenshot",
|
|
161
|
+
"left_click",
|
|
162
|
+
"type",
|
|
163
|
+
"key",
|
|
164
|
+
"mouse_move"
|
|
165
|
+
),
|
|
166
|
+
/**
|
|
167
|
+
* The x (pixels from the left edge) and y (pixels from the top edge)
|
|
168
|
+
* coordinates to move the mouse to. Required only by `action=mouse_move`.
|
|
169
|
+
*/
|
|
170
|
+
coordinate: Schema.optional(Coordinate),
|
|
171
|
+
/**
|
|
172
|
+
* Required only by `action=type` and `action=key`.
|
|
173
|
+
*/
|
|
174
|
+
text: Schema.optional(Schema.String)
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Allow Claude to interact with computer environments through the computer use
|
|
180
|
+
* tool, which provides screenshot capabilities and mouse/keyboard control for
|
|
181
|
+
* autonomous desktop interaction.
|
|
182
|
+
*
|
|
183
|
+
* @since 1.0.0
|
|
184
|
+
* @category Tools
|
|
185
|
+
*/
|
|
186
|
+
export const ComputerUse_20250124 = Tool.providerDefined({
|
|
187
|
+
id: "anthropic.computer_use_20250124",
|
|
188
|
+
toolkitName: "AnthropicComputerUse",
|
|
189
|
+
providerName: "computer",
|
|
190
|
+
args: Struct.omit(Generated.BetaComputerUseTool20241022.fields, "name", "type"),
|
|
191
|
+
requiresHandler: true,
|
|
192
|
+
success: Schema.String,
|
|
193
|
+
parameters: {
|
|
194
|
+
/**
|
|
195
|
+
* The action to perform. The available actions are:
|
|
196
|
+
* - `screenshot`: Take a screenshot of the screen.
|
|
197
|
+
* - `left_click`: Click the left mouse button at the specified (x, y) pixel
|
|
198
|
+
* coordinate on the screen. You can also include a key combination to
|
|
199
|
+
* hold down while clicking using the `text` parameter.
|
|
200
|
+
* - `type`: Type a string of text on the keyboard.
|
|
201
|
+
* - `key`: Press a key or key-combination on the keyboard.
|
|
202
|
+
* - This supports xdotool's `key` syntax.
|
|
203
|
+
* - Examples: "a", "Return", "alt+Tab", "ctrl+s", "Up", "KP_0" (for the
|
|
204
|
+
* numpad 0 key).
|
|
205
|
+
* - `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on
|
|
206
|
+
* - `scroll`: Scroll the screen in a specified direction by a specified
|
|
207
|
+
* amount of clicks of the scroll wheel, at the specified (x, y) pixel
|
|
208
|
+
* coordinate. DO NOT use PageUp/PageDown to scroll.
|
|
209
|
+
* - `left_click_drag`: Click and drag the cursor from `start_coordinate`
|
|
210
|
+
* to a specified (x, y) pixel coordinate on the screen.
|
|
211
|
+
* the screen.
|
|
212
|
+
* - `middle_click`: Click the middle mouse button at the specified (x, y)
|
|
213
|
+
* pixel coordinate on the screen.
|
|
214
|
+
* - `right_click`: Click the right mouse button at the specified (x, y)
|
|
215
|
+
* pixel coordinate on the screen.
|
|
216
|
+
* - `double_click`: Double-click the left mouse button at the specified
|
|
217
|
+
* (x, y) pixel coordinate on the screen.
|
|
218
|
+
* - `triple_click`: Triple-click the left mouse button at the specified
|
|
219
|
+
* (x, y) pixel coordinate on the screen.
|
|
220
|
+
* - `left_mouse_down`: Press the left mouse button.
|
|
221
|
+
* - `left_mouse_up`: Release the left mouse button.
|
|
222
|
+
* - `hold_key`: Hold down a key or multiple keys for a specified duration
|
|
223
|
+
* (in seconds). Supports the same syntax as `key`.
|
|
224
|
+
* - `wait`: Wait for a specified duration (in seconds).
|
|
225
|
+
*/
|
|
226
|
+
action: Schema.Literal(
|
|
227
|
+
"screenshot",
|
|
228
|
+
"left_click",
|
|
229
|
+
"type",
|
|
230
|
+
"key",
|
|
231
|
+
"mouse_move",
|
|
232
|
+
"scroll",
|
|
233
|
+
"left_click_drag",
|
|
234
|
+
"middle_click",
|
|
235
|
+
"right_click",
|
|
236
|
+
"double_click",
|
|
237
|
+
"triple_click",
|
|
238
|
+
"left_mouse_down",
|
|
239
|
+
"left_mouse_up",
|
|
240
|
+
"hold_key",
|
|
241
|
+
"wait"
|
|
242
|
+
),
|
|
243
|
+
/**
|
|
244
|
+
* The x (pixels from the left edge) and y (pixels from the top edge)
|
|
245
|
+
* coordinates to move the mouse to. Required only by `action=mouse_move`
|
|
246
|
+
* and `action=left_click_drag`.
|
|
247
|
+
*/
|
|
248
|
+
coordinate: Schema.optional(Coordinate),
|
|
249
|
+
/**
|
|
250
|
+
* The x (pixels from the left edge) and y (pixels from the top edge)
|
|
251
|
+
* coordinates to start the drag from. Required only by
|
|
252
|
+
* `action=left_click_drag`.
|
|
253
|
+
*/
|
|
254
|
+
start_coordinate: Schema.optional(Coordinate),
|
|
255
|
+
/**
|
|
256
|
+
* Required only by `action=type`, `action=key`, and `action=hold_key`. Can
|
|
257
|
+
* also be used by click or scroll actions to hold down keys while clicking
|
|
258
|
+
* or scrolling.
|
|
259
|
+
*/
|
|
260
|
+
text: Schema.optional(Schema.String),
|
|
261
|
+
/**
|
|
262
|
+
* The direction to scroll the screen. Required only by `action=scroll`.
|
|
263
|
+
*/
|
|
264
|
+
scroll_direction: Schema.optional(Schema.Literal("up", "down", "left", "right")),
|
|
265
|
+
/**
|
|
266
|
+
* The number of "clicks" of the scroll wheel to scroll. Required only by
|
|
267
|
+
* `action=scroll`.
|
|
268
|
+
*/
|
|
269
|
+
scroll_amount: Schema.optional(Schema.Number),
|
|
270
|
+
/**
|
|
271
|
+
* The duration to hold the key down for. Required only by `action=hold_key`
|
|
272
|
+
* and `action=wait`.
|
|
273
|
+
*/
|
|
274
|
+
duration: Schema.optional(Schema.Number)
|
|
275
|
+
}
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Allow Claude to directly interact with your files, providing hands-on
|
|
280
|
+
* assistance rather than just suggesting changes.
|
|
281
|
+
*
|
|
282
|
+
* @since 1.0.0
|
|
283
|
+
* @category Tools
|
|
284
|
+
*/
|
|
285
|
+
export const TextEditor_20241022 = Tool.providerDefined({
|
|
286
|
+
id: "anthropic.text_editor_20241022",
|
|
287
|
+
toolkitName: "AnthropicTextEditor",
|
|
288
|
+
providerName: "str_replace_editor",
|
|
289
|
+
args: {},
|
|
290
|
+
requiresHandler: true,
|
|
291
|
+
parameters: {
|
|
292
|
+
/**
|
|
293
|
+
* The command to run.
|
|
294
|
+
*/
|
|
295
|
+
command: Schema.Literal(
|
|
296
|
+
"view",
|
|
297
|
+
"create",
|
|
298
|
+
"str_replace",
|
|
299
|
+
"insert",
|
|
300
|
+
"undo_edit"
|
|
301
|
+
),
|
|
302
|
+
/**
|
|
303
|
+
* Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
|
|
304
|
+
*/
|
|
305
|
+
path: Schema.String,
|
|
306
|
+
/**
|
|
307
|
+
* Required parameter of `create` command, with the content of the file to
|
|
308
|
+
* be created.
|
|
309
|
+
*/
|
|
310
|
+
file_text: Schema.optional(Schema.String),
|
|
311
|
+
/**
|
|
312
|
+
* Required parameter of `insert` command. The `new_str` will be inserted
|
|
313
|
+
* AFTER the line `insert_line` of `path`.
|
|
314
|
+
*/
|
|
315
|
+
insert_line: Schema.optional(Schema.Number),
|
|
316
|
+
/**
|
|
317
|
+
* Optional parameter of `str_replace` command containing the new string (if
|
|
318
|
+
* not given, no string will be added). Required parameter of `insert`
|
|
319
|
+
* command containing the string to insert.
|
|
320
|
+
*/
|
|
321
|
+
new_str: Schema.optional(Schema.String),
|
|
322
|
+
/**
|
|
323
|
+
* Required parameter of `str_replace` command containing the string in
|
|
324
|
+
* `path` to replace.
|
|
325
|
+
*/
|
|
326
|
+
old_str: Schema.optional(Schema.String),
|
|
327
|
+
/**
|
|
328
|
+
* Optional parameter of `view` command when `path` points to a file. If
|
|
329
|
+
* none is given, the full file is shown. If provided, the file will be
|
|
330
|
+
* shown in the indicated line number range, e.g. [11, 12] will show lines
|
|
331
|
+
* 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all
|
|
332
|
+
* lines from `start_line` to the end of the file.
|
|
333
|
+
*/
|
|
334
|
+
view_range: Schema.optional(Schema.Array(Schema.Number))
|
|
335
|
+
}
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Allow Claude to directly interact with your files, providing hands-on
|
|
340
|
+
* assistance rather than just suggesting changes.
|
|
341
|
+
*
|
|
342
|
+
* @since 1.0.0
|
|
343
|
+
* @category Tools
|
|
344
|
+
*/
|
|
345
|
+
export const TextEditor_20250124 = Tool.providerDefined({
|
|
346
|
+
id: "anthropic.text_editor_20250124",
|
|
347
|
+
toolkitName: "AnthropicTextEditor",
|
|
348
|
+
providerName: "str_replace_editor",
|
|
349
|
+
args: {},
|
|
350
|
+
requiresHandler: true,
|
|
351
|
+
parameters: {
|
|
352
|
+
/**
|
|
353
|
+
* The command to run.
|
|
354
|
+
*/
|
|
355
|
+
command: Schema.Literal(
|
|
356
|
+
"view",
|
|
357
|
+
"create",
|
|
358
|
+
"str_replace",
|
|
359
|
+
"insert",
|
|
360
|
+
"undo_edit"
|
|
361
|
+
),
|
|
362
|
+
/**
|
|
363
|
+
* Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
|
|
364
|
+
*/
|
|
365
|
+
path: Schema.String,
|
|
366
|
+
/**
|
|
367
|
+
* Required parameter of `create` command, with the content of the file to
|
|
368
|
+
* be created.
|
|
369
|
+
*/
|
|
370
|
+
file_text: Schema.optional(Schema.String),
|
|
371
|
+
/**
|
|
372
|
+
* Required parameter of `insert` command. The `new_str` will be inserted
|
|
373
|
+
* AFTER the line `insert_line` of `path`.
|
|
374
|
+
*/
|
|
375
|
+
insert_line: Schema.optional(Schema.Number),
|
|
376
|
+
/**
|
|
377
|
+
* Optional parameter of `str_replace` command containing the new string (if
|
|
378
|
+
* not given, no string will be added). Required parameter of `insert`
|
|
379
|
+
* command containing the string to insert.
|
|
380
|
+
*/
|
|
381
|
+
new_str: Schema.optional(Schema.String),
|
|
382
|
+
/**
|
|
383
|
+
* Required parameter of `str_replace` command containing the string in
|
|
384
|
+
* `path` to replace.
|
|
385
|
+
*/
|
|
386
|
+
old_str: Schema.optional(Schema.String),
|
|
387
|
+
/**
|
|
388
|
+
* Optional parameter of `view` command when `path` points to a file. If
|
|
389
|
+
* none is given, the full file is shown. If provided, the file will be
|
|
390
|
+
* shown in the indicated line number range, e.g. [11, 12] will show lines
|
|
391
|
+
* 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all
|
|
392
|
+
* lines from `start_line` to the end of the file.
|
|
393
|
+
*/
|
|
394
|
+
view_range: Schema.optional(Schema.Array(Schema.Number))
|
|
395
|
+
}
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Allow Claude to directly interact with your files, providing hands-on
|
|
400
|
+
* assistance rather than just suggesting changes.
|
|
401
|
+
*
|
|
402
|
+
* @since 1.0.0
|
|
403
|
+
* @category Tools
|
|
404
|
+
*/
|
|
405
|
+
export const TextEditor_20250429 = Tool.providerDefined({
|
|
406
|
+
id: "anthropic.text_editor_20250429",
|
|
407
|
+
toolkitName: "AnthropicTextEditor",
|
|
408
|
+
providerName: "str_replace_based_edit_tool",
|
|
409
|
+
args: {},
|
|
410
|
+
requiresHandler: true,
|
|
411
|
+
parameters: {
|
|
412
|
+
/**
|
|
413
|
+
* The command to run.
|
|
414
|
+
*/
|
|
415
|
+
command: Schema.Literal(
|
|
416
|
+
"view",
|
|
417
|
+
"create",
|
|
418
|
+
"str_replace",
|
|
419
|
+
"insert"
|
|
420
|
+
),
|
|
421
|
+
/**
|
|
422
|
+
* Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
|
|
423
|
+
*/
|
|
424
|
+
path: Schema.String,
|
|
425
|
+
/**
|
|
426
|
+
* Required parameter of `create` command, with the content of the file to
|
|
427
|
+
* be created.
|
|
428
|
+
*/
|
|
429
|
+
file_text: Schema.optional(Schema.String),
|
|
430
|
+
/**
|
|
431
|
+
* Required parameter of `insert` command. The `new_str` will be inserted
|
|
432
|
+
* AFTER the line `insert_line` of `path`.
|
|
433
|
+
*/
|
|
434
|
+
insert_line: Schema.optional(Schema.Number),
|
|
435
|
+
/**
|
|
436
|
+
* Optional parameter of `str_replace` command containing the new string (if
|
|
437
|
+
* not given, no string will be added). Required parameter of `insert`
|
|
438
|
+
* command containing the string to insert.
|
|
439
|
+
*/
|
|
440
|
+
new_str: Schema.optional(Schema.String),
|
|
441
|
+
/**
|
|
442
|
+
* Required parameter of `str_replace` command containing the string in
|
|
443
|
+
* `path` to replace.
|
|
444
|
+
*/
|
|
445
|
+
old_str: Schema.optional(Schema.String),
|
|
446
|
+
/**
|
|
447
|
+
* Optional parameter of `view` command when `path` points to a file. If
|
|
448
|
+
* none is given, the full file is shown. If provided, the file will be
|
|
449
|
+
* shown in the indicated line number range, e.g. [11, 12] will show lines
|
|
450
|
+
* 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all
|
|
451
|
+
* lines from `start_line` to the end of the file.
|
|
452
|
+
*/
|
|
453
|
+
view_range: Schema.optional(Schema.Array(Schema.Number))
|
|
454
|
+
}
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Allow Claude to directly interact with your files, providing hands-on
|
|
459
|
+
* assistance rather than just suggesting changes.
|
|
460
|
+
*
|
|
461
|
+
* @since 1.0.0
|
|
462
|
+
* @category Tools
|
|
463
|
+
*/
|
|
464
|
+
export const TextEditor_20250728 = Tool.providerDefined({
|
|
465
|
+
id: "anthropic.text_editor_20250728",
|
|
466
|
+
toolkitName: "AnthropicTextEditor",
|
|
467
|
+
providerName: "str_replace_based_edit_tool",
|
|
468
|
+
args: {},
|
|
469
|
+
requiresHandler: true,
|
|
470
|
+
parameters: {
|
|
471
|
+
/**
|
|
472
|
+
* The command to run.
|
|
473
|
+
*/
|
|
474
|
+
command: Schema.Literal(
|
|
475
|
+
"view",
|
|
476
|
+
"create",
|
|
477
|
+
"str_replace",
|
|
478
|
+
"insert"
|
|
479
|
+
),
|
|
480
|
+
/**
|
|
481
|
+
* Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
|
|
482
|
+
*/
|
|
483
|
+
path: Schema.String,
|
|
484
|
+
/**
|
|
485
|
+
* Required parameter of `create` command, with the content of the file to
|
|
486
|
+
* be created.
|
|
487
|
+
*/
|
|
488
|
+
file_text: Schema.optional(Schema.String),
|
|
489
|
+
/**
|
|
490
|
+
* Required parameter of `insert` command. The `new_str` will be inserted
|
|
491
|
+
* AFTER the line `insert_line` of `path`.
|
|
492
|
+
*/
|
|
493
|
+
insert_line: Schema.optional(Schema.Number),
|
|
494
|
+
/**
|
|
495
|
+
* Optional parameter of `str_replace` command containing the new string (if
|
|
496
|
+
* not given, no string will be added). Required parameter of `insert`
|
|
497
|
+
* command containing the string to insert.
|
|
498
|
+
*/
|
|
499
|
+
new_str: Schema.optional(Schema.String),
|
|
500
|
+
/**
|
|
501
|
+
* Required parameter of `str_replace` command containing the string in
|
|
502
|
+
* `path` to replace.
|
|
503
|
+
*/
|
|
504
|
+
old_str: Schema.optional(Schema.String),
|
|
505
|
+
/**
|
|
506
|
+
* Optional parameter of `view` command when `path` points to a file. If
|
|
507
|
+
* none is given, the full file is shown. If provided, the file will be
|
|
508
|
+
* shown in the indicated line number range, e.g. [11, 12] will show lines
|
|
509
|
+
* 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all
|
|
510
|
+
* lines from `start_line` to the end of the file.
|
|
511
|
+
*/
|
|
512
|
+
view_range: Schema.optional(Schema.Array(Schema.Number))
|
|
513
|
+
}
|
|
514
|
+
})
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* @since 1.0.0
|
|
518
|
+
* @category Tools
|
|
519
|
+
*/
|
|
520
|
+
export const WebSearch_20250305 = Tool.providerDefined({
|
|
521
|
+
id: "anthropic.web_search_20250305",
|
|
522
|
+
toolkitName: "AnthropicWebSearch",
|
|
523
|
+
providerName: "web_search",
|
|
524
|
+
args: Struct.omit(Generated.WebSearchTool20250305.fields, "name", "type"),
|
|
525
|
+
success: Schema.Array(Generated.RequestWebSearchResultBlock),
|
|
526
|
+
failure: Generated.ResponseWebSearchToolResultError
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
const ProviderToolNamesMap: Map<ProviderDefinedTools["name"] | (string & {}), string> = new Map([
|
|
530
|
+
["bash", "AnthropicBash"],
|
|
531
|
+
["code_execution", "AnthropicCodeExecution"],
|
|
532
|
+
["computer", "AnthropicComputerUse"],
|
|
533
|
+
["str_replace_based_edit_tool", "AnthropicTextEditor"],
|
|
534
|
+
["str_replace_editor", "AnthropicTextEditor"],
|
|
535
|
+
["web_search", "AnthropicWebSearch"]
|
|
536
|
+
])
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* A helper method which takes in the name of a tool as returned in the response
|
|
540
|
+
* from a large language model provider, and returns either the provider-defined
|
|
541
|
+
* name for of the tool as found in the corresponding `Toolkit`, or `undefined`
|
|
542
|
+
* if the tool name is not a provider-defined tool.
|
|
543
|
+
*
|
|
544
|
+
* For example, if the large language model provider returns the tool name
|
|
545
|
+
* `"web_search"` in a response, calling this method would return `"AnthropicWebSearch"`.
|
|
546
|
+
*
|
|
547
|
+
* This method is primarily exposed for use by other Effect provider
|
|
548
|
+
* integrations which can utilize Anthropic tools (i.e. Amazon Bedrock).
|
|
549
|
+
*
|
|
550
|
+
* @since 1.0.0
|
|
551
|
+
* @category Tool Calling
|
|
552
|
+
*/
|
|
553
|
+
export const getProviderDefinedToolName = (name: string): string | undefined => ProviderToolNamesMap.get(name)
|