reachat 3.3.0 → 3.4.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/Chat.d.ts +1 -1
- package/dist/Markdown/Markdown.d.ts +3 -2
- package/dist/Markdown/index.d.ts +1 -0
- package/dist/Markdown/types.d.ts +21 -0
- package/dist/index.css +12 -0
- package/dist/index.js +38 -42
- package/dist/index.js.map +1 -1
- package/dist/stories/Markdown.stories.tsx +92 -0
- package/dist/theme.d.ts +2 -21
- package/package.json +1 -1
package/dist/Chat.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { FC, PropsWithChildren } from 'react';
|
|
2
2
|
import { Components } from 'react-markdown';
|
|
3
3
|
import { Plugin } from 'unified';
|
|
4
|
-
import {
|
|
4
|
+
import { MarkdownTheme } from './types';
|
|
5
5
|
interface MarkdownWrapperProps extends PropsWithChildren {
|
|
6
6
|
/**
|
|
7
7
|
* Remark plugins to apply to the markdown content.
|
|
8
|
+
* @default [remarkGfm, remarkYoutube, remarkMath]
|
|
8
9
|
*/
|
|
9
10
|
remarkPlugins?: Plugin[];
|
|
10
11
|
/**
|
|
@@ -15,7 +16,7 @@ interface MarkdownWrapperProps extends PropsWithChildren {
|
|
|
15
16
|
/**
|
|
16
17
|
* Theme to apply to the markdown content.
|
|
17
18
|
*/
|
|
18
|
-
theme
|
|
19
|
+
theme: MarkdownTheme;
|
|
19
20
|
/**
|
|
20
21
|
* Custom components to override default markdown rendering.
|
|
21
22
|
* These will be merged with the default components.
|
package/dist/Markdown/index.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface MarkdownTheme {
|
|
2
|
+
hr: string;
|
|
3
|
+
p: string;
|
|
4
|
+
a: string;
|
|
5
|
+
table: string;
|
|
6
|
+
th: string;
|
|
7
|
+
td: string;
|
|
8
|
+
code: string;
|
|
9
|
+
inlineCode: string;
|
|
10
|
+
toolbar: string;
|
|
11
|
+
li: string;
|
|
12
|
+
ul: string;
|
|
13
|
+
ol: string;
|
|
14
|
+
copy: string;
|
|
15
|
+
h1: string;
|
|
16
|
+
h2: string;
|
|
17
|
+
h3: string;
|
|
18
|
+
h4: string;
|
|
19
|
+
h5: string;
|
|
20
|
+
h6: string;
|
|
21
|
+
}
|
package/dist/index.css
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
--color-green-600: oklch(62.7% 0.194 149.214);
|
|
36
36
|
--color-green-800: oklch(44.8% 0.119 151.328);
|
|
37
37
|
--color-green-950: oklch(26.6% 0.065 152.934);
|
|
38
|
+
--color-cyan-300: oklch(86.5% 0.127 207.078);
|
|
38
39
|
--color-cyan-500: oklch(71.5% 0.143 215.221);
|
|
39
40
|
--color-blue-100: oklch(93.2% 0.032 255.585);
|
|
40
41
|
--color-blue-200: oklch(88.2% 0.059 254.128);
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
--color-blue-700: oklch(48.8% 0.243 264.376);
|
|
46
47
|
--color-blue-900: oklch(37.9% 0.146 265.522);
|
|
47
48
|
--color-blue-950: oklch(28.2% 0.091 267.935);
|
|
49
|
+
--color-indigo-300: oklch(78.5% 0.115 274.713);
|
|
48
50
|
--color-indigo-600: oklch(51.1% 0.262 276.966);
|
|
49
51
|
--color-indigo-700: oklch(45.7% 0.24 277.023);
|
|
50
52
|
--color-violet-500: oklch(60.6% 0.25 292.717);
|
|
@@ -74,6 +76,7 @@
|
|
|
74
76
|
--spacing: 0.25rem;
|
|
75
77
|
--container-sm: 24rem;
|
|
76
78
|
--container-2xl: 42rem;
|
|
79
|
+
--container-4xl: 56rem;
|
|
77
80
|
--text-xs: 0.75rem;
|
|
78
81
|
--text-xs--line-height: calc(1 / 0.75);
|
|
79
82
|
--text-sm: 0.875rem;
|
|
@@ -1011,6 +1014,9 @@
|
|
|
1011
1014
|
.max-w-2xl {
|
|
1012
1015
|
max-width: var(--container-2xl);
|
|
1013
1016
|
}
|
|
1017
|
+
.max-w-4xl {
|
|
1018
|
+
max-width: var(--container-4xl);
|
|
1019
|
+
}
|
|
1014
1020
|
.max-w-10 {
|
|
1015
1021
|
max-width: calc(var(--spacing) * 10);
|
|
1016
1022
|
}
|
|
@@ -2307,6 +2313,9 @@
|
|
|
2307
2313
|
.text-blue-700 {
|
|
2308
2314
|
color: var(--color-blue-700);
|
|
2309
2315
|
}
|
|
2316
|
+
.text-cyan-300 {
|
|
2317
|
+
color: var(--color-cyan-300);
|
|
2318
|
+
}
|
|
2310
2319
|
.text-gray-100 {
|
|
2311
2320
|
color: var(--color-gray-100);
|
|
2312
2321
|
}
|
|
@@ -2331,6 +2340,9 @@
|
|
|
2331
2340
|
.text-green-500 {
|
|
2332
2341
|
color: var(--color-green-500);
|
|
2333
2342
|
}
|
|
2343
|
+
.text-indigo-300 {
|
|
2344
|
+
color: var(--color-indigo-300);
|
|
2345
|
+
}
|
|
2334
2346
|
.text-inherit {
|
|
2335
2347
|
color: inherit;
|
|
2336
2348
|
}
|
package/dist/index.js
CHANGED
|
@@ -15,14 +15,14 @@ import { AnimatePresence, motion } from "motion/react";
|
|
|
15
15
|
import ReactMarkdown from "react-markdown";
|
|
16
16
|
import rehypeKatex from "rehype-katex";
|
|
17
17
|
import rehypeRaw from "rehype-raw";
|
|
18
|
+
import remarkGfm from "remark-gfm";
|
|
19
|
+
import remarkMath from "remark-math";
|
|
20
|
+
import remarkYoutube from "remark-youtube";
|
|
18
21
|
import { Prism } from "react-syntax-highlighter";
|
|
19
22
|
import { AreaChart, AreaSeries, BarChart, BarSeries, LineChart, LineSeries, LinearXAxis, LinearYAxis, PieArcSeries, PieChart, RadialAreaChart, RadialAreaSeries, RadialBarChart, RadialBarSeries, SparklineChart } from "reaviz";
|
|
20
23
|
import { findAndReplace } from "mdast-util-find-and-replace";
|
|
21
24
|
import debounce from "lodash/debounce.js";
|
|
22
25
|
import { useHotkeys } from "reakeys";
|
|
23
|
-
import remarkGfm from "remark-gfm";
|
|
24
|
-
import remarkYoutube from "remark-youtube";
|
|
25
|
-
import remarkMath from "remark-math";
|
|
26
26
|
import { differenceInYears, format, isThisWeek, isToday, isYesterday } from "date-fns";
|
|
27
27
|
import { offset } from "@floating-ui/react";
|
|
28
28
|
import { z } from "zod";
|
|
@@ -1413,9 +1413,12 @@ var TableDataCell = ({ children, ...props }) => /* @__PURE__ */ jsx("td", {
|
|
|
1413
1413
|
});
|
|
1414
1414
|
//#endregion
|
|
1415
1415
|
//#region src/Markdown/Markdown.tsx
|
|
1416
|
-
var
|
|
1417
|
-
|
|
1418
|
-
|
|
1416
|
+
var defaultRemarkPlugins = [
|
|
1417
|
+
remarkGfm,
|
|
1418
|
+
remarkYoutube,
|
|
1419
|
+
remarkMath
|
|
1420
|
+
];
|
|
1421
|
+
var Markdown = ({ children, remarkPlugins = defaultRemarkPlugins, rehypePlugins = [rehypeRaw, rehypeKatex], theme, customComponents }) => {
|
|
1419
1422
|
return /* @__PURE__ */ jsx(ReactMarkdown, {
|
|
1420
1423
|
remarkPlugins,
|
|
1421
1424
|
rehypePlugins,
|
|
@@ -1424,85 +1427,80 @@ var Markdown = ({ children, remarkPlugins, rehypePlugins = [rehypeRaw, rehypeKat
|
|
|
1424
1427
|
code: ({ className, children, ...props }) => /* @__PURE__ */ jsx(CodeHighlighter, {
|
|
1425
1428
|
...props,
|
|
1426
1429
|
language: cn(className),
|
|
1427
|
-
inlineClassName: cn(theme.
|
|
1428
|
-
className: cn(theme.
|
|
1429
|
-
copyClassName: cn(theme.
|
|
1430
|
-
toolbarClassName: cn(theme.
|
|
1430
|
+
inlineClassName: cn(theme.inlineCode),
|
|
1431
|
+
className: cn(theme.code, className),
|
|
1432
|
+
copyClassName: cn(theme.copy),
|
|
1433
|
+
toolbarClassName: cn(theme.toolbar),
|
|
1431
1434
|
children
|
|
1432
1435
|
}),
|
|
1433
1436
|
table: (props) => /* @__PURE__ */ jsx(TableComponent, {
|
|
1434
1437
|
...props,
|
|
1435
|
-
className: cn(theme.
|
|
1438
|
+
className: cn(theme.table)
|
|
1436
1439
|
}),
|
|
1437
1440
|
th: (props) => /* @__PURE__ */ jsx(TableHeaderCell, {
|
|
1438
1441
|
...props,
|
|
1439
|
-
className: cn(theme.
|
|
1442
|
+
className: cn(theme.th)
|
|
1440
1443
|
}),
|
|
1441
1444
|
td: (props) => /* @__PURE__ */ jsx(TableDataCell, {
|
|
1442
1445
|
...props,
|
|
1443
|
-
className: cn(theme.
|
|
1446
|
+
className: cn(theme.td)
|
|
1444
1447
|
}),
|
|
1445
1448
|
a: (props) => /* @__PURE__ */ jsx("a", {
|
|
1446
1449
|
...props,
|
|
1447
|
-
className: cn(theme.
|
|
1450
|
+
className: cn(theme.a)
|
|
1448
1451
|
}),
|
|
1449
1452
|
hr: (props) => /* @__PURE__ */ jsx("hr", {
|
|
1450
1453
|
...props,
|
|
1451
|
-
className: cn(theme.
|
|
1454
|
+
className: cn(theme.hr)
|
|
1452
1455
|
}),
|
|
1453
1456
|
p: (props) => /* @__PURE__ */ jsx("p", {
|
|
1454
1457
|
...props,
|
|
1455
|
-
className: cn(theme.
|
|
1458
|
+
className: cn(theme.p)
|
|
1456
1459
|
}),
|
|
1457
1460
|
li: (props) => /* @__PURE__ */ jsx("li", {
|
|
1458
1461
|
...props,
|
|
1459
|
-
className: cn(theme.
|
|
1462
|
+
className: cn(theme.li)
|
|
1460
1463
|
}),
|
|
1461
1464
|
ul: (props) => /* @__PURE__ */ jsx("ul", {
|
|
1462
1465
|
...props,
|
|
1463
|
-
className: cn(theme.
|
|
1466
|
+
className: cn(theme.ul)
|
|
1464
1467
|
}),
|
|
1465
1468
|
ol: (props) => /* @__PURE__ */ jsx("ol", {
|
|
1466
1469
|
...props,
|
|
1467
|
-
className: cn(theme.
|
|
1470
|
+
className: cn(theme.ol)
|
|
1468
1471
|
}),
|
|
1469
1472
|
h1: (props) => /* @__PURE__ */ jsx("h1", {
|
|
1470
1473
|
...props,
|
|
1471
|
-
className: cn(theme.
|
|
1474
|
+
className: cn(theme.h1)
|
|
1472
1475
|
}),
|
|
1473
1476
|
h2: (props) => /* @__PURE__ */ jsx("h2", {
|
|
1474
1477
|
...props,
|
|
1475
|
-
className: cn(theme.
|
|
1478
|
+
className: cn(theme.h2)
|
|
1476
1479
|
}),
|
|
1477
1480
|
h3: (props) => /* @__PURE__ */ jsx("h3", {
|
|
1478
1481
|
...props,
|
|
1479
|
-
className: cn(theme.
|
|
1482
|
+
className: cn(theme.h3)
|
|
1480
1483
|
}),
|
|
1481
1484
|
h4: (props) => /* @__PURE__ */ jsx("h4", {
|
|
1482
1485
|
...props,
|
|
1483
|
-
className: cn(theme.
|
|
1486
|
+
className: cn(theme.h4)
|
|
1484
1487
|
}),
|
|
1485
1488
|
h5: (props) => /* @__PURE__ */ jsx("h5", {
|
|
1486
1489
|
...props,
|
|
1487
|
-
className: cn(theme.
|
|
1490
|
+
className: cn(theme.h5)
|
|
1488
1491
|
}),
|
|
1489
1492
|
h6: (props) => /* @__PURE__ */ jsx("h6", {
|
|
1490
1493
|
...props,
|
|
1491
|
-
className: cn(theme.
|
|
1494
|
+
className: cn(theme.h6)
|
|
1492
1495
|
}),
|
|
1493
1496
|
redact: ((props) => /* @__PURE__ */ jsx(Redact, {
|
|
1494
1497
|
value: props["data-redact-value"] || props.children,
|
|
1495
1498
|
allowToggle: true,
|
|
1496
1499
|
tooltipText: `${props["data-redact-name"] || "Sensitive"} information - Click to toggle`
|
|
1497
1500
|
})),
|
|
1498
|
-
...markdownComponents,
|
|
1499
1501
|
...customComponents
|
|
1500
1502
|
};
|
|
1501
|
-
}, [
|
|
1502
|
-
theme,
|
|
1503
|
-
markdownComponents,
|
|
1504
|
-
customComponents
|
|
1505
|
-
]),
|
|
1503
|
+
}, [theme, customComponents]),
|
|
1506
1504
|
children
|
|
1507
1505
|
});
|
|
1508
1506
|
};
|
|
@@ -2032,7 +2030,7 @@ MessageFiles.displayName = "MessageFiles";
|
|
|
2032
2030
|
//#endregion
|
|
2033
2031
|
//#region src/SessionMessages/SessionMessage/MessageQuestion.tsx
|
|
2034
2032
|
var MessageQuestion = memo(({ children, ...props }) => {
|
|
2035
|
-
const { theme, remarkPlugins } = useContext(ChatContext);
|
|
2033
|
+
const { theme, remarkPlugins, markdownComponents } = useContext(ChatContext);
|
|
2036
2034
|
const { question, files } = props;
|
|
2037
2035
|
const Comp = children ? Slot : "div";
|
|
2038
2036
|
const [expanded, setExpanded] = useState(false);
|
|
@@ -2044,7 +2042,8 @@ var MessageQuestion = memo(({ children, ...props }) => {
|
|
|
2044
2042
|
/* @__PURE__ */ jsx(MessageFiles, { files }),
|
|
2045
2043
|
/* @__PURE__ */ jsx(Markdown, {
|
|
2046
2044
|
remarkPlugins,
|
|
2047
|
-
theme,
|
|
2045
|
+
theme: theme.messages.message.markdown,
|
|
2046
|
+
customComponents: markdownComponents,
|
|
2048
2047
|
children: question
|
|
2049
2048
|
}),
|
|
2050
2049
|
isLong && !expanded && /* @__PURE__ */ jsx(Button, {
|
|
@@ -2061,13 +2060,14 @@ MessageQuestion.displayName = "MessageQuestion";
|
|
|
2061
2060
|
//#endregion
|
|
2062
2061
|
//#region src/SessionMessages/SessionMessage/MessageResponse.tsx
|
|
2063
2062
|
var MessageResponse = memo(({ response, isLoading, children }) => {
|
|
2064
|
-
const { theme, isCompact, remarkPlugins } = useContext(ChatContext);
|
|
2063
|
+
const { theme, isCompact, remarkPlugins, markdownComponents } = useContext(ChatContext);
|
|
2065
2064
|
return /* @__PURE__ */ jsx(children ? Slot : "div", {
|
|
2066
2065
|
"data-compact": isCompact,
|
|
2067
2066
|
className: cn(theme.messages.message.response),
|
|
2068
2067
|
children: children || /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Markdown, {
|
|
2069
2068
|
remarkPlugins,
|
|
2070
|
-
theme,
|
|
2069
|
+
theme: theme.messages.message.markdown,
|
|
2070
|
+
customComponents: markdownComponents,
|
|
2071
2071
|
children: response
|
|
2072
2072
|
}), isLoading && /* @__PURE__ */ jsx(motion.div, {
|
|
2073
2073
|
className: cn(theme.messages.message.cursor),
|
|
@@ -2425,12 +2425,7 @@ var useDimensions = () => {
|
|
|
2425
2425
|
};
|
|
2426
2426
|
//#endregion
|
|
2427
2427
|
//#region src/Chat.tsx
|
|
2428
|
-
var
|
|
2429
|
-
remarkGfm,
|
|
2430
|
-
remarkYoutube,
|
|
2431
|
-
remarkMath
|
|
2432
|
-
];
|
|
2433
|
-
var Chat = ({ children, viewType = "console", sessions, onSelectSession, onDeleteSession, onSendMessage, onStopMessage, onFileUpload, isLoading, activeSessionId, theme: customTheme = chatTheme, onNewSession, remarkPlugins = defaultRemarkPlugins, markdownComponents, components: componentCatalog, disabled, style, className }) => {
|
|
2428
|
+
var Chat = ({ children, viewType = "console", sessions, onSelectSession, onDeleteSession, onSendMessage, onStopMessage, onFileUpload, isLoading, activeSessionId, theme: customTheme = chatTheme, onNewSession, remarkPlugins, markdownComponents, components: componentCatalog, disabled, style, className }) => {
|
|
2434
2429
|
const theme = useComponentTheme("chat", customTheme);
|
|
2435
2430
|
const [internalActiveSessionID, setInternalActiveSessionID] = useState(activeSessionId);
|
|
2436
2431
|
const { width, observe } = useDimensions();
|
|
@@ -2462,7 +2457,8 @@ var Chat = ({ children, viewType = "console", sessions, onSelectSession, onDelet
|
|
|
2462
2457
|
const activeSession = useMemo(() => sessions.find((session) => session.id === internalActiveSessionID), [sessions, internalActiveSessionID]);
|
|
2463
2458
|
const mergedRemarkPlugins = useMemo(() => {
|
|
2464
2459
|
if (!componentCatalog) return remarkPlugins;
|
|
2465
|
-
|
|
2460
|
+
if (!remarkPlugins) return;
|
|
2461
|
+
return [...remarkPlugins ?? [], componentCatalog.remarkPlugin];
|
|
2466
2462
|
}, [remarkPlugins, componentCatalog]);
|
|
2467
2463
|
const mergedMarkdownComponents = useMemo(() => {
|
|
2468
2464
|
if (!componentCatalog) return markdownComponents;
|