-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtoolNames.ts
More file actions
121 lines (107 loc) · 3.4 KB
/
Copy pathtoolNames.ts
File metadata and controls
121 lines (107 loc) · 3.4 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* User-friendly display names for tools.
*
* Internal tool names are developer-facing and can be cryptic.
* This mapping provides cleaner names for the UI.
*/
/**
* Display names for specific tools that need custom names
*/
const TOOL_DISPLAY_NAMES: Record<string, string> = {
// Built-in tools
'Glob': 'Finding Files',
'Grep': 'Searching Files',
'Read': 'Reading File',
'Write': 'Writing File',
'Edit': 'Editing File',
'Bash': 'Running Command',
'Task': 'Running Agent',
'task': 'Running Agent',
'Agent': 'Running Agent',
'agent': 'Running Agent',
'WebFetch': 'Fetching URL',
'WebSearch': 'Searching Web',
'TodoWrite': 'Updating Tasks',
'NotebookEdit': 'Editing Notebook',
// Documentation tools
'SearchCraftAgents': 'Search Documentation',
};
/**
* Set of tool names that represent parent task tools (subagent launchers).
* The SDK renamed 'Task' to 'Agent' in v0.2.72 — both must be recognised.
* Add future renames here instead of scattering checks across the codebase.
*/
export const PARENT_TASK_TOOLS: ReadonlySet<string> = new Set([
'Task',
'task',
'Agent',
'agent',
]);
/** Check whether a tool name is a parent task tool (Task or Agent). */
export const isParentTaskTool = (name: string): boolean => PARENT_TASK_TOOLS.has(name);
/**
* Tools that should be hidden from the UI (purely internal state changes)
*/
export const HIDDEN_TOOLS = new Set<string>([
// Currently empty - safe mode is toggled via UI, not tools
]);
/**
* Format tool name for display (snake_case to Title Case)
* Generic fallback for tools without explicit mappings
*/
function formatToolName(name: string): string {
// Handle MCP tools (mcp__server__tool)
if (name.startsWith('mcp__')) {
const parts = name.split('__');
const tool = parts[2] || parts[1] || name;
return tool.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
}
// Handle api_* tools
if (name.startsWith('api_')) {
const apiName = name.slice(4); // Remove 'api_' prefix
return `API: ${apiName.charAt(0).toUpperCase() + apiName.slice(1)}`;
}
// Default: convert to title case
return name
.replace(/_/g, ' ')
.replace(/\b\w/g, (c) => c.toUpperCase());
}
/**
* Get user-friendly display name for a tool.
*
* @param toolName - The internal tool name (e.g., "mcp__linear__list_issues")
* @returns User-friendly display name
*/
export function getToolDisplayName(toolName: string): string {
// Check explicit mappings first (full name)
if (TOOL_DISPLAY_NAMES[toolName]) {
return TOOL_DISPLAY_NAMES[toolName];
}
// For MCP tools, also check mapping with just the base tool name
// e.g., "mcp__linear__list_issues" -> check "list_issues"
if (toolName.startsWith('mcp__')) {
const parts = toolName.split('__');
const baseName = parts[parts.length - 1] || toolName;
if (baseName && TOOL_DISPLAY_NAMES[baseName]) {
return TOOL_DISPLAY_NAMES[baseName];
}
}
// Fallback to generic formatting
return formatToolName(toolName);
}
/**
* Check if a tool should be hidden from the UI
*/
export function shouldHideTool(toolName: string): boolean {
// Check full name first
if (HIDDEN_TOOLS.has(toolName)) {
return true;
}
// For MCP tools, also check the base name
if (toolName.startsWith('mcp__')) {
const parts = toolName.split('__');
const baseName = parts[parts.length - 1] || '';
return HIDDEN_TOOLS.has(baseName);
}
return false;
}