@copilotkit/react-ui 1.51.3-next.5 → 1.51.3-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/{chunk-O4PPO3K3.mjs → chunk-7CMZ7YPQ.mjs} +2 -2
- package/dist/{chunk-PKSW6ZMQ.mjs → chunk-F2CDEOFX.mjs} +2 -2
- package/dist/{chunk-XOBQLKUU.mjs → chunk-JZ3RFQQ6.mjs} +13 -3
- package/dist/chunk-JZ3RFQQ6.mjs.map +1 -0
- package/dist/{chunk-XEZ5ODJS.mjs → chunk-LBR23XXF.mjs} +2 -2
- package/dist/{chunk-SLM2AOHF.mjs → chunk-LYYDXL2G.mjs} +9 -5
- package/dist/chunk-LYYDXL2G.mjs.map +1 -0
- package/dist/{chunk-HKZL4P3F.mjs → chunk-OHGUQZJT.mjs} +4 -4
- package/dist/{chunk-YQOESY4Y.mjs → chunk-PD36EMOZ.mjs} +4 -4
- package/dist/{chunk-4S4ZEKE6.mjs → chunk-RKQM2AE5.mjs} +2 -2
- package/dist/{chunk-UH5GQ7QF.mjs → chunk-WNX755OE.mjs} +2 -2
- package/dist/components/chat/Chat.js +74 -60
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +6 -6
- package/dist/components/chat/Markdown.d.ts +2 -4
- package/dist/components/chat/Markdown.js +12 -2
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +1 -1
- package/dist/components/chat/Messages.js +34 -20
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +5 -5
- package/dist/components/chat/Modal.js +81 -67
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +7 -7
- package/dist/components/chat/Popup.js +81 -67
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +8 -8
- package/dist/components/chat/Sidebar.js +83 -69
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +8 -8
- package/dist/components/chat/index.d.ts +1 -1
- package/dist/components/chat/index.js +83 -69
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +9 -9
- package/dist/components/chat/messages/AssistantMessage.js +21 -7
- package/dist/components/chat/messages/AssistantMessage.js.map +1 -1
- package/dist/components/chat/messages/AssistantMessage.mjs +2 -2
- package/dist/components/chat/messages/ErrorMessage.js +14 -4
- package/dist/components/chat/messages/ErrorMessage.js.map +1 -1
- package/dist/components/chat/messages/ErrorMessage.mjs +1 -1
- package/dist/components/chat/messages/LegacyRenderMessage.js +23 -9
- package/dist/components/chat/messages/LegacyRenderMessage.js.map +1 -1
- package/dist/components/chat/messages/LegacyRenderMessage.mjs +4 -4
- package/dist/components/chat/messages/RenderMessage.js +23 -9
- package/dist/components/chat/messages/RenderMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderMessage.mjs +3 -3
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +83 -69
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +83 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -9
- package/package.json +8 -5
- package/src/components/chat/Markdown.tsx +17 -8
- package/src/components/chat/messages/AssistantMessage.tsx +6 -2
- package/dist/chunk-SLM2AOHF.mjs.map +0 -1
- package/dist/chunk-XOBQLKUU.mjs.map +0 -1
- /package/dist/{chunk-O4PPO3K3.mjs.map → chunk-7CMZ7YPQ.mjs.map} +0 -0
- /package/dist/{chunk-PKSW6ZMQ.mjs.map → chunk-F2CDEOFX.mjs.map} +0 -0
- /package/dist/{chunk-XEZ5ODJS.mjs.map → chunk-LBR23XXF.mjs.map} +0 -0
- /package/dist/{chunk-HKZL4P3F.mjs.map → chunk-OHGUQZJT.mjs.map} +0 -0
- /package/dist/{chunk-YQOESY4Y.mjs.map → chunk-PD36EMOZ.mjs.map} +0 -0
- /package/dist/{chunk-4S4ZEKE6.mjs.map → chunk-RKQM2AE5.mjs.map} +0 -0
- /package/dist/{chunk-UH5GQ7QF.mjs.map → chunk-WNX755OE.mjs.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotPopup
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-7CMZ7YPQ.mjs";
|
|
4
|
+
import "../../chunk-OHGUQZJT.mjs";
|
|
5
5
|
import "../../chunk-C3GSYRC3.mjs";
|
|
6
6
|
import "../../chunk-GDSZGYCE.mjs";
|
|
7
7
|
import "../../chunk-V7W6IM2V.mjs";
|
|
@@ -12,20 +12,20 @@ import "../../chunk-KXE2JCUH.mjs";
|
|
|
12
12
|
import "../../chunk-NRA3CFEE.mjs";
|
|
13
13
|
import "../../chunk-BH6PCAAL.mjs";
|
|
14
14
|
import "../../chunk-UFN2VWSR.mjs";
|
|
15
|
-
import "../../chunk-
|
|
15
|
+
import "../../chunk-PD36EMOZ.mjs";
|
|
16
16
|
import "../../chunk-VHKHX7GV.mjs";
|
|
17
17
|
import "../../chunk-6TWQUA2Q.mjs";
|
|
18
18
|
import "../../chunk-PLHTVHUW.mjs";
|
|
19
19
|
import "../../chunk-3W6J75HS.mjs";
|
|
20
20
|
import "../../chunk-ELGRNEAO.mjs";
|
|
21
21
|
import "../../chunk-QIOJXTIQ.mjs";
|
|
22
|
-
import "../../chunk-
|
|
23
|
-
import "../../chunk-
|
|
24
|
-
import "../../chunk-
|
|
25
|
-
import "../../chunk-
|
|
22
|
+
import "../../chunk-WNX755OE.mjs";
|
|
23
|
+
import "../../chunk-F2CDEOFX.mjs";
|
|
24
|
+
import "../../chunk-LBR23XXF.mjs";
|
|
25
|
+
import "../../chunk-LYYDXL2G.mjs";
|
|
26
26
|
import "../../chunk-DBKRAOH7.mjs";
|
|
27
27
|
import "../../chunk-RYUCX3ZK.mjs";
|
|
28
|
-
import "../../chunk-
|
|
28
|
+
import "../../chunk-JZ3RFQQ6.mjs";
|
|
29
29
|
import "../../chunk-IK2BPURM.mjs";
|
|
30
30
|
import "../../chunk-IEMQ2SQW.mjs";
|
|
31
31
|
import "../../chunk-XWG3L6QC.mjs";
|
|
@@ -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_react17 = require("react");
|
|
86
86
|
|
|
87
87
|
// src/components/chat/Modal.tsx
|
|
88
|
-
var
|
|
88
|
+
var import_react16 = __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_react10 = require("react");
|
|
1030
1030
|
var import_react_core5 = require("@copilotkit/react-core");
|
|
1031
1031
|
|
|
1032
1032
|
// src/components/chat/messages/UserMessage.tsx
|
|
@@ -1058,7 +1058,8 @@ var UserMessage = (props) => {
|
|
|
1058
1058
|
};
|
|
1059
1059
|
|
|
1060
1060
|
// src/components/chat/Markdown.tsx
|
|
1061
|
-
var
|
|
1061
|
+
var import_react7 = require("react");
|
|
1062
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1062
1063
|
|
|
1063
1064
|
// src/components/chat/CodeBlock.tsx
|
|
1064
1065
|
var import_react6 = require("react");
|
|
@@ -1470,6 +1471,9 @@ var highlightStyle = {
|
|
|
1470
1471
|
};
|
|
1471
1472
|
|
|
1472
1473
|
// 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"));
|
|
1473
1477
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1474
1478
|
var defaultComponents = {
|
|
1475
1479
|
a(_a) {
|
|
@@ -1563,21 +1567,27 @@ var defaultComponents = {
|
|
|
1563
1567
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
|
|
1564
1568
|
}
|
|
1565
1569
|
};
|
|
1570
|
+
var MemoizedReactMarkdown = (0, import_react7.memo)(
|
|
1571
|
+
import_react_markdown.default,
|
|
1572
|
+
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
|
|
1573
|
+
);
|
|
1566
1574
|
var Markdown = ({ content, components }) => {
|
|
1567
1575
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1568
|
-
|
|
1576
|
+
MemoizedReactMarkdown,
|
|
1569
1577
|
{
|
|
1570
1578
|
components: __spreadValues(__spreadValues({}, defaultComponents), components),
|
|
1579
|
+
remarkPlugins: [import_remark_gfm.default, [import_remark_math.default, { singleDollarTextMath: false }]],
|
|
1580
|
+
rehypePlugins: [import_rehype_raw.default],
|
|
1571
1581
|
children: content
|
|
1572
1582
|
}
|
|
1573
1583
|
) });
|
|
1574
1584
|
};
|
|
1575
1585
|
|
|
1576
1586
|
// src/components/chat/messages/AssistantMessage.tsx
|
|
1577
|
-
var
|
|
1587
|
+
var import_react8 = require("react");
|
|
1578
1588
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1579
1589
|
var AssistantMessage = (props) => {
|
|
1580
|
-
var _a;
|
|
1590
|
+
var _a, _b, _c;
|
|
1581
1591
|
const { icons, labels } = useChatContext();
|
|
1582
1592
|
const {
|
|
1583
1593
|
message,
|
|
@@ -1590,7 +1600,7 @@ var AssistantMessage = (props) => {
|
|
|
1590
1600
|
feedback,
|
|
1591
1601
|
markdownTagRenderers
|
|
1592
1602
|
} = props;
|
|
1593
|
-
const [copied, setCopied] = (0,
|
|
1603
|
+
const [copied, setCopied] = (0, import_react8.useState)(false);
|
|
1594
1604
|
const handleCopy = () => {
|
|
1595
1605
|
const content2 = (message == null ? void 0 : message.content) || "";
|
|
1596
1606
|
if (content2 && onCopy) {
|
|
@@ -1620,8 +1630,12 @@ var AssistantMessage = (props) => {
|
|
|
1620
1630
|
};
|
|
1621
1631
|
const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: icons.activityIcon });
|
|
1622
1632
|
const content = (message == null ? void 0 : message.content) || "";
|
|
1623
|
-
const subComponent = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message);
|
|
1633
|
+
const subComponent = (_b = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message)) != null ? _b : props.subComponent;
|
|
1634
|
+
const subComponentPosition = (_c = message == null ? void 0 : message.generativeUIPosition) != null ? _c : "after";
|
|
1635
|
+
const renderBefore = subComponent && subComponentPosition === "before";
|
|
1636
|
+
const renderAfter = subComponent && subComponentPosition !== "before";
|
|
1624
1637
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
1638
|
+
renderBefore ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }) : null,
|
|
1625
1639
|
content && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
|
|
1626
1640
|
content && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Markdown, { content, components: markdownTagRenderers }),
|
|
1627
1641
|
content && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
@@ -1673,16 +1687,16 @@ var AssistantMessage = (props) => {
|
|
|
1673
1687
|
}
|
|
1674
1688
|
)
|
|
1675
1689
|
] }),
|
|
1676
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }),
|
|
1690
|
+
renderAfter ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }) : null,
|
|
1677
1691
|
isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(LoadingIcon, {})
|
|
1678
1692
|
] });
|
|
1679
1693
|
};
|
|
1680
1694
|
|
|
1681
1695
|
// src/components/chat/messages/ImageRenderer.tsx
|
|
1682
|
-
var
|
|
1696
|
+
var import_react9 = require("react");
|
|
1683
1697
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1684
1698
|
var ImageRenderer = ({ image, content, className = "" }) => {
|
|
1685
|
-
const [imageError, setImageError] = (0,
|
|
1699
|
+
const [imageError, setImageError] = (0, import_react9.useState)(false);
|
|
1686
1700
|
const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
|
|
1687
1701
|
const altText = content || "User uploaded image";
|
|
1688
1702
|
const handleImageError = () => {
|
|
@@ -1925,18 +1939,18 @@ var Messages = ({
|
|
|
1925
1939
|
var _a;
|
|
1926
1940
|
const { labels, icons } = useChatContext();
|
|
1927
1941
|
const { messages: visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
|
|
1928
|
-
const initialMessages = (0,
|
|
1942
|
+
const initialMessages = (0, import_react10.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
|
|
1929
1943
|
const messages = [...initialMessages, ...visibleMessages];
|
|
1930
1944
|
const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
|
|
1931
1945
|
const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
|
|
1932
|
-
(0,
|
|
1946
|
+
(0, import_react10.useEffect)(() => {
|
|
1933
1947
|
if (hasLegacyProps) {
|
|
1934
1948
|
console.warn(
|
|
1935
1949
|
"[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"
|
|
1936
1950
|
);
|
|
1937
1951
|
}
|
|
1938
1952
|
}, [hasLegacyProps]);
|
|
1939
|
-
const legacyProps = (0,
|
|
1953
|
+
const legacyProps = (0, import_react10.useMemo)(
|
|
1940
1954
|
() => ({
|
|
1941
1955
|
RenderTextMessage,
|
|
1942
1956
|
RenderActionExecutionMessage,
|
|
@@ -2007,10 +2021,10 @@ function makeInitialMessages(initial) {
|
|
|
2007
2021
|
];
|
|
2008
2022
|
}
|
|
2009
2023
|
function useScrollToBottom(messages) {
|
|
2010
|
-
const messagesEndRef = (0,
|
|
2011
|
-
const messagesContainerRef = (0,
|
|
2012
|
-
const isProgrammaticScrollRef = (0,
|
|
2013
|
-
const isUserScrollUpRef = (0,
|
|
2024
|
+
const messagesEndRef = (0, import_react10.useRef)(null);
|
|
2025
|
+
const messagesContainerRef = (0, import_react10.useRef)(null);
|
|
2026
|
+
const isProgrammaticScrollRef = (0, import_react10.useRef)(false);
|
|
2027
|
+
const isUserScrollUpRef = (0, import_react10.useRef)(false);
|
|
2014
2028
|
const scrollToBottom = () => {
|
|
2015
2029
|
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
2016
2030
|
isProgrammaticScrollRef.current = true;
|
|
@@ -2027,7 +2041,7 @@ function useScrollToBottom(messages) {
|
|
|
2027
2041
|
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
2028
2042
|
}
|
|
2029
2043
|
};
|
|
2030
|
-
(0,
|
|
2044
|
+
(0, import_react10.useEffect)(() => {
|
|
2031
2045
|
const container = messagesContainerRef.current;
|
|
2032
2046
|
if (container) {
|
|
2033
2047
|
container.addEventListener("scroll", handleScroll);
|
|
@@ -2038,7 +2052,7 @@ function useScrollToBottom(messages) {
|
|
|
2038
2052
|
}
|
|
2039
2053
|
};
|
|
2040
2054
|
}, []);
|
|
2041
|
-
(0,
|
|
2055
|
+
(0, import_react10.useEffect)(() => {
|
|
2042
2056
|
const container = messagesContainerRef.current;
|
|
2043
2057
|
if (!container) {
|
|
2044
2058
|
return;
|
|
@@ -2057,7 +2071,7 @@ function useScrollToBottom(messages) {
|
|
|
2057
2071
|
mutationObserver.disconnect();
|
|
2058
2072
|
};
|
|
2059
2073
|
}, []);
|
|
2060
|
-
(0,
|
|
2074
|
+
(0, import_react10.useEffect)(() => {
|
|
2061
2075
|
isUserScrollUpRef.current = false;
|
|
2062
2076
|
scrollToBottom();
|
|
2063
2077
|
}, [messages.filter((m) => m.role === "user").length]);
|
|
@@ -2065,12 +2079,12 @@ function useScrollToBottom(messages) {
|
|
|
2065
2079
|
}
|
|
2066
2080
|
|
|
2067
2081
|
// src/components/chat/Input.tsx
|
|
2068
|
-
var
|
|
2082
|
+
var import_react14 = require("react");
|
|
2069
2083
|
|
|
2070
2084
|
// src/components/chat/Textarea.tsx
|
|
2071
|
-
var
|
|
2085
|
+
var import_react11 = require("react");
|
|
2072
2086
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2073
|
-
var AutoResizingTextarea = (0,
|
|
2087
|
+
var AutoResizingTextarea = (0, import_react11.forwardRef)(
|
|
2074
2088
|
({
|
|
2075
2089
|
maxRows = 1,
|
|
2076
2090
|
placeholder,
|
|
@@ -2081,10 +2095,10 @@ var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
|
2081
2095
|
onCompositionEnd,
|
|
2082
2096
|
autoFocus
|
|
2083
2097
|
}, ref) => {
|
|
2084
|
-
const internalTextareaRef = (0,
|
|
2085
|
-
const [maxHeight, setMaxHeight] = (0,
|
|
2086
|
-
(0,
|
|
2087
|
-
(0,
|
|
2098
|
+
const internalTextareaRef = (0, import_react11.useRef)(null);
|
|
2099
|
+
const [maxHeight, setMaxHeight] = (0, import_react11.useState)(0);
|
|
2100
|
+
(0, import_react11.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
2101
|
+
(0, import_react11.useEffect)(() => {
|
|
2088
2102
|
const calculateMaxHeight = () => {
|
|
2089
2103
|
const textarea = internalTextareaRef.current;
|
|
2090
2104
|
if (textarea) {
|
|
@@ -2098,7 +2112,7 @@ var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
|
2098
2112
|
};
|
|
2099
2113
|
calculateMaxHeight();
|
|
2100
2114
|
}, [maxRows]);
|
|
2101
|
-
(0,
|
|
2115
|
+
(0, import_react11.useEffect)(() => {
|
|
2102
2116
|
const textarea = internalTextareaRef.current;
|
|
2103
2117
|
if (textarea) {
|
|
2104
2118
|
textarea.style.height = "auto";
|
|
@@ -2130,7 +2144,7 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
2130
2144
|
// src/hooks/use-push-to-talk.tsx
|
|
2131
2145
|
var import_react_core6 = require("@copilotkit/react-core");
|
|
2132
2146
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
2133
|
-
var
|
|
2147
|
+
var import_react12 = require("react");
|
|
2134
2148
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
2135
2149
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
2136
2150
|
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
@@ -2179,16 +2193,16 @@ var usePushToTalk = ({
|
|
|
2179
2193
|
sendFunction,
|
|
2180
2194
|
inProgress
|
|
2181
2195
|
}) => {
|
|
2182
|
-
const [pushToTalkState, setPushToTalkState] = (0,
|
|
2183
|
-
const mediaStreamRef = (0,
|
|
2184
|
-
const audioContextRef = (0,
|
|
2185
|
-
const mediaRecorderRef = (0,
|
|
2186
|
-
const recordedChunks = (0,
|
|
2196
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react12.useState)("idle");
|
|
2197
|
+
const mediaStreamRef = (0, import_react12.useRef)(null);
|
|
2198
|
+
const audioContextRef = (0, import_react12.useRef)(null);
|
|
2199
|
+
const mediaRecorderRef = (0, import_react12.useRef)(null);
|
|
2200
|
+
const recordedChunks = (0, import_react12.useRef)([]);
|
|
2187
2201
|
const generalContext = (0, import_react_core6.useCopilotContext)();
|
|
2188
2202
|
const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
|
|
2189
2203
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2190
|
-
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0,
|
|
2191
|
-
(0,
|
|
2204
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react12.useState)(null);
|
|
2205
|
+
(0, import_react12.useEffect)(() => {
|
|
2192
2206
|
if (pushToTalkState === "recording") {
|
|
2193
2207
|
startRecording(
|
|
2194
2208
|
mediaStreamRef,
|
|
@@ -2216,7 +2230,7 @@ var usePushToTalk = ({
|
|
|
2216
2230
|
stopRecording(mediaRecorderRef);
|
|
2217
2231
|
};
|
|
2218
2232
|
}, [pushToTalkState]);
|
|
2219
|
-
(0,
|
|
2233
|
+
(0, import_react12.useEffect)(() => {
|
|
2220
2234
|
if (inProgress === false && startReadingFromMessageId) {
|
|
2221
2235
|
const lastMessageIndex = context.messages.findIndex(
|
|
2222
2236
|
(message) => message.id === startReadingFromMessageId
|
|
@@ -2235,7 +2249,7 @@ var usePushToTalk = ({
|
|
|
2235
2249
|
var import_react_core7 = require("@copilotkit/react-core");
|
|
2236
2250
|
|
|
2237
2251
|
// src/components/chat/PoweredByTag.tsx
|
|
2238
|
-
var
|
|
2252
|
+
var import_react13 = require("react");
|
|
2239
2253
|
|
|
2240
2254
|
// src/hooks/use-dark-mode.ts
|
|
2241
2255
|
var useDarkMode = () => {
|
|
@@ -2247,9 +2261,9 @@ var useDarkMode = () => {
|
|
|
2247
2261
|
// src/components/chat/PoweredByTag.tsx
|
|
2248
2262
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2249
2263
|
function PoweredByTag({ showPoweredBy = true }) {
|
|
2250
|
-
const [mounted, setMounted] = (0,
|
|
2264
|
+
const [mounted, setMounted] = (0, import_react13.useState)(false);
|
|
2251
2265
|
const isDark = useDarkMode();
|
|
2252
|
-
(0,
|
|
2266
|
+
(0, import_react13.useEffect)(() => {
|
|
2253
2267
|
setMounted(true);
|
|
2254
2268
|
}, []);
|
|
2255
2269
|
if (!showPoweredBy) {
|
|
@@ -2283,8 +2297,8 @@ var Input = ({
|
|
|
2283
2297
|
const copilotContext = (0, import_react_core7.useCopilotContext)();
|
|
2284
2298
|
const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
|
|
2285
2299
|
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
2286
|
-
const textareaRef = (0,
|
|
2287
|
-
const [isComposing, setIsComposing] = (0,
|
|
2300
|
+
const textareaRef = (0, import_react14.useRef)(null);
|
|
2301
|
+
const [isComposing, setIsComposing] = (0, import_react14.useState)(false);
|
|
2288
2302
|
const handleDivClick = (event) => {
|
|
2289
2303
|
var _a2;
|
|
2290
2304
|
const target = event.target;
|
|
@@ -2294,7 +2308,7 @@ var Input = ({
|
|
|
2294
2308
|
return;
|
|
2295
2309
|
(_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
|
|
2296
2310
|
};
|
|
2297
|
-
const [text, setText] = (0,
|
|
2311
|
+
const [text, setText] = (0, import_react14.useState)("");
|
|
2298
2312
|
const send = () => {
|
|
2299
2313
|
var _a2;
|
|
2300
2314
|
if (inProgress)
|
|
@@ -2308,17 +2322,17 @@ var Input = ({
|
|
|
2308
2322
|
inProgress
|
|
2309
2323
|
});
|
|
2310
2324
|
const isInProgress = inProgress || pushToTalkState === "transcribing";
|
|
2311
|
-
const { buttonIcon, buttonAlt } = (0,
|
|
2325
|
+
const { buttonIcon, buttonAlt } = (0, import_react14.useMemo)(() => {
|
|
2312
2326
|
if (!chatReady)
|
|
2313
2327
|
return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
|
|
2314
2328
|
return isInProgress && !hideStopButton && chatReady ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
|
|
2315
2329
|
}, [isInProgress, chatReady, hideStopButton, context.icons.stopIcon, context.icons.sendIcon]);
|
|
2316
2330
|
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
2317
2331
|
const { interrupt } = (0, import_react_core7.useCopilotChatInternal)();
|
|
2318
|
-
const canSend = (0,
|
|
2332
|
+
const canSend = (0, import_react14.useMemo)(() => {
|
|
2319
2333
|
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
|
|
2320
2334
|
}, [interrupt, isInProgress, text, pushToTalkState]);
|
|
2321
|
-
const canStop = (0,
|
|
2335
|
+
const canStop = (0, import_react14.useMemo)(() => {
|
|
2322
2336
|
return isInProgress && !hideStopButton;
|
|
2323
2337
|
}, [isInProgress, hideStopButton]);
|
|
2324
2338
|
const sendDisabled = !canSend && !canStop;
|
|
@@ -2375,7 +2389,7 @@ var Input = ({
|
|
|
2375
2389
|
};
|
|
2376
2390
|
|
|
2377
2391
|
// src/components/chat/Chat.tsx
|
|
2378
|
-
var
|
|
2392
|
+
var import_react15 = __toESM(require("react"));
|
|
2379
2393
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2380
2394
|
var import_shared3 = require("@copilotkit/shared");
|
|
2381
2395
|
|
|
@@ -2552,13 +2566,13 @@ function CopilotChat({
|
|
|
2552
2566
|
removeInternalErrorHandler
|
|
2553
2567
|
} = (0, import_react_core9.useCopilotContext)();
|
|
2554
2568
|
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
2555
|
-
const [selectedImages, setSelectedImages] = (0,
|
|
2556
|
-
const [chatError, setChatError] = (0,
|
|
2557
|
-
const [messageFeedback, setMessageFeedback] = (0,
|
|
2569
|
+
const [selectedImages, setSelectedImages] = (0, import_react15.useState)([]);
|
|
2570
|
+
const [chatError, setChatError] = (0, import_react15.useState)(null);
|
|
2571
|
+
const [messageFeedback, setMessageFeedback] = (0, import_react15.useState)(
|
|
2558
2572
|
{}
|
|
2559
2573
|
);
|
|
2560
|
-
const fileInputRef = (0,
|
|
2561
|
-
const triggerObservabilityHook = (0,
|
|
2574
|
+
const fileInputRef = (0, import_react15.useRef)(null);
|
|
2575
|
+
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2562
2576
|
(hookName, ...args) => {
|
|
2563
2577
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2564
2578
|
observabilityHooks[hookName](...args);
|
|
@@ -2577,7 +2591,7 @@ function CopilotChat({
|
|
|
2577
2591
|
},
|
|
2578
2592
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2579
2593
|
);
|
|
2580
|
-
const triggerChatError = (0,
|
|
2594
|
+
const triggerChatError = (0, import_react15.useCallback)(
|
|
2581
2595
|
(error, operation, originalError) => {
|
|
2582
2596
|
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
|
|
2583
2597
|
setChatError({
|
|
@@ -2623,7 +2637,7 @@ function CopilotChat({
|
|
|
2623
2637
|
},
|
|
2624
2638
|
[publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
|
|
2625
2639
|
);
|
|
2626
|
-
(0,
|
|
2640
|
+
(0, import_react15.useEffect)(() => {
|
|
2627
2641
|
const id = "chat-component";
|
|
2628
2642
|
setInternalErrorHandler({
|
|
2629
2643
|
[id]: (error) => {
|
|
@@ -2636,7 +2650,7 @@ function CopilotChat({
|
|
|
2636
2650
|
removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
|
|
2637
2651
|
};
|
|
2638
2652
|
}, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
|
|
2639
|
-
(0,
|
|
2653
|
+
(0, import_react15.useEffect)(() => {
|
|
2640
2654
|
if (!imageUploadsEnabled)
|
|
2641
2655
|
return;
|
|
2642
2656
|
const handlePaste = (e) => __async(this, null, function* () {
|
|
@@ -2682,7 +2696,7 @@ function CopilotChat({
|
|
|
2682
2696
|
document.addEventListener("paste", handlePaste);
|
|
2683
2697
|
return () => document.removeEventListener("paste", handlePaste);
|
|
2684
2698
|
}, [imageUploadsEnabled, triggerChatError]);
|
|
2685
|
-
(0,
|
|
2699
|
+
(0, import_react15.useEffect)(() => {
|
|
2686
2700
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
2687
2701
|
setChatInstructions(instructions || "");
|
|
2688
2702
|
return;
|
|
@@ -2710,8 +2724,8 @@ function CopilotChat({
|
|
|
2710
2724
|
onStopGeneration,
|
|
2711
2725
|
onReloadMessages
|
|
2712
2726
|
});
|
|
2713
|
-
const prevIsLoading = (0,
|
|
2714
|
-
(0,
|
|
2727
|
+
const prevIsLoading = (0, import_react15.useRef)(isLoading);
|
|
2728
|
+
(0, import_react15.useEffect)(() => {
|
|
2715
2729
|
if (prevIsLoading.current !== isLoading) {
|
|
2716
2730
|
if (isLoading) {
|
|
2717
2731
|
triggerObservabilityHook("onChatStarted");
|
|
@@ -2734,7 +2748,7 @@ function CopilotChat({
|
|
|
2734
2748
|
role: "user"
|
|
2735
2749
|
});
|
|
2736
2750
|
};
|
|
2737
|
-
const chatContext =
|
|
2751
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2738
2752
|
const isVisible = chatContext ? chatContext.open : true;
|
|
2739
2753
|
const handleRegenerate = (messageId) => {
|
|
2740
2754
|
if (onRegenerate) {
|
|
@@ -2878,7 +2892,7 @@ function WrappedCopilotChat({
|
|
|
2878
2892
|
labels,
|
|
2879
2893
|
className
|
|
2880
2894
|
}) {
|
|
2881
|
-
const chatContext =
|
|
2895
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2882
2896
|
if (!chatContext) {
|
|
2883
2897
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
2884
2898
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
|
|
@@ -2916,7 +2930,7 @@ var CopilotModalInner = (_a) => {
|
|
|
2916
2930
|
]);
|
|
2917
2931
|
const { copilotApiConfig, setBannerError } = (0, import_react_core10.useCopilotContext)();
|
|
2918
2932
|
const { publicApiKey } = copilotApiConfig;
|
|
2919
|
-
const triggerObservabilityHook = (0,
|
|
2933
|
+
const triggerObservabilityHook = (0, import_react16.useCallback)(
|
|
2920
2934
|
(hookName, ...args) => {
|
|
2921
2935
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2922
2936
|
observabilityHooks[hookName](...args);
|
|
@@ -2936,8 +2950,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2936
2950
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2937
2951
|
);
|
|
2938
2952
|
const { open } = useChatContext();
|
|
2939
|
-
const prevOpen = (0,
|
|
2940
|
-
(0,
|
|
2953
|
+
const prevOpen = (0, import_react16.useRef)(open);
|
|
2954
|
+
(0, import_react16.useEffect)(() => {
|
|
2941
2955
|
if (prevOpen.current !== open) {
|
|
2942
2956
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2943
2957
|
if (open) {
|
|
@@ -2948,8 +2962,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2948
2962
|
prevOpen.current = open;
|
|
2949
2963
|
}
|
|
2950
2964
|
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
2951
|
-
const memoizedHeader = (0,
|
|
2952
|
-
const memoizedChildren = (0,
|
|
2965
|
+
const memoizedHeader = (0, import_react16.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}), [Header2]);
|
|
2966
|
+
const memoizedChildren = (0, import_react16.useMemo)(() => children, [children]);
|
|
2953
2967
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
2954
2968
|
memoizedChildren,
|
|
2955
2969
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className, children: [
|
|
@@ -3029,7 +3043,7 @@ var CopilotModal = (_a) => {
|
|
|
3029
3043
|
"children",
|
|
3030
3044
|
"observabilityHooks"
|
|
3031
3045
|
]);
|
|
3032
|
-
const [openState, setOpenState] =
|
|
3046
|
+
const [openState, setOpenState] = import_react16.default.useState(defaultOpen);
|
|
3033
3047
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3034
3048
|
CopilotModalInner,
|
|
3035
3049
|
__spreadProps(__spreadValues({
|
|
@@ -3069,7 +3083,7 @@ function CopilotSidebar(props) {
|
|
|
3069
3083
|
props = __spreadProps(__spreadValues({}, props), {
|
|
3070
3084
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
3071
3085
|
});
|
|
3072
|
-
const [expandedClassName, setExpandedClassName] = (0,
|
|
3086
|
+
const [expandedClassName, setExpandedClassName] = (0, import_react17.useState)(
|
|
3073
3087
|
props.defaultOpen ? "sidebarExpanded" : ""
|
|
3074
3088
|
);
|
|
3075
3089
|
const onSetOpen = (open) => {
|