@copilotkit/react-ui 1.51.2-next.1 → 1.51.3-next.0
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 +20 -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
|
@@ -82,7 +82,7 @@ __export(Modal_exports, {
|
|
|
82
82
|
CopilotModal: () => CopilotModal
|
|
83
83
|
});
|
|
84
84
|
module.exports = __toCommonJS(Modal_exports);
|
|
85
|
-
var
|
|
85
|
+
var import_react15 = __toESM(require("react"));
|
|
86
86
|
|
|
87
87
|
// src/components/chat/ChatContext.tsx
|
|
88
88
|
var import_react = __toESM(require("react"));
|
|
@@ -1023,7 +1023,7 @@ var Header = ({}) => {
|
|
|
1023
1023
|
};
|
|
1024
1024
|
|
|
1025
1025
|
// src/components/chat/Messages.tsx
|
|
1026
|
-
var
|
|
1026
|
+
var import_react9 = require("react");
|
|
1027
1027
|
var import_react_core5 = require("@copilotkit/react-core");
|
|
1028
1028
|
|
|
1029
1029
|
// src/components/chat/messages/UserMessage.tsx
|
|
@@ -1055,8 +1055,7 @@ var UserMessage = (props) => {
|
|
|
1055
1055
|
};
|
|
1056
1056
|
|
|
1057
1057
|
// src/components/chat/Markdown.tsx
|
|
1058
|
-
var
|
|
1059
|
-
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1058
|
+
var import_streamdown = require("streamdown");
|
|
1060
1059
|
|
|
1061
1060
|
// src/components/chat/CodeBlock.tsx
|
|
1062
1061
|
var import_react6 = require("react");
|
|
@@ -1468,9 +1467,6 @@ var highlightStyle = {
|
|
|
1468
1467
|
};
|
|
1469
1468
|
|
|
1470
1469
|
// src/components/chat/Markdown.tsx
|
|
1471
|
-
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
1472
|
-
var import_remark_math = __toESM(require("remark-math"));
|
|
1473
|
-
var import_rehype_raw = __toESM(require("rehype-raw"));
|
|
1474
1470
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1475
1471
|
var defaultComponents = {
|
|
1476
1472
|
a(_a) {
|
|
@@ -1564,24 +1560,18 @@ var defaultComponents = {
|
|
|
1564
1560
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
|
|
1565
1561
|
}
|
|
1566
1562
|
};
|
|
1567
|
-
var MemoizedReactMarkdown = (0, import_react7.memo)(
|
|
1568
|
-
import_react_markdown.default,
|
|
1569
|
-
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
|
|
1570
|
-
);
|
|
1571
1563
|
var Markdown = ({ content, components }) => {
|
|
1572
1564
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1573
|
-
|
|
1565
|
+
import_streamdown.Streamdown,
|
|
1574
1566
|
{
|
|
1575
1567
|
components: __spreadValues(__spreadValues({}, defaultComponents), components),
|
|
1576
|
-
remarkPlugins: [import_remark_gfm.default, [import_remark_math.default, { singleDollarTextMath: false }]],
|
|
1577
|
-
rehypePlugins: [import_rehype_raw.default],
|
|
1578
1568
|
children: content
|
|
1579
1569
|
}
|
|
1580
1570
|
) });
|
|
1581
1571
|
};
|
|
1582
1572
|
|
|
1583
1573
|
// src/components/chat/messages/AssistantMessage.tsx
|
|
1584
|
-
var
|
|
1574
|
+
var import_react7 = require("react");
|
|
1585
1575
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1586
1576
|
var AssistantMessage = (props) => {
|
|
1587
1577
|
var _a;
|
|
@@ -1597,7 +1587,7 @@ var AssistantMessage = (props) => {
|
|
|
1597
1587
|
feedback,
|
|
1598
1588
|
markdownTagRenderers
|
|
1599
1589
|
} = props;
|
|
1600
|
-
const [copied, setCopied] = (0,
|
|
1590
|
+
const [copied, setCopied] = (0, import_react7.useState)(false);
|
|
1601
1591
|
const handleCopy = () => {
|
|
1602
1592
|
const content2 = (message == null ? void 0 : message.content) || "";
|
|
1603
1593
|
if (content2 && onCopy) {
|
|
@@ -1686,10 +1676,10 @@ var AssistantMessage = (props) => {
|
|
|
1686
1676
|
};
|
|
1687
1677
|
|
|
1688
1678
|
// src/components/chat/messages/ImageRenderer.tsx
|
|
1689
|
-
var
|
|
1679
|
+
var import_react8 = require("react");
|
|
1690
1680
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1691
1681
|
var ImageRenderer = ({ image, content, className = "" }) => {
|
|
1692
|
-
const [imageError, setImageError] = (0,
|
|
1682
|
+
const [imageError, setImageError] = (0, import_react8.useState)(false);
|
|
1693
1683
|
const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
|
|
1694
1684
|
const altText = content || "User uploaded image";
|
|
1695
1685
|
const handleImageError = () => {
|
|
@@ -1932,18 +1922,18 @@ var Messages = ({
|
|
|
1932
1922
|
var _a;
|
|
1933
1923
|
const { labels, icons } = useChatContext();
|
|
1934
1924
|
const { messages: visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
|
|
1935
|
-
const initialMessages = (0,
|
|
1925
|
+
const initialMessages = (0, import_react9.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
|
|
1936
1926
|
const messages = [...initialMessages, ...visibleMessages];
|
|
1937
1927
|
const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
|
|
1938
1928
|
const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
|
|
1939
|
-
(0,
|
|
1929
|
+
(0, import_react9.useEffect)(() => {
|
|
1940
1930
|
if (hasLegacyProps) {
|
|
1941
1931
|
console.warn(
|
|
1942
1932
|
"[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"
|
|
1943
1933
|
);
|
|
1944
1934
|
}
|
|
1945
1935
|
}, [hasLegacyProps]);
|
|
1946
|
-
const legacyProps = (0,
|
|
1936
|
+
const legacyProps = (0, import_react9.useMemo)(
|
|
1947
1937
|
() => ({
|
|
1948
1938
|
RenderTextMessage,
|
|
1949
1939
|
RenderActionExecutionMessage,
|
|
@@ -2014,10 +2004,10 @@ function makeInitialMessages(initial) {
|
|
|
2014
2004
|
];
|
|
2015
2005
|
}
|
|
2016
2006
|
function useScrollToBottom(messages) {
|
|
2017
|
-
const messagesEndRef = (0,
|
|
2018
|
-
const messagesContainerRef = (0,
|
|
2019
|
-
const isProgrammaticScrollRef = (0,
|
|
2020
|
-
const isUserScrollUpRef = (0,
|
|
2007
|
+
const messagesEndRef = (0, import_react9.useRef)(null);
|
|
2008
|
+
const messagesContainerRef = (0, import_react9.useRef)(null);
|
|
2009
|
+
const isProgrammaticScrollRef = (0, import_react9.useRef)(false);
|
|
2010
|
+
const isUserScrollUpRef = (0, import_react9.useRef)(false);
|
|
2021
2011
|
const scrollToBottom = () => {
|
|
2022
2012
|
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
2023
2013
|
isProgrammaticScrollRef.current = true;
|
|
@@ -2034,7 +2024,7 @@ function useScrollToBottom(messages) {
|
|
|
2034
2024
|
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
2035
2025
|
}
|
|
2036
2026
|
};
|
|
2037
|
-
(0,
|
|
2027
|
+
(0, import_react9.useEffect)(() => {
|
|
2038
2028
|
const container = messagesContainerRef.current;
|
|
2039
2029
|
if (container) {
|
|
2040
2030
|
container.addEventListener("scroll", handleScroll);
|
|
@@ -2045,7 +2035,7 @@ function useScrollToBottom(messages) {
|
|
|
2045
2035
|
}
|
|
2046
2036
|
};
|
|
2047
2037
|
}, []);
|
|
2048
|
-
(0,
|
|
2038
|
+
(0, import_react9.useEffect)(() => {
|
|
2049
2039
|
const container = messagesContainerRef.current;
|
|
2050
2040
|
if (!container) {
|
|
2051
2041
|
return;
|
|
@@ -2064,7 +2054,7 @@ function useScrollToBottom(messages) {
|
|
|
2064
2054
|
mutationObserver.disconnect();
|
|
2065
2055
|
};
|
|
2066
2056
|
}, []);
|
|
2067
|
-
(0,
|
|
2057
|
+
(0, import_react9.useEffect)(() => {
|
|
2068
2058
|
isUserScrollUpRef.current = false;
|
|
2069
2059
|
scrollToBottom();
|
|
2070
2060
|
}, [messages.filter((m) => m.role === "user").length]);
|
|
@@ -2072,12 +2062,12 @@ function useScrollToBottom(messages) {
|
|
|
2072
2062
|
}
|
|
2073
2063
|
|
|
2074
2064
|
// src/components/chat/Input.tsx
|
|
2075
|
-
var
|
|
2065
|
+
var import_react13 = require("react");
|
|
2076
2066
|
|
|
2077
2067
|
// src/components/chat/Textarea.tsx
|
|
2078
|
-
var
|
|
2068
|
+
var import_react10 = require("react");
|
|
2079
2069
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2080
|
-
var AutoResizingTextarea = (0,
|
|
2070
|
+
var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
2081
2071
|
({
|
|
2082
2072
|
maxRows = 1,
|
|
2083
2073
|
placeholder,
|
|
@@ -2088,10 +2078,10 @@ var AutoResizingTextarea = (0, import_react11.forwardRef)(
|
|
|
2088
2078
|
onCompositionEnd,
|
|
2089
2079
|
autoFocus
|
|
2090
2080
|
}, ref) => {
|
|
2091
|
-
const internalTextareaRef = (0,
|
|
2092
|
-
const [maxHeight, setMaxHeight] = (0,
|
|
2093
|
-
(0,
|
|
2094
|
-
(0,
|
|
2081
|
+
const internalTextareaRef = (0, import_react10.useRef)(null);
|
|
2082
|
+
const [maxHeight, setMaxHeight] = (0, import_react10.useState)(0);
|
|
2083
|
+
(0, import_react10.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
2084
|
+
(0, import_react10.useEffect)(() => {
|
|
2095
2085
|
const calculateMaxHeight = () => {
|
|
2096
2086
|
const textarea = internalTextareaRef.current;
|
|
2097
2087
|
if (textarea) {
|
|
@@ -2105,7 +2095,7 @@ var AutoResizingTextarea = (0, import_react11.forwardRef)(
|
|
|
2105
2095
|
};
|
|
2106
2096
|
calculateMaxHeight();
|
|
2107
2097
|
}, [maxRows]);
|
|
2108
|
-
(0,
|
|
2098
|
+
(0, import_react10.useEffect)(() => {
|
|
2109
2099
|
const textarea = internalTextareaRef.current;
|
|
2110
2100
|
if (textarea) {
|
|
2111
2101
|
textarea.style.height = "auto";
|
|
@@ -2137,7 +2127,7 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
2137
2127
|
// src/hooks/use-push-to-talk.tsx
|
|
2138
2128
|
var import_react_core6 = require("@copilotkit/react-core");
|
|
2139
2129
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
2140
|
-
var
|
|
2130
|
+
var import_react11 = require("react");
|
|
2141
2131
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
2142
2132
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
2143
2133
|
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
@@ -2186,16 +2176,16 @@ var usePushToTalk = ({
|
|
|
2186
2176
|
sendFunction,
|
|
2187
2177
|
inProgress
|
|
2188
2178
|
}) => {
|
|
2189
|
-
const [pushToTalkState, setPushToTalkState] = (0,
|
|
2190
|
-
const mediaStreamRef = (0,
|
|
2191
|
-
const audioContextRef = (0,
|
|
2192
|
-
const mediaRecorderRef = (0,
|
|
2193
|
-
const recordedChunks = (0,
|
|
2179
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react11.useState)("idle");
|
|
2180
|
+
const mediaStreamRef = (0, import_react11.useRef)(null);
|
|
2181
|
+
const audioContextRef = (0, import_react11.useRef)(null);
|
|
2182
|
+
const mediaRecorderRef = (0, import_react11.useRef)(null);
|
|
2183
|
+
const recordedChunks = (0, import_react11.useRef)([]);
|
|
2194
2184
|
const generalContext = (0, import_react_core6.useCopilotContext)();
|
|
2195
2185
|
const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
|
|
2196
2186
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2197
|
-
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0,
|
|
2198
|
-
(0,
|
|
2187
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react11.useState)(null);
|
|
2188
|
+
(0, import_react11.useEffect)(() => {
|
|
2199
2189
|
if (pushToTalkState === "recording") {
|
|
2200
2190
|
startRecording(
|
|
2201
2191
|
mediaStreamRef,
|
|
@@ -2223,7 +2213,7 @@ var usePushToTalk = ({
|
|
|
2223
2213
|
stopRecording(mediaRecorderRef);
|
|
2224
2214
|
};
|
|
2225
2215
|
}, [pushToTalkState]);
|
|
2226
|
-
(0,
|
|
2216
|
+
(0, import_react11.useEffect)(() => {
|
|
2227
2217
|
if (inProgress === false && startReadingFromMessageId) {
|
|
2228
2218
|
const lastMessageIndex = context.messages.findIndex(
|
|
2229
2219
|
(message) => message.id === startReadingFromMessageId
|
|
@@ -2242,7 +2232,7 @@ var usePushToTalk = ({
|
|
|
2242
2232
|
var import_react_core7 = require("@copilotkit/react-core");
|
|
2243
2233
|
|
|
2244
2234
|
// src/components/chat/PoweredByTag.tsx
|
|
2245
|
-
var
|
|
2235
|
+
var import_react12 = require("react");
|
|
2246
2236
|
|
|
2247
2237
|
// src/hooks/use-dark-mode.ts
|
|
2248
2238
|
var useDarkMode = () => {
|
|
@@ -2254,9 +2244,9 @@ var useDarkMode = () => {
|
|
|
2254
2244
|
// src/components/chat/PoweredByTag.tsx
|
|
2255
2245
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2256
2246
|
function PoweredByTag({ showPoweredBy = true }) {
|
|
2257
|
-
const [mounted, setMounted] = (0,
|
|
2247
|
+
const [mounted, setMounted] = (0, import_react12.useState)(false);
|
|
2258
2248
|
const isDark = useDarkMode();
|
|
2259
|
-
(0,
|
|
2249
|
+
(0, import_react12.useEffect)(() => {
|
|
2260
2250
|
setMounted(true);
|
|
2261
2251
|
}, []);
|
|
2262
2252
|
if (!showPoweredBy) {
|
|
@@ -2290,8 +2280,8 @@ var Input = ({
|
|
|
2290
2280
|
const copilotContext = (0, import_react_core7.useCopilotContext)();
|
|
2291
2281
|
const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
|
|
2292
2282
|
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
2293
|
-
const textareaRef = (0,
|
|
2294
|
-
const [isComposing, setIsComposing] = (0,
|
|
2283
|
+
const textareaRef = (0, import_react13.useRef)(null);
|
|
2284
|
+
const [isComposing, setIsComposing] = (0, import_react13.useState)(false);
|
|
2295
2285
|
const handleDivClick = (event) => {
|
|
2296
2286
|
var _a2;
|
|
2297
2287
|
const target = event.target;
|
|
@@ -2301,7 +2291,7 @@ var Input = ({
|
|
|
2301
2291
|
return;
|
|
2302
2292
|
(_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
|
|
2303
2293
|
};
|
|
2304
|
-
const [text, setText] = (0,
|
|
2294
|
+
const [text, setText] = (0, import_react13.useState)("");
|
|
2305
2295
|
const send = () => {
|
|
2306
2296
|
var _a2;
|
|
2307
2297
|
if (inProgress)
|
|
@@ -2315,17 +2305,17 @@ var Input = ({
|
|
|
2315
2305
|
inProgress
|
|
2316
2306
|
});
|
|
2317
2307
|
const isInProgress = inProgress || pushToTalkState === "transcribing";
|
|
2318
|
-
const { buttonIcon, buttonAlt } = (0,
|
|
2308
|
+
const { buttonIcon, buttonAlt } = (0, import_react13.useMemo)(() => {
|
|
2319
2309
|
if (!chatReady)
|
|
2320
2310
|
return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
|
|
2321
2311
|
return isInProgress && !hideStopButton && chatReady ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
|
|
2322
2312
|
}, [isInProgress, chatReady, hideStopButton, context.icons.stopIcon, context.icons.sendIcon]);
|
|
2323
2313
|
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
2324
2314
|
const { interrupt } = (0, import_react_core7.useCopilotChatInternal)();
|
|
2325
|
-
const canSend = (0,
|
|
2315
|
+
const canSend = (0, import_react13.useMemo)(() => {
|
|
2326
2316
|
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
|
|
2327
2317
|
}, [interrupt, isInProgress, text, pushToTalkState]);
|
|
2328
|
-
const canStop = (0,
|
|
2318
|
+
const canStop = (0, import_react13.useMemo)(() => {
|
|
2329
2319
|
return isInProgress && !hideStopButton;
|
|
2330
2320
|
}, [isInProgress, hideStopButton]);
|
|
2331
2321
|
const sendDisabled = !canSend && !canStop;
|
|
@@ -2382,7 +2372,7 @@ var Input = ({
|
|
|
2382
2372
|
};
|
|
2383
2373
|
|
|
2384
2374
|
// src/components/chat/Chat.tsx
|
|
2385
|
-
var
|
|
2375
|
+
var import_react14 = __toESM(require("react"));
|
|
2386
2376
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2387
2377
|
var import_shared3 = require("@copilotkit/shared");
|
|
2388
2378
|
|
|
@@ -2559,13 +2549,13 @@ function CopilotChat({
|
|
|
2559
2549
|
removeInternalErrorHandler
|
|
2560
2550
|
} = (0, import_react_core9.useCopilotContext)();
|
|
2561
2551
|
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
2562
|
-
const [selectedImages, setSelectedImages] = (0,
|
|
2563
|
-
const [chatError, setChatError] = (0,
|
|
2564
|
-
const [messageFeedback, setMessageFeedback] = (0,
|
|
2552
|
+
const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
|
|
2553
|
+
const [chatError, setChatError] = (0, import_react14.useState)(null);
|
|
2554
|
+
const [messageFeedback, setMessageFeedback] = (0, import_react14.useState)(
|
|
2565
2555
|
{}
|
|
2566
2556
|
);
|
|
2567
|
-
const fileInputRef = (0,
|
|
2568
|
-
const triggerObservabilityHook = (0,
|
|
2557
|
+
const fileInputRef = (0, import_react14.useRef)(null);
|
|
2558
|
+
const triggerObservabilityHook = (0, import_react14.useCallback)(
|
|
2569
2559
|
(hookName, ...args) => {
|
|
2570
2560
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2571
2561
|
observabilityHooks[hookName](...args);
|
|
@@ -2584,7 +2574,7 @@ function CopilotChat({
|
|
|
2584
2574
|
},
|
|
2585
2575
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2586
2576
|
);
|
|
2587
|
-
const triggerChatError = (0,
|
|
2577
|
+
const triggerChatError = (0, import_react14.useCallback)(
|
|
2588
2578
|
(error, operation, originalError) => {
|
|
2589
2579
|
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
|
|
2590
2580
|
setChatError({
|
|
@@ -2630,7 +2620,7 @@ function CopilotChat({
|
|
|
2630
2620
|
},
|
|
2631
2621
|
[publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
|
|
2632
2622
|
);
|
|
2633
|
-
(0,
|
|
2623
|
+
(0, import_react14.useEffect)(() => {
|
|
2634
2624
|
const id = "chat-component";
|
|
2635
2625
|
setInternalErrorHandler({
|
|
2636
2626
|
[id]: (error) => {
|
|
@@ -2643,7 +2633,7 @@ function CopilotChat({
|
|
|
2643
2633
|
removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
|
|
2644
2634
|
};
|
|
2645
2635
|
}, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
|
|
2646
|
-
(0,
|
|
2636
|
+
(0, import_react14.useEffect)(() => {
|
|
2647
2637
|
if (!imageUploadsEnabled)
|
|
2648
2638
|
return;
|
|
2649
2639
|
const handlePaste = (e) => __async(this, null, function* () {
|
|
@@ -2689,7 +2679,7 @@ function CopilotChat({
|
|
|
2689
2679
|
document.addEventListener("paste", handlePaste);
|
|
2690
2680
|
return () => document.removeEventListener("paste", handlePaste);
|
|
2691
2681
|
}, [imageUploadsEnabled, triggerChatError]);
|
|
2692
|
-
(0,
|
|
2682
|
+
(0, import_react14.useEffect)(() => {
|
|
2693
2683
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
2694
2684
|
setChatInstructions(instructions || "");
|
|
2695
2685
|
return;
|
|
@@ -2717,8 +2707,8 @@ function CopilotChat({
|
|
|
2717
2707
|
onStopGeneration,
|
|
2718
2708
|
onReloadMessages
|
|
2719
2709
|
});
|
|
2720
|
-
const prevIsLoading = (0,
|
|
2721
|
-
(0,
|
|
2710
|
+
const prevIsLoading = (0, import_react14.useRef)(isLoading);
|
|
2711
|
+
(0, import_react14.useEffect)(() => {
|
|
2722
2712
|
if (prevIsLoading.current !== isLoading) {
|
|
2723
2713
|
if (isLoading) {
|
|
2724
2714
|
triggerObservabilityHook("onChatStarted");
|
|
@@ -2741,7 +2731,7 @@ function CopilotChat({
|
|
|
2741
2731
|
role: "user"
|
|
2742
2732
|
});
|
|
2743
2733
|
};
|
|
2744
|
-
const chatContext =
|
|
2734
|
+
const chatContext = import_react14.default.useContext(ChatContext);
|
|
2745
2735
|
const isVisible = chatContext ? chatContext.open : true;
|
|
2746
2736
|
const handleRegenerate = (messageId) => {
|
|
2747
2737
|
if (onRegenerate) {
|
|
@@ -2885,7 +2875,7 @@ function WrappedCopilotChat({
|
|
|
2885
2875
|
labels,
|
|
2886
2876
|
className
|
|
2887
2877
|
}) {
|
|
2888
|
-
const chatContext =
|
|
2878
|
+
const chatContext = import_react14.default.useContext(ChatContext);
|
|
2889
2879
|
if (!chatContext) {
|
|
2890
2880
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
2891
2881
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
|
|
@@ -2923,7 +2913,7 @@ var CopilotModalInner = (_a) => {
|
|
|
2923
2913
|
]);
|
|
2924
2914
|
const { copilotApiConfig, setBannerError } = (0, import_react_core10.useCopilotContext)();
|
|
2925
2915
|
const { publicApiKey } = copilotApiConfig;
|
|
2926
|
-
const triggerObservabilityHook = (0,
|
|
2916
|
+
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2927
2917
|
(hookName, ...args) => {
|
|
2928
2918
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2929
2919
|
observabilityHooks[hookName](...args);
|
|
@@ -2943,8 +2933,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2943
2933
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2944
2934
|
);
|
|
2945
2935
|
const { open } = useChatContext();
|
|
2946
|
-
const prevOpen = (0,
|
|
2947
|
-
(0,
|
|
2936
|
+
const prevOpen = (0, import_react15.useRef)(open);
|
|
2937
|
+
(0, import_react15.useEffect)(() => {
|
|
2948
2938
|
if (prevOpen.current !== open) {
|
|
2949
2939
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2950
2940
|
if (open) {
|
|
@@ -2955,8 +2945,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2955
2945
|
prevOpen.current = open;
|
|
2956
2946
|
}
|
|
2957
2947
|
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
2958
|
-
const memoizedHeader = (0,
|
|
2959
|
-
const memoizedChildren = (0,
|
|
2948
|
+
const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}), [Header2]);
|
|
2949
|
+
const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
|
|
2960
2950
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
2961
2951
|
memoizedChildren,
|
|
2962
2952
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className, children: [
|
|
@@ -3036,7 +3026,7 @@ var CopilotModal = (_a) => {
|
|
|
3036
3026
|
"children",
|
|
3037
3027
|
"observabilityHooks"
|
|
3038
3028
|
]);
|
|
3039
|
-
const [openState, setOpenState] =
|
|
3029
|
+
const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
|
|
3040
3030
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3041
3031
|
CopilotModalInner,
|
|
3042
3032
|
__spreadProps(__spreadValues({
|