tmux-weblink 3.0.2 → 3.1.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.
- package/dist/assets/shell-client.js +78 -78
- package/dist/browser/bots-client.js +6 -6
- package/dist/lib/bots/store.js +3 -3
- package/dist/lib/pages/shell.js +109 -56
- package/package.json +1 -1
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)}selectRows(e,n){let i=this.terminal.buffer.active,[s,l]=e<=n?[e,n]:[n,e];this.terminal.selectLines(i.viewportY+s,i.viewportY+l)}selectCells(e,n,i,s){let l=this.terminal.buffer.active,
|
|
3
|
-
`)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function
|
|
4
|
-
\x1B[31m`+
|
|
5
|
-
`).then(()=>{kt();try{s?.close()}catch{}});return}if(v.type==="auth.ok"){v.token&&localStorage.setItem("tmux-web-token",v.token),
|
|
1
|
+
var As=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function en(t){return t.replace(/\x1b\[\?1049[hl]/g,"")}function Ge(t){return t.replace(As,"")}var St;function zs(){return St||(document.querySelector("link[data-tmux-web-xterm-css]")?St=Promise.resolve():(St=new Promise(t=>{let e=document.createElement("link");e.rel="stylesheet",e.href="/assets/xterm.css",e.setAttribute("data-tmux-web-xterm-css",""),e.addEventListener("load",()=>t(),{once:!0}),e.addEventListener("error",()=>t(),{once:!0}),document.head.appendChild(e)}),St))}var Ms=class us{terminal;fitAddon;container;webglActive=!1;repaintTimer=0;webglAddon=null;constructor(e,n,i){this.container=e,this.terminal=n,this.fitAddon=i,this.terminal.loadAddon(this.fitAddon),this.terminal.open(e),this.enableWebglRenderer(),document.addEventListener("visibilitychange",()=>{document.hidden||this.refreshPaintedRows()})}enableWebglRenderer(){if(Rs()==="webgl"){try{if(!document.createElement("canvas").getContext("webgl2",{failIfMajorPerformanceCaveat:!0}))return}catch{return}import("./addon-webgl-B45EJ6AW.js").then(({WebglAddon:e})=>{let n=new e;n.onContextLoss(()=>{this.webglActive=!1,this.webglAddon=null;try{n.dispose()}catch{}this.fit()});try{this.terminal.loadAddon(n)}catch{return}this.webglAddon=n,this.webglActive=!0,this.fit()}).catch(()=>{})}}refreshPaintedRows(){if(this.webglActive){try{this.webglAddon?.clearTextureAtlas?.()}catch{}try{this.terminal.refresh(0,Math.max(0,this.terminal.rows-1))}catch{}}}static async create(e,n,i){let[{Terminal:s},{FitAddon:l}]=await Promise.all([import("./xterm-BXEES47M.js"),import("./addon-fit-D5N335P2.js"),zs()]),a="'JetBrains Mono', 'SF Mono', 'Menlo', monospace",r=new s({fontSize:Bs(14,a),fontFamily:a,cursorBlink:!0,cursorStyle:"bar",scrollback:n,convertEol:!1,smoothScrollDuration:120,theme:i});return new us(e,r,new l)}get cols(){return this.terminal.cols}get rows(){return this.terminal.rows}write(e){return new Promise(n=>this.terminal.write(e,n))}reset(){this.terminal.reset()}scrollToBottom(){this.terminal.scrollToBottom()}scrollToLine(e,n=!1){this.terminal.scrollToLine(Math.max(0,e),n),this.scheduleRepaintCheck()}scrollLines(e){this.terminal.scrollLines(e),this.scheduleRepaintCheck()}scheduleRepaintCheck(){this.webglActive&&(this.repaintTimer&&clearTimeout(this.repaintTimer),this.repaintTimer=setTimeout(()=>{this.repaintTimer=0,this.refreshPaintedRows()},150))}isNearScrollbackTop(){return this.terminal.buffer.active.viewportY<=1}viewportY(){return this.terminal.buffer.active.viewportY}baseY(){return this.terminal.buffer.active.baseY}cellHeight(){let e=this.terminal.element?.querySelector(".xterm-screen")?.getBoundingClientRect().height??0,n=this.terminal.rows;return e>0&&n>0?e/n:16}fit(){let e=Ps(this.container);if(e.width<=0||e.height<=0)return!1;let n=this.terminal.cols,i=this.terminal.rows,s=this.paintedCellWidth();s<=0&&(this.fitAddon.fit(),s=this.paintedCellWidth());let l=this.fitAddon.proposeDimensions?.();if(!l)return this.fitAddon.fit(),!0;let a=this.overlayScrollbarWidth(),r=a>0?a+2:0,o=s>0?Math.max(10,Math.min(l.cols,Math.floor((e.width-r)/s))):l.cols,c=l.rows;return(o!==this.terminal.cols||c!==this.terminal.rows)&&this.terminal.resize(o,c),this.webglActive&&(n!==this.terminal.cols||i!==this.terminal.rows)&&this.refreshPaintedRows(),!0}paintedCellWidth(){let e=this.terminal.element?.querySelector(".xterm-screen")?.getBoundingClientRect().width??0,n=this.terminal.cols;return e>0&&n>0?e/n:0}overlayScrollbarWidth(){let e=this.terminal.element?.querySelector(".vertical.scrollbar");if(!e)return 0;let n=e.getBoundingClientRect();return!(n.width>0)||!(n.height>0)?0:Math.round(n.width)}focus(){this.terminal.focus()}pasteText(e){this.terminal.paste(e)}input(e){this.terminal.input(e,!1)}onData(e){this.terminal.onData(e),this.terminal.onBinary(e)}onResize(e){this.terminal.onResize(e)}onScroll(e){this.terminal.onScroll(e)}attachCustomKeyEventHandler(e){this.terminal.attachCustomKeyEventHandler(e)}isFocused(){let e=document.activeElement;return e?e===this.container||e===this.terminal.textarea||this.container.contains(e)||!!e.closest?.(".xterm"):!1}getScreenText(){return this.getRowsText(0,this.terminal.rows-1)}getRowsText(e,n){let i=this.terminal.buffer.active,[s,l]=e<=n?[e,n]:[n,e],a=i.viewportY,r=[];for(let o=s;o<=l;o++){let c=i.getLine(a+o);r.push(c?c.translateToString(!0):"")}return r.join(`
|
|
2
|
+
`)}selectRows(e,n){let i=this.terminal.buffer.active,[s,l]=e<=n?[e,n]:[n,e];this.terminal.selectLines(i.viewportY+s,i.viewportY+l)}selectCells(e,n,i,s){let l=this.terminal.buffer.active,a=Math.min(n,s),r=Math.max(n,s);if(a===r){let o=Math.min(e,i),c=Math.max(e,i);this.terminal.select(o,l.viewportY+a,c-o+1)}else this.terminal.selectLines(l.viewportY+a,l.viewportY+r)}getCellsText(e,n,i,s){let l=this.terminal.buffer.active,a=Math.min(n,s),r=Math.max(n,s),o=n<s?e:n>s?i:Math.min(e,i),c=n<s?i:n>s?e:Math.max(e,i),d=l.viewportY,m=[];for(let p=a;p<=r;p++){let h=l.getLine(d+p);if(!h){m.push("");continue}let f=p===a?o:0,b=p===r?c:this.terminal.cols-1,w="";for(let y=f;y<=b;y++){let C=h.getCell(y);C&&(w+=C.getChars())}m.push(w.replace(/\s+$/,""))}return m.join(`
|
|
3
|
+
`)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function Bs(t,e){try{let n=document.createElement("canvas").getContext("2d");if(!n)return t;let i=100;n.font=`${i}px ${e}`;let s=n.measureText("M").width/i;if(!Number.isFinite(s)||s<=0)return t;let l=window.devicePixelRatio||1,a=t,r=Number.POSITIVE_INFINITY;for(let o=4;o<=40;o++){let c=o/(s*l);if(c<t-1.5||c>t+1.5)continue;let d=Math.abs(c-t);d<r&&(r=d,a=c)}return Math.round(a*100)/100}catch{return t}}function Rs(){try{let t=new URLSearchParams(window.location.search).get("renderer");return t==="dom"||t==="webgl"?t:null}catch{return null}}function Ps(t){let e=t.getBoundingClientRect(),n=window.visualViewport;return n?{width:Math.min(e.width,n.width),height:Math.max(0,Math.min(e.height,n.height-Math.max(0,e.top)))}:e}function Ds(t,e,n){return t.innerHTML="",t.classList.add("terminal-pending"),(async()=>{let i=await Ms.create(t,n.scrollback,n.theme),s,l=0,a,r=null,o=0,c=0,d=.2,m=10,p=.95,h=.04,f=null,b=null;function w(u){f||(f=document.createElement("div"),f.style.cssText=["position:absolute","left:0","width:40%","padding:10px 0","text-align:center","font:600 14px/1.4 system-ui, -apple-system, sans-serif","color:rgba(255,255,255,0.95)","background:rgba(20,30,50,0.55)","border:1px solid rgba(255,255,255,0.25)","border-radius:10px","pointer-events:none","opacity:0","transition:opacity 0.15s ease","z-index:6"].join(";"),t.appendChild(f)),f.textContent=u?"\u2191 \u4E0A\u7FFB\u4E00\u9875 (PgUp)":"\u2193 \u4E0B\u7FFB\u4E00\u9875 (PgDn)",f.style.top=u?"10%":"auto",f.style.bottom=u?"auto":"10%",f.style.opacity="1",b&&clearTimeout(b),b=setTimeout(()=>{f&&(f.style.opacity="0")},900)}function y(){b&&clearTimeout(b),f&&(f.style.opacity="0")}function C(){o&&(cancelAnimationFrame(o),o=0),c=0}function M(u){if(C(),Math.abs(u)<d)return;c=Math.max(-m,Math.min(m,u));let v=()=>{if(B){o=0;return}let S=i.cellHeight(),R=S>0?Math.round(c*16/S):c>0?1:-1;R===0&&(R=c>0?1:-1);let O=i.viewportY()-R,he=i.baseY(),Ee=Math.max(0,Math.min(O,he));if(i.scrollToLine(Ee,!0),c*=p,Ee!==O){o=0;return}if(Math.abs(c)<h){o=0;return}o=requestAnimationFrame(v)};o=requestAnimationFrame(v)}let T=0,I="connecting",$=0,z=!1,x=[],F="",B=!1,Z=1e3,A=location.protocol==="https:"?"wss:":"ws:",Se=n.wsBase||"/ws",W=A+"//"+location.host+Se+"/"+encodeURIComponent(e),L=(Se.replace(/^\/ws/,"")||"")+"/api/session/"+encodeURIComponent(e)+"/upload",U=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function ve(){return x.join("")+F}async function q(u,v=0){let S=u?i.viewportY():0,R=Ge(ve());if(i.reset(),!R){u||i.scrollToBottom();return}await i.write(R),u?i.scrollToLine(v+S):i.scrollToBottom()}function Y(u){s?.readyState===WebSocket.OPEN&&s.send(JSON.stringify(u))}function $e(u){let v;try{v=JSON.parse(u)}catch{I==="live"&&(F+=u,i.write(Ge(u)));return}if(v.type==="auth.required"){let S=localStorage.getItem("tmux-web-token");S?Y({type:"auth.token",token:S}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(v.type==="attach_failed"&&typeof v.message=="string"){Ne=!0,I="dead",i.reset(),i.write(`\r
|
|
4
|
+
\x1B[31m`+Ge(v.message)+`\x1B[0m\r
|
|
5
|
+
`).then(()=>{kt();try{s?.close()}catch{}});return}if(v.type==="auth.ok"){v.token&&localStorage.setItem("tmux-web-token",v.token),Z=1e3,Ie(),Y({type:"resize",cols:i.cols,rows:i.rows}),ne();return}if(v.type==="auth.failed"){if(v.permanentLock||v.retryAfterMs&&v.retryAfterMs>6e4){localStorage.removeItem("tmux-web-token"),location.href="/login?error="+encodeURIComponent(v.message);return}return}if(v.type==="snapshot"&&typeof v.data=="string"){let S=en(Ge(v.data));x=[S],F="",$=typeof v.lines=="number"?v.lines:n.terminal.initialLines,I="live",i.reset(),Ie(),Y({type:"resize",cols:i.cols,rows:i.rows}),i.write(S).then(()=>i.scrollToBottom());return}if(v.type==="window_changed"&&typeof v.activeIndex=="number"){let S=new URL(location.href);S.searchParams.get("window")!==String(v.activeIndex)&&(S.searchParams.set("window",String(v.activeIndex)),history.replaceState(history.state,"",S)),window.dispatchEvent(new CustomEvent("tmux:windows",{detail:v.windows}));return}if(v.type==="history"&&typeof v.data=="string"){v.lines>0&&v.data?(x.unshift(en(v.data)),$+=v.lines,q(!0,v.lines).finally(()=>{z=!1})):z=!1;return}if(v.type==="data"&&typeof v.data=="string"){let S=en(Ge(v.data));if(I==="connecting"){I="live",F=S,i.write(S);return}I==="live"&&(F+=S,i.write(S))}}let Ne=!1;function Nn(){if(Ne)return;let u=W,v=localStorage.getItem("tmux-web-token");v&&(u+=(u.includes("?")?"&":"?")+"token="+encodeURIComponent(v)),u+=(u.includes("?")?"&":"?")+"cols="+i.cols+"&rows="+i.rows,s=new WebSocket(u),s.onopen=()=>{I="connecting",$=0,z=!1,x=[],F="",i.reset(),Z=1e3},s.onmessage=S=>{typeof S.data=="string"&&$e(S.data)},s.onclose=()=>{B||(I="connecting",!Ne&&setTimeout(()=>{Z=Math.min(Z*2,1e4),!B&&!Ne&&Nn()},Z))},s.onerror=()=>s?.close()}function Oe(u){Y({type:"input",data:u})}function Ie(){return i.fit()}function kt(){t.classList.remove("terminal-pending")}function ne(){l&&cancelAnimationFrame(l),a&&clearTimeout(a),Ie(),l=requestAnimationFrame(()=>{l=0,Ie()&&kt()}),a=setTimeout(()=>{Ie()&&kt()},120)}function hs(){ne(),setTimeout(ne,50),setTimeout(ne,150),setTimeout(ne,300)}function On(u){return typeof u=="string"&&u.startsWith("image/")}function qn(u){return u?.files?.length?u.files[0]??null:null}function ms(u){if(!u?.items)return null;for(let v=0;v<u.items.length;v++){let S=u.items[v];if(S?.kind==="file"&&On(S.type))return S.getAsFile()}return null}async function fs(u){let v=new FormData,S=u instanceof File&&u.name?u.name:"upload";v.append("file",u,S);let R=localStorage.getItem("tmux-web-token"),O={};R&&(O.Authorization="Bearer "+R);let he=await fetch(L,{method:"POST",body:v,headers:O});if(!he.ok){let Yn="upload failed";try{let Xn=await he.json();Xn.error&&(Yn=Xn.error)}catch{}throw new Error(Yn)}let Ee=await he.json();if(!Ee.path)throw new Error("no path in response");return Ee.path}async function Kt(u){try{let v=await fs(u);Oe(v)}catch{}}i.onData(u=>Oe(u)),i.onResize(({cols:u,rows:v})=>Y({type:"resize",cols:u,rows:v})),i.onScroll(()=>{I!=="live"||z||!i.isNearScrollbackTop()||(z=!0,Y({type:"load_history",before:$}))});let Ze=!1,Ye=!1,X=null,Q=null,Xe=document.createElement("div");Xe.className="terminal-copy-banner",Xe.innerHTML='<strong>Copy mode</strong><span class="hint">drag to copy \xB7 Esc exits</span>',Xe.hidden=!0,t.appendChild(Xe);let be=document.createElement("div");be.className="terminal-copy-banner terminal-copy-toast",be.textContent="Copied",be.hidden=!0,t.appendChild(be);function jn(u,v){let S=t.querySelector(".xterm-screen, canvas"),R=(S&&S.getBoundingClientRect().width>0?S:t).getBoundingClientRect(),O=R.height>0&&i.rows>0?R.height/i.rows:18,he=R.width>0&&i.cols>0?R.width/i.cols:9;return{row:Math.max(0,Math.min(i.rows-1,Math.floor((v-R.top)/O))),col:Math.max(0,Math.min(i.cols-1,Math.floor((u-R.left)/he)))}}async function wt(u){if(!u)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(u);return}}catch{}let v=document.createElement("textarea");v.value=u,v.style.position="fixed",v.style.opacity="0",v.style.pointerEvents="none",document.body.appendChild(v),v.focus(),v.select();try{document.execCommand("copy")}catch{}v.remove()}let Ke;function yt(){be.hidden=!1,Ke&&clearTimeout(Ke),Ke=setTimeout(()=>{be.hidden=!0},1e3)}function qe(u){Ze=u,Xe.hidden=!u,t.classList.toggle("terminal-copy-mode-active",u),u&&i.focus()}function Vn(){qe(!Ze)}function gs(u){B||u.button!==0||Ye||(Ze||u.shiftKey)&&(u.preventDefault(),u.stopPropagation(),Ye=!0,X=jn(u.clientX,u.clientY),Q=X,i.selectCells(X.col,X.row,Q.col,Q.row),document.addEventListener("mousemove",Qt,!0),document.addEventListener("mouseup",Gt,!0))}function Qt(u){B||!Ye||!X||(u.preventDefault(),u.stopPropagation(),Q=jn(u.clientX,u.clientY),i.selectCells(X.col,X.row,Q.col,Q.row))}function Gt(u){if(B||!Ye||!X||!Q)return;u.preventDefault(),u.stopPropagation(),document.removeEventListener("mousemove",Qt,!0),document.removeEventListener("mouseup",Gt,!0),Ye=!1;let v=i.getCellsText(X.col,X.row,Q.col,Q.row);X=null,Q=null,i.clearSelection(),qe(!1),v&&(be.textContent="\u5DF2\u590D\u5236",wt(v).then(yt)),i.focus()}t.addEventListener("mousedown",gs,!0),document.addEventListener("keydown",vs,!0);function vs(u){if(!(B||!i.isFocused()||u.defaultPrevented||u.isComposing)){if(Ze){if(u.key==="Escape"){u.preventDefault(),u.stopPropagation(),X=null,Q=null,i.clearSelection(),qe(!1);return}if(u.key==="Enter"||(u.ctrlKey||u.metaKey)&&u.code==="KeyC"){u.preventDefault(),u.stopPropagation(),wt(i.getScreenText()).then(yt),qe(!1);return}}if(u.altKey&&u.code==="KeyC"&&!u.ctrlKey&&!u.metaKey){if(u.preventDefault(),u.stopPropagation(),X&&Q){let v=i.getCellsText(X.col,X.row,Q.col,Q.row);X=null,Q=null,i.clearSelection(),qe(!1),v&&(be.textContent="Copied",wt(v).then(yt))}else{let v=i.getSelection();v?(i.clearSelection(),be.textContent="Copied",wt(v).then(yt)):Vn()}return}if((u.ctrlKey||u.metaKey)&&u.code==="KeyV"){u.preventDefault(),u.stopPropagation(),(async()=>{try{if(navigator.clipboard?.read){let v=await navigator.clipboard.read();for(let S of v)for(let R of S.types)if(On(R)){let O=await S.getType(R);await Kt(O);return}}}catch{}try{let v=await navigator.clipboard?.readText();v&&i.pasteText(Wn(v))}catch{}})();return}}}let xt=0;function Wn(u){return u.split(`\r
|
|
6
6
|
`).join(`
|
|
7
7
|
`).split(`
|
|
8
|
-
`).join("\r")}async function vs(p){let v=hs(p.clipboardData);if(v){p.preventDefault(),p.stopPropagation();let O=Date.now();if(O-xt<50)return;xt=O,await Kt(v);return}let S=p.clipboardData?.getData("text/plain");if(!S)return;p.preventDefault(),p.stopPropagation();let A=Date.now();A-xt<50||(xt=A,i.pasteText(Wn(S)))}let Ke=0;function bs(p){p.preventDefault(),Ke++,qn(p.dataTransfer)&&t.classList.add("terminal-drag-over")}function ks(p){p.preventDefault(),p.dataTransfer&&(p.dataTransfer.dropEffect="copy")}function ws(p){p.preventDefault(),Ke--,Ke<=0&&(Ke=0,t.classList.remove("terminal-drag-over"))}async function ys(p){p.preventDefault(),Ke=0,t.classList.remove("terminal-drag-over");let v=qn(p.dataTransfer);v&&await Kt(v)}function Un(p){!bt||p.key!=="Escape"||Ze||p.defaultPrevented||p.repeat||p.metaKey||p.ctrlKey||p.altKey||i.isFocused()&&(p.preventDefault(),p.stopPropagation(),_e("\x1B"))}t.addEventListener("paste",vs),t.addEventListener("dragenter",bs),t.addEventListener("dragover",ks),t.addEventListener("dragleave",ws),t.addEventListener("drop",ys),document.addEventListener("keydown",Un,!0);function xs(p){if(p.touches.length!==1){a=null;return}let v=p.touches[0];if(!v)return;y();let S=t.getBoundingClientRect(),A=v.clientX-S.left<S.width*.4?"tui":"history",O=v.clientY-S.top<S.height*.5;a={startX:v.clientX,startY:v.clientY,lastX:v.clientX,lastY:v.clientY,lastT:performance.now(),velocity:0,scrolling:!1,zone:A,tuiUp:O,sent:!1},p.stopPropagation()}function Es(p){if(!a||p.touches.length!==1)return;let v=p.touches[0];if(!v)return;let S=v.clientY-a.startY,A=v.clientX-a.startX;if(!a.scrolling){if(Math.abs(S)<8||Math.abs(S)<Math.abs(A))return;a.scrolling=!0,T=Date.now()+500}p.preventDefault(),p.stopPropagation();let O=performance.now(),ue=v.clientY-a.lastY;if(a.zone==="tui"){a.sent||(a.sent=!0,_e(a.tuiUp?"\x1B[5~":"\x1B[6~"),x(a.tuiUp)),a.lastX=v.clientX,a.lastY=v.clientY,a.lastT=O;return}let xe=O-a.lastT;xe>0&&(a.velocity=ue/xe),Ts(-ue),a.lastX=v.clientX,a.lastY=v.clientY,a.lastT=O}function Ss(p){if(!a)return;let v=a.scrolling,S=a.zone,A=a.tuiUp,O=a.velocity;if(a=null,p.stopPropagation(),S==="tui"){v||(_e(A?"\x1B[5~":"\x1B[6~"),x(A),T=Date.now()+500,p.preventDefault());return}if(!v){i.focus();return}T=Date.now()+500,p.preventDefault(),O&&z(O)}function Cs(p){a=null,y(),p.stopPropagation()}function Ls(p){p.pointerType==="touch"&&Date.now()<T&&(p.preventDefault(),p.stopPropagation())}function Ts(p){let v=i.cellHeight(),S=v>0?Math.round(p/v):p>0?1:-1;S===0&&(S=p>0?1:-1),i.scrollLines(S)}t.addEventListener("touchstart",xs,{passive:!0,capture:!0}),t.addEventListener("touchmove",Es,{passive:!1,capture:!0}),t.addEventListener("touchend",Ss,{passive:!1,capture:!0}),t.addEventListener("touchcancel",Cs,{passive:!0,capture:!0}),t.addEventListener("pointerup",Ls,!0);function Zn(){Q()}window.addEventListener("resize",Zn),window.visualViewport?.addEventListener("resize",Q),window.visualViewport?.addEventListener("scroll",Q);let Jn=new ResizeObserver(()=>Q());Jn.observe(t),document.fonts?.ready.then(()=>{Q(),setTimeout(Q,50),setTimeout(Q,200)}),t.addEventListener("focusin",us,!0);async function Is(){if(document.fonts?.ready)try{await Promise.race([document.fonts.ready,new Promise(p=>setTimeout(p,1e3))])}catch{}}return requestAnimationFrame(()=>{Te()&&kt(),(async()=>(await Is(),Te()&&pe({type:"resize",cols:i.cols,rows:i.rows}),Nn(),Q()))()}),{destroy(){if(C=!0,y(),Fe(!1),Xe&&clearTimeout(Xe),document.removeEventListener("mousemove",Qt,!0),document.removeEventListener("mouseup",Gt,!0),s){try{s.close(1e3,"session switch")}catch{}s=void 0}t.innerHTML="",t.classList.remove("terminal-pending"),window.removeEventListener("resize",Zn),Jn.disconnect(),document.removeEventListener("keydown",Un,!0)},focus(){i.focus()},sendInput(p){_e(p)},toggleCopyMode(){Vn()}}})()}var Kn={menu:"M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z",close:"M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7a1 1 0 1 0-1.41 1.41L10.59 12l-4.89 4.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 1 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4z",search:"M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z",refresh:"M17.65 6.35A7.96 7.96 0 0 0 12 4a8 8 0 1 0 8 8h-2a6 6 0 1 1-6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM5.92 19H5v-.92l9.06-9.06.92.92L5.92 19zm13.66-12.83a1 1 0 0 0 0-1.41l-1.34-1.34a1 1 0 0 0-1.41 0l-1.05 1.05 2.75 2.75 1.05-1.05z",delete:"M15 4V3H9v1H4v2h1.5l.81 13.05A2 2 0 0 0 8.3 21h7.4a2 2 0 0 0 1.99-1.95L18.5 6H20V4h-5zm-5.5 2h5l-.75 12h-3.5L9.5 6z",check:"M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",sessions:"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z",notes:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",schedule:"M19 4h-1V2h-2v2H8V2H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 16H5V10h14v10zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z",agents:"M12 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm-7 13v-2a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v2h2v-2a7 7 0 0 0-7-7H10a7 7 0 0 0-7 7v2h2z",history:"M13 3a9 9 0 0 0-9 9H1l4 4 4-4H6a7 7 0 1 1 7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.96 8.96 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.25 2.55.75-1.23-3.5-2.08V8H12z","quick-commands":"M13 3 4 14h7l-1 7 9-11h-7l1-7z",windows:"M4 6h16v2H4V6zm0 5h10v2H4v-2zm0 5h16v2H4v-2z",terminal:"M4 17.6 6.4 20l8-8-8-8L4 6.4 11.6 12 4 17.6zM20 18h-8v2h8v-2z",microphone:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z",keyboard:"M20 5H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-9 3h2v2h-2V8zm0 3h2v2h-2v-2zM8 8h2v2H8V8zm0 3h2v2H8v-2zm-1 2H5v-2h2v2zm0-3H5V8h2v2zm9 7H8v-2h8v2zm0-4h-2v-2h2v2zm0-3h-2V8h2v2zm3 3h-2v-2h2v2zm0-3h-2V8h2v2z",bot:"M11 2h2v3h2a3 3 0 0 1 3 3v1h1a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-1v1a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-1H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2h1V8a3 3 0 0 1 3-3h2V2zm-2 6v1h6V8H9zm-2 5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm10 0a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z",layers:"M12 2 2 7l10 5 10-5-10-5zm0 7.5L4.5 5.8 12 2l7.5 3.8L12 9.5zM2 12l10 5 10-5-1.9-.95L12 14.9l-8.1-3.85L2 12zm0 4.5 10 5 10-5-1.9-.95L12 19.4l-8.1-3.85-1.9.95z",inbox:"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 16H5v-3h3.6a3.5 3.5 0 0 0 6.8 0H19v3zm0-5h-4.7a3.5 3.5 0 0 1-6.6 0H5V5h14v9z","chevron-down":"M7.4 8.6 12 13.2l4.6-4.6L18 10l-6 6-6-6 1.4-1.4z",settings:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6a3.6 3.6 0 1 1 0-7.2 3.6 3.6 0 0 1 0 7.2z",pin:"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4z","pin-outline":"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4zm-4.8 7.2V11l2-2V4h1.6v5l2 2v5.2H11.2z",folder:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z",file:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",worktree:"M6 3a3 3 0 0 0-1 5.83v6.34a3 3 0 1 0 2 0V8.83A3 3 0 0 0 6 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm0 12a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM18 3a3 3 0 0 0-1 5.83V9a4 4 0 0 1-4 4h-2a3 3 0 1 0 0 2h2a6 6 0 0 0 6-6v-.17A3 3 0 0 0 18 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM9 13a1 1 0 1 1 0 2 1 1 0 0 1 0-2z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",export:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",chevronRight:"M9.29 6.71a1 1 0 0 0 0 1.41L13.17 12l-3.88 3.88a1 1 0 1 0 1.41 1.41l4.59-4.59a1 1 0 0 0 0-1.41L10.7 6.7a1 1 0 0 0-1.41.01z",lightning:"M11 21h-1l1-7H7.5c-.58 0-.57-.32-.38-.66.19-.33.51-.89.73-1.27L13 3h1l-1 7h3.5c.49 0 .56.33.47.51l-.07.15c-.22.46-.58 1.18-.78 1.58L11 21z","git-branch":"M13.5 7a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zm0 10a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zM11 9.5v5.1a4.03 4.03 0 0 0-3-.1V9.4a4.03 4.03 0 0 0 3 .1z",external:"M14 3h7v7h-2V6l-9.29 9.29-1.41-1.41L17.59 4.5H14V3zm4 16H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7h-2v7z",play:"M8 5v14l11-7L8 5z",stop:"M6 6h12v12H6V6z",warning:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z",info:"M11 7h2v2h-2V7zm0 4h2v6h-2v-6zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z",shield:"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25z","shield-up":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM13 8.6v4.6h2l-3 3.6-3-3.6h2V8.6h2z","shield-alert":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM11 7.5h2v5h-2v-5zm0 6.5h2v2h-2v-2z",spinner:"M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0 0 20 12c0-4.42-3.58-8-8-8z",dots:"M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"};function Ds(t){return Kn[t]??Kn.menu}function ve(t,e=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${e?" "+e:""}><path d="${Ds(t)}"/></svg>`}function tn(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ie=tn();function Qn(t){Ie=t}var $e={exec:()=>null};function ze(t){let e=[];return n=>{let i=Math.max(0,Math.min(3,n-1)),s=e[i];return s||(s=t(i),e[i]=s),s}}function L(t,e=""){let n=typeof t=="string"?t:t.source,i={replace:(s,l)=>{let r=typeof l=="string"?l:l.source;return r=r.replace(H.caret,"$1"),n=n.replace(s,r),i},getRegex:()=>new RegExp(n,e)};return i}var Gn=((t="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+t)}catch{return!1}})(),ei="^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)",H={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,listInterruptsParagraph:/^ {0,3}(?:[*+-]|0{0,8}1[.)])[ \t]+[^ \t\n]/,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^( {1,3})(?:`{3}|~{3})/,beginningSpace:/^[ \t]{1,3}/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,multipleSpaceTabGlobal:/[ \t\r\n]+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,textIndentedContinuation:/^(?:\n(?: {4}| {0,3}\t)[ \t]*[^ \t\n][^\n]*)+/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+)[ \t]*)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,blockquoteMarkerWhitespace:/^( {0,3}>)(\t[ \t]*)/gm,blockquoteFenceOpen:/^ {0,3}(`{3,}(?=[^`]*$)|~{3,})/,blockquoteFenceClose:/^ {0,3}(`{3,}|~{3,})[ \t]*$/,blockquoteListItemStart:/^ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|$)/,nestedBlockMarker:/^ {0,3}(?:(?:[*+-]|\d{1,9}[.)])(?: |$)|> ?)/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\][ \t]+\S/,listReplaceTask:/^\[[ xX]\][ \t]+/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableHeader:new RegExp(ei+"(?:\\n|$)"),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,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/,numericCharacterReferenceOrAmpersand:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,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,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:ze(t=>new RegExp(`^ {0,${t}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:ze(t=>new RegExp(`^ {0,${t}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:ze(t=>new RegExp(`^ {0,${t}}(?:\`{3,}(?=[^\`\\n]*(?:\\n|$))|~~~)`)),headingBeginRegex:ze(t=>new RegExp(`^ {0,${t}}#{1,6}(?:\\s|$)`)),pedanticHeadingBeginRegex:ze(t=>new RegExp(`^ {0,${t}}#`)),htmlBeginRegex:ze(t=>new RegExp(`^ {0,${t}}(?:</?(?:${sn})(?:[ \\t]+|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,"i")),blockquoteBeginRegex:ze(t=>new RegExp(`^ {0,${t}}>`)),nestedContainerMarkers:/^(?: {0,3}(?:(?:[*+-]|\d{1,9}[.)])[ \t]+|>[ \t]?))+/},Hs=/^(?:[ \t]*(?:\n|$))+/,_s=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Fs=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}(?:(?=`)\1`*|(?=~)\1~*)[ \t]*(?=\n|$)|$)/,Ge=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ns=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,nn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,sn="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",et=L(" {0,3}(?:</?(?:tag)(?:[ \\t]+|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",sn).getRegex(),ti=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?![ \t]*\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/,ni=L(ti).replace(/bull/g,nn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}(?=[^`\n]*(?:\n|$))|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/\|table/g,"").replace(/html/g,et).getRegex(),Os=L(ti).replace(/bull/g,nn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}(?=[^`\n]*(?:\n|$))|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).replace(/html/g,et).getRegex(),rn=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,qs=/^[^\n]+/,ln=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/,js=L(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<(?:\\.|[^\n<>\\])*>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ln).replace("title",/(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\\n]|\n(?!\n))*'|\((?:\\[\s\S]|[^()\\])*\))/).getRegex(),Vs=L(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,nn).getRegex(),an=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Ws=L("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?:[ \\t]+|\\n|/?>|$)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!(?:script|pre|style|textarea)(?![a-z0-9-]))([a-z][a-z0-9-]*)(?:attribute)*?[ \\t]*/?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",an).replace("tag",sn).replace("attribute",/[ \t]+[a-zA-Z:_][\w.:-]*(?:[ \t]*=[ \t]*"[^"\n]*"|[ \t]*=[ \t]*'[^'\n]*'|[ \t]*=[ \t]*[^\s"'=<>`]+)?/).getRegex(),ii=t=>L(rn).replace("hr",Ge).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",t).replace("html",et).getRegex(),Us=ii(H.listInterruptsParagraph),Zs=ii(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),si=/ {0,3}> ?(?:(?!blank)(paragraph)|[^\n]*)(?:\n|$)/,Js=L(/^(first)(?:next)*/).replace("first",L(si).replace("blank",/[ \t]*(?:\n|$)| {4}/).getRegex()).replace("next",L(si).replace("blank",/[ \t]*(?:\n|$)/).getRegex()).replace(/paragraph/g,Zs).getRegex(),on={blockquote:Js,code:_s,def:js,fences:Fs,heading:Ns,hr:Ge,html:Ws,lheading:ni,list:Vs,newline:Hs,paragraph:Us,table:$e,text:qs},Ys=L(ei+"(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ge).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|0{0,8}1[.)])[ \\t]").replace("html",et).getRegex(),Xs={...on,lheading:Os,table:Ys,paragraph:L(rn).replace("hr",Ge).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",H.tableHeader).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",H.listInterruptsParagraph).replace("html",et).getRegex()},Ks={...on,html:L(`^ *(?:comment(?: *\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1>(?: *\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?>(?: *\\n{2,}|\\s*$))`).replace("comment",an).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:$e,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:L(rn).replace("hr",Ge).replace("heading",` *#{1,6} *[^
|
|
9
|
-
]`).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").replace("lheading",ni).getRegex()},
|
|
10
|
-
`),n=e.length-1;for(;n>=0&&
|
|
11
|
-
`)}function Tt(t,e=!1){let n=e?
|
|
12
|
-
`:t[s-1],
|
|
13
|
-
`&&
|
|
14
|
-
`)}function
|
|
15
|
-
`).map(
|
|
16
|
-
`)}function wi(t,e,n,i){if(!e.includes("<"))return!1;for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="`"){let
|
|
8
|
+
`).join("\r")}async function bs(u){let v=ms(u.clipboardData);if(v){u.preventDefault(),u.stopPropagation();let O=Date.now();if(O-xt<50)return;xt=O,await Kt(v);return}let S=u.clipboardData?.getData("text/plain");if(!S)return;u.preventDefault(),u.stopPropagation();let R=Date.now();R-xt<50||(xt=R,i.pasteText(Wn(S)))}let Qe=0;function ks(u){u.preventDefault(),Qe++,qn(u.dataTransfer)&&t.classList.add("terminal-drag-over")}function ws(u){u.preventDefault(),u.dataTransfer&&(u.dataTransfer.dropEffect="copy")}function ys(u){u.preventDefault(),Qe--,Qe<=0&&(Qe=0,t.classList.remove("terminal-drag-over"))}async function xs(u){u.preventDefault(),Qe=0,t.classList.remove("terminal-drag-over");let v=qn(u.dataTransfer);v&&await Kt(v)}function Un(u){!U||u.key!=="Escape"||Ze||u.defaultPrevented||u.repeat||u.metaKey||u.ctrlKey||u.altKey||i.isFocused()&&(u.preventDefault(),u.stopPropagation(),Oe("\x1B"))}t.addEventListener("paste",bs),t.addEventListener("dragenter",ks),t.addEventListener("dragover",ws),t.addEventListener("dragleave",ys),t.addEventListener("drop",xs),document.addEventListener("keydown",Un,!0);function Ss(u){if(u.touches.length!==1){r=null;return}let v=u.touches[0];if(!v)return;C();let S=t.getBoundingClientRect(),R=v.clientX-S.left<S.width*.4?"tui":"history",O=v.clientY-S.top<S.height*.5;r={startX:v.clientX,startY:v.clientY,lastX:v.clientX,lastY:v.clientY,lastT:performance.now(),velocity:0,scrolling:!1,zone:R,tuiUp:O,sent:!1},u.stopPropagation()}function Es(u){if(!r||u.touches.length!==1)return;let v=u.touches[0];if(!v)return;let S=v.clientY-r.startY,R=v.clientX-r.startX;if(!r.scrolling){if(Math.abs(S)<8||Math.abs(S)<Math.abs(R))return;r.scrolling=!0,T=Date.now()+500}u.preventDefault(),u.stopPropagation();let O=performance.now(),he=v.clientY-r.lastY;if(r.zone==="tui"){r.sent||(r.sent=!0,Oe(r.tuiUp?"\x1B[5~":"\x1B[6~"),w(r.tuiUp)),r.lastX=v.clientX,r.lastY=v.clientY,r.lastT=O;return}let Ee=O-r.lastT;Ee>0&&(r.velocity=he/Ee),$s(-he),r.lastX=v.clientX,r.lastY=v.clientY,r.lastT=O}function Cs(u){if(!r)return;let v=r.scrolling,S=r.zone,R=r.tuiUp,O=r.velocity;if(r=null,u.stopPropagation(),S==="tui"){v||(Oe(R?"\x1B[5~":"\x1B[6~"),w(R),T=Date.now()+500,u.preventDefault());return}if(!v){i.focus();return}T=Date.now()+500,u.preventDefault(),O&&M(O)}function Ls(u){r=null,C(),u.stopPropagation()}function Ts(u){u.pointerType==="touch"&&Date.now()<T&&(u.preventDefault(),u.stopPropagation())}function $s(u){let v=i.cellHeight(),S=v>0?Math.round(u/v):u>0?1:-1;S===0&&(S=u>0?1:-1),i.scrollLines(S)}t.addEventListener("touchstart",Ss,{passive:!0,capture:!0}),t.addEventListener("touchmove",Es,{passive:!1,capture:!0}),t.addEventListener("touchend",Cs,{passive:!1,capture:!0}),t.addEventListener("touchcancel",Ls,{passive:!0,capture:!0}),t.addEventListener("pointerup",Ts,!0);function Jn(){ne()}window.addEventListener("resize",Jn),window.visualViewport?.addEventListener("resize",ne),window.visualViewport?.addEventListener("scroll",ne);let Zn=new ResizeObserver(()=>ne());Zn.observe(t),document.fonts?.ready.then(()=>{ne(),setTimeout(ne,50),setTimeout(ne,200)}),t.addEventListener("focusin",hs,!0);async function Is(){if(document.fonts?.ready)try{await Promise.race([document.fonts.ready,new Promise(u=>setTimeout(u,1e3))])}catch{}}return requestAnimationFrame(()=>{Ie()&&kt(),(async()=>(await Is(),Ie()&&Y({type:"resize",cols:i.cols,rows:i.rows}),Nn(),ne()))()}),{destroy(){if(B=!0,C(),qe(!1),Ke&&clearTimeout(Ke),document.removeEventListener("mousemove",Qt,!0),document.removeEventListener("mouseup",Gt,!0),s){try{s.close(1e3,"session switch")}catch{}s=void 0}t.innerHTML="",t.classList.remove("terminal-pending"),window.removeEventListener("resize",Jn),Zn.disconnect(),document.removeEventListener("keydown",Un,!0)},focus(){i.focus()},sendInput(u){Oe(u)},toggleCopyMode(){Vn()}}})()}var Kn={menu:"M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z",close:"M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7a1 1 0 1 0-1.41 1.41L10.59 12l-4.89 4.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 1 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4z",search:"M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z",refresh:"M17.65 6.35A7.96 7.96 0 0 0 12 4a8 8 0 1 0 8 8h-2a6 6 0 1 1-6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM5.92 19H5v-.92l9.06-9.06.92.92L5.92 19zm13.66-12.83a1 1 0 0 0 0-1.41l-1.34-1.34a1 1 0 0 0-1.41 0l-1.05 1.05 2.75 2.75 1.05-1.05z",delete:"M15 4V3H9v1H4v2h1.5l.81 13.05A2 2 0 0 0 8.3 21h7.4a2 2 0 0 0 1.99-1.95L18.5 6H20V4h-5zm-5.5 2h5l-.75 12h-3.5L9.5 6z",check:"M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",sessions:"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z",notes:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",schedule:"M19 4h-1V2h-2v2H8V2H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 16H5V10h14v10zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z",agents:"M12 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm-7 13v-2a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v2h2v-2a7 7 0 0 0-7-7H10a7 7 0 0 0-7 7v2h2z",history:"M13 3a9 9 0 0 0-9 9H1l4 4 4-4H6a7 7 0 1 1 7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.96 8.96 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.25 2.55.75-1.23-3.5-2.08V8H12z","quick-commands":"M13 3 4 14h7l-1 7 9-11h-7l1-7z",windows:"M4 6h16v2H4V6zm0 5h10v2H4v-2zm0 5h16v2H4v-2z",terminal:"M4 17.6 6.4 20l8-8-8-8L4 6.4 11.6 12 4 17.6zM20 18h-8v2h8v-2z",microphone:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z",keyboard:"M20 5H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-9 3h2v2h-2V8zm0 3h2v2h-2v-2zM8 8h2v2H8V8zm0 3h2v2H8v-2zm-1 2H5v-2h2v2zm0-3H5V8h2v2zm9 7H8v-2h8v2zm0-4h-2v-2h2v2zm0-3h-2V8h2v2zm3 3h-2v-2h2v2zm0-3h-2V8h2v2z",bot:"M11 2h2v3h2a3 3 0 0 1 3 3v1h1a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-1v1a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-1H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2h1V8a3 3 0 0 1 3-3h2V2zm-2 6v1h6V8H9zm-2 5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm10 0a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z",layers:"M12 2 2 7l10 5 10-5-10-5zm0 7.5L4.5 5.8 12 2l7.5 3.8L12 9.5zM2 12l10 5 10-5-1.9-.95L12 14.9l-8.1-3.85L2 12zm0 4.5 10 5 10-5-1.9-.95L12 19.4l-8.1-3.85-1.9.95z",inbox:"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 16H5v-3h3.6a3.5 3.5 0 0 0 6.8 0H19v3zm0-5h-4.7a3.5 3.5 0 0 1-6.6 0H5V5h14v9z","chevron-down":"M7.4 8.6 12 13.2l4.6-4.6L18 10l-6 6-6-6 1.4-1.4z",settings:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6a3.6 3.6 0 1 1 0-7.2 3.6 3.6 0 0 1 0 7.2z",pin:"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4z","pin-outline":"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4zm-4.8 7.2V11l2-2V4h1.6v5l2 2v5.2H11.2z",folder:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z",file:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",worktree:"M6 3a3 3 0 0 0-1 5.83v6.34a3 3 0 1 0 2 0V8.83A3 3 0 0 0 6 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm0 12a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM18 3a3 3 0 0 0-1 5.83V9a4 4 0 0 1-4 4h-2a3 3 0 1 0 0 2h2a6 6 0 0 0 6-6v-.17A3 3 0 0 0 18 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM9 13a1 1 0 1 1 0 2 1 1 0 0 1 0-2z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",export:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",chevronRight:"M9.29 6.71a1 1 0 0 0 0 1.41L13.17 12l-3.88 3.88a1 1 0 1 0 1.41 1.41l4.59-4.59a1 1 0 0 0 0-1.41L10.7 6.7a1 1 0 0 0-1.41.01z",lightning:"M11 21h-1l1-7H7.5c-.58 0-.57-.32-.38-.66.19-.33.51-.89.73-1.27L13 3h1l-1 7h3.5c.49 0 .56.33.47.51l-.07.15c-.22.46-.58 1.18-.78 1.58L11 21z","git-branch":"M13.5 7a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zm0 10a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zM11 9.5v5.1a4.03 4.03 0 0 0-3-.1V9.4a4.03 4.03 0 0 0 3 .1z",external:"M14 3h7v7h-2V6l-9.29 9.29-1.41-1.41L17.59 4.5H14V3zm4 16H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7h-2v7z",play:"M8 5v14l11-7L8 5z",stop:"M6 6h12v12H6V6z",warning:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z",info:"M11 7h2v2h-2V7zm0 4h2v6h-2v-6zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z",shield:"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25z","shield-up":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM13 8.6v4.6h2l-3 3.6-3-3.6h2V8.6h2z","shield-alert":"M12 2 4 5v6c0 5.55 3.84 10.74 8 12 4.16-1.26 8-6.45 8-12V5l-8-3zm0 2.18 6 2.25V11c0 4.52-3.05 8.86-6 10-2.95-1.14-6-5.48-6-10V6.43l6-2.25zM11 7.5h2v5h-2v-5zm0 6.5h2v2h-2v-2z",spinner:"M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0 0 20 12c0-4.42-3.58-8-8-8z",dots:"M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"};function Hs(t){return Kn[t]??Kn.menu}function ae(t,e=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${e?" "+e:""}><path d="${Hs(t)}"/></svg>`}function tn(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ae=tn();function Qn(t){Ae=t}var ze={exec:()=>null};function Me(t){let e=[];return n=>{let i=Math.max(0,Math.min(3,n-1)),s=e[i];return s||(s=t(i),e[i]=s),s}}function E(t,e=""){let n=typeof t=="string"?t:t.source,i={replace:(s,l)=>{let a=typeof l=="string"?l:l.source;return a=a.replace(_.caret,"$1"),n=n.replace(s,a),i},getRegex:()=>new RegExp(n,e)};return i}var Gn=((t="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+t)}catch{return!1}})(),ei="^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)",_={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,listInterruptsParagraph:/^ {0,3}(?:[*+-]|0{0,8}1[.)])[ \t]+[^ \t\n]/,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^( {1,3})(?:`{3}|~{3})/,beginningSpace:/^[ \t]{1,3}/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,multipleSpaceTabGlobal:/[ \t\r\n]+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,textIndentedContinuation:/^(?:\n(?: {4}| {0,3}\t)[ \t]*[^ \t\n][^\n]*)+/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+)[ \t]*)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,blockquoteMarkerWhitespace:/^( {0,3}>)(\t[ \t]*)/gm,blockquoteFenceOpen:/^ {0,3}(`{3,}(?=[^`]*$)|~{3,})/,blockquoteFenceClose:/^ {0,3}(`{3,}|~{3,})[ \t]*$/,blockquoteListItemStart:/^ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|$)/,nestedBlockMarker:/^ {0,3}(?:(?:[*+-]|\d{1,9}[.)])(?: |$)|> ?)/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\][ \t]+\S/,listReplaceTask:/^\[[ xX]\][ \t]+/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableHeader:new RegExp(ei+"(?:\\n|$)"),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,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/,numericCharacterReferenceOrAmpersand:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,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,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:Me(t=>new RegExp(`^ {0,${t}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:Me(t=>new RegExp(`^ {0,${t}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:Me(t=>new RegExp(`^ {0,${t}}(?:\`{3,}(?=[^\`\\n]*(?:\\n|$))|~~~)`)),headingBeginRegex:Me(t=>new RegExp(`^ {0,${t}}#{1,6}(?:\\s|$)`)),pedanticHeadingBeginRegex:Me(t=>new RegExp(`^ {0,${t}}#`)),htmlBeginRegex:Me(t=>new RegExp(`^ {0,${t}}(?:</?(?:${sn})(?:[ \\t]+|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,"i")),blockquoteBeginRegex:Me(t=>new RegExp(`^ {0,${t}}>`)),nestedContainerMarkers:/^(?: {0,3}(?:(?:[*+-]|\d{1,9}[.)])[ \t]+|>[ \t]?))+/},_s=/^(?:[ \t]*(?:\n|$))+/,Fs=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ns=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}(?:(?=`)\1`*|(?=~)\1~*)[ \t]*(?=\n|$)|$)/,et=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Os=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,nn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,sn="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",tt=E(" {0,3}(?:</?(?:tag)(?:[ \\t]+|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",sn).getRegex(),ti=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?![ \t]*\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+)[ \t]*(?:\n+|$)/,ni=E(ti).replace(/bull/g,nn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}(?=[^`\n]*(?:\n|$))|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/\|table/g,"").replace(/html/g,tt).getRegex(),qs=E(ti).replace(/bull/g,nn).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}(?=[^`\n]*(?:\n|$))|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).replace(/html/g,tt).getRegex(),an=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,js=/^[^\n]+/,ln=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/,Vs=E(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<(?:\\.|[^\n<>\\])*>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ln).replace("title",/(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\\n]|\n(?!\n))*'|\((?:\\[\s\S]|[^()\\])*\))/).getRegex(),Ws=E(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,nn).getRegex(),rn=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Us=E("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?:[ \\t]+|\\n|/?>|$)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!(?:script|pre|style|textarea)(?![a-z0-9-]))([a-z][a-z0-9-]*)(?:attribute)*?[ \\t]*/?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",rn).replace("tag",sn).replace("attribute",/[ \t]+[a-zA-Z:_][\w.:-]*(?:[ \t]*=[ \t]*"[^"\n]*"|[ \t]*=[ \t]*'[^'\n]*'|[ \t]*=[ \t]*[^\s"'=<>`]+)?/).getRegex(),ii=t=>E(an).replace("hr",et).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",t).replace("html",tt).getRegex(),Js=ii(_.listInterruptsParagraph),Zs=ii(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),si=/ {0,3}> ?(?:(?!blank)(paragraph)|[^\n]*)(?:\n|$)/,Ys=E(/^(first)(?:next)*/).replace("first",E(si).replace("blank",/[ \t]*(?:\n|$)| {4}/).getRegex()).replace("next",E(si).replace("blank",/[ \t]*(?:\n|$)/).getRegex()).replace(/paragraph/g,Zs).getRegex(),on={blockquote:Ys,code:Fs,def:Vs,fences:Ns,heading:Os,hr:et,html:Us,lheading:ni,list:Ws,newline:_s,paragraph:Js,table:ze,text:js},Xs=E(ei+"(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",et).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|0{0,8}1[.)])[ \\t]").replace("html",tt).getRegex(),Ks={...on,lheading:qs,table:Xs,paragraph:E(an).replace("hr",et).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",_.tableHeader).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",_.listInterruptsParagraph).replace("html",tt).getRegex()},Qs={...on,html:E(`^ *(?:comment(?: *\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1>(?: *\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?>(?: *\\n{2,}|\\s*$))`).replace("comment",rn).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:ze,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:E(an).replace("hr",et).replace("heading",` *#{1,6} *[^
|
|
9
|
+
]`).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").replace("lheading",ni).getRegex()},Gs=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,ea=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ai=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,ta=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,me=/[\p{P}\p{S}]/u,je=/[\s\p{P}\p{S}]/u,nt=/[^\s\p{P}\p{S}]/u,na=E(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,je).getRegex(),ia=/[\p{Pi}\p{Ps}"']/u,li=/(?!~)[\p{P}\p{S}]/u,sa=/(?!~)[\s\p{P}\p{S}]/u,aa=/(?:[^\s\p{P}\p{S}]|~)/u,la=E(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Gn?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),ri=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,ra=E(ri,"u").replace(/punct/g,me).getRegex(),oa=E(ri,"u").replace(/punct/g,li).getRegex(),ca=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,da=E(ca,"u").replace(/openQuote/g,ia).replace(/punct/g,me).getRegex(),oi="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",pa=E(oi,"gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),ua=E(oi,"gu").replace(/notPunctSpace/g,aa).replace(/punctSpace/g,sa).replace(/punct/g,li).getRegex(),ha="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",ma=E(ha,"gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),fa=E("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),ga="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",va=E(ga,"gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),ba=E(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,me).getRegex(),ka="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",wa=E(ka,"gu").replace(/notPunctSpace/g,nt).replace(/punctSpace/g,je).replace(/punct/g,me).getRegex(),ya=E(/\\(punct)/,"gu").replace(/punct/g,me).getRegex(),xa=E(/(`+)(?:[^`]|[^`][\s\S]*?[^`])\1(?!`)|`+|\\(punct)/,"gu").replace(/punct/g,me).getRegex(),Sa=E(/^<(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(),Ea=E(rn).replace("(?:-->|$)","-->").getRegex(),Ca=E("^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Ea).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ci=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,Et=E(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets",ci).getRegex(),Ct=/\\[^ \t\n\x00-\x1f]|\\(?=[ \t\n])|[^ \t\n\x00-\x1f\\()]/,La=E(/\((?:char)*\)/).replace("char",Ct).getRegex(),Ta=E(/\((?:char|p1)*\)/).replace("char",Ct).replace("p1",La).getRegex(),$a=E(/\((?:char|p2)*\)/).replace("char",Ct).replace("p2",Ta).getRegex(),Ia=E(/(?!<)(?:char|p3)+/).replace("char",Ct).replace("p3",$a).getRegex(),Aa=E(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace("label",Et).replace("href",E(/<(?:\\.|[^\n<>\\])*>|bareHref|(?=\))/).replace("bareHref",Ia).getRegex()).replace("title",/"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\((?:\\[\s\S]|[^)\\])*\)/).getRegex(),za=E(/^!?\[(label)\]\[(ref)\]/).replace("label",Et).replace("ref",ln).getRegex(),Ma=E(/^!?\[(ref)\](?:\[\])?/).replace("ref",ln).getRegex(),di=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,Ba=E(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets",ci).getRegex(),Ra=E("reflink|nolink(?!\\()","g").replace("reflink",E(/^!?\[(label)\]\[(ref)\]/).replace("label",Ba).replace("ref",di).getRegex()).replace("nolink",E(/^!?\[(ref)\](?:\[\])?/).replace("ref",di).getRegex()).getRegex(),pi=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Pa=/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/,Da=E(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,Pa).getRegex(),cn={_backpedal:ze,anyPunctuation:ya,anyPunctuationOutsideCode:xa,autolink:Sa,blockSkip:la,br:ai,code:ea,del:ze,delLDelim:ze,delRDelim:ze,emStrongLDelim:ra,emStrongRDelimAst:pa,emStrongRDelimUnd:fa,escape:Gs,link:Aa,nolink:Ma,punctuation:na,reflink:za,reflinkSearch:Ra,tag:Ca,text:ta,url:ze},Ha={...cn,emStrongLDelim:da,emStrongRDelimAst:ma,emStrongRDelimUnd:va,link:E(/^!?\[(label)\]\((.*?)\)/).replace("label",Et).getRegex(),reflink:E(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Et).getRegex()},dn={...cn,emStrongRDelimAst:ua,emStrongLDelim:oa,delLDelim:ba,delRDelim:wa,url:E(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol",Da).replace("protocol",pi).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:E(/^(?:[A-Za-z0-9.+-]+(?=@)|[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|wwwStart|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace("protocol",pi).replace(/emailProtocol/g,/(?:mailto|xmpp):/).replace("wwwStart",Gn?"(?<![^\\s*_~(])www\\.":"www\\.").getRegex()},_a={...dn,br:E(ai).replace("{2,}","*").getRegex(),text:E(dn.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Lt={normal:on,gfm:Ks,pedantic:Qs},it={normal:cn,gfm:dn,breaks:_a,pedantic:Ha},Fa={"&":"&","<":"<",">":">",'"':""","'":"'"},ui=t=>Fa[t];function G(t,e){if(e){if(_.escapeTest.test(t))return t.replace(_.escapeReplace,ui)}else if(_.escapeTestNoEncode.test(t))return t.replace(_.escapeReplaceNoEncode,ui);return t}function Na(t){return _.numericCharacterReference.test(t)?t.replace(_.numericCharacterReferenceOrAmpersand,(e,n,i)=>{if(n===void 0&&i===void 0)return"&";let s=n===void 0?Number.parseInt(i,16):Number.parseInt(n,10);return s===0||s>1114111||s>=55296&&s<=57343?"\uFFFD":s===38?"&":String.fromCodePoint(s)}):t}function hi(t){try{t=encodeURI(t).replace(_.percentDecode,"%")}catch{return null}return t}function pn(t,e){let n=t.replace(_.findPipe,(l,a,r)=>{let o=!1,c=a;for(;--c>=0&&r[c]==="\\";)o=!o;return o?"|":" |"}),i=n.split(_.splitPipe),s=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),e)if(i.length>e)i.splice(e);else for(;i.length<e;)i.push("");for(;s<i.length;s++)i[s]=i[s].trim().replace(_.slashPipe,"|");return i}function ke(t,e,n){let i=t.length;if(i===0)return"";let s=0;for(;s<i;){let l=t.charAt(i-s-1);if(l===e&&!n)s++;else if(l!==e&&n)s++;else break}return t.slice(0,i-s)}function mi(t){let e=t.split(`
|
|
10
|
+
`),n=e.length-1;for(;n>=0&&_.blankLine.test(e[n]);)n--;return e.length-n<=2?t:e.slice(0,n+1).join(`
|
|
11
|
+
`)}function Tt(t,e=!1){let n=e?_.multipleSpaceGlobal:_.multipleSpaceTabGlobal;return t.trim().replace(n," ").toLowerCase().toUpperCase().toLowerCase()}function fi(t,e){if(t.indexOf(e[0])===-1&&t.indexOf(e[1])===-1)return-1;let n=0;for(let i=0;i<t.length;i++)if(t[i]==="\\")i++;else if(t[i]===e[0])n++;else if(t[i]===e[1]&&(n--,n<0))return i;return n>0?-2:-1}var Ve=new WeakMap;function un(t){let e={"*":-1,_:-1},n=-1,i=t.length;for(let s=0;s<i;s++){let l=t[s];if(l!=="*"&&l!=="_"&&l!=="~")continue;let a=s===0?`
|
|
12
|
+
`:t[s-1],r=s+1;for(;r<i&&t[r]===l;)r++;a!==" "&&a!==" "&&a!==`
|
|
13
|
+
`&&a!=="\r"&&a!=="\f"&&(l==="~"?n=s:e[l]=s),s=r-1}return{maskedSrc:t,lastPossibleEmStrongCloserIndex:e,lastPossibleDelCloserIndex:n}}function Oa(t,e){let n=un(e),i=Ve.get(t);i?i.push(n):Ve.set(t,[n])}function qa(t){let e=Ve.get(t);e&&(e.pop(),e.length===0&&Ve.delete(t))}function gi(t,e,n){let i=Ve.get(t)?.at(-1);return i&&i.maskedSrc===e?i.lastPossibleEmStrongCloserIndex[n]:un(e).lastPossibleEmStrongCloserIndex[n]}function vi(t,e){let n=Ve.get(t)?.at(-1);return n&&n.maskedSrc===e?n.lastPossibleDelCloserIndex:un(e).lastPossibleDelCloserIndex}function st(t,e=0){let n=e,i="";for(let s of t)if(s===" "){let l=4-n%4;i+=" ".repeat(l),n+=l}else i+=s,n++;return i}function ja(t){let e,n=!1;return t.map(i=>{if(n)return i;let{depth:s,expanded:l,keptIndent:a,content:r}=Va(i,e?.depth??1/0);if(e?.depth!==s&&(e=void 0),e){let c=_.blockquoteFenceClose.exec(r)?.[1];return!c||c[0]!==e.marker[0]||c.length<e.marker.length?a:(e=void 0,l)}if(n=_.blockquoteListItemStart.test(r),n)return i;let o=_.blockquoteFenceOpen.exec(r)?.[1];return o&&(e={marker:o,depth:s}),l}).join(`
|
|
14
|
+
`)}function Va(t,e){let n=0,i=0,s=0,l=0,a="";for(;s<e;){let d=n,m=i;for(;t[d]===" "||t[d]===" ";)m+=bi(t[d],m),d++;if(t[d]!==">"||m-l>3)break;a+=" ".repeat(m-i)+">",s++,n=d+1,i=m+1,l=t[n]===" "||t[n]===" "?i+1:i}if(s===0)return{depth:s,expanded:t,keptIndent:t,content:t};let r="",o="";for(;(t[n]===" "||t[n]===" ")&&i<l+4;){let d=bi(t[n],i);r+=" ".repeat(d),o+=i<l&&d>1?" ".repeat(d):t[n],i+=d,n++}let c=t.slice(n);return{depth:s,expanded:a+r+c,keptIndent:a+o+c,content:" ".repeat(Math.max(0,i-l))+c}}function bi(t,e){return t===" "?4-e%4:1}function Wa(t,e){let n="";for(let i=0;i<t.length;i++){if(t[i]==="`"){let s=e.inline.code.exec(t.slice(i));if(s){n+=s[0],i+=s[0].length-1;continue}}if(t[i]==="\\"&&(t[i+1]==="["||t[i+1]==="]")){n+=t[i+1],i++;continue}n+=t[i]}return n}function ki(t,e,n,i,s){let l=e.href,a=e.title||null,r=Wa(t[1],s),o=t[0].charAt(0)==="!",c=i.state.inLink,d=i.state.linkEmitted,m=i.state.inRawBlock;i.state.inLink=!0,i.state.linkEmitted=!1;let p=i.inlineTokens(r),h=i.state.linkEmitted;if(i.state.linkEmitted=d,i.state.inLink=c,!o){if(h){i.state.inRawBlock=m;return}i.state.linkEmitted=!0}return{type:o?"image":"link",raw:n,href:l,title:a,text:r,tokens:p}}function Ua(t,e,n,i){let s=t.match(n.other.indentCodeCompensation);if(s===null)return e;let l=s[1].length;return e.split(`
|
|
15
|
+
`).map(a=>{let r=a.match(n.other.beginningSpace);if(r===null)return a;let[o]=r,c=o.indexOf(" ");if(c!==-1&&c<l){if(i)return" ".repeat(4-l)+a.slice(c+1);if(t[l]==="~")return a}return a.slice(Math.min(o.length,l))}).join(`
|
|
16
|
+
`)}function wi(t,e,n,i){if(!e.includes("<"))return!1;for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="`"){let r=i.inline.code.exec(e.slice(s));if(r){s+=r[0].length-1;continue}}if(e[s]!=="<")continue;let l=t.slice(n+s),a=i.inline.tag.exec(l)||i.inline.autolink.exec(l);if(a){if(a[0].length>e.length-s)return!0;s+=a[0].length-1}}return!1}var Be=class{options;rules;lexer;constructor(t){this.options=t||Ae}space(t){let e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){let e=this.rules.block.code.exec(t);if(e){let n=this.options.pedantic?e[0]:mi(e[0]),i=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:i}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],i=Ua(n,e[3]||"",this.rules,this.lexer.state.top&&!this.lexer.state.inBlockquote);e[3]!==void 0&&(i===""||i.endsWith(`
|
|
17
17
|
`))&&(i+=`
|
|
18
|
-
`);let s=e[2];if(s){let l=0,
|
|
19
|
-
`),depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){let e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:
|
|
20
|
-
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=
|
|
18
|
+
`);let s=e[2];if(s){let l=0,a=s.length;for(;l<a&&(s[l]===" "||s[l]===" ");)l++;for(;a>l&&(s[a-1]===" "||s[a-1]===" ");)a--;s=s.slice(l,a).replace(this.rules.inline.anyPunctuation,"$1")}return{type:"code",raw:n,lang:s,text:i}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){let i=ke(n,"#");(this.options.pedantic||!i||this.rules.other.endingSpaceTabChar.test(i))&&(n=i.trim())}return{type:"heading",raw:ke(e[0],`
|
|
19
|
+
`),depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){let e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:ke(e[0],`
|
|
20
|
+
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=ke(e[0],`
|
|
21
21
|
`).split(`
|
|
22
|
-
`),i="",s="",l=[];for(;n.length>0;){let
|
|
23
|
-
`),d=(this.lexer.state.top&&!this.lexer.state.inBlockquote&&c.includes(" ")?
|
|
22
|
+
`),i="",s="",l=[];for(;n.length>0;){let a=!1,r=[],o;for(o=0;o<n.length;o++)if(this.rules.other.blockquoteStart.test(n[o]))r.push(n[o]),a=!0;else if(!a)r.push(n[o]);else break;n=n.slice(o);let c=r.join(`
|
|
23
|
+
`),d=(this.lexer.state.top&&!this.lexer.state.inBlockquote&&c.includes(" ")?ja(r):c).replace(this.rules.other.blockquoteMarkerWhitespace,(b,w,y)=>y.startsWith(" ")?w+" "+y.slice(1):w+st(y,w.length)).replace(this.rules.other.blockquoteSetextReplace,`
|
|
24
24
|
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");i=i?`${i}
|
|
25
25
|
${c}`:c,s=s?`${s}
|
|
26
|
-
${d}`:d;let m=this.lexer.state.top,
|
|
27
|
-
`),
|
|
28
|
-
`+
|
|
26
|
+
${d}`:d;let m=this.lexer.state.top,p=this.lexer.state.inBlockquote,h=this.lexer.state.lastToken;if(this.lexer.state.top=!0,this.lexer.state.inBlockquote=!0,this.lexer.blockTokens(d,l,!0),this.lexer.state.top=m,this.lexer.state.inBlockquote=p,n.length===0)break;let f=l.at(-1);if(f?.type==="code"||f?.type==="heading"||f?.type==="hr"||f?.type==="html"||f?.type==="table")break;if(f?.type==="blockquote"){let b=f,w=n.join(`
|
|
27
|
+
`),y=b.raw+`
|
|
28
|
+
`+w.replace(this.rules.other.blockquoteSetextReplace2,"");this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=l.at(-2);let C=this.blockquote(y);this.lexer.state.inBlockquote=p,this.lexer.state.lastToken=h,l[l.length-1]=C;let M=y.substring(C.raw.length).replace(/^\n/,""),T=M?M.split(`
|
|
29
29
|
`).length:0,I=T?n.slice(0,-T):n;if(I.length>0&&(i=`${i}
|
|
30
30
|
${I.join(`
|
|
31
|
-
`)}`),s=s.substring(0,s.length-b.text.length)+
|
|
31
|
+
`)}`),s=s.substring(0,s.length-b.text.length)+C.text,n=n.slice(I.length),n.length>0&&this.rules.other.blockquoteStart.test(n[0]))continue;break}else if(f?.type==="list"){let b=f,w=b.raw+`
|
|
32
32
|
`+n.join(`
|
|
33
|
-
`);this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=l.at(-2);let
|
|
34
|
-
`).length:0;if(
|
|
33
|
+
`);this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=l.at(-2);let y=this.list(w);this.lexer.state.top=m,this.lexer.state.inBlockquote=p,this.lexer.state.lastToken=h,l[l.length-1]=y;let C=y.raw.length>b.raw.length?w.slice(b.raw.length+1,y.raw.length).split(`
|
|
34
|
+
`).length:0;if(C>0){let M=n.slice(0,C).join(`
|
|
35
35
|
`);i=`${i}
|
|
36
|
-
${
|
|
37
|
-
${
|
|
38
|
-
`,1)[0],
|
|
39
|
-
`,1)[0],
|
|
40
|
-
`,1)[0],
|
|
41
|
-
`+
|
|
42
|
-
`)&&!
|
|
43
|
-
${
|
|
44
|
-
`+
|
|
45
|
-
`),href:i,title:s}}}table(t){let e,n;if(this.options.gfm&&!this.options.pedantic){let
|
|
46
|
-
`):[],l={type:"table",raw:
|
|
47
|
-
`),header:[],align:[],rows:[]};if(e.length===n.length){for(let
|
|
36
|
+
${M}`,s=`${s}
|
|
37
|
+
${M}`}if(n=n.slice(C),n.length>0&&!this.rules.other.blockquoteStart.test(n[0]))break;continue}}return{type:"blockquote",raw:i,tokens:l,text:s}}}list(t){let e=this.rules.block.list.exec(t);if(e){if(!this.options.pedantic&&this.lexer.state.lastToken?.type==="text"&&!this.rules.other.listInterruptsParagraph.test(t))return;let n=t,i=()=>n.length-t.length,s=e[1].trim(),l=s.length>1,a={type:"list",raw:"",ordered:l,start:l?+s.slice(0,-1):"",loose:!1,items:[]};s=l?`\\d{1,9}\\${s.slice(-1)}`:`\\${s}`,this.options.pedantic&&(s=l?s:"[*+-]");let r=this.rules.other.listItemRegex(s),o=!1;for(;t;){let p=!1,h="";if(!(e=r.exec(t))||this.rules.block.hr.test(t))break;let f=i();t=t.substring(e[0].length);let b=e[2].split(`
|
|
38
|
+
`,1)[0],w=e[1].length,y=this.options.pedantic?st(b,w):b.replace(this.rules.other.leadingSpaceTab,$=>st($,w)),C=t.split(`
|
|
39
|
+
`,1)[0],M=!y.trim(),T=0;if(this.options.pedantic?(T=2,h=y.trimStart()):M?T=w+1:(T=y.search(this.rules.other.nonSpaceChar),T=T>4?1:T,h=y.slice(T),y=h,T+=w),M&&this.rules.other.blankLine.test(C)&&(t=t.substring(C.length+1),p=!0),!p){let $=this.rules.other.nextBulletRegex(T),z=this.rules.other.hrRegex(T),x=this.rules.other.fencesBeginRegex(T),F=this.options.pedantic?this.rules.other.pedanticHeadingBeginRegex(T):this.rules.other.headingBeginRegex(T),B=this.rules.other.htmlBeginRegex(T),Z=this.rules.other.blockquoteBeginRegex(T),A=!1;for(;t;){let Se=t.split(`
|
|
40
|
+
`,1)[0],W;if(C=Se,this.options.pedantic?(C=C.replace(this.rules.other.listReplaceNesting," "),W=C):W=C.replace(this.rules.other.leadingSpaceTab,L=>st(L)),x.test(C)||F.test(C)||B.test(C)||Z.test(C)||$.test(C)||z.test(C))break;if(W.search(this.rules.other.nonSpaceChar)>=T||!C.trim())h+=`
|
|
41
|
+
`+W.slice(T),A=!1;else{if(M)break;let L=y;if(!this.options.pedantic&&!h.includes(`
|
|
42
|
+
`)&&!y.includes(" ")){let q;for(;!z.test(L)&&(q=this.rules.other.nestedBlockMarker.exec(L));)L=L.slice(q[0].length);if(!L.trim())break}if(L.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||x.test(L)||F.test(L)||B.test(L)||z.test(L))break;if(!this.options.pedantic&&!A){let q=y.replace(this.rules.other.nestedContainerMarkers,"");if(this.rules.block.fences.test(q)||this.rules.block.heading.test(q)||this.rules.block.hr.test(q))break}let U=!this.options.pedantic&&/^ {0,3}(?:=+|-+) *$/.test(C)&&this.rules.block.lheading.test(`${y}
|
|
43
|
+
${C}`)?` ${W.replace(/^ {0,3}/,"")}`:C,ve=!this.options.pedantic&&!A&&W.startsWith(" ")?this.rules.block.list.exec(y):null;if(ve?.[2]){let q=ve[1].length,Y=ve[2].replace(this.rules.other.leadingSpaceTab,Ne=>st(Ne,q)),$e=Y.search(this.rules.other.nonSpaceChar);$e>0&&$e<=4&&!this.rules.other.nestedBlockMarker.test(Y.slice($e))&&W.search(this.rules.other.nonSpaceChar)>=q+$e&&this.rules.other.listInterruptsParagraph.test(W.slice(q+$e))&&(U=` ${W}`)}h+=`
|
|
44
|
+
`+U,A=!0}M=!C.trim(),t=t.substring(Se.length+1),y=W.slice(T)}}let I=n.slice(f,i());a.loose||(o?a.loose=!0:this.rules.other.doubleBlankLine.test(I)&&(o=!0)),a.items.push({type:"list_item",raw:I,task:!!this.options.gfm&&this.rules.other.listIsTask.test(h),loose:!1,text:h,tokens:[]})}let c=a.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd();else return;a.raw=n.slice(0,i()).trimEnd();let d=[],m=this.lexer.state.top;for(let p of a.items)if(this.lexer.state.top=!1,d.push(this.lexer.inlineQueue.length),p.tokens=this.lexer.blockTokens(p.text,[]),!a.loose){let h=p.tokens.filter(b=>b.type==="space"),f=h.length>0&&h.some(b=>this.rules.other.anyLine.test(b.raw));a.loose=f}this.lexer.state.top=m;for(let p=0;p<a.items.length;p++){let h=a.items[p],f=h.tokens[0];if(h.task&&(f?.type==="text"||f?.type==="paragraph")){h.text=h.text.replace(this.rules.other.listReplaceTask,""),f.raw=f.raw.replace(this.rules.other.listReplaceTask,""),f.text=f.text.replace(this.rules.other.listReplaceTask,"");let b=this.lexer.inlineQueue;for(let y=d[p];y<b.length;y++)if(b[y].tokens===f.tokens){b[y].src=b[y].src.replace(this.rules.other.listReplaceTask,"");break}let w=this.rules.other.listTaskCheckbox.exec(h.raw);if(w){let y={type:"checkbox",raw:w[0]+" ",checked:w[0]!=="[ ]"};h.checked=y.checked,a.loose?h.tokens[0]&&["paragraph","text"].includes(h.tokens[0].type)&&"tokens"in h.tokens[0]&&h.tokens[0].tokens?(h.tokens[0].raw=y.raw+h.tokens[0].raw,h.tokens[0].text=y.raw+h.tokens[0].text,h.tokens[0].tokens.unshift(y)):h.tokens.unshift({type:"paragraph",raw:y.raw,text:y.raw,tokens:[y]}):h.tokens.unshift(y)}}else h.task&&(h.task=!1)}if(a.loose)for(let p of a.items){p.loose=!0;for(let h of p.tokens)h.type==="text"&&(h.type="paragraph")}return a}}html(t){let e=this.rules.block.html.exec(t);if(e){if(this.lexer.state.lastToken?.type==="paragraph"&&!this.rules.other.htmlBeginRegex(4).test(t))return;let n=mi(e[0]);return{type:"html",block:!0,raw:n,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:n}}}def(t){let e=this.rules.block.def.exec(t);if(e){if(!this.rules.other.startAngleBracket.test(e[2])&&fi(e[2],"()")!==-1)return;let n=Tt(e[1],this.options.pedantic),i=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:n,raw:ke(e[0],`
|
|
45
|
+
`),href:i,title:s}}}table(t){let e,n;if(this.options.gfm&&!this.options.pedantic){let a=this.rules.other.tableHeader.exec(t);if(!a||!this.rules.other.tableDelimiter.test(a[2])||(e=pn(a[1]),n=a[2].replace(this.rules.other.tableAlignChars,"").split("|"),e.length!==n.length))return}let i=this.rules.block.table.exec(t);if(!i||!this.rules.other.tableDelimiter.test(i[2]))return;e??=pn(i[1]),n??=i[2].replace(this.rules.other.tableAlignChars,"").split("|");let s=i[3]?.trim()?i[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
46
|
+
`):[],l={type:"table",raw:ke(i[0],`
|
|
47
|
+
`),header:[],align:[],rows:[]};if(e.length===n.length){for(let a of n)this.rules.other.tableAlignRight.test(a)?l.align.push("right"):this.rules.other.tableAlignCenter.test(a)?l.align.push("center"):this.rules.other.tableAlignLeft.test(a)?l.align.push("left"):l.align.push(null);for(let a=0;a<e.length;a++)l.header.push({text:e[a],tokens:this.lexer.inline(e[a]),header:!0,align:l.align[a]});for(let a of s)l.rows.push(pn(a,l.header.length).map((r,o)=>({text:r,tokens:this.lexer.inline(r),header:!1,align:l.align[o]})));return l}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e){let n=e[1].trim();return{type:"heading",raw:ke(e[0],`
|
|
48
48
|
`),depth:e[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(t){let e=this.rules.block.paragraph.exec(t);if(e){let n=e[1].charAt(e[1].length-1)===`
|
|
49
|
-
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){let e=this.rules.block.text.exec(t);if(e){let n=e[0],i=e[0],s=this.rules.other.textIndentedContinuation.exec(t.slice(n.length));return s&&(n+=s[0],i+=s[0].replace(this.rules.other.codeRemoveIndent,"")),{type:"text",raw:n,text:i,tokens:this.lexer.inline(i)}}}escape(t){if(t.charCodeAt(0)!==92)return;let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){if(t.charCodeAt(0)!==60)return;let e=this.rules.inline.tag.exec(t);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(t){if(this.lexer.state.linkParenPossible===!1)return;let e=t.charCodeAt(0);if(e!==91&&e!==33)return;let n=this.rules.inline.link.exec(t);if(n){let i=n[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&wi(t,n[1],i,this.rules))return;let s=n[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(s)){if(!this.rules.other.endAngleBracket.test(s))return;let o=
|
|
50
|
-
`)),i.inlineTokens(e)}lex(e){e=e.replace(
|
|
51
|
-
`),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let i=this.inlineQueue[n];this.state.inRawBlock=!1,this.inlineTokens(i.src,i.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],i=!1){this.tokenizer.lexer=this;let s=this.state.lastToken;this.options.pedantic&&(e=e.replace(
|
|
49
|
+
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){let e=this.rules.block.text.exec(t);if(e){let n=e[0],i=e[0],s=this.rules.other.textIndentedContinuation.exec(t.slice(n.length));return s&&(n+=s[0],i+=s[0].replace(this.rules.other.codeRemoveIndent,"")),{type:"text",raw:n,text:i,tokens:this.lexer.inline(i)}}}escape(t){if(t.charCodeAt(0)!==92)return;let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){if(t.charCodeAt(0)!==60)return;let e=this.rules.inline.tag.exec(t);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(t){if(this.lexer.state.linkParenPossible===!1)return;let e=t.charCodeAt(0);if(e!==91&&e!==33)return;let n=this.rules.inline.link.exec(t);if(n){let i=n[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&wi(t,n[1],i,this.rules))return;let s=n[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(s)){if(!this.rules.other.endAngleBracket.test(s))return;let o=ke(s.slice(0,-1),"\\");if((s.length-o.length)%2===0)return}else{let o=fi(n[2],"()");if(o===-2)return;if(o>-1){let c=(n[0].indexOf("!")===0?5:4)+n[1].length+o;n[2]=n[2].substring(0,o),n[0]=n[0].substring(0,c).trim(),n[3]=""}}let l=ke(n[0].slice(0,-1),"\\");if((n[0].length-l.length)%2===0)return;let a=n[2],r="";if(this.options.pedantic){let o=this.rules.other.pedanticHrefTitle.exec(a);o&&(a=o[1],r=o[3])}else r=n[3]?n[3].slice(1,-1):"";return this.options.pedantic&&(a=a.trim()),this.rules.other.startAngleBracket.test(a)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(s)?a=a.slice(1):a=a.slice(1,-1)),ki(n,{href:a&&a.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},n[0],this.lexer,this.rules)}}reflink(t,e){let n=t.charCodeAt(0);if(n!==91&&n!==33)return;let i;if((i=this.rules.inline.reflink.exec(t))||(i=this.rules.inline.nolink.exec(t))){let s=i[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&wi(t,i[1],s,this.rules))return;let l=e[Tt(i[2]||i[1],this.options.pedantic)];if(!l){let a=i[0].charAt(0);return{type:"text",raw:a,text:a}}return ki(i,l,i[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let i=this.rules.inline.emStrongLDelim.exec(t);if(!i||!i[1]&&!i[2]&&!i[3]&&!i[4])return;let s=i[0][0],l=n===s,a=e.length-t.length,r=a;for(;!this.options.pedantic&&r>0&&e[r-1]===s;)r--;let o=[...e.slice(Math.max(0,r-2),r)].at(-1)??"",c=o==="*"||o==="_"||!!this.rules.inline.punctuation.exec(o);r<a&&(n=o);let d=r<a?c:n==="*"||n==="_"||!!this.rules.inline.punctuation.exec(n);if(i[4]&&n.match(this.rules.other.unicodeAlphaNumeric))return;let m=i[1]||i[3]||"";if(!m||!n||d){let p=[...i[0]].length-1,h,f,b=p,w=0,y=a-r+p,C=!this.options.pedantic&&!!o.trim()&&(!!m||s==="*"&&!c);if(s!=="*"&&s!=="_")return;let M=s==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd,T=gi(this,e,s),I=e.length-t.length+p;if(T<I)return;e=e.slice(-1*t.length+p);let $=T-I;for(M.lastIndex=0;(i=M.exec(e))!==null&&!(i.index>$);){if(h=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!h)continue;f=[...h].length;let z=f>b-p;if(i[3]||i[4]){b+=f;continue}else if((i[5]||i[6]||C&&z)&&y%3&&!((y+f)%3)){if(l&&(i[5]||i[6]))break;w+=f;continue}if(b-=f,b>0)continue;f=Math.min(f,f+b+w);let x=[...i[0]][0].length,F=t.slice(0,p+i.index+x+f);if(Math.min(p,f)%2){let Z=F.slice(1,-1);return{type:"em",raw:F,text:Z,tokens:this.lexer.inlineTokens(Z)}}let B=F.slice(2,-2);return{type:"strong",raw:F,text:B,tokens:this.lexer.inlineTokens(B)}}}}codespan(t){if(t.charCodeAt(0)!==96)return;let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),i=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return i&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){let e=t.charCodeAt(0);if(e!==32&&e!==92&&e!==10)return;let n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t,e,n=""){if(t.charCodeAt(0)!==126)return;let i=this.rules.inline.delLDelim.exec(t);if(i&&(!i[1]||!n||this.rules.inline.punctuation.exec(n))){let s=[...i[0]].length-1,l,a,r=s,o=this.rules.inline.delRDelim,c=vi(this,e),d=e.length-t.length+s;if(c<d)return;e=e.slice(-1*t.length+s);let m=c-d;for(o.lastIndex=0;(i=o.exec(e))!==null&&!(i.index>m);){if(l=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!l||(a=[...l].length,a!==s))continue;if(i[3]||i[4]){r+=a;continue}if(r-=a,r>0)continue;a=Math.min(a,a+r);let p=[...i[0]][0].length,h=t.slice(0,s+i.index+p+a),f=h.slice(s,-s);return{type:"del",raw:h,text:f,tokens:this.lexer.inlineTokens(f)}}}}autolink(t){if(t.charCodeAt(0)!==60)return;let e=this.rules.inline.autolink.exec(t);if(e){let n,i;return e[2]==="@"?(n=e[1],i="mailto:"+n):(n=e[1],i=n),{type:"link",raw:e[0],text:n,href:i,autolink:!0,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,i;if(e[2]==="@")n=e[0],i="mailto:"+n;else{let s;do s=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(s!==e[0]);n=e[0],e[1]==="www."?i="http://"+e[0]:i=e[0]}return{type:"link",raw:e[0],text:n,href:i,autolink:!0,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){let e=this.rules.inline.text.exec(t);if(e){let n=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:n?e[0]:Na(e[0]),escaped:n}}}},le=class _n{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Ae,this.options.tokenizer=this.options.tokenizer||new Be,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,linkEmitted:!1,linkParenPossible:!0,top:!0,inBlockquote:!1};let n={other:_,block:Lt.normal,inline:it.normal};this.options.pedantic?(n.block=Lt.pedantic,n.inline=it.pedantic):this.options.gfm&&(n.block=Lt.gfm,this.options.breaks?n.inline=it.breaks:n.inline=it.gfm),this.tokenizer.rules=n}static get rules(){return{block:Lt,inline:it}}static lex(e,n){return new _n(n).lex(e)}static lexInline(e,n){let i=new _n(n);return e.includes("\r")&&(e=e.replace(_.carriageReturn,`
|
|
50
|
+
`)),i.inlineTokens(e)}lex(e){e=e.replace(_.carriageReturn,`
|
|
51
|
+
`),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let i=this.inlineQueue[n];this.state.inRawBlock=!1,this.inlineTokens(i.src,i.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],i=!1){this.tokenizer.lexer=this;let s=this.state.lastToken;this.options.pedantic&&(e=e.replace(_.tabCharGlobal," ").replace(_.spaceLine,""));let l=1/0,a,r=this.options.gfm&&!this.options.pedantic&&this.tokenizer.paragraph===Be.prototype.paragraph;for(;e;){if(e.length<l)l=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}this.state.lastToken=n.at(-1);let o;if(this.options.extensions?.block?.some(d=>(o=d.call({lexer:this},e,n))?(e=e.substring(o.raw.length),n.push(o),!0):!1))continue;if(o=this.tokenizer.space(e)){e=e.substring(o.raw.length);let d=n.at(-1);o.raw.length===1&&d!==void 0?d.raw+=`
|
|
52
52
|
`:n.push(o);continue}if(o=this.tokenizer.code(e)){e=e.substring(o.raw.length);let d=n.at(-1);d?.type==="paragraph"||d?.type==="text"?(d.raw+=(d.raw.endsWith(`
|
|
53
53
|
`)?"":`
|
|
54
54
|
`)+o.raw,d.text+=`
|
|
55
55
|
`+o.text,this.inlineQueue.at(-1).src=d.text):n.push(o);continue}if(o=this.tokenizer.fences(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.heading(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.hr(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.blockquote(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.list(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.html(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.def(e)){e=e.substring(o.raw.length);let d=n.at(-1);d?.type==="paragraph"||d?.type==="text"?(d.raw+=(d.raw.endsWith(`
|
|
56
56
|
`)?"":`
|
|
57
57
|
`)+o.raw,d.text+=`
|
|
58
|
-
`+o.raw,this.inlineQueue.at(-1).src=d.text):(this.tokens.links[o.tag]||(this.tokens.links[o.tag]={href:o.href,title:o.title}),n.push(o));continue}if(o=this.tokenizer.table(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.lheading(e)){e=e.substring(o.raw.length),n.push(o);continue}let c=e;if(this.options.extensions?.startBlock){let d=1/0,m=e.slice(1),
|
|
58
|
+
`+o.raw,this.inlineQueue.at(-1).src=d.text):(this.tokens.links[o.tag]||(this.tokens.links[o.tag]={href:o.href,title:o.title}),n.push(o));continue}if(o=this.tokenizer.table(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.lheading(e)){e=e.substring(o.raw.length),n.push(o);continue}let c=e;if(this.options.extensions?.startBlock){let d=1/0,m=e.slice(1),p;this.options.extensions.startBlock.forEach(h=>{p=h.call({lexer:this},m),typeof p=="number"&&p>=0&&(d=Math.min(d,p))}),d<1/0&&d>=0&&(c=e.substring(0,d+1))}if(this.state.top&&(o=this.tokenizer.paragraph(c))){let d=n.at(-1);(i||d===a&&r)&&d?.type==="paragraph"?(d.raw+=(d.raw.endsWith(`
|
|
59
59
|
`)?"":`
|
|
60
60
|
`)+o.raw,d.text+=`
|
|
61
|
-
`+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text,
|
|
61
|
+
`+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text,a=d):(n.push(o),a=o),i=c.length!==e.length,e=e.substring(o.raw.length);continue}if(o=this.tokenizer.text(e)){e=e.substring(o.raw.length);let d=n.at(-1);d?.type==="text"?(d.raw+=(d.raw.endsWith(`
|
|
62
62
|
`)?"":`
|
|
63
63
|
`)+o.raw,d.text+=`
|
|
64
|
-
`+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text):n.push(o);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,this.state.lastToken=s,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}linkInText(e){if(!e.includes("["))return!1;let n=this.tokenizer.rules.inline.link;for(let i of e.matchAll(this.tokenizer.rules.inline.blockSkip))if(n.test(i[0])&&e.charAt(i.index-1)!=="!")return!0;for(let i of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)){let s=i[0],l=s.lastIndexOf("[");if(!(s.charAt(0)==="!"||!Object.hasOwn(this.tokens.links,Tt(s.slice(l+1,-1),this.options.pedantic)))&&!(l>1&&this.linkInText(s.slice(1,l-1))))return!0}return!1}inlineTokens(e,n=[]){this.tokenizer.lexer=this;let i=this.state.linkParenPossible;this.state.linkParenPossible=e.includes(")");try{return this.#t(e,n)}finally{this.state.linkParenPossible=i}}#t(e,n){let i=e.includes("*")||e.includes("_")||e.includes("~"),s=i||this.options.hooks?.emStrongMask||this.tokenizer.emStrong!==
|
|
65
|
-
`:"";return i?'<pre><code class="language-'+
|
|
66
|
-
`:"<pre><code>"+(n?s:
|
|
64
|
+
`+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text):n.push(o);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,this.state.lastToken=s,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}linkInText(e){if(!e.includes("["))return!1;let n=this.tokenizer.rules.inline.link;for(let i of e.matchAll(this.tokenizer.rules.inline.blockSkip))if(n.test(i[0])&&e.charAt(i.index-1)!=="!")return!0;for(let i of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)){let s=i[0],l=s.lastIndexOf("[");if(!(s.charAt(0)==="!"||!Object.hasOwn(this.tokens.links,Tt(s.slice(l+1,-1),this.options.pedantic)))&&!(l>1&&this.linkInText(s.slice(1,l-1))))return!0}return!1}inlineTokens(e,n=[]){this.tokenizer.lexer=this;let i=this.state.linkParenPossible;this.state.linkParenPossible=e.includes(")");try{return this.#t(e,n)}finally{this.state.linkParenPossible=i}}#t(e,n){let i=e.includes("*")||e.includes("_")||e.includes("~"),s=i||this.options.hooks?.emStrongMask||this.tokenizer.emStrong!==Be.prototype.emStrong||this.tokenizer.del!==Be.prototype.del?this.#i(e):e;if(!i)return this.#e(e,s,n);Oa(this.tokenizer,s);try{return this.#e(e,s,n)}finally{qa(this.tokenizer)}}#e(e,n,i){let s=!1,l="",a=1/0;for(;e;){if(e.length<a)a=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}s||(l=""),s=!1;let r;if(this.options.extensions?.inline?.some(d=>(r=d.call({lexer:this},e,i))?(e=e.substring(r.raw.length),i.push(r),!0):!1))continue;if(r=this.tokenizer.escape(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.tag(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.link(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let d=i.at(-1);r.type==="text"&&d?.type==="text"?(d.raw+=r.raw,d.text+=r.text):i.push(r);continue}let o=e[0];if(o==="*"||o==="_"){let d=n.length-e.length;if(gi(this.tokenizer,n,o)<=d){let m=1;for(;m<e.length&&e.charCodeAt(m)===o.charCodeAt(0);)m++;let p=e.substring(0,m),h=i.at(-1);h?.type==="text"&&!h.escaped?(h.raw+=p,h.text+=p):i.push({type:"text",raw:p,text:p,escaped:!1}),e=e.substring(m),l=o,s=!0;continue}}else if(o==="~"){let d=n.length-e.length;if(vi(this.tokenizer,n)<=d){let m=1;for(;m<e.length&&e.charCodeAt(m)===126;)m++;let p=e.substring(0,m),h=i.at(-1);h?.type==="text"&&!h.escaped?(h.raw+=p,h.text+=p):i.push({type:"text",raw:p,text:p,escaped:!1}),e=e.substring(m),l=o,s=!0;continue}}if(r=this.tokenizer.emStrong(e,n,l)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.codespan(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.br(e)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.del(e,n,l)){e=e.substring(r.raw.length),i.push(r);continue}if(r=this.tokenizer.autolink(e)){e=e.substring(r.raw.length),i.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),i.push(r);continue}let c=e;if(this.options.extensions?.startInline){let d=1/0,m=e.slice(1),p;this.options.extensions.startInline.forEach(h=>{p=h.call({lexer:this},m),typeof p=="number"&&p>=0&&(d=Math.min(d,p))}),d<1/0&&d>=0&&(c=e.substring(0,d+1))}if(r=this.tokenizer.inlineText(c)){e=e.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(l=r.raw.slice(-1)),s=!0;let d=i.at(-1);d?.type==="text"?(d.raw+=r.raw,d.text+=r.text):i.push(r);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return i}#n(e){let{blockSkip:n,tag:i,autolink:s}=this.tokenizer.rules.inline,l="",a=0,r;for(n.lastIndex=0;r=n.exec(e);){let o=r.index+(r[2]?r[2].length:0),c=r.index+r[0].length;if(e.charAt(o)==="<"){let d=e.slice(o),m=i.exec(d)||s.exec(d);if(!m){n.lastIndex=o+1;continue}c=o+m[0].length,n.lastIndex=c}l+=e.slice(a,o)+"["+"a".repeat(c-o-2)+"]",a=c}return l+e.slice(a)}#i(e){let n=e;if(this.tokens.links&&e.includes("[")){let i=this.tokenizer.rules.inline.reflinkSearch,s=l=>{let a=l.lastIndexOf("[");if(!Object.hasOwn(this.tokens.links,Tt(l.slice(a+1,-1),this.options.pedantic)))return l;if(a>1&&l.charAt(0)!=="!"){let r=l.slice(1,a-1);if(this.linkInText(r))return"["+r.replace(i,s)+"]["+"a".repeat(l.length-a-2)+"]"}return"["+"a".repeat(l.length-2)+"]"};n=n.replace(i,s)}return n=n.replace(this.tokenizer.rules.inline.anyPunctuationOutsideCode,(i,s,l)=>l?"+".repeat(i.length):s?s+i.slice(s.length,-s.length).replace(/`/g,"+")+s:i),n=this.#n(n),n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n,n}infiniteLoopError(e){let n="Infinite loop on byte: "+e;if(this.options.silent)console.error(n);else throw new Error(n)}};function hn(t,e=!1){let n;for(let i=0;i<t.length;i++){let s=t[i],l=s;if(s.type==="codespan"||s.type==="escape"||e&&s.type==="text"){let a=G(s.text,!0);a!==s.text&&(l={...s,text:a})}else if(s.type==="link"&&s.autolink){let a=G(s.text,!0),r=s.tokens,o=r&&(r.length===1&&r[0].type==="text"&&r[0].text===s.text?a!==s.text?[{...r[0],text:a}]:r:hn(r,!0));(a!==s.text||o!==r)&&(l=o!==r?{...s,text:a,tokens:o}:{...s,text:a})}else if("tokens"in s&&s.tokens){let a=hn(s.tokens,e);a!==s.tokens&&(l={...s,tokens:a})}l!==s?(n||(n=t.slice(0,i)),n.push(l)):n&&n.push(s)}return n||t}var $t=class{options;parser;constructor(t){this.options=t||Ae}space(t){return""}code({text:t,lang:e,escaped:n}){let i=(e||"").trim().match(_.notSpaceStart)?.[0],s=t?t.replace(_.endingNewline,"")+`
|
|
65
|
+
`:"";return i?'<pre><code class="language-'+G(i)+'">'+(n?s:G(s,!0))+`</code></pre>
|
|
66
|
+
`:"<pre><code>"+(n?s:G(s,!0))+`</code></pre>
|
|
67
67
|
`}blockquote({tokens:t}){return`<blockquote>
|
|
68
68
|
${this.parser.parse(t)}</blockquote>
|
|
69
69
|
`}html({text:t}){return t}def(t){return""}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
|
|
70
70
|
`}hr(t){return`<hr>
|
|
71
|
-
`}list(t){let e=t.ordered,n=t.start,i="";for(let
|
|
71
|
+
`}list(t){let e=t.ordered,n=t.start,i="";for(let a=0;a<t.items.length;a++){let r=t.items[a];i+=this.listitem(r)}let s=e?"ol":"ul",l=e&&n!==1?' start="'+n+'"':"";return"<"+s+l+`>
|
|
72
72
|
`+i+"</"+s+`>
|
|
73
73
|
`}listitem(t){return`<li>${this.parser.parse(t.tokens)}</li>
|
|
74
74
|
`}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
|
|
75
|
-
`}table(t){let e="",n="";for(let s=0;s<t.header.length;s++)n+=this.tablecell(t.header[s]);e+=this.tablerow({text:n});let i="";for(let s=0;s<t.rows.length;s++){let l=t.rows[s];n="";for(let
|
|
75
|
+
`}table(t){let e="",n="";for(let s=0;s<t.header.length;s++)n+=this.tablecell(t.header[s]);e+=this.tablerow({text:n});let i="";for(let s=0;s<t.rows.length;s++){let l=t.rows[s];n="";for(let a=0;a<l.length;a++)n+=this.tablecell(l[a]);i+=this.tablerow({text:n})}return i&&(i=`<tbody>${i}</tbody>`),`<table>
|
|
76
76
|
<thead>
|
|
77
77
|
`+e+`</thead>
|
|
78
78
|
`+i+`</table>
|
|
79
79
|
`}tablerow({text:t}){return`<tr>
|
|
80
80
|
${t}</tr>
|
|
81
81
|
`}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
|
|
82
|
-
`}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${
|
|
83
|
-
`}checkbox({raw:t}){return t}},re=class Fn{options;renderer;textRenderer;constructor(e){this.options=e||
|
|
84
|
-
Please report this to https://github.com/markedjs/marked.`,t){let s="<p>An error occurred:</p><pre>"+
|
|
85
|
-
`).forEach((h,f)=>{f>0&&m.appendChild(t.createElement("br")),h&&m.appendChild(t.createTextNode(h))})}function l(m,u){switch(u.type){case"text":{if(u.tokens?.length){for(let h of u.tokens)l(m,h);return}s(m,u.text??u.raw??"");return}case"escape":m.appendChild(t.createTextNode(u.text??""));return;case"strong":case"em":case"del":{let h=t.createElement(u.type==="strong"?"strong":u.type==="em"?"em":"del");for(let f of u.tokens??[])l(h,f);m.appendChild(h);return}case"codespan":{let h=t.createElement("code");h.textContent=u.text??"",m.appendChild(h);return}case"br":m.appendChild(t.createElement("br"));return;case"link":{let h=u.tokens??[],f=yi(u.href);if(!f){for(let x of h)l(m,x);return}let b=t.createElement("a");b.href=f,b.rel="noreferrer noopener",u.title&&(b.title=u.title),xi(f)&&(b.target="_blank");for(let x of h)l(b,x);m.appendChild(b);return}case"image":{let h=yi(u.href),f=u.text?.trim()||u.href||"image";if(!h){m.appendChild(t.createTextNode(f));return}let b=t.createElement("a");b.href=h,b.textContent=f,b.rel="noreferrer noopener",xi(h)&&(b.target="_blank"),m.appendChild(b);return}case"html":m.appendChild(t.createTextNode(u.raw??u.text??""));return;default:if(u.tokens?.length){for(let h of u.tokens)l(m,h);return}s(m,u.text??u.raw??"")}}function r(m){let u=t.createElement("div");u.className="bv-code";let h=t.createElement("div");h.className="bv-code-head";let f=(m.lang??"").trim().split(/\s+/)[0]??"",b=t.createElement("span");b.className="bv-code-lang",b.textContent=f||"text";let x=t.createElement("button");x.type="button",x.className="bv-code-copy",x.textContent="Copy";let k=m.text??"";x.addEventListener("click",()=>{let T=navigator.clipboard?.writeText(k);T&&T.then(()=>{x.textContent="Copied",window.setTimeout(()=>{x.textContent="Copy"},1200)},()=>{})}),h.append(b,x);let y=t.createElement("pre"),z=t.createElement("code");return f&&(z.className=`language-${f}`),z.textContent=k,y.appendChild(z),u.append(h,y),u}function a(m,u){let h=t.createElement("div");h.className="bv-table";let f=t.createElement("table"),b=t.createElement("thead"),x=t.createElement("tr"),k=u.align??[],y=(T,I,M)=>{let $=t.createElement(T);k[M]&&($.style.textAlign=k[M]);for(let E of I.tokens??[])l($,E);return $};(u.header??[]).forEach((T,I)=>x.appendChild(y("th",T,I))),b.appendChild(x);let z=t.createElement("tbody");for(let T of u.rows??[]){let I=t.createElement("tr");T.forEach((M,$)=>I.appendChild(y("td",M,$))),z.appendChild(I)}f.append(b,z),h.appendChild(f),m.appendChild(h)}function o(m,u){let h=t.createElement("li");if(u.task){let f=t.createElement("input");f.type="checkbox",f.disabled=!0,f.checked=u.checked===!0,h.appendChild(f)}for(let f of u.tokens??[])if(f.type==="text")l(h,f);else if(f.type==="paragraph")for(let b of f.tokens??[])l(h,b);else c(h,f);m.appendChild(h)}function c(m,u){switch(u.type){case"space":return;case"heading":{let h=Math.min(Math.max(u.depth??1,1),6),f=t.createElement(`h${h}`);for(let b of u.tokens??[])l(f,b);m.appendChild(f);return}case"paragraph":{let h=t.createElement("p");for(let f of u.tokens??[])l(h,f);m.appendChild(h);return}case"text":l(m,u);return;case"code":m.appendChild(r(u));return;case"blockquote":{let h=t.createElement("blockquote");for(let f of u.tokens??[])c(h,f);m.appendChild(h);return}case"list":{let h=u.items??u.tokens??[];if(u.ordered){let f=t.createElement("ol");typeof u.start=="number"&&u.start!==1&&(f.start=u.start);for(let b of h)o(f,b);m.appendChild(f)}else{let f=t.createElement("ul");for(let b of h)o(f,b);m.appendChild(f)}return}case"table":a(m,u);return;case"hr":m.appendChild(t.createElement("hr"));return;case"html":case"escape":m.appendChild(t.createTextNode(u.raw??u.text??""));return;default:if(u.tokens?.length){for(let h of u.tokens)c(m,h);return}u.text&&m.appendChild(t.createTextNode(u.text))}}function d(m){let u=t.createDocumentFragment();try{let h=R.lexer(m);for(let f of h)c(u,f)}catch{u.replaceChildren(t.createTextNode(m))}return u}return m=>{let u=e.get(m);if(u)return e.delete(m),e.set(m,u),u.fragment.cloneNode(!0);let h=d(m);return i(m,h),h.cloneNode(!0)}}var fn=Kr(document),w={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1},Se=[],me=!0,Qr=!1,Si=0;function gn(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function q(t,e){let n=await fetch(t,{...e,headers:{"content-type":"application/json",Authorization:`Bearer ${gn()}`,...e?.headers||{}}}),i=await n.text(),s=i?JSON.parse(i):null;if(!n.ok)throw new Error(s&&s.error||`HTTP ${n.status}`);return s}function g(t,e,n){let i=document.createElement(t);return e&&(i.className=e),n!==void 0&&(i.textContent=n),i}function Gr(t){return t==="running"?"var(--panel-success)":t==="waiting_approval"||t==="waiting_input"?"#e0a23c":t==="failed"?"var(--panel-danger, #e5534b)":t==="completed"?"var(--panel-accent)":"var(--panel-muted)"}function Ce(){vn||(vn=requestAnimationFrame(()=>{vn=0,el()}))}var vn=0,$t="";function el(){let t=document.getElementById("bots-view");if(!t)return;let e=window.visualViewport,n=window.matchMedia("(max-width: 640px)").matches,i=!document.querySelector(".sidebar")?.classList.contains("collapsed");if(w.activeId&&e&&n&&!i){let s=document.querySelector(".fixed-header"),l=s?Math.round(s.getBoundingClientRect().height):0,r=Math.round(e.offsetTop)+l,a=Math.round(e.offsetLeft),o=Math.round(e.width),c=Math.max(120,Math.round(e.height)-l),d=`fixed|${r}|${a}|${o}|${c}`;if(d===$t)return;$t=d,t.style.position="fixed",t.style.top=`${r}px`,t.style.left=`${a}px`,t.style.width=`${o}px`,t.style.height=`${c}px`,t.style.right="auto",t.style.bottom="auto"}else{if($t==="")return;$t="",t.style.position="",t.style.top="",t.style.left="",t.style.width="",t.style.height="",t.style.right="",t.style.bottom=""}}window.visualViewport?.addEventListener("resize",Ce),window.visualViewport?.addEventListener("scroll",Ce),window.addEventListener("resize",Ce),document.addEventListener("click",Ce);var Ci=document.querySelector(".sidebar");Ci&&new MutationObserver(Ce).observe(Ci,{attributes:!0,attributeFilter:["class"]}),window.__syncBotsViewport=Ce;function zt(){let t=w.approvals.length,e=document.getElementById("bots-inbox-badge");e&&(e.style.display=t?"inline-block":"none",e.textContent=String(t));let n=document.getElementById("bv-inbox-count");n&&(n.textContent=t?`(${t})`:""),window.__botsSnapshot=w.bots,window.__refreshSidebar?.()}function tl(){let t=document.getElementById("set-bot-templates"),e=document.getElementById("set-bot-new"),n=document.getElementById("set-bot-inbox"),i=()=>{document.getElementById("settings-popover")?.classList.remove("open"),document.getElementById("settings-backdrop")?.classList.remove("open")};t?.addEventListener("click",()=>{i(),rt()}),e?.addEventListener("click",()=>{i(),ml()}),n?.addEventListener("click",()=>{i(),Tn()})}function nl(){let t=g("div","bots-view");t.id="bots-view",t.hidden=!0;let e=g("div","bots-view-head"),n=g("div","bv-title"),i=g("span","bots-dot");i.id="bv-dot";let s=g("span","bv-title-text");s.id="bv-title";let l=g("span","bv-status");l.id="bv-status",n.append(i,s,l);let r=g("div","bv-actions"),a=g("div","bv-mode"),o=g("button","bv-mode-btn");o.id="bv-mode-btn",o.type="button",o.setAttribute("aria-haspopup","menu"),o.setAttribute("aria-expanded","false"),Ai(o,"supervised");let c=g("div","bv-mode-menu");c.id="bv-mode-menu",c.setAttribute("role","menu"),c.hidden=!0;for(let[C,F,_]of[["supervised","\u9ED8\u8BA4","\u53EA\u8BFB\u5DE5\u5177\uFF08read/grep/find/ls\uFF09\u76F4\u63A5\u653E\u884C\uFF1Bbash\u3001edit\u3001write\u3001\u6269\u5C55/MCP \u5DE5\u5177\u4F1A\u95EE\u4F60"],["parent-supervised","\u76D1\u7BA1","\u5176\u4F59\u5DE5\u5177\u4EA4\u7ED9\u4E0A\u7EA7 bot \u51B3\u5B9A\uFF08\u5E26\u7406\u7531\uFF09\uFF1B\u4F60\u4ECD\u7136\u80FD\u770B\u5230\u5E76\u56DE\u7B54\uFF0C\u5148\u7B54\u5148\u5F97\uFF1B\u6CA1\u6709\u4E0A\u7EA7\u65F6\u56DE\u843D\u5230\u9ED8\u8BA4"],["full-access","\u5168\u653E\u884C","\u6240\u6709\u5DE5\u5177\u76F4\u63A5\u6267\u884C\uFF0C\u4E0D\u518D\u8BE2\u95EE\u3002\u6CE8\u610F\u8FD9\u4E0D\u662F\u6C99\u7BB1"]]){let ie=g("button");ie.dataset.mode=C,ie.setAttribute("role","menuitemradio"),ie.innerHTML=`<span class="bv-mode-row-icon">${ve(Mi[C],'width="14" height="14"')}</span><span class="bv-mode-row-text"><b>${F}</b><span>${_}</span></span><span class="bv-mode-row-check">${ve("check",'width="13" height="13"')}</span>`,ie.onclick=()=>{d(!1),il(C)},c.appendChild(ie)}let d=C=>{c.hidden=!C,o.setAttribute("aria-expanded",C?"true":"false")};o.onclick=C=>{C.stopPropagation(),d(c.hidden)},a.append(o),document.addEventListener("click",C=>{let F=C.target;F&&!a.contains(F)&&!c.contains(F)&&d(!1)});let m=g("button","btn","Allow all");m.id="bv-allow-all",m.title="Approve every pending request for this bot",m.onclick=()=>{if(!w.activeId)return;let C=w.approvals.filter(F=>F.botId===w.activeId);Promise.all(C.map(F=>q(`/api/bots/${F.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:F.id,allow:!0})}))).finally(()=>void le(!0))};let u=g("button","btn","Needs you "),h=g("span");h.id="bv-inbox-count",u.appendChild(h),u.onclick=()=>void Tn();let f=g("button","btn","Resume");f.onclick=()=>void Ii(C=>q(`/api/bots/${C}/resume`,{method:"POST"}).then(()=>le(!0)));let b=g("button","btn danger","Stop");b.onclick=()=>void Ii(C=>q(`/api/bots/${C}/stop`,{method:"POST"}).then(()=>le(!0)));let x=g("button","btn","Delete");x.onclick=()=>{w.activeId&&confirm("Delete this bot and its session?")&&q(`/api/bots/${w.activeId}`,{method:"DELETE"}).then(()=>{kn(),le(!0)})},r.append(a,m,u,f,b,x),e.append(n,r);let k=g("div","bots-messages");k.id="bots-messages";let y=g("button","bv-jump");y.type="button",y.id="bv-jump",y.innerHTML=`${ve("chevron-down",'width="14" height="14"')}<span>Latest</span>`,y.title="Jump to the latest message",y.hidden=!0,y.onclick=()=>{me=!0,k.scrollTop=k.scrollHeight,y.hidden=!0};let z=()=>{me=k.scrollHeight-k.scrollTop-k.clientHeight<48,y.hidden=me};k.addEventListener("scroll",z,{passive:!0}),k.addEventListener("touchmove",()=>{me=!1,y.hidden=k.scrollHeight-k.clientHeight<1},{passive:!0}),k.addEventListener("wheel",()=>{me=!1},{passive:!0});let T=g("div","bots-composer-wrap"),I=g("div","bv-composer-error");I.id="bv-composer-error",I.hidden=!0;let M=g("div","bots-composer"),$=g("textarea");$.id="bots-input",$.rows=1,$.placeholder="Message the bot\u2026",$.spellcheck=!1;let E=window.matchMedia("(pointer: coarse)").matches;E||($.enterKeyHint="send"),$.onkeydown=C=>{C.key!=="Enter"||C.shiftKey||C.isComposing||E||C.keyCode===229||(C.preventDefault(),Ti())},$.oninput=()=>bn(null);let B=g("button","btn primary");B.id="bv-send",B.title="Send",B.setAttribute("aria-label","Send"),B.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>',B.onclick=()=>void Ti(),M.append($,B),M.addEventListener("click",C=>{C.target?.closest("button")||document.activeElement!==$&&$.focus()}),T.append(I,M),t.append(e,k,y,T,c),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||ul()}function bn(t){let e=document.getElementById("bv-composer-error");e&&(e.textContent=t??"",e.hidden=!t)}function Li(t){let e=document.getElementById("bv-send");e&&(e.disabled=t,e.setAttribute("aria-busy",t?"true":"false"),e.title=t?"Sending\u2026":"Send")}async function Ti(){let t=document.getElementById("bots-input");if(!t||!w.activeId||Qr||!t.value.trim())return;let e=w.activeId,n=t.value;bn(null),Li(!0);try{await q(`/api/bots/${e}/input`,{method:"POST",body:JSON.stringify({text:n})}),t.value===n&&(t.value=""),me=!0}catch(i){bn(i instanceof Error?i.message:String(i))}finally{Li(!1)}}function Ii(t){w.activeId&&t(w.activeId).catch(e=>qe({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function kn(){w.activeId=null,Se=[],me=!0,Ce();let t=document.getElementById("bots-view");t&&(t.hidden=!0);try{w.ws?.close()}catch{}w.ws=null,zt();let e=document.getElementById("terminal-container"),n=document.getElementById("main-placeholder"),i=!!document.querySelector(".session-item.active:not(.bot-item)");e&&i?(e.style.display="",n&&(n.style.display="none")):n&&(n.style.display="")}async function $i(t){w.activeId=t,Se=[],me=!0;let e=document.getElementById("bv-jump");e&&(e.hidden=!0),window.__collapseSidebar?.(),Ce(),w.items.set(t,[]);let n=document.getElementById("bots-view");n&&(n.hidden=!1);let i=document.getElementById("main-placeholder");i&&(i.style.display="none");let s=document.getElementById("terminal-container");s&&(s.style.display="none");let l=document.getElementById("file-editor");l&&(l.style.display="none"),zt(),Sn();try{w.ws?.close()}catch{}let r=location.protocol==="https:"?"wss:":"ws:",a=new WebSocket(`${r}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(gn())}`);w.ws=a,a.onmessage=o=>{try{Bi(JSON.parse(String(o.data)))}catch{}},a.onclose=()=>{w.activeId===t&&setTimeout(()=>{w.activeId===t&&le(!0)},1500)},await le(!0)}function wn(){return w.bots.find(t=>t.id===w.activeId)||null}function yn(){let t=wn();if(!t)return;let e=document.getElementById("bv-title"),n=document.getElementById("bv-status"),i=document.getElementById("bv-dot");e&&(e.textContent=t.title),n&&(n.textContent=`${t.status.replace(/_/g," ")} \xB7 ${t.templateId} \xB7 ${t.projectPath}`);let s=document.getElementById("bv-mode-btn");s&&Ai(s,t.runtimeMode||"supervised");for(let a of document.querySelectorAll("#bv-mode-menu button")){let o=a.dataset.mode===t.runtimeMode;a.classList.toggle("active",o),a.setAttribute("aria-checked",o?"true":"false")}let l=document.getElementById("bv-allow-all"),r=w.approvals.filter(a=>a.botId===t.id).length;l&&(l.hidden=r===0,l.textContent=`Allow all (${r})`),i&&(i.style.background=Gr(t.status))}var zi={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"},Mi={supervised:"shield","parent-supervised":"shield-up","full-access":"shield-alert"};function Ai(t,e){let n=Mi[e]??"shield";t.dataset.mode=e,t.innerHTML=ve(n,'width="15" height="15"');let i=`\u5BA1\u6279\u6A21\u5F0F\uFF1A${zi[e]??e}`;t.title=`${i}\uFF08\u70B9\u5F00\u53EF\u5207\u6362\uFF09`,t.setAttribute("aria-label",i)}async function il(t){if(w.activeId)try{await q(`/api/bots/${w.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:t})});let e=wn();e&&(e.runtimeMode=t),yn(),qe({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${zi[t]||t}`})}catch(e){qe({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)})}}function qe(t,e=w.activeId){if(!e)return;let n=w.items.get(e)||[];n.push(t),w.items.set(e,n),e===w.activeId&&Be()}function Be(){if(w.renderQueued)return;w.renderQueued=!0;let t=Math.max(0,60-(performance.now()-Si));window.setTimeout(()=>{w.renderQueued=!1,Si=performance.now(),Sn()},t)}function xn(t){switch(t.kind){case"assistant":return{text:t.text,thinking:t.thinking};case"tool":return{phase:t.phase,output:t.output,error:t.isError,durationMs:t.durationMs};case"approval":return{decided:t.decided,approvalState:t.approval.state};default:return{}}}function sl(t,e){return t.text!==e.text||t.thinking!==e.thinking||t.phase!==e.phase||t.output!==e.output||t.error!==e.error||t.durationMs!==e.durationMs||t.decided!==e.decided||t.approvalState!==e.approvalState}function En(t){if(t.kind==="user"){let e=g("div","bv-msg bv-user");return e.appendChild(fn(t.text)),e}if(t.kind==="assistant"){let e=g("div","bv-msg bv-assistant");if(t.thinking){let i=g("details","bv-thinking");i.appendChild(g("summary",void 0,"thinking")),i.appendChild(g("div",void 0,t.thinking)),e.appendChild(i)}let n=g("div","bv-text");return n.appendChild(fn(t.text)),e.appendChild(n),e}return t.kind==="tool"?ll(t):t.kind==="approval"?al(t):g("div",`bv-notice bv-notice-${t.level}`,t.text)}function rl(t,e){let n=t.querySelector("details.bv-thinking");if(e.thinking)if(n){let s=n.querySelector("div");s&&s.textContent!==e.thinking&&(s.textContent=e.thinking)}else{let s=g("details","bv-thinking");s.appendChild(g("summary",void 0,"thinking")),s.appendChild(g("div",void 0,e.thinking)),t.prepend(s)}else n&&n.remove();let i=t.querySelector(".bv-text");i&&i.replaceChildren(fn(e.text))}function Sn(){let t=document.getElementById("bots-messages");if(!t||!w.activeId||document.getElementById("bots-view")?.hidden)return;let e=w.items.get(w.activeId)||[],n=me;if(e.length<Se.length||e.some((i,s)=>Se[s]?.item!==i))t.textContent="",Se=e.map(i=>{let s=En(i);return t.appendChild(s),{item:i,snapshot:xn(i),node:s}});else{for(let i=Se.length;i<e.length;i++){let s=e[i],l=En(s);t.appendChild(l),Se.push({item:s,snapshot:xn(s),node:l})}for(let i=0;i<e.length;i++){let s=e[i],l=Se[i],r=xn(s);if(sl(l.snapshot,r)){if(s.kind==="assistant")rl(l.node,s);else{let a=En(s);l.node.replaceWith(a),l.node=a}l.snapshot=r}}}n&&(t.scrollTop=t.scrollHeight)}function ll(t){let e=g("details","bv-tool");e.open=t.phase!=="end"||!!t.isError;let n=g("summary"),i=g("span","bv-tool-name",t.name);if(n.appendChild(i),t.phase!=="end"&&n.appendChild(g("span","bv-tool-phase",t.phase)),t.isError&&n.appendChild(g("span","bv-tool-error","error")),typeof t.durationMs=="number"&&n.appendChild(g("span","bv-tool-meta",`${Math.round(t.durationMs)}ms`)),e.appendChild(n),t.args!==void 0){let s=g("pre","bv-pre");s.textContent=typeof t.args=="string"?t.args:JSON.stringify(t.args,null,2),e.appendChild(s)}if(t.output){let s=g("pre","bv-pre bv-output");s.textContent=t.output,e.appendChild(s)}return e}function al(t){let e=g("div","bv-approval"),n=t.approval;if(e.appendChild(g("div","bv-approval-title",n.title)),n.message&&e.appendChild(g("pre","bv-pre",n.message)),t.decided)return e.appendChild(g("div","bv-approval-decided",t.decided==="allowed"?"Allowed":"Denied")),e;let i=g("input","bv-reason");i.placeholder="reason (optional)";let s=g("div","bv-approval-actions"),l=g("button","btn primary","Allow"),r=g("button","btn",n.method==="confirm"&&/^Allow (.+?)\?$/.test(n.title)?`Always allow ${/^Allow (.+?)\?$/.exec(n.title)?.[1]}`:"Always allow");r.hidden=n.method!=="confirm";let a=g("button","btn danger","Deny"),o=async(c,d=!1)=>{try{await q(`/api/bots/${n.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:n.id,allow:c,always:d,reason:i.value||void 0})}),t.decided=c?"allowed":"denied",Be(),le(!0)}catch(m){qe({kind:"notice",level:"error",text:m instanceof Error?m.message:String(m)})}};return l.onclick=()=>void o(!0),r.onclick=()=>void o(!0,!0),a.onclick=()=>void o(!1),s.append(i,l,r,a),e.appendChild(s),e}function Bi(t){let e=String(t.type||""),n=w.activeId;if(!n)return;let i=w.items.get(n)||[];if(e==="snapshot")w.items.set(n,[]);else if(e==="user")me=!0,qe({kind:"user",text:String(t.text||"")});else if(e==="status"){let s=wn();s&&(s.status=String(t.status||s.status)),yn(),dl()}else if(e==="message"){let s=t.message;if(!s||String(s.role||"")!=="assistant")return;let l=ol(s),r=cl(s),a=i[i.length-1];a&&a.kind==="assistant"?(a.text=l||a.text,a.thinking=r||a.thinking):i.push({kind:"assistant",text:l,thinking:r}),w.items.set(n,i),Be()}else if(e==="delta"){let s=String(t.kind||""),l=String(t.delta||""),r=i[i.length-1];(!r||r.kind!=="assistant")&&(i.push({kind:"assistant",text:"",thinking:""}),r=i[i.length-1]),r.kind==="assistant"&&(s==="text"?r.text+=l:s==="thinking"&&(r.thinking+=l)),w.items.set(n,i),Be()}else if(e==="tool"){let s=String(t.callId||""),l=i.find(a=>a.kind==="tool"&&a.callId===s),r=String(t.phase||"start");l?(l.phase=r,r==="update"&&t.output&&(l.output=String(t.output)),r==="end"&&(t.output&&(l.output=String(t.output)),l.isError=t.isError===!0,typeof t.durationMs=="number"&&(l.durationMs=t.durationMs))):i.push({kind:"tool",callId:s,name:String(t.name||"tool"),args:t.args,output:t.output?String(t.output):void 0,isError:t.isError===!0,durationMs:typeof t.durationMs=="number"?t.durationMs:void 0,phase:r}),w.items.set(n,i),Be()}else if(e==="approval"){let s=t.approval;if(!s)return;let l=i;for(let r=l.length-1;r>=0;r--){let a=l[r];if(a.kind==="approval"&&a.approval.id===s.id){a.approval=s,s.state!=="pending"&&(a.decided=s.state==="allowed"?"allowed":"denied"),w.items.set(n,l),Be();return}}l.push({kind:"approval",approval:s}),w.items.set(n,l),Be()}else e==="notice"&&qe({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function ol(t){let e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="text"?String(n.text||""):"").join(""):String(t.text||"")}function cl(t){let e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="thinking"?String(n.thinking||""):"").join(""):""}async function le(t=!1){try{let[e,n]=await Promise.all([q("/api/bots"),q("/api/bots/approvals")]);if(w.bots=e,w.approvals=n,zt(),yn(),t&&w.activeId){let i=await q(`/api/bots/${w.activeId}/events?limit=300`);pl(i)}}catch{}}async function dl(){try{w.bots=await q("/api/bots"),zt()}catch{}}function pl(t){if(w.activeId){w.items.set(w.activeId,[]);for(let e of t)Bi(e);Sn()}}function ul(){let t=g("div","bots-modal");t.id="bots-modal",t.hidden=!0;let e=g("div","bots-modal-card"),n=g("div","bots-modal-head"),i=g("span");i.id="bots-modal-title";let s=g("button","btn");s.innerHTML=ve("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>Mt(),n.append(i,s);let l=g("div","bots-modal-body");l.id="bots-modal-body",e.append(n,l),t.appendChild(e),t.onclick=r=>{r.target===t&&Mt()},document.body.appendChild(t)}function Cn(t){let e=document.getElementById("bots-modal"),n=document.getElementById("bots-modal-title"),i=document.getElementById("bots-modal-body");if(!e||!i)throw new Error("modal missing");return n&&(n.textContent=t),i.textContent="",e.hidden=!1,i}function Mt(){let t=document.getElementById("bots-modal");t&&(t.hidden=!0)}async function hl(){return w.catalog||(w.catalog=await q("/api/bots/catalog")),w.catalog}async function Ri(){return w.templates=await q("/api/bots/templates"),w.templates}async function rt(){let t=Cn("Bot templates"),[e,n]=await Promise.all([hl(),Ri()]),i=g("div","bv-template-list");for(let o of n){let c=g("div","bv-template-row");c.appendChild(g("span","bv-template-name",o.manifest.name)),c.appendChild(g("span","bv-template-desc",o.manifest.description||""));let d=g("button","btn","Edit");d.onclick=()=>Pi(t,e,o);let m=g("button","btn","Copy");m.title="Duplicate this template",m.onclick=()=>{let f=JSON.parse(JSON.stringify(o.manifest));f.name=`${o.manifest.name} copy`,q("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:f})}).then(()=>rt()).catch(b=>alert(b instanceof Error?b.message:String(b)))};let u=g("button","btn danger","Delete");u.onclick=()=>{confirm(`Delete template ${o.manifest.name}?`)&&q(`/api/bots/templates/${o.id}`,{method:"DELETE"}).then(()=>rt())};let h=g("span","bv-template-actions");h.append(d,m,u),c.appendChild(h),i.appendChild(c)}n.length===0&&i.appendChild(g("div","bots-empty","No templates yet")),t.appendChild(i);let s=g("div","bv-template-actions"),l=g("button","btn primary","New template");l.onclick=()=>Pi(t,e,null);let r=g("button","btn","Export");r.title="Download templates + library as JSON",r.onclick=()=>{(async()=>{try{let o=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${gn()}`}});if(!o.ok)throw new Error(`HTTP ${o.status}`);let c=await o.blob(),d=document.createElement("a");d.href=URL.createObjectURL(c),d.download=`tmux-weblink-bots-${new Date().toISOString().slice(0,10)}.json`,d.click(),setTimeout(()=>URL.revokeObjectURL(d.href),2e3)}catch(o){alert(o instanceof Error?o.message:String(o))}})()};let a=g("button","btn","Import");a.title="Restore templates from a JSON bundle",a.onclick=()=>{let o=document.createElement("input");o.type="file",o.accept="application/json,.json",o.onchange=()=>{let c=o.files?.[0];c&&(async()=>{try{let d=JSON.parse(await c.text()),m=await q("/api/bots/import",{method:"POST",body:JSON.stringify(d)});alert(`Imported ${m.templates} templates, ${m.files} library files (${m.skipped} kept)`),await rt()}catch(d){alert(d instanceof Error?d.message:String(d))}})()},o.click()},s.append(l,r,a),t.appendChild(s)}function Ln(t,e,n){let i=g("div","bv-field");i.appendChild(g("label","bv-label",t));let s=g("div","bv-check-grid"),l=[];for(let r of e){let a=g("label","bv-check"),o=document.createElement("input");o.type="checkbox",o.checked=n.includes(r.id),a.append(o,g("span",void 0,r.label)),r.hint&&(a.title=r.hint),s.appendChild(a),l.push({id:r.id,input:o})}return i.appendChild(s),{element:i,get:()=>l.filter(r=>r.input.checked).map(r=>r.id)}}function Pi(t,e,n){t.textContent="";let i=n?JSON.parse(JSON.stringify(n.manifest)):{name:"new-bot",description:""},s=g("input","bv-input");s.value=i.name,s.placeholder="Template name";let l=g("input","bv-input");l.value=i.description||"",l.placeholder="One line description";let r=g("textarea","bv-textarea");r.rows=6,r.value=i.system||"",r.placeholder="System prompt for this bot (written to SYSTEM.md)";let a=Ln("Skills",e.skills.map(E=>({id:E.id,label:E.name,hint:E.description})),i.skills||[]),o=Ln("Extensions (Pi builtins + library)",e.extensions.map(E=>({id:E.id,label:`${E.name}${E.kind==="builtin"?" (builtin)":""}`,hint:E.description})),(i.extensions||[]).map(E=>E.replace(/^.*\//,"").replace(/\.(js|ts)$/,""))),c=Ln("Prompt templates",e.prompts.map(E=>({id:E.id,label:E.name})),i.prompts||[]),d=g("select","bv-input");d.appendChild(new Option("none",""));for(let E of e.mcp)d.appendChild(new Option(E.name,E.id));i.mcp&&(d.value=e.mcp.find(E=>JSON.stringify(E.servers)===JSON.stringify(i.mcp?.mcpServers))?.id||"");let m=g("div","bv-field");m.appendChild(g("label","bv-label","Tools (allow list; deny always blocks)"));let u=g("div","bv-check-grid"),h=[];for(let E of e.tools){let B=g("label","bv-check"),C=document.createElement("input");C.type="checkbox",C.checked=(i.tools?.allow||[]).includes(E.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(E.name),B.append(C,g("span",void 0,E.name)),u.appendChild(B),h.push({name:E.name,input:C})}m.appendChild(u);let f=g("input","bv-input");f.value=(i.tools?.deny||[]).join(", "),f.placeholder="Always deny (comma separated), e.g. bash, write";let b=g("textarea","bv-textarea");b.rows=2,b.value=(i.packages||[]).join(`
|
|
86
|
-
`),b.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";let
|
|
87
|
-
${
|
|
88
|
-
${i.model.id}`);let
|
|
89
|
-
`),
|
|
90
|
-
`).map(
|
|
91
|
-
<span>${
|
|
92
|
-
<button class="session-edit-btn" data-session="${
|
|
93
|
-
<span>${
|
|
94
|
-
<button class="session-edit-btn" data-session="${
|
|
95
|
-
`,e.addEventListener("click",i=>{i.target.closest(".session-edit-btn")||
|
|
96
|
-
<span>${
|
|
97
|
-
<button class="session-edit-btn" data-session="${
|
|
82
|
+
`}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${G(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,text:n,tokens:i,autolink:s}){let l=s?G(n,!0):this.parser.parseInline(i),a=hi(t);if(a===null)return l;t=G(a,s);let r='<a href="'+t+'"';return e&&(r+=' title="'+G(e)+'"'),r+=">"+l+"</a>",r}image({href:t,title:e,text:n,tokens:i}){i&&(n=this.parser.parseInline(hn(i),this.parser.textRenderer));let s=hi(t);if(s===null)return G(n);t=s;let l=`<img src="${G(t)}" alt="${G(n)}"`;return e&&(l+=` title="${G(e)}"`),l+=">",l}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:G(t.text)}},mn=class{parser;strong({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}em({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}codespan({text:t}){return t}del({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}html({text:t}){return t}text({text:t}){return t}link({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}image({text:t,tokens:e}){return e?this.parser.parseInline(e,this):t}br(){return`
|
|
83
|
+
`}checkbox({raw:t}){return t}},re=class Fn{options;renderer;textRenderer;constructor(e){this.options=e||Ae,this.options.renderer=this.options.renderer||new $t,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new mn,this.textRenderer.parser=this}static parse(e,n){return new Fn(n).parse(e)}static parseInline(e,n){return new Fn(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let i=0;i<e.length;i++){let s=e[i],l=this.options.extensions?.renderers;if(l&&Object.hasOwn(l,s.type)&&l[s.type]){let r=s,o=l[r.type].call({parser:this},r);if(o!==!1||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(r.type)){n+=o===!1?"":o??"";continue}}let a=s;switch(a.type){case"space":{n+=this.renderer.space(a);break}case"hr":{n+=this.renderer.hr(a);break}case"heading":{n+=this.renderer.heading(a);break}case"code":{n+=this.renderer.code(a);break}case"table":{n+=this.renderer.table(a);break}case"blockquote":{n+=this.renderer.blockquote(a);break}case"list":{n+=this.renderer.list(a);break}case"checkbox":{n+=this.renderer.checkbox(a);break}case"html":{n+=this.renderer.html(a);break}case"def":{n+=this.renderer.def(a);break}case"paragraph":{n+=this.renderer.paragraph(a);break}case"text":{n+=this.renderer.text(a);break}default:{let r='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(r),"";throw new Error(r)}}}return n}parseInline(e,n=this.renderer){this.renderer.parser=this;let i="";for(let s=0;s<e.length;s++){let l=e[s],a=this.options.extensions?.renderers;if(a&&Object.hasOwn(a,l.type)&&a[l.type]){let o=a[l.type].call({parser:this},l);if(o!==!1||!["escape","html","link","image","checkbox","strong","em","codespan","br","del","text"].includes(l.type)){i+=o===!1?"":o??"";continue}}let r=l;switch(r.type){case"escape":{i+=n.text(r);break}case"html":{i+=n.html(r);break}case"link":{i+=n.link(r);break}case"image":{i+=n.image(r);break}case"checkbox":{i+=n.checkbox(r);break}case"strong":{i+=n.strong(r);break}case"em":{i+=n.em(r);break}case"codespan":{i+=n.codespan(r);break}case"br":{i+=n.br(r);break}case"del":{i+=n.del(r);break}case"text":{i+=n.text(r);break}default:{let o='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return i}},at=class{options;block;constructor(t){this.options=t||Ae}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(t=this.block){return t?le.lex:le.lexInline}provideParser(t=this.block){return t?re.parse:re.parseInline}};function Ce(t,e){if(Array.isArray(e))for(let n=0;n<e.length;n++)t.push(e[n]);else t.push(e)}var Ja=class{defaults=tn();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=re;Renderer=$t;TextRenderer=mn;Lexer=le;Tokenizer=Be;Hooks=at;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let i of t)switch(Ce(n,e.call(this,i)),i.type){case"table":{let s=i;for(let l of s.header)Ce(n,this.walkTokens(l.tokens,e));for(let l of s.rows)for(let a of l)Ce(n,this.walkTokens(a.tokens,e));break}case"list":{let s=i;Ce(n,this.walkTokens(s.items,e));break}default:{let s=i;this.defaults.extensions?.childTokens?.[s.type]?this.defaults.extensions.childTokens[s.type].forEach(l=>{if(s[l]){let a=s[l].flat(1/0);Ce(n,this.walkTokens(a,e))}}):s.tokens&&Ce(n,this.walkTokens(s.tokens,e))}}return n}use(...t){let e=this.defaults.extensions||{renderers:Object.create(null),childTokens:Object.create(null)};return t.forEach(n=>{let i={...n};if(i.async=this.defaults.async||i.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s&&s.renderer){let l=s.renderer,a=e.renderers[s.name];a?e.renderers[s.name]=function(...r){let o=l.apply(this,r);return o===!1&&(o=a.apply(this,r)),o}:e.renderers[s.name]=l}if("tokenizer"in s&&s.tokenizer){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let l=e[s.level];l?l.unshift(s.tokenizer):e[s.level]=[s.tokenizer],s.start&&(s.level==="block"?e.startBlock?e.startBlock.push(s.start):e.startBlock=[s.start]:s.level==="inline"&&(e.startInline?e.startInline.push(s.start):e.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(e.childTokens[s.name]=s.childTokens)}),i.extensions=e),n.renderer){let s=this.defaults.renderer||new $t(this.defaults);for(let l in n.renderer){if(!(l in s))throw new Error(`renderer '${l}' does not exist`);if(["options","parser"].includes(l))continue;let a=l,r=n.renderer[a];if(r===void 0)continue;let o=s[a];s[a]=(...c)=>{let d=r.apply(s,c);return d===!1&&(d=o.apply(s,c)),d===!1?"":d??""}}i.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new Be(this.defaults);for(let l in n.tokenizer){if(!(l in s))throw new Error(`tokenizer '${l}' does not exist`);if(["options","rules","lexer"].includes(l))continue;let a=l,r=n.tokenizer[a];if(r===void 0)continue;let o=s[a];s[a]=(...c)=>{let d=r.apply(s,c);return d===!1&&(d=o.apply(s,c)),d}}i.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new at;for(let l in n.hooks){if(!(l in s))throw new Error(`hook '${l}' does not exist`);if(["options","block"].includes(l))continue;let a=l,r=n.hooks[a];if(r===void 0)continue;let o=s[a];at.passThroughHooks.has(l)?s[a]=c=>{if(s.options.async&&at.passThroughHooksRespectAsync.has(l))return(async()=>{let m=await r.call(s,c);return o.call(s,m)})();let d=r.call(s,c);return o.call(s,d)}:s[a]=(...c)=>{if(s.options.async)return(async()=>{let m=await r.apply(s,c);return m===!1&&(m=await o.apply(s,c)),m})();let d=r.apply(s,c);return d===!1&&(d=o.apply(s,c)),d}}i.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,l=n.walkTokens;i.walkTokens=function(a){let r=[];return Ce(r,l.call(this,a)),s&&Ce(r,s.call(this,a)),r}}this.defaults={...this.defaults,...i}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return le.lex(t,e??this.defaults)}parser(t,e){return re.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let i={...n},s={...this.defaults,...i},l=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&i.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 e>"u"||e===null)return l(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=t),s.async)return(async()=>{let a=s.hooks?await s.hooks.preprocess(e):e,r=await(s.hooks?await s.hooks.provideLexer(t):t?le.lex:le.lexInline)(a,s),o=s.hooks?await s.hooks.processAllTokens(r):r;s.walkTokens&&await Promise.all(this.walkTokens(o,s.walkTokens));let c=await(s.hooks?await s.hooks.provideParser(t):t?re.parse:re.parseInline)(o,s);return s.hooks?await s.hooks.postprocess(c):c})().catch(l);try{s.hooks&&(e=s.hooks.preprocess(e));let a=(s.hooks?s.hooks.provideLexer(t):t?le.lex:le.lexInline)(e,s);s.hooks&&(a=s.hooks.processAllTokens(a)),s.walkTokens&&this.walkTokens(a,s.walkTokens);let r=(s.hooks?s.hooks.provideParser(t):t?re.parse:re.parseInline)(a,s);return s.hooks&&(r=s.hooks.postprocess(r)),r}catch(a){return l(a)}}}onError(t,e){return n=>{let i=n instanceof Error?n:new Error(String(n));if(i.message+=`
|
|
84
|
+
Please report this to https://github.com/markedjs/marked.`,t){let s="<p>An error occurred:</p><pre>"+G(i.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(i);throw i}}},Re=new Ja;function P(t,e){return Re.parse(t,e)}function Za(t,e){return Re.parseInline(t,e)}P.options=P.setOptions=function(t){return Re.setOptions(t),P.defaults=Re.defaults,Qn(P.defaults),P},P.getDefaults=tn,P.defaults=Ae;function Ya(...t){return Re.use(...t),P.defaults=Re.defaults,Qn(P.defaults),P}P.use=Ya,P.walkTokens=function(t,e){return Re.walkTokens(t,e)},P.parseInline=Za,P.Parser=re,P.parser=re.parse,P.Renderer=$t,P.TextRenderer=mn,P.Lexer=le,P.lexer=le.lex,P.Tokenizer=Be,P.Hooks=at,P.parse=P;var Ql=P.options,Gl=P.setOptions,er=P.walkTokens,tr=P.parseInline,nr=re.parse,ir=le.lex,Xa=new Set(["http:","https:","mailto:"]);function yi(t){let e=(t??"").trim();if(!e||e.startsWith("//"))return null;if(!/^[a-z][a-z0-9+.-]*:/i.test(e))return e;try{return Xa.has(new URL(e).protocol)?e:null}catch{return null}}var xi=t=>/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith("mailto:"),Si=4e5,Ka=200;function Qa(t){let e=new Map,n=0;function i(m,p){let h=m.length+Ka;if(!(h>Si/4)){e.set(m,{fragment:p,chars:h}),n+=h;for(let f of e.keys()){if(n<=Si)break;let b=e.get(f);b&&(e.delete(f),n-=b.chars)}}}function s(m,p){p.split(`
|
|
85
|
+
`).forEach((h,f)=>{f>0&&m.appendChild(t.createElement("br")),h&&m.appendChild(t.createTextNode(h))})}function l(m,p){switch(p.type){case"text":{if(p.tokens?.length){for(let h of p.tokens)l(m,h);return}s(m,p.text??p.raw??"");return}case"escape":m.appendChild(t.createTextNode(p.text??""));return;case"strong":case"em":case"del":{let h=t.createElement(p.type==="strong"?"strong":p.type==="em"?"em":"del");for(let f of p.tokens??[])l(h,f);m.appendChild(h);return}case"codespan":{let h=t.createElement("code");h.textContent=p.text??"",m.appendChild(h);return}case"br":m.appendChild(t.createElement("br"));return;case"link":{let h=p.tokens??[],f=yi(p.href);if(!f){for(let w of h)l(m,w);return}let b=t.createElement("a");b.href=f,b.rel="noreferrer noopener",p.title&&(b.title=p.title),xi(f)&&(b.target="_blank");for(let w of h)l(b,w);m.appendChild(b);return}case"image":{let h=yi(p.href),f=p.text?.trim()||p.href||"image";if(!h){m.appendChild(t.createTextNode(f));return}let b=t.createElement("a");b.href=h,b.textContent=f,b.rel="noreferrer noopener",xi(h)&&(b.target="_blank"),m.appendChild(b);return}case"html":m.appendChild(t.createTextNode(p.raw??p.text??""));return;default:if(p.tokens?.length){for(let h of p.tokens)l(m,h);return}s(m,p.text??p.raw??"")}}function a(m){let p=t.createElement("div");p.className="bv-code";let h=t.createElement("div");h.className="bv-code-head";let f=(m.lang??"").trim().split(/\s+/)[0]??"",b=t.createElement("span");b.className="bv-code-lang",b.textContent=f||"text";let w=t.createElement("button");w.type="button",w.className="bv-code-copy",w.textContent="Copy";let y=m.text??"";w.addEventListener("click",()=>{let T=navigator.clipboard?.writeText(y);T&&T.then(()=>{w.textContent="Copied",window.setTimeout(()=>{w.textContent="Copy"},1200)},()=>{})}),h.append(b,w);let C=t.createElement("pre"),M=t.createElement("code");return f&&(M.className=`language-${f}`),M.textContent=y,C.appendChild(M),p.append(h,C),p}function r(m,p){let h=t.createElement("div");h.className="bv-table";let f=t.createElement("table"),b=t.createElement("thead"),w=t.createElement("tr"),y=p.align??[],C=(T,I,$)=>{let z=t.createElement(T);y[$]&&(z.style.textAlign=y[$]);for(let x of I.tokens??[])l(z,x);return z};(p.header??[]).forEach((T,I)=>w.appendChild(C("th",T,I))),b.appendChild(w);let M=t.createElement("tbody");for(let T of p.rows??[]){let I=t.createElement("tr");T.forEach(($,z)=>I.appendChild(C("td",$,z))),M.appendChild(I)}f.append(b,M),h.appendChild(f),m.appendChild(h)}function o(m,p){let h=t.createElement("li");if(p.task){let f=t.createElement("input");f.type="checkbox",f.disabled=!0,f.checked=p.checked===!0,h.appendChild(f)}for(let f of p.tokens??[])if(f.type==="text")l(h,f);else if(f.type==="paragraph")for(let b of f.tokens??[])l(h,b);else c(h,f);m.appendChild(h)}function c(m,p){switch(p.type){case"space":return;case"heading":{let h=Math.min(Math.max(p.depth??1,1),6),f=t.createElement(`h${h}`);for(let b of p.tokens??[])l(f,b);m.appendChild(f);return}case"paragraph":{let h=t.createElement("p");for(let f of p.tokens??[])l(h,f);m.appendChild(h);return}case"text":l(m,p);return;case"code":m.appendChild(a(p));return;case"blockquote":{let h=t.createElement("blockquote");for(let f of p.tokens??[])c(h,f);m.appendChild(h);return}case"list":{let h=p.items??p.tokens??[];if(p.ordered){let f=t.createElement("ol");typeof p.start=="number"&&p.start!==1&&(f.start=p.start);for(let b of h)o(f,b);m.appendChild(f)}else{let f=t.createElement("ul");for(let b of h)o(f,b);m.appendChild(f)}return}case"table":r(m,p);return;case"hr":m.appendChild(t.createElement("hr"));return;case"html":case"escape":m.appendChild(t.createTextNode(p.raw??p.text??""));return;default:if(p.tokens?.length){for(let h of p.tokens)c(m,h);return}p.text&&m.appendChild(t.createTextNode(p.text))}}function d(m){let p=t.createDocumentFragment();try{let h=P.lexer(m);for(let f of h)c(p,f)}catch{p.replaceChildren(t.createTextNode(m))}return p}return m=>{let p=e.get(m);if(p)return e.delete(m),e.set(m,p),p.fragment.cloneNode(!0);let h=d(m);return i(m,h),h.cloneNode(!0)}}var fn=Qa(document),k={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1},Le=[],fe=!0,Ga=!1,Ei=0;function gn(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function j(t,e){let n=await fetch(t,{...e,headers:{"content-type":"application/json",Authorization:`Bearer ${gn()}`,...e?.headers||{}}}),i=await n.text(),s=i?JSON.parse(i):null;if(!n.ok)throw new Error(s&&s.error||`HTTP ${n.status}`);return s}function g(t,e,n){let i=document.createElement(t);return e&&(i.className=e),n!==void 0&&(i.textContent=n),i}function Ci(t){return t==="running"?"var(--panel-success)":t==="waiting_approval"||t==="waiting_input"?"#e0a23c":t==="failed"?"var(--panel-danger, #e5534b)":t==="completed"?"var(--panel-accent)":"var(--panel-muted)"}function Te(){vn||(vn=requestAnimationFrame(()=>{vn=0,el()}))}var vn=0,It="";function el(){let t=document.getElementById("bots-view");if(!t)return;let e=window.visualViewport,n=window.matchMedia("(max-width: 640px)").matches,i=!document.querySelector(".sidebar")?.classList.contains("collapsed");if(k.activeId&&e&&n&&!i){let s=document.querySelector(".fixed-header"),l=s?Math.round(s.getBoundingClientRect().height):0,a=Math.round(e.offsetTop)+l,r=Math.round(e.offsetLeft),o=Math.round(e.width),c=Math.max(120,Math.round(e.height)-l),d=`fixed|${a}|${r}|${o}|${c}`;if(d===It)return;It=d,t.style.position="fixed",t.style.top=`${a}px`,t.style.left=`${r}px`,t.style.width=`${o}px`,t.style.height=`${c}px`,t.style.right="auto",t.style.bottom="auto"}else{if(It==="")return;It="",t.style.position="",t.style.top="",t.style.left="",t.style.width="",t.style.height="",t.style.right="",t.style.bottom=""}}window.visualViewport?.addEventListener("resize",Te),window.visualViewport?.addEventListener("scroll",Te),window.addEventListener("resize",Te),document.addEventListener("click",Te);var Li=document.querySelector(".sidebar");Li&&new MutationObserver(Te).observe(Li,{attributes:!0,attributeFilter:["class"]}),window.__syncBotsViewport=Te;function At(){let t=k.approvals.length,e=document.getElementById("bots-inbox-badge");e&&(e.style.display=t?"inline-block":"none",e.textContent=String(t));let n=document.getElementById("bv-inbox-count");n&&(n.textContent=t?`(${t})`:""),window.__botsSnapshot=k.bots,window.__refreshSidebar?.()}function tl(){let t=document.getElementById("set-bot-templates"),e=document.getElementById("set-bot-new"),n=document.getElementById("set-bot-inbox"),i=()=>{document.getElementById("settings-popover")?.classList.remove("open"),document.getElementById("settings-backdrop")?.classList.remove("open")};t?.addEventListener("click",()=>{i(),lt()}),e?.addEventListener("click",()=>{i(),fl()}),n?.addEventListener("click",()=>{i(),Tn()})}function nl(){let t=g("div","bots-view");t.id="bots-view",t.hidden=!0;let e=g("div","bots-view-head"),n=g("div","bv-title"),i=g("span","bots-dot");i.id="bv-dot";let s=g("span","bv-title-text");s.id="bv-title";let l=g("span","bv-status");l.id="bv-status",n.append(i,s,l);let a=g("div","bv-actions"),r=g("div","bv-mode"),o=g("button","bv-mode-btn");o.id="bv-mode-btn",o.type="button",o.setAttribute("aria-haspopup","menu"),o.setAttribute("aria-expanded","false"),Bi(o,"supervised");let c=g("div","bv-menu bv-mode-menu");c.id="bv-mode-menu",c.setAttribute("role","menu"),c.hidden=!0;for(let[L,U,ve]of[["supervised","\u9ED8\u8BA4","\u53EA\u8BFB\u5DE5\u5177\uFF08read/grep/find/ls\uFF09\u76F4\u63A5\u653E\u884C\uFF1Bbash\u3001edit\u3001write\u3001\u6269\u5C55/MCP \u5DE5\u5177\u4F1A\u95EE\u4F60"],["parent-supervised","\u76D1\u7BA1","\u5176\u4F59\u5DE5\u5177\u4EA4\u7ED9\u4E0A\u7EA7 bot \u51B3\u5B9A\uFF08\u5E26\u7406\u7531\uFF09\uFF1B\u4F60\u4ECD\u7136\u80FD\u770B\u5230\u5E76\u56DE\u7B54\uFF0C\u5148\u7B54\u5148\u5F97\uFF1B\u6CA1\u6709\u4E0A\u7EA7\u65F6\u56DE\u843D\u5230\u9ED8\u8BA4"],["full-access","\u5168\u653E\u884C","\u6240\u6709\u5DE5\u5177\u76F4\u63A5\u6267\u884C\uFF0C\u4E0D\u518D\u8BE2\u95EE\u3002\u6CE8\u610F\u8FD9\u4E0D\u662F\u6C99\u7BB1"]]){let q=g("button","bv-menu-item");q.dataset.mode=L,q.setAttribute("role","menuitemradio"),q.innerHTML=`<span class="bv-menu-icon">${ae(Mi[L],'width="15" height="15"')}</span><span class="bv-menu-text"><b>${U}</b><span>${ve}</span></span><span class="bv-menu-check">${ae("check",'width="13" height="13"')}</span>`,q.onclick=()=>{d(!1),sl(L)},c.appendChild(q)}let d=L=>{L&&I(!1),c.hidden=!L,o.setAttribute("aria-expanded",L?"true":"false")};o.onclick=L=>{L.stopPropagation(),d(c.hidden)},r.append(o);let m=g("button","btn bv-inbox");m.id="bv-inbox",m.title="Requests waiting for you";let p=g("span",void 0,"Needs you"),h=g("span","bv-inbox-count");h.id="bv-inbox-count",m.append(p,h),m.onclick=()=>void Tn();let f=g("button","bv-icon-btn");f.id="bv-more-btn",f.type="button",f.title="More actions",f.setAttribute("aria-label","More actions"),f.setAttribute("aria-haspopup","menu"),f.setAttribute("aria-expanded","false"),f.innerHTML=ae("dots",'width="16" height="16"');let b=g("div","bv-menu");b.id="bv-more-menu",b.setAttribute("role","menu"),b.hidden=!0;let w=(L,U,ve,q)=>{let Y=g("button",`bv-menu-item${L?` ${L}`:""}`);return Y.type="button",Y.setAttribute("role","menuitem"),Y.innerHTML=`<span class="bv-menu-icon">${ae(U,'width="15" height="15"')}</span><span class="bv-menu-text"><b>${ve}</b></span>`,Y.onclick=()=>{I(!1),q()},Y},y=w("","check","Allow all",()=>{if(!k.activeId)return;let L=k.approvals.filter(U=>U.botId===k.activeId);Promise.all(L.map(U=>j(`/api/bots/${U.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:U.id,allow:!0})}))).finally(()=>void oe(!0))});y.id="bv-allow-all",y.title="Approve every pending request for this bot";let C=w("","refresh","Resume bot",()=>Ii(L=>j(`/api/bots/${L}/resume`,{method:"POST"}).then(()=>oe(!0)))),M=w("","stop","Stop run",()=>Ii(L=>j(`/api/bots/${L}/stop`,{method:"POST"}).then(()=>oe(!0)))),T=w("danger","delete","Delete bot",()=>{k.activeId&&confirm("Delete this bot and its session?")&&j(`/api/bots/${k.activeId}`,{method:"DELETE"}).then(()=>{kn(),oe(!0)})});b.append(y,C,M,g("div","bv-menu-sep"),T);let I=L=>{L&&d(!1),b.hidden=!L,f.setAttribute("aria-expanded",L?"true":"false")};f.onclick=L=>{L.stopPropagation(),I(b.hidden)},document.addEventListener("click",L=>{let U=L.target;U&&(!r.contains(U)&&!c.contains(U)&&d(!1),!f.contains(U)&&!b.contains(U)&&I(!1))}),a.append(r,m,f),e.append(n,a);let $=g("div","bots-messages");$.id="bots-messages";let z=g("button","bv-jump");z.type="button",z.id="bv-jump",z.innerHTML=`${ae("chevron-down",'width="14" height="14"')}<span>Latest</span>`,z.title="Jump to the latest message",z.hidden=!0,z.onclick=()=>{fe=!0,$.scrollTop=$.scrollHeight,z.hidden=!0};let x=()=>{fe=$.scrollHeight-$.scrollTop-$.clientHeight<48,z.hidden=fe};$.addEventListener("scroll",x,{passive:!0}),$.addEventListener("touchmove",()=>{fe=!1,z.hidden=$.scrollHeight-$.clientHeight<1},{passive:!0}),$.addEventListener("wheel",()=>{fe=!1},{passive:!0});let F=g("div","bots-composer-wrap"),B=g("div","bv-composer-error");B.id="bv-composer-error",B.hidden=!0;let Z=g("div","bots-composer"),A=g("textarea");A.id="bots-input",A.rows=1,A.placeholder="Message the bot\u2026",A.spellcheck=!1;let Se=window.matchMedia("(pointer: coarse)").matches;Se||(A.enterKeyHint="send"),A.onkeydown=L=>{L.key!=="Enter"||L.shiftKey||L.isComposing||Se||L.keyCode===229||(L.preventDefault(),$i())},A.oninput=()=>bn(null);let W=g("button","btn primary");W.id="bv-send",W.title="Send",W.setAttribute("aria-label","Send"),W.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>',W.onclick=()=>void $i(),Z.append(A,W),Z.addEventListener("click",L=>{L.target?.closest("button")||document.activeElement!==A&&A.focus()}),F.append(B,Z),t.append(e,$,z,F,c,b),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||hl()}function bn(t){let e=document.getElementById("bv-composer-error");e&&(e.textContent=t??"",e.hidden=!t)}function Ti(t){let e=document.getElementById("bv-send");e&&(e.disabled=t,e.setAttribute("aria-busy",t?"true":"false"),e.title=t?"Sending\u2026":"Send")}async function $i(){let t=document.getElementById("bots-input");if(!t||!k.activeId||Ga||!t.value.trim())return;let e=k.activeId,n=t.value;bn(null),Ti(!0);try{await j(`/api/bots/${e}/input`,{method:"POST",body:JSON.stringify({text:n})}),t.value===n&&(t.value=""),fe=!0}catch(i){bn(i instanceof Error?i.message:String(i))}finally{Ti(!1)}}function Ii(t){k.activeId&&t(k.activeId).catch(e=>Pe({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function kn(){k.activeId=null,Le=[],fe=!0,Te();let t=document.getElementById("bots-view");t&&(t.hidden=!0);try{k.ws?.close()}catch{}k.ws=null,At();let e=document.getElementById("terminal-container"),n=document.getElementById("main-placeholder"),i=!!document.querySelector(".session-item.active:not(.bot-item)");e&&i?(e.style.display="",n&&(n.style.display="none")):n&&(n.style.display="")}async function Ai(t){k.activeId=t,Le=[],fe=!0;let e=document.getElementById("bv-jump");e&&(e.hidden=!0),window.__collapseSidebar?.(),Te(),k.items.set(t,[]);let n=document.getElementById("bots-view");n&&(n.hidden=!1);let i=document.getElementById("main-placeholder");i&&(i.style.display="none");let s=document.getElementById("terminal-container");s&&(s.style.display="none");let l=document.getElementById("file-editor");l&&(l.style.display="none"),At(),En();try{k.ws?.close()}catch{}let a=location.protocol==="https:"?"wss:":"ws:",r=new WebSocket(`${a}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(gn())}`);k.ws=r,r.onmessage=o=>{try{Ri(JSON.parse(String(o.data)))}catch{}},r.onclose=()=>{k.activeId===t&&setTimeout(()=>{k.activeId===t&&oe(!0)},1500)},await oe(!0)}function wn(){return k.bots.find(t=>t.id===k.activeId)||null}function yn(){let t=wn();if(!t)return;let e=document.getElementById("bv-title"),n=document.getElementById("bv-status"),i=document.getElementById("bv-dot");e&&(e.textContent=t.title),n&&(n.textContent=il[t.status]??t.status.replace(/_/g," "),n.dataset.status=t.status,n.style.color=Ci(t.status),n.title=`${t.status.replace(/_/g," ")} \xB7 ${t.templateId} \xB7 ${t.projectPath}`);let s=document.getElementById("bv-mode-btn");s&&Bi(s,t.runtimeMode||"supervised");for(let r of document.querySelectorAll("#bv-mode-menu button")){let o=r.dataset.mode===t.runtimeMode;r.classList.toggle("active",o),r.setAttribute("aria-checked",o?"true":"false")}let l=document.getElementById("bv-allow-all"),a=k.approvals.filter(r=>r.botId===t.id).length;if(l){l.hidden=a===0;let r=l.querySelector(".bv-menu-text b");r&&(r.textContent=`Allow all (${a})`)}i&&(i.style.background=Ci(t.status))}var il={queued:"queued",starting:"starting",running:"running",waiting_input:"waiting",waiting_approval:"approval",completed:"done",failed:"failed",cancelled:"stopped",stale:"stale"},zi={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"},Mi={supervised:"shield","parent-supervised":"shield-up","full-access":"shield-alert"};function Bi(t,e){let n=Mi[e]??"shield";t.dataset.mode=e,t.innerHTML=ae(n,'width="15" height="15"');let i=`\u5BA1\u6279\u6A21\u5F0F\uFF1A${zi[e]??e}`;t.title=`${i}\uFF08\u70B9\u5F00\u53EF\u5207\u6362\uFF09`,t.setAttribute("aria-label",i)}async function sl(t){if(k.activeId)try{await j(`/api/bots/${k.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:t})});let e=wn();e&&(e.runtimeMode=t),yn(),Pe({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${zi[t]||t}`})}catch(e){Pe({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)})}}function Pe(t,e=k.activeId){if(!e)return;let n=k.items.get(e)||[];n.push(t),k.items.set(e,n),e===k.activeId&&De()}function De(){if(k.renderQueued)return;k.renderQueued=!0;let t=Math.max(0,60-(performance.now()-Ei));window.setTimeout(()=>{k.renderQueued=!1,Ei=performance.now(),En()},t)}function xn(t){switch(t.kind){case"assistant":return{text:t.text,thinking:t.thinking};case"tool":return{phase:t.phase,output:t.output,error:t.isError,durationMs:t.durationMs};case"approval":return{decided:t.decided,approvalState:t.approval.state};default:return{}}}function al(t,e){return t.text!==e.text||t.thinking!==e.thinking||t.phase!==e.phase||t.output!==e.output||t.error!==e.error||t.durationMs!==e.durationMs||t.decided!==e.decided||t.approvalState!==e.approvalState}function Sn(t){if(t.kind==="user"){let e=g("div","bv-msg bv-user");return e.appendChild(fn(t.text)),e}if(t.kind==="assistant"){let e=g("div","bv-msg bv-assistant");if(t.thinking){let i=g("details","bv-thinking");i.appendChild(g("summary",void 0,"thinking")),i.appendChild(g("div",void 0,t.thinking)),e.appendChild(i)}let n=g("div","bv-text");return n.appendChild(fn(t.text)),e.appendChild(n),e}return t.kind==="tool"?rl(t):t.kind==="approval"?ol(t):g("div",`bv-notice bv-notice-${t.level}`,t.text)}function ll(t,e){let n=t.querySelector("details.bv-thinking");if(e.thinking)if(n){let s=n.querySelector("div");s&&s.textContent!==e.thinking&&(s.textContent=e.thinking)}else{let s=g("details","bv-thinking");s.appendChild(g("summary",void 0,"thinking")),s.appendChild(g("div",void 0,e.thinking)),t.prepend(s)}else n&&n.remove();let i=t.querySelector(".bv-text");i&&i.replaceChildren(fn(e.text))}function En(){let t=document.getElementById("bots-messages");if(!t||!k.activeId||document.getElementById("bots-view")?.hidden)return;let e=k.items.get(k.activeId)||[],n=fe;if(e.length<Le.length||e.some((i,s)=>Le[s]?.item!==i))t.textContent="",Le=e.map(i=>{let s=Sn(i);return t.appendChild(s),{item:i,snapshot:xn(i),node:s}});else{for(let i=Le.length;i<e.length;i++){let s=e[i],l=Sn(s);t.appendChild(l),Le.push({item:s,snapshot:xn(s),node:l})}for(let i=0;i<e.length;i++){let s=e[i],l=Le[i],a=xn(s);if(al(l.snapshot,a)){if(s.kind==="assistant")ll(l.node,s);else{let r=Sn(s);l.node.replaceWith(r),l.node=r}l.snapshot=a}}}n&&(t.scrollTop=t.scrollHeight)}function rl(t){let e=g("details","bv-tool");e.open=t.phase!=="end"||!!t.isError;let n=g("summary"),i=g("span","bv-tool-name",t.name);if(n.appendChild(i),t.phase!=="end"&&n.appendChild(g("span","bv-tool-phase",t.phase)),t.isError&&n.appendChild(g("span","bv-tool-error","error")),typeof t.durationMs=="number"&&n.appendChild(g("span","bv-tool-meta",`${Math.round(t.durationMs)}ms`)),e.appendChild(n),t.args!==void 0){let s=g("pre","bv-pre");s.textContent=typeof t.args=="string"?t.args:JSON.stringify(t.args,null,2),e.appendChild(s)}if(t.output){let s=g("pre","bv-pre bv-output");s.textContent=t.output,e.appendChild(s)}return e}function ol(t){let e=g("div","bv-approval"),n=t.approval;if(e.appendChild(g("div","bv-approval-tag","Needs approval")),e.appendChild(g("div","bv-approval-title",n.title)),n.message){let p=g("pre","bv-pre bv-approval-detail");p.textContent=n.message,e.appendChild(p)}if(t.decided)return e.appendChild(g("div","bv-approval-decided",t.decided==="allowed"?"Allowed":"Denied")),e;let i=g("input","bv-reason");i.placeholder="reason (optional)",i.setAttribute("aria-label","Reason (optional)");let s=g("div","bv-approval-actions"),l=g("button","btn primary","Allow once"),a=/^Allow (.+?)\?$/.exec(n.title)?.[1],r=n.method==="confirm"?a&&a.length<=24?`Always allow ${a}`:"Always allow this tool":"Allow for this session",o=g("button","btn",r);o.hidden=n.method!=="confirm";let c=g("button","btn danger","Deny"),d=[l,o,c],m=async(p,h,f)=>{let b=f.textContent??"";for(let w of d)w.disabled=!0;f.textContent=p?"Allowing\u2026":"Denying\u2026";try{await j(`/api/bots/${n.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:n.id,allow:p,always:h,reason:i.value||void 0})}),t.decided=p?"allowed":"denied",De(),oe(!0)}catch(w){for(let y of d)y.disabled=!1;f.textContent=b,Pe({kind:"notice",level:"error",text:w instanceof Error?w.message:String(w)})}};return l.onclick=()=>void m(!0,!1,l),o.onclick=()=>void m(!0,!0,o),c.onclick=()=>void m(!1,!1,c),s.append(i,l,o,c),e.appendChild(s),e}function Ri(t){let e=String(t.type||""),n=k.activeId;if(!n)return;let i=k.items.get(n)||[];if(e==="snapshot")k.items.set(n,[]);else if(e==="user")fe=!0,Pe({kind:"user",text:String(t.text||"")});else if(e==="status"){let s=wn();s&&(s.status=String(t.status||s.status)),yn(),pl()}else if(e==="message"){let s=t.message;if(!s||String(s.role||"")!=="assistant")return;let l=cl(s),a=dl(s),r=i[i.length-1];r&&r.kind==="assistant"?(r.text=l||r.text,r.thinking=a||r.thinking):i.push({kind:"assistant",text:l,thinking:a}),k.items.set(n,i),De()}else if(e==="delta"){let s=String(t.kind||""),l=String(t.delta||""),a=i[i.length-1];(!a||a.kind!=="assistant")&&(i.push({kind:"assistant",text:"",thinking:""}),a=i[i.length-1]),a.kind==="assistant"&&(s==="text"?a.text+=l:s==="thinking"&&(a.thinking+=l)),k.items.set(n,i),De()}else if(e==="tool"){let s=String(t.callId||""),l=i.find(r=>r.kind==="tool"&&r.callId===s),a=String(t.phase||"start");l?(l.phase=a,a==="update"&&t.output&&(l.output=String(t.output)),a==="end"&&(t.output&&(l.output=String(t.output)),l.isError=t.isError===!0,typeof t.durationMs=="number"&&(l.durationMs=t.durationMs))):i.push({kind:"tool",callId:s,name:String(t.name||"tool"),args:t.args,output:t.output?String(t.output):void 0,isError:t.isError===!0,durationMs:typeof t.durationMs=="number"?t.durationMs:void 0,phase:a}),k.items.set(n,i),De()}else if(e==="approval"){let s=t.approval;if(!s)return;let l=i;for(let a=l.length-1;a>=0;a--){let r=l[a];if(r.kind==="approval"&&r.approval.id===s.id){r.approval=s,s.state!=="pending"&&(r.decided=s.state==="allowed"?"allowed":"denied"),k.items.set(n,l),De();return}}l.push({kind:"approval",approval:s}),k.items.set(n,l),De()}else e==="notice"&&Pe({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function cl(t){let e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="text"?String(n.text||""):"").join(""):String(t.text||"")}function dl(t){let e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="thinking"?String(n.thinking||""):"").join(""):""}async function oe(t=!1){try{let[e,n]=await Promise.all([j("/api/bots"),j("/api/bots/approvals")]);if(k.bots=e,k.approvals=n,At(),yn(),t&&k.activeId){let i=await j(`/api/bots/${k.activeId}/events?limit=300`);ul(i)}}catch{}}async function pl(){try{k.bots=await j("/api/bots"),At()}catch{}}function ul(t){if(k.activeId){k.items.set(k.activeId,[]);for(let e of t)Ri(e);En()}}function hl(){let t=g("div","bots-modal");t.id="bots-modal",t.hidden=!0;let e=g("div","bots-modal-card"),n=g("div","bots-modal-head"),i=g("span");i.id="bots-modal-title";let s=g("button","btn");s.innerHTML=ae("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>zt(),n.append(i,s);let l=g("div","bots-modal-body");l.id="bots-modal-body",e.append(n,l),t.appendChild(e),t.onclick=a=>{a.target===t&&zt()},document.body.appendChild(t)}function Cn(t){let e=document.getElementById("bots-modal"),n=document.getElementById("bots-modal-title"),i=document.getElementById("bots-modal-body");if(!e||!i)throw new Error("modal missing");return n&&(n.textContent=t),i.textContent="",e.hidden=!1,i}function zt(){let t=document.getElementById("bots-modal");t&&(t.hidden=!0)}async function ml(){return k.catalog||(k.catalog=await j("/api/bots/catalog")),k.catalog}async function Pi(){return k.templates=await j("/api/bots/templates"),k.templates}async function lt(){let t=Cn("Bot templates"),[e,n]=await Promise.all([ml(),Pi()]),i=g("div","bv-template-list");for(let o of n){let c=g("div","bv-template-row");c.appendChild(g("span","bv-template-name",o.manifest.name)),c.appendChild(g("span","bv-template-desc",o.manifest.description||""));let d=g("button","btn","Edit");d.onclick=()=>Di(t,e,o);let m=g("button","btn","Copy");m.title="Duplicate this template",m.onclick=()=>{let f=JSON.parse(JSON.stringify(o.manifest));f.name=`${o.manifest.name} copy`,j("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:f})}).then(()=>lt()).catch(b=>alert(b instanceof Error?b.message:String(b)))};let p=g("button","btn danger","Delete");p.onclick=()=>{confirm(`Delete template ${o.manifest.name}?`)&&j(`/api/bots/templates/${o.id}`,{method:"DELETE"}).then(()=>lt())};let h=g("span","bv-template-actions");h.append(d,m,p),c.appendChild(h),i.appendChild(c)}n.length===0&&i.appendChild(g("div","bots-empty","No templates yet")),t.appendChild(i);let s=g("div","bv-template-actions"),l=g("button","btn primary","New template");l.onclick=()=>Di(t,e,null);let a=g("button","btn","Export");a.title="Download templates + library as JSON",a.onclick=()=>{(async()=>{try{let o=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${gn()}`}});if(!o.ok)throw new Error(`HTTP ${o.status}`);let c=await o.blob(),d=document.createElement("a");d.href=URL.createObjectURL(c),d.download=`tmux-weblink-bots-${new Date().toISOString().slice(0,10)}.json`,d.click(),setTimeout(()=>URL.revokeObjectURL(d.href),2e3)}catch(o){alert(o instanceof Error?o.message:String(o))}})()};let r=g("button","btn","Import");r.title="Restore templates from a JSON bundle",r.onclick=()=>{let o=document.createElement("input");o.type="file",o.accept="application/json,.json",o.onchange=()=>{let c=o.files?.[0];c&&(async()=>{try{let d=JSON.parse(await c.text()),m=await j("/api/bots/import",{method:"POST",body:JSON.stringify(d)});alert(`Imported ${m.templates} templates, ${m.files} library files (${m.skipped} kept)`),await lt()}catch(d){alert(d instanceof Error?d.message:String(d))}})()},o.click()},s.append(l,a,r),t.appendChild(s)}function Ln(t,e,n){let i=g("div","bv-field");i.appendChild(g("label","bv-label",t));let s=g("div","bv-check-grid"),l=[];for(let a of e){let r=g("label","bv-check"),o=document.createElement("input");o.type="checkbox",o.checked=n.includes(a.id),r.append(o,g("span",void 0,a.label)),a.hint&&(r.title=a.hint),s.appendChild(r),l.push({id:a.id,input:o})}return i.appendChild(s),{element:i,get:()=>l.filter(a=>a.input.checked).map(a=>a.id)}}function Di(t,e,n){t.textContent="";let i=n?JSON.parse(JSON.stringify(n.manifest)):{name:"new-bot",description:""},s=g("input","bv-input");s.value=i.name,s.placeholder="Template name";let l=g("input","bv-input");l.value=i.description||"",l.placeholder="One line description";let a=g("textarea","bv-textarea");a.rows=6,a.value=i.system||"",a.placeholder="System prompt for this bot (written to SYSTEM.md)";let r=Ln("Skills",e.skills.map(x=>({id:x.id,label:x.name,hint:x.description})),i.skills||[]),o=Ln("Extensions (Pi builtins + library)",e.extensions.map(x=>({id:x.id,label:`${x.name}${x.kind==="builtin"?" (builtin)":""}`,hint:x.description})),(i.extensions||[]).map(x=>x.replace(/^.*\//,"").replace(/\.(js|ts)$/,""))),c=Ln("Prompt templates",e.prompts.map(x=>({id:x.id,label:x.name})),i.prompts||[]),d=g("select","bv-input");d.appendChild(new Option("none",""));for(let x of e.mcp)d.appendChild(new Option(x.name,x.id));i.mcp&&(d.value=e.mcp.find(x=>JSON.stringify(x.servers)===JSON.stringify(i.mcp?.mcpServers))?.id||"");let m=g("div","bv-field");m.appendChild(g("label","bv-label","Tools (allow list; deny always blocks)"));let p=g("div","bv-check-grid"),h=[];for(let x of e.tools){let F=g("label","bv-check"),B=document.createElement("input");B.type="checkbox",B.checked=(i.tools?.allow||[]).includes(x.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(x.name),F.append(B,g("span",void 0,x.name)),p.appendChild(F),h.push({name:x.name,input:B})}m.appendChild(p);let f=g("input","bv-input");f.value=(i.tools?.deny||[]).join(", "),f.placeholder="Always deny (comma separated), e.g. bash, write";let b=g("textarea","bv-textarea");b.rows=2,b.value=(i.packages||[]).join(`
|
|
86
|
+
`),b.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";let w=g("select","bv-input");w.appendChild(new Option("default (Pi settings)",""));for(let x of e.models)w.appendChild(new Option(`${x.provider}/${x.model}`,`${x.provider}
|
|
87
|
+
${x.model}`));i.model?.provider&&i.model?.id&&(w.value=`${i.model.provider}
|
|
88
|
+
${i.model.id}`);let y=g("select","bv-input");for(let x of["","off","minimal","low","medium","high","xhigh","max"])y.appendChild(new Option(x||"default",x));i.model?.thinking&&(y.value=i.model.thinking);let C=g("select","bv-input");for(let x of["supervised","auto-accept-edits","full-access"])C.appendChild(new Option(x,x));C.value=i.permissions?.runtimeMode||"supervised";let M=g("select","bv-input");M.appendChild(new Option("ignore project .pi (recommended)","ignore")),M.appendChild(new Option("inherit project .pi (needs trust)","inherit")),M.value=i.projectResources||"ignore";let T=g("label","bv-check"),I=document.createElement("input");I.type="checkbox",I.checked=!!i.orchestrator,T.append(I,g("span",void 0,"Super bot: gets orchestration tools (create/stop/status child bots)"));let $=(x,F)=>{let B=g("div","bv-field");return B.appendChild(g("label","bv-label",x)),B.appendChild(F),B};t.append($("Name",s),$("Description",l),$("System prompt",a),r.element,o.element,c.element,$("MCP preset",d),m,$("Always deny tools",f),$("Packages",b),$("Model",w),$("Thinking level",y),$("Approval mode",C),$("Project resources",M),T);let z=g("button","btn primary",n?"Save template":"Create template");z.onclick=async()=>{let[x,F]=w.value.split(`
|
|
89
|
+
`),B=e.mcp.find(A=>A.id===d.value),Z={name:s.value.trim()||"bot",description:l.value.trim()||void 0,system:a.value.trim()||void 0,skills:r.get(),extensions:o.get().map(A=>(A.startsWith("builtin:"),A)),prompts:c.get(),packages:b.value.split(`
|
|
90
|
+
`).map(A=>A.trim()).filter(Boolean),mcp:B?{mcpServers:B.servers}:void 0,tools:{allow:h.filter(A=>A.input.checked).map(A=>A.name),deny:f.value.split(",").map(A=>A.trim()).filter(Boolean)},model:x?{provider:x,id:F,thinking:y.value||void 0}:void 0,permissions:{runtimeMode:C.value},projectResources:M.value==="inherit"?"inherit":"ignore",orchestrator:I.checked||void 0};try{await j("/api/bots/templates",{method:"POST",body:JSON.stringify({id:n?.id,manifest:Z})}),zt(),await lt()}catch(A){alert(A instanceof Error?A.message:String(A))}},t.appendChild(z)}async function fl(){return Hi("")}async function Hi(t){let e=Cn("New bot"),n=await Pi();if(n.length===0){e.appendChild(g("div","bots-empty","No templates yet \u2014 create one with \u201CNew template\u201D."));return}let i=g("select","bv-input");for(let c of n)i.appendChild(new Option(c.manifest.name,c.id));let s=g("input","bv-input");s.placeholder="Title (defaults to template name)";let l=g("input","bv-input");l.placeholder="/path/to/project";let a=t||k.bots[0]?.projectPath||"";l.value=a;let r=g("select","bv-input");r.appendChild(new Option("shared \u2014 run in the project folder","shared")),r.appendChild(new Option("worktree \u2014 isolated git worktree","worktree")),e.append(Mt("Template",i),Mt("Title",s),Mt("Project path",l),Mt("Workspace",r));let o=g("button","btn primary","Create bot");o.onclick=async()=>{try{let c=await j("/api/bots",{method:"POST",body:JSON.stringify({templateId:i.value,title:s.value.trim()||void 0,projectPath:l.value.trim()||void 0,isolation:r.value})});zt(),await oe(!0),await Ai(c.id)}catch(c){alert(c instanceof Error?c.message:String(c))}},e.appendChild(o)}function Mt(t,e){let n=g("div","bv-field");return n.appendChild(g("label","bv-label",t)),n.appendChild(e),n}async function Tn(){let t=Cn("Needs you");if(k.approvals=await j("/api/bots/approvals"),k.approvals.length===0){t.appendChild(g("div","bots-empty","Nothing waiting."));return}for(let e of k.approvals){let n=g("div","bv-approval");if(n.appendChild(g("div","bv-approval-tag",e.botTitle)),n.appendChild(g("div","bv-approval-title",e.title)),e.message){let c=g("pre","bv-pre bv-approval-detail");c.textContent=e.message,n.appendChild(c)}let i=g("input","bv-reason");i.placeholder="reason (optional)",i.setAttribute("aria-label","Reason (optional)");let s=g("div","bv-approval-actions"),l=g("button","btn primary","Allow once"),a=g("button","btn danger","Deny"),r=[l,a],o=async(c,d)=>{let m=d.textContent??"";for(let p of r)p.disabled=!0;d.textContent=c?"Allowing\u2026":"Denying\u2026";try{await j(`/api/bots/${e.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:e.id,allow:c,reason:i.value||void 0})}),await oe(!0),await Tn()}catch(p){for(let h of r)h.disabled=!1;d.textContent=m,Pe({kind:"notice",level:"error",text:p instanceof Error?p.message:String(p)})}};l.onclick=()=>void o(!0,l),a.onclick=()=>void o(!1,a),s.append(i,l,a),n.appendChild(s),t.appendChild(n)}}function gl(){window.__botsInited||(window.__botsInited=!0,nl(),tl(),window.__openBot=Ai,document.addEventListener("click",t=>{let e=t.target;e&&(e.closest(".session-item.bot-item")||e.closest(".session-item")&&k.activeId&&setTimeout(()=>kn(),0))},!0),document.addEventListener("click",t=>{let e=t.target;!e||!k.activeId||(e.closest("#mode-files")||e.closest(".file-tree-item")||e.closest(".file-roots-list li"))&&kn()}),oe(!0),k.pollTimer=window.setInterval(()=>{document.hidden||oe()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(k.pollTimer)))}var rt=window.__TMUX_WEB_SHELL__,N=null,V=null,ot=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null,ee=ot;window.__tmuxWebScopeAgent=ot;var $n="sessions",we="",Bt="",Rt="",_i="";function K(t){return ee?"/a/"+encodeURIComponent(ee)+t:t}var D=document.getElementById("sidebar-content"),He=document.getElementById("main-placeholder"),ie=document.getElementById("terminal-container"),ct=document.getElementById("file-editor"),vl=document.getElementById("fe-path"),ce=document.getElementById("fe-status"),dt=document.getElementById("fe-content"),_e=document.getElementById("fe-save"),bl=document.getElementById("fe-delete"),kl=document.getElementById("fe-back"),Fi=document.getElementById("fe-new-name"),wl=document.getElementById("fe-new-btn"),In=document.getElementById("settings-backdrop"),Ni=document.getElementById("settings-popover"),Oi=document.querySelector(".sidebar"),qi="tmux-web-force-narrow";function Pt(){try{return localStorage.getItem(qi)==="1"}catch{return!1}}function ji(){document.documentElement.classList.toggle("force-narrow",Pt()),Pt()&&Vi()&&pt()}function Vi(){return Pt()?!0:window.matchMedia("(max-width: 640px)").matches}function pt(){Vi()&&Oi.classList.add("collapsed")}function Wi(){Oi.classList.remove("collapsed")}window.__collapseSidebar=pt,document.getElementById("mode-sessions").addEventListener("click",()=>{Wi(),Ui("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{Wi(),Ui("files")});function Ui(t){$n=t,document.querySelectorAll(".mode-btn").forEach(n=>n.classList.remove("active"));let e=document.getElementById(t==="sessions"?"mode-sessions":"mode-files");e&&e.classList.add("active"),t==="sessions"?(An="",ye()):Pl()}var An="";async function ye(){if($n!=="sessions")return;try{let e=await(await fetch("/api/sidebar/sessions")).json(),n=(window.__botsSnapshot||[]).map(s=>[s.id,s.title,s.status,s.projectPath]),i=JSON.stringify({recent:e.recent,agents:e.agents,tombstones:e.tombstones,bots:n});if(i===An)return;An=i,Ll(e)}catch{D.innerHTML+='<div class="file-tree-empty">Failed to load sessions</div>'}let t=document.getElementById("ns-btn");t&&t.addEventListener("click",()=>{let e=window.__openNewSessionModal;typeof e=="function"?e():document.getElementById("new-session-modal")?.classList.add("open")}),Hn()}var Ji="tmux-web-sidebar-group-collapsed";function Zi(){try{return new Set(JSON.parse(localStorage.getItem(Ji)||"[]"))}catch{return new Set}}function yl(t){try{localStorage.setItem(Ji,JSON.stringify([...t]))}catch{}}function xl(t,e,n){if(!t)return"\u2026";let i=n&&(t===n||t.startsWith(n+"/"))?"~"+t.slice(n.length):t,s=i.split("/").filter(Boolean);if(s.length===0)return t;for(let l=1;l<=s.length;l++){let a=s.slice(-l).join("/");if(!e.some(r=>!r||r===t?!1:(n&&(r===n||r.startsWith(n+"/"))?"~"+r.slice(n.length):r).split("/").filter(Boolean).slice(-l).join("/")===a))return a}return i}function Sl(t){let e=document.createElement("div");e.className="session-item bot-item",e.setAttribute("data-bot-id",t.id),e.title=`Bot \xB7 ${t.projectPath}`;let n=t.status==="running"?"var(--panel-success)":t.status==="waiting_approval"||t.status==="waiting_input"?"#e0a23c":t.status==="failed"?"var(--panel-danger, #e5534b)":"var(--panel-muted)";return e.innerHTML=`${ae("bot",'class="bot-icon"')}<span>${H(t.title)}</span><span class="bot-status-dot" style="background:${n}"></span>`,e.addEventListener("click",i=>{i.stopPropagation(),window.__openBot?.(t.id)}),e}function Yi(t,e,n,i=!0){let s=new Map;for(let c of t){let d=c.path||"";s.has(d)||s.set(d,[]),s.get(d).push(c)}let l=n?[]:window.__botsSnapshot||[],a=new Map;for(let c of l)s.has(c.projectPath)||s.set(c.projectPath,[]),a.has(c.projectPath)||a.set(c.projectPath,[]),a.get(c.projectPath).push(c);let r=[...s.keys()],o=Zi();for(let[c,d]of s){let m=xl(c,r,e),p=o.has(c),h=document.createElement("div");if(h.className="session-group-header"+(p?" collapsed":""),h.title=c||"No working directory",h.innerHTML=`<span class="sg-folder">📁</span><span class="sg-label">${H(m)}</span>`,!n&&c){let b=document.createElement("button");b.className="sg-add-bot",b.innerHTML=ae("add",'width="12" height="12"'),b.title=`New bot in ${c}`,b.addEventListener("click",w=>{w.stopPropagation(),Mn(c)}),h.appendChild(b)}h.addEventListener("click",()=>{let b=Zi(),w=h.nextElementSibling;b.has(c)?(b.delete(c),h.classList.remove("collapsed"),w?.classList.remove("collapsed")):(b.add(c),h.classList.add("collapsed"),w?.classList.add("collapsed")),yl(b)});let f=document.createElement("div");f.className="session-group-body"+(p?" collapsed":"");for(let b of d)f.appendChild(n?El(b,n,i):Cl(b));for(let b of a.get(c)||[])f.appendChild(Sl(b));D.appendChild(h),D.appendChild(f)}}function El(t,e,n){let i=document.createElement("div");i.className="session-item"+(t.name===V&&ee===e?" active":"")+(n?"":" session-offline"),i.setAttribute("data-session",t.name),i.setAttribute("data-agent",e),i.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${t.attached?"M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 14H5V6h14v12z":"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"}"></svg>
|
|
91
|
+
<span>${H(t.name)}</span>${n?"":'<span class="meta">offline</span>'}
|
|
92
|
+
<button class="session-edit-btn" data-session="${H(t.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>`,n&&i.addEventListener("click",l=>{l.target.closest(".session-edit-btn")||ut(t.name,e)});let s=i.querySelector(".session-edit-btn");return s&&s.addEventListener("click",l=>{l.stopPropagation(),Wt(t.name,s,{agentId:e})}),i}function Cl(t){let e=document.createElement("div");e.className="session-item"+(t.name===V&&!ee?" active":""),e.setAttribute("data-session",t.name),e.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${t.attached?"M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 14H5V6h14v12z":"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"}"></svg>
|
|
93
|
+
<span>${H(t.name)}</span>
|
|
94
|
+
<button class="session-edit-btn" data-session="${H(t.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>
|
|
95
|
+
`,e.addEventListener("click",i=>{i.target.closest(".session-edit-btn")||ut(t.name)});let n=e.querySelector(".session-edit-btn");return n&&n.addEventListener("click",i=>{i.stopPropagation(),Wt(t.name,n)}),e}function Ll(t){D.innerHTML='<button class="new-session-sidebar-btn" id="ns-btn">+ New Session</button>';let e=t.recent||[],n=document.createElement("div");n.className="sidebar-section-label"+(ot?" clickable":""),n.textContent=ot?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",ot&&(n.title="Back to hub",n.addEventListener("click",()=>{window.location.href="/"})),D.appendChild(n),Yi(e,t.home);let i=t.agents||[];for(let l of i){if(!l.sessions||l.sessions.length===0)continue;let a=l.agentId===ee,r=document.createElement("div");r.className="sidebar-section-label machine-label"+(l.online?"":" agent-offline-label")+(!a&&l.online?" clickable":""),r.textContent=l.agentName+(l.online?"":" (offline)"),!a&&l.online&&(r.title="\u6253\u5F00 "+l.agentName,r.addEventListener("click",()=>{window.location.href="/a/"+encodeURIComponent(l.agentId)+"/"})),D.appendChild(r),Yi(l.sessions,t.home,l.agentId,l.online)}let s=t.tombstones||[];if(s.length>0){let l=document.createElement("div");l.className="sidebar-section-label tombstone-label",l.textContent="\u5931\u6548\u4F1A\u8BDD",D.appendChild(l);for(let a of s){let r=document.createElement("div");r.className="session-item session-tombstone",r.setAttribute("data-session",a.name),a.agentId&&r.setAttribute("data-agent",a.agentId);let o=a.agentId?a.agentOnline?" (agent)":" (agent \u79BB\u7EBF)":"";r.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"></svg>
|
|
96
|
+
<span>${H(a.name)}</span><span class="meta">\u5931\u6548${o}</span>
|
|
97
|
+
<button class="session-edit-btn" data-session="${H(a.name)}" title="\u6062\u590D\u4F1A\u8BDD"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>`,r.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",r.addEventListener("click",()=>{Wt(a.name,r,{tombstone:!0,agentId:a.agentId})});let c=r.querySelector(".session-edit-btn");c&&c.addEventListener("click",d=>{d.stopPropagation(),Wt(a.name,c,{tombstone:!0,agentId:a.agentId})}),D.appendChild(r)}}}function H(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function ut(t,e){if(V===t&&N&&ee===(e||null))return;ct.style.display="none",He.style.display="none",ie.style.display="",ie.classList.add("terminal-pending"),pt(),N&&(jt(),N.destroy(),N=null),V=t,ee=e||null,window.__tmuxWebScopeAgent=ee,window.__tmuxWebCurrentSession=V,Kl(t,e);let n=Dn(t,e);ds.set(n,Date.now()+Yl);let i=Je.get(n);if(i&&i.state==="working"){i.state="idle",i.doneUntil=void 0,i.unread=!1;let s=D.querySelector(e?'.session-item[data-agent="'+CSS.escape(e)+'"][data-session="'+CSS.escape(t)+'"]':'.session-item[data-session="'+CSS.escape(t)+'"]:not([data-agent])');s&&Xt(s,n,i)}for(let s of D.querySelectorAll(".session-item"))s.classList.toggle("active",s.getAttribute("data-session")===t&&(s.getAttribute("data-agent")||null)===ee);try{N=await Ds(ie,t,{terminal:rt.terminal,scrollback:rt.scrollback,theme:rt.theme,wsBase:ee?"/ws/a/"+encodeURIComponent(ee):rt.wsBase||"/ws"}),as()}catch(s){console.error("[shell] terminal init failed:",s);let l=s&&typeof s=="object"&&"message"in s?s.message:String(s);ie.textContent="Failed to open terminal for "+t+": "+l,ie.classList.remove("terminal-pending")}}var Dt=[],J=null,Xi=!1;function Tl(t){if(!J||!J.files.length)return null;let e=J.repoRoot;if(!e||!t.startsWith(e))return null;let n=t.slice(e.length+1);for(let i of J.files)if(i.path===n)return i.status;return null}async function $l(t){Xi=!0;try{let e=await fetch(K("/api/git/status?path="+encodeURIComponent(t)));e.ok?J=await e.json():J=null}catch{J=null}finally{Xi=!1}}function Il(){if(!J||!J.branch)return"";let{branch:t,linesAdded:e,linesRemoved:n}=J,i=`<div class="sidebar-git"><div class="git-branch-badge">
|
|
98
98
|
<svg viewBox="0 0 16 16" fill="currentColor"><path d="M11.63 1.22a.75.75 0 00-1.06 0L5.99 5.8 4.12 3.93a.75.75 0 10-1.06 1.06L4.93 6.87A3.5 3.5 0 003 10.09v3.16a.75.75 0 001 0v-3.16a2.5 2.5 0 012.5-2.5h.27l-1.06 1.06a.75.75 0 001.06 1.06l2.37-2.38a.75.75 0 000-1.06L7.59 5.27l4.04-4.05a.75.75 0 000-1.06L11.63 1.22zM3.25 13.94a.75.75 0 01-.75-.75v-.69a.75.75 0 011.5 0v.69c0 .414-.336.75-.75.75z"/></svg>
|
|
99
|
-
${
|
|
100
|
-
<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>`;else{let e=`<div class="git-popover-header">${t.length} file${t.length>1?"s":""} changed</div>`;for(let n=0;n<t.length;n++){let i=t[n],s=i.additions||0,l=i.deletions||0,
|
|
101
|
-
${
|
|
99
|
+
${H(t)}</div>`;return(e>0||n>0)&&(i+=`<div class="git-diff-stats">+<span class="add">${e}</span> <span class="del">-${n}</span></div>`),i+"</div>"}D.addEventListener("click",t=>{t.target.closest(".sidebar-git")&&We&&J&&(t.stopPropagation(),ts())});var ht=document.getElementById("header-git"),Ki=document.getElementById("git-diff-view"),Qi=document.getElementById("gd-path"),Ht=document.getElementById("gd-status"),_t=document.getElementById("gd-content"),Al=document.getElementById("gd-back"),We=null;function mt(t){if(!t||!t.branch){ht.style.display="none",We=null;return}We=t.repoRoot;let{branch:e,linesAdded:n,linesRemoved:i}=t,s=`<span class="branch">${H(e)}</span>`;(n>0||i>0)&&(s+=`<span class="sep">\xB7</span>+<span class="diff-add">${n}</span> <span class="diff-del">-${i}</span>`),ht.innerHTML=s,ht.style.display="block"}ht.addEventListener("click",t=>{We&&J&&(t.stopPropagation(),ts())});var te=document.getElementById("git-popover"),Ft=document.getElementById("git-popover-backdrop");function zn(){let t=ht.getBoundingClientRect();te.style.top=t.bottom+4+"px",te.style.left=Math.max(8,Math.min(t.left,window.innerWidth-400))+"px"}function Gi(){let t=We,e=document.getElementById("git-popover-browse");e&&e.addEventListener("click",()=>{if(Ot(),t){$n="files",document.querySelectorAll(".mode-btn").forEach(i=>i.classList.remove("active"));let n=document.getElementById("mode-files");n&&n.classList.add("active"),xe(t)}})}var es="";function ts(){if(!J)return;let t=J.files||[];if(!t.length)te.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
|
|
100
|
+
<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>`;else{let e=`<div class="git-popover-header">${t.length} file${t.length>1?"s":""} changed</div>`;for(let n=0;n<t.length;n++){let i=t[n],s=i.additions||0,l=i.deletions||0,a="";switch(i.status){case"M":a='<span class="git-file-status M">M</span>';break;case"A":a='<span class="git-file-status A">A</span>';break;case"D":a='<span class="git-file-status D">D</span>';break;case"?":a='<span class="git-file-status ?">?</span>';break;case"R":a='<span class="git-file-status R">R</span>';break}e+=`<div class="git-popover-item" data-idx="${n}">
|
|
101
|
+
${a}<span class="file-path">${H(i.path)}</span>
|
|
102
102
|
<span class="file-add">${s>0?"+"+s:""}</span>
|
|
103
103
|
<span class="file-del">${l>0?"-"+l:""}</span>
|
|
104
|
-
</div>`}e+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',
|
|
104
|
+
</div>`}e+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',es=e,te.innerHTML=e,te.querySelectorAll(".git-popover-item").forEach(n=>{let i=parseInt(n.dataset.idx||"0",10),s=t[i];!s||s.status==="D"||(n.classList.add("clickable"),n.style.cursor="pointer",n.addEventListener("click",()=>is(s.path)))})}zn(),te.classList.add("open"),Ft.classList.add("open"),Gi()}function zl(){return window.innerWidth>=1024}function ns(t,e){let n=(t+(e&&t?`
|
|
105
105
|
`:"")+e).split(`
|
|
106
|
-
`),i="",s=0,l=0;for(let
|
|
106
|
+
`),i="",s=0,l=0;for(let a of n){let r=a;if(r.startsWith("@@")){let o=r.match(/@@\s+-(\d+)[^+]*\+(\d+)/);o&&(s=parseInt(o[1],10)-1,l=parseInt(o[2],10)-1),i+=`<div class="diff-line hunk"><span class="ln-body">${H(r)}</span></div>`;continue}if(r.startsWith("diff --git")||r.startsWith("index ")||r.startsWith("--- ")||r.startsWith("+++ ")||r.startsWith("new file")||r.startsWith("deleted file")){r.startsWith("diff --git")&&(i+=`<div class="diff-line header"><span class="ln-body">${H(r)}</span></div>`);continue}if(r.startsWith("+"))l++,i+=`<div class="diff-line add"><span class="ln-no">${l}</span><span class="ln-body">${H(r)}</span></div>`;else if(r.startsWith("-"))s++,i+=`<div class="diff-line del"><span class="ln-no">${s}</span><span class="ln-body">${H(r)}</span></div>`;else if(r.startsWith("\\"))i+=`<div class="diff-line"><span class="ln-body">${H(r)}</span></div>`;else{if(!r&&!s&&!l)continue;s++,l++,i+=`<div class="diff-line"><span class="ln-no">${s}</span><span class="ln-no" style="margin-right:12px">${l}</span><span class="ln-body">${H(r)}</span></div>`}}return{html:i,lineCount:n.length}}var Nt=null;async function is(t){let e=We;if(e)if(Ot(),zl()){ie.style.display="none",N&&(jt(),N.destroy(),N=null,Nt=V,V=null),mt(null),ct.style.display="none",He.style.display="none",Ki.style.display="flex",Qi.textContent=t,Ht.textContent="Loading\u2026",_t.innerHTML="";try{let n=await fetch(K("/api/git/diff?path="+encodeURIComponent(e)+"&file="+encodeURIComponent(t)));if(!n.ok)throw new Error(await n.text());let i=await n.json();Bl(t,i.diff,i.stagedDiff)}catch(n){let i=n instanceof Error?n.message:String(n);Ht.textContent="Error",_t.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${H(i)}</div>`}}else{te.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
107
107
|
<button class="diff-back">\u2190 Back</button>
|
|
108
|
-
<span class="diff-filename">${
|
|
108
|
+
<span class="diff-filename">${H(t)}</span>
|
|
109
109
|
<span class="diff-loading">Loading\u2026</span>
|
|
110
|
-
</div></div>`,
|
|
110
|
+
</div></div>`,zn(),te.classList.add("open"),Ft.classList.add("open");try{let n=await fetch(K("/api/git/diff?path="+encodeURIComponent(e)+"&file="+encodeURIComponent(t)));if(!n.ok)throw new Error(await n.text());let i=await n.json();Ml(t,i.diff,i.stagedDiff)}catch(n){let i=n instanceof Error?n.message:String(n);te.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
111
111
|
<button class="diff-back">\u2190 Back</button>
|
|
112
|
-
<span class="diff-filename">${
|
|
113
|
-
</div><div class="diff-empty">Error loading diff: ${
|
|
112
|
+
<span class="diff-filename">${H(t)}</span>
|
|
113
|
+
</div><div class="diff-empty">Error loading diff: ${H(i)}</div></div>`}}}function Ml(t,e,n){if(!e&&!n){te.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
114
114
|
<button class="diff-back">\u2190 Back</button>
|
|
115
|
-
<span class="diff-filename">${
|
|
116
|
-
</div><div class="diff-empty">No diff content available</div></div>`;return}let{html:i,lineCount:s}=
|
|
115
|
+
<span class="diff-filename">${H(t)}</span>
|
|
116
|
+
</div><div class="diff-empty">No diff content available</div></div>`;return}let{html:i,lineCount:s}=ns(e,n);te.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
117
117
|
<button class="diff-back">\u2190 Back</button>
|
|
118
|
-
<span class="diff-filename">${
|
|
118
|
+
<span class="diff-filename">${H(t)}</span>
|
|
119
119
|
<span class="diff-filesize">${s} lines</span>
|
|
120
|
-
</div><div class="diff-content">${i}</div></div>`,
|
|
120
|
+
</div><div class="diff-content">${i}</div></div>`,te.querySelector(".diff-back")?.addEventListener("click",()=>{te.innerHTML=es,zn(),J&&te.querySelectorAll(".git-popover-item").forEach(l=>{let a=parseInt(l.dataset.idx||"0",10),r=J.files[a];!r||r.status==="D"||(l.style.cursor="pointer",l.addEventListener("click",()=>is(r.path)))}),Gi()})}function Bl(t,e,n){if(!e&&!n){Ht.textContent="No diff",_t.innerHTML='<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">No diff content available</div>';return}let{html:i,lineCount:s}=ns(e,n);Qi.textContent=t,Ht.textContent=s+" lines",_t.innerHTML=i}function Rl(){Ki.style.display="none",Nt?(ie.style.display="",ie.classList.add("terminal-pending"),ut(Nt),Nt=null):V?(ie.style.display="",ie.classList.add("terminal-pending"),as()):He.style.display="flex"}Al.addEventListener("click",Rl);function Ot(){te.classList.remove("open"),Ft.classList.remove("open")}Ft.addEventListener("click",Ot),document.addEventListener("keydown",t=>{t.key==="Escape"&&(Ot(),Yt())});async function ss(t){try{let e=await(await fetch("/api/fs/session-path?session="+encodeURIComponent(t))).json();if(e.path){let n=await fetch("/api/git/status?path="+encodeURIComponent(e.path));if(n.ok){let i=await n.json();J=i,mt(i);return}}}catch{}J=null,mt(null)}var qt=null;function as(){jt(),V&&(ss(V),qt=setInterval(()=>{V&&ss(V)},3e4))}function jt(){qt&&(clearInterval(qt),qt=null)}async function Mn(t){let e=t;if(e.startsWith("~"))try{let n=await(await fetch(K("/api/fs/list?path="+encodeURIComponent(e)))).json();typeof n.path=="string"&&n.path&&(e=n.path)}catch{}e=e.replace(/\/+$/,"")||"/",Hi(e)}function ls(t,e){let n=document.createElement("button");n.className="file-tree-bot-btn",n.innerHTML=ae("add",'width="12" height="12"'),n.title=`Create bot in ${e}`,n.setAttribute("aria-label",`Create bot in ${e}`),n.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),Mn(e)}),t.appendChild(n)}function Pl(){if(Dt=rt.fsRoots||[],Dt.length===0){if(V){Dl(V);return}xe("");return}D.innerHTML="";for(let t of Dt){let e=document.createElement("div");e.className="file-tree-item",e.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${H(t)}`,e.addEventListener("click",()=>xe(t)),ls(e,t),D.appendChild(e)}}async function Dl(t){D.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let e=await(await fetch(K("/api/fs/session-path?session="+encodeURIComponent(t)))).json();e.path?xe(e.path):D.innerHTML='<div class="file-tree-info">Could not determine session directory.</div>'}catch{D.innerHTML='<div class="file-tree-error">Failed to get session directory</div>'}}async function xe(t){we=t,D.innerHTML='<div class="file-tree-empty">Loading...</div>';let e=$l(t);try{let n=await(await fetch(K("/api/fs/list?path="+encodeURIComponent(t)))).json(),i=typeof n.path=="string"&&n.path?n.path:t;if(i&&(we=i),await e,D.innerHTML="",i){let a=document.createElement("div");a.className="file-tree-item file-tree-create-bot",a.innerHTML=`<span class="file-tree-bot-plus">${ae("add",'width="11" height="11"')}</span> Create bot in this folder`,a.title=`Create bot in ${i}`,a.addEventListener("click",()=>void Mn(i)),D.appendChild(a)}mt(J),D.innerHTML+=Il();let s=Hl(i||t);if(s&&!Dt.some(a=>i===a)){let a=document.createElement("div");a.className="file-tree-item",a.innerHTML="..",a.addEventListener("click",()=>xe(s)),D.appendChild(a)}if(n.dirs)for(let a of n.dirs){let r=a.split("/").pop()||a.split("\\").pop(),o=document.createElement("div");o.className="file-tree-item",o.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${H(r)}`,o.addEventListener("click",()=>xe(a)),ls(o,a),D.appendChild(o)}else D.innerHTML="";let l=n.files||[];for(let a of l){let r=a.split("/").pop()||a.split("\\").pop(),o=Tl(a),c="",d="";if(o)switch(o){case"M":c="git-mod",d='<span class="git-file-status M">M</span>';break;case"A":c="git-add",d='<span class="git-file-status A">A</span>';break;case"D":c="git-del",d='<span class="git-file-status D">D</span>';break;case"?":c="git-untracked",d='<span class="git-file-status ?">?</span>';break;case"R":c="git-mod",d='<span class="git-file-status R">R</span>';break}let m=document.createElement("div");m.className="file-tree-item file"+(c?" "+c:""),m.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${d}${H(r)}`,m.addEventListener("click",()=>_l(a)),D.appendChild(m)}}catch{D.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function Hl(t){let e=t.lastIndexOf("/");return e<=0?null:t.substring(0,e)}async function _l(t){Bt=t,ie.style.display="none",N&&(jt(),N.destroy(),N=null,V=null),mt(null),pt(),He.style.display="none",ct.style.display="flex",vl.textContent=t,ce.textContent="Loading...",_e.style.display="none";try{let e=await fetch(K("/api/file?path="+encodeURIComponent(t)));if(!e.ok){let i=await e.json();ce.textContent=i.error||"Failed to load",dt.value="";return}let n=await e.json();dt.value=n.content,Rt=n.content,_i=n.content,ce.textContent=n.size+" bytes",_e.style.display=""}catch{ce.textContent="Failed to load",dt.value=""}}dt.addEventListener("input",()=>{Rt=dt.value}),_e.addEventListener("click",async()=>{_e.textContent="Saving...",_e.disabled=!0;try{let t=await fetch(K("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Bt,content:Rt})});if(!t.ok){let e=await t.json();ce.textContent=e.error||"Save failed";return}_i=Rt,ce.textContent="Saved"}catch{ce.textContent="Save failed"}finally{_e.disabled=!1,_e.textContent="Save"}}),bl.addEventListener("click",async()=>{if(confirm("Delete "+Bt+"?"))try{let t=await fetch(K("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Bt})});if(!t.ok){let e=await t.json();ce.textContent=e.error||"Delete failed";return}ct.style.display="none",He.style.display="flex",we&&xe(we)}catch{ce.textContent="Delete failed"}}),kl.addEventListener("click",()=>{ct.style.display="none",He.style.display="flex",we&&xe(we)}),wl.addEventListener("click",async()=>{let t=Fi.value.trim();if(!t)return;let e=we+"/"+t;try{let n=await fetch(K("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})});if(!n.ok){let i=await n.json();ce.textContent=i.error||"Create failed";return}Fi.value="",we&&xe(we)}catch{ce.textContent="Create failed"}});var Vt=document.getElementById("force-narrow-toggle");Vt&&(Vt.checked=Pt(),Vt.addEventListener("change",()=>{try{localStorage.setItem(qi,Vt.checked?"1":"0")}catch{}ji(),ye()})),ji(),document.getElementById("mode-settings").addEventListener("click",()=>{let t=Ni.classList.toggle("open");In.classList.toggle("open",t)}),In.addEventListener("click",()=>{Ni.classList.remove("open"),In.classList.remove("open")});var se="",de=!1,pe,ft=document.createElement("div");ft.className="session-popover-backdrop",document.body.appendChild(ft);var ue=document.createElement("div");ue.id="session-popover",ue.className="session-popover",ue.style.display="none",ue.innerHTML=`<div class="sp-field">
|
|
121
121
|
<label>Rename session</label>
|
|
122
122
|
<input type="text" id="sp-name" />
|
|
123
123
|
</div>
|
|
@@ -127,5 +127,5 @@ ${i.model.id}`);let k=g("select","bv-input");for(let E of["","off","minimal","lo
|
|
|
127
127
|
<button class="btn danger sp-delete" id="sp-delete">Delete</button>
|
|
128
128
|
</div>
|
|
129
129
|
<hr class="sp-divider" id="sp-divider" />
|
|
130
|
-
<button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>`,document.body.appendChild(
|
|
131
|
-
`).length;
|
|
130
|
+
<button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>`,document.body.appendChild(ue);function Fl(t){let e=t.getBoundingClientRect(),n=window.innerHeight,i=ue.offsetHeight||240,s=e.bottom+4;s+i>n-8&&(s=Math.max(8,e.top-i-4)),ue.style.top=s+"px",ue.style.left=Math.max(8,Math.min(e.left,window.innerWidth-240))+"px"}function Wt(t,e,n){se=t,de=!!n?.tombstone,pe=n?.agentId;let i=document.getElementById("sp-name");i.value=t;let s=ue.querySelector(".sp-field label");s.textContent=de?"\u91CD\u547D\u540D (\u4EC5\u8BB0\u5F55\uFF0C\u4E0D\u91CD\u5EFA)":"Rename session";let l=document.getElementById("sp-rebuild");l.style.display=de?"":"none";let a=document.getElementById("sp-delete");a.textContent=de?"\u5220\u9664\u8BB0\u5F55":"Delete",a.title=de?"\u5220\u9664\u5931\u6548\u8BB0\u5F55\uFF08\u5893\u7891\u6D88\u5931\uFF09":"Delete session";let r=document.getElementById("sp-divider");r&&(r.style.display=de?"":"none");let o=document.getElementById("sp-save");o.textContent=de?"\u91CD\u547D\u540D":"Save",ft.classList.add("open"),ue.style.display="block",Fl(e),setTimeout(()=>i.focus(),50)}function Fe(){ft.classList.remove("open"),ue.style.display="none"}ft.addEventListener("click",Fe),document.getElementById("sp-save").addEventListener("click",async()=>{let t=document.getElementById("sp-name").value.trim();if(!t||t===se){Fe();return}try{let e=de?{oldName:se,newName:t,agentId:pe}:{oldName:se,newName:t,...pe?{agentId:pe}:{}};if(!(await fetch(K(de?"/api/sessions/rename-tombstone":"/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok)return;Fe(),ye(),!de&&V===se&&(pe??null)===ee&&ut(t,pe)}catch{}}),document.getElementById("sp-rebuild").addEventListener("click",async()=>{if(confirm('\u91CD\u5EFA\u4F1A\u8BDD "'+se+'" (\u540C\u540D\u540C\u8DEF\u5F84\uFF0C\u5185\u5BB9\u4E3A\u7A7A)\uFF1F'))try{let t=await fetch(K("/api/sessions/rebuild"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:se,agentId:pe})});if(!t.ok){let e=await t.json();alert(e.error||"\u91CD\u5EFA\u5931\u8D25");return}Fe(),ye()}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(de){if(!confirm('\u5220\u9664\u5931\u6548\u8BB0\u5F55 "'+se+'"\uFF1F'))return;try{if(!(await fetch(K("/api/sessions/dismiss"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:se,agentId:pe})})).ok)return;Fe(),ye()}catch{}return}if(confirm('Delete session "'+se+'"?'))try{if(!(await fetch(K("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:se,...pe?{agentId:pe}:{}})})).ok)return;Fe(),V===se&&(pe??null)===ee&&(N&&(N.destroy(),N=null),V=null,ie.style.display="none",He.style.display="flex"),ye()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",Fe);var rs={esc:"\x1B",tab:" ","s-tab":"\x1B[Z",up:"\x1B[A",down:"\x1B[B",left:"\x1B[D",right:"\x1B[C",space:" ",enter:"\r","ctrl-r":"","ctrl-c":"",btw:"/btw ",yes:"yes\r"},Ut=document.getElementById("mobile-keys"),Nl=new Set(["up","down","left","right","tab","s-tab","space"]),Ol=400,ql=80,gt=0,Jt=0,Zt=!1;function jl(){gt&&(clearTimeout(gt),gt=0),Jt&&(clearInterval(Jt),Jt=0)}Ut.addEventListener("mousedown",t=>{t.target.closest("button[data-key]")&&t.preventDefault()}),Ut.addEventListener("pointerdown",t=>{let e=t.target.closest("button[data-key]");if(!e)return;let n=e.dataset.key;Nl.has(n)&&(Zt=!1,gt=setTimeout(()=>{gt=0,Zt=!0,Jt=setInterval(()=>{let i=rs[n];i&&N&&N.sendInput(i)},ql)},Ol))});for(let t of["pointerup","pointercancel","pointerleave"])Ut.addEventListener(t,jl);Ut.addEventListener("click",t=>{let e=t.target.closest("button[data-key]");if(!e||!N)return;if(Zt){Zt=!1;return}let n=rs[e.dataset.key];n&&(N.sendInput(n),N.focus())});var ge=document.getElementById("mk-input"),os=document.getElementById("mk-send");function cs(){if(!ge||!N)return;let t=ge.value;t&&(N.sendInput(t+"\r"),ge.value="",ge.rows=1,N.focus())}if(ge&&(ge.addEventListener("input",()=>{ge.rows=1;let t=ge.value.split(`
|
|
131
|
+
`).length;ge.rows=Math.min(t,4)}),ge.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),cs())})),os&&os.addEventListener("click",cs),window.visualViewport){let t=document.querySelector(".app-layout"),e=()=>{t&&(t.style.height=window.visualViewport.height+"px"),window.scrollTo(0,0),document.documentElement.scrollTop=0,document.body.scrollTop=0};window.visualViewport.addEventListener("resize",e),window.addEventListener("orientationchange",()=>setTimeout(e,100)),document.addEventListener("touchstart",()=>{(window.scrollY>0||document.documentElement.scrollTop>0)&&window.scrollTo(0,0)},{passive:!0})}var Bn=document.getElementById("process-panel"),vt=document.getElementById("proc-list"),Vl=document.getElementById("proc-close"),Rn=document.getElementById("proc-backdrop"),Wl=document.getElementById("header-ram");function Ul(){vt.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(K("/api/system/processes")).then(t=>t.json()).then(t=>{if(!Array.isArray(t)||!t.length){vt.innerHTML='<div class="proc-empty">No processes</div>';return}let e="";for(let n of t){let i=n.rss,s=i<1048576?(i/1024).toFixed(0)+"K":(i/1048576).toFixed(1)+"M";e+='<div class="proc-row" data-pid="'+n.pid+'"><span class="proc-mem">'+n.mem+'%</span><span class="proc-rss">'+s+'</span><span class="proc-cmd" title="'+H(n.command)+'">'+H(n.command)+'</span><button class="proc-kill" title="Kill PID '+n.pid+'">×</button></div>'}vt.innerHTML=e;for(let n of vt.querySelectorAll(".proc-row")){let i=n.querySelector(".proc-kill");i&&i.addEventListener("click",s=>{let l=s.target.closest(".proc-row");!l||!confirm("Kill PID "+l.dataset.pid+"?")||fetch(K("/api/system/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:parseInt(l.dataset.pid,10)})}).then(a=>a.json()).then(a=>{a.ok?l.style.opacity="0.3":alert("Failed: "+(a.error||"unknown"))}).catch(()=>alert("Network error"))})}}).catch(()=>{vt.innerHTML='<div class="proc-empty">Failed to load</div>'})}function Jl(){Bn.classList.add("open"),Rn.classList.add("open"),Ul()}function Yt(){Bn.classList.remove("open"),Rn.classList.remove("open")}Wl.addEventListener("click",t=>{t.stopPropagation(),Bn.classList.contains("open")?Yt():Jl()}),Vl.addEventListener("click",Yt),Rn.addEventListener("click",Yt);var Zl=2e3,bt=null,Pn=null,Ue=new Map,Je=new Map,Yl=5e3,ds=new Map;function Dn(t,e){return(e?"a:"+e+":":"l:")+t}function Xl(t,e,n){let i=Dn(t,e);if(n==="working"){let c=ds.get(i);if(c&&Date.now()<c)return}let s=Je.get(i),l=t===V&&(e??null)===ee,a=n==="idle"&&s?.state==="working";Je.set(i,{session:t,agentId:e,state:n,doneUntil:a?Date.now()+Zl:void 0,unread:a?!l:!1});let r=e?'.session-item[data-agent="'+CSS.escape(e)+'"][data-session="'+CSS.escape(t)+'"]':'.session-item[data-session="'+CSS.escape(t)+'"]:not([data-agent])',o=D.querySelector(r);o&&Xt(o,i,Je.get(i))}function Xt(t,e,n){let i=Ue.get(e);i&&(clearTimeout(i),Ue.delete(e)),t.classList.remove("working","just-done");let s=n.session===V&&(n.agentId??null)===ee;n.state==="working"?t.classList.add("working"):s&&n.doneUntil&&Date.now()<n.doneUntil?(t.classList.add("just-done"),Ue.set(e,setTimeout(()=>{t.classList.remove("just-done"),Ue.delete(e)},Math.max(0,n.doneUntil-Date.now())))):!s&&n.unread&&t.classList.add("just-done")}function Hn(){for(let[t,e]of Je){let n=e.agentId?'.session-item[data-agent="'+CSS.escape(e.agentId)+'"][data-session="'+CSS.escape(e.session)+'"]':'.session-item[data-session="'+CSS.escape(e.session)+'"]:not([data-agent])',i=D.querySelector(n);i&&Xt(i,t,e)}}function Kl(t,e){let n=Dn(t,e),i=Je.get(n);if(!i)return;let s=Ue.get(n);s&&(clearTimeout(s),Ue.delete(n)),i.doneUntil=void 0,i.unread=!1;let l=e?'.session-item[data-agent="'+CSS.escape(e)+'"][data-session="'+CSS.escape(t)+'"]':'.session-item[data-session="'+CSS.escape(t)+'"]:not([data-agent])',a=D.querySelector(l);a&&Xt(a,n,i)}function ps(){if(bt||Pn)return;let t=localStorage.getItem("tmux-web-token"),e=(location.protocol==="https:"?"wss:":"ws:")+"//"+location.host+"/ws/activity";t&&(e+="?token="+encodeURIComponent(t));try{let n=new WebSocket(e);bt=n,n.onmessage=i=>{try{let s=JSON.parse(String(i.data));s&&s.type==="session.activity"&&typeof s.session=="string"&&Xl(s.session,s.agentId||void 0,s.state==="working"?"working":"idle")}catch{}},n.onclose=()=>{bt===n&&(bt=null,Pn=setTimeout(()=>{Pn=null,ps()},5e3))},n.onerror=()=>{try{n.close()}catch{}}}catch{bt=null}}window.__openSession=ut,window.__refreshSidebar=ye,ye(),pt(),Hn(),ps(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Hn()}),setInterval(()=>{document.visibilityState==="visible"&&ye()},1e4),gl();
|