wherever-dev 0.11.1 → 0.11.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/index.js +40 -65
- package/dist/index.js.map +1 -1
- package/dist/session-pool.d.ts +15 -1
- package/dist/session-pool.d.ts.map +1 -1
- package/dist/session-pool.js +29 -6
- package/dist/session-pool.js.map +1 -1
- package/package.json +1 -1
- package/public/_app/immutable/chunks/8jn76iTS.js +2 -0
- package/public/_app/immutable/chunks/{RXasHx9k.js.map → 8jn76iTS.js.map} +1 -1
- package/public/_app/immutable/chunks/{ByLcLrZX.js → BDmEqqqL.js} +2 -2
- package/public/_app/immutable/chunks/{ByLcLrZX.js.map → BDmEqqqL.js.map} +1 -1
- package/public/_app/immutable/chunks/{Cs_pvO9R.js → CE0jm7EC.js} +2 -2
- package/public/_app/immutable/chunks/{Cs_pvO9R.js.map → CE0jm7EC.js.map} +1 -1
- package/public/_app/immutable/entry/{app.gwwyWULZ.js → app.YbNg9lmT.js} +3 -3
- package/public/_app/immutable/entry/{app.gwwyWULZ.js.map → app.YbNg9lmT.js.map} +1 -1
- package/public/_app/immutable/entry/start.Mhebc2Bx.js +2 -0
- package/public/_app/immutable/entry/start.Mhebc2Bx.js.map +1 -0
- package/public/_app/immutable/nodes/{0.B5eCDNfb.js → 0.BwSufUPS.js} +2 -2
- package/public/_app/immutable/nodes/{0.B5eCDNfb.js.map → 0.BwSufUPS.js.map} +1 -1
- package/public/_app/immutable/nodes/{1.B92A9EWe.js → 1.x8yi4PgO.js} +2 -2
- package/public/_app/immutable/nodes/{1.B92A9EWe.js.map → 1.x8yi4PgO.js.map} +1 -1
- package/public/_app/immutable/nodes/{2.DKpq2-9F.js → 2.BWbDsdRU.js} +2 -2
- package/public/_app/immutable/nodes/{2.DKpq2-9F.js.map → 2.BWbDsdRU.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/chunks/RXasHx9k.js +0 -2
- package/public/_app/immutable/entry/start.CAV5FIFt.js +0 -2
- package/public/_app/immutable/entry/start.CAV5FIFt.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as co,a as p,c as hr,g as b,d as Lr,e as D,s as N,f as gr,t as Bn,h as Vs}from"../chunks/itgD7vGH.js";import{as as Vn,b3 as Bs,am as qr,bf as I,aq as ya,O as Yl,aT as Xl,ar as Ao,d as ui,an as Co,au as Zl,n as Ql,a1 as Jl,u as ec,t as tc,a2 as nc,W as rc,X as sc,H as oc,b4 as wa,C as ka,z as Sa,aF as Ys,a3 as Er,ad as ac,aA as ic,a_ as lc,az as fi,be as pi,bg as cc,bh as yr,aV as jo,aR as Ta,aQ as Tr,aN as Ar,ag as Jt,b7 as f,aj as t,a6 as dc,bi as F,$ as uc,bm as Rn,ai as Mn,a9 as fn,aL as ys,a$ as h,Y as d,aW as l,aJ as rt,ba as U,aP as Kn,bj as $t,bk as fc,aU as pc,aK as Aa}from"../chunks/CRRPBe07.js";import{i as y,s as Br,a as Ce,p as vr}from"../chunks/Dtm96ZKi.js";import{a as hc,b as Y,r as ht,c as hi,e as $n,i as tr,d as bi}from"../chunks/ByLcLrZX.js";import{_ as bc,b as nr}from"../chunks/CAWbdcQM.js";import{v as Ds}from"../chunks/RXasHx9k.js";import{p as vc}from"../chunks/Cs_pvO9R.js";function Ca(n,e,r=!1,s=!1,o=!1,a=!1){var i=n,c="";if(r){var v=n;Vn&&(i=Bs(qr(v)))}I(()=>{var g=Yl;if(c===(c=e()??"")){Vn&&ya();return}if(r&&!Vn){g.nodes=null,v.innerHTML=c,c!==""&&co(qr(v),v.lastChild);return}if(g.nodes!==null&&(Xl(g.nodes.start,g.nodes.end),g.nodes=null),c!==""){if(Vn){Ao.data;for(var m=ya(),x=m;m!==null&&(m.nodeType!==ui||m.data!=="");)x=m,m=Co(m);if(m===null)throw Zl(),Ql;co(Ao,x),i=Bs(m);return}var k=s?ec:o?tc:void 0,$=Jl(s?"svg":o?"math":"template",k);$.innerHTML=c;var L=s||o?$:$.content;if(co(qr(L),L.lastChild),s||o)for(;qr(L);)i.before(qr(L));else i.before(L)}})}function gc(n,e){let r=null,s=Vn;var o;if(Vn){r=Ao;for(var a=qr(document.head);a!==null&&(a.nodeType!==ui||a.data!==n);)a=Co(a);if(a===null)wa(!1);else{var i=Co(a);a.remove(),Bs(i)}}Vn||(o=document.head.appendChild(nc()));try{rc(()=>{var c=sc(()=>e(o));c.f|=oc})}finally{s&&(wa(!0),Bs(r))}}function vi(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=vi(n[e]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function mc(){for(var n,e,r=0,s="",o=arguments.length;r<o;r++)(n=arguments[r])&&(e=vi(n))&&(s&&(s+=" "),s+=e);return s}function gi(n){return typeof n=="object"?mc(n):n??""}function xc(n,e,r){var s=n==null?"":""+n;return s===""?null:s}function _c(n,e){return n==null?null:String(n)}function un(n,e,r,s,o,a){var i=n[ka];if(Vn||i!==r||i===void 0){var c=xc(r);(!Vn||c!==n.getAttribute("class"))&&(c==null?n.removeAttribute("class"):e?n.className=c:n.setAttribute("class",c)),n[ka]=r}return a}function yc(n,e,r,s){var o=n[Sa];if(Vn||o!==e){var a=_c(e);(!Vn||a!==n.getAttribute("style"))&&(a==null?n.removeAttribute("style"):n.style.cssText=a),n[Sa]=e}return s}function Wo(n,e,r=!1){if(n.multiple){if(e==null)return;if(!ic(e))return lc();for(var s of n.options)s.selected=e.includes(hs(s));return}for(s of n.options){var o=hs(s);if(fi(o,e)){s.selected=!0;return}}(!r||e!==void 0)&&(n.selectedIndex=-1)}function mi(n){var e=new MutationObserver(()=>{Wo(n,n.__value)});e.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),pi(()=>{e.disconnect()})}function xs(n,e,r=e){var s=new WeakSet,o=!0;Ys(n,"change",a=>{var i=a?"[selected]":":checked",c;if(n.multiple)c=[].map.call(n.querySelectorAll(i),hs);else{var v=n.querySelector(i)??n.querySelector("option:not([disabled])");c=v&&hs(v)}r(c),n.__value=c,Er!==null&&s.add(Er)}),ac(()=>{var a=e();if(n===document.activeElement){var i=Er;if(s.has(i))return}if(Wo(n,a,o),o&&a===void 0){var c=n.querySelector(":checked");c!==null&&(a=hs(c),r(a))}n.__value=a,o=!1}),mi(n)}function hs(n){return"__value"in n?n.__value:n.value}function cr(n,e,r=e){var s=new WeakSet;Ys(n,"input",async o=>{var a=o?n.defaultValue:n.value;if(a=fo(n)?po(a):a,r(a),Er!==null&&s.add(Er),await cc(),a!==(a=e())){var i=n.selectionStart,c=n.selectionEnd,v=n.value.length;if(n.value=a??"",c!==null){var g=n.value.length;i===c&&c===v&&g>v?(n.selectionStart=g,n.selectionEnd=g):(n.selectionStart=i,n.selectionEnd=Math.min(c,g))}}}),(Vn&&n.defaultValue!==n.value||yr(e)==null&&n.value)&&(r(fo(n)?po(n.value):n.value),Er!==null&&s.add(Er)),jo(()=>{var o=e();if(n===document.activeElement){var a=Er;if(s.has(a))return}fo(n)&&o===po(n.value)||n.type==="date"&&!o&&!n.value||o!==n.value&&(n.value=o??"")})}const uo=new Set;function Mr(n,e,r,s,o=s){var a=r.getAttribute("type")==="checkbox",i=n;let c=!1;if(e!==null)for(var v of e)i=i[v]??=[];i.push(r),Ys(r,"change",()=>{var g=r.__value;a&&(g=Ra(i,g,r.checked)),o(g)},()=>o(a?[]:null)),jo(()=>{var g=s();if(Vn&&r.defaultChecked!==r.checked){c=!0;return}a?(g=g||[],r.checked=g.includes(r.__value)):r.checked=fi(r.__value,g)}),pi(()=>{var g=i.indexOf(r);g!==-1&&i.splice(g,1)}),uo.has(i)||(uo.add(i),Ta(()=>{i.sort((g,m)=>g.compareDocumentPosition(m)===4?-1:1),uo.delete(i)})),Ta(()=>{if(c){var g;if(a)g=Ra(i,g,r.checked);else{var m=i.find(x=>x.checked);g=m?.__value}o(g)}})}function Wn(n,e,r=e){Ys(n,"change",s=>{var o=s?n.defaultChecked:n.checked;r(o)}),(Vn&&n.defaultChecked!==n.checked||yr(e)==null)&&r(n.checked),jo(()=>{var s=e();n.checked=!!s})}function Ra(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 fo(n){var e=n.type;return e==="number"||e==="range"}function po(n){return n===""?null:+n}const wc=!1,kc=!0,Fv=Object.freeze(Object.defineProperty({__proto__:null,prerender:kc,ssr:wc},Symbol.toStringTag,{value:"Module"})),ho="Wherever",Sc="Create & maintain apps from wherever with a beautiful remote workspace.",bo="https://localhost",Tc="#000000",Ac="black-translucent";function Vr(n,e){return hc(n)}var Cc=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 Rc(n,e){Tr(e,!0);const r=bo.endsWith("/")?bo.slice(0,-1):bo,s=r+"/preview.png";let o=F(()=>e.home||!1),a=F(()=>({type:e.type||"website",title:e.title||ho,description:e.description||Sc,image:e.image||s,url:`${r}${vc.url.pathname}`}));gc("13n5pl5",i=>{var c=Cc(),v=Jt(c),g=f(v,2),m=f(g,2);{var x=je=>{var Te=hr(),Me=Jt(Te);y(Me,Ct=>{}),p(je,Te)};y(m,je=>{t(o)&&je(x)})}var k=f(m,2),$=f(k,2),L=f($,2),H=f(L,2),ye=f(H,2),ee=f(ye,4),de=f(ee,2),xe=f(de,2),ae=f(xe,2),Se=f(ae,2),he=f(Se,2),V=f(he,2),ot=f(V,2),Mt=f(ot,2),Xe=f(Mt,4),bt=f(Xe,4),at=f(bt,2),Ut=f(at,2);I((je,Te,Me,Ct)=>{Y(v,"content",t(a).title),Y(g,"content",t(a).description),Y(k,"content",t(a).type),Y($,"content",t(a).url),Y(L,"content",t(a).title),Y(H,"content",t(a).description),Y(ye,"content",t(a).image),Y(ee,"content",t(a).url),Y(de,"content",t(a).title),Y(xe,"content",t(a).description),Y(ae,"content",t(a).image),Y(Se,"href",je),Y(he,"href",Te),Y(V,"href",Me),Y(ot,"href",Ct),Y(Mt,"content",Tc),Y(Xe,"content",ho),Y(bt,"content",Ac),Y(at,"content",ho),Y(Ut,"content",Ds)},[()=>Vr("/pwa/favicon.png"),()=>Vr("/pwa/favicon.ico"),()=>Vr("/pwa/apple-touch-icon.png"),()=>Vr("/pwa/manifest.webmanifest")]),dc(()=>{uc.title=t(a).title??""}),p(i,c)}),Ar()}let ts=null;function Ec(){if(typeof window>"u")return null;try{if(!ts){const n=window.AudioContext||window.webkitAudioContext;if(!n)return null;ts=new n}return ts.state==="suspended"&&ts.resume().catch(()=>{}),ts}catch{return null}}function Ea(n,e,r,s,o){const a=n.createOscillator(),i=n.createGain();a.type="sine",a.frequency.value=e;const c=.015;i.gain.setValueAtTime(1e-4,r),i.gain.exponentialRampToValueAtTime(o,r+c),i.gain.exponentialRampToValueAtTime(1e-4,r+s),a.connect(i),i.connect(n.destination),a.start(r),a.stop(r+s+.02)}const Ia=new Map;function Ic(n){if(typeof Audio>"u")return!1;try{let e=Ia.get(n);e||(e=new Audio(n),e.preload="auto",Ia.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 xi(n){if(n&&n.trim()&&Ic(n.trim()))return;const e=Ec();if(e)try{const r=e.currentTime;Ea(e,1046.5,r,.16,.12),Ea(e,1396.9,r+.13,.22,.12)}catch{}}function Go(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 Rs(n){const e=Go(n);return e?`skill:${e.skillName}\0${e.args}`:null}function Ps(){}function $c(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Mc(n,...e){if(n==null)return Ps;const r=n.subscribe(...e);return r.unsubscribe?()=>r.unsubscribe():r}function dn(n){let e;return Mc(n,r=>e=r)(),e}var Wr=[];function Lc(n,e=Ps){let r;const s=new Set;function o(c){if($c(n,c)&&(n=c,r)){const v=!Wr.length;for(const g of s)g[1](),Wr.push(g,n);if(v){for(let g=0;g<Wr.length;g+=2)Wr[g][0](Wr[g+1]);Wr.length=0}}}function a(c){o(c(n))}function i(c,v=Ps){const g=[c,v];return s.add(g),s.size===1&&(r=e(o)||Ps),c(n),()=>{s.delete(g),s.size===0&&(r(),r=null)}}return{set:o,update:a,subscribe:i}}function $a(){return`ck-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}const vo={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,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 ir{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(e){this.config={secure:!0,...e},this.clientKey=this.config.clientKey||$a(),this.stateStore=Lc({...vo,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}connect(e,r=!1){e&&(this.config={...this.config,...e}),this.disconnect(!1),this.stateStore.update($=>r?{...$,connecting:!0,error:null}:{...vo,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const s=this.config.secure?"wss":"ws",o=this.config.host.startsWith("http")?this.config.host.replace(/^https?:\/\//,""):this.config.host,a=[];this.config.token&&a.push(`token=${encodeURIComponent(this.config.token)}`),a.push(`clientKey=${encodeURIComponent(this.clientKey)}`);const i=`${s}://${o}:${this.config.port}/ws?${a.join("&")}`,c=this.config.WebSocketCtor||(typeof globalThis<"u"?globalThis.WebSocket:null);if(!c){this.stateStore.update($=>({...$,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}try{const $=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=$?new c(i,$):new c(i)}catch($){this.stateStore.update(L=>({...L,connecting:!1,error:`Failed to connect: ${$}`})),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(ee=>({...ee,connected:!0,connecting:!1,error:null}));const $=dn(this.stateStore),L=this.resumeSessionFile??$.activeSessionFile,H=this.resumeSessionFile!=null?this.resumeCwd:$.activeCwd??void 0,ye=this.resumeSessionFile!=null?this.resumeModel:$.activeModel??void 0;this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,L?(this.stateStore.update(ee=>ee.resyncing?ee:{...ee,resyncing:!0}),this.pendingLoadFile=L,this.send({type:"session_load",sessionFile:L,cwd:H,model:ye}),this.armLoadWatchdog()):this.stateStore.update(ee=>ee.resyncing?{...ee,resyncing:!1}:ee)},m=$=>{if(this.ws===v){this.lastInboundAt=Date.now();try{const L=typeof $.data=="string"?$.data:$.data.toString(),H=JSON.parse(L);this.handleMessage(H)}catch(L){console.error("Failed to parse WebSocket message:",L)}}},x=()=>{this.ws===v&&(this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.ws=null,this.stateStore.update($=>({...$,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:$.activeSessionFile?!0:$.resyncing})),this.scheduleReconnect())},k=$=>{this.ws===v&&this.stateStore.update(L=>({...L,error:L.error||"Connection error occurred"}))};typeof v.addEventListener=="function"?(v.addEventListener("open",g),v.addEventListener("message",m),v.addEventListener("close",x),v.addEventListener("error",k)):typeof v.on=="function"&&(v.on("open",g),v.on("message",$=>m({data:$})),v.on("close",x),v.on("error",k))}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.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.stateStore.set({...vo,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=dn(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=dn(this.stateStore);e.connected||e.connecting||((this.resumeSessionFile||e.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||dn(this.stateStore).activeSessionFile!==null}startLivenessWatchdog(){this.stopLivenessWatchdog(),this.lastInboundAt=Date.now();const e=()=>{try{this.ping()}catch{}};typeof setInterval=="function"&&(this.heartbeatTimer=setInterval(e,ir.HEARTBEAT_MS),this.heartbeatTimer&&typeof this.heartbeatTimer.unref=="function"&&this.heartbeatTimer.unref());const r=()=>{if(!this.ws)return;const s=Date.now()-this.lastInboundAt,o=dn(this.stateStore).isStreaming,a=o?ir.TURN_STALL_MS:ir.STALE_SOCKET_MS;if(s<a)return;console.warn(`[wherever] relay connection stale: no inbound frame for ${s}ms (threshold ${a}ms, ${o?"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(c=>({...c,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:o?"Connection to relay stalled mid-turn; reconnecting...":c.sessionError,isStreaming:!1})),this.scheduleReconnect()};typeof setInterval=="function"&&(this.livenessTimer=setInterval(r,ir.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 e=dn(this.stateStore);!e.loadingSession&&!e.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."})))},ir.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,dn(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."})))},ir.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>=ir.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=!!dn(this.stateStore).activeSessionFile;this.stateStore.update(r=>({...r,connecting:!0,error:"Reconnecting..."})),this.connect(void 0,e)},this.reconnectDelay))}handleMessage(e){for(const r of this.listeners)try{r(e)}catch(s){console.error("Error in message listener:",s)}switch(e.type){case"message_history":{const r=dn(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,error:null}));break;case"connection_superseded":this.clientKey=$a();try{this.config.onClientKeyChange?.(this.clientKey)}catch(s){console.error("onClientKeyChange failed:",s)}break;case"file_uploaded":{const s=this.pendingUploads.get(e.uploadId);s&&(s.resolve({savedPath:e.savedPath,filename:e.filename}),this.pendingUploads.delete(e.uploadId));break}case"file_upload_error":{const s=this.pendingUploads.get(e.uploadId);s&&(s.reject(new Error(e.error)),this.pendingUploads.delete(e.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 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(c=>c.role==="thinking"&&c.isStreaming);a&&(o=o.map(c=>c.id===a.id?{...c,isStreaming:!1}:c));const i=[...o].reverse().find(c=>c.role==="assistant"&&c.isStreaming);if(i)o=o.map(c=>c.id===i.id?{...c,content:e.content||c.content,isStreaming:!1}:c);else if(e.content){if(e.role==="user"){if(this.confirmDeliveredByContent(e.content))return dn(this.stateStore);const x=o.find(k=>k.role==="user"&&k.restoredFromQueue&&k.content===e.content);if(x)return{...s,messages:o.map(k=>k.id===x.id?{...k,restoredFromQueue:void 0}:k)}}const c=e.role==="user"?Rs(e.content):null;if(c){const m=[...o].reverse().find(x=>x.role==="user"&&Rs(x.content)===c);if(m)return m.content!==e.content&&(o=o.map(x=>x.id===m.id?{...x,content:e.content}:x)),{...s,messages:o}}const v=[...o].reverse().find(m=>m.role==="user");e.role==="user"&&v&&v.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(v=>v.isStreaming&&(v.role==="assistant"||v.role==="thinking")?{...v,isStreaming:!1}:v),a=Date.now(),i=!!e.forceCommand;if(i){const v=o.find(g=>g.role==="tool"&&g.optimistic&&g.isStreaming);if(v)return{...s,messages:o.map(g=>g.id===v.id?{...g,optimistic:!1,toolName:e.toolName,toolArgs:r,content:r?`$ ${e.toolName} ${r}`:`$ ${e.toolName}`,startedAt:a,timestamp:a,forceCommand:!0}:g)}}const c={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,c]}});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{b as co,a as p,c as hr,g as b,d as Lr,e as D,s as N,f as gr,t as Bn,h as Vs}from"../chunks/itgD7vGH.js";import{as as Vn,b3 as Bs,am as qr,bf as I,aq as ya,O as Yl,aT as Xl,ar as Ao,d as ui,an as Co,au as Zl,n as Ql,a1 as Jl,u as ec,t as tc,a2 as nc,W as rc,X as sc,H as oc,b4 as wa,C as ka,z as Sa,aF as Ys,a3 as Er,ad as ac,aA as ic,a_ as lc,az as fi,be as pi,bg as cc,bh as yr,aV as jo,aR as Ta,aQ as Tr,aN as Ar,ag as Jt,b7 as f,aj as t,a6 as dc,bi as F,$ as uc,bm as Rn,ai as Mn,a9 as fn,aL as ys,a$ as h,Y as d,aW as l,aJ as rt,ba as U,aP as Kn,bj as $t,bk as fc,aU as pc,aK as Aa}from"../chunks/CRRPBe07.js";import{i as y,s as Br,a as Ce,p as vr}from"../chunks/Dtm96ZKi.js";import{a as hc,b as Y,r as ht,c as hi,e as $n,i as tr,d as bi}from"../chunks/BDmEqqqL.js";import{_ as bc,b as nr}from"../chunks/CAWbdcQM.js";import{v as Ds}from"../chunks/8jn76iTS.js";import{p as vc}from"../chunks/CE0jm7EC.js";function Ca(n,e,r=!1,s=!1,o=!1,a=!1){var i=n,c="";if(r){var v=n;Vn&&(i=Bs(qr(v)))}I(()=>{var g=Yl;if(c===(c=e()??"")){Vn&&ya();return}if(r&&!Vn){g.nodes=null,v.innerHTML=c,c!==""&&co(qr(v),v.lastChild);return}if(g.nodes!==null&&(Xl(g.nodes.start,g.nodes.end),g.nodes=null),c!==""){if(Vn){Ao.data;for(var m=ya(),x=m;m!==null&&(m.nodeType!==ui||m.data!=="");)x=m,m=Co(m);if(m===null)throw Zl(),Ql;co(Ao,x),i=Bs(m);return}var k=s?ec:o?tc:void 0,$=Jl(s?"svg":o?"math":"template",k);$.innerHTML=c;var L=s||o?$:$.content;if(co(qr(L),L.lastChild),s||o)for(;qr(L);)i.before(qr(L));else i.before(L)}})}function gc(n,e){let r=null,s=Vn;var o;if(Vn){r=Ao;for(var a=qr(document.head);a!==null&&(a.nodeType!==ui||a.data!==n);)a=Co(a);if(a===null)wa(!1);else{var i=Co(a);a.remove(),Bs(i)}}Vn||(o=document.head.appendChild(nc()));try{rc(()=>{var c=sc(()=>e(o));c.f|=oc})}finally{s&&(wa(!0),Bs(r))}}function vi(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=vi(n[e]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function mc(){for(var n,e,r=0,s="",o=arguments.length;r<o;r++)(n=arguments[r])&&(e=vi(n))&&(s&&(s+=" "),s+=e);return s}function gi(n){return typeof n=="object"?mc(n):n??""}function xc(n,e,r){var s=n==null?"":""+n;return s===""?null:s}function _c(n,e){return n==null?null:String(n)}function un(n,e,r,s,o,a){var i=n[ka];if(Vn||i!==r||i===void 0){var c=xc(r);(!Vn||c!==n.getAttribute("class"))&&(c==null?n.removeAttribute("class"):e?n.className=c:n.setAttribute("class",c)),n[ka]=r}return a}function yc(n,e,r,s){var o=n[Sa];if(Vn||o!==e){var a=_c(e);(!Vn||a!==n.getAttribute("style"))&&(a==null?n.removeAttribute("style"):n.style.cssText=a),n[Sa]=e}return s}function Wo(n,e,r=!1){if(n.multiple){if(e==null)return;if(!ic(e))return lc();for(var s of n.options)s.selected=e.includes(hs(s));return}for(s of n.options){var o=hs(s);if(fi(o,e)){s.selected=!0;return}}(!r||e!==void 0)&&(n.selectedIndex=-1)}function mi(n){var e=new MutationObserver(()=>{Wo(n,n.__value)});e.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),pi(()=>{e.disconnect()})}function xs(n,e,r=e){var s=new WeakSet,o=!0;Ys(n,"change",a=>{var i=a?"[selected]":":checked",c;if(n.multiple)c=[].map.call(n.querySelectorAll(i),hs);else{var v=n.querySelector(i)??n.querySelector("option:not([disabled])");c=v&&hs(v)}r(c),n.__value=c,Er!==null&&s.add(Er)}),ac(()=>{var a=e();if(n===document.activeElement){var i=Er;if(s.has(i))return}if(Wo(n,a,o),o&&a===void 0){var c=n.querySelector(":checked");c!==null&&(a=hs(c),r(a))}n.__value=a,o=!1}),mi(n)}function hs(n){return"__value"in n?n.__value:n.value}function cr(n,e,r=e){var s=new WeakSet;Ys(n,"input",async o=>{var a=o?n.defaultValue:n.value;if(a=fo(n)?po(a):a,r(a),Er!==null&&s.add(Er),await cc(),a!==(a=e())){var i=n.selectionStart,c=n.selectionEnd,v=n.value.length;if(n.value=a??"",c!==null){var g=n.value.length;i===c&&c===v&&g>v?(n.selectionStart=g,n.selectionEnd=g):(n.selectionStart=i,n.selectionEnd=Math.min(c,g))}}}),(Vn&&n.defaultValue!==n.value||yr(e)==null&&n.value)&&(r(fo(n)?po(n.value):n.value),Er!==null&&s.add(Er)),jo(()=>{var o=e();if(n===document.activeElement){var a=Er;if(s.has(a))return}fo(n)&&o===po(n.value)||n.type==="date"&&!o&&!n.value||o!==n.value&&(n.value=o??"")})}const uo=new Set;function Mr(n,e,r,s,o=s){var a=r.getAttribute("type")==="checkbox",i=n;let c=!1;if(e!==null)for(var v of e)i=i[v]??=[];i.push(r),Ys(r,"change",()=>{var g=r.__value;a&&(g=Ra(i,g,r.checked)),o(g)},()=>o(a?[]:null)),jo(()=>{var g=s();if(Vn&&r.defaultChecked!==r.checked){c=!0;return}a?(g=g||[],r.checked=g.includes(r.__value)):r.checked=fi(r.__value,g)}),pi(()=>{var g=i.indexOf(r);g!==-1&&i.splice(g,1)}),uo.has(i)||(uo.add(i),Ta(()=>{i.sort((g,m)=>g.compareDocumentPosition(m)===4?-1:1),uo.delete(i)})),Ta(()=>{if(c){var g;if(a)g=Ra(i,g,r.checked);else{var m=i.find(x=>x.checked);g=m?.__value}o(g)}})}function Wn(n,e,r=e){Ys(n,"change",s=>{var o=s?n.defaultChecked:n.checked;r(o)}),(Vn&&n.defaultChecked!==n.checked||yr(e)==null)&&r(n.checked),jo(()=>{var s=e();n.checked=!!s})}function Ra(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 fo(n){var e=n.type;return e==="number"||e==="range"}function po(n){return n===""?null:+n}const wc=!1,kc=!0,Fv=Object.freeze(Object.defineProperty({__proto__:null,prerender:kc,ssr:wc},Symbol.toStringTag,{value:"Module"})),ho="Wherever",Sc="Create & maintain apps from wherever with a beautiful remote workspace.",bo="https://localhost",Tc="#000000",Ac="black-translucent";function Vr(n,e){return hc(n)}var Cc=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 Rc(n,e){Tr(e,!0);const r=bo.endsWith("/")?bo.slice(0,-1):bo,s=r+"/preview.png";let o=F(()=>e.home||!1),a=F(()=>({type:e.type||"website",title:e.title||ho,description:e.description||Sc,image:e.image||s,url:`${r}${vc.url.pathname}`}));gc("13n5pl5",i=>{var c=Cc(),v=Jt(c),g=f(v,2),m=f(g,2);{var x=je=>{var Te=hr(),Me=Jt(Te);y(Me,Ct=>{}),p(je,Te)};y(m,je=>{t(o)&&je(x)})}var k=f(m,2),$=f(k,2),L=f($,2),H=f(L,2),ye=f(H,2),ee=f(ye,4),de=f(ee,2),xe=f(de,2),ae=f(xe,2),Se=f(ae,2),he=f(Se,2),V=f(he,2),ot=f(V,2),Mt=f(ot,2),Xe=f(Mt,4),bt=f(Xe,4),at=f(bt,2),Ut=f(at,2);I((je,Te,Me,Ct)=>{Y(v,"content",t(a).title),Y(g,"content",t(a).description),Y(k,"content",t(a).type),Y($,"content",t(a).url),Y(L,"content",t(a).title),Y(H,"content",t(a).description),Y(ye,"content",t(a).image),Y(ee,"content",t(a).url),Y(de,"content",t(a).title),Y(xe,"content",t(a).description),Y(ae,"content",t(a).image),Y(Se,"href",je),Y(he,"href",Te),Y(V,"href",Me),Y(ot,"href",Ct),Y(Mt,"content",Tc),Y(Xe,"content",ho),Y(bt,"content",Ac),Y(at,"content",ho),Y(Ut,"content",Ds)},[()=>Vr("/pwa/favicon.png"),()=>Vr("/pwa/favicon.ico"),()=>Vr("/pwa/apple-touch-icon.png"),()=>Vr("/pwa/manifest.webmanifest")]),dc(()=>{uc.title=t(a).title??""}),p(i,c)}),Ar()}let ts=null;function Ec(){if(typeof window>"u")return null;try{if(!ts){const n=window.AudioContext||window.webkitAudioContext;if(!n)return null;ts=new n}return ts.state==="suspended"&&ts.resume().catch(()=>{}),ts}catch{return null}}function Ea(n,e,r,s,o){const a=n.createOscillator(),i=n.createGain();a.type="sine",a.frequency.value=e;const c=.015;i.gain.setValueAtTime(1e-4,r),i.gain.exponentialRampToValueAtTime(o,r+c),i.gain.exponentialRampToValueAtTime(1e-4,r+s),a.connect(i),i.connect(n.destination),a.start(r),a.stop(r+s+.02)}const Ia=new Map;function Ic(n){if(typeof Audio>"u")return!1;try{let e=Ia.get(n);e||(e=new Audio(n),e.preload="auto",Ia.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 xi(n){if(n&&n.trim()&&Ic(n.trim()))return;const e=Ec();if(e)try{const r=e.currentTime;Ea(e,1046.5,r,.16,.12),Ea(e,1396.9,r+.13,.22,.12)}catch{}}function Go(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 Rs(n){const e=Go(n);return e?`skill:${e.skillName}\0${e.args}`:null}function Ps(){}function $c(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Mc(n,...e){if(n==null)return Ps;const r=n.subscribe(...e);return r.unsubscribe?()=>r.unsubscribe():r}function dn(n){let e;return Mc(n,r=>e=r)(),e}var Wr=[];function Lc(n,e=Ps){let r;const s=new Set;function o(c){if($c(n,c)&&(n=c,r)){const v=!Wr.length;for(const g of s)g[1](),Wr.push(g,n);if(v){for(let g=0;g<Wr.length;g+=2)Wr[g][0](Wr[g+1]);Wr.length=0}}}function a(c){o(c(n))}function i(c,v=Ps){const g=[c,v];return s.add(g),s.size===1&&(r=e(o)||Ps),c(n),()=>{s.delete(g),s.size===0&&(r(),r=null)}}return{set:o,update:a,subscribe:i}}function $a(){return`ck-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}const vo={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,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 ir{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(e){this.config={secure:!0,...e},this.clientKey=this.config.clientKey||$a(),this.stateStore=Lc({...vo,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}connect(e,r=!1){e&&(this.config={...this.config,...e}),this.disconnect(!1),this.stateStore.update($=>r?{...$,connecting:!0,error:null}:{...vo,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const s=this.config.secure?"wss":"ws",o=this.config.host.startsWith("http")?this.config.host.replace(/^https?:\/\//,""):this.config.host,a=[];this.config.token&&a.push(`token=${encodeURIComponent(this.config.token)}`),a.push(`clientKey=${encodeURIComponent(this.clientKey)}`);const i=`${s}://${o}:${this.config.port}/ws?${a.join("&")}`,c=this.config.WebSocketCtor||(typeof globalThis<"u"?globalThis.WebSocket:null);if(!c){this.stateStore.update($=>({...$,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}try{const $=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=$?new c(i,$):new c(i)}catch($){this.stateStore.update(L=>({...L,connecting:!1,error:`Failed to connect: ${$}`})),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(ee=>({...ee,connected:!0,connecting:!1,error:null}));const $=dn(this.stateStore),L=this.resumeSessionFile??$.activeSessionFile,H=this.resumeSessionFile!=null?this.resumeCwd:$.activeCwd??void 0,ye=this.resumeSessionFile!=null?this.resumeModel:$.activeModel??void 0;this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,L?(this.stateStore.update(ee=>ee.resyncing?ee:{...ee,resyncing:!0}),this.pendingLoadFile=L,this.send({type:"session_load",sessionFile:L,cwd:H,model:ye}),this.armLoadWatchdog()):this.stateStore.update(ee=>ee.resyncing?{...ee,resyncing:!1}:ee)},m=$=>{if(this.ws===v){this.lastInboundAt=Date.now();try{const L=typeof $.data=="string"?$.data:$.data.toString(),H=JSON.parse(L);this.handleMessage(H)}catch(L){console.error("Failed to parse WebSocket message:",L)}}},x=()=>{this.ws===v&&(this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.ws=null,this.stateStore.update($=>({...$,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:$.activeSessionFile?!0:$.resyncing})),this.scheduleReconnect())},k=$=>{this.ws===v&&this.stateStore.update(L=>({...L,error:L.error||"Connection error occurred"}))};typeof v.addEventListener=="function"?(v.addEventListener("open",g),v.addEventListener("message",m),v.addEventListener("close",x),v.addEventListener("error",k)):typeof v.on=="function"&&(v.on("open",g),v.on("message",$=>m({data:$})),v.on("close",x),v.on("error",k))}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.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.stateStore.set({...vo,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=dn(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=dn(this.stateStore);e.connected||e.connecting||((this.resumeSessionFile||e.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||dn(this.stateStore).activeSessionFile!==null}startLivenessWatchdog(){this.stopLivenessWatchdog(),this.lastInboundAt=Date.now();const e=()=>{try{this.ping()}catch{}};typeof setInterval=="function"&&(this.heartbeatTimer=setInterval(e,ir.HEARTBEAT_MS),this.heartbeatTimer&&typeof this.heartbeatTimer.unref=="function"&&this.heartbeatTimer.unref());const r=()=>{if(!this.ws)return;const s=Date.now()-this.lastInboundAt,o=dn(this.stateStore).isStreaming,a=o?ir.TURN_STALL_MS:ir.STALE_SOCKET_MS;if(s<a)return;console.warn(`[wherever] relay connection stale: no inbound frame for ${s}ms (threshold ${a}ms, ${o?"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(c=>({...c,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:o?"Connection to relay stalled mid-turn; reconnecting...":c.sessionError,isStreaming:!1})),this.scheduleReconnect()};typeof setInterval=="function"&&(this.livenessTimer=setInterval(r,ir.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 e=dn(this.stateStore);!e.loadingSession&&!e.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."})))},ir.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,dn(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."})))},ir.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>=ir.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=!!dn(this.stateStore).activeSessionFile;this.stateStore.update(r=>({...r,connecting:!0,error:"Reconnecting..."})),this.connect(void 0,e)},this.reconnectDelay))}handleMessage(e){for(const r of this.listeners)try{r(e)}catch(s){console.error("Error in message listener:",s)}switch(e.type){case"message_history":{const r=dn(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,error:null}));break;case"connection_superseded":this.clientKey=$a();try{this.config.onClientKeyChange?.(this.clientKey)}catch(s){console.error("onClientKeyChange failed:",s)}break;case"file_uploaded":{const s=this.pendingUploads.get(e.uploadId);s&&(s.resolve({savedPath:e.savedPath,filename:e.filename}),this.pendingUploads.delete(e.uploadId));break}case"file_upload_error":{const s=this.pendingUploads.get(e.uploadId);s&&(s.reject(new Error(e.error)),this.pendingUploads.delete(e.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 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(c=>c.role==="thinking"&&c.isStreaming);a&&(o=o.map(c=>c.id===a.id?{...c,isStreaming:!1}:c));const i=[...o].reverse().find(c=>c.role==="assistant"&&c.isStreaming);if(i)o=o.map(c=>c.id===i.id?{...c,content:e.content||c.content,isStreaming:!1}:c);else if(e.content){if(e.role==="user"){if(this.confirmDeliveredByContent(e.content))return dn(this.stateStore);const x=o.find(k=>k.role==="user"&&k.restoredFromQueue&&k.content===e.content);if(x)return{...s,messages:o.map(k=>k.id===x.id?{...k,restoredFromQueue:void 0}:k)}}const c=e.role==="user"?Rs(e.content):null;if(c){const m=[...o].reverse().find(x=>x.role==="user"&&Rs(x.content)===c);if(m)return m.content!==e.content&&(o=o.map(x=>x.id===m.id?{...x,content:e.content}:x)),{...s,messages:o}}const v=[...o].reverse().find(m=>m.role==="user");e.role==="user"&&v&&v.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(v=>v.isStreaming&&(v.role==="assistant"||v.role==="thinking")?{...v,isStreaming:!1}:v),a=Date.now(),i=!!e.forceCommand;if(i){const v=o.find(g=>g.role==="tool"&&g.optimistic&&g.isStreaming);if(v)return{...s,messages:o.map(g=>g.id===v.id?{...g,optimistic:!1,toolName:e.toolName,toolArgs:r,content:r?`$ ${e.toolName} ${r}`:`$ ${e.toolName}`,startedAt:a,timestamp:a,forceCommand:!0}:g)}}const c={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,c]}});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(c=>{const v=c.messages.find(m=>m.role==="tool"&&m.toolName===e.toolName&&m.isStreaming)??[...c.messages].reverse().find(m=>m.role==="tool"&&m.toolName===e.toolName&&!m.content.startsWith("Tool error:")),g=Date.now();if(v){const m=a?"Error: ":"";return{...c,messages:c.messages.map(x=>x.id===v.id?{...x,content:`${m}${x.content}
|
|
4
4
|
${s}`,isStreaming:!1,isError:a,interrupted:o,toolOutput:s,...i?{images:i}:{},endedAt:g}:x)}}else{const m=a?`Tool error: ${e.toolName}
|
|
@@ -101,4 +101,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
101
101
|
${t(L)[t(G)]?"▲":"▼"}`)),D("click",Vt,()=>t(L)[t(G)]=!t(L)[t(G)]),p(De,vt)};y(ln,De=>{t(ue).length>0&&De(Kt)})}var Tn=f(ln,2);{var En=De=>{var vt=Ub(),Vt=d(vt);l(vt),I(An=>{Y(vt,"title",An),N(Vt,`+${t(q).otherHits??""} more match${t(q).otherHits===1?"":"es"} in this
|
|
102
102
|
conversation`)},[()=>Sb(t(q).snippet)]),p(De,vt)};y(Tn,De=>{t(q).otherHits>0&&De(En)})}l(we),I((De,vt)=>{N(tt,De),N(mt,vt)},[()=>Tb(t(q).kind,t(q).tool),()=>di(t(q).ts)]),p(X,we)}),I(()=>N(j,`${t(x).hits.length??""} result${t(x).hits.length===1?"":"s"} `)),p(ne,se)};y(it,ne=>{t(Ne)?ne(gt):t(k)&&!t(x)?ne(Lt,1):t(x)?.status==="not-indexed"?ne(qt,2):t(x)?.status==="unavailable"||t(x)?.status==="error"?ne(Re,3):t(x)&&t(x).hits.length===0?ne(Ht,4):t(x)&&ne(Ee,5)})}l(hn),l(at),I(()=>{Y(Te,"placeholder",v()?"Search read-only conversations...":"Search all conversations..."),bi(Te,t(m)),un(Ct,1,gi(t(k)?"animate-pulse":""))}),gr("submit",je,ot),D("input",Te,ne=>he(ne.currentTarget.value)),p(n,at),Ar(),i()}Lr(["click","input"]);var Wb=b(`<div class="fixed inset-0 z-50 flex items-center justify-center bg-brand-dark/60"><div class="mx-4 w-full max-w-md rounded-xl border border-brand-border bg-brand-surface-2 p-6 shadow-xl"><h2 class="mb-2 text-lg font-bold text-brand-text">Sudo password</h2> <p class="mb-3 text-sm text-brand-text-muted">This command needs your sudo password to run. It is used once and never
|
|
103
103
|
stored.</p> <pre class="mb-4 overflow-x-auto rounded-lg bg-brand-surface-3 px-3 py-2 font-mono text-xs text-brand-text"> </pre> <input type="password" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" placeholder="Password" class="mb-4 w-full rounded-lg border border-brand-border bg-brand-surface-3 px-3 py-2.5 text-sm text-brand-text outline-none focus:border-brand-blue"/> <div class="flex gap-3"><button class="flex-1 rounded-lg bg-brand-surface-3 px-4 py-2.5 text-sm text-brand-text transition-colors hover:bg-brand-surface-2">Cancel</button> <button class="flex-1 rounded-lg bg-brand-blue px-4 py-2.5 text-sm text-brand-text transition-colors hover:opacity-90">Run</button></div></div></div>`);function Gb(n,e){Tr(e,!0);const r=()=>Ce(pl,"$sudoPrompt",s),[s,o]=Br();let a=F(r),i=U(""),c=U(null),v=U(null);$t(()=>{const H=t(a)?.promptId??null;H!==t(v)&&(h(v,H,!0),h(i,""),H&&queueMicrotask(()=>t(c)?.focus()))});function g(){t(a)&&(ol(t(i)),h(i,""))}function m(){al(),h(i,"")}function x(H){H.key==="Enter"?(H.preventDefault(),g()):H.key==="Escape"&&(H.preventDefault(),m())}var k=hr(),$=Jt(k);{var L=H=>{var ye=Wb(),ee=d(ye),de=f(d(ee),4),xe=d(de,!0);l(de);var ae=f(de,2);ht(ae),nr(ae,ot=>h(c,ot),()=>t(c));var Se=f(ae,2),he=d(Se),V=f(he,2);l(Se),l(ee),l(ye),I(()=>N(xe,t(a).command)),D("keydown",ae,x),cr(ae,()=>t(i),ot=>h(i,ot)),D("click",he,m),D("click",V,g),p(H,ye)};y($,H=>{t(a)&&H(L)})}p(n,k),Ar(),o()}Lr(["keydown","click"]);function qb(n){return n.loading||n.resyncing||n.hasSessionHash}function Kb(n){return n.connected&&n.searchConfigured&&!n.hasSession&&!qb(n)}var Vb=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>'),Yb=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),Xb=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),Zb=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>'),Qb=b('<span class="text-brand-text-muted/70"> </span>'),Jb=b('<div class="truncate text-xs text-brand-text-muted"> </div>'),ev=b('<div class="truncate text-xs text-brand-text-muted"> </div>'),tv=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>'),nv=b('<div class="mt-2 text-xs text-rose-400"> </div>'),rv=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),sv=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>'),ov=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),av=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),iv=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>'),lv=b('<span class="text-sm text-brand-text-muted">Search the web below, or pick a session from the sidebar</span>'),cv=b('<span class="text-sm text-brand-text-muted">Select a session from sidebar</span>'),dv=b('<span class="text-sm text-brand-text-muted">Not connected</span>'),uv=b('<div class="flex min-w-0 items-center gap-2"><!></div>'),fv=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>'),pv=b("<option> </option>"),hv=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>'),bv=b('<span class="truncate text-brand-text-muted"> </span>'),vv=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>'),gv=b('<div class="flex min-w-0 flex-1 items-center gap-3"><!> <!></div>'),mv=b('<span class="flex-shrink-0 rounded bg-yellow-500/20 px-2 py-1 text-xs text-yellow-400">Read-only</span>'),xv=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>'),_v=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>'),yv=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>'),wv=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>'),kv=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>'),Sv=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>'),Tv=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>'),Av=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>'),Cv=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>'),Rv=b("<!> <!>",1),Ev=b('<button type="button" class="fixed inset-0 z-10 bg-brand-dark/50 md:hidden" aria-label="Close sidebar"></button>'),Iv=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 Uv(n,e){Tr(e,!0);const r=()=>Ce(Ss,"$isConnected",ee),s=()=>Ce(no,"$isResyncing",ee),o=()=>Ce(bl,"$isAgentPending",ee),a=()=>Ce(Ts,"$isLoadingSession",ee),i=()=>Ce(dl,"$isInterrupted",ee),c=()=>Ce(sa,"$sessionError",ee),v=()=>Ce(fl,"$sessionNotice",ee),g=()=>Ce(cl,"$folderConflict",ee),m=()=>Ce(to,"$isReadOnly",ee),x=()=>Ce(es,"$activeSessionInfo",ee),k=()=>Ce(pn,"$piState",ee),$=()=>Ce(Zr,"$availableModels",ee),L=()=>Ce(hl,"$isCreatingSession",ee),H=()=>Ce(Ko,"$searchFolderStore",ee),ye=()=>Ce(Si,"$searchDefaultModelStore",ee),[ee,de]=Br();let xe=U(!1),ae=U("main"),Se=U(!1),he=U("");function V(R,O=""){h(Se,R,!0),h(he,O,!0),h(ae,"search")}let ot=U(!1),Mt;ys(()=>{setTimeout(()=>Ur(),200);const R=()=>{if(t(Te)){const ge=window.location.hash?decodeURIComponent(window.location.hash.slice(1)):"";ge&&ge!==t(se)?ks(ge):!ge&&t(se)&&lr()}};window.addEventListener("hashchange",R);let O=null;const oe=8e3,_e=()=>{if(document.visibilityState==="hidden"){if(qi())return;O&&clearTimeout(O),O=setTimeout(()=>{O=null,document.visibilityState==="hidden"&&t(Te)&&Wi()},oe)}else na(),O&&(clearTimeout(O),O=null),t(Te)||(Mo()?$o():Ur())},Ke=ge=>{O&&(clearTimeout(O),O=null),document.visibilityState!=="hidden"&&!t(Te)&&(Mo()?$o():Ur())};return document.addEventListener("visibilitychange",_e),window.addEventListener("pageshow",Ke),()=>{window.removeEventListener("hashchange",R),document.removeEventListener("visibilitychange",_e),window.removeEventListener("pageshow",Ke),O&&clearTimeout(O)}});function Xe(){Ur()}function bt(){lr(),_s()}function at(){_s(),setTimeout(()=>Ur(),100)}function Ut(){bs()}function je(){typeof window<"u"&&(window.location.hash=""),lr(),h(xe,!1)}let Te=F(r),Me=F(s),Ct=F(o),hn=F(a),it=F(i),gt=F(c),Ne=F(v),Lt=F(g),qt=F(m),Re=F(x),Ht=F(k),Ee=F(()=>$().models),ne=U(!1),se=F(()=>t(Re).sessionId);$t(()=>{typeof window<"u"&&t(Te)&&(t(se)?(window.location.hash=encodeURIComponent(t(se)),h(ne,!0)):t(ne)&&(h(ne,!1),window.location.hash&&(window.location.hash="")))});let We=null;$t(()=>{if(!t(Te)||typeof window>"u"||!window.location.hash)return;const R=decodeURIComponent(window.location.hash.slice(1));R&&(t(se)===R||t(hn)||t(Me)||We||(We=setTimeout(()=>{We=null,!(t(se)===R||t(hn)||t(Me))&&Zi(R)},300)))}),$t(()=>{t(Te)||h(ne,!1)}),$t(()=>{(t(se)||t(hn)||t(Me))&&h(xe,!1)});let qe=F(L),j=F(H),Qe=U(void 0),Z=F(()=>Kb({connected:t(Te),searchConfigured:!!t(j),hasSession:!!t(Re).sessionFile,loading:t(hn),resyncing:t(Me),hasSessionHash:typeof window<"u"&&!!window.location.hash})),en=F(()=>t(Ee).map(R=>({value:`${R.provider}:${R.modelId}`,label:`${R.label}${R.isDefault?" (default)":""}`}))),et=F(ye),S=U("");$t(()=>{if(t(en).length===0||t(en).some(_e=>_e.value===t(S)))return;const O=t(en).find(_e=>_e.value===t(et)),oe=t(Ee).find(_e=>_e.isDefault);h(S,O?O.value:oe?`${oe.provider}:${oe.modelId}`:t(en)[0].value,!0)});let X=U(!1);$t(()=>{t(Z)&&!t(X)&&t(Qe)&&(h(X,!0),t(Qe).focusInput())});function q(){typeof window<"u"&&window.location.hash&&(window.location.hash=""),lr(),t(Qe)?.focusInput()}var T=Iv(),G=Jt(T);Rc(G,{title:"Wherever",description:"Create & maintain apps from wherever"});var be=f(G,2);{var ue=R=>{var O=Vb();p(R,O)};y(be,R=>{t(qe)&&R(ue)})}var we=f(be,2),ke=d(we),ve=d(ke),tt=d(ve),st=d(tt);{var mt=R=>{var O=Yb(),oe=f(Jt(O),2);D("click",oe,()=>h(ot,!1)),p(R,O)},nt=R=>{var O=Xb(),oe=Jt(O),_e=d(oe);rt(2),l(oe);var Ke=f(oe,2),ge=d(Ke),ie=f(ge,2);l(Ke),I(ze=>Y(_e,"src",ze),[()=>Vr("/logo.svg")]),D("click",oe,je),D("click",ge,()=>h(ot,!0)),D("click",ie,()=>h(xe,!1)),p(R,O)};y(st,R=>{t(ot)?R(mt):R(nt,-1)})}l(tt),l(ve);var Rt=f(ve,2);{var gn=R=>{var O=Zb(),oe=d(O);{let Be=F(()=>(t(Ht).connected,"localhost"));Ad(oe,{get host(){return t(Be)},port:31415,token:"",onConnected:Xe})}var _e=f(oe,2),Ke=f(d(_e),2),ge=d(Ke),ie=f(ge,2),ze=f(ie,2);l(Ke),l(_e),l(O),D("click",ge,Ut),D("click",ie,at),D("click",ze,bt),p(R,O)},xt=R=>{var O=av(),oe=Jt(O),_e=d(oe),Ke=d(_e),ge=f(Ke,2),ie=d(ge,!0);l(ge);var ze=f(ge,2),Be=d(ze),Bt=f(Be);{var Gt=C=>{var W=Qb(),me=d(W);l(W),I(()=>N(me,` / srv ${t(Ht).serverVersion??""}`)),p(C,W)};y(Bt,C=>{t(Ht).serverVersion&&C(Gt)})}l(ze),l(_e);var xn=f(_e,2);{var te=C=>{var W=tv(),me=d(W);{var kt=Et=>{var M=Jb(),u=d(M);l(M),I(_=>{Y(M,"title",t(Re).cwd),N(u,`📁 ${_??""}`)},[()=>t(Re).cwd.split("/").pop()||t(Re).cwd]),p(Et,M)};y(me,Et=>{t(Re).cwd&&Et(kt)})}var Xt=f(me,2);{var w=Et=>{var M=ev(),u=d(M);l(M),I(()=>{Y(M,"title",t(Re).model),N(u,`🤖 ${t(Re).model??""}`)}),p(Et,M)};y(Xt,Et=>{t(Re).model&&Et(w)})}var Fe=f(Xt,2),Ot=d(Fe);l(Fe),l(W),D("click",Ot,je),p(C,W)};y(xn,C=>{t(Re).sessionFile&&C(te)})}var Ie=f(xn,2);{var Le=C=>{var W=nv(),me=d(W,!0);l(W),I(()=>N(me,t(Ht).error)),p(C,W)};y(Ie,C=>{t(Ht).error&&!t(Te)&&C(Le)})}l(oe);var Ve=f(oe,2),ct=d(Ve);{var dt=C=>{var W=rv(),me=Jt(W),kt=f(me,2);D("click",me,()=>V(!1)),D("click",kt,()=>{h(ae,"readonly"),yi()}),p(C,W)},wt=C=>{var W=sv(),me=f(d(W),2),kt=d(me);l(me),l(W),I(()=>N(kt,`Back to ${t(Se)?"read-only sessions":"sessions"}`)),D("click",W,()=>h(ae,t(Se)?"readonly":"main",!0)),p(C,W)},bn=C=>{var W=ov(),me=Jt(W),kt=f(me,2);D("click",me,()=>h(ae,"main")),D("click",kt,()=>V(!0)),p(C,W)};y(ct,C=>{t(ae)==="main"?C(dt):t(ae)==="search"?C(wt,1):C(bn,-1)})}l(Ve);var vn=f(Ve,2),_n=d(vn);{var yn=C=>{jb(C,{get readOnly(){return t(Se)},get initialQuery(){return t(he)},onOpened:()=>h(xe,!1)})},er=C=>{ci(C,{readOnly:!0,onSearchAll:W=>V(!0,W)})},E=C=>{ci(C,{onSearchAll:W=>V(!1,W)})};y(_n,C=>{t(ae)==="search"?C(yn):t(ae)==="readonly"?C(er,1):C(E,-1)})}l(vn),I(()=>{un(Ke,1,`h-2.5 w-2.5 rounded-full ${t(Te)?"bg-emerald-500":"bg-rose-500"}`),un(ge,1,`text-sm ${t(Te)?"text-emerald-400":"text-rose-400"}`),N(ie,t(Te)?"Connected":"Disconnected"),Y(ze,"title",t(Ht).serverVersion?`App build ${Ds} · server ${t(Ht).serverVersion}`:`App build ${Ds}`),N(Be,`v${Ds}`)}),p(R,O)};y(Rt,R=>{t(ot)?R(gn):R(xt,-1)})}l(ke);var ft=f(ke,2),ln=d(ft),Kt=d(ln),Tn=f(Kt,2);{var En=R=>{var O=iv();D("click",O,q),p(R,O)};y(Tn,R=>{t(Te)&&t(j)&&t(Re).sessionFile&&R(En)})}var De=f(Tn,2);{var vt=R=>{var O=uv(),oe=d(O);{var _e=ie=>{var ze=lv();p(ie,ze)},Ke=ie=>{var ze=cv();p(ie,ze)},ge=ie=>{var ze=dv();p(ie,ze)};y(oe,ie=>{t(Te)&&t(Z)?ie(_e):t(Te)?ie(Ke,1):ie(ge,-1)})}l(O),p(R,O)};y(De,R=>{(!t(Te)||!t(Re).sessionFile)&&R(vt)})}var Vt=f(De,2);{var An=R=>{var O=gv(),oe=d(O);{var _e=ie=>{var ze=fv(),Be=f(d(ze),2),Bt=d(Be,!0);l(Be),l(ze),I(Gt=>{Y(Be,"title",t(Re).cwd),N(Bt,Gt)},[()=>t(Re).cwd.split("/").pop()||t(Re).cwd]),p(ie,ze)};y(oe,ie=>{t(Re).cwd&&ie(_e)})}var Ke=f(oe,2);{var ge=ie=>{var ze=vv(),Be=d(ze),Bt=f(d(Be),2);l(Be);var Gt=f(Be,2);{var xn=Ie=>{var Le=hv();$n(Le,21,()=>t(Ee),tr,(ct,dt)=>{var wt=pv(),bn=d(wt,!0);l(wt);var vn={};I(()=>{N(bn,t(dt).label),vn!==(vn=`${t(dt).provider}:${t(dt).modelId}`)&&(wt.value=wt.__value=`${t(dt).provider}:${t(dt).modelId}`)}),p(ct,wt)}),l(Le);var Ve;mi(Le),I(()=>{Ve!==(Ve=t(Re).model)&&(Le.value=(Le.__value=t(Re).model)??"",Wo(Le,t(Re).model))}),D("input",Le,ct=>il(ct.currentTarget.value)),p(Ie,Le)},te=Ie=>{var Le=bv(),Ve=d(Le,!0);l(Le),I(()=>{Y(Le,"title",t(Re).model),N(Ve,t(Re).model)}),p(Ie,Le)};y(Gt,Ie=>{t(Ee).length>0&&!t(qt)?Ie(xn):Ie(te,-1)})}l(ze),I(()=>{un(Bt,1,`absolute -right-0.5 -bottom-0.5 h-2 w-2 rounded-full border border-brand-surface ${t(Ht).isStreaming?"animate-pulse bg-orange-500":"bg-emerald-500"}`),Y(Bt,"title",t(Ht).isStreaming?"Agent working...":"Ready")}),p(ie,ze)};y(Ke,ie=>{t(Re).model&&ie(ge)})}l(O),p(R,O)};y(Vt,R=>{t(Re).sessionFile&&R(An)})}var Ln=f(Vt,2);{var tn=R=>{var O=mv();p(R,O)};y(Ln,R=>{t(qt)&&R(tn)})}l(ln);var nn=f(ln,2);{var jt=R=>{var O=xv();p(R,O)};y(nn,R=>{t(it)&&R(jt)})}var Cn=f(nn,2);{var le=R=>{var O=_v(),oe=d(O),_e=d(oe,!0);l(oe);var Ke=f(oe,2);l(O),I(()=>{un(O,1,`flex items-start justify-between gap-2 border px-4 py-2 text-sm ${t(Ne).level==="warning"?"border-yellow-500/30 bg-yellow-500/10 text-yellow-400":"border-blue-500/30 bg-blue-500/10 text-blue-400"}`),N(_e,t(Ne).message)}),D("click",Ke,()=>sl()),p(R,O)};y(Cn,R=>{t(Ne)&&R(le)})}var A=f(Cn,2);{var z=R=>{var O=wv(),oe=d(O),_e=f(d(oe));{var Ke=Be=>{var Bt=Bn("You are both working in it — changes may conflict.");p(Be,Bt)},ge=Be=>{var Bt=Bn("You are observing (read-only) to avoid clashing.");p(Be,Bt)};y(_e,Be=>{t(Lt).continued?Be(Ke):Be(ge,-1)})}l(oe);var ie=f(oe,2);{var ze=Be=>{var Bt=yv();D("click",Bt,()=>tl()),p(Be,Bt)};y(ie,Be=>{t(Lt).continued||Be(ze)})}l(O),p(R,O)};y(A,R=>{t(Lt)?.active&&R(z)})}var K=f(A,2);{var re=R=>{var O=kv(),oe=d(O),_e=d(oe,!0);l(oe);var Ke=f(oe,2);l(O),I(()=>N(_e,t(gt))),D("click",Ke,()=>Ir()),p(R,O)};y(K,R=>{t(gt)&&R(re)})}var fe=f(K,2);{var Pt=R=>{var O=Sv();p(R,O)};y(fe,R=>{t(qt)&&!t(it)&&!(t(Lt)?.active&&!t(Lt).continued)&&R(Pt)})}var Nt=f(fe,2);nr(rh(Nt,{onMessageSent:()=>{}}),R=>Mt=R,()=>Mt);var Yt=f(Nt,2);{var rn=R=>{var O=Tv();p(R,O)},sn=R=>{var O=Rv(),oe=Jt(O);{var _e=ie=>{var ze=Av();p(ie,ze)},Ke=ie=>{var ze=Cv();p(ie,ze)};y(oe,ie=>{t(Re).sessionFile&&(t(Me)||!t(Te))?ie(_e):t(Re).sessionFile&&t(Ct)&&ie(Ke,1)})}var ge=f(oe,2);{let ie=F(()=>!!t(j)),ze=F(()=>t(Z)?!t(Te):!t(Te)||t(qt)||!t(Re).sessionFile||t(Me)||t(Ct));nr(Ph(ge,{get searchMode(){return t(Z)},get searchConfigured(){return t(ie)},get searchModels(){return t(en)},onSubmit:(Be,Bt)=>Ji(Be,t(S),Bt),placeholder:"Search the web...",submitLabel:"Search",get disabled(){return t(ze)},onSend:()=>Mt?.forceScrollToBottom(),get searchModel(){return t(S)},set searchModel(Be){h(S,Be,!0)}}),Be=>h(Qe,Be,!0),()=>t(Qe))}p(R,O)};y(Yt,R=>{t(qt)&&t(Re).sessionFile?R(rn):R(sn,-1)})}l(ft);var on=f(ft,2);Gb(on,{});var Wt=f(on,2);{var lt=R=>{var O=Ev();D("click",O,()=>h(xe,!1)),p(R,O)};y(Wt,R=>{t(xe)&&R(lt)})}l(we),I(()=>un(ke,1,`app-chrome ${t(xe)?"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`)),D("click",Kt,()=>h(xe,!t(xe))),p(n,T),Ar(),de()}Lr(["click","input"]);export{Uv as component,Fv as universal};
|
|
104
|
-
//# sourceMappingURL=2.
|
|
104
|
+
//# sourceMappingURL=2.BWbDsdRU.js.map
|