From 310750c366412181b84ef03d25ffe9b953e7d10a Mon Sep 17 00:00:00 2001 From: vinland100 Date: Fri, 30 Jan 2026 13:31:41 +0800 Subject: [PATCH] feat: Allow specifying a custom time for progress logs and add type assertion for new findings. --- .../src/pages/AgentAudit/hooks/useAgentAuditState.ts | 9 ++++++--- frontend/src/pages/AgentAudit/types.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/AgentAudit/hooks/useAgentAuditState.ts b/frontend/src/pages/AgentAudit/hooks/useAgentAuditState.ts index 30f7cf0..016bd98 100644 --- a/frontend/src/pages/AgentAudit/hooks/useAgentAuditState.ts +++ b/frontend/src/pages/AgentAudit/hooks/useAgentAuditState.ts @@ -49,7 +49,7 @@ function agentAuditReducer(state: AgentAuditState, action: AgentAuditAction): Ag if (newFinding.id && existingIds.has(newFinding.id)) { return state; // 已存在,不添加 } - return { ...state, findings: [...state.findings, newFinding] }; + return { ...state, findings: [...state.findings, newFinding as AgentFinding] }; } case 'SET_AGENT_TREE': @@ -99,19 +99,21 @@ function agentAuditReducer(state: AgentAuditState, action: AgentAuditAction): Ag } case 'UPDATE_OR_ADD_PROGRESS_LOG': { - const { progressKey, title, agentName } = action.payload; + const { progressKey, title, agentName, time } = action.payload; // 查找是否已存在相同 progressKey 的进度日志 const existingIndex = state.logs.findIndex( log => log.type === 'progress' && log.progressKey === progressKey ); + const logTime = time || new Date().toLocaleTimeString('en-US', { hour12: false }); + if (existingIndex >= 0) { // 更新现有日志的 title 和 time const updatedLogs = [...state.logs]; updatedLogs[existingIndex] = { ...updatedLogs[existingIndex], title, - time: new Date().toLocaleTimeString('en-US', { hour12: false }), + time: logTime, }; return { ...state, logs: updatedLogs }; } else { @@ -121,6 +123,7 @@ function agentAuditReducer(state: AgentAuditState, action: AgentAuditAction): Ag title, progressKey, agentName, + time: logTime, }); return { ...state, logs: [...state.logs, newLog] }; } diff --git a/frontend/src/pages/AgentAudit/types.ts b/frontend/src/pages/AgentAudit/types.ts index 1ab9ae4..31550a8 100644 --- a/frontend/src/pages/AgentAudit/types.ts +++ b/frontend/src/pages/AgentAudit/types.ts @@ -78,7 +78,7 @@ export type AgentAuditAction = | { type: 'SET_LOGS'; payload: LogItem[] } | { type: 'ADD_LOG'; payload: Omit & { id?: string; time?: string } } | { type: 'UPDATE_LOG'; payload: { id: string; updates: Partial } } - | { type: 'UPDATE_OR_ADD_PROGRESS_LOG'; payload: { progressKey: string; title: string; agentName?: string } } + | { type: 'UPDATE_OR_ADD_PROGRESS_LOG'; payload: { progressKey: string; title: string; agentName?: string; time?: string } } | { type: 'COMPLETE_TOOL_LOG'; payload: { toolName: string; output: string; duration: number } } | { type: 'REMOVE_LOG'; payload: string } | { type: 'SELECT_AGENT'; payload: string | null }