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

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.
@@ -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: {
@@ -828,7 +830,7 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
828
830
  chat: ({ sessionCode, data, url, headers, }: {
829
831
  sessionCode: string;
830
832
  data?: Record<string, any>;
831
- url: string;
833
+ url?: string;
832
834
  headers?: Record<string, string>;
833
835
  }) => void;
834
836
  sendChat: (content: BasicChatContent | ShortcutChatContent, callback?: () => void) => void;
@@ -844,11 +846,8 @@ export declare const useChat: ({ handleStart, handleText, handleReferenceDoc, ha
844
846
  deleteSessionContents: (sessionCode: string, contentIds: number[]) => Promise<number>;
845
847
  handleStartChat: (sessionCode: string) => Promise<void | undefined>;
846
848
  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;
849
+ reGenerateChat: (sessionCode: string, sessionContent: ISessionContent, sessionIndex: number) => void;
850
+ reSendChat: (sessionCode: string, sessionContent: ISessionContent, sessionIndex: number) => void;
852
851
  deleteChat: (index: number) => void;
853
852
  clearSessionApi: (sessionCode: string) => Promise<unknown>;
854
853
  getSessionsApi: () => Promise<ISession[]>;
@@ -27,6 +27,34 @@ function _async_to_generator(fn) {
27
27
  });
28
28
  };
29
29
  }
30
+ function _define_property(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
+ }
43
+ function _object_spread(target) {
44
+ for(var i = 1; i < arguments.length; i++){
45
+ var source = arguments[i] != null ? arguments[i] : {};
46
+ var ownKeys = Object.keys(source);
47
+ if (typeof Object.getOwnPropertySymbols === "function") {
48
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
+ }));
51
+ }
52
+ ownKeys.forEach(function(key) {
53
+ _define_property(target, key, source[key]);
54
+ });
55
+ }
56
+ return target;
57
+ }
30
58
  import { ref, computed } from 'vue';
31
59
  import { HttpErrorCode, SessionContentRole, SessionContentStatus } from '../types/enum.js';
32
60
  import { getHtmlContentFromDocuments, removeReferenceDoc } from './use-reference-doc.js';
@@ -406,40 +434,42 @@ export const useChat = ({ handleStart, handleText, handleReferenceDoc, handleThi
406
434
  return _handleErrorChat.apply(this, arguments);
407
435
  }
408
436
  // 重新生成对话 仅支持重新生成 ai 的回复
409
- function reGenerateChat(chatIndex) {
410
- const chat = sessionContents.value[chatIndex];
411
- if (chat.role !== SessionContentRole.Ai) {
437
+ function reGenerateChat(sessionCode, sessionContent, sessionIndex) {
438
+ if (sessionContent.role !== SessionContentRole.Ai) {
412
439
  return;
413
440
  }
414
- const message = sessionContents.value[chatIndex - 1].content;
415
- const cite = sessionContents.value[chatIndex - 1].cite;
416
- sessionContents.value.splice(chatIndex - 1, sessionContents.value.length - chatIndex + 1); // 重新生成时,删除当前的 ai 回复和下方的所有内容
417
- sendChat({
418
- message,
419
- cite
420
- });
441
+ // 重新生成时,删除当前的 ai 回复和下方的所有内容
442
+ const sessionIds = sessionContents.value.slice(sessionIndex, sessionContents.value.length).map((item)=>item.id).filter((item)=>item !== undefined);
443
+ if (sessionIds.length > 0) {
444
+ deleteSessionContents(sessionCode, sessionIds);
445
+ }
446
+ const userSessionContent = sessionContents.value[sessionIndex - 1];
447
+ userSessionContent && chat(userSessionContent);
421
448
  }
422
449
  // 聊天
423
450
  function chat({ sessionCode, data, url, headers }) {
451
+ const sessionContent = getLastSessionContentBySessionCode(sessionCode);
424
452
  // 发送请求
425
453
  chatHelper.stream({
426
454
  sessionCode,
427
- url: url,
428
- data,
455
+ url: url || requestOptions.url,
456
+ data: _object_spread({
457
+ session_content_id: sessionContent.id,
458
+ session_code: sessionCode
459
+ }, data),
429
460
  headers: headers || (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers)
430
461
  });
431
462
  }
432
463
  // 重新发送聊天, 需要将当前聊天内容以及下方的所有内容删除
433
- function reSendChat(index, { message, cite }, callback) {
434
- const chat = sessionContents.value[index];
435
- if (chat.role !== SessionContentRole.User) {
464
+ function reSendChat(sessionCode, sessionContent, sessionIndex) {
465
+ if (sessionContent.role !== SessionContentRole.User) {
436
466
  return;
437
467
  }
438
- sessionContents.value.splice(index, sessionContents.value.length - index);
439
- sendChat({
440
- message,
441
- cite
442
- }, callback);
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);
443
473
  }
444
474
  // 发送聊天
445
475
  function sendChat(content, callback) {
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/ai-ui-sdk",
3
- "version": "0.0.15-beta.2",
3
+ "version": "0.0.15-beta.4",
4
4
  "description": "蓝鲸AI UI SDK",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -14,7 +14,7 @@
14
14
  "author": "",
15
15
  "license": "ISC",
16
16
  "dependencies": {
17
- "@blueking/cli-service": "0.1.0-beta.5",
17
+ "@blueking/cli-service": "0.1.0-beta.6",
18
18
  "bkui-vue": "^2.0.1-beta.100",
19
19
  "vue": "^3.5.13"
20
20
  },