@leeoohoo/aichat 1.0.0 → 1.0.7

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/dist/index.d.ts CHANGED
@@ -8,6 +8,89 @@ import { StoreApi } from 'zustand';
8
8
  import { UseBoundStore } from 'zustand';
9
9
  import { WritableDraft } from 'immer';
10
10
 
11
+ export declare interface AgentConfig {
12
+ id: string;
13
+ name: string;
14
+ description?: string;
15
+ ai_model_config_id: string;
16
+ enabled: boolean;
17
+ createdAt: Date;
18
+ updatedAt: Date;
19
+ app_ids?: string[];
20
+ }
21
+
22
+ /**
23
+ * AiChat 类 - 支持通过构造函数实例化的聊天组件
24
+ *
25
+ * 使用方式:
26
+ * ```typescript
27
+ *
28
+ * // 在React组件中使用
29
+ * function App() {
30
+ * return <div>{aiChat.render()}</div>;
31
+ * }
32
+ * ```
33
+ */
34
+ export declare class AiChat {
35
+ private userId;
36
+ private projectId;
37
+ private configUrl;
38
+ private apiClient;
39
+ private store;
40
+ private className?;
41
+ private showMcpManager;
42
+ private showAiModelManager;
43
+ private showSystemContextEditor;
44
+ private showAgentManager;
45
+ private onApplicationSelect?;
46
+ constructor(userId: string, projectId: string, configUrl?: string, className?: string, showMcpManager?: boolean, showAiModelManager?: boolean, showSystemContextEditor?: boolean, showAgentManager?: boolean, onApplicationSelect?: (app: Application) => void);
47
+ /**
48
+ * 渲染聊天界面
49
+ * @returns React 元素
50
+ */
51
+ render(): default_2.ReactElement;
52
+ /**
53
+ * 获取当前配置
54
+ */
55
+ getConfig(): AiChatConfig;
56
+ /**
57
+ * 更新配置
58
+ */
59
+ updateConfig(config: Partial<AiChatConfig>): void;
60
+ /**
61
+ * 获取 store 实例(用于高级用法)
62
+ */
63
+ getStore(): ChatStore;
64
+ /**
65
+ * 获取 API 客户端实例(用于高级用法)
66
+ */
67
+ getApiClient(): ApiClient;
68
+ /**
69
+ * 获取当前选中的应用对象
70
+ */
71
+ getSelectedApplication(): Application | null;
72
+ /**
73
+ * 获取当前选中的应用 URL
74
+ */
75
+ getSelectedApplicationUrl(): string | null;
76
+ /**
77
+ * 订阅应用选择变化(实时回调当前应用对象),返回取消订阅函数
78
+ */
79
+ subscribeSelectedApplication(listener: (app: Application | null) => void): () => void;
80
+ }
81
+
82
+ declare interface AiChatConfig {
83
+ userId: string;
84
+ projectId: string;
85
+ configUrl?: string;
86
+ className?: string;
87
+ showMcpManager?: boolean;
88
+ showAiModelManager?: boolean;
89
+ showSystemContextEditor?: boolean;
90
+ showAgentManager?: boolean;
91
+ onApplicationSelect?: (app: Application) => void;
92
+ }
93
+
11
94
  export declare interface AiClientConfig {
12
95
  apiKey: string;
13
96
  baseUrl?: string;
@@ -33,8 +116,275 @@ export declare const AiModelManager: default_2.FC<AiModelManagerProps>;
33
116
 
34
117
  declare interface AiModelManagerProps {
35
118
  onClose: () => void;
119
+ store?: any;
36
120
  }
37
121
 
122
+ export declare class AiServer {
123
+ private conversationId;
124
+ private userId;
125
+ private conversation;
126
+ private mcpServers;
127
+ private messages;
128
+ private tools;
129
+ private mcpToolsExecute;
130
+ private modelConfig;
131
+ private currentThread;
132
+ private isAborted;
133
+ private messageManager;
134
+ private configUrl;
135
+ private sessionId;
136
+ constructor(conversation_id: string, userId: string, messageManager: MessageManager, customModelConfig?: AiModelConfig | null, configUrl?: string, sessionId?: string);
137
+ init(): Promise<void>;
138
+ /**
139
+ * 回调函数,用于处理AI响应过程中的各种事件
140
+ * @param {string} type - 事件类型 ('chunk', 'tool_call', 'error', 'complete')
141
+ * @param {any} data - 事件数据
142
+ */
143
+ callback(type: CallbackType, data?: any): void;
144
+ sendMessage(userMessage: string): Promise<void>;
145
+ /**
146
+ * 获取会话消息
147
+ * @param {Object} params - 分页参数 {page, limit}
148
+ * @returns {Promise}
149
+ */
150
+ sendMessageDirect(userMessage: string): Promise<void>;
151
+ getMessages(params?: any): Promise<any>;
152
+ /**
153
+ * 添加消息到会话
154
+ * @param {string} message - 消息内容
155
+ * @param {string} role - 消息角色 ('user' | 'assistant')
156
+ * @returns {Promise}
157
+ */
158
+ addMessage(message: string, role?: string): Promise<any>;
159
+ /**
160
+ * 中止当前请求线程
161
+ */
162
+ abort(): void;
163
+ /**
164
+ * 检查是否已被中止
165
+ * @returns {boolean}
166
+ */
167
+ isRequestAborted(): boolean;
168
+ /**
169
+ * 重置中止状态
170
+ */
171
+ resetAbortState(): void;
172
+ }
173
+
174
+ export declare class ApiClient {
175
+ private baseUrl;
176
+ constructor(baseUrl?: string);
177
+ getBaseUrl(): string;
178
+ private request;
179
+ getSessions(userId?: string, projectId?: string): Promise<any[]>;
180
+ createSession(data: {
181
+ id: string;
182
+ title: string;
183
+ user_id: string;
184
+ project_id: string;
185
+ }): Promise<any>;
186
+ getSession(id: string): Promise<any>;
187
+ deleteSession(id: string): Promise<any>;
188
+ getSessionMessages(sessionId: string, params?: {
189
+ limit?: number;
190
+ offset?: number;
191
+ }): Promise<any[]>;
192
+ createMessage(data: {
193
+ id: string;
194
+ sessionId: string;
195
+ role: string;
196
+ content: string;
197
+ metadata?: any;
198
+ toolCalls?: any[];
199
+ createdAt?: Date;
200
+ status?: string;
201
+ }): Promise<any>;
202
+ getMcpConfigs(userId?: string): Promise<unknown>;
203
+ createMcpConfig(data: {
204
+ id: string;
205
+ name: string;
206
+ command: string;
207
+ type: 'http' | 'stdio';
208
+ args?: string[] | null;
209
+ env?: Record<string, string> | null;
210
+ cwd?: string | null;
211
+ enabled: boolean;
212
+ user_id?: string;
213
+ app_ids?: string[];
214
+ }): Promise<unknown>;
215
+ updateMcpConfig(id: string, data: {
216
+ id?: string;
217
+ name?: string;
218
+ command?: string;
219
+ type?: 'http' | 'stdio';
220
+ args?: string[] | null;
221
+ env?: Record<string, string> | null;
222
+ cwd?: string | null;
223
+ enabled?: boolean;
224
+ userId?: string;
225
+ app_ids?: string[];
226
+ }): Promise<unknown>;
227
+ deleteMcpConfig(id: string): Promise<unknown>;
228
+ getAiModelConfigs(userId?: string): Promise<unknown>;
229
+ createAiModelConfig(data: {
230
+ id: string;
231
+ name: string;
232
+ provider: string;
233
+ model: string;
234
+ api_key: string;
235
+ base_url: string;
236
+ user_id?: string;
237
+ enabled: boolean;
238
+ }): Promise<unknown>;
239
+ updateAiModelConfig(id: string, data: any): Promise<unknown>;
240
+ deleteAiModelConfig(id: string): Promise<unknown>;
241
+ getSystemContexts(userId: string): Promise<any[]>;
242
+ getActiveSystemContext(userId: string): Promise<{
243
+ content: string;
244
+ context: any;
245
+ }>;
246
+ createSystemContext(data: {
247
+ name: string;
248
+ content: string;
249
+ user_id: string;
250
+ app_ids?: string[];
251
+ }): Promise<any>;
252
+ updateSystemContext(id: string, data: {
253
+ name: string;
254
+ content: string;
255
+ app_ids?: string[];
256
+ }): Promise<any>;
257
+ deleteSystemContext(id: string): Promise<void>;
258
+ activateSystemContext(id: string, userId: string): Promise<any>;
259
+ getApplications(userId?: string): Promise<any[]>;
260
+ getApplication(id: string): Promise<any>;
261
+ createApplication(data: {
262
+ name: string;
263
+ url: string;
264
+ icon_url?: string | null;
265
+ user_id?: string;
266
+ }): Promise<any>;
267
+ updateApplication(id: string, data: {
268
+ name?: string;
269
+ url?: string;
270
+ icon_url?: string | null;
271
+ }): Promise<any>;
272
+ deleteApplication(id: string): Promise<any>;
273
+ getAgents(userId?: string): Promise<any[]>;
274
+ createAgent(data: {
275
+ name: string;
276
+ description?: string;
277
+ ai_model_config_id: string;
278
+ mcp_config_ids?: string[];
279
+ callable_agent_ids?: string[];
280
+ system_context_id?: string;
281
+ user_id?: string;
282
+ enabled?: boolean;
283
+ app_ids?: string[];
284
+ }): Promise<any>;
285
+ updateAgent(agentId: string, data: {
286
+ name?: string;
287
+ description?: string;
288
+ ai_model_config_id?: string;
289
+ mcp_config_ids?: string[];
290
+ callable_agent_ids?: string[];
291
+ system_context_id?: string;
292
+ enabled?: boolean;
293
+ app_ids?: string[];
294
+ }): Promise<any>;
295
+ deleteAgent(agentId: string): Promise<any>;
296
+ getConversationDetails(conversationId: string): Promise<{
297
+ data: {
298
+ conversation: {
299
+ id: any;
300
+ title: any;
301
+ created_at: any;
302
+ updated_at: any;
303
+ };
304
+ };
305
+ }>;
306
+ getAssistant(_conversationId: string): Promise<{
307
+ data: {
308
+ assistant: {
309
+ id: any;
310
+ name: any;
311
+ model_config: {
312
+ model_name: any;
313
+ temperature: number;
314
+ max_tokens: number;
315
+ api_key: any;
316
+ base_url: any;
317
+ };
318
+ };
319
+ };
320
+ }>;
321
+ getMcpServers(_conversationId?: string): Promise<{
322
+ data: {
323
+ mcp_servers: {
324
+ name: any;
325
+ url: any;
326
+ }[];
327
+ };
328
+ }>;
329
+ getMcpConfigResource(configId: string): Promise<{
330
+ success: boolean;
331
+ config: any;
332
+ alias?: string;
333
+ }>;
334
+ getMcpConfigResourceByCommand(data: {
335
+ type: 'stdio' | 'http';
336
+ command: string;
337
+ args?: string[] | null;
338
+ env?: Record<string, string> | null;
339
+ cwd?: string | null;
340
+ alias?: string | null;
341
+ }): Promise<{
342
+ success: boolean;
343
+ config: any;
344
+ alias?: string;
345
+ }>;
346
+ getMcpConfigProfiles(configId: string): Promise<any[]>;
347
+ createMcpConfigProfile(configId: string, data: {
348
+ name: string;
349
+ args?: string[] | null;
350
+ env?: Record<string, string> | null;
351
+ cwd?: string | null;
352
+ enabled?: boolean;
353
+ }): Promise<any>;
354
+ updateMcpConfigProfile(configId: string, profileId: string, data: {
355
+ name?: string;
356
+ args?: string[] | null;
357
+ env?: Record<string, string> | null;
358
+ cwd?: string | null;
359
+ enabled?: boolean;
360
+ }): Promise<any>;
361
+ deleteMcpConfigProfile(configId: string, profileId: string): Promise<any>;
362
+ activateMcpConfigProfile(configId: string, profileId: string): Promise<any>;
363
+ saveMessage(conversationId: string, message: any): Promise<{
364
+ data: {
365
+ message: any;
366
+ };
367
+ }>;
368
+ getMessages(conversationId: string, params?: {
369
+ limit?: number;
370
+ offset?: number;
371
+ }): Promise<{
372
+ data: {
373
+ messages: any[];
374
+ };
375
+ }>;
376
+ addMessage(conversationId: string, message: any): Promise<{
377
+ data: {
378
+ message: any;
379
+ };
380
+ }>;
381
+ streamChat(sessionId: string, content: string, modelConfig: any, userId?: string): Promise<ReadableStream>;
382
+ streamAgentChat(sessionId: string, content: string, agentId: string, userId?: string): Promise<ReadableStream>;
383
+ stopChat(sessionId: string): Promise<any>;
384
+ }
385
+
386
+ export declare const apiClient: ApiClient;
387
+
38
388
  /**
39
389
  * 错误处理工具
40
390
  */
@@ -44,6 +394,15 @@ export declare class AppError extends Error {
44
394
  constructor(message: string, code?: string, statusCode?: number);
45
395
  }
46
396
 
397
+ export declare interface Application {
398
+ id: string;
399
+ name: string;
400
+ url: string;
401
+ iconUrl?: string;
402
+ createdAt: Date;
403
+ updatedAt: Date;
404
+ }
405
+
47
406
  export declare interface Attachment {
48
407
  id: string;
49
408
  messageId: string;
@@ -65,6 +424,8 @@ declare interface AttachmentRendererProps {
65
424
 
66
425
  export declare type AttachmentType = 'image' | 'file' | 'audio';
67
426
 
427
+ declare type CallbackType = 'chunk' | 'tool_call' | 'tool_result' | 'tool_stream_chunk' | 'conversation_complete' | 'error' | 'complete';
428
+
68
429
  declare interface ChatActions {
69
430
  loadSessions: () => Promise<void>;
70
431
  createSession: (title?: string) => Promise<string>;
@@ -72,24 +433,39 @@ declare interface ChatActions {
72
433
  updateSession: (sessionId: string, updates: Partial<Session>) => Promise<void>;
73
434
  deleteSession: (sessionId: string) => Promise<void>;
74
435
  loadMessages: (sessionId: string) => Promise<void>;
436
+ loadMoreMessages: (sessionId: string) => Promise<void>;
75
437
  sendMessage: (content: string, attachments?: any[]) => Promise<void>;
76
438
  updateMessage: (messageId: string, updates: Partial<Message>) => Promise<void>;
77
439
  deleteMessage: (messageId: string) => Promise<void>;
78
440
  startStreaming: (messageId: string) => void;
79
441
  updateStreamingMessage: (content: string) => void;
80
442
  stopStreaming: () => void;
443
+ abortCurrentConversation: () => void;
81
444
  toggleSidebar: () => void;
82
445
  setTheme: (theme: Theme) => void;
83
446
  updateChatConfig: (config: Partial<ChatConfig>) => Promise<void>;
84
447
  loadMcpConfigs: () => Promise<void>;
85
- updateMcpConfig: (config: McpConfig) => Promise<void>;
448
+ updateMcpConfig: (config: McpConfig) => Promise<McpConfig | null>;
86
449
  deleteMcpConfig: (id: string) => Promise<void>;
87
450
  loadAiModelConfigs: () => Promise<void>;
88
451
  updateAiModelConfig: (config: AiModelConfig) => Promise<void>;
89
452
  deleteAiModelConfig: (id: string) => Promise<void>;
90
453
  setSelectedModel: (modelId: string | null) => void;
91
- loadSystemContext: () => Promise<void>;
92
- updateSystemContext: (content: string) => Promise<void>;
454
+ loadAgents: () => Promise<void>;
455
+ setSelectedAgent: (agentId: string | null) => void;
456
+ loadSystemContexts: () => Promise<void>;
457
+ createSystemContext: (name: string, content: string, appIds?: string[]) => Promise<any>;
458
+ updateSystemContext: (id: string, name: string, content: string, appIds?: string[]) => Promise<any>;
459
+ deleteSystemContext: (id: string) => Promise<void>;
460
+ activateSystemContext: (id: string) => Promise<void>;
461
+ loadApplications: () => Promise<void>;
462
+ createApplication: (name: string, url: string, iconUrl?: string) => Promise<void>;
463
+ updateApplication: (id: string, updates: Partial<Application>) => Promise<void>;
464
+ deleteApplication: (id: string) => Promise<void>;
465
+ setSelectedApplication: (appId: string | null) => void;
466
+ setMcpAppAssociation: (mcpId: string, appIds: string[]) => void;
467
+ setSystemContextAppAssociation: (contextId: string, appIds: string[]) => void;
468
+ setAgentAppAssociation: (agentId: string, appIds: string[]) => void;
93
469
  setError: (error: string | null) => void;
94
470
  clearError: () => void;
95
471
  }
@@ -158,8 +534,12 @@ export declare interface ChatPlugin {
158
534
  */
159
535
  export declare class ChatService {
160
536
  private currentAiClient;
537
+ private currentSessionId;
161
538
  private dbService;
162
- constructor();
539
+ private messageManager;
540
+ private userId;
541
+ private configUrl;
542
+ constructor(userId: string, projectId: string, messageManager: MessageManager, configUrl?: string);
163
543
  /**
164
544
  * 发送消息并处理AI响应
165
545
  */
@@ -173,15 +553,13 @@ export declare class ChatService {
173
553
  /**
174
554
  * 中止当前对话
175
555
  */
176
- abortCurrentConversation(): void;
556
+ abortCurrentConversation(): Promise<void>;
177
557
  /**
178
558
  * 获取聊天配置
179
559
  */
180
560
  getChatConfig(): Promise<ChatConfig_2>;
181
561
  }
182
562
 
183
- export declare const chatService: ChatService;
184
-
185
563
  /**
186
564
  * 聊天服务回调类型
187
565
  */
@@ -209,20 +587,38 @@ declare interface ChatState {
209
587
  isLoading: boolean;
210
588
  isStreaming: boolean;
211
589
  streamingMessageId: string | null;
590
+ hasMoreMessages: boolean;
212
591
  sidebarOpen: boolean;
213
592
  theme: Theme;
214
593
  chatConfig: ChatConfig;
215
594
  mcpConfigs: McpConfig[];
216
595
  aiModelConfigs: AiModelConfig[];
217
596
  selectedModelId: string | null;
218
- systemContext: string | null;
597
+ agents: AgentConfig[];
598
+ selectedAgentId: string | null;
599
+ systemContexts: SystemContext[];
600
+ activeSystemContext: SystemContext | null;
601
+ applications: Application[];
602
+ selectedApplicationId: string | null;
219
603
  error: string | null;
220
604
  }
221
605
 
606
+ declare type ChatStore = ReturnType<typeof createChatStoreWithBackend>;
607
+
608
+ declare interface ChatStoreConfig {
609
+ userId?: string;
610
+ projectId?: string;
611
+ configUrl?: string;
612
+ }
613
+
222
614
  export declare const CheckIcon: default_2.FC<{
223
615
  className?: string;
224
616
  }>;
225
617
 
618
+ export declare const ChevronDownIcon: default_2.FC<{
619
+ className?: string;
620
+ }>;
621
+
226
622
  /**
227
623
  * 清理HTML内容
228
624
  */
@@ -235,12 +631,12 @@ export declare function cn(...inputs: ClassValue[]): string;
235
631
 
236
632
  export declare interface ContentSegment {
237
633
  content: string | ToolCall;
238
- type: 'text' | 'tool_call';
634
+ type: 'text' | 'tool_call' | 'thinking';
239
635
  toolCallId?: string;
240
636
  }
241
637
 
242
638
  export declare const conversationsApi: {
243
- getDetails(conversationId: string): Promise<{
639
+ getDetails: (conversationId: string) => Promise<{
244
640
  data: {
245
641
  conversation: {
246
642
  id: any;
@@ -250,7 +646,7 @@ export declare const conversationsApi: {
250
646
  };
251
647
  };
252
648
  }>;
253
- getAssistant(_conversationId: string): Promise<{
649
+ getAssistant: (conversationId: string) => Promise<{
254
650
  data: {
255
651
  assistant: {
256
652
  id: any;
@@ -265,33 +661,70 @@ export declare const conversationsApi: {
265
661
  };
266
662
  };
267
663
  }>;
268
- getMcpServers(_conversationId?: string): Promise<{
664
+ getMcpServers: (conversationId?: string) => Promise<{
269
665
  data: {
270
- mcp_servers: any;
666
+ mcp_servers: {
667
+ name: any;
668
+ url: any;
669
+ }[];
271
670
  };
272
671
  }>;
273
- saveMessage(conversationId: string, message: any): Promise<{
672
+ saveMessage: (conversationId: string, message: any) => Promise<{
274
673
  data: {
275
674
  message: any;
276
675
  };
277
676
  }>;
278
- getMessages(conversationId: string, _params?: any): Promise<{
677
+ getMessages: (conversationId: string, params?: any) => Promise<{
279
678
  data: {
280
- messages: any;
679
+ messages: any[];
281
680
  };
282
681
  }>;
283
- addMessage(conversationId: string, message: any): Promise<{
682
+ addMessage: (conversationId: string, message: any) => Promise<{
284
683
  data: {
285
684
  message: any;
286
685
  };
287
686
  }>;
288
687
  };
289
688
 
689
+ export declare const CopyIcon: default_2.FC<{
690
+ className?: string;
691
+ }>;
692
+
290
693
  /**
291
694
  * 复制文本到剪贴板
292
695
  */
293
696
  export declare function copyToClipboard(text: string): Promise<boolean>;
294
697
 
698
+ /**
699
+ * 创建聊天store的工厂函数(使用后端API版本)
700
+ * @param customApiClient 自定义的API客户端实例,如果不提供则使用默认的apiClient
701
+ * @param config 自定义配置,包含userId和projectId
702
+ * @returns 聊天store hook
703
+ */
704
+ declare function createChatStoreWithBackend(customApiClient?: ApiClient, config?: ChatStoreConfig): UseBoundStore<Omit<Omit<StoreApi<ChatState & ChatActions>, "setState"> & {
705
+ setState(nextStateOrUpdater: (ChatState & ChatActions) | Partial<ChatState & ChatActions> | ((state: WritableDraft<ChatState & ChatActions>) => void), shouldReplace?: boolean | undefined): void;
706
+ }, "persist"> & {
707
+ persist: {
708
+ setOptions: (options: Partial<PersistOptions<ChatState & ChatActions, {
709
+ theme: Theme;
710
+ sidebarOpen: boolean;
711
+ chatConfig: ChatConfig;
712
+ selectedModelId: string | null;
713
+ }>>) => void;
714
+ clearStorage: () => void;
715
+ rehydrate: () => Promise<void> | void;
716
+ hasHydrated: () => boolean;
717
+ onHydrate: (fn: (state: ChatState & ChatActions) => void) => () => void;
718
+ onFinishHydration: (fn: (state: ChatState & ChatActions) => void) => () => void;
719
+ getOptions: () => Partial<PersistOptions<ChatState & ChatActions, {
720
+ theme: Theme;
721
+ sidebarOpen: boolean;
722
+ chatConfig: ChatConfig;
723
+ selectedModelId: string | null;
724
+ }>>;
725
+ };
726
+ }>;
727
+
295
728
  export declare interface DatabaseOperations {
296
729
  createSession: (title: string) => Promise<Session>;
297
730
  getSession: (id: string) => Promise<Session | null>;
@@ -305,21 +738,25 @@ export declare interface DatabaseOperations {
305
738
  getSessionMessages: (sessionId: string) => Promise<Message[]>;
306
739
  }
307
740
 
308
- declare class DatabaseService {
309
- constructor();
741
+ export declare class DatabaseService {
742
+ private userId;
743
+ private projectId;
744
+ private client;
745
+ constructor(userId: string, projectId: string, client?: ApiClient);
310
746
  createSession(data: Omit<Session_2, 'id'>): Promise<Session_2>;
311
747
  getSession(id: string): Promise<Session_2 | null>;
312
748
  getAllSessions(): Promise<Session_2[]>;
313
749
  updateSession(_id: string, _updates: Partial<Session_2>): Promise<Session_2 | null>;
314
750
  deleteSession(id: string): Promise<boolean>;
315
751
  createMessage(data: Omit<Message_2, 'id'>): Promise<Message_2>;
316
- getSessionMessages(sessionId: string): Promise<Message_2[]>;
752
+ getSessionMessages(sessionId: string, options?: {
753
+ limit?: number;
754
+ offset?: number;
755
+ }): Promise<Message_2[]>;
317
756
  updateMessage(_id: string, _updates: Partial<Message_2>): Promise<Message_2 | null>;
318
757
  deleteMessage(_id: string): Promise<boolean>;
319
758
  }
320
759
 
321
- export declare const databaseService: DatabaseService;
322
-
323
760
  /**
324
761
  * 防抖函数
325
762
  */
@@ -395,7 +832,9 @@ export declare const InputArea: default_2.FC<InputAreaProps>;
395
832
 
396
833
  export declare interface InputAreaProps {
397
834
  onSend: (content: string, attachments?: File[]) => void;
835
+ onStop?: () => void;
398
836
  disabled?: boolean;
837
+ isStreaming?: boolean;
399
838
  placeholder?: string;
400
839
  maxLength?: number;
401
840
  allowAttachments?: boolean;
@@ -404,6 +843,9 @@ export declare interface InputAreaProps {
404
843
  selectedModelId?: string | null;
405
844
  availableModels?: AiModelConfig[];
406
845
  onModelChange?: (modelId: string | null) => void;
846
+ selectedAgentId?: string | null;
847
+ availableAgents?: AgentConfig[];
848
+ onAgentChange?: (agentId: string | null) => void;
407
849
  }
408
850
 
409
851
  /**
@@ -439,27 +881,34 @@ declare interface MarkdownRendererProps {
439
881
  content: string;
440
882
  isStreaming?: boolean;
441
883
  className?: string;
884
+ onApplyCode?: (code: string, language: string) => void;
442
885
  }
443
886
 
444
887
  export declare interface McpConfig {
445
888
  id: string;
446
889
  name: string;
447
- serverUrl: string;
890
+ command: string;
891
+ type: 'http' | 'stdio';
892
+ args?: string[] | null;
893
+ env?: Record<string, string> | null;
894
+ cwd?: string | null;
448
895
  enabled: boolean;
449
896
  config?: any;
450
897
  createdAt: Date;
451
898
  updatedAt: Date;
899
+ app_ids?: string[];
452
900
  }
453
901
 
454
902
  export declare const McpManager: default_2.FC<McpManagerProps>;
455
903
 
456
904
  declare interface McpManagerProps {
457
905
  onClose?: () => void;
906
+ store?: any;
458
907
  }
459
908
 
460
909
  export declare interface McpToolConfig {
461
910
  name: string;
462
- serverUrl: string;
911
+ command: string;
463
912
  enabled: boolean;
464
913
  timeout: number;
465
914
  retryCount: number;
@@ -506,7 +955,7 @@ declare interface Message_2 {
506
955
  };
507
956
  }
508
957
 
509
- export declare const MessageItem: default_2.FC<MessageItemProps>;
958
+ export declare const MessageItem: default_2.NamedExoticComponent<MessageItemProps>;
510
959
 
511
960
  declare interface MessageItemProps {
512
961
  message: Message;
@@ -527,6 +976,8 @@ export declare interface MessageListProps {
527
976
  messages: Message[];
528
977
  isLoading?: boolean;
529
978
  isStreaming?: boolean;
979
+ hasMore?: boolean;
980
+ onLoadMore?: () => void;
530
981
  onMessageEdit?: (messageId: string, content: string) => void;
531
982
  onMessageDelete?: (messageId: string) => void;
532
983
  customRenderer?: {
@@ -535,6 +986,44 @@ export declare interface MessageListProps {
535
986
  };
536
987
  }
537
988
 
989
+ /**
990
+ * 统一的消息保存管理器
991
+ * 负责管理所有消息的保存逻辑,避免重复保存
992
+ */
993
+ export declare class MessageManager {
994
+ private pendingSaves;
995
+ private savedMessages;
996
+ private databaseService;
997
+ constructor(databaseService: DatabaseService);
998
+ /**
999
+ * 保存用户消息
1000
+ */
1001
+ saveUserMessage(data: Omit<Message, 'id'>): Promise<Message>;
1002
+ /**
1003
+ * 保存助手消息
1004
+ */
1005
+ saveAssistantMessage(data: Omit<Message, 'id'>): Promise<Message>;
1006
+ /**
1007
+ * 保存工具调用结果消息
1008
+ */
1009
+ saveToolMessage(data: Omit<Message, 'id'>): Promise<Message>;
1010
+ /**
1011
+ * 通用保存消息方法
1012
+ */
1013
+ saveMessage(data: Omit<Message, 'id'>): Promise<Message>;
1014
+ /**
1015
+ * 清理缓存(可选,用于内存管理)
1016
+ */
1017
+ clearCache(): void;
1018
+ /**
1019
+ * 获取缓存统计信息
1020
+ */
1021
+ getCacheStats(): {
1022
+ pendingCount: number;
1023
+ cachedCount: number;
1024
+ };
1025
+ }
1026
+
538
1027
  export declare type MessageRole = 'user' | 'assistant' | 'system' | 'tool';
539
1028
 
540
1029
  export declare type MessageStatus = 'pending' | 'streaming' | 'completed' | 'error';
@@ -543,6 +1032,10 @@ export declare const PencilIcon: default_2.FC<{
543
1032
  className?: string;
544
1033
  }>;
545
1034
 
1035
+ export declare const PlayIcon: default_2.FC<{
1036
+ className?: string;
1037
+ }>;
1038
+
546
1039
  export declare const PlusIcon: default_2.FC<{
547
1040
  className?: string;
548
1041
  }>;
@@ -602,16 +1095,15 @@ declare interface Session_2 {
602
1095
  export declare const SessionList: default_2.FC<SessionListProps_2>;
603
1096
 
604
1097
  export declare interface SessionListProps {
605
- sessions: Session[];
606
- currentSessionId?: string;
607
- onSessionSelect: (sessionId: string) => void;
608
- onSessionCreate: () => void;
609
- onSessionDelete: (sessionId: string) => void;
610
- onSessionRename: (sessionId: string, title: string) => void;
1098
+ isOpen?: boolean;
1099
+ onClose?: () => void;
1100
+ store?: any;
611
1101
  }
612
1102
 
613
1103
  declare interface SessionListProps_2 {
1104
+ isOpen?: boolean;
614
1105
  onClose?: () => void;
1106
+ store?: typeof useChatStore;
615
1107
  }
616
1108
 
617
1109
  /**
@@ -626,6 +1118,13 @@ export declare interface StandaloneChatInterfaceProps {
626
1118
  className?: string;
627
1119
  apiBaseUrl?: string;
628
1120
  port?: number;
1121
+ userId?: string;
1122
+ projectId?: string;
1123
+ showMcpManager?: boolean;
1124
+ showAiModelManager?: boolean;
1125
+ showSystemContextEditor?: boolean;
1126
+ showAgentManager?: boolean;
1127
+ onApplicationSelect?: (app: Application) => void;
629
1128
  }
630
1129
 
631
1130
  declare interface State {
@@ -650,10 +1149,22 @@ export declare interface StreamResponse {
650
1149
  metadata?: Record<string, any>;
651
1150
  }
652
1151
 
1152
+ export declare interface SystemContext {
1153
+ id: string;
1154
+ name: string;
1155
+ content: string;
1156
+ userId: string;
1157
+ isActive: boolean;
1158
+ createdAt: Date;
1159
+ updatedAt: Date;
1160
+ app_ids?: string[];
1161
+ }
1162
+
653
1163
  export declare const SystemContextEditor: default_2.FC<SystemContextEditorProps>;
654
1164
 
655
1165
  declare interface SystemContextEditorProps {
656
1166
  onClose?: () => void;
1167
+ store?: any;
657
1168
  }
658
1169
 
659
1170
  export declare type Theme = 'light' | 'dark' | 'auto';
@@ -698,37 +1209,7 @@ export declare const TrashIcon: default_2.FC<{
698
1209
  */
699
1210
  export declare function truncateText(text: string, maxLength: number): string;
700
1211
 
701
- export declare const useChatStore: UseBoundStore<Omit<Omit<Omit<StoreApi<ChatState & ChatActions>, "subscribe"> & {
702
- subscribe: {
703
- (listener: (selectedState: ChatState & ChatActions, previousSelectedState: ChatState & ChatActions) => void): () => void;
704
- <U>(selector: (state: ChatState & ChatActions) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
705
- equalityFn?: ((a: U, b: U) => boolean) | undefined;
706
- fireImmediately?: boolean;
707
- } | undefined): () => void;
708
- };
709
- }, "setState"> & {
710
- setState(nextStateOrUpdater: (ChatState & ChatActions) | Partial<ChatState & ChatActions> | ((state: WritableDraft<ChatState & ChatActions>) => void), shouldReplace?: boolean | undefined): void;
711
- }, "persist"> & {
712
- persist: {
713
- setOptions: (options: Partial<PersistOptions<ChatState & ChatActions, {
714
- theme: Theme;
715
- sidebarOpen: boolean;
716
- chatConfig: ChatConfig;
717
- selectedModelId: string | null;
718
- }>>) => void;
719
- clearStorage: () => void;
720
- rehydrate: () => Promise<void> | void;
721
- hasHydrated: () => boolean;
722
- onHydrate: (fn: (state: ChatState & ChatActions) => void) => () => void;
723
- onFinishHydration: (fn: (state: ChatState & ChatActions) => void) => () => void;
724
- getOptions: () => Partial<PersistOptions<ChatState & ChatActions, {
725
- theme: Theme;
726
- sidebarOpen: boolean;
727
- chatConfig: ChatConfig;
728
- selectedModelId: string | null;
729
- }>>;
730
- };
731
- }>;
1212
+ export declare const useChatStore: ChatStore;
732
1213
 
733
1214
  export declare const useTheme: () => {
734
1215
  theme: Theme_2;