@@ -41,10 +41,12 @@ const composioToolSearchToolSuggestion = z.object({
4141 tool_slug : z . string ( ) ,
4242 description : z . string ( ) ,
4343} ) ;
44+
4445const composioToolSearchResponseSchema = z . object ( {
45- results : z . array ( composioToolSearchToolSuggestion ) ,
46- related_tools : z . array ( composioToolSearchToolSuggestion ) ,
47- } ) ;
46+ main_tools : z . array ( composioToolSearchToolSuggestion ) . optional ( ) ,
47+ related_tools : z . array ( composioToolSearchToolSuggestion ) . optional ( ) ,
48+ results : z . array ( composioToolSearchToolSuggestion ) . optional ( ) , // Keep for backward compatibility
49+ } ) . passthrough ( ) ;
4850
4951function getContextPrompt ( context : z . infer < typeof CopilotChatContext > | null ) : string {
5052 let prompt = '' ;
@@ -127,17 +129,21 @@ async function searchRelevantTools(usageTracker: UsageTracker, query: string): P
127129 } ) ;
128130
129131 // parse results
132+ logger . log ( `raw search result data: ${ JSON . stringify ( searchResult . data ) } ` ) ;
130133 const result = composioToolSearchResponseSchema . safeParse ( searchResult . data ) ;
131134 if ( ! result . success ) {
132- logger . log ( `tool search response is invalid: ${ result . error } ` ) ;
135+ logger . log ( `tool search response is invalid: ${ JSON . stringify ( result . error ) } ` ) ;
136+ logger . log ( `expected schema: results (array), got: ${ JSON . stringify ( Object . keys ( searchResult . data || { } ) ) } ` ) ;
133137 return 'No tools found!' ;
134138 }
135- if ( ! result . data . results . length ) {
139+ const tools = result . data . main_tools || result . data . results || [ ] ;
140+
141+ if ( ! tools . length ) {
136142 logger . log ( `tool search yielded no results` ) ;
137143 return 'No tools found!' ;
138144 }
139145
140- const toolSlugs = result . data . results . map ( ( item ) => item . tool_slug ) ;
146+ const toolSlugs = tools . map ( ( item ) => item . tool_slug ) ;
141147 logger . log ( `found tool slugs: ${ toolSlugs . join ( ', ' ) } ` ) ;
142148 console . log ( "✅ TOOL CALL SUCCESS: COMPOSIO_SEARCH_TOOLS" , {
143149 toolSlugs,
0 commit comments