Merge remote-tracking branch 'origin/master'

This commit is contained in:
duanfuxiang
2025-06-11 15:05:43 +08:00
25 changed files with 626 additions and 95 deletions

View File

@@ -29,7 +29,10 @@ import {
LLMBaseUrlNotSetException,
LLMModelNotSetException,
} from '../../core/llm/exception'
import { regexSearchFiles } from '../../core/ripgrep'
import { matchSearchUsingCorePlugin } from '../../core/file-search/match/coreplugin-match'
import { matchSearchUsingOmnisearch } from '../../core/file-search/match/omnisearch-match'
import { regexSearchUsingRipgrep } from '../../core/file-search/regex/ripgrep-regex'
import { regexSearchUsingCorePlugin } from '../../core/file-search/regex/coreplugin-regex'
import { useChatHistory } from '../../hooks/use-chat-history'
import { useCustomModes } from '../../hooks/use-custom-mode'
import { t } from '../../lang/helpers'
@@ -609,12 +612,40 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
mentionables: [],
}
}
} else if (toolArgs.type === 'match_search_files') {
const searchBackend = settings.filesSearchSettings.matchBackend
let results: string;
if (searchBackend === 'omnisearch') {
results = await matchSearchUsingOmnisearch(toolArgs.query, app)
} else {
results = await matchSearchUsingCorePlugin(toolArgs.query, app)
}
const formattedContent = `[match_search_files for '${toolArgs.filepath}'] Result:\n${results}\n`;
return {
type: 'match_search_files',
applyMsgId,
applyStatus: ApplyStatus.Applied,
returnMsg: {
role: 'user',
applyStatus: ApplyStatus.Idle,
content: null,
promptContent: formattedContent,
id: uuidv4(),
mentionables: [],
}
}
} else if (toolArgs.type === 'regex_search_files') {
// @ts-expect-error Obsidian API type mismatch
const baseVaultPath = String(app.vault.adapter.getBasePath())
const ripgrepPath = settings.ripgrepPath
const absolutePath = path.join(baseVaultPath, toolArgs.filepath)
const results = await regexSearchFiles(absolutePath, toolArgs.regex, ripgrepPath)
const searchBackend = settings.filesSearchSettings.regexBackend
let results: string;
if (searchBackend === 'coreplugin') {
results = await regexSearchUsingCorePlugin(toolArgs.regex, app)
} else {
// @ts-expect-error Obsidian API type mismatch
const baseVaultPath = String(app.vault.adapter.getBasePath())
const absolutePath = path.join(baseVaultPath, toolArgs.filepath)
const ripgrepPath = settings.filesSearchSettings.ripgrepPath
results = await regexSearchUsingRipgrep(absolutePath, toolArgs.regex, ripgrepPath)
}
const formattedContent = `[regex_search_files for '${toolArgs.filepath}'] Result:\n${results}\n`;
return {
type: 'regex_search_files',

View File

@@ -367,7 +367,7 @@ const CustomModeView = () => {
{t('prompt.overrideWarning')} <button
className="infio-preview-btn"
onClick={async () => {
let filesSearchMethod = settings.filesSearchMethod
let filesSearchMethod = settings.filesSearchSettings.method
if (filesSearchMethod === 'auto' && settings.embeddingModelId && settings.embeddingModelId !== '') {
filesSearchMethod = 'semantic'
}

View File

@@ -0,0 +1,52 @@
import { FileSearch } from 'lucide-react'
import React from 'react'
import { useApp } from "../../../contexts/AppContext"
import { t } from '../../../lang/helpers'
import { ApplyStatus, MatchSearchFilesToolArgs } from "../../../types/apply"
import { openMarkdownFile } from "../../../utils/obsidian"
export default function MarkdownMatchSearchFilesBlock({
applyStatus,
onApply,
path,
query,
finish
}: {
applyStatus: ApplyStatus
onApply: (args: MatchSearchFilesToolArgs) => void
path: string,
query: string,
finish: boolean
}) {
const app = useApp()
const handleClick = () => {
openMarkdownFile(app, path)
}
React.useEffect(() => {
if (finish && applyStatus === ApplyStatus.Idle) {
onApply({
type: 'match_search_files',
filepath: path,
query: query,
file_pattern: ".md",
})
}
}, [finish])
return (
<div
className={`infio-chat-code-block ${path ? 'has-filename' : ''}`}
onClick={handleClick}
>
<div className={'infio-chat-code-block-header'}>
<div className={'infio-chat-code-block-header-filename'}>
<FileSearch size={14} className="infio-chat-code-block-header-icon" />
<span>{t('chat.reactMarkdown.matchSearchInPath').replace('{query}', query).replace('{path}', path)}</span>
</div>
</div>
</div>
)
}

View File

@@ -13,6 +13,7 @@ import MarkdownFetchUrlsContentBlock from './Markdown/MarkdownFetchUrlsContentBl
import MarkdownListFilesBlock from './Markdown/MarkdownListFilesBlock'
import MarkdownReadFileBlock from './Markdown/MarkdownReadFileBlock'
import MarkdownReasoningBlock from './Markdown/MarkdownReasoningBlock'
import MarkdownMatchSearchFilesBlock from './Markdown/MarkdownMatchSearchFilesBlock'
import MarkdownRegexSearchFilesBlock from './Markdown/MarkdownRegexSearchFilesBlock'
import MarkdownSearchAndReplace from './Markdown/MarkdownSearchAndReplace'
import MarkdownSearchWebBlock from './Markdown/MarkdownSearchWebBlock'
@@ -117,6 +118,15 @@ function ReactMarkdown({
recursive={block.recursive}
finish={block.finish}
/>
) : block.type === 'match_search_files' ? (
<MarkdownMatchSearchFilesBlock
key={"match-search-files-" + index}
applyStatus={applyStatus}
onApply={onApply}
path={block.path}
query={block.query}
finish={block.finish}
/>
) : block.type === 'regex_search_files' ? (
<MarkdownRegexSearchFilesBlock
key={"regex-search-files-" + index}