@kernelift/ai-chat 3.0.3 → 3.0.5
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/CHANGELOG.md +17 -0
- package/README.md +72 -75
- package/dist/ai-chat.css +1 -1
- package/dist/index.d.ts +31 -6
- package/dist/index.js +4956 -4894
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @kernelift/ai-chat
|
|
2
2
|
|
|
3
|
+
## 3.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 修复一些打包的基础性问题
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @kernelift/utils@1.0.6
|
|
10
|
+
- @kernelift/markdown@1.2.3
|
|
11
|
+
|
|
12
|
+
## 3.0.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 添加rendered函数
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
- @kernelift/markdown@1.2.2
|
|
19
|
+
|
|
3
20
|
## 3.0.3
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @gci/ai-chat
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/%40gci%2Fai-chat)
|
|
4
4
|
[](https://opensource.org/licenses/GPL-3.0)
|
|
5
5
|
|
|
6
|
-
在线预览地址: https://
|
|
6
|
+
- 在线预览地址: https://gci-labs.github.io/playground/#/ai-chat
|
|
7
|
+
- demo工程: https://github.com/gci-labs/playground
|
|
7
8
|
|
|
8
9
|
基于 Vue 3 + TypeScript 的现代化 AI 聊天框组件,提供企业级的对话界面解决方案。无UI库绑定。
|
|
9
10
|
|
|
@@ -27,20 +28,20 @@
|
|
|
27
28
|
|
|
28
29
|
```bash
|
|
29
30
|
# 使用 pnpm
|
|
30
|
-
pnpm add @
|
|
31
|
+
pnpm add @gci/ai-chat
|
|
31
32
|
|
|
32
33
|
# 使用 npm
|
|
33
|
-
npm install @
|
|
34
|
+
npm install @gci/ai-chat
|
|
34
35
|
|
|
35
36
|
# 使用 yarn
|
|
36
|
-
yarn add @
|
|
37
|
+
yarn add @gci/ai-chat
|
|
37
38
|
```
|
|
38
39
|
|
|
39
40
|
### 依赖要求
|
|
40
41
|
|
|
41
42
|
- Vue 3.3+
|
|
42
43
|
- TypeScript 5.0+
|
|
43
|
-
- @
|
|
44
|
+
- @gci/markdown (workspace:\*)
|
|
44
45
|
|
|
45
46
|
## 🚀 快速开始
|
|
46
47
|
|
|
@@ -48,7 +49,7 @@ yarn add @kernelift/ai-chat
|
|
|
48
49
|
|
|
49
50
|
```vue
|
|
50
51
|
<template>
|
|
51
|
-
<
|
|
52
|
+
<AiChat
|
|
52
53
|
v-model:messages="messages"
|
|
53
54
|
v-model:inputText="inputText"
|
|
54
55
|
v-model:loading="loading"
|
|
@@ -60,9 +61,9 @@ yarn add @kernelift/ai-chat
|
|
|
60
61
|
|
|
61
62
|
<script setup>
|
|
62
63
|
import { ref } from 'vue'
|
|
63
|
-
import {
|
|
64
|
-
import '@
|
|
65
|
-
import type { ChatMessage, ChatRecord, BubbleEvent } from '@
|
|
64
|
+
import { AiChat } from '@gci/ai-chat'
|
|
65
|
+
import '@gci/ai-chat/style.css'
|
|
66
|
+
import type { ChatMessage, ChatRecord, BubbleEvent } from '@gci/ai-chat'
|
|
66
67
|
|
|
67
68
|
const messages = ref<ChatMessage[]>([])
|
|
68
69
|
const inputText = ref('')
|
|
@@ -94,7 +95,7 @@ const handleBubbleEvent = (eventName: BubbleEvent, data: ChatMessage) => {
|
|
|
94
95
|
### 组件层次结构
|
|
95
96
|
|
|
96
97
|
```
|
|
97
|
-
|
|
98
|
+
AiChat (主容器)
|
|
98
99
|
├── ChatSidebar (侧边栏)
|
|
99
100
|
│ ├── Logo 区域
|
|
100
101
|
│ ├── 新建聊天按钮
|
|
@@ -127,13 +128,13 @@ ChatContainer (主容器)
|
|
|
127
128
|
|
|
128
129
|
## 🧩 组件详解
|
|
129
130
|
|
|
130
|
-
###
|
|
131
|
+
### AiChat - 主容器
|
|
131
132
|
|
|
132
133
|
主容器组件,负责整体布局和状态管理。
|
|
133
134
|
|
|
134
135
|
```vue
|
|
135
136
|
<template>
|
|
136
|
-
<
|
|
137
|
+
<AiChat
|
|
137
138
|
v-model:messages="messages"
|
|
138
139
|
v-model:inputText="inputText"
|
|
139
140
|
v-model:loading="loading"
|
|
@@ -153,7 +154,7 @@ ChatContainer (主容器)
|
|
|
153
154
|
@change-theme="handleThemeChange"
|
|
154
155
|
>
|
|
155
156
|
<!-- 插槽内容 -->
|
|
156
|
-
</
|
|
157
|
+
</AiChat>
|
|
157
158
|
</template>
|
|
158
159
|
```
|
|
159
160
|
|
|
@@ -333,7 +334,7 @@ ChatContainer (主容器)
|
|
|
333
334
|
|
|
334
335
|
```vue
|
|
335
336
|
<template>
|
|
336
|
-
<
|
|
337
|
+
<AiChat
|
|
337
338
|
v-model:messages="messages"
|
|
338
339
|
:i18n="{
|
|
339
340
|
chat: {
|
|
@@ -363,7 +364,7 @@ ChatContainer (主容器)
|
|
|
363
364
|
|
|
364
365
|
```vue
|
|
365
366
|
<template>
|
|
366
|
-
<
|
|
367
|
+
<AiChat
|
|
367
368
|
v-model:messages="messages"
|
|
368
369
|
:auto-scroll="true"
|
|
369
370
|
:auto-scroll-pause-time="3000"
|
|
@@ -392,7 +393,7 @@ ChatContainer (主容器)
|
|
|
392
393
|
|
|
393
394
|
```vue
|
|
394
395
|
<template>
|
|
395
|
-
<
|
|
396
|
+
<AiChat
|
|
396
397
|
v-model:messages="messages"
|
|
397
398
|
:show-sender="true"
|
|
398
399
|
:has-sender-tools="true"
|
|
@@ -564,7 +565,7 @@ const handleDeleteRecord = (record: ChatRecord) => {
|
|
|
564
565
|
### 流式消息处理
|
|
565
566
|
|
|
566
567
|
```typescript
|
|
567
|
-
import { SSEClient } from '@
|
|
568
|
+
import { SSEClient } from '@gci/ai-chat';
|
|
568
569
|
|
|
569
570
|
const handleStreamResponse = async (question: string, enableThink?: boolean) => {
|
|
570
571
|
const client = new SSEClient('your-token', 'https://api.example.com');
|
|
@@ -675,7 +676,7 @@ const handleStreamResponse = async (question: string, enableThink?: boolean) =>
|
|
|
675
676
|
|
|
676
677
|
```scss
|
|
677
678
|
// 自定义主题
|
|
678
|
-
.
|
|
679
|
+
.gci-chat-container {
|
|
679
680
|
// 主容器样式
|
|
680
681
|
border-radius: 16px;
|
|
681
682
|
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
|
@@ -701,7 +702,7 @@ const handleStreamResponse = async (question: string, enableThink?: boolean) =>
|
|
|
701
702
|
|
|
702
703
|
// 自定义消息气泡
|
|
703
704
|
.custom-chat-bubble {
|
|
704
|
-
.
|
|
705
|
+
.gci-chat-bubble__assistant {
|
|
705
706
|
background: linear-gradient(135deg, #ffffff 0%, #f0f4ff 100%);
|
|
706
707
|
border: 1px solid #e1e8ff;
|
|
707
708
|
border-radius: 12px;
|
|
@@ -711,7 +712,7 @@ const handleStreamResponse = async (question: string, enableThink?: boolean) =>
|
|
|
711
712
|
}
|
|
712
713
|
}
|
|
713
714
|
|
|
714
|
-
.
|
|
715
|
+
.gci-chat-bubble__user {
|
|
715
716
|
&-content {
|
|
716
717
|
background: linear-gradient(135deg, var(--kl-chat-primary-color) 0%, #8a86f1 100%);
|
|
717
718
|
color: white;
|
|
@@ -726,7 +727,7 @@ const handleStreamResponse = async (question: string, enableThink?: boolean) =>
|
|
|
726
727
|
|
|
727
728
|
// 自定义发送器
|
|
728
729
|
.custom-chat-sender {
|
|
729
|
-
.
|
|
730
|
+
.gci-chat-sender__textarea {
|
|
730
731
|
border-radius: 8px;
|
|
731
732
|
border: 2px solid var(--kl-border-color);
|
|
732
733
|
|
|
@@ -736,7 +737,7 @@ const handleStreamResponse = async (question: string, enableThink?: boolean) =>
|
|
|
736
737
|
}
|
|
737
738
|
}
|
|
738
739
|
|
|
739
|
-
.
|
|
740
|
+
.gci-chat-sender__send-button {
|
|
740
741
|
background: linear-gradient(135deg, var(--kl-chat-primary-color) 0%, #8a86f1 100%);
|
|
741
742
|
border-radius: 8px;
|
|
742
743
|
|
|
@@ -780,7 +781,7 @@ const handleStreamResponse = async (question: string, enableThink?: boolean) =>
|
|
|
780
781
|
animation: slideInFromRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
781
782
|
}
|
|
782
783
|
|
|
783
|
-
.
|
|
784
|
+
.gci-chat-bubble {
|
|
784
785
|
margin: 8px 12px;
|
|
785
786
|
|
|
786
787
|
&__actions {
|
|
@@ -800,9 +801,9 @@ const handleStreamResponse = async (question: string, enableThink?: boolean) =>
|
|
|
800
801
|
<!-- eslint-disable @typescript-eslint/no-explicit-any -->
|
|
801
802
|
<script setup lang="ts">
|
|
802
803
|
import { ref, watch, onMounted, nextTick } from 'vue';
|
|
803
|
-
import {
|
|
804
|
+
import { AiChat } from '@gci/ai-chat';
|
|
804
805
|
import { useChat } from './use-chat';
|
|
805
|
-
import '@
|
|
806
|
+
import '@gci/ai-chat/style.css';
|
|
806
807
|
import { CHAT_BASE_URL, CHAT_DEFAULT_MODEL } from './constants';
|
|
807
808
|
import Button from 'primevue/button';
|
|
808
809
|
import Textarea from 'primevue/textarea';
|
|
@@ -958,7 +959,7 @@ onMounted(() => {
|
|
|
958
959
|
|
|
959
960
|
<template>
|
|
960
961
|
<div class="w-full h-full relative">
|
|
961
|
-
<
|
|
962
|
+
<AiChat
|
|
962
963
|
v-model="userQuestion"
|
|
963
964
|
v-model:loading="senderLoading"
|
|
964
965
|
v-model:messages="chatMessages"
|
|
@@ -1191,7 +1192,7 @@ onMounted(() => {
|
|
|
1191
1192
|
@click="toggleSpeech"
|
|
1192
1193
|
/>
|
|
1193
1194
|
</template>
|
|
1194
|
-
</
|
|
1195
|
+
</AiChat>
|
|
1195
1196
|
|
|
1196
1197
|
<Dialog
|
|
1197
1198
|
v-if="editRecord"
|
|
@@ -1454,12 +1455,7 @@ onMounted(() => {
|
|
|
1454
1455
|
|
|
1455
1456
|
```ts
|
|
1456
1457
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1457
|
-
import type {
|
|
1458
|
-
BubbleEventAction,
|
|
1459
|
-
ChatMessage,
|
|
1460
|
-
ChatRecord,
|
|
1461
|
-
ChatRecordAction
|
|
1462
|
-
} from '@kernelift/ai-chat';
|
|
1458
|
+
import type { BubbleEventAction, ChatMessage, ChatRecord, ChatRecordAction } from '@gci/ai-chat';
|
|
1463
1459
|
import { formatDate, useAsyncState, useStorage } from '@vueuse/core';
|
|
1464
1460
|
import { useConfirm } from 'primevue/useconfirm';
|
|
1465
1461
|
import { useToast } from 'primevue/usetoast';
|
|
@@ -2156,7 +2152,7 @@ export const useChat = (options: {
|
|
|
2156
2152
|
|
|
2157
2153
|
```scss
|
|
2158
2154
|
// 自定义主题
|
|
2159
|
-
.
|
|
2155
|
+
.gci-chat-container {
|
|
2160
2156
|
// 修改主容器样式
|
|
2161
2157
|
border-radius: 16px;
|
|
2162
2158
|
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
|
@@ -2174,12 +2170,12 @@ export const useChat = (options: {
|
|
|
2174
2170
|
|
|
2175
2171
|
// 自定义消息气泡
|
|
2176
2172
|
.custom-chat-bubble {
|
|
2177
|
-
.
|
|
2173
|
+
.gci-chat-bubble__assistant {
|
|
2178
2174
|
background: linear-gradient(135deg, #ffffff 0%, #f0f4ff 100%);
|
|
2179
2175
|
border: 1px solid #e1e8ff;
|
|
2180
2176
|
}
|
|
2181
2177
|
|
|
2182
|
-
.
|
|
2178
|
+
.gci-chat-bubble__user {
|
|
2183
2179
|
&-content {
|
|
2184
2180
|
background: linear-gradient(135deg, var(--kl-chat-primary-color) 0%, #8a86f1 100%);
|
|
2185
2181
|
color: white;
|
|
@@ -2190,41 +2186,42 @@ export const useChat = (options: {
|
|
|
2190
2186
|
|
|
2191
2187
|
### Props 属性
|
|
2192
2188
|
|
|
2193
|
-
| 属性名
|
|
2194
|
-
|
|
|
2195
|
-
| `records`
|
|
2196
|
-
| `recordActions`
|
|
2197
|
-
| `bubbleExtEvents`
|
|
2198
|
-
| `hasHeader`
|
|
2199
|
-
| `headerHeight`
|
|
2200
|
-
| `hasThemeMode`
|
|
2201
|
-
| `hasThinking`
|
|
2202
|
-
| `hasNetSearch`
|
|
2203
|
-
| `hasSenderTools`
|
|
2204
|
-
| `alwaysShowSenderTools`
|
|
2205
|
-
| `showWorkspace`
|
|
2206
|
-
| `showSender`
|
|
2207
|
-
| `isGenerateLoading`
|
|
2208
|
-
| `defaultRecordId`
|
|
2209
|
-
| `defaultCollapse`
|
|
2210
|
-
| `defaultAsideWidth`
|
|
2211
|
-
| `markdownClassName`
|
|
2212
|
-
| `primaryColor`
|
|
2213
|
-
| `themeMode`
|
|
2214
|
-
| `enableNet`
|
|
2215
|
-
| `enableThink`
|
|
2216
|
-
| `disabledCreateRecord`
|
|
2217
|
-
| `inputHeight`
|
|
2218
|
-
| `defaultInputHeight`
|
|
2219
|
-
| `onCopy`
|
|
2220
|
-
| `i18n`
|
|
2221
|
-
| `autoScroll`
|
|
2222
|
-
| `autoScrollPauseTime`
|
|
2223
|
-
| `uuid`
|
|
2224
|
-
| `markdownPlugins`
|
|
2225
|
-
| `markdownOptions`
|
|
2226
|
-
| `markdownRender`
|
|
2227
|
-
| `onMarkdownAfterRender`
|
|
2189
|
+
| 属性名 | 类型 | 默认值 | 说明 |
|
|
2190
|
+
| ----------------------------- | ------------------------ | ----------- | -------------------------------------------------- |
|
|
2191
|
+
| `records` | `ChatRecord[]` | `[]` | 聊天记录列表 |
|
|
2192
|
+
| `recordActions` | `ChatRecordAction[]` | `[]` | 记录操作按钮配置 |
|
|
2193
|
+
| `bubbleExtEvents` | `BubbleEventAction[]` | `[]` | 气泡扩展事件配置 |
|
|
2194
|
+
| `hasHeader` | `boolean` | `true` | 是否显示头部 |
|
|
2195
|
+
| `headerHeight` | `number` | `38` | 头部高度 (px) |
|
|
2196
|
+
| `hasThemeMode` | `boolean` | `false` | 是否支持主题切换 |
|
|
2197
|
+
| `hasThinking` | `boolean` | `true` | 是否支持深度思考 |
|
|
2198
|
+
| `hasNetSearch` | `boolean` | `false` | 是否支持联网搜索 |
|
|
2199
|
+
| `hasSenderTools` | `boolean` | `false` | 是否显示发送工具区 |
|
|
2200
|
+
| `alwaysShowSenderTools` | `boolean` | `false` | 是否始终显示发送工具区(即使 showSender 为 false) |
|
|
2201
|
+
| `showWorkspace` | `boolean` | `true` | 是否显示工作区 |
|
|
2202
|
+
| `showSender` | `boolean` | `true` | 是否显示发送框 |
|
|
2203
|
+
| `isGenerateLoading` | `boolean` | `undefined` | 是否正在生成 |
|
|
2204
|
+
| `defaultRecordId` | `string` | `undefined` | 默认记录ID |
|
|
2205
|
+
| `defaultCollapse` | `boolean` | `false` | 侧边栏默认折叠 |
|
|
2206
|
+
| `defaultAsideWidth` | `number` | `250` | 侧边栏默认宽度 |
|
|
2207
|
+
| `markdownClassName` | `string` | `undefined` | Markdown 样式类名 |
|
|
2208
|
+
| `primaryColor` | `string` | `'#615ced'` | 主题色 |
|
|
2209
|
+
| `themeMode` | `'light' \| 'dark'` | `'light'` | 主题模式 |
|
|
2210
|
+
| `enableNet` | `boolean` | `undefined` | 联网搜索启用状态 |
|
|
2211
|
+
| `enableThink` | `boolean` | `undefined` | 深度思考启用状态 |
|
|
2212
|
+
| `disabledCreateRecord` | `boolean` | `false` | 是否禁用新建聊天记录 |
|
|
2213
|
+
| `inputHeight` | `number` | `140` | 输入框最大高度 (px) |
|
|
2214
|
+
| `defaultInputHeight` | `number` | `62` | 输入框初始默认高度 (px) |
|
|
2215
|
+
| `onCopy` | `(code: string) => void` | `undefined` | 复制代码回调 |
|
|
2216
|
+
| `i18n` | `Record<string, any>` | `zhCN` | 国际化配置 |
|
|
2217
|
+
| `autoScroll` | `boolean` | `true` | 是否自动滚动到底部 |
|
|
2218
|
+
| `autoScrollPauseTime` | `number` | `3000` | 用户滚动时自动滚动暂停时间 (ms) |
|
|
2219
|
+
| `uuid` | `string` | `'default'` | 实例唯一标识,用于存储状态 |
|
|
2220
|
+
| `markdownPlugins` | `any[]` | `[]` | Markdown 插件列表 |
|
|
2221
|
+
| `markdownOptions` | `any` | `{}` | Markdown 配置选项 |
|
|
2222
|
+
| `markdownRender` | `Component` | `MdRender` | 自定义 markdown 渲染组件 |
|
|
2223
|
+
| `onMarkdownAfterRender` | `(md: any) => void` | `undefined` | Markdown 渲染后回调 |
|
|
2224
|
+
| `disabledMarkdownIncremental` | `boolean` | `false` | 是否禁用Markdown增量渲染功能,默认开启 |
|
|
2228
2225
|
|
|
2229
2226
|
### v-model 双向绑定
|
|
2230
2227
|
|
|
@@ -2361,7 +2358,7 @@ interface ChatRecordAction {
|
|
|
2361
2358
|
A: 通过 `primary-color` 属性和 CSS 变量可以自定义主题色:
|
|
2362
2359
|
|
|
2363
2360
|
```vue
|
|
2364
|
-
<
|
|
2361
|
+
<AiChat primary-color="#ff6b6b" />
|
|
2365
2362
|
```
|
|
2366
2363
|
|
|
2367
2364
|
```css
|
|
@@ -2406,7 +2403,7 @@ const handleSend = async (text: string) => {
|
|
|
2406
2403
|
A: 使用内置的 SSEClient 或其他流式处理方案:
|
|
2407
2404
|
|
|
2408
2405
|
```typescript
|
|
2409
|
-
import { SSEClient } from '@
|
|
2406
|
+
import { SSEClient } from '@gci/ai-chat';
|
|
2410
2407
|
|
|
2411
2408
|
const handleStreamResponse = async (question: string) => {
|
|
2412
2409
|
const client = new SSEClient('token', 'https://api.example.com');
|