Skip to content

Commit 7e69225

Browse files
committed
Reorder tool list to be at top of tools.d.ts. Read it from file so it's formatted nicely
1 parent c1d61b8 commit 7e69225

File tree

3 files changed

+70
-60
lines changed

3 files changed

+70
-60
lines changed

backend/src/templates/agents/agent-builder.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
openrouterModels,
77
AGENT_CONFIG_FILE,
88
} from '@codebuff/common/constants'
9-
import { compileToolDefinitions } from '@codebuff/common/tools/compile-tool-definitions'
9+
1010
import { AgentTemplateTypes } from '@codebuff/common/types/session-state'
1111
import z from 'zod/v4'
1212

@@ -16,7 +16,6 @@ import type { ToolName } from '@codebuff/common/tools/constants'
1616

1717
const TEMPLATE_RELATIVE_PATH =
1818
`../../../../common/src/util/${AGENT_CONFIG_FILE}` as const
19-
2019
// Import to validate path exists at compile time
2120
import(TEMPLATE_RELATIVE_PATH)
2221

@@ -37,7 +36,18 @@ export const agentBuilder = (model: Model): Omit<AgentTemplate, 'id'> => {
3736
console.warn(`Could not read ${AGENT_CONFIG_FILE}:`, error)
3837
agentTemplateContent = '// Agent template types not available'
3938
}
40-
const toolDefinitionsContent = compileToolDefinitions()
39+
// Read the tools.d.ts content from common package
40+
let toolDefinitionsContent = ''
41+
try {
42+
const toolsPath = path.join(
43+
__dirname,
44+
'../../../../common/src/util/tools.d.ts',
45+
)
46+
toolDefinitionsContent = fs.readFileSync(toolsPath, 'utf8')
47+
} catch (error) {
48+
console.warn(`Could not read tools.d.ts from common:`, error)
49+
toolDefinitionsContent = '// Tool definitions not available'
50+
}
4151

4252
return {
4353
displayName: 'Bob the Agent Builder',
@@ -182,7 +192,7 @@ IMPORTANT: Always end your response with the end_turn tool when you have complet
182192
},
183193
}
184194

185-
// Step 3: Write the tool definitions file
195+
// Step 3: Write the tool definitions file (copy from existing tools.d.ts)
186196
yield {
187197
toolName: 'write_file',
188198
args: {

common/src/tools/compile-tool-definitions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export interface ${toPascalCase(toolName)}Params ${typeDefinition}`
3636
.map(([toolName]) => ` '${toolName}': ${toPascalCase(toolName)}Params`)
3737
.join('\n')
3838

39-
return `${toolInterfaces}
40-
41-
/**
39+
return `/**
4240
* Union type of all available tool names
4341
*/
4442
export type ToolName = ${toolUnion}
@@ -50,6 +48,8 @@ export interface ToolParamsMap {
5048
${toolParamsMap}
5149
}
5250
51+
${toolInterfaces}
52+
5353
/**
5454
* Get parameters type for a specific tool
5555
*/

common/src/util/tools.d.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
/**
2+
* Union type of all available tool names
3+
*/
4+
export type ToolName =
5+
| 'add_message'
6+
| 'add_subgoal'
7+
| 'browser_logs'
8+
| 'code_search'
9+
| 'create_plan'
10+
| 'end_turn'
11+
| 'find_files'
12+
| 'read_docs'
13+
| 'read_files'
14+
| 'run_file_change_hooks'
15+
| 'run_terminal_command'
16+
| 'send_agent_message'
17+
| 'set_messages'
18+
| 'set_output'
19+
| 'spawn_agents'
20+
| 'spawn_agents_async'
21+
| 'str_replace'
22+
| 'think_deeply'
23+
| 'update_subgoal'
24+
| 'web_search'
25+
| 'write_file'
26+
27+
/**
28+
* Map of tool names to their parameter types
29+
*/
30+
export interface ToolParamsMap {
31+
add_message: AddMessageParams
32+
add_subgoal: AddSubgoalParams
33+
browser_logs: BrowserLogsParams
34+
code_search: CodeSearchParams
35+
create_plan: CreatePlanParams
36+
end_turn: EndTurnParams
37+
find_files: FindFilesParams
38+
read_docs: ReadDocsParams
39+
read_files: ReadFilesParams
40+
run_file_change_hooks: RunFileChangeHooksParams
41+
run_terminal_command: RunTerminalCommandParams
42+
send_agent_message: SendAgentMessageParams
43+
set_messages: SetMessagesParams
44+
set_output: SetOutputParams
45+
spawn_agents: SpawnAgentsParams
46+
spawn_agents_async: SpawnAgentsAsyncParams
47+
str_replace: StrReplaceParams
48+
think_deeply: ThinkDeeplyParams
49+
update_subgoal: UpdateSubgoalParams
50+
web_search: WebSearchParams
51+
write_file: WriteFileParams
52+
}
53+
154
/**
255
* Add a new message to the conversation history. To be used for complex requests that can't be solved in a single step, as you may forget what happened!
356
*/
@@ -225,59 +278,6 @@ export interface WriteFileParams {
225278
content: string
226279
}
227280

228-
/**
229-
* Union type of all available tool names
230-
*/
231-
export type ToolName =
232-
| 'add_message'
233-
| 'add_subgoal'
234-
| 'browser_logs'
235-
| 'code_search'
236-
| 'create_plan'
237-
| 'end_turn'
238-
| 'find_files'
239-
| 'read_docs'
240-
| 'read_files'
241-
| 'run_file_change_hooks'
242-
| 'run_terminal_command'
243-
| 'send_agent_message'
244-
| 'set_messages'
245-
| 'set_output'
246-
| 'spawn_agents'
247-
| 'spawn_agents_async'
248-
| 'str_replace'
249-
| 'think_deeply'
250-
| 'update_subgoal'
251-
| 'web_search'
252-
| 'write_file'
253-
254-
/**
255-
* Map of tool names to their parameter types
256-
*/
257-
export interface ToolParamsMap {
258-
add_message: AddMessageParams
259-
add_subgoal: AddSubgoalParams
260-
browser_logs: BrowserLogsParams
261-
code_search: CodeSearchParams
262-
create_plan: CreatePlanParams
263-
end_turn: EndTurnParams
264-
find_files: FindFilesParams
265-
read_docs: ReadDocsParams
266-
read_files: ReadFilesParams
267-
run_file_change_hooks: RunFileChangeHooksParams
268-
run_terminal_command: RunTerminalCommandParams
269-
send_agent_message: SendAgentMessageParams
270-
set_messages: SetMessagesParams
271-
set_output: SetOutputParams
272-
spawn_agents: SpawnAgentsParams
273-
spawn_agents_async: SpawnAgentsAsyncParams
274-
str_replace: StrReplaceParams
275-
think_deeply: ThinkDeeplyParams
276-
update_subgoal: UpdateSubgoalParams
277-
web_search: WebSearchParams
278-
write_file: WriteFileParams
279-
}
280-
281281
/**
282282
* Get parameters type for a specific tool
283283
*/

0 commit comments

Comments
 (0)