wherever-dev 0.21.0 → 0.21.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 (37) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/attach-file-tool.d.ts +20 -1
  3. package/dist/attach-file-tool.d.ts.map +1 -1
  4. package/dist/attach-file-tool.js +45 -3
  5. package/dist/attach-file-tool.js.map +1 -1
  6. package/dist/download-grants.d.ts +12 -0
  7. package/dist/download-grants.d.ts.map +1 -0
  8. package/dist/download-grants.js +76 -0
  9. package/dist/download-grants.js.map +1 -0
  10. package/dist/index.js +35 -13
  11. package/dist/index.js.map +1 -1
  12. package/dist/session-pool.d.ts +11 -0
  13. package/dist/session-pool.d.ts.map +1 -1
  14. package/dist/session-pool.js +19 -1
  15. package/dist/session-pool.js.map +1 -1
  16. package/package.json +1 -1
  17. package/public/_app/immutable/chunks/{idnZrCTB.js → BQ9B_G4h.js} +2 -2
  18. package/public/_app/immutable/chunks/{idnZrCTB.js.map → BQ9B_G4h.js.map} +1 -1
  19. package/public/_app/immutable/chunks/{DJMI34rR.js → BUONgvl4.js} +2 -2
  20. package/public/_app/immutable/chunks/{DJMI34rR.js.map → BUONgvl4.js.map} +1 -1
  21. package/public/_app/immutable/chunks/{CkzyFwPn.js → DauELski.js} +2 -2
  22. package/public/_app/immutable/chunks/{CkzyFwPn.js.map → DauELski.js.map} +1 -1
  23. package/public/_app/immutable/entry/{app.CF_gzWKW.js → app.BZO7Xckk.js} +3 -3
  24. package/public/_app/immutable/entry/{app.CF_gzWKW.js.map → app.BZO7Xckk.js.map} +1 -1
  25. package/public/_app/immutable/entry/start.DWD60uNu.js +2 -0
  26. package/public/_app/immutable/entry/start.DWD60uNu.js.map +1 -0
  27. package/public/_app/immutable/nodes/{0.CIIhZFWl.js → 0.Czz2XmZU.js} +2 -2
  28. package/public/_app/immutable/nodes/{0.CIIhZFWl.js.map → 0.Czz2XmZU.js.map} +1 -1
  29. package/public/_app/immutable/nodes/{1.D4WVeMej.js → 1.DDvrriUW.js} +2 -2
  30. package/public/_app/immutable/nodes/{1.D4WVeMej.js.map → 1.DDvrriUW.js.map} +1 -1
  31. package/public/_app/immutable/nodes/{2._KcrsFWH.js → 2.C7E8EMKX.js} +2 -2
  32. package/public/_app/immutable/nodes/{2._KcrsFWH.js.map → 2.C7E8EMKX.js.map} +1 -1
  33. package/public/_app/version.json +1 -1
  34. package/public/index.html +10 -10
  35. package/public/service-worker.js +1 -1
  36. package/public/_app/immutable/entry/start.GpPJ13Gr.js +0 -2
  37. package/public/_app/immutable/entry/start.GpPJ13Gr.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 E,am as za,w as Hc,G as go,aL as jc,an as Lo,b as Gi,aj as Do,ap as Gc,k as Wc,V as Kc,q as qc,p as Vc,W as Yc,J as Xc,K as Zc,H as Jc,aV as Ha,C as ja,v as Ga,aw as Qs,X as Lr,a7 as Qc,as as ed,aS as td,ar as Wi,b4 as Ki,b7 as nd,b9 as Ar,aN as na,aJ as Wa,aI as hr,aF as br,aa as Dt,a_ as f,af as t,Z as rd,y as h,Q as dr,ac as b,ba as P,$ as sd,be as vr,a3 as vn,ae as Nn,a0 as Mr,aD as ys,aT as p,M as d,aO as c,aA as pt,a1 as M,b1 as N,aH as Vn,bb as Ut,bc as od,aW as I,a9 as wr,b6 as qn,ad as eo,aC as ad,aM as id,aB as Ka}from"../chunks/CAL8yDNt.js";import{i as k,s as Ur,a as we,p as ur}from"../chunks/Cjaz9aih.js";import{u as ld,F as Y,C as hs,E as cd,m as bs,a as dd,n as ws,o as ks,I as ud,z as qi,x as fd,t as Tt,d as Ks,f as Vi,G as ra,e as sa,p as oa,h as Ln,q as pr,g as pd,j as hd,i as Yi,H as Xi,k as Zi,s as Ji,B as Qi,D as el,w as bd,l as vd,y as gd,b as md}from"../chunks/CkzyFwPn.js";import{_ as xd,b as ir}from"../chunks/BORm3wtc.js";import{v as Fs}from"../chunks/idnZrCTB.js";import{p as _d}from"../chunks/DJMI34rR.js";function qa(n,e,r=!1,s=!1,o=!1,a=!1){var i=n,u="";if(r){var m=n;er&&(i=Ws(Zr(m)))}E(()=>{var v=Hc;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&&(jc(v.nodes.start,v.nodes.end),v.nodes=null),u!==""){if(er){Lo.data;for(var g=za(),x=g;g!==null&&(g.nodeType!==Gi||g.data!=="");)x=g,g=Do(g);if(g===null)throw Gc(),Wc;go(Lo,x),i=Ws(g);return}var _=s?qc:o?Vc:void 0,$=Kc(s?"svg":o?"math":"template",_);$.innerHTML=u;var L=s||o?$:$.content;if(go(Zr(L),L.lastChild),s||o)for(;Zr(L);)i.before(Zr(L));else i.before(L)}})}function yd(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(Yc()));try{Xc(()=>{var u=Zc(()=>e(o));u.f|=Jc})}finally{s&&(Ha(!0),Ws(r))}}function tl(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=tl(n[e]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function wd(){for(var n,e,r=0,s="",o=arguments.length;r<o;r++)(n=arguments[r])&&(e=tl(n))&&(s&&(s+=" "),s+=e);return s}function nl(n){return typeof n=="object"?wd(n):n??""}function kd(n,e,r){var s=n==null?"":""+n;return s===""?null:s}function Sd(n,e){return n==null?null:String(n)}function an(n,e,r,s,o,a){var i=n[ja];if(er||i!==r||i===void 0){var u=kd(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=Sd(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(!ed(e))return td();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 rl(n){var e=new MutationObserver(()=>{ia(n,n.__value)});e.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),Ki(()=>{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)}),Qc(()=>{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}),rl(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 nd(),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)}),Ki(()=>{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(x=>x.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 Td=!1,Ad=!0,lx=Object.freeze(Object.defineProperty({__proto__:null,prerender:Ad,ssr:Td},Symbol.toStringTag,{value:"Module"})),yo="Wherever",Cd="Create & maintain apps from wherever with a beautiful remote workspace.",wo="https://localhost",Ed="#000000",Rd="black-translucent";function Qr(n,e){return ld(n)}var Id=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 Md(n,e){hr(e,!0);const r=wo.endsWith("/")?wo.slice(0,-1):wo,s=r+"/preview.png";let o=P(()=>e.home||!1),a=P(()=>({type:e.type||"website",title:e.title||yo,description:e.description||Cd,image:e.image||s,url:`${r}${_d.url.pathname}`}));yd("13n5pl5",i=>{var u=Id(),m=Dt(u),v=f(m,2),g=f(v,2);{var x=_t=>{var Be=dr(),nt=Dt(Be);k(nt,yt=>{}),h(_t,Be)};k(g,_t=>{t(o)&&_t(x)})}var _=f(g,2),$=f(_,2),L=f($,2),B=f(L,2),W=f(B,2),Ne=f(W,4),re=f(Ne,2),Ke=f(re,2),ve=f(Ke,2),ce=f(ve,2),K=f(ce,2),je=f(K,2),Qe=f(je,2),Ue=f(Qe,2),oe=f(Ue,4),et=f(oe,4),dt=f(et,2),ht=f(dt,2);E((_t,Be,nt,yt)=>{Y(m,"content",t(a).title),Y(v,"content",t(a).description),Y(_,"content",t(a).type),Y($,"content",t(a).url),Y(L,"content",t(a).title),Y(B,"content",t(a).description),Y(W,"content",t(a).image),Y(Ne,"content",t(a).url),Y(re,"content",t(a).title),Y(Ke,"content",t(a).description),Y(ve,"content",t(a).image),Y(ce,"href",_t),Y(K,"href",Be),Y(je,"href",nt),Y(Qe,"href",yt),Y(Ue,"content",Ed),Y(oe,"content",yo),Y(et,"content",Rd),Y(dt,"content",yo),Y(ht,"content",Fs)},[()=>Qr("/pwa/favicon.png"),()=>Qr("/pwa/favicon.ico"),()=>Qr("/pwa/apple-touch-icon.png"),()=>Qr("/pwa/manifest.webmanifest")]),rd(()=>{sd.title=t(a).title??""}),h(i,u)}),br()}let ss=null;function $d(){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 Od(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 sl(n){if(n&&n.trim()&&Od(n.trim()))return;const e=$d();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 Ld(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Dd(n,...e){if(n==null)return Bs;const r=n.subscribe(...e);return r.unsubscribe?()=>r.unsubscribe():r}function Nt(n){let e;return Dd(n,r=>e=r)(),e}var Vr=[];function Za(n,e=Bs){let r;const s=new Set;function o(u){if(Ld(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 Pd="upload.v1",to=1024,Qa=64*to,Nd=1024*to,Ud=256*to,Fd=2,ei=.3,ti=3*256*to,ol="The file is no longer readable, pick it again";function Bd(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 al(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 zd(){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(al(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(ol);return e.code="not_readable",e}return new ts(`Failed to read the file: ${n&&n.message||n}`)}function ni(){const n=new ts(ol);return n.code="not_readable",n}function il(n){return n.startsWith("http")?n.replace(/^https?:\/\//,""):n}function Hd(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 qs(n){return`${il(n.host)}:${n.port}#${Hd(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 En{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;static MIN_RECONNECT_DELAY=2e3;reconnectDelay=En.MIN_RECONNECT_DELAY;socketStartedAt=0;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;static VISIBLE_PROBE_GRACE_MS=2e3;static STALLED_HANDSHAKE_MS=8e3;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=qs(this.config),o=Nt(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(B=>r?{...B,connecting:!0,error:null}:{...So,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const a=this.config.secure?"wss":"ws",i=il(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(B=>({...B,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}this.socketCapabilities=null,this.socketStartedAt=Date.now();try{const B=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=B?new v(m,B):new v(m)}catch(B){this.stateStore.update(W=>({...W,connecting:!1,error:`Failed to connect: ${B}`})),this.scheduleReconnect();return}const g=this.ws,x=()=>{if(this.ws!==g)return;this.isInitialConnect||console.info("[wherever] reconnected to relay"),this.hasEverConnected=!0,this.reconnectAttempts=0,this.reconnectDelay=En.MIN_RECONNECT_DELAY,this.isInitialConnect=!1,this.startLivenessWatchdog(),this.stateStore.update(Ke=>({...Ke,connected:!0,connecting:!1,error:null}));const B=Nt(this.stateStore),W=this.resumeSessionFile??B.activeSessionFile,Ne=this.resumeSessionFile!=null?this.resumeCwd:B.activeCwd??void 0,re=this.resumeSessionFile!=null?this.resumeModel:B.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(Ke=>Ke.resyncing&&!Ke.historyAuthoritative?Ke:{...Ke,resyncing:!0,historyAuthoritative:!1}),this.pendingLoadFile=W,this.send({type:"session_load",sessionFile:W,cwd:Ne,model:re}),this.armLoadWatchdog()):this.stateStore.update(Ke=>Ke.resyncing?{...Ke,resyncing:!1}:Ke)},_=B=>{if(this.ws===g){this.lastInboundAt=Date.now(),this.cancelLivenessProbe();try{const W=typeof B.data=="string"?B.data:B.data.toString(),Ne=JSON.parse(W);this.handleMessage(Ne)}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(B=>({...B,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:B.activeSessionFile?!0:B.resyncing})),this.scheduleReconnect())},L=B=>{this.ws===g&&this.stateStore.update(W=>({...W,error:W.error||"Connection error occurred"}))};typeof g.addEventListener=="function"?(g.addEventListener("open",x),g.addEventListener("message",_),g.addEventListener("close",$),g.addEventListener("error",L)):typeof g.on=="function"&&(g.on("open",x),g.on("message",B=>_({data:B})),g.on("close",$),g.on("error",L))}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=Nt(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=Nt(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||Nt(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,En.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*En.HEARTBEAT_MS){this.startLivenessProbe("clock jump");return}const a=s-this.lastInboundAt,i=Nt(this.stateStore).isStreaming,u=i?En.TURN_STALL_MS:En.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,En.HEARTBEAT_MS),this.livenessTimer&&typeof this.livenessTimer.unref=="function"&&this.livenessTimer.unref())}noteVisible(){this.reconnectDelay=En.MIN_RECONNECT_DELAY;const e=this.ws;if(e){if(e.readyState===0){Date.now()-this.socketStartedAt>En.STALLED_HANDSHAKE_MS&&(console.info("[wherever] handshake stalled; restarting it"),this.reconnectNow());return}e.readyState!==1||!this.livenessTimer||(this.lastInboundAt=Date.now(),this.lastLivenessTickAt=this.lastInboundAt,this.cancelLivenessProbe(),this.startLivenessProbe("page became visible",!0))}}startLivenessProbe(e,r=!1){const s=r?En.VISIBLE_PROBE_GRACE_MS:En.PROBE_GRACE_MS;if(this.probeTimer||!this.ws||typeof setTimeout!="function")return;const o=this.ws;try{this.ping()}catch{}const a=Date.now();this.probeTimer=setTimeout(()=>{if(this.probeTimer=null,this.ws===o){if(Date.now()-a>2*s){this.startLivenessProbe(e);return}this.tearDownStaleSocket(e,s,r)}},s),this.probeTimer&&typeof this.probeTimer.unref=="function"&&this.probeTimer.unref()}cancelLivenessProbe(){this.probeTimer&&(clearTimeout(this.probeTimer),this.probeTimer=null)}tearDownStaleSocket(e,r,s){if(!this.ws)return;const o=Nt(this.stateStore).isStreaming;console.warn(`[wherever] relay connection stale: ${e}; probe unanswered for ${r}ms; tearing down dead socket and reconnecting`),this.stopLivenessWatchdog();const a=this.ws;this.ws=null,this.uploadsLostSocket();try{typeof a.terminate=="function"?a.terminate():typeof a.close=="function"&&a.close()}catch{}this.stateStore.update(i=>({...i,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:o?"Connection to relay stalled mid-turn; reconnecting...":i.sessionError,isStreaming:!1})),s?this.reconnectNow():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=Nt(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."})))},En.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,Nt(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."})))},En.CREATE_WATCHDOG_MS)}clearCreateWatchdog(){this.createWatchdog&&(clearTimeout(this.createWatchdog),this.createWatchdog=null)}scheduleReconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*1.5,this.maxReconnectDelay),this.reconnectNow()},this.reconnectDelay))}reconnectNow(){if(this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),console.info(`[wherever] reconnecting to relay (attempt ${++this.reconnectAttempts})`),!this.hasEverConnected&&this.reconnectAttempts>=En.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=!!Nt(this.stateStore).activeSessionFile;this.stateStore.update(r=>({...r,connecting:!0,error:"Reconnecting..."})),this.connect(void 0,e)}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=Nt(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 Nt(this.stateStore);const x=o.find(_=>_.role==="user"&&_.restoredFromQueue&&_.content===e.content);if(x)return{...s,messages:o.map(_=>_.id===x.id?{..._,restoredFromQueue:void 0}:_)}}const u=e.role==="user"?$s(e.content):null;if(u){const g=[...o].reverse().find(x=>x.role==="user"&&$s(x.content)===u);if(g)return g.content!==e.content&&(o=o.map(x=>x.id===g.id?{...x,content:e.content}:x)),{...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 E,am as za,w as Hc,G as go,aL as jc,an as Lo,b as Gi,aj as Do,ap as Gc,k as Wc,V as Kc,q as qc,p as Vc,W as Yc,J as Xc,K as Zc,H as Jc,aV as Ha,C as ja,v as Ga,aw as Qs,X as Lr,a7 as Qc,as as ed,aS as td,ar as Wi,b4 as Ki,b7 as nd,b9 as Ar,aN as na,aJ as Wa,aI as hr,aF as br,aa as Dt,a_ as f,af as t,Z as rd,y as h,Q as dr,ac as b,ba as P,$ as sd,be as vr,a3 as vn,ae as Nn,a0 as Mr,aD as ys,aT as p,M as d,aO as c,aA as pt,a1 as M,b1 as N,aH as Vn,bb as Ut,bc as od,aW as I,a9 as wr,b6 as qn,ad as eo,aC as ad,aM as id,aB as Ka}from"../chunks/CAL8yDNt.js";import{i as k,s as Ur,a as we,p as ur}from"../chunks/Cjaz9aih.js";import{u as ld,F as Y,C as hs,E as cd,m as bs,a as dd,n as ws,o as ks,I as ud,z as qi,x as fd,t as Tt,d as Ks,f as Vi,G as ra,e as sa,p as oa,h as Ln,q as pr,g as pd,j as hd,i as Yi,H as Xi,k as Zi,s as Ji,B as Qi,D as el,w as bd,l as vd,y as gd,b as md}from"../chunks/DauELski.js";import{_ as xd,b as ir}from"../chunks/BORm3wtc.js";import{v as Fs}from"../chunks/BQ9B_G4h.js";import{p as _d}from"../chunks/BUONgvl4.js";function qa(n,e,r=!1,s=!1,o=!1,a=!1){var i=n,u="";if(r){var m=n;er&&(i=Ws(Zr(m)))}E(()=>{var v=Hc;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&&(jc(v.nodes.start,v.nodes.end),v.nodes=null),u!==""){if(er){Lo.data;for(var g=za(),x=g;g!==null&&(g.nodeType!==Gi||g.data!=="");)x=g,g=Do(g);if(g===null)throw Gc(),Wc;go(Lo,x),i=Ws(g);return}var _=s?qc:o?Vc:void 0,$=Kc(s?"svg":o?"math":"template",_);$.innerHTML=u;var L=s||o?$:$.content;if(go(Zr(L),L.lastChild),s||o)for(;Zr(L);)i.before(Zr(L));else i.before(L)}})}function yd(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(Yc()));try{Xc(()=>{var u=Zc(()=>e(o));u.f|=Jc})}finally{s&&(Ha(!0),Ws(r))}}function tl(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=tl(n[e]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function wd(){for(var n,e,r=0,s="",o=arguments.length;r<o;r++)(n=arguments[r])&&(e=tl(n))&&(s&&(s+=" "),s+=e);return s}function nl(n){return typeof n=="object"?wd(n):n??""}function kd(n,e,r){var s=n==null?"":""+n;return s===""?null:s}function Sd(n,e){return n==null?null:String(n)}function an(n,e,r,s,o,a){var i=n[ja];if(er||i!==r||i===void 0){var u=kd(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=Sd(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(!ed(e))return td();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 rl(n){var e=new MutationObserver(()=>{ia(n,n.__value)});e.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),Ki(()=>{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)}),Qc(()=>{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}),rl(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 nd(),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)}),Ki(()=>{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(x=>x.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 Td=!1,Ad=!0,lx=Object.freeze(Object.defineProperty({__proto__:null,prerender:Ad,ssr:Td},Symbol.toStringTag,{value:"Module"})),yo="Wherever",Cd="Create & maintain apps from wherever with a beautiful remote workspace.",wo="https://localhost",Ed="#000000",Rd="black-translucent";function Qr(n,e){return ld(n)}var Id=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 Md(n,e){hr(e,!0);const r=wo.endsWith("/")?wo.slice(0,-1):wo,s=r+"/preview.png";let o=P(()=>e.home||!1),a=P(()=>({type:e.type||"website",title:e.title||yo,description:e.description||Cd,image:e.image||s,url:`${r}${_d.url.pathname}`}));yd("13n5pl5",i=>{var u=Id(),m=Dt(u),v=f(m,2),g=f(v,2);{var x=_t=>{var Be=dr(),nt=Dt(Be);k(nt,yt=>{}),h(_t,Be)};k(g,_t=>{t(o)&&_t(x)})}var _=f(g,2),$=f(_,2),L=f($,2),B=f(L,2),W=f(B,2),Ne=f(W,4),re=f(Ne,2),Ke=f(re,2),ve=f(Ke,2),ce=f(ve,2),K=f(ce,2),je=f(K,2),Qe=f(je,2),Ue=f(Qe,2),oe=f(Ue,4),et=f(oe,4),dt=f(et,2),ht=f(dt,2);E((_t,Be,nt,yt)=>{Y(m,"content",t(a).title),Y(v,"content",t(a).description),Y(_,"content",t(a).type),Y($,"content",t(a).url),Y(L,"content",t(a).title),Y(B,"content",t(a).description),Y(W,"content",t(a).image),Y(Ne,"content",t(a).url),Y(re,"content",t(a).title),Y(Ke,"content",t(a).description),Y(ve,"content",t(a).image),Y(ce,"href",_t),Y(K,"href",Be),Y(je,"href",nt),Y(Qe,"href",yt),Y(Ue,"content",Ed),Y(oe,"content",yo),Y(et,"content",Rd),Y(dt,"content",yo),Y(ht,"content",Fs)},[()=>Qr("/pwa/favicon.png"),()=>Qr("/pwa/favicon.ico"),()=>Qr("/pwa/apple-touch-icon.png"),()=>Qr("/pwa/manifest.webmanifest")]),rd(()=>{sd.title=t(a).title??""}),h(i,u)}),br()}let ss=null;function $d(){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 Od(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 sl(n){if(n&&n.trim()&&Od(n.trim()))return;const e=$d();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 Ld(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Dd(n,...e){if(n==null)return Bs;const r=n.subscribe(...e);return r.unsubscribe?()=>r.unsubscribe():r}function Nt(n){let e;return Dd(n,r=>e=r)(),e}var Vr=[];function Za(n,e=Bs){let r;const s=new Set;function o(u){if(Ld(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 Pd="upload.v1",to=1024,Qa=64*to,Nd=1024*to,Ud=256*to,Fd=2,ei=.3,ti=3*256*to,ol="The file is no longer readable, pick it again";function Bd(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 al(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 zd(){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(al(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(ol);return e.code="not_readable",e}return new ts(`Failed to read the file: ${n&&n.message||n}`)}function ni(){const n=new ts(ol);return n.code="not_readable",n}function il(n){return n.startsWith("http")?n.replace(/^https?:\/\//,""):n}function Hd(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 qs(n){return`${il(n.host)}:${n.port}#${Hd(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 En{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;static MIN_RECONNECT_DELAY=2e3;reconnectDelay=En.MIN_RECONNECT_DELAY;socketStartedAt=0;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;static VISIBLE_PROBE_GRACE_MS=2e3;static STALLED_HANDSHAKE_MS=8e3;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=qs(this.config),o=Nt(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(B=>r?{...B,connecting:!0,error:null}:{...So,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const a=this.config.secure?"wss":"ws",i=il(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(B=>({...B,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}this.socketCapabilities=null,this.socketStartedAt=Date.now();try{const B=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=B?new v(m,B):new v(m)}catch(B){this.stateStore.update(W=>({...W,connecting:!1,error:`Failed to connect: ${B}`})),this.scheduleReconnect();return}const g=this.ws,x=()=>{if(this.ws!==g)return;this.isInitialConnect||console.info("[wherever] reconnected to relay"),this.hasEverConnected=!0,this.reconnectAttempts=0,this.reconnectDelay=En.MIN_RECONNECT_DELAY,this.isInitialConnect=!1,this.startLivenessWatchdog(),this.stateStore.update(Ke=>({...Ke,connected:!0,connecting:!1,error:null}));const B=Nt(this.stateStore),W=this.resumeSessionFile??B.activeSessionFile,Ne=this.resumeSessionFile!=null?this.resumeCwd:B.activeCwd??void 0,re=this.resumeSessionFile!=null?this.resumeModel:B.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(Ke=>Ke.resyncing&&!Ke.historyAuthoritative?Ke:{...Ke,resyncing:!0,historyAuthoritative:!1}),this.pendingLoadFile=W,this.send({type:"session_load",sessionFile:W,cwd:Ne,model:re}),this.armLoadWatchdog()):this.stateStore.update(Ke=>Ke.resyncing?{...Ke,resyncing:!1}:Ke)},_=B=>{if(this.ws===g){this.lastInboundAt=Date.now(),this.cancelLivenessProbe();try{const W=typeof B.data=="string"?B.data:B.data.toString(),Ne=JSON.parse(W);this.handleMessage(Ne)}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(B=>({...B,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:B.activeSessionFile?!0:B.resyncing})),this.scheduleReconnect())},L=B=>{this.ws===g&&this.stateStore.update(W=>({...W,error:W.error||"Connection error occurred"}))};typeof g.addEventListener=="function"?(g.addEventListener("open",x),g.addEventListener("message",_),g.addEventListener("close",$),g.addEventListener("error",L)):typeof g.on=="function"&&(g.on("open",x),g.on("message",B=>_({data:B})),g.on("close",$),g.on("error",L))}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=Nt(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=Nt(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||Nt(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,En.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*En.HEARTBEAT_MS){this.startLivenessProbe("clock jump");return}const a=s-this.lastInboundAt,i=Nt(this.stateStore).isStreaming,u=i?En.TURN_STALL_MS:En.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,En.HEARTBEAT_MS),this.livenessTimer&&typeof this.livenessTimer.unref=="function"&&this.livenessTimer.unref())}noteVisible(){this.reconnectDelay=En.MIN_RECONNECT_DELAY;const e=this.ws;if(e){if(e.readyState===0){Date.now()-this.socketStartedAt>En.STALLED_HANDSHAKE_MS&&(console.info("[wherever] handshake stalled; restarting it"),this.reconnectNow());return}e.readyState!==1||!this.livenessTimer||(this.lastInboundAt=Date.now(),this.lastLivenessTickAt=this.lastInboundAt,this.cancelLivenessProbe(),this.startLivenessProbe("page became visible",!0))}}startLivenessProbe(e,r=!1){const s=r?En.VISIBLE_PROBE_GRACE_MS:En.PROBE_GRACE_MS;if(this.probeTimer||!this.ws||typeof setTimeout!="function")return;const o=this.ws;try{this.ping()}catch{}const a=Date.now();this.probeTimer=setTimeout(()=>{if(this.probeTimer=null,this.ws===o){if(Date.now()-a>2*s){this.startLivenessProbe(e);return}this.tearDownStaleSocket(e,s,r)}},s),this.probeTimer&&typeof this.probeTimer.unref=="function"&&this.probeTimer.unref()}cancelLivenessProbe(){this.probeTimer&&(clearTimeout(this.probeTimer),this.probeTimer=null)}tearDownStaleSocket(e,r,s){if(!this.ws)return;const o=Nt(this.stateStore).isStreaming;console.warn(`[wherever] relay connection stale: ${e}; probe unanswered for ${r}ms; tearing down dead socket and reconnecting`),this.stopLivenessWatchdog();const a=this.ws;this.ws=null,this.uploadsLostSocket();try{typeof a.terminate=="function"?a.terminate():typeof a.close=="function"&&a.close()}catch{}this.stateStore.update(i=>({...i,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:o?"Connection to relay stalled mid-turn; reconnecting...":i.sessionError,isStreaming:!1})),s?this.reconnectNow():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=Nt(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."})))},En.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,Nt(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."})))},En.CREATE_WATCHDOG_MS)}clearCreateWatchdog(){this.createWatchdog&&(clearTimeout(this.createWatchdog),this.createWatchdog=null)}scheduleReconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*1.5,this.maxReconnectDelay),this.reconnectNow()},this.reconnectDelay))}reconnectNow(){if(this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),console.info(`[wherever] reconnecting to relay (attempt ${++this.reconnectAttempts})`),!this.hasEverConnected&&this.reconnectAttempts>=En.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=!!Nt(this.stateStore).activeSessionFile;this.stateStore.update(r=>({...r,connecting:!0,error:"Reconnecting..."})),this.connect(void 0,e)}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=Nt(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 Nt(this.stateStore);const x=o.find(_=>_.role==="user"&&_.restoredFromQueue&&_.content===e.content);if(x)return{...s,messages:o.map(_=>_.id===x.id?{..._,restoredFromQueue:void 0}:_)}}const u=e.role==="user"?$s(e.content):null;if(u){const g=[...o].reverse().find(x=>x.role==="user"&&$s(x.content)===u);if(g)return g.content!==e.content&&(o=o.map(x=>x.id===g.id?{...x,content:e.content}:x)),{...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(x=>x.id===m.id?{...x,content:`${g}${x.content}
4
4
  ${s}`,isStreaming:!1,isError:a,interrupted:o,toolOutput:s,...i?{images:i}:{},endedAt:v}:x)}}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(ne,Me)};k(It,ne=>{t(v)?.state==="cancelled"&&ne(Q)})}var H=f(It,2);{var Ye=ne=>{var Me=nm(),Xe=d(Me),bt=d(Xe,!0);c(Xe);var Ct=f(Xe,2);{var wt=Pt=>{var ln=tm(),Qt=Dt(ln),yn=d(Qt);c(Qt);var An=f(Qt,2);{var sn=en=>{var cn=em(),Sn=d(cn,!0);c(cn),E(()=>I(Sn,t(_).stderr)),h(en,cn)};k(An,en=>{t(K)&&en(sn)})}E(()=>I(yn,`${t(K)?"Hide":"Show"} git output`)),M("click",Qt,()=>p(K,!t(K))),h(Pt,ln)};k(Ct,Pt=>{t(_).stderr&&Pt(wt)})}c(Me),E(()=>I(bt,t(_).message)),h(ne,Me)};k(H,ne=>{t(_)&&ne(Ye)})}var fe=f(H,2);{var U=ne=>{var Me=rm(),Xe=d(Me,!0);c(Me),E(()=>I(Xe,t($).message)),h(ne,Me)};k(fe,ne=>{t($)&&ne(U)})}var Se=f(fe,4);Tt(Se);var X=f(Se,2);{var le=ne=>{var Me=om();Ln(Me,21,()=>t(ve),Xe=>Xe.url,(Xe,bt)=>{var Ct=sm(),wt=d(Ct,!0);c(Ct),E(()=>I(wt,t(bt).url)),M("click",Ct,()=>{p(re,t(bt).url,!0),p(Ke,!0)}),h(Xe,Ct)}),c(Me),h(ne,Me)},Te=ne=>{var Me=am();h(ne,Me)};k(X,ne=>{t(ve).length>1?ne(le):!t(ce)&&t(ve).length===0&&ne(Te,1)})}var T=f(X,2),Z=d(T,!0);c(T);var q=f(T,2),Ae=d(q);{var Ie=ne=>{var Me=im();M("click",Me,()=>p(je,!0)),h(ne,Me)},rt=ne=>{var Me=lm(),Xe=f(Dt(Me),2),bt=d(Xe);Tt(bt),pt(2),c(Xe);var Ct=f(Xe,2),wt=d(Ct,!0);c(Ct),E(()=>{ra(bt,t(Qe)),Ct.disabled=t(B),I(wt,t(B)?"Creating...":"Create folder")}),M("change",bt,Pt=>p(Ue,Pt.currentTarget.checked,!0)),M("click",Ct,dt),h(ne,Me)};k(Ae,ne=>{t(je)?ne(rt,-1):ne(Ie)})}c(q),E(ne=>{Y(Se,"placeholder",t(ce)?"Looking for the repository...":"git@github.com:owner/repo.git"),T.disabled=ne,I(Z,t(B)?"Starting...":"Clone repository")},[()=>!t(re).trim()||t(B)]),M("input",Se,()=>p(Ke,!0)),M("keydown",Se,ne=>{ne.key==="Enter"&&et()}),ar(Se,()=>t(re),ne=>p(re,ne)),M("click",T,et),h(Bt,At)};k(Wt,Bt=>{t(x)?Bt(ae):t(g)?Bt(Kt,1):Bt(ot,-1)})}c(yt),E(()=>I(Rt,t(u).cwd)),h(nt,yt)};k(_t,nt=>{t(u)&&nt(Be)})}h(n,ht),br(),i()}Mr(["click","input","keydown","change"]);function fm(n){return n.loading||n.resyncing||n.hasSessionHash&&!n.loadFailed}function pm(n){return n.connected&&n.searchConfigured&&!n.hasSession&&!fm(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 hm=b('<div class="mt-2 font-mono text-xs break-all text-brand-text-muted"> </div>'),bm=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>`),vm=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>'),gm=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),mm=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>'),xm=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),_m=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>'),ym=b('<span class="text-brand-text-muted/70"> </span>'),wm=b('<div class="truncate text-xs text-brand-text-muted"> </div>'),km=b('<div class="truncate text-xs text-brand-text-muted"> </div>'),Sm=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>'),Tm=b('<div class="mt-2 text-xs text-rose-400"> </div>'),Am=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),Cm=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>'),Em=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),Rm=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),Im=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>'),Mm=b('<span class="text-sm text-brand-text-muted">Search the web below, or pick a session from the sidebar</span>'),$m=b('<span class="text-sm text-brand-text-muted">Select a session from sidebar</span>'),Om=b('<span class="text-sm text-brand-text-muted">Not connected</span>'),Lm=b('<div class="flex min-w-0 items-center gap-2"><!></div>'),Dm=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>'),Pm=b("<option> </option>"),Nm=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>'),Um=b('<span class="truncate text-brand-text-muted"> </span>'),Fm=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>'),Bm=b('<div class="flex min-w-0 flex-1 items-center gap-3"><!> <!></div>'),zm=b('<button type="button"> </button>'),Hm=b('<span class="flex-shrink-0 rounded bg-yellow-500/20 px-2 py-1 text-xs text-yellow-400">Read-only</span>'),jm=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>'),Gm=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>'),Wm=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>'),Km=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>'),qm=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>'),Vm=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>'),Ym=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>'),Xm=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>'),Zm=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>'),Jm=b("<!> <!>",1),Qm=b('<button type="button" class="fixed inset-0 z-10 bg-brand-dark/50 md:hidden" aria-label="Close sidebar"></button>'),ex=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 cx(n,e){hr(e,!0);const r=()=>we(Cs,"$isConnected",K),s=()=>we(Rs,"$isResyncing",K),o=()=>we(rc,"$isAgentPending",K),a=()=>we(Es,"$isLoadingSession",K),i=()=>we(Jl,"$isInterrupted",K),u=()=>we(lo,"$sessionError",K),m=()=>we(ec,"$sessionNotice",K),v=()=>we(Zl,"$folderConflict",K),g=()=>we(ya,"$folderMissing",K),x=()=>we(co,"$isReadOnly",K),_=()=>we(rs,"$activeSessionInfo",K),$=()=>we(gn,"$piState",K),L=()=>we(sa,"$availableModels",K),B=()=>we(Qi,"$sessionFolders",K),W=()=>we(Ji,"$readOnlySessionFolders",K),Ne=()=>we(nc,"$isCreatingSession",K),re=()=>we(wa,"$restoreState",K),Ke=()=>we(qi,"$searchFolderStore",K),ve=()=>we(gd,"$searchDefaultModelStore",K),ce=()=>we(md,"$appearanceStore",K),[K,je]=Ur();let Qe=N(!1),Ue=N("main"),oe=N(!1),et=N("");function dt(S,C=""){p(oe,S,!0),p(et,C,!0),p(Ue,"search")}let ht=N(!1),_t,Be=!0;ys(()=>{{const ee=Cl(Ae());setTimeout(()=>{vu({cached:ee,hydrate:El,connect:Re=>{Be=!1,Gr(Re)}})},200)}const S=()=>{if(q=null,t(ae)){const ee=window.location.hash?decodeURIComponent(window.location.hash.slice(1)):"";ee&&ee!==t(Te)?(q=ee,As(ee)):!ee&&t(Te)&&fr()}};window.addEventListener("hashchange",S);let C=null;const J=8e3,pe=()=>{if(document.visibilityState==="hidden"){if(Uo(),$l())return;C&&clearTimeout(C),C=setTimeout(()=>{C=null,document.visibilityState==="hidden"&&t(ae)&&Il()},J)}else{ma(),C&&(clearTimeout(C),C=null),Bo();const ee=ci({booting:Be,connected:t(ae),hasActiveSession:zo()});ee==="resume"?Fo():ee==="connect"&&Gr()}},Ge=ee=>{if(C&&(clearTimeout(C),C=null),document.visibilityState==="hidden")return;Bo();const Re=ci({booting:Be,connected:t(ae),hasActiveSession:zo()});Re==="resume"?Fo():Re==="connect"&&Gr()},Oe=()=>Uo();return document.addEventListener("visibilitychange",pe),window.addEventListener("pageshow",Ge),window.addEventListener("pagehide",Oe),()=>{window.removeEventListener("hashchange",S),document.removeEventListener("visibilitychange",pe),window.removeEventListener("pageshow",Ge),window.removeEventListener("pagehide",Oe),C&&clearTimeout(C)}});function nt(){Gr()}function yt(){fr(),_s(),ba()}function Ft(){_s(),setTimeout(()=>Gr(),100)}function Rt(){bs()}function Wt(){typeof window<"u"&&(window.location.hash=""),fr(),p(Qe,!1)}let ae=P(r),Kt=P(s),ot=P(o),Bt=P(a),At=P(i),It=P(u),Q=P(m),H=P(v),Ye=P(g),fe=P(x),U=P(_),Se=P($),X=P(()=>L().models),le=N(!1),Te=P(()=>t(U).sessionId),T=P(()=>{const S=t(U).sessionFile;if(!S)return!1;for(const C of[B(),W()])for(const J of C.folders){const pe=J.sessions.find(Ge=>Ge.path===S);if(pe)return!!pe.starred}return!1});Ut(()=>{typeof window<"u"&&t(ae)&&(t(Te)?(window.location.hash=encodeURIComponent(t(Te)),p(le,!0)):t(le)&&(p(le,!1),window.location.hash&&(window.location.hash="")))});let Z=null,q=null;function Ae(){return typeof window>"u"||!window.location.hash?"":decodeURIComponent(window.location.hash.slice(1))}Ut(()=>{if(!t(ae)){q=null;return}const S=Ae();S&&t(Te)===S&&(q=null);const C=ji({connected:t(ae),hashId:S,currentSessionId:t(Te),loading:t(Bt),resyncing:t(Kt),attemptedHashId:q});if(C==="failed"){q=null,window.location.hash&&history.replaceState(history.state,"",window.location.pathname+window.location.search);return}C==="join"&&(Z||(Z=setTimeout(()=>{Z=null;const J=Ae();ji({connected:t(ae),hashId:J,currentSessionId:t(Te),loading:t(Bt),resyncing:t(Kt),attemptedHashId:q})==="join"&&(q=J,Ul(J))},300)))}),Ut(()=>{t(ae)||p(le,!1)}),Ut(()=>{(t(Te)||t(Bt)||t(Kt))&&p(Qe,!1)});let Ie=P(Ne),rt=P(()=>re()?.forSessionCreate?re():null),ne=P(Ke),Me=N(void 0),Xe=P(()=>pm({connected:t(ae),searchConfigured:!!t(ne),hasSession:!!t(U).sessionFile,loading:t(Bt),resyncing:t(Kt),hasSessionHash:typeof window<"u"&&!!window.location.hash,loadFailed:!!t(It)&&!t(Bt)&&!t(Kt)&&!t(U).sessionFile})),bt=P(()=>t(X).map(S=>({value:`${S.provider}:${S.modelId}`,label:`${S.label}${S.isDefault?" (default)":""}`}))),Ct=P(ve),wt=P(()=>ce().label),Pt=N("");Ut(()=>{if(t(bt).length===0||t(bt).some(pe=>pe.value===t(Pt)))return;const C=t(bt).find(pe=>pe.value===t(Ct)),J=t(X).find(pe=>pe.isDefault);p(Pt,C?C.value:J?`${J.provider}:${J.modelId}`:t(bt)[0].value,!0)});let ln=N(!1);Ut(()=>{t(Xe)&&!t(ln)&&t(Me)&&(p(ln,!0),t(Me).focusInput())});function Qt(){typeof window<"u"&&window.location.hash&&(window.location.hash=""),fr(),t(Me)?.focusInput()}var yn=ex(),An=Dt(yn);{let S=P(()=>t(wt)?`Wherever · ${t(wt)}`:"Wherever");Md(An,{get title(){return t(S)},description:"Create & maintain apps from wherever"})}var sn=f(An,2);{var en=S=>{var C=bm(),J=d(C),pe=f(d(J),4);{var Ge=Re=>{var V=hm(),me=d(V,!0);c(V),E(()=>I(me,t(rt).job.url)),h(Re,V)};k(pe,Re=>{t(rt).job?.url&&Re(Ge)})}var Oe=f(pe,2);Mc(Oe,{get job(){return t(rt).job}});var ee=f(Oe,2);c(J),c(C),M("click",ee,()=>xa()),h(S,C)},cn=S=>{var C=vm();h(S,C)};k(sn,S=>{t(rt)?S(en):t(Ie)&&S(cn,1)})}var Sn=f(sn,2),Cn=d(Sn),at=d(Cn),kt=d(at),wn=d(kt);{var In=S=>{var C=gm(),J=f(Dt(C),2);M("click",J,()=>p(ht,!1)),h(S,C)},Rn=S=>{var C=xm(),J=Dt(C),pe=d(J),Ge=f(pe,4);{var Oe=me=>{var ft=mm(),mt=d(ft,!0);c(ft),E(()=>{Y(ft,"title",t(wt)),I(mt,t(wt))}),h(me,ft)};k(Ge,me=>{t(wt)&&me(Oe)})}c(J);var ee=f(J,2),Re=d(ee),V=f(Re,2);c(ee),E(me=>Y(pe,"src",me),[()=>Qr("/logo.svg")]),M("click",J,Wt),M("click",Re,()=>p(ht,!0)),M("click",V,()=>p(Qe,!1)),h(S,C)};k(wn,S=>{t(ht)?S(In):S(Rn,-1)})}c(kt),c(at);var Gn=f(at,2);{var kn=S=>{var C=_m(),J=d(C);{let V=P(()=>(t(Se).connected,"localhost"));tf(J,{get host(){return t(V)},port:31415,token:"",onConnected:nt})}var pe=f(J,2),Ge=f(d(pe),2),Oe=d(Ge),ee=f(Oe,2),Re=f(ee,2);c(Ge),c(pe),c(C),M("click",Oe,Rt),M("click",ee,Ft),M("click",Re,yt),h(S,C)},mn=S=>{var C=Rm(),J=Dt(C),pe=d(J),Ge=d(pe),Oe=f(Ge,2),ee=d(Oe,!0);c(Oe);var Re=f(Oe,2),V=d(Re),me=f(V);{var ft=ue=>{var he=ym(),be=d(he);c(he),E(()=>I(be,` / srv ${t(Se).serverVersion??""}`)),h(ue,he)};k(me,ue=>{t(Se).serverVersion&&ue(ft)})}c(Re),c(pe);var mt=f(pe,2);{var Ht=ue=>{var he=Sm(),be=d(he);{var We=hn=>{var jt=wm(),Ot=d(jt);c(jt),E(xe=>{Y(jt,"title",t(U).cwd),I(Ot,`📁 ${xe??""}`)},[()=>t(U).cwd.split("/").pop()||t(U).cwd]),h(hn,jt)};k(be,hn=>{t(U).cwd&&hn(We)})}var lt=f(be,2);{var Pe=hn=>{var jt=km(),Ot=d(jt);c(jt),E(()=>{Y(jt,"title",t(U).model),I(Ot,`🤖 ${t(U).model??""}`)}),h(hn,jt)};k(lt,hn=>{t(U).model&&hn(Pe)})}var $t=f(lt,2),fn=d($t);c($t),c(he),M("click",fn,Wt),h(ue,he)};k(mt,ue=>{t(U).sessionFile&&ue(Ht)})}var R=f(mt,2);{var D=ue=>{var he=Tm(),be=d(he,!0);c(he),E(()=>I(be,t(Se).error)),h(ue,he)};k(R,ue=>{t(Se).error&&!t(ae)&&ue(D)})}c(J);var se=f(J,2),ze=d(se);{var tt=ue=>{var he=Am(),be=Dt(he),We=f(be,2);M("click",be,()=>dt(!1)),M("click",We,()=>{p(Ue,"readonly"),Zi()}),h(ue,he)},O=ue=>{var he=Cm(),be=f(d(he),2),We=d(be);c(be),c(he),E(()=>I(We,`Back to ${t(oe)?"read-only sessions":"sessions"}`)),M("click",he,()=>p(Ue,t(oe)?"readonly":"main",!0)),h(ue,he)},l=ue=>{var he=Em(),be=Dt(he),We=f(be,2);M("click",be,()=>p(Ue,"main")),M("click",We,()=>dt(!0)),h(ue,he)};k(ze,ue=>{t(Ue)==="main"?ue(tt):t(Ue)==="search"?ue(O,1):ue(l,-1)})}c(se);var y=f(se,2),A=d(y);{var z=ue=>{Fg(ue,{get readOnly(){return t(oe)},get initialQuery(){return t(et)},onOpened:()=>p(Qe,!1)})},ke=ue=>{zi(ue,{readOnly:!0,onSearchAll:he=>dt(!0,he)})},De=ue=>{zi(ue,{onSearchAll:he=>dt(!1,he)})};k(A,ue=>{t(Ue)==="search"?ue(z):t(Ue)==="readonly"?ue(ke,1):ue(De,-1)})}c(y),E(()=>{an(Ge,1,`h-2.5 w-2.5 rounded-full ${t(ae)?"bg-emerald-500":"bg-rose-500"}`),an(Oe,1,`text-sm ${t(ae)?"text-emerald-400":"text-rose-400"}`),I(ee,t(ae)?"Connected":"Disconnected"),Y(Re,"title",t(Se).serverVersion?`App build ${Fs} · server ${t(Se).serverVersion}${t(Se).piVersion?` · pi ${t(Se).piVersion}`:""}`:`App build ${Fs}`),I(V,`v${Fs}`)}),h(S,C)};k(Gn,S=>{t(ht)?S(kn):S(mn,-1)})}c(Cn);var Mn=f(Cn,2),qt=d(Mn),Fn=d(qt),F=f(Fn,2);{var te=S=>{var C=Im();M("click",C,Qt),h(S,C)};k(F,S=>{t(ae)&&t(ne)&&t(U).sessionFile&&S(te)})}var Ce=f(F,2);{var $e=S=>{var C=Lm(),J=d(C);{var pe=ee=>{var Re=Mm();h(ee,Re)},Ge=ee=>{var Re=$m();h(ee,Re)},Oe=ee=>{var Re=Om();h(ee,Re)};k(J,ee=>{t(ae)&&t(Xe)?ee(pe):t(ae)?ee(Ge,1):ee(Oe,-1)})}c(C),h(S,C)};k(Ce,S=>{(!t(ae)||!t(U).sessionFile)&&S($e)})}var w=f(Ce,2);{var G=S=>{var C=Bm(),J=d(C);{var pe=ee=>{var Re=Dm(),V=f(d(Re),2),me=d(V,!0);c(V),c(Re),E(ft=>{Y(V,"title",t(U).cwd),I(me,ft)},[()=>t(U).cwd.split("/").pop()||t(U).cwd]),h(ee,Re)};k(J,ee=>{t(U).cwd&&ee(pe)})}var Ge=f(J,2);{var Oe=ee=>{var Re=Fm(),V=d(Re),me=f(d(V),2);c(V);var ft=f(V,2);{var mt=R=>{var D=Nm();Ln(D,21,()=>t(X),pr,(ze,tt)=>{var O=Pm(),l=d(O,!0);c(O);var y={};E(()=>{I(l,t(tt).label),y!==(y=`${t(tt).provider}:${t(tt).modelId}`)&&(O.value=O.__value=`${t(tt).provider}:${t(tt).modelId}`)}),h(ze,O)}),c(D);var se;rl(D),E(()=>{se!==(se=t(U).model)&&(D.value=(D.__value=t(U).model)??"",ia(D,t(U).model))}),M("input",D,ze=>Vl(ze.currentTarget.value)),h(R,D)},Ht=R=>{var D=Um(),se=d(D,!0);c(D),E(()=>{Y(D,"title",t(U).model),I(se,t(U).model)}),h(R,D)};k(ft,R=>{t(X).length>0&&!t(fe)?R(mt):R(Ht,-1)})}c(Re),E(()=>{an(me,1,`absolute -right-0.5 -bottom-0.5 h-2 w-2 rounded-full border border-brand-surface ${t(Se).isStreaming?"animate-pulse bg-orange-500":"bg-emerald-500"}`),Y(me,"title",t(Se).isStreaming?"Agent working...":"Ready")}),h(ee,Re)};k(Ge,ee=>{t(U).model&&ee(Oe)})}c(C),h(S,C)};k(w,S=>{t(U).sessionFile&&S(G)})}var de=f(w,2);{var Ee=S=>{var C=zm(),J=d(C,!0);c(C),E(()=>{an(C,1,`flex flex-shrink-0 items-center justify-center rounded border px-2 py-1 text-sm transition-colors ${t(T)?"border-amber-400/50 bg-amber-400/10 text-amber-400 hover:bg-amber-400/20":"border-brand-border bg-brand-surface-2 text-brand-text-muted hover:bg-brand-surface-3 hover:text-amber-400"}`),Y(C,"title",t(T)?"Starred. Click to unstar.":"Star this session to come back to it later"),Y(C,"aria-label",t(T)?"Unstar session":"Star session"),Y(C,"aria-pressed",t(T)),I(J,t(T)?"★":"☆")}),M("click",C,()=>el(t(U).sessionFile,!t(T)).catch(()=>{})),h(S,C)};k(de,S=>{t(U).sessionFile&&S(Ee)})}var qe=f(de,2);{var Le=S=>{var C=Hm();h(S,C)};k(qe,S=>{t(fe)&&S(Le)})}c(qt);var _e=f(qt,2);{var ge=S=>{var C=jm();h(S,C)};k(_e,S=>{t(At)&&S(ge)})}var Zt=f(_e,2);{var on=S=>{var C=Gm(),J=d(C),pe=d(J,!0);c(J);var Ge=f(J,2);c(C),E(()=>{an(C,1,`flex items-start justify-between gap-2 border px-4 py-2 text-sm ${t(Q).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(pe,t(Q).message)}),M("click",Ge,()=>Wl()),h(S,C)};k(Zt,S=>{t(Q)&&S(on)})}var zt=f(Zt,2);{var dn=S=>{var C=Km(),J=d(C),pe=f(d(J));{var Ge=V=>{var me=qn("You are both working in it — changes may conflict.");h(V,me)},Oe=V=>{var me=qn("You are observing (read-only) to avoid clashing.");h(V,me)};k(pe,V=>{t(H).continued?V(Ge):V(Oe,-1)})}c(J);var ee=f(J,2);{var Re=V=>{var me=Wm();M("click",me,()=>Hl()),h(V,me)};k(ee,V=>{t(H).continued||V(Re)})}c(C),h(S,C)};k(zt,S=>{t(H)?.active&&S(dn)})}var tn=f(zt,2);{var Et=S=>{var C=qm(),J=d(C),pe=d(J,!0);c(J);var Ge=f(J,2);c(C),E(()=>I(pe,t(It))),M("click",Ge,()=>Dr()),h(S,C)};k(tn,S=>{t(It)&&S(Et)})}var vt=f(tn,2);{var xn=S=>{var C=Vm();h(S,C)};k(vt,S=>{t(fe)&&!t(At)&&!t(Ye)&&!(t(H)?.active&&!t(H).continued)&&S(xn)})}var it=f(vt,2);ir(Ob(it,{onMessageSent:()=>{}}),S=>_t=S,()=>_t);var ut=f(it,2);{var Mt=S=>{um(S,{})},un=S=>{var C=Ym();h(S,C)},pn=S=>{var C=Jm(),J=Dt(C);{var pe=ee=>{var Re=Xm();h(ee,Re)},Ge=ee=>{var Re=Zm();h(ee,Re)};k(J,ee=>{t(U).sessionFile&&(t(Kt)||!t(ae))?ee(pe):t(U).sessionFile&&t(ot)&&ee(Ge,1)})}var Oe=f(J,2);{let ee=P(()=>!!t(ne)),Re=P(()=>t(Xe)?!t(ae):t(fe)||!t(U).sessionFile),V=P(()=>!t(Xe)&&(!t(ae)||t(Kt)||t(ot)));ir(Iv(Oe,{get searchMode(){return t(Xe)},get searchConfigured(){return t(ee)},get searchModels(){return t(bt)},onSubmit:(me,ft)=>Bl(me,t(Pt),ft),placeholder:"Search the web...",submitLabel:"Search",get disabled(){return t(Re)},get sendDisabled(){return t(V)},onSend:()=>_t?.forceScrollToBottom(),get searchModel(){return t(Pt)},set searchModel(me){p(Pt,me,!0)}}),me=>p(Me,me,!0),()=>t(Me))}h(S,C)};k(ut,S=>{t(Ye)?S(Mt):t(fe)&&t(U).sessionFile?S(un,1):S(pn,-1)})}c(Mn);var ye=f(Mn,2);zg(ye,{});var Fe=f(ye,2);{var gt=S=>{var C=Qm();M("click",C,()=>p(Qe,!1)),h(S,C)};k(Fe,S=>{t(Qe)&&S(gt)})}c(Sn),E(()=>an(Cn,1,`app-chrome ${t(Qe)?"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",Fn,()=>p(Qe,!t(Qe))),h(n,yn),br(),je()}Mr(["click","input"]);export{cx as component,lx as universal};
120
- //# sourceMappingURL=2._KcrsFWH.js.map
120
+ //# sourceMappingURL=2.C7E8EMKX.js.map