@push.rocks/smartagent 1.8.0 → 3.0.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.
Files changed (87) hide show
  1. package/dist_ts/00_commitinfo_data.js +3 -3
  2. package/dist_ts/index.d.ts +8 -14
  3. package/dist_ts/index.js +8 -24
  4. package/dist_ts/plugins.d.ts +8 -9
  5. package/dist_ts/plugins.js +10 -12
  6. package/dist_ts/smartagent.classes.agent.d.ts +2 -0
  7. package/dist_ts/smartagent.classes.agent.js +173 -0
  8. package/dist_ts/smartagent.classes.toolregistry.d.ts +7 -70
  9. package/dist_ts/smartagent.classes.toolregistry.js +11 -155
  10. package/dist_ts/smartagent.interfaces.d.ts +47 -283
  11. package/dist_ts/smartagent.interfaces.js +6 -7
  12. package/dist_ts/smartagent.utils.truncation.d.ts +10 -0
  13. package/dist_ts/smartagent.utils.truncation.js +26 -0
  14. package/dist_ts_compaction/index.d.ts +1 -0
  15. package/dist_ts_compaction/index.js +2 -0
  16. package/dist_ts_compaction/plugins.d.ts +4 -0
  17. package/dist_ts_compaction/plugins.js +3 -0
  18. package/dist_ts_compaction/smartagent.compaction.d.ts +10 -0
  19. package/dist_ts_compaction/smartagent.compaction.js +46 -0
  20. package/dist_ts_tools/index.d.ts +8 -0
  21. package/dist_ts_tools/index.js +6 -0
  22. package/dist_ts_tools/plugins.d.ts +15 -0
  23. package/dist_ts_tools/plugins.js +19 -0
  24. package/dist_ts_tools/tool.filesystem.d.ts +6 -0
  25. package/dist_ts_tools/tool.filesystem.js +102 -0
  26. package/dist_ts_tools/tool.http.d.ts +2 -0
  27. package/dist_ts_tools/tool.http.js +65 -0
  28. package/dist_ts_tools/tool.json.d.ts +2 -0
  29. package/dist_ts_tools/tool.json.js +47 -0
  30. package/dist_ts_tools/tool.shell.d.ts +8 -0
  31. package/dist_ts_tools/tool.shell.js +40 -0
  32. package/npmextra.json +1 -1
  33. package/package.json +30 -18
  34. package/readme.hints.md +38 -84
  35. package/readme.md +254 -682
  36. package/ts/00_commitinfo_data.ts +2 -2
  37. package/ts/index.ts +10 -37
  38. package/ts/plugins.ts +22 -21
  39. package/ts/smartagent.classes.agent.ts +198 -0
  40. package/ts/smartagent.classes.toolregistry.ts +11 -179
  41. package/ts/smartagent.interfaces.ts +51 -363
  42. package/ts/smartagent.utils.truncation.ts +39 -0
  43. package/ts_compaction/index.ts +1 -0
  44. package/ts_compaction/plugins.ts +6 -0
  45. package/ts_compaction/smartagent.compaction.ts +51 -0
  46. package/ts_tools/index.ts +8 -0
  47. package/ts_tools/plugins.ts +30 -0
  48. package/ts_tools/tool.filesystem.ts +131 -0
  49. package/ts_tools/tool.http.ts +78 -0
  50. package/ts_tools/tool.json.ts +53 -0
  51. package/ts_tools/tool.shell.ts +62 -0
  52. package/dist_ts/smartagent.classes.driveragent.d.ts +0 -134
  53. package/dist_ts/smartagent.classes.driveragent.js +0 -671
  54. package/dist_ts/smartagent.classes.dualagent.d.ts +0 -93
  55. package/dist_ts/smartagent.classes.dualagent.js +0 -614
  56. package/dist_ts/smartagent.classes.guardianagent.d.ts +0 -46
  57. package/dist_ts/smartagent.classes.guardianagent.js +0 -201
  58. package/dist_ts/smartagent.tools.base.d.ts +0 -52
  59. package/dist_ts/smartagent.tools.base.js +0 -42
  60. package/dist_ts/smartagent.tools.browser.d.ts +0 -17
  61. package/dist_ts/smartagent.tools.browser.js +0 -229
  62. package/dist_ts/smartagent.tools.deno.d.ts +0 -21
  63. package/dist_ts/smartagent.tools.deno.js +0 -191
  64. package/dist_ts/smartagent.tools.expert.d.ts +0 -27
  65. package/dist_ts/smartagent.tools.expert.js +0 -126
  66. package/dist_ts/smartagent.tools.filesystem.d.ts +0 -40
  67. package/dist_ts/smartagent.tools.filesystem.js +0 -801
  68. package/dist_ts/smartagent.tools.http.d.ts +0 -16
  69. package/dist_ts/smartagent.tools.http.js +0 -264
  70. package/dist_ts/smartagent.tools.json.d.ts +0 -24
  71. package/dist_ts/smartagent.tools.json.js +0 -202
  72. package/dist_ts/smartagent.tools.search.d.ts +0 -29
  73. package/dist_ts/smartagent.tools.search.js +0 -215
  74. package/dist_ts/smartagent.tools.shell.d.ts +0 -17
  75. package/dist_ts/smartagent.tools.shell.js +0 -202
  76. package/ts/smartagent.classes.driveragent.ts +0 -775
  77. package/ts/smartagent.classes.dualagent.ts +0 -692
  78. package/ts/smartagent.classes.guardianagent.ts +0 -241
  79. package/ts/smartagent.tools.base.ts +0 -83
  80. package/ts/smartagent.tools.browser.ts +0 -253
  81. package/ts/smartagent.tools.deno.ts +0 -230
  82. package/ts/smartagent.tools.expert.ts +0 -144
  83. package/ts/smartagent.tools.filesystem.ts +0 -885
  84. package/ts/smartagent.tools.http.ts +0 -283
  85. package/ts/smartagent.tools.json.ts +0 -224
  86. package/ts/smartagent.tools.search.ts +0 -237
  87. package/ts/smartagent.tools.shell.ts +0 -230
@@ -1,230 +0,0 @@
1
- import * as plugins from './plugins.js';
2
- import * as interfaces from './smartagent.interfaces.js';
3
- import { BaseToolWrapper } from './smartagent.tools.base.js';
4
-
5
- /**
6
- * Deno permission types for sandboxed code execution
7
- */
8
- export type TDenoPermission =
9
- | 'all'
10
- | 'env'
11
- | 'ffi'
12
- | 'hrtime'
13
- | 'net'
14
- | 'read'
15
- | 'run'
16
- | 'sys'
17
- | 'write';
18
-
19
- /**
20
- * Deno tool for executing TypeScript/JavaScript code in a sandboxed environment
21
- * Wraps @push.rocks/smartdeno
22
- */
23
- export class DenoTool extends BaseToolWrapper {
24
- public name = 'deno';
25
- public description =
26
- 'Execute TypeScript/JavaScript code in a sandboxed Deno environment with fine-grained permission control';
27
-
28
- public actions: interfaces.IToolAction[] = [
29
- {
30
- name: 'execute',
31
- description:
32
- 'Execute TypeScript/JavaScript code and return stdout/stderr. Code runs in Deno sandbox with specified permissions.',
33
- parameters: {
34
- type: 'object',
35
- properties: {
36
- code: {
37
- type: 'string',
38
- description: 'TypeScript/JavaScript code to execute',
39
- },
40
- permissions: {
41
- type: 'array',
42
- items: {
43
- type: 'string',
44
- enum: ['all', 'env', 'ffi', 'hrtime', 'net', 'read', 'run', 'sys', 'write'],
45
- },
46
- description:
47
- 'Deno permissions to grant. Default: none (fully sandboxed). Options: all, env, net, read, write, run, sys, ffi, hrtime',
48
- },
49
- },
50
- required: ['code'],
51
- },
52
- },
53
- {
54
- name: 'executeWithResult',
55
- description:
56
- 'Execute code that outputs JSON on the last line of stdout. The JSON is parsed and returned as the result.',
57
- parameters: {
58
- type: 'object',
59
- properties: {
60
- code: {
61
- type: 'string',
62
- description:
63
- 'Code that console.logs a JSON value on the final line. This JSON will be parsed and returned.',
64
- },
65
- permissions: {
66
- type: 'array',
67
- items: {
68
- type: 'string',
69
- enum: ['all', 'env', 'ffi', 'hrtime', 'net', 'read', 'run', 'sys', 'write'],
70
- },
71
- description: 'Deno permissions to grant',
72
- },
73
- },
74
- required: ['code'],
75
- },
76
- },
77
- ];
78
-
79
- private smartdeno!: plugins.smartdeno.SmartDeno;
80
-
81
- public async initialize(): Promise<void> {
82
- this.smartdeno = new plugins.smartdeno.SmartDeno();
83
- await this.smartdeno.start();
84
- this.isInitialized = true;
85
- }
86
-
87
- public async cleanup(): Promise<void> {
88
- if (this.smartdeno) {
89
- await this.smartdeno.stop();
90
- }
91
- this.isInitialized = false;
92
- }
93
-
94
- public async execute(
95
- action: string,
96
- params: Record<string, unknown>
97
- ): Promise<interfaces.IToolExecutionResult> {
98
- this.validateAction(action);
99
- this.ensureInitialized();
100
-
101
- try {
102
- const code = params.code as string;
103
- const permissions = (params.permissions as TDenoPermission[]) || [];
104
-
105
- // Execute the script
106
- const result = await this.smartdeno.executeScript(code, {
107
- permissions,
108
- });
109
-
110
- switch (action) {
111
- case 'execute': {
112
- return {
113
- success: result.exitCode === 0,
114
- result: {
115
- exitCode: result.exitCode,
116
- stdout: result.stdout,
117
- stderr: result.stderr,
118
- permissions,
119
- },
120
- };
121
- }
122
-
123
- case 'executeWithResult': {
124
- if (result.exitCode !== 0) {
125
- return {
126
- success: false,
127
- error: `Script failed with exit code ${result.exitCode}: ${result.stderr}`,
128
- };
129
- }
130
-
131
- // Parse the last line of stdout as JSON
132
- const lines = result.stdout.trim().split('\n');
133
- const lastLine = lines[lines.length - 1];
134
-
135
- try {
136
- const parsedResult = JSON.parse(lastLine);
137
- return {
138
- success: true,
139
- result: {
140
- parsed: parsedResult,
141
- stdout: result.stdout,
142
- stderr: result.stderr,
143
- },
144
- };
145
- } catch (parseError) {
146
- return {
147
- success: false,
148
- error: `Failed to parse JSON from last line of output: ${lastLine}`,
149
- };
150
- }
151
- }
152
-
153
- default:
154
- return {
155
- success: false,
156
- error: `Unknown action: ${action}`,
157
- };
158
- }
159
- } catch (error) {
160
- return {
161
- success: false,
162
- error: error instanceof Error ? error.message : String(error),
163
- };
164
- }
165
- }
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
-
206
- public getCallSummary(action: string, params: Record<string, unknown>): string {
207
- const code = params.code as string;
208
- const permissions = (params.permissions as string[]) || [];
209
-
210
- // Create a preview of the code (first 100 chars)
211
- const codePreview = code.length > 100 ? code.substring(0, 100) + '...' : code;
212
- // Escape newlines for single-line display
213
- const cleanPreview = codePreview.replace(/\n/g, '\\n');
214
-
215
- const permissionInfo = permissions.length > 0
216
- ? ` [permissions: ${permissions.join(', ')}]`
217
- : ' [sandboxed - no permissions]';
218
-
219
- switch (action) {
220
- case 'execute':
221
- return `Execute Deno code${permissionInfo}: "${cleanPreview}"`;
222
-
223
- case 'executeWithResult':
224
- return `Execute Deno code and parse JSON result${permissionInfo}: "${cleanPreview}"`;
225
-
226
- default:
227
- return `Unknown action: ${action}`;
228
- }
229
- }
230
- }
@@ -1,144 +0,0 @@
1
- import * as plugins from './plugins.js';
2
- import * as interfaces from './smartagent.interfaces.js';
3
- import { BaseToolWrapper } from './smartagent.tools.base.js';
4
-
5
- // Forward declaration to avoid circular import at module load time
6
- // The actual import happens lazily in initialize()
7
- let DualAgentOrchestrator: typeof import('./smartagent.classes.dualagent.js').DualAgentOrchestrator;
8
-
9
- /**
10
- * ExpertTool - A specialized agent wrapped as a tool
11
- *
12
- * Enables hierarchical agent architectures where the Driver can delegate
13
- * complex tasks to specialized experts with their own tools and policies.
14
- */
15
- export class ExpertTool extends BaseToolWrapper {
16
- public name: string;
17
- public description: string;
18
- public actions: interfaces.IToolAction[] = [
19
- {
20
- name: 'consult',
21
- description: 'Delegate a task or question to this expert',
22
- parameters: {
23
- type: 'object',
24
- properties: {
25
- task: { type: 'string', description: 'The task or question for the expert' },
26
- context: { type: 'string', description: 'Additional context to help the expert' },
27
- },
28
- required: ['task'],
29
- },
30
- },
31
- ];
32
-
33
- private config: interfaces.IExpertConfig;
34
- private smartAi: plugins.smartai.SmartAi;
35
- private inner?: InstanceType<typeof DualAgentOrchestrator>;
36
-
37
- constructor(config: interfaces.IExpertConfig, smartAi: plugins.smartai.SmartAi) {
38
- super();
39
- this.config = config;
40
- this.smartAi = smartAi;
41
- this.name = config.name;
42
- this.description = config.description;
43
- }
44
-
45
- async initialize(): Promise<void> {
46
- // Lazy import to avoid circular dependency
47
- if (!DualAgentOrchestrator) {
48
- const module = await import('./smartagent.classes.dualagent.js');
49
- DualAgentOrchestrator = module.DualAgentOrchestrator;
50
- }
51
-
52
- this.inner = new DualAgentOrchestrator({
53
- smartAiInstance: this.smartAi, // Share SmartAi instance
54
- defaultProvider: this.config.provider,
55
- driverSystemMessage: this.config.systemMessage,
56
- guardianPolicyPrompt: this.config.guardianPolicy,
57
- maxIterations: this.config.maxIterations ?? 10,
58
- });
59
-
60
- // Register expert's tools
61
- if (this.config.tools) {
62
- for (const tool of this.config.tools) {
63
- // Tools in the config are IAgentToolWrapper, but we need BaseToolWrapper
64
- // Since all our tools extend BaseToolWrapper, this cast is safe
65
- this.inner.registerTool(tool as BaseToolWrapper);
66
- }
67
- }
68
-
69
- await this.inner.start();
70
- this.isInitialized = true;
71
- }
72
-
73
- async cleanup(): Promise<void> {
74
- if (this.inner) {
75
- await this.inner.stop();
76
- this.inner = undefined;
77
- }
78
- this.isInitialized = false;
79
- }
80
-
81
- async execute(
82
- action: string,
83
- params: Record<string, unknown>
84
- ): Promise<interfaces.IToolExecutionResult> {
85
- this.validateAction(action);
86
- this.ensureInitialized();
87
-
88
- const task = params.task as string;
89
- const context = params.context as string | undefined;
90
-
91
- const fullTask = context ? `Context: ${context}\n\nTask: ${task}` : task;
92
-
93
- try {
94
- const result = await this.inner!.run(fullTask);
95
-
96
- return {
97
- success: result.success,
98
- result: {
99
- response: result.result,
100
- iterations: result.iterations,
101
- status: result.status,
102
- },
103
- summary: result.success
104
- ? `Expert "${this.name}" completed (${result.iterations} iterations)`
105
- : `Expert "${this.name}" failed: ${result.status}`,
106
- };
107
- } catch (error) {
108
- return {
109
- success: false,
110
- error: `Expert error: ${error instanceof Error ? error.message : String(error)}`,
111
- };
112
- }
113
- }
114
-
115
- getCallSummary(action: string, params: Record<string, unknown>): string {
116
- const task = params.task as string;
117
- const preview = task.length > 60 ? task.substring(0, 60) + '...' : task;
118
- return `Consult ${this.name}: "${preview}"`;
119
- }
120
-
121
- getToolExplanation(): string {
122
- return `## Expert: ${this.name}
123
- ${this.description}
124
-
125
- ### Usage:
126
- Delegate tasks to this expert when you need specialized help.
127
-
128
- \`\`\`
129
- <tool_call>
130
- <tool>${this.name}</tool>
131
- <action>consult</action>
132
- <params>{"task": "Your question or task", "context": "Optional background"}</params>
133
- </tool_call>
134
- \`\`\`
135
- `;
136
- }
137
-
138
- /**
139
- * Get the expert's configuration
140
- */
141
- getConfig(): interfaces.IExpertConfig {
142
- return this.config;
143
- }
144
- }