()
| 56 | } |
| 57 | |
| 58 | export function loadLocalSession(): ChatSession | null { |
| 59 | try { |
| 60 | const raw = localStorage.getItem(STORAGE_KEY); |
| 61 | if (!raw) { |
| 62 | return null; |
| 63 | } |
| 64 | const parsed = JSON.parse(raw) as ChatSession; |
| 65 | if (!parsed?.id || !Array.isArray(parsed.messages)) { |
| 66 | return null; |
| 67 | } |
| 68 | return repairSession({ |
| 69 | ...parsed, |
| 70 | messages: parsed.messages.map((m) => ({ |
| 71 | ...m, |
| 72 | content: typeof m.content === "string" ? m.content : "", |
| 73 | reasoning: typeof m.reasoning === "string" ? m.reasoning : undefined, |
| 74 | })), |
| 75 | }); |
| 76 | } catch { |
| 77 | return null; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | export function saveLocalSession(session: ChatSession): void { |
| 82 | localStorage.setItem( |
no test coverage detected