contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
91 lines (85 loc) โข 3.47 kB
JavaScript
import { ToolManager } from '../services/tools/ToolManager.js';
import fs from 'fs/promises';
import path from 'path';
async function testToolArchitecture() {
console.log('๐งช Testing Tool Architecture...\n');
// Create a test directory and file
const testDir = path.join(process.cwd(), 'test-tools');
const testFile = path.join(testDir, 'sample.md');
try {
// Setup test environment
await fs.mkdir(testDir, { recursive: true });
await fs.writeFile(testFile, `# Sample Markdown File
This is a test file for the tool architecture.
## Features
- File reading capability
- Tool execution
- Context awareness
## Code Example
\`\`\`javascript
console.log("Hello from the tool system!");
\`\`\`
`);
console.log('โ
Created test file:', testFile);
// Initialize ToolManager
const toolManager = new ToolManager(process.cwd());
// Test 1: List available tools
console.log('\n๐ Available Tools:');
const tools = toolManager.getAvailableTools();
tools.forEach(tool => {
console.log(`- ${tool.name}: ${tool.description}`);
console.log(` Parameters: ${tool.parameters.map(p => p.name).join(', ')}`);
});
// Test 2: Generate file tree context
console.log('\n๐ณ File Tree Context:');
const fileTreeContext = await toolManager.generateFileTreeContext();
console.log(fileTreeContext.substring(0, 500) + '...');
// Test 3: Execute file read tool
console.log('\n๐ Testing File Read Tool:');
const toolCall = {
tool_name: 'read_file',
parameters: {
file_path: 'test-tools/sample.md'
}
};
const result = await toolManager.executeTool(toolCall);
if (result.success) {
console.log('โ
File read successful!');
console.log('๐ File info:', result.data?.fileInfo);
console.log('๐ Content preview:', result.data?.content.substring(0, 100) + '...');
}
else {
console.log('โ File read failed:', result.error);
}
// Test 4: Test tool call parsing
console.log('\n๐ Testing Tool Call Parsing:');
const sampleResponse = `Here's the content of your file:
[TOOL:read_file:{"file_path":"test-tools/sample.md"}]
The file contains markdown content with examples.`;
const parsedCalls = toolManager.parseToolCalls(sampleResponse);
console.log('Parsed tool calls:', parsedCalls);
// Test 5: Generate tool instructions
console.log('\n๐ Tool Instructions:');
const instructions = toolManager.generateToolInstructions();
console.log(instructions.substring(0, 300) + '...');
// Cleanup
await fs.rm(testDir, { recursive: true, force: true });
console.log('\n๐งน Cleaned up test files');
console.log('\n๐ All tests completed successfully!');
}
catch (error) {
console.error('โ Test failed:', error);
// Cleanup on error
try {
await fs.rm(testDir, { recursive: true, force: true });
}
catch (cleanupError) {
console.error('Failed to cleanup:', cleanupError);
}
}
}
// Run the test if this file is executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
testToolArchitecture().catch(console.error);
}
export { testToolArchitecture };