wherever-dev 0.18.0 → 0.18.2
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.
- package/dist/session-pool.d.ts +37 -0
- package/dist/session-pool.d.ts.map +1 -1
- package/dist/session-pool.js +105 -17
- package/dist/session-pool.js.map +1 -1
- package/package.json +1 -1
- package/public/_app/immutable/chunks/{6cDLdLMr.js → D9URj2y-.js} +2 -2
- package/public/_app/immutable/chunks/{6cDLdLMr.js.map → D9URj2y-.js.map} +1 -1
- package/public/_app/immutable/chunks/{BWLk4g7S.js → DGXiQ9ZV.js} +2 -2
- package/public/_app/immutable/chunks/{BWLk4g7S.js.map → DGXiQ9ZV.js.map} +1 -1
- package/public/_app/immutable/chunks/{C2gDSNg3.js → ayQO3yig.js} +2 -2
- package/public/_app/immutable/chunks/{C2gDSNg3.js.map → ayQO3yig.js.map} +1 -1
- package/public/_app/immutable/entry/{app.DCsaSS2h.js → app.BhOrDt22.js} +3 -3
- package/public/_app/immutable/entry/{app.DCsaSS2h.js.map → app.BhOrDt22.js.map} +1 -1
- package/public/_app/immutable/entry/start.g-UtlC0Y.js +2 -0
- package/public/_app/immutable/entry/start.g-UtlC0Y.js.map +1 -0
- package/public/_app/immutable/nodes/{0.BKhPUBoV.js → 0.CXdAzqGq.js} +2 -2
- package/public/_app/immutable/nodes/{0.BKhPUBoV.js.map → 0.CXdAzqGq.js.map} +1 -1
- package/public/_app/immutable/nodes/{1.D-6k-nc0.js → 1.B1fORJLJ.js} +2 -2
- package/public/_app/immutable/nodes/{1.D-6k-nc0.js.map → 1.B1fORJLJ.js.map} +1 -1
- package/public/_app/immutable/nodes/{2.B1UIQ9ew.js → 2.DnoKKNs8.js} +2 -2
- package/public/_app/immutable/nodes/{2.B1UIQ9ew.js.map → 2.DnoKKNs8.js.map} +1 -1
- package/public/_app/version.json +1 -1
- package/public/index.html +10 -10
- package/public/service-worker.js +1 -1
- package/public/_app/immutable/entry/start.CVu9YCQp.js +0 -2
- package/public/_app/immutable/entry/start.CVu9YCQp.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"../chunks/DsnmJJEf.js";import{ao as Vn,aU as Ps,ai as Wr,b5 as T,am as yo,w as ec,G as sa,aL as tc,an as xa,b as fi,aj as _a,ap as nc,k as rc,V as sc,q as ac,p as oc,W as ic,J as lc,K as cc,H as dc,aV as wo,C as ko,v as So,aw as Hs,X as Rr,a7 as uc,as as fc,aS as pc,ar as pi,b4 as bi,b7 as bc,b9 as yr,aN as Na,aJ as To,aI as lr,aF as cr,aa as Ft,a_ as u,af as e,Z as hc,y as b,Q as or,ac as h,ba as P,$ as vc,be as dr,a3 as pn,ae as jn,a0 as Tr,aD as bs,aT as p,M as c,aO as l,aA as pt,a1 as L,b1 as F,aH as Bn,bb as Dt,bc as gc,aW as I,a9 as gr,b6 as zn,ad as Ws,aC as mc,aM as xc,aB as Ao}from"../chunks/CAL8yDNt.js";import{i as y,s as Mr,a as Ae,p as vr}from"../chunks/Cjaz9aih.js";import{u as _c,D as te,C as is,m as ls,a as yc,n as hs,o as vs,G as wc,z as hi,x as kc,t as _t,d as Ns,f as vi,E as Fa,e as Ua,p as za,h as Cn,q as er,g as Sc,j as Tc,i as gi,F as mi,k as xi,s as Ac,B as Cc,w as Rc,l as Ec,y as Ic,b as $c}from"../chunks/C2gDSNg3.js";import{_ as Mc,b as nr}from"../chunks/BORm3wtc.js";import{v as Is}from"../chunks/BWLk4g7S.js";import{p as Lc}from"../chunks/6cDLdLMr.js";function Co(n,t,r=!1,s=!1,a=!1,o=!1){var i=n,d="";if(r){var v=n;Vn&&(i=Ps(Wr(v)))}T(()=>{var g=ec;if(d===(d=t()??"")){Vn&&yo();return}if(r&&!Vn){g.nodes=null,v.innerHTML=d,d!==""&&sa(Wr(v),v.lastChild);return}if(g.nodes!==null&&(tc(g.nodes.start,g.nodes.end),g.nodes=null),d!==""){if(Vn){xa.data;for(var m=yo(),x=m;m!==null&&(m.nodeType!==fi||m.data!=="");)x=m,m=_a(m);if(m===null)throw nc(),rc;sa(xa,x),i=Ps(m);return}var w=s?ac:a?oc:void 0,E=sc(s?"svg":a?"math":"template",w);E.innerHTML=d;var O=s||a?E:E.content;if(sa(Wr(O),O.lastChild),s||a)for(;Wr(O);)i.before(Wr(O));else i.before(O)}})}function Dc(n,t){let r=null,s=Vn;var a;if(Vn){r=xa;for(var o=Wr(document.head);o!==null&&(o.nodeType!==fi||o.data!==n);)o=_a(o);if(o===null)wo(!1);else{var i=_a(o);o.remove(),Ps(i)}}Vn||(a=document.head.appendChild(ic()));try{lc(()=>{var d=cc(()=>t(a));d.f|=dc})}finally{s&&(wo(!0),Ps(r))}}function _i(n){var t,r,s="";if(typeof n=="string"||typeof n=="number")s+=n;else if(typeof n=="object")if(Array.isArray(n)){var a=n.length;for(t=0;t<a;t++)n[t]&&(r=_i(n[t]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function Oc(){for(var n,t,r=0,s="",a=arguments.length;r<a;r++)(n=arguments[r])&&(t=_i(n))&&(s&&(s+=" "),s+=t);return s}function yi(n){return typeof n=="object"?Oc(n):n??""}function Pc(n,t,r){var s=n==null?"":""+n;return s===""?null:s}function Nc(n,t){return n==null?null:String(n)}function vn(n,t,r,s,a,o){var i=n[ko];if(Vn||i!==r||i===void 0){var d=Pc(r);(!Vn||d!==n.getAttribute("class"))&&(d==null?n.removeAttribute("class"):t?n.className=d:n.setAttribute("class",d)),n[ko]=r}return o}function wi(n,t,r,s){var a=n[So];if(Vn||a!==t){var o=Nc(t);(!Vn||o!==n.getAttribute("style"))&&(o==null?n.removeAttribute("style"):n.style.cssText=o),n[So]=t}return s}function Ba(n,t,r=!1){if(n.multiple){if(t==null)return;if(!fc(t))return pc();for(var s of n.options)s.selected=t.includes(cs(s));return}for(s of n.options){var a=cs(s);if(pi(a,t)){s.selected=!0;return}}(!r||t!==void 0)&&(n.selectedIndex=-1)}function ki(n){var t=new MutationObserver(()=>{Ba(n,n.__value)});t.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),bi(()=>{t.disconnect()})}function fs(n,t,r=t){var s=new WeakSet,a=!0;Hs(n,"change",o=>{var i=o?"[selected]":":checked",d;if(n.multiple)d=[].map.call(n.querySelectorAll(i),cs);else{var v=n.querySelector(i)??n.querySelector("option:not([disabled])");d=v&&cs(v)}r(d),n.__value=d,Rr!==null&&s.add(Rr)}),uc(()=>{var o=t();if(n===document.activeElement){var i=Rr;if(s.has(i))return}if(Ba(n,o,a),a&&o===void 0){var d=n.querySelector(":checked");d!==null&&(o=cs(d),r(o))}n.__value=o,a=!1}),ki(n)}function cs(n){return"__value"in n?n.__value:n.value}function tr(n,t,r=t){var s=new WeakSet;Hs(n,"input",async a=>{var o=a?n.defaultValue:n.value;if(o=oa(n)?ia(o):o,r(o),Rr!==null&&s.add(Rr),await bc(),o!==(o=t())){var i=n.selectionStart,d=n.selectionEnd,v=n.value.length;if(n.value=o??"",d!==null){var g=n.value.length;i===d&&d===v&&g>v?(n.selectionStart=g,n.selectionEnd=g):(n.selectionStart=i,n.selectionEnd=Math.min(d,g))}}}),(Vn&&n.defaultValue!==n.value||yr(t)==null&&n.value)&&(r(oa(n)?ia(n.value):n.value),Rr!==null&&s.add(Rr)),Na(()=>{var a=t();if(n===document.activeElement){var o=Rr;if(s.has(o))return}oa(n)&&a===ia(n.value)||n.type==="date"&&!a&&!n.value||a!==n.value&&(n.value=a??"")})}const aa=new Set;function $r(n,t,r,s,a=s){var o=r.getAttribute("type")==="checkbox",i=n;let d=!1;if(t!==null)for(var v of t)i=i[v]??=[];i.push(r),Hs(r,"change",()=>{var g=r.__value;o&&(g=Ro(i,g,r.checked)),a(g)},()=>a(o?[]:null)),Na(()=>{var g=s();if(Vn&&r.defaultChecked!==r.checked){d=!0;return}o?(g=g||[],r.checked=g.includes(r.__value)):r.checked=pi(r.__value,g)}),bi(()=>{var g=i.indexOf(r);g!==-1&&i.splice(g,1)}),aa.has(i)||(aa.add(i),To(()=>{i.sort((g,m)=>g.compareDocumentPosition(m)===4?-1:1),aa.delete(i)})),To(()=>{if(d){var g;if(o)g=Ro(i,g,r.checked);else{var m=i.find(x=>x.checked);g=m?.__value}a(g)}})}function Gn(n,t,r=t){Hs(n,"change",s=>{var a=s?n.defaultChecked:n.checked;r(a)}),(Vn&&n.defaultChecked!==n.checked||yr(t)==null)&&r(n.checked),Na(()=>{var s=t();n.checked=!!s})}function Ro(n,t,r){for(var s=new Set,a=0;a<n.length;a+=1)n[a].checked&&s.add(n[a].__value);return r||s.delete(t),Array.from(s)}function oa(n){var t=n.type;return t==="number"||t==="range"}function ia(n){return n===""?null:+n}const Fc=!1,Uc=!0,Og=Object.freeze(Object.defineProperty({__proto__:null,prerender:Uc,ssr:Fc},Symbol.toStringTag,{value:"Module"})),la="Wherever",zc="Create & maintain apps from wherever with a beautiful remote workspace.",ca="https://localhost",Bc="#000000",jc="black-translucent";function qr(n,t){return _c(n)}var Hc=h('<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 Wc(n,t){lr(t,!0);const r=ca.endsWith("/")?ca.slice(0,-1):ca,s=r+"/preview.png";let a=P(()=>t.home||!1),o=P(()=>({type:t.type||"website",title:t.title||la,description:t.description||zc,image:t.image||s,url:`${r}${Lc.url.pathname}`}));Dc("13n5pl5",i=>{var d=Hc(),v=Ft(d),g=u(v,2),m=u(g,2);{var x=Ye=>{var Mt=or(),Se=Ft(Mt);y(Se,bt=>{}),b(Ye,Mt)};y(m,Ye=>{e(a)&&Ye(x)})}var w=u(m,2),E=u(w,2),O=u(E,2),z=u(O,2),_e=u(z,2),xe=u(_e,4),fe=u(xe,2),De=u(fe,2),ee=u(De,2),Re=u(ee,2),ie=u(Re,2),Y=u(ie,2),Ke=u(Y,2),yt=u(Ke,2),ye=u(yt,4),$e=u(ye,4),Ve=u($e,2),Wt=u(Ve,2);T((Ye,Mt,Se,bt)=>{te(v,"content",e(o).title),te(g,"content",e(o).description),te(w,"content",e(o).type),te(E,"content",e(o).url),te(O,"content",e(o).title),te(z,"content",e(o).description),te(_e,"content",e(o).image),te(xe,"content",e(o).url),te(fe,"content",e(o).title),te(De,"content",e(o).description),te(ee,"content",e(o).image),te(Re,"href",Ye),te(ie,"href",Mt),te(Y,"href",Se),te(Ke,"href",bt),te(yt,"content",Bc),te(ye,"content",la),te($e,"content",jc),te(Ve,"content",la),te(Wt,"content",Is)},[()=>qr("/pwa/favicon.png"),()=>qr("/pwa/favicon.ico"),()=>qr("/pwa/apple-touch-icon.png"),()=>qr("/pwa/manifest.webmanifest")]),hc(()=>{vc.title=e(o).title??""}),b(i,d)}),cr()}let Zr=null;function Gc(){if(typeof window>"u")return null;try{if(!Zr){const n=window.AudioContext||window.webkitAudioContext;if(!n)return null;Zr=new n}return Zr.state==="suspended"&&Zr.resume().catch(()=>{}),Zr}catch{return null}}function Eo(n,t,r,s,a){const o=n.createOscillator(),i=n.createGain();o.type="sine",o.frequency.value=t;const d=.015;i.gain.setValueAtTime(1e-4,r),i.gain.exponentialRampToValueAtTime(a,r+d),i.gain.exponentialRampToValueAtTime(1e-4,r+s),o.connect(i),i.connect(n.destination),o.start(r),o.stop(r+s+.02)}const Io=new Map;function qc(n){if(typeof Audio>"u")return!1;try{let t=Io.get(n);t||(t=new Audio(n),t.preload="auto",Io.set(n,t));try{t.currentTime=0}catch{}const r=t.play();return r&&typeof r.catch=="function"&&r.catch(()=>{}),!0}catch{return!1}}function Si(n){if(n&&n.trim()&&qc(n.trim()))return;const t=Gc();if(t)try{const r=t.currentTime;Eo(t,1046.5,r,.16,.12),Eo(t,1396.9,r+.13,.22,.12)}catch{}}function ja(n){if(!n)return null;const t=n.trimStart(),r=t.match(/^<skill\s+name="([^"]*)"[^>]*>/);if(r){const s=t.indexOf("</skill>");return s===-1?null:{skillName:r[1],args:t.slice(s+8).trim()}}if(t.startsWith("/skill:")){const s=t.slice(7),a=s.indexOf(" "),o=a===-1?s:s.slice(0,a);if(!o)return null;const i=a===-1?"":s.slice(a+1).trim();return{skillName:o,args:i}}return null}function ks(n){const t=ja(n);return t?`skill:${t.skillName}\0${t.args}`:null}function $s(){}function Kc(n,t){return n!=n?t==t:n!==t||n&&typeof n=="object"||typeof n=="function"}function Vc(n,...t){if(n==null)return $s;const r=n.subscribe(...t);return r.unsubscribe?()=>r.unsubscribe():r}function Jt(n){let t;return Vc(n,r=>t=r)(),t}var jr=[];function Yc(n,t=$s){let r;const s=new Set;function a(d){if(Kc(n,d)&&(n=d,r)){const v=!jr.length;for(const g of s)g[1](),jr.push(g,n);if(v){for(let g=0;g<jr.length;g+=2)jr[g][0](jr[g+1]);jr.length=0}}}function o(d){a(d(n))}function i(d,v=$s){const g=[d,v];return s.add(g),s.size===1&&(r=t(a)||$s),d(n),()=>{s.delete(g),s.size===0&&(r(),r=null)}}return{set:a,update:o,subscribe:i}}function $o(){return`ck-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}const da={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,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,contextUsage:null,pendingSteering:[],skills:[]};class ar{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;isInitialConnect=!0;resumeSessionFile=null;resumeCwd;resumeModel;pendingLoadFile=null;listeners=new Set;pendingUploads=new Map;confirmTimers=new Map;static CONFIRM_MS=12e3;static PENDING_PREFIX="wherever-pending:";constructor(t){this.config={secure:!0,...t},this.clientKey=this.config.clientKey||$o(),this.stateStore=Yc({...da,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}connect(t,r=!1){t&&(this.config={...this.config,...t}),this.disconnect(!1),this.stateStore.update(E=>r?{...E,connecting:!0,error:null}:{...da,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const s=this.config.secure?"wss":"ws",a=this.config.host.startsWith("http")?this.config.host.replace(/^https?:\/\//,""):this.config.host,o=[];this.config.token&&o.push(`token=${encodeURIComponent(this.config.token)}`),o.push(`clientKey=${encodeURIComponent(this.clientKey)}`);const i=`${s}://${a}:${this.config.port}/ws?${o.join("&")}`,d=this.config.WebSocketCtor||(typeof globalThis<"u"?globalThis.WebSocket:null);if(!d){this.stateStore.update(E=>({...E,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}try{const E=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=E?new d(i,E):new d(i)}catch(E){this.stateStore.update(O=>({...O,connecting:!1,error:`Failed to connect: ${E}`})),this.scheduleReconnect();return}const v=this.ws,g=()=>{if(this.ws!==v)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(xe=>({...xe,connected:!0,connecting:!1,error:null}));const E=Jt(this.stateStore),O=this.resumeSessionFile??E.activeSessionFile,z=this.resumeSessionFile!=null?this.resumeCwd:E.activeCwd??void 0,_e=this.resumeSessionFile!=null?this.resumeModel:E.activeModel??void 0;this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,O?(this.stateStore.update(xe=>xe.resyncing?xe:{...xe,resyncing:!0}),this.pendingLoadFile=O,this.send({type:"session_load",sessionFile:O,cwd:z,model:_e}),this.armLoadWatchdog()):this.stateStore.update(xe=>xe.resyncing?{...xe,resyncing:!1}:xe)},m=E=>{if(this.ws===v){this.lastInboundAt=Date.now();try{const O=typeof E.data=="string"?E.data:E.data.toString(),z=JSON.parse(O);this.handleMessage(z)}catch(O){console.error("Failed to parse WebSocket message:",O)}}},x=()=>{this.ws===v&&(this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.ws=null,this.stateStore.update(E=>({...E,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:E.activeSessionFile?!0:E.resyncing})),this.scheduleReconnect())},w=E=>{this.ws===v&&this.stateStore.update(O=>({...O,error:O.error||"Connection error occurred"}))};typeof v.addEventListener=="function"?(v.addEventListener("open",g),v.addEventListener("message",m),v.addEventListener("close",x),v.addEventListener("error",w)):typeof v.on=="function"&&(v.on("open",g),v.on("message",E=>m({data:E})),v.on("close",x),v.on("error",w))}disconnect(t=!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.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(t){for(const r of this.confirmTimers.values())clearTimeout(r);this.confirmTimers.clear(),this.stateStore.set({...da,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}else this.stateStore.update(r=>({...r,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1}))}suspend(){const t=Jt(this.stateStore);t.activeSessionFile&&(this.resumeSessionFile=t.activeSessionFile,this.resumeCwd=t.activeCwd??void 0,this.resumeModel=t.activeModel??void 0),t.isStreaming&&this.stateStore.update(r=>({...r,isStreaming:!1})),this.disconnect(!1)}resume(){const t=Jt(this.stateStore);t.connected||t.connecting||((this.resumeSessionFile||t.activeSessionFile)&&(this.stateStore.update(r=>({...r,resyncing:!0})),this.armLoadWatchdog()),this.connect(void 0,!0))}hasSuspendedSession(){return this.resumeSessionFile!==null}hasActiveSession(){return this.resumeSessionFile!==null||Jt(this.stateStore).activeSessionFile!==null}startLivenessWatchdog(){this.stopLivenessWatchdog(),this.lastInboundAt=Date.now();const t=()=>{try{this.ping()}catch{}};typeof setInterval=="function"&&(this.heartbeatTimer=setInterval(t,ar.HEARTBEAT_MS),this.heartbeatTimer&&typeof this.heartbeatTimer.unref=="function"&&this.heartbeatTimer.unref());const r=()=>{if(!this.ws)return;const s=Date.now()-this.lastInboundAt,a=Jt(this.stateStore).isStreaming,o=a?ar.TURN_STALL_MS:ar.STALE_SOCKET_MS;if(s<o)return;console.warn(`[wherever] relay connection stale: no inbound frame for ${s}ms (threshold ${o}ms, ${a?"mid-turn":"idle"}); tearing down dead socket and reconnecting`),this.stopLivenessWatchdog();const i=this.ws;this.ws=null;try{typeof i.terminate=="function"?i.terminate():typeof i.close=="function"&&i.close()}catch{}this.stateStore.update(d=>({...d,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:a?"Connection to relay stalled mid-turn; reconnecting...":d.sessionError,isStreaming:!1})),this.scheduleReconnect()};typeof setInterval=="function"&&(this.livenessTimer=setInterval(r,ar.HEARTBEAT_MS),this.livenessTimer&&typeof this.livenessTimer.unref=="function"&&this.livenessTimer.unref())}stopLivenessWatchdog(){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 t=Jt(this.stateStore);!t.loadingSession&&!t.resyncing||(console.warn("[wherever] session load timed out; clearing loading state"),this.stateStore.update(r=>({...r,loadingSession:!1,resyncing:!1,sessionError:r.sessionError||"Loading the session timed out. Please retry from the sidebar or reload."})))},ar.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,Jt(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."})))},ar.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>=ar.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 t=!!Jt(this.stateStore).activeSessionFile;this.stateStore.update(r=>({...r,connecting:!0,error:"Reconnecting..."})),this.connect(void 0,t)},this.reconnectDelay))}handleMessage(t){for(const r of this.listeners)try{r(t)}catch(s){console.error("Error in message listener:",s)}switch(t.type){case"message_history":{const r=Jt(this.stateStore).sessionId;if(r&&t.sessionId&&t.sessionId!==r)break;this.clearLoadWatchdog();break}case"session_error":case"session_destroyed":case"session_interrupted":this.clearLoadWatchdog();break}switch(t.type){case"session_created":case"session_error":case"session_interrupted":this.clearCreateWatchdog();break}switch(t.type){case"connected":this.stateStore.update(s=>({...s,connected:!0,connecting:!1,clientId:t.clientId,serverVersion:t.serverVersion??null,error:null}));break;case"connection_superseded":this.clientKey=$o();try{this.config.onClientKeyChange?.(this.clientKey)}catch(s){console.error("onClientKeyChange failed:",s)}break;case"file_uploaded":{const s=this.pendingUploads.get(t.uploadId);s&&(s.resolve({savedPath:t.savedPath,filename:t.filename}),this.pendingUploads.delete(t.uploadId));break}case"file_upload_error":{const s=this.pendingUploads.get(t.uploadId);s&&(s.reject(new Error(t.error)),this.pendingUploads.delete(t.uploadId));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 a=[...s.messages].reverse().find(o=>o.role==="thinking"&&o.isStreaming);if(!a){const o={id:this.generateId(),role:"thinking",content:t.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,o]}}return{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content+t.delta,isStreaming:!0}:o)}});break;case"message_update":this.stateStore.update(s=>{let a=[...s.messages].reverse().find(o=>o.role==="assistant"&&o.isStreaming);if(!a){const o={id:this.generateId(),role:"assistant",content:t.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,o]}}return{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content+t.delta,isStreaming:!0}:o)}});break;case"message_ack":typeof t.content=="string"&&this.confirmDeliveredByContent(t.content);break;case"queue_update":{const s=Array.isArray(t.steering)?[...t.steering]:[];this.stateStore.update(a=>({...a,pendingSteering:s,messages:this.withRestoredQueuedMessages(a.messages,s)}));break}case"message_end":this.stateStore.update(s=>{let a=s.messages;const o=[...a].reverse().find(d=>d.role==="thinking"&&d.isStreaming);o&&(a=a.map(d=>d.id===o.id?{...d,isStreaming:!1}:d));const i=[...a].reverse().find(d=>d.role==="assistant"&&d.isStreaming);if(i)a=a.map(d=>d.id===i.id?{...d,content:t.content||d.content,isStreaming:!1}:d);else if(t.content){if(t.role==="user"){if(this.confirmDeliveredByContent(t.content))return Jt(this.stateStore);const x=a.find(w=>w.role==="user"&&w.restoredFromQueue&&w.content===t.content);if(x)return{...s,messages:a.map(w=>w.id===x.id?{...w,restoredFromQueue:void 0}:w)}}const d=t.role==="user"?ks(t.content):null;if(d){const m=[...a].reverse().find(x=>x.role==="user"&&ks(x.content)===d);if(m)return m.content!==t.content&&(a=a.map(x=>x.id===m.id?{...x,content:t.content}:x)),{...s,messages:a}}const v=[...a].reverse().find(m=>m.role==="user");t.role==="user"&&v&&v.content===t.content||(a=[...a,{id:this.generateId(),role:t.role||"assistant",content:t.content,timestamp:Date.now(),isStreaming:!1}])}return{...s,messages:a}});break;case"agent_end":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.agentEndTimeout=setTimeout(()=>{const s=Date.now();this.stateStore.update(a=>({...a,isStreaming:!1,pendingSteering:[],messages:a.messages.map(o=>o.isStreaming?{...o,isStreaming:!1,...o.role==="tool"?{interrupted:!0}:{},endedAt:o.role==="tool"&&o.endedAt===void 0?s:o.endedAt}:o)})),this.agentEndTimeout=null},300);break;case"tool_start":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null);const r=t.args?Object.entries(t.args).filter(([s,a])=>a!==void 0&&a!=="").map(([s,a])=>`${s}=${JSON.stringify(a)}`).join(" "):"";this.stateStore.update(s=>{const a=s.messages.map(v=>v.isStreaming&&(v.role==="assistant"||v.role==="thinking")?{...v,isStreaming:!1}:v),o=Date.now(),i=!!t.forceCommand;if(i){const v=a.find(g=>g.role==="tool"&&g.optimistic&&g.isStreaming);if(v)return{...s,messages:a.map(g=>g.id===v.id?{...g,optimistic:!1,toolName:t.toolName,toolArgs:r,content:r?`$ ${t.toolName} ${r}`:`$ ${t.toolName}`,startedAt:o,timestamp:o,forceCommand:!0}:g)}}const d={id:this.generateId(),role:"tool",content:r?`$ ${t.toolName} ${r}`:`$ ${t.toolName}`,timestamp:o,isStreaming:!0,toolName:t.toolName,toolArgs:r,toolOutput:"",startedAt:o,...i?{forceCommand:!0}:{}};return{...s,messages:[...a,d]}});break;case"tool_update":{this.stateStore.update(s=>{const a=[...s.messages].reverse().find(o=>o.role==="tool"&&o.toolName===t.toolName&&o.isStreaming);return a?{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content.includes(`
|
|
1
|
+
import"../chunks/DsnmJJEf.js";import{ao as Vn,aU as Ps,ai as Wr,b5 as T,am as yo,w as ec,G as sa,aL as tc,an as xa,b as fi,aj as _a,ap as nc,k as rc,V as sc,q as ac,p as oc,W as ic,J as lc,K as cc,H as dc,aV as wo,C as ko,v as So,aw as Hs,X as Rr,a7 as uc,as as fc,aS as pc,ar as pi,b4 as bi,b7 as bc,b9 as yr,aN as Na,aJ as To,aI as lr,aF as cr,aa as Ft,a_ as u,af as e,Z as hc,y as b,Q as or,ac as h,ba as P,$ as vc,be as dr,a3 as pn,ae as jn,a0 as Tr,aD as bs,aT as p,M as c,aO as l,aA as pt,a1 as L,b1 as F,aH as Bn,bb as Dt,bc as gc,aW as I,a9 as gr,b6 as zn,ad as Ws,aC as mc,aM as xc,aB as Ao}from"../chunks/CAL8yDNt.js";import{i as y,s as Mr,a as Ae,p as vr}from"../chunks/Cjaz9aih.js";import{u as _c,D as te,C as is,m as ls,a as yc,n as hs,o as vs,G as wc,z as hi,x as kc,t as _t,d as Ns,f as vi,E as Fa,e as Ua,p as za,h as Cn,q as er,g as Sc,j as Tc,i as gi,F as mi,k as xi,s as Ac,B as Cc,w as Rc,l as Ec,y as Ic,b as $c}from"../chunks/ayQO3yig.js";import{_ as Mc,b as nr}from"../chunks/BORm3wtc.js";import{v as Is}from"../chunks/DGXiQ9ZV.js";import{p as Lc}from"../chunks/D9URj2y-.js";function Co(n,t,r=!1,s=!1,a=!1,o=!1){var i=n,d="";if(r){var v=n;Vn&&(i=Ps(Wr(v)))}T(()=>{var g=ec;if(d===(d=t()??"")){Vn&&yo();return}if(r&&!Vn){g.nodes=null,v.innerHTML=d,d!==""&&sa(Wr(v),v.lastChild);return}if(g.nodes!==null&&(tc(g.nodes.start,g.nodes.end),g.nodes=null),d!==""){if(Vn){xa.data;for(var m=yo(),x=m;m!==null&&(m.nodeType!==fi||m.data!=="");)x=m,m=_a(m);if(m===null)throw nc(),rc;sa(xa,x),i=Ps(m);return}var w=s?ac:a?oc:void 0,E=sc(s?"svg":a?"math":"template",w);E.innerHTML=d;var O=s||a?E:E.content;if(sa(Wr(O),O.lastChild),s||a)for(;Wr(O);)i.before(Wr(O));else i.before(O)}})}function Dc(n,t){let r=null,s=Vn;var a;if(Vn){r=xa;for(var o=Wr(document.head);o!==null&&(o.nodeType!==fi||o.data!==n);)o=_a(o);if(o===null)wo(!1);else{var i=_a(o);o.remove(),Ps(i)}}Vn||(a=document.head.appendChild(ic()));try{lc(()=>{var d=cc(()=>t(a));d.f|=dc})}finally{s&&(wo(!0),Ps(r))}}function _i(n){var t,r,s="";if(typeof n=="string"||typeof n=="number")s+=n;else if(typeof n=="object")if(Array.isArray(n)){var a=n.length;for(t=0;t<a;t++)n[t]&&(r=_i(n[t]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function Oc(){for(var n,t,r=0,s="",a=arguments.length;r<a;r++)(n=arguments[r])&&(t=_i(n))&&(s&&(s+=" "),s+=t);return s}function yi(n){return typeof n=="object"?Oc(n):n??""}function Pc(n,t,r){var s=n==null?"":""+n;return s===""?null:s}function Nc(n,t){return n==null?null:String(n)}function vn(n,t,r,s,a,o){var i=n[ko];if(Vn||i!==r||i===void 0){var d=Pc(r);(!Vn||d!==n.getAttribute("class"))&&(d==null?n.removeAttribute("class"):t?n.className=d:n.setAttribute("class",d)),n[ko]=r}return o}function wi(n,t,r,s){var a=n[So];if(Vn||a!==t){var o=Nc(t);(!Vn||o!==n.getAttribute("style"))&&(o==null?n.removeAttribute("style"):n.style.cssText=o),n[So]=t}return s}function Ba(n,t,r=!1){if(n.multiple){if(t==null)return;if(!fc(t))return pc();for(var s of n.options)s.selected=t.includes(cs(s));return}for(s of n.options){var a=cs(s);if(pi(a,t)){s.selected=!0;return}}(!r||t!==void 0)&&(n.selectedIndex=-1)}function ki(n){var t=new MutationObserver(()=>{Ba(n,n.__value)});t.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),bi(()=>{t.disconnect()})}function fs(n,t,r=t){var s=new WeakSet,a=!0;Hs(n,"change",o=>{var i=o?"[selected]":":checked",d;if(n.multiple)d=[].map.call(n.querySelectorAll(i),cs);else{var v=n.querySelector(i)??n.querySelector("option:not([disabled])");d=v&&cs(v)}r(d),n.__value=d,Rr!==null&&s.add(Rr)}),uc(()=>{var o=t();if(n===document.activeElement){var i=Rr;if(s.has(i))return}if(Ba(n,o,a),a&&o===void 0){var d=n.querySelector(":checked");d!==null&&(o=cs(d),r(o))}n.__value=o,a=!1}),ki(n)}function cs(n){return"__value"in n?n.__value:n.value}function tr(n,t,r=t){var s=new WeakSet;Hs(n,"input",async a=>{var o=a?n.defaultValue:n.value;if(o=oa(n)?ia(o):o,r(o),Rr!==null&&s.add(Rr),await bc(),o!==(o=t())){var i=n.selectionStart,d=n.selectionEnd,v=n.value.length;if(n.value=o??"",d!==null){var g=n.value.length;i===d&&d===v&&g>v?(n.selectionStart=g,n.selectionEnd=g):(n.selectionStart=i,n.selectionEnd=Math.min(d,g))}}}),(Vn&&n.defaultValue!==n.value||yr(t)==null&&n.value)&&(r(oa(n)?ia(n.value):n.value),Rr!==null&&s.add(Rr)),Na(()=>{var a=t();if(n===document.activeElement){var o=Rr;if(s.has(o))return}oa(n)&&a===ia(n.value)||n.type==="date"&&!a&&!n.value||a!==n.value&&(n.value=a??"")})}const aa=new Set;function $r(n,t,r,s,a=s){var o=r.getAttribute("type")==="checkbox",i=n;let d=!1;if(t!==null)for(var v of t)i=i[v]??=[];i.push(r),Hs(r,"change",()=>{var g=r.__value;o&&(g=Ro(i,g,r.checked)),a(g)},()=>a(o?[]:null)),Na(()=>{var g=s();if(Vn&&r.defaultChecked!==r.checked){d=!0;return}o?(g=g||[],r.checked=g.includes(r.__value)):r.checked=pi(r.__value,g)}),bi(()=>{var g=i.indexOf(r);g!==-1&&i.splice(g,1)}),aa.has(i)||(aa.add(i),To(()=>{i.sort((g,m)=>g.compareDocumentPosition(m)===4?-1:1),aa.delete(i)})),To(()=>{if(d){var g;if(o)g=Ro(i,g,r.checked);else{var m=i.find(x=>x.checked);g=m?.__value}a(g)}})}function Gn(n,t,r=t){Hs(n,"change",s=>{var a=s?n.defaultChecked:n.checked;r(a)}),(Vn&&n.defaultChecked!==n.checked||yr(t)==null)&&r(n.checked),Na(()=>{var s=t();n.checked=!!s})}function Ro(n,t,r){for(var s=new Set,a=0;a<n.length;a+=1)n[a].checked&&s.add(n[a].__value);return r||s.delete(t),Array.from(s)}function oa(n){var t=n.type;return t==="number"||t==="range"}function ia(n){return n===""?null:+n}const Fc=!1,Uc=!0,Og=Object.freeze(Object.defineProperty({__proto__:null,prerender:Uc,ssr:Fc},Symbol.toStringTag,{value:"Module"})),la="Wherever",zc="Create & maintain apps from wherever with a beautiful remote workspace.",ca="https://localhost",Bc="#000000",jc="black-translucent";function qr(n,t){return _c(n)}var Hc=h('<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 Wc(n,t){lr(t,!0);const r=ca.endsWith("/")?ca.slice(0,-1):ca,s=r+"/preview.png";let a=P(()=>t.home||!1),o=P(()=>({type:t.type||"website",title:t.title||la,description:t.description||zc,image:t.image||s,url:`${r}${Lc.url.pathname}`}));Dc("13n5pl5",i=>{var d=Hc(),v=Ft(d),g=u(v,2),m=u(g,2);{var x=Ye=>{var Mt=or(),Se=Ft(Mt);y(Se,bt=>{}),b(Ye,Mt)};y(m,Ye=>{e(a)&&Ye(x)})}var w=u(m,2),E=u(w,2),O=u(E,2),z=u(O,2),_e=u(z,2),xe=u(_e,4),fe=u(xe,2),De=u(fe,2),ee=u(De,2),Re=u(ee,2),ie=u(Re,2),Y=u(ie,2),Ke=u(Y,2),yt=u(Ke,2),ye=u(yt,4),$e=u(ye,4),Ve=u($e,2),Wt=u(Ve,2);T((Ye,Mt,Se,bt)=>{te(v,"content",e(o).title),te(g,"content",e(o).description),te(w,"content",e(o).type),te(E,"content",e(o).url),te(O,"content",e(o).title),te(z,"content",e(o).description),te(_e,"content",e(o).image),te(xe,"content",e(o).url),te(fe,"content",e(o).title),te(De,"content",e(o).description),te(ee,"content",e(o).image),te(Re,"href",Ye),te(ie,"href",Mt),te(Y,"href",Se),te(Ke,"href",bt),te(yt,"content",Bc),te(ye,"content",la),te($e,"content",jc),te(Ve,"content",la),te(Wt,"content",Is)},[()=>qr("/pwa/favicon.png"),()=>qr("/pwa/favicon.ico"),()=>qr("/pwa/apple-touch-icon.png"),()=>qr("/pwa/manifest.webmanifest")]),hc(()=>{vc.title=e(o).title??""}),b(i,d)}),cr()}let Zr=null;function Gc(){if(typeof window>"u")return null;try{if(!Zr){const n=window.AudioContext||window.webkitAudioContext;if(!n)return null;Zr=new n}return Zr.state==="suspended"&&Zr.resume().catch(()=>{}),Zr}catch{return null}}function Eo(n,t,r,s,a){const o=n.createOscillator(),i=n.createGain();o.type="sine",o.frequency.value=t;const d=.015;i.gain.setValueAtTime(1e-4,r),i.gain.exponentialRampToValueAtTime(a,r+d),i.gain.exponentialRampToValueAtTime(1e-4,r+s),o.connect(i),i.connect(n.destination),o.start(r),o.stop(r+s+.02)}const Io=new Map;function qc(n){if(typeof Audio>"u")return!1;try{let t=Io.get(n);t||(t=new Audio(n),t.preload="auto",Io.set(n,t));try{t.currentTime=0}catch{}const r=t.play();return r&&typeof r.catch=="function"&&r.catch(()=>{}),!0}catch{return!1}}function Si(n){if(n&&n.trim()&&qc(n.trim()))return;const t=Gc();if(t)try{const r=t.currentTime;Eo(t,1046.5,r,.16,.12),Eo(t,1396.9,r+.13,.22,.12)}catch{}}function ja(n){if(!n)return null;const t=n.trimStart(),r=t.match(/^<skill\s+name="([^"]*)"[^>]*>/);if(r){const s=t.indexOf("</skill>");return s===-1?null:{skillName:r[1],args:t.slice(s+8).trim()}}if(t.startsWith("/skill:")){const s=t.slice(7),a=s.indexOf(" "),o=a===-1?s:s.slice(0,a);if(!o)return null;const i=a===-1?"":s.slice(a+1).trim();return{skillName:o,args:i}}return null}function ks(n){const t=ja(n);return t?`skill:${t.skillName}\0${t.args}`:null}function $s(){}function Kc(n,t){return n!=n?t==t:n!==t||n&&typeof n=="object"||typeof n=="function"}function Vc(n,...t){if(n==null)return $s;const r=n.subscribe(...t);return r.unsubscribe?()=>r.unsubscribe():r}function Jt(n){let t;return Vc(n,r=>t=r)(),t}var jr=[];function Yc(n,t=$s){let r;const s=new Set;function a(d){if(Kc(n,d)&&(n=d,r)){const v=!jr.length;for(const g of s)g[1](),jr.push(g,n);if(v){for(let g=0;g<jr.length;g+=2)jr[g][0](jr[g+1]);jr.length=0}}}function o(d){a(d(n))}function i(d,v=$s){const g=[d,v];return s.add(g),s.size===1&&(r=t(a)||$s),d(n),()=>{s.delete(g),s.size===0&&(r(),r=null)}}return{set:a,update:o,subscribe:i}}function $o(){return`ck-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}const da={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,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,contextUsage:null,pendingSteering:[],skills:[]};class ar{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;isInitialConnect=!0;resumeSessionFile=null;resumeCwd;resumeModel;pendingLoadFile=null;listeners=new Set;pendingUploads=new Map;confirmTimers=new Map;static CONFIRM_MS=12e3;static PENDING_PREFIX="wherever-pending:";constructor(t){this.config={secure:!0,...t},this.clientKey=this.config.clientKey||$o(),this.stateStore=Yc({...da,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}connect(t,r=!1){t&&(this.config={...this.config,...t}),this.disconnect(!1),this.stateStore.update(E=>r?{...E,connecting:!0,error:null}:{...da,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const s=this.config.secure?"wss":"ws",a=this.config.host.startsWith("http")?this.config.host.replace(/^https?:\/\//,""):this.config.host,o=[];this.config.token&&o.push(`token=${encodeURIComponent(this.config.token)}`),o.push(`clientKey=${encodeURIComponent(this.clientKey)}`);const i=`${s}://${a}:${this.config.port}/ws?${o.join("&")}`,d=this.config.WebSocketCtor||(typeof globalThis<"u"?globalThis.WebSocket:null);if(!d){this.stateStore.update(E=>({...E,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}try{const E=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=E?new d(i,E):new d(i)}catch(E){this.stateStore.update(O=>({...O,connecting:!1,error:`Failed to connect: ${E}`})),this.scheduleReconnect();return}const v=this.ws,g=()=>{if(this.ws!==v)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(xe=>({...xe,connected:!0,connecting:!1,error:null}));const E=Jt(this.stateStore),O=this.resumeSessionFile??E.activeSessionFile,z=this.resumeSessionFile!=null?this.resumeCwd:E.activeCwd??void 0,_e=this.resumeSessionFile!=null?this.resumeModel:E.activeModel??void 0;this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,O?(this.stateStore.update(xe=>xe.resyncing?xe:{...xe,resyncing:!0}),this.pendingLoadFile=O,this.send({type:"session_load",sessionFile:O,cwd:z,model:_e}),this.armLoadWatchdog()):this.stateStore.update(xe=>xe.resyncing?{...xe,resyncing:!1}:xe)},m=E=>{if(this.ws===v){this.lastInboundAt=Date.now();try{const O=typeof E.data=="string"?E.data:E.data.toString(),z=JSON.parse(O);this.handleMessage(z)}catch(O){console.error("Failed to parse WebSocket message:",O)}}},x=()=>{this.ws===v&&(this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.ws=null,this.stateStore.update(E=>({...E,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:E.activeSessionFile?!0:E.resyncing})),this.scheduleReconnect())},w=E=>{this.ws===v&&this.stateStore.update(O=>({...O,error:O.error||"Connection error occurred"}))};typeof v.addEventListener=="function"?(v.addEventListener("open",g),v.addEventListener("message",m),v.addEventListener("close",x),v.addEventListener("error",w)):typeof v.on=="function"&&(v.on("open",g),v.on("message",E=>m({data:E})),v.on("close",x),v.on("error",w))}disconnect(t=!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.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(t){for(const r of this.confirmTimers.values())clearTimeout(r);this.confirmTimers.clear(),this.stateStore.set({...da,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}else this.stateStore.update(r=>({...r,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1}))}suspend(){const t=Jt(this.stateStore);t.activeSessionFile&&(this.resumeSessionFile=t.activeSessionFile,this.resumeCwd=t.activeCwd??void 0,this.resumeModel=t.activeModel??void 0),t.isStreaming&&this.stateStore.update(r=>({...r,isStreaming:!1})),this.disconnect(!1)}resume(){const t=Jt(this.stateStore);t.connected||t.connecting||((this.resumeSessionFile||t.activeSessionFile)&&(this.stateStore.update(r=>({...r,resyncing:!0})),this.armLoadWatchdog()),this.connect(void 0,!0))}hasSuspendedSession(){return this.resumeSessionFile!==null}hasActiveSession(){return this.resumeSessionFile!==null||Jt(this.stateStore).activeSessionFile!==null}startLivenessWatchdog(){this.stopLivenessWatchdog(),this.lastInboundAt=Date.now();const t=()=>{try{this.ping()}catch{}};typeof setInterval=="function"&&(this.heartbeatTimer=setInterval(t,ar.HEARTBEAT_MS),this.heartbeatTimer&&typeof this.heartbeatTimer.unref=="function"&&this.heartbeatTimer.unref());const r=()=>{if(!this.ws)return;const s=Date.now()-this.lastInboundAt,a=Jt(this.stateStore).isStreaming,o=a?ar.TURN_STALL_MS:ar.STALE_SOCKET_MS;if(s<o)return;console.warn(`[wherever] relay connection stale: no inbound frame for ${s}ms (threshold ${o}ms, ${a?"mid-turn":"idle"}); tearing down dead socket and reconnecting`),this.stopLivenessWatchdog();const i=this.ws;this.ws=null;try{typeof i.terminate=="function"?i.terminate():typeof i.close=="function"&&i.close()}catch{}this.stateStore.update(d=>({...d,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:a?"Connection to relay stalled mid-turn; reconnecting...":d.sessionError,isStreaming:!1})),this.scheduleReconnect()};typeof setInterval=="function"&&(this.livenessTimer=setInterval(r,ar.HEARTBEAT_MS),this.livenessTimer&&typeof this.livenessTimer.unref=="function"&&this.livenessTimer.unref())}stopLivenessWatchdog(){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 t=Jt(this.stateStore);!t.loadingSession&&!t.resyncing||(console.warn("[wherever] session load timed out; clearing loading state"),this.stateStore.update(r=>({...r,loadingSession:!1,resyncing:!1,sessionError:r.sessionError||"Loading the session timed out. Please retry from the sidebar or reload."})))},ar.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,Jt(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."})))},ar.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>=ar.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 t=!!Jt(this.stateStore).activeSessionFile;this.stateStore.update(r=>({...r,connecting:!0,error:"Reconnecting..."})),this.connect(void 0,t)},this.reconnectDelay))}handleMessage(t){for(const r of this.listeners)try{r(t)}catch(s){console.error("Error in message listener:",s)}switch(t.type){case"message_history":{const r=Jt(this.stateStore).sessionId;if(r&&t.sessionId&&t.sessionId!==r)break;this.clearLoadWatchdog();break}case"session_error":case"session_destroyed":case"session_interrupted":this.clearLoadWatchdog();break}switch(t.type){case"session_created":case"session_error":case"session_interrupted":this.clearCreateWatchdog();break}switch(t.type){case"connected":this.stateStore.update(s=>({...s,connected:!0,connecting:!1,clientId:t.clientId,serverVersion:t.serverVersion??null,error:null}));break;case"connection_superseded":this.clientKey=$o();try{this.config.onClientKeyChange?.(this.clientKey)}catch(s){console.error("onClientKeyChange failed:",s)}break;case"file_uploaded":{const s=this.pendingUploads.get(t.uploadId);s&&(s.resolve({savedPath:t.savedPath,filename:t.filename}),this.pendingUploads.delete(t.uploadId));break}case"file_upload_error":{const s=this.pendingUploads.get(t.uploadId);s&&(s.reject(new Error(t.error)),this.pendingUploads.delete(t.uploadId));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 a=[...s.messages].reverse().find(o=>o.role==="thinking"&&o.isStreaming);if(!a){const o={id:this.generateId(),role:"thinking",content:t.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,o]}}return{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content+t.delta,isStreaming:!0}:o)}});break;case"message_update":this.stateStore.update(s=>{let a=[...s.messages].reverse().find(o=>o.role==="assistant"&&o.isStreaming);if(!a){const o={id:this.generateId(),role:"assistant",content:t.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,o]}}return{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content+t.delta,isStreaming:!0}:o)}});break;case"message_ack":typeof t.content=="string"&&this.confirmDeliveredByContent(t.content);break;case"queue_update":{const s=Array.isArray(t.steering)?[...t.steering]:[];this.stateStore.update(a=>({...a,pendingSteering:s,messages:this.withRestoredQueuedMessages(a.messages,s)}));break}case"message_end":this.stateStore.update(s=>{let a=s.messages;const o=[...a].reverse().find(d=>d.role==="thinking"&&d.isStreaming);o&&(a=a.map(d=>d.id===o.id?{...d,isStreaming:!1}:d));const i=[...a].reverse().find(d=>d.role==="assistant"&&d.isStreaming);if(i)a=a.map(d=>d.id===i.id?{...d,content:t.content||d.content,isStreaming:!1}:d);else if(t.content){if(t.role==="user"){if(this.confirmDeliveredByContent(t.content))return Jt(this.stateStore);const x=a.find(w=>w.role==="user"&&w.restoredFromQueue&&w.content===t.content);if(x)return{...s,messages:a.map(w=>w.id===x.id?{...w,restoredFromQueue:void 0}:w)}}const d=t.role==="user"?ks(t.content):null;if(d){const m=[...a].reverse().find(x=>x.role==="user"&&ks(x.content)===d);if(m)return m.content!==t.content&&(a=a.map(x=>x.id===m.id?{...x,content:t.content}:x)),{...s,messages:a}}const v=[...a].reverse().find(m=>m.role==="user");t.role==="user"&&v&&v.content===t.content||(a=[...a,{id:this.generateId(),role:t.role||"assistant",content:t.content,timestamp:Date.now(),isStreaming:!1}])}return{...s,messages:a}});break;case"agent_end":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.agentEndTimeout=setTimeout(()=>{const s=Date.now();this.stateStore.update(a=>({...a,isStreaming:!1,pendingSteering:[],messages:a.messages.map(o=>o.isStreaming?{...o,isStreaming:!1,...o.role==="tool"?{interrupted:!0}:{},endedAt:o.role==="tool"&&o.endedAt===void 0?s:o.endedAt}:o)})),this.agentEndTimeout=null},300);break;case"tool_start":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null);const r=t.args?Object.entries(t.args).filter(([s,a])=>a!==void 0&&a!=="").map(([s,a])=>`${s}=${JSON.stringify(a)}`).join(" "):"";this.stateStore.update(s=>{const a=s.messages.map(v=>v.isStreaming&&(v.role==="assistant"||v.role==="thinking")?{...v,isStreaming:!1}:v),o=Date.now(),i=!!t.forceCommand;if(i){const v=a.find(g=>g.role==="tool"&&g.optimistic&&g.isStreaming);if(v)return{...s,messages:a.map(g=>g.id===v.id?{...g,optimistic:!1,toolName:t.toolName,toolArgs:r,content:r?`$ ${t.toolName} ${r}`:`$ ${t.toolName}`,startedAt:o,timestamp:o,forceCommand:!0}:g)}}const d={id:this.generateId(),role:"tool",content:r?`$ ${t.toolName} ${r}`:`$ ${t.toolName}`,timestamp:o,isStreaming:!0,toolName:t.toolName,toolArgs:r,toolOutput:"",startedAt:o,...i?{forceCommand:!0}:{}};return{...s,messages:[...a,d]}});break;case"tool_update":{this.stateStore.update(s=>{const a=[...s.messages].reverse().find(o=>o.role==="tool"&&o.toolName===t.toolName&&o.isStreaming);return a?{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content.includes(`
|
|
2
2
|
`)?o.content+t.delta:`${o.content}
|
|
3
3
|
${t.delta}`,toolOutput:`${o.toolOutput}${t.delta}`}:o)}:s});break}case"tool_end":{const s=t.result?`${t.result}`:"",a=!!t.isError&&this.isAbortedToolResult(s),o=!!t.isError&&!a,i=Array.isArray(t.images)&&t.images.length>0?t.images:void 0;this.stateStore.update(d=>{const v=d.messages.find(m=>m.role==="tool"&&m.toolName===t.toolName&&m.isStreaming)??[...d.messages].reverse().find(m=>m.role==="tool"&&m.toolName===t.toolName&&!m.content.startsWith("Tool error:")),g=Date.now();if(v){const m=o?"Error: ":"";return{...d,messages:d.messages.map(x=>x.id===v.id?{...x,content:`${m}${x.content}
|
|
4
4
|
${s}`,isStreaming:!1,isError:o,interrupted:a,toolOutput:s,...i?{images:i}:{},endedAt:g}:x)}}else{const m=o?`Tool error: ${t.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.`)),b(re,Ee)};y(be,re=>{e(g)?.state==="cancelled"&&re(oe)})}var W=u(be,2);{var Me=re=>{var Ee=Iv(),rt=c(Ee),ht=c(rt,!0);l(rt);var Rt=u(rt,2);{var wt=Kt=>{var Xt=Ev(),Zt=Ft(Xt),on=c(Zt);l(Zt);var _n=u(Zt,2);{var gn=sn=>{var ln=Rv(),Sn=c(ln,!0);l(ln),T(()=>I(Sn,e(w).stderr)),b(sn,ln)};y(_n,sn=>{e(ie)&&sn(gn)})}T(()=>I(on,`${e(ie)?"Hide":"Show"} git output`)),L("click",Zt,()=>p(ie,!e(ie))),b(Kt,Xt)};y(Rt,Kt=>{e(w).stderr&&Kt(wt)})}l(Ee),T(()=>I(ht,e(w).message)),b(re,Ee)};y(W,re=>{e(w)&&re(Me)})}var Le=u(W,2);{var G=re=>{var Ee=$v(),rt=c(Ee,!0);l(Ee),T(()=>I(rt,e(E).message)),b(re,Ee)};y(Le,re=>{e(E)&&re(G)})}var Fe=u(Le,4);_t(Fe);var J=u(Fe,2);{var gt=re=>{var Ee=Lv();Cn(Ee,21,()=>e(ee),rt=>rt.url,(rt,ht)=>{var Rt=Mv(),wt=c(Rt,!0);l(Rt),T(()=>I(wt,e(ht).url)),L("click",Rt,()=>{p(fe,e(ht).url,!0),p(De,!0)}),b(rt,Rt)}),l(Ee),b(re,Ee)},Oe=re=>{var Ee=Dv();b(re,Ee)};y(J,re=>{e(ee).length>1?re(gt):!e(Re)&&e(ee).length===0&&re(Oe,1)})}var k=u(J,2),Z=c(k,!0);l(k);var K=u(k,2),he=c(K);{var Ze=re=>{var Ee=Ov();L("click",Ee,()=>p(Y,!0)),b(re,Ee)},lt=re=>{var Ee=Pv(),rt=u(Ft(Ee),2),ht=c(rt);_t(ht),pt(2),l(rt);var Rt=u(rt,2),wt=c(Rt,!0);l(Rt),T(()=>{Fa(ht,e(Ke)),Rt.disabled=e(z),I(wt,e(z)?"Creating...":"Create folder")}),L("change",ht,Kt=>p(yt,Kt.currentTarget.checked,!0)),L("click",Rt,Ve),b(re,Ee)};y(he,re=>{e(Y)?re(lt,-1):re(Ze)})}l(K),T(re=>{te(Fe,"placeholder",e(Re)?"Looking for the repository...":"git@github.com:owner/repo.git"),k.disabled=re,I(Z,e(z)?"Starting...":"Clone repository")},[()=>!e(fe).trim()||e(z)]),L("input",Fe,()=>p(De,!0)),L("keydown",Fe,re=>{re.key==="Enter"&&$e()}),tr(Fe,()=>e(fe),re=>p(fe,re)),L("click",k,$e),b(Xe,nt)};y(Ct,Xe=>{e(x)?Xe(Ne):e(m)?Xe(qt,1):Xe(Yt,-1)})}l(bt),T(()=>I(We,e(d).cwd)),b(Se,bt)};y(Ye,Se=>{e(d)&&Se(Mt)})}b(n,Wt),cr(),i()}Tr(["click","input","keydown","change"]);function zv(n){return n.loading||n.resyncing||n.hasSessionHash}function Bv(n){return n.connected&&n.searchConfigured&&!n.hasSession&&!zv(n)}var jv=h('<div class="mt-2 font-mono text-xs break-all text-brand-text-muted"> </div>'),Hv=h(`<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>`),Wv=h('<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>'),Gv=h('<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),qv=h('<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>'),Kv=h('<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),Vv=h('<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>'),Yv=h('<span class="text-brand-text-muted/70"> </span>'),Xv=h('<div class="truncate text-xs text-brand-text-muted"> </div>'),Zv=h('<div class="truncate text-xs text-brand-text-muted"> </div>'),Qv=h('<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>'),Jv=h('<div class="mt-2 text-xs text-rose-400"> </div>'),eg=h('<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),tg=h('<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>'),ng=h('<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),rg=h('<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),sg=h('<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>'),ag=h('<span class="text-sm text-brand-text-muted">Search the web below, or pick a session from the sidebar</span>'),og=h('<span class="text-sm text-brand-text-muted">Select a session from sidebar</span>'),ig=h('<span class="text-sm text-brand-text-muted">Not connected</span>'),lg=h('<div class="flex min-w-0 items-center gap-2"><!></div>'),cg=h('<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>'),dg=h("<option> </option>"),ug=h('<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>'),fg=h('<span class="truncate text-brand-text-muted"> </span>'),pg=h('<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>'),bg=h('<div class="flex min-w-0 flex-1 items-center gap-3"><!> <!></div>'),hg=h('<span class="flex-shrink-0 rounded bg-yellow-500/20 px-2 py-1 text-xs text-yellow-400">Read-only</span>'),vg=h('<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>'),gg=h('<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>'),mg=h('<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>'),xg=h('<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>'),_g=h('<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>'),yg=h('<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>'),wg=h('<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>'),kg=h('<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>'),Sg=h('<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>'),Tg=h("<!> <!>",1),Ag=h('<button type="button" class="fixed inset-0 z-10 bg-brand-dark/50 md:hidden" aria-label="Close sidebar"></button>'),Cg=h('<!> <!> <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 Pg(n,t){lr(t,!0);const r=()=>Ae(xs,"$isConnected",ee),s=()=>Ae(Zs,"$isResyncing",ee),a=()=>Ae(ml,"$isAgentPending",ee),o=()=>Ae(_s,"$isLoadingSession",ee),i=()=>Ae(pl,"$isInterrupted",ee),d=()=>Ae(no,"$sessionError",ee),v=()=>Ae(hl,"$sessionNotice",ee),g=()=>Ae(fl,"$folderConflict",ee),m=()=>Ae(eo,"$folderMissing",ee),x=()=>Ae(Xs,"$isReadOnly",ee),w=()=>Ae(Xr,"$activeSessionInfo",ee),E=()=>Ae(bn,"$piState",ee),O=()=>Ae(Ua,"$availableModels",ee),z=()=>Ae(gl,"$isCreatingSession",ee),_e=()=>Ae(to,"$restoreState",ee),xe=()=>Ae(hi,"$searchFolderStore",ee),fe=()=>Ae(Ic,"$searchDefaultModelStore",ee),De=()=>Ae($c,"$appearanceStore",ee),[ee,Re]=Mr();let ie=F(!1),Y=F("main"),Ke=F(!1),yt=F("");function ye($,j=""){p(Ke,$,!0),p(yt,j,!0),p(Y,"search")}let $e=F(!1),Ve;bs(()=>{setTimeout(()=>Fr(),200);const $=()=>{if(e(it)){const le=window.location.hash?decodeURIComponent(window.location.hash.slice(1)):"";le&&le!==e(Fe)?ms(le):!le&&e(Fe)&&ir()}};window.addEventListener("hashchange",$);let j=null;const ve=8e3,ze=()=>{if(document.visibilityState==="hidden"){if(Ki())return;j&&clearTimeout(j),j=setTimeout(()=>{j=null,document.visibilityState==="hidden"&&e(it)&&Gi()},ve)}else Za(),j&&(clearTimeout(j),j=null),e(it)||(ka()?wa():Fr())},se=le=>{j&&(clearTimeout(j),j=null),document.visibilityState!=="hidden"&&!e(it)&&(ka()?wa():Fr())};return document.addEventListener("visibilitychange",ze),window.addEventListener("pageshow",se),()=>{window.removeEventListener("hashchange",$),document.removeEventListener("visibilitychange",ze),window.removeEventListener("pageshow",se),j&&clearTimeout(j)}});function Wt(){Fr()}function Ye(){ir(),ps()}function Mt(){ps(),setTimeout(()=>Fr(),100)}function Se(){ls()}function bt(){typeof window<"u"&&(window.location.hash=""),ir(),p(ie,!1)}let it=P(r),We=P(s),Ct=P(a),Ne=P(o),qt=P(i),Yt=P(d),Xe=P(v),nt=P(g),be=P(m),oe=P(x),W=P(w),Me=P(E),Le=P(()=>O().models),G=F(!1),Fe=P(()=>e(W).sessionId);Dt(()=>{typeof window<"u"&&e(it)&&(e(Fe)?(window.location.hash=encodeURIComponent(e(Fe)),p(G,!0)):e(G)&&(p(G,!1),window.location.hash&&(window.location.hash="")))});let J=null;Dt(()=>{if(!e(it)||typeof window>"u"||!window.location.hash)return;const $=decodeURIComponent(window.location.hash.slice(1));$&&(e(Fe)===$||e(Ne)||e(We)||J||(J=setTimeout(()=>{J=null,!(e(Fe)===$||e(Ne)||e(We))&&Ji($)},300)))}),Dt(()=>{e(it)||p(G,!1)}),Dt(()=>{(e(Fe)||e(Ne)||e(We))&&p(ie,!1)});let gt=P(z),Oe=P(()=>_e()?.forSessionCreate?_e():null),k=P(xe),Z=F(void 0),K=P(()=>Bv({connected:e(it),searchConfigured:!!e(k),hasSession:!!e(W).sessionFile,loading:e(Ne),resyncing:e(We),hasSessionHash:typeof window<"u"&&!!window.location.hash})),he=P(()=>e(Le).map($=>({value:`${$.provider}:${$.modelId}`,label:`${$.label}${$.isDefault?" (default)":""}`}))),Ze=P(fe),lt=P(()=>De().label),re=F("");Dt(()=>{if(e(he).length===0||e(he).some(ze=>ze.value===e(re)))return;const j=e(he).find(ze=>ze.value===e(Ze)),ve=e(Le).find(ze=>ze.isDefault);p(re,j?j.value:ve?`${ve.provider}:${ve.modelId}`:e(he)[0].value,!0)});let Ee=F(!1);Dt(()=>{e(K)&&!e(Ee)&&e(Z)&&(p(Ee,!0),e(Z).focusInput())});function rt(){typeof window<"u"&&window.location.hash&&(window.location.hash=""),ir(),e(Z)?.focusInput()}var ht=Cg(),Rt=Ft(ht);{let $=P(()=>e(lt)?`Wherever · ${e(lt)}`:"Wherever");Wc(Rt,{get title(){return e($)},description:"Create & maintain apps from wherever"})}var wt=u(Rt,2);{var Kt=$=>{var j=Hv(),ve=c(j),ze=u(c(ve),4);{var se=U=>{var V=jv(),pe=c(V,!0);l(V),T(()=>I(pe,e(Oe).job.url)),b(U,V)};y(ze,U=>{e(Oe).job?.url&&U(se)})}var le=u(ze,2);Hl(le,{get job(){return e(Oe).job}});var D=u(le,2);l(ve),l(j),L("click",D,()=>Qa()),b($,j)},Xt=$=>{var j=Wv();b($,j)};y(wt,$=>{e(Oe)?$(Kt):e(gt)&&$(Xt,1)})}var Zt=u(wt,2),on=c(Zt),_n=c(on),gn=c(_n),sn=c(gn);{var ln=$=>{var j=Gv(),ve=u(Ft(j),2);L("click",ve,()=>p($e,!1)),b($,j)},Sn=$=>{var j=Kv(),ve=Ft(j),ze=c(ve),se=u(ze,4);{var le=pe=>{var at=qv(),St=c(at,!0);l(at),T(()=>{te(at,"title",e(lt)),I(St,e(lt))}),b(pe,at)};y(se,pe=>{e(lt)&&pe(le)})}l(ve);var D=u(ve,2),U=c(D),V=u(U,2);l(D),T(pe=>te(ze,"src",pe),[()=>qr("/logo.svg")]),L("click",ve,bt),L("click",U,()=>p($e,!0)),L("click",V,()=>p(ie,!1)),b($,j)};y(sn,$=>{e($e)?$(ln):$(Sn,-1)})}l(gn),l(_n);var En=u(_n,2);{var Ge=$=>{var j=Vv(),ve=c(j);{let V=P(()=>(e(Me).connected,"localhost"));Bd(ve,{get host(){return e(V)},port:31415,token:"",onConnected:Wt})}var ze=u(ve,2),se=u(c(ze),2),le=c(se),D=u(le,2),U=u(D,2);l(se),l(ze),l(j),L("click",le,Se),L("click",D,Mt),L("click",U,Ye),b($,j)},Lt=$=>{var j=rg(),ve=Ft(j),ze=c(ve),se=c(ze),le=u(se,2),D=c(le,!0);l(le);var U=u(le,2),V=c(U),pe=u(V);{var at=Q=>{var S=Yv(),f=c(S);l(S),T(()=>I(f,` / srv ${e(Me).serverVersion??""}`)),b(Q,S)};y(pe,Q=>{e(Me).serverVersion&&Q(at)})}l(U),l(ze);var St=u(ze,2);{var Je=Q=>{var S=Qv(),f=c(S);{var _=Ie=>{var me=Xv(),xt=c(me);l(me),T(an=>{te(me,"title",e(W).cwd),I(xt,`📁 ${an??""}`)},[()=>e(W).cwd.split("/").pop()||e(W).cwd]),b(Ie,me)};y(f,Ie=>{e(W).cwd&&Ie(_)})}var H=u(f,2);{var ae=Ie=>{var me=Zv(),xt=c(me);l(me),T(()=>{te(me,"title",e(W).model),I(xt,`🤖 ${e(W).model??""}`)}),b(Ie,me)};y(H,Ie=>{e(W).model&&Ie(ae)})}var Te=u(H,2),ge=c(Te);l(Te),l(S),L("click",ge,bt),b(Q,S)};y(St,Q=>{e(W).sessionFile&&Q(Je)})}var mt=u(St,2);{var ct=Q=>{var S=Jv(),f=c(S,!0);l(S),T(()=>I(f,e(Me).error)),b(Q,S)};y(mt,Q=>{e(Me).error&&!e(it)&&Q(ct)})}l(ve);var mn=u(ve,2),R=c(mn);{var N=Q=>{var S=eg(),f=Ft(S),_=u(f,2);L("click",f,()=>ye(!1)),L("click",_,()=>{p(Y,"readonly"),xi()}),b(Q,S)},ue=Q=>{var S=tg(),f=u(c(S),2),_=c(f);l(f),l(S),T(()=>I(_,`Back to ${e(Ke)?"read-only sessions":"sessions"}`)),L("click",S,()=>p(Y,e(Ke)?"readonly":"main",!0)),b(Q,S)},je=Q=>{var S=ng(),f=Ft(S),_=u(f,2);L("click",f,()=>p(Y,"main")),L("click",_,()=>ye(!0)),b(Q,S)};y(R,Q=>{e(Y)==="main"?Q(N):e(Y)==="search"?Q(ue,1):Q(je,-1)})}l(mn);var et=u(mn,2),It=c(et);{var M=Q=>{pv(Q,{get readOnly(){return e(Ke)},get initialQuery(){return e(yt)},onOpened:()=>p(ie,!1)})},Bt=Q=>{di(Q,{readOnly:!0,onSearchAll:S=>ye(!0,S)})},nn=Q=>{di(Q,{onSearchAll:S=>ye(!1,S)})};y(It,Q=>{e(Y)==="search"?Q(M):e(Y)==="readonly"?Q(Bt,1):Q(nn,-1)})}l(et),T(()=>{vn(se,1,`h-2.5 w-2.5 rounded-full ${e(it)?"bg-emerald-500":"bg-rose-500"}`),vn(le,1,`text-sm ${e(it)?"text-emerald-400":"text-rose-400"}`),I(D,e(it)?"Connected":"Disconnected"),te(U,"title",e(Me).serverVersion?`App build ${Is} · server ${e(Me).serverVersion}`:`App build ${Is}`),I(V,`v${Is}`)}),b($,j)};y(En,$=>{e($e)?$(Ge):$(Lt,-1)})}l(on);var dn=u(on,2),In=c(dn),Nn=c(In),A=u(Nn,2);{var X=$=>{var j=sg();L("click",j,rt),b($,j)};y(A,$=>{e(it)&&e(k)&&e(W).sessionFile&&$(X)})}var we=u(A,2);{var st=$=>{var j=lg(),ve=c(j);{var ze=D=>{var U=ag();b(D,U)},se=D=>{var U=og();b(D,U)},le=D=>{var U=ig();b(D,U)};y(ve,D=>{e(it)&&e(K)?D(ze):e(it)?D(se,1):D(le,-1)})}l(j),b($,j)};y(we,$=>{(!e(it)||!e(W).sessionFile)&&$(st)})}var Qe=u(we,2);{var C=$=>{var j=bg(),ve=c(j);{var ze=D=>{var U=cg(),V=u(c(U),2),pe=c(V,!0);l(V),l(U),T(at=>{te(V,"title",e(W).cwd),I(pe,at)},[()=>e(W).cwd.split("/").pop()||e(W).cwd]),b(D,U)};y(ve,D=>{e(W).cwd&&D(ze)})}var se=u(ve,2);{var le=D=>{var U=pg(),V=c(U),pe=u(c(V),2);l(V);var at=u(V,2);{var St=mt=>{var ct=ug();Cn(ct,21,()=>e(Le),er,(R,N)=>{var ue=dg(),je=c(ue,!0);l(ue);var et={};T(()=>{I(je,e(N).label),et!==(et=`${e(N).provider}:${e(N).modelId}`)&&(ue.value=ue.__value=`${e(N).provider}:${e(N).modelId}`)}),b(R,ue)}),l(ct);var mn;ki(ct),T(()=>{mn!==(mn=e(W).model)&&(ct.value=(ct.__value=e(W).model)??"",Ba(ct,e(W).model))}),L("input",ct,R=>cl(R.currentTarget.value)),b(mt,ct)},Je=mt=>{var ct=fg(),mn=c(ct,!0);l(ct),T(()=>{te(ct,"title",e(W).model),I(mn,e(W).model)}),b(mt,ct)};y(at,mt=>{e(Le).length>0&&!e(oe)?mt(St):mt(Je,-1)})}l(U),T(()=>{vn(pe,1,`absolute -right-0.5 -bottom-0.5 h-2 w-2 rounded-full border border-brand-surface ${e(Me).isStreaming?"animate-pulse bg-orange-500":"bg-emerald-500"}`),te(pe,"title",e(Me).isStreaming?"Agent working...":"Ready")}),b(D,U)};y(se,D=>{e(W).model&&D(le)})}l(j),b($,j)};y(Qe,$=>{e(W).sessionFile&&$(C)})}var B=u(Qe,2);{var ne=$=>{var j=hg();b($,j)};y(B,$=>{e(oe)&&$(ne)})}l(In);var de=u(In,2);{var Ce=$=>{var j=vg();b($,j)};y(de,$=>{e(qt)&&$(Ce)})}var Ot=u(de,2);{var Ut=$=>{var j=gg(),ve=c(j),ze=c(ve,!0);l(ve);var se=u(ve,2);l(j),T(()=>{vn(j,1,`flex items-start justify-between gap-2 border px-4 py-2 text-sm ${e(Xe).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(ze,e(Xe).message)}),L("click",se,()=>ol()),b($,j)};y(Ot,$=>{e(Xe)&&$(Ut)})}var tn=u(Ot,2);{var ut=$=>{var j=xg(),ve=c(j),ze=u(c(ve));{var se=V=>{var pe=zn("You are both working in it — changes may conflict.");b(V,pe)},le=V=>{var pe=zn("You are observing (read-only) to avoid clashing.");b(V,pe)};y(ze,V=>{e(nt).continued?V(se):V(le,-1)})}l(ve);var D=u(ve,2);{var U=V=>{var pe=mg();L("click",pe,()=>rl()),b(V,pe)};y(D,V=>{e(nt).continued||V(U)})}l(j),b($,j)};y(tn,$=>{e(nt)?.active&&$(ut)})}var vt=u(tn,2);{var yn=$=>{var j=_g(),ve=c(j),ze=c(ve,!0);l(ve);var se=u(ve,2);l(j),T(()=>I(ze,e(Yt))),L("click",se,()=>Er()),b($,j)};y(vt,$=>{e(Yt)&&$(yn)})}var Be=u(vt,2);{var Pe=$=>{var j=yg();b($,j)};y(Be,$=>{e(oe)&&!e(qt)&&!e(be)&&!(e(nt)?.active&&!e(nt).continued)&&$(Pe)})}var Et=u(Be,2);nr(mb(Et,{onMessageSent:()=>{}}),$=>Ve=$,()=>Ve);var Pt=u(Et,2);{var Qt=$=>{Uv($,{})},kt=$=>{var j=wg();b($,j)},cn=$=>{var j=Tg(),ve=Ft(j);{var ze=D=>{var U=kg();b(D,U)},se=D=>{var U=Sg();b(D,U)};y(ve,D=>{e(W).sessionFile&&(e(We)||!e(it))?D(ze):e(W).sessionFile&&e(Ct)&&D(se,1)})}var le=u(ve,2);{let D=P(()=>!!e(k)),U=P(()=>e(K)?!e(it):!e(it)||e(oe)||!e(W).sessionFile||e(We)||e(Ct));nr(ah(le,{get searchMode(){return e(K)},get searchConfigured(){return e(D)},get searchModels(){return e(he)},onSubmit:(V,pe)=>tl(V,e(re),pe),placeholder:"Search the web...",submitLabel:"Search",get disabled(){return e(U)},onSend:()=>Ve?.forceScrollToBottom(),get searchModel(){return e(re)},set searchModel(V){p(re,V,!0)}}),V=>p(Z,V,!0),()=>e(Z))}b($,j)};y(Pt,$=>{e(be)?$(Qt):e(oe)&&e(W).sessionFile?$(kt,1):$(cn,-1)})}l(dn);var zt=u(dn,2);hv(zt,{});var un=u(zt,2);{var wn=$=>{var j=Ag();L("click",j,()=>p(ie,!1)),b($,j)};y(un,$=>{e(ie)&&$(wn)})}l(Zt),T(()=>vn(on,1,`app-chrome ${e(ie)?"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`)),L("click",Nn,()=>p(ie,!e(ie))),b(n,ht),cr(),Re()}Tr(["click","input"]);export{Pg as component,Og as universal};
|
|
120
|
-
//# sourceMappingURL=2.
|
|
120
|
+
//# sourceMappingURL=2.DnoKKNs8.js.map
|