wherever-dev 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/index.js.map +1 -1
  3. package/dist/protocol.d.ts +1 -0
  4. package/dist/protocol.d.ts.map +1 -1
  5. package/dist/session-pool.d.ts +1 -1
  6. package/dist/session-pool.d.ts.map +1 -1
  7. package/dist/session-pool.js +12 -2
  8. package/dist/session-pool.js.map +1 -1
  9. package/package.json +1 -1
  10. package/public/_app/immutable/chunks/{7m9KUJTw.js → AKYq1B_H.js} +2 -2
  11. package/public/_app/immutable/chunks/{7m9KUJTw.js.map → AKYq1B_H.js.map} +1 -1
  12. package/public/_app/immutable/chunks/{iOifrPyg.js → B6nqL6vT.js} +2 -2
  13. package/public/_app/immutable/chunks/{iOifrPyg.js.map → B6nqL6vT.js.map} +1 -1
  14. package/public/_app/immutable/chunks/D1kp_rcw.js +2 -0
  15. package/public/_app/immutable/chunks/{BJ-yElom.js.map → D1kp_rcw.js.map} +1 -1
  16. package/public/_app/immutable/entry/{app.CoMMvtRj.js → app.CEswBNvV.js} +3 -3
  17. package/public/_app/immutable/entry/{app.CoMMvtRj.js.map → app.CEswBNvV.js.map} +1 -1
  18. package/public/_app/immutable/entry/start.uiuwtl9Q.js +2 -0
  19. package/public/_app/immutable/entry/start.uiuwtl9Q.js.map +1 -0
  20. package/public/_app/immutable/nodes/{0._ijXAasS.js → 0.BB8h1gn6.js} +2 -2
  21. package/public/_app/immutable/nodes/{0._ijXAasS.js.map → 0.BB8h1gn6.js.map} +1 -1
  22. package/public/_app/immutable/nodes/{1.CD-uwTM0.js → 1.Dz8Ni71j.js} +2 -2
  23. package/public/_app/immutable/nodes/{1.CD-uwTM0.js.map → 1.Dz8Ni71j.js.map} +1 -1
  24. package/public/_app/immutable/nodes/{2.BxrRwRXv.js → 2.DgGMrWj9.js} +31 -31
  25. package/public/_app/immutable/nodes/2.DgGMrWj9.js.map +1 -0
  26. package/public/_app/version.json +1 -1
  27. package/public/index.html +10 -10
  28. package/public/service-worker.js +1 -1
  29. package/public/_app/immutable/chunks/BJ-yElom.js +0 -2
  30. package/public/_app/immutable/entry/start.D1-dJuk4.js +0 -2
  31. package/public/_app/immutable/entry/start.D1-dJuk4.js.map +0 -1
  32. package/public/_app/immutable/nodes/2.BxrRwRXv.js.map +0 -1
@@ -1,46 +1,46 @@
1
- import{b as zr,a as h,c as Jn,g as m,d as Gn,e as W,f as Nn,s as ue,t as on}from"../chunks/vMsF8lo6.js";import{ar as hn,b2 as Ir,al as Kn,be as j,ap as Us,M as no,aS as ro,aq as Qr,d as ha,am as Jr,at as so,n as ao,a0 as oo,u as io,t as lo,a1 as co,V as uo,W as fo,H as po,b3 as zs,C as Hs,aE as Pr,a2 as On,ac as ho,az as bo,aZ as vo,ay as ba,bd as va,bf as go,bg as vs,aU as gs,aQ as Bs,aP as Fn,aM as Un,af as Ht,b6 as f,ai as t,a5 as mo,bh as se,$ as xo,bl as jn,ah as nr,a8 as Bt,aK as yr,a_ as p,X as u,aV as d,aI as it,b9 as V,aO as wn,bi as Rt,bj as _o,aT as yo}from"../chunks/CEg8tgYI.js";import{i as C,s as rr,a as qe,p as br}from"../chunks/MtE7VtNZ.js";import{a as wo,b as je,r as at,c as es,e as pn,i as An,d as ko}from"../chunks/iOifrPyg.js";import{_ as So,b as En}from"../chunks/ylfInSZr.js";import{v as ga}from"../chunks/BJ-yElom.js";import{p as To}from"../chunks/7m9KUJTw.js";function Ao(n,e,r=!1,s=!1,a=!1,o=!1){var l=n,c="";if(r){var _=n;hn&&(l=Ir(Kn(_)))}j(()=>{var v=no;if(c===(c=e()??"")){hn&&Us();return}if(r&&!hn){v.nodes=null,_.innerHTML=c,c!==""&&zr(Kn(_),_.lastChild);return}if(v.nodes!==null&&(ro(v.nodes.start,v.nodes.end),v.nodes=null),c!==""){if(hn){Qr.data;for(var I=Us(),N=I;I!==null&&(I.nodeType!==ha||I.data!=="");)N=I,I=Jr(I);if(I===null)throw so(),ao;zr(Qr,N),l=Ir(I);return}var $=s?io:a?lo:void 0,L=oo(s?"svg":a?"math":"template",$);L.innerHTML=c;var S=s||a?L:L.content;if(zr(Kn(S),S.lastChild),s||a)for(;Kn(S);)l.before(Kn(S));else l.before(S)}})}function Eo(n,e){let r=null,s=hn;var a;if(hn){r=Qr;for(var o=Kn(document.head);o!==null&&(o.nodeType!==ha||o.data!==n);)o=Jr(o);if(o===null)zs(!1);else{var l=Jr(o);o.remove(),Ir(l)}}hn||(a=document.head.appendChild(co()));try{uo(()=>{var c=fo(()=>e(a));c.f|=po})}finally{s&&(zs(!0),Ir(r))}}function ma(n){var e,r,s="";if(typeof n=="string"||typeof n=="number")s+=n;else if(typeof n=="object")if(Array.isArray(n)){var a=n.length;for(e=0;e<a;e++)n[e]&&(r=ma(n[e]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function Ro(){for(var n,e,r=0,s="",a=arguments.length;r<a;r++)(n=arguments[r])&&(e=ma(n))&&(s&&(s+=" "),s+=e);return s}function Co(n){return typeof n=="object"?Ro(n):n??""}function Io(n,e,r){var s=n==null?"":""+n;return s===""?null:s}function qt(n,e,r,s,a,o){var l=n[Hs];if(hn||l!==r||l===void 0){var c=Io(r);(!hn||c!==n.getAttribute("class"))&&(c==null?n.removeAttribute("class"):e?n.className=c:n.setAttribute("class",c)),n[Hs]=r}return o}function ms(n,e,r=!1){if(n.multiple){if(e==null)return;if(!bo(e))return vo();for(var s of n.options)s.selected=e.includes(vr(s));return}for(s of n.options){var a=vr(s);if(ba(a,e)){s.selected=!0;return}}(!r||e!==void 0)&&(n.selectedIndex=-1)}function xa(n){var e=new MutationObserver(()=>{ms(n,n.__value)});e.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),va(()=>{e.disconnect()})}function $r(n,e,r=e){var s=new WeakSet,a=!0;Pr(n,"change",o=>{var l=o?"[selected]":":checked",c;if(n.multiple)c=[].map.call(n.querySelectorAll(l),vr);else{var _=n.querySelector(l)??n.querySelector("option:not([disabled])");c=_&&vr(_)}r(c),n.__value=c,On!==null&&s.add(On)}),ho(()=>{var o=e();if(n===document.activeElement){var l=On;if(s.has(l))return}if(ms(n,o,a),a&&o===void 0){var c=n.querySelector(":checked");c!==null&&(o=vr(c),r(o))}n.__value=o,a=!1}),xa(n)}function vr(n){return"__value"in n?n.__value:n.value}function Rn(n,e,r=e){var s=new WeakSet;Pr(n,"input",async a=>{var o=a?n.defaultValue:n.value;if(o=Br(n)?Wr(o):o,r(o),On!==null&&s.add(On),await go(),o!==(o=e())){var l=n.selectionStart,c=n.selectionEnd,_=n.value.length;if(n.value=o??"",c!==null){var v=n.value.length;l===c&&c===_&&v>_?(n.selectionStart=v,n.selectionEnd=v):(n.selectionStart=l,n.selectionEnd=Math.min(c,v))}}}),(hn&&n.defaultValue!==n.value||vs(e)==null&&n.value)&&(r(Br(n)?Wr(n.value):n.value),On!==null&&s.add(On)),gs(()=>{var a=e();if(n===document.activeElement){var o=On;if(s.has(o))return}Br(n)&&a===Wr(n.value)||n.type==="date"&&!a&&!n.value||a!==n.value&&(n.value=a??"")})}const Hr=new Set;function Pn(n,e,r,s,a=s){var o=r.getAttribute("type")==="checkbox",l=n;let c=!1;if(e!==null)for(var _ of e)l=l[_]??=[];l.push(r),Pr(r,"change",()=>{var v=r.__value;o&&(v=Ws(l,v,r.checked)),a(v)},()=>a(o?[]:null)),gs(()=>{var v=s();if(hn&&r.defaultChecked!==r.checked){c=!0;return}o?(v=v||[],r.checked=v.includes(r.__value)):r.checked=ba(r.__value,v)}),va(()=>{var v=l.indexOf(r);v!==-1&&l.splice(v,1)}),Hr.has(l)||(Hr.add(l),Bs(()=>{l.sort((v,I)=>v.compareDocumentPosition(I)===4?-1:1),Hr.delete(l)})),Bs(()=>{if(c){var v;if(o)v=Ws(l,v,r.checked);else{var I=l.find(N=>N.checked);v=I?.__value}a(v)}})}function vn(n,e,r=e){Pr(n,"change",s=>{var a=s?n.defaultChecked:n.checked;r(a)}),(hn&&n.defaultChecked!==n.checked||vs(e)==null)&&r(n.checked),gs(()=>{var s=e();n.checked=!!s})}function Ws(n,e,r){for(var s=new Set,a=0;a<n.length;a+=1)n[a].checked&&s.add(n[a].__value);return r||s.delete(e),Array.from(s)}function Br(n){var e=n.type;return e==="number"||e==="range"}function Wr(n){return n===""?null:+n}const $o=!1,Mo=!0,vu=Object.freeze(Object.defineProperty({__proto__:null,prerender:Mo,ssr:$o},Symbol.toStringTag,{value:"Module"})),Gr="Wherever",Lo="Create & maintain apps from wherever with a beautiful remote workspace.",jr="https://localhost",Oo="#000000",Do="black-translucent";function Qn(n,e){return wo(n)}var Po=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 No(n,e){Fn(e,!0);const r=jr.endsWith("/")?jr.slice(0,-1):jr,s=r+"/preview.png";let a=se(()=>e.home||!1),o=se(()=>({type:e.type||"website",title:e.title||Gr,description:e.description||Lo,image:e.image||s,url:`${r}${To.url.pathname}`}));Eo("13n5pl5",l=>{var c=Po(),_=Ht(c),v=f(_,2),I=f(v,2);{var N=ft=>{var pt=Jn(),be=Ht(pt);C(be,Se=>{}),h(ft,pt)};C(I,ft=>{t(a)&&ft(N)})}var $=f(I,2),L=f($,2),S=f(L,2),ge=f(S,2),ye=f(ge,2),fe=f(ye,4),oe=f(fe,2),Ie=f(oe,2),Re=f(Ie,2),Ne=f(Re,2),he=f(Ne,2),$e=f(he,2),ot=f($e,2),me=f(ot,2),Ue=f(me,4),Me=f(Ue,4),Fe=f(Me,2),dt=f(Fe,2);j((ft,pt,be,Se)=>{je(_,"content",t(o).title),je(v,"content",t(o).description),je($,"content",t(o).type),je(L,"content",t(o).url),je(S,"content",t(o).title),je(ge,"content",t(o).description),je(ye,"content",t(o).image),je(fe,"content",t(o).url),je(oe,"content",t(o).title),je(Ie,"content",t(o).description),je(Re,"content",t(o).image),je(Ne,"href",ft),je(he,"href",pt),je($e,"href",be),je(ot,"href",Se),je(me,"content",Oo),je(Ue,"content",Gr),je(Me,"content",Do),je(Fe,"content",Gr),je(dt,"content",ga)},[()=>Qn("/pwa/favicon.png"),()=>Qn("/pwa/favicon.ico"),()=>Qn("/pwa/apple-touch-icon.png"),()=>Qn("/pwa/manifest.webmanifest")]),mo(()=>{xo.title=t(o).title??""}),h(l,c)}),Un()}function Rr(){}function Fo(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Uo(n,...e){if(n==null)return Rr;const r=n.subscribe(...e);return r.unsubscribe?()=>r.unsubscribe():r}function sn(n){let e;return Uo(n,r=>e=r)(),e}var Yn=[];function zo(n,e=Rr){let r;const s=new Set;function a(c){if(Fo(n,c)&&(n=c,r)){const _=!Yn.length;for(const v of s)v[1](),Yn.push(v,n);if(_){for(let v=0;v<Yn.length;v+=2)Yn[v][0](Yn[v+1]);Yn.length=0}}}function o(c){a(c(n))}function l(c,_=Rr){const v=[c,_];return s.add(v),s.size===1&&(r=e(a)||Rr),c(n),()=>{s.delete(v),s.size===0&&(r(),r=null)}}return{set:a,update:o,subscribe:l}}const qr={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,sessionError:null,readOnly:!1,activeSessionFile:null,activeCwd:null,activeModel:null,hideThinking:!1,hideTools:!1,historyTotalCount:0,historyOffset:0,loadingMoreHistory:!1,contextUsage:null};class Ln{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;constructor(e){this.config={secure:!0,...e},this.stateStore=zo({...qr,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}connect(e,r=!1){e&&(this.config={...this.config,...e}),this.disconnect(!1),this.stateStore.update(L=>r?{...L,connecting:!0,error:null}:{...qr,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const s=this.config.secure?"wss":"ws",a=this.config.host.startsWith("http")?this.config.host.replace(/^https?:\/\//,""):this.config.host,o=this.config.token?`?token=${encodeURIComponent(this.config.token)}`:"",l=`${s}://${a}:${this.config.port}/ws${o}`,c=this.config.WebSocketCtor||(typeof globalThis<"u"?globalThis.WebSocket:null);if(!c){this.stateStore.update(L=>({...L,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}try{const L=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=L?new c(l,L):new c(l)}catch(L){this.stateStore.update(S=>({...S,connecting:!1,error:`Failed to connect: ${L}`})),this.scheduleReconnect();return}const _=this.ws,v=()=>{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(fe=>({...fe,connected:!0,connecting:!1,error:null}));const L=sn(this.stateStore),S=this.resumeSessionFile??L.activeSessionFile,ge=this.resumeSessionFile!=null?this.resumeCwd:L.activeCwd??void 0,ye=this.resumeSessionFile!=null?this.resumeModel:L.activeModel??void 0;this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,S?(this.stateStore.update(fe=>fe.resyncing?fe:{...fe,resyncing:!0}),this.send({type:"session_load",sessionFile:S,cwd:ge,model:ye}),this.armLoadWatchdog()):this.stateStore.update(fe=>fe.resyncing?{...fe,resyncing:!1}:fe)},I=L=>{if(this.ws===_){this.lastInboundAt=Date.now();try{const S=typeof L.data=="string"?L.data:L.data.toString(),ge=JSON.parse(S);this.handleMessage(ge)}catch(S){console.error("Failed to parse WebSocket message:",S)}}},N=()=>{this.ws===_&&(this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.ws=null,this.stateStore.update(L=>({...L,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:L.activeSessionFile?!0:L.resyncing})),this.scheduleReconnect())},$=L=>{this.ws===_&&this.stateStore.update(S=>({...S,error:S.error||"Connection error occurred"}))};typeof _.addEventListener=="function"?(_.addEventListener("open",v),_.addEventListener("message",I),_.addEventListener("close",N),_.addEventListener("error",$)):typeof _.on=="function"&&(_.on("open",v),_.on("message",L=>I({data:L})),_.on("close",N),_.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}e?this.stateStore.set({...qr,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools}):this.stateStore.update(r=>({...r,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1}))}suspend(){const e=sn(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=sn(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||sn(this.stateStore).activeSessionFile!==null}startLivenessWatchdog(){this.stopLivenessWatchdog(),this.lastInboundAt=Date.now();const e=()=>{try{this.ping()}catch{}};typeof setInterval=="function"&&(this.heartbeatTimer=setInterval(e,Ln.HEARTBEAT_MS),this.heartbeatTimer&&typeof this.heartbeatTimer.unref=="function"&&this.heartbeatTimer.unref());const r=()=>{if(!this.ws)return;const s=Date.now()-this.lastInboundAt,a=sn(this.stateStore).isStreaming,o=a?Ln.TURN_STALL_MS:Ln.STALE_SOCKET_MS;if(s<o)return;console.warn(`[wherever] relay connection stale: no inbound frame for ${s}ms (threshold ${o}ms, ${a?"mid-turn":"idle"}); tearing down dead socket and reconnecting`),this.stopLivenessWatchdog();const l=this.ws;this.ws=null;try{typeof l.terminate=="function"?l.terminate():typeof l.close=="function"&&l.close()}catch{}this.stateStore.update(c=>({...c,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:a?"Connection to relay stalled mid-turn; reconnecting...":c.sessionError,isStreaming:!1})),this.scheduleReconnect()};typeof setInterval=="function"&&(this.livenessTimer=setInterval(r,Ln.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=sn(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."})))},Ln.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,sn(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."})))},Ln.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=!!sn(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 a=[...s.messages].reverse().find(o=>o.role==="thinking"&&o.isStreaming);if(!a){const o={id:this.generateId(),role:"thinking",content:e.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,o]}}return{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content+e.delta,isStreaming:!0}:o)}});break;case"message_update":this.stateStore.update(s=>{let a=[...s.messages].reverse().find(o=>o.role==="assistant"&&o.isStreaming);if(!a){const o={id:this.generateId(),role:"assistant",content:e.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,o]}}return{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content+e.delta,isStreaming:!0}:o)}});break;case"message_end":this.stateStore.update(s=>{let a=s.messages;const o=[...a].reverse().find(c=>c.role==="thinking"&&c.isStreaming);o&&(a=a.map(c=>c.id===o.id?{...c,isStreaming:!1}:c));const l=[...a].reverse().find(c=>c.role==="assistant"&&c.isStreaming);if(l)a=a.map(c=>c.id===l.id?{...c,content:e.content||c.content,isStreaming:!1}:c);else if(e.content){const c=[...a].reverse().find(v=>v.role==="user");e.role==="user"&&c&&c.content===e.content||(a=[...a,{id:this.generateId(),role:e.role||"assistant",content:e.content,timestamp:Date.now(),isStreaming:!1}])}return{...s,messages:a}});break;case"agent_end":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.agentEndTimeout=setTimeout(()=>{this.stateStore.update(s=>({...s,isStreaming:!1,messages:s.messages.map(a=>a.isStreaming?{...a,isStreaming:!1}: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,a])=>a!==void 0&&a!=="").map(([s,a])=>`${s}=${JSON.stringify(a)}`).join(" "):"";this.stateStore.update(s=>{const a=s.messages.map(l=>l.isStreaming&&(l.role==="assistant"||l.role==="thinking")?{...l,isStreaming:!1}:l),o={id:this.generateId(),role:"tool",content:r?`$ ${e.toolName} ${r}`:`$ ${e.toolName}`,timestamp:Date.now(),isStreaming:!0,toolName:e.toolName,toolArgs:r,toolOutput:""};return{...s,messages:[...a,o]}});break;case"tool_update":{this.stateStore.update(s=>{const a=[...s.messages].reverse().find(o=>o.role==="tool"&&o.toolName===e.toolName&&o.isStreaming);return a?{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content.includes(`
1
+ import{b as zr,a as h,c as Jn,g as m,d as Gn,e as W,f as Nn,s as ue,t as on}from"../chunks/vMsF8lo6.js";import{ar as hn,b2 as Ir,al as Kn,be as j,ap as Us,M as no,aS as ro,aq as Qr,d as ha,am as Jr,at as so,n as ao,a0 as oo,u as io,t as lo,a1 as co,V as uo,W as fo,H as po,b3 as zs,C as Hs,aE as Pr,a2 as On,ac as ho,az as bo,aZ as go,ay as ba,bd as ga,bf as vo,bg as gs,aU as vs,aQ as Bs,aP as Fn,aM as Un,af as Ht,b6 as f,ai as t,a5 as mo,bh as se,$ as xo,bl as jn,ah as nr,a8 as Bt,aK as yr,a_ as p,X as u,aV as d,aI as it,b9 as V,aO as wn,bi as Rt,bj as _o,aT as yo}from"../chunks/CEg8tgYI.js";import{i as C,s as rr,a as qe,p as br}from"../chunks/MtE7VtNZ.js";import{a as wo,b as je,r as at,c as es,e as pn,i as An,d as ko}from"../chunks/B6nqL6vT.js";import{_ as So,b as En}from"../chunks/ylfInSZr.js";import{v as va}from"../chunks/D1kp_rcw.js";import{p as To}from"../chunks/AKYq1B_H.js";function Ao(n,e,r=!1,s=!1,a=!1,o=!1){var l=n,c="";if(r){var _=n;hn&&(l=Ir(Kn(_)))}j(()=>{var g=no;if(c===(c=e()??"")){hn&&Us();return}if(r&&!hn){g.nodes=null,_.innerHTML=c,c!==""&&zr(Kn(_),_.lastChild);return}if(g.nodes!==null&&(ro(g.nodes.start,g.nodes.end),g.nodes=null),c!==""){if(hn){Qr.data;for(var I=Us(),N=I;I!==null&&(I.nodeType!==ha||I.data!=="");)N=I,I=Jr(I);if(I===null)throw so(),ao;zr(Qr,N),l=Ir(I);return}var $=s?io:a?lo:void 0,L=oo(s?"svg":a?"math":"template",$);L.innerHTML=c;var S=s||a?L:L.content;if(zr(Kn(S),S.lastChild),s||a)for(;Kn(S);)l.before(Kn(S));else l.before(S)}})}function Eo(n,e){let r=null,s=hn;var a;if(hn){r=Qr;for(var o=Kn(document.head);o!==null&&(o.nodeType!==ha||o.data!==n);)o=Jr(o);if(o===null)zs(!1);else{var l=Jr(o);o.remove(),Ir(l)}}hn||(a=document.head.appendChild(co()));try{uo(()=>{var c=fo(()=>e(a));c.f|=po})}finally{s&&(zs(!0),Ir(r))}}function ma(n){var e,r,s="";if(typeof n=="string"||typeof n=="number")s+=n;else if(typeof n=="object")if(Array.isArray(n)){var a=n.length;for(e=0;e<a;e++)n[e]&&(r=ma(n[e]))&&(s&&(s+=" "),s+=r)}else for(r in n)n[r]&&(s&&(s+=" "),s+=r);return s}function Ro(){for(var n,e,r=0,s="",a=arguments.length;r<a;r++)(n=arguments[r])&&(e=ma(n))&&(s&&(s+=" "),s+=e);return s}function Co(n){return typeof n=="object"?Ro(n):n??""}function Io(n,e,r){var s=n==null?"":""+n;return s===""?null:s}function qt(n,e,r,s,a,o){var l=n[Hs];if(hn||l!==r||l===void 0){var c=Io(r);(!hn||c!==n.getAttribute("class"))&&(c==null?n.removeAttribute("class"):e?n.className=c:n.setAttribute("class",c)),n[Hs]=r}return o}function ms(n,e,r=!1){if(n.multiple){if(e==null)return;if(!bo(e))return go();for(var s of n.options)s.selected=e.includes(gr(s));return}for(s of n.options){var a=gr(s);if(ba(a,e)){s.selected=!0;return}}(!r||e!==void 0)&&(n.selectedIndex=-1)}function xa(n){var e=new MutationObserver(()=>{ms(n,n.__value)});e.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),ga(()=>{e.disconnect()})}function $r(n,e,r=e){var s=new WeakSet,a=!0;Pr(n,"change",o=>{var l=o?"[selected]":":checked",c;if(n.multiple)c=[].map.call(n.querySelectorAll(l),gr);else{var _=n.querySelector(l)??n.querySelector("option:not([disabled])");c=_&&gr(_)}r(c),n.__value=c,On!==null&&s.add(On)}),ho(()=>{var o=e();if(n===document.activeElement){var l=On;if(s.has(l))return}if(ms(n,o,a),a&&o===void 0){var c=n.querySelector(":checked");c!==null&&(o=gr(c),r(o))}n.__value=o,a=!1}),xa(n)}function gr(n){return"__value"in n?n.__value:n.value}function Rn(n,e,r=e){var s=new WeakSet;Pr(n,"input",async a=>{var o=a?n.defaultValue:n.value;if(o=Br(n)?Wr(o):o,r(o),On!==null&&s.add(On),await vo(),o!==(o=e())){var l=n.selectionStart,c=n.selectionEnd,_=n.value.length;if(n.value=o??"",c!==null){var g=n.value.length;l===c&&c===_&&g>_?(n.selectionStart=g,n.selectionEnd=g):(n.selectionStart=l,n.selectionEnd=Math.min(c,g))}}}),(hn&&n.defaultValue!==n.value||gs(e)==null&&n.value)&&(r(Br(n)?Wr(n.value):n.value),On!==null&&s.add(On)),vs(()=>{var a=e();if(n===document.activeElement){var o=On;if(s.has(o))return}Br(n)&&a===Wr(n.value)||n.type==="date"&&!a&&!n.value||a!==n.value&&(n.value=a??"")})}const Hr=new Set;function Pn(n,e,r,s,a=s){var o=r.getAttribute("type")==="checkbox",l=n;let c=!1;if(e!==null)for(var _ of e)l=l[_]??=[];l.push(r),Pr(r,"change",()=>{var g=r.__value;o&&(g=Ws(l,g,r.checked)),a(g)},()=>a(o?[]:null)),vs(()=>{var g=s();if(hn&&r.defaultChecked!==r.checked){c=!0;return}o?(g=g||[],r.checked=g.includes(r.__value)):r.checked=ba(r.__value,g)}),ga(()=>{var g=l.indexOf(r);g!==-1&&l.splice(g,1)}),Hr.has(l)||(Hr.add(l),Bs(()=>{l.sort((g,I)=>g.compareDocumentPosition(I)===4?-1:1),Hr.delete(l)})),Bs(()=>{if(c){var g;if(o)g=Ws(l,g,r.checked);else{var I=l.find(N=>N.checked);g=I?.__value}a(g)}})}function gn(n,e,r=e){Pr(n,"change",s=>{var a=s?n.defaultChecked:n.checked;r(a)}),(hn&&n.defaultChecked!==n.checked||gs(e)==null)&&r(n.checked),vs(()=>{var s=e();n.checked=!!s})}function Ws(n,e,r){for(var s=new Set,a=0;a<n.length;a+=1)n[a].checked&&s.add(n[a].__value);return r||s.delete(e),Array.from(s)}function Br(n){var e=n.type;return e==="number"||e==="range"}function Wr(n){return n===""?null:+n}const $o=!1,Mo=!0,mu=Object.freeze(Object.defineProperty({__proto__:null,prerender:Mo,ssr:$o},Symbol.toStringTag,{value:"Module"})),Gr="Wherever",Lo="Create & maintain apps from wherever with a beautiful remote workspace.",jr="https://localhost",Oo="#000000",Do="black-translucent";function Qn(n,e){return wo(n)}var Po=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 No(n,e){Fn(e,!0);const r=jr.endsWith("/")?jr.slice(0,-1):jr,s=r+"/preview.png";let a=se(()=>e.home||!1),o=se(()=>({type:e.type||"website",title:e.title||Gr,description:e.description||Lo,image:e.image||s,url:`${r}${To.url.pathname}`}));Eo("13n5pl5",l=>{var c=Po(),_=Ht(c),g=f(_,2),I=f(g,2);{var N=ft=>{var pt=Jn(),be=Ht(pt);C(be,Se=>{}),h(ft,pt)};C(I,ft=>{t(a)&&ft(N)})}var $=f(I,2),L=f($,2),S=f(L,2),ve=f(S,2),ye=f(ve,2),fe=f(ye,4),oe=f(fe,2),Ie=f(oe,2),Re=f(Ie,2),Fe=f(Re,2),he=f(Fe,2),$e=f(he,2),ot=f($e,2),me=f(ot,2),Ue=f(me,4),Me=f(Ue,4),Le=f(Me,2),dt=f(Le,2);j((ft,pt,be,Se)=>{je(_,"content",t(o).title),je(g,"content",t(o).description),je($,"content",t(o).type),je(L,"content",t(o).url),je(S,"content",t(o).title),je(ve,"content",t(o).description),je(ye,"content",t(o).image),je(fe,"content",t(o).url),je(oe,"content",t(o).title),je(Ie,"content",t(o).description),je(Re,"content",t(o).image),je(Fe,"href",ft),je(he,"href",pt),je($e,"href",be),je(ot,"href",Se),je(me,"content",Oo),je(Ue,"content",Gr),je(Me,"content",Do),je(Le,"content",Gr),je(dt,"content",va)},[()=>Qn("/pwa/favicon.png"),()=>Qn("/pwa/favicon.ico"),()=>Qn("/pwa/apple-touch-icon.png"),()=>Qn("/pwa/manifest.webmanifest")]),mo(()=>{xo.title=t(o).title??""}),h(l,c)}),Un()}function Rr(){}function Fo(n,e){return n!=n?e==e:n!==e||n&&typeof n=="object"||typeof n=="function"}function Uo(n,...e){if(n==null)return Rr;const r=n.subscribe(...e);return r.unsubscribe?()=>r.unsubscribe():r}function sn(n){let e;return Uo(n,r=>e=r)(),e}var Yn=[];function zo(n,e=Rr){let r;const s=new Set;function a(c){if(Fo(n,c)&&(n=c,r)){const _=!Yn.length;for(const g of s)g[1](),Yn.push(g,n);if(_){for(let g=0;g<Yn.length;g+=2)Yn[g][0](Yn[g+1]);Yn.length=0}}}function o(c){a(c(n))}function l(c,_=Rr){const g=[c,_];return s.add(g),s.size===1&&(r=e(a)||Rr),c(n),()=>{s.delete(g),s.size===0&&(r(),r=null)}}return{set:a,update:o,subscribe:l}}const qr={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,sessionError:null,readOnly:!1,activeSessionFile:null,activeCwd:null,activeModel:null,hideThinking:!1,hideTools:!1,historyTotalCount:0,historyOffset:0,loadingMoreHistory:!1,contextUsage:null};class Ln{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;constructor(e){this.config={secure:!0,...e},this.stateStore=zo({...qr,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools})}connect(e,r=!1){e&&(this.config={...this.config,...e}),this.disconnect(!1),this.stateStore.update(L=>r?{...L,connecting:!0,error:null}:{...qr,connecting:!0,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools});const s=this.config.secure?"wss":"ws",a=this.config.host.startsWith("http")?this.config.host.replace(/^https?:\/\//,""):this.config.host,o=this.config.token?`?token=${encodeURIComponent(this.config.token)}`:"",l=`${s}://${a}:${this.config.port}/ws${o}`,c=this.config.WebSocketCtor||(typeof globalThis<"u"?globalThis.WebSocket:null);if(!c){this.stateStore.update(L=>({...L,connecting:!1,error:"No WebSocket implementation found. Please pass custom WebSocketCtor."}));return}try{const L=this.config.secure&&this.config.WebSocketCtor?{rejectUnauthorized:!1}:void 0;this.ws=L?new c(l,L):new c(l)}catch(L){this.stateStore.update(S=>({...S,connecting:!1,error:`Failed to connect: ${L}`})),this.scheduleReconnect();return}const _=this.ws,g=()=>{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(fe=>({...fe,connected:!0,connecting:!1,error:null}));const L=sn(this.stateStore),S=this.resumeSessionFile??L.activeSessionFile,ve=this.resumeSessionFile!=null?this.resumeCwd:L.activeCwd??void 0,ye=this.resumeSessionFile!=null?this.resumeModel:L.activeModel??void 0;this.resumeSessionFile=null,this.resumeCwd=void 0,this.resumeModel=void 0,S?(this.stateStore.update(fe=>fe.resyncing?fe:{...fe,resyncing:!0}),this.send({type:"session_load",sessionFile:S,cwd:ve,model:ye}),this.armLoadWatchdog()):this.stateStore.update(fe=>fe.resyncing?{...fe,resyncing:!1}:fe)},I=L=>{if(this.ws===_){this.lastInboundAt=Date.now();try{const S=typeof L.data=="string"?L.data:L.data.toString(),ve=JSON.parse(S);this.handleMessage(ve)}catch(S){console.error("Failed to parse WebSocket message:",S)}}},N=()=>{this.ws===_&&(this.stopLivenessWatchdog(),this.clearLoadWatchdog(),this.ws=null,this.stateStore.update(L=>({...L,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,resyncing:L.activeSessionFile?!0:L.resyncing})),this.scheduleReconnect())},$=L=>{this.ws===_&&this.stateStore.update(S=>({...S,error:S.error||"Connection error occurred"}))};typeof _.addEventListener=="function"?(_.addEventListener("open",g),_.addEventListener("message",I),_.addEventListener("close",N),_.addEventListener("error",$)):typeof _.on=="function"&&(_.on("open",g),_.on("message",L=>I({data:L})),_.on("close",N),_.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}e?this.stateStore.set({...qr,hideThinking:!!this.config.hideThinking,hideTools:!!this.config.hideTools}):this.stateStore.update(r=>({...r,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1}))}suspend(){const e=sn(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=sn(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||sn(this.stateStore).activeSessionFile!==null}startLivenessWatchdog(){this.stopLivenessWatchdog(),this.lastInboundAt=Date.now();const e=()=>{try{this.ping()}catch{}};typeof setInterval=="function"&&(this.heartbeatTimer=setInterval(e,Ln.HEARTBEAT_MS),this.heartbeatTimer&&typeof this.heartbeatTimer.unref=="function"&&this.heartbeatTimer.unref());const r=()=>{if(!this.ws)return;const s=Date.now()-this.lastInboundAt,a=sn(this.stateStore).isStreaming,o=a?Ln.TURN_STALL_MS:Ln.STALE_SOCKET_MS;if(s<o)return;console.warn(`[wherever] relay connection stale: no inbound frame for ${s}ms (threshold ${o}ms, ${a?"mid-turn":"idle"}); tearing down dead socket and reconnecting`),this.stopLivenessWatchdog();const l=this.ws;this.ws=null;try{typeof l.terminate=="function"?l.terminate():typeof l.close=="function"&&l.close()}catch{}this.stateStore.update(c=>({...c,connected:!1,connecting:!1,loadingSession:!1,creatingSession:!1,sessionError:a?"Connection to relay stalled mid-turn; reconnecting...":c.sessionError,isStreaming:!1})),this.scheduleReconnect()};typeof setInterval=="function"&&(this.livenessTimer=setInterval(r,Ln.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=sn(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."})))},Ln.LOAD_WATCHDOG_MS)}clearLoadWatchdog(){this.loadWatchdog&&(clearTimeout(this.loadWatchdog),this.loadWatchdog=null)}armCreateWatchdog(){this.clearCreateWatchdog(),this.createWatchdog=setTimeout(()=>{this.createWatchdog=null,sn(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."})))},Ln.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=!!sn(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 a=[...s.messages].reverse().find(o=>o.role==="thinking"&&o.isStreaming);if(!a){const o={id:this.generateId(),role:"thinking",content:e.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,o]}}return{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content+e.delta,isStreaming:!0}:o)}});break;case"message_update":this.stateStore.update(s=>{let a=[...s.messages].reverse().find(o=>o.role==="assistant"&&o.isStreaming);if(!a){const o={id:this.generateId(),role:"assistant",content:e.delta,timestamp:Date.now(),isStreaming:!0};return{...s,messages:[...s.messages,o]}}return{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content+e.delta,isStreaming:!0}:o)}});break;case"message_end":this.stateStore.update(s=>{let a=s.messages;const o=[...a].reverse().find(c=>c.role==="thinking"&&c.isStreaming);o&&(a=a.map(c=>c.id===o.id?{...c,isStreaming:!1}:c));const l=[...a].reverse().find(c=>c.role==="assistant"&&c.isStreaming);if(l)a=a.map(c=>c.id===l.id?{...c,content:e.content||c.content,isStreaming:!1}:c);else if(e.content){const c=[...a].reverse().find(g=>g.role==="user");e.role==="user"&&c&&c.content===e.content||(a=[...a,{id:this.generateId(),role:e.role||"assistant",content:e.content,timestamp:Date.now(),isStreaming:!1}])}return{...s,messages:a}});break;case"agent_end":this.agentEndTimeout&&(clearTimeout(this.agentEndTimeout),this.agentEndTimeout=null),this.agentEndTimeout=setTimeout(()=>{this.stateStore.update(s=>({...s,isStreaming:!1,messages:s.messages.map(a=>a.isStreaming?{...a,isStreaming:!1}: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,a])=>a!==void 0&&a!=="").map(([s,a])=>`${s}=${JSON.stringify(a)}`).join(" "):"";this.stateStore.update(s=>{const a=s.messages.map(l=>l.isStreaming&&(l.role==="assistant"||l.role==="thinking")?{...l,isStreaming:!1}:l),o={id:this.generateId(),role:"tool",content:r?`$ ${e.toolName} ${r}`:`$ ${e.toolName}`,timestamp:Date.now(),isStreaming:!0,toolName:e.toolName,toolArgs:r,toolOutput:""};return{...s,messages:[...a,o]}});break;case"tool_update":{this.stateStore.update(s=>{const a=[...s.messages].reverse().find(o=>o.role==="tool"&&o.toolName===e.toolName&&o.isStreaming);return a?{...s,messages:s.messages.map(o=>o.id===a.id?{...o,content:o.content.includes(`
2
2
  `)?o.content+e.delta:`${o.content}
3
3
  ${e.delta}`,toolOutput:`${o.toolOutput}${e.delta}`}:o)}:s});break}case"tool_end":{const s=e.result?`${e.result}`:"";this.stateStore.update(a=>{const o=[...a.messages].reverse().find(l=>l.role==="tool"&&l.toolName===e.toolName&&!l.content.startsWith("Tool error:"));if(o){const l=e.isError?"Error: ":"";return{...a,messages:a.messages.map(c=>c.id===o.id?{...c,content:`${l}${c.content}
4
4
  ${s}`,isStreaming:!1,isError:e.isError,toolOutput:s}:c)}}else{const l=e.isError?`Tool error: ${e.toolName}
5
5
  ${s}`:`${e.toolName}
6
6
  ${s}`,c={id:this.generateId(),role:"tool",content:l,timestamp:Date.now(),isStreaming:!1,toolName:e.toolName,toolArgs:"",toolOutput:s,isError:e.isError};return{...a,messages:[...a.messages,c]}}});break}case"aborted":this.stateStore.update(s=>({...s,isStreaming:!1,messages:s.messages.map(a=>a.isStreaming?{...a,isStreaming:!1}: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_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}: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}));break;case"message_history":this.stateStore.update(s=>{const a=this.mapHistory(e.messages,e.sessionId,s.isStreaming),o=typeof e.totalCount=="number"?e.totalCount:a.length,l=typeof e.offset=="number"?e.offset:0;return{...s,messages:a,historyTotalCount:o,historyOffset:l,loadingMoreHistory:!1,loadingSession:!1,resyncing:!1}});break;case"message_history_prepend":this.stateStore.update(s=>{const a=this.mapHistory(e.messages,e.sessionId,!1),o=typeof e.offset=="number"?e.offset:0;return a.length===0?{...s,loadingMoreHistory:!1,historyOffset:o}:{...s,messages:[...a,...s.messages],historyOffset:o,loadingMoreHistory:!1}});break;case"model_changed":this.stateStore.update(s=>({...s,activeModel:e.model}));break}}mapHistory(e,r,s){const a=[],o={};for(const l of e)if(l.role==="tool_call"){const c=l.toolName||"unknown";o[c]||(o[c]=[]),o[c].push(l.content||"")}else if(l.role==="tool_result"){const c=l.toolName||"unknown",_=o[c]&&o[c].length>0?o[c].shift():"";a.push({id:this.generateId(),role:"tool",content:_?`$ ${c} ${_}
7
7
  ${l.content}`:`$ ${c}
8
- ${l.content}`,timestamp:l.timestamp,isStreaming:!1,toolName:c,toolArgs:_,toolOutput:l.content,isError:l.isError,sessionId:r})}else a.push({id:this.generateId(),role:l.role,content:l.content,timestamp:l.timestamp,isStreaming:!1,toolName:l.toolName,sessionId:r});for(const[l,c]of Object.entries(o))for(const _ of c)a.push({id:this.generateId(),role:"tool",content:_?`$ ${l} ${_}`:`$ ${l}`,timestamp:a.length>0?a[a.length-1].timestamp+1:Date.now(),isStreaming:s,toolName:l,toolArgs:_,toolOutput:"",sessionId:r});if(s&&a.length>0){const l=a.length-1,c=a[l];(c.role==="assistant"||c.role==="thinking")&&(a[l]={...c,isStreaming:!0})}return a}loadMoreHistory(){const e=sn(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=sn(this.stateStore);if(!r.sessionId)return!1;if(r.agentPending)return this.stateStore.update(o=>({...o,sessionError:o.sessionError??"Preparing the session agent; please wait a moment, then resend."})),!1;if(!this.getIsConnected())return this.stateStore.update(o=>({...o,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(o=>({...o,sessionError:"Message failed to send (connection dropped). Please resend once reconnected."})),!1;const a={id:this.generateId(),role:"user",content:e,timestamp:Date.now(),isStreaming:!1,sessionId:r.sessionId};return this.stateStore.update(o=>({...o,sessionError:null,messages:[...o.messages,a]})),!0}abort(){const e=sn(this.stateStore);e.sessionId&&this.send({type:"abort",sessionId:e.sessionId})}joinSession(e,r,s){this.stateStore.update(a=>({...a,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 a=sn(this.stateStore);a.activeSessionFile===e&&!a.loadingSession&&!a.resyncing||(a.sessionId&&this.send({type:"session_leave",sessionId:a.sessionId}),this.stateStore.update(o=>({...o,messages:[],session:null,sessionId:null,activeSessionFile:null,activeCwd:null,activeModel:null,readOnly:!1,conflict:null,sessionError: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,a,o){this.stateStore.update(l=>({...l,conflict:null,sessionError:null,creatingSession:!0,loadingSession:!1})),this.send({type:"session_new",cwd:e,model:r,gitInit:s,createRemote:a,repoVisibility:o}),this.armCreateWatchdog()}leaveSession(){const e=sn(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,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=sn(this.stateStore);s.conflict&&(this.send({type:"session_resolve_conflict",action:e,sessionId:s.conflict.targetSessionId,cwd:r||s.conflict.conflictingCwd}),this.stateStore.update(a=>({...a,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}))}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((a,o)=>{const l=this.generateId();this.pendingUploads.set(l,{resolve:a,reject:o}),this.send({type:"file_upload",uploadId:l,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 er=jn({folders:[],activeSessions:[],currentSession:null,loading:!1}),tr=jn({models:[],loading:!1}),fr=jn({folders:[],activeSessions:[],currentSession:null,loading:!1});function Cn(){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 a=r.host||e;return(a==="localhost"||a==="127.0.0.1")&&e&&e!=="localhost"&&e!=="127.0.0.1"&&(a=e),a=a.startsWith("http")?a.replace(/^wss?:\/\//,""):a,`${s}//${a}:${r.port||31415}`}return`${window.location.protocol}//${window.location.host}`}let ar=null,ts=[],ns=!1,rs=!1,Gs=0;const Ho=150,Bo=1e3;async function js(){ns=!0;try{const n=Cn(),e=In(),r=`${n}/sessions${e?`?token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=await s.json();er.set({folders:a.folders||[],activeSessions:(a.activeSessions||[]).map(o=>o.sessionFile),currentSession:nr(er).currentSession,loading:!1})}catch(n){er.update(e=>({...e,loading:!1})),console.error("Failed to fetch sessions:",n)}finally{ns=!1}}function gr(){er.update(r=>({...r,loading:!0}));const n=new Promise(r=>{ts.push(r)});if(ns)return rs=!0,n;const e=Date.now();if(!ar)Gs=e;else if(clearTimeout(ar),e-Gs>=Bo)return ar=null,qs(),n;return ar=setTimeout(()=>{ar=null,qs()},Ho),n}async function qs(){const n=[...ts];ts=[];try{for(await js();rs;)rs=!1,await js()}finally{for(const e of n)e()}}async function _a(){fr.update(n=>({...n,loading:!0}));try{const n=Cn(),e=In(),r=`${n}/sessions?view=readonly${e?`&token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=await s.json();fr.set({folders:a.folders||[],activeSessions:(a.activeSessions||[]).map(o=>o.sessionFile),currentSession:nr(fr).currentSession,loading:!1})}catch(n){fr.update(e=>({...e,loading:!1})),console.error("Failed to fetch read-only sessions:",n)}}async function Wo(){tr.update(n=>({...n,loading:!0}));try{const n=Cn(),e=In(),r=`${n}/models${e?`?token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=await s.json();tr.set({models:a.models||[],loading:!1})}catch(n){tr.update(e=>({...e,loading:!1})),console.error("Failed to fetch models:",n)}}function In(){try{const n=localStorage.getItem("wherever-config");if(n)return JSON.parse(n).token||""}catch{}return""}const xs=jn(!1),ya=jn("websocket"),_s=jn(null),wa=jn(!1);async function ka(n){if(!n.trim())return null;try{const e=Cn(),r=In(),s=`${e}/check-path?path=${encodeURIComponent(n)}${r?`&token=${encodeURIComponent(r)}`:""}`,a=await fetch(s);if(!a.ok)throw new Error(`HTTP ${a.status}`);return await a.json()}catch(e){return console.error("Failed to check path:",e),null}}async function Mr(n){try{const e=Cn(),r=In(),s=`${e}/autocomplete-path?path=${encodeURIComponent(n)}${r?`&token=${encodeURIComponent(r)}`:""}`,a=await fetch(s);if(!a.ok)throw new Error(`HTTP ${a.status}`);return(await a.json()).completions||[]}catch(e){return console.error("Failed to autocomplete path:",e),[]}}async function Go(){try{const n=Cn(),e=In(),r=`${n}/config${e?`?token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=await s.json();xs.set(!!a.gitInitDefault),ya.set(a.uploadMethod||"websocket"),_s.set(a.searchFolder||null),wa.set(!!a.searchCreateRemote)}catch(n){console.error("Failed to fetch config:",n)}}function mr(n){er.update(e=>({...e,currentSession:n}))}function jo(){try{const n=localStorage.getItem("wherever-config");if(n)return JSON.parse(n)}catch{}return null}function ys(n){localStorage.setItem("wherever-config",JSON.stringify(n))}function wr(){const n=typeof window<"u"&&window.location&&window.location.hostname?window.location.hostname:"localhost",e=jo();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,...e}):{host:n,port:31415,token:"",hideThinking:!1,hideTools:!1}}const or=wr(),wt=new Ln({host:or.host,port:or.port,token:or.token,secure:typeof window<"u"&&window.location&&window.location.protocol==="https:",hideThinking:!!or.hideThinking,hideTools:!!or.hideTools}),ws=wt.stateStore;let pr=null;wt.onMessage(n=>{switch(n.type){case"session_created":if(mr(n.sessionFile),pr!==null){const r=pr;pr=null,queueMicrotask(()=>wt.sendMessage(r))}break;case"session_error":pr=null;break;case"session_destroyed":nr(ws).sessionId===n.sessionId&&mr(null);break;case"sessions_updated":gr();break;case"session_interrupted":mr(null);break}});function Hn(){const n=wr();ys(n);const e=typeof window<"u"&&window.location&&window.location.protocol==="https:";wt.connect({host:n.host,port:n.port,token:n.token,secure:e,hideThinking:!!n.hideThinking,hideTools:!!n.hideTools})}function _r(){wt.disconnect(!0),mr(null)}function Sa(){wt.suspend()}function ss(){wt.resume()}function qo(){return wt.hasSuspendedSession()}function as(){return wt.hasActiveSession()}let ks=0;const Vo=300*1e3;function Ta(){ks=Date.now()+Vo}function Ss(){ks=0}function Aa(){return Date.now()<ks}function os(n){return wt.sendMessage(n)}function Ea(){wt.abort()}function Ra(n,e,r){wt.joinSession(n,e,r)}function Ts(n,e,r){wt.switchSession(n,e,r)}function kn(n,e,r,s,a){wt.createSession(n,e,r,s,a)}function Ca(n){const e=n.trim();if(!e)return!1;const r=nr(_s);if(!r)return!1;const s=nr(wa);return pr=e,wt.createSession(r,void 0,s,s,s?"private":void 0),!0}function bn(){wt.leaveSession(),mr(null)}function Ia(){wt.loadMoreHistory()}function is(n,e){wt.resolveConflict(n,e)}function Yo(){wt.ping()}function $a(){wt.clearMessages()}function ls(n){ys(n),wt.setConfig(n)}function cs(n){const r={...wr(),...n};ys(r),wt.setConfig(r)}function Bn(){wt.dismissSessionError()}function Ma(n){wt.changeModel(n)}const $t=Bt(ws,n=>n),kr=Bt($t,n=>n.connected),As=Bt($t,n=>n.isStreaming),La=Bt($t,n=>n.messages),Zo=Bt($t,n=>n.error),Ko=Bt($t,n=>n.session),Oa=Bt($t,n=>n.conflict),Da=Bt($t,n=>n.isInterrupted),Es=Bt($t,n=>n.sessionError),Rs=Bt($t,n=>n.readOnly),Sr=Bt($t,n=>({sessionFile:n.activeSessionFile,cwd:n.activeCwd,model:n.activeModel,sessionId:n.sessionId})),Xo=Bt($t,n=>n.contextUsage),Pa=Bt($t,n=>n.creatingSession),Nr=Bt($t,n=>n.loadingSession),Cs=Bt($t,n=>n.resyncing),Na=Bt($t,n=>n.agentPending),Fa=Bt($t,n=>n.historyOffset>0),Ua=Bt($t,n=>n.loadingMoreHistory);async function Qo(n,e){const r=Cn(),s=In(),a=`${r}/session/upload?sessionId=${encodeURIComponent(n)}&filename=${encodeURIComponent(e.name)}${s?`&token=${encodeURIComponent(s)}`:""}`,o=await e.arrayBuffer(),l=await fetch(a,{method:"POST",headers:{"Content-Type":"text/plain"},body:o});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||`Upload failed with status ${l.status}`)}return await l.json()}function Jo(n,e){return new Promise((r,s)=>{try{const a=new FileReader;a.onload=()=>{try{const l=a.result.split(",")[1]||"";wt.uploadFileViaWebSocket(n,e.name,l).then(r).catch(s)}catch(o){s(new Error(`Failed to process file data: ${o.message}`))}},a.onerror=()=>{s(new Error("Failed to read file contents"))},a.readAsDataURL(e)}catch(a){s(a)}})}async function za(n,e){return nr(ya)==="post"?Qo(n,e):Jo(n,e)}async function ds(n){try{const e=Cn(),r=In(),s=`${e}/session/delete${r?`?token=${encodeURIComponent(r)}`:""}`,a=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionFile:n})});if(!a.ok){const o=await a.json().catch(()=>({}));throw new Error(o.error||`Delete failed with status ${a.status}`)}}catch(e){throw console.error("Failed to delete session:",e),e}}const ei=Object.freeze(Object.defineProperty({__proto__:null,abort:Ea,activeSessionInfo:Sr,beginFilePicker:Ta,changeModel:Ma,clearMessages:$a,client:wt,conflict:Oa,connect:Hn,connectionError:Zo,contextUsage:Xo,createSession:kn,currentSession:Ko,deleteSession:ds,disconnect:_r,dismissSessionError:Bn,endFilePicker:Ss,getConfig:wr,hasActiveSession:as,hasMoreHistory:Fa,hasSuspendedSession:qo,isAgentPending:Na,isConnected:kr,isCreatingSession:Pa,isFilePickerActive:Aa,isInterrupted:Da,isLoadingMoreHistory:Ua,isLoadingSession:Nr,isReadOnly:Rs,isResyncing:Cs,isStreaming:As,joinSession:Ra,leaveSession:bn,loadMoreHistory:Ia,messages:La,piState:$t,ping:Yo,resolveConflict:is,resume:ss,runSearch:Ca,sendMessage:os,sessionError:Es,setConfig:ls,state:ws,suspend:Sa,switchSession:Ts,updateConfig:cs,uploadFile:za},Symbol.toStringTag,{value:"Module"}));var ti=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>'),ni=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>'),ri=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-hide-tools" 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-tools" class="cursor-pointer text-xs text-brand-text select-none">Hide tool calls</label></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 si(n,e){Fn(e,!0);const r=()=>qe(kr,"$isConnected",s),[s,a]=rr();let o=V(""),l=V(0),c=V(""),_=V(!1),v=V(!1),I=!1,N=se(r);yr(()=>{const Se=wr();p(o,Se.host,!0),p(l,Se.port,!0),p(c,Se.token||"",!0),p(_,!!Se.hideThinking),p(v,!!Se.hideTools)});function $(){ls({host:t(o),port:t(l),token:t(c),hideThinking:t(_),hideTools:t(v)})}function L(){ls({host:t(o),port:t(l),token:t(c),hideThinking:t(_),hideTools:t(v)}),_r(),setTimeout(()=>Hn(),100)}function S(){_r()}function ge(){window.location.reload()}var ye=ri(),fe=u(ye),oe=u(fe),Ie=f(u(oe),2);at(Ie),d(oe);var Re=f(oe,2),Ne=f(u(Re),2);at(Ne),d(Re);var he=f(Re,2),$e=f(u(he),2);at($e),d(he);var ot=f(he,2),me=u(ot);at(me),it(2),d(ot);var Ue=f(ot,2),Me=u(Ue);at(Me),it(2),d(Ue);var Fe=f(Ue,2),dt=u(Fe);{var ft=Se=>{var Te=ti();W("click",Te,S),h(Se,Te)},pt=Se=>{var Te=ni();Te.disabled=I,Te.textContent="Connect",W("click",Te,L),h(Se,Te)};C(dt,Se=>{t(N)?Se(ft):Se(pt,-1)})}d(Fe);var be=f(Fe,2);d(fe),d(ye),Rn(Ie,()=>t(o),Se=>p(o,Se)),Rn(Ne,()=>t(l),Se=>p(l,Se)),Rn($e,()=>t(c),Se=>p(c,Se)),W("change",me,$),vn(me,()=>t(_),Se=>p(_,Se)),W("change",Me,$),vn(Me,()=>t(v),Se=>p(v,Se)),W("click",be,ge),h(n,ye),Un(),a()}Gn(["change","click"]);function Is(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var qn=Is();function Ha(n){qn=n}var xr={exec:()=>null};function ct(n,e=""){let r=typeof n=="string"?n:n.source;const s={replace:(a,o)=>{let l=typeof o=="string"?o:o.source;return l=l.replace(tn.caret,"$1"),r=r.replace(a,l),s},getRegex:()=>new RegExp(r,e)};return s}var tn={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")},ai=/^(?:[ \t]*(?:\n|$))+/,oi=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ii=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Tr=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,li=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,$s=/(?:[*+-]|\d{1,9}[.)])/,Ba=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Wa=ct(Ba).replace(/bull/g,$s).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(),ci=ct(Ba).replace(/bull/g,$s).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(),Ms=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,di=/^[^\n]+/,Ls=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ui=ct(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Ls).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),fi=ct(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,$s).getRegex(),Fr="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",Os=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,pi=ct("^ {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",Os).replace("tag",Fr).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ga=ct(Ms).replace("hr",Tr).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",Fr).getRegex(),hi=ct(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ga).getRegex(),Ds={blockquote:hi,code:oi,def:ui,fences:ii,heading:li,hr:Tr,html:pi,lheading:Wa,list:fi,newline:ai,paragraph:Ga,table:xr,text:di},Vs=ct("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Tr).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",Fr).getRegex(),bi={...Ds,lheading:ci,table:Vs,paragraph:ct(Ms).replace("hr",Tr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Vs).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",Fr).getRegex()},vi={...Ds,html:ct(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Os).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:xr,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ct(Ms).replace("hr",Tr).replace("heading",` *#{1,6} *[^
9
- ]`).replace("lheading",Wa).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},gi=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,mi=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ja=/^( {2,}|\\)\n(?!\s*$)/,xi=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Ur=/[\p{P}\p{S}]/u,Ps=/[\s\p{P}\p{S}]/u,qa=/[^\s\p{P}\p{S}]/u,_i=ct(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Ps).getRegex(),Va=/(?!~)[\p{P}\p{S}]/u,yi=/(?!~)[\s\p{P}\p{S}]/u,wi=/(?:[^\s\p{P}\p{S}]|~)/u,ki=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,Ya=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Si=ct(Ya,"u").replace(/punct/g,Ur).getRegex(),Ti=ct(Ya,"u").replace(/punct/g,Va).getRegex(),Za="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Ai=ct(Za,"gu").replace(/notPunctSpace/g,qa).replace(/punctSpace/g,Ps).replace(/punct/g,Ur).getRegex(),Ei=ct(Za,"gu").replace(/notPunctSpace/g,wi).replace(/punctSpace/g,yi).replace(/punct/g,Va).getRegex(),Ri=ct("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,qa).replace(/punctSpace/g,Ps).replace(/punct/g,Ur).getRegex(),Ci=ct(/\\(punct)/,"gu").replace(/punct/g,Ur).getRegex(),Ii=ct(/^<(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(),$i=ct(Os).replace("(?:-->|$)","-->").getRegex(),Mi=ct("^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",$i).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Lr=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Li=ct(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",Lr).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ka=ct(/^!?\[(label)\]\[(ref)\]/).replace("label",Lr).replace("ref",Ls).getRegex(),Xa=ct(/^!?\[(ref)\](?:\[\])?/).replace("ref",Ls).getRegex(),Oi=ct("reflink|nolink(?!\\()","g").replace("reflink",Ka).replace("nolink",Xa).getRegex(),Ns={_backpedal:xr,anyPunctuation:Ci,autolink:Ii,blockSkip:ki,br:ja,code:mi,del:xr,emStrongLDelim:Si,emStrongRDelimAst:Ai,emStrongRDelimUnd:Ri,escape:gi,link:Li,nolink:Xa,punctuation:_i,reflink:Ka,reflinkSearch:Oi,tag:Mi,text:xi,url:xr},Di={...Ns,link:ct(/^!?\[(label)\]\((.*?)\)/).replace("label",Lr).getRegex(),reflink:ct(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Lr).getRegex()},us={...Ns,emStrongRDelimAst:Ei,emStrongLDelim:Ti,url:ct(/^((?: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.!#$%&'*+\/=?_`{\|}~-]+@)))/},Pi={...us,br:ct(ja).replace("{2,}","*").getRegex(),text:ct(us.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Ar={normal:Ds,gfm:bi,pedantic:vi},ir={normal:Ns,gfm:us,breaks:Pi,pedantic:Di},Ni={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Ys=n=>Ni[n];function _n(n,e){if(e){if(tn.escapeTest.test(n))return n.replace(tn.escapeReplace,Ys)}else if(tn.escapeTestNoEncode.test(n))return n.replace(tn.escapeReplaceNoEncode,Ys);return n}function Zs(n){try{n=encodeURI(n).replace(tn.percentDecode,"%")}catch{return null}return n}function Ks(n,e){const r=n.replace(tn.findPipe,(o,l,c)=>{let _=!1,v=l;for(;--v>=0&&c[v]==="\\";)_=!_;return _?"|":" |"}),s=r.split(tn.splitPipe);let a=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(;a<s.length;a++)s[a]=s[a].trim().replace(tn.slashPipe,"|");return s}function lr(n,e,r){const s=n.length;if(s===0)return"";let a=0;for(;a<s&&n.charAt(s-a-1)===e;)a++;return n.slice(0,s-a)}function Fi(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 Xs(n,e,r,s,a){const o=e.href,l=e.title||null,c=n[1].replace(a.other.outputLinkReplace,"$1");s.state.inLink=!0;const _={type:n[0].charAt(0)==="!"?"image":"link",raw:r,href:o,title:l,text:c,tokens:s.inlineTokens(c)};return s.state.inLink=!1,_}function Ui(n,e,r){const s=n.match(r.other.indentCodeCompensation);if(s===null)return e;const a=s[1];return e.split(`
8
+ ${l.content}`,timestamp:l.timestamp,isStreaming:!1,toolName:c,toolArgs:_,toolOutput:l.content,isError:l.isError,sessionId:r})}else a.push({id:this.generateId(),role:l.role,content:l.content,timestamp:l.timestamp,isStreaming:!1,toolName:l.toolName,sessionId:r});for(const[l,c]of Object.entries(o))for(const _ of c)a.push({id:this.generateId(),role:"tool",content:_?`$ ${l} ${_}`:`$ ${l}`,timestamp:a.length>0?a[a.length-1].timestamp+1:Date.now(),isStreaming:s,toolName:l,toolArgs:_,toolOutput:"",sessionId:r});if(s&&a.length>0){const l=a.length-1,c=a[l];(c.role==="assistant"||c.role==="thinking")&&(a[l]={...c,isStreaming:!0})}return a}loadMoreHistory(){const e=sn(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=sn(this.stateStore);if(!r.sessionId)return!1;if(r.agentPending)return this.stateStore.update(o=>({...o,sessionError:o.sessionError??"Preparing the session agent; please wait a moment, then resend."})),!1;if(!this.getIsConnected())return this.stateStore.update(o=>({...o,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(o=>({...o,sessionError:"Message failed to send (connection dropped). Please resend once reconnected."})),!1;const a={id:this.generateId(),role:"user",content:e,timestamp:Date.now(),isStreaming:!1,sessionId:r.sessionId};return this.stateStore.update(o=>({...o,sessionError:null,messages:[...o.messages,a]})),!0}abort(){const e=sn(this.stateStore);e.sessionId&&this.send({type:"abort",sessionId:e.sessionId})}joinSession(e,r,s){this.stateStore.update(a=>({...a,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 a=sn(this.stateStore);a.activeSessionFile===e&&!a.loadingSession&&!a.resyncing||(a.sessionId&&this.send({type:"session_leave",sessionId:a.sessionId}),this.stateStore.update(o=>({...o,messages:[],session:null,sessionId:null,activeSessionFile:null,activeCwd:null,activeModel:null,readOnly:!1,conflict:null,sessionError: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,a,o){this.stateStore.update(l=>({...l,conflict:null,sessionError:null,creatingSession:!0,loadingSession:!1})),this.send({type:"session_new",cwd:e,model:r,gitInit:s,createRemote:a,repoVisibility:o}),this.armCreateWatchdog()}leaveSession(){const e=sn(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,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=sn(this.stateStore);s.conflict&&(this.send({type:"session_resolve_conflict",action:e,sessionId:s.conflict.targetSessionId,cwd:r||s.conflict.conflictingCwd}),this.stateStore.update(a=>({...a,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}))}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((a,o)=>{const l=this.generateId();this.pendingUploads.set(l,{resolve:a,reject:o}),this.send({type:"file_upload",uploadId:l,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 er=jn({folders:[],activeSessions:[],currentSession:null,loading:!1}),tr=jn({models:[],loading:!1}),fr=jn({folders:[],activeSessions:[],currentSession:null,loading:!1});function Cn(){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 a=r.host||e;return(a==="localhost"||a==="127.0.0.1")&&e&&e!=="localhost"&&e!=="127.0.0.1"&&(a=e),a=a.startsWith("http")?a.replace(/^wss?:\/\//,""):a,`${s}//${a}:${r.port||31415}`}return`${window.location.protocol}//${window.location.host}`}let ar=null,ts=[],ns=!1,rs=!1,Gs=0;const Ho=150,Bo=1e3;async function js(){ns=!0;try{const n=Cn(),e=In(),r=`${n}/sessions${e?`?token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=await s.json();er.set({folders:a.folders||[],activeSessions:(a.activeSessions||[]).map(o=>o.sessionFile),currentSession:nr(er).currentSession,loading:!1})}catch(n){er.update(e=>({...e,loading:!1})),console.error("Failed to fetch sessions:",n)}finally{ns=!1}}function vr(){er.update(r=>({...r,loading:!0}));const n=new Promise(r=>{ts.push(r)});if(ns)return rs=!0,n;const e=Date.now();if(!ar)Gs=e;else if(clearTimeout(ar),e-Gs>=Bo)return ar=null,qs(),n;return ar=setTimeout(()=>{ar=null,qs()},Ho),n}async function qs(){const n=[...ts];ts=[];try{for(await js();rs;)rs=!1,await js()}finally{for(const e of n)e()}}async function _a(){fr.update(n=>({...n,loading:!0}));try{const n=Cn(),e=In(),r=`${n}/sessions?view=readonly${e?`&token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=await s.json();fr.set({folders:a.folders||[],activeSessions:(a.activeSessions||[]).map(o=>o.sessionFile),currentSession:nr(fr).currentSession,loading:!1})}catch(n){fr.update(e=>({...e,loading:!1})),console.error("Failed to fetch read-only sessions:",n)}}async function Wo(){tr.update(n=>({...n,loading:!0}));try{const n=Cn(),e=In(),r=`${n}/models${e?`?token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=await s.json();tr.set({models:a.models||[],loading:!1})}catch(n){tr.update(e=>({...e,loading:!1})),console.error("Failed to fetch models:",n)}}function In(){try{const n=localStorage.getItem("wherever-config");if(n)return JSON.parse(n).token||""}catch{}return""}const xs=jn(!1),ya=jn("websocket"),_s=jn(null),wa=jn(!1);async function ka(n){if(!n.trim())return null;try{const e=Cn(),r=In(),s=`${e}/check-path?path=${encodeURIComponent(n)}${r?`&token=${encodeURIComponent(r)}`:""}`,a=await fetch(s);if(!a.ok)throw new Error(`HTTP ${a.status}`);return await a.json()}catch(e){return console.error("Failed to check path:",e),null}}async function Mr(n){try{const e=Cn(),r=In(),s=`${e}/autocomplete-path?path=${encodeURIComponent(n)}${r?`&token=${encodeURIComponent(r)}`:""}`,a=await fetch(s);if(!a.ok)throw new Error(`HTTP ${a.status}`);return(await a.json()).completions||[]}catch(e){return console.error("Failed to autocomplete path:",e),[]}}async function Go(){try{const n=Cn(),e=In(),r=`${n}/config${e?`?token=${encodeURIComponent(e)}`:""}`,s=await fetch(r);if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=await s.json();xs.set(!!a.gitInitDefault),ya.set(a.uploadMethod||"websocket"),_s.set(a.searchFolder||null),wa.set(!!a.searchCreateRemote)}catch(n){console.error("Failed to fetch config:",n)}}function mr(n){er.update(e=>({...e,currentSession:n}))}function jo(){try{const n=localStorage.getItem("wherever-config");if(n)return JSON.parse(n)}catch{}return null}function ys(n){localStorage.setItem("wherever-config",JSON.stringify(n))}function wr(){const n=typeof window<"u"&&window.location&&window.location.hostname?window.location.hostname:"localhost",e=jo();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,...e}):{host:n,port:31415,token:"",hideThinking:!1,hideTools:!1}}const or=wr(),wt=new Ln({host:or.host,port:or.port,token:or.token,secure:typeof window<"u"&&window.location&&window.location.protocol==="https:",hideThinking:!!or.hideThinking,hideTools:!!or.hideTools}),ws=wt.stateStore;let pr=null;wt.onMessage(n=>{switch(n.type){case"session_created":if(mr(n.sessionFile),pr!==null){const r=pr;pr=null,queueMicrotask(()=>wt.sendMessage(r))}break;case"session_error":pr=null;break;case"session_destroyed":nr(ws).sessionId===n.sessionId&&mr(null);break;case"sessions_updated":vr();break;case"session_interrupted":mr(null);break}});function Hn(){const n=wr();ys(n);const e=typeof window<"u"&&window.location&&window.location.protocol==="https:";wt.connect({host:n.host,port:n.port,token:n.token,secure:e,hideThinking:!!n.hideThinking,hideTools:!!n.hideTools})}function _r(){wt.disconnect(!0),mr(null)}function Sa(){wt.suspend()}function ss(){wt.resume()}function qo(){return wt.hasSuspendedSession()}function as(){return wt.hasActiveSession()}let ks=0;const Vo=300*1e3;function Ta(){ks=Date.now()+Vo}function Ss(){ks=0}function Aa(){return Date.now()<ks}function os(n){return wt.sendMessage(n)}function Ea(){wt.abort()}function Ra(n,e,r){wt.joinSession(n,e,r)}function Ts(n,e,r){wt.switchSession(n,e,r)}function kn(n,e,r,s,a){wt.createSession(n,e,r,s,a)}function Ca(n){const e=n.trim();if(!e)return!1;const r=nr(_s);if(!r)return!1;const s=nr(wa);return pr=e,wt.createSession(r,void 0,s,s,s?"private":void 0),!0}function bn(){wt.leaveSession(),mr(null)}function Ia(){wt.loadMoreHistory()}function is(n,e){wt.resolveConflict(n,e)}function Yo(){wt.ping()}function $a(){wt.clearMessages()}function ls(n){ys(n),wt.setConfig(n)}function cs(n){const r={...wr(),...n};ys(r),wt.setConfig(r)}function Bn(){wt.dismissSessionError()}function Ma(n){wt.changeModel(n)}const $t=Bt(ws,n=>n),kr=Bt($t,n=>n.connected),As=Bt($t,n=>n.isStreaming),La=Bt($t,n=>n.messages),Zo=Bt($t,n=>n.error),Ko=Bt($t,n=>n.session),Oa=Bt($t,n=>n.conflict),Da=Bt($t,n=>n.isInterrupted),Es=Bt($t,n=>n.sessionError),Rs=Bt($t,n=>n.readOnly),Sr=Bt($t,n=>({sessionFile:n.activeSessionFile,cwd:n.activeCwd,model:n.activeModel,sessionId:n.sessionId})),Xo=Bt($t,n=>n.contextUsage),Pa=Bt($t,n=>n.creatingSession),Nr=Bt($t,n=>n.loadingSession),Cs=Bt($t,n=>n.resyncing),Na=Bt($t,n=>n.agentPending),Fa=Bt($t,n=>n.historyOffset>0),Ua=Bt($t,n=>n.loadingMoreHistory);async function Qo(n,e){const r=Cn(),s=In(),a=`${r}/session/upload?sessionId=${encodeURIComponent(n)}&filename=${encodeURIComponent(e.name)}${s?`&token=${encodeURIComponent(s)}`:""}`,o=await e.arrayBuffer(),l=await fetch(a,{method:"POST",headers:{"Content-Type":"text/plain"},body:o});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||`Upload failed with status ${l.status}`)}return await l.json()}function Jo(n,e){return new Promise((r,s)=>{try{const a=new FileReader;a.onload=()=>{try{const l=a.result.split(",")[1]||"";wt.uploadFileViaWebSocket(n,e.name,l).then(r).catch(s)}catch(o){s(new Error(`Failed to process file data: ${o.message}`))}},a.onerror=()=>{s(new Error("Failed to read file contents"))},a.readAsDataURL(e)}catch(a){s(a)}})}async function za(n,e){return nr(ya)==="post"?Qo(n,e):Jo(n,e)}async function ds(n){try{const e=Cn(),r=In(),s=`${e}/session/delete${r?`?token=${encodeURIComponent(r)}`:""}`,a=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionFile:n})});if(!a.ok){const o=await a.json().catch(()=>({}));throw new Error(o.error||`Delete failed with status ${a.status}`)}}catch(e){throw console.error("Failed to delete session:",e),e}}const ei=Object.freeze(Object.defineProperty({__proto__:null,abort:Ea,activeSessionInfo:Sr,beginFilePicker:Ta,changeModel:Ma,clearMessages:$a,client:wt,conflict:Oa,connect:Hn,connectionError:Zo,contextUsage:Xo,createSession:kn,currentSession:Ko,deleteSession:ds,disconnect:_r,dismissSessionError:Bn,endFilePicker:Ss,getConfig:wr,hasActiveSession:as,hasMoreHistory:Fa,hasSuspendedSession:qo,isAgentPending:Na,isConnected:kr,isCreatingSession:Pa,isFilePickerActive:Aa,isInterrupted:Da,isLoadingMoreHistory:Ua,isLoadingSession:Nr,isReadOnly:Rs,isResyncing:Cs,isStreaming:As,joinSession:Ra,leaveSession:bn,loadMoreHistory:Ia,messages:La,piState:$t,ping:Yo,resolveConflict:is,resume:ss,runSearch:Ca,sendMessage:os,sessionError:Es,setConfig:ls,state:ws,suspend:Sa,switchSession:Ts,updateConfig:cs,uploadFile:za},Symbol.toStringTag,{value:"Module"}));var ti=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>'),ni=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>'),ri=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-hide-tools" 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-tools" class="cursor-pointer text-xs text-brand-text select-none">Hide tool calls</label></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 si(n,e){Fn(e,!0);const r=()=>qe(kr,"$isConnected",s),[s,a]=rr();let o=V(""),l=V(0),c=V(""),_=V(!1),g=V(!1),I=!1,N=se(r);yr(()=>{const Se=wr();p(o,Se.host,!0),p(l,Se.port,!0),p(c,Se.token||"",!0),p(_,!!Se.hideThinking),p(g,!!Se.hideTools)});function $(){ls({host:t(o),port:t(l),token:t(c),hideThinking:t(_),hideTools:t(g)})}function L(){ls({host:t(o),port:t(l),token:t(c),hideThinking:t(_),hideTools:t(g)}),_r(),setTimeout(()=>Hn(),100)}function S(){_r()}function ve(){window.location.reload()}var ye=ri(),fe=u(ye),oe=u(fe),Ie=f(u(oe),2);at(Ie),d(oe);var Re=f(oe,2),Fe=f(u(Re),2);at(Fe),d(Re);var he=f(Re,2),$e=f(u(he),2);at($e),d(he);var ot=f(he,2),me=u(ot);at(me),it(2),d(ot);var Ue=f(ot,2),Me=u(Ue);at(Me),it(2),d(Ue);var Le=f(Ue,2),dt=u(Le);{var ft=Se=>{var Te=ti();W("click",Te,S),h(Se,Te)},pt=Se=>{var Te=ni();Te.disabled=I,Te.textContent="Connect",W("click",Te,L),h(Se,Te)};C(dt,Se=>{t(N)?Se(ft):Se(pt,-1)})}d(Le);var be=f(Le,2);d(fe),d(ye),Rn(Ie,()=>t(o),Se=>p(o,Se)),Rn(Fe,()=>t(l),Se=>p(l,Se)),Rn($e,()=>t(c),Se=>p(c,Se)),W("change",me,$),gn(me,()=>t(_),Se=>p(_,Se)),W("change",Me,$),gn(Me,()=>t(g),Se=>p(g,Se)),W("click",be,ve),h(n,ye),Un(),a()}Gn(["change","click"]);function Is(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var qn=Is();function Ha(n){qn=n}var xr={exec:()=>null};function ct(n,e=""){let r=typeof n=="string"?n:n.source;const s={replace:(a,o)=>{let l=typeof o=="string"?o:o.source;return l=l.replace(tn.caret,"$1"),r=r.replace(a,l),s},getRegex:()=>new RegExp(r,e)};return s}var tn={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")},ai=/^(?:[ \t]*(?:\n|$))+/,oi=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ii=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Tr=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,li=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,$s=/(?:[*+-]|\d{1,9}[.)])/,Ba=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Wa=ct(Ba).replace(/bull/g,$s).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(),ci=ct(Ba).replace(/bull/g,$s).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(),Ms=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,di=/^[^\n]+/,Ls=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ui=ct(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Ls).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),fi=ct(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,$s).getRegex(),Fr="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",Os=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,pi=ct("^ {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",Os).replace("tag",Fr).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ga=ct(Ms).replace("hr",Tr).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",Fr).getRegex(),hi=ct(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ga).getRegex(),Ds={blockquote:hi,code:oi,def:ui,fences:ii,heading:li,hr:Tr,html:pi,lheading:Wa,list:fi,newline:ai,paragraph:Ga,table:xr,text:di},Vs=ct("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Tr).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",Fr).getRegex(),bi={...Ds,lheading:ci,table:Vs,paragraph:ct(Ms).replace("hr",Tr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Vs).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",Fr).getRegex()},gi={...Ds,html:ct(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Os).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:xr,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ct(Ms).replace("hr",Tr).replace("heading",` *#{1,6} *[^
9
+ ]`).replace("lheading",Wa).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},vi=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,mi=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ja=/^( {2,}|\\)\n(?!\s*$)/,xi=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Ur=/[\p{P}\p{S}]/u,Ps=/[\s\p{P}\p{S}]/u,qa=/[^\s\p{P}\p{S}]/u,_i=ct(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Ps).getRegex(),Va=/(?!~)[\p{P}\p{S}]/u,yi=/(?!~)[\s\p{P}\p{S}]/u,wi=/(?:[^\s\p{P}\p{S}]|~)/u,ki=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,Ya=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Si=ct(Ya,"u").replace(/punct/g,Ur).getRegex(),Ti=ct(Ya,"u").replace(/punct/g,Va).getRegex(),Za="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Ai=ct(Za,"gu").replace(/notPunctSpace/g,qa).replace(/punctSpace/g,Ps).replace(/punct/g,Ur).getRegex(),Ei=ct(Za,"gu").replace(/notPunctSpace/g,wi).replace(/punctSpace/g,yi).replace(/punct/g,Va).getRegex(),Ri=ct("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,qa).replace(/punctSpace/g,Ps).replace(/punct/g,Ur).getRegex(),Ci=ct(/\\(punct)/,"gu").replace(/punct/g,Ur).getRegex(),Ii=ct(/^<(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(),$i=ct(Os).replace("(?:-->|$)","-->").getRegex(),Mi=ct("^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",$i).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Lr=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Li=ct(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",Lr).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ka=ct(/^!?\[(label)\]\[(ref)\]/).replace("label",Lr).replace("ref",Ls).getRegex(),Xa=ct(/^!?\[(ref)\](?:\[\])?/).replace("ref",Ls).getRegex(),Oi=ct("reflink|nolink(?!\\()","g").replace("reflink",Ka).replace("nolink",Xa).getRegex(),Ns={_backpedal:xr,anyPunctuation:Ci,autolink:Ii,blockSkip:ki,br:ja,code:mi,del:xr,emStrongLDelim:Si,emStrongRDelimAst:Ai,emStrongRDelimUnd:Ri,escape:vi,link:Li,nolink:Xa,punctuation:_i,reflink:Ka,reflinkSearch:Oi,tag:Mi,text:xi,url:xr},Di={...Ns,link:ct(/^!?\[(label)\]\((.*?)\)/).replace("label",Lr).getRegex(),reflink:ct(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Lr).getRegex()},us={...Ns,emStrongRDelimAst:Ei,emStrongLDelim:Ti,url:ct(/^((?: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.!#$%&'*+\/=?_`{\|}~-]+@)))/},Pi={...us,br:ct(ja).replace("{2,}","*").getRegex(),text:ct(us.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Ar={normal:Ds,gfm:bi,pedantic:gi},ir={normal:Ns,gfm:us,breaks:Pi,pedantic:Di},Ni={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Ys=n=>Ni[n];function _n(n,e){if(e){if(tn.escapeTest.test(n))return n.replace(tn.escapeReplace,Ys)}else if(tn.escapeTestNoEncode.test(n))return n.replace(tn.escapeReplaceNoEncode,Ys);return n}function Zs(n){try{n=encodeURI(n).replace(tn.percentDecode,"%")}catch{return null}return n}function Ks(n,e){const r=n.replace(tn.findPipe,(o,l,c)=>{let _=!1,g=l;for(;--g>=0&&c[g]==="\\";)_=!_;return _?"|":" |"}),s=r.split(tn.splitPipe);let a=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(;a<s.length;a++)s[a]=s[a].trim().replace(tn.slashPipe,"|");return s}function lr(n,e,r){const s=n.length;if(s===0)return"";let a=0;for(;a<s&&n.charAt(s-a-1)===e;)a++;return n.slice(0,s-a)}function Fi(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 Xs(n,e,r,s,a){const o=e.href,l=e.title||null,c=n[1].replace(a.other.outputLinkReplace,"$1");s.state.inLink=!0;const _={type:n[0].charAt(0)==="!"?"image":"link",raw:r,href:o,title:l,text:c,tokens:s.inlineTokens(c)};return s.state.inLink=!1,_}function Ui(n,e,r){const s=n.match(r.other.indentCodeCompensation);if(s===null)return e;const a=s[1];return e.split(`
10
10
  `).map(o=>{const l=o.match(r.other.beginningSpace);if(l===null)return o;const[c]=l;return c.length>=a.length?o.slice(a.length):o}).join(`
11
11
  `)}var Or=class{options;rules;lexer;constructor(n){this.options=n||qn}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:lr(r,`
12
12
  `)}}}fences(n){const e=this.rules.block.fences.exec(n);if(e){const r=e[0],s=Ui(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=lr(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:lr(e[0],`
13
13
  `)}}blockquote(n){const e=this.rules.block.blockquote.exec(n);if(e){let r=lr(e[0],`
14
14
  `).split(`
15
- `),s="",a="";const o=[];for(;r.length>0;){let l=!1;const c=[];let _;for(_=0;_<r.length;_++)if(this.rules.other.blockquoteStart.test(r[_]))c.push(r[_]),l=!0;else if(!l)c.push(r[_]);else break;r=r.slice(_);const v=c.join(`
16
- `),I=v.replace(this.rules.other.blockquoteSetextReplace,`
15
+ `),s="",a="";const o=[];for(;r.length>0;){let l=!1;const c=[];let _;for(_=0;_<r.length;_++)if(this.rules.other.blockquoteStart.test(r[_]))c.push(r[_]),l=!0;else if(!l)c.push(r[_]);else break;r=r.slice(_);const g=c.join(`
16
+ `),I=g.replace(this.rules.other.blockquoteSetextReplace,`
17
17
  $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
18
- ${v}`:v,a=a?`${a}
18
+ ${g}`:g,a=a?`${a}
19
19
  ${I}`:I;const N=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(I,o,!0),this.lexer.state.top=N,r.length===0)break;const $=o.at(-1);if($?.type==="code")break;if($?.type==="blockquote"){const L=$,S=L.raw+`
20
20
  `+r.join(`
21
- `),ge=this.blockquote(S);o[o.length-1]=ge,s=s.substring(0,s.length-L.raw.length)+ge.raw,a=a.substring(0,a.length-L.text.length)+ge.text;break}else if($?.type==="list"){const L=$,S=L.raw+`
21
+ `),ve=this.blockquote(S);o[o.length-1]=ve,s=s.substring(0,s.length-L.raw.length)+ve.raw,a=a.substring(0,a.length-L.text.length)+ve.text;break}else if($?.type==="list"){const L=$,S=L.raw+`
22
22
  `+r.join(`
23
- `),ge=this.list(S);o[o.length-1]=ge,s=s.substring(0,s.length-$.raw.length)+ge.raw,a=a.substring(0,a.length-L.raw.length)+ge.raw,r=S.substring(o.at(-1).raw.length).split(`
24
- `);continue}}return{type:"blockquote",raw:s,tokens:o,text:a}}}list(n){let e=this.rules.block.list.exec(n);if(e){let r=e[1].trim();const s=r.length>1,a={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 o=this.rules.other.listItemRegex(r);let l=!1;for(;n;){let _=!1,v="",I="";if(!(e=o.exec(n))||this.rules.block.hr.test(n))break;v=e[0],n=n.substring(v.length);let N=e[2].split(`
23
+ `),ve=this.list(S);o[o.length-1]=ve,s=s.substring(0,s.length-$.raw.length)+ve.raw,a=a.substring(0,a.length-L.raw.length)+ve.raw,r=S.substring(o.at(-1).raw.length).split(`
24
+ `);continue}}return{type:"blockquote",raw:s,tokens:o,text:a}}}list(n){let e=this.rules.block.list.exec(n);if(e){let r=e[1].trim();const s=r.length>1,a={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 o=this.rules.other.listItemRegex(r);let l=!1;for(;n;){let _=!1,g="",I="";if(!(e=o.exec(n))||this.rules.block.hr.test(n))break;g=e[0],n=n.substring(g.length);let N=e[2].split(`
25
25
  `,1)[0].replace(this.rules.other.listReplaceTabs,fe=>" ".repeat(3*fe.length)),$=n.split(`
26
- `,1)[0],L=!N.trim(),S=0;if(this.options.pedantic?(S=2,I=N.trimStart()):L?S=e[1].length+1:(S=e[2].search(this.rules.other.nonSpaceChar),S=S>4?1:S,I=N.slice(S),S+=e[1].length),L&&this.rules.other.blankLine.test($)&&(v+=$+`
27
- `,n=n.substring($.length+1),_=!0),!_){const fe=this.rules.other.nextBulletRegex(S),oe=this.rules.other.hrRegex(S),Ie=this.rules.other.fencesBeginRegex(S),Re=this.rules.other.headingBeginRegex(S),Ne=this.rules.other.htmlBeginRegex(S);for(;n;){const he=n.split(`
28
- `,1)[0];let $e;if($=he,this.options.pedantic?($=$.replace(this.rules.other.listReplaceNesting," "),$e=$):$e=$.replace(this.rules.other.tabCharGlobal," "),Ie.test($)||Re.test($)||Ne.test($)||fe.test($)||oe.test($))break;if($e.search(this.rules.other.nonSpaceChar)>=S||!$.trim())I+=`
26
+ `,1)[0],L=!N.trim(),S=0;if(this.options.pedantic?(S=2,I=N.trimStart()):L?S=e[1].length+1:(S=e[2].search(this.rules.other.nonSpaceChar),S=S>4?1:S,I=N.slice(S),S+=e[1].length),L&&this.rules.other.blankLine.test($)&&(g+=$+`
27
+ `,n=n.substring($.length+1),_=!0),!_){const fe=this.rules.other.nextBulletRegex(S),oe=this.rules.other.hrRegex(S),Ie=this.rules.other.fencesBeginRegex(S),Re=this.rules.other.headingBeginRegex(S),Fe=this.rules.other.htmlBeginRegex(S);for(;n;){const he=n.split(`
28
+ `,1)[0];let $e;if($=he,this.options.pedantic?($=$.replace(this.rules.other.listReplaceNesting," "),$e=$):$e=$.replace(this.rules.other.tabCharGlobal," "),Ie.test($)||Re.test($)||Fe.test($)||fe.test($)||oe.test($))break;if($e.search(this.rules.other.nonSpaceChar)>=S||!$.trim())I+=`
29
29
  `+$e.slice(S);else{if(L||N.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||Ie.test(N)||Re.test(N)||oe.test(N))break;I+=`
30
- `+$}!L&&!$.trim()&&(L=!0),v+=he+`
31
- `,n=n.substring(he.length+1),N=$e.slice(S)}}a.loose||(l?a.loose=!0:this.rules.other.doubleBlankLine.test(v)&&(l=!0));let ge=null,ye;this.options.gfm&&(ge=this.rules.other.listIsTask.exec(I),ge&&(ye=ge[0]!=="[ ] ",I=I.replace(this.rules.other.listReplaceTask,""))),a.items.push({type:"list_item",raw:v,task:!!ge,checked:ye,loose:!1,text:I,tokens:[]}),a.raw+=v}const c=a.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd();else return;a.raw=a.raw.trimEnd();for(let _=0;_<a.items.length;_++)if(this.lexer.state.top=!1,a.items[_].tokens=this.lexer.blockTokens(a.items[_].text,[]),!a.loose){const v=a.items[_].tokens.filter(N=>N.type==="space"),I=v.length>0&&v.some(N=>this.rules.other.anyLine.test(N.raw));a.loose=I}if(a.loose)for(let _=0;_<a.items.length;_++)a.items[_].loose=!0;return a}}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"):"",a=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:a}}}table(n){const e=this.rules.block.table.exec(n);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;const r=Ks(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),a=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
30
+ `+$}!L&&!$.trim()&&(L=!0),g+=he+`
31
+ `,n=n.substring(he.length+1),N=$e.slice(S)}}a.loose||(l?a.loose=!0:this.rules.other.doubleBlankLine.test(g)&&(l=!0));let ve=null,ye;this.options.gfm&&(ve=this.rules.other.listIsTask.exec(I),ve&&(ye=ve[0]!=="[ ] ",I=I.replace(this.rules.other.listReplaceTask,""))),a.items.push({type:"list_item",raw:g,task:!!ve,checked:ye,loose:!1,text:I,tokens:[]}),a.raw+=g}const c=a.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd();else return;a.raw=a.raw.trimEnd();for(let _=0;_<a.items.length;_++)if(this.lexer.state.top=!1,a.items[_].tokens=this.lexer.blockTokens(a.items[_].text,[]),!a.loose){const g=a.items[_].tokens.filter(N=>N.type==="space"),I=g.length>0&&g.some(N=>this.rules.other.anyLine.test(N.raw));a.loose=I}if(a.loose)for(let _=0;_<a.items.length;_++)a.items[_].loose=!0;return a}}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"):"",a=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:a}}}table(n){const e=this.rules.block.table.exec(n);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;const r=Ks(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),a=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
32
32
  `):[],o={type:"table",raw:e[0],header:[],align:[],rows:[]};if(r.length===s.length){for(const l of s)this.rules.other.tableAlignRight.test(l)?o.align.push("right"):this.rules.other.tableAlignCenter.test(l)?o.align.push("center"):this.rules.other.tableAlignLeft.test(l)?o.align.push("left"):o.align.push(null);for(let l=0;l<r.length;l++)o.header.push({text:r[l],tokens:this.lexer.inline(r[l]),header:!0,align:o.align[l]});for(const l of a)o.rows.push(Ks(l,o.header.length).map((c,_)=>({text:c,tokens:this.lexer.inline(c),header:!1,align:o.align[_]})));return o}}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)===`
33
- `?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 o=lr(r.slice(0,-1),"\\");if((r.length-o.length)%2===0)return}else{const o=Fi(e[2],"()");if(o===-2)return;if(o>-1){const c=(e[0].indexOf("!")===0?5:4)+e[1].length+o;e[2]=e[2].substring(0,o),e[0]=e[0].substring(0,c).trim(),e[3]=""}}let s=e[2],a="";if(this.options.pedantic){const o=this.rules.other.pedanticHrefTitle.exec(s);o&&(s=o[1],a=o[3])}else a=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)),Xs(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:a&&a.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," "),a=e[s.toLowerCase()];if(!a){const o=r[0].charAt(0);return{type:"text",raw:o,text:o}}return Xs(r,a,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 o=[...s[0]].length-1;let l,c,_=o,v=0;const I=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(I.lastIndex=0,e=e.slice(-1*n.length+o);(s=I.exec(e))!=null;){if(l=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!l)continue;if(c=[...l].length,s[3]||s[4]){_+=c;continue}else if((s[5]||s[6])&&o%3&&!((o+c)%3)){v+=c;continue}if(_-=c,_>0)continue;c=Math.min(c,c+_+v);const N=[...s[0]][0].length,$=n.slice(0,o+s.index+N+c);if(Math.min(o,c)%2){const S=$.slice(1,-1);return{type:"em",raw:$,text:S,tokens:this.lexer.inlineTokens(S)}}const L=$.slice(2,-2);return{type:"strong",raw:$,text:L,tokens:this.lexer.inlineTokens(L)}}}}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),a=this.rules.other.startingSpaceChar.test(r)&&this.rules.other.endingSpaceChar.test(r);return s&&a&&(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 a;do a=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(a!==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}}}},Sn=class fs{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||qn,this.options.tokenizer=this.options.tokenizer||new Or,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:tn,block:Ar.normal,inline:ir.normal};this.options.pedantic?(r.block=Ar.pedantic,r.inline=ir.pedantic):this.options.gfm&&(r.block=Ar.gfm,this.options.breaks?r.inline=ir.breaks:r.inline=ir.gfm),this.tokenizer.rules=r}static get rules(){return{block:Ar,inline:ir}}static lex(e,r){return new fs(r).lex(e)}static lexInline(e,r){return new fs(r).inlineTokens(e)}lex(e){e=e.replace(tn.carriageReturn,`
33
+ `?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 o=lr(r.slice(0,-1),"\\");if((r.length-o.length)%2===0)return}else{const o=Fi(e[2],"()");if(o===-2)return;if(o>-1){const c=(e[0].indexOf("!")===0?5:4)+e[1].length+o;e[2]=e[2].substring(0,o),e[0]=e[0].substring(0,c).trim(),e[3]=""}}let s=e[2],a="";if(this.options.pedantic){const o=this.rules.other.pedanticHrefTitle.exec(s);o&&(s=o[1],a=o[3])}else a=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)),Xs(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:a&&a.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," "),a=e[s.toLowerCase()];if(!a){const o=r[0].charAt(0);return{type:"text",raw:o,text:o}}return Xs(r,a,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 o=[...s[0]].length-1;let l,c,_=o,g=0;const I=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(I.lastIndex=0,e=e.slice(-1*n.length+o);(s=I.exec(e))!=null;){if(l=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!l)continue;if(c=[...l].length,s[3]||s[4]){_+=c;continue}else if((s[5]||s[6])&&o%3&&!((o+c)%3)){g+=c;continue}if(_-=c,_>0)continue;c=Math.min(c,c+_+g);const N=[...s[0]][0].length,$=n.slice(0,o+s.index+N+c);if(Math.min(o,c)%2){const S=$.slice(1,-1);return{type:"em",raw:$,text:S,tokens:this.lexer.inlineTokens(S)}}const L=$.slice(2,-2);return{type:"strong",raw:$,text:L,tokens:this.lexer.inlineTokens(L)}}}}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),a=this.rules.other.startingSpaceChar.test(r)&&this.rules.other.endingSpaceChar.test(r);return s&&a&&(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 a;do a=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(a!==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}}}},Sn=class fs{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||qn,this.options.tokenizer=this.options.tokenizer||new Or,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:tn,block:Ar.normal,inline:ir.normal};this.options.pedantic?(r.block=Ar.pedantic,r.inline=ir.pedantic):this.options.gfm&&(r.block=Ar.gfm,this.options.breaks?r.inline=ir.breaks:r.inline=ir.gfm),this.tokenizer.rules=r}static get rules(){return{block:Ar,inline:ir}}static lex(e,r){return new fs(r).lex(e)}static lexInline(e,r){return new fs(r).inlineTokens(e)}lex(e){e=e.replace(tn.carriageReturn,`
34
34
  `),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(tn.tabCharGlobal," ").replace(tn.spaceLine,""));e;){let a;if(this.options.extensions?.block?.some(l=>(a=l.call({lexer:this},e,r))?(e=e.substring(a.raw.length),r.push(a),!0):!1))continue;if(a=this.tokenizer.space(e)){e=e.substring(a.raw.length);const l=r.at(-1);a.raw.length===1&&l!==void 0?l.raw+=`
35
35
  `:r.push(a);continue}if(a=this.tokenizer.code(e)){e=e.substring(a.raw.length);const l=r.at(-1);l?.type==="paragraph"||l?.type==="text"?(l.raw+=`
36
36
  `+a.raw,l.text+=`
37
37
  `+a.text,this.inlineQueue.at(-1).src=l.text):r.push(a);continue}if(a=this.tokenizer.fences(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.heading(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.hr(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.blockquote(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.list(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.html(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.def(e)){e=e.substring(a.raw.length);const l=r.at(-1);l?.type==="paragraph"||l?.type==="text"?(l.raw+=`
38
38
  `+a.raw,l.text+=`
39
- `+a.raw,this.inlineQueue.at(-1).src=l.text):this.tokens.links[a.tag]||(this.tokens.links[a.tag]={href:a.href,title:a.title});continue}if(a=this.tokenizer.table(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.lheading(e)){e=e.substring(a.raw.length),r.push(a);continue}let o=e;if(this.options.extensions?.startBlock){let l=1/0;const c=e.slice(1);let _;this.options.extensions.startBlock.forEach(v=>{_=v.call({lexer:this},c),typeof _=="number"&&_>=0&&(l=Math.min(l,_))}),l<1/0&&l>=0&&(o=e.substring(0,l+1))}if(this.state.top&&(a=this.tokenizer.paragraph(o))){const l=r.at(-1);s&&l?.type==="paragraph"?(l.raw+=`
39
+ `+a.raw,this.inlineQueue.at(-1).src=l.text):this.tokens.links[a.tag]||(this.tokens.links[a.tag]={href:a.href,title:a.title});continue}if(a=this.tokenizer.table(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.lheading(e)){e=e.substring(a.raw.length),r.push(a);continue}let o=e;if(this.options.extensions?.startBlock){let l=1/0;const c=e.slice(1);let _;this.options.extensions.startBlock.forEach(g=>{_=g.call({lexer:this},c),typeof _=="number"&&_>=0&&(l=Math.min(l,_))}),l<1/0&&l>=0&&(o=e.substring(0,l+1))}if(this.state.top&&(a=this.tokenizer.paragraph(o))){const l=r.at(-1);s&&l?.type==="paragraph"?(l.raw+=`
40
40
  `+a.raw,l.text+=`
41
41
  `+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):r.push(a),s=o.length!==e.length,e=e.substring(a.raw.length);continue}if(a=this.tokenizer.text(e)){e=e.substring(a.raw.length);const l=r.at(-1);l?.type==="text"?(l.raw+=`
42
42
  `+a.raw,l.text+=`
43
- `+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):r.push(a);continue}if(e){const l="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(l);break}else throw new Error(l)}}return this.state.top=!0,r}inline(e,r=[]){return this.inlineQueue.push({src:e,tokens:r}),r}inlineTokens(e,r=[]){let s=e,a=null;if(this.tokens.links){const c=Object.keys(this.tokens.links);if(c.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)c.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,a.index)+"["+"a".repeat(a[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(a=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,a.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(a=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)s=s.slice(0,a.index)+"["+"a".repeat(a[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let o=!1,l="";for(;e;){o||(l=""),o=!1;let c;if(this.options.extensions?.inline?.some(v=>(c=v.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 v=r.at(-1);c.type==="text"&&v?.type==="text"?(v.raw+=c.raw,v.text+=c.text):r.push(c);continue}if(c=this.tokenizer.emStrong(e,s,l)){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 v=1/0;const I=e.slice(1);let N;this.options.extensions.startInline.forEach($=>{N=$.call({lexer:this},I),typeof N=="number"&&N>=0&&(v=Math.min(v,N))}),v<1/0&&v>=0&&(_=e.substring(0,v+1))}if(c=this.tokenizer.inlineText(_)){e=e.substring(c.raw.length),c.raw.slice(-1)!=="_"&&(l=c.raw.slice(-1)),o=!0;const v=r.at(-1);v?.type==="text"?(v.raw+=c.raw,v.text+=c.text):r.push(c);continue}if(e){const v="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(v);break}else throw new Error(v)}}return r}},Dr=class{options;parser;constructor(n){this.options=n||qn}space(n){return""}code({text:n,lang:e,escaped:r}){const s=(e||"").match(tn.notSpaceStart)?.[0],a=n.replace(tn.endingNewline,"")+`
43
+ `+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):r.push(a);continue}if(e){const l="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(l);break}else throw new Error(l)}}return this.state.top=!0,r}inline(e,r=[]){return this.inlineQueue.push({src:e,tokens:r}),r}inlineTokens(e,r=[]){let s=e,a=null;if(this.tokens.links){const c=Object.keys(this.tokens.links);if(c.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)c.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,a.index)+"["+"a".repeat(a[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(a=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,a.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(a=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)s=s.slice(0,a.index)+"["+"a".repeat(a[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let o=!1,l="";for(;e;){o||(l=""),o=!1;let c;if(this.options.extensions?.inline?.some(g=>(c=g.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 g=r.at(-1);c.type==="text"&&g?.type==="text"?(g.raw+=c.raw,g.text+=c.text):r.push(c);continue}if(c=this.tokenizer.emStrong(e,s,l)){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 g=1/0;const I=e.slice(1);let N;this.options.extensions.startInline.forEach($=>{N=$.call({lexer:this},I),typeof N=="number"&&N>=0&&(g=Math.min(g,N))}),g<1/0&&g>=0&&(_=e.substring(0,g+1))}if(c=this.tokenizer.inlineText(_)){e=e.substring(c.raw.length),c.raw.slice(-1)!=="_"&&(l=c.raw.slice(-1)),o=!0;const g=r.at(-1);g?.type==="text"?(g.raw+=c.raw,g.text+=c.text):r.push(c);continue}if(e){const g="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(g);break}else throw new Error(g)}}return r}},Dr=class{options;parser;constructor(n){this.options=n||qn}space(n){return""}code({text:n,lang:e,escaped:r}){const s=(e||"").match(tn.notSpaceStart)?.[0],a=n.replace(tn.endingNewline,"")+`
44
44
  `;return s?'<pre><code class="language-'+_n(s)+'">'+(r?a:_n(a,!0))+`</code></pre>
45
45
  `:"<pre><code>"+(r?a:_n(a,!0))+`</code></pre>
46
46
  `}blockquote({tokens:n}){return`<blockquote>
@@ -59,24 +59,24 @@ ${this.parser.parse(n)}</blockquote>
59
59
  ${n}</tr>
60
60
  `}tablecell(n){const e=this.parser.parseInline(n.tokens),r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+e+`</${r}>
61
61
  `}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>${_n(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),a=Zs(n);if(a===null)return s;n=a;let o='<a href="'+n+'"';return e&&(o+=' title="'+_n(e)+'"'),o+=">"+s+"</a>",o}image({href:n,title:e,text:r,tokens:s}){s&&(r=this.parser.parseInline(s,this.parser.textRenderer));const a=Zs(n);if(a===null)return _n(r);n=a;let o=`<img src="${n}" alt="${r}"`;return e&&(o+=` title="${_n(e)}"`),o+=">",o}text(n){return"tokens"in n&&n.tokens?this.parser.parseInline(n.tokens):"escaped"in n&&n.escaped?n.text:_n(n.text)}},Fs=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""}},Tn=class ps{options;renderer;textRenderer;constructor(e){this.options=e||qn,this.options.renderer=this.options.renderer||new Dr,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Fs}static parse(e,r){return new ps(r).parse(e)}static parseInline(e,r){return new ps(r).parseInline(e)}parse(e,r=!0){let s="";for(let a=0;a<e.length;a++){const o=e[a];if(this.options.extensions?.renderers?.[o.type]){const c=o,_=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 l=o;switch(l.type){case"space":{s+=this.renderer.space(l);continue}case"hr":{s+=this.renderer.hr(l);continue}case"heading":{s+=this.renderer.heading(l);continue}case"code":{s+=this.renderer.code(l);continue}case"table":{s+=this.renderer.table(l);continue}case"blockquote":{s+=this.renderer.blockquote(l);continue}case"list":{s+=this.renderer.list(l);continue}case"html":{s+=this.renderer.html(l);continue}case"paragraph":{s+=this.renderer.paragraph(l);continue}case"text":{let c=l,_=this.renderer.text(c);for(;a+1<e.length&&e[a+1].type==="text";)c=e[++a],_+=`
62
- `+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 "'+l.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 a=0;a<e.length;a++){const o=e[a];if(this.options.extensions?.renderers?.[o.type]){const c=this.options.extensions.renderers[o.type].call({parser:this},o);if(c!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(o.type)){s+=c||"";continue}}const l=o;switch(l.type){case"escape":{s+=r.text(l);break}case"html":{s+=r.html(l);break}case"link":{s+=r.link(l);break}case"image":{s+=r.image(l);break}case"strong":{s+=r.strong(l);break}case"em":{s+=r.em(l);break}case"codespan":{s+=r.codespan(l);break}case"br":{s+=r.br(l);break}case"del":{s+=r.del(l);break}case"text":{s+=r.text(l);break}default:{const c='Token with "'+l.type+'" type was not found.';if(this.options.silent)return console.error(c),"";throw new Error(c)}}}return s}},Cr=class{options;block;constructor(n){this.options=n||qn}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(n){return n}postprocess(n){return n}processAllTokens(n){return n}provideLexer(){return this.block?Sn.lex:Sn.lexInline}provideParser(){return this.block?Tn.parse:Tn.parseInline}},zi=class{defaults=Is();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Tn;Renderer=Dr;TextRenderer=Fs;Lexer=Sn;Tokenizer=Or;Hooks=Cr;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 a=s;for(const o of a.header)r=r.concat(this.walkTokens(o.tokens,e));for(const o of a.rows)for(const l of o)r=r.concat(this.walkTokens(l.tokens,e));break}case"list":{const a=s;r=r.concat(this.walkTokens(a.items,e));break}default:{const a=s;this.defaults.extensions?.childTokens?.[a.type]?this.defaults.extensions.childTokens[a.type].forEach(o=>{const l=a[o].flat(1/0);r=r.concat(this.walkTokens(l,e))}):a.tokens&&(r=r.concat(this.walkTokens(a.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(a=>{if(!a.name)throw new Error("extension name required");if("renderer"in a){const o=e.renderers[a.name];o?e.renderers[a.name]=function(...l){let c=a.renderer.apply(this,l);return c===!1&&(c=o.apply(this,l)),c}:e.renderers[a.name]=a.renderer}if("tokenizer"in a){if(!a.level||a.level!=="block"&&a.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const o=e[a.level];o?o.unshift(a.tokenizer):e[a.level]=[a.tokenizer],a.start&&(a.level==="block"?e.startBlock?e.startBlock.push(a.start):e.startBlock=[a.start]:a.level==="inline"&&(e.startInline?e.startInline.push(a.start):e.startInline=[a.start]))}"childTokens"in a&&a.childTokens&&(e.childTokens[a.name]=a.childTokens)}),s.extensions=e),r.renderer){const a=this.defaults.renderer||new Dr(this.defaults);for(const o in r.renderer){if(!(o in a))throw new Error(`renderer '${o}' does not exist`);if(["options","parser"].includes(o))continue;const l=o,c=r.renderer[l],_=a[l];a[l]=(...v)=>{let I=c.apply(a,v);return I===!1&&(I=_.apply(a,v)),I||""}}s.renderer=a}if(r.tokenizer){const a=this.defaults.tokenizer||new Or(this.defaults);for(const o in r.tokenizer){if(!(o in a))throw new Error(`tokenizer '${o}' does not exist`);if(["options","rules","lexer"].includes(o))continue;const l=o,c=r.tokenizer[l],_=a[l];a[l]=(...v)=>{let I=c.apply(a,v);return I===!1&&(I=_.apply(a,v)),I}}s.tokenizer=a}if(r.hooks){const a=this.defaults.hooks||new Cr;for(const o in r.hooks){if(!(o in a))throw new Error(`hook '${o}' does not exist`);if(["options","block"].includes(o))continue;const l=o,c=r.hooks[l],_=a[l];Cr.passThroughHooks.has(o)?a[l]=v=>{if(this.defaults.async)return Promise.resolve(c.call(a,v)).then(N=>_.call(a,N));const I=c.call(a,v);return _.call(a,I)}:a[l]=(...v)=>{let I=c.apply(a,v);return I===!1&&(I=_.apply(a,v)),I}}s.hooks=a}if(r.walkTokens){const a=this.defaults.walkTokens,o=r.walkTokens;s.walkTokens=function(l){let c=[];return c.push(o.call(this,l)),a&&(c=c.concat(a.call(this,l))),c}}this.defaults={...this.defaults,...s}}),this}setOptions(n){return this.defaults={...this.defaults,...n},this}lexer(n,e){return Sn.lex(n,e??this.defaults)}parser(n,e){return Tn.parse(n,e??this.defaults)}parseMarkdown(n){return(r,s)=>{const a={...s},o={...this.defaults,...a},l=this.onError(!!o.silent,!!o.async);if(this.defaults.async===!0&&a.async===!1)return l(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 l(new Error("marked(): input parameter is undefined or null"));if(typeof r!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(r)+", string expected"));o.hooks&&(o.hooks.options=o,o.hooks.block=n);const c=o.hooks?o.hooks.provideLexer():n?Sn.lex:Sn.lexInline,_=o.hooks?o.hooks.provideParser():n?Tn.parse:Tn.parseInline;if(o.async)return Promise.resolve(o.hooks?o.hooks.preprocess(r):r).then(v=>c(v,o)).then(v=>o.hooks?o.hooks.processAllTokens(v):v).then(v=>o.walkTokens?Promise.all(this.walkTokens(v,o.walkTokens)).then(()=>v):v).then(v=>_(v,o)).then(v=>o.hooks?o.hooks.postprocess(v):v).catch(l);try{o.hooks&&(r=o.hooks.preprocess(r));let v=c(r,o);o.hooks&&(v=o.hooks.processAllTokens(v)),o.walkTokens&&this.walkTokens(v,o.walkTokens);let I=_(v,o);return o.hooks&&(I=o.hooks.postprocess(I)),I}catch(v){return l(v)}}}onError(n,e){return r=>{if(r.message+=`
63
- Please report this to https://github.com/markedjs/marked.`,n){const s="<p>An error occurred:</p><pre>"+_n(r.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(r);throw r}}},Wn=new zi;function lt(n,e){return Wn.parse(n,e)}lt.options=lt.setOptions=function(n){return Wn.setOptions(n),lt.defaults=Wn.defaults,Ha(lt.defaults),lt};lt.getDefaults=Is;lt.defaults=qn;lt.use=function(...n){return Wn.use(...n),lt.defaults=Wn.defaults,Ha(lt.defaults),lt};lt.walkTokens=function(n,e){return Wn.walkTokens(n,e)};lt.parseInline=Wn.parseInline;lt.Parser=Tn;lt.parser=Tn.parse;lt.Renderer=Dr;lt.TextRenderer=Fs;lt.Lexer=Sn;lt.lexer=Sn.lex;lt.Tokenizer=Or;lt.Hooks=Cr;lt.parse=lt;lt.options;lt.setOptions;lt.use;lt.walkTokens;lt.parseInline;Tn.parse;Sn.lex;function Qs(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 Hi(n){if(Array.isArray(n))return n}function Bi(n,e){var r=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(r!=null){var s,a,o,l,c=[],_=!0,v=!1;try{if(o=(r=r.call(n)).next,e!==0)for(;!(_=(s=o.call(r)).done)&&(c.push(s.value),c.length!==e);_=!0);}catch(I){v=!0,a=I}finally{try{if(!_&&r.return!=null&&(l=r.return(),Object(l)!==l))return}finally{if(v)throw a}}return c}}function Wi(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
64
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Gi(n,e){return Hi(n)||Bi(n,e)||ji(n,e)||Wi()}function ji(n,e){if(n){if(typeof n=="string")return Qs(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)?Qs(n,e):void 0}}const Qa=Object.entries,Js=Object.setPrototypeOf,qi=Object.isFrozen,Vi=Object.getPrototypeOf,Yi=Object.getOwnPropertyDescriptor;let Vt=Object.freeze,Yt=Object.seal,Xn=Object.create,Ja=typeof Reflect<"u"&&Reflect,hs=Ja.apply,bs=Ja.construct;Vt||(Vt=function(e){return e});Yt||(Yt=function(e){return e});hs||(hs=function(e,r){for(var s=arguments.length,a=new Array(s>2?s-2:0),o=2;o<s;o++)a[o-2]=arguments[o];return e.apply(r,a)});bs||(bs=function(e){for(var r=arguments.length,s=new Array(r>1?r-1:0),a=1;a<r;a++)s[a-1]=arguments[a];return new e(...s)});const cr=Ot(Array.prototype.forEach),Zi=Ot(Array.prototype.lastIndexOf),ea=Ot(Array.prototype.pop),Zn=Ot(Array.prototype.push),Ki=Ot(Array.prototype.splice),Dn=Array.isArray,hr=Ot(String.prototype.toLowerCase),Vr=Ot(String.prototype.toString),ta=Ot(String.prototype.match),dr=Ot(String.prototype.replace),na=Ot(String.prototype.indexOf),Xi=Ot(String.prototype.trim),Qi=Ot(Number.prototype.toString),Ji=Ot(Boolean.prototype.toString),ra=typeof BigInt>"u"?null:Ot(BigInt.prototype.toString),sa=typeof Symbol>"u"?null:Ot(Symbol.prototype.toString),zt=Ot(Object.prototype.hasOwnProperty),ur=Ot(Object.prototype.toString),jt=Ot(RegExp.prototype.test),zn=el(TypeError);function Ot(n){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var r=arguments.length,s=new Array(r>1?r-1:0),a=1;a<r;a++)s[a-1]=arguments[a];return hs(n,e,s)}}function el(n){return function(){for(var e=arguments.length,r=new Array(e),s=0;s<e;s++)r[s]=arguments[s];return bs(n,r)}}function Je(n,e){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:hr;if(Js&&Js(n,null),!Dn(e))return n;let s=e.length;for(;s--;){let a=e[s];if(typeof a=="string"){const o=r(a);o!==a&&(qi(e)||(e[s]=o),a=o)}n[a]=!0}return n}function tl(n){for(let e=0;e<n.length;e++)zt(n,e)||(n[e]=null);return n}function en(n){const e=Xn(null);for(const s of Qa(n)){var r=Gi(s,2);const a=r[0],o=r[1];zt(n,a)&&(Dn(o)?e[a]=tl(o):o&&typeof o=="object"&&o.constructor===Object?e[a]=en(o):e[a]=o)}return e}function nl(n){switch(typeof n){case"string":return n;case"number":return Qi(n);case"boolean":return Ji(n);case"bigint":return ra?ra(n):"0";case"symbol":return sa?sa(n):"Symbol()";case"undefined":return ur(n);case"function":case"object":{if(n===null)return ur(n);const e=n,r=yn(e,"toString");if(typeof r=="function"){const s=r(e);return typeof s=="string"?s:ur(s)}return ur(n)}default:return ur(n)}}function yn(n,e){for(;n!==null;){const s=Yi(n,e);if(s){if(s.get)return Ot(s.get);if(typeof s.value=="function")return Ot(s.value)}n=Vi(n)}function r(){return null}return r}function rl(n){try{return jt(n,""),!0}catch{return!1}}const aa=Vt(["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"]),Yr=Vt(["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"]),Zr=Vt(["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"]),sl=Vt(["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"]),Kr=Vt(["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"]),al=Vt(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),oa=Vt(["#text"]),ia=Vt(["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"]),Xr=Vt(["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"]),la=Vt(["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"]),Er=Vt(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),ol=Yt(/{{[\w\W]*|^[\w\W]*}}/g),il=Yt(/<%[\w\W]*|^[\w\W]*%>/g),ll=Yt(/\${[\w\W]*/g),cl=Yt(/^data-[\-\w.\u00B7-\uFFFF]+$/),dl=Yt(/^aria-[\-\w]+$/),ca=Yt(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ul=Yt(/^(?:\w+script|data):/i),fl=Yt(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),pl=Yt(/^html$/i),hl=Yt(/^[a-z][.\w]*(-[.\w]+)+$/i),da=Yt(/<[/\w!]/g),bl=Yt(/<[/\w]/g),vl=Yt(/<\/no(script|embed|frames)/i),gl=Yt(/\/>/i),xn={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},ml=function(){return typeof window>"u"?null:window},xl=function(e,r){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let s=null;const a="data-tt-policy-suffix";r&&r.hasAttribute(a)&&(s=r.getAttribute(a));const o="dompurify"+(s?"#"+s:"");try{return e.createPolicy(o,{createHTML(l){return l},createScriptURL(l){return l}})}catch{return console.warn("TrustedTypes policy "+o+" could not be created."),null}},ua=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Mn=function(e,r,s,a){return zt(e,r)&&Dn(e[r])?Je(a.base?en(a.base):{},e[r],a.transform):s};function eo(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:ml();const e=A=>eo(A);if(e.version="3.4.11",e.removed=[],!n||!n.document||n.document.nodeType!==xn.document||!n.Element)return e.isSupported=!1,e;let r=n.document;const s=r,a=s.currentScript;n.DocumentFragment;const o=n.HTMLTemplateElement,l=n.Node,c=n.Element,_=n.NodeFilter,v=n.NamedNodeMap;v===void 0&&(n.NamedNodeMap||n.MozNamedAttrMap),n.HTMLFormElement;const I=n.DOMParser,N=n.trustedTypes,$=c.prototype,L=yn($,"cloneNode"),S=yn($,"remove"),ge=yn($,"nextSibling"),ye=yn($,"childNodes"),fe=yn($,"parentNode"),oe=yn($,"shadowRoot"),Ie=yn($,"attributes"),Re=l&&l.prototype?yn(l.prototype,"nodeType"):null,Ne=l&&l.prototype?yn(l.prototype,"nodeName"):null;if(typeof o=="function"){const A=r.createElement("template");A.content&&A.content.ownerDocument&&(r=A.content.ownerDocument)}let he,$e="",ot,me=!1,Ue=0;const Me=function(){if(Ue>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.')},Fe=function(i){Me(),Ue++;try{return he.createHTML(i)}finally{Ue--}},dt=function(i){Me(),Ue++;try{return he.createScriptURL(i)}finally{Ue--}},ft=function(){return me||(ot=xl(N,a),me=!0),ot},pt=r,be=pt.implementation,Se=pt.createNodeIterator,Te=pt.createDocumentFragment,Dt=pt.getElementsByTagName,Xe=s.importNode;let ze=ua();e.isSupported=typeof Qa=="function"&&typeof fe=="function"&&be&&be.createHTMLDocument!==void 0;const nn=ol,Ve=il,Tt=ll,Nt=cl,ht=dl,kt=ul,Mt=fl,St=hl;let Y=ca,y=null;const z=Je({},[...aa,...Yr,...Zr,...Kr,...oa]);let R=null;const Z=Je({},[...ia,...Xr,...la,...Er]);let q=Object.seal(Xn(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}})),re=null,ee=null;const Qe=Object.seal(Xn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let He=!0,ut=!0,bt=!1,et=!0,rt=!1,Le=!0,Be=!1,Wt=!1,Ft=null,At=null,mt=!1,xt=!1,Zt=!1,Ce=!1,Ze=!0,Pt=!1;const _t="user-content-";let Xt=!0,Kt=!1,vt={},gt=null;const ln=Je({},["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 an=null;const cn=Je({},["audio","video","img","source","image","track"]);let rn=null;const dn=Je({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),E="http://www.w3.org/1998/Math/MathML",x="http://www.w3.org/2000/svg",w="http://www.w3.org/1999/xhtml";let O=w,Q=!1,We=null;const we=Je({},[E,x,w],Vr),ie=Vt(["mi","mo","mn","ms","mtext"]);let g=Je({},ie);const k=Vt(["annotation-xml"]);let H=Je({},k);const D=Je({},["title","style","font","a","script"]);let le=null;const K=["application/xhtml+xml","text/html"],T="text/html";let F=null,te=null;const Oe=r.createElement("form"),Ae=function(i){return i instanceof RegExp||i instanceof Function},xe=function(){let i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(te&&te===i)return;(!i||typeof i!="object")&&(i={}),i=en(i),le=K.indexOf(i.PARSER_MEDIA_TYPE)===-1?T:i.PARSER_MEDIA_TYPE,F=le==="application/xhtml+xml"?Vr:hr,y=Mn(i,"ALLOWED_TAGS",z,{transform:F}),R=Mn(i,"ALLOWED_ATTR",Z,{transform:F}),We=Mn(i,"ALLOWED_NAMESPACES",we,{transform:Vr}),rn=Mn(i,"ADD_URI_SAFE_ATTR",dn,{transform:F,base:dn}),an=Mn(i,"ADD_DATA_URI_TAGS",cn,{transform:F,base:cn}),gt=Mn(i,"FORBID_CONTENTS",ln,{transform:F}),re=Mn(i,"FORBID_TAGS",en({}),{transform:F}),ee=Mn(i,"FORBID_ATTR",en({}),{transform:F}),vt=zt(i,"USE_PROFILES")?i.USE_PROFILES&&typeof i.USE_PROFILES=="object"?en(i.USE_PROFILES):i.USE_PROFILES:!1,He=i.ALLOW_ARIA_ATTR!==!1,ut=i.ALLOW_DATA_ATTR!==!1,bt=i.ALLOW_UNKNOWN_PROTOCOLS||!1,et=i.ALLOW_SELF_CLOSE_IN_ATTR!==!1,rt=i.SAFE_FOR_TEMPLATES||!1,Le=i.SAFE_FOR_XML!==!1,Be=i.WHOLE_DOCUMENT||!1,xt=i.RETURN_DOM||!1,Zt=i.RETURN_DOM_FRAGMENT||!1,Ce=i.RETURN_TRUSTED_TYPE||!1,mt=i.FORCE_BODY||!1,Ze=i.SANITIZE_DOM!==!1,Pt=i.SANITIZE_NAMED_PROPS||!1,Xt=i.KEEP_CONTENT!==!1,Kt=i.IN_PLACE||!1,Y=rl(i.ALLOWED_URI_REGEXP)?i.ALLOWED_URI_REGEXP:ca,O=typeof i.NAMESPACE=="string"?i.NAMESPACE:w,g=zt(i,"MATHML_TEXT_INTEGRATION_POINTS")&&i.MATHML_TEXT_INTEGRATION_POINTS&&typeof i.MATHML_TEXT_INTEGRATION_POINTS=="object"?en(i.MATHML_TEXT_INTEGRATION_POINTS):Je({},ie),H=zt(i,"HTML_INTEGRATION_POINTS")&&i.HTML_INTEGRATION_POINTS&&typeof i.HTML_INTEGRATION_POINTS=="object"?en(i.HTML_INTEGRATION_POINTS):Je({},k);const b=zt(i,"CUSTOM_ELEMENT_HANDLING")&&i.CUSTOM_ELEMENT_HANDLING&&typeof i.CUSTOM_ELEMENT_HANDLING=="object"?en(i.CUSTOM_ELEMENT_HANDLING):Xn(null);if(q=Xn(null),zt(b,"tagNameCheck")&&Ae(b.tagNameCheck)&&(q.tagNameCheck=b.tagNameCheck),zt(b,"attributeNameCheck")&&Ae(b.attributeNameCheck)&&(q.attributeNameCheck=b.attributeNameCheck),zt(b,"allowCustomizedBuiltInElements")&&typeof b.allowCustomizedBuiltInElements=="boolean"&&(q.allowCustomizedBuiltInElements=b.allowCustomizedBuiltInElements),Yt(q),rt&&(ut=!1),Zt&&(xt=!0),vt&&(y=Je({},oa),R=Xn(null),vt.html===!0&&(Je(y,aa),Je(R,ia)),vt.svg===!0&&(Je(y,Yr),Je(R,Xr),Je(R,Er)),vt.svgFilters===!0&&(Je(y,Zr),Je(R,Xr),Je(R,Er)),vt.mathMl===!0&&(Je(y,Kr),Je(R,la),Je(R,Er))),Qe.tagCheck=null,Qe.attributeCheck=null,zt(i,"ADD_TAGS")&&(typeof i.ADD_TAGS=="function"?Qe.tagCheck=i.ADD_TAGS:Dn(i.ADD_TAGS)&&(y===z&&(y=en(y)),Je(y,i.ADD_TAGS,F))),zt(i,"ADD_ATTR")&&(typeof i.ADD_ATTR=="function"?Qe.attributeCheck=i.ADD_ATTR:Dn(i.ADD_ATTR)&&(R===Z&&(R=en(R)),Je(R,i.ADD_ATTR,F))),zt(i,"ADD_URI_SAFE_ATTR")&&Dn(i.ADD_URI_SAFE_ATTR)&&Je(rn,i.ADD_URI_SAFE_ATTR,F),zt(i,"FORBID_CONTENTS")&&Dn(i.FORBID_CONTENTS)&&(gt===ln&&(gt=en(gt)),Je(gt,i.FORBID_CONTENTS,F)),zt(i,"ADD_FORBID_CONTENTS")&&Dn(i.ADD_FORBID_CONTENTS)&&(gt===ln&&(gt=en(gt)),Je(gt,i.ADD_FORBID_CONTENTS,F)),Xt&&(y["#text"]=!0),Be&&Je(y,["html","head","body"]),y.table&&(Je(y,["tbody"]),delete re.tbody),i.TRUSTED_TYPES_POLICY){if(typeof i.TRUSTED_TYPES_POLICY.createHTML!="function")throw zn('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof i.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw zn('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const M=he;he=i.TRUSTED_TYPES_POLICY;try{$e=Fe("")}catch(X){throw he=M,X}}else i.TRUSTED_TYPES_POLICY===null?(he=void 0,$e=""):(he===void 0&&(he=ft()),he&&typeof $e=="string"&&($e=Fe("")));Vt&&Vt(i),te=i},st=Je({},[...Yr,...Zr,...sl]),It=Je({},[...Kr,...al]),Ge=function(i,b,M){return b.namespaceURI===w?i==="svg":b.namespaceURI===E?i==="svg"&&(M==="annotation-xml"||g[M]):!!st[i]},Ye=function(i,b,M){return b.namespaceURI===w?i==="math":b.namespaceURI===x?i==="math"&&H[M]:!!It[i]},pe=function(i,b,M){return b.namespaceURI===x&&!H[M]||b.namespaceURI===E&&!g[M]?!1:!It[i]&&(D[i]||!st[i])},B=function(i){let b=fe(i);(!b||!b.tagName)&&(b={namespaceURI:O,tagName:"template"});const M=hr(i.tagName),X=hr(b.tagName);return We[i.namespaceURI]?i.namespaceURI===x?Ge(M,b,X):i.namespaceURI===E?Ye(M,b,X):i.namespaceURI===w?pe(M,b,X):!!(le==="application/xhtml+xml"&&We[i.namespaceURI]):!1},U=function(i){Zn(e.removed,{element:i});try{fe(i).removeChild(i)}catch{if(S(i),!fe(i))throw zn("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},ce=function(i){const b=ye(i);if(b){const X=[];cr(b,Pe=>{Zn(X,Pe)}),cr(X,Pe=>{try{S(Pe)}catch{}})}const M=Ie(i);if(M)for(let X=M.length-1;X>=0;--X){const Pe=M[X],Ke=Pe&&Pe.name;if(typeof Ke=="string")try{i.removeAttribute(Ke)}catch{}}},de=function(i,b){try{Zn(e.removed,{attribute:b.getAttributeNode(i),from:b})}catch{Zn(e.removed,{attribute:null,from:b})}if(b.removeAttribute(i),i==="is")if(xt||Zt)try{U(b)}catch{}else try{b.setAttribute(i,"")}catch{}},ve=function(i){const b=Ie(i);if(b)for(let M=b.length-1;M>=0;--M){const X=b[M],Pe=X&&X.name;if(!(typeof Pe!="string"||R[F(Pe)]))try{i.removeAttribute(Pe)}catch{}}},ae=function(i){const b=[i];for(;b.length>0;){const M=b.pop();(Re?Re(M):M.nodeType)===xn.element&&ve(M);const Pe=ye(M);if(Pe)for(let Ke=Pe.length-1;Ke>=0;--Ke)b.push(Pe[Ke])}},G=function(i){let b=null,M=null;if(mt)i="<remove></remove>"+i;else{const Ke=ta(i,/^[\r\n\t ]+/);M=Ke&&Ke[0]}le==="application/xhtml+xml"&&O===w&&(i='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+i+"</body></html>");const X=he?Fe(i):i;if(O===w)try{b=new I().parseFromString(X,le)}catch{}if(!b||!b.documentElement){b=be.createDocument(O,"template",null);try{b.documentElement.innerHTML=Q?$e:X}catch{}}const Pe=b.body||b.documentElement;return i&&M&&Pe.insertBefore(r.createTextNode(M),Pe.childNodes[0]||null),O===w?Dt.call(b,Be?"html":"body")[0]:Be?b.documentElement:Pe},P=function(i){return Se.call(i.ownerDocument||i,i,_.SHOW_ELEMENT|_.SHOW_COMMENT|_.SHOW_TEXT|_.SHOW_PROCESSING_INSTRUCTION|_.SHOW_CDATA_SECTION,null)},J=function(i){return i=dr(i,nn," "),i=dr(i,Ve," "),i=dr(i,Tt," "),i},_e=function(i){var b;i.normalize();const M=Se.call(i.ownerDocument||i,i,_.SHOW_TEXT|_.SHOW_COMMENT|_.SHOW_CDATA_SECTION|_.SHOW_PROCESSING_INSTRUCTION,null);let X=M.nextNode();for(;X;)X.data=J(X.data),X=M.nextNode();const Pe=(b=i.querySelectorAll)===null||b===void 0?void 0:b.call(i,"template");Pe&&cr(Pe,Ke=>{ne(Ke.content)&&_e(Ke.content)})},Ee=function(i){const b=Ne?Ne(i):null;return typeof b!="string"||F(b)!=="form"?!1:typeof i.nodeName!="string"||typeof i.textContent!="string"||typeof i.removeChild!="function"||i.attributes!==Ie(i)||typeof i.removeAttribute!="function"||typeof i.setAttribute!="function"||typeof i.namespaceURI!="string"||typeof i.insertBefore!="function"||typeof i.hasChildNodes!="function"||i.nodeType!==Re(i)||i.childNodes!==ye(i)},ne=function(i){if(!Re||typeof i!="object"||i===null)return!1;try{return Re(i)===xn.documentFragment}catch{return!1}},ke=function(i){if(!Re||typeof i!="object"||i===null)return!1;try{return typeof Re(i)=="number"}catch{return!1}};function nt(A,i,b){A.length!==0&&cr(A,M=>{M.call(e,i,b,te)})}const De=function(i,b){return!!(Le&&i.hasChildNodes()&&!ke(i.firstElementChild)&&jt(da,i.textContent)&&jt(da,i.innerHTML)||Le&&i.namespaceURI===w&&b==="style"&&ke(i.firstElementChild)||i.nodeType===xn.processingInstruction||Le&&i.nodeType===xn.comment&&jt(bl,i.data))},tt=function(i,b){if(!re[b]&&Qt(b)&&(q.tagNameCheck instanceof RegExp&&jt(q.tagNameCheck,b)||q.tagNameCheck instanceof Function&&q.tagNameCheck(b)))return!1;if(Xt&&!gt[b]){const M=fe(i),X=ye(i);if(X&&M){const Pe=X.length;for(let Ke=Pe-1;Ke>=0;--Ke){const Lt=Kt?X[Ke]:L(X[Ke],!0);M.insertBefore(Lt,ge(i))}}}return U(i),!0},Ut=function(i){if(nt(ze.beforeSanitizeElements,i,null),Ee(i))return U(i),!0;const b=F(Ne?Ne(i):i.nodeName);if(nt(ze.uponSanitizeElement,i,{tagName:b,allowedTags:y}),De(i,b))return U(i),!0;if(re[b]||!(Qe.tagCheck instanceof Function&&Qe.tagCheck(b))&&!y[b])return tt(i,b);if((Re?Re(i):i.nodeType)===xn.element&&!B(i)||(b==="noscript"||b==="noembed"||b==="noframes")&&jt(vl,i.innerHTML))return U(i),!0;if(rt&&i.nodeType===xn.text){const X=J(i.textContent);i.textContent!==X&&(Zn(e.removed,{element:i.cloneNode()}),i.textContent=X)}return nt(ze.afterSanitizeElements,i,null),!1},un=function(i,b,M){if(ee[b]||Ze&&(b==="id"||b==="name")&&(M in r||M in Oe))return!1;const X=R[b]||Qe.attributeCheck instanceof Function&&Qe.attributeCheck(b,i);if(!(ut&&jt(Nt,b))){if(!(He&&jt(ht,b))){if(X){if(!rn[b]){if(!jt(Y,dr(M,Mt,""))){if(!((b==="src"||b==="xlink:href"||b==="href")&&i!=="script"&&na(M,"data:")===0&&an[i])){if(!(bt&&!jt(kt,dr(M,Mt,"")))){if(M)return!1}}}}}else if(!(Qt(i)&&(q.tagNameCheck instanceof RegExp&&jt(q.tagNameCheck,i)||q.tagNameCheck instanceof Function&&q.tagNameCheck(i))&&(q.attributeNameCheck instanceof RegExp&&jt(q.attributeNameCheck,b)||q.attributeNameCheck instanceof Function&&q.attributeNameCheck(b,i))||b==="is"&&q.allowCustomizedBuiltInElements&&(q.tagNameCheck instanceof RegExp&&jt(q.tagNameCheck,M)||q.tagNameCheck instanceof Function&&q.tagNameCheck(M))))return!1}}return!0},gn=Je({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Qt=function(i){return!gn[hr(i)]&&jt(St,i)},Jt=function(i,b,M,X){if(he&&typeof N=="object"&&typeof N.getAttributeType=="function"&&!M)switch(N.getAttributeType(i,b)){case"TrustedHTML":return Fe(X);case"TrustedScriptURL":return dt(X)}return X},fn=function(i,b,M,X){try{M?i.setAttributeNS(M,b,X):i.setAttribute(b,X),Ee(i)?U(i):ea(e.removed)}catch{de(b,i)}},Vn=function(i){nt(ze.beforeSanitizeAttributes,i,null);const b=i.attributes;if(!b||Ee(i))return;const M={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:R,forceKeepAttr:void 0};let X=b.length;const Pe=F(i.nodeName);for(;X--;){const Ke=b[X],Lt=Ke.name,Ct=Ke.namespaceURI,yt=Ke.value,Et=F(Lt),$n=yt;let Gt=Lt==="value"?$n:Xi($n);if(M.attrName=Et,M.attrValue=Gt,M.keepAttr=!0,M.forceKeepAttr=void 0,nt(ze.uponSanitizeAttribute,i,M),Gt=M.attrValue,Pt&&(Et==="id"||Et==="name")&&na(Gt,_t)!==0&&(de(Lt,i),Gt=_t+Gt),Le&&jt(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Gt)){de(Lt,i);continue}if(Et==="attributename"&&ta(Gt,"href")){de(Lt,i);continue}if(!M.forceKeepAttr){if(!M.keepAttr){de(Lt,i);continue}if(!et&&jt(gl,Gt)){de(Lt,i);continue}if(rt&&(Gt=J(Gt)),!un(Pe,Et,Gt)){de(Lt,i);continue}Gt=Jt(Pe,Et,Ct,Gt),Gt!==$n&&fn(i,Lt,Ct,Gt)}}nt(ze.afterSanitizeAttributes,i,null)},mn=function(i){let b=null;const M=P(i);for(nt(ze.beforeSanitizeShadowDOM,i,null);b=M.nextNode();)if(nt(ze.uponSanitizeShadowNode,b,null),Ut(b),Vn(b),ne(b.content)&&mn(b.content),(Re?Re(b):b.nodeType)===xn.element){const Pe=oe(b);ne(Pe)&&(sr(Pe),mn(Pe))}nt(ze.afterSanitizeShadowDOM,i,null)},sr=function(i){const b=[{node:i,shadow:null}];for(;b.length>0;){const M=b.pop();if(M.shadow){mn(M.shadow);continue}const X=M.node,Ke=(Re?Re(X):X.nodeType)===xn.element,Lt=ye(X);if(Lt)for(let Ct=Lt.length-1;Ct>=0;--Ct)b.push({node:Lt[Ct],shadow:null});if(Ke){const Ct=Ne?Ne(X):null;if(typeof Ct=="string"&&F(Ct)==="template"){const yt=X.content;ne(yt)&&b.push({node:yt,shadow:null})}}if(Ke){const Ct=oe(X);ne(Ct)&&b.push({node:null,shadow:Ct},{node:Ct,shadow:null})}}};return e.sanitize=function(A){let i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},b=null,M=null,X=null,Pe=null;if(Q=!A,Q&&(A="<!-->"),typeof A!="string"&&!ke(A)&&(A=nl(A),typeof A!="string"))throw zn("dirty is not a string, aborting");if(!e.isSupported)return A;Wt?(y=Ft,R=At):xe(i),(ze.uponSanitizeElement.length>0||ze.uponSanitizeAttribute.length>0)&&(y=en(y)),ze.uponSanitizeAttribute.length>0&&(R=en(R)),e.removed=[];const Ke=Kt&&typeof A!="string"&&ke(A);if(Ke){const yt=Ne?Ne(A):A.nodeName;if(typeof yt=="string"){const Et=F(yt);if(!y[Et]||re[Et])throw zn("root node is forbidden and cannot be sanitized in-place")}if(Ee(A))throw zn("root node is clobbered and cannot be sanitized in-place");try{sr(A)}catch(Et){throw ce(A),Et}}else if(ke(A))b=G("<!---->"),M=b.ownerDocument.importNode(A,!0),M.nodeType===xn.element&&M.nodeName==="BODY"||M.nodeName==="HTML"?b=M:b.appendChild(M),sr(M);else{if(!xt&&!rt&&!Be&&A.indexOf("<")===-1)return he&&Ce?Fe(A):A;if(b=G(A),!b)return xt?null:Ce?$e:""}b&&mt&&U(b.firstChild);const Lt=P(Ke?A:b);try{for(;X=Lt.nextNode();)Ut(X),Vn(X),ne(X.content)&&mn(X.content)}catch(yt){throw Ke&&ce(A),yt}if(Ke)return cr(e.removed,yt=>{yt.element&&ae(yt.element)}),rt&&_e(A),A;if(xt){if(rt&&_e(b),Zt)for(Pe=Te.call(b.ownerDocument);b.firstChild;)Pe.appendChild(b.firstChild);else Pe=b;return(R.shadowroot||R.shadowrootmode)&&(Pe=Xe.call(s,Pe,!0)),Pe}let Ct=Be?b.outerHTML:b.innerHTML;return Be&&y["!doctype"]&&b.ownerDocument&&b.ownerDocument.doctype&&b.ownerDocument.doctype.name&&jt(pl,b.ownerDocument.doctype.name)&&(Ct="<!DOCTYPE "+b.ownerDocument.doctype.name+`>
65
- `+Ct),rt&&(Ct=J(Ct)),he&&Ce?Fe(Ct):Ct},e.setConfig=function(){let A=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};xe(A),Wt=!0,Ft=y,At=R},e.clearConfig=function(){te=null,Wt=!1,Ft=null,At=null,he=ot,$e=""},e.isValidAttribute=function(A,i,b){te||xe({});const M=F(A),X=F(i);return un(M,X,b)},e.addHook=function(A,i){typeof i=="function"&&zt(ze,A)&&Zn(ze[A],i)},e.removeHook=function(A,i){if(zt(ze,A)){if(i!==void 0){const b=Zi(ze[A],i);return b===-1?void 0:Ki(ze[A],b,1)[0]}return ea(ze[A])}},e.removeHooks=function(A){zt(ze,A)&&(ze[A]=[])},e.removeAllHooks=function(){ze=ua()},e}var to=eo();lt.setOptions({gfm:!0,breaks:!0});let fa=!1;function _l(){fa||typeof window>"u"||(fa=!0,to.addHook("afterSanitizeAttributes",n=>{n.tagName==="A"&&(n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer"))}))}function yl(n){if(!n)return"";const e=lt.parse(n,{async:!1});return typeof window>"u"?"":(_l(),to.sanitize(e,{ADD_ATTR:["target","rel"]}))}var wl=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>'),kl=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>'),Sl=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
62
+ `+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 "'+l.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 a=0;a<e.length;a++){const o=e[a];if(this.options.extensions?.renderers?.[o.type]){const c=this.options.extensions.renderers[o.type].call({parser:this},o);if(c!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(o.type)){s+=c||"";continue}}const l=o;switch(l.type){case"escape":{s+=r.text(l);break}case"html":{s+=r.html(l);break}case"link":{s+=r.link(l);break}case"image":{s+=r.image(l);break}case"strong":{s+=r.strong(l);break}case"em":{s+=r.em(l);break}case"codespan":{s+=r.codespan(l);break}case"br":{s+=r.br(l);break}case"del":{s+=r.del(l);break}case"text":{s+=r.text(l);break}default:{const c='Token with "'+l.type+'" type was not found.';if(this.options.silent)return console.error(c),"";throw new Error(c)}}}return s}},Cr=class{options;block;constructor(n){this.options=n||qn}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(n){return n}postprocess(n){return n}processAllTokens(n){return n}provideLexer(){return this.block?Sn.lex:Sn.lexInline}provideParser(){return this.block?Tn.parse:Tn.parseInline}},zi=class{defaults=Is();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Tn;Renderer=Dr;TextRenderer=Fs;Lexer=Sn;Tokenizer=Or;Hooks=Cr;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 a=s;for(const o of a.header)r=r.concat(this.walkTokens(o.tokens,e));for(const o of a.rows)for(const l of o)r=r.concat(this.walkTokens(l.tokens,e));break}case"list":{const a=s;r=r.concat(this.walkTokens(a.items,e));break}default:{const a=s;this.defaults.extensions?.childTokens?.[a.type]?this.defaults.extensions.childTokens[a.type].forEach(o=>{const l=a[o].flat(1/0);r=r.concat(this.walkTokens(l,e))}):a.tokens&&(r=r.concat(this.walkTokens(a.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(a=>{if(!a.name)throw new Error("extension name required");if("renderer"in a){const o=e.renderers[a.name];o?e.renderers[a.name]=function(...l){let c=a.renderer.apply(this,l);return c===!1&&(c=o.apply(this,l)),c}:e.renderers[a.name]=a.renderer}if("tokenizer"in a){if(!a.level||a.level!=="block"&&a.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const o=e[a.level];o?o.unshift(a.tokenizer):e[a.level]=[a.tokenizer],a.start&&(a.level==="block"?e.startBlock?e.startBlock.push(a.start):e.startBlock=[a.start]:a.level==="inline"&&(e.startInline?e.startInline.push(a.start):e.startInline=[a.start]))}"childTokens"in a&&a.childTokens&&(e.childTokens[a.name]=a.childTokens)}),s.extensions=e),r.renderer){const a=this.defaults.renderer||new Dr(this.defaults);for(const o in r.renderer){if(!(o in a))throw new Error(`renderer '${o}' does not exist`);if(["options","parser"].includes(o))continue;const l=o,c=r.renderer[l],_=a[l];a[l]=(...g)=>{let I=c.apply(a,g);return I===!1&&(I=_.apply(a,g)),I||""}}s.renderer=a}if(r.tokenizer){const a=this.defaults.tokenizer||new Or(this.defaults);for(const o in r.tokenizer){if(!(o in a))throw new Error(`tokenizer '${o}' does not exist`);if(["options","rules","lexer"].includes(o))continue;const l=o,c=r.tokenizer[l],_=a[l];a[l]=(...g)=>{let I=c.apply(a,g);return I===!1&&(I=_.apply(a,g)),I}}s.tokenizer=a}if(r.hooks){const a=this.defaults.hooks||new Cr;for(const o in r.hooks){if(!(o in a))throw new Error(`hook '${o}' does not exist`);if(["options","block"].includes(o))continue;const l=o,c=r.hooks[l],_=a[l];Cr.passThroughHooks.has(o)?a[l]=g=>{if(this.defaults.async)return Promise.resolve(c.call(a,g)).then(N=>_.call(a,N));const I=c.call(a,g);return _.call(a,I)}:a[l]=(...g)=>{let I=c.apply(a,g);return I===!1&&(I=_.apply(a,g)),I}}s.hooks=a}if(r.walkTokens){const a=this.defaults.walkTokens,o=r.walkTokens;s.walkTokens=function(l){let c=[];return c.push(o.call(this,l)),a&&(c=c.concat(a.call(this,l))),c}}this.defaults={...this.defaults,...s}}),this}setOptions(n){return this.defaults={...this.defaults,...n},this}lexer(n,e){return Sn.lex(n,e??this.defaults)}parser(n,e){return Tn.parse(n,e??this.defaults)}parseMarkdown(n){return(r,s)=>{const a={...s},o={...this.defaults,...a},l=this.onError(!!o.silent,!!o.async);if(this.defaults.async===!0&&a.async===!1)return l(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 l(new Error("marked(): input parameter is undefined or null"));if(typeof r!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(r)+", string expected"));o.hooks&&(o.hooks.options=o,o.hooks.block=n);const c=o.hooks?o.hooks.provideLexer():n?Sn.lex:Sn.lexInline,_=o.hooks?o.hooks.provideParser():n?Tn.parse:Tn.parseInline;if(o.async)return Promise.resolve(o.hooks?o.hooks.preprocess(r):r).then(g=>c(g,o)).then(g=>o.hooks?o.hooks.processAllTokens(g):g).then(g=>o.walkTokens?Promise.all(this.walkTokens(g,o.walkTokens)).then(()=>g):g).then(g=>_(g,o)).then(g=>o.hooks?o.hooks.postprocess(g):g).catch(l);try{o.hooks&&(r=o.hooks.preprocess(r));let g=c(r,o);o.hooks&&(g=o.hooks.processAllTokens(g)),o.walkTokens&&this.walkTokens(g,o.walkTokens);let I=_(g,o);return o.hooks&&(I=o.hooks.postprocess(I)),I}catch(g){return l(g)}}}onError(n,e){return r=>{if(r.message+=`
63
+ Please report this to https://github.com/markedjs/marked.`,n){const s="<p>An error occurred:</p><pre>"+_n(r.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(r);throw r}}},Wn=new zi;function lt(n,e){return Wn.parse(n,e)}lt.options=lt.setOptions=function(n){return Wn.setOptions(n),lt.defaults=Wn.defaults,Ha(lt.defaults),lt};lt.getDefaults=Is;lt.defaults=qn;lt.use=function(...n){return Wn.use(...n),lt.defaults=Wn.defaults,Ha(lt.defaults),lt};lt.walkTokens=function(n,e){return Wn.walkTokens(n,e)};lt.parseInline=Wn.parseInline;lt.Parser=Tn;lt.parser=Tn.parse;lt.Renderer=Dr;lt.TextRenderer=Fs;lt.Lexer=Sn;lt.lexer=Sn.lex;lt.Tokenizer=Or;lt.Hooks=Cr;lt.parse=lt;lt.options;lt.setOptions;lt.use;lt.walkTokens;lt.parseInline;Tn.parse;Sn.lex;function Qs(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 Hi(n){if(Array.isArray(n))return n}function Bi(n,e){var r=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(r!=null){var s,a,o,l,c=[],_=!0,g=!1;try{if(o=(r=r.call(n)).next,e!==0)for(;!(_=(s=o.call(r)).done)&&(c.push(s.value),c.length!==e);_=!0);}catch(I){g=!0,a=I}finally{try{if(!_&&r.return!=null&&(l=r.return(),Object(l)!==l))return}finally{if(g)throw a}}return c}}function Wi(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
64
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Gi(n,e){return Hi(n)||Bi(n,e)||ji(n,e)||Wi()}function ji(n,e){if(n){if(typeof n=="string")return Qs(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)?Qs(n,e):void 0}}const Qa=Object.entries,Js=Object.setPrototypeOf,qi=Object.isFrozen,Vi=Object.getPrototypeOf,Yi=Object.getOwnPropertyDescriptor;let Vt=Object.freeze,Yt=Object.seal,Xn=Object.create,Ja=typeof Reflect<"u"&&Reflect,hs=Ja.apply,bs=Ja.construct;Vt||(Vt=function(e){return e});Yt||(Yt=function(e){return e});hs||(hs=function(e,r){for(var s=arguments.length,a=new Array(s>2?s-2:0),o=2;o<s;o++)a[o-2]=arguments[o];return e.apply(r,a)});bs||(bs=function(e){for(var r=arguments.length,s=new Array(r>1?r-1:0),a=1;a<r;a++)s[a-1]=arguments[a];return new e(...s)});const cr=Ot(Array.prototype.forEach),Zi=Ot(Array.prototype.lastIndexOf),ea=Ot(Array.prototype.pop),Zn=Ot(Array.prototype.push),Ki=Ot(Array.prototype.splice),Dn=Array.isArray,hr=Ot(String.prototype.toLowerCase),Vr=Ot(String.prototype.toString),ta=Ot(String.prototype.match),dr=Ot(String.prototype.replace),na=Ot(String.prototype.indexOf),Xi=Ot(String.prototype.trim),Qi=Ot(Number.prototype.toString),Ji=Ot(Boolean.prototype.toString),ra=typeof BigInt>"u"?null:Ot(BigInt.prototype.toString),sa=typeof Symbol>"u"?null:Ot(Symbol.prototype.toString),zt=Ot(Object.prototype.hasOwnProperty),ur=Ot(Object.prototype.toString),jt=Ot(RegExp.prototype.test),zn=el(TypeError);function Ot(n){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var r=arguments.length,s=new Array(r>1?r-1:0),a=1;a<r;a++)s[a-1]=arguments[a];return hs(n,e,s)}}function el(n){return function(){for(var e=arguments.length,r=new Array(e),s=0;s<e;s++)r[s]=arguments[s];return bs(n,r)}}function Je(n,e){let r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:hr;if(Js&&Js(n,null),!Dn(e))return n;let s=e.length;for(;s--;){let a=e[s];if(typeof a=="string"){const o=r(a);o!==a&&(qi(e)||(e[s]=o),a=o)}n[a]=!0}return n}function tl(n){for(let e=0;e<n.length;e++)zt(n,e)||(n[e]=null);return n}function en(n){const e=Xn(null);for(const s of Qa(n)){var r=Gi(s,2);const a=r[0],o=r[1];zt(n,a)&&(Dn(o)?e[a]=tl(o):o&&typeof o=="object"&&o.constructor===Object?e[a]=en(o):e[a]=o)}return e}function nl(n){switch(typeof n){case"string":return n;case"number":return Qi(n);case"boolean":return Ji(n);case"bigint":return ra?ra(n):"0";case"symbol":return sa?sa(n):"Symbol()";case"undefined":return ur(n);case"function":case"object":{if(n===null)return ur(n);const e=n,r=yn(e,"toString");if(typeof r=="function"){const s=r(e);return typeof s=="string"?s:ur(s)}return ur(n)}default:return ur(n)}}function yn(n,e){for(;n!==null;){const s=Yi(n,e);if(s){if(s.get)return Ot(s.get);if(typeof s.value=="function")return Ot(s.value)}n=Vi(n)}function r(){return null}return r}function rl(n){try{return jt(n,""),!0}catch{return!1}}const aa=Vt(["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"]),Yr=Vt(["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"]),Zr=Vt(["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"]),sl=Vt(["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"]),Kr=Vt(["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"]),al=Vt(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),oa=Vt(["#text"]),ia=Vt(["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"]),Xr=Vt(["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"]),la=Vt(["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"]),Er=Vt(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),ol=Yt(/{{[\w\W]*|^[\w\W]*}}/g),il=Yt(/<%[\w\W]*|^[\w\W]*%>/g),ll=Yt(/\${[\w\W]*/g),cl=Yt(/^data-[\-\w.\u00B7-\uFFFF]+$/),dl=Yt(/^aria-[\-\w]+$/),ca=Yt(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ul=Yt(/^(?:\w+script|data):/i),fl=Yt(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),pl=Yt(/^html$/i),hl=Yt(/^[a-z][.\w]*(-[.\w]+)+$/i),da=Yt(/<[/\w!]/g),bl=Yt(/<[/\w]/g),gl=Yt(/<\/no(script|embed|frames)/i),vl=Yt(/\/>/i),xn={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},ml=function(){return typeof window>"u"?null:window},xl=function(e,r){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let s=null;const a="data-tt-policy-suffix";r&&r.hasAttribute(a)&&(s=r.getAttribute(a));const o="dompurify"+(s?"#"+s:"");try{return e.createPolicy(o,{createHTML(l){return l},createScriptURL(l){return l}})}catch{return console.warn("TrustedTypes policy "+o+" could not be created."),null}},ua=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Mn=function(e,r,s,a){return zt(e,r)&&Dn(e[r])?Je(a.base?en(a.base):{},e[r],a.transform):s};function eo(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:ml();const e=A=>eo(A);if(e.version="3.4.11",e.removed=[],!n||!n.document||n.document.nodeType!==xn.document||!n.Element)return e.isSupported=!1,e;let r=n.document;const s=r,a=s.currentScript;n.DocumentFragment;const o=n.HTMLTemplateElement,l=n.Node,c=n.Element,_=n.NodeFilter,g=n.NamedNodeMap;g===void 0&&(n.NamedNodeMap||n.MozNamedAttrMap),n.HTMLFormElement;const I=n.DOMParser,N=n.trustedTypes,$=c.prototype,L=yn($,"cloneNode"),S=yn($,"remove"),ve=yn($,"nextSibling"),ye=yn($,"childNodes"),fe=yn($,"parentNode"),oe=yn($,"shadowRoot"),Ie=yn($,"attributes"),Re=l&&l.prototype?yn(l.prototype,"nodeType"):null,Fe=l&&l.prototype?yn(l.prototype,"nodeName"):null;if(typeof o=="function"){const A=r.createElement("template");A.content&&A.content.ownerDocument&&(r=A.content.ownerDocument)}let he,$e="",ot,me=!1,Ue=0;const Me=function(){if(Ue>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.')},Le=function(i){Me(),Ue++;try{return he.createHTML(i)}finally{Ue--}},dt=function(i){Me(),Ue++;try{return he.createScriptURL(i)}finally{Ue--}},ft=function(){return me||(ot=xl(N,a),me=!0),ot},pt=r,be=pt.implementation,Se=pt.createNodeIterator,Te=pt.createDocumentFragment,Dt=pt.getElementsByTagName,Xe=s.importNode;let ze=ua();e.isSupported=typeof Qa=="function"&&typeof fe=="function"&&be&&be.createHTMLDocument!==void 0;const nn=ol,Ve=il,Tt=ll,Nt=cl,ht=dl,kt=ul,Mt=fl,St=hl;let Y=ca,y=null;const z=Je({},[...aa,...Yr,...Zr,...Kr,...oa]);let R=null;const Z=Je({},[...ia,...Xr,...la,...Er]);let q=Object.seal(Xn(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}})),re=null,ee=null;const Qe=Object.seal(Xn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let He=!0,ut=!0,bt=!1,et=!0,rt=!1,Oe=!0,Be=!1,Wt=!1,Ft=null,At=null,mt=!1,xt=!1,Zt=!1,Ce=!1,Ze=!0,Pt=!1;const _t="user-content-";let Xt=!0,Kt=!1,gt={},vt=null;const ln=Je({},["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 an=null;const cn=Je({},["audio","video","img","source","image","track"]);let rn=null;const dn=Je({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),E="http://www.w3.org/1998/Math/MathML",x="http://www.w3.org/2000/svg",w="http://www.w3.org/1999/xhtml";let O=w,Q=!1,We=null;const we=Je({},[E,x,w],Vr),ie=Vt(["mi","mo","mn","ms","mtext"]);let v=Je({},ie);const k=Vt(["annotation-xml"]);let H=Je({},k);const D=Je({},["title","style","font","a","script"]);let le=null;const K=["application/xhtml+xml","text/html"],T="text/html";let F=null,te=null;const De=r.createElement("form"),Ae=function(i){return i instanceof RegExp||i instanceof Function},xe=function(){let i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(te&&te===i)return;(!i||typeof i!="object")&&(i={}),i=en(i),le=K.indexOf(i.PARSER_MEDIA_TYPE)===-1?T:i.PARSER_MEDIA_TYPE,F=le==="application/xhtml+xml"?Vr:hr,y=Mn(i,"ALLOWED_TAGS",z,{transform:F}),R=Mn(i,"ALLOWED_ATTR",Z,{transform:F}),We=Mn(i,"ALLOWED_NAMESPACES",we,{transform:Vr}),rn=Mn(i,"ADD_URI_SAFE_ATTR",dn,{transform:F,base:dn}),an=Mn(i,"ADD_DATA_URI_TAGS",cn,{transform:F,base:cn}),vt=Mn(i,"FORBID_CONTENTS",ln,{transform:F}),re=Mn(i,"FORBID_TAGS",en({}),{transform:F}),ee=Mn(i,"FORBID_ATTR",en({}),{transform:F}),gt=zt(i,"USE_PROFILES")?i.USE_PROFILES&&typeof i.USE_PROFILES=="object"?en(i.USE_PROFILES):i.USE_PROFILES:!1,He=i.ALLOW_ARIA_ATTR!==!1,ut=i.ALLOW_DATA_ATTR!==!1,bt=i.ALLOW_UNKNOWN_PROTOCOLS||!1,et=i.ALLOW_SELF_CLOSE_IN_ATTR!==!1,rt=i.SAFE_FOR_TEMPLATES||!1,Oe=i.SAFE_FOR_XML!==!1,Be=i.WHOLE_DOCUMENT||!1,xt=i.RETURN_DOM||!1,Zt=i.RETURN_DOM_FRAGMENT||!1,Ce=i.RETURN_TRUSTED_TYPE||!1,mt=i.FORCE_BODY||!1,Ze=i.SANITIZE_DOM!==!1,Pt=i.SANITIZE_NAMED_PROPS||!1,Xt=i.KEEP_CONTENT!==!1,Kt=i.IN_PLACE||!1,Y=rl(i.ALLOWED_URI_REGEXP)?i.ALLOWED_URI_REGEXP:ca,O=typeof i.NAMESPACE=="string"?i.NAMESPACE:w,v=zt(i,"MATHML_TEXT_INTEGRATION_POINTS")&&i.MATHML_TEXT_INTEGRATION_POINTS&&typeof i.MATHML_TEXT_INTEGRATION_POINTS=="object"?en(i.MATHML_TEXT_INTEGRATION_POINTS):Je({},ie),H=zt(i,"HTML_INTEGRATION_POINTS")&&i.HTML_INTEGRATION_POINTS&&typeof i.HTML_INTEGRATION_POINTS=="object"?en(i.HTML_INTEGRATION_POINTS):Je({},k);const b=zt(i,"CUSTOM_ELEMENT_HANDLING")&&i.CUSTOM_ELEMENT_HANDLING&&typeof i.CUSTOM_ELEMENT_HANDLING=="object"?en(i.CUSTOM_ELEMENT_HANDLING):Xn(null);if(q=Xn(null),zt(b,"tagNameCheck")&&Ae(b.tagNameCheck)&&(q.tagNameCheck=b.tagNameCheck),zt(b,"attributeNameCheck")&&Ae(b.attributeNameCheck)&&(q.attributeNameCheck=b.attributeNameCheck),zt(b,"allowCustomizedBuiltInElements")&&typeof b.allowCustomizedBuiltInElements=="boolean"&&(q.allowCustomizedBuiltInElements=b.allowCustomizedBuiltInElements),Yt(q),rt&&(ut=!1),Zt&&(xt=!0),gt&&(y=Je({},oa),R=Xn(null),gt.html===!0&&(Je(y,aa),Je(R,ia)),gt.svg===!0&&(Je(y,Yr),Je(R,Xr),Je(R,Er)),gt.svgFilters===!0&&(Je(y,Zr),Je(R,Xr),Je(R,Er)),gt.mathMl===!0&&(Je(y,Kr),Je(R,la),Je(R,Er))),Qe.tagCheck=null,Qe.attributeCheck=null,zt(i,"ADD_TAGS")&&(typeof i.ADD_TAGS=="function"?Qe.tagCheck=i.ADD_TAGS:Dn(i.ADD_TAGS)&&(y===z&&(y=en(y)),Je(y,i.ADD_TAGS,F))),zt(i,"ADD_ATTR")&&(typeof i.ADD_ATTR=="function"?Qe.attributeCheck=i.ADD_ATTR:Dn(i.ADD_ATTR)&&(R===Z&&(R=en(R)),Je(R,i.ADD_ATTR,F))),zt(i,"ADD_URI_SAFE_ATTR")&&Dn(i.ADD_URI_SAFE_ATTR)&&Je(rn,i.ADD_URI_SAFE_ATTR,F),zt(i,"FORBID_CONTENTS")&&Dn(i.FORBID_CONTENTS)&&(vt===ln&&(vt=en(vt)),Je(vt,i.FORBID_CONTENTS,F)),zt(i,"ADD_FORBID_CONTENTS")&&Dn(i.ADD_FORBID_CONTENTS)&&(vt===ln&&(vt=en(vt)),Je(vt,i.ADD_FORBID_CONTENTS,F)),Xt&&(y["#text"]=!0),Be&&Je(y,["html","head","body"]),y.table&&(Je(y,["tbody"]),delete re.tbody),i.TRUSTED_TYPES_POLICY){if(typeof i.TRUSTED_TYPES_POLICY.createHTML!="function")throw zn('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof i.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw zn('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const M=he;he=i.TRUSTED_TYPES_POLICY;try{$e=Le("")}catch(X){throw he=M,X}}else i.TRUSTED_TYPES_POLICY===null?(he=void 0,$e=""):(he===void 0&&(he=ft()),he&&typeof $e=="string"&&($e=Le("")));Vt&&Vt(i),te=i},st=Je({},[...Yr,...Zr,...sl]),It=Je({},[...Kr,...al]),Ge=function(i,b,M){return b.namespaceURI===w?i==="svg":b.namespaceURI===E?i==="svg"&&(M==="annotation-xml"||v[M]):!!st[i]},Ye=function(i,b,M){return b.namespaceURI===w?i==="math":b.namespaceURI===x?i==="math"&&H[M]:!!It[i]},pe=function(i,b,M){return b.namespaceURI===x&&!H[M]||b.namespaceURI===E&&!v[M]?!1:!It[i]&&(D[i]||!st[i])},B=function(i){let b=fe(i);(!b||!b.tagName)&&(b={namespaceURI:O,tagName:"template"});const M=hr(i.tagName),X=hr(b.tagName);return We[i.namespaceURI]?i.namespaceURI===x?Ge(M,b,X):i.namespaceURI===E?Ye(M,b,X):i.namespaceURI===w?pe(M,b,X):!!(le==="application/xhtml+xml"&&We[i.namespaceURI]):!1},U=function(i){Zn(e.removed,{element:i});try{fe(i).removeChild(i)}catch{if(S(i),!fe(i))throw zn("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},ce=function(i){const b=ye(i);if(b){const X=[];cr(b,Ne=>{Zn(X,Ne)}),cr(X,Ne=>{try{S(Ne)}catch{}})}const M=Ie(i);if(M)for(let X=M.length-1;X>=0;--X){const Ne=M[X],Ke=Ne&&Ne.name;if(typeof Ke=="string")try{i.removeAttribute(Ke)}catch{}}},de=function(i,b){try{Zn(e.removed,{attribute:b.getAttributeNode(i),from:b})}catch{Zn(e.removed,{attribute:null,from:b})}if(b.removeAttribute(i),i==="is")if(xt||Zt)try{U(b)}catch{}else try{b.setAttribute(i,"")}catch{}},ge=function(i){const b=Ie(i);if(b)for(let M=b.length-1;M>=0;--M){const X=b[M],Ne=X&&X.name;if(!(typeof Ne!="string"||R[F(Ne)]))try{i.removeAttribute(Ne)}catch{}}},ae=function(i){const b=[i];for(;b.length>0;){const M=b.pop();(Re?Re(M):M.nodeType)===xn.element&&ge(M);const Ne=ye(M);if(Ne)for(let Ke=Ne.length-1;Ke>=0;--Ke)b.push(Ne[Ke])}},G=function(i){let b=null,M=null;if(mt)i="<remove></remove>"+i;else{const Ke=ta(i,/^[\r\n\t ]+/);M=Ke&&Ke[0]}le==="application/xhtml+xml"&&O===w&&(i='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+i+"</body></html>");const X=he?Le(i):i;if(O===w)try{b=new I().parseFromString(X,le)}catch{}if(!b||!b.documentElement){b=be.createDocument(O,"template",null);try{b.documentElement.innerHTML=Q?$e:X}catch{}}const Ne=b.body||b.documentElement;return i&&M&&Ne.insertBefore(r.createTextNode(M),Ne.childNodes[0]||null),O===w?Dt.call(b,Be?"html":"body")[0]:Be?b.documentElement:Ne},P=function(i){return Se.call(i.ownerDocument||i,i,_.SHOW_ELEMENT|_.SHOW_COMMENT|_.SHOW_TEXT|_.SHOW_PROCESSING_INSTRUCTION|_.SHOW_CDATA_SECTION,null)},J=function(i){return i=dr(i,nn," "),i=dr(i,Ve," "),i=dr(i,Tt," "),i},_e=function(i){var b;i.normalize();const M=Se.call(i.ownerDocument||i,i,_.SHOW_TEXT|_.SHOW_COMMENT|_.SHOW_CDATA_SECTION|_.SHOW_PROCESSING_INSTRUCTION,null);let X=M.nextNode();for(;X;)X.data=J(X.data),X=M.nextNode();const Ne=(b=i.querySelectorAll)===null||b===void 0?void 0:b.call(i,"template");Ne&&cr(Ne,Ke=>{ne(Ke.content)&&_e(Ke.content)})},Ee=function(i){const b=Fe?Fe(i):null;return typeof b!="string"||F(b)!=="form"?!1:typeof i.nodeName!="string"||typeof i.textContent!="string"||typeof i.removeChild!="function"||i.attributes!==Ie(i)||typeof i.removeAttribute!="function"||typeof i.setAttribute!="function"||typeof i.namespaceURI!="string"||typeof i.insertBefore!="function"||typeof i.hasChildNodes!="function"||i.nodeType!==Re(i)||i.childNodes!==ye(i)},ne=function(i){if(!Re||typeof i!="object"||i===null)return!1;try{return Re(i)===xn.documentFragment}catch{return!1}},ke=function(i){if(!Re||typeof i!="object"||i===null)return!1;try{return typeof Re(i)=="number"}catch{return!1}};function nt(A,i,b){A.length!==0&&cr(A,M=>{M.call(e,i,b,te)})}const Pe=function(i,b){return!!(Oe&&i.hasChildNodes()&&!ke(i.firstElementChild)&&jt(da,i.textContent)&&jt(da,i.innerHTML)||Oe&&i.namespaceURI===w&&b==="style"&&ke(i.firstElementChild)||i.nodeType===xn.processingInstruction||Oe&&i.nodeType===xn.comment&&jt(bl,i.data))},tt=function(i,b){if(!re[b]&&Qt(b)&&(q.tagNameCheck instanceof RegExp&&jt(q.tagNameCheck,b)||q.tagNameCheck instanceof Function&&q.tagNameCheck(b)))return!1;if(Xt&&!vt[b]){const M=fe(i),X=ye(i);if(X&&M){const Ne=X.length;for(let Ke=Ne-1;Ke>=0;--Ke){const Lt=Kt?X[Ke]:L(X[Ke],!0);M.insertBefore(Lt,ve(i))}}}return U(i),!0},Ut=function(i){if(nt(ze.beforeSanitizeElements,i,null),Ee(i))return U(i),!0;const b=F(Fe?Fe(i):i.nodeName);if(nt(ze.uponSanitizeElement,i,{tagName:b,allowedTags:y}),Pe(i,b))return U(i),!0;if(re[b]||!(Qe.tagCheck instanceof Function&&Qe.tagCheck(b))&&!y[b])return tt(i,b);if((Re?Re(i):i.nodeType)===xn.element&&!B(i)||(b==="noscript"||b==="noembed"||b==="noframes")&&jt(gl,i.innerHTML))return U(i),!0;if(rt&&i.nodeType===xn.text){const X=J(i.textContent);i.textContent!==X&&(Zn(e.removed,{element:i.cloneNode()}),i.textContent=X)}return nt(ze.afterSanitizeElements,i,null),!1},un=function(i,b,M){if(ee[b]||Ze&&(b==="id"||b==="name")&&(M in r||M in De))return!1;const X=R[b]||Qe.attributeCheck instanceof Function&&Qe.attributeCheck(b,i);if(!(ut&&jt(Nt,b))){if(!(He&&jt(ht,b))){if(X){if(!rn[b]){if(!jt(Y,dr(M,Mt,""))){if(!((b==="src"||b==="xlink:href"||b==="href")&&i!=="script"&&na(M,"data:")===0&&an[i])){if(!(bt&&!jt(kt,dr(M,Mt,"")))){if(M)return!1}}}}}else if(!(Qt(i)&&(q.tagNameCheck instanceof RegExp&&jt(q.tagNameCheck,i)||q.tagNameCheck instanceof Function&&q.tagNameCheck(i))&&(q.attributeNameCheck instanceof RegExp&&jt(q.attributeNameCheck,b)||q.attributeNameCheck instanceof Function&&q.attributeNameCheck(b,i))||b==="is"&&q.allowCustomizedBuiltInElements&&(q.tagNameCheck instanceof RegExp&&jt(q.tagNameCheck,M)||q.tagNameCheck instanceof Function&&q.tagNameCheck(M))))return!1}}return!0},vn=Je({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Qt=function(i){return!vn[hr(i)]&&jt(St,i)},Jt=function(i,b,M,X){if(he&&typeof N=="object"&&typeof N.getAttributeType=="function"&&!M)switch(N.getAttributeType(i,b)){case"TrustedHTML":return Le(X);case"TrustedScriptURL":return dt(X)}return X},fn=function(i,b,M,X){try{M?i.setAttributeNS(M,b,X):i.setAttribute(b,X),Ee(i)?U(i):ea(e.removed)}catch{de(b,i)}},Vn=function(i){nt(ze.beforeSanitizeAttributes,i,null);const b=i.attributes;if(!b||Ee(i))return;const M={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:R,forceKeepAttr:void 0};let X=b.length;const Ne=F(i.nodeName);for(;X--;){const Ke=b[X],Lt=Ke.name,Ct=Ke.namespaceURI,yt=Ke.value,Et=F(Lt),$n=yt;let Gt=Lt==="value"?$n:Xi($n);if(M.attrName=Et,M.attrValue=Gt,M.keepAttr=!0,M.forceKeepAttr=void 0,nt(ze.uponSanitizeAttribute,i,M),Gt=M.attrValue,Pt&&(Et==="id"||Et==="name")&&na(Gt,_t)!==0&&(de(Lt,i),Gt=_t+Gt),Oe&&jt(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Gt)){de(Lt,i);continue}if(Et==="attributename"&&ta(Gt,"href")){de(Lt,i);continue}if(!M.forceKeepAttr){if(!M.keepAttr){de(Lt,i);continue}if(!et&&jt(vl,Gt)){de(Lt,i);continue}if(rt&&(Gt=J(Gt)),!un(Ne,Et,Gt)){de(Lt,i);continue}Gt=Jt(Ne,Et,Ct,Gt),Gt!==$n&&fn(i,Lt,Ct,Gt)}}nt(ze.afterSanitizeAttributes,i,null)},mn=function(i){let b=null;const M=P(i);for(nt(ze.beforeSanitizeShadowDOM,i,null);b=M.nextNode();)if(nt(ze.uponSanitizeShadowNode,b,null),Ut(b),Vn(b),ne(b.content)&&mn(b.content),(Re?Re(b):b.nodeType)===xn.element){const Ne=oe(b);ne(Ne)&&(sr(Ne),mn(Ne))}nt(ze.afterSanitizeShadowDOM,i,null)},sr=function(i){const b=[{node:i,shadow:null}];for(;b.length>0;){const M=b.pop();if(M.shadow){mn(M.shadow);continue}const X=M.node,Ke=(Re?Re(X):X.nodeType)===xn.element,Lt=ye(X);if(Lt)for(let Ct=Lt.length-1;Ct>=0;--Ct)b.push({node:Lt[Ct],shadow:null});if(Ke){const Ct=Fe?Fe(X):null;if(typeof Ct=="string"&&F(Ct)==="template"){const yt=X.content;ne(yt)&&b.push({node:yt,shadow:null})}}if(Ke){const Ct=oe(X);ne(Ct)&&b.push({node:null,shadow:Ct},{node:Ct,shadow:null})}}};return e.sanitize=function(A){let i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},b=null,M=null,X=null,Ne=null;if(Q=!A,Q&&(A="<!-->"),typeof A!="string"&&!ke(A)&&(A=nl(A),typeof A!="string"))throw zn("dirty is not a string, aborting");if(!e.isSupported)return A;Wt?(y=Ft,R=At):xe(i),(ze.uponSanitizeElement.length>0||ze.uponSanitizeAttribute.length>0)&&(y=en(y)),ze.uponSanitizeAttribute.length>0&&(R=en(R)),e.removed=[];const Ke=Kt&&typeof A!="string"&&ke(A);if(Ke){const yt=Fe?Fe(A):A.nodeName;if(typeof yt=="string"){const Et=F(yt);if(!y[Et]||re[Et])throw zn("root node is forbidden and cannot be sanitized in-place")}if(Ee(A))throw zn("root node is clobbered and cannot be sanitized in-place");try{sr(A)}catch(Et){throw ce(A),Et}}else if(ke(A))b=G("<!---->"),M=b.ownerDocument.importNode(A,!0),M.nodeType===xn.element&&M.nodeName==="BODY"||M.nodeName==="HTML"?b=M:b.appendChild(M),sr(M);else{if(!xt&&!rt&&!Be&&A.indexOf("<")===-1)return he&&Ce?Le(A):A;if(b=G(A),!b)return xt?null:Ce?$e:""}b&&mt&&U(b.firstChild);const Lt=P(Ke?A:b);try{for(;X=Lt.nextNode();)Ut(X),Vn(X),ne(X.content)&&mn(X.content)}catch(yt){throw Ke&&ce(A),yt}if(Ke)return cr(e.removed,yt=>{yt.element&&ae(yt.element)}),rt&&_e(A),A;if(xt){if(rt&&_e(b),Zt)for(Ne=Te.call(b.ownerDocument);b.firstChild;)Ne.appendChild(b.firstChild);else Ne=b;return(R.shadowroot||R.shadowrootmode)&&(Ne=Xe.call(s,Ne,!0)),Ne}let Ct=Be?b.outerHTML:b.innerHTML;return Be&&y["!doctype"]&&b.ownerDocument&&b.ownerDocument.doctype&&b.ownerDocument.doctype.name&&jt(pl,b.ownerDocument.doctype.name)&&(Ct="<!DOCTYPE "+b.ownerDocument.doctype.name+`>
65
+ `+Ct),rt&&(Ct=J(Ct)),he&&Ce?Le(Ct):Ct},e.setConfig=function(){let A=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};xe(A),Wt=!0,Ft=y,At=R},e.clearConfig=function(){te=null,Wt=!1,Ft=null,At=null,he=ot,$e=""},e.isValidAttribute=function(A,i,b){te||xe({});const M=F(A),X=F(i);return un(M,X,b)},e.addHook=function(A,i){typeof i=="function"&&zt(ze,A)&&Zn(ze[A],i)},e.removeHook=function(A,i){if(zt(ze,A)){if(i!==void 0){const b=Zi(ze[A],i);return b===-1?void 0:Ki(ze[A],b,1)[0]}return ea(ze[A])}},e.removeHooks=function(A){zt(ze,A)&&(ze[A]=[])},e.removeAllHooks=function(){ze=ua()},e}var to=eo();lt.setOptions({gfm:!0,breaks:!0});let fa=!1;function _l(){fa||typeof window>"u"||(fa=!0,to.addHook("afterSanitizeAttributes",n=>{n.tagName==="A"&&(n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer"))}))}function yl(n){if(!n)return"";const e=lt.parse(n,{async:!1});return typeof window>"u"?"":(_l(),to.sanitize(e,{ADD_ATTR:["target","rel"]}))}var wl=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>'),kl=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>'),Sl=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
66
66
  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>`),Tl=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>'),Al=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>'),El=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>'),Rl=m('<span class="ml-1 font-medium text-emerald-400">(Git repo detected)</span>'),Cl=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>'),Il=m('<span class="mt-1 block text-[10px] text-brand-text-muted">Relative paths are created inside your home folder.</span>'),$l=m("<option> </option>"),Ml=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>'),Ll=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"/>'),Ol=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>'),Dl=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>'),Pl=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>'),Nl=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
67
- 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>`),Fl=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>'),Ul=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>'),zl=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>'),Hl=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>'),Bl=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>'),Wl=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>'),Gl=m('<div class="flex flex-col gap-1"><!> <div class="font-mono text-sm whitespace-pre-wrap"> </div></div>'),jl=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>'),ql=m('<span class="inline-block animate-spin font-bold text-amber-400">⚡</span>'),Vl=m('<span class="font-bold text-rose-400" title="Failed">❌</span>'),Yl=m('<span class="font-bold text-emerald-400" title="Succeeded">✅</span>'),Zl=m('<span class="max-w-[180px] truncate font-mono text-xs text-brand-text-muted sm:max-w-[300px] md:max-w-[450px]"> </span>'),Kl=m('Collapse <span class="text-[10px]">▲</span>',1),Xl=m('Expand <span class="text-[10px]">▼</span>',1),Ql=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>'),Jl=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>'),ec=m('<div class="animate-pulse p-1 text-xs text-brand-text-muted italic">Running and waiting for output...</div>'),tc=m('<div class="p-1 text-xs text-brand-text-muted italic">No output returned</div>'),nc=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>'),rc=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>'),sc=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>'),ac=m('<div class="chat-selectable markdown-body text-sm leading-relaxed"></div>'),oc=m('<span class="text-brand-text-muted italic"> </span>'),ic=m('<span class="ml-1 inline-block h-4 w-1.5 animate-pulse bg-brand-cyan"></span>'),lc=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>'),cc=m('<div class="mt-2 flex flex-col gap-1 border-t border-brand-blue/20 pt-2"></div>'),dc=m('<div class="text-sm leading-relaxed whitespace-pre-wrap"><!> <!></div> <!>',1),uc=m("<div> </div>"),fc=m("<div><div><!> <!></div></div>"),pc=m('<div class="flex-1 space-y-4 overflow-y-auto overscroll-y-contain p-4"><!> <!></div>'),hc=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>'),bc=m('<span class="ml-1 text-xs text-brand-text-muted">(already a Git repository)</span>'),vc=m('<span class="ml-1 text-xs font-medium text-yellow-500">(folder not empty)</span>'),gc=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>'),mc=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>'),xc=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>'),_c=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> <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 Tools</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 yc(n,e){Fn(e,!0);const r=()=>qe($t,"$piState",N),s=()=>qe(tr,"$availableModels",N),a=()=>qe(xs,"$gitInitDefaultStore",N),o=()=>qe(Sr,"$activeSessionInfo",N),l=()=>qe(Nr,"$isLoadingSession",N),c=()=>qe(La,"$messages",N),_=()=>qe(As,"$isStreaming",N),v=()=>qe(Fa,"$hasMoreHistory",N),I=()=>qe(Ua,"$isLoadingMoreHistory",N),[N,$]=rr(),L=[],S=new Map;function ge(g,k){const H=`${g}:${k.length}`;let D=S.get(H);return D===void 0&&(D=yl(k),S.set(H,D)),D}function ye(g){if(g>=1e6){const k=g/1e6;return(k>=10?Math.round(k).toString():k.toFixed(1))+"M"}return g>=1e3?Math.round(g/1e3)+"K":String(g)}let fe=se(()=>{const g=r().contextUsage;if(!g||!g.contextWindow)return null;const k=ye(g.contextWindow);return g.percent==null?`– / ${k}`:`${g.percent.toFixed(1)}% / ${k}`});function oe(g){if(!g)return{cleanContent:"",attachments:[]};const k=g.split(`
67
+ 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>`),Fl=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>'),Ul=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>'),zl=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>'),Hl=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>'),Bl=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>'),Wl=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>'),Gl=m('<div class="flex flex-col gap-1"><!> <div class="font-mono text-sm whitespace-pre-wrap"> </div></div>'),jl=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>'),ql=m('<span class="inline-block animate-spin font-bold text-amber-400">⚡</span>'),Vl=m('<span class="font-bold text-rose-400" title="Failed">❌</span>'),Yl=m('<span class="font-bold text-emerald-400" title="Succeeded">✅</span>'),Zl=m('<span class="max-w-[180px] truncate font-mono text-xs text-brand-text-muted sm:max-w-[300px] md:max-w-[450px]"> </span>'),Kl=m('Collapse <span class="text-[10px]">▲</span>',1),Xl=m('Expand <span class="text-[10px]">▼</span>',1),Ql=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>'),Jl=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>'),ec=m('<div class="animate-pulse p-1 text-xs text-brand-text-muted italic">Running and waiting for output...</div>'),tc=m('<div class="p-1 text-xs text-brand-text-muted italic">No output returned</div>'),nc=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>'),rc=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>'),sc=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>'),ac=m('<div class="chat-selectable markdown-body text-sm leading-relaxed"></div>'),oc=m('<span class="text-brand-text-muted italic"> </span>'),ic=m('<span class="ml-1 inline-block h-4 w-1.5 animate-pulse bg-brand-cyan"></span>'),lc=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>'),cc=m('<div class="mt-2 flex flex-col gap-1 border-t border-brand-blue/20 pt-2"></div>'),dc=m('<div class="text-sm leading-relaxed whitespace-pre-wrap"><!> <!></div> <!>',1),uc=m("<div> </div>"),fc=m("<div><div><!> <!></div></div>"),pc=m('<div class="flex-1 space-y-4 overflow-y-auto overscroll-y-contain p-4"><!> <!></div>'),hc=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>'),bc=m('<span class="ml-1 text-xs text-brand-text-muted">(already a Git repository)</span>'),gc=m('<span class="ml-1 text-xs font-medium text-yellow-500">(folder not empty)</span>'),vc=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>'),mc=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>'),xc=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>'),_c=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> <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 Tools</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 yc(n,e){Fn(e,!0);const r=()=>qe($t,"$piState",N),s=()=>qe(tr,"$availableModels",N),a=()=>qe(xs,"$gitInitDefaultStore",N),o=()=>qe(Sr,"$activeSessionInfo",N),l=()=>qe(Nr,"$isLoadingSession",N),c=()=>qe(La,"$messages",N),_=()=>qe(As,"$isStreaming",N),g=()=>qe(Fa,"$hasMoreHistory",N),I=()=>qe(Ua,"$isLoadingMoreHistory",N),[N,$]=rr(),L=[],S=new Map;function ve(v,k){const H=`${v}:${k.length}`;let D=S.get(H);return D===void 0&&(D=yl(k),S.set(H,D)),D}function ye(v){if(v>=1e6){const k=v/1e6;return(k>=10?Math.round(k).toString():k.toFixed(1))+"M"}return v>=1e3?Math.round(v/1e3)+"K":String(v)}let fe=se(()=>{const v=r().contextUsage;if(!v||!v.contextWindow)return null;const k=ye(v.contextWindow);return v.percent==null?`– / ${k}`:`${v.percent.toFixed(1)}% / ${k}`});function oe(v){if(!v)return{cleanContent:"",attachments:[]};const k=v.split(`
68
68
  `),H=/^\[Uploaded file: (.+)\]$/,D=[],le=[];for(const T of k){const F=T.match(H);F?le.push(F[1]):D.push(T)}let K=D.join(`
69
- `).trim();return K==="I have uploaded the following file(s) for you:"&&(K=""),{cleanContent:K,attachments:le}}let Ie=V(""),Re=V(wn([])),Ne=V(!1),he=V(null),$e=V(null),ot="",me=V(""),Ue=V(!1),Me=V(null),Fe=V(!0),dt=V("private"),ft=V(!1),pt=se(r),be=se(s),Se=se(a);Rt(()=>{t(Me)===null&&p(Ue,t(Se),!0)});let Te=V(wn({exists:null,isGit:!1,resolvedPath:"",matchingRule:null})),Dt=se(()=>t(Te).exists!==!0&&t(Te).matchingRule&&t(Fe)),Xe=null;async function ze(g,k=!1){if(Xe&&clearTimeout(Xe),g===ot&&!k)return;if(ot=g,!g.trim()){p(Te,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0);const D=async()=>{const le=await Mr("");p(Re,le||[],!0)};k?await D():Xe=setTimeout(D,300);return}const H=async()=>{const[D,le]=await Promise.all([ka(g),Mr(g)]);p(Re,le||[],!0),D?(p(Te,{exists:D.exists,isGit:D.isGit,resolvedPath:D.resolvedPath,matchingRule:D.matchingRule||null},!0),D.exists||(p(Ue,t(Me)!==null?t(Me):t(Se),!0),p(Fe,!0),D.matchingRule&&p(dt,D.matchingRule.visibility,!0))):p(Te,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0)};k?await H():Xe=setTimeout(H,300)}Rt(()=>{const g=t(Ie);ze(g,!1)}),Rt(()=>{if(t(be).models.length>0&&!t(me)){const g=t(be).models.find(k=>k.isDefault);g?p(me,`${g.provider}:${g.modelId}`):p(me,`${t(be).models[0].provider}:${t(be).models[0].modelId}`)}});function nn(){t(Ie).trim()&&(t(Te).exists===!0?(p(Ue,!1),p(Fe,!1),t(Te).matchingRule&&p(dt,t(Te).matchingRule.visibility,!0),p(ft,!0)):kn(t(Ie).trim(),t(me)||void 0,t(Ue),t(Te).matchingRule?t(Fe):void 0,t(Te).matchingRule?t(dt):void 0))}let Ve=V(void 0),Tt=se(o),Nt=se(l),ht=se(()=>!!t(Tt).sessionFile),kt=V(!0),Mt=V(!1),St=wn({});function Y(g,k){St[g]=!k}function y(g){if(!g)return null;const k=g.trim();if(!k)return null;if(k.startsWith("{"))try{return JSON.parse(k)}catch{}const H={},D=/([a-zA-Z0-9_-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|(\S+))/g;let le;for(;(le=D.exec(k))!==null;){const K=le[1],T=le[2]!==void 0?le[2]:le[3]!==void 0?le[3]:le[4];H[K]=T}return Object.keys(H).length>0?H:null}function z(g,k,H){if(!k)return H?H.trim():"";const D=g.toLowerCase();if(["read","write","edit","ls"].includes(D)){const K=k.path||k.filepath||k.file;if(K)return String(K)}if(D==="bash"){const K=k.command||k.cmd;if(K){const T=String(K).replace(/\s+/g," ").trim();return T.length>50?T.slice(0,47)+"...":T}}if(D==="grep"){const K=k.pattern,T=k.path;if(K)return T?`"${K}" in ${T}`:`"${K}"`}if(D==="find"){const K=k.pattern||k.path;if(K)return String(K)}const le=k.path||k.filepath||k.file||k.name||k.query;return le?String(le):Object.entries(k).filter(([K,T])=>T!==void 0&&T!=="").map(([K,T])=>`${K}=${typeof T=="object"?JSON.stringify(T):T}`).join(" ")}function R(g,k){return g?JSON.stringify(g,null,2):k?k.trim():""}function Z(g){let k=g.toolName||"tool",H=g.toolArgs!==void 0?g.toolArgs:"",D=g.toolOutput!==void 0?g.toolOutput:"",le=!!g.isError;if(!H&&!D&&g.content){let te=g.content||"";te.startsWith("Error: ")?(le=!0,te=te.slice(7)):te.startsWith("Tool error: ")&&(le=!0,te=te.slice(12));const Oe=te.indexOf(`
70
- `),Ae=Oe!==-1?te.slice(0,Oe):te;D=Oe!==-1?te.slice(Oe+1):"";let xe=Ae.trim();xe.startsWith("$ ")&&(xe=xe.slice(2));const st=xe.indexOf(" ");k=g.toolName||(st!==-1?xe.slice(0,st):xe)||"tool",H=st!==-1?xe.slice(st+1):""}const K=y(H),T=z(k,K,H),F=R(K,H);return{toolName:k,smartTitleArgs:T,fullArgs:F,toolOutput:D,isError:le}}function q(g){return g.scrollHeight-g.scrollTop-g.clientHeight<=20}function re(){t(Ve)&&p(kt,q(t(Ve)),!0)}function ee(){t(Ve)&&(t(Ve).scrollTop=t(Ve).scrollHeight)}function Qe(){(t(kt)||t(Mt))&&(ee(),p(Mt,!1))}yr(ee),Rt(()=>{if(t(Ve))return t(Ve).addEventListener("scroll",re),()=>{t(Ve)&&t(Ve).removeEventListener("scroll",re)}});let He=V(null),ut=V(!1);function bt(){p(Mt,!0),ee(),requestAnimationFrame(()=>{ee(),requestAnimationFrame(ee)}),setTimeout(ee,60),setTimeout(ee,150)}Rt(()=>{const g=t(Tt).sessionFile;g!==t(He)&&(p(He,g,!0),p(Mt,!0));const k=t(Nt);t(ut)&&!k&&bt(),p(ut,k,!0)});let et=se(()=>{const g=c().filter(H=>H.role==="thinking"&&r().hideThinking?!1:H.role==="tool"&&r().hideTools?Be(H)||!!H.isStreaming:H.role!=="assistant"&&H.role!=="thinking"||H.isStreaming||H.content.trim()!==""),k=g.some(H=>H.isStreaming);if(t(rt)&&!k){const H=c().some(D=>D.role==="thinking"&&D.isStreaming);g.push({id:"fallback-loader-message-id",role:"thinking",content:H?"FALLBACK_THINKING_LOADER":"FALLBACK_LOADER",timestamp:Date.now(),isStreaming:!0})}return g}),rt=se(_);_o(()=>{const g=t(et)[t(et).length-1];g&&`${t(et).length}${g.content.length}`,t(Ve)&&p(kt,q(t(Ve)),!0)}),Rt(()=>{const g=t(et)[t(et).length-1];g&&`${t(et).length}${g.content.length}`,Qe()});function Le(g){return new Date(g).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Be(g){const k=c(),H=k.findIndex(D=>D.id===g.id);if(H===-1)return!1;for(let D=H-1;D>=0;D--)if(k[D].role==="user"){const le=k[D].content?k[D].content.trim():"";return le.startsWith("!")||le.startsWith("!!")}return!1}function Wt(g,k){return Be(g)}function Ft(){p(Mt,!0),setTimeout(ee,0)}let At=se(v),mt=se(I),xt=V(null);function Zt(){!t(Ve)||t(mt)||!t(At)||(p(xt,t(Ve).scrollHeight-t(Ve).scrollTop),Ia())}Rt(()=>{if(c().length,t(xt)!==null&&t(Ve)){const g=t(xt);p(xt,null),requestAnimationFrame(()=>{t(Ve)&&(t(Ve).scrollTop=t(Ve).scrollHeight-g)})}});var Ce={forceScrollToBottom:Ft},Ze=_c(),Pt=u(Ze);{var _t=g=>{var k=wl();h(g,k)},Xt=g=>{var k=Sl(),H=u(k),D=f(u(H),6);{var le=T=>{var F=kl(),te=u(F,!0);d(F),j(()=>ue(te,t(pt).error)),h(T,F)};C(D,T=>{t(pt).error&&T(le)})}var K=f(D,2);d(H),d(k),W("click",K,()=>{So(()=>Promise.resolve().then(()=>ei),void 0,import.meta.url).then(T=>T.connect())}),h(g,k)},Kt=g=>{var k=Tl();h(g,k)},vt=g=>{var k=Nl(),H=u(k),D=u(H),le=u(D),K=u(le);d(le),it(6),d(D);var T=f(D,2),F=u(T),te=f(u(F),2),Oe=u(te);at(Oe),En(Oe,P=>p(he,P),()=>t(he));var Ae=f(Oe,2);{var xe=P=>{var J=El();pn(J,21,()=>t(Re),An,(_e,Ee)=>{var ne=Al(),ke=u(ne,!0);d(ne),j(()=>ue(ke,t(Ee))),W("click",ne,()=>{p(Ie,t(Ee),!0),ze(t(Ee),!0),t(he)?.focus()}),h(_e,ne)}),d(J),h(P,J)};C(Ae,P=>{t(Ne)&&t(Re).length>0&&P(xe)})}d(te),En(te,P=>p($e,P),()=>t($e));var st=f(te,2);{var It=P=>{var J=Cl(),_e=f(u(J));{var Ee=ne=>{var ke=Rl();h(ne,ke)};C(_e,ne=>{t(Te).isGit&&ne(Ee)})}d(J),h(P,J)},Ge=P=>{var J=Il();h(P,J)};C(st,P=>{t(Te).exists===!0?P(It):P(Ge,-1)})}d(F);var Ye=f(F,2),pe=f(u(Ye),2);{var B=P=>{var J=Ml();pn(J,21,()=>t(be).models,An,(_e,Ee)=>{var ne=$l(),ke=u(ne);d(ne);var nt={};j(()=>{ue(ke,`${t(Ee).label??""}${t(Ee).isDefault?" (default)":""}`),nt!==(nt=`${t(Ee).provider}:${t(Ee).modelId}`)&&(ne.value=ne.__value=`${t(Ee).provider}:${t(Ee).modelId}`)}),h(_e,ne)}),d(J),$r(J,()=>t(me),_e=>p(me,_e)),h(P,J)},U=P=>{var J=Ll();at(J),Rn(J,()=>t(me),_e=>p(me,_e)),h(P,J)};C(pe,P=>{t(be).models.length>0?P(B):P(U,-1)})}d(Ye);var ce=f(Ye,2);{var de=P=>{var J=Dl(),_e=u(J),Ee=u(_e);at(Ee);var ne=f(Ee,2),ke=u(ne);d(ne),d(_e);var nt=f(_e,2);{var De=tt=>{var Ut=Ol(),un=f(u(Ut),2),gn=u(un);at(gn),gn.value=gn.__value="private",it(),d(un);var Qt=f(un,2),Jt=u(Qt);at(Jt),Jt.value=Jt.__value="public",it(),d(Qt),d(Ut),Pn(L,[],gn,()=>t(dt),fn=>p(dt,fn)),Pn(L,[],Jt,()=>t(dt),fn=>p(dt,fn)),h(tt,Ut)};C(nt,tt=>{t(Fe)&&tt(De)})}d(J),j(()=>ue(ke,`Create remote ${t(Te).matchingRule.provider??""} repository`)),vn(Ee,()=>t(Fe),tt=>p(Fe,tt)),h(P,J)};C(ce,P=>{t(Te).exists!==!0&&t(Te).matchingRule&&P(de)})}var ve=f(ce,2);{var ae=P=>{var J=Pl(),_e=u(J);at(_e),it(2),d(J),W("change",_e,Ee=>{p(Me,Ee.currentTarget.checked,!0)}),vn(_e,()=>t(Ue),Ee=>p(Ue,Ee)),h(P,J)};C(ve,P=>{t(Te).exists!==!0&&(!t(Te).matchingRule||!t(Fe))&&P(ae)})}var G=f(ve,2);d(T),d(H),d(k),j((P,J)=>{je(K,"src",P),qt(Oe,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(Dt)?"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"}`),G.disabled=J},[()=>Qn("/logo.svg"),()=>!t(Ie).trim()]),Nn("submit",T,P=>{P.preventDefault(),nn()}),Nn("focus",Oe,()=>{p(Ne,!0),ze(t(Ie),!0)}),Nn("blur",Oe,P=>{t($e)&&t($e).contains(P.relatedTarget)||p(Ne,!1)}),W("keydown",Oe,P=>{P.key==="Escape"&&p(Ne,!1)}),Rn(Oe,()=>t(Ie),P=>p(Ie,P)),h(g,k)},gt=g=>{var k=Fl();h(g,k)},ln=g=>{var k=pc(),H=u(k);{var D=K=>{var T=Ul(),F=u(T),te=u(F);{var Oe=xe=>{var st=on("Loading older messages...");h(xe,st)},Ae=xe=>{var st=on("Load older messages");h(xe,st)};C(te,xe=>{t(mt)?xe(Oe):xe(Ae,-1)})}d(F),d(T),j(()=>F.disabled=t(mt)),W("click",F,Zt),h(K,T)};C(H,K=>{t(At)&&K(D)})}var le=f(H,2);pn(le,17,()=>t(et),K=>K.id,(K,T)=>{var F=fc(),te=u(F),Oe=u(te);{var Ae=pe=>{var B=Jn(),U=Ht(B);{var ce=G=>{var P=zl();h(G,P)},de=G=>{var P=Hl();h(G,P)},ve=G=>{var P=Bl();h(G,P)},ae=G=>{var P=Gl(),J=u(P);{var _e=ke=>{var nt=Wl();h(ke,nt)};C(J,ke=>{t(T).isStreaming&&ke(_e)})}var Ee=f(J,2),ne=u(Ee,!0);d(Ee),d(P),j(()=>ue(ne,t(T).content)),h(G,P)};C(U,G=>{t(T).content==="FALLBACK_THINKING_LOADER"?G(ce):t(T).content==="FALLBACK_LOADER"?G(de,1):r().hideThinking?G(ve,2):G(ae,-1)})}h(pe,B)},xe=pe=>{var B=Jn(),U=Ht(B);{var ce=ae=>{var G=jl(),P=f(u(G),2),J=f(u(P)),_e=u(J,!0);d(J),it(),d(P),d(G),j(()=>ue(_e,t(T).toolName||"agent")),h(ae,G)},de=se(()=>r().hideTools&&!Be(t(T))),ve=ae=>{const G=se(()=>Z(t(T))),P=se(()=>St[t(T).id]!==void 0?St[t(T).id]:Wt(t(T),t(et)));var J=rc(),_e=u(J),Ee=u(_e),ne=u(Ee);{var ke=A=>{var i=ql();h(A,i)},nt=A=>{var i=Vl();h(A,i)},De=A=>{var i=Yl();h(A,i)};C(ne,A=>{t(T).isStreaming?A(ke):t(G).isError?A(nt,1):A(De,-1)})}var tt=f(ne,2),Ut=u(tt,!0);d(tt);var un=f(tt,2);{var gn=A=>{var i=Zl(),b=u(i,!0);d(i),j(()=>{je(i,"title",t(G).smartTitleArgs),ue(b,t(G).smartTitleArgs)}),h(A,i)};C(un,A=>{t(G).smartTitleArgs&&A(gn)})}d(Ee);var Qt=f(Ee,2),Jt=u(Qt);{var fn=A=>{var i=Kl();it(),h(A,i)},Vn=A=>{var i=Xl();it(),h(A,i)};C(Jt,A=>{t(P)?A(fn):A(Vn,-1)})}d(Qt),d(_e);var mn=f(_e,2);{var sr=A=>{var i=nc(),b=u(i);{var M=yt=>{var Et=Ql(),$n=f(u(Et),2),Gt=u($n,!0);d($n),d(Et),j(()=>ue(Gt,t(G).fullArgs)),h(yt,Et)};C(b,yt=>{t(G).fullArgs&&t(G).fullArgs!=="{}"&&yt(M)})}var X=f(b,2),Pe=f(u(X),2);{var Ke=yt=>{var Et=Jl(),$n=u(Et,!0);d(Et),j(()=>ue($n,t(G).toolOutput)),h(yt,Et)},Lt=yt=>{var Et=ec();h(yt,Et)},Ct=yt=>{var Et=tc();h(yt,Et)};C(Pe,yt=>{t(G).toolOutput?yt(Ke):t(T).isStreaming?yt(Lt,1):yt(Ct,-1)})}d(X),d(i),h(A,i)};C(mn,A=>{t(P)&&A(sr)})}d(J),j(()=>ue(Ut,t(G).toolName)),W("click",_e,()=>Y(t(T).id,t(P))),h(ae,J)};C(U,ae=>{t(de)?ae(ce):ae(ve,-1)})}h(pe,B)},st=pe=>{var B=Jn(),U=Ht(B);{var ce=ve=>{var ae=sc(),G=u(ae,!0);it(),d(ae),j(()=>ue(G,t(T).content)),h(ve,ae)},de=ve=>{var ae=ac();Ao(ae,()=>ge(t(T).id,t(T).content),!0),d(ae),h(ve,ae)};C(U,ve=>{t(T).isStreaming?ve(ce):ve(de,-1)})}h(pe,B)},It=pe=>{const B=se(()=>oe(t(T).content));var U=dc(),ce=Ht(U),de=u(ce);{var ve=ne=>{var ke=on();j(()=>ue(ke,t(B).cleanContent)),h(ne,ke)},ae=ne=>{var ke=oc(),nt=u(ke);d(ke),j(()=>ue(nt,`Shared file${t(B).attachments.length>1?"s":""} with agent:`)),h(ne,ke)},G=ne=>{var ke=on();j(()=>ue(ke,t(T).content||(t(T).isStreaming?"Thinking...":""))),h(ne,ke)};C(de,ne=>{t(B).cleanContent?ne(ve):t(B).attachments.length>0?ne(ae,1):ne(G,-1)})}var P=f(de,2);{var J=ne=>{var ke=ic();h(ne,ke)};C(P,ne=>{t(T).isStreaming&&t(rt)&&ne(J)})}d(ce);var _e=f(ce,2);{var Ee=ne=>{var ke=cc();pn(ke,21,()=>t(B).attachments,An,(nt,De)=>{var tt=lc(),Ut=f(u(tt),2),un=u(Ut,!0);d(Ut),d(tt),j(()=>{je(Ut,"title",t(De)),ue(un,t(De))}),h(nt,tt)}),d(ke),h(ne,ke)};C(_e,ne=>{t(B).attachments.length>0&&ne(Ee)})}h(pe,U)};C(Oe,pe=>{t(T).role==="thinking"?pe(Ae):t(T).role==="tool"?pe(xe,1):t(T).role==="assistant"&&t(T).content!==""?pe(st,2):pe(It,-1)})}var Ge=f(Oe,2);{var Ye=pe=>{var B=uc(),U=u(B,!0);d(B),j(ce=>{qt(B,1,`mt-1 text-xs opacity-50 ${t(T).role==="user"?"text-brand-text-muted":t(T).role==="assistant"?"text-brand-purple":"text-brand-text-muted"}`),ue(U,ce)},[()=>Le(t(T).timestamp)]),h(pe,B)};C(Ge,pe=>{t(T).role!=="thinking"&&t(T).role!=="tool"&&pe(Ye)})}d(te),d(F),j(pe=>{qt(F,1,`flex ${t(T).role==="user"?"justify-end":"justify-start"}`),qt(te,1,`max-w-[85%] rounded-lg px-4 py-3 ${pe??""}`)},[()=>t(T).role==="user"?"bg-brand-blue/80 text-brand-text":t(T).role==="thinking"?"border-l-2 border-brand-border bg-brand-surface/30 text-sm text-brand-text-muted":t(T).role==="tool"?r().hideTools&&!Be(t(T))?"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(T).isStreaming?"border-amber-400":t(T).isError?"border-rose-400":"border-emerald-400"}`:t(T).role==="assistant"?"border-l-2 border-brand-purple bg-brand-purple/10 text-brand-text":t(T).content===""&&t(T).isStreaming?"bg-brand-surface-3 text-brand-text-muted italic":"bg-brand-surface-2 text-brand-text"]),h(K,F)}),d(k),En(k,K=>p(Ve,K),()=>t(Ve)),h(g,k)};C(Pt,g=>{t(pt).connecting&&!t(ht)?g(_t):!t(pt).connected&&!t(ht)?g(Xt,1):!t(ht)&&(t(Nt)||typeof window<"u"&&window.location.hash)?g(Kt,2):t(Tt).sessionFile?t(et).length===0?g(gt,4):g(ln,-1):g(vt,3)})}var an=f(Pt,2),cn=u(an),rn=u(cn),dn=u(rn);at(dn),it(),d(rn);var E=f(rn,2),x=u(E);at(x),it(),d(E);var w=f(E,2);{var O=g=>{var k=hc(),H=f(u(k),2),D=u(H,!0);d(H),d(k),j(le=>{je(k,"title",le),ue(D,t(fe))},[()=>r().contextUsage?.tokens!=null?`${r().contextUsage.tokens.toLocaleString()} context tokens of ${r().contextUsage.contextWindow.toLocaleString()}`:"Context window size"]),h(g,k)};C(w,g=>{t(fe)&&g(O)})}d(cn);var Q=f(cn,2);d(an);var We=f(an,2);{var we=g=>{var k=xc(),H=u(k),D=f(u(H),2),le=f(u(D)),K=u(le,!0);d(le),it(),d(D);var T=f(D,2),F=u(T),te=u(F);at(te);var Oe=f(te,2),Ae=f(u(Oe));{var xe=U=>{var ce=bc();h(U,ce)},st=U=>{var ce=vc();h(U,ce)};C(Ae,U=>{t(Te).isGit?U(xe):U(st,-1)})}d(Oe),d(F);var It=f(F,2);{var Ge=U=>{var ce=mc(),de=u(ce),ve=u(de);at(ve);var ae=f(ve,2),G=u(ae);d(ae),d(de);var P=f(de,2);{var J=_e=>{var Ee=gc(),ne=f(u(Ee),2),ke=u(ne);at(ke),ke.value=ke.__value="private",it(),d(ne);var nt=f(ne,2),De=u(nt);at(De),De.value=De.__value="public",it(),d(nt),d(Ee),Pn(L,[],ke,()=>t(dt),tt=>p(dt,tt)),Pn(L,[],De,()=>t(dt),tt=>p(dt,tt)),h(_e,Ee)};C(P,_e=>{t(Fe)&&_e(J)})}d(ce),j(()=>ue(G,`Create remote ${t(Te).matchingRule.provider??""} repository`)),vn(ve,()=>t(Fe),_e=>p(Fe,_e)),h(U,ce)};C(It,U=>{t(Te).matchingRule&&U(Ge)})}d(T);var Ye=f(T,2),pe=u(Ye),B=f(pe,2);d(Ye),d(H),d(k),j(()=>{ue(K,t(Ie)),te.disabled=t(Te).isGit}),vn(te,()=>t(Ue),U=>p(Ue,U)),W("click",pe,()=>p(ft,!1)),W("click",B,()=>{p(ft,!1),kn(t(Ie).trim(),t(me)||void 0,t(Ue),t(Te).matchingRule?t(Fe):void 0,t(Te).matchingRule?t(dt):void 0)}),h(g,k)};C(We,g=>{t(ft)&&g(we)})}d(Ze),j(()=>{es(dn,r().hideThinking),es(x,r().hideTools),Q.disabled=!t(rt)}),W("change",dn,g=>cs({hideThinking:g.currentTarget.checked})),W("change",x,g=>cs({hideTools:g.currentTarget.checked})),W("click",Q,function(...g){Ea?.apply(this,g)}),h(n,Ze);var ie=Un(Ce);return $(),ie}Gn(["click","keydown","change"]);var wc=m("<option> </option>"),kc=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>'),Sc=m('<div class="mt-2 rounded border border-red-900/40 bg-red-950/40 p-2 leading-normal text-red-400"> </div>'),Tc=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
71
- the message.</p></div> <!></div>`,1),Ac=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 Ec(n,e){Fn(e,!0);let r=br(e,"text",15);const s=typeof window<"u"?window.SpeechRecognition||window.webkitSpeechRecognition:null,a=!!s;let o=V(!1),l=V(!1),c=V(!1),_=V(!1),v=V(!1),I=V("en-US"),N=V("browser"),$=V(null),L=V(null),S=null,ge=null,ye=null,fe=null,oe=null,Ie=[],Re="",Ne=!1;const he=[{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)"}];yr(()=>{const y=localStorage.getItem("wherever-speech-direct-send");y!==null&&p(v,y==="true");const z=localStorage.getItem("wherever-speech-locale");z!==null&&p(I,z,!0);const R=localStorage.getItem("wherever-speech-engine");return R!==null?p(N,R,!0):a||p(N,"cloud"),()=>{if(S)try{S.abort()}catch{}if(fe)try{fe.disconnect()}catch{}if(ye)try{ye.disconnect()}catch{}if(oe)try{oe.getTracks().forEach(Z=>Z.stop())}catch{}if(ge)try{ge.close()}catch{}t(L)&&clearTimeout(t(L))}});function $e(){localStorage.setItem("wherever-speech-direct-send",String(t(v))),localStorage.setItem("wherever-speech-locale",t(I)),localStorage.setItem("wherever-speech-engine",t(N))}function ot(){const y=localStorage.getItem("wherever-config");if(y){const z=JSON.parse(y),R=window.location.protocol==="https:"?"https:":"http:",Z=z.host.startsWith("http")?z.host.replace(/^wss?:\/\//,""):z.host;return`${R}//${Z}:${z.port}`}return`${window.location.protocol}//${window.location.host}`}function me(){try{const y=localStorage.getItem("wherever-config");if(y)return JSON.parse(y).token||""}catch{}return""}function Ue(){try{const y=window.AudioContext||window.webkitAudioContext;if(!y)return;const z=new y,R=z.createOscillator(),Z=z.createGain();R.type="sine",R.frequency.setValueAtTime(400,z.currentTime),Z.gain.setValueAtTime(.08,z.currentTime),Z.gain.exponentialRampToValueAtTime(.001,z.currentTime+.12),R.connect(Z),Z.connect(z.destination),R.start(),R.stop(z.currentTime+.12)}catch(y){console.warn("Could not play audio beep feedback:",y)}}function Me(y,z,R){if(z===R)return y;const Z=z/R,q=Math.round(y.length/Z),re=new Float32Array(q);let ee=0,Qe=0;for(;ee<re.length;){const He=Math.round((ee+1)*Z);let ut=0,bt=0;for(let et=Qe;et<He&&et<y.length;et++)ut+=y[et],bt++;re[ee]=bt>0?ut/bt:0,ee++,Qe=He}return re}function Fe(){if(a)try{S=new s,S.continuous=!0,S.interimResults=!0,S.lang=t(I),S.onstart=()=>{p(o,!0),p(l,!1),Ue()},S.onresult=y=>{let z="",R="";for(let q=y.resultIndex;q<y.results.length;++q){const re=y.results[q];re.isFinal?z+=re[0].transcript:R+=re[0].transcript}const Z=(z+R).trim();Z&&(Ne=!0,r(Re+(Re?" ":"")+Z))},S.onerror=y=>{console.error("Browser speech recognition error:",y.error),y.error!=="no-speech"&&p($,`Error: ${y.error}`),dt()},S.onend=()=>{p(o,!1),t(v)&&Ne&&e.onSend&&setTimeout(()=>{r().trim()&&e.onSend()},50)},S.start(),navigator.vibrate&&navigator.vibrate(40)}catch(y){console.error("Failed to start browser speech recognition:",y),p($,"Failed to start browser recording"),p(o,!1)}}function dt(){if(S)try{S.stop()}catch{}p(o,!1)}async function ft(){try{const y=await navigator.mediaDevices.getUserMedia({audio:!0});oe=y,Ie=[];const z=window.AudioContext||window.webkitAudioContext;ge=new z,ye=ge.createMediaStreamSource(y),fe=ge.createScriptProcessor(4096,1,1),fe.onaudioprocess=R=>{const Z=R.inputBuffer.getChannelData(0);Ie.push(new Float32Array(Z))},ye.connect(fe),fe.connect(ge.destination),p(o,!0),p(l,!1),Ue(),navigator.vibrate&&navigator.vibrate(40)}catch(y){console.error("Failed to start cloud audio recording:",y),p($,y.message||"Microphone access denied",!0),p(o,!1),p(l,!1)}}function pt(){if(t(o)){if(p(o,!1),p(l,!0),fe){try{fe.disconnect()}catch{}fe.onaudioprocess=null}if(ye)try{ye.disconnect()}catch{}if(oe)try{oe.getTracks().forEach(y=>y.stop())}catch{}be()}}async function be(){try{if(Ie.length===0){p(l,!1);return}p($,null);let y=0;for(const Le of Ie)y+=Le.length;const z=new Float32Array(y);let R=0;for(const Le of Ie)z.set(Le,R),R+=Le.length;const Z=ge?ge.sampleRate:48e3,q=16e3,re=Me(z,Z,q),ee=nn(re,1,q,1,16),Qe=new Blob([ee],{type:"audio/wav"}),He=ot(),ut=me(),bt=`${He}/session/transcribe${ut?`?token=${encodeURIComponent(ut)}`:""}`,et=await fetch(bt,{method:"POST",body:Qe,headers:{"Content-Type":"application/octet-stream"}}),rt=await et.json();if(!et.ok)throw new Error(rt.error||`HTTP ${et.status}`);rt.text&&rt.text.trim()&&(Ne=!0,r(Re+(Re?" ":"")+rt.text.trim()),t(v)&&e.onSend&&setTimeout(()=>{r().trim()&&e.onSend()},50))}catch(y){console.error("Cloud transcription request failed:",y),p($,y.message||"Cloud API failed",!0)}finally{if(p(l,!1),ge){try{ge.close()}catch{}ge=null}}}function Se(){e.disabled||t(o)||t(l)||(p($,null),Ne=!1,Re=r(),t(N)==="cloud"?ft():Fe())}function Te(){t(N)==="cloud"?pt():dt()}function Dt(y){if(y.button===0&&!e.disabled){if(y.preventDefault(),t(o)){Te();return}p(c,!1),p(L,setTimeout(()=>{p(c,!0),Se()},350),!0)}}function Xe(y){t(L)&&(clearTimeout(t(L)),p(L,null)),t(c)?(p(c,!1),Te()):t(o)||Se()}function ze(){t(L)&&(clearTimeout(t(L)),p(L,null)),t(c)&&(p(c,!1),Te())}function nn(y,z,R,Z,q){const re=new ArrayBuffer(44+y.length*2),ee=new DataView(re);return Tt(ee,0,"RIFF"),ee.setUint32(4,36+y.length*2,!0),Tt(ee,8,"WAVE"),Tt(ee,12,"fmt "),ee.setUint32(16,16,!0),ee.setUint16(20,Z,!0),ee.setUint16(22,z,!0),ee.setUint32(24,R,!0),ee.setUint32(28,R*z*(q/8),!0),ee.setUint16(32,z*(q/8),!0),ee.setUint16(34,q,!0),Tt(ee,36,"data"),ee.setUint32(40,y.length*2,!0),Ve(ee,44,y),re}function Ve(y,z,R){for(let Z=0;Z<R.length;Z++,z+=2){let q=Math.max(-1,Math.min(1,R[Z]));y.setInt16(z,q<0?q*32768:q*32767,!0)}}function Tt(y,z,R){for(let Z=0;Z<R.length;Z++)y.setUint8(z+Z,R.charCodeAt(Z))}var Nt=Ac(),ht=u(Nt),kt=f(ht,2),Mt=u(kt);d(kt);var St=f(kt,2);{var Y=y=>{var z=Tc(),R=Ht(z),Z=f(R,2),q=f(u(Z),2),re=f(u(q),2),ee=u(re),Qe=f(ee,2);d(re);var He=f(re,2),ut=u(He,!0);d(He),d(q);var bt=f(q,2);{var et=At=>{var mt=kc(),xt=f(u(mt),2);pn(xt,21,()=>he,An,(Zt,Ce)=>{var Ze=wc(),Pt=u(Ze,!0);d(Ze);var _t={};j(()=>{ue(Pt,t(Ce).label),_t!==(_t=t(Ce).code)&&(Ze.value=(Ze.__value=t(Ce).code)??"")}),h(Zt,Ze)}),d(xt),d(mt),W("change",xt,$e),$r(xt,()=>t(I),Zt=>p(I,Zt)),h(At,mt)};C(bt,At=>{t(N)==="browser"&&At(et)})}var rt=f(bt,2),Le=u(rt),Be=u(Le);at(Be),it(2),d(Le),it(2),d(rt);var Wt=f(rt,2);{var Ft=At=>{var mt=Sc(),xt=u(mt,!0);d(mt),j(()=>ue(xt,t($))),h(At,mt)};C(Wt,At=>{t($)&&At(Ft)})}d(Z),j(()=>{ee.disabled=!a,qt(ee,1,`flex-1 rounded border px-2 py-1.5 text-center font-medium transition-colors disabled:opacity-40
69
+ `).trim();return K==="I have uploaded the following file(s) for you:"&&(K=""),{cleanContent:K,attachments:le}}let Ie=V(""),Re=V(wn([])),Fe=V(!1),he=V(null),$e=V(null),ot="",me=V(""),Ue=V(!1),Me=V(null),Le=V(!0),dt=V("private"),ft=V(!1),pt=se(r),be=se(s),Se=se(a);Rt(()=>{t(Me)===null&&p(Ue,t(Se),!0)});let Te=V(wn({exists:null,isGit:!1,resolvedPath:"",matchingRule:null})),Dt=se(()=>t(Te).exists!==!0&&t(Te).matchingRule&&t(Le)),Xe=null;async function ze(v,k=!1){if(Xe&&clearTimeout(Xe),v===ot&&!k)return;if(ot=v,!v.trim()){p(Te,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0);const D=async()=>{const le=await Mr("");p(Re,le||[],!0)};k?await D():Xe=setTimeout(D,300);return}const H=async()=>{const[D,le]=await Promise.all([ka(v),Mr(v)]);p(Re,le||[],!0),D?(p(Te,{exists:D.exists,isGit:D.isGit,resolvedPath:D.resolvedPath,matchingRule:D.matchingRule||null},!0),D.exists||(p(Ue,t(Me)!==null?t(Me):t(Se),!0),p(Le,!0),D.matchingRule&&p(dt,D.matchingRule.visibility,!0))):p(Te,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0)};k?await H():Xe=setTimeout(H,300)}Rt(()=>{const v=t(Ie);ze(v,!1)}),Rt(()=>{if(t(be).models.length>0&&!t(me)){const v=t(be).models.find(k=>k.isDefault);v?p(me,`${v.provider}:${v.modelId}`):p(me,`${t(be).models[0].provider}:${t(be).models[0].modelId}`)}});function nn(){t(Ie).trim()&&(t(Te).exists===!0?(p(Ue,!1),p(Le,!1),t(Te).matchingRule&&p(dt,t(Te).matchingRule.visibility,!0),p(ft,!0)):kn(t(Ie).trim(),t(me)||void 0,t(Ue),t(Te).matchingRule?t(Le):void 0,t(Te).matchingRule?t(dt):void 0))}let Ve=V(void 0),Tt=se(o),Nt=se(l),ht=se(()=>!!t(Tt).sessionFile),kt=V(!0),Mt=V(!1),St=wn({});function Y(v,k){St[v]=!k}function y(v){if(!v)return null;const k=v.trim();if(!k)return null;if(k.startsWith("{"))try{return JSON.parse(k)}catch{}const H={},D=/([a-zA-Z0-9_-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|(\S+))/g;let le;for(;(le=D.exec(k))!==null;){const K=le[1],T=le[2]!==void 0?le[2]:le[3]!==void 0?le[3]:le[4];H[K]=T}return Object.keys(H).length>0?H:null}function z(v,k,H){if(!k)return H?H.trim():"";const D=v.toLowerCase();if(["read","write","edit","ls"].includes(D)){const K=k.path||k.filepath||k.file;if(K)return String(K)}if(D==="bash"){const K=k.command||k.cmd;if(K){const T=String(K).replace(/\s+/g," ").trim();return T.length>50?T.slice(0,47)+"...":T}}if(D==="grep"){const K=k.pattern,T=k.path;if(K)return T?`"${K}" in ${T}`:`"${K}"`}if(D==="find"){const K=k.pattern||k.path;if(K)return String(K)}const le=k.path||k.filepath||k.file||k.name||k.query;return le?String(le):Object.entries(k).filter(([K,T])=>T!==void 0&&T!=="").map(([K,T])=>`${K}=${typeof T=="object"?JSON.stringify(T):T}`).join(" ")}function R(v,k){return v?JSON.stringify(v,null,2):k?k.trim():""}function Z(v){let k=v.toolName||"tool",H=v.toolArgs!==void 0?v.toolArgs:"",D=v.toolOutput!==void 0?v.toolOutput:"",le=!!v.isError;if(!H&&!D&&v.content){let te=v.content||"";te.startsWith("Error: ")?(le=!0,te=te.slice(7)):te.startsWith("Tool error: ")&&(le=!0,te=te.slice(12));const De=te.indexOf(`
70
+ `),Ae=De!==-1?te.slice(0,De):te;D=De!==-1?te.slice(De+1):"";let xe=Ae.trim();xe.startsWith("$ ")&&(xe=xe.slice(2));const st=xe.indexOf(" ");k=v.toolName||(st!==-1?xe.slice(0,st):xe)||"tool",H=st!==-1?xe.slice(st+1):""}const K=y(H),T=z(k,K,H),F=R(K,H);return{toolName:k,smartTitleArgs:T,fullArgs:F,toolOutput:D,isError:le}}function q(v){return v.scrollHeight-v.scrollTop-v.clientHeight<=20}function re(){t(Ve)&&p(kt,q(t(Ve)),!0)}function ee(){t(Ve)&&(t(Ve).scrollTop=t(Ve).scrollHeight)}function Qe(){(t(kt)||t(Mt))&&(ee(),p(Mt,!1))}yr(ee),Rt(()=>{if(t(Ve))return t(Ve).addEventListener("scroll",re),()=>{t(Ve)&&t(Ve).removeEventListener("scroll",re)}});let He=V(null),ut=V(!1);function bt(){p(Mt,!0),ee(),requestAnimationFrame(()=>{ee(),requestAnimationFrame(ee)}),setTimeout(ee,60),setTimeout(ee,150)}Rt(()=>{const v=t(Tt).sessionFile;v!==t(He)&&(p(He,v,!0),p(Mt,!0));const k=t(Nt);t(ut)&&!k&&bt(),p(ut,k,!0)});let et=se(()=>{const v=c().filter(H=>H.role==="thinking"&&r().hideThinking?!1:H.role==="tool"&&r().hideTools?Be(H)||!!H.isStreaming:H.role!=="assistant"&&H.role!=="thinking"||H.isStreaming||H.content.trim()!==""),k=v.some(H=>H.isStreaming);if(t(rt)&&!k){const H=c().some(D=>D.role==="thinking"&&D.isStreaming);v.push({id:"fallback-loader-message-id",role:"thinking",content:H?"FALLBACK_THINKING_LOADER":"FALLBACK_LOADER",timestamp:Date.now(),isStreaming:!0})}return v}),rt=se(_);_o(()=>{const v=t(et)[t(et).length-1];v&&`${t(et).length}${v.content.length}`,t(Ve)&&p(kt,q(t(Ve)),!0)}),Rt(()=>{const v=t(et)[t(et).length-1];v&&`${t(et).length}${v.content.length}`,Qe()});function Oe(v){return new Date(v).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Be(v){const k=c(),H=k.findIndex(D=>D.id===v.id);if(H===-1)return!1;for(let D=H-1;D>=0;D--)if(k[D].role==="user"){const le=k[D].content?k[D].content.trim():"";return le.startsWith("!")||le.startsWith("!!")}return!1}function Wt(v,k){return Be(v)}function Ft(){p(Mt,!0),setTimeout(ee,0)}let At=se(g),mt=se(I),xt=V(null);function Zt(){!t(Ve)||t(mt)||!t(At)||(p(xt,t(Ve).scrollHeight-t(Ve).scrollTop),Ia())}Rt(()=>{if(c().length,t(xt)!==null&&t(Ve)){const v=t(xt);p(xt,null),requestAnimationFrame(()=>{t(Ve)&&(t(Ve).scrollTop=t(Ve).scrollHeight-v)})}});var Ce={forceScrollToBottom:Ft},Ze=_c(),Pt=u(Ze);{var _t=v=>{var k=wl();h(v,k)},Xt=v=>{var k=Sl(),H=u(k),D=f(u(H),6);{var le=T=>{var F=kl(),te=u(F,!0);d(F),j(()=>ue(te,t(pt).error)),h(T,F)};C(D,T=>{t(pt).error&&T(le)})}var K=f(D,2);d(H),d(k),W("click",K,()=>{So(()=>Promise.resolve().then(()=>ei),void 0,import.meta.url).then(T=>T.connect())}),h(v,k)},Kt=v=>{var k=Tl();h(v,k)},gt=v=>{var k=Nl(),H=u(k),D=u(H),le=u(D),K=u(le);d(le),it(6),d(D);var T=f(D,2),F=u(T),te=f(u(F),2),De=u(te);at(De),En(De,P=>p(he,P),()=>t(he));var Ae=f(De,2);{var xe=P=>{var J=El();pn(J,21,()=>t(Re),An,(_e,Ee)=>{var ne=Al(),ke=u(ne,!0);d(ne),j(()=>ue(ke,t(Ee))),W("click",ne,()=>{p(Ie,t(Ee),!0),ze(t(Ee),!0),t(he)?.focus()}),h(_e,ne)}),d(J),h(P,J)};C(Ae,P=>{t(Fe)&&t(Re).length>0&&P(xe)})}d(te),En(te,P=>p($e,P),()=>t($e));var st=f(te,2);{var It=P=>{var J=Cl(),_e=f(u(J));{var Ee=ne=>{var ke=Rl();h(ne,ke)};C(_e,ne=>{t(Te).isGit&&ne(Ee)})}d(J),h(P,J)},Ge=P=>{var J=Il();h(P,J)};C(st,P=>{t(Te).exists===!0?P(It):P(Ge,-1)})}d(F);var Ye=f(F,2),pe=f(u(Ye),2);{var B=P=>{var J=Ml();pn(J,21,()=>t(be).models,An,(_e,Ee)=>{var ne=$l(),ke=u(ne);d(ne);var nt={};j(()=>{ue(ke,`${t(Ee).label??""}${t(Ee).isDefault?" (default)":""}`),nt!==(nt=`${t(Ee).provider}:${t(Ee).modelId}`)&&(ne.value=ne.__value=`${t(Ee).provider}:${t(Ee).modelId}`)}),h(_e,ne)}),d(J),$r(J,()=>t(me),_e=>p(me,_e)),h(P,J)},U=P=>{var J=Ll();at(J),Rn(J,()=>t(me),_e=>p(me,_e)),h(P,J)};C(pe,P=>{t(be).models.length>0?P(B):P(U,-1)})}d(Ye);var ce=f(Ye,2);{var de=P=>{var J=Dl(),_e=u(J),Ee=u(_e);at(Ee);var ne=f(Ee,2),ke=u(ne);d(ne),d(_e);var nt=f(_e,2);{var Pe=tt=>{var Ut=Ol(),un=f(u(Ut),2),vn=u(un);at(vn),vn.value=vn.__value="private",it(),d(un);var Qt=f(un,2),Jt=u(Qt);at(Jt),Jt.value=Jt.__value="public",it(),d(Qt),d(Ut),Pn(L,[],vn,()=>t(dt),fn=>p(dt,fn)),Pn(L,[],Jt,()=>t(dt),fn=>p(dt,fn)),h(tt,Ut)};C(nt,tt=>{t(Le)&&tt(Pe)})}d(J),j(()=>ue(ke,`Create remote ${t(Te).matchingRule.provider??""} repository`)),gn(Ee,()=>t(Le),tt=>p(Le,tt)),h(P,J)};C(ce,P=>{t(Te).exists!==!0&&t(Te).matchingRule&&P(de)})}var ge=f(ce,2);{var ae=P=>{var J=Pl(),_e=u(J);at(_e),it(2),d(J),W("change",_e,Ee=>{p(Me,Ee.currentTarget.checked,!0)}),gn(_e,()=>t(Ue),Ee=>p(Ue,Ee)),h(P,J)};C(ge,P=>{t(Te).exists!==!0&&(!t(Te).matchingRule||!t(Le))&&P(ae)})}var G=f(ge,2);d(T),d(H),d(k),j((P,J)=>{je(K,"src",P),qt(De,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(Dt)?"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"}`),G.disabled=J},[()=>Qn("/logo.svg"),()=>!t(Ie).trim()]),Nn("submit",T,P=>{P.preventDefault(),nn()}),Nn("focus",De,()=>{p(Fe,!0),ze(t(Ie),!0)}),Nn("blur",De,P=>{t($e)&&t($e).contains(P.relatedTarget)||p(Fe,!1)}),W("keydown",De,P=>{P.key==="Escape"&&p(Fe,!1)}),Rn(De,()=>t(Ie),P=>p(Ie,P)),h(v,k)},vt=v=>{var k=Fl();h(v,k)},ln=v=>{var k=pc(),H=u(k);{var D=K=>{var T=Ul(),F=u(T),te=u(F);{var De=xe=>{var st=on("Loading older messages...");h(xe,st)},Ae=xe=>{var st=on("Load older messages");h(xe,st)};C(te,xe=>{t(mt)?xe(De):xe(Ae,-1)})}d(F),d(T),j(()=>F.disabled=t(mt)),W("click",F,Zt),h(K,T)};C(H,K=>{t(At)&&K(D)})}var le=f(H,2);pn(le,17,()=>t(et),K=>K.id,(K,T)=>{var F=fc(),te=u(F),De=u(te);{var Ae=pe=>{var B=Jn(),U=Ht(B);{var ce=G=>{var P=zl();h(G,P)},de=G=>{var P=Hl();h(G,P)},ge=G=>{var P=Bl();h(G,P)},ae=G=>{var P=Gl(),J=u(P);{var _e=ke=>{var nt=Wl();h(ke,nt)};C(J,ke=>{t(T).isStreaming&&ke(_e)})}var Ee=f(J,2),ne=u(Ee,!0);d(Ee),d(P),j(()=>ue(ne,t(T).content)),h(G,P)};C(U,G=>{t(T).content==="FALLBACK_THINKING_LOADER"?G(ce):t(T).content==="FALLBACK_LOADER"?G(de,1):r().hideThinking?G(ge,2):G(ae,-1)})}h(pe,B)},xe=pe=>{var B=Jn(),U=Ht(B);{var ce=ae=>{var G=jl(),P=f(u(G),2),J=f(u(P)),_e=u(J,!0);d(J),it(),d(P),d(G),j(()=>ue(_e,t(T).toolName||"agent")),h(ae,G)},de=se(()=>r().hideTools&&!Be(t(T))),ge=ae=>{const G=se(()=>Z(t(T))),P=se(()=>St[t(T).id]!==void 0?St[t(T).id]:Wt(t(T),t(et)));var J=rc(),_e=u(J),Ee=u(_e),ne=u(Ee);{var ke=A=>{var i=ql();h(A,i)},nt=A=>{var i=Vl();h(A,i)},Pe=A=>{var i=Yl();h(A,i)};C(ne,A=>{t(T).isStreaming?A(ke):t(G).isError?A(nt,1):A(Pe,-1)})}var tt=f(ne,2),Ut=u(tt,!0);d(tt);var un=f(tt,2);{var vn=A=>{var i=Zl(),b=u(i,!0);d(i),j(()=>{je(i,"title",t(G).smartTitleArgs),ue(b,t(G).smartTitleArgs)}),h(A,i)};C(un,A=>{t(G).smartTitleArgs&&A(vn)})}d(Ee);var Qt=f(Ee,2),Jt=u(Qt);{var fn=A=>{var i=Kl();it(),h(A,i)},Vn=A=>{var i=Xl();it(),h(A,i)};C(Jt,A=>{t(P)?A(fn):A(Vn,-1)})}d(Qt),d(_e);var mn=f(_e,2);{var sr=A=>{var i=nc(),b=u(i);{var M=yt=>{var Et=Ql(),$n=f(u(Et),2),Gt=u($n,!0);d($n),d(Et),j(()=>ue(Gt,t(G).fullArgs)),h(yt,Et)};C(b,yt=>{t(G).fullArgs&&t(G).fullArgs!=="{}"&&yt(M)})}var X=f(b,2),Ne=f(u(X),2);{var Ke=yt=>{var Et=Jl(),$n=u(Et,!0);d(Et),j(()=>ue($n,t(G).toolOutput)),h(yt,Et)},Lt=yt=>{var Et=ec();h(yt,Et)},Ct=yt=>{var Et=tc();h(yt,Et)};C(Ne,yt=>{t(G).toolOutput?yt(Ke):t(T).isStreaming?yt(Lt,1):yt(Ct,-1)})}d(X),d(i),h(A,i)};C(mn,A=>{t(P)&&A(sr)})}d(J),j(()=>ue(Ut,t(G).toolName)),W("click",_e,()=>Y(t(T).id,t(P))),h(ae,J)};C(U,ae=>{t(de)?ae(ce):ae(ge,-1)})}h(pe,B)},st=pe=>{var B=Jn(),U=Ht(B);{var ce=ge=>{var ae=sc(),G=u(ae,!0);it(),d(ae),j(()=>ue(G,t(T).content)),h(ge,ae)},de=ge=>{var ae=ac();Ao(ae,()=>ve(t(T).id,t(T).content),!0),d(ae),h(ge,ae)};C(U,ge=>{t(T).isStreaming?ge(ce):ge(de,-1)})}h(pe,B)},It=pe=>{const B=se(()=>oe(t(T).content));var U=dc(),ce=Ht(U),de=u(ce);{var ge=ne=>{var ke=on();j(()=>ue(ke,t(B).cleanContent)),h(ne,ke)},ae=ne=>{var ke=oc(),nt=u(ke);d(ke),j(()=>ue(nt,`Shared file${t(B).attachments.length>1?"s":""} with agent:`)),h(ne,ke)},G=ne=>{var ke=on();j(()=>ue(ke,t(T).content||(t(T).isStreaming?"Thinking...":""))),h(ne,ke)};C(de,ne=>{t(B).cleanContent?ne(ge):t(B).attachments.length>0?ne(ae,1):ne(G,-1)})}var P=f(de,2);{var J=ne=>{var ke=ic();h(ne,ke)};C(P,ne=>{t(T).isStreaming&&t(rt)&&ne(J)})}d(ce);var _e=f(ce,2);{var Ee=ne=>{var ke=cc();pn(ke,21,()=>t(B).attachments,An,(nt,Pe)=>{var tt=lc(),Ut=f(u(tt),2),un=u(Ut,!0);d(Ut),d(tt),j(()=>{je(Ut,"title",t(Pe)),ue(un,t(Pe))}),h(nt,tt)}),d(ke),h(ne,ke)};C(_e,ne=>{t(B).attachments.length>0&&ne(Ee)})}h(pe,U)};C(De,pe=>{t(T).role==="thinking"?pe(Ae):t(T).role==="tool"?pe(xe,1):t(T).role==="assistant"&&t(T).content!==""?pe(st,2):pe(It,-1)})}var Ge=f(De,2);{var Ye=pe=>{var B=uc(),U=u(B,!0);d(B),j(ce=>{qt(B,1,`mt-1 text-xs opacity-50 ${t(T).role==="user"?"text-brand-text-muted":t(T).role==="assistant"?"text-brand-purple":"text-brand-text-muted"}`),ue(U,ce)},[()=>Oe(t(T).timestamp)]),h(pe,B)};C(Ge,pe=>{t(T).role!=="thinking"&&t(T).role!=="tool"&&pe(Ye)})}d(te),d(F),j(pe=>{qt(F,1,`flex ${t(T).role==="user"?"justify-end":"justify-start"}`),qt(te,1,`max-w-[85%] rounded-lg px-4 py-3 ${pe??""}`)},[()=>t(T).role==="user"?"bg-brand-blue/80 text-brand-text":t(T).role==="thinking"?"border-l-2 border-brand-border bg-brand-surface/30 text-sm text-brand-text-muted":t(T).role==="tool"?r().hideTools&&!Be(t(T))?"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(T).isStreaming?"border-amber-400":t(T).isError?"border-rose-400":"border-emerald-400"}`:t(T).role==="assistant"?"border-l-2 border-brand-purple bg-brand-purple/10 text-brand-text":t(T).content===""&&t(T).isStreaming?"bg-brand-surface-3 text-brand-text-muted italic":"bg-brand-surface-2 text-brand-text"]),h(K,F)}),d(k),En(k,K=>p(Ve,K),()=>t(Ve)),h(v,k)};C(Pt,v=>{t(pt).connecting&&!t(ht)?v(_t):!t(pt).connected&&!t(ht)?v(Xt,1):!t(ht)&&(t(Nt)||typeof window<"u"&&window.location.hash)?v(Kt,2):t(Tt).sessionFile?t(et).length===0?v(vt,4):v(ln,-1):v(gt,3)})}var an=f(Pt,2),cn=u(an),rn=u(cn),dn=u(rn);at(dn),it(),d(rn);var E=f(rn,2),x=u(E);at(x),it(),d(E);var w=f(E,2);{var O=v=>{var k=hc(),H=f(u(k),2),D=u(H,!0);d(H),d(k),j(le=>{je(k,"title",le),ue(D,t(fe))},[()=>r().contextUsage?.tokens!=null?`${r().contextUsage.tokens.toLocaleString()} context tokens of ${r().contextUsage.contextWindow.toLocaleString()}`:"Context window size"]),h(v,k)};C(w,v=>{t(fe)&&v(O)})}d(cn);var Q=f(cn,2);d(an);var We=f(an,2);{var we=v=>{var k=xc(),H=u(k),D=f(u(H),2),le=f(u(D)),K=u(le,!0);d(le),it(),d(D);var T=f(D,2),F=u(T),te=u(F);at(te);var De=f(te,2),Ae=f(u(De));{var xe=U=>{var ce=bc();h(U,ce)},st=U=>{var ce=gc();h(U,ce)};C(Ae,U=>{t(Te).isGit?U(xe):U(st,-1)})}d(De),d(F);var It=f(F,2);{var Ge=U=>{var ce=mc(),de=u(ce),ge=u(de);at(ge);var ae=f(ge,2),G=u(ae);d(ae),d(de);var P=f(de,2);{var J=_e=>{var Ee=vc(),ne=f(u(Ee),2),ke=u(ne);at(ke),ke.value=ke.__value="private",it(),d(ne);var nt=f(ne,2),Pe=u(nt);at(Pe),Pe.value=Pe.__value="public",it(),d(nt),d(Ee),Pn(L,[],ke,()=>t(dt),tt=>p(dt,tt)),Pn(L,[],Pe,()=>t(dt),tt=>p(dt,tt)),h(_e,Ee)};C(P,_e=>{t(Le)&&_e(J)})}d(ce),j(()=>ue(G,`Create remote ${t(Te).matchingRule.provider??""} repository`)),gn(ge,()=>t(Le),_e=>p(Le,_e)),h(U,ce)};C(It,U=>{t(Te).matchingRule&&U(Ge)})}d(T);var Ye=f(T,2),pe=u(Ye),B=f(pe,2);d(Ye),d(H),d(k),j(()=>{ue(K,t(Ie)),te.disabled=t(Te).isGit}),gn(te,()=>t(Ue),U=>p(Ue,U)),W("click",pe,()=>p(ft,!1)),W("click",B,()=>{p(ft,!1),kn(t(Ie).trim(),t(me)||void 0,t(Ue),t(Te).matchingRule?t(Le):void 0,t(Te).matchingRule?t(dt):void 0)}),h(v,k)};C(We,v=>{t(ft)&&v(we)})}d(Ze),j(()=>{es(dn,r().hideThinking),es(x,r().hideTools),Q.disabled=!t(rt)}),W("change",dn,v=>cs({hideThinking:v.currentTarget.checked})),W("change",x,v=>cs({hideTools:v.currentTarget.checked})),W("click",Q,function(...v){Ea?.apply(this,v)}),h(n,Ze);var ie=Un(Ce);return $(),ie}Gn(["click","keydown","change"]);var wc=m("<option> </option>"),kc=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>'),Sc=m('<div class="mt-2 rounded border border-red-900/40 bg-red-950/40 p-2 leading-normal text-red-400"> </div>'),Tc=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
71
+ the message.</p></div> <!></div>`,1),Ac=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 Ec(n,e){Fn(e,!0);let r=br(e,"text",15);const s=typeof window<"u"?window.SpeechRecognition||window.webkitSpeechRecognition:null,a=!!s;let o=V(!1),l=V(!1),c=V(!1),_=V(!1),g=V(!1),I=V("en-US"),N=V("browser"),$=V(null),L=V(null),S=null,ve=null,ye=null,fe=null,oe=null,Ie=[],Re="",Fe=!1;const he=[{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)"}];yr(()=>{const y=localStorage.getItem("wherever-speech-direct-send");y!==null&&p(g,y==="true");const z=localStorage.getItem("wherever-speech-locale");z!==null&&p(I,z,!0);const R=localStorage.getItem("wherever-speech-engine");return R!==null?p(N,R,!0):a||p(N,"cloud"),()=>{if(S)try{S.abort()}catch{}if(fe)try{fe.disconnect()}catch{}if(ye)try{ye.disconnect()}catch{}if(oe)try{oe.getTracks().forEach(Z=>Z.stop())}catch{}if(ve)try{ve.close()}catch{}t(L)&&clearTimeout(t(L))}});function $e(){localStorage.setItem("wherever-speech-direct-send",String(t(g))),localStorage.setItem("wherever-speech-locale",t(I)),localStorage.setItem("wherever-speech-engine",t(N))}function ot(){const y=localStorage.getItem("wherever-config");if(y){const z=JSON.parse(y),R=window.location.protocol==="https:"?"https:":"http:",Z=z.host.startsWith("http")?z.host.replace(/^wss?:\/\//,""):z.host;return`${R}//${Z}:${z.port}`}return`${window.location.protocol}//${window.location.host}`}function me(){try{const y=localStorage.getItem("wherever-config");if(y)return JSON.parse(y).token||""}catch{}return""}function Ue(){try{const y=window.AudioContext||window.webkitAudioContext;if(!y)return;const z=new y,R=z.createOscillator(),Z=z.createGain();R.type="sine",R.frequency.setValueAtTime(400,z.currentTime),Z.gain.setValueAtTime(.08,z.currentTime),Z.gain.exponentialRampToValueAtTime(.001,z.currentTime+.12),R.connect(Z),Z.connect(z.destination),R.start(),R.stop(z.currentTime+.12)}catch(y){console.warn("Could not play audio beep feedback:",y)}}function Me(y,z,R){if(z===R)return y;const Z=z/R,q=Math.round(y.length/Z),re=new Float32Array(q);let ee=0,Qe=0;for(;ee<re.length;){const He=Math.round((ee+1)*Z);let ut=0,bt=0;for(let et=Qe;et<He&&et<y.length;et++)ut+=y[et],bt++;re[ee]=bt>0?ut/bt:0,ee++,Qe=He}return re}function Le(){if(a)try{S=new s,S.continuous=!0,S.interimResults=!0,S.lang=t(I),S.onstart=()=>{p(o,!0),p(l,!1),Ue()},S.onresult=y=>{let z="",R="";for(let q=y.resultIndex;q<y.results.length;++q){const re=y.results[q];re.isFinal?z+=re[0].transcript:R+=re[0].transcript}const Z=(z+R).trim();Z&&(Fe=!0,r(Re+(Re?" ":"")+Z))},S.onerror=y=>{console.error("Browser speech recognition error:",y.error),y.error!=="no-speech"&&p($,`Error: ${y.error}`),dt()},S.onend=()=>{p(o,!1),t(g)&&Fe&&e.onSend&&setTimeout(()=>{r().trim()&&e.onSend()},50)},S.start(),navigator.vibrate&&navigator.vibrate(40)}catch(y){console.error("Failed to start browser speech recognition:",y),p($,"Failed to start browser recording"),p(o,!1)}}function dt(){if(S)try{S.stop()}catch{}p(o,!1)}async function ft(){try{const y=await navigator.mediaDevices.getUserMedia({audio:!0});oe=y,Ie=[];const z=window.AudioContext||window.webkitAudioContext;ve=new z,ye=ve.createMediaStreamSource(y),fe=ve.createScriptProcessor(4096,1,1),fe.onaudioprocess=R=>{const Z=R.inputBuffer.getChannelData(0);Ie.push(new Float32Array(Z))},ye.connect(fe),fe.connect(ve.destination),p(o,!0),p(l,!1),Ue(),navigator.vibrate&&navigator.vibrate(40)}catch(y){console.error("Failed to start cloud audio recording:",y),p($,y.message||"Microphone access denied",!0),p(o,!1),p(l,!1)}}function pt(){if(t(o)){if(p(o,!1),p(l,!0),fe){try{fe.disconnect()}catch{}fe.onaudioprocess=null}if(ye)try{ye.disconnect()}catch{}if(oe)try{oe.getTracks().forEach(y=>y.stop())}catch{}be()}}async function be(){try{if(Ie.length===0){p(l,!1);return}p($,null);let y=0;for(const Oe of Ie)y+=Oe.length;const z=new Float32Array(y);let R=0;for(const Oe of Ie)z.set(Oe,R),R+=Oe.length;const Z=ve?ve.sampleRate:48e3,q=16e3,re=Me(z,Z,q),ee=nn(re,1,q,1,16),Qe=new Blob([ee],{type:"audio/wav"}),He=ot(),ut=me(),bt=`${He}/session/transcribe${ut?`?token=${encodeURIComponent(ut)}`:""}`,et=await fetch(bt,{method:"POST",body:Qe,headers:{"Content-Type":"application/octet-stream"}}),rt=await et.json();if(!et.ok)throw new Error(rt.error||`HTTP ${et.status}`);rt.text&&rt.text.trim()&&(Fe=!0,r(Re+(Re?" ":"")+rt.text.trim()),t(g)&&e.onSend&&setTimeout(()=>{r().trim()&&e.onSend()},50))}catch(y){console.error("Cloud transcription request failed:",y),p($,y.message||"Cloud API failed",!0)}finally{if(p(l,!1),ve){try{ve.close()}catch{}ve=null}}}function Se(){e.disabled||t(o)||t(l)||(p($,null),Fe=!1,Re=r(),t(N)==="cloud"?ft():Le())}function Te(){t(N)==="cloud"?pt():dt()}function Dt(y){if(y.button===0&&!e.disabled){if(y.preventDefault(),t(o)){Te();return}p(c,!1),p(L,setTimeout(()=>{p(c,!0),Se()},350),!0)}}function Xe(y){t(L)&&(clearTimeout(t(L)),p(L,null)),t(c)?(p(c,!1),Te()):t(o)||Se()}function ze(){t(L)&&(clearTimeout(t(L)),p(L,null)),t(c)&&(p(c,!1),Te())}function nn(y,z,R,Z,q){const re=new ArrayBuffer(44+y.length*2),ee=new DataView(re);return Tt(ee,0,"RIFF"),ee.setUint32(4,36+y.length*2,!0),Tt(ee,8,"WAVE"),Tt(ee,12,"fmt "),ee.setUint32(16,16,!0),ee.setUint16(20,Z,!0),ee.setUint16(22,z,!0),ee.setUint32(24,R,!0),ee.setUint32(28,R*z*(q/8),!0),ee.setUint16(32,z*(q/8),!0),ee.setUint16(34,q,!0),Tt(ee,36,"data"),ee.setUint32(40,y.length*2,!0),Ve(ee,44,y),re}function Ve(y,z,R){for(let Z=0;Z<R.length;Z++,z+=2){let q=Math.max(-1,Math.min(1,R[Z]));y.setInt16(z,q<0?q*32768:q*32767,!0)}}function Tt(y,z,R){for(let Z=0;Z<R.length;Z++)y.setUint8(z+Z,R.charCodeAt(Z))}var Nt=Ac(),ht=u(Nt),kt=f(ht,2),Mt=u(kt);d(kt);var St=f(kt,2);{var Y=y=>{var z=Tc(),R=Ht(z),Z=f(R,2),q=f(u(Z),2),re=f(u(q),2),ee=u(re),Qe=f(ee,2);d(re);var He=f(re,2),ut=u(He,!0);d(He),d(q);var bt=f(q,2);{var et=At=>{var mt=kc(),xt=f(u(mt),2);pn(xt,21,()=>he,An,(Zt,Ce)=>{var Ze=wc(),Pt=u(Ze,!0);d(Ze);var _t={};j(()=>{ue(Pt,t(Ce).label),_t!==(_t=t(Ce).code)&&(Ze.value=(Ze.__value=t(Ce).code)??"")}),h(Zt,Ze)}),d(xt),d(mt),W("change",xt,$e),$r(xt,()=>t(I),Zt=>p(I,Zt)),h(At,mt)};C(bt,At=>{t(N)==="browser"&&At(et)})}var rt=f(bt,2),Oe=u(rt),Be=u(Oe);at(Be),it(2),d(Oe),it(2),d(rt);var Wt=f(rt,2);{var Ft=At=>{var mt=Sc(),xt=u(mt,!0);d(mt),j(()=>ue(xt,t($))),h(At,mt)};C(Wt,At=>{t($)&&At(Ft)})}d(Z),j(()=>{ee.disabled=!a,qt(ee,1,`flex-1 rounded border px-2 py-1.5 text-center font-medium transition-colors disabled:opacity-40
72
72
  ${t(N)==="browser"?"border-blue-500 bg-blue-600 text-white":"border-gray-600 bg-gray-950 text-gray-400 hover:text-white"}`),qt(Qe,1,`flex-1 rounded border px-2 py-1.5 text-center font-medium transition-colors
73
- ${t(N)==="cloud"?"border-blue-500 bg-blue-600 text-white":"border-gray-600 bg-gray-950 text-gray-400 hover:text-white"}`),ue(ut,t(N)==="browser"?"Uses free built-in browser dictation. Streaming, zero-latency.":"Uses server-side Z.ai / Groq / OpenAI keys. High accent tolerance.")}),W("click",R,()=>p(_,!1)),W("click",ee,()=>{p(N,"browser"),$e()}),W("click",Qe,()=>{p(N,"cloud"),$e()}),W("change",Be,$e),vn(Be,()=>t(v),At=>p(v,At)),h(y,z)};C(St,y=>{t(_)&&y(Y)})}d(Nt),j(()=>{ht.disabled=e.disabled&&!t(o)&&!t(l)||t(l),qt(ht,1,`flex h-[48px] w-[48px] items-center justify-center rounded-lg border transition-all duration-150 disabled:cursor-not-allowed disabled:opacity-40
74
- ${t(o)?"animate-pulse border-red-500 bg-red-600 text-white":t(l)?"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"}`),je(ht,"title",t(o)?"Recording (release/tap to stop)...":t(l)?"Processing speech...":"Hold to speak (walkie-talkie) or Tap to toggle recording"),kt.disabled=e.disabled&&!t(o)&&!t(l)||t(l),qt(Mt,0,`h-4 w-4 transition-transform duration-200 ${t(_)?"rotate-45 text-white":""}`)}),W("pointerdown",ht,Dt),W("pointerup",ht,Xe),Nn("pointercancel",ht,ze),W("click",kt,()=>p(_,!t(_))),h(n,Nt),Un()}Gn(["pointerdown","pointerup","click","change"]);var Rc=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),Cc=m('<span class="text-rose-400">⚠️</span> <span class="text-rose-400/80"> </span>',1),Ic=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),$c=m('<div class="mb-2.5 flex items-center gap-1.5 text-xs font-medium text-brand-text-muted select-none"><!></div>'),Mc=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>'),Lc=m('<span class="inline-block h-3 w-3 animate-spin rounded-full border-2 border-brand-blue border-t-transparent"></span>'),Oc=m('<a target="_blank" class="ml-1 shrink-0 font-semibold text-brand-blue underline hover:opacity-80">[Test Link]</a>'),Dc=m('<span class="flex items-center gap-1 text-[10px] font-medium text-rose-400"><span class="max-w-[120px] truncate"> </span> <!></span>'),Pc=m('<span class="text-emerald-400">✓</span>'),Nc=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>'),Fc=m('<div class="mb-3 flex flex-wrap gap-2"></div>'),Uc=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),zc=m('<button type="button" class="flex h-[40px] w-full items-center justify-center rounded-lg bg-amber-500 text-xs font-medium text-brand-text transition-colors hover:bg-amber-600">Unqueue</button>'),Hc=m('<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>'),Bc=m('<span class="hidden font-mono opacity-60 sm:inline">Shift+Enter to send</span>'),Wc=m('<!> <form class="flex items-stretch gap-3"><div class="min-w-0 flex-1"><textarea></textarea></div> <div class="flex w-[80px] shrink-0 flex-col justify-end gap-2"><!> <div class="flex w-full justify-center"><!></div> <!></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),Gc=m('<div class="border-t border-brand-border p-4"><!> <!></div>');function jc(n,e){Fn(e,!0);const r=()=>qe(As,"$isStreaming",c),s=()=>qe(Rs,"$isReadOnly",c),a=()=>qe(Sr,"$activeSessionInfo",c),o=()=>qe(kr,"$isConnected",c),l=()=>qe($t,"$piState",c),[c,_]=rr();let v=br(e,"showAttach",3,!0),I=br(e,"searchMode",3,!1),N=br(e,"searchConfigured",3,!1),$=V(""),L=V(!0),S=V(null),ge=V(null),ye=V(!1),fe=V(void 0),oe=V(wn([])),Ie=se(r),Re=se(s),Ne=se(a),he=se(o),$e=se(l),ot=se(()=>I()?e.disabled||!t(he)||!N():e.disabled||!t(he)||t(Re)||!t(Ne).sessionId||!!t(S)),me=se(()=>t(oe).some(Y=>Y.uploading)),Ue=se(()=>!t(ot)&&!t(me)&&(t($).trim().length>0||t(oe).length>0)),Me=V(void 0);const Fe="wherever-draft:";let dt=se(()=>Fe+(t(Ne).sessionId??"search")),ft=V(null);yr(()=>{const Y=localStorage.getItem("wherever-enter-to-send");Y!==null&&p(L,Y==="true")}),Rt(()=>{const Y=t(dt);Y!==t(ft)&&vs(()=>{let y=null;if(typeof localStorage<"u")try{y=localStorage.getItem(Y)}catch{}t(S)||p($,y??"",!0),p(ft,Y,!0)})}),Rt(()=>{const Y=t($),y=t(dt);if(!(y!==t(ft)||typeof localStorage>"u"))try{Y.trim().length>0?localStorage.setItem(y,Y):localStorage.removeItem(y)}catch{}});function pt(){t(ye)&&p(ye,!1),t(Me)?.focus()}function be(){p(L,!t(L)),localStorage.setItem("wherever-enter-to-send",String(t(L)))}Rt(()=>{t(Me)&&(t($),t(Me).style.height="auto",t(Me).style.height=`${t(Me).scrollHeight}px`)}),Rt(()=>{!t(ot)&&t(Me)&&t(Me).focus()}),Rt(()=>{t(S)&&p($,t(S),!0)}),Rt(()=>{!t(Ie)&&t(S)&&t(he)&&os(t(S))&&(p($,""),p(S,null),p(ge,null),e.onSend?.())});function Se(){const Y=t(ge)??t(S)??"";p(S,null),p(ge,null),p($,Y,!0),setTimeout(()=>{t(Me)?.focus(),t(Me)&&(t(Me).selectionStart=t(Me).selectionEnd=t($).length)},0)}async function Te(Y){Ss();const y=Y.target;if(!y.files)return;const z=Array.from(y.files);y.value="";const R=t(oe).length;p(oe,[...t(oe),...z.map(Z=>({name:Z.name,uploading:!0}))],!0);for(let Z=0;Z<z.length;Z++){const q=z[Z],re=R+Z;try{if(!t(Ne).sessionId)throw new Error("No active session");const ee=await za(t(Ne).sessionId,q);p(oe,t(oe).map((Qe,He)=>He===re?{name:q.name,path:ee.savedPath,uploading:!1}:Qe),!0)}catch(ee){const Qe=ee.message||"Failed to upload";console.error("File upload error details:",ee);let He="";try{const ut=Cn(),bt=In();He=`${ut}/health${bt?`?token=${encodeURIComponent(bt)}`:""}`}catch{}p(oe,t(oe).map((ut,bt)=>bt===re?{name:q.name,error:Qe,url:He,uploading:!1}:ut),!0)}}}function Dt(Y){p(oe,t(oe).filter((y,z)=>z!==Y),!0)}function Xe(){const Y=t($).trim();if(I()){if(!Y||t(ot))return;e.onSubmit?.(Y),p($,""),e.onSend?.();return}if(!Y&&t(oe).length===0)return;let y=Y;if(t(oe).length>0){const z=t(oe).filter(R=>R.path);if(z.length>0){const R=z.map(Z=>`[Uploaded file: ${Z.path}]`).join(`
73
+ ${t(N)==="cloud"?"border-blue-500 bg-blue-600 text-white":"border-gray-600 bg-gray-950 text-gray-400 hover:text-white"}`),ue(ut,t(N)==="browser"?"Uses free built-in browser dictation. Streaming, zero-latency.":"Uses server-side Z.ai / Groq / OpenAI keys. High accent tolerance.")}),W("click",R,()=>p(_,!1)),W("click",ee,()=>{p(N,"browser"),$e()}),W("click",Qe,()=>{p(N,"cloud"),$e()}),W("change",Be,$e),gn(Be,()=>t(g),At=>p(g,At)),h(y,z)};C(St,y=>{t(_)&&y(Y)})}d(Nt),j(()=>{ht.disabled=e.disabled&&!t(o)&&!t(l)||t(l),qt(ht,1,`flex h-[48px] w-[48px] items-center justify-center rounded-lg border transition-all duration-150 disabled:cursor-not-allowed disabled:opacity-40
74
+ ${t(o)?"animate-pulse border-red-500 bg-red-600 text-white":t(l)?"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"}`),je(ht,"title",t(o)?"Recording (release/tap to stop)...":t(l)?"Processing speech...":"Hold to speak (walkie-talkie) or Tap to toggle recording"),kt.disabled=e.disabled&&!t(o)&&!t(l)||t(l),qt(Mt,0,`h-4 w-4 transition-transform duration-200 ${t(_)?"rotate-45 text-white":""}`)}),W("pointerdown",ht,Dt),W("pointerup",ht,Xe),Nn("pointercancel",ht,ze),W("click",kt,()=>p(_,!t(_))),h(n,Nt),Un()}Gn(["pointerdown","pointerup","click","change"]);var Rc=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),Cc=m('<span class="text-rose-400">⚠️</span> <span class="text-rose-400/80"> </span>',1),Ic=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),$c=m('<div class="mb-2.5 flex items-center gap-1.5 text-xs font-medium text-brand-text-muted select-none"><!></div>'),Mc=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>'),Lc=m('<span class="inline-block h-3 w-3 animate-spin rounded-full border-2 border-brand-blue border-t-transparent"></span>'),Oc=m('<a target="_blank" class="ml-1 shrink-0 font-semibold text-brand-blue underline hover:opacity-80">[Test Link]</a>'),Dc=m('<span class="flex items-center gap-1 text-[10px] font-medium text-rose-400"><span class="max-w-[120px] truncate"> </span> <!></span>'),Pc=m('<span class="text-emerald-400">✓</span>'),Nc=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>'),Fc=m('<div class="mb-3 flex flex-wrap gap-2"></div>'),Uc=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),zc=m('<button type="button" class="flex h-[40px] w-full items-center justify-center rounded-lg bg-amber-500 text-xs font-medium text-brand-text transition-colors hover:bg-amber-600">Unqueue</button>'),Hc=m('<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>'),Bc=m('<span class="hidden font-mono opacity-60 sm:inline">Shift+Enter to send</span>'),Wc=m('<!> <form class="flex items-stretch gap-3"><div class="min-w-0 flex-1"><textarea></textarea></div> <div class="flex w-[80px] shrink-0 flex-col justify-end gap-2"><!> <div class="flex w-full justify-center"><!></div> <!></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),Gc=m('<div class="border-t border-brand-border p-4"><!> <!></div>');function jc(n,e){Fn(e,!0);const r=()=>qe(As,"$isStreaming",c),s=()=>qe(Rs,"$isReadOnly",c),a=()=>qe(Sr,"$activeSessionInfo",c),o=()=>qe(kr,"$isConnected",c),l=()=>qe($t,"$piState",c),[c,_]=rr();let g=br(e,"showAttach",3,!0),I=br(e,"searchMode",3,!1),N=br(e,"searchConfigured",3,!1),$=V(""),L=V(!0),S=V(null),ve=V(null),ye=V(!1),fe=V(void 0),oe=V(wn([])),Ie=se(r),Re=se(s),Fe=se(a),he=se(o),$e=se(l),ot=se(()=>I()?e.disabled||!t(he)||!N():e.disabled||!t(he)||t(Re)||!t(Fe).sessionId||!!t(S)),me=se(()=>t(oe).some(Y=>Y.uploading)),Ue=se(()=>!t(ot)&&!t(me)&&(t($).trim().length>0||t(oe).length>0)),Me=V(void 0);const Le="wherever-draft:";let dt=se(()=>Le+(t(Fe).sessionId??"search")),ft=V(null);yr(()=>{const Y=localStorage.getItem("wherever-enter-to-send");Y!==null&&p(L,Y==="true")}),Rt(()=>{const Y=t(dt);Y!==t(ft)&&gs(()=>{let y=null;if(typeof localStorage<"u")try{y=localStorage.getItem(Y)}catch{}t(S)||p($,y??"",!0),p(ft,Y,!0)})}),Rt(()=>{const Y=t($),y=t(dt);if(!(y!==t(ft)||typeof localStorage>"u"))try{Y.trim().length>0?localStorage.setItem(y,Y):localStorage.removeItem(y)}catch{}});function pt(){t(ye)&&p(ye,!1),t(Me)?.focus()}function be(){p(L,!t(L)),localStorage.setItem("wherever-enter-to-send",String(t(L)))}Rt(()=>{t(Me)&&(t($),t(Me).style.height="auto",t(Me).style.height=`${t(Me).scrollHeight}px`)}),Rt(()=>{!t(ot)&&t(Me)&&t(Me).focus()}),Rt(()=>{t(S)&&p($,t(S),!0)}),Rt(()=>{!t(Ie)&&t(S)&&t(he)&&os(t(S))&&(p($,""),p(S,null),p(ve,null),e.onSend?.())});function Se(){const Y=t(ve)??t(S)??"";p(S,null),p(ve,null),p($,Y,!0),setTimeout(()=>{t(Me)?.focus(),t(Me)&&(t(Me).selectionStart=t(Me).selectionEnd=t($).length)},0)}async function Te(Y){Ss();const y=Y.target;if(!y.files)return;const z=Array.from(y.files);y.value="";const R=t(oe).length;p(oe,[...t(oe),...z.map(Z=>({name:Z.name,uploading:!0}))],!0);for(let Z=0;Z<z.length;Z++){const q=z[Z],re=R+Z;try{if(!t(Fe).sessionId)throw new Error("No active session");const ee=await za(t(Fe).sessionId,q);p(oe,t(oe).map((Qe,He)=>He===re?{name:q.name,path:ee.savedPath,uploading:!1}:Qe),!0)}catch(ee){const Qe=ee.message||"Failed to upload";console.error("File upload error details:",ee);let He="";try{const ut=Cn(),bt=In();He=`${ut}/health${bt?`?token=${encodeURIComponent(bt)}`:""}`}catch{}p(oe,t(oe).map((ut,bt)=>bt===re?{name:q.name,error:Qe,url:He,uploading:!1}:ut),!0)}}}function Dt(Y){p(oe,t(oe).filter((y,z)=>z!==Y),!0)}function Xe(){const Y=t($).trim();if(I()){if(!Y||t(ot))return;e.onSubmit?.(Y),p($,""),e.onSend?.();return}if(!Y&&t(oe).length===0)return;let y=Y;if(t(oe).length>0){const z=t(oe).filter(R=>R.path);if(z.length>0){const R=z.map(Z=>`[Uploaded file: ${Z.path}]`).join(`
75
75
  `);y?y+=`
76
76
 
77
77
  `+R:y=`I have uploaded the following file(s) for you:
78
- ${R}`}}if(Y.startsWith("/")&&t(oe).length===0){const z=Y.toLowerCase();if(z==="/new"||z==="/reset"){if(t(Ne).cwd){kn(t(Ne).cwd,t(Ne).model||void 0),p($,""),p(S,null);return}}else if(z==="/clear"){$a(),p($,""),p(S,null);return}else if(z==="/leave"||z==="/exit"){bn(),p($,""),p(S,null);return}}t(Ie)&&t(he)?(p(S,y,!0),p(ge,y,!0),p(oe,[],!0)):os(y)&&(p($,""),p(oe,[],!0),e.onSend?.())}function ze(Y){Y.key==="Enter"&&(t(L)?Y.shiftKey||(Y.preventDefault(),Xe()):Y.shiftKey&&(Y.preventDefault(),Xe()))}var nn={focusInput:pt},Ve=Gc(),Tt=u(Ve);{var Nt=Y=>{var y=$c(),z=u(y);{var R=re=>{var ee=Rc();it(2),h(re,ee)},Z=re=>{var ee=Cc(),Qe=f(Ht(ee),2),He=u(Qe,!0);d(Qe),j(()=>ue(He,t($e).error)),h(re,ee)},q=re=>{var ee=Ic();it(2),h(re,ee)};C(z,re=>{t($e).connecting?re(R):t($e).error?re(Z,1):t(he)||re(q,2)})}d(y),h(Y,y)};C(Tt,Y=>{(!t(he)||t($e).connecting||t($e).error)&&Y(Nt)})}var ht=f(Tt,2);{var kt=Y=>{var y=Mc(),z=u(y),R=u(z),Z=u(R),q=u(Z,!0);d(Z);var re=f(Z,2),ee=u(re);{var Qe=Le=>{var Be=on();j(()=>ue(Be,e.placeholder??"Search the web...")),h(Le,Be)},He=Le=>{var Be=on("Message is queued...");h(Le,Be)},ut=Le=>{var Be=on("Agent is working (click to type next)...");h(Le,Be)},bt=Le=>{var Be=on("Read-only mode");h(Le,Be)},et=Le=>{var Be=on("Select a session first...");h(Le,Be)},rt=Le=>{var Be=on("Tap to type a message...");h(Le,Be)};C(ee,Le=>{I()?Le(Qe):t(S)?Le(He,1):t(Ie)?Le(ut,2):t(Re)?Le(bt,3):t(Ne).sessionId?Le(rt,-1):Le(et,4)})}d(re),d(R),it(2),d(z),d(y),j(()=>ue(q,I()?"🔍":"💬")),W("click",z,()=>{p(ye,!1),setTimeout(()=>t(Me)?.focus(),50)}),h(Y,y)},Mt=Y=>{var y=Wc(),z=Ht(y);{var R=Ce=>{var Ze=Fc();pn(Ze,21,()=>t(oe),An,(Pt,_t,Xt)=>{var Kt=Nc(),vt=u(Kt),gt=u(vt,!0);d(vt);var ln=f(vt,2);{var an=E=>{var x=Lc();h(E,x)},cn=E=>{var x=Dc(),w=u(x),O=u(w);d(w);var Q=f(w,2);{var We=we=>{var ie=Oc();j(()=>je(ie,"href",t(_t).url)),h(we,ie)};C(Q,we=>{t(_t).url&&we(We)})}d(x),j(()=>{je(x,"title",t(_t).error),ue(O,`⚠️ ${t(_t).error??""}`)}),h(E,x)},rn=E=>{var x=Pc();h(E,x)};C(ln,E=>{t(_t).uploading?E(an):t(_t).error?E(cn,1):E(rn,-1)})}var dn=f(ln,2);d(Kt),j(()=>{je(vt,"title",t(_t).name),ue(gt,t(_t).name)}),W("click",dn,()=>Dt(Xt)),h(Pt,Kt)}),d(Ze),h(Ce,Ze)};C(z,Ce=>{t(oe).length>0&&Ce(R)})}var Z=f(z,2),q=u(Z),re=u(q);yo(re),je(re,"rows",1),En(re,Ce=>p(Me,Ce),()=>t(Me)),d(q);var ee=f(q,2),Qe=u(ee);{var He=Ce=>{var Ze=Uc(),Pt=Ht(Ze),_t=f(Pt,2);En(_t,Xt=>p(fe,Xt),()=>t(fe)),j(()=>Pt.disabled=t(ot)),W("click",Pt,()=>{Ta(),t(fe)?.click()}),W("change",_t,Te),h(Ce,Ze)};C(Qe,Ce=>{v()&&!I()&&Ce(He)})}var ut=f(Qe,2),bt=u(ut);Ec(bt,{get disabled(){return t(ot)},onSend:Xe,get text(){return t($)},set text(Ce){p($,Ce,!0)}}),d(ut);var et=f(ut,2);{var rt=Ce=>{var Ze=zc();W("click",Ze,Se),h(Ce,Ze)},Le=Ce=>{var Ze=Hc(),Pt=u(Ze);{var _t=vt=>{var gt=on();j(()=>ue(gt,e.submitLabel??"Search")),h(vt,gt)},Xt=vt=>{var gt=on("Queue");h(vt,gt)},Kt=vt=>{var gt=on("Send");h(vt,gt)};C(Pt,vt=>{I()?vt(_t):t(Ie)?vt(Xt,1):vt(Kt,-1)})}d(Ze),j(()=>Ze.disabled=!t(Ue)),h(Ce,Ze)};C(et,Ce=>{t(S)?Ce(rt):Ce(Le,-1)})}d(ee),d(Z);var Be=f(Z,2),Wt=u(Be),Ft=u(Wt);at(Ft),it(2),d(Wt);var At=f(Wt,2),mt=u(At),xt=f(mt,2);{var Zt=Ce=>{var Ze=Bc();h(Ce,Ze)};C(xt,Ce=>{t(L)||Ce(Zt)})}d(At),d(Be),j(()=>{re.disabled=t(ot),je(re,"placeholder",I()?e.placeholder??"Search the web...":t(he)?t(Ie)?"Agent is working (type next message...)":t(Re)?"Read-only mode":t(Ne).sessionId?"Type a message...":"Select a session first...":t($e).connecting?"Reconnecting to remote server...":"Disconnected - cannot send"),qt(re,1,`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 placeholder-brand-text-muted focus:border-brand-blue focus:outline-none disabled:opacity-50 ${t(S)?"text-brand-text-muted italic":"text-brand-text"}`),es(Ft,t(L))}),Nn("submit",Z,Ce=>{Ce.preventDefault(),Xe()}),W("keydown",re,ze),Rn(re,()=>t($),Ce=>p($,Ce)),W("change",Ft,be),W("click",mt,()=>p(ye,!0)),h(Y,y)};C(ht,Y=>{t(ye)?Y(kt):Y(Mt,-1)})}d(Ve),h(n,Ve);var St=Un(nn);return _(),St}Gn(["click","keydown","change"]);var qc=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>'),Vc=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>'),Yc=m('<span class="ml-1 font-semibold text-emerald-400">(Git repo)</span>'),Zc=m('<span class="mt-1 block text-[10px] font-medium text-yellow-400">📁 Folder already exists. <!></span>'),Kc=m("<option> </option>"),Xc=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>'),Qc=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"/>'),Jc=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>'),ed=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>'),td=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>'),nd=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>'),rd=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>'),sd=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>'),ad=m('<div class="p-4 text-center text-sm text-brand-text-muted"> </div>'),od=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>'),id=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>'),ld=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>'),cd=m('<span class="h-2 w-2 flex-shrink-0 rounded-full bg-emerald-500"></span>'),dd=m('<span class="h-2 w-2 flex-shrink-0 rounded-full bg-brand-surface-3"></span>'),ud=m('<span class="rounded bg-brand-surface-3 px-1.5 py-0.5 text-xs text-brand-text"> </span>'),fd=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>'),pd=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>'),hd=m('<div class="flex-shrink-0"><!></div>'),bd=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>'),vd=m('<div class="px-3 pb-2"><!> <!></div>'),gd=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>'),md=m("<option> </option>"),xd=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>'),_d=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"/>'),yd=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>'),wd=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>'),kd=m('<span class="ml-1 text-[10px] text-brand-text-muted">(already a Git repo)</span>'),Sd=m('<span class="ml-1 text-[10px] font-medium text-yellow-500">(folder not empty)</span>'),Td=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>'),Ad=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>'),Ed=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>'),Rd=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 pa(n,e){Fn(e,!0);const r=()=>qe(fr,"$readOnlySessionFolders",N),s=()=>qe(er,"$sessionFolders",N),a=()=>qe(Sr,"$activeSessionInfo",N),o=()=>qe(kr,"$isConnected",N),l=()=>qe(Nr,"$isLoadingSession",N),c=()=>qe(Cs,"$isResyncing",N),_=()=>qe(tr,"$availableModels",N),v=()=>qe(xs,"$gitInitDefaultStore",N),I=()=>qe(Es,"$sessionError",N),[N,$]=rr(),L=[];let S=br(e,"readOnly",3,!1),ge=se(()=>S()?r().folders:s().folders),ye=se(()=>S()?r().loading:s().loading);function fe(){S()?_a():gr()}let oe=se(()=>a().sessionFile),Ie=se(o),Re=se(l),Ne=se(c),he=se(()=>_().models),$e=wn({}),ot=V(wn({})),me=V(null),Ue=V(null),Me=V(""),Fe=V(wn([]));Rt(()=>{t(Ie)&&(fe(),S()||(Wo(),Go()))});function dt(E,x,w){if(!w)return!0;const O=w.toLowerCase();return(E.name||"").toLowerCase().includes(O)||E.firstMessage.toLowerCase().includes(O)||x.toLowerCase().includes(O)}Rt(()=>{const E=t(Me),x=t(ge);E?p(Fe,x.map(w=>({...w,sessions:w.sessions.filter(O=>dt(O,w.name,E))})).filter(w=>w.sessions.length>0),!0):(p(Fe,x,!0),p(ot,{},!0))});function ft(E){return t(Me)?t(ot)[E]!==void 0?t(ot)[E]:!0:!!$e[E]}function pt(E){t(Me)?t(ot)[E]=!ft(E):$e[E]=!ft(E)}async function be(E){try{t(oe)===E&&(typeof window<"u"&&(window.location.hash=""),bn()),await ds(E),t(me)===E&&p(me,null),gr()}catch(x){console.error("Failed to delete session:",x)}}async function Se(E){try{const x=E.sessions.map(w=>w.path);t(oe)&&x.includes(t(oe))&&(typeof window<"u"&&(window.location.hash=""),bn()),await Promise.all(E.sessions.map(w=>ds(w.path))),t(Ue)===E.path&&p(Ue,null),gr()}catch(x){console.error("Failed to delete all sessions of folder:",x)}}function Te(E){t(oe)===E&&!t(Re)&&!t(Ne)||(Bn(),Ts(E))}let Dt=V(!1),Xe=V(""),ze=V(wn([])),nn=V(!1),Ve=V(null),Tt=V(null),Nt="",ht=V(""),kt=V(!1),Mt=V(null),St=V(!0),Y=V("private"),y=V(!1),z=se(v);Rt(()=>{t(Mt)===null&&p(kt,t(z),!0)});let R=V(wn({exists:null,isGit:!1,resolvedPath:"",matchingRule:null})),Z=se(()=>t(R).exists!==!0&&t(R).matchingRule&&t(St)),q=null;async function re(E,x=!1){if(q&&clearTimeout(q),E===Nt&&!x)return;if(Nt=E,!E.trim()){p(R,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0);const O=async()=>{const Q=await Mr("");p(ze,Q||[],!0)};x?await O():q=setTimeout(O,300);return}const w=async()=>{const[O,Q]=await Promise.all([ka(E),Mr(E)]);p(ze,Q||[],!0),O?(p(R,{exists:O.exists,isGit:O.isGit,resolvedPath:O.resolvedPath,matchingRule:O.matchingRule||null},!0),O.exists||(p(kt,t(Mt)!==null?t(Mt):t(z),!0),p(St,!0),O.matchingRule&&p(Y,O.matchingRule.visibility,!0))):p(R,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0)};x?await w():q=setTimeout(w,300)}Rt(()=>{const E=t(Xe);re(E,!1)}),Rt(()=>{if(t(he).length>0&&!t(ht)){const E=t(he).find(x=>x.isDefault);E?p(ht,`${E.provider}:${E.modelId}`):p(ht,`${t(he)[0].provider}:${t(he)[0].modelId}`)}});function ee(){if(t(Xe).trim())if(t(R).exists===!0)p(kt,!1),p(St,!1),t(R).matchingRule&&p(Y,t(R).matchingRule.visibility,!0),p(y,!0);else{Bn();const E=t(Xe).trim(),x=t(ht)||void 0,w=t(kt),O=t(R).matchingRule?t(St):void 0,Q=t(R).matchingRule?t(Y):void 0;p(Xe,""),p(Dt,!1),t(oe)?(bn(),setTimeout(()=>{kn(E,x,w,O,Q)},100)):kn(E,x,w,O,Q)}}function Qe(){p(y,!1),Bn();const E=t(Xe).trim(),x=t(ht)||void 0,w=t(kt),O=t(R).matchingRule?t(St):void 0,Q=t(R).matchingRule?t(Y):void 0;p(Xe,""),p(Dt,!1),t(oe)?(bn(),setTimeout(()=>{kn(E,x,w,O,Q)},100)):kn(E,x,w,O,Q)}let He=V(wn({open:!1,folderPath:"",selected:""}));function ut(E){const x=t(he).find(w=>w.isDefault);p(He,{open:!0,folderPath:E,selected:x?`${x.provider}:${x.modelId}`:""},!0)}function bt(){t(He).open=!1}function et(){if(!t(He).open)return;Bn();const E=t(He).folderPath,x=t(He).selected||void 0;bt(),t(oe)?(bn(),setTimeout(()=>{kn(E,x)},100)):kn(E,x)}function rt(E){const x=Date.now()-new Date(E).getTime(),w=Math.floor(x/6e4);if(w<1)return"just now";if(w<60)return`${w}m ago`;const O=Math.floor(w/60);return O<24?`${O}h ago`:`${Math.floor(O/24)}d ago`}function Le(E,x=40){return E.length>x?E.slice(0,x)+"...":E}var Be=Rd(),Wt=Ht(Be),Ft=u(Wt),At=u(Ft),mt=u(At);at(mt);var xt=f(mt,2),Zt=u(xt);d(xt),d(At),d(Ft);var Ce=f(Ft,2),Ze=u(Ce);{var Pt=E=>{var x=rd(),w=u(x),O=u(w),Q=u(O,!0);d(O),d(w);var We=f(w,2);{var we=ie=>{var g=nd(),k=u(g),H=f(u(k),2),D=u(H);at(D),En(D,B=>p(Ve,B),()=>t(Ve));var le=f(D,2);{var K=B=>{var U=Vc();pn(U,21,()=>t(ze),An,(ce,de)=>{var ve=qc(),ae=u(ve,!0);d(ve),j(()=>ue(ae,t(de))),W("click",ve,()=>{p(Xe,t(de),!0),re(t(de),!0),t(Ve)?.focus()}),h(ce,ve)}),d(U),h(B,U)};C(le,B=>{t(nn)&&t(ze).length>0&&B(K)})}d(H),En(H,B=>p(Tt,B),()=>t(Tt));var T=f(H,2);{var F=B=>{var U=Zc(),ce=f(u(U));{var de=ve=>{var ae=Yc();h(ve,ae)};C(ce,ve=>{t(R).isGit&&ve(de)})}d(U),h(B,U)};C(T,B=>{t(R).exists===!0&&B(F)})}d(k);var te=f(k,2),Oe=f(u(te),2);{var Ae=B=>{var U=Xc();pn(U,21,()=>t(he),An,(ce,de)=>{var ve=Kc(),ae=u(ve);d(ve);var G={};j(()=>{ue(ae,`${t(de).label??""}${t(de).isDefault?" (default)":""}`),G!==(G=`${t(de).provider}:${t(de).modelId}`)&&(ve.value=ve.__value=`${t(de).provider}:${t(de).modelId}`)}),h(ce,ve)}),d(U),$r(U,()=>t(ht),ce=>p(ht,ce)),h(B,U)},xe=B=>{var U=Qc();at(U),Rn(U,()=>t(ht),ce=>p(ht,ce)),h(B,U)};C(Oe,B=>{t(he).length>0?B(Ae):B(xe,-1)})}d(te);var st=f(te,2);{var It=B=>{var U=ed(),ce=u(U),de=u(ce);at(de);var ve=f(de,2),ae=u(ve);d(ve),d(ce);var G=f(ce,2);{var P=J=>{var _e=Jc(),Ee=f(u(_e),2),ne=u(Ee);at(ne),ne.value=ne.__value="private",it(),d(Ee);var ke=f(Ee,2),nt=u(ke);at(nt),nt.value=nt.__value="public",it(),d(ke),d(_e),Pn(L,[],ne,()=>t(Y),De=>p(Y,De)),Pn(L,[],nt,()=>t(Y),De=>p(Y,De)),h(J,_e)};C(G,J=>{t(St)&&J(P)})}d(U),j(()=>ue(ae,`Create remote ${t(R).matchingRule.provider??""} repository`)),vn(de,()=>t(St),J=>p(St,J)),h(B,U)};C(st,B=>{t(R).exists!==!0&&t(R).matchingRule&&B(It)})}var Ge=f(st,2);{var Ye=B=>{var U=td(),ce=u(U);at(ce),it(2),d(U),W("change",ce,de=>{p(Mt,de.currentTarget.checked,!0)}),vn(ce,()=>t(kt),de=>p(kt,de)),h(B,U)};C(Ge,B=>{t(R).exists!==!0&&(!t(R).matchingRule||!t(St))&&B(Ye)})}var pe=f(Ge,2);d(g),j(B=>{qt(D,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(Z)?"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"}`),pe.disabled=B},[()=>!t(Xe).trim()]),Nn("submit",g,B=>{B.preventDefault(),ee()}),Nn("focus",D,()=>{p(nn,!0),re(t(Xe),!0)}),Nn("blur",D,B=>{t(Tt)&&t(Tt).contains(B.relatedTarget)||p(nn,!1)}),W("keydown",D,B=>{B.key==="Escape"&&p(nn,!1)}),Rn(D,()=>t(Xe),B=>p(Xe,B)),h(ie,g)};C(We,ie=>{t(Dt)&&ie(we)})}d(x),j(()=>ue(Q,t(Dt)?"▼ Close Create Session":"✚ Create New Session")),W("click",w,()=>p(Dt,!t(Dt))),h(E,x)};C(Ze,E=>{S()||E(Pt)})}var _t=f(Ze,2);{var Xt=E=>{var x=sd();h(E,x)},Kt=E=>{var x=ad(),w=u(x,!0);d(x),j(()=>ue(w,t(Me)?"No sessions match your filter":"No sessions found")),h(E,x)},vt=E=>{var x=Jn(),w=Ht(x);pn(w,17,()=>t(Fe),O=>O.path,(O,Q)=>{var We=gd(),we=u(We),ie=u(we),g=f(ie,2),k=u(g),H=u(k,!0);d(k);var D=f(k,2),le=u(D,!0);d(D),d(g);var K=f(g,2),T=u(K,!0);d(K),d(we);var F=f(we,2);{var te=Ae=>{var xe=vd(),st=u(xe);{var It=Ye=>{var pe=ld(),B=u(pe),U=f(B,2),ce=u(U);{var de=ae=>{var G=od(),P=u(G),J=f(P,2);d(G),W("click",P,_e=>{_e.stopPropagation(),Se(t(Q))}),W("click",J,_e=>{_e.stopPropagation(),p(Ue,null)}),h(ae,G)},ve=ae=>{var G=id();W("click",G,P=>{P.stopPropagation(),p(Ue,t(Q).path,!0)}),h(ae,G)};C(ce,ae=>{t(Ue)===t(Q).path?ae(de):ae(ve,-1)})}d(U),d(pe),W("click",B,()=>ut(t(Q).path)),h(Ye,pe)};C(st,Ye=>{S()||Ye(It)})}var Ge=f(st,2);pn(Ge,17,()=>t(Q).sessions,Ye=>Ye.path,(Ye,pe)=>{var B=bd(),U=u(B),ce=u(U);{var de=De=>{var tt=cd();h(De,tt)},ve=De=>{var tt=dd();h(De,tt)};C(ce,De=>{t(pe).isActive?De(de):De(ve,-1)})}var ae=f(ce,2),G=u(ae),P=u(G,!0);d(G);var J=f(G,2),_e=u(J);d(J),d(ae);var Ee=f(ae,2);{var ne=De=>{var tt=ud(),Ut=u(tt,!0);d(tt),j(()=>ue(Ut,t(pe).clientCount)),h(De,tt)};C(Ee,De=>{t(pe).clientCount>0&&De(ne)})}d(U);var ke=f(U,2);{var nt=De=>{var tt=hd(),Ut=u(tt);{var un=Qt=>{var Jt=fd(),fn=u(Jt),Vn=f(fn,2);d(Jt),W("click",fn,mn=>{mn.stopPropagation(),be(t(pe).path)}),W("click",Vn,mn=>{mn.stopPropagation(),p(me,null)}),h(Qt,Jt)},gn=Qt=>{var Jt=pd();W("click",Jt,fn=>{fn.stopPropagation(),p(me,t(pe).path,!0)}),h(Qt,Jt)};C(Ut,Qt=>{t(me)===t(pe).path?Qt(un):Qt(gn,-1)})}d(tt),h(De,tt)};C(ke,De=>{S()||De(nt)})}d(B),j((De,tt,Ut)=>{qt(B,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(oe)===t(pe).path?"bg-brand-surface-3":""}`),je(U,"href",`#${De??""}`),ue(P,tt),ue(_e,`${Ut??""} · ${t(pe).messageCount??""}
79
- msgs`)},[()=>encodeURIComponent(t(pe).id),()=>t(pe).name||Le(t(pe).firstMessage)||"Empty session",()=>rt(t(pe).modified)]),W("click",U,De=>{De.button===0&&!De.ctrlKey&&!De.metaKey&&!De.altKey&&!De.shiftKey&&(De.preventDefault(),Te(t(pe).path))}),h(Ye,B)}),d(xe),h(Ae,xe)},Oe=se(()=>ft(t(Q).path));C(F,Ae=>{t(Oe)&&Ae(te)})}d(We),j(Ae=>{qt(ie,1,`text-xs text-brand-text-muted transition-transform ${Ae??""}`),ue(H,t(Q).name),ue(le,t(Q).path),ue(T,t(Q).sessions.length)},[()=>ft(t(Q).path)?"rotate-90":""]),W("click",we,()=>pt(t(Q).path)),h(O,We)}),h(E,x)};C(_t,E=>{t(ye)&&t(Fe).length===0?E(Xt):t(Fe).length===0?E(Kt,1):E(vt,-1)})}d(Ce),d(Wt);var gt=f(Wt,2);{var ln=E=>{var x=yd(),w=u(x),O=f(u(w),2),Q=f(u(O),2),We=u(Q,!0);d(Q),d(O);var we=f(O,2),ie=f(u(we),2);{var g=K=>{var T=xd();pn(T,21,()=>t(he),An,(F,te)=>{var Oe=md(),Ae=u(Oe);d(Oe);var xe={};j(()=>{ue(Ae,`${t(te).label??""}${t(te).isDefault?" (default)":""}`),xe!==(xe=`${t(te).provider}:${t(te).modelId}`)&&(Oe.value=Oe.__value=`${t(te).provider}:${t(te).modelId}`)}),h(F,Oe)}),d(T),$r(T,()=>t(He).selected,F=>t(He).selected=F),h(K,T)},k=K=>{var T=_d();at(T),Rn(T,()=>t(He).selected,F=>t(He).selected=F),h(K,T)};C(ie,K=>{t(he).length>0?K(g):K(k,-1)})}d(we);var H=f(we,2),D=u(H),le=f(D,2);d(H),d(w),d(x),j(()=>ue(We,t(He).folderPath)),W("click",x,bt),W("click",w,K=>K.stopPropagation()),W("click",D,bt),W("click",le,et),h(E,x)};C(gt,E=>{t(He).open&&E(ln)})}var an=f(gt,2);{var cn=E=>{var x=wd(),w=u(x),O=u(w,!0);d(w);var Q=f(w,2);d(x),j(()=>ue(O,I())),W("click",Q,()=>Bn()),h(E,x)};C(an,E=>{I()&&E(cn)})}var rn=f(an,2);{var dn=E=>{var x=Ed(),w=u(x),O=f(u(w),2),Q=f(u(O)),We=u(Q,!0);d(Q),it(),d(O);var we=f(O,2),ie=u(we),g=u(ie);at(g);var k=f(g,2),H=f(u(k));{var D=Ae=>{var xe=kd();h(Ae,xe)},le=Ae=>{var xe=Sd();h(Ae,xe)};C(H,Ae=>{t(R).isGit?Ae(D):Ae(le,-1)})}d(k),d(ie);var K=f(ie,2);{var T=Ae=>{var xe=Ad(),st=u(xe),It=u(st);at(It);var Ge=f(It,2),Ye=u(Ge);d(Ge),d(st);var pe=f(st,2);{var B=U=>{var ce=Td(),de=f(u(ce),2),ve=u(de);at(ve),ve.value=ve.__value="private",it(),d(de);var ae=f(de,2),G=u(ae);at(G),G.value=G.__value="public",it(),d(ae),d(ce),Pn(L,[],ve,()=>t(Y),P=>p(Y,P)),Pn(L,[],G,()=>t(Y),P=>p(Y,P)),h(U,ce)};C(pe,U=>{t(St)&&U(B)})}d(xe),j(()=>ue(Ye,`Create remote ${t(R).matchingRule.provider??""} repository`)),vn(It,()=>t(St),U=>p(St,U)),h(Ae,xe)};C(K,Ae=>{t(R).matchingRule&&Ae(T)})}d(we);var F=f(we,2),te=u(F),Oe=f(te,2);d(F),d(w),d(x),j(()=>{ue(We,t(Xe)),g.disabled=t(R).isGit}),vn(g,()=>t(kt),Ae=>p(kt,Ae)),W("click",te,()=>p(y,!1)),W("click",Oe,Qe),h(E,x)};C(rn,E=>{t(y)&&E(dn)})}j(()=>{ko(mt,t(Me)),qt(Zt,1,Co(t(ye)?"animate-spin":""))}),W("input",mt,E=>p(Me,E.currentTarget.value,!0)),W("click",xt,()=>fe()),h(n,Be),Un(),$()}Gn(["input","click","keydown","change"]);var Cd=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
78
+ ${R}`}}if(Y.startsWith("/")&&t(oe).length===0){const z=Y.toLowerCase();if(z==="/new"||z==="/reset"){if(t(Fe).cwd){kn(t(Fe).cwd,t(Fe).model||void 0),p($,""),p(S,null);return}}else if(z==="/clear"){$a(),p($,""),p(S,null);return}else if(z==="/leave"||z==="/exit"){bn(),p($,""),p(S,null);return}}t(Ie)&&t(he)?(p(S,y,!0),p(ve,y,!0),p(oe,[],!0)):os(y)&&(p($,""),p(oe,[],!0),e.onSend?.())}function ze(Y){Y.key==="Enter"&&(t(L)?Y.shiftKey||(Y.preventDefault(),Xe()):Y.shiftKey&&(Y.preventDefault(),Xe()))}var nn={focusInput:pt},Ve=Gc(),Tt=u(Ve);{var Nt=Y=>{var y=$c(),z=u(y);{var R=re=>{var ee=Rc();it(2),h(re,ee)},Z=re=>{var ee=Cc(),Qe=f(Ht(ee),2),He=u(Qe,!0);d(Qe),j(()=>ue(He,t($e).error)),h(re,ee)},q=re=>{var ee=Ic();it(2),h(re,ee)};C(z,re=>{t($e).connecting?re(R):t($e).error?re(Z,1):t(he)||re(q,2)})}d(y),h(Y,y)};C(Tt,Y=>{(!t(he)||t($e).connecting||t($e).error)&&Y(Nt)})}var ht=f(Tt,2);{var kt=Y=>{var y=Mc(),z=u(y),R=u(z),Z=u(R),q=u(Z,!0);d(Z);var re=f(Z,2),ee=u(re);{var Qe=Oe=>{var Be=on();j(()=>ue(Be,e.placeholder??"Search the web...")),h(Oe,Be)},He=Oe=>{var Be=on("Message is queued...");h(Oe,Be)},ut=Oe=>{var Be=on("Agent is working (click to type next)...");h(Oe,Be)},bt=Oe=>{var Be=on("Read-only mode");h(Oe,Be)},et=Oe=>{var Be=on("Select a session first...");h(Oe,Be)},rt=Oe=>{var Be=on("Tap to type a message...");h(Oe,Be)};C(ee,Oe=>{I()?Oe(Qe):t(S)?Oe(He,1):t(Ie)?Oe(ut,2):t(Re)?Oe(bt,3):t(Fe).sessionId?Oe(rt,-1):Oe(et,4)})}d(re),d(R),it(2),d(z),d(y),j(()=>ue(q,I()?"🔍":"💬")),W("click",z,()=>{p(ye,!1),setTimeout(()=>t(Me)?.focus(),50)}),h(Y,y)},Mt=Y=>{var y=Wc(),z=Ht(y);{var R=Ce=>{var Ze=Fc();pn(Ze,21,()=>t(oe),An,(Pt,_t,Xt)=>{var Kt=Nc(),gt=u(Kt),vt=u(gt,!0);d(gt);var ln=f(gt,2);{var an=E=>{var x=Lc();h(E,x)},cn=E=>{var x=Dc(),w=u(x),O=u(w);d(w);var Q=f(w,2);{var We=we=>{var ie=Oc();j(()=>je(ie,"href",t(_t).url)),h(we,ie)};C(Q,we=>{t(_t).url&&we(We)})}d(x),j(()=>{je(x,"title",t(_t).error),ue(O,`⚠️ ${t(_t).error??""}`)}),h(E,x)},rn=E=>{var x=Pc();h(E,x)};C(ln,E=>{t(_t).uploading?E(an):t(_t).error?E(cn,1):E(rn,-1)})}var dn=f(ln,2);d(Kt),j(()=>{je(gt,"title",t(_t).name),ue(vt,t(_t).name)}),W("click",dn,()=>Dt(Xt)),h(Pt,Kt)}),d(Ze),h(Ce,Ze)};C(z,Ce=>{t(oe).length>0&&Ce(R)})}var Z=f(z,2),q=u(Z),re=u(q);yo(re),je(re,"rows",1),En(re,Ce=>p(Me,Ce),()=>t(Me)),d(q);var ee=f(q,2),Qe=u(ee);{var He=Ce=>{var Ze=Uc(),Pt=Ht(Ze),_t=f(Pt,2);En(_t,Xt=>p(fe,Xt),()=>t(fe)),j(()=>Pt.disabled=t(ot)),W("click",Pt,()=>{Ta(),t(fe)?.click()}),W("change",_t,Te),h(Ce,Ze)};C(Qe,Ce=>{g()&&!I()&&Ce(He)})}var ut=f(Qe,2),bt=u(ut);Ec(bt,{get disabled(){return t(ot)},onSend:Xe,get text(){return t($)},set text(Ce){p($,Ce,!0)}}),d(ut);var et=f(ut,2);{var rt=Ce=>{var Ze=zc();W("click",Ze,Se),h(Ce,Ze)},Oe=Ce=>{var Ze=Hc(),Pt=u(Ze);{var _t=gt=>{var vt=on();j(()=>ue(vt,e.submitLabel??"Search")),h(gt,vt)},Xt=gt=>{var vt=on("Queue");h(gt,vt)},Kt=gt=>{var vt=on("Send");h(gt,vt)};C(Pt,gt=>{I()?gt(_t):t(Ie)?gt(Xt,1):gt(Kt,-1)})}d(Ze),j(()=>Ze.disabled=!t(Ue)),h(Ce,Ze)};C(et,Ce=>{t(S)?Ce(rt):Ce(Oe,-1)})}d(ee),d(Z);var Be=f(Z,2),Wt=u(Be),Ft=u(Wt);at(Ft),it(2),d(Wt);var At=f(Wt,2),mt=u(At),xt=f(mt,2);{var Zt=Ce=>{var Ze=Bc();h(Ce,Ze)};C(xt,Ce=>{t(L)||Ce(Zt)})}d(At),d(Be),j(()=>{re.disabled=t(ot),je(re,"placeholder",I()?e.placeholder??"Search the web...":t(he)?t(Ie)?"Agent is working (type next message...)":t(Re)?"Read-only mode":t(Fe).sessionId?"Type a message...":"Select a session first...":t($e).connecting?"Reconnecting to remote server...":"Disconnected - cannot send"),qt(re,1,`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 placeholder-brand-text-muted focus:border-brand-blue focus:outline-none disabled:opacity-50 ${t(S)?"text-brand-text-muted italic":"text-brand-text"}`),es(Ft,t(L))}),Nn("submit",Z,Ce=>{Ce.preventDefault(),Xe()}),W("keydown",re,ze),Rn(re,()=>t($),Ce=>p($,Ce)),W("change",Ft,be),W("click",mt,()=>p(ye,!0)),h(Y,y)};C(ht,Y=>{t(ye)?Y(kt):Y(Mt,-1)})}d(Ve),h(n,Ve);var St=Un(nn);return _(),St}Gn(["click","keydown","change"]);var qc=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>'),Vc=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>'),Yc=m('<span class="ml-1 font-semibold text-emerald-400">(Git repo)</span>'),Zc=m('<span class="mt-1 block text-[10px] font-medium text-yellow-400">📁 Folder already exists. <!></span>'),Kc=m("<option> </option>"),Xc=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>'),Qc=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"/>'),Jc=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>'),ed=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>'),td=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>'),nd=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>'),rd=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>'),sd=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>'),ad=m('<div class="p-4 text-center text-sm text-brand-text-muted"> </div>'),od=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>'),id=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>'),ld=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>'),cd=m('<span class="h-2 w-2 flex-shrink-0 rounded-full bg-emerald-500"></span>'),dd=m('<span class="h-2 w-2 flex-shrink-0 rounded-full bg-brand-surface-3"></span>'),ud=m('<span class="rounded bg-brand-surface-3 px-1.5 py-0.5 text-xs text-brand-text"> </span>'),fd=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>'),pd=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>'),hd=m('<div class="flex-shrink-0"><!></div>'),bd=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>'),gd=m('<div class="px-3 pb-2"><!> <!></div>'),vd=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>'),md=m("<option> </option>"),xd=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>'),_d=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"/>'),yd=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>'),wd=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>'),kd=m('<span class="ml-1 text-[10px] text-brand-text-muted">(already a Git repo)</span>'),Sd=m('<span class="ml-1 text-[10px] font-medium text-yellow-500">(folder not empty)</span>'),Td=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>'),Ad=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>'),Ed=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>'),Rd=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 pa(n,e){Fn(e,!0);const r=()=>qe(fr,"$readOnlySessionFolders",N),s=()=>qe(er,"$sessionFolders",N),a=()=>qe(Sr,"$activeSessionInfo",N),o=()=>qe(kr,"$isConnected",N),l=()=>qe(Nr,"$isLoadingSession",N),c=()=>qe(Cs,"$isResyncing",N),_=()=>qe(tr,"$availableModels",N),g=()=>qe(xs,"$gitInitDefaultStore",N),I=()=>qe(Es,"$sessionError",N),[N,$]=rr(),L=[];let S=br(e,"readOnly",3,!1),ve=se(()=>S()?r().folders:s().folders),ye=se(()=>S()?r().loading:s().loading);function fe(){S()?_a():vr()}let oe=se(()=>a().sessionFile),Ie=se(o),Re=se(l),Fe=se(c),he=se(()=>_().models),$e=wn({}),ot=V(wn({})),me=V(null),Ue=V(null),Me=V(""),Le=V(wn([]));Rt(()=>{t(Ie)&&(fe(),S()||(Wo(),Go()))});function dt(E,x,w){if(!w)return!0;const O=w.toLowerCase();return(E.name||"").toLowerCase().includes(O)||E.firstMessage.toLowerCase().includes(O)||x.toLowerCase().includes(O)}Rt(()=>{const E=t(Me),x=t(ve);E?p(Le,x.map(w=>({...w,sessions:w.sessions.filter(O=>dt(O,w.name,E))})).filter(w=>w.sessions.length>0),!0):(p(Le,x,!0),p(ot,{},!0))});function ft(E){return t(Me)?t(ot)[E]!==void 0?t(ot)[E]:!0:!!$e[E]}function pt(E){t(Me)?t(ot)[E]=!ft(E):$e[E]=!ft(E)}async function be(E){try{t(oe)===E&&(typeof window<"u"&&(window.location.hash=""),bn()),await ds(E),t(me)===E&&p(me,null),vr()}catch(x){console.error("Failed to delete session:",x)}}async function Se(E){try{const x=E.sessions.map(w=>w.path);t(oe)&&x.includes(t(oe))&&(typeof window<"u"&&(window.location.hash=""),bn()),await Promise.all(E.sessions.map(w=>ds(w.path))),t(Ue)===E.path&&p(Ue,null),vr()}catch(x){console.error("Failed to delete all sessions of folder:",x)}}function Te(E){t(oe)===E&&!t(Re)&&!t(Fe)||(Bn(),Ts(E))}let Dt=V(!1),Xe=V(""),ze=V(wn([])),nn=V(!1),Ve=V(null),Tt=V(null),Nt="",ht=V(""),kt=V(!1),Mt=V(null),St=V(!0),Y=V("private"),y=V(!1),z=se(g);Rt(()=>{t(Mt)===null&&p(kt,t(z),!0)});let R=V(wn({exists:null,isGit:!1,resolvedPath:"",matchingRule:null})),Z=se(()=>t(R).exists!==!0&&t(R).matchingRule&&t(St)),q=null;async function re(E,x=!1){if(q&&clearTimeout(q),E===Nt&&!x)return;if(Nt=E,!E.trim()){p(R,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0);const O=async()=>{const Q=await Mr("");p(ze,Q||[],!0)};x?await O():q=setTimeout(O,300);return}const w=async()=>{const[O,Q]=await Promise.all([ka(E),Mr(E)]);p(ze,Q||[],!0),O?(p(R,{exists:O.exists,isGit:O.isGit,resolvedPath:O.resolvedPath,matchingRule:O.matchingRule||null},!0),O.exists||(p(kt,t(Mt)!==null?t(Mt):t(z),!0),p(St,!0),O.matchingRule&&p(Y,O.matchingRule.visibility,!0))):p(R,{exists:null,isGit:!1,resolvedPath:"",matchingRule:null},!0)};x?await w():q=setTimeout(w,300)}Rt(()=>{const E=t(Xe);re(E,!1)}),Rt(()=>{if(t(he).length>0&&!t(ht)){const E=t(he).find(x=>x.isDefault);E?p(ht,`${E.provider}:${E.modelId}`):p(ht,`${t(he)[0].provider}:${t(he)[0].modelId}`)}});function ee(){if(t(Xe).trim())if(t(R).exists===!0)p(kt,!1),p(St,!1),t(R).matchingRule&&p(Y,t(R).matchingRule.visibility,!0),p(y,!0);else{Bn();const E=t(Xe).trim(),x=t(ht)||void 0,w=t(kt),O=t(R).matchingRule?t(St):void 0,Q=t(R).matchingRule?t(Y):void 0;p(Xe,""),p(Dt,!1),t(oe)?(bn(),setTimeout(()=>{kn(E,x,w,O,Q)},100)):kn(E,x,w,O,Q)}}function Qe(){p(y,!1),Bn();const E=t(Xe).trim(),x=t(ht)||void 0,w=t(kt),O=t(R).matchingRule?t(St):void 0,Q=t(R).matchingRule?t(Y):void 0;p(Xe,""),p(Dt,!1),t(oe)?(bn(),setTimeout(()=>{kn(E,x,w,O,Q)},100)):kn(E,x,w,O,Q)}let He=V(wn({open:!1,folderPath:"",selected:""}));function ut(E){const x=t(he).find(w=>w.isDefault);p(He,{open:!0,folderPath:E,selected:x?`${x.provider}:${x.modelId}`:""},!0)}function bt(){t(He).open=!1}function et(){if(!t(He).open)return;Bn();const E=t(He).folderPath,x=t(He).selected||void 0;bt(),t(oe)?(bn(),setTimeout(()=>{kn(E,x)},100)):kn(E,x)}function rt(E){const x=Date.now()-new Date(E).getTime(),w=Math.floor(x/6e4);if(w<1)return"just now";if(w<60)return`${w}m ago`;const O=Math.floor(w/60);return O<24?`${O}h ago`:`${Math.floor(O/24)}d ago`}function Oe(E,x=40){return E.length>x?E.slice(0,x)+"...":E}var Be=Rd(),Wt=Ht(Be),Ft=u(Wt),At=u(Ft),mt=u(At);at(mt);var xt=f(mt,2),Zt=u(xt);d(xt),d(At),d(Ft);var Ce=f(Ft,2),Ze=u(Ce);{var Pt=E=>{var x=rd(),w=u(x),O=u(w),Q=u(O,!0);d(O),d(w);var We=f(w,2);{var we=ie=>{var v=nd(),k=u(v),H=f(u(k),2),D=u(H);at(D),En(D,B=>p(Ve,B),()=>t(Ve));var le=f(D,2);{var K=B=>{var U=Vc();pn(U,21,()=>t(ze),An,(ce,de)=>{var ge=qc(),ae=u(ge,!0);d(ge),j(()=>ue(ae,t(de))),W("click",ge,()=>{p(Xe,t(de),!0),re(t(de),!0),t(Ve)?.focus()}),h(ce,ge)}),d(U),h(B,U)};C(le,B=>{t(nn)&&t(ze).length>0&&B(K)})}d(H),En(H,B=>p(Tt,B),()=>t(Tt));var T=f(H,2);{var F=B=>{var U=Zc(),ce=f(u(U));{var de=ge=>{var ae=Yc();h(ge,ae)};C(ce,ge=>{t(R).isGit&&ge(de)})}d(U),h(B,U)};C(T,B=>{t(R).exists===!0&&B(F)})}d(k);var te=f(k,2),De=f(u(te),2);{var Ae=B=>{var U=Xc();pn(U,21,()=>t(he),An,(ce,de)=>{var ge=Kc(),ae=u(ge);d(ge);var G={};j(()=>{ue(ae,`${t(de).label??""}${t(de).isDefault?" (default)":""}`),G!==(G=`${t(de).provider}:${t(de).modelId}`)&&(ge.value=ge.__value=`${t(de).provider}:${t(de).modelId}`)}),h(ce,ge)}),d(U),$r(U,()=>t(ht),ce=>p(ht,ce)),h(B,U)},xe=B=>{var U=Qc();at(U),Rn(U,()=>t(ht),ce=>p(ht,ce)),h(B,U)};C(De,B=>{t(he).length>0?B(Ae):B(xe,-1)})}d(te);var st=f(te,2);{var It=B=>{var U=ed(),ce=u(U),de=u(ce);at(de);var ge=f(de,2),ae=u(ge);d(ge),d(ce);var G=f(ce,2);{var P=J=>{var _e=Jc(),Ee=f(u(_e),2),ne=u(Ee);at(ne),ne.value=ne.__value="private",it(),d(Ee);var ke=f(Ee,2),nt=u(ke);at(nt),nt.value=nt.__value="public",it(),d(ke),d(_e),Pn(L,[],ne,()=>t(Y),Pe=>p(Y,Pe)),Pn(L,[],nt,()=>t(Y),Pe=>p(Y,Pe)),h(J,_e)};C(G,J=>{t(St)&&J(P)})}d(U),j(()=>ue(ae,`Create remote ${t(R).matchingRule.provider??""} repository`)),gn(de,()=>t(St),J=>p(St,J)),h(B,U)};C(st,B=>{t(R).exists!==!0&&t(R).matchingRule&&B(It)})}var Ge=f(st,2);{var Ye=B=>{var U=td(),ce=u(U);at(ce),it(2),d(U),W("change",ce,de=>{p(Mt,de.currentTarget.checked,!0)}),gn(ce,()=>t(kt),de=>p(kt,de)),h(B,U)};C(Ge,B=>{t(R).exists!==!0&&(!t(R).matchingRule||!t(St))&&B(Ye)})}var pe=f(Ge,2);d(v),j(B=>{qt(D,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(Z)?"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"}`),pe.disabled=B},[()=>!t(Xe).trim()]),Nn("submit",v,B=>{B.preventDefault(),ee()}),Nn("focus",D,()=>{p(nn,!0),re(t(Xe),!0)}),Nn("blur",D,B=>{t(Tt)&&t(Tt).contains(B.relatedTarget)||p(nn,!1)}),W("keydown",D,B=>{B.key==="Escape"&&p(nn,!1)}),Rn(D,()=>t(Xe),B=>p(Xe,B)),h(ie,v)};C(We,ie=>{t(Dt)&&ie(we)})}d(x),j(()=>ue(Q,t(Dt)?"▼ Close Create Session":"✚ Create New Session")),W("click",w,()=>p(Dt,!t(Dt))),h(E,x)};C(Ze,E=>{S()||E(Pt)})}var _t=f(Ze,2);{var Xt=E=>{var x=sd();h(E,x)},Kt=E=>{var x=ad(),w=u(x,!0);d(x),j(()=>ue(w,t(Me)?"No sessions match your filter":"No sessions found")),h(E,x)},gt=E=>{var x=Jn(),w=Ht(x);pn(w,17,()=>t(Le),O=>O.path,(O,Q)=>{var We=vd(),we=u(We),ie=u(we),v=f(ie,2),k=u(v),H=u(k,!0);d(k);var D=f(k,2),le=u(D,!0);d(D),d(v);var K=f(v,2),T=u(K,!0);d(K),d(we);var F=f(we,2);{var te=Ae=>{var xe=gd(),st=u(xe);{var It=Ye=>{var pe=ld(),B=u(pe),U=f(B,2),ce=u(U);{var de=ae=>{var G=od(),P=u(G),J=f(P,2);d(G),W("click",P,_e=>{_e.stopPropagation(),Se(t(Q))}),W("click",J,_e=>{_e.stopPropagation(),p(Ue,null)}),h(ae,G)},ge=ae=>{var G=id();W("click",G,P=>{P.stopPropagation(),p(Ue,t(Q).path,!0)}),h(ae,G)};C(ce,ae=>{t(Ue)===t(Q).path?ae(de):ae(ge,-1)})}d(U),d(pe),W("click",B,()=>ut(t(Q).path)),h(Ye,pe)};C(st,Ye=>{S()||Ye(It)})}var Ge=f(st,2);pn(Ge,17,()=>t(Q).sessions,Ye=>Ye.path,(Ye,pe)=>{var B=bd(),U=u(B),ce=u(U);{var de=Pe=>{var tt=cd();h(Pe,tt)},ge=Pe=>{var tt=dd();h(Pe,tt)};C(ce,Pe=>{t(pe).isActive?Pe(de):Pe(ge,-1)})}var ae=f(ce,2),G=u(ae),P=u(G,!0);d(G);var J=f(G,2),_e=u(J);d(J),d(ae);var Ee=f(ae,2);{var ne=Pe=>{var tt=ud(),Ut=u(tt,!0);d(tt),j(()=>ue(Ut,t(pe).clientCount)),h(Pe,tt)};C(Ee,Pe=>{t(pe).clientCount>0&&Pe(ne)})}d(U);var ke=f(U,2);{var nt=Pe=>{var tt=hd(),Ut=u(tt);{var un=Qt=>{var Jt=fd(),fn=u(Jt),Vn=f(fn,2);d(Jt),W("click",fn,mn=>{mn.stopPropagation(),be(t(pe).path)}),W("click",Vn,mn=>{mn.stopPropagation(),p(me,null)}),h(Qt,Jt)},vn=Qt=>{var Jt=pd();W("click",Jt,fn=>{fn.stopPropagation(),p(me,t(pe).path,!0)}),h(Qt,Jt)};C(Ut,Qt=>{t(me)===t(pe).path?Qt(un):Qt(vn,-1)})}d(tt),h(Pe,tt)};C(ke,Pe=>{S()||Pe(nt)})}d(B),j((Pe,tt,Ut)=>{qt(B,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(oe)===t(pe).path?"bg-brand-surface-3":""}`),je(U,"href",`#${Pe??""}`),ue(P,tt),ue(_e,`${Ut??""} · ${t(pe).messageCount??""}
79
+ msgs`)},[()=>encodeURIComponent(t(pe).id),()=>t(pe).name||Oe(t(pe).firstMessage)||"Empty session",()=>rt(t(pe).modified)]),W("click",U,Pe=>{Pe.button===0&&!Pe.ctrlKey&&!Pe.metaKey&&!Pe.altKey&&!Pe.shiftKey&&(Pe.preventDefault(),Te(t(pe).path))}),h(Ye,B)}),d(xe),h(Ae,xe)},De=se(()=>ft(t(Q).path));C(F,Ae=>{t(De)&&Ae(te)})}d(We),j(Ae=>{qt(ie,1,`text-xs text-brand-text-muted transition-transform ${Ae??""}`),ue(H,t(Q).name),ue(le,t(Q).path),ue(T,t(Q).sessions.length)},[()=>ft(t(Q).path)?"rotate-90":""]),W("click",we,()=>pt(t(Q).path)),h(O,We)}),h(E,x)};C(_t,E=>{t(ye)&&t(Le).length===0?E(Xt):t(Le).length===0?E(Kt,1):E(gt,-1)})}d(Ce),d(Wt);var vt=f(Wt,2);{var ln=E=>{var x=yd(),w=u(x),O=f(u(w),2),Q=f(u(O),2),We=u(Q,!0);d(Q),d(O);var we=f(O,2),ie=f(u(we),2);{var v=K=>{var T=xd();pn(T,21,()=>t(he),An,(F,te)=>{var De=md(),Ae=u(De);d(De);var xe={};j(()=>{ue(Ae,`${t(te).label??""}${t(te).isDefault?" (default)":""}`),xe!==(xe=`${t(te).provider}:${t(te).modelId}`)&&(De.value=De.__value=`${t(te).provider}:${t(te).modelId}`)}),h(F,De)}),d(T),$r(T,()=>t(He).selected,F=>t(He).selected=F),h(K,T)},k=K=>{var T=_d();at(T),Rn(T,()=>t(He).selected,F=>t(He).selected=F),h(K,T)};C(ie,K=>{t(he).length>0?K(v):K(k,-1)})}d(we);var H=f(we,2),D=u(H),le=f(D,2);d(H),d(w),d(x),j(()=>ue(We,t(He).folderPath)),W("click",x,bt),W("click",w,K=>K.stopPropagation()),W("click",D,bt),W("click",le,et),h(E,x)};C(vt,E=>{t(He).open&&E(ln)})}var an=f(vt,2);{var cn=E=>{var x=wd(),w=u(x),O=u(w,!0);d(w);var Q=f(w,2);d(x),j(()=>ue(O,I())),W("click",Q,()=>Bn()),h(E,x)};C(an,E=>{I()&&E(cn)})}var rn=f(an,2);{var dn=E=>{var x=Ed(),w=u(x),O=f(u(w),2),Q=f(u(O)),We=u(Q,!0);d(Q),it(),d(O);var we=f(O,2),ie=u(we),v=u(ie);at(v);var k=f(v,2),H=f(u(k));{var D=Ae=>{var xe=kd();h(Ae,xe)},le=Ae=>{var xe=Sd();h(Ae,xe)};C(H,Ae=>{t(R).isGit?Ae(D):Ae(le,-1)})}d(k),d(ie);var K=f(ie,2);{var T=Ae=>{var xe=Ad(),st=u(xe),It=u(st);at(It);var Ge=f(It,2),Ye=u(Ge);d(Ge),d(st);var pe=f(st,2);{var B=U=>{var ce=Td(),de=f(u(ce),2),ge=u(de);at(ge),ge.value=ge.__value="private",it(),d(de);var ae=f(de,2),G=u(ae);at(G),G.value=G.__value="public",it(),d(ae),d(ce),Pn(L,[],ge,()=>t(Y),P=>p(Y,P)),Pn(L,[],G,()=>t(Y),P=>p(Y,P)),h(U,ce)};C(pe,U=>{t(St)&&U(B)})}d(xe),j(()=>ue(Ye,`Create remote ${t(R).matchingRule.provider??""} repository`)),gn(It,()=>t(St),U=>p(St,U)),h(Ae,xe)};C(K,Ae=>{t(R).matchingRule&&Ae(T)})}d(we);var F=f(we,2),te=u(F),De=f(te,2);d(F),d(w),d(x),j(()=>{ue(We,t(Xe)),v.disabled=t(R).isGit}),gn(v,()=>t(kt),Ae=>p(kt,Ae)),W("click",te,()=>p(y,!1)),W("click",De,Qe),h(E,x)};C(rn,E=>{t(y)&&E(dn)})}j(()=>{ko(mt,t(Me)),qt(Zt,1,Co(t(ye)?"animate-spin":""))}),W("input",mt,E=>p(Me,E.currentTarget.value,!0)),W("click",xt,()=>fe()),h(n,Be),Un(),$()}Gn(["input","click","keydown","change"]);var Cd=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
80
80
  live but cannot send messages.<br/> <strong class="text-brand-text">Take Over:</strong> Interrupt the other client
81
- and gain control.</p></div></div>`);function Id(n,e){Fn(e,!0);const r=()=>qe(Oa,"$conflict",s),[s,a]=rr();let o=se(r);var l=Jn(),c=Ht(l);{var _=v=>{var I=Cd(),N=u(I),$=f(u(N),2),L=f(u($)),S=u(L,!0);d(L),it(),d($);var ge=f($,2),ye=u(ge),fe=f(ye,2);d(ge),it(2),d(N),d(I),j(()=>ue(S,t(o).conflictingCwd)),W("click",ye,()=>is("read_only")),W("click",fe,()=>is("take_over")),h(v,I)};C(c,v=>{t(o)&&v(_)})}h(n,l),Un(),a()}Gn(["click"]);var $d=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>'),Md=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),Ld=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),Od=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>'),Dd=m('<div class="truncate text-xs text-brand-text-muted"> </div>'),Pd=m('<div class="truncate text-xs text-brand-text-muted"> </div>'),Nd=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>'),Fd=m('<div class="mt-2 text-xs text-rose-400"> </div>'),Ud=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>'),zd=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>'),Hd=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),Bd=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>'),Wd=m('<span class="text-sm text-brand-text-muted">Search the web below, or pick a session from the sidebar</span>'),Gd=m('<span class="text-sm text-brand-text-muted">Select a session from sidebar</span>'),jd=m('<span class="text-sm text-brand-text-muted">Not connected</span>'),qd=m('<div class="flex min-w-0 items-center gap-2"><!></div>'),Vd=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>'),Yd=m("<option> </option>"),Zd=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>'),Kd=m('<span class="truncate text-brand-text-muted"> </span>'),Xd=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>'),Qd=m('<div class="flex min-w-0 flex-1 items-center gap-3"><!> <!></div>'),Jd=m('<span class="flex-shrink-0 rounded bg-yellow-500/20 px-2 py-1 text-xs text-yellow-400">Read-only</span>'),eu=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>'),tu=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>'),nu=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>'),ru=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>'),su=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>'),au=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>'),ou=m("<!> <!>",1),iu=m('<button type="button" class="fixed inset-0 z-10 bg-brand-dark/50 md:hidden" aria-label="Close sidebar"></button>'),lu=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 gu(n,e){Fn(e,!0);const r=()=>qe(kr,"$isConnected",S),s=()=>qe(Cs,"$isResyncing",S),a=()=>qe(Na,"$isAgentPending",S),o=()=>qe(Nr,"$isLoadingSession",S),l=()=>qe(Da,"$isInterrupted",S),c=()=>qe(Es,"$sessionError",S),_=()=>qe(Rs,"$isReadOnly",S),v=()=>qe(Sr,"$activeSessionInfo",S),I=()=>qe($t,"$piState",S),N=()=>qe(tr,"$availableModels",S),$=()=>qe(Pa,"$isCreatingSession",S),L=()=>qe(_s,"$searchFolderStore",S),[S,ge]=rr();let ye=V(!1),fe=V("main"),oe=V(!1),Ie;yr(()=>{setTimeout(()=>Hn(),200);const x=()=>{if(t(me)){const we=window.location.hash?decodeURIComponent(window.location.hash.slice(1)):"";we&&we!==t(Xe)?Ts(we):!we&&t(Xe)&&bn()}};window.addEventListener("hashchange",x);let w=null;const O=8e3,Q=()=>{if(document.visibilityState==="hidden"){if(Aa())return;w&&clearTimeout(w),w=setTimeout(()=>{w=null,document.visibilityState==="hidden"&&t(me)&&Sa()},O)}else Ss(),w&&(clearTimeout(w),w=null),t(me)||(as()?ss():Hn())},We=we=>{w&&(clearTimeout(w),w=null),document.visibilityState!=="hidden"&&!t(me)&&(as()?ss():Hn())};return document.addEventListener("visibilitychange",Q),window.addEventListener("pageshow",We),()=>{window.removeEventListener("hashchange",x),document.removeEventListener("visibilitychange",Q),window.removeEventListener("pageshow",We),w&&clearTimeout(w)}});function Re(){Hn()}function Ne(){bn(),_r()}function he(){_r(),setTimeout(()=>Hn(),100)}function $e(){gr()}function ot(){typeof window<"u"&&(window.location.hash=""),bn(),p(ye,!1)}let me=se(r),Ue=se(s),Me=se(a),Fe=se(o),dt=se(l),ft=se(c),pt=se(_),be=se(v),Se=se(I),Te=se(()=>N().models),Dt=V(!1),Xe=se(()=>t(be).sessionId);Rt(()=>{typeof window<"u"&&t(me)&&(t(Xe)?(window.location.hash=encodeURIComponent(t(Xe)),p(Dt,!0)):t(Dt)&&(p(Dt,!1),window.location.hash&&(window.location.hash="")))});let ze=null;Rt(()=>{if(!t(me)||typeof window>"u"||!window.location.hash)return;const x=decodeURIComponent(window.location.hash.slice(1));x&&(t(Xe)===x||t(Fe)||t(Ue)||ze||(ze=setTimeout(()=>{ze=null,!(t(Xe)===x||t(Fe)||t(Ue))&&Ra(x)},300)))}),Rt(()=>{t(me)||p(Dt,!1)}),Rt(()=>{(t(Xe)||t(Fe)||t(Ue))&&p(ye,!1)});let nn=se($),Ve=se(L),Tt=V(void 0),Nt=se(()=>t(me)&&!!t(Ve)&&!t(be).sessionFile),ht=V(!1);Rt(()=>{t(Nt)&&!t(ht)&&t(Tt)&&(p(ht,!0),t(Tt).focusInput())});function kt(){typeof window<"u"&&window.location.hash&&(window.location.hash=""),bn(),t(Tt)?.focusInput()}var Mt=lu(),St=Ht(Mt);No(St,{title:"Wherever",description:"Create & maintain apps from wherever"});var Y=f(St,2);{var y=x=>{var w=$d();h(x,w)};C(Y,x=>{t(nn)&&x(y)})}var z=f(Y,2),R=u(z),Z=u(R),q=u(Z),re=u(q);{var ee=x=>{var w=Md(),O=f(Ht(w),2);W("click",O,()=>p(oe,!1)),h(x,w)},Qe=x=>{var w=Ld(),O=Ht(w),Q=u(O);it(2),d(O);var We=f(O,2),we=u(We),ie=f(we,2);d(We),j(g=>je(Q,"src",g),[()=>Qn("/logo.svg")]),W("click",O,ot),W("click",we,()=>p(oe,!0)),W("click",ie,()=>p(ye,!1)),h(x,w)};C(re,x=>{t(oe)?x(ee):x(Qe,-1)})}d(q),d(Z);var He=f(Z,2);{var ut=x=>{var w=Od(),O=u(w);{let k=se(()=>(t(Se).connected,"localhost"));si(O,{get host(){return t(k)},port:31415,token:"",onConnected:Re})}var Q=f(O,2),We=f(u(Q),2),we=u(We),ie=f(we,2),g=f(ie,2);d(We),d(Q),d(w),W("click",we,$e),W("click",ie,he),W("click",g,Ne),h(x,w)},bt=x=>{var w=Hd(),O=Ht(w),Q=u(O),We=u(Q),we=f(We,2),ie=u(we,!0);d(we);var g=f(we,2),k=u(g);d(g),d(Q);var H=f(Q,2);{var D=Ge=>{var Ye=Nd(),pe=u(Ye);{var B=ae=>{var G=Dd(),P=u(G);d(G),j(J=>{je(G,"title",t(be).cwd),ue(P,`📁 ${J??""}`)},[()=>t(be).cwd.split("/").pop()||t(be).cwd]),h(ae,G)};C(pe,ae=>{t(be).cwd&&ae(B)})}var U=f(pe,2);{var ce=ae=>{var G=Pd(),P=u(G);d(G),j(()=>{je(G,"title",t(be).model),ue(P,`🤖 ${t(be).model??""}`)}),h(ae,G)};C(U,ae=>{t(be).model&&ae(ce)})}var de=f(U,2),ve=u(de);d(de),d(Ye),W("click",ve,ot),h(Ge,Ye)};C(H,Ge=>{t(be).sessionFile&&Ge(D)})}var le=f(H,2);{var K=Ge=>{var Ye=Fd(),pe=u(Ye,!0);d(Ye),j(()=>ue(pe,t(Se).error)),h(Ge,Ye)};C(le,Ge=>{t(Se).error&&!t(me)&&Ge(K)})}d(O);var T=f(O,2),F=u(T);{var te=Ge=>{var Ye=Ud();W("click",Ye,()=>{p(fe,"readonly"),_a()}),h(Ge,Ye)},Oe=Ge=>{var Ye=zd();W("click",Ye,()=>p(fe,"main")),h(Ge,Ye)};C(F,Ge=>{t(fe)==="main"?Ge(te):Ge(Oe,-1)})}d(T);var Ae=f(T,2),xe=u(Ae);{var st=Ge=>{pa(Ge,{readOnly:!0})},It=Ge=>{pa(Ge,{})};C(xe,Ge=>{t(fe)==="readonly"?Ge(st):Ge(It,-1)})}d(Ae),j(()=>{qt(We,1,`h-2.5 w-2.5 rounded-full ${t(me)?"bg-emerald-500":"bg-rose-500"}`),qt(we,1,`text-sm ${t(me)?"text-emerald-400":"text-rose-400"}`),ue(ie,t(me)?"Connected":"Disconnected"),ue(k,`v${ga}`)}),h(x,w)};C(He,x=>{t(oe)?x(ut):x(bt,-1)})}d(R);var et=f(R,2),rt=u(et),Le=u(rt),Be=f(Le,2);{var Wt=x=>{var w=Bd();W("click",w,kt),h(x,w)};C(Be,x=>{t(me)&&t(Ve)&&t(be).sessionFile&&x(Wt)})}var Ft=f(Be,2);{var At=x=>{var w=qd(),O=u(w);{var Q=ie=>{var g=Wd();h(ie,g)},We=ie=>{var g=Gd();h(ie,g)},we=ie=>{var g=jd();h(ie,g)};C(O,ie=>{t(me)&&t(Nt)?ie(Q):t(me)?ie(We,1):ie(we,-1)})}d(w),h(x,w)};C(Ft,x=>{(!t(me)||!t(be).sessionFile)&&x(At)})}var mt=f(Ft,2);{var xt=x=>{var w=Qd(),O=u(w);{var Q=ie=>{var g=Vd(),k=f(u(g),2),H=u(k,!0);d(k),d(g),j(D=>{je(k,"title",t(be).cwd),ue(H,D)},[()=>t(be).cwd.split("/").pop()||t(be).cwd]),h(ie,g)};C(O,ie=>{t(be).cwd&&ie(Q)})}var We=f(O,2);{var we=ie=>{var g=Xd(),k=u(g),H=f(u(k),2);d(k);var D=f(k,2);{var le=T=>{var F=Zd();pn(F,21,()=>t(Te),An,(Oe,Ae)=>{var xe=Yd(),st=u(xe,!0);d(xe);var It={};j(()=>{ue(st,t(Ae).label),It!==(It=`${t(Ae).provider}:${t(Ae).modelId}`)&&(xe.value=xe.__value=`${t(Ae).provider}:${t(Ae).modelId}`)}),h(Oe,xe)}),d(F);var te;xa(F),j(()=>{te!==(te=t(be).model)&&(F.value=(F.__value=t(be).model)??"",ms(F,t(be).model))}),W("input",F,Oe=>Ma(Oe.currentTarget.value)),h(T,F)},K=T=>{var F=Kd(),te=u(F,!0);d(F),j(()=>{je(F,"title",t(be).model),ue(te,t(be).model)}),h(T,F)};C(D,T=>{t(Te).length>0&&!t(pt)?T(le):T(K,-1)})}d(g),j(()=>{qt(H,1,`absolute -right-0.5 -bottom-0.5 h-2 w-2 rounded-full border border-brand-surface ${t(Se).isStreaming?"animate-pulse bg-orange-500":"bg-emerald-500"}`),je(H,"title",t(Se).isStreaming?"Agent working...":"Ready")}),h(ie,g)};C(We,ie=>{t(be).model&&ie(we)})}d(w),h(x,w)};C(mt,x=>{t(be).sessionFile&&x(xt)})}var Zt=f(mt,2);{var Ce=x=>{var w=Jd();h(x,w)};C(Zt,x=>{t(pt)&&x(Ce)})}d(rt);var Ze=f(rt,2);{var Pt=x=>{var w=eu();h(x,w)};C(Ze,x=>{t(dt)&&x(Pt)})}var _t=f(Ze,2);{var Xt=x=>{var w=tu(),O=u(w),Q=u(O,!0);d(O);var We=f(O,2);d(w),j(()=>ue(Q,t(ft))),W("click",We,()=>Bn()),h(x,w)};C(_t,x=>{t(ft)&&x(Xt)})}var Kt=f(_t,2);{var vt=x=>{var w=nu();h(x,w)};C(Kt,x=>{t(pt)&&!t(dt)&&x(vt)})}var gt=f(Kt,2);En(yc(gt,{onMessageSent:()=>{}}),x=>Ie=x,()=>Ie);var ln=f(gt,2);{var an=x=>{var w=ru();h(x,w)},cn=x=>{var w=ou(),O=Ht(w);{var Q=ie=>{var g=su();h(ie,g)},We=ie=>{var g=au();h(ie,g)};C(O,ie=>{t(be).sessionFile&&(t(Ue)||!t(me))?ie(Q):t(be).sessionFile&&t(Me)&&ie(We,1)})}var we=f(O,2);{let ie=se(()=>!!t(Ve)),g=se(()=>t(Nt)?!t(me):!t(me)||t(pt)||!t(be).sessionFile||t(Ue)||t(Me));En(jc(we,{get searchMode(){return t(Nt)},get searchConfigured(){return t(ie)},onSubmit:k=>Ca(k),placeholder:"Search the web...",submitLabel:"Search",get disabled(){return t(g)},onSend:()=>Ie?.forceScrollToBottom()}),k=>p(Tt,k,!0),()=>t(Tt))}h(x,w)};C(ln,x=>{t(pt)&&t(be).sessionFile?x(an):x(cn,-1)})}d(et);var rn=f(et,2);Id(rn,{});var dn=f(rn,2);{var E=x=>{var w=iu();W("click",w,()=>p(ye,!1)),h(x,w)};C(dn,x=>{t(ye)&&x(E)})}d(z),j(()=>qt(R,1,`app-chrome ${t(ye)?"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`)),W("click",Le,()=>p(ye,!t(ye))),h(n,Mt),Un(),ge()}Gn(["click","input"]);export{gu as component,vu as universal};
82
- //# sourceMappingURL=2.BxrRwRXv.js.map
81
+ and gain control.</p></div></div>`);function Id(n,e){Fn(e,!0);const r=()=>qe(Oa,"$conflict",s),[s,a]=rr();let o=se(r);var l=Jn(),c=Ht(l);{var _=g=>{var I=Cd(),N=u(I),$=f(u(N),2),L=f(u($)),S=u(L,!0);d(L),it(),d($);var ve=f($,2),ye=u(ve),fe=f(ye,2);d(ve),it(2),d(N),d(I),j(()=>ue(S,t(o).conflictingCwd)),W("click",ye,()=>is("read_only")),W("click",fe,()=>is("take_over")),h(g,I)};C(c,g=>{t(o)&&g(_)})}h(n,l),Un(),a()}Gn(["click"]);function $d(n){return n.loading||n.resyncing||n.hasSessionHash}function Md(n){return n.connected&&n.searchConfigured&&!n.hasSession&&!$d(n)}var Ld=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>'),Od=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),Dd=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),Pd=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>'),Nd=m('<div class="truncate text-xs text-brand-text-muted"> </div>'),Fd=m('<div class="truncate text-xs text-brand-text-muted"> </div>'),Ud=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>'),zd=m('<div class="mt-2 text-xs text-rose-400"> </div>'),Hd=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>'),Bd=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>'),Wd=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),Gd=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>'),jd=m('<span class="text-sm text-brand-text-muted">Search the web below, or pick a session from the sidebar</span>'),qd=m('<span class="text-sm text-brand-text-muted">Select a session from sidebar</span>'),Vd=m('<span class="text-sm text-brand-text-muted">Not connected</span>'),Yd=m('<div class="flex min-w-0 items-center gap-2"><!></div>'),Zd=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>'),Kd=m("<option> </option>"),Xd=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>'),Qd=m('<span class="truncate text-brand-text-muted"> </span>'),Jd=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>'),eu=m('<div class="flex min-w-0 flex-1 items-center gap-3"><!> <!></div>'),tu=m('<span class="flex-shrink-0 rounded bg-yellow-500/20 px-2 py-1 text-xs text-yellow-400">Read-only</span>'),nu=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>'),ru=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>'),su=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>'),au=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>'),ou=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>'),iu=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>'),lu=m("<!> <!>",1),cu=m('<button type="button" class="fixed inset-0 z-10 bg-brand-dark/50 md:hidden" aria-label="Close sidebar"></button>'),du=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 xu(n,e){Fn(e,!0);const r=()=>qe(kr,"$isConnected",S),s=()=>qe(Cs,"$isResyncing",S),a=()=>qe(Na,"$isAgentPending",S),o=()=>qe(Nr,"$isLoadingSession",S),l=()=>qe(Da,"$isInterrupted",S),c=()=>qe(Es,"$sessionError",S),_=()=>qe(Rs,"$isReadOnly",S),g=()=>qe(Sr,"$activeSessionInfo",S),I=()=>qe($t,"$piState",S),N=()=>qe(tr,"$availableModels",S),$=()=>qe(Pa,"$isCreatingSession",S),L=()=>qe(_s,"$searchFolderStore",S),[S,ve]=rr();let ye=V(!1),fe=V("main"),oe=V(!1),Ie;yr(()=>{setTimeout(()=>Hn(),200);const x=()=>{if(t(me)){const we=window.location.hash?decodeURIComponent(window.location.hash.slice(1)):"";we&&we!==t(Xe)?Ts(we):!we&&t(Xe)&&bn()}};window.addEventListener("hashchange",x);let w=null;const O=8e3,Q=()=>{if(document.visibilityState==="hidden"){if(Aa())return;w&&clearTimeout(w),w=setTimeout(()=>{w=null,document.visibilityState==="hidden"&&t(me)&&Sa()},O)}else Ss(),w&&(clearTimeout(w),w=null),t(me)||(as()?ss():Hn())},We=we=>{w&&(clearTimeout(w),w=null),document.visibilityState!=="hidden"&&!t(me)&&(as()?ss():Hn())};return document.addEventListener("visibilitychange",Q),window.addEventListener("pageshow",We),()=>{window.removeEventListener("hashchange",x),document.removeEventListener("visibilitychange",Q),window.removeEventListener("pageshow",We),w&&clearTimeout(w)}});function Re(){Hn()}function Fe(){bn(),_r()}function he(){_r(),setTimeout(()=>Hn(),100)}function $e(){vr()}function ot(){typeof window<"u"&&(window.location.hash=""),bn(),p(ye,!1)}let me=se(r),Ue=se(s),Me=se(a),Le=se(o),dt=se(l),ft=se(c),pt=se(_),be=se(g),Se=se(I),Te=se(()=>N().models),Dt=V(!1),Xe=se(()=>t(be).sessionId);Rt(()=>{typeof window<"u"&&t(me)&&(t(Xe)?(window.location.hash=encodeURIComponent(t(Xe)),p(Dt,!0)):t(Dt)&&(p(Dt,!1),window.location.hash&&(window.location.hash="")))});let ze=null;Rt(()=>{if(!t(me)||typeof window>"u"||!window.location.hash)return;const x=decodeURIComponent(window.location.hash.slice(1));x&&(t(Xe)===x||t(Le)||t(Ue)||ze||(ze=setTimeout(()=>{ze=null,!(t(Xe)===x||t(Le)||t(Ue))&&Ra(x)},300)))}),Rt(()=>{t(me)||p(Dt,!1)}),Rt(()=>{(t(Xe)||t(Le)||t(Ue))&&p(ye,!1)});let nn=se($),Ve=se(L),Tt=V(void 0),Nt=se(()=>Md({connected:t(me),searchConfigured:!!t(Ve),hasSession:!!t(be).sessionFile,loading:t(Le),resyncing:t(Ue),hasSessionHash:typeof window<"u"&&!!window.location.hash})),ht=V(!1);Rt(()=>{t(Nt)&&!t(ht)&&t(Tt)&&(p(ht,!0),t(Tt).focusInput())});function kt(){typeof window<"u"&&window.location.hash&&(window.location.hash=""),bn(),t(Tt)?.focusInput()}var Mt=du(),St=Ht(Mt);No(St,{title:"Wherever",description:"Create & maintain apps from wherever"});var Y=f(St,2);{var y=x=>{var w=Ld();h(x,w)};C(Y,x=>{t(nn)&&x(y)})}var z=f(Y,2),R=u(z),Z=u(R),q=u(Z),re=u(q);{var ee=x=>{var w=Od(),O=f(Ht(w),2);W("click",O,()=>p(oe,!1)),h(x,w)},Qe=x=>{var w=Dd(),O=Ht(w),Q=u(O);it(2),d(O);var We=f(O,2),we=u(We),ie=f(we,2);d(We),j(v=>je(Q,"src",v),[()=>Qn("/logo.svg")]),W("click",O,ot),W("click",we,()=>p(oe,!0)),W("click",ie,()=>p(ye,!1)),h(x,w)};C(re,x=>{t(oe)?x(ee):x(Qe,-1)})}d(q),d(Z);var He=f(Z,2);{var ut=x=>{var w=Pd(),O=u(w);{let k=se(()=>(t(Se).connected,"localhost"));si(O,{get host(){return t(k)},port:31415,token:"",onConnected:Re})}var Q=f(O,2),We=f(u(Q),2),we=u(We),ie=f(we,2),v=f(ie,2);d(We),d(Q),d(w),W("click",we,$e),W("click",ie,he),W("click",v,Fe),h(x,w)},bt=x=>{var w=Wd(),O=Ht(w),Q=u(O),We=u(Q),we=f(We,2),ie=u(we,!0);d(we);var v=f(we,2),k=u(v);d(v),d(Q);var H=f(Q,2);{var D=Ge=>{var Ye=Ud(),pe=u(Ye);{var B=ae=>{var G=Nd(),P=u(G);d(G),j(J=>{je(G,"title",t(be).cwd),ue(P,`📁 ${J??""}`)},[()=>t(be).cwd.split("/").pop()||t(be).cwd]),h(ae,G)};C(pe,ae=>{t(be).cwd&&ae(B)})}var U=f(pe,2);{var ce=ae=>{var G=Fd(),P=u(G);d(G),j(()=>{je(G,"title",t(be).model),ue(P,`🤖 ${t(be).model??""}`)}),h(ae,G)};C(U,ae=>{t(be).model&&ae(ce)})}var de=f(U,2),ge=u(de);d(de),d(Ye),W("click",ge,ot),h(Ge,Ye)};C(H,Ge=>{t(be).sessionFile&&Ge(D)})}var le=f(H,2);{var K=Ge=>{var Ye=zd(),pe=u(Ye,!0);d(Ye),j(()=>ue(pe,t(Se).error)),h(Ge,Ye)};C(le,Ge=>{t(Se).error&&!t(me)&&Ge(K)})}d(O);var T=f(O,2),F=u(T);{var te=Ge=>{var Ye=Hd();W("click",Ye,()=>{p(fe,"readonly"),_a()}),h(Ge,Ye)},De=Ge=>{var Ye=Bd();W("click",Ye,()=>p(fe,"main")),h(Ge,Ye)};C(F,Ge=>{t(fe)==="main"?Ge(te):Ge(De,-1)})}d(T);var Ae=f(T,2),xe=u(Ae);{var st=Ge=>{pa(Ge,{readOnly:!0})},It=Ge=>{pa(Ge,{})};C(xe,Ge=>{t(fe)==="readonly"?Ge(st):Ge(It,-1)})}d(Ae),j(()=>{qt(We,1,`h-2.5 w-2.5 rounded-full ${t(me)?"bg-emerald-500":"bg-rose-500"}`),qt(we,1,`text-sm ${t(me)?"text-emerald-400":"text-rose-400"}`),ue(ie,t(me)?"Connected":"Disconnected"),ue(k,`v${va}`)}),h(x,w)};C(He,x=>{t(oe)?x(ut):x(bt,-1)})}d(R);var et=f(R,2),rt=u(et),Oe=u(rt),Be=f(Oe,2);{var Wt=x=>{var w=Gd();W("click",w,kt),h(x,w)};C(Be,x=>{t(me)&&t(Ve)&&t(be).sessionFile&&x(Wt)})}var Ft=f(Be,2);{var At=x=>{var w=Yd(),O=u(w);{var Q=ie=>{var v=jd();h(ie,v)},We=ie=>{var v=qd();h(ie,v)},we=ie=>{var v=Vd();h(ie,v)};C(O,ie=>{t(me)&&t(Nt)?ie(Q):t(me)?ie(We,1):ie(we,-1)})}d(w),h(x,w)};C(Ft,x=>{(!t(me)||!t(be).sessionFile)&&x(At)})}var mt=f(Ft,2);{var xt=x=>{var w=eu(),O=u(w);{var Q=ie=>{var v=Zd(),k=f(u(v),2),H=u(k,!0);d(k),d(v),j(D=>{je(k,"title",t(be).cwd),ue(H,D)},[()=>t(be).cwd.split("/").pop()||t(be).cwd]),h(ie,v)};C(O,ie=>{t(be).cwd&&ie(Q)})}var We=f(O,2);{var we=ie=>{var v=Jd(),k=u(v),H=f(u(k),2);d(k);var D=f(k,2);{var le=T=>{var F=Xd();pn(F,21,()=>t(Te),An,(De,Ae)=>{var xe=Kd(),st=u(xe,!0);d(xe);var It={};j(()=>{ue(st,t(Ae).label),It!==(It=`${t(Ae).provider}:${t(Ae).modelId}`)&&(xe.value=xe.__value=`${t(Ae).provider}:${t(Ae).modelId}`)}),h(De,xe)}),d(F);var te;xa(F),j(()=>{te!==(te=t(be).model)&&(F.value=(F.__value=t(be).model)??"",ms(F,t(be).model))}),W("input",F,De=>Ma(De.currentTarget.value)),h(T,F)},K=T=>{var F=Qd(),te=u(F,!0);d(F),j(()=>{je(F,"title",t(be).model),ue(te,t(be).model)}),h(T,F)};C(D,T=>{t(Te).length>0&&!t(pt)?T(le):T(K,-1)})}d(v),j(()=>{qt(H,1,`absolute -right-0.5 -bottom-0.5 h-2 w-2 rounded-full border border-brand-surface ${t(Se).isStreaming?"animate-pulse bg-orange-500":"bg-emerald-500"}`),je(H,"title",t(Se).isStreaming?"Agent working...":"Ready")}),h(ie,v)};C(We,ie=>{t(be).model&&ie(we)})}d(w),h(x,w)};C(mt,x=>{t(be).sessionFile&&x(xt)})}var Zt=f(mt,2);{var Ce=x=>{var w=tu();h(x,w)};C(Zt,x=>{t(pt)&&x(Ce)})}d(rt);var Ze=f(rt,2);{var Pt=x=>{var w=nu();h(x,w)};C(Ze,x=>{t(dt)&&x(Pt)})}var _t=f(Ze,2);{var Xt=x=>{var w=ru(),O=u(w),Q=u(O,!0);d(O);var We=f(O,2);d(w),j(()=>ue(Q,t(ft))),W("click",We,()=>Bn()),h(x,w)};C(_t,x=>{t(ft)&&x(Xt)})}var Kt=f(_t,2);{var gt=x=>{var w=su();h(x,w)};C(Kt,x=>{t(pt)&&!t(dt)&&x(gt)})}var vt=f(Kt,2);En(yc(vt,{onMessageSent:()=>{}}),x=>Ie=x,()=>Ie);var ln=f(vt,2);{var an=x=>{var w=au();h(x,w)},cn=x=>{var w=lu(),O=Ht(w);{var Q=ie=>{var v=ou();h(ie,v)},We=ie=>{var v=iu();h(ie,v)};C(O,ie=>{t(be).sessionFile&&(t(Ue)||!t(me))?ie(Q):t(be).sessionFile&&t(Me)&&ie(We,1)})}var we=f(O,2);{let ie=se(()=>!!t(Ve)),v=se(()=>t(Nt)?!t(me):!t(me)||t(pt)||!t(be).sessionFile||t(Ue)||t(Me));En(jc(we,{get searchMode(){return t(Nt)},get searchConfigured(){return t(ie)},onSubmit:k=>Ca(k),placeholder:"Search the web...",submitLabel:"Search",get disabled(){return t(v)},onSend:()=>Ie?.forceScrollToBottom()}),k=>p(Tt,k,!0),()=>t(Tt))}h(x,w)};C(ln,x=>{t(pt)&&t(be).sessionFile?x(an):x(cn,-1)})}d(et);var rn=f(et,2);Id(rn,{});var dn=f(rn,2);{var E=x=>{var w=cu();W("click",w,()=>p(ye,!1)),h(x,w)};C(dn,x=>{t(ye)&&x(E)})}d(z),j(()=>qt(R,1,`app-chrome ${t(ye)?"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`)),W("click",Oe,()=>p(ye,!t(ye))),h(n,Mt),Un(),ve()}Gn(["click","input"]);export{xu as component,mu as universal};
82
+ //# sourceMappingURL=2.DgGMrWj9.js.map