@blueking/ai-ui-sdk 0.0.1-beta.1 → 0.0.1-beta.3

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.
@@ -0,0 +1,32 @@
1
+ import type { Document } from '../types/type';
2
+ type HandleStart = (sessionCode: string) => any;
3
+ type HandleText = (sessionCode: string, message: string, cover?: boolean) => void;
4
+ type HandleReferenceDoc = (sessionCode: string, documents: Document[], cover?: boolean) => void;
5
+ type HandleThink = (sessionCode: string, content: string, cover?: boolean, elapsed_time?: number) => void;
6
+ type HandleEnd = (sessionCode: string, message?: string) => void;
7
+ type HandleError = (sessionCode: string, message: string, code: string) => any;
8
+ export declare class ChatHelper {
9
+ handleStart: HandleStart;
10
+ handleText: HandleText;
11
+ handleReferenceDoc?: HandleReferenceDoc;
12
+ handleThink?: HandleThink;
13
+ handleEnd: HandleEnd;
14
+ handleError: HandleError;
15
+ controllerMap: Record<string, AbortController>;
16
+ constructor({ handleStart, handleText, handleReferenceDoc, handleThink, handleEnd, handleError, }: {
17
+ handleStart: HandleStart;
18
+ handleText: HandleText;
19
+ handleReferenceDoc?: HandleReferenceDoc;
20
+ handleThink?: HandleThink;
21
+ handleEnd: HandleEnd;
22
+ handleError: HandleError;
23
+ });
24
+ stream({ sessionCode, url, headers, data, }: {
25
+ sessionCode: string;
26
+ url: string;
27
+ headers?: Record<string, string>;
28
+ data?: Record<string, any>;
29
+ }): Promise<void>;
30
+ stop(sessionCode: string): void;
31
+ }
32
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ISessionContent, ISessionPrompt } from '../types/type';
2
+ /**
3
+ * 将 sessionContent 转换为 sessionPrompt
4
+ * @param sessionContent sessionContent
5
+ * @returns sessionPrompt
6
+ */
7
+ export declare const transferSessionContent2SessionPrompt: (sessionContent: ISessionContent) => ISessionPrompt;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 判断是否是 JSON 字符串
3
+ * @param str 字符串
4
+ * @returns 是否是 JSON 字符串
5
+ */
6
+ export declare const isJSON: (str: string) => boolean;
7
+ /**
8
+ * 响应时间格式化
9
+ * @param val 待格式化时间,xxms
10
+ * @returns 格式化后的时间,xx小时xx分钟xx秒
11
+ */
12
+ export declare function durationFormatter(val: number): string;
@@ -0,0 +1,14 @@
1
+ import type { Document } from '../types/type';
2
+ /**
3
+ * 获取引用资料的 HTML 内容
4
+ * @param documents
5
+ * @returns
6
+ */
7
+ export declare const getHtmlContentFromDocuments: (documents: Document[]) => string;
8
+ /**
9
+ * 移除引用资料的 HTML 内容
10
+ * @param content
11
+ * @returns
12
+ */
13
+ export declare const removeReferenceDoc: (content: string) => string;
14
+ export declare const useReferenceDoc: () => void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 获取思考的 HTML 内容
3
+ * @param chatContent 聊天内容
4
+ * @param content 思考内容
5
+ * @param elapsedTime 思考时间
6
+ * @returns 完整的 chatContent
7
+ */
8
+ export declare const getHtmlContentFromThink: (chatContent: string, content: string, cover?: boolean, elapsedTime?: number) => string;
9
+ /**
10
+ * 移除思考的 HTML 内容
11
+ * @param content
12
+ * @returns
13
+ */
14
+ export declare const removeThink: (content: string) => string;
15
+ /**
16
+ * 判断是否是思考中
17
+ * @param content
18
+ * @returns
19
+ */
20
+ export declare const isThinking: (content: string) => boolean | null;
21
+ export declare const useThink: () => void;
package/dist/main.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ import type { ISessionContent, ISession, ISessionPrompt } from './types/type.ts';
2
+ import { SessionContentRole, SessionContentStatus } from './types/enum';
3
+ type SessionContentsMap = {
4
+ [key: string]: ISessionContent[];
5
+ };
6
+ type SessionLoadingMap = {
7
+ [key: string]: boolean;
8
+ };
9
+ export type * from './types/type';
10
+ export type * from './types/enum';
11
+ export interface AICallbacks {
12
+ handleStart?: (sessionCode: string, sessionContent: ISessionContent) => void;
13
+ handleText?: (sessionCode: string, sessionContent: ISessionContent) => void;
14
+ handleReferenceDoc?: (sessionCode: string, sessionContent: ISessionContent) => void;
15
+ handleThink?: (sessionCode: string, sessionContent: ISessionContent) => void;
16
+ handleEnd?: (sessionCode: string, sessionContent: ISessionContent) => void;
17
+ handleError?: (sessionCode: string, sessionContent: ISessionContent, code: string | undefined) => void;
18
+ }
19
+ export declare const useAI: ({ handleStart, handleText, handleReferenceDoc, handleThink, handleEnd, handleError, }: AICallbacks) => {
20
+ currentSession: import("vue").Ref<ISession | undefined, ISession | undefined>;
21
+ sessionContents: import("vue").Ref<{
22
+ id?: number | undefined;
23
+ createdAt?: string | undefined;
24
+ createdBy?: string | undefined;
25
+ updatedAt?: string | undefined;
26
+ updatedBy?: string | undefined;
27
+ spaceId?: string | undefined;
28
+ liked?: boolean | undefined;
29
+ role: SessionContentRole;
30
+ content: string;
31
+ rate?: number | undefined;
32
+ status?: SessionContentStatus | undefined;
33
+ sessionCode?: string | undefined;
34
+ }[], ISessionContent[] | {
35
+ id?: number | undefined;
36
+ createdAt?: string | undefined;
37
+ createdBy?: string | undefined;
38
+ updatedAt?: string | undefined;
39
+ updatedBy?: string | undefined;
40
+ spaceId?: string | undefined;
41
+ liked?: boolean | undefined;
42
+ role: SessionContentRole;
43
+ content: string;
44
+ rate?: number | undefined;
45
+ status?: SessionContentStatus | undefined;
46
+ sessionCode?: string | undefined;
47
+ }[]>;
48
+ sessionContentsMap: SessionContentsMap;
49
+ sessionLoadingMap: import("vue").Ref<SessionLoadingMap, SessionLoadingMap>;
50
+ prompts: import("vue").ComputedRef<ISessionPrompt[]>;
51
+ chat: ({ sessionCode, data, url, headers, }: {
52
+ sessionCode: string;
53
+ data?: Record<string, any>;
54
+ url: string;
55
+ headers?: Record<string, string>;
56
+ }) => void;
57
+ getSessionContentBySessionCode: (sessionCode: string) => ISessionContent;
58
+ getSessionContentsBySessionCode: (sessionCode: string) => ISessionContent[];
59
+ setCurrentSession: (session: ISession) => void;
60
+ setSessionContents: (data: ISessionContent[]) => void;
61
+ };
62
+ export declare const useStyle: () => void;
package/dist/main.js ADDED
@@ -0,0 +1,189 @@
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 m={};h.r(m),h.d(m,{default:()=>P,useAI:()=>U,useStyle:()=>H});var f={};h.r(f),h.d(f,{O:()=>U,X:()=>H});var g=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 v=e=>{let t=`<section class="knowledge-head click-close">
2
+ <svg
3
+ class="bkaidev-wenzhang"
4
+ >
5
+ <use href="#bkaidev-wenzhang"></use>
6
+ </svg>
7
+ 找到 ${e.length} 篇资料参考
8
+ <i class="bkaidev-icon bkaidev-angle-up"></i>
9
+ </section>
10
+ <ul class="knowledge-body">`;return e.forEach(e=>{let{file_path:n,preview_path:o}=e.metadata,i=n.split("/").pop();t+=`<li
11
+ class="knowledge-item"
12
+ title="${i} (${o||n})"
13
+ >
14
+ <i class="bkaidev-icon bkaidev-zhishiku"></i>
15
+ <a href="${o||n}" target="_blank" class="knowledge-link g-flex-truncate">
16
+ ${i}
17
+ </a>
18
+ </li>`}),t+="</ul>"},b=()=>{let e=null,t=()=>{let t=`.knowledge-tips {
19
+ position: relative;
20
+ padding: 6px 8px;
21
+ margin-bottom: 14px;
22
+ line-height: 22px;
23
+ background: #f5f7fa;
24
+ border-radius: 4px;
25
+
26
+ &.closed {
27
+ .bkaidev-angle-up {
28
+ transform: rotate(180deg);
29
+ }
30
+
31
+ .knowledge-summary {
32
+ margin-bottom: 0;
33
+ }
34
+
35
+ .knowledge-link {
36
+ display: none;
37
+ }
38
+ }
39
+
40
+ .bkaidev-angle-up {
41
+ position: absolute;
42
+ top: 4px;
43
+ right: 0px;
44
+ font-size: 22px;
45
+ color: #979ba5;
46
+ cursor: pointer;
47
+ }
48
+
49
+ .bkaidev-help-document {
50
+ margin-right: 4px;
51
+ font-size: 19px;
52
+ color: #3a84ff;
53
+ }
54
+
55
+ .knowledge-summary {
56
+ display: block;
57
+ margin-bottom: 4px;
58
+ color: #313238;
59
+ }
60
+
61
+ .knowledge-link {
62
+ display: block;
63
+ color: #3a84ff;
64
+ text-decoration: none;
65
+ cursor: pointer;
66
+
67
+ .bkaidev-cc-jump-link {
68
+ font-size: 14px;
69
+ }
70
+
71
+ &:last-child {
72
+ margin-bottom: 2px;
73
+ }
74
+ }
75
+ }`,n=`.knowledge-head {
76
+ display: flex;
77
+ align-items: center;
78
+ padding: 0 8px 0 6px;
79
+ margin-bottom: 8px;
80
+ line-height: 28px;
81
+ background: #F0F1F5;
82
+ border-radius: 4px;
83
+ font-size: 12px;
84
+ color: #313238;
85
+ cursor: pointer;
86
+ width: fit-content;
87
+
88
+ .bkaidev-wenzhang {
89
+ width: 14px;
90
+ height: 14px;
91
+ margin-right: 6px;
92
+ }
93
+
94
+ .bkaidev-angle-up {
95
+ font-size: 22px;
96
+ color: #4D4F56;
97
+ margin-left: 4px;
98
+ }
99
+
100
+ &.closed {
101
+ margin-bottom: 16px;
102
+
103
+ .bkaidev-angle-up {
104
+ transform: rotate(180deg);
105
+ }
106
+
107
+ &~ .knowledge-body {
108
+ display: none;
109
+ }
110
+ }
111
+
112
+ &:hover {
113
+ background: #EAEBF0;
114
+ }
115
+ }
116
+ .knowledge-body {
117
+ background: #F5F7FA;
118
+ padding: 16px !important;
119
+ .knowledge-item {
120
+ display: flex;
121
+ align-items: center;
122
+ line-height: 28px;
123
+ a {
124
+ margin-right: 20px;
125
+ }
126
+ .bkaidev-zhishiku {
127
+ color: #D66F6B;
128
+ font-size: 14px;
129
+ margin-right: 6px;
130
+ }
131
+ &:hover {
132
+ background: #EAEBF0;
133
+ }
134
+ }
135
+ }`;(e=document.createElement("style")).textContent=t+n,document.head.appendChild(e)},n=()=>{e&&(e.remove(),e=null)};(0,g.onBeforeMount)(()=>{t()}),(0,g.onBeforeUnmount)(()=>{n()})},k=e=>{try{return JSON.parse(e),!0}catch(e){return!1}},x=(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
+ `);i=i.replace(n,o)}}else i+=`<section class="think-head click-close">
137
+ <i class="bkaidev-icon bkaidev-sikao"></i>思考中...<i class="bkaidev-icon bkaidev-angle-up"></i>
138
+ </section>
139
+ <section class="think-body">
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,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},y=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
+ display: flex;
143
+ align-items: center;
144
+ padding: 0 8px 0 6px;
145
+ margin-bottom: 8px;
146
+ line-height: 28px;
147
+ background: #F0F1F5;
148
+ border-radius: 4px;
149
+ font-size: 12px;
150
+ color: #313238;
151
+ cursor: pointer;
152
+ width: fit-content;
153
+ .bkaidev-sikao {
154
+ font-size: 14px;
155
+ color: #979ba5;
156
+ margin-right: 4px;
157
+ }
158
+
159
+ .bkaidev-angle-up {
160
+ font-size: 22px;
161
+ color: #4D4F56;
162
+ margin-left: 4px;
163
+ }
164
+
165
+ &.closed {
166
+ margin-bottom: 16px;
167
+
168
+ .bkaidev-angle-up {
169
+ transform: rotate(180deg);
170
+ }
171
+
172
+ &~ .think-body {
173
+ display: none;
174
+ }
175
+ }
176
+
177
+ &:hover {
178
+ background: #EAEBF0;
179
+ }
180
+ }
181
+ .think-body {
182
+ background: #F5F7FA;
183
+ color: #979BA5;
184
+ padding: 16px;
185
+ margin-bottom: 16px;
186
+ &~ .knowledge-head {
187
+ margin-bottom: 8px;
188
+ }
189
+ }`;(e=document.createElement("style")).textContent=t,document.head.appendChild(e)},n=()=>{e&&(e.remove(),e=null)};(0,g.onBeforeMount)(()=>{t()}),(0,g.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:m}=JSON.parse(l);if(!1===c||200!==t.status){i.handleError(e,m||"模型调用失败",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,m||"模型调用失败",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]}},U=({handleStart:e,handleText:t,handleReferenceDoc:l,handleThink:r,handleEnd:a,handleError:d})=>{let s="内容正在生成中...",u=(0,g.ref)(),c=(0,g.ref)({}),p=(0,g.ref)([]),h={},m=(0,g.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}),f=(0,g.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(...m.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!function(e,t){S(e).push(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=v(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=x(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||y(o.content))&&T(e,"聊天内容已中断")},handleError:T});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,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:f,chat:function({sessionCode:e,data:t,url:n,headers:o}){b.stream({sessionCode:e,url:n,data:t,headers:o})},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)}}},H=()=>{b(),S()},P=f.default;if("undefined"!=typeof window){let{currentScript:e}=window.document,t=e&&e.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);t&&(h.p=t[1])}return m})());
@@ -0,0 +1,89 @@
1
+ export declare enum SessionPromptRole {
2
+ System = "system",
3
+ Assistant = "assistant",
4
+ User = "user",
5
+ Guide = "guide",
6
+ Pause = "pause",
7
+ UserImage = "user-image",
8
+ Hidden = "hidden",
9
+ HiddenUser = "hidden-user",
10
+ HiddenAssistant = "hidden-assistant",
11
+ HiddenSystem = "hidden-system",
12
+ HiddenGuide = "hidden-guide",
13
+ TemplateUser = "template-user",
14
+ TemplateAssistant = "template-assistant",
15
+ TemplateSystem = "template-system",
16
+ TemplateGuide = "template-guide",
17
+ TemplateHidden = "template-hidden"
18
+ }
19
+ export declare enum SessionContentStatus {
20
+ Fail = "fail",
21
+ Loading = "loading",
22
+ Success = "success"
23
+ }
24
+ export declare enum SessionContentRole {
25
+ Ai = "ai",
26
+ User = "user",
27
+ Time = "time",
28
+ System = "system",
29
+ Role = "role",
30
+ Hidden = "hidden",
31
+ Guide = "guide",
32
+ Pause = "pause",
33
+ TokenExpired = "token-expired",
34
+ UserImage = "user-image",
35
+ HiddenUser = "hidden-user",
36
+ HiddenAi = "hidden-ai",
37
+ HiddenRole = "hidden-role",
38
+ HiddenGuide = "hidden-guide",
39
+ TemplateUser = "template-user",
40
+ TemplateAi = "template-ai",
41
+ TemplateRole = "template-role",
42
+ TemplateGuide = "template-guide",
43
+ TemplateHidden = "template-hidden",
44
+ ImageNotSupported = "image-not-supported"
45
+ }
46
+ export declare enum HttpErrorCode {
47
+ TokenExpired = "80003",
48
+ ImageNotSupported = "82003",
49
+ UnAuthorizedPreviewFile = "80401",
50
+ TagRepeat = "1513405",
51
+ Aborted = 20,
52
+ UnLogin = 401,
53
+ IamNoPermission = "IAM_NO_PERMISSION"
54
+ }
55
+ export declare enum FileLinkType {
56
+ External = "external",
57
+ BkRepo = "bk_repo"
58
+ }
59
+ export declare enum FileStatus {
60
+ Init = "init",
61
+ Uploading = "uploading",
62
+ Uploaded = "uploaded",
63
+ Deleting = "deleting",
64
+ Deleted = "deleted",
65
+ Failed = "failed"
66
+ }
67
+ export declare enum ApiValueType {
68
+ String = "string",
69
+ Number = "number",
70
+ Boolean = "boolean",
71
+ Array = "array",
72
+ Object = "object"
73
+ }
74
+ export declare enum EnumCharacter {
75
+ All = "all",
76
+ System = "system",
77
+ User = "user",
78
+ Public = "public",
79
+ Space = "space"
80
+ }
81
+ export declare enum KnowledgePathType {
82
+ File = "file",
83
+ Folder = "folder"
84
+ }
85
+ export declare enum KnowledgeType {
86
+ File = "file",
87
+ Manual = "manual",
88
+ Link = "link"
89
+ }
@@ -0,0 +1,200 @@
1
+ import { SessionContentRole, SessionPromptRole, SessionContentStatus, FileLinkType, FileStatus, ApiValueType, EnumCharacter, KnowledgePathType, KnowledgeType } from './enum';
2
+ export type Document = {
3
+ metadata: {
4
+ file_path: string;
5
+ path: string;
6
+ preview_path: string;
7
+ };
8
+ };
9
+ export interface IContent {
10
+ role: SessionPromptRole;
11
+ content: string;
12
+ }
13
+ export interface IVariable {
14
+ name: string;
15
+ value: string;
16
+ }
17
+ export interface IToolRule {
18
+ func: string;
19
+ message: string;
20
+ value: string;
21
+ }
22
+ export interface IToolParam {
23
+ name: string;
24
+ required: boolean;
25
+ type: ApiValueType;
26
+ default: string | number | boolean;
27
+ description: string;
28
+ validate: {
29
+ enable: boolean;
30
+ rules: IToolRule[];
31
+ };
32
+ }
33
+ export interface IResourcePermission {
34
+ accessModel?: boolean;
35
+ accessModelStrategy?: boolean;
36
+ viewSpace?: boolean;
37
+ manageSpace?: boolean;
38
+ viewAgent?: boolean;
39
+ createAgent?: boolean;
40
+ manageAgent?: boolean;
41
+ viewPrompt?: boolean;
42
+ createPrompt?: boolean;
43
+ managePrompt?: boolean;
44
+ viewCollection?: boolean;
45
+ createCollection?: boolean;
46
+ manageCollection?: boolean;
47
+ viewTool?: boolean;
48
+ createTool?: boolean;
49
+ manageTool?: boolean;
50
+ viewKnowledgebase?: boolean;
51
+ createKnowledgebase?: boolean;
52
+ manageKnowledgebase?: boolean;
53
+ viewQueryTemplate?: boolean;
54
+ createQueryTemplate?: boolean;
55
+ manageQueryTemplate?: boolean;
56
+ }
57
+ export interface ITool {
58
+ spaceId?: string;
59
+ header: IToolParam[];
60
+ query?: IToolParam[];
61
+ body?: IToolParam[];
62
+ creator: string;
63
+ createTime: string;
64
+ updateTime: string;
65
+ toolCode: string;
66
+ toolName: string;
67
+ icon: string;
68
+ description: string;
69
+ method: string;
70
+ url: string;
71
+ generateType: EnumCharacter;
72
+ id?: number;
73
+ status?: string;
74
+ isSensitive?: boolean;
75
+ permission?: IResourcePermission;
76
+ }
77
+ export interface ILinkFile {
78
+ url: string;
79
+ fileName: string;
80
+ fileSize: number;
81
+ fileType: string;
82
+ linkType: FileLinkType;
83
+ fileNumber?: number;
84
+ id?: string;
85
+ files?: File[];
86
+ loadingPercentage?: number;
87
+ headers?: Record<string, string>;
88
+ }
89
+ export interface IKnowledgeLinkFile extends ILinkFile {
90
+ name: string;
91
+ handleType: string[];
92
+ splitter: string;
93
+ pathType: KnowledgePathType;
94
+ indexConfig?: IKnowledgeIndexConfig;
95
+ }
96
+ export interface IKnowledgeIndexApi {
97
+ index_name: string;
98
+ index_type: string;
99
+ status?: 'normal' | 'init' | 'deleting';
100
+ index_config: {
101
+ type?: 'user' | 'system';
102
+ data_type?: string;
103
+ columns: string[];
104
+ };
105
+ }
106
+ export interface IKnowledgeIndexConfig {
107
+ vector_indexes: IKnowledgeIndexApi[];
108
+ scalar_indexes: IKnowledgeIndexApi[];
109
+ full_text_indexes: IKnowledgeIndexApi[];
110
+ }
111
+ export interface IKnowledge {
112
+ id?: number;
113
+ spaceId?: string;
114
+ url: string;
115
+ content: string;
116
+ tagNames: string[];
117
+ splitter: string;
118
+ handleType: string[];
119
+ updateFrequency?: number;
120
+ headers?: Record<string, string>;
121
+ name: string;
122
+ fileName: string;
123
+ fileSize: number;
124
+ fileType: string;
125
+ filePath: string;
126
+ pathType: KnowledgePathType;
127
+ createdType: KnowledgeType;
128
+ status?: FileStatus;
129
+ knowledgebaseId: number;
130
+ knowledgebaseName: string;
131
+ parentAnchorPath?: string;
132
+ permission?: IResourcePermission;
133
+ anchorPath?: string;
134
+ linkFiles?: IKnowledgeLinkFile[];
135
+ updatedAt?: string;
136
+ updatedBy?: string;
137
+ errorMessage?: string;
138
+ indexConfig?: IKnowledgeIndexConfig;
139
+ }
140
+ export interface IKnowledgebase {
141
+ id?: number;
142
+ spaceId?: string;
143
+ anchorPath?: string;
144
+ parentAnchorPath?: string;
145
+ filePath: string;
146
+ fileName?: string;
147
+ fileType?: string;
148
+ handleType: string[];
149
+ updateFrequency?: number;
150
+ name: string;
151
+ generateType?: EnumCharacter;
152
+ pathType?: KnowledgePathType;
153
+ createdType?: KnowledgeType;
154
+ number: number;
155
+ folderNumber?: number;
156
+ url?: string;
157
+ updatedBy?: string;
158
+ indexConfig?: IKnowledgeIndexConfig;
159
+ permission?: IResourcePermission;
160
+ children?: Array<IKnowledgebase>;
161
+ }
162
+ export interface ISession {
163
+ sessionCode: string;
164
+ sessionName: string;
165
+ model: string;
166
+ roleInfo?: {
167
+ collectionId: number;
168
+ collectionName: string;
169
+ content: IContent[];
170
+ variables: IVariable[];
171
+ };
172
+ sessionProperty?: {
173
+ isAutoClear?: boolean;
174
+ isAutoCalcPrompt?: boolean;
175
+ };
176
+ tools?: ITool[];
177
+ anchorPathResources?: {
178
+ knowledges: IKnowledge[];
179
+ knowledgebases: IKnowledgebase[];
180
+ knowledgeFolders: IKnowledgebase[];
181
+ };
182
+ }
183
+ export interface ISessionContent {
184
+ id?: number;
185
+ createdAt?: string;
186
+ createdBy?: string;
187
+ updatedAt?: string;
188
+ updatedBy?: string;
189
+ spaceId?: string;
190
+ liked?: boolean;
191
+ role: SessionContentRole;
192
+ content: string;
193
+ rate?: number;
194
+ status?: SessionContentStatus;
195
+ sessionCode?: string;
196
+ }
197
+ export interface ISessionPrompt {
198
+ content: string;
199
+ role: SessionPromptRole;
200
+ }
package/package.json CHANGED
@@ -1,16 +1,23 @@
1
1
  {
2
2
  "name": "@blueking/ai-ui-sdk",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.3",
4
4
  "description": "蓝鲸AI UI SDK",
5
- "main": "main.js",
5
+ "main": "dist/main.js",
6
+ "types": "dist/main.d.ts",
6
7
  "scripts": {
7
- "build": "bk-cli-service-webpack build"
8
+ "build": "bk-cli-service-webpack build && tsc --emitDeclarationOnly"
8
9
  },
10
+ "files": [
11
+ "dist"
12
+ ],
9
13
  "keywords": [],
10
14
  "author": "",
11
15
  "license": "ISC",
12
16
  "dependencies": {
13
17
  "@blueking/cli-service-webpack": "0.0.7-beta.1",
14
18
  "vue": "^3.5.13"
19
+ },
20
+ "devDependencies": {
21
+ "typescript": "^5.5.4"
15
22
  }
16
23
  }