|
41 | 41 | "_track_file_activity", |
42 | 42 | ] |
43 | 43 |
|
44 | | -_HANDLED_ENTRY_TYPES = frozenset({"user", "assistant", "system", "progress"}) |
45 | 44 | _SKIP_ENTRY_TYPES = frozenset({"file-history-snapshot"}) |
46 | 45 | _VALID_ROLES = frozenset(get_args(RoleLiteral)) |
| 46 | +_log = logging.getLogger(__name__) |
47 | 47 |
|
48 | 48 |
|
49 | 49 | def _coerce_role(raw: str) -> RoleLiteral: |
50 | 50 | if raw in _VALID_ROLES: |
51 | 51 | return cast(RoleLiteral, raw) |
52 | | - logging.warning("Unknown message role %r; mapping to 'system'", raw) |
| 52 | + _log.warning("Unknown message role %r; mapping to 'system'", raw) |
53 | 53 | return "system" |
54 | 54 |
|
55 | 55 |
|
56 | 56 | def _fallback_message(entry: dict[str, Any], role: RoleLiteral) -> MessageDict: |
57 | 57 | """Minimal message for JSONL entry types without a dedicated processor.""" |
58 | | - content = entry.get("content", "") |
59 | | - text = content if isinstance(content, str) else (str(content) if content is not None else "") |
| 58 | + raw_content = entry.get("content", "") |
| 59 | + if isinstance(raw_content, str): |
| 60 | + text = raw_content |
| 61 | + elif raw_content is not None: |
| 62 | + text = _extract_text(_normalize_content(raw_content)) |
| 63 | + else: |
| 64 | + text = "" |
60 | 65 | return { |
61 | 66 | "role": role, |
62 | 67 | "uuid": entry.get("uuid"), |
63 | 68 | "parent_uuid": entry.get("parentUuid"), |
64 | 69 | "timestamp": entry.get("timestamp"), |
| 70 | + "text": text, |
65 | 71 | "content": text, |
66 | 72 | "is_sidechain": entry.get("isSidechain", False), |
67 | 73 | } |
@@ -172,7 +178,7 @@ def parse_session(filepath: str) -> SessionDict: |
172 | 178 | _process_progress(entry, messages) |
173 | 179 | elif entry_type: |
174 | 180 | type_str = entry_type if isinstance(entry_type, str) else str(entry_type) |
175 | | - if type_str not in _HANDLED_ENTRY_TYPES and type_str not in _SKIP_ENTRY_TYPES: |
| 181 | + if type_str not in _SKIP_ENTRY_TYPES: |
176 | 182 | messages.append(_fallback_message(entry, _coerce_role(type_str))) |
177 | 183 |
|
178 | 184 | metadata["models_used"] = sorted(metadata["models_used"]) |
|
0 commit comments