Build extensible agent harness with interactive chat loop
This commit is contained in:
24
src/tools/registry.ts
Normal file
24
src/tools/registry.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user