@blueking/ai-ui-sdk 0.0.1-beta.4 → 0.0.1-beta.5
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/main.d.ts +6 -2
- package/dist/main.js +4 -4
- package/dist/types/type.d.ts +1 -1
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
@@ -31,7 +31,7 @@ export declare const useAI: ({ handleStart, handleText, handleReferenceDoc, hand
|
|
31
31
|
content: string;
|
32
32
|
rate?: number | undefined;
|
33
33
|
status?: SessionContentStatus | undefined;
|
34
|
-
sessionCode
|
34
|
+
sessionCode: string;
|
35
35
|
}[], ISessionContent[] | {
|
36
36
|
id?: number | undefined;
|
37
37
|
createdAt?: string | undefined;
|
@@ -44,7 +44,7 @@ export declare const useAI: ({ handleStart, handleText, handleReferenceDoc, hand
|
|
44
44
|
content: string;
|
45
45
|
rate?: number | undefined;
|
46
46
|
status?: SessionContentStatus | undefined;
|
47
|
-
sessionCode
|
47
|
+
sessionCode: string;
|
48
48
|
}[]>;
|
49
49
|
sessionContentsMap: SessionContentsMap;
|
50
50
|
sessionLoadingMap: import("vue").Ref<SessionLoadingMap, SessionLoadingMap>;
|
@@ -56,9 +56,13 @@ export declare const useAI: ({ handleStart, handleText, handleReferenceDoc, hand
|
|
56
56
|
headers?: Record<string, string>;
|
57
57
|
}) => void;
|
58
58
|
stopChat: (sessionCode: string) => void;
|
59
|
+
plusSessionContent: (sessionCode: string, sessionContent: ISessionContent) => void;
|
60
|
+
updateSessionContent: (sessionContent: ISessionContent) => void;
|
59
61
|
getSessionContentBySessionCode: (sessionCode: string) => ISessionContent;
|
60
62
|
getSessionContentsBySessionCode: (sessionCode: string) => ISessionContent[];
|
61
63
|
setCurrentSession: (session: ISession) => void;
|
62
64
|
setSessionContents: (data: ISessionContent[]) => void;
|
65
|
+
deleteSessionContent: (sessionCode: string, contentId: number, callback?: (deleteSessionContentIds: number[]) => void) => void | undefined;
|
66
|
+
deleteSessionContents: (sessionCode: string, contentIds: number[], callback?: (deleteSessionContentIds: number[]) => void) => Promise<void | undefined>;
|
63
67
|
};
|
64
68
|
export declare const useStyle: () => void;
|
package/dist/main.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):"object"==typeof exports?exports["ai-ui-sdk"]=t(require("vue")):e["ai-ui-sdk"]=t(e.vue)}("undefined"!=typeof self?self:this,e=>(()=>{"use strict";var t,n,o,i,r,
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):"object"==typeof exports?exports["ai-ui-sdk"]=t(require("vue")):e["ai-ui-sdk"]=t(e.vue)}("undefined"!=typeof self?self:this,e=>(()=>{"use strict";var t,n,o,i,l,r,a,d,s,u,c={380:t=>{t.exports=e}},p={};function h(e){var t=p[e];if(void 0!==t)return t.exports;var n=p[e]={exports:{}};return c[e](n,n.exports,h),n.exports}h.d=(e,t)=>{for(var n in t)h.o(t,n)&&!h.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},h.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),h.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},h.p="/";var f={};h.r(f),h.d(f,{ApiValueType:()=>a,EnumCharacter:()=>d,FileLinkType:()=>l,FileStatus:()=>r,HttpErrorCode:()=>i,KnowledgePathType:()=>s,KnowledgeType:()=>u,SessionContentRole:()=>o,SessionContentStatus:()=>n,SessionPromptRole:()=>t,default:()=>H,transferSessionContent2SessionPrompt:()=>F,useAI:()=>P,useStyle:()=>U});var m={};h.r(m),h.d(m,{Cy:()=>a,hb:()=>d,rs:()=>l,BM:()=>r,eo:()=>i,sh:()=>s,zW:()=>u,In:()=>o,c_:()=>n,bJ:()=>t,DA:()=>F,OD:()=>P,X3:()=>U});var v=h(380);!function(e){e.System="system",e.Assistant="assistant",e.User="user",e.Guide="guide",e.Pause="pause",e.UserImage="user-image",e.Hidden="hidden",e.HiddenUser="hidden-user",e.HiddenAssistant="hidden-assistant",e.HiddenSystem="hidden-system",e.HiddenGuide="hidden-guide",e.TemplateUser="template-user",e.TemplateAssistant="template-assistant",e.TemplateSystem="template-system",e.TemplateGuide="template-guide",e.TemplateHidden="template-hidden"}(t||(t={})),function(e){e.Fail="fail",e.Loading="loading",e.Success="success"}(n||(n={})),function(e){e.Ai="ai",e.User="user",e.Time="time",e.System="system",e.Role="role",e.Hidden="hidden",e.Guide="guide",e.Pause="pause",e.TokenExpired="token-expired",e.UserImage="user-image",e.HiddenUser="hidden-user",e.HiddenAi="hidden-ai",e.HiddenRole="hidden-role",e.HiddenGuide="hidden-guide",e.TemplateUser="template-user",e.TemplateAi="template-ai",e.TemplateRole="template-role",e.TemplateGuide="template-guide",e.TemplateHidden="template-hidden",e.ImageNotSupported="image-not-supported"}(o||(o={})),function(e){e.TokenExpired="80003",e.ImageNotSupported="82003",e.UnAuthorizedPreviewFile="80401",e.TagRepeat="1513405",e[e.Aborted=20]="Aborted",e[e.UnLogin=401]="UnLogin",e.IamNoPermission="IAM_NO_PERMISSION"}(i||(i={})),function(e){e.External="external",e.BkRepo="bk_repo"}(l||(l={})),function(e){e.Init="init",e.Uploading="uploading",e.Uploaded="uploaded",e.Deleting="deleting",e.Deleted="deleted",e.Failed="failed"}(r||(r={})),function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.Array="array",e.Object="object"}(a||(a={})),function(e){e.All="all",e.System="system",e.User="user",e.Public="public",e.Space="space"}(d||(d={})),function(e){e.File="file",e.Folder="folder"}(s||(s={})),function(e){e.File="file",e.Manual="manual",e.Link="link"}(u||(u={}));let g=e=>{let t=`<section class="knowledge-head click-close">
|
2
2
|
<svg
|
3
3
|
class="bkaidev-wenzhang"
|
4
4
|
>
|
@@ -132,13 +132,13 @@
|
|
132
132
|
background: #EAEBF0;
|
133
133
|
}
|
134
134
|
}
|
135
|
-
}`;(e=document.createElement("style")).textContent=t+n,document.head.appendChild(e)},n=()=>{e&&(e.remove(),e=null)};(0,
|
135
|
+
}`;(e=document.createElement("style")).textContent=t+n,document.head.appendChild(e)},n=()=>{e&&(e.remove(),e=null)};(0,v.onBeforeMount)(()=>{t()}),(0,v.onBeforeUnmount)(()=>{n()})},k=e=>{try{return JSON.parse(e),!0}catch(e){return!1}},y=(e,t,n,o)=>{let i="内容正在生成中..."===e||n?"":e;if(i.includes('<section class="think-head click-close">')){let e=i.match(/<section class="think-body">([\s\S]*?)<\/section>/);if(e){let n=e[1],o=n.replace(/\n$/g,`${t}
|
136
136
|
`);i=i.replace(n,o)}}else i+=`<section class="think-head click-close">
|
137
137
|
<i class="bkaidev-icon bkaidev-sikao"></i>思考中...<i class="bkaidev-icon bkaidev-angle-up"></i>
|
138
138
|
</section>
|
139
139
|
<section class="think-body">
|
140
140
|
${t}
|
141
|
-
</section>`;return o&&(i=i.replace("思考中...",`已完成思考 (耗时:${function(e){let t=Math.floor(e/36e5),n=Math.floor(e%36e5/6e4),o=Math.floor(e%6e4/1e3),i=e%1e3,
|
141
|
+
</section>`;return o&&(i=i.replace("思考中...",`已完成思考 (耗时:${function(e){let t=Math.floor(e/36e5),n=Math.floor(e%36e5/6e4),o=Math.floor(e%6e4/1e3),i=e%1e3,l=[];return t>0&&l.push(`${t}h`),n>0&&l.push(`${n}min`),o>0&&l.push(`${o}s`),i>0&&l.push(`${i.toFixed(2)}ms`),l.join(" ")}(o)})`)),i},x=e=>{let t="正在思考..."===e,n=e.match(/<section class="think-body">([\s\S]*?)<\/section>$/),o=n&&""===n[1].trim();return t||o},S=()=>{let e=null,t=()=>{let t=`.think-head {
|
142
142
|
display: flex;
|
143
143
|
align-items: center;
|
144
144
|
padding: 0 8px 0 6px;
|
@@ -186,4 +186,4 @@
|
|
186
186
|
&~ .knowledge-head {
|
187
187
|
margin-bottom: 8px;
|
188
188
|
}
|
189
|
-
}`;(e=document.createElement("style")).textContent=t,document.head.appendChild(e)},n=()=>{e&&(e.remove(),e=null)};(0,
|
189
|
+
}`;(e=document.createElement("style")).textContent=t,document.head.appendChild(e)},n=()=>{e&&(e.remove(),e=null)};(0,v.onBeforeMount)(()=>{t()}),(0,v.onBeforeUnmount)(()=>{n()})};function T(e,t,n,o,i,l,r){try{var a=e[l](r),d=a.value}catch(e){n(e);return}a.done?t(d):Promise.resolve(d).then(o,i)}function w(e){return function(){var t=this,n=arguments;return new Promise(function(o,i){var l=e.apply(t,n);function r(e){T(l,o,i,r,a,"next",e)}function a(e){T(l,o,i,r,a,"throw",e)}r(void 0)})}}function E(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class A{stream({sessionCode:e,url:t,headers:n,data:o}){var i=this;return w(function*(){var l,r;yield null===(l=i.handleStart)||void 0===l?void 0:l.call(i,e);let a=new AbortController;i.controllerMap[e]=a,fetch(t,{method:"post",signal:a.signal,headers:function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},o=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),o.forEach(function(t){E(e,t,n[t])})}return e}({"Content-Type":"application/json"},n),mode:"cors",credentials:"include",body:JSON.stringify(o)}).then((r=w(function*(t){let n=t.body.pipeThrough(new window.TextDecoderStream).getReader(),o="";for(;;)try{let{value:l,done:r}=yield n.read();if(!t.ok){i.handleError(e,l||t.statusText,t.status);break}if(r){i.handleEnd(e);break}(o+l.toString()).split("\n").forEach(n=>{let l=n.replace("data:","").trim();if(k(l)){var r,a;let{event:n,content:d,cover:s,documents:u,result:c,code:p,elapsed_time:h,message:f}=JSON.parse(l);if(!1===c||200!==t.status){i.handleError(e,f||"模型调用失败",p);return}switch(n){case"text":i.handleText(e,d,s);break;case"reference_doc":null===(r=i.handleReferenceDoc)||void 0===r||r.call(i,e,u,s);break;case"think":null===(a=i.handleThink)||void 0===a||a.call(i,e,d,s,h);break;case"done":i.handleEnd(e,s?d:"");break;case"error":i.handleError(e,f||"模型调用失败",p)}o=""}else l&&(o=l)})}catch(t){(null==t?void 0:t.code)!==20&&i.handleError(e,`模型调用失败:${t.message}`,t.code);break}}),function(e){return r.apply(this,arguments)}))})()}stop(e){var t,n;return null===(n=this.controllerMap[e])||void 0===n||null===(t=n.abort)||void 0===t||t.call(n),this.handleEnd(e)}constructor({handleStart:e,handleText:t,handleReferenceDoc:n,handleThink:o,handleEnd:i,handleError:l}){E(this,"handleStart",void 0),E(this,"handleText",void 0),E(this,"handleReferenceDoc",void 0),E(this,"handleThink",void 0),E(this,"handleEnd",void 0),E(this,"handleError",void 0),E(this,"controllerMap",void 0),this.handleStart=e,this.handleText=t,this.handleReferenceDoc=n,this.handleThink=o,this.handleEnd=i,this.handleError=l,this.controllerMap={}}}let F=e=>{let n={[o.Ai]:t.Assistant,[o.User]:t.User,[o.System]:t.System,[o.Hidden]:t.Hidden,[o.Guide]:t.Guide,[o.Time]:t.System,[o.Role]:t.System,[o.HiddenAi]:t.HiddenAssistant,[o.HiddenGuide]:t.HiddenGuide,[o.HiddenRole]:t.HiddenSystem,[o.HiddenUser]:t.HiddenUser,[o.TemplateAi]:t.TemplateAssistant,[o.TemplateGuide]:t.TemplateGuide,[o.TemplateRole]:t.TemplateSystem,[o.TemplateUser]:t.TemplateUser,[o.TemplateHidden]:t.TemplateHidden,[o.Pause]:t.Pause,[o.TokenExpired]:t.Pause,[o.ImageNotSupported]:t.Pause,[o.UserImage]:t.UserImage};return{content:e.content,role:n[e.role]}};function C(e,t,n,o,i,l,r){try{var a=e[l](r),d=a.value}catch(e){n(e);return}a.done?t(d):Promise.resolve(d).then(o,i)}let P=({handleStart:e,handleText:t,handleReferenceDoc:l,handleThink:r,handleEnd:a,handleError:d}={})=>{let s="内容正在生成中...",u=(0,v.ref)(),c=(0,v.ref)({}),p=(0,v.ref)([]),h={},f=(0,v.computed)(()=>{let e=[];for(let t=p.value.length-1;t>=0;t--){let i=p.value[t],l=t+1,r=p.value[l];for(;r&&![o.Ai,o.TokenExpired,o.ImageNotSupported,o.Pause,o.Guide].includes(r.role);)l+=1,r=p.value[l];if(i.role===o.System)break;i.status===n.Fail||(null==r?void 0:r.status)===n.Fail&&[o.User,o.UserImage].includes(i.role)||[o.Time,o.System].includes(i.role)||e.unshift(i)}return e}),m=(0,v.computed)(()=>{var e,t,n;let i=[],l=[],r=[],a=p.value.findLastIndex(e=>e.role===o.System&&["已启用角色","已启用模型"].some(t=>e.content.includes(t))),d=0;null===(n=u.value)||void 0===n||null===(t=n.roleInfo)||void 0===t||null===(e=t.content)||void 0===e||e.forEach(e=>{let t=p.value[a+1+d],n=p.value[a+2+d];if((null==t?void 0:t.content)===e.content&&t.role!==o.System&&(i.push(F(t)),d+=1,(null==t?void 0:t.role)===o.Pause)){for(;n&&n.role===o.System;)d+=1,n=p.value[a+1+d];for(;n&&[o.User,o.UserImage].includes(n.role);)i.push(F(n)),d+=1,n=p.value[a+1+d]}}),l.push(...f.value.map(F));let s=e=>{let t=!0;for(let o=e;o<i.length;o++){var n;i[o].content!==(null===(n=l[o-e])||void 0===n?void 0:n.content)&&(t=!1)}return t};for(let e=0;e<i.length;e++){let t=i[e];if(s(e))break;r.push(t)}return r.push(...l),r}),b=new A({handleStart:function(t){c.value[t]=!0;let i={sessionCode:t,role:o.Ai,status:n.Loading,content:s};return T(t,i),null==e?void 0:e(t,i)},handleText:function(e,o,i){let l=k(e);if(l.content===s)l.content=o;else{if(l.status!==n.Loading)return;l.content=i?o:l.content+o}return null==t?void 0:t(e,l)},handleReferenceDoc:function(e,t,n){let o=k(e),i=g(t);return o.content=n?i:o.content+i,null==l?void 0:l(e,o)},handleThink:function(e,t,n,o){let i=k(e);return i.content=y(i.content,t,n,o),null==r?void 0:r(e,i)},handleEnd:function(e,t){let o=k(e);if(o.status===n.Loading)return c.value[e]=!1,t&&(o.content=t),o.status=n.Success,null==a?void 0:a(e,o);(o.content===s||x(o.content))&&P(e,"聊天内容已中断")},handleError:P});function k(e){var t,n;return(null===(t=u.value)||void 0===t?void 0:t.sessionCode)===e?p.value.at(-1):null===(n=h[e])||void 0===n?void 0:n.at(-1)}function S(e){var t;return(null===(t=u.value)||void 0===t?void 0:t.sessionCode)===e?p.value:h[e]}function T(e,t){S(e).push(t)}function w(e,t,n){var i;let l=(null===(i=u.value)||void 0===i?void 0:i.sessionCode)===e?p.value:h[e],r=[];return t.forEach(e=>{let t=l.findIndex(t=>t.id===e);if(t>-1){let i=l[t-1],a=l[t+1],d=l[t+2];if(l.splice(t,1),r.push(e),[o.Hidden].includes(null==i?void 0:i.role)){let e=l.findIndex(e=>e.id===i.id);l.splice(e,1),r.push(i.id)}if((null==a?void 0:a.role)===o.Ai||n&&[o.Ai,o.Guide,o.TokenExpired,o.ImageNotSupported,o.Pause].includes(null==a?void 0:a.role)){let e=l.findIndex(e=>e.id===a.id);l.splice(e,1),r.push(a.id)}if([o.Guide].includes(null==d?void 0:d.role)&&n){let e=l.findIndex(e=>e.id===d.id);l.splice(e,1),r.push(d.id)}}}),r}function E(){var e;return e=function*(e,t,n){let o=w(e,t,!1);return null==n?void 0:n(o)},(E=function(){var t=this,n=arguments;return new Promise(function(o,i){var l=e.apply(t,n);function r(e){C(l,o,i,r,a,"next",e)}function a(e){C(l,o,i,r,a,"throw",e)}r(void 0)})}).apply(this,arguments)}function P(e,t,l){let r=k(e);return r.status=n.Fail,r.content=t,c.value[e]=!1,l===i.TokenExpired&&(r.content="抱歉,您的剩余 Token 不足,无法返回回答内容,请先清空当前会话(上下文仍会作为历史记录保留))",r.role=o.TokenExpired),l===i.ImageNotSupported&&(r.content="抱歉,当前模型不支持图片内容解析",r.role=o.ImageNotSupported),null==d?void 0:d(e,r,l)}return{currentSession:u,sessionContents:p,sessionContentsMap:h,sessionLoadingMap:c,prompts:m,chat:function({sessionCode:e,data:t,url:n,headers:o}){b.stream({sessionCode:e,url:n,data:t,headers:o})},stopChat:function(e){b.stop(e)},plusSessionContent:T,updateSessionContent:function(e){var t;let n=((null===(t=u.value)||void 0===t?void 0:t.sessionCode)===e.sessionCode?p.value:h[e.sessionCode]).find(t=>+(t.id||0)==+(e.id||0));n&&Object.assign(n,e)},getSessionContentBySessionCode:k,getSessionContentsBySessionCode:S,setCurrentSession:function(e){u.value=e,h[e.sessionCode]||(h[e.sessionCode]=[]),p.value=h[e.sessionCode]},setSessionContents:function(e){u.value&&(h[u.value.sessionCode]=e,p.value=e)},deleteSessionContent:function(e,t,n){let o=w(e,[t],!0);return null==n?void 0:n(o)},deleteSessionContents:function(e,t,n){return E.apply(this,arguments)}}},U=()=>{b(),S()},H=m.default;if("undefined"!=typeof window){let{currentScript:e}=window.document,t=e&&e.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);t&&(h.p=t[1])}return f})());
|
package/dist/types/type.d.ts
CHANGED