update chat view, handl tool & new md component

This commit is contained in:
duanfuxiang
2025-03-12 21:38:31 +08:00
parent c0c81bd1d8
commit 23e7a5d5d7
6 changed files with 360 additions and 449 deletions

View File

@@ -1,67 +1,140 @@
import React, { useMemo } from 'react'
import Markdown from 'react-markdown'
import { ApplyStatus, ToolArgs } from '../../types/apply'
import {
InfioBlockAction,
ParsedInfioBlock,
parseinfioBlocks,
ParsedMsgBlock,
parseMsgBlocks,
} from '../../utils/parse-infio-block'
import MarkdownActionBlock from './MarkdownActionBlock'
import MarkdownReferenceBlock from './MarkdownReferenceBlock'
import MarkdownEditFileBlock from './MarkdownEditFileBlock'
import MarkdownListFilesBlock from './MarkdownListFilesBlock'
import MarkdownReadFileBlock from './MarkdownReadFileBlock'
import MarkdownReasoningBlock from './MarkdownReasoningBlock'
import MarkdownRegexSearchFilesBlock from './MarkdownRegexSearchFilesBlock'
import MarkdownSearchAndReplace from './MarkdownSearchAndReplace'
import MarkdownSemanticSearchFilesBlock from './MarkdownSemanticSearchFilesBlock'
import MarkdownWithIcons from './MarkdownWithIcon'
function ReactMarkdown({
applyStatus,
onApply,
isApplying,
children,
}: {
onApply: (blockInfo: {
content: string
filename?: string
startLine?: number
endLine?: number
}) => void
applyStatus: ApplyStatus
onApply: (toolArgs: ToolArgs) => void
children: string
isApplying: boolean
}) {
const blocks: ParsedInfioBlock[] = useMemo(
() => parseinfioBlocks(children),
const blocks: ParsedMsgBlock[] = useMemo(
() => parseMsgBlocks(children),
[children],
)
return (
<>
{blocks.map((block, index) =>
block.type === 'string' ? (
<Markdown key={index} className="infio-markdown">
block.type === 'thinking' ? (
<Markdown key={"markdown-" + index} className="infio-markdown">
{block.content}
</Markdown>
) : block.type === 'think' ? (
<MarkdownReasoningBlock
key={index}
reasoningContent={block.content}
<MarkdownReasoningBlock
key={"reasoning-" + index}
reasoningContent={block.content}
/>
) : block.startLine && block.endLine && block.filename && block.action === InfioBlockAction.Reference ? (
<MarkdownReferenceBlock
key={index}
filename={block.filename}
startLine={block.startLine}
endLine={block.endLine}
/>
) : (
<MarkdownActionBlock
key={index}
) : block.type === 'write_to_file' ? (
<MarkdownEditFileBlock
key={"write-to-file-" + index}
applyStatus={applyStatus}
mode={block.type}
onApply={onApply}
isApplying={isApplying}
language={block.language}
filename={block.filename}
startLine={block.startLine}
endLine={block.endLine}
action={block.action}
path={block.path}
startLine={1}
>
{block.content}
</MarkdownActionBlock>
</MarkdownEditFileBlock>
) : block.type === 'insert_content' ? (
<MarkdownEditFileBlock
key={"insert-content-" + index}
applyStatus={applyStatus}
mode={block.type}
onApply={onApply}
path={block.path}
startLine={block.startLine}
endLine={block.startLine} // 插入内容时endLine 和 startLine 相同
>
{block.content}
</MarkdownEditFileBlock>
) : block.type === 'search_and_replace' ? (
<MarkdownSearchAndReplace
key={"search-and-replace-" + index}
applyStatus={applyStatus}
onApply={onApply}
path={block.path}
operations={block.operations.map(op => ({
search: op.search,
replace: op.replace,
startLine: op.start_line,
endLine: op.end_line,
useRegex: op.use_regex,
ignoreCase: op.ignore_case,
regexFlags: op.regex_flags,
}))}
finish={block.finish}
/>
) : block.type === 'read_file' ? (
<MarkdownReadFileBlock
key={"read-file-" + index}
applyStatus={applyStatus}
onApply={onApply}
path={block.path}
finish={block.finish}
/>
) : block.type === 'list_files' ? (
<MarkdownListFilesBlock
key={"list-files-" + index}
applyStatus={applyStatus}
onApply={onApply}
path={block.path}
recursive={block.recursive}
finish={block.finish}
/>
) : block.type === 'regex_search_files' ? (
<MarkdownRegexSearchFilesBlock
key={"regex-search-files-" + index}
applyStatus={applyStatus}
onApply={onApply}
path={block.path}
regex={block.regex}
finish={block.finish}
/>
) : block.type === 'semantic_search_files' ? (
<MarkdownSemanticSearchFilesBlock
key={"semantic-search-files-" + index}
applyStatus={applyStatus}
onApply={onApply}
path={block.path}
query={block.query}
finish={block.finish}
/>
) : block.type === 'attempt_completion' ? (
<MarkdownWithIcons
key={"attempt-completion-" + index}
className="infio-markdown infio-attempt-completion"
markdownContent={
`<icon name='attempt_completion' size={14} className="infio-markdown-icon" />
${block.result && block.result.trimStart()}`} />
) : block.type === 'ask_followup_question' ? (
<MarkdownWithIcons
key={"ask-followup-question-" + index}
className="infio-markdown infio-followup-question"
markdownContent={
`<icon name='ask_followup_question' size={14} className="infio-markdown-icon" />
${block.question && block.question.trimStart()}`} />
) : (
<Markdown key={"markdown-" + index} className="infio-markdown">
{block.content}
</Markdown>
),
)}
</>