import type { ToolDefinition } from "../types.js"; import type { EventBus } from "../events.js"; export class ToolRegistry { private readonly tools = new Map>(); constructor(private readonly events: EventBus) {} async register(tool: ToolDefinition): Promise { if (this.tools.has(tool.name)) { throw new Error(`Tool already registered: ${tool.name}`); } this.tools.set(tool.name, tool); await this.events.emit("tool.registered", { tool: tool.name }); } list(): ToolDefinition[] { return [...this.tools.values()]; } get(name: string): ToolDefinition | undefined { return this.tools.get(name); } }