@blueking/ai-blueking 0.2.15 → 0.3.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 +96 -3
- package/dist/ai-blueking.vue.d.ts +13 -4
- package/dist/components/ai-avatar.vue.d.ts +28 -0
- package/dist/components/ai-cite.vue.d.ts +21 -0
- package/dist/components/render-content.vue.d.ts +3 -3
- package/dist/components/render-modal.vue.d.ts +1 -1
- package/dist/components/render-popup.vue.d.ts +6 -0
- package/dist/components/render-shortcuts.vue.d.ts +19 -0
- package/dist/composables/use-bk-ai.d.ts +22 -0
- package/dist/composables/use-scroll-show.d.ts +4 -0
- package/dist/composables/use-select-pop.d.ts +12 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/shortcuts.d.ts +2 -0
- package/dist/lang/index.d.ts +4 -1
- package/dist/types/enum.d.ts +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/vue2/index.es.min.js +9079 -8783
- package/dist/vue2/index.iife.min.js +70 -65
- package/dist/vue2/index.umd.min.js +35 -30
- package/dist/vue2/style.css +1 -1
- package/dist/vue3/index.es.min.js +809 -513
- package/dist/vue3/index.iife.min.js +72 -67
- package/dist/vue3/index.umd.min.js +8 -3
- package/dist/vue3/style.css +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,77 @@
|
|
|
1
1
|
# AI 小鲸使用指南
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
## 新特性
|
|
5
|
+
|
|
6
|
+
- 支持 popup 弹框唤起
|
|
7
|
+
- 支持引用提问功能
|
|
8
|
+
- 支持快捷提问(当前支持翻译、解释功能)
|
|
9
|
+
|
|
10
|
+
## 0.3.0 重大变更(Breaking Changes)
|
|
11
|
+
|
|
12
|
+
### 1. 组件显示/隐藏方式变更
|
|
13
|
+
|
|
14
|
+
- 不再使用 `v-if` 控制组件显示
|
|
15
|
+
- 需要定义一个变量并使用 `v-model:is-show` 绑定到组件
|
|
16
|
+
|
|
17
|
+
### 2. handleSend 回调参数变更
|
|
18
|
+
|
|
19
|
+
回调函数现在接收一个对象参数,而不是简单的字符串。参数格式如下:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
interface ISendData {
|
|
23
|
+
content: string; // 用户输入的内容
|
|
24
|
+
cite?: string; // 引用的内容(可选)
|
|
25
|
+
prompt?: string; // 使用的 prompt 模板(可选)
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 使用示例
|
|
30
|
+
|
|
31
|
+
以下展示了如何处理新的 handleSend 回调:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
const handleSend = (args: ISendData) => {
|
|
35
|
+
// 记录当前消息记录
|
|
36
|
+
const chatHistory = [...messages.value];
|
|
37
|
+
|
|
38
|
+
// 添加用户消息
|
|
39
|
+
messages.value.push({
|
|
40
|
+
role: 'user',
|
|
41
|
+
content: args.content,
|
|
42
|
+
cite: args.cite,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// 根据参数构造输入内容
|
|
46
|
+
const input = args.prompt
|
|
47
|
+
? args.prompt // 如果有 prompt,直接使用
|
|
48
|
+
: args.cite
|
|
49
|
+
? `${args.content}: ${args.cite}` // 如果有 cite,拼接 content 和 cite
|
|
50
|
+
: args.content; // 否则只使用 content
|
|
51
|
+
|
|
52
|
+
// 调用 AI 流式对话
|
|
53
|
+
// 注:id 是唯一标识当前流,调用 chatHelper.stop 时需要传入
|
|
54
|
+
chatHelper.stream(
|
|
55
|
+
{
|
|
56
|
+
inputs: {
|
|
57
|
+
input,
|
|
58
|
+
chat_history: chatHistory,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
1,
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 注意事项
|
|
67
|
+
|
|
68
|
+
- 使用 `v-model:is-show` 时需要提前定义对应的响应式变量
|
|
69
|
+
- 处理 handleSend 回调时需要注意新的参数格式
|
|
70
|
+
- 在调用 `chatHelper.stop` 方法时需要传入正确的流 ID
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
3
75
|
## 安装
|
|
4
76
|
|
|
5
77
|
```bash
|
|
@@ -50,6 +122,7 @@ npm i @blueking/ai-blueking
|
|
|
50
122
|
```vue
|
|
51
123
|
<template>
|
|
52
124
|
<AIBlueking
|
|
125
|
+
v-model:is-show="isShow"
|
|
53
126
|
:loading="loading"
|
|
54
127
|
:messages="messages"
|
|
55
128
|
@clear="handleClear"
|
|
@@ -63,8 +136,15 @@ npm i @blueking/ai-blueking
|
|
|
63
136
|
import AIBlueking, { ChatHelper, RoleType, MessageStatus } from '@blueking/ai-blueking';
|
|
64
137
|
import '@blueking/ai-blueking/dist/vue3/style.css';
|
|
65
138
|
|
|
139
|
+
interface ISendData {
|
|
140
|
+
content: string; // 用户输入的内容
|
|
141
|
+
cite?: string; // 引用的内容
|
|
142
|
+
prompt?: string; // 使用的 prompt 模板
|
|
143
|
+
}
|
|
144
|
+
|
|
66
145
|
const loading = ref(false);
|
|
67
146
|
const messages = ref([]);
|
|
147
|
+
const isShow = ref(false);
|
|
68
148
|
|
|
69
149
|
// 聊天开始
|
|
70
150
|
const handleStart = (id: number | string) => {
|
|
@@ -131,19 +211,28 @@ npm i @blueking/ai-blueking
|
|
|
131
211
|
};
|
|
132
212
|
|
|
133
213
|
// 发送消息
|
|
134
|
-
const handleSend = (
|
|
214
|
+
const handleSend = (args: ISendData) => {
|
|
135
215
|
// 记录当前消息记录
|
|
136
216
|
const chatHistory = [...messages.value];
|
|
137
217
|
// 添加一条消息
|
|
138
218
|
messages.value.push({
|
|
139
219
|
role: 'user',
|
|
140
|
-
content:
|
|
220
|
+
content: args.content,
|
|
221
|
+
cite: args.cite,
|
|
141
222
|
});
|
|
223
|
+
|
|
224
|
+
// 根据参数构造输入内容
|
|
225
|
+
const input = args.prompt
|
|
226
|
+
? args.prompt // 如果有 prompt,直接使用
|
|
227
|
+
: args.cite
|
|
228
|
+
? `${args.content}: ${args.cite}` // 如果有 cite,拼接 content 和 cite
|
|
229
|
+
: args.content; // 否则只使用 content
|
|
230
|
+
|
|
142
231
|
// ai 消息,id是唯一标识当前流,调用 chatHelper.stop 的时候需要传入
|
|
143
232
|
chatHelper.stream(
|
|
144
233
|
{
|
|
145
234
|
inputs: {
|
|
146
|
-
input
|
|
235
|
+
input,
|
|
147
236
|
chat_history: chatHistory,
|
|
148
237
|
},
|
|
149
238
|
},
|
|
@@ -273,6 +362,10 @@ npm i @blueking/ai-blueking
|
|
|
273
362
|
|
|
274
363
|
const handleSend = (val: string) => {
|
|
275
364
|
console.log('trigger send', val);
|
|
365
|
+
// args 包含:
|
|
366
|
+
// - content: 用户输入的内容
|
|
367
|
+
// - cite: 引用的内容(可选)
|
|
368
|
+
// - prompt: 使用的 prompt 模板(可选)
|
|
276
369
|
};
|
|
277
370
|
|
|
278
371
|
const handleStop = () => {
|
|
@@ -17,27 +17,36 @@ interface IProps {
|
|
|
17
17
|
alert?: string;
|
|
18
18
|
models?: IModel[];
|
|
19
19
|
model?: string;
|
|
20
|
+
isShow?: boolean;
|
|
20
21
|
}
|
|
21
22
|
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<IProps>, {
|
|
22
23
|
setInputMessage: (val: string) => void;
|
|
23
24
|
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
24
|
-
close: () => void;
|
|
25
25
|
stop: () => void;
|
|
26
|
+
close: () => void;
|
|
26
27
|
clear: () => void;
|
|
27
28
|
"scroll-load": () => void;
|
|
28
29
|
"ai-click": (val: string) => void;
|
|
29
|
-
send: (val: string) => void;
|
|
30
30
|
"update:model": (val: string) => void;
|
|
31
31
|
"choose-prompt": (prompt: IPrompt) => void;
|
|
32
|
+
send: (data: {
|
|
33
|
+
content: string;
|
|
34
|
+
cite?: string | undefined;
|
|
35
|
+
}) => void;
|
|
36
|
+
"update:isShow": (val: boolean) => void;
|
|
32
37
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<IProps>>> & {
|
|
38
|
+
onClose?: (() => any) | undefined;
|
|
33
39
|
"onChoose-prompt"?: ((prompt: IPrompt) => any) | undefined;
|
|
34
40
|
onClear?: (() => any) | undefined;
|
|
35
41
|
onStop?: (() => any) | undefined;
|
|
36
|
-
onSend?: ((
|
|
42
|
+
onSend?: ((data: {
|
|
43
|
+
content: string;
|
|
44
|
+
cite?: string | undefined;
|
|
45
|
+
}) => any) | undefined;
|
|
37
46
|
"onAi-click"?: ((val: string) => any) | undefined;
|
|
38
47
|
"onScroll-load"?: (() => any) | undefined;
|
|
39
|
-
onClose?: (() => any) | undefined;
|
|
40
48
|
"onUpdate:model"?: ((val: string) => any) | undefined;
|
|
49
|
+
"onUpdate:isShow"?: ((val: boolean) => any) | undefined;
|
|
41
50
|
}, {}, {}>;
|
|
42
51
|
export default _default;
|
|
43
52
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
size?: number;
|
|
3
|
+
}
|
|
4
|
+
declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
|
|
5
|
+
size: number;
|
|
6
|
+
}>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
|
|
7
|
+
size: number;
|
|
8
|
+
}>>>, {
|
|
9
|
+
size: number;
|
|
10
|
+
}, {}>;
|
|
11
|
+
export default _default;
|
|
12
|
+
type __VLS_WithDefaults<P, D> = {
|
|
13
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
14
|
+
default: D[K];
|
|
15
|
+
}> : P[K];
|
|
16
|
+
};
|
|
17
|
+
type __VLS_Prettify<T> = {
|
|
18
|
+
[K in keyof T]: T[K];
|
|
19
|
+
} & {};
|
|
20
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
21
|
+
type __VLS_TypePropsToOption<T> = {
|
|
22
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
23
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
24
|
+
} : {
|
|
25
|
+
type: import('vue').PropType<T[K]>;
|
|
26
|
+
required: true;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<{
|
|
2
|
+
text: string;
|
|
3
|
+
showCloseIcon?: boolean | undefined;
|
|
4
|
+
}>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
5
|
+
close: () => void;
|
|
6
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<{
|
|
7
|
+
text: string;
|
|
8
|
+
showCloseIcon?: boolean | undefined;
|
|
9
|
+
}>>> & {
|
|
10
|
+
onClose?: (() => any) | undefined;
|
|
11
|
+
}, {}, {}>;
|
|
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
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IMessage, IPrompt } from '../types/index';
|
|
1
|
+
import type { IMessage, IPrompt, ISendData } from '../types/index';
|
|
2
2
|
interface IProps {
|
|
3
3
|
messages: IMessage[];
|
|
4
4
|
prompts?: IPrompt[];
|
|
@@ -17,7 +17,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
17
17
|
setInputMessage: (val: string) => void;
|
|
18
18
|
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
19
19
|
"ai-click": (userInput: string) => void;
|
|
20
|
-
send: (
|
|
20
|
+
send: (data: ISendData) => void;
|
|
21
21
|
"choose-prompt": (prompt: IPrompt) => void;
|
|
22
22
|
stop: () => void;
|
|
23
23
|
"scroll-load": () => void;
|
|
@@ -27,7 +27,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
27
27
|
}>>> & {
|
|
28
28
|
"onChoose-prompt"?: ((prompt: IPrompt) => any) | undefined;
|
|
29
29
|
onStop?: (() => any) | undefined;
|
|
30
|
-
onSend?: ((
|
|
30
|
+
onSend?: ((data: ISendData) => any) | undefined;
|
|
31
31
|
"onAi-click"?: ((userInput: string) => any) | undefined;
|
|
32
32
|
"onScroll-load"?: (() => any) | undefined;
|
|
33
33
|
}, {
|
|
@@ -60,8 +60,8 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
|
|
|
60
60
|
};
|
|
61
61
|
logo: string;
|
|
62
62
|
}>>> & {
|
|
63
|
-
onClear?: (() => any) | undefined;
|
|
64
63
|
onClose?: (() => any) | undefined;
|
|
64
|
+
onClear?: (() => any) | undefined;
|
|
65
65
|
"onChoose-model"?: ((val: string) => any) | undefined;
|
|
66
66
|
}, {
|
|
67
67
|
headBackground: string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
2
|
+
click: (...args: any[]) => void;
|
|
3
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>> & {
|
|
4
|
+
onClick?: ((...args: any[]) => any) | undefined;
|
|
5
|
+
}, {}, {}>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IShortCut } from '../types/index';
|
|
2
|
+
interface IProps {
|
|
3
|
+
shortcuts: IShortCut[];
|
|
4
|
+
}
|
|
5
|
+
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<IProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
6
|
+
select: (shortcut: IShortCut) => void;
|
|
7
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<IProps>>> & {
|
|
8
|
+
onSelect?: ((shortcut: IShortCut) => any) | undefined;
|
|
9
|
+
}, {}, {}>;
|
|
10
|
+
export default _default;
|
|
11
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
12
|
+
type __VLS_TypePropsToOption<T> = {
|
|
13
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
14
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
15
|
+
} : {
|
|
16
|
+
type: import('vue').PropType<T[K]>;
|
|
17
|
+
required: true;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RoleType, MessageStatus } from '../types/enum';
|
|
2
|
+
interface UseBkAiOptions {
|
|
3
|
+
useStream?: boolean;
|
|
4
|
+
apiUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function useBkAi(options?: UseBkAiOptions): {
|
|
7
|
+
loading: import("vue").Ref<boolean>;
|
|
8
|
+
messages: import("vue").Ref<{
|
|
9
|
+
status?: MessageStatus | undefined;
|
|
10
|
+
time?: string | number | undefined;
|
|
11
|
+
cite?: string | undefined;
|
|
12
|
+
role: RoleType;
|
|
13
|
+
content: string;
|
|
14
|
+
}[]>;
|
|
15
|
+
isShow: import("vue").Ref<boolean>;
|
|
16
|
+
handleShowAi: () => void;
|
|
17
|
+
handleClose: () => void;
|
|
18
|
+
handleClear: () => void;
|
|
19
|
+
handleSend: (args: any) => void;
|
|
20
|
+
handleStop: () => void;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function useSelect(): {
|
|
2
|
+
isIconVisible: import("vue").Ref<boolean>;
|
|
3
|
+
iconPosition: import("vue").Ref<{
|
|
4
|
+
top: string;
|
|
5
|
+
left: string;
|
|
6
|
+
}>;
|
|
7
|
+
selectedText: import("vue").Ref<string>;
|
|
8
|
+
hideIcon: () => void;
|
|
9
|
+
clearSelection: () => void;
|
|
10
|
+
setSelection: (text: string) => void;
|
|
11
|
+
lockSelectedText: import("vue").Ref<boolean>;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './shortcuts';
|
package/dist/lang/index.d.ts
CHANGED
|
@@ -23,5 +23,8 @@ export declare const langData: {
|
|
|
23
23
|
readonly 本周: "this week";
|
|
24
24
|
readonly 上周: "last week";
|
|
25
25
|
readonly 复制成功: "Copy success";
|
|
26
|
+
readonly 您选择的文本内容: "The text content you selected";
|
|
27
|
+
readonly 问小鲸: "Ask BK GPT";
|
|
28
|
+
readonly 想对选中的文本做什么: "What do you want to do with the selected text?";
|
|
26
29
|
};
|
|
27
|
-
export declare const t: (key: keyof typeof langData) => "BK GPT" | "shrink down" | "expand upward" | "Empty chat records" | "
|
|
30
|
+
export declare const t: (key: keyof typeof langData) => "close" | "BK GPT" | "shrink down" | "expand upward" | "Empty chat records" | "The content is being executed, please send it after the execution is completed." | "Send" | "You can type \"/\" to see more Prompts" | "Please input" | "Latest" | "Stop" | "Scroll up to load more records" | " sunday" | " monday" | " tuesday" | " wednesday" | " thursday" | " friday" | " saturday" | "yesterday" | "this week" | "last week" | "Copy success" | "The text content you selected" | "Ask BK GPT" | "What do you want to do with the selected text?" | "小鲸" | "向下收缩" | "向上扩展" | "清空聊天记录" | "关闭" | "内容正在执行中,请执行完成后再发送" | "发送" | "您可以键入 “/” 查看更多Prompt" | "请输入" | "返回最新" | "终止生成" | "向上滚动加载更多记录" | "日" | "一" | "二" | "三" | "四" | "五" | "六" | "昨天" | "本周" | "上周" | "复制成功" | "您选择的文本内容" | "问小鲸" | "想对选中的文本做什么";
|
package/dist/types/enum.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { RoleType, MessageStatus } from './enum';
|
|
|
2
2
|
export interface IMessage extends IChatHistory {
|
|
3
3
|
status?: MessageStatus;
|
|
4
4
|
time?: number | string;
|
|
5
|
+
cite?: string;
|
|
5
6
|
}
|
|
6
7
|
export interface IPrompt {
|
|
7
8
|
id: number | string;
|
|
@@ -31,3 +32,12 @@ export interface IModel {
|
|
|
31
32
|
id: string;
|
|
32
33
|
name: string;
|
|
33
34
|
}
|
|
35
|
+
export interface IShortCut {
|
|
36
|
+
label: string;
|
|
37
|
+
prompt: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ISendData {
|
|
40
|
+
content: string;
|
|
41
|
+
cite?: string;
|
|
42
|
+
prompt?: string;
|
|
43
|
+
}
|