@push.rocks/smartagent 1.7.0 → 3.0.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.
Files changed (81) hide show
  1. package/dist_ts/00_commitinfo_data.js +3 -3
  2. package/dist_ts/index.d.ts +9 -12
  3. package/dist_ts/index.js +9 -20
  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 +12 -0
  9. package/dist_ts/smartagent.classes.toolregistry.js +17 -0
  10. package/dist_ts/smartagent.interfaces.d.ts +47 -231
  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 +43 -42
  35. package/readme.md +257 -526
  36. package/ts/00_commitinfo_data.ts +2 -2
  37. package/ts/index.ts +11 -31
  38. package/ts/plugins.ts +22 -21
  39. package/ts/smartagent.classes.agent.ts +198 -0
  40. package/ts/smartagent.classes.toolregistry.ts +20 -0
  41. package/ts/smartagent.interfaces.ts +51 -303
  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 -79
  55. package/dist_ts/smartagent.classes.dualagent.js +0 -583
  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.filesystem.d.ts +0 -40
  65. package/dist_ts/smartagent.tools.filesystem.js +0 -801
  66. package/dist_ts/smartagent.tools.http.d.ts +0 -16
  67. package/dist_ts/smartagent.tools.http.js +0 -264
  68. package/dist_ts/smartagent.tools.json.d.ts +0 -24
  69. package/dist_ts/smartagent.tools.json.js +0 -202
  70. package/dist_ts/smartagent.tools.shell.d.ts +0 -17
  71. package/dist_ts/smartagent.tools.shell.js +0 -202
  72. package/ts/smartagent.classes.driveragent.ts +0 -775
  73. package/ts/smartagent.classes.dualagent.ts +0 -657
  74. package/ts/smartagent.classes.guardianagent.ts +0 -241
  75. package/ts/smartagent.tools.base.ts +0 -83
  76. package/ts/smartagent.tools.browser.ts +0 -253
  77. package/ts/smartagent.tools.deno.ts +0 -230
  78. package/ts/smartagent.tools.filesystem.ts +0 -885
  79. package/ts/smartagent.tools.http.ts +0 -283
  80. package/ts/smartagent.tools.json.ts +0 -224
  81. 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
- }