refactor: code review improvements — fix bugs, extract shared utilities, add README

- Fix reactivity bug: use SvelteMap instead of Map in sessions store
- Fix theme listener memory leak: guard against double-init, return cleanup function
- Fix transport singleton ignoring different endpoints
- Fix form/button type mismatch in MessageInput
- Add safer retry validation in chat page
- Extract shared utilities: date formatting, session config check, result source config
- Extract shared components: Backdrop, PageHeader
- Extract orchestration composable from chat page (310→85 lines of script)
- Consolidate AuditTimeline switch functions into config record
- Move sample data to dedicated module
- Add dark mode support for LineageTree SVG colors
- Memoize leaf count computation in LineageTree
- Update README with usage guide and project structure

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shahondin1624
2026-03-12 13:48:06 +01:00
parent bb0eebff1b
commit 38f5f31b92
26 changed files with 753 additions and 579 deletions

View File

@@ -1,3 +1,4 @@
import { SvelteMap } from 'svelte/reactivity';
import type { ChatMessage } from '$lib/types';
export interface Session {
@@ -10,24 +11,24 @@ export interface Session {
const STORAGE_KEY = 'llm-multiverse-sessions';
const ACTIVE_SESSION_KEY = 'llm-multiverse-active-session';
function loadSessions(): Map<string, Session> {
if (typeof localStorage === 'undefined') return new Map();
function loadSessions(): SvelteMap<string, Session> {
if (typeof localStorage === 'undefined') return new SvelteMap();
try {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return new Map();
if (!raw) return new SvelteMap();
const arr: [string, Session][] = JSON.parse(raw);
return new Map(
return new SvelteMap(
arr.map(([id, s]) => [
id,
{ ...s, createdAt: new Date(s.createdAt), messages: s.messages.map(m => ({ ...m, timestamp: new Date(m.timestamp) })) }
])
);
} catch {
return new Map();
return new SvelteMap();
}
}
function saveSessions(sessions: Map<string, Session>) {
function saveSessions(sessions: SvelteMap<string, Session>) {
if (typeof localStorage === 'undefined') return;
localStorage.setItem(STORAGE_KEY, JSON.stringify([...sessions.entries()]));
}
@@ -43,7 +44,7 @@ function saveActiveSessionId(id: string) {
}
function createSessionStore() {
const sessions = $state<Map<string, Session>>(loadSessions());
const sessions = $state<SvelteMap<string, Session>>(loadSessions());
let activeSessionId = $state<string | null>(loadActiveSessionId());
function createSession(id?: string): Session {