@leeoohoo/aichat 1.0.8 → 1.0.10

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
@@ -1,214 +1,179 @@
1
1
  # @leeoohoo/aichat
2
2
 
3
- 一个功能完整的React AI聊天组件,支持会话管理、MCP集成和SQLite持久化存储。
3
+ React AI Chat Component and Node server. Bilingual README (中文/English).
4
4
 
5
- ## 特性
5
+
6
6
 
7
- - 🚀 **开箱即用** - 一个标签即可使用完整的AI聊天功能
8
- - 💬 **会话管理** - 支持多会话切换、创建、删除和重命名
9
- - 🤖 **AI模型支持** - 支持OpenAI GPT系列模型
10
- - 🔧 **MCP集成** - 支持Model Context Protocol工具调用
11
- - 💾 **数据持久化** - 基于SQLite的本地数据存储
12
- - 🎨 **主题切换** - 支持明暗主题切换
13
- - 📱 **响应式设计** - 适配各种屏幕尺寸
14
- - 🔒 **类型安全** - 完整的TypeScript类型定义
7
+ 一个功能完整的 React AI 聊天组件库,配套 Node 后端服务,支持会话管理、MCP 工具集成与持久化存储。
15
8
 
16
- ## 🚀 快速开始
9
+ ## 功能 Features
17
10
 
18
- ### 安装
11
+ - 开箱即用 Standalone chat UI, drop-in usage
12
+ - 会话管理 Sessions CRUD, multi-session switching
13
+ - AI 模型配置 AI model configs (OpenAI-compatible)
14
+ - MCP 集成 Model Context Protocol tool calls (HTTP/STDIO)
15
+ - 数据持久化 SQLite by default (MongoDB optional in server)
16
+ - 主题切换 Light/Dark/Auto, responsive UI
17
+ - 类型安全 Full TypeScript types
19
18
 
20
- ```bash
21
- # 使用 npm
22
- npm install @leeoohoo/aichat
23
-
24
- # 或使用 yarn
25
- yarn add @leeoohoo/aichat
19
+ ## 代码结构 Repository Structure
26
20
 
27
- # 或使用 pnpm
28
- pnpm add @leeoohoo/aichat
29
- ```
21
+ - 根目录 Root: React 组件库 React component library (Vite + TS)
22
+ - server/chat_app_node_server: Node API 服务 Node API server (Express, SSE, MCP, SQLite/MongoDB)
23
+ - examples/complete-example: 集成示例 Example app (web/Electron)
30
24
 
31
- ### 启动后端服务
25
+ ## 快速开始 Quick Start
32
26
 
33
- 组件需要后端API服务支持,请先启动后端服务:
27
+ 1) 作为依赖使用 Use as a dependency
34
28
 
35
29
  ```bash
36
- # 方式一:使用npm脚本启动
37
- npx @leeoohoo/aichat start:server
38
-
39
- # 方式二:直接运行服务器文件
40
- node node_modules/@leeoohoo/aichat/server/index.js
30
+ npm install @leeoohoo/aichat
31
+ # or
32
+ yarn add @leeoohoo/aichat
33
+ # or
34
+ pnpm add @leeoohoo/aichat
41
35
  ```
42
36
 
43
- 后端服务默认运行在 `http://localhost:3001`,提供以下API:
44
- - 会话管理 (`/api/sessions`)
45
- - 消息管理 (`/api/messages`)
46
- - MCP配置 (`/api/mcp-configs`)
47
- - AI模型配置 (`/api/ai-model-configs`)
48
- - 系统上下文 (`/api/system-context`)
49
-
50
- ### 基础使用(推荐)
51
-
52
- 使用独立聊天组件,无需任何配置,开箱即用:
37
+ 最简用法 Minimal usage
53
38
 
54
39
  ```tsx
55
- import React from 'react';
56
40
  import StandaloneChatInterface from '@leeoohoo/aichat';
57
41
  import '@leeoohoo/aichat/styles';
58
42
 
59
- function App() {
60
- return (
61
- <div className="h-screen w-full">
62
- <StandaloneChatInterface className="h-full" />
63
- </div>
64
- );
43
+ export default function App() {
44
+ return <StandaloneChatInterface className="h-screen" />;
65
45
  }
46
+ ```
47
+
48
+ 2) 本仓库本地开发 Run locally (this repo)
66
49
 
67
- export default App;
50
+ - 启动后端 Start the API server
51
+
52
+ ```bash
53
+ cd server/chat_app_node_server
54
+ npm install
55
+ cp .env.example .env # 设置 OPENAI_API_KEY 等 set your OPENAI_API_KEY
56
+ npm start # http://localhost:3001
68
57
  ```
69
58
 
70
- ## 高级配置
59
+ - 启动前端 Start the frontend demo
71
60
 
72
- ### 自定义事件处理
61
+ ```bash
62
+ cd /path/to/chat_app
63
+ npm install
64
+ npm run dev # http://localhost:5173 (proxy /api → 3001)
65
+ ```
66
+
67
+ 生产环境可通过组件传入 `apiBaseUrl` 或 `port` 覆盖后端地址。
68
+ In production, pass `apiBaseUrl` or `port` to the component to point at your server.
73
69
 
74
70
  ```tsx
75
- import React from 'react';
76
- import { ChatInterface, type Message, type Attachment } from '@leeoohoo/aichat';
77
-
78
- function App() {
79
- const handleMessageSend = (content: string, attachments?: Attachment[]) => {
80
- console.log('发送消息:', content, attachments);
81
- };
82
-
83
- const handleSessionChange = (sessionId: string) => {
84
- console.log('切换会话:', sessionId);
85
- };
86
-
87
- return (
88
- <ChatInterface
89
- onMessageSend={handleMessageSend}
90
- onSessionChange={handleSessionChange}
91
- />
92
- );
93
- }
71
+ <StandaloneChatInterface apiBaseUrl="https://your.domain/api" />
72
+ // or
73
+ <StandaloneChatInterface port={3001} />
94
74
  ```
95
75
 
96
- ### 自定义渲染器
76
+ ## 使用 Usage
77
+
78
+ 推荐 Recommended: 独立组件 Standalone component
97
79
 
98
80
  ```tsx
99
- import React from 'react';
100
- import { ChatInterface, type Message, type Attachment } from '@leeoohoo/aichat';
101
-
102
- function App() {
103
- const customRenderer = {
104
- renderMessage: (message: Message) => (
105
- <div className="custom-message">
106
- {message.content}
107
- </div>
108
- ),
109
- renderAttachment: (attachment: Attachment) => (
110
- <div className="custom-attachment">
111
- {attachment.name}
112
- </div>
113
- ),
114
- };
115
-
116
- return (
117
- <ChatInterface customRenderer={customRenderer} />
118
- );
119
- }
120
- ```
81
+ import StandaloneChatInterface from '@leeoohoo/aichat';
82
+ import '@leeoohoo/aichat/styles';
121
83
 
122
- ## 组件API
84
+ <StandaloneChatInterface
85
+ className="h-full"
86
+ userId="user_123"
87
+ projectId="proj_456"
88
+ showMcpManager
89
+ showAiModelManager
90
+ showSystemContextEditor
91
+ showAgentManager
92
+ />
93
+ ```
123
94
 
124
- ### ChatInterface
95
+ 可选:类方式 API Optional: class-style API
125
96
 
126
- 主要的聊天界面组件。
97
+ ```tsx
98
+ import { AiChat } from '@leeoohoo/aichat';
99
+
100
+ const aiChat = new AiChat(
101
+ 'user_123',
102
+ 'proj_456',
103
+ '/api', // configUrl (API base)
104
+ 'h-full', // className
105
+ true, true, true, // showMcpManager, showAiModelManager, showSystemContextEditor
106
+ true // showAgentManager
107
+ );
108
+
109
+ export default function App() {
110
+ return aiChat.render();
111
+ }
112
+ ```
127
113
 
128
- #### Props
114
+ 常用导出 Common exports
129
115
 
130
- | 属性 | 类型 | 默认值 | 描述 |
131
- |------|------|--------|------|
132
- | `className` | `string` | - | 自定义CSS类名 |
133
- | `onMessageSend` | `(content: string, attachments?: Attachment[]) => void` | - | 消息发送回调 |
134
- | `onSessionChange` | `(sessionId: string) => void` | - | 会话切换回调 |
135
- | `customRenderer` | `CustomRenderer` | - | 自定义渲染器 |
116
+ - 组件 Components: `StandaloneChatInterface`, `ChatInterface`, `MessageList`, `InputArea`, `SessionList`, `ThemeToggle`, `McpManager`, `AiModelManager`, `SystemContextEditor`
117
+ - Hooks: `useTheme`, `useChatStore`
118
+ - 工具 Utils/API: `lib/api`, `lib/services`, `lib/utils`
119
+ - 类型 Types: `@leeoohoo/aichat` 导入类型 Import types from the package
136
120
 
137
- ### 其他组件
121
+ ## 环境与配置 Env & Config
138
122
 
139
- - `MessageList` - 消息列表组件
140
- - `InputArea` - 输入区域组件
141
- - `SessionList` - 会话列表组件
142
- - `ThemeToggle` - 主题切换组件
143
- - `McpManager` - MCP管理组件
144
- - `AiModelManager` - AI模型管理组件
123
+ 前端 Frontend
145
124
 
146
- ## Hooks
125
+ - 开发环境 dev: Vite 代理将 `/api` 指向 `http://localhost:3001`
126
+ - 生产 prod: 通过 `apiBaseUrl`/`port` 或自行配置反向代理 Configure `apiBaseUrl`/`port` or reverse proxy
147
127
 
148
- ### useChatStore
128
+ 后端 Server (`server/chat_app_node_server`)
149
129
 
150
- 聊天状态管理Hook。
130
+ - `.env`
151
131
 
152
- ```tsx
153
- import { useChatStore } from '@leeoohoo/aichat';
154
-
155
- function MyComponent() {
156
- const {
157
- currentSession,
158
- messages,
159
- isLoading,
160
- sendMessage,
161
- createSession,
162
- switchSession,
163
- } = useChatStore();
164
-
165
- // 使用状态和方法
166
- }
132
+ ```env
133
+ OPENAI_API_KEY=your_api_key
134
+ OPENAI_BASE_URL=https://api.openai.com/v1
135
+ PORT=3001
136
+ NODE_ENV=development
167
137
  ```
168
138
 
169
- ### useTheme
139
+ - 数据库 Database: 默认 SQLite,配置见 `server/chat_app_node_server/config/database.json`;可切换 MongoDB
170
140
 
171
- 主题管理Hook。
141
+ ## API 概览 API Overview
172
142
 
173
- ```tsx
174
- import { useTheme } from '@leeoohoo/aichat';
143
+ - Sessions: `/api/sessions` CRUD, messages: `/api/sessions/:id/messages`
144
+ - Agents: `/api/agents` CRUD, stream: `/api/agents/chat/stream`
145
+ - MCP: `/api/mcp-configs` CRUD, profiles, resource reading
146
+ - AI Model Configs: `/api/ai-model-configs` CRUD
147
+ - System Contexts: `/api/system-contexts` CRUD, active context
148
+ - Streaming chat: `/api/agent_v2/chat/stream` (SSE)
175
149
 
176
- function MyComponent() {
177
- const { theme, setTheme, actualTheme } = useTheme();
150
+ 详细见 See details: `server/chat_app_node_server/README.md`
178
151
 
179
- return (
180
- <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
181
- 切换到 {theme === 'light' ? '暗色' : '亮色'} 主题
182
- </button>
183
- );
184
- }
185
- ```
152
+ ## 示例 Examples
186
153
 
187
- ## 配置
154
+ - `examples/complete-example`: 完整示例(含 Electron) Complete sample (with Electron)
188
155
 
189
- ### 环境变量
156
+ ```bash
157
+ cd examples/complete-example
158
+ npm install
159
+ npm run dev:full # 前端 + 后端 Frontend + Server
160
+ ```
190
161
 
191
- 在使用前,请确保设置以下环境变量:
162
+ ## 开发脚本 Scripts (root)
192
163
 
193
- ```env
194
- # OpenAI配置
195
- VITE_OPENAI_API_KEY=your_openai_api_key
196
- VITE_OPENAI_BASE_URL=https://api.openai.com/v1
164
+ - `npm run dev` Vite 本地预览 Local dev
165
+ - `npm run build:lib` 构建库 Build library bundle
166
+ - `npm run test`/`test:ui` 单测 Vitest
167
+ - `npm run lint`/`lint:fix` ESLint
168
+ - `npm run storybook` 组件调试 Storybook
197
169
 
198
- # 服务器配置
199
- VITE_API_BASE_URL=http://localhost:3001
200
- ```
170
+ ## 许可证 License
201
171
 
202
- ### 数据库初始化
172
+ MIT
203
173
 
204
- ```tsx
205
- import { initDatabase } from '@leeoohoo/aichat';
174
+
206
175
 
207
- // 在应用启动时初始化数据库
208
- initDatabase().then(() => {
209
- console.log('数据库初始化完成');
210
- });
211
- ```
176
+ 如需更细的接入与排障,参见 Also see: `USAGE.md`, `INTEGRATION_EXAMPLE.md`, `MODULE_CONTROL.md`。
212
177
 
213
178
  ## 样式定制
214
179
 
@@ -274,4 +239,4 @@ MIT
274
239
 
275
240
  ## 支持
276
241
 
277
- 如果你觉得这个项目有用,请给它一个⭐️!
242
+ 如果你觉得这个项目有用,请给它一个⭐️!