@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
|
@@ -3,11 +3,11 @@ import "../chunk-SC6JRFAJ.mjs";
|
|
|
3
3
|
import "../chunk-WB3YULQ4.mjs";
|
|
4
4
|
import {
|
|
5
5
|
CopilotPopup
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-7CMZ7YPQ.mjs";
|
|
7
7
|
import {
|
|
8
8
|
CopilotSidebar
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-RKQM2AE5.mjs";
|
|
10
|
+
import "../chunk-OHGUQZJT.mjs";
|
|
11
11
|
import "../chunk-C3GSYRC3.mjs";
|
|
12
12
|
import "../chunk-GDSZGYCE.mjs";
|
|
13
13
|
import "../chunk-V7W6IM2V.mjs";
|
|
@@ -24,7 +24,7 @@ import "../chunk-BH6PCAAL.mjs";
|
|
|
24
24
|
import "../chunk-UFN2VWSR.mjs";
|
|
25
25
|
import {
|
|
26
26
|
CopilotChat
|
|
27
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-PD36EMOZ.mjs";
|
|
28
28
|
import {
|
|
29
29
|
Suggestions
|
|
30
30
|
} from "../chunk-VHKHX7GV.mjs";
|
|
@@ -35,12 +35,12 @@ import "../chunk-PLHTVHUW.mjs";
|
|
|
35
35
|
import "../chunk-3W6J75HS.mjs";
|
|
36
36
|
import "../chunk-ELGRNEAO.mjs";
|
|
37
37
|
import "../chunk-QIOJXTIQ.mjs";
|
|
38
|
-
import "../chunk-
|
|
39
|
-
import "../chunk-
|
|
40
|
-
import "../chunk-
|
|
38
|
+
import "../chunk-WNX755OE.mjs";
|
|
39
|
+
import "../chunk-F2CDEOFX.mjs";
|
|
40
|
+
import "../chunk-LBR23XXF.mjs";
|
|
41
41
|
import {
|
|
42
42
|
AssistantMessage
|
|
43
|
-
} from "../chunk-
|
|
43
|
+
} from "../chunk-LYYDXL2G.mjs";
|
|
44
44
|
import {
|
|
45
45
|
ImageRenderer
|
|
46
46
|
} from "../chunk-DBKRAOH7.mjs";
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
} from "../chunk-RYUCX3ZK.mjs";
|
|
50
50
|
import {
|
|
51
51
|
Markdown
|
|
52
|
-
} from "../chunk-
|
|
52
|
+
} from "../chunk-JZ3RFQQ6.mjs";
|
|
53
53
|
import "../chunk-IK2BPURM.mjs";
|
|
54
54
|
import {
|
|
55
55
|
useChatContext
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -97,7 +97,7 @@ __export(src_exports, {
|
|
|
97
97
|
module.exports = __toCommonJS(src_exports);
|
|
98
98
|
|
|
99
99
|
// src/components/chat/Modal.tsx
|
|
100
|
-
var
|
|
100
|
+
var import_react16 = __toESM(require("react"));
|
|
101
101
|
|
|
102
102
|
// src/components/chat/ChatContext.tsx
|
|
103
103
|
var import_react = __toESM(require("react"));
|
|
@@ -1038,7 +1038,7 @@ var Header = ({}) => {
|
|
|
1038
1038
|
};
|
|
1039
1039
|
|
|
1040
1040
|
// src/components/chat/Messages.tsx
|
|
1041
|
-
var
|
|
1041
|
+
var import_react10 = require("react");
|
|
1042
1042
|
var import_react_core5 = require("@copilotkit/react-core");
|
|
1043
1043
|
|
|
1044
1044
|
// src/components/chat/messages/UserMessage.tsx
|
|
@@ -1070,7 +1070,8 @@ var UserMessage = (props) => {
|
|
|
1070
1070
|
};
|
|
1071
1071
|
|
|
1072
1072
|
// src/components/chat/Markdown.tsx
|
|
1073
|
-
var
|
|
1073
|
+
var import_react7 = require("react");
|
|
1074
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1074
1075
|
|
|
1075
1076
|
// src/components/chat/CodeBlock.tsx
|
|
1076
1077
|
var import_react6 = require("react");
|
|
@@ -1482,6 +1483,9 @@ var highlightStyle = {
|
|
|
1482
1483
|
};
|
|
1483
1484
|
|
|
1484
1485
|
// src/components/chat/Markdown.tsx
|
|
1486
|
+
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
1487
|
+
var import_remark_math = __toESM(require("remark-math"));
|
|
1488
|
+
var import_rehype_raw = __toESM(require("rehype-raw"));
|
|
1485
1489
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1486
1490
|
var defaultComponents = {
|
|
1487
1491
|
a(_a) {
|
|
@@ -1575,21 +1579,27 @@ var defaultComponents = {
|
|
|
1575
1579
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
|
|
1576
1580
|
}
|
|
1577
1581
|
};
|
|
1582
|
+
var MemoizedReactMarkdown = (0, import_react7.memo)(
|
|
1583
|
+
import_react_markdown.default,
|
|
1584
|
+
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
|
|
1585
|
+
);
|
|
1578
1586
|
var Markdown = ({ content, components }) => {
|
|
1579
1587
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1580
|
-
|
|
1588
|
+
MemoizedReactMarkdown,
|
|
1581
1589
|
{
|
|
1582
1590
|
components: __spreadValues(__spreadValues({}, defaultComponents), components),
|
|
1591
|
+
remarkPlugins: [import_remark_gfm.default, [import_remark_math.default, { singleDollarTextMath: false }]],
|
|
1592
|
+
rehypePlugins: [import_rehype_raw.default],
|
|
1583
1593
|
children: content
|
|
1584
1594
|
}
|
|
1585
1595
|
) });
|
|
1586
1596
|
};
|
|
1587
1597
|
|
|
1588
1598
|
// src/components/chat/messages/AssistantMessage.tsx
|
|
1589
|
-
var
|
|
1599
|
+
var import_react8 = require("react");
|
|
1590
1600
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1591
1601
|
var AssistantMessage = (props) => {
|
|
1592
|
-
var _a;
|
|
1602
|
+
var _a, _b, _c;
|
|
1593
1603
|
const { icons, labels } = useChatContext();
|
|
1594
1604
|
const {
|
|
1595
1605
|
message,
|
|
@@ -1602,7 +1612,7 @@ var AssistantMessage = (props) => {
|
|
|
1602
1612
|
feedback,
|
|
1603
1613
|
markdownTagRenderers
|
|
1604
1614
|
} = props;
|
|
1605
|
-
const [copied, setCopied] = (0,
|
|
1615
|
+
const [copied, setCopied] = (0, import_react8.useState)(false);
|
|
1606
1616
|
const handleCopy = () => {
|
|
1607
1617
|
const content2 = (message == null ? void 0 : message.content) || "";
|
|
1608
1618
|
if (content2 && onCopy) {
|
|
@@ -1632,8 +1642,12 @@ var AssistantMessage = (props) => {
|
|
|
1632
1642
|
};
|
|
1633
1643
|
const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: icons.activityIcon });
|
|
1634
1644
|
const content = (message == null ? void 0 : message.content) || "";
|
|
1635
|
-
const subComponent = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message);
|
|
1645
|
+
const subComponent = (_b = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message)) != null ? _b : props.subComponent;
|
|
1646
|
+
const subComponentPosition = (_c = message == null ? void 0 : message.generativeUIPosition) != null ? _c : "after";
|
|
1647
|
+
const renderBefore = subComponent && subComponentPosition === "before";
|
|
1648
|
+
const renderAfter = subComponent && subComponentPosition !== "before";
|
|
1636
1649
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
1650
|
+
renderBefore ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }) : null,
|
|
1637
1651
|
content && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
|
|
1638
1652
|
content && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Markdown, { content, components: markdownTagRenderers }),
|
|
1639
1653
|
content && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
@@ -1685,16 +1699,16 @@ var AssistantMessage = (props) => {
|
|
|
1685
1699
|
}
|
|
1686
1700
|
)
|
|
1687
1701
|
] }),
|
|
1688
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }),
|
|
1702
|
+
renderAfter ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }) : null,
|
|
1689
1703
|
isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(LoadingIcon, {})
|
|
1690
1704
|
] });
|
|
1691
1705
|
};
|
|
1692
1706
|
|
|
1693
1707
|
// src/components/chat/messages/ImageRenderer.tsx
|
|
1694
|
-
var
|
|
1708
|
+
var import_react9 = require("react");
|
|
1695
1709
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1696
1710
|
var ImageRenderer = ({ image, content, className = "" }) => {
|
|
1697
|
-
const [imageError, setImageError] = (0,
|
|
1711
|
+
const [imageError, setImageError] = (0, import_react9.useState)(false);
|
|
1698
1712
|
const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
|
|
1699
1713
|
const altText = content || "User uploaded image";
|
|
1700
1714
|
const handleImageError = () => {
|
|
@@ -1937,18 +1951,18 @@ var Messages = ({
|
|
|
1937
1951
|
var _a;
|
|
1938
1952
|
const { labels, icons } = useChatContext();
|
|
1939
1953
|
const { messages: visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
|
|
1940
|
-
const initialMessages = (0,
|
|
1954
|
+
const initialMessages = (0, import_react10.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
|
|
1941
1955
|
const messages = [...initialMessages, ...visibleMessages];
|
|
1942
1956
|
const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
|
|
1943
1957
|
const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
|
|
1944
|
-
(0,
|
|
1958
|
+
(0, import_react10.useEffect)(() => {
|
|
1945
1959
|
if (hasLegacyProps) {
|
|
1946
1960
|
console.warn(
|
|
1947
1961
|
"[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"
|
|
1948
1962
|
);
|
|
1949
1963
|
}
|
|
1950
1964
|
}, [hasLegacyProps]);
|
|
1951
|
-
const legacyProps = (0,
|
|
1965
|
+
const legacyProps = (0, import_react10.useMemo)(
|
|
1952
1966
|
() => ({
|
|
1953
1967
|
RenderTextMessage,
|
|
1954
1968
|
RenderActionExecutionMessage,
|
|
@@ -2019,10 +2033,10 @@ function makeInitialMessages(initial) {
|
|
|
2019
2033
|
];
|
|
2020
2034
|
}
|
|
2021
2035
|
function useScrollToBottom(messages) {
|
|
2022
|
-
const messagesEndRef = (0,
|
|
2023
|
-
const messagesContainerRef = (0,
|
|
2024
|
-
const isProgrammaticScrollRef = (0,
|
|
2025
|
-
const isUserScrollUpRef = (0,
|
|
2036
|
+
const messagesEndRef = (0, import_react10.useRef)(null);
|
|
2037
|
+
const messagesContainerRef = (0, import_react10.useRef)(null);
|
|
2038
|
+
const isProgrammaticScrollRef = (0, import_react10.useRef)(false);
|
|
2039
|
+
const isUserScrollUpRef = (0, import_react10.useRef)(false);
|
|
2026
2040
|
const scrollToBottom = () => {
|
|
2027
2041
|
if (messagesContainerRef.current && messagesEndRef.current) {
|
|
2028
2042
|
isProgrammaticScrollRef.current = true;
|
|
@@ -2039,7 +2053,7 @@ function useScrollToBottom(messages) {
|
|
|
2039
2053
|
isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
|
|
2040
2054
|
}
|
|
2041
2055
|
};
|
|
2042
|
-
(0,
|
|
2056
|
+
(0, import_react10.useEffect)(() => {
|
|
2043
2057
|
const container = messagesContainerRef.current;
|
|
2044
2058
|
if (container) {
|
|
2045
2059
|
container.addEventListener("scroll", handleScroll);
|
|
@@ -2050,7 +2064,7 @@ function useScrollToBottom(messages) {
|
|
|
2050
2064
|
}
|
|
2051
2065
|
};
|
|
2052
2066
|
}, []);
|
|
2053
|
-
(0,
|
|
2067
|
+
(0, import_react10.useEffect)(() => {
|
|
2054
2068
|
const container = messagesContainerRef.current;
|
|
2055
2069
|
if (!container) {
|
|
2056
2070
|
return;
|
|
@@ -2069,7 +2083,7 @@ function useScrollToBottom(messages) {
|
|
|
2069
2083
|
mutationObserver.disconnect();
|
|
2070
2084
|
};
|
|
2071
2085
|
}, []);
|
|
2072
|
-
(0,
|
|
2086
|
+
(0, import_react10.useEffect)(() => {
|
|
2073
2087
|
isUserScrollUpRef.current = false;
|
|
2074
2088
|
scrollToBottom();
|
|
2075
2089
|
}, [messages.filter((m) => m.role === "user").length]);
|
|
@@ -2077,12 +2091,12 @@ function useScrollToBottom(messages) {
|
|
|
2077
2091
|
}
|
|
2078
2092
|
|
|
2079
2093
|
// src/components/chat/Input.tsx
|
|
2080
|
-
var
|
|
2094
|
+
var import_react14 = require("react");
|
|
2081
2095
|
|
|
2082
2096
|
// src/components/chat/Textarea.tsx
|
|
2083
|
-
var
|
|
2097
|
+
var import_react11 = require("react");
|
|
2084
2098
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2085
|
-
var AutoResizingTextarea = (0,
|
|
2099
|
+
var AutoResizingTextarea = (0, import_react11.forwardRef)(
|
|
2086
2100
|
({
|
|
2087
2101
|
maxRows = 1,
|
|
2088
2102
|
placeholder,
|
|
@@ -2093,10 +2107,10 @@ var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
|
2093
2107
|
onCompositionEnd,
|
|
2094
2108
|
autoFocus
|
|
2095
2109
|
}, ref) => {
|
|
2096
|
-
const internalTextareaRef = (0,
|
|
2097
|
-
const [maxHeight, setMaxHeight] = (0,
|
|
2098
|
-
(0,
|
|
2099
|
-
(0,
|
|
2110
|
+
const internalTextareaRef = (0, import_react11.useRef)(null);
|
|
2111
|
+
const [maxHeight, setMaxHeight] = (0, import_react11.useState)(0);
|
|
2112
|
+
(0, import_react11.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
2113
|
+
(0, import_react11.useEffect)(() => {
|
|
2100
2114
|
const calculateMaxHeight = () => {
|
|
2101
2115
|
const textarea = internalTextareaRef.current;
|
|
2102
2116
|
if (textarea) {
|
|
@@ -2110,7 +2124,7 @@ var AutoResizingTextarea = (0, import_react10.forwardRef)(
|
|
|
2110
2124
|
};
|
|
2111
2125
|
calculateMaxHeight();
|
|
2112
2126
|
}, [maxRows]);
|
|
2113
|
-
(0,
|
|
2127
|
+
(0, import_react11.useEffect)(() => {
|
|
2114
2128
|
const textarea = internalTextareaRef.current;
|
|
2115
2129
|
if (textarea) {
|
|
2116
2130
|
textarea.style.height = "auto";
|
|
@@ -2142,7 +2156,7 @@ var Textarea_default = AutoResizingTextarea;
|
|
|
2142
2156
|
// src/hooks/use-push-to-talk.tsx
|
|
2143
2157
|
var import_react_core6 = require("@copilotkit/react-core");
|
|
2144
2158
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
2145
|
-
var
|
|
2159
|
+
var import_react12 = require("react");
|
|
2146
2160
|
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
2147
2161
|
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
2148
2162
|
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
@@ -2191,16 +2205,16 @@ var usePushToTalk = ({
|
|
|
2191
2205
|
sendFunction,
|
|
2192
2206
|
inProgress
|
|
2193
2207
|
}) => {
|
|
2194
|
-
const [pushToTalkState, setPushToTalkState] = (0,
|
|
2195
|
-
const mediaStreamRef = (0,
|
|
2196
|
-
const audioContextRef = (0,
|
|
2197
|
-
const mediaRecorderRef = (0,
|
|
2198
|
-
const recordedChunks = (0,
|
|
2208
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react12.useState)("idle");
|
|
2209
|
+
const mediaStreamRef = (0, import_react12.useRef)(null);
|
|
2210
|
+
const audioContextRef = (0, import_react12.useRef)(null);
|
|
2211
|
+
const mediaRecorderRef = (0, import_react12.useRef)(null);
|
|
2212
|
+
const recordedChunks = (0, import_react12.useRef)([]);
|
|
2199
2213
|
const generalContext = (0, import_react_core6.useCopilotContext)();
|
|
2200
2214
|
const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
|
|
2201
2215
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2202
|
-
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0,
|
|
2203
|
-
(0,
|
|
2216
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react12.useState)(null);
|
|
2217
|
+
(0, import_react12.useEffect)(() => {
|
|
2204
2218
|
if (pushToTalkState === "recording") {
|
|
2205
2219
|
startRecording(
|
|
2206
2220
|
mediaStreamRef,
|
|
@@ -2228,7 +2242,7 @@ var usePushToTalk = ({
|
|
|
2228
2242
|
stopRecording(mediaRecorderRef);
|
|
2229
2243
|
};
|
|
2230
2244
|
}, [pushToTalkState]);
|
|
2231
|
-
(0,
|
|
2245
|
+
(0, import_react12.useEffect)(() => {
|
|
2232
2246
|
if (inProgress === false && startReadingFromMessageId) {
|
|
2233
2247
|
const lastMessageIndex = context.messages.findIndex(
|
|
2234
2248
|
(message) => message.id === startReadingFromMessageId
|
|
@@ -2247,7 +2261,7 @@ var usePushToTalk = ({
|
|
|
2247
2261
|
var import_react_core7 = require("@copilotkit/react-core");
|
|
2248
2262
|
|
|
2249
2263
|
// src/components/chat/PoweredByTag.tsx
|
|
2250
|
-
var
|
|
2264
|
+
var import_react13 = require("react");
|
|
2251
2265
|
|
|
2252
2266
|
// src/hooks/use-dark-mode.ts
|
|
2253
2267
|
var useDarkMode = () => {
|
|
@@ -2259,9 +2273,9 @@ var useDarkMode = () => {
|
|
|
2259
2273
|
// src/components/chat/PoweredByTag.tsx
|
|
2260
2274
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2261
2275
|
function PoweredByTag({ showPoweredBy = true }) {
|
|
2262
|
-
const [mounted, setMounted] = (0,
|
|
2276
|
+
const [mounted, setMounted] = (0, import_react13.useState)(false);
|
|
2263
2277
|
const isDark = useDarkMode();
|
|
2264
|
-
(0,
|
|
2278
|
+
(0, import_react13.useEffect)(() => {
|
|
2265
2279
|
setMounted(true);
|
|
2266
2280
|
}, []);
|
|
2267
2281
|
if (!showPoweredBy) {
|
|
@@ -2295,8 +2309,8 @@ var Input = ({
|
|
|
2295
2309
|
const copilotContext = (0, import_react_core7.useCopilotContext)();
|
|
2296
2310
|
const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
|
|
2297
2311
|
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
2298
|
-
const textareaRef = (0,
|
|
2299
|
-
const [isComposing, setIsComposing] = (0,
|
|
2312
|
+
const textareaRef = (0, import_react14.useRef)(null);
|
|
2313
|
+
const [isComposing, setIsComposing] = (0, import_react14.useState)(false);
|
|
2300
2314
|
const handleDivClick = (event) => {
|
|
2301
2315
|
var _a2;
|
|
2302
2316
|
const target = event.target;
|
|
@@ -2306,7 +2320,7 @@ var Input = ({
|
|
|
2306
2320
|
return;
|
|
2307
2321
|
(_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
|
|
2308
2322
|
};
|
|
2309
|
-
const [text, setText] = (0,
|
|
2323
|
+
const [text, setText] = (0, import_react14.useState)("");
|
|
2310
2324
|
const send = () => {
|
|
2311
2325
|
var _a2;
|
|
2312
2326
|
if (inProgress)
|
|
@@ -2320,17 +2334,17 @@ var Input = ({
|
|
|
2320
2334
|
inProgress
|
|
2321
2335
|
});
|
|
2322
2336
|
const isInProgress = inProgress || pushToTalkState === "transcribing";
|
|
2323
|
-
const { buttonIcon, buttonAlt } = (0,
|
|
2337
|
+
const { buttonIcon, buttonAlt } = (0, import_react14.useMemo)(() => {
|
|
2324
2338
|
if (!chatReady)
|
|
2325
2339
|
return { buttonIcon: context.icons.spinnerIcon, buttonAlt: "Loading" };
|
|
2326
2340
|
return isInProgress && !hideStopButton && chatReady ? { buttonIcon: context.icons.stopIcon, buttonAlt: "Stop" } : { buttonIcon: context.icons.sendIcon, buttonAlt: "Send" };
|
|
2327
2341
|
}, [isInProgress, chatReady, hideStopButton, context.icons.stopIcon, context.icons.sendIcon]);
|
|
2328
2342
|
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
2329
2343
|
const { interrupt } = (0, import_react_core7.useCopilotChatInternal)();
|
|
2330
|
-
const canSend = (0,
|
|
2344
|
+
const canSend = (0, import_react14.useMemo)(() => {
|
|
2331
2345
|
return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interrupt;
|
|
2332
2346
|
}, [interrupt, isInProgress, text, pushToTalkState]);
|
|
2333
|
-
const canStop = (0,
|
|
2347
|
+
const canStop = (0, import_react14.useMemo)(() => {
|
|
2334
2348
|
return isInProgress && !hideStopButton;
|
|
2335
2349
|
}, [isInProgress, hideStopButton]);
|
|
2336
2350
|
const sendDisabled = !canSend && !canStop;
|
|
@@ -2387,7 +2401,7 @@ var Input = ({
|
|
|
2387
2401
|
};
|
|
2388
2402
|
|
|
2389
2403
|
// src/components/chat/Chat.tsx
|
|
2390
|
-
var
|
|
2404
|
+
var import_react15 = __toESM(require("react"));
|
|
2391
2405
|
var import_react_core9 = require("@copilotkit/react-core");
|
|
2392
2406
|
var import_shared3 = require("@copilotkit/shared");
|
|
2393
2407
|
|
|
@@ -2564,13 +2578,13 @@ function CopilotChat({
|
|
|
2564
2578
|
removeInternalErrorHandler
|
|
2565
2579
|
} = (0, import_react_core9.useCopilotContext)();
|
|
2566
2580
|
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
2567
|
-
const [selectedImages, setSelectedImages] = (0,
|
|
2568
|
-
const [chatError, setChatError] = (0,
|
|
2569
|
-
const [messageFeedback, setMessageFeedback] = (0,
|
|
2581
|
+
const [selectedImages, setSelectedImages] = (0, import_react15.useState)([]);
|
|
2582
|
+
const [chatError, setChatError] = (0, import_react15.useState)(null);
|
|
2583
|
+
const [messageFeedback, setMessageFeedback] = (0, import_react15.useState)(
|
|
2570
2584
|
{}
|
|
2571
2585
|
);
|
|
2572
|
-
const fileInputRef = (0,
|
|
2573
|
-
const triggerObservabilityHook = (0,
|
|
2586
|
+
const fileInputRef = (0, import_react15.useRef)(null);
|
|
2587
|
+
const triggerObservabilityHook = (0, import_react15.useCallback)(
|
|
2574
2588
|
(hookName, ...args) => {
|
|
2575
2589
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2576
2590
|
observabilityHooks[hookName](...args);
|
|
@@ -2589,7 +2603,7 @@ function CopilotChat({
|
|
|
2589
2603
|
},
|
|
2590
2604
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2591
2605
|
);
|
|
2592
|
-
const triggerChatError = (0,
|
|
2606
|
+
const triggerChatError = (0, import_react15.useCallback)(
|
|
2593
2607
|
(error, operation, originalError) => {
|
|
2594
2608
|
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
|
|
2595
2609
|
setChatError({
|
|
@@ -2635,7 +2649,7 @@ function CopilotChat({
|
|
|
2635
2649
|
},
|
|
2636
2650
|
[publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
|
|
2637
2651
|
);
|
|
2638
|
-
(0,
|
|
2652
|
+
(0, import_react15.useEffect)(() => {
|
|
2639
2653
|
const id = "chat-component";
|
|
2640
2654
|
setInternalErrorHandler({
|
|
2641
2655
|
[id]: (error) => {
|
|
@@ -2648,7 +2662,7 @@ function CopilotChat({
|
|
|
2648
2662
|
removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
|
|
2649
2663
|
};
|
|
2650
2664
|
}, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
|
|
2651
|
-
(0,
|
|
2665
|
+
(0, import_react15.useEffect)(() => {
|
|
2652
2666
|
if (!imageUploadsEnabled)
|
|
2653
2667
|
return;
|
|
2654
2668
|
const handlePaste = (e) => __async(this, null, function* () {
|
|
@@ -2694,7 +2708,7 @@ function CopilotChat({
|
|
|
2694
2708
|
document.addEventListener("paste", handlePaste);
|
|
2695
2709
|
return () => document.removeEventListener("paste", handlePaste);
|
|
2696
2710
|
}, [imageUploadsEnabled, triggerChatError]);
|
|
2697
|
-
(0,
|
|
2711
|
+
(0, import_react15.useEffect)(() => {
|
|
2698
2712
|
if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
|
|
2699
2713
|
setChatInstructions(instructions || "");
|
|
2700
2714
|
return;
|
|
@@ -2722,8 +2736,8 @@ function CopilotChat({
|
|
|
2722
2736
|
onStopGeneration,
|
|
2723
2737
|
onReloadMessages
|
|
2724
2738
|
});
|
|
2725
|
-
const prevIsLoading = (0,
|
|
2726
|
-
(0,
|
|
2739
|
+
const prevIsLoading = (0, import_react15.useRef)(isLoading);
|
|
2740
|
+
(0, import_react15.useEffect)(() => {
|
|
2727
2741
|
if (prevIsLoading.current !== isLoading) {
|
|
2728
2742
|
if (isLoading) {
|
|
2729
2743
|
triggerObservabilityHook("onChatStarted");
|
|
@@ -2746,7 +2760,7 @@ function CopilotChat({
|
|
|
2746
2760
|
role: "user"
|
|
2747
2761
|
});
|
|
2748
2762
|
};
|
|
2749
|
-
const chatContext =
|
|
2763
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2750
2764
|
const isVisible = chatContext ? chatContext.open : true;
|
|
2751
2765
|
const handleRegenerate = (messageId) => {
|
|
2752
2766
|
if (onRegenerate) {
|
|
@@ -2890,7 +2904,7 @@ function WrappedCopilotChat({
|
|
|
2890
2904
|
labels,
|
|
2891
2905
|
className
|
|
2892
2906
|
}) {
|
|
2893
|
-
const chatContext =
|
|
2907
|
+
const chatContext = import_react15.default.useContext(ChatContext);
|
|
2894
2908
|
if (!chatContext) {
|
|
2895
2909
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
|
|
2896
2910
|
}, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
|
|
@@ -2928,7 +2942,7 @@ var CopilotModalInner = (_a) => {
|
|
|
2928
2942
|
]);
|
|
2929
2943
|
const { copilotApiConfig, setBannerError } = (0, import_react_core10.useCopilotContext)();
|
|
2930
2944
|
const { publicApiKey } = copilotApiConfig;
|
|
2931
|
-
const triggerObservabilityHook = (0,
|
|
2945
|
+
const triggerObservabilityHook = (0, import_react16.useCallback)(
|
|
2932
2946
|
(hookName, ...args) => {
|
|
2933
2947
|
if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
|
|
2934
2948
|
observabilityHooks[hookName](...args);
|
|
@@ -2948,8 +2962,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2948
2962
|
[publicApiKey, observabilityHooks, setBannerError]
|
|
2949
2963
|
);
|
|
2950
2964
|
const { open } = useChatContext();
|
|
2951
|
-
const prevOpen = (0,
|
|
2952
|
-
(0,
|
|
2965
|
+
const prevOpen = (0, import_react16.useRef)(open);
|
|
2966
|
+
(0, import_react16.useEffect)(() => {
|
|
2953
2967
|
if (prevOpen.current !== open) {
|
|
2954
2968
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
2955
2969
|
if (open) {
|
|
@@ -2960,8 +2974,8 @@ var CopilotModalInner = (_a) => {
|
|
|
2960
2974
|
prevOpen.current = open;
|
|
2961
2975
|
}
|
|
2962
2976
|
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
2963
|
-
const memoizedHeader = (0,
|
|
2964
|
-
const memoizedChildren = (0,
|
|
2977
|
+
const memoizedHeader = (0, import_react16.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}), [Header2]);
|
|
2978
|
+
const memoizedChildren = (0, import_react16.useMemo)(() => children, [children]);
|
|
2965
2979
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
2966
2980
|
memoizedChildren,
|
|
2967
2981
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className, children: [
|
|
@@ -3041,7 +3055,7 @@ var CopilotModal = (_a) => {
|
|
|
3041
3055
|
"children",
|
|
3042
3056
|
"observabilityHooks"
|
|
3043
3057
|
]);
|
|
3044
|
-
const [openState, setOpenState] =
|
|
3058
|
+
const [openState, setOpenState] = import_react16.default.useState(defaultOpen);
|
|
3045
3059
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3046
3060
|
CopilotModalInner,
|
|
3047
3061
|
__spreadProps(__spreadValues({
|
|
@@ -3085,13 +3099,13 @@ function CopilotPopup(props) {
|
|
|
3085
3099
|
}
|
|
3086
3100
|
|
|
3087
3101
|
// src/components/chat/Sidebar.tsx
|
|
3088
|
-
var
|
|
3102
|
+
var import_react17 = require("react");
|
|
3089
3103
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
3090
3104
|
function CopilotSidebar(props) {
|
|
3091
3105
|
props = __spreadProps(__spreadValues({}, props), {
|
|
3092
3106
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
3093
3107
|
});
|
|
3094
|
-
const [expandedClassName, setExpandedClassName] = (0,
|
|
3108
|
+
const [expandedClassName, setExpandedClassName] = (0, import_react17.useState)(
|
|
3095
3109
|
props.defaultOpen ? "sidebarExpanded" : ""
|
|
3096
3110
|
);
|
|
3097
3111
|
const onSetOpen = (open) => {
|