feat: add ToolRegistry.clone() and replace() for per-session registries
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user