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