@blueking/ai-blueking 0.3.29 → 0.4.1
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 +12 -15
- package/dist/ai-blueking.vue.d.ts +13 -1
- package/dist/chat-helper.d.ts +9 -2
- package/dist/components/render-content.vue.d.ts +12 -0
- package/dist/components/render-popup.vue.d.ts +15 -2
- package/dist/composables/use-reference-docs.d.ts +19 -0
- package/dist/composables/use-think.d.ts +26 -0
- package/dist/lang/index.d.ts +1 -1
- package/dist/types/index.d.ts +6 -0
- package/dist/util/index.d.ts +6 -0
- package/dist/vue2/index.es.min.js +5620 -5366
- package/dist/vue2/index.iife.min.js +256 -70
- package/dist/vue2/index.umd.min.js +230 -44
- package/dist/vue2/style.css +1 -1
- package/dist/vue3/index.es.min.js +932 -674
- package/dist/vue3/index.iife.min.js +250 -64
- package/dist/vue3/index.umd.min.js +201 -15
- package/dist/vue3/style.css +1 -1
- package/dist/vue3.d.ts +1 -0
- package/package.json +1 -1
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
|
|
183
|
+
if (currentMessage?.status === MessageStatus.Loading) {
|
|
184
184
|
// 如果是loading状态,直接覆盖
|
|
185
185
|
currentMessage.content = message;
|
|
186
186
|
currentMessage.status = MessageStatus.Success;
|
|
187
|
-
} else if (currentMessage
|
|
188
|
-
//
|
|
189
|
-
currentMessage.content
|
|
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
|
|
194
|
+
const handleEnd = (id: number | string) => {
|
|
195
195
|
loading.value = false;
|
|
196
196
|
const currentMessage = messages.value.at(-1);
|
|
197
|
-
|
|
198
|
-
|
|
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,11 +224,12 @@ AI 小鲸支持渲染可点击的交互式 HTML 元素。以下是如何实现
|
|
|
228
224
|
handleReceiveMessage,
|
|
229
225
|
handleEnd,
|
|
230
226
|
handleError,
|
|
227
|
+
messages.value,
|
|
231
228
|
);
|
|
232
229
|
|
|
233
230
|
// 清空消息
|
|
234
231
|
const handleClear = () => {
|
|
235
|
-
messages.value = []
|
|
232
|
+
messages.value.splice(0); // 必须使用这种方式清空消息, 不能使用 messages.value = [],否则 ChatHelper 无法感知消息数组的变化
|
|
236
233
|
};
|
|
237
234
|
|
|
238
235
|
// 发送消息
|
|
@@ -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: "
|
|
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
|
}, {
|
package/dist/chat-helper.d.ts
CHANGED
|
@@ -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;
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import { IShortCut } from '../types';
|
|
2
|
+
interface IProps {
|
|
3
|
+
shortcuts: IShortCut[];
|
|
4
|
+
}
|
|
5
|
+
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<IProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
2
6
|
click: (...args: any[]) => void;
|
|
3
7
|
shortcutClick: (...args: any[]) => void;
|
|
4
|
-
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<
|
|
8
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<IProps>>> & {
|
|
5
9
|
onClick?: ((...args: any[]) => any) | undefined;
|
|
6
10
|
onShortcutClick?: ((...args: any[]) => any) | undefined;
|
|
7
11
|
}, {}, {}>;
|
|
8
12
|
export default _default;
|
|
13
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
14
|
+
type __VLS_TypePropsToOption<T> = {
|
|
15
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
16
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
17
|
+
} : {
|
|
18
|
+
type: import('vue').PropType<T[K]>;
|
|
19
|
+
required: true;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -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;
|
package/dist/lang/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare const langData: {
|
|
|
29
29
|
readonly translateShortcut: "You are a highly skilled AI trained in language translation. I would like you to translate the text delimited by triple quotes (Translation of Chinese into English and other languages into Chinese), ensuring that the translation is colloquial and authentic.\n Only give me the output and nothing else. Do not wrap responses in quotes\n '''\n {{ SELECTED_TEXT }}\n '''\n ";
|
|
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
|
-
readonly 解释: "
|
|
32
|
+
readonly 解释: "explanation";
|
|
33
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";
|
|
34
34
|
};
|
|
35
35
|
export declare const zhLangData: {
|
package/dist/types/index.d.ts
CHANGED
package/dist/util/index.d.ts
CHANGED
|
@@ -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;
|