agent-afk 5.161.0 → 5.162.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,34 @@
1
- var It="__AFK_WEB_TOKEN__",_e="afk_web_token",ze="";function He(){let t=new URLSearchParams(location.search);(t.get("token")||t.get("k"))&&history.replaceState(null,"",location.pathname);let e=Pt();return e?(Mt(e),e):_t()}function Pt(){let t=document.querySelector('meta[name="afk-token"]')?.getAttribute("content");return!t||t===It?"":t}function Mt(t){ze=t;try{sessionStorage.setItem(_e,t)}catch{}}function _t(){try{let t=sessionStorage.getItem(_e);if(t)return t}catch{}return ze}var ss=Object.freeze({end:!0,reason:"session_closed"});function qe(t){return typeof t=="object"&&t!==null&&t.end===!0}function Ne(t){let n=t.replace(/\r\n/g,`
1
+ var Ht="__AFK_WEB_TOKEN__",He="afk_web_token",qe="";function Ne(){let t=new URLSearchParams(location.search);(t.get("token")||t.get("k"))&&history.replaceState(null,"",location.pathname);let e=qt();return e?(Nt(e),e):Bt()}function qt(){let t=document.querySelector('meta[name="afk-token"]')?.getAttribute("content");return!t||t===Ht?"":t}function Nt(t){qe=t;try{sessionStorage.setItem(He,t)}catch{}}function Bt(){try{let t=sessionStorage.getItem(He);if(t)return t}catch{}return qe}var ls=Object.freeze({end:!0,reason:"session_closed"});function Be(t){return typeof t=="object"&&t!==null&&t.end===!0}function De(t){let n=t.replace(/\r\n/g,`
2
2
  `).split(`
3
3
 
4
4
  `),r=n.pop()??"",s=[];for(let i of n){if(i.trim()==="")continue;let o,l;for(let a of i.split(`
5
- `))a.startsWith("id: ")?o=a.slice(4):a.startsWith("id:")?o=a.slice(3).trimStart():a.startsWith("data: ")?l=a.slice(6):a.startsWith("data:")&&(l=a.slice(5).trimStart());l!==void 0&&s.push({id:o,data:l})}return{events:s,remainder:r}}var zt=15e3,Ht=500,K=class{constructor(e,n,r){this.sessionId=e;this.token=n;this.handlers=r}sessionId;token;handlers;controller;lastEventId;attempt=0;stopped=!1;start(){this.stopped=!1,this.connect()}stop(){this.stopped=!0,this.controller?.abort(),this.handlers.onStatus?.("closed")}async connect(){if(this.stopped)return;this.handlers.onStatus?.(this.attempt===0?"connecting":"reconnecting");let e=!1;this.controller=new AbortController;let n={authorization:`Bearer ${this.token}`};this.lastEventId!==void 0&&(n["last-event-id"]=this.lastEventId);try{let i=await fetch(`/api/sessions/${encodeURIComponent(this.sessionId)}/stream`,{headers:n,signal:this.controller.signal});if(!i.ok){if(i.status===401||i.status===403||i.status===404){this.stopped=!0;let p=i.status===401?"unauthorized":i.status===403?"forbidden":"not-found";this.handlers.onStatus?.("closed",p);return}throw new Error(`stream failed: ${i.status}`)}if(i.body===null)throw new Error("stream failed: no body");this.attempt=0,this.handlers.onStatus?.("open");let o=i.body.getReader(),l=new TextDecoder,a="";e:for(;;){let{done:p,value:c}=await o.read();if(p)break;a+=l.decode(c,{stream:!0});let{events:h,remainder:u}=Ne(a);a=u;for(let m of h){if(m.id!==void 0&&(this.lastEventId=m.id),m.data===void 0)continue;let g;try{g=JSON.parse(m.data)}catch{continue}if(qe(g)){e=!0,this.stopped=!0;break e}this.handlers.onEvent(g,{id:m.id})}}}catch{}if(this.stopped){e&&this.handlers.onStatus?.("ended");return}this.attempt+=1;let r=.75+Math.random()*.5,s=Math.min(Ht*2**(this.attempt-1),zt)*r;setTimeout(()=>{this.connect()},s)}};var Be=/(?:^|\s)(\/[A-Za-z][A-Za-z0-9_:-]*)/g,qt=Number.POSITIVE_INFINITY;function Oe(t){let e=new Map;for(let n=0;n<t.length;n++){let r=t[n];if(!r)continue;Be.lastIndex=0;let s;for(;(s=Be.exec(r))!==null;){let i=s[1]?.toLowerCase();i!==void 0&&!e.has(i)&&e.set(i,n)}}return e}function De(t,e){let n=t.startsWith("/")?t.toLowerCase():`/${t.toLowerCase()}`;return e.get(n)??qt}function je(t,e,n){let r=De(t,n),s=De(e,n);return r!==s?r-s:t.localeCompare(e)}var Nt=20;function Bt(t,e){if(t.length===0)return!0;let n=0;for(let r=0;r<e.length&&n<t.length;r++)e[r]===t[n]&&(n+=1);return n===t.length}function Ue(t,e,n=[]){let r=e.toLowerCase(),s=t.map(c=>({key:c.name.replace(/^\//,"").toLowerCase(),cand:{value:c.name,...c.summary!==void 0?{summary:c.summary}:{},...c.hint!==void 0?{hint:c.hint}:{}}})),i=s.filter(c=>c.key.startsWith(r)),o=new Set(i.map(c=>c.cand.value)),l=r.length===0?[]:s.filter(c=>!o.has(c.cand.value)&&Bt(r,c.key)),a=Oe(n),p=(c,h)=>je(c.cand.value,h.cand.value,a);return i.sort(p),l.sort(p),[...i,...l].map(c=>c.cand).slice(0,Nt)}function Q(t){t.dispatchEvent(new Event("input"))}var Fe=new Set(["/clear","/compact","/editor","/exit","/fast","/font-size","/fork","/keys","/model","/reauth","/resume","/rewind","/sh","/theme","/thinking"]);function Ze(t,e,n,r){let s=document.createElement("div");s.id=e,s.setAttribute("role","option"),s.setAttribute("aria-selected",String(n)),s.className=n?"slash-row is-selected":"slash-row";let i=document.createElement("span");if(i.className="slash-name",i.textContent=t.value,s.appendChild(i),Fe.has(t.value)){let o=document.createElement("span");o.className="slash-badge",o.textContent="REPL only",o.title="Drives terminal-only machinery; cannot act in the browser.",s.appendChild(o)}if(t.summary!==void 0&&t.summary!==""){let o=document.createElement("span");o.className="slash-summary",o.textContent=t.summary,s.appendChild(o)}return s.addEventListener("mousedown",o=>{o.button===0&&(o.preventDefault(),r(t))}),s}var Ke=/^\/(?:[A-Za-z][\w:-]*)?$/,W=class{constructor(e){this.deps=e;this.menuId=e.menu.id||"slash-autocomplete-listbox",this.focused=document.activeElement===e.input,e.menu.id=this.menuId,e.menu.setAttribute("role","listbox"),e.input.removeAttribute("role"),e.input.setAttribute("aria-autocomplete","list"),e.input.setAttribute("aria-haspopup","listbox"),e.input.setAttribute("aria-controls",this.menuId),this.status=document.createElement("div"),this.status.className="slash-status",this.status.setAttribute("role","status"),this.status.setAttribute("aria-live","polite"),this.status.setAttribute("aria-atomic","true"),e.menu.insertAdjacentElement("afterend",this.status),this.syncAria()}deps;commands=null;loading=null;candidates=[];selected=0;open=!1;openIntent=!1;focused=!1;composing=!1;generation=0;menuId;status;isOpen(){return this.open&&this.candidates.length>0}knows(e){return this.commands?.some(n=>n.name===e)??!1}async preload(){await this.ensureCommands()}current(){return this.isOpen()?this.candidates[this.selected]:void 0}wire(){this.deps.input.addEventListener("focus",()=>{this.focused=!0}),this.deps.input.addEventListener("keydown",e=>this.onKeyDown(e)),this.deps.input.addEventListener("compositionstart",()=>{this.composing=!0}),this.deps.input.addEventListener("compositionend",()=>{this.composing=!1,this.openIntent&&this.refresh()}),this.deps.input.addEventListener("input",()=>{this.openIntent=!0,this.composing||this.refresh()}),this.deps.input.addEventListener("blur",()=>{this.focused=!1,this.composing=!1,this.close(!0)})}onKeyDown(e){if(!(e.isComposing||e.keyCode===229)){if(e.key==="Escape"&&(this.openIntent||this.loading!==null)){this.close(!0),e.preventDefault(),e.stopImmediatePropagation();return}if(this.isOpen()&&!(e.key==="Enter"&&(e.metaKey||e.ctrlKey))){switch(e.key){case"ArrowDown":this.move(1);break;case"ArrowUp":this.move(-1);break;case"Tab":case"Enter":this.accept();break;case"Escape":this.close();break;default:return}e.preventDefault(),e.stopImmediatePropagation()}}}move(e){let n=this.candidates.length;this.selected=(this.selected+e+n)%n,this.render(),this.revealSelected()}revealSelected(){let e=this.deps.menu.children[this.selected];e instanceof HTMLElement&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}accept(){let e=this.current();e&&(this.deps.input.value=`${e.value} `,this.close(!0),this.deps.input.focus(),Q(this.deps.input))}close(e=!1){e&&(this.openIntent=!1,this.generation+=1),this.open=!1,this.candidates=[],this.selected=0,this.deps.menu.hidden=!0,this.deps.menu.textContent="",this.status.textContent="",this.syncAria()}syncAria(){let e=this.isOpen();if(this.deps.input.setAttribute("aria-expanded",String(e)),e){this.deps.input.setAttribute("aria-activedescendant",this.optionId(this.selected));let n=this.candidates[this.selected];this.status.textContent=n?`${this.candidates.length} suggestions. ${n.value}, ${this.selected+1} of ${this.candidates.length}.`:""}else this.deps.input.removeAttribute("aria-activedescendant"),this.status.textContent=""}optionId(e){return`${this.menuId}-option-${e}`}async refresh(){!this.focused&&document.activeElement===this.deps.input&&(this.focused=!0);let e=this.deps.input.value;if(!Ke.test(e)){this.close(!0);return}this.openIntent=!0;let n=++this.generation;if(await this.ensureCommands(),n!==this.generation||!this.openIntent||!this.focused||!Ke.test(this.deps.input.value)){n===this.generation&&this.close();return}let r=this.deps.input.value.slice(1);this.candidates=Ue(this.commands??[],r),this.selected=0,this.open=this.candidates.length>0,this.openIntent=this.open,this.render()}async ensureCommands(){this.commands===null&&(this.loading??=this.deps.loadCommands().then(e=>{this.commands=e,this.deps.onCommandsLoaded?.()}).catch(e=>{console.error("[web] failed to load slash-command autocomplete:",e)}).finally(()=>{this.loading=null}),await this.loading)}render(){let e=this.deps.menu;if(e.textContent="",!this.isOpen()){e.hidden=!0,this.syncAria();return}this.candidates.forEach((n,r)=>{e.appendChild(this.row(n,r,r===this.selected))}),e.hidden=!1,this.syncAria()}row(e,n,r){return Ze(e,this.optionId(n),r,s=>{this.selected=this.candidates.indexOf(s),this.accept()})}};var Dt=/^\/[A-Za-z][\w:-]*$/;function Ot(t,e){return t===""?[]:t.split(/(\s+)/).filter(n=>n!=="").map(n=>Dt.test(n)?{text:n,kind:e(n)?"known":"slash"}:{text:n,kind:"plain"})}function jt(t,e){t.textContent="";for(let n of e){if(n.kind==="plain"){t.appendChild(document.createTextNode(n.text));continue}let r=document.createElement("span");r.className=n.kind==="known"?"tok-known":"tok-slash",r.textContent=n.text,t.appendChild(r)}t.appendChild(document.createTextNode("\u200B"))}function le(t,e,n){jt(e,Ot(t.value,n)),e.scrollTop=t.scrollTop,e.scrollLeft=t.scrollLeft}function Qe(t,e,n){let r=()=>{le(t,e,n)},s=()=>{e.scrollTop=t.scrollTop,e.scrollLeft=t.scrollLeft},i=()=>{t.removeEventListener("input",r),t.removeEventListener("scroll",s),e.textContent=""};return t.addEventListener("input",r),t.addEventListener("scroll",s),r(),i}var Ut="slash-menu",Ft="prompt-mirror";function We(t){let e=document.getElementById(Ut),n=document.getElementById(Ft);if(!e||!n)return;let r;return r=new W({input:t.input,menu:e,loadCommands:t.loadCommands,onCommandsLoaded:()=>le(t.input,n,s=>r.knows(s))}),r.wire(),Qe(t.input,n,s=>r.knows(s)),t.input.classList.add("slash-highlight-active"),r.preload(),r}var Zt=/\x1B\][^\x07\x1B\x9C]*(?:\x07|\x1B\\|\x9C)|\x1B[P^_X][^\x1B\x9C]*(?:\x1B\\|\x9C)|\x1B\[[0-?]*[ -/]*[@-~]|\x9B[0-?]*[ -/]*[@-~]|\x1B[6-_]/g;function Ge(t){return t.replace(Zt,"")}function G(t){return Ge(t)}function ue(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var M=ue();function nt(t){M=t}var I={exec:()=>null};function f(t,e=""){let n=typeof t=="string"?t:t.source,r={replace:(s,i)=>{let o=typeof i=="string"?i:i.source;return o=o.replace(y.caret,"$1"),n=n.replace(s,o),r},getRegex:()=>new RegExp(n,e)};return r}var Kt=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),y={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,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:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}>`)},Qt=/^(?:[ \t]*(?:\n|$))+/,Wt=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Gt=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,F=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Vt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,he=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,st=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,rt=f(st).replace(/bull/g,he).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Xt=f(st).replace(/bull/g,he).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),fe=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Jt=/^[^\n]+/,ge=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Yt=f(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ge).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),en=f(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,he).getRegex(),ee="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",me=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,tn=f("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",me).replace("tag",ee).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),it=f(fe).replace("hr",F).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ee).getRegex(),nn=f(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",it).getRegex(),ke={blockquote:nn,code:Wt,def:Yt,fences:Gt,heading:Vt,hr:F,html:tn,lheading:rt,list:en,newline:Qt,paragraph:it,table:I,text:Jt},Ve=f("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",F).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ee).getRegex(),sn={...ke,lheading:Xt,table:Ve,paragraph:f(fe).replace("hr",F).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ve).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ee).getRegex()},rn={...ke,html:f(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",me).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:I,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:f(fe).replace("hr",F).replace("heading",` *#{1,6} *[^
6
- ]`).replace("lheading",rt).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},on=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,an=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ot=/^( {2,}|\\)\n(?!\s*$)/,ln=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,q=/[\p{P}\p{S}]/u,te=/[\s\p{P}\p{S}]/u,xe=/[^\s\p{P}\p{S}]/u,cn=f(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,te).getRegex(),at=/(?!~)[\p{P}\p{S}]/u,pn=/(?!~)[\s\p{P}\p{S}]/u,dn=/(?:[^\s\p{P}\p{S}]|~)/u,un=f(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Kt?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),lt=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,hn=f(lt,"u").replace(/punct/g,q).getRegex(),fn=f(lt,"u").replace(/punct/g,at).getRegex(),ct="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",gn=f(ct,"gu").replace(/notPunctSpace/g,xe).replace(/punctSpace/g,te).replace(/punct/g,q).getRegex(),mn=f(ct,"gu").replace(/notPunctSpace/g,dn).replace(/punctSpace/g,pn).replace(/punct/g,at).getRegex(),kn=f("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,xe).replace(/punctSpace/g,te).replace(/punct/g,q).getRegex(),xn=f(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,q).getRegex(),bn="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",wn=f(bn,"gu").replace(/notPunctSpace/g,xe).replace(/punctSpace/g,te).replace(/punct/g,q).getRegex(),yn=f(/\\(punct)/,"gu").replace(/punct/g,q).getRegex(),vn=f(/^<(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(),Tn=f(me).replace("(?:-->|$)","-->").getRegex(),Sn=f("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Tn).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),X=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Cn=f(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",X).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),pt=f(/^!?\[(label)\]\[(ref)\]/).replace("label",X).replace("ref",ge).getRegex(),dt=f(/^!?\[(ref)\](?:\[\])?/).replace("ref",ge).getRegex(),En=f("reflink|nolink(?!\\()","g").replace("reflink",pt).replace("nolink",dt).getRegex(),Xe=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,be={_backpedal:I,anyPunctuation:yn,autolink:vn,blockSkip:un,br:ot,code:an,del:I,delLDelim:I,delRDelim:I,emStrongLDelim:hn,emStrongRDelimAst:gn,emStrongRDelimUnd:kn,escape:on,link:Cn,nolink:dt,punctuation:cn,reflink:pt,reflinkSearch:En,tag:Sn,text:ln,url:I},Rn={...be,link:f(/^!?\[(label)\]\((.*?)\)/).replace("label",X).getRegex(),reflink:f(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",X).getRegex()},ce={...be,emStrongRDelimAst:mn,emStrongLDelim:fn,delLDelim:xn,delRDelim:wn,url:f(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Xe).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:f(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Xe).getRegex()},Ln={...ce,br:f(ot).replace("{2,}","*").getRegex(),text:f(ce.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},V={normal:ke,gfm:sn,pedantic:rn},O={normal:be,gfm:ce,breaks:Ln,pedantic:Rn},An={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Je=t=>An[t];function E(t,e){if(e){if(y.escapeTest.test(t))return t.replace(y.escapeReplace,Je)}else if(y.escapeTestNoEncode.test(t))return t.replace(y.escapeReplaceNoEncode,Je);return t}function Ye(t){try{t=encodeURI(t).replace(y.percentDecode,"%")}catch{return null}return t}function et(t,e){let n=t.replace(y.findPipe,(i,o,l)=>{let a=!1,p=o;for(;--p>=0&&l[p]==="\\";)a=!a;return a?"|":" |"}),r=n.split(y.splitPipe),s=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),e)if(r.length>e)r.splice(e);else for(;r.length<e;)r.push("");for(;s<r.length;s++)r[s]=r[s].trim().replace(y.slashPipe,"|");return r}function j(t,e,n){let r=t.length;if(r===0)return"";let s=0;for(;s<r;){let i=t.charAt(r-s-1);if(i===e&&!n)s++;else if(i!==e&&n)s++;else break}return t.slice(0,r-s)}function $n(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let r=0;r<t.length;r++)if(t[r]==="\\")r++;else if(t[r]===e[0])n++;else if(t[r]===e[1]&&(n--,n<0))return r;return n>0?-2:-1}function In(t,e=0){let n=e,r="";for(let s of t)if(s===" "){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=s,n++;return r}function tt(t,e,n,r,s){let i=e.href,o=e.title||null,l=t[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;let a={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:o,text:l,tokens:r.inlineTokens(l)};return r.state.inLink=!1,a}function Pn(t,e,n){let r=t.match(n.other.indentCodeCompensation);if(r===null)return e;let s=r[1];return e.split(`
5
+ `))a.startsWith("id: ")?o=a.slice(4):a.startsWith("id:")?o=a.slice(3).trimStart():a.startsWith("data: ")?l=a.slice(6):a.startsWith("data:")&&(l=a.slice(5).trimStart());l!==void 0&&s.push({id:o,data:l})}return{events:s,remainder:r}}var Dt=15e3,Ot=500,Q=class{constructor(e,n,r){this.sessionId=e;this.token=n;this.handlers=r}sessionId;token;handlers;controller;lastEventId;attempt=0;stopped=!1;start(){this.stopped=!1,this.connect()}stop(){this.stopped=!0,this.controller?.abort(),this.handlers.onStatus?.("closed")}async connect(){if(this.stopped)return;this.handlers.onStatus?.(this.attempt===0?"connecting":"reconnecting");let e=!1;this.controller=new AbortController;let n={authorization:`Bearer ${this.token}`};this.lastEventId!==void 0&&(n["last-event-id"]=this.lastEventId);try{let i=await fetch(`/api/sessions/${encodeURIComponent(this.sessionId)}/stream`,{headers:n,signal:this.controller.signal});if(!i.ok){if(i.status===401||i.status===403||i.status===404){this.stopped=!0;let p=i.status===401?"unauthorized":i.status===403?"forbidden":"not-found";this.handlers.onStatus?.("closed",p);return}throw new Error(`stream failed: ${i.status}`)}if(i.body===null)throw new Error("stream failed: no body");this.attempt=0,this.handlers.onStatus?.("open");let o=i.body.getReader(),l=new TextDecoder,a="";e:for(;;){let{done:p,value:c}=await o.read();if(p)break;a+=l.decode(c,{stream:!0});let{events:h,remainder:u}=De(a);a=u;for(let g of h){if(g.id!==void 0&&(this.lastEventId=g.id),g.data===void 0)continue;let m;try{m=JSON.parse(g.data)}catch{continue}if(Be(m)){e=!0,this.stopped=!0;break e}this.handlers.onEvent(m,{id:g.id})}}}catch{}if(this.stopped){e&&this.handlers.onStatus?.("ended");return}this.attempt+=1;let r=.75+Math.random()*.5,s=Math.min(Ot*2**(this.attempt-1),Dt)*r;setTimeout(()=>{this.connect()},s)}};var Oe=/(?:^|\s)(\/[A-Za-z][A-Za-z0-9_:-]*)/g,jt=Number.POSITIVE_INFINITY;function Fe(t){let e=new Map;for(let n=0;n<t.length;n++){let r=t[n];if(!r)continue;Oe.lastIndex=0;let s;for(;(s=Oe.exec(r))!==null;){let i=s[1]?.toLowerCase();i!==void 0&&!e.has(i)&&e.set(i,n)}}return e}function je(t,e){let n=t.startsWith("/")?t.toLowerCase():`/${t.toLowerCase()}`;return e.get(n)??jt}function Ue(t,e,n){let r=je(t,n),s=je(e,n);return r!==s?r-s:t.localeCompare(e)}var Ft=20;function Ut(t,e){if(t.length===0)return!0;let n=0;for(let r=0;r<e.length&&n<t.length;r++)e[r]===t[n]&&(n+=1);return n===t.length}function Ze(t,e,n=[]){let r=e.toLowerCase(),s=t.map(c=>({key:c.name.replace(/^\//,"").toLowerCase(),cand:{value:c.name,...c.summary!==void 0?{summary:c.summary}:{},...c.hint!==void 0?{hint:c.hint}:{}}})),i=s.filter(c=>c.key.startsWith(r)),o=new Set(i.map(c=>c.cand.value)),l=r.length===0?[]:s.filter(c=>!o.has(c.cand.value)&&Ut(r,c.key)),a=Fe(n),p=(c,h)=>Ue(c.cand.value,h.cand.value,a);return i.sort(p),l.sort(p),[...i,...l].map(c=>c.cand).slice(0,Ft)}function W(t){t.dispatchEvent(new Event("input"))}var Ke=new Set(["/clear","/compact","/editor","/exit","/fast","/font-size","/fork","/keys","/model","/reauth","/resume","/rewind","/sh","/theme","/thinking"]);function Qe(t,e,n,r){let s=document.createElement("div");s.id=e,s.setAttribute("role","option"),s.setAttribute("aria-selected",String(n)),s.className=n?"slash-row is-selected":"slash-row";let i=document.createElement("span");if(i.className="slash-name",i.textContent=t.value,s.appendChild(i),Ke.has(t.value)){let o=document.createElement("span");o.className="slash-badge",o.textContent="REPL only",o.title="Drives terminal-only machinery; cannot act in the browser.",s.appendChild(o)}if(t.summary!==void 0&&t.summary!==""){let o=document.createElement("span");o.className="slash-summary",o.textContent=t.summary,s.appendChild(o)}return s.addEventListener("mousedown",o=>{o.button===0&&(o.preventDefault(),r(t))}),s}var We=/^\/(?:[A-Za-z][\w:-]*)?$/,G=class{constructor(e){this.deps=e;this.menuId=e.menu.id||"slash-autocomplete-listbox",this.focused=document.activeElement===e.input,e.menu.id=this.menuId,e.menu.setAttribute("role","listbox"),e.input.removeAttribute("role"),e.input.setAttribute("aria-autocomplete","list"),e.input.setAttribute("aria-haspopup","listbox"),e.input.setAttribute("aria-controls",this.menuId),this.status=document.createElement("div"),this.status.className="slash-status",this.status.setAttribute("role","status"),this.status.setAttribute("aria-live","polite"),this.status.setAttribute("aria-atomic","true"),e.menu.insertAdjacentElement("afterend",this.status),this.syncAria()}deps;commands=null;loading=null;candidates=[];selected=0;open=!1;openIntent=!1;focused=!1;composing=!1;generation=0;menuId;status;isOpen(){return this.open&&this.candidates.length>0}knows(e){return this.commands?.some(n=>n.name===e)??!1}async preload(){await this.ensureCommands()}current(){return this.isOpen()?this.candidates[this.selected]:void 0}wire(){this.deps.input.addEventListener("focus",()=>{this.focused=!0}),this.deps.input.addEventListener("keydown",e=>this.onKeyDown(e)),this.deps.input.addEventListener("compositionstart",()=>{this.composing=!0}),this.deps.input.addEventListener("compositionend",()=>{this.composing=!1,this.openIntent&&this.refresh()}),this.deps.input.addEventListener("input",()=>{this.openIntent=!0,this.composing||this.refresh()}),this.deps.input.addEventListener("blur",()=>{this.focused=!1,this.composing=!1,this.close(!0)})}onKeyDown(e){if(!(e.isComposing||e.keyCode===229)){if(e.key==="Escape"&&(this.openIntent||this.loading!==null)){this.close(!0),e.preventDefault(),e.stopImmediatePropagation();return}if(this.isOpen()&&!(e.key==="Enter"&&(e.metaKey||e.ctrlKey))){switch(e.key){case"ArrowDown":this.move(1);break;case"ArrowUp":this.move(-1);break;case"Tab":case"Enter":this.accept();break;case"Escape":this.close();break;default:return}e.preventDefault(),e.stopImmediatePropagation()}}}move(e){let n=this.candidates.length;this.selected=(this.selected+e+n)%n,this.render(),this.revealSelected()}revealSelected(){let e=this.deps.menu.children[this.selected];e instanceof HTMLElement&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}accept(){let e=this.current();e&&(this.deps.input.value=`${e.value} `,this.close(!0),this.deps.input.focus(),W(this.deps.input))}close(e=!1){e&&(this.openIntent=!1,this.generation+=1),this.open=!1,this.candidates=[],this.selected=0,this.deps.menu.hidden=!0,this.deps.menu.textContent="",this.status.textContent="",this.syncAria()}syncAria(){let e=this.isOpen();if(this.deps.input.setAttribute("aria-expanded",String(e)),e){this.deps.input.setAttribute("aria-activedescendant",this.optionId(this.selected));let n=this.candidates[this.selected];this.status.textContent=n?`${this.candidates.length} suggestions. ${n.value}, ${this.selected+1} of ${this.candidates.length}.`:""}else this.deps.input.removeAttribute("aria-activedescendant"),this.status.textContent=""}optionId(e){return`${this.menuId}-option-${e}`}async refresh(){!this.focused&&document.activeElement===this.deps.input&&(this.focused=!0);let e=this.deps.input.value;if(!We.test(e)){this.close(!0);return}this.openIntent=!0;let n=++this.generation;if(await this.ensureCommands(),n!==this.generation||!this.openIntent||!this.focused||!We.test(this.deps.input.value)){n===this.generation&&this.close();return}let r=this.deps.input.value.slice(1);this.candidates=Ze(this.commands??[],r),this.selected=0,this.open=this.candidates.length>0,this.openIntent=this.open,this.render()}async ensureCommands(){this.commands===null&&(this.loading??=this.deps.loadCommands().then(e=>{this.commands=e,this.deps.onCommandsLoaded?.()}).catch(e=>{console.error("[web] failed to load slash-command autocomplete:",e)}).finally(()=>{this.loading=null}),await this.loading)}render(){let e=this.deps.menu;if(e.textContent="",!this.isOpen()){e.hidden=!0,this.syncAria();return}this.candidates.forEach((n,r)=>{e.appendChild(this.row(n,r,r===this.selected))}),e.hidden=!1,this.syncAria()}row(e,n,r){return Qe(e,this.optionId(n),r,s=>{this.selected=this.candidates.indexOf(s),this.accept()})}};var Zt=/^\/[A-Za-z][\w:-]*$/;function Kt(t,e){return t===""?[]:t.split(/(\s+)/).filter(n=>n!=="").map(n=>Zt.test(n)?{text:n,kind:e(n)?"known":"slash"}:{text:n,kind:"plain"})}function Qt(t,e){t.textContent="";for(let n of e){if(n.kind==="plain"){t.appendChild(document.createTextNode(n.text));continue}let r=document.createElement("span");r.className=n.kind==="known"?"tok-known":"tok-slash",r.textContent=n.text,t.appendChild(r)}t.appendChild(document.createTextNode("\u200B"))}function de(t,e,n){Qt(e,Kt(t.value,n)),e.scrollTop=t.scrollTop,e.scrollLeft=t.scrollLeft}function Ge(t,e,n){let r=()=>{de(t,e,n)},s=()=>{e.scrollTop=t.scrollTop,e.scrollLeft=t.scrollLeft},i=()=>{t.removeEventListener("input",r),t.removeEventListener("scroll",s),e.textContent=""};return t.addEventListener("input",r),t.addEventListener("scroll",s),r(),i}var Wt="slash-menu",Gt="prompt-mirror";function Ve(t){let e=document.getElementById(Wt),n=document.getElementById(Gt);if(!e||!n)return;let r;return r=new G({input:t.input,menu:e,loadCommands:t.loadCommands,onCommandsLoaded:()=>de(t.input,n,s=>r.knows(s))}),r.wire(),Ge(t.input,n,s=>r.knows(s)),t.input.classList.add("slash-highlight-active"),r.preload(),r}function V(t){return document.getElementById(t)}function q(t,e=5e3){let n=V("toast");n&&(n.textContent=t,n.hidden=!1,n.classList.add("is-visible"),setTimeout(()=>{n.classList.remove("is-visible"),setTimeout(()=>{n.hidden=!0},300)},e))}function Xe(){let t=V("sidebar-backdrop"),e=V("sidebar");t?.addEventListener("click",()=>{e?.classList.remove("is-open")}),document.addEventListener("keydown",n=>{n.key==="Escape"&&!n.defaultPrevented&&e?.classList.remove("is-open")})}function Je(t){let e=document.getElementById("new-session-form");if(e){e.remove();return}let n=V("sidebar");if(!n)return;let r=document.createElement("div");r.id="new-session-form",r.className="new-session-form";let s=document.createElement("select");s.className="nsf-select";for(let a of["haiku","sonnet","opus"]){let p=document.createElement("option");p.value=a,p.textContent=a,a==="sonnet"&&(p.selected=!0),s.appendChild(p)}let i=document.createElement("input");i.type="text",i.className="nsf-input",i.placeholder="working directory (optional)";let o=document.createElement("button");o.className="nsf-btn",o.textContent="Create";let l=()=>{r.remove(),t(s.value,i.value.trim())};o.addEventListener("click",l),i.addEventListener("keydown",a=>{a.key==="Enter"&&l(),a.key==="Escape"&&r.remove()}),r.append(s,i,o),n.insertAdjacentElement("afterbegin",r),i.focus()}var Vt=/\x1B\][^\x07\x1B\x9C]*(?:\x07|\x1B\\|\x9C)|\x1B[P^_X][^\x1B\x9C]*(?:\x1B\\|\x9C)|\x1B\[[0-?]*[ -/]*[@-~]|\x9B[0-?]*[ -/]*[@-~]|\x1B[6-_]/g;function Ye(t){return t.replace(Vt,"")}function X(t){return Ye(t)}function me(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var M=me();function ot(t){M=t}var I={exec:()=>null};function f(t,e=""){let n=typeof t=="string"?t:t.source,r={replace:(s,i)=>{let o=typeof i=="string"?i:i.source;return o=o.replace(v.caret,"$1"),n=n.replace(s,o),r},getRegex:()=>new RegExp(n,e)};return r}var Xt=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),v={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,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:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}>`)},Jt=/^(?:[ \t]*(?:\n|$))+/,Yt=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,en=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Z=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,tn=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ge=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,at=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,lt=f(at).replace(/bull/g,ge).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),nn=f(at).replace(/bull/g,ge).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),ke=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,sn=/^[^\n]+/,be=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,rn=f(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",be).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),on=f(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ge).getRegex(),ne="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",xe=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,an=f("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",xe).replace("tag",ne).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ct=f(ke).replace("hr",Z).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ne).getRegex(),ln=f(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",ct).getRegex(),we={blockquote:ln,code:Yt,def:rn,fences:en,heading:tn,hr:Z,html:an,lheading:lt,list:on,newline:Jt,paragraph:ct,table:I,text:sn},et=f("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Z).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ne).getRegex(),cn={...we,lheading:nn,table:et,paragraph:f(ke).replace("hr",Z).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",et).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ne).getRegex()},pn={...we,html:f(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",xe).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:I,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:f(ke).replace("hr",Z).replace("heading",` *#{1,6} *[^
6
+ ]`).replace("lheading",lt).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},dn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,un=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,pt=/^( {2,}|\\)\n(?!\s*$)/,hn=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,N=/[\p{P}\p{S}]/u,se=/[\s\p{P}\p{S}]/u,ve=/[^\s\p{P}\p{S}]/u,fn=f(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,se).getRegex(),dt=/(?!~)[\p{P}\p{S}]/u,mn=/(?!~)[\s\p{P}\p{S}]/u,gn=/(?:[^\s\p{P}\p{S}]|~)/u,kn=f(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Xt?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),ut=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,bn=f(ut,"u").replace(/punct/g,N).getRegex(),xn=f(ut,"u").replace(/punct/g,dt).getRegex(),ht="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",wn=f(ht,"gu").replace(/notPunctSpace/g,ve).replace(/punctSpace/g,se).replace(/punct/g,N).getRegex(),vn=f(ht,"gu").replace(/notPunctSpace/g,gn).replace(/punctSpace/g,mn).replace(/punct/g,dt).getRegex(),yn=f("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,ve).replace(/punctSpace/g,se).replace(/punct/g,N).getRegex(),Tn=f(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,N).getRegex(),Sn="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Cn=f(Sn,"gu").replace(/notPunctSpace/g,ve).replace(/punctSpace/g,se).replace(/punct/g,N).getRegex(),En=f(/\\(punct)/,"gu").replace(/punct/g,N).getRegex(),Ln=f(/^<(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(),Rn=f(xe).replace("(?:-->|$)","-->").getRegex(),An=f("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Rn).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Y=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,$n=f(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Y).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),ft=f(/^!?\[(label)\]\[(ref)\]/).replace("label",Y).replace("ref",be).getRegex(),mt=f(/^!?\[(ref)\](?:\[\])?/).replace("ref",be).getRegex(),In=f("reflink|nolink(?!\\()","g").replace("reflink",ft).replace("nolink",mt).getRegex(),tt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,ye={_backpedal:I,anyPunctuation:En,autolink:Ln,blockSkip:kn,br:pt,code:un,del:I,delLDelim:I,delRDelim:I,emStrongLDelim:bn,emStrongRDelimAst:wn,emStrongRDelimUnd:yn,escape:dn,link:$n,nolink:mt,punctuation:fn,reflink:ft,reflinkSearch:In,tag:An,text:hn,url:I},Pn={...ye,link:f(/^!?\[(label)\]\((.*?)\)/).replace("label",Y).getRegex(),reflink:f(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Y).getRegex()},ue={...ye,emStrongRDelimAst:vn,emStrongLDelim:xn,delLDelim:Tn,delRDelim:Cn,url:f(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",tt).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:f(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",tt).getRegex()},Mn={...ue,br:f(pt).replace("{2,}","*").getRegex(),text:f(ue.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},J={normal:we,gfm:cn,pedantic:pn},j={normal:ye,gfm:ue,breaks:Mn,pedantic:Pn},_n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},nt=t=>_n[t];function E(t,e){if(e){if(v.escapeTest.test(t))return t.replace(v.escapeReplace,nt)}else if(v.escapeTestNoEncode.test(t))return t.replace(v.escapeReplaceNoEncode,nt);return t}function st(t){try{t=encodeURI(t).replace(v.percentDecode,"%")}catch{return null}return t}function rt(t,e){let n=t.replace(v.findPipe,(i,o,l)=>{let a=!1,p=o;for(;--p>=0&&l[p]==="\\";)a=!a;return a?"|":" |"}),r=n.split(v.splitPipe),s=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),e)if(r.length>e)r.splice(e);else for(;r.length<e;)r.push("");for(;s<r.length;s++)r[s]=r[s].trim().replace(v.slashPipe,"|");return r}function F(t,e,n){let r=t.length;if(r===0)return"";let s=0;for(;s<r;){let i=t.charAt(r-s-1);if(i===e&&!n)s++;else if(i!==e&&n)s++;else break}return t.slice(0,r-s)}function zn(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let r=0;r<t.length;r++)if(t[r]==="\\")r++;else if(t[r]===e[0])n++;else if(t[r]===e[1]&&(n--,n<0))return r;return n>0?-2:-1}function Hn(t,e=0){let n=e,r="";for(let s of t)if(s===" "){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=s,n++;return r}function it(t,e,n,r,s){let i=e.href,o=e.title||null,l=t[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;let a={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:o,text:l,tokens:r.inlineTokens(l)};return r.state.inLink=!1,a}function qn(t,e,n){let r=t.match(n.other.indentCodeCompensation);if(r===null)return e;let s=r[1];return e.split(`
7
7
  `).map(i=>{let o=i.match(n.other.beginningSpace);if(o===null)return i;let[l]=o;return l.length>=s.length?i.slice(s.length):i}).join(`
8
- `)}var J=class{options;rules;lexer;constructor(t){this.options=t||M}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=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?n:j(n,`
9
- `)}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],r=Pn(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:r}}}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 r=j(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:e[0],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:j(e[0],`
10
- `)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=j(e[0],`
8
+ `)}var ee=class{options;rules;lexer;constructor(t){this.options=t||M}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=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?n:F(n,`
9
+ `)}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],r=qn(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:r}}}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 r=F(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:e[0],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:F(e[0],`
10
+ `)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=F(e[0],`
11
11
  `).split(`
12
12
  `),r="",s="",i=[];for(;n.length>0;){let o=!1,l=[],a;for(a=0;a<n.length;a++)if(this.rules.other.blockquoteStart.test(n[a]))l.push(n[a]),o=!0;else if(!o)l.push(n[a]);else break;n=n.slice(a);let p=l.join(`
13
13
  `),c=p.replace(this.rules.other.blockquoteSetextReplace,`
14
14
  $1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
15
15
  ${p}`:p,s=s?`${s}
16
- ${c}`:c;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,i,!0),this.lexer.state.top=h,n.length===0)break;let u=i.at(-1);if(u?.type==="code")break;if(u?.type==="blockquote"){let m=u,g=m.raw+`
16
+ ${c}`:c;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,i,!0),this.lexer.state.top=h,n.length===0)break;let u=i.at(-1);if(u?.type==="code")break;if(u?.type==="blockquote"){let g=u,m=g.raw+`
17
17
  `+n.join(`
18
- `),w=this.blockquote(g);i[i.length-1]=w,r=r.substring(0,r.length-m.raw.length)+w.raw,s=s.substring(0,s.length-m.text.length)+w.text;break}else if(u?.type==="list"){let m=u,g=m.raw+`
18
+ `),w=this.blockquote(m);i[i.length-1]=w,r=r.substring(0,r.length-g.raw.length)+w.raw,s=s.substring(0,s.length-g.text.length)+w.text;break}else if(u?.type==="list"){let g=u,m=g.raw+`
19
19
  `+n.join(`
20
- `),w=this.list(g);i[i.length-1]=w,r=r.substring(0,r.length-u.raw.length)+w.raw,s=s.substring(0,s.length-m.raw.length)+w.raw,n=g.substring(i.at(-1).raw.length).split(`
21
- `);continue}}return{type:"blockquote",raw:r,tokens:i,text:s}}}list(t){let e=this.rules.block.list.exec(t);if(e){let n=e[1].trim(),r=n.length>1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let i=this.rules.other.listItemRegex(n),o=!1;for(;t;){let a=!1,p="",c="";if(!(e=i.exec(t))||this.rules.block.hr.test(t))break;p=e[0],t=t.substring(p.length);let h=In(e[2].split(`
20
+ `),w=this.list(m);i[i.length-1]=w,r=r.substring(0,r.length-u.raw.length)+w.raw,s=s.substring(0,s.length-g.raw.length)+w.raw,n=m.substring(i.at(-1).raw.length).split(`
21
+ `);continue}}return{type:"blockquote",raw:r,tokens:i,text:s}}}list(t){let e=this.rules.block.list.exec(t);if(e){let n=e[1].trim(),r=n.length>1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let i=this.rules.other.listItemRegex(n),o=!1;for(;t;){let a=!1,p="",c="";if(!(e=i.exec(t))||this.rules.block.hr.test(t))break;p=e[0],t=t.substring(p.length);let h=Hn(e[2].split(`
22
22
  `,1)[0],e[1].length),u=t.split(`
23
- `,1)[0],m=!h.trim(),g=0;if(this.options.pedantic?(g=2,c=h.trimStart()):m?g=e[1].length+1:(g=h.search(this.rules.other.nonSpaceChar),g=g>4?1:g,c=h.slice(g),g+=e[1].length),m&&this.rules.other.blankLine.test(u)&&(p+=u+`
24
- `,t=t.substring(u.length+1),a=!0),!a){let w=this.rules.other.nextBulletRegex(g),H=this.rules.other.hrRegex(g),$=this.rules.other.fencesBeginRegex(g),Me=this.rules.other.headingBeginRegex(g),At=this.rules.other.htmlBeginRegex(g),$t=this.rules.other.blockquoteBeginRegex(g);for(;t;){let ae=t.split(`
25
- `,1)[0],D;if(u=ae,this.options.pedantic?(u=u.replace(this.rules.other.listReplaceNesting," "),D=u):D=u.replace(this.rules.other.tabCharGlobal," "),$.test(u)||Me.test(u)||At.test(u)||$t.test(u)||w.test(u)||H.test(u))break;if(D.search(this.rules.other.nonSpaceChar)>=g||!u.trim())c+=`
26
- `+D.slice(g);else{if(m||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||$.test(h)||Me.test(h)||H.test(h))break;c+=`
27
- `+u}m=!u.trim(),p+=ae+`
28
- `,t=t.substring(ae.length+1),h=D.slice(g)}}s.loose||(o?s.loose=!0:this.rules.other.doubleBlankLine.test(p)&&(o=!0)),s.items.push({type:"list_item",raw:p,task:!!this.options.gfm&&this.rules.other.listIsTask.test(c),loose:!1,text:c,tokens:[]}),s.raw+=p}let l=s.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let a of s.items){if(this.lexer.state.top=!1,a.tokens=this.lexer.blockTokens(a.text,[]),a.task){if(a.text=a.text.replace(this.rules.other.listReplaceTask,""),a.tokens[0]?.type==="text"||a.tokens[0]?.type==="paragraph"){a.tokens[0].raw=a.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),a.tokens[0].text=a.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let c=this.lexer.inlineQueue.length-1;c>=0;c--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)){this.lexer.inlineQueue[c].src=this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask,"");break}}let p=this.rules.other.listTaskCheckbox.exec(a.raw);if(p){let c={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};a.checked=c.checked,s.loose?a.tokens[0]&&["paragraph","text"].includes(a.tokens[0].type)&&"tokens"in a.tokens[0]&&a.tokens[0].tokens?(a.tokens[0].raw=c.raw+a.tokens[0].raw,a.tokens[0].text=c.raw+a.tokens[0].text,a.tokens[0].tokens.unshift(c)):a.tokens.unshift({type:"paragraph",raw:c.raw,text:c.raw,tokens:[c]}):a.tokens.unshift(c)}}if(!s.loose){let p=a.tokens.filter(h=>h.type==="space"),c=p.length>0&&p.some(h=>this.rules.other.anyLine.test(h.raw));s.loose=c}}if(s.loose)for(let a of s.items){a.loose=!0;for(let p of a.tokens)p.type==="text"&&(p.type="paragraph")}return s}}html(t){let e=this.rules.block.html.exec(t);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(t){let e=this.rules.block.def.exec(t);if(e){let n=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=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:e[0],href:r,title:s}}}table(t){let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let n=et(e[1]),r=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
29
- `):[],i={type:"table",raw:e[0],header:[],align:[],rows:[]};if(n.length===r.length){for(let o of r)this.rules.other.tableAlignRight.test(o)?i.align.push("right"):this.rules.other.tableAlignCenter.test(o)?i.align.push("center"):this.rules.other.tableAlignLeft.test(o)?i.align.push("left"):i.align.push(null);for(let o=0;o<n.length;o++)i.header.push({text:n[o],tokens:this.lexer.inline(n[o]),header:!0,align:i.align[o]});for(let o of s)i.rows.push(et(o,i.header.length).map((l,a)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:i.align[a]})));return i}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e){let n=e[1].trim();return{type:"heading",raw:e[0],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)===`
30
- `?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)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){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){let e=this.rules.inline.link.exec(t);if(e){let n=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let i=j(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=$n(e[2],"()");if(i===-2)return;if(i>-1){let o=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,o).trim(),e[3]=""}}let r=e[2],s="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],s=i[3])}else s=e[3]?e[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),tt(e,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=e[r.toLowerCase()];if(!s){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return tt(n,s,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let r=this.rules.inline.emStrongLDelim.exec(t);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,o,l=s,a=0,p=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(p.lastIndex=0,e=e.slice(-1*t.length+s);(r=p.exec(e))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(o=[...i].length,r[3]||r[4]){l+=o;continue}else if((r[5]||r[6])&&s%3&&!((s+o)%3)){a+=o;continue}if(l-=o,l>0)continue;o=Math.min(o,o+l+a);let c=[...r[0]][0].length,h=t.slice(0,s+r.index+c+o);if(Math.min(s,o)%2){let m=h.slice(1,-1);return{type:"em",raw:h,text:m,tokens:this.lexer.inlineTokens(m)}}let u=h.slice(2,-2);return{type:"strong",raw:h,text:u,tokens:this.lexer.inlineTokens(u)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){let e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t,e,n=""){let r=this.rules.inline.delLDelim.exec(t);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,o,l=s,a=this.rules.inline.delRDelim;for(a.lastIndex=0,e=e.slice(-1*t.length+s);(r=a.exec(e))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(o=[...i].length,o!==s))continue;if(r[3]||r[4]){l+=o;continue}if(l-=o,l>0)continue;o=Math.min(o,o+l);let p=[...r[0]][0].length,c=t.slice(0,s+r.index+p+o),h=c.slice(s,-s);return{type:"del",raw:c,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(t){let e=this.rules.inline.autolink.exec(t);if(e){let n,r;return e[2]==="@"?(n=e[1],r="mailto:"+n):(n=e[1],r=n),{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,r;if(e[2]==="@")n=e[0],r="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."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:n,href:r,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:e[0],escaped:n}}}},T=class pe{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||M,this.options.tokenizer=this.options.tokenizer||new J,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let n={other:y,block:V.normal,inline:O.normal};this.options.pedantic?(n.block=V.pedantic,n.inline=O.pedantic):this.options.gfm&&(n.block=V.gfm,this.options.breaks?n.inline=O.breaks:n.inline=O.gfm),this.tokenizer.rules=n}static get rules(){return{block:V,inline:O}}static lex(e,n){return new pe(n).lex(e)}static lexInline(e,n){return new pe(n).inlineTokens(e)}lex(e){e=e.replace(y.carriageReturn,`
31
- `),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let r=this.inlineQueue[n];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],r=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(y.tabCharGlobal," ").replace(y.spaceLine,""));e;){let s;if(this.options.extensions?.block?.some(o=>(s=o.call({lexer:this},e,n))?(e=e.substring(s.raw.length),n.push(s),!0):!1))continue;if(s=this.tokenizer.space(e)){e=e.substring(s.raw.length);let o=n.at(-1);s.raw.length===1&&o!==void 0?o.raw+=`
23
+ `,1)[0],g=!h.trim(),m=0;if(this.options.pedantic?(m=2,c=h.trimStart()):g?m=e[1].length+1:(m=h.search(this.rules.other.nonSpaceChar),m=m>4?1:m,c=h.slice(m),m+=e[1].length),g&&this.rules.other.blankLine.test(u)&&(p+=u+`
24
+ `,t=t.substring(u.length+1),a=!0),!a){let w=this.rules.other.nextBulletRegex(m),H=this.rules.other.hrRegex(m),$=this.rules.other.fencesBeginRegex(m),ze=this.rules.other.headingBeginRegex(m),_t=this.rules.other.htmlBeginRegex(m),zt=this.rules.other.blockquoteBeginRegex(m);for(;t;){let pe=t.split(`
25
+ `,1)[0],O;if(u=pe,this.options.pedantic?(u=u.replace(this.rules.other.listReplaceNesting," "),O=u):O=u.replace(this.rules.other.tabCharGlobal," "),$.test(u)||ze.test(u)||_t.test(u)||zt.test(u)||w.test(u)||H.test(u))break;if(O.search(this.rules.other.nonSpaceChar)>=m||!u.trim())c+=`
26
+ `+O.slice(m);else{if(g||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||$.test(h)||ze.test(h)||H.test(h))break;c+=`
27
+ `+u}g=!u.trim(),p+=pe+`
28
+ `,t=t.substring(pe.length+1),h=O.slice(m)}}s.loose||(o?s.loose=!0:this.rules.other.doubleBlankLine.test(p)&&(o=!0)),s.items.push({type:"list_item",raw:p,task:!!this.options.gfm&&this.rules.other.listIsTask.test(c),loose:!1,text:c,tokens:[]}),s.raw+=p}let l=s.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let a of s.items){if(this.lexer.state.top=!1,a.tokens=this.lexer.blockTokens(a.text,[]),a.task){if(a.text=a.text.replace(this.rules.other.listReplaceTask,""),a.tokens[0]?.type==="text"||a.tokens[0]?.type==="paragraph"){a.tokens[0].raw=a.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),a.tokens[0].text=a.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let c=this.lexer.inlineQueue.length-1;c>=0;c--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)){this.lexer.inlineQueue[c].src=this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask,"");break}}let p=this.rules.other.listTaskCheckbox.exec(a.raw);if(p){let c={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};a.checked=c.checked,s.loose?a.tokens[0]&&["paragraph","text"].includes(a.tokens[0].type)&&"tokens"in a.tokens[0]&&a.tokens[0].tokens?(a.tokens[0].raw=c.raw+a.tokens[0].raw,a.tokens[0].text=c.raw+a.tokens[0].text,a.tokens[0].tokens.unshift(c)):a.tokens.unshift({type:"paragraph",raw:c.raw,text:c.raw,tokens:[c]}):a.tokens.unshift(c)}}if(!s.loose){let p=a.tokens.filter(h=>h.type==="space"),c=p.length>0&&p.some(h=>this.rules.other.anyLine.test(h.raw));s.loose=c}}if(s.loose)for(let a of s.items){a.loose=!0;for(let p of a.tokens)p.type==="text"&&(p.type="paragraph")}return s}}html(t){let e=this.rules.block.html.exec(t);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(t){let e=this.rules.block.def.exec(t);if(e){let n=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=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:e[0],href:r,title:s}}}table(t){let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let n=rt(e[1]),r=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
29
+ `):[],i={type:"table",raw:e[0],header:[],align:[],rows:[]};if(n.length===r.length){for(let o of r)this.rules.other.tableAlignRight.test(o)?i.align.push("right"):this.rules.other.tableAlignCenter.test(o)?i.align.push("center"):this.rules.other.tableAlignLeft.test(o)?i.align.push("left"):i.align.push(null);for(let o=0;o<n.length;o++)i.header.push({text:n[o],tokens:this.lexer.inline(n[o]),header:!0,align:i.align[o]});for(let o of s)i.rows.push(rt(o,i.header.length).map((l,a)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:i.align[a]})));return i}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e){let n=e[1].trim();return{type:"heading",raw:e[0],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)===`
30
+ `?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)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){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){let e=this.rules.inline.link.exec(t);if(e){let n=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let i=F(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=zn(e[2],"()");if(i===-2)return;if(i>-1){let o=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,o).trim(),e[3]=""}}let r=e[2],s="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],s=i[3])}else s=e[3]?e[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),it(e,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=e[r.toLowerCase()];if(!s){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return it(n,s,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let r=this.rules.inline.emStrongLDelim.exec(t);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,o,l=s,a=0,p=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(p.lastIndex=0,e=e.slice(-1*t.length+s);(r=p.exec(e))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(o=[...i].length,r[3]||r[4]){l+=o;continue}else if((r[5]||r[6])&&s%3&&!((s+o)%3)){a+=o;continue}if(l-=o,l>0)continue;o=Math.min(o,o+l+a);let c=[...r[0]][0].length,h=t.slice(0,s+r.index+c+o);if(Math.min(s,o)%2){let g=h.slice(1,-1);return{type:"em",raw:h,text:g,tokens:this.lexer.inlineTokens(g)}}let u=h.slice(2,-2);return{type:"strong",raw:h,text:u,tokens:this.lexer.inlineTokens(u)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){let e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t,e,n=""){let r=this.rules.inline.delLDelim.exec(t);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,o,l=s,a=this.rules.inline.delRDelim;for(a.lastIndex=0,e=e.slice(-1*t.length+s);(r=a.exec(e))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(o=[...i].length,o!==s))continue;if(r[3]||r[4]){l+=o;continue}if(l-=o,l>0)continue;o=Math.min(o,o+l);let p=[...r[0]][0].length,c=t.slice(0,s+r.index+p+o),h=c.slice(s,-s);return{type:"del",raw:c,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(t){let e=this.rules.inline.autolink.exec(t);if(e){let n,r;return e[2]==="@"?(n=e[1],r="mailto:"+n):(n=e[1],r=n),{type:"link",raw:e[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,r;if(e[2]==="@")n=e[0],r="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."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:n,href:r,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:e[0],escaped:n}}}},T=class he{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||M,this.options.tokenizer=this.options.tokenizer||new ee,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let n={other:v,block:J.normal,inline:j.normal};this.options.pedantic?(n.block=J.pedantic,n.inline=j.pedantic):this.options.gfm&&(n.block=J.gfm,this.options.breaks?n.inline=j.breaks:n.inline=j.gfm),this.tokenizer.rules=n}static get rules(){return{block:J,inline:j}}static lex(e,n){return new he(n).lex(e)}static lexInline(e,n){return new he(n).inlineTokens(e)}lex(e){e=e.replace(v.carriageReturn,`
31
+ `),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let r=this.inlineQueue[n];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],r=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(v.tabCharGlobal," ").replace(v.spaceLine,""));e;){let s;if(this.options.extensions?.block?.some(o=>(s=o.call({lexer:this},e,n))?(e=e.substring(s.raw.length),n.push(s),!0):!1))continue;if(s=this.tokenizer.space(e)){e=e.substring(s.raw.length);let o=n.at(-1);s.raw.length===1&&o!==void 0?o.raw+=`
32
32
  `:n.push(s);continue}if(s=this.tokenizer.code(e)){e=e.substring(s.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
33
33
  `)?"":`
34
34
  `)+s.raw,o.text+=`
@@ -41,7 +41,7 @@ ${c}`:c;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo
41
41
  `+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(s),r=i.length!==e.length,e=e.substring(s.raw.length);continue}if(s=this.tokenizer.text(e)){e=e.substring(s.raw.length);let o=n.at(-1);o?.type==="text"?(o.raw+=(o.raw.endsWith(`
42
42
  `)?"":`
43
43
  `)+s.raw,o.text+=`
44
- `+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(s);continue}if(e){let o="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(o);break}else throw new Error(o)}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){this.tokenizer.lexer=this;let r=e,s=null;if(this.tokens.links){let a=Object.keys(this.tokens.links);if(a.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(r))!=null;)a.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.anyPunctuation.exec(r))!=null;)r=r.slice(0,s.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(s=this.tokenizer.rules.inline.blockSkip.exec(r))!=null;)i=s[2]?s[2].length:0,r=r.slice(0,s.index+i)+"["+"a".repeat(s[0].length-i-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let o=!1,l="";for(;e;){o||(l=""),o=!1;let a;if(this.options.extensions?.inline?.some(c=>(a=c.call({lexer:this},e,n))?(e=e.substring(a.raw.length),n.push(a),!0):!1))continue;if(a=this.tokenizer.escape(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.tag(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.link(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(a.raw.length);let c=n.at(-1);a.type==="text"&&c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(a=this.tokenizer.emStrong(e,r,l)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.codespan(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.br(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.del(e,r,l)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.autolink(e)){e=e.substring(a.raw.length),n.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(e))){e=e.substring(a.raw.length),n.push(a);continue}let p=e;if(this.options.extensions?.startInline){let c=1/0,h=e.slice(1),u;this.options.extensions.startInline.forEach(m=>{u=m.call({lexer:this},h),typeof u=="number"&&u>=0&&(c=Math.min(c,u))}),c<1/0&&c>=0&&(p=e.substring(0,c+1))}if(a=this.tokenizer.inlineText(p)){e=e.substring(a.raw.length),a.raw.slice(-1)!=="_"&&(l=a.raw.slice(-1)),o=!0;let c=n.at(-1);c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(e){let c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return n}},Y=class{options;parser;constructor(t){this.options=t||M}space(t){return""}code({text:t,lang:e,escaped:n}){let r=(e||"").match(y.notSpaceStart)?.[0],s=t.replace(y.endingNewline,"")+`
44
+ `+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(s);continue}if(e){let o="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(o);break}else throw new Error(o)}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){this.tokenizer.lexer=this;let r=e,s=null;if(this.tokens.links){let a=Object.keys(this.tokens.links);if(a.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(r))!=null;)a.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.anyPunctuation.exec(r))!=null;)r=r.slice(0,s.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(s=this.tokenizer.rules.inline.blockSkip.exec(r))!=null;)i=s[2]?s[2].length:0,r=r.slice(0,s.index+i)+"["+"a".repeat(s[0].length-i-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let o=!1,l="";for(;e;){o||(l=""),o=!1;let a;if(this.options.extensions?.inline?.some(c=>(a=c.call({lexer:this},e,n))?(e=e.substring(a.raw.length),n.push(a),!0):!1))continue;if(a=this.tokenizer.escape(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.tag(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.link(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(a.raw.length);let c=n.at(-1);a.type==="text"&&c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(a=this.tokenizer.emStrong(e,r,l)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.codespan(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.br(e)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.del(e,r,l)){e=e.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.autolink(e)){e=e.substring(a.raw.length),n.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(e))){e=e.substring(a.raw.length),n.push(a);continue}let p=e;if(this.options.extensions?.startInline){let c=1/0,h=e.slice(1),u;this.options.extensions.startInline.forEach(g=>{u=g.call({lexer:this},h),typeof u=="number"&&u>=0&&(c=Math.min(c,u))}),c<1/0&&c>=0&&(p=e.substring(0,c+1))}if(a=this.tokenizer.inlineText(p)){e=e.substring(a.raw.length),a.raw.slice(-1)!=="_"&&(l=a.raw.slice(-1)),o=!0;let c=n.at(-1);c?.type==="text"?(c.raw+=a.raw,c.text+=a.text):n.push(a);continue}if(e){let c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return n}},te=class{options;parser;constructor(t){this.options=t||M}space(t){return""}code({text:t,lang:e,escaped:n}){let r=(e||"").match(v.notSpaceStart)?.[0],s=t.replace(v.endingNewline,"")+`
45
45
  `;return r?'<pre><code class="language-'+E(r)+'">'+(n?s:E(s,!0))+`</code></pre>
46
46
  `:"<pre><code>"+(n?s:E(s,!0))+`</code></pre>
47
47
  `}blockquote({tokens:t}){return`<blockquote>
@@ -59,7 +59,7 @@ ${this.parser.parse(t)}</blockquote>
59
59
  `}tablerow({text:t}){return`<tr>
60
60
  ${t}</tr>
61
61
  `}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
62
- `}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>${E(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){let r=this.parser.parseInline(n),s=Ye(t);if(s===null)return r;t=s;let i='<a href="'+t+'"';return e&&(i+=' title="'+E(e)+'"'),i+=">"+r+"</a>",i}image({href:t,title:e,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let s=Ye(t);if(s===null)return E(n);t=s;let i=`<img src="${t}" alt="${E(n)}"`;return e&&(i+=` title="${E(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:E(t.text)}},we=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}checkbox({raw:t}){return t}},S=class de{options;renderer;textRenderer;constructor(e){this.options=e||M,this.options.renderer=this.options.renderer||new Y,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new we}static parse(e,n){return new de(n).parse(e)}static parseInline(e,n){return new de(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let r=0;r<e.length;r++){let s=e[r];if(this.options.extensions?.renderers?.[s.type]){let o=s,l=this.options.extensions.renderers[o.type].call({parser:this},o);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(o.type)){n+=l||"";continue}}let i=s;switch(i.type){case"space":{n+=this.renderer.space(i);break}case"hr":{n+=this.renderer.hr(i);break}case"heading":{n+=this.renderer.heading(i);break}case"code":{n+=this.renderer.code(i);break}case"table":{n+=this.renderer.table(i);break}case"blockquote":{n+=this.renderer.blockquote(i);break}case"list":{n+=this.renderer.list(i);break}case"checkbox":{n+=this.renderer.checkbox(i);break}case"html":{n+=this.renderer.html(i);break}case"def":{n+=this.renderer.def(i);break}case"paragraph":{n+=this.renderer.paragraph(i);break}case"text":{n+=this.renderer.text(i);break}default:{let o='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}parseInline(e,n=this.renderer){this.renderer.parser=this;let r="";for(let s=0;s<e.length;s++){let i=e[s];if(this.options.extensions?.renderers?.[i.type]){let l=this.options.extensions.renderers[i.type].call({parser:this},i);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){r+=l||"";continue}}let o=i;switch(o.type){case"escape":{r+=n.text(o);break}case"html":{r+=n.html(o);break}case"link":{r+=n.link(o);break}case"image":{r+=n.image(o);break}case"checkbox":{r+=n.checkbox(o);break}case"strong":{r+=n.strong(o);break}case"em":{r+=n.em(o);break}case"codespan":{r+=n.codespan(o);break}case"br":{r+=n.br(o);break}case"del":{r+=n.del(o);break}case"text":{r+=n.text(o);break}default:{let l='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return r}},U=class{options;block;constructor(t){this.options=t||M}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(){return this.block?T.lex:T.lexInline}provideParser(){return this.block?S.parse:S.parseInline}},Mn=class{defaults=ue();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=S;Renderer=Y;TextRenderer=we;Lexer=T;Tokenizer=J;Hooks=U;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let r of t)switch(n=n.concat(e.call(this,r)),r.type){case"table":{let s=r;for(let i of s.header)n=n.concat(this.walkTokens(i.tokens,e));for(let i of s.rows)for(let o of i)n=n.concat(this.walkTokens(o.tokens,e));break}case"list":{let s=r;n=n.concat(this.walkTokens(s.items,e));break}default:{let s=r;this.defaults.extensions?.childTokens?.[s.type]?this.defaults.extensions.childTokens[s.type].forEach(i=>{let o=s[i].flat(1/0);n=n.concat(this.walkTokens(o,e))}):s.tokens&&(n=n.concat(this.walkTokens(s.tokens,e)))}}return n}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){let i=e.renderers[s.name];i?e.renderers[s.name]=function(...o){let l=s.renderer.apply(this,o);return l===!1&&(l=i.apply(this,o)),l}:e.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=e[s.level];i?i.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)}),r.extensions=e),n.renderer){let s=this.defaults.renderer||new Y(this.defaults);for(let i in n.renderer){if(!(i in s))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let o=i,l=n.renderer[o],a=s[o];s[o]=(...p)=>{let c=l.apply(s,p);return c===!1&&(c=a.apply(s,p)),c||""}}r.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new J(this.defaults);for(let i in n.tokenizer){if(!(i in s))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let o=i,l=n.tokenizer[o],a=s[o];s[o]=(...p)=>{let c=l.apply(s,p);return c===!1&&(c=a.apply(s,p)),c}}r.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new U;for(let i in n.hooks){if(!(i in s))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let o=i,l=n.hooks[o],a=s[o];U.passThroughHooks.has(i)?s[o]=p=>{if(this.defaults.async&&U.passThroughHooksRespectAsync.has(i))return(async()=>{let h=await l.call(s,p);return a.call(s,h)})();let c=l.call(s,p);return a.call(s,c)}:s[o]=(...p)=>{if(this.defaults.async)return(async()=>{let h=await l.apply(s,p);return h===!1&&(h=await a.apply(s,p)),h})();let c=l.apply(s,p);return c===!1&&(c=a.apply(s,p)),c}}r.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(o){let l=[];return l.push(i.call(this,o)),s&&(l=l.concat(s.call(this,o))),l}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return T.lex(t,e??this.defaults)}parser(t,e){return S.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let r={...n},s={...this.defaults,...r},i=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&r.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(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 o=s.hooks?await s.hooks.preprocess(e):e,l=await(s.hooks?await s.hooks.provideLexer():t?T.lex:T.lexInline)(o,s),a=s.hooks?await s.hooks.processAllTokens(l):l;s.walkTokens&&await Promise.all(this.walkTokens(a,s.walkTokens));let p=await(s.hooks?await s.hooks.provideParser():t?S.parse:S.parseInline)(a,s);return s.hooks?await s.hooks.postprocess(p):p})().catch(i);try{s.hooks&&(e=s.hooks.preprocess(e));let o=(s.hooks?s.hooks.provideLexer():t?T.lex:T.lexInline)(e,s);s.hooks&&(o=s.hooks.processAllTokens(o)),s.walkTokens&&this.walkTokens(o,s.walkTokens);let l=(s.hooks?s.hooks.provideParser():t?S.parse:S.parseInline)(o,s);return s.hooks&&(l=s.hooks.postprocess(l)),l}catch(o){return i(o)}}}onError(t,e){return n=>{if(n.message+=`
63
- Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+E(n.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},P=new Mn;function x(t,e){return P.parse(t,e)}x.options=x.setOptions=function(t){return P.setOptions(t),x.defaults=P.defaults,nt(x.defaults),x};x.getDefaults=ue;x.defaults=M;x.use=function(...t){return P.use(...t),x.defaults=P.defaults,nt(x.defaults),x};x.walkTokens=function(t,e){return P.walkTokens(t,e)};x.parseInline=P.parseInline;x.Parser=S;x.parser=S.parse;x.Renderer=Y;x.TextRenderer=we;x.Lexer=T;x.lexer=T.lex;x.Tokenizer=J;x.Hooks=U;x.parse=x;var Ss=x.options,Cs=x.setOptions,Es=x.use,Rs=x.walkTokens,Ls=x.parseInline;var As=S.parse,$s=T.lex;var _n=["http:","https:","mailto:"];function zn(t){try{let e=new URL(t);return _n.includes(e.protocol)?e.href:void 0}catch{return}}function k(t,e){let n=document.createElement(t);return e&&(n.className=e),n}function C(t,e){if(e)for(let n of e)switch(n.type){case"strong":{let r=k("strong");C(r,n.tokens),t.appendChild(r);break}case"em":{let r=k("em");C(r,n.tokens),t.appendChild(r);break}case"del":{let r=k("s");C(r,n.tokens),t.appendChild(r);break}case"codespan":{let r=k("code","md-code-inline");r.textContent=n.text,t.appendChild(r);break}case"link":{let r=n,s=zn(r.href);if(s===void 0){let o=k("span");C(o,r.tokens),t.appendChild(o);break}let i=k("a","md-link");i.href=s,i.target="_blank",i.rel="noopener noreferrer",C(i,r.tokens),t.appendChild(i);break}case"image":{let r=k("span","md-image");r.textContent=`[image: ${n.text||"untitled"}]`,t.appendChild(r);break}case"br":t.appendChild(k("br"));break;default:{let r=n.text??"",s=n.tokens;s&&s.length>0&&n.type==="text"?C(t,s):r&&t.appendChild(document.createTextNode(r));break}}}function Hn(t){let e=t.ordered?k("ol","md-list"):k("ul","md-list");t.ordered&&typeof t.start=="number"&&t.start>1&&(e.start=t.start);for(let n of t.items){let r=k("li");if(n.task){let s=k("input","md-task");s.type="checkbox",s.checked=!!n.checked,s.disabled=!0,r.appendChild(s)}ye(r,n.tokens),e.appendChild(r)}return e}function qn(t){let e=k("pre","md-pre"),n=k("code");if(t.lang){let r=t.lang.split(/\s+/)[0]??"";r&&(n.className=`md-lang-${r}`,e.dataset.lang=r)}return n.textContent=t.text,e.appendChild(n),e}function Nn(t){let e=k("table","md-table"),n=k("thead"),r=k("tr");for(let i of t.header){let o=k("th");C(o,i.tokens),r.appendChild(o)}n.appendChild(r),e.appendChild(n);let s=k("tbody");for(let i of t.rows){let o=k("tr");for(let l of i){let a=k("td");C(a,l.tokens),o.appendChild(a)}s.appendChild(o)}return e.appendChild(s),e}function ye(t,e){for(let n of e)switch(n.type){case"heading":{let r=Math.min(Math.max(n.depth,1),6),s=k(`h${r}`,"md-heading");C(s,n.tokens),t.appendChild(s);break}case"paragraph":{let r=k("p","md-p");C(r,n.tokens),t.appendChild(r);break}case"code":t.appendChild(qn(n));break;case"list":t.appendChild(Hn(n));break;case"blockquote":{let r=k("blockquote","md-quote");ye(r,n.tokens),t.appendChild(r);break}case"table":t.appendChild(Nn(n));break;case"hr":t.appendChild(k("hr","md-hr"));break;case"space":break;case"html":{let r=k("p","md-p");r.textContent=n.text,t.appendChild(r);break}default:{let r=n.tokens;if(r&&r.length>0){let i=k("p","md-p");C(i,r),t.appendChild(i);break}let s=n.text??"";if(s.trim()){let i=k("p","md-p");i.textContent=s,t.appendChild(i)}break}}}function ut(t,e="md"){let n=k("div",e);try{ye(n,new T().lex(t))}catch{n.textContent=t}return n}var ne=new Map;function Bn(t,e){return t.kind!=="tool"?!1:e.className!==`tool tool-${t.status}`}function ht(t,e,n){e.length<t.childElementCount&&(ne.clear(),t.textContent="");for(let r of e){let s=ne.get(r.id);if(s===void 0){let i=n(r);ne.set(r.id,i),t.appendChild(i)}else if(Bn(r,s)){let i=n(r);ne.set(r.id,i),t.replaceChild(i,s)}}}var ft=2e3,gt=2e3;function d(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!==void 0&&(r.textContent=n),r}function Dn(t){if(!t)return;let e=t.replace(/[/\\]+$/,"").split(/[/\\]/).pop()??"";return e&&e!=="."?e:void 0}function On(t){return(t.title??"").replace(/^\s*\[[^\]]{0,80}\]\s*/,"").trim()||t.title||t.id.slice(0,8)}function Te(t,e,n,r){t.textContent="";for(let s of e){let i=d("button","session-row");s.id===n&&i.classList.add("is-active");let o=d("span","session-title",On(s));i.appendChild(o);let l=d("span","session-meta"),a=Dn(s.cwd);if(a){let c=d("span","session-cwd",a);c.title=s.cwd??a,l.appendChild(c)}let p=d("span",s.mode==="live"?"badge badge-live":"badge badge-readonly");p.textContent=s.mode==="live"?"live":"read-only",l.appendChild(p),s.alive&&l.appendChild(d("span","badge badge-alive","running")),s.updatedAt&&l.appendChild(d("span","session-time",Kn(s.updatedAt))),i.appendChild(l),i.addEventListener("click",()=>r(s.id)),t.appendChild(i)}e.length===0&&t.appendChild(d("div","empty","No sessions found."))}function Se(t,e){ht(t,e,jn)}function jn(t){switch(t.kind){case"user":{let e=d("div","msg msg-user");return e.appendChild(d("div","msg-role","you")),e.appendChild(d("div","msg-body",t.text)),e}case"assistant":{let e=d("div","msg msg-assistant");e.appendChild(d("div","msg-role","agent"));let n=d("div","msg-body md-body");return n.appendChild(ut(t.text)),e.appendChild(n),e}case"thinking":{let e=d("details","msg msg-thinking");return e.appendChild(d("summary","msg-role","thinking")),e.appendChild(d("div","msg-body",t.text)),e}case"error":{let e=d("div","msg msg-error");return e.appendChild(d("div","msg-role","error")),e.appendChild(d("div","msg-body",t.message)),e}case"notice":return d("div","notice",t.text);case"tool":return Un(t)}}function Un(t){let e=d("details",`tool tool-${t.status}`),n=d("summary","tool-summary");n.appendChild(d("span",`tool-dot tool-dot-${t.status}`,"")),n.appendChild(d("span","tool-name",t.name)),t.inputPreview&&n.appendChild(d("span","tool-target",Zn(t.name,t.inputPreview))),e.appendChild(n);let r=d("div","tool-body");if(t.inputPreview){r.appendChild(d("div","tool-label","input"));let s=G(t.inputPreview);if(s.length>gt){let i=d("pre","tool-pre",s.slice(0,gt));r.appendChild(i);let o=d("button","tool-more",`Show full input (${s.length.toLocaleString()} chars)`);o.addEventListener("click",()=>{i.textContent=s,o.remove()}),r.appendChild(o)}else r.appendChild(d("pre","tool-pre",s))}if(t.outputUnavailable===!0)r.appendChild(d("div","tool-unavailable","Result not available after refresh \u2014 successful tool output is not persisted to the session ledger."));else if(t.output!==void 0&&t.output!==""){r.appendChild(d("div","tool-label","output"));let s=G(t.output);if(s.length>ft){let i=d("pre","tool-pre",s.slice(0,ft));r.appendChild(i);let o=d("button","tool-more",`Show full output (${s.length.toLocaleString()} chars)`);o.addEventListener("click",()=>{i.textContent=s,o.remove()}),r.appendChild(o)}else r.appendChild(d("pre","tool-pre",s))}return t.diff!==void 0&&(r.appendChild(d("div","tool-label","diff")),r.appendChild(Fn(G(String(t.diff))))),e.appendChild(r),e}function ve(t,e){let n=t.replace(/\s+/g," ").trim();return n.length<=e?n:`${n.slice(0,e-1)}\u2026`}function Fn(t){let e=d("pre","tool-pre tool-diff");for(let n of t.split(`
64
- `)){let r=document.createElement("span");r.textContent=n,r.className=n.startsWith("+++")||n.startsWith("---")?"diff-ctx":n.startsWith("+")?"diff-add":n.startsWith("-")?"diff-del":n.startsWith("@@")?"diff-hunk":"diff-ctx",e.appendChild(r)}return e}function Zn(t,e){try{let n=JSON.parse(e);if((t==="bash"||t==="shell")&&typeof n.command=="string")return ve(n.command,80);if((t==="edit_file"||t==="write_file"||t==="read_file")&&typeof n.file_path=="string")return n.file_path;if(t==="agent"&&typeof n.prompt=="string")return ve(n.prompt,60);if((t==="grep"||t==="glob")&&typeof n.pattern=="string")return n.pattern}catch{}return ve(e,90)}function Kn(t){let e=Date.parse(t);if(Number.isNaN(e))return"";let n=Math.max(0,(Date.now()-e)/1e3);return n<60?"just now":n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:`${Math.floor(n/86400)}d ago`}var mt=/bash|delete|remove|overwrite|rm |drop/i;function Qn(t){if(!t)return"";let e=Math.floor((Date.now()-new Date(t).getTime())/6e4);return e>=1?`waiting ${e}m`:""}function Ce(t,e,n){t.textContent="",t.classList.toggle("has-pending",e.length>0);for(let r of e){let s=r.request??{},i=s.title??s.message??"The agent is waiting for a response.",o=mt.test(i)||mt.test(s.serverName??""),l=d("div",o?"approval-card approval-card--destructive":"approval-card"),a=d("div","approval-head");a.appendChild(d("span","approval-badge",s.origin==="agent"?"question":"approval")),s.serverName&&a.appendChild(d("span","approval-source",s.serverName));let p=Qn(r.createdAt);p&&a.appendChild(d("span","approval-time",p)),l.appendChild(a),l.appendChild(d("div","approval-title",i)),s.description&&l.appendChild(d("div","approval-desc",s.description));let c=d("div","approval-actions");if(s.type==="choice"&&Array.isArray(s.choices)&&s.choices.length>0)for(let u of s.choices){let m=d("button","approval-btn",u);m.addEventListener("click",()=>n(r.id,{action:"accept",content:{value:u}})),c.appendChild(m)}else if(s.type==="multi_choice"&&Array.isArray(s.choices)&&s.choices.length>0){let u=d("div","approval-checkboxes"),m=[];for(let w of s.choices){let H=d("label","approval-checkbox-row"),$=document.createElement("input");$.type="checkbox",$.value=w,m.push($),H.appendChild($),H.appendChild(d("span",void 0,w)),u.appendChild(H)}l.appendChild(u);let g=d("button","approval-btn approval-primary","Submit");g.addEventListener("click",()=>n(r.id,{action:"accept",content:{value:m.filter(w=>w.checked).map(w=>w.value)}})),c.appendChild(g)}else if(s.type==="text"||s.type==="number"){let u=document.createElement("input");u.className="approval-input",u.type=s.type==="number"?"number":"text",s.questionDefault!==void 0&&(u.value=String(s.questionDefault));let m=()=>n(r.id,{action:"accept",content:{value:s.type==="number"?Number(u.value):u.value}});u.addEventListener("keydown",w=>{w.key==="Enter"&&m()}),l.appendChild(u);let g=d("button","approval-btn approval-primary","Submit");g.addEventListener("click",m),c.appendChild(g)}else{let u=d("button","approval-btn approval-primary","Approve");u.addEventListener("click",()=>n(r.id,{action:"accept",content:{value:!0}})),c.appendChild(u)}let h=d("button","approval-btn approval-danger","Deny");h.addEventListener("click",()=>n(r.id,{action:"decline"})),c.appendChild(h),l.appendChild(c),t.appendChild(l)}}var kt=0;function L(t){return kt+=1,`${t}_${kt}`}function _(t){return typeof t=="string"?t:void 0}function xt(t){let e=t;if(typeof e.kind=="string")switch(e.kind){case"user":return{kind:"user",id:L("u"),text:_(e.text)??""};case"assistant":return{kind:"assistant",id:L("a"),text:_(e.text)??""};case"tool":{let n=_(e.input)??"";return n.trim()==="\u2026"?void 0:{kind:"tool",id:L("t"),name:_(e.toolName)??"tool",inputPreview:n,status:"ok",outputUnavailable:!0}}case"tool_error":{let n=_(e.content)??"",r=n.split(`
65
- `,1)[0]??"";return{kind:"tool",id:L("t"),name:_(e.toolName)??"error",inputPreview:r,status:"error",output:n}}case"error":return{kind:"error",id:L("e"),message:_(e.message)??"error"};case"done":{let n=e.costUsd,r=e.durationMs,s=[];return typeof n=="number"&&s.push(`$${n.toFixed(4)}`),typeof r=="number"&&s.push(`${(r/1e3).toFixed(1)}s`),{kind:"notice",id:L("n"),text:s.length?`turn complete \xB7 ${s.join(" \xB7 ")}`:"turn complete"}}case"paused":return{kind:"notice",id:L("n"),text:"paused \u2014 usage limit"};case"resumed":return{kind:"notice",id:L("n"),text:"resumed"};default:return}}function bt(t,e){let n=e;if(n.kind!=="done")return t;let r=n.costUsd,s=n.durationMs;return{costUsd:t.costUsd+(typeof r=="number"?r:0),durationMs:t.durationMs+(typeof s=="number"?s:0),turns:t.turns+1}}function Ee(t,e){return Number.isInteger(e)&&e>=0&&e<t.length}function wt(t,e){if(!Ee(t,e)||e===0)return t.slice();let n=t.slice(),r=n[e-1],s=n[e];return r===void 0||s===void 0?t.slice():(n[e-1]=s,n[e]=r,n)}function yt(t,e){if(!Ee(t,e)||e===t.length-1)return t.slice();let n=t.slice(),r=n[e+1],s=n[e];return r===void 0||s===void 0?t.slice():(n[e+1]=s,n[e]=r,n)}function vt(t,e){if(!Ee(t,e))return t.slice();let n=t.slice();return n.splice(e,1),n}var se=class{constructor(e){this.deps=e}deps;queue=[];flushing=!1;entries(){return[...this.queue]}clear(){this.queue=[],this.render()}wire(){let e=()=>{let n=this.deps.input.value.trim();n&&(this.queue=[...this.queue,n],this.deps.input.value="",Q(this.deps.input),this.render(),this.flush())};this.deps.send.addEventListener("click",e),this.deps.input.addEventListener("keydown",n=>{n.key==="Enter"&&(n.metaKey||n.ctrlKey)&&e()})}render(){let e=this.deps.container;e.textContent="",this.queue.forEach((n,r)=>{let s=document.createElement("div");s.className="queue-row";let i=document.createElement("span");i.className="queue-text",i.textContent=n,s.appendChild(i);for(let[o,l]of[["\u2191",()=>{this.queue=wt(this.queue,r)}],["\u2193",()=>{this.queue=yt(this.queue,r)}],["\u2715",()=>{this.queue=vt(this.queue,r)}]]){let a=document.createElement("button");a.className="queue-btn",a.textContent=o,a.addEventListener("click",()=>{l(),this.render()}),s.appendChild(a)}e.appendChild(s)})}async flush(){if(this.flushing||!this.deps.isLive()||this.deps.isTurnActive())return;let e=this.queue[0];if(e!==void 0){this.flushing=!0;try{await this.deps.submit(e),this.queue=this.queue.slice(1),this.render(),this.deps.onAccepted()}catch(n){this.deps.onError(n instanceof Error?n.message:"send failed")}finally{this.flushing=!1}}}};function Tt(t,e=80){return t.scrollHeight-t.scrollTop-t.clientHeight<=e}var Et=He(),N=[],v,re=[],A={costUsd:0,durationMs:0,turns:0},Re,R=[],Le,B=!1,Z=!1;function b(t){let e=document.getElementById(t);if(!e)throw new Error(`missing #${t}`);return e}var Ae;function $e(){return Ae||(Ae=new se({container:b("queue"),input:b("prompt"),send:b("send"),submit:async t=>{if(v===void 0)throw new Error("no active session");await z(`/api/sessions/${encodeURIComponent(v)}/prompt`,{method:"POST",body:JSON.stringify({text:t})})},isLive:Pe,isTurnActive:()=>B,onAccepted:()=>{B=!0,ie()},onError:t=>{b("status").textContent=t}})),Ae}async function z(t,e){let n=await fetch(t,{...e,headers:{authorization:`Bearer ${Et}`,"content-type":"application/json",...e?.headers??{}}});if(n.status===401)throw new Error("Session credential missing \u2014 reopen the URL printed by `afk web`. A new tab does not inherit the credential from the first one.");if(!n.ok)throw new Error(`${n.status} ${await n.text()}`);return await n.json()}function Wn(t){t.scrollTop=t.scrollHeight}function Gn(){return N.find(t=>t.id===v)}function Pe(){return Gn()?.mode==="live"}async function Ie(){if(N=(await z("/api/sessions")).sessions,v===void 0&&N.length>0){let e=N[0];e&&oe(e.id)}Te(b("sessions"),N,v,oe)}function oe(t){v=t;let e=t;re=[],$e().clear(),A={costUsd:0,durationMs:0,turns:0},Re?.stop(),B=!1,Z=!1,Te(b("sessions"),N,v,oe),Se(b("transcript"),re),St(),ie(),Re=new K(t,Et,{onEvent:n=>{if(v!==e)return;let s=n.record;if(!s)return;(s.kind==="done"||s.kind==="error")&&(B=!1,ie(),$e().flush());let i=xt(s);if(A=bt(A,s),i){re.push(i);let o=Tt(b("transcript"));Se(b("transcript"),re),o&&Wn(b("transcript"))}Rt()},onStatus:n=>{if(v!==e)return;let r=b("status");r.textContent=n==="ended"?"session ended":n,r.className=`status status-${n}`,n==="ended"&&(B=!1),Z=n==="reconnecting"||n==="connecting",St(),ie()}}),Re.start()}function Rt(){let t=[`${A.turns} turns`];A.costUsd>0&&t.push(`$${A.costUsd.toFixed(4)}`),A.durationMs>0&&t.push(`${(A.durationMs/1e3).toFixed(1)}s`),b("meter").textContent=t.join(" \xB7 ")}function St(){let t=Pe(),e=b("prompt"),n=b("send"),r=!t||Z;e.disabled=r,n.disabled=r,e.placeholder=t?Z?"Reconnecting\u2026":"Message the agent\u2026 (queues while it works)":"Read-only \u2014 this session runs in another process",b("composer").classList.toggle("is-readonly",!t),b("composer").classList.toggle("is-reconnecting",t&&Z)}function ie(){b("stop").hidden=!(B&&Pe())}async function Vn(){let t=b("new-session");t.disabled=!0,t.textContent="starting\u2026";let e=v;try{let{session:n}=await z("/api/sessions",{method:"POST",body:JSON.stringify({})});if(await Ie(),v!==e&&v!==n.id)return;oe(n.id)}catch(n){b("status").textContent=n instanceof Error?n.message:"could not start session"}finally{t.disabled=!1,t.textContent="+ New"}}async function Ct(){let t=await z("/api/pending"),e=t.pending.length!==R.length||t.pending.some((n,r)=>n.id!==R[r]?.id);R=t.pending,e&&Ce(b("approvals"),R,Lt),document.title=R.length>0?`(${R.length}) afk web`:"afk web"}function Lt(t,e){R=R.filter(n=>n.id!==t),Ce(b("approvals"),R,Lt),z("/api/approve",{method:"POST",body:JSON.stringify({requestId:t,response:e})}).catch(n=>{b("status").textContent=n instanceof Error?n.message:"approval failed"})}async function Xn(){if(v===void 0)return;let t=b("stop");t.disabled=!0,t.textContent="Stopping\u2026";try{await z(`/api/sessions/${encodeURIComponent(v)}/interrupt`,{method:"POST",body:JSON.stringify({})})}catch(e){throw t.disabled=!1,t.textContent="Stop",e}}async function Jn(){We({input:b("prompt"),loadCommands:async()=>(await z("/api/commands")).commands}),$e().wire(),b("new-session").addEventListener("click",()=>{Vn()}),b("stop").addEventListener("click",()=>{Xn().catch(t=>{b("status").textContent=t instanceof Error?t.message:"stop failed"})}),Rt(),await Ie(),setInterval(()=>{Ie().catch(()=>{})},1e4),Le=setInterval(()=>{Ct().catch(()=>{})},1e3),Ct().catch(()=>{}),window.addEventListener("beforeunload",()=>{Le&&clearInterval(Le)})}Jn().catch(t=>{b("status").textContent=t instanceof Error?t.message:String(t)});
62
+ `}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>${E(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){let r=this.parser.parseInline(n),s=st(t);if(s===null)return r;t=s;let i='<a href="'+t+'"';return e&&(i+=' title="'+E(e)+'"'),i+=">"+r+"</a>",i}image({href:t,title:e,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let s=st(t);if(s===null)return E(n);t=s;let i=`<img src="${t}" alt="${E(n)}"`;return e&&(i+=` title="${E(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:E(t.text)}},Te=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}checkbox({raw:t}){return t}},S=class fe{options;renderer;textRenderer;constructor(e){this.options=e||M,this.options.renderer=this.options.renderer||new te,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Te}static parse(e,n){return new fe(n).parse(e)}static parseInline(e,n){return new fe(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let r=0;r<e.length;r++){let s=e[r];if(this.options.extensions?.renderers?.[s.type]){let o=s,l=this.options.extensions.renderers[o.type].call({parser:this},o);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(o.type)){n+=l||"";continue}}let i=s;switch(i.type){case"space":{n+=this.renderer.space(i);break}case"hr":{n+=this.renderer.hr(i);break}case"heading":{n+=this.renderer.heading(i);break}case"code":{n+=this.renderer.code(i);break}case"table":{n+=this.renderer.table(i);break}case"blockquote":{n+=this.renderer.blockquote(i);break}case"list":{n+=this.renderer.list(i);break}case"checkbox":{n+=this.renderer.checkbox(i);break}case"html":{n+=this.renderer.html(i);break}case"def":{n+=this.renderer.def(i);break}case"paragraph":{n+=this.renderer.paragraph(i);break}case"text":{n+=this.renderer.text(i);break}default:{let o='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}parseInline(e,n=this.renderer){this.renderer.parser=this;let r="";for(let s=0;s<e.length;s++){let i=e[s];if(this.options.extensions?.renderers?.[i.type]){let l=this.options.extensions.renderers[i.type].call({parser:this},i);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){r+=l||"";continue}}let o=i;switch(o.type){case"escape":{r+=n.text(o);break}case"html":{r+=n.html(o);break}case"link":{r+=n.link(o);break}case"image":{r+=n.image(o);break}case"checkbox":{r+=n.checkbox(o);break}case"strong":{r+=n.strong(o);break}case"em":{r+=n.em(o);break}case"codespan":{r+=n.codespan(o);break}case"br":{r+=n.br(o);break}case"del":{r+=n.del(o);break}case"text":{r+=n.text(o);break}default:{let l='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return r}},U=class{options;block;constructor(t){this.options=t||M}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(){return this.block?T.lex:T.lexInline}provideParser(){return this.block?S.parse:S.parseInline}},Nn=class{defaults=me();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=S;Renderer=te;TextRenderer=Te;Lexer=T;Tokenizer=ee;Hooks=U;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let r of t)switch(n=n.concat(e.call(this,r)),r.type){case"table":{let s=r;for(let i of s.header)n=n.concat(this.walkTokens(i.tokens,e));for(let i of s.rows)for(let o of i)n=n.concat(this.walkTokens(o.tokens,e));break}case"list":{let s=r;n=n.concat(this.walkTokens(s.items,e));break}default:{let s=r;this.defaults.extensions?.childTokens?.[s.type]?this.defaults.extensions.childTokens[s.type].forEach(i=>{let o=s[i].flat(1/0);n=n.concat(this.walkTokens(o,e))}):s.tokens&&(n=n.concat(this.walkTokens(s.tokens,e)))}}return n}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){let i=e.renderers[s.name];i?e.renderers[s.name]=function(...o){let l=s.renderer.apply(this,o);return l===!1&&(l=i.apply(this,o)),l}:e.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=e[s.level];i?i.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)}),r.extensions=e),n.renderer){let s=this.defaults.renderer||new te(this.defaults);for(let i in n.renderer){if(!(i in s))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let o=i,l=n.renderer[o],a=s[o];s[o]=(...p)=>{let c=l.apply(s,p);return c===!1&&(c=a.apply(s,p)),c||""}}r.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new ee(this.defaults);for(let i in n.tokenizer){if(!(i in s))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let o=i,l=n.tokenizer[o],a=s[o];s[o]=(...p)=>{let c=l.apply(s,p);return c===!1&&(c=a.apply(s,p)),c}}r.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new U;for(let i in n.hooks){if(!(i in s))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let o=i,l=n.hooks[o],a=s[o];U.passThroughHooks.has(i)?s[o]=p=>{if(this.defaults.async&&U.passThroughHooksRespectAsync.has(i))return(async()=>{let h=await l.call(s,p);return a.call(s,h)})();let c=l.call(s,p);return a.call(s,c)}:s[o]=(...p)=>{if(this.defaults.async)return(async()=>{let h=await l.apply(s,p);return h===!1&&(h=await a.apply(s,p)),h})();let c=l.apply(s,p);return c===!1&&(c=a.apply(s,p)),c}}r.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(o){let l=[];return l.push(i.call(this,o)),s&&(l=l.concat(s.call(this,o))),l}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return T.lex(t,e??this.defaults)}parser(t,e){return S.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let r={...n},s={...this.defaults,...r},i=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&r.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(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 o=s.hooks?await s.hooks.preprocess(e):e,l=await(s.hooks?await s.hooks.provideLexer():t?T.lex:T.lexInline)(o,s),a=s.hooks?await s.hooks.processAllTokens(l):l;s.walkTokens&&await Promise.all(this.walkTokens(a,s.walkTokens));let p=await(s.hooks?await s.hooks.provideParser():t?S.parse:S.parseInline)(a,s);return s.hooks?await s.hooks.postprocess(p):p})().catch(i);try{s.hooks&&(e=s.hooks.preprocess(e));let o=(s.hooks?s.hooks.provideLexer():t?T.lex:T.lexInline)(e,s);s.hooks&&(o=s.hooks.processAllTokens(o)),s.walkTokens&&this.walkTokens(o,s.walkTokens);let l=(s.hooks?s.hooks.provideParser():t?S.parse:S.parseInline)(o,s);return s.hooks&&(l=s.hooks.postprocess(l)),l}catch(o){return i(o)}}}onError(t,e){return n=>{if(n.message+=`
63
+ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+E(n.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},P=new Nn;function b(t,e){return P.parse(t,e)}b.options=b.setOptions=function(t){return P.setOptions(t),b.defaults=P.defaults,ot(b.defaults),b};b.getDefaults=me;b.defaults=M;b.use=function(...t){return P.use(...t),b.defaults=P.defaults,ot(b.defaults),b};b.walkTokens=function(t,e){return P.walkTokens(t,e)};b.parseInline=P.parseInline;b.Parser=S;b.parser=S.parse;b.Renderer=te;b.TextRenderer=Te;b.Lexer=T;b.lexer=T.lex;b.Tokenizer=ee;b.Hooks=U;b.parse=b;var $s=b.options,Is=b.setOptions,Ps=b.use,Ms=b.walkTokens,_s=b.parseInline;var zs=S.parse,Hs=T.lex;var Bn=["http:","https:","mailto:"];function Dn(t){try{let e=new URL(t);return Bn.includes(e.protocol)?e.href:void 0}catch{return}}function k(t,e){let n=document.createElement(t);return e&&(n.className=e),n}function C(t,e){if(e)for(let n of e)switch(n.type){case"strong":{let r=k("strong");C(r,n.tokens),t.appendChild(r);break}case"em":{let r=k("em");C(r,n.tokens),t.appendChild(r);break}case"del":{let r=k("s");C(r,n.tokens),t.appendChild(r);break}case"codespan":{let r=k("code","md-code-inline");r.textContent=n.text,t.appendChild(r);break}case"link":{let r=n,s=Dn(r.href);if(s===void 0){let o=k("span");C(o,r.tokens),t.appendChild(o);break}let i=k("a","md-link");i.href=s,i.target="_blank",i.rel="noopener noreferrer",C(i,r.tokens),t.appendChild(i);break}case"image":{let r=k("span","md-image");r.textContent=`[image: ${n.text||"untitled"}]`,t.appendChild(r);break}case"br":t.appendChild(k("br"));break;default:{let r=n.text??"",s=n.tokens;s&&s.length>0&&n.type==="text"?C(t,s):r&&t.appendChild(document.createTextNode(r));break}}}function On(t){let e=t.ordered?k("ol","md-list"):k("ul","md-list");t.ordered&&typeof t.start=="number"&&t.start>1&&(e.start=t.start);for(let n of t.items){let r=k("li");if(n.task){let s=k("input","md-task");s.type="checkbox",s.checked=!!n.checked,s.disabled=!0,r.appendChild(s)}Se(r,n.tokens),e.appendChild(r)}return e}function jn(t){let e=k("pre","md-pre"),n=k("code");if(t.lang){let r=t.lang.split(/\s+/)[0]??"";r&&(n.className=`md-lang-${r}`,e.dataset.lang=r)}return n.textContent=t.text,e.appendChild(n),e}function Fn(t){let e=k("table","md-table"),n=k("thead"),r=k("tr");for(let i of t.header){let o=k("th");C(o,i.tokens),r.appendChild(o)}n.appendChild(r),e.appendChild(n);let s=k("tbody");for(let i of t.rows){let o=k("tr");for(let l of i){let a=k("td");C(a,l.tokens),o.appendChild(a)}s.appendChild(o)}return e.appendChild(s),e}function Se(t,e){for(let n of e)switch(n.type){case"heading":{let r=Math.min(Math.max(n.depth,1),6),s=k(`h${r}`,"md-heading");C(s,n.tokens),t.appendChild(s);break}case"paragraph":{let r=k("p","md-p");C(r,n.tokens),t.appendChild(r);break}case"code":t.appendChild(jn(n));break;case"list":t.appendChild(On(n));break;case"blockquote":{let r=k("blockquote","md-quote");Se(r,n.tokens),t.appendChild(r);break}case"table":t.appendChild(Fn(n));break;case"hr":t.appendChild(k("hr","md-hr"));break;case"space":break;case"html":{let r=k("p","md-p");r.textContent=n.text,t.appendChild(r);break}default:{let r=n.tokens;if(r&&r.length>0){let i=k("p","md-p");C(i,r),t.appendChild(i);break}let s=n.text??"";if(s.trim()){let i=k("p","md-p");i.textContent=s,t.appendChild(i)}break}}}function gt(t,e="md"){let n=k("div",e);try{Se(n,new T().lex(t))}catch{n.textContent=t}return n}var re=new Map;function Un(t,e){return t.kind!=="tool"?!1:e.className!==`tool tool-${t.status}`}function kt(t,e,n){e.length<t.childElementCount&&(re.clear(),t.textContent="");for(let r of e){let s=re.get(r.id);if(s===void 0){let i=n(r);re.set(r.id,i),t.appendChild(i)}else if(Un(r,s)){let i=n(r);re.set(r.id,i),t.replaceChild(i,s)}}}var bt=2e3,xt=2e3;function d(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!==void 0&&(r.textContent=n),r}function Zn(t){if(!t)return;let e=t.replace(/[/\\]+$/,"").split(/[/\\]/).pop()??"";return e&&e!=="."?e:void 0}function Kn(t){return(t.title??"").replace(/^\s*\[[^\]]{0,80}\]\s*/,"").trim()||t.title||t.id.slice(0,8)}function Ee(t,e,n,r){t.textContent="";for(let s of e){let i=d("button","session-row");s.id===n&&i.classList.add("is-active");let o=d("span","session-title",Kn(s));i.appendChild(o);let l=d("span","session-meta"),a=Zn(s.cwd);if(a){let c=d("span","session-cwd",a);c.title=s.cwd??a,l.appendChild(c)}let p=d("span",s.mode==="live"?"badge badge-live":"badge badge-readonly");p.textContent=s.mode==="live"?"live":"read-only",l.appendChild(p),s.alive&&l.appendChild(d("span","badge badge-alive","running")),s.updatedAt&&l.appendChild(d("span","session-time",Xn(s.updatedAt))),i.appendChild(l),i.addEventListener("click",()=>r(s.id)),t.appendChild(i)}e.length===0&&t.appendChild(d("div","empty","No sessions found."))}function Le(t,e){kt(t,e,Qn)}function Qn(t){switch(t.kind){case"user":{let e=d("div","msg msg-user");return e.appendChild(d("div","msg-role","you")),e.appendChild(d("div","msg-body",t.text)),e}case"assistant":{let e=d("div","msg msg-assistant");e.appendChild(d("div","msg-role","agent"));let n=d("div","msg-body md-body");return n.appendChild(gt(t.text)),e.appendChild(n),e}case"thinking":{let e=d("details","msg msg-thinking");return e.appendChild(d("summary","msg-role","thinking")),e.appendChild(d("div","msg-body",t.text)),e}case"error":{let e=d("div","msg msg-error");return e.appendChild(d("div","msg-role","error")),e.appendChild(d("div","msg-body",t.message)),e}case"notice":return d("div","notice",t.text);case"tool":return Wn(t)}}function Wn(t){let e=d("details",`tool tool-${t.status}`),n=d("summary","tool-summary");n.appendChild(d("span",`tool-dot tool-dot-${t.status}`,"")),n.appendChild(d("span","tool-name",t.name)),t.inputPreview&&n.appendChild(d("span","tool-target",Vn(t.name,t.inputPreview))),e.appendChild(n);let r=d("div","tool-body");if(t.inputPreview){r.appendChild(d("div","tool-label","input"));let s=X(t.inputPreview);if(s.length>xt){let i=d("pre","tool-pre",s.slice(0,xt));r.appendChild(i);let o=d("button","tool-more",`Show full input (${s.length.toLocaleString()} chars)`);o.addEventListener("click",()=>{i.textContent=s,o.remove()}),r.appendChild(o)}else r.appendChild(d("pre","tool-pre",s))}if(t.outputUnavailable===!0)r.appendChild(d("div","tool-unavailable","Result not available after refresh \u2014 successful tool output is not persisted to the session ledger."));else if(t.output!==void 0&&t.output!==""){r.appendChild(d("div","tool-label","output"));let s=X(t.output);if(s.length>bt){let i=d("pre","tool-pre",s.slice(0,bt));r.appendChild(i);let o=d("button","tool-more",`Show full output (${s.length.toLocaleString()} chars)`);o.addEventListener("click",()=>{i.textContent=s,o.remove()}),r.appendChild(o)}else r.appendChild(d("pre","tool-pre",s))}return t.diff!==void 0&&(r.appendChild(d("div","tool-label","diff")),r.appendChild(Gn(X(String(t.diff))))),e.appendChild(r),e}function Ce(t,e){let n=t.replace(/\s+/g," ").trim();return n.length<=e?n:`${n.slice(0,e-1)}\u2026`}function Gn(t){let e=d("pre","tool-pre tool-diff");for(let n of t.split(`
64
+ `)){let r=document.createElement("span");r.textContent=n,r.className=n.startsWith("+++")||n.startsWith("---")?"diff-ctx":n.startsWith("+")?"diff-add":n.startsWith("-")?"diff-del":n.startsWith("@@")?"diff-hunk":"diff-ctx",e.appendChild(r)}return e}function Vn(t,e){try{let n=JSON.parse(e);if((t==="bash"||t==="shell")&&typeof n.command=="string")return Ce(n.command,80);if((t==="edit_file"||t==="write_file"||t==="read_file")&&typeof n.file_path=="string")return n.file_path;if(t==="agent"&&typeof n.prompt=="string")return Ce(n.prompt,60);if((t==="grep"||t==="glob")&&typeof n.pattern=="string")return n.pattern}catch{}return Ce(e,90)}function Xn(t){let e=Date.parse(t);if(Number.isNaN(e))return"";let n=Math.max(0,(Date.now()-e)/1e3);return n<60?"just now":n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:`${Math.floor(n/86400)}d ago`}var wt=/bash|delete|remove|overwrite|rm |drop/i;function Jn(t){if(!t)return"";let e=Math.floor((Date.now()-new Date(t).getTime())/6e4);return e>=1?`waiting ${e}m`:""}function Re(t,e,n){t.textContent="",t.classList.toggle("has-pending",e.length>0);for(let r of e){let s=r.request??{},i=s.title??s.message??"The agent is waiting for a response.",o=wt.test(i)||wt.test(s.serverName??""),l=d("div",o?"approval-card approval-card--destructive":"approval-card"),a=d("div","approval-head");a.appendChild(d("span","approval-badge",s.origin==="agent"?"question":"approval")),s.serverName&&a.appendChild(d("span","approval-source",s.serverName));let p=Jn(r.createdAt);p&&a.appendChild(d("span","approval-time",p)),l.appendChild(a),l.appendChild(d("div","approval-title",i)),s.description&&l.appendChild(d("div","approval-desc",s.description));let c=d("div","approval-actions");if(s.type==="choice"&&Array.isArray(s.choices)&&s.choices.length>0)for(let u of s.choices){let g=d("button","approval-btn",u);g.addEventListener("click",()=>n(r.id,{action:"accept",content:{value:u}})),c.appendChild(g)}else if(s.type==="multi_choice"&&Array.isArray(s.choices)&&s.choices.length>0){let u=d("div","approval-checkboxes"),g=[];for(let w of s.choices){let H=d("label","approval-checkbox-row"),$=document.createElement("input");$.type="checkbox",$.value=w,g.push($),H.appendChild($),H.appendChild(d("span",void 0,w)),u.appendChild(H)}l.appendChild(u);let m=d("button","approval-btn approval-primary","Submit");m.addEventListener("click",()=>n(r.id,{action:"accept",content:{value:g.filter(w=>w.checked).map(w=>w.value)}})),c.appendChild(m)}else if(s.type==="text"||s.type==="number"){let u=document.createElement("input");u.className="approval-input",u.type=s.type==="number"?"number":"text",s.questionDefault!==void 0&&(u.value=String(s.questionDefault));let g=()=>n(r.id,{action:"accept",content:{value:s.type==="number"?Number(u.value):u.value}});u.addEventListener("keydown",w=>{w.key==="Enter"&&g()}),l.appendChild(u);let m=d("button","approval-btn approval-primary","Submit");m.addEventListener("click",g),c.appendChild(m)}else{let u=d("button","approval-btn approval-primary","Approve");u.addEventListener("click",()=>n(r.id,{action:"accept",content:{value:!0}})),c.appendChild(u)}let h=d("button","approval-btn approval-danger","Deny");h.addEventListener("click",()=>n(r.id,{action:"decline"})),c.appendChild(h),l.appendChild(c),t.appendChild(l)}}var vt=0;function R(t){return vt+=1,`${t}_${vt}`}function _(t){return typeof t=="string"?t:void 0}function yt(t){let e=t;if(typeof e.kind=="string")switch(e.kind){case"user":return{kind:"user",id:R("u"),text:_(e.text)??""};case"assistant":return{kind:"assistant",id:R("a"),text:_(e.text)??""};case"tool":{let n=_(e.input)??"";return n.trim()==="\u2026"?void 0:{kind:"tool",id:R("t"),name:_(e.toolName)??"tool",inputPreview:n,status:"ok",outputUnavailable:!0}}case"tool_error":{let n=_(e.content)??"",r=n.split(`
65
+ `,1)[0]??"";return{kind:"tool",id:R("t"),name:_(e.toolName)??"error",inputPreview:r,status:"error",output:n}}case"error":return{kind:"error",id:R("e"),message:_(e.message)??"error"};case"done":{let n=e.costUsd,r=e.durationMs,s=[];return typeof n=="number"&&s.push(`$${n.toFixed(4)}`),typeof r=="number"&&s.push(`${(r/1e3).toFixed(1)}s`),{kind:"notice",id:R("n"),text:s.length?`turn complete \xB7 ${s.join(" \xB7 ")}`:"turn complete"}}case"paused":return{kind:"notice",id:R("n"),text:"paused \u2014 usage limit"};case"resumed":return{kind:"notice",id:R("n"),text:"resumed"};default:return}}function Tt(t,e){let n=e;if(n.kind!=="done")return t;let r=n.costUsd,s=n.durationMs;return{costUsd:t.costUsd+(typeof r=="number"?r:0),durationMs:t.durationMs+(typeof s=="number"?s:0),turns:t.turns+1}}function ie(t,e){return Number.isInteger(e)&&e>=0&&e<t.length}function St(t,e){if(!ie(t,e)||e===0)return t.slice();let n=t.slice(),r=n[e-1],s=n[e];return r===void 0||s===void 0?t.slice():(n[e-1]=s,n[e]=r,n)}function Ct(t,e){if(!ie(t,e)||e===t.length-1)return t.slice();let n=t.slice(),r=n[e+1],s=n[e];return r===void 0||s===void 0?t.slice():(n[e+1]=s,n[e]=r,n)}function Et(t,e){if(!ie(t,e))return t.slice();let n=t.slice();return n.splice(e,1),n}function Lt(t,e,n){if(!ie(t,e))return t.slice();let r=t.slice();return r[e]=n,r}var oe=class{constructor(e){this.deps=e}deps;queue=[];flushing=!1;entries(){return[...this.queue]}clear(){this.queue=[],this.render()}wire(){let e=()=>{let n=this.deps.input.value.trim();n&&(this.queue=[...this.queue,n],this.deps.input.value="",W(this.deps.input),this.render(),this.flush())};this.deps.send.addEventListener("click",e),this.deps.input.addEventListener("keydown",n=>{n.key==="Enter"&&(n.metaKey||n.ctrlKey)&&e()})}render(){let e=this.deps.container;e.textContent="",this.queue.forEach((n,r)=>{let s=document.createElement("div");s.className="queue-row";let i=document.createElement("span");i.className="queue-text",i.textContent=n,s.appendChild(i);let o=document.createElement("button");o.className="queue-btn",o.textContent="\u270E",o.title="Edit",o.addEventListener("click",()=>{let l=document.createElement("input");l.className="queue-text queue-edit-input",l.value=n,s.replaceChild(l,i),l.focus();let a=!1,p=()=>{a||(a=!0,this.queue=Lt(this.queue,r,l.value),this.render())};l.addEventListener("keydown",c=>{c.key==="Enter"&&p(),c.key==="Escape"&&(c.preventDefault(),a=!0,s.replaceChild(i,l))}),l.addEventListener("blur",p)}),s.appendChild(o);for(let[l,a]of[["\u2191",()=>{this.queue=St(this.queue,r)}],["\u2193",()=>{this.queue=Ct(this.queue,r)}],["\u2715",()=>{this.queue=Et(this.queue,r)}]]){let p=document.createElement("button");p.className="queue-btn",p.textContent=l,p.addEventListener("click",()=>{a(),this.render()}),s.appendChild(p)}e.appendChild(s)})}async flush(){if(this.flushing||!this.deps.isLive()||this.deps.isTurnActive())return;let e=this.queue[0];if(e!==void 0){this.flushing=!0;try{await this.deps.submit(e),this.queue=this.queue.slice(1),this.render(),this.deps.onAccepted()}catch(n){this.deps.onError(n instanceof Error?n.message:"send failed")}finally{this.flushing=!1}}}};function Rt(t,e=80){return t.scrollHeight-t.scrollTop-t.clientHeight<=e}var It=Ne(),B=[],y,ae=[],A={costUsd:0,durationMs:0,turns:0},Ae,L=[],$e,D=!1,K=!1;function x(t){let e=document.getElementById(t);if(!e)throw new Error(`missing #${t}`);return e}var Ie;function Pe(){return Ie||(Ie=new oe({container:x("queue"),input:x("prompt"),send:x("send"),submit:async t=>{if(y===void 0)throw new Error("no active session");await z(`/api/sessions/${encodeURIComponent(y)}/prompt`,{method:"POST",body:JSON.stringify({text:t})})},isLive:_e,isTurnActive:()=>D,onAccepted:()=>{D=!0,le()},onError:t=>{q(t)}})),Ie}async function z(t,e){let n=await fetch(t,{...e,headers:{authorization:`Bearer ${It}`,"content-type":"application/json",...e?.headers??{}}});if(n.status===401){let r="Session credential missing \u2014 reopen the URL printed by `afk web`. A new tab does not inherit the credential from the first one.";try{let s=document.getElementById("status");s&&(s.textContent=r)}catch{}throw new Error(r)}if(!n.ok)throw new Error(`${n.status} ${await n.text()}`);return await n.json()}function Yn(t){t.scrollTop=t.scrollHeight}function es(){return B.find(t=>t.id===y)}function _e(){return es()?.mode==="live"}async function Me(){if(B=(await z("/api/sessions")).sessions,y===void 0&&B.length>0){let e=B[0];e&&ce(e.id)}Ee(x("sessions"),B,y,ce)}function ce(t){y=t;let e=t;ae=[],Pe().clear(),A={costUsd:0,durationMs:0,turns:0},Ae?.stop(),D=!1,K=!1,Ee(x("sessions"),B,y,ce),Le(x("transcript"),ae),At(),le(),Ae=new Q(t,It,{onEvent:n=>{if(y!==e)return;let s=n.record;if(!s)return;(s.kind==="done"||s.kind==="error")&&(D=!1,le(),Pe().flush());let i=yt(s);if(A=Tt(A,s),i){ae.push(i);let o=Rt(x("transcript"));Le(x("transcript"),ae),o&&Yn(x("transcript"))}Pt()},onStatus:n=>{if(y!==e)return;let r=x("status");r.textContent=n==="ended"?"session ended":n,r.className=`status status-${n}`,n==="ended"&&(D=!1),K=n==="reconnecting"||n==="connecting",At(),le()}}),Ae.start()}function Pt(){let t=[`${A.turns} turns`];A.costUsd>0&&t.push(`$${A.costUsd.toFixed(4)}`),A.durationMs>0&&t.push(`${(A.durationMs/1e3).toFixed(1)}s`),x("meter").textContent=t.join(" \xB7 ")}function At(){let t=_e(),e=x("prompt"),n=x("send"),r=!t||K;e.disabled=r,n.disabled=r,e.placeholder=t?K?"Reconnecting\u2026":"Message the agent\u2026 (queues while it works)":"Read-only \u2014 this session runs in another process",x("composer").classList.toggle("is-readonly",!t),x("composer").classList.toggle("is-reconnecting",t&&K)}function le(){x("stop").hidden=!(D&&_e())}async function ts(t,e){let n=x("new-session");n.disabled=!0,n.textContent="starting\u2026";let r=y;try{let s={model:t};e&&(s.cwd=e);let{session:i}=await z("/api/sessions",{method:"POST",body:JSON.stringify(s)});if(await Me(),y!==r&&y!==i.id)return;ce(i.id)}catch(s){q(s instanceof Error?s.message:"could not start session")}finally{n.disabled=!1,n.textContent="+ New"}}async function $t(){let t=await z("/api/pending"),e=t.pending.length!==L.length||t.pending.some((n,r)=>n.id!==L[r]?.id);L=t.pending,e&&Re(x("approvals"),L,Mt),document.title=L.length>0?`(${L.length}) afk web`:"afk web"}function Mt(t,e){L=L.filter(n=>n.id!==t),Re(x("approvals"),L,Mt),z("/api/approve",{method:"POST",body:JSON.stringify({requestId:t,response:e})}).catch(n=>{q(n instanceof Error?n.message:"approval failed")})}async function ns(){if(y===void 0)return;let t=x("stop");t.disabled=!0,t.textContent="Stopping\u2026";try{await z(`/api/sessions/${encodeURIComponent(y)}/interrupt`,{method:"POST",body:JSON.stringify({})})}catch(e){throw t.disabled=!1,t.textContent="Stop",e}}async function ss(){Ve({input:x("prompt"),loadCommands:async()=>(await z("/api/commands")).commands}),Pe().wire(),x("new-session").addEventListener("click",()=>Je((t,e)=>{ts(t,e)})),Xe(),x("stop").addEventListener("click",()=>{ns().catch(t=>{q(t instanceof Error?t.message:"stop failed")})}),Pt(),await Me(),setInterval(()=>{Me().catch(()=>{})},1e4),$e=setInterval(()=>{$t().catch(()=>{})},1e3),$t().catch(()=>{}),window.addEventListener("beforeunload",()=>{$e&&clearInterval($e)})}ss().catch(t=>{q(t instanceof Error?t.message:String(t))});
@@ -33,6 +33,7 @@
33
33
  <div id="status" class="status">idle</div>
34
34
  <button id="menu-toggle" class="menu-toggle" aria-label="Toggle sessions">☰</button>
35
35
  </header>
36
+ <div id="toast" class="toast" hidden></div>
36
37
 
37
38
  <main class="layout">
38
39
  <aside id="sidebar" class="sidebar">
@@ -42,6 +43,7 @@
42
43
  </div>
43
44
  <div id="sessions" class="sessions"></div>
44
45
  </aside>
46
+ <div id="sidebar-backdrop" class="sidebar-backdrop"></div>
45
47
 
46
48
  <section class="main">
47
49
  <div id="transcript" class="transcript"></div>
@@ -349,6 +349,21 @@ details[open] > .tool-summary::before { transform: rotate(90deg); }
349
349
  cursor: pointer; padding: 0 4px; font-size: 12px;
350
350
  }
351
351
  .queue-btn:hover { color: var(--accent); }
352
+ .queue-edit-input {
353
+ flex: 1; background: var(--bg-sunken); border: 1px solid var(--accent);
354
+ border-radius: 4px; color: var(--text); font: inherit; font-size: 12px;
355
+ padding: 1px 5px; min-width: 0;
356
+ }
357
+
358
+ /* ── sidebar backdrop (mobile close-on-outside-click) ────────────────────── */
359
+ .sidebar-backdrop {
360
+ display: none;
361
+ position: fixed; inset: 0; z-index: 8;
362
+ background: rgba(0,0,0,0.5);
363
+ }
364
+ @media (max-width: 720px) {
365
+ .sidebar.is-open ~ .sidebar-backdrop { display: block; }
366
+ }
352
367
 
353
368
  /* ── mobile ──────────────────────────────────────────────────────────────── */
354
369
  @media (max-width: 720px) {
@@ -369,3 +384,35 @@ details[open] > .tool-summary::before { transform: rotate(90deg); }
369
384
  border: 1px solid var(--error); border-radius: 6px; padding: 0 14px;
370
385
  }
371
386
  .stop:hover { background: rgba(248, 113, 113, 0.12); }
387
+
388
+ /* ── toast ───────────────────────────────────────────────────────────────── */
389
+ .toast {
390
+ position: fixed; top: 56px; right: 16px; z-index: 100;
391
+ max-width: 360px; padding: 10px 14px;
392
+ background: var(--bg-raised); border: 1px solid var(--error);
393
+ color: var(--error); border-radius: var(--radius);
394
+ font-size: 13px; line-height: 1.4;
395
+ opacity: 0; transition: opacity 0.2s ease;
396
+ pointer-events: none;
397
+ }
398
+ .toast.is-visible { opacity: 1; pointer-events: auto; }
399
+
400
+ /* ── new-session form ────────────────────────────────────────────────────── */
401
+ .new-session-form {
402
+ display: flex; flex-direction: column; gap: 6px;
403
+ padding: 10px 14px 12px; border-bottom: 1px solid var(--border);
404
+ background: var(--bg-raised);
405
+ }
406
+ .nsf-select, .nsf-input {
407
+ width: 100%; padding: 5px 8px;
408
+ background: var(--bg-sunken); border: 1px solid var(--border);
409
+ border-radius: 6px; color: var(--text); font: inherit; font-size: 12px;
410
+ }
411
+ .nsf-select:focus, .nsf-input:focus { outline: none; border-color: var(--accent); }
412
+ .nsf-btn {
413
+ align-self: flex-start; padding: 4px 14px;
414
+ background: var(--accent); color: #1a0d05;
415
+ border: none; border-radius: 6px; font: inherit; font-size: 12px;
416
+ font-weight: 600; cursor: pointer;
417
+ }
418
+ .nsf-btn:hover { opacity: 0.88; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-afk",
3
- "version": "5.161.0",
3
+ "version": "5.162.1",
4
4
  "description": "Open-source coding-agent harness you can actually change — own the loop (prompts, gates, routing, skills, terminal states), use any model, run long tasks while you're away.",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",