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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useRef, useEffect } from 'react'
|
| 2 |
+
import type { ChatMessage, Metrics, MemorySamples } from '../types'
|
| 3 |
+
import { SourceBadge } from './SourceBadge'
|
| 4 |
+
|
| 5 |
+
interface ApiProps {
|
| 6 |
+
connected: boolean
|
| 7 |
+
metrics: Metrics | null
|
| 8 |
+
loading: boolean
|
| 9 |
+
sendMessage: (message: string, temperature?: number, maxTokens?: number) => Promise<any>
|
| 10 |
+
teachModel: (question: string, answer: string) => Promise<any>
|
| 11 |
+
learnText: (text: string) => Promise<any>
|
| 12 |
+
dream: (cycles: number) => Promise<any>
|
| 13 |
+
reason: (question: string) => Promise<any>
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
type SidebarTab = 'chat' | 'teach' | 'learn' | 'dream' | 'stats'
|
| 17 |
+
|
| 18 |
+
const SUGGESTIONS = [
|
| 19 |
+
{ icon: 'π', title: 'Say hello', q: 'hello' },
|
| 20 |
+
{ icon: 'π§ ', title: 'Who are you?', q: 'who are you' },
|
| 21 |
+
{ icon: 'π', title: 'What is Python?', q: 'what is python' },
|
| 22 |
+
{ icon: 'β¨', title: 'Write a poem', q: 'write a poem about the sea' },
|
| 23 |
+
{ icon: 'π»', title: 'Write code', q: 'write a python function to check if a number is prime' },
|
| 24 |
+
{ icon: 'π', title: 'Explain something', q: 'explain how the internet works' },
|
| 25 |
+
{ icon: 'π', title: 'Science facts', q: 'what is dark matter' },
|
| 26 |
+
{ icon: 'π‘', title: 'Get advice', q: 'how to stay focused' },
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
export function ChatGPTLayout({ api }: { api: ApiProps }) {
|
| 30 |
+
const [messages, setMessages] = useState<ChatMessage[]>([])
|
| 31 |
+
const [input, setInput] = useState('')
|
| 32 |
+
const [sidebarOpen, setSidebarOpen] = useState(true)
|
| 33 |
+
const [tab, setTab] = useState<SidebarTab>('chat')
|
| 34 |
+
const scrollRef = useRef<HTMLDivElement>(null)
|
| 35 |
+
|
| 36 |
+
// Teach state
|
| 37 |
+
const [teachQ, setTeachQ] = useState('')
|
| 38 |
+
const [teachA, setTeachA] = useState('')
|
| 39 |
+
const [teachHistory, setTeachHistory] = useState<{q: string, a: string, tokens: number}[]>([])
|
| 40 |
+
|
| 41 |
+
// Learn state
|
| 42 |
+
const [learnText, setLearnText] = useState('')
|
| 43 |
+
const [learnResult, setLearnResult] = useState<any>(null)
|
| 44 |
+
|
| 45 |
+
// Dream state
|
| 46 |
+
const [dreamResult, setDreamResult] = useState<any>(null)
|
| 47 |
+
|
| 48 |
+
useEffect(() => {
|
| 49 |
+
if (scrollRef.current) scrollRef.current.scrollTop = scrollRef.current.scrollHeight
|
| 50 |
+
}, [messages, api.loading])
|
| 51 |
+
|
| 52 |
+
const handleSend = async () => {
|
| 53 |
+
const msg = input.trim()
|
| 54 |
+
if (!msg || api.loading) return
|
| 55 |
+
setInput('')
|
| 56 |
+
const userMsg: ChatMessage = { id: `u-${Date.now()}`, role: 'user', text: msg, timestamp: Date.now() }
|
| 57 |
+
setMessages(prev => [...prev, userMsg])
|
| 58 |
+
try {
|
| 59 |
+
const resp = await api.sendMessage(msg)
|
| 60 |
+
setMessages(prev => [...prev, {
|
| 61 |
+
id: `b-${Date.now()}`, role: 'palimpseste', text: resp.response,
|
| 62 |
+
confidence: resp.confidence, source: resp.source,
|
| 63 |
+
explanation: resp.explanation, chain: resp.chain,
|
| 64 |
+
elapsed_ms: resp.elapsed_ms, timestamp: Date.now(),
|
| 65 |
+
}])
|
| 66 |
+
} catch {
|
| 67 |
+
setMessages(prev => [...prev, {
|
| 68 |
+
id: `e-${Date.now()}`, role: 'palimpseste',
|
| 69 |
+
text: 'β οΈ Cannot connect to server. Is the API running on :3332?',
|
| 70 |
+
source: 'fallback', confidence: 0, timestamp: Date.now(),
|
| 71 |
+
}])
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
const handleTeach = async () => {
|
| 76 |
+
if (!teachQ.trim() || !teachA.trim() || api.loading) return
|
| 77 |
+
try {
|
| 78 |
+
const resp = await api.teachModel(teachQ, teachA)
|
| 79 |
+
setTeachHistory(prev => [{ q: teachQ, a: teachA, tokens: resp.tokens_written }, ...prev])
|
| 80 |
+
setTeachQ(''); setTeachA('')
|
| 81 |
+
} catch {}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
const handleLearn = async () => {
|
| 85 |
+
if (!learnText.trim() || api.loading) return
|
| 86 |
+
try {
|
| 87 |
+
const r = await api.learnText(learnText)
|
| 88 |
+
setLearnResult(r)
|
| 89 |
+
} catch {}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
const handleDream = async () => {
|
| 93 |
+
try {
|
| 94 |
+
const r = await api.dream(3)
|
| 95 |
+
setDreamResult(r)
|
| 96 |
+
} catch {}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
const newChat = () => { setMessages([]); setTab('chat') }
|
| 100 |
+
|
| 101 |
+
return (
|
| 102 |
+
<div className="h-screen w-screen flex bg-pal-bg relative overflow-hidden">
|
| 103 |
+
{/* Background orbs */}
|
| 104 |
+
<div className="bg-orbs">
|
| 105 |
+
<div className="bg-orb" style={{ width: '500px', height: '500px', background: '#7c3aed', top: '-100px', left: '-100px' }} />
|
| 106 |
+
<div className="bg-orb" style={{ width: '400px', height: '400px', background: '#06b6d4', bottom: '-50px', right: '-50px', animationDelay: '2s' }} />
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
{/* Sidebar */}
|
| 110 |
+
{sidebarOpen && (
|
| 111 |
+
<aside className="relative z-10 w-72 glass border-r border-pal-border flex flex-col">
|
| 112 |
+
{/* New chat button */}
|
| 113 |
+
<div className="p-3">
|
| 114 |
+
<button onClick={newChat} className="w-full flex items-center gap-2 px-3 py-2.5 rounded-xl glass-card hover:border-pal-accent/30 transition-all text-sm text-pal-text font-medium">
|
| 115 |
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M12 5v14M5 12h14"/></svg>
|
| 116 |
+
New Chat
|
| 117 |
+
</button>
|
| 118 |
+
</div>
|
| 119 |
+
|
| 120 |
+
{/* Nav */}
|
| 121 |
+
<nav className="px-2 space-y-0.5">
|
| 122 |
+
{([
|
| 123 |
+
['chat', 'π¬', 'Chat'],
|
| 124 |
+
['teach', 'π', 'Teach'],
|
| 125 |
+
['learn', 'π', 'Learn Text'],
|
| 126 |
+
['dream', 'π', 'Dream'],
|
| 127 |
+
['stats', 'π', 'Statistics'],
|
| 128 |
+
] as [SidebarTab, string, string][]).map(([t, icon, label]) => (
|
| 129 |
+
<button key={t} onClick={() => setTab(t)}
|
| 130 |
+
className={`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all ${
|
| 131 |
+
tab === t ? 'glass-card text-pal-text font-medium' : 'text-pal-muted hover:text-pal-text'
|
| 132 |
+
}`}>
|
| 133 |
+
<span>{icon}</span> {label}
|
| 134 |
+
</button>
|
| 135 |
+
))}
|
| 136 |
+
</nav>
|
| 137 |
+
|
| 138 |
+
{/* Connection status */}
|
| 139 |
+
<div className="mt-auto p-3 border-t border-pal-border">
|
| 140 |
+
<div className="flex items-center gap-2 mb-2">
|
| 141 |
+
<div className={`w-2 h-2 rounded-full ${api.connected ? 'bg-pal-green' : 'bg-pal-red'}`}>
|
| 142 |
+
{api.connected && <div className="w-2 h-2 rounded-full bg-pal-green animate-ping" />}
|
| 143 |
+
</div>
|
| 144 |
+
<span className="text-xs text-pal-muted">{api.connected ? 'Connected' : 'Offline'}</span>
|
| 145 |
+
</div>
|
| 146 |
+
<p className="text-[10px] text-pal-muted">PALIMPSESTE Β· No GPU Β· 0 weights</p>
|
| 147 |
+
<p className="text-[10px] text-pal-muted">Philippe-Antoine Robert Β· 2026</p>
|
| 148 |
+
</div>
|
| 149 |
+
</aside>
|
| 150 |
+
)}
|
| 151 |
+
|
| 152 |
+
{/* Main content */}
|
| 153 |
+
<main className="relative z-10 flex-1 flex flex-col">
|
| 154 |
+
{/* Top bar */}
|
| 155 |
+
<header className="flex items-center justify-between px-4 py-2.5 border-b border-pal-border glass">
|
| 156 |
+
<div className="flex items-center gap-3">
|
| 157 |
+
<button onClick={() => setSidebarOpen(!sidebarOpen)}
|
| 158 |
+
className="p-1.5 rounded-lg hover:bg-pal-card text-pal-muted hover:text-pal-text transition-all">
|
| 159 |
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M3 12h18M3 6h18M3 18h18"/></svg>
|
| 160 |
+
</button>
|
| 161 |
+
<span className="text-sm font-bold gradient-text">PALIMPSESTE</span>
|
| 162 |
+
<span className="text-[10px] px-1.5 py-0.5 rounded-full bg-pal-accent/15 text-pal-accent font-semibold">BPE</span>
|
| 163 |
+
</div>
|
| 164 |
+
{api.metrics && (
|
| 165 |
+
<div className="hidden md:flex items-center gap-3 text-xs text-pal-muted">
|
| 166 |
+
<span>D={api.metrics.model.D.toLocaleString()}</span>
|
| 167 |
+
<span>Β·</span>
|
| 168 |
+
<span>|M|={api.metrics.model.n_traces.toLocaleString()}</span>
|
| 169 |
+
</div>
|
| 170 |
+
)}
|
| 171 |
+
</header>
|
| 172 |
+
|
| 173 |
+
{/* Content area */}
|
| 174 |
+
{tab === 'chat' && (
|
| 175 |
+
<>
|
| 176 |
+
{/* Messages */}
|
| 177 |
+
<div ref={scrollRef} className="flex-1 overflow-y-auto">
|
| 178 |
+
{messages.length === 0 ? (
|
| 179 |
+
<div className="h-full flex flex-col items-center justify-center px-6">
|
| 180 |
+
<div className="text-5xl mb-4 animate-float">π§ </div>
|
| 181 |
+
<h1 className="text-2xl font-bold gradient-text mb-1">PALIMPSESTE</h1>
|
| 182 |
+
<p className="text-sm text-pal-muted mb-8">A self-referential hypervectorial cortex</p>
|
| 183 |
+
<div className="grid grid-cols-2 gap-2 max-w-lg w-full">
|
| 184 |
+
{SUGGESTIONS.map(s => (
|
| 185 |
+
<button key={s.q} onClick={() => setInput(s.q)}
|
| 186 |
+
className="flex items-center gap-2 p-3 rounded-xl glass-card hover:border-pal-accent/30 transition-all text-left">
|
| 187 |
+
<span className="text-lg">{s.icon}</span>
|
| 188 |
+
<div>
|
| 189 |
+
<div className="text-xs font-medium text-pal-text">{s.title}</div>
|
| 190 |
+
<div className="text-[10px] text-pal-muted truncate">{s.q}</div>
|
| 191 |
+
</div>
|
| 192 |
+
</button>
|
| 193 |
+
))}
|
| 194 |
+
</div>
|
| 195 |
+
</div>
|
| 196 |
+
) : (
|
| 197 |
+
<div className="max-w-3xl mx-auto px-4 py-6 space-y-6">
|
| 198 |
+
{messages.map(msg => (
|
| 199 |
+
<div key={msg.id} className={`flex gap-3 ${msg.role === 'user' ? 'justify-end' : ''} animate-slide-up`}>
|
| 200 |
+
{msg.role === 'palimpseste' && (
|
| 201 |
+
<div className="w-8 h-8 rounded-full bg-gradient-to-br from-pal-accent to-pal-accent2 flex items-center justify-center text-sm flex-shrink-0">
|
| 202 |
+
π§
|
| 203 |
+
</div>
|
| 204 |
+
)}
|
| 205 |
+
<div className={`max-w-[80%] ${msg.role === 'user' ? 'order-1' : ''}`}>
|
| 206 |
+
<div className={`rounded-2xl px-4 py-3 ${
|
| 207 |
+
msg.role === 'user'
|
| 208 |
+
? 'bg-gradient-to-br from-pal-accent/30 to-pal-accent/10 border border-pal-accent/30'
|
| 209 |
+
: 'glass border border-pal-border'
|
| 210 |
+
}`}>
|
| 211 |
+
<p className="text-sm text-pal-text whitespace-pre-wrap break-words">{msg.text}</p>
|
| 212 |
+
{msg.role === 'palimpseste' && msg.source && (
|
| 213 |
+
<div className="mt-2 pt-2 border-t border-pal-border/50">
|
| 214 |
+
<div className="flex items-center justify-between gap-2">
|
| 215 |
+
<SourceBadge source={msg.source} confidence={msg.confidence ?? 0} />
|
| 216 |
+
{msg.elapsed_ms !== undefined && (
|
| 217 |
+
<span className="text-[10px] text-pal-muted font-mono">{msg.elapsed_ms < 1 ? '<1' : msg.elapsed_ms.toFixed(0)}ms</span>
|
| 218 |
+
)}
|
| 219 |
+
</div>
|
| 220 |
+
</div>
|
| 221 |
+
)}
|
| 222 |
+
</div>
|
| 223 |
+
</div>
|
| 224 |
+
{msg.role === 'user' && (
|
| 225 |
+
<div className="w-8 h-8 rounded-full bg-pal-card flex items-center justify-center text-sm flex-shrink-0">
|
| 226 |
+
π§
|
| 227 |
+
</div>
|
| 228 |
+
)}
|
| 229 |
+
</div>
|
| 230 |
+
))}
|
| 231 |
+
{api.loading && (
|
| 232 |
+
<div className="flex gap-3">
|
| 233 |
+
<div className="w-8 h-8 rounded-full bg-gradient-to-br from-pal-accent to-pal-accent2 flex items-center justify-center text-sm">π§ </div>
|
| 234 |
+
<div className="glass border border-pal-border rounded-2xl px-4 py-3">
|
| 235 |
+
<div className="flex gap-1.5">
|
| 236 |
+
<span className="w-2 h-2 rounded-full bg-pal-accent animate-bounce" style={{ animationDelay: '0ms' }} />
|
| 237 |
+
<span className="w-2 h-2 rounded-full bg-pal-accent animate-bounce" style={{ animationDelay: '150ms' }} />
|
| 238 |
+
<span className="w-2 h-2 rounded-full bg-pal-accent animate-bounce" style={{ animationDelay: '300ms' }} />
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
)}
|
| 243 |
+
</div>
|
| 244 |
+
)}
|
| 245 |
+
</div>
|
| 246 |
+
|
| 247 |
+
{/* Input bar */}
|
| 248 |
+
<div className="border-t border-pal-border glass px-4 py-3">
|
| 249 |
+
<div className="max-w-3xl mx-auto flex gap-2 items-end">
|
| 250 |
+
<textarea
|
| 251 |
+
value={input}
|
| 252 |
+
onChange={e => setInput(e.target.value)}
|
| 253 |
+
onKeyDown={e => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend() } }}
|
| 254 |
+
placeholder="Message PALIMPSESTE..."
|
| 255 |
+
rows={1}
|
| 256 |
+
className="flex-1 bg-pal-surface border border-pal-border rounded-2xl px-4 py-3 text-sm text-pal-text placeholder:text-pal-muted focus:outline-none focus:border-pal-accent/40 transition-all resize-none max-h-32"
|
| 257 |
+
style={{ minHeight: '46px' }}
|
| 258 |
+
/>
|
| 259 |
+
<button onClick={handleSend} disabled={!input.trim() || api.loading}
|
| 260 |
+
className="p-3 rounded-2xl bg-gradient-to-br from-pal-accent to-pal-accent2 text-white transition-all hover:scale-105 hover:glow-accent disabled:opacity-30 disabled:cursor-not-allowed">
|
| 261 |
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"/></svg>
|
| 262 |
+
</button>
|
| 263 |
+
</div>
|
| 264 |
+
<p className="text-center text-[10px] text-pal-muted mt-1.5">
|
| 265 |
+
PALIMPSESTE can make mistakes. No weights, no gradient, no GPU.
|
| 266 |
+
</p>
|
| 267 |
+
</div>
|
| 268 |
+
</>
|
| 269 |
+
)}
|
| 270 |
+
|
| 271 |
+
{/* TEACH TAB */}
|
| 272 |
+
{tab === 'teach' && (
|
| 273 |
+
<div className="flex-1 overflow-y-auto p-6">
|
| 274 |
+
<div className="max-w-lg mx-auto space-y-4">
|
| 275 |
+
<h2 className="text-lg font-bold text-pal-text flex items-center gap-2">π Teach PALIMPSESTE</h2>
|
| 276 |
+
<p className="text-sm text-pal-muted">Teach new facts instantly. O(1) memory write, immediately retrievable.</p>
|
| 277 |
+
<input value={teachQ} onChange={e => setTeachQ(e.target.value)} onKeyDown={e => e.key === 'Enter' && handleTeach()}
|
| 278 |
+
placeholder="Question" className="w-full bg-pal-surface border border-pal-border rounded-xl px-4 py-2.5 text-sm text-pal-text placeholder:text-pal-muted focus:outline-none focus:border-pal-green/40" />
|
| 279 |
+
<input value={teachA} onChange={e => setTeachA(e.target.value)} onKeyDown={e => e.key === 'Enter' && handleTeach()}
|
| 280 |
+
placeholder="Answer" className="w-full bg-pal-surface border border-pal-border rounded-xl px-4 py-2.5 text-sm text-pal-text placeholder:text-pal-muted focus:outline-none focus:border-pal-green/40" />
|
| 281 |
+
<button onClick={handleTeach} disabled={!teachQ.trim() || !teachA.trim() || api.loading}
|
| 282 |
+
className="w-full py-2.5 rounded-xl bg-gradient-to-r from-pal-green to-pal-accent2 text-white font-semibold text-sm transition-all hover:scale-[1.02] disabled:opacity-30">
|
| 283 |
+
β‘ Teach Instantly
|
| 284 |
+
</button>
|
| 285 |
+
{teachHistory.map((h, i) => (
|
| 286 |
+
<div key={i} className="p-3 rounded-xl glass-card animate-slide-up">
|
| 287 |
+
<div className="text-sm text-pal-text">{h.q} β <span className="text-pal-green font-medium">{h.a}</span></div>
|
| 288 |
+
<div className="text-[10px] text-pal-muted mt-0.5">+{h.tokens} tokens</div>
|
| 289 |
+
</div>
|
| 290 |
+
))}
|
| 291 |
+
</div>
|
| 292 |
+
</div>
|
| 293 |
+
)}
|
| 294 |
+
|
| 295 |
+
{/* LEARN TAB */}
|
| 296 |
+
{tab === 'learn' && (
|
| 297 |
+
<div className="flex-1 overflow-y-auto p-6">
|
| 298 |
+
<div className="max-w-lg mx-auto space-y-4">
|
| 299 |
+
<h2 className="text-lg font-bold text-pal-text flex items-center gap-2">π Instant Expertise</h2>
|
| 300 |
+
<p className="text-sm text-pal-muted">Paste any text. PALIMPSESTE becomes an expert in milliseconds.</p>
|
| 301 |
+
<textarea value={learnText} onChange={e => setLearnText(e.target.value)} placeholder="Paste a document, article, or any text..." rows={8}
|
| 302 |
+
className="w-full bg-pal-surface border border-pal-border rounded-xl px-4 py-2.5 text-sm text-pal-text placeholder:text-pal-muted focus:outline-none focus:border-pal-accent2/40 resize-none" />
|
| 303 |
+
<button onClick={handleLearn} disabled={!learnText.trim() || api.loading}
|
| 304 |
+
className="w-full py-2.5 rounded-xl bg-gradient-to-r from-pal-accent2 to-pal-green text-white font-semibold text-sm transition-all hover:scale-[1.02] disabled:opacity-30">
|
| 305 |
+
β‘ Learn Instantly
|
| 306 |
+
</button>
|
| 307 |
+
{learnResult && !learnResult.error && (
|
| 308 |
+
<div className="p-3 rounded-xl glass-card border-pal-accent2/20 animate-slide-up">
|
| 309 |
+
<div className="text-sm font-semibold text-pal-green mb-1">β Learned {learnResult.n_facts} facts in {learnResult.n_seconds}s</div>
|
| 310 |
+
{learnResult.facts?.map((f: any, i: number) => (
|
| 311 |
+
<div key={i} className="text-xs text-pal-text mt-1"><span className="text-pal-accent2">Q:</span> {f.q}<br/><span className="text-pal-green">A:</span> {f.a?.slice(0, 80)}</div>
|
| 312 |
+
))}
|
| 313 |
+
</div>
|
| 314 |
+
)}
|
| 315 |
+
</div>
|
| 316 |
+
</div>
|
| 317 |
+
)}
|
| 318 |
+
|
| 319 |
+
{/* DREAM TAB */}
|
| 320 |
+
{tab === 'dream' && (
|
| 321 |
+
<div className="flex-1 overflow-y-auto p-6">
|
| 322 |
+
<div className="max-w-lg mx-auto space-y-4">
|
| 323 |
+
<h2 className="text-lg font-bold text-pal-text flex items-center gap-2">π Dream Consolidation</h2>
|
| 324 |
+
<p className="text-sm text-pal-muted">When idle, PALIMPSESTE replays memory, discovers concepts, and gets smarter autonomously.</p>
|
| 325 |
+
<button onClick={handleDream} disabled={api.loading}
|
| 326 |
+
className="w-full py-2.5 rounded-xl bg-gradient-to-r from-pal-accent to-pal-accent2 text-white font-semibold text-sm transition-all hover:scale-[1.02] hover:glow-accent disabled:opacity-30">
|
| 327 |
+
π Trigger Dream
|
| 328 |
+
</button>
|
| 329 |
+
{dreamResult && !dreamResult.error && (
|
| 330 |
+
<div className="p-3 rounded-xl glass-card border-pal-accent/20 animate-slide-up">
|
| 331 |
+
<div className="text-sm font-semibold text-pal-accent">β {dreamResult.n_concepts_extracted} concepts discovered</div>
|
| 332 |
+
<div className="text-xs text-pal-muted mt-1">in {dreamResult.n_seconds}s Β· {dreamResult.n_total_concepts} total</div>
|
| 333 |
+
{dreamResult.concept_labels?.length > 0 && (
|
| 334 |
+
<div className="flex flex-wrap gap-1 mt-2">
|
| 335 |
+
{dreamResult.concept_labels.map((l: string, i: number) => (
|
| 336 |
+
<span key={i} className="text-[10px] px-2 py-0.5 rounded-full bg-pal-accent/10 text-pal-accent">{l}</span>
|
| 337 |
+
))}
|
| 338 |
+
</div>
|
| 339 |
+
)}
|
| 340 |
+
</div>
|
| 341 |
+
)}
|
| 342 |
+
</div>
|
| 343 |
+
</div>
|
| 344 |
+
)}
|
| 345 |
+
|
| 346 |
+
{/* STATS TAB */}
|
| 347 |
+
{tab === 'stats' && api.metrics && (
|
| 348 |
+
<div className="flex-1 overflow-y-auto p-6">
|
| 349 |
+
<div className="max-w-lg mx-auto space-y-3">
|
| 350 |
+
<h2 className="text-lg font-bold text-pal-text">π Statistics</h2>
|
| 351 |
+
<div className="grid grid-cols-2 gap-2">
|
| 352 |
+
<StatCard label="Dimension (D)" value={api.metrics.model.D.toLocaleString()} />
|
| 353 |
+
<StatCard label="Memory Traces" value={api.metrics.model.n_traces.toLocaleString()} />
|
| 354 |
+
<StatCard label="Vocab" value={api.metrics.model.vocab_size.toLocaleString()} />
|
| 355 |
+
<StatCard label="Context Window" value={api.metrics.model.context_window.toString()} />
|
| 356 |
+
<StatCard label="Kernel Radius" value={api.metrics.config.kernel_radius.toString()} />
|
| 357 |
+
<StatCard label="Temperature" value={api.metrics.config.temperature.toString()} />
|
| 358 |
+
<StatCard label="Turns" value={api.metrics.conversation.turns.toString()} />
|
| 359 |
+
<StatCard label="Mean Weight" value={api.metrics.memory.mean_weight.toFixed(3)} />
|
| 360 |
+
</div>
|
| 361 |
+
<div className="p-3 rounded-xl glass-card">
|
| 362 |
+
<div className="text-[10px] text-pal-muted uppercase font-medium mb-1">Theoretical Capacity</div>
|
| 363 |
+
<div className="text-lg font-bold gradient-text">2^{(api.metrics.model.theoretical_capacity_log2 / 3.32).toFixed(0)}</div>
|
| 364 |
+
<div className="text-[10px] text-pal-muted">β 10^{api.metrics.model.theoretical_capacity_log2.toFixed(0)} associations</div>
|
| 365 |
+
</div>
|
| 366 |
+
</div>
|
| 367 |
+
</div>
|
| 368 |
+
)}
|
| 369 |
+
{tab === 'stats' && !api.metrics && (
|
| 370 |
+
<div className="flex-1 flex items-center justify-center text-pal-muted text-sm">Loading statistics...</div>
|
| 371 |
+
)}
|
| 372 |
+
</main>
|
| 373 |
+
</div>
|
| 374 |
+
)
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
function StatCard({ label, value }: { label: string; value: string }) {
|
| 378 |
+
return (
|
| 379 |
+
<div className="p-3 rounded-xl glass-card">
|
| 380 |
+
<div className="text-[10px] text-pal-muted uppercase font-medium">{label}</div>
|
| 381 |
+
<div className="text-lg font-bold text-pal-text">{value}</div>
|
| 382 |
+
</div>
|
| 383 |
+
)
|
| 384 |
+
}
|