diff options
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts')
-rw-r--r-- | src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts b/src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts new file mode 100644 index 000000000..5fdc52375 --- /dev/null +++ b/src/client/views/nodes/chatbot/tools/CodebaseSummarySearchTool.ts @@ -0,0 +1,75 @@ +import { Observation } from '../types/types'; +import { ParametersType, ToolInfo } from '../types/tool_types'; +import { Vectorstore } from '../vectorstore/Vectorstore'; +import { BaseTool } from './BaseTool'; + +const codebaseSummarySearchToolParams = [ + { + name: 'query', + type: 'string[]', + description: 'HIGHLY detailed (MANY SENTENCES) descriptions of the code files you want to find in the codebase.', + required: true, + }, + { + name: 'top_k', + type: 'number', + description: 'Number of top matching files to return. Default is 5.', + required: false, + }, +] as const; + +type CodebaseSummarySearchToolParamsType = typeof codebaseSummarySearchToolParams; + +const codebaseSummarySearchToolInfo: ToolInfo<CodebaseSummarySearchToolParamsType> = { + name: 'codebaseSummarySearch', + description: 'Searches the Dash codebase for files that match a semantic query. Returns a list of the most relevant files with their summaries to help understand the codebase structure.', + citationRules: `When using the CodebaseSummarySearchTool: +1. Present results clearly, showing filepaths and their summaries +2. Use the file summaries to provide context about the codebase organization +3. The results can be used to identify relevant files for deeper inspection`, + parameterRules: codebaseSummarySearchToolParams, +}; + +export class CodebaseSummarySearchTool extends BaseTool<CodebaseSummarySearchToolParamsType> { + constructor(private vectorstore: Vectorstore) { + super(codebaseSummarySearchToolInfo); + } + + async execute(args: ParametersType<CodebaseSummarySearchToolParamsType>): Promise<Observation[]> { + console.log(`Executing codebase summary search with query: "${args.query}"`); + + // Use the vectorstore's searchFileSummaries method + const topK = args.top_k || 5; + const results: { filepath: string; summary: string; score?: number | undefined }[] = []; + for (const query of args.query) { + const result = await this.vectorstore.searchFileSummaries(query, topK); + results.push(...result); + } + + if (results.length === 0) { + return [ + { + type: 'text', + text: `No files matching the query "${args.query}" were found in the codebase.`, + }, + ]; + } + + // Format results as observations + const formattedResults: Observation[] = [ + { + type: 'text', + text: `Found ${results.length} file(s) matching the query "${args.query}":\n\n`, + }, + ]; + + results.forEach((result, index) => { + formattedResults.push({ + type: 'text', + text: `File #${index + 1}: ${result.filepath}\n` + `Relevance Score: ${result.score?.toFixed(4) || 'N/A'}\n` + `Summary: ${result.summary}\n\n`, + }); + }); + + return formattedResults; + } +} |