@huyooo/ai-chat-frontend-react 0.1.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.
@@ -0,0 +1,401 @@
1
+ import { FC, ReactNode } from 'react';
2
+
3
+ /**
4
+ * AI Chat 前端类型定义
5
+ * 与 Vue 版本保持一致
6
+ */
7
+ /** 搜索结果 */
8
+ interface SearchResult {
9
+ title: string;
10
+ url: string;
11
+ snippet: string;
12
+ }
13
+ /** 工具调用 */
14
+ interface ToolCall {
15
+ name: string;
16
+ args?: Record<string, unknown>;
17
+ result?: string;
18
+ status: 'running' | 'success' | 'error';
19
+ }
20
+ /** 模型提供商 */
21
+ type ModelProvider = 'openrouter' | 'doubao' | 'deepseek' | 'qwen' | 'gemini' | 'ark';
22
+ /** 模型配置 */
23
+ interface ModelConfig {
24
+ provider: ModelProvider;
25
+ model: string;
26
+ displayName: string;
27
+ supportsTools: boolean;
28
+ supportsWebSearch: boolean;
29
+ supportedThinkingModes: ThinkingMode[];
30
+ }
31
+ /** 思考模式 */
32
+ type ThinkingMode = 'enabled' | 'disabled';
33
+ /** 聊天模式 */
34
+ type ChatMode = 'agent' | 'ask';
35
+ /** 聊天消息 */
36
+ interface ChatMessage {
37
+ id: string;
38
+ role: 'user' | 'assistant';
39
+ content: string;
40
+ images?: string[];
41
+ thinking?: string;
42
+ thinkingComplete?: boolean;
43
+ searchResults?: SearchResult[];
44
+ searching?: boolean;
45
+ toolCalls?: ToolCall[];
46
+ copied?: boolean;
47
+ loading?: boolean;
48
+ timestamp?: Date;
49
+ }
50
+ /** 会话记录 */
51
+ interface SessionRecord {
52
+ id: string;
53
+ title: string;
54
+ model: string;
55
+ mode: ChatMode;
56
+ createdAt: Date;
57
+ updatedAt: Date;
58
+ }
59
+ /** 消息记录 */
60
+ interface MessageRecord {
61
+ id: string;
62
+ sessionId: string;
63
+ role: 'user' | 'assistant';
64
+ content: string;
65
+ thinking?: string;
66
+ toolCalls?: string;
67
+ searchResults?: string;
68
+ timestamp: Date;
69
+ }
70
+ /** 默认模型列表 */
71
+ declare const DEFAULT_MODELS: ModelConfig[];
72
+ /** @deprecated 使用 SessionRecord */
73
+ interface ChatSession {
74
+ id: string;
75
+ title: string;
76
+ messages: ChatMessage[];
77
+ createdAt: Date;
78
+ updatedAt: Date;
79
+ }
80
+ /** 音视频操作类型 */
81
+ interface MediaOperation {
82
+ id: string;
83
+ type: 'clip' | 'transcode' | 'merge' | 'extract_audio' | 'add_subtitle' | 'analyze';
84
+ description: string;
85
+ sourceFiles: string[];
86
+ targetFile?: string;
87
+ parameters?: Record<string, unknown>;
88
+ status?: 'pending' | 'applied' | 'rejected';
89
+ preview?: string;
90
+ }
91
+ /** @deprecated 使用字符串枚举 */
92
+ type AiModel = 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview';
93
+ declare enum FileType {
94
+ FOLDER = "folder",
95
+ IMAGE = "image",
96
+ VIDEO = "video",
97
+ AUDIO = "audio",
98
+ TEXT = "text",
99
+ PDF = "pdf",
100
+ CODE = "code",
101
+ ARCHIVE = "archive",
102
+ OTHER = "other"
103
+ }
104
+ interface DiffStat {
105
+ file: string;
106
+ additions: number;
107
+ deletions: number;
108
+ type: 'modified' | 'added' | 'deleted';
109
+ }
110
+
111
+ /**
112
+ * Chat Adapter 接口定义
113
+ * 解耦前端组件与后端通信方式
114
+ *
115
+ * 与 Vue 版本保持一致
116
+ */
117
+
118
+ /** 聊天进度类型 */
119
+ type ChatProgressType = 'thinking' | 'search_start' | 'search_result' | 'tool_call' | 'tool_result' | 'text_delta' | 'text' | 'done' | 'error';
120
+ /** 思考数据 */
121
+ interface ThinkingData {
122
+ content: string;
123
+ isComplete: boolean;
124
+ }
125
+ /** 工具调用数据 */
126
+ interface ToolCallData {
127
+ name: string;
128
+ args: Record<string, unknown>;
129
+ }
130
+ /** 工具结果数据 */
131
+ interface ToolResultData {
132
+ name: string;
133
+ result: string;
134
+ }
135
+ /** 图片数据 */
136
+ interface ImageData {
137
+ base64: string;
138
+ mimeType: string;
139
+ }
140
+ /** 聊天进度事件 */
141
+ interface ChatProgress {
142
+ type: ChatProgressType;
143
+ data: string | ThinkingData | ToolCallData | ToolResultData | {
144
+ results: SearchResult[];
145
+ };
146
+ }
147
+ /** 发送消息选项 */
148
+ interface SendMessageOptions {
149
+ mode: ChatMode;
150
+ model: string;
151
+ enableWebSearch: boolean;
152
+ thinkingMode: ThinkingMode;
153
+ }
154
+ /** 创建会话选项 */
155
+ interface CreateSessionOptions {
156
+ title: string;
157
+ model: string;
158
+ mode: ChatMode;
159
+ }
160
+ /** 更新会话选项 */
161
+ interface UpdateSessionOptions {
162
+ title?: string;
163
+ model?: string;
164
+ mode?: ChatMode;
165
+ }
166
+ /** 保存消息选项 */
167
+ interface SaveMessageOptions {
168
+ sessionId: string;
169
+ role: 'user' | 'assistant';
170
+ content: string;
171
+ thinking?: string;
172
+ toolCalls?: string;
173
+ searchResults?: string;
174
+ }
175
+ /**
176
+ * Chat Adapter 接口
177
+ * 所有后端通信实现都需要实现此接口
178
+ */
179
+ interface ChatAdapter {
180
+ /** 获取所有会话 */
181
+ getSessions(): Promise<SessionRecord[]>;
182
+ /** 创建新会话 */
183
+ createSession(options: CreateSessionOptions): Promise<SessionRecord>;
184
+ /** 更新会话 */
185
+ updateSession(sessionId: string, options: UpdateSessionOptions): Promise<void>;
186
+ /** 删除会话 */
187
+ deleteSession(sessionId: string): Promise<void>;
188
+ /** 获取会话消息 */
189
+ getMessages(sessionId: string): Promise<MessageRecord[]>;
190
+ /** 保存消息 */
191
+ saveMessage(options: SaveMessageOptions): Promise<MessageRecord>;
192
+ /** 发送消息并获取流式响应 */
193
+ sendMessage(content: string, options: SendMessageOptions, images?: string[]): AsyncGenerator<ChatProgress, void, unknown>;
194
+ /** 取消当前请求 */
195
+ cancel(): void;
196
+ /** 设置工作目录 */
197
+ setWorkingDir?(dir: string): void;
198
+ }
199
+ /**
200
+ * 创建空 Adapter(用于测试或无后端场景)
201
+ */
202
+ declare function createNullAdapter(): ChatAdapter;
203
+
204
+ /**
205
+ * useChat Hook
206
+ * 管理聊天状态和与后端的通信
207
+ * 使用 Adapter 模式解耦后端通信
208
+ *
209
+ * 与 Vue 版本 useChat composable 保持一致
210
+ */
211
+
212
+ interface UseChatOptions {
213
+ /** Adapter 实例 */
214
+ adapter?: ChatAdapter;
215
+ /** 默认模型 */
216
+ defaultModel?: string;
217
+ /** 默认模式 */
218
+ defaultMode?: ChatMode;
219
+ }
220
+ /**
221
+ * 聊天状态管理 Hook
222
+ */
223
+ declare function useChat(options?: UseChatOptions): {
224
+ sessions: SessionRecord[];
225
+ currentSessionId: string | null;
226
+ messages: ChatMessage[];
227
+ isLoading: boolean;
228
+ mode: ChatMode;
229
+ model: string;
230
+ webSearch: boolean;
231
+ thinking: boolean;
232
+ loadSessions: () => Promise<void>;
233
+ switchSession: (sessionId: string) => Promise<void>;
234
+ createNewSession: () => Promise<void>;
235
+ deleteSession: (sessionId: string) => Promise<void>;
236
+ deleteCurrentSession: () => Promise<void>;
237
+ sendMessage: (text: string, images?: string[]) => Promise<void>;
238
+ cancelRequest: () => void;
239
+ copyMessage: (messageId: string) => Promise<void>;
240
+ regenerateMessage: (messageIndex: number) => void;
241
+ setMode: (value: ChatMode) => void;
242
+ setModel: (value: string) => void;
243
+ setWebSearch: (value: boolean) => void;
244
+ setThinking: (value: boolean) => void;
245
+ setWorkingDirectory: (dir: string) => void;
246
+ };
247
+
248
+ /**
249
+ * ChatPanel Component
250
+ * 与 Vue 版本 ChatPanel.vue 保持一致
251
+ */
252
+
253
+ interface ChatPanelProps {
254
+ /** Adapter 实例 */
255
+ adapter?: ChatAdapter;
256
+ /** 工作目录 */
257
+ workingDir?: string;
258
+ /** 默认模型 */
259
+ defaultModel?: string;
260
+ /** 默认模式 */
261
+ defaultMode?: ChatMode;
262
+ /** 可用模型列表 */
263
+ models?: ModelConfig[];
264
+ /** 隐藏标题栏 */
265
+ hideHeader?: boolean;
266
+ /** 关闭回调(有此属性时显示关闭按钮) */
267
+ onClose?: () => void;
268
+ /** 自定义类名 */
269
+ className?: string;
270
+ /** 自定义 Markdown 渲染器 */
271
+ renderMarkdown?: (content: string) => ReactNode;
272
+ }
273
+ declare const ChatPanel: FC<ChatPanelProps>;
274
+
275
+ /**
276
+ * ChatInput Component
277
+ * 与 Vue 版本 ChatInput.vue 保持一致
278
+ */
279
+
280
+ interface ChatInputProps {
281
+ /** 变体模式:input-底部输入框,message-历史消息 */
282
+ variant?: 'input' | 'message';
283
+ /** 受控值(用于历史消息编辑) */
284
+ value?: string;
285
+ selectedImages?: string[];
286
+ isLoading?: boolean;
287
+ mode?: ChatMode;
288
+ model?: string;
289
+ models?: ModelConfig[];
290
+ webSearchEnabled?: boolean;
291
+ thinkingEnabled?: boolean;
292
+ onSend?: (text: string) => void;
293
+ onRemoveImage?: (index: number) => void;
294
+ onCancel?: () => void;
295
+ onUploadImage?: () => void;
296
+ onAtContext?: () => void;
297
+ onModeChange?: (mode: ChatMode) => void;
298
+ onModelChange?: (model: string) => void;
299
+ onWebSearchChange?: (enabled: boolean) => void;
300
+ onThinkingChange?: (enabled: boolean) => void;
301
+ }
302
+ declare const ChatInput: FC<ChatInputProps>;
303
+
304
+ /**
305
+ * ChatHeader Component
306
+ * 与 Vue 版本 ChatHeader.vue 保持一致
307
+ */
308
+
309
+ interface ChatHeaderProps {
310
+ /** 当前会话列表 */
311
+ sessions: SessionRecord[];
312
+ /** 当前会话 ID */
313
+ currentSessionId?: string | null;
314
+ /** 是否显示关闭按钮 */
315
+ showClose?: boolean;
316
+ /** 创建新会话 */
317
+ onNewSession?: () => void;
318
+ /** 切换会话 */
319
+ onSwitchSession?: (sessionId: string) => void;
320
+ /** 删除会话 */
321
+ onDeleteSession?: (sessionId: string) => void;
322
+ /** 关闭面板 */
323
+ onClose?: () => void;
324
+ /** 清空所有对话 */
325
+ onClearAll?: () => void;
326
+ /** 关闭其他对话 */
327
+ onCloseOthers?: () => void;
328
+ /** 导出对话 */
329
+ onExport?: () => void;
330
+ /** 复制请求 ID */
331
+ onCopyId?: () => void;
332
+ /** 反馈 */
333
+ onFeedback?: () => void;
334
+ /** Agent 设置 */
335
+ onSettings?: () => void;
336
+ }
337
+ declare const ChatHeader: FC<ChatHeaderProps>;
338
+
339
+ /**
340
+ * WelcomeMessage Component
341
+ * 与 Vue 版本 WelcomeMessage.vue 保持一致
342
+ */
343
+
344
+ interface WelcomeMessageProps {
345
+ /** 快捷操作回调 */
346
+ onQuickAction: (text: string) => void;
347
+ }
348
+ declare const WelcomeMessage: FC<WelcomeMessageProps>;
349
+
350
+ /**
351
+ * MessageBubble Component
352
+ * 与 Vue 版本 MessageBubble.vue 保持一致
353
+ */
354
+
355
+ interface MessageBubbleProps {
356
+ role: 'user' | 'assistant';
357
+ content: string;
358
+ images?: string[];
359
+ thinking?: string;
360
+ thinkingComplete?: boolean;
361
+ thinkingDuration?: number;
362
+ searchResults?: SearchResult[];
363
+ searching?: boolean;
364
+ toolCalls?: ToolCall[];
365
+ copied?: boolean;
366
+ loading?: boolean;
367
+ onCopy?: () => void;
368
+ onRegenerate?: () => void;
369
+ /** 编辑用户消息后重新发送 */
370
+ onSend?: (text: string) => void;
371
+ /** 自定义 Markdown 渲染器 */
372
+ renderMarkdown?: (content: string) => ReactNode;
373
+ }
374
+ declare const MessageBubble: FC<MessageBubbleProps>;
375
+
376
+ /**
377
+ * ExecutionSteps Component
378
+ * 与 Vue 版本 ExecutionSteps.vue 保持一致
379
+ */
380
+
381
+ interface ExecutionStepsProps {
382
+ /** 是否正在加载 */
383
+ loading?: boolean;
384
+ /** 是否有消息内容 */
385
+ hasContent?: boolean;
386
+ /** 思考内容 */
387
+ thinking?: string;
388
+ /** 思考是否完成 */
389
+ thinkingComplete?: boolean;
390
+ /** 思考耗时 */
391
+ thinkingDuration?: number;
392
+ /** 是否正在搜索 */
393
+ searching?: boolean;
394
+ /** 搜索结果 */
395
+ searchResults?: SearchResult[];
396
+ /** 工具调用列表 */
397
+ toolCalls?: ToolCall[];
398
+ }
399
+ declare const ExecutionSteps: FC<ExecutionStepsProps>;
400
+
401
+ export { type AiModel, type ChatAdapter, ChatHeader, ChatInput, type ChatMessage, type ChatMode, ChatPanel, type ChatProgress, type ChatProgressType, type ChatSession, type CreateSessionOptions, DEFAULT_MODELS, type DiffStat, ExecutionSteps, FileType, type ImageData, type MediaOperation, MessageBubble, type MessageRecord, type ModelConfig, type ModelProvider, type SaveMessageOptions, type SearchResult, type SendMessageOptions, type SessionRecord, type ThinkingData, type ThinkingMode, type ToolCall, type ToolCallData, type ToolResultData, type UpdateSessionOptions, type UseChatOptions, WelcomeMessage, createNullAdapter, useChat };