feat: 增强会话历史风险与绑定状态展示
This commit is contained in:
@@ -26,6 +26,7 @@ def index(request):
|
||||
{
|
||||
"conversation": None,
|
||||
"conversations": [],
|
||||
"conversation_history": [],
|
||||
"form": ChatForm(),
|
||||
"documents": [],
|
||||
"result": None,
|
||||
@@ -91,6 +92,7 @@ def detail(request, conversation_id: str):
|
||||
export_card = _build_export_card(result, conversation)
|
||||
risk_card = _build_risk_card(result, conversation)
|
||||
notify_card = _build_notify_card(result, conversation)
|
||||
conversation_history = _build_conversation_history(Conversation.objects.all())
|
||||
|
||||
return render(
|
||||
request,
|
||||
@@ -98,6 +100,7 @@ def detail(request, conversation_id: str):
|
||||
{
|
||||
"conversation": conversation,
|
||||
"conversations": Conversation.objects.all(),
|
||||
"conversation_history": conversation_history,
|
||||
"batch": batch,
|
||||
"form": form,
|
||||
"documents": documents,
|
||||
@@ -276,6 +279,30 @@ def _build_prompt_templates() -> list[str]:
|
||||
]
|
||||
|
||||
|
||||
def _build_conversation_history(conversations) -> list[dict]:
|
||||
"""
|
||||
组装左栏会话历史摘要。
|
||||
|
||||
左栏只展示稳定摘要字段,不在模板里拼风险判断逻辑。
|
||||
"""
|
||||
history = []
|
||||
for item in conversations:
|
||||
node_status_map = {node.get("label"): node.get("status", "") for node in item.node_results}
|
||||
risk_status = node_status_map.get("风险预警", "待处理")
|
||||
history.append(
|
||||
{
|
||||
"conversation_id": item.conversation_id,
|
||||
"title": item.title,
|
||||
"product_name": item.product_name,
|
||||
"batch_id": item.batch_id,
|
||||
"risk_level": "高" if risk_status in {"已阻断", "待复核"} else "中",
|
||||
"updated_at": item.updated_at,
|
||||
"batch_binding_label": "已绑定资料包" if item.batch_id else "未绑定资料包",
|
||||
}
|
||||
)
|
||||
return history
|
||||
|
||||
|
||||
def _build_analysis_card(result: AgentResult | None, conversation: Conversation) -> dict:
|
||||
structured_output = {}
|
||||
if result and result.structured_output:
|
||||
|
||||
@@ -49,11 +49,16 @@
|
||||
<h2 class="section-title">会话历史</h2>
|
||||
<p class="section-copy">左侧保留历史会话,标题默认使用解析后的产品名称。</p>
|
||||
<ul class="detail-list">
|
||||
{% for item in conversations %}
|
||||
{% for item in conversation_history %}
|
||||
<li class="detail-item">
|
||||
<strong><a href="{% url 'chat:detail' item.conversation_id %}">{{ item.title }}</a></strong>
|
||||
<div class="muted">产品:{{ item.product_name|default:"未识别" }}</div>
|
||||
<div class="muted">批次:{{ item.batch_id }}</div>
|
||||
<div class="muted">风险:{{ item.risk_level }}</div>
|
||||
<div class="muted">最近更新:{{ item.updated_at|date:"Y-m-d H:i" }}</div>
|
||||
<div class="badge-row" style="margin-top: 8px;">
|
||||
<span class="pill pill-accent">{{ item.batch_binding_label }}</span>
|
||||
</div>
|
||||
</li>
|
||||
{% empty %}
|
||||
<li class="detail-item">暂无会话,请先从资料包页面导入资料。</li>
|
||||
|
||||
@@ -134,6 +134,29 @@ def test_chat_renders_three_column_workspace_and_node_results(client, db):
|
||||
assert "目录汇总 / 处理中" in content
|
||||
|
||||
|
||||
def test_chat_history_sidebar_shows_risk_status_update_time_and_batch_binding(client, db):
|
||||
batch, conversation = _create_conversation_with_batch()
|
||||
conversation.node_results = [
|
||||
{"label": "资料包导入", "status": "已完成"},
|
||||
{"label": "目录汇总", "status": "已完成"},
|
||||
{"label": "法规完整性检查", "status": "已完成"},
|
||||
{"label": "字段抽取", "status": "已完成"},
|
||||
{"label": "一致性核查", "status": "待复核"},
|
||||
{"label": "风险预警", "status": "已阻断"},
|
||||
{"label": "Word 回填导出", "status": "待复核"},
|
||||
{"label": "飞书通知", "status": "待处理"},
|
||||
]
|
||||
conversation.save(update_fields=["node_results", "updated_at"])
|
||||
|
||||
response = client.get(reverse("chat:detail", args=[conversation.conversation_id]))
|
||||
|
||||
content = response.content.decode("utf-8")
|
||||
assert response.status_code == 200
|
||||
assert "风险:高" in content
|
||||
assert "最近更新:" in content
|
||||
assert "已绑定资料包" in content
|
||||
|
||||
|
||||
def test_chat_execution_creates_notification_record_from_agent_result(client, db, monkeypatch):
|
||||
batch, conversation = _create_conversation_with_batch()
|
||||
UploadedDocument.objects.create(
|
||||
|
||||
Reference in New Issue
Block a user