aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/FileContentTool.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/FileContentTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/FileContentTool.ts78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/tools/FileContentTool.ts b/src/client/views/nodes/chatbot/tools/FileContentTool.ts
new file mode 100644
index 000000000..f994aab67
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/FileContentTool.ts
@@ -0,0 +1,78 @@
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+import { Vectorstore } from '../vectorstore/Vectorstore';
+import { BaseTool } from './BaseTool';
+
+const fileContentToolParams = [
+ {
+ name: 'filepaths',
+ type: 'string[]',
+ description: 'Array of file paths to retrieve content for. Limited to a maximum of 3 files.',
+ required: true,
+ },
+] as const;
+
+type FileContentToolParamsType = typeof fileContentToolParams;
+
+const fileContentToolInfo: ToolInfo<FileContentToolParamsType> = {
+ name: 'fileContent',
+ description: 'Retrieves the complete content of up to 3 specified files from the Dash codebase to help understand implementation details.',
+ citationRules: `When using the FileContentTool:
+1. Present file content clearly with proper code formatting
+2. Include the file path at the beginning of each file's content
+3. Use this tool after identifying relevant files with the CodebaseSummarySearchTool
+4. Maximum of 3 files can be retrieved at once`,
+ parameterRules: fileContentToolParams,
+};
+
+export class FileContentTool extends BaseTool<FileContentToolParamsType> {
+ constructor(private vectorstore: Vectorstore) {
+ super(fileContentToolInfo);
+ }
+
+ async execute(args: ParametersType<FileContentToolParamsType>): Promise<Observation[]> {
+ console.log(`Executing file content retrieval for: ${args.filepaths.join(', ')}`);
+
+ // Enforce the limit of 3 files
+ const filepaths = args.filepaths.slice(0, 3);
+ if (args.filepaths.length > 3) {
+ console.warn(`FileContentTool: Request for ${args.filepaths.length} files was limited to 3`);
+ }
+
+ const observations: Observation[] = [];
+
+ if (filepaths.length === 0) {
+ return [
+ {
+ type: 'text',
+ text: 'No filepaths provided. Please specify at least one file path to retrieve content.',
+ },
+ ];
+ }
+
+ // Add initial message
+ observations.push({
+ type: 'text',
+ text: `Retrieving content for ${filepaths.length} file(s):\n\n`,
+ });
+
+ // Fetch content for each file
+ for (const filepath of filepaths) {
+ const content = await this.vectorstore.getFileContent(filepath);
+
+ if (content) {
+ observations.push({
+ type: 'text',
+ text: `File: ${filepath}\n\n\`\`\`\n${content}\n\`\`\`\n\n`,
+ });
+ } else {
+ observations.push({
+ type: 'text',
+ text: `Error: Could not retrieve content for file "${filepath}"\n\n`,
+ });
+ }
+ }
+
+ return observations;
+ }
+}