@blueking/ai-blueking 0.3.28 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -154,7 +154,7 @@ AI 小鲸支持渲染可点击的交互式 HTML 元素。以下是如何实现
154
154
 
155
155
  <script lang="ts" setup>
156
156
  import { ref } from 'vue';
157
- import AIBlueking, { ChatHelper, RoleType, MessageStatus } from '@blueking/ai-blueking';
157
+ import AIBlueking, { ChatHelper, RoleType, MessageStatus, isThinking } from '@blueking/ai-blueking';
158
158
  import '@blueking/ai-blueking/dist/vue3/style.css';
159
159
 
160
160
  interface ISendData {
@@ -178,32 +178,28 @@ AI 小鲸支持渲染可点击的交互式 HTML 元素。以下是如何实现
178
178
  };
179
179
 
180
180
  // 接收消息
181
- const handleReceiveMessage = (message: string, id: number | string) => {
181
+ const handleReceiveMessage = (message: string, id: number | string, cover?: boolean) => {
182
182
  const currentMessage = messages.value.at(-1);
183
- if (currentMessage.status === MessageStatus.Loading) {
183
+ if (currentMessage?.status === MessageStatus.Loading) {
184
184
  // 如果是loading状态,直接覆盖
185
185
  currentMessage.content = message;
186
186
  currentMessage.status = MessageStatus.Success;
187
- } else if (currentMessage.status === MessageStatus.Success) {
188
- // 如果是后续消息,就追加消息
189
- currentMessage.content += message;
187
+ } else if (currentMessage?.status === MessageStatus.Success) {
188
+ // 根据 cover 参数决定是追加还是覆盖
189
+ currentMessage.content = cover ? message : currentMessage.content + message;
190
190
  }
191
191
  };
192
192
 
193
193
  // 聊天结束
194
- const handleEnd = (id: number | string, message?: string) => {
194
+ const handleEnd = (id: number | string) => {
195
195
  loading.value = false;
196
196
  const currentMessage = messages.value.at(-1);
197
- if (message) {
198
- // done 的情况下,返回 message,直接覆盖
199
- currentMessage.content = message;
200
- currentMessage.status = MessageStatus.Success;
201
- } else if (currentMessage.status === MessageStatus.Loading) {
202
- // loading 情况下终止
197
+ // loading 状态或思考状态下终止时,标记为错误
198
+ if (currentMessage?.status === MessageStatus.Loading || isThinking(currentMessage?.content || '')) {
203
199
  currentMessage.content = '聊天内容已中断';
204
200
  currentMessage.status = MessageStatus.Error;
205
201
  }
206
- }
202
+ };
207
203
 
208
204
  // 错误处理
209
205
  const handleError = (message: string, code: string | number, id: number | string) => {
@@ -228,6 +224,7 @@ AI 小鲸支持渲染可点击的交互式 HTML 元素。以下是如何实现
228
224
  handleReceiveMessage,
229
225
  handleEnd,
230
226
  handleError,
227
+ messages.value,
231
228
  );
232
229
 
233
230
  // 清空消息
@@ -26,7 +26,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
26
26
  enablePopup: boolean;
27
27
  }>, {
28
28
  setInputMessage: (val: string) => void;
29
- quickActions: (type: "translate" | "explanation", content: string) => void;
29
+ quickActions: (type: "explanation" | "translate", content: string) => void;
30
30
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
31
31
  send: (data: ISendData) => void;
32
32
  close: () => void;
@@ -38,6 +38,12 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
38
38
  "update:model": (val: string) => void;
39
39
  "choose-prompt": (prompt: IPrompt) => void;
40
40
  "update:isShow": (val: boolean) => void;
41
+ "shortcut-click": (data: {
42
+ type: string;
43
+ label: string;
44
+ cite: string;
45
+ prompt: string;
46
+ }) => void;
41
47
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<IProps>, {
42
48
  enablePopup: boolean;
43
49
  }>>> & {
@@ -49,6 +55,12 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
49
55
  onSend?: ((data: ISendData) => any) | undefined;
50
56
  "onAi-click"?: ((val: string) => any) | undefined;
51
57
  "onScroll-load"?: (() => any) | undefined;
58
+ "onShortcut-click"?: ((data: {
59
+ type: string;
60
+ label: string;
61
+ cite: string;
62
+ prompt: string;
63
+ }) => any) | undefined;
52
64
  "onUpdate:model"?: ((val: string) => any) | undefined;
53
65
  "onUpdate:isShow"?: ((val: boolean) => any) | undefined;
54
66
  }, {
@@ -1,5 +1,8 @@
1
+ import { ReferenceDocStyleManager } from './composables/use-reference-docs';
2
+ import { ThinkStyleManager } from './composables/use-think';
3
+ import { IMessage } from './types';
1
4
  type HandleStart = (id: number | string) => unknown;
2
- type HandleReceiveMessage = (message: string, id: number | string) => void;
5
+ type HandleReceiveMessage = (message: string, id: number | string, cover?: boolean) => void;
3
6
  type HandleEnd = (id: number | string, message?: string) => void;
4
7
  type HandleError = (message: string, code: number | string, id: number | string) => unknown;
5
8
  export declare class ChatHelper {
@@ -8,8 +11,12 @@ export declare class ChatHelper {
8
11
  handleError: HandleError;
9
12
  handleReceiveMessage: HandleReceiveMessage;
10
13
  handleStart: HandleStart;
14
+ messages: IMessage[];
15
+ styleManager: InstanceType<typeof ReferenceDocStyleManager>;
16
+ thinkStyleManager: InstanceType<typeof ThinkStyleManager>;
11
17
  url: string;
12
- constructor(url: string, handleStart: HandleStart, handleReceiveMessage: HandleReceiveMessage, handleEnd: HandleEnd, handleError: HandleError);
18
+ constructor(url: string, handleStart: HandleStart, handleReceiveMessage: HandleReceiveMessage, handleEnd: HandleEnd, handleError: HandleError, messages: IMessage[]);
19
+ destroy(): void;
13
20
  stop(id: number | string): void;
14
21
  stream(param: unknown, id: number | string, headers?: Record<string, string>): Promise<void>;
15
22
  }
@@ -25,6 +25,12 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
25
25
  "choose-prompt": (prompt: IPrompt) => void;
26
26
  stop: () => void;
27
27
  "scroll-load": () => void;
28
+ "shortcut-click": (data: {
29
+ type: string;
30
+ label: string;
31
+ cite: string;
32
+ prompt: string;
33
+ }) => void;
28
34
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<IProps>, {
29
35
  background: string;
30
36
  scrollLoadingEnd: boolean;
@@ -36,6 +42,12 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
36
42
  onSend?: ((data: ISendData) => any) | undefined;
37
43
  "onAi-click"?: ((userInput: string) => any) | undefined;
38
44
  "onScroll-load"?: (() => any) | undefined;
45
+ "onShortcut-click"?: ((data: {
46
+ type: string;
47
+ label: string;
48
+ cite: string;
49
+ prompt: string;
50
+ }) => any) | undefined;
39
51
  }, {
40
52
  shortcuts: IShortCut[];
41
53
  background: string;
@@ -8,6 +8,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
8
8
  startPosition?: IStartPosition | undefined;
9
9
  models?: IModel[] | undefined;
10
10
  model?: string | undefined;
11
+ loading?: boolean | undefined;
11
12
  }>, {
12
13
  headBackground: string;
13
14
  positionLimit: () => {
@@ -40,6 +41,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
40
41
  startPosition?: IStartPosition | undefined;
41
42
  models?: IModel[] | undefined;
42
43
  model?: string | undefined;
44
+ loading?: boolean | undefined;
43
45
  }>, {
44
46
  headBackground: string;
45
47
  positionLimit: () => {
@@ -0,0 +1,19 @@
1
+ import type { IDocument } from '../types/index';
2
+ /**
3
+ * 获取引用资料的 HTML 内容
4
+ * @param documents
5
+ * @returns
6
+ */
7
+ export declare const getHtmlContentFromDocuments: (documents: IDocument[]) => string;
8
+ /**
9
+ * 移除引用资料的 HTML 内容
10
+ * @param content
11
+ * @returns
12
+ */
13
+ export declare const removeReferenceDoc: (content: string) => string;
14
+ export declare class ReferenceDocStyleManager {
15
+ private styleEle;
16
+ addStyle(): void;
17
+ removeStyle(): void;
18
+ }
19
+ export declare const useReferenceDoc: () => void;
@@ -0,0 +1,26 @@
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, elapsedTime?: number) => string;
9
+ /**
10
+ * 判断是否是思考中
11
+ * @param content
12
+ * @returns
13
+ */
14
+ export declare const isThinking: (content: string) => boolean | null;
15
+ /**
16
+ * 移除思考的 HTML 内容
17
+ * @param content
18
+ * @returns
19
+ */
20
+ export declare const removeThink: (content: string) => string;
21
+ export declare class ThinkStyleManager {
22
+ private styleEle;
23
+ addStyle(): void;
24
+ removeStyle(): void;
25
+ }
26
+ export declare const useThink: () => void;
@@ -30,6 +30,7 @@ export declare const langData: {
30
30
  readonly explanationShortcut: "You are a professional explainer. Please provide a detailed explanation of \"{{ SELECTED_TEXT }}\". Your explanation should include: 1) basic meaning and conceptual explanation; 2) practical applications or use cases; 3) if it's a technical term, please provide relevant technical background; 4) where appropriate, provide specific examples to aid understanding. Use clear and accessible language to ensure non-experts can understand. If the word/phrase has multiple meanings, please list the main definitions. Keep your response concise and clear while ensuring completeness and accuracy of information.";
31
31
  readonly 翻译: "translate";
32
32
  readonly 解释: "explan";
33
+ readonly 'AI\u5C0F\u9CB8\u6B63\u5728\u56DE\u590D\uFF0C\u8BF7\u7ED3\u675F\u540E\u518D\u6E05\u7A7A': "AI BK GPT is executing, please clear after completion";
33
34
  };
34
35
  export declare const zhLangData: {
35
36
  translateShortcut: string;
@@ -46,3 +46,9 @@ export interface AIBluekingExpose {
46
46
  setInputMessage: (val: string) => void;
47
47
  quickActions: (type: 'explanation' | 'translate', content: string) => void;
48
48
  }
49
+ export type IDocument = {
50
+ metadata: {
51
+ file_path: string;
52
+ path: string;
53
+ };
54
+ };
@@ -30,3 +30,9 @@ export declare const debounce: <T, R>(fn: (P?: T) => R, delay?: number) => (para
30
30
  * @returns 处理后的提示词
31
31
  */
32
32
  export declare const processPromptTemplate: (prompt: string, selectedText: string) => string;
33
+ /**
34
+ * 格式化时间
35
+ * @param val 时间
36
+ * @returns 格式化后的时间
37
+ */
38
+ export declare function durationFormatter(val: number): string;