| 160 | os.replace(tmp, self.path) |
| 161 | |
| 162 | def record_turn( |
| 163 | self, |
| 164 | user_message: str, |
| 165 | assistant_text: str, |
| 166 | new_history: list[dict[str, Any]], |
| 167 | ) -> None: |
| 168 | self.history = sanitize_history(new_history) |
| 169 | self.user_turns.append(user_message) |
| 170 | self.assistant_texts.append(assistant_text) |
| 171 | self.turn_count = len(self.user_turns) |
| 172 | if not self.title: |
| 173 | self.title = _title_from(user_message) |
| 174 | self.updated_at = _utcnow_iso() |
| 175 | self.save() |
| 176 | |
| 177 | |
| 178 | def load_session(kb_dir: Path, session_id: str) -> ChatSession: |