@szjy/ai-coms 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +576 -516
- package/dist/index.umd.js +2 -2
- package/dist/packages/api/ai.d.ts +10 -0
- package/dist/packages/common/custom-render/routeLinkRender.d.ts +14 -3
- package/dist/packages/components/AiChat/src/index.vue.d.ts +19 -0
- package/dist/packages/components/AiChat/src/transform/index.d.ts +7 -0
- package/dist/style.css +1 -1
- package/package.json +3 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`)).getReader();console.log("reader from response:",t),s({error:0,reader:t})}else s({error:1,reader:null})}).catch(o=>{s({error:1,reader:null})})}):{error:1,reader:null}}let I=null;function de(){return I||(window.markdownit?I=new window.markdownit({html:!0,linkify:!0,typographer:!0}):console.log("markdownit is not loaded"),I)}const q=(n,r)=>{const a=n.__vccOpts||n;for(const[s,o]of r)a[s]=o;return a},ue=["src","alt"],$=q({__name:"SvgIcon",props:{name:{type:String,required:!0},size:{type:[Number,String],default:16},color:{type:String,default:""},className:{type:String,default:""},basePath:{type:String,default:"/icons/"}},setup(n){const r=n,a=e.computed(()=>{if(r.name.startsWith("http://")||r.name.startsWith("https://")||r.name.startsWith("/"))return r.name;const t=r.name.endsWith(".svg")?r.name:`${r.name}.svg`;return`${r.basePath}${t}`}),s=e.computed(()=>{const t=typeof r.size=="number"?`${r.size}px`:r.size;return{width:t,height:t,display:"inline-flex",justifyContent:"center",alignItems:"center"}}),o=e.computed(()=>{const t={width:"100%",height:"100%"};return r.color&&(t.filter=`drop-shadow(0 0 0 ${r.color})`),t});return(t,c)=>(e.openBlock(),e.createElementBlock("div",{class:"svg-icon-wrapper",style:e.normalizeStyle(s.value)},[e.createElementVNode("img",{src:a.value,alt:n.name,class:e.normalizeClass(["svg-icon",n.className]),style:e.normalizeStyle(o.value)},null,14,ue)],4))}},[["__scopeId","data-v-490b11c1"]]),fe=async n=>{if(navigator.clipboard&&navigator.permissions)await navigator.clipboard.writeText(n);else{const r=document.createElement("textArea");r.value=n,r.style.width=0,r.style.position="fixed",r.style.left="-999px",r.style.top="10px",r.setAttribute("readonly","readonly"),document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r)}},me=["innerHTML"],pe={__name:"Previewer",props:{reader:null,model:"szjy",scrollToBottomFn:null,displayText:"",messagePostRender:{type:Function,default:null}},emits:["failed","completed","updating"],setup(n,{expose:r,emit:a}){const{appContext:s}=e.getCurrentInstance(),{$message:o}=s.config.globalProperties,t=n,c=e.ref(t.displayText||""),y=e.ref(""),g=e.ref(!0),w=e.ref(!1),E=e.ref(!!t.displayText),T=a,z=e.ref(null);let _=null;const V=e.computed(()=>I?I.render(c.value):c.value),B=()=>{t.reader&&t.reader.cancel(),w.value=!0,i.value=!1,f(),E.value=!0,T("completed",c.value),g.value=!1,_&&(cancelAnimationFrame(_),_=null)},j=e.computed(()=>`${V.value}`),m=e.ref(!1),u=()=>{m.value=!0},f=()=>{m.value=!1},i=e.ref(!1),l=async()=>{if(!t.reader)return;const k=new TextDecoder("utf-8");for(g.value=!0;!w.value;)try{if(!t.reader){i.value=!0;break}const{value:d,done:h}=await t.reader.read();if(!t.reader){i.value=!0;break}if(h){i.value=!0;break}const v=A[t.model];if(!v)break;const N=v.call(A,d,k);if(N.done){i.value=!0;break}y.value+=N.content,_===null&&S()}catch(d){i.value=!0,console.log(3333,d),T("failed",d),B();break}finally{f()}},b=async()=>{t.scrollToBottomFn&&t.scrollToBottomFn()},p=(k=()=>{},d=()=>{})=>{if(y.value.length>0){const h=y.value.substring(0,10);c.value+=h,y.value=y.value.substring(10),k()}else d()},S=()=>{if(w.value&&_){cancelAnimationFrame(_),_=null,g.value=!1;return}i.value?p(()=>{_=requestAnimationFrame(S),T("updating",null)},()=>{T("completed",c.value),g.value=!1,E.value=!0,e.nextTick(()=>{if(i.value=!1,t.messagePostRender&&z.value)try{t.messagePostRender(z.value,c.value)}catch(k){console.error("messagePostRender 执行失败:",k)}}),_=null}):(p(),_=requestAnimationFrame(S)),b()};e.watch(()=>t.reader,()=>{t.reader&&l()},{immediate:!0,deep:!0}),e.onUnmounted(()=>{B()}),r({abortReader:B,initializeStart:u,initializeEnd:f}),e.computed(()=>m.value?!0:(!t.reader||!g||c.value,!1));const x=async()=>{try{const k=c.value;await fe(k),o.success("复制成功")}catch(k){console.error("复制失败:",k),o.error("复制失败")}};return(k,d)=>(e.openBlock(),e.createBlock(e.Transition,{name:"fade"},{default:e.withCtx(()=>[j.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"refWrapperContent",ref:z,"text-16":"",class:"w-full h-full overflow-y-auto relative","p-24px":""},[e.createElementVNode("div",{class:"markdown-wrapper",innerHTML:j.value},null,8,me),E.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"ai-copy-btn-wrapper",onClick:x},[e.createVNode($,{name:"/images/svg/copy.svg",color:"#666666"}),d[0]||(d[0]=e.createElementVNode("span",{class:"copy-text"},"复制",-1))])):e.createCommentVNode("",!0)],512)):e.createCommentVNode("",!0)]),_:1}))}},he={class:"panel-header"},ge={class:"header-actions"},ye={class:"header-title"},be={class:"action-icons"},we={class:"body-content"},ke={key:0,class:"welcome-content"},ve={class:"subtitle"},xe={class:"highlight"},Se={class:"quick-questions"},_e=["onClick"],Ne={key:1,class:"message-content user-content"},Ce={class:"panel-footer"},Ee={key:0,src:G,alt:"加载中",class:"loading-icon"},Te={class:"input-box"},Re=["src"],Pe={__name:"ChatPanel",props:{modelValue:{type:Boolean,default:!1},token:{type:String,default:""},identifier:{type:String,default:""},baseUrl:{type:String,default:""},title:{type:String,default:"数智AI助理"},messagePostRender:{type:Function,default:null}},emits:["update:modelValue","submit"],setup(n,{emit:r}){const{appContext:a}=e.getCurrentInstance(),{$message:s}=a.config.globalProperties,o=Y("llmName")||"szjy",t=e.computed(()=>le.find(h=>h.modelName===o)),c=n,y=r,g=e.ref(""),w=e.ref(null),E=e.ref(!1),T=e.ref([]),z=e.ref(["什么是AI助理,能做什么?","当前项目的基本情况?","当前项目的进度情况?","当前项目的参建方有哪些?","数智建管平台有哪些功能?能做什么?"]),_=e.ref([]),V=e.ref(!1),B=e.ref(null),j=()=>{e.nextTick(()=>{if(B.value){const h=B.value,v=h.scrollHeight,N=h.scrollTop,L=h.clientHeight;v-N-L<100?h.scrollTop=v:h.scrollTo({top:v})}})},m=e.ref(!1),u=e.computed(()=>m.value?"/images/ai-stop.png":"/images/ai-send.png"),f=(h,v)=>{console.log("onFailedReader",h,v),V.value=!1;const N=k();N&&N.initializeEnd(),s.error("转换失败,请重试"),m.value=!1,setTimeout(()=>{w.value&&w.value.focus()})},i=(h,v)=>{V.value=!1,m.value=!1,j(),v&&T.value[h]&&(T.value[h].displayText=v),setTimeout(()=>{w.value&&w.value.focus()})},l=h=>{m.value=!0},b=()=>{m.value=!1,y("update:modelValue",!1),E.value=!1,T.value=[]},p=e.ref(!1),S=()=>{p.value=!p.value},x=h=>{g.value=h,d()},k=()=>{for(let h=_.value.length-1;h>=0;h--)if(_.value[h])return _.value[h];return null},d=async()=>{if(console.log("stylizingLoading:",V.value),V.value){const C=k();console.log("lastPreviewer:",C),C&&(console.log("abortReader"),C.abortReader());return}if(!g.value.trim()){console.log("no input, return"),w.value.focus();return}T.value.push({type:"user",content:g.value}),m.value=!0,E.value=!0,y("submit",g.value),j();const h=g.value;g.value="";const v=T.value.length;_.value[v]&&_.value[v].initializeStart(),V.value=!0,T.value.push({type:"ai"});const{error:N,reader:L}=await ce(t.value,{text:h,token:c.token,identifier:c.identifier,baseUrl:c.baseUrl});if(N){console.log(45455,N),f(v,N);return}L&&(T.value[v].reader=L)};return(h,v)=>{const N=e.resolveComponent("el-icon"),L=e.resolveComponent("el-input");return e.openBlock(),e.createBlock(e.Transition,{name:"slide"},{default:e.withCtx(()=>[n.modelValue?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["ai-panel",{"drawer-mode":p.value}])},[e.createElementVNode("div",he,[e.createElementVNode("div",ge,[e.createElementVNode("div",ye,e.toDisplayString(n.title),1),e.createElementVNode("div",be,[e.createVNode(N,{class:"action-icon",onClick:S},{default:e.withCtx(()=>[e.createVNode($,{name:"/images/svg/drawer-layout.svg",color:"#999999"})]),_:1}),e.createVNode(N,{class:"action-icon",onClick:b},{default:e.withCtx(()=>[e.createVNode($,{name:"/images/svg/close.svg",color:"#999999"})]),_:1})])])]),e.createElementVNode("div",we,[E.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"chat-messages",ref_key:"messageContainerRef",ref:B},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(T.value,(C,O)=>(e.openBlock(),e.createElementBlock("div",{key:O,class:e.normalizeClass(["message-item",C.type==="user"?"user-message":"ai-message"])},[C.type==="ai"?(e.openBlock(),e.createBlock(pe,{key:0,ref_for:!0,ref:P=>_.value[O]=P,reader:C.reader,"onUpdate:reader":P=>C.reader=P,model:e.unref(o),displayText:C.displayText,scrollToBottomFn:j,messagePostRender:n.messagePostRender,onFailed:P=>f(O,P),onCompleted:P=>i(O,P),onUpdating:()=>l()},null,8,["reader","onUpdate:reader","model","displayText","messagePostRender","onFailed","onCompleted","onUpdating"])):(e.openBlock(),e.createElementBlock("div",Ne,e.toDisplayString(C.content),1))],2))),128))],512)):(e.openBlock(),e.createElementBlock("div",ke,[v[2]||(v[2]=e.createElementVNode("div",{class:"title"},[e.createElementVNode("img",{src:X,alt:"AI助手",class:"panel-icon"}),e.createElementVNode("h3",{class:"title-text"},"Hi, 您好")],-1)),e.createElementVNode("div",ve,[v[1]||(v[1]=e.createTextVNode(" 我是",-1)),e.createElementVNode("span",xe,e.toDisplayString(n.title),1)]),e.createElementVNode("div",Se,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(z.value,(C,O)=>(e.openBlock(),e.createElementBlock("div",{key:O,class:"question-item",onClick:P=>x(C)},[e.createElementVNode("span",null,e.toDisplayString(C),1),e.createVNode(N,null,{default:e.withCtx(()=>[e.createVNode($,{name:"/images/svg/arrow-right.svg",color:"#999999"})]),_:1})],8,_e))),128))])]))]),e.createElementVNode("div",Ce,[m.value?(e.openBlock(),e.createElementBlock("img",Ee)):e.createCommentVNode("",!0),e.createElementVNode("div",Te,[e.createVNode(L,{modelValue:g.value,"onUpdate:modelValue":v[0]||(v[0]=C=>g.value=C),ref_key:"refInputTextString",ref:w,placeholder:"请输入您的问题",autofocus:"",onKeyup:e.withKeys(d,["enter"])},{append:e.withCtx(()=>[e.createElementVNode("div",{class:"send-icon-box",onClick:d},[e.createElementVNode("img",{src:u.value,alt:"发送",class:"send-icon"},null,8,Re)])]),_:1},8,["modelValue"])])])],2)):e.createCommentVNode("",!0)]),_:1})}}};var F={exports:{}};(function(n,r){(function(a,s){n.exports=s()})(window,function(){return function(a){var s={};function o(t){if(s[t])return s[t].exports;var c=s[t]={i:t,l:!1,exports:{}};return a[t].call(c.exports,c,c.exports,o),c.l=!0,c.exports}return o.m=a,o.c=s,o.d=function(t,c,y){o.o(t,c)||Object.defineProperty(t,c,{enumerable:!0,get:y})},o.r=function(t){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,c){if(1&c&&(t=o(t)),8&c||4&c&&typeof t=="object"&&t&&t.__esModule)return t;var y=Object.create(null);if(o.r(y),Object.defineProperty(y,"default",{enumerable:!0,value:t}),2&c&&typeof t!="string")for(var g in t)o.d(y,g,(function(w){return t[w]}).bind(null,g));return y},o.n=function(t){var c=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(c,"a",c),c},o.o=function(t,c){return Object.prototype.hasOwnProperty.call(t,c)},o.p="",o(o.s=0)}([function(a,s,o){function t(m,u,f,i){f.push(m),i.push([].concat(u[m]||[]))}function c(m,u){if(!m)throw new Error("[getMaxDepsChain] dep 参数不能为空");var f=[],i=[],l=[];for(t(m,u,i,l);i.length;){var b=l.pop();if(b&&b.length){var p=b.shift();if(l.push(b),~i.indexOf(p))throw new Error("[getMaxDepsChain][loop] 存在循环依赖,请检查依赖关系; nextName: "+p+", mainStack: "+i);t(p,u,i,l)}else f.push([].concat(i)),i.pop()}return f.reduce(function(S,x){return x.length>S.length?x:S},[])}function y(m){if(!m)throw new Error("[depsParser] 入参不能为空");var u={};m.forEach(function(i){u[i.name]=i.deps||[]});var f=[];return m.forEach(function(i){var l=c(i.name,u).length-1;i.priority=l,f[l]=(f[l]||[]).concat(i)}),f}o.r(s),o.d(s,"loadScript",function(){return z}),o.d(s,"loadScripts",function(){return _}),o.d(s,"dynamicLoadScripts",function(){return V}),o.d(s,"createScriptsLoadIterator",function(){return B}),o.d(s,"loadScriptsQueue",function(){return j}),o.d(s,"getMaxDepsChain",function(){return c}),o.d(s,"depsParser",function(){return y});var g=function(){return(g=Object.assign||function(m){for(var u,f=1,i=arguments.length;f<i;f++)for(var l in u=arguments[f])Object.prototype.hasOwnProperty.call(u,l)&&(m[l]=u[l]);return m}).apply(this,arguments)},w=function(m,u,f,i){return new(f||(f=Promise))(function(l,b){function p(k){try{x(i.next(k))}catch(d){b(d)}}function S(k){try{x(i.throw(k))}catch(d){b(d)}}function x(k){var d;k.done?l(k.value):(d=k.value,d instanceof f?d:new f(function(h){h(d)})).then(p,S)}x((i=i.apply(m,[])).next())})},E=function(m,u){var f,i,l,b,p={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return b={next:S(0),throw:S(1),return:S(2)},typeof Symbol=="function"&&(b[Symbol.iterator]=function(){return this}),b;function S(x){return function(k){return function(d){if(f)throw new TypeError("Generator is already executing.");for(;p;)try{if(f=1,i&&(l=2&d[0]?i.return:d[0]?i.throw||((l=i.return)&&l.call(i),0):i.next)&&!(l=l.call(i,d[1])).done)return l;switch(i=0,l&&(d=[2&d[0],l.value]),d[0]){case 0:case 1:l=d;break;case 4:return p.label++,{value:d[1],done:!1};case 5:p.label++,i=d[1],d=[0];continue;case 7:d=p.ops.pop(),p.trys.pop();continue;default:if(l=p.trys,!((l=l.length>0&&l[l.length-1])||d[0]!==6&&d[0]!==2)){p=0;continue}if(d[0]===3&&(!l||d[1]>l[0]&&d[1]<l[3])){p.label=d[1];break}if(d[0]===6&&p.label<l[1]){p.label=l[1],l=d;break}if(l&&p.label<l[2]){p.label=l[2],p.ops.push(d);break}l[2]&&p.ops.pop(),p.trys.pop();continue}d=u.call(m,p)}catch(h){d=[6,h],i=0}finally{f=l=0}if(5&d[0])throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}([x,k])}}},T=function(m){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var u,f=m[Symbol.asyncIterator];return f?f.call(m):(m=typeof __values=="function"?__values(m):m[Symbol.iterator](),u={},i("next"),i("throw"),i("return"),u[Symbol.asyncIterator]=function(){return this},u);function i(l){u[l]=m[l]&&function(b){return new Promise(function(p,S){(function(x,k,d,h){Promise.resolve(h).then(function(v){x({value:v,done:d})},k)})(p,S,(b=m[l](b)).done,b.value)})}}};function z(m,u){return u===void 0&&(u=!1),new Promise(function(f,i){var l=u?document.head:document.body,b=document.createElement("script");b.type="text/javascript",b.src=m,b.crossOrigin="anonymous",b.onreadystatechange=f,b.onload=f,b.onerror=i,l.appendChild(b)})}var _=function(m,u){return u===void 0&&(u={}),w(void 0,void 0,void 0,function(){var f,i,l,b,p;return E(this,function(S){switch(S.label){case 0:return f=u.baseUrl,i=f===void 0?"":f,l=u.lastLoadResult,b=u.inHead,p=b!==void 0&&b,[4,Promise.all(m.map(function(x){return w(void 0,void 0,void 0,function(){var k,d,h,v,N,L,C,O;return E(this,function(P){switch(P.label){case 0:return k=x.name,d=x.path,h=x.deps,(C={})[k]=!0,v=C,(O={})[k]=!1,N=O,window[k]?[2,v]:[3,1];case 1:return L=!0,h&&l&&[].concat(h).forEach(function(qe){l[qe]!==!1&&(L=!0)}),L?[4,z(d.indexOf("http")===0||d.indexOf("//:")===0?d:i+d,p).then(function(){return v}).catch(function(){return N})]:[3,3];case 2:return[2,P.sent()];case 3:return[2,N]}})})}))];case 1:return[2,S.sent()]}})})},V=function(m,u){return u===void 0&&(u={}),function(){var f=[].concat(y(m));return{next:function(){if(f.length){var i=f.shift();return _(i,u).then(function(l){return{value:l,done:!1}})}return Promise.resolve({done:!0})}}}},B=function(m,u){var f;return u===void 0&&(u={}),(f={})[Symbol.asyncIterator]=V(m,u),f},j=function(m,u){return u===void 0&&(u={}),w(void 0,void 0,void 0,function(){var f,i,l,b,p,S;return E(this,function(x){switch(x.label){case 0:x.trys.push([0,5,6,11]),f=T(B(m,u)),x.label=1;case 1:return[4,f.next()];case 2:if((i=x.sent()).done)return[3,4];l=i.value,u.lastLoadResult=u.lastLoadResult||{},console.log("current load: ",l),l.forEach(function(k){u.lastLoadResult=g(g({},u.lastLoadResult),k)}),x.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return b=x.sent(),p={error:b},[3,11];case 6:return x.trys.push([6,,9,10]),i&&!i.done&&(S=f.return)?[4,S.call(f)]:[3,8];case 7:x.sent(),x.label=8;case 8:return[3,10];case 9:if(p)throw p.error;return[7];case 10:return[7];case 11:return[2,u.lastLoadResult]}})})}}])})})(F);var Ve=F.exports;const Be={key:0,class:"ai-assistant"},Le={name:"AiChat"},Oe=e.defineComponent({...Le,props:{token:{type:String,default:""},identifier:{type:String,default:""},baseUrl:{type:String,default:""},title:{type:String,default:"数智AI助理"},messagePostRender:{type:Function,default:null}},setup(n){const r=e.ref(!1),a=e.ref(!1),s=()=>{r.value=!r.value},o=()=>{a.value=!0,r.value=!1},t=g=>{console.log("用户输入:",g)},c=[{name:"markdownit",path:"markdown-it.min.js"},{name:"hljs",path:"highlight.11.11.1.min.js"}];let y={};return Ve.loadScriptsQueue(c,{baseUrl:"/scripts/ai/",lastLoadResult:y,inHead:!1}).then(g=>{if(console.log("load ai deps: ",g),window.markdownit){const w=window.markdownit();console.log("markdownit: ",w),de()}}),(g,w)=>a.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Be,[e.createVNode(Pe,{modelValue:r.value,"onUpdate:modelValue":w[0]||(w[0]=E=>r.value=E),onSubmit:t,token:n.token,identifier:n.identifier,baseUrl:n.baseUrl,title:n.title,messagePostRender:n.messagePostRender},null,8,["modelValue","token","identifier","baseUrl","title","messagePostRender"]),e.createElementVNode("div",{class:"ai-icon",onClick:s},[e.createElementVNode("div",{class:"close-icon",onClick:e.withModifiers(o,["stop"])},[...w[1]||(w[1]=[e.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"8",height:"8"},[e.createElementVNode("path",{d:"M512 456.310154L94.247385 38.557538a39.384615 39.384615 0 0 0-55.689847 55.689847L456.310154 512 38.557538 929.752615a39.384615 39.384615 0 0 0 55.689847 55.689847L512 567.689846l417.752615 417.752616c15.163077 15.163077 40.526769 15.163077 55.689847 0s15.163077-40.526769 0-55.689847L567.689846 512l417.752616-417.752615a39.384615 39.384615 0 0 0-55.689847-55.689847L512 456.310154z",fill:"currentColor"})],-1)])]),w[2]||(w[2]=e.createElementVNode("img",{src:K,alt:"AI助手"},null,-1)),w[3]||(w[3]=e.createElementVNode("span",{class:"ai-icon-text"},"AI助手",-1))])]))}}),D=q(Oe,[["__scopeId","data-v-a4639f2d"]]),W=Object.freeze(Object.defineProperty({__proto__:null,SzAiChat:D},Symbol.toStringTag,{value:"Module"})),U=function(n){if(!U.installed){U.installed=!0;for(let r in W){const a=Reflect.get(W,r);n.component(a.name,a)}}},ze=n=>{console.log(`点击了路由链接: ${n}`)},je={color:"#536fec",fontWeight:"bold",textDecoration:"underline",cursor:"pointer",padding:"0 3px"},H=n=>{const r=/#router:([^#]+)#/g,a=[];let s=0,o;for(;(o=r.exec(n))!==null;){o.index>s&&a.push({text:n.substring(s,o.index)});const t=o[1];a.push({text:t,routeName:t}),s=r.lastIndex}return s<n.length&&a.push({text:n.substring(s)}),a},J=(n,r,a={})=>{const{onRouteClick:s=ze,linkStyle:o={}}=a,t=document.createElement("a");t.href="#",t.textContent=n;const c={...je,...o};return Object.assign(t.style,c),t.addEventListener("click",y=>{y.preventDefault(),s(r)}),t},Q=n=>{const r=/#router:([^#]+)#/g,a=[],s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);let o=s.nextNode();for(;o;){const t=o,c=t.textContent||"";if(r.test(c)){r.lastIndex=0;const y=H(c);y.length>0&&a.push({node:t,replacements:y})}o=s.nextNode()}return a},Ie=(n,r,a={})=>{const s=Q(n);s.forEach(({node:o,replacements:t})=>{var y;const c=document.createDocumentFragment();t.forEach(({text:g,routeName:w})=>{if(w){const E=J(g,w,a);c.appendChild(E)}else c.appendChild(document.createTextNode(g))}),(y=o.parentNode)==null||y.replaceChild(c,o)}),a!=null&&a.nodeCallback&&s.forEach(({node:o,replacements:t})=>{var c;(c=a.nodeCallback)==null||c.call(a,o,t)})},$e="0.1.4",Ue="Sz";function Ae({componentPrefix:n=Ue,components:r=[]}={}){const a=[];function s(t,c,y){t.component(n+c)||t.component(n+c,y)}function o(t){a.includes(t)||(a.push(t),r.forEach(c=>{const{name:y,alias:g}=c;s(t,y,c),g&&g.forEach(w=>{s(t,w,c)})}))}return{version:$e,componentPrefix:n,install:o}}const Me={install(n){U(n)}};R.SzAiChat=D,R.create=Ae,R.createRouteLink=J,R.default=Me,R.findRouteTextNodes=Q,R.parseRouteMarkers=H,R.routeLinkRender=Ie,Object.defineProperties(R,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(E,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(E=typeof globalThis<"u"?globalThis:E||self,e(E["szjy-ai-coms"]={},E.Vue))})(this,function(E,e){"use strict";const Z="/images/ai-round.png",G="/images/ai-sqrt.png",ee="/images/bars-loading.svg";function A(n){return n.startsWith("http://")||n.startsWith("https://")?n:`${location.protocol}//${location.host}${n}`}async function te(n,r,s,l=""){const o=A(l),t=new URL(`${o}/v1/chat/completions`),i=new Request(t,{method:"post",headers:{"Content-Type":"application/json",Authorization:"Bearer app-oLZVFFdYyJX2QK3rdOLWsC2u"},body:JSON.stringify({model:"dify",stream:!0,inputs:{token:r},messages:[{role:"system",content:"你是一个专业的AI助手,请用中文回答问题。"},{role:"user",content:n}]})});return fetch(i)}async function ne(n){const r=new URL("http://localhost:11434/api/chat"),s={};Object.keys(s).forEach(o=>{r.searchParams.append(o,s[o])});const l=new Request(r,{mode:"cors",method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:"llama3",stream:!0,messages:[{role:"system",content:"全程使用中文回答问题。"},{role:"user",content:n}]})});return fetch(l)}async function re(n,r){const s=new URL(`${location.origin}/spark/v1/chat/completions`),l={};Object.keys(l).forEach(t=>{s.searchParams.append(t,l[t])});const o=new Request(s,{method:"post",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({model:"generalv4.0Ultra",stream:!0,messages:[{role:"user",content:n}]})});return fetch(o)}async function oe(n,r){const s=new URL(`${location.origin}/siliconflow/v1/chat/completions`),l={};Object.keys(l).forEach(t=>{s.searchParams.append(t,l[t])});const o=new Request(s,{method:"post",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({model:"Qwen/Qwen1.5-110B-Chat",stream:!0,messages:[{role:"user",content:n}]})});return fetch(o)}async function ae(n,r){const s=new URL(`${location.origin}/moonshot/v1/chat/completions`),l={};Object.keys(l).forEach(t=>{s.searchParams.append(t,l[t])});const o=new Request(s,{method:"post",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({model:"moonshot-v1-8k",stream:!0,messages:[{role:"system",content:"你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。"},{role:"user",content:n}]})});return fetch(o)}async function se(n,r){const s=new URL(`${location.origin}/dashscope/compatible-mode/v1/chat/completions`),l={};Object.keys(l).forEach(t=>{s.searchParams.append(t,l[t])});const o=new Request(s,{method:"post",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({model:"qwq-32b-preview",stream:!0,messages:[{role:"system",content:"全程使用中文回答问题"},{role:"user",content:n}]})});return fetch(o)}async function le(n,r,s,l=""){const o=A(l),t=new URL(`${o}/support/${s}/a`),i={};Object.keys(i).forEach(h=>{t.searchParams.append(h,i[h])});const m=new Request(t,{method:"post",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({content:n})});return fetch(m)}const ie=n=>{if(n.startsWith("data:")){const r=n.substring(5).trim();if(r==="[DONE]")return{done:!0};try{return JSON.parse(r)}catch(s){console.error("JSON parsing error:",s)}}return null},U=[{label:"模拟数据模型",modelName:"standard",api:null},{label:"Spark 星火大模型",modelName:"spark",api:re},{label:"Ollama 3 大模型",modelName:"ollama3",api:ne},{label:"SiliconFlow 硅基流动大模型",modelName:"siliconflow",api:oe},{label:"Kimi Moonshot 月之暗面大模型",modelName:"moonshot",api:ae},{label:"通义千问大模型",modelName:"dashscope",api:se},{label:"数智建管大模型",modelName:"szjy",api:le},{label:"Dify (OpenAI 兼容)",modelName:"dify-openai",api:te}],q={standard(n,r){let s="";return n instanceof Uint8Array?s=r.decode(n,{stream:!0}):s=n,{content:s}},spark(n){const r=ie(n);return r.done?{done:!0}:{content:r.choices[0].delta.content||""}},siliconflow(n){return this.spark(n)},moonshot(n){return this.spark(n)},dashscope(n){return this.spark(n)},szjy(n){return this.spark(n)},"dify-openai"(n){return this.spark(n)},ollama3(n){return{content:JSON.parse(n).message.content}}},M=(n,r,s)=>{const l=n.split(s);return l.slice(0,-1).forEach(o=>{o.trim()!==""&&r.enqueue(o)}),l[l.length-1]},ce=n=>{let r="";return new TransformStream({transform(s,l){if(r+=s,r.trim().startsWith("data:"))r=M(r,l,n);else try{JSON.parse(r),r=M(r,l,n)}catch{l.enqueue(s),r=""}},flush(s){r.trim()!==""&&s.enqueue(r)}})};async function de(n,r){const s=n.api;return s?new Promise(l=>{s(r.text,r.token,r.identifier,r.baseUrl).then(o=>{if(o.body){const t=o.body.pipeThrough(new TextDecoderStream).pipeThrough(ce(`
|
|
2
|
+
`)).getReader();console.log("reader from response:",t),l({error:0,reader:t})}else l({error:1,reader:null})}).catch(o=>{l({error:1,reader:null})})}):{error:1,reader:null}}let j=null;function ue(){return j||(window.markdownit?j=new window.markdownit({html:!0,linkify:!0,typographer:!0}):console.log("markdownit is not loaded"),j)}const F=(n,r)=>{const s=n.__vccOpts||n;for(const[l,o]of r)s[l]=o;return s},fe=["src","alt"],I=F({__name:"SvgIcon",props:{name:{type:String,required:!0},size:{type:[Number,String],default:16},color:{type:String,default:""},className:{type:String,default:""},basePath:{type:String,default:"/icons/"}},setup(n){const r=n,s=e.computed(()=>{if(r.name.startsWith("http://")||r.name.startsWith("https://")||r.name.startsWith("/"))return r.name;const t=r.name.endsWith(".svg")?r.name:`${r.name}.svg`;return`${r.basePath}${t}`}),l=e.computed(()=>{const t=typeof r.size=="number"?`${r.size}px`:r.size;return{width:t,height:t,display:"inline-flex",justifyContent:"center",alignItems:"center"}}),o=e.computed(()=>{const t={width:"100%",height:"100%"};return r.color&&(t.filter=`drop-shadow(0 0 0 ${r.color})`),t});return(t,i)=>(e.openBlock(),e.createElementBlock("div",{class:"svg-icon-wrapper",style:e.normalizeStyle(l.value)},[e.createElementVNode("img",{src:s.value,alt:n.name,class:e.normalizeClass(["svg-icon",n.className]),style:e.normalizeStyle(o.value)},null,14,fe)],4))}},[["__scopeId","data-v-490b11c1"]]),me=async n=>{if(navigator.clipboard&&navigator.permissions)await navigator.clipboard.writeText(n);else{const r=document.createElement("textArea");r.value=n,r.style.width=0,r.style.position="fixed",r.style.left="-999px",r.style.top="10px",r.setAttribute("readonly","readonly"),document.body.appendChild(r),r.select(),document.execCommand("copy"),document.body.removeChild(r)}},pe=["innerHTML"],he={__name:"Previewer",props:{reader:null,model:"szjy",scrollToBottomFn:null,displayText:"",messagePostRender:{type:Function,default:null}},emits:["failed","completed","updating"],setup(n,{expose:r,emit:s}){const{appContext:l}=e.getCurrentInstance(),{$message:o}=l.config.globalProperties,t=n,i=e.ref(t.displayText||""),m=e.ref(""),h=e.ref(!0),k=e.ref(!1),N=e.ref(!!t.displayText),B=s,T=e.ref(null);let C=null;const z=e.computed(()=>j?j.render(i.value):i.value),O=()=>{t.reader&&t.reader.cancel(),k.value=!0,d.value=!1,f(),N.value=!0,B("completed",i.value),h.value=!1,C&&(cancelAnimationFrame(C),C=null)},P=e.computed(()=>`${z.value}`),p=e.ref(!1),u=()=>{p.value=!0},f=()=>{p.value=!1},d=e.ref(!1),c=async()=>{if(!t.reader)return;const w=new TextDecoder("utf-8");for(h.value=!0;!k.value;)try{if(!t.reader){d.value=!0;break}const{value:a,done:b}=await t.reader.read();if(!t.reader){d.value=!0;break}if(b){d.value=!0;break}const x=q[t.model];if(!x)break;const R=x.call(q,a,w);if(R.done){d.value=!0;break}m.value+=R.content,C===null&&S()}catch(a){d.value=!0,console.log(3333,a),B("failed",a),O();break}finally{f()}},y=async()=>{t.scrollToBottomFn&&t.scrollToBottomFn()},g=(w=()=>{},a=()=>{})=>{if(m.value.length>0){const b=m.value.substring(0,10);i.value+=b,m.value=m.value.substring(10),w()}else a()},S=()=>{if(k.value&&C){cancelAnimationFrame(C),C=null,h.value=!1;return}d.value?g(()=>{C=requestAnimationFrame(S),B("updating",null)},()=>{B("completed",i.value),h.value=!1,N.value=!0,e.nextTick(()=>{if(d.value=!1,t.messagePostRender&&T.value)try{t.messagePostRender(T.value,i.value)}catch(w){console.error("messagePostRender 执行失败:",w)}}),C=null}):(g(),C=requestAnimationFrame(S)),y()};e.watch(()=>t.reader,()=>{t.reader&&c()},{immediate:!0,deep:!0}),e.onUnmounted(()=>{O()}),r({abortReader:O,initializeStart:u,initializeEnd:f}),e.computed(()=>p.value?!0:(!t.reader||!h||i.value,!1));const v=async()=>{try{const w=i.value;await me(w),o.success("复制成功")}catch(w){console.error("复制失败:",w),o.error("复制失败")}};return(w,a)=>(e.openBlock(),e.createBlock(e.Transition,{name:"fade"},{default:e.withCtx(()=>[P.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"refWrapperContent",ref:T,"text-16":"",class:"w-full h-full overflow-y-auto relative","p-24px":""},[e.createElementVNode("div",{class:"markdown-wrapper",innerHTML:P.value},null,8,pe),N.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"ai-copy-btn-wrapper",onClick:v},[e.createVNode(I,{name:"/images/svg/copy.svg",color:"#666666"}),a[0]||(a[0]=e.createElementVNode("span",{class:"copy-text"},"复制",-1))])):e.createCommentVNode("",!0)],512)):e.createCommentVNode("",!0)]),_:1}))}},ye={class:"panel-header"},ge={class:"header-actions"},be={class:"header-title"},we={class:"action-icons"},ke={class:"body-content"},ve={key:0,class:"welcome-content"},Se={class:"subtitle"},xe={class:"highlight"},Ne={class:"quick-questions"},Ce=["onClick"],_e={key:1,class:"message-content user-content"},Ee={class:"panel-footer"},Te={key:0,src:ee,alt:"加载中",class:"loading-icon"},Re={class:"input-box"},Pe=["src"],Ve={__name:"ChatPanel",props:{modelValue:{type:Boolean,default:!1},token:{type:String,default:""},identifier:{type:String,default:""},baseUrl:{type:String,default:""},title:{type:String,default:"数智AI助理"},llmName:{type:String,default:"szjy"},messagePostRender:{type:Function,default:null}},emits:["update:modelValue","submit"],setup(n,{emit:r}){const{appContext:s}=e.getCurrentInstance(),{$message:l}=s.config.globalProperties,o=n,t=e.computed(()=>U.find(a=>a.modelName===o.llmName)??U.find(a=>a.modelName==="szjy")),i=r,m=e.ref(""),h=e.ref(null),k=e.ref(!1),N=e.ref([]),B=e.ref(["什么是AI助理,能做什么?","当前项目的基本情况?","当前项目的进度情况?","当前项目的参建方有哪些?","数智建管平台有哪些功能?能做什么?"]),T=e.ref([]),C=e.ref(!1),z=e.ref(null),O=()=>{e.nextTick(()=>{if(z.value){const a=z.value,b=a.scrollHeight,x=a.scrollTop,R=a.clientHeight;b-x-R<100?a.scrollTop=b:a.scrollTo({top:b})}})},P=e.ref(!1),p=e.computed(()=>P.value?"/images/ai-stop.png":"/images/ai-send.png"),u=(a,b)=>{console.log("onFailedReader",a,b),C.value=!1;const x=v();x&&x.initializeEnd(),l.error("转换失败,请重试"),P.value=!1,setTimeout(()=>{h.value&&h.value.focus()})},f=(a,b)=>{C.value=!1,P.value=!1,O(),b&&N.value[a]&&(N.value[a].displayText=b),setTimeout(()=>{h.value&&h.value.focus()})},d=a=>{P.value=!0},c=()=>{P.value=!1,i("update:modelValue",!1),k.value=!1,N.value=[]},y=e.ref(!1),g=()=>{y.value=!y.value},S=a=>{m.value=a,w()},v=()=>{for(let a=T.value.length-1;a>=0;a--)if(T.value[a])return T.value[a];return null},w=async()=>{if(console.log("stylizingLoading:",C.value),C.value){const _=v();console.log("lastPreviewer:",_),_&&(console.log("abortReader"),_.abortReader());return}if(!m.value.trim()){console.log("no input, return"),h.value.focus();return}N.value.push({type:"user",content:m.value}),P.value=!0,k.value=!0,i("submit",m.value),O();const a=m.value;m.value="";const b=N.value.length;T.value[b]&&T.value[b].initializeStart(),C.value=!0,N.value.push({type:"ai"});const{error:x,reader:R}=await de(t.value,{text:a,token:o.token,identifier:o.identifier,baseUrl:o.baseUrl});if(x){console.log(45455,x),u(b,x);return}R&&(N.value[b].reader=R)};return(a,b)=>{const x=e.resolveComponent("el-icon"),R=e.resolveComponent("el-input");return e.openBlock(),e.createBlock(e.Transition,{name:"slide"},{default:e.withCtx(()=>[n.modelValue?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["ai-panel",{"drawer-mode":y.value}])},[e.createElementVNode("div",ye,[e.createElementVNode("div",ge,[e.createElementVNode("div",be,e.toDisplayString(n.title),1),e.createElementVNode("div",we,[e.createVNode(x,{class:"action-icon",onClick:g},{default:e.withCtx(()=>[e.createVNode(I,{name:"/images/svg/drawer-layout.svg",color:"#999999"})]),_:1}),e.createVNode(x,{class:"action-icon",onClick:c},{default:e.withCtx(()=>[e.createVNode(I,{name:"/images/svg/close.svg",color:"#999999"})]),_:1})])])]),e.createElementVNode("div",ke,[k.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:"chat-messages",ref_key:"messageContainerRef",ref:z},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,(_,L)=>(e.openBlock(),e.createElementBlock("div",{key:L,class:e.normalizeClass(["message-item",_.type==="user"?"user-message":"ai-message"])},[_.type==="ai"?(e.openBlock(),e.createBlock(he,{key:0,ref_for:!0,ref:V=>T.value[L]=V,reader:_.reader,"onUpdate:reader":V=>_.reader=V,model:o.llmName,displayText:_.displayText,scrollToBottomFn:O,messagePostRender:n.messagePostRender,onFailed:V=>u(L,V),onCompleted:V=>f(L,V),onUpdating:()=>d()},null,8,["reader","onUpdate:reader","model","displayText","messagePostRender","onFailed","onCompleted","onUpdating"])):(e.openBlock(),e.createElementBlock("div",_e,e.toDisplayString(_.content),1))],2))),128))],512)):(e.openBlock(),e.createElementBlock("div",ve,[b[2]||(b[2]=e.createElementVNode("div",{class:"title"},[e.createElementVNode("img",{src:G,alt:"AI助手",class:"panel-icon"}),e.createElementVNode("h3",{class:"title-text"},"Hi, 您好")],-1)),e.createElementVNode("div",Se,[b[1]||(b[1]=e.createTextVNode(" 我是",-1)),e.createElementVNode("span",xe,e.toDisplayString(n.title),1)]),e.createElementVNode("div",Ne,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,(_,L)=>(e.openBlock(),e.createElementBlock("div",{key:L,class:"question-item",onClick:V=>S(_)},[e.createElementVNode("span",null,e.toDisplayString(_),1),e.createVNode(x,null,{default:e.withCtx(()=>[e.createVNode(I,{name:"/images/svg/arrow-right.svg",color:"#999999"})]),_:1})],8,Ce))),128))])]))]),e.createElementVNode("div",Ee,[P.value?(e.openBlock(),e.createElementBlock("img",Te)):e.createCommentVNode("",!0),e.createElementVNode("div",Re,[e.createVNode(R,{modelValue:m.value,"onUpdate:modelValue":b[0]||(b[0]=_=>m.value=_),ref_key:"refInputTextString",ref:h,placeholder:"请输入您的问题",autofocus:"",onKeyup:e.withKeys(w,["enter"])},{append:e.withCtx(()=>[e.createElementVNode("div",{class:"send-icon-box",onClick:w},[e.createElementVNode("img",{src:p.value,alt:"发送",class:"send-icon"},null,8,Pe)])]),_:1},8,["modelValue"])])])],2)):e.createCommentVNode("",!0)]),_:1})}}};var D={exports:{}};(function(n,r){(function(s,l){n.exports=l()})(window,function(){return function(s){var l={};function o(t){if(l[t])return l[t].exports;var i=l[t]={i:t,l:!1,exports:{}};return s[t].call(i.exports,i,i.exports,o),i.l=!0,i.exports}return o.m=s,o.c=l,o.d=function(t,i,m){o.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:m})},o.r=function(t){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,i){if(1&i&&(t=o(t)),8&i||4&i&&typeof t=="object"&&t&&t.__esModule)return t;var m=Object.create(null);if(o.r(m),Object.defineProperty(m,"default",{enumerable:!0,value:t}),2&i&&typeof t!="string")for(var h in t)o.d(m,h,(function(k){return t[k]}).bind(null,h));return m},o.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(i,"a",i),i},o.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},o.p="",o(o.s=0)}([function(s,l,o){function t(p,u,f,d){f.push(p),d.push([].concat(u[p]||[]))}function i(p,u){if(!p)throw new Error("[getMaxDepsChain] dep 参数不能为空");var f=[],d=[],c=[];for(t(p,u,d,c);d.length;){var y=c.pop();if(y&&y.length){var g=y.shift();if(c.push(y),~d.indexOf(g))throw new Error("[getMaxDepsChain][loop] 存在循环依赖,请检查依赖关系; nextName: "+g+", mainStack: "+d);t(g,u,d,c)}else f.push([].concat(d)),d.pop()}return f.reduce(function(S,v){return v.length>S.length?v:S},[])}function m(p){if(!p)throw new Error("[depsParser] 入参不能为空");var u={};p.forEach(function(d){u[d.name]=d.deps||[]});var f=[];return p.forEach(function(d){var c=i(d.name,u).length-1;d.priority=c,f[c]=(f[c]||[]).concat(d)}),f}o.r(l),o.d(l,"loadScript",function(){return T}),o.d(l,"loadScripts",function(){return C}),o.d(l,"dynamicLoadScripts",function(){return z}),o.d(l,"createScriptsLoadIterator",function(){return O}),o.d(l,"loadScriptsQueue",function(){return P}),o.d(l,"getMaxDepsChain",function(){return i}),o.d(l,"depsParser",function(){return m});var h=function(){return(h=Object.assign||function(p){for(var u,f=1,d=arguments.length;f<d;f++)for(var c in u=arguments[f])Object.prototype.hasOwnProperty.call(u,c)&&(p[c]=u[c]);return p}).apply(this,arguments)},k=function(p,u,f,d){return new(f||(f=Promise))(function(c,y){function g(w){try{v(d.next(w))}catch(a){y(a)}}function S(w){try{v(d.throw(w))}catch(a){y(a)}}function v(w){var a;w.done?c(w.value):(a=w.value,a instanceof f?a:new f(function(b){b(a)})).then(g,S)}v((d=d.apply(p,[])).next())})},N=function(p,u){var f,d,c,y,g={label:0,sent:function(){if(1&c[0])throw c[1];return c[1]},trys:[],ops:[]};return y={next:S(0),throw:S(1),return:S(2)},typeof Symbol=="function"&&(y[Symbol.iterator]=function(){return this}),y;function S(v){return function(w){return function(a){if(f)throw new TypeError("Generator is already executing.");for(;g;)try{if(f=1,d&&(c=2&a[0]?d.return:a[0]?d.throw||((c=d.return)&&c.call(d),0):d.next)&&!(c=c.call(d,a[1])).done)return c;switch(d=0,c&&(a=[2&a[0],c.value]),a[0]){case 0:case 1:c=a;break;case 4:return g.label++,{value:a[1],done:!1};case 5:g.label++,d=a[1],a=[0];continue;case 7:a=g.ops.pop(),g.trys.pop();continue;default:if(c=g.trys,!((c=c.length>0&&c[c.length-1])||a[0]!==6&&a[0]!==2)){g=0;continue}if(a[0]===3&&(!c||a[1]>c[0]&&a[1]<c[3])){g.label=a[1];break}if(a[0]===6&&g.label<c[1]){g.label=c[1],c=a;break}if(c&&g.label<c[2]){g.label=c[2],g.ops.push(a);break}c[2]&&g.ops.pop(),g.trys.pop();continue}a=u.call(p,g)}catch(b){a=[6,b],d=0}finally{f=c=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([v,w])}}},B=function(p){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var u,f=p[Symbol.asyncIterator];return f?f.call(p):(p=typeof __values=="function"?__values(p):p[Symbol.iterator](),u={},d("next"),d("throw"),d("return"),u[Symbol.asyncIterator]=function(){return this},u);function d(c){u[c]=p[c]&&function(y){return new Promise(function(g,S){(function(v,w,a,b){Promise.resolve(b).then(function(x){v({value:x,done:a})},w)})(g,S,(y=p[c](y)).done,y.value)})}}};function T(p,u){return u===void 0&&(u=!1),new Promise(function(f,d){var c=u?document.head:document.body,y=document.createElement("script");y.type="text/javascript",y.src=p,y.crossOrigin="anonymous",y.onreadystatechange=f,y.onload=f,y.onerror=d,c.appendChild(y)})}var C=function(p,u){return u===void 0&&(u={}),k(void 0,void 0,void 0,function(){var f,d,c,y,g;return N(this,function(S){switch(S.label){case 0:return f=u.baseUrl,d=f===void 0?"":f,c=u.lastLoadResult,y=u.inHead,g=y!==void 0&&y,[4,Promise.all(p.map(function(v){return k(void 0,void 0,void 0,function(){var w,a,b,x,R,_,L,V;return N(this,function(Y){switch(Y.label){case 0:return w=v.name,a=v.path,b=v.deps,(L={})[w]=!0,x=L,(V={})[w]=!1,R=V,window[w]?[2,x]:[3,1];case 1:return _=!0,b&&c&&[].concat(b).forEach(function(Fe){c[Fe]!==!1&&(_=!0)}),_?[4,T(a.indexOf("http")===0||a.indexOf("//:")===0?a:d+a,g).then(function(){return x}).catch(function(){return R})]:[3,3];case 2:return[2,Y.sent()];case 3:return[2,R]}})})}))];case 1:return[2,S.sent()]}})})},z=function(p,u){return u===void 0&&(u={}),function(){var f=[].concat(m(p));return{next:function(){if(f.length){var d=f.shift();return C(d,u).then(function(c){return{value:c,done:!1}})}return Promise.resolve({done:!0})}}}},O=function(p,u){var f;return u===void 0&&(u={}),(f={})[Symbol.asyncIterator]=z(p,u),f},P=function(p,u){return u===void 0&&(u={}),k(void 0,void 0,void 0,function(){var f,d,c,y,g,S;return N(this,function(v){switch(v.label){case 0:v.trys.push([0,5,6,11]),f=B(O(p,u)),v.label=1;case 1:return[4,f.next()];case 2:if((d=v.sent()).done)return[3,4];c=d.value,u.lastLoadResult=u.lastLoadResult||{},console.log("current load: ",c),c.forEach(function(w){u.lastLoadResult=h(h({},u.lastLoadResult),w)}),v.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return y=v.sent(),g={error:y},[3,11];case 6:return v.trys.push([6,,9,10]),d&&!d.done&&(S=f.return)?[4,S.call(f)]:[3,8];case 7:v.sent(),v.label=8;case 8:return[3,10];case 9:if(g)throw g.error;return[7];case 10:return[7];case 11:return[2,u.lastLoadResult]}})})}}])})})(D);var Be=D.exports;const Oe={key:0,class:"ai-assistant"},Le={name:"AiChat"},ze=e.defineComponent({...Le,props:{token:{type:String,default:""},identifier:{type:String,default:""},baseUrl:{type:String,default:""},title:{type:String,default:"数智AI助理"},llmName:{type:String,default:"szjy"},messagePostRender:{type:Function,default:null}},setup(n){const r=e.ref(!1),s=e.ref(!1),l=()=>{r.value=!r.value},o=()=>{s.value=!0,r.value=!1},t=h=>{console.log("用户输入:",h)},i=[{name:"markdownit",path:"markdown-it.min.js"},{name:"hljs",path:"highlight.11.11.1.min.js"}];let m={};return Be.loadScriptsQueue(i,{baseUrl:"/scripts/ai/",lastLoadResult:m,inHead:!1}).then(h=>{if(console.log("load ai deps: ",h),window.markdownit){const k=window.markdownit();console.log("markdownit: ",k),ue()}}),(h,k)=>s.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Oe,[e.createVNode(Ve,{modelValue:r.value,"onUpdate:modelValue":k[0]||(k[0]=N=>r.value=N),onSubmit:t,token:n.token,identifier:n.identifier,baseUrl:n.baseUrl,title:n.title,llmName:n.llmName,messagePostRender:n.messagePostRender},null,8,["modelValue","token","identifier","baseUrl","title","llmName","messagePostRender"]),e.createElementVNode("div",{class:"ai-icon",onClick:l},[e.createElementVNode("div",{class:"close-icon",onClick:e.withModifiers(o,["stop"])},[...k[1]||(k[1]=[e.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"8",height:"8"},[e.createElementVNode("path",{d:"M512 456.310154L94.247385 38.557538a39.384615 39.384615 0 0 0-55.689847 55.689847L456.310154 512 38.557538 929.752615a39.384615 39.384615 0 0 0 55.689847 55.689847L512 567.689846l417.752615 417.752616c15.163077 15.163077 40.526769 15.163077 55.689847 0s15.163077-40.526769 0-55.689847L567.689846 512l417.752616-417.752615a39.384615 39.384615 0 0 0-55.689847-55.689847L512 456.310154z",fill:"currentColor"})],-1)])]),k[2]||(k[2]=e.createElementVNode("img",{src:Z,alt:"AI助手"},null,-1)),k[3]||(k[3]=e.createElementVNode("span",{class:"ai-icon-text"},"AI助手",-1))])]))}}),W=F(ze,[["__scopeId","data-v-9d212a48"]]),J=Object.freeze(Object.defineProperty({__proto__:null,SzAiChat:W},Symbol.toStringTag,{value:"Module"})),$=function(n){if(!$.installed){$.installed=!0;for(let r in J){const s=Reflect.get(J,r);n.component(s.name,s)}}},je=(n,r)=>{const s=r?`?${new URLSearchParams(r).toString()}`:"";console.log(`点击了路由链接: ${n}${s}`)},H=n=>{const r=n.indexOf("?");if(r===-1)return{routeName:n};const s=n.substring(0,r),l=n.substring(r+1),o={};return new URLSearchParams(l).forEach((i,m)=>{o[m]=i}),{routeName:s,queryParams:Object.keys(o).length>0?o:void 0}},Ie={color:"#536fec",fontWeight:"bold",textDecoration:"underline",cursor:"pointer",padding:"0 3px"},Q=n=>{const r=/#router:([^#]+)#/g,s=[];let l=0,o;for(;(o=r.exec(n))!==null;){o.index>l&&s.push({text:n.substring(l,o.index)});const t=o[1],{routeName:i,queryParams:m}=H(t);s.push({text:i,routeName:i,queryParams:m}),l=r.lastIndex}return l<n.length&&s.push({text:n.substring(l)}),s},K=(n,r,s={},l)=>{const{onRouteClick:o=je,linkStyle:t={}}=s,i=document.createElement("a");i.href="#",i.textContent=n;const m={...Ie,...t};return Object.assign(i.style,m),i.addEventListener("click",h=>{h.preventDefault(),o(r,l)}),i},X=n=>{const r=/#router:([^#]+)#/g,s=[],l=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);let o=l.nextNode();for(;o;){const t=o,i=t.textContent||"";if(r.test(i)){r.lastIndex=0;const m=Q(i);m.length>0&&s.push({node:t,replacements:m})}o=l.nextNode()}return s},$e=(n,r,s={})=>{const l=X(n);l.forEach(({node:o,replacements:t})=>{var m;const i=document.createDocumentFragment();t.forEach(({text:h,routeName:k,queryParams:N})=>{if(k){const B=K(h,k,s,N);i.appendChild(B)}else i.appendChild(document.createTextNode(h))}),(m=o.parentNode)==null||m.replaceChild(i,o)}),s!=null&&s.nodeCallback&&l.forEach(({node:o,replacements:t})=>{var i;(i=s.nodeCallback)==null||i.call(s,o,t)})},Ae="0.1.6",Ue="Sz";function qe({componentPrefix:n=Ue,components:r=[]}={}){const s=[];function l(t,i,m){t.component(n+i)||t.component(n+i,m)}function o(t){s.includes(t)||(s.push(t),r.forEach(i=>{const{name:m,alias:h}=i;l(t,m,i),h&&h.forEach(k=>{l(t,k,i)})}))}return{version:Ae,componentPrefix:n,install:o}}const Me={install(n){$(n)}};E.SzAiChat=W,E.create=qe,E.createRouteLink=K,E.default=Me,E.findRouteTextNodes=X,E.parseRouteMarkerContent=H,E.parseRouteMarkers=Q,E.routeLinkRender=$e,Object.defineProperties(E,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Stream 调用大模型接口 Dify(兼容 OpenAI 格式)(Fetch 调用)
|
|
3
|
+
* 请求格式:
|
|
4
|
+
* {
|
|
5
|
+
* "model": "dify",
|
|
6
|
+
* "inputs": { "token": "<项目token>" },
|
|
7
|
+
* "messages": [ { role, content }, ... ]
|
|
8
|
+
* }
|
|
9
|
+
*/
|
|
10
|
+
export declare function createDifyOpenAIStylized(text: any, token: any, identifier: any, baseUrl?: string): Promise<Response>;
|
|
1
11
|
/**
|
|
2
12
|
* Event Stream 调用大模型接口 Ollama3 (Fetch 调用)
|
|
3
13
|
*/
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* 将 #router:xxx# 格式的文本替换为可点击的路由链接
|
|
4
4
|
*/
|
|
5
5
|
export interface RouteLinkOptions {
|
|
6
|
-
/**
|
|
7
|
-
onRouteClick?: (routeName: string) => void;
|
|
6
|
+
/** 路由跳转处理函数,接收路由名称和查询参数作为参数 */
|
|
7
|
+
onRouteClick?: (routeName: string, queryParams?: Record<string, string>) => void;
|
|
8
8
|
/** 节点遍历回调函数,接收节点和替换数组作为参数 */
|
|
9
9
|
nodeCallback?: (node: Node, replacements: RouteReplacement[]) => void;
|
|
10
10
|
/** 链接样式配置 */
|
|
@@ -13,7 +13,18 @@ export interface RouteLinkOptions {
|
|
|
13
13
|
export interface RouteReplacement {
|
|
14
14
|
text: string;
|
|
15
15
|
routeName?: string;
|
|
16
|
+
/** 路由链接中的查询参数,如 #router:personal?a=xx&b=yy# 中的 { a: 'xx', b: 'yy' } */
|
|
17
|
+
queryParams?: Record<string, string>;
|
|
16
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* 解析路由标记内容,分离路由名称和查询参数
|
|
21
|
+
* @param markerContent - #router:xxx# 中 xxx 部分的内容,如 "personal?a=xx&b=yy"
|
|
22
|
+
* @returns 路由名称和查询参数
|
|
23
|
+
*/
|
|
24
|
+
export declare const parseRouteMarkerContent: (markerContent: string) => {
|
|
25
|
+
routeName: string;
|
|
26
|
+
queryParams?: Record<string, string>;
|
|
27
|
+
};
|
|
17
28
|
/**
|
|
18
29
|
* 解析文本中的路由标记,返回替换数组
|
|
19
30
|
* @param text - 要解析的文本
|
|
@@ -27,7 +38,7 @@ export declare const parseRouteMarkers: (text: string) => RouteReplacement[];
|
|
|
27
38
|
* @param options - 配置选项
|
|
28
39
|
* @returns 链接元素
|
|
29
40
|
*/
|
|
30
|
-
export declare const createRouteLink: (text: string, routeName: string, options?: RouteLinkOptions) => HTMLAnchorElement;
|
|
41
|
+
export declare const createRouteLink: (text: string, routeName: string, options?: RouteLinkOptions, queryParams?: Record<string, string>) => HTMLAnchorElement;
|
|
31
42
|
/**
|
|
32
43
|
* 查找容器中包含路由标记的文本节点
|
|
33
44
|
* @param container - 容器元素
|
|
@@ -15,6 +15,15 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
15
15
|
type: StringConstructor;
|
|
16
16
|
default: string;
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* 大模型名称,对应 LLMTypes 中的 modelName
|
|
20
|
+
* 例如: 'szjy' | 'spark' | 'dify-openai' | 'siliconflow' 等
|
|
21
|
+
* 默认使用 'szjy'
|
|
22
|
+
*/
|
|
23
|
+
llmName: {
|
|
24
|
+
type: StringConstructor;
|
|
25
|
+
default: string;
|
|
26
|
+
};
|
|
18
27
|
/**
|
|
19
28
|
* 消息后处理回调函数
|
|
20
29
|
* 在 AI 消息渲染完成后调用,可用于自定义处理渲染后的内容
|
|
@@ -42,6 +51,15 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
42
51
|
type: StringConstructor;
|
|
43
52
|
default: string;
|
|
44
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* 大模型名称,对应 LLMTypes 中的 modelName
|
|
56
|
+
* 例如: 'szjy' | 'spark' | 'dify-openai' | 'siliconflow' 等
|
|
57
|
+
* 默认使用 'szjy'
|
|
58
|
+
*/
|
|
59
|
+
llmName: {
|
|
60
|
+
type: StringConstructor;
|
|
61
|
+
default: string;
|
|
62
|
+
};
|
|
45
63
|
/**
|
|
46
64
|
* 消息后处理回调函数
|
|
47
65
|
* 在 AI 消息渲染完成后调用,可用于自定义处理渲染后的内容
|
|
@@ -57,6 +75,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
57
75
|
identifier: string;
|
|
58
76
|
baseUrl: string;
|
|
59
77
|
title: string;
|
|
78
|
+
llmName: string;
|
|
60
79
|
messagePostRender: Function;
|
|
61
80
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
62
81
|
export default _default;
|
|
@@ -59,6 +59,13 @@ export declare const transformStreamValue: {
|
|
|
59
59
|
content: any;
|
|
60
60
|
done?: undefined;
|
|
61
61
|
};
|
|
62
|
+
'dify-openai'(readValue: any): {
|
|
63
|
+
done: boolean;
|
|
64
|
+
content?: undefined;
|
|
65
|
+
} | {
|
|
66
|
+
content: any;
|
|
67
|
+
done?: undefined;
|
|
68
|
+
};
|
|
62
69
|
ollama3(readValue: any): {
|
|
63
70
|
content: any;
|
|
64
71
|
};
|
package/dist/style.css
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
Website: https://highlightjs.org/
|
|
7
7
|
License: see project LICENSE
|
|
8
8
|
Touched: 2021
|
|
9
|
-
*/pre code.hljs[data-v-
|
|
9
|
+
*/pre code.hljs[data-v-9d212a48]{display:block;overflow-x:auto;padding:1em}code.hljs[data-v-9d212a48]{padding:3px 5px}.hljs[data-v-9d212a48]{background:#f3f3f3;color:#444}.hljs-comment[data-v-9d212a48]{color:#697070}.hljs-punctuation[data-v-9d212a48],.hljs-tag[data-v-9d212a48]{color:#444a}.hljs-tag .hljs-attr[data-v-9d212a48],.hljs-tag .hljs-name[data-v-9d212a48]{color:#444}.hljs-attribute[data-v-9d212a48],.hljs-doctag[data-v-9d212a48],.hljs-keyword[data-v-9d212a48],.hljs-meta .hljs-keyword[data-v-9d212a48],.hljs-name[data-v-9d212a48],.hljs-selector-tag[data-v-9d212a48]{font-weight:700}.hljs-deletion[data-v-9d212a48],.hljs-number[data-v-9d212a48],.hljs-quote[data-v-9d212a48],.hljs-selector-class[data-v-9d212a48],.hljs-selector-id[data-v-9d212a48],.hljs-string[data-v-9d212a48],.hljs-template-tag[data-v-9d212a48],.hljs-type[data-v-9d212a48]{color:#800}.hljs-section[data-v-9d212a48],.hljs-title[data-v-9d212a48]{color:#800;font-weight:700}.hljs-link[data-v-9d212a48],.hljs-operator[data-v-9d212a48],.hljs-regexp[data-v-9d212a48],.hljs-selector-attr[data-v-9d212a48],.hljs-selector-pseudo[data-v-9d212a48],.hljs-symbol[data-v-9d212a48],.hljs-template-variable[data-v-9d212a48],.hljs-variable[data-v-9d212a48]{color:#ab5656}.hljs-literal[data-v-9d212a48]{color:#695}.hljs-addition[data-v-9d212a48],.hljs-built_in[data-v-9d212a48],.hljs-bullet[data-v-9d212a48],.hljs-code[data-v-9d212a48]{color:#397300}.hljs-meta[data-v-9d212a48]{color:#1f7199}.hljs-meta .hljs-string[data-v-9d212a48]{color:#38a}.hljs-emphasis[data-v-9d212a48]{font-style:italic}.hljs-strong[data-v-9d212a48]{font-weight:700}.ai-assistant{box-sizing:border-box;position:fixed;right:20px;bottom:40px;z-index:1000;display:flex;align-items:flex-end}.ai-assistant div{box-sizing:border-box}.ai-assistant .ai-icon{box-sizing:border-box;display:flex;flex-direction:column;align-items:center;cursor:pointer;width:44px;padding:6px;transition:all .3s;height:114px;background-color:#fff;box-shadow:0 4px 16px 4px #00000008,0 2px 8px #0000000d,0 0 4px -2px #00000014;border-radius:22px;border:1px solid transparent;background-image:linear-gradient(#fff,#fff),linear-gradient(180deg,#60fffc,#0a84ff);background-origin:border-box;background-clip:padding-box,border-box}.ai-assistant .ai-icon:hover{transform:translateY(-2px);box-shadow:0 4px 16px #00000026}.ai-assistant .ai-icon img{width:32px;height:32px;margin-bottom:6px}.ai-assistant .ai-icon .ai-icon-text{display:inline-block;width:20px;font-size:16px;line-height:18px;font-weight:700;color:#333}.ai-assistant .ai-icon:hover .close-icon{display:flex}.ai-assistant .ai-icon .close-icon{display:none;position:absolute;top:-6px;right:-6px;width:16px;height:16px;background:#fff;border-radius:50%;align-items:center;justify-content:center;box-shadow:0 2px 4px #0000001a;color:#666;cursor:pointer;z-index:1}.ai-assistant .ai-icon .close-icon:hover{color:#333;background:#f5f5f5}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@szjy/ai-coms",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "vue3 ai component",
|
|
5
5
|
"main": "dist/index.umd.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"less": "^4.2.0",
|
|
30
30
|
"sass": "^1.79.3",
|
|
31
31
|
"typescript": "^5.2.2",
|
|
32
|
+
"unplugin-icons": "^22.1.0",
|
|
33
|
+
"@iconify-json/mdi": "^1.2.3",
|
|
32
34
|
"unplugin-vue-components": "^0.26.0",
|
|
33
35
|
"vite": "^5.1.6",
|
|
34
36
|
"vite-plugin-dts": "^3.7.3",
|