contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
108 lines (107 loc) • 3.3 kB
JavaScript
/**
* Registry for managing available tools in the agentic CLI system
*/
export class ToolRegistry {
constructor() {
this.tools = new Map();
this.registerDefaultTools();
}
/**
* Register a tool
*/
registerTool(tool) {
const definition = tool.getDefinition();
this.tools.set(definition.name, tool);
}
/**
* Get a tool by name
*/
getTool(name) {
return this.tools.get(name);
}
/**
* Get all available tools
*/
getAvailableTools() {
return Array.from(this.tools.values()).map(tool => tool.getDefinition());
}
/**
* Get tools by category
*/
getToolsByCategory(category) {
return this.getAvailableTools().filter(tool => tool.category === category);
}
/**
* Check if a tool exists
*/
hasTool(name) {
return this.tools.has(name);
}
/**
* Remove a tool
*/
removeTool(name) {
return this.tools.delete(name);
}
/**
* Get tool count
*/
getToolCount() {
return this.tools.size;
}
/**
* Register default tools
*/
registerDefaultTools() {
// Import and register core file tools
import('../tools/file/ReadFileTool.js').then(({ ReadFileTool }) => {
this.registerTool(new ReadFileTool());
}).catch(() => console.warn('ReadFileTool not available'));
import('../tools/file/WriteFileTool.js').then(({ WriteFileTool }) => {
this.registerTool(new WriteFileTool());
}).catch(() => console.warn('WriteFileTool not available'));
import('../tools/file/AnalyzeFileTool.js').then(({ AnalyzeFileTool }) => {
this.registerTool(new AnalyzeFileTool());
}).catch(() => console.warn('AnalyzeFileTool not available'));
import('../tools/file/SummarizeFileTool.js').then(({ SummarizeFileTool }) => {
this.registerTool(new SummarizeFileTool());
}).catch(() => console.warn('SummarizeFileTool not available'));
import('../tools/file/ClassifyFileTool.js').then(({ ClassifyFileTool }) => {
this.registerTool(new ClassifyFileTool());
}).catch(() => console.warn('ClassifyFileTool not available'));
console.log('ToolRegistry initialized with core file tools');
}
/**
* Get tool usage statistics
*/
getToolStats() {
const stats = {};
for (const [name, tool] of this.tools) {
const definition = tool.getDefinition();
stats[name] = {
name: definition.name,
category: definition.category,
usageCount: 0 // TODO: Implement usage tracking
};
}
return stats;
}
/**
* Validate tool dependencies
*/
validateDependencies() {
const errors = [];
for (const [name, tool] of this.tools) {
const dependencies = tool.getDependencies();
for (const dep of dependencies) {
if (!this.hasTool(dep)) {
errors.push(`Tool ${name} depends on ${dep} which is not registered`);
}
}
}
return {
valid: errors.length === 0,
errors
};
}
}