progresss

This commit is contained in:
2026-02-21 17:24:21 -05:00
parent 09459aa334
commit c4a3034093
3 changed files with 107 additions and 142 deletions

37
gui.py
View File

@@ -1,4 +1,4 @@
# gui.py
# gui.py
import dearpygui.dearpygui as dpg
import tomllib
import tomli_w
@@ -283,6 +283,41 @@ class ConfirmDialog:
return self._approved, self._script
DISC_ROLES = ["User", "AI", "Vendor API", "System"]
def _parse_history_entries(history: list[str]) -> list[dict]:
"""
Convert the raw TOML string array into a flat list of {role, content} dicts.
Each TOML string is one excerpt (may contain multiple role blocks separated
by lines like "Role:" or "[Role]"). We detect the common patterns:
"User:\n..." "AI:\n..." "[User]\n..." "[AI]\n..."
and split accordingly. Unrecognised text becomes a User entry.
"""
import re
entries: list[dict] = []
role_pattern = re.compile(
r'^(?:\[)?(' + '|'.join(re.escape(r) for r in DISC_ROLES) + r')(?:\])?:?\s*$',
re.IGNORECASE | re.MULTILINE,
)
for excerpt in history:
# Find all role header positions
splits = [(m.start(), m.end(), m.group(1).capitalize()) for m in role_pattern.finditer(excerpt)]
if not splits:
# No role headers found - treat whole excerpt as User content
text = excerpt.strip()
if text:
entries.append({"role": "User", "content": text})
continue
# Extract content between headers
for idx, (start, end, role) in enumerate(splits):
next_start = splits[idx + 1][0] if idx + 1 < len(splits) else len(excerpt)
content = excerpt[end:next_start].strip()
# Normalise role capitalisation to match DISC_ROLES
matched = next((r for r in DISC_ROLES if r.lower() == role.lower()), role)
entries.append({"role": matched, "content": content})
return entries
class App:
def __init__(self):
self.config = load_config()