diff --git a/AIClasses/Gemini/Gemini.ts b/AIClasses/Gemini/Gemini.ts index cafc28a..1b58fa6 100644 --- a/AIClasses/Gemini/Gemini.ts +++ b/AIClasses/Gemini/Gemini.ts @@ -51,16 +51,6 @@ export class Gemini implements IAIClass { description: `Use this function when you need to search the web for current information, recent events, news, or facts that may have changed. After calling this, you will be able to perform web searches.`, - parameters: { - type: "object", - properties: { - reasoning: { - type: "string", - description: "Brief explanation of why web search is needed" - } - }, - required: ["reasoning"] - } }, ...this.mapFunctionDefinitions(this.aiFunctionDefinitions.getQueryActions(allowDestructiveActions)), ] diff --git a/Enums/Path.ts b/Enums/Path.ts index b9e03cb..abf6496 100644 --- a/Enums/Path.ts +++ b/Enums/Path.ts @@ -1,5 +1,6 @@ export enum Path { - Root = "AI Agent", - UserInstruction = `${Path.Root}/AGENT_INSTRUCTIONS.md`, - Conversations = `${Path.Root}/Conversations` + Root = "/", + AIAgentDir = "AI Agent", + UserInstruction = `${Path.AIAgentDir}/AGENT_INSTRUCTIONS.md`, + Conversations = `${Path.AIAgentDir}/Conversations` }; \ No newline at end of file diff --git a/Services/AIFunctionService.ts b/Services/AIFunctionService.ts index 034f5a6..b807c73 100644 --- a/Services/AIFunctionService.ts +++ b/Services/AIFunctionService.ts @@ -6,6 +6,7 @@ import { AIFunctionResponse } from "AIClasses/FunctionDefinitions/AIFunctionResp import type { AIFunctionCall } from "AIClasses/AIFunctionCall"; import type { SearchMatch } from "../Helpers/SearchTypes"; import { normalizePath, TFile } from "obsidian"; +import { Path } from "Enums/Path"; export class AIFunctionService { @@ -40,7 +41,7 @@ export class AIFunctionService { const matches: SearchMatch[] = searchTerm.trim() === "" ? [] : await this.fileSystemService.searchVaultFiles(searchTerm); if (matches.length === 0) { - const files: TFile[] = await this.fileSystemService.listFilesInDirectory("/"); + const files: TFile[] = await this.fileSystemService.listFilesInDirectory(Path.Root); return files.map((file) => ({ name: file.basename, path: file.path diff --git a/Services/VaultService.ts b/Services/VaultService.ts index 62e782b..61dddee 100644 --- a/Services/VaultService.ts +++ b/Services/VaultService.ts @@ -9,7 +9,7 @@ import type { SearchMatch, SearchSnippet } from "../Helpers/SearchTypes"; /* This service protects the users vault through their exclusions. The plugin root is excluded by default */ export class VaultService { - private readonly AGENT_ROOT = `${Path.Root}/**`; + private readonly AGENT_ROOT = `${Path.AIAgentDir}/**`; private readonly USER_INSTRUCTION = Path.UserInstruction; private readonly plugin: AIAgentPlugin; @@ -95,12 +95,12 @@ export class VaultService { public async searchVaultFiles(searchTerm: string): Promise { let regex: RegExp; try { - regex = new RegExp(searchTerm, "ig"); // Added 'g' flag for global matching + regex = new RegExp(searchTerm, "ig"); } catch { regex = new RegExp(escapeRegex(searchTerm), "ig"); } - const files: TFile[] = this.vault.getFiles().filter(file => !this.isExclusion(file.path)); + const files: TFile[] = await this.listFilesInDirectory(Path.Root); const allMatches: SearchMatch[] = []; @@ -143,6 +143,14 @@ export class VaultService { results.push({ file, snippets }); } + // add filename matches + for (const file of files) { + if (file.basename.match(regex) && + !results.some(result => result.file.basename === file.basename)) { + results.push({ file, snippets: [] }); + } + } + return results; }