@tyvm/knowhow 0.0.21 → 0.0.22
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/package.json +3 -1
- package/src/agents/tools/executeScript/README.md +78 -0
- package/src/agents/tools/executeScript/definition.ts +73 -0
- package/src/agents/tools/executeScript/examples/quick-test.ts +80 -0
- package/src/agents/tools/executeScript/examples/serialization-test.ts +309 -0
- package/src/agents/tools/executeScript/examples/test-runner.ts +204 -0
- package/src/agents/tools/executeScript/index.ts +74 -0
- package/src/agents/tools/index.ts +1 -0
- package/src/agents/tools/list.ts +2 -1
- package/src/cli.ts +2 -6
- package/src/clients/index.ts +23 -9
- package/src/services/Tools.ts +19 -3
- package/src/services/script-execution/SandboxContext.ts +278 -0
- package/src/services/script-execution/ScriptExecutor.ts +337 -0
- package/src/services/script-execution/ScriptPolicy.ts +236 -0
- package/src/services/script-execution/ScriptTracer.ts +249 -0
- package/src/services/script-execution/types.ts +134 -0
- package/ts_build/src/agents/tools/executeScript/definition.d.ts +2 -0
- package/ts_build/src/agents/tools/executeScript/definition.js +70 -0
- package/ts_build/src/agents/tools/executeScript/definition.js.map +1 -0
- package/ts_build/src/agents/tools/executeScript/examples/quick-test.d.ts +3 -0
- package/ts_build/src/agents/tools/executeScript/examples/quick-test.js +68 -0
- package/ts_build/src/agents/tools/executeScript/examples/quick-test.js.map +1 -0
- package/ts_build/src/agents/tools/executeScript/examples/serialization-test.d.ts +15 -0
- package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js +267 -0
- package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js.map +1 -0
- package/ts_build/src/agents/tools/executeScript/examples/simple-example.d.ts +20 -0
- package/ts_build/src/agents/tools/executeScript/examples/simple-example.js +35 -0
- package/ts_build/src/agents/tools/executeScript/examples/simple-example.js.map +1 -0
- package/ts_build/src/agents/tools/executeScript/examples/test-runner.d.ts +4 -0
- package/ts_build/src/agents/tools/executeScript/examples/test-runner.js +202 -0
- package/ts_build/src/agents/tools/executeScript/examples/test-runner.js.map +1 -0
- package/ts_build/src/agents/tools/executeScript/handler.d.ts +27 -0
- package/ts_build/src/agents/tools/executeScript/handler.js +64 -0
- package/ts_build/src/agents/tools/executeScript/handler.js.map +1 -0
- package/ts_build/src/agents/tools/executeScript/index.d.ts +27 -0
- package/ts_build/src/agents/tools/executeScript/index.js +64 -0
- package/ts_build/src/agents/tools/executeScript/index.js.map +1 -0
- package/ts_build/src/agents/tools/executeScript.d.ts +29 -0
- package/ts_build/src/agents/tools/executeScript.js +124 -0
- package/ts_build/src/agents/tools/executeScript.js.map +1 -0
- package/ts_build/src/agents/tools/index.d.ts +1 -0
- package/ts_build/src/agents/tools/index.js +1 -0
- package/ts_build/src/agents/tools/index.js.map +1 -1
- package/ts_build/src/agents/tools/list.js +2 -0
- package/ts_build/src/agents/tools/list.js.map +1 -1
- package/ts_build/src/cli.js +2 -6
- package/ts_build/src/cli.js.map +1 -1
- package/ts_build/src/clients/index.d.ts +9 -2
- package/ts_build/src/clients/index.js +17 -4
- package/ts_build/src/clients/index.js.map +1 -1
- package/ts_build/src/services/Tools.d.ts +3 -0
- package/ts_build/src/services/Tools.js +10 -2
- package/ts_build/src/services/Tools.js.map +1 -1
- package/ts_build/src/services/script-execution/SandboxContext.d.ts +34 -0
- package/ts_build/src/services/script-execution/SandboxContext.js +188 -0
- package/ts_build/src/services/script-execution/SandboxContext.js.map +1 -0
- package/ts_build/src/services/script-execution/ScriptExecutor.d.ts +17 -0
- package/ts_build/src/services/script-execution/ScriptExecutor.js +207 -0
- package/ts_build/src/services/script-execution/ScriptExecutor.js.map +1 -0
- package/ts_build/src/services/script-execution/ScriptPolicy.d.ts +27 -0
- package/ts_build/src/services/script-execution/ScriptPolicy.js +150 -0
- package/ts_build/src/services/script-execution/ScriptPolicy.js.map +1 -0
- package/ts_build/src/services/script-execution/ScriptTracer.d.ts +19 -0
- package/ts_build/src/services/script-execution/ScriptTracer.js +186 -0
- package/ts_build/src/services/script-execution/ScriptTracer.js.map +1 -0
- package/ts_build/src/services/script-execution/types.d.ts +108 -0
- package/ts_build/src/services/script-execution/types.js +3 -0
- package/ts_build/src/services/script-execution/types.js.map +1 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.testCases = exports.runSerializationTests = void 0;
|
|
5
|
+
const executeScript_1 = require("../../executeScript");
|
|
6
|
+
const services_1 = require("../../../../services");
|
|
7
|
+
const clients_1 = require("../../../../clients");
|
|
8
|
+
const testCases = [
|
|
9
|
+
{
|
|
10
|
+
name: "primitive-string",
|
|
11
|
+
expectedToWork: true,
|
|
12
|
+
description: "Simple string return - should work",
|
|
13
|
+
script: `
|
|
14
|
+
console.log("Testing primitive string return");
|
|
15
|
+
return "Hello World";
|
|
16
|
+
`
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "primitive-number",
|
|
20
|
+
expectedToWork: true,
|
|
21
|
+
description: "Simple number return - should work",
|
|
22
|
+
script: `
|
|
23
|
+
console.log("Testing primitive number return");
|
|
24
|
+
return 42;
|
|
25
|
+
`
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "primitive-boolean",
|
|
29
|
+
expectedToWork: true,
|
|
30
|
+
description: "Simple boolean return - should work",
|
|
31
|
+
script: `
|
|
32
|
+
console.log("Testing primitive boolean return");
|
|
33
|
+
return true;
|
|
34
|
+
`
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "simple-array",
|
|
38
|
+
expectedToWork: true,
|
|
39
|
+
description: "Simple array return - you said this works",
|
|
40
|
+
script: `
|
|
41
|
+
console.log("Testing simple array return");
|
|
42
|
+
return [1, 2, 3, "hello"];
|
|
43
|
+
`
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "simple-object",
|
|
47
|
+
expectedToWork: false,
|
|
48
|
+
description: "Simple object return - expected to fail with transferable error",
|
|
49
|
+
script: `
|
|
50
|
+
console.log("Testing simple object return");
|
|
51
|
+
return {
|
|
52
|
+
message: "Hello",
|
|
53
|
+
count: 42,
|
|
54
|
+
success: true
|
|
55
|
+
};
|
|
56
|
+
`
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "nested-object",
|
|
60
|
+
expectedToWork: false,
|
|
61
|
+
description: "Nested object return - expected to fail",
|
|
62
|
+
script: `
|
|
63
|
+
console.log("Testing nested object return");
|
|
64
|
+
return {
|
|
65
|
+
data: {
|
|
66
|
+
items: [1, 2, 3],
|
|
67
|
+
metadata: { timestamp: new Date().toISOString() }
|
|
68
|
+
},
|
|
69
|
+
status: "success"
|
|
70
|
+
};
|
|
71
|
+
`
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "object-with-functions",
|
|
75
|
+
expectedToWork: false,
|
|
76
|
+
description: "Object with functions - definitely should fail",
|
|
77
|
+
script: `
|
|
78
|
+
console.log("Testing object with functions");
|
|
79
|
+
return {
|
|
80
|
+
data: [1, 2, 3],
|
|
81
|
+
transform: function(x) { return x * 2; },
|
|
82
|
+
helper: () => "test"
|
|
83
|
+
};
|
|
84
|
+
`
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "array-of-objects",
|
|
88
|
+
expectedToWork: false,
|
|
89
|
+
description: "Array containing objects - expected to fail",
|
|
90
|
+
script: `
|
|
91
|
+
console.log("Testing array of objects");
|
|
92
|
+
return [
|
|
93
|
+
{ id: 1, name: "Alice" },
|
|
94
|
+
{ id: 2, name: "Bob" },
|
|
95
|
+
{ id: 3, name: "Charlie" }
|
|
96
|
+
];
|
|
97
|
+
`
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "json-stringify-workaround",
|
|
101
|
+
expectedToWork: true,
|
|
102
|
+
description: "Using JSON.stringify as workaround - should work",
|
|
103
|
+
script: `
|
|
104
|
+
console.log("Testing JSON.stringify workaround");
|
|
105
|
+
const data = {
|
|
106
|
+
message: "Hello",
|
|
107
|
+
items: [1, 2, 3],
|
|
108
|
+
nested: { key: "value" }
|
|
109
|
+
};
|
|
110
|
+
return JSON.stringify(data);
|
|
111
|
+
`
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "tool-call-result",
|
|
115
|
+
expectedToWork: false,
|
|
116
|
+
description: "Tool call result object - expected to fail",
|
|
117
|
+
script: `
|
|
118
|
+
console.log("Testing tool call result return");
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const searchResult = await callTool("fileSearch", { searchTerm: "package.json" });
|
|
122
|
+
|
|
123
|
+
// Try to return a structured response with the tool result
|
|
124
|
+
return {
|
|
125
|
+
success: true,
|
|
126
|
+
toolResult: searchResult,
|
|
127
|
+
timestamp: new Date().toISOString()
|
|
128
|
+
};
|
|
129
|
+
} catch (error) {
|
|
130
|
+
return {
|
|
131
|
+
success: false,
|
|
132
|
+
error: error.message
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
`
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "date-object",
|
|
139
|
+
expectedToWork: false,
|
|
140
|
+
description: "Date object return - expected to fail",
|
|
141
|
+
script: `
|
|
142
|
+
console.log("Testing Date object return");
|
|
143
|
+
return new Date();
|
|
144
|
+
`
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "map-object",
|
|
148
|
+
expectedToWork: false,
|
|
149
|
+
description: "Map object return - expected to fail",
|
|
150
|
+
script: `
|
|
151
|
+
console.log("Testing Map object return");
|
|
152
|
+
const map = new Map();
|
|
153
|
+
map.set("key1", "value1");
|
|
154
|
+
map.set("key2", "value2");
|
|
155
|
+
return map;
|
|
156
|
+
`
|
|
157
|
+
}
|
|
158
|
+
];
|
|
159
|
+
exports.testCases = testCases;
|
|
160
|
+
async function runSerializationTests() {
|
|
161
|
+
console.log("🧪 Running executeScript Serialization Tests\\n");
|
|
162
|
+
console.log("=".repeat(80));
|
|
163
|
+
const results = {
|
|
164
|
+
passed: 0,
|
|
165
|
+
failed: 0,
|
|
166
|
+
unexpected: 0,
|
|
167
|
+
details: []
|
|
168
|
+
};
|
|
169
|
+
for (const testCase of testCases) {
|
|
170
|
+
console.log(`\\n📋 Testing: ${testCase.name}`);
|
|
171
|
+
console.log(`📝 Description: ${testCase.description}`);
|
|
172
|
+
console.log(`🎯 Expected to work: ${testCase.expectedToWork}`);
|
|
173
|
+
try {
|
|
174
|
+
const result = await (0, executeScript_1.executeScript)({
|
|
175
|
+
script: testCase.script,
|
|
176
|
+
maxToolCalls: 5,
|
|
177
|
+
maxTokens: 500,
|
|
178
|
+
maxExecutionTimeMs: 10000,
|
|
179
|
+
maxCostUsd: 0.1
|
|
180
|
+
}, {
|
|
181
|
+
tools: services_1.Tools,
|
|
182
|
+
clients: clients_1.Clients,
|
|
183
|
+
});
|
|
184
|
+
const actualWorked = result.success;
|
|
185
|
+
const matchesExpectation = actualWorked === testCase.expectedToWork;
|
|
186
|
+
if (matchesExpectation) {
|
|
187
|
+
results.passed++;
|
|
188
|
+
console.log(`✅ PASS - Behaved as expected`);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
results.unexpected++;
|
|
192
|
+
console.log(`⚠️ UNEXPECTED - Expected ${testCase.expectedToWork ? 'success' : 'failure'}, got ${actualWorked ? 'success' : 'failure'}`);
|
|
193
|
+
}
|
|
194
|
+
results.details.push({
|
|
195
|
+
name: testCase.name,
|
|
196
|
+
expected: testCase.expectedToWork,
|
|
197
|
+
actual: actualWorked,
|
|
198
|
+
matches: matchesExpectation,
|
|
199
|
+
result: actualWorked ? result.result : null,
|
|
200
|
+
error: actualWorked ? null : result.error,
|
|
201
|
+
consoleOutput: result.consoleOutput
|
|
202
|
+
});
|
|
203
|
+
if (actualWorked) {
|
|
204
|
+
console.log(`📊 Result type: ${typeof result.result}`);
|
|
205
|
+
console.log(`📊 Result: ${JSON.stringify(result.result).substring(0, 200)}${JSON.stringify(result.result).length > 200 ? '...' : ''}`);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
console.log(`❌ Error: ${result.error}`);
|
|
209
|
+
}
|
|
210
|
+
if (result.consoleOutput.length > 0) {
|
|
211
|
+
console.log(`📝 Console: ${result.consoleOutput.join(', ')}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
results.failed++;
|
|
216
|
+
console.log(`💥 TEST FRAMEWORK ERROR: ${error.message}`);
|
|
217
|
+
results.details.push({
|
|
218
|
+
name: testCase.name,
|
|
219
|
+
expected: testCase.expectedToWork,
|
|
220
|
+
actual: false,
|
|
221
|
+
matches: !testCase.expectedToWork,
|
|
222
|
+
result: null,
|
|
223
|
+
error: error.message,
|
|
224
|
+
consoleOutput: []
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
console.log("\\n" + "=".repeat(80));
|
|
229
|
+
console.log("📊 SERIALIZATION TEST SUMMARY");
|
|
230
|
+
console.log("=".repeat(80));
|
|
231
|
+
console.log(`✅ Tests matching expectations: ${results.passed}`);
|
|
232
|
+
console.log(`⚠️ Unexpected behaviors: ${results.unexpected}`);
|
|
233
|
+
console.log(`💥 Framework failures: ${results.failed}`);
|
|
234
|
+
console.log(`📋 Total tests: ${testCases.length}`);
|
|
235
|
+
if (results.unexpected > 0) {
|
|
236
|
+
console.log("\\n🔍 UNEXPECTED RESULTS:");
|
|
237
|
+
results.details
|
|
238
|
+
.filter(d => !d.matches)
|
|
239
|
+
.forEach(detail => {
|
|
240
|
+
console.log(` - ${detail.name}: Expected ${detail.expected ? 'success' : 'failure'}, got ${detail.actual ? 'success' : 'failure'}`);
|
|
241
|
+
if (detail.error) {
|
|
242
|
+
console.log(` Error: ${detail.error}`);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
console.log("\\n🔬 ANALYSIS:");
|
|
247
|
+
const workingTypes = results.details.filter(d => d.actual).map(d => d.name);
|
|
248
|
+
const failingTypes = results.details.filter(d => !d.actual).map(d => d.name);
|
|
249
|
+
console.log("\\n✅ Types that work:");
|
|
250
|
+
workingTypes.forEach(name => console.log(` - ${name}`));
|
|
251
|
+
console.log("\\n❌ Types that fail:");
|
|
252
|
+
failingTypes.forEach(name => console.log(` - ${name}`));
|
|
253
|
+
console.log("\\n💡 RECOMMENDATIONS:");
|
|
254
|
+
console.log(" 1. Use JSON.stringify() for complex objects");
|
|
255
|
+
console.log(" 2. Return primitive values when possible");
|
|
256
|
+
console.log(" 3. Consider createArtifact() for structured data");
|
|
257
|
+
console.log(" 4. Test your return types with this suite");
|
|
258
|
+
return results;
|
|
259
|
+
}
|
|
260
|
+
exports.runSerializationTests = runSerializationTests;
|
|
261
|
+
if (require.main === module) {
|
|
262
|
+
runSerializationTests().catch(error => {
|
|
263
|
+
console.error("Test suite failed:", error);
|
|
264
|
+
process.exit(1);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=serialization-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization-test.js","sourceRoot":"","sources":["../../../../../../src/agents/tools/executeScript/examples/serialization-test.ts"],"names":[],"mappings":";;;;AASA,uDAAoD;AACpD,mDAA6C;AAC7C,iDAA8C;AAS9C,MAAM,SAAS,GAAe;IAC5B;QACE,IAAI,EAAE,kBAAkB;QACxB,cAAc,EAAE,IAAI;QACpB,WAAW,EAAE,oCAAoC;QACjD,MAAM,EAAE;;;KAGP;KACF;IAED;QACE,IAAI,EAAE,kBAAkB;QACxB,cAAc,EAAE,IAAI;QACpB,WAAW,EAAE,oCAAoC;QACjD,MAAM,EAAE;;;KAGP;KACF;IAED;QACE,IAAI,EAAE,mBAAmB;QACzB,cAAc,EAAE,IAAI;QACpB,WAAW,EAAE,qCAAqC;QAClD,MAAM,EAAE;;;KAGP;KACF;IAED;QACE,IAAI,EAAE,cAAc;QACpB,cAAc,EAAE,IAAI;QACpB,WAAW,EAAE,2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AAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare function callTool(name: string, args: any): Promise<any>;
|
|
2
|
+
declare function llm(messages: {
|
|
3
|
+
role: string;
|
|
4
|
+
content: string;
|
|
5
|
+
}[], options?: {
|
|
6
|
+
model?: string;
|
|
7
|
+
max_tokens?: number;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
choices: {
|
|
10
|
+
message: {
|
|
11
|
+
content: string;
|
|
12
|
+
};
|
|
13
|
+
}[];
|
|
14
|
+
}>;
|
|
15
|
+
declare function main(): Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
filesFound: any;
|
|
18
|
+
aiAnalysis: string;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
async function main() {
|
|
2
|
+
console.log("Starting example script execution...");
|
|
3
|
+
const fileSearchResult = await callTool("fileSearch", {
|
|
4
|
+
searchTerm: "package.json",
|
|
5
|
+
});
|
|
6
|
+
console.log("Found files:", fileSearchResult);
|
|
7
|
+
const analysis = await llm([
|
|
8
|
+
{
|
|
9
|
+
role: "system",
|
|
10
|
+
content: "You are a helpful assistant that analyzes file search results.",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
role: "user",
|
|
14
|
+
content: `Please analyze these file search results and provide a brief summary: ${JSON.stringify(fileSearchResult)}`,
|
|
15
|
+
},
|
|
16
|
+
], {
|
|
17
|
+
model: "gpt-4o-mini",
|
|
18
|
+
max_tokens: 200,
|
|
19
|
+
});
|
|
20
|
+
console.log("AI Analysis:", analysis.choices[0].message.content);
|
|
21
|
+
return {
|
|
22
|
+
success: true,
|
|
23
|
+
filesFound: fileSearchResult,
|
|
24
|
+
aiAnalysis: analysis.choices[0].message.content,
|
|
25
|
+
timestamp: new Date().toISOString(),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
main()
|
|
29
|
+
.then((result) => {
|
|
30
|
+
console.log("Script completed successfully:", result);
|
|
31
|
+
})
|
|
32
|
+
.catch((error) => {
|
|
33
|
+
console.error("Script failed:", error);
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=simple-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple-example.js","sourceRoot":"","sources":["../../../../../../src/agents/tools/executeScript/examples/simple-example.ts"],"names":[],"mappings":"AAkBA,KAAK,UAAU,IAAI;IACjB,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IAGpD,MAAM,gBAAgB,GAAG,MAAM,QAAQ,CAAC,YAAY,EAAE;QACpD,UAAU,EAAE,cAAc;KAC3B,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAG9C,MAAM,QAAQ,GAAG,MAAM,GAAG,CACxB;QACE;YACE,IAAI,EAAE,QAAQ;YACd,OAAO,EACL,gEAAgE;SACnE;QACD;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,yEAAyE,IAAI,CAAC,SAAS,CAC9F,gBAAgB,CACjB,EAAE;SACJ;KACF,EACD;QACE,KAAK,EAAE,aAAa;QACpB,UAAU,EAAE,GAAG;KAChB,CACF,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAGjE,OAAO;QACL,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,gBAAgB;QAC5B,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO;QAC/C,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAC;AACJ,CAAC;AAGD,IAAI,EAAE;KACH,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;IACf,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC,CAAC;KACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACf,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
declare const testScript = "\n// Test script that demonstrates various executeScript capabilities\nconsole.log(\"Starting test script execution...\");\n\nasync function main() {\n // Test 1: Simple console output\n console.log(\"Test 1: Basic logging works\");\n\n // Test 2: Call a tool (file search)\n try {\n console.log(\"Test 2: Calling fileSearch tool...\");\n const searchResult = await callTool(\"fileSearch\", {\n searchTerm: \"package.json\"\n });\n console.log(\"File search result:\", searchResult);\n } catch (error) {\n console.error(\"Tool call failed:\", error.message);\n }\n\n // Test 3: Call another tool (text search)\n try {\n console.log(\"Test 3: Calling textSearch tool...\");\n const textResult = await callTool(\"textSearch\", {\n searchTerm: \"executeScript\"\n });\n console.log(\"Text search found\", textResult?.length || 0, \"matches\");\n } catch (error) {\n console.error(\"Text search failed:\", error.message);\n }\n\n // Test 4: Make an LLM call\n try {\n console.log(\"Test 4: Making LLM call...\");\n const llmResponse = await llm([\n {\n role: \"system\",\n content: \"You are a helpful assistant. Respond with exactly one sentence.\"\n },\n {\n role: \"user\",\n content: \"What is 2+2? Just give the answer briefly.\"\n }\n ], {\n model: \"gpt-4o-mini\",\n max_tokens: 50\n });\n\n console.log(\"LLM Response:\", llmResponse.choices[0].message.content);\n } catch (error) {\n console.error(\"LLM call failed:\", error.message);\n }\n\n // Test 5: Create an artifact\n try {\n console.log(\"Test 5: Creating artifact...\");\n createArtifact(\"test-results.md\", `# Test Results\n\nScript executed successfully at: ${new Date().toISOString()}\n\nThis is a test artifact created by the executeScript tool.\n\n## Test Summary\n- Console logging: \u2713\n- Tool calls: \u2713\n- LLM calls: \u2713\n- Artifact creation: \u2713\n`, \"markdown\");\n console.log(\"Artifact created successfully\");\n } catch (error) {\n console.error(\"Artifact creation failed:\", error.message);\n }\n\n // Return final result\n return {\n success: true,\n message: \"All tests completed successfully\",\n timestamp: new Date().toISOString(),\n testsRun: 5\n };\n}\n\n// Execute the main function\nawait main().then(result => {\n console.log(\"=== SCRIPT COMPLETED ===\");\n console.log(\"Final result:\", JSON.stringify(result, null, 2));\n}).catch(error => {\n console.error(\"=== SCRIPT FAILED ===\");\n console.error(\"Error:\", error);\n throw error;\n});\n";
|
|
3
|
+
declare function runTest(): Promise<void>;
|
|
4
|
+
export { runTest, testScript };
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.testScript = exports.runTest = void 0;
|
|
28
|
+
const executeScript_1 = require("../../executeScript");
|
|
29
|
+
const services_1 = require("../../../../services");
|
|
30
|
+
const clients_1 = require("../../../../clients");
|
|
31
|
+
const list_1 = require("../../../tools/list");
|
|
32
|
+
const allTools = __importStar(require("../../../tools"));
|
|
33
|
+
const testScript = `
|
|
34
|
+
// Test script that demonstrates various executeScript capabilities
|
|
35
|
+
console.log("Starting test script execution...");
|
|
36
|
+
|
|
37
|
+
async function main() {
|
|
38
|
+
// Test 1: Simple console output
|
|
39
|
+
console.log("Test 1: Basic logging works");
|
|
40
|
+
|
|
41
|
+
// Test 2: Call a tool (file search)
|
|
42
|
+
try {
|
|
43
|
+
console.log("Test 2: Calling fileSearch tool...");
|
|
44
|
+
const searchResult = await callTool("fileSearch", {
|
|
45
|
+
searchTerm: "package.json"
|
|
46
|
+
});
|
|
47
|
+
console.log("File search result:", searchResult);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error("Tool call failed:", error.message);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Test 3: Call another tool (text search)
|
|
53
|
+
try {
|
|
54
|
+
console.log("Test 3: Calling textSearch tool...");
|
|
55
|
+
const textResult = await callTool("textSearch", {
|
|
56
|
+
searchTerm: "executeScript"
|
|
57
|
+
});
|
|
58
|
+
console.log("Text search found", textResult?.length || 0, "matches");
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("Text search failed:", error.message);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Test 4: Make an LLM call
|
|
64
|
+
try {
|
|
65
|
+
console.log("Test 4: Making LLM call...");
|
|
66
|
+
const llmResponse = await llm([
|
|
67
|
+
{
|
|
68
|
+
role: "system",
|
|
69
|
+
content: "You are a helpful assistant. Respond with exactly one sentence."
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
role: "user",
|
|
73
|
+
content: "What is 2+2? Just give the answer briefly."
|
|
74
|
+
}
|
|
75
|
+
], {
|
|
76
|
+
model: "gpt-4o-mini",
|
|
77
|
+
max_tokens: 50
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
console.log("LLM Response:", llmResponse.choices[0].message.content);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error("LLM call failed:", error.message);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Test 5: Create an artifact
|
|
86
|
+
try {
|
|
87
|
+
console.log("Test 5: Creating artifact...");
|
|
88
|
+
createArtifact("test-results.md", \`# Test Results
|
|
89
|
+
|
|
90
|
+
Script executed successfully at: \${new Date().toISOString()}
|
|
91
|
+
|
|
92
|
+
This is a test artifact created by the executeScript tool.
|
|
93
|
+
|
|
94
|
+
## Test Summary
|
|
95
|
+
- Console logging: ✓
|
|
96
|
+
- Tool calls: ✓
|
|
97
|
+
- LLM calls: ✓
|
|
98
|
+
- Artifact creation: ✓
|
|
99
|
+
\`, "markdown");
|
|
100
|
+
console.log("Artifact created successfully");
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error("Artifact creation failed:", error.message);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Return final result
|
|
106
|
+
return {
|
|
107
|
+
success: true,
|
|
108
|
+
message: "All tests completed successfully",
|
|
109
|
+
timestamp: new Date().toISOString(),
|
|
110
|
+
testsRun: 5
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Execute the main function
|
|
115
|
+
await main().then(result => {
|
|
116
|
+
console.log("=== SCRIPT COMPLETED ===");
|
|
117
|
+
console.log("Final result:", JSON.stringify(result, null, 2));
|
|
118
|
+
}).catch(error => {
|
|
119
|
+
console.error("=== SCRIPT FAILED ===");
|
|
120
|
+
console.error("Error:", error);
|
|
121
|
+
throw error;
|
|
122
|
+
});
|
|
123
|
+
`;
|
|
124
|
+
exports.testScript = testScript;
|
|
125
|
+
async function runTest() {
|
|
126
|
+
console.log("🚀 Starting executeScript test...\n");
|
|
127
|
+
try {
|
|
128
|
+
services_1.Tools.defineTools(list_1.includedTools, allTools);
|
|
129
|
+
const context = {
|
|
130
|
+
tools: services_1.Tools,
|
|
131
|
+
clients: clients_1.Clients,
|
|
132
|
+
};
|
|
133
|
+
console.log("📋 Test Parameters:");
|
|
134
|
+
console.log("- Max Tool Calls: 10");
|
|
135
|
+
console.log("- Max Tokens: 1000");
|
|
136
|
+
console.log("- Max Execution Time: 60s");
|
|
137
|
+
console.log("- Max Cost: $0.50\n");
|
|
138
|
+
const startTime = Date.now();
|
|
139
|
+
const result = await (0, executeScript_1.executeScript)({
|
|
140
|
+
script: testScript,
|
|
141
|
+
maxToolCalls: 10,
|
|
142
|
+
maxTokens: 1000,
|
|
143
|
+
maxExecutionTimeMs: 60000,
|
|
144
|
+
maxCostUsd: 0.5,
|
|
145
|
+
}, context);
|
|
146
|
+
const executionTime = Date.now() - startTime;
|
|
147
|
+
console.log("\n" + "=".repeat(60));
|
|
148
|
+
console.log("🎯 TEST RESULTS");
|
|
149
|
+
console.log("=".repeat(60));
|
|
150
|
+
console.log(`⏱️ Execution Time: ${executionTime}ms`);
|
|
151
|
+
console.log(`✅ Success: ${result.success}`);
|
|
152
|
+
if (result.success) {
|
|
153
|
+
console.log(`📊 Result:`, result.result);
|
|
154
|
+
console.log(`🔧 Tool Calls Made: ${result.quotaUsage.toolCalls}`);
|
|
155
|
+
console.log(`🎯 Tokens Used: ${result.quotaUsage.tokens}`);
|
|
156
|
+
console.log(`💰 Cost: $${result.quotaUsage.costUsd.toFixed(4)}`);
|
|
157
|
+
if (result.artifacts.length > 0) {
|
|
158
|
+
console.log(`📁 Artifacts Created: ${result.artifacts.length}`);
|
|
159
|
+
result.artifacts.forEach((artifact) => {
|
|
160
|
+
console.log(` - ${artifact.name} (${artifact.type}, ${artifact.contentLength} bytes)`);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (result.consoleOutput.length > 0) {
|
|
164
|
+
console.log(`\n📝 Console Output (${result.consoleOutput.length} entries):`);
|
|
165
|
+
result.consoleOutput.forEach((entry) => {
|
|
166
|
+
console.log(` ${entry}`);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (result.violations.length > 0) {
|
|
170
|
+
console.log(`\n⚠️ Policy Violations: ${result.violations.length}`);
|
|
171
|
+
result.violations.forEach((violation) => {
|
|
172
|
+
console.log(` - ${JSON.stringify(violation)}`);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
console.log(`❌ Error: ${result.error}`);
|
|
178
|
+
if (result.consoleOutput.length > 0) {
|
|
179
|
+
console.log(`\n📝 Console Output Before Failure:`);
|
|
180
|
+
result.consoleOutput.forEach((entry) => {
|
|
181
|
+
console.log(` ${entry}`);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
console.log("\n" + "=".repeat(60));
|
|
186
|
+
console.log(result.success ? "🎉 TEST PASSED!" : "💥 TEST FAILED!");
|
|
187
|
+
console.log("=".repeat(60));
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
console.error("\n💥 TEST RUNNER ERROR:");
|
|
191
|
+
console.error(error);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.runTest = runTest;
|
|
196
|
+
if (require.main === module) {
|
|
197
|
+
runTest().catch((error) => {
|
|
198
|
+
console.error("Unhandled error:", error);
|
|
199
|
+
process.exit(1);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=test-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-runner.js","sourceRoot":"","sources":["../../../../../../src/agents/tools/executeScript/examples/test-runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,uDAAoD;AACpD,mDAA6C;AAC7C,iDAA8C;AAC9C,8CAAo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CAAC,CAAC,KAAK,EAAE,EAAE;QACxB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const executeScript: ({ script, maxToolCalls, maxTokens, maxExecutionTimeMs, maxCostUsd }: {
|
|
2
|
+
script: any;
|
|
3
|
+
maxToolCalls: any;
|
|
4
|
+
maxTokens: any;
|
|
5
|
+
maxExecutionTimeMs: any;
|
|
6
|
+
maxCostUsd: any;
|
|
7
|
+
}, context: any) => Promise<{
|
|
8
|
+
success: boolean;
|
|
9
|
+
result: any;
|
|
10
|
+
error: string;
|
|
11
|
+
artifacts: {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
type: "text" | "json" | "html" | "csv" | "markdown";
|
|
15
|
+
contentLength: number;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
}[];
|
|
18
|
+
consoleOutput: string[];
|
|
19
|
+
metrics: import("../../../services/script-execution/types").TraceMetrics;
|
|
20
|
+
violations: any[];
|
|
21
|
+
executionTimeMs: number;
|
|
22
|
+
quotaUsage: {
|
|
23
|
+
toolCalls: number;
|
|
24
|
+
tokens: number;
|
|
25
|
+
costUsd: number;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeScript = void 0;
|
|
4
|
+
const ScriptExecutor_1 = require("../../../services/script-execution/ScriptExecutor");
|
|
5
|
+
const services_1 = require("../../../services");
|
|
6
|
+
const clients_1 = require("../../../clients");
|
|
7
|
+
const executeScript = async ({ script, maxToolCalls, maxTokens, maxExecutionTimeMs, maxCostUsd }, context) => {
|
|
8
|
+
try {
|
|
9
|
+
const executor = new ScriptExecutor_1.ScriptExecutor(services_1.Tools, clients_1.Clients);
|
|
10
|
+
const result = await executor.execute({
|
|
11
|
+
script,
|
|
12
|
+
quotas: {
|
|
13
|
+
maxToolCalls: maxToolCalls || 50,
|
|
14
|
+
maxTokens: maxTokens || 10000,
|
|
15
|
+
maxExecutionTimeMs: maxExecutionTimeMs || 30000,
|
|
16
|
+
maxCostUsd: maxCostUsd || 1.0,
|
|
17
|
+
maxMemoryMb: 100,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const violations = result.trace.events
|
|
21
|
+
.filter((e) => e.type.includes("violation") || e.type.includes("error"))
|
|
22
|
+
.map((e) => e.data);
|
|
23
|
+
return {
|
|
24
|
+
success: result.success,
|
|
25
|
+
result: result.result,
|
|
26
|
+
error: result.error,
|
|
27
|
+
artifacts: result.artifacts.map((a) => ({
|
|
28
|
+
id: a.id,
|
|
29
|
+
name: a.name,
|
|
30
|
+
type: a.type,
|
|
31
|
+
contentLength: a.content.length,
|
|
32
|
+
createdAt: a.createdAt,
|
|
33
|
+
})),
|
|
34
|
+
consoleOutput: result.consoleOutput,
|
|
35
|
+
metrics: result.trace.metrics,
|
|
36
|
+
violations,
|
|
37
|
+
executionTimeMs: result.trace.endTime - result.trace.startTime,
|
|
38
|
+
quotaUsage: {
|
|
39
|
+
toolCalls: result.trace.metrics.toolCallCount,
|
|
40
|
+
tokens: result.trace.metrics.tokenUsage.total,
|
|
41
|
+
costUsd: result.trace.metrics.costUsd,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: error instanceof Error ? error.message : String(error),
|
|
49
|
+
result: null,
|
|
50
|
+
artifacts: [],
|
|
51
|
+
consoleOutput: [],
|
|
52
|
+
metrics: null,
|
|
53
|
+
violations: [],
|
|
54
|
+
executionTimeMs: 0,
|
|
55
|
+
quotaUsage: {
|
|
56
|
+
toolCalls: 0,
|
|
57
|
+
tokens: 0,
|
|
58
|
+
costUsd: 0,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.executeScript = executeScript;
|
|
64
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../../src/agents/tools/executeScript/handler.ts"],"names":[],"mappings":";;;AAAA,sFAAmF;AACnF,gDAA0C;AAC1C,8CAA2C;AAOpC,MAAM,aAAa,GAAG,KAAK,EAChC,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,EACnE,OAAO,EACP,EAAE;IACF,IAAI;QAEF,MAAM,QAAQ,GAAG,IAAI,+BAAc,CAAC,gBAAK,EAAE,iBAAO,CAAC,CAAC;QAGpD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC;YACpC,MAAM;YACN,MAAM,EAAE;gBACN,YAAY,EAAE,YAAY,IAAI,EAAE;gBAChC,SAAS,EAAE,SAAS,IAAI,KAAK;gBAC7B,kBAAkB,EAAE,kBAAkB,IAAI,KAAK;gBAC/C,UAAU,EAAE,UAAU,IAAI,GAAG;gBAC7B,WAAW,EAAE,GAAG;aACjB;SACF,CAAC,CAAC;QAGH,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM;aACnC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;aACvE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAGtB,OAAO;YACL,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,SAAS,EA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