From 9488146162da8ec6e329b81df2031c588bbf62e9 Mon Sep 17 00:00:00 2001 From: duanfuxiang Date: Mon, 17 Mar 2025 11:05:41 +0800 Subject: [PATCH] update settings, add search files method --- src/core/prompts/system.ts | 11 +++++---- src/settings/SettingTab.tsx | 45 +++++++++++++++++++++++++---------- src/types/settings.ts | 5 +++- src/utils/prompt-generator.ts | 14 ++++++++--- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/core/prompts/system.ts b/src/core/prompts/system.ts index ebb47ae..652862a 100644 --- a/src/core/prompts/system.ts +++ b/src/core/prompts/system.ts @@ -28,6 +28,7 @@ async function generatePrompt( cwd: string, supportsComputerUse: boolean, mode: Mode, + filesSearchMethod: string, mcpHub?: McpHub, diffStrategy?: DiffStrategy, browserViewportSize?: string, @@ -43,8 +44,6 @@ async function generatePrompt( // throw new Error("Extension context is required for generating system prompt") // } - const searchTool = "semantic" - // If diff is disabled, don't pass the diffStrategy const effectiveDiffStrategy = diffEnabled ? diffStrategy : undefined @@ -66,7 +65,7 @@ ${getSharedToolUseSection()} ${getToolDescriptionsForMode( mode, cwd, - searchTool, + filesSearchMethod, supportsComputerUse, effectiveDiffStrategy, browserViewportSize, @@ -82,7 +81,7 @@ ${mcpServersSection} ${getCapabilitiesSection( mode, cwd, - searchTool, + filesSearchMethod, )} ${modesSection} @@ -90,7 +89,7 @@ ${modesSection} ${getRulesSection( mode, cwd, - searchTool, + filesSearchMethod, supportsComputerUse, effectiveDiffStrategy, experiments, @@ -109,6 +108,7 @@ export const SYSTEM_PROMPT = async ( cwd: string, supportsComputerUse: boolean, mode: Mode = defaultModeSlug, + filesSearchMethod: string = 'regex', mcpHub?: McpHub, diffStrategy?: DiffStrategy, browserViewportSize?: string, @@ -158,6 +158,7 @@ export const SYSTEM_PROMPT = async ( cwd, supportsComputerUse, currentMode.slug, + filesSearchMethod, mcpHub, effectiveDiffStrategy, browserViewportSize, diff --git a/src/settings/SettingTab.tsx b/src/settings/SettingTab.tsx index 9dc41e5..6dde387 100644 --- a/src/settings/SettingTab.tsx +++ b/src/settings/SettingTab.tsx @@ -38,6 +38,7 @@ export class InfioSettingTab extends PluginSettingTab { containerEl.empty() this.renderModelsSection(containerEl) this.renderDeepResearchSection(containerEl) + this.renderFilesSearchSection(containerEl) this.renderRAGSection(containerEl) this.renderAutoCompleteSection(containerEl) } @@ -58,6 +59,26 @@ export class InfioSettingTab extends PluginSettingTab { ); } + private renderFilesSearchSection(containerEl: HTMLElement): void { + new Setting(containerEl) + .setHeading() + .setName('Files Search Method') + .setDesc('Choose the method to search for files.') + .addDropdown((dropdown) => + dropdown + .addOption('auto', 'Auto') + .addOption('regex', 'Regex') + .addOption('semantic', 'Semantic') + .setValue(this.plugin.settings.filesSearchMethod) + .onChange(async (value) => { + await this.plugin.setSettings({ + ...this.plugin.settings, + filesSearchMethod: value as 'regex' | 'semantic' | 'auto', + }) + }), + ) + } + renderModelsSection(containerEl: HTMLElement): void { const modelsDiv = containerEl.createDiv("models-section"); this.modelsContainer = modelsDiv; @@ -73,7 +94,7 @@ export class InfioSettingTab extends PluginSettingTab { .setName('Serper Api Key') .setDesc(createFragment(el => { el.appendText('API key for web search functionality. Serper allows the plugin to search the internet for information, similar to a search engine. Get your key from '); - const a = el.createEl('a', { + const a = el.createEl('a', { href: 'https://serpapi.com/manage-api-key', text: 'https://serpapi.com/manage-api-key' }); @@ -96,7 +117,7 @@ export class InfioSettingTab extends PluginSettingTab { .setName('Jina Api Key (Optional)') .setDesc(createFragment(el => { el.appendText('API key for parsing web pages into markdown format. If not provided, local parsing will be used. Get your key from '); - const a = el.createEl('a', { + const a = el.createEl('a', { href: 'https://jina.ai/api-key', text: 'https://jina.ai/api-key' }); @@ -290,16 +311,16 @@ export class InfioSettingTab extends PluginSettingTab { private renderAutoCompleteContent(containerEl: HTMLElement): void { const updateSettings = async (update: Partial) => { - await this.plugin.setSettings({ - ...this.plugin.settings, - ...update - }); - - // 只重新渲染 AutoComplete 部分 - if (this.autoCompleteContainer) { - this.autoCompleteContainer.empty(); - this.renderAutoCompleteContent(this.autoCompleteContainer); - } + await this.plugin.setSettings({ + ...this.plugin.settings, + ...update + }); + + // 只重新渲染 AutoComplete 部分 + if (this.autoCompleteContainer) { + this.autoCompleteContainer.empty(); + this.renderAutoCompleteContent(this.autoCompleteContainer); + } }; const errors = new Map(); diff --git a/src/types/settings.ts b/src/types/settings.ts index 80923af..affa9d3 100644 --- a/src/types/settings.ts +++ b/src/types/settings.ts @@ -222,10 +222,13 @@ export const InfioSettingsSchema = z.object({ // Mode mode: z.string().catch('ask'), - // Web Search + // Deep Research serperApiKey: z.string().catch(''), jinaApiKey: z.string().catch(''), + // Files Search + filesSearchMethod: z.enum(['regex', 'semantic', 'auto']).catch('auto'), + /// [compatible] // activeModels [compatible] activeModels: z.array( diff --git a/src/utils/prompt-generator.ts b/src/utils/prompt-generator.ts index a931bd1..ffd02c8 100644 --- a/src/utils/prompt-generator.ts +++ b/src/utils/prompt-generator.ts @@ -158,7 +158,15 @@ export class PromptGenerator { }, ] console.log('this.settings.mode', this.settings.mode) - const systemMessage = await this.getSystemMessageNew(this.settings.mode) + let filesSearchMethod = this.settings.filesSearchMethod + if (filesSearchMethod === 'auto' && this.settings.embeddingModelId && this.settings.embeddingModelId !== '') { + filesSearchMethod = 'semantic' + } else { + filesSearchMethod = 'regex' + } + + console.log('filesSearchMethod: ', filesSearchMethod) + const systemMessage = await this.getSystemMessageNew(this.settings.mode, filesSearchMethod) const requestMessages: RequestMessage[] = [ systemMessage, @@ -446,8 +454,8 @@ export class PromptGenerator { } } - private async getSystemMessageNew(mode: Mode): Promise { - const systemPrompt = await SYSTEM_PROMPT(this.app.vault.getRoot().path, false, mode) + private async getSystemMessageNew(mode: Mode, filesSearchMethod: string): Promise { + const systemPrompt = await SYSTEM_PROMPT(this.app.vault.getRoot().path, false, mode, filesSearchMethod) return { role: 'system',