From f8d5f0253aac051b2200935c859c6bd6d7ec9876 Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Tue, 7 Jul 2026 17:53:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B8=85=E7=90=86=20P1=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=80=BA=E4=B8=8E=20React=20key=20=E5=80=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 消除 useChat.ts 中 13 处 (message as any).timestamp,改用已收窄变量的 .timestamp - 给 ExecutionCancelled 接口补 timestamp?: number 字段,与后端对齐 - 修复 MessageInput 附件列表 key={index}: 给 FileAttachment 加 id 字段(crypto.randomUUID()) - 修复 ConfigPage TagEditor key={i} → key={t}(tag 值唯一) - 修复 ConfigPage SourceEditor customPaths key={i} → key={p}(路径值唯一) --- web/src/components/Chat/MessageInput.tsx | 5 ++++- web/src/components/Settings/ConfigPage.tsx | 6 ++--- web/src/hooks/useChat.ts | 26 +++++++++++----------- web/src/types/protocol.ts | 1 + 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/web/src/components/Chat/MessageInput.tsx b/web/src/components/Chat/MessageInput.tsx index e572ee4..aaf9f6c 100644 --- a/web/src/components/Chat/MessageInput.tsx +++ b/web/src/components/Chat/MessageInput.tsx @@ -16,6 +16,7 @@ interface MessageInputProps { } interface FileAttachment { + id: string file: File attachment: Attachment preview?: string // 用于图片预览 @@ -92,6 +93,7 @@ export function MessageInput({ } const fileAttachment: FileAttachment = { + id: crypto.randomUUID(), file, attachment, preview: mediaType === 'image' ? base64 : undefined, @@ -170,6 +172,7 @@ export function MessageInput({ } const fileAttachment: FileAttachment = { + id: crypto.randomUUID(), file, attachment, preview: mediaType === 'image' ? base64 : undefined, @@ -295,7 +298,7 @@ export function MessageInput({
{attachments.map((att, index) => (
{att.preview ? ( diff --git a/web/src/components/Settings/ConfigPage.tsx b/web/src/components/Settings/ConfigPage.tsx index 4335b1a..e69f703 100644 --- a/web/src/components/Settings/ConfigPage.tsx +++ b/web/src/components/Settings/ConfigPage.tsx @@ -192,7 +192,7 @@ function TagEditor({ tags, onChange }: { tags: string[]; onChange: (t: string[])
{tags.map((t, i) => ( - + {t} @@ -286,8 +286,8 @@ function SourceEditor({
自定义路径
{customPaths.length > 0 && (
- {customPaths.map((p, i) => ( - + {customPaths.map((p) => ( + {p} diff --git a/web/src/hooks/useChat.ts b/web/src/hooks/useChat.ts index 4cb6522..5eb7ff8 100644 --- a/web/src/hooks/useChat.ts +++ b/web/src/hooks/useChat.ts @@ -236,7 +236,7 @@ export function useChat(): UseChatReturn { id: msg.id, role: role as ChatMessage['role'], content: msg.content, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: msg.timestamp ?? Math.floor(Date.now() / 1000), type: 'message', attachments: msg.attachments, subagentTaskId: msg.subagent_task_id, @@ -249,7 +249,7 @@ export function useChat(): UseChatReturn { id: msg.id, role: 'tool', content: msg.content, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: msg.timestamp ?? Math.floor(Date.now() / 1000), type: 'tool_call', toolName: msg.tool_name, toolCallId: msg.tool_call_id, @@ -264,7 +264,7 @@ export function useChat(): UseChatReturn { id: msg.id, role: 'tool', content: msg.content, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: msg.timestamp ?? Math.floor(Date.now() / 1000), type: 'tool_result', toolName: msg.tool_name, toolCallId: msg.tool_call_id, @@ -278,7 +278,7 @@ export function useChat(): UseChatReturn { id: msg.id, role: 'tool', content: `${msg.content}\n\n${msg.resume_hint}`, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: msg.timestamp ?? Math.floor(Date.now() / 1000), type: 'tool_pending', toolName: msg.tool_name, toolCallId: msg.tool_call_id, @@ -302,7 +302,7 @@ export function useChat(): UseChatReturn { id: generateMessageId(), role: 'assistant', content: `Error: ${message.message}`, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: message.timestamp ?? Math.floor(Date.now() / 1000), type: 'message', } } @@ -362,7 +362,7 @@ export function useChat(): UseChatReturn { id: generateMessageId(), role: 'assistant', content: `Error: ${errMsg.message}`, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: errMsg.timestamp ?? Math.floor(Date.now() / 1000), type: 'message', } setSubAgentStack((prev) => { @@ -423,7 +423,7 @@ export function useChat(): UseChatReturn { id: generateMessageId(), role: 'assistant', content: `Error: ${errMsg.message}`, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: errMsg.timestamp ?? Math.floor(Date.now() / 1000), type: 'message', } const newStack = [...prev] @@ -800,7 +800,7 @@ export function useChat(): UseChatReturn { id: msg.id, role, content: msg.content, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: msg.timestamp ?? Math.floor(Date.now() / 1000), type: 'message', attachments: msg.attachments, reasoningContent: msg.reasoning_content, @@ -833,7 +833,7 @@ export function useChat(): UseChatReturn { id: msg.id, role: 'tool', content: msg.content, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: msg.timestamp ?? Math.floor(Date.now() / 1000), type: 'tool_call', toolName: msg.tool_name, toolCallId: msg.tool_call_id, @@ -856,7 +856,7 @@ export function useChat(): UseChatReturn { id: msg.id, role: 'tool', content: msg.content, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: msg.timestamp ?? Math.floor(Date.now() / 1000), type: 'tool_result', toolName: msg.tool_name, toolCallId: msg.tool_call_id, @@ -877,7 +877,7 @@ export function useChat(): UseChatReturn { id: msg.id, role: 'tool', content: `${msg.content}\n\n${msg.resume_hint}`, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: msg.timestamp ?? Math.floor(Date.now() / 1000), type: 'tool_pending', toolName: msg.tool_name, toolCallId: msg.tool_call_id, @@ -893,7 +893,7 @@ export function useChat(): UseChatReturn { id: generateMessageId(), role: 'assistant', content: (message as { type: 'execution_cancelled'; message: string }).message, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: message.timestamp ?? Math.floor(Date.now() / 1000), type: 'message', }, ]) @@ -910,7 +910,7 @@ export function useChat(): UseChatReturn { id: generateMessageId(), role: 'assistant', content: `Error: ${message.message}`, - timestamp: (message as any).timestamp ?? Math.floor(Date.now() / 1000), + timestamp: message.timestamp ?? Math.floor(Date.now() / 1000), type: 'message', }, ]) diff --git a/web/src/types/protocol.ts b/web/src/types/protocol.ts index 1822ea5..a21a7a7 100644 --- a/web/src/types/protocol.ts +++ b/web/src/types/protocol.ts @@ -260,6 +260,7 @@ export interface TaskMessagesLoaded { export interface ExecutionCancelled { type: 'execution_cancelled' message: string + timestamp?: number } export interface StreamDelta {