示例:ToolRegistry
ts
export class ToolRegistry {
private tools = new Map<string, Tool>()
register(tool: Tool) {
if (this.tools.has(tool.name)) {
throw new Error(`Duplicate tool: ${tool.name}`)
}
this.tools.set(tool.name, tool)
}
get(name: string): Tool {
const tool = this.tools.get(name)
if (!tool) {
throw new Error(`Unknown tool: ${name}`)
}
return tool
}
toSchemas() {
return [...this.tools.values()].map(tool => ({
name: tool.name,
description: tool.description,
input_schema: tool.schema.toJSON(),
}))
}
}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
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
这个注册表只做注册、查找和 schema 输出。权限、执行、UI 都不应该塞进这里。