-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathEditTool.tsx
More file actions
60 lines (56 loc) · 1.77 KB
/
EditTool.tsx
File metadata and controls
60 lines (56 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { CollapseProps } from 'antd'
import { ClickableFilePath } from './ClickableFilePath'
import { ToolHeader } from './GenericTools'
import type { EditToolInput, EditToolOutput } from './types'
import { AgentToolsType } from './types'
// 处理多行文本显示
export const renderCodeBlock = (content: string, variant: 'old' | 'new') => {
const lines = content.split('\n')
const textColorClass =
variant === 'old' ? 'text-danger-600 dark:text-danger-400' : 'text-success-600 dark:text-success-400'
return (
// 删除线
<pre className={`whitespace-pre-wrap font-mono text-xs ${textColorClass}`}>
{lines.map((line, idx) => (
<div key={idx} className="flex hover:bg-default-100/50 dark:hover:bg-default-900/50">
<span className="mr-3 min-w-[2rem] select-none text-right opacity-50">
{variant === 'old' && '-'}
{variant === 'new' && '+'}
{idx + 1}
</span>
<span className={`flex-1 ${variant === 'old' && 'line-through'}`}>{line || ' '}</span>
</div>
))}
</pre>
)
}
export function EditTool({
input,
output
}: {
input?: EditToolInput
output?: EditToolOutput
}): NonNullable<CollapseProps['items']>[number] {
return {
key: AgentToolsType.Edit,
label: (
<ToolHeader
toolName={AgentToolsType.Edit}
params={input?.file_path ? <ClickableFilePath path={input.file_path} /> : undefined}
variant="collapse-label"
showStatus={false}
/>
),
children: (
<>
{/* Diff View */}
{/* Old Content */}
{renderCodeBlock(input?.old_string ?? '', 'old')}
{/* New Content */}
{renderCodeBlock(input?.new_string ?? '', 'new')}
{/* Output */}
{output}
</>
)
}
}