wherever-dev 0.19.0 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/CHANGELOG.md +1180 -0
  2. package/README.md +60 -0
  3. package/package.json +28 -8
  4. package/public/_app/immutable/chunks/{D7cniAcl.js → Be584n9t.js} +2 -2
  5. package/public/_app/immutable/chunks/{D7cniAcl.js.map → Be584n9t.js.map} +1 -1
  6. package/public/_app/immutable/chunks/CDh6N9EK.js +2 -0
  7. package/public/_app/immutable/chunks/{CMMpRRWm.js.map → CDh6N9EK.js.map} +1 -1
  8. package/public/_app/immutable/chunks/{B4u7MCsa.js → CHdncqe4.js} +2 -2
  9. package/public/_app/immutable/chunks/{B4u7MCsa.js.map → CHdncqe4.js.map} +1 -1
  10. package/public/_app/immutable/entry/{app.B09hP3rk.js → app.Bvi1whhV.js} +3 -3
  11. package/public/_app/immutable/entry/{app.B09hP3rk.js.map → app.Bvi1whhV.js.map} +1 -1
  12. package/public/_app/immutable/entry/start.DrBMY1f9.js +2 -0
  13. package/public/_app/immutable/entry/start.DrBMY1f9.js.map +1 -0
  14. package/public/_app/immutable/nodes/{0.Bl6oKVU5.js → 0.BXOlI-1A.js} +2 -2
  15. package/public/_app/immutable/nodes/{0.Bl6oKVU5.js.map → 0.BXOlI-1A.js.map} +1 -1
  16. package/public/_app/immutable/nodes/{1.H6kc-Qsz.js → 1.Dw59rM0a.js} +2 -2
  17. package/public/_app/immutable/nodes/{1.H6kc-Qsz.js.map → 1.Dw59rM0a.js.map} +1 -1
  18. package/public/_app/immutable/nodes/{2.B6sChdvF.js → 2.B4mmUgEN.js} +2 -2
  19. package/public/_app/immutable/nodes/{2.B6sChdvF.js.map → 2.B4mmUgEN.js.map} +1 -1
  20. package/public/_app/version.json +1 -1
  21. package/public/index.html +10 -10
  22. package/public/service-worker.js +1 -1
  23. package/public/_app/immutable/chunks/CMMpRRWm.js +0 -2
  24. package/public/_app/immutable/entry/start.DsunIvKH.js +0 -2
  25. package/public/_app/immutable/entry/start.DsunIvKH.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import"../chunks/DsnmJJEf.js";import{ao as er,aU as Ws,ai as Zr,b5 as C,am as za,w as Fc,G as go,aL as Bc,an as Lo,b as Gi,aj as Do,ap as zc,k as Hc,V as jc,q as Gc,p as Wc,W as qc,J as Kc,K as Vc,H as Yc,aV as Ha,C as ja,v as Ga,aw as Qs,X as Lr,a7 as Xc,as as Zc,aS as Jc,ar as Wi,b4 as qi,b7 as Qc,b9 as Ar,aN as na,aJ as Wa,aI as hr,aF as br,aa as Ot,a_ as f,af as t,Z as ed,y as h,Q as dr,ac as b,ba as D,$ as td,be as vr,a3 as pn,ae as Un,a0 as Mr,aD as ys,aT as p,M as d,aO as c,aA as ft,a1 as M,b1 as N,aH as Vn,bb as Bt,bc as nd,aW as I,a9 as wr,b6 as Kn,ad as eo,aC as rd,aM as sd,aB as qa}from"../chunks/CAL8yDNt.js";import{i as w,s as Ur,a as Ae,p as ur}from"../chunks/Cjaz9aih.js";import{u as od,D as Y,C as hs,m as bs,a as ad,n as ws,o as ks,G as id,z as Ki,x as ld,t as Ct,d as qs,f as Vi,E as ra,e as sa,p as oa,h as In,q as pr,g as cd,j as dd,i as Yi,F as Xi,k as Zi,s as ud,B as fd,w as pd,l as hd,y as bd,b as vd}from"../chunks/D7cniAcl.js";import{_ as gd,b as ir}from"../chunks/BORm3wtc.js";import{v as Fs}from"../chunks/CMMpRRWm.js";import{p as md}from"../chunks/B4u7MCsa.js";function Ka(n,e,r=!1,s=!1,o=!1,a=!1){var i=n,u="";if(r){var m=n;er&&(i=Ws(Zr(m)))}C(()=>{var v=Fc;if(u===(u=e()??"")){er&&za();return}if(r&&!er){v.nodes=null,m.innerHTML=u,u!==""&&go(Zr(m),m.lastChild);return}if(v.nodes!==null&&(Bc(v.nodes.start,v.nodes.end),v.nodes=null),u!==""){if(er){Lo.data;for(var g=za(),_=g;g!==null&&(g.nodeType!==Gi||g.data!=="");)_=g,g=Do(g);if(g===null)throw zc(),Hc;go(Lo,_),i=Ws(g);return}var y=s?Gc:o?Wc:void 0,$=jc(s?"svg":o?"math":"template",y);$.innerHTML=u;var O=s||o?$:$.content;if(go(Zr(O),O.lastChild),s||o)for(;Zr(O);)i.before(Zr(O));else i.before(O)}})}function xd(n,e){let r=null,s=er;var o;if(er){r=Lo;for(var a=Zr(document.head);a!==null&&(a.nodeType!==Gi||a.data!==n);)a=Do(a);if(a===null)Ha(!1);else{var i=Do(a);a.remove(),Ws(i)}}er||(o=document.head.appendChild(qc()));try{Kc(()=>{var u=Vc(()=>e(o));u.f|=Yc})}finally{s&&(Ha(!0),Ws(r))}}function Ji(n){var e,r,s="";if(typeof n=="string"||typeof n=="number")s+=n;else if(typeof n=="object")if(Array.isArray(n)){var o=n.length;for(e=0;e<o;e++)n[e]&&(r=Ji(n[e]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function _d(){for(var n,e,r=0,s="",o=arguments.length;r<o;r++)(n=arguments[r])&&(e=Ji(n))&&(s&&(s+=" "),s+=e);return s}function Qi(n){return typeof n=="object"?_d(n):n??""}function yd(n,e,r){var s=n==null?"":""+n;return s===""?null:s}function wd(n,e){return n==null?null:String(n)}function fn(n,e,r,s,o,a){var i=n[ja];if(er||i!==r||i===void 0){var u=yd(r);(!er||u!==n.getAttribute("class"))&&(u==null?n.removeAttribute("class"):e?n.className=u:n.setAttribute("class",u)),n[ja]=r}return a}function aa(n,e,r,s){var o=n[Ga];if(er||o!==e){var a=wd(e);(!er||a!==n.getAttribute("style"))&&(a==null?n.removeAttribute("style"):n.style.cssText=a),n[Ga]=e}return s}function ia(n,e,r=!1){if(n.multiple){if(e==null)return;if(!Zc(e))return Jc();for(var s of n.options)s.selected=e.includes(vs(s));return}for(s of n.options){var o=vs(s);if(Wi(o,e)){s.selected=!0;return}}(!r||e!==void 0)&&(n.selectedIndex=-1)}function el(n){var e=new MutationObserver(()=>{ia(n,n.__value)});e.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),qi(()=>{e.disconnect()})}function xs(n,e,r=e){var s=new WeakSet,o=!0;Qs(n,"change",a=>{var i=a?"[selected]":":checked",u;if(n.multiple)u=[].map.call(n.querySelectorAll(i),vs);else{var m=n.querySelector(i)??n.querySelector("option:not([disabled])");u=m&&vs(m)}r(u),n.__value=u,Lr!==null&&s.add(Lr)}),Xc(()=>{var a=e();if(n===document.activeElement){var i=Lr;if(s.has(i))return}if(ia(n,a,o),o&&a===void 0){var u=n.querySelector(":checked");u!==null&&(a=vs(u),r(a))}n.__value=a,o=!1}),el(n)}function vs(n){return"__value"in n?n.__value:n.value}function ar(n,e,r=e){var s=new WeakSet;Qs(n,"input",async o=>{var a=o?n.defaultValue:n.value;if(a=xo(n)?_o(a):a,r(a),Lr!==null&&s.add(Lr),await Qc(),a!==(a=e())){var i=n.selectionStart,u=n.selectionEnd,m=n.value.length;if(n.value=a??"",u!==null){var v=n.value.length;i===u&&u===m&&v>m?(n.selectionStart=v,n.selectionEnd=v):(n.selectionStart=i,n.selectionEnd=Math.min(u,v))}}}),(er&&n.defaultValue!==n.value||Ar(e)==null&&n.value)&&(r(xo(n)?_o(n.value):n.value),Lr!==null&&s.add(Lr)),na(()=>{var o=e();if(n===document.activeElement){var a=Lr;if(s.has(a))return}xo(n)&&o===_o(n.value)||n.type==="date"&&!o&&!n.value||o!==n.value&&(n.value=o??"")})}const mo=new Set;function Nr(n,e,r,s,o=s){var a=r.getAttribute("type")==="checkbox",i=n;let u=!1;if(e!==null)for(var m of e)i=i[m]??=[];i.push(r),Qs(r,"change",()=>{var v=r.__value;a&&(v=Va(i,v,r.checked)),o(v)},()=>o(a?[]:null)),na(()=>{var v=s();if(er&&r.defaultChecked!==r.checked){u=!0;return}a?(v=v||[],r.checked=v.includes(r.__value)):r.checked=Wi(r.__value,v)}),qi(()=>{var v=i.indexOf(r);v!==-1&&i.splice(v,1)}),mo.has(i)||(mo.add(i),Wa(()=>{i.sort((v,g)=>v.compareDocumentPosition(g)===4?-1:1),mo.delete(i)})),Wa(()=>{if(u){var v;if(a)v=Va(i,v,r.checked);else{var g=i.find(_=>_.checked);v=g?.__value}o(v)}})}function Zn(n,e,r=e){Qs(n,"change",s=>{var o=s?n.defaultChecked:n.checked;r(o)}),(er&&n.defaultChecked!==n.checked||Ar(e)==null)&&r(n.checked),na(()=>{var s=e();n.checked=!!s})}function Va(n,e,r){for(var s=new Set,o=0;o<n.length;o+=1)n[o].checked&&s.add(n[o].__value);return r||s.delete(e),Array.from(s)}function xo(n){var e=n.type;return e==="number"||e==="range"}function _o(n){return n===""?null:+n}const kd=!1,Sd=!0,sx=Object.freeze(Object.defineProperty({__proto__:null,prerender:Sd,ssr:kd},Symbol.toStringTag,{value:"Module"})),yo="Wherever",Td="Create & maintain apps from wherever with a beautiful remote workspace.",wo="https://localhost",Ad="#000000",Cd="black-translucent";function Qr(n,e){return od(n)}var Rd=b('<meta name="title"/> <meta name="description"/> <!> <meta property="og:type"/> <meta property="og:url"/> <meta property="og:title"/> <meta property="og:description"/> <meta property="og:image"/> <meta property="twitter:card" content="summary_large_image"/> <meta property="twitter:url"/> <meta property="twitter:title"/> <meta property="twitter:description"/> <meta property="twitter:image"/> <link rel="icon" type="image/png"/> <link rel="icon" sizes="any"/> <link rel="apple-touch-icon"/> <link rel="manifest"/> <meta name="theme-color"/> <meta name="mobile-web-app-capable" content="yes"/> <meta name="application-name"/> <meta name="apple-mobile-web-app-capable" content="yes"/> <meta name="apple-mobile-web-app-status-bar-style"/> <meta name="apple-mobile-web-app-title"/> <meta name="version"/>',1);function Ed(n,e){hr(e,!0);const r=wo.endsWith("/")?wo.slice(0,-1):wo,s=r+"/preview.png";let o=D(()=>e.home||!1),a=D(()=>({type:e.type||"website",title:e.title||yo,description:e.description||Td,image:e.image||s,url:`${r}${md.url.pathname}`}));xd("13n5pl5",i=>{var u=Rd(),m=Ot(u),v=f(m,2),g=f(v,2);{var _=ht=>{var Ke=dr(),tt=Ot(Ke);w(tt,xt=>{}),h(ht,Ke)};w(g,ht=>{t(o)&&ht(_)})}var y=f(g,2),$=f(y,2),O=f($,2),z=f(O,2),W=f(z,2),$e=f(W,4),oe=f($e,2),ze=f(oe,2),X=f(ze,2),fe=f(X,2),Q=f(fe,2),Ee=f(Q,2),gt=f(Ee,2),We=f(gt,2),ae=f(We,4),qe=f(ae,4),pt=f(qe,2),mt=f(pt,2);C((ht,Ke,tt,xt)=>{Y(m,"content",t(a).title),Y(v,"content",t(a).description),Y(y,"content",t(a).type),Y($,"content",t(a).url),Y(O,"content",t(a).title),Y(z,"content",t(a).description),Y(W,"content",t(a).image),Y($e,"content",t(a).url),Y(oe,"content",t(a).title),Y(ze,"content",t(a).description),Y(X,"content",t(a).image),Y(fe,"href",ht),Y(Q,"href",Ke),Y(Ee,"href",tt),Y(gt,"href",xt),Y(We,"content",Ad),Y(ae,"content",yo),Y(qe,"content",Cd),Y(pt,"content",yo),Y(mt,"content",Fs)},[()=>Qr("/pwa/favicon.png"),()=>Qr("/pwa/favicon.ico"),()=>Qr("/pwa/apple-touch-icon.png"),()=>Qr("/pwa/manifest.webmanifest")]),ed(()=>{td.title=t(a).title??""}),h(i,u)}),br()}let ss=null;function Id(){if(typeof window>"u")return null;try{if(!ss){const n=window.AudioContext||window.webkitAudioContext;if(!n)return null;ss=new n}return ss.state==="suspended"&&ss.resume().catch(()=>{}),ss}catch{return null}}function Ya(n,e,r,s,o){const a=n.createOscillator(),i=n.createGain();a.type="sine",a.frequency.value=e;const u=.015;i.gain.setValueAtTime(1e-4,r),i.gain.exponentialRampToValueAtTime(o,r+u),i.gain.exponentialRampToValueAtTime(1e-4,r+s),a.connect(i),i.connect(n.destination),a.start(r),a.stop(r+s+.02)}const Xa=new Map;function Md(n){if(typeof Audio>"u")return!1;try{let e=Xa.get(n);e||(e=new Audio(n),e.preload="auto",Xa.set(n,e));try{e.currentTime=0}catch{}const r=e.play();return r&&typeof r.catch=="function"&&r.catch(()=>{}),!0}catch{return!1}}function tl(n){if(n&&n.trim()&&Md(n.trim()))return;const e=Id();if(e)try{const r=e.currentTime;Ya(e,1046.5,r,.16,.12),Ya(e,1396.9,r+.13,.22,.12)}catch{}}function la(n){if(!n)return null;const e=n.trimStart(),r=e.match(/^<skill\s+name="([^"]*)"[^>]*>/);if(r){const s=e.indexOf("</skill>");return s===-1?null:{skillName:r[1],args:e.slice(s+8).trim()}}if(e.startsWith("/skill:")){const s=e.slice(7),o=s.indexOf(" "),a=o===-1?s:s.slice(0,o);if(!a)return null;const i=o===-1?"":s.slice(o+1).trim();return{skillName:a,args:i}}return null}function $s(n){const e=la(n);return e?`skill:${e.skillName}\0${e.args}`:null}function Bs(){}function $d(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Od(n,...e){if(n==null)return Bs;const r=n.subscribe(...e);return r.unsubscribe?()=>r.unsubscribe():r}function Ft(n){let e;return Od(n,r=>e=r)(),e}var Vr=[];function Za(n,e=Bs){let r;const s=new Set;function o(u){if($d(n,u)&&(n=u,r)){const m=!Vr.length;for(const v of s)v[1](),Vr.push(v,n);if(m){for(let v=0;v<Vr.length;v+=2)Vr[v][0](Vr[v+1]);Vr.length=0}}}function a(u){o(u(n))}function i(u,m=Bs){const v=[u,m];return s.add(v),s.size===1&&(r=e(o)||Bs),u(n),()=>{s.delete(v),s.size===0&&(r(),r=null)}}return{set:o,update:a,subscribe:i}}function Ja(){return`ck-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}const Ld="upload.v1",to=1024,Qa=64*to,Dd=1024*to,Pd=256*to,Nd=2,ei=.3,ti=3*256*to,nl="The file is no longer readable, pick it again";function Ud(n,e,r){const s=3+n.length,o=new Uint8Array(s+8+r.length);o[0]=1,o[1]=1,o[2]=n.length;for(let i=0;i<n.length;i++)o[3+i]=n.charCodeAt(i);const a=new DataView(o.buffer);return a.setUint32(s,Math.floor(e/2**32)),a.setUint32(s+4,e>>>0),o.set(r,s+8),o}function rl(n){let e="";for(let r=0;r<n.length;r+=32768)e+=String.fromCharCode.apply(null,n.subarray(r,r+32768));return e}function Fd(){const n=new Uint8Array(16),e=globalThis.crypto;if(e&&typeof e.getRandomValues=="function")e.getRandomValues(n);else for(let r=0;r<n.length;r++)n[r]=Math.floor(Math.random()*256);return btoa(rl(n)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}class ts extends Error{code}function ko(n){if(n instanceof ts)return n;if(n&&n.name==="NotReadableError"){const e=new ts(nl);return e.code="not_readable",e}return new ts(`Failed to read the file: ${n&&n.message||n}`)}function ni(){const n=new ts(nl);return n.code="not_readable",n}function sl(n){return n.startsWith("http")?n.replace(/^https?:\/\//,""):n}function Bd(n){let e=2166136261;for(let r=0;r<n.length;r++)e^=n.charCodeAt(r),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}function Ks(n){return`${sl(n.host)}:${n.port}#${Bd(n.token??"")}`}const So={connected:!1,connecting:!1,creatingSession:!1,loadingSession:!1,resyncing:!1,agentPending:!1,error:null,session:null,sessionId:null,isStreaming:!1,messages:[],clientId:null,serverVersion:null,piVersion:null,folderConflict:null,folderMissing:null,restore:null,isInterrupted:!1,notice:null,sudoPrompt:null,sessionError:null,readOnly:!1,activeSessionFile:null,activeCwd:null,activeModel:null,hideThinking:!1,hideTools:!1,historyTotalCount:0,historyOffset:0,loadingMoreHistory:!1,historyAuthoritative:!1,serverKey:null,contextUsage:null,pendingSteering:[],skills:[]};class Dn{ws=null;config;clientKey;stateStore;reconnectTimer=null;agentEndTimeout=null;loadWatchdog=null;static LOAD_WATCHDOG_MS=12e3;createWatchdog=null;static CREATE_WATCHDOG_MS=25e3;reconnectAttempts=0;reconnectDelay=2e3;maxReconnectDelay=15e3;hasEverConnected=!1;static HANDSHAKE_FAIL_HINT_AFTER=2;livenessTimer=null;heartbeatTimer=null;lastInboundAt=0;static STALE_SOCKET_MS=6e4;static TURN_STALL_MS=45e3;static HEARTBEAT_MS=25e3;static PROBE_GRACE_MS=5e3;probeTimer=null;lastLivenessTickAt=0;isInitialConnect=!0;resumeSessionFile=null;resumeCwd;resumeModel;pendingLoadFile=null;socketServerKey=null;hydratedFile=null;listeners=new Set;pendingUploads=new Map;uploadsStore=Za({});socketCapabilities=null;static MAX_UPLOAD_SENDS=3;static MAX_UPLOAD_BASE64_CHARS=96*1024*1024;static MAX_LEGACY_UPLOAD_BYTES=72*1024*1024;static UPLOAD_TIMEOUT_MS=10*6e4;uploadsHeldForRejoin=!1;confirmTimers=new Map;static CONFIRM_MS=12e3;static PENDING_PREFIX="wherever-pending:";constructor(e){this.config={secure:!0,...e},this.clientKey=this.config.clientKey||Ja(),this.stateStore=Za({...So,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}connect(e,r=!1){e&&(this.config={...this.config,...e}),this.disconnect(!1);const s=Ks(this.config),o=Ft(this.stateStore).serverKey;o!==null&&o!==s&&(r=!1,this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,this.pendingLoadFile=null,this.hydratedFile=null),this.socketServerKey=s,this.stateStore.update(z=>r?{...z,connecting:!0,error:null}:{...So,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const a=this.config.secure?"wss":"ws",i=sl(this.config.host),u=[];this.config.token&&u.push(`token=${encodeURIComponent(this.config.token)}`),u.push(`clientKey=${encodeURIComponent(this.clientKey)}`);const m=`${a}://${i}:${this.config.port}/ws?${u.join("&")}`,v=this.config.WebSocketCtor||(typeof globalThis<"u"?globalThis.WebSocket:null);if(!v){this.stateStore.update(z=>({...z,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}this.socketCapabilities=null;try{const z=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=z?new v(m,z):new v(m)}catch(z){this.stateStore.update(W=>({...W,connecting:!1,error:`Failed to connect: ${z}`})),this.scheduleReconnect();return}const g=this.ws,_=()=>{if(this.ws!==g)return;this.isInitialConnect||console.info("[wherever] reconnected to relay"),this.hasEverConnected=!0,this.reconnectAttempts=0,this.reconnectDelay=2e3,this.isInitialConnect=!1,this.startLivenessWatchdog(),this.stateStore.update(ze=>({...ze,connected:!0,connecting:!1,error:null}));const z=Ft(this.stateStore),W=this.resumeSessionFile??z.activeSessionFile,$e=this.resumeSessionFile!=null?this.resumeCwd:z.activeCwd??void 0,oe=this.resumeSessionFile!=null?this.resumeModel:z.activeModel??void 0;this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,this.uploadsHeldForRejoin=!!W,W||this.rejectPendingUploads("The session was closed before the upload could be sent"),W?(this.stateStore.update(ze=>ze.resyncing&&!ze.historyAuthoritative?ze:{...ze,resyncing:!0,historyAuthoritative:!1}),this.pendingLoadFile=W,this.send({type:"session_load",sessionFile:W,cwd:$e,model:oe}),this.armLoadWatchdog()):this.stateStore.update(ze=>ze.resyncing?{...ze,resyncing:!1}:ze)},y=z=>{if(this.ws===g){this.lastInboundAt=Date.now(),this.cancelLivenessProbe();try{const W=typeof z.data=="string"?z.data:z.data.toString(),$e=JSON.parse(W);this.handleMessage($e)}catch(W){console.error("Failed to parse WebSocket message:",W)}}},$=()=>{this.ws===g&&(this.uploadsLostSocket(),this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.ws=null,this.stateStore.update(z=>({...z,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:z.activeSessionFile?!0:z.resyncing})),this.scheduleReconnect())},O=z=>{this.ws===g&&this.stateStore.update(W=>({...W,error:W.error||"Connection error occurred"}))};typeof g.addEventListener=="function"?(g.addEventListener("open",_),g.addEventListener("message",y),g.addEventListener("close",$),g.addEventListener("error",O)):typeof g.on=="function"&&(g.on("open",_),g.on("message",z=>y({data:z})),g.on("close",$),g.on("error",O))}disconnect(e=!0){if(this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.clearCreateWatchdog(),this.uploadsLostSocket(),this.ws){const r=this.ws;try{typeof r.removeAllListeners=="function"&&r.removeAllListeners();const s=()=>{};typeof r.on=="function"?r.on("error",s):typeof r.addEventListener=="function"?r.addEventListener("error",s):r.onerror=s,r.close()}catch{}this.ws=null}if(e){for(const r of this.confirmTimers.values())clearTimeout(r);this.confirmTimers.clear(),this.rejectPendingUploads("Disconnected before the upload completed"),this.uploadsHeldForRejoin=!1,this.hydratedFile=null,this.stateStore.set({...So,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}else this.stateStore.update(r=>({...r,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1}))}suspend(){const e=Ft(this.stateStore);e.activeSessionFile&&(this.resumeSessionFile=e.activeSessionFile,this.resumeCwd=e.activeCwd??void 0,this.resumeModel=e.activeModel??void 0),e.isStreaming&&this.stateStore.update(r=>({...r,isStreaming:!1})),this.disconnect(!1)}resume(){const e=Ft(this.stateStore);e.connected||e.connecting||((this.resumeSessionFile||e.activeSessionFile)&&this.stateStore.update(r=>({...r,resyncing:!0})),this.connect(void 0,!0))}hasSuspendedSession(){return this.resumeSessionFile!==null}hasActiveSession(){return this.resumeSessionFile!==null||Ft(this.stateStore).activeSessionFile!==null}startLivenessWatchdog(){this.stopLivenessWatchdog(),this.lastInboundAt=Date.now(),this.lastLivenessTickAt=this.lastInboundAt;const e=()=>{try{this.ping()}catch{}};typeof setInterval=="function"&&(this.heartbeatTimer=setInterval(e,Dn.HEARTBEAT_MS),this.heartbeatTimer&&typeof this.heartbeatTimer.unref=="function"&&this.heartbeatTimer.unref());const r=()=>{if(!this.ws)return;const s=Date.now(),o=s-this.lastLivenessTickAt;if(this.lastLivenessTickAt=s,o>2*Dn.HEARTBEAT_MS){this.startLivenessProbe("clock jump");return}const a=s-this.lastInboundAt,i=Ft(this.stateStore).isStreaming,u=i?Dn.TURN_STALL_MS:Dn.STALE_SOCKET_MS;a<u||this.startLivenessProbe(`no inbound frame for ${a}ms (threshold ${u}ms, ${i?"mid-turn":"idle"})`)};typeof setInterval=="function"&&(this.livenessTimer=setInterval(r,Dn.HEARTBEAT_MS),this.livenessTimer&&typeof this.livenessTimer.unref=="function"&&this.livenessTimer.unref())}noteVisible(){const e=this.ws;!e||e.readyState!==1||!this.livenessTimer||(this.lastInboundAt=Date.now(),this.lastLivenessTickAt=this.lastInboundAt,this.cancelLivenessProbe(),this.startLivenessProbe("page became visible"))}startLivenessProbe(e){if(this.probeTimer||!this.ws||typeof setTimeout!="function")return;const r=this.ws;try{this.ping()}catch{}const s=Date.now();this.probeTimer=setTimeout(()=>{if(this.probeTimer=null,this.ws===r){if(Date.now()-s>2*Dn.PROBE_GRACE_MS){this.startLivenessProbe(e);return}this.tearDownStaleSocket(e)}},Dn.PROBE_GRACE_MS),this.probeTimer&&typeof this.probeTimer.unref=="function"&&this.probeTimer.unref()}cancelLivenessProbe(){this.probeTimer&&(clearTimeout(this.probeTimer),this.probeTimer=null)}tearDownStaleSocket(e){if(!this.ws)return;const r=Ft(this.stateStore).isStreaming;console.warn(`[wherever] relay connection stale: ${e}; probe unanswered for ${Dn.PROBE_GRACE_MS}ms; tearing down dead socket and reconnecting`),this.stopLivenessWatchdog();const s=this.ws;this.ws=null,this.uploadsLostSocket();try{typeof s.terminate=="function"?s.terminate():typeof s.close=="function"&&s.close()}catch{}this.stateStore.update(o=>({...o,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:r?"Connection to relay stalled mid-turn; reconnecting...":o.sessionError,isStreaming:!1})),this.scheduleReconnect()}stopLivenessWatchdog(){this.cancelLivenessProbe(),this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null),this.livenessTimer&&(clearInterval(this.livenessTimer),this.livenessTimer=null)}armLoadWatchdog(){this.clearLoadWatchdog(),this.loadWatchdog=setTimeout(()=>{this.loadWatchdog=null;const e=Ft(this.stateStore);!e.loadingSession&&!e.resyncing||(console.warn("[wherever] session load timed out; clearing loading state"),this.failHeldUploads("Could not rejoin the session, so the upload was not sent"),this.stateStore.update(r=>({...r,loadingSession:!1,resyncing:!1,sessionError:r.sessionError||"Loading the session timed out. Please retry from the sidebar or reload."})))},Dn.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,Ft(this.stateStore).creatingSession&&(console.warn("[wherever] session create timed out; clearing creating state"),this.stateStore.update(r=>({...r,creatingSession:!1,sessionError:r.sessionError||"Creating the session timed out. It may still be starting on the server; check the sidebar or reload."})))},Dn.CREATE_WATCHDOG_MS)}clearCreateWatchdog(){this.createWatchdog&&(clearTimeout(this.createWatchdog),this.createWatchdog=null)}scheduleReconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{if(this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*1.5,this.maxReconnectDelay),console.info(`[wherever] reconnecting to relay (attempt ${++this.reconnectAttempts})`),!this.hasEverConnected&&this.reconnectAttempts>=Dn.HANDSHAKE_FAIL_HINT_AFTER){const r=this.config.secure?"wss":"ws";this.stateStore.update(s=>({...s,error:`Cannot connect to the wherever server: the connection is being rejected. This usually means a missing or wrong token, or a wrong host/port/scheme (currently ${r}://${this.config.host}:${this.config.port}). Check the auth token and connection settings.`}))}const e=!!Ft(this.stateStore).activeSessionFile;this.stateStore.update(r=>({...r,connecting:!0,error:"Reconnecting..."})),this.connect(void 0,e)},this.reconnectDelay))}handleMessage(e){for(const r of this.listeners)try{r(e)}catch(s){console.error("Error in message listener:",s)}switch(e.type){case"message_history":{const r=Ft(this.stateStore).sessionId;if(r&&e.sessionId&&e.sessionId!==r)break;this.clearLoadWatchdog();break}case"session_error":case"session_destroyed":case"session_interrupted":this.clearLoadWatchdog();break}switch(e.type){case"session_created":case"session_error":case"session_interrupted":this.clearCreateWatchdog();break}switch(e.type){case"connected":this.stateStore.update(s=>({...s,connected:!0,connecting:!1,clientId:e.clientId,serverVersion:e.serverVersion??null,piVersion:e.piVersion??null,error:null})),this.socketCapabilities=Array.isArray(e.capabilities)?e.capabilities.filter(s=>typeof s=="string"):[],this.resendPendingUploads();break;case"connection_superseded":this.clientKey=Ja();try{this.config.onClientKeyChange?.(this.clientKey)}catch(s){console.error("onClientKeyChange failed:",s)}break;case"file_uploaded":this.completeUpload(e.uploadId,{savedPath:e.savedPath,filename:e.filename});break;case"file_upload_error":this.failUpload(e.uploadId,e.error);break;case"upload_offset":this.handleUploadOffset(e);break;case"agent_start":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.stateStore.update(s=>({...s,isStreaming:!0}));break;case"thinking_update":this.stateStore.update(s=>{let o=[...s.messages].reverse().find(a=>a.role==="thinking"&&a.isStreaming);if(!o){const a={id:this.generateId(),role:"thinking",content:e.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,a]}}return{...s,messages:s.messages.map(a=>a.id===o.id?{...a,content:a.content+e.delta,isStreaming:!0}:a)}});break;case"message_update":this.stateStore.update(s=>{let o=[...s.messages].reverse().find(a=>a.role==="assistant"&&a.isStreaming);if(!o){const a={id:this.generateId(),role:"assistant",content:e.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,a]}}return{...s,messages:s.messages.map(a=>a.id===o.id?{...a,content:a.content+e.delta,isStreaming:!0}:a)}});break;case"message_ack":typeof e.content=="string"&&this.confirmDeliveredByContent(e.content);break;case"queue_update":{const s=Array.isArray(e.steering)?[...e.steering]:[];this.stateStore.update(o=>({...o,pendingSteering:s,messages:this.withRestoredQueuedMessages(o.messages,s)}));break}case"message_end":this.stateStore.update(s=>{let o=s.messages;const a=[...o].reverse().find(u=>u.role==="thinking"&&u.isStreaming);a&&(o=o.map(u=>u.id===a.id?{...u,isStreaming:!1}:u));const i=[...o].reverse().find(u=>u.role==="assistant"&&u.isStreaming);if(i)o=o.map(u=>u.id===i.id?{...u,content:e.content||u.content,isStreaming:!1}:u);else if(e.content){if(e.role==="user"){if(this.confirmDeliveredByContent(e.content))return Ft(this.stateStore);const _=o.find(y=>y.role==="user"&&y.restoredFromQueue&&y.content===e.content);if(_)return{...s,messages:o.map(y=>y.id===_.id?{...y,restoredFromQueue:void 0}:y)}}const u=e.role==="user"?$s(e.content):null;if(u){const g=[...o].reverse().find(_=>_.role==="user"&&$s(_.content)===u);if(g)return g.content!==e.content&&(o=o.map(_=>_.id===g.id?{..._,content:e.content}:_)),{...s,messages:o}}const m=[...o].reverse().find(g=>g.role==="user");e.role==="user"&&m&&m.content===e.content||(o=[...o,{id:this.generateId(),role:e.role||"assistant",content:e.content,timestamp:Date.now(),isStreaming:!1}])}return{...s,messages:o}});break;case"agent_end":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.agentEndTimeout=setTimeout(()=>{const s=Date.now();this.stateStore.update(o=>({...o,isStreaming:!1,pendingSteering:[],messages:o.messages.map(a=>a.isStreaming?{...a,isStreaming:!1,...a.role==="tool"?{interrupted:!0}:{},endedAt:a.role==="tool"&&a.endedAt===void 0?s:a.endedAt}:a)})),this.agentEndTimeout=null},300);break;case"tool_start":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null);const r=e.args?Object.entries(e.args).filter(([s,o])=>o!==void 0&&o!=="").map(([s,o])=>`${s}=${JSON.stringify(o)}`).join(" "):"";this.stateStore.update(s=>{const o=s.messages.map(m=>m.isStreaming&&(m.role==="assistant"||m.role==="thinking")?{...m,isStreaming:!1}:m),a=Date.now(),i=!!e.forceCommand;if(i){const m=o.find(v=>v.role==="tool"&&v.optimistic&&v.isStreaming);if(m)return{...s,messages:o.map(v=>v.id===m.id?{...v,optimistic:!1,toolName:e.toolName,toolArgs:r,content:r?`$ ${e.toolName} ${r}`:`$ ${e.toolName}`,startedAt:a,timestamp:a,forceCommand:!0}:v)}}const u={id:this.generateId(),role:"tool",content:r?`$ ${e.toolName} ${r}`:`$ ${e.toolName}`,timestamp:a,isStreaming:!0,toolName:e.toolName,toolArgs:r,toolOutput:"",startedAt:a,...i?{forceCommand:!0}:{}};return{...s,messages:[...o,u]}});break;case"tool_update":{this.stateStore.update(s=>{const o=[...s.messages].reverse().find(a=>a.role==="tool"&&a.toolName===e.toolName&&a.isStreaming);return o?{...s,messages:s.messages.map(a=>a.id===o.id?{...a,content:a.content.includes(`
1
+ import"../chunks/DsnmJJEf.js";import{ao as er,aU as Ws,ai as Zr,b5 as C,am as za,w as Fc,G as go,aL as Bc,an as Lo,b as Gi,aj as Do,ap as zc,k as Hc,V as jc,q as Gc,p as Wc,W as qc,J as Kc,K as Vc,H as Yc,aV as Ha,C as ja,v as Ga,aw as Qs,X as Lr,a7 as Xc,as as Zc,aS as Jc,ar as Wi,b4 as qi,b7 as Qc,b9 as Ar,aN as na,aJ as Wa,aI as hr,aF as br,aa as Ot,a_ as f,af as t,Z as ed,y as h,Q as dr,ac as b,ba as D,$ as td,be as vr,a3 as pn,ae as Un,a0 as Mr,aD as ys,aT as p,M as d,aO as c,aA as ft,a1 as M,b1 as N,aH as Vn,bb as Bt,bc as nd,aW as I,a9 as wr,b6 as Kn,ad as eo,aC as rd,aM as sd,aB as qa}from"../chunks/CAL8yDNt.js";import{i as w,s as Ur,a as Ae,p as ur}from"../chunks/Cjaz9aih.js";import{u as od,D as Y,C as hs,m as bs,a as ad,n as ws,o as ks,G as id,z as Ki,x as ld,t as Ct,d as qs,f as Vi,E as ra,e as sa,p as oa,h as In,q as pr,g as cd,j as dd,i as Yi,F as Xi,k as Zi,s as ud,B as fd,w as pd,l as hd,y as bd,b as vd}from"../chunks/Be584n9t.js";import{_ as gd,b as ir}from"../chunks/BORm3wtc.js";import{v as Fs}from"../chunks/CDh6N9EK.js";import{p as md}from"../chunks/CHdncqe4.js";function Ka(n,e,r=!1,s=!1,o=!1,a=!1){var i=n,u="";if(r){var m=n;er&&(i=Ws(Zr(m)))}C(()=>{var v=Fc;if(u===(u=e()??"")){er&&za();return}if(r&&!er){v.nodes=null,m.innerHTML=u,u!==""&&go(Zr(m),m.lastChild);return}if(v.nodes!==null&&(Bc(v.nodes.start,v.nodes.end),v.nodes=null),u!==""){if(er){Lo.data;for(var g=za(),_=g;g!==null&&(g.nodeType!==Gi||g.data!=="");)_=g,g=Do(g);if(g===null)throw zc(),Hc;go(Lo,_),i=Ws(g);return}var y=s?Gc:o?Wc:void 0,$=jc(s?"svg":o?"math":"template",y);$.innerHTML=u;var O=s||o?$:$.content;if(go(Zr(O),O.lastChild),s||o)for(;Zr(O);)i.before(Zr(O));else i.before(O)}})}function xd(n,e){let r=null,s=er;var o;if(er){r=Lo;for(var a=Zr(document.head);a!==null&&(a.nodeType!==Gi||a.data!==n);)a=Do(a);if(a===null)Ha(!1);else{var i=Do(a);a.remove(),Ws(i)}}er||(o=document.head.appendChild(qc()));try{Kc(()=>{var u=Vc(()=>e(o));u.f|=Yc})}finally{s&&(Ha(!0),Ws(r))}}function Ji(n){var e,r,s="";if(typeof n=="string"||typeof n=="number")s+=n;else if(typeof n=="object")if(Array.isArray(n)){var o=n.length;for(e=0;e<o;e++)n[e]&&(r=Ji(n[e]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function _d(){for(var n,e,r=0,s="",o=arguments.length;r<o;r++)(n=arguments[r])&&(e=Ji(n))&&(s&&(s+=" "),s+=e);return s}function Qi(n){return typeof n=="object"?_d(n):n??""}function yd(n,e,r){var s=n==null?"":""+n;return s===""?null:s}function wd(n,e){return n==null?null:String(n)}function fn(n,e,r,s,o,a){var i=n[ja];if(er||i!==r||i===void 0){var u=yd(r);(!er||u!==n.getAttribute("class"))&&(u==null?n.removeAttribute("class"):e?n.className=u:n.setAttribute("class",u)),n[ja]=r}return a}function aa(n,e,r,s){var o=n[Ga];if(er||o!==e){var a=wd(e);(!er||a!==n.getAttribute("style"))&&(a==null?n.removeAttribute("style"):n.style.cssText=a),n[Ga]=e}return s}function ia(n,e,r=!1){if(n.multiple){if(e==null)return;if(!Zc(e))return Jc();for(var s of n.options)s.selected=e.includes(vs(s));return}for(s of n.options){var o=vs(s);if(Wi(o,e)){s.selected=!0;return}}(!r||e!==void 0)&&(n.selectedIndex=-1)}function el(n){var e=new MutationObserver(()=>{ia(n,n.__value)});e.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),qi(()=>{e.disconnect()})}function xs(n,e,r=e){var s=new WeakSet,o=!0;Qs(n,"change",a=>{var i=a?"[selected]":":checked",u;if(n.multiple)u=[].map.call(n.querySelectorAll(i),vs);else{var m=n.querySelector(i)??n.querySelector("option:not([disabled])");u=m&&vs(m)}r(u),n.__value=u,Lr!==null&&s.add(Lr)}),Xc(()=>{var a=e();if(n===document.activeElement){var i=Lr;if(s.has(i))return}if(ia(n,a,o),o&&a===void 0){var u=n.querySelector(":checked");u!==null&&(a=vs(u),r(a))}n.__value=a,o=!1}),el(n)}function vs(n){return"__value"in n?n.__value:n.value}function ar(n,e,r=e){var s=new WeakSet;Qs(n,"input",async o=>{var a=o?n.defaultValue:n.value;if(a=xo(n)?_o(a):a,r(a),Lr!==null&&s.add(Lr),await Qc(),a!==(a=e())){var i=n.selectionStart,u=n.selectionEnd,m=n.value.length;if(n.value=a??"",u!==null){var v=n.value.length;i===u&&u===m&&v>m?(n.selectionStart=v,n.selectionEnd=v):(n.selectionStart=i,n.selectionEnd=Math.min(u,v))}}}),(er&&n.defaultValue!==n.value||Ar(e)==null&&n.value)&&(r(xo(n)?_o(n.value):n.value),Lr!==null&&s.add(Lr)),na(()=>{var o=e();if(n===document.activeElement){var a=Lr;if(s.has(a))return}xo(n)&&o===_o(n.value)||n.type==="date"&&!o&&!n.value||o!==n.value&&(n.value=o??"")})}const mo=new Set;function Nr(n,e,r,s,o=s){var a=r.getAttribute("type")==="checkbox",i=n;let u=!1;if(e!==null)for(var m of e)i=i[m]??=[];i.push(r),Qs(r,"change",()=>{var v=r.__value;a&&(v=Va(i,v,r.checked)),o(v)},()=>o(a?[]:null)),na(()=>{var v=s();if(er&&r.defaultChecked!==r.checked){u=!0;return}a?(v=v||[],r.checked=v.includes(r.__value)):r.checked=Wi(r.__value,v)}),qi(()=>{var v=i.indexOf(r);v!==-1&&i.splice(v,1)}),mo.has(i)||(mo.add(i),Wa(()=>{i.sort((v,g)=>v.compareDocumentPosition(g)===4?-1:1),mo.delete(i)})),Wa(()=>{if(u){var v;if(a)v=Va(i,v,r.checked);else{var g=i.find(_=>_.checked);v=g?.__value}o(v)}})}function Zn(n,e,r=e){Qs(n,"change",s=>{var o=s?n.defaultChecked:n.checked;r(o)}),(er&&n.defaultChecked!==n.checked||Ar(e)==null)&&r(n.checked),na(()=>{var s=e();n.checked=!!s})}function Va(n,e,r){for(var s=new Set,o=0;o<n.length;o+=1)n[o].checked&&s.add(n[o].__value);return r||s.delete(e),Array.from(s)}function xo(n){var e=n.type;return e==="number"||e==="range"}function _o(n){return n===""?null:+n}const kd=!1,Sd=!0,sx=Object.freeze(Object.defineProperty({__proto__:null,prerender:Sd,ssr:kd},Symbol.toStringTag,{value:"Module"})),yo="Wherever",Td="Create & maintain apps from wherever with a beautiful remote workspace.",wo="https://localhost",Ad="#000000",Cd="black-translucent";function Qr(n,e){return od(n)}var Rd=b('<meta name="title"/> <meta name="description"/> <!> <meta property="og:type"/> <meta property="og:url"/> <meta property="og:title"/> <meta property="og:description"/> <meta property="og:image"/> <meta property="twitter:card" content="summary_large_image"/> <meta property="twitter:url"/> <meta property="twitter:title"/> <meta property="twitter:description"/> <meta property="twitter:image"/> <link rel="icon" type="image/png"/> <link rel="icon" sizes="any"/> <link rel="apple-touch-icon"/> <link rel="manifest"/> <meta name="theme-color"/> <meta name="mobile-web-app-capable" content="yes"/> <meta name="application-name"/> <meta name="apple-mobile-web-app-capable" content="yes"/> <meta name="apple-mobile-web-app-status-bar-style"/> <meta name="apple-mobile-web-app-title"/> <meta name="version"/>',1);function Ed(n,e){hr(e,!0);const r=wo.endsWith("/")?wo.slice(0,-1):wo,s=r+"/preview.png";let o=D(()=>e.home||!1),a=D(()=>({type:e.type||"website",title:e.title||yo,description:e.description||Td,image:e.image||s,url:`${r}${md.url.pathname}`}));xd("13n5pl5",i=>{var u=Rd(),m=Ot(u),v=f(m,2),g=f(v,2);{var _=ht=>{var Ke=dr(),tt=Ot(Ke);w(tt,xt=>{}),h(ht,Ke)};w(g,ht=>{t(o)&&ht(_)})}var y=f(g,2),$=f(y,2),O=f($,2),z=f(O,2),W=f(z,2),$e=f(W,4),oe=f($e,2),ze=f(oe,2),X=f(ze,2),fe=f(X,2),Q=f(fe,2),Ee=f(Q,2),gt=f(Ee,2),We=f(gt,2),ae=f(We,4),qe=f(ae,4),pt=f(qe,2),mt=f(pt,2);C((ht,Ke,tt,xt)=>{Y(m,"content",t(a).title),Y(v,"content",t(a).description),Y(y,"content",t(a).type),Y($,"content",t(a).url),Y(O,"content",t(a).title),Y(z,"content",t(a).description),Y(W,"content",t(a).image),Y($e,"content",t(a).url),Y(oe,"content",t(a).title),Y(ze,"content",t(a).description),Y(X,"content",t(a).image),Y(fe,"href",ht),Y(Q,"href",Ke),Y(Ee,"href",tt),Y(gt,"href",xt),Y(We,"content",Ad),Y(ae,"content",yo),Y(qe,"content",Cd),Y(pt,"content",yo),Y(mt,"content",Fs)},[()=>Qr("/pwa/favicon.png"),()=>Qr("/pwa/favicon.ico"),()=>Qr("/pwa/apple-touch-icon.png"),()=>Qr("/pwa/manifest.webmanifest")]),ed(()=>{td.title=t(a).title??""}),h(i,u)}),br()}let ss=null;function Id(){if(typeof window>"u")return null;try{if(!ss){const n=window.AudioContext||window.webkitAudioContext;if(!n)return null;ss=new n}return ss.state==="suspended"&&ss.resume().catch(()=>{}),ss}catch{return null}}function Ya(n,e,r,s,o){const a=n.createOscillator(),i=n.createGain();a.type="sine",a.frequency.value=e;const u=.015;i.gain.setValueAtTime(1e-4,r),i.gain.exponentialRampToValueAtTime(o,r+u),i.gain.exponentialRampToValueAtTime(1e-4,r+s),a.connect(i),i.connect(n.destination),a.start(r),a.stop(r+s+.02)}const Xa=new Map;function Md(n){if(typeof Audio>"u")return!1;try{let e=Xa.get(n);e||(e=new Audio(n),e.preload="auto",Xa.set(n,e));try{e.currentTime=0}catch{}const r=e.play();return r&&typeof r.catch=="function"&&r.catch(()=>{}),!0}catch{return!1}}function tl(n){if(n&&n.trim()&&Md(n.trim()))return;const e=Id();if(e)try{const r=e.currentTime;Ya(e,1046.5,r,.16,.12),Ya(e,1396.9,r+.13,.22,.12)}catch{}}function la(n){if(!n)return null;const e=n.trimStart(),r=e.match(/^<skill\s+name="([^"]*)"[^>]*>/);if(r){const s=e.indexOf("</skill>");return s===-1?null:{skillName:r[1],args:e.slice(s+8).trim()}}if(e.startsWith("/skill:")){const s=e.slice(7),o=s.indexOf(" "),a=o===-1?s:s.slice(0,o);if(!a)return null;const i=o===-1?"":s.slice(o+1).trim();return{skillName:a,args:i}}return null}function $s(n){const e=la(n);return e?`skill:${e.skillName}\0${e.args}`:null}function Bs(){}function $d(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Od(n,...e){if(n==null)return Bs;const r=n.subscribe(...e);return r.unsubscribe?()=>r.unsubscribe():r}function Ft(n){let e;return Od(n,r=>e=r)(),e}var Vr=[];function Za(n,e=Bs){let r;const s=new Set;function o(u){if($d(n,u)&&(n=u,r)){const m=!Vr.length;for(const v of s)v[1](),Vr.push(v,n);if(m){for(let v=0;v<Vr.length;v+=2)Vr[v][0](Vr[v+1]);Vr.length=0}}}function a(u){o(u(n))}function i(u,m=Bs){const v=[u,m];return s.add(v),s.size===1&&(r=e(o)||Bs),u(n),()=>{s.delete(v),s.size===0&&(r(),r=null)}}return{set:o,update:a,subscribe:i}}function Ja(){return`ck-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}const Ld="upload.v1",to=1024,Qa=64*to,Dd=1024*to,Pd=256*to,Nd=2,ei=.3,ti=3*256*to,nl="The file is no longer readable, pick it again";function Ud(n,e,r){const s=3+n.length,o=new Uint8Array(s+8+r.length);o[0]=1,o[1]=1,o[2]=n.length;for(let i=0;i<n.length;i++)o[3+i]=n.charCodeAt(i);const a=new DataView(o.buffer);return a.setUint32(s,Math.floor(e/2**32)),a.setUint32(s+4,e>>>0),o.set(r,s+8),o}function rl(n){let e="";for(let r=0;r<n.length;r+=32768)e+=String.fromCharCode.apply(null,n.subarray(r,r+32768));return e}function Fd(){const n=new Uint8Array(16),e=globalThis.crypto;if(e&&typeof e.getRandomValues=="function")e.getRandomValues(n);else for(let r=0;r<n.length;r++)n[r]=Math.floor(Math.random()*256);return btoa(rl(n)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}class ts extends Error{code}function ko(n){if(n instanceof ts)return n;if(n&&n.name==="NotReadableError"){const e=new ts(nl);return e.code="not_readable",e}return new ts(`Failed to read the file: ${n&&n.message||n}`)}function ni(){const n=new ts(nl);return n.code="not_readable",n}function sl(n){return n.startsWith("http")?n.replace(/^https?:\/\//,""):n}function Bd(n){let e=2166136261;for(let r=0;r<n.length;r++)e^=n.charCodeAt(r),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}function Ks(n){return`${sl(n.host)}:${n.port}#${Bd(n.token??"")}`}const So={connected:!1,connecting:!1,creatingSession:!1,loadingSession:!1,resyncing:!1,agentPending:!1,error:null,session:null,sessionId:null,isStreaming:!1,messages:[],clientId:null,serverVersion:null,piVersion:null,folderConflict:null,folderMissing:null,restore:null,isInterrupted:!1,notice:null,sudoPrompt:null,sessionError:null,readOnly:!1,activeSessionFile:null,activeCwd:null,activeModel:null,hideThinking:!1,hideTools:!1,historyTotalCount:0,historyOffset:0,loadingMoreHistory:!1,historyAuthoritative:!1,serverKey:null,contextUsage:null,pendingSteering:[],skills:[]};class Dn{ws=null;config;clientKey;stateStore;reconnectTimer=null;agentEndTimeout=null;loadWatchdog=null;static LOAD_WATCHDOG_MS=12e3;createWatchdog=null;static CREATE_WATCHDOG_MS=25e3;reconnectAttempts=0;reconnectDelay=2e3;maxReconnectDelay=15e3;hasEverConnected=!1;static HANDSHAKE_FAIL_HINT_AFTER=2;livenessTimer=null;heartbeatTimer=null;lastInboundAt=0;static STALE_SOCKET_MS=6e4;static TURN_STALL_MS=45e3;static HEARTBEAT_MS=25e3;static PROBE_GRACE_MS=5e3;probeTimer=null;lastLivenessTickAt=0;isInitialConnect=!0;resumeSessionFile=null;resumeCwd;resumeModel;pendingLoadFile=null;socketServerKey=null;hydratedFile=null;listeners=new Set;pendingUploads=new Map;uploadsStore=Za({});socketCapabilities=null;static MAX_UPLOAD_SENDS=3;static MAX_UPLOAD_BASE64_CHARS=96*1024*1024;static MAX_LEGACY_UPLOAD_BYTES=72*1024*1024;static UPLOAD_TIMEOUT_MS=10*6e4;uploadsHeldForRejoin=!1;confirmTimers=new Map;static CONFIRM_MS=12e3;static PENDING_PREFIX="wherever-pending:";constructor(e){this.config={secure:!0,...e},this.clientKey=this.config.clientKey||Ja(),this.stateStore=Za({...So,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}connect(e,r=!1){e&&(this.config={...this.config,...e}),this.disconnect(!1);const s=Ks(this.config),o=Ft(this.stateStore).serverKey;o!==null&&o!==s&&(r=!1,this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,this.pendingLoadFile=null,this.hydratedFile=null),this.socketServerKey=s,this.stateStore.update(z=>r?{...z,connecting:!0,error:null}:{...So,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const a=this.config.secure?"wss":"ws",i=sl(this.config.host),u=[];this.config.token&&u.push(`token=${encodeURIComponent(this.config.token)}`),u.push(`clientKey=${encodeURIComponent(this.clientKey)}`);const m=`${a}://${i}:${this.config.port}/ws?${u.join("&")}`,v=this.config.WebSocketCtor||(typeof globalThis<"u"?globalThis.WebSocket:null);if(!v){this.stateStore.update(z=>({...z,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}this.socketCapabilities=null;try{const z=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=z?new v(m,z):new v(m)}catch(z){this.stateStore.update(W=>({...W,connecting:!1,error:`Failed to connect: ${z}`})),this.scheduleReconnect();return}const g=this.ws,_=()=>{if(this.ws!==g)return;this.isInitialConnect||console.info("[wherever] reconnected to relay"),this.hasEverConnected=!0,this.reconnectAttempts=0,this.reconnectDelay=2e3,this.isInitialConnect=!1,this.startLivenessWatchdog(),this.stateStore.update(ze=>({...ze,connected:!0,connecting:!1,error:null}));const z=Ft(this.stateStore),W=this.resumeSessionFile??z.activeSessionFile,$e=this.resumeSessionFile!=null?this.resumeCwd:z.activeCwd??void 0,oe=this.resumeSessionFile!=null?this.resumeModel:z.activeModel??void 0;this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,this.uploadsHeldForRejoin=!!W,W||this.rejectPendingUploads("The session was closed before the upload could be sent"),W?(this.stateStore.update(ze=>ze.resyncing&&!ze.historyAuthoritative?ze:{...ze,resyncing:!0,historyAuthoritative:!1}),this.pendingLoadFile=W,this.send({type:"session_load",sessionFile:W,cwd:$e,model:oe}),this.armLoadWatchdog()):this.stateStore.update(ze=>ze.resyncing?{...ze,resyncing:!1}:ze)},y=z=>{if(this.ws===g){this.lastInboundAt=Date.now(),this.cancelLivenessProbe();try{const W=typeof z.data=="string"?z.data:z.data.toString(),$e=JSON.parse(W);this.handleMessage($e)}catch(W){console.error("Failed to parse WebSocket message:",W)}}},$=()=>{this.ws===g&&(this.uploadsLostSocket(),this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.ws=null,this.stateStore.update(z=>({...z,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:z.activeSessionFile?!0:z.resyncing})),this.scheduleReconnect())},O=z=>{this.ws===g&&this.stateStore.update(W=>({...W,error:W.error||"Connection error occurred"}))};typeof g.addEventListener=="function"?(g.addEventListener("open",_),g.addEventListener("message",y),g.addEventListener("close",$),g.addEventListener("error",O)):typeof g.on=="function"&&(g.on("open",_),g.on("message",z=>y({data:z})),g.on("close",$),g.on("error",O))}disconnect(e=!0){if(this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.clearCreateWatchdog(),this.uploadsLostSocket(),this.ws){const r=this.ws;try{typeof r.removeAllListeners=="function"&&r.removeAllListeners();const s=()=>{};typeof r.on=="function"?r.on("error",s):typeof r.addEventListener=="function"?r.addEventListener("error",s):r.onerror=s,r.close()}catch{}this.ws=null}if(e){for(const r of this.confirmTimers.values())clearTimeout(r);this.confirmTimers.clear(),this.rejectPendingUploads("Disconnected before the upload completed"),this.uploadsHeldForRejoin=!1,this.hydratedFile=null,this.stateStore.set({...So,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}else this.stateStore.update(r=>({...r,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1}))}suspend(){const e=Ft(this.stateStore);e.activeSessionFile&&(this.resumeSessionFile=e.activeSessionFile,this.resumeCwd=e.activeCwd??void 0,this.resumeModel=e.activeModel??void 0),e.isStreaming&&this.stateStore.update(r=>({...r,isStreaming:!1})),this.disconnect(!1)}resume(){const e=Ft(this.stateStore);e.connected||e.connecting||((this.resumeSessionFile||e.activeSessionFile)&&this.stateStore.update(r=>({...r,resyncing:!0})),this.connect(void 0,!0))}hasSuspendedSession(){return this.resumeSessionFile!==null}hasActiveSession(){return this.resumeSessionFile!==null||Ft(this.stateStore).activeSessionFile!==null}startLivenessWatchdog(){this.stopLivenessWatchdog(),this.lastInboundAt=Date.now(),this.lastLivenessTickAt=this.lastInboundAt;const e=()=>{try{this.ping()}catch{}};typeof setInterval=="function"&&(this.heartbeatTimer=setInterval(e,Dn.HEARTBEAT_MS),this.heartbeatTimer&&typeof this.heartbeatTimer.unref=="function"&&this.heartbeatTimer.unref());const r=()=>{if(!this.ws)return;const s=Date.now(),o=s-this.lastLivenessTickAt;if(this.lastLivenessTickAt=s,o>2*Dn.HEARTBEAT_MS){this.startLivenessProbe("clock jump");return}const a=s-this.lastInboundAt,i=Ft(this.stateStore).isStreaming,u=i?Dn.TURN_STALL_MS:Dn.STALE_SOCKET_MS;a<u||this.startLivenessProbe(`no inbound frame for ${a}ms (threshold ${u}ms, ${i?"mid-turn":"idle"})`)};typeof setInterval=="function"&&(this.livenessTimer=setInterval(r,Dn.HEARTBEAT_MS),this.livenessTimer&&typeof this.livenessTimer.unref=="function"&&this.livenessTimer.unref())}noteVisible(){const e=this.ws;!e||e.readyState!==1||!this.livenessTimer||(this.lastInboundAt=Date.now(),this.lastLivenessTickAt=this.lastInboundAt,this.cancelLivenessProbe(),this.startLivenessProbe("page became visible"))}startLivenessProbe(e){if(this.probeTimer||!this.ws||typeof setTimeout!="function")return;const r=this.ws;try{this.ping()}catch{}const s=Date.now();this.probeTimer=setTimeout(()=>{if(this.probeTimer=null,this.ws===r){if(Date.now()-s>2*Dn.PROBE_GRACE_MS){this.startLivenessProbe(e);return}this.tearDownStaleSocket(e)}},Dn.PROBE_GRACE_MS),this.probeTimer&&typeof this.probeTimer.unref=="function"&&this.probeTimer.unref()}cancelLivenessProbe(){this.probeTimer&&(clearTimeout(this.probeTimer),this.probeTimer=null)}tearDownStaleSocket(e){if(!this.ws)return;const r=Ft(this.stateStore).isStreaming;console.warn(`[wherever] relay connection stale: ${e}; probe unanswered for ${Dn.PROBE_GRACE_MS}ms; tearing down dead socket and reconnecting`),this.stopLivenessWatchdog();const s=this.ws;this.ws=null,this.uploadsLostSocket();try{typeof s.terminate=="function"?s.terminate():typeof s.close=="function"&&s.close()}catch{}this.stateStore.update(o=>({...o,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:r?"Connection to relay stalled mid-turn; reconnecting...":o.sessionError,isStreaming:!1})),this.scheduleReconnect()}stopLivenessWatchdog(){this.cancelLivenessProbe(),this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null),this.livenessTimer&&(clearInterval(this.livenessTimer),this.livenessTimer=null)}armLoadWatchdog(){this.clearLoadWatchdog(),this.loadWatchdog=setTimeout(()=>{this.loadWatchdog=null;const e=Ft(this.stateStore);!e.loadingSession&&!e.resyncing||(console.warn("[wherever] session load timed out; clearing loading state"),this.failHeldUploads("Could not rejoin the session, so the upload was not sent"),this.stateStore.update(r=>({...r,loadingSession:!1,resyncing:!1,sessionError:r.sessionError||"Loading the session timed out. Please retry from the sidebar or reload."})))},Dn.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,Ft(this.stateStore).creatingSession&&(console.warn("[wherever] session create timed out; clearing creating state"),this.stateStore.update(r=>({...r,creatingSession:!1,sessionError:r.sessionError||"Creating the session timed out. It may still be starting on the server; check the sidebar or reload."})))},Dn.CREATE_WATCHDOG_MS)}clearCreateWatchdog(){this.createWatchdog&&(clearTimeout(this.createWatchdog),this.createWatchdog=null)}scheduleReconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{if(this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*1.5,this.maxReconnectDelay),console.info(`[wherever] reconnecting to relay (attempt ${++this.reconnectAttempts})`),!this.hasEverConnected&&this.reconnectAttempts>=Dn.HANDSHAKE_FAIL_HINT_AFTER){const r=this.config.secure?"wss":"ws";this.stateStore.update(s=>({...s,error:`Cannot connect to the wherever server: the connection is being rejected. This usually means a missing or wrong token, or a wrong host/port/scheme (currently ${r}://${this.config.host}:${this.config.port}). Check the auth token and connection settings.`}))}const e=!!Ft(this.stateStore).activeSessionFile;this.stateStore.update(r=>({...r,connecting:!0,error:"Reconnecting..."})),this.connect(void 0,e)},this.reconnectDelay))}handleMessage(e){for(const r of this.listeners)try{r(e)}catch(s){console.error("Error in message listener:",s)}switch(e.type){case"message_history":{const r=Ft(this.stateStore).sessionId;if(r&&e.sessionId&&e.sessionId!==r)break;this.clearLoadWatchdog();break}case"session_error":case"session_destroyed":case"session_interrupted":this.clearLoadWatchdog();break}switch(e.type){case"session_created":case"session_error":case"session_interrupted":this.clearCreateWatchdog();break}switch(e.type){case"connected":this.stateStore.update(s=>({...s,connected:!0,connecting:!1,clientId:e.clientId,serverVersion:e.serverVersion??null,piVersion:e.piVersion??null,error:null})),this.socketCapabilities=Array.isArray(e.capabilities)?e.capabilities.filter(s=>typeof s=="string"):[],this.resendPendingUploads();break;case"connection_superseded":this.clientKey=Ja();try{this.config.onClientKeyChange?.(this.clientKey)}catch(s){console.error("onClientKeyChange failed:",s)}break;case"file_uploaded":this.completeUpload(e.uploadId,{savedPath:e.savedPath,filename:e.filename});break;case"file_upload_error":this.failUpload(e.uploadId,e.error);break;case"upload_offset":this.handleUploadOffset(e);break;case"agent_start":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.stateStore.update(s=>({...s,isStreaming:!0}));break;case"thinking_update":this.stateStore.update(s=>{let o=[...s.messages].reverse().find(a=>a.role==="thinking"&&a.isStreaming);if(!o){const a={id:this.generateId(),role:"thinking",content:e.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,a]}}return{...s,messages:s.messages.map(a=>a.id===o.id?{...a,content:a.content+e.delta,isStreaming:!0}:a)}});break;case"message_update":this.stateStore.update(s=>{let o=[...s.messages].reverse().find(a=>a.role==="assistant"&&a.isStreaming);if(!o){const a={id:this.generateId(),role:"assistant",content:e.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,a]}}return{...s,messages:s.messages.map(a=>a.id===o.id?{...a,content:a.content+e.delta,isStreaming:!0}:a)}});break;case"message_ack":typeof e.content=="string"&&this.confirmDeliveredByContent(e.content);break;case"queue_update":{const s=Array.isArray(e.steering)?[...e.steering]:[];this.stateStore.update(o=>({...o,pendingSteering:s,messages:this.withRestoredQueuedMessages(o.messages,s)}));break}case"message_end":this.stateStore.update(s=>{let o=s.messages;const a=[...o].reverse().find(u=>u.role==="thinking"&&u.isStreaming);a&&(o=o.map(u=>u.id===a.id?{...u,isStreaming:!1}:u));const i=[...o].reverse().find(u=>u.role==="assistant"&&u.isStreaming);if(i)o=o.map(u=>u.id===i.id?{...u,content:e.content||u.content,isStreaming:!1}:u);else if(e.content){if(e.role==="user"){if(this.confirmDeliveredByContent(e.content))return Ft(this.stateStore);const _=o.find(y=>y.role==="user"&&y.restoredFromQueue&&y.content===e.content);if(_)return{...s,messages:o.map(y=>y.id===_.id?{...y,restoredFromQueue:void 0}:y)}}const u=e.role==="user"?$s(e.content):null;if(u){const g=[...o].reverse().find(_=>_.role==="user"&&$s(_.content)===u);if(g)return g.content!==e.content&&(o=o.map(_=>_.id===g.id?{..._,content:e.content}:_)),{...s,messages:o}}const m=[...o].reverse().find(g=>g.role==="user");e.role==="user"&&m&&m.content===e.content||(o=[...o,{id:this.generateId(),role:e.role||"assistant",content:e.content,timestamp:Date.now(),isStreaming:!1}])}return{...s,messages:o}});break;case"agent_end":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.agentEndTimeout=setTimeout(()=>{const s=Date.now();this.stateStore.update(o=>({...o,isStreaming:!1,pendingSteering:[],messages:o.messages.map(a=>a.isStreaming?{...a,isStreaming:!1,...a.role==="tool"?{interrupted:!0}:{},endedAt:a.role==="tool"&&a.endedAt===void 0?s:a.endedAt}:a)})),this.agentEndTimeout=null},300);break;case"tool_start":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null);const r=e.args?Object.entries(e.args).filter(([s,o])=>o!==void 0&&o!=="").map(([s,o])=>`${s}=${JSON.stringify(o)}`).join(" "):"";this.stateStore.update(s=>{const o=s.messages.map(m=>m.isStreaming&&(m.role==="assistant"||m.role==="thinking")?{...m,isStreaming:!1}:m),a=Date.now(),i=!!e.forceCommand;if(i){const m=o.find(v=>v.role==="tool"&&v.optimistic&&v.isStreaming);if(m)return{...s,messages:o.map(v=>v.id===m.id?{...v,optimistic:!1,toolName:e.toolName,toolArgs:r,content:r?`$ ${e.toolName} ${r}`:`$ ${e.toolName}`,startedAt:a,timestamp:a,forceCommand:!0}:v)}}const u={id:this.generateId(),role:"tool",content:r?`$ ${e.toolName} ${r}`:`$ ${e.toolName}`,timestamp:a,isStreaming:!0,toolName:e.toolName,toolArgs:r,toolOutput:"",startedAt:a,...i?{forceCommand:!0}:{}};return{...s,messages:[...o,u]}});break;case"tool_update":{this.stateStore.update(s=>{const o=[...s.messages].reverse().find(a=>a.role==="tool"&&a.toolName===e.toolName&&a.isStreaming);return o?{...s,messages:s.messages.map(a=>a.id===o.id?{...a,content:a.content.includes(`
2
2
  `)?a.content+e.delta:`${a.content}
3
3
  ${e.delta}`,toolOutput:`${a.toolOutput}${e.delta}`}:a)}:s});break}case"tool_end":{const s=e.result?`${e.result}`:"",o=!!e.isError&&this.isAbortedToolResult(s),a=!!e.isError&&!o,i=Array.isArray(e.images)&&e.images.length>0?e.images:void 0;this.stateStore.update(u=>{const m=u.messages.find(g=>g.role==="tool"&&g.toolName===e.toolName&&g.isStreaming)??[...u.messages].reverse().find(g=>g.role==="tool"&&g.toolName===e.toolName&&!g.content.startsWith("Tool error:")),v=Date.now();if(m){const g=a?"Error: ":"";return{...u,messages:u.messages.map(_=>_.id===m.id?{..._,content:`${g}${_.content}
4
4
  ${s}`,isStreaming:!1,isError:a,interrupted:o,toolOutput:s,...i?{images:i}:{},endedAt:v}:_)}}else{const g=a?`Tool error: ${e.toolName}
@@ -117,4 +117,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
117
117
  it had created was removed.`)),h(se,Pe)};w(Je,se=>{t(v)?.state==="cancelled"&&se(ee)})}var q=f(Je,2);{var Z=se=>{var Pe=Qg(),Ye=d(Pe),dt=d(Ye,!0);c(Ye);var _t=f(Ye,2);{var Dt=qt=>{var ln=Jg(),en=Ot(ln),Sn=d(en);c(en);var Tn=f(en,2);{var cn=jt=>{var tn=Zg(),yn=d(tn,!0);c(tn),C(()=>I(yn,t(y).stderr)),h(jt,tn)};w(Tn,jt=>{t(Q)&&jt(cn)})}C(()=>I(Sn,`${t(Q)?"Hide":"Show"} git output`)),M("click",en,()=>p(Q,!t(Q))),h(qt,ln)};w(_t,qt=>{t(y).stderr&&qt(Dt)})}c(Pe),C(()=>I(dt,t(y).message)),h(se,Pe)};w(q,se=>{t(y)&&se(Z)})}var ie=f(q,2);{var ce=se=>{var Pe=em(),Ye=d(Pe,!0);c(Pe),C(()=>I(Ye,t($).message)),h(se,Pe)};w(ie,se=>{t($)&&se(ce)})}var Fe=f(ie,4);Ct(Fe);var P=f(Fe,2);{var Qe=se=>{var Pe=nm();In(Pe,21,()=>t(X),Ye=>Ye.url,(Ye,dt)=>{var _t=tm(),Dt=d(_t,!0);c(_t),C(()=>I(Dt,t(dt).url)),M("click",_t,()=>{p(oe,t(dt).url,!0),p(ze,!0)}),h(Ye,_t)}),c(Pe),h(se,Pe)},ye=se=>{var Pe=rm();h(se,Pe)};w(P,se=>{t(X).length>1?se(Qe):!t(fe)&&t(X).length===0&&se(ye,1)})}var S=f(P,2),te=d(S,!0);c(S);var K=f(S,2),ue=d(K);{var Be=se=>{var Pe=sm();M("click",Pe,()=>p(Ee,!0)),h(se,Pe)},Ve=se=>{var Pe=om(),Ye=f(Ot(Pe),2),dt=d(Ye);Ct(dt),ft(2),c(Ye);var _t=f(Ye,2),Dt=d(_t,!0);c(_t),C(()=>{ra(dt,t(gt)),_t.disabled=t(z),I(Dt,t(z)?"Creating...":"Create folder")}),M("change",dt,qt=>p(We,qt.currentTarget.checked,!0)),M("click",_t,pt),h(se,Pe)};w(ue,se=>{t(Ee)?se(Ve,-1):se(Be)})}c(K),C(se=>{Y(Fe,"placeholder",t(fe)?"Looking for the repository...":"git@github.com:owner/repo.git"),S.disabled=se,I(te,t(z)?"Starting...":"Clone repository")},[()=>!t(oe).trim()||t(z)]),M("input",Fe,()=>p(ze,!0)),M("keydown",Fe,se=>{se.key==="Enter"&&qe()}),ar(Fe,()=>t(oe),se=>p(oe,se)),M("click",S,qe),h(Ht,It)};w(nt,Ht=>{t(_)?Ht(rt):t(g)?Ht(Xt,1):Ht(ct,-1)})}c(xt),C(()=>I(_e,t(u).cwd)),h(tt,xt)};w(ht,tt=>{t(u)&&tt(Ke)})}h(n,mt),br(),i()}Mr(["click","input","keydown","change"]);function cm(n){return n.loading||n.resyncing||n.hasSessionHash&&!n.loadFailed}function dm(n){return n.connected&&n.searchConfigured&&!n.hasSession&&!cm(n)}function ji(n){return!n.connected||!n.hashId||n.currentSessionId===n.hashId||n.loading||n.resyncing?"skip":n.attemptedHashId===n.hashId?n.currentSessionId?"skip":"failed":"join"}var um=b('<div class="mt-2 font-mono text-xs break-all text-brand-text-muted"> </div>'),fm=b(`<div class="fixed inset-0 z-[100] flex items-center justify-center bg-brand-dark/60 p-4 backdrop-blur-sm"><div class="w-full max-w-sm rounded-lg border border-brand-border bg-brand-surface-2 p-5 text-brand-text"><div class="text-base font-bold">Cloning the repository...</div> <div class="mt-1 text-xs text-brand-text-muted">The session is created as soon as the clone finishes, so there is
118
118
  nothing to wait for afterwards. It keeps running on the server if this
119
119
  page goes away.</div> <!> <!> <button type="button" class="mt-3 rounded bg-brand-surface-3 px-3.5 py-1.5 text-xs font-semibold text-brand-text transition-colors hover:bg-brand-surface-2">Cancel</button></div></div>`),pm=b('<div class="fixed inset-0 z-[100] flex items-center justify-center bg-brand-dark/60 backdrop-blur-sm"><div class="flex flex-col items-center gap-4"><div class="h-12 w-12 animate-spin rounded-full border-4 border-brand-blue border-t-transparent"></div> <span class="text-lg font-bold text-brand-text">Creating session...</span></div></div>'),hm=b('<span class="text-lg font-bold text-brand-text">Connection Settings</span> <button class="rounded px-2 py-1 text-xs font-semibold text-brand-blue transition-colors hover:bg-brand-surface-2 hover:text-brand-blue">◀ Back</button>',1),bm=b('<span class="max-w-32 truncate rounded-full border border-brand-border bg-brand-blue/15 px-2 py-0.5 text-[10px] font-semibold text-brand-blue"> </span>'),vm=b('<button class="flex items-center gap-2 text-left" title="Show Main Screen / New Session"><img alt="Wherever" class="h-6 w-6"/> <span class="gradient-text text-lg font-bold">Wherever</span> <!></button> <div class="flex items-center gap-2"><button class="flex items-center gap-1 rounded border border-brand-border px-1.5 py-1 text-xs text-brand-text-muted transition-colors hover:bg-brand-surface-2 hover:text-brand-text" title="Connection Settings">⚙️ Config</button> <button class="text-brand-text-muted hover:text-brand-text md:hidden">X</button></div>',1),gm=b('<div class="flex-1 overflow-y-auto"><!> <div class="mt-2 border-t border-brand-border p-4"><h3 class="mb-3 text-xs font-bold tracking-wider text-brand-text-muted uppercase">Server Control</h3> <div class="space-y-2"><button class="flex w-full items-center justify-between rounded border border-brand-border bg-brand-surface-2 px-3 py-2 text-left text-sm text-brand-text transition-colors hover:bg-brand-surface-3 hover:text-brand-text"><span>Refresh Session List</span> <span>🔄</span></button> <button class="flex w-full items-center justify-between rounded border border-brand-border bg-brand-surface-2 px-3 py-2 text-left text-sm text-brand-text transition-colors hover:bg-brand-surface-3 hover:text-brand-text"><span>Reconnect WebSocket</span> <span>🔌</span></button> <button class="flex w-full items-center justify-between rounded border border-red-500/30 bg-red-500/10 px-3 py-2 text-left text-sm text-rose-400 transition-colors hover:bg-red-500/20 hover:text-rose-300"><span>Disconnect Server</span> <span>🛑</span></button></div></div></div>'),mm=b('<span class="text-brand-text-muted/70"> </span>'),xm=b('<div class="truncate text-xs text-brand-text-muted"> </div>'),_m=b('<div class="truncate text-xs text-brand-text-muted"> </div>'),ym=b('<div class="mt-2 space-y-1"><!> <!> <div class="pt-1.5"><button class="w-full rounded border border-brand-border bg-brand-surface-2 px-2 py-1 text-center text-xs text-brand-text transition-colors hover:bg-brand-surface-3 hover:text-brand-text" title="Show Main Screen (Clear URL Hash)">Close Session</button></div></div>'),wm=b('<div class="mt-2 text-xs text-rose-400"> </div>'),km=b('<button class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs text-brand-text-muted transition-colors hover:bg-brand-surface-3/50 hover:text-brand-text" title="Search everything ever said in any session"><span>🔎</span> <span>Search conversations</span> <span class="ml-auto">→</span></button> <button class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs text-brand-text-muted transition-colors hover:bg-brand-surface-3/50 hover:text-brand-text" title="View read-only sessions (e.g. autonomous agent fleets)"><span>👁️</span> <span>Read-only sessions</span> <span class="ml-auto">→</span></button>',1),Sm=b('<button class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs font-semibold text-brand-blue transition-colors hover:bg-brand-surface-3/50" title="Back to the session list"><span>←</span> <span> </span></button>'),Tm=b('<button class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs font-semibold text-brand-blue transition-colors hover:bg-brand-surface-3/50" title="Back to your sessions"><span>←</span> <span>Back to sessions</span></button> <button class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs text-brand-text-muted transition-colors hover:bg-brand-surface-3/50 hover:text-brand-text" title="Search the read-only conversations"><span>🔎</span> <span>Search these conversations</span> <span class="ml-auto">→</span></button>',1),Am=b('<div class="border-b border-brand-border p-4"><div class="flex items-center gap-2"><div></div> <span> </span> <span class="ml-auto font-mono text-xs text-brand-text-muted"> <!></span></div> <!> <!></div> <div class="border-b border-brand-border/50 px-2 py-1.5"><!></div> <div class="flex-1 overflow-hidden"><!></div>',1),Cm=b('<button type="button" class="flex flex-shrink-0 items-center justify-center rounded border border-brand-border bg-brand-surface-2 px-2.5 py-1.5 text-sm text-brand-text-muted transition-colors hover:bg-brand-surface-3 hover:text-brand-text" title="Search the web" aria-label="Search the web">🔍</button>'),Rm=b('<span class="text-sm text-brand-text-muted">Search the web below, or pick a session from the sidebar</span>'),Em=b('<span class="text-sm text-brand-text-muted">Select a session from sidebar</span>'),Im=b('<span class="text-sm text-brand-text-muted">Not connected</span>'),Mm=b('<div class="flex min-w-0 items-center gap-2"><!></div>'),$m=b('<div class="flex min-w-0 items-center gap-1.5 text-xs text-brand-text-muted"><span class="flex-shrink-0">📁</span> <span class="truncate"> </span></div>'),Om=b("<option> </option>"),Lm=b('<select class="max-w-48 truncate rounded border border-brand-border bg-brand-surface-2 px-1.5 py-0.5 text-brand-text focus:border-brand-blue focus:outline-none"></select>'),Dm=b('<span class="truncate text-brand-text-muted"> </span>'),Pm=b('<div class="flex min-w-0 items-center gap-1.5 text-xs"><span class="relative flex flex-shrink-0 items-center justify-center text-sm"><span>🤖</span> <span></span></span> <!></div>'),Nm=b('<div class="flex min-w-0 flex-1 items-center gap-3"><!> <!></div>'),Um=b('<span class="flex-shrink-0 rounded bg-yellow-500/20 px-2 py-1 text-xs text-yellow-400">Read-only</span>'),Fm=b('<div class="border border-red-500/30 bg-red-500/10 px-4 py-2 text-center text-sm text-rose-400">Your session was interrupted — another client took over.</div>'),Bm=b('<div><span class="min-w-0 flex-1 break-words whitespace-pre-wrap"> </span> <button aria-label="Dismiss notice" class="flex-shrink-0 opacity-80 hover:opacity-100">X</button></div>'),zm=b('<button class="flex-shrink-0 rounded-md border border-yellow-500/40 bg-yellow-500/20 px-3 py-1 text-xs font-medium text-yellow-300 transition-colors hover:bg-yellow-500/30">Continue anyway</button>'),Hm=b('<div class="flex items-center justify-between gap-3 border border-yellow-500/30 bg-yellow-500/10 px-4 py-2 text-sm text-yellow-400"><span class="min-w-0 flex-1 break-words">⚠️ Another client is active in this folder. <!></span> <!></div>'),jm=b('<div class="flex items-start justify-between gap-2 border border-red-500/30 bg-red-500/10 px-4 py-2 text-sm text-rose-400"><span class="max-h-24 min-w-0 flex-1 overflow-y-auto break-words whitespace-pre-wrap"> </span> <button aria-label="Dismiss error" class="flex-shrink-0 text-rose-300 hover:text-rose-200">X</button></div>'),Gm=b('<div class="border border-yellow-500/30 bg-yellow-500/10 px-4 py-2 text-center text-sm text-yellow-400">Read-only: this session cannot be driven from here</div>'),Wm=b('<div class="border-t border-brand-border bg-brand-surface px-4 py-3 text-center text-xs text-brand-text-muted">👁️ Read-only session, observing only, no input.</div>'),qm=b('<div class="flex items-center justify-center gap-2 border-t border-brand-border bg-brand-surface px-4 py-2 text-center text-sm text-brand-text-muted"><span class="h-3.5 w-3.5 animate-spin rounded-full border-2 border-brand-blue border-t-transparent"></span> <span>Reconnecting and syncing session...</span></div>'),Km=b('<div class="flex items-center justify-center gap-2 border-t border-brand-border bg-brand-surface px-4 py-2 text-center text-sm text-brand-text-muted"><span class="h-3.5 w-3.5 animate-spin rounded-full border-2 border-brand-blue border-t-transparent"></span> <span>Preparing the session agent...</span></div>'),Vm=b("<!> <!>",1),Ym=b('<button type="button" class="fixed inset-0 z-10 bg-brand-dark/50 md:hidden" aria-label="Close sidebar"></button>'),Xm=b('<!> <!> <div class="fixed inset-0 flex overflow-hidden overscroll-none bg-brand-dark text-brand-text"><div><div class="border-b border-brand-border bg-brand-surface-2/20 p-4"><div class="flex items-center justify-between"><!></div></div> <!></div> <div class="flex min-w-0 flex-1 flex-col"><div class="app-chrome flex items-center gap-3 border-b border-brand-border bg-brand-surface p-3"><button class="p-1 text-brand-text-muted hover:text-brand-text md:hidden">=</button> <!> <!> <!> <!></div> <!> <!> <!> <!> <!> <!> <!></div> <!> <!></div>',1);function ox(n,e){hr(e,!0);const r=()=>Ae(Cs,"$isConnected",X),s=()=>Ae(Es,"$isResyncing",X),o=()=>Ae(ec,"$isAgentPending",X),a=()=>Ae(Rs,"$isLoadingSession",X),i=()=>Ae(Yl,"$isInterrupted",X),u=()=>Ae(lo,"$sessionError",X),m=()=>Ae(Zl,"$sessionNotice",X),v=()=>Ae(Vl,"$folderConflict",X),g=()=>Ae(ya,"$folderMissing",X),_=()=>Ae(co,"$isReadOnly",X),y=()=>Ae(rs,"$activeSessionInfo",X),$=()=>Ae(hn,"$piState",X),O=()=>Ae(sa,"$availableModels",X),z=()=>Ae(Ql,"$isCreatingSession",X),W=()=>Ae(wa,"$restoreState",X),$e=()=>Ae(Ki,"$searchFolderStore",X),oe=()=>Ae(bd,"$searchDefaultModelStore",X),ze=()=>Ae(vd,"$appearanceStore",X),[X,fe]=Ur();let Q=N(!1),Ee=N("main"),gt=N(!1),We=N("");function ae(L,T=""){p(gt,L,!0),p(We,T,!0),p(Ee,"search")}let qe=N(!1),pt,mt=!0;ys(()=>{{const V=Sl(S());setTimeout(()=>{hu({cached:V,hydrate:Tl,connect:me=>{mt=!1,Gr(me)}})},200)}const L=()=>{if(ye=null,t(_e)){const V=window.location.hash?decodeURIComponent(window.location.hash.slice(1)):"";V&&V!==t(P)?(ye=V,As(V)):!V&&t(P)&&fr()}};window.addEventListener("hashchange",L);let T=null;const U=8e3,ne=()=>{if(document.visibilityState==="hidden"){if(Uo(),El())return;T&&clearTimeout(T),T=setTimeout(()=>{T=null,document.visibilityState==="hidden"&&t(_e)&&Cl()},U)}else{ma(),T&&(clearTimeout(T),T=null),Bo();const V=ci({booting:mt,connected:t(_e),hasActiveSession:zo()});V==="resume"?Fo():V==="connect"&&Gr()}},re=V=>{if(T&&(clearTimeout(T),T=null),Bo(),document.visibilityState==="hidden")return;const me=ci({booting:mt,connected:t(_e),hasActiveSession:zo()});me==="resume"?Fo():me==="connect"&&Gr()},be=()=>Uo();return document.addEventListener("visibilitychange",ne),window.addEventListener("pageshow",re),window.addEventListener("pagehide",be),()=>{window.removeEventListener("hashchange",L),document.removeEventListener("visibilitychange",ne),window.removeEventListener("pageshow",re),window.removeEventListener("pagehide",be),T&&clearTimeout(T)}});function ht(){Gr()}function Ke(){fr(),_s(),ba()}function tt(){_s(),setTimeout(()=>Gr(),100)}function xt(){bs()}function Lt(){typeof window<"u"&&(window.location.hash=""),fr(),p(Q,!1)}let _e=D(r),nt=D(s),rt=D(o),Xt=D(a),ct=D(i),Ht=D(u),It=D(m),Je=D(v),ee=D(g),q=D(_),Z=D(y),ie=D($),ce=D(()=>O().models),Fe=N(!1),P=D(()=>t(Z).sessionId);Bt(()=>{typeof window<"u"&&t(_e)&&(t(P)?(window.location.hash=encodeURIComponent(t(P)),p(Fe,!0)):t(Fe)&&(p(Fe,!1),window.location.hash&&(window.location.hash="")))});let Qe=null,ye=null;function S(){return typeof window>"u"||!window.location.hash?"":decodeURIComponent(window.location.hash.slice(1))}Bt(()=>{if(!t(_e)){ye=null;return}const L=S();L&&t(P)===L&&(ye=null);const T=ji({connected:t(_e),hashId:L,currentSessionId:t(P),loading:t(Xt),resyncing:t(nt),attemptedHashId:ye});if(T==="failed"){ye=null,window.location.hash&&history.replaceState(history.state,"",window.location.pathname+window.location.search);return}T==="join"&&(Qe||(Qe=setTimeout(()=>{Qe=null;const U=S();ji({connected:t(_e),hashId:U,currentSessionId:t(P),loading:t(Xt),resyncing:t(nt),attemptedHashId:ye})==="join"&&(ye=U,Dl(U))},300)))}),Bt(()=>{t(_e)||p(Fe,!1)}),Bt(()=>{(t(P)||t(Xt)||t(nt))&&p(Q,!1)});let te=D(z),K=D(()=>W()?.forSessionCreate?W():null),ue=D($e),Be=N(void 0),Ve=D(()=>dm({connected:t(_e),searchConfigured:!!t(ue),hasSession:!!t(Z).sessionFile,loading:t(Xt),resyncing:t(nt),hasSessionHash:typeof window<"u"&&!!window.location.hash,loadFailed:!!t(Ht)&&!t(Xt)&&!t(nt)&&!t(Z).sessionFile})),se=D(()=>t(ce).map(L=>({value:`${L.provider}:${L.modelId}`,label:`${L.label}${L.isDefault?" (default)":""}`}))),Pe=D(oe),Ye=D(()=>ze().label),dt=N("");Bt(()=>{if(t(se).length===0||t(se).some(ne=>ne.value===t(dt)))return;const T=t(se).find(ne=>ne.value===t(Pe)),U=t(ce).find(ne=>ne.isDefault);p(dt,T?T.value:U?`${U.provider}:${U.modelId}`:t(se)[0].value,!0)});let _t=N(!1);Bt(()=>{t(Ve)&&!t(_t)&&t(Be)&&(p(_t,!0),t(Be).focusInput())});function Dt(){typeof window<"u"&&window.location.hash&&(window.location.hash=""),fr(),t(Be)?.focusInput()}var qt=Xm(),ln=Ot(qt);{let L=D(()=>t(Ye)?`Wherever · ${t(Ye)}`:"Wherever");Ed(ln,{get title(){return t(L)},description:"Create & maintain apps from wherever"})}var en=f(ln,2);{var Sn=L=>{var T=fm(),U=d(T),ne=f(d(U),4);{var re=me=>{var Me=um(),Se=d(Me,!0);c(Me),C(()=>I(Se,t(K).job.url)),h(me,Me)};w(ne,me=>{t(K).job?.url&&me(re)})}var be=f(ne,2);Rc(be,{get job(){return t(K).job}});var V=f(be,2);c(U),c(T),M("click",V,()=>xa()),h(L,T)},Tn=L=>{var T=pm();h(L,T)};w(en,L=>{t(K)?L(Sn):t(te)&&L(Tn,1)})}var cn=f(en,2),jt=d(cn),tn=d(jt),yn=d(tn),Pn=d(yn);{var bt=L=>{var T=hm(),U=f(Ot(T),2);M("click",U,()=>p(qe,!1)),h(L,T)},kt=L=>{var T=vm(),U=Ot(T),ne=d(U),re=f(ne,4);{var be=Se=>{var yt=bm(),sn=d(yt,!0);c(yt),C(()=>{Y(yt,"title",t(Ye)),I(sn,t(Ye))}),h(Se,yt)};w(re,Se=>{t(Ye)&&Se(be)})}c(U);var V=f(U,2),me=d(V),Me=f(me,2);c(V),C(Se=>Y(ne,"src",Se),[()=>Qr("/logo.svg")]),M("click",U,Lt),M("click",me,()=>p(qe,!0)),M("click",Me,()=>p(Q,!1)),h(L,T)};w(Pn,L=>{t(qe)?L(bt):L(kt,-1)})}c(yn),c(tn);var _n=f(tn,2);{var An=L=>{var T=gm(),U=d(T);{let Me=D(()=>(t(ie).connected,"localhost"));Qu(U,{get host(){return t(Me)},port:31415,token:"",onConnected:ht})}var ne=f(U,2),re=f(d(ne),2),be=d(re),V=f(be,2),me=f(V,2);c(re),c(ne),c(T),M("click",be,xt),M("click",V,tt),M("click",me,Ke),h(L,T)},kn=L=>{var T=Am(),U=Ot(T),ne=d(U),re=d(ne),be=f(re,2),V=d(be,!0);c(be);var me=f(be,2),Me=d(me),Se=f(Me);{var yt=x=>{var A=mm(),F=d(A);c(A),C(()=>I(F,` / srv ${t(ie).serverVersion??""}`)),h(x,A)};w(Se,x=>{t(ie).serverVersion&&x(yt)})}c(me),c(ne);var sn=f(ne,2);{var On=x=>{var A=ym(),F=d(A);{var he=at=>{var je=xm(),De=d(je);c(je),C(Ut=>{Y(je,"title",t(Z).cwd),I(De,`📁 ${Ut??""}`)},[()=>t(Z).cwd.split("/").pop()||t(Z).cwd]),h(at,je)};w(F,at=>{t(Z).cwd&&at(he)})}var Ce=f(F,2);{var Et=at=>{var je=_m(),De=d(je);c(je),C(()=>{Y(je,"title",t(Z).model),I(De,`🤖 ${t(Z).model??""}`)}),h(at,je)};w(Ce,at=>{t(Z).model&&at(Et)})}var At=f(Ce,2),ot=d(At);c(At),c(A),M("click",ot,Lt),h(x,A)};w(sn,x=>{t(Z).sessionFile&&x(On)})}var pe=f(sn,2);{var Le=x=>{var A=wm(),F=d(A,!0);c(A),C(()=>I(F,t(ie).error)),h(x,A)};w(pe,x=>{t(ie).error&&!t(_e)&&x(Le)})}c(U);var Pt=f(U,2),Nt=d(Pt);{var Tt=x=>{var A=km(),F=Ot(A),he=f(F,2);M("click",F,()=>ae(!1)),M("click",he,()=>{p(Ee,"readonly"),Zi()}),h(x,A)},R=x=>{var A=Sm(),F=f(d(A),2),he=d(F);c(F),c(A),C(()=>I(he,`Back to ${t(gt)?"read-only sessions":"sessions"}`)),M("click",A,()=>p(Ee,t(gt)?"readonly":"main",!0)),h(x,A)},B=x=>{var A=Tm(),F=Ot(A),he=f(F,2);M("click",F,()=>p(Ee,"main")),M("click",he,()=>ae(!0)),h(x,A)};w(Nt,x=>{t(Ee)==="main"?x(Tt):t(Ee)==="search"?x(R,1):x(B,-1)})}c(Pt);var de=f(Pt,2),He=d(de);{var Te=x=>{Pg(x,{get readOnly(){return t(gt)},get initialQuery(){return t(We)},onOpened:()=>p(Q,!1)})},E=x=>{zi(x,{readOnly:!0,onSearchAll:A=>ae(!0,A)})},l=x=>{zi(x,{onSearchAll:A=>ae(!1,A)})};w(He,x=>{t(Ee)==="search"?x(Te):t(Ee)==="readonly"?x(E,1):x(l,-1)})}c(de),C(()=>{fn(re,1,`h-2.5 w-2.5 rounded-full ${t(_e)?"bg-emerald-500":"bg-rose-500"}`),fn(be,1,`text-sm ${t(_e)?"text-emerald-400":"text-rose-400"}`),I(V,t(_e)?"Connected":"Disconnected"),Y(me,"title",t(ie).serverVersion?`App build ${Fs} · server ${t(ie).serverVersion}${t(ie).piVersion?` · pi ${t(ie).piVersion}`:""}`:`App build ${Fs}`),I(Me,`v${Fs}`)}),h(L,T)};w(_n,L=>{t(qe)?L(An):L(kn,-1)})}c(jt);var Bn=f(jt,2),dn=d(Bn),bn=d(dn),$n=f(bn,2);{var Zt=L=>{var T=Cm();M("click",T,Dt),h(L,T)};w($n,L=>{t(_e)&&t(ue)&&t(Z).sessionFile&&L(Zt)})}var H=f($n,2);{var J=L=>{var T=Mm(),U=d(T);{var ne=V=>{var me=Rm();h(V,me)},re=V=>{var me=Em();h(V,me)},be=V=>{var me=Im();h(V,me)};w(U,V=>{t(_e)&&t(Ve)?V(ne):t(_e)?V(re,1):V(be,-1)})}c(T),h(L,T)};w(H,L=>{(!t(_e)||!t(Z).sessionFile)&&L(J)})}var ke=f(H,2);{var Oe=L=>{var T=Nm(),U=d(T);{var ne=V=>{var me=$m(),Me=f(d(me),2),Se=d(Me,!0);c(Me),c(me),C(yt=>{Y(Me,"title",t(Z).cwd),I(Se,yt)},[()=>t(Z).cwd.split("/").pop()||t(Z).cwd]),h(V,me)};w(U,V=>{t(Z).cwd&&V(ne)})}var re=f(U,2);{var be=V=>{var me=Pm(),Me=d(me),Se=f(d(Me),2);c(Me);var yt=f(Me,2);{var sn=pe=>{var Le=Lm();In(Le,21,()=>t(ce),pr,(Nt,Tt)=>{var R=Om(),B=d(R,!0);c(R);var de={};C(()=>{I(B,t(Tt).label),de!==(de=`${t(Tt).provider}:${t(Tt).modelId}`)&&(R.value=R.__value=`${t(Tt).provider}:${t(Tt).modelId}`)}),h(Nt,R)}),c(Le);var Pt;el(Le),C(()=>{Pt!==(Pt=t(Z).model)&&(Le.value=(Le.__value=t(Z).model)??"",ia(Le,t(Z).model))}),M("input",Le,Nt=>Wl(Nt.currentTarget.value)),h(pe,Le)},On=pe=>{var Le=Dm(),Pt=d(Le,!0);c(Le),C(()=>{Y(Le,"title",t(Z).model),I(Pt,t(Z).model)}),h(pe,Le)};w(yt,pe=>{t(ce).length>0&&!t(q)?pe(sn):pe(On,-1)})}c(me),C(()=>{fn(Se,1,`absolute -right-0.5 -bottom-0.5 h-2 w-2 rounded-full border border-brand-surface ${t(ie).isStreaming?"animate-pulse bg-orange-500":"bg-emerald-500"}`),Y(Se,"title",t(ie).isStreaming?"Agent working...":"Ready")}),h(V,me)};w(re,V=>{t(Z).model&&V(be)})}c(T),h(L,T)};w(ke,L=>{t(Z).sessionFile&&L(Oe)})}var ut=f(ke,2);{var k=L=>{var T=Um();h(L,T)};w(ut,L=>{t(q)&&L(k)})}c(dn);var j=f(dn,2);{var ve=L=>{var T=Fm();h(L,T)};w(j,L=>{t(ct)&&L(ve)})}var we=f(j,2);{var et=L=>{var T=Bm(),U=d(T),ne=d(U,!0);c(U);var re=f(U,2);c(T),C(()=>{fn(T,1,`flex items-start justify-between gap-2 border px-4 py-2 text-sm ${t(It).level==="warning"?"border-yellow-500/30 bg-yellow-500/10 text-yellow-400":"border-blue-500/30 bg-blue-500/10 text-blue-400"}`),I(ne,t(It).message)}),M("click",re,()=>Hl()),h(L,T)};w(we,L=>{t(It)&&L(et)})}var Ie=f(we,2);{var ge=L=>{var T=Hm(),U=d(T),ne=f(d(U));{var re=Me=>{var Se=Kn("You are both working in it — changes may conflict.");h(Me,Se)},be=Me=>{var Se=Kn("You are observing (read-only) to avoid clashing.");h(Me,Se)};w(ne,Me=>{t(Je).continued?Me(re):Me(be,-1)})}c(U);var V=f(U,2);{var me=Me=>{var Se=zm();M("click",Se,()=>Fl()),h(Me,Se)};w(V,Me=>{t(Je).continued||Me(me)})}c(T),h(L,T)};w(Ie,L=>{t(Je)?.active&&L(ge)})}var Re=f(Ie,2);{var Rt=L=>{var T=jm(),U=d(T),ne=d(U,!0);c(U);var re=f(U,2);c(T),C(()=>I(ne,t(Ht))),M("click",re,()=>Dr()),h(L,T)};w(Re,L=>{t(Ht)&&L(Rt)})}var nn=f(Re,2);{var rn=L=>{var T=Gm();h(L,T)};w(nn,L=>{t(q)&&!t(ct)&&!t(ee)&&!(t(Je)?.active&&!t(Je).continued)&&L(rn)})}var Kt=f(nn,2);ir(Mb(Kt,{onMessageSent:()=>{}}),L=>pt=L,()=>pt);var mn=f(Kt,2);{var st=L=>{lm(L,{})},Mt=L=>{var T=Wm();h(L,T)},Cn=L=>{var T=Vm(),U=Ot(T);{var ne=V=>{var me=qm();h(V,me)},re=V=>{var me=Km();h(V,me)};w(U,V=>{t(Z).sessionFile&&(t(nt)||!t(_e))?V(ne):t(Z).sessionFile&&t(rt)&&V(re,1)})}var be=f(U,2);{let V=D(()=>!!t(ue)),me=D(()=>t(Ve)?!t(_e):t(q)||!t(Z).sessionFile),Me=D(()=>!t(Ve)&&(!t(_e)||t(nt)||t(rt)));ir(Rv(be,{get searchMode(){return t(Ve)},get searchConfigured(){return t(V)},get searchModels(){return t(se)},onSubmit:(Se,yt)=>Nl(Se,t(dt),yt),placeholder:"Search the web...",submitLabel:"Search",get disabled(){return t(me)},get sendDisabled(){return t(Me)},onSend:()=>pt?.forceScrollToBottom(),get searchModel(){return t(dt)},set searchModel(Se){p(dt,Se,!0)}}),Se=>p(Be,Se,!0),()=>t(Be))}h(L,T)};w(mn,L=>{t(ee)?L(st):t(q)&&t(Z).sessionFile?L(Mt,1):L(Cn,-1)})}c(Bn);var Ne=f(Bn,2);Ug(Ne,{});var St=f(Ne,2);{var Jt=L=>{var T=Ym();M("click",T,()=>p(Q,!1)),h(L,T)};w(St,L=>{t(Q)&&L(Jt)})}c(cn),C(()=>fn(jt,1,`app-chrome ${t(Q)?"translate-x-0":"-translate-x-full"} fixed z-20 flex h-full w-72 flex-col border-r border-brand-border bg-brand-surface transition-transform duration-200 md:relative md:translate-x-0`)),M("click",bn,()=>p(Q,!t(Q))),h(n,qt),br(),fe()}Mr(["click","input"]);export{ox as component,sx as universal};
120
- //# sourceMappingURL=2.B6sChdvF.js.map
120
+ //# sourceMappingURL=2.B4mmUgEN.js.map