wherever-dev 0.6.1 → 0.6.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.
Files changed (25) hide show
  1. package/package.json +1 -1
  2. package/public/_app/immutable/assets/{0.C2Vl85yD.css → 0.CbRAwd0M.css} +1 -1
  3. package/public/_app/immutable/chunks/{C2oprduI.js → Bn3ighFw.js} +2 -2
  4. package/public/_app/immutable/chunks/{C2oprduI.js.map → Bn3ighFw.js.map} +1 -1
  5. package/public/_app/immutable/chunks/{DXvc7DJA.js → DtEGJeyB.js} +2 -2
  6. package/public/_app/immutable/chunks/{DXvc7DJA.js.map → DtEGJeyB.js.map} +1 -1
  7. package/public/_app/immutable/chunks/{BxDc2a9S.js → Dwvtln8S.js} +2 -2
  8. package/public/_app/immutable/chunks/{BxDc2a9S.js.map → Dwvtln8S.js.map} +1 -1
  9. package/public/_app/immutable/entry/{app.yrkydP4x.js → app.5x6-QYdD.js} +3 -3
  10. package/public/_app/immutable/entry/{app.yrkydP4x.js.map → app.5x6-QYdD.js.map} +1 -1
  11. package/public/_app/immutable/entry/start.CJPjsQpp.js +2 -0
  12. package/public/_app/immutable/entry/start.CJPjsQpp.js.map +1 -0
  13. package/public/_app/immutable/nodes/{0.BR2ysPfV.js → 0.BaCrnkif.js} +2 -2
  14. package/public/_app/immutable/nodes/{0.BR2ysPfV.js.map → 0.BaCrnkif.js.map} +1 -1
  15. package/public/_app/immutable/nodes/{1.D4O7RJRM.js → 1.DvIJ6W8S.js} +2 -2
  16. package/public/_app/immutable/nodes/{1.D4O7RJRM.js.map → 1.DvIJ6W8S.js.map} +1 -1
  17. package/public/_app/immutable/nodes/2.AnNiHhvN.js +88 -0
  18. package/public/_app/immutable/nodes/2.AnNiHhvN.js.map +1 -0
  19. package/public/_app/version.json +1 -1
  20. package/public/index.html +11 -11
  21. package/public/service-worker.js +1 -1
  22. package/public/_app/immutable/entry/start.BoFs4n_B.js +0 -2
  23. package/public/_app/immutable/entry/start.BoFs4n_B.js.map +0 -1
  24. package/public/_app/immutable/nodes/2.CkE0xTRs.js +0 -87
  25. package/public/_app/immutable/nodes/2.CkE0xTRs.js.map +0 -1
@@ -1,87 +0,0 @@
1
- import{b as ns,a as h,c as dr,g as m,d as tr,e as B,f as qn,s as re,t as _n}from"../chunks/vMsF8lo6.js";import{ar as yn,b2 as Wr,al as ir,be as H,ap as eo,M as Ua,aS as za,aq as bs,d as Oo,am as vs,at as Ba,n as Ha,a0 as Wa,u as Ga,t as ja,a1 as qa,V as Va,W as Ka,H as Ya,b3 as to,C as no,aE as Kr,a2 as Wn,ac as Za,az as Xa,aZ as Qa,ay as Do,bd as Lo,bf as Ja,bg as $s,aU as Ms,aQ as ro,aP as Vn,aM as Kn,af as Zt,b6 as f,ai as t,a5 as ei,bh as Q,$ as ti,bl as An,ah as Fn,a8 as jt,aK as Mr,a_ as p,X as u,aV as d,aI as dt,b9 as V,aO as wn,bi as Lt,bj as ni,aT as ri}from"../chunks/CEg8tgYI.js";import{i as E,s as pr,a as Ue,p as Xn}from"../chunks/MtE7VtNZ.js";import{a as si,b as Fe,r as it,c as Po,e as gn,i as Sn,d as oi}from"../chunks/DXvc7DJA.js";import{_ as ai,b as Nn}from"../chunks/ylfInSZr.js";import{v as No}from"../chunks/BxDc2a9S.js";import{p as ii}from"../chunks/C2oprduI.js";function li(n,e,r=!1,s=!1,o=!1,a=!1){var i=n,c="";if(r){var _=n;yn&&(i=Wr(ir(_)))}H(()=>{var b=Ua;if(c===(c=e()??"")){yn&&eo();return}if(r&&!yn){b.nodes=null,_.innerHTML=c,c!==""&&ns(ir(_),_.lastChild);return}if(b.nodes!==null&&(za(b.nodes.start,b.nodes.end),b.nodes=null),c!==""){if(yn){bs.data;for(var v=eo(),A=v;v!==null&&(v.nodeType!==Oo||v.data!=="");)A=v,v=vs(v);if(v===null)throw Ba(),Ha;ns(bs,A),i=Wr(v);return}var $=s?Ga:o?ja:void 0,O=Wa(s?"svg":o?"math":"template",$);O.innerHTML=c;var k=s||o?O:O.content;if(ns(ir(k),k.lastChild),s||o)for(;ir(k);)i.before(ir(k));else i.before(k)}})}function ci(n,e){let r=null,s=yn;var o;if(yn){r=bs;for(var a=ir(document.head);a!==null&&(a.nodeType!==Oo||a.data!==n);)a=vs(a);if(a===null)to(!1);else{var i=vs(a);a.remove(),Wr(i)}}yn||(o=document.head.appendChild(qa()));try{Va(()=>{var c=Ka(()=>e(o));c.f|=Ya})}finally{s&&(to(!0),Wr(r))}}function Fo(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=Fo(n[e]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function di(){for(var n,e,r=0,s="",o=arguments.length;r<o;r++)(n=arguments[r])&&(e=Fo(n))&&(s&&(s+=" "),s+=e);return s}function ui(n){return typeof n=="object"?di(n):n??""}function fi(n,e,r){var s=n==null?"":""+n;return s===""?null:s}function Yt(n,e,r,s,o,a){var i=n[no];if(yn||i!==r||i===void 0){var c=fi(r);(!yn||c!==n.getAttribute("class"))&&(c==null?n.removeAttribute("class"):e?n.className=c:n.setAttribute("class",c)),n[no]=r}return a}function Os(n,e,r=!1){if(n.multiple){if(e==null)return;if(!Xa(e))return Qa();for(var s of n.options)s.selected=e.includes(Ar(s));return}for(s of n.options){var o=Ar(s);if(Do(o,e)){s.selected=!0;return}}(!r||e!==void 0)&&(n.selectedIndex=-1)}function Uo(n){var e=new MutationObserver(()=>{Os(n,n.__value)});e.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),Lo(()=>{e.disconnect()})}function Ir(n,e,r=e){var s=new WeakSet,o=!0;Kr(n,"change",a=>{var i=a?"[selected]":":checked",c;if(n.multiple)c=[].map.call(n.querySelectorAll(i),Ar);else{var _=n.querySelector(i)??n.querySelector("option:not([disabled])");c=_&&Ar(_)}r(c),n.__value=c,Wn!==null&&s.add(Wn)}),Za(()=>{var a=e();if(n===document.activeElement){var i=Wn;if(s.has(i))return}if(Os(n,a,o),o&&a===void 0){var c=n.querySelector(":checked");c!==null&&(a=Ar(c),r(a))}n.__value=a,o=!1}),Uo(n)}function Ar(n){return"__value"in n?n.__value:n.value}function On(n,e,r=e){var s=new WeakSet;Kr(n,"input",async o=>{var a=o?n.defaultValue:n.value;if(a=ss(n)?os(a):a,r(a),Wn!==null&&s.add(Wn),await Ja(),a!==(a=e())){var i=n.selectionStart,c=n.selectionEnd,_=n.value.length;if(n.value=a??"",c!==null){var b=n.value.length;i===c&&c===_&&b>_?(n.selectionStart=b,n.selectionEnd=b):(n.selectionStart=i,n.selectionEnd=Math.min(c,b))}}}),(yn&&n.defaultValue!==n.value||$s(e)==null&&n.value)&&(r(ss(n)?os(n.value):n.value),Wn!==null&&s.add(Wn)),Ms(()=>{var o=e();if(n===document.activeElement){var a=Wn;if(s.has(a))return}ss(n)&&o===os(n.value)||n.type==="date"&&!o&&!n.value||o!==n.value&&(n.value=o??"")})}const rs=new Set;function jn(n,e,r,s,o=s){var a=r.getAttribute("type")==="checkbox",i=n;let c=!1;if(e!==null)for(var _ of e)i=i[_]??=[];i.push(r),Kr(r,"change",()=>{var b=r.__value;a&&(b=so(i,b,r.checked)),o(b)},()=>o(a?[]:null)),Ms(()=>{var b=s();if(yn&&r.defaultChecked!==r.checked){c=!0;return}a?(b=b||[],r.checked=b.includes(r.__value)):r.checked=Do(r.__value,b)}),Lo(()=>{var b=i.indexOf(r);b!==-1&&i.splice(b,1)}),rs.has(i)||(rs.add(i),ro(()=>{i.sort((b,v)=>b.compareDocumentPosition(v)===4?-1:1),rs.delete(i)})),ro(()=>{if(c){var b;if(a)b=so(i,b,r.checked);else{var v=i.find(A=>A.checked);b=v?.__value}o(b)}})}function Tn(n,e,r=e){Kr(n,"change",s=>{var o=s?n.defaultChecked:n.checked;r(o)}),(yn&&n.defaultChecked!==n.checked||$s(e)==null)&&r(n.checked),Ms(()=>{var s=e();n.checked=!!s})}function so(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 ss(n){var e=n.type;return e==="number"||e==="range"}function os(n){return n===""?null:+n}const pi=!1,hi=!0,xf=Object.freeze(Object.defineProperty({__proto__:null,prerender:hi,ssr:pi},Symbol.toStringTag,{value:"Module"})),as="Wherever",bi="Create & maintain apps from wherever with a beautiful remote workspace.",is="https://localhost",vi="#000000",gi="black-translucent";function cr(n,e){return si(n)}var mi=m('<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 xi(n,e){Vn(e,!0);const r=is.endsWith("/")?is.slice(0,-1):is,s=r+"/preview.png";let o=Q(()=>e.home||!1),a=Q(()=>({type:e.type||"website",title:e.title||as,description:e.description||bi,image:e.image||s,url:`${r}${ii.url.pathname}`}));ci("13n5pl5",i=>{var c=mi(),_=Zt(c),b=f(_,2),v=f(b,2);{var A=ot=>{var Je=dr(),et=Zt(Je);E(et,Mt=>{}),h(ot,Je)};E(v,ot=>{t(o)&&ot(A)})}var $=f(v,2),O=f($,2),k=f(O,2),ae=f(k,2),se=f(ae,2),he=f(se,4),ie=f(he,2),rt=f(ie,2),Me=f(rt,2),Ge=f(Me,2),le=f(Ge,2),Pe=f(le,2),st=f(Pe,2),Ct=f(st,2),at=f(Ct,4),be=f(at,4),je=f(be,2),_t=f(je,2);H((ot,Je,et,Mt)=>{Fe(_,"content",t(a).title),Fe(b,"content",t(a).description),Fe($,"content",t(a).type),Fe(O,"content",t(a).url),Fe(k,"content",t(a).title),Fe(ae,"content",t(a).description),Fe(se,"content",t(a).image),Fe(he,"content",t(a).url),Fe(ie,"content",t(a).title),Fe(rt,"content",t(a).description),Fe(Me,"content",t(a).image),Fe(Ge,"href",ot),Fe(le,"href",Je),Fe(Pe,"href",et),Fe(st,"href",Mt),Fe(Ct,"content",vi),Fe(at,"content",as),Fe(be,"content",gi),Fe(je,"content",as),Fe(_t,"content",No)},[()=>cr("/pwa/favicon.png"),()=>cr("/pwa/favicon.ico"),()=>cr("/pwa/apple-touch-icon.png"),()=>cr("/pwa/manifest.webmanifest")]),ei(()=>{ti.title=t(a).title??""}),h(i,c)}),Kn()}let br=null;function _i(){if(typeof window>"u")return null;try{if(!br){const n=window.AudioContext||window.webkitAudioContext;if(!n)return null;br=new n}return br.state==="suspended"&&br.resume().catch(()=>{}),br}catch{return null}}function oo(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 ao=new Map;function yi(n){if(typeof Audio>"u")return!1;try{let e=ao.get(n);e||(e=new Audio(n),e.preload="auto",ao.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 zo(n){if(n&&n.trim()&&yi(n.trim()))return;const e=_i();if(e)try{const r=e.currentTime;oo(e,1046.5,r,.16,.12),oo(e,1396.9,r+.13,.22,.12)}catch{}}function zr(){}function wi(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function ki(n,...e){if(n==null)return zr;const r=n.subscribe(...e);return r.unsubscribe?()=>r.unsubscribe():r}function Jt(n){let e;return ki(n,r=>e=r)(),e}var or=[];function Si(n,e=zr){let r;const s=new Set;function o(c){if(wi(n,c)&&(n=c,r)){const _=!or.length;for(const b of s)b[1](),or.push(b,n);if(_){for(let b=0;b<or.length;b+=2)or[b][0](or[b+1]);or.length=0}}}function a(c){o(c(n))}function i(c,_=zr){const b=[c,_];return s.add(b),s.size===1&&(r=e(o)||zr),c(n),()=>{s.delete(b),s.size===0&&(r(),r=null)}}return{set:o,update:a,subscribe:i}}const ls={connected:!1,connecting:!1,creatingSession:!1,loadingSession:!1,resyncing:!1,agentPending:!1,error:null,session:null,sessionId:null,isStreaming:!1,messages:[],clientId:null,conflict:null,isInterrupted:!1,notice:null,sessionError:null,readOnly:!1,activeSessionFile:null,activeCwd:null,activeModel:null,hideThinking:!1,hideTools:!1,historyTotalCount:0,historyOffset:0,loadingMoreHistory:!1,contextUsage:null};class $n{ws=null;config;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;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;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.stateStore=Si({...ls,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}connect(e,r=!1){e&&(this.config={...this.config,...e}),this.disconnect(!1),this.stateStore.update(O=>r?{...O,connecting:!0,error:null}:{...ls,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?`?token=${encodeURIComponent(this.config.token)}`:"",i=`${s}://${o}:${this.config.port}/ws${a}`,c=this.config.WebSocketCtor||(typeof globalThis<"u"?globalThis.WebSocket:null);if(!c){this.stateStore.update(O=>({...O,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}try{const O=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=O?new c(i,O):new c(i)}catch(O){this.stateStore.update(k=>({...k,connecting:!1,error:`Failed to connect: ${O}`})),this.scheduleReconnect();return}const _=this.ws,b=()=>{if(this.ws!==_)return;this.isInitialConnect||console.info("[wherever] reconnected to relay"),this.reconnectAttempts=0,this.reconnectDelay=2e3,this.isInitialConnect=!1,this.startLivenessWatchdog(),this.stateStore.update(he=>({...he,connected:!0,connecting:!1,error:null}));const O=Jt(this.stateStore),k=this.resumeSessionFile??O.activeSessionFile,ae=this.resumeSessionFile!=null?this.resumeCwd:O.activeCwd??void 0,se=this.resumeSessionFile!=null?this.resumeModel:O.activeModel??void 0;this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,k?(this.stateStore.update(he=>he.resyncing?he:{...he,resyncing:!0}),this.send({type:"session_load",sessionFile:k,cwd:ae,model:se}),this.armLoadWatchdog()):this.stateStore.update(he=>he.resyncing?{...he,resyncing:!1}:he)},v=O=>{if(this.ws===_){this.lastInboundAt=Date.now();try{const k=typeof O.data=="string"?O.data:O.data.toString(),ae=JSON.parse(k);this.handleMessage(ae)}catch(k){console.error("Failed to parse WebSocket message:",k)}}},A=()=>{this.ws===_&&(this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.ws=null,this.stateStore.update(O=>({...O,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:O.activeSessionFile?!0:O.resyncing})),this.scheduleReconnect())},$=O=>{this.ws===_&&this.stateStore.update(k=>({...k,error:k.error||"Connection error occurred"}))};typeof _.addEventListener=="function"?(_.addEventListener("open",b),_.addEventListener("message",v),_.addEventListener("close",A),_.addEventListener("error",$)):typeof _.on=="function"&&(_.on("open",b),_.on("message",O=>v({data:O})),_.on("close",A),_.on("error",$))}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){try{typeof this.ws.removeAllListeners=="function"&&this.ws.removeAllListeners(),this.ws.close()}catch{}this.ws=null}if(e){for(const r of this.confirmTimers.values())clearTimeout(r);this.confirmTimers.clear(),this.stateStore.set({...ls,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=Jt(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=Jt(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||Jt(this.stateStore).activeSessionFile!==null}startLivenessWatchdog(){this.stopLivenessWatchdog(),this.lastInboundAt=Date.now();const e=()=>{try{this.ping()}catch{}};typeof setInterval=="function"&&(this.heartbeatTimer=setInterval(e,$n.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=Jt(this.stateStore).isStreaming,a=o?$n.TURN_STALL_MS:$n.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,$n.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=Jt(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."})))},$n.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."})))},$n.CREATE_WATCHDOG_MS)}clearCreateWatchdog(){this.createWatchdog&&(clearTimeout(this.createWatchdog),this.createWatchdog=null)}scheduleReconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*1.5,this.maxReconnectDelay),console.info(`[wherever] reconnecting to relay (attempt ${++this.reconnectAttempts})`);const e=!!Jt(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":case"session_error":case"session_conflict":case"session_destroyed":case"session_interrupted":this.clearLoadWatchdog();break}switch(e.type){case"session_created":case"session_error":case"session_conflict":case"session_interrupted":this.clearCreateWatchdog();break}switch(e.type){case"connected":this.stateStore.update(s=>({...s,connected:!0,connecting:!1,clientId:e.clientId,error:null}));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_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"&&this.confirmDeliveredByContent(e.content))return Jt(this.stateStore);const c=[...o].reverse().find(b=>b.role==="user");e.role==="user"&&c&&c.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,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(c=>c.isStreaming&&(c.role==="assistant"||c.role==="thinking")?{...c,isStreaming:!1}:c),a=Date.now(),i={id:this.generateId(),role:"tool",content:r?`$ ${e.toolName} ${r}`:`$ ${e.toolName}`,timestamp:a,isStreaming:!0,toolName:e.toolName,toolArgs:r,toolOutput:"",startedAt:a};return{...s,messages:[...o,i]}});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
- `)?a.content+e.delta:`${a.content}
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 _=c.messages.find(v=>v.role==="tool"&&v.toolName===e.toolName&&v.isStreaming)??[...c.messages].reverse().find(v=>v.role==="tool"&&v.toolName===e.toolName&&!v.content.startsWith("Tool error:")),b=Date.now();if(_){const v=a?"Error: ":"";return{...c,messages:c.messages.map(A=>A.id===_.id?{...A,content:`${v}${A.content}
4
- ${s}`,isStreaming:!1,isError:a,interrupted:o,toolOutput:s,...i?{images:i}:{},endedAt:b}:A)}}else{const v=a?`Tool error: ${e.toolName}
5
- ${s}`:`${e.toolName}
6
- ${s}`,A={id:this.generateId(),role:"tool",content:v,timestamp:b,isStreaming:!1,toolName:e.toolName,toolArgs:"",toolOutput:s,...i?{images:i}:{},isError:a,interrupted:o,endedAt:b};return{...c,messages:[...c.messages,A]}}});break}case"aborted":{const s=Date.now();this.stateStore.update(o=>({...o,isStreaming:!1,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)}));break}case"session_created":this.stateStore.update(s=>({...s,session:e.sessionFile,sessionId:e.sessionId,activeSessionFile:e.sessionFile,activeCwd:e.cwd,activeModel:e.model,isStreaming:e.isStreaming??!1,creatingSession:!1,readOnly:e.readOnly??!1,agentPending:e.pending===!0,contextUsage:e.contextUsage??null}));break;case"session_ready":this.stateStore.update(s=>e.sessionFile&&s.activeSessionFile&&e.sessionFile!==s.activeSessionFile?s:{...s,agentPending:!1,activeModel:e.model??s.activeModel,isStreaming:e.isStreaming??s.isStreaming,contextUsage:e.contextUsage??s.contextUsage});break;case"context_usage":this.stateStore.update(s=>({...s,contextUsage:e.contextUsage??null}));break;case"session_notice":this.stateStore.update(s=>s.sessionId&&e.sessionId&&s.sessionId!==e.sessionId?s:{...s,notice:{level:e.level,message:e.message}});break;case"session_destroyed":this.stateStore.update(s=>s.sessionId===e.sessionId?{...s,messages:[],session:null,sessionId:null,activeSessionFile:null,activeCwd:null,activeModel:null,loadingSession:!1,agentPending:!1,notice:null}:s);break;case"session_error":this.stateStore.update(s=>({...s,sessionError:e.error,isStreaming:!1,creatingSession:!1,loadingSession:!1,resyncing:!1,agentPending:!1}));break;case"session_conflict":this.stateStore.update(s=>({...s,conflict:{targetSessionId:e.sessionId,conflictingSessionId:e.conflictingSession,conflictingCwd:e.conflictingCwd},creatingSession:!1,loadingSession:!1,resyncing:!1,agentPending:!1}));break;case"session_interrupted":this.stateStore.update(s=>({...s,isInterrupted:!0,readOnly:!0,messages:[],session:null,sessionId:null,activeSessionFile:null,activeCwd:null,activeModel:null,creatingSession:!1,loadingSession:!1,agentPending:!1,notice:null}));break;case"message_history":{const s=e.sessionId,o=Jt(this.stateStore).messages.filter(c=>c.role==="user"&&c.delivery!==void 0),i=[...this.loadPersistedPending(s),...o];this.stateStore.update(c=>{const _=this.mapHistory(e.messages,e.sessionId,c.isStreaming),b=typeof e.totalCount=="number"?e.totalCount:_.length,v=typeof e.offset=="number"?e.offset:0,A=new Set(_.filter(k=>k.role==="user").map(k=>k.content)),$=new Set,O=[];for(const k of i)A.has(k.content)||$.has(k.content)||($.add(k.content),O.push({...k,sessionId:s,delivery:"failed"}));return{...c,messages:[..._,...O],historyTotalCount:b,historyOffset:v,loadingMoreHistory:!1,loadingSession:!1,resyncing:!1}});for(const c of i)this.clearConfirm(c.id);this.persistPending(s);break}case"message_history_prepend":this.stateStore.update(s=>{const o=this.mapHistory(e.messages,e.sessionId,!1),a=typeof e.offset=="number"?e.offset:0;return o.length===0?{...s,loadingMoreHistory:!1,historyOffset:a}:{...s,messages:[...o,...s.messages],historyOffset:a,loadingMoreHistory:!1}});break;case"model_changed":this.stateStore.update(s=>({...s,activeModel:e.model}));break}}isAbortedToolResult(e){if(!e)return!1;const r=e.trimEnd().split(`
7
- `),s=(r[r.length-1]||"").trim();return/^(command|operation)?\s*aborted$/i.test(s)}mapHistory(e,r,s){const o=[],a={},i={},c=(v,A)=>{const $=a[v];if(!$)return;const O=$.indexOf(A);O!==-1&&$.splice(O,1)};for(const v of e)if(v.role==="tool_call"){const A=v.toolName||"unknown",$=v.content||"",O=o.length;o.push({id:this.generateId(),role:"tool",content:$?`$ ${A} ${$}`:`$ ${A}`,timestamp:v.timestamp,isStreaming:!1,toolName:A,toolArgs:$,toolOutput:"",sessionId:r,...Number.isFinite(v.timestamp)?{startedAt:v.timestamp}:{}}),a[A]||(a[A]=[]),a[A].push(O),typeof v.toolCallId=="string"&&v.toolCallId&&(i[v.toolCallId]=O)}else if(v.role==="tool_result"){const A=v.toolName||"unknown";let $;if(typeof v.toolCallId=="string"&&v.toolCallId&&i[v.toolCallId]!==void 0)$=i[v.toolCallId],delete i[v.toolCallId],c(A,$);else if(a[A]&&a[A].length>0){$=a[A].shift();for(const[ae,se]of Object.entries(i))se===$&&delete i[ae]}const O=v.isError&&!this.isAbortedToolResult(v.content),k=!!v.isError&&this.isAbortedToolResult(v.content);if($!==void 0){const ae=o[$],se=ae.toolArgs||"",he=ae.startedAt;o[$]={...ae,content:se?`$ ${A} ${se}
8
- ${v.content}`:`$ ${A}
9
- ${v.content}`,isStreaming:!1,toolOutput:v.content,...Array.isArray(v.images)&&v.images.length>0?{images:v.images}:{},isError:O,interrupted:k,timestamp:v.timestamp,...he!==void 0&&Number.isFinite(he)&&Number.isFinite(v.timestamp)&&v.timestamp>=he?{endedAt:v.timestamp}:{}}}else o.push({id:this.generateId(),role:"tool",content:`$ ${A}
10
- ${v.content}`,timestamp:v.timestamp,isStreaming:!1,toolName:A,toolArgs:"",toolOutput:v.content,...Array.isArray(v.images)&&v.images.length>0?{images:v.images}:{},isError:O,interrupted:k,sessionId:r})}else o.push({id:this.generateId(),role:v.role,content:v.content,timestamp:v.timestamp,isStreaming:!1,toolName:v.toolName,sessionId:r});const _=[];for(const v of Object.values(a))_.push(...v);_.sort((v,A)=>v-A);const b=s&&_.length>0?_[_.length-1]:-1;for(const v of _)v===b?o[v]={...o[v],isStreaming:!0}:o[v]={...o[v],interrupted:!0};if(s&&o.length>0){const v=o.length-1,A=o[v];(A.role==="assistant"||A.role==="thinking")&&(o[v]={...A,isStreaming:!0})}return o}loadMoreHistory(){const e=Jt(this.stateStore);e.sessionId&&(e.loadingMoreHistory||e.historyOffset<=0||(this.stateStore.update(r=>({...r,loadingMoreHistory:!0})),this.send({type:"history_load_more",sessionId:e.sessionId,beforeOffset:e.historyOffset})))}send(e){if(this.ws&&this.ws.readyState===1)try{return this.ws.send(JSON.stringify(e)),!0}catch{return!1}return!1}sendMessage(e){const r=Jt(this.stateStore);if(!r.sessionId)return!1;if(r.agentPending)return this.stateStore.update(a=>({...a,sessionError:a.sessionError??"Preparing the session agent; please wait a moment, then resend."})),!1;if(!this.getIsConnected())return this.stateStore.update(a=>({...a,sessionError:"Not connected to the relay; your message was not sent. Reconnecting, then please resend."})),!this.ws&&!this.reconnectTimer&&this.scheduleReconnect(),!1;if(!this.send({type:"message",message:e,sessionId:r.sessionId}))return this.stateStore.update(a=>({...a,sessionError:"Message failed to send (connection dropped). Please resend once reconnected."})),!1;const o={id:this.generateId(),role:"user",content:e,timestamp:Date.now(),isStreaming:!1,sessionId:r.sessionId,delivery:"sending"};return this.stateStore.update(a=>({...a,sessionError:null,messages:[...a.messages,o]})),this.armConfirm(o.id),this.persistPending(r.sessionId),!0}pendingKey(e){return $n.PENDING_PREFIX+e}persistPending(e){if(!e||typeof localStorage>"u")return;const r=Jt(this.stateStore).messages.filter(s=>s.role==="user"&&s.delivery!==void 0);try{r.length===0?localStorage.removeItem(this.pendingKey(e)):localStorage.setItem(this.pendingKey(e),JSON.stringify(r.map(s=>({id:s.id,content:s.content,timestamp:s.timestamp,delivery:"failed"}))))}catch{}}loadPersistedPending(e){if(typeof localStorage>"u")return[];try{const r=localStorage.getItem(this.pendingKey(e));if(!r)return[];const s=JSON.parse(r);return Array.isArray(s)?s.filter(o=>o&&typeof o.content=="string").map(o=>({id:typeof o.id=="string"?o.id:this.generateId(),role:"user",content:o.content,timestamp:typeof o.timestamp=="number"?o.timestamp:Date.now(),isStreaming:!1,sessionId:e,delivery:"failed"})):[]}catch{return[]}}armConfirm(e){if(this.clearConfirm(e),typeof setTimeout!="function")return;const r=setTimeout(()=>{this.confirmTimers.delete(e);let s=null;this.stateStore.update(o=>{const a=o.messages.find(i=>i.id===e);return!a||a.delivery!=="sending"?o:(s=o.sessionId,{...o,messages:o.messages.map(i=>i.id===e?{...i,delivery:"failed"}:i)})}),s&&this.persistPending(s)},$n.CONFIRM_MS);r&&typeof r.unref=="function"&&r.unref(),this.confirmTimers.set(e,r)}clearConfirm(e){const r=this.confirmTimers.get(e);r&&(clearTimeout(r),this.confirmTimers.delete(e))}confirmDeliveredByContent(e){let r=null,s=null;return this.stateStore.update(o=>{const a=o.messages.find(i=>i.role==="user"&&i.delivery!==void 0&&i.content===e);return a?(r=a.id,s=o.sessionId,{...o,messages:o.messages.map(i=>i.id===a.id?{...i,delivery:void 0}:i)}):o}),r?(this.clearConfirm(r),this.persistPending(s),!0):!1}resendMessage(e){const r=Jt(this.stateStore),s=r.messages.find(a=>a.id===e&&a.role==="user");return!s||!r.sessionId?!1:this.getIsConnected()?this.send({type:"message",message:s.content,sessionId:r.sessionId})?(this.stateStore.update(a=>({...a,sessionError:null,messages:a.messages.map(i=>i.id===e?{...i,delivery:"sending",timestamp:Date.now()}:i)})),this.armConfirm(e),this.persistPending(r.sessionId),!0):!1:(!this.ws&&!this.reconnectTimer&&this.scheduleReconnect(),!1)}discardMessage(e){let r=null;this.clearConfirm(e),this.stateStore.update(s=>(r=s.sessionId,{...s,messages:s.messages.filter(o=>o.id!==e)})),r&&this.persistPending(r)}abort(){const e=Jt(this.stateStore);e.sessionId&&this.send({type:"abort",sessionId:e.sessionId})}joinSession(e,r,s){this.stateStore.update(o=>({...o,conflict:null,sessionError:null,loadingSession:!0,agentPending:!1})),this.send({type:"session_load",sessionFile:e,cwd:r,model:s}),this.armLoadWatchdog()}switchSession(e,r,s){const o=Jt(this.stateStore);o.activeSessionFile===e&&!o.loadingSession&&!o.resyncing||(o.sessionId&&this.send({type:"session_leave",sessionId:o.sessionId}),this.stateStore.update(a=>({...a,messages:[],session:null,sessionId:null,activeSessionFile:null,activeCwd:null,activeModel:null,readOnly:!1,conflict:null,sessionError:null,notice:null,creatingSession:!1,resyncing:!1,agentPending:!1,contextUsage:null,loadingSession:!0})),this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,this.clearCreateWatchdog(),this.send({type:"session_load",sessionFile:e,cwd:r,model:s}),this.armLoadWatchdog())}createSession(e,r,s,o,a){this.stateStore.update(i=>({...i,conflict:null,sessionError:null,creatingSession:!0,loadingSession:!1})),this.send({type:"session_new",cwd:e,model:r,gitInit:s,createRemote:o,repoVisibility:a}),this.armCreateWatchdog()}leaveSession(){const e=Jt(this.stateStore);if(this.clearCreateWatchdog(),!e.sessionId){e.creatingSession&&this.stateStore.update(r=>({...r,creatingSession:!1}));return}this.send({type:"session_leave",sessionId:e.sessionId}),this.stateStore.update(r=>({...r,messages:[],session:null,sessionId:null,activeSessionFile:null,activeCwd:null,activeModel:null,readOnly:!1,notice:null,creatingSession:!1,loadingSession:!1,resyncing:!1,agentPending:!1,contextUsage:null})),this.clearLoadWatchdog(),this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0}resolveConflict(e,r){const s=Jt(this.stateStore);s.conflict&&(this.send({type:"session_resolve_conflict",action:e,sessionId:s.conflict.targetSessionId,cwd:r||s.conflict.conflictingCwd}),this.stateStore.update(o=>({...o,conflict:null,readOnly:e==="read_only"})))}ping(){this.send({type:"ping"})}clearMessages(){this.stateStore.update(e=>({...e,messages:[]}))}dismissSessionError(){this.stateStore.update(e=>({...e,sessionError:null}))}dismissNotice(){this.stateStore.update(e=>({...e,notice:null}))}changeModel(e){this.send({type:"model_change",model:e})}setConfig(e){this.config={...this.config,...e},this.stateStore.update(r=>{const s={...r};return e.hideThinking!==void 0&&(s.hideThinking=!!e.hideThinking),e.hideTools!==void 0&&(s.hideTools=!!e.hideTools),s})}onMessage(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}uploadFileViaWebSocket(e,r,s){return new Promise((o,a)=>{const i=this.generateId();this.pendingUploads.set(i,{resolve:o,reject:a}),this.send({type:"file_upload",uploadId:i,sessionId:e,filename:r,data:s})})}generateId(){return Math.random().toString(36).substring(2)+Date.now().toString(36)}getIsConnected(){return this.ws&&this.ws.readyState===1}}const ur=An({folders:[],activeSessions:[],currentSession:null,loading:!1}),fr=An({models:[],loading:!1}),kr=An({folders:[],activeSessions:[],currentSession:null,loading:!1});function Un(){const n=localStorage.getItem("wherever-config"),e=typeof window<"u"&&window.location&&window.location.hostname?window.location.hostname:"localhost";if(n){const r=JSON.parse(n),s=window.location.protocol==="https:"?"https:":"http:";let o=r.host||e;return(o==="localhost"||o==="127.0.0.1")&&e&&e!=="localhost"&&e!=="127.0.0.1"&&(o=e),o=o.startsWith("http")?o.replace(/^wss?:\/\//,""):o,`${s}//${o}:${r.port||31415}`}return`${window.location.protocol}//${window.location.host}`}let vr=null,gs=[],ms=!1,xs=!1,io=0;const Ti=150,Ai=1e3;async function lo(){ms=!0;try{const n=Un(),e=zn(),r=`${n}/sessions${e?`?token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const o=await s.json();ur.set({folders:o.folders||[],activeSessions:(o.activeSessions||[]).map(a=>a.sessionFile),currentSession:Fn(ur).currentSession,loading:!1})}catch(n){ur.update(e=>({...e,loading:!1})),console.error("Failed to fetch sessions:",n)}finally{ms=!1}}function Er(){ur.update(r=>({...r,loading:!0}));const n=new Promise(r=>{gs.push(r)});if(ms)return xs=!0,n;const e=Date.now();if(!vr)io=e;else if(clearTimeout(vr),e-io>=Ai)return vr=null,co(),n;return vr=setTimeout(()=>{vr=null,co()},Ti),n}async function co(){const n=[...gs];gs=[];try{for(await lo();xs;)xs=!1,await lo()}finally{for(const e of n)e()}}async function Bo(){kr.update(n=>({...n,loading:!0}));try{const n=Un(),e=zn(),r=`${n}/sessions?view=readonly${e?`&token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const o=await s.json();kr.set({folders:o.folders||[],activeSessions:(o.activeSessions||[]).map(a=>a.sessionFile),currentSession:Fn(kr).currentSession,loading:!1})}catch(n){kr.update(e=>({...e,loading:!1})),console.error("Failed to fetch read-only sessions:",n)}}async function Ei(){fr.update(n=>({...n,loading:!0}));try{const n=Un(),e=zn(),r=`${n}/models${e?`?token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const o=await s.json();fr.set({models:o.models||[],loading:!1})}catch(n){fr.update(e=>({...e,loading:!1})),console.error("Failed to fetch models:",n)}}function zn(){try{const n=localStorage.getItem("wherever-config");if(n)return JSON.parse(n).token||""}catch{}return""}const Ds=An(!1),Ho=An("websocket"),Ls=An(null),Wo=An(!1),Go=An(null);async function jo(n){if(!n.trim())return null;try{const e=Un(),r=zn(),s=`${e}/check-path?path=${encodeURIComponent(n)}${r?`&token=${encodeURIComponent(r)}`:""}`,o=await fetch(s);if(!o.ok)throw new Error(`HTTP ${o.status}`);return await o.json()}catch(e){return console.error("Failed to check path:",e),null}}async function Gr(n){try{const e=Un(),r=zn(),s=`${e}/autocomplete-path?path=${encodeURIComponent(n)}${r?`&token=${encodeURIComponent(r)}`:""}`,o=await fetch(s);if(!o.ok)throw new Error(`HTTP ${o.status}`);return(await o.json()).completions||[]}catch(e){return console.error("Failed to autocomplete path:",e),[]}}async function Ci(){try{const n=Un(),e=zn(),r=`${n}/config${e?`?token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const o=await s.json();Ds.set(!!o.gitInitDefault),Ho.set(o.uploadMethod||"websocket"),Ls.set(o.searchFolder||null),Wo.set(!!o.searchCreateRemote),Go.set(o.searchDefaultModel||null)}catch(n){console.error("Failed to fetch config:",n)}}function Cr(n){ur.update(e=>({...e,currentSession:n}))}function Ri(){try{const n=localStorage.getItem("wherever-config");if(n)return JSON.parse(n)}catch{}return null}function Or(n){localStorage.setItem("wherever-config",JSON.stringify(n))}function Bn(){const n=typeof window<"u"&&window.location&&window.location.hostname?window.location.hostname:"localhost",e=Ri();return e?(!e.host||e.host==="localhost"||e.host==="127.0.0.1")&&n&&n!=="localhost"&&n!=="127.0.0.1"?{hideThinking:!1,hideTools:!1,...e,host:n}:(e.host||(e.host=n),{hideThinking:!1,hideTools:!1,beepDefault:!1,beepSoundUrl:"",...e}):{host:n,port:31415,token:"",hideThinking:!1,hideTools:!1,beepDefault:!1,beepSoundUrl:""}}const Yr=An(!!Bn().beepDefault),qo="wherever-beep-overrides";function Ii(){try{const n=localStorage.getItem(qo);if(n){const e=JSON.parse(n);if(e&&typeof e=="object")return e}}catch{}return{}}function $i(n){try{localStorage.setItem(qo,JSON.stringify(n))}catch{}}const Vo=An(typeof localStorage<"u"?Ii():{}),Ps=An("");function Mi(){return Fn(Yr)}function Ko(){const n=Bn().beepSoundUrl;return typeof n=="string"?n:""}function Oi(n){const e=Bn();Or({...e,beepSoundUrl:n})}const Ns=jt([Ps,Vo],([n,e])=>n&&n in e?e[n]:void 0),Fs=jt([Ns,Yr],([n,e])=>n===void 0?e:n);function Di(n){const e=Bn();Or({...e,beepDefault:n}),Yr.set(n)}function Br(n){const e=Fn(Ps);e&&Vo.update(r=>{const s={...r};return n===void 0?delete s[e]:s[e]=n,$i(s),s})}function Yo(n){Ps.set(n??"")}const gr=Bn(),xt=new $n({host:gr.host,port:gr.port,token:gr.token,secure:typeof window<"u"&&window.location&&window.location.protocol==="https:",hideThinking:!!gr.hideThinking,hideTools:!!gr.hideTools}),Zr=xt.stateStore;let cs=!1,uo=null;Zr.subscribe(n=>{const e=n.sessionId??n.activeSessionFile??null;if(e!==uo){uo=e,Yo(e),cs=n.isStreaming;return}cs&&!n.isStreaming&&e&&Fn(Fs)&&zo(Ko()),cs=n.isStreaming});let Sr=null;xt.onMessage(n=>{switch(n.type){case"session_created":if(Cr(n.sessionFile),Sr!==null){const r=Sr;Sr=null,queueMicrotask(()=>xt.sendMessage(r))}break;case"session_error":Sr=null;break;case"session_destroyed":Fn(Zr).sessionId===n.sessionId&&Cr(null);break;case"sessions_updated":Er();break;case"session_interrupted":Cr(null);break}});function Qn(){const n=Bn();Or(n);const e=typeof window<"u"&&window.location&&window.location.protocol==="https:";xt.connect({host:n.host,port:n.port,token:n.token,secure:e,hideThinking:!!n.hideThinking,hideTools:!!n.hideTools})}function $r(){xt.disconnect(!0),Cr(null)}function Zo(){xt.suspend()}function _s(){xt.resume()}function Li(){return xt.hasSuspendedSession()}function ys(){return xt.hasActiveSession()}let Us=0;const Pi=300*1e3;function Xo(){Us=Date.now()+Pi}function zs(){Us=0}function Qo(){return Date.now()<Us}function ws(n){return xt.sendMessage(n)}function Jo(n){return xt.resendMessage(n)}function ea(n){xt.discardMessage(n)}function ta(){xt.abort()}function na(n,e,r){xt.joinSession(n,e,r)}function Bs(n,e,r){xt.switchSession(n,e,r)}function Mn(n,e,r,s,o){xt.createSession(n,e,r,s,o)}function ra(n,e){const r=n.trim();if(!r)return!1;const s=Fn(Ls);if(!s)return!1;const o=Fn(Wo);return Sr=r,xt.createSession(s,e||void 0,o,o,o?"private":void 0),!0}function kn(){xt.leaveSession(),Cr(null)}function sa(){xt.loadMoreHistory()}function ks(n,e){xt.resolveConflict(n,e)}function Ni(){xt.ping()}function oa(){xt.clearMessages()}function Ss(n){Or(n);const{host:e,port:r,token:s,hideThinking:o,hideTools:a}=n;xt.setConfig({host:e,port:r,token:s,hideThinking:o,hideTools:a}),n.beepDefault!==void 0&&Yr.set(!!n.beepDefault)}function aa(n){const r={...Bn(),...n};Or(r),xt.setConfig(r)}function Jn(){xt.dismissSessionError()}function ia(){xt.dismissNotice()}function la(n){xt.changeModel(n)}const Nt=jt(Zr,n=>n),Dr=jt(Nt,n=>n.connected),Hs=jt(Nt,n=>n.isStreaming),ca=jt(Nt,n=>n.messages),Fi=jt(Nt,n=>n.error),Ui=jt(Nt,n=>n.session),da=jt(Nt,n=>n.conflict),ua=jt(Nt,n=>n.isInterrupted),Ws=jt(Nt,n=>n.sessionError),fa=jt(Nt,n=>n.notice),Xr=jt(Nt,n=>n.readOnly),Lr=jt(Nt,n=>({sessionFile:n.activeSessionFile,cwd:n.activeCwd,model:n.activeModel,sessionId:n.sessionId})),zi=jt(Nt,n=>n.contextUsage),pa=jt(Nt,n=>n.creatingSession),Qr=jt(Nt,n=>n.loadingSession),Gs=jt(Nt,n=>n.resyncing),ha=jt(Nt,n=>n.agentPending),ba=jt(Nt,n=>n.historyOffset>0),va=jt(Nt,n=>n.loadingMoreHistory);async function Bi(n,e){const r=Un(),s=zn(),o=`${r}/session/upload?sessionId=${encodeURIComponent(n)}&filename=${encodeURIComponent(e.name)}${s?`&token=${encodeURIComponent(s)}`:""}`,a=await e.arrayBuffer(),i=await fetch(o,{method:"POST",headers:{"Content-Type":"text/plain"},body:a});if(!i.ok){const c=await i.json().catch(()=>({}));throw new Error(c.error||`Upload failed with status ${i.status}`)}return await i.json()}function Hi(n,e){return new Promise((r,s)=>{try{const o=new FileReader;o.onload=()=>{try{const i=o.result.split(",")[1]||"";xt.uploadFileViaWebSocket(n,e.name,i).then(r).catch(s)}catch(a){s(new Error(`Failed to process file data: ${a.message}`))}},o.onerror=()=>{s(new Error("Failed to read file contents"))},o.readAsDataURL(e)}catch(o){s(o)}})}async function ga(n,e){return Fn(Ho)==="post"?Bi(n,e):Hi(n,e)}async function Ts(n){try{const e=Un(),r=zn(),s=`${e}/session/delete${r?`?token=${encodeURIComponent(r)}`:""}`,o=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionFile:n})});if(!o.ok){const a=await o.json().catch(()=>({}));throw new Error(a.error||`Delete failed with status ${o.status}`)}}catch(e){throw console.error("Failed to delete session:",e),e}}const Wi=Object.freeze(Object.defineProperty({__proto__:null,abort:ta,activeSessionInfo:Lr,beepEnabled:Fs,beepSessionOverride:Ns,beginFilePicker:Xo,changeModel:la,clearMessages:oa,client:xt,conflict:da,connect:Qn,connectionError:Fi,contextUsage:zi,createSession:Mn,currentSession:Ui,deleteSession:Ts,discardMessage:ea,disconnect:$r,dismissNotice:ia,dismissSessionError:Jn,endFilePicker:zs,getBeepDefault:Mi,getBeepSoundUrl:Ko,getConfig:Bn,hasActiveSession:ys,hasMoreHistory:ba,hasSuspendedSession:Li,isAgentPending:ha,isConnected:Dr,isCreatingSession:pa,isFilePickerActive:Qo,isInterrupted:ua,isLoadingMoreHistory:va,isLoadingSession:Qr,isReadOnly:Xr,isResyncing:Gs,isStreaming:Hs,joinSession:na,leaveSession:kn,loadMoreHistory:sa,messages:ca,piState:Nt,ping:Ni,resendMessage:Jo,resolveConflict:ks,resume:_s,runSearch:ra,sendMessage:ws,sessionError:Ws,sessionNotice:fa,setBeepDefault:Di,setBeepSessionKey:Yo,setBeepSessionOverride:Br,setBeepSoundUrl:Oi,setConfig:Ss,state:Zr,suspend:Zo,switchSession:Bs,updateConfig:aa,uploadFile:ga},Symbol.toStringTag,{value:"Module"}));var Gi=m('<button class="flex-1 rounded bg-rose-500 px-4 py-2 text-sm text-white transition-colors hover:bg-rose-600">Disconnect</button>'),ji=m('<button class="flex-1 rounded bg-gradient-to-r from-brand-cyan to-brand-blue px-4 py-2 text-sm text-white transition-all hover:opacity-90 disabled:cursor-not-allowed disabled:from-brand-surface-3 disabled:to-brand-surface-3"></button>'),qi=m('<div class="border-b border-brand-border p-4"><div class="space-y-3"><div><label for="pi-host" class="mb-1 block text-xs text-brand-text-muted">Host</label> <input id="pi-host" type="text" placeholder="localhost" class="w-full rounded border border-brand-border bg-brand-surface-2 px-3 py-2 text-sm text-brand-text placeholder-brand-text-muted focus:border-brand-blue focus:outline-none"/></div> <div><label for="pi-port" class="mb-1 block text-xs text-brand-text-muted">Port</label> <input id="pi-port" type="number" class="w-full rounded border border-brand-border bg-brand-surface-2 px-3 py-2 text-sm text-brand-text placeholder-brand-text-muted focus:border-brand-blue focus:outline-none"/></div> <div><label for="pi-token" class="mb-1 block text-xs text-brand-text-muted">Token (optional)</label> <input id="pi-token" type="password" placeholder="Authentication token" class="w-full rounded border border-brand-border bg-brand-surface-2 px-3 py-2 text-sm text-brand-text placeholder-brand-text-muted focus:border-brand-blue focus:outline-none"/></div> <div class="flex items-center gap-2 py-1"><input id="pi-hide-thinking" type="checkbox" class="h-4 w-4 rounded border-brand-border bg-brand-surface-2 text-brand-blue focus:ring-brand-blue focus:ring-offset-0"/> <label for="pi-hide-thinking" class="cursor-pointer text-xs text-brand-text select-none">Hide thinking steps</label></div> <div class="flex items-center gap-2 py-1"><input id="pi-beep-default" type="checkbox" class="h-4 w-4 rounded border-brand-border bg-brand-surface-2 text-brand-blue focus:ring-brand-blue focus:ring-offset-0"/> <label for="pi-beep-default" class="cursor-pointer text-xs text-brand-text select-none">Beep when the agent is waiting (default for new sessions)</label></div> <div><label for="pi-beep-sound" class="mb-1 block text-xs text-brand-text-muted">Beep sound URL (optional, blank = built-in chime)</label> <div class="flex gap-2"><input id="pi-beep-sound" type="text" placeholder="/sounds/complete.mp3 or https://..." class="w-full rounded border border-brand-border bg-brand-surface-2 px-3 py-2 text-sm text-brand-text placeholder-brand-text-muted focus:border-brand-blue focus:outline-none"/> <button type="button" title="Play the beep to test it" class="flex-shrink-0 rounded border border-brand-border bg-brand-surface-2 px-3 py-2 text-sm text-brand-text transition-colors hover:bg-brand-surface-3">Test</button></div></div> <div class="flex gap-2"><!></div> <button title="Reload the page" class="flex w-full items-center justify-center gap-2 rounded border border-brand-border bg-brand-surface-2 px-4 py-2 text-sm text-brand-text transition-colors hover:bg-brand-surface-3"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" aria-hidden="true"><path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"></path><path d="M21 3v5h-5"></path><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"></path><path d="M8 16H3v5"></path></svg> Reload</button></div></div>');function Vi(n,e){Vn(e,!0);const r=()=>Ue(Dr,"$isConnected",s),[s,o]=pr();let a=V(""),i=V(0),c=V(""),_=V(!1),b=V(!1),v=V(""),A=!1,$=Q(r);Mr(()=>{const ye=Bn();p(a,ye.host,!0),p(i,ye.port,!0),p(c,ye.token||"",!0),p(_,!!ye.hideThinking),p(b,!!ye.beepDefault),p(v,ye.beepSoundUrl||"",!0)});function O(){zo(t(v).trim()||void 0)}function k(){Ss({host:t(a),port:t(i),token:t(c),hideThinking:t(_),hideTools:!1,beepDefault:t(b),beepSoundUrl:t(v).trim()})}function ae(){Ss({host:t(a),port:t(i),token:t(c),hideThinking:t(_),hideTools:!1,beepDefault:t(b),beepSoundUrl:t(v).trim()}),$r(),setTimeout(()=>Qn(),100)}function se(){$r()}function he(){window.location.reload()}var ie=qi(),rt=u(ie),Me=u(rt),Ge=f(u(Me),2);it(Ge),d(Me);var le=f(Me,2),Pe=f(u(le),2);it(Pe),d(le);var st=f(le,2),Ct=f(u(st),2);it(Ct),d(st);var at=f(st,2),be=u(at);it(be),dt(2),d(at);var je=f(at,2),_t=u(je);it(_t),dt(2),d(je);var ot=f(je,2),Je=f(u(ot),2),et=u(Je);it(et);var Mt=f(et,2);d(Je),d(ot);var Rt=f(ot,2),ve=u(Rt);{var pt=ye=>{var ht=Gi();B("click",ht,se),h(ye,ht)},te=ye=>{var ht=ji();ht.disabled=A,ht.textContent="Connect",B("click",ht,ae),h(ye,ht)};E(ve,ye=>{t($)?ye(pt):ye(te,-1)})}d(Rt);var Ft=f(Rt,2);d(rt),d(ie),On(Ge,()=>t(a),ye=>p(a,ye)),On(Pe,()=>t(i),ye=>p(i,ye)),On(Ct,()=>t(c),ye=>p(c,ye)),B("change",be,k),Tn(be,()=>t(_),ye=>p(_,ye)),B("change",_t,k),Tn(_t,()=>t(b),ye=>p(b,ye)),B("change",et,k),On(et,()=>t(v),ye=>p(v,ye)),B("click",Mt,O),B("click",Ft,he),h(n,ie),Kn(),o()}tr(["change","click"]);function js(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var nr=js();function ma(n){nr=n}var Rr={exec:()=>null};function ft(n,e=""){let r=typeof n=="string"?n:n.source;const s={replace:(o,a)=>{let i=typeof a=="string"?a:a.source;return i=i.replace(pn.caret,"$1"),r=r.replace(o,i),s},getRegex:()=>new RegExp(r,e)};return s}var pn={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:n=>new RegExp(`^( {0,3}${n})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}#`),htmlBeginRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}<(?:[a-z].*>|!--)`,"i")},Ki=/^(?:[ \t]*(?:\n|$))+/,Yi=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Zi=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Pr=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Xi=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,qs=/(?:[*+-]|\d{1,9}[.)])/,xa=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_a=ft(xa).replace(/bull/g,qs).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Qi=ft(xa).replace(/bull/g,qs).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Vs=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Ji=/^[^\n]+/,Ks=/(?!\s*\])(?:\\.|[^\[\]\\])+/,el=ft(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Ks).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),tl=ft(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,qs).getRegex(),Jr="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Ys=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,nl=ft("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",Ys).replace("tag",Jr).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ya=ft(Vs).replace("hr",Pr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Jr).getRegex(),rl=ft(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",ya).getRegex(),Zs={blockquote:rl,code:Yi,def:el,fences:Zi,heading:Xi,hr:Pr,html:nl,lheading:_a,list:tl,newline:Ki,paragraph:ya,table:Rr,text:Ji},fo=ft("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Pr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Jr).getRegex(),sl={...Zs,lheading:Qi,table:fo,paragraph:ft(Vs).replace("hr",Pr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",fo).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Jr).getRegex()},ol={...Zs,html:ft(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Ys).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Rr,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ft(Vs).replace("hr",Pr).replace("heading",` *#{1,6} *[^
11
- ]`).replace("lheading",_a).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},al=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,il=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,wa=/^( {2,}|\\)\n(?!\s*$)/,ll=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,es=/[\p{P}\p{S}]/u,Xs=/[\s\p{P}\p{S}]/u,ka=/[^\s\p{P}\p{S}]/u,cl=ft(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Xs).getRegex(),Sa=/(?!~)[\p{P}\p{S}]/u,dl=/(?!~)[\s\p{P}\p{S}]/u,ul=/(?:[^\s\p{P}\p{S}]|~)/u,fl=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,Ta=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,pl=ft(Ta,"u").replace(/punct/g,es).getRegex(),hl=ft(Ta,"u").replace(/punct/g,Sa).getRegex(),Aa="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",bl=ft(Aa,"gu").replace(/notPunctSpace/g,ka).replace(/punctSpace/g,Xs).replace(/punct/g,es).getRegex(),vl=ft(Aa,"gu").replace(/notPunctSpace/g,ul).replace(/punctSpace/g,dl).replace(/punct/g,Sa).getRegex(),gl=ft("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,ka).replace(/punctSpace/g,Xs).replace(/punct/g,es).getRegex(),ml=ft(/\\(punct)/,"gu").replace(/punct/g,es).getRegex(),xl=ft(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),_l=ft(Ys).replace("(?:-->|$)","-->").getRegex(),yl=ft("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",_l).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),jr=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,wl=ft(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",jr).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ea=ft(/^!?\[(label)\]\[(ref)\]/).replace("label",jr).replace("ref",Ks).getRegex(),Ca=ft(/^!?\[(ref)\](?:\[\])?/).replace("ref",Ks).getRegex(),kl=ft("reflink|nolink(?!\\()","g").replace("reflink",Ea).replace("nolink",Ca).getRegex(),Qs={_backpedal:Rr,anyPunctuation:ml,autolink:xl,blockSkip:fl,br:wa,code:il,del:Rr,emStrongLDelim:pl,emStrongRDelimAst:bl,emStrongRDelimUnd:gl,escape:al,link:wl,nolink:Ca,punctuation:cl,reflink:Ea,reflinkSearch:kl,tag:yl,text:ll,url:Rr},Sl={...Qs,link:ft(/^!?\[(label)\]\((.*?)\)/).replace("label",jr).getRegex(),reflink:ft(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",jr).getRegex()},As={...Qs,emStrongRDelimAst:vl,emStrongLDelim:hl,url:ft(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Tl={...As,br:ft(wa).replace("{2,}","*").getRegex(),text:ft(As.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Fr={normal:Zs,gfm:sl,pedantic:ol},mr={normal:Qs,gfm:As,breaks:Tl,pedantic:Sl},Al={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},po=n=>Al[n];function Rn(n,e){if(e){if(pn.escapeTest.test(n))return n.replace(pn.escapeReplace,po)}else if(pn.escapeTestNoEncode.test(n))return n.replace(pn.escapeReplaceNoEncode,po);return n}function ho(n){try{n=encodeURI(n).replace(pn.percentDecode,"%")}catch{return null}return n}function bo(n,e){const r=n.replace(pn.findPipe,(a,i,c)=>{let _=!1,b=i;for(;--b>=0&&c[b]==="\\";)_=!_;return _?"|":" |"}),s=r.split(pn.splitPipe);let o=0;if(s[0].trim()||s.shift(),s.length>0&&!s.at(-1)?.trim()&&s.pop(),e)if(s.length>e)s.splice(e);else for(;s.length<e;)s.push("");for(;o<s.length;o++)s[o]=s[o].trim().replace(pn.slashPipe,"|");return s}function xr(n,e,r){const s=n.length;if(s===0)return"";let o=0;for(;o<s&&n.charAt(s-o-1)===e;)o++;return n.slice(0,s-o)}function El(n,e){if(n.indexOf(e[1])===-1)return-1;let r=0;for(let s=0;s<n.length;s++)if(n[s]==="\\")s++;else if(n[s]===e[0])r++;else if(n[s]===e[1]&&(r--,r<0))return s;return r>0?-2:-1}function vo(n,e,r,s,o){const a=e.href,i=e.title||null,c=n[1].replace(o.other.outputLinkReplace,"$1");s.state.inLink=!0;const _={type:n[0].charAt(0)==="!"?"image":"link",raw:r,href:a,title:i,text:c,tokens:s.inlineTokens(c)};return s.state.inLink=!1,_}function Cl(n,e,r){const s=n.match(r.other.indentCodeCompensation);if(s===null)return e;const o=s[1];return e.split(`
12
- `).map(a=>{const i=a.match(r.other.beginningSpace);if(i===null)return a;const[c]=i;return c.length>=o.length?a.slice(o.length):a}).join(`
13
- `)}var qr=class{options;rules;lexer;constructor(n){this.options=n||nr}space(n){const e=this.rules.block.newline.exec(n);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(n){const e=this.rules.block.code.exec(n);if(e){const r=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?r:xr(r,`
14
- `)}}}fences(n){const e=this.rules.block.fences.exec(n);if(e){const r=e[0],s=Cl(r,e[3]||"",this.rules);return{type:"code",raw:r,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(n){const e=this.rules.block.heading.exec(n);if(e){let r=e[2].trim();if(this.rules.other.endingHash.test(r)){const s=xr(r,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(r=s.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(n){const e=this.rules.block.hr.exec(n);if(e)return{type:"hr",raw:xr(e[0],`
15
- `)}}blockquote(n){const e=this.rules.block.blockquote.exec(n);if(e){let r=xr(e[0],`
16
- `).split(`
17
- `),s="",o="";const a=[];for(;r.length>0;){let i=!1;const c=[];let _;for(_=0;_<r.length;_++)if(this.rules.other.blockquoteStart.test(r[_]))c.push(r[_]),i=!0;else if(!i)c.push(r[_]);else break;r=r.slice(_);const b=c.join(`
18
- `),v=b.replace(this.rules.other.blockquoteSetextReplace,`
19
- $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
20
- ${b}`:b,o=o?`${o}
21
- ${v}`:v;const A=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(v,a,!0),this.lexer.state.top=A,r.length===0)break;const $=a.at(-1);if($?.type==="code")break;if($?.type==="blockquote"){const O=$,k=O.raw+`
22
- `+r.join(`
23
- `),ae=this.blockquote(k);a[a.length-1]=ae,s=s.substring(0,s.length-O.raw.length)+ae.raw,o=o.substring(0,o.length-O.text.length)+ae.text;break}else if($?.type==="list"){const O=$,k=O.raw+`
24
- `+r.join(`
25
- `),ae=this.list(k);a[a.length-1]=ae,s=s.substring(0,s.length-$.raw.length)+ae.raw,o=o.substring(0,o.length-O.raw.length)+ae.raw,r=k.substring(a.at(-1).raw.length).split(`
26
- `);continue}}return{type:"blockquote",raw:s,tokens:a,text:o}}}list(n){let e=this.rules.block.list.exec(n);if(e){let r=e[1].trim();const s=r.length>1,o={type:"list",raw:"",ordered:s,start:s?+r.slice(0,-1):"",loose:!1,items:[]};r=s?`\\d{1,9}\\${r.slice(-1)}`:`\\${r}`,this.options.pedantic&&(r=s?r:"[*+-]");const a=this.rules.other.listItemRegex(r);let i=!1;for(;n;){let _=!1,b="",v="";if(!(e=a.exec(n))||this.rules.block.hr.test(n))break;b=e[0],n=n.substring(b.length);let A=e[2].split(`
27
- `,1)[0].replace(this.rules.other.listReplaceTabs,he=>" ".repeat(3*he.length)),$=n.split(`
28
- `,1)[0],O=!A.trim(),k=0;if(this.options.pedantic?(k=2,v=A.trimStart()):O?k=e[1].length+1:(k=e[2].search(this.rules.other.nonSpaceChar),k=k>4?1:k,v=A.slice(k),k+=e[1].length),O&&this.rules.other.blankLine.test($)&&(b+=$+`
29
- `,n=n.substring($.length+1),_=!0),!_){const he=this.rules.other.nextBulletRegex(k),ie=this.rules.other.hrRegex(k),rt=this.rules.other.fencesBeginRegex(k),Me=this.rules.other.headingBeginRegex(k),Ge=this.rules.other.htmlBeginRegex(k);for(;n;){const le=n.split(`
30
- `,1)[0];let Pe;if($=le,this.options.pedantic?($=$.replace(this.rules.other.listReplaceNesting," "),Pe=$):Pe=$.replace(this.rules.other.tabCharGlobal," "),rt.test($)||Me.test($)||Ge.test($)||he.test($)||ie.test($))break;if(Pe.search(this.rules.other.nonSpaceChar)>=k||!$.trim())v+=`
31
- `+Pe.slice(k);else{if(O||A.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||rt.test(A)||Me.test(A)||ie.test(A))break;v+=`
32
- `+$}!O&&!$.trim()&&(O=!0),b+=le+`
33
- `,n=n.substring(le.length+1),A=Pe.slice(k)}}o.loose||(i?o.loose=!0:this.rules.other.doubleBlankLine.test(b)&&(i=!0));let ae=null,se;this.options.gfm&&(ae=this.rules.other.listIsTask.exec(v),ae&&(se=ae[0]!=="[ ] ",v=v.replace(this.rules.other.listReplaceTask,""))),o.items.push({type:"list_item",raw:b,task:!!ae,checked:se,loose:!1,text:v,tokens:[]}),o.raw+=b}const c=o.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd();else return;o.raw=o.raw.trimEnd();for(let _=0;_<o.items.length;_++)if(this.lexer.state.top=!1,o.items[_].tokens=this.lexer.blockTokens(o.items[_].text,[]),!o.loose){const b=o.items[_].tokens.filter(A=>A.type==="space"),v=b.length>0&&b.some(A=>this.rules.other.anyLine.test(A.raw));o.loose=v}if(o.loose)for(let _=0;_<o.items.length;_++)o.items[_].loose=!0;return o}}html(n){const e=this.rules.block.html.exec(n);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(n){const e=this.rules.block.def.exec(n);if(e){const r=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",o=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:r,raw:e[0],href:s,title:o}}}table(n){const e=this.rules.block.table.exec(n);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;const r=bo(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),o=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
34
- `):[],a={type:"table",raw:e[0],header:[],align:[],rows:[]};if(r.length===s.length){for(const i of s)this.rules.other.tableAlignRight.test(i)?a.align.push("right"):this.rules.other.tableAlignCenter.test(i)?a.align.push("center"):this.rules.other.tableAlignLeft.test(i)?a.align.push("left"):a.align.push(null);for(let i=0;i<r.length;i++)a.header.push({text:r[i],tokens:this.lexer.inline(r[i]),header:!0,align:a.align[i]});for(const i of o)a.rows.push(bo(i,a.header.length).map((c,_)=>({text:c,tokens:this.lexer.inline(c),header:!1,align:a.align[_]})));return a}}lheading(n){const e=this.rules.block.lheading.exec(n);if(e)return{type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(n){const e=this.rules.block.paragraph.exec(n);if(e){const r=e[1].charAt(e[1].length-1)===`
35
- `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:r,tokens:this.lexer.inline(r)}}}text(n){const e=this.rules.block.text.exec(n);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(n){const e=this.rules.inline.escape.exec(n);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(n){const e=this.rules.inline.tag.exec(n);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(n){const e=this.rules.inline.link.exec(n);if(e){const r=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(r)){if(!this.rules.other.endAngleBracket.test(r))return;const a=xr(r.slice(0,-1),"\\");if((r.length-a.length)%2===0)return}else{const a=El(e[2],"()");if(a===-2)return;if(a>-1){const c=(e[0].indexOf("!")===0?5:4)+e[1].length+a;e[2]=e[2].substring(0,a),e[0]=e[0].substring(0,c).trim(),e[3]=""}}let s=e[2],o="";if(this.options.pedantic){const a=this.rules.other.pedanticHrefTitle.exec(s);a&&(s=a[1],o=a[3])}else o=e[3]?e[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(r)?s=s.slice(1):s=s.slice(1,-1)),vo(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:o&&o.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(n,e){let r;if((r=this.rules.inline.reflink.exec(n))||(r=this.rules.inline.nolink.exec(n))){const s=(r[2]||r[1]).replace(this.rules.other.multipleSpaceGlobal," "),o=e[s.toLowerCase()];if(!o){const a=r[0].charAt(0);return{type:"text",raw:a,text:a}}return vo(r,o,r[0],this.lexer,this.rules)}}emStrong(n,e,r=""){let s=this.rules.inline.emStrongLDelim.exec(n);if(!s||s[3]&&r.match(this.rules.other.unicodeAlphaNumeric))return;if(!(s[1]||s[2]||"")||!r||this.rules.inline.punctuation.exec(r)){const a=[...s[0]].length-1;let i,c,_=a,b=0;const v=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(v.lastIndex=0,e=e.slice(-1*n.length+a);(s=v.exec(e))!=null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i)continue;if(c=[...i].length,s[3]||s[4]){_+=c;continue}else if((s[5]||s[6])&&a%3&&!((a+c)%3)){b+=c;continue}if(_-=c,_>0)continue;c=Math.min(c,c+_+b);const A=[...s[0]][0].length,$=n.slice(0,a+s.index+A+c);if(Math.min(a,c)%2){const k=$.slice(1,-1);return{type:"em",raw:$,text:k,tokens:this.lexer.inlineTokens(k)}}const O=$.slice(2,-2);return{type:"strong",raw:$,text:O,tokens:this.lexer.inlineTokens(O)}}}}codespan(n){const e=this.rules.inline.code.exec(n);if(e){let r=e[2].replace(this.rules.other.newLineCharGlobal," ");const s=this.rules.other.nonSpaceChar.test(r),o=this.rules.other.startingSpaceChar.test(r)&&this.rules.other.endingSpaceChar.test(r);return s&&o&&(r=r.substring(1,r.length-1)),{type:"codespan",raw:e[0],text:r}}}br(n){const e=this.rules.inline.br.exec(n);if(e)return{type:"br",raw:e[0]}}del(n){const e=this.rules.inline.del.exec(n);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(n){const e=this.rules.inline.autolink.exec(n);if(e){let r,s;return e[2]==="@"?(r=e[1],s="mailto:"+r):(r=e[1],s=r),{type:"link",raw:e[0],text:r,href:s,tokens:[{type:"text",raw:r,text:r}]}}}url(n){let e;if(e=this.rules.inline.url.exec(n)){let r,s;if(e[2]==="@")r=e[0],s="mailto:"+r;else{let o;do o=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(o!==e[0]);r=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:r,href:s,tokens:[{type:"text",raw:r,text:r}]}}}inlineText(n){const e=this.rules.inline.text.exec(n);if(e){const r=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:r}}}},Ln=class Es{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||nr,this.options.tokenizer=this.options.tokenizer||new qr,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const r={other:pn,block:Fr.normal,inline:mr.normal};this.options.pedantic?(r.block=Fr.pedantic,r.inline=mr.pedantic):this.options.gfm&&(r.block=Fr.gfm,this.options.breaks?r.inline=mr.breaks:r.inline=mr.gfm),this.tokenizer.rules=r}static get rules(){return{block:Fr,inline:mr}}static lex(e,r){return new Es(r).lex(e)}static lexInline(e,r){return new Es(r).inlineTokens(e)}lex(e){e=e.replace(pn.carriageReturn,`
36
- `),this.blockTokens(e,this.tokens);for(let r=0;r<this.inlineQueue.length;r++){const s=this.inlineQueue[r];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,r=[],s=!1){for(this.options.pedantic&&(e=e.replace(pn.tabCharGlobal," ").replace(pn.spaceLine,""));e;){let o;if(this.options.extensions?.block?.some(i=>(o=i.call({lexer:this},e,r))?(e=e.substring(o.raw.length),r.push(o),!0):!1))continue;if(o=this.tokenizer.space(e)){e=e.substring(o.raw.length);const i=r.at(-1);o.raw.length===1&&i!==void 0?i.raw+=`
37
- `:r.push(o);continue}if(o=this.tokenizer.code(e)){e=e.substring(o.raw.length);const i=r.at(-1);i?.type==="paragraph"||i?.type==="text"?(i.raw+=`
38
- `+o.raw,i.text+=`
39
- `+o.text,this.inlineQueue.at(-1).src=i.text):r.push(o);continue}if(o=this.tokenizer.fences(e)){e=e.substring(o.raw.length),r.push(o);continue}if(o=this.tokenizer.heading(e)){e=e.substring(o.raw.length),r.push(o);continue}if(o=this.tokenizer.hr(e)){e=e.substring(o.raw.length),r.push(o);continue}if(o=this.tokenizer.blockquote(e)){e=e.substring(o.raw.length),r.push(o);continue}if(o=this.tokenizer.list(e)){e=e.substring(o.raw.length),r.push(o);continue}if(o=this.tokenizer.html(e)){e=e.substring(o.raw.length),r.push(o);continue}if(o=this.tokenizer.def(e)){e=e.substring(o.raw.length);const i=r.at(-1);i?.type==="paragraph"||i?.type==="text"?(i.raw+=`
40
- `+o.raw,i.text+=`
41
- `+o.raw,this.inlineQueue.at(-1).src=i.text):this.tokens.links[o.tag]||(this.tokens.links[o.tag]={href:o.href,title:o.title});continue}if(o=this.tokenizer.table(e)){e=e.substring(o.raw.length),r.push(o);continue}if(o=this.tokenizer.lheading(e)){e=e.substring(o.raw.length),r.push(o);continue}let a=e;if(this.options.extensions?.startBlock){let i=1/0;const c=e.slice(1);let _;this.options.extensions.startBlock.forEach(b=>{_=b.call({lexer:this},c),typeof _=="number"&&_>=0&&(i=Math.min(i,_))}),i<1/0&&i>=0&&(a=e.substring(0,i+1))}if(this.state.top&&(o=this.tokenizer.paragraph(a))){const i=r.at(-1);s&&i?.type==="paragraph"?(i.raw+=`
42
- `+o.raw,i.text+=`
43
- `+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):r.push(o),s=a.length!==e.length,e=e.substring(o.raw.length);continue}if(o=this.tokenizer.text(e)){e=e.substring(o.raw.length);const i=r.at(-1);i?.type==="text"?(i.raw+=`
44
- `+o.raw,i.text+=`
45
- `+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):r.push(o);continue}if(e){const i="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(i);break}else throw new Error(i)}}return this.state.top=!0,r}inline(e,r=[]){return this.inlineQueue.push({src:e,tokens:r}),r}inlineTokens(e,r=[]){let s=e,o=null;if(this.tokens.links){const c=Object.keys(this.tokens.links);if(c.length>0)for(;(o=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)c.includes(o[0].slice(o[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(o=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,o.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(o=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)s=s.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let a=!1,i="";for(;e;){a||(i=""),a=!1;let c;if(this.options.extensions?.inline?.some(b=>(c=b.call({lexer:this},e,r))?(e=e.substring(c.raw.length),r.push(c),!0):!1))continue;if(c=this.tokenizer.escape(e)){e=e.substring(c.raw.length),r.push(c);continue}if(c=this.tokenizer.tag(e)){e=e.substring(c.raw.length),r.push(c);continue}if(c=this.tokenizer.link(e)){e=e.substring(c.raw.length),r.push(c);continue}if(c=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(c.raw.length);const b=r.at(-1);c.type==="text"&&b?.type==="text"?(b.raw+=c.raw,b.text+=c.text):r.push(c);continue}if(c=this.tokenizer.emStrong(e,s,i)){e=e.substring(c.raw.length),r.push(c);continue}if(c=this.tokenizer.codespan(e)){e=e.substring(c.raw.length),r.push(c);continue}if(c=this.tokenizer.br(e)){e=e.substring(c.raw.length),r.push(c);continue}if(c=this.tokenizer.del(e)){e=e.substring(c.raw.length),r.push(c);continue}if(c=this.tokenizer.autolink(e)){e=e.substring(c.raw.length),r.push(c);continue}if(!this.state.inLink&&(c=this.tokenizer.url(e))){e=e.substring(c.raw.length),r.push(c);continue}let _=e;if(this.options.extensions?.startInline){let b=1/0;const v=e.slice(1);let A;this.options.extensions.startInline.forEach($=>{A=$.call({lexer:this},v),typeof A=="number"&&A>=0&&(b=Math.min(b,A))}),b<1/0&&b>=0&&(_=e.substring(0,b+1))}if(c=this.tokenizer.inlineText(_)){e=e.substring(c.raw.length),c.raw.slice(-1)!=="_"&&(i=c.raw.slice(-1)),a=!0;const b=r.at(-1);b?.type==="text"?(b.raw+=c.raw,b.text+=c.text):r.push(c);continue}if(e){const b="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(b);break}else throw new Error(b)}}return r}},Vr=class{options;parser;constructor(n){this.options=n||nr}space(n){return""}code({text:n,lang:e,escaped:r}){const s=(e||"").match(pn.notSpaceStart)?.[0],o=n.replace(pn.endingNewline,"")+`
46
- `;return s?'<pre><code class="language-'+Rn(s)+'">'+(r?o:Rn(o,!0))+`</code></pre>
47
- `:"<pre><code>"+(r?o:Rn(o,!0))+`</code></pre>
48
- `}blockquote({tokens:n}){return`<blockquote>
49
- ${this.parser.parse(n)}</blockquote>
50
- `}html({text:n}){return n}heading({tokens:n,depth:e}){return`<h${e}>${this.parser.parseInline(n)}</h${e}>
51
- `}hr(n){return`<hr>
52
- `}list(n){const e=n.ordered,r=n.start;let s="";for(let i=0;i<n.items.length;i++){const c=n.items[i];s+=this.listitem(c)}const o=e?"ol":"ul",a=e&&r!==1?' start="'+r+'"':"";return"<"+o+a+`>
53
- `+s+"</"+o+`>
54
- `}listitem(n){let e="";if(n.task){const r=this.checkbox({checked:!!n.checked});n.loose?n.tokens[0]?.type==="paragraph"?(n.tokens[0].text=r+" "+n.tokens[0].text,n.tokens[0].tokens&&n.tokens[0].tokens.length>0&&n.tokens[0].tokens[0].type==="text"&&(n.tokens[0].tokens[0].text=r+" "+Rn(n.tokens[0].tokens[0].text),n.tokens[0].tokens[0].escaped=!0)):n.tokens.unshift({type:"text",raw:r+" ",text:r+" ",escaped:!0}):e+=r+" "}return e+=this.parser.parse(n.tokens,!!n.loose),`<li>${e}</li>
55
- `}checkbox({checked:n}){return"<input "+(n?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:n}){return`<p>${this.parser.parseInline(n)}</p>
56
- `}table(n){let e="",r="";for(let o=0;o<n.header.length;o++)r+=this.tablecell(n.header[o]);e+=this.tablerow({text:r});let s="";for(let o=0;o<n.rows.length;o++){const a=n.rows[o];r="";for(let i=0;i<a.length;i++)r+=this.tablecell(a[i]);s+=this.tablerow({text:r})}return s&&(s=`<tbody>${s}</tbody>`),`<table>
57
- <thead>
58
- `+e+`</thead>
59
- `+s+`</table>
60
- `}tablerow({text:n}){return`<tr>
61
- ${n}</tr>
62
- `}tablecell(n){const e=this.parser.parseInline(n.tokens),r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+e+`</${r}>
63
- `}strong({tokens:n}){return`<strong>${this.parser.parseInline(n)}</strong>`}em({tokens:n}){return`<em>${this.parser.parseInline(n)}</em>`}codespan({text:n}){return`<code>${Rn(n,!0)}</code>`}br(n){return"<br>"}del({tokens:n}){return`<del>${this.parser.parseInline(n)}</del>`}link({href:n,title:e,tokens:r}){const s=this.parser.parseInline(r),o=ho(n);if(o===null)return s;n=o;let a='<a href="'+n+'"';return e&&(a+=' title="'+Rn(e)+'"'),a+=">"+s+"</a>",a}image({href:n,title:e,text:r,tokens:s}){s&&(r=this.parser.parseInline(s,this.parser.textRenderer));const o=ho(n);if(o===null)return Rn(r);n=o;let a=`<img src="${n}" alt="${r}"`;return e&&(a+=` title="${Rn(e)}"`),a+=">",a}text(n){return"tokens"in n&&n.tokens?this.parser.parseInline(n.tokens):"escaped"in n&&n.escaped?n.text:Rn(n.text)}},Js=class{strong({text:n}){return n}em({text:n}){return n}codespan({text:n}){return n}del({text:n}){return n}html({text:n}){return n}text({text:n}){return n}link({text:n}){return""+n}image({text:n}){return""+n}br(){return""}},Pn=class Cs{options;renderer;textRenderer;constructor(e){this.options=e||nr,this.options.renderer=this.options.renderer||new Vr,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Js}static parse(e,r){return new Cs(r).parse(e)}static parseInline(e,r){return new Cs(r).parseInline(e)}parse(e,r=!0){let s="";for(let o=0;o<e.length;o++){const a=e[o];if(this.options.extensions?.renderers?.[a.type]){const c=a,_=this.options.extensions.renderers[c.type].call({parser:this},c);if(_!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(c.type)){s+=_||"";continue}}const i=a;switch(i.type){case"space":{s+=this.renderer.space(i);continue}case"hr":{s+=this.renderer.hr(i);continue}case"heading":{s+=this.renderer.heading(i);continue}case"code":{s+=this.renderer.code(i);continue}case"table":{s+=this.renderer.table(i);continue}case"blockquote":{s+=this.renderer.blockquote(i);continue}case"list":{s+=this.renderer.list(i);continue}case"html":{s+=this.renderer.html(i);continue}case"paragraph":{s+=this.renderer.paragraph(i);continue}case"text":{let c=i,_=this.renderer.text(c);for(;o+1<e.length&&e[o+1].type==="text";)c=e[++o],_+=`
64
- `+this.renderer.text(c);r?s+=this.renderer.paragraph({type:"paragraph",raw:_,text:_,tokens:[{type:"text",raw:_,text:_,escaped:!0}]}):s+=_;continue}default:{const c='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(c),"";throw new Error(c)}}}return s}parseInline(e,r=this.renderer){let s="";for(let o=0;o<e.length;o++){const a=e[o];if(this.options.extensions?.renderers?.[a.type]){const c=this.options.extensions.renderers[a.type].call({parser:this},a);if(c!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(a.type)){s+=c||"";continue}}const i=a;switch(i.type){case"escape":{s+=r.text(i);break}case"html":{s+=r.html(i);break}case"link":{s+=r.link(i);break}case"image":{s+=r.image(i);break}case"strong":{s+=r.strong(i);break}case"em":{s+=r.em(i);break}case"codespan":{s+=r.codespan(i);break}case"br":{s+=r.br(i);break}case"del":{s+=r.del(i);break}case"text":{s+=r.text(i);break}default:{const c='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(c),"";throw new Error(c)}}}return s}},Hr=class{options;block;constructor(n){this.options=n||nr}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(n){return n}postprocess(n){return n}processAllTokens(n){return n}provideLexer(){return this.block?Ln.lex:Ln.lexInline}provideParser(){return this.block?Pn.parse:Pn.parseInline}},Rl=class{defaults=js();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Pn;Renderer=Vr;TextRenderer=Js;Lexer=Ln;Tokenizer=qr;Hooks=Hr;constructor(...n){this.use(...n)}walkTokens(n,e){let r=[];for(const s of n)switch(r=r.concat(e.call(this,s)),s.type){case"table":{const o=s;for(const a of o.header)r=r.concat(this.walkTokens(a.tokens,e));for(const a of o.rows)for(const i of a)r=r.concat(this.walkTokens(i.tokens,e));break}case"list":{const o=s;r=r.concat(this.walkTokens(o.items,e));break}default:{const o=s;this.defaults.extensions?.childTokens?.[o.type]?this.defaults.extensions.childTokens[o.type].forEach(a=>{const i=o[a].flat(1/0);r=r.concat(this.walkTokens(i,e))}):o.tokens&&(r=r.concat(this.walkTokens(o.tokens,e)))}}return r}use(...n){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return n.forEach(r=>{const s={...r};if(s.async=this.defaults.async||s.async||!1,r.extensions&&(r.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if("renderer"in o){const a=e.renderers[o.name];a?e.renderers[o.name]=function(...i){let c=o.renderer.apply(this,i);return c===!1&&(c=a.apply(this,i)),c}:e.renderers[o.name]=o.renderer}if("tokenizer"in o){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const a=e[o.level];a?a.unshift(o.tokenizer):e[o.level]=[o.tokenizer],o.start&&(o.level==="block"?e.startBlock?e.startBlock.push(o.start):e.startBlock=[o.start]:o.level==="inline"&&(e.startInline?e.startInline.push(o.start):e.startInline=[o.start]))}"childTokens"in o&&o.childTokens&&(e.childTokens[o.name]=o.childTokens)}),s.extensions=e),r.renderer){const o=this.defaults.renderer||new Vr(this.defaults);for(const a in r.renderer){if(!(a in o))throw new Error(`renderer '${a}' does not exist`);if(["options","parser"].includes(a))continue;const i=a,c=r.renderer[i],_=o[i];o[i]=(...b)=>{let v=c.apply(o,b);return v===!1&&(v=_.apply(o,b)),v||""}}s.renderer=o}if(r.tokenizer){const o=this.defaults.tokenizer||new qr(this.defaults);for(const a in r.tokenizer){if(!(a in o))throw new Error(`tokenizer '${a}' does not exist`);if(["options","rules","lexer"].includes(a))continue;const i=a,c=r.tokenizer[i],_=o[i];o[i]=(...b)=>{let v=c.apply(o,b);return v===!1&&(v=_.apply(o,b)),v}}s.tokenizer=o}if(r.hooks){const o=this.defaults.hooks||new Hr;for(const a in r.hooks){if(!(a in o))throw new Error(`hook '${a}' does not exist`);if(["options","block"].includes(a))continue;const i=a,c=r.hooks[i],_=o[i];Hr.passThroughHooks.has(a)?o[i]=b=>{if(this.defaults.async)return Promise.resolve(c.call(o,b)).then(A=>_.call(o,A));const v=c.call(o,b);return _.call(o,v)}:o[i]=(...b)=>{let v=c.apply(o,b);return v===!1&&(v=_.apply(o,b)),v}}s.hooks=o}if(r.walkTokens){const o=this.defaults.walkTokens,a=r.walkTokens;s.walkTokens=function(i){let c=[];return c.push(a.call(this,i)),o&&(c=c.concat(o.call(this,i))),c}}this.defaults={...this.defaults,...s}}),this}setOptions(n){return this.defaults={...this.defaults,...n},this}lexer(n,e){return Ln.lex(n,e??this.defaults)}parser(n,e){return Pn.parse(n,e??this.defaults)}parseMarkdown(n){return(r,s)=>{const o={...s},a={...this.defaults,...o},i=this.onError(!!a.silent,!!a.async);if(this.defaults.async===!0&&o.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof r>"u"||r===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof r!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(r)+", string expected"));a.hooks&&(a.hooks.options=a,a.hooks.block=n);const c=a.hooks?a.hooks.provideLexer():n?Ln.lex:Ln.lexInline,_=a.hooks?a.hooks.provideParser():n?Pn.parse:Pn.parseInline;if(a.async)return Promise.resolve(a.hooks?a.hooks.preprocess(r):r).then(b=>c(b,a)).then(b=>a.hooks?a.hooks.processAllTokens(b):b).then(b=>a.walkTokens?Promise.all(this.walkTokens(b,a.walkTokens)).then(()=>b):b).then(b=>_(b,a)).then(b=>a.hooks?a.hooks.postprocess(b):b).catch(i);try{a.hooks&&(r=a.hooks.preprocess(r));let b=c(r,a);a.hooks&&(b=a.hooks.processAllTokens(b)),a.walkTokens&&this.walkTokens(b,a.walkTokens);let v=_(b,a);return a.hooks&&(v=a.hooks.postprocess(v)),v}catch(b){return i(b)}}}onError(n,e){return r=>{if(r.message+=`
65
- Please report this to https://github.com/markedjs/marked.`,n){const s="<p>An error occurred:</p><pre>"+Rn(r.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(r);throw r}}},er=new Rl;function ut(n,e){return er.parse(n,e)}ut.options=ut.setOptions=function(n){return er.setOptions(n),ut.defaults=er.defaults,ma(ut.defaults),ut};ut.getDefaults=js;ut.defaults=nr;ut.use=function(...n){return er.use(...n),ut.defaults=er.defaults,ma(ut.defaults),ut};ut.walkTokens=function(n,e){return er.walkTokens(n,e)};ut.parseInline=er.parseInline;ut.Parser=Pn;ut.parser=Pn.parse;ut.Renderer=Vr;ut.TextRenderer=Js;ut.Lexer=Ln;ut.lexer=Ln.lex;ut.Tokenizer=qr;ut.Hooks=Hr;ut.parse=ut;ut.options;ut.setOptions;ut.use;ut.walkTokens;ut.parseInline;Pn.parse;Ln.lex;function go(n,e){(e==null||e>n.length)&&(e=n.length);for(var r=0,s=Array(e);r<e;r++)s[r]=n[r];return s}function Il(n){if(Array.isArray(n))return n}function $l(n,e){var r=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(r!=null){var s,o,a,i,c=[],_=!0,b=!1;try{if(a=(r=r.call(n)).next,e!==0)for(;!(_=(s=a.call(r)).done)&&(c.push(s.value),c.length!==e);_=!0);}catch(v){b=!0,o=v}finally{try{if(!_&&r.return!=null&&(i=r.return(),Object(i)!==i))return}finally{if(b)throw o}}return c}}function Ml(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
66
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ol(n,e){return Il(n)||$l(n,e)||Dl(n,e)||Ml()}function Dl(n,e){if(n){if(typeof n=="string")return go(n,e);var r={}.toString.call(n).slice(8,-1);return r==="Object"&&n.constructor&&(r=n.constructor.name),r==="Map"||r==="Set"?Array.from(n):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?go(n,e):void 0}}const Ra=Object.entries,mo=Object.setPrototypeOf,Ll=Object.isFrozen,Pl=Object.getPrototypeOf,Nl=Object.getOwnPropertyDescriptor;let sn=Object.freeze,on=Object.seal,lr=Object.create,Ia=typeof Reflect<"u"&&Reflect,Rs=Ia.apply,Is=Ia.construct;sn||(sn=function(e){return e});on||(on=function(e){return e});Rs||(Rs=function(e,r){for(var s=arguments.length,o=new Array(s>2?s-2:0),a=2;a<s;a++)o[a-2]=arguments[a];return e.apply(r,o)});Is||(Is=function(e){for(var r=arguments.length,s=new Array(r>1?r-1:0),o=1;o<r;o++)s[o-1]=arguments[o];return new e(...s)});const _r=qt(Array.prototype.forEach),Fl=qt(Array.prototype.lastIndexOf),xo=qt(Array.prototype.pop),ar=qt(Array.prototype.push),Ul=qt(Array.prototype.splice),Gn=Array.isArray,Tr=qt(String.prototype.toLowerCase),ds=qt(String.prototype.toString),_o=qt(String.prototype.match),yr=qt(String.prototype.replace),yo=qt(String.prototype.indexOf),zl=qt(String.prototype.trim),Bl=qt(Number.prototype.toString),Hl=qt(Boolean.prototype.toString),wo=typeof BigInt>"u"?null:qt(BigInt.prototype.toString),ko=typeof Symbol>"u"?null:qt(Symbol.prototype.toString),en=qt(Object.prototype.hasOwnProperty),wr=qt(Object.prototype.toString),rn=qt(RegExp.prototype.test),Zn=Wl(TypeError);function qt(n){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var r=arguments.length,s=new Array(r>1?r-1:0),o=1;o<r;o++)s[o-1]=arguments[o];return Rs(n,e,s)}}function Wl(n){return function(){for(var e=arguments.length,r=new Array(e),s=0;s<e;s++)r[s]=arguments[s];return Is(n,r)}}function nt(n,e){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Tr;if(mo&&mo(n,null),!Gn(e))return n;let s=e.length;for(;s--;){let o=e[s];if(typeof o=="string"){const a=r(o);a!==o&&(Ll(e)||(e[s]=a),o=a)}n[o]=!0}return n}function Gl(n){for(let e=0;e<n.length;e++)en(n,e)||(n[e]=null);return n}function fn(n){const e=lr(null);for(const s of Ra(n)){var r=Ol(s,2);const o=r[0],a=r[1];en(n,o)&&(Gn(a)?e[o]=Gl(a):a&&typeof a=="object"&&a.constructor===Object?e[o]=fn(a):e[o]=a)}return e}function jl(n){switch(typeof n){case"string":return n;case"number":return Bl(n);case"boolean":return Hl(n);case"bigint":return wo?wo(n):"0";case"symbol":return ko?ko(n):"Symbol()";case"undefined":return wr(n);case"function":case"object":{if(n===null)return wr(n);const e=n,r=In(e,"toString");if(typeof r=="function"){const s=r(e);return typeof s=="string"?s:wr(s)}return wr(n)}default:return wr(n)}}function In(n,e){for(;n!==null;){const s=Nl(n,e);if(s){if(s.get)return qt(s.get);if(typeof s.value=="function")return qt(s.value)}n=Pl(n)}function r(){return null}return r}function ql(n){try{return rn(n,""),!0}catch{return!1}}const So=sn(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),us=sn(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),fs=sn(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Vl=sn(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),ps=sn(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),Kl=sn(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),To=sn(["#text"]),Ao=sn(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),hs=sn(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Eo=sn(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Ur=sn(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Yl=on(/{{[\w\W]*|^[\w\W]*}}/g),Zl=on(/<%[\w\W]*|^[\w\W]*%>/g),Xl=on(/\${[\w\W]*/g),Ql=on(/^data-[\-\w.\u00B7-\uFFFF]+$/),Jl=on(/^aria-[\-\w]+$/),Co=on(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ec=on(/^(?:\w+script|data):/i),tc=on(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),nc=on(/^html$/i),rc=on(/^[a-z][.\w]*(-[.\w]+)+$/i),Ro=on(/<[/\w!]/g),sc=on(/<[/\w]/g),oc=on(/<\/no(script|embed|frames)/i),ac=on(/\/>/i),Cn={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},ic=function(){return typeof window>"u"?null:window},lc=function(e,r){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let s=null;const o="data-tt-policy-suffix";r&&r.hasAttribute(o)&&(s=r.getAttribute(o));const a="dompurify"+(s?"#"+s:"");try{return e.createPolicy(a,{createHTML(i){return i},createScriptURL(i){return i}})}catch{return console.warn("TrustedTypes policy "+a+" could not be created."),null}},Io=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Hn=function(e,r,s,o){return en(e,r)&&Gn(e[r])?nt(o.base?fn(o.base):{},e[r],o.transform):s};function $a(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:ic();const e=R=>$a(R);if(e.version="3.4.11",e.removed=[],!n||!n.document||n.document.nodeType!==Cn.document||!n.Element)return e.isSupported=!1,e;let r=n.document;const s=r,o=s.currentScript;n.DocumentFragment;const a=n.HTMLTemplateElement,i=n.Node,c=n.Element,_=n.NodeFilter,b=n.NamedNodeMap;b===void 0&&(n.NamedNodeMap||n.MozNamedAttrMap),n.HTMLFormElement;const v=n.DOMParser,A=n.trustedTypes,$=c.prototype,O=In($,"cloneNode"),k=In($,"remove"),ae=In($,"nextSibling"),se=In($,"childNodes"),he=In($,"parentNode"),ie=In($,"shadowRoot"),rt=In($,"attributes"),Me=i&&i.prototype?In(i.prototype,"nodeType"):null,Ge=i&&i.prototype?In(i.prototype,"nodeName"):null;if(typeof a=="function"){const R=r.createElement("template");R.content&&R.content.ownerDocument&&(r=R.content.ownerDocument)}let le,Pe="",st,Ct=!1,at=0;const be=function(){if(at>0)throw Zn('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},je=function(l){be(),at++;try{return le.createHTML(l)}finally{at--}},_t=function(l){be(),at++;try{return le.createScriptURL(l)}finally{at--}},ot=function(){return Ct||(st=lc(A,o),Ct=!0),st},Je=r,et=Je.implementation,Mt=Je.createNodeIterator,Rt=Je.createDocumentFragment,ve=Je.getElementsByTagName,pt=s.importNode;let te=Io();e.isSupported=typeof Ra=="function"&&typeof he=="function"&&et&&et.createHTMLDocument!==void 0;const Ft=Yl,ye=Zl,ht=Xl,hn=Ql,Ee=Jl,lt=ec,Vt=tc,j=rc;let ge=Co,S=null;const J=nt({},[...So,...us,...fs,...ps,...To]);let T=null;const ee=nt({},[...Ao,...hs,...Eo,...Ur]);let U=Object.seal(lr(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),we=null,me=null;const Ze=Object.seal(lr(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let Ve=!0,yt=!0,Tt=!1,Ye=!0,Ce=!1,Ut=!0,zt=!1,an=!1,cn=null,tt=null,wt=!1,kt=!1,Xt=!1,Bt=!1,Qt=!0,dn=!1;const Re="user-content-";let bt=!0,Ht=!1,St={},vt=null;const Kt=nt({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]);let tn=null;const un=nt({},["audio","video","img","source","image","track"]);let bn=null;const En=nt({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),I="http://www.w3.org/1998/Math/MathML",W="http://www.w3.org/2000/svg",K="http://www.w3.org/1999/xhtml";let Y=K,ke=!1,Ot=null;const Et=nt({},[I,W,K],ds),Dt=sn(["mi","mo","mn","ms","mtext"]);let At=nt({},Dt);const C=sn(["annotation-xml"]);let D=nt({},C);const de=nt({},["title","style","font","a","script"]);let Oe=null;const Ne=["application/xhtml+xml","text/html"],ze="text/html";let G=null,xe=null;const x=r.createElement("form"),y=function(l){return l instanceof RegExp||l instanceof Function},L=function(){let l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(xe&&xe===l)return;(!l||typeof l!="object")&&(l={}),l=fn(l),Oe=Ne.indexOf(l.PARSER_MEDIA_TYPE)===-1?ze:l.PARSER_MEDIA_TYPE,G=Oe==="application/xhtml+xml"?ds:Tr,S=Hn(l,"ALLOWED_TAGS",J,{transform:G}),T=Hn(l,"ALLOWED_ATTR",ee,{transform:G}),Ot=Hn(l,"ALLOWED_NAMESPACES",Et,{transform:ds}),bn=Hn(l,"ADD_URI_SAFE_ATTR",En,{transform:G,base:En}),tn=Hn(l,"ADD_DATA_URI_TAGS",un,{transform:G,base:un}),vt=Hn(l,"FORBID_CONTENTS",Kt,{transform:G}),we=Hn(l,"FORBID_TAGS",fn({}),{transform:G}),me=Hn(l,"FORBID_ATTR",fn({}),{transform:G}),St=en(l,"USE_PROFILES")?l.USE_PROFILES&&typeof l.USE_PROFILES=="object"?fn(l.USE_PROFILES):l.USE_PROFILES:!1,Ve=l.ALLOW_ARIA_ATTR!==!1,yt=l.ALLOW_DATA_ATTR!==!1,Tt=l.ALLOW_UNKNOWN_PROTOCOLS||!1,Ye=l.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Ce=l.SAFE_FOR_TEMPLATES||!1,Ut=l.SAFE_FOR_XML!==!1,zt=l.WHOLE_DOCUMENT||!1,kt=l.RETURN_DOM||!1,Xt=l.RETURN_DOM_FRAGMENT||!1,Bt=l.RETURN_TRUSTED_TYPE||!1,wt=l.FORCE_BODY||!1,Qt=l.SANITIZE_DOM!==!1,dn=l.SANITIZE_NAMED_PROPS||!1,bt=l.KEEP_CONTENT!==!1,Ht=l.IN_PLACE||!1,ge=ql(l.ALLOWED_URI_REGEXP)?l.ALLOWED_URI_REGEXP:Co,Y=typeof l.NAMESPACE=="string"?l.NAMESPACE:K,At=en(l,"MATHML_TEXT_INTEGRATION_POINTS")&&l.MATHML_TEXT_INTEGRATION_POINTS&&typeof l.MATHML_TEXT_INTEGRATION_POINTS=="object"?fn(l.MATHML_TEXT_INTEGRATION_POINTS):nt({},Dt),D=en(l,"HTML_INTEGRATION_POINTS")&&l.HTML_INTEGRATION_POINTS&&typeof l.HTML_INTEGRATION_POINTS=="object"?fn(l.HTML_INTEGRATION_POINTS):nt({},C);const g=en(l,"CUSTOM_ELEMENT_HANDLING")&&l.CUSTOM_ELEMENT_HANDLING&&typeof l.CUSTOM_ELEMENT_HANDLING=="object"?fn(l.CUSTOM_ELEMENT_HANDLING):lr(null);if(U=lr(null),en(g,"tagNameCheck")&&y(g.tagNameCheck)&&(U.tagNameCheck=g.tagNameCheck),en(g,"attributeNameCheck")&&y(g.attributeNameCheck)&&(U.attributeNameCheck=g.attributeNameCheck),en(g,"allowCustomizedBuiltInElements")&&typeof g.allowCustomizedBuiltInElements=="boolean"&&(U.allowCustomizedBuiltInElements=g.allowCustomizedBuiltInElements),on(U),Ce&&(yt=!1),Xt&&(kt=!0),St&&(S=nt({},To),T=lr(null),St.html===!0&&(nt(S,So),nt(T,Ao)),St.svg===!0&&(nt(S,us),nt(T,hs),nt(T,Ur)),St.svgFilters===!0&&(nt(S,fs),nt(T,hs),nt(T,Ur)),St.mathMl===!0&&(nt(S,ps),nt(T,Eo),nt(T,Ur))),Ze.tagCheck=null,Ze.attributeCheck=null,en(l,"ADD_TAGS")&&(typeof l.ADD_TAGS=="function"?Ze.tagCheck=l.ADD_TAGS:Gn(l.ADD_TAGS)&&(S===J&&(S=fn(S)),nt(S,l.ADD_TAGS,G))),en(l,"ADD_ATTR")&&(typeof l.ADD_ATTR=="function"?Ze.attributeCheck=l.ADD_ATTR:Gn(l.ADD_ATTR)&&(T===ee&&(T=fn(T)),nt(T,l.ADD_ATTR,G))),en(l,"ADD_URI_SAFE_ATTR")&&Gn(l.ADD_URI_SAFE_ATTR)&&nt(bn,l.ADD_URI_SAFE_ATTR,G),en(l,"FORBID_CONTENTS")&&Gn(l.FORBID_CONTENTS)&&(vt===Kt&&(vt=fn(vt)),nt(vt,l.FORBID_CONTENTS,G)),en(l,"ADD_FORBID_CONTENTS")&&Gn(l.ADD_FORBID_CONTENTS)&&(vt===Kt&&(vt=fn(vt)),nt(vt,l.ADD_FORBID_CONTENTS,G)),bt&&(S["#text"]=!0),zt&&nt(S,["html","head","body"]),S.table&&(nt(S,["tbody"]),delete we.tbody),l.TRUSTED_TYPES_POLICY){if(typeof l.TRUSTED_TYPES_POLICY.createHTML!="function")throw Zn('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof l.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Zn('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const M=le;le=l.TRUSTED_TYPES_POLICY;try{Pe=je("")}catch(q){throw le=M,q}}else l.TRUSTED_TYPES_POLICY===null?(le=void 0,Pe=""):(le===void 0&&(le=ot()),le&&typeof Pe=="string"&&(Pe=je("")));sn&&sn(l),xe=l},z=nt({},[...us,...fs,...Vl]),fe=nt({},[...ps,...Kl]),X=function(l,g,M){return g.namespaceURI===K?l==="svg":g.namespaceURI===I?l==="svg"&&(M==="annotation-xml"||At[M]):!!z[l]},w=function(l,g,M){return g.namespaceURI===K?l==="math":g.namespaceURI===W?l==="math"&&D[M]:!!fe[l]},ce=function(l,g,M){return g.namespaceURI===W&&!D[M]||g.namespaceURI===I&&!At[M]?!1:!fe[l]&&(de[l]||!z[l])},P=function(l){let g=he(l);(!g||!g.tagName)&&(g={namespaceURI:Y,tagName:"template"});const M=Tr(l.tagName),q=Tr(g.tagName);return Ot[l.namespaceURI]?l.namespaceURI===W?X(M,g,q):l.namespaceURI===I?w(M,g,q):l.namespaceURI===K?ce(M,g,q):!!(Oe==="application/xhtml+xml"&&Ot[l.namespaceURI]):!1},F=function(l){ar(e.removed,{element:l});try{he(l).removeChild(l)}catch{if(k(l),!he(l))throw Zn("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},Te=function(l){const g=se(l);if(g){const q=[];_r(g,$e=>{ar(q,$e)}),_r(q,$e=>{try{k($e)}catch{}})}const M=rt(l);if(M)for(let q=M.length-1;q>=0;--q){const $e=M[q],Xe=$e&&$e.name;if(typeof Xe=="string")try{l.removeAttribute(Xe)}catch{}}},ne=function(l,g){try{ar(e.removed,{attribute:g.getAttributeNode(l),from:g})}catch{ar(e.removed,{attribute:null,from:g})}if(g.removeAttribute(l),l==="is")if(kt||Xt)try{F(g)}catch{}else try{g.setAttribute(l,"")}catch{}},Se=function(l){const g=rt(l);if(g)for(let M=g.length-1;M>=0;--M){const q=g[M],$e=q&&q.name;if(!(typeof $e!="string"||T[G($e)]))try{l.removeAttribute($e)}catch{}}},_e=function(l){const g=[l];for(;g.length>0;){const M=g.pop();(Me?Me(M):M.nodeType)===Cn.element&&Se(M);const $e=se(M);if($e)for(let Xe=$e.length-1;Xe>=0;--Xe)g.push($e[Xe])}},De=function(l){let g=null,M=null;if(wt)l="<remove></remove>"+l;else{const Xe=_o(l,/^[\r\n\t ]+/);M=Xe&&Xe[0]}Oe==="application/xhtml+xml"&&Y===K&&(l='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+l+"</body></html>");const q=le?je(l):l;if(Y===K)try{g=new v().parseFromString(q,Oe)}catch{}if(!g||!g.documentElement){g=et.createDocument(Y,"template",null);try{g.documentElement.innerHTML=ke?Pe:q}catch{}}const $e=g.body||g.documentElement;return l&&M&&$e.insertBefore(r.createTextNode(M),$e.childNodes[0]||null),Y===K?ve.call(g,zt?"html":"body")[0]:zt?g.documentElement:$e},gt=function(l){return Mt.call(l.ownerDocument||l,l,_.SHOW_ELEMENT|_.SHOW_COMMENT|_.SHOW_TEXT|_.SHOW_PROCESSING_INSTRUCTION|_.SHOW_CDATA_SECTION,null)},Be=function(l){return l=yr(l,Ft," "),l=yr(l,ye," "),l=yr(l,ht," "),l},Ke=function(l){var g;l.normalize();const M=Mt.call(l.ownerDocument||l,l,_.SHOW_TEXT|_.SHOW_COMMENT|_.SHOW_CDATA_SECTION|_.SHOW_PROCESSING_INSTRUCTION,null);let q=M.nextNode();for(;q;)q.data=Be(q.data),q=M.nextNode();const $e=(g=l.querySelectorAll)===null||g===void 0?void 0:g.call(l,"template");$e&&_r($e,Xe=>{qe(Xe.content)&&Ke(Xe.content)})},He=function(l){const g=Ge?Ge(l):null;return typeof g!="string"||G(g)!=="form"?!1:typeof l.nodeName!="string"||typeof l.textContent!="string"||typeof l.removeChild!="function"||l.attributes!==rt(l)||typeof l.removeAttribute!="function"||typeof l.setAttribute!="function"||typeof l.namespaceURI!="string"||typeof l.insertBefore!="function"||typeof l.hasChildNodes!="function"||l.nodeType!==Me(l)||l.childNodes!==se(l)},qe=function(l){if(!Me||typeof l!="object"||l===null)return!1;try{return Me(l)===Cn.documentFragment}catch{return!1}},mt=function(l){if(!Me||typeof l!="object"||l===null)return!1;try{return typeof Me(l)=="number"}catch{return!1}};function Ie(R,l,g){R.length!==0&&_r(R,M=>{M.call(e,l,g,xe)})}const Z=function(l,g){return!!(Ut&&l.hasChildNodes()&&!mt(l.firstElementChild)&&rn(Ro,l.textContent)&&rn(Ro,l.innerHTML)||Ut&&l.namespaceURI===K&&g==="style"&&mt(l.firstElementChild)||l.nodeType===Cn.processingInstruction||Ut&&l.nodeType===Cn.comment&&rn(sc,l.data))},oe=function(l,g){if(!we[g]&&Ae(g)&&(U.tagNameCheck instanceof RegExp&&rn(U.tagNameCheck,g)||U.tagNameCheck instanceof Function&&U.tagNameCheck(g)))return!1;if(bt&&!vt[g]){const M=he(l),q=se(l);if(q&&M){const $e=q.length;for(let Xe=$e-1;Xe>=0;--Xe){const Gt=Ht?q[Xe]:O(q[Xe],!0);M.insertBefore(Gt,ae(l))}}}return F(l),!0},N=function(l){if(Ie(te.beforeSanitizeElements,l,null),He(l))return F(l),!0;const g=G(Ge?Ge(l):l.nodeName);if(Ie(te.uponSanitizeElement,l,{tagName:g,allowedTags:S}),Z(l,g))return F(l),!0;if(we[g]||!(Ze.tagCheck instanceof Function&&Ze.tagCheck(g))&&!S[g])return oe(l,g);if((Me?Me(l):l.nodeType)===Cn.element&&!P(l)||(g==="noscript"||g==="noembed"||g==="noframes")&&rn(oc,l.innerHTML))return F(l),!0;if(Ce&&l.nodeType===Cn.text){const q=Be(l.textContent);l.textContent!==q&&(ar(e.removed,{element:l.cloneNode()}),l.textContent=q)}return Ie(te.afterSanitizeElements,l,null),!1},pe=function(l,g,M){if(me[g]||Qt&&(g==="id"||g==="name")&&(M in r||M in x))return!1;const q=T[g]||Ze.attributeCheck instanceof Function&&Ze.attributeCheck(g,l);if(!(yt&&rn(hn,g))){if(!(Ve&&rn(Ee,g))){if(q){if(!bn[g]){if(!rn(ge,yr(M,Vt,""))){if(!((g==="src"||g==="xlink:href"||g==="href")&&l!=="script"&&yo(M,"data:")===0&&tn[l])){if(!(Tt&&!rn(lt,yr(M,Vt,"")))){if(M)return!1}}}}}else if(!(Ae(l)&&(U.tagNameCheck instanceof RegExp&&rn(U.tagNameCheck,l)||U.tagNameCheck instanceof Function&&U.tagNameCheck(l))&&(U.attributeNameCheck instanceof RegExp&&rn(U.attributeNameCheck,g)||U.attributeNameCheck instanceof Function&&U.attributeNameCheck(g,l))||g==="is"&&U.allowCustomizedBuiltInElements&&(U.tagNameCheck instanceof RegExp&&rn(U.tagNameCheck,M)||U.tagNameCheck instanceof Function&&U.tagNameCheck(M))))return!1}}return!0},We=nt({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Ae=function(l){return!We[Tr(l)]&&rn(j,l)},ue=function(l,g,M,q){if(le&&typeof A=="object"&&typeof A.getAttributeType=="function"&&!M)switch(A.getAttributeType(l,g)){case"TrustedHTML":return je(q);case"TrustedScriptURL":return _t(q)}return q},Le=function(l,g,M,q){try{M?l.setAttributeNS(M,g,q):l.setAttribute(g,q),He(l)?F(l):xo(e.removed)}catch{ne(g,l)}},It=function(l){Ie(te.beforeSanitizeAttributes,l,null);const g=l.attributes;if(!g||He(l))return;const M={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:T,forceKeepAttr:void 0};let q=g.length;const $e=G(l.nodeName);for(;q--;){const Xe=g[q],Gt=Xe.name,Pt=Xe.namespaceURI,vn=Xe.value,mn=G(Gt),rr=vn;let nn=Gt==="value"?rr:zl(rr);if(M.attrName=mn,M.attrValue=nn,M.keepAttr=!0,M.forceKeepAttr=void 0,Ie(te.uponSanitizeAttribute,l,M),nn=M.attrValue,dn&&(mn==="id"||mn==="name")&&yo(nn,Re)!==0&&(ne(Gt,l),nn=Re+nn),Ut&&rn(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,nn)){ne(Gt,l);continue}if(mn==="attributename"&&_o(nn,"href")){ne(Gt,l);continue}if(!M.forceKeepAttr){if(!M.keepAttr){ne(Gt,l);continue}if(!Ye&&rn(ac,nn)){ne(Gt,l);continue}if(Ce&&(nn=Be(nn)),!pe($e,mn,nn)){ne(Gt,l);continue}nn=ue($e,mn,Pt,nn),nn!==rr&&Le(l,Gt,Pt,nn)}}Ie(te.afterSanitizeAttributes,l,null)},$t=function(l){let g=null;const M=gt(l);for(Ie(te.beforeSanitizeShadowDOM,l,null);g=M.nextNode();)if(Ie(te.uponSanitizeShadowNode,g,null),N(g),It(g),qe(g.content)&&$t(g.content),(Me?Me(g):g.nodeType)===Cn.element){const $e=ie(g);qe($e)&&(Wt($e),$t($e))}Ie(te.afterSanitizeShadowDOM,l,null)},Wt=function(l){const g=[{node:l,shadow:null}];for(;g.length>0;){const M=g.pop();if(M.shadow){$t(M.shadow);continue}const q=M.node,Xe=(Me?Me(q):q.nodeType)===Cn.element,Gt=se(q);if(Gt)for(let Pt=Gt.length-1;Pt>=0;--Pt)g.push({node:Gt[Pt],shadow:null});if(Xe){const Pt=Ge?Ge(q):null;if(typeof Pt=="string"&&G(Pt)==="template"){const vn=q.content;qe(vn)&&g.push({node:vn,shadow:null})}}if(Xe){const Pt=ie(q);qe(Pt)&&g.push({node:null,shadow:Pt},{node:Pt,shadow:null})}}};return e.sanitize=function(R){let l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},g=null,M=null,q=null,$e=null;if(ke=!R,ke&&(R="<!-->"),typeof R!="string"&&!mt(R)&&(R=jl(R),typeof R!="string"))throw Zn("dirty is not a string, aborting");if(!e.isSupported)return R;an?(S=cn,T=tt):L(l),(te.uponSanitizeElement.length>0||te.uponSanitizeAttribute.length>0)&&(S=fn(S)),te.uponSanitizeAttribute.length>0&&(T=fn(T)),e.removed=[];const Xe=Ht&&typeof R!="string"&&mt(R);if(Xe){const vn=Ge?Ge(R):R.nodeName;if(typeof vn=="string"){const mn=G(vn);if(!S[mn]||we[mn])throw Zn("root node is forbidden and cannot be sanitized in-place")}if(He(R))throw Zn("root node is clobbered and cannot be sanitized in-place");try{Wt(R)}catch(mn){throw Te(R),mn}}else if(mt(R))g=De("<!---->"),M=g.ownerDocument.importNode(R,!0),M.nodeType===Cn.element&&M.nodeName==="BODY"||M.nodeName==="HTML"?g=M:g.appendChild(M),Wt(M);else{if(!kt&&!Ce&&!zt&&R.indexOf("<")===-1)return le&&Bt?je(R):R;if(g=De(R),!g)return kt?null:Bt?Pe:""}g&&wt&&F(g.firstChild);const Gt=gt(Xe?R:g);try{for(;q=Gt.nextNode();)N(q),It(q),qe(q.content)&&$t(q.content)}catch(vn){throw Xe&&Te(R),vn}if(Xe)return _r(e.removed,vn=>{vn.element&&_e(vn.element)}),Ce&&Ke(R),R;if(kt){if(Ce&&Ke(g),Xt)for($e=Rt.call(g.ownerDocument);g.firstChild;)$e.appendChild(g.firstChild);else $e=g;return(T.shadowroot||T.shadowrootmode)&&($e=pt.call(s,$e,!0)),$e}let Pt=zt?g.outerHTML:g.innerHTML;return zt&&S["!doctype"]&&g.ownerDocument&&g.ownerDocument.doctype&&g.ownerDocument.doctype.name&&rn(nc,g.ownerDocument.doctype.name)&&(Pt="<!DOCTYPE "+g.ownerDocument.doctype.name+`>
67
- `+Pt),Ce&&(Pt=Be(Pt)),le&&Bt?je(Pt):Pt},e.setConfig=function(){let R=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};L(R),an=!0,cn=S,tt=T},e.clearConfig=function(){xe=null,an=!1,cn=null,tt=null,le=st,Pe=""},e.isValidAttribute=function(R,l,g){xe||L({});const M=G(R),q=G(l);return pe(M,q,g)},e.addHook=function(R,l){typeof l=="function"&&en(te,R)&&ar(te[R],l)},e.removeHook=function(R,l){if(en(te,R)){if(l!==void 0){const g=Fl(te[R],l);return g===-1?void 0:Ul(te[R],g,1)[0]}return xo(te[R])}},e.removeHooks=function(R){en(te,R)&&(te[R]=[])},e.removeAllHooks=function(){te=Io()},e}var Ma=$a();ut.setOptions({gfm:!0,breaks:!0});let $o=!1;function cc(){$o||typeof window>"u"||($o=!0,Ma.addHook("afterSanitizeAttributes",n=>{n.tagName==="A"&&(n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer"))}))}function dc(n){if(!n)return"";const e=ut.parse(n,{async:!1});return typeof window>"u"?"":(cc(),Ma.sanitize(e,{ADD_ATTR:["target","rel"]}))}var uc=m('<div class="flex flex-1 flex-col items-center justify-center bg-brand-dark p-6 text-brand-text-muted"><div class="text-center"><div class="mb-4 inline-block h-8 w-8 animate-spin rounded-full border-4 border-brand-blue border-t-transparent"></div> <p class="text-base font-medium text-brand-text">Connecting to Wherever Server...</p> <p class="mt-1 text-xs text-brand-text-muted">Establishing secure connection to your agent</p></div></div>'),fc=m('<p class="mt-3 max-h-24 overflow-y-auto rounded bg-brand-surface-3 p-2 font-mono text-xs text-rose-300/80"> </p>'),pc=m(`<div class="flex flex-1 flex-col items-center justify-center bg-brand-dark p-6 text-brand-text-muted"><div class="w-full max-w-md rounded-lg border border-red-500/30 bg-red-500/10 p-6 text-center text-brand-text"><div class="mb-3 text-4xl">⚠️</div> <h3 class="text-lg font-bold text-rose-400">Not Connected to Server</h3> <p class="mt-2 text-sm text-brand-text-muted">We couldn't connect to the Wherever Server. Please verify the server
68
- is running and check your connection settings in the sidebar.</p> <!> <button class="mt-5 rounded bg-brand-surface-2 px-4 py-2 text-sm font-semibold text-brand-text transition-colors hover:bg-brand-surface-3">Retry Connection</button></div></div>`),hc=m('<div class="flex flex-1 flex-col items-center justify-center bg-brand-dark p-6 text-brand-text-muted"><div class="text-center"><div class="mb-4 inline-block h-8 w-8 animate-spin rounded-full border-4 border-brand-blue border-t-transparent"></div> <p class="text-base font-medium text-brand-text">Loading session...</p> <p class="mt-1 text-xs text-brand-text-muted">Retrieving workspace session history</p></div></div>'),bc=m('<button type="button" class="block w-full px-3 py-1.5 text-left text-sm text-brand-text transition-colors hover:bg-brand-surface-3 hover:text-brand-text"> </button>'),vc=m('<div class="absolute right-0 left-0 z-50 mt-1 max-h-48 overflow-y-auto rounded border border-brand-border bg-brand-surface-2 py-1 shadow-xl"></div>'),gc=m('<span class="ml-1 font-medium text-emerald-400">(Git repo detected)</span>'),mc=m('<span class="mt-1.5 block text-xs font-medium text-yellow-400">📁 Folder already exists. Joining will create a session in it. <!></span>'),xc=m('<span class="mt-1 block text-[10px] text-brand-text-muted">Relative paths are created inside your home folder.</span>'),_c=m("<option> </option>"),yc=m('<select id="main-model-select" class="w-full rounded border border-brand-border bg-brand-surface-3 px-3 py-2 text-sm text-brand-text focus:border-brand-blue focus:outline-none"></select>'),wc=m('<input id="main-model-select" type="text" placeholder="provider:model" class="w-full rounded border border-brand-border bg-brand-surface-3 px-3 py-2 text-sm text-brand-text placeholder-brand-text-muted focus:border-brand-blue focus:outline-none"/>'),kc=m('<div class="flex items-center gap-4 pl-6 text-xs text-brand-text-muted"><span>Visibility:</span> <label class="flex cursor-pointer items-center gap-1.5 transition-colors select-none hover:text-brand-text"><input type="radio" name="main-visibility" class="border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue"/> Private</label> <label class="flex cursor-pointer items-center gap-1.5 transition-colors select-none hover:text-brand-text"><input type="radio" name="main-visibility" class="border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue"/> Public</label></div>'),Sc=m('<div class="space-y-1.5 pt-1"><div class="flex items-center gap-2"><input id="main-create-remote" type="checkbox" class="h-4 w-4 rounded border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue focus:ring-offset-brand-surface"/> <label for="main-create-remote" class="cursor-pointer text-sm text-brand-text select-none"> </label></div> <!></div>'),Tc=m('<div class="flex items-center gap-2 pt-1"><input id="main-git-init" type="checkbox" class="h-4 w-4 rounded border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue focus:ring-offset-brand-surface"/> <label for="main-git-init" class="cursor-pointer text-sm text-brand-text select-none">Initialize Git repository</label></div>'),Ac=m(`<div class="flex flex-1 items-center justify-center p-6"><div class="w-full max-w-md rounded-lg border border-brand-border bg-brand-surface/40 p-6 text-brand-text"><div class="mb-5 text-center"><div class="mb-3 flex justify-center"><img alt="Wherever" class="h-16 w-16"/></div> <h2 class="mb-1 text-2xl font-bold"><span class="gradient-text">Wherever</span></h2> <h3 class="text-sm font-semibold text-brand-text">Create a New Session</h3> <p class="mt-1 text-xs text-brand-text-muted">Start a coding session in any folder on your machine, or use the
69
- sidebar to open an existing session.</p></div> <form class="space-y-4"><div><label class="mb-1 block text-xs font-bold tracking-wider text-brand-text-muted uppercase" for="main-folder-path">Folder Path</label> <div class="relative"><input id="main-folder-path" type="text" autocomplete="off" spellcheck="false" placeholder="e.g. ~/projects/my-new-app"/> <!></div> <!></div> <div><label class="mb-1 block text-xs font-bold tracking-wider text-brand-text-muted uppercase" for="main-model-select">Model</label> <!></div> <!> <!> <button type="submit" class="w-full rounded bg-gradient-to-r from-brand-cyan to-brand-blue py-2.5 text-sm font-semibold text-brand-text transition-all hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50">Create & Start Session</button></form></div></div>`),Ec=m('<div class="flex flex-1 items-center justify-center text-brand-text-muted"><div class="text-center"><div class="mb-4 text-4xl">💬</div> <p class="mb-2 text-lg font-medium text-brand-text">New Session Started</p> <p class="text-sm">Type a message below to start building</p></div></div>'),Cc=m('<div class="flex justify-center pb-2"><button class="rounded border border-brand-border bg-brand-surface-2 px-3 py-1.5 text-xs text-brand-text-muted transition-colors hover:bg-brand-surface-3 hover:text-brand-text disabled:cursor-not-allowed disabled:opacity-50"><!></button></div>'),Rc=m('<div class="flex items-center gap-2 font-sans text-sm text-brand-text-muted italic select-none"><svg class="h-4 w-4 animate-spin text-brand-cyan" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg> <span>Agent is thinking...</span></div>'),Ic=m('<div class="flex items-center gap-2 font-sans text-sm text-brand-text-muted italic select-none"><svg class="h-4 w-4 animate-spin text-brand-cyan" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg> <span>Agent working...</span></div>'),$c=m('<div class="flex items-center gap-2 font-sans text-sm text-brand-text-muted italic select-none"><svg class="h-4 w-4 animate-spin text-brand-cyan" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg> <span>Agent is thinking...</span></div>'),Mc=m('<div class="mb-1 flex items-center gap-1.5 text-[10px] font-bold tracking-wider text-brand-cyan uppercase select-none"><span class="inline-block h-1.5 w-1.5 animate-pulse rounded-full bg-brand-cyan"></span> <span>Thinking</span></div>'),Oc=m('<div class="flex flex-col gap-1"><!> <div class="font-mono text-sm whitespace-pre-wrap"> </div></div>'),Dc=m('<span class="font-mono text-xs text-brand-text-muted tabular-nums"> </span>'),Lc=m('<div class="flex items-center gap-2 font-sans text-sm text-brand-text-muted italic select-none"><svg class="h-4 w-4 animate-spin text-amber-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg> <span>Running tool: <span class="rounded bg-brand-surface-3 px-1 py-0.5 font-mono text-xs font-semibold"> </span>...</span> <!></div>'),Pc=m('<span class="inline-block animate-spin font-bold text-amber-400">⚡</span>'),Nc=m('<span class="font-bold text-rose-400" title="Failed">❌</span>'),Fc=m('<span class="font-bold text-brand-text-muted" title="Interrupted, no result (the running tool was stopped, e.g. by a CLI takeover)">⊘</span>'),Uc=m('<span class="font-bold text-emerald-400" title="Succeeded">✅</span>'),zc=m('<span class="max-w-[180px] truncate font-mono text-xs text-brand-text-muted sm:max-w-[300px] md:max-w-[450px]"> </span>'),Bc=m("<span> </span>"),Hc=m('Collapse <span class="text-[10px]">▲</span>',1),Wc=m('Expand <span class="text-[10px]">▼</span>',1),Gc=m('<a target="_blank" rel="noopener noreferrer" class="block"><img alt="Tool output" class="max-h-96 max-w-full rounded border border-brand-border/40 bg-brand-dark/60 object-contain"/></a>'),jc=m('<div class="mt-2 flex flex-col gap-1"><div class="flex flex-wrap gap-2"></div></div>'),qc=m('<div class="flex flex-col gap-1"><span class="font-sans text-[10px] font-bold tracking-wider text-brand-text-muted uppercase">Arguments</span> <pre class="max-h-40 overflow-x-auto rounded border border-brand-border/30 bg-brand-dark/60 p-1.5 font-mono text-[11px] whitespace-pre-wrap text-amber-400"> </pre></div>'),Vc=m('<pre class="max-h-96 overflow-x-auto rounded border border-brand-border/40 bg-brand-dark/60 p-2 font-mono text-xs whitespace-pre-wrap text-brand-text"> </pre>'),Kc=m('<div class="animate-pulse p-1 text-xs text-brand-text-muted italic">Running and waiting for output...</div>'),Yc=m(`<div class="p-1 text-xs text-brand-text-muted italic">Interrupted before a result was returned (the
70
- running tool was stopped, e.g. by a CLI takeover).
71
- Its outcome is unknown.</div>`),Zc=m('<div class="p-1 text-xs text-brand-text-muted italic">No output returned</div>'),Xc=m('<div class="mt-2 flex flex-col gap-3 overflow-hidden border-t border-brand-border/40 pt-2"><!> <div class="flex flex-col gap-1"><span class="font-sans text-[10px] font-bold tracking-wider text-brand-text-muted uppercase">Output</span> <!></div></div>'),Qc=m('<div class="flex max-w-full min-w-[280px] flex-col sm:min-w-[400px] md:min-w-[550px]"><button class="flex w-full items-center justify-between gap-3 rounded p-1 text-left transition-colors hover:bg-brand-surface-3/30 focus:outline-none"><div class="flex flex-1 items-center gap-2 overflow-hidden"><!> <span class="font-mono text-sm font-bold text-brand-text"> </span> <!> <!></div> <div class="flex shrink-0 items-center gap-1 font-sans text-xs font-medium whitespace-nowrap text-brand-text-muted select-none hover:text-brand-text"><!></div></button> <!> <!></div>'),Jc=m('<pre class="chat-selectable font-sans text-sm leading-relaxed whitespace-pre-wrap"> <span class="ml-0.5 inline-block h-4 w-1.5 animate-pulse bg-brand-cyan align-text-bottom"></span></pre>'),ed=m('<div class="chat-selectable markdown-body text-sm leading-relaxed"></div>'),td=m('<span class="text-brand-text-muted italic"> </span>'),nd=m('<span class="ml-1 inline-block h-4 w-1.5 animate-pulse bg-brand-cyan"></span>'),rd=m('<div class="flex items-center gap-1.5 rounded bg-brand-blue/20 px-2 py-1 font-mono text-xs text-brand-text select-all"><span>📎</span> <span class="truncate"> </span></div>'),sd=m('<div class="mt-2 flex flex-col gap-1 border-t border-brand-blue/20 pt-2"></div>'),od=m('<div class="text-sm leading-relaxed whitespace-pre-wrap"><!> <!></div> <!>',1),ad=m('<span title="Sending, awaiting confirmation">Sending...</span> <span>·</span>',1),id=m('<div class="mt-1.5 flex flex-wrap items-center justify-end gap-2 text-xs"><span class="font-medium text-amber-400">⚠️ Not delivered</span> <button type="button" class="rounded bg-brand-blue/80 px-2 py-0.5 font-medium text-brand-text transition-colors hover:bg-brand-blue">Retry</button> <button type="button" class="rounded bg-brand-surface-3 px-2 py-0.5 font-medium text-brand-text-muted transition-colors hover:text-brand-text">Discard</button></div>'),ld=m("<div><!> </div> <!>",1),cd=m("<div><div><!> <!></div></div>"),dd=m('<div class="flex-1 space-y-4 overflow-y-auto overscroll-y-contain p-4"><!> <!></div>'),ud=m('<button type="button" aria-label="Cycle waiting-for-human beep for this session"><span> </span> <span> </span></button>'),fd=m('<div class="flex items-center gap-1 text-xs text-brand-text-muted"><span class="flex-shrink-0">🧠</span> <span class="whitespace-nowrap tabular-nums"> </span></div>'),pd=m('<span class="ml-1 text-xs text-brand-text-muted">(already a Git repository)</span>'),hd=m('<span class="ml-1 text-xs font-medium text-yellow-500">(folder not empty)</span>'),bd=m('<div class="flex items-center gap-4 pl-6 text-xs text-brand-text-muted"><span>Visibility:</span> <label class="flex cursor-pointer items-center gap-1.5 transition-colors select-none hover:text-brand-text"><input type="radio" name="modal-visibility" class="border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue"/> Private</label> <label class="flex cursor-pointer items-center gap-1.5 transition-colors select-none hover:text-brand-text"><input type="radio" name="modal-visibility" class="border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue"/> Public</label></div>'),vd=m('<div class="space-y-1.5"><div class="flex items-center gap-2"><input id="modal-create-remote" type="checkbox" class="h-4 w-4 rounded border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue"/> <label for="modal-create-remote" class="cursor-pointer text-sm text-brand-text select-none"> </label></div> <!></div>'),gd=m('<div class="fixed inset-0 z-50 flex items-center justify-center bg-brand-dark/65 p-4" role="dialog" aria-modal="true"><div class="w-full max-w-sm rounded-lg border border-brand-border bg-brand-surface-2 p-6 text-brand-text"><h3 class="mb-2 text-base font-bold text-brand-text">Folder Already Exists</h3> <p class="mb-4 text-sm text-brand-text-muted">The folder <span class="font-mono text-xs text-brand-text"> </span> already exists. Do you want to initialize a Git repository in it?</p> <div class="mb-6 flex flex-col gap-3.5"><div class="flex items-center gap-2"><input id="modal-git-init" type="checkbox" class="h-4 w-4 rounded border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue disabled:opacity-50"/> <label for="modal-git-init" class="cursor-pointer text-sm text-brand-text select-none disabled:opacity-50">Initialize Git repository <!></label></div> <!></div> <div class="flex justify-end gap-2.5"><button type="button" class="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> <button type="button" class="rounded bg-gradient-to-r from-brand-cyan to-brand-blue px-3.5 py-1.5 text-xs font-semibold text-brand-text transition-all hover:opacity-90">Confirm & Create</button></div></div></div>'),md=m('<div class="flex flex-1 flex-col overflow-hidden bg-brand-dark"><!> <div class="app-chrome flex flex-wrap items-center justify-between gap-x-4 gap-y-2 border-t border-brand-border p-2"><div class="flex flex-wrap items-center gap-x-4 gap-y-2"><label class="flex cursor-pointer items-center gap-1.5 text-xs text-brand-text-muted select-none hover:text-brand-text"><input type="checkbox" class="h-3.5 w-3.5 rounded border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue"/> Hide Thinking</label> <!> <!></div> <button class="rounded bg-rose-500 px-3 py-1.5 text-xs text-brand-text transition-colors hover:bg-rose-600 disabled:cursor-not-allowed disabled:opacity-50" title="Abort">Abort</button></div> <!></div>');function xd(n,e){Vn(e,!0);const r=()=>Ue(Nt,"$piState",k),s=()=>Ue(fr,"$availableModels",k),o=()=>Ue(Ds,"$gitInitDefaultStore",k),a=()=>Ue(Lr,"$activeSessionInfo",k),i=()=>Ue(Qr,"$isLoadingSession",k),c=()=>Ue(Ns,"$beepSessionOverride",k),_=()=>Ue(Fs,"$beepEnabled",k),b=()=>Ue(ca,"$messages",k),v=()=>Ue(Hs,"$isStreaming",k),A=()=>Ue(ba,"$hasMoreHistory",k),$=()=>Ue(va,"$isLoadingMoreHistory",k),O=()=>Ue(Xr,"$isReadOnly",k),[k,ae]=pr(),se=[],he=new Map;function ie(x,y){const L=`${x}:${y.length}`;let z=he.get(L);return z===void 0&&(z=dc(y),he.set(L,z)),z}function rt(x){if(x>=1e6){const y=x/1e6;return(y>=10?Math.round(y).toString():y.toFixed(1))+"M"}return x>=1e3?Math.round(x/1e3)+"K":String(x)}let Me=Q(()=>{const x=r().contextUsage;if(!x||!x.contextWindow)return null;const y=rt(x.contextWindow);return x.percent==null?`– / ${y}`:`${x.percent.toFixed(1)}% / ${y}`});function Ge(x){if(!x)return{cleanContent:"",attachments:[]};const y=x.split(`
72
- `),L=/^\[Uploaded file: (.+)\]$/,z=[],fe=[];for(const w of y){const ce=w.match(L);ce?fe.push(ce[1]):z.push(w)}let X=z.join(`
73
- `).trim();return X==="I have uploaded the following file(s) for you:"&&(X=""),{cleanContent:X,attachments:fe}}let le=V(""),Pe=V(wn([])),st=V(!1),Ct=V(null),at=V(null),be="",je=V(""),_t=V(!1),ot=V(null),Je=V(!0),et=V("private"),Mt=V(!1),Rt=Q(r),ve=Q(s),pt=Q(o);Lt(()=>{t(ot)===null&&p(_t,t(pt),!0)});let te=V(wn({exists:null,isGit:!1,resolvedPath:"",matchingRule:null})),Ft=Q(()=>t(te).exists!==!0&&t(te).matchingRule&&t(Je)),ye=null;async function ht(x,y=!1){if(ye&&clearTimeout(ye),x===be&&!y)return;if(be=x,!x.trim()){p(te,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0);const z=async()=>{const fe=await Gr("");p(Pe,fe||[],!0)};y?await z():ye=setTimeout(z,300);return}const L=async()=>{const[z,fe]=await Promise.all([jo(x),Gr(x)]);p(Pe,fe||[],!0),z?(p(te,{exists:z.exists,isGit:z.isGit,resolvedPath:z.resolvedPath,matchingRule:z.matchingRule||null},!0),z.exists||(p(_t,t(ot)!==null?t(ot):t(pt),!0),p(Je,!0),z.matchingRule&&p(et,z.matchingRule.visibility,!0))):p(te,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0)};y?await L():ye=setTimeout(L,300)}Lt(()=>{const x=t(le);ht(x,!1)}),Lt(()=>{if(t(ve).models.length>0&&!t(je)){const x=t(ve).models.find(y=>y.isDefault);x?p(je,`${x.provider}:${x.modelId}`):p(je,`${t(ve).models[0].provider}:${t(ve).models[0].modelId}`)}});function hn(){t(le).trim()&&(t(te).exists===!0?(p(_t,!1),p(Je,!1),t(te).matchingRule&&p(et,t(te).matchingRule.visibility,!0),p(Mt,!0)):Mn(t(le).trim(),t(je)||void 0,t(_t),t(te).matchingRule?t(Je):void 0,t(te).matchingRule?t(et):void 0))}let Ee=V(void 0),lt=Q(a),Vt=Q(i),j=Q(c),ge=Q(_);function S(){t(j)===void 0?Br(!0):t(j)===!0?Br(!1):Br(void 0)}let J=Q(()=>!!t(lt).sessionFile),T=V(!0),ee=V(!1),U=wn({});function we(x,y){U[x]=!y}function me(x){if(!x)return null;const y=x.trim();if(!y)return null;if(y.startsWith("{"))try{return JSON.parse(y)}catch{}const L={},z=/([a-zA-Z0-9_-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|(\S+))/g;let fe;for(;(fe=z.exec(y))!==null;){const X=fe[1],w=fe[2]!==void 0?fe[2]:fe[3]!==void 0?fe[3]:fe[4];L[X]=w}return Object.keys(L).length>0?L:null}function Ze(x,y,L){if(!y)return L?L.trim():"";const z=x.toLowerCase();if(["read","write","edit","ls"].includes(z)){const X=y.path||y.filepath||y.file;if(X)return String(X)}if(z==="bash"){const X=y.command||y.cmd;if(X){const w=String(X).replace(/\s+/g," ").trim();return w.length>50?w.slice(0,47)+"...":w}}if(z==="grep"){const X=y.pattern,w=y.path;if(X)return w?`"${X}" in ${w}`:`"${X}"`}if(z==="find"){const X=y.pattern||y.path;if(X)return String(X)}const fe=y.path||y.filepath||y.file||y.name||y.query;return fe?String(fe):Object.entries(y).filter(([X,w])=>w!==void 0&&w!=="").map(([X,w])=>`${X}=${typeof w=="object"?JSON.stringify(w):w}`).join(" ")}function Ve(x,y){return x?JSON.stringify(x,null,2):y?y.trim():""}function yt(x){let y=x.toolName||"tool",L=x.toolArgs!==void 0?x.toolArgs:"",z=x.toolOutput!==void 0?x.toolOutput:"",fe=!!x.isError;if(!L&&!z&&x.content){let P=x.content||"";P.startsWith("Error: ")?(fe=!0,P=P.slice(7)):P.startsWith("Tool error: ")&&(fe=!0,P=P.slice(12));const F=P.indexOf(`
74
- `),Te=F!==-1?P.slice(0,F):P;z=F!==-1?P.slice(F+1):"";let ne=Te.trim();ne.startsWith("$ ")&&(ne=ne.slice(2));const Se=ne.indexOf(" ");y=x.toolName||(Se!==-1?ne.slice(0,Se):ne)||"tool",L=Se!==-1?ne.slice(Se+1):""}const X=me(L),w=Ze(y,X,L),ce=Ve(X,L);return{toolName:y,smartTitleArgs:w,fullArgs:ce,toolOutput:z,isError:fe,interrupted:!!x.interrupted}}function Tt(x){return x.scrollHeight-x.scrollTop-x.clientHeight<=20}function Ye(){t(Ee)&&p(T,Tt(t(Ee)),!0)}function Ce(){t(Ee)&&(t(Ee).scrollTop=t(Ee).scrollHeight)}function Ut(){(t(T)||t(ee))&&(Ce(),p(ee,!1))}Mr(Ce),Lt(()=>{if(t(Ee))return t(Ee).addEventListener("scroll",Ye),()=>{t(Ee)&&t(Ee).removeEventListener("scroll",Ye)}});let zt=V(null),an=V(!1);function cn(){p(ee,!0),Ce(),requestAnimationFrame(()=>{Ce(),requestAnimationFrame(Ce)}),setTimeout(Ce,60),setTimeout(Ce,150)}Lt(()=>{const x=t(lt).sessionFile;x!==t(zt)&&(p(zt,x,!0),p(ee,!0));const y=t(Vt);t(an)&&!y&&cn(),p(an,y,!0)});let tt=Q(()=>{const x=b().filter(L=>L.role==="thinking"&&r().hideThinking?!1:L.role==="tool"&&r().hideTools?dn(L)||!!L.isStreaming:L.role!=="assistant"&&L.role!=="thinking"||L.isStreaming||L.content.trim()!==""),y=x.some(L=>L.isStreaming);if(t(wt)&&!y){const L=b().some(z=>z.role==="thinking"&&z.isStreaming);x.push({id:"fallback-loader-message-id",role:"thinking",content:L?"FALLBACK_THINKING_LOADER":"FALLBACK_LOADER",timestamp:Date.now(),isStreaming:!0})}return x}),wt=Q(v),kt=V(wn(Date.now())),Xt=Q(()=>t(tt).some(x=>x.role==="tool"&&x.isStreaming));Lt(()=>{if(!t(Xt))return;p(kt,Date.now(),!0);const x=setInterval(()=>p(kt,Date.now(),!0),100);return()=>clearInterval(x)});function Bt(x){if(x.startedAt===void 0)return null;const y=x.endedAt??(x.isStreaming?t(kt):void 0);return y===void 0?null:`${(Math.max(0,y-x.startedAt)/1e3).toFixed(1)}s`}ni(()=>{const x=t(tt)[t(tt).length-1];x&&`${t(tt).length}${x.content.length}`,t(Ee)&&p(T,Tt(t(Ee)),!0)}),Lt(()=>{const x=t(tt)[t(tt).length-1];x&&`${t(tt).length}${x.content.length}`,Ut()});function Qt(x){return new Date(x).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function dn(x){const y=b(),L=y.findIndex(z=>z.id===x.id);if(L===-1)return!1;for(let z=L-1;z>=0;z--)if(y[z].role==="user"){const fe=y[z].content?y[z].content.trim():"";return fe.startsWith("!")||fe.startsWith("!!")}return!1}function Re(x,y){return dn(x)}function bt(){p(ee,!0),setTimeout(Ce,0)}let Ht=Q(A),St=Q($),vt=V(null);function Kt(){!t(Ee)||t(St)||!t(Ht)||(p(vt,t(Ee).scrollHeight-t(Ee).scrollTop),sa())}Lt(()=>{if(b().length,t(vt)!==null&&t(Ee)){const x=t(vt);p(vt,null),requestAnimationFrame(()=>{t(Ee)&&(t(Ee).scrollTop=t(Ee).scrollHeight-x)})}});var tn={forceScrollToBottom:bt},un=md(),bn=u(un);{var En=x=>{var y=uc();h(x,y)},I=x=>{var y=pc(),L=u(y),z=f(u(L),6);{var fe=w=>{var ce=fc(),P=u(ce,!0);d(ce),H(()=>re(P,t(Rt).error)),h(w,ce)};E(z,w=>{t(Rt).error&&w(fe)})}var X=f(z,2);d(L),d(y),B("click",X,()=>{ai(()=>Promise.resolve().then(()=>Wi),void 0,import.meta.url).then(w=>w.connect())}),h(x,y)},W=x=>{var y=hc();h(x,y)},K=x=>{var y=Ac(),L=u(y),z=u(L),fe=u(z),X=u(fe);d(fe),dt(6),d(z);var w=f(z,2),ce=u(w),P=f(u(ce),2),F=u(P);it(F),Nn(F,N=>p(Ct,N),()=>t(Ct));var Te=f(F,2);{var ne=N=>{var pe=vc();gn(pe,21,()=>t(Pe),Sn,(We,Ae)=>{var ue=bc(),Le=u(ue,!0);d(ue),H(()=>re(Le,t(Ae))),B("click",ue,()=>{p(le,t(Ae),!0),ht(t(Ae),!0),t(Ct)?.focus()}),h(We,ue)}),d(pe),h(N,pe)};E(Te,N=>{t(st)&&t(Pe).length>0&&N(ne)})}d(P),Nn(P,N=>p(at,N),()=>t(at));var Se=f(P,2);{var _e=N=>{var pe=mc(),We=f(u(pe));{var Ae=ue=>{var Le=gc();h(ue,Le)};E(We,ue=>{t(te).isGit&&ue(Ae)})}d(pe),h(N,pe)},De=N=>{var pe=xc();h(N,pe)};E(Se,N=>{t(te).exists===!0?N(_e):N(De,-1)})}d(ce);var gt=f(ce,2),Be=f(u(gt),2);{var Ke=N=>{var pe=yc();gn(pe,21,()=>t(ve).models,Sn,(We,Ae)=>{var ue=_c(),Le=u(ue);d(ue);var It={};H(()=>{re(Le,`${t(Ae).label??""}${t(Ae).isDefault?" (default)":""}`),It!==(It=`${t(Ae).provider}:${t(Ae).modelId}`)&&(ue.value=ue.__value=`${t(Ae).provider}:${t(Ae).modelId}`)}),h(We,ue)}),d(pe),Ir(pe,()=>t(je),We=>p(je,We)),h(N,pe)},He=N=>{var pe=wc();it(pe),On(pe,()=>t(je),We=>p(je,We)),h(N,pe)};E(Be,N=>{t(ve).models.length>0?N(Ke):N(He,-1)})}d(gt);var qe=f(gt,2);{var mt=N=>{var pe=Sc(),We=u(pe),Ae=u(We);it(Ae);var ue=f(Ae,2),Le=u(ue);d(ue),d(We);var It=f(We,2);{var $t=Wt=>{var R=kc(),l=f(u(R),2),g=u(l);it(g),g.value=g.__value="private",dt(),d(l);var M=f(l,2),q=u(M);it(q),q.value=q.__value="public",dt(),d(M),d(R),jn(se,[],g,()=>t(et),$e=>p(et,$e)),jn(se,[],q,()=>t(et),$e=>p(et,$e)),h(Wt,R)};E(It,Wt=>{t(Je)&&Wt($t)})}d(pe),H(()=>re(Le,`Create remote ${t(te).matchingRule.provider??""} repository`)),Tn(Ae,()=>t(Je),Wt=>p(Je,Wt)),h(N,pe)};E(qe,N=>{t(te).exists!==!0&&t(te).matchingRule&&N(mt)})}var Ie=f(qe,2);{var Z=N=>{var pe=Tc(),We=u(pe);it(We),dt(2),d(pe),B("change",We,Ae=>{p(ot,Ae.currentTarget.checked,!0)}),Tn(We,()=>t(_t),Ae=>p(_t,Ae)),h(N,pe)};E(Ie,N=>{t(te).exists!==!0&&(!t(te).matchingRule||!t(Je))&&N(Z)})}var oe=f(Ie,2);d(w),d(L),d(y),H((N,pe)=>{Fe(X,"src",N),Yt(F,1,`w-full rounded border px-3 py-2 text-sm text-brand-text placeholder-brand-text-muted transition-all duration-200 focus:outline-none ${t(Ft)?"border-emerald-500/80 bg-emerald-500/10 focus:border-emerald-400 focus:ring-1 focus:ring-emerald-400/30":"border-brand-border bg-brand-surface-3 focus:border-brand-blue"}`),oe.disabled=pe},[()=>cr("/logo.svg"),()=>!t(le).trim()]),qn("submit",w,N=>{N.preventDefault(),hn()}),qn("focus",F,()=>{p(st,!0),ht(t(le),!0)}),qn("blur",F,N=>{t(at)&&t(at).contains(N.relatedTarget)||p(st,!1)}),B("keydown",F,N=>{N.key==="Escape"&&p(st,!1)}),On(F,()=>t(le),N=>p(le,N)),h(x,y)},Y=x=>{var y=Ec();h(x,y)},ke=x=>{var y=dd(),L=u(y);{var z=X=>{var w=Cc(),ce=u(w),P=u(ce);{var F=ne=>{var Se=_n("Loading older messages...");h(ne,Se)},Te=ne=>{var Se=_n("Load older messages");h(ne,Se)};E(P,ne=>{t(St)?ne(F):ne(Te,-1)})}d(ce),d(w),H(()=>ce.disabled=t(St)),B("click",ce,Kt),h(X,w)};E(L,X=>{t(Ht)&&X(z)})}var fe=f(L,2);gn(fe,17,()=>t(tt),X=>X.id,(X,w)=>{var ce=cd(),P=u(ce),F=u(P);{var Te=Be=>{var Ke=dr(),He=Zt(Ke);{var qe=oe=>{var N=Rc();h(oe,N)},mt=oe=>{var N=Ic();h(oe,N)},Ie=oe=>{var N=$c();h(oe,N)},Z=oe=>{var N=Oc(),pe=u(N);{var We=Le=>{var It=Mc();h(Le,It)};E(pe,Le=>{t(w).isStreaming&&Le(We)})}var Ae=f(pe,2),ue=u(Ae,!0);d(Ae),d(N),H(()=>re(ue,t(w).content)),h(oe,N)};E(He,oe=>{t(w).content==="FALLBACK_THINKING_LOADER"?oe(qe):t(w).content==="FALLBACK_LOADER"?oe(mt,1):r().hideThinking?oe(Ie,2):oe(Z,-1)})}h(Be,Ke)},ne=Be=>{var Ke=dr(),He=Zt(Ke);{var qe=Z=>{var oe=Lc(),N=f(u(oe),2),pe=f(u(N)),We=u(pe,!0);d(pe),dt(),d(N);var Ae=f(N,2);{var ue=It=>{var $t=Dc(),Wt=u($t,!0);d($t),H(R=>re(Wt,R),[()=>Bt(t(w))]),h(It,$t)},Le=Q(()=>Bt(t(w)));E(Ae,It=>{t(Le)&&It(ue)})}d(oe),H(()=>re(We,t(w).toolName||"agent")),h(Z,oe)},mt=Q(()=>r().hideTools&&!dn(t(w))),Ie=Z=>{const oe=Q(()=>yt(t(w))),N=Q(()=>U[t(w).id]!==void 0?U[t(w).id]:Re(t(w),t(tt)));var pe=Qc(),We=u(pe),Ae=u(We),ue=u(Ae);{var Le=Qe=>{var ct=Pc();h(Qe,ct)},It=Qe=>{var ct=Nc();h(Qe,ct)},$t=Qe=>{var ct=Fc();h(Qe,ct)},Wt=Qe=>{var ct=Uc();h(Qe,ct)};E(ue,Qe=>{t(w).isStreaming?Qe(Le):t(oe).isError?Qe(It,1):t(oe).interrupted?Qe($t,2):Qe(Wt,-1)})}var R=f(ue,2),l=u(R,!0);d(R);var g=f(R,2);{var M=Qe=>{var ct=zc(),Dn=u(ct,!0);d(ct),H(()=>{Fe(ct,"title",t(oe).smartTitleArgs),re(Dn,t(oe).smartTitleArgs)}),h(Qe,ct)};E(g,Qe=>{t(oe).smartTitleArgs&&Qe(M)})}var q=f(g,2);{var $e=Qe=>{var ct=Bc(),Dn=u(ct);d(ct),H(hr=>{Yt(ct,1,`shrink-0 font-mono text-xs tabular-nums ${t(w).isStreaming?"text-amber-400":"text-brand-text-muted"}`),Fe(ct,"title",t(w).isStreaming?"Elapsed time":"Time taken"),re(Dn,`${t(w).isStreaming?"Elapsed":"Took"}
75
- ${hr??""}`)},[()=>Bt(t(w))]),h(Qe,ct)},Xe=Q(()=>Bt(t(w)));E(q,Qe=>{t(Xe)&&Qe($e)})}d(Ae);var Gt=f(Ae,2),Pt=u(Gt);{var vn=Qe=>{var ct=Hc();dt(),h(Qe,ct)},mn=Qe=>{var ct=Wc();dt(),h(Qe,ct)};E(Pt,Qe=>{t(N)?Qe(vn):Qe(mn,-1)})}d(Gt),d(We);var rr=f(We,2);{var nn=Qe=>{var ct=jc(),Dn=u(ct);gn(Dn,21,()=>t(w).images,Sn,(hr,Yn)=>{var sr=Gc(),ts=u(sr);d(sr),H(()=>{Fe(sr,"href",`data:${t(Yn).mimeType};base64,${t(Yn).data}`),Fe(ts,"src",`data:${t(Yn).mimeType};base64,${t(Yn).data}`)}),h(hr,sr)}),d(Dn),d(ct),h(Qe,ct)};E(rr,Qe=>{t(w).images&&t(w).images.length>0&&Qe(nn)})}var Oa=f(rr,2);{var Da=Qe=>{var ct=Xc(),Dn=u(ct);{var hr=ln=>{var xn=qc(),Nr=f(u(xn),2),Fa=u(Nr,!0);d(Nr),d(xn),H(()=>re(Fa,t(oe).fullArgs)),h(ln,xn)};E(Dn,ln=>{t(oe).fullArgs&&t(oe).fullArgs!=="{}"&&ln(hr)})}var Yn=f(Dn,2),sr=f(u(Yn),2);{var ts=ln=>{var xn=Vc(),Nr=u(xn,!0);d(xn),H(()=>re(Nr,t(oe).toolOutput)),h(ln,xn)},La=ln=>{var xn=Kc();h(ln,xn)},Pa=ln=>{var xn=Yc();h(ln,xn)},Na=ln=>{var xn=Zc();h(ln,xn)};E(sr,ln=>{t(oe).toolOutput?ln(ts):t(w).isStreaming?ln(La,1):t(oe).interrupted?ln(Pa,2):ln(Na,-1)})}d(Yn),d(ct),h(Qe,ct)};E(Oa,Qe=>{t(N)&&Qe(Da)})}d(pe),H(()=>re(l,t(oe).toolName)),B("click",We,()=>we(t(w).id,t(N))),h(Z,pe)};E(He,Z=>{t(mt)?Z(qe):Z(Ie,-1)})}h(Be,Ke)},Se=Be=>{var Ke=dr(),He=Zt(Ke);{var qe=Ie=>{var Z=Jc(),oe=u(Z,!0);dt(),d(Z),H(()=>re(oe,t(w).content)),h(Ie,Z)},mt=Ie=>{var Z=ed();li(Z,()=>ie(t(w).id,t(w).content),!0),d(Z),h(Ie,Z)};E(He,Ie=>{t(w).isStreaming?Ie(qe):Ie(mt,-1)})}h(Be,Ke)},_e=Be=>{const Ke=Q(()=>Ge(t(w).content));var He=od(),qe=Zt(He),mt=u(qe);{var Ie=ue=>{var Le=_n();H(()=>re(Le,t(Ke).cleanContent)),h(ue,Le)},Z=ue=>{var Le=td(),It=u(Le);d(Le),H(()=>re(It,`Shared file${t(Ke).attachments.length>1?"s":""} with agent:`)),h(ue,Le)},oe=ue=>{var Le=_n();H(()=>re(Le,t(w).content||(t(w).isStreaming?"Thinking...":""))),h(ue,Le)};E(mt,ue=>{t(Ke).cleanContent?ue(Ie):t(Ke).attachments.length>0?ue(Z,1):ue(oe,-1)})}var N=f(mt,2);{var pe=ue=>{var Le=nd();h(ue,Le)};E(N,ue=>{t(w).isStreaming&&t(wt)&&ue(pe)})}d(qe);var We=f(qe,2);{var Ae=ue=>{var Le=sd();gn(Le,21,()=>t(Ke).attachments,Sn,(It,$t)=>{var Wt=rd(),R=f(u(Wt),2),l=u(R,!0);d(R),d(Wt),H(()=>{Fe(R,"title",t($t)),re(l,t($t))}),h(It,Wt)}),d(Le),h(ue,Le)};E(We,ue=>{t(Ke).attachments.length>0&&ue(Ae)})}h(Be,He)};E(F,Be=>{t(w).role==="thinking"?Be(Te):t(w).role==="tool"?Be(ne,1):t(w).role==="assistant"&&t(w).content!==""?Be(Se,2):Be(_e,-1)})}var De=f(F,2);{var gt=Be=>{var Ke=ld(),He=Zt(Ke),qe=u(He);{var mt=N=>{var pe=ad();dt(2),h(N,pe)};E(qe,N=>{t(w).role==="user"&&t(w).delivery==="sending"&&N(mt)})}var Ie=f(qe);d(He);var Z=f(He,2);{var oe=N=>{var pe=id(),We=f(u(pe),2),Ae=f(We,2);d(pe),B("click",We,()=>Jo(t(w).id)),B("click",Ae,()=>ea(t(w).id)),h(N,pe)};E(Z,N=>{t(w).role==="user"&&t(w).delivery==="failed"&&N(oe)})}H(N=>{Yt(He,1,`mt-1 flex items-center gap-1.5 text-xs opacity-50 ${t(w).role==="user"?"justify-end text-brand-text-muted":t(w).role==="assistant"?"text-brand-purple":"text-brand-text-muted"}`),re(Ie,` ${N??""}`)},[()=>Qt(t(w).timestamp)]),h(Be,Ke)};E(De,Be=>{t(w).role!=="thinking"&&t(w).role!=="tool"&&Be(gt)})}d(P),d(ce),H(Be=>{Yt(ce,1,`flex ${t(w).role==="user"?"justify-end":"justify-start"}`),Yt(P,1,`max-w-[85%] rounded-lg px-4 py-3 ${Be??""}`)},[()=>t(w).role==="user"?"bg-brand-blue/80 text-brand-text":t(w).role==="thinking"?"border-l-2 border-brand-border bg-brand-surface/30 text-sm text-brand-text-muted":t(w).role==="tool"?r().hideTools&&!dn(t(w))?"border-l-2 border-brand-border bg-brand-surface/30 text-sm text-brand-text-muted":`border-l-2 bg-brand-surface-2 font-mono text-sm text-brand-text ${t(w).isStreaming?"border-amber-400":t(w).isError?"border-rose-400":t(w).interrupted?"border-brand-border":"border-emerald-400"}`:t(w).role==="assistant"?"border-l-2 border-brand-purple bg-brand-purple/10 text-brand-text":t(w).content===""&&t(w).isStreaming?"bg-brand-surface-3 text-brand-text-muted italic":"bg-brand-surface-2 text-brand-text"]),h(X,ce)}),d(y),Nn(y,X=>p(Ee,X),()=>t(Ee)),h(x,y)};E(bn,x=>{t(Rt).connecting&&!t(J)?x(En):!t(Rt).connected&&!t(J)?x(I,1):!t(J)&&(t(Vt)||typeof window<"u"&&window.location.hash)?x(W,2):t(lt).sessionFile?t(tt).length===0?x(Y,4):x(ke,-1):x(K,3)})}var Ot=f(bn,2),Et=u(Ot),Dt=u(Et),At=u(Dt);it(At),dt(),d(Dt);var C=f(Dt,2);{var D=x=>{var y=ud(),L=u(y),z=u(L,!0);d(L);var fe=f(L,2),X=u(fe,!0);d(fe),d(y),H(()=>{Yt(y,1,`flex items-center gap-1.5 rounded px-1.5 py-0.5 text-xs select-none hover:text-brand-text ${t(j)===void 0?"text-brand-text-muted":"text-brand-blue"}`),Fe(y,"title",t(j)===void 0?`Beep when the agent is waiting: following the default (${t(ge)?"on":"off"}). Click to set On for this session.`:t(j)===!0?"Beep when the agent is waiting: ON for this session. Click to set Off.":"Beep when the agent is waiting: OFF for this session. Click to follow the default."),re(z,t(ge)?"🔔":"🔕"),re(X,t(j)===void 0?`Beep: Default (${t(ge)?"on":"off"})`:t(j)?"Beep: On":"Beep: Off")}),B("click",y,S),h(x,y)};E(C,x=>{t(lt).sessionFile&&!O()&&x(D)})}var de=f(C,2);{var Oe=x=>{var y=fd(),L=f(u(y),2),z=u(L,!0);d(L),d(y),H(fe=>{Fe(y,"title",fe),re(z,t(Me))},[()=>r().contextUsage?.tokens!=null?`${r().contextUsage.tokens.toLocaleString()} context tokens of ${r().contextUsage.contextWindow.toLocaleString()}`:"Context window size"]),h(x,y)};E(de,x=>{t(Me)&&x(Oe)})}d(Et);var Ne=f(Et,2);d(Ot);var ze=f(Ot,2);{var G=x=>{var y=gd(),L=u(y),z=f(u(L),2),fe=f(u(z)),X=u(fe,!0);d(fe),dt(),d(z);var w=f(z,2),ce=u(w),P=u(ce);it(P);var F=f(P,2),Te=f(u(F));{var ne=He=>{var qe=pd();h(He,qe)},Se=He=>{var qe=hd();h(He,qe)};E(Te,He=>{t(te).isGit?He(ne):He(Se,-1)})}d(F),d(ce);var _e=f(ce,2);{var De=He=>{var qe=vd(),mt=u(qe),Ie=u(mt);it(Ie);var Z=f(Ie,2),oe=u(Z);d(Z),d(mt);var N=f(mt,2);{var pe=We=>{var Ae=bd(),ue=f(u(Ae),2),Le=u(ue);it(Le),Le.value=Le.__value="private",dt(),d(ue);var It=f(ue,2),$t=u(It);it($t),$t.value=$t.__value="public",dt(),d(It),d(Ae),jn(se,[],Le,()=>t(et),Wt=>p(et,Wt)),jn(se,[],$t,()=>t(et),Wt=>p(et,Wt)),h(We,Ae)};E(N,We=>{t(Je)&&We(pe)})}d(qe),H(()=>re(oe,`Create remote ${t(te).matchingRule.provider??""} repository`)),Tn(Ie,()=>t(Je),We=>p(Je,We)),h(He,qe)};E(_e,He=>{t(te).matchingRule&&He(De)})}d(w);var gt=f(w,2),Be=u(gt),Ke=f(Be,2);d(gt),d(L),d(y),H(()=>{re(X,t(le)),P.disabled=t(te).isGit}),Tn(P,()=>t(_t),He=>p(_t,He)),B("click",Be,()=>p(Mt,!1)),B("click",Ke,()=>{p(Mt,!1),Mn(t(le).trim(),t(je)||void 0,t(_t),t(te).matchingRule?t(Je):void 0,t(te).matchingRule?t(et):void 0)}),h(x,y)};E(ze,x=>{t(Mt)&&x(G)})}d(un),H(()=>{Po(At,r().hideThinking),Ne.disabled=!t(wt)}),B("change",At,x=>aa({hideThinking:x.currentTarget.checked})),B("click",Ne,function(...x){ta?.apply(this,x)}),h(n,un);var xe=Kn(tn);return ae(),xe}tr(["click","keydown","change"]);function _d(n,e){return n.hasSession?n.readOnly?{action:"blocked",reason:"read-only"}:n.connected?n.agentPending?{action:"blocked",reason:"agent-pending"}:{action:"send",deliverAs:"steer"}:{action:"blocked",reason:"disconnected"}:{action:"blocked",reason:"no-session"}}var yd=m("<option> </option>"),wd=m('<div class="mb-3.5"><label for="speech-locale" class="mb-1 block font-medium text-gray-400">Accent / Locale</label> <select id="speech-locale" class="w-full rounded border border-gray-600 bg-gray-950 px-2 py-1.5 text-white focus:border-blue-500 focus:outline-none"></select></div>'),kd=m('<div class="mt-2 rounded border border-red-900/40 bg-red-950/40 p-2 leading-normal text-red-400"> </div>'),Sd=m(`<div class="fixed inset-0 z-40"></div> <div class="absolute right-0 bottom-14 z-50 w-64 rounded-lg border border-gray-600 bg-gray-800 p-4 text-xs text-white shadow-xl"><h4 class="mb-3 border-b border-gray-700 pb-1.5 font-semibold text-gray-300">Speech Settings</h4> <div class="mb-3.5"><span class="mb-1 block font-medium text-gray-400">Speech-to-Text Engine</span> <div class="flex gap-2"><button type="button">On-Device</button> <button type="button">Cloud AI</button></div> <p class="mt-1 text-[10px] leading-relaxed text-gray-400"> </p></div> <!> <div class="mb-2"><label class="flex cursor-pointer items-center gap-2 py-1"><input type="checkbox" class="rounded border-gray-600 bg-gray-950 text-blue-600 focus:ring-0 focus:ring-offset-0"/> <span class="font-medium text-gray-300">Direct Send (Auto-dispatch)</span></label> <p class="pl-6 text-[10px] leading-relaxed text-gray-400">When enabled, releasing or stopping the microphone immediately sends
76
- the message.</p></div> <!></div>`,1),Td=m('<div class="relative flex shrink-0 items-center gap-1 select-none"><button type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-5 w-5"><path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" x2="12" y1="19" y2="22"></line></svg></button> <button type="button" class="flex h-[48px] w-[28px] items-center justify-center rounded-lg border border-gray-600 bg-gray-800 text-gray-400 hover:bg-gray-700 hover:text-white disabled:cursor-not-allowed disabled:opacity-40" title="Speech Settings"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg></button> <!></div>');function Ad(n,e){Vn(e,!0);let r=Xn(e,"text",15);const s=typeof window<"u"?window.SpeechRecognition||window.webkitSpeechRecognition:null,o=!!s;let a=V(!1),i=V(!1),c=V(!1),_=V(!1),b=V(!1),v=V("en-US"),A=V("browser"),$=V(null),O=V(null),k=null,ae=null,se=null,he=null,ie=null,rt=[],Me="",Ge=!1;const le=[{code:"en-US",label:"English (US)"},{code:"en-GB",label:"English (UK)"},{code:"en-IN",label:"English (India)"},{code:"en-AU",label:"English (Australia)"},{code:"en-CA",label:"English (Canada)"},{code:"en-ZA",label:"English (South Africa)"}];Mr(()=>{const S=localStorage.getItem("wherever-speech-direct-send");S!==null&&p(b,S==="true");const J=localStorage.getItem("wherever-speech-locale");J!==null&&p(v,J,!0);const T=localStorage.getItem("wherever-speech-engine");return T!==null?p(A,T,!0):o||p(A,"cloud"),()=>{if(k)try{k.abort()}catch{}if(he)try{he.disconnect()}catch{}if(se)try{se.disconnect()}catch{}if(ie)try{ie.getTracks().forEach(ee=>ee.stop())}catch{}if(ae)try{ae.close()}catch{}t(O)&&clearTimeout(t(O))}});function Pe(){localStorage.setItem("wherever-speech-direct-send",String(t(b))),localStorage.setItem("wherever-speech-locale",t(v)),localStorage.setItem("wherever-speech-engine",t(A))}function st(){const S=localStorage.getItem("wherever-config");if(S){const J=JSON.parse(S),T=window.location.protocol==="https:"?"https:":"http:",ee=J.host.startsWith("http")?J.host.replace(/^wss?:\/\//,""):J.host;return`${T}//${ee}:${J.port}`}return`${window.location.protocol}//${window.location.host}`}function Ct(){try{const S=localStorage.getItem("wherever-config");if(S)return JSON.parse(S).token||""}catch{}return""}function at(){try{const S=window.AudioContext||window.webkitAudioContext;if(!S)return;const J=new S,T=J.createOscillator(),ee=J.createGain();T.type="sine",T.frequency.setValueAtTime(400,J.currentTime),ee.gain.setValueAtTime(.08,J.currentTime),ee.gain.exponentialRampToValueAtTime(.001,J.currentTime+.12),T.connect(ee),ee.connect(J.destination),T.start(),T.stop(J.currentTime+.12)}catch(S){console.warn("Could not play audio beep feedback:",S)}}function be(S,J,T){if(J===T)return S;const ee=J/T,U=Math.round(S.length/ee),we=new Float32Array(U);let me=0,Ze=0;for(;me<we.length;){const Ve=Math.round((me+1)*ee);let yt=0,Tt=0;for(let Ye=Ze;Ye<Ve&&Ye<S.length;Ye++)yt+=S[Ye],Tt++;we[me]=Tt>0?yt/Tt:0,me++,Ze=Ve}return we}function je(){if(o)try{k=new s,k.continuous=!0,k.interimResults=!0,k.lang=t(v),k.onstart=()=>{p(a,!0),p(i,!1),at()},k.onresult=S=>{let J="",T="";for(let U=S.resultIndex;U<S.results.length;++U){const we=S.results[U];we.isFinal?J+=we[0].transcript:T+=we[0].transcript}const ee=(J+T).trim();ee&&(Ge=!0,r(Me+(Me?" ":"")+ee))},k.onerror=S=>{console.error("Browser speech recognition error:",S.error),S.error!=="no-speech"&&p($,`Error: ${S.error}`),_t()},k.onend=()=>{p(a,!1),t(b)&&Ge&&e.onSend&&setTimeout(()=>{r().trim()&&e.onSend()},50)},k.start(),navigator.vibrate&&navigator.vibrate(40)}catch(S){console.error("Failed to start browser speech recognition:",S),p($,"Failed to start browser recording"),p(a,!1)}}function _t(){if(k)try{k.stop()}catch{}p(a,!1)}async function ot(){try{const S=await navigator.mediaDevices.getUserMedia({audio:!0});ie=S,rt=[];const J=window.AudioContext||window.webkitAudioContext;ae=new J,se=ae.createMediaStreamSource(S),he=ae.createScriptProcessor(4096,1,1),he.onaudioprocess=T=>{const ee=T.inputBuffer.getChannelData(0);rt.push(new Float32Array(ee))},se.connect(he),he.connect(ae.destination),p(a,!0),p(i,!1),at(),navigator.vibrate&&navigator.vibrate(40)}catch(S){console.error("Failed to start cloud audio recording:",S),p($,S.message||"Microphone access denied",!0),p(a,!1),p(i,!1)}}function Je(){if(t(a)){if(p(a,!1),p(i,!0),he){try{he.disconnect()}catch{}he.onaudioprocess=null}if(se)try{se.disconnect()}catch{}if(ie)try{ie.getTracks().forEach(S=>S.stop())}catch{}et()}}async function et(){try{if(rt.length===0){p(i,!1);return}p($,null);let S=0;for(const Ut of rt)S+=Ut.length;const J=new Float32Array(S);let T=0;for(const Ut of rt)J.set(Ut,T),T+=Ut.length;const ee=ae?ae.sampleRate:48e3,U=16e3,we=be(J,ee,U),me=Ft(we,1,U,1,16),Ze=new Blob([me],{type:"audio/wav"}),Ve=st(),yt=Ct(),Tt=`${Ve}/session/transcribe${yt?`?token=${encodeURIComponent(yt)}`:""}`,Ye=await fetch(Tt,{method:"POST",body:Ze,headers:{"Content-Type":"application/octet-stream"}}),Ce=await Ye.json();if(!Ye.ok)throw new Error(Ce.error||`HTTP ${Ye.status}`);Ce.text&&Ce.text.trim()&&(Ge=!0,r(Me+(Me?" ":"")+Ce.text.trim()),t(b)&&e.onSend&&setTimeout(()=>{r().trim()&&e.onSend()},50))}catch(S){console.error("Cloud transcription request failed:",S),p($,S.message||"Cloud API failed",!0)}finally{if(p(i,!1),ae){try{ae.close()}catch{}ae=null}}}function Mt(){e.disabled||t(a)||t(i)||(p($,null),Ge=!1,Me=r(),t(A)==="cloud"?ot():je())}function Rt(){t(A)==="cloud"?Je():_t()}function ve(S){if(S.button===0&&!e.disabled){if(S.preventDefault(),t(a)){Rt();return}p(c,!1),p(O,setTimeout(()=>{p(c,!0),Mt()},350),!0)}}function pt(S){t(O)&&(clearTimeout(t(O)),p(O,null)),t(c)?(p(c,!1),Rt()):t(a)||Mt()}function te(){t(O)&&(clearTimeout(t(O)),p(O,null)),t(c)&&(p(c,!1),Rt())}function Ft(S,J,T,ee,U){const we=new ArrayBuffer(44+S.length*2),me=new DataView(we);return ht(me,0,"RIFF"),me.setUint32(4,36+S.length*2,!0),ht(me,8,"WAVE"),ht(me,12,"fmt "),me.setUint32(16,16,!0),me.setUint16(20,ee,!0),me.setUint16(22,J,!0),me.setUint32(24,T,!0),me.setUint32(28,T*J*(U/8),!0),me.setUint16(32,J*(U/8),!0),me.setUint16(34,U,!0),ht(me,36,"data"),me.setUint32(40,S.length*2,!0),ye(me,44,S),we}function ye(S,J,T){for(let ee=0;ee<T.length;ee++,J+=2){let U=Math.max(-1,Math.min(1,T[ee]));S.setInt16(J,U<0?U*32768:U*32767,!0)}}function ht(S,J,T){for(let ee=0;ee<T.length;ee++)S.setUint8(J+ee,T.charCodeAt(ee))}var hn=Td(),Ee=u(hn),lt=f(Ee,2),Vt=u(lt);d(lt);var j=f(lt,2);{var ge=S=>{var J=Sd(),T=Zt(J),ee=f(T,2),U=f(u(ee),2),we=f(u(U),2),me=u(we),Ze=f(me,2);d(we);var Ve=f(we,2),yt=u(Ve,!0);d(Ve),d(U);var Tt=f(U,2);{var Ye=tt=>{var wt=wd(),kt=f(u(wt),2);gn(kt,21,()=>le,Sn,(Xt,Bt)=>{var Qt=yd(),dn=u(Qt,!0);d(Qt);var Re={};H(()=>{re(dn,t(Bt).label),Re!==(Re=t(Bt).code)&&(Qt.value=(Qt.__value=t(Bt).code)??"")}),h(Xt,Qt)}),d(kt),d(wt),B("change",kt,Pe),Ir(kt,()=>t(v),Xt=>p(v,Xt)),h(tt,wt)};E(Tt,tt=>{t(A)==="browser"&&tt(Ye)})}var Ce=f(Tt,2),Ut=u(Ce),zt=u(Ut);it(zt),dt(2),d(Ut),dt(2),d(Ce);var an=f(Ce,2);{var cn=tt=>{var wt=kd(),kt=u(wt,!0);d(wt),H(()=>re(kt,t($))),h(tt,wt)};E(an,tt=>{t($)&&tt(cn)})}d(ee),H(()=>{me.disabled=!o,Yt(me,1,`flex-1 rounded border px-2 py-1.5 text-center font-medium transition-colors disabled:opacity-40
77
- ${t(A)==="browser"?"border-blue-500 bg-blue-600 text-white":"border-gray-600 bg-gray-950 text-gray-400 hover:text-white"}`),Yt(Ze,1,`flex-1 rounded border px-2 py-1.5 text-center font-medium transition-colors
78
- ${t(A)==="cloud"?"border-blue-500 bg-blue-600 text-white":"border-gray-600 bg-gray-950 text-gray-400 hover:text-white"}`),re(yt,t(A)==="browser"?"Uses free built-in browser dictation. Streaming, zero-latency.":"Uses server-side Z.ai / Groq / OpenAI keys. High accent tolerance.")}),B("click",T,()=>p(_,!1)),B("click",me,()=>{p(A,"browser"),Pe()}),B("click",Ze,()=>{p(A,"cloud"),Pe()}),B("change",zt,Pe),Tn(zt,()=>t(b),tt=>p(b,tt)),h(S,J)};E(j,S=>{t(_)&&S(ge)})}d(hn),H(()=>{Ee.disabled=e.disabled&&!t(a)&&!t(i)||t(i),Yt(Ee,1,`flex h-[48px] w-[48px] items-center justify-center rounded-lg border transition-all duration-150 disabled:cursor-not-allowed disabled:opacity-40
79
- ${t(a)?"animate-pulse border-red-500 bg-red-600 text-white":t(i)?"cursor-wait border-amber-500 bg-amber-600 text-white":"border-gray-600 bg-gray-800 text-gray-400 hover:bg-gray-700 hover:text-white"}`),Fe(Ee,"title",t(a)?"Recording (release/tap to stop)...":t(i)?"Processing speech...":"Hold to speak (walkie-talkie) or Tap to toggle recording"),lt.disabled=e.disabled&&!t(a)&&!t(i)||t(i),Yt(Vt,0,`h-4 w-4 transition-transform duration-200 ${t(_)?"rotate-45 text-white":""}`)}),B("pointerdown",Ee,ve),B("pointerup",Ee,pt),qn("pointercancel",Ee,te),B("click",lt,()=>p(_,!t(_))),h(n,hn),Kn()}tr(["pointerdown","pointerup","click","change"]);var Ed=m('<span class="inline-block h-1.5 w-1.5 animate-ping rounded-full bg-amber-400"></span> <span>Connecting to remote server...</span>',1),Cd=m('<span class="text-rose-400">⚠️</span> <span class="text-rose-400/80"> </span>',1),Rd=m('<span class="inline-block h-1.5 w-1.5 rounded-full bg-brand-surface-3"></span> <span>Disconnected from remote server</span>',1),Id=m('<div class="mb-2.5 flex items-center gap-1.5 text-xs font-medium text-brand-text-muted select-none"><!></div>'),$d=m('<div class="flex items-center"><button type="button" class="flex w-full items-center justify-between rounded-lg border border-brand-border bg-brand-surface-2 px-4 py-2.5 text-sm text-brand-text-muted transition-all hover:bg-brand-surface-3 hover:text-brand-text"><span class="flex items-center gap-2"><span> </span> <span><!></span></span> <span class="rounded bg-brand-surface-3 px-2 py-1 text-xs font-medium text-brand-text transition-colors hover:bg-brand-surface-2">Expand ▲</span></button></div>'),Md=m('<span class="inline-block h-3 w-3 animate-spin rounded-full border-2 border-brand-blue border-t-transparent"></span>'),Od=m('<a target="_blank" class="ml-1 shrink-0 font-semibold text-brand-blue underline hover:opacity-80">[Test Link]</a>'),Dd=m('<span class="flex items-center gap-1 text-[10px] font-medium text-rose-400"><span class="max-w-[120px] truncate"> </span> <!></span>'),Ld=m('<span class="text-emerald-400">✓</span>'),Pd=m('<div class="flex items-center gap-2 rounded border border-brand-border bg-brand-surface-2 px-2.5 py-1.5 text-xs"><span class="max-w-[150px] truncate font-medium text-brand-text"> </span> <!> <button type="button" class="ml-1 font-bold text-brand-text-muted hover:text-brand-text">×</button></div>'),Nd=m('<div class="mb-3 flex flex-wrap gap-2"></div>'),Fd=m("<option> </option>"),Ud=m('<div class="mb-2 flex items-center gap-2"><label for="search-model" class="text-xs font-medium text-brand-text-muted">Model</label> <select id="search-model" class="min-w-0 flex-1 rounded-lg border border-brand-border bg-brand-surface-2 px-2 py-1.5 text-xs text-brand-text focus:border-brand-blue focus:outline-none disabled:opacity-50"></select></div>'),zd=m('<button type="button" class="flex h-[40px] w-full items-center justify-center rounded-lg border border-brand-border bg-brand-surface-2 text-brand-text-muted transition-colors hover:bg-brand-surface-3 hover:text-brand-text disabled:cursor-not-allowed disabled:opacity-50" title="Attach file (image or document)">📎</button> <input type="file" multiple="" class="hidden"/>',1),Bd=m('<span class="hidden font-mono opacity-60 sm:inline">Shift+Enter to send</span>'),Hd=m('<!> <!> <form class="flex items-stretch gap-3"><div class="min-w-0 flex-1"><textarea class="h-full max-h-48 min-h-[120px] w-full resize-none overflow-y-auto rounded-lg border border-brand-border bg-brand-surface-2 px-4 py-3 leading-relaxed text-brand-text placeholder-brand-text-muted focus:border-brand-blue focus:outline-none disabled:opacity-50"></textarea></div> <div class="flex w-[80px] shrink-0 flex-col justify-end gap-2"><!> <div class="flex w-full justify-center"><!></div> <button type="submit" class="flex h-[40px] w-full items-center justify-center rounded-lg bg-gradient-to-r from-brand-cyan to-brand-blue text-xs font-medium text-brand-text transition-all hover:opacity-90 disabled:cursor-not-allowed disabled:bg-brand-surface-3 disabled:from-brand-surface-3 disabled:to-brand-surface-3 disabled:opacity-50"><!></button></div></form> <div class="mt-2 flex items-center justify-between px-1 text-[11px] text-brand-text-muted select-none"><label class="flex cursor-pointer items-center gap-1.5 hover:text-brand-text"><input type="checkbox" class="rounded border-brand-border bg-brand-surface-2 text-brand-blue focus:ring-0 focus:ring-offset-0"/> <span>Press Enter to send</span></label> <div class="flex items-center gap-3"><button type="button" class="rounded bg-brand-surface-3/50 px-2 py-0.5 text-xs text-brand-text-muted transition-colors hover:bg-brand-surface-3 hover:text-brand-text">Collapse ▽</button> <!></div></div>',1),Wd=m('<div class="border-t border-brand-border p-4"><!> <!></div>');function Gd(n,e){Vn(e,!0);const r=()=>Ue(Hs,"$isStreaming",c),s=()=>Ue(Xr,"$isReadOnly",c),o=()=>Ue(Lr,"$activeSessionInfo",c),a=()=>Ue(Dr,"$isConnected",c),i=()=>Ue(Nt,"$piState",c),[c,_]=pr();let b=Xn(e,"showAttach",3,!0),v=Xn(e,"searchMode",3,!1),A=Xn(e,"searchConfigured",3,!1),$=Xn(e,"searchModels",19,()=>[]),O=Xn(e,"searchModel",15,""),k=V(""),ae=V(!0),se=V(!1),he=V(void 0),ie=V(wn([])),rt=Q(r),Me=Q(s),Ge=Q(o),le=Q(a),Pe=Q(i),st=Q(()=>v()?e.disabled||!t(le)||!A():e.disabled||!t(le)||t(Me)||!t(Ge).sessionId),Ct=Q(()=>t(ie).some(j=>j.uploading)),at=Q(()=>!t(st)&&!t(Ct)&&(t(k).trim().length>0||t(ie).length>0)),be=V(void 0);const je="wherever-draft:";let _t=Q(()=>je+(t(Ge).sessionId??"search")),ot=V(null);Mr(()=>{const j=localStorage.getItem("wherever-enter-to-send");j!==null&&p(ae,j==="true")}),Lt(()=>{const j=t(_t);j!==t(ot)&&$s(()=>{let ge=null;if(typeof localStorage<"u")try{ge=localStorage.getItem(j)}catch{}p(k,ge??"",!0),p(ot,j,!0)})}),Lt(()=>{const j=t(k),ge=t(_t);if(!(ge!==t(ot)||typeof localStorage>"u"))try{j.trim().length>0?localStorage.setItem(ge,j):localStorage.removeItem(ge)}catch{}});function Je(){t(se)&&p(se,!1),t(be)?.focus()}function et(){p(ae,!t(ae)),localStorage.setItem("wherever-enter-to-send",String(t(ae)))}Lt(()=>{t(be)&&(t(k),t(be).style.height="auto",t(be).style.height=`${t(be).scrollHeight}px`)}),Lt(()=>{!t(st)&&t(be)&&t(be).focus()});async function Mt(j){zs();const ge=j.target;if(!ge.files)return;const S=Array.from(ge.files);ge.value="";const J=t(ie).length;p(ie,[...t(ie),...S.map(T=>({name:T.name,uploading:!0}))],!0);for(let T=0;T<S.length;T++){const ee=S[T],U=J+T;try{if(!t(Ge).sessionId)throw new Error("No active session");const we=await ga(t(Ge).sessionId,ee);p(ie,t(ie).map((me,Ze)=>Ze===U?{name:ee.name,path:we.savedPath,uploading:!1}:me),!0)}catch(we){const me=we.message||"Failed to upload";console.error("File upload error details:",we);let Ze="";try{const Ve=Un(),yt=zn();Ze=`${Ve}/health${yt?`?token=${encodeURIComponent(yt)}`:""}`}catch{}p(ie,t(ie).map((Ve,yt)=>yt===U?{name:ee.name,error:me,url:Ze,uploading:!1}:Ve),!0)}}}function Rt(j){p(ie,t(ie).filter((ge,S)=>S!==j),!0)}function ve(){const j=t(k).trim();if(v()){if(!j||t(st))return;e.onSubmit?.(j),p(k,""),e.onSend?.();return}if(!j&&t(ie).length===0)return;let ge=j;if(t(ie).length>0){const T=t(ie).filter(ee=>ee.path);if(T.length>0){const ee=T.map(U=>`[Uploaded file: ${U.path}]`).join(`
80
- `);ge?ge+=`
81
-
82
- `+ee:ge=`I have uploaded the following file(s) for you:
83
- ${ee}`}}if(j.startsWith("/")&&t(ie).length===0){const T=j.toLowerCase();if(T==="/new"||T==="/reset"){if(t(Ge).cwd){Mn(t(Ge).cwd,t(Ge).model||void 0),p(k,"");return}}else if(T==="/clear"){oa(),p(k,"");return}else if(T==="/leave"||T==="/exit"){kn(),p(k,"");return}}const S=_d({streaming:t(rt),connected:t(le),agentPending:t(Pe).agentPending,readOnly:t(Me),hasSession:!!t(Ge).sessionId});if(S.action!=="send"){(S.reason==="disconnected"||S.reason==="agent-pending")&&ws(ge);return}ws(ge)&&(p(k,""),p(ie,[],!0),e.onSend?.())}function pt(j){j.key==="Enter"&&(t(ae)?j.shiftKey||(j.preventDefault(),ve()):j.shiftKey&&(j.preventDefault(),ve()))}var te={focusInput:Je},Ft=Wd(),ye=u(Ft);{var ht=j=>{var ge=Id(),S=u(ge);{var J=U=>{var we=Ed();dt(2),h(U,we)},T=U=>{var we=Cd(),me=f(Zt(we),2),Ze=u(me,!0);d(me),H(()=>re(Ze,t(Pe).error)),h(U,we)},ee=U=>{var we=Rd();dt(2),h(U,we)};E(S,U=>{t(Pe).connecting?U(J):t(Pe).error?U(T,1):t(le)||U(ee,2)})}d(ge),h(j,ge)};E(ye,j=>{(!t(le)||t(Pe).connecting||t(Pe).error)&&j(ht)})}var hn=f(ye,2);{var Ee=j=>{var ge=$d(),S=u(ge),J=u(S),T=u(J),ee=u(T,!0);d(T);var U=f(T,2),we=u(U);{var me=Ye=>{var Ce=_n();H(()=>re(Ce,e.placeholder??"Search the web...")),h(Ye,Ce)},Ze=Ye=>{var Ce=_n("Agent is working, tap to Steer...");h(Ye,Ce)},Ve=Ye=>{var Ce=_n("Read-only mode");h(Ye,Ce)},yt=Ye=>{var Ce=_n("Select a session first...");h(Ye,Ce)},Tt=Ye=>{var Ce=_n("Tap to type a message...");h(Ye,Ce)};E(we,Ye=>{v()?Ye(me):t(rt)?Ye(Ze,1):t(Me)?Ye(Ve,2):t(Ge).sessionId?Ye(Tt,-1):Ye(yt,3)})}d(U),d(J),dt(2),d(S),d(ge),H(()=>re(ee,v()?"🔍":"💬")),B("click",S,()=>{p(se,!1),setTimeout(()=>t(be)?.focus(),50)}),h(j,ge)},lt=j=>{var ge=Hd(),S=Zt(ge);{var J=Re=>{var bt=Nd();gn(bt,21,()=>t(ie),Sn,(Ht,St,vt)=>{var Kt=Pd(),tn=u(Kt),un=u(tn,!0);d(tn);var bn=f(tn,2);{var En=Y=>{var ke=Md();h(Y,ke)},I=Y=>{var ke=Dd(),Ot=u(ke),Et=u(Ot);d(Ot);var Dt=f(Ot,2);{var At=C=>{var D=Od();H(()=>Fe(D,"href",t(St).url)),h(C,D)};E(Dt,C=>{t(St).url&&C(At)})}d(ke),H(()=>{Fe(ke,"title",t(St).error),re(Et,`⚠️ ${t(St).error??""}`)}),h(Y,ke)},W=Y=>{var ke=Ld();h(Y,ke)};E(bn,Y=>{t(St).uploading?Y(En):t(St).error?Y(I,1):Y(W,-1)})}var K=f(bn,2);d(Kt),H(()=>{Fe(tn,"title",t(St).name),re(un,t(St).name)}),B("click",K,()=>Rt(vt)),h(Ht,Kt)}),d(bt),h(Re,bt)};E(S,Re=>{t(ie).length>0&&Re(J)})}var T=f(S,2);{var ee=Re=>{var bt=Ud(),Ht=f(u(bt),2);gn(Ht,21,$,Sn,(St,vt)=>{var Kt=Fd(),tn=u(Kt,!0);d(Kt);var un={};H(()=>{re(tn,t(vt).label),un!==(un=t(vt).value)&&(Kt.value=(Kt.__value=t(vt).value)??"")}),h(St,Kt)}),d(Ht),d(bt),H(()=>Ht.disabled=t(st)),Ir(Ht,O),h(Re,bt)};E(T,Re=>{v()&&$().length>0&&Re(ee)})}var U=f(T,2),we=u(U),me=u(we);ri(me),Fe(me,"rows",1),Nn(me,Re=>p(be,Re),()=>t(be)),d(we);var Ze=f(we,2),Ve=u(Ze);{var yt=Re=>{var bt=zd(),Ht=Zt(bt),St=f(Ht,2);Nn(St,vt=>p(he,vt),()=>t(he)),H(()=>Ht.disabled=t(st)),B("click",Ht,()=>{Xo(),t(he)?.click()}),B("change",St,Mt),h(Re,bt)};E(Ve,Re=>{b()&&!v()&&Re(yt)})}var Tt=f(Ve,2),Ye=u(Tt);Ad(Ye,{get disabled(){return t(st)},onSend:ve,get text(){return t(k)},set text(Re){p(k,Re,!0)}}),d(Tt);var Ce=f(Tt,2),Ut=u(Ce);{var zt=Re=>{var bt=_n();H(()=>re(bt,e.submitLabel??"Search")),h(Re,bt)},an=Re=>{var bt=_n("Steer");h(Re,bt)},cn=Re=>{var bt=_n("Send");h(Re,bt)};E(Ut,Re=>{v()?Re(zt):t(rt)?Re(an,1):Re(cn,-1)})}d(Ce),d(Ze),d(U);var tt=f(U,2),wt=u(tt),kt=u(wt);it(kt),dt(2),d(wt);var Xt=f(wt,2),Bt=u(Xt),Qt=f(Bt,2);{var dn=Re=>{var bt=Bd();h(Re,bt)};E(Qt,Re=>{t(ae)||Re(dn)})}d(Xt),d(tt),H(()=>{me.disabled=t(st),Fe(me,"placeholder",v()?e.placeholder??"Search the web...":t(le)?t(rt)?"Agent is working, Steer to interrupt...":t(Me)?"Read-only mode":t(Ge).sessionId?"Type a message...":"Select a session first...":t(Pe).connecting?"Reconnecting to remote server...":"Disconnected - cannot send"),Ce.disabled=!t(at),Fe(Ce,"title",!v()&&t(rt)?"Steer the agent now (injected at the next step, before the next model call)":void 0),Po(kt,t(ae))}),qn("submit",U,Re=>{Re.preventDefault(),ve()}),B("keydown",me,pt),On(me,()=>t(k),Re=>p(k,Re)),B("change",kt,et),B("click",Bt,()=>p(se,!0)),h(j,ge)};E(hn,j=>{t(se)?j(Ee):j(lt,-1)})}d(Ft),h(n,Ft);var Vt=Kn(te);return _(),Vt}tr(["click","keydown","change"]);var jd=m('<button type="button" class="block w-full px-2.5 py-1 text-left text-xs text-brand-text transition-colors hover:bg-brand-surface-3 hover:text-brand-text"> </button>'),qd=m('<div class="absolute right-0 left-0 z-50 mt-1 max-h-40 overflow-y-auto rounded border border-brand-border bg-brand-surface-2 py-1 shadow-xl"></div>'),Vd=m('<span class="ml-1 font-semibold text-emerald-400">(Git repo)</span>'),Kd=m('<span class="mt-1 block text-[10px] font-medium text-yellow-400">📁 Folder already exists. <!></span>'),Yd=m("<option> </option>"),Zd=m('<select id="sidebar-model" class="w-full rounded border border-brand-border bg-brand-dark/60 px-2 py-1 text-xs text-brand-text focus:border-brand-blue focus:outline-none"></select>'),Xd=m('<input id="sidebar-model" type="text" placeholder="provider:model" class="w-full rounded border border-brand-border bg-brand-dark/60 px-2 py-1 text-xs text-brand-text placeholder-brand-text-muted focus:border-brand-blue focus:outline-none"/>'),Qd=m('<div class="flex items-center gap-3 pl-5 text-[10px] text-brand-text-muted"><span>Visibility:</span> <label class="flex cursor-pointer items-center gap-1 transition-colors select-none hover:text-brand-text"><input type="radio" name="sidebar-visibility" class="border-brand-border bg-brand-surface-2 text-brand-blue focus:ring-brand-blue"/> Private</label> <label class="flex cursor-pointer items-center gap-1 transition-colors select-none hover:text-brand-text"><input type="radio" name="sidebar-visibility" class="border-brand-border bg-brand-surface-2 text-brand-blue focus:ring-brand-blue"/> Public</label></div>'),Jd=m('<div class="space-y-1 py-0.5"><div class="flex items-center gap-1.5"><input id="sidebar-create-remote" type="checkbox" class="h-3.5 w-3.5 rounded border-brand-border bg-brand-surface-2 text-brand-blue focus:ring-brand-blue focus:ring-offset-brand-surface"/> <label for="sidebar-create-remote" class="cursor-pointer text-xs text-brand-text select-none"> </label></div> <!></div>'),eu=m('<div class="flex items-center gap-1.5 py-0.5"><input id="sidebar-git-init" type="checkbox" class="h-3.5 w-3.5 rounded border-brand-border bg-brand-surface-2 text-brand-blue focus:ring-brand-blue focus:ring-offset-brand-surface"/> <label for="sidebar-git-init" class="cursor-pointer text-xs text-brand-text select-none">Initialize Git repository</label></div>'),tu=m('<form class="space-y-2.5 border-t border-brand-border/30 bg-brand-surface/30 p-3"><div><label class="mb-1 block text-[10px] font-bold tracking-wider text-brand-text-muted uppercase" for="sidebar-folder">Folder Path</label> <div class="relative"><input id="sidebar-folder" type="text" autocomplete="off" spellcheck="false" placeholder="e.g. ~/projects/my-new-app"/> <!></div> <!></div> <div><label class="mb-1 block text-[10px] font-bold tracking-wider text-brand-text-muted uppercase" for="sidebar-model">Model</label> <!></div> <!> <!> <button type="submit" class="w-full rounded bg-gradient-to-r from-brand-cyan to-brand-blue py-1.5 text-xs font-semibold text-brand-text transition-all hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50">Create Session</button></form>'),nu=m('<div class="border-b border-brand-border/50 bg-brand-surface/10"><button class="flex w-full items-center justify-between px-3 py-2 text-left text-xs font-semibold text-brand-blue transition-colors hover:bg-brand-surface-3/30"><span> </span></button> <!></div>'),ru=m('<div class="p-4 text-center text-brand-text-muted"><div class="inline-block h-4 w-4 animate-spin rounded-full border-2 border-brand-text-muted border-t-transparent"></div> <span class="ml-2 text-sm">Loading sessions...</span></div>'),su=m('<div class="p-4 text-center text-sm text-brand-text-muted"> </div>'),ou=m('<div class="flex items-center gap-1 rounded border border-red-500/30 bg-brand-surface-2/80 px-1 py-0.5"><button class="px-1.5 text-xs font-bold text-rose-400 hover:text-rose-300 focus:outline-none" title="Confirm Delete All">Delete All?</button> <button class="px-1.5 text-[10px] text-brand-text-muted hover:text-brand-text focus:outline-none" title="Cancel">✕</button></div>'),au=m('<button class="rounded px-2 py-1 text-xs text-brand-text-muted transition-colors hover:bg-brand-surface-3/50 hover:text-rose-400 focus:outline-none" title="Delete all sessions in this folder">Delete All</button>'),iu=m('<div class="mb-1.5 flex items-center justify-between"><button class="rounded px-2 py-1 text-left text-xs text-brand-blue transition-colors hover:bg-brand-surface-3/50 hover:opacity-90">+ New Session Here</button> <div class="flex-shrink-0"><!></div></div>'),lu=m('<span class="h-2 w-2 flex-shrink-0 rounded-full bg-emerald-500"></span>'),cu=m('<span class="h-2 w-2 flex-shrink-0 rounded-full bg-brand-surface-3"></span>'),du=m('<span class="rounded bg-brand-surface-3 px-1.5 py-0.5 text-xs text-brand-text"> </span>'),uu=m('<div class="flex items-center gap-1 rounded border border-red-500/30 bg-brand-surface-2/80 px-1 py-0.5"><button class="px-1.5 text-xs font-bold text-rose-400 hover:text-rose-300 focus:outline-none" title="Confirm Delete">❓</button> <button class="px-1.5 text-[10px] text-brand-text-muted hover:text-brand-text focus:outline-none" title="Cancel">✕</button></div>'),fu=m('<button class="p-1 text-xs text-brand-text-muted transition-opacity hover:text-rose-400 focus:outline-none md:opacity-0 md:group-hover:opacity-100" title="Delete session">✕</button>'),pu=m('<div class="flex-shrink-0"><!></div>'),hu=m('<div><a class="flex min-w-0 flex-1 items-center gap-2 text-left no-underline"><!> <div class="min-w-0 flex-1"><div class="truncate text-xs text-brand-text"> </div> <div class="text-xs text-brand-text-muted"> </div></div> <!></a> <!></div>'),bu=m('<div class="px-3 pb-2"><!> <!></div>'),vu=m('<div class="border-b border-brand-border/50"><button class="flex w-full items-center gap-2 px-3 py-2 text-left transition-colors hover:bg-brand-surface-3/50"><span>▶</span> <div class="min-w-0 flex-1"><div class="truncate text-sm font-medium text-brand-text"> </div> <div class="truncate text-[10px] text-brand-text-muted"> </div></div> <span class="text-xs text-brand-text-muted"> </span></button> <!></div>'),gu=m("<option> </option>"),mu=m('<select id="model-select" class="w-full rounded border border-brand-border bg-brand-surface-3 px-2 py-1.5 text-xs text-brand-text"></select>'),xu=m('<input id="model-select" type="text" placeholder="provider:model" class="w-full rounded border border-brand-border bg-brand-surface-3 px-2 py-1.5 text-xs text-brand-text placeholder-brand-text-muted"/>'),_u=m('<div class="fixed inset-0 z-50 flex items-center justify-center bg-brand-dark/60" role="presentation"><div class="w-80 rounded-lg border border-brand-border bg-brand-surface-2 p-6" role="dialog" tabindex="-1"><h3 class="mb-4 text-sm font-bold text-brand-text">New Session</h3> <div class="mb-4"><span class="mb-1 block text-xs text-brand-text-muted">Folder</span> <div class="truncate rounded bg-brand-surface-3 px-2 py-1.5 text-xs text-brand-text"> </div></div> <div class="mb-4"><label class="mb-1 block text-xs text-brand-text-muted" for="model-select">Model</label> <!></div> <div class="flex justify-end gap-2"><button class="rounded bg-brand-surface-3 px-3 py-1.5 text-xs text-brand-text transition-colors hover:bg-brand-surface-2">Cancel</button> <button class="rounded bg-gradient-to-r from-brand-cyan to-brand-blue px-3 py-1.5 text-xs font-semibold text-brand-text transition-all hover:opacity-90">Create</button></div></div></div>'),yu=m('<div class="absolute right-0 bottom-0 left-0 flex items-center justify-between border-t border-red-500/30 bg-red-500/10 px-3 py-2 text-xs text-rose-400"><span class="truncate"> </span> <button class="ml-2 flex-shrink-0 text-rose-300 hover:text-rose-200">✕</button></div>'),wu=m('<span class="ml-1 text-[10px] text-brand-text-muted">(already a Git repo)</span>'),ku=m('<span class="ml-1 text-[10px] font-medium text-yellow-500">(folder not empty)</span>'),Su=m('<div class="flex items-center gap-3 pl-5 text-[10px] text-brand-text-muted"><span>Visibility:</span> <label class="flex cursor-pointer items-center gap-1 transition-colors select-none hover:text-brand-text"><input type="radio" name="sidebar-modal-visibility" class="border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue"/> Private</label> <label class="flex cursor-pointer items-center gap-1 transition-colors select-none hover:text-brand-text"><input type="radio" name="sidebar-modal-visibility" class="border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue"/> Public</label></div>'),Tu=m('<div class="space-y-1"><div class="flex items-center gap-1.5"><input id="sidebar-modal-create-remote" type="checkbox" class="h-3.5 w-3.5 rounded border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue"/> <label for="sidebar-modal-create-remote" class="cursor-pointer text-xs text-brand-text select-none"> </label></div> <!></div>'),Au=m('<div class="fixed inset-0 z-50 flex items-center justify-center bg-brand-dark/65 p-4" role="dialog" aria-modal="true"><div class="w-80 rounded-lg border border-brand-border bg-brand-surface-2 p-5 text-brand-text"><h3 class="mb-2 text-sm font-bold text-brand-text">Folder Already Exists</h3> <p class="mb-3 text-xs text-brand-text-muted">The folder <span class="font-mono text-[11px] break-all text-brand-text"> </span> already exists. Do you want to initialize a Git repository in it?</p> <div class="mb-4 flex flex-col gap-3"><div class="flex items-center gap-1.5"><input id="sidebar-modal-git-init" type="checkbox" class="h-3.5 w-3.5 rounded border-brand-border bg-brand-surface-3 text-brand-blue focus:ring-brand-blue disabled:opacity-50"/> <label for="sidebar-modal-git-init" class="cursor-pointer text-xs text-brand-text select-none disabled:opacity-50">Initialize Git repository <!></label></div> <!></div> <div class="flex justify-end gap-2"><button type="button" class="rounded bg-brand-surface-3 px-3 py-1.5 text-xs text-brand-text transition-colors hover:bg-brand-surface-2">Cancel</button> <button type="button" class="rounded bg-gradient-to-r from-brand-cyan to-brand-blue px-3 py-1.5 text-xs font-semibold text-brand-text transition-all hover:opacity-90">Confirm & Create</button></div></div></div>'),Eu=m('<div class="flex h-full flex-col"><div class="border-b border-brand-border/50 p-2"><div class="flex gap-1.5"><input type="text" placeholder="Filter sessions..." class="min-w-0 flex-1 rounded border border-brand-border bg-brand-surface-2 px-2 py-1.5 text-xs text-brand-text placeholder-brand-text-muted focus:border-brand-blue focus:outline-none"/> <button type="button" class="flex shrink-0 items-center justify-center rounded border border-brand-border bg-brand-surface-2 px-1.5 py-1.5 text-brand-text-muted transition-colors hover:bg-brand-surface-3 hover:text-brand-text" title="Refresh session list"><span>↻</span></button></div></div> <div class="flex-1 overflow-y-auto"><!> <!></div></div> <!> <!> <!>',1);function Mo(n,e){Vn(e,!0);const r=()=>Ue(kr,"$readOnlySessionFolders",A),s=()=>Ue(ur,"$sessionFolders",A),o=()=>Ue(Lr,"$activeSessionInfo",A),a=()=>Ue(Dr,"$isConnected",A),i=()=>Ue(Qr,"$isLoadingSession",A),c=()=>Ue(Gs,"$isResyncing",A),_=()=>Ue(fr,"$availableModels",A),b=()=>Ue(Ds,"$gitInitDefaultStore",A),v=()=>Ue(Ws,"$sessionError",A),[A,$]=pr(),O=[];let k=Xn(e,"readOnly",3,!1),ae=Q(()=>k()?r().folders:s().folders),se=Q(()=>k()?r().loading:s().loading);function he(){k()?Bo():Er()}let ie=Q(()=>o().sessionFile),rt=Q(a),Me=Q(i),Ge=Q(c),le=Q(()=>_().models),Pe=wn({}),st=V(wn({})),Ct=V(null),at=V(null),be=V(""),je=V(wn([]));Lt(()=>{t(rt)&&(he(),k()||(Ei(),Ci()))});function _t(I,W,K){if(!K)return!0;const Y=K.toLowerCase();return(I.name||"").toLowerCase().includes(Y)||I.firstMessage.toLowerCase().includes(Y)||W.toLowerCase().includes(Y)}Lt(()=>{const I=t(be),W=t(ae);I?p(je,W.map(K=>({...K,sessions:K.sessions.filter(Y=>_t(Y,K.name,I))})).filter(K=>K.sessions.length>0),!0):(p(je,W,!0),p(st,{},!0))});function ot(I){return t(be)?t(st)[I]!==void 0?t(st)[I]:!0:!!Pe[I]}function Je(I){t(be)?t(st)[I]=!ot(I):Pe[I]=!ot(I)}async function et(I){try{t(ie)===I&&(typeof window<"u"&&(window.location.hash=""),kn()),await Ts(I),t(Ct)===I&&p(Ct,null),Er()}catch(W){console.error("Failed to delete session:",W)}}async function Mt(I){try{const W=I.sessions.map(K=>K.path);t(ie)&&W.includes(t(ie))&&(typeof window<"u"&&(window.location.hash=""),kn()),await Promise.all(I.sessions.map(K=>Ts(K.path))),t(at)===I.path&&p(at,null),Er()}catch(W){console.error("Failed to delete all sessions of folder:",W)}}function Rt(I){t(ie)===I&&!t(Me)&&!t(Ge)||(Jn(),Bs(I))}let ve=V(!1),pt=V(""),te=V(wn([])),Ft=V(!1),ye=V(null),ht=V(null),hn="",Ee=V(""),lt=V(!1),Vt=V(null),j=V(!0),ge=V("private"),S=V(!1),J=Q(b);Lt(()=>{t(Vt)===null&&p(lt,t(J),!0)});let T=V(wn({exists:null,isGit:!1,resolvedPath:"",matchingRule:null})),ee=Q(()=>t(T).exists!==!0&&t(T).matchingRule&&t(j)),U=null;async function we(I,W=!1){if(U&&clearTimeout(U),I===hn&&!W)return;if(hn=I,!I.trim()){p(T,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0);const Y=async()=>{const ke=await Gr("");p(te,ke||[],!0)};W?await Y():U=setTimeout(Y,300);return}const K=async()=>{const[Y,ke]=await Promise.all([jo(I),Gr(I)]);p(te,ke||[],!0),Y?(p(T,{exists:Y.exists,isGit:Y.isGit,resolvedPath:Y.resolvedPath,matchingRule:Y.matchingRule||null},!0),Y.exists||(p(lt,t(Vt)!==null?t(Vt):t(J),!0),p(j,!0),Y.matchingRule&&p(ge,Y.matchingRule.visibility,!0))):p(T,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0)};W?await K():U=setTimeout(K,300)}Lt(()=>{const I=t(pt);we(I,!1)}),Lt(()=>{if(t(le).length>0&&!t(Ee)){const I=t(le).find(W=>W.isDefault);I?p(Ee,`${I.provider}:${I.modelId}`):p(Ee,`${t(le)[0].provider}:${t(le)[0].modelId}`)}});function me(){if(t(pt).trim())if(t(T).exists===!0)p(lt,!1),p(j,!1),t(T).matchingRule&&p(ge,t(T).matchingRule.visibility,!0),p(S,!0);else{Jn();const I=t(pt).trim(),W=t(Ee)||void 0,K=t(lt),Y=t(T).matchingRule?t(j):void 0,ke=t(T).matchingRule?t(ge):void 0;p(pt,""),p(ve,!1),t(ie)?(kn(),setTimeout(()=>{Mn(I,W,K,Y,ke)},100)):Mn(I,W,K,Y,ke)}}function Ze(){p(S,!1),Jn();const I=t(pt).trim(),W=t(Ee)||void 0,K=t(lt),Y=t(T).matchingRule?t(j):void 0,ke=t(T).matchingRule?t(ge):void 0;p(pt,""),p(ve,!1),t(ie)?(kn(),setTimeout(()=>{Mn(I,W,K,Y,ke)},100)):Mn(I,W,K,Y,ke)}let Ve=V(wn({open:!1,folderPath:"",selected:""}));function yt(I){const W=t(le).find(K=>K.isDefault);p(Ve,{open:!0,folderPath:I,selected:W?`${W.provider}:${W.modelId}`:""},!0)}function Tt(){t(Ve).open=!1}function Ye(){if(!t(Ve).open)return;Jn();const I=t(Ve).folderPath,W=t(Ve).selected||void 0;Tt(),t(ie)?(kn(),setTimeout(()=>{Mn(I,W)},100)):Mn(I,W)}function Ce(I){const W=Date.now()-new Date(I).getTime(),K=Math.floor(W/6e4);if(K<1)return"just now";if(K<60)return`${K}m ago`;const Y=Math.floor(K/60);return Y<24?`${Y}h ago`:`${Math.floor(Y/24)}d ago`}function Ut(I,W=40){return I.length>W?I.slice(0,W)+"...":I}var zt=Eu(),an=Zt(zt),cn=u(an),tt=u(cn),wt=u(tt);it(wt);var kt=f(wt,2),Xt=u(kt);d(kt),d(tt),d(cn);var Bt=f(cn,2),Qt=u(Bt);{var dn=I=>{var W=nu(),K=u(W),Y=u(K),ke=u(Y,!0);d(Y),d(K);var Ot=f(K,2);{var Et=Dt=>{var At=tu(),C=u(At),D=f(u(C),2),de=u(D);it(de),Nn(de,P=>p(ye,P),()=>t(ye));var Oe=f(de,2);{var Ne=P=>{var F=qd();gn(F,21,()=>t(te),Sn,(Te,ne)=>{var Se=jd(),_e=u(Se,!0);d(Se),H(()=>re(_e,t(ne))),B("click",Se,()=>{p(pt,t(ne),!0),we(t(ne),!0),t(ye)?.focus()}),h(Te,Se)}),d(F),h(P,F)};E(Oe,P=>{t(Ft)&&t(te).length>0&&P(Ne)})}d(D),Nn(D,P=>p(ht,P),()=>t(ht));var ze=f(D,2);{var G=P=>{var F=Kd(),Te=f(u(F));{var ne=Se=>{var _e=Vd();h(Se,_e)};E(Te,Se=>{t(T).isGit&&Se(ne)})}d(F),h(P,F)};E(ze,P=>{t(T).exists===!0&&P(G)})}d(C);var xe=f(C,2),x=f(u(xe),2);{var y=P=>{var F=Zd();gn(F,21,()=>t(le),Sn,(Te,ne)=>{var Se=Yd(),_e=u(Se);d(Se);var De={};H(()=>{re(_e,`${t(ne).label??""}${t(ne).isDefault?" (default)":""}`),De!==(De=`${t(ne).provider}:${t(ne).modelId}`)&&(Se.value=Se.__value=`${t(ne).provider}:${t(ne).modelId}`)}),h(Te,Se)}),d(F),Ir(F,()=>t(Ee),Te=>p(Ee,Te)),h(P,F)},L=P=>{var F=Xd();it(F),On(F,()=>t(Ee),Te=>p(Ee,Te)),h(P,F)};E(x,P=>{t(le).length>0?P(y):P(L,-1)})}d(xe);var z=f(xe,2);{var fe=P=>{var F=Jd(),Te=u(F),ne=u(Te);it(ne);var Se=f(ne,2),_e=u(Se);d(Se),d(Te);var De=f(Te,2);{var gt=Be=>{var Ke=Qd(),He=f(u(Ke),2),qe=u(He);it(qe),qe.value=qe.__value="private",dt(),d(He);var mt=f(He,2),Ie=u(mt);it(Ie),Ie.value=Ie.__value="public",dt(),d(mt),d(Ke),jn(O,[],qe,()=>t(ge),Z=>p(ge,Z)),jn(O,[],Ie,()=>t(ge),Z=>p(ge,Z)),h(Be,Ke)};E(De,Be=>{t(j)&&Be(gt)})}d(F),H(()=>re(_e,`Create remote ${t(T).matchingRule.provider??""} repository`)),Tn(ne,()=>t(j),Be=>p(j,Be)),h(P,F)};E(z,P=>{t(T).exists!==!0&&t(T).matchingRule&&P(fe)})}var X=f(z,2);{var w=P=>{var F=eu(),Te=u(F);it(Te),dt(2),d(F),B("change",Te,ne=>{p(Vt,ne.currentTarget.checked,!0)}),Tn(Te,()=>t(lt),ne=>p(lt,ne)),h(P,F)};E(X,P=>{t(T).exists!==!0&&(!t(T).matchingRule||!t(j))&&P(w)})}var ce=f(X,2);d(At),H(P=>{Yt(de,1,`w-full rounded border px-2 py-1 text-xs text-brand-text placeholder-brand-text-muted transition-all duration-200 focus:outline-none ${t(ee)?"border-emerald-500/80 bg-emerald-500/10 focus:border-emerald-400 focus:ring-1 focus:ring-emerald-400/30":"border-brand-border bg-brand-dark/60 focus:border-brand-blue"}`),ce.disabled=P},[()=>!t(pt).trim()]),qn("submit",At,P=>{P.preventDefault(),me()}),qn("focus",de,()=>{p(Ft,!0),we(t(pt),!0)}),qn("blur",de,P=>{t(ht)&&t(ht).contains(P.relatedTarget)||p(Ft,!1)}),B("keydown",de,P=>{P.key==="Escape"&&p(Ft,!1)}),On(de,()=>t(pt),P=>p(pt,P)),h(Dt,At)};E(Ot,Dt=>{t(ve)&&Dt(Et)})}d(W),H(()=>re(ke,t(ve)?"▼ Close Create Session":"✚ Create New Session")),B("click",K,()=>p(ve,!t(ve))),h(I,W)};E(Qt,I=>{k()||I(dn)})}var Re=f(Qt,2);{var bt=I=>{var W=ru();h(I,W)},Ht=I=>{var W=su(),K=u(W,!0);d(W),H(()=>re(K,t(be)?"No sessions match your filter":"No sessions found")),h(I,W)},St=I=>{var W=dr(),K=Zt(W);gn(K,17,()=>t(je),Y=>Y.path,(Y,ke)=>{var Ot=vu(),Et=u(Ot),Dt=u(Et),At=f(Dt,2),C=u(At),D=u(C,!0);d(C);var de=f(C,2),Oe=u(de,!0);d(de),d(At);var Ne=f(At,2),ze=u(Ne,!0);d(Ne),d(Et);var G=f(Et,2);{var xe=y=>{var L=bu(),z=u(L);{var fe=w=>{var ce=iu(),P=u(ce),F=f(P,2),Te=u(F);{var ne=_e=>{var De=ou(),gt=u(De),Be=f(gt,2);d(De),B("click",gt,Ke=>{Ke.stopPropagation(),Mt(t(ke))}),B("click",Be,Ke=>{Ke.stopPropagation(),p(at,null)}),h(_e,De)},Se=_e=>{var De=au();B("click",De,gt=>{gt.stopPropagation(),p(at,t(ke).path,!0)}),h(_e,De)};E(Te,_e=>{t(at)===t(ke).path?_e(ne):_e(Se,-1)})}d(F),d(ce),B("click",P,()=>yt(t(ke).path)),h(w,ce)};E(z,w=>{k()||w(fe)})}var X=f(z,2);gn(X,17,()=>t(ke).sessions,w=>w.path,(w,ce)=>{var P=hu(),F=u(P),Te=u(F);{var ne=Z=>{var oe=lu();h(Z,oe)},Se=Z=>{var oe=cu();h(Z,oe)};E(Te,Z=>{t(ce).isActive?Z(ne):Z(Se,-1)})}var _e=f(Te,2),De=u(_e),gt=u(De,!0);d(De);var Be=f(De,2),Ke=u(Be);d(Be),d(_e);var He=f(_e,2);{var qe=Z=>{var oe=du(),N=u(oe,!0);d(oe),H(()=>re(N,t(ce).clientCount)),h(Z,oe)};E(He,Z=>{t(ce).clientCount>0&&Z(qe)})}d(F);var mt=f(F,2);{var Ie=Z=>{var oe=pu(),N=u(oe);{var pe=Ae=>{var ue=uu(),Le=u(ue),It=f(Le,2);d(ue),B("click",Le,$t=>{$t.stopPropagation(),et(t(ce).path)}),B("click",It,$t=>{$t.stopPropagation(),p(Ct,null)}),h(Ae,ue)},We=Ae=>{var ue=fu();B("click",ue,Le=>{Le.stopPropagation(),p(Ct,t(ce).path,!0)}),h(Ae,ue)};E(N,Ae=>{t(Ct)===t(ce).path?Ae(pe):Ae(We,-1)})}d(oe),h(Z,oe)};E(mt,Z=>{k()||Z(Ie)})}d(P),H((Z,oe,N)=>{Yt(P,1,`group flex w-full items-center gap-2 rounded px-2 py-1.5 text-left transition-colors hover:bg-brand-surface-3/30 ${t(ie)===t(ce).path?"bg-brand-surface-3":""}`),Fe(F,"href",`#${Z??""}`),re(gt,oe),re(Ke,`${N??""} · ${t(ce).messageCount??""}
84
- msgs`)},[()=>encodeURIComponent(t(ce).id),()=>t(ce).name||Ut(t(ce).firstMessage)||"Empty session",()=>Ce(t(ce).modified)]),B("click",F,Z=>{Z.button===0&&!Z.ctrlKey&&!Z.metaKey&&!Z.altKey&&!Z.shiftKey&&(Z.preventDefault(),Rt(t(ce).path))}),h(w,P)}),d(L),h(y,L)},x=Q(()=>ot(t(ke).path));E(G,y=>{t(x)&&y(xe)})}d(Ot),H(y=>{Yt(Dt,1,`text-xs text-brand-text-muted transition-transform ${y??""}`),re(D,t(ke).name),re(Oe,t(ke).path),re(ze,t(ke).sessions.length)},[()=>ot(t(ke).path)?"rotate-90":""]),B("click",Et,()=>Je(t(ke).path)),h(Y,Ot)}),h(I,W)};E(Re,I=>{t(se)&&t(je).length===0?I(bt):t(je).length===0?I(Ht,1):I(St,-1)})}d(Bt),d(an);var vt=f(an,2);{var Kt=I=>{var W=_u(),K=u(W),Y=f(u(K),2),ke=f(u(Y),2),Ot=u(ke,!0);d(ke),d(Y);var Et=f(Y,2),Dt=f(u(Et),2);{var At=Ne=>{var ze=mu();gn(ze,21,()=>t(le),Sn,(G,xe)=>{var x=gu(),y=u(x);d(x);var L={};H(()=>{re(y,`${t(xe).label??""}${t(xe).isDefault?" (default)":""}`),L!==(L=`${t(xe).provider}:${t(xe).modelId}`)&&(x.value=x.__value=`${t(xe).provider}:${t(xe).modelId}`)}),h(G,x)}),d(ze),Ir(ze,()=>t(Ve).selected,G=>t(Ve).selected=G),h(Ne,ze)},C=Ne=>{var ze=xu();it(ze),On(ze,()=>t(Ve).selected,G=>t(Ve).selected=G),h(Ne,ze)};E(Dt,Ne=>{t(le).length>0?Ne(At):Ne(C,-1)})}d(Et);var D=f(Et,2),de=u(D),Oe=f(de,2);d(D),d(K),d(W),H(()=>re(Ot,t(Ve).folderPath)),B("click",W,Tt),B("click",K,Ne=>Ne.stopPropagation()),B("click",de,Tt),B("click",Oe,Ye),h(I,W)};E(vt,I=>{t(Ve).open&&I(Kt)})}var tn=f(vt,2);{var un=I=>{var W=yu(),K=u(W),Y=u(K,!0);d(K);var ke=f(K,2);d(W),H(()=>re(Y,v())),B("click",ke,()=>Jn()),h(I,W)};E(tn,I=>{v()&&I(un)})}var bn=f(tn,2);{var En=I=>{var W=Au(),K=u(W),Y=f(u(K),2),ke=f(u(Y)),Ot=u(ke,!0);d(ke),dt(),d(Y);var Et=f(Y,2),Dt=u(Et),At=u(Dt);it(At);var C=f(At,2),D=f(u(C));{var de=y=>{var L=wu();h(y,L)},Oe=y=>{var L=ku();h(y,L)};E(D,y=>{t(T).isGit?y(de):y(Oe,-1)})}d(C),d(Dt);var Ne=f(Dt,2);{var ze=y=>{var L=Tu(),z=u(L),fe=u(z);it(fe);var X=f(fe,2),w=u(X);d(X),d(z);var ce=f(z,2);{var P=F=>{var Te=Su(),ne=f(u(Te),2),Se=u(ne);it(Se),Se.value=Se.__value="private",dt(),d(ne);var _e=f(ne,2),De=u(_e);it(De),De.value=De.__value="public",dt(),d(_e),d(Te),jn(O,[],Se,()=>t(ge),gt=>p(ge,gt)),jn(O,[],De,()=>t(ge),gt=>p(ge,gt)),h(F,Te)};E(ce,F=>{t(j)&&F(P)})}d(L),H(()=>re(w,`Create remote ${t(T).matchingRule.provider??""} repository`)),Tn(fe,()=>t(j),F=>p(j,F)),h(y,L)};E(Ne,y=>{t(T).matchingRule&&y(ze)})}d(Et);var G=f(Et,2),xe=u(G),x=f(xe,2);d(G),d(K),d(W),H(()=>{re(Ot,t(pt)),At.disabled=t(T).isGit}),Tn(At,()=>t(lt),y=>p(lt,y)),B("click",xe,()=>p(S,!1)),B("click",x,Ze),h(I,W)};E(bn,I=>{t(S)&&I(En)})}H(()=>{oi(wt,t(be)),Yt(Xt,1,ui(t(se)?"animate-spin":""))}),B("input",wt,I=>p(be,I.currentTarget.value,!0)),B("click",kt,()=>he()),h(n,zt),Kn(),$()}tr(["input","click","keydown","change"]);var Cu=m(`<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">Session Conflict</h2> <p class="mb-6 text-sm text-brand-text-muted">Another client is active on a session in folder <span class="font-mono text-xs text-brand-text"> </span>. What would you like to do?</p> <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">Read Only</button> <button class="flex-1 rounded-lg bg-rose-500 px-4 py-2.5 text-sm text-brand-text transition-colors hover:bg-rose-600">Take Over</button></div> <p class="mt-4 text-xs text-brand-text-muted"><strong class="text-brand-text">Read Only:</strong> Observe the session
85
- live but cannot send messages.<br/> <strong class="text-brand-text">Take Over:</strong> Interrupt the other client
86
- and gain control.</p></div></div>`);function Ru(n,e){Vn(e,!0);const r=()=>Ue(da,"$conflict",s),[s,o]=pr();let a=Q(r);var i=dr(),c=Zt(i);{var _=b=>{var v=Cu(),A=u(v),$=f(u(A),2),O=f(u($)),k=u(O,!0);d(O),dt(),d($);var ae=f($,2),se=u(ae),he=f(se,2);d(ae),dt(2),d(A),d(v),H(()=>re(k,t(a).conflictingCwd)),B("click",se,()=>ks("read_only")),B("click",he,()=>ks("take_over")),h(b,v)};E(c,b=>{t(a)&&b(_)})}h(n,i),Kn(),o()}tr(["click"]);function Iu(n){return n.loading||n.resyncing||n.hasSessionHash}function $u(n){return n.connected&&n.searchConfigured&&!n.hasSession&&!Iu(n)}var Mu=m('<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>'),Ou=m('<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),Du=m('<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),Lu=m('<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>'),Pu=m('<div class="truncate text-xs text-brand-text-muted"> </div>'),Nu=m('<div class="truncate text-xs text-brand-text-muted"> </div>'),Fu=m('<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>'),Uu=m('<div class="mt-2 text-xs text-rose-400"> </div>'),zu=m('<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>'),Bu=m('<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>'),Hu=m('<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" title="App build version"> </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),Wu=m('<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>'),Gu=m('<span class="text-sm text-brand-text-muted">Search the web below, or pick a session from the sidebar</span>'),ju=m('<span class="text-sm text-brand-text-muted">Select a session from sidebar</span>'),qu=m('<span class="text-sm text-brand-text-muted">Not connected</span>'),Vu=m('<div class="flex min-w-0 items-center gap-2"><!></div>'),Ku=m('<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>'),Yu=m("<option> </option>"),Zu=m('<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>'),Xu=m('<span class="truncate text-brand-text-muted"> </span>'),Qu=m('<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>'),Ju=m('<div class="flex min-w-0 flex-1 items-center gap-3"><!> <!></div>'),ef=m('<span class="flex-shrink-0 rounded bg-yellow-500/20 px-2 py-1 text-xs text-yellow-400">Read-only</span>'),tf=m('<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>'),nf=m('<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>'),rf=m('<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>'),sf=m('<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>'),of=m('<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>'),af=m('<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>'),lf=m('<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>'),cf=m("<!> <!>",1),df=m('<button type="button" class="fixed inset-0 z-10 bg-brand-dark/50 md:hidden" aria-label="Close sidebar"></button>'),uf=m('<!> <!> <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 _f(n,e){Vn(e,!0);const r=()=>Ue(Dr,"$isConnected",se),s=()=>Ue(Gs,"$isResyncing",se),o=()=>Ue(ha,"$isAgentPending",se),a=()=>Ue(Qr,"$isLoadingSession",se),i=()=>Ue(ua,"$isInterrupted",se),c=()=>Ue(Ws,"$sessionError",se),_=()=>Ue(fa,"$sessionNotice",se),b=()=>Ue(Xr,"$isReadOnly",se),v=()=>Ue(Lr,"$activeSessionInfo",se),A=()=>Ue(Nt,"$piState",se),$=()=>Ue(fr,"$availableModels",se),O=()=>Ue(pa,"$isCreatingSession",se),k=()=>Ue(Ls,"$searchFolderStore",se),ae=()=>Ue(Go,"$searchDefaultModelStore",se),[se,he]=pr();let ie=V(!1),rt=V("main"),Me=V(!1),Ge;Mr(()=>{setTimeout(()=>Qn(),200);const C=()=>{if(t(be)){const ze=window.location.hash?decodeURIComponent(window.location.hash.slice(1)):"";ze&&ze!==t(ye)?Bs(ze):!ze&&t(ye)&&kn()}};window.addEventListener("hashchange",C);let D=null;const de=8e3,Oe=()=>{if(document.visibilityState==="hidden"){if(Qo())return;D&&clearTimeout(D),D=setTimeout(()=>{D=null,document.visibilityState==="hidden"&&t(be)&&Zo()},de)}else zs(),D&&(clearTimeout(D),D=null),t(be)||(ys()?_s():Qn())},Ne=ze=>{D&&(clearTimeout(D),D=null),document.visibilityState!=="hidden"&&!t(be)&&(ys()?_s():Qn())};return document.addEventListener("visibilitychange",Oe),window.addEventListener("pageshow",Ne),()=>{window.removeEventListener("hashchange",C),document.removeEventListener("visibilitychange",Oe),window.removeEventListener("pageshow",Ne),D&&clearTimeout(D)}});function le(){Qn()}function Pe(){kn(),$r()}function st(){$r(),setTimeout(()=>Qn(),100)}function Ct(){Er()}function at(){typeof window<"u"&&(window.location.hash=""),kn(),p(ie,!1)}let be=Q(r),je=Q(s),_t=Q(o),ot=Q(a),Je=Q(i),et=Q(c),Mt=Q(_),Rt=Q(b),ve=Q(v),pt=Q(A),te=Q(()=>$().models),Ft=V(!1),ye=Q(()=>t(ve).sessionId);Lt(()=>{typeof window<"u"&&t(be)&&(t(ye)?(window.location.hash=encodeURIComponent(t(ye)),p(Ft,!0)):t(Ft)&&(p(Ft,!1),window.location.hash&&(window.location.hash="")))});let ht=null;Lt(()=>{if(!t(be)||typeof window>"u"||!window.location.hash)return;const C=decodeURIComponent(window.location.hash.slice(1));C&&(t(ye)===C||t(ot)||t(je)||ht||(ht=setTimeout(()=>{ht=null,!(t(ye)===C||t(ot)||t(je))&&na(C)},300)))}),Lt(()=>{t(be)||p(Ft,!1)}),Lt(()=>{(t(ye)||t(ot)||t(je))&&p(ie,!1)});let hn=Q(O),Ee=Q(k),lt=V(void 0),Vt=Q(()=>$u({connected:t(be),searchConfigured:!!t(Ee),hasSession:!!t(ve).sessionFile,loading:t(ot),resyncing:t(je),hasSessionHash:typeof window<"u"&&!!window.location.hash})),j=Q(()=>t(te).map(C=>({value:`${C.provider}:${C.modelId}`,label:`${C.label}${C.isDefault?" (default)":""}`}))),ge=Q(ae),S=V("");Lt(()=>{if(t(j).length===0||t(j).some(Oe=>Oe.value===t(S)))return;const D=t(j).find(Oe=>Oe.value===t(ge)),de=t(te).find(Oe=>Oe.isDefault);p(S,D?D.value:de?`${de.provider}:${de.modelId}`:t(j)[0].value,!0)});let J=V(!1);Lt(()=>{t(Vt)&&!t(J)&&t(lt)&&(p(J,!0),t(lt).focusInput())});function T(){typeof window<"u"&&window.location.hash&&(window.location.hash=""),kn(),t(lt)?.focusInput()}var ee=uf(),U=Zt(ee);xi(U,{title:"Wherever",description:"Create & maintain apps from wherever"});var we=f(U,2);{var me=C=>{var D=Mu();h(C,D)};E(we,C=>{t(hn)&&C(me)})}var Ze=f(we,2),Ve=u(Ze),yt=u(Ve),Tt=u(yt),Ye=u(Tt);{var Ce=C=>{var D=Ou(),de=f(Zt(D),2);B("click",de,()=>p(Me,!1)),h(C,D)},Ut=C=>{var D=Du(),de=Zt(D),Oe=u(de);dt(2),d(de);var Ne=f(de,2),ze=u(Ne),G=f(ze,2);d(Ne),H(xe=>Fe(Oe,"src",xe),[()=>cr("/logo.svg")]),B("click",de,at),B("click",ze,()=>p(Me,!0)),B("click",G,()=>p(ie,!1)),h(C,D)};E(Ye,C=>{t(Me)?C(Ce):C(Ut,-1)})}d(Tt),d(yt);var zt=f(yt,2);{var an=C=>{var D=Lu(),de=u(D);{let x=Q(()=>(t(pt).connected,"localhost"));Vi(de,{get host(){return t(x)},port:31415,token:"",onConnected:le})}var Oe=f(de,2),Ne=f(u(Oe),2),ze=u(Ne),G=f(ze,2),xe=f(G,2);d(Ne),d(Oe),d(D),B("click",ze,Ct),B("click",G,st),B("click",xe,Pe),h(C,D)},cn=C=>{var D=Hu(),de=Zt(D),Oe=u(de),Ne=u(Oe),ze=f(Ne,2),G=u(ze,!0);d(ze);var xe=f(ze,2),x=u(xe);d(xe),d(Oe);var y=f(Oe,2);{var L=_e=>{var De=Fu(),gt=u(De);{var Be=Ie=>{var Z=Pu(),oe=u(Z);d(Z),H(N=>{Fe(Z,"title",t(ve).cwd),re(oe,`📁 ${N??""}`)},[()=>t(ve).cwd.split("/").pop()||t(ve).cwd]),h(Ie,Z)};E(gt,Ie=>{t(ve).cwd&&Ie(Be)})}var Ke=f(gt,2);{var He=Ie=>{var Z=Nu(),oe=u(Z);d(Z),H(()=>{Fe(Z,"title",t(ve).model),re(oe,`🤖 ${t(ve).model??""}`)}),h(Ie,Z)};E(Ke,Ie=>{t(ve).model&&Ie(He)})}var qe=f(Ke,2),mt=u(qe);d(qe),d(De),B("click",mt,at),h(_e,De)};E(y,_e=>{t(ve).sessionFile&&_e(L)})}var z=f(y,2);{var fe=_e=>{var De=Uu(),gt=u(De,!0);d(De),H(()=>re(gt,t(pt).error)),h(_e,De)};E(z,_e=>{t(pt).error&&!t(be)&&_e(fe)})}d(de);var X=f(de,2),w=u(X);{var ce=_e=>{var De=zu();B("click",De,()=>{p(rt,"readonly"),Bo()}),h(_e,De)},P=_e=>{var De=Bu();B("click",De,()=>p(rt,"main")),h(_e,De)};E(w,_e=>{t(rt)==="main"?_e(ce):_e(P,-1)})}d(X);var F=f(X,2),Te=u(F);{var ne=_e=>{Mo(_e,{readOnly:!0})},Se=_e=>{Mo(_e,{})};E(Te,_e=>{t(rt)==="readonly"?_e(ne):_e(Se,-1)})}d(F),H(()=>{Yt(Ne,1,`h-2.5 w-2.5 rounded-full ${t(be)?"bg-emerald-500":"bg-rose-500"}`),Yt(ze,1,`text-sm ${t(be)?"text-emerald-400":"text-rose-400"}`),re(G,t(be)?"Connected":"Disconnected"),re(x,`v${No}`)}),h(C,D)};E(zt,C=>{t(Me)?C(an):C(cn,-1)})}d(Ve);var tt=f(Ve,2),wt=u(tt),kt=u(wt),Xt=f(kt,2);{var Bt=C=>{var D=Wu();B("click",D,T),h(C,D)};E(Xt,C=>{t(be)&&t(Ee)&&t(ve).sessionFile&&C(Bt)})}var Qt=f(Xt,2);{var dn=C=>{var D=Vu(),de=u(D);{var Oe=G=>{var xe=Gu();h(G,xe)},Ne=G=>{var xe=ju();h(G,xe)},ze=G=>{var xe=qu();h(G,xe)};E(de,G=>{t(be)&&t(Vt)?G(Oe):t(be)?G(Ne,1):G(ze,-1)})}d(D),h(C,D)};E(Qt,C=>{(!t(be)||!t(ve).sessionFile)&&C(dn)})}var Re=f(Qt,2);{var bt=C=>{var D=Ju(),de=u(D);{var Oe=G=>{var xe=Ku(),x=f(u(xe),2),y=u(x,!0);d(x),d(xe),H(L=>{Fe(x,"title",t(ve).cwd),re(y,L)},[()=>t(ve).cwd.split("/").pop()||t(ve).cwd]),h(G,xe)};E(de,G=>{t(ve).cwd&&G(Oe)})}var Ne=f(de,2);{var ze=G=>{var xe=Qu(),x=u(xe),y=f(u(x),2);d(x);var L=f(x,2);{var z=X=>{var w=Zu();gn(w,21,()=>t(te),Sn,(P,F)=>{var Te=Yu(),ne=u(Te,!0);d(Te);var Se={};H(()=>{re(ne,t(F).label),Se!==(Se=`${t(F).provider}:${t(F).modelId}`)&&(Te.value=Te.__value=`${t(F).provider}:${t(F).modelId}`)}),h(P,Te)}),d(w);var ce;Uo(w),H(()=>{ce!==(ce=t(ve).model)&&(w.value=(w.__value=t(ve).model)??"",Os(w,t(ve).model))}),B("input",w,P=>la(P.currentTarget.value)),h(X,w)},fe=X=>{var w=Xu(),ce=u(w,!0);d(w),H(()=>{Fe(w,"title",t(ve).model),re(ce,t(ve).model)}),h(X,w)};E(L,X=>{t(te).length>0&&!t(Rt)?X(z):X(fe,-1)})}d(xe),H(()=>{Yt(y,1,`absolute -right-0.5 -bottom-0.5 h-2 w-2 rounded-full border border-brand-surface ${t(pt).isStreaming?"animate-pulse bg-orange-500":"bg-emerald-500"}`),Fe(y,"title",t(pt).isStreaming?"Agent working...":"Ready")}),h(G,xe)};E(Ne,G=>{t(ve).model&&G(ze)})}d(D),h(C,D)};E(Re,C=>{t(ve).sessionFile&&C(bt)})}var Ht=f(Re,2);{var St=C=>{var D=ef();h(C,D)};E(Ht,C=>{t(Rt)&&C(St)})}d(wt);var vt=f(wt,2);{var Kt=C=>{var D=tf();h(C,D)};E(vt,C=>{t(Je)&&C(Kt)})}var tn=f(vt,2);{var un=C=>{var D=nf(),de=u(D),Oe=u(de,!0);d(de);var Ne=f(de,2);d(D),H(()=>{Yt(D,1,`flex items-start justify-between gap-2 border px-4 py-2 text-sm ${t(Mt).level==="warning"?"border-yellow-500/30 bg-yellow-500/10 text-yellow-400":"border-blue-500/30 bg-blue-500/10 text-blue-400"}`),re(Oe,t(Mt).message)}),B("click",Ne,()=>ia()),h(C,D)};E(tn,C=>{t(Mt)&&C(un)})}var bn=f(tn,2);{var En=C=>{var D=rf(),de=u(D),Oe=u(de,!0);d(de);var Ne=f(de,2);d(D),H(()=>re(Oe,t(et))),B("click",Ne,()=>Jn()),h(C,D)};E(bn,C=>{t(et)&&C(En)})}var I=f(bn,2);{var W=C=>{var D=sf();h(C,D)};E(I,C=>{t(Rt)&&!t(Je)&&C(W)})}var K=f(I,2);Nn(xd(K,{onMessageSent:()=>{}}),C=>Ge=C,()=>Ge);var Y=f(K,2);{var ke=C=>{var D=of();h(C,D)},Ot=C=>{var D=cf(),de=Zt(D);{var Oe=G=>{var xe=af();h(G,xe)},Ne=G=>{var xe=lf();h(G,xe)};E(de,G=>{t(ve).sessionFile&&(t(je)||!t(be))?G(Oe):t(ve).sessionFile&&t(_t)&&G(Ne,1)})}var ze=f(de,2);{let G=Q(()=>!!t(Ee)),xe=Q(()=>t(Vt)?!t(be):!t(be)||t(Rt)||!t(ve).sessionFile||t(je)||t(_t));Nn(Gd(ze,{get searchMode(){return t(Vt)},get searchConfigured(){return t(G)},get searchModels(){return t(j)},onSubmit:x=>ra(x,t(S)),placeholder:"Search the web...",submitLabel:"Search",get disabled(){return t(xe)},onSend:()=>Ge?.forceScrollToBottom(),get searchModel(){return t(S)},set searchModel(x){p(S,x,!0)}}),x=>p(lt,x,!0),()=>t(lt))}h(C,D)};E(Y,C=>{t(Rt)&&t(ve).sessionFile?C(ke):C(Ot,-1)})}d(tt);var Et=f(tt,2);Ru(Et,{});var Dt=f(Et,2);{var At=C=>{var D=df();B("click",D,()=>p(ie,!1)),h(C,D)};E(Dt,C=>{t(ie)&&C(At)})}d(Ze),H(()=>Yt(Ve,1,`app-chrome ${t(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`)),B("click",kt,()=>p(ie,!t(ie))),h(n,ee),Kn(),he()}tr(["click","input"]);export{_f as component,xf as universal};
87
- //# sourceMappingURL=2.CkE0xTRs.js.map