import{c as D,u as Ce,a as Ee,b as Se,j as e,f as ce,d as De,e as g,g as B,q as te,B as ae,h as qe,E as _e,i as Ge,r as y,X as Re,C as J,T as re,k as Z,H as Ae,l as P,m as me,n as Fe,o as Ke,p as Oe,S as pe,s as Ie,P as Te,t as Ue,v as He,w as Le,x as Pe,y as Qe}from"./index-ClYatDZT.js";import{C as xe,Z as ue,L as Ve,a as We,b as Je}from"./zap-raGIywOo.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 Ze=D("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 Ye=D("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 ze=D("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 se=D("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 Xe=D("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 et=D("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 tt=D("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 rt=D("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 st=D("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 $e=D("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 nt=D("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 at=D("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 ot(){const t=Ce(),{data:s=[]}=Ee(),{showAlert:u,dialogElement:l}=Se();async function p(a){try{await B(`/api/jobs/${a}/cancel`,{method:"POST"}),t.invalidateQueries({queryKey:te.jobs})}catch(C){u("Fehler",C.message)}}const k=s.filter(a=>a.state==="running"||a.state==="queued"),f=s.filter(a=>a.state!=="running"&&a.state!=="queued").slice(-3);return k.length===0&&f.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"}),k.map(a=>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:a.label}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-muted-foreground font-mono",children:[a.progress??0,"% • ",ce(a.done_bytes),"/",ce(a.total_bytes),a.eta_s?` • ETA ${De(a.eta_s)}`:""]}),e.jsx("button",{onClick:()=>p(a.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:`${a.progress??0}%`}})})]},a.id)),f.map(a=>e.jsxs("div",{className:"flex justify-between items-center text-xs text-muted-foreground px-1",children:[e.jsx("span",{className:"truncate",children:a.label}),e.jsx("span",{className:g("font-semibold text-[10px] px-1.5 py-0.5 rounded uppercase font-mono",a.state==="done"?"bg-emerald-500/10 text-emerald-400":"bg-amber-500/10 text-amber-400"),children:a.state})]},a.id)),l]})}function O({children:t,tone:s="muted"}){const u={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 ${u[s]}`,children:t})}function lt({caps:t}){return t?e.jsxs("span",{className:"inline-flex flex-wrap gap-1",children:[t.coder&&e.jsx(O,{children:"💻 Code"}),t.vision&&e.jsx(O,{children:"👁 Bild"}),t.reasoning&&e.jsx(O,{children:"🧠 Reason"}),t.moe&&e.jsxs(O,{tone:"primary",children:["🧩 MoE",t.active_b?`·${t.active_b}b`:""]}),t.tools==="yes"&&e.jsx(O,{tone:"primary",children:"🛠 Tools"}),t.tools==="likely"&&e.jsx(O,{tone:"warn",children:"🛠 Tools?"}),t.embedding&&e.jsx(O,{children:"🔢 Embed"})]}):null}const he=[{role:"hermes",label:"Lucys Hirn",short:"Hirn",icon:ae,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:qe,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:tt,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:_e,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:Ye,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:xe,desc:"Schnelles Programmieren im Alltag.",tone:"bg-violet-500/15 text-violet-400 border-violet-500/25"},{role:"coder",label:"Programmierer (gründlich)",short:"Code gründlich",icon:xe,desc:"Schreibt und prüft Code besonders sorgfältig — für schwere Coding-Aufgaben.",tone:"bg-fuchsia-500/15 text-fuchsia-400 border-fuchsia-500/25"},{role:"scout",label:"Späher",short:"Späher",icon:at,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:$e,desc:"Die unbestechliche Zweitmeinung — prüft Behauptungen und Patches (anderer Hersteller als das Hirn).",tone:"bg-cyan-500/15 text-cyan-400 border-cyan-500/25"}];he.map(t=>t.role);const ge=Object.fromEntries(he.map(t=>[t.role,t])),fe=t=>({role:t||"?",label:t||"unbekannt",short:t||"?",icon:ae,desc:"Rolle ohne hinterlegten Klartext-Namen.",tone:"bg-slate-500/15 text-slate-300 border-slate-500/25"}),it={fast:"hermes",coder_lite:"coder-lite"};function R(t){return t&&(ge[t]||ge[it[t]])||fe(t)}function dt({role:t,dense:s=!1,className:u}){const l=R(t),p=l.icon;return e.jsxs("span",{className:g("inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-semibold border tracking-wide",l.tone,u),title:`${l.desc} (${l.role})`,children:[e.jsx(p,{className:"h-3 w-3 shrink-0","aria-hidden":"true"}),s?l.short:l.label]})}function ct({fit:t}){const s={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:g("rounded px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider font-mono",s),children:[t.text," • ",t.req_gb," GB RAM"]})}function Be(t){const s=t.toLowerCase();return s.includes("qwen")?{name:"Qwen",color:"bg-purple-500/20 text-purple-300 border-purple-500/30",initial:"Q"}:s.includes("gemma")?{name:"Gemma",color:"bg-blue-500/20 text-blue-300 border-blue-500/30",initial:"G"}:s.includes("llama")?{name:"Llama",color:"bg-red-500/20 text-red-300 border-red-500/30",initial:"🦙"}:s.includes("mistral")||s.includes("mixtral")?{name:"Mistral",color:"bg-orange-500/20 text-orange-300 border-orange-500/30",initial:"M"}:s.includes("deepseek")?{name:"DeepSeek",color:"bg-cyan-500/20 text-cyan-300 border-cyan-500/30",initial:"D"}:s.includes("hermes")||s.includes("nous")?{name:"Hermes",color:"bg-amber-500/20 text-amber-300 border-amber-500/30",initial:"H"}:s.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 xt({model:t,onClose:s,onChanged:u}){var _,E;const{data:l,isLoading:p}=Ge(t.gguf_path),[k,f]=y.useState(null),[a,C]=y.useState(""),o=l==null?void 0:l.target_vocab,N=(l==null?void 0:l.drafts)??[],w=N.filter(i=>i.compatible===!0),j=t.spec_draft_model;async function M(i){f(i??"__clear__"),C("");try{await B(`/api/models/${encodeURIComponent(t.name)}/draft`,{method:"POST",body:JSON.stringify({draft_path:i})}),u(),s()}catch(h){C(String((h==null?void 0:h.message)||h)),f(null)}}const c=i=>{var h;return i?`${i.pre??"?"} · ${((h=i.n_vocab)==null?void 0:h.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(ue,{className:"h-4 w-4"})," Speculative Draft"]}),e.jsx("button",{onClick:s,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground cursor-pointer",children:e.jsx(Re,{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:(_=t.name.split("/").pop())==null?void 0:_.replace(/\.gguf$/i,"")}),e.jsxs("span",{className:"text-foreground",children:["Vocab: ",c(o)]})]}),t.spec_active&&j&&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(J,{className:"h-3.5 w-3.5 shrink-0"})," Aktiv: ",j]}),e.jsx("button",{onClick:()=>M(null),disabled:k!==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"})]}),!(l!=null&&l.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:p?e.jsx("div",{className:"text-xs text-muted-foreground py-6 text-center",children:"Prüfe Vocab-Kompatibilität…"}):N.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."]}):N.map(i=>{var z,$;const h=i.filename===j,v=i.compatible===!0;return e.jsxs("div",{className:g("rounded-lg border px-3 py-2 flex items-center justify-between gap-2 text-left",v?"border-border/40 bg-background/20":"border-border/20 bg-background/10 opacity-60",h&&"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:[i.filename,i.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:[Z(i.size_bytes)," · Vocab: ",c(i.vocab)]})]}),v?h?e.jsxs("span",{className:"text-[9px] font-bold uppercase text-primary flex items-center gap-1 shrink-0",children:[e.jsx(J,{className:"h-3.5 w-3.5"})," Aktiv"]}):e.jsx("button",{onClick:()=>M(i.path),disabled:k!==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:i.compatible===!1?`Inkompatibel: Tokenizer/Vocab weicht ab (Draft ${(z=i.vocab)==null?void 0:z.pre}/${($=i.vocab)==null?void 0:$.n_vocab} ≠ Modell ${o==null?void 0:o.pre}/${o==null?void 0:o.n_vocab}).`:"Kompatibilität nicht prüfbar (Datei fehlt).",children:[e.jsx(re,{className:"h-3.5 w-3.5"})," ",i.compatible===!1?"Vocab ≠":"n/a"]})]},i.path)})}),!p&&(l==null?void 0:l.target_exists)&&N.length>0&&w.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:o==null?void 0:o.pre}),", n_vocab=",e.jsx("span",{className:"font-mono",children:(E=o==null?void 0:o.n_vocab)==null?void 0:E.toLocaleString()}),")."]}),a&&e.jsx("div",{className:"text-[10px] text-red-400 font-mono",children:a})]})})}const ye={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"}},mt={fast:"hermes",coder_lite:"coder-lite"},je={bar:"bg-slate-400",dot:"bg-slate-400",text:"text-slate-300"};function ne(t){return t&&(ye[t]||ye[mt[t]])||je}const ve=1024**3,ke=t=>{var s;return((s=t.split("/").pop())==null?void 0:s.replace(/\.gguf$/i,""))??t};function pt({running:t,capacityBytes:s,realUsedBytes:u,selected:l,onSelect:p}){const k=s>2*ve?s:124*ve,f=t.reduce((o,N)=>o+(N.size_bytes||0),0),a=Math.max(0,k-f),C=a/k*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(Ae,{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:"Arbeitsspeicher"}),e.jsxs("div",{className:"font-space text-xl font-bold tracking-tight text-foreground",children:[P(k)," 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:[P(f)," GB"]})," Modelle geladen"]}),u>0&&e.jsxs("div",{children:[P(u)," GB real belegt (inkl. KV-Cache)"]}),e.jsxs("div",{className:"text-emerald-400",children:[P(a)," 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(o=>{const N=(o.size_bytes||0)/k*100,w=ne(o.role),j=l===o.name;return e.jsxs("button",{onClick:()=>p==null?void 0:p(o.name),style:{width:`${N}%`},title:`${R(o.role).label} · ${ke(o.name)} · ${Z(o.size_bytes)}`,className:g("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",w.bar,j?"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:R(o.role).short}),e.jsx("span",{className:"truncate font-mono text-[9px] leading-tight opacity-85",children:Z(o.size_bytes)})]},o.name)}),C>1.5&&e.jsx("div",{style:{width:`${C}%`},className:"flex h-full min-w-[2rem] items-center justify-center rounded-lg text-[9px] font-mono text-muted-foreground/50",title:`${P(a)} 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(o=>{const N=ne(o.role);return e.jsxs("button",{onClick:()=>p==null?void 0:p(o.name),className:"flex items-center gap-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:[e.jsx("span",{className:g("h-2.5 w-2.5 rounded-sm",N.dot)}),e.jsx("span",{className:g("font-semibold",N.text),children:R(o.role).short}),e.jsx("span",{className:"font-mono text-muted-foreground/70",children:ke(o.name)})]},o.name)}),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 · ",P(a)," GB"]})]})]})}const Ne=1024**3,I=t=>{var s;return((s=t.split("/").pop())==null?void 0:s.replace(/\.gguf$/i,""))??t};function ut(){var r,x,L,F;const t=Ce(),{data:s,isLoading:u,error:l}=me(),{data:p}=Fe(),{data:k}=Ke(),{showAlert:f,showConfirm:a,showPrompt:C,dialogElement:o}=Se(),N=Oe(),w=(s==null?void 0:s.models)??[],j=(s==null?void 0:s.running)??[],M=n=>!!R(n).protected,c=(r=k==null?void 0:k.groups)==null?void 0:r.brains,_=(c==null?void 0:c.members)??[],E=n=>_.includes(n),[i,h]=y.useState(null),[v,z]=y.useState(""),[$,S]=y.useState("all"),[b,T]=y.useState(null),q=()=>{t.invalidateQueries({queryKey:te.models}),t.invalidateQueries({queryKey:te.routing}),t.invalidateQueries({queryKey:te.groups})},U=w.filter(n=>j.includes(n.name)),H=((x=p==null?void 0:p.gpu)==null?void 0:x.gtt_total)||((L=p==null?void 0:p.gpu)==null?void 0:L.vram_total)||0,Q=((F=p==null?void 0:p.gpu)==null?void 0:F.gtt_used)||0,oe=H>2*Ne?H:124*Ne,V=y.useMemo(()=>{const n=v.trim().toLowerCase();return w.filter(d=>$==="in_use"?!!d.role||j.includes(d.name):!0).filter(d=>n?d.name.toLowerCase().includes(n):!0).sort((d,m)=>{const G=j.includes(d.name)?0:1,K=j.includes(m.name)?0:1;return G!==K?G-K:I(d.name).localeCompare(I(m.name))})},[w,j,$,v]),A=w.find(n=>n.name===i)??null;async function W(n){try{await B(`/api/models/${encodeURIComponent(n)}/load`,{method:"POST"}),q()}catch(d){f("Fehler",`Laden fehlgeschlagen: ${d.message||d}`)}}async function Y(n){const d=_.some(m=>j.includes(m));if(c&&d&&!E(n)){const m=_.filter(G=>j.includes(G)).map(I).join(", ");a("Verdrängt das Hirn?",`„${I(n)}" ist nicht ko-resident. Beim Laden wirft es das warme Hirn (${m}) raus — Lucy verliert Hirn bzw. Augen. Trotzdem exklusiv laden?`,()=>W(n));return}W(n)}async function X(n){const d=w.find(m=>m.name===n);if(d&&M(d.role)){f("Geschützt",`„${R(d.role).label}" ist lebenswichtig und bleibt geladen.`);return}try{await B(`/api/models/${encodeURIComponent(n)}/unload`,{method:"POST"}),q()}catch(m){f("Fehler",`Entladen fehlgeschlagen: ${m.message||m}`)}}async function le(n,d){try{const m=await B(`/api/models/${encodeURIComponent(d)}/role`,{method:"POST",body:JSON.stringify({role:n||null})});q(),m!=null&&m.warning&&f("Rolle gesetzt — Hinweis",m.warning)}catch(m){f("Fehler",`Rolle zuweisen fehlgeschlagen: ${m.message||m}`)}}async function ie(n,d){let m=null;try{m=await B(`/api/models/${encodeURIComponent(n)}/ctx/auto`)}catch{}const G=m?`Optimal für dein Setup: ${(m.ctx/1024).toFixed(0)}k (${m.ctx}). »Auto« trägt diesen Wert ein.`:"Gib die gewünschte Kontextlänge in Tokens an:";C("Kontextlänge anpassen",G,String(d||32768),async K=>{if(K)try{await B(`/api/models/${encodeURIComponent(n)}/ctx`,{method:"POST",body:JSON.stringify({ctx:parseInt(K,10)})}),q()}catch(be){f("Fehler",`Kontext setzen fehlgeschlagen: ${be.message||be}`)}},void 0,m?{autoValue:String(m.ctx),autoLabel:`Auto (${(m.ctx/1024).toFixed(0)}k)`}:void 0)}async function de(n){const d=w.find(m=>m.name===n);if(d&&M(d.role)){f("Geschützt",`„${R(d.role).label}" kann nicht gelöscht werden. Weise die Rolle zuerst einem anderen Modell zu.`);return}a("Modell löschen?",`„${I(n)}" und alle GGUF-Dateien unwiderruflich von der Box löschen?`,async()=>{try{await B(`/api/models/${encodeURIComponent(n)}`,{method:"DELETE"}),i===n&&h(null),q()}catch(m){f("Fehler",`Löschen fehlgeschlagen: ${m.message||m}`)}})}return u?e.jsx("div",{className:"py-16 text-center text-xs text-muted-foreground",children:"Werkbank wird geladen …"}):l?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(l),")."]}):e.jsxs("div",{className:"space-y-5",children:[e.jsx(pt,{running:U,capacityBytes:oe,realUsedBytes:Q,selected:i,onSelect:h}),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(pe,{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:v,onChange:n=>z(n.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(n=>e.jsx("button",{onClick:()=>S(n),className:g("rounded-md px-2 py-1 text-[9px] font-bold uppercase transition-all cursor-pointer",$===n?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"),children:n==="all"?"Alle":"In Benutzung"},n))})]}),e.jsx("div",{className:"max-h-[60vh] space-y-1.5 overflow-y-auto scrollbar-thin pr-1",children:V.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."}):V.map(n=>{const d=j.includes(n.name),m=i===n.name,G=Be(n.name),K=ne(n.role);return e.jsxs("button",{onClick:()=>h(n.name),className:g("flex w-full items-center gap-2.5 rounded-xl border p-2.5 text-left transition-all cursor-pointer",m?"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:g("flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-[10px] font-bold",G.color),children:G.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:I(n.name)}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-1.5",children:[n.role&&e.jsx("span",{className:g("h-2 w-2 rounded-sm",K.dot)}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:n.role?R(n.role).short:"keine Rolle"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground/50",children:["· ",Z(n.size_bytes)]})]})]}),d?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"]}):n.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"})]},n.name)})})]}),e.jsx("div",{className:"mc-card p-5",children:A?e.jsx(ht,{m:A,warm:j.includes(A.name),expert:N,protectedRole:M(A.role),coresident:E(A.name),onLoad:()=>Y(A.name),onUnload:()=>X(A.name),onRole:n=>le(n,A.name),onCtx:()=>ie(A.name,A.ctx),onSpec:()=>T(A),onDelete:()=>de(A.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(Ie,{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."})]})})]}),b&&e.jsx(xt,{model:b,onClose:()=>T(null),onChanged:q}),o]})}function ht({m:t,warm:s,expert:u,protectedRole:l,coresident:p,onLoad:k,onUnload:f,onRole:a,onCtx:C,onSpec:o,onDelete:N}){const w=Be(t.name),j=s&&l;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:g("flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border text-sm font-bold",w.color),children:w.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:I(t.name)}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[t.role?e.jsx(dt,{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"}),l&&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(Ve,{className:"mr-0.5 inline h-3 w-3"}),"geschützt"]}),p&&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(ae,{className:"mr-0.5 inline h-3 w-3"}),"Ko-resident"]}),s&&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:s?f:k,disabled:t.incomplete&&!s||j,className:g("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",s?"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:j?`„${R(t.role).label}" bleibt geladen (geschützt).`:void 0,children:[s?e.jsx(st,{className:"h-4 w-4"}):e.jsx(Te,{className:"h-4 w-4"}),j?"🔒 bleibt geladen":s?"Entladen":"Ins Warm-Set laden"]}),e.jsxs("div",{className:"rounded-xl border border-border/30 bg-background/20 p-3",children:[e.jsx("div",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Rolle"}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx(we,{active:!t.role,onClick:()=>a(""),dot:"bg-slate-400",label:"keine"}),he.map(M=>e.jsx(we,{active:t.role===M.role,onClick:()=>a(M.role),dot:ne(M.role).dot,label:M.short},M.role))]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsx(bt,{icon:Ae,label:"Größe",value:Z(t.size_bytes)}),e.jsxs("button",{onClick:C,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(rt,{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:Ue(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"}),u&&e.jsxs("button",{onClick:o,className:g("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(ue,{className:"h-3 w-3"})," Spec"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.spec_active&&e.jsx(ee,{tone:"emerald",label:"Spec-Decoding aktiv"}),!t.spec_active&&t.spec_draft_model&&e.jsx(ee,{tone:"amber",label:"Spec inaktiv"}),t.prompt_cache&&e.jsx(ee,{tone:"cyan",label:"Prompt-Cache"}),t.parallel_slots>1&&e.jsx(ee,{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(lt,{caps:t.capabilities})}),e.jsxs("button",{onClick:N,disabled:l,className:g("mt-auto flex h-9 items-center justify-center gap-1.5 rounded-lg border text-xs font-semibold transition-colors",l?"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(He,{className:"h-3.5 w-3.5"})," ",l?"geschützt — nicht löschbar":"Modell löschen"]})]})}function we({active:t,onClick:s,dot:u,label:l}){return e.jsxs("button",{onClick:s,className:g("flex items-center gap-1.5 rounded-lg border px-2 py-1 text-[10px] font-semibold transition-all cursor-pointer",t?"border-primary/60 bg-primary/15 text-foreground":"border-border/40 bg-background/20 text-muted-foreground hover:border-primary/30"),children:[e.jsx("span",{className:g("h-2 w-2 rounded-sm",u)}),l,t&&e.jsx(J,{className:"h-3 w-3 text-primary"})]})}function bt({icon:t,label:s,value:u}){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:s}),e.jsx("div",{className:"font-semibold text-foreground",children:u})]})]})}function ee({tone:t,label:s}){const u={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:g("rounded border px-1.5 py-0.5 text-[10px] font-semibold",u),children:s})}const gt=[{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"}],ft=["fast","heavy","coder","vision","hermes","scout"],yt=new Intl.NumberFormat(void 0,{notation:"compact",maximumFractionDigits:1});function Me(t){return yt.format(t)}function jt(){const{data:t}=me(),s=(t==null?void 0:t.models)??[],[u,l]=y.useState(""),[p,k]=y.useState([]),[f,a]=y.useState(!1),[C,o]=y.useState(""),[N,w]=y.useState("popular"),[j,M]=y.useState(""),[c,_]=y.useState(null),[E,i]=y.useState([]),[h,v]=y.useState("Q4_K_M"),[z,$]=y.useState(""),[S,b]=y.useState(null),[T,q]=y.useState(!1),[U,H]=y.useState({});async function Q(r){a(!0),o("");try{const x=await B(`/api/hf/search?q=${encodeURIComponent(r)}`);k(x.results),x.results.length||o("Keine Ergebnisse.")}catch(x){o(`Suche fehlgeschlagen: ${x}`)}finally{a(!1)}}y.useEffect(()=>{Q("")},[]);function oe(r){w(r.key),l(""),Q(r.q)}function V(){w(""),Q(u)}async function A(r,x,L){q(!1);try{const F=await B(`/api/fit?params_b=0&quant=${encodeURIComponent(x)}&ctx=8192&name=${encodeURIComponent(r)}&role=${encodeURIComponent(L)}`);b(F)}catch{b(null)}}async function W(r){if(c===r){_(null);return}_(r),i([]),b(null),$(""),q(!1),o("Analysiere Repository…");try{const x=await B(`/api/hf/quants?repo=${encodeURIComponent(r)}`);i(x.quants);const L=x.quants.includes("Q4_K_M")?"Q4_K_M":x.quants[0]||"Q4_K_M";v(L),o(x.quants.length?"":"Keine GGUF-Dateien in diesem Repo gefunden."),x.quants.length&&A(x.repo,L,"")}catch(x){o(`Fehler: ${x}`)}}function Y(){const r=j.trim();r&&(k(x=>x.some(L=>L.repo===r)?x:[{repo:r,downloads:0,likes:0},...x]),M(""),W(r))}const X=z?s.find(r=>(r.role||"").toLowerCase()===z):void 0;async function le(r){if((S==null?void 0:S.fit.level)==="too_tight"&&!T){q(!0);return}H(x=>({...x,[r]:"Starte…"}));try{await B("/api/models/install",{method:"POST",body:JSON.stringify({repo:r,quant:h,role:z||void 0,jinja:!0})}),H(x=>({...x,[r]:"Download läuft"})),q(!1)}catch{H(L=>({...L,[r]:"Fehler"}))}}const ie=r=>{var L;const x=((L=r.split("/").pop())==null?void 0:L.toLowerCase().replace(/-gguf$/i,""))||"";return x.length>3&&s.some(F=>F.name.toLowerCase().includes(x))},de=r=>r==="perfect"?"text-emerald-400 border-emerald-500/40 bg-emerald-500/10":r==="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(pe,{className:"absolute left-3 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx("input",{value:u,onChange:r=>l(r.target.value),onKeyDown:r=>r.key==="Enter"&&V(),"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:V,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:gt.map(r=>e.jsxs("button",{onClick:()=>oe(r),className:g("flex items-center gap-1.5 rounded-full px-3 py-1.5 text-[11px] font-semibold transition-all cursor-pointer border",N===r.key?"bg-primary/15 text-primary border-primary/30":"border-border/50 text-muted-foreground hover:text-foreground hover:border-border"),children:[r.key==="popular"&&e.jsx(Xe,{className:"h-3 w-3"}),r.label]},r.key))}),f?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:[p.map(r=>{const x=c===r.repo,L=ie(r.repo),F=r.repo.includes("/")?r.repo.split("/")[0]:"—",n=r.repo.split("/").pop();return e.jsxs("div",{className:g("mc-card-sm",x?"border-primary/40 shadow-lg shadow-primary/5":"border-border/50 hover:border-primary/30"),children:[e.jsxs("button",{onClick:()=>W(r.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:r.repo,children:n}),L&&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(J,{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:F}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(se,{className:"h-3 w-3"})," ",Me(r.downloads)]}),r.likes>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(et,{className:"h-3 w-3"})," ",Me(r.likes)]})]})]}),x?e.jsx(ze,{className:"h-4 w-4 text-muted-foreground shrink-0"}):e.jsx(Le,{className:"h-4 w-4 text-muted-foreground shrink-0"})]}),x&&e.jsx("div",{className:"border-t border-border/30 p-3.5 space-y-3",children:E.length===0?e.jsx("div",{className:"text-[11px] text-muted-foreground font-mono",children:C||"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:h,onChange:d=>{v(d.target.value),A(r.repo,d.target.value,z)},"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:E.map(d=>e.jsx("option",{value:d,className:"bg-popover text-foreground",children:d},d))}),e.jsx("label",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground ml-1",children:"Rolle"}),e.jsxs("select",{value:z,onChange:d=>{$(d.target.value),A(r.repo,h,d.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"}),ft.map(d=>e.jsx("option",{value:d,className:"bg-popover text-foreground",children:d},d))]}),e.jsx("button",{onClick:()=>le(r.repo),disabled:!!U[r.repo]&&U[r.repo]==="Download läuft",className:g("h-8 px-3.5 ml-auto rounded-lg text-xs font-semibold transition-all cursor-pointer flex items-center gap-1.5",T?"bg-red-500 text-white hover:opacity-90":"bg-primary text-primary-foreground hover:opacity-90"),children:U[r.repo]?U[r.repo]:T?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(se,{className:"h-3.5 w-3.5"})," Herunterladen"]})})]}),S&&e.jsxs("div",{className:g("flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border px-3 py-2 text-[11px] font-medium",de(S.fit.level)),children:[e.jsx("span",{className:"font-bold uppercase tracking-wide",children:S.fit.text}),e.jsxs("span",{className:"font-mono opacity-90",children:["~",S.params_b,"B · ~",S.fit.req_gb," GB / ",S.sys_ram_gb," GB · ~",S.fit.tps," t/s"]}),S.fit.level!=="too_tight"?e.jsxs("span",{className:"font-mono opacity-80",children:["ctx → ",(S.assigned_ctx/1024).toFixed(0),"k"]}):e.jsx("span",{className:"opacity-90",children:"— passt nicht, würde beim Laden abstürzen (OOM)."})]}),X&&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:["„",z,'"']})," hält aktuell ",e.jsx("strong",{children:X.name.split("/").pop()})," — wird beim Download übernommen."]})]})]})})]},r.repo)}),!p.length&&!f&&e.jsx("div",{className:"text-xs text-muted-foreground py-10 text-center",children:C||"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:j,onChange:r=>M(r.target.value),onKeyDown:r=>r.key==="Enter"&&Y(),"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:Y,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 vt={fast:{title:"Schnelles Alltags-Hirn",desc:"Schnelle MoE-Antworten für Chat, Zusammenfassungen und alltägliche Aufgaben.",icon:ue},heavy:{title:"Schweres Reasoning",desc:"Große Modelle für komplexe Logik, Mathematik und tiefgründiges Planen.",icon:ae},coder:{title:"Coden & Entwicklung",desc:"Autovervollständigung, Refactoring und Codegenerierung direkt in deiner IDE.",icon:xe},vision:{title:"Bilder & Vision",desc:"Verarbeitet Bilder, Screenshots und visuelle Diagramme in multimodalen Chats.",icon:_e},hermes:{title:"Lucys Hirn (Agent)",desc:"Lucys dauer-warmes Agent-Hirn mit Tool-Calling — bleibt ko-resident, lädt nie kalt nach.",icon:Ze},scout:{title:"Multimodal-Allrounder",desc:"Multimodaler Allrounder für schnelle Antworten, Übersetzungen und Alltag.",icon:We},kritiker:{title:"Kritisches Prüf-Hirn",desc:"Schärfer Blick für Fehler, Schwachstellen und Sicherheitslücken — denkt skeptisch, bevor du deployst.",icon:$e},reranker:{title:"Gedächtnis-Sortierer",desc:"Sortiert und gewichtet gespeicherte Fakten nach Relevanz — damit die richtige Info sofort da ist.",icon:pe}};function kt(){const{data:t,isLoading:s,error:u}=Pe(),{data:l}=me(),{data:p}=Qe(),k=(l==null?void 0:l.models)??[],f=u?String(u):"",[a,C]=y.useState({}),[o,N]=y.useState({}),[w,j]=y.useState("recommended");async function M(c,_,E,i){C(h=>({...h,[c]:"Starte..."}));try{await B("/api/models/install",{method:"POST",body:JSON.stringify({repo:c,role:_,quant:E,jinja:i})}),C(h=>({...h,[c]:"Download läuft"}))}catch{C(v=>({...v,[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,_])=>e.jsx("button",{onClick:()=>j(c),className:g("rounded-lg px-4 py-1.5 text-xs font-semibold tracking-wide transition-all cursor-pointer",w===c?"bg-primary text-primary-foreground shadow-md shadow-primary/10":"text-muted-foreground hover:text-foreground"),children:_},c))}),w==="browse"?e.jsx(jt,{}):s?e.jsx("div",{className:"text-xs text-muted-foreground py-12 text-center",children:"Analysiere Hardware und suche passende GGUF-Empfehlungen…"}):f||!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 (",f,")."]}):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(nt,{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 _=vt[c.role]||{title:c.title||c.role,desc:"Spezifisches Modell für diese Systemrolle.",icon:Je},E=_.icon,i=k.find(b=>b.role===c.role||(b.aliases||[]).includes(c.role)),h=p==null?void 0:p.model_list.find(b=>b.role===c.role),v=c.models.find(b=>b.repo===c.recommended)||c.models[0];if(!v)return null;const z=a[v.repo],$=c.models.filter(b=>b.repo!==c.recommended),S=!!o[c.role];return e.jsxs("div",{className:g("mc-card p-5 flex flex-col justify-between gap-5",i?"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(E,{className:"h-5.5 w-5.5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold tracking-tight text-foreground",children:_.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]})]})]}),i?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:_.desc}),e.jsx("div",{className:"p-3.5 rounded-xl bg-background/35 border border-border/30 space-y-2.5",children:i?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:i.name,children:i.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: ",ce(i.size_bytes||0)]}),e.jsx("span",{children:"•"}),e.jsxs("span",{children:["Quant: ",i.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:v.name,children:v.name}),e.jsxs("div",{className:"text-[10px] text-muted-foreground/80 flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{children:["Ersteller: ",v.author]}),e.jsx("span",{children:"•"}),e.jsxs("span",{children:["Quant: ",v.quant]})]}),e.jsx("div",{className:"flex items-center gap-1.5 pt-0.5",children:e.jsx(ct,{fit:v.fit})})]})}),e.jsx("div",{className:"pt-1",children:i?h?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: ",h.repo.split("/").pop()]})]}),e.jsxs("button",{onClick:()=>M(h.repo,c.role,v.quant||"Q4_K_M",v.caps.tools!=="no"),disabled:!!a[h.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(se,{className:"h-3.5 w-3.5"}),a[h.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(J,{className:"h-4 w-4"})," Auf neuestem Stand"]}):e.jsxs("button",{onClick:()=>M(v.repo,c.role,v.quant||"Q4_K_M",v.caps.tools!=="no"),disabled:!!z,className:g("h-8 w-full flex items-center justify-center gap-1.5 rounded-lg text-xs font-bold transition-all cursor-pointer border",z?"border-primary/40 bg-primary/5 text-primary":"bg-primary text-primary-foreground hover:opacity-90 shadow-md shadow-primary/10"),children:[e.jsx(se,{className:"h-3.5 w-3.5"}),z||"Optimales Modell einsetzen"]})})]}),$.length>0&&e.jsxs("div",{className:"border-t border-border/20 pt-3",children:[e.jsxs("button",{onClick:()=>N(b=>({...b,[c.role]:!S})),className:"flex items-center gap-1.5 text-[10px] text-muted-foreground/80 hover:text-foreground transition-colors cursor-pointer",children:[S?e.jsx(ze,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"}),e.jsxs("span",{children:["Alternative Empfehlungen anzeigen (",$.length,")"]})]}),S&&e.jsx("div",{className:"mt-2.5 space-y-2 max-h-36 overflow-y-auto pr-1 scrollbar-thin",children:$.map(b=>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:b.name,children:b.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: ",b.quant]}),e.jsx("span",{children:"•"}),e.jsx("span",{children:b.fit.text})]})]}),e.jsx("button",{onClick:()=>M(b.repo,c.role,b.quant||"Q4_K_M",b.caps.tools!=="no"),disabled:!!a[b.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:a[b.repo]||"Installieren"})]},b.repo))})]})]},c.role)})})]})]})}function Mt(){const[t,s]=y.useState("cockpit");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:"Verwalte deine Modelle und passe das Gateway-Routing live über das interaktive Cockpit an."})]}),e.jsx("div",{className:"flex mc-card-sm p-1 self-start",children:["cockpit","discover"].map(u=>e.jsx("button",{onClick:()=>s(u),className:g("rounded-lg px-4 py-1.5 text-xs font-semibold tracking-wide uppercase transition-all cursor-pointer",t===u?"bg-primary text-primary-foreground shadow-md shadow-primary/10":"text-muted-foreground hover:text-foreground"),children:u==="cockpit"?"Werkbank":"Modelle finden"},u))})]}),e.jsx(ot,{}),e.jsx("div",{className:"transition-all duration-300",children:t==="cockpit"?e.jsx(ut,{}):e.jsx(kt,{})})]})}export{Mt as ModelsView};