@copilotkit/react-ui 1.51.3-next.5 → 1.51.3-next.6
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 +8 -0
- package/dist/{chunk-PKSW6ZMQ.mjs → chunk-7OURDQZJ.mjs} +2 -2
- package/dist/{chunk-HKZL4P3F.mjs → chunk-BVKKSSB2.mjs} +4 -4
- package/dist/{chunk-4S4ZEKE6.mjs → chunk-DI7DDMRS.mjs} +2 -2
- package/dist/{chunk-UH5GQ7QF.mjs → chunk-HIW7RXCD.mjs} +2 -2
- package/dist/{chunk-SLM2AOHF.mjs → chunk-IHFR6PYG.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-NCIAFFQ2.mjs} +2 -2
- package/dist/{chunk-YQOESY4Y.mjs → chunk-NSJWSIPR.mjs} +4 -4
- package/dist/{chunk-O4PPO3K3.mjs → chunk-VVCCMYGT.mjs} +2 -2
- package/dist/components/chat/Chat.js +67 -57
- 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 +27 -17
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +5 -5
- package/dist/components/chat/Modal.js +74 -64
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +7 -7
- package/dist/components/chat/Popup.js +74 -64
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +8 -8
- package/dist/components/chat/Sidebar.js +76 -66
- 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 +76 -66
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +9 -9
- package/dist/components/chat/messages/AssistantMessage.js +14 -4
- 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 +16 -6
- 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 +16 -6
- 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 +76 -66
- 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 +76 -66
- 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/dist/chunk-XOBQLKUU.mjs.map +0 -1
- /package/dist/{chunk-PKSW6ZMQ.mjs.map → chunk-7OURDQZJ.mjs.map} +0 -0
- /package/dist/{chunk-HKZL4P3F.mjs.map → chunk-BVKKSSB2.mjs.map} +0 -0
- /package/dist/{chunk-4S4ZEKE6.mjs.map → chunk-DI7DDMRS.mjs.map} +0 -0
- /package/dist/{chunk-UH5GQ7QF.mjs.map → chunk-HIW7RXCD.mjs.map} +0 -0
- /package/dist/{chunk-SLM2AOHF.mjs.map → chunk-IHFR6PYG.mjs.map} +0 -0
- /package/dist/{chunk-XEZ5ODJS.mjs.map → chunk-NCIAFFQ2.mjs.map} +0 -0
- /package/dist/{chunk-YQOESY4Y.mjs.map → chunk-NSJWSIPR.mjs.map} +0 -0
- /package/dist/{chunk-O4PPO3K3.mjs.map → chunk-VVCCMYGT.mjs.map} +0 -0
package/dist/components/index.js
CHANGED
|
@@ -95,7 +95,7 @@ __export(components_exports, {
|
|
|
95
95
|
module.exports = __toCommonJS(components_exports);
|
|
96
96
|
|
|
97
97
|
// src/components/chat/Modal.tsx
|
|
98
|
-
var
|
|
98
|
+
var import_react16 = __toESM(require("react"));
|
|
99
99
|
|
|
100
100
|
// src/components/chat/ChatContext.tsx
|
|
101
101
|
var import_react = __toESM(require("react"));
|
|
@@ -1036,7 +1036,7 @@ var Header = ({}) => {
|
|
|
1036
1036
|
};
|
|
1037
1037
|
|
|
1038
1038
|
// src/components/chat/Messages.tsx
|
|
1039
|
-
var
|
|
1039
|
+
var import_react10 = require("react");
|
|
1040
1040
|
var import_react_core5 = require("@copilotkit/react-core");
|
|
1041
1041
|
|
|
1042
1042
|
// src/components/chat/messages/UserMessage.tsx
|
|
@@ -1068,7 +1068,8 @@ var UserMessage = (props) => {
|
|
|
1068
1068
|
};
|
|
1069
1069
|
|
|
1070
1070
|
// src/components/chat/Markdown.tsx
|
|
1071
|
-
var
|
|
1071
|
+
var import_react7 = require("react");
|
|
1072
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1072
1073
|
|
|
1073
1074
|
// src/components/chat/CodeBlock.tsx
|
|
1074
1075
|
var import_react6 = require("react");
|
|
@@ -1480,6 +1481,9 @@ var highlightStyle = {
|
|
|
1480
1481
|
};
|
|
1481
1482
|
|
|
1482
1483
|
// src/components/chat/Markdown.tsx
|
|
1484
|
+
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
1485
|
+
var import_remark_math = __toESM(require("remark-math"));
|
|
1486
|
+
var import_rehype_raw = __toESM(require("rehype-raw"));
|
|
1483
1487
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1484
1488
|
var defaultComponents = {
|
|
1485
1489
|
a(_a) {
|
|
@@ -1573,18 +1577,24 @@ var defaultComponents = {
|
|
|
1573
1577
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
|
|
1574
1578
|
}
|
|
1575
1579
|
};
|
|
1580
|
+
var MemoizedReactMarkdown = (0, import_react7.memo)(
|
|
1581
|
+
import_react_markdown.default,
|
|
1582
|
+
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
|
|
1583
|
+
);
|
|
1576
1584
|
var Markdown = ({ content, components }) => {
|
|
1577
1585
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1578
|
-
|
|
1586
|
+
MemoizedReactMarkdown,
|
|
1579
1587
|
{
|
|
1580
1588
|
components: __spreadValues(__spreadValues({}, defaultComponents), components),
|
|
1589
|
+
remarkPlugins: [import_remark_gfm.default, [import_remark_math.default, { singleDollarTextMath: false }]],
|
|
1590
|
+
rehypePlugins: [import_rehype_raw.default],
|
|
1581
1591
|
children: content
|
|
1582
1592
|
}
|
|
1583
1593
|
) });
|
|
1584
1594
|
};
|
|
1585
1595
|
|
|
1586
1596
|
// src/components/chat/messages/AssistantMessage.tsx
|
|
1587
|
-
var
|
|
1597
|
+
var import_react8 = require("react");
|
|
1588
1598
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1589
1599
|
var AssistantMessage = (props) => {
|
|
1590
1600
|
var _a;
|
|
@@ -1600,7 +1610,7 @@ var AssistantMessage = (props) => {
|
|
|
1600
1610
|
feedback,
|
|
1601
1611
|
markdownTagRenderers
|
|
1602
1612
|
} = props;
|
|
1603
|
-
const [copied, setCopied] = (0,
|
|
1613
|
+
const [copied, setCopied] = (0, import_react8.useState)(false);
|
|
1604
1614
|
const handleCopy = () => {
|
|
1605
1615
|
const content2 = (message == null ? void 0 : message.content) || "";
|
|
1606
1616
|
if (content2 && onCopy) {
|
|
@@ -1689,10 +1699,10 @@ var AssistantMessage = (props) => {
|
|
|
1689
1699
|
};
|
|
1690
1700
|
|
|
1691
1701
|
// src/components/chat/messages/ImageRenderer.tsx
|
|
1692
|
-
var
|
|
1702
|
+
var import_react9 = require("react");
|
|
1693
1703
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1694
1704
|
var ImageRenderer = ({ image, content, className = "" }) => {
|
|
1695
|
-
const [imageError, setImageError] = (0,
|
|
1705
|
+
const [imageError, setImageError] = (0, import_react9.useState)(false);
|
|
1696
1706
|
const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
|
|
1697
1707
|
const altText = content || "User uploaded image";
|
|
1698
1708
|
const handleImageError = () => {
|
|
@@ -1935,18 +1945,18 @@ var Messages = ({
|
|
|
1935
1945
|
var _a;
|
|
1936
1946
|
const { labels, icons } = useChatContext();
|
|
1937
1947
|
const { messages: visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
|
|
1938
|
-
const initialMessages = (0,
|
|
1948
|
+
const initialMessages = (0, import_react10.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
|
|
1939
1949
|
const messages = [...initialMessages, ...visibleMessages];
|
|
1940
1950
|
const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
|
|
1941
1951
|
const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
|
|
1942
|
-
(0,
|
|
1952
|
+
(0, import_react10.useEffect)(() => {
|
|
1943
1953
|
if (hasLegacyProps) {
|
|
1944
1954
|
console.warn(
|
|
1945
1955
|
"[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
1956
|
);
|
|
1947
1957
|
}
|
|
1948
1958
|
}, [hasLegacyProps]);
|
|
1949
|
-
const legacyProps = (0,
|
|
1959
|
+
const legacyProps = (0, import_react10.useMemo)(
|
|
1950
1960
|
() => ({
|
|
1951
1961
|
RenderTextMessage,
|
|
1952
1962
|
RenderActionExecutionMessage,
|
|
@@ -2017,10 +2027,10 @@ function makeInitialMessages(initial) {
|
|
|
2017
2027
|
];
|
|
2018
2028
|
}
|
|
2019
2029
|
function useScrollToBottom(messages) {
|
|
2020
|
-
const messagesEndRef = (0,
|
|
2021
|
-
const messagesContainerRef = (0,
|
|
2022
|
-
const isProgrammaticScrollRef = (0,
|
|
2023
|
-
const isUserScrollUpRef = (0,
|
|
2030
|
+
const messagesEndRef = (0, import_react10.useRef)(null);
|
|
2031
|
+
const messagesContainerRef = (0, import_react10.useRef)(null);
|
|
2032
|
+
const isProgrammaticScrollRef = (0, import_react10.useRef)(false);
|
|
2033
|
+
const isUserScrollUpRef = (0, import_react10.useRef)(false);
|
|
2024
2034
|
const scrollToBottom = () => {
|
|
2025
2035
|
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
2026
2036
|
isProgrammaticScrollRef.current = true;
|
|
@@ -2037,7 +2047,7 @@ function useScrollToBottom(messages) {
|
|
|
2037
2047
|
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
2038
2048
|
}
|
|
2039
2049
|
};
|
|
2040
|
-
(0,
|
|
2050
|
+
(0, import_react10.useEffect)(() => {
|
|
2041
2051
|
const container = messagesContainerRef.current;
|
|
2042
2052
|
if (container) {
|
|
2043
2053
|
container.addEventListener("scroll", handleScroll);
|
|
@@ -2048,7 +2058,7 @@ function useScrollToBottom(messages) {
|
|
|
2048
2058
|
}
|
|
2049
2059
|
};
|
|
2050
2060
|
}, []);
|
|
2051
|
-
(0,
|
|
2061
|
+
(0, import_react10.useEffect)(() => {
|
|
2052
2062
|
const container = messagesContainerRef.current;
|
|
2053
2063
|
if (!container) {
|
|
2054
2064
|
return;
|
|
@@ -2067,7 +2077,7 @@ function useScrollToBottom(messages) {
|
|
|
2067
2077
|
mutationObserver.disconnect();
|
|
2068
2078
|
};
|
|
2069
2079
|
}, []);
|
|
2070
|
-
(0,
|
|
2080
|
+
(0, import_react10.useEffect)(() => {
|
|
2071
2081
|
isUserScrollUpRef.current = false;
|
|
2072
2082
|
scrollToBottom();
|
|
2073
2083
|
}, [messages.filter((m) => m.role === "user").length]);
|
|
@@ -2075,12 +2085,12 @@ function useScrollToBottom(messages) {
|
|
|
2075
2085
|
}
|
|
2076
2086
|
|
|
2077
2087
|
// src/components/chat/Input.tsx
|
|
2078
|
-
var
|
|
2088
|
+
var import_react14 = require("react");
|
|
2079
2089
|
|
|
2080
2090
|
// src/components/chat/Textarea.tsx
|
|
2081
|
-
var
|
|
2091
|
+
var import_react11 = require("react");
|
|
2082
2092
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2083
|
-
var AutoResizingTextarea = (0,
|
|
2093
|
+
var AutoResizingTextarea = (0, import_react11.forwardRef)(
|
|
2084
2094
|
({
|
|
2085
2095
|
maxRows = 1,
|
|
2086
2096
|
placeholder,
|
|
@@ -2091,10 +2101,10 @@ var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
|
2091
2101
|
onCompositionEnd,
|
|
2092
2102
|
autoFocus
|
|
2093
2103
|
}, ref) => {
|
|
2094
|
-
const internalTextareaRef = (0,
|
|
2095
|
-
const [maxHeight, setMaxHeight] = (0,
|
|
2096
|
-
(0,
|
|
2097
|
-
(0,
|
|
2104
|
+
const internalTextareaRef = (0, import_react11.useRef)(null);
|
|
2105
|
+
const [maxHeight, setMaxHeight] = (0, import_react11.useState)(0);
|
|
2106
|
+
(0, import_react11.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
2107
|
+
(0, import_react11.useEffect)(() => {
|
|
2098
2108
|
const calculateMaxHeight = () => {
|
|
2099
2109
|
const textarea = internalTextareaRef.current;
|
|
2100
2110
|
if (textarea) {
|
|
@@ -2108,7 +2118,7 @@ var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
|
2108
2118
|
};
|
|
2109
2119
|
calculateMaxHeight();
|
|
2110
2120
|
}, [maxRows]);
|
|
2111
|
-
(0,
|
|
2121
|
+
(0, import_react11.useEffect)(() => {
|
|
2112
2122
|
const textarea = internalTextareaRef.current;
|
|
2113
2123
|
if (textarea) {
|
|
2114
2124
|
textarea.style.height = "auto";
|
|
@@ -2140,7 +2150,7 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
2140
2150
|
// src/hooks/use-push-to-talk.tsx
|
|
2141
2151
|
var import_react_core6 = require("@copilotkit/react-core");
|
|
2142
2152
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
2143
|
-
var
|
|
2153
|
+
var import_react12 = require("react");
|
|
2144
2154
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
2145
2155
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
2146
2156
|
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
@@ -2189,16 +2199,16 @@ var usePushToTalk = ({
|
|
|
2189
2199
|
sendFunction,
|
|
2190
2200
|
inProgress
|
|
2191
2201
|
}) => {
|
|
2192
|
-
const [pushToTalkState, setPushToTalkState] = (0,
|
|
2193
|
-
const mediaStreamRef = (0,
|
|
2194
|
-
const audioContextRef = (0,
|
|
2195
|
-
const mediaRecorderRef = (0,
|
|
2196
|
-
const recordedChunks = (0,
|
|
2202
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react12.useState)("idle");
|
|
2203
|
+
const mediaStreamRef = (0, import_react12.useRef)(null);
|
|
2204
|
+
const audioContextRef = (0, import_react12.useRef)(null);
|
|
2205
|
+
const mediaRecorderRef = (0, import_react12.useRef)(null);
|
|
2206
|
+
const recordedChunks = (0, import_react12.useRef)([]);
|
|
2197
2207
|
const generalContext = (0, import_react_core6.useCopilotContext)();
|
|
2198
2208
|
const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
|
|
2199
2209
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2200
|
-
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0,
|
|
2201
|
-
(0,
|
|
2210
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react12.useState)(null);
|
|
2211
|
+
(0, import_react12.useEffect)(() => {
|
|
2202
2212
|
if (pushToTalkState === "recording") {
|
|
2203
2213
|
startRecording(
|
|
2204
2214
|
mediaStreamRef,
|
|
@@ -2226,7 +2236,7 @@ var usePushToTalk = ({
|
|
|
2226
2236
|
stopRecording(mediaRecorderRef);
|
|
2227
2237
|
};
|
|
2228
2238
|
}, [pushToTalkState]);
|
|
2229
|
-
(0,
|
|
2239
|
+
(0, import_react12.useEffect)(() => {
|
|
2230
2240
|
if (inProgress === false && startReadingFromMessageId) {
|
|
2231
2241
|
const lastMessageIndex = context.messages.findIndex(
|
|
2232
2242
|
(message) => message.id === startReadingFromMessageId
|
|
@@ -2245,7 +2255,7 @@ var usePushToTalk = ({
|
|
|
2245
2255
|
var import_react_core7 = require("@copilotkit/react-core");
|
|
2246
2256
|
|
|
2247
2257
|
// src/components/chat/PoweredByTag.tsx
|
|
2248
|
-
var
|
|
2258
|
+
var import_react13 = require("react");
|
|
2249
2259
|
|
|
2250
2260
|
// src/hooks/use-dark-mode.ts
|
|
2251
2261
|
var useDarkMode = () => {
|
|
@@ -2257,9 +2267,9 @@ var useDarkMode = () => {
|
|
|
2257
2267
|
// src/components/chat/PoweredByTag.tsx
|
|
2258
2268
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2259
2269
|
function PoweredByTag({ showPoweredBy = true }) {
|
|
2260
|
-
const [mounted, setMounted] = (0,
|
|
2270
|
+
const [mounted, setMounted] = (0, import_react13.useState)(false);
|
|
2261
2271
|
const isDark = useDarkMode();
|
|
2262
|
-
(0,
|
|
2272
|
+
(0, import_react13.useEffect)(() => {
|
|
2263
2273
|
setMounted(true);
|
|
2264
2274
|
}, []);
|
|
2265
2275
|
if (!showPoweredBy) {
|
|
@@ -2293,8 +2303,8 @@ var Input = ({
|
|
|
2293
2303
|
const copilotContext = (0, import_react_core7.useCopilotContext)();
|
|
2294
2304
|
const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
|
|
2295
2305
|
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
2296
|
-
const textareaRef = (0,
|
|
2297
|
-
const [isComposing, setIsComposing] = (0,
|
|
2306
|
+
const textareaRef = (0, import_react14.useRef)(null);
|
|
2307
|
+
const [isComposing, setIsComposing] = (0, import_react14.useState)(false);
|
|
2298
2308
|
const handleDivClick = (event) => {
|
|
2299
2309
|
var _a2;
|
|
2300
2310
|
const target = event.target;
|
|
@@ -2304,7 +2314,7 @@ var Input = ({
|
|
|
2304
2314
|
return;
|
|
2305
2315
|
(_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
|
|
2306
2316
|
};
|
|
2307
|
-
const [text, setText] = (0,
|
|
2317
|
+
const [text, setText] = (0, import_react14.useState)("");
|
|
2308
2318
|
const send = () => {
|
|
2309
2319
|
var _a2;
|
|
2310
2320
|
if (inProgress)
|
|
@@ -2318,17 +2328,17 @@ var Input = ({
|
|
|
2318
2328
|
inProgress
|
|
2319
2329
|
});
|
|
2320
2330
|
const isInProgress = inProgress || pushToTalkState === "transcribing";
|
|
2321
|
-
const { buttonIcon, buttonAlt } = (0,
|
|
2331
|
+
const { buttonIcon, buttonAlt } = (0, import_react14.useMemo)(() => {
|
|
2322
2332
|
if (!chatReady)
|
|
2323
2333
|
return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
|
|
2324
2334
|
return isInProgress && !hideStopButton && chatReady ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
|
|
2325
2335
|
}, [isInProgress, chatReady, hideStopButton, context.icons.stopIcon, context.icons.sendIcon]);
|
|
2326
2336
|
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
2327
2337
|
const { interrupt } = (0, import_react_core7.useCopilotChatInternal)();
|
|
2328
|
-
const canSend = (0,
|
|
2338
|
+
const canSend = (0, import_react14.useMemo)(() => {
|
|
2329
2339
|
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
|
|
2330
2340
|
}, [interrupt, isInProgress, text, pushToTalkState]);
|
|
2331
|
-
const canStop = (0,
|
|
2341
|
+
const canStop = (0, import_react14.useMemo)(() => {
|
|
2332
2342
|
return isInProgress && !hideStopButton;
|
|
2333
2343
|
}, [isInProgress, hideStopButton]);
|
|
2334
2344
|
const sendDisabled = !canSend && !canStop;
|
|
@@ -2385,7 +2395,7 @@ var Input = ({
|
|
|
2385
2395
|
};
|
|
2386
2396
|
|
|
2387
2397
|
// src/components/chat/Chat.tsx
|
|
2388
|
-
var
|
|
2398
|
+
var import_react15 = __toESM(require("react"));
|
|
2389
2399
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2390
2400
|
var import_shared3 = require("@copilotkit/shared");
|
|
2391
2401
|
|
|
@@ -2562,13 +2572,13 @@ function CopilotChat({
|
|
|
2562
2572
|
removeInternalErrorHandler
|
|
2563
2573
|
} = (0, import_react_core9.useCopilotContext)();
|
|
2564
2574
|
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
2565
|
-
const [selectedImages, setSelectedImages] = (0,
|
|
2566
|
-
const [chatError, setChatError] = (0,
|
|
2567
|
-
const [messageFeedback, setMessageFeedback] = (0,
|
|
2575
|
+
const [selectedImages, setSelectedImages] = (0, import_react15.useState)([]);
|
|
2576
|
+
const [chatError, setChatError] = (0, import_react15.useState)(null);
|
|
2577
|
+
const [messageFeedback, setMessageFeedback] = (0, import_react15.useState)(
|
|
2568
2578
|
{}
|
|
2569
2579
|
);
|
|
2570
|
-
const fileInputRef = (0,
|
|
2571
|
-
const triggerObservabilityHook = (0,
|
|
2580
|
+
const fileInputRef = (0, import_react15.useRef)(null);
|
|
2581
|
+
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2572
2582
|
(hookName, ...args) => {
|
|
2573
2583
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2574
2584
|
observabilityHooks[hookName](...args);
|
|
@@ -2587,7 +2597,7 @@ function CopilotChat({
|
|
|
2587
2597
|
},
|
|
2588
2598
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2589
2599
|
);
|
|
2590
|
-
const triggerChatError = (0,
|
|
2600
|
+
const triggerChatError = (0, import_react15.useCallback)(
|
|
2591
2601
|
(error, operation, originalError) => {
|
|
2592
2602
|
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
|
|
2593
2603
|
setChatError({
|
|
@@ -2633,7 +2643,7 @@ function CopilotChat({
|
|
|
2633
2643
|
},
|
|
2634
2644
|
[publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
|
|
2635
2645
|
);
|
|
2636
|
-
(0,
|
|
2646
|
+
(0, import_react15.useEffect)(() => {
|
|
2637
2647
|
const id = "chat-component";
|
|
2638
2648
|
setInternalErrorHandler({
|
|
2639
2649
|
[id]: (error) => {
|
|
@@ -2646,7 +2656,7 @@ function CopilotChat({
|
|
|
2646
2656
|
removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
|
|
2647
2657
|
};
|
|
2648
2658
|
}, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
|
|
2649
|
-
(0,
|
|
2659
|
+
(0, import_react15.useEffect)(() => {
|
|
2650
2660
|
if (!imageUploadsEnabled)
|
|
2651
2661
|
return;
|
|
2652
2662
|
const handlePaste = (e) => __async(this, null, function* () {
|
|
@@ -2692,7 +2702,7 @@ function CopilotChat({
|
|
|
2692
2702
|
document.addEventListener("paste", handlePaste);
|
|
2693
2703
|
return () => document.removeEventListener("paste", handlePaste);
|
|
2694
2704
|
}, [imageUploadsEnabled, triggerChatError]);
|
|
2695
|
-
(0,
|
|
2705
|
+
(0, import_react15.useEffect)(() => {
|
|
2696
2706
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
2697
2707
|
setChatInstructions(instructions || "");
|
|
2698
2708
|
return;
|
|
@@ -2720,8 +2730,8 @@ function CopilotChat({
|
|
|
2720
2730
|
onStopGeneration,
|
|
2721
2731
|
onReloadMessages
|
|
2722
2732
|
});
|
|
2723
|
-
const prevIsLoading = (0,
|
|
2724
|
-
(0,
|
|
2733
|
+
const prevIsLoading = (0, import_react15.useRef)(isLoading);
|
|
2734
|
+
(0, import_react15.useEffect)(() => {
|
|
2725
2735
|
if (prevIsLoading.current !== isLoading) {
|
|
2726
2736
|
if (isLoading) {
|
|
2727
2737
|
triggerObservabilityHook("onChatStarted");
|
|
@@ -2744,7 +2754,7 @@ function CopilotChat({
|
|
|
2744
2754
|
role: "user"
|
|
2745
2755
|
});
|
|
2746
2756
|
};
|
|
2747
|
-
const chatContext =
|
|
2757
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2748
2758
|
const isVisible = chatContext ? chatContext.open : true;
|
|
2749
2759
|
const handleRegenerate = (messageId) => {
|
|
2750
2760
|
if (onRegenerate) {
|
|
@@ -2888,7 +2898,7 @@ function WrappedCopilotChat({
|
|
|
2888
2898
|
labels,
|
|
2889
2899
|
className
|
|
2890
2900
|
}) {
|
|
2891
|
-
const chatContext =
|
|
2901
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2892
2902
|
if (!chatContext) {
|
|
2893
2903
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
2894
2904
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
|
|
@@ -2926,7 +2936,7 @@ var CopilotModalInner = (_a) => {
|
|
|
2926
2936
|
]);
|
|
2927
2937
|
const { copilotApiConfig, setBannerError } = (0, import_react_core10.useCopilotContext)();
|
|
2928
2938
|
const { publicApiKey } = copilotApiConfig;
|
|
2929
|
-
const triggerObservabilityHook = (0,
|
|
2939
|
+
const triggerObservabilityHook = (0, import_react16.useCallback)(
|
|
2930
2940
|
(hookName, ...args) => {
|
|
2931
2941
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2932
2942
|
observabilityHooks[hookName](...args);
|
|
@@ -2946,8 +2956,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2946
2956
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2947
2957
|
);
|
|
2948
2958
|
const { open } = useChatContext();
|
|
2949
|
-
const prevOpen = (0,
|
|
2950
|
-
(0,
|
|
2959
|
+
const prevOpen = (0, import_react16.useRef)(open);
|
|
2960
|
+
(0, import_react16.useEffect)(() => {
|
|
2951
2961
|
if (prevOpen.current !== open) {
|
|
2952
2962
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2953
2963
|
if (open) {
|
|
@@ -2958,8 +2968,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2958
2968
|
prevOpen.current = open;
|
|
2959
2969
|
}
|
|
2960
2970
|
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
2961
|
-
const memoizedHeader = (0,
|
|
2962
|
-
const memoizedChildren = (0,
|
|
2971
|
+
const memoizedHeader = (0, import_react16.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}), [Header2]);
|
|
2972
|
+
const memoizedChildren = (0, import_react16.useMemo)(() => children, [children]);
|
|
2963
2973
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
2964
2974
|
memoizedChildren,
|
|
2965
2975
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className, children: [
|
|
@@ -3039,7 +3049,7 @@ var CopilotModal = (_a) => {
|
|
|
3039
3049
|
"children",
|
|
3040
3050
|
"observabilityHooks"
|
|
3041
3051
|
]);
|
|
3042
|
-
const [openState, setOpenState] =
|
|
3052
|
+
const [openState, setOpenState] = import_react16.default.useState(defaultOpen);
|
|
3043
3053
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3044
3054
|
CopilotModalInner,
|
|
3045
3055
|
__spreadProps(__spreadValues({
|
|
@@ -3083,13 +3093,13 @@ function CopilotPopup(props) {
|
|
|
3083
3093
|
}
|
|
3084
3094
|
|
|
3085
3095
|
// src/components/chat/Sidebar.tsx
|
|
3086
|
-
var
|
|
3096
|
+
var import_react17 = require("react");
|
|
3087
3097
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
3088
3098
|
function CopilotSidebar(props) {
|
|
3089
3099
|
props = __spreadProps(__spreadValues({}, props), {
|
|
3090
3100
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
3091
3101
|
});
|
|
3092
|
-
const [expandedClassName, setExpandedClassName] = (0,
|
|
3102
|
+
const [expandedClassName, setExpandedClassName] = (0, import_react17.useState)(
|
|
3093
3103
|
props.defaultOpen ? "sidebarExpanded" : ""
|
|
3094
3104
|
);
|
|
3095
3105
|
const onSetOpen = (open) => {
|