@tyvm/knowhow 0.0.108-dev.126b29e → 0.0.108-dev.4a8ba55

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 (147) hide show
  1. package/package.json +2 -3
  2. package/src/agents/base/base.ts +9 -0
  3. package/src/agents/tools/index.ts +0 -1
  4. package/src/agents/tools/list.ts +0 -2
  5. package/src/chat/CliChatService.ts +7 -1
  6. package/src/chat/renderer/CompactRenderer.ts +20 -0
  7. package/src/chat/renderer/ConsoleRenderer.ts +19 -0
  8. package/src/chat/renderer/FancyRenderer.ts +19 -0
  9. package/src/chat/renderer/types.ts +11 -0
  10. package/src/cli.ts +79 -666
  11. package/src/clients/types.ts +12 -4
  12. package/src/commands/agent.ts +246 -0
  13. package/src/commands/misc.ts +169 -0
  14. package/src/commands/modules.ts +182 -0
  15. package/src/commands/services.ts +72 -0
  16. package/src/commands/workers.ts +160 -0
  17. package/src/config.ts +37 -0
  18. package/src/index.ts +1 -0
  19. package/src/plugins/plugins.ts +0 -21
  20. package/src/processors/JsonCompressor.ts +6 -6
  21. package/src/services/modules/index.ts +58 -49
  22. package/src/services/modules/types.ts +2 -0
  23. package/src/tunnel.ts +216 -0
  24. package/src/types.ts +0 -1
  25. package/src/worker.ts +65 -336
  26. package/src/workers/auth/WsMiddleware.ts +99 -0
  27. package/src/workers/auth/authMiddleware.ts +104 -0
  28. package/src/workers/auth/types.ts +14 -2
  29. package/tests/unit/modules/moduleLoading.test.ts +0 -25
  30. package/tests/unit/plugins/pluginLoading.test.ts +0 -85
  31. package/ts_build/package.json +2 -3
  32. package/ts_build/src/agents/base/base.js +10 -0
  33. package/ts_build/src/agents/base/base.js.map +1 -1
  34. package/ts_build/src/agents/tools/index.d.ts +0 -1
  35. package/ts_build/src/agents/tools/index.js +0 -1
  36. package/ts_build/src/agents/tools/index.js.map +1 -1
  37. package/ts_build/src/agents/tools/list.js +0 -2
  38. package/ts_build/src/agents/tools/list.js.map +1 -1
  39. package/ts_build/src/chat/CliChatService.js +10 -1
  40. package/ts_build/src/chat/CliChatService.js.map +1 -1
  41. package/ts_build/src/chat/renderer/CompactRenderer.d.ts +4 -0
  42. package/ts_build/src/chat/renderer/CompactRenderer.js +16 -0
  43. package/ts_build/src/chat/renderer/CompactRenderer.js.map +1 -1
  44. package/ts_build/src/chat/renderer/ConsoleRenderer.d.ts +4 -0
  45. package/ts_build/src/chat/renderer/ConsoleRenderer.js +16 -0
  46. package/ts_build/src/chat/renderer/ConsoleRenderer.js.map +1 -1
  47. package/ts_build/src/chat/renderer/FancyRenderer.d.ts +4 -0
  48. package/ts_build/src/chat/renderer/FancyRenderer.js +16 -0
  49. package/ts_build/src/chat/renderer/FancyRenderer.js.map +1 -1
  50. package/ts_build/src/chat/renderer/types.d.ts +2 -0
  51. package/ts_build/src/cli.js +40 -525
  52. package/ts_build/src/cli.js.map +1 -1
  53. package/ts_build/src/clients/types.d.ts +2 -2
  54. package/ts_build/src/commands/agent.d.ts +6 -0
  55. package/ts_build/src/commands/agent.js +229 -0
  56. package/ts_build/src/commands/agent.js.map +1 -0
  57. package/ts_build/src/commands/misc.d.ts +10 -0
  58. package/ts_build/src/commands/misc.js +195 -0
  59. package/ts_build/src/commands/misc.js.map +1 -0
  60. package/ts_build/src/commands/modules.d.ts +3 -0
  61. package/ts_build/src/commands/modules.js +160 -0
  62. package/ts_build/src/commands/modules.js.map +1 -0
  63. package/ts_build/src/commands/services.d.ts +5 -0
  64. package/ts_build/src/commands/services.js +86 -0
  65. package/ts_build/src/commands/services.js.map +1 -0
  66. package/ts_build/src/commands/workers.d.ts +6 -0
  67. package/ts_build/src/commands/workers.js +163 -0
  68. package/ts_build/src/commands/workers.js.map +1 -0
  69. package/ts_build/src/config.d.ts +1 -0
  70. package/ts_build/src/config.js +32 -0
  71. package/ts_build/src/config.js.map +1 -1
  72. package/ts_build/src/index.d.ts +1 -0
  73. package/ts_build/src/index.js +3 -1
  74. package/ts_build/src/index.js.map +1 -1
  75. package/ts_build/src/plugins/plugins.d.ts +0 -2
  76. package/ts_build/src/plugins/plugins.js +0 -11
  77. package/ts_build/src/plugins/plugins.js.map +1 -1
  78. package/ts_build/src/processors/JsonCompressor.js +4 -4
  79. package/ts_build/src/processors/JsonCompressor.js.map +1 -1
  80. package/ts_build/src/services/modules/index.d.ts +33 -0
  81. package/ts_build/src/services/modules/index.js +38 -42
  82. package/ts_build/src/services/modules/index.js.map +1 -1
  83. package/ts_build/src/services/modules/types.d.ts +2 -0
  84. package/ts_build/src/tunnel.d.ts +27 -0
  85. package/ts_build/src/tunnel.js +112 -0
  86. package/ts_build/src/tunnel.js.map +1 -0
  87. package/ts_build/src/types.d.ts +0 -1
  88. package/ts_build/src/types.js.map +1 -1
  89. package/ts_build/src/worker.d.ts +1 -4
  90. package/ts_build/src/worker.js +38 -244
  91. package/ts_build/src/worker.js.map +1 -1
  92. package/ts_build/src/workers/auth/WsMiddleware.d.ts +8 -0
  93. package/ts_build/src/workers/auth/WsMiddleware.js +65 -0
  94. package/ts_build/src/workers/auth/WsMiddleware.js.map +1 -0
  95. package/ts_build/src/workers/auth/authMiddleware.d.ts +3 -0
  96. package/ts_build/src/workers/auth/authMiddleware.js +60 -0
  97. package/ts_build/src/workers/auth/authMiddleware.js.map +1 -0
  98. package/ts_build/src/workers/auth/types.d.ts +8 -1
  99. package/ts_build/tests/unit/modules/moduleLoading.test.js +0 -19
  100. package/ts_build/tests/unit/modules/moduleLoading.test.js.map +1 -1
  101. package/ts_build/tests/unit/plugins/pluginLoading.test.js +0 -65
  102. package/ts_build/tests/unit/plugins/pluginLoading.test.js.map +1 -1
  103. package/src/agents/tools/executeScript/README.md +0 -94
  104. package/src/agents/tools/executeScript/definition.ts +0 -79
  105. package/src/agents/tools/executeScript/examples/dependency-injection-validation.ts +0 -272
  106. package/src/agents/tools/executeScript/examples/quick-test.ts +0 -74
  107. package/src/agents/tools/executeScript/examples/serialization-test.ts +0 -321
  108. package/src/agents/tools/executeScript/examples/test-runner.ts +0 -197
  109. package/src/agents/tools/executeScript/index.ts +0 -98
  110. package/src/services/script-execution/SandboxContext.ts +0 -282
  111. package/src/services/script-execution/ScriptExecutor.ts +0 -441
  112. package/src/services/script-execution/ScriptPolicy.ts +0 -194
  113. package/src/services/script-execution/ScriptTracer.ts +0 -249
  114. package/src/services/script-execution/types.ts +0 -134
  115. package/ts_build/src/agents/tools/executeScript/definition.d.ts +0 -2
  116. package/ts_build/src/agents/tools/executeScript/definition.js +0 -76
  117. package/ts_build/src/agents/tools/executeScript/definition.js.map +0 -1
  118. package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.d.ts +0 -18
  119. package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.js +0 -192
  120. package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.js.map +0 -1
  121. package/ts_build/src/agents/tools/executeScript/examples/quick-test.d.ts +0 -3
  122. package/ts_build/src/agents/tools/executeScript/examples/quick-test.js +0 -64
  123. package/ts_build/src/agents/tools/executeScript/examples/quick-test.js.map +0 -1
  124. package/ts_build/src/agents/tools/executeScript/examples/serialization-test.d.ts +0 -15
  125. package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js +0 -266
  126. package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js.map +0 -1
  127. package/ts_build/src/agents/tools/executeScript/examples/test-runner.d.ts +0 -4
  128. package/ts_build/src/agents/tools/executeScript/examples/test-runner.js +0 -208
  129. package/ts_build/src/agents/tools/executeScript/examples/test-runner.js.map +0 -1
  130. package/ts_build/src/agents/tools/executeScript/index.d.ts +0 -28
  131. package/ts_build/src/agents/tools/executeScript/index.js +0 -72
  132. package/ts_build/src/agents/tools/executeScript/index.js.map +0 -1
  133. package/ts_build/src/services/script-execution/SandboxContext.d.ts +0 -34
  134. package/ts_build/src/services/script-execution/SandboxContext.js +0 -189
  135. package/ts_build/src/services/script-execution/SandboxContext.js.map +0 -1
  136. package/ts_build/src/services/script-execution/ScriptExecutor.d.ts +0 -19
  137. package/ts_build/src/services/script-execution/ScriptExecutor.js +0 -269
  138. package/ts_build/src/services/script-execution/ScriptExecutor.js.map +0 -1
  139. package/ts_build/src/services/script-execution/ScriptPolicy.d.ts +0 -28
  140. package/ts_build/src/services/script-execution/ScriptPolicy.js +0 -115
  141. package/ts_build/src/services/script-execution/ScriptPolicy.js.map +0 -1
  142. package/ts_build/src/services/script-execution/ScriptTracer.d.ts +0 -19
  143. package/ts_build/src/services/script-execution/ScriptTracer.js +0 -186
  144. package/ts_build/src/services/script-execution/ScriptTracer.js.map +0 -1
  145. package/ts_build/src/services/script-execution/types.d.ts +0 -108
  146. package/ts_build/src/services/script-execution/types.js +0 -3
  147. package/ts_build/src/services/script-execution/types.js.map +0 -1
@@ -1,321 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- /**
3
- * Serialization Test for executeScript - demonstrates transfer issues
4
- * Usage: npx ts-node src/agents/tools/executeScript/examples/serialization-test.ts
5
- *
6
- * This test demonstrates the "A non-transferable value was passed" errors
7
- * that occur when trying to return complex objects from executeScript.
8
- */
9
-
10
- import { executeScript } from "../../executeScript";
11
- import { services } from "../../../../services";
12
-
13
- interface TestCase {
14
- name: string;
15
- script: string;
16
- expectedToWork: boolean;
17
- description: string;
18
- }
19
-
20
- const testCases: TestCase[] = [
21
- {
22
- name: "primitive-string",
23
- expectedToWork: true,
24
- description: "Simple string return - should work",
25
- script: `
26
- console.log("Testing primitive string return");
27
- return "Hello World";
28
- `,
29
- },
30
-
31
- {
32
- name: "primitive-number",
33
- expectedToWork: true,
34
- description: "Simple number return - should work",
35
- script: `
36
- console.log("Testing primitive number return");
37
- return 42;
38
- `,
39
- },
40
-
41
- {
42
- name: "primitive-boolean",
43
- expectedToWork: true,
44
- description: "Simple boolean return - should work",
45
- script: `
46
- console.log("Testing primitive boolean return");
47
- return true;
48
- `,
49
- },
50
-
51
- {
52
- name: "simple-array",
53
- expectedToWork: true, // You mentioned this works
54
- description: "Simple array return - you said this works",
55
- script: `
56
- console.log("Testing simple array return");
57
- return [1, 2, 3, "hello"];
58
- `,
59
- },
60
-
61
- {
62
- name: "simple-object",
63
- expectedToWork: false, // This is where I got errors
64
- description:
65
- "Simple object return - expected to fail with transferable error",
66
- script: `
67
- console.log("Testing simple object return");
68
- return {
69
- message: "Hello",
70
- count: 42,
71
- success: true
72
- };
73
- `,
74
- },
75
-
76
- {
77
- name: "nested-object",
78
- expectedToWork: false,
79
- description: "Nested object return - expected to fail",
80
- script: `
81
- console.log("Testing nested object return");
82
- return {
83
- data: {
84
- items: [1, 2, 3],
85
- metadata: { timestamp: new Date().toISOString() }
86
- },
87
- status: "success"
88
- };
89
- `,
90
- },
91
-
92
- {
93
- name: "object-with-functions",
94
- expectedToWork: false,
95
- description: "Object with functions - definitely should fail",
96
- script: `
97
- console.log("Testing object with functions");
98
- return {
99
- data: [1, 2, 3],
100
- transform: function(x) { return x * 2; },
101
- helper: () => "test"
102
- };
103
- `,
104
- },
105
-
106
- {
107
- name: "array-of-objects",
108
- expectedToWork: false, // Based on my experience
109
- description: "Array containing objects - expected to fail",
110
- script: `
111
- console.log("Testing array of objects");
112
- return [
113
- { id: 1, name: "Alice" },
114
- { id: 2, name: "Bob" },
115
- { id: 3, name: "Charlie" }
116
- ];
117
- `,
118
- },
119
-
120
- {
121
- name: "json-stringify-workaround",
122
- expectedToWork: true,
123
- description: "Using JSON.stringify as workaround - should work",
124
- script: `
125
- console.log("Testing JSON.stringify workaround");
126
- const data = {
127
- message: "Hello",
128
- items: [1, 2, 3],
129
- nested: { key: "value" }
130
- };
131
- return JSON.stringify(data);
132
- `,
133
- },
134
-
135
- {
136
- name: "tool-call-result",
137
- expectedToWork: false, // Based on my experience with news aggregation
138
- description: "Tool call result object - expected to fail",
139
- script: `
140
- console.log("Testing tool call result return");
141
-
142
- try {
143
- const searchResult = await callTool("fileSearch", { searchTerm: "package.json" });
144
-
145
- // Try to return a structured response with the tool result
146
- return {
147
- success: true,
148
- toolResult: searchResult,
149
- timestamp: new Date().toISOString()
150
- };
151
- } catch (error) {
152
- return {
153
- success: false,
154
- error: error.message
155
- };
156
- }
157
- `,
158
- },
159
-
160
- {
161
- name: "date-object",
162
- expectedToWork: false,
163
- description: "Date object return - expected to fail",
164
- script: `
165
- console.log("Testing Date object return");
166
- return new Date();
167
- `,
168
- },
169
-
170
- {
171
- name: "map-object",
172
- expectedToWork: false,
173
- description: "Map object return - expected to fail",
174
- script: `
175
- console.log("Testing Map object return");
176
- const map = new Map();
177
- map.set("key1", "value1");
178
- map.set("key2", "value2");
179
- return map;
180
- `,
181
- },
182
- ];
183
-
184
- async function runSerializationTests() {
185
- console.log("🧪 Running executeScript Serialization Tests\\n");
186
- console.log("=".repeat(80));
187
-
188
- const results = {
189
- passed: 0,
190
- failed: 0,
191
- unexpected: 0,
192
- details: [] as any[],
193
- };
194
-
195
- for (const testCase of testCases) {
196
- console.log(`\\nšŸ“‹ Testing: ${testCase.name}`);
197
- console.log(`šŸ“ Description: ${testCase.description}`);
198
- console.log(`šŸŽÆ Expected to work: ${testCase.expectedToWork}`);
199
-
200
- try {
201
- const result = await executeScript({
202
- script: testCase.script,
203
- maxToolCalls: 5,
204
- maxTokens: 500,
205
- maxExecutionTimeMs: 10000,
206
- maxCostUsd: 0.1,
207
- });
208
-
209
- const actualWorked = result.success;
210
- const matchesExpectation = actualWorked === testCase.expectedToWork;
211
-
212
- if (matchesExpectation) {
213
- results.passed++;
214
- console.log(`āœ… PASS - Behaved as expected`);
215
- } else {
216
- results.unexpected++;
217
- console.log(
218
- `āš ļø UNEXPECTED - Expected ${
219
- testCase.expectedToWork ? "success" : "failure"
220
- }, got ${actualWorked ? "success" : "failure"}`
221
- );
222
- }
223
-
224
- results.details.push({
225
- name: testCase.name,
226
- expected: testCase.expectedToWork,
227
- actual: actualWorked,
228
- matches: matchesExpectation,
229
- result: actualWorked ? result.result : null,
230
- error: actualWorked ? null : result.error,
231
- consoleOutput: result.consoleOutput,
232
- });
233
-
234
- if (actualWorked) {
235
- console.log(`šŸ“Š Result type: ${typeof result.result}`);
236
- console.log(
237
- `šŸ“Š Result: ${JSON.stringify(result.result).substring(0, 200)}${
238
- JSON.stringify(result.result).length > 200 ? "..." : ""
239
- }`
240
- );
241
- } else {
242
- console.log(`āŒ Error: ${result.error}`);
243
- }
244
-
245
- if (result.consoleOutput.length > 0) {
246
- console.log(`šŸ“ Console: ${result.consoleOutput.join(", ")}`);
247
- }
248
- } catch (error) {
249
- results.failed++;
250
- console.log(`šŸ’„ TEST FRAMEWORK ERROR: ${error.message}`);
251
-
252
- results.details.push({
253
- name: testCase.name,
254
- expected: testCase.expectedToWork,
255
- actual: false,
256
- matches: !testCase.expectedToWork,
257
- result: null,
258
- error: error.message,
259
- consoleOutput: [],
260
- });
261
- }
262
- }
263
-
264
- // Print summary
265
- console.log("\\n" + "=".repeat(80));
266
- console.log("šŸ“Š SERIALIZATION TEST SUMMARY");
267
- console.log("=".repeat(80));
268
- console.log(`āœ… Tests matching expectations: ${results.passed}`);
269
- console.log(`āš ļø Unexpected behaviors: ${results.unexpected}`);
270
- console.log(`šŸ’„ Framework failures: ${results.failed}`);
271
- console.log(`šŸ“‹ Total tests: ${testCases.length}`);
272
-
273
- if (results.unexpected > 0) {
274
- console.log("\\nšŸ” UNEXPECTED RESULTS:");
275
- results.details
276
- .filter((d) => !d.matches)
277
- .forEach((detail) => {
278
- console.log(
279
- ` - ${detail.name}: Expected ${
280
- detail.expected ? "success" : "failure"
281
- }, got ${detail.actual ? "success" : "failure"}`
282
- );
283
- if (detail.error) {
284
- console.log(` Error: ${detail.error}`);
285
- }
286
- });
287
- }
288
-
289
- // Analysis and recommendations
290
- console.log("\\nšŸ”¬ ANALYSIS:");
291
-
292
- const workingTypes = results.details
293
- .filter((d) => d.actual)
294
- .map((d) => d.name);
295
- const failingTypes = results.details
296
- .filter((d) => !d.actual)
297
- .map((d) => d.name);
298
-
299
- console.log("\\nāœ… Types that work:");
300
- workingTypes.forEach((name) => console.log(` - ${name}`));
301
-
302
- console.log("\\nāŒ Types that fail:");
303
- failingTypes.forEach((name) => console.log(` - ${name}`));
304
-
305
- console.log("\\nšŸ’” RECOMMENDATIONS:");
306
- console.log(" 1. Use JSON.stringify() for complex objects");
307
- console.log(" 2. Return primitive values when possible");
308
- console.log(" 3. Consider createArtifact() for structured data");
309
- console.log(" 4. Test your return types with this suite");
310
-
311
- return results;
312
- }
313
-
314
- if (require.main === module) {
315
- runSerializationTests().catch((error) => {
316
- console.error("Test suite failed:", error);
317
- process.exit(1);
318
- });
319
- }
320
-
321
- export { runSerializationTests, testCases };
@@ -1,197 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- /**
3
- * Test runner for the executeScript tool
4
- * Usage: npx ts-node src/agents/tools/executeScript/examples/test-runner.ts
5
- */
6
-
7
- import { executeScript } from "../../executeScript";
8
- import { services } from "../../../../services";
9
- import { Clients } from "../../../../clients";
10
- import { includedTools } from "../../../tools/list";
11
- import * as allTools from "../../../tools";
12
-
13
- // Sample script to test with
14
- const testScript = `
15
- // Test script that demonstrates various executeScript capabilities
16
- console.log("Starting test script execution...");
17
-
18
- async function main() {
19
- // Test 1: Simple console output
20
- console.log("Test 1: Basic logging works");
21
-
22
- // Test 2: Call a tool (file search)
23
- try {
24
- console.log("Test 2: Calling fileSearch tool...");
25
- const searchResult = await callTool("fileSearch", {
26
- searchTerm: "package.json"
27
- });
28
- console.log("File search result:", searchResult);
29
- } catch (error) {
30
- console.error("Tool call failed:", error.message);
31
- }
32
-
33
- // Test 3: Call another tool (text search)
34
- try {
35
- console.log("Test 3: Calling textSearch tool...");
36
- const textResult = await callTool("textSearch", {
37
- searchTerm: "executeScript"
38
- });
39
- console.log("Text search found", textResult?.length || 0, "matches");
40
- } catch (error) {
41
- console.error("Text search failed:", error.message);
42
- }
43
-
44
- // Test 4: Make an LLM call
45
- try {
46
- console.log("Test 4: Making LLM call...");
47
- const llmResponse = await llm([
48
- {
49
- role: "system",
50
- content: "You are a helpful assistant. Respond with exactly one sentence."
51
- },
52
- {
53
- role: "user",
54
- content: "What is 2+2? Just give the answer briefly."
55
- }
56
- ], {
57
- model: "gpt-4o-mini",
58
- max_tokens: 50
59
- });
60
-
61
- console.log("LLM Response:", llmResponse.choices[0].message.content);
62
- } catch (error) {
63
- console.error("LLM call failed:", error.message);
64
- }
65
-
66
- // Test 5: Create an artifact
67
- try {
68
- console.log("Test 5: Creating artifact...");
69
- createArtifact("test-results.md", \`# Test Results
70
-
71
- Script executed successfully at: \${new Date().toISOString()}
72
-
73
- This is a test artifact created by the executeScript tool.
74
-
75
- ## Test Summary
76
- - Console logging: āœ“
77
- - Tool calls: āœ“
78
- - LLM calls: āœ“
79
- - Artifact creation: āœ“
80
- \`, "markdown");
81
- console.log("Artifact created successfully");
82
- } catch (error) {
83
- console.error("Artifact creation failed:", error.message);
84
- }
85
-
86
- // Return final result
87
- return {
88
- success: true,
89
- message: "All tests completed successfully",
90
- timestamp: new Date().toISOString(),
91
- testsRun: 5
92
- };
93
- }
94
-
95
- // Execute the main function
96
- await main().then(result => {
97
- console.log("=== SCRIPT COMPLETED ===");
98
- console.log("Final result:", JSON.stringify(result, null, 2));
99
- }).catch(error => {
100
- console.error("=== SCRIPT FAILED ===");
101
- console.error("Error:", error);
102
- throw error;
103
- });
104
- `;
105
-
106
- async function runTest() {
107
- console.log("šŸš€ Starting executeScript test...\n");
108
- const { Tools } = services();
109
-
110
- try {
111
- Tools.defineTools(includedTools, allTools);
112
-
113
- console.log("šŸ“‹ Test Parameters:");
114
- console.log("- Max Tool Calls: 10");
115
- console.log("- Max Tokens: 1000");
116
- console.log("- Max Execution Time: 60s");
117
- console.log("- Max Cost: $0.50\n");
118
-
119
- const startTime = Date.now();
120
-
121
- // Execute the test script
122
- const result = await executeScript({
123
- script: testScript,
124
- maxToolCalls: 10,
125
- maxTokens: 1000,
126
- maxExecutionTimeMs: 60000,
127
- maxCostUsd: 0.5,
128
- });
129
-
130
- const executionTime = Date.now() - startTime;
131
-
132
- console.log("\n" + "=".repeat(60));
133
- console.log("šŸŽÆ TEST RESULTS");
134
- console.log("=".repeat(60));
135
- console.log(`ā±ļø Execution Time: ${executionTime}ms`);
136
- console.log(`āœ… Success: ${result.success}`);
137
-
138
- if (result.success) {
139
- console.log(`šŸ“Š Result:`, result.result);
140
- console.log(`šŸ”§ Tool Calls Made: ${result.quotaUsage.toolCalls}`);
141
- console.log(`šŸŽÆ Tokens Used: ${result.quotaUsage.tokens}`);
142
- console.log(`šŸ’° Cost: $${result.quotaUsage.costUsd.toFixed(4)}`);
143
-
144
- if (result.artifacts.length > 0) {
145
- console.log(`šŸ“ Artifacts Created: ${result.artifacts.length}`);
146
- result.artifacts.forEach((artifact) => {
147
- console.log(
148
- ` - ${artifact.name} (${artifact.type}, ${artifact.contentLength} bytes)`
149
- );
150
- });
151
- }
152
-
153
- if (result.consoleOutput.length > 0) {
154
- console.log(
155
- `\nšŸ“ Console Output (${result.consoleOutput.length} entries):`
156
- );
157
- result.consoleOutput.forEach((entry) => {
158
- console.log(` ${entry}`);
159
- });
160
- }
161
-
162
- if (result.violations.length > 0) {
163
- console.log(`\nāš ļø Policy Violations: ${result.violations.length}`);
164
- result.violations.forEach((violation) => {
165
- console.log(` - ${JSON.stringify(violation)}`);
166
- });
167
- }
168
- } else {
169
- console.log(`āŒ Error: ${result.error}`);
170
-
171
- if (result.consoleOutput.length > 0) {
172
- console.log(`\nšŸ“ Console Output Before Failure:`);
173
- result.consoleOutput.forEach((entry) => {
174
- console.log(` ${entry}`);
175
- });
176
- }
177
- }
178
-
179
- console.log("\n" + "=".repeat(60));
180
- console.log(result.success ? "šŸŽ‰ TEST PASSED!" : "šŸ’„ TEST FAILED!");
181
- console.log("=".repeat(60));
182
- } catch (error) {
183
- console.error("\nšŸ’„ TEST RUNNER ERROR:");
184
- console.error(error);
185
- process.exit(1);
186
- }
187
- }
188
-
189
- // Run the test if this file is executed directly
190
- if (require.main === module) {
191
- runTest().catch((error) => {
192
- console.error("Unhandled error:", error);
193
- process.exit(1);
194
- });
195
- }
196
-
197
- export { runTest, testScript };
@@ -1,98 +0,0 @@
1
- import { ScriptExecutor } from "../../../services/script-execution/ScriptExecutor";
2
- import { ToolsService } from "../../../services/Tools";
3
- import {
4
- ExecutionRequest,
5
- ExecutionResult,
6
- } from "../../../services/script-execution/types";
7
- import { services } from "../../../services";
8
-
9
- export async function executeScript({
10
- script,
11
- maxToolCalls,
12
- maxTokens,
13
- maxExecutionTimeMs,
14
- maxCostUsd,
15
- allowNetworkAccess,
16
- }: {
17
- script: string;
18
- maxToolCalls?: number;
19
- maxTokens?: number;
20
- maxExecutionTimeMs?: number;
21
- maxCostUsd?: number;
22
- allowNetworkAccess?: boolean;
23
- }) {
24
- try {
25
- // Get context from bound ToolsService
26
- const toolService = (
27
- this instanceof ToolsService ? this : services().Tools
28
- ) as ToolsService;
29
- const toolContext = toolService.getContext();
30
- const { Clients, Tools } = toolContext;
31
-
32
- if (!Clients) {
33
- throw new Error("Clients not available in tool context");
34
- }
35
-
36
- // Create script executor with access to tools and clients
37
- const executor = new ScriptExecutor(Tools, Clients);
38
-
39
- // Execute the script
40
- const result = await executor.execute({
41
- script,
42
- quotas: {
43
- maxToolCalls: maxToolCalls || 50,
44
- maxTokens: maxTokens || 10000,
45
- maxExecutionTimeMs: maxExecutionTimeMs || 30000,
46
- maxCostUsd: maxCostUsd || 1.0,
47
- maxMemoryMb: 100,
48
- },
49
- policy: {
50
- allowNetworkAccess: allowNetworkAccess ?? false,
51
- },
52
- });
53
-
54
- // If there were policy violations, include them in the response
55
- const violations = result.trace.events
56
- .filter((e) => e.type.includes("violation") || e.type.includes("error"))
57
- .map((e) => e.data);
58
-
59
- // Format the response
60
- return {
61
- success: result.success,
62
- result: result.result,
63
- error: result.error,
64
- artifacts: result.artifacts.map((a) => ({
65
- id: a.id,
66
- name: a.name,
67
- type: a.type,
68
- contentLength: a.content.length,
69
- createdAt: a.createdAt,
70
- })),
71
- consoleOutput: result.consoleOutput,
72
- metrics: result.trace.metrics,
73
- violations,
74
- executionTimeMs: result.trace.endTime - result.trace.startTime,
75
- quotaUsage: {
76
- toolCalls: result.trace.metrics.toolCallCount,
77
- tokens: result.trace.metrics.tokenUsage.total,
78
- costUsd: result.trace.metrics.costUsd,
79
- },
80
- };
81
- } catch (error) {
82
- return {
83
- success: false,
84
- error: error instanceof Error ? error.message : String(error),
85
- result: null,
86
- artifacts: [],
87
- consoleOutput: [],
88
- metrics: null,
89
- violations: [],
90
- executionTimeMs: 0,
91
- quotaUsage: {
92
- toolCalls: 0,
93
- tokens: 0,
94
- costUsd: 0,
95
- },
96
- };
97
- }
98
- }