reachat 1.3.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.
@@ -33,22 +33,57 @@
33
33
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
34
34
  const SvgSend = (props) => /* @__PURE__ */ React__namespace.createElement("svg", { width: 17, height: 17, viewBox: "0 0 17 17", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React__namespace.createElement("g", { id: "send" }, /* @__PURE__ */ React__namespace.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" })));
35
35
  const SvgStop = (props) => /* @__PURE__ */ React__namespace.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__namespace.createElement("path", { d: "m15 9-6 6" }), /* @__PURE__ */ React__namespace.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__namespace.createElement("path", { d: "m9 9 6 6" }));
36
- const SvgPaperclip = (props) => /* @__PURE__ */ React__namespace.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__namespace.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" }));
37
36
  const ChatContext = React.createContext({
38
37
  sessions: [],
39
38
  activeSessionId: null
40
39
  });
40
+ const SvgPaperclip = (props) => /* @__PURE__ */ React__namespace.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__namespace.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" }));
41
+ const FileInput = ({
42
+ allowedFiles,
43
+ onFileUpload,
44
+ isLoading,
45
+ disabled,
46
+ attachIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgPaperclip, {})
47
+ }) => {
48
+ const { theme } = React.useContext(ChatContext);
49
+ const fileInputRef = React.useRef(null);
50
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
51
+ /* @__PURE__ */ jsxRuntime.jsx(
52
+ "input",
53
+ {
54
+ type: "file",
55
+ ref: fileInputRef,
56
+ className: "hidden",
57
+ accept: allowedFiles.join(","),
58
+ onChange: onFileUpload
59
+ }
60
+ ),
61
+ /* @__PURE__ */ jsxRuntime.jsx(
62
+ reablocks.Button,
63
+ {
64
+ title: "Upload",
65
+ variant: "text",
66
+ disabled: isLoading || disabled,
67
+ className: reablocks.cn(theme.input.upload),
68
+ onClick: () => {
69
+ var _a;
70
+ return (_a = fileInputRef.current) == null ? void 0 : _a.click();
71
+ },
72
+ children: attachIcon
73
+ }
74
+ )
75
+ ] });
76
+ };
41
77
  const ChatInput = React.forwardRef(({
42
78
  allowedFiles,
43
79
  placeholder,
44
80
  defaultValue,
45
81
  sendIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgSend, {}),
46
82
  stopIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgStop, {}),
47
- attachIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgPaperclip, {})
83
+ attachIcon
48
84
  }, ref) => {
49
85
  const { theme, isLoading, disabled, sendMessage, stopMessage, fileUpload } = React.useContext(ChatContext);
50
86
  const [message, setMessage] = React.useState("");
51
- const fileInputRef = React.useRef(null);
52
87
  const inputRef = React.useRef(null);
53
88
  React.useImperativeHandle(ref, () => ({
54
89
  focus: () => {
@@ -92,32 +127,16 @@
92
127
  }
93
128
  ),
94
129
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: reablocks.cn(theme.input.actions.base), children: [
95
- (allowedFiles == null ? void 0 : allowedFiles.length) > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
96
- /* @__PURE__ */ jsxRuntime.jsx(
97
- "input",
98
- {
99
- type: "file",
100
- ref: fileInputRef,
101
- className: "hidden",
102
- accept: allowedFiles.join(","),
103
- onChange: handleFileUpload
104
- }
105
- ),
106
- /* @__PURE__ */ jsxRuntime.jsx(
107
- reablocks.Button,
108
- {
109
- title: "Upload",
110
- variant: "text",
111
- disabled: isLoading || disabled,
112
- className: reablocks.cn(theme.input.upload),
113
- onClick: () => {
114
- var _a;
115
- return (_a = fileInputRef.current) == null ? void 0 : _a.click();
116
- },
117
- children: attachIcon
118
- }
119
- )
120
- ] }),
130
+ (allowedFiles == null ? void 0 : allowedFiles.length) > 0 && /* @__PURE__ */ jsxRuntime.jsx(
131
+ FileInput,
132
+ {
133
+ allowedFiles,
134
+ onFileUpload: handleFileUpload,
135
+ isLoading,
136
+ disabled,
137
+ attachIcon
138
+ }
139
+ ),
121
140
  isLoading && /* @__PURE__ */ jsxRuntime.jsx(
122
141
  reablocks.Button,
123
142
  {
@@ -1306,8 +1325,41 @@
1306
1325
  ];
1307
1326
  }
1308
1327
  }
1328
+ const SvgFile = (props) => /* @__PURE__ */ React__namespace.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 16, height: 16, viewBox: "0 0 16 16", fill: "currentColor", ...props }, /* @__PURE__ */ React__namespace.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" }));
1329
+ const MessageFile = ({
1330
+ name,
1331
+ type,
1332
+ url,
1333
+ limit = 100,
1334
+ fileIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgFile, {})
1335
+ }) => {
1336
+ const { theme } = React.useContext(ChatContext);
1337
+ const isImage = type == null ? void 0 : type.startsWith("image/");
1338
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1339
+ "figure",
1340
+ {
1341
+ className: reablocks.cn(theme.messages.message.files.file.base),
1342
+ onClick: () => {
1343
+ window.open(url, "_blank");
1344
+ },
1345
+ children: [
1346
+ isImage ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: url, className: "h-10 w-10" }) }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fileIcon }),
1347
+ name && /* @__PURE__ */ jsxRuntime.jsx("figcaption", { children: name && /* @__PURE__ */ jsxRuntime.jsx("span", { className: reablocks.cn(theme.messages.message.files.file.name), children: /* @__PURE__ */ jsxRuntime.jsx(reablocks.Ellipsis, { value: name, limit }) }) })
1348
+ ]
1349
+ }
1350
+ );
1351
+ };
1352
+ const MessageFiles = ({ files, children }) => {
1353
+ const { theme } = React.useContext(ChatContext);
1354
+ const Comp = children ? reactSlot.Slot : MessageFile;
1355
+ if (!files || files.length === 0) {
1356
+ return null;
1357
+ }
1358
+ return files.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: reablocks.cn(theme.messages.message.files.base), children: files.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...file, children }, index)) });
1359
+ };
1309
1360
  const MessageQuestion = ({
1310
1361
  question,
1362
+ files,
1311
1363
  children
1312
1364
  }) => {
1313
1365
  const { theme, remarkPlugins } = React.useContext(ChatContext);
@@ -1317,6 +1369,7 @@
1317
1369
  return /* @__PURE__ */ jsxRuntime.jsxs(Comp, { className: reablocks.cn(theme.messages.message.question, {
1318
1370
  [theme.messages.message.overlay]: isLong && !expanded
1319
1371
  }), children: [
1372
+ /* @__PURE__ */ jsxRuntime.jsx(MessageFiles, { files }),
1320
1373
  children || /* @__PURE__ */ jsxRuntime.jsx(Markdown, { remarkPlugins, children: question }),
1321
1374
  isLong && !expanded && /* @__PURE__ */ jsxRuntime.jsx(
1322
1375
  reablocks.Button,
@@ -1364,38 +1417,6 @@
1364
1417
  }
1365
1418
  );
1366
1419
  };
1367
- const SvgFile = (props) => /* @__PURE__ */ React__namespace.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 16, height: 16, viewBox: "0 0 16 16", fill: "currentColor", ...props }, /* @__PURE__ */ React__namespace.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" }));
1368
- const MessageFile = ({
1369
- name,
1370
- type,
1371
- url,
1372
- limit = 100,
1373
- fileIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgFile, {})
1374
- }) => {
1375
- const { theme } = React.useContext(ChatContext);
1376
- const isImage = type == null ? void 0 : type.startsWith("image/");
1377
- return /* @__PURE__ */ jsxRuntime.jsxs(
1378
- "figure",
1379
- {
1380
- className: reablocks.cn(theme.messages.message.files.file.base),
1381
- onClick: () => {
1382
- window.open(url, "_blank");
1383
- },
1384
- children: [
1385
- isImage ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: url, className: "h-10 w-10" }) }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fileIcon }),
1386
- name && /* @__PURE__ */ jsxRuntime.jsx("figcaption", { children: name && /* @__PURE__ */ jsxRuntime.jsx("span", { className: reablocks.cn(theme.messages.message.files.file.name), children: /* @__PURE__ */ jsxRuntime.jsx(reablocks.Ellipsis, { value: name, limit }) }) })
1387
- ]
1388
- }
1389
- );
1390
- };
1391
- const MessageFiles = ({ files, children }) => {
1392
- const { theme } = React.useContext(ChatContext);
1393
- const Comp = children ? reactSlot.Slot : MessageFile;
1394
- if (!files || files.length === 0) {
1395
- return null;
1396
- }
1397
- return files.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: reablocks.cn(theme.messages.message.files.base), children: files.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...file, children }, index)) });
1398
- };
1399
1420
  const MessageSource = ({ title, url, image, limit = 50 }) => {
1400
1421
  const { theme, isCompact } = React.useContext(ChatContext);
1401
1422
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1527,8 +1548,7 @@ ${response}`),
1527
1548
  const { theme, isLoading } = React.useContext(ChatContext);
1528
1549
  return /* @__PURE__ */ jsxRuntime.jsxs(framerMotion.motion.div, { variants: messageVariants, children: [
1529
1550
  /* @__PURE__ */ jsxRuntime.jsx(reablocks.Card, { className: reablocks.cn(theme.messages.message.base), children: children || /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1530
- /* @__PURE__ */ jsxRuntime.jsx(MessageFiles, { files: conversation.files }),
1531
- /* @__PURE__ */ jsxRuntime.jsx(MessageQuestion, { question: conversation.question }),
1551
+ /* @__PURE__ */ jsxRuntime.jsx(MessageQuestion, { question: conversation.question, files: conversation.files }),
1532
1552
  /* @__PURE__ */ jsxRuntime.jsx(
1533
1553
  MessageResponse,
1534
1554
  {
@@ -2030,6 +2050,7 @@ ${response}`),
2030
2050
  exports2.ChatContext = ChatContext;
2031
2051
  exports2.ChatInput = ChatInput;
2032
2052
  exports2.CodeHighlighter = CodeHighlighter;
2053
+ exports2.FileInput = FileInput;
2033
2054
  exports2.Markdown = Markdown;
2034
2055
  exports2.MessageActions = MessageActions;
2035
2056
  exports2.MessageFile = MessageFile;