feat: add ToolRegistry.clone() and replace() for per-session registries

This commit is contained in:
William Valentin
2026-02-06 15:58:19 -08:00
parent ed1e290ddd
commit 1314ac0163
3 changed files with 93 additions and 1 deletions
+20
View File
@@ -31,6 +31,26 @@ export class ToolRegistry {
return this.tools.delete(name);
}
/** Replace an existing tool with a new implementation. Throws if not registered. */
replace(tool: Tool): void {
if (!this.tools.has(tool.name)) {
throw new Error(`Tool '${tool.name}' is not registered — cannot replace`);
}
this.tools.set(tool.name, tool);
}
/** Create a shallow clone of this registry (new Map, same Tool objects + policy). */
clone(): ToolRegistry {
const cloned = new ToolRegistry();
for (const tool of this.tools.values()) {
cloned.register(tool);
}
if (this._policy) {
cloned.setPolicy(this._policy);
}
return cloned;
}
get(name: string): Tool | undefined {
return this.tools.get(name);
}