lke-component 2.0.0-beta.9 → 2.0.1-beta.2
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 +401 -0
- package/dist/lke-component.cjs.js +64 -62
- package/dist/lke-component.es.js +20601 -20045
- package/dist/lke-component.umd.js +66 -64
- package/dist/style.css +1 -1
- package/lib/react/msg.js +2 -0
- package/lib/react/msg.js.LICENSE.txt +10 -0
- package/lib/react/msg.min.css +9 -0
- package/package.json +6 -3
package/README.md
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
# lke-component
|
|
2
|
+
|
|
3
|
+
[English](#english) | [中文](#中文)
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<a id="english"></a>
|
|
8
|
+
|
|
9
|
+
## English
|
|
10
|
+
|
|
11
|
+
Message rendering component for LKE (Large Knowledge Engine) conversations, designed for Vue2 and React projects.
|
|
12
|
+
|
|
13
|
+
For other environments:
|
|
14
|
+
* Vue3 projects: [Link](https://www.npmjs.com/package/lke-component-vue3)
|
|
15
|
+
* React projects: [Link](#usage-in-react-projects)
|
|
16
|
+
* Mini Programs: [Link](https://www.npmjs.com/package/lke-utils)
|
|
17
|
+
|
|
18
|
+
### Components
|
|
19
|
+
|
|
20
|
+
Four components are provided: `LkeMsg`, `MsgContent`, `MsgLoading`, `MsgThought`
|
|
21
|
+
|
|
22
|
+
**MsgLoading**: Shows model loading state
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
props:
|
|
26
|
+
loadingIcon: String, // Message icon, displays if provided
|
|
27
|
+
loadingMessage: Boolean, // Whether in loading state
|
|
28
|
+
loadingText: String, // Loading message content
|
|
29
|
+
transferStatus: Boolean // Transfer to human agent status
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**MsgContent**: Renders Markdown content
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
props:
|
|
36
|
+
content: String, // Markdown message
|
|
37
|
+
isFinal: Boolean, // Whether the message output is complete
|
|
38
|
+
isReplaceLinks: Boolean, // Whether to replace links with third-party prompts
|
|
39
|
+
styleObj: Object, // Style object for MD message body
|
|
40
|
+
clazzTable: String, // Table class for MD message body (default styles will be added)
|
|
41
|
+
clazzMd: String, // Class for MD message body
|
|
42
|
+
anchorAttributes: Object, // Props passed to vue-markdown, see example
|
|
43
|
+
linkify: Boolean // Props passed to vue-markdown, see example
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**LkeMsg**: Aggregated component combining the above
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
props:
|
|
50
|
+
LoadingIcon: String, // CDN URL for loading icon, not displayed if not provided
|
|
51
|
+
type: String, // Current message type, usually 'reply' or 'token_stat'
|
|
52
|
+
isReplaceLinks: Boolean, // Whether to replace with LLM third-party link prompts
|
|
53
|
+
showProcedures: Boolean, // Whether to show model output status
|
|
54
|
+
transferStatus: Boolean, // Transfer to human agent status
|
|
55
|
+
clazz: String, // Class name for outer wrapper div
|
|
56
|
+
item: Object, // Current message content
|
|
57
|
+
styleObj: Object, // Style object for MD message body
|
|
58
|
+
clazzTable: String, // Table class for MD message body, default styles: table-style, table
|
|
59
|
+
clazzMd: String, // Class for MD message body, default style: answer-md
|
|
60
|
+
anchorAttributes: Object, // Props passed to vue-markdown, see example
|
|
61
|
+
linkify: Boolean // Props passed to vue-markdown, see example
|
|
62
|
+
printCount: Number | undefined // Characters per print for timing control
|
|
63
|
+
hideCursorPoint: Boolean | undefined // Whether to show print cursor icon
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**MsgThought**: Renders DeepSeek thinking content
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
props:
|
|
70
|
+
content: String // Thinking content
|
|
71
|
+
title: String // Title, e.g., "Thinking Complete"
|
|
72
|
+
titleIcon: String // Small icon, 16x16px
|
|
73
|
+
nodeName: String // Optional, e.g., "deepseek"
|
|
74
|
+
status: String // Thinking status: 'success', 'failed', 'processing', 'stop'
|
|
75
|
+
elapsed: number // Time spent thinking in milliseconds, e.g., 17485
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Usage in Vue2 Projects
|
|
79
|
+
|
|
80
|
+
1. Install and import
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
// Import in Vue entry file
|
|
84
|
+
import lkeComponent from 'lke-component';
|
|
85
|
+
Vue.use(lkeComponent);
|
|
86
|
+
|
|
87
|
+
// Use in Vue pages
|
|
88
|
+
<!-- Loading toggle + Markdown rendering -->
|
|
89
|
+
<LkeMsg :loadingIcon="loadingIcon" :loadingMessage="item.loading_message" :loadingText="item.text" :transferStatus="transferStatus" :isReplaceLinks="true" :content="item.content" :isFinal="item.is_final" />
|
|
90
|
+
|
|
91
|
+
<!-- Show temporary [Thinking...] message when not transferring to human -->
|
|
92
|
+
<MsgLoading :loadingIcon="loadingIcon" :loadingMessage="item.loading_message" :loadingText="item.text" :transferStatus="transferStatus" />
|
|
93
|
+
|
|
94
|
+
<!-- DeepSeek thinking content rendering -->
|
|
95
|
+
<MsgThought
|
|
96
|
+
:content="thinkingContent"
|
|
97
|
+
:title="thinkingTitle"
|
|
98
|
+
:titleIcon="test.png"
|
|
99
|
+
:nodeName="deepseek"
|
|
100
|
+
:status="success"
|
|
101
|
+
:elapsed="17485"
|
|
102
|
+
/>
|
|
103
|
+
|
|
104
|
+
<!-- Markdown rendering -->
|
|
105
|
+
<MsgContent :isReplaceLinks="true" :loadingMessage="item.loading_message" :content="item.content" :isFinal="item.is_final" :printCount="1" :hideCursorPoint="true"/>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
2. Import method
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
// Import in Vue file, e.g., component.vue
|
|
112
|
+
import { MsgLoading, MsgContent, MsgThought } from '@tencent/lke-component';
|
|
113
|
+
|
|
114
|
+
// Register components
|
|
115
|
+
export default {
|
|
116
|
+
components: {
|
|
117
|
+
MsgContent,
|
|
118
|
+
MsgLoading,
|
|
119
|
+
MsgThought,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Use in template
|
|
124
|
+
<MsgLoading :loadingIcon="loadingIcon" :loadingMessage="item.loading_message" :loadingText="item.text" :transferStatus="transferStatus" />
|
|
125
|
+
|
|
126
|
+
<!-- Markdown rendering -->
|
|
127
|
+
<MsgContent :isReplaceLinks="true" :loadingMessage="item.loading_message" :content="item.content" :isFinal="item.is_final" />
|
|
128
|
+
|
|
129
|
+
<!-- DeepSeek thinking content rendering -->
|
|
130
|
+
<MsgThought
|
|
131
|
+
:content="thinkingContent"
|
|
132
|
+
:title="thinkingTitle"
|
|
133
|
+
:titleIcon="test.png"
|
|
134
|
+
:nodeName="deepseek"
|
|
135
|
+
:status="success"
|
|
136
|
+
:elapsed="17485"
|
|
137
|
+
/>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Usage in React Projects
|
|
141
|
+
|
|
142
|
+
```jsx
|
|
143
|
+
import { MsgContent, MsgThought } from "lke-component/react";
|
|
144
|
+
import "lke-component/css";
|
|
145
|
+
|
|
146
|
+
const App = () => {
|
|
147
|
+
const [list, setList] = useState([{
|
|
148
|
+
content: "Nice weather today<b>?</b>",
|
|
149
|
+
isFinal: true,
|
|
150
|
+
loadingMessage: false,
|
|
151
|
+
isReplaceLinks: false,
|
|
152
|
+
styleObj: {},
|
|
153
|
+
clazzTable: '',
|
|
154
|
+
clazzMd: '',
|
|
155
|
+
anchorAttributes: {},
|
|
156
|
+
id: 1,
|
|
157
|
+
linkify: false,
|
|
158
|
+
thoughts: [{
|
|
159
|
+
title: "Thinking Complete",
|
|
160
|
+
titleIcon: 'test.png',
|
|
161
|
+
nodeName: "deepseek",
|
|
162
|
+
status: "success",
|
|
163
|
+
detailVisible: true,
|
|
164
|
+
elapsed: 17485,
|
|
165
|
+
content: `Okay, I need to process the user's question...`,
|
|
166
|
+
}]
|
|
167
|
+
}]);
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<div className="main">
|
|
171
|
+
{list.map((item, index) => (
|
|
172
|
+
<div>
|
|
173
|
+
{item.thoughts.map((thought, index) => (
|
|
174
|
+
<MsgThought
|
|
175
|
+
key={index}
|
|
176
|
+
detailVisible={thought.detailVisible}
|
|
177
|
+
content={thought.content}
|
|
178
|
+
title={thought.title}
|
|
179
|
+
titleIcon={thought.titleIcon}
|
|
180
|
+
nodeName={thought.nodeName}
|
|
181
|
+
status={thought.status}
|
|
182
|
+
elapsed={thought.elapsed}
|
|
183
|
+
onTitleClick={() => void 0}
|
|
184
|
+
/>
|
|
185
|
+
))}
|
|
186
|
+
</div>
|
|
187
|
+
<MsgContent
|
|
188
|
+
key={id}
|
|
189
|
+
content={item.content}
|
|
190
|
+
isFinal={item.isFinal}
|
|
191
|
+
styleObj={item.styleObj}
|
|
192
|
+
clazzTable={item.clazzTable}
|
|
193
|
+
clazzMd={item.clazzMd}
|
|
194
|
+
anchorAttributes={item.anchorAttributes}
|
|
195
|
+
linkify={item.linkify}
|
|
196
|
+
isReplaceLinks={item.isReplaceLinks}
|
|
197
|
+
/>
|
|
198
|
+
))}
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
<a id="中文"></a>
|
|
207
|
+
|
|
208
|
+
## 中文
|
|
209
|
+
|
|
210
|
+
知识引擎大模型对话消息渲染组件,适用于基于vue2和react搭建的项目。
|
|
211
|
+
|
|
212
|
+
其它项目环境参考
|
|
213
|
+
* 基于vue3的项目参考 [链接](https://www.npmjs.com/package/lke-component-vue3)
|
|
214
|
+
* 基于react的项目参考 [链接](#在react项目中使用)
|
|
215
|
+
* 小程序参考 [链接](https://www.npmjs.com/package/lke-utils)
|
|
216
|
+
|
|
217
|
+
### 组件介绍
|
|
218
|
+
|
|
219
|
+
提供四个组件:LkeMsg、MsgContent、MsgLoading、MsgThought
|
|
220
|
+
|
|
221
|
+
**MsgLoading**: 展示模型加载中的状态
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
props:
|
|
225
|
+
loadingIcon: String, // 消息的ICON,如果有话显示Icon,没有的话不会显示Icon
|
|
226
|
+
loadingMessage: Boolean, // 是否处于加载中
|
|
227
|
+
loadingText: String, // 加载中的消息内容
|
|
228
|
+
transferStatus: Boolean // 转人工状态
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**MsgContent**: 展示MD内容
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
props:
|
|
235
|
+
content: String, // MD消息
|
|
236
|
+
isFinal: Boolean, // 消息是否输出结束
|
|
237
|
+
isReplaceLinks: Boolean, // 是否替换链接为第三方提示
|
|
238
|
+
styleObj: Object, // MD消息体的style
|
|
239
|
+
clazzTable: String, // MD消息体的 table 样式 (后面会加上默认统一样式),props方便修改
|
|
240
|
+
clazzMd: String, // MD消息体的class
|
|
241
|
+
anchorAttributes: Object, // vue-markdown 的props透传,见示例
|
|
242
|
+
linkify: Boolean // vue-markdown 的props透传,见示例
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**LkeMsg**: 两个组件的聚合态
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
props:
|
|
249
|
+
LoadingIcon: String, // 加载中的图标CDN地址,如果没有传的话,默认不显示图标
|
|
250
|
+
type: String, // 当前消息的类型,type透传,一般为 reply 、 token_stat
|
|
251
|
+
isReplaceLinks: Boolean, // 是否替换为大模型的第三方链接提示
|
|
252
|
+
showProcedures: Boolean, // 是否显示模型输出的状态
|
|
253
|
+
transferStatus: Boolean, // 转人工状态
|
|
254
|
+
clazz: String, //外层包裹的div的类名
|
|
255
|
+
item: Object, // 当前的消息内容
|
|
256
|
+
styleObj: Object, // MD消息体的style
|
|
257
|
+
clazzTable: String, // MD消息体的 table 样式 (后面会加上默认统一样式),props方便修改, 组件自带默认样式:table-style、table
|
|
258
|
+
clazzMd: String, // MD消息体的class, 组件自带默认样式:answer-md
|
|
259
|
+
anchorAttributes: Object, // vue-markdown 的props透传,见示例
|
|
260
|
+
linkify: Boolean //vue-markdown 的props透传,见示例
|
|
261
|
+
printCount: Number | undefined //每次打印的字数用于控制时间
|
|
262
|
+
hideCursorPoint: Boolean | undefined //是否显示打印的图标
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**MsgThought**: 渲染deepseek 的思考内容
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
props:
|
|
269
|
+
content: String // 思考内容
|
|
270
|
+
title: String // 标题,如"思考完成"
|
|
271
|
+
titleIcon: String // 图标小图标icon 大小16x16px
|
|
272
|
+
nodeName: String // 可不填,如"deepseek"
|
|
273
|
+
status: String // 思考状态,可选值'success', 'failed', 'processing', 'stop'
|
|
274
|
+
elapsed: number // 思考花费时间, 毫秒,如17485
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### 在vue2项目里使用
|
|
278
|
+
|
|
279
|
+
1. install方式引入
|
|
280
|
+
|
|
281
|
+
```js
|
|
282
|
+
// 在vue的入口文件引入组件库
|
|
283
|
+
import lkeComponent from 'lke-component';
|
|
284
|
+
Vue.use(lkeComponent);
|
|
285
|
+
|
|
286
|
+
// 在对应的vue页面里面使用组件
|
|
287
|
+
<!-- Loading切换 + Markdown渲染 -->
|
|
288
|
+
<LkeMsg :loadingIcon="loadingIcon" :loadingMessage="item.loading_message" :loadingText="item.text" :transferStatus="transferStatus" :isReplaceLinks="true" :content="item.content" :isFinal="item.is_final" />
|
|
289
|
+
|
|
290
|
+
<!-- 非转人工情况下, 展示临时[正在思考中]消息 -->
|
|
291
|
+
<MsgLoading :loadingIcon="loadingIcon" :loadingMessage="item.loading_message" :loadingText="item.text" :transferStatus="transferStatus" />
|
|
292
|
+
|
|
293
|
+
<!-- deepseek 思考内容渲染 -->
|
|
294
|
+
<MsgThought
|
|
295
|
+
:content="思考内容"
|
|
296
|
+
:title="思考标题"
|
|
297
|
+
:titleIcon="test.png"
|
|
298
|
+
:nodeName="deepseek"
|
|
299
|
+
:status="success"
|
|
300
|
+
:elapsed="17485"
|
|
301
|
+
/>
|
|
302
|
+
|
|
303
|
+
<!-- Markdown渲染 -->
|
|
304
|
+
<MsgContent :isReplaceLinks="true" :loadingMessage="item.loading_message" :content="item.content" :isFinal="item.is_final" :printCount="1" :hideCursorPoint="true"/>
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
2. import方式引入
|
|
308
|
+
|
|
309
|
+
```js
|
|
310
|
+
// 在需要使用此组件的vue文件,比如component.vue中引入
|
|
311
|
+
import { MsgLoading, MsgContent, MsgThought } from '@tencent/lke-component';
|
|
312
|
+
|
|
313
|
+
// components中注册此组件
|
|
314
|
+
export default {
|
|
315
|
+
components: {
|
|
316
|
+
MsgContent,
|
|
317
|
+
MsgLoading,
|
|
318
|
+
MsgThought,
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// 在template标签中使用
|
|
323
|
+
<MsgLoading :loadingIcon="loadingIcon" :loadingMessage="item.loading_message" :loadingText="item.text" :transferStatus="transferStatus" />
|
|
324
|
+
|
|
325
|
+
<!-- Markdown渲染 -->
|
|
326
|
+
<MsgContent :isReplaceLinks="true" :loadingMessage="item.loading_message" :content="item.content" :isFinal="item.is_final" />
|
|
327
|
+
|
|
328
|
+
<!-- deepseek 思考内容渲染 -->
|
|
329
|
+
<MsgThought
|
|
330
|
+
:content="思考内容"
|
|
331
|
+
:title="思考标题"
|
|
332
|
+
:titleIcon="test.png"
|
|
333
|
+
:nodeName="deepseek"
|
|
334
|
+
:status="success"
|
|
335
|
+
:elapsed="17485"
|
|
336
|
+
/>
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### 在react项目中使用
|
|
340
|
+
|
|
341
|
+
```jsx
|
|
342
|
+
import { MsgContent, MsgThought } from "lke-component/react";
|
|
343
|
+
import "lke-component/css";
|
|
344
|
+
|
|
345
|
+
const App = () => {
|
|
346
|
+
const [list, setList] = useState([{
|
|
347
|
+
content: "天气不错哦<b>?</b>",
|
|
348
|
+
isFinal: true,
|
|
349
|
+
loadingMessage: false,
|
|
350
|
+
isReplaceLinks: false,
|
|
351
|
+
styleObj: {},
|
|
352
|
+
clazzTable: '',
|
|
353
|
+
clazzMd: '',
|
|
354
|
+
anchorAttributes: {},
|
|
355
|
+
id: 1,
|
|
356
|
+
linkify: false,
|
|
357
|
+
thoughts: [{
|
|
358
|
+
title: "思考完成",
|
|
359
|
+
titleIcon: 'test.png',
|
|
360
|
+
nodeName: "deepseek",
|
|
361
|
+
status: "success",
|
|
362
|
+
detailVisible: true,
|
|
363
|
+
elapsed: 17485,
|
|
364
|
+
content: `好的,我现在需要处理用户的问题...`,
|
|
365
|
+
}]
|
|
366
|
+
}]);
|
|
367
|
+
|
|
368
|
+
return (
|
|
369
|
+
<div className="main">
|
|
370
|
+
{list.map((item, index) => (
|
|
371
|
+
<div>
|
|
372
|
+
{item.thoughts.map((thought, index) => (
|
|
373
|
+
<MsgThought
|
|
374
|
+
key={index}
|
|
375
|
+
detailVisible={thought.detailVisible}
|
|
376
|
+
content={thought.content}
|
|
377
|
+
title={thought.title}
|
|
378
|
+
titleIcon={thought.titleIcon}
|
|
379
|
+
nodeName={thought.nodeName}
|
|
380
|
+
status={thought.status}
|
|
381
|
+
elapsed={thought.elapsed}
|
|
382
|
+
onTitleClick={() => void 0}
|
|
383
|
+
/>
|
|
384
|
+
))}
|
|
385
|
+
</div>
|
|
386
|
+
<MsgContent
|
|
387
|
+
key={id}
|
|
388
|
+
content={item.content}
|
|
389
|
+
isFinal={item.isFinal}
|
|
390
|
+
styleObj={item.styleObj}
|
|
391
|
+
clazzTable={item.clazzTable}
|
|
392
|
+
clazzMd={item.clazzMd}
|
|
393
|
+
anchorAttributes={item.anchorAttributes}
|
|
394
|
+
linkify={item.linkify}
|
|
395
|
+
isReplaceLinks={item.isReplaceLinks}
|
|
396
|
+
/>
|
|
397
|
+
))}
|
|
398
|
+
</div>
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
```
|