import type { Tool, ToolInputSchema } from './types.js'; export interface AnthropicToolDef { name: string; description: string; input_schema: ToolInputSchema; } export interface OpenAIToolDef { type: 'function'; function: { name: string; description: string; parameters: ToolInputSchema; }; } export class ToolRegistry { private tools: Map = new Map(); register(tool: Tool): void { if (this.tools.has(tool.name)) { throw new Error(`Tool '${tool.name}' is already registered`); } this.tools.set(tool.name, tool); } unregister(name: string): boolean { return this.tools.delete(name); } get(name: string): Tool | undefined { return this.tools.get(name); } list(): Tool[] { return Array.from(this.tools.values()); } toAnthropicFormat(): AnthropicToolDef[] { return this.list().map(t => ({ name: t.name, description: t.description, input_schema: t.inputSchema, })); } toOpenAIFormat(): OpenAIToolDef[] { return this.list().map(t => ({ type: 'function' as const, function: { name: t.name, description: t.description, parameters: t.inputSchema, }, })); } }