import{c as C,a as v,f as D,t as X}from"./vfPE-AD7.js";import"./1jpszzm8.js";import{i as b,p as Ie,j as He,g as a,u as J,s as I,d as t,e as o,r as i,f as c,t as W,n as G,c as Oe}from"./DhUiKsxN.js";import{I as T,a as F,b as je}from"./QNXDtpsh.js";import{l as q,b as A,i as z}from"./DUil1G3I.js";import{s as S}from"./Dsv8gxIT.js";import{g as Ue}from"./b2QY-nV2.js";import{r as Ve}from"./DyqxJaEr.js";import{s as H,L as pe}from"./SjYvl9yQ.js";import{p as _e}from"./DEcqogKB.js";import{T as We,B as Y,H as Ge,a as Je}from"./CPs-cmJs.js";import{C as Ke,B as O}from"./BWzyK28a.js";import{M as Qe,C as Xe}from"./AByEuEpv.js";function he(x,e){const y=q(e,["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 g=[["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"}]];T(x,A({name:"activity"},()=>y,{get iconNode(){return g},children:(l,u)=>{var r=C(),f=b(r);F(f,e,"default",{}),v(l,r)},$$slots:{default:!0}}))}function Ye(x,e){const y=q(e,["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 g=[["circle",{cx:"12",cy:"12",r:"10"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16"}]];T(x,A({name:"circle-alert"},()=>y,{get iconNode(){return g},children:(l,u)=>{var r=C(),f=b(r);F(f,e,"default",{}),v(l,r)},$$slots:{default:!0}}))}function Ze(x,e){const y=q(e,["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 g=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"}]];T(x,A({name:"copy"},()=>y,{get iconNode(){return g},children:(l,u)=>{var r=C(),f=b(r);F(f,e,"default",{}),v(l,r)},$$slots:{default:!0}}))}function et(x,e){const y=q(e,["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 g=[["polygon",{points:"6 3 20 12 6 21 6 3"}]];T(x,A({name:"play"},()=>y,{get iconNode(){return g},children:(l,u)=>{var r=C(),f=b(r);F(f,e,"default",{}),v(l,r)},$$slots:{default:!0}}))}function Mt(x,e){const y=q(e,["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 g=[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]];T(x,A({name:"plus"},()=>y,{get iconNode(){return g},children:(l,u)=>{var r=C(),f=b(r);F(f,e,"default",{}),v(l,r)},$$slots:{default:!0}}))}function tt(x,e){const y=q(e,["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 g=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}],["path",{d:"M21 3v5h-5"}]];T(x,A({name:"rotate-cw"},()=>y,{get iconNode(){return g},children:(l,u)=>{var r=C(),f=b(r);F(f,e,"default",{}),v(l,r)},$$slots:{default:!0}}))}function at(x,e){const y=q(e,["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 g=[["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"}]];T(x,A({name:"square-pen"},()=>y,{get iconNode(){return g},children:(l,u)=>{var r=C(),f=b(r);F(f,e,"default",{}),v(l,r)},$$slots:{default:!0}}))}function rt(x,e){const y=q(e,["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 g=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}]];T(x,A({name:"square"},()=>y,{get iconNode(){return g},children:(l,u)=>{var r=C(),f=b(r);F(f,e,"default",{}),v(l,r)},$$slots:{default:!0}}))}var st=D('<p class="text-sm text-muted-foreground mt-1"> </p>'),lt=D("<!> Chat",1),nt=D("<!> <!> <!>",1),ot=D("<!> Start",1),it=D('<div class="mt-4 grid grid-cols-2 md:grid-cols-4 gap-4 text-sm"><div class="flex items-center gap-2"><!> <span class="text-muted-foreground">Port:</span> <span class="font-mono"> </span></div> <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>'),dt=D('<div class="mt-3 flex items-center gap-4 text-sm text-muted-foreground"><div class="flex items-center gap-2"><!> <span>Port:</span> <span class="font-mono"> </span></div> <div class="flex items-center gap-2"><span>Type:</span> <span> </span></div></div>'),ct=D('<details class="mt-2"><summary class="text-xs text-red-500 dark:text-red-400 cursor-pointer hover:underline">Show server log</summary> <pre class="mt-2 text-xs text-red-600 dark:text-red-300 bg-red-100 dark:bg-red-900/50 p-2 rounded overflow-x-auto max-h-48 whitespace-pre-wrap font-mono"> </pre></details>'),ft=D('<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>'),vt=D('<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 items-center gap-2 flex-shrink-0"><!> <!> <!> <!></div></div> <!> <!>',1);function Nt(x,e){Ie(e,!0);const y=12e4,g=5e3;let l=I(!1),u=I(null),r=I(!1),f=I(!1),B=I(null),L=I(!1),j=I(null);const U=J(()=>!!e.server||H.isRunning(e.profile.id)),K=J(()=>e.server||H.getServer(e.profile.id));He(()=>{a(U)&&!a(r)&&!a(f)&&Q(),a(U)||t(r,!1)});async function Q(){if(t(f,!0),a(B)&&Date.now()-a(B)>y){t(f,!1),t(L,!0),t(u,"Model loading timed out after 2 minutes. Check server logs for details.");return}try{const d=await je.status(e.profile.id);if(!d.running){if(d.failed){t(L,!0),t(j,d.error_message||"Server process exited unexpectedly",!0),t(u,"Server crashed while loading model"),t(f,!1),await H.refresh();return}t(f,!1);return}}catch{}try{const d=await fetch(`http://${e.profile.host}:${e.profile.port}/v1/models`);if(d.ok){const V=await d.json();t(r,V.data&&V.data.length>0,!0)}}catch{t(r,!1)}finally{t(f,!1)}a(U)&&!a(r)&&!a(L)&&setTimeout(Q,g)}async function ge(){t(l,!0),t(u,null),t(r,!1),t(L,!1),t(j,null),t(B,Date.now(),!0);try{await H.start(e.profile.id),Q()}catch(d){t(u,d instanceof Error?d.message:"Failed to start server",!0),t(B,null)}finally{t(l,!1)}}async function $e(){t(l,!0),t(u,null),t(r,!1),t(L,!1),t(j,null),t(B,null);try{await H.stop(e.profile.id)}catch(d){t(u,d instanceof Error?d.message:"Failed to stop server",!0)}finally{t(l,!1)}}async function xe(){t(l,!0),t(u,null),t(r,!1),t(L,!1),t(j,null),t(B,Date.now(),!0);try{await H.restart(e.profile.id),setTimeout(Q,g)}catch(d){t(u,d instanceof Error?d.message:"Failed to restart server",!0),t(B,null)}finally{t(l,!1)}}async function ye(){if(confirm("Are you sure you want to delete this profile?")){t(l,!0),t(u,null);try{a(U)&&await H.stop(e.profile.id),await _e.delete(e.profile.id)}catch(d){t(u,d instanceof Error?d.message:"Failed to delete profile",!0)}finally{t(l,!1)}}}async function we(){const d=prompt("Enter name for the duplicate profile:",`${e.profile.name} (copy)`);if(d){t(l,!0),t(u,null);try{await _e.duplicate(e.profile.id,d)}catch(V){t(u,V instanceof Error?V.message:"Failed to duplicate profile",!0)}finally{t(l,!1)}}}async function Pe(){const d=`${Ve("/chat")}?profile=${e.profile.id}`;await Ue(d)}Ke(x,{class:"p-4",children:(d,V)=>{var re=vt(),Z=b(re),ee=o(Z),te=o(ee),ae=o(te),be=o(ae,!0);i(ae);var se=c(ae,2);{var ke=s=>{var n=C(),p=b(n);{var $=m=>{Y(m,{variant:"destructive",children:(_,h)=>{G();var M=X("Error");v(_,M)},$$slots:{default:!0}})},P=m=>{var _=C(),h=b(_);{var M=w=>{Y(w,{variant:"success",children:(N,R)=>{G();var k=X("Ready");v(N,k)},$$slots:{default:!0}})},E=w=>{Y(w,{variant:"warning",children:(N,R)=>{G();var k=X("Loading...");v(N,k)},$$slots:{default:!0}})};z(h,w=>{a(r)?w(M):w(E,!1)},!0)}v(m,_)};z(p,m=>{a(L)?m($):m(P,!1)})}v(s,n)};z(se,s=>{(a(U)||a(L))&&s(ke)})}var Me=c(se,2);{var Ne=s=>{Y(s,{variant:"outline",children:(n,p)=>{G();var $=X("launchd");v(n,$)},$$slots:{default:!0}})};z(Me,s=>{e.profile.launchd_installed&&s(Ne)})}i(te);var le=c(te,2);{var ze=s=>{var n=st(),p=o(n,!0);i(n),W(()=>S(p,e.profile.description)),v(s,n)};z(le,s=>{e.profile.description&&s(ze)})}var ne=c(le,2),oe=o(ne),Se=o(oe,!0);i(oe),i(ne),i(ee);var ie=c(ee,2),de=o(ie);{var Ee=s=>{var n=nt(),p=b(n);{let m=J(()=>a(l)||!a(r)),_=J(()=>a(r)?"Chat with model":"Waiting for model to load...");O(p,{variant:"default",size:"sm",onclick:Pe,get disabled(){return a(m)},get title(){return a(_)},children:(h,M)=>{var E=lt(),w=b(E);{var N=k=>{pe(k,{class:"w-4 h-4 mr-1 animate-spin"})},R=k=>{Qe(k,{class:"w-4 h-4 mr-1"})};z(w,k=>{a(f)&&!a(r)?k(N):k(R,!1)})}G(),v(h,E)},$$slots:{default:!0}})}var $=c(p,2);O($,{variant:"outline",size:"icon",onclick:$e,get disabled(){return a(l)},title:"Stop",children:(m,_)=>{rt(m,{class:"w-4 h-4"})},$$slots:{default:!0}});var P=c($,2);O(P,{variant:"outline",size:"icon",onclick:xe,get disabled(){return a(l)},title:"Restart",children:(m,_)=>{tt(m,{class:"w-4 h-4"})},$$slots:{default:!0}}),v(s,n)},Ce=s=>{O(s,{variant:"default",size:"sm",onclick:ge,get disabled(){return a(l)},title:"Start",children:(n,p)=>{var $=ot(),P=b($);{var m=h=>{pe(h,{class:"w-4 h-4 mr-1 animate-spin"})},_=h=>{et(h,{class:"w-4 h-4 mr-1"})};z(P,h=>{a(l)?h(m):h(_,!1)})}G(),v(n,$)},$$slots:{default:!0}})};z(de,s=>{a(U)?s(Ee):s(Ce,!1)})}var ce=c(de,2);{let s=J(()=>`/profiles/${e.profile.id}`);O(ce,{variant:"outline",size:"icon",get href(){return a(s)},title:"Edit",children:(n,p)=>{at(n,{class:"w-4 h-4"})},$$slots:{default:!0}})}var fe=c(ce,2);O(fe,{variant:"outline",size:"icon",onclick:we,get disabled(){return a(l)},title:"Duplicate",children:(s,n)=>{Ze(s,{class:"w-4 h-4"})},$$slots:{default:!0}});var De=c(fe,2);O(De,{variant:"outline",size:"icon",onclick:ye,get disabled(){return a(l)},title:"Delete",children:(s,n)=>{We(s,{class:"w-4 h-4"})},$$slots:{default:!0}}),i(ie),i(Z);var ve=c(Z,2);{var Le=s=>{var n=it(),p=o(n),$=o(p);he($,{class:"w-4 h-4 text-muted-foreground"});var P=c($,4),m=o(P,!0);i(P),i(p);var _=c(p,2),h=o(_);Xe(h,{class:"w-4 h-4 text-muted-foreground"});var M=c(h,4),E=o(M,!0);i(M),i(_);var w=c(_,2),N=o(w);Ge(N,{class:"w-4 h-4 text-muted-foreground"});var R=c(N,4),k=o(R);i(R),i(w);var ue=c(w,2),me=c(o(ue),2),qe=o(me,!0);i(me),i(ue),i(n),W((Ae,Be)=>{S(m,e.profile.port),S(E,a(K).pid),S(k,`${Ae??""} MB`),S(qe,Be)},[()=>a(K).memory_mb.toFixed(1),()=>Je(a(K).uptime_seconds)]),v(s,n)},Re=s=>{var n=dt(),p=o(n),$=o(p);he($,{class:"w-4 h-4"});var P=c($,4),m=o(P,!0);i(P),i(p);var _=c(p,2),h=c(o(_),2),M=o(h,!0);i(h),i(_),i(n),W(()=>{S(m,e.profile.port),S(M,e.profile.model_type)}),v(s,n)};z(ve,s=>{a(K)?s(Le):s(Re,!1)})}var Te=c(ve,2);{var Fe=s=>{var n=ft(),p=o(n),$=o(p);Ye($,{class:"w-4 h-4 text-red-500 mt-0.5 flex-shrink-0"});var P=c($,2),m=o(P),_=o(m,!0);i(m);var h=c(m,2);{var M=E=>{var w=ct(),N=c(o(w),2),R=o(N,!0);i(N),i(w),W(()=>S(R,a(j))),v(E,w)};z(h,E=>{a(j)&&E(M)})}i(P),i(p),i(n),W(()=>S(_,a(u))),v(s,n)};z(Te,s=>{a(u)&&s(Fe)})}W(()=>{S(be,e.profile.name),S(Se,e.profile.model_path)}),v(d,re)},$$slots:{default:!0}}),Oe()}export{Mt as P,Nt as a};
