react-ai-agent 1.5.6
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 +106 -0
- package/dist/index.cjs +1 -0
- package/dist/index.esm.js +1 -0
- package/dist/ui.css +1 -0
- package/index.d.ts +633 -0
- package/package.json +100 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactNode, ComponentType, RefObject, ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Core Types
|
|
6
|
+
// ============================================================================
|
|
7
|
+
|
|
8
|
+
export interface SessionData {
|
|
9
|
+
sessionId: string;
|
|
10
|
+
token?: string;
|
|
11
|
+
refreshToken?: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface AuthConfig {
|
|
16
|
+
sessionId: string;
|
|
17
|
+
accessToken: string;
|
|
18
|
+
refreshToken?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface WelcomeConfig {
|
|
22
|
+
title?: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
component?: React.ReactNode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TypingAnimationConfig {
|
|
28
|
+
mode?: 'char' | 'word' | 'batch' | 'instant';
|
|
29
|
+
speed?: number; // Units per second
|
|
30
|
+
batchSize?: number; // Characters per batch (for 'batch' mode)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ForwardingMetadata {
|
|
34
|
+
action: string;
|
|
35
|
+
isLive: boolean;
|
|
36
|
+
event: 'chunk' | 'end';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type ForwardingHandler = (
|
|
40
|
+
incrementalText: string,
|
|
41
|
+
fullText: string,
|
|
42
|
+
metadata: ForwardingMetadata
|
|
43
|
+
) => void;
|
|
44
|
+
|
|
45
|
+
export interface ForwardingHandlerConfig {
|
|
46
|
+
handler: ForwardingHandler;
|
|
47
|
+
mode?: 'dual' | 'replace' | 'raw';
|
|
48
|
+
animated?: boolean;
|
|
49
|
+
subscriptionMode?: 'delta' | 'full';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ForwardingHandlers {
|
|
53
|
+
[action: string]: ForwardingHandlerConfig;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface Message {
|
|
57
|
+
id: string;
|
|
58
|
+
role: 'user' | 'assistant' | 'system';
|
|
59
|
+
content: string;
|
|
60
|
+
timestamp?: number;
|
|
61
|
+
isLive?: boolean;
|
|
62
|
+
thinking?: string;
|
|
63
|
+
tools?: any[];
|
|
64
|
+
files?: AttachedFile[];
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface AttachedFile {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
size: number;
|
|
72
|
+
type: string;
|
|
73
|
+
url?: string;
|
|
74
|
+
preview?: string;
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface SessionMetrics {
|
|
79
|
+
usedTokens?: number;
|
|
80
|
+
contextLimit?: number;
|
|
81
|
+
[key: string]: any;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface StreamError {
|
|
85
|
+
message: string;
|
|
86
|
+
code?: string;
|
|
87
|
+
[key: string]: any;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ============================================================================
|
|
91
|
+
// Chat Context
|
|
92
|
+
// ============================================================================
|
|
93
|
+
|
|
94
|
+
export interface SendMessageParams {
|
|
95
|
+
messageId?: string;
|
|
96
|
+
message?: string;
|
|
97
|
+
attachedFiles?: AttachedFile[];
|
|
98
|
+
uploadId?: string | null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface StatusRegistry {
|
|
102
|
+
register: (action: string, handler: (statusData: any) => void) => () => void;
|
|
103
|
+
registerGlobal: (handler: (statusData: any) => void) => () => void;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface ChatContextValue {
|
|
107
|
+
// Message operations
|
|
108
|
+
sendMsg: (params?: SendMessageParams) => Promise<void>;
|
|
109
|
+
messages: any[];
|
|
110
|
+
messageManager: {
|
|
111
|
+
addMessage: (msg: any) => any;
|
|
112
|
+
updateMessage: (id: string, updates: any, options?: { silent?: boolean }) => any;
|
|
113
|
+
removeMessage: (id: string) => boolean;
|
|
114
|
+
getMessage: (id: string) => any;
|
|
115
|
+
clear: () => void;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Loading states
|
|
119
|
+
isLoading: boolean;
|
|
120
|
+
isStreaming: boolean;
|
|
121
|
+
isResponseStarted: boolean;
|
|
122
|
+
isInitialLoading: boolean;
|
|
123
|
+
isLoadingMore: boolean;
|
|
124
|
+
|
|
125
|
+
// Error handling
|
|
126
|
+
error: any;
|
|
127
|
+
streamError: any;
|
|
128
|
+
clearStreamError: () => void;
|
|
129
|
+
|
|
130
|
+
// Message history
|
|
131
|
+
getHistory: () => Promise<void>;
|
|
132
|
+
loadMoreMessages: () => Promise<void>;
|
|
133
|
+
hasMoreMessages: boolean;
|
|
134
|
+
enableHistory: boolean;
|
|
135
|
+
|
|
136
|
+
// Retry & Control
|
|
137
|
+
retryLastMessage: () => Promise<void>;
|
|
138
|
+
abort: () => any;
|
|
139
|
+
|
|
140
|
+
// Session management
|
|
141
|
+
sessionId: string | undefined;
|
|
142
|
+
setSessionId: (id: string | undefined) => void;
|
|
143
|
+
|
|
144
|
+
// Instance identification
|
|
145
|
+
instanceId: string;
|
|
146
|
+
|
|
147
|
+
// File management
|
|
148
|
+
currentSelectedFile: any;
|
|
149
|
+
setCurrentSelectedFile: (file: any) => void;
|
|
150
|
+
|
|
151
|
+
// Welcome message
|
|
152
|
+
welcome: any;
|
|
153
|
+
|
|
154
|
+
// Status handling
|
|
155
|
+
statusRegistry: StatusRegistry;
|
|
156
|
+
|
|
157
|
+
// Markdown components
|
|
158
|
+
markdownComponents: any;
|
|
159
|
+
|
|
160
|
+
// Typing animation config
|
|
161
|
+
typingAnimation: TypingAnimationConfig;
|
|
162
|
+
|
|
163
|
+
// Status components
|
|
164
|
+
statusComponents?: any;
|
|
165
|
+
|
|
166
|
+
// Loading component
|
|
167
|
+
loadingComponent?: ComponentType<any>;
|
|
168
|
+
|
|
169
|
+
// Header component
|
|
170
|
+
headerComponent?: React.ReactNode;
|
|
171
|
+
|
|
172
|
+
// Debug
|
|
173
|
+
debug?: boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function useChatContext(): ChatContextValue;
|
|
177
|
+
|
|
178
|
+
// ============================================================================
|
|
179
|
+
// Chat Provider
|
|
180
|
+
// ============================================================================
|
|
181
|
+
|
|
182
|
+
export interface ChatProviderProps {
|
|
183
|
+
children: ReactNode;
|
|
184
|
+
debug?: boolean;
|
|
185
|
+
initialWelcome?: any;
|
|
186
|
+
authConfig?: AuthConfig;
|
|
187
|
+
markdownComponents?: any;
|
|
188
|
+
typingAnimation?: TypingAnimationConfig;
|
|
189
|
+
statusComponents?: any;
|
|
190
|
+
forwardingHandlers?: ForwardingHandlers;
|
|
191
|
+
enableHistory?: boolean;
|
|
192
|
+
loadingComponent?: ComponentType<any>;
|
|
193
|
+
headerComponent?: ComponentType<any>;
|
|
194
|
+
allowThinking?: boolean;
|
|
195
|
+
config?: any;
|
|
196
|
+
agentId?: string; // Unique identifier for multi-instance support
|
|
197
|
+
refreshTokenCallback?: (refreshToken: string) => Promise<any>;
|
|
198
|
+
onError?: (error: any) => void; // Error handler callback
|
|
199
|
+
// Legacy support (deprecated)
|
|
200
|
+
sessionData?: SessionData | null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function ChatProvider(props: ChatProviderProps): ReactElement;
|
|
204
|
+
|
|
205
|
+
// ============================================================================
|
|
206
|
+
// Components
|
|
207
|
+
// ============================================================================
|
|
208
|
+
|
|
209
|
+
export interface DefaultPanelProps {
|
|
210
|
+
onCreateSession?: () => void;
|
|
211
|
+
isDark?: boolean;
|
|
212
|
+
allowEditMessage?: boolean;
|
|
213
|
+
config?: {
|
|
214
|
+
chatUrl?: string;
|
|
215
|
+
uploadUrl?: string;
|
|
216
|
+
historyUrl?: string;
|
|
217
|
+
prepareSessionUrl?: string;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export const DefaultPanel: ComponentType<DefaultPanelProps>;
|
|
222
|
+
|
|
223
|
+
// ============================================================================
|
|
224
|
+
// ChatCore - Standalone Message Rendering Component
|
|
225
|
+
// ============================================================================
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Ref handle for ChatCore component
|
|
229
|
+
* Provides imperative access to scroll, messages, and stream control
|
|
230
|
+
*/
|
|
231
|
+
export interface ChatCoreRef {
|
|
232
|
+
/** Scroll the message container to bottom */
|
|
233
|
+
scrollToBottom: () => void;
|
|
234
|
+
/** Check if scroll is at bottom */
|
|
235
|
+
isAtBottom: () => boolean;
|
|
236
|
+
/** Direct access to scroll container element */
|
|
237
|
+
scrollContainer: HTMLDivElement | null;
|
|
238
|
+
/** TanStack virtualizer instance */
|
|
239
|
+
virtualizer: any;
|
|
240
|
+
/** Send a message (wraps context sendMsg with auto-scroll) */
|
|
241
|
+
sendMessage: (messageData?: SendMessageParams) => Promise<void>;
|
|
242
|
+
/** Abort current streaming response */
|
|
243
|
+
abort: () => any;
|
|
244
|
+
/** Current streaming state */
|
|
245
|
+
isStreaming: boolean;
|
|
246
|
+
/** Current loading state */
|
|
247
|
+
isLoading: boolean;
|
|
248
|
+
/** Current messages array */
|
|
249
|
+
messages: any[];
|
|
250
|
+
/** Message manager instance */
|
|
251
|
+
messageManager: ChatContextValue['messageManager'];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface ChatCoreProps {
|
|
255
|
+
/** Enable dark theme */
|
|
256
|
+
isDark?: boolean;
|
|
257
|
+
/** Additional CSS classes for the container */
|
|
258
|
+
className?: string;
|
|
259
|
+
/** Allow editing messages */
|
|
260
|
+
allowEditMessage?: boolean;
|
|
261
|
+
/** Show welcome screen when no messages */
|
|
262
|
+
showWelcome?: boolean;
|
|
263
|
+
/** Show load more button for history */
|
|
264
|
+
showLoadMore?: boolean;
|
|
265
|
+
/** Show loading indicator during response */
|
|
266
|
+
showLoadingIndicator?: boolean;
|
|
267
|
+
/** Custom welcome component */
|
|
268
|
+
welcomeComponent?: ComponentType<{ error?: any }>;
|
|
269
|
+
/** Custom loading component (overrides context loadingComponent) */
|
|
270
|
+
loadingComponent?: ComponentType<any>;
|
|
271
|
+
/** Additional inline styles for container */
|
|
272
|
+
containerStyle?: React.CSSProperties;
|
|
273
|
+
/** Enable gradient mask on scroll */
|
|
274
|
+
useGradientMask?: boolean;
|
|
275
|
+
/** Custom gradient mask CSS value */
|
|
276
|
+
gradientMaskStyle?: string;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* ChatCore - Standalone message rendering component
|
|
281
|
+
*
|
|
282
|
+
* Renders messages with virtualization and scroll handling.
|
|
283
|
+
* Must be used within a ChatProvider context.
|
|
284
|
+
*
|
|
285
|
+
* @example Basic usage
|
|
286
|
+
* ```tsx
|
|
287
|
+
* <ChatProvider authConfig={authConfig}>
|
|
288
|
+
* <ChatCore isDark={true} className="h-full" />
|
|
289
|
+
* </ChatProvider>
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* @example With ref for imperative access
|
|
293
|
+
* ```tsx
|
|
294
|
+
* const coreRef = useRef<ChatCoreRef>(null);
|
|
295
|
+
*
|
|
296
|
+
* <ChatProvider authConfig={authConfig}>
|
|
297
|
+
* <ChatCore ref={coreRef} />
|
|
298
|
+
* <button onClick={() => coreRef.current?.scrollToBottom()}>
|
|
299
|
+
* Scroll to bottom
|
|
300
|
+
* </button>
|
|
301
|
+
* </ChatProvider>
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* @example Custom layout with ChatInput
|
|
305
|
+
* ```tsx
|
|
306
|
+
* <ChatProvider authConfig={authConfig}>
|
|
307
|
+
* <div className="flex flex-col h-screen">
|
|
308
|
+
* <ChatCore className="flex-1" isDark={true} />
|
|
309
|
+
* <ChatInput onSend={handleSend} />
|
|
310
|
+
* </div>
|
|
311
|
+
* </ChatProvider>
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
export const ChatCore: React.ForwardRefExoticComponent<
|
|
315
|
+
ChatCoreProps & React.RefAttributes<ChatCoreRef>
|
|
316
|
+
>;
|
|
317
|
+
|
|
318
|
+
export interface MessageItemProps {
|
|
319
|
+
message: Message;
|
|
320
|
+
isLast?: boolean;
|
|
321
|
+
theme?: string;
|
|
322
|
+
[key: string]: any;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export const MessageItem: ComponentType<MessageItemProps>;
|
|
326
|
+
|
|
327
|
+
export interface ChatInputProps {
|
|
328
|
+
onSend?: (message: string, files?: AttachedFile[]) => void;
|
|
329
|
+
disabled?: boolean;
|
|
330
|
+
placeholder?: string;
|
|
331
|
+
[key: string]: any;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export const ChatInput: ComponentType<ChatInputProps>;
|
|
335
|
+
|
|
336
|
+
export interface ChatHeaderProps {
|
|
337
|
+
title?: string;
|
|
338
|
+
subtitle?: string;
|
|
339
|
+
onClose?: () => void;
|
|
340
|
+
[key: string]: any;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export const ChatHeader: ComponentType<ChatHeaderProps>;
|
|
344
|
+
|
|
345
|
+
export interface ModeToggleProps {
|
|
346
|
+
currentMode: 'sse' | 'websocket';
|
|
347
|
+
onModeChange: (mode: 'sse' | 'websocket') => void;
|
|
348
|
+
[key: string]: any;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export const ModeToggle: ComponentType<ModeToggleProps>;
|
|
352
|
+
|
|
353
|
+
export interface StatusBlockProps {
|
|
354
|
+
status?: any;
|
|
355
|
+
message?: any;
|
|
356
|
+
[key: string]: any;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export const StatusBlock: ComponentType<StatusBlockProps>;
|
|
360
|
+
|
|
361
|
+
export interface ShimmerTextProps {
|
|
362
|
+
text?: string;
|
|
363
|
+
[key: string]: any;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export const ShimmerText: ComponentType<ShimmerTextProps>;
|
|
367
|
+
|
|
368
|
+
export interface StartChatProps {
|
|
369
|
+
error?: any;
|
|
370
|
+
miniMode?: boolean;
|
|
371
|
+
[key: string]: any;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export const StartChat: ComponentType<StartChatProps>;
|
|
375
|
+
|
|
376
|
+
export interface LoadingResponseProps {
|
|
377
|
+
type?: 'text' | 'dots';
|
|
378
|
+
[key: string]: any;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export const LoadingResponse: ComponentType<LoadingResponseProps>;
|
|
382
|
+
|
|
383
|
+
export interface ChatLoadingMockProps {
|
|
384
|
+
[key: string]: any;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export const ChatLoadingMock: ComponentType<ChatLoadingMockProps>;
|
|
388
|
+
|
|
389
|
+
// ============================================================================
|
|
390
|
+
// Services & Managers
|
|
391
|
+
// ============================================================================
|
|
392
|
+
|
|
393
|
+
export declare class TokenManager {
|
|
394
|
+
setTokens: (tokens: SessionData) => void;
|
|
395
|
+
setAuth: (auth: AuthConfig) => Promise<void>;
|
|
396
|
+
getAccessToken: () => string | null;
|
|
397
|
+
getRefreshToken: () => string | null;
|
|
398
|
+
clearTokens: () => void;
|
|
399
|
+
setRefreshCallback: (callback: (refreshToken: string) => Promise<any>) => void;
|
|
400
|
+
[key: string]: any;
|
|
401
|
+
|
|
402
|
+
constructor();
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export declare class SessionManager {
|
|
406
|
+
getSessionId: () => string | null;
|
|
407
|
+
setSessionId: (id: string) => void;
|
|
408
|
+
clearSession: () => void;
|
|
409
|
+
[key: string]: any;
|
|
410
|
+
|
|
411
|
+
constructor();
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export declare class ChatApi {
|
|
415
|
+
sendMessage: (message: string, sessionId?: string, files?: AttachedFile[]) => Promise<any>;
|
|
416
|
+
getHistory: (sessionId: string, limit?: number, offset?: number) => Promise<any>;
|
|
417
|
+
abort: () => void;
|
|
418
|
+
[key: string]: any;
|
|
419
|
+
|
|
420
|
+
constructor(tokenManager: TokenManager, config?: any);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export declare class StreamService {
|
|
424
|
+
setMode: (mode: 'sse' | 'websocket', websocketService?: any) => void;
|
|
425
|
+
connect: (sessionId: string, onMessage: (data: any) => void, onError?: (error: Error) => void) => void;
|
|
426
|
+
disconnect: () => void;
|
|
427
|
+
isConnected: () => boolean;
|
|
428
|
+
on: (event: string, handler: (data: any) => void) => void;
|
|
429
|
+
off: (event: string, handler: (data: any) => void) => void;
|
|
430
|
+
startStream: (params: any, feedbackClient?: any, rawFeedback?: boolean) => Promise<any>;
|
|
431
|
+
abort: () => void;
|
|
432
|
+
[key: string]: any;
|
|
433
|
+
|
|
434
|
+
constructor(chatApi: ChatApi);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export default class WebSocketService {
|
|
438
|
+
connect: (sessionId: string, onMessage: (data: any) => void, onError?: (error: Error) => void) => void;
|
|
439
|
+
disconnect: () => void;
|
|
440
|
+
send: (data: any) => void;
|
|
441
|
+
isConnected: () => boolean;
|
|
442
|
+
[key: string]: any;
|
|
443
|
+
|
|
444
|
+
constructor();
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// ============================================================================
|
|
448
|
+
// Forwarding Hook
|
|
449
|
+
// ============================================================================
|
|
450
|
+
|
|
451
|
+
export interface UseForwardingReturn {
|
|
452
|
+
register: (action: string, handler: ForwardingHandler, options?: Partial<ForwardingHandlerConfig>) => () => void;
|
|
453
|
+
unregister: (action: string) => void;
|
|
454
|
+
getActiveSessions: () => string[];
|
|
455
|
+
getHandler: (action: string) => ForwardingHandlerConfig | undefined;
|
|
456
|
+
getAllHandlers: () => Array<{ action: string } & ForwardingHandlerConfig>;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export function useForwarding(
|
|
460
|
+
action: string,
|
|
461
|
+
handler: ForwardingHandler,
|
|
462
|
+
options?: Partial<ForwardingHandlerConfig>
|
|
463
|
+
): UseForwardingReturn;
|
|
464
|
+
|
|
465
|
+
export function useForwarding(
|
|
466
|
+
handlers: ForwardingHandlers
|
|
467
|
+
): UseForwardingReturn;
|
|
468
|
+
|
|
469
|
+
export function useForwarding(): UseForwardingReturn;
|
|
470
|
+
|
|
471
|
+
// ============================================================================
|
|
472
|
+
// Status Subscription Hook
|
|
473
|
+
// ============================================================================
|
|
474
|
+
|
|
475
|
+
export interface UseStatusSubscriptionOptions {
|
|
476
|
+
instanceId?: string;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export type StatusHandler = (statusData: any) => void;
|
|
480
|
+
|
|
481
|
+
export type StatusHandlers = {
|
|
482
|
+
[action: string]: StatusHandler;
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Hook to subscribe to status notifications from ChatProvider
|
|
487
|
+
*
|
|
488
|
+
* @example Single action (inside ChatProvider)
|
|
489
|
+
* useStatusSubscription('tool_call', (statusData) => {
|
|
490
|
+
* console.log('Tool call status:', statusData);
|
|
491
|
+
* });
|
|
492
|
+
*
|
|
493
|
+
* @example Multiple actions
|
|
494
|
+
* useStatusSubscription({
|
|
495
|
+
* tool_call: (data) => console.log('Tool:', data),
|
|
496
|
+
* edit_file: (data) => console.log('Edit:', data)
|
|
497
|
+
* });
|
|
498
|
+
*
|
|
499
|
+
* @example Listen to specific instance (outside ChatProvider)
|
|
500
|
+
* useStatusSubscription('tool_call', handler, { instanceId: 'agent-123' });
|
|
501
|
+
*
|
|
502
|
+
* @example Global listener (all instances)
|
|
503
|
+
* useStatusSubscription('*', (data) => console.log('All statuses:', data));
|
|
504
|
+
*/
|
|
505
|
+
export function useStatusSubscription(
|
|
506
|
+
action: string,
|
|
507
|
+
handler: StatusHandler,
|
|
508
|
+
options?: UseStatusSubscriptionOptions
|
|
509
|
+
): void;
|
|
510
|
+
|
|
511
|
+
export function useStatusSubscription(
|
|
512
|
+
handlers: StatusHandlers,
|
|
513
|
+
handler?: never,
|
|
514
|
+
options?: UseStatusSubscriptionOptions
|
|
515
|
+
): void;
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Context to provide instanceId for multi-instance support
|
|
519
|
+
* Used internally by ChatProvider
|
|
520
|
+
*/
|
|
521
|
+
export const ChatInstanceContext: React.Context<string | null>;
|
|
522
|
+
|
|
523
|
+
// ============================================================================
|
|
524
|
+
// Forwarding Manager
|
|
525
|
+
// ============================================================================
|
|
526
|
+
|
|
527
|
+
export declare class ForwardingManager {
|
|
528
|
+
handlers: ForwardingHandlers;
|
|
529
|
+
register(action: string, handler: ForwardingHandler, options?: Partial<ForwardingHandlerConfig>): () => void;
|
|
530
|
+
startSession(statusId: string, action: string): boolean;
|
|
531
|
+
endSession(statusId: string): void;
|
|
532
|
+
isActive(statusId: string): boolean;
|
|
533
|
+
getSession(statusId: string): any;
|
|
534
|
+
forwardChunk(statusId: string, newText: string, isLive?: boolean): boolean;
|
|
535
|
+
shouldReplace(statusId: string): boolean;
|
|
536
|
+
isAnimated(statusId: string): boolean;
|
|
537
|
+
getActiveSessions(): string[];
|
|
538
|
+
clearAll(): void;
|
|
539
|
+
constructor(forwardingHandlers?: ForwardingHandlers);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export function getGlobalForwardingManager(initialHandlers?: ForwardingHandlers): ForwardingManager;
|
|
543
|
+
export function setGlobalForwardingManager(instance: ForwardingManager): void;
|
|
544
|
+
export function resetGlobalForwardingManager(): void;
|
|
545
|
+
|
|
546
|
+
// ============================================================================
|
|
547
|
+
// Status Handler Registry
|
|
548
|
+
// ============================================================================
|
|
549
|
+
|
|
550
|
+
export interface StatusFilter {
|
|
551
|
+
instanceId?: string;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export declare class StatusHandlerRegistry {
|
|
555
|
+
handlers: Map<string, Array<{ handler: StatusHandler; filter: StatusFilter }>>;
|
|
556
|
+
globalHandlers: Array<{ handler: StatusHandler; filter: StatusFilter }>;
|
|
557
|
+
streamForwarders: Map<string, any>;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Register a handler for a specific status type
|
|
561
|
+
* @param statusType - The status type to handle (e.g., 'tool_call', 'prompt_create')
|
|
562
|
+
* @param handler - Handler function (statusData) => void
|
|
563
|
+
* @param filter - Optional filter { instanceId: string }
|
|
564
|
+
*/
|
|
565
|
+
register(statusType: string, handler: StatusHandler, filter?: StatusFilter): () => void;
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Register a global handler that receives all status messages
|
|
569
|
+
* @param handler - Handler function (statusData) => void
|
|
570
|
+
* @param filter - Optional filter { instanceId: string }
|
|
571
|
+
*/
|
|
572
|
+
registerGlobal(handler: StatusHandler, filter?: StatusFilter): () => void;
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Execute handlers for a status message
|
|
576
|
+
* @param statusData - Status data from the stream
|
|
577
|
+
*/
|
|
578
|
+
handle(statusData: any): Promise<void>;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Register a stream forwarder
|
|
582
|
+
*/
|
|
583
|
+
registerStreamForwarder(forwarder: any): { id: string; stop: () => void };
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Forward stream data to registered forwarders
|
|
587
|
+
*/
|
|
588
|
+
forwardStream(messageId: string, data: any): void;
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Clear all handlers
|
|
592
|
+
*/
|
|
593
|
+
clear(): void;
|
|
594
|
+
|
|
595
|
+
constructor();
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Get the global status registry (single instance - event bus pattern)
|
|
600
|
+
* This is the single source of truth for all status events
|
|
601
|
+
*/
|
|
602
|
+
export function getGlobalStatusRegistry(): StatusHandlerRegistry;
|
|
603
|
+
|
|
604
|
+
// ============================================================================
|
|
605
|
+
// Message Manager
|
|
606
|
+
// ============================================================================
|
|
607
|
+
|
|
608
|
+
export declare class MessageManager {
|
|
609
|
+
messages: any[];
|
|
610
|
+
subscribers: Set<(messages: any[]) => void>;
|
|
611
|
+
|
|
612
|
+
addMessage(msg: any): any;
|
|
613
|
+
updateMessage(id: string, updates: any, options?: { silent?: boolean }): any;
|
|
614
|
+
removeMessage(id: string): boolean;
|
|
615
|
+
getMessage(id: string): any;
|
|
616
|
+
insertMessages(messages: any[], position?: 'start' | 'end'): void;
|
|
617
|
+
subscribe(callback: (messages: any[]) => void): () => void;
|
|
618
|
+
clear(): void;
|
|
619
|
+
|
|
620
|
+
get count(): number;
|
|
621
|
+
|
|
622
|
+
constructor();
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// ============================================================================
|
|
626
|
+
// CSS Import
|
|
627
|
+
// ============================================================================
|
|
628
|
+
|
|
629
|
+
declare module 'react-chat-agent/ui.css' {
|
|
630
|
+
const content: string;
|
|
631
|
+
export default content;
|
|
632
|
+
}
|
|
633
|
+
|