@robota-sdk/agent-tools 3.0.0-beta.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/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/node/index.cjs +1352 -0
- package/dist/node/index.d.cts +353 -0
- package/dist/node/index.d.ts +353 -0
- package/dist/node/index.js +1303 -0
- package/package.json +51 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { IToolRegistry, ITool, IToolSchema, TToolParameters, TUniversalValue, IFunctionTool, TToolExecutor, IEventService, IToolExecutionContext, IToolResult, IParameterValidationResult, IOpenAPIToolConfig } from '@robota-sdk/agent-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result returned by a CLI tool invocation
|
|
5
|
+
*/
|
|
6
|
+
interface TToolResult {
|
|
7
|
+
success: boolean;
|
|
8
|
+
output: string;
|
|
9
|
+
error?: string;
|
|
10
|
+
exitCode?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tool registry implementation
|
|
15
|
+
* Manages tool registration, validation, and retrieval
|
|
16
|
+
*/
|
|
17
|
+
declare class ToolRegistry implements IToolRegistry {
|
|
18
|
+
private tools;
|
|
19
|
+
/**
|
|
20
|
+
* Register a tool
|
|
21
|
+
*/
|
|
22
|
+
register(tool: ITool): void;
|
|
23
|
+
/**
|
|
24
|
+
* Unregister a tool
|
|
25
|
+
*/
|
|
26
|
+
unregister(name: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get tool by name
|
|
29
|
+
*/
|
|
30
|
+
get(name: string): ITool | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get all registered tools
|
|
33
|
+
*/
|
|
34
|
+
getAll(): ITool[];
|
|
35
|
+
/**
|
|
36
|
+
* Get tool schemas
|
|
37
|
+
*/
|
|
38
|
+
getSchemas(): IToolSchema[];
|
|
39
|
+
/**
|
|
40
|
+
* Check if tool exists
|
|
41
|
+
*/
|
|
42
|
+
has(name: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Clear all tools
|
|
45
|
+
*/
|
|
46
|
+
clear(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get tool names
|
|
49
|
+
*/
|
|
50
|
+
getToolNames(): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Get tools by pattern
|
|
53
|
+
*/
|
|
54
|
+
getToolsByPattern(pattern: string | RegExp): ITool[];
|
|
55
|
+
/**
|
|
56
|
+
* Get tool count
|
|
57
|
+
*/
|
|
58
|
+
size(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Validate tool schema
|
|
61
|
+
*/
|
|
62
|
+
private validateToolSchema;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* FunctionTool - Type definitions for Facade pattern implementation
|
|
67
|
+
*
|
|
68
|
+
* REASON: Complex Zod schema type compatibility requires separation of concerns
|
|
69
|
+
* ALTERNATIVES_CONSIDERED:
|
|
70
|
+
* 1. Fix all Zod undefined issues in single file (creates maintenance burden)
|
|
71
|
+
* 2. Use any types strategically (reduces type safety)
|
|
72
|
+
* 3. Remove Zod support entirely (breaks existing functionality)
|
|
73
|
+
* 4. Create complex conditional types (adds cognitive overhead)
|
|
74
|
+
* 5. Use type assertions everywhere (increases runtime risk)
|
|
75
|
+
* NOTE: Tool functionality is now integrated into @robota-sdk/agent-tools package
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Zod schema compatibility types
|
|
80
|
+
*/
|
|
81
|
+
interface IZodParseResult {
|
|
82
|
+
success: boolean;
|
|
83
|
+
data?: TToolParameters;
|
|
84
|
+
error?: string | Error;
|
|
85
|
+
}
|
|
86
|
+
interface IZodSchemaDef {
|
|
87
|
+
typeName?: string;
|
|
88
|
+
innerType?: IZodSchema;
|
|
89
|
+
checks?: Array<{
|
|
90
|
+
kind: string;
|
|
91
|
+
value?: TUniversalValue;
|
|
92
|
+
}>;
|
|
93
|
+
shape?: () => Record<string, IZodSchema>;
|
|
94
|
+
type?: IZodSchema;
|
|
95
|
+
values?: TUniversalValue[];
|
|
96
|
+
description?: string;
|
|
97
|
+
}
|
|
98
|
+
interface IZodSchema {
|
|
99
|
+
parse(value: TToolParameters): TToolParameters;
|
|
100
|
+
safeParse(value: TToolParameters): IZodParseResult;
|
|
101
|
+
_def?: IZodSchemaDef;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Parameter type validation options
|
|
105
|
+
*/
|
|
106
|
+
interface IFunctionToolValidationOptions {
|
|
107
|
+
strict?: boolean;
|
|
108
|
+
allowUnknown?: boolean;
|
|
109
|
+
validateTypes?: boolean;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Schema conversion options
|
|
113
|
+
*/
|
|
114
|
+
interface ISchemaConversionOptions {
|
|
115
|
+
includeDescription?: boolean;
|
|
116
|
+
strictTypes?: boolean;
|
|
117
|
+
allowAdditionalProperties?: boolean;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Tool execution metadata
|
|
121
|
+
*/
|
|
122
|
+
interface IFunctionToolExecutionMetadata {
|
|
123
|
+
executionTime: number;
|
|
124
|
+
toolName: string;
|
|
125
|
+
parameters: TToolParameters;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Tool result with metadata
|
|
129
|
+
*/
|
|
130
|
+
interface IFunctionToolResult {
|
|
131
|
+
success: boolean;
|
|
132
|
+
data: TUniversalValue;
|
|
133
|
+
metadata?: IFunctionToolExecutionMetadata;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Function tool implementation
|
|
138
|
+
* Wraps a JavaScript function as a tool with schema validation
|
|
139
|
+
*
|
|
140
|
+
* Implements IFunctionTool without extending AbstractTool to avoid
|
|
141
|
+
* circular runtime dependency (tools → agents → tools).
|
|
142
|
+
*/
|
|
143
|
+
declare class FunctionTool implements IFunctionTool {
|
|
144
|
+
readonly schema: IToolSchema;
|
|
145
|
+
readonly fn: TToolExecutor;
|
|
146
|
+
private eventService;
|
|
147
|
+
constructor(schema: IToolSchema, fn: TToolExecutor);
|
|
148
|
+
/**
|
|
149
|
+
* Get tool name
|
|
150
|
+
*/
|
|
151
|
+
getName(): string;
|
|
152
|
+
/**
|
|
153
|
+
* Set EventService for post-construction injection.
|
|
154
|
+
* Accepts EventService as-is without transformation.
|
|
155
|
+
* Caller is responsible for providing properly configured EventService.
|
|
156
|
+
*/
|
|
157
|
+
setEventService(eventService: IEventService | undefined): void;
|
|
158
|
+
/**
|
|
159
|
+
* Execute the function tool
|
|
160
|
+
*/
|
|
161
|
+
execute(parameters: TToolParameters, context?: IToolExecutionContext): Promise<IToolResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Validate parameters (simple boolean result)
|
|
164
|
+
*/
|
|
165
|
+
validate(parameters: TToolParameters): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Validate tool parameters with detailed result
|
|
168
|
+
*/
|
|
169
|
+
validateParameters(parameters: TToolParameters): IParameterValidationResult;
|
|
170
|
+
/**
|
|
171
|
+
* Get tool description
|
|
172
|
+
*/
|
|
173
|
+
getDescription(): string;
|
|
174
|
+
/**
|
|
175
|
+
* Get detailed validation errors
|
|
176
|
+
*/
|
|
177
|
+
private getValidationErrors;
|
|
178
|
+
/**
|
|
179
|
+
* Validate individual parameter type
|
|
180
|
+
*/
|
|
181
|
+
private validateParameterType;
|
|
182
|
+
/**
|
|
183
|
+
* Validate constructor inputs
|
|
184
|
+
*/
|
|
185
|
+
private validateConstructorInputs;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Helper function to create a function tool from a simple function
|
|
189
|
+
*/
|
|
190
|
+
declare function createFunctionTool(name: string, description: string, parameters: IToolSchema['parameters'], fn: TToolExecutor): FunctionTool;
|
|
191
|
+
/**
|
|
192
|
+
* Helper function to create a function tool from Zod schema
|
|
193
|
+
*/
|
|
194
|
+
declare function createZodFunctionTool(name: string, description: string, zodSchema: IZodSchema, fn: TToolExecutor): FunctionTool;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* OpenAPI tool implementation
|
|
198
|
+
* Executes API calls based on OpenAPI 3.0 specifications
|
|
199
|
+
*
|
|
200
|
+
* Implements ITool without extending AbstractTool to avoid
|
|
201
|
+
* circular runtime dependency (tools → agents → tools).
|
|
202
|
+
*/
|
|
203
|
+
declare class OpenAPITool implements ITool {
|
|
204
|
+
readonly schema: IToolSchema;
|
|
205
|
+
private readonly apiSpec;
|
|
206
|
+
private readonly operationId;
|
|
207
|
+
private readonly baseURL;
|
|
208
|
+
private readonly config;
|
|
209
|
+
private eventService;
|
|
210
|
+
constructor(config: IOpenAPIToolConfig);
|
|
211
|
+
/**
|
|
212
|
+
* Execute the OpenAPI tool
|
|
213
|
+
*/
|
|
214
|
+
execute(parameters: TToolParameters, context?: IToolExecutionContext): Promise<IToolResult>;
|
|
215
|
+
/**
|
|
216
|
+
* Validate tool parameters
|
|
217
|
+
*/
|
|
218
|
+
validate(parameters: TToolParameters): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Validate tool parameters with detailed result
|
|
221
|
+
*/
|
|
222
|
+
validateParameters(parameters: TToolParameters): IParameterValidationResult;
|
|
223
|
+
/**
|
|
224
|
+
* Get tool name
|
|
225
|
+
*/
|
|
226
|
+
getName(): string;
|
|
227
|
+
/**
|
|
228
|
+
* Set EventService for post-construction injection.
|
|
229
|
+
*/
|
|
230
|
+
setEventService(eventService: IEventService | undefined): void;
|
|
231
|
+
/**
|
|
232
|
+
* Get tool description
|
|
233
|
+
*/
|
|
234
|
+
getDescription(): string;
|
|
235
|
+
/**
|
|
236
|
+
* Execute the actual API call
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
private executeAPICall;
|
|
240
|
+
/**
|
|
241
|
+
* Find the operation in the OpenAPI specification
|
|
242
|
+
*/
|
|
243
|
+
private findOperation;
|
|
244
|
+
/**
|
|
245
|
+
* Build HTTP request configuration from OpenAPI operation and parameters
|
|
246
|
+
*/
|
|
247
|
+
private buildRequestConfig;
|
|
248
|
+
/**
|
|
249
|
+
* Create tool schema from OpenAPI operation specification
|
|
250
|
+
*/
|
|
251
|
+
private createSchemaFromOpenAPI;
|
|
252
|
+
/**
|
|
253
|
+
* Convert OpenAPI parameter to tool parameter schema
|
|
254
|
+
*/
|
|
255
|
+
private convertOpenAPIParamToSchema;
|
|
256
|
+
/**
|
|
257
|
+
* Convert OpenAPI schema to parameter schema
|
|
258
|
+
*/
|
|
259
|
+
private convertOpenAPISchemaToParameterSchema;
|
|
260
|
+
/**
|
|
261
|
+
* Map OpenAPI type to JSON schema type
|
|
262
|
+
*/
|
|
263
|
+
private mapOpenAPIType;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Factory function to create OpenAPI tools from specification
|
|
267
|
+
*/
|
|
268
|
+
declare function createOpenAPITool(config: IOpenAPIToolConfig): OpenAPITool;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* FunctionTool - Schema conversion utilities for Facade pattern
|
|
272
|
+
*
|
|
273
|
+
* REASON: Complex Zod to JSON schema conversion requires isolated utility functions
|
|
274
|
+
* ALTERNATIVES_CONSIDERED:
|
|
275
|
+
* 1. Keep conversion logic in main class (violates single responsibility)
|
|
276
|
+
* 2. Use third-party library (adds external dependency)
|
|
277
|
+
* 3. Manual conversion each time (code duplication)
|
|
278
|
+
* 4. Runtime type checking only (loses compile-time safety)
|
|
279
|
+
* 5. Remove Zod support (breaks backward compatibility)
|
|
280
|
+
* TODO: Consider caching conversion results for performance
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Convert Zod schema to JSON Schema format with safe undefined handling
|
|
285
|
+
*/
|
|
286
|
+
declare function zodToJsonSchema(schema: IZodSchema, options?: ISchemaConversionOptions): IToolSchema['parameters'];
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* BashTool — execute shell commands via child_process.spawn
|
|
290
|
+
*
|
|
291
|
+
* Returns TToolResult JSON string. Non-zero exit is returned as success:true
|
|
292
|
+
* with exitCode set, matching Claude Code behaviour (the command ran, it just
|
|
293
|
+
* exited non-zero — the LLM can decide what to do with that information).
|
|
294
|
+
*/
|
|
295
|
+
/**
|
|
296
|
+
* BashTool instance — register with Robota agent tools registry.
|
|
297
|
+
*/
|
|
298
|
+
declare const bashTool: FunctionTool;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* ReadTool — read a file and return its contents with line numbers (cat -n style).
|
|
302
|
+
*
|
|
303
|
+
* Supports offset/limit for partial reads. Detects binary files and refuses to
|
|
304
|
+
* return their raw bytes. Default limit is 2000 lines.
|
|
305
|
+
*/
|
|
306
|
+
/**
|
|
307
|
+
* ReadTool instance — register with Robota agent tools registry.
|
|
308
|
+
*/
|
|
309
|
+
declare const readTool: FunctionTool;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* WriteTool — write content to a file, auto-creating parent directories.
|
|
313
|
+
*/
|
|
314
|
+
/**
|
|
315
|
+
* WriteTool instance — register with Robota agent tools registry.
|
|
316
|
+
*/
|
|
317
|
+
declare const writeTool: FunctionTool;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* EditTool — perform string-replace edits on a file.
|
|
321
|
+
*
|
|
322
|
+
* By default, requires the oldString to appear exactly once in the file
|
|
323
|
+
* (ensuring surgical edits). Pass replaceAll:true to replace all occurrences.
|
|
324
|
+
*/
|
|
325
|
+
/**
|
|
326
|
+
* EditTool instance — register with Robota agent tools registry.
|
|
327
|
+
*/
|
|
328
|
+
declare const editTool: FunctionTool;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* GlobTool — fast file pattern search using fast-glob.
|
|
332
|
+
*
|
|
333
|
+
* Excludes node_modules and .git by default.
|
|
334
|
+
* Results are sorted by modification time (most recently modified first).
|
|
335
|
+
*/
|
|
336
|
+
/**
|
|
337
|
+
* GlobTool instance — register with Robota agent tools registry.
|
|
338
|
+
*/
|
|
339
|
+
declare const globTool: FunctionTool;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* GrepTool — recursive regex content search.
|
|
343
|
+
*
|
|
344
|
+
* Supports two output modes:
|
|
345
|
+
* - files_with_matches (default): return only file paths that contain a match
|
|
346
|
+
* - content: return matching lines with optional context lines
|
|
347
|
+
*/
|
|
348
|
+
/**
|
|
349
|
+
* GrepTool instance — register with Robota agent tools registry.
|
|
350
|
+
*/
|
|
351
|
+
declare const grepTool: FunctionTool;
|
|
352
|
+
|
|
353
|
+
export { FunctionTool, type IFunctionToolExecutionMetadata, type IFunctionToolResult, type IFunctionToolValidationOptions, type ISchemaConversionOptions, type IZodParseResult, type IZodSchema, type IZodSchemaDef, OpenAPITool, type TToolResult, ToolRegistry, bashTool, createFunctionTool, createOpenAPITool, createZodFunctionTool, editTool, globTool, grepTool, readTool, writeTool, zodToJsonSchema };
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { IToolRegistry, ITool, IToolSchema, TToolParameters, TUniversalValue, IFunctionTool, TToolExecutor, IEventService, IToolExecutionContext, IToolResult, IParameterValidationResult, IOpenAPIToolConfig } from '@robota-sdk/agent-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result returned by a CLI tool invocation
|
|
5
|
+
*/
|
|
6
|
+
interface TToolResult {
|
|
7
|
+
success: boolean;
|
|
8
|
+
output: string;
|
|
9
|
+
error?: string;
|
|
10
|
+
exitCode?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tool registry implementation
|
|
15
|
+
* Manages tool registration, validation, and retrieval
|
|
16
|
+
*/
|
|
17
|
+
declare class ToolRegistry implements IToolRegistry {
|
|
18
|
+
private tools;
|
|
19
|
+
/**
|
|
20
|
+
* Register a tool
|
|
21
|
+
*/
|
|
22
|
+
register(tool: ITool): void;
|
|
23
|
+
/**
|
|
24
|
+
* Unregister a tool
|
|
25
|
+
*/
|
|
26
|
+
unregister(name: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get tool by name
|
|
29
|
+
*/
|
|
30
|
+
get(name: string): ITool | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get all registered tools
|
|
33
|
+
*/
|
|
34
|
+
getAll(): ITool[];
|
|
35
|
+
/**
|
|
36
|
+
* Get tool schemas
|
|
37
|
+
*/
|
|
38
|
+
getSchemas(): IToolSchema[];
|
|
39
|
+
/**
|
|
40
|
+
* Check if tool exists
|
|
41
|
+
*/
|
|
42
|
+
has(name: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Clear all tools
|
|
45
|
+
*/
|
|
46
|
+
clear(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get tool names
|
|
49
|
+
*/
|
|
50
|
+
getToolNames(): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Get tools by pattern
|
|
53
|
+
*/
|
|
54
|
+
getToolsByPattern(pattern: string | RegExp): ITool[];
|
|
55
|
+
/**
|
|
56
|
+
* Get tool count
|
|
57
|
+
*/
|
|
58
|
+
size(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Validate tool schema
|
|
61
|
+
*/
|
|
62
|
+
private validateToolSchema;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* FunctionTool - Type definitions for Facade pattern implementation
|
|
67
|
+
*
|
|
68
|
+
* REASON: Complex Zod schema type compatibility requires separation of concerns
|
|
69
|
+
* ALTERNATIVES_CONSIDERED:
|
|
70
|
+
* 1. Fix all Zod undefined issues in single file (creates maintenance burden)
|
|
71
|
+
* 2. Use any types strategically (reduces type safety)
|
|
72
|
+
* 3. Remove Zod support entirely (breaks existing functionality)
|
|
73
|
+
* 4. Create complex conditional types (adds cognitive overhead)
|
|
74
|
+
* 5. Use type assertions everywhere (increases runtime risk)
|
|
75
|
+
* NOTE: Tool functionality is now integrated into @robota-sdk/agent-tools package
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Zod schema compatibility types
|
|
80
|
+
*/
|
|
81
|
+
interface IZodParseResult {
|
|
82
|
+
success: boolean;
|
|
83
|
+
data?: TToolParameters;
|
|
84
|
+
error?: string | Error;
|
|
85
|
+
}
|
|
86
|
+
interface IZodSchemaDef {
|
|
87
|
+
typeName?: string;
|
|
88
|
+
innerType?: IZodSchema;
|
|
89
|
+
checks?: Array<{
|
|
90
|
+
kind: string;
|
|
91
|
+
value?: TUniversalValue;
|
|
92
|
+
}>;
|
|
93
|
+
shape?: () => Record<string, IZodSchema>;
|
|
94
|
+
type?: IZodSchema;
|
|
95
|
+
values?: TUniversalValue[];
|
|
96
|
+
description?: string;
|
|
97
|
+
}
|
|
98
|
+
interface IZodSchema {
|
|
99
|
+
parse(value: TToolParameters): TToolParameters;
|
|
100
|
+
safeParse(value: TToolParameters): IZodParseResult;
|
|
101
|
+
_def?: IZodSchemaDef;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Parameter type validation options
|
|
105
|
+
*/
|
|
106
|
+
interface IFunctionToolValidationOptions {
|
|
107
|
+
strict?: boolean;
|
|
108
|
+
allowUnknown?: boolean;
|
|
109
|
+
validateTypes?: boolean;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Schema conversion options
|
|
113
|
+
*/
|
|
114
|
+
interface ISchemaConversionOptions {
|
|
115
|
+
includeDescription?: boolean;
|
|
116
|
+
strictTypes?: boolean;
|
|
117
|
+
allowAdditionalProperties?: boolean;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Tool execution metadata
|
|
121
|
+
*/
|
|
122
|
+
interface IFunctionToolExecutionMetadata {
|
|
123
|
+
executionTime: number;
|
|
124
|
+
toolName: string;
|
|
125
|
+
parameters: TToolParameters;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Tool result with metadata
|
|
129
|
+
*/
|
|
130
|
+
interface IFunctionToolResult {
|
|
131
|
+
success: boolean;
|
|
132
|
+
data: TUniversalValue;
|
|
133
|
+
metadata?: IFunctionToolExecutionMetadata;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Function tool implementation
|
|
138
|
+
* Wraps a JavaScript function as a tool with schema validation
|
|
139
|
+
*
|
|
140
|
+
* Implements IFunctionTool without extending AbstractTool to avoid
|
|
141
|
+
* circular runtime dependency (tools → agents → tools).
|
|
142
|
+
*/
|
|
143
|
+
declare class FunctionTool implements IFunctionTool {
|
|
144
|
+
readonly schema: IToolSchema;
|
|
145
|
+
readonly fn: TToolExecutor;
|
|
146
|
+
private eventService;
|
|
147
|
+
constructor(schema: IToolSchema, fn: TToolExecutor);
|
|
148
|
+
/**
|
|
149
|
+
* Get tool name
|
|
150
|
+
*/
|
|
151
|
+
getName(): string;
|
|
152
|
+
/**
|
|
153
|
+
* Set EventService for post-construction injection.
|
|
154
|
+
* Accepts EventService as-is without transformation.
|
|
155
|
+
* Caller is responsible for providing properly configured EventService.
|
|
156
|
+
*/
|
|
157
|
+
setEventService(eventService: IEventService | undefined): void;
|
|
158
|
+
/**
|
|
159
|
+
* Execute the function tool
|
|
160
|
+
*/
|
|
161
|
+
execute(parameters: TToolParameters, context?: IToolExecutionContext): Promise<IToolResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Validate parameters (simple boolean result)
|
|
164
|
+
*/
|
|
165
|
+
validate(parameters: TToolParameters): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Validate tool parameters with detailed result
|
|
168
|
+
*/
|
|
169
|
+
validateParameters(parameters: TToolParameters): IParameterValidationResult;
|
|
170
|
+
/**
|
|
171
|
+
* Get tool description
|
|
172
|
+
*/
|
|
173
|
+
getDescription(): string;
|
|
174
|
+
/**
|
|
175
|
+
* Get detailed validation errors
|
|
176
|
+
*/
|
|
177
|
+
private getValidationErrors;
|
|
178
|
+
/**
|
|
179
|
+
* Validate individual parameter type
|
|
180
|
+
*/
|
|
181
|
+
private validateParameterType;
|
|
182
|
+
/**
|
|
183
|
+
* Validate constructor inputs
|
|
184
|
+
*/
|
|
185
|
+
private validateConstructorInputs;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Helper function to create a function tool from a simple function
|
|
189
|
+
*/
|
|
190
|
+
declare function createFunctionTool(name: string, description: string, parameters: IToolSchema['parameters'], fn: TToolExecutor): FunctionTool;
|
|
191
|
+
/**
|
|
192
|
+
* Helper function to create a function tool from Zod schema
|
|
193
|
+
*/
|
|
194
|
+
declare function createZodFunctionTool(name: string, description: string, zodSchema: IZodSchema, fn: TToolExecutor): FunctionTool;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* OpenAPI tool implementation
|
|
198
|
+
* Executes API calls based on OpenAPI 3.0 specifications
|
|
199
|
+
*
|
|
200
|
+
* Implements ITool without extending AbstractTool to avoid
|
|
201
|
+
* circular runtime dependency (tools → agents → tools).
|
|
202
|
+
*/
|
|
203
|
+
declare class OpenAPITool implements ITool {
|
|
204
|
+
readonly schema: IToolSchema;
|
|
205
|
+
private readonly apiSpec;
|
|
206
|
+
private readonly operationId;
|
|
207
|
+
private readonly baseURL;
|
|
208
|
+
private readonly config;
|
|
209
|
+
private eventService;
|
|
210
|
+
constructor(config: IOpenAPIToolConfig);
|
|
211
|
+
/**
|
|
212
|
+
* Execute the OpenAPI tool
|
|
213
|
+
*/
|
|
214
|
+
execute(parameters: TToolParameters, context?: IToolExecutionContext): Promise<IToolResult>;
|
|
215
|
+
/**
|
|
216
|
+
* Validate tool parameters
|
|
217
|
+
*/
|
|
218
|
+
validate(parameters: TToolParameters): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Validate tool parameters with detailed result
|
|
221
|
+
*/
|
|
222
|
+
validateParameters(parameters: TToolParameters): IParameterValidationResult;
|
|
223
|
+
/**
|
|
224
|
+
* Get tool name
|
|
225
|
+
*/
|
|
226
|
+
getName(): string;
|
|
227
|
+
/**
|
|
228
|
+
* Set EventService for post-construction injection.
|
|
229
|
+
*/
|
|
230
|
+
setEventService(eventService: IEventService | undefined): void;
|
|
231
|
+
/**
|
|
232
|
+
* Get tool description
|
|
233
|
+
*/
|
|
234
|
+
getDescription(): string;
|
|
235
|
+
/**
|
|
236
|
+
* Execute the actual API call
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
private executeAPICall;
|
|
240
|
+
/**
|
|
241
|
+
* Find the operation in the OpenAPI specification
|
|
242
|
+
*/
|
|
243
|
+
private findOperation;
|
|
244
|
+
/**
|
|
245
|
+
* Build HTTP request configuration from OpenAPI operation and parameters
|
|
246
|
+
*/
|
|
247
|
+
private buildRequestConfig;
|
|
248
|
+
/**
|
|
249
|
+
* Create tool schema from OpenAPI operation specification
|
|
250
|
+
*/
|
|
251
|
+
private createSchemaFromOpenAPI;
|
|
252
|
+
/**
|
|
253
|
+
* Convert OpenAPI parameter to tool parameter schema
|
|
254
|
+
*/
|
|
255
|
+
private convertOpenAPIParamToSchema;
|
|
256
|
+
/**
|
|
257
|
+
* Convert OpenAPI schema to parameter schema
|
|
258
|
+
*/
|
|
259
|
+
private convertOpenAPISchemaToParameterSchema;
|
|
260
|
+
/**
|
|
261
|
+
* Map OpenAPI type to JSON schema type
|
|
262
|
+
*/
|
|
263
|
+
private mapOpenAPIType;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Factory function to create OpenAPI tools from specification
|
|
267
|
+
*/
|
|
268
|
+
declare function createOpenAPITool(config: IOpenAPIToolConfig): OpenAPITool;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* FunctionTool - Schema conversion utilities for Facade pattern
|
|
272
|
+
*
|
|
273
|
+
* REASON: Complex Zod to JSON schema conversion requires isolated utility functions
|
|
274
|
+
* ALTERNATIVES_CONSIDERED:
|
|
275
|
+
* 1. Keep conversion logic in main class (violates single responsibility)
|
|
276
|
+
* 2. Use third-party library (adds external dependency)
|
|
277
|
+
* 3. Manual conversion each time (code duplication)
|
|
278
|
+
* 4. Runtime type checking only (loses compile-time safety)
|
|
279
|
+
* 5. Remove Zod support (breaks backward compatibility)
|
|
280
|
+
* TODO: Consider caching conversion results for performance
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Convert Zod schema to JSON Schema format with safe undefined handling
|
|
285
|
+
*/
|
|
286
|
+
declare function zodToJsonSchema(schema: IZodSchema, options?: ISchemaConversionOptions): IToolSchema['parameters'];
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* BashTool — execute shell commands via child_process.spawn
|
|
290
|
+
*
|
|
291
|
+
* Returns TToolResult JSON string. Non-zero exit is returned as success:true
|
|
292
|
+
* with exitCode set, matching Claude Code behaviour (the command ran, it just
|
|
293
|
+
* exited non-zero — the LLM can decide what to do with that information).
|
|
294
|
+
*/
|
|
295
|
+
/**
|
|
296
|
+
* BashTool instance — register with Robota agent tools registry.
|
|
297
|
+
*/
|
|
298
|
+
declare const bashTool: FunctionTool;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* ReadTool — read a file and return its contents with line numbers (cat -n style).
|
|
302
|
+
*
|
|
303
|
+
* Supports offset/limit for partial reads. Detects binary files and refuses to
|
|
304
|
+
* return their raw bytes. Default limit is 2000 lines.
|
|
305
|
+
*/
|
|
306
|
+
/**
|
|
307
|
+
* ReadTool instance — register with Robota agent tools registry.
|
|
308
|
+
*/
|
|
309
|
+
declare const readTool: FunctionTool;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* WriteTool — write content to a file, auto-creating parent directories.
|
|
313
|
+
*/
|
|
314
|
+
/**
|
|
315
|
+
* WriteTool instance — register with Robota agent tools registry.
|
|
316
|
+
*/
|
|
317
|
+
declare const writeTool: FunctionTool;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* EditTool — perform string-replace edits on a file.
|
|
321
|
+
*
|
|
322
|
+
* By default, requires the oldString to appear exactly once in the file
|
|
323
|
+
* (ensuring surgical edits). Pass replaceAll:true to replace all occurrences.
|
|
324
|
+
*/
|
|
325
|
+
/**
|
|
326
|
+
* EditTool instance — register with Robota agent tools registry.
|
|
327
|
+
*/
|
|
328
|
+
declare const editTool: FunctionTool;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* GlobTool — fast file pattern search using fast-glob.
|
|
332
|
+
*
|
|
333
|
+
* Excludes node_modules and .git by default.
|
|
334
|
+
* Results are sorted by modification time (most recently modified first).
|
|
335
|
+
*/
|
|
336
|
+
/**
|
|
337
|
+
* GlobTool instance — register with Robota agent tools registry.
|
|
338
|
+
*/
|
|
339
|
+
declare const globTool: FunctionTool;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* GrepTool — recursive regex content search.
|
|
343
|
+
*
|
|
344
|
+
* Supports two output modes:
|
|
345
|
+
* - files_with_matches (default): return only file paths that contain a match
|
|
346
|
+
* - content: return matching lines with optional context lines
|
|
347
|
+
*/
|
|
348
|
+
/**
|
|
349
|
+
* GrepTool instance — register with Robota agent tools registry.
|
|
350
|
+
*/
|
|
351
|
+
declare const grepTool: FunctionTool;
|
|
352
|
+
|
|
353
|
+
export { FunctionTool, type IFunctionToolExecutionMetadata, type IFunctionToolResult, type IFunctionToolValidationOptions, type ISchemaConversionOptions, type IZodParseResult, type IZodSchema, type IZodSchemaDef, OpenAPITool, type TToolResult, ToolRegistry, bashTool, createFunctionTool, createOpenAPITool, createZodFunctionTool, editTool, globTool, grepTool, readTool, writeTool, zodToJsonSchema };
|