forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprops.ts
More file actions
386 lines (323 loc) · 8.82 KB
/
Copy pathprops.ts
File metadata and controls
386 lines (323 loc) · 8.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
import {
AIMessage,
Message,
UserMessage,
CopilotErrorEvent,
} from "@copilotkit/shared";
import { CopilotChatSuggestion } from "../../types/suggestions";
import { ReactNode } from "react";
import { ImageData } from "@copilotkit/shared";
import type { InputContentSource } from "@copilotkit/shared";
import type {
AttachmentsConfig,
Attachment,
AttachmentModality,
} from "@copilotkit/shared";
// Re-export for backward compat
export type { AttachmentsConfig, Attachment, AttachmentModality };
/**
* Event hooks for CopilotKit chat events.
* These hooks only work when publicApiKey is provided.
*/
export interface CopilotObservabilityHooks {
/**
* Called when a message is sent by the user
*/
onMessageSent?: (message: string) => void;
/**
* Called when the chat is minimized/closed
*/
onChatMinimized?: () => void;
/**
* Called when the chat is expanded/opened
*/
onChatExpanded?: () => void;
/**
* Called when a message is regenerated
*/
onMessageRegenerated?: (messageId: string) => void;
/**
* Called when a message is copied
*/
onMessageCopied?: (content: string) => void;
/**
* Called when feedback is given (thumbs up/down)
*/
onFeedbackGiven?: (
messageId: string,
type: "thumbsUp" | "thumbsDown",
) => void;
/**
* Called when chat generation starts
*/
onChatStarted?: () => void;
/**
* Called when chat generation stops
*/
onChatStopped?: () => void;
/**
* Called when an error occurs in the chat
* This enables chat-specific error handling UX while preserving system-wide error monitoring
*/
onError?: (errorEvent: CopilotErrorEvent) => void;
}
export interface ButtonProps {}
export interface WindowProps {
clickOutsideToClose: boolean;
hitEscapeToClose: boolean;
shortcut: string;
children?: React.ReactNode;
}
export interface HeaderProps {}
export interface SuggestionsProps {
title: string;
message: string;
partial?: boolean;
className?: string;
onClick: (message: string) => void;
}
export type ComponentsMap<
T extends Record<string, object> = Record<string, object>,
> = {
[K in keyof T]: React.FC<{ children?: ReactNode } & T[K]>;
};
export interface MessagesProps {
messages: Message[];
inProgress: boolean;
children?: React.ReactNode;
chatError?: ChatError | null;
AssistantMessage: React.ComponentType<AssistantMessageProps>;
UserMessage: React.ComponentType<UserMessageProps>;
ErrorMessage?: React.ComponentType<ErrorMessageProps>;
RenderMessage: React.ComponentType<RenderMessageProps>;
ImageRenderer: React.ComponentType<ImageRendererProps>;
/**
* Callback function to regenerate the assistant's response
*/
onRegenerate?: (messageId: string) => void;
/**
* Callback function when the message is copied
*/
onCopy?: (message: string) => void;
/**
* Callback function for thumbs up feedback
*/
onThumbsUp?: (message: Message) => void;
/**
* Callback function for thumbs down feedback
*/
onThumbsDown?: (message: Message) => void;
/**
* Map of message IDs to their feedback state
*/
messageFeedback?: Record<string, "thumbsUp" | "thumbsDown">;
/**
* A list of markdown components to render in assistant message.
* Useful when you want to render custom elements in the message (e.g a reference tag element)
*/
markdownTagRenderers?: ComponentsMap;
/**
* @deprecated Use RenderMessage instead
*/
RenderTextMessage?: React.ComponentType<RenderMessageProps>;
/**
* @deprecated Use RenderMessage instead
*/
RenderActionExecutionMessage?: React.ComponentType<RenderMessageProps>;
/**
* @deprecated Use RenderMessage instead
*/
RenderAgentStateMessage?: React.ComponentType<RenderMessageProps>;
/**
* @deprecated Use RenderMessage instead
*/
RenderResultMessage?: React.ComponentType<RenderMessageProps>;
/**
* @deprecated Use RenderMessage instead
*/
RenderImageMessage?: React.ComponentType<RenderMessageProps>;
}
export interface Renderer {
content: string;
}
export interface UserMessageProps {
message?: UserMessage;
ImageRenderer: React.ComponentType<ImageRendererProps>;
/**
* @deprecated use message instead
*
* The raw data from the assistant's response
*/
rawData: any;
}
export interface AssistantMessageProps {
/**
* The message content from the assistant
*/
message?: AIMessage;
messages?: Message[];
/**
* Indicates if this is the last message
*/
isCurrentMessage?: boolean;
/**
* Whether a response is loading, this is when the LLM is thinking of a response but hasn't finished yet.
*/
isLoading: boolean;
/**
* Whether a response is generating, this is when the LLM is actively generating and streaming content.
*/
isGenerating: boolean;
/**
* Callback function to regenerate the assistant's response
*/
onRegenerate?: () => void;
/**
* Callback function when the message is copied
*/
onCopy?: (message: string) => void;
/**
* Callback function for thumbs up feedback
*/
onThumbsUp?: (message: Message) => void;
/**
* Callback function for thumbs down feedback
*/
onThumbsDown?: (message: Message) => void;
/**
* The feedback state for this message ("thumbsUp" or "thumbsDown")
*/
feedback?: "thumbsUp" | "thumbsDown" | null;
/**
* A list of markdown components to render in assistant message.
* Useful when you want to render custom elements in the message (e.g a reference tag element)
*/
markdownTagRenderers?: ComponentsMap;
/**
* A custom image rendering component to use instead of the default.
*/
ImageRenderer?: React.ComponentType<ImageRendererProps>;
/**
* @deprecated use message instead
*
* The raw data from the assistant's response
*/
rawData: any;
/**
*
* @deprecated
*
* use `message.generativeUI()` instead.
*
* For example:
*
* ```tsx
* const CustomAssistantMessage = ({ message }: AssistantMessageProps) => {
* const subComponent = message?.generativeUI?.();
* return <div>{subComponent}</div>;
* };
*
* ```
*/
subComponent?: React.JSX.Element;
}
export interface ErrorMessageProps {
/**
* The message content from the assistant
*/
error: ChatError;
/**
* Indicates if this is the last message
*/
isCurrentMessage?: boolean;
/**
* Callback function to regenerate the assistant's response
*/
onRegenerate?: () => void;
/**
* Callback function when the message is copied
*/
onCopy?: (message: string) => void;
}
export interface RenderMessageProps {
message: Message;
messages: Message[];
inProgress: boolean;
index: number;
isCurrentMessage: boolean;
actionResult?: string;
AssistantMessage?: React.ComponentType<AssistantMessageProps>;
UserMessage?: React.ComponentType<UserMessageProps>;
ImageRenderer?: React.ComponentType<ImageRendererProps>;
/**
* Callback function to regenerate the assistant's response
*/
onRegenerate?: (messageId: string) => void;
/**
* Callback function when the message is copied
*/
onCopy?: (message: string) => void;
/**
* Callback function for thumbs up feedback
*/
onThumbsUp?: (message: Message) => void;
/**
* Callback function for thumbs down feedback
*/
onThumbsDown?: (message: Message) => void;
/**
* Map of message IDs to their feedback state
*/
messageFeedback?: Record<string, "thumbsUp" | "thumbsDown">;
/**
* A list of markdown components to render in assistant message.
* Useful when you want to render custom elements in the message (e.g a reference tag element)
*/
markdownTagRenderers?: ComponentsMap;
}
export interface InputProps {
inProgress: boolean;
onSend: (text: string) => Promise<Message>;
isVisible?: boolean;
onStop?: () => void;
onUpload?: () => void;
hideStopButton?: boolean;
chatReady?: boolean;
}
export interface RenderSuggestionsListProps {
suggestions: CopilotChatSuggestion[];
onSuggestionClick: (message: string) => void;
isLoading: boolean;
}
/**
* @deprecated Use `CopilotChatAttachmentRenderer` from `@copilotkit/react-core/v2` instead.
* See https://docs.copilotkit.ai/migration-guides/migrate-attachments
* @since 1.56.0
*/
export interface ImageRendererProps {
/**
* @deprecated Use `source` (type `InputContentSource`) instead.
* `image` only carried base64 image data. `source` supports both data and URL
* sources for any modality.
* See https://docs.copilotkit.ai/migration-guides/migrate-attachments
* @since 1.56.0
*/
image?: ImageData;
/**
* The content source for the image (new AG-UI format)
*/
source?: InputContentSource;
/**
* Optional content to display alongside the image
*/
content?: string;
/**
* Additional CSS class name for styling
*/
className?: string;
}
export interface ChatError {
message: string;
operation?: string;
timestamp: number;
}