fix(acp): refresh session info after auto-title

This commit is contained in:
HenkDz
2026-05-15 20:32:57 +01:00
committed by Teknium
parent eda1c97a1e
commit 741a349458
2 changed files with 81 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ from acp.schema import (
ResourceContentBlock,
SessionCapabilities,
SessionForkCapabilities,
SessionInfoUpdate,
SessionListCapabilities,
SessionMode,
SessionModeState,
@@ -707,6 +708,35 @@ class HermesACPAgent(acp.Agent):
exc_info=True,
)
async def _send_session_info_update(self, session_id: str) -> None:
"""Send ACP native session metadata after Hermes changes it."""
if not self._conn:
return
try:
row = self.session_manager._get_db().get_session(session_id)
except Exception:
logger.debug("Could not read ACP session info for %s", session_id, exc_info=True)
return
if not row:
return
title = row.get("title")
updated_at = row.get("updated_at")
if updated_at is not None and not isinstance(updated_at, str):
updated_at = str(updated_at)
update = SessionInfoUpdate(
session_update="session_info_update",
title=title if isinstance(title, str) and title.strip() else None,
updated_at=updated_at,
)
try:
await self._conn.session_update(
session_id=session_id,
update=update,
)
except Exception:
logger.debug("Could not send ACP session info update for %s", session_id, exc_info=True)
def _schedule_usage_update(self, state: SessionState) -> None:
"""Schedule native context indicator refresh after ACP responses."""
if not self._conn:
@@ -1471,12 +1501,20 @@ class HermesACPAgent(acp.Agent):
try:
from agent.title_generator import maybe_auto_title
def _notify_title_update(_title: str) -> None:
if conn:
loop.call_soon_threadsafe(
asyncio.create_task,
self._send_session_info_update(session_id),
)
maybe_auto_title(
self.session_manager._get_db(),
session_id,
user_text,
final_response,
state.history,
title_callback=_notify_title_update,
)
except Exception:
logger.debug("Failed to auto-title ACP session %s", session_id, exc_info=True)