feat(M4.2): 前端会话侧边栏——学科窗口列表/默认流兜底/新建(选学科+继承源)/切换加载历史/判题落库带会话;后端 history 按会话过滤
这个提交包含在:
@@ -152,12 +152,13 @@ async def chat(body: ChatBody, authorization: str | None = Header(None), session
|
||||
|
||||
|
||||
@router.get("/history")
|
||||
async def history(limit: int = 200, authorization: str | None = Header(None), session: Session = Depends(get_session)):
|
||||
"""当前用户的完整对话流(含 user/assistant/judge/explain/sys),升序返回。"""
|
||||
async def history(limit: int = 200, conversation_id: int = 0,
|
||||
authorization: str | None = Header(None), session: Session = Depends(get_session)):
|
||||
"""当前用户某会话的完整对话流(默认流 conversation_id=0),升序返回。"""
|
||||
user = _current_user(_bearer(authorization), session)
|
||||
if not user:
|
||||
raise HTTPException(401, "未登录")
|
||||
msgs = MessageRepo(session).list_by_user(user["id"], limit=min(limit, 500))
|
||||
msgs = MessageRepo(session).list_by_user(user["id"], limit=min(limit, 500), conversation_id=conversation_id)
|
||||
return {"messages": [m.to_dict() for m in msgs]}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ class SubmitBody(BaseModel):
|
||||
pretest: bool = False
|
||||
input: str | None = None # pretest 时的自测输入
|
||||
uid: str = "guest"
|
||||
conversation_id: int = 0 # 会话(学科窗口)
|
||||
|
||||
|
||||
def _current(authorization: str | None, session: Session) -> tuple[str, int | None, dict | None]:
|
||||
@@ -51,6 +52,7 @@ async def submit(body: SubmitBody, authorization: str | None = Header(None), ses
|
||||
user_id, "judge", body.code, kind="judge",
|
||||
meta={"rid": result["rid"], "pid": body.pid, "lang": body.lang,
|
||||
"verdict": result.get("verdict", "PENDING"), "score": 0},
|
||||
conversation_id=body.conversation_id if user_id else 0,
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户