feat(webui): add temporary chat mode

This commit is contained in:
Xubin Ren committed 2026-08-08 23:20:59 +08:00
1 parent 113e8d67ad
commit c9a6145878
41 files changed
+1500 -119

No files matched your search

+61 -21
View File
@@ -923,11 +923,9 @@ class Consolidator:
len(chunk),
replay_max_messages,
)
summary = await self.archive(
chunk,
runtime=runtime,
session_key=session.key,
)
summary = await self._archive_session_chunk(session, chunk, runtime=runtime)
if session.transient is True and not summary:
return None
session.last_consolidated = end_idx
session.provider_state = None
self.sessions.save(session)
@@ -996,8 +994,9 @@ class Consolidator:
runtime: LLMRuntime,
session_key: str | None = None,
summary_messages: list[dict[str, Any]] | None = None,
persist: bool = True,
) -> str | None:
"""Summarize messages and append the result to history.jsonl.
"""Summarize messages, optionally retaining the result in history.jsonl.
``summary_messages`` adds context but is excluded from raw fallback.
"""
@@ -1029,21 +1028,53 @@ class Consolidator:
reasoning_effort=runtime.generation.reasoning_effort,
)
except Exception:
logger.warning("Consolidation provider call failed, raw-dumping to history")
self.store.raw_archive(messages, session_key=session_key)
logger.warning("Consolidation provider call failed")
if persist:
self.store.raw_archive(messages, session_key=session_key)
return None
if response.finish_reason == "error":
logger.warning("Consolidation provider returned an error, raw-dumping to history")
self.store.raw_archive(messages, session_key=session_key)
logger.warning("Consolidation provider returned an error")
if persist:
self.store.raw_archive(messages, session_key=session_key)
return None
summary = response.content or "[no summary]"
self.store.append_history(
summary,
max_chars=_ARCHIVE_SUMMARY_MAX_CHARS,
session_key=session_key,
)
if persist:
self.store.append_history(
summary,
max_chars=_ARCHIVE_SUMMARY_MAX_CHARS,
session_key=session_key,
)
return summary
async def _archive_session_chunk(
self,
session: Session,
chunk: list[dict[str, Any]],
*,
runtime: LLMRuntime,
previous_summary: str | None = None,
) -> str | None:
"""Archive normally, or retain a transient summary only on the session."""
if session.transient is not True:
return await self.archive(
chunk,
runtime=runtime,
session_key=session.key,
)
summary_messages = chunk
if previous_summary:
summary_messages = [{
"role": "assistant",
"content": f"Earlier conversation summary:\n{previous_summary}",
}, *chunk]
return await self.archive(
chunk,
runtime=runtime,
session_key=session.key,
summary_messages=summary_messages,
persist=False,
)
async def maybe_consolidate_by_tokens(
self,
session: Session,
@@ -1075,6 +1106,11 @@ class Consolidator:
replay_max_messages,
runtime=runtime,
)
if session.transient is True and not last_summary:
meta = session.metadata.get("_last_summary")
if isinstance(meta, dict):
value = cast(dict[str, object], meta).get("text")
last_summary = value if isinstance(value, str) and value else None
estimated, source = self.estimate_session_prompt_tokens(
session,
runtime=runtime,
@@ -1123,17 +1159,21 @@ class Consolidator:
source,
len(chunk),
)
summary = await self.archive(
summary = await self._archive_session_chunk(
session,
chunk,
runtime=runtime,
session_key=session.key,
previous_summary=last_summary,
)
# Advance the cursor either way: on success the chunk was
# summarized; on failure archive() already raw-archived it as
# a breadcrumb. Re-archiving the same chunk on the next call
# would just emit duplicate [RAW] entries.
# Durable sessions advance after either a summary or their raw
# fallback. A transient failure has no fallback, so it retries
# later without moving the replay boundary.
if summary:
last_summary = summary
elif session.transient is True:
# There is no durable raw fallback for a transient session,
# so keep its replay boundary unchanged and retry later.
break
session.last_consolidated = end_idx
session.provider_state = None
self.sessions.save(session)