feat(frontend): 优化对话与管理页面展示体验

This commit is contained in:
2026-05-30 00:26:18 +08:00
parent df45a89eb1
commit 905067277a
10 changed files with 776 additions and 218 deletions

View File

@@ -2,6 +2,8 @@ from django import forms
class ChatForm(forms.Form):
# 该表单只负责收集用户问题和可选文档范围,
# 不承载任何 Agent 业务逻辑,便于在 View 层保持轻量。
message = forms.CharField(
label="问题",
max_length=4000,
@@ -9,7 +11,12 @@ class ChatForm(forms.Form):
"required": "请输入要咨询的问题。",
"max_length": "问题过长,请控制在 4000 字以内。",
},
widget=forms.Textarea(attrs={"rows": 6}),
widget=forms.Textarea(
attrs={
"rows": 8,
"placeholder": "例如:请结合已上传 SOP分析当前异常的原因、风险等级和建议动作。",
}
),
)
document_ids = forms.MultipleChoiceField(
label="文档范围",
@@ -22,9 +29,12 @@ class ChatForm(forms.Form):
def __init__(self, *args, documents=None, **kwargs):
super().__init__(*args, **kwargs)
documents = documents or []
# 仅允许选择当前场景且已完成入库的文档,
# 避免前端把无效文件范围传入 Agent Core。
self.fields["document_ids"].choices = [
(str(document.id), document.original_name) for document in documents
]
def clean_document_ids(self):
# View 与 Agent Core 都使用整型文档 ID统一在表单层完成转换。
return [int(document_id) for document_id in self.cleaned_data.get("document_ids", [])]

View File

@@ -10,6 +10,8 @@ from .forms import ChatForm
def index(request, scenario_id: str):
# View 只负责请求编排、表单校验和模板渲染。
# 具体 Agent 执行、审计写入和文档筛选规则分别交给独立模块处理。
try:
scenario = get_scenario(scenario_id)
except ScenarioNotFound:
@@ -34,6 +36,7 @@ def index(request, scenario_id: str):
if request.method == "POST" and form.is_valid():
message = form.cleaned_data["message"]
try:
# 只把必要的运行选项传给 Agent Core避免在 View 中散落模型细节。
result = run_agent(
scenario,
message,
@@ -50,6 +53,7 @@ def index(request, scenario_id: str):
"scenario": scenario,
"form": form,
"documents": documents,
"document_count": documents.count(),
"result": result,
"audit_log": audit_log,
},