const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/js/mermaid-CWQI515T.js","assets/js/rolldown-runtime-M0oDzQ_3.js"])))=>i.map(i=>d[i]);
import{a as Ee,n as M}from"./rolldown-runtime-M0oDzQ_3.js";import{$t as Y,Cn as Ae,En as Re,Jt as Te,Kn as T,Kt as Ie,M as Ne,On as z,P as Pe,Qt as De,Rn as x,Rt as Se,Xt as J,Zn as Be,Zt as Q,_n as He,an as We,en as I,g as ze,hn as Ue,in as N,pn as ee,qt as Oe,t as je,yn as F,z as Ge}from"./ui-vendor-CepnLjNg.js";import{c as Ve,l as qe}from"./vue-vendor-BQwgTLLQ.js";import{B as Ke,z as Ze}from"./mermaid-CWQI515T.js";import{a as Xe,c as Ye,i as Je,l as Qe,o as et,r as te,s as ne}from"./vendor-B1Lfatlz.js";import{D as tt,E as P,O as re,k as nt}from"./index-BxPouqCs.js";import{n as rt,t as at}from"./clipboard-1NPxC3YL.js";function D(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#39;")}function ot(e){return e.replace(/[^a-z0-9_-]/gi,"-")||"plain"}function it(e){const a=e?.trim().toLowerCase()||"";return pe[a]||a}function ae(e,a,r,o={}){const i=a?.trim().toLowerCase()||"",l=it(i),p=o.maxHighlightLength??Number.POSITIVE_INFINITY;let m="",_=l||i||"plain",v=i;try{l&&te.getLanguage(l)&&e.length<=p?(m=te.highlight(e,{language:l,ignoreIllegals:!0}).value,_=l):(m=D(e),v||(v="text"))}catch{m=D(e),v||(v="text")}return`<pre class="hljs-code-block"><div class="code-header">${v?`<span class="code-lang">${D(v)}</span>`:""}<button type="button" class="copy-btn" data-copy-code="true">${D(r)}</button></div><code class="hljs language-${ot(_)}">${m}</code></pre>`}async function st(e){return at(e)}async function lt(e){const a=e.target;if(!(a instanceof HTMLElement))return null;const r=a.closest('[data-copy-code="true"]');if(!r)return null;e.preventDefault();const o=r.closest(".hljs-code-block")?.querySelector("code")?.textContent??"";return o?st(o):!1}var pe,ct=M((()=>{Je(),rt(),pe={shellscript:"bash",sh:"bash",zsh:"bash",yml:"yaml",vue:"xml"}}));function b(e){const a=e.match(/^( {0,3})(`{3,}|~{3,})(.*)$/);if(!a)return null;const[,r,o,i=""]=a,l=o[0],p=i.trim();return l==="`"&&p.includes("`")?null:{indent:r,marker:l,fence:o,length:o.length,info:p}}function oe(e,a=e.length,r=e.info){return`${e.indent}${e.marker.repeat(a)}${r?` ${r}`:""}`}function he(e){const a=e.info.split(/\s+/)[0]?.toLowerCase();return we.has(a)}function dt(e,a){const r=b(e);return!!(r&&r.marker===a.marker&&r.length>=a.length&&r.info==="")}function ge(e,a=e.length-1){let r=a;for(;r>=0&&e[r].trim()==="";)r-=1;return r}function ut(e,a,r){for(let o=ge(e);o>r;o-=1)if(dt(e[o],a))return o;return-1}function mt(e,a){const r=[];let o=!1;for(const i of e){const l=b(i);if(!l||l.marker!==a)continue;o=!0;const p=r[r.length-1];if(l.info===""&&p&&l.length>=p.length){r.pop();continue}r.push({marker:l.marker,length:l.length})}return o&&r.length===0}function ft(e,a,r){const o=[];for(let i=r;i<e.length;i+=1){const l=b(e[i]);l&&l.marker===a.marker&&l.info===""&&l.length>=a.length&&o.push(i)}for(let i=o.length-1;i>=0;i-=1){const l=o[i];if(mt(e.slice(r,l),a.marker))return l}return o[0]??-1}function pt(e,a){let r=0;for(const o of e){const i=b(o);i?.marker===a&&(r=Math.max(r,i.length))}return r}function ht(e){const a=[];for(let r=0;r<e.length;r+=1){const o=b(e[r]);if(!o||!he(o)){a.push(e[r]);continue}const i=ft(e,o,r+1);if(i===-1){a.push(e[r]);continue}const l=e.slice(r+1,i),p=pt(l,o.marker);if(p>=o.length){const m=p+1;a.push(oe(o,m)),a.push(...l),a.push(oe(o,m,""))}else a.push(e[r]),a.push(...l),a.push(e[i]);r=i}return a}function gt(e){if(!e.includes("```")&&!e.includes("~~~"))return e;const a=e.split(`
`),r=[];let o=!1;for(let i=0;i<a.length;i+=1){const l=b(a[i]);if(!l||!he(l)){r.push(a[i]);continue}const p=ut(a,l,i+1);if(p===-1){r.push(a[i]);continue}if(p!==ge(a)){r.push(a[i]);continue}r.push(...ht(a.slice(i+1,p))),r.push(...a.slice(p+1)),o=!0;break}return o?r.join(`
`):e}var we,wt=M((()=>{we=new Set(["md","markdown","mdown","mkd"])}));function _t(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#39;")}function vt(e){return e?.trim().split(/\s+/)[0]?.toLowerCase()||""}function kt(e){return vt(e)===_e}function yt(e){return encodeURIComponent(e)}function ie(e){if(!e)return"";try{return decodeURIComponent(e)}catch{return""}}function $t(e){return['<div class="mermaid-diagram" data-mermaid-pending="true"',` data-mermaid-source="${_t(yt(e))}">`,'<div class="mermaid-loading">Rendering Mermaid diagram…</div>',"</div>"].join("")}var _e,xt,U,ve,Mt=M((()=>{_e="mermaid",xt=2e4,U=5e3,ve=["txt","md","json","csv","log","py","yaml","yml","toml","sh","xml","html","css","js","ts","rs","go","java","c","cpp","h"]})),se,le,ce,de,ue,me,ke,fe=M((()=>{Se(),Ve(),je(),Ye(),et(),se=Ee(Xe()),ct(),wt(),Mt(),nt(),Ke(),le=["innerHTML"],ce={key:0,class:"text-preview-markdown"},de={key:1,class:"text-preview-body"},ue=["src"],me="min(800px, 100vw)",ke=We({__name:"MarkdownRenderer",props:{content:{},mentionNames:{default:()=>[]},headingIdPrefix:{default:""}},setup(e){const a=new Set(["latex","tex","math","katex"]);function r(t){return t.trim().split(/\s+/)[0]?.toLowerCase()??""}function o(t){return a.has(r(t))}function i(t){const n=t.trim();return n.startsWith("\\[")&&n.endsWith("\\]")||n.startsWith("$$")&&n.endsWith("$$")||n.startsWith("\\(")&&n.endsWith("\\)")?n.slice(2,-2).trim():n}function l(t){const n=i(t);return`<div class="latex-block">${ne.renderToString(n,{displayMode:!0,output:"htmlAndMathml",throwOnError:!1,strict:"ignore"})}</div>`}const p=e,{t:m}=qe(),_=Ge(),v=new Qe({html:!1,breaks:!0,linkify:!0,typographer:!0,highlight(t,n){return ae(t,n,m("common.copy"))}});v.use(se.default,{katex:ne,throwOnError:!1,strict:"ignore"});const O=v.renderer.rules.fence?.bind(v.renderer.rules);v.renderer.rules.fence=(t,n,f,d,h)=>{const u=t[n];return o(u.info)?l(u.content):kt(u.info)?$t(u.content):O?O(t,n,f,d,h):h.renderToken(t,n,f)};const S=x(null),j=`hermes-mermaid-${Math.random().toString(36).slice(2)}`,C=x(null),$=x(null),G=x(""),B=x(!1),E=x(!1),ye=J(()=>/\.(md|markdown)$/i.test(G.value));let k=0,y=!1;function H(t){return t.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(t)}function W(t){return/^[a-zA-Z]:\\/.test(t)?t.replace(/\\/g,"/"):t}const V=J(()=>{let t=v.render(gt(p.content));const n=p.headingIdPrefix?`${p.headingIdPrefix}-`:"";let f=0;if(t=t.replace(/<(h[1-6])([^>]*)>/g,(d,h,u)=>{f++;const c=`${n}heading-${f}`;return u.includes("id=")?d.replace(/id="[^"]*"/,`id="${c}"`).replace(/id='[^']*'/,`id="${c}"`):u.trim()===""?`<${h} id="${c}">`:`<${h} ${u.trim()} id="${c}">`}),t=t.replace(/\bsrc=(["'])([^"']+)\1/g,(d,h,u)=>H(u)?`src=${h}${re(W(u))}${h}`:d),t=t.replace(/<a href="([^"]+)">([^<]+)<\/a>/g,(d,h,u)=>{if(!H(h))return d;const c=W(h),g=u.trim(),s=c.split(".").pop()?.toLowerCase();return s==="mp4"||s==="webm"||s==="mov"?`<div class="markdown-video-container">
        <video class="markdown-video" controls preload="metadata" src="${re(c)}"></video>
        <div class="markdown-video-footer">
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
            <polygon points="5 3 19 12 5 21 5 3"/>
          </svg>
          <span class="att-name">${g}</span>
        </div>
      </div>`:`<div class="markdown-file-card" data-path="${c}" data-filename="${g}" title="${m("download.downloadFile")}">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
        <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
        <polyline points="14 2 14 8 20 8" />
      </svg>
      <span class="att-name">${g}</span>
      <button class="att-download-btn" type="button" title="${m("download.downloadFile")}" aria-label="${m("download.downloadFile")}">
        <svg class="att-download-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
          <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
          <polyline points="7 10 12 15 17 10" />
          <line x1="12" y1="15" x2="12" y2="3" />
        </svg>
      </button>
    </div>`}),p.mentionNames&&p.mentionNames.length>0){const d=[...p.mentionNames].sort((u,c)=>c.length-u.length).map(u=>u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),h=new RegExp(`(?<=[\\s>({\\[<]|^)@(${d.join("|")})(?=[\\s.,!?;:，。！？；：)\\]}>]|<|$)`,"gi");t=t.replace(h,'<span class="mention-highlight">@$1</span>')}return t});function A(t,n){t.outerHTML=ae(n,"mermaid",m("common.copy"))}function q(t,n,f){let d;const h=new Promise((u,c)=>{d=setTimeout(()=>{c(new Error(`${f} timed out after ${n}ms`))},n)});return Promise.race([t,h]).finally(()=>{d!==void 0&&clearTimeout(d)})}function $e(t){if(!t)return null;let n=t.parentElement;for(;n;){const{overflow:f,overflowY:d}=getComputedStyle(n);if(f==="auto"||f==="scroll"||d==="auto"||d==="scroll")return n;n=n.parentElement}return null}function xe(t,n=200){return t.scrollHeight-t.scrollTop-t.clientHeight<n}function K(t){document.getElementById(t)?.remove(),document.getElementById(`d${t}`)?.remove()}async function Z(){const t=++k;await ee();const n=S.value;if(y||t!==k||!n)return;const f=Array.from(n.querySelectorAll('[data-mermaid-pending="true"]'));if(f.length===0)return;const d=f.slice(0,4),h=f.slice(4);for(const s of h)A(s,ie(s.getAttribute("data-mermaid-source")));const u=d.map(s=>({element:s,source:ie(s.getAttribute("data-mermaid-source"))})),c=[];for(const s of u){if(y||t!==k||!n.contains(s.element))return;if(!s.source||s.source.length>2e4){A(s.element,s.source);continue}c.push(s)}if(c.length===0)return;let g;try{if(g=(await q(Ze(()=>import("./mermaid-CWQI515T.js").then(s=>(s.t(),s.n)),__vite__mapDeps([0,1])),U,"Mermaid import")).default,y||t!==k)return;g.initialize({startOnLoad:!1,securityLevel:"strict"})}catch{if(y||t!==k)return;for(const{element:s,source:w}of c)n.contains(s)&&A(s,w);return}for(const[s,{element:w,source:R}]of c.entries()){if(y||t!==k||!n.contains(w))return;try{const X=`${j}-${t}-${s}`,Le=await q(g.render(X,R),U,"Mermaid render");if(K(X),y||t!==k||!n.contains(w))return;const L=$e(S.value),Fe=L?xe(L):!1;w.removeAttribute("data-mermaid-pending"),w.removeAttribute("data-mermaid-source"),w.innerHTML=Le.svg,L&&Fe&&ee(()=>{L.scrollTop=L.scrollHeight})}catch{if(K(`${j}-${t}-${s}`),y||t!==k||!n.contains(w))return;A(w,R)}}}He(()=>{Z()}),Re(V,()=>{Z()},{flush:"post"}),Ue(()=>{y=!0,k+=1});async function Me(t){const n=await lt(t);if(n!==null){n?_.success(m("common.copied")):_.error(m("chat.copyFailed"));return}const f=t.target,d=f.closest("img");if(d){t.preventDefault(),C.value=d.src;return}const h=f.closest(".markdown-file-card");if(h){t.preventDefault(),t.stopPropagation();const g=h.getAttribute("data-path"),s=h.getAttribute("data-filename")||void 0;if(f.closest(".att-download-btn")&&g){_.info(m("download.downloading")),P(g,s).catch(w=>{_.error(w.message||m("download.downloadFailed"))});return}if(g){const w=s?.split(".").pop()?.toLowerCase();ve.includes(w||"")?be(g,s||""):P(g,s).catch(R=>{_.error(R.message||m("download.downloadFailed"))})}return}const u=f.closest("a");if(!u)return;const c=u.getAttribute("href");if(c){if(c.startsWith("http://")||c.startsWith("https://")){t.preventDefault(),window.open(c,"_blank","noopener,noreferrer");return}if(c.startsWith("/api/hermes/download?")){t.preventDefault(),t.stopPropagation();const g=u.textContent||"",s=g.startsWith("File: ")?g.slice(6).trim():g.trim();_.info(m("download.downloading")),P(new URL(c,window.location.origin).searchParams.get("path")||c,s||void 0).catch(w=>{_.error(w.message||m("download.downloadFailed"))});return}if(H(c)){t.preventDefault(),t.stopPropagation();const g=u.textContent||"",s=g.startsWith("File: ")?g.slice(6).trim():g.trim();_.info(m("download.downloading")),P(W(c),s||void 0).catch(w=>{_.error(w.message||m("download.downloadFailed"))})}}}async function be(t,n){B.value=!0,E.value=!0,G.value=n,$.value=null;try{$.value=await tt(t,n)}catch(f){_.error(f.message||m("download.downloadFailed"))}finally{B.value=!1}}function Ce(){E.value=!1}return(t,n)=>{const f=Ae("MarkdownRenderer",!0);return F(),I(Oe,null,[Q("div",{ref_key:"markdownBody",ref:S,class:"markdown-body",innerHTML:V.value,onClick:Me},null,8,le),N(T(Pe),{show:E.value,"onUpdate:show":n[0]||(n[0]=d=>E.value=d),width:me,placement:"right","show-mask":!1,"trap-focus":!1,class:"markdown-text-preview-drawer"},{default:z(()=>[N(T(Ne),{title:T(m)("download.contentDisplay"),closable:"","body-content-style":{padding:0},onClose:Ce},{default:z(()=>[N(T(ze),{show:B.value},{default:z(()=>[$.value!==null&&ye.value?(F(),I("div",ce,[N(f,{content:$.value},null,8,["content"])])):$.value!==null?(F(),I("pre",de,Be($.value),1)):Y("",!0)]),_:1},8,["show"])]),_:1},8,["title"])]),_:1},8,["show"]),(F(),De(Te,{to:"body"},[C.value?(F(),I("div",{key:0,class:"image-preview-overlay",onClick:n[2]||(n[2]=Ie(d=>C.value=null,["self"]))},[Q("img",{src:C.value,class:"image-preview-img",onClick:n[1]||(n[1]=d=>C.value=null)},null,8,ue)])):Y("",!0)]))],64)}}})})),bt=M((()=>{})),Ct,Ot=M((()=>{fe(),fe(),bt(),Ct=ke}));export{ct as a,lt as i,Ot as n,ae as o,st as r,Ct as t};
