File size: 12,175 Bytes
21bc16e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | import { useState } from 'react'
interface CortexPanelProps {
onLearnText: (text: string) => Promise<any>
onDream: (cycles: number) => Promise<any>
onReason: (question: string) => Promise<any>
loading: boolean
}
type Tab = 'learn' | 'dream' | 'reason'
export function CortexPanel({ onLearnText, onDream, onReason, loading }: CortexPanelProps) {
const [tab, setTab] = useState<Tab>('learn')
const [learnText, setLearnText] = useState('')
const [learnResult, setLearnResult] = useState<any>(null)
const [dreamCycles, setDreamCycles] = useState(3)
const [dreamResult, setDreamResult] = useState<any>(null)
const [reasonQuestion, setReasonQuestion] = useState('')
const [reasonResult, setReasonResult] = useState<any>(null)
const handleLearn = async () => {
if (!learnText.trim() || loading) return
try {
const r = await onLearnText(learnText.trim())
setLearnResult(r)
} catch {
setLearnResult({ error: 'API not reachable' })
}
}
const handleDream = async () => {
if (loading) return
try {
const r = await onDream(dreamCycles)
setDreamResult(r)
} catch {
setDreamResult({ error: 'API not reachable' })
}
}
const handleReason = async () => {
if (!reasonQuestion.trim() || loading) return
try {
const r = await onReason(reasonQuestion.trim())
setReasonResult(r)
} catch {
setReasonResult({ error: 'API not reachable' })
}
}
return (
<div className="flex flex-col h-full glass-card overflow-hidden">
{/* Header */}
<div className="px-5 py-3 border-b border-pal-border">
<div className="flex items-center gap-2">
<span className="text-base">π§ </span>
<h2 className="text-sm font-semibold text-pal-text">Cortex</h2>
<span className="text-[10px] px-1.5 py-0.5 rounded-full bg-pal-accent/15 text-pal-accent font-semibold">
7 FEATURES
</span>
</div>
</div>
{/* Tabs */}
<div className="flex gap-1 p-2 border-b border-pal-border">
{([
['learn', 'π Learn', 'from-pal-accent2/20'],
['dream', 'π Dream', 'from-pal-accent/20'],
['reason', 'π Reason', 'from-pal-gold/20'],
] as [Tab, string, string][]).map(([t, label, color]) => (
<button
key={t}
onClick={() => setTab(t)}
className={`flex-1 py-1.5 rounded-lg text-xs font-semibold transition-all ${
tab === t ? `bg-gradient-to-r ${color} text-pal-text` : 'text-pal-muted hover:text-pal-text'
}`}
>
{label}
</button>
))}
</div>
{/* Content */}
<div className="flex-1 overflow-y-auto p-4">
{/* LEARN TAB */}
{tab === 'learn' && (
<div className="space-y-3">
<div>
<label className="text-[11px] text-pal-muted font-medium uppercase tracking-wide block mb-1">
Paste any text β PALIMPSESTE becomes an expert instantly
</label>
<textarea
value={learnText}
onChange={e => setLearnText(e.target.value)}
placeholder="Paste a Wikipedia article, documentation, book chapter..."
rows={6}
className="w-full bg-pal-surface border border-pal-border rounded-lg px-3 py-2 text-sm text-pal-text placeholder:text-pal-muted focus:outline-none focus:border-pal-accent2/50 transition-all resize-none"
/>
</div>
<button
onClick={handleLearn}
disabled={!learnText.trim() || loading}
className="w-full py-2 rounded-lg 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 disabled:cursor-not-allowed"
>
{loading ? 'Learning...' : 'β‘ Learn Instantly (O(1) per token)'}
</button>
{learnResult && !learnResult.error && (
<div className="p-3 rounded-lg bg-pal-surface/60 border border-pal-accent2/20 animate-slide-up">
<div className="flex items-center gap-3 mb-2">
<div className="text-pal-green text-lg">β</div>
<div>
<div className="text-xs font-semibold text-pal-text">
Learned {learnResult.n_facts} facts in {learnResult.n_seconds}s
</div>
<div className="text-[10px] text-pal-muted">
{learnResult.n_tokens} tokens written Β· tag: {learnResult.document_tag}
</div>
</div>
</div>
{learnResult.facts && learnResult.facts.length > 0 && (
<div className="space-y-1 mt-2 pt-2 border-t border-pal-border/50">
<div className="text-[10px] text-pal-muted uppercase font-medium">Extracted facts:</div>
{learnResult.facts.slice(0, 8).map((f: any, i: number) => (
<div key={i} className="text-[11px] text-pal-text">
<span className="text-pal-accent2">Q:</span> {f.q}
<br />
<span className="text-pal-green">A:</span> {f.a.slice(0, 80)}{f.a.length > 80 ? '...' : ''}
</div>
))}
</div>
)}
</div>
)}
{learnResult?.error && (
<div className="text-xs text-pal-red text-center">{learnResult.error}</div>
)}
</div>
)}
{/* DREAM TAB */}
{tab === 'dream' && (
<div className="space-y-3">
<div className="text-center py-4">
<div className="text-3xl mb-2 animate-float">π</div>
<p className="text-xs text-pal-muted max-w-xs mx-auto">
When idle, PALIMPSESTE replays its memory, discovers co-activations,
and creates new abstract concepts. It gets smarter without any new data.
</p>
</div>
<div className="flex items-center gap-3">
<label className="text-xs text-pal-muted font-medium whitespace-nowrap">
Cycles: <span className="text-pal-accent font-mono">{dreamCycles}</span>
</label>
<input
type="range" min="1" max="10" step="1"
value={dreamCycles}
onChange={e => setDreamCycles(parseInt(e.target.value))}
className="flex-1 accent-pal-accent"
/>
</div>
<button
onClick={handleDream}
disabled={loading}
className="w-full py-2 rounded-lg 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"
>
{loading ? 'Dreaming...' : 'π Trigger Dream'}
</button>
{dreamResult && !dreamResult.error && (
<div className="p-3 rounded-lg bg-pal-surface/60 border border-pal-accent/20 animate-slide-up space-y-2">
<div className="flex items-center gap-3">
<div className="text-pal-accent text-lg">β</div>
<div>
<div className="text-xs font-semibold text-pal-text">
{dreamResult.n_concepts_promoted} promoted, {dreamResult.n_concepts_extracted} extracted
</div>
<div className="text-[10px] text-pal-muted">
{dreamResult.n_seconds}s Β· {dreamResult.n_total_concepts} total concepts
</div>
</div>
</div>
{dreamResult.concept_labels && dreamResult.concept_labels.length > 0 && (
<div className="pt-2 border-t border-pal-border/50">
<div className="text-[10px] text-pal-muted uppercase font-medium mb-1">Concepts:</div>
<div className="flex flex-wrap gap-1">
{dreamResult.concept_labels.map((label: string, i: number) => (
<span key={i} className="text-[10px] px-2 py-0.5 rounded-full bg-pal-accent/10 text-pal-accent">
{label}
</span>
))}
</div>
</div>
)}
</div>
)}
</div>
)}
{/* REASON TAB */}
{tab === 'reason' && (
<div className="space-y-3">
<div>
<label className="text-[11px] text-pal-muted font-medium uppercase tracking-wide block mb-1">
Ask a complex question β PALIMPSESTE decomposes and resolves
</label>
<input
type="text"
value={reasonQuestion}
onChange={e => setReasonQuestion(e.target.value)}
onKeyDown={e => e.key === 'Enter' && handleReason()}
placeholder="what is the capital of the country that won the world cup 2018?"
className="w-full bg-pal-surface border border-pal-border rounded-lg px-3 py-2 text-sm text-pal-text placeholder:text-pal-muted focus:outline-none focus:border-pal-gold/50"
/>
</div>
<button
onClick={handleReason}
disabled={!reasonQuestion.trim() || loading}
className="w-full py-2 rounded-lg bg-gradient-to-r from-pal-gold to-pal-accent text-white font-semibold text-sm transition-all hover:scale-[1.02] disabled:opacity-30"
>
{loading ? 'Reasoning...' : 'π Decompose & Resolve'}
</button>
{reasonResult && !reasonResult.error && (
<div className="p-3 rounded-lg bg-pal-surface/60 border border-pal-gold/20 animate-slide-up space-y-2">
<div className="flex items-center gap-2">
<div className={`text-lg ${reasonResult.success ? 'text-pal-green' : 'text-pal-red'}`}>
{reasonResult.success ? 'β' : 'β'}
</div>
<div className="text-xs font-semibold text-pal-text">
{reasonResult.n_decompositions} decompositions, {reasonResult.n_hops} hops, {reasonResult.n_seconds}s
</div>
</div>
<div className="p-2 rounded-lg bg-pal-bg/50 border border-pal-border/30">
<div className="text-[10px] text-pal-muted uppercase font-medium mb-0.5">Answer:</div>
<div className="text-sm text-pal-gold font-medium">{reasonResult.answer}</div>
</div>
{reasonResult.steps && reasonResult.steps.length > 0 && (
<div className="pt-2 border-t border-pal-border/50 space-y-1">
<div className="text-[10px] text-pal-muted uppercase font-medium">Reasoning trace:</div>
{reasonResult.steps.filter((s: any) => s.answer).map((s: any, i: number) => (
<div key={i} className="text-[11px] flex items-start gap-2">
<span className={`px-1 rounded font-mono ${
s.type === 'resolve' ? 'bg-pal-green/10 text-pal-green' :
s.type === 'compose' ? 'bg-pal-gold/10 text-pal-gold' :
'bg-pal-muted/10 text-pal-muted'
}`}>
{s.type}
</span>
<div>
<span className="text-pal-muted">{s.question?.slice(0, 40)}</span>
{s.answer && <span className="text-pal-text"> β <b>{s.answer.slice(0, 50)}</b></span>}
</div>
</div>
))}
</div>
)}
</div>
)}
</div>
)}
</div>
</div>
)
}
|