@blueking/ai-ui-sdk 0.0.15-beta.4 → 0.0.15-beta.40

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 (90) 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 +9 -8
  72. package/dist/hooks/use-chat.js +140 -75
  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 +16 -0
  83. package/dist/http/helper/session.d.ts +10 -0
  84. package/dist/http/helper/session.js +92 -8
  85. package/dist/types/agent.d.ts +19 -0
  86. package/dist/types/enum.d.ts +6 -1
  87. package/dist/types/enum.js +7 -1
  88. package/dist/types/model.d.ts +14 -0
  89. package/dist/types/session.d.ts +7 -2
  90. package/package.json +25 -5
@@ -1,4 +1,4 @@
1
- import type { ISessionContent, ISession, ISessionPrompt, ChatCallbacks, BasicChatContent, ShortcutChatContent } from '../types/session';
1
+ import type { ISessionContent, ISession, ISessionPrompt, ChatCallbacks } from '../types/session';
2
2
  import { SessionContentRole, SessionContentStatus } from '../types/enum';
3
3
  type SessionContentsMap = {
4
4
  [key: string]: ISessionContent[];
@@ -827,13 +827,11 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
827
827
  sessionLoadingMap: import("vue").Ref<SessionLoadingMap, SessionLoadingMap>;
828
828
  prompts: import("vue").ComputedRef<ISessionPrompt[]>;
829
829
  currentSessionLoading: import("vue").ComputedRef<boolean>;
830
- chat: ({ sessionCode, data, url, headers, }: {
830
+ chat: ({ sessionCode, data, headers, }: {
831
831
  sessionCode: string;
832
- data?: Record<string, any>;
833
- url?: string;
832
+ data?: Record<string, unknown>;
834
833
  headers?: Record<string, string>;
835
834
  }) => void;
836
- sendChat: (content: BasicChatContent | ShortcutChatContent, callback?: () => void) => void;
837
835
  stopChat: (sessionCode: string) => void;
838
836
  plusSessionContent: (sessionCode: string, sessionContent: ISessionContent) => Promise<ISessionContent>;
839
837
  updateSessionContent: (sessionContent: ISessionContent) => false | undefined;
@@ -845,10 +843,12 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
845
843
  deleteSessionContent: (sessionCode: string, contentId: number) => Promise<number>;
846
844
  deleteSessionContents: (sessionCode: string, contentIds: number[]) => Promise<number>;
847
845
  handleStartChat: (sessionCode: string) => Promise<void | undefined>;
848
- handleErrorChat: (sessionCode: string, message: string, code?: string) => Promise<void | undefined>;
846
+ handleErrorChat: (sessionCode: string, message: string, code?: string) => Promise<void>;
847
+ handleCompleteRole: (sessionCode: string, prompts: ISessionPrompt[]) => Promise<void>;
849
848
  reGenerateChat: (sessionCode: string, sessionContent: ISessionContent, sessionIndex: number) => void;
850
- reSendChat: (sessionCode: string, sessionContent: ISessionContent, sessionIndex: number) => void;
851
- deleteChat: (index: 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>;
852
852
  clearSessionApi: (sessionCode: string) => Promise<unknown>;
853
853
  getSessionsApi: () => Promise<ISession[]>;
854
854
  plusSessionApi: (data: ISession) => Promise<ISession>;
@@ -861,5 +861,6 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
861
861
  modifySessionContentApi: (data: ISessionContent) => Promise<ISessionContent>;
862
862
  deleteSessionContentApi: (id: number) => Promise<ISessionContent>;
863
863
  batchDeleteSessionContentsApi: (ids: number[]) => Promise<number>;
864
+ updateRequestOptions: (newOptions: Partial<typeof requestOptions>) => void;
864
865
  };
865
866
  export {};
@@ -55,24 +55,60 @@ function _object_spread(target) {
55
55
  }
56
56
  return target;
57
57
  }
58
+ function ownKeys(object, enumerableOnly) {
59
+ var keys = Object.keys(object);
60
+ if (Object.getOwnPropertySymbols) {
61
+ var symbols = Object.getOwnPropertySymbols(object);
62
+ if (enumerableOnly) {
63
+ symbols = symbols.filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
+ });
66
+ }
67
+ keys.push.apply(keys, symbols);
68
+ }
69
+ return keys;
70
+ }
71
+ function _object_spread_props(target, source) {
72
+ source = source != null ? source : {};
73
+ if (Object.getOwnPropertyDescriptors) {
74
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
75
+ } else {
76
+ ownKeys(Object(source)).forEach(function(key) {
77
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
78
+ });
79
+ }
80
+ return target;
81
+ }
58
82
  import { ref, computed } from 'vue';
59
83
  import { HttpErrorCode, SessionContentRole, SessionContentStatus } from '../types/enum.js';
60
84
  import { getHtmlContentFromDocuments, removeReferenceDoc } from './use-reference-doc.js';
61
85
  import { getHtmlContentFromThink, isThinking, removeThink } from './use-think.js';
62
86
  import { useHttp } from './use-http.js';
63
- import { transferSessionContent2SessionPrompt } from '../http/helper/session.js';
87
+ import { transferSessionContent2SessionPrompt, transferSessionPrompt2SessionContent } from '../http/helper/session.js';
64
88
  import { ChatHelper } from '../common/chart-helper.js';
65
- import { processPromptTemplate, throttle } from '../common/util.js';
89
+ import { throttle } from '../common/util.js';
66
90
  // ai 聊天
67
91
  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);
92
+ // 用 ref 存储 requestOptions,使其可更新
93
+ const currentRequestOptions = ref(requestOptions);
94
+ // 创建一个变量保存当前的API实现
95
+ let apiImpl = useHttp(currentRequestOptions.value.url);
96
+ // 更新 requestOptions 的方法
97
+ function updateRequestOptions(newOptions) {
98
+ // 合并新旧配置
99
+ currentRequestOptions.value = _object_spread({}, currentRequestOptions.value, newOptions);
100
+ // 如果 URL 变更,重新获取 API
101
+ if (newOptions.url) {
102
+ apiImpl = useHttp(currentRequestOptions.value.url);
103
+ }
104
+ }
70
105
  const startMessage = '内容正在生成中...';
71
106
  // 聊天上下文
72
107
  const currentSession = ref();
73
108
  const sessionLoadingMap = ref({});
74
109
  const sessionContents = ref([]);
75
110
  const sessionContentsMap = {};
111
+ const sessionWaitingPromptsMap = {};
76
112
  // 通过计算得到的会话列表
77
113
  const calculatedSessionContents = computed(()=>{
78
114
  const calculatedSessionContents = [];
@@ -188,14 +224,14 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
188
224
  });
189
225
  // 新增 db
190
226
  function plusSessionContent2Db(sessionContent) {
191
- return plusSessionContentApi(sessionContent).then((result)=>{
227
+ return apiImpl.plusSessionContent(sessionContent).then((result)=>{
192
228
  sessionContent.id = result.id;
193
229
  sessionContent.createdAt = result.createdAt;
194
230
  return sessionContent;
195
231
  });
196
232
  }
197
233
  // 防抖更新 db
198
- const throttleModifySessionContentApi = throttle((id, sessionContent)=>modifySessionContentApi(sessionContent), 1000);
234
+ const throttleModifySessionContentApi = throttle((id, sessionContent)=>apiImpl.modifySessionContent(sessionContent), 1000);
199
235
  // 设置 currentSession
200
236
  function setCurrentSession(session) {
201
237
  currentSession.value = session;
@@ -300,12 +336,12 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
300
336
  const deleteSessionContentIds = getDeleteSessionContents(sessionCode, [
301
337
  contentId
302
338
  ], true);
303
- return batchDeleteSessionContentsApi(deleteSessionContentIds);
339
+ return apiImpl.batchDeleteSessionContents(deleteSessionContentIds);
304
340
  }
305
341
  // 批量删除
306
342
  function deleteSessionContents(sessionCode, contentIds) {
307
343
  const deleteSessionContentIds = getDeleteSessionContents(sessionCode, contentIds, false);
308
- return batchDeleteSessionContentsApi(deleteSessionContentIds);
344
+ return apiImpl.batchDeleteSessionContents(deleteSessionContentIds);
309
345
  }
310
346
  function handleStartChat(sessionCode) {
311
347
  return _handleStartChat.apply(this, arguments);
@@ -337,7 +373,7 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
337
373
  const content = getHtmlContentFromDocuments(documents);
338
374
  sessionContent.content = cover ? content : sessionContent.content + content;
339
375
  yield throttleModifySessionContentApi(sessionContent.id, sessionContent);
340
- return handleReferenceDoc === null || handleReferenceDoc === void 0 ? void 0 : handleReferenceDoc(sessionCode, sessionContent);
376
+ yield handleReferenceDoc === null || handleReferenceDoc === void 0 ? void 0 : handleReferenceDoc(sessionCode, sessionContent);
341
377
  });
342
378
  return _handleReferenceDocChat.apply(this, arguments);
343
379
  }
@@ -353,7 +389,7 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
353
389
  // 更新 db
354
390
  yield throttleModifySessionContentApi(sessionContent.id, sessionContent);
355
391
  // 调用cb
356
- return handleThink === null || handleThink === void 0 ? void 0 : handleThink(sessionCode, sessionContent);
392
+ yield handleThink === null || handleThink === void 0 ? void 0 : handleThink(sessionCode, sessionContent);
357
393
  });
358
394
  return _handleThinkChat.apply(this, arguments);
359
395
  }
@@ -374,7 +410,7 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
374
410
  // 更新 db
375
411
  yield throttleModifySessionContentApi(sessionContent.id, sessionContent);
376
412
  // 调用cb
377
- return handleText === null || handleText === void 0 ? void 0 : handleText(sessionCode, sessionContent);
413
+ yield handleText === null || handleText === void 0 ? void 0 : handleText(sessionCode, sessionContent);
378
414
  });
379
415
  return _handleTextChat.apply(this, arguments);
380
416
  }
@@ -402,7 +438,7 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
402
438
  // 更新 db
403
439
  yield throttleModifySessionContentApi(sessionContent.id, sessionContent);
404
440
  // 调用cb
405
- return handleEnd === null || handleEnd === void 0 ? void 0 : handleEnd(sessionCode, sessionContent);
441
+ yield handleEnd === null || handleEnd === void 0 ? void 0 : handleEnd(sessionCode, sessionContent);
406
442
  }
407
443
  });
408
444
  return _handleEndChat.apply(this, arguments);
@@ -429,10 +465,36 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
429
465
  // 更新 db
430
466
  yield throttleModifySessionContentApi(sessionContent.id, sessionContent);
431
467
  // 调用cb
432
- return handleError === null || handleError === void 0 ? void 0 : handleError(sessionCode, sessionContent, code);
468
+ yield handleError === null || handleError === void 0 ? void 0 : handleError(sessionCode, sessionContent, code);
433
469
  });
434
470
  return _handleErrorChat.apply(this, arguments);
435
471
  }
472
+ function handleCompleteRole(sessionCode, prompts) {
473
+ return _handleCompleteRole.apply(this, arguments);
474
+ }
475
+ function _handleCompleteRole() {
476
+ _handleCompleteRole = // 完成角色演绎
477
+ _async_to_generator(function*(sessionCode, prompts) {
478
+ let isPaused = false;
479
+ sessionWaitingPromptsMap[sessionCode] = [];
480
+ for (const prompt of prompts){
481
+ if (isPaused) {
482
+ sessionWaitingPromptsMap[sessionCode].push(prompt);
483
+ } else {
484
+ const sessionContent = _object_spread_props(_object_spread({}, transferSessionPrompt2SessionContent(prompt)), {
485
+ sessionCode,
486
+ status: SessionContentStatus.Success
487
+ });
488
+ yield plusSessionContent(sessionCode, sessionContent);
489
+ // 遇到 pause 就暂停
490
+ if (sessionContent.role === SessionContentRole.Pause) {
491
+ isPaused = true;
492
+ }
493
+ }
494
+ }
495
+ });
496
+ return _handleCompleteRole.apply(this, arguments);
497
+ }
436
498
  // 重新生成对话 仅支持重新生成 ai 的回复
437
499
  function reGenerateChat(sessionCode, sessionContent, sessionIndex) {
438
500
  if (sessionContent.role !== SessionContentRole.Ai) {
@@ -447,63 +509,59 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
447
509
  userSessionContent && chat(userSessionContent);
448
510
  }
449
511
  // 聊天
450
- function chat({ sessionCode, data, url, headers }) {
512
+ function chat({ sessionCode, data, headers }) {
513
+ const sessionWaitingPrompts = sessionWaitingPromptsMap[sessionCode];
514
+ if ((sessionWaitingPrompts === null || sessionWaitingPrompts === void 0 ? void 0 : sessionWaitingPrompts.length) > 0) {
515
+ handleCompleteRole(sessionCode, sessionWaitingPrompts);
516
+ } else {
517
+ streamChat(sessionCode, data, headers);
518
+ }
519
+ }
520
+ // stream 聊天
521
+ function streamChat(sessionCode, data, headers) {
522
+ var _currentRequestOptions_value;
451
523
  const sessionContent = getLastSessionContentBySessionCode(sessionCode);
452
524
  // 发送请求
453
525
  chatHelper.stream({
454
526
  sessionCode,
455
- url: url || requestOptions.url,
527
+ url: `${currentRequestOptions.value.url}/chat_completion/`,
456
528
  data: _object_spread({
457
- session_content_id: sessionContent.id,
458
- session_code: sessionCode
459
- }, data),
460
- headers: headers || (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers)
529
+ session_content_id: sessionContent === null || sessionContent === void 0 ? void 0 : sessionContent.id,
530
+ session_code: sessionCode,
531
+ execute_kwargs: {
532
+ stream: true
533
+ }
534
+ }, data, currentRequestOptions.value.data),
535
+ headers: headers || ((_currentRequestOptions_value = currentRequestOptions.value) === null || _currentRequestOptions_value === void 0 ? void 0 : _currentRequestOptions_value.headers)
461
536
  });
462
537
  }
463
- // 重新发送聊天, 需要将当前聊天内容以及下方的所有内容删除
464
538
  function reSendChat(sessionCode, sessionContent, sessionIndex) {
465
- if (sessionContent.role !== SessionContentRole.User) {
466
- return;
467
- }
468
- const sessionIds = sessionContents.value.slice(sessionIndex, sessionContents.value.length).map((item)=>item.id).filter((item)=>item !== undefined);
469
- if (sessionIds.length > 0) {
470
- deleteSessionContents(sessionCode, sessionIds);
471
- }
472
- chat(sessionContent);
539
+ return _reSendChat.apply(this, arguments);
473
540
  }
474
- // 发送聊天
475
- function sendChat(content, callback) {
476
- var _currentSession_value, _currentSession_value1, _currentSession_value2;
477
- 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) {
478
- return;
479
- }
480
- const { message, cite, shortcut } = content;
481
- let input = '';
482
- if (shortcut) {
483
- input = processPromptTemplate(shortcut.prompt, cite);
484
- } else {
485
- input = cite ? `${message}: "${cite}"` : message;
486
- }
487
- sessionContents.value.push({
488
- sessionCode: (_currentSession_value1 = currentSession.value) === null || _currentSession_value1 === void 0 ? void 0 : _currentSession_value1.sessionCode,
489
- content: message,
490
- role: SessionContentRole.User,
491
- status: SessionContentStatus.Success,
492
- cite
493
- });
494
- // 发送请求
495
- chatHelper.stream({
496
- sessionCode: (_currentSession_value2 = currentSession.value) === null || _currentSession_value2 === void 0 ? void 0 : _currentSession_value2.sessionCode,
497
- url: requestOptions.url,
498
- headers: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers,
499
- data: {
500
- inputs: {
501
- chat_history: prompts.value.slice(0, prompts.value.length - 1),
502
- input
503
- }
541
+ function _reSendChat() {
542
+ _reSendChat = // 重新发送聊天, 需要将当前聊天内容以及下方的所有内容删除
543
+ _async_to_generator(function*(sessionCode, sessionContent, sessionIndex) {
544
+ var _sessionContent_property_extra, _sessionContent_property;
545
+ if (sessionContent.role !== SessionContentRole.User) {
546
+ return;
547
+ }
548
+ const sessionIds = sessionContents.value.slice(sessionIndex, sessionContents.value.length).map((item)=>item.id).filter((item)=>item !== undefined);
549
+ if (sessionIds.length > 0) {
550
+ deleteSessionContents(sessionCode, sessionIds);
504
551
  }
552
+ yield plusSessionContent(sessionCode, {
553
+ role: SessionContentRole.User,
554
+ content: sessionContent.content,
555
+ sessionCode,
556
+ property: {
557
+ extra: {
558
+ 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
559
+ }
560
+ }
561
+ });
562
+ chat(sessionContent);
505
563
  });
506
- callback === null || callback === void 0 ? void 0 : callback();
564
+ return _reSendChat.apply(this, arguments);
507
565
  }
508
566
  /**
509
567
  * 删除聊天内容
@@ -511,18 +569,22 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
511
569
  * @description
512
570
  * - 如果删除的是用户消息,则同时删除该消息及其对应的AI回复(共2条)
513
571
  * - 如果删除的是其他类型消息(如AI回复),则只删除该条消息
514
- */ function deleteChat(index) {
572
+ */ function deleteChat(index, sessionCode) {
573
+ let sessionIds = [];
515
574
  const chat = sessionContents.value[index];
516
575
  if (chat.role === SessionContentRole.User) {
517
- sessionContents.value.splice(index, 2);
576
+ sessionIds = sessionContents.value.slice(index, index + 2).map((item)=>item.id).filter((item)=>item !== undefined);
577
+ deleteSessionContents(sessionCode, sessionIds);
518
578
  return;
519
579
  }
520
- sessionContents.value.splice(index - 1, 2);
580
+ sessionIds = sessionContents.value.slice(index - 1, index + 1).map((item)=>item.id).filter((item)=>item !== undefined);
581
+ deleteSessionContents(sessionCode, sessionIds);
521
582
  }
522
583
  // 停止聊天
523
584
  function stopChat(sessionCode) {
524
585
  chatHelper.stop(sessionCode);
525
586
  }
587
+ // 返回包装函数,这些函数会在调用时使用当前的apiImpl
526
588
  return {
527
589
  currentSession,
528
590
  sessionContents,
@@ -531,7 +593,6 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
531
593
  prompts,
532
594
  currentSessionLoading,
533
595
  chat,
534
- sendChat,
535
596
  stopChat,
536
597
  plusSessionContent,
537
598
  updateSessionContent,
@@ -544,20 +605,24 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
544
605
  deleteSessionContents,
545
606
  handleStartChat,
546
607
  handleErrorChat,
608
+ handleCompleteRole,
547
609
  reGenerateChat,
548
610
  reSendChat,
549
611
  deleteChat,
550
- clearSessionApi,
551
- getSessionsApi,
552
- plusSessionApi,
553
- modifySessionApi,
554
- deleteSessionApi,
555
- batchDeleteSessionsApi,
556
- getSessionApi,
557
- getSessionContentsApi,
558
- plusSessionContentApi,
559
- modifySessionContentApi,
560
- deleteSessionContentApi,
561
- batchDeleteSessionContentsApi
612
+ // API 方法包装器,使用正确的类型签名
613
+ getAgentInfoApi: (...args)=>apiImpl.getAgentInfo(...args),
614
+ clearSessionApi: (...args)=>apiImpl.clearSession(...args),
615
+ getSessionsApi: (...args)=>apiImpl.getSessions(...args),
616
+ plusSessionApi: (...args)=>apiImpl.plusSession(...args),
617
+ modifySessionApi: (...args)=>apiImpl.modifySession(...args),
618
+ deleteSessionApi: (...args)=>apiImpl.deleteSession(...args),
619
+ batchDeleteSessionsApi: (...args)=>apiImpl.batchDeleteSessions(...args),
620
+ getSessionApi: (...args)=>apiImpl.getSession(...args),
621
+ getSessionContentsApi: (...args)=>apiImpl.getSessionContents(...args),
622
+ plusSessionContentApi: (...args)=>apiImpl.plusSessionContent(...args),
623
+ modifySessionContentApi: (...args)=>apiImpl.modifySessionContent(...args),
624
+ deleteSessionContentApi: (...args)=>apiImpl.deleteSessionContent(...args),
625
+ batchDeleteSessionContentsApi: (...args)=>apiImpl.batchDeleteSessionContents(...args),
626
+ updateRequestOptions
562
627
  };
563
628
  };
@@ -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,16 @@
1
+ /**
2
+ * 转换agentapi为agent
3
+ * @param data IAgentInfoApi
4
+ * @returns IAgentInfo
5
+ */ export const transferAgentInfoApi2AgentInfo = (data)=>{
6
+ var _data_conversation_settings, _data_conversation_settings1, _data_prompt_setting;
7
+ return {
8
+ conversationSettings: {
9
+ openingRemark: data === null || data === void 0 ? void 0 : (_data_conversation_settings = data.conversation_settings) === null || _data_conversation_settings === void 0 ? void 0 : _data_conversation_settings.opening_remark,
10
+ predefinedQuestions: data === null || data === void 0 ? void 0 : (_data_conversation_settings1 = data.conversation_settings) === null || _data_conversation_settings1 === void 0 ? void 0 : _data_conversation_settings1.predefined_questions
11
+ },
12
+ promptSetting: {
13
+ content: data === null || data === void 0 ? void 0 : (_data_prompt_setting = data.prompt_setting) === null || _data_prompt_setting === void 0 ? void 0 : _data_prompt_setting.content
14
+ }
15
+ };
16
+ };
@@ -1,10 +1,20 @@
1
1
  import type { ISession, ISessionApi, ISessionContent, ISessionContentApi, ISessionPrompt } from '@/types/session';
2
+ import { SessionContentRole } from '@/types/enum';
2
3
  /**
3
4
  * 将 sessionContent 转换为 sessionPrompt
4
5
  * @param sessionContent sessionContent
5
6
  * @returns sessionPrompt
6
7
  */
7
8
  export declare const transferSessionContent2SessionPrompt: (sessionContent: ISessionContent) => ISessionPrompt;
9
+ /**
10
+ * 将前端使用的 session 提示数据转换为前端使用的 session 内容数据
11
+ * @param prompt 前端使用的 session 提示数据
12
+ * @returns 前端使用的 session 内容数据
13
+ */
14
+ export declare const transferSessionPrompt2SessionContent: (prompt: ISessionPrompt) => {
15
+ role: SessionContentRole;
16
+ content: string;
17
+ };
8
18
  /**
9
19
  * 将 API 返回的 session 数据转换为前端使用的 session 数据
10
20
  * @param data API 返回的 session 数据