fix(gui): fix missing thinking_segments parameter persistence across sessions
This commit is contained in:
@@ -111,6 +111,7 @@ DEFAULT_TOOL_CATEGORIES: Dict[str, List[str]] = {
|
|||||||
|
|
||||||
def parse_history_entries(history_strings: list[str], roles: list[str]) -> list[dict[str, Any]]:
|
def parse_history_entries(history_strings: list[str], roles: list[str]) -> list[dict[str, Any]]:
|
||||||
import re
|
import re
|
||||||
|
from src import thinking_parser
|
||||||
entries = []
|
entries = []
|
||||||
for raw in history_strings:
|
for raw in history_strings:
|
||||||
ts = ""
|
ts = ""
|
||||||
@@ -128,7 +129,15 @@ def parse_history_entries(history_strings: list[str], roles: list[str]) -> list[
|
|||||||
content = rest[match.end():].strip()
|
content = rest[match.end():].strip()
|
||||||
else:
|
else:
|
||||||
content = rest
|
content = rest
|
||||||
entries.append({"role": role, "content": content, "collapsed": True, "ts": ts})
|
|
||||||
|
entry_obj = {"role": role, "content": content, "collapsed": True, "ts": ts}
|
||||||
|
if role == "AI" and ("<thinking>" in content or "<thought>" in content or "Thinking:" in content):
|
||||||
|
segments, parsed_content = thinking_parser.parse_thinking_trace(content)
|
||||||
|
if segments:
|
||||||
|
entry_obj["content"] = parsed_content
|
||||||
|
entry_obj["thinking_segments"] = [{"content": s.content, "marker": s.marker} for s in segments]
|
||||||
|
|
||||||
|
entries.append(entry_obj)
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@@ -33,6 +33,14 @@ def entry_to_str(entry: dict[str, Any]) -> str:
|
|||||||
ts = entry.get("ts", "")
|
ts = entry.get("ts", "")
|
||||||
role = entry.get("role", "User")
|
role = entry.get("role", "User")
|
||||||
content = entry.get("content", "")
|
content = entry.get("content", "")
|
||||||
|
|
||||||
|
segments = entry.get("thinking_segments")
|
||||||
|
if segments:
|
||||||
|
for s in segments:
|
||||||
|
marker = s.get("marker", "thinking")
|
||||||
|
s_content = s.get("content", "")
|
||||||
|
content = f"<{marker}>\n{s_content}\n</{marker}>\n{content}"
|
||||||
|
|
||||||
if ts:
|
if ts:
|
||||||
return f"@{ts}\n{role}:\n{content}"
|
return f"@{ts}\n{role}:\n{content}"
|
||||||
return f"{role}:\n{content}"
|
return f"{role}:\n{content}"
|
||||||
|
|||||||
Reference in New Issue
Block a user