reachat 1.0.3 → 1.0.4

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.
@@ -14,6 +14,10 @@ export interface SessionListItemProps extends PropsWithChildren {
14
14
  * Icon to show for delete.
15
15
  */
16
16
  deleteIcon?: ReactElement;
17
+ /**
18
+ * Icon to show for chat.
19
+ */
20
+ chatIcon?: ReactElement;
17
21
  /**
18
22
  * Limit for the ellipsis.
19
23
  */
package/dist/docs.json CHANGED
@@ -825,6 +825,27 @@
825
825
  "name": "ReactElement<any, string | JSXElementConstructor<any>>"
826
826
  }
827
827
  },
828
+ "chatIcon": {
829
+ "defaultValue": {
830
+ "value": "<ChatIcon className=\"mr-2\" />"
831
+ },
832
+ "description": "Icon to show for chat.",
833
+ "name": "chatIcon",
834
+ "parent": {
835
+ "fileName": "src/SessionsList/SessionListItem.tsx",
836
+ "name": "SessionListItemProps"
837
+ },
838
+ "declarations": [
839
+ {
840
+ "fileName": "src/SessionsList/SessionListItem.tsx",
841
+ "name": "SessionListItemProps"
842
+ }
843
+ ],
844
+ "required": false,
845
+ "type": {
846
+ "name": "ReactElement<any, string | JSXElementConstructor<any>>"
847
+ }
848
+ },
828
849
  "limit": {
829
850
  "defaultValue": {
830
851
  "value": "100"
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import { createContext, useContext, useState, useRef, useEffect, useMemo, useCallback } from "react";
4
- import { cn, Textarea, Button, Ellipsis, DateFormat, IconButton, Card, useInfinityList, useComponentTheme, List, ListItem } from "reablocks";
4
+ import { cn, Textarea, Button, Ellipsis, DateFormat, IconButton, Card, Divider, useInfinityList, useComponentTheme, List, ListItem } from "reablocks";
5
5
  import { Slot } from "@radix-ui/react-slot";
6
6
  import { motion, AnimatePresence } from "framer-motion";
7
7
  import ReactMarkdown from "react-markdown";
@@ -11,7 +11,7 @@ import { findAndReplace } from "mdast-util-find-and-replace";
11
11
  import remarkYoutube from "remark-youtube";
12
12
  import { useHotkeys } from "reakeys";
13
13
  import { isToday, isYesterday, isThisWeek, isThisMonth, isThisYear, format } from "date-fns";
14
- const SvgSend = (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-send-horizontal", ...props }, /* @__PURE__ */ React.createElement("path", { d: "m3 3 3 9-3 9 19-9Z" }), /* @__PURE__ */ React.createElement("path", { d: "M6 12h16" }));
14
+ 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" })));
15
15
  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" }));
16
16
  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" }));
17
17
  const ChatContext = createContext({
@@ -63,51 +63,54 @@ const ChatInput = ({
63
63
  disabled: isLoading || disabled
64
64
  }
65
65
  ),
66
- (allowedFiles == null ? void 0 : allowedFiles.length) > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
67
- /* @__PURE__ */ jsx(
68
- "input",
66
+ /* @__PURE__ */ jsxs("div", { className: cn(theme.input.actions.base), children: [
67
+ (allowedFiles == null ? void 0 : allowedFiles.length) > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
68
+ /* @__PURE__ */ jsx(
69
+ "input",
70
+ {
71
+ type: "file",
72
+ ref: fileInputRef,
73
+ className: "hidden",
74
+ accept: allowedFiles.join(","),
75
+ onChange: handleFileUpload
76
+ }
77
+ ),
78
+ /* @__PURE__ */ jsx(
79
+ Button,
80
+ {
81
+ title: "Upload",
82
+ variant: "text",
83
+ disabled: isLoading || disabled,
84
+ className: cn(theme.input.upload),
85
+ onClick: () => {
86
+ var _a;
87
+ return (_a = fileInputRef.current) == null ? void 0 : _a.click();
88
+ },
89
+ children: attachIcon
90
+ }
91
+ )
92
+ ] }),
93
+ isLoading && /* @__PURE__ */ jsx(
94
+ Button,
69
95
  {
70
- type: "file",
71
- ref: fileInputRef,
72
- className: "hidden",
73
- accept: allowedFiles.join(","),
74
- onChange: handleFileUpload
96
+ title: "Stop",
97
+ className: cn(theme.input.actions.stop),
98
+ onClick: stopMessage,
99
+ disabled,
100
+ children: stopIcon
75
101
  }
76
102
  ),
77
103
  /* @__PURE__ */ jsx(
78
104
  Button,
79
105
  {
80
- title: "Upload",
106
+ title: "Send",
107
+ className: cn(theme.input.actions.send),
108
+ onClick: handleSendMessage,
81
109
  disabled: isLoading || disabled,
82
- className: cn(theme.input.upload),
83
- onClick: () => {
84
- var _a;
85
- return (_a = fileInputRef.current) == null ? void 0 : _a.click();
86
- },
87
- children: attachIcon
110
+ children: sendIcon
88
111
  }
89
112
  )
90
- ] }),
91
- isLoading && /* @__PURE__ */ jsx(
92
- Button,
93
- {
94
- title: "Stop",
95
- className: cn(theme.input.stop),
96
- onClick: stopMessage,
97
- disabled,
98
- children: stopIcon
99
- }
100
- ),
101
- /* @__PURE__ */ jsx(
102
- Button,
103
- {
104
- title: "Send",
105
- className: cn(theme.input.send),
106
- onClick: handleSendMessage,
107
- disabled: isLoading || disabled,
108
- children: sendIcon
109
- }
110
- )
113
+ ] })
111
114
  ] });
112
115
  };
113
116
  const SessionEmpty = ({
@@ -1459,29 +1462,32 @@ const SessionMessage = ({
1459
1462
  children
1460
1463
  }) => {
1461
1464
  const { theme, isLoading } = useContext(ChatContext);
1462
- return /* @__PURE__ */ jsx(motion.div, { variants: messageVariants, children: /* @__PURE__ */ jsx(Card, { className: cn(theme.messages.message.base), children: children || /* @__PURE__ */ jsxs(Fragment, { children: [
1463
- /* @__PURE__ */ jsx(MessageFiles, { files: conversation.files }),
1464
- /* @__PURE__ */ jsx(MessageQuestion, { question: conversation.question }),
1465
- /* @__PURE__ */ jsx(
1466
- MessageResponse,
1467
- {
1468
- response: conversation.response,
1469
- isLoading: isLast && isLoading
1470
- }
1471
- ),
1472
- /* @__PURE__ */ jsx(MessageSources, { sources: conversation.sources }),
1473
- /* @__PURE__ */ jsx(
1474
- MessageActions,
1475
- {
1476
- question: conversation.question,
1477
- response: conversation.response,
1478
- copyIcon: /* @__PURE__ */ jsx(SvgCopy, {}),
1479
- thumbsUpIcon: /* @__PURE__ */ jsx(SvgThumbsUp, {}),
1480
- thumbsDownIcon: /* @__PURE__ */ jsx(SvgThumbsDown, {}),
1481
- refreshIcon: /* @__PURE__ */ jsx(SvgRefresh, {})
1482
- }
1483
- )
1484
- ] }) }) }, conversation.id);
1465
+ return /* @__PURE__ */ jsxs(motion.div, { variants: messageVariants, children: [
1466
+ /* @__PURE__ */ jsx(Card, { className: cn(theme.messages.message.base), children: children || /* @__PURE__ */ jsxs(Fragment, { children: [
1467
+ /* @__PURE__ */ jsx(MessageFiles, { files: conversation.files }),
1468
+ /* @__PURE__ */ jsx(MessageQuestion, { question: conversation.question }),
1469
+ /* @__PURE__ */ jsx(
1470
+ MessageResponse,
1471
+ {
1472
+ response: conversation.response,
1473
+ isLoading: isLast && isLoading
1474
+ }
1475
+ ),
1476
+ /* @__PURE__ */ jsx(MessageSources, { sources: conversation.sources }),
1477
+ /* @__PURE__ */ jsx(
1478
+ MessageActions,
1479
+ {
1480
+ question: conversation.question,
1481
+ response: conversation.response,
1482
+ copyIcon: /* @__PURE__ */ jsx(SvgCopy, {}),
1483
+ thumbsUpIcon: /* @__PURE__ */ jsx(SvgThumbsUp, {}),
1484
+ thumbsDownIcon: /* @__PURE__ */ jsx(SvgThumbsDown, {}),
1485
+ refreshIcon: /* @__PURE__ */ jsx(SvgRefresh, {})
1486
+ }
1487
+ )
1488
+ ] }) }),
1489
+ !isLast && /* @__PURE__ */ jsx(Divider, {})
1490
+ ] }, conversation.id);
1485
1491
  };
1486
1492
  const containerVariants = {
1487
1493
  hidden: {},
@@ -1558,13 +1564,13 @@ const chatTheme = {
1558
1564
  empty: "text-center flex-1",
1559
1565
  sessions: {
1560
1566
  base: "overflow-auto",
1561
- console: "min-w-[150px] w-[30%] max-w-[300px] bg-[#11111F] p-5 rounded",
1567
+ console: "min-w-[150px] w-[30%] max-w-[300px] bg-[#11111F] p-5 rounded-3xl",
1562
1568
  companion: "w-full h-full",
1563
- group: "text-xs text-gray-400 mt-4",
1564
- create: "mb-4",
1569
+ group: "text-xs text-gray-400 mt-4 hover:bg-transparent mb-1",
1570
+ create: "relative mb-4 rounded-[10px]",
1565
1571
  session: {
1566
- base: "",
1567
- active: " text-primary",
1572
+ base: "my-1 rounded-[10px] p-2 text-typography hover:bg-gray-800/50 border border-transparent hover:border-gray-700/50",
1573
+ active: "bg-gray-800/70 border border-gray-700/70 hover:bg-gray-800/50 border-gray-700/50 text-white",
1568
1574
  delete: "[&>svg]:w-4 [&>svg]:h-4 opacity-50"
1569
1575
  }
1570
1576
  },
@@ -1580,8 +1586,8 @@ const chatTheme = {
1580
1586
  header: "flex justify-between items-start gap-2",
1581
1587
  showMore: "mb-4",
1582
1588
  message: {
1583
- base: "mb-6 flex flex-col p-5 rounded",
1584
- question: "font-semibold text-gray-400 mb-1",
1589
+ base: "mt-4 mb-4 flex flex-col p-0 rounded border-none",
1590
+ question: "font-semibold text-gray-400 mb-4 px-4 py-3 pb-1 rounded-3xl rounded-br-none text-typography bg-gray-900/60 border border-gray-700/50",
1585
1591
  response: "",
1586
1592
  cursor: "inline-block w-1 h-4 bg-current",
1587
1593
  files: {
@@ -1613,20 +1619,23 @@ const chatTheme = {
1613
1619
  ol: "mb-4 list-decimal"
1614
1620
  },
1615
1621
  footer: {
1616
- base: "mt-3 flex gap-3",
1617
- copy: "[&>svg]:w-4 [&>svg]:h-4 opacity-50",
1618
- upvote: "[&>svg]:w-4 [&>svg]:h-4 opacity-50",
1619
- downvote: "[&>svg]:w-4 [&>svg]:h-4 opacity-50",
1620
- refresh: "[&>svg]:w-4 [&>svg]:h-4 opacity-50"
1622
+ base: "mt-3 flex gap-1.5",
1623
+ copy: "p-3 rounded-[10px] [&>svg]:w-4 [&>svg]:h-4 opacity-50 hover:!opacity-100 hover:bg-gray-700/40 hover:text-white",
1624
+ upvote: "p-3 rounded-[10px] [&>svg]:w-4 [&>svg]:h-4 opacity-50 hover:!opacity-100 hover:bg-gray-700/40 hover:text-white",
1625
+ downvote: "p-3 rounded-[10px] [&>svg]:w-4 [&>svg]:h-4 opacity-50 hover:!opacity-100 hover:bg-gray-700/40 hover:text-white",
1626
+ refresh: "p-3 rounded-[10px] [&>svg]:w-4 [&>svg]:h-4 opacity-50 hover:!opacity-100 hover:bg-gray-700/40 hover:text-white"
1621
1627
  }
1622
1628
  }
1623
1629
  },
1624
1630
  input: {
1625
- base: "flex mt-4",
1626
- upload: "px-4 py-2 text-white",
1627
- input: "w-full",
1628
- send: "px-4 py-2 text-white",
1629
- stop: "px-4 py-2 bg-red-500 text-white rounded hover:bg-red-700"
1631
+ base: "flex mt-4 relative",
1632
+ upload: "px-5 py-2 text-white size-10",
1633
+ input: "w-full text-typography border border-gray-700/70 rounded-3xl px-3 py-2 pr-16 after:!mx-10 [&>textarea]:w-full",
1634
+ actions: {
1635
+ base: "absolute flex gap-2 items-center right-5 top-[50%] -translate-y-1/2 z-10",
1636
+ send: "px-3 py-3 text-white bg-gray-800 hover:bg-primary-hover rounded-full ",
1637
+ stop: "px-2 py-2 bg-red-500 text-white rounded-full hover:bg-red-700 "
1638
+ }
1630
1639
  }
1631
1640
  };
1632
1641
  const useDimensions = () => {
@@ -1780,12 +1789,14 @@ const SessionsList = ({ children }) => {
1780
1789
  );
1781
1790
  };
1782
1791
  const SvgTrash = (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-trash-2", ...props }, /* @__PURE__ */ React.createElement("path", { d: "M3 6h18" }), /* @__PURE__ */ React.createElement("path", { d: "M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" }), /* @__PURE__ */ React.createElement("path", { d: "M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" }), /* @__PURE__ */ React.createElement("line", { x1: 10, x2: 10, y1: 11, y2: 17 }), /* @__PURE__ */ React.createElement("line", { x1: 14, x2: 14, y1: 11, y2: 17 }));
1792
+ const SvgChat = (props) => /* @__PURE__ */ React.createElement("svg", { width: 16, height: 17, viewBox: "0 0 16 17", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React.createElement("path", { d: "M8 3C4.55375 3 1.75 5.23753 1.75 7.98828C1.75 9.70653 2.83659 11.2762 4.62109 12.188C4.11184 13.0465 3.62587 13.7378 3.62012 13.7461C3.50687 13.9071 3.49862 14.1196 3.59912 14.2891C3.69012 14.4418 3.8543 14.5342 4.0293 14.5342C4.0483 14.5342 4.06743 14.533 4.08643 14.5308C4.15168 14.5233 5.66214 14.3364 7.50439 12.9604C7.67239 12.9712 7.8385 12.9766 8 12.9766C11.4462 12.9766 14.25 10.739 14.25 7.98828C14.25 5.23753 11.4462 3 8 3ZM8 4C10.8948 4 13.25 5.78903 13.25 7.98828C13.25 10.1875 10.8948 11.9766 8 11.9766C7.8055 11.9766 7.60225 11.968 7.396 11.9497C7.271 11.9382 7.1454 11.9752 7.0459 12.0527C6.3589 12.5855 5.72033 12.9308 5.20508 13.1528C5.38383 12.8648 5.57691 12.5418 5.76416 12.2061C5.83416 12.0813 5.84705 11.9324 5.7998 11.7974C5.75255 11.6624 5.64983 11.5542 5.51758 11.5C3.81033 10.7993 2.75 9.45328 2.75 7.98828C2.75 5.78903 5.10525 4 8 4ZM5.5 7.25C5.08575 7.25 4.75 7.58575 4.75 8C4.75 8.41425 5.08575 8.75 5.5 8.75C5.91425 8.75 6.25 8.41425 6.25 8C6.25 7.58575 5.91425 7.25 5.5 7.25ZM8 7.25C7.58575 7.25 7.25 7.58575 7.25 8C7.25 8.41425 7.58575 8.75 8 8.75C8.41425 8.75 8.75 8.41425 8.75 8C8.75 7.58575 8.41425 7.25 8 7.25ZM10.5 7.25C10.0857 7.25 9.75 7.58575 9.75 8C9.75 8.41425 10.0857 8.75 10.5 8.75C10.9143 8.75 11.25 8.41425 11.25 8C11.25 7.58575 10.9143 7.25 10.5 7.25Z", fill: "currentColor" }));
1783
1793
  const SessionListItem = ({
1784
1794
  children,
1785
1795
  session,
1786
1796
  deletable = true,
1787
1797
  limit = 100,
1788
- deleteIcon = /* @__PURE__ */ jsx(SvgTrash, {})
1798
+ deleteIcon = /* @__PURE__ */ jsx(SvgTrash, {}),
1799
+ chatIcon = /* @__PURE__ */ jsx(SvgChat, { className: "mr-2" })
1789
1800
  }) => {
1790
1801
  const { activeSessionId, selectSession, deleteSession, theme } = useContext(ChatContext);
1791
1802
  const Comp = children ? Slot : ListItem;
@@ -1799,6 +1810,7 @@ const SessionListItem = ({
1799
1810
  [theme.sessions.session.active]: session.id === activeSessionId
1800
1811
  }),
1801
1812
  onClick: () => selectSession == null ? void 0 : selectSession(session.id),
1813
+ start: chatIcon,
1802
1814
  end: /* @__PURE__ */ jsx(Fragment, { children: deletable && /* @__PURE__ */ jsx(
1803
1815
  IconButton,
1804
1816
  {
@@ -1816,24 +1828,26 @@ const SessionListItem = ({
1816
1828
  }
1817
1829
  );
1818
1830
  };
1831
+ const SvgPlus = (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: "add" }, /* @__PURE__ */ React.createElement("path", { id: "Vector", d: "M13.1667 9.16658H9.16671V13.1666H7.83337V9.16658H3.83337V7.83325H7.83337V3.83325H9.16671V7.83325H13.1667V9.16658Z", fill: "currentColor" })));
1819
1832
  const NewSessionButton = ({
1820
1833
  children,
1821
1834
  newSessionText = "New Session"
1822
1835
  }) => {
1823
1836
  const { theme, createSession, disabled } = useContext(ChatContext);
1824
1837
  const Comp = children ? Slot : Button;
1825
- return /* @__PURE__ */ jsx(
1838
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
1826
1839
  Comp,
1827
1840
  {
1828
1841
  fullWidth: true,
1829
1842
  disableMargins: true,
1830
1843
  color: "primary",
1844
+ startAdornment: /* @__PURE__ */ jsx(SvgPlus, {}),
1831
1845
  className: cn(theme.sessions.create),
1832
1846
  disabled,
1833
1847
  onClick: createSession,
1834
1848
  children: children || newSessionText
1835
1849
  }
1836
- );
1850
+ ) });
1837
1851
  };
1838
1852
  const sortOrder = [
1839
1853
  "Today",