import{a as e,n as t}from"./lit-xS7RrYW6.js";import{t as n}from"./string-coerce-CuNcS1Hz.js";import{n as r,t as i}from"./directive-CUxOzvVj.js";import{A as a,C as o,D as s,E as c,F as l,J as u,M as d,N as f,O as p,P as m,R as h,S as g,T as _,W as v,Z as y,b,d as ee,h as x,i as S,j as C,k as te,n as w,o as T,r as E,v as D,w as O,x as ne,y as k,z as A}from"./index-Bt8RaTD0.js";import{r as re}from"./channel-config-extras-D50yz0bl.js";import{i as j,n as M,r as N,t as ie}from"./skills-shared-B7xxkfzE.js";var ae=i(class extends r{constructor(){super(...arguments),this.key=t}render(e,t){return this.key=e,t}update(e,[t,n]){return t!==this.key&&(u(e),this.key=t),n}});function oe(n){var r,i,o,l,u,d,f,m,h,g,v,y,ee;let{agent:x,configForm:S,agentFilesList:w,configLoading:T,configSaving:E,configDirty:D,onConfigReload:O,onConfigSave:ne,onModelChange:k,onModelFallbacksChange:A,onSelectPanel:re}=n,j=!!(n.defaultId&&x.id===n.defaultId),M=s(S,x.id),N=x.model,ie=(w&&w.agentId===x.id?w.workspace:null)||((r=M.entry)==null?void 0:r.workspace)||((i=M.defaults)==null?void 0:i.workspace)||x.workspace||`default`,ae=(o=M.entry)!=null&&o.model?a((l=M.entry)==null?void 0:l.model):(u=M.defaults)!=null&&u.model?a((d=M.defaults)==null?void 0:d.model):a(N),oe=p(x.agentRuntime),se=a(((f=M.defaults)==null?void 0:f.model)??N),ce=C((m=M.entry)==null?void 0:m.model),P=C((h=M.defaults)==null?void 0:h.model)||(se===`-`?null:_(se))||(S?null:C(N)),le=ce??P??null,F=j?le:ce,I=te((g=M.entry)==null?void 0:g.model)??te((v=M.defaults)==null?void 0:v.model)??(S?null:te(N))??[],L=Array.isArray((y=M.entry)==null?void 0:y.skills)?(ee=M.entry)==null?void 0:ee.skills:null,ue=(L==null?void 0:L.length)??null,R=!S||T||E,de=e=>{let t=I.filter((t,n)=>n!==e);A(x.id,t)};return e`
    <section class="card">
      <div class="card-title">Overview</div>
      <div class="card-sub">Workspace paths and identity metadata.</div>

      <div class="agents-overview-grid" style="margin-top: 16px;">
        <div class="agent-kv">
          <div class="label">Workspace</div>
          <div>
            <button
              type="button"
              class="workspace-link mono"
              @click=${()=>re(`files`)}
              title="Open Files tab"
            >
              ${ie}
            </button>
          </div>
        </div>
        <div class="agent-kv">
          <div class="label">Primary Model</div>
          <div class="mono">${ae}</div>
        </div>
        <div class="agent-kv">
          <div class="label">Runtime</div>
          <div class="mono">${oe}</div>
        </div>
        <div class="agent-kv">
          <div class="label">Skills Filter</div>
          <div>${L?`${ue} selected`:`all skills`}</div>
        </div>
      </div>

      ${D?e`
            <div class="callout warn" style="margin-top: 16px">
              You have unsaved config changes.
            </div>
          `:t}

      <div class="agent-model-select" style="margin-top: 20px;">
        <div class="label">Model Selection</div>
        <div class="agent-model-fields">
          <label class="field">
            <span>Primary model${j?` (default)`:``}</span>
            <select
              .value=${F??``}
              ?disabled=${R}
              @change=${e=>k(x.id,e.target.value||null)}
            >
              ${j?e` <option value="" ?selected=${!F}>Not set</option> `:e`
                    <option value="" ?selected=${!F}>
                      ${P?`Inherit default (${P})`:`Inherit default`}
                    </option>
                  `}
              ${b(S,le??void 0,n.modelCatalog,F)}
            </select>
          </label>
          <div class="field">
            <span>Fallbacks</span>
            <div
              class="agent-chip-input"
              @click=${e=>{let t=e.currentTarget.querySelector(`input`);t&&t.focus()}}
            >
              ${I.map((t,n)=>e`
                  <span class="chip">
                    ${t}
                    <button
                      type="button"
                      class="chip-remove"
                      ?disabled=${R}
                      @click=${()=>de(n)}
                    >
                      &times;
                    </button>
                  </span>
                `)}
              <input
                ?disabled=${R}
                placeholder=${I.length===0?`provider/model`:``}
                @keydown=${e=>{let t=e.target;if(e.key===`Enter`||e.key===`,`){e.preventDefault();let n=c(t.value);n.length>0&&(A(x.id,[...I,...n]),t.value=``)}}}
                @blur=${e=>{let t=e.target,n=c(t.value);n.length>0&&(A(x.id,[...I,...n]),t.value=``)}}
              />
            </div>
          </div>
        </div>
        <div class="agent-model-actions">
          <button
            type="button"
            class="btn btn--sm"
            ?disabled=${T}
            @click=${O}
          >
            ${`重新加载配置`}
          </button>
          <button
            type="button"
            class="btn btn--sm primary"
            ?disabled=${E||!D}
            @click=${ne}
          >
            ${E?`Saving…`:`Save`}
          </button>
        </div>
      </div>
    </section>
  `}var se=Object.defineProperty,ce=(e,t,n)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,P=(e,t,n)=>ce(e,typeof t==`symbol`?t:t+``,n),le={classPrefix:`cm-`,theme:`github`,linkTarget:`_blank`,sanitize:!1,plugins:[],customRenderers:{}};function F(e){return{...le,...e,plugins:(e==null?void 0:e.plugins)??[],customRenderers:(e==null?void 0:e.customRenderers)??{}}}function I(e,t){return typeof t==`function`?t(e):e}function L(e,t){let n=F(t),r=n.classPrefix,i=e;for(let e of n.plugins)e.transformBlock&&(i=i.map(e.transformBlock));let a=`<div class="${r}preview">${i.map(e=>{for(let t of n.plugins)if(t.renderBlock){let r=t.renderBlock(e,()=>R(e,n));if(r!==null)return r}let t=n.customRenderers[e.type];return t?t(e):R(e,n)}).join(`
`)}</div>`;return a=I(a,n.sanitize),a}async function ue(e,t){let n=F(t);for(let e of n.plugins)e.init&&await e.init();let r=L(e,t);for(let e of n.plugins)e.postProcess&&(r=await e.postProcess(r));return r}function R(e,t){let n=t.classPrefix;switch(e.type){case`paragraph`:return`<p class="${n}paragraph">${z(e.content,t)}</p>`;case`heading`:return de(e,t);case`bulletList`:return fe(e,t);case`numberedList`:return pe(e,t);case`checkList`:return me(e,t);case`codeBlock`:return he(e,t);case`blockquote`:return`<blockquote class="${n}blockquote">${z(e.content,t)}</blockquote>`;case`table`:return ge(e,t);case`image`:return _e(e,t);case`divider`:return`<hr class="${n}divider" />`;case`callout`:return ve(e,t);default:return`<div class="${n}unknown">${z(e.content,t)}</div>`}}function de(e,t){let n=t.classPrefix,r=e.props.level,i=`h${r}`;return`<${i} class="${n}heading ${n}h${r}">${z(e.content,t)}</${i}>`}function fe(e,t){return`<ul class="${t.classPrefix}bullet-list">
${e.children.map(e=>`<li>${z(e.content,t)}</li>`).join(`
`)}
</ul>`}function pe(e,t){return`<ol class="${t.classPrefix}numbered-list">
${e.children.map(e=>`<li>${z(e.content,t)}</li>`).join(`
`)}
</ol>`}function me(e,t){let n=t.classPrefix,r=e.props.checked;return`
<div class="${n}checklist-item">
  <input type="checkbox" ${r?`checked disabled`:`disabled`} />
  <span class="${r?`${n}checked`:``}">${z(e.content,t)}</span>
</div>`.trim()}function he(e,t){let n=t.classPrefix,r=e.content.map(e=>e.text).join(``),i=e.props.language||``,a=B(r),o=i?` language-${i}`:``;return`<pre class="${n}code-block"${i?` data-language="${i}"`:``}><code class="${n}code${o}">${a}</code></pre>`}function ge(e,t){let n=t.classPrefix,{headers:r,rows:i,alignments:a}=e.props,o=e=>{let t=a==null?void 0:a[e];return t?` style="text-align: ${t}"`:``};return`<table class="${n}table">
${r.length>0?`<thead><tr>${r.map((e,t)=>`<th${o(t)}>${B(e)}</th>`).join(``)}</tr></thead>`:``}
<tbody>
${i.map(e=>`<tr>${e.map((e,t)=>`<td${o(t)}>${B(e)}</td>`).join(``)}</tr>`).join(`
`)}
</tbody>
</table>`}function _e(e,t){let n=t.classPrefix,{url:r,alt:i,title:a,width:o,height:s}=e.props,c=i?` alt="${B(i)}"`:` alt=""`,l=a?` title="${B(a)}"`:``,u=o?` width="${o}"`:``,d=s?` height="${s}"`:``;return`<figure class="${n}image">${`<img src="${B(r)}"${c}${l}${u}${d} />`}${i?`<figcaption>${B(i)}</figcaption>`:``}</figure>`}function ve(e,t){let n=t.classPrefix,r=e.props.type;return`
<div class="${n}callout ${n}callout-${r}" role="alert">
  <strong class="${n}callout-title">${r}</strong>
  <div class="${n}callout-content">${z(e.content,t)}</div>
</div>`.trim()}function z(e,t){return e.map(e=>ye(e,t)).join(``)}function ye(e,t){let n=B(e.text),r=e.styles;if(r.code&&(n=`<code>${n}</code>`),r.highlight&&(n=`<mark>${n}</mark>`),r.strikethrough&&(n=`<del>${n}</del>`),r.underline&&(n=`<u>${n}</u>`),r.italic&&(n=`<em>${n}</em>`),r.bold&&(n=`<strong>${n}</strong>`),r.link){let e=t.linkTarget===`_blank`?` target="_blank" rel="noopener noreferrer"`:``,i=r.link.title?` title="${B(r.link.title)}"`:``;n=`<a href="${B(r.link.url)}"${i}${e}>${n}</a>`}return n}function B(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function be(e){return[...[1,2,3,4,5,6].map(t=>({tag:`h${t}`,classes:[`${e}heading`,`${e}h${t}`]})),{tag:`p`,classes:[`${e}paragraph`]},{tag:`ul`,classes:[`${e}bullet-list`]},{tag:`ol`,classes:[`${e}numbered-list`]},{tag:`pre`,classes:[`${e}code-block`]},{tag:`blockquote`,classes:[`${e}blockquote`]},{tag:`hr`,classes:[`${e}divider`]},{tag:`table`,classes:[`${e}table`]},{tag:`figure`,classes:[`${e}image`]}]}function xe(e,t){let n=t.join(` `),r=/\bclass\s*=\s*"([^"]*)"/i,i=e.match(r);return i?e.replace(r,`class="${n} ${i[1]}"`):e.endsWith(`/>`)?e.slice(0,-2)+` class="${n}" />`:e.slice(0,-1)+` class="${n}">`}function Se(e,t){return e.replace(RegExp(`(?<!<figure[^>]*>\\s*)(<img\\s[^>]*\\/?>)(?!\\s*<\\/figure>)`,`gi`),`<figure class="${t}image">$1</figure>`)}function Ce(e,t){let n=(t==null?void 0:t.classPrefix)??`cm-`,r=(t==null?void 0:t.wrapperClass)??`${n}preview`,i=be(n),a=e;for(let{tag:e,classes:t}of i){let n=RegExp(`<${e}(\\s[^>]*)?>|<${e}\\s*\\/?>`,`gi`);a=a.replace(n,e=>xe(e,t))}return a=Se(a,n),a=`<div class="${r}">${a}</div>`,typeof(t==null?void 0:t.sanitize)==`function`&&(a=t.sanitize(a)),a}async function we(e){try{return(await ee(()=>import(`./preview-BXm_lUys.js`),[])).parse(e)}catch{throw Error(`@create-markdown/core is required to parse markdown in <markdown-preview>. Install it, or provide pre-parsed blocks via the blocks attribute / setBlocks().`)}}P(class extends HTMLElement{constructor(){super(),P(this,`_shadow`,null),P(this,`plugins`,[]),P(this,`defaultTheme`,`github`),P(this,`styleElement`),P(this,`contentElement`);let e=this.constructor._shadowMode;e!==`none`&&(this._shadow=this.attachShadow({mode:e})),this.styleElement=document.createElement(`style`),this.renderRoot.appendChild(this.styleElement),this.contentElement=document.createElement(`div`),this.contentElement.className=`markdown-preview-content`,this.renderRoot.appendChild(this.contentElement),this.updateStyles()}static get observedAttributes(){return[`theme`,`link-target`,`async`]}get renderRoot(){return this._shadow??this}connectedCallback(){this.render()}attributeChangedCallback(e,t,n){this.render()}setPlugins(e){this.plugins=e,this.render()}setDefaultTheme(e){this.defaultTheme=e,this.render()}getMarkdown(){let e=this.getAttribute(`blocks`);if(e)try{return JSON.parse(e).map(e=>e.content.map(e=>e.text).join(``)).join(`

`)}catch{return``}return this.textContent||``}setMarkdown(e){this.textContent=e,this.render()}setBlocks(e){this.setAttribute(`blocks`,JSON.stringify(e)),this.render()}getOptions(){return{theme:this.getAttribute(`theme`)||this.defaultTheme,linkTarget:this.getAttribute(`link-target`)||`_blank`,plugins:this.plugins}}async getBlocks(){let e=this.getAttribute(`blocks`);if(e)try{return JSON.parse(e)}catch{return console.warn(`Invalid blocks JSON in markdown-preview element`),[]}return we(this.textContent||``)}async render(){let e=await this.getBlocks(),t=this.getOptions(),n=this.hasAttribute(`async`)||this.plugins.length>0;try{let r;r=n?await ue(e,t):L(e,t),this.contentElement.innerHTML=r}catch(e){console.error(`Error rendering markdown preview:`,e),this.contentElement.innerHTML=`<div class="error">Error rendering content</div>`}}updateStyles(){let e=this.plugins.filter(e=>e.getCSS).map(e=>e.getCSS()).join(`

`),t=this._shadow?`:host { display: block; }`:`markdown-preview { display: block; }`;this.styleElement.textContent=`
${t}

.markdown-preview-content {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

.error {
  color: #cf222e;
  padding: 1rem;
  background: #ffebe9;
  border-radius: 6px;
}

${e}
    `.trim()}},`_shadowMode`,`open`);var Te;function Ee(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var V=Ee();function De(e){V=e}var H={exec:()=>null};function U(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(W.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var Oe=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),W={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[	 ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ 	][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`),blockquoteBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}>`)},ke=/^(?:[ \t]*(?:\n|$))+/,Ae=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,je=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,G=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Me=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Ne=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Pe=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Fe=U(Pe).replace(/bull/g,Ne).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(),Ie=U(Pe).replace(/bull/g,Ne).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(),Le=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Re=/^[^\n]+/,ze=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Be=U(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,ze).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ve=U(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Ne).getRegex(),He=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,Ue=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,We=U(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ 	]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ 	]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ 	]*)+\\n|$))`,`i`).replace(`comment`,Ue).replace(`tag`,He).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ge=U(Le).replace(`hr`,G).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,He).getRegex(),Ke={blockquote:U(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,Ge).getRegex(),code:Ae,def:Be,fences:je,heading:Me,hr:G,html:We,lheading:Fe,list:Ve,newline:ke,paragraph:Ge,table:H,text:Re},qe=U(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,G).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`,He).getRegex(),Je={...Ke,lheading:Ie,table:qe,paragraph:U(Le).replace(`hr`,G).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,qe).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,He).getRegex()},Ye={...Ke,html:U(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,Ue).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:H,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:U(Le).replace(`hr`,G).replace(`heading`,` *#{1,6} *[^
]`).replace(`lheading`,Fe).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},Xe=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Ze=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Qe=/^( {2,}|\\)\n(?!\s*$)/,$e=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,K=/[\p{P}\p{S}]/u,et=/[\s\p{P}\p{S}]/u,tt=/[^\s\p{P}\p{S}]/u,nt=U(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,et).getRegex(),rt=/(?!~)[\p{P}\p{S}]/u,it=/(?!~)[\s\p{P}\p{S}]/u,at=/(?:[^\s\p{P}\p{S}]|~)/u,ot=U(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,Oe?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),st=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,ct=U(st,`u`).replace(/punct/g,K).getRegex(),lt=U(st,`u`).replace(/punct/g,rt).getRegex(),ut=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,dt=U(ut,`gu`).replace(/notPunctSpace/g,tt).replace(/punctSpace/g,et).replace(/punct/g,K).getRegex(),ft=U(ut,`gu`).replace(/notPunctSpace/g,at).replace(/punctSpace/g,it).replace(/punct/g,rt).getRegex(),pt=U(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,tt).replace(/punctSpace/g,et).replace(/punct/g,K).getRegex(),mt=U(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,K).getRegex(),ht=U(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,tt).replace(/punctSpace/g,et).replace(/punct/g,K).getRegex(),gt=U(/\\(punct)/,`gu`).replace(/punct/g,K).getRegex(),_t=U(/^<(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(),vt=U(Ue).replace(`(?:-->|$)`,`-->`).getRegex(),yt=U(`^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`,vt).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),bt=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,xt=U(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,bt).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),St=U(/^!?\[(label)\]\[(ref)\]/).replace(`label`,bt).replace(`ref`,ze).getRegex(),Ct=U(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,ze).getRegex(),wt=U(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,St).replace(`nolink`,Ct).getRegex(),Tt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Et={_backpedal:H,anyPunctuation:gt,autolink:_t,blockSkip:ot,br:Qe,code:Ze,del:H,delLDelim:H,delRDelim:H,emStrongLDelim:ct,emStrongRDelimAst:dt,emStrongRDelimUnd:pt,escape:Xe,link:xt,nolink:Ct,punctuation:nt,reflink:St,reflinkSearch:wt,tag:yt,text:$e,url:H},Dt={...Et,link:U(/^!?\[(label)\]\((.*?)\)/).replace(`label`,bt).getRegex(),reflink:U(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,bt).getRegex()},Ot={...Et,emStrongRDelimAst:ft,emStrongLDelim:lt,delLDelim:mt,delRDelim:ht,url:U(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,Tt).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:U(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,Tt).getRegex()},kt={...Ot,br:U(Qe).replace(`{2,}`,`*`).getRegex(),text:U(Ot.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},At={normal:Ke,gfm:Je,pedantic:Ye},q={normal:Et,gfm:Ot,breaks:kt,pedantic:Dt},jt={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},Mt=e=>jt[e];function J(e,t){if(t){if(W.escapeTest.test(e))return e.replace(W.escapeReplace,Mt)}else if(W.escapeTestNoEncode.test(e))return e.replace(W.escapeReplaceNoEncode,Mt);return e}function Nt(e){try{e=encodeURI(e).replace(W.percentDecode,`%`)}catch{return null}return e}function Pt(e,t){var n;let r=e.replace(W.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(W.splitPipe),i=0;if(r[0].trim()||r.shift(),r.length>0&&!((n=r.at(-1))!=null&&n.trim())&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push(``);for(;i<r.length;i++)r[i]=r[i].trim().replace(W.slashPipe,`|`);return r}function Y(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function Ft(e){let t=e.split(`
`),n=t.length-1;for(;n>=0&&W.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
`)}function It(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 Lt(e,t=0){let n=t,r=``;for(let t of e)if(t===`	`){let e=4-n%4;r+=` `.repeat(e),n+=e}else r+=t,n++;return r}function Rt(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function zt(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
`).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(`
`)}var Bt=class{constructor(e){y(this,`options`,void 0),y(this,`rules`,void 0),y(this,`lexer`,void 0),this.options=e||V}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 e=this.options.pedantic?t[0]:Ft(t[0]);return{type:`code`,raw:e,codeBlockStyle:`indented`,text:e.replace(this.rules.other.codeRemoveIndent,``)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=zt(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=Y(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:Y(t[0],`
`),depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:Y(t[0],`
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=Y(t[0],`
`).split(`
`),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o;for(o=0;o<e.length;o++)if(this.rules.other.blockquoteStart.test(e[o]))a.push(e[o]),t=!0;else if(!t)a.push(e[o]);else break;e=e.slice(o);let s=a.join(`
`),c=s.replace(this.rules.other.blockquoteSetextReplace,`
    $1`).replace(this.rules.other.blockquoteSetextReplace2,``);n=n?`${n}
${s}`:s,r=r?`${r}
${c}`:c;let l=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,i,!0),this.lexer.state.top=l,e.length===0)break;let u=i.at(-1);if((u==null?void 0:u.type)===`code`)break;if((u==null?void 0:u.type)===`blockquote`){let t=u,a=t.raw+`
`+e.join(`
`),o=this.blockquote(a);i[i.length-1]=o,n=n.substring(0,n.length-t.raw.length)+o.raw,r=r.substring(0,r.length-t.text.length)+o.text;break}else if((u==null?void 0:u.type)===`list`){let t=u,a=t.raw+`
`+e.join(`
`),o=this.list(a);i[i.length-1]=o,n=n.substring(0,n.length-u.raw.length)+o.raw,r=r.substring(0,r.length-t.raw.length)+o.raw,e=a.substring(i.at(-1).raw.length).split(`
`);continue}}return{type:`blockquote`,raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,i={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 a=this.rules.other.listItemRegex(n),o=!1;for(;e;){let n=!1,r=``,s=``;if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let c=Lt(t[2].split(`
`,1)[0],t[1].length),l=e.split(`
`,1)[0],u=!c.trim(),d=0;if(this.options.pedantic?(d=2,s=c.trimStart()):u?d=t[1].length+1:(d=c.search(this.rules.other.nonSpaceChar),d=d>4?1:d,s=c.slice(d),d+=t[1].length),u&&this.rules.other.blankLine.test(l)&&(r+=l+`
`,e=e.substring(l.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(d),n=this.rules.other.hrRegex(d),i=this.rules.other.fencesBeginRegex(d),a=this.rules.other.headingBeginRegex(d),o=this.rules.other.htmlBeginRegex(d),f=this.rules.other.blockquoteBeginRegex(d);for(;e;){let p=e.split(`
`,1)[0],m;if(l=p,this.options.pedantic?(l=l.replace(this.rules.other.listReplaceNesting,`  `),m=l):m=l.replace(this.rules.other.tabCharGlobal,`    `),i.test(l)||a.test(l)||o.test(l)||f.test(l)||t.test(l)||n.test(l))break;if(m.search(this.rules.other.nonSpaceChar)>=d||!l.trim())s+=`
`+m.slice(d);else{if(u||c.replace(this.rules.other.tabCharGlobal,`    `).search(this.rules.other.nonSpaceChar)>=4||i.test(c)||a.test(c)||n.test(c))break;s+=`
`+l}u=!l.trim(),r+=p+`
`,e=e.substring(p.length+1),c=m.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0)),i.items.push({type:`list_item`,raw:r,task:!!this.options.gfm&&this.rules.other.listIsTask.test(s),loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e of i.items){this.lexer.state.top=!1,e.tokens=this.lexer.blockTokens(e.text,[]);let t=e.tokens[0];if(e.task&&((t==null?void 0:t.type)===`text`||(t==null?void 0:t.type)===`paragraph`)){e.text=e.text.replace(this.rules.other.listReplaceTask,``),t.raw=t.raw.replace(this.rules.other.listReplaceTask,``),t.text=t.text.replace(this.rules.other.listReplaceTask,``);for(let e=this.lexer.inlineQueue.length-1;e>=0;e--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[e].src)){this.lexer.inlineQueue[e].src=this.lexer.inlineQueue[e].src.replace(this.rules.other.listReplaceTask,``);break}let n=this.rules.other.listTaskCheckbox.exec(e.raw);if(n){let t={type:`checkbox`,raw:n[0]+` `,checked:n[0]!==`[ ]`};e.checked=t.checked,i.loose?e.tokens[0]&&[`paragraph`,`text`].includes(e.tokens[0].type)&&`tokens`in e.tokens[0]&&e.tokens[0].tokens?(e.tokens[0].raw=t.raw+e.tokens[0].raw,e.tokens[0].text=t.raw+e.tokens[0].text,e.tokens[0].tokens.unshift(t)):e.tokens.unshift({type:`paragraph`,raw:t.raw,text:t.raw,tokens:[t]}):e.tokens.unshift(t)}}else e.task&&(e.task=!1);if(!i.loose){let t=e.tokens.filter(e=>e.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}}if(i.loose)for(let e of i.items){e.loose=!0;for(let t of e.tokens)t.type===`text`&&(t.type=`paragraph`)}return i}}html(e){let t=this.rules.block.html.exec(e);if(t){let e=Ft(t[0]);return{type:`html`,block:!0,raw:e,pre:t[1]===`pre`||t[1]===`script`||t[1]===`style`,text:e}}}def(e){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal,` `),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,`$1`).replace(this.rules.inline.anyPunctuation,`$1`):``,r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,`$1`):t[3];return{type:`def`,tag:e,raw:Y(t[0],`
`),href:n,title:r}}}table(e){var t;let n=this.rules.block.table.exec(e);if(!n||!this.rules.other.tableDelimiter.test(n[2]))return;let r=Pt(n[1]),i=n[2].replace(this.rules.other.tableAlignChars,``).split(`|`),a=(t=n[3])!=null&&t.trim()?n[3].replace(this.rules.other.tableRowBlankLine,``).split(`
`):[],o={type:`table`,raw:Y(n[0],`
`),header:[],align:[],rows:[]};if(r.length===i.length){for(let e of i)this.rules.other.tableAlignRight.test(e)?o.align.push(`right`):this.rules.other.tableAlignCenter.test(e)?o.align.push(`center`):this.rules.other.tableAlignLeft.test(e)?o.align.push(`left`):o.align.push(null);for(let e=0;e<r.length;e++)o.header.push({text:r[e],tokens:this.lexer.inline(r[e]),header:!0,align:o.align[e]});for(let e of a)o.rows.push(Pt(e,o.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:o.align[t]})));return o}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let e=t[1].trim();return{type:`heading`,raw:Y(t[0],`
`),depth:t[2].charAt(0)===`=`?1:2,text:e,tokens:this.lexer.inline(e)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===`
`?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}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 e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=Y(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=It(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),Rt(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.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 e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return Rt(n,e,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 n=[...r[0]].length-1,i,a,o=n,s=0,c=r[0][0]===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);(r=c.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])&&n%3&&!((n+a)%3)){s+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+s);let t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+a);if(Math.min(n,a)%2){let e=c.slice(1,-1);return{type:`em`,raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}let l=c.slice(2,-2);return{type:`strong`,raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}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 n=[...r[0]].length-1,i,a,o=n,s=this.rules.inline.delRDelim;for(s.lastIndex=0,t=t.slice(-1*e.length+n);(r=s.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(a=[...i].length,a!==n))continue;if(r[3]||r[4]){o+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o);let t=[...r[0]][0].length,s=e.slice(0,n+r.index+t+a),c=s.slice(n,-n);return{type:`del`,raw:s,text:c,tokens:this.lexer.inlineTokens(c)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,r;if(t[2]===`@`)e=t[0],r=`mailto:`+e;else{var n;let i;do i=t[0],t[0]=((n=this.rules.inline._backpedal.exec(t[0]))==null?void 0:n[0])??``;while(i!==t[0]);e=t[0],r=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:r,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},X=class e{constructor(e){y(this,`tokens`,void 0),y(this,`options`,void 0),y(this,`state`,void 0),y(this,`inlineQueue`,void 0),y(this,`tokenizer`,void 0),this.tokens=[],this.tokens.links=Object.create(null),this.options=e||V,this.options.tokenizer=this.options.tokenizer||new Bt,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 t={other:W,block:At.normal,inline:q.normal};this.options.pedantic?(t.block=At.pedantic,t.inline=q.pedantic):this.options.gfm&&(t.block=At.gfm,this.options.breaks?t.inline=q.breaks:t.inline=q.gfm),this.tokenizer.rules=t}static get rules(){return{block:At,inline:q}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(W.carriageReturn,`
`),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(W.tabCharGlobal,`    `).replace(W.spaceLine,``));let r=1/0;for(;e;){var i,a;if(e.length<r)r=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let o;if(!((i=this.options.extensions)==null||(i=i.block)==null)&&i.some(n=>(o=n.call({lexer:this},e,t))?(e=e.substring(o.raw.length),t.push(o),!0):!1))continue;if(o=this.tokenizer.space(e)){e=e.substring(o.raw.length);let n=t.at(-1);o.raw.length===1&&n!==void 0?n.raw+=`
`:t.push(o);continue}if(o=this.tokenizer.code(e)){e=e.substring(o.raw.length);let n=t.at(-1);(n==null?void 0:n.type)===`paragraph`||(n==null?void 0:n.type)===`text`?(n.raw+=(n.raw.endsWith(`
`)?``:`
`)+o.raw,n.text+=`
`+o.text,this.inlineQueue.at(-1).src=n.text):t.push(o);continue}if(o=this.tokenizer.fences(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.heading(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.hr(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.blockquote(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.list(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.html(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.def(e)){e=e.substring(o.raw.length);let n=t.at(-1);(n==null?void 0:n.type)===`paragraph`||(n==null?void 0:n.type)===`text`?(n.raw+=(n.raw.endsWith(`
`)?``:`
`)+o.raw,n.text+=`
`+o.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[o.tag]||(this.tokens.links[o.tag]={href:o.href,title:o.title},t.push(o));continue}if(o=this.tokenizer.table(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.lheading(e)){e=e.substring(o.raw.length),t.push(o);continue}let s=e;if((a=this.options.extensions)!=null&&a.startBlock){let t=1/0,n=e.slice(1),r;this.options.extensions.startBlock.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(s=e.substring(0,t+1))}if(this.state.top&&(o=this.tokenizer.paragraph(s))){let r=t.at(-1);n&&(r==null?void 0:r.type)===`paragraph`?(r.raw+=(r.raw.endsWith(`
`)?``:`
`)+o.raw,r.text+=`
`+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):t.push(o),n=s.length!==e.length,e=e.substring(o.raw.length);continue}if(o=this.tokenizer.text(e)){e=e.substring(o.raw.length);let n=t.at(-1);(n==null?void 0:n.type)===`text`?(n.raw+=(n.raw.endsWith(`
`)?``:`
`)+o.raw,n.text+=`
`+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(o);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){var n;this.tokenizer.lexer=this;let r=e,i=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;(i=this.tokenizer.rules.inline.reflinkSearch.exec(r))!==null;)e.includes(i[0].slice(i[0].lastIndexOf(`[`)+1,-1))&&(r=r.slice(0,i.index)+`[`+`a`.repeat(i[0].length-2)+`]`+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(i=this.tokenizer.rules.inline.anyPunctuation.exec(r))!==null;)r=r.slice(0,i.index)+`++`+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let a;for(;(i=this.tokenizer.rules.inline.blockSkip.exec(r))!==null;)a=i[2]?i[2].length:0,r=r.slice(0,i.index+a)+`[`+`a`.repeat(i[0].length-a-2)+`]`+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=((n=this.options.hooks)==null||(n=n.emStrongMask)==null?void 0:n.call({lexer:this},r))??r;let o=!1,s=``,c=1/0;for(;e;){var l,u;if(e.length<c)c=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}o||(s=``),o=!1;let n;if(!((l=this.options.extensions)==null||(l=l.inline)==null)&&l.some(r=>(n=r.call({lexer:this},e,t))?(e=e.substring(n.raw.length),t.push(n),!0):!1))continue;if(n=this.tokenizer.escape(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.tag(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.link(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(n.raw.length);let r=t.at(-1);n.type===`text`&&(r==null?void 0:r.type)===`text`?(r.raw+=n.raw,r.text+=n.text):t.push(n);continue}if(n=this.tokenizer.emStrong(e,r,s)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.codespan(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.br(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.del(e,r,s)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.autolink(e)){e=e.substring(n.raw.length),t.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(e))){e=e.substring(n.raw.length),t.push(n);continue}let i=e;if((u=this.options.extensions)!=null&&u.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(n=this.tokenizer.inlineText(i)){e=e.substring(n.raw.length),n.raw.slice(-1)!==`_`&&(s=n.raw.slice(-1)),o=!0;let r=t.at(-1);(r==null?void 0:r.type)===`text`?(r.raw+=n.raw,r.text+=n.text):t.push(n);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t=`Infinite loop on byte: `+e;if(this.options.silent)console.error(t);else throw Error(t)}},Vt=class{constructor(e){y(this,`options`,void 0),y(this,`parser`,void 0),this.options=e||V}space(e){return``}code({text:e,lang:t,escaped:n}){var r;let i=(r=(t||``).match(W.notSpaceStart))==null?void 0:r[0],a=e.replace(W.endingNewline,``)+`
`;return i?`<pre><code class="language-`+J(i)+`">`+(n?a:J(a,!0))+`</code></pre>
`:`<pre><code>`+(n?a:J(a,!0))+`</code></pre>
`}blockquote({tokens:e}){return`<blockquote>
${this.parser.parse(e)}</blockquote>
`}html({text:e}){return e}def(e){return``}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
`}hr(e){return`<hr>
`}list(e){let t=e.ordered,n=e.start,r=``;for(let t=0;t<e.items.length;t++){let n=e.items[t];r+=this.listitem(n)}let i=t?`ol`:`ul`,a=t&&n!==1?` start="`+n+`"`:``;return`<`+i+a+`>
`+r+`</`+i+`>
`}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
`}checkbox({checked:e}){return`<input `+(e?`checked="" `:``)+`disabled="" type="checkbox"> `}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
`}table(e){let t=``,n=``;for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r=``;for(let t=0;t<e.rows.length;t++){let i=e.rows[t];n=``;for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
<thead>
`+t+`</thead>
`+r+`</table>
`}tablerow({text:e}){return`<tr>
${e}</tr>
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
`}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>${J(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),i=Nt(e);if(i===null)return r;e=i;let a=`<a href="`+e+`"`;return t&&(a+=` title="`+J(t)+`"`),a+=`>`+r+`</a>`,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Nt(e);if(i===null)return J(n);e=i;let a=`<img src="${e}" alt="${J(n)}"`;return t&&(a+=` title="${J(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:J(e.text)}},Ht=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}},Z=class e{constructor(e){y(this,`options`,void 0),y(this,`renderer`,void 0),y(this,`textRenderer`,void 0),this.options=e||V,this.options.renderer=this.options.renderer||new Vt,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Ht}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){this.renderer.parser=this;let t=``;for(let r=0;r<e.length;r++){var n;let i=e[r];if(!((n=this.options.extensions)==null||(n=n.renderers)==null)&&n[i.type]){let e=i,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(n!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`html`,`def`,`paragraph`,`text`].includes(e.type)){t+=n||``;continue}}let a=i;switch(a.type){case`space`:t+=this.renderer.space(a);break;case`hr`:t+=this.renderer.hr(a);break;case`heading`:t+=this.renderer.heading(a);break;case`code`:t+=this.renderer.code(a);break;case`table`:t+=this.renderer.table(a);break;case`blockquote`:t+=this.renderer.blockquote(a);break;case`list`:t+=this.renderer.list(a);break;case`checkbox`:t+=this.renderer.checkbox(a);break;case`html`:t+=this.renderer.html(a);break;case`def`:t+=this.renderer.def(a);break;case`paragraph`:t+=this.renderer.paragraph(a);break;case`text`:t+=this.renderer.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let n=``;for(let i=0;i<e.length;i++){var r;let a=e[i];if(!((r=this.options.extensions)==null||(r=r.renderers)==null)&&r[a.type]){let e=this.options.extensions.renderers[a.type].call({parser:this},a);if(e!==!1||![`escape`,`html`,`link`,`image`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(a.type)){n+=e||``;continue}}let o=a;switch(o.type){case`escape`:n+=t.text(o);break;case`html`:n+=t.html(o);break;case`link`:n+=t.link(o);break;case`image`:n+=t.image(o);break;case`checkbox`:n+=t.checkbox(o);break;case`strong`:n+=t.strong(o);break;case`em`:n+=t.em(o);break;case`codespan`:n+=t.codespan(o);break;case`br`:n+=t.br(o);break;case`del`:n+=t.del(o);break;case`text`:n+=t.text(o);break;default:{let e=`Token with "`+o.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},Ut=(Te=class{constructor(e){y(this,`options`,void 0),y(this,`block`,void 0),this.options=e||V}preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?X.lex:X.lexInline}provideParser(e=this.block){return e?Z.parse:Z.parseInline}},y(Te,`passThroughHooks`,new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`])),y(Te,`passThroughHooksRespectAsync`,new Set([`preprocess`,`postprocess`,`processAllTokens`])),Te),Q=new class{constructor(...e){y(this,`defaults`,Ee()),y(this,`options`,this.setOptions),y(this,`parse`,this.parseMarkdown(!0)),y(this,`parseInline`,this.parseMarkdown(!1)),y(this,`Parser`,Z),y(this,`Renderer`,Vt),y(this,`TextRenderer`,Ht),y(this,`Lexer`,X),y(this,`Tokenizer`,Bt),y(this,`Hooks`,Ut),this.use(...e)}walkTokens(e,t){let n=[];for(let i of e)switch(n=n.concat(t.call(this,i)),i.type){case`table`:{let e=i;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=i;n=n.concat(this.walkTokens(e.items,t));break}default:{var r;let e=i;!((r=this.defaults.extensions)==null||(r=r.childTokens)==null)&&r[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new Vt(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new Bt(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new Ut;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];Ut.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async&&Ut.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:t[r]=(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return X.lex(e,t??this.defaults)}parser(e,t){return Z.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(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 a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer(e):e?X.lex:X.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser(e):e?Z.parse:Z.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer(e):e?X.lex:X.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser(e):e?Z.parse:Z.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+J(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function $(e,t){return Q.parse(e,t)}$.options=$.setOptions=function(e){return Q.setOptions(e),$.defaults=Q.defaults,De($.defaults),$},$.getDefaults=Ee,$.defaults=V,$.use=function(...e){return Q.use(...e),$.defaults=Q.defaults,De($.defaults),$},$.walkTokens=function(e,t){return Q.walkTokens(e,t)},$.parseInline=Q.parseInline,$.Parser=Z,$.parser=Z.parse,$.Renderer=Vt,$.TextRenderer=Ht,$.Lexer=X,$.lexer=X.lex,$.Tokenizer=Bt,$.Hooks=Ut,$.parse=$,$.options,$.setOptions,$.use,$.walkTokens,$.parseInline,Z.parse,X.lex;function Wt(e){let t=e.trim();return t?t.split(/\s+/).length:0}function Gt(e){return e.length===0?0:e.split(/\r?\n/).length}function Kt(e){return e<=0?`空草稿`:`${String(Math.max(1,Math.round(e/220)))} 分钟阅读`}function qt(e){var t;let n=(t=e.split(`.`).pop())==null?void 0:t.trim().toLowerCase();return n===`md`||n===`markdown`?`Markdown 预览`:n?`${n.toUpperCase()} 预览`:`预览`}function Jt(e,t){let n=e.trim(),r=t==null?void 0:t.trim();if(!n)return``;if(r&&n===r)return`.`;if(r&&n.startsWith(`${r}/`))return n.slice(r.length+1)||`.`;let i=n.split(/[\\/]+/);for(let e=i.length-1;e>=0;--e){let t=i[e];if(t)return t}return n}function Yt(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`preview`}function Xt(e,t){if(!(e instanceof HTMLElement))return;let n=t?`收起预览`:`展开预览`;e.classList.toggle(`is-fullscreen`,t),e.setAttribute(`aria-pressed`,String(t)),e.setAttribute(`aria-label`,n),e.setAttribute(`title`,n)}function Zt(t,n,r){return e`
    <section class="card">
      <div class="card-title">${`代理上下文`}</div>
      <div class="card-sub">${n}</div>
      <div class="agents-overview-grid" style="margin-top: 16px;">
        <div class="agent-kv">
          <div class="label">${`工作区`}</div>
          <div>
            <button
              type="button"
              class="workspace-link mono"
              @click=${()=>r(`files`)}
              title=${`打开文件标签`}
            >
              ${t.workspace}
            </button>
          </div>
        </div>
        <div class="agent-kv">
          <div class="label">${`主模型`}</div>
          <div class="mono">${t.model}</div>
        </div>
        <div class="agent-kv">
          <div class="label">${`运行时`}</div>
          <div class="mono">${t.runtime}</div>
        </div>
        <div class="agent-kv">
          <div class="label">${`身份名称`}</div>
          <div>${t.identityName}</div>
        </div>
        <div class="agent-kv">
          <div class="label">${`身份头像`}</div>
          <div>${t.identityAvatar}</div>
        </div>
        <div class="agent-kv">
          <div class="label">${`技能筛选器`}</div>
          <div>${t.skillsLabel}</div>
        </div>
        <div class="agent-kv">
          <div class="label">${`默认`}</div>
          <div>${t.isDefault?`是`:`否`}</div>
        </div>
      </div>
    </section>
  `}function Qt(e,t){var n,r;let i=(n=e.channelMeta)==null?void 0:n.find(e=>e.id===t);return i!=null&&i.label?i.label:((r=e.channelLabels)==null?void 0:r[t])??t}function $t(e){var t;if(!e)return[];let n=new Set;for(let t of e.channelOrder??[])n.add(t);for(let t of e.channelMeta??[])n.add(t.id);for(let t of Object.keys(e.channelAccounts??{}))n.add(t);let r=[],i=(t=e.channelOrder)!=null&&t.length?e.channelOrder:Array.from(n);for(let e of i)n.has(e)&&(r.push(e),n.delete(e));for(let e of n)r.push(e);return r.map(t=>{var n;return{id:t,label:Qt(e,t),accounts:((n=e.channelAccounts)==null?void 0:n[t])??[]}})}var en=[`groupPolicy`,`streamMode`,`dmPolicy`];function tn(e){let t=0,n=0,r=0;for(let i of e){let e=i.probe&&typeof i.probe==`object`&&`ok`in i.probe?!!i.probe.ok:!1;(i.connected===!0||i.running===!0||e)&&(t+=1),i.configured&&(n+=1),i.enabled&&(r+=1)}return{total:e.length,connected:t,configured:n,enabled:r}}function nn(n){let r=$t(n.snapshot),i=n.lastSuccess?v(n.lastSuccess):`从未`;return e`
    <section class="grid grid-cols-2">
      ${Zt(n.context,`工作区、身份和模型配置。`,n.onSelectPanel)}
      <section class="card">
        <div class="row" style="justify-content: space-between;">
          <div>
            <div class="card-title">${`频道`}</div>
            <div class="card-sub">${`Gateway 全局频道状态快照。`}</div>
          </div>
          <button class="btn btn--sm" ?disabled=${n.loading} @click=${n.onRefresh}>
            ${n.loading?`刷新中…`:`刷新`}
          </button>
        </div>
        <div class="muted" style="margin-top: 8px;">${`上次刷新：${i}`}</div>
        ${n.error?e`<div class="callout danger" style="margin-top: 12px;">${n.error}</div>`:t}
        ${n.snapshot?t:e`
              <div class="callout info" style="margin-top: 12px">${`加载频道以查看实时状态。`}</div>
            `}
        ${r.length===0?e` <div class="muted" style="margin-top: 16px">${`未找到频道。`}</div>`:e`
              <div class="list" style="margin-top: 16px;">
                ${r.map(r=>{let i=tn(r.accounts),a=i.total?`${String(i.connected)}/${String(i.total)} 已连接`:`无账户`,o=i.configured?`已配置 ${String(i.configured)} 个`:`未配置`,s=i.total?`已启用 ${String(i.enabled)} 个`:`已禁用`,c=re({configForm:n.configForm,channelId:r.id,fields:en});return e`
                    <div class="list-item">
                      <div class="list-main">
                        <div class="list-title">${r.label}</div>
                        <div class="list-sub mono">${r.id}</div>
                      </div>
                      <div class="list-meta">
                        <div>${a}</div>
                        <div>${o}</div>
                        <div>${s}</div>
                        ${i.configured===0?e`
                              <div>
                                <a
                                  href="https://docs.openclaw.ai/channels"
                                  target="_blank"
                                  rel="noopener"
                                  style="color: var(--accent); font-size: 12px"
                                  >${`设置指南`}</a
                                >
                              </div>
                            `:t}
                        ${c.length>0?c.map(t=>e`<div>${t.label}: ${t.value}</div>`):t}
                      </div>
                    </div>
                  `})}
              </div>
            `}
      </section>
    </section>
  `}function rn(n){var r,i;let a=n.jobs.filter(e=>e.agentId===n.agentId);return e`
    <section class="grid grid-cols-2">
      ${Zt(n.context,`工作区和调度目标。`,n.onSelectPanel)}
      <section class="card">
        <div class="row" style="justify-content: space-between;">
          <div>
            <div class="card-title">${`调度器`}</div>
            <div class="card-sub">${`Gateway 定时任务状态。`}</div>
          </div>
          <button class="btn btn--sm" ?disabled=${n.loading} @click=${n.onRefresh}>
            ${n.loading?`刷新中…`:`刷新`}
          </button>
        </div>
        <div class="stat-grid" style="margin-top: 16px;">
          <div class="stat">
            <div class="stat-label">${`已启用`}</div>
            <div class="stat-value">
              ${n.status?n.status.enabled?`是`:`否`:`不适用`}
            </div>
          </div>
          <div class="stat">
            <div class="stat-label">${`任务`}</div>
            <div class="stat-value">${((r=n.status)==null?void 0:r.jobs)??`不适用`}</div>
          </div>
          <div class="stat">
            <div class="stat-label">${`下次唤醒`}</div>
            <div class="stat-value">${T(((i=n.status)==null?void 0:i.nextWakeAtMs)??null)}</div>
          </div>
        </div>
        ${n.error?e`<div class="callout danger" style="margin-top: 12px;">${n.error}</div>`:t}
      </section>
    </section>
    <section class="card">
      <div class="card-title">${`代理定时任务`}</div>
      <div class="card-sub">${`面向此代理的计划任务。`}</div>
      ${a.length===0?e` <div class="muted" style="margin-top: 16px">${`未分配任务。`}</div>`:e`
            <div class="list" style="margin-top: 16px;">
              ${a.map(r=>e`
                  <div class="list-item">
                    <div class="list-main">
                      <div class="list-title">${r.name}</div>
                      ${r.description?e`<div class="list-sub">${r.description}</div>`:t}
                      <div class="chip-row" style="margin-top: 6px;">
                        <span class="chip">${E(r)}</span>
                        <span class="chip ${r.enabled?`chip-ok`:`chip-warn`}">
                          ${r.enabled?`已启用`:`已禁用`}
                        </span>
                        <span class="chip">${r.sessionTarget}</span>
                      </div>
                    </div>
                    <div class="list-meta">
                      <div class="mono">${S(r)}</div>
                      <div class="muted">${w(r)}</div>
                      <button
                        class="btn btn--sm"
                        style="margin-top: 6px;"
                        ?disabled=${!r.enabled}
                        @click=${()=>n.onRunNow(r.id)}
                      >
                        ${`立即运行`}
                      </button>
                    </div>
                  </div>
                `)}
            </div>
          `}
    </section>
  `}function an(n){var r;let i=((r=n.agentFilesList)==null?void 0:r.agentId)===n.agentId?n.agentFilesList:null,a=(i==null?void 0:i.files)??[],o=n.agentFileActive??null,s=o?a.find(e=>e.name===o)??null:null,c=o?n.agentFileContents[o]??``:``,l=o?n.agentFileDrafts[o]??c:``,u=o?l!==c:!1,d=s?Ce($.parse(l,{gfm:!0,breaks:!0}),{sanitize:e=>x.sanitize(e)}):``,f=ne(new TextEncoder().encode(l).length),p=Wt(l),m=Gt(l),g=s?Jt(s.path,i==null?void 0:i.workspace):``,_=s?`agent-file-preview-title-${Yt(s.name)}`:``,y=s!=null&&s.missing?`保存时将创建`:u?`实时草稿预览`:`已保存预览`,b=s!=null&&s.missing?`is-missing`:u?`is-dirty`:`is-synced`,ee=s!=null&&s.updatedAtMs?`更新于 ${v(s.updatedAtMs)}`:s!=null&&s.missing?`尚未创建`:`更新时间未知`;return e`
    <section class="card">
      <div class="row" style="justify-content: space-between;">
        <div>
          <div class="card-title">${`核心文件`}</div>
          <div class="card-sub">${`引导人格、身份和工具指引。`}</div>
        </div>
        <button
          class="btn btn--sm"
          ?disabled=${n.agentFilesLoading}
          @click=${()=>n.onLoadFiles(n.agentId)}
        >
          ${n.agentFilesLoading?`加载中…`:`刷新`}
        </button>
      </div>
      ${i?e`<div class="muted mono" style="margin-top: 8px;">
            ${`工作区`}: <span>${i.workspace}</span>
          </div>`:t}
      ${n.agentFilesError?e`<div class="callout danger" style="margin-top: 12px;">
            ${n.agentFilesError}
          </div>`:t}
      ${i?a.length===0?e` <div class="muted" style="margin-top: 16px">${`未找到文件。`}</div> `:e`
              <div class="agent-tabs" style="margin-top: 14px;">
                ${a.map(r=>{let i=o===r.name,a=r.name.replace(/\.md$/i,``);return e`
                    <button
                      class="agent-tab ${i?`active`:``} ${r.missing?`agent-tab--missing`:``}"
                      @click=${()=>n.onSelectFile(r.name)}
                    >
                      ${a}${r.missing?e` <span class="agent-tab-badge">${`缺失`}</span> `:t}
                    </button>
                  `})}
              </div>
              ${s?e`
                    <div class="agent-file-header" style="margin-top: 14px;">
                      <div>
                        <div class="agent-file-sub mono">${s.path}</div>
                      </div>
                      <div class="agent-file-actions">
                        <button
                          class="btn btn--sm"
                          title=${`预览渲染后的 Markdown`}
                          @click=${e=>{var t;let n=(t=e.currentTarget.closest(`.card`))==null?void 0:t.querySelector(`dialog`);n&&n.showModal()}}
                        >
                          ${h.eye} ${`预览`}
                        </button>
                        <button
                          class="btn btn--sm"
                          ?disabled=${!u}
                          @click=${()=>n.onFileReset(s.name)}
                        >
                          ${`重置`}
                        </button>
                        <button
                          class="btn btn--sm primary"
                          ?disabled=${n.agentFileSaving||!u}
                          @click=${()=>n.onFileSave(s.name)}
                        >
                          ${n.agentFileSaving?`保存中…`:`保存`}
                        </button>
                      </div>
                    </div>
                    ${s.missing?e`
                          <div class="callout info" style="margin-top: 10px">
                            ${`此文件缺失。保存后将在代理工作区中创建它。`}
                          </div>
                        `:t}
                    <label class="field agent-file-field" style="margin-top: 12px;">
                      <span>${`内容`}</span>
                      <textarea
                        class="agent-file-textarea"
                        .value=${l}
                        @input=${e=>n.onFileDraftChange(s.name,e.target.value)}
                      ></textarea>
                    </label>
                    <dialog
                      class="md-preview-dialog"
                      aria-labelledby=${_}
                      @click=${e=>{let t=e.currentTarget;e.target===t&&t.close()}}
                      @close=${e=>{var t;let n=e.currentTarget;(t=n.querySelector(`.md-preview-dialog__panel`))==null||t.classList.remove(`fullscreen`),Xt(n.querySelector(`.md-preview-expand-btn`),!1)}}
                    >
                      <div class="md-preview-dialog__panel">
                        <div class="md-preview-dialog__header">
                          <div class="md-preview-dialog__header-main">
                            <div class="md-preview-dialog__eyebrow">
                              ${h.scrollText}
                              <span>${qt(s.name)}</span>
                            </div>
                            <div class="md-preview-dialog__title-wrap">
                              <div
                                id=${_}
                                class="md-preview-dialog__title"
                                translate="no"
                              >
                                ${s.name}
                              </div>
                              <div class="md-preview-dialog__path mono" translate="no">
                                ${g}
                              </div>
                            </div>
                          </div>
                          <div class="md-preview-dialog__actions">
                            <button
                              type="button"
                              class="btn btn--sm md-preview-icon-btn md-preview-expand-btn"
                              title=${`展开预览`}
                              aria-label=${`展开预览`}
                              aria-pressed="false"
                              @click=${e=>{let t=e.currentTarget,n=t.closest(`.md-preview-dialog__panel`);n&&Xt(t,n.classList.toggle(`fullscreen`))}}
                            >
                              <span class="when-normal" aria-hidden="true">${h.maximize}</span
                              ><span class="when-fullscreen" aria-hidden="true"
                                >${h.minimize}</span
                              >
                            </button>
                            <button
                              type="button"
                              class="btn btn--sm md-preview-icon-btn"
                              title=${`编辑文件`}
                              aria-label=${`编辑文件`}
                              @click=${e=>{var t;(t=e.currentTarget.closest(`dialog`))==null||t.close();let n=document.querySelector(`.agent-file-textarea`);n==null||n.focus()}}
                            >
                              <span aria-hidden="true">${h.edit}</span>
                            </button>
                            <button
                              type="button"
                              class="btn btn--sm md-preview-icon-btn"
                              title=${`关闭预览`}
                              aria-label=${`关闭预览`}
                              @click=${e=>{var t;(t=e.currentTarget.closest(`dialog`))==null||t.close()}}
                            >
                              <span aria-hidden="true">${h.x}</span>
                            </button>
                          </div>
                        </div>
                        <div class="md-preview-dialog__meta">
                          <div class="md-preview-dialog__chip ${b}">
                            <strong>${y}</strong>
                          </div>
                          <div class="md-preview-dialog__chip">
                            <strong>${Kt(p)}</strong>
                            <span>${`${String(p)} 个词`}</span>
                          </div>
                          <div class="md-preview-dialog__chip">
                            <strong>${m}</strong>
                            <span>${`行`}</span>
                          </div>
                          <div class="md-preview-dialog__chip">
                            <strong>${f}</strong>
                            <span>${ee}</span>
                          </div>
                        </div>
                        <div class="md-preview-dialog__body">
                          <article class="md-preview-dialog__reader sidebar-markdown">
                            ${A(d)}
                          </article>
                        </div>
                      </div>
                    </dialog>
                  `:e` <div class="muted" style="margin-top: 16px">${`选择要编辑的文件。`}</div>`}
            `:e`
            <div class="callout info" style="margin-top: 12px">
              ${`加载代理工作区文件以编辑核心指令。`}
            </div>
          `}
    </section>
  `}function on(n){return n.length===0?t:e`
    <div class="agent-tool-badges">
      ${n.map(t=>e`<span class="agent-pill">${t}</span>`)}
    </div>
  `}function sn(e,t){let n=t.source??e.source,r=t.pluginId??e.pluginId,i=[];return n===`plugin`&&r?i.push(`Plugin: ${r}`):n===`core`&&i.push(`Built-In`),t.optional&&i.push(`Optional`),i}function cn(e){let t=sn(e.section,e.tool);return e.activeEntry&&t.unshift(`Live Now`),t}function ln(e){return e.denied?`Disabled by agent override.`:e.allowed&&e.baseAllowed?`Enabled by the current profile.`:e.allowed?`Enabled by agent override.`:`Not included in the current profile.`}function un(e,t){let n=t.source??e.source,r=t.pluginId??e.pluginId;return n===`plugin`&&r?`Plugin: ${r}`:`Built-In`}function dn(e){return e.denied?`Override Off`:e.allowed&&e.baseAllowed?`Enabled`:e.allowed?`Override On`:`Profile Off`}function fn(e){return e.activeEntry?`Live Now`:e.runtimeSessionMatchesSelectedAgent?`Not Live`:`Other Agent`}function pn(e){return`agent-tool-${l(e).replace(/[^a-z0-9_-]+/g,`-`)}`}function mn(e,t,n=`${t}s`){return`${e} ${e===1?t:n}`}function hn(e){return(e??[]).flatMap(e=>e.tools)}var gn=12;function _n(e){let t=e.currentTarget;if(!(!(t instanceof HTMLDetailsElement)||t.open))for(let e of t.querySelectorAll(`.agent-tool-card[open]`))e.open=!1}function vn(e,t){let n=document.getElementById(t);if(!(n instanceof HTMLDetailsElement))return;e.preventDefault();let r=n.closest(`.agent-tools-group`);r&&(r.open=!0),n.open=!0;let i=new URL(window.location.href);i.hash=t,window.history.replaceState(null,``,i),requestAnimationFrame(()=>{var e,t;let r=typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;(e=n.scrollIntoView)==null||e.call(n,{block:`center`,behavior:r?`auto`:`smooth`}),(t=n.querySelector(`summary`))==null||t.focus()})}function yn(e){return e.source===`plugin`?e.pluginId?`已连接：${e.pluginId}`:`已连接`:e.source===`channel`?e.channelId?`频道：${e.channelId}`:`渠道`:`内置`}function bn(n){var r,i,a;let c=s(n.configForm,n.agentId),u=((r=c.entry)==null?void 0:r.tools)??{},p=c.globalTools??{},h=u.profile??p.profile??`full`,_=f(n.toolsCatalogResult),v=m(n.toolsCatalogResult),y=u.profile?`agent override`:p.profile?`global default`:`default`,b=Array.isArray(u.allow)&&u.allow.length>0,ee=Array.isArray(p.allow)&&p.allow.length>0,x=!!n.configForm&&!n.configLoading&&!n.configSaving&&!b&&!(n.toolsCatalogLoading&&!n.toolsCatalogResult&&!n.toolsCatalogError),S=b?[]:Array.isArray(u.alsoAllow)?u.alsoAllow:[],C=b?[]:Array.isArray(u.deny)?u.deny:[],te=b?{allow:u.allow??[],deny:u.deny??[]}:d(h)??void 0,w=v.flatMap(e=>e.tools.map(e=>e.id)),T=e=>{let t=g(e,te),n=o(e,S),r=o(e,C);return{allowed:(t||n)&&!r,baseAllowed:t,denied:r}},E=w.filter(e=>T(e).allowed).length,D=n.runtimeSessionMatchesSelectedAgent&&!n.toolsEffectiveError?hn((i=n.toolsEffectiveResult)==null?void 0:i.groups):[],O=Array.from(new Map(D.map(e=>[l(e.id),e])).values()),ne=O.slice(0,gn),k=Math.max(0,O.length-ne.length),A=O.length,re=new Map(D.map(e=>[l(e.id),e])),j=new Set(re.keys()),M=e=>e.toSorted((e,t)=>{let n=l(e.id),r=l(t.id),i=+!!j.has(n),a=+!!j.has(r);if(i!==a)return a-i;let o=+!!T(e.id).allowed,s=+!!T(t.id).allowed;return o===s?e.label.localeCompare(t.label):s-o}),N=(e,t)=>{let r=new Set(S.map(e=>l(e)).filter(e=>e.length>0)),i=new Set(C.map(e=>l(e)).filter(e=>e.length>0)),a=T(e).baseAllowed,o=l(e);t?(i.delete(o),a||r.add(o)):(r.delete(o),i.add(o)),n.onOverridesChange(n.agentId,[...r],[...i])},ie=e=>{let t=new Set(S.map(e=>l(e)).filter(e=>e.length>0)),r=new Set(C.map(e=>l(e)).filter(e=>e.length>0));for(let n of w){let i=T(n).baseAllowed,a=l(n);e?(r.delete(a),i||t.add(a)):(t.delete(a),r.add(a))}n.onOverridesChange(n.agentId,[...t],[...r])};return e`
    <section class="card">
      <div class="agent-tools-header">
        <div class="agent-tools-header__intro">
          <div class="card-title">Tool Access</div>
          <div class="card-sub">
            Profile + per-tool overrides for this agent.
            <span class="mono">${E}/${w.length}</span> enabled.
          </div>
        </div>
        <div class="agent-tools-header__actions">
          <button class="btn btn--sm" ?disabled=${!x} @click=${()=>ie(!0)}>
            Enable All
          </button>
          <button class="btn btn--sm" ?disabled=${!x} @click=${()=>ie(!1)}>
            Disable All
          </button>
          <button
            class="btn btn--sm"
            ?disabled=${n.configLoading}
            @click=${n.onConfigReload}
          >
            ${`重新加载配置`}
          </button>
          <button
            class="btn btn--sm primary"
            ?disabled=${n.configSaving||!n.configDirty}
            @click=${n.onConfigSave}
          >
            ${n.configSaving?`Saving…`:`Save`}
          </button>
        </div>
      </div>

      ${n.configForm?t:e`
            <div class="callout info" style="margin-top: 12px">
              Load the gateway config to adjust tool profiles.
            </div>
          `}
      ${b?e`
            <div class="callout info" style="margin-top: 12px">
              This agent is using an explicit allowlist in config. Tool overrides are managed in the
              Config tab.
            </div>
          `:t}
      ${ee?e`
            <div class="callout info" style="margin-top: 12px">
              Global tools.allow is set. Agent overrides cannot enable tools that are globally
              blocked.
            </div>
          `:t}
      ${n.toolsCatalogLoading&&!n.toolsCatalogResult&&!n.toolsCatalogError?e`
            <div class="callout info" style="margin-top: 12px">Loading runtime tool catalog…</div>
          `:t}
      ${n.toolsCatalogError?e`
            <div class="callout info" style="margin-top: 12px">
              Could not load runtime tool catalog. Showing built-in fallback list instead.
            </div>
          `:t}

      <div class="agent-tools-overview">
        <div class="agent-tools-overview__primary">
          <div class="agent-tools-pane">
            <div class="label">Available Right Now</div>
            <div class="card-sub">
              What this agent can use in the current chat session.
              <span class="mono">${n.runtimeSessionKey||`no session`}</span>
            </div>
            ${n.runtimeSessionMatchesSelectedAgent?n.toolsEffectiveLoading&&!n.toolsEffectiveResult&&!n.toolsEffectiveError?e`
                    <div class="callout info" style="margin-top: 12px">
                      Loading available tools…
                    </div>
                  `:n.toolsEffectiveError?e`
                      <div class="callout info" style="margin-top: 12px">
                        Could not load available tools for this session.
                      </div>
                    `:(((a=n.toolsEffectiveResult)==null||(a=a.groups)==null?void 0:a.length)??0)===0?e`
                        <div class="callout info" style="margin-top: 12px">
                          No tools are available for this session right now.
                        </div>
                      `:e`
                        <div class="agent-tools-runtime">
                          ${ne.map(t=>{let n=pn(t.id);return e`
                              <a
                                class="agent-tools-runtime-chip"
                                href="#${n}"
                                @click=${e=>vn(e,n)}
                              >
                                <span class="mono" translate="no">${t.label}</span>
                                <span class="agent-tools-runtime-chip__meta"
                                  >${yn(t)}</span
                                >
                              </a>
                            `})}
                          ${k>0?e`
                                <span
                                  class="agent-tools-runtime-chip agent-tools-runtime-chip--more"
                                  title=${`${k} more live tools are available in the groups below.`}
                                >
                                  +${k} more live tools
                                </span>
                              `:t}
                        </div>
                      `:e`
                  <div class="callout info" style="margin-top: 12px">
                    Switch chat to this agent to view its live runtime tools.
                  </div>
                `}
          </div>

          <div class="agent-tools-pane">
            <div class="label">Quick Presets</div>
            <div class="agent-tools-buttons">
              ${_.map(t=>e`
                  <button
                    class="btn btn--sm ${h===t.id?`active`:``}"
                    ?disabled=${!x}
                    @click=${()=>n.onProfileChange(n.agentId,t.id,!0)}
                  >
                    ${t.label}
                  </button>
                `)}
              <button
                class="btn btn--sm"
                ?disabled=${!x}
                @click=${()=>n.onProfileChange(n.agentId,null,!1)}
              >
                Inherit
              </button>
            </div>
          </div>
        </div>

        <div class="agent-tools-facts">
          <div class="agent-tools-fact">
            <div class="label">Profile</div>
            <div class="mono">${h}</div>
          </div>
          <div class="agent-tools-fact">
            <div class="label">Source</div>
            <div>${y}</div>
          </div>
          <div class="agent-tools-fact">
            <div class="label">Enabled</div>
            <div class="mono">${E}/${w.length}</div>
          </div>
          <div class="agent-tools-fact">
            <div class="label">Live</div>
            <div class="mono">${A}</div>
          </div>
          <div class="agent-tools-fact">
            <div class="label">Status</div>
            <div class="mono">
              ${n.configSaving?`saving…`:n.configDirty?`unsaved`:`saved`}
            </div>
          </div>
        </div>
      </div>

      <div class="agent-tools-grid">
        ${v.map(r=>{let i=M(r.tools),a=r.tools.filter(e=>T(e.id).allowed).length,o=r.tools.filter(e=>j.has(l(e.id))).length,s=i.slice(0,4),c=Math.max(0,i.length-s.length);return e`
            <details class="agent-tools-group" @toggle=${_n}>
              <summary class="agent-tools-group__summary">
                <span class="agent-tools-group__summary-main">
                  <span class="agent-tools-group__title">
                    ${r.label}
                    ${r.source===`plugin`&&r.pluginId?e`<span class="agent-pill">Plugin: ${r.pluginId}</span>`:t}
                  </span>
                  <span class="agent-tools-group__preview" aria-label="Tool preview">
                    ${s.map(t=>e`<span class="mono" translate="no" title=${t.label}
                          >${t.label}</span
                        >`)}
                    ${c>0?e`<span>+${c} more</span>`:t}
                  </span>
                </span>
                <span class="agent-tools-group__counts">
                  <span>${mn(r.tools.length,`Tool`)}</span>
                  <span>${mn(a,`Enabled Tool`)}</span>
                  ${o>0?e`<span>${mn(o,`Live Tool`)}</span>`:t}
                </span>
              </summary>
              <div class="agent-tools-list agent-tools-list--stacked">
                ${i.map(i=>{let a=pn(i.id),o=T(i.id),s=re.get(l(i.id))??null,c=i.defaultProfiles??[],u=cn({section:r,tool:i,activeEntry:s}),d=dn(o),f=fn({activeEntry:s,runtimeSessionMatchesSelectedAgent:n.runtimeSessionMatchesSelectedAgent});return e`
                    <details class="agent-tool-card" id=${a}>
                      <summary class="agent-tool-summary">
                        <div class="agent-tool-summary__main">
                          <div class="agent-tool-summary__title-row">
                            <span class="agent-tool-title mono" translate="no">${i.label}</span>
                          </div>
                          <div class="agent-tool-sub">${i.description}</div>
                        </div>
                        <dl class="agent-tool-summary__facts">
                          <div class="agent-tool-summary__fact">
                            <dt class="label">Access</dt>
                            <dd>${d}</dd>
                          </div>
                          <div class="agent-tool-summary__fact">
                            <dt class="label">Session</dt>
                            <dd>${f}</dd>
                          </div>
                        </dl>
                        <div class="agent-tool-summary__badges">
                          ${on(u)}
                        </div>
                        <label
                          class="cfg-toggle agent-tool-toggle"
                          @click=${e=>e.stopPropagation()}
                          @keydown=${e=>e.stopPropagation()}
                        >
                          <input
                            type="checkbox"
                            .checked=${o.allowed}
                            ?disabled=${!x}
                            aria-label=${`${o.allowed?`Disable`:`Enable`} ${i.label}`}
                            @change=${e=>N(i.id,e.target.checked)}
                          />
                          <span class="cfg-toggle__track"></span>
                        </label>
                      </summary>
                      <div class="agent-tool-details">
                        <div class="agent-tool-details-strip">
                          <div class="agent-tool-detail agent-tool-detail--inline">
                            <div class="label">Access</div>
                            <div>${ln(o)}</div>
                          </div>
                          <div class="agent-tool-detail agent-tool-detail--inline">
                            <div class="label">Source</div>
                            <div>${un(r,i)}</div>
                          </div>
                          ${c.length>0?e`
                                <div class="agent-tool-detail agent-tool-detail--inline">
                                  <div class="label">Default Presets</div>
                                  <div class="agent-tool-badges">
                                    ${c.map(t=>e`<span class="agent-pill">${t}</span>`)}
                                  </div>
                                </div>
                              `:t}
                          <div class="agent-tool-detail agent-tool-detail--inline">
                            <div class="label">Current Session</div>
                            <div>
                              ${s?`Available now via ${yn(s)}.`:n.runtimeSessionMatchesSelectedAgent?`Not available in this chat session right now.`:`Switch chat to this agent to inspect live availability.`}
                            </div>
                          </div>
                          <a class="agent-tool-jump" href="#${a}"> Link to This Tool </a>
                        </div>
                      </div>
                    </details>
                  `})}
              </div>
            </details>
          `})}
      </div>
    </section>
  `}function xn(r){var i,a,o;let c=!!r.configForm&&!r.configLoading&&!r.configSaving,l=s(r.configForm,r.agentId),u=Array.isArray((i=l.entry)==null?void 0:i.skills)?(a=l.entry)==null?void 0:a.skills:void 0,d=new Set((u??[]).map(e=>e.trim()).filter(Boolean)),f=u!==void 0,p=!!(r.report&&r.activeAgentId===r.agentId),m=p?((o=r.report)==null?void 0:o.skills)??[]:[],h=n(r.filter),g=h?m.filter(e=>n([e.name,e.description,e.source].join(` `)).includes(h)):m,_=j(g),v=f?m.filter(e=>d.has(e.name)).length:m.length,y=m.length;return e`
    <section class="card">
      <div class="row" style="justify-content: space-between; flex-wrap: wrap;">
        <div style="min-width: 0;">
          <div class="card-title">Skills</div>
          <div class="card-sub">
            Per-agent skill allowlist and workspace skills.
            ${y>0?e`<span class="mono">${v}/${y}</span>`:t}
          </div>
        </div>
        <div class="row" style="gap: 8px; flex-wrap: wrap;">
          <div
            class="row"
            style="gap: 4px; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 2px;"
          >
            <button
              class="btn btn--sm"
              ?disabled=${!c}
              @click=${()=>r.onClear(r.agentId)}
            >
              Enable All
            </button>
            <button
              class="btn btn--sm"
              ?disabled=${!c}
              @click=${()=>r.onDisableAll(r.agentId)}
            >
              Disable All
            </button>
            <button
              class="btn btn--sm"
              ?disabled=${!c||!f}
              @click=${()=>r.onClear(r.agentId)}
              title="Remove per-agent allowlist and use all skills"
            >
              Reset
            </button>
          </div>
          <button
            class="btn btn--sm"
            ?disabled=${r.configLoading}
            @click=${r.onConfigReload}
          >
            ${`重新加载配置`}
          </button>
          <button class="btn btn--sm" ?disabled=${r.loading} @click=${r.onRefresh}>
            ${r.loading?`加载中…`:`刷新`}
          </button>
          <button
            class="btn btn--sm primary"
            ?disabled=${r.configSaving||!r.configDirty}
            @click=${r.onConfigSave}
          >
            ${r.configSaving?`Saving…`:`Save`}
          </button>
        </div>
      </div>

      ${r.configForm?t:e`
            <div class="callout info" style="margin-top: 12px">
              Load the gateway config to set per-agent skills.
            </div>
          `}
      ${f?e`
            <div class="callout info" style="margin-top: 12px">
              This agent uses a custom skill allowlist.
            </div>
          `:e`
            <div class="callout info" style="margin-top: 12px">
              All skills are enabled. Disabling any skill will create a per-agent allowlist.
            </div>
          `}
      ${!p&&!r.loading?e`
            <div class="callout info" style="margin-top: 12px">
              Load skills for this agent to view workspace-specific entries.
            </div>
          `:t}
      ${r.error?e`<div class="callout danger" style="margin-top: 12px;">${r.error}</div>`:t}

      <div class="filters" style="margin-top: 14px;">
        <label class="field" style="flex: 1;">
          <span>Filter</span>
          <input
            .value=${r.filter}
            @input=${e=>r.onFilterChange(e.target.value)}
            placeholder="Search skills"
            autocomplete="off"
            name="agent-skills-filter"
          />
        </label>
        <div class="muted">${g.length} shown</div>
      </div>

      ${g.length===0?e` <div class="muted" style="margin-top: 16px">No skills found.</div> `:e`
            <div class="agent-skills-groups" style="margin-top: 16px;">
              ${_.map(e=>Sn(e,{agentId:r.agentId,allowSet:d,usingAllowlist:f,editable:c,onToggle:r.onToggle}))}
            </div>
          `}
    </section>
  `}function Sn(t,n){return e`
    <details class="agent-skills-group" ?open=${!(t.id===`workspace`||t.id===`built-in`)}>
      <summary class="agent-skills-header">
        <span>${t.label}</span>
        <span class="muted">${t.skills.length}</span>
      </summary>
      <div class="list skills-grid">
        ${t.skills.map(e=>Cn(e,{agentId:n.agentId,allowSet:n.allowSet,usingAllowlist:n.usingAllowlist,editable:n.editable,onToggle:n.onToggle}))}
      </div>
    </details>
  `}function Cn(n,r){let i=r.usingAllowlist?r.allowSet.has(n.name):!0,a=ie(n),o=M(n);return e`
    <div class="list-item agent-skill-row">
      <div class="list-main">
        <div class="list-title">${n.emoji?`${n.emoji} `:``}${n.name}</div>
        <div class="list-sub">${n.description}</div>
        ${N({skill:n})}
        ${a.length>0?e`<div class="muted" style="margin-top: 6px;">Missing: ${a.join(`, `)}</div>`:t}
        ${o.length>0?e`<div class="muted" style="margin-top: 6px;">Reason: ${o.join(`, `)}</div>`:t}
      </div>
      <div class="list-meta">
        <label class="cfg-toggle">
          <input
            type="checkbox"
            .checked=${i}
            ?disabled=${!r.editable}
            @change=${e=>r.onToggle(r.agentId,n.name,e.target.checked)}
          />
          <span class="cfg-toggle__track"></span>
        </label>
      </div>
    </div>
  `}function wn(n){var r,i,a,o,s;let c=((r=n.agentsList)==null?void 0:r.agents)??[],l=((i=n.agentsList)==null?void 0:i.defaultId)??null,u=n.selectedAgentId??l??((a=c[0])==null?void 0:a.id)??null,d=u?c.find(e=>e.id===u)??null:null,f=u&&n.agentSkills.agentId===u?((o=n.agentSkills.report)==null||(o=o.skills)==null?void 0:o.length)??null:null,p=n.channels.snapshot?Object.keys(n.channels.snapshot.channelAccounts??{}).length:null,m=u?n.cron.jobs.filter(e=>e.agentId===u).length:null,h={files:((s=n.agentFiles.list)==null||(s=s.files)==null?void 0:s.length)??null,skills:f,channels:p,cron:m||null};return e`
    <div class="agents-layout">
      <section class="agents-toolbar">
        <div class="agents-toolbar-row">
          <div class="agents-control-select">
            <select
              class="agents-select"
              .value=${u??``}
              ?disabled=${n.loading||c.length===0}
              @change=${e=>n.onSelectAgent(e.target.value)}
            >
              ${c.length===0?e` <option value="">${`无代理`}</option> `:c.map(t=>e`
                      <option value=${t.id} ?selected=${t.id===u}>
                        ${O(t)}${D(t.id,l)?` (${D(t.id,l)})`:``}
                      </option>
                    `)}
            </select>
          </div>
          <div class="agents-toolbar-actions">
            ${d?e`
                  <button
                    type="button"
                    class="btn btn--sm btn--ghost"
                    @click=${()=>void navigator.clipboard.writeText(d.id)}
                    title=${`将代理 ID 复制到剪贴板`}
                  >
                    ${`复制 ID`}
                  </button>
                  <button
                    type="button"
                    class="btn btn--sm btn--ghost"
                    ?disabled=${!!(l&&d.id===l)}
                    @click=${()=>n.onSetDefault(d.id)}
                    title=${l&&d.id===l?`已是默认代理`:`设为默认代理`}
                  >
                    ${l&&d.id===l?`默认`:`设为默认`}
                  </button>
                `:t}
            <button
              class="btn btn--sm agents-refresh-btn"
              ?disabled=${n.loading}
              @click=${n.onRefresh}
            >
              ${n.loading?`加载中…`:`刷新`}
            </button>
          </div>
        </div>
        ${n.error?e`<div class="callout danger" style="margin-top: 8px;">${n.error}</div>`:t}
      </section>
      <section class="agents-main">
        ${d?e`
              ${Tn(n.activePanel,e=>n.onSelectPanel(e),h)}
              ${n.activePanel===`overview`?ae(d.id,oe({agent:d,basePath:n.basePath,defaultId:l,configForm:n.config.form,agentFilesList:n.agentFiles.list,agentIdentity:n.agentIdentityById[d.id]??null,agentIdentityError:n.agentIdentityError,agentIdentityLoading:n.agentIdentityLoading,configLoading:n.config.loading,configSaving:n.config.saving,configDirty:n.config.dirty,modelCatalog:n.modelCatalog,onConfigReload:n.onConfigReload,onConfigSave:n.onConfigSave,onModelChange:n.onModelChange,onModelFallbacksChange:n.onModelFallbacksChange,onSelectPanel:n.onSelectPanel})):t}
              ${n.activePanel===`files`?an({agentId:d.id,agentFilesList:n.agentFiles.list,agentFilesLoading:n.agentFiles.loading,agentFilesError:n.agentFiles.error,agentFileActive:n.agentFiles.active,agentFileContents:n.agentFiles.contents,agentFileDrafts:n.agentFiles.drafts,agentFileSaving:n.agentFiles.saving,onLoadFiles:n.onLoadFiles,onSelectFile:n.onSelectFile,onFileDraftChange:n.onFileDraftChange,onFileReset:n.onFileReset,onFileSave:n.onFileSave}):t}
              ${n.activePanel===`tools`?bn({agentId:d.id,configForm:n.config.form,configLoading:n.config.loading,configSaving:n.config.saving,configDirty:n.config.dirty,toolsCatalogLoading:n.toolsCatalog.loading,toolsCatalogError:n.toolsCatalog.error,toolsCatalogResult:n.toolsCatalog.result,toolsEffectiveLoading:n.toolsEffective.loading,toolsEffectiveError:n.toolsEffective.error,toolsEffectiveResult:n.toolsEffective.result,runtimeSessionKey:n.runtimeSessionKey,runtimeSessionMatchesSelectedAgent:n.runtimeSessionMatchesSelectedAgent,onProfileChange:n.onToolsProfileChange,onOverridesChange:n.onToolsOverridesChange,onConfigReload:n.onConfigReload,onConfigSave:n.onConfigSave}):t}
              ${n.activePanel===`skills`?xn({agentId:d.id,report:n.agentSkills.report,loading:n.agentSkills.loading,error:n.agentSkills.error,activeAgentId:n.agentSkills.agentId,configForm:n.config.form,configLoading:n.config.loading,configSaving:n.config.saving,configDirty:n.config.dirty,filter:n.agentSkills.filter,onFilterChange:n.onSkillsFilterChange,onRefresh:n.onSkillsRefresh,onToggle:n.onAgentSkillToggle,onClear:n.onAgentSkillsClear,onDisableAll:n.onAgentSkillsDisableAll,onConfigReload:n.onConfigReload,onConfigSave:n.onConfigSave}):t}
              ${n.activePanel===`channels`?nn({context:k(d,n.config.form,n.agentFiles.list,l,n.agentIdentityById[d.id]??null),configForm:n.config.form,snapshot:n.channels.snapshot,loading:n.channels.loading,error:n.channels.error,lastSuccess:n.channels.lastSuccess,onRefresh:n.onChannelsRefresh,onSelectPanel:n.onSelectPanel}):t}
              ${n.activePanel===`cron`?rn({context:k(d,n.config.form,n.agentFiles.list,l,n.agentIdentityById[d.id]??null),agentId:d.id,jobs:n.cron.jobs,status:n.cron.status,loading:n.cron.loading,error:n.cron.error,onRefresh:n.onCronRefresh,onRunNow:n.onCronRunNow,onSelectPanel:n.onSelectPanel}):t}
            `:e`
              <div class="card">
                <div class="card-title">${`选择代理`}</div>
                <div class="card-sub">${`选择代理以查看其工作区和工具。`}</div>
              </div>
            `}
      </section>
    </div>
  `}function Tn(n,r,i){return e`
    <div class="agent-tabs">
      ${[{id:`overview`,label:`概览`},{id:`files`,label:`文件`},{id:`tools`,label:`工具`},{id:`skills`,label:`Skills`},{id:`channels`,label:`频道`},{id:`cron`,label:`Cron Jobs`}].map(a=>e`
          <button
            class="agent-tab ${n===a.id?`active`:``}"
            type="button"
            @click=${()=>r(a.id)}
          >
            ${a.label}${i[a.id]==null?t:e`<span class="agent-tab-count">${i[a.id]}</span>`}
          </button>
        `)}
    </div>
  `}export{wn as renderAgents};
//# sourceMappingURL=agents-DvLA3qvc.js.map