feat: Allow specifying a custom time for progress logs and add type assertion for new findings.
Build and Push CodeReview / build (push) Waiting to run Details

This commit is contained in:
vinland100 2026-01-30 13:31:41 +08:00
parent 62c42341c4
commit 310750c366
2 changed files with 7 additions and 4 deletions

View File

@ -49,7 +49,7 @@ function agentAuditReducer(state: AgentAuditState, action: AgentAuditAction): Ag
if (newFinding.id && existingIds.has(newFinding.id)) { if (newFinding.id && existingIds.has(newFinding.id)) {
return state; // 已存在,不添加 return state; // 已存在,不添加
} }
return { ...state, findings: [...state.findings, newFinding] }; return { ...state, findings: [...state.findings, newFinding as AgentFinding] };
} }
case 'SET_AGENT_TREE': case 'SET_AGENT_TREE':
@ -99,19 +99,21 @@ function agentAuditReducer(state: AgentAuditState, action: AgentAuditAction): Ag
} }
case 'UPDATE_OR_ADD_PROGRESS_LOG': { case 'UPDATE_OR_ADD_PROGRESS_LOG': {
const { progressKey, title, agentName } = action.payload; const { progressKey, title, agentName, time } = action.payload;
// 查找是否已存在相同 progressKey 的进度日志 // 查找是否已存在相同 progressKey 的进度日志
const existingIndex = state.logs.findIndex( const existingIndex = state.logs.findIndex(
log => log.type === 'progress' && log.progressKey === progressKey log => log.type === 'progress' && log.progressKey === progressKey
); );
const logTime = time || new Date().toLocaleTimeString('en-US', { hour12: false });
if (existingIndex >= 0) { if (existingIndex >= 0) {
// 更新现有日志的 title 和 time // 更新现有日志的 title 和 time
const updatedLogs = [...state.logs]; const updatedLogs = [...state.logs];
updatedLogs[existingIndex] = { updatedLogs[existingIndex] = {
...updatedLogs[existingIndex], ...updatedLogs[existingIndex],
title, title,
time: new Date().toLocaleTimeString('en-US', { hour12: false }), time: logTime,
}; };
return { ...state, logs: updatedLogs }; return { ...state, logs: updatedLogs };
} else { } else {
@ -121,6 +123,7 @@ function agentAuditReducer(state: AgentAuditState, action: AgentAuditAction): Ag
title, title,
progressKey, progressKey,
agentName, agentName,
time: logTime,
}); });
return { ...state, logs: [...state.logs, newLog] }; return { ...state, logs: [...state.logs, newLog] };
} }

View File

@ -78,7 +78,7 @@ export type AgentAuditAction =
| { type: 'SET_LOGS'; payload: LogItem[] } | { type: 'SET_LOGS'; payload: LogItem[] }
| { type: 'ADD_LOG'; payload: Omit<LogItem, 'id' | 'time'> & { id?: string; time?: string } } | { type: 'ADD_LOG'; payload: Omit<LogItem, 'id' | 'time'> & { id?: string; time?: string } }
| { type: 'UPDATE_LOG'; payload: { id: string; updates: Partial<LogItem> } } | { type: 'UPDATE_LOG'; payload: { id: string; updates: Partial<LogItem> } }
| { 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: 'COMPLETE_TOOL_LOG'; payload: { toolName: string; output: string; duration: number } }
| { type: 'REMOVE_LOG'; payload: string } | { type: 'REMOVE_LOG'; payload: string }
| { type: 'SELECT_AGENT'; payload: string | null } | { type: 'SELECT_AGENT'; payload: string | null }