@copilotkit/react-ui 1.51.3-next.5 → 1.51.3-next.7
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/CHANGELOG.md +17 -0
- package/dist/{chunk-O4PPO3K3.mjs → chunk-7CMZ7YPQ.mjs} +2 -2
- package/dist/{chunk-PKSW6ZMQ.mjs → chunk-F2CDEOFX.mjs} +2 -2
- package/dist/{chunk-XOBQLKUU.mjs → chunk-JZ3RFQQ6.mjs} +13 -3
- package/dist/chunk-JZ3RFQQ6.mjs.map +1 -0
- package/dist/{chunk-XEZ5ODJS.mjs → chunk-LBR23XXF.mjs} +2 -2
- package/dist/{chunk-SLM2AOHF.mjs → chunk-LYYDXL2G.mjs} +9 -5
- package/dist/chunk-LYYDXL2G.mjs.map +1 -0
- package/dist/{chunk-HKZL4P3F.mjs → chunk-OHGUQZJT.mjs} +4 -4
- package/dist/{chunk-YQOESY4Y.mjs → chunk-PD36EMOZ.mjs} +4 -4
- package/dist/{chunk-4S4ZEKE6.mjs → chunk-RKQM2AE5.mjs} +2 -2
- package/dist/{chunk-UH5GQ7QF.mjs → chunk-WNX755OE.mjs} +2 -2
- package/dist/components/chat/Chat.js +74 -60
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +6 -6
- package/dist/components/chat/Markdown.d.ts +2 -4
- package/dist/components/chat/Markdown.js +12 -2
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +1 -1
- package/dist/components/chat/Messages.js +34 -20
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +5 -5
- package/dist/components/chat/Modal.js +81 -67
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +7 -7
- package/dist/components/chat/Popup.js +81 -67
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +8 -8
- package/dist/components/chat/Sidebar.js +83 -69
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +8 -8
- package/dist/components/chat/index.d.ts +1 -1
- package/dist/components/chat/index.js +83 -69
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +9 -9
- package/dist/components/chat/messages/AssistantMessage.js +21 -7
- package/dist/components/chat/messages/AssistantMessage.js.map +1 -1
- package/dist/components/chat/messages/AssistantMessage.mjs +2 -2
- package/dist/components/chat/messages/ErrorMessage.js +14 -4
- package/dist/components/chat/messages/ErrorMessage.js.map +1 -1
- package/dist/components/chat/messages/ErrorMessage.mjs +1 -1
- package/dist/components/chat/messages/LegacyRenderMessage.js +23 -9
- package/dist/components/chat/messages/LegacyRenderMessage.js.map +1 -1
- package/dist/components/chat/messages/LegacyRenderMessage.mjs +4 -4
- package/dist/components/chat/messages/RenderMessage.js +23 -9
- package/dist/components/chat/messages/RenderMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderMessage.mjs +3 -3
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +83 -69
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +83 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -9
- package/package.json +8 -5
- package/src/components/chat/Markdown.tsx +17 -8
- package/src/components/chat/messages/AssistantMessage.tsx +6 -2
- package/dist/chunk-SLM2AOHF.mjs.map +0 -1
- package/dist/chunk-XOBQLKUU.mjs.map +0 -1
- /package/dist/{chunk-O4PPO3K3.mjs.map → chunk-7CMZ7YPQ.mjs.map} +0 -0
- /package/dist/{chunk-PKSW6ZMQ.mjs.map → chunk-F2CDEOFX.mjs.map} +0 -0
- /package/dist/{chunk-XEZ5ODJS.mjs.map → chunk-LBR23XXF.mjs.map} +0 -0
- /package/dist/{chunk-HKZL4P3F.mjs.map → chunk-OHGUQZJT.mjs.map} +0 -0
- /package/dist/{chunk-YQOESY4Y.mjs.map → chunk-PD36EMOZ.mjs.map} +0 -0
- /package/dist/{chunk-4S4ZEKE6.mjs.map → chunk-RKQM2AE5.mjs.map} +0 -0
- /package/dist/{chunk-UH5GQ7QF.mjs.map → chunk-WNX755OE.mjs.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotSidebar
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-RKQM2AE5.mjs";
|
|
4
|
+
import "../../chunk-OHGUQZJT.mjs";
|
|
5
5
|
import "../../chunk-C3GSYRC3.mjs";
|
|
6
6
|
import "../../chunk-GDSZGYCE.mjs";
|
|
7
7
|
import "../../chunk-V7W6IM2V.mjs";
|
|
@@ -12,20 +12,20 @@ import "../../chunk-KXE2JCUH.mjs";
|
|
|
12
12
|
import "../../chunk-NRA3CFEE.mjs";
|
|
13
13
|
import "../../chunk-BH6PCAAL.mjs";
|
|
14
14
|
import "../../chunk-UFN2VWSR.mjs";
|
|
15
|
-
import "../../chunk-
|
|
15
|
+
import "../../chunk-PD36EMOZ.mjs";
|
|
16
16
|
import "../../chunk-VHKHX7GV.mjs";
|
|
17
17
|
import "../../chunk-6TWQUA2Q.mjs";
|
|
18
18
|
import "../../chunk-PLHTVHUW.mjs";
|
|
19
19
|
import "../../chunk-3W6J75HS.mjs";
|
|
20
20
|
import "../../chunk-ELGRNEAO.mjs";
|
|
21
21
|
import "../../chunk-QIOJXTIQ.mjs";
|
|
22
|
-
import "../../chunk-
|
|
23
|
-
import "../../chunk-
|
|
24
|
-
import "../../chunk-
|
|
25
|
-
import "../../chunk-
|
|
22
|
+
import "../../chunk-WNX755OE.mjs";
|
|
23
|
+
import "../../chunk-F2CDEOFX.mjs";
|
|
24
|
+
import "../../chunk-LBR23XXF.mjs";
|
|
25
|
+
import "../../chunk-LYYDXL2G.mjs";
|
|
26
26
|
import "../../chunk-DBKRAOH7.mjs";
|
|
27
27
|
import "../../chunk-RYUCX3ZK.mjs";
|
|
28
|
-
import "../../chunk-
|
|
28
|
+
import "../../chunk-JZ3RFQQ6.mjs";
|
|
29
29
|
import "../../chunk-IK2BPURM.mjs";
|
|
30
30
|
import "../../chunk-IEMQ2SQW.mjs";
|
|
31
31
|
import "../../chunk-XWG3L6QC.mjs";
|
|
@@ -93,7 +93,7 @@ __export(chat_exports, {
|
|
|
93
93
|
module.exports = __toCommonJS(chat_exports);
|
|
94
94
|
|
|
95
95
|
// src/components/chat/Modal.tsx
|
|
96
|
-
var
|
|
96
|
+
var import_react16 = __toESM(require("react"));
|
|
97
97
|
|
|
98
98
|
// src/components/chat/ChatContext.tsx
|
|
99
99
|
var import_react = __toESM(require("react"));
|
|
@@ -1034,7 +1034,7 @@ var Header = ({}) => {
|
|
|
1034
1034
|
};
|
|
1035
1035
|
|
|
1036
1036
|
// src/components/chat/Messages.tsx
|
|
1037
|
-
var
|
|
1037
|
+
var import_react10 = require("react");
|
|
1038
1038
|
var import_react_core5 = require("@copilotkit/react-core");
|
|
1039
1039
|
|
|
1040
1040
|
// src/components/chat/messages/UserMessage.tsx
|
|
@@ -1066,7 +1066,8 @@ var UserMessage = (props) => {
|
|
|
1066
1066
|
};
|
|
1067
1067
|
|
|
1068
1068
|
// src/components/chat/Markdown.tsx
|
|
1069
|
-
var
|
|
1069
|
+
var import_react7 = require("react");
|
|
1070
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1070
1071
|
|
|
1071
1072
|
// src/components/chat/CodeBlock.tsx
|
|
1072
1073
|
var import_react6 = require("react");
|
|
@@ -1478,6 +1479,9 @@ var highlightStyle = {
|
|
|
1478
1479
|
};
|
|
1479
1480
|
|
|
1480
1481
|
// src/components/chat/Markdown.tsx
|
|
1482
|
+
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
1483
|
+
var import_remark_math = __toESM(require("remark-math"));
|
|
1484
|
+
var import_rehype_raw = __toESM(require("rehype-raw"));
|
|
1481
1485
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1482
1486
|
var defaultComponents = {
|
|
1483
1487
|
a(_a) {
|
|
@@ -1571,21 +1575,27 @@ var defaultComponents = {
|
|
|
1571
1575
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
|
|
1572
1576
|
}
|
|
1573
1577
|
};
|
|
1578
|
+
var MemoizedReactMarkdown = (0, import_react7.memo)(
|
|
1579
|
+
import_react_markdown.default,
|
|
1580
|
+
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
|
|
1581
|
+
);
|
|
1574
1582
|
var Markdown = ({ content, components }) => {
|
|
1575
1583
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1576
|
-
|
|
1584
|
+
MemoizedReactMarkdown,
|
|
1577
1585
|
{
|
|
1578
1586
|
components: __spreadValues(__spreadValues({}, defaultComponents), components),
|
|
1587
|
+
remarkPlugins: [import_remark_gfm.default, [import_remark_math.default, { singleDollarTextMath: false }]],
|
|
1588
|
+
rehypePlugins: [import_rehype_raw.default],
|
|
1579
1589
|
children: content
|
|
1580
1590
|
}
|
|
1581
1591
|
) });
|
|
1582
1592
|
};
|
|
1583
1593
|
|
|
1584
1594
|
// src/components/chat/messages/AssistantMessage.tsx
|
|
1585
|
-
var
|
|
1595
|
+
var import_react8 = require("react");
|
|
1586
1596
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1587
1597
|
var AssistantMessage = (props) => {
|
|
1588
|
-
var _a;
|
|
1598
|
+
var _a, _b, _c;
|
|
1589
1599
|
const { icons, labels } = useChatContext();
|
|
1590
1600
|
const {
|
|
1591
1601
|
message,
|
|
@@ -1598,7 +1608,7 @@ var AssistantMessage = (props) => {
|
|
|
1598
1608
|
feedback,
|
|
1599
1609
|
markdownTagRenderers
|
|
1600
1610
|
} = props;
|
|
1601
|
-
const [copied, setCopied] = (0,
|
|
1611
|
+
const [copied, setCopied] = (0, import_react8.useState)(false);
|
|
1602
1612
|
const handleCopy = () => {
|
|
1603
1613
|
const content2 = (message == null ? void 0 : message.content) || "";
|
|
1604
1614
|
if (content2 && onCopy) {
|
|
@@ -1628,8 +1638,12 @@ var AssistantMessage = (props) => {
|
|
|
1628
1638
|
};
|
|
1629
1639
|
const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: icons.activityIcon });
|
|
1630
1640
|
const content = (message == null ? void 0 : message.content) || "";
|
|
1631
|
-
const subComponent = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message);
|
|
1641
|
+
const subComponent = (_b = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message)) != null ? _b : props.subComponent;
|
|
1642
|
+
const subComponentPosition = (_c = message == null ? void 0 : message.generativeUIPosition) != null ? _c : "after";
|
|
1643
|
+
const renderBefore = subComponent && subComponentPosition === "before";
|
|
1644
|
+
const renderAfter = subComponent && subComponentPosition !== "before";
|
|
1632
1645
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
1646
|
+
renderBefore ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }) : null,
|
|
1633
1647
|
content && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
|
|
1634
1648
|
content && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Markdown, { content, components: markdownTagRenderers }),
|
|
1635
1649
|
content && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
@@ -1681,16 +1695,16 @@ var AssistantMessage = (props) => {
|
|
|
1681
1695
|
}
|
|
1682
1696
|
)
|
|
1683
1697
|
] }),
|
|
1684
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }),
|
|
1698
|
+
renderAfter ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }) : null,
|
|
1685
1699
|
isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(LoadingIcon, {})
|
|
1686
1700
|
] });
|
|
1687
1701
|
};
|
|
1688
1702
|
|
|
1689
1703
|
// src/components/chat/messages/ImageRenderer.tsx
|
|
1690
|
-
var
|
|
1704
|
+
var import_react9 = require("react");
|
|
1691
1705
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1692
1706
|
var ImageRenderer = ({ image, content, className = "" }) => {
|
|
1693
|
-
const [imageError, setImageError] = (0,
|
|
1707
|
+
const [imageError, setImageError] = (0, import_react9.useState)(false);
|
|
1694
1708
|
const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
|
|
1695
1709
|
const altText = content || "User uploaded image";
|
|
1696
1710
|
const handleImageError = () => {
|
|
@@ -1933,18 +1947,18 @@ var Messages = ({
|
|
|
1933
1947
|
var _a;
|
|
1934
1948
|
const { labels, icons } = useChatContext();
|
|
1935
1949
|
const { messages: visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
|
|
1936
|
-
const initialMessages = (0,
|
|
1950
|
+
const initialMessages = (0, import_react10.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
|
|
1937
1951
|
const messages = [...initialMessages, ...visibleMessages];
|
|
1938
1952
|
const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
|
|
1939
1953
|
const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
|
|
1940
|
-
(0,
|
|
1954
|
+
(0, import_react10.useEffect)(() => {
|
|
1941
1955
|
if (hasLegacyProps) {
|
|
1942
1956
|
console.warn(
|
|
1943
1957
|
"[CopilotKit] Legacy message render props (RenderTextMessage, RenderActionExecutionMessage, etc.) are deprecated. Please use the unified 'RenderMessage' prop instead. See migration guide: https://docs.copilotkit.ai/migration/render-message"
|
|
1944
1958
|
);
|
|
1945
1959
|
}
|
|
1946
1960
|
}, [hasLegacyProps]);
|
|
1947
|
-
const legacyProps = (0,
|
|
1961
|
+
const legacyProps = (0, import_react10.useMemo)(
|
|
1948
1962
|
() => ({
|
|
1949
1963
|
RenderTextMessage,
|
|
1950
1964
|
RenderActionExecutionMessage,
|
|
@@ -2015,10 +2029,10 @@ function makeInitialMessages(initial) {
|
|
|
2015
2029
|
];
|
|
2016
2030
|
}
|
|
2017
2031
|
function useScrollToBottom(messages) {
|
|
2018
|
-
const messagesEndRef = (0,
|
|
2019
|
-
const messagesContainerRef = (0,
|
|
2020
|
-
const isProgrammaticScrollRef = (0,
|
|
2021
|
-
const isUserScrollUpRef = (0,
|
|
2032
|
+
const messagesEndRef = (0, import_react10.useRef)(null);
|
|
2033
|
+
const messagesContainerRef = (0, import_react10.useRef)(null);
|
|
2034
|
+
const isProgrammaticScrollRef = (0, import_react10.useRef)(false);
|
|
2035
|
+
const isUserScrollUpRef = (0, import_react10.useRef)(false);
|
|
2022
2036
|
const scrollToBottom = () => {
|
|
2023
2037
|
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
2024
2038
|
isProgrammaticScrollRef.current = true;
|
|
@@ -2035,7 +2049,7 @@ function useScrollToBottom(messages) {
|
|
|
2035
2049
|
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
2036
2050
|
}
|
|
2037
2051
|
};
|
|
2038
|
-
(0,
|
|
2052
|
+
(0, import_react10.useEffect)(() => {
|
|
2039
2053
|
const container = messagesContainerRef.current;
|
|
2040
2054
|
if (container) {
|
|
2041
2055
|
container.addEventListener("scroll", handleScroll);
|
|
@@ -2046,7 +2060,7 @@ function useScrollToBottom(messages) {
|
|
|
2046
2060
|
}
|
|
2047
2061
|
};
|
|
2048
2062
|
}, []);
|
|
2049
|
-
(0,
|
|
2063
|
+
(0, import_react10.useEffect)(() => {
|
|
2050
2064
|
const container = messagesContainerRef.current;
|
|
2051
2065
|
if (!container) {
|
|
2052
2066
|
return;
|
|
@@ -2065,7 +2079,7 @@ function useScrollToBottom(messages) {
|
|
|
2065
2079
|
mutationObserver.disconnect();
|
|
2066
2080
|
};
|
|
2067
2081
|
}, []);
|
|
2068
|
-
(0,
|
|
2082
|
+
(0, import_react10.useEffect)(() => {
|
|
2069
2083
|
isUserScrollUpRef.current = false;
|
|
2070
2084
|
scrollToBottom();
|
|
2071
2085
|
}, [messages.filter((m) => m.role === "user").length]);
|
|
@@ -2073,12 +2087,12 @@ function useScrollToBottom(messages) {
|
|
|
2073
2087
|
}
|
|
2074
2088
|
|
|
2075
2089
|
// src/components/chat/Input.tsx
|
|
2076
|
-
var
|
|
2090
|
+
var import_react14 = require("react");
|
|
2077
2091
|
|
|
2078
2092
|
// src/components/chat/Textarea.tsx
|
|
2079
|
-
var
|
|
2093
|
+
var import_react11 = require("react");
|
|
2080
2094
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2081
|
-
var AutoResizingTextarea = (0,
|
|
2095
|
+
var AutoResizingTextarea = (0, import_react11.forwardRef)(
|
|
2082
2096
|
({
|
|
2083
2097
|
maxRows = 1,
|
|
2084
2098
|
placeholder,
|
|
@@ -2089,10 +2103,10 @@ var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
|
2089
2103
|
onCompositionEnd,
|
|
2090
2104
|
autoFocus
|
|
2091
2105
|
}, ref) => {
|
|
2092
|
-
const internalTextareaRef = (0,
|
|
2093
|
-
const [maxHeight, setMaxHeight] = (0,
|
|
2094
|
-
(0,
|
|
2095
|
-
(0,
|
|
2106
|
+
const internalTextareaRef = (0, import_react11.useRef)(null);
|
|
2107
|
+
const [maxHeight, setMaxHeight] = (0, import_react11.useState)(0);
|
|
2108
|
+
(0, import_react11.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
2109
|
+
(0, import_react11.useEffect)(() => {
|
|
2096
2110
|
const calculateMaxHeight = () => {
|
|
2097
2111
|
const textarea = internalTextareaRef.current;
|
|
2098
2112
|
if (textarea) {
|
|
@@ -2106,7 +2120,7 @@ var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
|
2106
2120
|
};
|
|
2107
2121
|
calculateMaxHeight();
|
|
2108
2122
|
}, [maxRows]);
|
|
2109
|
-
(0,
|
|
2123
|
+
(0, import_react11.useEffect)(() => {
|
|
2110
2124
|
const textarea = internalTextareaRef.current;
|
|
2111
2125
|
if (textarea) {
|
|
2112
2126
|
textarea.style.height = "auto";
|
|
@@ -2138,7 +2152,7 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
2138
2152
|
// src/hooks/use-push-to-talk.tsx
|
|
2139
2153
|
var import_react_core6 = require("@copilotkit/react-core");
|
|
2140
2154
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
2141
|
-
var
|
|
2155
|
+
var import_react12 = require("react");
|
|
2142
2156
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
2143
2157
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
2144
2158
|
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
@@ -2187,16 +2201,16 @@ var usePushToTalk = ({
|
|
|
2187
2201
|
sendFunction,
|
|
2188
2202
|
inProgress
|
|
2189
2203
|
}) => {
|
|
2190
|
-
const [pushToTalkState, setPushToTalkState] = (0,
|
|
2191
|
-
const mediaStreamRef = (0,
|
|
2192
|
-
const audioContextRef = (0,
|
|
2193
|
-
const mediaRecorderRef = (0,
|
|
2194
|
-
const recordedChunks = (0,
|
|
2204
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react12.useState)("idle");
|
|
2205
|
+
const mediaStreamRef = (0, import_react12.useRef)(null);
|
|
2206
|
+
const audioContextRef = (0, import_react12.useRef)(null);
|
|
2207
|
+
const mediaRecorderRef = (0, import_react12.useRef)(null);
|
|
2208
|
+
const recordedChunks = (0, import_react12.useRef)([]);
|
|
2195
2209
|
const generalContext = (0, import_react_core6.useCopilotContext)();
|
|
2196
2210
|
const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
|
|
2197
2211
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2198
|
-
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0,
|
|
2199
|
-
(0,
|
|
2212
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react12.useState)(null);
|
|
2213
|
+
(0, import_react12.useEffect)(() => {
|
|
2200
2214
|
if (pushToTalkState === "recording") {
|
|
2201
2215
|
startRecording(
|
|
2202
2216
|
mediaStreamRef,
|
|
@@ -2224,7 +2238,7 @@ var usePushToTalk = ({
|
|
|
2224
2238
|
stopRecording(mediaRecorderRef);
|
|
2225
2239
|
};
|
|
2226
2240
|
}, [pushToTalkState]);
|
|
2227
|
-
(0,
|
|
2241
|
+
(0, import_react12.useEffect)(() => {
|
|
2228
2242
|
if (inProgress === false && startReadingFromMessageId) {
|
|
2229
2243
|
const lastMessageIndex = context.messages.findIndex(
|
|
2230
2244
|
(message) => message.id === startReadingFromMessageId
|
|
@@ -2243,7 +2257,7 @@ var usePushToTalk = ({
|
|
|
2243
2257
|
var import_react_core7 = require("@copilotkit/react-core");
|
|
2244
2258
|
|
|
2245
2259
|
// src/components/chat/PoweredByTag.tsx
|
|
2246
|
-
var
|
|
2260
|
+
var import_react13 = require("react");
|
|
2247
2261
|
|
|
2248
2262
|
// src/hooks/use-dark-mode.ts
|
|
2249
2263
|
var useDarkMode = () => {
|
|
@@ -2255,9 +2269,9 @@ var useDarkMode = () => {
|
|
|
2255
2269
|
// src/components/chat/PoweredByTag.tsx
|
|
2256
2270
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2257
2271
|
function PoweredByTag({ showPoweredBy = true }) {
|
|
2258
|
-
const [mounted, setMounted] = (0,
|
|
2272
|
+
const [mounted, setMounted] = (0, import_react13.useState)(false);
|
|
2259
2273
|
const isDark = useDarkMode();
|
|
2260
|
-
(0,
|
|
2274
|
+
(0, import_react13.useEffect)(() => {
|
|
2261
2275
|
setMounted(true);
|
|
2262
2276
|
}, []);
|
|
2263
2277
|
if (!showPoweredBy) {
|
|
@@ -2291,8 +2305,8 @@ var Input = ({
|
|
|
2291
2305
|
const copilotContext = (0, import_react_core7.useCopilotContext)();
|
|
2292
2306
|
const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
|
|
2293
2307
|
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
2294
|
-
const textareaRef = (0,
|
|
2295
|
-
const [isComposing, setIsComposing] = (0,
|
|
2308
|
+
const textareaRef = (0, import_react14.useRef)(null);
|
|
2309
|
+
const [isComposing, setIsComposing] = (0, import_react14.useState)(false);
|
|
2296
2310
|
const handleDivClick = (event) => {
|
|
2297
2311
|
var _a2;
|
|
2298
2312
|
const target = event.target;
|
|
@@ -2302,7 +2316,7 @@ var Input = ({
|
|
|
2302
2316
|
return;
|
|
2303
2317
|
(_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
|
|
2304
2318
|
};
|
|
2305
|
-
const [text, setText] = (0,
|
|
2319
|
+
const [text, setText] = (0, import_react14.useState)("");
|
|
2306
2320
|
const send = () => {
|
|
2307
2321
|
var _a2;
|
|
2308
2322
|
if (inProgress)
|
|
@@ -2316,17 +2330,17 @@ var Input = ({
|
|
|
2316
2330
|
inProgress
|
|
2317
2331
|
});
|
|
2318
2332
|
const isInProgress = inProgress || pushToTalkState === "transcribing";
|
|
2319
|
-
const { buttonIcon, buttonAlt } = (0,
|
|
2333
|
+
const { buttonIcon, buttonAlt } = (0, import_react14.useMemo)(() => {
|
|
2320
2334
|
if (!chatReady)
|
|
2321
2335
|
return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
|
|
2322
2336
|
return isInProgress && !hideStopButton && chatReady ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
|
|
2323
2337
|
}, [isInProgress, chatReady, hideStopButton, context.icons.stopIcon, context.icons.sendIcon]);
|
|
2324
2338
|
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
2325
2339
|
const { interrupt } = (0, import_react_core7.useCopilotChatInternal)();
|
|
2326
|
-
const canSend = (0,
|
|
2340
|
+
const canSend = (0, import_react14.useMemo)(() => {
|
|
2327
2341
|
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
|
|
2328
2342
|
}, [interrupt, isInProgress, text, pushToTalkState]);
|
|
2329
|
-
const canStop = (0,
|
|
2343
|
+
const canStop = (0, import_react14.useMemo)(() => {
|
|
2330
2344
|
return isInProgress && !hideStopButton;
|
|
2331
2345
|
}, [isInProgress, hideStopButton]);
|
|
2332
2346
|
const sendDisabled = !canSend && !canStop;
|
|
@@ -2383,7 +2397,7 @@ var Input = ({
|
|
|
2383
2397
|
};
|
|
2384
2398
|
|
|
2385
2399
|
// src/components/chat/Chat.tsx
|
|
2386
|
-
var
|
|
2400
|
+
var import_react15 = __toESM(require("react"));
|
|
2387
2401
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2388
2402
|
var import_shared3 = require("@copilotkit/shared");
|
|
2389
2403
|
|
|
@@ -2560,13 +2574,13 @@ function CopilotChat({
|
|
|
2560
2574
|
removeInternalErrorHandler
|
|
2561
2575
|
} = (0, import_react_core9.useCopilotContext)();
|
|
2562
2576
|
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
2563
|
-
const [selectedImages, setSelectedImages] = (0,
|
|
2564
|
-
const [chatError, setChatError] = (0,
|
|
2565
|
-
const [messageFeedback, setMessageFeedback] = (0,
|
|
2577
|
+
const [selectedImages, setSelectedImages] = (0, import_react15.useState)([]);
|
|
2578
|
+
const [chatError, setChatError] = (0, import_react15.useState)(null);
|
|
2579
|
+
const [messageFeedback, setMessageFeedback] = (0, import_react15.useState)(
|
|
2566
2580
|
{}
|
|
2567
2581
|
);
|
|
2568
|
-
const fileInputRef = (0,
|
|
2569
|
-
const triggerObservabilityHook = (0,
|
|
2582
|
+
const fileInputRef = (0, import_react15.useRef)(null);
|
|
2583
|
+
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2570
2584
|
(hookName, ...args) => {
|
|
2571
2585
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2572
2586
|
observabilityHooks[hookName](...args);
|
|
@@ -2585,7 +2599,7 @@ function CopilotChat({
|
|
|
2585
2599
|
},
|
|
2586
2600
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2587
2601
|
);
|
|
2588
|
-
const triggerChatError = (0,
|
|
2602
|
+
const triggerChatError = (0, import_react15.useCallback)(
|
|
2589
2603
|
(error, operation, originalError) => {
|
|
2590
2604
|
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
|
|
2591
2605
|
setChatError({
|
|
@@ -2631,7 +2645,7 @@ function CopilotChat({
|
|
|
2631
2645
|
},
|
|
2632
2646
|
[publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
|
|
2633
2647
|
);
|
|
2634
|
-
(0,
|
|
2648
|
+
(0, import_react15.useEffect)(() => {
|
|
2635
2649
|
const id = "chat-component";
|
|
2636
2650
|
setInternalErrorHandler({
|
|
2637
2651
|
[id]: (error) => {
|
|
@@ -2644,7 +2658,7 @@ function CopilotChat({
|
|
|
2644
2658
|
removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
|
|
2645
2659
|
};
|
|
2646
2660
|
}, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
|
|
2647
|
-
(0,
|
|
2661
|
+
(0, import_react15.useEffect)(() => {
|
|
2648
2662
|
if (!imageUploadsEnabled)
|
|
2649
2663
|
return;
|
|
2650
2664
|
const handlePaste = (e) => __async(this, null, function* () {
|
|
@@ -2690,7 +2704,7 @@ function CopilotChat({
|
|
|
2690
2704
|
document.addEventListener("paste", handlePaste);
|
|
2691
2705
|
return () => document.removeEventListener("paste", handlePaste);
|
|
2692
2706
|
}, [imageUploadsEnabled, triggerChatError]);
|
|
2693
|
-
(0,
|
|
2707
|
+
(0, import_react15.useEffect)(() => {
|
|
2694
2708
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
2695
2709
|
setChatInstructions(instructions || "");
|
|
2696
2710
|
return;
|
|
@@ -2718,8 +2732,8 @@ function CopilotChat({
|
|
|
2718
2732
|
onStopGeneration,
|
|
2719
2733
|
onReloadMessages
|
|
2720
2734
|
});
|
|
2721
|
-
const prevIsLoading = (0,
|
|
2722
|
-
(0,
|
|
2735
|
+
const prevIsLoading = (0, import_react15.useRef)(isLoading);
|
|
2736
|
+
(0, import_react15.useEffect)(() => {
|
|
2723
2737
|
if (prevIsLoading.current !== isLoading) {
|
|
2724
2738
|
if (isLoading) {
|
|
2725
2739
|
triggerObservabilityHook("onChatStarted");
|
|
@@ -2742,7 +2756,7 @@ function CopilotChat({
|
|
|
2742
2756
|
role: "user"
|
|
2743
2757
|
});
|
|
2744
2758
|
};
|
|
2745
|
-
const chatContext =
|
|
2759
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2746
2760
|
const isVisible = chatContext ? chatContext.open : true;
|
|
2747
2761
|
const handleRegenerate = (messageId) => {
|
|
2748
2762
|
if (onRegenerate) {
|
|
@@ -2886,7 +2900,7 @@ function WrappedCopilotChat({
|
|
|
2886
2900
|
labels,
|
|
2887
2901
|
className
|
|
2888
2902
|
}) {
|
|
2889
|
-
const chatContext =
|
|
2903
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2890
2904
|
if (!chatContext) {
|
|
2891
2905
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
2892
2906
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
|
|
@@ -2924,7 +2938,7 @@ var CopilotModalInner = (_a) => {
|
|
|
2924
2938
|
]);
|
|
2925
2939
|
const { copilotApiConfig, setBannerError } = (0, import_react_core10.useCopilotContext)();
|
|
2926
2940
|
const { publicApiKey } = copilotApiConfig;
|
|
2927
|
-
const triggerObservabilityHook = (0,
|
|
2941
|
+
const triggerObservabilityHook = (0, import_react16.useCallback)(
|
|
2928
2942
|
(hookName, ...args) => {
|
|
2929
2943
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2930
2944
|
observabilityHooks[hookName](...args);
|
|
@@ -2944,8 +2958,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2944
2958
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2945
2959
|
);
|
|
2946
2960
|
const { open } = useChatContext();
|
|
2947
|
-
const prevOpen = (0,
|
|
2948
|
-
(0,
|
|
2961
|
+
const prevOpen = (0, import_react16.useRef)(open);
|
|
2962
|
+
(0, import_react16.useEffect)(() => {
|
|
2949
2963
|
if (prevOpen.current !== open) {
|
|
2950
2964
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2951
2965
|
if (open) {
|
|
@@ -2956,8 +2970,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2956
2970
|
prevOpen.current = open;
|
|
2957
2971
|
}
|
|
2958
2972
|
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
2959
|
-
const memoizedHeader = (0,
|
|
2960
|
-
const memoizedChildren = (0,
|
|
2973
|
+
const memoizedHeader = (0, import_react16.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}), [Header2]);
|
|
2974
|
+
const memoizedChildren = (0, import_react16.useMemo)(() => children, [children]);
|
|
2961
2975
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
2962
2976
|
memoizedChildren,
|
|
2963
2977
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className, children: [
|
|
@@ -3037,7 +3051,7 @@ var CopilotModal = (_a) => {
|
|
|
3037
3051
|
"children",
|
|
3038
3052
|
"observabilityHooks"
|
|
3039
3053
|
]);
|
|
3040
|
-
const [openState, setOpenState] =
|
|
3054
|
+
const [openState, setOpenState] = import_react16.default.useState(defaultOpen);
|
|
3041
3055
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3042
3056
|
CopilotModalInner,
|
|
3043
3057
|
__spreadProps(__spreadValues({
|
|
@@ -3081,13 +3095,13 @@ function CopilotPopup(props) {
|
|
|
3081
3095
|
}
|
|
3082
3096
|
|
|
3083
3097
|
// src/components/chat/Sidebar.tsx
|
|
3084
|
-
var
|
|
3098
|
+
var import_react17 = require("react");
|
|
3085
3099
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
3086
3100
|
function CopilotSidebar(props) {
|
|
3087
3101
|
props = __spreadProps(__spreadValues({}, props), {
|
|
3088
3102
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
3089
3103
|
});
|
|
3090
|
-
const [expandedClassName, setExpandedClassName] = (0,
|
|
3104
|
+
const [expandedClassName, setExpandedClassName] = (0, import_react17.useState)(
|
|
3091
3105
|
props.defaultOpen ? "sidebarExpanded" : ""
|
|
3092
3106
|
);
|
|
3093
3107
|
const onSetOpen = (open) => {
|