| 176 | |
| 177 | |
| 178 | def load_session(kb_dir: Path, session_id: str) -> ChatSession: |
| 179 | path = chats_dir(kb_dir) / f"{session_id}.json" |
| 180 | data = json.loads(path.read_text(encoding="utf-8")) |
| 181 | return ChatSession( |
| 182 | id=data["id"], |
| 183 | created_at=data["created_at"], |
| 184 | updated_at=data["updated_at"], |
| 185 | model=data["model"], |
| 186 | language=data.get("language", "en"), |
| 187 | title=data.get("title", ""), |
| 188 | turn_count=data.get("turn_count", 0), |
| 189 | history=sanitize_history(data.get("history", [])), |
| 190 | user_turns=data.get("user_turns", []), |
| 191 | assistant_texts=data.get("assistant_texts", []), |
| 192 | path=path, |
| 193 | ) |
| 194 | |
| 195 | |
| 196 | def list_sessions(kb_dir: Path) -> list[dict[str, Any]]: |