import{$ as e,A as t,B as n,G as r,I as i,K as a,L as o,M as s,N as c,O as l,Q as u,W as d,X as f,Z as p,ct as m,f as h,ft as g,it as _,j as v,k as y,nt as b,r as x,rt as S,st as C,tt as w,x as T}from"../chunks/BBI__kVO.js";import"../chunks/xihTtKlq.js";import{t as E}from"../chunks/Cub6afmL.js";import{a as D,o as O,t as k}from"../chunks/DMSxHu0j.js";var A=c(`<iframe class="opencode-frame svelte-1z0msvj" title="OpenCode — Advanced Chat" allow="clipboard-read; clipboard-write; microphone"></iframe>`),j=c(`<p class="status-line svelte-1z0msvj"> </p>`),M=c(`<h2 class="svelte-1z0msvj"> </h2> <p class="svelte-1z0msvj">The connection looks dead or its session expired. Reconnect to try again, or pick a different assistant from the switcher above.</p> <button class="btn btn-primary btn-lg svelte-1z0msvj"> </button>`,1),N=c(`<div class="advanced-status svelte-1z0msvj" aria-live="polite"><!></div>`),P=c(`<!> <div class="advanced-layout svelte-1z0msvj"><!></div>`,1);function F(i,c){m(c,!0);let F=_(()=>D.active),I=_(()=>E.url.searchParams.get(`session`)),L=b(``),R=b(`checking`),z=b(!1),B=b(0),V=0;async function H(){let e=++V;w(R,`checking`);let t=n(F)?.url??`http://127.0.0.1:3800`;try{let r=await fetch(`/proxy/assistant/`,{headers:{accept:`text/html`}});if(e!==V)return;if(!r.ok){w(R,`dead`);return}let i=t;if(n(I)){let r=await fetch(`/proxy/assistant/session/${encodeURIComponent(n(I))}`,{headers:{accept:`application/json`}});if(e!==V)return;if(r.ok){let a=await r.json().catch(()=>null);if(e!==V)return;i=O(t,n(I),a?.directory)}}w(L,i,!0),w(R,`ready`)}catch{if(e!==V)return;w(R,`dead`)}}async function U(){if(!n(z)){w(z,!0);try{await D.load(!0),await H(),n(R)===`ready`&&S(B)}finally{w(z,!1)}}}a(()=>{n(F)?.id&&(n(I),H())}),x(()=>(document.documentElement.classList.add(`chat-locked`),document.body.classList.add(`chat-locked`),D.load(),()=>{document.documentElement.classList.remove(`chat-locked`),document.body.classList.remove(`chat-locked`)}));var W=P();T(`1z0msvj`,e=>{d(()=>{f.title=`Advanced Chat — OpenPalm`})});var G=u(W);k(G,{});var K=e(G,2),q=p(K),J=e=>{var t=s();l(u(t),()=>n(B),e=>{var t=A();r(()=>h(t,`src`,n(L))),v(e,t)}),v(e,t)},Y=i=>{var a=N(),s=p(a),c=e=>{var i=j(),a=p(i);g(i),r(()=>t(a,`Connecting to ${n(F)?.label??`your assistant`??``}…`)),v(e,i)},l=i=>{var a=M(),s=u(a),c=p(s);g(s);var l=e(s,4),d=p(l,!0);g(l),r(()=>{t(c,`Can’t reach ${n(F)?.label??`your assistant`??``}`),l.disabled=n(z),t(d,n(z)?`Reconnecting…`:`Reconnect`)}),o(`click`,l,U),v(i,a)};y(s,e=>{n(R)===`checking`?e(c):e(l,-1)}),g(a),r(()=>h(a,`role`,n(R)===`dead`?`alert`:`status`)),v(i,a)};y(q,e=>{n(R)===`ready`?e(J):e(Y,-1)}),g(K),v(i,W),C()}i([`click`]);export{F as component};