import{c as me,a as f,f as F,t as Pe}from"./bmn8XlW7.js";import{o as yt}from"./CJbqisBi.js";import{f as B,p as nt,s as P,b as Ze,c as t,u as Ge,e as i,r as l,d as s,g as e,ag as $e,h as O,n as A,t as I,a as dt,ah as kt}from"./DpkolLiq.js";import{d as ut,s as D,e as ct}from"./pfhwnV1O.js";import{l as vt,s as ft,i as T}from"./TXeUdaq1.js";import{I as mt,s as pt,m as wt,r as fe,i as je,e as et,g as tt,j as Pt,k as St,b,l as at,p as rt}from"./DxBGAPM1.js";import{b as lt,a as it,L as st}from"./C8B7Gptd.js";import{C as _t,I as Ve,B as W,a as Tt,i as Ft,b as Ct,d as Dt}from"./SxayRmdi.js";import{r as gt}from"./CiPTfhJW.js";import{R as Mt,b as zt,C as Lt}from"./BozyOGoo.js";import{g as Et}from"./C2ETuzsT.js";import{f as Ot,P as It}from"./Cc006E0t.js";import{T as jt,C as At}from"./CkcI5Cyl.js";import{B as He}from"./DJJfkUlF.js";import"./EMQoTJgY.js";import{S as ot}from"./CWwN5y2H.js";import{C as Rt}from"./A7qlmPR5.js";import{H as Bt}from"./D1TVLabE.js";import{M as Nt}from"./_hewIRpL.js";function qt(pe,a){const Y=vt(a,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const U=[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"}]];mt(pe,ft({name:"activity"},()=>Y,{get iconNode(){return U},children:(k,N)=>{var w=me(),L=B(w);pt(L,a,"default",{}),f(k,w)},$$slots:{default:!0}}))}function Ut(pe,a){const Y=vt(a,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const U=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"}]];mt(pe,ft({name:"square-pen"},()=>Y,{get iconNode(){return U},children:(k,N)=>{var w=me(),L=B(w);pt(L,a,"default",{}),f(k,w)},$$slots:{default:!0}}))}var Vt=F('<p class="text-sm text-muted-foreground">Loading models...</p>'),Ht=F('<p class="text-sm text-muted-foreground">No probed models available. <a class="text-primary hover:underline">Download and probe a model</a> first.</p>'),Gt=F("<option> </option>"),Yt=F('<p class="text-xs text-muted-foreground mt-1"> <!></p>'),Jt=F('<select id="modelSelect" class="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"><option>Select a model...</option><!></select> <!>',1),Kt=F('<span class="text-amber-500">(long prompt may affect performance)</span>'),Qt=F('<span class="text-xs text-muted-foreground ml-2"> <!></span>'),Wt=F(`<div><label for="systemPrompt" class="block text-sm font-medium mb-1">System Prompt <!></label> <textarea id="systemPrompt" placeholder="e.g., You are a helpful coding assistant specializing in Python..." rows="4" class="flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"></textarea> <p class="text-xs text-muted-foreground mt-1">Sets the model's behavior context. Appears as first message when chatting.</p></div>`),Xt=F('<div class="pt-4 border-t"><h3 class="text-sm font-medium mb-3">Generation Settings</h3> <p class="text-xs text-muted-foreground mb-4">Control how the model generates responses. These can be overridden per-request.</p> <div class="space-y-4"><div><label for="temperature" class="block text-sm font-medium mb-1"> </label> <input id="temperature" type="range" min="0" max="2" step="0.1" class="w-full h-2 bg-muted rounded-lg appearance-none cursor-pointer"/> <div class="flex justify-between text-xs text-muted-foreground mt-1"><span>Deterministic (0)</span> <span>Creative (2)</span></div></div> <div><label for="maxTokens" class="block text-sm font-medium mb-1">Max Tokens</label> <input id="maxTokens" type="number" min="1" max="128000" placeholder="4096" class="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"/> <p class="text-xs text-muted-foreground mt-1">Maximum number of tokens to generate (1-128,000).</p></div> <div><label for="topP" class="block text-sm font-medium mb-1"> </label> <input id="topP" type="range" min="0" max="1" step="0.05" class="w-full h-2 bg-muted rounded-lg appearance-none cursor-pointer"/> <div class="flex justify-between text-xs text-muted-foreground mt-1"><span>Focused (0)</span> <span>Diverse (1)</span></div></div></div></div>'),Zt=F('<div class="pt-4 border-t"><h3 class="text-sm font-medium mb-3">Audio Settings</h3> <div class="space-y-4"><div><label for="ttsVoice" class="block text-sm font-medium mb-1">Default Voice</label> <!></div> <div><label for="ttsSpeed" class="block text-sm font-medium mb-1"> </label> <input id="ttsSpeed" type="range" min="0.25" max="4" step="0.25" class="w-full h-2 bg-muted rounded-lg appearance-none cursor-pointer"/> <div class="flex justify-between text-xs text-muted-foreground mt-1"><span>Slow (0.25x)</span> <span>Fast (4x)</span></div></div> <div><label for="ttsSampleRate" class="block text-sm font-medium mb-1">Sample Rate</label> <input id="ttsSampleRate" type="number" placeholder="24000" class="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"/></div> <div><label for="sttLanguage" class="block text-sm font-medium mb-1">STT Language</label> <!></div></div></div>'),$t=F('<div class="space-y-1"><label class="flex items-center gap-2"><input type="checkbox" class="rounded"/> <span class="text-sm"> </span></label> <p class="text-xs text-muted-foreground ml-6"> </p></div>'),ea=F('<div><label class="block text-sm font-medium mb-1"> </label> <!> <p class="text-xs text-muted-foreground mt-1"> </p></div>'),ta=F(`<div class="pt-4 border-t"><h3 class="text-sm font-medium mb-3">Model Options</h3> <p class="text-xs text-muted-foreground mb-4">Options discovered from this model's chat template. Changes affect how the model processes conversations.</p> <div class="space-y-3"></div></div>`),aa=F(`<div class="space-y-2"><label class="flex items-center gap-2"><input type="checkbox" class="rounded"/> <span class="text-sm">Enable experimental tool support (via prompt injection)</span></label> <p class="text-xs text-muted-foreground ml-6">Experimental: Enables tool calling for models without native support by
								injecting tool descriptions into the system prompt. Results may vary.</p></div>`),ra=F('<div class="space-y-4 pt-4 border-t"><div class="space-y-2"><label class="flex items-center gap-2"><input type="checkbox" class="rounded"/> <span class="text-sm">Auto-load on startup</span></label> <p class="text-xs text-muted-foreground ml-6">Preload this model when the server starts for faster first response.</p></div> <!></div>'),la=F('<div class="mt-4 text-sm text-red-500 dark:text-red-400"> </div>'),ia=F('<h2 class="text-xl font-semibold mb-6"> </h2> <div class="space-y-4"><div><label for="name" class="block text-sm font-medium mb-1">Name *</label> <!></div> <div><label for="description" class="block text-sm font-medium mb-1">Description</label> <textarea id="description" placeholder="Optional description" rows="2" class="flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"></textarea></div> <div><label for="modelSelect" class="block text-sm font-medium mb-1">Model *</label> <!></div> <!> <!> <!> <!> <div class="pt-4"><button type="button" class="text-sm text-primary hover:underline"> </button></div> <!></div> <!> <div class="mt-6 flex justify-end gap-3"><!> <!></div>',1),sa=F("<form><!></form>");function Ia(pe,a){nt(a,!0);let Y=P(!1),U=P(null),k=P(Ze([])),N=P(!0),w=P(""),L=P(""),J=P(""),K=P(null),te=P(!1),_e=P(null),Q=P(null),X=P(null),ae=P(!1),se=P(null),re=P(null),Se=P(null),oe=P(null),V=P(Ze({})),ge=P(!1);const H=O(()=>e(k).find(C=>C.id===(typeof e(K)=="number"?e(K):null))),ze=O(()=>{var C;return((C=e(H))==null?void 0:C.model_type)??null}),ne=O(()=>e(ze)==="text-gen"||e(ze)==="vision"),Ae=O(()=>e(ze)==="audio"),Le=O(()=>{var C,R;return((R=(C=e(H))==null?void 0:C.capabilities)==null?void 0:R.template_params)??null});yt(async()=>{try{const C=await wt.listDownloaded();t(k,C.filter(R=>R.probed_at!=null),!0)}catch(C){console.error("Failed to load models:",C)}finally{t(N,!1)}}),Ge(()=>{var C,R,c,M,le,Z,$,de,ee,be,ie,Fe,Ce,De,xe,he,ye,ke,ue,Me,ce,we,ve;t(w,((C=a.profile)==null?void 0:C.name)??"",!0),t(L,((R=a.profile)==null?void 0:R.description)??"",!0),t(J,((M=(c=a.profile)==null?void 0:c.context)==null?void 0:M.system_prompt)??"",!0),t(K,((le=a.profile)==null?void 0:le.model_id)??a.initialModelId??null,!0),t(te,((Z=a.profile)==null?void 0:Z.auto_start)??!1,!0),t(_e,((de=($=a.profile)==null?void 0:$.inference)==null?void 0:de.temperature)??null,!0),t(Q,((be=(ee=a.profile)==null?void 0:ee.inference)==null?void 0:be.max_tokens)??null,!0),t(X,((Fe=(ie=a.profile)==null?void 0:ie.inference)==null?void 0:Fe.top_p)??null,!0),t(ae,((De=(Ce=a.profile)==null?void 0:Ce.context)==null?void 0:De.enable_tool_injection)??!1,!0),t(se,((he=(xe=a.profile)==null?void 0:xe.audio)==null?void 0:he.tts_voice)??null,!0),t(re,((ke=(ye=a.profile)==null?void 0:ye.audio)==null?void 0:ke.tts_speed)??null,!0),t(Se,((Me=(ue=a.profile)==null?void 0:ue.audio)==null?void 0:Me.tts_sample_rate)??null,!0),t(oe,((we=(ce=a.profile)==null?void 0:ce.audio)==null?void 0:we.stt_language)??null,!0),t(V,((ve=a.profile)==null?void 0:ve.model_options)??{},!0)});async function Ye(C){C.preventDefault();const R=typeof e(K)=="number"?e(K):null;if(!R){t(U,"Please select a model");return}t(Y,!0),t(U,null);try{const c={name:e(w),description:e(L)||void 0,model_id:R,auto_start:e(te),inference:e(ne)?{temperature:e(_e)??null,max_tokens:e(Q)??null,top_p:e(X)??null}:void 0,context:e(ne)?{context_length:null,system_prompt:e(J)||null,enable_tool_injection:e(ae)}:void 0,audio:e(Ae)?{tts_voice:e(se)??null,tts_speed:e(re)??null,tts_sample_rate:e(Se)??null,stt_language:e(oe)??null}:void 0,model_options:Object.keys(e(V)).length>0?e(V):void 0};await a.onSubmit(c)}catch(c){t(U,c instanceof Error?c.message:"Failed to save profile",!0)}finally{t(Y,!1)}}function Je(C){const R=C.model_type??"unknown",c=C.size_gb?` (${C.size_gb} GB)`:"";return`${C.repo_id}${c} [${R}]`}var Te=sa(),Re=i(Te);_t(Re,{class:"p-6",children:(C,R)=>{var c=ia(),M=B(c),le=i(M,!0);l(M);var Z=s(M,2),$=i(Z),de=s(i($),2);Ve(de,{id:"name",placeholder:"e.g., Coding Assistant",required:!0,get value(){return e(w)},set value(r){t(w,r,!0)}}),l($);var ee=s($,2),be=s(i(ee),2);$e(be),l(ee);var ie=s(ee,2),Fe=s(i(ie),2);{var Ce=r=>{var o=Vt();f(r,o)},De=r=>{var o=me(),u=B(o);{var p=v=>{var n=Ht(),d=s(i(n));A(),l(n),I(_=>tt(d,"href",_),[()=>gt("/models")]),f(v,n)},y=v=>{var n=Jt(),d=B(n),_=i(d);_.value=_.__value="";var x=s(_);et(x,17,()=>e(k),m=>m.id,(m,g)=>{var S=Gt(),E=i(S,!0);l(S);var q={};I(G=>{D(E,G),q!==(q=e(g).id)&&(S.value=(S.__value=e(g).id)??"")},[()=>Je(e(g))]),f(m,S)}),l(d);var h=s(d,2);{var z=m=>{var g=Yt(),S=i(g),E=s(S);{var q=G=>{var j=Pe();I(()=>D(j,`| Size: ${e(H).size_gb??""} GB`)),f(G,j)};T(E,G=>{e(H).size_gb&&G(q)})}l(g),I(()=>D(S,`Type: ${e(H).model_type??"unknown"??""} `)),f(m,g)};T(h,m=>{e(H)&&m(z)})}Pt(d,()=>e(K),m=>t(K,m)),f(v,n)};T(u,v=>{e(k).length===0?v(p):v(y,!1)},!0)}f(r,o)};T(Fe,r=>{e(N)?r(Ce):r(De,!1)})}l(ie);var xe=s(ie,2);{var he=r=>{var o=Wt(),u=i(o),p=s(i(u));{var y=n=>{var d=Qt(),_=i(d),x=s(_);{var h=z=>{var m=Kt();f(z,m)};T(x,z=>{e(J).length>2e3&&z(h)})}l(d),I(()=>D(_,`${e(J).length??""} chars `)),f(n,d)};T(p,n=>{e(J).length>0&&n(y)})}l(u);var v=s(u,2);$e(v),A(2),l(o),lt(v,()=>e(J),n=>t(J,n)),f(r,o)};T(xe,r=>{e(ne)&&r(he)})}var ye=s(xe,2);{var ke=r=>{var o=Xt(),u=s(i(o),4),p=i(u),y=i(p),v=i(y);l(y);var n=s(y,2);fe(n),n.__input=g=>t(_e,parseFloat(g.currentTarget.value),!0),A(2),l(p);var d=s(p,2),_=s(i(d),2);fe(_),_.__input=g=>t(Q,parseInt(g.currentTarget.value)||null,!0),A(2),l(d);var x=s(d,2),h=i(x),z=i(h);l(h);var m=s(h,2);fe(m),m.__input=g=>t(X,parseFloat(g.currentTarget.value),!0),A(2),l(x),l(u),l(o),I((g,S)=>{D(v,`Temperature: ${g??""}`),je(n,e(_e)??.7),je(_,e(Q)??4096),D(z,`Top P (Nucleus Sampling): ${S??""}`),je(m,e(X)??1)},[()=>(e(_e)??.7).toFixed(1),()=>(e(X)??1).toFixed(2)]),f(r,o)};T(ye,r=>{e(ne)&&r(ke)})}var ue=s(ye,2);{var Me=r=>{var o=Zt(),u=s(i(o),2),p=i(u),y=s(i(p),2);{let g=O(()=>e(se)??"");Ve(y,{id:"ttsVoice",get value(){return e(g)},oninput:S=>{const E=S.currentTarget;t(se,E.value||null,!0)},placeholder:"e.g., af_heart"})}l(p);var v=s(p,2),n=i(v),d=i(n);l(n);var _=s(n,2);fe(_),_.__input=g=>t(re,parseFloat(g.currentTarget.value),!0),A(2),l(v);var x=s(v,2),h=s(i(x),2);fe(h),h.__input=g=>t(Se,parseInt(g.currentTarget.value)||null,!0),l(x);var z=s(x,2),m=s(i(z),2);{let g=O(()=>e(oe)??"");Ve(m,{id:"sttLanguage",get value(){return e(g)},oninput:S=>{const E=S.currentTarget;t(oe,E.value||null,!0)},placeholder:"e.g., en"})}l(z),l(u),l(o),I(g=>{D(d,`Speech Speed: ${g??""}x`),je(_,e(re)??1),je(h,e(Se)??"")},[()=>(e(re)??1).toFixed(1)]),f(r,o)};T(ue,r=>{e(Ae)&&r(Me)})}var ce=s(ue,2);{var we=r=>{var o=ta(),u=s(i(o),4);et(u,21,()=>Object.entries(e(Le)),([p,y])=>p,(p,y)=>{var v=O(()=>kt(e(y),2));let n=()=>e(v)[0],d=()=>e(v)[1];var _=me(),x=B(_);{var h=m=>{var g=$t(),S=i(g),E=i(S);fe(E),E.__change=Ie=>{t(V,{...e(V),[n()]:Ie.currentTarget.checked},!0)};var q=s(E,2),G=i(q,!0);l(q),l(S);var j=s(S,2),Xe=i(j,!0);l(j),l(g),I(Ie=>{St(E,Ie),D(G,d().label),D(Xe,d().description)},[()=>e(V)[n()]!==void 0?!!e(V)[n()]:!!d().default]),f(m,g)},z=m=>{var g=ea(),S=i(g),E=i(S,!0);l(S);var q=s(S,2);{let Xe=O(()=>`opt-${n()}`),Ie=O(()=>String(e(V)[n()]??d().default??"")),bt=O(()=>d().default?String(d().default):"");Ve(q,{get id(){return e(Xe)},get value(){return e(Ie)},oninput:xt=>{const ht=xt.currentTarget;t(V,{...e(V),[n()]:ht.value||null},!0)},get placeholder(){return e(bt)}})}var G=s(q,2),j=i(G,!0);l(G),l(g),I(()=>{tt(S,"for",`opt-${n()}`),D(E,d().label),D(j,d().description)}),f(m,g)};T(x,m=>{d().param_type==="bool"?m(h):m(z,!1)})}f(p,_)}),l(u),l(o),f(r,o)};T(ce,r=>{e(Le)&&Object.keys(e(Le)).length>0&&r(we)})}var ve=s(ce,2),Ee=i(ve);Ee.__click=()=>t(ge,!e(ge));var Be=i(Ee);l(Ee),l(ve);var Ne=s(ve,2);{var Ke=r=>{var o=ra(),u=i(o),p=i(u),y=i(p);fe(y),A(2),l(p),A(2),l(u);var v=s(u,2);{var n=d=>{var _=aa(),x=i(_),h=i(x);fe(h),A(2),l(x),A(2),l(_),it(h,()=>e(ae),z=>t(ae,z)),f(d,_)};T(v,d=>{e(ne)&&d(n)})}l(o),it(y,()=>e(te),d=>t(te,d)),f(r,o)};T(Ne,r=>{e(ge)&&r(Ke)})}l(Z);var Oe=s(Z,2);{var Qe=r=>{var o=la(),u=i(o,!0);l(o),I(()=>D(u,e(U))),f(r,o)};T(Oe,r=>{e(U)&&r(Qe)})}var qe=s(Oe,2),Ue=i(qe);W(Ue,{variant:"outline",get onclick(){return a.onCancel},get disabled(){return e(Y)},children:(r,o)=>{A();var u=Pe("Cancel");f(r,u)},$$slots:{default:!0}});var We=s(Ue,2);{let r=O(()=>e(Y)||typeof e(K)!="number");W(We,{type:"submit",get disabled(){return e(r)},children:(o,u)=>{A();var p=Pe();I(()=>D(p,e(Y)?"Saving...":a.profile?"Update Profile":"Create Profile")),f(o,p)},$$slots:{default:!0}})}l(qe),I(()=>{D(le,a.profile?"Edit Profile":"Create Profile"),D(Be,`${e(ge)?"Hide":"Show"} Advanced Options`)}),lt(be,()=>e(L),r=>t(L,r)),f(C,c)},$$slots:{default:!0}}),l(Te),ct("submit",Te,Ye),f(pe,Te),dt()}ut(["input","change","click"]);var oa=F('<p class="text-sm text-muted-foreground mt-1"> </p>'),na=F("<!> <!> <!>",1),da=F("<!> <!>",1),ua=F('<div class="mt-4 grid grid-cols-2 md:grid-cols-3 gap-4 text-sm"><div class="flex items-center gap-2"><!> <span class="text-muted-foreground">PID:</span> <span class="font-mono"> </span></div> <div class="flex items-center gap-2"><!> <span class="text-muted-foreground">Memory:</span> <span> </span></div> <div class="flex items-center gap-2"><!> <span class="text-muted-foreground">Uptime:</span> <span> </span></div></div>'),ca=F('<div class="mt-3 flex items-center gap-4 text-sm text-muted-foreground"><div class="flex items-center gap-2"><span>Type:</span> <span> </span></div></div>'),va=F('<details class="mt-2"><summary class="text-xs text-red-500 dark:text-red-400 cursor-pointer hover:underline">Show server log</summary> <div class="mt-2 relative"><button class="absolute top-2 right-2 p-1.5 rounded bg-red-200 dark:bg-red-800 hover:bg-red-300 dark:hover:bg-red-700 transition-colors" title="Copy to clipboard"><!></button> <pre class="text-xs text-red-600 dark:text-red-300 bg-red-100 dark:bg-red-900/50 p-2 pr-10 rounded overflow-x-auto max-h-48 whitespace-pre-wrap font-mono"> </pre></div></details>'),fa=F('<div class="mt-3 p-3 bg-red-50 dark:bg-red-950/50 rounded-lg border border-red-200 dark:border-red-900"><div class="flex items-start gap-2"><!> <div class="flex-1 min-w-0"><p class="text-sm text-red-600 dark:text-red-400 font-medium"> </p> <!></div></div></div>'),ma=F('<div class="flex items-start justify-between gap-4"><div class="flex-1 min-w-0"><div class="flex items-center gap-2 flex-wrap"><h3 class="font-semibold text-lg"> </h3> <!> <!></div> <!> <div class="mt-2 text-sm text-muted-foreground truncate"><span class="font-mono"> </span></div></div> <div class="flex shrink-0 gap-1"><!> <!> <!> <!></div></div> <!> <!>',1),pa=F("<!> <!>",1);function ja(pe,a){nt(a,!0);const Y=12e4,U=2e3;let k=P(!1),N=P(null),w=P(null),L=P(!1),J=P(!1);const K=O(()=>b.isStarting(a.profile.id)),te=O(()=>b.isRunning(a.profile.id)),_e=O(()=>b.isFailed(a.profile.id)),Q=O(()=>b.getFailure(a.profile.id)),X=O(()=>a.server||b.getServer(a.profile.id));let ae=P(!1),se=!1,re=P(null);Ge(()=>{const c=b.getFailure(a.profile.id);c&&e(re)!==a.profile.id?(t(re,a.profile.id,!0),se=!0,t(ae,c.detailsOpen,!0),requestAnimationFrame(()=>{se=!1})):c||(t(re,null),t(ae,!1))});function Se(){se||b.toggleDetailsOpen(a.profile.id)}let oe=P(!1);async function V(){var c;if((c=e(Q))!=null&&c.details)try{await navigator.clipboard.writeText(e(Q).details),t(oe,!0),setTimeout(()=>{t(oe,!1)},2e3)}catch(M){console.error("Failed to copy to clipboard:",M)}}let ge=P(!1);Ge(()=>{e(ge)||(t(ge,!0),b.isStarting(a.profile.id)&&!b.isProfilePolling(a.profile.id)&&b.startProfilePolling(a.profile.id)&&(t(L,!0),t(N,Date.now(),!0),H()))}),Ge(()=>()=>{e(w)&&(clearTimeout(e(w)),t(w,null)),e(L)&&(t(L,!1),b.stopProfilePolling(a.profile.id))});async function H(){if(!e(L)){b.stopProfilePolling(a.profile.id);return}if(e(N)&&Date.now()-e(N)>Y){b.markStartupFailed(a.profile.id,"Model loading timed out after 2 minutes. Check server logs for details."),t(L,!1),t(w,null),b.stopProfilePolling(a.profile.id);return}try{const c=await at.status(a.profile.id);if(!c.running){c.failed?b.markStartupFailed(a.profile.id,"Server crashed while loading model",c.error_message||"Server process exited unexpectedly"):b.markStartupSuccess(a.profile.id),t(L,!1),t(w,null),b.stopProfilePolling(a.profile.id);return}try{const M=await at.health(a.profile.id);if(M.status==="healthy"&&M.model_loaded){b.markStartupSuccess(a.profile.id),t(L,!1),t(w,null),b.stopProfilePolling(a.profile.id);return}}catch{}t(w,setTimeout(H,U),!0)}catch{t(w,setTimeout(H,U),!0)}}async function ze(){if(t(k,!0),b.clearFailure(a.profile.id),t(N,Date.now(),!0),e(w)&&(clearTimeout(e(w)),t(w,null)),!b.startProfilePolling(a.profile.id)){t(k,!1);return}t(L,!0);try{await b.start(a.profile.id),H()}catch(c){const M=c instanceof Error?c.message:"Failed to start server";b.markStartupFailed(a.profile.id,M),t(N,null),t(L,!1),b.stopProfilePolling(a.profile.id)}finally{t(k,!1)}}async function ne(){t(k,!0),t(N,null),t(L,!1),e(w)&&(clearTimeout(e(w)),t(w,null)),b.stopProfilePolling(a.profile.id);try{await b.stop(a.profile.id)}catch(c){const M=c instanceof Error?c.message:"Failed to stop server";b.markStartupFailed(a.profile.id,M)}finally{t(k,!1)}}async function Ae(){if(t(k,!0),b.clearFailure(a.profile.id),t(N,Date.now(),!0),e(w)&&(clearTimeout(e(w)),t(w,null)),b.stopProfilePolling(a.profile.id),!b.startProfilePolling(a.profile.id)){t(k,!1);return}t(L,!0);try{await b.restart(a.profile.id),H()}catch(c){const M=c instanceof Error?c.message:"Failed to restart server";b.markStartupFailed(a.profile.id,M),t(N,null),t(L,!1),b.stopProfilePolling(a.profile.id)}finally{t(k,!1)}}function Le(){t(J,!0)}async function Ye(){t(k,!0),b.clearFailure(a.profile.id);try{e(te)&&await b.stop(a.profile.id),await rt.delete(a.profile.id)}catch(c){const M=c instanceof Error?c.message:"Failed to delete profile";b.markStartupFailed(a.profile.id,M)}finally{t(k,!1)}}async function Je(){const c=prompt("Enter name for the duplicate profile:",`${a.profile.name} (copy)`);if(c){t(k,!0);try{await rt.duplicate(a.profile.id,c)}catch(M){const le=M instanceof Error?M.message:"Failed to duplicate profile";alert(le)}finally{t(k,!1)}}}async function Te(){const c=`${gt("/chat")}?profile=${a.profile.id}`;await Et(c)}var Re=pa(),C=B(Re);_t(C,{class:"p-4",children:(c,M)=>{var le=ma(),Z=B(le),$=i(Z),de=i($),ee=i(de),be=i(ee,!0);l(ee);var ie=s(ee,2);{var Fe=r=>{He(r,{variant:"destructive",children:(o,u)=>{A();var p=Pe("Error");f(o,p)},$$slots:{default:!0}})},Ce=r=>{var o=me(),u=B(o);{var p=v=>{He(v,{variant:"success",children:(n,d)=>{A();var _=Pe("Running");f(n,_)},$$slots:{default:!0}})},y=v=>{var n=me(),d=B(n);{var _=x=>{He(x,{variant:"warning",children:(h,z)=>{A();var m=Pe("Loading...");f(h,m)},$$slots:{default:!0}})};T(d,x=>{e(K)&&x(_)},!0)}f(v,n)};T(u,v=>{e(te)?v(p):v(y,!1)},!0)}f(r,o)};T(ie,r=>{e(_e)?r(Fe):r(Ce,!1)})}var De=s(ie,2);{var xe=r=>{He(r,{variant:"outline",children:(o,u)=>{A();var p=Pe("launchd");f(o,p)},$$slots:{default:!0}})};T(De,r=>{a.profile.launchd_installed&&r(xe)})}l(de);var he=s(de,2);{var ye=r=>{var o=oa(),u=i(o,!0);l(o),I(()=>D(u,a.profile.description)),f(r,o)};T(he,r=>{a.profile.description&&r(ye)})}var ke=s(he,2),ue=i(ke),Me=i(ue,!0);l(ue),l(ke),l($);var ce=s($,2),we=i(ce);{var ve=r=>{var o=na(),u=B(o);{var p=n=>{W(n,{variant:"outline",size:"sm",onclick:Te,get disabled(){return e(k)},title:"Chat",children:(d,_)=>{Nt(d,{class:"h-4 w-4"})},$$slots:{default:!0}})};T(u,n=>{Ft(a.profile.model_type)&&n(p)})}var y=s(u,2);W(y,{variant:"outline",size:"sm",onclick:Ae,get disabled(){return e(k)},title:"Restart",children:(n,d)=>{Mt(n,{class:"h-4 w-4"})},$$slots:{default:!0}});var v=s(y,2);W(v,{variant:"destructive",size:"sm",onclick:ne,get disabled(){return e(k)},title:"Stop",children:(n,d)=>{ot(n,{class:"h-4 w-4"})},$$slots:{default:!0}}),f(r,o)},Ee=r=>{var o=me(),u=B(o);{var p=v=>{var n=da(),d=B(n);W(d,{variant:"outline",size:"sm",disabled:!0,title:"Starting...",children:(x,h)=>{st(x,{class:"h-4 w-4 animate-spin"})},$$slots:{default:!0}});var _=s(d,2);W(_,{variant:"destructive",size:"sm",onclick:ne,get disabled(){return e(k)},title:"Cancel",children:(x,h)=>{ot(x,{class:"h-4 w-4"})},$$slots:{default:!0}}),f(v,n)},y=v=>{W(v,{variant:"default",size:"sm",onclick:ze,get disabled(){return e(k)},title:"Start",children:(n,d)=>{var _=me(),x=B(_);{var h=m=>{st(m,{class:"h-4 w-4 animate-spin"})},z=m=>{It(m,{class:"h-4 w-4"})};T(x,m=>{e(k)?m(h):m(z,!1)})}f(n,_)},$$slots:{default:!0}})};T(u,v=>{e(K)?v(p):v(y,!1)},!0)}f(r,o)};T(we,r=>{e(te)?r(ve):r(Ee,!1)})}var Be=s(we,2);{let r=O(()=>`/profiles/${a.profile.id}`);W(Be,{variant:"outline",size:"sm",get href(){return e(r)},title:"Edit",children:(o,u)=>{Ut(o,{class:"h-4 w-4"})},$$slots:{default:!0}})}var Ne=s(Be,2);W(Ne,{variant:"outline",size:"sm",onclick:Je,get disabled(){return e(k)},title:"Duplicate",children:(r,o)=>{Tt(r,{class:"h-4 w-4"})},$$slots:{default:!0}});var Ke=s(Ne,2);W(Ke,{variant:"outline",size:"sm",onclick:Le,get disabled(){return e(k)},title:"Delete",children:(r,o)=>{jt(r,{class:"h-4 w-4"})},$$slots:{default:!0}}),l(ce),l(Z);var Oe=s(Z,2);{var Qe=r=>{var o=ua(),u=i(o),p=i(u);Rt(p,{class:"w-4 h-4 text-muted-foreground"});var y=s(p,4),v=i(y,!0);l(y),l(u);var n=s(u,2),d=i(n);Bt(d,{class:"w-4 h-4 text-muted-foreground"});var _=s(d,4),x=i(_);l(_),l(n);var h=s(n,2),z=i(h);qt(z,{class:"w-4 h-4 text-muted-foreground"});var m=s(z,4),g=i(m,!0);l(m),l(h),l(o),I((S,E)=>{D(v,e(X).pid),D(x,`${S??""} MB`),D(g,E)},[()=>e(X).memory_mb.toFixed(1),()=>Ot(e(X).uptime_seconds)]),f(r,o)},qe=r=>{var o=ca(),u=i(o),p=s(i(u),2),y=i(p,!0);l(p),l(u),l(o),I(()=>D(y,a.profile.model_type??"unknown")),f(r,o)};T(Oe,r=>{e(X)&&e(te)?r(Qe):r(qe,!1)})}var Ue=s(Oe,2);{var We=r=>{var o=fa(),u=i(o),p=i(u);Ct(p,{class:"w-4 h-4 text-red-500 dark:text-red-400 mt-0.5 flex-shrink-0"});var y=s(p,2),v=i(y),n=i(v,!0);l(v);var d=s(v,2);{var _=x=>{var h=va(),z=s(i(h),2),m=i(z);m.__click=V;var g=i(m);{var S=j=>{Dt(j,{class:"w-3.5 h-3.5 text-green-600 dark:text-green-400"})},E=j=>{Lt(j,{class:"w-3.5 h-3.5 text-red-600 dark:text-red-300"})};T(g,j=>{e(oe)?j(S):j(E,!1)})}l(m);var q=s(m,2),G=i(q,!0);l(q),l(z),l(h),I(()=>D(G,e(Q).details)),ct("toggle",h,Se),zt("open","toggle",h,j=>t(ae,j),()=>e(ae)),f(x,h)};T(d,x=>{e(Q).details&&x(_)})}l(y),l(u),l(o),I(()=>D(n,e(Q).error)),f(r,o)};T(Ue,r=>{e(Q)&&r(We)})}I(()=>{D(be,a.profile.name),D(Me,a.profile.model_repo_id??"Unknown model")}),f(c,le)},$$slots:{default:!0}});var R=s(C,2);At(R,{title:"Delete Profile",get description(){return`Are you sure you want to delete '${a.profile.name??""}'? This action cannot be undone.`},confirmLabel:"Delete",cancelLabel:"Cancel",variant:"destructive",onConfirm:Ye,onCancel:()=>{},get open(){return e(J)},set open(c){t(J,c,!0)}}),f(pe,Re),dt()}ut(["click"]);export{ja as P,Ia as a};
