UNPKG

@wavequery/conductor

Version:
51 lines 1.49 kB
export class ToolRegistry { constructor() { this.tools = new Map(); this.typeIndex = new Map(); } register(tool, type) { if (this.tools.has(tool.name)) { throw new Error(`Tool with name ${tool.name} is already registered`); } this.tools.set(tool.name, tool); if (!this.typeIndex.has(type)) { this.typeIndex.set(type, new Set()); } this.typeIndex.get(type).add(tool.name); } get(name) { const tool = this.tools.get(name); if (!tool) { throw new Error(`Tool ${name} not found`); } return tool; } getByType(type) { const toolNames = this.typeIndex.get(type); if (!toolNames) { return []; } return Array.from(toolNames).map(name => this.tools.get(name)); } unregister(name) { const tool = this.tools.get(name); if (tool) { this.tools.delete(name); for (const [type, tools] of this.typeIndex.entries()) { if (tools.has(name)) { tools.delete(name); if (tools.size === 0) { this.typeIndex.delete(type); } } } } } listTools() { return Array.from(this.tools.keys()); } listTypes() { return Array.from(this.typeIndex.keys()); } } //# sourceMappingURL=tool-registry.js.map