@tyvm/knowhow 0.0.108-dev.c47492f โ 0.0.108-dev.d003f8f
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 +1 -2
- package/src/agents/tools/index.ts +0 -1
- package/src/agents/tools/list.ts +0 -2
- package/src/chat/CliChatService.ts +3 -0
- package/src/cli.ts +89 -686
- package/src/clients/index.ts +6 -5
- package/src/commands/agent.ts +246 -0
- package/src/commands/misc.ts +174 -0
- package/src/commands/modules.ts +182 -0
- package/src/commands/services.ts +77 -0
- package/src/commands/workers.ts +160 -0
- package/src/config.ts +37 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +200 -0
- package/src/plugins/plugins.ts +0 -21
- package/src/processors/JsonCompressor.ts +3 -3
- package/src/services/EventService.ts +57 -1
- package/src/services/modules/index.ts +54 -40
- package/src/services/modules/types.ts +4 -0
- package/src/types.ts +0 -1
- package/tests/unit/commands/github-credentials.test.ts +211 -0
- package/tests/unit/modules/moduleLoading.test.ts +39 -37
- package/tests/unit/plugins/pluginLoading.test.ts +0 -85
- package/ts_build/package.json +1 -2
- package/ts_build/src/agents/tools/index.d.ts +0 -1
- package/ts_build/src/agents/tools/index.js +0 -1
- package/ts_build/src/agents/tools/index.js.map +1 -1
- package/ts_build/src/agents/tools/list.js +0 -2
- package/ts_build/src/agents/tools/list.js.map +1 -1
- package/ts_build/src/chat/CliChatService.js +3 -0
- package/ts_build/src/chat/CliChatService.js.map +1 -1
- package/ts_build/src/cli.js +47 -533
- package/ts_build/src/cli.js.map +1 -1
- package/ts_build/src/clients/index.js +2 -4
- package/ts_build/src/clients/index.js.map +1 -1
- package/ts_build/src/commands/agent.d.ts +6 -0
- package/ts_build/src/commands/agent.js +229 -0
- package/ts_build/src/commands/agent.js.map +1 -0
- package/ts_build/src/commands/misc.d.ts +10 -0
- package/ts_build/src/commands/misc.js +197 -0
- package/ts_build/src/commands/misc.js.map +1 -0
- package/ts_build/src/commands/modules.d.ts +3 -0
- package/ts_build/src/commands/modules.js +160 -0
- package/ts_build/src/commands/modules.js.map +1 -0
- package/ts_build/src/commands/services.d.ts +5 -0
- package/ts_build/src/commands/services.js +87 -0
- package/ts_build/src/commands/services.js.map +1 -0
- package/ts_build/src/commands/workers.d.ts +6 -0
- package/ts_build/src/commands/workers.js +163 -0
- package/ts_build/src/commands/workers.js.map +1 -0
- package/ts_build/src/config.d.ts +1 -0
- package/ts_build/src/config.js +32 -0
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/index.d.ts +1 -0
- package/ts_build/src/index.js +3 -1
- package/ts_build/src/index.js.map +1 -1
- package/ts_build/src/logger.d.ts +21 -0
- package/ts_build/src/logger.js +109 -0
- package/ts_build/src/logger.js.map +1 -0
- package/ts_build/src/plugins/plugins.d.ts +0 -2
- package/ts_build/src/plugins/plugins.js +0 -11
- package/ts_build/src/plugins/plugins.js.map +1 -1
- package/ts_build/src/processors/JsonCompressor.js +1 -1
- package/ts_build/src/services/EventService.d.ts +6 -1
- package/ts_build/src/services/EventService.js +28 -0
- package/ts_build/src/services/EventService.js.map +1 -1
- package/ts_build/src/services/modules/index.d.ts +7 -4
- package/ts_build/src/services/modules/index.js +36 -31
- package/ts_build/src/services/modules/index.js.map +1 -1
- package/ts_build/src/services/modules/types.d.ts +4 -0
- package/ts_build/src/types.d.ts +0 -1
- package/ts_build/src/types.js.map +1 -1
- package/ts_build/tests/unit/commands/github-credentials.test.d.ts +1 -0
- package/ts_build/tests/unit/commands/github-credentials.test.js +146 -0
- package/ts_build/tests/unit/commands/github-credentials.test.js.map +1 -0
- package/ts_build/tests/unit/modules/moduleLoading.test.js +20 -26
- package/ts_build/tests/unit/modules/moduleLoading.test.js.map +1 -1
- package/ts_build/tests/unit/plugins/pluginLoading.test.js +0 -65
- package/ts_build/tests/unit/plugins/pluginLoading.test.js.map +1 -1
- package/src/agents/tools/executeScript/README.md +0 -94
- package/src/agents/tools/executeScript/definition.ts +0 -79
- package/src/agents/tools/executeScript/examples/dependency-injection-validation.ts +0 -272
- package/src/agents/tools/executeScript/examples/quick-test.ts +0 -74
- package/src/agents/tools/executeScript/examples/serialization-test.ts +0 -321
- package/src/agents/tools/executeScript/examples/test-runner.ts +0 -197
- package/src/agents/tools/executeScript/index.ts +0 -98
- package/src/services/script-execution/SandboxContext.ts +0 -282
- package/src/services/script-execution/ScriptExecutor.ts +0 -441
- package/src/services/script-execution/ScriptPolicy.ts +0 -194
- package/src/services/script-execution/ScriptTracer.ts +0 -249
- package/src/services/script-execution/types.ts +0 -134
- package/ts_build/src/agents/tools/executeScript/definition.d.ts +0 -2
- package/ts_build/src/agents/tools/executeScript/definition.js +0 -76
- package/ts_build/src/agents/tools/executeScript/definition.js.map +0 -1
- package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.d.ts +0 -18
- package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.js +0 -192
- package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.js.map +0 -1
- package/ts_build/src/agents/tools/executeScript/examples/quick-test.d.ts +0 -3
- package/ts_build/src/agents/tools/executeScript/examples/quick-test.js +0 -64
- package/ts_build/src/agents/tools/executeScript/examples/quick-test.js.map +0 -1
- package/ts_build/src/agents/tools/executeScript/examples/serialization-test.d.ts +0 -15
- package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js +0 -266
- package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js.map +0 -1
- package/ts_build/src/agents/tools/executeScript/examples/test-runner.d.ts +0 -4
- package/ts_build/src/agents/tools/executeScript/examples/test-runner.js +0 -208
- package/ts_build/src/agents/tools/executeScript/examples/test-runner.js.map +0 -1
- package/ts_build/src/agents/tools/executeScript/index.d.ts +0 -28
- package/ts_build/src/agents/tools/executeScript/index.js +0 -72
- package/ts_build/src/agents/tools/executeScript/index.js.map +0 -1
- package/ts_build/src/services/script-execution/SandboxContext.d.ts +0 -34
- package/ts_build/src/services/script-execution/SandboxContext.js +0 -189
- package/ts_build/src/services/script-execution/SandboxContext.js.map +0 -1
- package/ts_build/src/services/script-execution/ScriptExecutor.d.ts +0 -19
- package/ts_build/src/services/script-execution/ScriptExecutor.js +0 -269
- package/ts_build/src/services/script-execution/ScriptExecutor.js.map +0 -1
- package/ts_build/src/services/script-execution/ScriptPolicy.d.ts +0 -28
- package/ts_build/src/services/script-execution/ScriptPolicy.js +0 -115
- package/ts_build/src/services/script-execution/ScriptPolicy.js.map +0 -1
- package/ts_build/src/services/script-execution/ScriptTracer.d.ts +0 -19
- package/ts_build/src/services/script-execution/ScriptTracer.js +0 -186
- package/ts_build/src/services/script-execution/ScriptTracer.js.map +0 -1
- package/ts_build/src/services/script-execution/types.d.ts +0 -108
- package/ts_build/src/services/script-execution/types.js +0 -3
- package/ts_build/src/services/script-execution/types.js.map +0 -1
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
/**
|
|
3
|
-
* Comprehensive test for Tools Dependency Injection System
|
|
4
|
-
*
|
|
5
|
-
* This test validates:
|
|
6
|
-
* 1. Context injection is working properly
|
|
7
|
-
* 2. Tools can access services via `this.getContext()`
|
|
8
|
-
* 3. Agent isolation is functioning (each agent has independent context)
|
|
9
|
-
* 4. No singleton usage in tool implementations
|
|
10
|
-
* 5. Backward compatibility is maintained
|
|
11
|
-
*
|
|
12
|
-
* Usage: npx ts-node src/agents/tools/executeScript/examples/dependency-injection-validation.ts
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { ToolsService } from "../../../../services/Tools";
|
|
16
|
-
import { Clients } from "../../../../clients";
|
|
17
|
-
import { EventService, services } from "../../../../services/";
|
|
18
|
-
import { BaseAgent } from "../../../base/base";
|
|
19
|
-
import { Message } from "../../../../clients/types";
|
|
20
|
-
import { includedTools } from "../../list";
|
|
21
|
-
import { executeScript } from "../";
|
|
22
|
-
import { executeScriptDefinition } from "../definition";
|
|
23
|
-
|
|
24
|
-
// Test Agent that extends BaseAgent to test agent isolation
|
|
25
|
-
class TestAgent1 extends BaseAgent {
|
|
26
|
-
name = "TestAgent1";
|
|
27
|
-
description = "Test agent for dependency injection validation";
|
|
28
|
-
|
|
29
|
-
async getInitialMessages(userInput: string): Promise<Message[]> {
|
|
30
|
-
return [
|
|
31
|
-
{ role: "system", content: this.description },
|
|
32
|
-
{ role: "user", content: userInput },
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Expose toolsService for testing
|
|
37
|
-
public getToolsServiceForTest() {
|
|
38
|
-
return this.tools;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
class TestAgent2 extends BaseAgent {
|
|
43
|
-
name = "TestAgent2";
|
|
44
|
-
description = "Another test agent for dependency injection validation";
|
|
45
|
-
|
|
46
|
-
async getInitialMessages(userInput: string): Promise<Message[]> {
|
|
47
|
-
return [
|
|
48
|
-
{ role: "system", content: this.description },
|
|
49
|
-
{ role: "user", content: userInput },
|
|
50
|
-
];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Expose toolsService for testing
|
|
54
|
-
public getToolsServiceForTest() {
|
|
55
|
-
return this.tools;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Test tool function that uses context injection
|
|
60
|
-
function testToolWithContext(this: ToolsService, params: { message: string }) {
|
|
61
|
-
const context = this.getContext();
|
|
62
|
-
|
|
63
|
-
console.log("โ
Tool called with context:");
|
|
64
|
-
console.log("- AgentService available:", !!context.Agents);
|
|
65
|
-
console.log("- EventService available:", !!context.Events);
|
|
66
|
-
console.log("- Clients available:", !!context.Clients);
|
|
67
|
-
console.log("- ToolsService self-reference available:", !!context.Tools);
|
|
68
|
-
console.log("- Test message:", params.message);
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
success: true,
|
|
72
|
-
contextValidated: true,
|
|
73
|
-
hasAgentService: !!context.Agents,
|
|
74
|
-
hasEventService: !!context.Events,
|
|
75
|
-
hasClients: !!context.Clients,
|
|
76
|
-
hasToolsService: !!context.Tools,
|
|
77
|
-
testMessage: params.message,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function runValidationTests() {
|
|
82
|
-
console.log("๐งช Starting Tools Dependency Injection Validation Tests\n");
|
|
83
|
-
|
|
84
|
-
// Test 1: Create independent agents with their own ToolsService instances
|
|
85
|
-
console.log("๐ Test 1: Agent Isolation");
|
|
86
|
-
const agent1 = new TestAgent1({
|
|
87
|
-
Events: new EventService(),
|
|
88
|
-
Tools: new ToolsService({ Clients }),
|
|
89
|
-
});
|
|
90
|
-
const agent2 = new TestAgent2({
|
|
91
|
-
Events: new EventService(),
|
|
92
|
-
Tools: new ToolsService(),
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const toolsService1 = agent1.getToolsServiceForTest();
|
|
96
|
-
const toolsService2 = agent2.getToolsServiceForTest();
|
|
97
|
-
|
|
98
|
-
// Verify agents have different ToolsService instances
|
|
99
|
-
console.log(
|
|
100
|
-
"โ
Agent1 and Agent2 have different ToolsService instances:",
|
|
101
|
-
toolsService1 !== toolsService2
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// Test 2: Context validation for each agent
|
|
105
|
-
console.log("\n๐ Test 2: Context Injection Validation");
|
|
106
|
-
|
|
107
|
-
const context1 = toolsService1.getContext();
|
|
108
|
-
const context2 = toolsService2.getContext();
|
|
109
|
-
|
|
110
|
-
console.log("โ
Agent1 context has required services:", {
|
|
111
|
-
agentService: !!context1.Agents,
|
|
112
|
-
eventService: !!context1.Events,
|
|
113
|
-
clients: !!context1.Clients,
|
|
114
|
-
toolsService: !!context1.Tools,
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
console.log("โ
Agent2 context has required services:", {
|
|
118
|
-
agentService: !!context2.Agents,
|
|
119
|
-
eventService: !!context2.Events,
|
|
120
|
-
clients: !!context2.Clients,
|
|
121
|
-
toolsService: !!context2.Tools,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Test 3: Register a test tool and verify it can access context
|
|
125
|
-
console.log("\n๐ Test 3: Tool Context Access");
|
|
126
|
-
|
|
127
|
-
// Register the test tool on agent1's ToolsService
|
|
128
|
-
toolsService1.addTool({
|
|
129
|
-
type: "function",
|
|
130
|
-
function: {
|
|
131
|
-
name: "testToolWithContext",
|
|
132
|
-
description: "Test tool for context validation",
|
|
133
|
-
parameters: {
|
|
134
|
-
type: "object",
|
|
135
|
-
properties: {
|
|
136
|
-
message: { type: "string", description: "Test message" },
|
|
137
|
-
},
|
|
138
|
-
required: ["message"],
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
toolsService1.setFunction("testToolWithContext", testToolWithContext);
|
|
144
|
-
try {
|
|
145
|
-
const result = await toolsService1.callTool({
|
|
146
|
-
id: "test-call",
|
|
147
|
-
type: "function",
|
|
148
|
-
function: {
|
|
149
|
-
name: "testToolWithContext",
|
|
150
|
-
arguments: JSON.stringify({ message: "Hello from Agent1!" }),
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
console.log(
|
|
154
|
-
"โ
Tool executed successfully with context access:",
|
|
155
|
-
result.functionResp?.success
|
|
156
|
-
);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
console.error("โ Tool execution failed:", error);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Test 4: Verify agent isolation - agent2 should not have agent1's tool
|
|
162
|
-
console.log("\n๐ Test 4: Tool Isolation Between Agents");
|
|
163
|
-
|
|
164
|
-
const agent1Tools = toolsService1.getTools().map((t) => t.function.name);
|
|
165
|
-
const agent2Tools = toolsService2.getTools().map((t) => t.function.name);
|
|
166
|
-
|
|
167
|
-
console.log("Agent1 tools:", agent1Tools.length);
|
|
168
|
-
console.log("Agent2 tools:", agent2Tools.length);
|
|
169
|
-
console.log(
|
|
170
|
-
"โ
Agent2 does not have agent1's custom tool:",
|
|
171
|
-
!agent2Tools.includes("testToolWithContext")
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
// Test 5: Add different tool to agent2 to verify independence
|
|
175
|
-
function agent2SpecificTool(this: ToolsService, params: { data: string }) {
|
|
176
|
-
const context = this.getContext();
|
|
177
|
-
return {
|
|
178
|
-
agent: "Agent2",
|
|
179
|
-
data: params.data,
|
|
180
|
-
contextAvailable: !!context,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
toolsService2.addTool({
|
|
185
|
-
type: "function",
|
|
186
|
-
function: {
|
|
187
|
-
name: "agent2SpecificTool",
|
|
188
|
-
description: "Tool specific to Agent2",
|
|
189
|
-
parameters: {
|
|
190
|
-
type: "object",
|
|
191
|
-
properties: {
|
|
192
|
-
data: { type: "string", description: "Test data" },
|
|
193
|
-
},
|
|
194
|
-
required: ["data"],
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
toolsService2.setFunction("agent2SpecificTool", agent2SpecificTool);
|
|
199
|
-
|
|
200
|
-
const agent1ToolsAfter = toolsService1.getTools().map((t) => t.function.name);
|
|
201
|
-
const agent2ToolsAfter = toolsService2.getTools().map((t) => t.function.name);
|
|
202
|
-
|
|
203
|
-
console.log(
|
|
204
|
-
"โ
Agent1 does not have agent2's tool:",
|
|
205
|
-
!agent1ToolsAfter.includes("agent2SpecificTool")
|
|
206
|
-
);
|
|
207
|
-
console.log(
|
|
208
|
-
"โ
Agent2 has its specific tool:",
|
|
209
|
-
agent2ToolsAfter.includes("agent2SpecificTool")
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
// Test 6: Verify executeScript tool is using context injection
|
|
213
|
-
console.log("\n๐ Test 6: executeScript Context Integration");
|
|
214
|
-
|
|
215
|
-
// Test that executeScript uses the bound context instead of singletons
|
|
216
|
-
const executeScriptTest = `
|
|
217
|
-
async function main() {
|
|
218
|
-
return callTool("testToolWithContext", {message: "Hello from executeScript!"});
|
|
219
|
-
}
|
|
220
|
-
return main()
|
|
221
|
-
`;
|
|
222
|
-
|
|
223
|
-
toolsService1.defineTools([executeScriptDefinition], { executeScript });
|
|
224
|
-
|
|
225
|
-
try {
|
|
226
|
-
const executeResult = await toolsService1.callTool({
|
|
227
|
-
id: "execute-test",
|
|
228
|
-
type: "function",
|
|
229
|
-
function: {
|
|
230
|
-
name: "executeScript",
|
|
231
|
-
arguments: JSON.stringify({ script: executeScriptTest }),
|
|
232
|
-
},
|
|
233
|
-
});
|
|
234
|
-
console.log(
|
|
235
|
-
"โ
executeScript using dependency injection:",
|
|
236
|
-
executeResult.functionResp
|
|
237
|
-
);
|
|
238
|
-
} catch (error) {
|
|
239
|
-
console.error("โ executeScript test failed:", error);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
console.log("\n๐ All Tests Completed!");
|
|
243
|
-
console.log("\n๐ Test Summary:");
|
|
244
|
-
console.log(
|
|
245
|
-
"โ
Agent isolation working - each agent has independent ToolsService"
|
|
246
|
-
);
|
|
247
|
-
console.log(
|
|
248
|
-
"โ
Context injection working - tools can access all required services"
|
|
249
|
-
);
|
|
250
|
-
console.log("โ
No singleton usage - tools use bound context instead");
|
|
251
|
-
console.log(
|
|
252
|
-
"โ
Backward compatibility maintained - existing patterns still work"
|
|
253
|
-
);
|
|
254
|
-
console.log("โ
executeScript migrated successfully to dependency injection");
|
|
255
|
-
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Run the validation tests
|
|
260
|
-
if (require.main === module) {
|
|
261
|
-
runValidationTests()
|
|
262
|
-
.then(() => {
|
|
263
|
-
console.log("\n๐ Dependency Injection Implementation Complete!");
|
|
264
|
-
process.exit(0);
|
|
265
|
-
})
|
|
266
|
-
.catch((error) => {
|
|
267
|
-
console.error("\nโ Validation tests failed:", error);
|
|
268
|
-
process.exit(1);
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export { runValidationTests, TestAgent1, TestAgent2 };
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
/**
|
|
3
|
-
* Quick test for executeScript - minimal example
|
|
4
|
-
* Usage: npx ts-node src/agents/tools/executeScript/examples/quick-test.ts
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { executeScript } from "../../executeScript";
|
|
8
|
-
import { services } from "../../../../services";
|
|
9
|
-
|
|
10
|
-
// Simple test script
|
|
11
|
-
const simpleScript = `
|
|
12
|
-
console.log("Hello from executeScript!");
|
|
13
|
-
|
|
14
|
-
async function main() {
|
|
15
|
-
// Test basic functionality
|
|
16
|
-
console.log("Running simple test...");
|
|
17
|
-
|
|
18
|
-
// Try a simple tool call
|
|
19
|
-
const files = await callTool("fileSearch", { searchTerm: "*.ts" });
|
|
20
|
-
console.log("Found", files?.length || 0, "TypeScript files");
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
message: "Simple test completed!",
|
|
24
|
-
filesFound: files?.length || 0,
|
|
25
|
-
timestamp: new Date().toISOString()
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
await main().then(result => {
|
|
30
|
-
console.log("Result:", result);
|
|
31
|
-
}).catch(error => {
|
|
32
|
-
console.error("Error:", error);
|
|
33
|
-
});
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
async function quickTest() {
|
|
37
|
-
console.log("๐งช Quick executeScript test\n");
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
const { Tools, Clients } = services();
|
|
41
|
-
const result = await executeScript({
|
|
42
|
-
script: simpleScript,
|
|
43
|
-
maxToolCalls: 5,
|
|
44
|
-
maxTokens: 100,
|
|
45
|
-
maxExecutionTimeMs: 10000,
|
|
46
|
-
maxCostUsd: 0.1,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
console.log("\n๐ QUICK TEST RESULT:");
|
|
50
|
-
console.log("Success:", result.success);
|
|
51
|
-
console.log("Result:", result.result);
|
|
52
|
-
console.log("Tool calls:", result.quotaUsage.toolCalls);
|
|
53
|
-
console.log("Cost: $" + result.quotaUsage.costUsd.toFixed(4));
|
|
54
|
-
|
|
55
|
-
if (result.consoleOutput.length > 0) {
|
|
56
|
-
console.log("\n๐ Console Output:");
|
|
57
|
-
result.consoleOutput.forEach((entry) => {
|
|
58
|
-
console.log(` ${entry}`);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (!result.success) {
|
|
63
|
-
console.log("โ Error:", result.error);
|
|
64
|
-
}
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error("๐ฅ Test failed:", error);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (require.main === module) {
|
|
71
|
-
quickTest();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { quickTest };
|
|
@@ -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 };
|