forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool-registry.ts
More file actions
52 lines (41 loc) · 1.11 KB
/
Copy pathtool-registry.ts
File metadata and controls
52 lines (41 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { RuntimeError } from "../errors/runtime-errors.js";
import type { ToolDefinition } from "./types.js";
export class ToolRegistry {
private readonly tools = new Map<string, ToolDefinition>();
public register(tool: ToolDefinition): void {
if (this.tools.has(tool.name)) {
throw new RuntimeError(
"DUPLICATE_TOOL",
`Tool "${tool.name}" is already registered.`,
{ toolName: tool.name }
);
}
this.tools.set(tool.name, tool);
}
public get(toolName: string): ToolDefinition {
const tool = this.tools.get(toolName);
if (!tool) {
throw new RuntimeError(
"TOOL_NOT_FOUND",
`Tool "${toolName}" is not registered.`,
{ toolName }
);
}
return tool;
}
public has(toolName: string): boolean {
return this.tools.has(toolName);
}
public unregister(toolName: string): boolean {
return this.tools.delete(toolName);
}
public clear(): void {
this.tools.clear();
}
public size(): number {
return this.tools.size;
}
public list(): ToolDefinition[] {
return Array.from(this.tools.values());
}
}