@ai-code-agents/environment-utils 0.1.0
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/LICENSE.md +7 -0
- package/README.md +63 -0
- package/dist/index.cjs +529 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +482 -0
- package/dist/index.d.ts +482 -0
- package/dist/index.js +478 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +69 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import { FlexibleSchema } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { ToolExecutionOptions } from 'ai';
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
|
|
5
|
+
declare const ReadFileResult: z.ZodObject<{
|
|
6
|
+
path: z.ZodString;
|
|
7
|
+
content: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type ReadFileResult = z.infer<typeof ReadFileResult>;
|
|
10
|
+
declare const WriteFileResult: z.ZodObject<{
|
|
11
|
+
path: z.ZodString;
|
|
12
|
+
message: z.ZodString;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
type WriteFileResult = z.infer<typeof WriteFileResult>;
|
|
15
|
+
declare const DeleteFileResult: z.ZodObject<{
|
|
16
|
+
path: z.ZodString;
|
|
17
|
+
message: z.ZodString;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
type DeleteFileResult = z.infer<typeof DeleteFileResult>;
|
|
20
|
+
declare const MoveFileResult: z.ZodObject<{
|
|
21
|
+
sourcePath: z.ZodString;
|
|
22
|
+
destinationPath: z.ZodString;
|
|
23
|
+
message: z.ZodString;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
type MoveFileResult = z.infer<typeof MoveFileResult>;
|
|
26
|
+
declare const CopyFileResult: z.ZodObject<{
|
|
27
|
+
sourcePath: z.ZodString;
|
|
28
|
+
destinationPath: z.ZodString;
|
|
29
|
+
message: z.ZodString;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
type CopyFileResult = z.infer<typeof CopyFileResult>;
|
|
32
|
+
declare const RunCommandResult: z.ZodObject<{
|
|
33
|
+
command: z.ZodString;
|
|
34
|
+
exitCode: z.ZodNumber;
|
|
35
|
+
stdout: z.ZodString;
|
|
36
|
+
stderr: z.ZodString;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
type RunCommandResult = z.infer<typeof RunCommandResult>;
|
|
39
|
+
interface FilesystemEnvironmentInterface {
|
|
40
|
+
get name(): string;
|
|
41
|
+
readFile(path: string): Promise<ReadFileResult>;
|
|
42
|
+
writeFile(path: string, content: string): Promise<WriteFileResult>;
|
|
43
|
+
deleteFile(path: string): Promise<DeleteFileResult>;
|
|
44
|
+
moveFile(sourcePath: string, destinationPath: string): Promise<MoveFileResult>;
|
|
45
|
+
copyFile(sourcePath: string, destinationPath: string): Promise<CopyFileResult>;
|
|
46
|
+
}
|
|
47
|
+
interface CommandLineEnvironmentInterface extends FilesystemEnvironmentInterface {
|
|
48
|
+
runCommand(command: string): Promise<RunCommandResult>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Interface for environments that support explicit shutdown/cleanup.
|
|
52
|
+
*
|
|
53
|
+
* Environments implementing this interface may hold resources (connections,
|
|
54
|
+
* sandboxes, containers) that should be released when no longer needed.
|
|
55
|
+
*/
|
|
56
|
+
interface ShutdownableEnvironmentInterface {
|
|
57
|
+
/**
|
|
58
|
+
* Shuts down the environment and releases any held resources.
|
|
59
|
+
*
|
|
60
|
+
* @returns A promise that resolves when shutdown is complete.
|
|
61
|
+
*/
|
|
62
|
+
shutdown(): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
type Environment = FilesystemEnvironmentInterface | CommandLineEnvironmentInterface;
|
|
65
|
+
/**
|
|
66
|
+
* Type guard to check if an environment supports command-line operations.
|
|
67
|
+
*
|
|
68
|
+
* @param env - The environment to check.
|
|
69
|
+
* @returns True if the environment implements CommandLineEnvironmentInterface.
|
|
70
|
+
*/
|
|
71
|
+
declare function isCommandLine(env: Environment): env is CommandLineEnvironmentInterface;
|
|
72
|
+
/**
|
|
73
|
+
* Type guard to check if an environment supports shutdown.
|
|
74
|
+
*
|
|
75
|
+
* @param env - The environment to check.
|
|
76
|
+
* @returns True if the environment implements ShutdownableEnvironmentInterface.
|
|
77
|
+
*/
|
|
78
|
+
declare function isShutdownable(env: Environment): env is Environment & ShutdownableEnvironmentInterface;
|
|
79
|
+
type ModelTextResult = {
|
|
80
|
+
type: 'text';
|
|
81
|
+
value: string;
|
|
82
|
+
};
|
|
83
|
+
type ModelTextPart = {
|
|
84
|
+
type: 'text';
|
|
85
|
+
text: string;
|
|
86
|
+
};
|
|
87
|
+
type ModelMediaPart = {
|
|
88
|
+
type: 'media';
|
|
89
|
+
data: string;
|
|
90
|
+
mediaType: string;
|
|
91
|
+
};
|
|
92
|
+
type ModelToolResultToFormat<ToolInputType, ToolOutputType> = {
|
|
93
|
+
toolCallId: string;
|
|
94
|
+
input: ToolInputType;
|
|
95
|
+
output: ToolOutputType;
|
|
96
|
+
};
|
|
97
|
+
type ModelFormattedToolResult = ModelTextResult | {
|
|
98
|
+
type: 'content';
|
|
99
|
+
value: Array<ModelTextPart | ModelMediaPart>;
|
|
100
|
+
};
|
|
101
|
+
type ToolExample<ToolInputType, ToolOutputType> = {
|
|
102
|
+
input: ToolInputType;
|
|
103
|
+
output: ToolOutputType | string;
|
|
104
|
+
};
|
|
105
|
+
interface ToolInterface<ToolInputType, ToolOutputType> {
|
|
106
|
+
get name(): string;
|
|
107
|
+
get description(): string;
|
|
108
|
+
get inputSchema(): FlexibleSchema<ToolInputType>;
|
|
109
|
+
get outputSchema(): FlexibleSchema<ToolOutputType>;
|
|
110
|
+
execute(input: ToolInputType, options: ToolExecutionOptions): Promise<ToolOutputType>;
|
|
111
|
+
toModelOutput(options: ModelToolResultToFormat<ToolInputType, ToolOutputType>): ModelFormattedToolResult;
|
|
112
|
+
get examples(): Array<ToolExample<ToolInputType, ToolOutputType>>;
|
|
113
|
+
get inputExamples(): Array<{
|
|
114
|
+
input: ToolInputType;
|
|
115
|
+
}>;
|
|
116
|
+
get needsApproval(): boolean;
|
|
117
|
+
}
|
|
118
|
+
interface EnvironmentToolInterface<ToolInputType, ToolOutputType, EnvironmentType> extends ToolInterface<ToolInputType, ToolOutputType> {
|
|
119
|
+
get environment(): EnvironmentType;
|
|
120
|
+
}
|
|
121
|
+
type ToolConfig = {
|
|
122
|
+
name?: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
needsApproval?: boolean;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Base class for a filesystem-based execution environment.
|
|
129
|
+
*/
|
|
130
|
+
declare abstract class FilesystemEnvironmentBase<EnvironmentConfig> implements FilesystemEnvironmentInterface {
|
|
131
|
+
protected _envConfig: EnvironmentConfig;
|
|
132
|
+
/**
|
|
133
|
+
* Constructs a new environment instance.
|
|
134
|
+
*
|
|
135
|
+
* @param config - Environment configuration.
|
|
136
|
+
*/
|
|
137
|
+
constructor(config: EnvironmentConfig);
|
|
138
|
+
/**
|
|
139
|
+
* Gets the environment name.
|
|
140
|
+
*
|
|
141
|
+
* @returns The environment name.
|
|
142
|
+
*/
|
|
143
|
+
abstract get name(): string;
|
|
144
|
+
/**
|
|
145
|
+
* Reads the content of a file at the specified path.
|
|
146
|
+
*
|
|
147
|
+
* @param path - The path to the file to read, relative to the project directory.
|
|
148
|
+
* @returns A promise that resolves to a ReadFileResult.
|
|
149
|
+
*/
|
|
150
|
+
readFile(path: string): Promise<ReadFileResult>;
|
|
151
|
+
/**
|
|
152
|
+
* Writes content to a file at the specified path.
|
|
153
|
+
*
|
|
154
|
+
* If a file is already present at the path, it will be overwritten.
|
|
155
|
+
*
|
|
156
|
+
* @param path - The path to the file to write, relative to the project directory.
|
|
157
|
+
* @param content - The content to write to the file.
|
|
158
|
+
* @returns A promise that resolves to a WriteFileResult.
|
|
159
|
+
*/
|
|
160
|
+
writeFile(path: string, content: string): Promise<WriteFileResult>;
|
|
161
|
+
/**
|
|
162
|
+
* Deletes a file at the specified path.
|
|
163
|
+
*
|
|
164
|
+
* @param path - The path to the file to delete, relative to the project directory.
|
|
165
|
+
* @returns A promise that resolves to a DeleteFileResult.
|
|
166
|
+
*/
|
|
167
|
+
deleteFile(path: string): Promise<DeleteFileResult>;
|
|
168
|
+
/**
|
|
169
|
+
* Moves a file from a source path to a destination path.
|
|
170
|
+
*
|
|
171
|
+
* If a file is already present at the destination path, it will be overwritten.
|
|
172
|
+
*
|
|
173
|
+
* @param sourcePath - The path to the file to move.
|
|
174
|
+
* @param destinationPath - The path to move the file to.
|
|
175
|
+
* @returns A promise that resolves to a MoveFileResult.
|
|
176
|
+
*/
|
|
177
|
+
moveFile(sourcePath: string, destinationPath: string): Promise<MoveFileResult>;
|
|
178
|
+
/**
|
|
179
|
+
* Copies a file from a source path to a destination path.
|
|
180
|
+
*
|
|
181
|
+
* If a file is already present at the destination path, it will be overwritten.
|
|
182
|
+
*
|
|
183
|
+
* @param sourcePath - The path to the file to copy.
|
|
184
|
+
* @param destinationPath - The path to copy the file to.
|
|
185
|
+
* @returns A promise that resolves to a CopyFileResult.
|
|
186
|
+
*/
|
|
187
|
+
copyFile(sourcePath: string, destinationPath: string): Promise<CopyFileResult>;
|
|
188
|
+
/**
|
|
189
|
+
* Checks whether a file exists at the specified path relative to the project directory.
|
|
190
|
+
*
|
|
191
|
+
* @param relativePath - The path to the file to check, relative to the project directory.
|
|
192
|
+
* @returns True if the file exists, false otherwise.
|
|
193
|
+
*/
|
|
194
|
+
protected abstract fileExists(relativePath: string): Promise<boolean>;
|
|
195
|
+
/**
|
|
196
|
+
* Gets the content of a file at the specified path, relative to the project directory.
|
|
197
|
+
*
|
|
198
|
+
* When this method is called, it is guaranteed that the file exists.
|
|
199
|
+
*
|
|
200
|
+
* @param relativePath - The path to the file to read, relative to the project directory.
|
|
201
|
+
* @returns The content of the file.
|
|
202
|
+
*/
|
|
203
|
+
protected abstract readFileContent(relativePath: string): Promise<string>;
|
|
204
|
+
/**
|
|
205
|
+
* Writes content to a file at the specified path, relative to the project directory.
|
|
206
|
+
*
|
|
207
|
+
* This method unconditionally writes the content, even if a file already exists at the path, or if the file is new.
|
|
208
|
+
*
|
|
209
|
+
* @param relativePath - The path to the file to write, relative to the project directory.
|
|
210
|
+
* @param content - The content to write to the file.
|
|
211
|
+
*/
|
|
212
|
+
protected abstract writeFileContent(relativePath: string, content: string): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Deletes a file at the specified path, relative to the project directory.
|
|
215
|
+
*
|
|
216
|
+
* When this method is called, it is guaranteed that the file exists.
|
|
217
|
+
*
|
|
218
|
+
* @param relativePath - The path to the file to delete, relative to the project directory.
|
|
219
|
+
*/
|
|
220
|
+
protected abstract deleteFileContent(relativePath: string): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Moves the content of a file from a source path to a destination path, relative to the project directory.
|
|
223
|
+
*
|
|
224
|
+
* When this method is called, it is guaranteed that the source file exists.
|
|
225
|
+
* This method unconditionally moves the content, even if a file already exists at the destination path.
|
|
226
|
+
*
|
|
227
|
+
* @param relativeSourcePath - The path to the file to move, relative to the project directory.
|
|
228
|
+
* @param relativeDestinationPath - The path to move the file to, relative to the project directory.
|
|
229
|
+
*/
|
|
230
|
+
protected moveFileContent(relativeSourcePath: string, relativeDestinationPath: string): Promise<void>;
|
|
231
|
+
/**
|
|
232
|
+
* Copies the content of a file from a source path to a destination path, relative to the project directory.
|
|
233
|
+
*
|
|
234
|
+
* When this method is called, it is guaranteed that the source file exists.
|
|
235
|
+
* This method unconditionally copies the content, even if a file already exists at the destination path.
|
|
236
|
+
*
|
|
237
|
+
* @param relativeSourcePath - The path to the file to copy, relative to the project directory.
|
|
238
|
+
* @param relativeDestinationPath - The path to copy the file to, relative to the project directory.
|
|
239
|
+
*/
|
|
240
|
+
protected copyFileContent(relativeSourcePath: string, relativeDestinationPath: string): Promise<void>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Base class for a command-line based execution environment.
|
|
245
|
+
*/
|
|
246
|
+
declare abstract class CommandLineEnvironmentBase<EnvironmentConfig> extends FilesystemEnvironmentBase<EnvironmentConfig> implements CommandLineEnvironmentInterface {
|
|
247
|
+
/**
|
|
248
|
+
* Runs a CLI command in environment.
|
|
249
|
+
*
|
|
250
|
+
* @param command - The command to run.
|
|
251
|
+
* @returns A promise that resolves to a RunCommandResult.
|
|
252
|
+
*/
|
|
253
|
+
runCommand(command: string): Promise<RunCommandResult>;
|
|
254
|
+
/**
|
|
255
|
+
* Executes a command in the environment and returns the exit code, stdout, and stderr.
|
|
256
|
+
*
|
|
257
|
+
* @param command - The command to execute.
|
|
258
|
+
* @returns A promise that resolves to a tuple containing the exit code, stdout, and stderr.
|
|
259
|
+
*/
|
|
260
|
+
protected abstract executeCommand(command: string): Promise<[number, string, string]>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Base class for a Unix-like command line execution environment.
|
|
265
|
+
*/
|
|
266
|
+
declare abstract class UnixEnvironmentBase<EnvironmentConfig> extends CommandLineEnvironmentBase<EnvironmentConfig> {
|
|
267
|
+
/**
|
|
268
|
+
* Checks whether a file exists at the specified path relative to the project directory.
|
|
269
|
+
*
|
|
270
|
+
* @param relativePath - The path to the file to check, relative to the project directory.
|
|
271
|
+
* @returns True if the file exists, false otherwise.
|
|
272
|
+
*/
|
|
273
|
+
protected fileExists(relativePath: string): Promise<boolean>;
|
|
274
|
+
/**
|
|
275
|
+
* Gets the content of a file at the specified path, relative to the project directory.
|
|
276
|
+
*
|
|
277
|
+
* When this method is called, it is guaranteed that the file exists.
|
|
278
|
+
*
|
|
279
|
+
* @param relativePath - The path to the file to read, relative to the project directory.
|
|
280
|
+
* @returns The content of the file.
|
|
281
|
+
*/
|
|
282
|
+
protected readFileContent(relativePath: string): Promise<string>;
|
|
283
|
+
/**
|
|
284
|
+
* Writes content to a file at the specified path, relative to the project directory.
|
|
285
|
+
*
|
|
286
|
+
* This method unconditionally writes the content, even if a file already exists at the path, or if the file is new.
|
|
287
|
+
*
|
|
288
|
+
* @param relativePath - The path to the file to write, relative to the project directory.
|
|
289
|
+
* @param content - The content to write to the file.
|
|
290
|
+
*/
|
|
291
|
+
protected writeFileContent(relativePath: string, content: string): Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Deletes a file at the specified path, relative to the project directory.
|
|
294
|
+
*
|
|
295
|
+
* When this method is called, it is guaranteed that the file exists.
|
|
296
|
+
*
|
|
297
|
+
* @param relativePath - The path to the file to delete, relative to the project directory.
|
|
298
|
+
*/
|
|
299
|
+
protected deleteFileContent(relativePath: string): Promise<void>;
|
|
300
|
+
/**
|
|
301
|
+
* Moves the content of a file from a source path to a destination path, relative to the project directory.
|
|
302
|
+
*
|
|
303
|
+
* When this method is called, it is guaranteed that the source file exists.
|
|
304
|
+
* This method unconditionally moves the content, even if a file already exists at the destination path.
|
|
305
|
+
*
|
|
306
|
+
* @param relativeSourcePath - The path to the file to move, relative to the project directory.
|
|
307
|
+
* @param relativeDestinationPath - The path to move the file to, relative to the project directory.
|
|
308
|
+
*/
|
|
309
|
+
protected moveFileContent(relativeSourcePath: string, relativeDestinationPath: string): Promise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Copies the content of a file from a source path to a destination path, relative to the project directory.
|
|
312
|
+
*
|
|
313
|
+
* When this method is called, it is guaranteed that the source file exists.
|
|
314
|
+
* This method unconditionally copies the content, even if a file already exists at the destination path.
|
|
315
|
+
*
|
|
316
|
+
* @param relativeSourcePath - The path to the file to copy, relative to the project directory.
|
|
317
|
+
* @param relativeDestinationPath - The path to copy the file to, relative to the project directory.
|
|
318
|
+
*/
|
|
319
|
+
protected copyFileContent(relativeSourcePath: string, relativeDestinationPath: string): Promise<void>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
type FlexibleInputSchema<T> = ToolInterface<T, unknown>['inputSchema'];
|
|
323
|
+
type FlexibleOutputSchema<T> = ToolInterface<unknown, T>['outputSchema'];
|
|
324
|
+
type ToolMetadata<ToolInputType, ToolOutputType> = {
|
|
325
|
+
name: string;
|
|
326
|
+
description: string;
|
|
327
|
+
inputSchema: FlexibleInputSchema<ToolInputType>;
|
|
328
|
+
outputSchema: FlexibleOutputSchema<ToolOutputType>;
|
|
329
|
+
needsApproval: boolean;
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Base class for a tool.
|
|
333
|
+
*/
|
|
334
|
+
declare abstract class ToolBase<ToolConfig extends ToolConfig, ToolInputType, ToolOutputType> implements ToolInterface<ToolInputType, ToolOutputType> {
|
|
335
|
+
readonly _toolConfig: ToolConfig;
|
|
336
|
+
protected readonly _name: string;
|
|
337
|
+
protected readonly _description: string;
|
|
338
|
+
protected readonly _inputSchema: FlexibleInputSchema<ToolInputType>;
|
|
339
|
+
protected readonly _outputSchema: FlexibleOutputSchema<ToolOutputType>;
|
|
340
|
+
protected readonly _needsApproval: boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Constructs a new tool instance.
|
|
343
|
+
*
|
|
344
|
+
* @param toolConfig - Optional tool config, can be used to override some defaults.
|
|
345
|
+
*/
|
|
346
|
+
constructor(toolConfig?: ToolConfig);
|
|
347
|
+
/**
|
|
348
|
+
* Gets the tool name.
|
|
349
|
+
*
|
|
350
|
+
* @returns The tool name.
|
|
351
|
+
*/
|
|
352
|
+
get name(): string;
|
|
353
|
+
/**
|
|
354
|
+
* Gets the tool description.
|
|
355
|
+
*
|
|
356
|
+
* @returns The tool description.
|
|
357
|
+
*/
|
|
358
|
+
get description(): string;
|
|
359
|
+
/**
|
|
360
|
+
* Gets the input schema for the tool.
|
|
361
|
+
*
|
|
362
|
+
* @returns The input schema.
|
|
363
|
+
*/
|
|
364
|
+
get inputSchema(): FlexibleInputSchema<ToolInputType>;
|
|
365
|
+
/**
|
|
366
|
+
* Gets the input schema for the tool.
|
|
367
|
+
*
|
|
368
|
+
* @returns The input schema.
|
|
369
|
+
*/
|
|
370
|
+
get outputSchema(): FlexibleInputSchema<ToolOutputType>;
|
|
371
|
+
/**
|
|
372
|
+
* Gets whether the tool needs approval before use.
|
|
373
|
+
*
|
|
374
|
+
* @returns True if the tool needs approval, false otherwise.
|
|
375
|
+
*/
|
|
376
|
+
get needsApproval(): boolean;
|
|
377
|
+
/**
|
|
378
|
+
* Gets the input examples for the tool.
|
|
379
|
+
*
|
|
380
|
+
* This is used for AI SDK v6 compatibility, which supports input examples, but without output examples.
|
|
381
|
+
*
|
|
382
|
+
* @returns The tool input examples.
|
|
383
|
+
*/
|
|
384
|
+
get inputExamples(): Array<{
|
|
385
|
+
input: ToolInputType;
|
|
386
|
+
}>;
|
|
387
|
+
/**
|
|
388
|
+
* Gets the examples for the tool.
|
|
389
|
+
*
|
|
390
|
+
* @returns The tool examples.
|
|
391
|
+
*/
|
|
392
|
+
abstract get examples(): Array<ToolExample<ToolInputType, ToolOutputType>>;
|
|
393
|
+
/**
|
|
394
|
+
* Executes the tool with the given input.
|
|
395
|
+
*
|
|
396
|
+
* @param input - The input for the tool.
|
|
397
|
+
* @param options - Options for the tool execution.
|
|
398
|
+
* @returns A promise that resolves to the tool execution result.
|
|
399
|
+
*/
|
|
400
|
+
abstract execute(input: ToolInputType, options: ToolExecutionOptions): Promise<ToolOutputType>;
|
|
401
|
+
/**
|
|
402
|
+
* Converts the tool output to a format suitable for model consumption.
|
|
403
|
+
*
|
|
404
|
+
* @param options - The tool result, including the output from the tool execution.
|
|
405
|
+
* @returns The formatted tool result.
|
|
406
|
+
*/
|
|
407
|
+
abstract toModelOutput(options: ModelToolResultToFormat<ToolInputType, ToolOutputType>): ModelFormattedToolResult;
|
|
408
|
+
/**
|
|
409
|
+
* Returns the metadata for the tool.
|
|
410
|
+
*
|
|
411
|
+
* The name, description, and needsApproval properties are defaults which can be overridden in the constructor.
|
|
412
|
+
*
|
|
413
|
+
* @returns The tool metadata.
|
|
414
|
+
*/
|
|
415
|
+
protected abstract getMetadata(): ToolMetadata<ToolInputType, ToolOutputType>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
type EnvironmentToolMetadata<ToolInputType, ToolOutputType> = ToolMetadata<ToolInputType, ToolOutputType>;
|
|
419
|
+
/**
|
|
420
|
+
* Base class for an execution environment tool.
|
|
421
|
+
*/
|
|
422
|
+
declare abstract class EnvironmentToolBase<ToolConfig extends ToolConfig, ToolInputType, ToolOutputType, EnvironmentType> extends ToolBase<ToolConfig, ToolInputType, ToolOutputType> implements EnvironmentToolInterface<ToolInputType, ToolOutputType, EnvironmentType> {
|
|
423
|
+
protected readonly _environment: EnvironmentType;
|
|
424
|
+
/**
|
|
425
|
+
* Constructs a new `EnvironmentToolBase` instance.
|
|
426
|
+
*
|
|
427
|
+
* @param environment - The execution environment to apply the tool in.
|
|
428
|
+
* @param toolConfig - Optional tool config, can be used to override some defaults.
|
|
429
|
+
*/
|
|
430
|
+
constructor(environment: EnvironmentType, toolConfig?: ToolConfig);
|
|
431
|
+
/**
|
|
432
|
+
* Gets the current execution environment for the tool.
|
|
433
|
+
*
|
|
434
|
+
* @returns The current execution environment.
|
|
435
|
+
*/
|
|
436
|
+
get environment(): EnvironmentType;
|
|
437
|
+
/**
|
|
438
|
+
* Executes the tool with the given input.
|
|
439
|
+
*
|
|
440
|
+
* @param input - The input for the tool.
|
|
441
|
+
* @param _options - Options for the tool execution.
|
|
442
|
+
* @returns A promise that resolves to the tool execution result.
|
|
443
|
+
*/
|
|
444
|
+
execute(input: ToolInputType, _options: ToolExecutionOptions): Promise<ToolOutputType>;
|
|
445
|
+
/**
|
|
446
|
+
* Returns the metadata for the tool.
|
|
447
|
+
*
|
|
448
|
+
* The name, description, and needsApproval properties are defaults which can be overridden in the constructor.
|
|
449
|
+
*
|
|
450
|
+
* @returns The tool metadata.
|
|
451
|
+
*/
|
|
452
|
+
protected abstract getMetadata(): EnvironmentToolMetadata<ToolInputType, ToolOutputType>;
|
|
453
|
+
/**
|
|
454
|
+
* Executes the tool in the given execution environment with the given input.
|
|
455
|
+
*
|
|
456
|
+
* @param env - The execution environment to use.
|
|
457
|
+
* @param input - The input for the tool.
|
|
458
|
+
* @returns A promise that resolves to the tool execution result.
|
|
459
|
+
*/
|
|
460
|
+
protected abstract executeForEnvironment(env: EnvironmentType, input: ToolInputType): Promise<ToolOutputType>;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Escapes a string to be used as a single command-line argument in a POSIX-compliant shell.
|
|
465
|
+
*
|
|
466
|
+
* The string is wrapped in single quotes, and any existing single quotes are
|
|
467
|
+
* safely escaped. This prevents the shell from interpreting special
|
|
468
|
+
* characters or expanding variables.
|
|
469
|
+
*
|
|
470
|
+
* @param arg - The argument string to escape.
|
|
471
|
+
* @returns The escaped and quoted argument string.
|
|
472
|
+
*/
|
|
473
|
+
declare function escapeCommandArg(arg: string): string;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Validates that the given path is a relative path and does not contain path traversal.
|
|
477
|
+
*
|
|
478
|
+
* @param filePath - The file path to validate.
|
|
479
|
+
*/
|
|
480
|
+
declare function validateRelativePath(filePath: string): void;
|
|
481
|
+
|
|
482
|
+
export { CommandLineEnvironmentBase, type CommandLineEnvironmentInterface, CopyFileResult, DeleteFileResult, type Environment, EnvironmentToolBase, type EnvironmentToolInterface, type EnvironmentToolMetadata, FilesystemEnvironmentBase, type FilesystemEnvironmentInterface, type ModelFormattedToolResult, type ModelToolResultToFormat, MoveFileResult, ReadFileResult, RunCommandResult, type ShutdownableEnvironmentInterface, ToolBase, type ToolConfig, type ToolExample, type ToolInterface, type ToolMetadata, UnixEnvironmentBase, WriteFileResult, escapeCommandArg, isCommandLine, isShutdownable, validateRelativePath };
|