mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 01:21:43 +00:00
refactor: unify gateway session title sync flow
This commit is contained in:
parent
59d45346ba
commit
3438de3623
8 changed files with 421 additions and 61 deletions
|
|
@ -641,6 +641,31 @@ class SessionDB:
|
|||
rowcount = self._execute_write(_do)
|
||||
return rowcount > 0
|
||||
|
||||
def set_session_title_if_missing(self, session_id: str, title: str) -> bool:
|
||||
"""Atomically set a session title only when the current title is NULL."""
|
||||
title = self.sanitize_title(title)
|
||||
if not title:
|
||||
return False
|
||||
|
||||
def _do(conn):
|
||||
cursor = conn.execute(
|
||||
"SELECT id FROM sessions WHERE title = ? AND id != ?",
|
||||
(title, session_id),
|
||||
)
|
||||
conflict = cursor.fetchone()
|
||||
if conflict:
|
||||
raise ValueError(
|
||||
f"Title '{title}' is already in use by session {conflict['id']}"
|
||||
)
|
||||
cursor = conn.execute(
|
||||
"UPDATE sessions SET title = ? WHERE id = ? AND title IS NULL",
|
||||
(title, session_id),
|
||||
)
|
||||
return cursor.rowcount
|
||||
|
||||
rowcount = self._execute_write(_do)
|
||||
return rowcount > 0
|
||||
|
||||
def get_session_title(self, session_id: str) -> Optional[str]:
|
||||
"""Get the title for a session, or None."""
|
||||
with self._lock:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue