25 lines
695 B
TypeScript
25 lines
695 B
TypeScript
import type { ToolDefinition } from "../types.js";
|
|
import type { EventBus } from "../events.js";
|
|
|
|
export class ToolRegistry {
|
|
private readonly tools = new Map<string, ToolDefinition<any>>();
|
|
|
|
constructor(private readonly events: EventBus) {}
|
|
|
|
async register(tool: ToolDefinition<any>): Promise<void> {
|
|
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<any>[] {
|
|
return [...this.tools.values()];
|
|
}
|
|
|
|
get(name: string): ToolDefinition<any> | undefined {
|
|
return this.tools.get(name);
|
|
}
|
|
}
|