|
24 | 24 |
|
25 | 25 | __all__ = ["parse_session", "quick_session_info"] |
26 | 26 |
|
27 | | -_HANDLED_ENTRY_TYPES = frozenset({"user", "assistant", "system", "progress"}) |
28 | 27 | _SKIP_ENTRY_TYPES = frozenset({"file-history-snapshot"}) |
29 | 28 | _VALID_ROLES = frozenset(get_args(RoleLiteral)) |
| 29 | +_log = logging.getLogger(__name__) |
30 | 30 |
|
31 | 31 |
|
32 | 32 | def _coerce_role(raw: str) -> RoleLiteral: |
33 | 33 | if raw in _VALID_ROLES: |
34 | 34 | return cast(RoleLiteral, raw) |
35 | | - logging.warning("Unknown message role %r; mapping to 'system'", raw) |
| 35 | + _log.warning("Unknown message role %r; mapping to 'system'", raw) |
36 | 36 | return "system" |
37 | 37 |
|
38 | 38 |
|
39 | 39 | def _fallback_message(entry: dict[str, Any], role: RoleLiteral) -> MessageDict: |
40 | 40 | """Minimal message for JSONL entry types without a dedicated processor.""" |
41 | | - content = entry.get("content", "") |
42 | | - text = content if isinstance(content, str) else (str(content) if content is not None else "") |
| 41 | + raw_content = entry.get("content", "") |
| 42 | + if isinstance(raw_content, str): |
| 43 | + text = raw_content |
| 44 | + elif raw_content is not None: |
| 45 | + text = _extract_text(_normalize_content(raw_content)) |
| 46 | + else: |
| 47 | + text = "" |
43 | 48 | return { |
44 | 49 | "role": role, |
45 | 50 | "uuid": entry.get("uuid"), |
46 | 51 | "parent_uuid": entry.get("parentUuid"), |
47 | 52 | "timestamp": entry.get("timestamp"), |
| 53 | + "text": text, |
48 | 54 | "content": text, |
49 | 55 | "is_sidechain": entry.get("isSidechain", False), |
50 | 56 | } |
@@ -155,7 +161,7 @@ def parse_session(filepath: str) -> SessionDict: |
155 | 161 | _process_progress(entry, messages) |
156 | 162 | elif entry_type: |
157 | 163 | type_str = entry_type if isinstance(entry_type, str) else str(entry_type) |
158 | | - if type_str not in _HANDLED_ENTRY_TYPES and type_str not in _SKIP_ENTRY_TYPES: |
| 164 | + if type_str not in _SKIP_ENTRY_TYPES: |
159 | 165 | messages.append(_fallback_message(entry, _coerce_role(type_str))) |
160 | 166 |
|
161 | 167 | metadata["models_used"] = sorted(metadata["models_used"]) |
|
0 commit comments