agent-afk 5.108.0 → 5.108.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,64 +1,64 @@
1
- var ut="__AFK_WEB_TOKEN__",Ee="afk_web_token",Ae="";function Le(){let t=new URLSearchParams(location.search);(t.get("token")||t.get("k"))&&history.replaceState(null,"",location.pathname);let e=dt();return e?(ht(e),e):gt()}function dt(){let t=document.querySelector('meta[name="afk-token"]')?.getAttribute("content");return!t||t===ut?"":t}function ht(t){Ae=t;try{sessionStorage.setItem(Ee,t)}catch{}}function gt(){try{let t=sessionStorage.getItem(Ee);if(t)return t}catch{}return Ae}var $n=Object.freeze({end:!0,reason:"session_closed"});function Pe(t){return typeof t=="object"&&t!==null&&t.end===!0}function Ie(t){let n=t.replace(/\r\n/g,`
1
+ var St="__AFK_WEB_TOKEN__",Ie="afk_web_token",Pe="";function Me(){let t=new URLSearchParams(location.search);(t.get("token")||t.get("k"))&&history.replaceState(null,"",location.pathname);let e=Ct();return e?(Et(e),e):Rt()}function Ct(){let t=document.querySelector('meta[name="afk-token"]')?.getAttribute("content");return!t||t===St?"":t}function Et(t){Pe=t;try{sessionStorage.setItem(Ie,t)}catch{}}function Rt(){try{let t=sessionStorage.getItem(Ie);if(t)return t}catch{}return Pe}var Gn=Object.freeze({end:!0,reason:"session_closed"});function _e(t){return typeof t=="object"&&t!==null&&t.end===!0}function ze(t){let n=t.replace(/\r\n/g,`
2
2
  `).split(`
3
3
 
4
- `),s=n.pop()??"",r=[];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&&r.push({id:o,data:l})}return{events:r,remainder:s}}var ft=15e3,kt=500,U=class{constructor(e,n,s){this.sessionId=e;this.token=n;this.handlers=s}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 r=await fetch(`/api/sessions/${encodeURIComponent(this.sessionId)}/stream`,{headers:n,signal:this.controller.signal});if(!r.ok||r.body===null)throw new Error(`stream failed: ${r.status}`);this.attempt=0,this.handlers.onStatus?.("open");let i=r.body.getReader(),o=new TextDecoder,l="";e:for(;;){let{done:a,value:p}=await i.read();if(a)break;l+=o.decode(p,{stream:!0});let{events:c,remainder:h}=Ie(l);l=h;for(let d of c){if(d.id!==void 0&&(this.lastEventId=d.id),d.data===void 0)continue;let x;try{x=JSON.parse(d.data)}catch{continue}if(Pe(x)){e=!0,this.stopped=!0;break e}this.handlers.onEvent(x,{id:d.id})}}}catch{}if(this.stopped){e&&this.handlers.onStatus?.("ended");return}this.attempt+=1;let s=Math.min(kt*2**(this.attempt-1),ft);setTimeout(()=>{this.connect()},s)}};var mt=/\x1B\][^\x07\x1B]*(?:\x07|\x1B\\)|\x1B[P^_X][^\x1B]*\x1B\\|\x1B\[[0-?]*[ -/]*[@-~]|\x9B[0-?]*[ -/]*[@-~]|\x1B[@-_]/g;function _e(t){return t.replace(mt,"")}function j(t){return _e(t)}function ie(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var P=ie();function De(t){P=t}var A={exec:()=>null};function g(t,e=""){let n=typeof t=="string"?t:t.source,s={replace:(r,i)=>{let o=typeof i=="string"?i:i.source;return o=o.replace(w.caret,"$1"),n=n.replace(r,o),s},getRegex:()=>new RegExp(n,e)};return s}var xt=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),w={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)}}>`)},bt=/^(?:[ \t]*(?:\n|$))+/,wt=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,yt=/^ {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+|$)/,oe=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Oe=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Fe=g(Oe).replace(/bull/g,oe).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(),Tt=g(Oe).replace(/bull/g,oe).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(),ae=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,St=/^[^\n]+/,le=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Ct=g(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",le).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Rt=g(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,oe).getRegex(),G="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",ce=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,$t=g("^ {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",ce).replace("tag",G).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ue=g(ae).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",G).getRegex(),Et=g(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ue).getRegex(),pe={blockquote:Et,code:wt,def:Ct,fences:yt,heading:vt,hr:F,html:$t,lheading:Fe,list:Rt,newline:bt,paragraph:Ue,table:A,text:St},ze=g("^ *([^\\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",G).getRegex(),At={...pe,lheading:Tt,table:ze,paragraph:g(ae).replace("hr",F).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",ze).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",G).getRegex()},Lt={...pe,html:g(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ce).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:A,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:g(ae).replace("hr",F).replace("heading",` *#{1,6} *[^
6
- ]`).replace("lheading",Fe).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Pt=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,It=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,je=/^( {2,}|\\)\n(?!\s*$)/,_t=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,z=/[\p{P}\p{S}]/u,X=/[\s\p{P}\p{S}]/u,ue=/[^\s\p{P}\p{S}]/u,zt=g(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,X).getRegex(),Ze=/(?!~)[\p{P}\p{S}]/u,Mt=/(?!~)[\s\p{P}\p{S}]/u,qt=/(?:[^\s\p{P}\p{S}]|~)/u,Bt=g(/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(),Qe=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Ht=g(Qe,"u").replace(/punct/g,z).getRegex(),Nt=g(Qe,"u").replace(/punct/g,Ze).getRegex(),Ke="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Dt=g(Ke,"gu").replace(/notPunctSpace/g,ue).replace(/punctSpace/g,X).replace(/punct/g,z).getRegex(),Ot=g(Ke,"gu").replace(/notPunctSpace/g,qt).replace(/punctSpace/g,Mt).replace(/punct/g,Ze).getRegex(),Ft=g("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,ue).replace(/punctSpace/g,X).replace(/punct/g,z).getRegex(),Ut=g(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,z).getRegex(),jt="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Zt=g(jt,"gu").replace(/notPunctSpace/g,ue).replace(/punctSpace/g,X).replace(/punct/g,z).getRegex(),Qt=g(/\\(punct)/,"gu").replace(/punct/g,z).getRegex(),Kt=g(/^<(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(),Wt=g(ce).replace("(?:-->|$)","-->").getRegex(),Gt=g("^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",Wt).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Q=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Xt=g(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Q).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),We=g(/^!?\[(label)\]\[(ref)\]/).replace("label",Q).replace("ref",le).getRegex(),Ge=g(/^!?\[(ref)\](?:\[\])?/).replace("ref",le).getRegex(),Jt=g("reflink|nolink(?!\\()","g").replace("reflink",We).replace("nolink",Ge).getRegex(),Me=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,de={_backpedal:A,anyPunctuation:Qt,autolink:Kt,blockSkip:Bt,br:je,code:It,del:A,delLDelim:A,delRDelim:A,emStrongLDelim:Ht,emStrongRDelimAst:Dt,emStrongRDelimUnd:Ft,escape:Pt,link:Xt,nolink:Ge,punctuation:zt,reflink:We,reflinkSearch:Jt,tag:Gt,text:_t,url:A},Vt={...de,link:g(/^!?\[(label)\]\((.*?)\)/).replace("label",Q).getRegex(),reflink:g(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Q).getRegex()},ne={...de,emStrongRDelimAst:Ot,emStrongLDelim:Nt,delLDelim:Ut,delRDelim:Zt,url:g(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Me).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:g(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Me).getRegex()},Yt={...ne,br:g(je).replace("{2,}","*").getRegex(),text:g(ne.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Z={normal:pe,gfm:At,pedantic:Lt},N={normal:de,gfm:ne,breaks:Yt,pedantic:Vt},en={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},qe=t=>en[t];function S(t,e){if(e){if(w.escapeTest.test(t))return t.replace(w.escapeReplace,qe)}else if(w.escapeTestNoEncode.test(t))return t.replace(w.escapeReplaceNoEncode,qe);return t}function Be(t){try{t=encodeURI(t).replace(w.percentDecode,"%")}catch{return null}return t}function He(t,e){let n=t.replace(w.findPipe,(i,o,l)=>{let a=!1,p=o;for(;--p>=0&&l[p]==="\\";)a=!a;return a?"|":" |"}),s=n.split(w.splitPipe),r=0;if(s[0].trim()||s.shift(),s.length>0&&!s.at(-1)?.trim()&&s.pop(),e)if(s.length>e)s.splice(e);else for(;s.length<e;)s.push("");for(;r<s.length;r++)s[r]=s[r].trim().replace(w.slashPipe,"|");return s}function D(t,e,n){let s=t.length;if(s===0)return"";let r=0;for(;r<s;){let i=t.charAt(s-r-1);if(i===e&&!n)r++;else if(i!==e&&n)r++;else break}return t.slice(0,s-r)}function tn(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let s=0;s<t.length;s++)if(t[s]==="\\")s++;else if(t[s]===e[0])n++;else if(t[s]===e[1]&&(n--,n<0))return s;return n>0?-2:-1}function nn(t,e=0){let n=e,s="";for(let r of t)if(r===" "){let i=4-n%4;s+=" ".repeat(i),n+=i}else s+=r,n++;return s}function Ne(t,e,n,s,r){let i=e.href,o=e.title||null,l=t[1].replace(r.other.outputLinkReplace,"$1");s.state.inLink=!0;let a={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:o,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,a}function rn(t,e,n){let s=t.match(n.other.indentCodeCompensation);if(s===null)return e;let r=s[1];return e.split(`
7
- `).map(i=>{let o=i.match(n.other.beginningSpace);if(o===null)return i;let[l]=o;return l.length>=r.length?i.slice(r.length):i}).join(`
8
- `)}var K=class{options;rules;lexer;constructor(t){this.options=t||P}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:D(n,`
9
- `)}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],s=rn(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:s}}}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 s=D(n,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(n=s.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:D(e[0],`
4
+ `),r=n.pop()??"",s=[];for(let i of n){if(i.trim()==="")continue;let o,c;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: ")?c=a.slice(6):a.startsWith("data:")&&(c=a.slice(5).trimStart());c!==void 0&&s.push({id:o,data:c})}return{events:s,remainder:r}}var At=15e3,Lt=500,j=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 s=await fetch(`/api/sessions/${encodeURIComponent(this.sessionId)}/stream`,{headers:n,signal:this.controller.signal});if(!s.ok||s.body===null)throw new Error(`stream failed: ${s.status}`);this.attempt=0,this.handlers.onStatus?.("open");let i=s.body.getReader(),o=new TextDecoder,c="";e:for(;;){let{done:a,value:p}=await i.read();if(a)break;c+=o.decode(p,{stream:!0});let{events:l,remainder:u}=ze(c);c=u;for(let h of l){if(h.id!==void 0&&(this.lastEventId=h.id),h.data===void 0)continue;let x;try{x=JSON.parse(h.data)}catch{continue}if(_e(x)){e=!0,this.stopped=!0;break e}this.handlers.onEvent(x,{id:h.id})}}}catch{}if(this.stopped){e&&this.handlers.onStatus?.("ended");return}this.attempt+=1;let r=Math.min(Lt*2**(this.attempt-1),At);setTimeout(()=>{this.connect()},r)}};var He=/(?:^|\s)(\/[A-Za-z][A-Za-z0-9_:-]*)/g,$t=Number.POSITIVE_INFINITY;function Be(t){let e=new Map;for(let n=0;n<t.length;n++){let r=t[n];if(!r)continue;He.lastIndex=0;let s;for(;(s=He.exec(r))!==null;){let i=s[1]?.toLowerCase();i!==void 0&&!e.has(i)&&e.set(i,n)}}return e}function qe(t,e){let n=t.startsWith("/")?t.toLowerCase():`/${t.toLowerCase()}`;return e.get(n)??$t}function Ne(t,e,n){let r=qe(t,n),s=qe(e,n);return r!==s?r-s:t.localeCompare(e)}var It=20;function Pt(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 De(t,e,n=[]){let r=e.toLowerCase(),s=t.map(l=>({key:l.name.replace(/^\//,"").toLowerCase(),cand:{value:l.name,...l.summary!==void 0?{summary:l.summary}:{},...l.hint!==void 0?{hint:l.hint}:{}}})),i=s.filter(l=>l.key.startsWith(r)),o=new Set(i.map(l=>l.cand.value)),c=r.length===0?[]:s.filter(l=>!o.has(l.cand.value)&&Pt(r,l.key)),a=Be(n),p=(l,u)=>Ne(l.cand.value,u.cand.value,a);return i.sort(p),c.sort(p),[...i,...c].map(l=>l.cand).slice(0,It)}function U(t){t.dispatchEvent(new Event("input"))}var Oe=new Set(["/clear","/compact","/editor","/exit","/fast","/font-size","/fork","/keys","/model","/reauth","/resume","/rewind","/sh","/theme","/thinking"]);function Fe(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),Oe.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 je=/^\/(?:[A-Za-z][\w:-]*)?$/,Z=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(),U(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(!je.test(e)){this.close(!0);return}this.openIntent=!0;let n=++this.generation;if(await this.ensureCommands(),n!==this.generation||!this.openIntent||!this.focused||!je.test(this.deps.input.value)){n===this.generation&&this.close();return}let r=this.deps.input.value.slice(1);this.candidates=De(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 Fe(e,this.optionId(n),r,s=>{this.selected=this.candidates.indexOf(s),this.accept()})}};var Mt=/^\/[A-Za-z][\w:-]*$/;function _t(t,e){return t===""?[]:t.split(/(\s+)/).filter(n=>n!=="").map(n=>Mt.test(n)?{text:n,kind:e(n)?"known":"slash"}:{text:n,kind:"plain"})}function zt(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 re(t,e,n){zt(e,_t(t.value,n)),e.scrollTop=t.scrollTop,e.scrollLeft=t.scrollLeft}function Ue(t,e,n){let r=()=>{re(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 Ht="slash-menu",qt="prompt-mirror";function Ze(t){let e=document.getElementById(Ht),n=document.getElementById(qt);if(!e||!n)return;let r;return r=new Z({input:t.input,menu:e,loadCommands:t.loadCommands,onCommandsLoaded:()=>re(t.input,n,s=>r.knows(s))}),r.wire(),Ue(t.input,n,s=>r.knows(s)),t.input.classList.add("slash-highlight-active"),r.preload(),r}var Bt=/\x1B\][^\x07\x1B]*(?:\x07|\x1B\\)|\x1B[P^_X][^\x1B]*\x1B\\|\x1B\[[0-?]*[ -/]*[@-~]|\x9B[0-?]*[ -/]*[@-~]|\x1B[@-_]/g;function Ke(t){return t.replace(Bt,"")}function K(t){return Ke(t)}function le(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var I=le();function Ye(t){I=t}var L={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(w.caret,"$1"),n=n.replace(s,o),r},getRegex:()=>new RegExp(n,e)};return r}var Nt=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),w={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)}}>`)},Dt=/^(?:[ \t]*(?:\n|$))+/,Ot=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ft=/^ {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+|$)/,jt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ce=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,et=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,tt=f(et).replace(/bull/g,ce).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(),Ut=f(et).replace(/bull/g,ce).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(),pe=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Zt=/^[^\n]+/,de=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Kt=f(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",de).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Qt=f(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ce).getRegex(),V="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",ue=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Gt=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",ue).replace("tag",V).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),nt=f(pe).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",V).getRegex(),Wt=f(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",nt).getRegex(),he={blockquote:Wt,code:Ot,def:Kt,fences:Ft,heading:jt,hr:F,html:Gt,lheading:tt,list:Qt,newline:Dt,paragraph:nt,table:L,text:Zt},Qe=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",V).getRegex(),Xt={...he,lheading:Ut,table:Qe,paragraph:f(pe).replace("hr",F).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Qe).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",V).getRegex()},Vt={...he,html:f(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ue).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:L,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:f(pe).replace("hr",F).replace("heading",` *#{1,6} *[^
6
+ ]`).replace("lheading",tt).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Jt=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Yt=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,st=/^( {2,}|\\)\n(?!\s*$)/,en=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,z=/[\p{P}\p{S}]/u,J=/[\s\p{P}\p{S}]/u,fe=/[^\s\p{P}\p{S}]/u,tn=f(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,J).getRegex(),rt=/(?!~)[\p{P}\p{S}]/u,nn=/(?!~)[\s\p{P}\p{S}]/u,sn=/(?:[^\s\p{P}\p{S}]|~)/u,rn=f(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Nt?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),it=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,on=f(it,"u").replace(/punct/g,z).getRegex(),an=f(it,"u").replace(/punct/g,rt).getRegex(),ot="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",ln=f(ot,"gu").replace(/notPunctSpace/g,fe).replace(/punctSpace/g,J).replace(/punct/g,z).getRegex(),cn=f(ot,"gu").replace(/notPunctSpace/g,sn).replace(/punctSpace/g,nn).replace(/punct/g,rt).getRegex(),pn=f("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,fe).replace(/punctSpace/g,J).replace(/punct/g,z).getRegex(),dn=f(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,z).getRegex(),un="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",hn=f(un,"gu").replace(/notPunctSpace/g,fe).replace(/punctSpace/g,J).replace(/punct/g,z).getRegex(),fn=f(/\\(punct)/,"gu").replace(/punct/g,z).getRegex(),gn=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(),mn=f(ue).replace("(?:-->|$)","-->").getRegex(),kn=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",mn).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),G=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,xn=f(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",G).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),at=f(/^!?\[(label)\]\[(ref)\]/).replace("label",G).replace("ref",de).getRegex(),lt=f(/^!?\[(ref)\](?:\[\])?/).replace("ref",de).getRegex(),bn=f("reflink|nolink(?!\\()","g").replace("reflink",at).replace("nolink",lt).getRegex(),Ge=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,ge={_backpedal:L,anyPunctuation:fn,autolink:gn,blockSkip:rn,br:st,code:Yt,del:L,delLDelim:L,delRDelim:L,emStrongLDelim:on,emStrongRDelimAst:ln,emStrongRDelimUnd:pn,escape:Jt,link:xn,nolink:lt,punctuation:tn,reflink:at,reflinkSearch:bn,tag:kn,text:en,url:L},wn={...ge,link:f(/^!?\[(label)\]\((.*?)\)/).replace("label",G).getRegex(),reflink:f(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",G).getRegex()},ie={...ge,emStrongRDelimAst:cn,emStrongLDelim:an,delLDelim:dn,delRDelim:hn,url:f(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Ge).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",Ge).getRegex()},yn={...ie,br:f(st).replace("{2,}","*").getRegex(),text:f(ie.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Q={normal:he,gfm:Xt,pedantic:Vt},N={normal:ge,gfm:ie,breaks:yn,pedantic:wn},vn={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},We=t=>vn[t];function S(t,e){if(e){if(w.escapeTest.test(t))return t.replace(w.escapeReplace,We)}else if(w.escapeTestNoEncode.test(t))return t.replace(w.escapeReplaceNoEncode,We);return t}function Xe(t){try{t=encodeURI(t).replace(w.percentDecode,"%")}catch{return null}return t}function Ve(t,e){let n=t.replace(w.findPipe,(i,o,c)=>{let a=!1,p=o;for(;--p>=0&&c[p]==="\\";)a=!a;return a?"|":" |"}),r=n.split(w.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(w.slashPipe,"|");return r}function D(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 Tn(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 Sn(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 Je(t,e,n,r,s){let i=e.href,o=e.title||null,c=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:c,tokens:r.inlineTokens(c)};return r.state.inLink=!1,a}function Cn(t,e,n){let r=t.match(n.other.indentCodeCompensation);if(r===null)return e;let s=r[1];return e.split(`
7
+ `).map(i=>{let o=i.match(n.other.beginningSpace);if(o===null)return i;let[c]=o;return c.length>=s.length?i.slice(s.length):i}).join(`
8
+ `)}var W=class{options;rules;lexer;constructor(t){this.options=t||I}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:D(n,`
9
+ `)}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],r=Cn(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=D(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:D(e[0],`
10
10
  `)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=D(e[0],`
11
11
  `).split(`
12
- `),s="",r="",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
- `),c=p.replace(this.rules.other.blockquoteSetextReplace,`
14
- $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
15
- ${p}`:p,r=r?`${r}
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 d=i.at(-1);if(d?.type==="code")break;if(d?.type==="blockquote"){let x=d,b=x.raw+`
12
+ `),r="",s="",i=[];for(;n.length>0;){let o=!1,c=[],a;for(a=0;a<n.length;a++)if(this.rules.other.blockquoteStart.test(n[a]))c.push(n[a]),o=!0;else if(!o)c.push(n[a]);else break;n=n.slice(a);let p=c.join(`
13
+ `),l=p.replace(this.rules.other.blockquoteSetextReplace,`
14
+ $1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
15
+ ${p}`:p,s=s?`${s}
16
+ ${l}`:l;let u=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,i,!0),this.lexer.state.top=u,n.length===0)break;let h=i.at(-1);if(h?.type==="code")break;if(h?.type==="blockquote"){let x=h,b=x.raw+`
17
17
  `+n.join(`
18
- `),C=this.blockquote(b);i[i.length-1]=C,s=s.substring(0,s.length-x.raw.length)+C.raw,r=r.substring(0,r.length-x.text.length)+C.text;break}else if(d?.type==="list"){let x=d,b=x.raw+`
18
+ `),C=this.blockquote(b);i[i.length-1]=C,r=r.substring(0,r.length-x.raw.length)+C.raw,s=s.substring(0,s.length-x.text.length)+C.text;break}else if(h?.type==="list"){let x=h,b=x.raw+`
19
19
  `+n.join(`
20
- `),C=this.list(b);i[i.length-1]=C,s=s.substring(0,s.length-d.raw.length)+C.raw,r=r.substring(0,r.length-x.raw.length)+C.raw,n=b.substring(i.at(-1).raw.length).split(`
21
- `);continue}}return{type:"blockquote",raw:s,tokens:i,text:r}}}list(t){let e=this.rules.block.list.exec(t);if(e){let n=e[1].trim(),s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?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=nn(e[2].split(`
22
- `,1)[0],e[1].length),d=t.split(`
23
- `,1)[0],x=!h.trim(),b=0;if(this.options.pedantic?(b=2,c=h.trimStart()):x?b=e[1].length+1:(b=h.search(this.rules.other.nonSpaceChar),b=b>4?1:b,c=h.slice(b),b+=e[1].length),x&&this.rules.other.blankLine.test(d)&&(p+=d+`
24
- `,t=t.substring(d.length+1),a=!0),!a){let C=this.rules.other.nextBulletRegex(b),Ce=this.rules.other.hrRegex(b),Re=this.rules.other.fencesBeginRegex(b),$e=this.rules.other.headingBeginRegex(b),ct=this.rules.other.htmlBeginRegex(b),pt=this.rules.other.blockquoteBeginRegex(b);for(;t;){let te=t.split(`
25
- `,1)[0],H;if(d=te,this.options.pedantic?(d=d.replace(this.rules.other.listReplaceNesting," "),H=d):H=d.replace(this.rules.other.tabCharGlobal," "),Re.test(d)||$e.test(d)||ct.test(d)||pt.test(d)||C.test(d)||Ce.test(d))break;if(H.search(this.rules.other.nonSpaceChar)>=b||!d.trim())c+=`
26
- `+H.slice(b);else{if(x||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||Re.test(h)||$e.test(h)||Ce.test(h))break;c+=`
27
- `+d}x=!d.trim(),p+=te+`
28
- `,t=t.substring(te.length+1),h=H.slice(b)}}r.loose||(o?r.loose=!0:this.rules.other.doubleBlankLine.test(p)&&(o=!0)),r.items.push({type:"list_item",raw:p,task:!!this.options.gfm&&this.rules.other.listIsTask.test(c),loose:!1,text:c,tokens:[]}),r.raw+=p}let l=r.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;r.raw=r.raw.trimEnd();for(let a of r.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,r.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(!r.loose){let p=a.tokens.filter(h=>h.type==="space"),c=p.length>0&&p.some(h=>this.rules.other.anyLine.test(h.raw));r.loose=c}}if(r.loose)for(let a of r.items){a.loose=!0;for(let p of a.tokens)p.type==="text"&&(p.type="paragraph")}return r}}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," "),s=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=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:s,title:r}}}table(t){let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let n=He(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),r=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
29
- `):[],i={type:"table",raw:e[0],header:[],align:[],rows:[]};if(n.length===s.length){for(let o of s)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 r)i.rows.push(He(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=D(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=tn(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 s=e[2],r="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(s);i&&(s=i[1],r=i[3])}else r=e[3]?e[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?s=s.slice(1):s=s.slice(1,-1)),Ne(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.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 s=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),r=e[s.toLowerCase()];if(!r){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return Ne(n,r,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let s=this.rules.inline.emStrongLDelim.exec(t);if(!(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[3])||!n||this.rules.inline.punctuation.exec(n))){let r=[...s[0]].length-1,i,o,l=r,a=0,p=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(p.lastIndex=0,e=e.slice(-1*t.length+r);(s=p.exec(e))!=null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i)continue;if(o=[...i].length,s[3]||s[4]){l+=o;continue}else if((s[5]||s[6])&&r%3&&!((r+o)%3)){a+=o;continue}if(l-=o,l>0)continue;o=Math.min(o,o+l+a);let c=[...s[0]][0].length,h=t.slice(0,r+s.index+c+o);if(Math.min(r,o)%2){let x=h.slice(1,-1);return{type:"em",raw:h,text:x,tokens:this.lexer.inlineTokens(x)}}let d=h.slice(2,-2);return{type:"strong",raw:h,text:d,tokens:this.lexer.inlineTokens(d)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(n),r=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return s&&r&&(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 s=this.rules.inline.delLDelim.exec(t);if(s&&(!s[1]||!n||this.rules.inline.punctuation.exec(n))){let r=[...s[0]].length-1,i,o,l=r,a=this.rules.inline.delRDelim;for(a.lastIndex=0,e=e.slice(-1*t.length+r);(s=a.exec(e))!=null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i||(o=[...i].length,o!==r))continue;if(s[3]||s[4]){l+=o;continue}if(l-=o,l>0)continue;o=Math.min(o,o+l);let p=[...s[0]][0].length,c=t.slice(0,r+s.index+p+o),h=c.slice(r,-r);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,s;return e[2]==="@"?(n=e[1],s="mailto:"+n):(n=e[1],s=n),{type:"link",raw:e[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,s;if(e[2]==="@")n=e[0],s="mailto:"+n;else{let r;do r=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(r!==e[0]);n=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:n,href:s,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}}}},y=class re{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||P,this.options.tokenizer=this.options.tokenizer||new K,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:w,block:Z.normal,inline:N.normal};this.options.pedantic?(n.block=Z.pedantic,n.inline=N.pedantic):this.options.gfm&&(n.block=Z.gfm,this.options.breaks?n.inline=N.breaks:n.inline=N.gfm),this.tokenizer.rules=n}static get rules(){return{block:Z,inline:N}}static lex(e,n){return new re(n).lex(e)}static lexInline(e,n){return new re(n).inlineTokens(e)}lex(e){e=e.replace(w.carriageReturn,`
31
- `),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let s=this.inlineQueue[n];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],s=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(w.tabCharGlobal," ").replace(w.spaceLine,""));e;){let r;if(this.options.extensions?.block?.some(o=>(r=o.call({lexer:this},e,n))?(e=e.substring(r.raw.length),n.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let o=n.at(-1);r.raw.length===1&&o!==void 0?o.raw+=`
32
- `:n.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
20
+ `),C=this.list(b);i[i.length-1]=C,r=r.substring(0,r.length-h.raw.length)+C.raw,s=s.substring(0,s.length-x.raw.length)+C.raw,n=b.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="",l="";if(!(e=i.exec(t))||this.rules.block.hr.test(t))break;p=e[0],t=t.substring(p.length);let u=Sn(e[2].split(`
22
+ `,1)[0],e[1].length),h=t.split(`
23
+ `,1)[0],x=!u.trim(),b=0;if(this.options.pedantic?(b=2,l=u.trimStart()):x?b=e[1].length+1:(b=u.search(this.rules.other.nonSpaceChar),b=b>4?1:b,l=u.slice(b),b+=e[1].length),x&&this.rules.other.blankLine.test(h)&&(p+=h+`
24
+ `,t=t.substring(h.length+1),a=!0),!a){let C=this.rules.other.nextBulletRegex(b),Ae=this.rules.other.hrRegex(b),Le=this.rules.other.fencesBeginRegex(b),$e=this.rules.other.headingBeginRegex(b),vt=this.rules.other.htmlBeginRegex(b),Tt=this.rules.other.blockquoteBeginRegex(b);for(;t;){let se=t.split(`
25
+ `,1)[0],B;if(h=se,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),B=h):B=h.replace(this.rules.other.tabCharGlobal," "),Le.test(h)||$e.test(h)||vt.test(h)||Tt.test(h)||C.test(h)||Ae.test(h))break;if(B.search(this.rules.other.nonSpaceChar)>=b||!h.trim())l+=`
26
+ `+B.slice(b);else{if(x||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||Le.test(u)||$e.test(u)||Ae.test(u))break;l+=`
27
+ `+h}x=!h.trim(),p+=se+`
28
+ `,t=t.substring(se.length+1),u=B.slice(b)}}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(l),loose:!1,text:l,tokens:[]}),s.raw+=p}let c=s.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.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 l=this.lexer.inlineQueue.length-1;l>=0;l--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[l].src)){this.lexer.inlineQueue[l].src=this.lexer.inlineQueue[l].src.replace(this.rules.other.listReplaceTask,"");break}}let p=this.rules.other.listTaskCheckbox.exec(a.raw);if(p){let l={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};a.checked=l.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=l.raw+a.tokens[0].raw,a.tokens[0].text=l.raw+a.tokens[0].text,a.tokens[0].tokens.unshift(l)):a.tokens.unshift({type:"paragraph",raw:l.raw,text:l.raw,tokens:[l]}):a.tokens.unshift(l)}}if(!s.loose){let p=a.tokens.filter(u=>u.type==="space"),l=p.length>0&&p.some(u=>this.rules.other.anyLine.test(u.raw));s.loose=l}}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=Ve(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(Ve(o,i.header.length).map((c,a)=>({text:c,tokens:this.lexer.inline(c),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=D(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=Tn(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)),Je(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 Je(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,c=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]){c+=o;continue}else if((r[5]||r[6])&&s%3&&!((s+o)%3)){a+=o;continue}if(c-=o,c>0)continue;o=Math.min(o,o+c+a);let l=[...r[0]][0].length,u=t.slice(0,s+r.index+l+o);if(Math.min(s,o)%2){let x=u.slice(1,-1);return{type:"em",raw:u,text:x,tokens:this.lexer.inlineTokens(x)}}let h=u.slice(2,-2);return{type:"strong",raw:u,text:h,tokens:this.lexer.inlineTokens(h)}}}}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,c=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]){c+=o;continue}if(c-=o,c>0)continue;o=Math.min(o,o+c);let p=[...r[0]][0].length,l=t.slice(0,s+r.index+p+o),u=l.slice(s,-s);return{type:"del",raw:l,text:u,tokens:this.lexer.inlineTokens(u)}}}}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}}}},y=class oe{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||I,this.options.tokenizer=this.options.tokenizer||new W,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:w,block:Q.normal,inline:N.normal};this.options.pedantic?(n.block=Q.pedantic,n.inline=N.pedantic):this.options.gfm&&(n.block=Q.gfm,this.options.breaks?n.inline=N.breaks:n.inline=N.gfm),this.tokenizer.rules=n}static get rules(){return{block:Q,inline:N}}static lex(e,n){return new oe(n).lex(e)}static lexInline(e,n){return new oe(n).inlineTokens(e)}lex(e){e=e.replace(w.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(w.tabCharGlobal," ").replace(w.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
+ `: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
- `)+r.raw,o.text+=`
35
- `+r.text,this.inlineQueue.at(-1).src=o.text):n.push(r);continue}if(r=this.tokenizer.fences(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.heading(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.hr(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.blockquote(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.list(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.html(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
34
+ `)+s.raw,o.text+=`
35
+ `+s.text,this.inlineQueue.at(-1).src=o.text):n.push(s);continue}if(s=this.tokenizer.fences(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.heading(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.hr(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.blockquote(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.list(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.html(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.def(e)){e=e.substring(s.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
36
36
  `)?"":`
37
- `)+r.raw,o.text+=`
38
- `+r.raw,this.inlineQueue.at(-1).src=o.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},n.push(r));continue}if(r=this.tokenizer.table(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.lheading(e)){e=e.substring(r.raw.length),n.push(r);continue}let i=e;if(this.options.extensions?.startBlock){let o=1/0,l=e.slice(1),a;this.options.extensions.startBlock.forEach(p=>{a=p.call({lexer:this},l),typeof a=="number"&&a>=0&&(o=Math.min(o,a))}),o<1/0&&o>=0&&(i=e.substring(0,o+1))}if(this.state.top&&(r=this.tokenizer.paragraph(i))){let o=n.at(-1);s&&o?.type==="paragraph"?(o.raw+=(o.raw.endsWith(`
37
+ `)+s.raw,o.text+=`
38
+ `+s.raw,this.inlineQueue.at(-1).src=o.text):this.tokens.links[s.tag]||(this.tokens.links[s.tag]={href:s.href,title:s.title},n.push(s));continue}if(s=this.tokenizer.table(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.lheading(e)){e=e.substring(s.raw.length),n.push(s);continue}let i=e;if(this.options.extensions?.startBlock){let o=1/0,c=e.slice(1),a;this.options.extensions.startBlock.forEach(p=>{a=p.call({lexer:this},c),typeof a=="number"&&a>=0&&(o=Math.min(o,a))}),o<1/0&&o>=0&&(i=e.substring(0,o+1))}if(this.state.top&&(s=this.tokenizer.paragraph(i))){let o=n.at(-1);r&&o?.type==="paragraph"?(o.raw+=(o.raw.endsWith(`
39
39
  `)?"":`
40
- `)+r.raw,o.text+=`
41
- `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(r),s=i.length!==e.length,e=e.substring(r.raw.length);continue}if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let o=n.at(-1);o?.type==="text"?(o.raw+=(o.raw.endsWith(`
40
+ `)+s.raw,o.text+=`
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
- `)+r.raw,o.text+=`
44
- `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(r);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 s=e,r=null;if(this.tokens.links){let a=Object.keys(this.tokens.links);if(a.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)a.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,r.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(r=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)i=r[2]?r[2].length:0,s=s.slice(0,r.index+i)+"["+"a".repeat(r[0].length-i-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;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,s,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,s,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),d;this.options.extensions.startInline.forEach(x=>{d=x.call({lexer:this},h),typeof d=="number"&&d>=0&&(c=Math.min(c,d))}),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}},W=class{options;parser;constructor(t){this.options=t||P}space(t){return""}code({text:t,lang:e,escaped:n}){let s=(e||"").match(w.notSpaceStart)?.[0],r=t.replace(w.endingNewline,"")+`
45
- `;return s?'<pre><code class="language-'+S(s)+'">'+(n?r:S(r,!0))+`</code></pre>
46
- `:"<pre><code>"+(n?r:S(r,!0))+`</code></pre>
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,c="";for(;e;){o||(c=""),o=!1;let a;if(this.options.extensions?.inline?.some(l=>(a=l.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 l=n.at(-1);a.type==="text"&&l?.type==="text"?(l.raw+=a.raw,l.text+=a.text):n.push(a);continue}if(a=this.tokenizer.emStrong(e,r,c)){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,c)){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 l=1/0,u=e.slice(1),h;this.options.extensions.startInline.forEach(x=>{h=x.call({lexer:this},u),typeof h=="number"&&h>=0&&(l=Math.min(l,h))}),l<1/0&&l>=0&&(p=e.substring(0,l+1))}if(a=this.tokenizer.inlineText(p)){e=e.substring(a.raw.length),a.raw.slice(-1)!=="_"&&(c=a.raw.slice(-1)),o=!0;let l=n.at(-1);l?.type==="text"?(l.raw+=a.raw,l.text+=a.text):n.push(a);continue}if(e){let l="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(l);break}else throw new Error(l)}}return n}},X=class{options;parser;constructor(t){this.options=t||I}space(t){return""}code({text:t,lang:e,escaped:n}){let r=(e||"").match(w.notSpaceStart)?.[0],s=t.replace(w.endingNewline,"")+`
45
+ `;return r?'<pre><code class="language-'+S(r)+'">'+(n?s:S(s,!0))+`</code></pre>
46
+ `:"<pre><code>"+(n?s:S(s,!0))+`</code></pre>
47
47
  `}blockquote({tokens:t}){return`<blockquote>
48
48
  ${this.parser.parse(t)}</blockquote>
49
49
  `}html({text:t}){return t}def(t){return""}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
50
50
  `}hr(t){return`<hr>
51
- `}list(t){let e=t.ordered,n=t.start,s="";for(let o=0;o<t.items.length;o++){let l=t.items[o];s+=this.listitem(l)}let r=e?"ol":"ul",i=e&&n!==1?' start="'+n+'"':"";return"<"+r+i+`>
52
- `+s+"</"+r+`>
51
+ `}list(t){let e=t.ordered,n=t.start,r="";for(let o=0;o<t.items.length;o++){let c=t.items[o];r+=this.listitem(c)}let s=e?"ol":"ul",i=e&&n!==1?' start="'+n+'"':"";return"<"+s+i+`>
52
+ `+r+"</"+s+`>
53
53
  `}listitem(t){return`<li>${this.parser.parse(t.tokens)}</li>
54
54
  `}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
55
- `}table(t){let e="",n="";for(let r=0;r<t.header.length;r++)n+=this.tablecell(t.header[r]);e+=this.tablerow({text:n});let s="";for(let r=0;r<t.rows.length;r++){let i=t.rows[r];n="";for(let o=0;o<i.length;o++)n+=this.tablecell(i[o]);s+=this.tablerow({text:n})}return s&&(s=`<tbody>${s}</tbody>`),`<table>
55
+ `}table(t){let e="",n="";for(let s=0;s<t.header.length;s++)n+=this.tablecell(t.header[s]);e+=this.tablerow({text:n});let r="";for(let s=0;s<t.rows.length;s++){let i=t.rows[s];n="";for(let o=0;o<i.length;o++)n+=this.tablecell(i[o]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
56
56
  <thead>
57
57
  `+e+`</thead>
58
- `+s+`</table>
58
+ `+r+`</table>
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>${S(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 s=this.parser.parseInline(n),r=Be(t);if(r===null)return s;t=r;let i='<a href="'+t+'"';return e&&(i+=' title="'+S(e)+'"'),i+=">"+s+"</a>",i}image({href:t,title:e,text:n,tokens:s}){s&&(n=this.parser.parseInline(s,this.parser.textRenderer));let r=Be(t);if(r===null)return S(n);t=r;let i=`<img src="${t}" alt="${S(n)}"`;return e&&(i+=` title="${S(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:S(t.text)}},he=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}},v=class se{options;renderer;textRenderer;constructor(e){this.options=e||P,this.options.renderer=this.options.renderer||new W,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new he}static parse(e,n){return new se(n).parse(e)}static parseInline(e,n){return new se(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let s=0;s<e.length;s++){let r=e[s];if(this.options.extensions?.renderers?.[r.type]){let o=r,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=r;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 s="";for(let r=0;r<e.length;r++){let i=e[r];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)){s+=l||"";continue}}let o=i;switch(o.type){case"escape":{s+=n.text(o);break}case"html":{s+=n.html(o);break}case"link":{s+=n.link(o);break}case"image":{s+=n.image(o);break}case"checkbox":{s+=n.checkbox(o);break}case"strong":{s+=n.strong(o);break}case"em":{s+=n.em(o);break}case"codespan":{s+=n.codespan(o);break}case"br":{s+=n.br(o);break}case"del":{s+=n.del(o);break}case"text":{s+=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 s}},O=class{options;block;constructor(t){this.options=t||P}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?y.lex:y.lexInline}provideParser(){return this.block?v.parse:v.parseInline}},sn=class{defaults=ie();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=v;Renderer=W;TextRenderer=he;Lexer=y;Tokenizer=K;Hooks=O;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let s of t)switch(n=n.concat(e.call(this,s)),s.type){case"table":{let r=s;for(let i of r.header)n=n.concat(this.walkTokens(i.tokens,e));for(let i of r.rows)for(let o of i)n=n.concat(this.walkTokens(o.tokens,e));break}case"list":{let r=s;n=n.concat(this.walkTokens(r.items,e));break}default:{let r=s;this.defaults.extensions?.childTokens?.[r.type]?this.defaults.extensions.childTokens[r.type].forEach(i=>{let o=r[i].flat(1/0);n=n.concat(this.walkTokens(o,e))}):r.tokens&&(n=n.concat(this.walkTokens(r.tokens,e)))}}return n}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let s={...n};if(s.async=this.defaults.async||s.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){let i=e.renderers[r.name];i?e.renderers[r.name]=function(...o){let l=r.renderer.apply(this,o);return l===!1&&(l=i.apply(this,o)),l}:e.renderers[r.name]=r.renderer}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=e[r.level];i?i.unshift(r.tokenizer):e[r.level]=[r.tokenizer],r.start&&(r.level==="block"?e.startBlock?e.startBlock.push(r.start):e.startBlock=[r.start]:r.level==="inline"&&(e.startInline?e.startInline.push(r.start):e.startInline=[r.start]))}"childTokens"in r&&r.childTokens&&(e.childTokens[r.name]=r.childTokens)}),s.extensions=e),n.renderer){let r=this.defaults.renderer||new W(this.defaults);for(let i in n.renderer){if(!(i in r))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let o=i,l=n.renderer[o],a=r[o];r[o]=(...p)=>{let c=l.apply(r,p);return c===!1&&(c=a.apply(r,p)),c||""}}s.renderer=r}if(n.tokenizer){let r=this.defaults.tokenizer||new K(this.defaults);for(let i in n.tokenizer){if(!(i in r))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let o=i,l=n.tokenizer[o],a=r[o];r[o]=(...p)=>{let c=l.apply(r,p);return c===!1&&(c=a.apply(r,p)),c}}s.tokenizer=r}if(n.hooks){let r=this.defaults.hooks||new O;for(let i in n.hooks){if(!(i in r))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let o=i,l=n.hooks[o],a=r[o];O.passThroughHooks.has(i)?r[o]=p=>{if(this.defaults.async&&O.passThroughHooksRespectAsync.has(i))return(async()=>{let h=await l.call(r,p);return a.call(r,h)})();let c=l.call(r,p);return a.call(r,c)}:r[o]=(...p)=>{if(this.defaults.async)return(async()=>{let h=await l.apply(r,p);return h===!1&&(h=await a.apply(r,p)),h})();let c=l.apply(r,p);return c===!1&&(c=a.apply(r,p)),c}}s.hooks=r}if(n.walkTokens){let r=this.defaults.walkTokens,i=n.walkTokens;s.walkTokens=function(o){let l=[];return l.push(i.call(this,o)),r&&(l=l.concat(r.call(this,o))),l}}this.defaults={...this.defaults,...s}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return y.lex(t,e??this.defaults)}parser(t,e){return v.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let s={...n},r={...this.defaults,...s},i=this.onError(!!r.silent,!!r.async);if(this.defaults.async===!0&&s.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(r.hooks&&(r.hooks.options=r,r.hooks.block=t),r.async)return(async()=>{let o=r.hooks?await r.hooks.preprocess(e):e,l=await(r.hooks?await r.hooks.provideLexer():t?y.lex:y.lexInline)(o,r),a=r.hooks?await r.hooks.processAllTokens(l):l;r.walkTokens&&await Promise.all(this.walkTokens(a,r.walkTokens));let p=await(r.hooks?await r.hooks.provideParser():t?v.parse:v.parseInline)(a,r);return r.hooks?await r.hooks.postprocess(p):p})().catch(i);try{r.hooks&&(e=r.hooks.preprocess(e));let o=(r.hooks?r.hooks.provideLexer():t?y.lex:y.lexInline)(e,r);r.hooks&&(o=r.hooks.processAllTokens(o)),r.walkTokens&&this.walkTokens(o,r.walkTokens);let l=(r.hooks?r.hooks.provideParser():t?v.parse:v.parseInline)(o,r);return r.hooks&&(l=r.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 s="<p>An error occurred:</p><pre>"+S(n.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(n);throw n}}},L=new sn;function k(t,e){return L.parse(t,e)}k.options=k.setOptions=function(t){return L.setOptions(t),k.defaults=L.defaults,De(k.defaults),k};k.getDefaults=ie;k.defaults=P;k.use=function(...t){return L.use(...t),k.defaults=L.defaults,De(k.defaults),k};k.walkTokens=function(t,e){return L.walkTokens(t,e)};k.parseInline=L.parseInline;k.Parser=v;k.parser=v.parse;k.Renderer=W;k.TextRenderer=he;k.Lexer=y;k.lexer=y.lex;k.Tokenizer=K;k.Hooks=O;k.parse=k;var zn=k.options,Mn=k.setOptions,qn=k.use,Bn=k.walkTokens,Hn=k.parseInline;var Nn=v.parse,Dn=y.lex;var on=["http:","https:","mailto:"];function an(t){try{let e=new URL(t);return on.includes(e.protocol)?e.href:void 0}catch{return}}function f(t,e){let n=document.createElement(t);return e&&(n.className=e),n}function T(t,e){if(e)for(let n of e)switch(n.type){case"strong":{let s=f("strong");T(s,n.tokens),t.appendChild(s);break}case"em":{let s=f("em");T(s,n.tokens),t.appendChild(s);break}case"del":{let s=f("s");T(s,n.tokens),t.appendChild(s);break}case"codespan":{let s=f("code","md-code-inline");s.textContent=n.text,t.appendChild(s);break}case"link":{let s=n,r=an(s.href);if(r===void 0){let o=f("span");T(o,s.tokens),t.appendChild(o);break}let i=f("a","md-link");i.href=r,i.target="_blank",i.rel="noopener noreferrer",T(i,s.tokens),t.appendChild(i);break}case"image":{let s=f("span","md-image");s.textContent=`[image: ${n.text||"untitled"}]`,t.appendChild(s);break}case"br":t.appendChild(f("br"));break;default:{let s=n.text??"",r=n.tokens;r&&r.length>0&&n.type==="text"?T(t,r):s&&t.appendChild(document.createTextNode(s));break}}}function ln(t){let e=t.ordered?f("ol","md-list"):f("ul","md-list");t.ordered&&typeof t.start=="number"&&t.start>1&&(e.start=t.start);for(let n of t.items){let s=f("li");if(n.task){let r=f("input","md-task");r.type="checkbox",r.checked=!!n.checked,r.disabled=!0,s.appendChild(r)}ge(s,n.tokens),e.appendChild(s)}return e}function cn(t){let e=f("pre","md-pre"),n=f("code");return t.lang&&(n.className=`md-lang-${t.lang.split(/\s+/)[0]??""}`),n.textContent=t.text,e.appendChild(n),e}function pn(t){let e=f("table","md-table"),n=f("thead"),s=f("tr");for(let i of t.header){let o=f("th");T(o,i.tokens),s.appendChild(o)}n.appendChild(s),e.appendChild(n);let r=f("tbody");for(let i of t.rows){let o=f("tr");for(let l of i){let a=f("td");T(a,l.tokens),o.appendChild(a)}r.appendChild(o)}return e.appendChild(r),e}function ge(t,e){for(let n of e)switch(n.type){case"heading":{let s=Math.min(Math.max(n.depth,1),6),r=f(`h${s}`,"md-heading");T(r,n.tokens),t.appendChild(r);break}case"paragraph":{let s=f("p","md-p");T(s,n.tokens),t.appendChild(s);break}case"code":t.appendChild(cn(n));break;case"list":t.appendChild(ln(n));break;case"blockquote":{let s=f("blockquote","md-quote");ge(s,n.tokens),t.appendChild(s);break}case"table":t.appendChild(pn(n));break;case"hr":t.appendChild(f("hr","md-hr"));break;case"space":break;case"html":{let s=f("p","md-p");s.textContent=n.text,t.appendChild(s);break}default:{let s=n.tokens;if(s&&s.length>0){let i=f("p","md-p");T(i,s),t.appendChild(i);break}let r=n.text??"";if(r.trim()){let i=f("p","md-p");i.textContent=r,t.appendChild(i)}break}}}function Xe(t,e="md"){let n=f("div",e);try{ge(n,new y().lex(t))}catch{n.textContent=t}return n}var Je=2e3;function u(t,e,n){let s=document.createElement(t);return e&&(s.className=e),n!==void 0&&(s.textContent=n),s}function un(t){if(!t)return;let e=t.split("/").filter(Boolean);return e.length>0?e[e.length-1]:void 0}function dn(t){return(t.title??"").replace(/^\s*\[[^\]]{0,80}\]\s*/,"").trim()||t.title||t.id.slice(0,8)}function fe(t,e,n,s){t.textContent="";for(let r of e){let i=u("button","session-row");r.id===n&&i.classList.add("is-active");let o=u("span","session-title",dn(r));i.appendChild(o);let l=u("span","session-meta"),a=un(r.cwd);a&&l.appendChild(u("span","session-cwd",a));let p=u("span",r.mode==="live"?"badge badge-live":"badge badge-readonly");p.textContent=r.mode==="live"?"live":"read-only",l.appendChild(p),r.alive&&l.appendChild(u("span","badge badge-alive","running")),r.updatedAt&&l.appendChild(u("span","session-time",kn(r.updatedAt))),i.appendChild(l),i.addEventListener("click",()=>s(r.id)),t.appendChild(i)}e.length===0&&t.appendChild(u("div","empty","No sessions found."))}function ke(t,e){t.textContent="";for(let n of e)t.appendChild(hn(n))}function hn(t){switch(t.kind){case"user":{let e=u("div","msg msg-user");return e.appendChild(u("div","msg-role","you")),e.appendChild(u("div","msg-body",t.text)),e}case"assistant":{let e=u("div","msg msg-assistant");e.appendChild(u("div","msg-role","agent"));let n=u("div","msg-body md-body");return n.appendChild(Xe(t.text)),e.appendChild(n),e}case"thinking":{let e=u("details","msg msg-thinking");return e.appendChild(u("summary","msg-role","thinking")),e.appendChild(u("div","msg-body",t.text)),e}case"error":{let e=u("div","msg msg-error");return e.appendChild(u("div","msg-role","error")),e.appendChild(u("div","msg-body",t.message)),e}case"notice":return u("div","notice",t.text);case"tool":return gn(t)}}function gn(t){let e=u("details",`tool tool-${t.status}`),n=u("summary","tool-summary");n.appendChild(u("span",`tool-dot tool-dot-${t.status}`,"")),n.appendChild(u("span","tool-name",t.name)),t.inputPreview&&n.appendChild(u("span","tool-target",fn(t.inputPreview,90))),e.appendChild(n);let s=u("div","tool-body");if(t.inputPreview&&(s.appendChild(u("div","tool-label","input")),s.appendChild(u("pre","tool-pre",j(t.inputPreview)))),t.outputUnavailable===!0)s.appendChild(u("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!==""){s.appendChild(u("div","tool-label","output"));let r=j(t.output);if(r.length>Je){let i=u("pre","tool-pre",r.slice(0,Je));s.appendChild(i);let o=u("button","tool-more",`Show full output (${r.length.toLocaleString()} chars)`);o.addEventListener("click",()=>{i.textContent=r,o.remove()}),s.appendChild(o)}else s.appendChild(u("pre","tool-pre",r))}return t.diff!==void 0&&(s.appendChild(u("div","tool-label","diff")),s.appendChild(u("pre","tool-pre",j(String(t.diff))))),e.appendChild(s),e}function fn(t,e){let n=t.replace(/\s+/g," ").trim();return n.length<=e?n:`${n.slice(0,e-1)}\u2026`}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`}function me(t,e,n){t.textContent="",t.classList.toggle("has-pending",e.length>0);for(let s of e){let r=s.request??{},i=u("div","approval-card"),o=u("div","approval-head");o.appendChild(u("span","approval-badge",r.origin==="agent"?"question":"approval")),r.serverName&&o.appendChild(u("span","approval-source",r.serverName)),i.appendChild(o);let l=r.title??r.message??"The agent is waiting for a response.";i.appendChild(u("div","approval-title",l)),r.description&&r.description!==l&&i.appendChild(u("div","approval-desc",r.description));let a=u("div","approval-actions");if(r.type==="choice"&&Array.isArray(r.choices)&&r.choices.length>0)for(let c of r.choices){let h=u("button","approval-btn",c);h.addEventListener("click",()=>n(s.id,{action:"accept",content:{value:c}})),a.appendChild(h)}else if(r.type==="text"||r.type==="number"){let c=document.createElement("input");c.className="approval-input",c.type=r.type==="number"?"number":"text",r.questionDefault!==void 0&&(c.value=String(r.questionDefault));let h=()=>n(s.id,{action:"accept",content:{value:r.type==="number"?Number(c.value):c.value}});c.addEventListener("keydown",x=>{x.key==="Enter"&&h()}),i.appendChild(c);let d=u("button","approval-btn approval-primary","Submit");d.addEventListener("click",h),a.appendChild(d)}else{let c=u("button","approval-btn approval-primary","Approve");c.addEventListener("click",()=>n(s.id,{action:"accept",content:{value:!0}})),a.appendChild(c)}let p=u("button","approval-btn approval-danger","Deny");p.addEventListener("click",()=>n(s.id,{action:"decline"})),a.appendChild(p),i.appendChild(a),t.appendChild(i)}}var Ve=0;function $(t){return Ve+=1,`${t}_${Ve}`}function I(t){return typeof t=="string"?t:void 0}function Ye(t){let e=t;if(typeof e.kind=="string")switch(e.kind){case"user":return{kind:"user",id:$("u"),text:I(e.text)??""};case"assistant":return{kind:"assistant",id:$("a"),text:I(e.text)??""};case"tool":{let n=I(e.input)??"";return n.trim()==="\u2026"?void 0:{kind:"tool",id:$("t"),name:I(e.toolName)??"tool",inputPreview:n,status:"ok",outputUnavailable:!0}}case"tool_error":{let n=I(e.content)??"",s=n.split(`
64
- `,1)[0]??"";return{kind:"tool",id:$("t"),name:I(e.toolName)??"error",inputPreview:s,status:"error",output:n}}case"error":return{kind:"error",id:$("e"),message:I(e.message)??"error"};case"done":{let n=e.costUsd,s=e.durationMs,r=[];return typeof n=="number"&&r.push(`$${n.toFixed(4)}`),typeof s=="number"&&r.push(`${(s/1e3).toFixed(1)}s`),{kind:"notice",id:$("n"),text:r.length?`turn complete \xB7 ${r.join(" \xB7 ")}`:"turn complete"}}case"paused":return{kind:"notice",id:$("n"),text:"paused \u2014 usage limit"};case"resumed":return{kind:"notice",id:$("n"),text:"resumed"};default:return}}function et(t,e){let n=e;if(n.kind!=="done")return t;let s=n.costUsd,r=n.durationMs;return{costUsd:t.costUsd+(typeof s=="number"?s:0),durationMs:t.durationMs+(typeof r=="number"?r:0),turns:t.turns+1}}function xe(t,e){return Number.isInteger(e)&&e>=0&&e<t.length}function tt(t,e){if(!xe(t,e)||e===0)return t.slice();let n=t.slice(),s=n[e-1],r=n[e];return s===void 0||r===void 0?t.slice():(n[e-1]=r,n[e]=s,n)}function nt(t,e){if(!xe(t,e)||e===t.length-1)return t.slice();let n=t.slice(),s=n[e+1],r=n[e];return s===void 0||r===void 0?t.slice():(n[e+1]=r,n[e]=s,n)}function rt(t,e){if(!xe(t,e))return t.slice();let n=t.slice();return n.splice(e,1),n}var J=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="",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,s)=>{let r=document.createElement("div");r.className="queue-row";let i=document.createElement("span");i.className="queue-text",i.textContent=n,r.appendChild(i);for(let[o,l]of[["\u2191",()=>{this.queue=tt(this.queue,s)}],["\u2193",()=>{this.queue=nt(this.queue,s)}],["\u2715",()=>{this.queue=rt(this.queue,s)}]]){let a=document.createElement("button");a.className="queue-btn",a.textContent=o,a.addEventListener("click",()=>{l(),this.render()}),r.appendChild(a)}e.appendChild(r)})}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 st(t,e=80){return t.scrollHeight-t.scrollTop-t.clientHeight<=e}var ot=Le(),M=[],R,V=[],E={costUsd:0,durationMs:0,turns:0},be,_=[],we,q=!1;function m(t){let e=document.getElementById(t);if(!e)throw new Error(`missing #${t}`);return e}var ye;function ve(){return ye||(ye=new J({container:m("queue"),input:m("prompt"),send:m("send"),submit:async t=>{if(R===void 0)throw new Error("no active session");await B(`/api/sessions/${encodeURIComponent(R)}/prompt`,{method:"POST",body:JSON.stringify({text:t})})},isLive:Se,isTurnActive:()=>q,onAccepted:()=>{q=!0,Y()},onError:t=>{m("status").textContent=t}})),ye}async function B(t,e){let n=await fetch(t,{...e,headers:{authorization:`Bearer ${ot}`,"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 mn(t){t.scrollTop=t.scrollHeight}function xn(){return M.find(t=>t.id===R)}function Se(){return xn()?.mode==="live"}async function Te(){if(M=(await B("/api/sessions")).sessions,R===void 0&&M.length>0){let e=M[0];e&&ee(e.id)}fe(m("sessions"),M,R,ee)}function ee(t){R=t,V=[],ve().clear(),E={costUsd:0,durationMs:0,turns:0},be?.stop(),q=!1,fe(m("sessions"),M,R,ee),ke(m("transcript"),V),bn(),Y(),be=new U(t,ot,{onEvent:e=>{let s=e.record;if(!s)return;(s.kind==="done"||s.kind==="error")&&(q=!1,Y(),ve().flush());let r=Ye(s);if(E=et(E,s),r){V.push(r);let i=st(m("transcript"));ke(m("transcript"),V),i&&mn(m("transcript"))}at()},onStatus:e=>{let n=m("status");n.textContent=e==="ended"?"session ended":e,n.className=`status status-${e}`,e==="ended"&&(q=!1),Y()}}),be.start()}function at(){let t=[`${E.turns} turns`];E.costUsd>0&&t.push(`$${E.costUsd.toFixed(4)}`),E.durationMs>0&&t.push(`${(E.durationMs/1e3).toFixed(1)}s`),m("meter").textContent=t.join(" \xB7 ")}function bn(){let t=Se(),e=m("prompt"),n=m("send");e.disabled=!t,n.disabled=!t,e.placeholder=t?"Message the agent\u2026 (queues while it works)":"Read-only \u2014 this session runs in another process",m("composer").classList.toggle("is-readonly",!t)}function Y(){m("stop").hidden=!(q&&Se())}async function wn(){let t=m("new-session");t.disabled=!0,t.textContent="starting\u2026";try{let{session:e}=await B("/api/sessions",{method:"POST",body:JSON.stringify({})});await Te(),ee(e.id)}catch(e){m("status").textContent=e instanceof Error?e.message:"could not start session"}finally{t.disabled=!1,t.textContent="+ New"}}async function it(){let t=await B("/api/pending"),e=t.pending.length!==_.length||t.pending.some((n,s)=>n.id!==_[s]?.id);_=t.pending,e&&me(m("approvals"),_,lt)}function lt(t,e){_=_.filter(n=>n.id!==t),me(m("approvals"),_,lt),B("/api/approve",{method:"POST",body:JSON.stringify({requestId:t,response:e})}).catch(n=>{m("status").textContent=n instanceof Error?n.message:"approval failed"})}async function yn(){R!==void 0&&await B(`/api/sessions/${encodeURIComponent(R)}/interrupt`,{method:"POST",body:JSON.stringify({})})}async function vn(){ve().wire(),m("new-session").addEventListener("click",()=>{wn()}),m("stop").addEventListener("click",()=>{yn().catch(t=>{m("status").textContent=t instanceof Error?t.message:"stop failed"})}),at(),await Te(),setInterval(()=>{Te().catch(()=>{})},1e4),we=setInterval(()=>{it().catch(()=>{})},1e3),it().catch(()=>{}),window.addEventListener("beforeunload",()=>{we&&clearInterval(we)})}vn().catch(t=>{m("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>${S(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=Xe(t);if(s===null)return r;t=s;let i='<a href="'+t+'"';return e&&(i+=' title="'+S(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=Xe(t);if(s===null)return S(n);t=s;let i=`<img src="${t}" alt="${S(n)}"`;return e&&(i+=` title="${S(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:S(t.text)}},me=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}},v=class ae{options;renderer;textRenderer;constructor(e){this.options=e||I,this.options.renderer=this.options.renderer||new X,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new me}static parse(e,n){return new ae(n).parse(e)}static parseInline(e,n){return new ae(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,c=this.options.extensions.renderers[o.type].call({parser:this},o);if(c!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(o.type)){n+=c||"";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 c=this.options.extensions.renderers[i.type].call({parser:this},i);if(c!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){r+=c||"";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 c='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(c),"";throw new Error(c)}}}return r}},O=class{options;block;constructor(t){this.options=t||I}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?y.lex:y.lexInline}provideParser(){return this.block?v.parse:v.parseInline}},En=class{defaults=le();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=v;Renderer=X;TextRenderer=me;Lexer=y;Tokenizer=W;Hooks=O;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 c=s.renderer.apply(this,o);return c===!1&&(c=i.apply(this,o)),c}: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 X(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,c=n.renderer[o],a=s[o];s[o]=(...p)=>{let l=c.apply(s,p);return l===!1&&(l=a.apply(s,p)),l||""}}r.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new W(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,c=n.tokenizer[o],a=s[o];s[o]=(...p)=>{let l=c.apply(s,p);return l===!1&&(l=a.apply(s,p)),l}}r.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new O;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,c=n.hooks[o],a=s[o];O.passThroughHooks.has(i)?s[o]=p=>{if(this.defaults.async&&O.passThroughHooksRespectAsync.has(i))return(async()=>{let u=await c.call(s,p);return a.call(s,u)})();let l=c.call(s,p);return a.call(s,l)}:s[o]=(...p)=>{if(this.defaults.async)return(async()=>{let u=await c.apply(s,p);return u===!1&&(u=await a.apply(s,p)),u})();let l=c.apply(s,p);return l===!1&&(l=a.apply(s,p)),l}}r.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(o){let c=[];return c.push(i.call(this,o)),s&&(c=c.concat(s.call(this,o))),c}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return y.lex(t,e??this.defaults)}parser(t,e){return v.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,c=await(s.hooks?await s.hooks.provideLexer():t?y.lex:y.lexInline)(o,s),a=s.hooks?await s.hooks.processAllTokens(c):c;s.walkTokens&&await Promise.all(this.walkTokens(a,s.walkTokens));let p=await(s.hooks?await s.hooks.provideParser():t?v.parse:v.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?y.lex:y.lexInline)(e,s);s.hooks&&(o=s.hooks.processAllTokens(o)),s.walkTokens&&this.walkTokens(o,s.walkTokens);let c=(s.hooks?s.hooks.provideParser():t?v.parse:v.parseInline)(o,s);return s.hooks&&(c=s.hooks.postprocess(c)),c}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>"+S(n.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},$=new En;function m(t,e){return $.parse(t,e)}m.options=m.setOptions=function(t){return $.setOptions(t),m.defaults=$.defaults,Ye(m.defaults),m};m.getDefaults=le;m.defaults=I;m.use=function(...t){return $.use(...t),m.defaults=$.defaults,Ye(m.defaults),m};m.walkTokens=function(t,e){return $.walkTokens(t,e)};m.parseInline=$.parseInline;m.Parser=v;m.parser=v.parse;m.Renderer=X;m.TextRenderer=me;m.Lexer=y;m.lexer=y.lex;m.Tokenizer=W;m.Hooks=O;m.parse=m;var gs=m.options,ms=m.setOptions,ks=m.use,xs=m.walkTokens,bs=m.parseInline;var ws=v.parse,ys=y.lex;var Rn=["http:","https:","mailto:"];function An(t){try{let e=new URL(t);return Rn.includes(e.protocol)?e.href:void 0}catch{return}}function g(t,e){let n=document.createElement(t);return e&&(n.className=e),n}function T(t,e){if(e)for(let n of e)switch(n.type){case"strong":{let r=g("strong");T(r,n.tokens),t.appendChild(r);break}case"em":{let r=g("em");T(r,n.tokens),t.appendChild(r);break}case"del":{let r=g("s");T(r,n.tokens),t.appendChild(r);break}case"codespan":{let r=g("code","md-code-inline");r.textContent=n.text,t.appendChild(r);break}case"link":{let r=n,s=An(r.href);if(s===void 0){let o=g("span");T(o,r.tokens),t.appendChild(o);break}let i=g("a","md-link");i.href=s,i.target="_blank",i.rel="noopener noreferrer",T(i,r.tokens),t.appendChild(i);break}case"image":{let r=g("span","md-image");r.textContent=`[image: ${n.text||"untitled"}]`,t.appendChild(r);break}case"br":t.appendChild(g("br"));break;default:{let r=n.text??"",s=n.tokens;s&&s.length>0&&n.type==="text"?T(t,s):r&&t.appendChild(document.createTextNode(r));break}}}function Ln(t){let e=t.ordered?g("ol","md-list"):g("ul","md-list");t.ordered&&typeof t.start=="number"&&t.start>1&&(e.start=t.start);for(let n of t.items){let r=g("li");if(n.task){let s=g("input","md-task");s.type="checkbox",s.checked=!!n.checked,s.disabled=!0,r.appendChild(s)}ke(r,n.tokens),e.appendChild(r)}return e}function $n(t){let e=g("pre","md-pre"),n=g("code");return t.lang&&(n.className=`md-lang-${t.lang.split(/\s+/)[0]??""}`),n.textContent=t.text,e.appendChild(n),e}function In(t){let e=g("table","md-table"),n=g("thead"),r=g("tr");for(let i of t.header){let o=g("th");T(o,i.tokens),r.appendChild(o)}n.appendChild(r),e.appendChild(n);let s=g("tbody");for(let i of t.rows){let o=g("tr");for(let c of i){let a=g("td");T(a,c.tokens),o.appendChild(a)}s.appendChild(o)}return e.appendChild(s),e}function ke(t,e){for(let n of e)switch(n.type){case"heading":{let r=Math.min(Math.max(n.depth,1),6),s=g(`h${r}`,"md-heading");T(s,n.tokens),t.appendChild(s);break}case"paragraph":{let r=g("p","md-p");T(r,n.tokens),t.appendChild(r);break}case"code":t.appendChild($n(n));break;case"list":t.appendChild(Ln(n));break;case"blockquote":{let r=g("blockquote","md-quote");ke(r,n.tokens),t.appendChild(r);break}case"table":t.appendChild(In(n));break;case"hr":t.appendChild(g("hr","md-hr"));break;case"space":break;case"html":{let r=g("p","md-p");r.textContent=n.text,t.appendChild(r);break}default:{let r=n.tokens;if(r&&r.length>0){let i=g("p","md-p");T(i,r),t.appendChild(i);break}let s=n.text??"";if(s.trim()){let i=g("p","md-p");i.textContent=s,t.appendChild(i)}break}}}function ct(t,e="md"){let n=g("div",e);try{ke(n,new y().lex(t))}catch{n.textContent=t}return n}var pt=2e3;function d(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!==void 0&&(r.textContent=n),r}function Pn(t){if(!t)return;let e=t.split("/").filter(Boolean);return e.length>0?e[e.length-1]:void 0}function Mn(t){return(t.title??"").replace(/^\s*\[[^\]]{0,80}\]\s*/,"").trim()||t.title||t.id.slice(0,8)}function xe(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",Mn(s));i.appendChild(o);let c=d("span","session-meta"),a=Pn(s.cwd);a&&c.appendChild(d("span","session-cwd",a));let p=d("span",s.mode==="live"?"badge badge-live":"badge badge-readonly");p.textContent=s.mode==="live"?"live":"read-only",c.appendChild(p),s.alive&&c.appendChild(d("span","badge badge-alive","running")),s.updatedAt&&c.appendChild(d("span","session-time",qn(s.updatedAt))),i.appendChild(c),i.addEventListener("click",()=>r(s.id)),t.appendChild(i)}e.length===0&&t.appendChild(d("div","empty","No sessions found."))}function be(t,e){t.textContent="";for(let n of e)t.appendChild(_n(n))}function _n(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(ct(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 zn(t)}}function zn(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",Hn(t.inputPreview,90))),e.appendChild(n);let r=d("div","tool-body");if(t.inputPreview&&(r.appendChild(d("div","tool-label","input")),r.appendChild(d("pre","tool-pre",K(t.inputPreview)))),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=K(t.output);if(s.length>pt){let i=d("pre","tool-pre",s.slice(0,pt));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(d("pre","tool-pre",K(String(t.diff))))),e.appendChild(r),e}function Hn(t,e){let n=t.replace(/\s+/g," ").trim();return n.length<=e?n:`${n.slice(0,e-1)}\u2026`}function qn(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`}function we(t,e,n){t.textContent="",t.classList.toggle("has-pending",e.length>0);for(let r of e){let s=r.request??{},i=d("div","approval-card"),o=d("div","approval-head");o.appendChild(d("span","approval-badge",s.origin==="agent"?"question":"approval")),s.serverName&&o.appendChild(d("span","approval-source",s.serverName)),i.appendChild(o);let c=s.title??s.message??"The agent is waiting for a response.";i.appendChild(d("div","approval-title",c)),s.description&&s.description!==c&&i.appendChild(d("div","approval-desc",s.description));let a=d("div","approval-actions");if(s.type==="choice"&&Array.isArray(s.choices)&&s.choices.length>0)for(let l of s.choices){let u=d("button","approval-btn",l);u.addEventListener("click",()=>n(r.id,{action:"accept",content:{value:l}})),a.appendChild(u)}else if(s.type==="text"||s.type==="number"){let l=document.createElement("input");l.className="approval-input",l.type=s.type==="number"?"number":"text",s.questionDefault!==void 0&&(l.value=String(s.questionDefault));let u=()=>n(r.id,{action:"accept",content:{value:s.type==="number"?Number(l.value):l.value}});l.addEventListener("keydown",x=>{x.key==="Enter"&&u()}),i.appendChild(l);let h=d("button","approval-btn approval-primary","Submit");h.addEventListener("click",u),a.appendChild(h)}else{let l=d("button","approval-btn approval-primary","Approve");l.addEventListener("click",()=>n(r.id,{action:"accept",content:{value:!0}})),a.appendChild(l)}let p=d("button","approval-btn approval-danger","Deny");p.addEventListener("click",()=>n(r.id,{action:"decline"})),a.appendChild(p),i.appendChild(a),t.appendChild(i)}}var dt=0;function R(t){return dt+=1,`${t}_${dt}`}function P(t){return typeof t=="string"?t:void 0}function ut(t){let e=t;if(typeof e.kind=="string")switch(e.kind){case"user":return{kind:"user",id:R("u"),text:P(e.text)??""};case"assistant":return{kind:"assistant",id:R("a"),text:P(e.text)??""};case"tool":{let n=P(e.input)??"";return n.trim()==="\u2026"?void 0:{kind:"tool",id:R("t"),name:P(e.toolName)??"tool",inputPreview:n,status:"ok",outputUnavailable:!0}}case"tool_error":{let n=P(e.content)??"",r=n.split(`
64
+ `,1)[0]??"";return{kind:"tool",id:R("t"),name:P(e.toolName)??"error",inputPreview:r,status:"error",output:n}}case"error":return{kind:"error",id:R("e"),message:P(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 ht(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 ye(t,e){return Number.isInteger(e)&&e>=0&&e<t.length}function ft(t,e){if(!ye(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 gt(t,e){if(!ye(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 mt(t,e){if(!ye(t,e))return t.slice();let n=t.slice();return n.splice(e,1),n}var Y=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="",U(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,c]of[["\u2191",()=>{this.queue=ft(this.queue,r)}],["\u2193",()=>{this.queue=gt(this.queue,r)}],["\u2715",()=>{this.queue=mt(this.queue,r)}]]){let a=document.createElement("button");a.className="queue-btn",a.textContent=o,a.addEventListener("click",()=>{c(),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 kt(t,e=80){return t.scrollHeight-t.scrollTop-t.clientHeight<=e}var bt=Me(),H=[],E,ee=[],A={costUsd:0,durationMs:0,turns:0},ve,M=[],Te,q=!1;function k(t){let e=document.getElementById(t);if(!e)throw new Error(`missing #${t}`);return e}var Se;function Ce(){return Se||(Se=new Y({container:k("queue"),input:k("prompt"),send:k("send"),submit:async t=>{if(E===void 0)throw new Error("no active session");await _(`/api/sessions/${encodeURIComponent(E)}/prompt`,{method:"POST",body:JSON.stringify({text:t})})},isLive:Re,isTurnActive:()=>q,onAccepted:()=>{q=!0,te()},onError:t=>{k("status").textContent=t}})),Se}async function _(t,e){let n=await fetch(t,{...e,headers:{authorization:`Bearer ${bt}`,"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 Bn(t){t.scrollTop=t.scrollHeight}function Nn(){return H.find(t=>t.id===E)}function Re(){return Nn()?.mode==="live"}async function Ee(){if(H=(await _("/api/sessions")).sessions,E===void 0&&H.length>0){let e=H[0];e&&ne(e.id)}xe(k("sessions"),H,E,ne)}function ne(t){E=t,ee=[],Ce().clear(),A={costUsd:0,durationMs:0,turns:0},ve?.stop(),q=!1,xe(k("sessions"),H,E,ne),be(k("transcript"),ee),Dn(),te(),ve=new j(t,bt,{onEvent:e=>{let r=e.record;if(!r)return;(r.kind==="done"||r.kind==="error")&&(q=!1,te(),Ce().flush());let s=ut(r);if(A=ht(A,r),s){ee.push(s);let i=kt(k("transcript"));be(k("transcript"),ee),i&&Bn(k("transcript"))}wt()},onStatus:e=>{let n=k("status");n.textContent=e==="ended"?"session ended":e,n.className=`status status-${e}`,e==="ended"&&(q=!1),te()}}),ve.start()}function wt(){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`),k("meter").textContent=t.join(" \xB7 ")}function Dn(){let t=Re(),e=k("prompt"),n=k("send");e.disabled=!t,n.disabled=!t,e.placeholder=t?"Message the agent\u2026 (queues while it works)":"Read-only \u2014 this session runs in another process",k("composer").classList.toggle("is-readonly",!t)}function te(){k("stop").hidden=!(q&&Re())}async function On(){let t=k("new-session");t.disabled=!0,t.textContent="starting\u2026";try{let{session:e}=await _("/api/sessions",{method:"POST",body:JSON.stringify({})});await Ee(),ne(e.id)}catch(e){k("status").textContent=e instanceof Error?e.message:"could not start session"}finally{t.disabled=!1,t.textContent="+ New"}}async function xt(){let t=await _("/api/pending"),e=t.pending.length!==M.length||t.pending.some((n,r)=>n.id!==M[r]?.id);M=t.pending,e&&we(k("approvals"),M,yt)}function yt(t,e){M=M.filter(n=>n.id!==t),we(k("approvals"),M,yt),_("/api/approve",{method:"POST",body:JSON.stringify({requestId:t,response:e})}).catch(n=>{k("status").textContent=n instanceof Error?n.message:"approval failed"})}async function Fn(){E!==void 0&&await _(`/api/sessions/${encodeURIComponent(E)}/interrupt`,{method:"POST",body:JSON.stringify({})})}async function jn(){Ze({input:k("prompt"),loadCommands:async()=>(await _("/api/commands")).commands}),Ce().wire(),k("new-session").addEventListener("click",()=>{On()}),k("stop").addEventListener("click",()=>{Fn().catch(t=>{k("status").textContent=t instanceof Error?t.message:"stop failed"})}),wt(),await Ee(),setInterval(()=>{Ee().catch(()=>{})},1e4),Te=setInterval(()=>{xt().catch(()=>{})},1e3),xt().catch(()=>{}),window.addEventListener("beforeunload",()=>{Te&&clearInterval(Te)})}jn().catch(t=>{k("status").textContent=t instanceof Error?t.message:String(t)});
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Approvals.
3
+ *
4
+ * Invariant: a pending approval BLOCKS the agent's turn, so these cards must be
5
+ * impossible to miss — they sit directly above the composer (the region the
6
+ * operator is already looking at) rather than in the transcript, where new
7
+ * output would scroll them out of view while the turn stays stuck.
8
+ */
9
+ .approvals:empty { display: none; }
10
+ .approvals {
11
+ border-top: 1px solid var(--border); background: var(--bg-sunken);
12
+ padding: 10px 16px; display: flex; flex-direction: column; gap: 8px;
13
+ max-height: 42vh; overflow-y: auto;
14
+ }
15
+ .approval-card {
16
+ border: 1px solid var(--warning); border-radius: var(--radius);
17
+ background: var(--bg-raised); padding: 11px 13px;
18
+ }
19
+ .approval-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
20
+ .approval-badge {
21
+ font-family: var(--mono); font-size: 10px; text-transform: uppercase;
22
+ letter-spacing: 0.06em; color: var(--warning);
23
+ border: 1px solid var(--warning); border-radius: 4px; padding: 1px 6px;
24
+ }
25
+ .approval-source { font-family: var(--mono); font-size: 10px; color: var(--text-faint); }
26
+ .approval-title { font-size: 13px; line-height: 1.5; color: var(--text); }
27
+ .approval-desc { font-size: 12px; line-height: 1.5; color: var(--text-dim); margin-top: 4px; }
28
+ .approval-input {
29
+ width: 100%; margin-top: 8px; padding: 7px 9px;
30
+ font-family: var(--mono); font-size: 12px;
31
+ color: var(--text); background: var(--bg-sunken);
32
+ border: 1px solid var(--border); border-radius: 6px;
33
+ }
34
+ .approval-input:focus { outline: none; border-color: var(--accent); }
35
+ .approval-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
36
+ .approval-btn {
37
+ font: inherit; font-size: 12px; cursor: pointer;
38
+ color: var(--text); background: var(--bg-sunken);
39
+ border: 1px solid var(--border); border-radius: 6px; padding: 5px 12px;
40
+ }
41
+ .approval-btn:hover { border-color: var(--text-dim); }
42
+ .approval-primary { color: var(--bg); background: var(--success); border-color: var(--success); }
43
+ .approval-primary:hover { filter: brightness(1.08); }
44
+ .approval-danger { color: var(--error); border-color: var(--error); background: transparent; }
45
+ .approval-danger:hover { background: rgba(248, 113, 113, 0.12); }
@@ -21,6 +21,7 @@
21
21
  href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='10' fill='%23f9854b'/%3E%3C/svg%3E"
22
22
  />
23
23
  <link rel="stylesheet" href="/styles.css" />
24
+ <link rel="stylesheet" href="/approvals.css" />
24
25
  </head>
25
26
  <body>
26
27
  <header class="topbar">
@@ -46,9 +47,16 @@
46
47
  <div id="transcript" class="transcript"></div>
47
48
  <div id="approvals" class="approvals"></div>
48
49
  <div id="composer" class="composer">
50
+ <div id="slash-menu" class="slash-menu" hidden></div>
49
51
  <div id="queue" class="queue"></div>
50
52
  <div class="composer-row">
51
- <textarea id="prompt" rows="2" placeholder="Message the agent…"></textarea>
53
+ <!-- The mirror renders the highlighted copy of the textarea's text;
54
+ the textarea paints its own text transparent and keeps the
55
+ caret. Both must share text metrics — see styles.css. -->
56
+ <div class="prompt-wrap">
57
+ <div id="prompt-mirror" class="prompt-mirror" aria-hidden="true"></div>
58
+ <textarea id="prompt" rows="2" placeholder="Message the agent…"></textarea>
59
+ </div>
52
60
  <button id="stop" class="stop" hidden>Stop</button>
53
61
  <button id="send" class="send">Send</button>
54
62
  </div>