@blueking/ai-ui-sdk 0.0.15-beta.3 → 0.0.15-beta.30

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 (89) hide show
  1. package/dist/assets/images/ai.png +0 -0
  2. package/dist/assets/images/user.png +0 -0
  3. package/dist/assets/svg/picture-fail.svg +1 -0
  4. package/dist/common/util.d.ts +10 -0
  5. package/dist/common/util.js +34 -0
  6. package/dist/component/render-image/index.script.vue.js +37 -0
  7. package/dist/component/render-image/index.vue.d.ts +6 -0
  8. package/dist/component/render-image/index.vue.js +3 -0
  9. package/dist/component/render-input/index.script.vue.js +210 -0
  10. package/dist/component/render-input/index.vue.css +124 -0
  11. package/dist/component/render-input/index.vue.d.ts +20 -0
  12. package/dist/component/render-input/index.vue.js +5 -0
  13. package/dist/component/render-input/render-drag.script.vue.js +61 -0
  14. package/dist/component/render-input/render-drag.vue.css +28 -0
  15. package/dist/component/render-input/render-drag.vue.d.ts +13 -0
  16. package/dist/component/render-input/render-drag.vue.js +5 -0
  17. package/dist/component/render-input/render-quill.script.vue.js +197 -0
  18. package/dist/component/render-input/render-quill.vue.css +27 -0
  19. package/dist/component/render-input/render-quill.vue.d.ts +24 -0
  20. package/dist/component/render-input/render-quill.vue.js +4 -0
  21. package/dist/component/render-knowledge-icon/index.script.vue.js +40 -0
  22. package/dist/component/render-knowledge-icon/index.vue.css +4 -0
  23. package/dist/component/render-knowledge-icon/index.vue.d.ts +14 -0
  24. package/dist/component/render-knowledge-icon/index.vue.js +5 -0
  25. package/dist/component/render-markdown/mark-down-code.d.ts +2 -0
  26. package/dist/component/render-markdown/mark-down-code.js +171 -0
  27. package/dist/component/render-markdown/mark-down-emoji.d.ts +2 -0
  28. package/dist/component/render-markdown/mark-down-emoji.js +4 -0
  29. package/dist/component/render-markdown/mark-down.d.ts +74 -0
  30. package/dist/component/render-markdown/mark-down.js +147 -0
  31. package/dist/component/render-markdown/mark-down.postcss.css +129 -0
  32. package/dist/component/render-message/index.d.ts +61 -0
  33. package/dist/component/render-message/index.js +110 -0
  34. package/dist/component/render-message/openai-message.script.vue.js +215 -0
  35. package/dist/component/render-message/openai-message.vue.css +99 -0
  36. package/dist/component/render-message/openai-message.vue.d.ts +15 -0
  37. package/dist/component/render-message/openai-message.vue.js +5 -0
  38. package/dist/component/render-message/skeleton-message.script.vue.js +7 -0
  39. package/dist/component/render-message/skeleton-message.vue.css +7 -0
  40. package/dist/component/render-message/skeleton-message.vue.d.ts +2 -0
  41. package/dist/component/render-message/skeleton-message.vue.js +6 -0
  42. package/dist/component/render-message/system-message.script.vue.js +17 -0
  43. package/dist/component/render-message/system-message.vue.css +18 -0
  44. package/dist/component/render-message/system-message.vue.d.ts +6 -0
  45. package/dist/component/render-message/system-message.vue.js +5 -0
  46. package/dist/component/render-message/time-message.script.vue.js +41 -0
  47. package/dist/component/render-message/time-message.vue.css +14 -0
  48. package/dist/component/render-message/time-message.vue.d.ts +6 -0
  49. package/dist/component/render-message/time-message.vue.js +5 -0
  50. package/dist/component/render-message/token-expired-message.script.vue.js +78 -0
  51. package/dist/component/render-message/token-expired-message.vue.css +56 -0
  52. package/dist/component/render-message/token-expired-message.vue.d.ts +15 -0
  53. package/dist/component/render-message/token-expired-message.vue.js +5 -0
  54. package/dist/component/render-message/user-message.script.vue.js +230 -0
  55. package/dist/component/render-message/user-message.vue.css +90 -0
  56. package/dist/component/render-message/user-message.vue.d.ts +21 -0
  57. package/dist/component/render-message/user-message.vue.js +5 -0
  58. package/dist/component/render-stop/index.script.vue.js +24 -0
  59. package/dist/component/render-stop/index.vue.css +18 -0
  60. package/dist/component/render-stop/index.vue.d.ts +6 -0
  61. package/dist/component/render-stop/index.vue.js +5 -0
  62. package/dist/component.d.ts +5 -0
  63. package/dist/component.js +6 -0
  64. package/dist/css/fonts/iconcool.eot +0 -0
  65. package/dist/css/fonts/iconcool.svg +30 -0
  66. package/dist/css/fonts/iconcool.ttf +0 -0
  67. package/dist/css/fonts/iconcool.woff +0 -0
  68. package/dist/css/iconcool.js +1 -1
  69. package/dist/css/style.css +34 -4
  70. package/dist/event/index.js +2 -1
  71. package/dist/hooks/use-chat.d.ts +8 -8
  72. package/dist/hooks/use-chat.js +88 -51
  73. package/dist/hooks/use-click-proxy.js +1 -1
  74. package/dist/hooks/use-http.d.ts +1 -0
  75. package/dist/hooks/use-http.js +4 -0
  76. package/dist/hooks/use-mouse-drag.d.ts +13 -0
  77. package/dist/hooks/use-mouse-drag.js +59 -0
  78. package/dist/hooks/use-reference-doc.js +4 -4
  79. package/dist/http/fetch/error-interceptor.js +23 -2
  80. package/dist/http/fetch/index.js +5 -6
  81. package/dist/http/helper/agent.d.ts +7 -0
  82. package/dist/http/helper/agent.js +8 -0
  83. package/dist/http/helper/session.js +1 -1
  84. package/dist/types/agent.d.ts +8 -0
  85. package/dist/types/enum.d.ts +6 -1
  86. package/dist/types/enum.js +7 -1
  87. package/dist/types/model.d.ts +14 -0
  88. package/dist/types/session.d.ts +4 -2
  89. package/package.json +25 -5
@@ -25,6 +25,7 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
25
25
  time?: string | undefined;
26
26
  property?: {
27
27
  extra?: {
28
+ [x: string]: any;
28
29
  tools?: {
29
30
  spaceId?: string | undefined;
30
31
  header: {
@@ -431,6 +432,7 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
431
432
  time?: string | undefined;
432
433
  property?: {
433
434
  extra?: {
435
+ [x: string]: any;
434
436
  tools?: {
435
437
  spaceId?: string | undefined;
436
438
  header: {
@@ -825,10 +827,9 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
825
827
  sessionLoadingMap: import("vue").Ref<SessionLoadingMap, SessionLoadingMap>;
826
828
  prompts: import("vue").ComputedRef<ISessionPrompt[]>;
827
829
  currentSessionLoading: import("vue").ComputedRef<boolean>;
828
- chat: ({ sessionCode, data, url, headers, }: {
830
+ chat: ({ sessionCode, data, headers, }: {
829
831
  sessionCode: string;
830
832
  data?: Record<string, any>;
831
- url: string;
832
833
  headers?: Record<string, string>;
833
834
  }) => void;
834
835
  sendChat: (content: BasicChatContent | ShortcutChatContent, callback?: () => void) => void;
@@ -844,12 +845,10 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
844
845
  deleteSessionContents: (sessionCode: string, contentIds: number[]) => Promise<number>;
845
846
  handleStartChat: (sessionCode: string) => Promise<void | undefined>;
846
847
  handleErrorChat: (sessionCode: string, message: string, code?: string) => Promise<void | undefined>;
847
- reGenerateChat: (chatIndex: number) => void;
848
- reSendChat: (index: number, { message, cite }: {
849
- message: string;
850
- cite?: string;
851
- }, callback?: () => void) => void;
852
- deleteChat: (index: number) => void;
848
+ reGenerateChat: (sessionCode: string, sessionContent: ISessionContent, sessionIndex: number) => void;
849
+ reSendChat: (sessionCode: string, sessionContent: ISessionContent, sessionIndex: number) => Promise<void>;
850
+ deleteChat: (index: number, sessionCode: string) => void;
851
+ getAgentInfoApi: () => Promise<import("../types/agent").IAgentInfo>;
853
852
  clearSessionApi: (sessionCode: string) => Promise<unknown>;
854
853
  getSessionsApi: () => Promise<ISession[]>;
855
854
  plusSessionApi: (data: ISession) => Promise<ISession>;
@@ -862,5 +861,6 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
862
861
  modifySessionContentApi: (data: ISessionContent) => Promise<ISessionContent>;
863
862
  deleteSessionContentApi: (id: number) => Promise<ISessionContent>;
864
863
  batchDeleteSessionContentsApi: (ids: number[]) => Promise<number>;
864
+ updateRequestOptions: (newOptions: Partial<typeof requestOptions>) => void;
865
865
  };
866
866
  export {};
@@ -65,8 +65,19 @@ import { ChatHelper } from '../common/chart-helper.js';
65
65
  import { processPromptTemplate, throttle } from '../common/util.js';
66
66
  // ai 聊天
67
67
  export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThink, handleEnd, handleError, requestOptions })=>{
68
- // 接口
69
- const { clearSession: clearSessionApi, getSessions: getSessionsApi, plusSession: plusSessionApi, modifySession: modifySessionApi, deleteSession: deleteSessionApi, batchDeleteSessions: batchDeleteSessionsApi, getSession: getSessionApi, getSessionContents: getSessionContentsApi, plusSessionContent: plusSessionContentApi, modifySessionContent: modifySessionContentApi, deleteSessionContent: deleteSessionContentApi, batchDeleteSessionContents: batchDeleteSessionContentsApi } = useHttp(requestOptions.url);
68
+ // 用 ref 存储 requestOptions,使其可更新
69
+ const currentRequestOptions = ref(requestOptions);
70
+ // 创建一个变量保存当前的API实现
71
+ let apiImpl = useHttp(currentRequestOptions.value.url);
72
+ // 更新 requestOptions 的方法
73
+ function updateRequestOptions(newOptions) {
74
+ // 合并新旧配置
75
+ currentRequestOptions.value = _object_spread({}, currentRequestOptions.value, newOptions);
76
+ // 如果 URL 变更,重新获取 API
77
+ if (newOptions.url) {
78
+ apiImpl = useHttp(currentRequestOptions.value.url);
79
+ }
80
+ }
70
81
  const startMessage = '内容正在生成中...';
71
82
  // 聊天上下文
72
83
  const currentSession = ref();
@@ -188,14 +199,14 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
188
199
  });
189
200
  // 新增 db
190
201
  function plusSessionContent2Db(sessionContent) {
191
- return plusSessionContentApi(sessionContent).then((result)=>{
202
+ return apiImpl.plusSessionContent(sessionContent).then((result)=>{
192
203
  sessionContent.id = result.id;
193
204
  sessionContent.createdAt = result.createdAt;
194
205
  return sessionContent;
195
206
  });
196
207
  }
197
208
  // 防抖更新 db
198
- const throttleModifySessionContentApi = throttle((id, sessionContent)=>modifySessionContentApi(sessionContent), 1000);
209
+ const throttleModifySessionContentApi = throttle((id, sessionContent)=>apiImpl.modifySessionContent(sessionContent), 1000);
199
210
  // 设置 currentSession
200
211
  function setCurrentSession(session) {
201
212
  currentSession.value = session;
@@ -300,12 +311,12 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
300
311
  const deleteSessionContentIds = getDeleteSessionContents(sessionCode, [
301
312
  contentId
302
313
  ], true);
303
- return batchDeleteSessionContentsApi(deleteSessionContentIds);
314
+ return apiImpl.batchDeleteSessionContents(deleteSessionContentIds);
304
315
  }
305
316
  // 批量删除
306
317
  function deleteSessionContents(sessionCode, contentIds) {
307
318
  const deleteSessionContentIds = getDeleteSessionContents(sessionCode, contentIds, false);
308
- return batchDeleteSessionContentsApi(deleteSessionContentIds);
319
+ return apiImpl.batchDeleteSessionContents(deleteSessionContentIds);
309
320
  }
310
321
  function handleStartChat(sessionCode) {
311
322
  return _handleStartChat.apply(this, arguments);
@@ -434,49 +445,68 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
434
445
  return _handleErrorChat.apply(this, arguments);
435
446
  }
436
447
  // 重新生成对话 仅支持重新生成 ai 的回复
437
- function reGenerateChat(chatIndex) {
438
- const chat = sessionContents.value[chatIndex];
439
- if (chat.role !== SessionContentRole.Ai) {
448
+ function reGenerateChat(sessionCode, sessionContent, sessionIndex) {
449
+ if (sessionContent.role !== SessionContentRole.Ai) {
440
450
  return;
441
451
  }
442
- const message = sessionContents.value[chatIndex - 1].content;
443
- const cite = sessionContents.value[chatIndex - 1].cite;
444
- sessionContents.value.splice(chatIndex - 1, sessionContents.value.length - chatIndex + 1); // 重新生成时,删除当前的 ai 回复和下方的所有内容
445
- sendChat({
446
- message,
447
- cite
448
- });
452
+ // 重新生成时,删除当前的 ai 回复和下方的所有内容
453
+ const sessionIds = sessionContents.value.slice(sessionIndex, sessionContents.value.length).map((item)=>item.id).filter((item)=>item !== undefined);
454
+ if (sessionIds.length > 0) {
455
+ deleteSessionContents(sessionCode, sessionIds);
456
+ }
457
+ const userSessionContent = sessionContents.value[sessionIndex - 1];
458
+ userSessionContent && chat(userSessionContent);
449
459
  }
450
460
  // 聊天
451
- function chat({ sessionCode, data, url, headers }) {
461
+ function chat({ sessionCode, data, headers }) {
462
+ var _currentRequestOptions_value;
452
463
  const sessionContent = getLastSessionContentBySessionCode(sessionCode);
453
464
  // 发送请求
454
465
  chatHelper.stream({
455
466
  sessionCode,
456
- url: url,
467
+ url: `${currentRequestOptions.value.url}/chat_completion/`,
457
468
  data: _object_spread({
458
- session_content_id: sessionContent.id,
459
- session_code: sessionCode
469
+ session_content_id: sessionContent === null || sessionContent === void 0 ? void 0 : sessionContent.id,
470
+ session_code: sessionCode,
471
+ execute_kwargs: {
472
+ stream: true
473
+ }
460
474
  }, data),
461
- headers: headers || (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers)
475
+ headers: headers || ((_currentRequestOptions_value = currentRequestOptions.value) === null || _currentRequestOptions_value === void 0 ? void 0 : _currentRequestOptions_value.headers)
462
476
  });
463
477
  }
464
- // 重新发送聊天, 需要将当前聊天内容以及下方的所有内容删除
465
- function reSendChat(index, { message, cite }, callback) {
466
- const chat = sessionContents.value[index];
467
- if (chat.role !== SessionContentRole.User) {
468
- return;
469
- }
470
- sessionContents.value.splice(index, sessionContents.value.length - index);
471
- sendChat({
472
- message,
473
- cite
474
- }, callback);
478
+ function reSendChat(sessionCode, sessionContent, sessionIndex) {
479
+ return _reSendChat.apply(this, arguments);
480
+ }
481
+ function _reSendChat() {
482
+ _reSendChat = // 重新发送聊天, 需要将当前聊天内容以及下方的所有内容删除
483
+ _async_to_generator(function*(sessionCode, sessionContent, sessionIndex) {
484
+ var _sessionContent_property_extra, _sessionContent_property;
485
+ if (sessionContent.role !== SessionContentRole.User) {
486
+ return;
487
+ }
488
+ const sessionIds = sessionContents.value.slice(sessionIndex, sessionContents.value.length).map((item)=>item.id).filter((item)=>item !== undefined);
489
+ if (sessionIds.length > 0) {
490
+ deleteSessionContents(sessionCode, sessionIds);
491
+ }
492
+ yield plusSessionContent(sessionCode, {
493
+ role: SessionContentRole.User,
494
+ content: sessionContent.content,
495
+ sessionCode,
496
+ property: {
497
+ extra: {
498
+ cite: (_sessionContent_property = sessionContent.property) === null || _sessionContent_property === void 0 ? void 0 : (_sessionContent_property_extra = _sessionContent_property.extra) === null || _sessionContent_property_extra === void 0 ? void 0 : _sessionContent_property_extra.cite
499
+ }
500
+ }
501
+ });
502
+ chat(sessionContent);
503
+ });
504
+ return _reSendChat.apply(this, arguments);
475
505
  }
476
506
  // 发送聊天
477
507
  function sendChat(content, callback) {
478
- var _currentSession_value, _currentSession_value1, _currentSession_value2;
479
- if (!((_currentSession_value = currentSession.value) === null || _currentSession_value === void 0 ? void 0 : _currentSession_value.sessionCode) || !(requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.url) || currentSessionLoading.value) {
508
+ var _currentSession_value, _currentRequestOptions_value, _currentSession_value1, _currentSession_value2, _currentRequestOptions_value1;
509
+ if (!((_currentSession_value = currentSession.value) === null || _currentSession_value === void 0 ? void 0 : _currentSession_value.sessionCode) || !((_currentRequestOptions_value = currentRequestOptions.value) === null || _currentRequestOptions_value === void 0 ? void 0 : _currentRequestOptions_value.url) || currentSessionLoading.value) {
480
510
  return;
481
511
  }
482
512
  const { message, cite, shortcut } = content;
@@ -496,8 +526,8 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
496
526
  // 发送请求
497
527
  chatHelper.stream({
498
528
  sessionCode: (_currentSession_value2 = currentSession.value) === null || _currentSession_value2 === void 0 ? void 0 : _currentSession_value2.sessionCode,
499
- url: requestOptions.url,
500
- headers: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers,
529
+ url: currentRequestOptions.value.url,
530
+ headers: (_currentRequestOptions_value1 = currentRequestOptions.value) === null || _currentRequestOptions_value1 === void 0 ? void 0 : _currentRequestOptions_value1.headers,
501
531
  data: {
502
532
  inputs: {
503
533
  chat_history: prompts.value.slice(0, prompts.value.length - 1),
@@ -513,18 +543,22 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
513
543
  * @description
514
544
  * - 如果删除的是用户消息,则同时删除该消息及其对应的AI回复(共2条)
515
545
  * - 如果删除的是其他类型消息(如AI回复),则只删除该条消息
516
- */ function deleteChat(index) {
546
+ */ function deleteChat(index, sessionCode) {
547
+ let sessionIds = [];
517
548
  const chat = sessionContents.value[index];
518
549
  if (chat.role === SessionContentRole.User) {
519
- sessionContents.value.splice(index, 2);
550
+ sessionIds = sessionContents.value.slice(index, index + 2).map((item)=>item.id).filter((item)=>item !== undefined);
551
+ deleteSessionContents(sessionCode, sessionIds);
520
552
  return;
521
553
  }
522
- sessionContents.value.splice(index - 1, 2);
554
+ sessionIds = sessionContents.value.slice(index - 1, index + 1).map((item)=>item.id).filter((item)=>item !== undefined);
555
+ deleteSessionContents(sessionCode, sessionIds);
523
556
  }
524
557
  // 停止聊天
525
558
  function stopChat(sessionCode) {
526
559
  chatHelper.stop(sessionCode);
527
560
  }
561
+ // 返回包装函数,这些函数会在调用时使用当前的apiImpl
528
562
  return {
529
563
  currentSession,
530
564
  sessionContents,
@@ -549,17 +583,20 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
549
583
  reGenerateChat,
550
584
  reSendChat,
551
585
  deleteChat,
552
- clearSessionApi,
553
- getSessionsApi,
554
- plusSessionApi,
555
- modifySessionApi,
556
- deleteSessionApi,
557
- batchDeleteSessionsApi,
558
- getSessionApi,
559
- getSessionContentsApi,
560
- plusSessionContentApi,
561
- modifySessionContentApi,
562
- deleteSessionContentApi,
563
- batchDeleteSessionContentsApi
586
+ // API 方法包装器,使用正确的类型签名
587
+ getAgentInfoApi: (...args)=>apiImpl.getAgentInfo(...args),
588
+ clearSessionApi: (...args)=>apiImpl.clearSession(...args),
589
+ getSessionsApi: (...args)=>apiImpl.getSessions(...args),
590
+ plusSessionApi: (...args)=>apiImpl.plusSession(...args),
591
+ modifySessionApi: (...args)=>apiImpl.modifySession(...args),
592
+ deleteSessionApi: (...args)=>apiImpl.deleteSession(...args),
593
+ batchDeleteSessionsApi: (...args)=>apiImpl.batchDeleteSessions(...args),
594
+ getSessionApi: (...args)=>apiImpl.getSession(...args),
595
+ getSessionContentsApi: (...args)=>apiImpl.getSessionContents(...args),
596
+ plusSessionContentApi: (...args)=>apiImpl.plusSessionContent(...args),
597
+ modifySessionContentApi: (...args)=>apiImpl.modifySessionContent(...args),
598
+ deleteSessionContentApi: (...args)=>apiImpl.deleteSessionContent(...args),
599
+ batchDeleteSessionContentsApi: (...args)=>apiImpl.batchDeleteSessionContents(...args),
600
+ updateRequestOptions
564
601
  };
565
602
  };
@@ -5,7 +5,7 @@ export const useClickProxy = ()=>{
5
5
  const clickProxy = (e)=>{
6
6
  const target = e.target;
7
7
  // 聊天窗里面的引用资料和思考内容
8
- if (target === null || target === void 0 ? void 0 : target.classList.contains('bkaidev-angle-up')) {
8
+ if (target === null || target === void 0 ? void 0 : target.classList.contains('ai-ui-sdk-angle-up')) {
9
9
  const parent = target === null || target === void 0 ? void 0 : target.parentElement;
10
10
  if (parent === null || parent === void 0 ? void 0 : parent.classList.contains('closed')) {
11
11
  parent === null || parent === void 0 ? void 0 : parent.classList.remove('closed');
@@ -1,5 +1,6 @@
1
1
  import type { ISession, ISessionContent } from '@/types/session';
2
2
  export declare const useHttp: (apiPrefix: string) => {
3
+ getAgentInfo: () => Promise<import("@/types/agent").IAgentInfo>;
3
4
  clearSession: (sessionCode: string) => Promise<unknown>;
4
5
  getSessions: () => Promise<ISession[]>;
5
6
  plusSession: (data: ISession) => Promise<ISession>;
@@ -1,6 +1,9 @@
1
1
  import fetch from '../http/fetch/index.js';
2
2
  import { transferSession2SessionApi, transferSessionApi2Session, transferSessionContent2SessionContentApi, transferSessionContentApi2SessionContent } from '../http/helper/session.js';
3
+ import { transferAgentInfoApi2AgentInfo } from '../http/helper/agent.js';
3
4
  export const useHttp = (apiPrefix)=>{
5
+ // 获取 agent 信息
6
+ const getAgentInfo = ()=>fetch.get(`${apiPrefix}/agent/info/`).then((res)=>transferAgentInfoApi2AgentInfo(res));
4
7
  // 清除聊天上下文
5
8
  const clearSession = (sessionCode)=>fetch.post(`${apiPrefix}/chat_completion/${sessionCode}/clear/`);
6
9
  // 获取会话列表
@@ -32,6 +35,7 @@ export const useHttp = (apiPrefix)=>{
32
35
  ids
33
36
  });
34
37
  return {
38
+ getAgentInfo,
35
39
  clearSession,
36
40
  getSessions,
37
41
  plusSession,
@@ -0,0 +1,13 @@
1
+ export type PositionInfo = {
2
+ moveDistance: {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ singleMoveDistance: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ };
11
+ export declare const useMouseDrag: (targetsClassName: string[], callBack: (positionInfo: PositionInfo) => void) => {
12
+ isDragging: import("vue").Ref<boolean, boolean>;
13
+ };
@@ -0,0 +1,59 @@
1
+ import { onBeforeUnmount, onMounted, ref } from 'vue';
2
+ export const useMouseDrag = (targetsClassName, callBack)=>{
3
+ const isDragging = ref(false);
4
+ const startPosition = {
5
+ x: 0,
6
+ y: 0
7
+ };
8
+ const lastPosition = {
9
+ x: 0,
10
+ y: 0
11
+ };
12
+ const handleMouseDown = (event)=>{
13
+ const ele = event.target;
14
+ if (targetsClassName.some((name)=>{
15
+ var _ele_className_includes, _ele_className;
16
+ return (_ele_className = ele.className) === null || _ele_className === void 0 ? void 0 : (_ele_className_includes = _ele_className.includes) === null || _ele_className_includes === void 0 ? void 0 : _ele_className_includes.call(_ele_className, name);
17
+ })) {
18
+ isDragging.value = true;
19
+ startPosition.x = event.x;
20
+ startPosition.y = event.y;
21
+ lastPosition.x = event.x;
22
+ lastPosition.y = event.y;
23
+ }
24
+ };
25
+ const handleMouseMove = (event)=>{
26
+ if (!isDragging.value) return;
27
+ event.preventDefault();
28
+ const positionInfo = {
29
+ moveDistance: {
30
+ x: event.x - startPosition.x,
31
+ y: event.y - startPosition.y
32
+ },
33
+ singleMoveDistance: {
34
+ x: event.x - lastPosition.x,
35
+ y: event.y - lastPosition.y
36
+ }
37
+ };
38
+ // record lastPosition
39
+ lastPosition.x = event.x;
40
+ lastPosition.y = event.y;
41
+ callBack(positionInfo);
42
+ };
43
+ const handleMouseUp = ()=>{
44
+ isDragging.value = false;
45
+ };
46
+ onMounted(()=>{
47
+ document.addEventListener('mousedown', handleMouseDown);
48
+ document.addEventListener('mousemove', handleMouseMove);
49
+ document.addEventListener('mouseup', handleMouseUp);
50
+ });
51
+ onBeforeUnmount(()=>{
52
+ document.removeEventListener('mousedown', handleMouseDown);
53
+ document.removeEventListener('mousemove', handleMouseMove);
54
+ document.removeEventListener('mouseup', handleMouseUp);
55
+ });
56
+ return {
57
+ isDragging
58
+ };
59
+ };
@@ -43,7 +43,7 @@ export const useReferenceDoc = ()=>{
43
43
  border-radius: 4px;
44
44
 
45
45
  &.closed {
46
- .bkaidev-angle-up {
46
+ .ai-ui-sdk-angle-up {
47
47
  transform: rotate(180deg);
48
48
  }
49
49
 
@@ -56,7 +56,7 @@ export const useReferenceDoc = ()=>{
56
56
  }
57
57
  }
58
58
 
59
- .bkaidev-angle-up {
59
+ .ai-ui-sdk-angle-up {
60
60
  position: absolute;
61
61
  top: 4px;
62
62
  right: 0px;
@@ -65,7 +65,7 @@ export const useReferenceDoc = ()=>{
65
65
  cursor: pointer;
66
66
  }
67
67
 
68
- .bkaidev-help-document {
68
+ .ai-ui-sdk-help-document {
69
69
  margin-right: 4px;
70
70
  font-size: 19px;
71
71
  color: #3a84ff;
@@ -83,7 +83,7 @@ export const useReferenceDoc = ()=>{
83
83
  text-decoration: none;
84
84
  cursor: pointer;
85
85
 
86
- .bkaidev-cc-jump-link {
86
+ .ai-ui-sdk-cc-jump-link {
87
87
  font-size: 14px;
88
88
  }
89
89
 
@@ -1,7 +1,28 @@
1
1
  import { emitEvent } from '../../event/index.js';
2
- import { EventType } from '../../types/enum.js';
2
+ import { EventType, HttpErrorCode } from '../../types/enum.js';
3
+ import { Message } from 'bkui-vue';
3
4
  // 请求执行失败拦截器
4
5
  export default ((error, config)=>{
5
- emitEvent(EventType.Error, error, config);
6
+ const { code, message, response } = error;
7
+ // 用户登录状态失效
8
+ if ([
9
+ 'ret: 1002',
10
+ 'ret: 1001',
11
+ 'user authentication failed'
12
+ ].some((item)=>{
13
+ var _response_message;
14
+ return response === null || response === void 0 ? void 0 : (_response_message = response.message) === null || _response_message === void 0 ? void 0 : _response_message.includes(item);
15
+ }) || code === HttpErrorCode.UnLogin) {
16
+ emitEvent(EventType.Unlogin);
17
+ } else if (code === HttpErrorCode.IamNoPermission && !config.noCheckPermission) {
18
+ emitEvent(EventType.Unauthorized);
19
+ } else if (config.globalError && code !== HttpErrorCode.Aborted) {
20
+ // 全局捕获错误给出提示
21
+ Message({
22
+ theme: 'error',
23
+ message,
24
+ width: 'auto'
25
+ });
26
+ }
6
27
  return Promise.reject(error);
7
28
  });
@@ -60,9 +60,6 @@ const getFetchConfig = (method, payload, config)=>{
60
60
  if (config.requestType !== 'formData') {
61
61
  headers['Content-Type'] = contentTypeMap[config.requestType] || 'application/json';
62
62
  }
63
- if (!config.withoutSpace) {
64
- headers['X-SPACE-ID'] = localStorage.getItem('spaceId') || '';
65
- }
66
63
  // 合并配置
67
64
  let fetchConfig = deepMerge({
68
65
  method: method.toLocaleUpperCase(),
@@ -93,9 +90,11 @@ const getFetchUrl = (url, method, payload = {})=>{
93
90
  // 构造 url 对象
94
91
  const urlObject = new URL(url, baseUrl);
95
92
  // add path
96
- const configPath = window.SITE_URL;
97
- const subPath = configPath.endsWith('/') ? configPath.slice(0, -1) : configPath;
98
- urlObject.pathname = subPath + urlObject.pathname;
93
+ if (!/https?:\/\//.test(url)) {
94
+ const configPath = window.SITE_URL || '';
95
+ const subPath = configPath.endsWith('/') ? configPath.slice(0, -1) : configPath;
96
+ urlObject.pathname = subPath + urlObject.pathname;
97
+ }
99
98
  // get 请求需要将参数拼接到url上
100
99
  // if (methodsWithoutData.includes(method)) {
101
100
  // urlObject.search = qs.stringify(payload);
@@ -0,0 +1,7 @@
1
+ import type { IAgentInfoApi, IAgentInfo } from '@/types/agent';
2
+ /**
3
+ * 转换agentapi为agent
4
+ * @param data IAgentInfoApi
5
+ * @returns IAgentInfo
6
+ */
7
+ export declare const transferAgentInfoApi2AgentInfo: (data: IAgentInfoApi) => IAgentInfo;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 转换agentapi为agent
3
+ * @param data IAgentInfoApi
4
+ * @returns IAgentInfo
5
+ */ export const transferAgentInfoApi2AgentInfo = (data)=>({
6
+ openingRemark: data.opening_remark,
7
+ predefinedQuestions: data.predefined_questions
8
+ });
@@ -70,7 +70,7 @@ import { SessionContentRole, SessionPromptRole } from '../../types/enum.js';
70
70
  return {
71
71
  session_code: data.sessionCode,
72
72
  session_name: data.sessionName,
73
- model: data.model,
73
+ model: data.model || undefined,
74
74
  role_info: data.roleInfo ? {
75
75
  collection_id: data.roleInfo.collectionId,
76
76
  collection_name: data.roleInfo.collectionName,
@@ -0,0 +1,8 @@
1
+ export interface IAgentInfoApi {
2
+ opening_remark: string;
3
+ predefined_questions: string[];
4
+ }
5
+ export interface IAgentInfo {
6
+ openingRemark: string;
7
+ predefinedQuestions: string[];
8
+ }
@@ -89,5 +89,10 @@ export declare enum FileLinkType {
89
89
  BkRepo = "bk_repo"
90
90
  }
91
91
  export declare enum EventType {
92
- Error = "error"
92
+ Unlogin = "unlogin",
93
+ Unauthorized = "unauthorized"
94
+ }
95
+ export declare enum LLMSupport {
96
+ Summary = "summary",
97
+ ChatCompletion = "chat.completion"
93
98
  }
@@ -101,5 +101,11 @@ export var FileLinkType;
101
101
  })(FileLinkType || (FileLinkType = {}));
102
102
  export var EventType;
103
103
  (function(EventType) {
104
- EventType["Error"] = "error";
104
+ EventType["Unlogin"] = "unlogin";
105
+ EventType["Unauthorized"] = "unauthorized";
105
106
  })(EventType || (EventType = {}));
107
+ export var LLMSupport;
108
+ (function(LLMSupport) {
109
+ LLMSupport["Summary"] = "summary";
110
+ LLMSupport["ChatCompletion"] = "chat.completion";
111
+ })(LLMSupport || (LLMSupport = {}));
@@ -0,0 +1,14 @@
1
+ import { LLMSupport } from '@/types/enum';
2
+ export interface IModel {
3
+ llmCode: string;
4
+ llmName: string;
5
+ llmType: LLMSupport;
6
+ property: {
7
+ onlyUserAssistant?: boolean;
8
+ supportTools?: boolean;
9
+ supportWindow?: boolean;
10
+ supportVision?: boolean;
11
+ default?: boolean;
12
+ isSelfHost?: boolean;
13
+ };
14
+ }
@@ -27,6 +27,7 @@ export interface ISessionContentApi {
27
27
  knowledgebases?: IKnowledgebaseApi[];
28
28
  knowledge_folders?: IKnowledgeApi[];
29
29
  };
30
+ [key: string]: any;
30
31
  };
31
32
  };
32
33
  }
@@ -49,6 +50,7 @@ export interface ISessionContent {
49
50
  extra?: {
50
51
  tools?: ITool[];
51
52
  anchorPathResources?: IAnchorPathResources;
53
+ [key: string]: any;
52
54
  };
53
55
  };
54
56
  }
@@ -59,7 +61,7 @@ export interface ISessionPrompt {
59
61
  export interface ISessionApi {
60
62
  session_code: string;
61
63
  session_name: string;
62
- model: string;
64
+ model?: string;
63
65
  role_info?: {
64
66
  collection_id: number;
65
67
  collection_name: string;
@@ -83,7 +85,7 @@ export interface ISessionApi {
83
85
  export interface ISession {
84
86
  sessionCode: string;
85
87
  sessionName: string;
86
- model: string;
88
+ model?: string;
87
89
  roleInfo?: {
88
90
  collectionId: number;
89
91
  collectionName: string;
package/package.json CHANGED
@@ -1,24 +1,44 @@
1
1
  {
2
2
  "name": "@blueking/ai-ui-sdk",
3
- "version": "0.0.15-beta.3",
3
+ "version": "0.0.15-beta.30",
4
4
  "description": "蓝鲸AI UI SDK",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
7
7
  "scripts": {
8
- "build": "bk-cli-service build && tsc --emitDeclarationOnly"
8
+ "build": "bk-cli-service build && vue-tsc --emitDeclarationOnly"
9
9
  },
10
10
  "files": [
11
11
  "dist"
12
12
  ],
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/main.js",
16
+ "types": "./dist/main.d.ts"
17
+ },
18
+ "./component": {
19
+ "import": "./dist/component.js",
20
+ "require": "./dist/component.d.ts"
21
+ }
22
+ },
13
23
  "keywords": [],
14
24
  "author": "",
15
25
  "license": "ISC",
16
26
  "dependencies": {
17
- "@blueking/cli-service": "0.1.0-beta.6",
27
+ "postcss-nested": "^7.0.2",
28
+ "postcss-nested-ancestors": "^3.0.0"
29
+ },
30
+ "peerDependencies": {
18
31
  "bkui-vue": "^2.0.1-beta.100",
19
- "vue": "^3.5.13"
32
+ "dayjs": "^1.11.13",
33
+ "quill": "^1.3.7",
34
+ "vue": "^3.5.13",
35
+ "x-mavon-editor": "^0.0.15"
20
36
  },
21
37
  "devDependencies": {
22
- "typescript": "^5.5.4"
38
+ "@blueking/cli-service": "0.1.0-beta.15",
39
+ "@types/quill": "^1.3.10",
40
+ "@types/markdown-it": "^14.1.2",
41
+ "typescript": "^5.5.4",
42
+ "vue-tsc": "^2.2.10"
23
43
  }
24
44
  }