rt-chat-messages 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -0
- package/dist/chat-messages.es.js +1151 -0
- package/dist/chat-messages.umd.js +1 -0
- package/dist/style.css +1 -0
- package/dist/types/components/AgentSteps.vue.d.ts +11 -0
- package/dist/types/components/ChatMessageList.vue.d.ts +72 -0
- package/dist/types/components/MarkdownMessage.vue.d.ts +11 -0
- package/dist/types/components/MultimodalMessage.vue.d.ts +25 -0
- package/dist/types/components/ui/Button.vue.d.ts +34 -0
- package/dist/types/components/ui/Dialog.vue.d.ts +38 -0
- package/dist/types/icons/index.d.ts +14 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/types/index.d.ts +21 -0
- package/package.json +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(v,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("markdown-it"),require("@vscode/markdown-it-katex"),require("mermaid")):typeof define=="function"&&define.amd?define(["exports","vue","markdown-it","@vscode/markdown-it-katex","mermaid"],e):(v=typeof globalThis<"u"?globalThis:v||self,e(v.ChatMessages={},v.Vue,v.markdownit,v.markdownItKatex,v.mermaid))})(this,(function(v,e,we,Ce,ce){"use strict";const Ee={class:"cm-dialog__body"},Be=e.defineComponent({__name:"Dialog",props:{visible:{type:Boolean,default:!1},width:{default:"50%"},fullscreen:{type:Boolean,default:!1},showClose:{type:Boolean,default:!0},closeOnClickModal:{type:Boolean,default:!0},appendToBody:{type:Boolean,default:!0}},emits:["update:visible","close"],setup(o,{emit:i}){const y=o,c=i,E=e.ref(!1);e.onMounted(()=>{E.value=!0});const w=e.computed(()=>y.fullscreen?{width:"100%",height:"100%",margin:0}:{width:y.width}),B=()=>{c("update:visible",!1),c("close")},h=()=>{y.closeOnClickModal&&B()};return(T,M)=>E.value?(e.openBlock(),e.createBlock(e.Teleport,{key:0,to:"body"},[o.visible?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["cm-dialog-overlay",{"is-fullscreen":o.fullscreen}]),onClick:e.withModifiers(h,["self"])},[e.createElementVNode("div",{class:"cm-dialog",style:e.normalizeStyle(w.value),role:"dialog","aria-modal":"true"},[e.createElementVNode("div",Ee,[e.renderSlot(T.$slots,"default",{},void 0,!0)]),o.showClose?(e.openBlock(),e.createElementBlock("button",{key:0,class:"cm-dialog__close",onClick:B},[...M[0]||(M[0]=[e.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"16",height:"16"},[e.createElementVNode("path",{fill:"currentColor",d:"M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"})],-1)])])):e.createCommentVNode("",!0)],4)],2)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)}}),U=(o,i)=>{const y=o.__vccOpts||o;for(const[c,E]of i)y[c]=E;return y},te=U(Be,[["__scopeId","data-v-efdf0259"]]),Me=["disabled"],Ve={key:0,class:"cm-icon-loading"},z=U(e.defineComponent({__name:"Button",props:{type:{default:"default"},size:{default:"default"},circle:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},loading:{type:Boolean,default:!1}},emits:["click"],setup(o,{emit:i}){const y=o,c=i,E=w=>{y.disabled||y.loading||c("click",w)};return(w,B)=>(e.openBlock(),e.createElementBlock("button",{class:e.normalizeClass(["cm-button",[`cm-button--${o.type}`,`cm-button--${o.size}`,{"is-circle":o.circle,"is-disabled":o.disabled,"is-loading":o.loading}]]),disabled:o.disabled||o.loading,onClick:E},[o.loading?(e.openBlock(),e.createElementBlock("span",Ve,[...B[0]||(B[0]=[e.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"1em",height:"1em"},[e.createElementVNode("path",{fill:"currentColor",d:"M512 64a448 448 0 0 1 448 448 32 32 0 1 1-64 0 416 416 0 0 0-416-416 416 416 0 0 0-416 416 32 32 0 1 1-64 0 448 448 0 0 1 448-448z"})],-1)])])):e.renderSlot(w.$slots,"default",{key:1},void 0,!0)],10,Me))}}),[["__scopeId","data-v-bab126c7"]]),L=(o,i)=>e.defineComponent({name:o,render(){return e.h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024",width:"1em",height:"1em",fill:"currentColor",style:"vertical-align: middle"},[e.h("path",{d:i})])}}),G=L("Close","M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"),ie=L("ZoomIn","M637.696 587.392a316.032 316.032 0 1 0-45.44 49.344l191.232 191.296a32 32 0 0 0 45.312-45.184L637.696 587.392zM73.152 357.696a284.48 284.48 0 1 1 284.48 284.48A284.672 284.672 0 0 1 73.152 357.568zm268.48-154.56a32 32 0 0 0-32 32v90.496h-90.56a32 32 0 0 0 0 64h90.56v90.56a32 32 0 0 0 64 0v-90.496h90.496a32 32 0 0 0 0-64H373.632v-90.56a32 32 0 0 0-32-32z"),de=L("ZoomOut","M637.696 587.392a316.032 316.032 0 1 0-45.44 49.344l191.232 191.296a32 32 0 0 0 45.312-45.184L637.696 587.392zM73.152 357.696a284.48 284.48 0 1 1 284.48 284.48A284.672 284.672 0 0 1 73.152 357.568zm145.92-58.56a32 32 0 0 0 0 64h245.12a32 32 0 0 0 0-64H219.072z"),me=L("Document","M854.6 288.7c0.4 0 0.7 0 1 0v431.5c0 17.6-14.4 32-32 32H200.4c-17.6 0-32-14.4-32-32l0-575.2c0-17.6 14.4-32 32-32h391.5c0 0.3 0 0.7 0 1l0 142.1c0 17.6 14.4 32.1 32 32.1h142.6c0-0.4 0-0.7 0-1.1L854.6 288.7zM790.2 220.2L668 97.9v122.3h122.2zM240 448h544a32 32 0 0 0 0-64H240a32 32 0 0 0 0 64zm0 128h544a32 32 0 0 0 0-64H240a32 32 0 0 0 0 64zm0 128h384a32 32 0 0 0 0-64H240a32 32 0 0 0 0 64z"),ge=L("Download","M505.7 661a8 8 0 0 0 12.6 0l112-141.7c4.1-5.2 0.4-12.9-6.3-12.9h-74.1V168c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v338.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.8zM878 626h-60c-4.4 0-8 3.6-8 8v154H214V634c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v198c0 17.7 14.3 32 32 32h684c17.7 0 32-14.3 32-32V634c0-4.4-3.6-8-8-8z"),Ne=L("VideoPlay","M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 832a384 384 0 1 0 0-768 384 384 0 0 0 0 768zm-48-247.616L668.608 512 464 375.616v272.768zm10.656-340.32a32 32 0 0 1 32 32V673.92a32 32 0 0 1-50.208 26.24l-236.8-161.92a32 32 0 0 1 0-52.48l236.8-161.92a32 32 0 0 1 18.208-5.632z"),_e=L("VideoPause","M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 832a384 384 0 1 0 0-768 384 384 0 0 0 0 768zm-96-544a32 32 0 0 1 32 32v256a32 32 0 0 1-64 0V384a32 32 0 0 1 32-32zm192 0a32 32 0 0 1 32 32v256a32 32 0 0 1-64 0V384a32 32 0 0 1 32-32z"),be=L("ArrowLeft","M609.408 149.376 277.76 489.6a32 32 0 0 0 0 44.672l331.648 340.352a29.12 29.12 0 0 0 41.728 0 30.592 30.592 0 0 0 0-42.752L339.264 511.936l311.872-319.872a30.592 30.592 0 0 0 0-42.688 29.12 29.12 0 0 0-41.728 0z"),xe=L("ArrowRight","M340.864 149.312a29.12 29.12 0 0 0-41.728 0 30.592 30.592 0 0 0 0 42.752L611.072 511.936 299.136 831.872a30.592 30.592 0 0 0 0 42.752 29.12 29.12 0 0 0 41.728 0L672.448 534.272a32 32 0 0 0 0-44.672L340.864 149.312z"),fe=L("Spinner","M512 64a448 448 0 0 1 448 448 32 32 0 1 1-64 0 416 416 0 0 0-416-416 416 416 0 0 0-416 416 32 32 0 1 1-64 0 448 448 0 0 1 448-448z"),he=L("Check","M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474a32 32 0 0 0-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1 0.4-12.8-6.3-12.8z"),$e=L("ChevronUp","M854.6 642.5l-320-320c-12.5-12.5-32.8-12.5-45.3 0l-320 320c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L512 390.6l297.4 297.4c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3z"),Se=L("ChevronDown","M854.6 381.5l-320 320c-12.5 12.5-32.8 12.5-45.3 0l-320-320c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L512 633.4l297.4-297.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3z"),ve=["src","alt"],ze={class:"preview-controls"},Le={class:"cm-button-group"},De={key:0,class:"mobile-close-hint"},Te=["innerHTML"],Ie={class:"preview-controls"},Ae={class:"cm-button-group"},He={key:0,class:"mobile-close-hint"},ae=U(e.defineComponent({__name:"MarkdownMessage",props:{content:{},isStreaming:{type:Boolean,default:!1}},setup(o){const i=o,y=e.ref(),c=e.ref(),E=e.ref(!1),w=e.ref(""),B=e.ref(""),h=e.ref(!1),T=e.ref(""),M=e.ref(!1),l=e.ref(1),k=e.ref({x:0,y:0}),V=e.ref(!1),b=e.ref({x:0,y:0}),x=e.ref(1),C=e.ref({x:0,y:0}),q=e.ref(!1),Y=e.ref({x:0,y:0}),O=e.ref(""),F=e.ref(new Map);let W=0;ce.initialize({startOnLoad:!1,theme:"default",securityLevel:"loose",fontFamily:"inherit"});const Q=t=>{const a=t.renderer.rules.fence;t.renderer.rules.fence=(s,g,r,n,m)=>{const p=s[g],S=p.content.trim();return(p.info?p.info.trim():"")==="mermaid"?(W++,`<div class="mermaid-container"><pre class="mermaid" data-mermaid-id="${`mermaid-${Date.now()}-${W}`}">${S}</pre></div>`):a(s,g,r,n,m)}},R=new we({html:!0,xhtmlOut:!1,breaks:!0,langPrefix:"language-",linkify:!0,typographer:!0,quotes:`""''`,highlight:function(t,a){return a&&a.trim()?`<pre class="hljs language-${a}"><code>${(g=>g.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"))(t)}</code></pre>`:`<pre class="hljs"><code>${t}</code></pre>`}}),Z=R.renderer.rules.image||function(t,a,s,g,r){return r.renderToken(t,a,s)};R.renderer.rules.image=function(t,a,s,g,r){const n=t[a],m=n.attrIndex("src");if(m>=0){const p=n.attrs[m][1],_="img-"+(I=>{let $=0;for(let D=0;D<I.length;D++){const H=I.charCodeAt(D);$=($<<5)-$+H,$=$&$}return Math.abs($).toString(36)})(p);n.attrSet("id",_),n.attrSet("data-image-id",_),n.attrSet("key",_),n.attrSet("loading","eager"),n.attrSet("decoding","async"),n.attrSet("fetchpriority","high"),n.attrSet("data-src",p),n.attrSet("data-cached","true")}return Z(t,a,s,g,r)},R.use(Ce,{throwOnError:!1,errorColor:"#cc0000"}),R.use(Q);const oe=t=>{const a=t.match(/```[\w]*\n/g),s=t.match(/\n```/g),g=(a==null?void 0:a.length)||0,r=(s==null?void 0:s.length)||0;return g>r&&(t+="\n```"),t},ee=t=>{if(!t)return"";t=t.replace(/;;\s*$/g,""),t=t.replace(/;;\s*$/g,"");const a=/^```(?:markdown|md)\s*\n([\s\S]*?)\n```$/,s=t.match(a);if(s)t=s[1];else{const g=/^```\s*\n([\s\S]*?)\n```$/,r=t.match(g);if(r){const n=r[1];(/^#{1,6}\s/.test(n)||/^\*{1,2}[^*]+\*{1,2}/.test(n)||/^[-*+]\s/.test(n)||/^\d+\.\s/.test(n)||/!\[.*?\]\(.*?\)/.test(n)||/\[.*?\]\(.*?\)/.test(n)||/^\|.+\|/.test(n)||/^\|[\s-:]+\|/m.test(n))&&(t=n)}}if(i.isStreaming){const g=/^```(?:markdown|md)?\s*\n/;if(g.test(t)){const n=t.replace(g,"");(/^#{1,6}\s/.test(n)||/^\|.+\|/.test(n)||/^\|[\s-:]+\|/m.test(n)||/!\[.*?\]\(.*?\)/.test(n)||/\[.*?\]\(.*?\)/.test(n))&&(t=t.replace(g,""))}if(/^```(?:markdown|md)?\s*\n/.test(i.content)){const n=/\n```\s*$/;n.test(t)&&(t=t.replace(n,""))}}return t=t.replace(/```(?:markdown|md)\s*\n([\s\S]*?)\n```/g,(g,r)=>r),i.isStreaming&&(t=oe(t)),t},se=t=>{if(!t.includes("<img"))return t;const a=/<img[^>]*?src="([^"]*)"[^>]*?>/g;let s,g=t;const r=[];for(;(s=a.exec(t))!==null;){const n=s[0],m=s[1];if(F.value.has(m)){const p=F.value.get(m);n!==p&&r.push({original:n,cached:p})}else F.value.set(m,n)}for(const{original:n,cached:m}of r)g=g.replace(n,m);return g},le=t=>{if(!c.value)return;const a=c.value;if(!i.isStreaming||a.children.length===0){a.innerHTML=t,i.isStreaming||e.nextTick(()=>{ye(),u()});return}const s=document.createElement("div");s.innerHTML=t;const g=new Map;a.querySelectorAll("img[data-image-id]").forEach(n=>{const m=n.getAttribute("data-image-id");m&&g.set(m,n)}),s.querySelectorAll("img[data-image-id]").forEach(n=>{const m=n.getAttribute("data-image-id");if(m&&g.has(m)){const p=g.get(m);n.parentNode&&n.parentNode.replaceChild(p,n)}});const r=document.createDocumentFragment();for(;s.firstChild;)r.appendChild(s.firstChild);a.innerHTML="",a.appendChild(r)},P=()=>{try{if(!i.content){O.value="",c.value&&(c.value.innerHTML=""),i.isStreaming||F.value.clear();return}const t=ee(i.content);let a=R.render(t);i.isStreaming&&a.includes("<img")&&(a=se(a)),a!==O.value&&(O.value=a,le(a)),i.isStreaming||F.value.clear()}catch(t){console.error("Markdown rendering error:",t),c.value&&(c.value.innerHTML=`<pre style="white-space: pre-wrap; word-wrap: break-word;">${i.content}</pre>`)}};e.watch(()=>i.content,P),e.watch(()=>i.isStreaming,(t,a)=>{a&&!t&&e.nextTick(()=>{P()})});const d=()=>{M.value=window.innerWidth<768},f=t=>{let a=t;return a=a.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1"),[/([A-Za-z0-9_]+)\[([^\]]*[\u4e00-\u9fa5]+[^\]]*)\]/g,/([A-Za-z0-9_]+)\(([^)]*[\u4e00-\u9fa5]+[^)]*)\)/g,/([A-Za-z0-9_]+)\{([^}]*[\u4e00-\u9fa5]+[^}]*)\}/g].forEach(g=>{a=a.replace(g,(r,n,m)=>{if(m.startsWith('"')&&m.endsWith('"'))return r;let p=m.replace(/^["']+|["']+$/g,"").replace(/["]/g,'\\"');return r.includes("[")?`${n}["${p}"]`:r.includes("(")?`${n}("${p}")`:r.includes("{")?`${n}{"${p}"}`:r})}),a},u=async()=>{var a,s;if(i.isStreaming||(await e.nextTick(),!y.value))return;const t=y.value.querySelectorAll(".mermaid");if(t.length!==0)for(const g of Array.from(t)){const r=g;let n=(a=r.textContent)==null?void 0:a.trim();if(n&&r.getAttribute("data-processed")!=="true")try{r.setAttribute("data-processed","true"),n=f(n);const m=r.getAttribute("data-mermaid-id")||`mermaid-${Date.now()}-${Math.random()}`,{svg:p}=await ce.render(m,n),S=r.parentElement;if(S){const _=document.createElement("div");_.className="mermaid-svg",_.innerHTML=p,_.setAttribute("data-mermaid-svg","true"),_.style.cursor="pointer",_.title="Click to zoom",_.addEventListener("click",I=>{I.preventDefault(),I.stopPropagation(),T.value=p,x.value=1,C.value={x:0,y:0},h.value=!0}),S.replaceChild(_,r)}}catch(m){console.error("Mermaid render failure:",m);const p=document.createElement("div");p.className="mermaid-error",p.textContent=`Mermaid render error: ${m}`,(s=r.parentElement)==null||s.replaceChild(p,r)}}},N=t=>{t.preventDefault(),t.stopPropagation();const a=t.target;w.value=a.src,B.value=a.alt||"Image Preview",l.value=1,k.value={x:0,y:0},E.value=!0},A=()=>{l.value<=1&&(k.value={x:0,y:0})},Ht=()=>{l.value=Math.min(l.value+1,10),A()},Ft=()=>{l.value=Math.max(l.value-1,.5),A()},pe=()=>{l.value=1,k.value={x:0,y:0}},Rt=()=>{l.value<=1&&(E.value=!1)},Pt=t=>{t.preventDefault();const a=t.deltaY>0?-.5:.5,s=Math.max(.5,Math.min(10,l.value+a));l.value=s,A()},Ut=t=>{var n;if(l.value<=1)return;t.preventDefault(),V.value=!0,b.value={x:t.clientX-k.value.x,y:t.clientY-k.value.y};const a=t.target,s=(n=a.parentElement)==null?void 0:n.getBoundingClientRect(),g=m=>{if(!V.value||!s)return;let p=m.clientX-b.value.x,S=m.clientY-b.value.y;const _=a.offsetWidth,I=a.offsetHeight,$=_*l.value,D=I*l.value,H=.3,re=s.width*(1-H-.5)-$/2,j=$/2-s.width*(1-H-.5),K=s.height*(1-H-.5)-D/2,X=D/2-s.height*(1-H-.5);$>s.width?p=Math.max(re,Math.min(j,p)):p=0,D>s.height?S=Math.max(K,Math.min(X,S)):S=0,k.value={x:p,y:S}},r=()=>{V.value=!1,document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",r)};document.addEventListener("mousemove",g),document.addEventListener("mouseup",r)},Yt=t=>{var S;if(t.touches.length!==1)return;const a=t.touches[0],s=a.clientX,g=a.clientY;if(l.value<=1)return;V.value=!0,b.value={x:s-k.value.x,y:g-k.value.y};const r=t.target,n=(S=r.parentElement)==null?void 0:S.getBoundingClientRect(),m=_=>{if(!V.value||_.touches.length!==1||!n)return;const I=_.touches[0];let $=I.clientX-b.value.x,D=I.clientY-b.value.y;const H=r.offsetWidth,re=r.offsetHeight,j=H*l.value,K=re*l.value,X=.3,jt=n.width*(1-X-.5)-j/2,Kt=j/2-n.width*(1-X-.5),Gt=n.height*(1-X-.5)-K/2,Jt=K/2-n.height*(1-X-.5);j>n.width?$=Math.max(jt,Math.min(Kt,$)):$=0,K>n.height?D=Math.max(Gt,Math.min(Jt,D)):D=0,k.value={x:$,y:D}},p=()=>{V.value=!1,document.removeEventListener("touchmove",m),document.removeEventListener("touchend",p)};document.addEventListener("touchmove",m,{passive:!1}),document.addEventListener("touchend",p)},Ot=()=>{x.value=Math.min(x.value+1,10)},Wt=()=>{x.value=Math.max(x.value-1,.5)},ke=()=>{x.value=1,C.value={x:0,y:0}},Xt=t=>{t.preventDefault();const a=t.deltaY>0?-.5:.5;x.value=Math.max(.5,Math.min(10,x.value+a))},qt=t=>{var n,m;if(x.value<=1)return;t.preventDefault(),q.value=!0,Y.value={x:t.clientX-C.value.x,y:t.clientY-C.value.y};const s=(m=(n=t.target.closest(".mermaid-preview-content"))==null?void 0:n.parentElement)==null?void 0:m.getBoundingClientRect(),g=p=>{if(!q.value||!s)return;let S=p.clientX-Y.value.x,_=p.clientY-Y.value.y;C.value={x:S,y:_}},r=()=>{q.value=!1,document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",r)};document.addEventListener("mousemove",g),document.addEventListener("mouseup",r)},Zt=t=>{},ye=()=>{i.isStreaming||e.nextTick(()=>{if(!y.value)return;y.value.querySelectorAll(".markdown-content img").forEach(a=>{const s=a;s.getAttribute("data-processed")!=="true"&&(s.setAttribute("data-processed","true"),s.style.cursor="pointer",s.addEventListener("click",N))})})};return e.onMounted(()=>{d(),window.addEventListener("resize",d),P(),ye(),u()}),e.onUnmounted(()=>{y.value&&y.value.querySelectorAll(".markdown-content img").forEach(a=>{a.removeEventListener("click",N)})}),(t,a)=>(e.openBlock(),e.createElementBlock("div",{class:"markdown-message",ref_key:"markdownContainer",ref:y},[e.createElementVNode("div",{ref_key:"markdownContent",ref:c,class:"markdown-content"},null,512),e.createVNode(te,{visible:E.value,"onUpdate:visible":a[2]||(a[2]=s=>E.value=s),width:M.value?"95vw":"80vw",fullscreen:M.value,class:"image-preview-dialog","close-on-click-modal":!1,"append-to-body":""},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"image-preview-container",onClick:a[1]||(a[1]=e.withModifiers(s=>E.value=!1,["self"]))},[e.createElementVNode("img",{src:w.value,alt:B.value,class:"preview-image",style:e.normalizeStyle({transform:`translate(${k.value.x}px, ${k.value.y}px) scale(${l.value})`}),onWheel:e.withModifiers(Pt,["prevent"]),onDblclick:pe,onMousedown:Ut,onTouchstart:e.withModifiers(Yt,["prevent"]),onClick:Rt},null,44,ve),e.createElementVNode("div",ze,[e.createElementVNode("div",Le,[e.createVNode(z,{size:"small",onClick:Ft,disabled:l.value<=.5},{default:e.withCtx(()=>[e.createVNode(e.unref(de))]),_:1},8,["disabled"]),e.createVNode(z,{size:"small",onClick:pe},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(Math.round(l.value*100))+"% ",1)]),_:1}),e.createVNode(z,{size:"small",onClick:Ht,disabled:l.value>=10},{default:e.withCtx(()=>[e.createVNode(e.unref(ie))]),_:1},8,["disabled"])]),e.createVNode(z,{size:"small",onClick:a[0]||(a[0]=s=>E.value=!1),type:"danger"},{default:e.withCtx(()=>[e.createVNode(e.unref(G))]),_:1})]),M.value?(e.openBlock(),e.createElementBlock("div",De,"双击重置 · 轻触关闭")):e.createCommentVNode("",!0)])]),_:1},8,["visible","width","fullscreen"]),e.createVNode(te,{visible:h.value,"onUpdate:visible":a[5]||(a[5]=s=>h.value=s),width:M.value?"95vw":"90vw",fullscreen:M.value,class:"mermaid-preview-dialog","close-on-click-modal":!1,"append-to-body":""},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"mermaid-preview-container",onClick:a[4]||(a[4]=e.withModifiers(s=>h.value=!1,["self"]))},[e.createElementVNode("div",{class:"mermaid-preview-content",innerHTML:T.value,style:e.normalizeStyle({transform:`translate(${C.value.x}px, ${C.value.y}px) scale(${x.value})`}),onWheel:e.withModifiers(Xt,["prevent"]),onDblclick:ke,onMousedown:qt,onTouchstart:e.withModifiers(Zt,["prevent"])},null,44,Te),e.createElementVNode("div",Ie,[e.createElementVNode("div",Ae,[e.createVNode(z,{size:"small",onClick:Wt,disabled:x.value<=.5},{default:e.withCtx(()=>[e.createVNode(e.unref(de))]),_:1},8,["disabled"]),e.createVNode(z,{size:"small",onClick:ke},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(Math.round(x.value*100))+"% ",1)]),_:1}),e.createVNode(z,{size:"small",onClick:Ot,disabled:x.value>=10},{default:e.withCtx(()=>[e.createVNode(e.unref(ie))]),_:1},8,["disabled"])]),e.createVNode(z,{size:"small",onClick:a[3]||(a[3]=s=>h.value=!1),type:"danger"},{default:e.withCtx(()=>[e.createVNode(e.unref(G))]),_:1})]),M.value?(e.openBlock(),e.createElementBlock("div",He,"双击重置 · 轻触关闭")):e.createCommentVNode("",!0)])]),_:1},8,["visible","width","fullscreen"])],512))}}),[["__scopeId","data-v-3b421627"]]),Fe={key:0,class:"text-content"},Re={key:1,class:"images-content"},Pe=["onClick"],Ue=["src","alt","onError"],Ye={key:0,class:"more-images"},Oe={key:2,class:"attachments-content"},We={class:"file-icon-wrapper"},Xe={class:"attachment-info"},qe={class:"attachment-name"},Ze={class:"attachment-size"},je={key:3,class:"files-content"},Ke=["onClick"],Ge={class:"file-icon-wrapper-small"},Je={class:"file-info"},Qe={class:"file-name"},et={class:"file-type"},tt={class:"file-actions"},at={key:4,class:"audio-content"},nt={class:"audio-player"},ot={class:"audio-info"},st={class:"audio-progress"},lt={class:"progress-bar"},rt={class:"audio-time"},ct={class:"image-preview-container"},it=["src"],dt={key:0,class:"image-nav"},mt={class:"image-counter"},J=U(e.defineComponent({__name:"MultimodalMessage",props:{message:{},isUser:{type:Boolean,default:!1},isStreaming:{type:Boolean,default:!1}},setup(o){const i=o,y=e.computed(()=>{try{return i.message.metadata?JSON.parse(i.message.metadata):{}}catch{return{}}}),c=e.computed(()=>y.value.imageUrls||[]),E=e.computed(()=>y.value.fileUrls||[]),w=e.computed(()=>y.value.audioUrl),B=e.computed(()=>i.message.attachments&&i.message.attachments.length>0?i.message.attachments:y.value.attachments&&Array.isArray(y.value.attachments)?y.value.attachments:[]),h=e.ref(!1),T=e.ref(""),M=e.ref(0),l=e.ref(!1),k=e.ref(!1),V=e.ref(0),b=e.ref(0),x=e.computed(()=>b.value>0?V.value/b.value*100:0);let C=null;const q=(d,f)=>{T.value=d,M.value=f,h.value=!0},Y=()=>{M.value>0&&(M.value--,T.value=c.value[M.value])},O=()=>{M.value<c.value.length-1&&(M.value++,T.value=c.value[M.value])},F=(d,f)=>{console.error("Image load failed:",f);const u=d.target;u.style.display="none"},W=d=>{try{const u=new URL(d).pathname,N=u.substring(u.lastIndexOf("/")+1);return decodeURIComponent(N)||"Unknown File"}catch{return"Unknown File"}},Q=d=>{var N;return((N=W(d).split(".").pop())==null?void 0:N.toUpperCase())||"FILE"},R=d=>{const f=Q(d).toLowerCase();["jpg","jpeg","png","gif","webp","pdf"].includes(f)?window.open(d,"_blank"):Z(d)},Z=d=>{try{const f=document.createElement("a");f.href=d,f.download=W(d),f.target="_blank",document.body.appendChild(f),f.click(),document.body.removeChild(f)}catch(f){console.error("Download failed:",f),alert("下载失败")}},oe=async()=>{if(w.value)try{C||(C=new Audio,C.src=w.value,C.addEventListener("loadedmetadata",()=>{b.value=(C==null?void 0:C.duration)||0}),C.addEventListener("timeupdate",()=>{V.value=(C==null?void 0:C.currentTime)||0}),C.addEventListener("ended",()=>{l.value=!1,V.value=0}),C.addEventListener("error",d=>{console.error("Audio playback error:",d),k.value=!1,l.value=!1})),l.value?(C.pause(),l.value=!1):(k.value=!0,await C.play(),l.value=!0,k.value=!1)}catch(d){console.error("Audio playback failed:",d),k.value=!1,l.value=!1}},ee=d=>{const f=Math.floor(d/60),u=Math.floor(d%60);return`${f}:${u.toString().padStart(2,"0")}`},se=d=>{if(d===0)return"0 B";const f=1024,u=["B","KB","MB","GB"],N=Math.floor(Math.log(d)/Math.log(f));return(d/Math.pow(f,N)).toFixed(2)+u[N]},le=d=>{var u;return((u=d.split(".").pop())==null?void 0:u.toUpperCase())||"FILE"},P=d=>{h.value&&(d.key==="ArrowLeft"?Y():d.key==="ArrowRight"?O():d.key==="Escape"&&(h.value=!1))};return e.watch(h,d=>{d?document.addEventListener("keydown",P):document.removeEventListener("keydown",P)}),e.onUnmounted(()=>{C&&(C.pause(),C=null),document.removeEventListener("keydown",P)}),(d,f)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["multimodal-message",{"is-user":o.isUser,"is-assistant":!o.isUser}])},[o.message.content?(e.openBlock(),e.createElementBlock("div",Fe,[e.createVNode(ae,{content:o.message.content,"is-streaming":o.isStreaming},null,8,["content","is-streaming"])])):e.createCommentVNode("",!0),c.value&&c.value.length>0?(e.openBlock(),e.createElementBlock("div",Re,[e.createElementVNode("div",{class:e.normalizeClass(["images-grid",`grid-${Math.min(c.value.length,4)}`])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.value.slice(0,4),(u,N)=>(e.openBlock(),e.createElementBlock("div",{key:N,class:"image-item",onClick:A=>q(u,N)},[e.createElementVNode("img",{src:u,alt:`图片 ${N+1}`,onError:A=>F(A,u),loading:"lazy"},null,40,Ue),N===3&&c.value.length>4?(e.openBlock(),e.createElementBlock("div",Ye," +"+e.toDisplayString(c.value.length-4),1)):e.createCommentVNode("",!0)],8,Pe))),128))],2)])):e.createCommentVNode("",!0),B.value&&B.value.length>0?(e.openBlock(),e.createElementBlock("div",Oe,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,(u,N)=>(e.openBlock(),e.createElementBlock("div",{key:N,class:"attachment-item"},[e.createElementVNode("div",We,[e.createVNode(e.unref(me),{class:"file-icon"})]),e.createElementVNode("div",Xe,[e.createElementVNode("span",qe,e.toDisplayString(u.name),1),e.createElementVNode("span",Ze,e.toDisplayString(le(u.name))+" "+e.toDisplayString(se(u.size)),1)])]))),128))])):e.createCommentVNode("",!0),E.value&&E.value.length>0?(e.openBlock(),e.createElementBlock("div",je,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(E.value,(u,N)=>(e.openBlock(),e.createElementBlock("div",{key:N,class:"file-item",onClick:A=>R(u)},[e.createElementVNode("div",Ge,[e.createVNode(e.unref(me),{class:"file-icon"})]),e.createElementVNode("div",Je,[e.createElementVNode("span",Qe,e.toDisplayString(W(u)),1),e.createElementVNode("span",et,e.toDisplayString(Q(u)),1)]),e.createElementVNode("div",tt,[e.createVNode(z,{size:"small",type:"text",onClick:e.withModifiers(A=>Z(u),["stop"])},{default:e.withCtx(()=>[e.createVNode(e.unref(ge))]),_:1},8,["onClick"])])],8,Ke))),128))])):e.createCommentVNode("",!0),w.value?(e.openBlock(),e.createElementBlock("div",at,[e.createElementVNode("div",nt,[e.createVNode(z,{onClick:oe,loading:k.value,circle:"",size:"small",class:"play-btn"},{default:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(l.value?e.unref(_e):e.unref(Ne))))]),_:1},8,["loading"]),e.createElementVNode("div",ot,[e.createElementVNode("div",st,[e.createElementVNode("div",lt,[e.createElementVNode("div",{class:"progress-fill",style:e.normalizeStyle({width:x.value+"%"})},null,4)])]),e.createElementVNode("div",rt,[e.createElementVNode("span",null,e.toDisplayString(ee(V.value)),1),f[4]||(f[4]=e.createElementVNode("span",null,"/",-1)),e.createElementVNode("span",null,e.toDisplayString(ee(b.value)),1)])]),e.createVNode(z,{onClick:f[0]||(f[0]=u=>Z(w.value)),size:"small",type:"text",class:"download-btn"},{default:e.withCtx(()=>[e.createVNode(e.unref(ge))]),_:1})])])):e.createCommentVNode("",!0),e.createVNode(te,{visible:h.value,"onUpdate:visible":f[3]||(f[3]=u=>h.value=u),width:"90%","show-close":!1,"append-to-body":"",class:"image-preview-dialog-wrapper"},{default:e.withCtx(()=>[e.createElementVNode("div",ct,[e.createElementVNode("img",{src:T.value,alt:"预览图片",class:"preview-image",onClick:f[1]||(f[1]=u=>h.value=!1)},null,8,it),c.value&&c.value.length>1?(e.openBlock(),e.createElementBlock("div",dt,[e.createVNode(z,{onClick:Y,disabled:M.value===0,circle:"",class:"nav-btn"},{default:e.withCtx(()=>[e.createVNode(e.unref(be))]),_:1},8,["disabled"]),e.createElementVNode("span",mt,e.toDisplayString(M.value+1)+" / "+e.toDisplayString(c.value.length),1),e.createVNode(z,{onClick:O,disabled:M.value===c.value.length-1,circle:"",class:"nav-btn"},{default:e.withCtx(()=>[e.createVNode(e.unref(xe))]),_:1},8,["disabled"])])):e.createCommentVNode("",!0),e.createVNode(z,{onClick:f[2]||(f[2]=u=>h.value=!1),class:"close-btn",circle:""},{default:e.withCtx(()=>[e.createVNode(e.unref(G))]),_:1})])]),_:1},8,["visible"])],2))}}),[["__scopeId","data-v-8a954827"]]),gt={key:0,class:"agent-steps"},ft={class:"steps-indicator"},ht={key:0,class:"icon-running"},ut={key:1,class:"icon-completed"},pt={class:"steps-summary"},kt={class:"icon-chevron"},yt={class:"steps-list"},wt={class:"step-icon"},Ct={key:3,class:"icon-dot"},Et={class:"step-name"},ne=U(e.defineComponent({__name:"AgentSteps",props:{steps:{}},setup(o){const i=o,y=e.ref(!0),c=e.computed(()=>i.steps.some(w=>w.status==="running")),E=e.computed(()=>{const w=i.steps.find(h=>h.status==="running");if(w)return`正在${w.displayName}...`;const B=i.steps.filter(h=>h.status==="completed").length;return B===i.steps.length?"处理完成":`已完成 ${B}/${i.steps.length} 个步骤`});return(w,B)=>o.steps.length>0?(e.openBlock(),e.createElementBlock("div",gt,[e.createElementVNode("div",{class:"steps-header",onClick:B[0]||(B[0]=h=>y.value=!y.value)},[e.createElementVNode("div",ft,[c.value?(e.openBlock(),e.createElementBlock("div",ht,[e.createVNode(e.unref(fe))])):(e.openBlock(),e.createElementBlock("div",ut,[e.createVNode(e.unref(he))]))]),e.createElementVNode("span",pt,e.toDisplayString(E.value),1),e.createElementVNode("div",kt,[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(y.value?e.unref($e):e.unref(Se))))])]),e.withDirectives(e.createElementVNode("div",yt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.steps,h=>(e.openBlock(),e.createElementBlock("div",{key:h.name,class:e.normalizeClass(["step-item",{"is-running":h.status==="running","is-completed":h.status==="completed","is-error":h.status==="error"}])},[e.createElementVNode("div",wt,[h.status==="running"?(e.openBlock(),e.createBlock(e.unref(fe),{key:0,class:"icon-spin"})):h.status==="completed"?(e.openBlock(),e.createBlock(e.unref(he),{key:1})):h.status==="error"?(e.openBlock(),e.createBlock(e.unref(G),{key:2})):(e.openBlock(),e.createElementBlock("div",Ct))]),e.createElementVNode("span",Et,e.toDisplayString(h.displayName),1)],2))),128))],512),[[e.vShow,y.value]])])):e.createCommentVNode("",!0)}}),[["__scopeId","data-v-eaae06ac"]]),Bt={class:"chat-message-list-root"},Mt={key:0,class:"bg-grid"},Vt={key:0,class:"welcome-screen"},Nt={class:"cm-welcome-center"},_t={class:"welcome-logo"},bt=["src"],xt={key:1,class:"default-logo"},$t={class:"welcome-title"},St={key:1,class:"messages-container"},vt={key:0,class:"message-bubble user-bubble"},zt={key:1,class:"message-content assistant-content"},Lt={class:"message-bubble assistant-bubble"},Dt={key:1,class:"message-actions"},Tt=["onClick"],It={key:0,class:"message-row message-assistant"},ue=U(e.defineComponent({__name:"ChatMessageList",props:{messages:{default:()=>[]},isStreaming:{type:Boolean,default:!1},isTyping:{type:Boolean,default:!1},showWelcome:{type:Boolean,default:!0},appName:{default:"AI助手"},appLogo:{},agentSteps:{},showAgentSteps:{type:Boolean,default:!0},autoScroll:{type:Boolean,default:!0},contentPaddingTop:{default:"80px"},contentPaddingBottom:{default:"100px"},showBackground:{type:Boolean,default:!0}},emits:["copy","scroll","scroll-bottom"],setup(o,{expose:i,emit:y}){const c=o,E=y,w=e.ref(null),B=e.ref(!1),h=async(l="smooth")=>{await e.nextTick(),w.value&&w.value.scrollTo({top:w.value.scrollHeight,behavior:l})},T=l=>{E("scroll",l);const k=l.target;if(!k)return;const{scrollTop:V,scrollHeight:b,clientHeight:x}=k;b-V-x<50?(B.value=!1,E("scroll-bottom")):c.isStreaming&&(B.value=!0)};e.watch(()=>c.messages.length,async()=>{c.autoScroll&&!B.value&&h()}),e.watch(()=>{var l;return(l=c.messages[c.messages.length-1])==null?void 0:l.content},async(l,k)=>{c.isStreaming&&c.autoScroll&&!B.value&&l&&k&&l.length>k.length&&w.value&&(w.value.scrollTop=w.value.scrollHeight)}),e.watch(()=>c.isTyping,l=>{l&&c.autoScroll&&h()});const M=l=>{E("copy",l),navigator.clipboard&&l.content&&navigator.clipboard.writeText(l.content)};return i({scrollToBottom:h,containerRef:w}),(l,k)=>(e.openBlock(),e.createElementBlock("div",Bt,[o.showBackground?(e.openBlock(),e.createElementBlock("div",Mt)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"chat-message-list",ref_key:"containerRef",ref:w,onScroll:T,style:e.normalizeStyle({paddingTop:o.contentPaddingTop,paddingBottom:o.contentPaddingBottom})},[o.showWelcome&&o.messages.length===0?(e.openBlock(),e.createElementBlock("div",Vt,[e.renderSlot(l.$slots,"welcome",{},()=>[e.createElementVNode("div",Nt,[e.createElementVNode("div",_t,[o.appLogo?(e.openBlock(),e.createElementBlock("img",{key:0,src:o.appLogo,alt:"Logo"},null,8,bt)):(e.openBlock(),e.createElementBlock("div",xt,[...k[0]||(k[0]=[e.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"32",height:"32"},[e.createElementVNode("path",{fill:"currentColor",d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"})],-1)])]))]),e.createElementVNode("h2",$t,e.toDisplayString(o.appName),1),k[1]||(k[1]=e.createElementVNode("p",{class:"welcome-desc"},"今天有什么可以帮您?",-1))])],!0)])):(e.openBlock(),e.createElementBlock("div",St,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.messages,(V,b)=>(e.openBlock(),e.createElementBlock("div",{key:V.id||b,class:e.normalizeClass(["message-row",V.role==="user"?"message-user":"message-assistant"])},[V.role==="user"?(e.openBlock(),e.createElementBlock("div",vt,[e.createVNode(J,{message:V,"is-user":!0},null,8,["message"])])):(e.openBlock(),e.createElementBlock("div",zt,[o.showAgentSteps&&b===o.messages.length-1&&o.agentSteps&&o.agentSteps.length>0?(e.openBlock(),e.createBlock(ne,{key:0,steps:o.agentSteps},null,8,["steps"])):e.createCommentVNode("",!0),e.createElementVNode("div",Lt,[e.createVNode(J,{message:V,"is-user":!1,"is-streaming":o.isStreaming&&b===o.messages.length-1},null,8,["message","is-streaming"])]),V.content&&!(o.isStreaming&&b===o.messages.length-1)?(e.openBlock(),e.createElementBlock("div",Dt,[e.createElementVNode("button",{class:"action-btn",onClick:x=>M(V),title:"复制"},[...k[2]||(k[2]=[e.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"12",height:"12"},[e.createElementVNode("path",{fill:"currentColor",d:"M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c6 6 14.1 9.4 22.6 9.4H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM352 853.3V704h149.3l-149.3 149.3zM224 256h448v640H416V672c0-17.7-14.3-32-32-32H224V256z"})],-1),e.createElementVNode("span",null,"复制",-1)])],8,Tt)])):e.createCommentVNode("",!0)]))],2))),128)),o.isTyping?(e.openBlock(),e.createElementBlock("div",It,[...k[3]||(k[3]=[e.createElementVNode("div",{class:"typing-indicator"},[e.createElementVNode("div",{class:"typing-dot"}),e.createElementVNode("div",{class:"typing-dot",style:{"animation-delay":"0.2s"}}),e.createElementVNode("div",{class:"typing-dot",style:{"animation-delay":"0.4s"}})],-1)])])):e.createCommentVNode("",!0)]))],36)]))}}),[["__scopeId","data-v-bbd7bdf6"]]),At={install(o){o.component("ChatMessageList",ue),o.component("MultimodalMessage",J),o.component("MarkdownMessage",ae),o.component("AgentSteps",ne)}};v.AgentSteps=ne,v.ChatMessageList=ue,v.MarkdownMessage=ae,v.MultimodalMessage=J,v.default=At,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|