@push.rocks/smartagent 1.3.0 → 1.4.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/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/smartagent.classes.dualagent.js +21 -3
- package/dist_ts/smartagent.tools.base.d.ts +7 -1
- package/dist_ts/smartagent.tools.base.js +3 -6
- package/dist_ts/smartagent.tools.browser.d.ts +1 -0
- package/dist_ts/smartagent.tools.browser.js +53 -1
- package/dist_ts/smartagent.tools.deno.d.ts +1 -0
- package/dist_ts/smartagent.tools.deno.js +39 -1
- package/dist_ts/smartagent.tools.filesystem.d.ts +1 -0
- package/dist_ts/smartagent.tools.filesystem.js +164 -1
- package/dist_ts/smartagent.tools.http.d.ts +1 -0
- package/dist_ts/smartagent.tools.http.js +78 -1
- package/dist_ts/smartagent.tools.json.d.ts +1 -0
- package/dist_ts/smartagent.tools.json.js +31 -1
- package/dist_ts/smartagent.tools.shell.d.ts +1 -0
- package/dist_ts/smartagent.tools.shell.js +48 -1
- package/package.json +1 -1
- package/readme.hints.md +29 -5
- package/readme.md +145 -9
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/smartagent.classes.dualagent.ts +20 -2
- package/ts/smartagent.tools.base.ts +9 -6
- package/ts/smartagent.tools.browser.ts +53 -0
- package/ts/smartagent.tools.deno.ts +39 -0
- package/ts/smartagent.tools.filesystem.ts +164 -0
- package/ts/smartagent.tools.http.ts +78 -0
- package/ts/smartagent.tools.json.ts +31 -0
- package/ts/smartagent.tools.shell.ts +48 -0
package/readme.hints.md
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
# Project Readme Hints
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
|
-
`@push.rocks/smartagent` is
|
|
4
|
+
`@push.rocks/smartagent` is a dual-agent agentic framework built on top of `@push.rocks/smartai`. It implements a Driver/Guardian architecture where the Driver proposes tool calls and the Guardian evaluates them against security policies.
|
|
5
5
|
|
|
6
6
|
## Architecture
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
7
|
+
- **DualAgentOrchestrator**: Main entry point, coordinates Driver and Guardian agents
|
|
8
|
+
- **DriverAgent**: Reasons about tasks, plans steps, proposes tool calls
|
|
9
|
+
- **GuardianAgent**: Evaluates tool calls against configured policies
|
|
10
|
+
- **BaseToolWrapper**: Base class for creating custom tools
|
|
11
|
+
- **plugins.ts**: Imports and re-exports smartai and other dependencies
|
|
12
|
+
|
|
13
|
+
## Standard Tools
|
|
14
|
+
1. **FilesystemTool** - File operations with scoping and exclusion patterns
|
|
15
|
+
2. **HttpTool** - HTTP requests
|
|
16
|
+
3. **ShellTool** - Secure shell commands (no injection possible)
|
|
17
|
+
4. **BrowserTool** - Web page interaction via Puppeteer
|
|
18
|
+
5. **DenoTool** - Sandboxed TypeScript/JavaScript execution
|
|
19
|
+
6. **JsonValidatorTool** - JSON validation and formatting
|
|
20
|
+
|
|
21
|
+
## Key Features
|
|
22
|
+
- Token streaming support (`onToken` callback)
|
|
23
|
+
- Vision support (pass images as base64)
|
|
24
|
+
- Progress events (`onProgress` callback)
|
|
25
|
+
- Scoped filesystem with exclusion patterns
|
|
26
|
+
- Result truncation with configurable limits
|
|
27
|
+
- History windowing to manage token usage
|
|
10
28
|
|
|
11
29
|
## Key Dependencies
|
|
12
|
-
- `@push.rocks/smartai`:
|
|
30
|
+
- `@push.rocks/smartai`: Multi-provider AI interface
|
|
31
|
+
- `@push.rocks/smartfs`: Filesystem operations
|
|
32
|
+
- `@push.rocks/smartshell`: Shell command execution
|
|
33
|
+
- `@push.rocks/smartbrowser`: Browser automation
|
|
34
|
+
- `@push.rocks/smartdeno`: Deno code execution
|
|
35
|
+
- `@push.rocks/smartrequest`: HTTP requests
|
|
36
|
+
- `minimatch`: Glob pattern matching for exclusions
|
|
13
37
|
|
|
14
38
|
## Test Structure
|
|
15
39
|
- Tests use `@git.zone/tstest/tapbundle`
|
package/readme.md
CHANGED
|
@@ -50,6 +50,7 @@ flowchart TB
|
|
|
50
50
|
Shell["Shell"]
|
|
51
51
|
Browser["Browser"]
|
|
52
52
|
Deno["Deno"]
|
|
53
|
+
JSON["JSON Validator"]
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
Task --> Orchestrator
|
|
@@ -99,7 +100,7 @@ await orchestrator.stop();
|
|
|
99
100
|
|
|
100
101
|
## Standard Tools
|
|
101
102
|
|
|
102
|
-
SmartAgent comes with
|
|
103
|
+
SmartAgent comes with six battle-tested tools out of the box:
|
|
103
104
|
|
|
104
105
|
### 🗂️ FilesystemTool
|
|
105
106
|
|
|
@@ -117,11 +118,29 @@ File and directory operations powered by `@push.rocks/smartfs`.
|
|
|
117
118
|
</tool_call>
|
|
118
119
|
```
|
|
119
120
|
|
|
120
|
-
**Scoped Filesystem**: Lock file operations to a specific directory:
|
|
121
|
+
**Scoped Filesystem**: Lock file operations to a specific directory with optional exclusion patterns:
|
|
121
122
|
|
|
122
123
|
```typescript
|
|
123
124
|
// Only allow access within a specific directory
|
|
124
125
|
orchestrator.registerScopedFilesystemTool('/home/user/workspace');
|
|
126
|
+
|
|
127
|
+
// With exclusion patterns (glob syntax)
|
|
128
|
+
orchestrator.registerScopedFilesystemTool('/home/user/workspace', [
|
|
129
|
+
'.nogit/**',
|
|
130
|
+
'node_modules/**',
|
|
131
|
+
'*.secret',
|
|
132
|
+
]);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Line-range Reading**: Read specific portions of large files:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
<tool_call>
|
|
139
|
+
<tool>filesystem</tool>
|
|
140
|
+
<action>read</action>
|
|
141
|
+
<params>{"path": "/var/log/app.log", "startLine": 100, "endLine": 150}</params>
|
|
142
|
+
<reasoning>Reading only the relevant log section to avoid token overload</reasoning>
|
|
143
|
+
</tool_call>
|
|
125
144
|
```
|
|
126
145
|
|
|
127
146
|
### 🌐 HttpTool
|
|
@@ -212,6 +231,105 @@ By default, code runs **fully sandboxed with no permissions**. Permissions must
|
|
|
212
231
|
</tool_call>
|
|
213
232
|
```
|
|
214
233
|
|
|
234
|
+
### 📋 JsonValidatorTool
|
|
235
|
+
|
|
236
|
+
Validate and format JSON data. Perfect for agents to self-check their JSON output before completing tasks.
|
|
237
|
+
|
|
238
|
+
**Actions**: `validate`, `format`
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
// Validate JSON with required field checking
|
|
242
|
+
<tool_call>
|
|
243
|
+
<tool>json</tool>
|
|
244
|
+
<action>validate</action>
|
|
245
|
+
<params>{
|
|
246
|
+
"jsonString": "{\"name\": \"test\", \"version\": \"1.0.0\"}",
|
|
247
|
+
"requiredFields": ["name", "version", "description"]
|
|
248
|
+
}</params>
|
|
249
|
+
<reasoning>Ensuring the config has all required fields before saving</reasoning>
|
|
250
|
+
</tool_call>
|
|
251
|
+
|
|
252
|
+
// Pretty-print JSON
|
|
253
|
+
<tool_call>
|
|
254
|
+
<tool>json</tool>
|
|
255
|
+
<action>format</action>
|
|
256
|
+
<params>{"jsonString": "{\"compact\":true,\"data\":[1,2,3]}"}</params>
|
|
257
|
+
<reasoning>Formatting JSON for readable output</reasoning>
|
|
258
|
+
</tool_call>
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## 🎥 Streaming Support
|
|
262
|
+
|
|
263
|
+
SmartAgent supports token-by-token streaming for real-time output during LLM generation:
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
const orchestrator = new DualAgentOrchestrator({
|
|
267
|
+
openaiToken: 'sk-...',
|
|
268
|
+
defaultProvider: 'openai',
|
|
269
|
+
guardianPolicyPrompt: '...',
|
|
270
|
+
|
|
271
|
+
// Token streaming callback
|
|
272
|
+
onToken: (token, source) => {
|
|
273
|
+
// source is 'driver' or 'guardian'
|
|
274
|
+
process.stdout.write(token);
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
This is perfect for CLI applications or UIs that need to show progress as the agent thinks.
|
|
280
|
+
|
|
281
|
+
## 🖼️ Vision Support
|
|
282
|
+
|
|
283
|
+
Pass images to vision-capable models for multimodal tasks:
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import { readFileSync } from 'fs';
|
|
287
|
+
|
|
288
|
+
// Load image as base64
|
|
289
|
+
const imageBase64 = readFileSync('screenshot.png').toString('base64');
|
|
290
|
+
|
|
291
|
+
// Run task with images
|
|
292
|
+
const result = await orchestrator.run(
|
|
293
|
+
'Analyze this UI screenshot and describe any usability issues',
|
|
294
|
+
{ images: [imageBase64] }
|
|
295
|
+
);
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## 📊 Progress Events
|
|
299
|
+
|
|
300
|
+
Get real-time feedback on task execution with the `onProgress` callback:
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
const orchestrator = new DualAgentOrchestrator({
|
|
304
|
+
openaiToken: 'sk-...',
|
|
305
|
+
guardianPolicyPrompt: '...',
|
|
306
|
+
logPrefix: '[MyAgent]', // Optional prefix for log messages
|
|
307
|
+
|
|
308
|
+
onProgress: (event) => {
|
|
309
|
+
// Pre-formatted log message ready for output
|
|
310
|
+
console.log(event.logMessage);
|
|
311
|
+
|
|
312
|
+
// Or handle specific event types
|
|
313
|
+
switch (event.type) {
|
|
314
|
+
case 'tool_proposed':
|
|
315
|
+
console.log(`Proposing: ${event.toolName}.${event.action}`);
|
|
316
|
+
break;
|
|
317
|
+
case 'tool_approved':
|
|
318
|
+
console.log(`✓ Approved`);
|
|
319
|
+
break;
|
|
320
|
+
case 'tool_rejected':
|
|
321
|
+
console.log(`✗ Rejected: ${event.reason}`);
|
|
322
|
+
break;
|
|
323
|
+
case 'task_completed':
|
|
324
|
+
console.log(`Done in ${event.iteration} iterations`);
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**Event Types**: `task_started`, `iteration_started`, `tool_proposed`, `guardian_evaluating`, `tool_approved`, `tool_rejected`, `tool_executing`, `tool_completed`, `task_completed`, `clarification_needed`, `max_iterations`, `max_rejections`
|
|
332
|
+
|
|
215
333
|
## Guardian Policy Examples
|
|
216
334
|
|
|
217
335
|
The Guardian's power comes from your policy. Here are battle-tested examples:
|
|
@@ -294,10 +412,19 @@ interface IDualAgentOptions {
|
|
|
294
412
|
// Agent configuration
|
|
295
413
|
driverSystemMessage?: string; // Custom system message for Driver
|
|
296
414
|
guardianPolicyPrompt: string; // REQUIRED: Policy for Guardian to enforce
|
|
415
|
+
name?: string; // Agent system name
|
|
416
|
+
verbose?: boolean; // Enable verbose logging
|
|
297
417
|
|
|
298
418
|
// Limits
|
|
299
419
|
maxIterations?: number; // Max task iterations (default: 20)
|
|
300
420
|
maxConsecutiveRejections?: number; // Abort after N rejections (default: 3)
|
|
421
|
+
maxResultChars?: number; // Max chars for tool results before truncation (default: 15000)
|
|
422
|
+
maxHistoryMessages?: number; // Max history messages for API (default: 20)
|
|
423
|
+
|
|
424
|
+
// Callbacks
|
|
425
|
+
onProgress?: (event: IProgressEvent) => void; // Progress event callback
|
|
426
|
+
onToken?: (token: string, source: 'driver' | 'guardian') => void; // Streaming callback
|
|
427
|
+
logPrefix?: string; // Prefix for log messages
|
|
301
428
|
}
|
|
302
429
|
```
|
|
303
430
|
|
|
@@ -311,6 +438,10 @@ interface IDualAgentRunResult {
|
|
|
311
438
|
iterations: number; // Number of iterations taken
|
|
312
439
|
history: IAgentMessage[]; // Full conversation history
|
|
313
440
|
status: TDualAgentRunStatus; // 'completed' | 'max_iterations_reached' | etc.
|
|
441
|
+
toolCallCount?: number; // Number of tool calls made
|
|
442
|
+
rejectionCount?: number; // Number of Guardian rejections
|
|
443
|
+
toolLog?: IToolExecutionLog[]; // Detailed tool execution log
|
|
444
|
+
error?: string; // Error message if status is 'error'
|
|
314
445
|
}
|
|
315
446
|
|
|
316
447
|
type TDualAgentRunStatus =
|
|
@@ -365,6 +496,7 @@ class MyCustomTool extends BaseToolWrapper {
|
|
|
365
496
|
return {
|
|
366
497
|
success: true,
|
|
367
498
|
result: { processed: params.input },
|
|
499
|
+
summary: `Processed input: ${params.input}`, // Optional human-readable summary
|
|
368
500
|
};
|
|
369
501
|
}
|
|
370
502
|
|
|
@@ -439,11 +571,11 @@ const orchestrator = new DualAgentOrchestrator({
|
|
|
439
571
|
|--------|-------------|
|
|
440
572
|
| `start()` | Initialize all tools and AI providers |
|
|
441
573
|
| `stop()` | Cleanup all tools and resources |
|
|
442
|
-
| `run(task
|
|
443
|
-
| `continueTask(input
|
|
574
|
+
| `run(task, options?)` | Execute a task with optional images for vision |
|
|
575
|
+
| `continueTask(input)` | Continue a task with user input |
|
|
444
576
|
| `registerTool(tool)` | Register a custom tool |
|
|
445
577
|
| `registerStandardTools()` | Register all built-in tools |
|
|
446
|
-
| `registerScopedFilesystemTool(basePath)` | Register filesystem tool with path restriction |
|
|
578
|
+
| `registerScopedFilesystemTool(basePath, excludePatterns?)` | Register filesystem tool with path restriction |
|
|
447
579
|
| `setGuardianPolicy(policy)` | Update Guardian policy at runtime |
|
|
448
580
|
| `getHistory()` | Get conversation history |
|
|
449
581
|
| `getToolNames()` | Get list of registered tool names |
|
|
@@ -459,14 +591,18 @@ export { GuardianAgent } from '@push.rocks/smartagent';
|
|
|
459
591
|
|
|
460
592
|
// Tools
|
|
461
593
|
export { BaseToolWrapper } from '@push.rocks/smartagent';
|
|
462
|
-
export { FilesystemTool } from '@push.rocks/smartagent';
|
|
594
|
+
export { FilesystemTool, type IFilesystemToolOptions } from '@push.rocks/smartagent';
|
|
463
595
|
export { HttpTool } from '@push.rocks/smartagent';
|
|
464
596
|
export { ShellTool } from '@push.rocks/smartagent';
|
|
465
597
|
export { BrowserTool } from '@push.rocks/smartagent';
|
|
466
|
-
export { DenoTool } from '@push.rocks/smartagent';
|
|
598
|
+
export { DenoTool, type TDenoPermission } from '@push.rocks/smartagent';
|
|
599
|
+
export { JsonValidatorTool } from '@push.rocks/smartagent';
|
|
467
600
|
|
|
468
601
|
// Types and interfaces
|
|
469
|
-
export * from '@push.rocks/smartagent';
|
|
602
|
+
export * from '@push.rocks/smartagent'; // All interfaces
|
|
603
|
+
|
|
604
|
+
// Re-exported from @push.rocks/smartai
|
|
605
|
+
export { type ISmartAiOptions, type TProvider, type ChatMessage, type ChatOptions, type ChatResponse };
|
|
470
606
|
```
|
|
471
607
|
|
|
472
608
|
## License and Legal Information
|
|
@@ -483,7 +619,7 @@ Use of these trademarks must comply with Task Venture Capital GmbH's Trademark G
|
|
|
483
619
|
|
|
484
620
|
### Company Information
|
|
485
621
|
|
|
486
|
-
Task Venture Capital GmbH
|
|
622
|
+
Task Venture Capital GmbH
|
|
487
623
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
|
488
624
|
|
|
489
625
|
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -319,9 +319,27 @@ export class DualAgentOrchestrator {
|
|
|
319
319
|
const proposals = this.driver.parseToolCallProposals(driverResponse.content);
|
|
320
320
|
|
|
321
321
|
if (proposals.length === 0) {
|
|
322
|
-
// No tool calls
|
|
322
|
+
// No tool calls found - remind the model of the exact XML format
|
|
323
323
|
driverResponse = await this.driver.continueWithMessage(
|
|
324
|
-
|
|
324
|
+
`No valid tool call was found in your response. To use a tool, you MUST output the exact XML format:
|
|
325
|
+
|
|
326
|
+
<tool_call>
|
|
327
|
+
<tool>tool_name</tool>
|
|
328
|
+
<action>action_name</action>
|
|
329
|
+
<params>{"param1": "value1"}</params>
|
|
330
|
+
</tool_call>
|
|
331
|
+
|
|
332
|
+
For example, to validate JSON:
|
|
333
|
+
<tool_call>
|
|
334
|
+
<tool>json</tool>
|
|
335
|
+
<action>validate</action>
|
|
336
|
+
<params>{"jsonString": "{\\"key\\":\\"value\\"}", "requiredFields": ["key"]}</params>
|
|
337
|
+
</tool_call>
|
|
338
|
+
|
|
339
|
+
Or to complete the task:
|
|
340
|
+
<task_complete>your final JSON output here</task_complete>
|
|
341
|
+
|
|
342
|
+
Please output the exact XML format above.`
|
|
325
343
|
);
|
|
326
344
|
this.conversationHistory.push(driverResponse);
|
|
327
345
|
continue;
|
|
@@ -35,6 +35,13 @@ export abstract class BaseToolWrapper implements interfaces.IAgentToolWrapper {
|
|
|
35
35
|
*/
|
|
36
36
|
abstract getCallSummary(action: string, params: Record<string, unknown>): string;
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Get a comprehensive explanation of this tool for LLM consumption.
|
|
40
|
+
* Tools should implement this to provide detailed usage instructions with examples.
|
|
41
|
+
* This includes parameter schemas and concrete <tool_call> XML examples.
|
|
42
|
+
*/
|
|
43
|
+
abstract getToolExplanation(): string;
|
|
44
|
+
|
|
38
45
|
/**
|
|
39
46
|
* Validate that an action exists for this tool
|
|
40
47
|
* @throws Error if the action is not valid
|
|
@@ -60,14 +67,10 @@ export abstract class BaseToolWrapper implements interfaces.IAgentToolWrapper {
|
|
|
60
67
|
|
|
61
68
|
/**
|
|
62
69
|
* Get the full tool description including all actions
|
|
63
|
-
* Used for Driver's tool awareness
|
|
70
|
+
* Used for Driver's tool awareness - now delegates to getToolExplanation()
|
|
64
71
|
*/
|
|
65
72
|
public getFullDescription(): string {
|
|
66
|
-
|
|
67
|
-
.map((a) => ` - ${a.name}: ${a.description}`)
|
|
68
|
-
.join('\n');
|
|
69
|
-
|
|
70
|
-
return `${this.name}: ${this.description}\nActions:\n${actionDescriptions}`;
|
|
73
|
+
return this.getToolExplanation();
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
/**
|
|
@@ -176,6 +176,59 @@ export class BrowserTool extends BaseToolWrapper {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
public getToolExplanation(): string {
|
|
180
|
+
return `## Tool: browser
|
|
181
|
+
Interact with web pages - take screenshots, generate PDFs, and execute JavaScript on pages.
|
|
182
|
+
|
|
183
|
+
### Actions:
|
|
184
|
+
|
|
185
|
+
**screenshot** - Take a screenshot of a webpage
|
|
186
|
+
Parameters:
|
|
187
|
+
- url (required): URL of the page to screenshot
|
|
188
|
+
|
|
189
|
+
Example:
|
|
190
|
+
<tool_call>
|
|
191
|
+
<tool>browser</tool>
|
|
192
|
+
<action>screenshot</action>
|
|
193
|
+
<params>{"url": "https://example.com"}</params>
|
|
194
|
+
</tool_call>
|
|
195
|
+
|
|
196
|
+
**pdf** - Generate a PDF from a webpage
|
|
197
|
+
Parameters:
|
|
198
|
+
- url (required): URL of the page to convert to PDF
|
|
199
|
+
|
|
200
|
+
Example:
|
|
201
|
+
<tool_call>
|
|
202
|
+
<tool>browser</tool>
|
|
203
|
+
<action>pdf</action>
|
|
204
|
+
<params>{"url": "https://example.com/report"}</params>
|
|
205
|
+
</tool_call>
|
|
206
|
+
|
|
207
|
+
**evaluate** - Execute JavaScript code on a webpage and return the result
|
|
208
|
+
Parameters:
|
|
209
|
+
- url (required): URL of the page to run the script on
|
|
210
|
+
- script (required): JavaScript code to execute (must return a value)
|
|
211
|
+
|
|
212
|
+
Example:
|
|
213
|
+
<tool_call>
|
|
214
|
+
<tool>browser</tool>
|
|
215
|
+
<action>evaluate</action>
|
|
216
|
+
<params>{"url": "https://example.com", "script": "document.querySelectorAll('a').length"}</params>
|
|
217
|
+
</tool_call>
|
|
218
|
+
|
|
219
|
+
**getPageContent** - Get the text content and title of a webpage
|
|
220
|
+
Parameters:
|
|
221
|
+
- url (required): URL of the page to get content from
|
|
222
|
+
|
|
223
|
+
Example:
|
|
224
|
+
<tool_call>
|
|
225
|
+
<tool>browser</tool>
|
|
226
|
+
<action>getPageContent</action>
|
|
227
|
+
<params>{"url": "https://example.com"}</params>
|
|
228
|
+
</tool_call>
|
|
229
|
+
`;
|
|
230
|
+
}
|
|
231
|
+
|
|
179
232
|
public getCallSummary(action: string, params: Record<string, unknown>): string {
|
|
180
233
|
switch (action) {
|
|
181
234
|
case 'screenshot':
|
|
@@ -164,6 +164,45 @@ export class DenoTool extends BaseToolWrapper {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
public getToolExplanation(): string {
|
|
168
|
+
return `## Tool: deno
|
|
169
|
+
Execute TypeScript/JavaScript code in a sandboxed Deno environment with fine-grained permission control.
|
|
170
|
+
|
|
171
|
+
### Actions:
|
|
172
|
+
|
|
173
|
+
**execute** - Execute TypeScript/JavaScript code and return stdout/stderr
|
|
174
|
+
Parameters:
|
|
175
|
+
- code (required): TypeScript/JavaScript code to execute
|
|
176
|
+
- permissions (optional): Array of Deno permissions to grant. Options: "all", "env", "net", "read", "write", "run", "sys", "ffi", "hrtime". Default: none (fully sandboxed)
|
|
177
|
+
|
|
178
|
+
Example - Simple execution:
|
|
179
|
+
<tool_call>
|
|
180
|
+
<tool>deno</tool>
|
|
181
|
+
<action>execute</action>
|
|
182
|
+
<params>{"code": "console.log('Hello from Deno!');"}</params>
|
|
183
|
+
</tool_call>
|
|
184
|
+
|
|
185
|
+
Example - With network permission:
|
|
186
|
+
<tool_call>
|
|
187
|
+
<tool>deno</tool>
|
|
188
|
+
<action>execute</action>
|
|
189
|
+
<params>{"code": "const resp = await fetch('https://api.example.com/data');\\nconsole.log(await resp.text());", "permissions": ["net"]}</params>
|
|
190
|
+
</tool_call>
|
|
191
|
+
|
|
192
|
+
**executeWithResult** - Execute code that outputs JSON on the last line of stdout
|
|
193
|
+
Parameters:
|
|
194
|
+
- code (required): Code that console.logs a JSON value on the final line
|
|
195
|
+
- permissions (optional): Array of Deno permissions to grant
|
|
196
|
+
|
|
197
|
+
Example:
|
|
198
|
+
<tool_call>
|
|
199
|
+
<tool>deno</tool>
|
|
200
|
+
<action>executeWithResult</action>
|
|
201
|
+
<params>{"code": "const result = { sum: 1 + 2, product: 2 * 3 };\\nconsole.log(JSON.stringify(result));"}</params>
|
|
202
|
+
</tool_call>
|
|
203
|
+
`;
|
|
204
|
+
}
|
|
205
|
+
|
|
167
206
|
public getCallSummary(action: string, params: Record<string, unknown>): string {
|
|
168
207
|
const code = params.code as string;
|
|
169
208
|
const permissions = (params.permissions as string[]) || [];
|
|
@@ -666,6 +666,170 @@ export class FilesystemTool extends BaseToolWrapper {
|
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
668
|
|
|
669
|
+
public getToolExplanation(): string {
|
|
670
|
+
return `## Tool: filesystem
|
|
671
|
+
Read, write, list, and delete files and directories.
|
|
672
|
+
|
|
673
|
+
### Actions:
|
|
674
|
+
|
|
675
|
+
**read** - Read file contents (full or specific line range)
|
|
676
|
+
Parameters:
|
|
677
|
+
- path (required): Path to the file
|
|
678
|
+
- encoding (optional): File encoding - "utf8" (default), "binary", or "base64"
|
|
679
|
+
- startLine (optional): First line to read (1-indexed, inclusive)
|
|
680
|
+
- endLine (optional): Last line to read (1-indexed, inclusive)
|
|
681
|
+
|
|
682
|
+
Example:
|
|
683
|
+
<tool_call>
|
|
684
|
+
<tool>filesystem</tool>
|
|
685
|
+
<action>read</action>
|
|
686
|
+
<params>{"path": "/path/to/file.txt"}</params>
|
|
687
|
+
</tool_call>
|
|
688
|
+
|
|
689
|
+
Example with line range:
|
|
690
|
+
<tool_call>
|
|
691
|
+
<tool>filesystem</tool>
|
|
692
|
+
<action>read</action>
|
|
693
|
+
<params>{"path": "/path/to/file.txt", "startLine": 10, "endLine": 20}</params>
|
|
694
|
+
</tool_call>
|
|
695
|
+
|
|
696
|
+
**write** - Write content to a file (creates or overwrites)
|
|
697
|
+
Parameters:
|
|
698
|
+
- path (required): Absolute path to the file
|
|
699
|
+
- content (required): Content to write
|
|
700
|
+
- encoding (optional): File encoding - "utf8" (default), "binary", or "base64"
|
|
701
|
+
|
|
702
|
+
Example:
|
|
703
|
+
<tool_call>
|
|
704
|
+
<tool>filesystem</tool>
|
|
705
|
+
<action>write</action>
|
|
706
|
+
<params>{"path": "/path/to/output.txt", "content": "Hello, World!"}</params>
|
|
707
|
+
</tool_call>
|
|
708
|
+
|
|
709
|
+
**list** - List files and directories in a path
|
|
710
|
+
Parameters:
|
|
711
|
+
- path (required): Directory path to list
|
|
712
|
+
- recursive (optional): List recursively (default: false)
|
|
713
|
+
- filter (optional): Glob pattern to filter results (e.g., "*.ts")
|
|
714
|
+
|
|
715
|
+
Example:
|
|
716
|
+
<tool_call>
|
|
717
|
+
<tool>filesystem</tool>
|
|
718
|
+
<action>list</action>
|
|
719
|
+
<params>{"path": "/path/to/dir", "recursive": true, "filter": "*.ts"}</params>
|
|
720
|
+
</tool_call>
|
|
721
|
+
|
|
722
|
+
**exists** - Check if a file or directory exists
|
|
723
|
+
Parameters:
|
|
724
|
+
- path (required): Path to check
|
|
725
|
+
|
|
726
|
+
Example:
|
|
727
|
+
<tool_call>
|
|
728
|
+
<tool>filesystem</tool>
|
|
729
|
+
<action>exists</action>
|
|
730
|
+
<params>{"path": "/path/to/check"}</params>
|
|
731
|
+
</tool_call>
|
|
732
|
+
|
|
733
|
+
**mkdir** - Create a directory
|
|
734
|
+
Parameters:
|
|
735
|
+
- path (required): Directory path to create
|
|
736
|
+
- recursive (optional): Create parent directories if needed (default: true)
|
|
737
|
+
|
|
738
|
+
Example:
|
|
739
|
+
<tool_call>
|
|
740
|
+
<tool>filesystem</tool>
|
|
741
|
+
<action>mkdir</action>
|
|
742
|
+
<params>{"path": "/path/to/new/dir"}</params>
|
|
743
|
+
</tool_call>
|
|
744
|
+
|
|
745
|
+
**delete** - Delete a file or directory
|
|
746
|
+
Parameters:
|
|
747
|
+
- path (required): Path to delete
|
|
748
|
+
- recursive (optional): For directories, delete recursively (default: false)
|
|
749
|
+
|
|
750
|
+
Example:
|
|
751
|
+
<tool_call>
|
|
752
|
+
<tool>filesystem</tool>
|
|
753
|
+
<action>delete</action>
|
|
754
|
+
<params>{"path": "/path/to/delete", "recursive": true}</params>
|
|
755
|
+
</tool_call>
|
|
756
|
+
|
|
757
|
+
**copy** - Copy a file to a new location
|
|
758
|
+
Parameters:
|
|
759
|
+
- source (required): Source file path
|
|
760
|
+
- destination (required): Destination file path
|
|
761
|
+
|
|
762
|
+
Example:
|
|
763
|
+
<tool_call>
|
|
764
|
+
<tool>filesystem</tool>
|
|
765
|
+
<action>copy</action>
|
|
766
|
+
<params>{"source": "/path/to/source.txt", "destination": "/path/to/dest.txt"}</params>
|
|
767
|
+
</tool_call>
|
|
768
|
+
|
|
769
|
+
**move** - Move a file to a new location
|
|
770
|
+
Parameters:
|
|
771
|
+
- source (required): Source file path
|
|
772
|
+
- destination (required): Destination file path
|
|
773
|
+
|
|
774
|
+
Example:
|
|
775
|
+
<tool_call>
|
|
776
|
+
<tool>filesystem</tool>
|
|
777
|
+
<action>move</action>
|
|
778
|
+
<params>{"source": "/path/to/old.txt", "destination": "/path/to/new.txt"}</params>
|
|
779
|
+
</tool_call>
|
|
780
|
+
|
|
781
|
+
**stat** - Get file or directory statistics (size, dates, etc.)
|
|
782
|
+
Parameters:
|
|
783
|
+
- path (required): Path to get stats for
|
|
784
|
+
|
|
785
|
+
Example:
|
|
786
|
+
<tool_call>
|
|
787
|
+
<tool>filesystem</tool>
|
|
788
|
+
<action>stat</action>
|
|
789
|
+
<params>{"path": "/path/to/file.txt"}</params>
|
|
790
|
+
</tool_call>
|
|
791
|
+
|
|
792
|
+
**append** - Append content to a file
|
|
793
|
+
Parameters:
|
|
794
|
+
- path (required): Absolute path to the file
|
|
795
|
+
- content (required): Content to append
|
|
796
|
+
|
|
797
|
+
Example:
|
|
798
|
+
<tool_call>
|
|
799
|
+
<tool>filesystem</tool>
|
|
800
|
+
<action>append</action>
|
|
801
|
+
<params>{"path": "/path/to/log.txt", "content": "New log entry\\n"}</params>
|
|
802
|
+
</tool_call>
|
|
803
|
+
|
|
804
|
+
**tree** - Show directory structure as a tree
|
|
805
|
+
Parameters:
|
|
806
|
+
- path (required): Root directory path
|
|
807
|
+
- maxDepth (optional): Maximum depth to traverse (default: 3)
|
|
808
|
+
- filter (optional): Glob pattern to filter files
|
|
809
|
+
- showSizes (optional): Include file sizes in output (default: false)
|
|
810
|
+
- format (optional): Output format - "string" (default) or "json"
|
|
811
|
+
|
|
812
|
+
Example:
|
|
813
|
+
<tool_call>
|
|
814
|
+
<tool>filesystem</tool>
|
|
815
|
+
<action>tree</action>
|
|
816
|
+
<params>{"path": "/path/to/dir", "maxDepth": 2}</params>
|
|
817
|
+
</tool_call>
|
|
818
|
+
|
|
819
|
+
**glob** - Find files matching a glob pattern
|
|
820
|
+
Parameters:
|
|
821
|
+
- pattern (required): Glob pattern (e.g., "**/*.ts", "src/**/*.js")
|
|
822
|
+
- path (optional): Base path to search from
|
|
823
|
+
|
|
824
|
+
Example:
|
|
825
|
+
<tool_call>
|
|
826
|
+
<tool>filesystem</tool>
|
|
827
|
+
<action>glob</action>
|
|
828
|
+
<params>{"pattern": "**/*.ts", "path": "/path/to/project"}</params>
|
|
829
|
+
</tool_call>
|
|
830
|
+
`;
|
|
831
|
+
}
|
|
832
|
+
|
|
669
833
|
public getCallSummary(action: string, params: Record<string, unknown>): string {
|
|
670
834
|
switch (action) {
|
|
671
835
|
case 'read': {
|