ai-chat-ui-kit 0.1.0

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.
Files changed (95) hide show
  1. package/.eslintrc.cjs +74 -0
  2. package/.github/actions/screenshot/action.yml +35 -0
  3. package/.github/workflows/pages.yml +46 -0
  4. package/README.md +285 -0
  5. package/docs/README.md +176 -0
  6. package/docs/api/components.md +344 -0
  7. package/docs/api/core.md +349 -0
  8. package/docs/chat-style-1-minimal.html +78 -0
  9. package/docs/chat-style-2-neon.html +74 -0
  10. package/docs/chat-style-3-glass.html +73 -0
  11. package/docs/chat-style-4-terminal.html +84 -0
  12. package/docs/chat-style-5-gradient.html +69 -0
  13. package/docs/chat-style-6-corporate.html +116 -0
  14. package/docs/examples/basic-chat.md +291 -0
  15. package/docs/examples/custom-plugins.md +431 -0
  16. package/docs/examples/multi-model.md +466 -0
  17. package/docs/guide/api-adapters.md +431 -0
  18. package/docs/guide/getting-started.md +244 -0
  19. package/docs/guide/headless-mode.md +508 -0
  20. package/docs/guide/plugins.md +416 -0
  21. package/docs/guide/themes.md +327 -0
  22. package/docs/index.html +256 -0
  23. package/docs/theme-preview-1-minimal.html +74 -0
  24. package/docs/theme-preview-2-neon.html +73 -0
  25. package/docs/theme-preview-3-glass.html +77 -0
  26. package/docs/theme-preview-4-terminal.html +86 -0
  27. package/docs/theme-preview-5-gradient.html +79 -0
  28. package/docs/theme-preview-6-corporate.html +71 -0
  29. package/examples/index.html +414 -0
  30. package/examples/react-app/App.tsx +131 -0
  31. package/examples/react-app/index.html +12 -0
  32. package/examples/react-app/main.tsx +15 -0
  33. package/examples/react-app/package.json +24 -0
  34. package/examples/vue-app/index.html +12 -0
  35. package/examples/vue-app/package.json +22 -0
  36. package/examples/vue-app/src/App.vue +145 -0
  37. package/examples/vue-app/src/main.ts +9 -0
  38. package/package.json +44 -0
  39. package/packages/components/package.json +25 -0
  40. package/packages/components/src/chat/chat.css +80 -0
  41. package/packages/components/src/chat/chat.ts +236 -0
  42. package/packages/components/src/index.ts +36 -0
  43. package/packages/components/src/input/input.css +52 -0
  44. package/packages/components/src/input/input.ts +116 -0
  45. package/packages/components/src/markdown/markdown.css +118 -0
  46. package/packages/components/src/markdown/markdown.ts +229 -0
  47. package/packages/components/src/message/message.css +56 -0
  48. package/packages/components/src/message/message.ts +72 -0
  49. package/packages/components/src/styles/global.css +43 -0
  50. package/packages/components/src/tool-call/tool-call.css +98 -0
  51. package/packages/components/src/tool-call/tool-call.ts +171 -0
  52. package/packages/components/src/types.ts +55 -0
  53. package/packages/components/src/utils/helpers.ts +128 -0
  54. package/packages/components/tsconfig.json +25 -0
  55. package/packages/components/tsup.config.ts +18 -0
  56. package/packages/core/package.json +47 -0
  57. package/packages/core/pnpm-lock.yaml +2032 -0
  58. package/packages/core/pnpm-workspace.yaml +2 -0
  59. package/packages/core/src/api/adapters.ts +717 -0
  60. package/packages/core/src/api/base.ts +210 -0
  61. package/packages/core/src/api/index.ts +54 -0
  62. package/packages/core/src/index.ts +93 -0
  63. package/packages/core/src/parser/latex.ts +274 -0
  64. package/packages/core/src/parser/markdown.test.ts +58 -0
  65. package/packages/core/src/parser/markdown.ts +206 -0
  66. package/packages/core/src/parser/mermaid.ts +276 -0
  67. package/packages/core/src/plugins/PluginManager.ts +232 -0
  68. package/packages/core/src/plugins/builtin.ts +406 -0
  69. package/packages/core/src/store/ChatStore.ts +163 -0
  70. package/packages/core/src/store/ModelConfigStore.ts +136 -0
  71. package/packages/core/src/store/ToolCallStore.ts +164 -0
  72. package/packages/core/src/store/base.ts +75 -0
  73. package/packages/core/src/types/index.ts +133 -0
  74. package/packages/core/tsup.config.ts +18 -0
  75. package/packages/themes/package.json +33 -0
  76. package/packages/themes/src/corporate/index.ts +52 -0
  77. package/packages/themes/src/corporate/theme.css +228 -0
  78. package/packages/themes/src/glass/index.ts +52 -0
  79. package/packages/themes/src/glass/theme.css +237 -0
  80. package/packages/themes/src/gradient/index.ts +53 -0
  81. package/packages/themes/src/gradient/theme.css +218 -0
  82. package/packages/themes/src/index.ts +13 -0
  83. package/packages/themes/src/minimal/index.ts +52 -0
  84. package/packages/themes/src/minimal/theme.css +198 -0
  85. package/packages/themes/src/neon/index.ts +52 -0
  86. package/packages/themes/src/neon/theme.css +233 -0
  87. package/packages/themes/src/terminal/index.ts +52 -0
  88. package/packages/themes/src/terminal/theme.css +235 -0
  89. package/packages/themes/src/types.ts +10 -0
  90. package/packages/themes/src/vite-env.d.ts +9 -0
  91. package/packages/themes/tsup.config.ts +21 -0
  92. package/pnpm-workspace.yaml +4 -0
  93. package/tsconfig.json +27 -0
  94. package/vite.config.ts +25 -0
  95. package/vitest.config.ts +28 -0
package/.eslintrc.cjs ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @generated-by AI: edenxpzhang
3
+ * @generated-date 2026-05-13
4
+ */
5
+
6
+ module.exports = {
7
+ root: true,
8
+ env: {
9
+ browser: true,
10
+ es2020: true,
11
+ node: true,
12
+ },
13
+ parser: '@typescript-eslint/parser',
14
+ parserOptions: {
15
+ ecmaVersion: 2020,
16
+ sourceType: 'module',
17
+ ecmaFeatures: {
18
+ jsx: true,
19
+ tsx: true,
20
+ },
21
+ },
22
+ plugins: ['@typescript-eslint'],
23
+ extends: [
24
+ 'eslint:recommended',
25
+ 'plugin:@typescript-eslint/recommended',
26
+ ],
27
+ rules: {
28
+ // TypeScript specific rules
29
+ '@typescript-eslint/no-explicit-any': 'warn',
30
+ '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
31
+ '@typescript-eslint/explicit-function-return-type': 'off',
32
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
33
+ '@typescript-eslint/no-non-null-assertion': 'warn',
34
+ '@typescript-eslint/consistent-type-imports': 'error',
35
+
36
+ // General rules
37
+ 'no-console': ['warn', { allow: ['warn', 'error', 'info'] }],
38
+ 'no-debugger': 'error',
39
+ 'no-alert': 'warn',
40
+ 'no-restricted-syntax': 'off',
41
+
42
+ // Import rules
43
+ 'no-unused-vars': 'off', // Handled by @typescript-eslint
44
+ },
45
+ overrides: [
46
+ // Lit component rules
47
+ {
48
+ files: ['*.ts'],
49
+ excludedFiles: ['*.test.ts', '*.spec.ts'],
50
+ rules: {
51
+ 'class-methods-use-this': 'off',
52
+ },
53
+ },
54
+ // Test files
55
+ {
56
+ files: ['*.test.ts', '*.spec.ts', '**/tests/**/*.ts'],
57
+ env: {
58
+ jest: true,
59
+ },
60
+ rules: {
61
+ '@typescript-eslint/no-explicit-any': 'off',
62
+ },
63
+ },
64
+ ],
65
+ ignorePatterns: [
66
+ 'dist/',
67
+ 'node_modules/',
68
+ '*.config.js',
69
+ '*.config.cjs',
70
+ 'build/',
71
+ 'coverage/',
72
+ '.turbo/',
73
+ ],
74
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @generated-by AI: edenxpzhang
3
+ * @generated-date 2026-05-13
4
+ */
5
+ name: Generate Theme Screenshots
6
+ description: Take screenshots of all 6 chat UI themes
7
+
8
+ inputs:
9
+ output-dir:
10
+ description: Directory to save screenshots
11
+ required: false
12
+ default: docs/screenshots
13
+
14
+ runs:
15
+ using: composite
16
+ steps:
17
+ - name: Install Playwright
18
+ shell: bash
19
+ run: |
20
+ npm install -g playwright
21
+ playwright install chromium
22
+
23
+ - name: Take screenshots
24
+ shell: bash
25
+ run: |
26
+ mkdir -p ${{ inputs.output-dir }}
27
+ for theme in minimal neon glass terminal gradient corporate; do
28
+ echo "Screenshotting ${theme}..."
29
+ playwright screenshot \
30
+ --url "file://$(pwd)/docs/chat-style-${theme}.html" \
31
+ --output "${{ inputs.output-dir }}/${theme}.png" \
32
+ --viewport "400,700" \
33
+ --timeout 10000 || true
34
+ done
35
+ echo "Screenshots saved to ${{ inputs.output-dir }}/"
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @generated-by AI: edenxpzhang
3
+ * @generated-date 2026-05-13
4
+ */
5
+ name: Deploy to GitHub Pages
6
+
7
+ on:
8
+ push:
9
+ branches: [master]
10
+ workflow_dispatch:
11
+
12
+ permissions:
13
+ contents: read
14
+ pages: write
15
+ id-token: write
16
+
17
+ concurrency:
18
+ group: pages
19
+ cancel-in-progress: true
20
+
21
+ jobs:
22
+ deploy:
23
+ environment:
24
+ name: github-pages
25
+ url: ${{ steps.deployment.outputs.page_url }}
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - name: Checkout
29
+ uses: actions/checkout@v4
30
+
31
+ - name: Setup Node.js
32
+ uses: actions/setup-node@v4
33
+ with:
34
+ node-version: 20
35
+
36
+ - name: Generate screenshots
37
+ uses: .github/actions/screenshot
38
+
39
+ - name: Upload artifact
40
+ uses: actions/upload-pages-artifact@v3
41
+ with:
42
+ path: ./docs
43
+
44
+ - name: Deploy to GitHub Pages
45
+ id: deployment
46
+ uses: actions/deploy-pages@v4
package/README.md ADDED
@@ -0,0 +1,285 @@
1
+ /**
2
+ * @generated-by AI: edenxpzhang
3
+ * @generated-date 2026-05-13
4
+ */
5
+ # AI Chat UI Kit
6
+
7
+ ![Version](https://img.shields.io/badge/version-0.1.0-blue.svg)
8
+ ![License](https://img.shields.io/badge/license-MIT-green.svg)
9
+ ![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)
10
+ ![Lit](https://img.shields.io/badge/Lit-3.0-orange.svg)
11
+ ![Live Demo](https://img.shields.io/badge/Live%20Demo-GitHub%20Pages-blue?logo=github)
12
+
13
+ 一套基于 Web Components 的 AI 聊天 UI 组件库,支持 Headless 模式,可跨框架使用(React、Vue、原生 HTML)。
14
+
15
+ ## ✨ 在线预览
16
+
17
+ 🎉 **[点击这里查看在线 Demo](https://edenxpzhang.github.io/ai-chat-ui-kit/)**(部署后自动生效)
18
+
19
+ ## 🎨 6 套主题预览
20
+
21
+ | 序号 | 主题 | 风格 | 预览 |
22
+ |------|------|------|------|
23
+ | 01 | **Minimal Clean** | 极简苹果风,圆角气泡、蓝白配色 | [在线预览](docs/chat-style-1-minimal.html) |
24
+ | 02 | **Dark Neon** | 赛博朋克深色,霓虹发光效果 | [在线预览](docs/chat-style-2-neon.html) |
25
+ | 03 | **Glassmorphism** | 毛玻璃拟态,半透明模糊 | [在线预览](docs/chat-style-3-glass.html) |
26
+ | 04 | **Retro Terminal** | 复古终端,绿绿配色 + 扫描线 | [在线预览](docs/chat-style-4-terminal.html) |
27
+ | 05 | **Gradient Bubbles** | 多彩渐变气泡,弹出动画 | [在线预览](docs/chat-style-5-gradient.html) |
28
+ | 06 | **Corporate Professional** | 企业商务风,蓝色主题 | [在线预览](docs/chat-style-6-corporate.html) |
29
+
30
+ > 💡 也可访问 [主题总览页](docs/index.html) 一次性查看所有主题。
31
+
32
+ ## ✨ 特性
33
+
34
+ - 🚀 **基于 Web Components** - 原生组件,跨框架兼容
35
+ - 🎨 **Headless 模式** - 可只使用逻辑层,自定义 UI
36
+ - 🎭 **6 套主题** - Minimal / Neon / Glass / Terminal / Gradient / Corporate
37
+ - 🔌 **插件系统** - 易于扩展功能
38
+ - 🌐 **API 适配器** - 兼容多种后端 API 格式
39
+ - 🎯 **TypeScript 支持** - 完整的类型定义
40
+ - 📦 **轻量级** - 无 heavy dependencies
41
+
42
+ ## 📦 安装
43
+
44
+ ### 使用 PNPM(推荐)
45
+ ```bash
46
+ pnpm add @ai-chat/core @ai-chat/components @ai-chat/themes
47
+ ```
48
+
49
+ ### 使用 NPM
50
+ ```bash
51
+ npm install @ai-chat/core @ai-chat/components @ai-chat/themes
52
+ ```
53
+
54
+ ### 使用 Yarn
55
+ ```bash
56
+ yarn add @ai-chat/core @ai-chat/components @ai-chat/themes
57
+ ```
58
+
59
+ ## 🚀 快速开始
60
+
61
+ ### 原生 HTML 使用
62
+
63
+ ```html
64
+ <!DOCTYPE html>
65
+ <html lang="zh-CN">
66
+ <head>
67
+ <meta charset="UTF-8">
68
+ <title>AI Chat Demo</title>
69
+ <script type="module">
70
+ import '@ai-chat/components';
71
+ import '@ai-chat/themes';
72
+ </script>
73
+ <style>
74
+ html, body {
75
+ margin: 0;
76
+ padding: 0;
77
+ height: 100%;
78
+ }
79
+ #app {
80
+ height: 100vh;
81
+ }
82
+ </style>
83
+ </head>
84
+ <body>
85
+ <div id="app">
86
+ <ai-chat></ai-chat>
87
+ </div>
88
+
89
+ <script>
90
+ const chat = document.querySelector('ai-chat');
91
+
92
+ // 设置 AI 回复回调
93
+ chat.setMessageHandler(async (message) => {
94
+ // 模拟 AI 回复
95
+ await new Promise(resolve => setTimeout(resolve, 1000));
96
+ return `您说的是:${message}`;
97
+ });
98
+ </script>
99
+ </body>
100
+ </html>
101
+ ```
102
+
103
+ ### React 使用
104
+
105
+ ```tsx
106
+ import React, { useEffect, useRef } from 'react';
107
+ import '@ai-chat/components';
108
+ import '@ai-chat/themes';
109
+
110
+ const ChatApp: React.FC = () => {
111
+ const chatRef = useRef<HTMLElement>(null);
112
+
113
+ useEffect(() => {
114
+ if (chatRef.current) {
115
+ (chatRef.current as any).setMessageHandler(async (message: string) => {
116
+ await new Promise(resolve => setTimeout(resolve, 1000));
117
+ return `AI 回复:${message}`;
118
+ });
119
+ }
120
+ }, []);
121
+
122
+ return (
123
+ <div style={{ height: '100vh' }}>
124
+ <ai-chat ref={chatRef}></ai-chat>
125
+ </div>
126
+ );
127
+ };
128
+
129
+ export default ChatApp;
130
+ ```
131
+
132
+ ### Vue 3 使用
133
+
134
+ ```vue
135
+ <template>
136
+ <div style="height: 100vh">
137
+ <ai-chat ref="chatRef"></ai-chat>
138
+ </div>
139
+ </template>
140
+
141
+ <script setup lang="ts">
142
+ import { ref, onMounted } from 'vue';
143
+ import '@ai-chat/components';
144
+ import '@ai-chat/themes';
145
+
146
+ const chatRef = ref<HTMLElement>();
147
+
148
+ onMounted(() => {
149
+ if (chatRef.value) {
150
+ (chatRef.value as any).setMessageHandler(async (message: string) => {
151
+ await new Promise(resolve => setTimeout(resolve, 1000));
152
+ return `AI 回复:${message}`;
153
+ });
154
+ }
155
+ });
156
+ </script>
157
+ ```
158
+
159
+ ## 🎨 主题切换
160
+
161
+ ```tsx
162
+ // 导入主题样式
163
+ import '@ai-chat/themes/minimal'; // 极简苹果风
164
+ import '@ai-chat/themes/neon'; // 赛博朋克深色
165
+ import '@ai-chat/themes/glass'; // 毛玻璃拟态
166
+ import '@ai-chat/themes/terminal'; // 复古终端
167
+ import '@ai-chat/themes/gradient'; // 多彩渐变
168
+ import '@ai-chat/themes/corporate'; // 企业商务
169
+
170
+ // 运行时动态切换主题
171
+ import { applyTheme } from '@ai-chat/themes';
172
+ import { minimalTheme } from '@ai-chat/themes/minimal';
173
+ import { neonTheme } from '@ai-chat/themes/neon';
174
+
175
+ // 应用极简主题
176
+ applyTheme(minimalTheme);
177
+
178
+ // 切换到赛博朋克主题
179
+ applyTheme(neonTheme);
180
+ ```
181
+
182
+ ## 📖 文档
183
+
184
+ 完整文档请访问:[文档链接]
185
+
186
+ - [快速开始](./docs/guide/getting-started.md)
187
+ - [Headless 模式](./docs/guide/headless-mode.md)
188
+ - [主题定制](./docs/guide/themes.md)
189
+ - [插件开发](./docs/guide/plugins.md)
190
+ - [API 适配器](./docs/guide/api-adapters.md)
191
+
192
+ ## 📚 示例
193
+
194
+ 查看 [examples](./examples/) 目录获取更多示例:
195
+
196
+ - [原生 HTML 示例](./examples/index.html)
197
+ - [React 示例](./examples/react-app/)
198
+ - [Vue 示例](./examples/vue-app/)
199
+
200
+ ## 🏗️ 项目结构
201
+
202
+ ```
203
+ ai-chat-ui-kit/
204
+ ├── packages/
205
+ │ ├── core/ # 核心逻辑层(状态管理、API 适配)
206
+ │ ├── components/ # Web Components 封装(Lit)
207
+ │ └── themes/ # 主题包(CSS + 配置)
208
+ ├── docs/ # 文档 & 主题预览页(GitHub Pages)
209
+ │ ├── index.html # 主题总览页
210
+ │ ├── chat-style-1-minimal.html # 主题1:极简
211
+ │ ├── chat-style-2-neon.html # 主题2:赛博朋克
212
+ │ ├── chat-style-3-glass.html # 主题3:毛玻璃
213
+ │ ├── chat-style-4-terminal.html # 主题4:终端
214
+ │ ├── chat-style-5-gradient.html # 主题5:渐变
215
+ │ └── chat-style-6-corporate.html # 主题6:企业
216
+ ├── examples/ # 使用示例
217
+ ├── README.md # 本文件
218
+ └── package.json # 根 package.json
219
+ ```
220
+
221
+ ## 🛠️ 开发
222
+
223
+ ### 安装依赖
224
+ ```bash
225
+ pnpm install
226
+ ```
227
+
228
+ ### 开发模式
229
+ ```bash
230
+ pnpm dev
231
+ ```
232
+
233
+ ### 构建
234
+ ```bash
235
+ pnpm build
236
+ ```
237
+
238
+ ### 测试
239
+ ```bash
240
+ pnpm test
241
+ ```
242
+
243
+ ### Lint
244
+ ```bash
245
+ pnpm lint
246
+ ```
247
+
248
+ ## 🚀 GitHub Pages 部署
249
+
250
+ 本项目的 `docs/` 目录已配置为 GitHub Pages 源目录,推送到 `master` 分支后会自动部署。
251
+
252
+ **查看在线预览:** `https://<your-username>.github.io/ai-chat-ui-kit/`
253
+
254
+ ## 📝 API 参考
255
+
256
+ ### Core 包
257
+ - `createChatStore()` - 创建聊天状态管理
258
+ - `createAPIAdapter()` - 创建 API 适配器
259
+ - `createPluginSystem()` - 创建插件系统
260
+
261
+ 详见:[Core API 文档](./docs/api/core.md)
262
+
263
+ ### Components 包
264
+ - `<ai-chat>` - 聊天容器组件
265
+ - `<ai-message>` - 消息组件
266
+ - `<ai-input>` - 输入框组件
267
+ - `<ai-tool-call>` - 工具调用组件
268
+
269
+ 详见:[Components API 文档](./docs/api/components.md)
270
+
271
+ ## 🤝 贡献
272
+
273
+ 欢迎提交 Issue 和 Pull Request!
274
+
275
+ ## 📄 许可证
276
+
277
+ [MIT License](./LICENSE)
278
+
279
+ ## 👤 作者
280
+
281
+ edenxpzhang
282
+
283
+ ---
284
+
285
+ Built with ❤️ using [Lit](https://lit.dev/)
package/docs/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # AI Chat UI Kit 文档
2
+
3
+ ![Version](https://img.shields.io/badge/version-0.1.0-blue.svg)
4
+ ![License](https://img.shields.io/badge/license-MIT-green.svg)
5
+
6
+ 欢迎使用 AI Chat UI Kit 官方文档!
7
+
8
+ ## 📖 文档导航
9
+
10
+ ### 🚀 快速开始
11
+ - [快速开始指南](./guide/getting-started.md) - 5分钟上手教程
12
+ - [安装指南](./guide/getting-started.md#安装) - 详细安装步骤
13
+
14
+ ### 📚 使用指南
15
+ - [Headless 模式](./guide/headless-mode.md) - 只使用逻辑层,自定义 UI
16
+ - [主题定制](./guide/themes.md) - 自定义主题和样式
17
+ - [插件开发](./guide/plugins.md) - 扩展功能
18
+ - [API 适配器](./guide/api-adapters.md) - 兼容多种后端 API
19
+
20
+ ### 🔧 API 参考
21
+ - [Core 包 API](./api/core.md) - 核心逻辑层 API
22
+ - [Components 包 API](./api/components.md) - Web Components API
23
+
24
+ ### 💡 示例
25
+ - [基本聊天](./examples/basic-chat.md) - 最简单的聊天功能
26
+ - [自定义插件](./examples/custom-plugins.md) - 创建自定义插件
27
+ - [多模型支持](./examples/multi-model.md) - 切换不同 AI 模型
28
+
29
+ ## 🎯 项目简介
30
+
31
+ AI Chat UI Kit 是一套基于 Web Components 的 AI 聊天 UI 组件库,具有以下特点:
32
+
33
+ - ✨ **跨框架兼容** - 原生 Web Components,支持 React、Vue、Angular 等
34
+ - 🎨 **Headless 模式** - 可只使用逻辑层,完全自定义 UI
35
+ - 🎭 **多主题支持** - 内置默认、气泡、扁平三种主题
36
+ - 🔌 **插件系统** - 易于扩展功能
37
+ - 📡 **API 适配器** - 兼容多种后端 API 格式
38
+ - 📦 **轻量级** - 无 heavy dependencies
39
+
40
+ ## 📦 安装
41
+
42
+ ```bash
43
+ # PNPM(推荐)
44
+ pnpm add @ai-chat/core @ai-chat/components @ai-chat/themes
45
+
46
+ # NPM
47
+ npm install @ai-chat/core @ai-chat/components @ai-chat/themes
48
+
49
+ # Yarn
50
+ yarn add @ai-chat/core @ai-chat/components @ai-chat/themes
51
+ ```
52
+
53
+ ## 🚀 快速开始
54
+
55
+ ### 原生 HTML
56
+
57
+ ```html
58
+ <!DOCTYPE html>
59
+ <html lang="zh-CN">
60
+ <head>
61
+ <meta charset="UTF-8">
62
+ <title>AI Chat Demo</title>
63
+ <script type="module">
64
+ import '@ai-chat/components';
65
+ import '@ai-chat/themes/default';
66
+ </script>
67
+ </head>
68
+ <body>
69
+ <div style="height: 100vh">
70
+ <ai-chat></ai-chat>
71
+ </div>
72
+
73
+ <script>
74
+ const chat = document.querySelector('ai-chat');
75
+ chat.setMessageHandler(async (message) => {
76
+ await new Promise(resolve => setTimeout(resolve, 1000));
77
+ return `您说的是:${message}`;
78
+ });
79
+ </script>
80
+ </body>
81
+ </html>
82
+ ```
83
+
84
+ ### React
85
+
86
+ ```tsx
87
+ import React, { useEffect, useRef } from 'react';
88
+ import '@ai-chat/components';
89
+ import '@ai-chat/themes/default';
90
+
91
+ const ChatApp: React.FC = () => {
92
+ const chatRef = useRef<HTMLElement>(null);
93
+
94
+ useEffect(() => {
95
+ if (chatRef.current) {
96
+ (chatRef.current as any).setMessageHandler(async (message: string) => {
97
+ await new Promise(resolve => setTimeout(resolve, 1000));
98
+ return `AI 回复:${message}`;
99
+ });
100
+ }
101
+ }, []);
102
+
103
+ return (
104
+ <div style={{ height: '100vh' }}>
105
+ <ai-chat ref={chatRef}></ai-chat>
106
+ </div>
107
+ );
108
+ };
109
+
110
+ export default ChatApp;
111
+ ```
112
+
113
+ ### Vue 3
114
+
115
+ ```vue
116
+ <template>
117
+ <div style="height: 100vh">
118
+ <ai-chat ref="chatRef"></ai-chat>
119
+ </div>
120
+ </template>
121
+
122
+ <script setup lang="ts">
123
+ import { ref, onMounted } from 'vue';
124
+ import '@ai-chat/components';
125
+ import '@ai-chat/themes/default';
126
+
127
+ const chatRef = ref<HTMLElement>();
128
+
129
+ onMounted(() => {
130
+ if (chatRef.value) {
131
+ (chatRef.value as any).setMessageHandler(async (message: string) => {
132
+ await new Promise(resolve => setTimeout(resolve, 1000));
133
+ return `AI 回复:${message}`;
134
+ });
135
+ }
136
+ });
137
+ </script>
138
+ ```
139
+
140
+ ## 🎨 主题切换
141
+
142
+ ```typescript
143
+ // 使用默认主题
144
+ import '@ai-chat/themes/default';
145
+
146
+ // 使用气泡主题(仿微信/QQ 风格)
147
+ import '@ai-chat/themes/bubble';
148
+
149
+ // 使用扁平主题
150
+ import '@ai-chat/themes/flat';
151
+ ```
152
+
153
+ ## 🏗️ 项目结构
154
+
155
+ ```
156
+ ai-chat-ui-kit/
157
+ ├── packages/
158
+ │ ├── core/ # 核心逻辑层(状态管理、API 适配)
159
+ │ ├── components/ # Web Components 封装(Lit)
160
+ │ └── themes/ # 主题包(CSS + 配置)
161
+ ├── docs/ # 文档
162
+ ├── examples/ # 使用示例
163
+ └── README.md # 项目说明
164
+ ```
165
+
166
+ ## 🤝 贡献
167
+
168
+ 欢迎提交 Issue 和 Pull Request!
169
+
170
+ ## 📄 许可证
171
+
172
+ [MIT License](./LICENSE)
173
+
174
+ ---
175
+
176
+ Built with ❤️ using [Lit](https://lit.dev/)