feat(ai): extensible agent tool registry

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-01 18:10:11 +10:00
parent f80fd278a5
commit de4b6a8403
2 changed files with 49 additions and 0 deletions

17
lib/ai/agent/registry.js Normal file
View File

@@ -0,0 +1,17 @@
export function createRegistry() {
const tools = new Map();
return {
registerTool(def) {
if (!def?.name) throw new Error('tool def needs a name');
if (tools.has(def.name)) throw new Error(`tool "${def.name}" already registered`);
tools.set(def.name, def);
},
getTool(name) { return tools.get(name); },
listTools() { return [...tools.values()]; },
// Anthropic tool-use schema — handlers are intentionally stripped.
toAnthropicTools() {
return [...tools.values()].map(({ name, description, input_schema }) =>
({ name, description, input_schema }));
}
};
}