-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathregistry.ts
More file actions
106 lines (94 loc) · 3.47 KB
/
registry.ts
File metadata and controls
106 lines (94 loc) · 3.47 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Tool registry - manages available tools
*/
import type { Tool, ToolDefinition } from '../types/tools';
import { ReadTool } from './read';
import { WriteTool } from './write';
import { EditTool } from './edit';
import { BashTool } from './bash';
import { GlobTool } from './glob';
import { GrepTool } from './grep';
import { TaskListTool } from './task-list';
import { TaskCreateTool } from './task-create';
import { TaskGetTool } from './task-get';
import { TaskUpdateTool } from './task-update';
import { WebSearchTool } from './web-search';
import { WebFetchTool } from './web-fetch';
import { BashOutputTool } from './bash-output';
import { KillBashTool } from './kill-bash';
import { SkillTool } from './skill';
export class ToolRegistry {
private tools = new Map<string, Tool<any, any>>();
register(tool: Tool<any, any>): void {
this.tools.set(tool.name, tool);
}
unregister(name: string): boolean {
return this.tools.delete(name);
}
get(name: string): Tool<any, any> | undefined {
return this.tools.get(name);
}
has(name: string): boolean {
return this.tools.has(name);
}
getAll(): Tool<any, any>[] {
return Array.from(this.tools.values());
}
getDefinitions(): ToolDefinition[] {
return this.getAll().map((tool) => ({
type: 'function',
function: {
name: tool.name,
description: tool.description,
parameters: tool.parameters,
},
}));
}
getAllowedTools(allowedTools?: string[]): Tool<any, any>[] {
if (!allowedTools || allowedTools.length === 0) {
return this.getAll();
}
return allowedTools
.map((name) => this.tools.get(name))
.filter((tool): tool is Tool<any, any> => tool !== undefined);
}
}
// Create default registry with built-in tools
export function createDefaultRegistry(): ToolRegistry {
const registry = new ToolRegistry();
registry.register(new ReadTool());
registry.register(new WriteTool());
registry.register(new EditTool());
registry.register(new BashTool());
registry.register(new GlobTool());
registry.register(new GrepTool());
registry.register(new TaskListTool());
registry.register(new TaskCreateTool());
registry.register(new TaskGetTool());
registry.register(new TaskUpdateTool());
registry.register(new WebSearchTool());
registry.register(new WebFetchTool());
registry.register(new BashOutputTool());
registry.register(new KillBashTool());
registry.register(new SkillTool());
return registry;
}
// Global default registry with specific tool types
export const defaultToolRegistry = createDefaultRegistry();
// Re-export tools
export { readTool, ReadTool } from './read';
export { writeTool, WriteTool } from './write';
export { editTool, EditTool } from './edit';
export { bashTool, BashTool, cleanupBackgroundProcesses } from './bash';
export { globTool, GlobTool } from './glob';
export { grepTool, GrepTool } from './grep';
export { taskListTool, TaskListTool } from './task-list';
export { taskCreateTool, TaskCreateTool } from './task-create';
export { taskGetTool, TaskGetTool } from './task-get';
export { taskUpdateTool, TaskUpdateTool } from './task-update';
export { webSearchTool, WebSearchTool } from './web-search';
export { webFetchTool, WebFetchTool } from './web-fetch';
export { bashOutputTool, BashOutputTool } from './bash-output';
export { killBashTool, KillBashTool } from './kill-bash';
export { askUserQuestionTool, AskUserQuestionTool } from './ask-user-question';
export { skillTool, SkillTool } from './skill';