agent-afk 5.145.0 → 5.145.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +2 -2
- package/dist/index.mjs +1 -1
- package/dist/telegram.mjs +1 -1
- package/dist/web-ui-assets/app.js +15 -14
- package/dist/web-ui-assets/styles.css +19 -1
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Rt="__AFK_WEB_TOKEN__",Me="afk_web_token",_e="";function ze(){let t=new URLSearchParams(location.search);(t.get("token")||t.get("k"))&&history.replaceState(null,"",location.pathname);let e=At();return e?(Lt(e),e):$t()}function At(){let t=document.querySelector('meta[name="afk-token"]')?.getAttribute("content");return!t||t===Rt?"":t}function Lt(t){_e=t;try{sessionStorage.setItem(Me,t)}catch{}}function $t(){try{let t=sessionStorage.getItem(Me);if(t)return t}catch{}return _e}var Vn=Object.freeze({end:!0,reason:"session_closed"});function He(t){return typeof t=="object"&&t!==null&&t.end===!0}function qe(t){let n=t.replace(/\r\n/g,`
|
|
2
2
|
`).split(`
|
|
3
3
|
|
|
4
4
|
`),r=n.pop()??"",s=[];for(let i of n){if(i.trim()==="")continue;let o,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 $t=15e3,It=500,U=class{constructor(e,n,r){this.sessionId=e;this.token=n;this.handlers=r}sessionId;token;handlers;controller;lastEventId;attempt=0;stopped=!1;start(){this.stopped=!1,this.connect()}stop(){this.stopped=!0,this.controller?.abort(),this.handlers.onStatus?.("closed")}async connect(){if(this.stopped)return;this.handlers.onStatus?.(this.attempt===0?"connecting":"reconnecting");let e=!1;this.controller=new AbortController;let n={authorization:`Bearer ${this.token}`};this.lastEventId!==void 0&&(n["last-event-id"]=this.lastEventId);try{let i=await fetch(`/api/sessions/${encodeURIComponent(this.sessionId)}/stream`,{headers:n,signal:this.controller.signal});if(!i.ok){if(i.status===401||i.status===403||i.status===404){this.stopped=!0;let p=i.status===401?"unauthorized":i.status===403?"forbidden":"not-found";this.handlers.onStatus?.("closed",p);return}throw new Error(`stream failed: ${i.status}`)}if(i.body===null)throw new Error("stream failed: no body");this.attempt=0,this.handlers.onStatus?.("open");let o=i.body.getReader(),c=new TextDecoder,a="";e:for(;;){let{done:p,value:l}=await o.read();if(p)break;a+=c.decode(l,{stream:!0});let{events:u,remainder:h}=He(a);a=h;for(let b of u){if(b.id!==void 0&&(this.lastEventId=b.id),b.data===void 0)continue;let x;try{x=JSON.parse(b.data)}catch{continue}if(ze(x)){e=!0,this.stopped=!0;break e}this.handlers.onEvent(x,{id:b.id})}}}catch{}if(this.stopped){e&&this.handlers.onStatus?.("ended");return}this.attempt+=1;let r=.75+Math.random()*.5,s=Math.min(It*2**(this.attempt-1),$t)*r;setTimeout(()=>{this.connect()},s)}};var qe=/(?:^|\s)(\/[A-Za-z][A-Za-z0-9_:-]*)/g,Pt=Number.POSITIVE_INFINITY;function Ne(t){let e=new Map;for(let n=0;n<t.length;n++){let r=t[n];if(!r)continue;qe.lastIndex=0;let s;for(;(s=qe.exec(r))!==null;){let i=s[1]?.toLowerCase();i!==void 0&&!e.has(i)&&e.set(i,n)}}return e}function Be(t,e){let n=t.startsWith("/")?t.toLowerCase():`/${t.toLowerCase()}`;return e.get(n)??Pt}function De(t,e,n){let r=Be(t,n),s=Be(e,n);return r!==s?r-s:t.localeCompare(e)}var Mt=20;function _t(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 Oe(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)&&_t(r,l.key)),a=Ne(n),p=(l,u)=>De(l.cand.value,u.cand.value,a);return i.sort(p),c.sort(p),[...i,...c].map(l=>l.cand).slice(0,Mt)}function Z(t){t.dispatchEvent(new Event("input"))}var je=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),je.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 Ue=/^\/(?:[A-Za-z][\w:-]*)?$/,K=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(),Z(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(!Ue.test(e)){this.close(!0);return}this.openIntent=!0;let n=++this.generation;if(await this.ensureCommands(),n!==this.generation||!this.openIntent||!this.focused||!Ue.test(this.deps.input.value)){n===this.generation&&this.close();return}let r=this.deps.input.value.slice(1);this.candidates=Oe(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 zt=/^\/[A-Za-z][\w:-]*$/;function Ht(t,e){return t===""?[]:t.split(/(\s+)/).filter(n=>n!=="").map(n=>zt.test(n)?{text:n,kind:e(n)?"known":"slash"}:{text:n,kind:"plain"})}function qt(t,e){t.textContent="";for(let n of e){if(n.kind==="plain"){t.appendChild(document.createTextNode(n.text));continue}let r=document.createElement("span");r.className=n.kind==="known"?"tok-known":"tok-slash",r.textContent=n.text,t.appendChild(r)}t.appendChild(document.createTextNode("\u200B"))}function ie(t,e,n){qt(e,Ht(t.value,n)),e.scrollTop=t.scrollTop,e.scrollLeft=t.scrollLeft}function Ze(t,e,n){let r=()=>{ie(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 Bt="slash-menu",Nt="prompt-mirror";function Ke(t){let e=document.getElementById(Bt),n=document.getElementById(Nt);if(!e||!n)return;let r;return r=new K({input:t.input,menu:e,loadCommands:t.loadCommands,onCommandsLoaded:()=>ie(t.input,n,s=>r.knows(s))}),r.wire(),Ze(t.input,n,s=>r.knows(s)),t.input.classList.add("slash-highlight-active"),r.preload(),r}var Dt=/\x1B\][^\x07\x1B\x9C]*(?:\x07|\x1B\\|\x9C)|\x1B[P^_X][^\x1B\x9C]*(?:\x1B\\|\x9C)|\x1B\[[0-?]*[ -/]*[@-~]|\x9B[0-?]*[ -/]*[@-~]|\x1B[6-_]/g;function Qe(t){return t.replace(Dt,"")}function Q(t){return Qe(t)}function ce(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var I=ce();function et(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 Ot=(()=>{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)}}>`)},jt=/^(?:[ \t]*(?:\n|$))+/,Ft=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ut=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,j=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Zt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,pe=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,tt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,nt=f(tt).replace(/bull/g,pe).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(),Kt=f(tt).replace(/bull/g,pe).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(),de=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Qt=/^[^\n]+/,ue=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Gt=f(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ue).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Wt=f(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,pe).getRegex(),J="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",he=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Xt=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",he).replace("tag",J).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),st=f(de).replace("hr",j).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",J).getRegex(),Vt=f(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",st).getRegex(),fe={blockquote:Vt,code:Ft,def:Gt,fences:Ut,heading:Zt,hr:j,html:Xt,lheading:nt,list:Wt,newline:jt,paragraph:st,table:L,text:Qt},Ge=f("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",j).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",J).getRegex(),Jt={...fe,lheading:Kt,table:Ge,paragraph:f(de).replace("hr",j).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ge).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",J).getRegex()},Yt={...fe,html:f(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",he).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(de).replace("hr",j).replace("heading",` *#{1,6} *[^
|
|
6
|
-
]`).replace("lheading",
|
|
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 It=15e3,Pt=500,U=class{constructor(e,n,r){this.sessionId=e;this.token=n;this.handlers=r}sessionId;token;handlers;controller;lastEventId;attempt=0;stopped=!1;start(){this.stopped=!1,this.connect()}stop(){this.stopped=!0,this.controller?.abort(),this.handlers.onStatus?.("closed")}async connect(){if(this.stopped)return;this.handlers.onStatus?.(this.attempt===0?"connecting":"reconnecting");let e=!1;this.controller=new AbortController;let n={authorization:`Bearer ${this.token}`};this.lastEventId!==void 0&&(n["last-event-id"]=this.lastEventId);try{let i=await fetch(`/api/sessions/${encodeURIComponent(this.sessionId)}/stream`,{headers:n,signal:this.controller.signal});if(!i.ok){if(i.status===401||i.status===403||i.status===404){this.stopped=!0;let p=i.status===401?"unauthorized":i.status===403?"forbidden":"not-found";this.handlers.onStatus?.("closed",p);return}throw new Error(`stream failed: ${i.status}`)}if(i.body===null)throw new Error("stream failed: no body");this.attempt=0,this.handlers.onStatus?.("open");let o=i.body.getReader(),c=new TextDecoder,a="";e:for(;;){let{done:p,value:l}=await o.read();if(p)break;a+=c.decode(l,{stream:!0});let{events:u,remainder:h}=qe(a);a=h;for(let b of u){if(b.id!==void 0&&(this.lastEventId=b.id),b.data===void 0)continue;let x;try{x=JSON.parse(b.data)}catch{continue}if(He(x)){e=!0,this.stopped=!0;break e}this.handlers.onEvent(x,{id:b.id})}}}catch{}if(this.stopped){e&&this.handlers.onStatus?.("ended");return}this.attempt+=1;let r=.75+Math.random()*.5,s=Math.min(Pt*2**(this.attempt-1),It)*r;setTimeout(()=>{this.connect()},s)}};var Be=/(?:^|\s)(\/[A-Za-z][A-Za-z0-9_:-]*)/g,Mt=Number.POSITIVE_INFINITY;function De(t){let e=new Map;for(let n=0;n<t.length;n++){let r=t[n];if(!r)continue;Be.lastIndex=0;let s;for(;(s=Be.exec(r))!==null;){let i=s[1]?.toLowerCase();i!==void 0&&!e.has(i)&&e.set(i,n)}}return e}function Ne(t,e){let n=t.startsWith("/")?t.toLowerCase():`/${t.toLowerCase()}`;return e.get(n)??Mt}function Oe(t,e,n){let r=Ne(t,n),s=Ne(e,n);return r!==s?r-s:t.localeCompare(e)}var _t=20;function zt(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 je(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)&&zt(r,l.key)),a=De(n),p=(l,u)=>Oe(l.cand.value,u.cand.value,a);return i.sort(p),c.sort(p),[...i,...c].map(l=>l.cand).slice(0,_t)}function Z(t){t.dispatchEvent(new Event("input"))}var Fe=new Set(["/clear","/compact","/editor","/exit","/fast","/font-size","/fork","/keys","/model","/reauth","/resume","/rewind","/sh","/theme","/thinking"]);function Ue(t,e,n,r){let s=document.createElement("div");s.id=e,s.setAttribute("role","option"),s.setAttribute("aria-selected",String(n)),s.className=n?"slash-row is-selected":"slash-row";let i=document.createElement("span");if(i.className="slash-name",i.textContent=t.value,s.appendChild(i),Fe.has(t.value)){let o=document.createElement("span");o.className="slash-badge",o.textContent="REPL only",o.title="Drives terminal-only machinery; cannot act in the browser.",s.appendChild(o)}if(t.summary!==void 0&&t.summary!==""){let o=document.createElement("span");o.className="slash-summary",o.textContent=t.summary,s.appendChild(o)}return s.addEventListener("mousedown",o=>{o.button===0&&(o.preventDefault(),r(t))}),s}var Ze=/^\/(?:[A-Za-z][\w:-]*)?$/,K=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(),Z(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(!Ze.test(e)){this.close(!0);return}this.openIntent=!0;let n=++this.generation;if(await this.ensureCommands(),n!==this.generation||!this.openIntent||!this.focused||!Ze.test(this.deps.input.value)){n===this.generation&&this.close();return}let r=this.deps.input.value.slice(1);this.candidates=je(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 Ue(e,this.optionId(n),r,s=>{this.selected=this.candidates.indexOf(s),this.accept()})}};var Ht=/^\/[A-Za-z][\w:-]*$/;function qt(t,e){return t===""?[]:t.split(/(\s+)/).filter(n=>n!=="").map(n=>Ht.test(n)?{text:n,kind:e(n)?"known":"slash"}:{text:n,kind:"plain"})}function Bt(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 ie(t,e,n){Bt(e,qt(t.value,n)),e.scrollTop=t.scrollTop,e.scrollLeft=t.scrollLeft}function Ke(t,e,n){let r=()=>{ie(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 Nt="slash-menu",Dt="prompt-mirror";function Qe(t){let e=document.getElementById(Nt),n=document.getElementById(Dt);if(!e||!n)return;let r;return r=new K({input:t.input,menu:e,loadCommands:t.loadCommands,onCommandsLoaded:()=>ie(t.input,n,s=>r.knows(s))}),r.wire(),Ke(t.input,n,s=>r.knows(s)),t.input.classList.add("slash-highlight-active"),r.preload(),r}var Ot=/\x1B\][^\x07\x1B\x9C]*(?:\x07|\x1B\\|\x9C)|\x1B[P^_X][^\x1B\x9C]*(?:\x1B\\|\x9C)|\x1B\[[0-?]*[ -/]*[@-~]|\x9B[0-?]*[ -/]*[@-~]|\x1B[6-_]/g;function We(t){return t.replace(Ot,"")}function Q(t){return We(t)}function ce(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var I=ce();function tt(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 jt=(()=>{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)}}>`)},Ft=/^(?:[ \t]*(?:\n|$))+/,Ut=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Zt=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,j=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Kt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,pe=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,nt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,st=f(nt).replace(/bull/g,pe).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(),Qt=f(nt).replace(/bull/g,pe).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(),de=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Wt=/^[^\n]+/,ue=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Gt=f(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ue).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Xt=f(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,pe).getRegex(),J="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",he=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Vt=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",he).replace("tag",J).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),rt=f(de).replace("hr",j).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",J).getRegex(),Jt=f(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",rt).getRegex(),fe={blockquote:Jt,code:Ut,def:Gt,fences:Zt,heading:Kt,hr:j,html:Vt,lheading:st,list:Xt,newline:Ft,paragraph:rt,table:L,text:Wt},Ge=f("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",j).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",J).getRegex(),Yt={...fe,lheading:Qt,table:Ge,paragraph:f(de).replace("hr",j).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ge).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",J).getRegex()},en={...fe,html:f(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",he).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(de).replace("hr",j).replace("heading",` *#{1,6} *[^
|
|
6
|
+
]`).replace("lheading",st).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},tn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,nn=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,it=/^( {2,}|\\)\n(?!\s*$)/,sn=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,z=/[\p{P}\p{S}]/u,Y=/[\s\p{P}\p{S}]/u,ge=/[^\s\p{P}\p{S}]/u,rn=f(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Y).getRegex(),ot=/(?!~)[\p{P}\p{S}]/u,on=/(?!~)[\s\p{P}\p{S}]/u,an=/(?:[^\s\p{P}\p{S}]|~)/u,ln=f(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",jt?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),at=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,cn=f(at,"u").replace(/punct/g,z).getRegex(),pn=f(at,"u").replace(/punct/g,ot).getRegex(),lt="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",dn=f(lt,"gu").replace(/notPunctSpace/g,ge).replace(/punctSpace/g,Y).replace(/punct/g,z).getRegex(),un=f(lt,"gu").replace(/notPunctSpace/g,an).replace(/punctSpace/g,on).replace(/punct/g,ot).getRegex(),hn=f("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,ge).replace(/punctSpace/g,Y).replace(/punct/g,z).getRegex(),fn=f(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,z).getRegex(),gn="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",mn=f(gn,"gu").replace(/notPunctSpace/g,ge).replace(/punctSpace/g,Y).replace(/punct/g,z).getRegex(),kn=f(/\\(punct)/,"gu").replace(/punct/g,z).getRegex(),xn=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(),bn=f(he).replace("(?:-->|$)","-->").getRegex(),wn=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",bn).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),G=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,yn=f(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",G).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),ct=f(/^!?\[(label)\]\[(ref)\]/).replace("label",G).replace("ref",ue).getRegex(),pt=f(/^!?\[(ref)\](?:\[\])?/).replace("ref",ue).getRegex(),vn=f("reflink|nolink(?!\\()","g").replace("reflink",ct).replace("nolink",pt).getRegex(),Xe=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,me={_backpedal:L,anyPunctuation:kn,autolink:xn,blockSkip:ln,br:it,code:nn,del:L,delLDelim:L,delRDelim:L,emStrongLDelim:cn,emStrongRDelimAst:dn,emStrongRDelimUnd:hn,escape:tn,link:yn,nolink:pt,punctuation:rn,reflink:ct,reflinkSearch:vn,tag:wn,text:sn,url:L},Tn={...me,link:f(/^!?\[(label)\]\((.*?)\)/).replace("label",G).getRegex(),reflink:f(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",G).getRegex()},oe={...me,emStrongRDelimAst:un,emStrongLDelim:pn,delLDelim:fn,delRDelim:mn,url:f(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Xe).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:f(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Xe).getRegex()},Sn={...oe,br:f(it).replace("{2,}","*").getRegex(),text:f(oe.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},W={normal:fe,gfm:Yt,pedantic:en},N={normal:me,gfm:oe,breaks:Sn,pedantic:Tn},Cn={"&":"&","<":"<",">":">",'"':""","'":"'"},Ve=t=>Cn[t];function S(t,e){if(e){if(w.escapeTest.test(t))return t.replace(w.escapeReplace,Ve)}else if(w.escapeTestNoEncode.test(t))return t.replace(w.escapeReplaceNoEncode,Ve);return t}function Je(t){try{t=encodeURI(t).replace(w.percentDecode,"%")}catch{return null}return t}function Ye(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 En(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 Rn(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 et(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 An(t,e,n){let r=t.match(n.other.indentCodeCompensation);if(r===null)return e;let s=r[1];return e.split(`
|
|
7
7
|
`).map(i=>{let o=i.match(n.other.beginningSpace);if(o===null)return i;let[c]=o;return c.length>=s.length?i.slice(s.length):i}).join(`
|
|
8
8
|
`)}var X=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=
|
|
9
|
+
`)}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],r=An(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
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(`
|
|
@@ -18,16 +18,16 @@ ${l}`:l;let u=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo
|
|
|
18
18
|
`),C=this.blockquote(x);i[i.length-1]=C,r=r.substring(0,r.length-b.raw.length)+C.raw,s=s.substring(0,s.length-b.text.length)+C.text;break}else if(h?.type==="list"){let b=h,x=b.raw+`
|
|
19
19
|
`+n.join(`
|
|
20
20
|
`),C=this.list(x);i[i.length-1]=C,r=r.substring(0,r.length-h.raw.length)+C.raw,s=s.substring(0,s.length-b.raw.length)+C.raw,n=x.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=
|
|
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=Rn(e[2].split(`
|
|
22
22
|
`,1)[0],e[1].length),h=t.split(`
|
|
23
23
|
`,1)[0],b=!u.trim(),x=0;if(this.options.pedantic?(x=2,l=u.trimStart()):b?x=e[1].length+1:(x=u.search(this.rules.other.nonSpaceChar),x=x>4?1:x,l=u.slice(x),x+=e[1].length),b&&this.rules.other.blankLine.test(h)&&(p+=h+`
|
|
24
|
-
`,t=t.substring(h.length+1),a=!0),!a){let C=this.rules.other.nextBulletRegex(x)
|
|
25
|
-
`,1)[0],B;if(h=re,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),B=h):B=h.replace(this.rules.other.tabCharGlobal," ")
|
|
26
|
-
`+B.slice(x);else{if(b||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4
|
|
24
|
+
`,t=t.substring(h.length+1),a=!0),!a){let C=this.rules.other.nextBulletRegex(x),$e=this.rules.other.hrRegex(x),Ie=this.rules.other.fencesBeginRegex(x),Pe=this.rules.other.headingBeginRegex(x),Ct=this.rules.other.htmlBeginRegex(x),Et=this.rules.other.blockquoteBeginRegex(x);for(;t;){let re=t.split(`
|
|
25
|
+
`,1)[0],B;if(h=re,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),B=h):B=h.replace(this.rules.other.tabCharGlobal," "),Ie.test(h)||Pe.test(h)||Ct.test(h)||Et.test(h)||C.test(h)||$e.test(h))break;if(B.search(this.rules.other.nonSpaceChar)>=x||!h.trim())l+=`
|
|
26
|
+
`+B.slice(x);else{if(b||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||Ie.test(u)||Pe.test(u)||$e.test(u))break;l+=`
|
|
27
27
|
`+h}b=!h.trim(),p+=re+`
|
|
28
|
-
`,t=t.substring(re.length+1),u=B.slice(x)}}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=
|
|
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(
|
|
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=
|
|
28
|
+
`,t=t.substring(re.length+1),u=B.slice(x)}}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=Ye(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(Ye(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=En(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)),et(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 et(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 b=u.slice(1,-1);return{type:"em",raw:u,text:b,tokens:this.lexer.inlineTokens(b)}}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 ae{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 X,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:W.normal,inline:N.normal};this.options.pedantic?(n.block=W.pedantic,n.inline=N.pedantic):this.options.gfm&&(n.block=W.gfm,this.options.breaks?n.inline=N.breaks:n.inline=N.gfm),this.tokenizer.rules=n}static get rules(){return{block:W,inline:N}}static lex(e,n){return new ae(n).lex(e)}static lexInline(e,n){return new ae(n).inlineTokens(e)}lex(e){e=e.replace(w.carriageReturn,`
|
|
31
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
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
|
`)?"":`
|
|
@@ -59,6 +59,7 @@ ${this.parser.parse(t)}</blockquote>
|
|
|
59
59
|
`}tablerow({text:t}){return`<tr>
|
|
60
60
|
${t}</tr>
|
|
61
61
|
`}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
|
|
62
|
-
`}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${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=
|
|
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
|
|
64
|
-
|
|
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=Je(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=Je(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)}},ke=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 le{options;renderer;textRenderer;constructor(e){this.options=e||I,this.options.renderer=this.options.renderer||new V,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ke}static parse(e,n){return new le(n).parse(e)}static parseInline(e,n){return new le(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}},Ln=class{defaults=ce();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=v;Renderer=V;TextRenderer=ke;Lexer=y;Tokenizer=X;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 V(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 X(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 Ln;function m(t,e){return $.parse(t,e)}m.options=m.setOptions=function(t){return $.setOptions(t),m.defaults=$.defaults,tt(m.defaults),m};m.getDefaults=ce;m.defaults=I;m.use=function(...t){return $.use(...t),m.defaults=$.defaults,tt(m.defaults),m};m.walkTokens=function(t,e){return $.walkTokens(t,e)};m.parseInline=$.parseInline;m.Parser=v;m.parser=v.parse;m.Renderer=V;m.TextRenderer=ke;m.Lexer=y;m.lexer=y.lex;m.Tokenizer=X;m.Hooks=O;m.parse=m;var xs=m.options,bs=m.setOptions,ws=m.use,ys=m.walkTokens,vs=m.parseInline;var Ts=v.parse,Ss=y.lex;var $n=["http:","https:","mailto:"];function In(t){try{let e=new URL(t);return $n.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=In(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 Pn(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)}xe(r,n.tokens),e.appendChild(r)}return e}function Mn(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 _n(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 xe(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(Mn(n));break;case"list":t.appendChild(Pn(n));break;case"blockquote":{let r=g("blockquote","md-quote");xe(r,n.tokens),t.appendChild(r);break}case"table":t.appendChild(_n(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 dt(t,e="md"){let n=g("div",e);try{xe(n,new y().lex(t))}catch{n.textContent=t}return n}var ut=2e3;function d(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!==void 0&&(r.textContent=n),r}function zn(t){if(!t)return;let e=t.split("/").filter(Boolean);return e.length>0?e[e.length-1]:void 0}function Hn(t){return(t.title??"").replace(/^\s*\[[^\]]{0,80}\]\s*/,"").trim()||t.title||t.id.slice(0,8)}function we(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",Hn(s));i.appendChild(o);let c=d("span","session-meta"),a=zn(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",On(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 ye(t,e){t.textContent="";for(let n of e)t.appendChild(qn(n))}function qn(t){switch(t.kind){case"user":{let e=d("div","msg msg-user");return e.appendChild(d("div","msg-role","you")),e.appendChild(d("div","msg-body",t.text)),e}case"assistant":{let e=d("div","msg msg-assistant");e.appendChild(d("div","msg-role","agent"));let n=d("div","msg-body md-body");return n.appendChild(dt(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 Bn(t)}}function Bn(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",Dn(t.name,t.inputPreview))),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",Q(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=Q(t.output);if(s.length>ut){let i=d("pre","tool-pre",s.slice(0,ut));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(Nn(Q(String(t.diff))))),e.appendChild(r),e}function be(t,e){let n=t.replace(/\s+/g," ").trim();return n.length<=e?n:`${n.slice(0,e-1)}\u2026`}function Nn(t){let e=d("pre","tool-pre tool-diff");for(let n of t.split(`
|
|
64
|
+
`)){let r=document.createElement("span");r.textContent=n,r.className=n.startsWith("+++")||n.startsWith("---")?"diff-ctx":n.startsWith("+")?"diff-add":n.startsWith("-")?"diff-del":n.startsWith("@@")?"diff-hunk":"diff-ctx",e.appendChild(r)}return e}function Dn(t,e){try{let n=JSON.parse(e);if((t==="bash"||t==="shell")&&typeof n.command=="string")return be(n.command,80);if((t==="edit_file"||t==="write_file"||t==="read_file")&&typeof n.file_path=="string")return n.file_path;if(t==="agent"&&typeof n.prompt=="string")return be(n.prompt,60);if((t==="grep"||t==="glob")&&typeof n.pattern=="string")return n.pattern}catch{}return be(e,90)}function On(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 ve(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",b=>{b.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 ht=0;function R(t){return ht+=1,`${t}_${ht}`}function P(t){return typeof t=="string"?t:void 0}function ft(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(`
|
|
65
|
+
`,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 gt(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 Te(t,e){return Number.isInteger(e)&&e>=0&&e<t.length}function mt(t,e){if(!Te(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 kt(t,e){if(!Te(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 xt(t,e){if(!Te(t,e))return t.slice();let n=t.slice();return n.splice(e,1),n}var ee=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="",Z(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=mt(this.queue,r)}],["\u2193",()=>{this.queue=kt(this.queue,r)}],["\u2715",()=>{this.queue=xt(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 bt(t,e=80){return t.scrollHeight-t.scrollTop-t.clientHeight<=e}var vt=ze(),H=[],E,te=[],A={costUsd:0,durationMs:0,turns:0},Se,M=[],Ce,q=!1,F=!1;function k(t){let e=document.getElementById(t);if(!e)throw new Error(`missing #${t}`);return e}var Ee;function Re(){return Ee||(Ee=new ee({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:Le,isTurnActive:()=>q,onAccepted:()=>{q=!0,ne()},onError:t=>{k("status").textContent=t}})),Ee}async function _(t,e){let n=await fetch(t,{...e,headers:{authorization:`Bearer ${vt}`,"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 jn(t){t.scrollTop=t.scrollHeight}function Fn(){return H.find(t=>t.id===E)}function Le(){return Fn()?.mode==="live"}async function Ae(){if(H=(await _("/api/sessions")).sessions,E===void 0&&H.length>0){let e=H[0];e&&se(e.id)}we(k("sessions"),H,E,se)}function se(t){E=t,te=[],Re().clear(),A={costUsd:0,durationMs:0,turns:0},Se?.stop(),q=!1,F=!1,we(k("sessions"),H,E,se),ye(k("transcript"),te),wt(),ne(),Se=new U(t,vt,{onEvent:e=>{let r=e.record;if(!r)return;(r.kind==="done"||r.kind==="error")&&(q=!1,ne(),Re().flush());let s=ft(r);if(A=gt(A,r),s){te.push(s);let i=bt(k("transcript"));ye(k("transcript"),te),i&&jn(k("transcript"))}Tt()},onStatus:e=>{let n=k("status");n.textContent=e==="ended"?"session ended":e,n.className=`status status-${e}`,e==="ended"&&(q=!1),F=e==="reconnecting"||e==="connecting",wt(),ne()}}),Se.start()}function Tt(){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 wt(){let t=Le(),e=k("prompt"),n=k("send"),r=!t||F;e.disabled=r,n.disabled=r,e.placeholder=t?F?"Reconnecting\u2026":"Message the agent\u2026 (queues while it works)":"Read-only \u2014 this session runs in another process",k("composer").classList.toggle("is-readonly",!t),k("composer").classList.toggle("is-reconnecting",t&&F)}function ne(){k("stop").hidden=!(q&&Le())}async function Un(){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 Ae(),se(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 yt(){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&&ve(k("approvals"),M,St)}function St(t,e){M=M.filter(n=>n.id!==t),ve(k("approvals"),M,St),_("/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 Zn(){if(E===void 0)return;let t=k("stop");t.disabled=!0,t.textContent="Stopping\u2026";try{await _(`/api/sessions/${encodeURIComponent(E)}/interrupt`,{method:"POST",body:JSON.stringify({})})}catch(e){throw t.disabled=!1,t.textContent="Stop",e}}async function Kn(){Qe({input:k("prompt"),loadCommands:async()=>(await _("/api/commands")).commands}),Re().wire(),k("new-session").addEventListener("click",()=>{Un()}),k("stop").addEventListener("click",()=>{Zn().catch(t=>{k("status").textContent=t instanceof Error?t.message:"stop failed"})}),Tt(),await Ae(),setInterval(()=>{Ae().catch(()=>{})},1e4),Ce=setInterval(()=>{yt().catch(()=>{})},1e3),yt().catch(()=>{}),window.addEventListener("beforeunload",()=>{Ce&&clearInterval(Ce)})}Kn().catch(t=>{k("status").textContent=t instanceof Error?t.message:String(t)});
|
|
@@ -209,8 +209,22 @@ html, body {
|
|
|
209
209
|
cursor: pointer; font-family: var(--mono); font-size: 12px; list-style: none;
|
|
210
210
|
}
|
|
211
211
|
.tool-summary::-webkit-details-marker { display: none; }
|
|
212
|
+
.tool-summary::before {
|
|
213
|
+
content: '›';
|
|
214
|
+
display: inline-block;
|
|
215
|
+
font-size: 14px;
|
|
216
|
+
color: var(--text-faint);
|
|
217
|
+
transition: transform 0.15s ease;
|
|
218
|
+
margin-right: 4px;
|
|
219
|
+
flex: 0 0 auto;
|
|
220
|
+
}
|
|
221
|
+
details[open] > .tool-summary::before { transform: rotate(90deg); }
|
|
212
222
|
.tool-dot { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 6px; }
|
|
213
|
-
|
|
223
|
+
@keyframes afk-pulse {
|
|
224
|
+
0%, 100% { opacity: 1; }
|
|
225
|
+
50% { opacity: 0.35; }
|
|
226
|
+
}
|
|
227
|
+
.tool-dot-running { background: var(--warning); animation: afk-pulse 1.4s ease-in-out infinite; }
|
|
214
228
|
.tool-dot-ok { background: var(--success); }
|
|
215
229
|
.tool-dot-error { background: var(--error); }
|
|
216
230
|
.tool-name { color: var(--accent); }
|
|
@@ -240,6 +254,10 @@ html, body {
|
|
|
240
254
|
cursor: pointer; font-family: var(--mono); font-size: 11px;
|
|
241
255
|
}
|
|
242
256
|
.tool-more:hover { color: var(--text); border-color: var(--accent); }
|
|
257
|
+
.diff-add { color: var(--success); background: color-mix(in srgb, var(--success) 8%, transparent); display: block; }
|
|
258
|
+
.diff-del { color: var(--error); background: color-mix(in srgb, var(--error) 8%, transparent); display: block; }
|
|
259
|
+
.diff-hunk { color: var(--accent); opacity: 0.75; display: block; }
|
|
260
|
+
.diff-ctx { color: var(--text-dim); display: block; }
|
|
243
261
|
|
|
244
262
|
/* ── composer ────────────────────────────────────────────────────────────── */
|
|
245
263
|
.composer { border-top: 1px solid var(--border); background: var(--bg-raised); padding: 12px 20px; position: relative; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-afk",
|
|
3
|
-
"version": "5.145.
|
|
3
|
+
"version": "5.145.1",
|
|
4
4
|
"description": "Open-source coding-agent harness you can actually change — own the loop (prompts, gates, routing, skills, terminal states), use any model, run long tasks while you're away.",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|