mirror of
https://github.com/usestrix/strix.git
synced 2026-08-28 05:25:00 +00:00
fix(tui): key render cache by content string and return copies
Co-Authored-By: Ahmed Allam <ahmed39652003@gmail.com>
This commit is contained in:
parent
dd29d99b85
commit
5c6cbe0884
2 changed files with 5 additions and 6 deletions
|
|
@ -161,7 +161,7 @@ def _process_inline_formatting(line: str) -> Text:
|
|||
|
||||
|
||||
class AgentMessageRenderer:
|
||||
_cache: ClassVar[dict[int, Text]] = {}
|
||||
_cache: ClassVar[dict[str, Text]] = {}
|
||||
|
||||
@classmethod
|
||||
def render_simple(cls, content: str) -> Text:
|
||||
|
|
@ -170,12 +170,11 @@ class AgentMessageRenderer:
|
|||
cleaned = _BLANK_LINE_RUNS.sub("\n\n", content).strip()
|
||||
if not cleaned:
|
||||
return Text()
|
||||
cache_key = hash(cleaned)
|
||||
cached = cls._cache.get(cache_key)
|
||||
cached = cls._cache.get(cleaned)
|
||||
if cached is not None:
|
||||
return cached.copy()
|
||||
rendered = _apply_markdown_styles(cleaned)
|
||||
if len(cls._cache) > 100:
|
||||
cls._cache.clear()
|
||||
cls._cache[cache_key] = rendered
|
||||
return rendered
|
||||
cls._cache[cleaned] = rendered
|
||||
return rendered.copy()
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ def _truncate_line(line: str) -> str:
|
|||
|
||||
|
||||
def _clean_output(output: str) -> str:
|
||||
cleaned = Text.from_ansi(output).plain.translate(_CONTROL_BYTES_TO_DROP)
|
||||
cleaned: str = Text.from_ansi(output).plain.translate(_CONTROL_BYTES_TO_DROP)
|
||||
for pattern in STRIP_PATTERNS:
|
||||
cleaned = re.sub(pattern, "", cleaned, flags=re.MULTILINE)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue