reachat 1.2.0 → 1.3.1
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/{ChatInput.d.ts → ChatInput/ChatInput.d.ts} +8 -2
- package/dist/ChatInput/FileInput.d.ts +26 -0
- package/dist/ChatInput/index.d.ts +2 -0
- package/dist/SessionMessages/SessionMessage/MessageQuestion.d.ts +5 -0
- package/dist/docs.json +143 -20
- package/dist/index.js +128 -81
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +124 -77
- package/dist/index.umd.cjs.map +1 -1
- package/dist/theme.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
2
|
|
|
3
3
|
interface ChatInputProps {
|
|
4
4
|
/**
|
|
@@ -26,5 +26,11 @@ interface ChatInputProps {
|
|
|
26
26
|
*/
|
|
27
27
|
attachIcon?: ReactElement;
|
|
28
28
|
}
|
|
29
|
-
export
|
|
29
|
+
export interface ChatInputRef {
|
|
30
|
+
/**
|
|
31
|
+
* Focus the input.
|
|
32
|
+
*/
|
|
33
|
+
focus: () => void;
|
|
34
|
+
}
|
|
35
|
+
export declare const ChatInput: import('react').ForwardRefExoticComponent<ChatInputProps & import('react').RefAttributes<ChatInputRef>>;
|
|
30
36
|
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FC, ReactNode, ChangeEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
interface FileInputProps {
|
|
4
|
+
/**
|
|
5
|
+
* Array of allowed file extensions.
|
|
6
|
+
*/
|
|
7
|
+
allowedFiles: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Indicates whether a file upload is in progress.
|
|
10
|
+
*/
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Disables the file input when true.
|
|
14
|
+
*/
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Custom icon for the attach button.
|
|
18
|
+
*/
|
|
19
|
+
attachIcon: ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* Callback function triggered when a file is selected.
|
|
22
|
+
*/
|
|
23
|
+
onFileUpload: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
24
|
+
}
|
|
25
|
+
export declare const FileInput: FC<FileInputProps>;
|
|
26
|
+
export {};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { ConversationFile } from '../../types';
|
|
2
3
|
|
|
3
4
|
export interface MessageQuestionProps extends PropsWithChildren {
|
|
4
5
|
/**
|
|
5
6
|
* Question to render.
|
|
6
7
|
*/
|
|
7
8
|
question: string;
|
|
9
|
+
/**
|
|
10
|
+
* Array of sources referenced in the conversation
|
|
11
|
+
*/
|
|
12
|
+
files?: ConversationFile[];
|
|
8
13
|
}
|
|
9
14
|
export declare const MessageQuestion: FC<MessageQuestionProps>;
|
package/dist/docs.json
CHANGED
|
@@ -123,7 +123,9 @@
|
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
"remarkPlugins": {
|
|
126
|
-
"defaultValue":
|
|
126
|
+
"defaultValue": {
|
|
127
|
+
"value": "[remarkGfm, remarkYoutube, remarkMath]"
|
|
128
|
+
},
|
|
127
129
|
"description": "Remark plugins to apply to the request/response.",
|
|
128
130
|
"name": "remarkPlugins",
|
|
129
131
|
"parent": {
|
|
@@ -297,7 +299,7 @@
|
|
|
297
299
|
},
|
|
298
300
|
{
|
|
299
301
|
"tags": {},
|
|
300
|
-
"filePath": "src/ChatInput.tsx",
|
|
302
|
+
"filePath": "src/ChatInput/ChatInput.tsx",
|
|
301
303
|
"description": "",
|
|
302
304
|
"displayName": "ChatInput",
|
|
303
305
|
"methods": [],
|
|
@@ -307,12 +309,12 @@
|
|
|
307
309
|
"description": "Default value for the input field.",
|
|
308
310
|
"name": "defaultValue",
|
|
309
311
|
"parent": {
|
|
310
|
-
"fileName": "src/ChatInput.tsx",
|
|
312
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
311
313
|
"name": "ChatInputProps"
|
|
312
314
|
},
|
|
313
315
|
"declarations": [
|
|
314
316
|
{
|
|
315
|
-
"fileName": "src/ChatInput.tsx",
|
|
317
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
316
318
|
"name": "ChatInputProps"
|
|
317
319
|
}
|
|
318
320
|
],
|
|
@@ -326,12 +328,12 @@
|
|
|
326
328
|
"description": "Allowed file types for upload.",
|
|
327
329
|
"name": "allowedFiles",
|
|
328
330
|
"parent": {
|
|
329
|
-
"fileName": "src/ChatInput.tsx",
|
|
331
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
330
332
|
"name": "ChatInputProps"
|
|
331
333
|
},
|
|
332
334
|
"declarations": [
|
|
333
335
|
{
|
|
334
|
-
"fileName": "src/ChatInput.tsx",
|
|
336
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
335
337
|
"name": "ChatInputProps"
|
|
336
338
|
}
|
|
337
339
|
],
|
|
@@ -345,12 +347,12 @@
|
|
|
345
347
|
"description": "Placeholder text for the input field.",
|
|
346
348
|
"name": "placeholder",
|
|
347
349
|
"parent": {
|
|
348
|
-
"fileName": "src/ChatInput.tsx",
|
|
350
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
349
351
|
"name": "ChatInputProps"
|
|
350
352
|
},
|
|
351
353
|
"declarations": [
|
|
352
354
|
{
|
|
353
|
-
"fileName": "src/ChatInput.tsx",
|
|
355
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
354
356
|
"name": "ChatInputProps"
|
|
355
357
|
}
|
|
356
358
|
],
|
|
@@ -366,12 +368,12 @@
|
|
|
366
368
|
"description": "Icon to show for send.",
|
|
367
369
|
"name": "sendIcon",
|
|
368
370
|
"parent": {
|
|
369
|
-
"fileName": "src/ChatInput.tsx",
|
|
371
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
370
372
|
"name": "ChatInputProps"
|
|
371
373
|
},
|
|
372
374
|
"declarations": [
|
|
373
375
|
{
|
|
374
|
-
"fileName": "src/ChatInput.tsx",
|
|
376
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
375
377
|
"name": "ChatInputProps"
|
|
376
378
|
}
|
|
377
379
|
],
|
|
@@ -387,12 +389,12 @@
|
|
|
387
389
|
"description": "Icon to show for send.",
|
|
388
390
|
"name": "stopIcon",
|
|
389
391
|
"parent": {
|
|
390
|
-
"fileName": "src/ChatInput.tsx",
|
|
392
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
391
393
|
"name": "ChatInputProps"
|
|
392
394
|
},
|
|
393
395
|
"declarations": [
|
|
394
396
|
{
|
|
395
|
-
"fileName": "src/ChatInput.tsx",
|
|
397
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
396
398
|
"name": "ChatInputProps"
|
|
397
399
|
}
|
|
398
400
|
],
|
|
@@ -402,18 +404,16 @@
|
|
|
402
404
|
}
|
|
403
405
|
},
|
|
404
406
|
"attachIcon": {
|
|
405
|
-
"defaultValue":
|
|
406
|
-
"value": "<AttachIcon />"
|
|
407
|
-
},
|
|
407
|
+
"defaultValue": null,
|
|
408
408
|
"description": "Icon to show for attach.",
|
|
409
409
|
"name": "attachIcon",
|
|
410
410
|
"parent": {
|
|
411
|
-
"fileName": "src/ChatInput.tsx",
|
|
411
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
412
412
|
"name": "ChatInputProps"
|
|
413
413
|
},
|
|
414
414
|
"declarations": [
|
|
415
415
|
{
|
|
416
|
-
"fileName": "src/ChatInput.tsx",
|
|
416
|
+
"fileName": "src/ChatInput/ChatInput.tsx",
|
|
417
417
|
"name": "ChatInputProps"
|
|
418
418
|
}
|
|
419
419
|
],
|
|
@@ -424,6 +424,112 @@
|
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
},
|
|
427
|
+
{
|
|
428
|
+
"tags": {},
|
|
429
|
+
"filePath": "src/ChatInput/FileInput.tsx",
|
|
430
|
+
"description": "",
|
|
431
|
+
"displayName": "FileInput",
|
|
432
|
+
"methods": [],
|
|
433
|
+
"props": {
|
|
434
|
+
"allowedFiles": {
|
|
435
|
+
"defaultValue": null,
|
|
436
|
+
"description": "Array of allowed file extensions.",
|
|
437
|
+
"name": "allowedFiles",
|
|
438
|
+
"parent": {
|
|
439
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
440
|
+
"name": "FileInputProps"
|
|
441
|
+
},
|
|
442
|
+
"declarations": [
|
|
443
|
+
{
|
|
444
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
445
|
+
"name": "FileInputProps"
|
|
446
|
+
}
|
|
447
|
+
],
|
|
448
|
+
"required": true,
|
|
449
|
+
"type": {
|
|
450
|
+
"name": "string[]"
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
"isLoading": {
|
|
454
|
+
"defaultValue": null,
|
|
455
|
+
"description": "Indicates whether a file upload is in progress.",
|
|
456
|
+
"name": "isLoading",
|
|
457
|
+
"parent": {
|
|
458
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
459
|
+
"name": "FileInputProps"
|
|
460
|
+
},
|
|
461
|
+
"declarations": [
|
|
462
|
+
{
|
|
463
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
464
|
+
"name": "FileInputProps"
|
|
465
|
+
}
|
|
466
|
+
],
|
|
467
|
+
"required": true,
|
|
468
|
+
"type": {
|
|
469
|
+
"name": "boolean"
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
"disabled": {
|
|
473
|
+
"defaultValue": null,
|
|
474
|
+
"description": "Disables the file input when true.",
|
|
475
|
+
"name": "disabled",
|
|
476
|
+
"parent": {
|
|
477
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
478
|
+
"name": "FileInputProps"
|
|
479
|
+
},
|
|
480
|
+
"declarations": [
|
|
481
|
+
{
|
|
482
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
483
|
+
"name": "FileInputProps"
|
|
484
|
+
}
|
|
485
|
+
],
|
|
486
|
+
"required": true,
|
|
487
|
+
"type": {
|
|
488
|
+
"name": "boolean"
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
"attachIcon": {
|
|
492
|
+
"defaultValue": {
|
|
493
|
+
"value": "<AttachIcon />"
|
|
494
|
+
},
|
|
495
|
+
"description": "Custom icon for the attach button.",
|
|
496
|
+
"name": "attachIcon",
|
|
497
|
+
"parent": {
|
|
498
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
499
|
+
"name": "FileInputProps"
|
|
500
|
+
},
|
|
501
|
+
"declarations": [
|
|
502
|
+
{
|
|
503
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
504
|
+
"name": "FileInputProps"
|
|
505
|
+
}
|
|
506
|
+
],
|
|
507
|
+
"required": false,
|
|
508
|
+
"type": {
|
|
509
|
+
"name": "ReactNode"
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
"onFileUpload": {
|
|
513
|
+
"defaultValue": null,
|
|
514
|
+
"description": "Callback function triggered when a file is selected.",
|
|
515
|
+
"name": "onFileUpload",
|
|
516
|
+
"parent": {
|
|
517
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
518
|
+
"name": "FileInputProps"
|
|
519
|
+
},
|
|
520
|
+
"declarations": [
|
|
521
|
+
{
|
|
522
|
+
"fileName": "src/ChatInput/FileInput.tsx",
|
|
523
|
+
"name": "FileInputProps"
|
|
524
|
+
}
|
|
525
|
+
],
|
|
526
|
+
"required": true,
|
|
527
|
+
"type": {
|
|
528
|
+
"name": "(event: ChangeEvent<HTMLInputElement>) => void"
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
},
|
|
427
533
|
{
|
|
428
534
|
"tags": {},
|
|
429
535
|
"filePath": "src/Markdown/CodeHighlighter.tsx",
|
|
@@ -559,9 +665,7 @@
|
|
|
559
665
|
"methods": [],
|
|
560
666
|
"props": {
|
|
561
667
|
"remarkPlugins": {
|
|
562
|
-
"defaultValue":
|
|
563
|
-
"value": "[remarkGfm, remarkMath]"
|
|
564
|
-
},
|
|
668
|
+
"defaultValue": null,
|
|
565
669
|
"description": "Remark plugins to apply to the markdown content.",
|
|
566
670
|
"name": "remarkPlugins",
|
|
567
671
|
"parent": {
|
|
@@ -1324,6 +1428,25 @@
|
|
|
1324
1428
|
"type": {
|
|
1325
1429
|
"name": "string"
|
|
1326
1430
|
}
|
|
1431
|
+
},
|
|
1432
|
+
"files": {
|
|
1433
|
+
"defaultValue": null,
|
|
1434
|
+
"description": "Array of sources referenced in the conversation",
|
|
1435
|
+
"name": "files",
|
|
1436
|
+
"parent": {
|
|
1437
|
+
"fileName": "src/SessionMessages/SessionMessage/MessageQuestion.tsx",
|
|
1438
|
+
"name": "MessageQuestionProps"
|
|
1439
|
+
},
|
|
1440
|
+
"declarations": [
|
|
1441
|
+
{
|
|
1442
|
+
"fileName": "src/SessionMessages/SessionMessage/MessageQuestion.tsx",
|
|
1443
|
+
"name": "MessageQuestionProps"
|
|
1444
|
+
}
|
|
1445
|
+
],
|
|
1446
|
+
"required": false,
|
|
1447
|
+
"type": {
|
|
1448
|
+
"name": "ConversationFile[]"
|
|
1449
|
+
}
|
|
1327
1450
|
}
|
|
1328
1451
|
}
|
|
1329
1452
|
},
|
package/dist/index.js
CHANGED
|
@@ -10,39 +10,81 @@
|
|
|
10
10
|
console.error("vite-plugin-css-injected-by-js", e);
|
|
11
11
|
}
|
|
12
12
|
})();
|
|
13
|
-
import { jsxs,
|
|
13
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
14
14
|
import * as React from "react";
|
|
15
|
-
import { createContext, useContext, useState,
|
|
16
|
-
import { cn, Textarea,
|
|
15
|
+
import { createContext, useContext, useRef, forwardRef, useState, useImperativeHandle, useEffect, useMemo, useCallback } from "react";
|
|
16
|
+
import { Button, cn, Textarea, Ellipsis, DateFormat, IconButton, Card, Divider, useInfinityList, useComponentTheme, List, ListItem } from "reablocks";
|
|
17
17
|
import { Slot } from "@radix-ui/react-slot";
|
|
18
18
|
import { motion, AnimatePresence } from "framer-motion";
|
|
19
19
|
import ReactMarkdown from "react-markdown";
|
|
20
|
-
import remarkGfm from "remark-gfm";
|
|
21
20
|
import { Prism } from "react-syntax-highlighter";
|
|
22
21
|
import rehypeKatex from "rehype-katex";
|
|
23
|
-
import remarkMath from "remark-math";
|
|
24
22
|
import { findAndReplace } from "mdast-util-find-and-replace";
|
|
25
|
-
import remarkYoutube from "remark-youtube";
|
|
26
23
|
import { useHotkeys } from "reakeys";
|
|
24
|
+
import remarkGfm from "remark-gfm";
|
|
25
|
+
import remarkYoutube from "remark-youtube";
|
|
26
|
+
import remarkMath from "remark-math";
|
|
27
27
|
import { isToday, isYesterday, isThisWeek, isThisMonth, isThisYear, format } from "date-fns";
|
|
28
28
|
const SvgSend = (props) => /* @__PURE__ */ React.createElement("svg", { width: 17, height: 17, viewBox: "0 0 17 17", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React.createElement("g", { id: "send" }, /* @__PURE__ */ React.createElement("path", { id: "Vector", d: "M14.6111 2.33327C14.5349 2.3339 14.4598 2.35194 14.3917 2.386L2.39168 8.386C2.31456 8.42456 2.24872 8.4824 2.20055 8.55391C2.15238 8.62543 2.12352 8.70818 2.11677 8.79414C2.11002 8.88009 2.12561 8.96634 2.16203 9.04449C2.19845 9.12264 2.25446 9.19005 2.32462 9.24017L4.52514 10.8124L5.47371 13.6581C5.50257 13.7447 5.55457 13.8217 5.62406 13.8808C5.69355 13.9399 5.7779 13.9789 5.86796 13.9935C5.95802 14.0082 6.05036 13.9979 6.13499 13.9638C6.21962 13.9297 6.2933 13.873 6.34806 13.8001L7.05249 12.8606L10.3207 15.2376C10.3843 15.2839 10.4579 15.3146 10.5355 15.3271C10.6132 15.3396 10.6927 15.3336 10.7676 15.3097C10.8425 15.2857 10.9107 15.2444 10.9667 15.1891C11.0226 15.1338 11.0647 15.0661 11.0896 14.9915L15.0896 2.99147C15.1148 2.91597 15.1216 2.83555 15.1094 2.7569C15.0972 2.67825 15.0665 2.60363 15.0197 2.53926C14.9729 2.47488 14.9114 2.42261 14.8403 2.38678C14.7693 2.35096 14.6907 2.33261 14.6111 2.33327ZM13.2478 5.35345L10.3565 14.0266L7.67293 12.0755L13.2478 5.35345ZM10.684 5.35801L4.934 9.87559L3.58113 8.90879L10.684 5.35801ZM11.2784 6.16205L6.56746 11.843C6.56681 11.8437 6.56616 11.8443 6.56551 11.845L6.56355 11.8476C6.55841 11.8538 6.55342 11.8601 6.54858 11.8665C6.54319 11.8733 6.53798 11.8802 6.53295 11.8873L6.12085 12.4361L5.53426 10.6751L11.2784 6.16205Z", fill: "currentColor" })));
|
|
29
29
|
const SvgStop = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1, strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-octagon-x", ...props }, /* @__PURE__ */ React.createElement("path", { d: "m15 9-6 6" }), /* @__PURE__ */ React.createElement("path", { d: "M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z" }), /* @__PURE__ */ React.createElement("path", { d: "m9 9 6 6" }));
|
|
30
|
-
const SvgPaperclip = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1, strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-paperclip", ...props }, /* @__PURE__ */ React.createElement("path", { d: "m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48" }));
|
|
31
30
|
const ChatContext = createContext({
|
|
32
31
|
sessions: [],
|
|
33
32
|
activeSessionId: null
|
|
34
33
|
});
|
|
35
|
-
const
|
|
34
|
+
const SvgPaperclip = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1, strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-paperclip", ...props }, /* @__PURE__ */ React.createElement("path", { d: "m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48" }));
|
|
35
|
+
const FileInput = ({
|
|
36
|
+
allowedFiles,
|
|
37
|
+
onFileUpload,
|
|
38
|
+
isLoading,
|
|
39
|
+
disabled,
|
|
40
|
+
attachIcon = /* @__PURE__ */ jsx(SvgPaperclip, {})
|
|
41
|
+
}) => {
|
|
42
|
+
const { theme } = useContext(ChatContext);
|
|
43
|
+
const fileInputRef = useRef(null);
|
|
44
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
45
|
+
/* @__PURE__ */ jsx(
|
|
46
|
+
"input",
|
|
47
|
+
{
|
|
48
|
+
type: "file",
|
|
49
|
+
ref: fileInputRef,
|
|
50
|
+
className: "hidden",
|
|
51
|
+
accept: allowedFiles.join(","),
|
|
52
|
+
onChange: onFileUpload
|
|
53
|
+
}
|
|
54
|
+
),
|
|
55
|
+
/* @__PURE__ */ jsx(
|
|
56
|
+
Button,
|
|
57
|
+
{
|
|
58
|
+
title: "Upload",
|
|
59
|
+
variant: "text",
|
|
60
|
+
disabled: isLoading || disabled,
|
|
61
|
+
className: cn(theme.input.upload),
|
|
62
|
+
onClick: () => {
|
|
63
|
+
var _a;
|
|
64
|
+
return (_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
65
|
+
},
|
|
66
|
+
children: attachIcon
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
] });
|
|
70
|
+
};
|
|
71
|
+
const ChatInput = forwardRef(({
|
|
36
72
|
allowedFiles,
|
|
37
73
|
placeholder,
|
|
38
74
|
defaultValue,
|
|
39
75
|
sendIcon = /* @__PURE__ */ jsx(SvgSend, {}),
|
|
40
76
|
stopIcon = /* @__PURE__ */ jsx(SvgStop, {}),
|
|
41
|
-
attachIcon
|
|
42
|
-
}) => {
|
|
77
|
+
attachIcon
|
|
78
|
+
}, ref) => {
|
|
43
79
|
const { theme, isLoading, disabled, sendMessage, stopMessage, fileUpload } = useContext(ChatContext);
|
|
44
80
|
const [message, setMessage] = useState("");
|
|
45
|
-
const
|
|
81
|
+
const inputRef = useRef(null);
|
|
82
|
+
useImperativeHandle(ref, () => ({
|
|
83
|
+
focus: () => {
|
|
84
|
+
var _a;
|
|
85
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
46
88
|
const handleSendMessage = () => {
|
|
47
89
|
if (message.trim()) {
|
|
48
90
|
sendMessage == null ? void 0 : sendMessage(message);
|
|
@@ -66,44 +108,29 @@ const ChatInput = ({
|
|
|
66
108
|
/* @__PURE__ */ jsx(
|
|
67
109
|
Textarea,
|
|
68
110
|
{
|
|
111
|
+
inputRef,
|
|
69
112
|
containerClassName: cn(theme.input.input),
|
|
70
113
|
minRows: 1,
|
|
71
114
|
autoFocus: true,
|
|
72
115
|
value: message,
|
|
73
|
-
onChange: (e) => setMessage(e.target.value),
|
|
74
116
|
defaultValue,
|
|
75
117
|
onKeyPress: handleKeyPress,
|
|
76
118
|
placeholder,
|
|
77
|
-
disabled: isLoading || disabled
|
|
119
|
+
disabled: isLoading || disabled,
|
|
120
|
+
onChange: (e) => setMessage(e.target.value)
|
|
78
121
|
}
|
|
79
122
|
),
|
|
80
123
|
/* @__PURE__ */ jsxs("div", { className: cn(theme.input.actions.base), children: [
|
|
81
|
-
(allowedFiles == null ? void 0 : allowedFiles.length) > 0 && /* @__PURE__ */
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
),
|
|
92
|
-
/* @__PURE__ */ jsx(
|
|
93
|
-
Button,
|
|
94
|
-
{
|
|
95
|
-
title: "Upload",
|
|
96
|
-
variant: "text",
|
|
97
|
-
disabled: isLoading || disabled,
|
|
98
|
-
className: cn(theme.input.upload),
|
|
99
|
-
onClick: () => {
|
|
100
|
-
var _a;
|
|
101
|
-
return (_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
102
|
-
},
|
|
103
|
-
children: attachIcon
|
|
104
|
-
}
|
|
105
|
-
)
|
|
106
|
-
] }),
|
|
124
|
+
(allowedFiles == null ? void 0 : allowedFiles.length) > 0 && /* @__PURE__ */ jsx(
|
|
125
|
+
FileInput,
|
|
126
|
+
{
|
|
127
|
+
allowedFiles,
|
|
128
|
+
onFileUpload: handleFileUpload,
|
|
129
|
+
isLoading,
|
|
130
|
+
disabled,
|
|
131
|
+
attachIcon
|
|
132
|
+
}
|
|
133
|
+
),
|
|
107
134
|
isLoading && /* @__PURE__ */ jsx(
|
|
108
135
|
Button,
|
|
109
136
|
{
|
|
@@ -126,7 +153,7 @@ const ChatInput = ({
|
|
|
126
153
|
)
|
|
127
154
|
] })
|
|
128
155
|
] });
|
|
129
|
-
};
|
|
156
|
+
});
|
|
130
157
|
const SessionEmpty = ({
|
|
131
158
|
children
|
|
132
159
|
}) => {
|
|
@@ -1239,7 +1266,7 @@ const TableHeaderCell = ({ children, ...props }) => /* @__PURE__ */ jsx("th", {
|
|
|
1239
1266
|
const TableDataCell = ({ children, ...props }) => /* @__PURE__ */ jsx("td", { ...props, children });
|
|
1240
1267
|
const Markdown = ({
|
|
1241
1268
|
children,
|
|
1242
|
-
remarkPlugins
|
|
1269
|
+
remarkPlugins,
|
|
1243
1270
|
rehypePlugins = [rehypeKatex]
|
|
1244
1271
|
}) => {
|
|
1245
1272
|
const { theme } = useContext(ChatContext);
|
|
@@ -1292,13 +1319,63 @@ function remarkCve() {
|
|
|
1292
1319
|
];
|
|
1293
1320
|
}
|
|
1294
1321
|
}
|
|
1322
|
+
const SvgFile = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 16, height: 16, viewBox: "0 0 16 16", fill: "currentColor", ...props }, /* @__PURE__ */ React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M2.7036 1.37034C3.04741 1.02653 3.51373 0.833374 3.99996 0.833374H9.33329H9.33331C9.47275 0.833374 9.59885 0.890449 9.68954 0.98251L13.6843 4.97722C13.7763 5.0679 13.8333 5.19398 13.8333 5.33337L13.8333 5.3379V13.3334C13.8333 13.8196 13.6401 14.2859 13.2963 14.6297C12.9525 14.9736 12.4862 15.1667 12 15.1667H3.99996C3.51373 15.1667 3.04741 14.9736 2.7036 14.6297C2.35978 14.2859 2.16663 13.8196 2.16663 13.3334V2.66671C2.16663 2.18048 2.35978 1.71416 2.7036 1.37034ZM3.99996 1.83337H8.83331V5.33337C8.83331 5.60952 9.05717 5.83337 9.33331 5.83337H12.8333V13.3334C12.8333 13.5544 12.7455 13.7663 12.5892 13.9226C12.4329 14.0789 12.221 14.1667 12 14.1667H3.99996C3.77895 14.1667 3.56698 14.0789 3.4107 13.9226C3.25442 13.7663 3.16663 13.5544 3.16663 13.3334V2.66671C3.16663 2.44569 3.25442 2.23373 3.4107 2.07745C3.56698 1.92117 3.77895 1.83337 3.99996 1.83337ZM9.83331 2.5405L12.1262 4.83337H9.83331V2.5405ZM5.33331 8.16663C5.05717 8.16663 4.83331 8.39048 4.83331 8.66663C4.83331 8.94277 5.05717 9.16663 5.33331 9.16663H10.6666C10.9428 9.16663 11.1666 8.94277 11.1666 8.66663C11.1666 8.39048 10.9428 8.16663 10.6666 8.16663H5.33331ZM4.83331 11.3334C4.83331 11.0572 5.05717 10.8334 5.33331 10.8334H10.6666C10.9428 10.8334 11.1666 11.0572 11.1666 11.3334C11.1666 11.6095 10.9428 11.8334 10.6666 11.8334H5.33331C5.05717 11.8334 4.83331 11.6095 4.83331 11.3334ZM5.33331 5.5C5.05717 5.5 4.83331 5.72386 4.83331 6C4.83331 6.27614 5.05717 6.5 5.33331 6.5H6.66665C6.94279 6.5 7.16665 6.27614 7.16665 6C7.16665 5.72386 6.94279 5.5 6.66665 5.5H5.33331Z" }));
|
|
1323
|
+
const MessageFile = ({
|
|
1324
|
+
name,
|
|
1325
|
+
type,
|
|
1326
|
+
url,
|
|
1327
|
+
limit = 100,
|
|
1328
|
+
fileIcon = /* @__PURE__ */ jsx(SvgFile, {})
|
|
1329
|
+
}) => {
|
|
1330
|
+
const { theme } = useContext(ChatContext);
|
|
1331
|
+
const isImage = type == null ? void 0 : type.startsWith("image/");
|
|
1332
|
+
return /* @__PURE__ */ jsxs(
|
|
1333
|
+
"figure",
|
|
1334
|
+
{
|
|
1335
|
+
className: cn(theme.messages.message.files.file.base),
|
|
1336
|
+
onClick: () => {
|
|
1337
|
+
window.open(url, "_blank");
|
|
1338
|
+
},
|
|
1339
|
+
children: [
|
|
1340
|
+
isImage ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("img", { src: url, className: "h-10 w-10" }) }) : /* @__PURE__ */ jsx(Fragment, { children: fileIcon }),
|
|
1341
|
+
name && /* @__PURE__ */ jsx("figcaption", { children: name && /* @__PURE__ */ jsx("span", { className: cn(theme.messages.message.files.file.name), children: /* @__PURE__ */ jsx(Ellipsis, { value: name, limit }) }) })
|
|
1342
|
+
]
|
|
1343
|
+
}
|
|
1344
|
+
);
|
|
1345
|
+
};
|
|
1346
|
+
const MessageFiles = ({ files, children }) => {
|
|
1347
|
+
const { theme } = useContext(ChatContext);
|
|
1348
|
+
const Comp = children ? Slot : MessageFile;
|
|
1349
|
+
if (!files || files.length === 0) {
|
|
1350
|
+
return null;
|
|
1351
|
+
}
|
|
1352
|
+
return files.length > 0 && /* @__PURE__ */ jsx("div", { className: cn(theme.messages.message.files.base), children: files.map((file, index) => /* @__PURE__ */ jsx(Comp, { ...file, children }, index)) });
|
|
1353
|
+
};
|
|
1295
1354
|
const MessageQuestion = ({
|
|
1296
1355
|
question,
|
|
1356
|
+
files,
|
|
1297
1357
|
children
|
|
1298
1358
|
}) => {
|
|
1299
|
-
const { theme, remarkPlugins
|
|
1359
|
+
const { theme, remarkPlugins } = useContext(ChatContext);
|
|
1300
1360
|
const Comp = children ? Slot : "div";
|
|
1301
|
-
|
|
1361
|
+
const [expanded, setExpanded] = useState(false);
|
|
1362
|
+
const isLong = question.length > 500;
|
|
1363
|
+
return /* @__PURE__ */ jsxs(Comp, { className: cn(theme.messages.message.question, {
|
|
1364
|
+
[theme.messages.message.overlay]: isLong && !expanded
|
|
1365
|
+
}), children: [
|
|
1366
|
+
/* @__PURE__ */ jsx(MessageFiles, { files }),
|
|
1367
|
+
children || /* @__PURE__ */ jsx(Markdown, { remarkPlugins, children: question }),
|
|
1368
|
+
isLong && !expanded && /* @__PURE__ */ jsx(
|
|
1369
|
+
Button,
|
|
1370
|
+
{
|
|
1371
|
+
variant: "link",
|
|
1372
|
+
size: "small",
|
|
1373
|
+
className: theme.messages.message.expand,
|
|
1374
|
+
onClick: () => setExpanded(true),
|
|
1375
|
+
children: "Show more"
|
|
1376
|
+
}
|
|
1377
|
+
)
|
|
1378
|
+
] });
|
|
1302
1379
|
};
|
|
1303
1380
|
const MessageResponse = ({
|
|
1304
1381
|
response,
|
|
@@ -1308,7 +1385,7 @@ const MessageResponse = ({
|
|
|
1308
1385
|
const {
|
|
1309
1386
|
theme,
|
|
1310
1387
|
isCompact,
|
|
1311
|
-
remarkPlugins
|
|
1388
|
+
remarkPlugins
|
|
1312
1389
|
} = useContext(ChatContext);
|
|
1313
1390
|
const Comp = children ? Slot : "div";
|
|
1314
1391
|
return /* @__PURE__ */ jsx(
|
|
@@ -1334,38 +1411,6 @@ const MessageResponse = ({
|
|
|
1334
1411
|
}
|
|
1335
1412
|
);
|
|
1336
1413
|
};
|
|
1337
|
-
const SvgFile = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 16, height: 16, viewBox: "0 0 16 16", fill: "currentColor", ...props }, /* @__PURE__ */ React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M2.7036 1.37034C3.04741 1.02653 3.51373 0.833374 3.99996 0.833374H9.33329H9.33331C9.47275 0.833374 9.59885 0.890449 9.68954 0.98251L13.6843 4.97722C13.7763 5.0679 13.8333 5.19398 13.8333 5.33337L13.8333 5.3379V13.3334C13.8333 13.8196 13.6401 14.2859 13.2963 14.6297C12.9525 14.9736 12.4862 15.1667 12 15.1667H3.99996C3.51373 15.1667 3.04741 14.9736 2.7036 14.6297C2.35978 14.2859 2.16663 13.8196 2.16663 13.3334V2.66671C2.16663 2.18048 2.35978 1.71416 2.7036 1.37034ZM3.99996 1.83337H8.83331V5.33337C8.83331 5.60952 9.05717 5.83337 9.33331 5.83337H12.8333V13.3334C12.8333 13.5544 12.7455 13.7663 12.5892 13.9226C12.4329 14.0789 12.221 14.1667 12 14.1667H3.99996C3.77895 14.1667 3.56698 14.0789 3.4107 13.9226C3.25442 13.7663 3.16663 13.5544 3.16663 13.3334V2.66671C3.16663 2.44569 3.25442 2.23373 3.4107 2.07745C3.56698 1.92117 3.77895 1.83337 3.99996 1.83337ZM9.83331 2.5405L12.1262 4.83337H9.83331V2.5405ZM5.33331 8.16663C5.05717 8.16663 4.83331 8.39048 4.83331 8.66663C4.83331 8.94277 5.05717 9.16663 5.33331 9.16663H10.6666C10.9428 9.16663 11.1666 8.94277 11.1666 8.66663C11.1666 8.39048 10.9428 8.16663 10.6666 8.16663H5.33331ZM4.83331 11.3334C4.83331 11.0572 5.05717 10.8334 5.33331 10.8334H10.6666C10.9428 10.8334 11.1666 11.0572 11.1666 11.3334C11.1666 11.6095 10.9428 11.8334 10.6666 11.8334H5.33331C5.05717 11.8334 4.83331 11.6095 4.83331 11.3334ZM5.33331 5.5C5.05717 5.5 4.83331 5.72386 4.83331 6C4.83331 6.27614 5.05717 6.5 5.33331 6.5H6.66665C6.94279 6.5 7.16665 6.27614 7.16665 6C7.16665 5.72386 6.94279 5.5 6.66665 5.5H5.33331Z" }));
|
|
1338
|
-
const MessageFile = ({
|
|
1339
|
-
name,
|
|
1340
|
-
type,
|
|
1341
|
-
url,
|
|
1342
|
-
limit = 100,
|
|
1343
|
-
fileIcon = /* @__PURE__ */ jsx(SvgFile, {})
|
|
1344
|
-
}) => {
|
|
1345
|
-
const { theme } = useContext(ChatContext);
|
|
1346
|
-
const isImage = type == null ? void 0 : type.startsWith("image/");
|
|
1347
|
-
return /* @__PURE__ */ jsxs(
|
|
1348
|
-
"figure",
|
|
1349
|
-
{
|
|
1350
|
-
className: cn(theme.messages.message.files.file.base),
|
|
1351
|
-
onClick: () => {
|
|
1352
|
-
window.open(url, "_blank");
|
|
1353
|
-
},
|
|
1354
|
-
children: [
|
|
1355
|
-
isImage ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("img", { src: url, className: "h-10 w-10" }) }) : /* @__PURE__ */ jsx(Fragment, { children: fileIcon }),
|
|
1356
|
-
name && /* @__PURE__ */ jsx("figcaption", { children: name && /* @__PURE__ */ jsx("span", { className: cn(theme.messages.message.files.file.name), children: /* @__PURE__ */ jsx(Ellipsis, { value: name, limit }) }) })
|
|
1357
|
-
]
|
|
1358
|
-
}
|
|
1359
|
-
);
|
|
1360
|
-
};
|
|
1361
|
-
const MessageFiles = ({ files, children }) => {
|
|
1362
|
-
const { theme } = useContext(ChatContext);
|
|
1363
|
-
const Comp = children ? Slot : MessageFile;
|
|
1364
|
-
if (!files || files.length === 0) {
|
|
1365
|
-
return null;
|
|
1366
|
-
}
|
|
1367
|
-
return files.length > 0 && /* @__PURE__ */ jsx("div", { className: cn(theme.messages.message.files.base), children: files.map((file, index) => /* @__PURE__ */ jsx(Comp, { ...file, children }, index)) });
|
|
1368
|
-
};
|
|
1369
1414
|
const MessageSource = ({ title, url, image, limit = 50 }) => {
|
|
1370
1415
|
const { theme, isCompact } = useContext(ChatContext);
|
|
1371
1416
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1497,8 +1542,7 @@ const SessionMessage = ({
|
|
|
1497
1542
|
const { theme, isLoading } = useContext(ChatContext);
|
|
1498
1543
|
return /* @__PURE__ */ jsxs(motion.div, { variants: messageVariants, children: [
|
|
1499
1544
|
/* @__PURE__ */ jsx(Card, { className: cn(theme.messages.message.base), children: children || /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1500
|
-
/* @__PURE__ */ jsx(
|
|
1501
|
-
/* @__PURE__ */ jsx(MessageQuestion, { question: conversation.question }),
|
|
1545
|
+
/* @__PURE__ */ jsx(MessageQuestion, { question: conversation.question, files: conversation.files }),
|
|
1502
1546
|
/* @__PURE__ */ jsx(
|
|
1503
1547
|
MessageResponse,
|
|
1504
1548
|
{
|
|
@@ -1629,11 +1673,13 @@ const chatTheme = {
|
|
|
1629
1673
|
message: {
|
|
1630
1674
|
base: "mt-4 mb-4 flex flex-col p-0 rounded border-none bg-transparent",
|
|
1631
1675
|
question: [
|
|
1632
|
-
"font-semibold mb-4 px-4 py-4 pb-2 rounded-3xl rounded-br-none text-typography border bg-gray-200 border-gray-300 text-gray-900",
|
|
1676
|
+
"relative font-semibold mb-4 px-4 py-4 pb-2 rounded-3xl rounded-br-none text-typography border bg-gray-200 border-gray-300 text-gray-900",
|
|
1633
1677
|
"dark:bg-gray-900/60 dark:border-gray-700/50 dark:text-gray-100"
|
|
1634
1678
|
].join(" "),
|
|
1635
|
-
response: ["data-[compact=false]:px-4 text-gray-900", "dark:text-gray-100"].join(" "),
|
|
1679
|
+
response: ["relative data-[compact=false]:px-4 text-gray-900", "dark:text-gray-100"].join(" "),
|
|
1680
|
+
overlay: `overflow-y-hidden max-h-[350px] after:content-[''] after:absolute after:inset-x-0 after:bottom-0 after:h-16 after:bg-gradient-to-b after:from-transparent dark:after:to-gray-900 after:to-gray-200`,
|
|
1636
1681
|
cursor: "inline-block w-1 h-4 bg-current",
|
|
1682
|
+
expand: "absolute bottom-1 right-1 z-10",
|
|
1637
1683
|
files: {
|
|
1638
1684
|
base: "mb-2 flex flex-wrap gap-3 ",
|
|
1639
1685
|
file: {
|
|
@@ -1732,7 +1778,7 @@ const Chat = ({
|
|
|
1732
1778
|
activeSessionId,
|
|
1733
1779
|
theme: customTheme = chatTheme,
|
|
1734
1780
|
onNewSession,
|
|
1735
|
-
remarkPlugins,
|
|
1781
|
+
remarkPlugins = [remarkGfm, remarkYoutube, remarkMath],
|
|
1736
1782
|
disabled,
|
|
1737
1783
|
style,
|
|
1738
1784
|
className
|
|
@@ -1999,6 +2045,7 @@ export {
|
|
|
1999
2045
|
ChatContext,
|
|
2000
2046
|
ChatInput,
|
|
2001
2047
|
CodeHighlighter,
|
|
2048
|
+
FileInput,
|
|
2002
2049
|
Markdown,
|
|
2003
2050
|
MessageActions,
|
|
2004
2051
|
MessageFile,
|