import{c as q,u as oe,a as Fe,b as ge,j as e,f as ue,d as Re,e as w,g as K,q as P,h as Ie,r as N,C as Y,L as Oe,i as Pe,B as le,k as Te,E as Be,l as de,m as Ge,n as $e,o as He,p as ee,X as pe,P as Qe,H as fe,T as re,s as Ue,t as Ve,v as V,w as We,S as ye,x as Ze,y as Je,z as Xe,A as Ye,D as De,F as et,G as tt}from"./index-DCel3VuW.js";import{C as rt}from"./code-xml-D8KV20lN.js";import{R as st}from"./rotate-ccw-D-_Gb8HQ.js";import{C as be,Z as ie,L as nt,a as at}from"./zap-BzgvZa8u.js";import{L as ot}from"./layers-BNyHHdLg.js";/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const lt=q("BrainCircuit",[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M9 13a4.5 4.5 0 0 0 3-4",key:"10igwf"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M12 13h4",key:"1ku699"}],["path",{d:"M12 18h6a2 2 0 0 1 2 2v1",key:"105ag5"}],["path",{d:"M12 8h8",key:"1lhi5i"}],["path",{d:"M16 8V5a2 2 0 0 1 2-2",key:"u6izg6"}],["circle",{cx:"16",cy:"13",r:".5",key:"ry7gng"}],["circle",{cx:"18",cy:"3",r:".5",key:"1aiba7"}],["circle",{cx:"20",cy:"21",r:".5",key:"yhc1fs"}],["circle",{cx:"20",cy:"8",r:".5",key:"1e43v0"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const dt=q("BrainCog",[["path",{d:"M12 5a3 3 0 1 0-5.997.142 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588 4 4 0 0 0 7.636 2.106 3.2 3.2 0 0 0 .164-.546c.028-.13.306-.13.335 0a3.2 3.2 0 0 0 .163.546 4 4 0 0 0 7.636-2.106 4 4 0 0 0 .556-6.588 4 4 0 0 0-2.526-5.77A3 3 0 1 0 12 5",key:"1kgmhc"}],["path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375",key:"tmeiqw"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M19.938 10.5a4 4 0 0 1 .585.396",key:"1qfode"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M19.967 17.484A4 4 0 0 1 18 18",key:"159ez6"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m15.7 10.4-.9.4",key:"ayzo6p"}],["path",{d:"m9.2 13.2-.9.4",key:"1uzb3g"}],["path",{d:"m13.6 15.7-.4-.9",key:"11ifqf"}],["path",{d:"m10.8 9.2-.4-.9",key:"1pmk2v"}],["path",{d:"m15.7 13.5-.9-.4",key:"7ng02m"}],["path",{d:"m9.2 10.9-.9-.4",key:"1x66zd"}],["path",{d:"m10.5 15.7.4-.9",key:"3js94g"}],["path",{d:"m13.1 9.2.4-.9",key:"18n7mc"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ee=q("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ne=q("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const it=q("Flame",[["path",{d:"M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z",key:"96xj49"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ct=q("Heart",[["path",{d:"M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",key:"c3ymky"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const xt=q("ListOrdered",[["path",{d:"M10 12h11",key:"6m4ad9"}],["path",{d:"M10 18h11",key:"11hvi2"}],["path",{d:"M10 6h11",key:"c7qv1k"}],["path",{d:"M4 10h2",key:"16xx2s"}],["path",{d:"M4 6h1v4",key:"cnovpq"}],["path",{d:"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1",key:"m9a95d"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const mt=q("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ut=q("PenLine",[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z",key:"1ykcvy"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const pt=q("PowerOff",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const qe=q("Scale",[["path",{d:"m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z",key:"7g6ntu"}],["path",{d:"m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z",key:"ijws7r"}],["path",{d:"M7 21h10",key:"1b0cd5"}],["path",{d:"M12 3v18",key:"108xh3"}],["path",{d:"M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2",key:"3gwbw2"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const bt=q("SlidersVertical",[["line",{x1:"4",x2:"4",y1:"21",y2:"14",key:"1p332r"}],["line",{x1:"4",x2:"4",y1:"10",y2:"3",key:"gb41h5"}],["line",{x1:"12",x2:"12",y1:"21",y2:"12",key:"hf2csr"}],["line",{x1:"12",x2:"12",y1:"8",y2:"3",key:"1kfi7u"}],["line",{x1:"20",x2:"20",y1:"21",y2:"16",key:"1lhrwl"}],["line",{x1:"20",x2:"20",y1:"12",y2:"3",key:"16vvfq"}],["line",{x1:"2",x2:"6",y1:"14",y2:"14",key:"1uebub"}],["line",{x1:"10",x2:"14",y1:"8",y2:"8",key:"1yglbp"}],["line",{x1:"18",x2:"22",y1:"16",y2:"16",key:"1jxqpz"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ht=q("Star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]);/** * @license lucide-react v0.460.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const gt=q("Telescope",[["path",{d:"m10.065 12.493-6.18 1.318a.934.934 0 0 1-1.108-.702l-.537-2.15a1.07 1.07 0 0 1 .691-1.265l13.504-4.44",key:"k4qptu"}],["path",{d:"m13.56 11.747 4.332-.924",key:"19l80z"}],["path",{d:"m16 21-3.105-6.21",key:"7oh9d"}],["path",{d:"M16.485 5.94a2 2 0 0 1 1.455-2.425l1.09-.272a1 1 0 0 1 1.212.727l1.515 6.06a1 1 0 0 1-.727 1.213l-1.09.272a2 2 0 0 1-2.425-1.455z",key:"m7xp4m"}],["path",{d:"m6.158 8.633 1.114 4.456",key:"74o979"}],["path",{d:"m8 21 3.105-6.21",key:"1fvxut"}],["circle",{cx:"12",cy:"13",r:"2",key:"1c1ljs"}]]);function ft(){const t=oe(),{data:r=[]}=Fe(),{showAlert:h,dialogElement:n}=ge();async function x(d){try{await K(`/api/jobs/${d}/cancel`,{method:"POST"}),t.invalidateQueries({queryKey:P.jobs})}catch(S){h("Fehler",S.message)}}const M=r.filter(d=>d.state==="running"||d.state==="queued"),v=r.filter(d=>d.state!=="running"&&d.state!=="queued").slice(-3);return M.length===0&&v.length===0?null:e.jsxs("div",{className:"space-y-3 mc-card p-4",children:[e.jsx("div",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider",children:"Aktive Downloads"}),M.map(d=>e.jsxs("div",{className:"space-y-1.5 p-3 rounded-xl bg-background/20 border border-border/40",children:[e.jsxs("div",{className:"flex justify-between items-center text-xs",children:[e.jsx("span",{className:"font-semibold truncate max-w-[250px]",children:d.label}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-muted-foreground font-mono",children:[d.progress??0,"% • ",ue(d.done_bytes),"/",ue(d.total_bytes),d.eta_s?` • ETA ${Re(d.eta_s)}`:""]}),e.jsx("button",{onClick:()=>x(d.id),className:"text-[10px] text-red-400 hover:text-red-300 font-semibold border border-red-500/25 bg-red-500/5 px-2 py-0.5 rounded transition-all cursor-pointer",children:"Abbrechen"})]})]}),e.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-500",style:{width:`${d.progress??0}%`}})})]},d.id)),v.map(d=>e.jsxs("div",{className:"flex justify-between items-center text-xs text-muted-foreground px-1",children:[e.jsx("span",{className:"truncate",children:d.label}),e.jsx("span",{className:w("font-semibold text-[10px] px-1.5 py-0.5 rounded uppercase font-mono",d.state==="done"?"bg-emerald-500/10 text-emerald-400":"bg-amber-500/10 text-amber-400"),children:d.state})]},d.id)),n]})}const yt=["fast","heavy","heavy_chars"],jt=["coder_lite","coder","coding_escalate_chars"];function vt(){const t=oe(),{data:r,isLoading:h}=Ie(),[n,x]=N.useState(null),[M,v]=N.useState(!1),[d,S]=N.useState(""),[g,z]=N.useState(0);if(N.useEffect(()=>{r!=null&&r.policy&&!n&&x({...r.policy})},[r,n]),h||!r||!n)return e.jsx("div",{className:"mc-card p-5 text-xs text-muted-foreground",children:"Lade Routing-Policy…"});const m=s=>r.fields.find(o=>o.key===s),f=Object.keys(n).some(s=>n[s]!==r.policy[s]),b=(s,o)=>{x(i=>i&&{...i,[s]:o}),S("")},c=s=>b(s,r.defaults[s]);async function L(){if(!n)return;const s={};for(const o of Object.keys(n))n[o]!==r.policy[o]&&(s[o]=n[o]);if(Object.keys(s).length!==0){v(!0),S("");try{const{policy:o}=await Pe(s);x({...o}),t.invalidateQueries({queryKey:P.routingPolicy}),t.invalidateQueries({queryKey:P.routing}),z(Date.now()),setTimeout(()=>z(0),2e3)}catch(o){S(o.message||String(o))}finally{v(!1)}}}function B({k:s}){const o=m(s),i=n[s],G=n[s]===r.defaults[s];return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("label",{className:"text-[10px] font-semibold text-muted-foreground",children:o.label}),!G&&e.jsxs("button",{onClick:()=>c(s),className:"flex items-center gap-0.5 text-[9px] text-muted-foreground/60 hover:text-foreground transition-colors cursor-pointer",title:`Auf Default zurücksetzen (${String(r.defaults[s])||"leer"})`,children:[e.jsx(st,{className:"h-2.5 w-2.5"})," Default"]})]}),o.type==="bool"?e.jsxs("button",{onClick:()=>b(s,!i),className:w("flex h-8 w-full items-center justify-between rounded-lg border px-3 text-[11px] font-semibold transition-all cursor-pointer",i?"border-emerald-500/40 bg-emerald-500/10 text-emerald-300":"border-border/40 bg-background/40 text-muted-foreground"),children:[e.jsx("span",{children:i?"An":"Aus"}),e.jsx("span",{className:w("h-3.5 w-3.5 rounded-full transition-colors",i?"bg-emerald-400":"bg-muted-foreground/40")})]}):o.type==="int"?e.jsx("input",{type:"number",value:i,min:o.min,max:o.max,"aria-label":o.label,onChange:A=>b(s,Number(A.target.value)),className:"h-8 w-full rounded-lg border border-border/40 bg-background/40 px-3 font-mono text-[11px] text-foreground outline-none focus:border-primary/50"}):e.jsx("input",{type:"text",value:i,"aria-label":o.label,spellCheck:!1,placeholder:s==="coder_lite"?"(leer = aus)":"",onChange:A=>b(s,A.target.value),className:"h-8 w-full rounded-lg border border-border/40 bg-background/40 px-3 font-mono text-[11px] text-foreground outline-none focus:border-primary/50"})]})}return e.jsxs("div",{className:"mc-card p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(bt,{className:"h-4.5 w-4.5 text-primary"}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-foreground",children:"Lane-Routing & Policy"}),e.jsx("span",{className:"text-[9px] font-mono px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-300 border border-emerald-500/20",children:"hot-reload"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d&&e.jsx("span",{className:"text-[10px] text-red-400 max-w-[280px] truncate",title:d,children:d}),g>0&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-emerald-400",children:[e.jsx(Y,{className:"h-3.5 w-3.5"})," gespeichert"]}),e.jsxs("button",{onClick:L,disabled:!f||M,className:w("h-8 px-4 rounded-lg text-[10px] font-bold uppercase tracking-wide transition-all flex items-center gap-1.5",f&&!M?"bg-primary text-primary-foreground hover:opacity-90 cursor-pointer shadow-md shadow-primary/10":"bg-background/40 text-muted-foreground/50 border border-border/40 cursor-not-allowed"),children:[M?e.jsx(Oe,{className:"h-3.5 w-3.5 animate-spin"}):null,"Speichern"]})]})]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground/70 leading-relaxed -mt-1",children:["Welches echte Modell hinter den virtuellen Lanes ",e.jsx("code",{className:"text-cyan-300",children:"chat"})," und"," ",e.jsx("code",{className:"text-cyan-300",children:"coding"})," steckt. Änderungen greifen sofort (kein Neustart). Die Keyword-Heuristiken bleiben im Code."]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-border/40 bg-background/25 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 pb-2",children:[e.jsx(mt,{className:"h-4 w-4 text-teal-400"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider text-foreground",children:"chat"}),e.jsx("span",{className:"text-[9px] text-muted-foreground/60 font-mono",children:"(= auto)"})]}),yt.map(s=>e.jsx(B,{k:s},s))]}),e.jsxs("div",{className:"rounded-xl border border-border/40 bg-background/25 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 pb-2",children:[e.jsx(rt,{className:"h-4 w-4 text-indigo-400"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider text-foreground",children:"coding"}),e.jsx("span",{className:"text-[9px] text-muted-foreground/60 font-mono",children:"(agentisch → immer Coder)"})]}),jt.map(s=>e.jsx(B,{k:s},s))]})]}),e.jsx("div",{className:"rounded-xl border border-border/40 bg-background/25 p-4",children:e.jsx("div",{className:"max-w-xs",children:e.jsx(B,{k:"fast_no_think"})})})]})}const je=[{role:"hermes",label:"Lucys Hirn",short:"Hirn",icon:le,desc:"Lucys Alltags-Verstand — denkt und redet mit dir. Immer bereit.",tone:"bg-indigo-500/15 text-indigo-400 border-indigo-500/25",protected:!0},{role:"embed",label:"Lucys Gedächtnis",short:"Gedächtnis",icon:Te,desc:"Merkt sich Wichtiges und findet es später wieder.",tone:"bg-emerald-500/15 text-emerald-400 border-emerald-500/25",protected:!0},{role:"reranker",label:"Gedächtnis-Sortierer",short:"Sortierer",icon:xt,desc:"Ordnet gefundene Erinnerungen nach echter Relevanz — die Feinsortierung hinter dem Gedächtnis.",tone:"bg-lime-500/15 text-lime-400 border-lime-500/25"},{role:"vision",label:"Lucys Augen",short:"Augen",icon:Be,desc:"Sieht Bilder und Screenshots und beschreibt, was drauf ist.",tone:"bg-pink-500/15 text-pink-400 border-pink-500/25"},{role:"heavy",label:"Großes Hirn",short:"Groß",icon:dt,desc:"Das schwere Geschütz — wird für besonders knifflige Fragen dazugeholt.",tone:"bg-amber-500/15 text-amber-400 border-amber-500/25"},{role:"coder-lite",label:"Programmierer (schnell)",short:"Code schnell",icon:be,desc:"Schnelles Programmieren im Alltag.",tone:"bg-violet-500/15 text-violet-400 border-violet-500/25"},{role:"coder",label:"Programmierer",short:"Code",icon:be,desc:"Baut und plant. Der Kopf der Coding-Mannschaft — er hält den Faden und verteilt Zuarbeit.",tone:"bg-fuchsia-500/15 text-fuchsia-400 border-fuchsia-500/25",protected:!0},{role:"scout",label:"Späher",short:"Späher",icon:gt,desc:"Schneller erster Blick und grobe Einschätzung.",tone:"bg-teal-500/15 text-teal-400 border-teal-500/25"},{role:"kritiker",label:"Kritiker",short:"Kritiker",icon:qe,desc:"Liest dem Programmierer nach jeder Etappe gegen — bewusst aus einer FREMDEN Modellfamilie (Mistral statt Qwen), damit er andere blinde Flecken hat.",tone:"bg-cyan-500/15 text-cyan-400 border-cyan-500/25"}];je.map(t=>t.role);const Ne=Object.fromEntries(je.map(t=>[t.role,t])),ke=t=>({role:t||"?",label:t||"unbekannt",short:t||"?",icon:le,desc:"Rolle ohne hinterlegten Klartext-Namen.",tone:"bg-slate-500/15 text-slate-300 border-slate-500/25"}),Nt={fast:"hermes",coder_lite:"coder-lite"};function F(t){return t&&(Ne[t]||Ne[Nt[t]])||ke(t)}function he({role:t,dense:r=!1,className:h}){const n=F(t),x=n.icon;return e.jsxs("span",{className:w("inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-semibold border tracking-wide",n.tone,h),title:`${n.desc} (${n.role})`,children:[e.jsx(x,{className:"h-3 w-3 shrink-0","aria-hidden":"true"}),r?n.short:n.label]})}function kt({fit:t}){const r={perfect:"bg-emerald-500/15 text-emerald-400 border border-emerald-500/20",marginal:"bg-amber-500/15 text-amber-400 border border-amber-500/20",too_tight:"bg-red-500/15 text-red-400 border border-red-500/20"}[t.level];return e.jsxs("span",{className:w("rounded px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider font-mono",r),children:[t.text," • ",t.req_gb," GB RAM"]})}function Ke(t){const r=t.toLowerCase();return r.includes("qwen")?{name:"Qwen",color:"bg-purple-500/20 text-purple-300 border-purple-500/30",initial:"Q"}:r.includes("gemma")?{name:"Gemma",color:"bg-blue-500/20 text-blue-300 border-blue-500/30",initial:"G"}:r.includes("llama")?{name:"Llama",color:"bg-red-500/20 text-red-300 border-red-500/30",initial:"🦙"}:r.includes("mistral")||r.includes("mixtral")?{name:"Mistral",color:"bg-orange-500/20 text-orange-300 border-orange-500/30",initial:"M"}:r.includes("deepseek")?{name:"DeepSeek",color:"bg-cyan-500/20 text-cyan-300 border-cyan-500/30",initial:"D"}:r.includes("hermes")||r.includes("nous")?{name:"Hermes",color:"bg-amber-500/20 text-amber-300 border-amber-500/30",initial:"H"}:r.includes("phi")?{name:"Phi",color:"bg-emerald-500/20 text-emerald-300 border-emerald-500/30",initial:"Φ"}:{name:"Other",color:"bg-slate-500/20 text-slate-300 border-slate-500/30",initial:"AI"}}function wt(){var te,H,$;const t=oe(),{data:r}=de(),{data:h}=Ge(),{data:n}=$e(),{data:x}=He(),{showAlert:M,dialogElement:v}=ge(),[d,S]=N.useState(!1),[g,z]=N.useState(!1),m=(r==null?void 0:r.models)??[],f=(r==null?void 0:r.running)??[],b=(te=h==null?void 0:h.groups)==null?void 0:te.brains,c=(b==null?void 0:b.members)??[],L=p=>m.find(_=>_.name===p),B=p=>{var _;return((_=p.split("/").pop())==null?void 0:_.replace(/\.gguf$/i,""))||p},s=c.map(L).filter(Boolean),o=1024**3,i=x==null?void 0:x.budget,G=s.reduce((p,_)=>p+(_.size_bytes||0),0)/o,A=((H=n==null?void 0:n.gpu)==null?void 0:H.gtt_total)||(($=n==null?void 0:n.gpu)==null?void 0:$.vram_total)||0,C=(i==null?void 0:i.gtt_gb)||(A?A/o:0),k=(i==null?void 0:i.warm_projected_gb)??G,R=C>0?Math.min(100,k/C*100):0,E=m.filter(p=>!c.includes(p.name)&&!p.incomplete);async function I(p){z(!0);try{await Ue("brains",p,(b==null?void 0:b.swap)??!1,(b==null?void 0:b.persist)??!0),t.invalidateQueries({queryKey:P.groups}),t.invalidateQueries({queryKey:P.models}),t.invalidateQueries({queryKey:P.hermesBrain})}catch(_){M("Fehler",`Immer-bereit-Set konnte nicht geändert werden: ${(_==null?void 0:_.message)||_}`)}finally{z(!1)}}function T(p){const _=L(p);if(_&&F(_.role).protected){M("Geschützt",`„${F(_.role).label}" ist lebenswichtig und bleibt immer bereit.`);return}I(c.filter(Q=>Q!==p))}function W(p){S(!1),I([...c,p])}return b?e.jsxs("div",{className:"mc-card p-5 space-y-4",children:[e.jsx(we,{}),e.jsxs("div",{className:"space-y-1.5",children:[s.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Noch keine Modelle im Set."}),s.map(p=>{const _=f.includes(p.name),Q=F(p.role).protected;return e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-xl border border-border/30 bg-background/20 p-2.5",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:w("h-2 w-2 shrink-0 rounded-full ring-2 ring-black/40",_?"bg-emerald-500 animate-pulse":"bg-muted-foreground/40"),title:_?"Gerade warm (bereit)":"Reserviert — lädt bei Bedarf sofort"}),p.role&&e.jsx(he,{role:p.role,dense:!0,className:"shrink-0"}),e.jsx("span",{className:"truncate font-mono text-xs font-semibold text-foreground",title:p.name,children:B(p.name)}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground/70",children:ee(p.size_bytes)})]}),Q?e.jsx("span",{className:"shrink-0 text-[10px] font-semibold text-muted-foreground",title:"Lebenswichtig — bleibt immer im Set.",children:"🔒"}):e.jsx("button",{onClick:()=>T(p.name),disabled:g,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border border-border/40 text-muted-foreground transition-colors hover:bg-red-500/5 hover:text-red-400 cursor-pointer disabled:opacity-50",title:"Aus dem Immer-bereit-Set nehmen (lädt dann nur noch bei Bedarf)",children:e.jsx(pe,{className:"h-3.5 w-3.5"})})]},p.name)})]}),e.jsxs("button",{onClick:()=>S(!0),disabled:g||E.length===0,className:"flex h-8 w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-border/50 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground transition-colors hover:border-primary/40 hover:text-primary cursor-pointer disabled:opacity-50",children:[e.jsx(Qe,{className:"h-3.5 w-3.5"})," Modell dauerhaft bereithalten"]}),e.jsxs("div",{className:"rounded-xl border border-border/30 bg-background/20 p-3",children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between text-[11px]",children:[e.jsxs("span",{className:"flex items-center gap-1.5 font-semibold uppercase tracking-wider text-muted-foreground",title:"Modellgewichte + KV-Cache, berechnet aus den echten Architektur-Daten jedes Modells (Layer × KV-Köpfe × Kontext) und seiner KV-Quantisierung. So viel legt llama.cpp beim Laden wirklich für den eingestellten Kontext an — kein Aufschlag mehr.",children:[e.jsx(fe,{className:"h-3.5 w-3.5"})," Reserviert fürs Set"]}),e.jsxs("span",{className:"font-mono font-bold text-foreground",children:[k.toFixed(1),C>0?` / ${C.toFixed(0)}`:""," GB"]})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full border border-border/30 bg-background/50",children:e.jsx("div",{className:w("h-full rounded-full transition-all duration-500",R>=85?"bg-red-500":R>=65?"bg-amber-500":"bg-teal-500"),style:{width:`${R}%`}})}),i&&!i.fits&&e.jsxs("p",{className:"mt-2 flex items-start gap-1.5 text-[11px] text-amber-400",children:[e.jsx(re,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsxs("span",{children:["Zusammen mit dem größten Gelegenheits-Modell (~",i.largest_ondemand_gb," GB) wird der Speicher knapp. Das Set bleibt dabei immer geladen — wird es wirklich eng, schlägt das Laden des großen Modells fehl (es wartet dann, statt das Set zu verdrängen)."]})]}),i&&i.fits&&e.jsxs("p",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-emerald-400",children:[e.jsx(Y,{className:"h-3.5 w-3.5 shrink-0"})," Passt auch neben dem größten Gelegenheits-Modell — nichts wird verdrängt."]})]}),d&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4 backdrop-blur-sm",role:"dialog","aria-modal":"true","aria-label":"Modell zum Immer-bereit-Set hinzufügen",children:e.jsxs("div",{className:"w-full max-w-md space-y-3 rounded-2xl border border-border/80 bg-card p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/20 pb-2",children:[e.jsx("h3",{className:"text-xs font-bold uppercase tracking-wider text-primary",children:"Dauerhaft bereithalten"}),e.jsx("button",{onClick:()=>S(!1),className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground cursor-pointer",children:e.jsx(pe,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Wähle ein Modell, das ohne Ladezeit bereitstehen soll:"}),e.jsx("div",{className:"max-h-60 space-y-1.5 overflow-y-auto pr-1",children:E.map(p=>e.jsxs("button",{onClick:()=>W(p.name),className:"flex w-full items-center justify-between gap-2 rounded-lg border border-border/30 bg-background/20 px-3 py-2.5 text-left transition-colors hover:bg-accent cursor-pointer",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[p.role&&e.jsx(he,{role:p.role,dense:!0,className:"shrink-0"}),e.jsx("span",{className:"truncate font-mono text-xs font-semibold text-foreground",children:B(p.name)})]}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground/70",children:ee(p.size_bytes)})]},p.name))})]})}),v]}):e.jsxs("div",{className:"mc-card p-5",children:[e.jsx(we,{}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Es gibt noch kein Immer-bereit-Set. Es entsteht automatisch, sobald Lucys Hirn zugewiesen ist."}),v]})}function we(){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{className:"h-4.5 w-4.5 text-primary"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold uppercase tracking-wide text-foreground",children:"Immer-bereit-Set"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Diese Modelle hält Lucy immer bereit — sie antworten ohne Ladezeit."})]})]})}function J({children:t,tone:r="muted"}){const h={muted:"bg-muted text-muted-foreground",primary:"bg-primary/15 text-primary",warn:"bg-amber-500/15 text-amber-500"};return e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[11px] font-medium ${h[r]}`,children:t})}function Mt({caps:t}){return t?e.jsxs("span",{className:"inline-flex flex-wrap gap-1",children:[t.coder&&e.jsx(J,{children:"💻 Code"}),t.vision&&e.jsx(J,{children:"👁 Bild"}),t.reasoning&&e.jsx(J,{children:"🧠 Reason"}),t.moe&&e.jsxs(J,{tone:"primary",children:["🧩 MoE",t.active_b?`·${t.active_b}b`:""]}),t.tools==="yes"&&e.jsx(J,{tone:"primary",children:"🛠 Tools"}),t.tools==="likely"&&e.jsx(J,{tone:"warn",children:"🛠 Tools?"}),t.embedding&&e.jsx(J,{children:"🔢 Embed"})]}):null}function St({model:t,onClose:r,onChanged:h}){var L,B;const{data:n,isLoading:x}=Ve(t.gguf_path),[M,v]=N.useState(null),[d,S]=N.useState(""),g=n==null?void 0:n.target_vocab,z=(n==null?void 0:n.drafts)??[],m=z.filter(s=>s.compatible===!0),f=t.spec_draft_model;async function b(s){v(s??"__clear__"),S("");try{await K(`/api/models/${encodeURIComponent(t.name)}/draft`,{method:"POST",body:JSON.stringify({draft_path:s})}),h(),r()}catch(o){S(String((o==null?void 0:o.message)||o)),v(null)}}const c=s=>{var o;return s?`${s.pre??"?"} · ${((o=s.n_vocab)==null?void 0:o.toLocaleString())??"?"} Tokens`:"—"};return e.jsx("div",{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-sm flex items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-lg rounded-2xl border border-border/80 bg-card p-6 shadow-2xl space-y-4 animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/20 pb-2",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-primary flex items-center gap-2",children:[e.jsx(ie,{className:"h-4 w-4"})," Speculative Draft"]}),e.jsx("button",{onClick:r,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground cursor-pointer",children:e.jsx(pe,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"text-xs text-muted-foreground leading-relaxed",children:['Beschleunigt die Token-Generierung mit einem kleinen "Draft"-Modell. Voraussetzung: der Draft muss den ',e.jsx("strong",{className:"text-foreground",children:"exakt gleichen Tokenizer (Vocab)"})," haben wie das Modell — sonst lehnt llama.cpp es ab."]}),e.jsxs("div",{className:"rounded-lg border border-border/40 bg-background/30 px-3 py-2 text-[11px] font-mono flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:(L=t.name.split("/").pop())==null?void 0:L.replace(/\.gguf$/i,"")}),e.jsxs("span",{className:"text-foreground",children:["Vocab: ",c(g)]})]}),t.spec_active&&f&&e.jsxs("div",{className:"rounded-lg border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-[11px] text-emerald-400 font-mono flex items-center gap-1.5 truncate",children:[e.jsx(Y,{className:"h-3.5 w-3.5 shrink-0"})," Aktiv: ",f]}),e.jsx("button",{onClick:()=>b(null),disabled:M!==null,className:"h-6 px-2.5 rounded border border-amber-500/30 bg-amber-500/5 hover:bg-amber-500/10 text-amber-400 text-[9px] font-bold uppercase shrink-0 cursor-pointer disabled:opacity-50",children:"Deaktivieren"})]}),!(n!=null&&n.target_exists)&&e.jsxs("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-[11px] text-amber-400 flex items-center gap-2",children:[e.jsx(re,{className:"h-3.5 w-3.5 shrink-0"}),"Modell-GGUF noch nicht vorhanden — Spec-Draft ist nach dem Download konfigurierbar."]}),e.jsx("div",{className:"space-y-1.5 max-h-64 overflow-y-auto pr-1",children:x?e.jsx("div",{className:"text-xs text-muted-foreground py-6 text-center",children:"Prüfe Vocab-Kompatibilität…"}):z.length===0?e.jsxs("div",{className:"text-[11px] text-muted-foreground border border-dashed border-border/50 rounded-lg p-4 text-center",children:["Keine Draft-Modelle in ",e.jsx("code",{className:"font-mono",children:"/srv/models/drafts"}),". Lade ein kleines same-family-Modell (z.B. Qwen3-0.6B) und lege es dort ab."]}):z.map(s=>{var G,A;const o=s.filename===f,i=s.compatible===!0;return e.jsxs("div",{className:w("rounded-lg border px-3 py-2 flex items-center justify-between gap-2 text-left",i?"border-border/40 bg-background/20":"border-border/20 bg-background/10 opacity-60",o&&"border-primary/40 bg-primary/10"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-[11px] font-mono font-semibold text-foreground truncate flex items-center gap-1.5",children:[s.filename,s.mtp&&e.jsx("span",{className:"shrink-0 rounded bg-indigo-500/15 px-1.5 py-0.5 text-[8px] font-bold uppercase tracking-wider text-indigo-400 border border-indigo-500/25",title:"MTP-Kopf (Multi-Token-Prediction) — by-construction vocab-identisch, höchste Akzeptanzrate",children:"MTP"})]}),e.jsxs("div",{className:"text-[9px] text-muted-foreground font-mono",children:[ee(s.size_bytes)," · Vocab: ",c(s.vocab)]})]}),i?o?e.jsxs("span",{className:"text-[9px] font-bold uppercase text-primary flex items-center gap-1 shrink-0",children:[e.jsx(Y,{className:"h-3.5 w-3.5"})," Aktiv"]}):e.jsx("button",{onClick:()=>b(s.path),disabled:M!==null,className:"h-7 px-3 rounded-lg border border-emerald-500/30 bg-emerald-500/5 hover:bg-emerald-500/15 text-emerald-400 text-[9px] font-bold uppercase shrink-0 cursor-pointer disabled:opacity-50",children:"Aktivieren"}):e.jsxs("span",{className:"text-[9px] font-bold uppercase text-amber-400/80 flex items-center gap-1 shrink-0",title:s.compatible===!1?`Inkompatibel: Tokenizer/Vocab weicht ab (Draft ${(G=s.vocab)==null?void 0:G.pre}/${(A=s.vocab)==null?void 0:A.n_vocab} ≠ Modell ${g==null?void 0:g.pre}/${g==null?void 0:g.n_vocab}).`:"Kompatibilität nicht prüfbar (Datei fehlt).",children:[e.jsx(re,{className:"h-3.5 w-3.5"})," ",s.compatible===!1?"Vocab ≠":"n/a"]})]},s.path)})}),!x&&(n==null?void 0:n.target_exists)&&z.length>0&&m.length===0&&e.jsxs("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-[11px] text-amber-400 leading-relaxed",children:["Kein vocab-kompatibler Draft verfügbar — Speculative Decoding ist für dieses Modell nicht möglich. Es braucht einen Draft mit identischem Tokenizer (pre=",e.jsx("span",{className:"font-mono",children:g==null?void 0:g.pre}),", n_vocab=",e.jsx("span",{className:"font-mono",children:(B=g==null?void 0:g.n_vocab)==null?void 0:B.toLocaleString()}),")."]}),d&&e.jsx("div",{className:"text-[10px] text-red-400 font-mono",children:d})]})})}const Me={hermes:{bar:"bg-indigo-500",dot:"bg-indigo-500",text:"text-indigo-400"},embed:{bar:"bg-emerald-500",dot:"bg-emerald-500",text:"text-emerald-400"},vision:{bar:"bg-pink-500",dot:"bg-pink-500",text:"text-pink-400"},heavy:{bar:"bg-amber-500",dot:"bg-amber-500",text:"text-amber-400"},"coder-lite":{bar:"bg-violet-500",dot:"bg-violet-500",text:"text-violet-400"},coder:{bar:"bg-fuchsia-500",dot:"bg-fuchsia-500",text:"text-fuchsia-400"},scout:{bar:"bg-teal-500",dot:"bg-teal-500",text:"text-teal-400"},kritiker:{bar:"bg-cyan-500",dot:"bg-cyan-500",text:"text-cyan-400"},reranker:{bar:"bg-lime-500",dot:"bg-lime-500",text:"text-lime-400"}},Ct={fast:"hermes",coder_lite:"coder-lite"},Se={bar:"bg-slate-400",dot:"bg-slate-400",text:"text-slate-300"};function ae(t){return t&&(Me[t]||Me[Ct[t]])||Se}const Ce=1024**3,_e=t=>{var r;return((r=t.split("/").pop())==null?void 0:r.replace(/\.gguf$/i,""))??t};function _t({running:t,capacityBytes:r,realUsedBytes:h,selected:n,onSelect:x}){const M=r>2*Ce?r:124*Ce,v=t.reduce((m,f)=>m+(f.size_bytes||0),0),d=Math.max(0,h-v),S=Math.max(0,M-Math.max(v,h)),g=S/M*100,z=d/M*100;return e.jsxs("div",{className:"mc-card p-5",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-end justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Modell-Speicher (GPU-Pool)"}),e.jsxs("div",{className:"font-space text-xl font-bold tracking-tight text-foreground",children:[V(M)," GB ",e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"gesamt"})]})]})]}),e.jsxs("div",{className:"text-right text-[11px] font-mono text-muted-foreground",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-bold text-foreground",children:[V(v)," GB"]})," Modell-Gewichte"]}),d>0&&e.jsxs("div",{children:[V(d)," GB KV-Cache & Betrieb"]}),e.jsxs("div",{className:"text-emerald-400",children:[V(S)," GB frei"]})]})]}),e.jsx("div",{className:"flex h-12 w-full overflow-hidden rounded-xl border border-border/40 bg-background/50 p-1",children:t.length===0?e.jsx("div",{className:"flex w-full items-center justify-center text-[11px] italic text-muted-foreground/60",children:"Kein Modell geladen — Auto-Swap holt bei Anfrage automatisch das passende."}):e.jsxs(e.Fragment,{children:[t.map(m=>{const f=(m.size_bytes||0)/M*100,b=ae(m.role),c=n===m.name;return e.jsxs("button",{onClick:()=>x==null?void 0:x(m.name),style:{width:`${f}%`},title:`${F(m.role).label} · ${_e(m.name)} · ${ee(m.size_bytes)}`,className:w("group flex h-full min-w-[2.5rem] shrink-0 flex-col justify-center gap-0.5 rounded-lg px-2 text-left text-white transition-all",b.bar,c?"ring-2 ring-white/70":"opacity-90 hover:opacity-100"),children:[e.jsx("span",{className:"truncate font-space text-[10px] font-bold leading-tight tracking-wide",children:F(m.role).short}),e.jsx("span",{className:"truncate font-mono text-[9px] leading-tight opacity-85",children:ee(m.size_bytes)})]},m.name)}),z>1.5&&e.jsx("div",{style:{width:`${z}%`},className:"flex h-full min-w-[2rem] items-center justify-center rounded-lg border border-dashed border-border/60 bg-background/40 text-[9px] font-mono text-muted-foreground/70",title:`${V(d)} GB KV-Cache & Betrieb (reale Belegung über den Modell-Gewichten)`,children:"KV"}),g>1.5&&e.jsx("div",{style:{width:`${g}%`},className:"flex h-full min-w-[2rem] items-center justify-center rounded-lg text-[9px] font-mono text-muted-foreground/50",title:`${V(S)} GB frei`,children:"frei"})]})}),t.length>0&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-x-4 gap-y-1.5",children:[t.map(m=>{const f=ae(m.role);return e.jsxs("button",{onClick:()=>x==null?void 0:x(m.name),className:"flex items-center gap-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:[e.jsx("span",{className:w("h-2.5 w-2.5 rounded-sm",f.dot)}),e.jsx("span",{className:w("font-semibold",f.text),children:F(m.role).short}),e.jsx("span",{className:"font-mono text-muted-foreground/70",children:_e(m.name)})]},m.name)}),d>0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground/60",title:"Reale Belegung über den Modell-Gewichten (Kontext-Speicher der laufenden Modelle)",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-dashed border-border/60 bg-background/40"})," KV-Cache & Betrieb · ",V(d)," GB"]}),e.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground/60",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-border/50 bg-background/50"})," frei · ",V(S)," GB"]})]})]})}const Le=1024**3,X=t=>{var r;return((r=t.split("/").pop())==null?void 0:r.replace(/\.gguf$/i,""))??t};function Lt(){var a,y,D,U;const t=oe(),{data:r,isLoading:h,error:n}=de(),{data:x}=$e(),{data:M}=Ge(),{showAlert:v,showConfirm:d,showPrompt:S,dialogElement:g}=ge(),z=We(),m=(r==null?void 0:r.models)??[],f=(r==null?void 0:r.running)??[],b=l=>!!F(l).protected,c=(a=M==null?void 0:M.groups)==null?void 0:a.brains,L=(c==null?void 0:c.members)??[],B=l=>L.includes(l),[s,o]=N.useState(null),[i,G]=N.useState(""),[A,C]=N.useState("all"),[k,R]=N.useState(null),E=()=>{t.invalidateQueries({queryKey:P.models}),t.invalidateQueries({queryKey:P.routing}),t.invalidateQueries({queryKey:P.groups})},I=m.filter(l=>f.includes(l.name)),T=((y=x==null?void 0:x.gpu)==null?void 0:y.gtt_total)||((D=x==null?void 0:x.gpu)==null?void 0:D.vram_total)||0,W=((U=x==null?void 0:x.gpu)==null?void 0:U.gtt_used)||0,te=T>2*Le?T:124*Le,H=N.useMemo(()=>{const l=i.trim().toLowerCase();return m.filter(u=>A==="in_use"?!!u.role||f.includes(u.name):!0).filter(u=>l?u.name.toLowerCase().includes(l):!0).sort((u,j)=>{const O=f.includes(u.name)?0:1,Z=f.includes(j.name)?0:1;return O!==Z?O-Z:X(u.name).localeCompare(X(j.name))})},[m,f,A,i]),$=m.find(l=>l.name===s)??null;async function p(l){try{await K(`/api/models/${encodeURIComponent(l)}/load`,{method:"POST"}),E()}catch(u){v("Fehler",`Laden fehlgeschlagen: ${u.message||u}`)}}async function _(l){const u=L.some(j=>f.includes(j));if(c&&u&&!B(l)){const j=L.filter(O=>f.includes(O)).map(X).join(", ");d("Verdrängt das Hirn?",`„${X(l)}" ist nicht ko-resident. Beim Laden wirft es das warme Hirn (${j}) raus — Lucy verliert Hirn bzw. Augen. Trotzdem exklusiv laden?`,()=>p(l));return}p(l)}async function Q(l){const u=m.find(j=>j.name===l);if(u&&b(u.role)){v("Geschützt",`„${F(u.role).label}" ist lebenswichtig und bleibt geladen.`);return}try{await K(`/api/models/${encodeURIComponent(l)}/unload`,{method:"POST"}),E()}catch(j){v("Fehler",`Entladen fehlgeschlagen: ${j.message||j}`)}}async function ce(l,u){try{const j=await K(`/api/models/${encodeURIComponent(u)}/role`,{method:"POST",body:JSON.stringify({role:l||null})});E(),j!=null&&j.warning&&v("Rolle gesetzt — Hinweis",j.warning)}catch(j){v("Fehler",`Rolle zuweisen fehlgeschlagen: ${j.message||j}`)}}async function xe(l,u){let j=null;try{j=await K(`/api/models/${encodeURIComponent(l)}/ctx/auto`)}catch{}const O=j?`Optimal für dein Setup: ${(j.ctx/1024).toFixed(0)}k (${j.ctx}). »Auto« trägt diesen Wert ein.`:"Gib die gewünschte Kontextlänge in Tokens an:";S("Kontextlänge anpassen",O,String(u||32768),async Z=>{if(Z)try{await K(`/api/models/${encodeURIComponent(l)}/ctx`,{method:"POST",body:JSON.stringify({ctx:parseInt(Z,10)})}),E()}catch(ve){v("Fehler",`Kontext setzen fehlgeschlagen: ${ve.message||ve}`)}},void 0,j?{autoValue:String(j.ctx),autoLabel:`Auto (${(j.ctx/1024).toFixed(0)}k)`}:void 0)}async function me(l){const u=m.find(j=>j.name===l);if(u&&b(u.role)){v("Geschützt",`„${F(u.role).label}" kann nicht gelöscht werden. Weise die Rolle zuerst einem anderen Modell zu.`);return}d("Modell löschen?",`„${X(l)}" und alle GGUF-Dateien unwiderruflich von der Box löschen?`,async()=>{try{await K(`/api/models/${encodeURIComponent(l)}`,{method:"DELETE"}),s===l&&o(null),E()}catch(j){v("Fehler",`Löschen fehlgeschlagen: ${j.message||j}`)}})}return h?e.jsx("div",{className:"py-16 text-center text-xs text-muted-foreground",children:"Werkbank wird geladen …"}):n?e.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 p-4 text-xs text-red-400",children:["Gateway oder Engine nicht erreichbar (",String(n),")."]}):e.jsxs("div",{className:"space-y-5",children:[e.jsx(_t,{running:I,capacityBytes:te,realUsedBytes:W,selected:s,onSelect:o}),e.jsxs("div",{className:"grid gap-5 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.3fr)]",children:[e.jsxs("div",{className:"mc-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ye,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground/60"}),e.jsx("input",{value:i,onChange:l=>G(l.target.value),placeholder:"Modell suchen …",className:"h-8 w-full rounded-lg border border-border/40 bg-background/40 pl-8 pr-2 text-xs text-foreground placeholder:text-muted-foreground/50 focus:border-primary/50 focus:outline-none"})]}),e.jsx("div",{className:"flex rounded-lg border border-border/40 bg-background/30 p-0.5",children:["all","in_use"].map(l=>e.jsx("button",{onClick:()=>C(l),className:w("rounded-md px-2 py-1 text-[9px] font-bold uppercase transition-all cursor-pointer",A===l?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"),children:l==="all"?"Alle":"In Benutzung"},l))})]}),e.jsx("div",{className:"max-h-[60vh] space-y-1.5 overflow-y-auto scrollbar-thin pr-1",children:H.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-border/50 p-8 text-center text-xs text-muted-foreground",children:"Keine Modelle."}):H.map(l=>{const u=f.includes(l.name),j=s===l.name,O=Ke(l.name),Z=ae(l.role);return e.jsxs("button",{onClick:()=>o(l.name),className:w("flex w-full items-center gap-2.5 rounded-xl border p-2.5 text-left transition-all cursor-pointer",j?"border-primary/60 bg-primary/10":"border-border/40 bg-background/20 hover:border-primary/30 hover:bg-background/40"),children:[e.jsx("span",{className:w("flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-[10px] font-bold",O.color),children:O.initial}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-mono text-xs font-semibold text-foreground",children:X(l.name)}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-1.5",children:[l.role&&e.jsx("span",{className:w("h-2 w-2 rounded-sm",Z.dot)}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:l.role?F(l.role).short:"keine Rolle"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground/50",children:["· ",ee(l.size_bytes)]})]})]}),u?e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[9px] font-bold uppercase text-emerald-400",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse"}),"warm"]}):l.incomplete?e.jsx("span",{className:"shrink-0 text-[9px] font-bold uppercase text-amber-400",children:"⚠ fehlt"}):e.jsx("span",{className:"shrink-0 text-[9px] font-semibold uppercase text-muted-foreground/50",children:"bereit"})]},l.name)})})]}),e.jsx("div",{className:"mc-card p-5",children:$?e.jsx(zt,{m:$,warm:f.includes($.name),expert:z,protectedRole:b($.role),coresident:B($.name),onLoad:()=>_($.name),onUnload:()=>Q($.name),onRole:l=>ce(l,$.name),onCtx:()=>xe($.name,$.ctx),onSpec:()=>R($),onDelete:()=>me($.name)}):e.jsxs("div",{className:"flex h-full min-h-[16rem] flex-col items-center justify-center gap-2 text-center text-muted-foreground",children:[e.jsx(Ze,{className:"h-8 w-8 opacity-40"}),e.jsx("p",{className:"text-sm font-semibold",children:"Links ein Modell wählen"}),e.jsx("p",{className:"text-xs",children:"Dann verwaltest du es hier — laden, Rolle, Kontext, löschen."})]})})]}),k&&e.jsx(St,{model:k,onClose:()=>R(null),onChanged:E}),g]})}function zt({m:t,warm:r,expert:h,protectedRole:n,coresident:x,onLoad:M,onUnload:v,onRole:d,onCtx:S,onSpec:g,onDelete:z}){const m=Ke(t.name),f=r&&n;return e.jsxs("div",{className:"flex h-full flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:w("flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border text-sm font-bold",m.color),children:m.initial}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h2",{className:"break-all font-mono text-sm font-bold text-foreground",children:X(t.name)}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[t.role?e.jsx(he,{role:t.role}):e.jsx("span",{className:"rounded border border-dashed border-border/50 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:"keine Rolle"}),n&&e.jsxs("span",{className:"rounded bg-background/40 px-1.5 py-0.5 text-[10px] text-muted-foreground",title:"Lebenswichtig — geschützt",children:[e.jsx(nt,{className:"mr-0.5 inline h-3 w-3"}),"geschützt"]}),x&&e.jsxs("span",{className:"rounded border border-fuchsia-500/30 bg-fuchsia-500/10 px-1.5 py-0.5 text-[10px] font-bold uppercase text-fuchsia-300",children:[e.jsx(le,{className:"mr-0.5 inline h-3 w-3"}),"Ko-resident"]}),r&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] font-bold uppercase text-emerald-400",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse"}),"warm"]})]})]})]}),e.jsxs("button",{onClick:r?v:M,disabled:t.incomplete&&!r||f,className:w("flex h-11 w-full items-center justify-center gap-2 rounded-xl border text-sm font-bold transition-all cursor-pointer disabled:cursor-not-allowed disabled:opacity-50",r?"border-amber-500/40 bg-amber-500/10 text-amber-300 hover:bg-amber-500/20":"border-primary/40 bg-primary/10 text-primary hover:bg-primary/20"),title:f?`„${F(t.role).label}" bleibt geladen (geschützt).`:void 0,children:[r?e.jsx(pt,{className:"h-4 w-4"}):e.jsx(Je,{className:"h-4 w-4"}),f?"🔒 bleibt geladen":r?"Entladen":"Ins Warm-Set laden"]}),e.jsxs("div",{className:"rounded-xl border border-border/30 bg-background/20 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:[e.jsx("span",{children:"Rolle"}),n&&e.jsx("span",{className:"normal-case font-medium tracking-normal text-muted-foreground/70",children:"🔒 lebenswichtig — zum Tausch die Rolle woanders zuweisen"})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx(ze,{active:!t.role,onClick:()=>d(""),dot:"bg-slate-400",label:"keine",disabled:n}),je.map(b=>e.jsx(ze,{active:t.role===b.role,onClick:()=>d(b.role),dot:ae(b.role).dot,label:b.short,disabled:n&&t.role!==b.role},b.role))]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsx(At,{icon:fe,label:"Größe",value:ee(t.size_bytes)}),e.jsxs("button",{onClick:S,className:"group flex items-center gap-2 rounded-lg border border-border/30 bg-background/20 p-2.5 text-left transition-colors hover:border-primary/40 cursor-pointer",children:[e.jsx(ut,{className:"h-4 w-4 text-primary/80"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:"Kontext · ändern"}),e.jsx("div",{className:"font-semibold text-foreground",children:Xe(t.ctx)})]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border/30 bg-background/20 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Beschleuniger"}),h&&e.jsxs("button",{onClick:g,className:w("flex h-6 items-center gap-1 rounded-lg border px-2 text-[9px] font-bold uppercase transition-colors cursor-pointer",t.spec_active?"border-emerald-500/30 text-emerald-400 hover:bg-emerald-500/10":t.spec_draft_model?"border-amber-500/30 text-amber-400 hover:bg-amber-500/10":"border-border/40 text-muted-foreground hover:bg-accent"),children:[e.jsx(ie,{className:"h-3 w-3"})," Spec"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.spec_active&&e.jsx(se,{tone:"emerald",label:"Spec-Decoding aktiv"}),!t.spec_active&&t.spec_draft_model&&e.jsx(se,{tone:"amber",label:"Spec inaktiv"}),t.prompt_cache&&e.jsx(se,{tone:"cyan",label:"Prompt-Cache"}),t.parallel_slots>1&&e.jsx(se,{tone:"violet",label:`${t.parallel_slots} Slots`}),!t.spec_active&&!t.spec_draft_model&&!t.prompt_cache&&t.parallel_slots<=1&&e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:"keine aktiv"})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:e.jsx(Mt,{caps:t.capabilities})}),e.jsxs("button",{onClick:z,disabled:n,className:w("mt-auto flex h-9 items-center justify-center gap-1.5 rounded-lg border text-xs font-semibold transition-colors",n?"cursor-not-allowed border-border/30 text-muted-foreground/40":"border-red-500/30 text-red-400 hover:bg-red-500/10 cursor-pointer"),children:[e.jsx(Ye,{className:"h-3.5 w-3.5"})," ",n?"geschützt — nicht löschbar":"Modell löschen"]})]})}function ze({active:t,onClick:r,dot:h,label:n,disabled:x}){return e.jsxs("button",{onClick:r,disabled:x,title:x?"Gesperrt: dieses Modell hält eine lebenswichtige Rolle.":void 0,className:w("flex items-center gap-1.5 rounded-lg border px-2 py-1 text-[10px] font-semibold transition-all",x?"cursor-not-allowed opacity-40 border-border/40 bg-background/20 text-muted-foreground":t?"cursor-pointer border-primary/60 bg-primary/15 text-foreground":"cursor-pointer border-border/40 bg-background/20 text-muted-foreground hover:border-primary/30"),children:[e.jsx("span",{className:w("h-2 w-2 rounded-sm",h)}),n,t&&e.jsx(Y,{className:"h-3 w-3 text-primary"})]})}function At({icon:t,label:r,value:h}){return e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/30 bg-background/20 p-2.5",children:[e.jsx(t,{className:"h-4 w-4 text-primary/80"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:r}),e.jsx("div",{className:"font-semibold text-foreground",children:h})]})]})}function se({tone:t,label:r}){const h={emerald:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",amber:"bg-amber-500/10 text-amber-400 border-amber-500/20",cyan:"bg-cyan-500/10 text-cyan-400 border-cyan-500/20",violet:"bg-violet-500/10 text-violet-400 border-violet-500/20"}[t];return e.jsx("span",{className:w("rounded border px-1.5 py-0.5 text-[10px] font-semibold",h),children:r})}const Bt=[{key:"popular",label:"Beliebt",q:""},{key:"coder",label:"Coder",q:"coder"},{key:"vision",label:"Vision",q:"vision"},{key:"reasoning",label:"Reasoning",q:"reasoning"},{key:"small",label:"Klein (≤4B)",q:"3B"}],Gt=["fast","heavy","coder","vision","hermes","scout"],$t=new Intl.NumberFormat(void 0,{notation:"compact",maximumFractionDigits:1});function Ae(t){return $t.format(t)}function Dt(){const{data:t}=de(),r=(t==null?void 0:t.models)??[],[h,n]=N.useState(""),[x,M]=N.useState([]),[v,d]=N.useState(!1),[S,g]=N.useState(""),[z,m]=N.useState("popular"),[f,b]=N.useState(""),[c,L]=N.useState(null),[B,s]=N.useState([]),[o,i]=N.useState("Q4_K_M"),[G,A]=N.useState(""),[C,k]=N.useState(null),[R,E]=N.useState(!1),[I,T]=N.useState({});async function W(a){d(!0),g("");try{const y=await K(`/api/hf/search?q=${encodeURIComponent(a)}`);M(y.results),y.results.length||g("Keine Ergebnisse.")}catch(y){g(`Suche fehlgeschlagen: ${y}`)}finally{d(!1)}}N.useEffect(()=>{W("")},[]);function te(a){m(a.key),n(""),W(a.q)}function H(){m(""),W(h)}async function $(a,y,D){E(!1);try{const U=await K(`/api/fit?params_b=0&quant=${encodeURIComponent(y)}&ctx=8192&name=${encodeURIComponent(a)}&role=${encodeURIComponent(D)}`);k(U)}catch{k(null)}}async function p(a){if(c===a){L(null);return}L(a),s([]),k(null),A(""),E(!1),g("Analysiere Repository…");try{const y=await K(`/api/hf/quants?repo=${encodeURIComponent(a)}`);s(y.quants);const D=y.quants.includes("Q4_K_M")?"Q4_K_M":y.quants[0]||"Q4_K_M";i(D),g(y.quants.length?"":"Keine GGUF-Dateien in diesem Repo gefunden."),y.quants.length&&$(y.repo,D,"")}catch(y){g(`Fehler: ${y}`)}}function _(){const a=f.trim();a&&(M(y=>y.some(D=>D.repo===a)?y:[{repo:a,downloads:0,likes:0},...y]),b(""),p(a))}const Q=G?r.find(a=>(a.role||"").toLowerCase()===G):void 0;async function ce(a){if((C==null?void 0:C.fit.level)==="too_tight"&&!R){E(!0);return}T(y=>({...y,[a]:"Starte…"}));try{await K("/api/models/install",{method:"POST",body:JSON.stringify({repo:a,quant:o,role:G||void 0,jinja:!0})}),T(y=>({...y,[a]:"Download läuft"})),E(!1)}catch{T(D=>({...D,[a]:"Fehler"}))}}const xe=a=>{var D;const y=((D=a.split("/").pop())==null?void 0:D.toLowerCase().replace(/-gguf$/i,""))||"";return y.length>3&&r.some(U=>U.name.toLowerCase().includes(y))},me=a=>a==="perfect"?"text-emerald-400 border-emerald-500/40 bg-emerald-500/10":a==="marginal"?"text-amber-400 border-amber-500/40 bg-amber-500/10":"text-red-400 border-red-500/40 bg-red-500/10";return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ye,{className:"absolute left-3 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx("input",{value:h,onChange:a=>n(a.target.value),onKeyDown:a=>a.key==="Enter"&&H(),"aria-label":"HuggingFace durchsuchen",type:"search",spellCheck:!1,placeholder:"HuggingFace durchsuchen (z.B. Qwen Coder, Llama-3.1, gemma)…",className:"w-full h-10 pl-9 pr-3 rounded-xl border border-border/60 bg-background/40 text-xs outline-none focus:ring-1 focus:ring-primary/50 text-foreground"})]}),e.jsx("button",{onClick:H,className:"h-10 px-5 rounded-xl bg-primary text-primary-foreground text-xs font-semibold hover:opacity-90 transition-all cursor-pointer",children:"Suchen"})]}),e.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:Bt.map(a=>e.jsxs("button",{onClick:()=>te(a),className:w("flex items-center gap-1.5 rounded-full px-3 py-1.5 text-[11px] font-semibold transition-all cursor-pointer border",z===a.key?"bg-primary/15 text-primary border-primary/30":"border-border/50 text-muted-foreground hover:text-foreground hover:border-border"),children:[a.key==="popular"&&e.jsx(it,{className:"h-3 w-3"}),a.label]},a.key))}),v?e.jsx("div",{className:"text-xs text-muted-foreground py-10 text-center",children:"Lade GGUF-Modelle von HuggingFace…"}):e.jsxs("div",{className:"space-y-2",children:[x.map(a=>{const y=c===a.repo,D=xe(a.repo),U=a.repo.includes("/")?a.repo.split("/")[0]:"—",l=a.repo.split("/").pop();return e.jsxs("div",{className:w("mc-card-sm",y?"border-primary/40 shadow-lg shadow-primary/5":"border-border/50 hover:border-primary/30"),children:[e.jsxs("button",{onClick:()=>p(a.repo),className:"w-full flex items-center gap-3 p-3.5 text-left cursor-pointer",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-xs font-bold font-mono text-foreground truncate max-w-[280px]",title:a.repo,children:l}),D&&e.jsxs("span",{className:"flex items-center gap-1 text-[8px] font-bold text-emerald-400 uppercase tracking-wider bg-emerald-500/10 border border-emerald-500/20 px-1.5 py-0.5 rounded",children:[e.jsx(Y,{className:"h-2.5 w-2.5"})," installiert"]})]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground/80 flex items-center gap-3 mt-0.5 font-mono",children:[e.jsx("span",{children:U}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ne,{className:"h-3 w-3"})," ",Ae(a.downloads)]}),a.likes>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ct,{className:"h-3 w-3"})," ",Ae(a.likes)]})]})]}),y?e.jsx(Ee,{className:"h-4 w-4 text-muted-foreground shrink-0"}):e.jsx(De,{className:"h-4 w-4 text-muted-foreground shrink-0"})]}),y&&e.jsx("div",{className:"border-t border-border/30 p-3.5 space-y-3",children:B.length===0?e.jsx("div",{className:"text-[11px] text-muted-foreground font-mono",children:S||"Lade Quants…"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("label",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground",children:"Quant"}),e.jsx("select",{value:o,onChange:u=>{i(u.target.value),$(a.repo,u.target.value,G)},"aria-label":"Quantisierung",className:"h-8 rounded-lg border border-border/60 bg-background/40 px-2 text-xs text-foreground font-semibold outline-none",children:B.map(u=>e.jsx("option",{value:u,className:"bg-popover text-foreground",children:u},u))}),e.jsx("label",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground ml-1",children:"Rolle"}),e.jsxs("select",{value:G,onChange:u=>{A(u.target.value),$(a.repo,o,u.target.value)},"aria-label":"Rolle",title:"Optional — bestimmt Auto-Konfiguration + setup-bewussten Kontext",className:"h-8 rounded-lg border border-border/60 bg-background/40 px-2 text-xs text-foreground font-semibold outline-none",children:[e.jsx("option",{value:"",className:"bg-popover text-foreground",children:"keine"}),Gt.map(u=>e.jsx("option",{value:u,className:"bg-popover text-foreground",children:u},u))]}),e.jsx("button",{onClick:()=>ce(a.repo),disabled:!!I[a.repo]&&I[a.repo]==="Download läuft",className:w("h-8 px-3.5 ml-auto rounded-lg text-xs font-semibold transition-all cursor-pointer flex items-center gap-1.5",R?"bg-red-500 text-white hover:opacity-90":"bg-primary text-primary-foreground hover:opacity-90"),children:I[a.repo]?I[a.repo]:R?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"h-3.5 w-3.5"})," OOM — trotzdem laden"]}):e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-3.5 w-3.5"})," Herunterladen"]})})]}),C&&e.jsxs("div",{className:w("flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border px-3 py-2 text-[11px] font-medium",me(C.fit.level)),children:[e.jsx("span",{className:"font-bold uppercase tracking-wide",children:C.fit.text}),e.jsxs("span",{className:"font-mono opacity-90",children:["~",C.params_b,"B · ~",C.fit.req_gb," GB / ",C.sys_ram_gb," GB · ~",C.fit.tps," t/s"]}),C.fit.level!=="too_tight"?e.jsxs("span",{className:"font-mono opacity-80",children:["ctx → ",(C.assigned_ctx/1024).toFixed(0),"k"]}):e.jsx("span",{className:"opacity-90",children:"— passt nicht, würde beim Laden abstürzen (OOM)."})]}),Q&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-400",children:[e.jsx(re,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsxs("span",{children:["Rolle ",e.jsxs("strong",{children:["„",G,'"']})," hält aktuell ",e.jsx("strong",{children:Q.name.split("/").pop()})," — wird beim Download übernommen."]})]})]})})]},a.repo)}),!x.length&&!v&&e.jsx("div",{className:"text-xs text-muted-foreground py-10 text-center",children:S||"Keine Ergebnisse."})]}),e.jsxs("div",{className:"border-t border-border/30 pt-4 flex flex-col sm:flex-row gap-2 items-stretch sm:items-center",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground shrink-0",children:"Direkt:"}),e.jsx("input",{value:f,onChange:a=>b(a.target.value),onKeyDown:a=>a.key==="Enter"&&_(),"aria-label":"Repository oder URL direkt eingeben",spellCheck:!1,placeholder:"org/repo oder HF-URL (z.B. unsloth/Qwen2.5-Coder-7B-Instruct-GGUF)",className:"flex-1 h-9 rounded-lg border border-border/60 bg-background/40 px-3 text-xs outline-none focus:ring-1 focus:ring-primary/50 text-foreground font-mono"}),e.jsx("button",{onClick:_,className:"h-9 px-4 rounded-lg border border-border/60 bg-background/20 text-xs font-semibold hover:border-primary/50 hover:bg-background/40 transition-all cursor-pointer whitespace-nowrap",children:"Laden"})]})]})}const Et={fast:{title:"Schnelles Alltags-Hirn",desc:"Schnelle MoE-Antworten für Chat, Zusammenfassungen und alltägliche Aufgaben.",icon:ie},heavy:{title:"Schweres Reasoning",desc:"Große Modelle für komplexe Logik, Mathematik und tiefgründiges Planen.",icon:le},coder:{title:"Coden & Entwicklung",desc:"Autovervollständigung, Refactoring und Codegenerierung direkt in deiner IDE.",icon:be},vision:{title:"Bilder & Vision",desc:"Verarbeitet Bilder, Screenshots und visuelle Diagramme in multimodalen Chats.",icon:Be},hermes:{title:"Lucys Hirn (Agent)",desc:"Lucys dauer-warmes Agent-Hirn mit Tool-Calling — bleibt ko-resident, lädt nie kalt nach.",icon:lt},scout:{title:"Multimodal-Allrounder",desc:"Multimodaler Allrounder für schnelle Antworten, Übersetzungen und Alltag.",icon:at},kritiker:{title:"Kritisches Prüf-Hirn",desc:"Schärfer Blick für Fehler, Schwachstellen und Sicherheitslücken — denkt skeptisch, bevor du deployst.",icon:qe},reranker:{title:"Gedächtnis-Sortierer",desc:"Sortiert und gewichtet gespeicherte Fakten nach Relevanz — damit die richtige Info sofort da ist.",icon:ye}};function qt(){const{data:t,isLoading:r,error:h}=et(),{data:n}=de(),{data:x}=tt(),M=(n==null?void 0:n.models)??[],v=h?String(h):"",[d,S]=N.useState({}),[g,z]=N.useState({}),[m,f]=N.useState("recommended");async function b(c,L,B,s){S(o=>({...o,[c]:"Starte..."}));try{await K("/api/models/install",{method:"POST",body:JSON.stringify({repo:c,role:L,quant:B,jinja:s})}),S(o=>({...o,[c]:"Download läuft"}))}catch{S(i=>({...i,[c]:"Fehler"}))}}return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex mc-card-sm p-1 w-fit",children:[["recommended","Empfohlen"],["browse","Stöbern & Suchen"]].map(([c,L])=>e.jsx("button",{onClick:()=>f(c),className:w("rounded-lg px-4 py-1.5 text-xs font-semibold tracking-wide transition-all cursor-pointer",m===c?"bg-primary text-primary-foreground shadow-md shadow-primary/10":"text-muted-foreground hover:text-foreground"),children:L},c))}),m==="browse"?e.jsx(Dt,{}):r?e.jsx("div",{className:"text-xs text-muted-foreground py-12 text-center",children:"Analysiere Hardware und suche passende GGUF-Empfehlungen…"}):v||!t?e.jsxs("div",{className:"rounded-xl border border-red-500/20 bg-red-500/5 p-4 text-xs text-red-400",children:["Empfehlungsdienst temporär nicht erreichbar (",v,")."]}):e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"text-[10px] font-mono text-muted-foreground bg-background/25 border border-border/40 p-4 rounded-xl flex flex-col sm:flex-row sm:items-center justify-between gap-3 shadow-sm",children:[e.jsxs("div",{children:["Modell-Registry geladen für ",e.jsxs("span",{className:"text-foreground font-bold",children:[t.sys_ram_gb," GB"]})," System-RAM."]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ht,{className:"h-3.5 w-3.5 text-primary fill-primary/20"}),e.jsx("span",{children:"Empfehlungen sind automatisch auf deine Box-Hardware optimiert."})]})]}),e.jsx("div",{className:"grid gap-6 md:grid-cols-2",children:t.categories.map(c=>{const L=Et[c.role]||{title:c.title||c.role,desc:"Spezifisches Modell für diese Systemrolle.",icon:ot},B=L.icon,s=M.find(k=>k.role===c.role||(k.aliases||[]).includes(c.role)),o=x==null?void 0:x.model_list.find(k=>k.role===c.role),i=c.models.find(k=>k.repo===c.recommended)||c.models[0];if(!i)return null;const G=d[i.repo],A=c.models.filter(k=>k.repo!==c.recommended),C=!!g[c.role];return e.jsxs("div",{className:w("mc-card p-5 flex flex-col justify-between gap-5",s?"border-border/60":"border-primary/20 shadow-primary/5"),children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 border border-primary/20 flex items-center justify-center text-primary shadow-sm shrink-0",children:e.jsx(B,{className:"h-5.5 w-5.5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold tracking-tight text-foreground",children:L.title}),e.jsxs("span",{className:"text-[9px] font-mono text-muted-foreground uppercase bg-background/50 px-1.5 py-0.5 rounded border border-border/30 inline-block mt-0.5",children:["Rolle: ",c.role]})]})]}),s?e.jsxs("span",{className:"flex items-center gap-1.5 text-[9px] font-bold text-emerald-400 uppercase tracking-wider bg-emerald-500/10 border border-emerald-500/20 px-2.5 py-1 rounded-lg",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse"}),"Aktiviert"]}):e.jsx("span",{className:"text-[9px] font-bold text-primary/70 uppercase tracking-wider bg-primary/10 border border-primary/20 px-2.5 py-1 rounded-lg",children:"Frei"})]}),e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:L.desc}),e.jsx("div",{className:"p-3.5 rounded-xl bg-background/35 border border-border/30 space-y-2.5",children:s?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"text-[9px] font-bold uppercase tracking-wider text-muted-foreground/60",children:"Aktive GGUF-Belegung"}),e.jsx("div",{className:"text-xs font-mono font-bold text-foreground truncate",title:s.name,children:s.name.split("/").pop()}),e.jsxs("div",{className:"text-[10px] text-muted-foreground/80 flex items-center gap-2",children:[e.jsxs("span",{children:["Größe: ",ue(s.size_bytes||0)]}),e.jsx("span",{children:"•"}),e.jsxs("span",{children:["Quant: ",s.quant||"GGUF"]})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"text-[9px] font-bold uppercase tracking-wider text-primary/80",children:"Empfohlenes Modell"}),e.jsx("div",{className:"text-xs font-mono font-bold text-foreground truncate",title:i.name,children:i.name}),e.jsxs("div",{className:"text-[10px] text-muted-foreground/80 flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{children:["Ersteller: ",i.author]}),e.jsx("span",{children:"•"}),e.jsxs("span",{children:["Quant: ",i.quant]})]}),e.jsx("div",{className:"flex items-center gap-1.5 pt-0.5",children:e.jsx(kt,{fit:i.fit})})]})}),e.jsx("div",{className:"pt-1",children:s?o?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[9px] font-semibold text-amber-400 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 animate-ping shrink-0"}),e.jsxs("span",{children:["Bessere Version in der Registry: ",o.repo.split("/").pop()]})]}),e.jsxs("button",{onClick:()=>b(o.repo,c.role,o.repo===i.repo&&i.quant||"Q4_K_M",i.caps.tools!=="no"),disabled:!!d[o.repo],className:"h-8 w-full flex items-center justify-center gap-1.5 rounded-lg bg-amber-500 text-black text-xs font-bold hover:bg-amber-400 disabled:opacity-50 transition-all cursor-pointer shadow-md shadow-amber-500/10",children:[e.jsx(ne,{className:"h-3.5 w-3.5"}),d[o.repo]||"Auf neue Version aktualisieren"]})]}):e.jsxs("div",{className:"h-8 flex items-center justify-center gap-1.5 text-[10px] font-bold text-emerald-400 uppercase tracking-wide bg-emerald-500/5 border border-emerald-500/10 rounded-lg select-none",children:[e.jsx(Y,{className:"h-4 w-4"})," Auf neuestem Stand"]}):e.jsxs("button",{onClick:()=>b(i.repo,c.role,i.quant||"Q4_K_M",i.caps.tools!=="no"),disabled:!!G,className:w("h-8 w-full flex items-center justify-center gap-1.5 rounded-lg text-xs font-bold transition-all cursor-pointer border",G?"border-primary/40 bg-primary/5 text-primary":"bg-primary text-primary-foreground hover:opacity-90 shadow-md shadow-primary/10"),children:[e.jsx(ne,{className:"h-3.5 w-3.5"}),G||"Optimales Modell einsetzen"]})})]}),A.length>0&&e.jsxs("div",{className:"border-t border-border/20 pt-3",children:[e.jsxs("button",{onClick:()=>z(k=>({...k,[c.role]:!C})),className:"flex items-center gap-1.5 text-[10px] text-muted-foreground/80 hover:text-foreground transition-colors cursor-pointer",children:[C?e.jsx(Ee,{className:"h-3 w-3"}):e.jsx(De,{className:"h-3 w-3"}),e.jsxs("span",{children:["Alternative Empfehlungen anzeigen (",A.length,")"]})]}),C&&e.jsx("div",{className:"mt-2.5 space-y-2 max-h-36 overflow-y-auto pr-1 scrollbar-thin",children:A.map(k=>e.jsxs("div",{className:"p-2 rounded-lg bg-background/25 border border-border/20 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-mono font-bold text-foreground truncate",title:k.name,children:k.name}),e.jsxs("div",{className:"text-[9px] text-muted-foreground flex items-center gap-1.5 mt-0.5",children:[e.jsxs("span",{children:["Quant: ",k.quant]}),e.jsx("span",{children:"•"}),e.jsx("span",{children:k.fit.text})]})]}),e.jsx("button",{onClick:()=>b(k.repo,c.role,k.quant||"Q4_K_M",k.caps.tools!=="no"),disabled:!!d[k.repo],className:"h-6 px-2.5 rounded bg-background/40 hover:bg-background/80 border border-border/40 text-[9px] font-bold text-foreground transition-all cursor-pointer shrink-0 disabled:opacity-50",children:d[k.repo]||"Installieren"})]},k.repo))})]})]},c.role)})})]})]})}const Kt=[{id:"werkbank",label:"Werkbank"},{id:"routing",label:"Routing & Warm-Set"},{id:"discover",label:"Modelle finden"}];function Tt(){const[t,r]=N.useState("werkbank");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-space font-bold tracking-tight bg-gradient-to-r from-foreground via-foreground to-primary bg-clip-text text-transparent",children:"Modell-Manager"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Modelle verwalten, das Lane-Routing einstellen und Neues von HuggingFace holen."})]}),e.jsx("div",{className:"flex mc-card-sm p-1 self-start",children:Kt.map(h=>e.jsx("button",{onClick:()=>r(h.id),className:w("rounded-lg px-4 py-1.5 text-xs font-semibold tracking-wide uppercase transition-all cursor-pointer",t===h.id?"bg-primary text-primary-foreground shadow-md shadow-primary/10":"text-muted-foreground hover:text-foreground"),children:h.label},h.id))})]}),e.jsx(ft,{}),e.jsxs("div",{className:"transition-all duration-300",children:[t==="werkbank"&&e.jsx(Lt,{}),t==="routing"&&e.jsxs("div",{className:"space-y-5",children:[e.jsx(vt,{}),e.jsx(wt,{})]}),t==="discover"&&e.jsx(qt,{})]})]})}export{Tt as ModelsView};