(id: string)
| 32 | } |
| 33 | |
| 34 | export async function loadSessionById(id: string): Promise<ChatSession | null> { |
| 35 | try { |
| 36 | const res = await fetch(`/api/session?id=${encodeURIComponent(id)}`); |
| 37 | if (!res.ok) { |
| 38 | return null; |
| 39 | } |
| 40 | const parsed = (await res.json()) as ChatSession; |
| 41 | if (!parsed?.id || !Array.isArray(parsed.messages)) { |
| 42 | return null; |
| 43 | } |
| 44 | return normalizeSession(parsed); |
| 45 | } catch { |
| 46 | return null; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | export function sessionPreview(session: ChatSession): string { |
| 51 | const firstUser = session.messages.find((m) => m.role === "user"); |
no test coverage detected