tmux-weblink 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/shell-client.js +51 -51
- package/dist/browser/bots-client.js +6 -6
- package/dist/lib/icons.js +1 -1
- package/dist/lib/pages/shell.js +54 -26
- package/package.json +1 -1
|
@@ -1,52 +1,52 @@
|
|
|
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,r=Math.min(n,s),a=Math.max(n,s);if(r===a){let o=Math.min(e,i),c=Math.max(e,i);this.terminal.select(o,l.viewportY+r,c-o+1)}else this.terminal.selectLines(l.viewportY+r,l.viewportY+a)}getCellsText(e,n,i,s){let l=this.terminal.buffer.active,r=Math.min(n,s),a=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
|
|
3
|
-
`)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function
|
|
1
|
+
var $s=/\x1b\](?:10|11|110|111|104)(?:;[^\x07\x1b]*)?\x1b?(?:\\|\x07)/g;function en(t){return t.replace(/\x1b\[\?1049[hl]/g,"")}function Qe(t){return t.replace($s,"")}var Et;function zs(){return Et||(document.querySelector("link[data-tmux-web-xterm-css]")?Et=Promise.resolve():(Et=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)}),Et))}var Ms=class ps{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(Bs()==="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()]),r="'JetBrains Mono', 'SF Mono', 'Menlo', monospace",a=new s({fontSize:As(14,r),fontFamily:r,cursorBlink:!0,cursorStyle:"bar",scrollback:n,convertEol:!1,smoothScrollDuration:120,theme:i});return new ps(e,a,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=Rs(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 r=this.overlayScrollbarWidth(),a=r>0?r+2:0,o=s>0?Math.max(10,Math.min(l.cols,Math.floor((e.width-a)/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],r=i.viewportY,a=[];for(let o=s;o<=l;o++){let c=i.getLine(r+o);a.push(c?c.translateToString(!0):"")}return a.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,r=Math.min(n,s),a=Math.max(n,s);if(r===a){let o=Math.min(e,i),c=Math.max(e,i);this.terminal.select(o,l.viewportY+r,c-o+1)}else this.terminal.selectLines(l.viewportY+r,l.viewportY+a)}getCellsText(e,n,i,s){let l=this.terminal.buffer.active,r=Math.min(n,s),a=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 u=r;u<=a;u++){let h=l.getLine(d+u);if(!h){m.push("");continue}let f=u===r?o:0,b=u===a?c:this.terminal.cols-1,x="";for(let k=f;k<=b;k++){let y=h.getCell(k);y&&(x+=y.getChars())}m.push(x.replace(/\s+$/,""))}return m.join(`
|
|
3
|
+
`)}getSelection(){return this.terminal.getSelection()}clearSelection(){this.terminal.clearSelection()}hasSelectionSupport(){return!0}};function As(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,r=t,a=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<a&&(a=d,r=c)}return Math.round(r*100)/100}catch{return t}}function Bs(){try{let t=new URLSearchParams(window.location.search).get("renderer");return t==="dom"||t==="webgl"?t:null}catch{return null}}function Rs(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 Ps(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,r,a=null,o=0,c=0,d=.2,m=10,u=.95,h=.04,f=null,b=null;function x(p){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=p?"\u2191 \u4E0A\u7FFB\u4E00\u9875 (PgUp)":"\u2193 \u4E0B\u7FFB\u4E00\u9875 (PgDn)",f.style.top=p?"10%":"auto",f.style.bottom=p?"auto":"10%",f.style.opacity="1",b&&clearTimeout(b),b=setTimeout(()=>{f&&(f.style.opacity="0")},900)}function k(){b&&clearTimeout(b),f&&(f.style.opacity="0")}function y(){o&&(cancelAnimationFrame(o),o=0),c=0}function z(p){if(y(),Math.abs(p)<d)return;c=Math.max(-m,Math.min(m,p));let v=()=>{if(C){o=0;return}let S=i.cellHeight(),A=S>0?Math.round(c*16/S):c>0?1:-1;A===0&&(A=c>0?1:-1);let O=i.viewportY()-A,ue=i.baseY(),xe=Math.max(0,Math.min(O,ue));if(i.scrollToLine(xe,!0),c*=u,xe!==O){o=0;return}if(Math.abs(c)<h){o=0;return}o=requestAnimationFrame(v)};o=requestAnimationFrame(v)}let T=0,I="connecting",M=0,$=!1,E=[],B="",C=!1,F=1e3,_=location.protocol==="https:"?"wss:":"ws:",ie=n.wsBase||"/ws",G=_+"//"+location.host+ie+"/"+encodeURIComponent(e),K=(ie.replace(/^\/ws/,"")||"")+"/api/session/"+encodeURIComponent(e)+"/upload",bt=/^((?!chrome|android|crios|fxios|edgios).)*safari/i.test(navigator.userAgent);function Ue(){return E.join("")+B}async function ee(p,v=0){let S=p?i.viewportY():0,A=Qe(Ue());if(i.reset(),!A){p||i.scrollToBottom();return}await i.write(A),p?i.scrollToLine(v+S):i.scrollToBottom()}function pe(p){s?.readyState===WebSocket.OPEN&&s.send(JSON.stringify(p))}function Le(p){let v;try{v=JSON.parse(p)}catch{I==="live"&&(B+=p,i.write(Qe(p)));return}if(v.type==="auth.required"){let S=localStorage.getItem("tmux-web-token");S?pe({type:"auth.token",token:S}):location.href="/login?returnTo="+encodeURIComponent(location.pathname+location.search);return}if(v.type==="attach_failed"&&typeof v.message=="string"){He=!0,I="dead",i.reset(),i.write(`\r
|
|
4
4
|
\x1B[31m`+Qe(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),
|
|
5
|
+
`).then(()=>{kt();try{s?.close()}catch{}});return}if(v.type==="auth.ok"){v.token&&localStorage.setItem("tmux-web-token",v.token),F=1e3,Te(),pe({type:"resize",cols:i.cols,rows:i.rows}),Q();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(Qe(v.data));E=[S],B="",M=typeof v.lines=="number"?v.lines:n.terminal.initialLines,I="live",i.reset(),Te(),pe({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?(E.unshift(en(v.data)),M+=v.lines,ee(!0,v.lines).finally(()=>{$=!1})):$=!1;return}if(v.type==="data"&&typeof v.data=="string"){let S=en(Qe(v.data));if(I==="connecting"){I="live",B=S,i.write(S);return}I==="live"&&(B+=S,i.write(S))}}let He=!1;function Nn(){if(He)return;let p=G,v=localStorage.getItem("tmux-web-token");v&&(p+=(p.includes("?")?"&":"?")+"token="+encodeURIComponent(v)),p+=(p.includes("?")?"&":"?")+"cols="+i.cols+"&rows="+i.rows,s=new WebSocket(p),s.onopen=()=>{I="connecting",M=0,$=!1,E=[],B="",i.reset(),F=1e3},s.onmessage=S=>{typeof S.data=="string"&&Le(S.data)},s.onclose=()=>{C||(I="connecting",!He&&setTimeout(()=>{F=Math.min(F*2,1e4),!C&&!He&&Nn()},F))},s.onerror=()=>s?.close()}function _e(p){pe({type:"input",data:p})}function Te(){return i.fit()}function kt(){t.classList.remove("terminal-pending")}function Q(){l&&cancelAnimationFrame(l),r&&clearTimeout(r),Te(),l=requestAnimationFrame(()=>{l=0,Te()&&kt()}),r=setTimeout(()=>{Te()&&kt()},120)}function us(){Q(),setTimeout(Q,50),setTimeout(Q,150),setTimeout(Q,300)}function On(p){return typeof p=="string"&&p.startsWith("image/")}function qn(p){return p?.files?.length?p.files[0]??null:null}function hs(p){if(!p?.items)return null;for(let v=0;v<p.items.length;v++){let S=p.items[v];if(S?.kind==="file"&&On(S.type))return S.getAsFile()}return null}async function ms(p){let v=new FormData,S=p instanceof File&&p.name?p.name:"upload";v.append("file",p,S);let A=localStorage.getItem("tmux-web-token"),O={};A&&(O.Authorization="Bearer "+A);let ue=await fetch(K,{method:"POST",body:v,headers:O});if(!ue.ok){let Yn="upload failed";try{let Xn=await ue.json();Xn.error&&(Yn=Xn.error)}catch{}throw new Error(Yn)}let xe=await ue.json();if(!xe.path)throw new Error("no path in response");return xe.path}async function Kt(p){try{let v=await ms(p);_e(v)}catch{}}i.onData(p=>_e(p)),i.onResize(({cols:p,rows:v})=>pe({type:"resize",cols:p,rows:v})),i.onScroll(()=>{I!=="live"||$||!i.isNearScrollbackTop()||($=!0,pe({type:"load_history",before:M}))});let Ze=!1,Je=!1,W=null,Z=null,Ye=document.createElement("div");Ye.className="terminal-copy-banner",Ye.innerHTML='<strong>Copy mode</strong><span class="hint">drag to copy \xB7 Esc exits</span>',Ye.hidden=!0,t.appendChild(Ye);let ge=document.createElement("div");ge.className="terminal-copy-banner terminal-copy-toast",ge.textContent="Copied",ge.hidden=!0,t.appendChild(ge);function jn(p,v){let S=t.querySelector(".xterm-screen, canvas"),A=(S&&S.getBoundingClientRect().width>0?S:t).getBoundingClientRect(),O=A.height>0&&i.rows>0?A.height/i.rows:18,ue=A.width>0&&i.cols>0?A.width/i.cols:9;return{row:Math.max(0,Math.min(i.rows-1,Math.floor((v-A.top)/O))),col:Math.max(0,Math.min(i.cols-1,Math.floor((p-A.left)/ue)))}}async function wt(p){if(!p)return;try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(p);return}}catch{}let v=document.createElement("textarea");v.value=p,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 Xe;function yt(){ge.hidden=!1,Xe&&clearTimeout(Xe),Xe=setTimeout(()=>{ge.hidden=!0},1e3)}function Fe(p){Ze=p,Ye.hidden=!p,t.classList.toggle("terminal-copy-mode-active",p),p&&i.focus()}function Vn(){Fe(!Ze)}function fs(p){C||p.button!==0||Je||(Ze||p.shiftKey)&&(p.preventDefault(),p.stopPropagation(),Je=!0,W=jn(p.clientX,p.clientY),Z=W,i.selectCells(W.col,W.row,Z.col,Z.row),document.addEventListener("mousemove",Qt,!0),document.addEventListener("mouseup",Gt,!0))}function Qt(p){C||!Je||!W||(p.preventDefault(),p.stopPropagation(),Z=jn(p.clientX,p.clientY),i.selectCells(W.col,W.row,Z.col,Z.row))}function Gt(p){if(C||!Je||!W||!Z)return;p.preventDefault(),p.stopPropagation(),document.removeEventListener("mousemove",Qt,!0),document.removeEventListener("mouseup",Gt,!0),Je=!1;let v=i.getCellsText(W.col,W.row,Z.col,Z.row);W=null,Z=null,i.clearSelection(),Fe(!1),v&&(ge.textContent="\u5DF2\u590D\u5236",wt(v).then(yt)),i.focus()}t.addEventListener("mousedown",fs,!0),document.addEventListener("keydown",gs,!0);function gs(p){if(!(C||!i.isFocused()||p.defaultPrevented||p.isComposing)){if(Ze){if(p.key==="Escape"){p.preventDefault(),p.stopPropagation(),W=null,Z=null,i.clearSelection(),Fe(!1);return}if(p.key==="Enter"||(p.ctrlKey||p.metaKey)&&p.code==="KeyC"){p.preventDefault(),p.stopPropagation(),wt(i.getScreenText()).then(yt),Fe(!1);return}}if(p.altKey&&p.code==="KeyC"&&!p.ctrlKey&&!p.metaKey){if(p.preventDefault(),p.stopPropagation(),W&&Z){let v=i.getCellsText(W.col,W.row,Z.col,Z.row);W=null,Z=null,i.clearSelection(),Fe(!1),v&&(ge.textContent="Copied",wt(v).then(yt))}else{let v=i.getSelection();v?(i.clearSelection(),ge.textContent="Copied",wt(v).then(yt)):Vn()}return}if((p.ctrlKey||p.metaKey)&&p.code==="KeyV"){p.preventDefault(),p.stopPropagation(),(async()=>{try{if(navigator.clipboard?.read){let v=await navigator.clipboard.read();for(let S of v)for(let A of S.types)if(On(A)){let O=await S.getType(A);await Kt(O);return}}}catch{}try{let v=await navigator.clipboard?.readText();v&&i.pasteText(Wn(v))}catch{}})();return}}}let xt=0;function Wn(p){return p.split(`\r
|
|
6
6
|
`).join(`
|
|
7
7
|
`).split(`
|
|
8
|
-
`).join("\r")}async function fs(p){let v=ps(p.clipboardData);if(v){p.preventDefault(),p.stopPropagation();let N=Date.now();if(N-xt<50)return;xt=N,await Kt(v);return}let S=p.clipboardData?.getData("text/plain");if(!S)return;p.preventDefault(),p.stopPropagation();let z=Date.now();z-xt<50||(xt=z,i.pasteText(Wn(S)))}let Ke=0;function gs(p){p.preventDefault(),Ke++,qn(p.dataTransfer)&&t.classList.add("terminal-drag-over")}function vs(p){p.preventDefault(),p.dataTransfer&&(p.dataTransfer.dropEffect="copy")}function bs(p){p.preventDefault(),Ke--,Ke<=0&&(Ke=0,t.classList.remove("terminal-drag-over"))}async function ks(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"||Je||p.defaultPrevented||p.repeat||p.metaKey||p.ctrlKey||p.altKey||i.isFocused()&&(p.preventDefault(),p.stopPropagation(),_e("\x1B"))}t.addEventListener("paste",fs),t.addEventListener("dragenter",gs),t.addEventListener("dragover",vs),t.addEventListener("dragleave",bs),t.addEventListener("drop",ks),document.addEventListener("keydown",Un,!0);function ws(p){if(p.touches.length!==1){a=null;return}let v=p.touches[0];if(!v)return;y();let S=t.getBoundingClientRect(),z=v.clientX-S.left<S.width*.4?"tui":"history",N=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:z,tuiUp:N,sent:!1},p.stopPropagation()}function ys(p){if(!a||p.touches.length!==1)return;let v=p.touches[0];if(!v)return;let S=v.clientY-a.startY,z=v.clientX-a.startX;if(!a.scrolling){if(Math.abs(S)<8||Math.abs(S)<Math.abs(z))return;a.scrolling=!0,T=Date.now()+500}p.preventDefault(),p.stopPropagation();let N=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=N;return}let ye=N-a.lastT;ye>0&&(a.velocity=ue/ye),Cs(-ue),a.lastX=v.clientX,a.lastY=v.clientY,a.lastT=N}function xs(p){if(!a)return;let v=a.scrolling,S=a.zone,z=a.tuiUp,N=a.velocity;if(a=null,p.stopPropagation(),S==="tui"){v||(_e(z?"\x1B[5~":"\x1B[6~"),x(z),T=Date.now()+500,p.preventDefault());return}if(!v){i.focus();return}T=Date.now()+500,p.preventDefault(),N&&B(N)}function Es(p){a=null,y(),p.stopPropagation()}function Ss(p){p.pointerType==="touch"&&Date.now()<T&&(p.preventDefault(),p.stopPropagation())}function Cs(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",ws,{passive:!0,capture:!0}),t.addEventListener("touchmove",ys,{passive:!1,capture:!0}),t.addEventListener("touchend",xs,{passive:!1,capture:!0}),t.addEventListener("touchcancel",Es,{passive:!0,capture:!0}),t.addEventListener("pointerup",Ss,!0);function Jn(){Q()}window.addEventListener("resize",Jn),window.visualViewport?.addEventListener("resize",Q),window.visualViewport?.addEventListener("scroll",Q);let Zn=new ResizeObserver(()=>Q());Zn.observe(t),document.fonts?.ready.then(()=>{Q(),setTimeout(Q,50),setTimeout(Q,200)}),t.addEventListener("focusin",ds,!0);async function Ls(){if(document.fonts?.ready)try{await Promise.race([document.fonts.ready,new Promise(p=>setTimeout(p,1e3))])}catch{}}return requestAnimationFrame(()=>{Te()&&kt(),(async()=>(await Ls(),Te()&&pe({type:"resize",cols:i.cols,rows:i.rows}),Nn(),Q()))()}),{destroy(){if(L=!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",Jn),Zn.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",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 Rs(t){return Kn[t]??Kn.menu}function xe(t,e=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${e?" "+e:""}><path d="${Rs(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 Be(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 C(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:Be(t=>new RegExp(`^ {0,${t}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:Be(t=>new RegExp(`^ {0,${t}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:Be(t=>new RegExp(`^ {0,${t}}(?:\`{3,}(?=[^\`\\n]*(?:\\n|$))|~~~)`)),headingBeginRegex:Be(t=>new RegExp(`^ {0,${t}}#{1,6}(?:\\s|$)`)),pedanticHeadingBeginRegex:Be(t=>new RegExp(`^ {0,${t}}#`)),htmlBeginRegex:Be(t=>new RegExp(`^ {0,${t}}(?:</?(?:${sn})(?:[ \\t]+|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,"i")),blockquoteBeginRegex:Be(t=>new RegExp(`^ {0,${t}}>`)),nestedContainerMarkers:/^(?: {0,3}(?:(?:[*+-]|\d{1,9}[.)])[ \t]+|>[ \t]?))+/},Ps=/^(?:[ \t]*(?:\n|$))+/,Ds=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Hs=/^ {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+|$)/,_s=/^ {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=C(" {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=C(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(),Fs=C(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]+)*)/,Ns=/^[^\n]+/,ln=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/,Os=C(/^ {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(),qs=C(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,nn).getRegex(),an=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,js=C("^ {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=>C(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(),Vs=ii(H.listInterruptsParagraph),Ws=ii(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),si=/ {0,3}> ?(?:(?!blank)(paragraph)|[^\n]*)(?:\n|$)/,Us=C(/^(first)(?:next)*/).replace("first",C(si).replace("blank",/[ \t]*(?:\n|$)| {4}/).getRegex()).replace("next",C(si).replace("blank",/[ \t]*(?:\n|$)/).getRegex()).replace(/paragraph/g,Ws).getRegex(),on={blockquote:Us,code:Ds,def:Os,fences:Hs,heading:_s,hr:Ge,html:js,lheading:ni,list:qs,newline:Ps,paragraph:Vs,table:$e,text:Ns},Js=C(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(),Zs={...on,lheading:Fs,table:Js,paragraph:C(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()},Ys={...on,html:C(`^ *(?: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:C(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()},
|
|
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()},Qs=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Gs=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ri=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,er=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,he=/[\p{P}\p{S}]/u,Ne=/[\s\p{P}\p{S}]/u,tt=/[^\s\p{P}\p{S}]/u,tr=L(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Ne).getRegex(),nr=/[\p{Pi}\p{Ps}"']/u,li=/(?!~)[\p{P}\p{S}]/u,ir=/(?!~)[\s\p{P}\p{S}]/u,sr=/(?:[^\s\p{P}\p{S}]|~)/u,rr=L(/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(),ai=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,lr=L(ai,"u").replace(/punct/g,he).getRegex(),ar=L(ai,"u").replace(/punct/g,li).getRegex(),or=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,cr=L(or,"u").replace(/openQuote/g,nr).replace(/punct/g,he).getRegex(),oi="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",dr=L(oi,"gu").replace(/notPunctSpace/g,tt).replace(/punctSpace/g,Ne).replace(/punct/g,he).getRegex(),pr=L(oi,"gu").replace(/notPunctSpace/g,sr).replace(/punctSpace/g,ir).replace(/punct/g,li).getRegex(),ur="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",hr=L(ur,"gu").replace(/notPunctSpace/g,tt).replace(/punctSpace/g,Ne).replace(/punct/g,he).getRegex(),mr=L("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,tt).replace(/punctSpace/g,Ne).replace(/punct/g,he).getRegex(),fr="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",gr=L(fr,"gu").replace(/notPunctSpace/g,tt).replace(/punctSpace/g,Ne).replace(/punct/g,he).getRegex(),vr=L(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,he).getRegex(),br="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",kr=L(br,"gu").replace(/notPunctSpace/g,tt).replace(/punctSpace/g,Ne).replace(/punct/g,he).getRegex(),wr=L(/\\(punct)/,"gu").replace(/punct/g,he).getRegex(),yr=L(/(`+)(?:[^`]|[^`][\s\S]*?[^`])\1(?!`)|`+|\\(punct)/,"gu").replace(/punct/g,he).getRegex(),xr=L(/^<(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(),Er=L(an).replace("(?:-->|$)","-->").getRegex(),Sr=L("^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",Er).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ci=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,St=L(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets",ci).getRegex(),Ct=/\\[^ \t\n\x00-\x1f]|\\(?=[ \t\n])|[^ \t\n\x00-\x1f\\()]/,Cr=L(/\((?:char)*\)/).replace("char",Ct).getRegex(),Lr=L(/\((?:char|p1)*\)/).replace("char",Ct).replace("p1",Cr).getRegex(),Tr=L(/\((?:char|p2)*\)/).replace("char",Ct).replace("p2",Lr).getRegex(),Ir=L(/(?!<)(?:char|p3)+/).replace("char",Ct).replace("p3",Tr).getRegex(),$r=L(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace("label",St).replace("href",L(/<(?:\\.|[^\n<>\\])*>|bareHref|(?=\))/).replace("bareHref",Ir).getRegex()).replace("title",/"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\((?:\\[\s\S]|[^)\\])*\)/).getRegex(),zr=L(/^!?\[(label)\]\[(ref)\]/).replace("label",St).replace("ref",ln).getRegex(),Mr=L(/^!?\[(ref)\](?:\[\])?/).replace("ref",ln).getRegex(),di=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,Ar=L(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets",ci).getRegex(),Br=L("reflink|nolink(?!\\()","g").replace("reflink",L(/^!?\[(label)\]\[(ref)\]/).replace("label",Ar).replace("ref",di).getRegex()).replace("nolink",L(/^!?\[(ref)\](?:\[\])?/).replace("ref",di).getRegex()).getRegex(),pi=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Rr=/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/,Pr=L(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,Rr).getRegex(),cn={_backpedal:$e,anyPunctuation:wr,anyPunctuationOutsideCode:yr,autolink:xr,blockSkip:rr,br:ri,code:Gs,del:$e,delLDelim:$e,delRDelim:$e,emStrongLDelim:lr,emStrongRDelimAst:dr,emStrongRDelimUnd:mr,escape:Qs,link:$r,nolink:Mr,punctuation:tr,reflink:zr,reflinkSearch:Br,tag:Sr,text:er,url:$e},Dr={...cn,emStrongLDelim:cr,emStrongRDelimAst:hr,emStrongRDelimUnd:gr,link:L(/^!?\[(label)\]\((.*?)\)/).replace("label",St).getRegex(),reflink:L(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",St).getRegex()},dn={...cn,emStrongRDelimAst:pr,emStrongLDelim:ar,delLDelim:vr,delRDelim:kr,url:L(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol",Pr).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:L(/^(?:[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()},Hr={...dn,br:L(ri).replace("{2,}","*").getRegex(),text:L(dn.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Lt={normal:on,gfm:Xs,pedantic:Ks},nt={normal:cn,gfm:dn,breaks:Hr,pedantic:Dr},_r={"&":"&","<":"<",">":">",'"':""","'":"'"},ui=t=>_r[t];function J(t,e){if(e){if(H.escapeTest.test(t))return t.replace(H.escapeReplace,ui)}else if(H.escapeTestNoEncode.test(t))return t.replace(H.escapeReplaceNoEncode,ui);return t}function Fr(t){return H.numericCharacterReference.test(t)?t.replace(H.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(H.percentDecode,"%")}catch{return null}return t}function pn(t,e){let n=t.replace(H.findPipe,(l,r,a)=>{let o=!1,c=r;for(;--c>=0&&a[c]==="\\";)o=!o;return o?"|":" |"}),i=n.split(H.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(H.slashPipe,"|");return i}function be(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
10
|
`),n=e.length-1;for(;n>=0&&H.blankLine.test(e[n]);)n--;return e.length-n<=2?t:e.slice(0,n+1).join(`
|
|
11
11
|
`)}function Tt(t,e=!1){let n=e?H.multipleSpaceGlobal:H.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 Oe=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 r=s===0?`
|
|
12
12
|
`:t[s-1],a=s+1;for(;a<i&&t[a]===l;)a++;r!==" "&&r!==" "&&r!==`
|
|
13
|
-
`&&r!=="\r"&&r!=="\f"&&(l==="~"?n=s:e[l]=s),s=a-1}return{maskedSrc:t,lastPossibleEmStrongCloserIndex:e,lastPossibleDelCloserIndex:n}}function
|
|
14
|
-
`)}function
|
|
13
|
+
`&&r!=="\r"&&r!=="\f"&&(l==="~"?n=s:e[l]=s),s=a-1}return{maskedSrc:t,lastPossibleEmStrongCloserIndex:e,lastPossibleDelCloserIndex:n}}function Nr(t,e){let n=un(e),i=Oe.get(t);i?i.push(n):Oe.set(t,[n])}function Or(t){let e=Oe.get(t);e&&(e.pop(),e.length===0&&Oe.delete(t))}function gi(t,e,n){let i=Oe.get(t)?.at(-1);return i&&i.maskedSrc===e?i.lastPossibleEmStrongCloserIndex[n]:un(e).lastPossibleEmStrongCloserIndex[n]}function vi(t,e){let n=Oe.get(t)?.at(-1);return n&&n.maskedSrc===e?n.lastPossibleDelCloserIndex:un(e).lastPossibleDelCloserIndex}function it(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 qr(t){let e,n=!1;return t.map(i=>{if(n)return i;let{depth:s,expanded:l,keptIndent:r,content:a}=jr(i,e?.depth??1/0);if(e?.depth!==s&&(e=void 0),e){let c=H.blockquoteFenceClose.exec(a)?.[1];return!c||c[0]!==e.marker[0]||c.length<e.marker.length?r:(e=void 0,l)}if(n=H.blockquoteListItemStart.test(a),n)return i;let o=H.blockquoteFenceOpen.exec(a)?.[1];return o&&(e={marker:o,depth:s}),l}).join(`
|
|
14
|
+
`)}function jr(t,e){let n=0,i=0,s=0,l=0,r="";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;r+=" ".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 a="",o="";for(;(t[n]===" "||t[n]===" ")&&i<l+4;){let d=bi(t[n],i);a+=" ".repeat(d),o+=i<l&&d>1?" ".repeat(d):t[n],i+=d,n++}let c=t.slice(n);return{depth:s,expanded:r+a+c,keptIndent:r+o+c,content:" ".repeat(Math.max(0,i-l))+c}}function bi(t,e){return t===" "?4-e%4:1}function Vr(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,r=e.title||null,a=Vr(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 u=i.inlineTokens(a),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:r,text:a,tokens:u}}function Wr(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
15
|
`).map(r=>{let a=r.match(n.other.beginningSpace);if(a===null)return r;let[o]=a,c=o.indexOf(" ");if(c!==-1&&c<l){if(i)return" ".repeat(4-l)+r.slice(c+1);if(t[l]==="~")return r}return r.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 a=i.inline.code.exec(e.slice(s));if(a){s+=a[0].length-1;continue}}if(e[s]!=="<")continue;let l=t.slice(n+s),r=i.inline.tag.exec(l)||i.inline.autolink.exec(l);if(r){if(r[0].length>e.length-s)return!0;s+=r[0].length-1}}return!1}var Me=class{options;rules;lexer;constructor(t){this.options=t||Ie}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=
|
|
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 a=i.inline.code.exec(e.slice(s));if(a){s+=a[0].length-1;continue}}if(e[s]!=="<")continue;let l=t.slice(n+s),r=i.inline.tag.exec(l)||i.inline.autolink.exec(l);if(r){if(r[0].length>e.length-s)return!0;s+=r[0].length-1}}return!1}var Me=class{options;rules;lexer;constructor(t){this.options=t||Ie}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=Wr(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,r=s.length;for(;l<r&&(s[l]===" "||s[l]===" ");)l++;for(;r>l&&(s[r-1]===" "||s[r-1]===" ");)r--;s=s.slice(l,r).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=
|
|
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,r=s.length;for(;l<r&&(s[l]===" "||s[l]===" ");)l++;for(;r>l&&(s[r-1]===" "||s[r-1]===" ");)r--;s=s.slice(l,r).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=be(n,"#");(this.options.pedantic||!i||this.rules.other.endingSpaceTabChar.test(i))&&(n=i.trim())}return{type:"heading",raw:be(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:be(e[0],`
|
|
20
|
+
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=be(e[0],`
|
|
21
21
|
`).split(`
|
|
22
22
|
`),i="",s="",l=[];for(;n.length>0;){let r=!1,a=[],o;for(o=0;o<n.length;o++)if(this.rules.other.blockquoteStart.test(n[o]))a.push(n[o]),r=!0;else if(!r)a.push(n[o]);else break;n=n.slice(o);let c=a.join(`
|
|
23
|
-
`),d=(this.lexer.state.top&&!this.lexer.state.inBlockquote&&c.includes(" ")?
|
|
23
|
+
`),d=(this.lexer.state.top&&!this.lexer.state.inBlockquote&&c.includes(" ")?qr(a):c).replace(this.rules.other.blockquoteMarkerWhitespace,(b,x,k)=>k.startsWith(" ")?x+" "+k.slice(1):x+it(k,x.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,
|
|
26
|
+
${d}`:d;let m=this.lexer.state.top,u=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=u,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,x=n.join(`
|
|
27
27
|
`),k=b.raw+`
|
|
28
|
-
`+x.replace(this.rules.other.blockquoteSetextReplace2,"");this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=l.at(-2);let y=this.blockquote(k);this.lexer.state.inBlockquote=
|
|
28
|
+
`+x.replace(this.rules.other.blockquoteSetextReplace2,"");this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=l.at(-2);let y=this.blockquote(k);this.lexer.state.inBlockquote=u,this.lexer.state.lastToken=h,l[l.length-1]=y;let z=k.substring(y.raw.length).replace(/^\n/,""),T=z?z.split(`
|
|
29
29
|
`).length:0,I=T?n.slice(0,-T):n;if(I.length>0&&(i=`${i}
|
|
30
30
|
${I.join(`
|
|
31
31
|
`)}`),s=s.substring(0,s.length-b.text.length)+y.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,x=b.raw+`
|
|
32
32
|
`+n.join(`
|
|
33
|
-
`);this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=l.at(-2);let k=this.list(x);this.lexer.state.top=m,this.lexer.state.inBlockquote=
|
|
34
|
-
`).length:0;if(y>0){let
|
|
33
|
+
`);this.lexer.state.inBlockquote=!0,this.lexer.state.lastToken=l.at(-2);let k=this.list(x);this.lexer.state.top=m,this.lexer.state.inBlockquote=u,this.lexer.state.lastToken=h,l[l.length-1]=k;let y=k.raw.length>b.raw.length?x.slice(b.raw.length+1,k.raw.length).split(`
|
|
34
|
+
`).length:0;if(y>0){let z=n.slice(0,y).join(`
|
|
35
35
|
`);i=`${i}
|
|
36
|
-
${
|
|
37
|
-
${
|
|
36
|
+
${z}`,s=`${s}
|
|
37
|
+
${z}`}if(n=n.slice(y),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,r={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 a=this.rules.other.listItemRegex(s),o=!1;for(;t;){let u=!1,h="";if(!(e=a.exec(t))||this.rules.block.hr.test(t))break;let f=i();t=t.substring(e[0].length);let b=e[2].split(`
|
|
38
38
|
`,1)[0],x=e[1].length,k=this.options.pedantic?it(b,x):b.replace(this.rules.other.leadingSpaceTab,M=>it(M,x)),y=t.split(`
|
|
39
|
-
`,1)[0],
|
|
40
|
-
`,1)[0],G;if(y=
|
|
41
|
-
`+G.slice(T),_=!1;else{if(
|
|
42
|
-
`)&&!k.includes(" ")){let ee;for(;!$.test(K)&&(ee=this.rules.other.nestedBlockMarker.exec(K));)K=K.slice(ee[0].length);if(!K.trim())break}if(K.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||E.test(K)||
|
|
43
|
-
${y}`)?` ${G.replace(/^ {0,3}/,"")}`:y,Ue=!this.options.pedantic&&!_&&G.startsWith(" ")?this.rules.block.list.exec(k):null;if(Ue?.[2]){let ee=Ue[1].length,pe=Ue[2].replace(this.rules.other.leadingSpaceTab,He=>it(He,ee)),Le=pe.search(this.rules.other.nonSpaceChar);Le>0&&Le<=4&&!this.rules.other.nestedBlockMarker.test(pe.slice(Le))&&G.search(this.rules.other.nonSpaceChar)>=ee+Le&&this.rules.other.listInterruptsParagraph.test(G.slice(ee+Le))&&(bt=` ${G}`)}
|
|
44
|
-
`+bt,_=!0}
|
|
39
|
+
`,1)[0],z=!k.trim(),T=0;if(this.options.pedantic?(T=2,h=k.trimStart()):z?T=x+1:(T=k.search(this.rules.other.nonSpaceChar),T=T>4?1:T,h=k.slice(T),k=h,T+=x),z&&this.rules.other.blankLine.test(y)&&(t=t.substring(y.length+1),u=!0),!u){let M=this.rules.other.nextBulletRegex(T),$=this.rules.other.hrRegex(T),E=this.rules.other.fencesBeginRegex(T),B=this.options.pedantic?this.rules.other.pedanticHeadingBeginRegex(T):this.rules.other.headingBeginRegex(T),C=this.rules.other.htmlBeginRegex(T),F=this.rules.other.blockquoteBeginRegex(T),_=!1;for(;t;){let ie=t.split(`
|
|
40
|
+
`,1)[0],G;if(y=ie,this.options.pedantic?(y=y.replace(this.rules.other.listReplaceNesting," "),G=y):G=y.replace(this.rules.other.leadingSpaceTab,K=>it(K)),E.test(y)||B.test(y)||C.test(y)||F.test(y)||M.test(y)||$.test(y))break;if(G.search(this.rules.other.nonSpaceChar)>=T||!y.trim())h+=`
|
|
41
|
+
`+G.slice(T),_=!1;else{if(z)break;let K=k;if(!this.options.pedantic&&!h.includes(`
|
|
42
|
+
`)&&!k.includes(" ")){let ee;for(;!$.test(K)&&(ee=this.rules.other.nestedBlockMarker.exec(K));)K=K.slice(ee[0].length);if(!K.trim())break}if(K.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||E.test(K)||B.test(K)||C.test(K)||$.test(K))break;if(!this.options.pedantic&&!_){let ee=k.replace(this.rules.other.nestedContainerMarkers,"");if(this.rules.block.fences.test(ee)||this.rules.block.heading.test(ee)||this.rules.block.hr.test(ee))break}let bt=!this.options.pedantic&&/^ {0,3}(?:=+|-+) *$/.test(y)&&this.rules.block.lheading.test(`${k}
|
|
43
|
+
${y}`)?` ${G.replace(/^ {0,3}/,"")}`:y,Ue=!this.options.pedantic&&!_&&G.startsWith(" ")?this.rules.block.list.exec(k):null;if(Ue?.[2]){let ee=Ue[1].length,pe=Ue[2].replace(this.rules.other.leadingSpaceTab,He=>it(He,ee)),Le=pe.search(this.rules.other.nonSpaceChar);Le>0&&Le<=4&&!this.rules.other.nestedBlockMarker.test(pe.slice(Le))&&G.search(this.rules.other.nonSpaceChar)>=ee+Le&&this.rules.other.listInterruptsParagraph.test(G.slice(ee+Le))&&(bt=` ${G}`)}h+=`
|
|
44
|
+
`+bt,_=!0}z=!y.trim(),t=t.substring(ie.length+1),k=G.slice(T)}}let I=n.slice(f,i());r.loose||(o?r.loose=!0:this.rules.other.doubleBlankLine.test(I)&&(o=!0)),r.items.push({type:"list_item",raw:I,task:!!this.options.gfm&&this.rules.other.listIsTask.test(h),loose:!1,text:h,tokens:[]})}let c=r.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd();else return;r.raw=n.slice(0,i()).trimEnd();let d=[],m=this.lexer.state.top;for(let u of r.items)if(this.lexer.state.top=!1,d.push(this.lexer.inlineQueue.length),u.tokens=this.lexer.blockTokens(u.text,[]),!r.loose){let h=u.tokens.filter(b=>b.type==="space"),f=h.length>0&&h.some(b=>this.rules.other.anyLine.test(b.raw));r.loose=f}this.lexer.state.top=m;for(let u=0;u<r.items.length;u++){let h=r.items[u],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 k=d[u];k<b.length;k++)if(b[k].tokens===f.tokens){b[k].src=b[k].src.replace(this.rules.other.listReplaceTask,"");break}let x=this.rules.other.listTaskCheckbox.exec(h.raw);if(x){let k={type:"checkbox",raw:x[0]+" ",checked:x[0]!=="[ ]"};h.checked=k.checked,r.loose?h.tokens[0]&&["paragraph","text"].includes(h.tokens[0].type)&&"tokens"in h.tokens[0]&&h.tokens[0].tokens?(h.tokens[0].raw=k.raw+h.tokens[0].raw,h.tokens[0].text=k.raw+h.tokens[0].text,h.tokens[0].tokens.unshift(k)):h.tokens.unshift({type:"paragraph",raw:k.raw,text:k.raw,tokens:[k]}):h.tokens.unshift(k)}}else h.task&&(h.task=!1)}if(r.loose)for(let u of r.items){u.loose=!0;for(let h of u.tokens)h.type==="text"&&(h.type="paragraph")}return r}}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:be(e[0],`
|
|
45
45
|
`),href:i,title:s}}}table(t){let e,n;if(this.options.gfm&&!this.options.pedantic){let r=this.rules.other.tableHeader.exec(t);if(!r||!this.rules.other.tableDelimiter.test(r[2])||(e=pn(r[1]),n=r[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:
|
|
47
|
-
`),header:[],align:[],rows:[]};if(e.length===n.length){for(let r of n)this.rules.other.tableAlignRight.test(r)?l.align.push("right"):this.rules.other.tableAlignCenter.test(r)?l.align.push("center"):this.rules.other.tableAlignLeft.test(r)?l.align.push("left"):l.align.push(null);for(let r=0;r<e.length;r++)l.header.push({text:e[r],tokens:this.lexer.inline(e[r]),header:!0,align:l.align[r]});for(let r of s)l.rows.push(pn(r,l.header.length).map((a,o)=>({text:a,tokens:this.lexer.inline(a),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:
|
|
46
|
+
`):[],l={type:"table",raw:be(i[0],`
|
|
47
|
+
`),header:[],align:[],rows:[]};if(e.length===n.length){for(let r of n)this.rules.other.tableAlignRight.test(r)?l.align.push("right"):this.rules.other.tableAlignCenter.test(r)?l.align.push("center"):this.rules.other.tableAlignLeft.test(r)?l.align.push("left"):l.align.push(null);for(let r=0;r<e.length;r++)l.header.push({text:e[r],tokens:this.lexer.inline(e[r]),header:!0,align:l.align[r]});for(let r of s)l.rows.push(pn(r,l.header.length).map((a,o)=>({text:a,tokens:this.lexer.inline(a),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:be(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=
|
|
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=be(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=be(n[0].slice(0,-1),"\\");if((n[0].length-l.length)%2===0)return;let r=n[2],a="";if(this.options.pedantic){let o=this.rules.other.pedanticHrefTitle.exec(r);o&&(r=o[1],a=o[3])}else a=n[3]?n[3].slice(1,-1):"";return this.options.pedantic&&(r=r.trim()),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(s)?r=r.slice(1):r=r.slice(1,-1)),ki(n,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:a&&a.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 r=i[0].charAt(0);return{type:"text",raw:r,text:r}}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,r=e.length-t.length,a=r;for(;!this.options.pedantic&&a>0&&e[a-1]===s;)a--;let o=[...e.slice(Math.max(0,a-2),a)].at(-1)??"",c=o==="*"||o==="_"||!!this.rules.inline.punctuation.exec(o);a<r&&(n=o);let d=a<r?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 u=[...i[0]].length-1,h,f,b=u,x=0,k=r-a+u,y=!this.options.pedantic&&!!o.trim()&&(!!m||s==="*"&&!c);if(s!=="*"&&s!=="_")return;let z=s==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd,T=gi(this,e,s),I=e.length-t.length+u;if(T<I)return;e=e.slice(-1*t.length+u);let M=T-I;for(z.lastIndex=0;(i=z.exec(e))!==null&&!(i.index>M);){if(h=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!h)continue;f=[...h].length;let $=f>b-u;if(i[3]||i[4]){b+=f;continue}else if((i[5]||i[6]||y&&$)&&k%3&&!((k+f)%3)){if(l&&(i[5]||i[6]))break;x+=f;continue}if(b-=f,b>0)continue;f=Math.min(f,f+b+x);let E=[...i[0]][0].length,B=t.slice(0,u+i.index+E+f);if(Math.min(u,f)%2){let F=B.slice(1,-1);return{type:"em",raw:B,text:F,tokens:this.lexer.inlineTokens(F)}}let C=B.slice(2,-2);return{type:"strong",raw:B,text:C,tokens:this.lexer.inlineTokens(C)}}}}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,r,a=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||(r=[...l].length,r!==s))continue;if(i[3]||i[4]){a+=r;continue}if(a-=r,a>0)continue;r=Math.min(r,r+a);let u=[...i[0]][0].length,h=t.slice(0,s+i.index+u+r),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]:Fr(e[0]),escaped:n}}}},se=class _n{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Ie,this.options.tokenizer=this.options.tokenizer||new Me,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:H,block:Lt.normal,inline:nt.normal};this.options.pedantic?(n.block=Lt.pedantic,n.inline=nt.pedantic):this.options.gfm&&(n.block=Lt.gfm,this.options.breaks?n.inline=nt.breaks:n.inline=nt.gfm),this.tokenizer.rules=n}static get rules(){return{block:Lt,inline:nt}}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(H.carriageReturn,`
|
|
50
50
|
`)),i.inlineTokens(e)}lex(e){e=e.replace(H.carriageReturn,`
|
|
51
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(H.tabCharGlobal," ").replace(H.spaceLine,""));let l=1/0,r,a=this.options.gfm&&!this.options.pedantic&&this.tokenizer.paragraph===Me.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(`
|
|
@@ -55,15 +55,15 @@ ${y}`)?` ${G.replace(/^ {0,3}/,"")}`:y,Ue=!this.options.pedantic&&!_&&G.start
|
|
|
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),u;this.options.extensions.startBlock.forEach(h=>{u=h.call({lexer:this},m),typeof u=="number"&&u>=0&&(d=Math.min(d,u))}),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===r&&a)&&d?.type==="paragraph"?(d.raw+=(d.raw.endsWith(`
|
|
59
59
|
`)?"":`
|
|
60
60
|
`)+o.raw,d.text+=`
|
|
61
61
|
`+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=d.text,r=d):(n.push(o),r=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!==Me.prototype.emStrong||this.tokenizer.del!==Me.prototype.del?this.#i(e):e;if(!i)return this.#e(e,s,n);
|
|
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!==Me.prototype.emStrong||this.tokenizer.del!==Me.prototype.del?this.#i(e):e;if(!i)return this.#e(e,s,n);Nr(this.tokenizer,s);try{return this.#e(e,s,n)}finally{Or(this.tokenizer)}}#e(e,n,i){let s=!1,l="",r=1/0;for(;e;){if(e.length<r)r=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}s||(l=""),s=!1;let a;if(this.options.extensions?.inline?.some(d=>(a=d.call({lexer:this},e,i))?(e=e.substring(a.raw.length),i.push(a),!0):!1))continue;if(a=this.tokenizer.escape(e)){e=e.substring(a.raw.length),i.push(a);continue}if(a=this.tokenizer.tag(e)){e=e.substring(a.raw.length),i.push(a);continue}if(a=this.tokenizer.link(e)){e=e.substring(a.raw.length),i.push(a);continue}if(a=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(a.raw.length);let d=i.at(-1);a.type==="text"&&d?.type==="text"?(d.raw+=a.raw,d.text+=a.text):i.push(a);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 u=e.substring(0,m),h=i.at(-1);h?.type==="text"&&!h.escaped?(h.raw+=u,h.text+=u):i.push({type:"text",raw:u,text:u,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 u=e.substring(0,m),h=i.at(-1);h?.type==="text"&&!h.escaped?(h.raw+=u,h.text+=u):i.push({type:"text",raw:u,text:u,escaped:!1}),e=e.substring(m),l=o,s=!0;continue}}if(a=this.tokenizer.emStrong(e,n,l)){e=e.substring(a.raw.length),i.push(a);continue}if(a=this.tokenizer.codespan(e)){e=e.substring(a.raw.length),i.push(a);continue}if(a=this.tokenizer.br(e)){e=e.substring(a.raw.length),i.push(a);continue}if(a=this.tokenizer.del(e,n,l)){e=e.substring(a.raw.length),i.push(a);continue}if(a=this.tokenizer.autolink(e)){e=e.substring(a.raw.length),i.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(e))){e=e.substring(a.raw.length),i.push(a);continue}let c=e;if(this.options.extensions?.startInline){let d=1/0,m=e.slice(1),u;this.options.extensions.startInline.forEach(h=>{u=h.call({lexer:this},m),typeof u=="number"&&u>=0&&(d=Math.min(d,u))}),d<1/0&&d>=0&&(c=e.substring(0,d+1))}if(a=this.tokenizer.inlineText(c)){e=e.substring(a.raw.length),a.raw.slice(-1)!=="_"&&(l=a.raw.slice(-1)),s=!0;let d=i.at(-1);d?.type==="text"?(d.raw+=a.raw,d.text+=a.text):i.push(a);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="",r=0,a;for(n.lastIndex=0;a=n.exec(e);){let o=a.index+(a[2]?a[2].length:0),c=a.index+a[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(r,o)+"["+"a".repeat(c-o-2)+"]",r=c}return l+e.slice(r)}#i(e){let n=e;if(this.tokens.links&&e.includes("[")){let i=this.tokenizer.rules.inline.reflinkSearch,s=l=>{let r=l.lastIndexOf("[");if(!Object.hasOwn(this.tokens.links,Tt(l.slice(r+1,-1),this.options.pedantic)))return l;if(r>1&&l.charAt(0)!=="!"){let a=l.slice(1,r-1);if(this.linkInText(a))return"["+a.replace(i,s)+"]["+"a".repeat(l.length-r-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 r=J(s.text,!0);r!==s.text&&(l={...s,text:r})}else if(s.type==="link"&&s.autolink){let r=J(s.text,!0),a=s.tokens,o=a&&(a.length===1&&a[0].type==="text"&&a[0].text===s.text?r!==s.text?[{...a[0],text:r}]:a:hn(a,!0));(r!==s.text||o!==a)&&(l=o!==a?{...s,text:r,tokens:o}:{...s,text:r})}else if("tokens"in s&&s.tokens){let r=hn(s.tokens,e);r!==s.tokens&&(l={...s,tokens:r})}l!==s?(n||(n=t.slice(0,i)),n.push(l)):n&&n.push(s)}return n||t}var It=class{options;parser;constructor(t){this.options=t||Ie}space(t){return""}code({text:t,lang:e,escaped:n}){let i=(e||"").trim().match(H.notSpaceStart)?.[0],s=t?t.replace(H.endingNewline,"")+`
|
|
65
|
+
`:"";return i?'<pre><code class="language-'+J(i)+'">'+(n?s:J(s,!0))+`</code></pre>
|
|
66
|
+
`:"<pre><code>"+(n?s:J(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}>
|
|
@@ -79,45 +79,45 @@ ${this.parser.parse(t)}</blockquote>
|
|
|
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}},
|
|
84
|
-
Please report this to https://github.com/markedjs/marked.`,t){let s="<p>An error occurred:</p><pre>"+
|
|
85
|
-
`).forEach((u,f)=>{f>0&&m.appendChild(t.createElement("br")),u&&m.appendChild(t.createTextNode(u))})}function l(m,h){switch(h.type){case"text":{if(h.tokens?.length){for(let u of h.tokens)l(m,u);return}s(m,h.text??h.raw??"");return}case"escape":m.appendChild(t.createTextNode(h.text??""));return;case"strong":case"em":case"del":{let u=t.createElement(h.type==="strong"?"strong":h.type==="em"?"em":"del");for(let f of h.tokens??[])l(u,f);m.appendChild(u);return}case"codespan":{let u=t.createElement("code");u.textContent=h.text??"",m.appendChild(u);return}case"br":m.appendChild(t.createElement("br"));return;case"link":{let u=h.tokens??[],f=yi(h.href);if(!f){for(let x of u)l(m,x);return}let b=t.createElement("a");b.href=f,b.rel="noreferrer noopener",h.title&&(b.title=h.title),xi(f)&&(b.target="_blank");for(let x of u)l(b,x);m.appendChild(b);return}case"image":{let u=yi(h.href),f=h.text?.trim()||h.href||"image";if(!u){m.appendChild(t.createTextNode(f));return}let b=t.createElement("a");b.href=u,b.textContent=f,b.rel="noreferrer noopener",xi(u)&&(b.target="_blank"),m.appendChild(b);return}case"html":m.appendChild(t.createTextNode(h.raw??h.text??""));return;default:if(h.tokens?.length){for(let u of h.tokens)l(m,u);return}s(m,h.text??h.raw??"")}}function r(m){let h=t.createElement("div");h.className="bv-code";let u=t.createElement("div");u.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)},()=>{})}),u.append(b,x);let y=t.createElement("pre"),B=t.createElement("code");return f&&(B.className=`language-${f}`),B.textContent=k,y.appendChild(B),h.append(u,y),h}function a(m,h){let u=t.createElement("div");u.className="bv-table";let f=t.createElement("table"),b=t.createElement("thead"),x=t.createElement("tr"),k=h.align??[],y=(T,I,M)=>{let $=t.createElement(T);k[M]&&($.style.textAlign=k[M]);for(let E of I.tokens??[])l($,E);return $};(h.header??[]).forEach((T,I)=>x.appendChild(y("th",T,I))),b.appendChild(x);let B=t.createElement("tbody");for(let T of h.rows??[]){let I=t.createElement("tr");T.forEach((M,$)=>I.appendChild(y("td",M,$))),B.appendChild(I)}f.append(b,B),u.appendChild(f),m.appendChild(u)}function o(m,h){let u=t.createElement("li");if(h.task){let f=t.createElement("input");f.type="checkbox",f.disabled=!0,f.checked=h.checked===!0,u.appendChild(f)}for(let f of h.tokens??[])if(f.type==="text")l(u,f);else if(f.type==="paragraph")for(let b of f.tokens??[])l(u,b);else c(u,f);m.appendChild(u)}function c(m,h){switch(h.type){case"space":return;case"heading":{let u=Math.min(Math.max(h.depth??1,1),6),f=t.createElement(`h${u}`);for(let b of h.tokens??[])l(f,b);m.appendChild(f);return}case"paragraph":{let u=t.createElement("p");for(let f of h.tokens??[])l(u,f);m.appendChild(u);return}case"text":l(m,h);return;case"code":m.appendChild(r(h));return;case"blockquote":{let u=t.createElement("blockquote");for(let f of h.tokens??[])c(u,f);m.appendChild(u);return}case"list":{let u=h.items??h.tokens??[];if(h.ordered){let f=t.createElement("ol");typeof h.start=="number"&&h.start!==1&&(f.start=h.start);for(let b of u)o(f,b);m.appendChild(f)}else{let f=t.createElement("ul");for(let b of u)o(f,b);m.appendChild(f)}return}case"table":a(m,h);return;case"hr":m.appendChild(t.createElement("hr"));return;case"html":case"escape":m.appendChild(t.createTextNode(h.raw??h.text??""));return;default:if(h.tokens?.length){for(let u of h.tokens)c(m,u);return}h.text&&m.appendChild(t.createTextNode(h.text))}}function d(m){let h=t.createDocumentFragment();try{let u=R.lexer(m);for(let f of u)c(h,f)}catch{h.replaceChildren(t.createTextNode(m))}return h}return m=>{let h=e.get(m);if(h)return e.delete(m),e.set(m,h),h.fragment.cloneNode(!0);let u=d(m);return i(m,u),u.cloneNode(!0)}}var fn=Yr(document),w={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1},Se=[],me=!0,Xr=!1,Si=0;function gn(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function O(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 Kr(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,Qr()}))}var vn=0,$t="";function Qr(){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 Bt(){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 Gr(){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(),ul()}),n?.addEventListener("click",()=>{i(),Tn()})}function el(){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.title="\u5BA1\u6279\u6A21\u5F0F\uFF08\u70B9\u5F00\u770B\u8BF4\u660E\uFF09",o.innerHTML=`<span id="bv-mode-label"></span>${xe("chevron-down",'width="12" height="12"')}`;let c=g("div","bv-mode-menu");c.id="bv-mode-menu",c.hidden=!0;for(let[L,j,_]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 de=g("button");de.dataset.mode=L,de.innerHTML=`<b>${j}</b><span>${_}</span>`,de.onclick=()=>{c.hidden=!0,tl(L)},c.appendChild(de)}o.onclick=L=>{L.stopPropagation(),c.hidden=!c.hidden},a.append(o,c),document.addEventListener("click",L=>{a.contains(L.target)||(c.hidden=!0)});let d=g("button","btn","Allow all");d.id="bv-allow-all",d.title="Approve every pending request for this bot",d.onclick=()=>{if(!w.activeId)return;let L=w.approvals.filter(j=>j.botId===w.activeId);Promise.all(L.map(j=>O(`/api/bots/${j.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:j.id,allow:!0})}))).finally(()=>void re(!0))};let m=g("button","btn","Needs you "),h=g("span");h.id="bv-inbox-count",m.appendChild(h),m.onclick=()=>void Tn();let u=g("button","btn","Resume");u.onclick=()=>void Ii(L=>O(`/api/bots/${L}/resume`,{method:"POST"}).then(()=>re(!0)));let f=g("button","btn danger","Stop");f.onclick=()=>void Ii(L=>O(`/api/bots/${L}/stop`,{method:"POST"}).then(()=>re(!0)));let b=g("button","btn","Delete");b.onclick=()=>{w.activeId&&confirm("Delete this bot and its session?")&&O(`/api/bots/${w.activeId}`,{method:"DELETE"}).then(()=>{kn(),re(!0)})};let x=g("button","btn");x.innerHTML=xe("close",'width="14" height="14"'),x.title="Close bot view",x.onclick=()=>kn(),r.append(a,d,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=`${xe("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 B=()=>{me=k.scrollHeight-k.scrollTop-k.clientHeight<48,y.hidden=me};k.addEventListener("scroll",B,{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=L=>{L.key!=="Enter"||L.shiftKey||L.isComposing||E||L.keyCode===229||(L.preventDefault(),Ti())},$.oninput=()=>bn(null);let A=g("button","btn primary");A.id="bv-send",A.title="Send",A.setAttribute("aria-label","Send"),A.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>',A.onclick=()=>void Ti(),M.append($,A),M.addEventListener("click",L=>{L.target?.closest("button")||document.activeElement!==$&&$.focus()}),T.append(I,M),t.append(e,k,y,T),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||dl()}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||Xr||!t.value.trim())return;let e=w.activeId,n=t.value;bn(null),Li(!0);try{await O(`/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,Bt();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"),Bt(),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{Mi(JSON.parse(String(o.data)))}catch{}},a.onclose=()=>{w.activeId===t&&setTimeout(()=>{w.activeId===t&&re(!0)},1500)},await re(!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-label");s&&t.runtimeMode&&(s.textContent=Bi[t.runtimeMode]||t.runtimeMode);for(let a of document.querySelectorAll("#bv-mode-menu button"))a.classList.toggle("active",a.dataset.mode===t.runtimeMode);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=Kr(t.status))}var Bi={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"};async function tl(t){if(w.activeId)try{await O(`/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${Bi[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&&Ae()}function Ae(){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 nl(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"?sl(t):t.kind==="approval"?rl(t):g("div",`bv-notice bv-notice-${t.level}`,t.text)}function il(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(nl(l.snapshot,r)){if(s.kind==="assistant")il(l.node,s);else{let a=En(s);l.node.replaceWith(a),l.node=a}l.snapshot=r}}}n&&(t.scrollTop=t.scrollHeight)}function sl(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 rl(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 O(`/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",Ae(),re(!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 Mi(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(),ol()}else if(e==="message"){let s=t.message;if(!s||String(s.role||"")!=="assistant")return;let l=ll(s),r=al(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),Ae()}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),Ae()}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),Ae()}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),Ae();return}}l.push({kind:"approval",approval:s}),w.items.set(n,l),Ae()}else e==="notice"&&qe({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function ll(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 al(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 re(t=!1){try{let[e,n]=await Promise.all([O("/api/bots"),O("/api/bots/approvals")]);if(w.bots=e,w.approvals=n,Bt(),yn(),t&&w.activeId){let i=await O(`/api/bots/${w.activeId}/events?limit=300`);cl(i)}}catch{}}async function ol(){try{w.bots=await O("/api/bots"),Bt()}catch{}}function cl(t){if(w.activeId){w.items.set(w.activeId,[]);for(let e of t)Mi(e);Sn()}}function dl(){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=xe("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 pl(){return w.catalog||(w.catalog=await O("/api/bots/catalog")),w.catalog}async function zi(){return w.templates=await O("/api/bots/templates"),w.templates}async function rt(){let t=Cn("Bot templates"),[e,n]=await Promise.all([pl(),zi()]),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=()=>Ai(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`,O("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:f})}).then(()=>rt()).catch(b=>alert(b instanceof Error?b.message:String(b)))};let h=g("button","btn danger","Delete");h.onclick=()=>{confirm(`Delete template ${o.manifest.name}?`)&&O(`/api/bots/templates/${o.id}`,{method:"DELETE"}).then(()=>rt())};let u=g("span","bv-template-actions");u.append(d,m,h),c.appendChild(u),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=()=>Ai(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 O("/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 Ai(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 h=g("div","bv-check-grid"),u=[];for(let E of e.tools){let A=g("label","bv-check"),L=document.createElement("input");L.type="checkbox",L.checked=(i.tools?.allow||[]).includes(E.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(E.name),A.append(L,g("span",void 0,E.name)),h.appendChild(A),u.push({name:E.name,input:L})}m.appendChild(h);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(`
|
|
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>${J(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?J(n,!0):this.parser.parseInline(i),r=hi(t);if(r===null)return l;t=J(r,s);let a='<a href="'+t+'"';return e&&(a+=' title="'+J(e)+'"'),a+=">"+l+"</a>",a}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 J(n);t=s;let l=`<img src="${J(t)}" alt="${J(n)}"`;return e&&(l+=` title="${J(e)}"`),l+=">",l}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:J(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||Ie,this.options.renderer=this.options.renderer||new It,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 a=s,o=l[a.type].call({parser:this},a);if(o!==!1||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(a.type)){n+=o===!1?"":o??"";continue}}let r=s;switch(r.type){case"space":{n+=this.renderer.space(r);break}case"hr":{n+=this.renderer.hr(r);break}case"heading":{n+=this.renderer.heading(r);break}case"code":{n+=this.renderer.code(r);break}case"table":{n+=this.renderer.table(r);break}case"blockquote":{n+=this.renderer.blockquote(r);break}case"list":{n+=this.renderer.list(r);break}case"checkbox":{n+=this.renderer.checkbox(r);break}case"html":{n+=this.renderer.html(r);break}case"def":{n+=this.renderer.def(r);break}case"paragraph":{n+=this.renderer.paragraph(r);break}case"text":{n+=this.renderer.text(r);break}default:{let a='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}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],r=this.options.extensions?.renderers;if(r&&Object.hasOwn(r,l.type)&&r[l.type]){let o=r[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 a=l;switch(a.type){case"escape":{i+=n.text(a);break}case"html":{i+=n.html(a);break}case"link":{i+=n.link(a);break}case"image":{i+=n.image(a);break}case"checkbox":{i+=n.checkbox(a);break}case"strong":{i+=n.strong(a);break}case"em":{i+=n.em(a);break}case"codespan":{i+=n.codespan(a);break}case"br":{i+=n.br(a);break}case"del":{i+=n.del(a);break}case"text":{i+=n.text(a);break}default:{let o='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return i}},st=class{options;block;constructor(t){this.options=t||Ie}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?se.lex:se.lexInline}provideParser(t=this.block){return t?re.parse:re.parseInline}};function Ee(t,e){if(Array.isArray(e))for(let n=0;n<e.length;n++)t.push(e[n]);else t.push(e)}var Ur=class{defaults=tn();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=re;Renderer=It;TextRenderer=mn;Lexer=se;Tokenizer=Me;Hooks=st;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let i of t)switch(Ee(n,e.call(this,i)),i.type){case"table":{let s=i;for(let l of s.header)Ee(n,this.walkTokens(l.tokens,e));for(let l of s.rows)for(let r of l)Ee(n,this.walkTokens(r.tokens,e));break}case"list":{let s=i;Ee(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 r=s[l].flat(1/0);Ee(n,this.walkTokens(r,e))}}):s.tokens&&Ee(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,r=e.renderers[s.name];r?e.renderers[s.name]=function(...a){let o=l.apply(this,a);return o===!1&&(o=r.apply(this,a)),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 It(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 r=l,a=n.renderer[r];if(a===void 0)continue;let o=s[r];s[r]=(...c)=>{let d=a.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 Me(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 r=l,a=n.tokenizer[r];if(a===void 0)continue;let o=s[r];s[r]=(...c)=>{let d=a.apply(s,c);return d===!1&&(d=o.apply(s,c)),d}}i.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new st;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 r=l,a=n.hooks[r];if(a===void 0)continue;let o=s[r];st.passThroughHooks.has(l)?s[r]=c=>{if(s.options.async&&st.passThroughHooksRespectAsync.has(l))return(async()=>{let m=await a.call(s,c);return o.call(s,m)})();let d=a.call(s,c);return o.call(s,d)}:s[r]=(...c)=>{if(s.options.async)return(async()=>{let m=await a.apply(s,c);return m===!1&&(m=await o.apply(s,c)),m})();let d=a.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(r){let a=[];return Ee(a,l.call(this,r)),s&&Ee(a,s.call(this,r)),a}}this.defaults={...this.defaults,...i}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return se.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 r=s.hooks?await s.hooks.preprocess(e):e,a=await(s.hooks?await s.hooks.provideLexer(t):t?se.lex:se.lexInline)(r,s),o=s.hooks?await s.hooks.processAllTokens(a):a;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 r=(s.hooks?s.hooks.provideLexer(t):t?se.lex:se.lexInline)(e,s);s.hooks&&(r=s.hooks.processAllTokens(r)),s.walkTokens&&this.walkTokens(r,s.walkTokens);let a=(s.hooks?s.hooks.provideParser(t):t?re.parse:re.parseInline)(r,s);return s.hooks&&(a=s.hooks.postprocess(a)),a}catch(r){return l(r)}}}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>"+J(i.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(i);throw i}}},Ae=new Ur;function R(t,e){return Ae.parse(t,e)}function Zr(t,e){return Ae.parseInline(t,e)}R.options=R.setOptions=function(t){return Ae.setOptions(t),R.defaults=Ae.defaults,Qn(R.defaults),R},R.getDefaults=tn,R.defaults=Ie;function Jr(...t){return Ae.use(...t),R.defaults=Ae.defaults,Qn(R.defaults),R}R.use=Jr,R.walkTokens=function(t,e){return Ae.walkTokens(t,e)},R.parseInline=Zr,R.Parser=re,R.parser=re.parse,R.Renderer=It,R.TextRenderer=mn,R.Lexer=se,R.lexer=se.lex,R.Tokenizer=Me,R.Hooks=st,R.parse=R;var Kl=R.options,Ql=R.setOptions,Gl=R.walkTokens,ea=R.parseInline,ta=re.parse,na=se.lex,Yr=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 Yr.has(new URL(e).protocol)?e:null}catch{return null}}var xi=t=>/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith("mailto:"),Ei=4e5,Xr=200;function Kr(t){let e=new Map,n=0;function i(m,u){let h=m.length+Xr;if(!(h>Ei/4)){e.set(m,{fragment:u,chars:h}),n+=h;for(let f of e.keys()){if(n<=Ei)break;let b=e.get(f);b&&(e.delete(f),n-=b.chars)}}}function s(m,u){u.split(`
|
|
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
86
|
`),b.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";let x=g("select","bv-input");x.appendChild(new Option("default (Pi settings)",""));for(let E of e.models)x.appendChild(new Option(`${E.provider}/${E.model}`,`${E.provider}
|
|
87
87
|
${E.model}`));i.model?.provider&&i.model?.id&&(x.value=`${i.model.provider}
|
|
88
|
-
${i.model.id}`);let k=g("select","bv-input");for(let E of["","off","minimal","low","medium","high","xhigh","max"])k.appendChild(new Option(E||"default",E));i.model?.thinking&&(k.value=i.model.thinking);let y=g("select","bv-input");for(let E of["supervised","auto-accept-edits","full-access"])y.appendChild(new Option(E,E));y.value=i.permissions?.runtimeMode||"supervised";let
|
|
89
|
-
`),
|
|
90
|
-
`).map(_=>_.trim()).filter(Boolean),mcp:
|
|
88
|
+
${i.model.id}`);let k=g("select","bv-input");for(let E of["","off","minimal","low","medium","high","xhigh","max"])k.appendChild(new Option(E||"default",E));i.model?.thinking&&(k.value=i.model.thinking);let y=g("select","bv-input");for(let E of["supervised","auto-accept-edits","full-access"])y.appendChild(new Option(E,E));y.value=i.permissions?.runtimeMode||"supervised";let z=g("select","bv-input");z.appendChild(new Option("ignore project .pi (recommended)","ignore")),z.appendChild(new Option("inherit project .pi (needs trust)","inherit")),z.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 M=(E,B)=>{let C=g("div","bv-field");return C.appendChild(g("label","bv-label",E)),C.appendChild(B),C};t.append(M("Name",s),M("Description",l),M("System prompt",r),a.element,o.element,c.element,M("MCP preset",d),m,M("Always deny tools",f),M("Packages",b),M("Model",x),M("Thinking level",k),M("Approval mode",y),M("Project resources",z),T);let $=g("button","btn primary",n?"Save template":"Create template");$.onclick=async()=>{let[E,B]=x.value.split(`
|
|
89
|
+
`),C=e.mcp.find(_=>_.id===d.value),F={name:s.value.trim()||"bot",description:l.value.trim()||void 0,system:r.value.trim()||void 0,skills:a.get(),extensions:o.get().map(_=>(_.startsWith("builtin:"),_)),prompts:c.get(),packages:b.value.split(`
|
|
90
|
+
`).map(_=>_.trim()).filter(Boolean),mcp:C?{mcpServers:C.servers}:void 0,tools:{allow:h.filter(_=>_.input.checked).map(_=>_.name),deny:f.value.split(",").map(_=>_.trim()).filter(Boolean)},model:E?{provider:E,id:B,thinking:k.value||void 0}:void 0,permissions:{runtimeMode:y.value},projectResources:z.value==="inherit"?"inherit":"ignore",orchestrator:I.checked||void 0};try{await q("/api/bots/templates",{method:"POST",body:JSON.stringify({id:n?.id,manifest:F})}),Mt(),await rt()}catch(_){alert(_ instanceof Error?_.message:String(_))}},t.appendChild($)}async function ml(){return Di("")}async function Di(t){let e=Cn("New bot"),n=await Ri();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 r=t||w.bots[0]?.projectPath||"";l.value=r;let a=g("select","bv-input");a.appendChild(new Option("shared \u2014 run in the project folder","shared")),a.appendChild(new Option("worktree \u2014 isolated git worktree","worktree")),e.append(At("Template",i),At("Title",s),At("Project path",l),At("Workspace",a));let o=g("button","btn primary","Create bot");o.onclick=async()=>{try{let c=await q("/api/bots",{method:"POST",body:JSON.stringify({templateId:i.value,title:s.value.trim()||void 0,projectPath:l.value.trim()||void 0,isolation:a.value})});Mt(),await le(!0),await $i(c.id)}catch(c){alert(c instanceof Error?c.message:String(c))}},e.appendChild(o)}function At(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(w.approvals=await q("/api/bots/approvals"),w.approvals.length===0){t.appendChild(g("div","bots-empty","Nothing waiting."));return}for(let e of w.approvals){let n=g("div","bv-approval");n.appendChild(g("div","bv-approval-title",`${e.botTitle}: ${e.title}`)),e.message&&n.appendChild(g("pre","bv-pre",e.message));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 danger","Deny"),a=async o=>{await q(`/api/bots/${e.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:e.id,allow:o,reason:i.value||void 0})}),await le(!0),await Tn()};l.onclick=()=>void a(!0),r.onclick=()=>void a(!1),s.append(i,l,r),n.appendChild(s),t.appendChild(n)}}function fl(){window.__botsInited||(window.__botsInited=!0,nl(),tl(),window.__openBot=$i,document.addEventListener("click",t=>{let e=t.target;e&&(e.closest(".session-item.bot-item")||e.closest(".session-item")&&w.activeId&&setTimeout(()=>kn(),0))},!0),document.addEventListener("click",t=>{let e=t.target;!e||!w.activeId||(e.closest("#mode-files")||e.closest(".file-tree-item")||e.closest(".file-roots-list li"))&&kn()}),le(!0),w.pollTimer=window.setInterval(()=>{document.hidden||le()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(w.pollTimer)))}var lt=window.__TMUX_WEB_SHELL__,N=null,j=null,at=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null,Y=at;window.__tmuxWebScopeAgent=at;var In="sessions",ke="",Bt="",Rt="",Hi="";function U(t){return Y?"/a/"+encodeURIComponent(Y)+t:t}var P=document.getElementById("sidebar-content"),Re=document.getElementById("main-placeholder"),te=document.getElementById("terminal-container"),ot=document.getElementById("file-editor"),gl=document.getElementById("fe-path"),ae=document.getElementById("fe-status"),ct=document.getElementById("fe-content"),Pe=document.getElementById("fe-save"),vl=document.getElementById("fe-delete"),bl=document.getElementById("fe-back"),_i=document.getElementById("fe-new-name"),kl=document.getElementById("fe-new-btn"),$n=document.getElementById("settings-backdrop"),Fi=document.getElementById("settings-popover"),Ni=document.querySelector(".sidebar"),Oi="tmux-web-force-narrow";function Pt(){try{return localStorage.getItem(Oi)==="1"}catch{return!1}}function qi(){document.documentElement.classList.toggle("force-narrow",Pt()),Pt()&&ji()&&dt()}function ji(){return Pt()?!0:window.matchMedia("(max-width: 640px)").matches}function dt(){ji()&&Ni.classList.add("collapsed")}function Vi(){Ni.classList.remove("collapsed")}window.__collapseSidebar=dt,document.getElementById("mode-sessions").addEventListener("click",()=>{Vi(),Wi("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{Vi(),Wi("files")});function Wi(t){In=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"?(zn="",we()):Rl()}var zn="";async function we(){if(In!=="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===zn)return;zn=i,Cl(e)}catch{P.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 Ui="tmux-web-sidebar-group-collapsed";function Zi(){try{return new Set(JSON.parse(localStorage.getItem(Ui)||"[]"))}catch{return new Set}}function wl(t){try{localStorage.setItem(Ui,JSON.stringify([...t]))}catch{}}function yl(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 r=s.slice(-l).join("/");if(!e.some(a=>!a||a===t?!1:(n&&(a===n||a.startsWith(n+"/"))?"~"+a.slice(n.length):a).split("/").filter(Boolean).slice(-l).join("/")===r))return r}return i}function xl(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=`${ve("bot",'class="bot-icon"')}<span>${D(t.title)}</span><span class="bot-status-dot" style="background:${n}"></span>`,e.addEventListener("click",i=>{i.stopPropagation(),window.__openBot?.(t.id)}),e}function Ji(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||[],r=new Map;for(let c of l)s.has(c.projectPath)||s.set(c.projectPath,[]),r.has(c.projectPath)||r.set(c.projectPath,[]),r.get(c.projectPath).push(c);let a=[...s.keys()],o=Zi();for(let[c,d]of s){let m=yl(c,a,e),u=o.has(c),h=document.createElement("div");if(h.className="session-group-header"+(u?" collapsed":""),h.title=c||"No working directory",h.innerHTML=`<span class="sg-folder">📁</span><span class="sg-label">${D(m)}</span>`,!n&&c){let b=document.createElement("button");b.className="sg-add-bot",b.innerHTML=ve("add",'width="12" height="12"'),b.title=`New bot in ${c}`,b.addEventListener("click",x=>{x.stopPropagation(),An(c)}),h.appendChild(b)}h.addEventListener("click",()=>{let b=Zi(),x=h.nextElementSibling;b.has(c)?(b.delete(c),h.classList.remove("collapsed"),x?.classList.remove("collapsed")):(b.add(c),h.classList.add("collapsed"),x?.classList.add("collapsed")),wl(b)});let f=document.createElement("div");f.className="session-group-body"+(u?" collapsed":"");for(let b of d)f.appendChild(n?El(b,n,i):Sl(b));for(let b of r.get(c)||[])f.appendChild(xl(b));P.appendChild(h),P.appendChild(f)}}function El(t,e,n){let i=document.createElement("div");i.className="session-item"+(t.name===j&&Y===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
91
|
<span>${D(t.name)}</span>${n?"":'<span class="meta">offline</span>'}
|
|
92
|
-
<button class="session-edit-btn" data-session="${D(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")||pt(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
|
|
92
|
+
<button class="session-edit-btn" data-session="${D(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")||pt(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 Sl(t){let e=document.createElement("div");e.className="session-item"+(t.name===j&&!Y?" 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
93
|
<span>${D(t.name)}</span>
|
|
94
94
|
<button class="session-edit-btn" data-session="${D(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")||pt(t.name)});let n=e.querySelector(".session-edit-btn");return n&&n.addEventListener("click",i=>{i.stopPropagation(),Wt(t.name,n)}),e}function
|
|
95
|
+
`,e.addEventListener("click",i=>{i.target.closest(".session-edit-btn")||pt(t.name)});let n=e.querySelector(".session-edit-btn");return n&&n.addEventListener("click",i=>{i.stopPropagation(),Wt(t.name,n)}),e}function Cl(t){P.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"+(at?" clickable":""),n.textContent=at?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",at&&(n.title="Back to hub",n.addEventListener("click",()=>{window.location.href="/"})),P.appendChild(n),Ji(e,t.home);let i=t.agents||[];for(let l of i){if(!l.sessions||l.sessions.length===0)continue;let r=l.agentId===Y,a=document.createElement("div");a.className="sidebar-section-label machine-label"+(l.online?"":" agent-offline-label")+(!r&&l.online?" clickable":""),a.textContent=l.agentName+(l.online?"":" (offline)"),!r&&l.online&&(a.title="\u6253\u5F00 "+l.agentName,a.addEventListener("click",()=>{window.location.href="/a/"+encodeURIComponent(l.agentId)+"/"})),P.appendChild(a),Ji(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",P.appendChild(l);for(let r of s){let a=document.createElement("div");a.className="session-item session-tombstone",a.setAttribute("data-session",r.name),r.agentId&&a.setAttribute("data-agent",r.agentId);let o=r.agentId?r.agentOnline?" (agent)":" (agent \u79BB\u7EBF)":"";a.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"></svg>
|
|
96
96
|
<span>${D(r.name)}</span><span class="meta">\u5931\u6548${o}</span>
|
|
97
|
-
<button class="session-edit-btn" data-session="${D(r.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>`,a.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",a.addEventListener("click",()=>{Wt(r.name,a,{tombstone:!0,agentId:r.agentId})});let c=a.querySelector(".session-edit-btn");c&&c.addEventListener("click",d=>{d.stopPropagation(),Wt(r.name,c,{tombstone:!0,agentId:r.agentId})}),P.appendChild(a)}}}function D(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function pt(t,e){if(
|
|
97
|
+
<button class="session-edit-btn" data-session="${D(r.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>`,a.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",a.addEventListener("click",()=>{Wt(r.name,a,{tombstone:!0,agentId:r.agentId})});let c=a.querySelector(".session-edit-btn");c&&c.addEventListener("click",d=>{d.stopPropagation(),Wt(r.name,c,{tombstone:!0,agentId:r.agentId})}),P.appendChild(a)}}}function D(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function pt(t,e){if(j===t&&N&&Y===(e||null))return;ot.style.display="none",Re.style.display="none",te.style.display="",te.classList.add("terminal-pending"),dt(),N&&(jt(),N.destroy(),N=null),j=t,Y=e||null,window.__tmuxWebScopeAgent=Y,window.__tmuxWebCurrentSession=j,Xl(t,e);let n=Dn(t,e);cs.set(n,Date.now()+Jl);let i=We.get(n);if(i&&i.state==="working"){i.state="idle",i.doneUntil=void 0,i.unread=!1;let s=P.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 P.querySelectorAll(".session-item"))s.classList.toggle("active",s.getAttribute("data-session")===t&&(s.getAttribute("data-agent")||null)===Y);try{N=await Ps(te,t,{terminal:lt.terminal,scrollback:lt.scrollback,theme:lt.theme,wsBase:Y?"/ws/a/"+encodeURIComponent(Y):lt.wsBase||"/ws"}),ss()}catch(s){console.error("[shell] terminal init failed:",s);let l=s&&typeof s=="object"&&"message"in s?s.message:String(s);te.textContent="Failed to open terminal for "+t+": "+l,te.classList.remove("terminal-pending")}}var Dt=[],V=null,Yi=!1;function Ll(t){if(!V||!V.files.length)return null;let e=V.repoRoot;if(!e||!t.startsWith(e))return null;let n=t.slice(e.length+1);for(let i of V.files)if(i.path===n)return i.status;return null}async function Tl(t){Yi=!0;try{let e=await fetch(U("/api/git/status?path="+encodeURIComponent(t)));e.ok?V=await e.json():V=null}catch{V=null}finally{Yi=!1}}function Il(){if(!V||!V.branch)return"";let{branch:t,linesAdded:e,linesRemoved:n}=V,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
|
-
${D(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>"}P.addEventListener("click",t=>{t.target.closest(".sidebar-git")&&je&&V&&(t.stopPropagation(),
|
|
99
|
+
${D(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>"}P.addEventListener("click",t=>{t.target.closest(".sidebar-git")&&je&&V&&(t.stopPropagation(),es())});var ut=document.getElementById("header-git"),Xi=document.getElementById("git-diff-view"),Ki=document.getElementById("gd-path"),Ht=document.getElementById("gd-status"),_t=document.getElementById("gd-content"),$l=document.getElementById("gd-back"),je=null;function ht(t){if(!t||!t.branch){ut.style.display="none",je=null;return}je=t.repoRoot;let{branch:e,linesAdded:n,linesRemoved:i}=t,s=`<span class="branch">${D(e)}</span>`;(n>0||i>0)&&(s+=`<span class="sep">\xB7</span>+<span class="diff-add">${n}</span> <span class="diff-del">-${i}</span>`),ut.innerHTML=s,ut.style.display="block"}ut.addEventListener("click",t=>{je&&V&&(t.stopPropagation(),es())});var X=document.getElementById("git-popover"),Ft=document.getElementById("git-popover-backdrop");function Mn(){let t=ut.getBoundingClientRect();X.style.top=t.bottom+4+"px",X.style.left=Math.max(8,Math.min(t.left,window.innerWidth-400))+"px"}function Qi(){let t=je,e=document.getElementById("git-popover-browse");e&&e.addEventListener("click",()=>{if(Ot(),t){In="files",document.querySelectorAll(".mode-btn").forEach(i=>i.classList.remove("active"));let n=document.getElementById("mode-files");n&&n.classList.add("active"),ye(t)}})}var Gi="";function es(){if(!V)return;let t=V.files||[];if(!t.length)X.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
|
|
100
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,r="";switch(i.status){case"M":r='<span class="git-file-status M">M</span>';break;case"A":r='<span class="git-file-status A">A</span>';break;case"D":r='<span class="git-file-status D">D</span>';break;case"?":r='<span class="git-file-status ?">?</span>';break;case"R":r='<span class="git-file-status R">R</span>';break}e+=`<div class="git-popover-item" data-idx="${n}">
|
|
101
101
|
${r}<span class="file-path">${D(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>',Gi=e,X.innerHTML=e,X.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",()=>ns(s.path)))})}Mn(),X.classList.add("open"),Ft.classList.add("open"),Qi()}function zl(){return window.innerWidth>=1024}function ts(t,e){let n=(t+(e&&t?`
|
|
105
105
|
`:"")+e).split(`
|
|
106
|
-
`),i="",s=0,l=0;for(let r of n){let a=r;if(a.startsWith("@@")){let o=a.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">${D(a)}</span></div>`;continue}if(a.startsWith("diff --git")||a.startsWith("index ")||a.startsWith("--- ")||a.startsWith("+++ ")||a.startsWith("new file")||a.startsWith("deleted file")){a.startsWith("diff --git")&&(i+=`<div class="diff-line header"><span class="ln-body">${D(a)}</span></div>`);continue}if(a.startsWith("+"))l++,i+=`<div class="diff-line add"><span class="ln-no">${l}</span><span class="ln-body">${D(a)}</span></div>`;else if(a.startsWith("-"))s++,i+=`<div class="diff-line del"><span class="ln-no">${s}</span><span class="ln-body">${D(a)}</span></div>`;else if(a.startsWith("\\"))i+=`<div class="diff-line"><span class="ln-body">${D(a)}</span></div>`;else{if(!a&&!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">${D(a)}</span></div>`}}return{html:i,lineCount:n.length}}var Nt=null;async function
|
|
106
|
+
`),i="",s=0,l=0;for(let r of n){let a=r;if(a.startsWith("@@")){let o=a.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">${D(a)}</span></div>`;continue}if(a.startsWith("diff --git")||a.startsWith("index ")||a.startsWith("--- ")||a.startsWith("+++ ")||a.startsWith("new file")||a.startsWith("deleted file")){a.startsWith("diff --git")&&(i+=`<div class="diff-line header"><span class="ln-body">${D(a)}</span></div>`);continue}if(a.startsWith("+"))l++,i+=`<div class="diff-line add"><span class="ln-no">${l}</span><span class="ln-body">${D(a)}</span></div>`;else if(a.startsWith("-"))s++,i+=`<div class="diff-line del"><span class="ln-no">${s}</span><span class="ln-body">${D(a)}</span></div>`;else if(a.startsWith("\\"))i+=`<div class="diff-line"><span class="ln-body">${D(a)}</span></div>`;else{if(!a&&!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">${D(a)}</span></div>`}}return{html:i,lineCount:n.length}}var Nt=null;async function ns(t){let e=je;if(e)if(Ot(),zl()){te.style.display="none",N&&(jt(),N.destroy(),N=null,Nt=j,j=null),ht(null),ot.style.display="none",Re.style.display="none",Xi.style.display="flex",Ki.textContent=t,Ht.textContent="Loading\u2026",_t.innerHTML="";try{let n=await fetch(U("/api/git/diff?path="+encodeURIComponent(e)+"&file="+encodeURIComponent(t)));if(!n.ok)throw new Error(await n.text());let i=await n.json();Al(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: ${D(i)}</div>`}}else{X.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
107
107
|
<button class="diff-back">\u2190 Back</button>
|
|
108
108
|
<span class="diff-filename">${D(t)}</span>
|
|
109
109
|
<span class="diff-loading">Loading\u2026</span>
|
|
110
|
-
</div></div>`,Mn(),X.classList.add("open"),Ft.classList.add("open");try{let n=await fetch(U("/api/git/diff?path="+encodeURIComponent(e)+"&file="+encodeURIComponent(t)));if(!n.ok)throw new Error(await n.text());let i=await n.json()
|
|
110
|
+
</div></div>`,Mn(),X.classList.add("open"),Ft.classList.add("open");try{let n=await fetch(U("/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);X.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
111
111
|
<button class="diff-back">\u2190 Back</button>
|
|
112
112
|
<span class="diff-filename">${D(t)}</span>
|
|
113
|
-
</div><div class="diff-empty">Error loading diff: ${D(i)}</div></div>`}}}function
|
|
113
|
+
</div><div class="diff-empty">Error loading diff: ${D(i)}</div></div>`}}}function Ml(t,e,n){if(!e&&!n){X.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
114
114
|
<button class="diff-back">\u2190 Back</button>
|
|
115
115
|
<span class="diff-filename">${D(t)}</span>
|
|
116
|
-
</div><div class="diff-empty">No diff content available</div></div>`;return}let{html:i,lineCount:s}=
|
|
116
|
+
</div><div class="diff-empty">No diff content available</div></div>`;return}let{html:i,lineCount:s}=ts(e,n);X.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
117
117
|
<button class="diff-back">\u2190 Back</button>
|
|
118
118
|
<span class="diff-filename">${D(t)}</span>
|
|
119
119
|
<span class="diff-filesize">${s} lines</span>
|
|
120
|
-
</div><div class="diff-content">${i}</div></div>`,X.querySelector(".diff-back")?.addEventListener("click",()=>{X.innerHTML=
|
|
120
|
+
</div><div class="diff-content">${i}</div></div>`,X.querySelector(".diff-back")?.addEventListener("click",()=>{X.innerHTML=Gi,Mn(),V&&X.querySelectorAll(".git-popover-item").forEach(l=>{let r=parseInt(l.dataset.idx||"0",10),a=V.files[r];!a||a.status==="D"||(l.style.cursor="pointer",l.addEventListener("click",()=>ns(a.path)))}),Qi()})}function Al(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}=ts(e,n);Ki.textContent=t,Ht.textContent=s+" lines",_t.innerHTML=i}function Bl(){Xi.style.display="none",Nt?(te.style.display="",te.classList.add("terminal-pending"),pt(Nt),Nt=null):j?(te.style.display="",te.classList.add("terminal-pending"),ss()):Re.style.display="flex"}$l.addEventListener("click",Bl);function Ot(){X.classList.remove("open"),Ft.classList.remove("open")}Ft.addEventListener("click",Ot),document.addEventListener("keydown",t=>{t.key==="Escape"&&(Ot(),Yt())});async function is(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();V=i,ht(i);return}}}catch{}V=null,ht(null)}var qt=null;function ss(){jt(),j&&(is(j),qt=setInterval(()=>{j&&is(j)},3e4))}function jt(){qt&&(clearInterval(qt),qt=null)}async function An(t){let e=t;if(e.startsWith("~"))try{let n=await(await fetch(U("/api/fs/list?path="+encodeURIComponent(e)))).json();typeof n.path=="string"&&n.path&&(e=n.path)}catch{}e=e.replace(/\/+$/,"")||"/",Di(e)}function rs(t,e){let n=document.createElement("button");n.className="file-tree-bot-btn",n.innerHTML=ve("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(),An(e)}),t.appendChild(n)}function Rl(){if(Dt=lt.fsRoots||[],Dt.length===0){if(j){Pl(j);return}ye("");return}P.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> ${D(t)}`,e.addEventListener("click",()=>ye(t)),rs(e,t),P.appendChild(e)}}async function Pl(t){P.innerHTML='<div class="file-tree-empty">Loading...</div>';try{let e=await(await fetch(U("/api/fs/session-path?session="+encodeURIComponent(t)))).json();e.path?ye(e.path):P.innerHTML='<div class="file-tree-info">Could not determine session directory.</div>'}catch{P.innerHTML='<div class="file-tree-error">Failed to get session directory</div>'}}async function ye(t){ke=t,P.innerHTML='<div class="file-tree-empty">Loading...</div>';let e=Tl(t);try{let n=await(await fetch(U("/api/fs/list?path="+encodeURIComponent(t)))).json(),i=typeof n.path=="string"&&n.path?n.path:t;if(i&&(ke=i),await e,P.innerHTML="",i){let r=document.createElement("div");r.className="file-tree-item file-tree-create-bot",r.innerHTML=`<span class="file-tree-bot-plus">${ve("add",'width="11" height="11"')}</span> Create bot in this folder`,r.title=`Create bot in ${i}`,r.addEventListener("click",()=>void An(i)),P.appendChild(r)}ht(V),P.innerHTML+=Il();let s=Dl(i||t);if(s&&!Dt.some(r=>i===r)){let r=document.createElement("div");r.className="file-tree-item",r.innerHTML="..",r.addEventListener("click",()=>ye(s)),P.appendChild(r)}if(n.dirs)for(let r of n.dirs){let a=r.split("/").pop()||r.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> ${D(a)}`,o.addEventListener("click",()=>ye(r)),rs(o,r),P.appendChild(o)}else P.innerHTML="";let l=n.files||[];for(let r of l){let a=r.split("/").pop()||r.split("\\").pop(),o=Ll(r),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}${D(a)}`,m.addEventListener("click",()=>Hl(r)),P.appendChild(m)}}catch{P.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function Dl(t){let e=t.lastIndexOf("/");return e<=0?null:t.substring(0,e)}async function Hl(t){Bt=t,te.style.display="none",N&&(jt(),N.destroy(),N=null,j=null),ht(null),dt(),Re.style.display="none",ot.style.display="flex",gl.textContent=t,ae.textContent="Loading...",Pe.style.display="none";try{let e=await fetch(U("/api/file?path="+encodeURIComponent(t)));if(!e.ok){let i=await e.json();ae.textContent=i.error||"Failed to load",ct.value="";return}let n=await e.json();ct.value=n.content,Rt=n.content,Hi=n.content,ae.textContent=n.size+" bytes",Pe.style.display=""}catch{ae.textContent="Failed to load",ct.value=""}}ct.addEventListener("input",()=>{Rt=ct.value}),Pe.addEventListener("click",async()=>{Pe.textContent="Saving...",Pe.disabled=!0;try{let t=await fetch(U("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Bt,content:Rt})});if(!t.ok){let e=await t.json();ae.textContent=e.error||"Save failed";return}Hi=Rt,ae.textContent="Saved"}catch{ae.textContent="Save failed"}finally{Pe.disabled=!1,Pe.textContent="Save"}}),vl.addEventListener("click",async()=>{if(confirm("Delete "+Bt+"?"))try{let t=await fetch(U("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:Bt})});if(!t.ok){let e=await t.json();ae.textContent=e.error||"Delete failed";return}ot.style.display="none",Re.style.display="flex",ke&&ye(ke)}catch{ae.textContent="Delete failed"}}),bl.addEventListener("click",()=>{ot.style.display="none",Re.style.display="flex",ke&&ye(ke)}),kl.addEventListener("click",async()=>{let t=_i.value.trim();if(!t)return;let e=ke+"/"+t;try{let n=await fetch(U("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})});if(!n.ok){let i=await n.json();ae.textContent=i.error||"Create failed";return}_i.value="",ke&&ye(ke)}catch{ae.textContent="Create failed"}});var Vt=document.getElementById("force-narrow-toggle");Vt&&(Vt.checked=Pt(),Vt.addEventListener("change",()=>{try{localStorage.setItem(Oi,Vt.checked?"1":"0")}catch{}qi(),we()})),qi(),document.getElementById("mode-settings").addEventListener("click",()=>{let t=Fi.classList.toggle("open");$n.classList.toggle("open",t)}),$n.addEventListener("click",()=>{Fi.classList.remove("open"),$n.classList.remove("open")});var ne="",oe=!1,ce,mt=document.createElement("div");mt.className="session-popover-backdrop",document.body.appendChild(mt);var de=document.createElement("div");de.id="session-popover",de.className="session-popover",de.style.display="none",de.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;fe.rows=Math.min(t,4)}),fe.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),
|
|
130
|
+
<button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>`,document.body.appendChild(de);function _l(t){let e=t.getBoundingClientRect(),n=window.innerHeight,i=de.offsetHeight||240,s=e.bottom+4;s+i>n-8&&(s=Math.max(8,e.top-i-4)),de.style.top=s+"px",de.style.left=Math.max(8,Math.min(e.left,window.innerWidth-240))+"px"}function Wt(t,e,n){ne=t,oe=!!n?.tombstone,ce=n?.agentId;let i=document.getElementById("sp-name");i.value=t;let s=de.querySelector(".sp-field label");s.textContent=oe?"\u91CD\u547D\u540D (\u4EC5\u8BB0\u5F55\uFF0C\u4E0D\u91CD\u5EFA)":"Rename session";let l=document.getElementById("sp-rebuild");l.style.display=oe?"":"none";let r=document.getElementById("sp-delete");r.textContent=oe?"\u5220\u9664\u8BB0\u5F55":"Delete",r.title=oe?"\u5220\u9664\u5931\u6548\u8BB0\u5F55\uFF08\u5893\u7891\u6D88\u5931\uFF09":"Delete session";let a=document.getElementById("sp-divider");a&&(a.style.display=oe?"":"none");let o=document.getElementById("sp-save");o.textContent=oe?"\u91CD\u547D\u540D":"Save",mt.classList.add("open"),de.style.display="block",_l(e),setTimeout(()=>i.focus(),50)}function De(){mt.classList.remove("open"),de.style.display="none"}mt.addEventListener("click",De),document.getElementById("sp-save").addEventListener("click",async()=>{let t=document.getElementById("sp-name").value.trim();if(!t||t===ne){De();return}try{let e=oe?{oldName:ne,newName:t,agentId:ce}:{oldName:ne,newName:t,...ce?{agentId:ce}:{}};if(!(await fetch(U(oe?"/api/sessions/rename-tombstone":"/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok)return;De(),we(),!oe&&j===ne&&(ce??null)===Y&&pt(t,ce)}catch{}}),document.getElementById("sp-rebuild").addEventListener("click",async()=>{if(confirm('\u91CD\u5EFA\u4F1A\u8BDD "'+ne+'" (\u540C\u540D\u540C\u8DEF\u5F84\uFF0C\u5185\u5BB9\u4E3A\u7A7A)\uFF1F'))try{let t=await fetch(U("/api/sessions/rebuild"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ne,agentId:ce})});if(!t.ok){let e=await t.json();alert(e.error||"\u91CD\u5EFA\u5931\u8D25");return}De(),we()}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(oe){if(!confirm('\u5220\u9664\u5931\u6548\u8BB0\u5F55 "'+ne+'"\uFF1F'))return;try{if(!(await fetch(U("/api/sessions/dismiss"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ne,agentId:ce})})).ok)return;De(),we()}catch{}return}if(confirm('Delete session "'+ne+'"?'))try{if(!(await fetch(U("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ne,...ce?{agentId:ce}:{}})})).ok)return;De(),j===ne&&(ce??null)===Y&&(N&&(N.destroy(),N=null),j=null,te.style.display="none",Re.style.display="flex"),we()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",De);var ls={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"),Fl=new Set(["up","down","left","right","tab","s-tab","space"]),Nl=400,Ol=80,ft=0,Zt=0,Jt=!1;function ql(){ft&&(clearTimeout(ft),ft=0),Zt&&(clearInterval(Zt),Zt=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;Fl.has(n)&&(Jt=!1,ft=setTimeout(()=>{ft=0,Jt=!0,Zt=setInterval(()=>{let i=ls[n];i&&N&&N.sendInput(i)},Ol)},Nl))});for(let t of["pointerup","pointercancel","pointerleave"])Ut.addEventListener(t,ql);Ut.addEventListener("click",t=>{let e=t.target.closest("button[data-key]");if(!e||!N)return;if(Jt){Jt=!1;return}let n=ls[e.dataset.key];n&&(N.sendInput(n),N.focus())});var fe=document.getElementById("mk-input"),as=document.getElementById("mk-send");function os(){if(!fe||!N)return;let t=fe.value;t&&(N.sendInput(t+"\r"),fe.value="",fe.rows=1,N.focus())}if(fe&&(fe.addEventListener("input",()=>{fe.rows=1;let t=fe.value.split(`
|
|
131
|
+
`).length;fe.rows=Math.min(t,4)}),fe.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),os())})),as&&as.addEventListener("click",os),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"),gt=document.getElementById("proc-list"),jl=document.getElementById("proc-close"),Rn=document.getElementById("proc-backdrop"),Vl=document.getElementById("header-ram");function Wl(){gt.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(U("/api/system/processes")).then(t=>t.json()).then(t=>{if(!Array.isArray(t)||!t.length){gt.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="'+D(n.command)+'">'+D(n.command)+'</span><button class="proc-kill" title="Kill PID '+n.pid+'">×</button></div>'}gt.innerHTML=e;for(let n of gt.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(U("/api/system/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:parseInt(l.dataset.pid,10)})}).then(r=>r.json()).then(r=>{r.ok?l.style.opacity="0.3":alert("Failed: "+(r.error||"unknown"))}).catch(()=>alert("Network error"))})}}).catch(()=>{gt.innerHTML='<div class="proc-empty">Failed to load</div>'})}function Ul(){Bn.classList.add("open"),Rn.classList.add("open"),Wl()}function Yt(){Bn.classList.remove("open"),Rn.classList.remove("open")}Vl.addEventListener("click",t=>{t.stopPropagation(),Bn.classList.contains("open")?Yt():Ul()}),jl.addEventListener("click",Yt),Rn.addEventListener("click",Yt);var Zl=2e3,vt=null,Pn=null,Ve=new Map,We=new Map,Jl=5e3,cs=new Map;function Dn(t,e){return(e?"a:"+e+":":"l:")+t}function Yl(t,e,n){let i=Dn(t,e);if(n==="working"){let c=cs.get(i);if(c&&Date.now()<c)return}let s=We.get(i),l=t===j&&(e??null)===Y,r=n==="idle"&&s?.state==="working";We.set(i,{session:t,agentId:e,state:n,doneUntil:r?Date.now()+Zl:void 0,unread:r?!l:!1});let a=e?'.session-item[data-agent="'+CSS.escape(e)+'"][data-session="'+CSS.escape(t)+'"]':'.session-item[data-session="'+CSS.escape(t)+'"]:not([data-agent])',o=P.querySelector(a);o&&Xt(o,i,We.get(i))}function Xt(t,e,n){let i=Ve.get(e);i&&(clearTimeout(i),Ve.delete(e)),t.classList.remove("working","just-done");let s=n.session===j&&(n.agentId??null)===Y;n.state==="working"?t.classList.add("working"):s&&n.doneUntil&&Date.now()<n.doneUntil?(t.classList.add("just-done"),Ve.set(e,setTimeout(()=>{t.classList.remove("just-done"),Ve.delete(e)},Math.max(0,n.doneUntil-Date.now())))):!s&&n.unread&&t.classList.add("just-done")}function Hn(){for(let[t,e]of We){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=P.querySelector(n);i&&Xt(i,t,e)}}function Xl(t,e){let n=Dn(t,e),i=We.get(n);if(!i)return;let s=Ve.get(n);s&&(clearTimeout(s),Ve.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])',r=P.querySelector(l);r&&Xt(r,n,i)}function ds(){if(vt||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);vt=n,n.onmessage=i=>{try{let s=JSON.parse(String(i.data));s&&s.type==="session.activity"&&typeof s.session=="string"&&Yl(s.session,s.agentId||void 0,s.state==="working"?"working":"idle")}catch{}},n.onclose=()=>{vt===n&&(vt=null,Pn=setTimeout(()=>{Pn=null,ds()},5e3))},n.onerror=()=>{try{n.close()}catch{}}}catch{vt=null}}window.__openSession=pt,window.__refreshSidebar=we,we(),dt(),Hn(),ds(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Hn()}),setInterval(()=>{document.visibilityState==="visible"&&we()},1e4),fl();
|