优化第一阶段
This commit is contained in:
23
lib/plugins/registry.js
Normal file
23
lib/plugins/registry.js
Normal file
@ -0,0 +1,23 @@
|
||||
const tools = [];
|
||||
|
||||
export function registerTool(definition) {
|
||||
const { id, name, desc, run } = definition || {};
|
||||
if (!id || !name || !run) {
|
||||
throw new Error("Tool definition must include id, name and run");
|
||||
}
|
||||
|
||||
const existing = tools.findIndex(t => t.id === id);
|
||||
const tool = { ...definition };
|
||||
|
||||
if (existing >= 0) {
|
||||
tools[existing] = tool;
|
||||
} else {
|
||||
tools.push(tool);
|
||||
}
|
||||
|
||||
return tool;
|
||||
}
|
||||
|
||||
export function getTools() {
|
||||
return [...tools];
|
||||
}
|
||||
Reference in New Issue
Block a user