@aparte/n8n-chat 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +207 -2
- package/dist/cdn/chunks/chunk-MU6PIUJC.js +206 -0
- package/dist/cdn/chunks/chunk-MU6PIUJC.js.map +7 -0
- package/dist/cdn/chunks/chunk-XAWE4EAK.js +2 -0
- package/dist/cdn/chunks/chunk-XAWE4EAK.js.map +7 -0
- package/dist/cdn/chunks/de-WJNL5YNK.js +2 -0
- package/dist/cdn/chunks/de-WJNL5YNK.js.map +7 -0
- package/dist/cdn/chunks/es-DV5N3CXP.js +2 -0
- package/dist/cdn/chunks/es-DV5N3CXP.js.map +7 -0
- package/dist/cdn/chunks/fr-YU75PBOR.js +2 -0
- package/dist/cdn/chunks/fr-YU75PBOR.js.map +7 -0
- package/dist/cdn/chunks/highlight-HDJ3ROJ4.js +153 -0
- package/dist/cdn/chunks/highlight-HDJ3ROJ4.js.map +7 -0
- package/dist/cdn/chunks/it-DZTHWNO3.js +2 -0
- package/dist/cdn/chunks/it-DZTHWNO3.js.map +7 -0
- package/dist/cdn/chunks/ja-QO442LBN.js +2 -0
- package/dist/cdn/chunks/ja-QO442LBN.js.map +7 -0
- package/dist/cdn/chunks/ko-EGFZJCXQ.js +2 -0
- package/dist/cdn/chunks/ko-EGFZJCXQ.js.map +7 -0
- package/dist/cdn/chunks/pt-BR-526LHI67.js +2 -0
- package/dist/cdn/chunks/pt-BR-526LHI67.js.map +7 -0
- package/dist/cdn/chunks/ru-5WNEMKNP.js +2 -0
- package/dist/cdn/chunks/ru-5WNEMKNP.js.map +7 -0
- package/dist/cdn/chunks/zh-CN-ABSHNLG6.js +2 -0
- package/dist/cdn/chunks/zh-CN-ABSHNLG6.js.map +7 -0
- package/dist/cdn/n8n-chat.js +97 -0
- package/dist/cdn/n8n-chat.js.map +7 -0
- package/dist/create-chat.d.ts +187 -0
- package/dist/highlight-DDyMJYBk.js +29 -0
- package/dist/highlight-DDyMJYBk.js.map +1 -0
- package/dist/highlight.d.ts +2 -0
- package/dist/icons.d.ts +7 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +593 -0
- package/dist/index.js.map +1 -0
- package/dist/strings.d.ts +40 -0
- package/dist/style.css +370 -0
- package/dist/theme.css +368 -0
- package/package.json +81 -5
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import{a as $,b as O,c as ie,d as dt,e as ft,f as Ee,g as gt,h as mt,i as kt}from"./chunks/chunk-MU6PIUJC.js";import"./chunks/chunk-XAWE4EAK.js";function qe(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var le=qe();function vt(e){le=e}var ae={exec:()=>null};function fe(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),s=t[r];return s||(s=e(r),t[r]=s),s}}function w(e,t=""){let n=typeof e=="string"?e:e.source,r={replace:(s,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(L.caret,"$1"),n=n.replace(s,a),r},getRegex:()=>new RegExp(n,t)};return r}var xn=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),L={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:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:fe(e=>new RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:fe(e=>new RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:fe(e=>new RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:fe(e=>new RegExp(`^ {0,${e}}#`)),htmlBeginRegex:fe(e=>new RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:fe(e=>new RegExp(`^ {0,${e}}>`))},yn=/^(?:[ \t]*(?:\n|$))+/,Sn=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Rn=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,ye=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,En=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,je=/ {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+|$)/,It=w(Tt).replace(/bull/g,je).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(),vn=w(Tt).replace(/bull/g,je).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Ke=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Tn=/^[^\n]+/,Fe=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,In=w(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Fe).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),$n=w(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,je).getRegex(),Ae="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",We=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,An=w("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n+|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n+|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n+|$)|</?(tag)(?: +|\\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",We).replace("tag",Ae).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),$t=e=>w(Ke).replace("hr",ye).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",e).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Ae).getRegex(),Cn=$t(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),_n=$t(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/),On=w(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",_n).getRegex(),Ge={blockquote:On,code:Sn,def:In,fences:Rn,heading:En,hr:ye,html:An,lheading:It,list:$n,newline:yn,paragraph:Cn,table:ae,text:Tn},bt=w("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ye).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",Ae).getRegex(),Ln={...Ge,lheading:vn,table:bt,paragraph:w(Ke).replace("hr",ye).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",bt).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Ae).getRegex()},Pn={...Ge,html:w(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",We).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:ae,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:w(Ke).replace("hr",ye).replace("heading",` *#{1,6} *[^
|
|
2
|
+
]`).replace("lheading",It).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Nn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Mn=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,At=/^( {2,}|\\)\n(?!\s*$)/,Bn=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,ge=/[\p{P}\p{S}]/u,Ce=/[\s\p{P}\p{S}]/u,Ze=/[^\s\p{P}\p{S}]/u,Dn=w(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Ce).getRegex(),Ct=/(?!~)[\p{P}\p{S}]/u,zn=/(?!~)[\s\p{P}\p{S}]/u,Un=/(?:[^\s\p{P}\p{S}]|~)/u,Hn=w(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",xn?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),_t=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,qn=w(_t,"u").replace(/punct/g,ge).getRegex(),jn=w(_t,"u").replace(/punct/g,Ct).getRegex(),Ot="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Kn=w(Ot,"gu").replace(/notPunctSpace/g,Ze).replace(/punctSpace/g,Ce).replace(/punct/g,ge).getRegex(),Fn=w(Ot,"gu").replace(/notPunctSpace/g,Un).replace(/punctSpace/g,zn).replace(/punct/g,Ct).getRegex(),Wn=w("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Ze).replace(/punctSpace/g,Ce).replace(/punct/g,ge).getRegex(),Gn=w(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,ge).getRegex(),Zn="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Vn=w(Zn,"gu").replace(/notPunctSpace/g,Ze).replace(/punctSpace/g,Ce).replace(/punct/g,ge).getRegex(),Qn=w(/\\(punct)/,"gu").replace(/punct/g,ge).getRegex(),Jn=w(/^<(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(),Xn=w(We).replace("(?:-->|$)","-->").getRegex(),Yn=w("^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",Xn).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Te=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,er=w(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Te).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Lt=w(/^!?\[(label)\]\[(ref)\]/).replace("label",Te).replace("ref",Fe).getRegex(),Pt=w(/^!?\[(ref)\](?:\[\])?/).replace("ref",Fe).getRegex(),tr=w("reflink|nolink(?!\\()","g").replace("reflink",Lt).replace("nolink",Pt).getRegex(),wt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Ve={_backpedal:ae,anyPunctuation:Qn,autolink:Jn,blockSkip:Hn,br:At,code:Mn,del:ae,delLDelim:ae,delRDelim:ae,emStrongLDelim:qn,emStrongRDelimAst:Kn,emStrongRDelimUnd:Wn,escape:Nn,link:er,nolink:Pt,punctuation:Dn,reflink:Lt,reflinkSearch:tr,tag:Yn,text:Bn,url:ae},nr={...Ve,link:w(/^!?\[(label)\]\((.*?)\)/).replace("label",Te).getRegex(),reflink:w(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Te).getRegex()},ze={...Ve,emStrongRDelimAst:Fn,emStrongLDelim:jn,delLDelim:Gn,delRDelim:Vn,url:w(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",wt).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:w(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",wt).getRegex()},rr={...ze,br:w(At).replace("{2,}","*").getRegex(),text:w(ze.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},ve={normal:Ge,gfm:Ln,pedantic:Pn},we={normal:Ve,gfm:ze,breaks:rr,pedantic:nr},sr={"&":"&","<":"<",">":">",'"':""","'":"'"},xt=e=>sr[e];function G(e,t){if(t){if(L.escapeTest.test(e))return e.replace(L.escapeReplace,xt)}else if(L.escapeTestNoEncode.test(e))return e.replace(L.escapeReplaceNoEncode,xt);return e}function yt(e){try{e=encodeURI(e).replace(L.percentDecode,"%")}catch{return null}return e}function St(e,t){let n=e.replace(L.findPipe,(i,a,o)=>{let c=!1,l=a;for(;--l>=0&&o[l]==="\\";)c=!c;return c?"|":" |"}),r=n.split(L.splitPipe),s=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;s<r.length;s++)r[s]=r[s].trim().replace(L.slashPipe,"|");return r}function Y(e,t,n){let r=e.length;if(r===0)return"";let s=0;for(;s<r;){let i=e.charAt(r-s-1);if(i===t&&!n)s++;else if(i!==t&&n)s++;else break}return e.slice(0,r-s)}function Rt(e){let t=e.split(`
|
|
3
|
+
`),n=t.length-1;for(;n>=0&&L.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
|
|
4
|
+
`)}function ir(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]==="\\")r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function ar(e,t=0){let n=t,r="";for(let s of e)if(s===" "){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=s,n++;return r}function Et(e,t,n,r,s){let i=t.href,a=t.title||null,o=e[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;let c={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:a,text:o,tokens:r.inlineTokens(o)};return r.state.inLink=!1,c}function or(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let s=r[1];return t.split(`
|
|
5
|
+
`).map(i=>{let a=i.match(n.other.beginningSpace);if(a===null)return i;let[o]=a;return o.length>=s.length?i.slice(s.length):i}).join(`
|
|
6
|
+
`)}var Ie=class{options;rules;lexer;constructor(e){this.options=e||le}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=this.options.pedantic?t[0]:Rt(t[0]),r=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:r}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],r=or(n,t[3]||"",this.rules);return{type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:r}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let r=Y(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:Y(t[0],`
|
|
7
|
+
`),depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:Y(t[0],`
|
|
8
|
+
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=Y(t[0],`
|
|
9
|
+
`).split(`
|
|
10
|
+
`),r="",s="",i=[];for(;n.length>0;){let a=!1,o=[],c;for(c=0;c<n.length;c++)if(this.rules.other.blockquoteStart.test(n[c]))o.push(n[c]),a=!0;else if(!a)o.push(n[c]);else break;n=n.slice(c);let l=o.join(`
|
|
11
|
+
`),h=l.replace(this.rules.other.blockquoteSetextReplace,`
|
|
12
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
|
|
13
|
+
${l}`:l,s=s?`${s}
|
|
14
|
+
${h}`:h;let u=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(h,i,!0),this.lexer.state.top=u,n.length===0)break;let d=i.at(-1);if(d?.type==="code")break;if(d?.type==="blockquote"){let k=d,m=k.raw+`
|
|
15
|
+
`+n.join(`
|
|
16
|
+
`),T=this.blockquote(m);i[i.length-1]=T,r=r.substring(0,r.length-k.raw.length)+T.raw,s=s.substring(0,s.length-k.text.length)+T.text;break}else if(d?.type==="list"){let k=d,m=k.raw+`
|
|
17
|
+
`+n.join(`
|
|
18
|
+
`),T=this.list(m);i[i.length-1]=T,r=r.substring(0,r.length-d.raw.length)+T.raw,s=s.substring(0,s.length-k.raw.length)+T.raw,n=m.substring(i.at(-1).raw.length).split(`
|
|
19
|
+
`);continue}}return{type:"blockquote",raw:r,tokens:i,text:s}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[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),a=!1;for(;e;){let c=!1,l="",h="";if(!(t=i.exec(e))||this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let u=ar(t[2].split(`
|
|
20
|
+
`,1)[0],t[1].length),d=e.split(`
|
|
21
|
+
`,1)[0],k=!u.trim(),m=0;if(this.options.pedantic?(m=2,h=u.trimStart()):k?m=t[1].length+1:(m=u.search(this.rules.other.nonSpaceChar),m=m>4?1:m,h=u.slice(m),m+=t[1].length),k&&this.rules.other.blankLine.test(d)&&(l+=d+`
|
|
22
|
+
`,e=e.substring(d.length+1),c=!0),!c){let T=this.rules.other.nextBulletRegex(m),b=this.rules.other.hrRegex(m),x=this.rules.other.fencesBeginRegex(m),v=this.rules.other.headingBeginRegex(m),z=this.rules.other.htmlBeginRegex(m),U=this.rules.other.blockquoteBeginRegex(m);for(;e;){let C=e.split(`
|
|
23
|
+
`,1)[0],y;if(d=C,this.options.pedantic?(d=d.replace(this.rules.other.listReplaceNesting," "),y=d):y=d.replace(this.rules.other.tabCharGlobal," "),x.test(d)||v.test(d)||z.test(d)||U.test(d)||T.test(d)||b.test(d))break;if(y.search(this.rules.other.nonSpaceChar)>=m||!d.trim())h+=`
|
|
24
|
+
`+y.slice(m);else{if(k||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||x.test(u)||v.test(u)||b.test(u))break;h+=`
|
|
25
|
+
`+d}k=!d.trim(),l+=C+`
|
|
26
|
+
`,e=e.substring(C.length+1),u=y.slice(m)}}s.loose||(a?s.loose=!0:this.rules.other.doubleBlankLine.test(l)&&(a=!0)),s.items.push({type:"list_item",raw:l,task:!!this.options.gfm&&this.rules.other.listIsTask.test(h),loose:!1,text:h,tokens:[]}),s.raw+=l}let o=s.items.at(-1);if(o)o.raw=o.raw.trimEnd(),o.text=o.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let c of s.items){this.lexer.state.top=!1,c.tokens=this.lexer.blockTokens(c.text,[]);let l=c.tokens[0];if(c.task&&(l?.type==="text"||l?.type==="paragraph")){c.text=c.text.replace(this.rules.other.listReplaceTask,""),l.raw=l.raw.replace(this.rules.other.listReplaceTask,""),l.text=l.text.replace(this.rules.other.listReplaceTask,"");for(let u=this.lexer.inlineQueue.length-1;u>=0;u--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[u].src)){this.lexer.inlineQueue[u].src=this.lexer.inlineQueue[u].src.replace(this.rules.other.listReplaceTask,"");break}let h=this.rules.other.listTaskCheckbox.exec(c.raw);if(h){let u={type:"checkbox",raw:h[0]+" ",checked:h[0]!=="[ ]"};c.checked=u.checked,s.loose?c.tokens[0]&&["paragraph","text"].includes(c.tokens[0].type)&&"tokens"in c.tokens[0]&&c.tokens[0].tokens?(c.tokens[0].raw=u.raw+c.tokens[0].raw,c.tokens[0].text=u.raw+c.tokens[0].text,c.tokens[0].tokens.unshift(u)):c.tokens.unshift({type:"paragraph",raw:u.raw,text:u.raw,tokens:[u]}):c.tokens.unshift(u)}}else c.task&&(c.task=!1);if(!s.loose){let h=c.tokens.filter(d=>d.type==="space"),u=h.length>0&&h.some(d=>this.rules.other.anyLine.test(d.raw));s.loose=u}}if(s.loose)for(let c of s.items){c.loose=!0;for(let l of c.tokens)l.type==="text"&&(l.type="paragraph")}return s}}html(e){let t=this.rules.block.html.exec(e);if(t){let n=Rt(t[0]);return{type:"html",block:!0,raw:n,pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:n}}}def(e){let t=this.rules.block.def.exec(e);if(t){let n=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:Y(t[0],`
|
|
27
|
+
`),href:r,title:s}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=St(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
28
|
+
`):[],i={type:"table",raw:Y(t[0],`
|
|
29
|
+
`),header:[],align:[],rows:[]};if(n.length===r.length){for(let a of r)this.rules.other.tableAlignRight.test(a)?i.align.push("right"):this.rules.other.tableAlignCenter.test(a)?i.align.push("center"):this.rules.other.tableAlignLeft.test(a)?i.align.push("left"):i.align.push(null);for(let a=0;a<n.length;a++)i.header.push({text:n[a],tokens:this.lexer.inline(n[a]),header:!0,align:i.align[a]});for(let a of s)i.rows.push(St(a,i.header.length).map((o,c)=>({text:o,tokens:this.lexer.inline(o),header:!1,align:i.align[c]})));return i}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let n=t[1].trim();return{type:"heading",raw:Y(t[0],`
|
|
30
|
+
`),depth:t[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
|
|
31
|
+
`?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let n=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let i=Y(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=ir(t[2],"()");if(i===-2)return;if(i>-1){let a=(t[0].indexOf("!")===0?5:4)+t[1].length+i;t[2]=t[2].substring(0,i),t[0]=t[0].substring(0,a).trim(),t[3]=""}}let r=t[2],s="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],s=i[3])}else s=t[3]?t[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(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=t[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(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);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,a,o=s,c=0,l=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+s);(r=l.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}else if((r[5]||r[6])&&s%3&&!((s+a)%3)){c+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+c);let h=[...r[0]][0].length,u=e.slice(0,s+r.index+h+a);if(Math.min(s,a)%2){let k=u.slice(1,-1);return{type:"em",raw:u,text:k,tokens:this.lexer.inlineTokens(k)}}let d=u.slice(2,-2);return{type:"strong",raw:u,text:d,tokens:this.lexer.inlineTokens(d)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[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:t[0],text:n}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e,t,n=""){let r=this.rules.inline.delLDelim.exec(e);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,a,o=s,c=this.rules.inline.delRDelim;for(c.lastIndex=0,t=t.slice(-1*e.length+s);(r=c.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(a=[...i].length,a!==s))continue;if(r[3]||r[4]){o+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o);let l=[...r[0]][0].length,h=e.slice(0,s+r.index+l+a),u=h.slice(s,-s);return{type:"del",raw:h,text:u,tokens:this.lexer.inlineTokens(u)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let n,r;return t[2]==="@"?(n=t[1],r="mailto:"+n):(n=t[1],r=n),{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let n,r;if(t[2]==="@")n=t[0],r="mailto:"+n;else{let s;do s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(s!==t[0]);n=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:n}}}},j=class Ue{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||le,this.options.tokenizer=this.options.tokenizer||new Ie,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:L,block:ve.normal,inline:we.normal};this.options.pedantic?(n.block=ve.pedantic,n.inline=we.pedantic):this.options.gfm&&(n.block=ve.gfm,this.options.breaks?n.inline=we.breaks:n.inline=we.gfm),this.tokenizer.rules=n}static get rules(){return{block:ve,inline:we}}static lex(t,n){return new Ue(n).lex(t)}static lexInline(t,n){return new Ue(n).inlineTokens(t)}lex(t){t=t.replace(L.carriageReturn,`
|
|
32
|
+
`),this.blockTokens(t,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(t,n=[],r=!1){this.tokenizer.lexer=this,this.options.pedantic&&(t=t.replace(L.tabCharGlobal," ").replace(L.spaceLine,""));let s=1/0;for(;t;){if(t.length<s)s=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(o=>(i=o.call({lexer:this},t,n))?(t=t.substring(i.raw.length),n.push(i),!0):!1))continue;if(i=this.tokenizer.space(t)){t=t.substring(i.raw.length);let o=n.at(-1);i.raw.length===1&&o!==void 0?o.raw+=`
|
|
33
|
+
`:n.push(i);continue}if(i=this.tokenizer.code(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
|
|
34
|
+
`)?"":`
|
|
35
|
+
`)+i.raw,o.text+=`
|
|
36
|
+
`+i.text,this.inlineQueue.at(-1).src=o.text):n.push(i);continue}if(i=this.tokenizer.fences(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.heading(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.hr(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.blockquote(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.list(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.html(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.def(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
|
|
37
|
+
`)?"":`
|
|
38
|
+
`)+i.raw,o.text+=`
|
|
39
|
+
`+i.raw,this.inlineQueue.at(-1).src=o.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},n.push(i));continue}if(i=this.tokenizer.table(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.lheading(t)){t=t.substring(i.raw.length),n.push(i);continue}let a=t;if(this.options.extensions?.startBlock){let o=1/0,c=t.slice(1),l;this.options.extensions.startBlock.forEach(h=>{l=h.call({lexer:this},c),typeof l=="number"&&l>=0&&(o=Math.min(o,l))}),o<1/0&&o>=0&&(a=t.substring(0,o+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let o=n.at(-1);r&&o?.type==="paragraph"?(o.raw+=(o.raw.endsWith(`
|
|
40
|
+
`)?"":`
|
|
41
|
+
`)+i.raw,o.text+=`
|
|
42
|
+
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(i),r=a.length!==t.length,t=t.substring(i.raw.length);continue}if(i=this.tokenizer.text(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="text"?(o.raw+=(o.raw.endsWith(`
|
|
43
|
+
`)?"":`
|
|
44
|
+
`)+i.raw,o.text+=`
|
|
45
|
+
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(i);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){this.tokenizer.lexer=this;let r=t,s=null;if(this.tokens.links){let l=Object.keys(this.tokens.links);if(l.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(r))!==null;)l.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 a=!1,o="",c=1/0;for(;t;){if(t.length<c)c=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}a||(o=""),a=!1;let l;if(this.options.extensions?.inline?.some(u=>(l=u.call({lexer:this},t,n))?(t=t.substring(l.raw.length),n.push(l),!0):!1))continue;if(l=this.tokenizer.escape(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.tag(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.link(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(l.raw.length);let u=n.at(-1);l.type==="text"&&u?.type==="text"?(u.raw+=l.raw,u.text+=l.text):n.push(l);continue}if(l=this.tokenizer.emStrong(t,r,o)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.codespan(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.br(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.del(t,r,o)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.autolink(t)){t=t.substring(l.raw.length),n.push(l);continue}if(!this.state.inLink&&(l=this.tokenizer.url(t))){t=t.substring(l.raw.length),n.push(l);continue}let h=t;if(this.options.extensions?.startInline){let u=1/0,d=t.slice(1),k;this.options.extensions.startInline.forEach(m=>{k=m.call({lexer:this},d),typeof k=="number"&&k>=0&&(u=Math.min(u,k))}),u<1/0&&u>=0&&(h=t.substring(0,u+1))}if(l=this.tokenizer.inlineText(h)){t=t.substring(l.raw.length),l.raw.slice(-1)!=="_"&&(o=l.raw.slice(-1)),a=!0;let u=n.at(-1);u?.type==="text"?(u.raw+=l.raw,u.text+=l.text):n.push(l);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return n}infiniteLoopError(t){let n="Infinite loop on byte: "+t;if(this.options.silent)console.error(n);else throw new Error(n)}},$e=class{options;parser;constructor(e){this.options=e||le}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(L.notSpaceStart)?.[0],s=e.replace(L.endingNewline,"")+`
|
|
46
|
+
`;return r?'<pre><code class="language-'+G(r)+'">'+(n?s:G(s,!0))+`</code></pre>
|
|
47
|
+
`:"<pre><code>"+(n?s:G(s,!0))+`</code></pre>
|
|
48
|
+
`}blockquote({tokens:e}){return`<blockquote>
|
|
49
|
+
${this.parser.parse(e)}</blockquote>
|
|
50
|
+
`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
51
|
+
`}hr(e){return`<hr>
|
|
52
|
+
`}list(e){let t=e.ordered,n=e.start,r="";for(let a=0;a<e.items.length;a++){let o=e.items[a];r+=this.listitem(o)}let s=t?"ol":"ul",i=t&&n!==1?' start="'+n+'"':"";return"<"+s+i+`>
|
|
53
|
+
`+r+"</"+s+`>
|
|
54
|
+
`}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
|
|
55
|
+
`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
|
|
56
|
+
`}table(e){let t="",n="";for(let s=0;s<e.header.length;s++)n+=this.tablecell(e.header[s]);t+=this.tablerow({text:n});let r="";for(let s=0;s<e.rows.length;s++){let i=e.rows[s];n="";for(let a=0;a<i.length;a++)n+=this.tablecell(i[a]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
|
|
57
|
+
<thead>
|
|
58
|
+
`+t+`</thead>
|
|
59
|
+
`+r+`</table>
|
|
60
|
+
`}tablerow({text:e}){return`<tr>
|
|
61
|
+
${e}</tr>
|
|
62
|
+
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
|
63
|
+
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${G(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),s=yt(e);if(s===null)return r;e=s;let i='<a href="'+e+'"';return t&&(i+=' title="'+G(t)+'"'),i+=">"+r+"</a>",i}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let s=yt(e);if(s===null)return G(n);e=s;let i=`<img src="${e}" alt="${G(n)}"`;return t&&(i+=` title="${G(t)}"`),i+=">",i}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:G(e.text)}},Qe=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},K=class He{options;renderer;textRenderer;constructor(t){this.options=t||le,this.options.renderer=this.options.renderer||new $e,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Qe}static parse(t,n){return new He(n).parse(t)}static parseInline(t,n){return new He(n).parseInline(t)}parse(t){this.renderer.parser=this;let n="";for(let r=0;r<t.length;r++){let s=t[r];if(this.options.extensions?.renderers?.[s.type]){let a=s,o=this.options.extensions.renderers[a.type].call({parser:this},a);if(o!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(a.type)){n+=o||"";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 a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return n}parseInline(t,n=this.renderer){this.renderer.parser=this;let r="";for(let s=0;s<t.length;s++){let i=t[s];if(this.options.extensions?.renderers?.[i.type]){let o=this.options.extensions.renderers[i.type].call({parser:this},i);if(o!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){r+=o||"";continue}}let a=i;switch(a.type){case"escape":{r+=n.text(a);break}case"html":{r+=n.html(a);break}case"link":{r+=n.link(a);break}case"image":{r+=n.image(a);break}case"checkbox":{r+=n.checkbox(a);break}case"strong":{r+=n.strong(a);break}case"em":{r+=n.em(a);break}case"codespan":{r+=n.codespan(a);break}case"br":{r+=n.br(a);break}case"del":{r+=n.del(a);break}case"text":{r+=n.text(a);break}default:{let o='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return r}},xe=class{options;block;constructor(e){this.options=e||le}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?j.lex:j.lexInline}provideParser(e=this.block){return e?K.parse:K.parseInline}},Je=class{defaults=qe();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=K;Renderer=$e;TextRenderer=Qe;Lexer=j;Tokenizer=Ie;Hooks=xe;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{let s=r;for(let i of s.header)n=n.concat(this.walkTokens(i.tokens,t));for(let i of s.rows)for(let a of i)n=n.concat(this.walkTokens(a.tokens,t));break}case"list":{let s=r;n=n.concat(this.walkTokens(s.items,t));break}default:{let s=r;this.defaults.extensions?.childTokens?.[s.type]?this.defaults.extensions.childTokens[s.type].forEach(i=>{let a=s[i].flat(1/0);n=n.concat(this.walkTokens(a,t))}):s.tokens&&(n=n.concat(this.walkTokens(s.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.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=t.renderers[s.name];i?t.renderers[s.name]=function(...a){let o=s.renderer.apply(this,a);return o===!1&&(o=i.apply(this,a)),o}:t.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=t[s.level];i?i.unshift(s.tokenizer):t[s.level]=[s.tokenizer],s.start&&(s.level==="block"?t.startBlock?t.startBlock.push(s.start):t.startBlock=[s.start]:s.level==="inline"&&(t.startInline?t.startInline.push(s.start):t.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(t.childTokens[s.name]=s.childTokens)}),r.extensions=t),n.renderer){let s=this.defaults.renderer||new $e(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 a=i,o=n.renderer[a],c=s[a];s[a]=(...l)=>{let h=o.apply(s,l);return h===!1&&(h=c.apply(s,l)),h||""}}r.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new Ie(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 a=i,o=n.tokenizer[a],c=s[a];s[a]=(...l)=>{let h=o.apply(s,l);return h===!1&&(h=c.apply(s,l)),h}}r.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new xe;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 a=i,o=n.hooks[a],c=s[a];xe.passThroughHooks.has(i)?s[a]=l=>{if(this.defaults.async&&xe.passThroughHooksRespectAsync.has(i))return(async()=>{let u=await o.call(s,l);return c.call(s,u)})();let h=o.call(s,l);return c.call(s,h)}:s[a]=(...l)=>{if(this.defaults.async)return(async()=>{let u=await o.apply(s,l);return u===!1&&(u=await c.apply(s,l)),u})();let h=o.apply(s,l);return h===!1&&(h=c.apply(s,l)),h}}r.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(a){let o=[];return o.push(i.call(this,a)),s&&(o=o.concat(s.call(this,a))),o}}this.defaults={...this.defaults,...r}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return j.lex(e,t??this.defaults)}parser(e,t){return K.parse(e,t??this.defaults)}parseMarkdown(e){return(t,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 t>"u"||t===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=e),s.async)return(async()=>{let a=s.hooks?await s.hooks.preprocess(t):t,o=await(s.hooks?await s.hooks.provideLexer(e):e?j.lex:j.lexInline)(a,s),c=s.hooks?await s.hooks.processAllTokens(o):o;s.walkTokens&&await Promise.all(this.walkTokens(c,s.walkTokens));let l=await(s.hooks?await s.hooks.provideParser(e):e?K.parse:K.parseInline)(c,s);return s.hooks?await s.hooks.postprocess(l):l})().catch(i);try{s.hooks&&(t=s.hooks.preprocess(t));let a=(s.hooks?s.hooks.provideLexer(e):e?j.lex:j.lexInline)(t,s);s.hooks&&(a=s.hooks.processAllTokens(a)),s.walkTokens&&this.walkTokens(a,s.walkTokens);let o=(s.hooks?s.hooks.provideParser(e):e?K.parse:K.parseInline)(a,s);return s.hooks&&(o=s.hooks.postprocess(o)),o}catch(a){return i(a)}}}onError(e,t){return n=>{if(n.message+=`
|
|
64
|
+
Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+G(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},oe=new Je;function S(e,t){return oe.parse(e,t)}S.options=S.setOptions=function(e){return oe.setOptions(e),S.defaults=oe.defaults,vt(S.defaults),S};S.getDefaults=qe;S.defaults=le;S.use=function(...e){return oe.use(...e),S.defaults=oe.defaults,vt(S.defaults),S};S.walkTokens=function(e,t){return oe.walkTokens(e,t)};S.parseInline=oe.parseInline;S.Parser=K;S.parser=K.parse;S.Renderer=$e;S.TextRenderer=Qe;S.Lexer=j;S.lexer=j.lex;S.Tokenizer=Ie;S.Hooks=xe;S.parse=S;var _i=S.options,Oi=S.setOptions,Li=S.use,Pi=S.walkTokens,Ni=S.parseInline;var Mi=K.parse,Bi=j.lex;var lr=Object.defineProperty,cr=Object.defineProperties,ur=Object.getOwnPropertyDescriptors,Nt=Object.getOwnPropertySymbols,hr=Object.prototype.hasOwnProperty,pr=Object.prototype.propertyIsEnumerable,Mt=(e,t,n)=>t in e?lr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,qt=(e,t)=>{for(var n in t||(t={}))hr.call(t,n)&&Mt(e,n,t[n]);if(Nt)for(var n of Nt(t))pr.call(t,n)&&Mt(e,n,t[n]);return e},jt=(e,t)=>cr(e,ur(t)),E={PROSE:0,FENCE_MARKER:1,FENCE_INFO:2,FENCE_BODY:3,CODE_SPAN:4,CODE_SPAN_OPEN:5},dr=/^(`{3,}|~{3,})(.*)$/,fr=e=>e!==void 0&&e>="0"&&e<="9",gr=(e,t)=>{let n=t;if(e[n]==="-"||e[n]==="*"||e[n]==="+")n+=1;else{for(;fr(e[n])&&n-t<9;)n+=1;if(n===t||e[n]!=="."&&e[n]!==")")return-1;n+=1}return e[n]===" "?n+1:-1},mr=(e,t,n)=>{let r=0,s=t,i=!1,a=t;for(;;){for(;a<n&&e[a]===" ";)a+=1;if(e[a]===">"){r+=1,a+=e[a+1]===" "?2:1,s=a,i=!1;continue}let o=a<n?gr(e,a):-1;if(o===-1)return{contentStart:a,listIndent:i?a-s:0,quoteDepth:r};a=o,i=!0}},kr=(e,t,n,r)=>{let s=t;for(let i=0;i<r;i+=1){for(;s<n&&e[s]===" ";)s+=1;if(e[s]!==">")return-1;s+=1,e[s]===" "&&(s+=1)}return s},br=(e,t,n,r,s)=>{let i=t+r;e.fill(E.FENCE_MARKER,i,i+s),e.fill(E.FENCE_INFO,i+s,Math.min(n+1,e.length))},wr=(e,t,n,r)=>{let s=t;for(;s<n&&e[s]===" ";)s+=1;let i=0;for(;s<n&&e[s]===r.char;)s+=1,i+=1;if(i<r.length)return!1;for(;s<n;){if(e[s]!==" "&&e[s]!==" "&&e[s]!=="\r")return!1;s+=1}return!0},xr=(e,t,n,r)=>{let s=r>n&&e[r-1]==="\r"?r-1:r,i=mr(e,n,s),a=e.slice(i.contentStart,s).match(dr);if(!a)return null;let[,o,c]=a,l=o[0];return l==="`"&&c.includes("`")?null:(br(t,n,r,i.contentStart-n,o.length),{char:l,length:o.length,listIndent:i.listIndent,quoteDepth:i.quoteDepth})},yr=(e,t,n,r)=>{let s=kr(e,t,n,r.quoteDepth);if(s===-1||r.listIndent===0)return s;let i=s;for(;i<n&&e[i]===" ";)i+=1;return i===n||e[i]==="\r"&&i+1===n||i-s>=r.listIndent?s:-1},Sr=(e,t)=>{let n=e.length,r=null,s=0;for(;s<n;){let i=e.indexOf(`
|
|
65
|
+
`,s);i===-1&&(i=n);let a=r?yr(e,s,i,r):-1;r&&a===-1&&(r=null),r?wr(e,a,i,r)?(t.fill(E.FENCE_MARKER,s,i),r=null):t.fill(E.FENCE_BODY,s,Math.min(i+1,n)):r=xr(e,t,s,i),s=i+1}return r},Bt=(e,t)=>{let n=t+1;for(;n<e.length&&e[n]==="`";)n+=1;return n},Rr=(e,t)=>{let n=t+1;for(;n<e.length&&(e[n]===" "||e[n]===" "||e[n]==="\r");)n+=1;return n<e.length&&e[n]===`
|
|
66
|
+
`},Er=(e,t,n)=>{let r=n;for(;;){let s=e.indexOf("`",r);if(s===-1)return-1;let i=s>r&&e[s-1]==="\\"&&t[s-1]===E.PROSE;if(t[s]===E.PROSE&&!i)return s;r=s+1}},vr=(e,t)=>{let n=e.length,r=-1,s=0,i=0;for(;i<n;){if(r<0){if(i=Er(e,t,i),i===-1)break;let o=Bt(e,i);r=i,s=o-i,i=o;continue}if(t[i]!==E.PROSE){t.fill(E.CODE_SPAN_OPEN,r,i),r=-1,i+=1;continue}if(e[i]===`
|
|
67
|
+
`&&Rr(e,i)){r=-1,i+=1;continue}if(e[i]!=="`"){i+=1;continue}let a=Bt(e,i);a-i===s&&(t.fill(E.CODE_SPAN,r,a),r=-1),i=a}return r>=0?(t.fill(E.CODE_SPAN_OPEN,r,n),{start:r,runLength:s}):null},Tr=e=>{let t=new Uint8Array(e.length),n=Sr(e,t),r=vr(e,t);return{text:e,regions:t,openFence:n,openSpan:r,mathMask:null,linkUrlMask:null,htmlTagMask:null}},Ye=null,_e=null,H=e=>{if(_e!==null&&e===Ye)return _e;let t=Tr(e);return Ye=e,_e=t,t},Ir=()=>{Ye=null,_e=null},$r=(e,t)=>t>=e.regions.length?e.openFence!==null||e.openSpan!==null:t<0?!1:e.regions[t]!==E.PROSE;var Ar=(e,t)=>e.regions[t]===E.CODE_SPAN,et=(e,t)=>{let n=H(e),r=t+t,s=0;for(let i=e.indexOf(r);i!==-1;i=e.indexOf(r,i))n.regions[i]===E.PROSE?(s+=1,i+=2):i+=1;return s},tt=new Uint8Array(0),Cr=e=>e==="inlineLatex"||e==="blockLatex",_r=(e,t)=>t==="["&&e==="none"?"blockLatex":t==="]"&&e==="blockLatex"?"none":t==="("&&e==="none"?"inlineLatex":t===")"&&e==="inlineLatex"?"none":null,Or=(e,t)=>t?e==="blockDollar"?"none":"blockDollar":e==="blockDollar"?e:e==="inlineDollar"?"none":"inlineDollar",Lr=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),Pr=(e,t,n)=>{let r=e[t+1];if(e[t]==="\\"){if(r==="$")return{context:n,length:2};let s=_r(n,r);return s===null?null:{context:s,length:2}}if(e[t]==="$"&&!Cr(n)){let s=r==="$";return{context:Or(n,s),length:s?2:1}}return null},Nr=e=>{let{text:t,regions:n}=e,r=t.length,s=new Uint8Array(r),i="none",a=0;for(;a<r;){s[a]=i==="none"?0:1;let o=n[a]===E.PROSE?Pr(t,a,i):null;if(o===null){a+=1;continue}i=o.context,o.length===2&&(s[a+1]=i==="none"?0:1),a+=o.length}return s},me=(e,t)=>t<0||t>=e.text.length?!1:(e.mathMask===null&&(e.mathMask=Lr(e.text)?Nr(e):tt),e.mathMask[t]===1),Mr=(e,t,n,r)=>{let{text:s,regions:i}=e,a=new Uint8Array(n-t),o=0;for(let l=n-1;l>=t;l-=1)s[l]===")"&&i[l]===E.PROSE&&(o=1),a[l-t]=o;let c=!1;for(let l=t;l<n;l+=1)c&&a[l-t]===1&&(r[l]=1),i[l]===E.PROSE&&(s[l]===")"?c=!1:s[l]==="("&&(c=l>0&&s[l-1]==="]"))},Br=e=>{let{text:t}=e,n=t.length,r=new Uint8Array(n),s=0;for(;s<n;){let i=t.indexOf(`
|
|
68
|
+
`,s);i===-1&&(i=n),Mr(e,s,i,r),s=i+1}return r},nt=(e,t)=>t<0||t>=e.text.length?!1:(e.linkUrlMask===null&&(e.linkUrlMask=e.text.includes("](")?Br(e):tt),e.linkUrlMask[t]===1),Dr=e=>{let{text:t,regions:n}=e,r=t.length,s=new Uint8Array(r),i=!1;for(let a=0;a<r;a+=1){if(t[a]===`
|
|
69
|
+
`){i=!1;continue}if(s[a]=i?1:0,n[a]===E.PROSE){if(t[a]===">")i=!1;else if(t[a]==="<"){let o=t[a+1];i=o!==void 0&&(o>="a"&&o<="z"||o>="A"&&o<="Z"||o==="/")}}}return s},Kt=(e,t)=>t<0||t>=e.text.length?!1:(e.htmlTagMask===null&&(e.htmlTagMask=e.text.includes("<")?Dr(e):tt),e.htmlTagMask[t]===1),N=(e,t)=>$r(H(e),t),ee=(e,t)=>Ar(H(e),t),zr=/^(\s*(?:[-*+]|\d+[.)]) +)>(=?\s*[$]?\d)/gm,Ur=e=>!e||typeof e!="string"||!e.includes(">")?e:e.replace(zr,(t,n,r,s)=>N(e,s)?t:`${n}\\>${r}`),te=(e,{delimiter:t,markerLength:n,regex:r})=>{let s=e.lastIndexOf(t,e.length-2),i=s===-1?e.length-1:s;return e.slice(Math.max(0,i-n+1)).match(r)},Hr={delimiter:"*",markerLength:2,regex:/(\*\*)([^*]*\*?)$/},qr={delimiter:"_",markerLength:2,regex:/(__)([^_]*?)$/},jr={delimiter:"*",markerLength:3,regex:/(\*\*\*)([^*]*?)$/},Kr={delimiter:"*",markerLength:1,regex:/(\*)([^*]*?)$/},Fr={delimiter:"_",markerLength:1,regex:/(_)([^_]*?)$/},Wr={delimiter:"~",markerLength:2,regex:/(~~)([^~]*?)$/},Gr={delimiter:"_",markerLength:2,regex:/(__)([^_]+)_$/},Zr={delimiter:"~",markerLength:2,regex:/(~~)([^~]+)~$/},ce=/^[\s_~*`]*$/,Ft=/^[\s]*[-*+][\s]+$/,Vr=/[\p{L}\p{N}_]/u,Qr=/^\*{4,}$/,F=e=>{if(!e)return!1;let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||t===95?!0:Vr.test(e)};var Jr=(e,t)=>{let n=1;for(let r=t-1;r>=0;r-=1)if(e[r]==="]")n+=1;else if(e[r]==="["&&(n-=1,n===0))return r;return-1},Wt=(e,t)=>{let n=1;for(let r=t+1;r<e.length;r+=1)if(e[r]==="[")n+=1;else if(e[r]==="]"&&(n-=1,n===0))return r;return-1},Xr=(e,t)=>me(H(e),t);var Pe=(e,t,n)=>{let r=0;for(let c=t-1;c>=0;c-=1)if(e[c]===`
|
|
70
|
+
`){r=c+1;break}let s=e.length;for(let c=t;c<e.length;c+=1)if(e[c]===`
|
|
71
|
+
`){s=c;break}let i=e.substring(r,s),a=0,o=!1;for(let c of i)if(c===n)a+=1;else if(c!==" "&&c!==" "){o=!0;break}return a>=3&&!o},Yr=(e,t,n,r)=>n==="\\"||me(e,t)?!0:n!=="*"&&r==="*"?(t<e.text.length-2?e.text[t+2]:"")!=="*":n==="*"||(!n||n===" "||n===" "||n===`
|
|
72
|
+
`)&&(!r||r===" "||r===" "||r===`
|
|
73
|
+
`),Oe=e=>e===" "||e===" "||e===`
|
|
74
|
+
`,es=(e,t)=>!!(e&&t&&F(e)&&F(t)),ts=(e,t,n,r)=>{let s=es(e,t),i=!!t&&!Oe(t),a=!!e&&!Oe(e);return s&&n%2===0&&!r?{count:!1}:a&&n%2===1||i?{count:!0,inWordAsteriskChain:s}:{count:!1}},Gt=e=>{let t=H(e),n=0,r=!1,s=e.length;for(let i=0;i<s;i+=1){if(e[i]!=="*"||t.regions[i]!==E.PROSE){F(e[i])||(r=!1);continue}let a=i>0?e[i-1]:"",o=i<s-1?e[i+1]:"";if(Yr(t,i,a,o))continue;let c=ts(a,o,n,r);c.count&&(n+=1,r=c.inWordAsteriskChain)}return n},ns=(e,t,n,r)=>!!(n==="\\"||me(e,t)||nt(e,t)||Kt(e,t)||n==="_"||r==="_"||n&&r&&F(n)&&F(r)),rs=e=>{let t=H(e),n=0,r=e.length;for(let s=0;s<r;s+=1){if(e[s]!=="_"||t.regions[s]!==E.PROSE)continue;let i=s>0?e[s-1]:"",a=s<r-1?e[s+1]:"";ns(t,s,i,a)||(n+=1)}return n},ss=e=>{let t=H(e),n=0,r=0;for(let s=0;s<e.length;s+=1)e[s]==="*"&&t.regions[s]===E.PROSE?r+=1:(r>=3&&(n+=Math.floor(r/3)),r=0);return r>=3&&(n+=Math.floor(r/3)),n},rt=e=>et(e,"*"),Dt=e=>e===""||e===" "||e===" "||e===`
|
|
75
|
+
`,is=(e,t,n,r,s)=>{if(!(Dt(n)&&Dt(r)))return!1;if(t>s.lineEnd){let i=e.indexOf(`
|
|
76
|
+
`,t);s.lineEnd=i===-1?e.length:i,s.result=Pe(e,t,"_")}return s.result},as=(e,t,n,r)=>{let s=e.text,i=t,a=!1;i>0&&s[i-1]==="\\"&&(i+=1,a=!0);let o=n-i;if(o<2)return!1;let c=i>0?s[i-1]:"",l=a?"\\":c,h=n<s.length?s[n]:"";return F(l)&&F(h)||is(s,i,l,h,r)||me(e,i)||nt(e,i)||Kt(e,i)?!1:Math.floor(o/2)%2===1},zt=e=>{let t=H(e),n=e.length,r={lineEnd:-1,result:!1},s=!1,i=0;for(;i<n;){if(e[i]!=="_"||t.regions[i]!==E.PROSE){i+=1;continue}let a=i,o=i+1;for(;o<n&&e[o]==="_"&&t.regions[o]===E.PROSE;)o+=1;i=o,as(t,a,o,r)&&(s=!s)}return s},os=(e,t,n)=>{if(!t||ce.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
|
|
77
|
+
`),s=r===-1?0:r+1,i=e.substring(s,n);return Ft.test(i)&&t.includes(`
|
|
78
|
+
`)?!0:Pe(e,n,"*")},ls=e=>{let t=te(e,Hr);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return N(e,r)||ee(e,r)||os(e,n,r)?e:rt(e)%2===1?n.endsWith("*")?`${e}*`:`${e}**`:e},cs=(e,t,n)=>{if(!t||ce.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
|
|
79
|
+
`),s=r===-1?0:r+1,i=e.substring(s,n);return Ft.test(i)&&t.includes(`
|
|
80
|
+
`)?!0:Pe(e,n,"_")},us=e=>{let t=te(e,qr);if(!t){let s=te(e,Gr);if(s){let i=e.lastIndexOf(s[1]);if(!(N(e,i)||ee(e,i))&&zt(e))return`${e}_`}return e}let n=t[2],r=e.lastIndexOf(t[1]);return N(e,r)||ee(e,r)||cs(e,n,r)?e:zt(e)?`${e}__`:e},hs=(e,t)=>{let{text:n}=e;return n[t]==="*"&&e.regions[t]===E.PROSE&&n[t-1]!=="*"&&n[t+1]!=="*"&&n[t-1]!=="\\"&&!me(e,t)},ps=e=>{let t=H(e);for(let n=e.indexOf("*");n!==-1;n=e.indexOf("*",n+1)){if(!hs(t,n))continue;let r=n>0?e[n-1]:"",s=n<e.length-1?e[n+1]:"",i=!r||Oe(r),a=!s||Oe(s);if(!(i&&a)&&!(r&&s&&F(r)&&F(s))&&!a)return n}return-1},ds=e=>{if(!te(e,Kr))return e;let t=ps(e);if(t===-1||N(e,t)||ee(e,t))return e;let n=e.substring(t+1);return!n||ce.test(n)?e:Gt(e)%2===1?`${e}*`:e},Zt=e=>{let t=H(e);for(let n=e.indexOf("_");n!==-1;n=e.indexOf("_",n+1))if(t.regions[n]===E.PROSE&&e[n-1]!=="_"&&e[n+1]!=="_"&&e[n-1]!=="\\"&&!me(t,n)&&!nt(t,n)){let r=n>0?e[n-1]:"",s=n<e.length-1?e[n+1]:"";if(r&&s&&F(r)&&F(s))continue;return n}return-1},fs=e=>{let t=e.length;for(;t>0&&e[t-1]===`
|
|
81
|
+
`;)t-=1;if(t<e.length){let n=e.slice(0,t),r=e.slice(t);return`${n}_${r}`}return`${e}_`},gs=e=>{if(!e.endsWith("**"))return null;let t=e.slice(0,-2);if(rt(t)%2!==1)return null;let n=t.indexOf("**"),r=Zt(t);return n!==-1&&r!==-1&&n<r?`${t}_**`:null},ms=e=>{if(!te(e,Fr))return e;let t=Zt(e);if(t===-1)return e;let n=e.substring(t+1);if(!n||ce.test(n)||N(e,t)||ee(e,t))return e;if(rs(e)%2===1){let r=gs(e);return r!==null?r:fs(e)}return e},ks=e=>{let t=rt(e),n=Gt(e);return t%2===0&&n%2===0},bs=(e,t,n)=>!t||ce.test(t)||N(e,n)||ee(e,n)?!0:Pe(e,n,"*"),ws=e=>{if(Qr.test(e))return e;let t=te(e,jr);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return bs(e,n,r)?e:ss(e)%2===1?ks(e)?e:`${e}***`:e},xs=/<[a-zA-Z/][^>]*$/,ys=/[a-zA-Z/]/,Ss=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),Rs=(e,t)=>{let n=e[t+1];return n!==void 0&&ys.test(n)},Es=e=>{let t=e.match(xs);if(!t||t.index===void 0)return e;let n=Ss(e);for(let r=t.index;r<e.length;r+=1)if(!(e[r]!=="<"||!Rs(e,r))&&!N(e,r)&&!(n&&Xr(e,r)))return e.substring(0,r).trimEnd();return e},vs=e=>{let t=H(e);if(t.openFence)return e;let n=t.openSpan;if(!n)return e;let r=e.slice(n.start+n.runLength);if(!r||ce.test(r))return e;let s=0,i=e.length-1;for(;i>=0&&e[i]==="`";)s+=1,i-=1;return s>=n.runLength?e:e+"`".repeat(n.runLength-s)},Ts=e=>et(e,"$"),Is=e=>{let t=H(e),n=0;for(let r=0;r<e.length;r+=1){if(e[r]==="\\"){r+=1;continue}t.regions[r]===E.PROSE&&e[r]==="$"&&(r+1<e.length&&e[r+1]==="$"?r+=1:n+=1)}return n},$s=e=>{if(e.endsWith("$")&&!e.endsWith("$$"))return`${e}$`;let t=e.indexOf("$$");return t!==-1&&e.indexOf(`
|
|
82
|
+
`,t)!==-1&&!e.endsWith(`
|
|
83
|
+
`)?`${e}
|
|
84
|
+
$$`:`${e}$$`},As=e=>Ts(e)%2===0?e:$s(e),Cs=e=>Is(e)%2===1?`${e}$`:e,Le="streamdown:incomplete-image",_s=(e,t,n)=>{if(e.substring(t+2).includes(")"))return null;let r=Jr(e,t);if(r===-1||N(e,r))return null;let s=r>0&&e[r-1]==="!",i=s?r-1:r,a=e.substring(0,i),o=e.substring(r+1,t);return s?`${a}`:n==="text-only"?`${a}${o}`:`${a}[${o}](streamdown:incomplete-link)`},Ut=(e,t)=>{for(let n=0;n<t;n++)if(e[n]==="["&&!N(e,n)){if(n>0&&e[n-1]==="!")continue;let r=Wt(e,n);if(r===-1)return n;if(r+1<e.length&&e[r+1]==="("){let s=e.indexOf(")",r+2);s!==-1&&(n=s)}}return t},Os=(e,t,n)=>{let r=t>0&&e[t-1]==="!",s=r?t-1:t;if(!e.substring(t+1).includes("]")){let i=e.substring(0,s);if(r){let a=e.substring(t+1);return`${i}`}if(n==="text-only"){let a=Ut(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}if(Wt(e,t)===-1){let i=e.substring(0,s);if(r){let a=e.substring(t+1);return`${i}`}if(n==="text-only"){let a=Ut(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}return null},Ls=(e,t)=>{let n=e.lastIndexOf("](");if(n!==-1&&!N(e,n)){let r=_s(e,n,t);if(r!==null)return r}for(let r=e.lastIndexOf("[");r!==-1;r=r===0?-1:e.lastIndexOf("[",r-1))if(!N(e,r)){let s=Os(e,r,t);if(s!==null)return s}return e},Ps=32,Vt=(e,t="protocol")=>{let n=e;for(let r=0;r<Ps;r+=1){let s=Ls(n,t);if(s.length>=n.length)return s;n=s}return n},Ns=/^-{1,2}$/,Ms=/^[\s]*-{1,2}[\s]+$/,Bs=/^={1,2}$/,Ds=/^[\s]*={1,2}[\s]+$/,zs=e=>{if(!e||typeof e!="string")return e;let t=e.lastIndexOf(`
|
|
85
|
+
`);if(t===-1)return e;let n=e.substring(t+1),r=e.substring(0,t),s=n.trim();if(Ns.test(s)&&!n.match(Ms)){let i=r.split(`
|
|
86
|
+
`).at(-1);if(i&&i.trim().length>0)return`${e}\u200B`}if(Bs.test(s)&&!n.match(Ds)){let i=r.split(`
|
|
87
|
+
`).at(-1);if(i&&i.trim().length>0)return`${e}\u200B`}return e},Us=/([\p{L}\p{N}_])~(?!~)(?=[\p{L}\p{N}_])/gu,Hs=e=>!e||typeof e!="string"||!e.includes("~")?e:e.replace(Us,(t,n,r)=>{let s=r+n.length;return N(e,s)?t:`${n}\\~`}),Ht=e=>et(e,"~"),qs=e=>{let t=te(e,Wr);if(t){let n=t[2];if(!n||ce.test(n))return e;let r=e.lastIndexOf(t[1]);if(N(e,r)||ee(e,r))return e;if(Ht(e)%2===1)return`${e}~~`}else{let n=te(e,Zr);if(n){let r=e.lastIndexOf(n[0].slice(0,2));if(N(e,r)||ee(e,r))return e;if(Ht(e)%2===1)return`${e}~`}}return e},Xe=e=>e!==!1,js=e=>e===!0,P={SINGLE_TILDE:0,COMPARISON_OPERATORS:5,HTML_TAGS:10,SETEXT_HEADINGS:15,LINKS:20,BOLD_ITALIC:30,BOLD:35,ITALIC_DOUBLE_UNDERSCORE:40,ITALIC_SINGLE_ASTERISK:41,ITALIC_SINGLE_UNDERSCORE:42,INLINE_CODE:50,STRIKETHROUGH:60,KATEX:70,INLINE_KATEX:75,DEFAULT:100},Ks=[{handler:{name:"singleTilde",handle:Hs,priority:P.SINGLE_TILDE},optionKey:"singleTilde"},{handler:{name:"comparisonOperators",handle:Ur,priority:P.COMPARISON_OPERATORS},optionKey:"comparisonOperators"},{handler:{name:"htmlTags",handle:Es,priority:P.HTML_TAGS},optionKey:"htmlTags"},{handler:{name:"setextHeadings",handle:zs,priority:P.SETEXT_HEADINGS},optionKey:"setextHeadings"},{handler:{name:"links",handle:Vt,priority:P.LINKS},optionKey:"links",earlyReturn:e=>e.endsWith("](streamdown:incomplete-link)")||e.endsWith(`](${Le})`)},{handler:{name:"boldItalic",handle:ws,priority:P.BOLD_ITALIC},optionKey:"boldItalic"},{handler:{name:"bold",handle:ls,priority:P.BOLD},optionKey:"bold"},{handler:{name:"italicDoubleUnderscore",handle:us,priority:P.ITALIC_DOUBLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"italicSingleAsterisk",handle:ds,priority:P.ITALIC_SINGLE_ASTERISK},optionKey:"italic"},{handler:{name:"italicSingleUnderscore",handle:ms,priority:P.ITALIC_SINGLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"inlineCode",handle:vs,priority:P.INLINE_CODE},optionKey:"inlineCode"},{handler:{name:"strikethrough",handle:qs,priority:P.STRIKETHROUGH},optionKey:"strikethrough"},{handler:{name:"katex",handle:As,priority:P.KATEX},optionKey:"katex"},{handler:{name:"inlineKatex",handle:Cs,priority:P.INLINE_KATEX},optionKey:"inlineKatex"}],Fs=e=>{var t;let n=(t=e?.linkMode)!=null?t:"protocol";return Ks.filter(({handler:r,optionKey:s})=>r.name==="links"?Xe(e?.links)||Xe(e?.images):r.name==="inlineKatex"?js(e?.inlineKatex):Xe(e?.[s])).map(({handler:r,earlyReturn:s})=>r.name==="links"?{handler:jt(qt({},r),{handle:i=>Vt(i,n)}),earlyReturn:n==="protocol"?s:void 0}:{handler:r,earlyReturn:s})},Ws=(e,t)=>{var n;if(!e||typeof e!="string")return e;let r=e.endsWith(" ")&&!e.endsWith(" ")?e.slice(0,-1):e,s=Fs(t),i=((n=t?.handlers)!=null?n:[]).map(o=>{var c;return{handler:jt(qt({},o),{priority:(c=o.priority)!=null?c:P.DEFAULT}),earlyReturn:void 0}}),a=[...s,...i].sort((o,c)=>{var l,h;return((l=o.handler.priority)!=null?l:0)-((h=c.handler.priority)!=null?h:0)});try{for(let{handler:o,earlyReturn:c}of a)if(r=o.handle(r),c!=null&&c(r))return r;return r.endsWith(" ")&&!r.endsWith(" ")?r.slice(0,-1):r}finally{Ir()}},Qt=Ws;var Jt="streamdown:",Gs=/(^|[ \t])[*_~`]+$/;function Zs(e){return Qt(e.replace(Gs,"$1"))}function Vs(e,t,n){let r=document.createElement("template");if(r.innerHTML=e,t){for(let s of r.content.querySelectorAll(`a[href^="${Jt}"]`))s.removeAttribute("href");for(let s of r.content.querySelectorAll(`img[src^="${Jt}"]`))s.remove()}return r.innerHTML=n.sanitizeHtml(r.innerHTML),Array.from(r.content.childNodes)}function Qs(e,t,n){let r="",s=[],i=a=>{let o=t.lexer(r),c=0;for(;c<o.length&&c<s.length;){let h=a&&c===o.length-1,u=s[c];if(u.raw!==o[c].raw||u.healed!==h)break;c++}for(let h of s.slice(c))for(let u of h.nodes)u.remove();let l=s.slice(0,c);for(let h=c;h<o.length;h++){let u=o[h].raw,d=a&&h===o.length-1,k=t.parse(d?Zs(u):u,{async:!1}),m=Vs(k,d,n);e.append(...m),l.push({raw:u,healed:d,nodes:m})}s=l};return{write(a){r+=a,i(!0)},end(){i(!1)}}}function Xt(e,t=Ee){let n=e?new Je(e):S;t.setMarkdownProvider(r=>n.parse(r,{async:!1})),t.setStreamingMarkdownProvider(r=>Qs(r,n,t))}function Js(e){if(!rn(e))return!1;let t=e.metadata,n=typeof t=="object"&&t!==null&&typeof t.nodeId=="string";return e.type==="keepalive"?!0:e.type==="error"?n||typeof e.content=="string":n}function tn(e){return/^\s*<(?:!doctype|html|head|body)[\s>]/i.test(e)}function nn(e){try{return JSON.parse(e)}catch{return}}function rn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function st(e){let t=e.metadata??{};return`${String(t.nodeId??"")}:${String(t.runIndex??0)}:${String(t.itemIndex??0)}`}function Xs(e){switch(e.type){case"begin":return{kind:"begin",stream:st(e)};case"item":return{kind:"item",stream:st(e),text:typeof e.content=="string"?e.content:""};case"end":return{kind:"end",stream:st(e)};case"error":return{kind:"error",message:typeof e.content=="string"?e.content:""};case"keepalive":return;default:return{kind:"unknown",type:e.type}}}function sn(e){if(typeof e=="string")return e;if(Array.isArray(e)){let s=e.map(sn);return s.every(i=>i===void 0)&&e.length>0?void 0:s.filter(i=>i!==void 0).join(`
|
|
88
|
+
|
|
89
|
+
`)}if(typeof e!="object"||e===null)return e==null?"":String(e);let t=e,n=["output","text","message"].find(s=>t[s]!==void 0&&t[s]!==null);if(n===void 0)return Object.keys(t).length>0?void 0:"";let r=t[n];return typeof r=="string"?r:typeof r=="object"&&r!==null&&r.type==="text"&&typeof r.text=="string"?r.text:typeof r=="number"||typeof r=="boolean"?String(r):["```json",JSON.stringify(r,null,2),"```"].join(`
|
|
90
|
+
`)}function Ys(e){let t=e;for(;Array.isArray(t);)t=t[0];return Object.keys(t).slice(0,6)}function ei(e){let t=e.trim();if(!t)return;let n=nn(t);if(n===void 0)return tn(t)?{kind:"html"}:{kind:"reply",text:e};if(typeof n=="object"&&n!==null&&n.executionStarted===!0){let{executionId:s,resumeToken:i}=n;return{kind:"deferred",...typeof s=="string"||typeof s=="number"?{executionId:String(s)}:{},...typeof i=="string"?{resumeToken:i}:{}}}let r=sn(n);return r===void 0?{kind:"unreadable",fields:Ys(n)}:{kind:"reply",text:r}}async function*ti(e){let t=e.getReader(),n=new TextDecoder,r="unknown",s="",i="";function*a(o,c){let l=o.split(`
|
|
91
|
+
`);for(let[h,u]of l.entries()){if(!u.trim())continue;let d=nn(u);if(r==="unknown"){if(!Js(d)){r="whole";return}r="frames"}if(rn(d)){let k=Xs(d);k&&(yield k)}else c&&h===l.length-1&&u.trimStart().startsWith("{")?yield{kind:"cut"}:tn(u)?yield{kind:"html"}:yield{kind:"item",text:u}}}try{for(;;){let{done:o,value:c}=await t.read(),l=o?n.decode():n.decode(c,{stream:!0});if(s+=l,r!=="whole"){i+=l;let h=o?i.length:i.lastIndexOf(`
|
|
92
|
+
`)+1,u=i.slice(0,h);i=i.slice(h),yield*a(u,o)}if(o)break}}finally{t.releaseLock()}if(r!=="frames"){let o=ei(s);o&&(yield o)}}var ni=new Set([502,504,524]);function ri(e){let n=(Array.isArray(e.credentials)?e.credentials:[]).map(r=>typeof r=="object"&&r!==null?r.credentialName:void 0).filter(r=>typeof r=="string"&&r.length>0);return n.length>0?` (${n.join(", ")})`:""}async function it(e,t){let n=e.status,r=(await e.text().catch(()=>"")).trim(),s=O.codeForStatus(n)??(n===404?$.PROVIDER_MISCONFIGURED:$.PROVIDER_ERROR),i=(l,h=s)=>new O(l,h,void 0,void 0,n),a=$.PROVIDER_MISCONFIGURED;if(r.startsWith("<")||(e.headers.get("content-type")??"").includes("text/html"))return ni.has(n)?i(`A proxy in front of n8n gave up waiting (HTTP ${n}). The workflow may still be running \u2014 its execution list shows the result.`,$.NET_TIMEOUT):i(`n8n answered HTTP ${n} with a web page instead of a chat answer. Check that the URL is the Chat Trigger's production URL, the one that ends in /chat.`,O.codeForStatus(n)??a);let o={};try{o=JSON.parse(r)}catch{}if(n===428||o.status==="credential_connections_required")return i(`The n8n workflow cannot run until its credentials are connected${ri(o)}. Connect them in n8n, then try again.`,a);if(o.status==="credential_readiness_check_failed")return i("n8n could not check the workflow's credentials. Open the workflow in n8n to see which one fails.");if(t==="history"&&n===500)return i(`n8n could not load the conversation's history. When the Chat Trigger's "Load Previous Session" is "From Memory", connect the memory node to the Chat Trigger as well as to the agent.`,a);let c=typeof o.message=="string"?o.message:r;return typeof o.message=="string"&&typeof o.hint=="string"&&(c=`${o.message} ${o.hint}`),i(c.slice(0,400)||`The n8n workflow answered HTTP ${n}.`)}function at(e,t){if(!(e instanceof TypeError))return e;let n=typeof location>"u"?"this page's origin":location.origin,r=typeof navigator<"u"&&navigator.onLine===!1;return new O(`Could not reach n8n at ${t}. Check that it is the Chat Trigger's production URL, that the workflow is published, and that ${n} is in the trigger's Allowed Origins (CORS).`,r?$.NET_OFFLINE:$.NET_ERROR)}function si(e,t,n,r){let s=new URL(e).origin.replace(/^http/,"ws"),i=new URLSearchParams({sessionId:t,executionId:n,isPublic:"true"});return r&&i.set("token",r),`${s}/chat?${i.toString()}`}function ii(e){if(e==="n8n|heartbeat")return"heartbeat";if(e==="n8n|continue")return{kind:"continue"};let t;try{t=JSON.parse(e)}catch{return{kind:"text",text:e}}if(typeof t!="object"||t===null)return{kind:"text",text:e};let n=t;switch(n.type){case"heartbeat":return"heartbeat-json";case"continue":return{kind:"continue"};case"message":return{kind:"text",text:typeof n.text=="string"?n.text:""};case"error":return{kind:"error",message:typeof n.message=="string"?n.message:""};case"with-buttons":{let r=(Array.isArray(n.buttons)?n.buttons:[]).filter(s=>typeof s=="object"&&s!==null&&typeof s.text=="string"&&typeof s.link=="string").map(s=>({text:s.text,link:s.link,type:typeof s.type=="string"?s.type:"primary"}));return{kind:"buttons",text:typeof n.text=="string"?n.text:"",buttons:r,blockUserInput:n.blockUserInput===!0}}default:return{kind:"text",text:e}}}var ai=1,ot=class{closed=!1;socket;queue=[];waiter;opened;constructor(t,n){this.socket=new n(t),this.opened=new Promise(r=>{this.socket.onopen=()=>r()}),this.socket.onmessage=r=>{let s=ii(String(r.data));s==="heartbeat"?this.socket.send("n8n|heartbeat-ack"):s==="heartbeat-json"?this.socket.send(JSON.stringify({type:"heartbeat-ack"})):this.push(s)},this.socket.onerror=()=>{},this.socket.onclose=()=>{this.closed=!0,this.push({kind:"closed"})}}push(t){let n=this.waiter;this.waiter=void 0,n?n(t):this.queue.push(t)}unshift(t){this.queue.unshift(t)}next(t,n){let r=this.queue.shift();return r?Promise.resolve(r):this.closed?Promise.resolve({kind:"closed"}):t.aborted?Promise.resolve(void 0):new Promise(s=>{let i,a=l=>{i!==void 0&&clearTimeout(i),t.removeEventListener("abort",c),this.waiter===o&&(this.waiter=void 0),s(l)},o=l=>a(l),c=()=>a(void 0);this.waiter=o,t.addEventListener("abort",c,{once:!0}),n!==void 0&&(i=setTimeout(()=>a("timeout"),n))})}async send(t){this.socket.readyState!==ai&&await this.opened,this.socket.send(JSON.stringify(t))}close(){this.socket.close()}},Ne="n8n_buttons";function an(e=Ee){e.registerTool({name:Ne,description:"The buttons of an n8n Chat node that waits for an answer. Answered by the person in the page.",inputSchema:{type:"object",properties:{}}},async(t,n,r)=>{let s=t.input,i=await mt({kind:"approval",message:s.text,options:s.buttons.map((u,d)=>({value:String(d),label:u.text,tone:u.type==="secondary"?"deny":"affirm"})),allowOther:!s.blockUserInput,signal:n,...r?.target?{target:r.target}:{}}),a=i.action==="accept"?i.content:void 0,o=a?.instruction?.trim();if(o&&a?.option===void 0){let u={index:-1,text:o,written:!0};return{toolCallId:t.id,content:o,structuredContent:u}}let c=a?.option===void 0?-1:Number(a.option),l=s.buttons[c];if(!l)throw new Error("No button was chosen.");let h={index:c,text:l.text};return{toolCallId:t.id,content:l.text,structuredContent:h}}),e.registerToolDisplay(Ne,{icon:"messageSquare",label:t=>typeof t.result=="string"&&t.result?t.result:oi(t),quiet:!0,details:!1})}function oi(e){return e.toolCall?.input?.text??""}function li(e){if(e)try{let t=JSON.parse(e);return t.v===1&&typeof t.sessionId=="string"&&typeof t.executionId=="string"&&typeof t.toolCallId=="string"&&Array.isArray(t.links)?t:void 0}catch{return}}var ci=250;async function ui(e){let t=new Uint8Array(await e.blob.arrayBuffer()),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);let r=e.blob.type||"application/octet-stream";return{name:e.name,type:r,data:`data:${r};base64,${btoa(n)}`}}var Yt=`The n8n workflow streamed nothing. When its Chat Trigger streams, the node that answers has to stream too: turn on streaming in the AI Agent's options, or set the trigger's Response Mode to "When Last Node Finishes".`,hi="The n8n workflow finished without an answer: its last node returned no text. End the workflow on the node that answers \u2014 an AI Agent, or a node that returns an `output` field.",pi="A proxy timed out waiting for n8n's answer. The workflow may still be running \u2014 its execution list shows the result.",di="This n8n workflow answers through response nodes, over n8n's chat WebSocket, and n8n did not say which execution to listen to. Check the Chat Trigger's Response Mode.",fi="This n8n workflow answers through response nodes, over n8n's chat WebSocket, and this runtime has no WebSocket. Pass one as the runner's `WebSocket` option.",gi=e=>`The n8n workflow answered with the fields ${e.map(t=>`"${t}"`).join(", ")} but no "output", "text" or "message" field, which is where a chat reads the answer. End the workflow on an AI Agent, or add a Set node that puts the reply in "output".`;function mi(e){for(let t=e.length-1;t>=0;t--)if(e[t]?.role==="user")return t;return-1}function en(e){return e===void 0?"":typeof e=="string"?e:e.flatMap(t=>t.type==="text"&&t.text?[t.text]:[]).join(`
|
|
93
|
+
|
|
94
|
+
`)}var ki={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg"};function bi(e,t,n){let r=/^data:([^;,]+)?((?:;[^;,]*)*?);base64,(.*)$/s.exec(e);if(!r)return;let s=t??r[1]??"application/octet-stream",i=atob(r[3]??""),a=new Uint8Array(i.length);for(let o=0;o<i.length;o++)a[o]=i.charCodeAt(o);return{blob:new Blob([a],{type:s}),name:`image-${n+1}.${ki[s]??"bin"}`}}function wi(e,t){return e.files&&e.files.length>0?e.files.map(n=>({blob:n,name:n.name})):(Array.isArray(t?.content)?t.content:[]).flatMap(n=>n.type==="image"?[n]:[]).map((n,r)=>bi(n.image,n.mimeType,r)).filter(n=>n!==void 0)}function on(e){let t=e.onWarning??(l=>console.warn(`[aparte] n8n: ${l}`)),n=e.chatSessionKey??"sessionId",r=e.chatInputKey??"chatInput",s=`aparte-${ie()}`,i=new Map,a=(l,h,u)=>{let d=e.WebSocket??globalThis.WebSocket;if(!d)throw new O(fi,$.PROVIDER_MISCONFIGURED);i.get(l)?.socket.close();let k={socket:new ot(si(e.webhookUrl,l,h,u),d),executionId:h,...u?{token:u}:{}};return i.set(l,k),k},o=async(l,h)=>{let u=l.emitter,d=i.get(h),{socket:k}=d,m=!1,T=()=>{m&&u({type:"text-flush"}),u({type:"run-done"})};for(;;){let b=await k.next(l.signal);if(b===void 0)return;if(!(b==="timeout"||b.kind==="continue"))switch(b.kind){case"text":{m&&u({type:"text-flush"}),b.text&&(u({type:"text-delta",delta:b.text}),m=!0);let x=await k.next(l.signal,ci);if(x===void 0)return;if(x==="timeout")return T();x.kind!=="continue"&&k.unshift(x);break}case"buttons":{m&&u({type:"text-flush"}),b.text&&(u({type:"text-delta",delta:b.text}),u({type:"text-flush"}));let x=new URL(e.webhookUrl).origin,v=b.buttons.filter(y=>{try{return new URL(y.link,e.webhookUrl).origin===x}catch{return!1}});if(v.length===0){t("An n8n Chat node sent buttons whose links lead off this n8n instance; they were not shown."),u({type:"run-done"});return}let z=`n8n-buttons-${ie()}`,U={text:b.text,buttons:v.map(y=>({text:y.text,type:y.type})),blockUserInput:b.blockUserInput},C={v:1,sessionId:h,executionId:d.executionId,...d.token?{token:d.token}:{},toolCallId:z,links:v.map(y=>y.link)};u({type:"tool-start",toolCallId:z,name:Ne,input:U}),u({type:"run-suspended",pending:[{toolCallId:z,name:Ne,input:U,reason:"external"}],ticket:JSON.stringify(C)});return}case"error":throw m&&u({type:"text-flush"}),new O(b.message||"The n8n workflow failed.",$.PROVIDER_ERROR);case"closed":return i.delete(h),T()}}},c=async(l,h,u)=>{let d=l.emitter;d({type:"run-start"}),d({type:"turn-start"});let k=l.deferral?.outcomes?.[h.toolCallId],m=k?.kind==="result"?k.structuredContent:void 0,T=m?h.links[m.index]:void 0;if(k?.kind==="result"&&m?.written){d({type:"tool-resolved",toolCallId:h.toolCallId,result:k.content,structuredResult:m}),await(i.get(h.sessionId)??a(h.sessionId,h.executionId,h.token)).socket.send({sessionId:h.sessionId,action:"sendMessage",chatInput:m.text,files:[]}),await o(l,h.sessionId);return}if(!k||k.kind!=="result"||!T){d({type:"tool-aborted",toolCallId:h.toolCallId}),d({type:"run-done"});return}d({type:"tool-resolved",toolCallId:h.toolCallId,result:k.content,structuredResult:m});let b=i.get(h.sessionId);(!b||b.socket.closed)&&a(h.sessionId,h.executionId,h.token);let x=await u(T,{signal:l.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(v=>{throw at(v,T)});if(!x.ok)throw await it(x,"answer");await o(l,h.sessionId)};return async l=>{let h=l.emitter,u=e.fetch??fetch;try{let d=li(l.deferral?.token);if(d){await c(l,d,u);return}let k=l.baseRequest.messages,m=mi(k),T=m>=0?k[m]:void 0;e.sessionId===void 0&&!k.slice(0,Math.max(m,0)).some(f=>f.role==="assistant")&&(s=`aparte-${ie()}`);let b=typeof e.headers=="function"?await e.headers():e.headers??{},x=(typeof e.sessionId=="function"?e.sessionId(l):e.sessionId)??s,v=typeof e.metadata=="function"?e.metadata(l):e.metadata,z=wi(l,T),U=i.get(x);if(U&&!U.socket.closed){h({type:"run-start"}),h({type:"turn-start"}),await U.socket.send({sessionId:x,action:"sendMessage",chatInput:en(T?.content),files:await Promise.all(z.map(ui))}),await o(l,x);return}let C={action:"sendMessage",[n]:x,[r]:en(T?.content),...v?{metadata:v}:{}},y,ue={Accept:"text/plain"};for(let[f,A]of Object.entries(b))f.toLowerCase()!=="content-type"&&(ue[f]=A);if(z.length>0){let f=new FormData;for(let[A,V]of Object.entries(C))f.append(A,typeof V=="string"?V:JSON.stringify(V));for(let A of z)f.append("files",A.blob,A.name);y=f}else y=JSON.stringify(C),ue["Content-Type"]="application/json";let J=await u(e.webhookUrl,{method:"POST",headers:ue,body:y,signal:l.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(f=>{throw at(f,e.webhookUrl)});if(!J.ok)throw await it(J,"answer");h({type:"run-start"}),h({type:"turn-start"});let Re=!1,ke=!1,ne=!1,X=!1,M,Z=new Map,be=new Set,re=()=>{ne&&h({type:"text-flush"}),ne=!1},q=f=>{f&&(Re=!0,ne=!0,h({type:"text-delta",delta:f}))},W=f=>{M=f,re()},he=()=>{M=void 0;for(let[f,A]of Z){Z.delete(f),W(f);for(let V of A.text)q(V);if(!A.ended)return;M=void 0}},pe=f=>{let A=Z.get(f);return A||Z.set(f,A={text:[],ended:!1}),A};if(!J.body)throw new O(Yt,$.PROVIDER_MISCONFIGURED);for await(let f of ti(J.body))switch(f.kind){case"begin":M===void 0?W(f.stream):f.stream!==M&&pe(f.stream);break;case"item":f.stream===void 0||f.stream===M?q(f.text):M===void 0?(W(f.stream),q(f.text)):pe(f.stream).text.push(f.text);break;case"end":f.stream===M?he():pe(f.stream).ended=!0;break;case"error":throw re(),new O(f.message||"The n8n workflow failed.",$.PROVIDER_ERROR);case"reply":ke=!0,q(f.text);break;case"unreadable":throw new O(gi(f.fields),$.PROVIDER_MISCONFIGURED);case"deferred":if(!f.executionId)throw new O(di,$.PROVIDER_MISCONFIGURED);a(x,f.executionId,f.resumeToken),X=!0;break;case"html":throw re(),new O(pi,$.NET_TIMEOUT);case"cut":t("n8n's stream stopped in the middle of a frame; the text before it is kept.");break;case"unknown":be.has(f.type)||t(`n8n sent a "${f.type}" frame, which this runner does not read; it was skipped.`),be.add(f.type);break}if(X){await o(l,x);return}he();for(let[f,A]of Z){Z.delete(f),W(f);for(let V of A.text)q(V)}if(!Re)throw new O(ke?hi:Yt,$.PROVIDER_MISCONFIGURED);re(),h({type:"run-done"});return}catch(d){if(l.signal.aborted)return;throw d}}}function xi(e){let t=Array.isArray(e.id)?e.id:[],n=t[t.length-1];return typeof n=="string"?n:typeof e.type=="string"?e.type:""}function yi(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>typeof t=="string"?t:typeof t=="object"&&t!==null&&t.type==="text"?String(t.text??""):"").filter(Boolean).join(`
|
|
95
|
+
|
|
96
|
+
`):""}function Si(e,{now:t=Date.now()}={}){let n=[];return e.forEach((r,s)=>{if(typeof r!="object"||r===null)return;let i=r,a=xi(i),o=/^Human/.test(a)||a==="human"?"user":/^AI/.test(a)||a==="ai"?"assistant":void 0;if(!o)return;let c=yi(i.kwargs?.content);c.trim()&&n.push({id:`n8n-${s}`,role:o,content:c,timestamp:t-(e.length-s),status:"completed"})}),n}async function ln(e){let t=e.fetch??fetch,n=typeof e.headers=="function"?await e.headers():e.headers??{},r={"Content-Type":"application/json"};for(let[o,c]of Object.entries(n))o.toLowerCase()!=="content-type"&&(r[o]=c);let s=await t(e.webhookUrl,{method:"POST",headers:r,body:JSON.stringify({action:"loadPreviousSession",[e.chatSessionKey??"sessionId"]:e.sessionId,...e.metadata?{metadata:e.metadata}:{}}),...e.signal?{signal:e.signal}:{},...e.credentials?{credentials:e.credentials}:{}}).catch(o=>{throw at(o,e.webhookUrl)});if(!s.ok)throw await it(s,"history");let i;try{i=await s.json()}catch{throw new O("n8n answered the history request with something that is not JSON. Check that the URL is the Chat Trigger's production URL.",$.PROVIDER_MISCONFIGURED)}let a=typeof i=="object"&&i!==null?i.data:void 0;return Si(Array.isArray(a)?a:[])}var Ri='<svg class="aparte-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M5.5 3.5h13a3 3 0 0 1 3 3v8.5a3 3 0 0 1-3 3h-6.2l-4.8 3.6a.6.6 0 0 1-1-.5v-3.1H5.5a3 3 0 0 1-3-3V6.5a3 3 0 0 1 3-3Z"/></svg>',Ei='<svg class="aparte-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9.5 6 6 6-6"/></svg>',vi='<svg class="aparte-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M3.4 20.2 21 12.6a.7.7 0 0 0 0-1.2L3.4 3.8a.6.6 0 0 0-.9.7L5 11l8 1-8 1-2.5 6.5a.6.6 0 0 0 .9.7Z"/></svg>',cn={launcherOpen:()=>Ri,launcherClose:()=>Ei,send:()=>vi};var Se={en:{strings:{title:"Hi there! \u{1F44B}",subtitle:"Start a chat. We're here to help you 24/7.",footer:"",getStarted:"New Conversation",inputPlaceholder:"Type your question..",closeButtonTooltip:"Close chat",repostButton:"Repost message",reuseButton:"Reuse message"},initial:["Hi there! \u{1F44B}","My name is Nathan. How can I assist you today?"]},fr:{strings:{title:"Bonjour ! \u{1F44B}",subtitle:"D\xE9marrez une conversation. Nous sommes l\xE0 pour vous aider, 24 h/24.",footer:"",getStarted:"Nouvelle conversation",inputPlaceholder:"Posez votre question\u2026",closeButtonTooltip:"Fermer le chat",repostButton:"Renvoyer le message",reuseButton:"R\xE9utiliser le message"},initial:["Bonjour ! \u{1F44B}","Je m\u2019appelle Nathan. Comment puis-je vous aider ?"],locale:()=>import("./chunks/fr-YU75PBOR.js").then(e=>e.fr)},es:{strings:{title:"\xA1Hola! \u{1F44B}",subtitle:"Inicia una conversaci\xF3n. Estamos aqu\xED para ayudarte, 24/7.",footer:"",getStarted:"Nueva conversaci\xF3n",inputPlaceholder:"Escribe tu pregunta\u2026",closeButtonTooltip:"Cerrar el chat",repostButton:"Volver a enviar el mensaje",reuseButton:"Reutilizar el mensaje"},initial:["\xA1Hola! \u{1F44B}","Me llamo Nathan. \xBFEn qu\xE9 puedo ayudarte hoy?"],locale:()=>import("./chunks/es-DV5N3CXP.js").then(e=>e.es)},"pt-BR":{strings:{title:"Ol\xE1! \u{1F44B}",subtitle:"Comece uma conversa. Estamos aqui para ajudar, 24 horas por dia.",footer:"",getStarted:"Nova conversa",inputPlaceholder:"Digite sua pergunta\u2026",closeButtonTooltip:"Fechar o chat",repostButton:"Reenviar a mensagem",reuseButton:"Reutilizar a mensagem"},initial:["Ol\xE1! \u{1F44B}","Meu nome \xE9 Nathan. Como posso ajudar voc\xEA hoje?"],locale:()=>import("./chunks/pt-BR-526LHI67.js").then(e=>e.ptBR)},de:{strings:{title:"Hallo! \u{1F44B}",subtitle:"Starte ein Gespr\xE4ch. Wir sind rund um die Uhr f\xFCr dich da.",footer:"",getStarted:"Neues Gespr\xE4ch",inputPlaceholder:"Stell deine Frage\u2026",closeButtonTooltip:"Chat schlie\xDFen",repostButton:"Nachricht erneut senden",reuseButton:"Nachricht wiederverwenden"},initial:["Hallo! \u{1F44B}","Ich hei\xDFe Nathan. Wie kann ich dir heute helfen?"],locale:()=>import("./chunks/de-WJNL5YNK.js").then(e=>e.de)},it:{strings:{title:"Ciao! \u{1F44B}",subtitle:"Inizia una conversazione. Siamo qui per aiutarti, 24 ore su 24.",footer:"",getStarted:"Nuova conversazione",inputPlaceholder:"Scrivi la tua domanda\u2026",closeButtonTooltip:"Chiudi la chat",repostButton:"Invia di nuovo il messaggio",reuseButton:"Riusa il messaggio"},initial:["Ciao! \u{1F44B}","Mi chiamo Nathan. Come posso aiutarti oggi?"],locale:()=>import("./chunks/it-DZTHWNO3.js").then(e=>e.it)},ru:{strings:{title:"\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u{1F44B}",subtitle:"\u041D\u0430\u0447\u043D\u0438\u0442\u0435 \u0440\u0430\u0437\u0433\u043E\u0432\u043E\u0440. \u041C\u044B \u043D\u0430 \u0441\u0432\u044F\u0437\u0438 \u043A\u0440\u0443\u0433\u043B\u043E\u0441\u0443\u0442\u043E\u0447\u043D\u043E.",footer:"",getStarted:"\u041D\u043E\u0432\u044B\u0439 \u0440\u0430\u0437\u0433\u043E\u0432\u043E\u0440",inputPlaceholder:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432\u0430\u0448 \u0432\u043E\u043F\u0440\u043E\u0441\u2026",closeButtonTooltip:"\u0417\u0430\u043A\u0440\u044B\u0442\u044C \u0447\u0430\u0442",repostButton:"\u041E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435 \u0435\u0449\u0451 \u0440\u0430\u0437",reuseButton:"\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435 \u0441\u043D\u043E\u0432\u0430"},initial:["\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u{1F44B}","\u041C\u0435\u043D\u044F \u0437\u043E\u0432\u0443\u0442 \u041D\u0430\u0442\u0430\u043D. \u0427\u0435\u043C \u043C\u043E\u0433\u0443 \u043F\u043E\u043C\u043E\u0447\u044C?"],locale:()=>import("./chunks/ru-5WNEMKNP.js").then(e=>e.ru)},ja:{strings:{title:"\u3053\u3093\u306B\u3061\u306F\uFF01\u{1F44B}",subtitle:"\u30C1\u30E3\u30C3\u30C8\u3092\u59CB\u3081\u307E\u3057\u3087\u3046\u300224\u6642\u9593\u3044\u3064\u3067\u3082\u304A\u624B\u4F1D\u3044\u3057\u307E\u3059\u3002",footer:"",getStarted:"\u65B0\u3057\u3044\u4F1A\u8A71",inputPlaceholder:"\u8CEA\u554F\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\u2026",closeButtonTooltip:"\u30C1\u30E3\u30C3\u30C8\u3092\u9589\u3058\u308B",repostButton:"\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u518D\u9001\u4FE1",reuseButton:"\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u518D\u5229\u7528"},initial:["\u3053\u3093\u306B\u3061\u306F\uFF01\u{1F44B}","\u30CD\u30A4\u30B5\u30F3\u3067\u3059\u3002\u4ECA\u65E5\u306F\u3069\u306E\u3088\u3046\u306A\u3054\u7528\u4EF6\u3067\u3057\u3087\u3046\u304B\uFF1F"],locale:()=>import("./chunks/ja-QO442LBN.js").then(e=>e.ja)},ko:{strings:{title:"\uC548\uB155\uD558\uC138\uC694! \u{1F44B}",subtitle:"\uB300\uD654\uB97C \uC2DC\uC791\uD558\uC138\uC694. 24\uC2DC\uAC04 \uC5B8\uC81C\uB4E0 \uB3C4\uC640\uB4DC\uB9B4\uAC8C\uC694.",footer:"",getStarted:"\uC0C8 \uB300\uD654",inputPlaceholder:"\uC9C8\uBB38\uC744 \uC785\uB825\uD558\uC138\uC694\u2026",closeButtonTooltip:"\uCC44\uD305 \uB2EB\uAE30",repostButton:"\uBA54\uC2DC\uC9C0 \uB2E4\uC2DC \uBCF4\uB0B4\uAE30",reuseButton:"\uBA54\uC2DC\uC9C0 \uB2E4\uC2DC \uC0AC\uC6A9"},initial:["\uC548\uB155\uD558\uC138\uC694! \u{1F44B}","\uC800\uB294 \uB124\uC774\uC120\uC785\uB2C8\uB2E4. \uBB34\uC5C7\uC744 \uB3C4\uC640\uB4DC\uB9B4\uAE4C\uC694?"],locale:()=>import("./chunks/ko-EGFZJCXQ.js").then(e=>e.ko)},"zh-CN":{strings:{title:"\u4F60\u597D\uFF01\u{1F44B}",subtitle:"\u5F00\u59CB\u804A\u5929\u5427\u3002\u6211\u4EEC\u5168\u5929\u5019\u4E3A\u4F60\u670D\u52A1\u3002",footer:"",getStarted:"\u65B0\u5BF9\u8BDD",inputPlaceholder:"\u8F93\u5165\u4F60\u7684\u95EE\u9898\u2026",closeButtonTooltip:"\u5173\u95ED\u804A\u5929",repostButton:"\u91CD\u65B0\u53D1\u9001\u6D88\u606F",reuseButton:"\u91CD\u65B0\u4F7F\u7528\u6D88\u606F"},initial:["\u4F60\u597D\uFF01\u{1F44B}","\u6211\u662F Nathan\u3002\u4ECA\u5929\u6709\u4EC0\u4E48\u53EF\u4EE5\u5E2E\u4F60\u7684\uFF1F"],locale:()=>import("./chunks/zh-CN-ABSHNLG6.js").then(e=>e.zhCN)}};function lt(e){if(Se[e])return e;let t=e.split("-")[0]?.toLowerCase()??"";return Object.keys(Se).find(n=>n.split("-")[0]?.toLowerCase()===t)??"en"}function un(e,t){return{...Se[lt(e)].strings,...t?.[e]??{}}}function hn(e){return Se[lt(e)].initial}function pn(e){return Se[lt(e)].locale?.()}var ct="n8n-chat/sessionId",dn="N8N_WORKFLOW_ERROR",mn=new WeakMap,fn=!1;function Ti(){fn||(fn=!0,gt({type:"n8n-component",render:e=>{let{key:t,arguments:n}=e,r=document.createElement("div");return r.className="aparte-segment aparte-n8n__component",r.setAttribute("data-component",t),queueMicrotask(()=>{let s=r.closest("aparte-chat"),i=s?mn.get(s)?.[t]:void 0;if(!i){console.warn(`[aparte] n8n: no messageComponents entry for "${t}".`);return}let a=i(n);typeof a=="string"?r.innerHTML=a:r.replaceChildren(a)}),r}}))}function Ii(e){try{return localStorage.getItem(e)??void 0}catch{return}}function gn(e,t){try{localStorage.setItem(e,t)}catch{}}function $i(e){if(typeof e!="string")return e;let t=document.querySelector(e);if(t)return t;let n=document.createElement("div");return e.startsWith("#")?n.id=e.slice(1):e.startsWith(".")&&(n.className=e.slice(1)),document.body.appendChild(n),n}function R(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=n),r}var Ai=0;function Ci(e){let t=e.mode??"window",n=e.defaultLanguage??"en",r=un(n,e.i18n),s=e.loadPreviousSession??!0,i=e.initialMessages??hn(n),a=++Ai,o=`aparte-n8n-title-${a}`,c=e.sessionId??(s?Ii(ct):void 0)??ie();s&&!e.sessionId&&gn(ct,c);let l=new ft;e.locale&&l.setLocale(e.locale);let h=!1;pn(n)?.then(p=>{!h&&!e.locale&&l.setLocale(p)},p=>console.warn("[aparte] n8n: the chat's language could not be loaded; it stays in English.",p)),l.registerIcons(cn),e.enableMessageActions&&(l.registerAction({id:"n8n-repost",icon:"retry",label:r.repostButton,zones:["bubble"],bubble:{roles:["user"]}}),l.registerAction({id:"n8n-reuse",icon:"edit",label:r.reuseButton,zones:["bubble"],bubble:{roles:["user"]}})),l.setHostHandlers({attachmentPreview:!0,filePreview:!0}),an(l),l.setErrorRenderer(({message:p,sentence:g,code:I})=>{let _=I===dn,B=R("div","aparte-segment aparte-alert aparte-alert--danger aparte-segment-error");I&&B.setAttribute("data-error-code",_?$.PROVIDER_ERROR:I);let se=R("span","aparte-alert__icon");se.innerHTML=l.getIcon("error")||"\u26A0";let D=R("div","aparte-alert__body");return D.append(R("div","aparte-alert__title",l.t("error")),R("div","aparte-alert__message",_?l.t("errorNoAnswer"):g??p)),_&&p&&D.append(R("p","aparte-n8n__error-detail",p)),B.append(se,D),B}),Xt(void 0,l);let u;l.setHighlightProvider(async(p,g)=>(u??=import("./chunks/highlight-HDJ3ROJ4.js").then(I=>I.createHighlighter()),(await u)(p,g)));let d=R("section","aparte-n8n__window");d.setAttribute("aria-labelledby",o);let k=R("header","aparte-n8n__header"),m=R("div","aparte-n8n__heading"),T=R("p","aparte-n8n__title",r.title);if(T.id=o,m.append(T),r.subtitle&&m.append(R("p","aparte-n8n__subtitle",r.subtitle)),k.append(m),t==="window"&&e.showWindowCloseButton){let p=R("button","aparte-btn aparte-btn--icon aparte-btn--ghost aparte-n8n__close");p.type="button",p.setAttribute("aria-label",r.closeButtonTooltip),p.setAttribute("data-aparte-launcher-close","");let g=R("aparte-icon");g.setAttribute("name","close"),p.append(g),k.append(p)}let b=R("aparte-chat","aparte-n8n__chat");b.id=`aparte-n8n-chat-${a}`,e.messageComponents&&(Ti(),mn.set(b,e.messageComponents));let x=R("aparte-composer");x.setAttribute("placeholder",r.inputPlaceholder);let v;e.suggestions?.length&&(v=R("aparte-suggestions"),v.setAttribute("suggestions",JSON.stringify(e.suggestions.map(p=>({label:p,prompt:p})))),x.append(v));let z=R("div","aparte-composer-shell"),U=R("div","aparte-composer-row");if(U.append(R("aparte-composer-input")),e.allowFileUploads){z.append(R("aparte-composer-attachments"));let p=R("aparte-composer-add-attachment");e.allowedFilesMimeTypes&&p.setAttribute("accept",e.allowedFilesMimeTypes),U.append(p)}U.append(R("aparte-composer-send")),z.append(U),x.append(z),b.append(R("aparte-chat-viewport"),R("aparte-elicitation"),x),d.append(k,b),r.footer&&d.append(R("p","aparte-n8n__footer",r.footer));let C;if(e.showWelcomeScreen){C=R("div","aparte-n8n__welcome");let p=R("button","aparte-btn aparte-btn--primary aparte-btn--solid aparte-n8n__start",r.getStarted);p.type="button",p.addEventListener("click",()=>{C.hidden=!0,b.hidden=!1,b.querySelector("aparte-composer-input")?.focusEnd?.()}),C.append(p),b.hidden=!0,d.insertBefore(C,b)}let y;t==="window"?(y=R("aparte-launcher","aparte-n8n aparte-n8n--window"),y.append(d)):(y=R("div","aparte-n8n aparte-n8n--fullscreen"),y.append(d));let ue=e.colorScheme??"light";ue!=="auto"&&y.setAttribute("data-aparte-theme",ue),y.setAttribute("lang",n),t==="window"&&y.addEventListener("aparte-launcher-toggle",p=>{let{open:g,sheet:I}=p.detail;g&&I?(d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true")):(d.removeAttribute("role"),d.removeAttribute("aria-modal"))}),dt(y,l),$i(e.target??"#n8n-chat").append(y);let J=()=>i.map((p,g)=>({id:`n8n-initial-${g}`,role:"assistant",content:p,timestamp:Date.now()-i.length+g,status:"completed"})),Re=()=>(e.messageHistory??[]).map((p,g)=>{let I={id:`n8n-seed-${g}`,role:p.sender==="user"?"user":"assistant",timestamp:Date.now(),status:"completed"};if(p.type==="component"){let _={id:`n8n-seed-${g}-component`,type:"n8n-component",key:p.key,arguments:p.arguments??{}};return{...I,content:"",segments:[_]}}return{...I,content:p.text}}),ke=new Set((e.messageHistory??[]).flatMap((p,g)=>p.transparent?[`n8n-seed-${g}`]:[]));ke.size&&new MutationObserver(()=>{for(let p of ke){let g=b.querySelector(`aparte-chat-bubble[message-id="${p}"]`);g&&!g.hasAttribute("data-n8n-transparent")&&g.setAttribute("data-n8n-transparent","")}}).observe(b,{childList:!0,subtree:!0});let ne=p=>b.viewport?.setMessages(p);ne([...J(),...Re()]),e.messageHistory?.length&&v&&(v.hidden=!0);let X=0,M,Z=()=>{let p=++X;M=new AbortController,ln({webhookUrl:e.webhookUrl,sessionId:c,...e.metadata?{metadata:e.metadata}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{},headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},signal:M.signal}).then(g=>{p!==X||g.length===0||(v&&(v.hidden=!0),ne([...J(),...g]))},g=>{M?.signal.aborted||console.warn(`[aparte] n8n: ${g instanceof Error?g.message:String(g)}`)})};if(s)if(t==="window"){let p=g=>{g.detail.open&&(y.removeEventListener("aparte-launcher-toggle",p),X===0&&Z())};y.addEventListener("aparte-launcher-toggle",p)}else Z();let be="",re=c,q=!1,W=[];b.addEventListener("aparte-send",p=>{X++,be=String(p.detail?.content??""),re=c,v&&(v.hidden=!0)});let he=(p,g)=>{C&&!C.hidden&&(C.hidden=!0,b.hidden=!1),b.dispatchEvent(new CustomEvent("aparte-send",{detail:{content:p,timestamp:Date.now(),targetId:b.id,...g?.length?{files:g}:{}},bubbles:!0,composed:!0}))},pe=()=>{q=!1;let p=W.shift();p!==void 0&&queueMicrotask(()=>he(p))};b.addEventListener("aparte-message-start",()=>{q=!0});for(let p of["aparte-message-done","aparte-message-error","aparte-message-aborted"])b.addEventListener(p,pe);let f=p=>{p.detail?.targetId===b.id&&pe()};window.addEventListener("aparte-message-aborted",f);let A=c,V=on({webhookUrl:e.webhookUrl,sessionId:()=>A,headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},...e.metadata?{metadata:e.metadata}:{},...e.chatInputKey?{chatInputKey:e.chatInputKey}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{}}),kn=async p=>{let g=be,I=re;if(await e.beforeMessageSent?.(g),p.signal.aborted)return;A=I;let _="",B=!1,se=await V({...p,emitter:D=>{D.type==="text-delta"&&(_+=D.delta),D.type==="run-done"&&(B=!0),p.emitter(D)}}).catch(D=>{let de=D;throw de?.code===$.PROVIDER_ERROR&&de.httpStatus===void 0?new O(de.message??"",dn,de.data,D):D});if(B&&e.afterMessageSent){let D=e.afterMessageSent;queueMicrotask(()=>{Promise.resolve().then(()=>D(g,{output:_,message:_,hasReceivedChunks:_.length>0})).catch(de=>console.warn("[aparte] n8n: afterMessageSent threw:",de))})}return se},Me=new kt({config:l,streamRunner:kn,rawFileInject:"none",scopeToTargetId:b.id});Me.start();let ut=()=>b.viewport,bn=p=>{let{actionId:g,messageId:I}=p.detail;if(g!=="n8n-repost"&&g!=="n8n-reuse")return;let _=ut()?.getMessage?.(I);if(_){if(g==="n8n-reuse"){x.setValue(_.content??""),b.querySelector("aparte-composer-input")?.focusEnd?.();return}Promise.all((_.attachments??[]).map(async B=>{let se=await(await fetch(B.url)).blob();return new File([se],B.name,{type:B.type||se.type})})).then(B=>{q?W.push(_.content??""):he(_.content??"",B)},B=>console.warn("[aparte] n8n: a file of that message could not be read again:",B))}};b.addEventListener("aparte-action",bn);let Q=-1,Be="",wn=()=>b.querySelector("aparte-composer-input");x.addEventListener("keydown",p=>{if(p.key!=="ArrowUp"&&p.key!=="ArrowDown"||p.altKey||p.ctrlKey||p.metaKey||p.shiftKey||p.isComposing||!p.target?.closest("aparte-composer-input"))return;let g=(ut()?.getMessages?.()??[]).filter(I=>I.role==="user"&&I.content?.trim()).map(I=>I.content??"");if(p.key==="ArrowUp"){if(Q===-1&&x.value!==""||Q>=g.length-1)return;Q===-1&&(Be=x.value),Q++}else{if(Q===-1)return;Q--}p.preventDefault(),x.setValue(Q===-1?Be:g[g.length-1-Q]??""),wn()?.focusEnd?.()}),b.addEventListener("aparte-send",()=>{Q=-1,Be=""}),b.addEventListener("click",p=>{if(p.defaultPrevented||p.button!==0||p.metaKey||p.ctrlKey||p.shiftKey||p.altKey)return;let g=p.target?.closest(".aparte-message-content a[href]");!g||g.getAttribute("href")?.startsWith("#")||(p.preventDefault(),window.open(g.href,"_blank","noopener"))}),b.addEventListener("aparte-attachment-preview",p=>{let{url:g}=p.detail;g&&window.open(g,"_blank","noopener")});let ht=p=>x.toggleAttribute("disabled",p);(typeof e.disabled=="object"?e.disabled?.value:e.disabled)&&ht(!0);let De=()=>t==="window"?y:void 0,pt=()=>{h=!0,M?.abort(),W.length=0,window.removeEventListener("aparte-message-aborted",f),Me.stop(),y.remove()};return{element:y,get sessionId(){return c},open:()=>De()?.show(),close:()=>De()?.close(),toggle:()=>De()?.toggle(),send:p=>{q?W.push(p):he(p)},reset:()=>{W.length=0,x.streaming&&x.cancel(),Me.abort(),q=!1,M?.abort(),X++,c=e.sessionId??ie(),s&&!e.sessionId&&gn(ct,c),v&&(v.hidden=!1),ne(J())},setDisabled:ht,destroy:pt,unmount:pt}}export{Ci as createChat};
|
|
97
|
+
//# sourceMappingURL=n8n-chat.js.map
|