@copilotkit/react-ui 1.51.2 → 1.51.3-next.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/CHANGELOG.md +16 -0
- package/dist/{chunk-DI7DDMRS.mjs → chunk-4S4ZEKE6.mjs} +2 -2
- package/dist/{chunk-BVKKSSB2.mjs → chunk-HKZL4P3F.mjs} +4 -4
- package/dist/{chunk-VVCCMYGT.mjs → chunk-O4PPO3K3.mjs} +2 -2
- package/dist/{chunk-7OURDQZJ.mjs → chunk-PKSW6ZMQ.mjs} +2 -2
- package/dist/{chunk-IHFR6PYG.mjs → chunk-SLM2AOHF.mjs} +2 -2
- package/dist/{chunk-HIW7RXCD.mjs → chunk-UH5GQ7QF.mjs} +2 -2
- package/dist/{chunk-NCIAFFQ2.mjs → chunk-XEZ5ODJS.mjs} +2 -2
- package/dist/{chunk-JZ3RFQQ6.mjs → chunk-XOBQLKUU.mjs} +3 -13
- package/dist/chunk-XOBQLKUU.mjs.map +1 -0
- package/dist/{chunk-NSJWSIPR.mjs → chunk-YQOESY4Y.mjs} +4 -4
- package/dist/components/chat/Chat.js +57 -67
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +6 -6
- package/dist/components/chat/Markdown.d.ts +4 -2
- package/dist/components/chat/Markdown.js +2 -12
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +1 -1
- package/dist/components/chat/Messages.js +17 -27
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +5 -5
- package/dist/components/chat/Modal.js +64 -74
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +7 -7
- package/dist/components/chat/Popup.js +64 -74
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +8 -8
- package/dist/components/chat/Sidebar.js +66 -76
- 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 +66 -76
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +9 -9
- package/dist/components/chat/messages/AssistantMessage.js +4 -14
- 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 +4 -14
- 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 +6 -16
- 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 +6 -16
- 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 +66 -76
- 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 +66 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -9
- package/package.json +5 -8
- package/src/components/chat/Markdown.tsx +8 -17
- package/dist/chunk-JZ3RFQQ6.mjs.map +0 -1
- /package/dist/{chunk-DI7DDMRS.mjs.map → chunk-4S4ZEKE6.mjs.map} +0 -0
- /package/dist/{chunk-BVKKSSB2.mjs.map → chunk-HKZL4P3F.mjs.map} +0 -0
- /package/dist/{chunk-VVCCMYGT.mjs.map → chunk-O4PPO3K3.mjs.map} +0 -0
- /package/dist/{chunk-7OURDQZJ.mjs.map → chunk-PKSW6ZMQ.mjs.map} +0 -0
- /package/dist/{chunk-IHFR6PYG.mjs.map → chunk-SLM2AOHF.mjs.map} +0 -0
- /package/dist/{chunk-HIW7RXCD.mjs.map → chunk-UH5GQ7QF.mjs.map} +0 -0
- /package/dist/{chunk-NCIAFFQ2.mjs.map → chunk-XEZ5ODJS.mjs.map} +0 -0
- /package/dist/{chunk-NSJWSIPR.mjs.map → chunk-YQOESY4Y.mjs.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotPopup
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-O4PPO3K3.mjs";
|
|
4
|
+
import "../../chunk-HKZL4P3F.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-YQOESY4Y.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-UH5GQ7QF.mjs";
|
|
23
|
+
import "../../chunk-PKSW6ZMQ.mjs";
|
|
24
|
+
import "../../chunk-XEZ5ODJS.mjs";
|
|
25
|
+
import "../../chunk-SLM2AOHF.mjs";
|
|
26
26
|
import "../../chunk-DBKRAOH7.mjs";
|
|
27
27
|
import "../../chunk-RYUCX3ZK.mjs";
|
|
28
|
-
import "../../chunk-
|
|
28
|
+
import "../../chunk-XOBQLKUU.mjs";
|
|
29
29
|
import "../../chunk-IK2BPURM.mjs";
|
|
30
30
|
import "../../chunk-IEMQ2SQW.mjs";
|
|
31
31
|
import "../../chunk-XWG3L6QC.mjs";
|
|
@@ -82,10 +82,10 @@ __export(Sidebar_exports, {
|
|
|
82
82
|
CopilotSidebar: () => CopilotSidebar
|
|
83
83
|
});
|
|
84
84
|
module.exports = __toCommonJS(Sidebar_exports);
|
|
85
|
-
var
|
|
85
|
+
var import_react16 = require("react");
|
|
86
86
|
|
|
87
87
|
// src/components/chat/Modal.tsx
|
|
88
|
-
var
|
|
88
|
+
var import_react15 = __toESM(require("react"));
|
|
89
89
|
|
|
90
90
|
// src/components/chat/ChatContext.tsx
|
|
91
91
|
var import_react = __toESM(require("react"));
|
|
@@ -1026,7 +1026,7 @@ var Header = ({}) => {
|
|
|
1026
1026
|
};
|
|
1027
1027
|
|
|
1028
1028
|
// src/components/chat/Messages.tsx
|
|
1029
|
-
var
|
|
1029
|
+
var import_react9 = require("react");
|
|
1030
1030
|
var import_react_core5 = require("@copilotkit/react-core");
|
|
1031
1031
|
|
|
1032
1032
|
// src/components/chat/messages/UserMessage.tsx
|
|
@@ -1058,8 +1058,7 @@ var UserMessage = (props) => {
|
|
|
1058
1058
|
};
|
|
1059
1059
|
|
|
1060
1060
|
// src/components/chat/Markdown.tsx
|
|
1061
|
-
var
|
|
1062
|
-
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1061
|
+
var import_streamdown = require("streamdown");
|
|
1063
1062
|
|
|
1064
1063
|
// src/components/chat/CodeBlock.tsx
|
|
1065
1064
|
var import_react6 = require("react");
|
|
@@ -1471,9 +1470,6 @@ var highlightStyle = {
|
|
|
1471
1470
|
};
|
|
1472
1471
|
|
|
1473
1472
|
// src/components/chat/Markdown.tsx
|
|
1474
|
-
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
1475
|
-
var import_remark_math = __toESM(require("remark-math"));
|
|
1476
|
-
var import_rehype_raw = __toESM(require("rehype-raw"));
|
|
1477
1473
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1478
1474
|
var defaultComponents = {
|
|
1479
1475
|
a(_a) {
|
|
@@ -1567,24 +1563,18 @@ var defaultComponents = {
|
|
|
1567
1563
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
|
|
1568
1564
|
}
|
|
1569
1565
|
};
|
|
1570
|
-
var MemoizedReactMarkdown = (0, import_react7.memo)(
|
|
1571
|
-
import_react_markdown.default,
|
|
1572
|
-
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
|
|
1573
|
-
);
|
|
1574
1566
|
var Markdown = ({ content, components }) => {
|
|
1575
1567
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1576
|
-
|
|
1568
|
+
import_streamdown.Streamdown,
|
|
1577
1569
|
{
|
|
1578
1570
|
components: __spreadValues(__spreadValues({}, defaultComponents), components),
|
|
1579
|
-
remarkPlugins: [import_remark_gfm.default, [import_remark_math.default, { singleDollarTextMath: false }]],
|
|
1580
|
-
rehypePlugins: [import_rehype_raw.default],
|
|
1581
1571
|
children: content
|
|
1582
1572
|
}
|
|
1583
1573
|
) });
|
|
1584
1574
|
};
|
|
1585
1575
|
|
|
1586
1576
|
// src/components/chat/messages/AssistantMessage.tsx
|
|
1587
|
-
var
|
|
1577
|
+
var import_react7 = require("react");
|
|
1588
1578
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1589
1579
|
var AssistantMessage = (props) => {
|
|
1590
1580
|
var _a;
|
|
@@ -1600,7 +1590,7 @@ var AssistantMessage = (props) => {
|
|
|
1600
1590
|
feedback,
|
|
1601
1591
|
markdownTagRenderers
|
|
1602
1592
|
} = props;
|
|
1603
|
-
const [copied, setCopied] = (0,
|
|
1593
|
+
const [copied, setCopied] = (0, import_react7.useState)(false);
|
|
1604
1594
|
const handleCopy = () => {
|
|
1605
1595
|
const content2 = (message == null ? void 0 : message.content) || "";
|
|
1606
1596
|
if (content2 && onCopy) {
|
|
@@ -1689,10 +1679,10 @@ var AssistantMessage = (props) => {
|
|
|
1689
1679
|
};
|
|
1690
1680
|
|
|
1691
1681
|
// src/components/chat/messages/ImageRenderer.tsx
|
|
1692
|
-
var
|
|
1682
|
+
var import_react8 = require("react");
|
|
1693
1683
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1694
1684
|
var ImageRenderer = ({ image, content, className = "" }) => {
|
|
1695
|
-
const [imageError, setImageError] = (0,
|
|
1685
|
+
const [imageError, setImageError] = (0, import_react8.useState)(false);
|
|
1696
1686
|
const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
|
|
1697
1687
|
const altText = content || "User uploaded image";
|
|
1698
1688
|
const handleImageError = () => {
|
|
@@ -1935,18 +1925,18 @@ var Messages = ({
|
|
|
1935
1925
|
var _a;
|
|
1936
1926
|
const { labels, icons } = useChatContext();
|
|
1937
1927
|
const { messages: visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
|
|
1938
|
-
const initialMessages = (0,
|
|
1928
|
+
const initialMessages = (0, import_react9.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
|
|
1939
1929
|
const messages = [...initialMessages, ...visibleMessages];
|
|
1940
1930
|
const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
|
|
1941
1931
|
const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
|
|
1942
|
-
(0,
|
|
1932
|
+
(0, import_react9.useEffect)(() => {
|
|
1943
1933
|
if (hasLegacyProps) {
|
|
1944
1934
|
console.warn(
|
|
1945
1935
|
"[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"
|
|
1946
1936
|
);
|
|
1947
1937
|
}
|
|
1948
1938
|
}, [hasLegacyProps]);
|
|
1949
|
-
const legacyProps = (0,
|
|
1939
|
+
const legacyProps = (0, import_react9.useMemo)(
|
|
1950
1940
|
() => ({
|
|
1951
1941
|
RenderTextMessage,
|
|
1952
1942
|
RenderActionExecutionMessage,
|
|
@@ -2017,10 +2007,10 @@ function makeInitialMessages(initial) {
|
|
|
2017
2007
|
];
|
|
2018
2008
|
}
|
|
2019
2009
|
function useScrollToBottom(messages) {
|
|
2020
|
-
const messagesEndRef = (0,
|
|
2021
|
-
const messagesContainerRef = (0,
|
|
2022
|
-
const isProgrammaticScrollRef = (0,
|
|
2023
|
-
const isUserScrollUpRef = (0,
|
|
2010
|
+
const messagesEndRef = (0, import_react9.useRef)(null);
|
|
2011
|
+
const messagesContainerRef = (0, import_react9.useRef)(null);
|
|
2012
|
+
const isProgrammaticScrollRef = (0, import_react9.useRef)(false);
|
|
2013
|
+
const isUserScrollUpRef = (0, import_react9.useRef)(false);
|
|
2024
2014
|
const scrollToBottom = () => {
|
|
2025
2015
|
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
2026
2016
|
isProgrammaticScrollRef.current = true;
|
|
@@ -2037,7 +2027,7 @@ function useScrollToBottom(messages) {
|
|
|
2037
2027
|
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
2038
2028
|
}
|
|
2039
2029
|
};
|
|
2040
|
-
(0,
|
|
2030
|
+
(0, import_react9.useEffect)(() => {
|
|
2041
2031
|
const container = messagesContainerRef.current;
|
|
2042
2032
|
if (container) {
|
|
2043
2033
|
container.addEventListener("scroll", handleScroll);
|
|
@@ -2048,7 +2038,7 @@ function useScrollToBottom(messages) {
|
|
|
2048
2038
|
}
|
|
2049
2039
|
};
|
|
2050
2040
|
}, []);
|
|
2051
|
-
(0,
|
|
2041
|
+
(0, import_react9.useEffect)(() => {
|
|
2052
2042
|
const container = messagesContainerRef.current;
|
|
2053
2043
|
if (!container) {
|
|
2054
2044
|
return;
|
|
@@ -2067,7 +2057,7 @@ function useScrollToBottom(messages) {
|
|
|
2067
2057
|
mutationObserver.disconnect();
|
|
2068
2058
|
};
|
|
2069
2059
|
}, []);
|
|
2070
|
-
(0,
|
|
2060
|
+
(0, import_react9.useEffect)(() => {
|
|
2071
2061
|
isUserScrollUpRef.current = false;
|
|
2072
2062
|
scrollToBottom();
|
|
2073
2063
|
}, [messages.filter((m) => m.role === "user").length]);
|
|
@@ -2075,12 +2065,12 @@ function useScrollToBottom(messages) {
|
|
|
2075
2065
|
}
|
|
2076
2066
|
|
|
2077
2067
|
// src/components/chat/Input.tsx
|
|
2078
|
-
var
|
|
2068
|
+
var import_react13 = require("react");
|
|
2079
2069
|
|
|
2080
2070
|
// src/components/chat/Textarea.tsx
|
|
2081
|
-
var
|
|
2071
|
+
var import_react10 = require("react");
|
|
2082
2072
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2083
|
-
var AutoResizingTextarea = (0,
|
|
2073
|
+
var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
2084
2074
|
({
|
|
2085
2075
|
maxRows = 1,
|
|
2086
2076
|
placeholder,
|
|
@@ -2091,10 +2081,10 @@ var AutoResizingTextarea = (0, import_react11.forwardRef)(
|
|
|
2091
2081
|
onCompositionEnd,
|
|
2092
2082
|
autoFocus
|
|
2093
2083
|
}, ref) => {
|
|
2094
|
-
const internalTextareaRef = (0,
|
|
2095
|
-
const [maxHeight, setMaxHeight] = (0,
|
|
2096
|
-
(0,
|
|
2097
|
-
(0,
|
|
2084
|
+
const internalTextareaRef = (0, import_react10.useRef)(null);
|
|
2085
|
+
const [maxHeight, setMaxHeight] = (0, import_react10.useState)(0);
|
|
2086
|
+
(0, import_react10.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
2087
|
+
(0, import_react10.useEffect)(() => {
|
|
2098
2088
|
const calculateMaxHeight = () => {
|
|
2099
2089
|
const textarea = internalTextareaRef.current;
|
|
2100
2090
|
if (textarea) {
|
|
@@ -2108,7 +2098,7 @@ var AutoResizingTextarea = (0, import_react11.forwardRef)(
|
|
|
2108
2098
|
};
|
|
2109
2099
|
calculateMaxHeight();
|
|
2110
2100
|
}, [maxRows]);
|
|
2111
|
-
(0,
|
|
2101
|
+
(0, import_react10.useEffect)(() => {
|
|
2112
2102
|
const textarea = internalTextareaRef.current;
|
|
2113
2103
|
if (textarea) {
|
|
2114
2104
|
textarea.style.height = "auto";
|
|
@@ -2140,7 +2130,7 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
2140
2130
|
// src/hooks/use-push-to-talk.tsx
|
|
2141
2131
|
var import_react_core6 = require("@copilotkit/react-core");
|
|
2142
2132
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
2143
|
-
var
|
|
2133
|
+
var import_react11 = require("react");
|
|
2144
2134
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
2145
2135
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
2146
2136
|
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
@@ -2189,16 +2179,16 @@ var usePushToTalk = ({
|
|
|
2189
2179
|
sendFunction,
|
|
2190
2180
|
inProgress
|
|
2191
2181
|
}) => {
|
|
2192
|
-
const [pushToTalkState, setPushToTalkState] = (0,
|
|
2193
|
-
const mediaStreamRef = (0,
|
|
2194
|
-
const audioContextRef = (0,
|
|
2195
|
-
const mediaRecorderRef = (0,
|
|
2196
|
-
const recordedChunks = (0,
|
|
2182
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react11.useState)("idle");
|
|
2183
|
+
const mediaStreamRef = (0, import_react11.useRef)(null);
|
|
2184
|
+
const audioContextRef = (0, import_react11.useRef)(null);
|
|
2185
|
+
const mediaRecorderRef = (0, import_react11.useRef)(null);
|
|
2186
|
+
const recordedChunks = (0, import_react11.useRef)([]);
|
|
2197
2187
|
const generalContext = (0, import_react_core6.useCopilotContext)();
|
|
2198
2188
|
const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
|
|
2199
2189
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2200
|
-
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0,
|
|
2201
|
-
(0,
|
|
2190
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react11.useState)(null);
|
|
2191
|
+
(0, import_react11.useEffect)(() => {
|
|
2202
2192
|
if (pushToTalkState === "recording") {
|
|
2203
2193
|
startRecording(
|
|
2204
2194
|
mediaStreamRef,
|
|
@@ -2226,7 +2216,7 @@ var usePushToTalk = ({
|
|
|
2226
2216
|
stopRecording(mediaRecorderRef);
|
|
2227
2217
|
};
|
|
2228
2218
|
}, [pushToTalkState]);
|
|
2229
|
-
(0,
|
|
2219
|
+
(0, import_react11.useEffect)(() => {
|
|
2230
2220
|
if (inProgress === false && startReadingFromMessageId) {
|
|
2231
2221
|
const lastMessageIndex = context.messages.findIndex(
|
|
2232
2222
|
(message) => message.id === startReadingFromMessageId
|
|
@@ -2245,7 +2235,7 @@ var usePushToTalk = ({
|
|
|
2245
2235
|
var import_react_core7 = require("@copilotkit/react-core");
|
|
2246
2236
|
|
|
2247
2237
|
// src/components/chat/PoweredByTag.tsx
|
|
2248
|
-
var
|
|
2238
|
+
var import_react12 = require("react");
|
|
2249
2239
|
|
|
2250
2240
|
// src/hooks/use-dark-mode.ts
|
|
2251
2241
|
var useDarkMode = () => {
|
|
@@ -2257,9 +2247,9 @@ var useDarkMode = () => {
|
|
|
2257
2247
|
// src/components/chat/PoweredByTag.tsx
|
|
2258
2248
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2259
2249
|
function PoweredByTag({ showPoweredBy = true }) {
|
|
2260
|
-
const [mounted, setMounted] = (0,
|
|
2250
|
+
const [mounted, setMounted] = (0, import_react12.useState)(false);
|
|
2261
2251
|
const isDark = useDarkMode();
|
|
2262
|
-
(0,
|
|
2252
|
+
(0, import_react12.useEffect)(() => {
|
|
2263
2253
|
setMounted(true);
|
|
2264
2254
|
}, []);
|
|
2265
2255
|
if (!showPoweredBy) {
|
|
@@ -2293,8 +2283,8 @@ var Input = ({
|
|
|
2293
2283
|
const copilotContext = (0, import_react_core7.useCopilotContext)();
|
|
2294
2284
|
const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
|
|
2295
2285
|
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
2296
|
-
const textareaRef = (0,
|
|
2297
|
-
const [isComposing, setIsComposing] = (0,
|
|
2286
|
+
const textareaRef = (0, import_react13.useRef)(null);
|
|
2287
|
+
const [isComposing, setIsComposing] = (0, import_react13.useState)(false);
|
|
2298
2288
|
const handleDivClick = (event) => {
|
|
2299
2289
|
var _a2;
|
|
2300
2290
|
const target = event.target;
|
|
@@ -2304,7 +2294,7 @@ var Input = ({
|
|
|
2304
2294
|
return;
|
|
2305
2295
|
(_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
|
|
2306
2296
|
};
|
|
2307
|
-
const [text, setText] = (0,
|
|
2297
|
+
const [text, setText] = (0, import_react13.useState)("");
|
|
2308
2298
|
const send = () => {
|
|
2309
2299
|
var _a2;
|
|
2310
2300
|
if (inProgress)
|
|
@@ -2318,17 +2308,17 @@ var Input = ({
|
|
|
2318
2308
|
inProgress
|
|
2319
2309
|
});
|
|
2320
2310
|
const isInProgress = inProgress || pushToTalkState === "transcribing";
|
|
2321
|
-
const { buttonIcon, buttonAlt } = (0,
|
|
2311
|
+
const { buttonIcon, buttonAlt } = (0, import_react13.useMemo)(() => {
|
|
2322
2312
|
if (!chatReady)
|
|
2323
2313
|
return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
|
|
2324
2314
|
return isInProgress && !hideStopButton && chatReady ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
|
|
2325
2315
|
}, [isInProgress, chatReady, hideStopButton, context.icons.stopIcon, context.icons.sendIcon]);
|
|
2326
2316
|
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
2327
2317
|
const { interrupt } = (0, import_react_core7.useCopilotChatInternal)();
|
|
2328
|
-
const canSend = (0,
|
|
2318
|
+
const canSend = (0, import_react13.useMemo)(() => {
|
|
2329
2319
|
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
|
|
2330
2320
|
}, [interrupt, isInProgress, text, pushToTalkState]);
|
|
2331
|
-
const canStop = (0,
|
|
2321
|
+
const canStop = (0, import_react13.useMemo)(() => {
|
|
2332
2322
|
return isInProgress && !hideStopButton;
|
|
2333
2323
|
}, [isInProgress, hideStopButton]);
|
|
2334
2324
|
const sendDisabled = !canSend && !canStop;
|
|
@@ -2385,7 +2375,7 @@ var Input = ({
|
|
|
2385
2375
|
};
|
|
2386
2376
|
|
|
2387
2377
|
// src/components/chat/Chat.tsx
|
|
2388
|
-
var
|
|
2378
|
+
var import_react14 = __toESM(require("react"));
|
|
2389
2379
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2390
2380
|
var import_shared3 = require("@copilotkit/shared");
|
|
2391
2381
|
|
|
@@ -2562,13 +2552,13 @@ function CopilotChat({
|
|
|
2562
2552
|
removeInternalErrorHandler
|
|
2563
2553
|
} = (0, import_react_core9.useCopilotContext)();
|
|
2564
2554
|
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
2565
|
-
const [selectedImages, setSelectedImages] = (0,
|
|
2566
|
-
const [chatError, setChatError] = (0,
|
|
2567
|
-
const [messageFeedback, setMessageFeedback] = (0,
|
|
2555
|
+
const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
|
|
2556
|
+
const [chatError, setChatError] = (0, import_react14.useState)(null);
|
|
2557
|
+
const [messageFeedback, setMessageFeedback] = (0, import_react14.useState)(
|
|
2568
2558
|
{}
|
|
2569
2559
|
);
|
|
2570
|
-
const fileInputRef = (0,
|
|
2571
|
-
const triggerObservabilityHook = (0,
|
|
2560
|
+
const fileInputRef = (0, import_react14.useRef)(null);
|
|
2561
|
+
const triggerObservabilityHook = (0, import_react14.useCallback)(
|
|
2572
2562
|
(hookName, ...args) => {
|
|
2573
2563
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2574
2564
|
observabilityHooks[hookName](...args);
|
|
@@ -2587,7 +2577,7 @@ function CopilotChat({
|
|
|
2587
2577
|
},
|
|
2588
2578
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2589
2579
|
);
|
|
2590
|
-
const triggerChatError = (0,
|
|
2580
|
+
const triggerChatError = (0, import_react14.useCallback)(
|
|
2591
2581
|
(error, operation, originalError) => {
|
|
2592
2582
|
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
|
|
2593
2583
|
setChatError({
|
|
@@ -2633,7 +2623,7 @@ function CopilotChat({
|
|
|
2633
2623
|
},
|
|
2634
2624
|
[publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
|
|
2635
2625
|
);
|
|
2636
|
-
(0,
|
|
2626
|
+
(0, import_react14.useEffect)(() => {
|
|
2637
2627
|
const id = "chat-component";
|
|
2638
2628
|
setInternalErrorHandler({
|
|
2639
2629
|
[id]: (error) => {
|
|
@@ -2646,7 +2636,7 @@ function CopilotChat({
|
|
|
2646
2636
|
removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
|
|
2647
2637
|
};
|
|
2648
2638
|
}, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
|
|
2649
|
-
(0,
|
|
2639
|
+
(0, import_react14.useEffect)(() => {
|
|
2650
2640
|
if (!imageUploadsEnabled)
|
|
2651
2641
|
return;
|
|
2652
2642
|
const handlePaste = (e) => __async(this, null, function* () {
|
|
@@ -2692,7 +2682,7 @@ function CopilotChat({
|
|
|
2692
2682
|
document.addEventListener("paste", handlePaste);
|
|
2693
2683
|
return () => document.removeEventListener("paste", handlePaste);
|
|
2694
2684
|
}, [imageUploadsEnabled, triggerChatError]);
|
|
2695
|
-
(0,
|
|
2685
|
+
(0, import_react14.useEffect)(() => {
|
|
2696
2686
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
2697
2687
|
setChatInstructions(instructions || "");
|
|
2698
2688
|
return;
|
|
@@ -2720,8 +2710,8 @@ function CopilotChat({
|
|
|
2720
2710
|
onStopGeneration,
|
|
2721
2711
|
onReloadMessages
|
|
2722
2712
|
});
|
|
2723
|
-
const prevIsLoading = (0,
|
|
2724
|
-
(0,
|
|
2713
|
+
const prevIsLoading = (0, import_react14.useRef)(isLoading);
|
|
2714
|
+
(0, import_react14.useEffect)(() => {
|
|
2725
2715
|
if (prevIsLoading.current !== isLoading) {
|
|
2726
2716
|
if (isLoading) {
|
|
2727
2717
|
triggerObservabilityHook("onChatStarted");
|
|
@@ -2744,7 +2734,7 @@ function CopilotChat({
|
|
|
2744
2734
|
role: "user"
|
|
2745
2735
|
});
|
|
2746
2736
|
};
|
|
2747
|
-
const chatContext =
|
|
2737
|
+
const chatContext = import_react14.default.useContext(ChatContext);
|
|
2748
2738
|
const isVisible = chatContext ? chatContext.open : true;
|
|
2749
2739
|
const handleRegenerate = (messageId) => {
|
|
2750
2740
|
if (onRegenerate) {
|
|
@@ -2888,7 +2878,7 @@ function WrappedCopilotChat({
|
|
|
2888
2878
|
labels,
|
|
2889
2879
|
className
|
|
2890
2880
|
}) {
|
|
2891
|
-
const chatContext =
|
|
2881
|
+
const chatContext = import_react14.default.useContext(ChatContext);
|
|
2892
2882
|
if (!chatContext) {
|
|
2893
2883
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
2894
2884
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
|
|
@@ -2926,7 +2916,7 @@ var CopilotModalInner = (_a) => {
|
|
|
2926
2916
|
]);
|
|
2927
2917
|
const { copilotApiConfig, setBannerError } = (0, import_react_core10.useCopilotContext)();
|
|
2928
2918
|
const { publicApiKey } = copilotApiConfig;
|
|
2929
|
-
const triggerObservabilityHook = (0,
|
|
2919
|
+
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2930
2920
|
(hookName, ...args) => {
|
|
2931
2921
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2932
2922
|
observabilityHooks[hookName](...args);
|
|
@@ -2946,8 +2936,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2946
2936
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2947
2937
|
);
|
|
2948
2938
|
const { open } = useChatContext();
|
|
2949
|
-
const prevOpen = (0,
|
|
2950
|
-
(0,
|
|
2939
|
+
const prevOpen = (0, import_react15.useRef)(open);
|
|
2940
|
+
(0, import_react15.useEffect)(() => {
|
|
2951
2941
|
if (prevOpen.current !== open) {
|
|
2952
2942
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2953
2943
|
if (open) {
|
|
@@ -2958,8 +2948,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2958
2948
|
prevOpen.current = open;
|
|
2959
2949
|
}
|
|
2960
2950
|
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
2961
|
-
const memoizedHeader = (0,
|
|
2962
|
-
const memoizedChildren = (0,
|
|
2951
|
+
const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}), [Header2]);
|
|
2952
|
+
const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
|
|
2963
2953
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
2964
2954
|
memoizedChildren,
|
|
2965
2955
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className, children: [
|
|
@@ -3039,7 +3029,7 @@ var CopilotModal = (_a) => {
|
|
|
3039
3029
|
"children",
|
|
3040
3030
|
"observabilityHooks"
|
|
3041
3031
|
]);
|
|
3042
|
-
const [openState, setOpenState] =
|
|
3032
|
+
const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
|
|
3043
3033
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3044
3034
|
CopilotModalInner,
|
|
3045
3035
|
__spreadProps(__spreadValues({
|
|
@@ -3079,7 +3069,7 @@ function CopilotSidebar(props) {
|
|
|
3079
3069
|
props = __spreadProps(__spreadValues({}, props), {
|
|
3080
3070
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
3081
3071
|
});
|
|
3082
|
-
const [expandedClassName, setExpandedClassName] = (0,
|
|
3072
|
+
const [expandedClassName, setExpandedClassName] = (0, import_react16.useState)(
|
|
3083
3073
|
props.defaultOpen ? "sidebarExpanded" : ""
|
|
3084
3074
|
);
|
|
3085
3075
|
const onSetOpen = (open) => {
|