fix(chat): 前端审计修复——预览契约改HTML/状态机统一/进度错误持久化/chat_state.js抽取
- app.py: /result/preview 返回渲染 HTML(HTMLResponse) 而非 {html} JSON;新增 /chat_state.js 静态路由;预览缺失返回 404(RESULT_NOT_FOUND)
- chat.html: currentProject 统一为 draftProject;新会话继承已选项目(§4.2);上传区显隐/类型映射/抽屉脏检测改用 GenesisState;loadSession 按 role 渲染 progress/error;加 h1 标题
- chat_state.js(新): 抽取 autoBindProject/shouldHideUploadSelect/resolveUploadType/computeDrawerSnapshot/isDrawerDirty/buildWelcome 纯函数(U+1 分隔符)
- agent.py: 新增 _persist_progress/_store_error,进度与错误以 role 入库(重载可见)
- 测试: test_chat_state.js(11 passed) + test_frontend_audit_fixes.py(5) + 修正 test_server_api 旧 JSON 契约断言;全量 pytest 568 passed / 99.06%
This commit is contained in:
@@ -110,6 +110,13 @@ def create_app(
|
||||
def index():
|
||||
return chat_html
|
||||
|
||||
@app.get("/chat_state.js")
|
||||
def chat_state_js():
|
||||
p = static_dir / "chat_state.js"
|
||||
if not p.exists():
|
||||
raise _error(404, "NOT_FOUND", "chat_state.js 不存在")
|
||||
return FileResponse(p, media_type="application/javascript")
|
||||
|
||||
# ---------- 项目配置 ----------
|
||||
|
||||
@app.post("/api/projects")
|
||||
@@ -266,10 +273,13 @@ def create_app(
|
||||
|
||||
# ---------- 结果 ----------
|
||||
|
||||
@app.get("/api/sessions/{sid}/result/preview")
|
||||
@app.get("/api/sessions/{sid}/result/preview", response_class=HTMLResponse)
|
||||
def result_preview(sid: str):
|
||||
html = service.result_preview(sid)
|
||||
return {"html": html}
|
||||
try:
|
||||
html = service.result_preview(sid)
|
||||
except ServiceStepError:
|
||||
raise _error(404, "RESULT_NOT_FOUND", "结果文档不存在")
|
||||
return HTMLResponse(html)
|
||||
|
||||
@app.get("/api/sessions/{sid}/result/download")
|
||||
def result_download(sid: str):
|
||||
|
||||
Reference in New Issue
Block a user