@@ -10,12 +10,13 @@ import type { ToolName } from '@codebuff/common/tools/constants'
1010import type { customToolDefinitionsSchema } from '@codebuff/common/util/file'
1111import type { JSONSchema } from 'zod/v4/core'
1212
13- function paramsSection (
13+ function paramsSection ( params : {
1414 schema :
1515 | { type : 'zod' ; value : z . ZodObject }
16- | { type : 'json' ; value : JSONSchema . BaseSchema } ,
17- endsAgentStep : boolean ,
18- ) {
16+ | { type : 'json' ; value : JSONSchema . BaseSchema }
17+ endsAgentStep : boolean
18+ } ) {
19+ const { schema, endsAgentStep } = params
1920 const schemaWithEndsAgentStepParam =
2021 schema . type === 'zod'
2122 ? z . toJSONSchema (
@@ -61,15 +62,22 @@ function paramsSection(
6162}
6263
6364// Helper function to build the full tool description markdown
64- export function buildToolDescription (
65- toolName : string ,
65+ export function buildToolDescription ( params : {
66+ toolName : string
6667 schema :
6768 | { type : 'zod' ; value : z . ZodObject }
68- | { type : 'json' ; value : JSONSchema . BaseSchema } ,
69- description : string = '' ,
70- endsAgentStep : boolean ,
71- exampleInputs : any [ ] = [ ] ,
72- ) : string {
69+ | { type : 'json' ; value : JSONSchema . BaseSchema }
70+ description ?: string
71+ endsAgentStep : boolean
72+ exampleInputs ?: any [ ]
73+ } ) : string {
74+ const {
75+ toolName,
76+ schema,
77+ description = '' ,
78+ endsAgentStep,
79+ exampleInputs = [ ] ,
80+ } = params
7381 const descriptionWithExamples = buildArray (
7482 description ,
7583 exampleInputs . length > 0
@@ -82,31 +90,32 @@ export function buildToolDescription(
8290 return buildArray ( [
8391 `### ${ toolName } ` ,
8492 schema . value . description || '' ,
85- paramsSection ( schema , endsAgentStep ) ,
93+ paramsSection ( { schema, endsAgentStep } ) ,
8694 descriptionWithExamples ,
8795 ] ) . join ( '\n\n' )
8896}
8997
9098export const toolDescriptions = Object . fromEntries (
9199 Object . entries ( codebuffToolDefs ) . map ( ( [ name , config ] ) => [
92100 name ,
93- buildToolDescription (
94- name ,
95- { type : 'zod' , value : config . parameters } ,
96- config . description ,
97- config . endsAgentStep ,
98- ) ,
101+ buildToolDescription ( {
102+ toolName : name ,
103+ schema : { type : 'zod' , value : config . parameters } ,
104+ description : config . description ,
105+ endsAgentStep : config . endsAgentStep ,
106+ } ) ,
99107 ] ) ,
100108) as Record < keyof typeof codebuffToolDefs , string >
101109
102- function buildShortToolDescription (
103- toolName : string ,
110+ function buildShortToolDescription ( params : {
111+ toolName : string
104112 schema :
105113 | { type : 'zod' ; value : z . ZodObject }
106- | { type : 'json' ; value : JSONSchema . BaseSchema } ,
107- endsAgentStep : boolean ,
108- ) : string {
109- return `${ toolName } :\n${ paramsSection ( schema , endsAgentStep ) } `
114+ | { type : 'json' ; value : JSONSchema . BaseSchema }
115+ endsAgentStep : boolean
116+ } ) : string {
117+ const { toolName, schema, endsAgentStep } = params
118+ return `${ toolName } :\n${ paramsSection ( { schema, endsAgentStep } ) } `
110119}
111120
112121export const getToolsInstructions = (
@@ -199,13 +208,13 @@ ${[
199208 ) . map ( ( name ) => toolDescriptions [ name ] ) ,
200209 ...Object . keys ( additionalToolDefinitions ) . map ( ( toolName ) => {
201210 const toolDef = additionalToolDefinitions [ toolName ]
202- return buildToolDescription (
211+ return buildToolDescription ( {
203212 toolName,
204- { type : 'json' , value : toolDef . inputJsonSchema } ,
205- toolDef . description ,
206- toolDef . endsAgentStep ,
207- toolDef . exampleInputs ,
208- )
213+ schema : { type : 'json' , value : toolDef . inputJsonSchema } ,
214+ description : toolDef . description ,
215+ endsAgentStep : toolDef . endsAgentStep ,
216+ exampleInputs : toolDef . exampleInputs ,
217+ } )
209218 } ) ,
210219] . join ( '\n\n' ) } `. trim ( )
211220}
@@ -221,19 +230,19 @@ export const getShortToolInstructions = (
221230 ) as ( keyof typeof codebuffToolDefs ) [ ]
222231 ) . map ( ( name ) => {
223232 const tool = codebuffToolDefs [ name ]
224- return buildShortToolDescription (
225- name ,
226- { type : 'zod' , value : tool . parameters } ,
227- tool . endsAgentStep ,
228- )
233+ return buildShortToolDescription ( {
234+ toolName : name ,
235+ schema : { type : 'zod' , value : tool . parameters } ,
236+ endsAgentStep : tool . endsAgentStep ,
237+ } )
229238 } ) ,
230239 ...Object . keys ( additionalToolDefinitions ) . map ( ( name ) => {
231240 const { inputJsonSchema, endsAgentStep } = additionalToolDefinitions [ name ]
232- return buildShortToolDescription (
233- name ,
234- { type : 'json' , value : inputJsonSchema } ,
241+ return buildShortToolDescription ( {
242+ toolName : name ,
243+ schema : { type : 'json' , value : inputJsonSchema } ,
235244 endsAgentStep,
236- )
245+ } )
237246 } ) ,
238247 ]
239248
0 commit comments