mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
refactor: simplify web search params and improve vault file handling
- Remove unnecessary reasoning parameter from web search function - Update Path enum to separate root and AI agent directory - Add filename matching to vault search results - Use Path enum constants consistently across services
This commit is contained in:
parent
8ab4c93553
commit
9ab0897c57
4 changed files with 17 additions and 17 deletions
|
|
@ -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)),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
};
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<SearchMatch[]> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue