From 47ca11693789e4f064077387e6b7642cfaff1dcb Mon Sep 17 00:00:00 2001 From: bruce Date: Thu, 4 Jun 2026 04:11:00 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E7=BB=9F=E4=B8=80=E9=A3=9E=E4=B9=A6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E8=8A=82=E7=82=B9=E7=8A=B6=E6=80=81=E8=AF=AD?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent_core/orchestrator.py | 2 +- apps/audit/services.py | 22 ++++++++++++++++++++++ apps/audit/views.py | 10 +++++++++- apps/chat/views.py | 31 +++++++++++++++++++++++++++---- templates/audit/log_detail.html | 4 ++-- tests/test_agent_core.py | 2 +- tests/test_audit.py | 1 + tests/test_chat.py | 1 + 8 files changed, 64 insertions(+), 9 deletions(-) diff --git a/agent_core/orchestrator.py b/agent_core/orchestrator.py index 67137f4..13d8607 100644 --- a/agent_core/orchestrator.py +++ b/agent_core/orchestrator.py @@ -259,7 +259,7 @@ def _build_registration_node_results(output_type: str, structured_output: dict) if message_status in {"failed", "error"}: nodes[7]["status"] = "失败" elif message_status in {"sent", "success"}: - nodes[7]["status"] = "已完成" + nodes[7]["status"] = "已发送" else: nodes[7]["status"] = "待处理" return nodes diff --git a/apps/audit/services.py b/apps/audit/services.py index 3e395af..127be16 100644 --- a/apps/audit/services.py +++ b/apps/audit/services.py @@ -241,6 +241,28 @@ def build_detail_summary(log: AgentAuditLog, conversation, notifications) -> dic } +def normalize_conversation_node_results(node_results: list[dict] | None) -> list[dict]: + """ + 统一处理历史详情页的节点状态展示口径。 + + 兼容历史上遗留的“飞书通知 / 已完成”节点状态, + 页面展示时统一映射为“已发送”。 + """ + normalized = [] + for node in node_results or []: + item = dict(node) + if item.get("label") == "飞书通知": + status = item.get("status", "") + if status in {"已完成", "success", "sent"}: + item["status"] = "已发送" + elif status in {"failed", "error"}: + item["status"] = "失败" + elif status in {"pending", "processing"}: + item["status"] = "待处理" + normalized.append(item) + return normalized + + def _get_risk_status_display_text(status: str) -> str: return RISK_STATUS_DISPLAY.get(status, status or "-") diff --git a/apps/audit/views.py b/apps/audit/views.py index 7fe2b9e..faa3c66 100644 --- a/apps/audit/views.py +++ b/apps/audit/views.py @@ -2,7 +2,12 @@ from django.shortcuts import get_object_or_404, render from .models import AgentAuditLog, NotificationRecord from apps.chat.models import Conversation -from .services import build_detail_summary, build_history_metrics, build_history_rows +from .services import ( + build_detail_summary, + build_history_metrics, + build_history_rows, + normalize_conversation_node_results, +) def log_list(request): @@ -67,6 +72,9 @@ def log_detail(request, log_id: int): "log": audit_log, "notifications": notifications, "conversation": conversation, + "conversation_node_results": normalize_conversation_node_results( + conversation.node_results if conversation else [] + ), "detail_summary": detail_summary, }, ) diff --git a/apps/chat/views.py b/apps/chat/views.py index 91d707e..f08c60f 100644 --- a/apps/chat/views.py +++ b/apps/chat/views.py @@ -117,7 +117,8 @@ def detail(request, conversation_id: str): ) active_node = "risk" conversation.refresh_from_db() - workspace_summary = _build_workspace_summary(conversation, batch) + display_node_results = _normalize_node_results(conversation.node_results) + workspace_summary = _build_workspace_summary(conversation, batch, display_node_results) conversation_context = _build_conversation_context(conversation, batch, workspace_summary) prompt_templates = _build_prompt_templates() analysis_card = _build_analysis_card(result, conversation) @@ -140,7 +141,7 @@ def detail(request, conversation_id: str): "result": result, "audit_log": audit_log, "task_modes": task_modes, - "node_results": conversation.node_results, + "node_results": display_node_results, "active_node": active_node, "workspace_summary": workspace_summary, "conversation_context": conversation_context, @@ -258,8 +259,13 @@ def _persist_notification_records(result: AgentResult, *, web_detail_url: str = ) -def _build_workspace_summary(conversation: Conversation, batch: SubmissionBatch | None) -> dict: - node_status_map = {node.get("label"): node.get("status", "") for node in conversation.node_results} +def _build_workspace_summary( + conversation: Conversation, + batch: SubmissionBatch | None, + display_node_results: list[dict] | None = None, +) -> dict: + normalized_nodes = display_node_results or _normalize_node_results(conversation.node_results) + node_status_map = {node.get("label"): node.get("status", "") for node in normalized_nodes} risk_status = node_status_map.get("风险预警", "待处理") notify_status = node_status_map.get("飞书通知", "待处理") export_status = node_status_map.get("Word 回填导出", "待处理") @@ -458,6 +464,23 @@ def _build_notify_card(result: AgentResult | None, conversation: Conversation) - } +def _normalize_node_results(node_results: list[dict]) -> list[dict]: + normalized = [] + for node in node_results or []: + item = dict(node) + label = item.get("label", "") + status = item.get("status", "") + if label == "飞书通知": + if status in {"已完成", "success", "sent"}: + item["status"] = "已发送" + elif status in {"failed", "error"}: + item["status"] = "失败" + elif status in {"pending", "processing"}: + item["status"] = "待处理" + normalized.append(item) + return normalized + + def _get_risk_level_display_text(level: str) -> str: return RISK_LEVEL_DISPLAY.get(level, level) diff --git a/templates/audit/log_detail.html b/templates/audit/log_detail.html index 4b41e1a..d9553da 100644 --- a/templates/audit/log_detail.html +++ b/templates/audit/log_detail.html @@ -37,8 +37,8 @@

会话节点结果