fix: 草稿首次落库前先改绑发布助手会话,避免路由重挂新建空会话

This commit is contained in:
2026-10-20 15:57:49 +08:00
parent 9bbb01fdee
commit e667871c58
6 changed files with 263 additions and 8 deletions
+37
View File
@@ -91,6 +91,43 @@ class SessionService:
session.title = title.strip() or session.title
return await self._sessions.update(session)
async def rebind_scene_ref(
self,
actor: Actor,
thread_id: str,
*,
scene_ref: str,
title: str | None = None,
) -> Session:
"""把未落库会话(scene_ref=local-*)改绑到稳定业务键(如系统草稿 ID)。"""
new_ref = (scene_ref or "").strip()
if not new_ref:
raise ValueError("scene_ref 不能为空")
if new_ref.startswith("local-"):
raise ValueError("不能改绑到临时 local 键")
session = await self.require_owned(actor, thread_id)
if session.scene_ref == new_ref:
if title is not None:
session.title = title.strip() or session.title
return await self._sessions.update(session)
return session
current = (session.scene_ref or "").strip()
if current and not current.startswith("local-"):
raise ValueError("仅未落库会话可改绑 scene_ref")
existing = await self.find_by_scene_ref(
actor, scene=session.scene or "general", scene_ref=new_ref
)
if existing is not None and existing.thread_id != thread_id:
raise ValueError("该业务对象已有关联会话")
session.scene_ref = new_ref
if title is not None:
session.title = title.strip() or session.title
return await self._sessions.update(session)
async def update_llm_selection(
self,
actor: Actor,