@autobe/ui 0.30.2 → 0.30.4-dev.20260324

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.
Files changed (69) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +261 -0
  3. package/lib/components/AutoBeChatMain.d.ts +6 -0
  4. package/lib/components/AutoBeChatMain.js +46 -37
  5. package/lib/components/AutoBeChatMain.js.map +1 -1
  6. package/lib/components/AutoBeConfigModal.js +9 -9
  7. package/lib/components/events/AutoBeEventMovie.js +0 -4
  8. package/lib/components/events/AutoBeEventMovie.js.map +1 -1
  9. package/lib/components/events/AutoBeProgressEventMovie.js +0 -10
  10. package/lib/components/events/AutoBeProgressEventMovie.js.map +1 -1
  11. package/lib/components/upload/AutoBeChatUploadBox.d.ts +1 -0
  12. package/lib/components/upload/AutoBeChatUploadBox.js +11 -16
  13. package/lib/components/upload/AutoBeChatUploadBox.js.map +1 -1
  14. package/lib/context/AutoBeAgentContext.js +78 -30
  15. package/lib/context/AutoBeAgentContext.js.map +1 -1
  16. package/lib/context/SearchParamsContext.js +1 -1
  17. package/lib/context/SearchParamsContext.js.map +1 -1
  18. package/lib/structure/AutoBeListener.d.ts +1 -0
  19. package/lib/structure/AutoBeListener.js +9 -11
  20. package/lib/structure/AutoBeListener.js.map +1 -1
  21. package/package.json +2 -2
  22. package/src/components/AutoBeAssistantMessageMovie.tsx +22 -22
  23. package/src/components/AutoBeChatMain.tsx +394 -376
  24. package/src/components/AutoBeChatSidebar.tsx +414 -414
  25. package/src/components/AutoBeConfigButton.tsx +83 -83
  26. package/src/components/AutoBeConfigModal.tsx +443 -443
  27. package/src/components/AutoBeStatusButton.tsx +75 -75
  28. package/src/components/AutoBeStatusModal.tsx +486 -486
  29. package/src/components/AutoBeUserMessageMovie.tsx +27 -27
  30. package/src/components/common/ActionButton.tsx +205 -205
  31. package/src/components/common/ActionButtonGroup.tsx +80 -80
  32. package/src/components/common/AutoBeConfigInput.tsx +185 -185
  33. package/src/components/common/ChatBubble.tsx +119 -119
  34. package/src/components/common/Collapsible.tsx +95 -95
  35. package/src/components/common/CompactSessionIndicator.tsx +73 -73
  36. package/src/components/common/CompactSessionList.tsx +82 -82
  37. package/src/components/common/openai/OpenAIContent.tsx +53 -53
  38. package/src/components/common/openai/OpenAIUserAudioContent.tsx +70 -70
  39. package/src/components/common/openai/OpenAIUserFileContent.tsx +76 -76
  40. package/src/components/common/openai/OpenAIUserImageContent.tsx +34 -34
  41. package/src/components/common/openai/OpenAIUserTextContent.tsx +15 -15
  42. package/src/components/events/AutoBeCompleteEventMovie.tsx +402 -402
  43. package/src/components/events/AutoBeCorrectEventMovie.tsx +354 -354
  44. package/src/components/events/AutoBeEventGroupMovie.tsx +18 -18
  45. package/src/components/events/AutoBeEventMovie.tsx +154 -158
  46. package/src/components/events/AutoBeProgressEventMovie.tsx +207 -217
  47. package/src/components/events/AutoBeScenarioEventMovie.tsx +135 -135
  48. package/src/components/events/AutoBeStartEventMovie.tsx +82 -82
  49. package/src/components/events/AutoBeValidateEventMovie.tsx +249 -249
  50. package/src/components/events/README.md +300 -300
  51. package/src/components/events/common/CollapsibleEventGroup.tsx +211 -211
  52. package/src/components/events/common/EventCard.tsx +61 -61
  53. package/src/components/events/common/EventContent.tsx +31 -31
  54. package/src/components/events/common/EventHeader.tsx +85 -85
  55. package/src/components/events/common/EventIcon.tsx +82 -82
  56. package/src/components/events/common/ProgressBar.tsx +64 -64
  57. package/src/components/events/groups/CorrectEventGroup.tsx +183 -183
  58. package/src/components/events/groups/ValidateEventGroup.tsx +143 -143
  59. package/src/components/events/utils/eventGrouper.tsx +116 -116
  60. package/src/components/upload/AutoBeChatUploadBox.tsx +433 -425
  61. package/src/components/upload/AutoBeChatUploadSendButton.tsx +66 -66
  62. package/src/components/upload/AutoBeFileUploadBox.tsx +123 -123
  63. package/src/components/upload/AutoBeVoiceRecoderButton.tsx +100 -100
  64. package/src/context/AutoBeAgentContext.tsx +301 -245
  65. package/src/context/AutoBeAgentSessionList.tsx +58 -58
  66. package/src/context/SearchParamsContext.tsx +49 -49
  67. package/src/icons/Receipt.tsx +74 -74
  68. package/src/structure/AutoBeListener.ts +368 -373
  69. package/tsconfig.json +9 -9
@@ -1,425 +1,433 @@
1
- import {
2
- AutoBeUserConversateContent,
3
- AutoBeUserImageConversateContent,
4
- AutoBeUserMessageAudioContent,
5
- AutoBeUserMessageFileContent,
6
- } from "@autobe/interface";
7
- import { ReactNode, RefObject, useEffect, useRef, useState } from "react";
8
-
9
- import {
10
- AutoBeChatUploadSendButton,
11
- AutoBeFileUploadBox,
12
- AutoBeVoiceRecoderButton,
13
- } from ".";
14
- import { useAutoBeAgent } from "../../context/AutoBeAgentContext";
15
- import { useMediaQuery } from "../../hooks/useMediaQuery";
16
- import { AutoBeFileUploader } from "../../utils";
17
-
18
- export interface IAutoBeBucket {
19
- file: File;
20
- content:
21
- | AutoBeUserMessageAudioContent
22
- | AutoBeUserMessageFileContent
23
- | AutoBeUserImageConversateContent;
24
- }
25
-
26
- export interface IAutoBeChatUploadConfig {
27
- supportAudio?: boolean;
28
- file?: (file: File) => Promise<{ id: string }>;
29
- image?: (file: File) => Promise<{ url: string }>;
30
- }
31
-
32
- export const AutoBeChatUploadBox = (props: AutoBeChatUploadBox.IProps) => {
33
- const { listener } = useAutoBeAgent();
34
- const inputRef = useRef<HTMLDivElement>(null);
35
- const fileInputRef = useRef<HTMLInputElement>(null);
36
-
37
- const [dragging, setDragging] = useState(false);
38
- const [enabled, setEnabled] = useState(true);
39
- const [text, setText] = useState("");
40
- const [buckets, setBuckets] = useState<IAutoBeBucket[]>([]);
41
- const [extensionError, setExtensionError] = useState<ReactNode | null>(null);
42
-
43
- const [emptyText, setEmptyText] = useState(false);
44
- const [isComposing, setIsComposing] = useState(false);
45
-
46
- const removeFile = (index: number) => {
47
- setBuckets(buckets.filter((_, i) => i !== index));
48
- };
49
-
50
- useEffect(() => {
51
- async function trackEnable(value: boolean) {
52
- setEnabled(value);
53
- }
54
- listener?.onEnable(trackEnable);
55
- return () => {
56
- listener?.offEnable(trackEnable);
57
- };
58
- }, [listener]);
59
-
60
- // Sync text state when cleared programmatically (like after sending message)
61
- useEffect(() => {
62
- if (inputRef.current && text === "" && inputRef.current.innerText !== "") {
63
- inputRef.current.innerText = "";
64
- }
65
- }, [text]);
66
-
67
- const conversate = async () => {
68
- if (enabled === false) return;
69
-
70
- if (text.trim().length === 0 && buckets.length === 0) {
71
- setEmptyText(true);
72
- return;
73
- }
74
-
75
- const messages: AutoBeUserConversateContent[] = [
76
- {
77
- type: "text",
78
- text: text.trim(),
79
- },
80
- ...buckets.map(({ content }) => content),
81
- ];
82
-
83
- setEmptyText(false);
84
- setText("");
85
- setBuckets([]);
86
-
87
- try {
88
- await props.conversate(messages);
89
- } catch (error) {
90
- props.setError(
91
- error instanceof Error ? error : new Error("Unknown error"),
92
- );
93
- }
94
- };
95
-
96
- const handleFileSelect = async (fileList: FileList | null) => {
97
- if (!fileList) return;
98
-
99
- setEnabled(false);
100
- setExtensionError(null);
101
-
102
- const newFiles: IAutoBeBucket[] = [];
103
- const errorFileNames: string[] = [];
104
-
105
- const files = Array.from(fileList);
106
- for (const file of files) {
107
- try {
108
- newFiles.push(
109
- await AutoBeFileUploader.compose(props.uploadConfig ?? {}, file),
110
- );
111
- } catch (error) {
112
- errorFileNames.push(file.name);
113
- }
114
- }
115
- if (errorFileNames.length > 0) {
116
- const extensions: string[] = Array.from(
117
- new Set(errorFileNames.map((n) => n.split(".").pop() ?? "unknown")),
118
- ).sort();
119
- setExtensionError(
120
- <>
121
- <h2>
122
- Unsupported extension{extensions.length > 1 ? "s" : ""}: (
123
- {extensions.join(", ")})
124
- </h2>
125
- <ul>
126
- {errorFileNames.map((name) => (
127
- <li key={name}>{name}</li>
128
- ))}
129
- </ul>
130
- </>,
131
- );
132
- setTimeout(() => setExtensionError(null), 5_000);
133
- }
134
- setBuckets((o) => [...o, ...newFiles]);
135
- setEnabled(true);
136
- };
137
-
138
- const handleDragEnter = (e: React.DragEvent) => {
139
- e.preventDefault();
140
- e.stopPropagation();
141
- setDragging(true);
142
- };
143
-
144
- const handleDragLeave = (e: React.DragEvent) => {
145
- e.preventDefault();
146
- e.stopPropagation();
147
- // Only set dragging to false if we're leaving the entire container
148
- const rect = e.currentTarget.getBoundingClientRect();
149
- const x = e.clientX;
150
- const y = e.clientY;
151
- if (x < rect.left || x >= rect.right || y < rect.top || y >= rect.bottom) {
152
- setDragging(false);
153
- }
154
- };
155
-
156
- const handleDragOver = (e: React.DragEvent) => {
157
- e.preventDefault();
158
- e.stopPropagation();
159
- };
160
-
161
- const handleDrop = async (e: React.DragEvent) => {
162
- e.preventDefault();
163
- e.stopPropagation();
164
- setDragging(false);
165
-
166
- const files = e.dataTransfer.files;
167
- await handleFileSelect(files);
168
- };
169
-
170
- useEffect(() => {
171
- if (!props.listener?.current) return;
172
- props.listener.current.handleDragEnter = handleDragEnter;
173
- props.listener.current.handleDragLeave = handleDragLeave;
174
- props.listener.current.handleDrop = handleDrop;
175
- props.listener.current.handleDragOver = handleDragOver;
176
- }, [props.listener]);
177
-
178
- return (
179
- <div
180
- style={{
181
- maxWidth: useMediaQuery.WIDTH_MD,
182
- margin: "0 auto",
183
- padding: "12px",
184
- borderRadius: "16px",
185
- border: dragging ? "3px solid #1976d2" : "2px solid #e0e0e0",
186
- backgroundColor: dragging
187
- ? "rgba(25, 118, 210, 0.04)"
188
- : "rgba(255, 255, 255, 0.95)",
189
- backdropFilter: "blur(10px)",
190
- transition: "all 0.2s",
191
- position: "relative",
192
- boxShadow: "0px 8px 24px rgba(0, 0, 0, 0.12)",
193
- }}
194
- >
195
- {dragging ? (
196
- <div
197
- style={{
198
- display: "flex",
199
- alignItems: "center",
200
- justifyContent: "center",
201
- minHeight: "120px",
202
- paddingTop: "32px",
203
- paddingBottom: "32px",
204
- }}
205
- >
206
- <h6
207
- style={{
208
- color: "#1976d2",
209
- fontWeight: "bold",
210
- textAlign: "center",
211
- fontSize: "1.25rem",
212
- margin: 0,
213
- }}
214
- >
215
- Drop files here to upload
216
- </h6>
217
- </div>
218
- ) : null}
219
-
220
- <div
221
- style={{
222
- display: dragging ? "none" : "flex",
223
- flexDirection: "column",
224
- gap: "8px",
225
- }}
226
- >
227
- {buckets.length > 0 && (
228
- <div
229
- style={{
230
- display: "flex",
231
- flexWrap: "wrap",
232
- gap: "4px",
233
- }}
234
- >
235
- {buckets.map(({ file }, index) => (
236
- <div
237
- key={index}
238
- style={{
239
- display: "inline-flex",
240
- alignItems: "center",
241
- backgroundColor: "#f5f5f5",
242
- borderRadius: "16px",
243
- padding: "4px 8px",
244
- fontSize: "0.875rem",
245
- maxWidth: "200px",
246
- border: "1px solid #e0e0e0",
247
- }}
248
- >
249
- <span
250
- style={{
251
- overflow: "hidden",
252
- textOverflow: "ellipsis",
253
- whiteSpace: "nowrap",
254
- marginRight: "4px",
255
- }}
256
- >
257
- {file.name}
258
- </span>
259
- <button
260
- style={{
261
- background: "none",
262
- border: "none",
263
- cursor: "pointer",
264
- padding: "2px",
265
- display: "flex",
266
- alignItems: "center",
267
- justifyContent: "center",
268
- borderRadius: "50%",
269
- width: "16px",
270
- height: "16px",
271
- }}
272
- onClick={() => removeFile(index)}
273
- onMouseEnter={(e) => {
274
- e.currentTarget.style.backgroundColor = "#f0f0f0";
275
- }}
276
- onMouseLeave={(e) => {
277
- e.currentTarget.style.backgroundColor = "transparent";
278
- }}
279
- >
280
- <svg
281
- width="12"
282
- height="12"
283
- viewBox="0 0 24 24"
284
- fill="currentColor"
285
- >
286
- <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" />
287
- </svg>
288
- </button>
289
- </div>
290
- ))}
291
- </div>
292
- )}
293
-
294
- <div style={{ position: "relative" }}>
295
- <div
296
- ref={inputRef}
297
- contentEditable={true}
298
- style={{
299
- width: "97%",
300
- minHeight: "40px",
301
- maxHeight: "192px",
302
- padding: "8px 12px",
303
- border: "none",
304
- borderRadius: "8px",
305
- fontSize: "0.95rem",
306
- fontFamily: "inherit",
307
- outline: "none",
308
- boxShadow: "none",
309
- backgroundColor: "transparent",
310
- transition: "color 0.2s, opacity 0.2s",
311
- overflowY: "auto",
312
- wordBreak: "break-word",
313
- whiteSpace: "pre-wrap",
314
- lineHeight: "1.4",
315
- // Custom scrollbar styles
316
- scrollbarWidth: "thin",
317
- scrollbarColor: "rgba(0, 0, 0, 0.3) transparent",
318
- }}
319
- onKeyDown={(e) => {
320
- if (e.key === "Enter" && !e.shiftKey && !isComposing) {
321
- e.preventDefault();
322
- if (enabled) {
323
- void conversate();
324
- }
325
- }
326
- }}
327
- onCompositionStart={() => {
328
- setIsComposing(true);
329
- }}
330
- onCompositionEnd={() => {
331
- setIsComposing(false);
332
- }}
333
- onInput={(e) => {
334
- const target = e.target as HTMLDivElement;
335
- const newText = target.innerText || "";
336
- // Only update state if text actually changed to prevent cursor issues
337
- if (newText !== text) {
338
- setText(newText);
339
- }
340
- }}
341
- suppressContentEditableWarning={true}
342
- />
343
- {!text && (
344
- <div
345
- style={{
346
- position: "absolute",
347
- top: "8px",
348
- left: "12px",
349
- right: "12px",
350
- bottom: "8px",
351
- color: "rgba(153, 153, 153, 0.6)",
352
- fontSize: "0.95rem",
353
- fontFamily: "inherit",
354
- pointerEvents: "none",
355
- lineHeight: "1.4",
356
- padding: "2px 0",
357
- }}
358
- >
359
- {emptyText
360
- ? "Cannot send empty message"
361
- : dragging
362
- ? "Drop files here..."
363
- : "Conversate with AI Chatbot"}
364
- </div>
365
- )}
366
- </div>
367
-
368
- <input
369
- ref={fileInputRef}
370
- type="file"
371
- multiple
372
- accept={AutoBeFileUploader.getAcceptAttribute(
373
- props.uploadConfig?.supportAudio ?? false,
374
- !!props.uploadConfig?.file,
375
- )}
376
- style={{ display: "none" }}
377
- onChange={(e) => {
378
- void handleFileSelect(e.target.files);
379
- // Reset input to allow selecting the same file again
380
- if (fileInputRef.current) fileInputRef.current.value = "";
381
- }}
382
- />
383
-
384
- <div
385
- style={{
386
- display: "flex",
387
- justifyContent: "space-between",
388
- alignItems: "center",
389
- }}
390
- >
391
- <AutoBeFileUploadBox
392
- extensionError={extensionError}
393
- onClick={() => fileInputRef.current?.click()}
394
- enabled={enabled}
395
- />
396
- {props.uploadConfig?.supportAudio === true ? (
397
- <AutoBeVoiceRecoderButton
398
- enabled={enabled}
399
- onComplete={(content) => setBuckets((o) => [...o, content])}
400
- />
401
- ) : null}
402
- <AutoBeChatUploadSendButton
403
- onClick={() => conversate()}
404
- enabled={enabled}
405
- />
406
- </div>
407
- </div>
408
- </div>
409
- );
410
- };
411
-
412
- export namespace AutoBeChatUploadBox {
413
- export interface IProps {
414
- listener: RefObject<IListener>;
415
- uploadConfig?: IAutoBeChatUploadConfig;
416
- conversate: (messages: AutoBeUserConversateContent[]) => Promise<void>;
417
- setError: (error: Error) => void;
418
- }
419
- export interface IListener {
420
- handleDragEnter: (event: React.DragEvent) => void;
421
- handleDragLeave: (event: React.DragEvent) => void;
422
- handleDragOver: (event: React.DragEvent) => void;
423
- handleDrop: (event: React.DragEvent) => void;
424
- }
425
- }
1
+ import {
2
+ AutoBeUserConversateContent,
3
+ AutoBeUserImageConversateContent,
4
+ AutoBeUserMessageAudioContent,
5
+ AutoBeUserMessageFileContent,
6
+ } from "@autobe/interface";
7
+ import { ReactNode, RefObject, useEffect, useRef, useState } from "react";
8
+
9
+ import {
10
+ AutoBeChatUploadSendButton,
11
+ AutoBeFileUploadBox,
12
+ AutoBeVoiceRecoderButton,
13
+ } from ".";
14
+ import { useAutoBeAgent } from "../../context/AutoBeAgentContext";
15
+ import { useMediaQuery } from "../../hooks/useMediaQuery";
16
+ import { AutoBeFileUploader } from "../../utils";
17
+
18
+ export interface IAutoBeBucket {
19
+ file: File;
20
+ content:
21
+ | AutoBeUserMessageAudioContent
22
+ | AutoBeUserMessageFileContent
23
+ | AutoBeUserImageConversateContent;
24
+ }
25
+
26
+ export interface IAutoBeChatUploadConfig {
27
+ supportAudio?: boolean;
28
+ file?: (file: File) => Promise<{ id: string }>;
29
+ image?: (file: File) => Promise<{ url: string }>;
30
+ }
31
+
32
+ export const AutoBeChatUploadBox = (props: AutoBeChatUploadBox.IProps) => {
33
+ const { listener } = useAutoBeAgent();
34
+ const inputRef = useRef<HTMLDivElement>(null);
35
+ const fileInputRef = useRef<HTMLInputElement>(null);
36
+
37
+ const [dragging, setDragging] = useState(false);
38
+ const [enabled, setEnabled] = useState(true);
39
+ const [text, setText] = useState("");
40
+ const [buckets, setBuckets] = useState<IAutoBeBucket[]>([]);
41
+ const [extensionError, setExtensionError] = useState<ReactNode | null>(null);
42
+
43
+ const [emptyText, setEmptyText] = useState(false);
44
+ const [isComposing, setIsComposing] = useState(false);
45
+
46
+ const removeFile = (index: number) => {
47
+ setBuckets(buckets.filter((_, i) => i !== index));
48
+ };
49
+
50
+ useEffect(() => {
51
+ if (!listener) return;
52
+ async function trackEnable(value: boolean) {
53
+ setEnabled(value);
54
+ }
55
+ setEnabled(listener.getEnable());
56
+ listener.onEnable(trackEnable);
57
+ return () => {
58
+ listener.offEnable(trackEnable);
59
+ };
60
+ }, [listener]);
61
+
62
+ // Sync text state when cleared programmatically (like after sending message)
63
+ useEffect(() => {
64
+ if (inputRef.current && text === "" && inputRef.current.innerText !== "") {
65
+ inputRef.current.innerText = "";
66
+ }
67
+ }, [text]);
68
+
69
+ const isDisabled = props.disabled === true;
70
+
71
+ const conversate = async () => {
72
+ if (enabled === false || isDisabled) return;
73
+
74
+ if (text.trim().length === 0 && buckets.length === 0) {
75
+ setEmptyText(true);
76
+ return;
77
+ }
78
+
79
+ const messages: AutoBeUserConversateContent[] = [
80
+ {
81
+ type: "text",
82
+ text: text.trim(),
83
+ },
84
+ ...buckets.map(({ content }) => content),
85
+ ];
86
+
87
+ setEmptyText(false);
88
+ setText("");
89
+ setBuckets([]);
90
+
91
+ try {
92
+ await props.conversate(messages);
93
+ } catch (error) {
94
+ props.setError(
95
+ error instanceof Error ? error : new Error("Unknown error"),
96
+ );
97
+ }
98
+ };
99
+
100
+ const handleFileSelect = async (fileList: FileList | null) => {
101
+ if (!fileList) return;
102
+
103
+ setEnabled(false);
104
+ setExtensionError(null);
105
+
106
+ const newFiles: IAutoBeBucket[] = [];
107
+ const errorFileNames: string[] = [];
108
+
109
+ const files = Array.from(fileList);
110
+ for (const file of files) {
111
+ try {
112
+ newFiles.push(
113
+ await AutoBeFileUploader.compose(props.uploadConfig ?? {}, file),
114
+ );
115
+ } catch (error) {
116
+ errorFileNames.push(file.name);
117
+ }
118
+ }
119
+ if (errorFileNames.length > 0) {
120
+ const extensions: string[] = Array.from(
121
+ new Set(errorFileNames.map((n) => n.split(".").pop() ?? "unknown")),
122
+ ).sort();
123
+ setExtensionError(
124
+ <>
125
+ <h2>
126
+ Unsupported extension{extensions.length > 1 ? "s" : ""}: (
127
+ {extensions.join(", ")})
128
+ </h2>
129
+ <ul>
130
+ {errorFileNames.map((name) => (
131
+ <li key={name}>{name}</li>
132
+ ))}
133
+ </ul>
134
+ </>,
135
+ );
136
+ setTimeout(() => setExtensionError(null), 5_000);
137
+ }
138
+ setBuckets((o) => [...o, ...newFiles]);
139
+ setEnabled(true);
140
+ };
141
+
142
+ const handleDragEnter = (e: React.DragEvent) => {
143
+ e.preventDefault();
144
+ e.stopPropagation();
145
+ setDragging(true);
146
+ };
147
+
148
+ const handleDragLeave = (e: React.DragEvent) => {
149
+ e.preventDefault();
150
+ e.stopPropagation();
151
+ // Only set dragging to false if we're leaving the entire container
152
+ const rect = e.currentTarget.getBoundingClientRect();
153
+ const x = e.clientX;
154
+ const y = e.clientY;
155
+ if (x < rect.left || x >= rect.right || y < rect.top || y >= rect.bottom) {
156
+ setDragging(false);
157
+ }
158
+ };
159
+
160
+ const handleDragOver = (e: React.DragEvent) => {
161
+ e.preventDefault();
162
+ e.stopPropagation();
163
+ };
164
+
165
+ const handleDrop = async (e: React.DragEvent) => {
166
+ e.preventDefault();
167
+ e.stopPropagation();
168
+ setDragging(false);
169
+
170
+ const files = e.dataTransfer.files;
171
+ await handleFileSelect(files);
172
+ };
173
+
174
+ useEffect(() => {
175
+ if (!props.listener?.current) return;
176
+ props.listener.current.handleDragEnter = handleDragEnter;
177
+ props.listener.current.handleDragLeave = handleDragLeave;
178
+ props.listener.current.handleDrop = handleDrop;
179
+ props.listener.current.handleDragOver = handleDragOver;
180
+ }, [props.listener]);
181
+
182
+ return (
183
+ <div
184
+ style={{
185
+ maxWidth: useMediaQuery.WIDTH_MD,
186
+ margin: "0 auto",
187
+ padding: "12px",
188
+ borderRadius: "16px",
189
+ border: dragging ? "3px solid #1976d2" : "2px solid #e0e0e0",
190
+ backgroundColor: dragging
191
+ ? "rgba(25, 118, 210, 0.04)"
192
+ : "rgba(255, 255, 255, 0.95)",
193
+ backdropFilter: "blur(10px)",
194
+ transition: "all 0.2s",
195
+ position: "relative",
196
+ boxShadow: "0px 8px 24px rgba(0, 0, 0, 0.12)",
197
+ ...(isDisabled
198
+ ? { opacity: 0.45, pointerEvents: "none" as const }
199
+ : {}),
200
+ }}
201
+ >
202
+ {dragging ? (
203
+ <div
204
+ style={{
205
+ display: "flex",
206
+ alignItems: "center",
207
+ justifyContent: "center",
208
+ minHeight: "120px",
209
+ paddingTop: "32px",
210
+ paddingBottom: "32px",
211
+ }}
212
+ >
213
+ <h6
214
+ style={{
215
+ color: "#1976d2",
216
+ fontWeight: "bold",
217
+ textAlign: "center",
218
+ fontSize: "1.25rem",
219
+ margin: 0,
220
+ }}
221
+ >
222
+ Drop files here to upload
223
+ </h6>
224
+ </div>
225
+ ) : null}
226
+
227
+ <div
228
+ style={{
229
+ display: dragging ? "none" : "flex",
230
+ flexDirection: "column",
231
+ gap: "8px",
232
+ }}
233
+ >
234
+ {buckets.length > 0 && (
235
+ <div
236
+ style={{
237
+ display: "flex",
238
+ flexWrap: "wrap",
239
+ gap: "4px",
240
+ }}
241
+ >
242
+ {buckets.map(({ file }, index) => (
243
+ <div
244
+ key={index}
245
+ style={{
246
+ display: "inline-flex",
247
+ alignItems: "center",
248
+ backgroundColor: "#f5f5f5",
249
+ borderRadius: "16px",
250
+ padding: "4px 8px",
251
+ fontSize: "0.875rem",
252
+ maxWidth: "200px",
253
+ border: "1px solid #e0e0e0",
254
+ }}
255
+ >
256
+ <span
257
+ style={{
258
+ overflow: "hidden",
259
+ textOverflow: "ellipsis",
260
+ whiteSpace: "nowrap",
261
+ marginRight: "4px",
262
+ }}
263
+ >
264
+ {file.name}
265
+ </span>
266
+ <button
267
+ style={{
268
+ background: "none",
269
+ border: "none",
270
+ cursor: "pointer",
271
+ padding: "2px",
272
+ display: "flex",
273
+ alignItems: "center",
274
+ justifyContent: "center",
275
+ borderRadius: "50%",
276
+ width: "16px",
277
+ height: "16px",
278
+ }}
279
+ onClick={() => removeFile(index)}
280
+ onMouseEnter={(e) => {
281
+ e.currentTarget.style.backgroundColor = "#f0f0f0";
282
+ }}
283
+ onMouseLeave={(e) => {
284
+ e.currentTarget.style.backgroundColor = "transparent";
285
+ }}
286
+ >
287
+ <svg
288
+ width="12"
289
+ height="12"
290
+ viewBox="0 0 24 24"
291
+ fill="currentColor"
292
+ >
293
+ <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" />
294
+ </svg>
295
+ </button>
296
+ </div>
297
+ ))}
298
+ </div>
299
+ )}
300
+
301
+ <div style={{ position: "relative" }}>
302
+ <div
303
+ ref={inputRef}
304
+ contentEditable={true}
305
+ style={{
306
+ width: "97%",
307
+ minHeight: "40px",
308
+ maxHeight: "192px",
309
+ padding: "8px 12px",
310
+ border: "none",
311
+ borderRadius: "8px",
312
+ fontSize: "0.95rem",
313
+ fontFamily: "inherit",
314
+ outline: "none",
315
+ boxShadow: "none",
316
+ backgroundColor: "transparent",
317
+ transition: "color 0.2s, opacity 0.2s",
318
+ overflowY: "auto",
319
+ wordBreak: "break-word",
320
+ whiteSpace: "pre-wrap",
321
+ lineHeight: "1.4",
322
+ // Custom scrollbar styles
323
+ scrollbarWidth: "thin",
324
+ scrollbarColor: "rgba(0, 0, 0, 0.3) transparent",
325
+ }}
326
+ onKeyDown={(e) => {
327
+ if (e.key === "Enter" && !e.shiftKey && !isComposing) {
328
+ e.preventDefault();
329
+ if (enabled) {
330
+ void conversate();
331
+ }
332
+ }
333
+ }}
334
+ onCompositionStart={() => {
335
+ setIsComposing(true);
336
+ }}
337
+ onCompositionEnd={() => {
338
+ setIsComposing(false);
339
+ }}
340
+ onInput={(e) => {
341
+ const target = e.target as HTMLDivElement;
342
+ const newText = target.innerText || "";
343
+ // Only update state if text actually changed to prevent cursor issues
344
+ if (newText !== text) {
345
+ setText(newText);
346
+ }
347
+ }}
348
+ suppressContentEditableWarning={true}
349
+ />
350
+ {!text && (
351
+ <div
352
+ style={{
353
+ position: "absolute",
354
+ top: "8px",
355
+ left: "12px",
356
+ right: "12px",
357
+ bottom: "8px",
358
+ color: "rgba(153, 153, 153, 0.6)",
359
+ fontSize: "0.95rem",
360
+ fontFamily: "inherit",
361
+ pointerEvents: "none",
362
+ lineHeight: "1.4",
363
+ padding: "2px 0",
364
+ }}
365
+ >
366
+ {emptyText
367
+ ? "Cannot send empty message"
368
+ : dragging
369
+ ? "Drop files here..."
370
+ : "Conversate with AI Chatbot"}
371
+ </div>
372
+ )}
373
+ </div>
374
+
375
+ <input
376
+ ref={fileInputRef}
377
+ type="file"
378
+ multiple
379
+ accept={AutoBeFileUploader.getAcceptAttribute(
380
+ props.uploadConfig?.supportAudio ?? false,
381
+ !!props.uploadConfig?.file,
382
+ )}
383
+ style={{ display: "none" }}
384
+ onChange={(e) => {
385
+ void handleFileSelect(e.target.files);
386
+ // Reset input to allow selecting the same file again
387
+ if (fileInputRef.current) fileInputRef.current.value = "";
388
+ }}
389
+ />
390
+
391
+ <div
392
+ style={{
393
+ display: "flex",
394
+ justifyContent: "space-between",
395
+ alignItems: "center",
396
+ }}
397
+ >
398
+ <AutoBeFileUploadBox
399
+ extensionError={extensionError}
400
+ onClick={() => fileInputRef.current?.click()}
401
+ enabled={enabled}
402
+ />
403
+ {props.uploadConfig?.supportAudio === true ? (
404
+ <AutoBeVoiceRecoderButton
405
+ enabled={enabled}
406
+ onComplete={(content) => setBuckets((o) => [...o, content])}
407
+ />
408
+ ) : null}
409
+ <AutoBeChatUploadSendButton
410
+ onClick={() => conversate()}
411
+ enabled={enabled}
412
+ />
413
+ </div>
414
+ </div>
415
+ </div>
416
+ );
417
+ };
418
+
419
+ export namespace AutoBeChatUploadBox {
420
+ export interface IProps {
421
+ listener: RefObject<IListener>;
422
+ uploadConfig?: IAutoBeChatUploadConfig;
423
+ conversate: (messages: AutoBeUserConversateContent[]) => Promise<void>;
424
+ setError: (error: Error) => void;
425
+ disabled?: boolean;
426
+ }
427
+ export interface IListener {
428
+ handleDragEnter: (event: React.DragEvent) => void;
429
+ handleDragLeave: (event: React.DragEvent) => void;
430
+ handleDragOver: (event: React.DragEvent) => void;
431
+ handleDrop: (event: React.DragEvent) => void;
432
+ }
433
+ }