UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

91 lines (85 loc) โ€ข 3.47 kB
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 };