@blueking/ai-ui-sdk 0.0.9 → 0.0.11

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.
Files changed (2) hide show
  1. package/dist/main.js +3 -3
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -189,13 +189,13 @@ url(${D}) format("embedded-opentype");
189
189
  }
190
190
  }
191
191
  }
192
- }`;(A=document.createElement("style")).textContent=e+i,document.head.appendChild(A)},i=()=>{A&&(A.remove(),A=null)};(0,T.onBeforeMount)(()=>{e()}),(0,T.onBeforeUnmount)(()=>{i()})},k=(A,e,i,t)=>{let n="内容正在生成中..."===A||i?"":A;if(n.includes('<section class="think-head click-close">')){let A=n.match(/<section class="think-body">([\s\S]*?)<\/section>/);if(A){let i=A[1],t=i.replace(/\n$/g,`${e}
192
+ }`;(A=document.createElement("style")).textContent=e+i,document.head.appendChild(A)},i=()=>{A&&(A.remove(),A=null)};(0,T.onBeforeMount)(()=>{e()}),(0,T.onBeforeUnmount)(()=>{i()})},m=(A,e,i,t)=>{let n="内容正在生成中..."===A||i?"":A;if(n.includes('<section class="think-head click-close">')){let A=n.match(/<section class="think-body">([\s\S]*?)<\/section>/);if(A){let i=A[1],t=i.replace(/\n$/g,`${e}
193
193
  `);n=n.replace(i,t)}}else n+=`<section class="think-head click-close">
194
194
  <i class="ai-ui-sdk-icon ai-ui-sdk-sikao"></i>思考中...<i class="ai-ui-sdk-icon ai-ui-sdk-angle-up"></i>
195
195
  </section>
196
196
  <section class="think-body">
197
197
  ${e}
198
- </section>`;return t&&(n=n.replace("思考中...",`已完成思考 (耗时:${function(A){let e=Math.floor(A/36e5),i=Math.floor(A%36e5/6e4),t=Math.floor(A%6e4/1e3),n=A%1e3,o=[];return e>0&&o.push(`${e}h`),i>0&&o.push(`${i}min`),t>0&&o.push(`${t}s`),n>0&&o.push(`${n.toFixed(2)}ms`),o.join(" ")}(t)})`)),n},m=A=>{let e=A.replace(/<section class="think-head click-close">[\s\S]*<\/section>/,"").replace(/<section class="think-body">[\s\S]*<\/section>/,"");if(""===e.trim()){let i=A.match(/<section class="think-body">([\s\S]*?)<\/section>/);i&&([,e]=i)}return e},x=A=>{let e="正在思考..."===A,i=A.match(/<section class="think-body">([\s\S]*?)<\/section>$/),t=i&&""===i[1].trim();return e||t},v=()=>{let A=null,e=()=>{let e=`.think-head {
198
+ </section>`;return t&&(n=n.replace("思考中...",`已完成思考 (耗时:${function(A){let e=Math.floor(A/36e5),i=Math.floor(A%36e5/6e4),t=Math.floor(A%6e4/1e3),n=A%1e3,o=[];return e>0&&o.push(`${e}h`),i>0&&o.push(`${i}min`),t>0&&o.push(`${t}s`),n>0&&o.push(`${n.toFixed(2)}ms`),o.join(" ")}(t)})`)),n},k=A=>{let e=A.replace(/<section class="think-head click-close">[\s\S]*<\/section>/,"").replace(/<section class="think-body">[\s\S]*<\/section>/,"");if(""===e.trim()){let i=A.match(/<section class="think-body">([\s\S]*?)<\/section>/);i&&([,e]=i)}return e},x=A=>{let e="正在思考..."===A,i=A.match(/<section class="think-body">([\s\S]*?)<\/section>$/),t=i&&""===i[1].trim();return e||t},v=()=>{let A=null,e=()=>{let e=`.think-head {
199
199
  display: flex;
200
200
  align-items: center;
201
201
  padding: 0 8px 0 6px;
@@ -243,6 +243,6 @@ url(${D}) format("embedded-opentype");
243
243
  &~ .knowledge-head {
244
244
  margin-bottom: 8px;
245
245
  }
246
- }`;(A=document.createElement("style")).textContent=e,document.head.appendChild(A)},i=()=>{A&&(A.remove(),A=null)};(0,T.onBeforeMount)(()=>{e()}),(0,T.onBeforeUnmount)(()=>{i()})};function L(A,e,i,t,n,o,g){try{var l=A[o](g),a=l.value}catch(A){i(A);return}l.done?e(a):Promise.resolve(a).then(t,n)}function Y(A){return function(){var e=this,i=arguments;return new Promise(function(t,n){var o=A.apply(e,i);function g(A){L(o,t,n,g,l,"next",A)}function l(A){L(o,t,n,g,l,"throw",A)}g(void 0)})}}function O(A,e,i){return e in A?Object.defineProperty(A,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):A[e]=i,A}class f{stream({sessionCode:A,url:e,headers:i,data:t}){var n=this;return Y(function*(){var o,g;yield null===(o=n.handleStart)||void 0===o?void 0:o.call(n,A);let l=new AbortController;n.controllerMap[A]=l,fetch(e,{method:"post",signal:l.signal,headers:function(A){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{},t=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(i).filter(function(A){return Object.getOwnPropertyDescriptor(i,A).enumerable}))),t.forEach(function(e){O(A,e,i[e])})}return A}({"Content-Type":"application/json"},i),mode:"cors",credentials:"include",body:JSON.stringify(t)}).then((g=Y(function*(e){let i=e.body.pipeThrough(new window.TextDecoderStream).getReader(),t="";for(;;)try{let{value:o,done:g}=yield i.read();if(!e.ok){n.handleError(A,o||e.statusText,e.status);break}if(g){n.handleEnd(A);break}(t+o.toString()).split("\n").forEach(i=>{let o=i.replace("data:","").trim();if(C(o)){var g,l;let{event:i,content:a,cover:M,documents:s,result:c,code:u,elapsed_time:r,message:N}=JSON.parse(o);if(!1===c||200!==e.status){n.handleError(A,N||"模型调用失败",u);return}switch(i){case"text":n.handleText(A,a,M);break;case"reference_doc":null===(g=n.handleReferenceDoc)||void 0===g||g.call(n,A,s,M);break;case"think":null===(l=n.handleThink)||void 0===l||l.call(n,A,a,M,r);break;case"done":n.handleEnd(A,M?a:"");break;case"error":n.handleError(A,N||"模型调用失败",u)}t=""}else o&&(t=o)})}catch(e){(null==e?void 0:e.code)!==20&&n.handleError(A,`模型调用失败:${e.message}`,e.code);break}}),function(A){return g.apply(this,arguments)}))})()}stop(A){var e,i;return null===(i=this.controllerMap[A])||void 0===i||null===(e=i.abort)||void 0===e||e.call(i),this.handleEnd(A)}constructor({handleStart:A,handleText:e,handleReferenceDoc:i,handleThink:t,handleEnd:n,handleError:o}){O(this,"handleStart",void 0),O(this,"handleText",void 0),O(this,"handleReferenceDoc",void 0),O(this,"handleThink",void 0),O(this,"handleEnd",void 0),O(this,"handleError",void 0),O(this,"controllerMap",void 0),this.handleStart=A,this.handleText=e,this.handleReferenceDoc=i,this.handleThink=t,this.handleEnd=n,this.handleError=o,this.controllerMap={}}}let b=({handleStart:A,handleText:e,handleReferenceDoc:i,handleThink:t,handleEnd:n,handleError:o,requestOptions:g}={})=>{let l="内容正在生成中...",a=(0,T.ref)(),M=(0,T.ref)({}),s=(0,T.ref)([]),N={},d=(0,T.computed)(()=>{let A=[];for(let e=s.value.length-1;e>=0;e--){let i=s.value[e],t=e+1,n=s.value[t];for(;n&&![u.Ai,u.TokenExpired,u.ImageNotSupported,u.Pause,u.Guide].includes(n.role);)t+=1,n=s.value[t];if(i.role===u.System)break;i.status===c.Fail||(null==n?void 0:n.status)===c.Fail&&[u.User,u.UserImage].includes(i.role)||[u.Time,u.System].includes(i.role)||A.unshift(i)}return A}),I=(0,T.computed)(()=>{var A;let e=null===(A=a.value)||void 0===A?void 0:A.sessionCode;return!!e&&M.value[e]}),D=(0,T.computed)(()=>{var A,e,i;let t=[],n=[],o=[],g=s.value.findLastIndex(A=>A.role===u.System&&["已启用角色","已启用模型"].some(e=>A.content.includes(e))),l=0;null===(i=a.value)||void 0===i||null===(e=i.roleInfo)||void 0===e||null===(A=e.content)||void 0===A||A.forEach(A=>{let e=s.value[g+1+l],i=s.value[g+2+l];if((null==e?void 0:e.content)===A.content&&e.role!==u.System&&(t.push(j(e)),l+=1,(null==e?void 0:e.role)===u.Pause)){for(;i&&i.role===u.System;)l+=1,i=s.value[g+1+l];for(;i&&[u.User,u.UserImage].includes(i.role);)t.push(j(i)),l+=1,i=s.value[g+1+l]}}),n.push(...d.value.map(j));let M=A=>{let e=!0;for(let o=A;o<t.length;o++){var i;t[o].content!==(null===(i=n[o-A])||void 0===i?void 0:i.content)&&(e=!1)}return e};for(let A=0;A<t.length;A++){let e=t[A];if(M(A))break;o.push(e)}return o.push(...n),o.forEach(A=>{A.content=m(A.content),A.content=z(A.content)}),o}),E=new f({handleStart:w,handleText:function(A,i,t){let n=B(A);if(n.content===l)n.content=i;else{if(n.status!==c.Loading)return;n.content=t?i:n.content+i}return null==e?void 0:e(A,n)},handleReferenceDoc:function(A,e,t){let n=B(A),o=h(e);return n.content=t?o:n.content+o,null==i?void 0:i(A,n)},handleThink:function(A,e,i,n){let o=B(A);return o.content=k(o.content,e,i,n),null==t?void 0:t(A,o)},handleEnd:function(A,e){let i=B(A);if(i.status===c.Loading)return M.value[A]=!1,e&&(i.content=e),i.status=c.Success,null==n?void 0:n(A,i);(i.content===l||x(i.content))&&v(A,"聊天内容已中断")},handleError:v});function B(A){var e,i;return(null===(e=a.value)||void 0===e?void 0:e.sessionCode)===A?s.value.at(-1):null===(i=N[A])||void 0===i?void 0:i.at(-1)}function C(A){var e;return(null===(e=a.value)||void 0===e?void 0:e.sessionCode)===A?s.value:N[A]}function Q(A,e){C(A).push(e)}function p(A,e,i){var t;let n=(null===(t=a.value)||void 0===t?void 0:t.sessionCode)===A?s.value:N[A],o=[];return e.forEach(A=>{let e=n.findIndex(e=>e.id===A);if(e>-1){let t=n[e-1],g=n[e+1],l=n[e+2];if(n.splice(e,1),o.push(A),[u.Hidden].includes(null==t?void 0:t.role)){let A=n.findIndex(A=>A.id===t.id);n.splice(A,1),o.push(t.id)}if((null==g?void 0:g.role)===u.Ai||i&&[u.Ai,u.Guide,u.TokenExpired,u.ImageNotSupported,u.Pause].includes(null==g?void 0:g.role)){let A=n.findIndex(A=>A.id===g.id);n.splice(A,1),o.push(g.id)}if([u.Guide].includes(null==l?void 0:l.role)&&i){let A=n.findIndex(A=>A.id===l.id);n.splice(A,1),o.push(l.id)}}}),o}function w(e){M.value[e]=!0;let i={sessionCode:e,role:u.Ai,status:c.Loading,content:l};return Q(e,i),null==A?void 0:A(e,i)}function v(A,e,i){let t=B(A);return t.status=c.Fail,t.content=e,M.value[A]=!1,i===r.TokenExpired&&(t.content="抱歉,您的剩余 Token 不足,无法返回回答内容,请先清空当前会话(上下文仍会作为历史记录保留))",t.role=u.TokenExpired),i===r.ImageNotSupported&&(t.content="抱歉,当前模型不支持图片内容解析",t.role=u.ImageNotSupported),null==o?void 0:o(A,t,i)}function L(A,e){var i,t,n;if(!(null===(i=a.value)||void 0===i?void 0:i.sessionCode)||!(null==g?void 0:g.url)||I.value)return;let{message:o,cite:l,shortcut:M}=A,r="";r=M?y(M.prompt,l):l?`${o}: "${l}"`:o,s.value.push({sessionCode:null===(t=a.value)||void 0===t?void 0:t.sessionCode,content:o,role:u.User,status:c.Success,cite:l}),E.stream({sessionCode:null===(n=a.value)||void 0===n?void 0:n.sessionCode,url:g.url,headers:null==g?void 0:g.headers,data:{inputs:{chat_history:D.value.slice(0,D.value.length-1),input:r}}}),null==e||e()}return{currentSession:a,sessionContents:s,sessionContentsMap:N,sessionLoadingMap:M,prompts:D,currentSessionLoading:I,chat:function({sessionCode:A,data:e,url:i,headers:t}){E.stream({sessionCode:A,url:i,data:e,headers:t||(null==g?void 0:g.headers)})},sendChat:L,stopChat:function(A){E.stop(A)},plusSessionContent:Q,updateSessionContent:function(A){var e;let i=((null===(e=a.value)||void 0===e?void 0:e.sessionCode)===A.sessionCode?s.value:N[A.sessionCode]).find(e=>+(e.id||0)==+(A.id||0));i&&Object.assign(i,A)},getSessionContentById:function(A,e){return C(e).find(e=>e.id===A)},getLastSessionContentBySessionCode:B,getSessionContentsBySessionCode:C,setCurrentSession:function(A){a.value=A,(null==A?void 0:A.sessionCode)&&(N[A.sessionCode]||(N[A.sessionCode]=[]),s.value=N[A.sessionCode])},setSessionContents:function(A){a.value&&(N[a.value.sessionCode]=A,s.value=A)},deleteSessionContent:function(A,e){return p(A,[e],!0)},deleteSessionContents:function(A,e){return p(A,e,!1)},handleStartChat:w,handleErrorChat:v,reGenerateChat:function(A){if(s.value[A].role!==u.Ai)return;let e=s.value[A-1].content,i=s.value[A-1].cite;s.value.splice(A-1,s.value.length-A+1),L({message:e,cite:i})},reSendChat:function(A,{message:e,cite:i},t){s.value[A].role===u.User&&(s.value.splice(A,s.value.length-A),L({message:e,cite:i},t))},deleteChat:function(A){if(s.value[A].role===u.User){s.value.splice(A,2);return}s.value.splice(A-1,2)}}},S=({handleStart:A,handleEnd:e,handleError:i}={})=>{let t="",n=new f({handleStart:()=>(t="",null==A?void 0:A()),handleText:(A,e,i)=>{i||"正在思考..."===t?t=e:t+=e},handleEnd:()=>("无话可说"===t&&(t=""),null==e?void 0:e(t)),handleError:(A,e,t)=>null==i?void 0:i(e,t)});return{summary:({content:A,url:e,headers:i,model:t})=>{let o=m(z(A)),g=[{role:s.User,content:`你是一个总结大师,请帮助我对下面这段话进行总结。要求总结精炼,不超过 15 个字!且末尾没有标点符号!请注意:如果你无法总结,请回复“无话可说”!
246
+ }`;(A=document.createElement("style")).textContent=e,document.head.appendChild(A)},i=()=>{A&&(A.remove(),A=null)};(0,T.onBeforeMount)(()=>{e()}),(0,T.onBeforeUnmount)(()=>{i()})};function L(A,e,i,t,n,o,g){try{var l=A[o](g),a=l.value}catch(A){i(A);return}l.done?e(a):Promise.resolve(a).then(t,n)}function Y(A){return function(){var e=this,i=arguments;return new Promise(function(t,n){var o=A.apply(e,i);function g(A){L(o,t,n,g,l,"next",A)}function l(A){L(o,t,n,g,l,"throw",A)}g(void 0)})}}function O(A,e,i){return e in A?Object.defineProperty(A,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):A[e]=i,A}class f{stream({sessionCode:A,url:e,headers:i,data:t}){var n=this;return Y(function*(){var o,g;yield null===(o=n.handleStart)||void 0===o?void 0:o.call(n,A);let l=new AbortController;n.controllerMap[A]=l,fetch(e,{method:"post",signal:l.signal,headers:function(A){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{},t=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(i).filter(function(A){return Object.getOwnPropertyDescriptor(i,A).enumerable}))),t.forEach(function(e){O(A,e,i[e])})}return A}({"Content-Type":"application/json"},i),mode:"cors",credentials:"include",body:JSON.stringify(t)}).then((g=Y(function*(e){let i=e.body.pipeThrough(new window.TextDecoderStream).getReader(),t="";for(;;)try{let{value:o,done:g}=yield i.read();if(!e.ok){let i=o||e.statusText;try{let A=JSON.parse(i);i=A.message||A.error.message||i}catch(A){console.error(A.message||A)}n.handleError(A,i,e.status);break}if(g){n.handleEnd(A);break}(t+o.toString()).split("\n").forEach(i=>{let o=i.replace("data:","").trim();if(C(o)){var g,l;let{event:i,content:a,cover:M,documents:s,result:c,code:u,elapsed_time:r,message:N}=JSON.parse(o);if(!1===c||200!==e.status){n.handleError(A,N||"模型调用失败",u);return}switch(i){case"text":n.handleText(A,a,M);break;case"reference_doc":null===(g=n.handleReferenceDoc)||void 0===g||g.call(n,A,s,M);break;case"think":null===(l=n.handleThink)||void 0===l||l.call(n,A,a,M,r);break;case"done":n.handleEnd(A,M?a:"");break;case"error":n.handleError(A,N||"模型调用失败",u)}t=""}else o&&(t=o)})}catch(e){(null==e?void 0:e.code)!==20&&n.handleError(A,`模型调用失败:${e.message}`,e.code);break}}),function(A){return g.apply(this,arguments)}))})()}stop(A){var e,i;return null===(i=this.controllerMap[A])||void 0===i||null===(e=i.abort)||void 0===e||e.call(i),this.handleEnd(A)}constructor({handleStart:A,handleText:e,handleReferenceDoc:i,handleThink:t,handleEnd:n,handleError:o}){O(this,"handleStart",void 0),O(this,"handleText",void 0),O(this,"handleReferenceDoc",void 0),O(this,"handleThink",void 0),O(this,"handleEnd",void 0),O(this,"handleError",void 0),O(this,"controllerMap",void 0),this.handleStart=A,this.handleText=e,this.handleReferenceDoc=i,this.handleThink=t,this.handleEnd=n,this.handleError=o,this.controllerMap={}}}let b=({handleStart:A,handleText:e,handleReferenceDoc:i,handleThink:t,handleEnd:n,handleError:o,requestOptions:g}={})=>{let l="内容正在生成中...",a=(0,T.ref)(),M=(0,T.ref)({}),s=(0,T.ref)([]),N={},d=(0,T.computed)(()=>{let A=[];for(let e=s.value.length-1;e>=0;e--){let i=s.value[e],t=e+1,n=s.value[t];for(;n&&![u.Ai,u.TokenExpired,u.ImageNotSupported,u.Pause,u.Guide].includes(n.role);)t+=1,n=s.value[t];if(i.role===u.System)break;i.status===c.Fail||(null==n?void 0:n.status)===c.Fail&&[u.User,u.UserImage].includes(i.role)||[u.Time,u.System].includes(i.role)||A.unshift(i)}return A}),I=(0,T.computed)(()=>{var A;let e=null===(A=a.value)||void 0===A?void 0:A.sessionCode;return!!e&&M.value[e]}),D=(0,T.computed)(()=>{var A,e,i;let t=[],n=[],o=[],g=s.value.findLastIndex(A=>A.role===u.System&&["已启用角色","已启用模型"].some(e=>A.content.includes(e))),l=0;null===(i=a.value)||void 0===i||null===(e=i.roleInfo)||void 0===e||null===(A=e.content)||void 0===A||A.forEach(A=>{let e=s.value[g+1+l],i=s.value[g+2+l];if((null==e?void 0:e.content)===A.content&&e.role!==u.System&&(t.push(j(e)),l+=1,(null==e?void 0:e.role)===u.Pause)){for(;i&&i.role===u.System;)l+=1,i=s.value[g+1+l];for(;i&&[u.User,u.UserImage].includes(i.role);)t.push(j(i)),l+=1,i=s.value[g+1+l]}}),n.push(...d.value.map(j));let M=A=>{let e=!0;for(let o=A;o<t.length;o++){var i;t[o].content!==(null===(i=n[o-A])||void 0===i?void 0:i.content)&&(e=!1)}return e};for(let A=0;A<t.length;A++){let e=t[A];if(M(A))break;o.push(e)}return o.push(...n),o.forEach(A=>{A.content=k(A.content),A.content=z(A.content)}),o}),E=new f({handleStart:w,handleText:function(A,i,t){let n=B(A);if(n.content===l)n.content=i;else{if(n.status!==c.Loading)return;n.content=t?i:n.content+i}return null==e?void 0:e(A,n)},handleReferenceDoc:function(A,e,t){let n=B(A),o=h(e);return n.content=t?o:n.content+o,null==i?void 0:i(A,n)},handleThink:function(A,e,i,n){let o=B(A);return o.content=m(o.content,e,i,n),null==t?void 0:t(A,o)},handleEnd:function(A,e){let i=B(A);if(i.content===l||x(i.content)){v(A,"聊天内容已中断");return}if(i.status===c.Loading)return M.value[A]=!1,e&&(i.content=e),i.status=c.Success,null==n?void 0:n(A,i)},handleError:v});function B(A){var e,i;return(null===(e=a.value)||void 0===e?void 0:e.sessionCode)===A?s.value.at(-1):null===(i=N[A])||void 0===i?void 0:i.at(-1)}function C(A){var e;return(null===(e=a.value)||void 0===e?void 0:e.sessionCode)===A?s.value:N[A]}function Q(A,e){C(A).push(e)}function p(A,e,i){var t;let n=(null===(t=a.value)||void 0===t?void 0:t.sessionCode)===A?s.value:N[A],o=[];return e.forEach(A=>{let e=n.findIndex(e=>e.id===A);if(e>-1){let t=n[e-1],g=n[e+1],l=n[e+2];if(n.splice(e,1),o.push(A),[u.Hidden].includes(null==t?void 0:t.role)){let A=n.findIndex(A=>A.id===t.id);n.splice(A,1),o.push(t.id)}if((null==g?void 0:g.role)===u.Ai||i&&[u.Ai,u.Guide,u.TokenExpired,u.ImageNotSupported,u.Pause].includes(null==g?void 0:g.role)){let A=n.findIndex(A=>A.id===g.id);n.splice(A,1),o.push(g.id)}if([u.Guide].includes(null==l?void 0:l.role)&&i){let A=n.findIndex(A=>A.id===l.id);n.splice(A,1),o.push(l.id)}}}),o}function w(e){M.value[e]=!0;let i={sessionCode:e,role:u.Ai,status:c.Loading,content:l};return Q(e,i),null==A?void 0:A(e,i)}function v(A,e,i){let t=B(A);return t.status=c.Fail,t.content=e,M.value[A]=!1,i===r.TokenExpired&&(t.content="抱歉,您的剩余 Token 不足,无法返回回答内容,请先清空当前会话(上下文仍会作为历史记录保留))",t.role=u.TokenExpired),i===r.ImageNotSupported&&(t.content="抱歉,当前模型不支持图片内容解析",t.role=u.ImageNotSupported),null==o?void 0:o(A,t,i)}function L(A,e){var i,t,n;if(!(null===(i=a.value)||void 0===i?void 0:i.sessionCode)||!(null==g?void 0:g.url)||I.value)return;let{message:o,cite:l,shortcut:M}=A,r="";r=M?y(M.prompt,l):l?`${o}: "${l}"`:o,s.value.push({sessionCode:null===(t=a.value)||void 0===t?void 0:t.sessionCode,content:o,role:u.User,status:c.Success,cite:l}),E.stream({sessionCode:null===(n=a.value)||void 0===n?void 0:n.sessionCode,url:g.url,headers:null==g?void 0:g.headers,data:{inputs:{chat_history:D.value.slice(0,D.value.length-1),input:r}}}),null==e||e()}return{currentSession:a,sessionContents:s,sessionContentsMap:N,sessionLoadingMap:M,prompts:D,currentSessionLoading:I,chat:function({sessionCode:A,data:e,url:i,headers:t}){E.stream({sessionCode:A,url:i,data:e,headers:t||(null==g?void 0:g.headers)})},sendChat:L,stopChat:function(A){E.stop(A)},plusSessionContent:Q,updateSessionContent:function(A){var e;let i=((null===(e=a.value)||void 0===e?void 0:e.sessionCode)===A.sessionCode?s.value:N[A.sessionCode]).find(e=>+(e.id||0)==+(A.id||0));i&&Object.assign(i,A)},getSessionContentById:function(A,e){return C(e).find(e=>e.id===A)},getLastSessionContentBySessionCode:B,getSessionContentsBySessionCode:C,setCurrentSession:function(A){a.value=A,(null==A?void 0:A.sessionCode)&&(N[A.sessionCode]||(N[A.sessionCode]=[]),s.value=N[A.sessionCode])},setSessionContents:function(A){a.value&&(N[a.value.sessionCode]=A,s.value=A)},deleteSessionContent:function(A,e){return p(A,[e],!0)},deleteSessionContents:function(A,e){return p(A,e,!1)},handleStartChat:w,handleErrorChat:v,reGenerateChat:function(A){if(s.value[A].role!==u.Ai)return;let e=s.value[A-1].content,i=s.value[A-1].cite;s.value.splice(A-1,s.value.length-A+1),L({message:e,cite:i})},reSendChat:function(A,{message:e,cite:i},t){s.value[A].role===u.User&&(s.value.splice(A,s.value.length-A),L({message:e,cite:i},t))},deleteChat:function(A){if(s.value[A].role===u.User){s.value.splice(A,2);return}s.value.splice(A-1,2)}}},S=({handleStart:A,handleEnd:e,handleError:i}={})=>{let t="",n=new f({handleStart:()=>(t="",null==A?void 0:A()),handleText:(A,e,i)=>{i||"正在思考..."===t?t=e:t+=e},handleEnd:()=>("无话可说"===t&&(t=""),null==e?void 0:e(t)),handleError:(A,e,t)=>null==i?void 0:i(e,t)});return{summary:({content:A,url:e,headers:i,model:t})=>{let o=k(z(A)),g=[{role:s.User,content:`你是一个总结大师,请帮助我对下面这段话进行总结。要求总结精炼,不超过 15 个字!且末尾没有标点符号!请注意:如果你无法总结,请回复“无话可说”!
247
247
  文字如下:
248
248
  ${o}`}];n.stream({sessionCode:"summary",url:e,data:{prompts:g,model:t},headers:i})}}};I(86),I(84);let U=()=>{w(),v()},G=E.default;if("undefined"!=typeof window){let{currentScript:A}=window.document,e=A&&A.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);e&&(I.p=e[1])}var R=D.eo,F=D.In,Z=D.c_,W=D.bJ,H=D.Ay,P=D.DA,J=D.Y_,X=D.a2,K=D.X3,_=D.S0;export{R as HttpErrorCode,F as SessionContentRole,Z as SessionContentStatus,W as SessionPromptRole,H as default,P as transferSessionContent2SessionPrompt,J as useChat,X as useClickProxy,K as useStyle,_ as useSummary};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/ai-ui-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "蓝鲸AI UI SDK",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",