@blueking/ai-blueking 0.2.13 → 0.2.15-beta.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 CHANGED
@@ -6,6 +6,43 @@
6
6
  npm i @blueking/ai-blueking
7
7
  ```
8
8
 
9
+ ## 通过模板字符串渲染特定 html
10
+
11
+ #### 渲染知识库列表的模板
12
+
13
+ 可以使用类似如下的模板来渲染匹配的知识库列表
14
+
15
+ ```
16
+ <section class="knowledge-tips">
17
+ <i class="ai-blueking-icon ai-blueking-angle-up"></i>
18
+ <span class="knowledge-summary">
19
+ <i class="ai-blueking-icon ai-blueking-help-document"></i>
20
+ 引用 4 篇资料作为参考
21
+ </span>
22
+ <a href="xxx" target="_blank" class="knowledge-link">
23
+ 1. vivo 容器平台如何实现资源超卖方案
24
+ <i class="ai-blueking-icon ai-blueking-cc-jump-link"></i>
25
+ </a>
26
+ <a href="xxx" target="_blank" class="knowledge-link">
27
+ 1. vivo 容器平台如何实现资源超卖方案
28
+ <i class="ai-blueking-icon ai-blueking-cc-jump-link"></i>
29
+ </a>
30
+ <a href="xxx" target="_blank" class="knowledge-link">
31
+ 1. vivo 容器平台如何实现资源超卖方案
32
+ <i class="ai-blueking-icon ai-blueking-cc-jump-link"></i>
33
+ </a>
34
+ </section>
35
+ ```
36
+
37
+ #### 渲染带有点击交互的html
38
+
39
+ 可以使用类似如下的模板来渲染可点击交互的 html(具有'ai-clickable'的class),点击以后会触发组件的`ai-click`事件,并把 html 标签的`data-ai`的数据传递出来。这样业务可以进行二次处理。比如说把`data-ai`上的字符串赋值到输入框,可以使用`aiRef.value?.setInputMessage(val)`来设置输入框内容。
40
+
41
+ ```
42
+ <button data-ai="{ type: 'button', data: xxx }" class="ai-clickable">可点击的按钮</button>
43
+ <a data-ai="{ type: 'link', data: 'link url' }" class="ai-clickable" href="void">可点击的链接</a>
44
+ ```
45
+
9
46
  ## stream 模式
10
47
 
11
48
  不同框架,组件引入方式不同,具体可参考下面的的例子。这里使用 vue3 项目为例,来展示 stream 模式交互:
@@ -136,6 +173,7 @@ npm i @blueking/ai-blueking
136
173
  :scroll-loading-end="scrollLoadingEnd"
137
174
  :size-limit="sizeLimit"
138
175
  :start-position="startPosition"
176
+ @ai-click="handleAIClick"
139
177
  @choose-prompt="handleChoosePrompt"
140
178
  @clear="handleClear"
141
179
  @close="handleClose"
@@ -145,7 +183,7 @@ npm i @blueking/ai-blueking
145
183
  />
146
184
  </template>
147
185
  <script setup lang="ts">
148
- import { ref } from 'vue';
186
+ import { type ComponentInstance, ref } from 'vue';
149
187
 
150
188
  import AIBlueking, { type IPrompt, type IMessage, RoleType, MessageStatus } from '@blueking/ai-blueking';
151
189
 
@@ -226,6 +264,8 @@ npm i @blueking/ai-blueking
226
264
  // 向上滚动加载
227
265
  const scrollLoading = ref(false);
228
266
  const scrollLoadingEnd = ref(false);
267
+ // 组件实例
268
+ const aiRef = ref<ComponentInstance<typeof AIBlueking>>();
229
269
 
230
270
  const handleClear = () => {
231
271
  console.log('trigger clear');
@@ -270,6 +310,10 @@ npm i @blueking/ai-blueking
270
310
  const handleChoosePrompt = (prompt: IPrompt) => {
271
311
  console.log('choose prompt', prompt);
272
312
  };
313
+
314
+ const handleAIClick = (val: string) => {
315
+ aiRef.value?.setInputMessage(val);
316
+ };
273
317
  </script>
274
318
  ```
275
319
 
@@ -1,56 +1,52 @@
1
1
  import type { IMessage, IPrompt, IPositionLimit, ISize, IStartPosition, IModel } from './types';
2
- declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<{
2
+ interface IProps {
3
3
  messages: IMessage[];
4
- prompts?: IPrompt[] | undefined;
5
- loading?: boolean | undefined;
6
- headBackground?: string | undefined;
7
- background?: string | undefined;
8
- positionLimit?: IPositionLimit | undefined;
9
- sizeLimit?: ISize | undefined;
10
- startPosition?: IStartPosition | undefined;
11
- userPhoto?: string | undefined;
12
- name?: string | undefined;
13
- placeholder?: string | undefined;
14
- logo?: string | undefined;
15
- scrollLoading?: boolean | undefined;
16
- scrollLoadingEnd?: boolean | undefined;
17
- alert?: string | undefined;
18
- models?: IModel[] | undefined;
19
- model?: string | undefined;
20
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
21
- close: () => void;
4
+ prompts?: IPrompt[];
5
+ loading?: boolean;
6
+ headBackground?: string;
7
+ background?: string;
8
+ positionLimit?: IPositionLimit;
9
+ sizeLimit?: ISize;
10
+ startPosition?: IStartPosition;
11
+ userPhoto?: string;
12
+ name?: string;
13
+ placeholder?: string;
14
+ logo?: string;
15
+ scrollLoading?: boolean;
16
+ scrollLoadingEnd?: boolean;
17
+ alert?: string;
18
+ models?: IModel[];
19
+ model?: string;
20
+ isShow?: boolean;
21
+ }
22
+ declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<IProps>, {
23
+ setInputMessage: (val: string) => void;
24
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
22
25
  stop: () => void;
26
+ close: () => void;
23
27
  clear: () => void;
24
28
  "scroll-load": () => void;
25
- send: (val: string) => void;
29
+ "ai-click": (val: string) => void;
26
30
  "update:model": (val: string) => void;
27
31
  "choose-prompt": (prompt: IPrompt) => void;
28
- }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<{
29
- messages: IMessage[];
30
- prompts?: IPrompt[] | undefined;
31
- loading?: boolean | undefined;
32
- headBackground?: string | undefined;
33
- background?: string | undefined;
34
- positionLimit?: IPositionLimit | undefined;
35
- sizeLimit?: ISize | undefined;
36
- startPosition?: IStartPosition | undefined;
37
- userPhoto?: string | undefined;
38
- name?: string | undefined;
39
- placeholder?: string | undefined;
40
- logo?: string | undefined;
41
- scrollLoading?: boolean | undefined;
42
- scrollLoadingEnd?: boolean | undefined;
43
- alert?: string | undefined;
44
- models?: IModel[] | undefined;
45
- model?: string | undefined;
46
- }>>> & {
32
+ send: (data: {
33
+ content: string;
34
+ cite?: string | undefined;
35
+ }) => void;
36
+ "update:isShow": (val: boolean) => void;
37
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<IProps>>> & {
38
+ onClose?: (() => any) | undefined;
47
39
  "onChoose-prompt"?: ((prompt: IPrompt) => any) | undefined;
48
40
  onClear?: (() => any) | undefined;
49
41
  onStop?: (() => any) | undefined;
50
- onSend?: ((val: string) => any) | undefined;
42
+ onSend?: ((data: {
43
+ content: string;
44
+ cite?: string | undefined;
45
+ }) => any) | undefined;
46
+ "onAi-click"?: ((val: string) => any) | undefined;
51
47
  "onScroll-load"?: (() => any) | undefined;
52
- onClose?: (() => any) | undefined;
53
48
  "onUpdate:model"?: ((val: string) => any) | undefined;
49
+ "onUpdate:isShow"?: ((val: boolean) => any) | undefined;
54
50
  }, {}, {}>;
55
51
  export default _default;
56
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,39 +1,40 @@
1
1
  import type { IMessage, IPrompt } from '../types/index';
2
- declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<{
2
+ interface IProps {
3
3
  messages: IMessage[];
4
- prompts?: IPrompt[] | undefined;
5
- loading?: boolean | undefined;
6
- background?: string | undefined;
7
- userPhoto?: string | undefined;
8
- placeholder?: string | undefined;
9
- scrollLoading?: boolean | undefined;
10
- scrollLoadingEnd?: boolean | undefined;
11
- alert?: string | undefined;
12
- }>, {
4
+ prompts?: IPrompt[];
5
+ loading?: boolean;
6
+ background?: string;
7
+ userPhoto?: string;
8
+ placeholder?: string;
9
+ scrollLoading?: boolean;
10
+ scrollLoadingEnd?: boolean;
11
+ alert?: string;
12
+ }
13
+ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<IProps>, {
13
14
  background: string;
14
15
  scrollLoadingEnd: boolean;
15
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
16
- send: (userInput: string) => void;
16
+ }>, {
17
+ setInputMessage: (val: string) => void;
18
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
19
+ "ai-click": (userInput: string) => void;
20
+ send: (data: {
21
+ content: string;
22
+ cite?: string | undefined;
23
+ }) => void;
17
24
  "choose-prompt": (prompt: IPrompt) => void;
18
25
  stop: () => void;
19
26
  "scroll-load": () => void;
20
- }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<{
21
- messages: IMessage[];
22
- prompts?: IPrompt[] | undefined;
23
- loading?: boolean | undefined;
24
- background?: string | undefined;
25
- userPhoto?: string | undefined;
26
- placeholder?: string | undefined;
27
- scrollLoading?: boolean | undefined;
28
- scrollLoadingEnd?: boolean | undefined;
29
- alert?: string | undefined;
30
- }>, {
27
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<IProps>, {
31
28
  background: string;
32
29
  scrollLoadingEnd: boolean;
33
30
  }>>> & {
34
31
  "onChoose-prompt"?: ((prompt: IPrompt) => any) | undefined;
35
32
  onStop?: (() => any) | undefined;
36
- onSend?: ((userInput: string) => any) | undefined;
33
+ onSend?: ((data: {
34
+ content: string;
35
+ cite?: string | undefined;
36
+ }) => any) | undefined;
37
+ "onAi-click"?: ((userInput: string) => any) | undefined;
37
38
  "onScroll-load"?: (() => any) | undefined;
38
39
  }, {
39
40
  background: string;
@@ -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,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,4 @@
1
+ export declare function useScrollShow(): {
2
+ isShow: import("vue").Ref<boolean>;
3
+ scrollToBottom: () => void;
4
+ };
@@ -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
+ };
@@ -23,5 +23,7 @@ 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";
26
28
  };
27
- export declare const t: (key: keyof typeof langData) => "BK GPT" | "shrink down" | "expand upward" | "Empty chat records" | "close" | "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" | "小鲸" | "向下收缩" | "向上扩展" | "清空聊天记录" | "关闭" | "内容正在执行中,请执行完成后再发送" | "发送" | "您可以键入 “/” 查看更多Prompt" | "请输入" | "返回最新" | "终止生成" | "向上滚动加载更多记录" | "日" | "一" | "二" | "三" | "四" | "五" | "六" | "昨天" | "本周" | "上周" | "复制成功";
29
+ 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" | "小鲸" | "向下收缩" | "向上扩展" | "清空聊天记录" | "关闭" | "内容正在执行中,请执行完成后再发送" | "发送" | "您可以键入 “/” 查看更多Prompt" | "请输入" | "返回最新" | "终止生成" | "向上滚动加载更多记录" | "日" | "一" | "二" | "三" | "四" | "五" | "六" | "昨天" | "本周" | "上周" | "复制成功" | "您选择的文本内容" | "问小鲸";
@@ -4,6 +4,7 @@ export declare enum AgentMessageType {
4
4
  }
5
5
  export declare enum RoleType {
6
6
  Assistant = "assistant",
7
+ Cite = "cite",
7
8
  System = "system",
8
9
  User = "user"
9
10
  }
@@ -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;