fix: Add missing parse_history_entries function to models.py

This commit is contained in:
2026-03-06 18:55:36 -05:00
parent b99900932f
commit df26e73314

View File

@@ -31,6 +31,29 @@ AGENT_TOOL_NAMES = [
"py_get_hierarchy" "py_get_hierarchy"
] ]
def parse_history_entries(history_strings: list[str], roles: list[str]) -> list[dict[str, Any]]:
"""Parse stored history strings back to disc entry dicts."""
import re
entries = []
for raw in history_strings:
ts = ""
rest = raw
if rest.startswith("@"):
nl = rest.find("\n")
if nl != -1:
ts = rest[1:nl]
rest = rest[nl + 1:]
known = roles or ["User", "AI"]
role_pat = re.compile(r"^(" + "|".join(re.escape(r) for r in known) + r"):", re.IGNORECASE)
match = role_pat.match(rest)
role = match.group(1) if match else "User"
if match:
content = rest[match.end():].strip()
else:
content = rest
entries.append({"role": role, "content": content, "collapsed": False, "ts": ts})
return entries
@dataclass @dataclass
class Ticket: class Ticket:
""" """