@copilotkit/react-ui 1.10.0-next.8 → 1.10.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/dist/{chunk-U5ATIGWH.mjs → chunk-BJHJBS5M.mjs} +45 -5
  3. package/dist/chunk-BJHJBS5M.mjs.map +1 -0
  4. package/dist/{chunk-KLV4ERV6.mjs → chunk-GBP47ONN.mjs} +2 -2
  5. package/dist/{chunk-3DVMCBME.mjs → chunk-GJ4SX4JE.mjs} +97 -35
  6. package/dist/chunk-GJ4SX4JE.mjs.map +1 -0
  7. package/dist/{chunk-APLX7E54.mjs → chunk-J5ZZR6YB.mjs} +2 -2
  8. package/dist/chunk-MIVUCSGO.mjs +126 -0
  9. package/dist/chunk-MIVUCSGO.mjs.map +1 -0
  10. package/dist/{chunk-JHUTTP5C.mjs → chunk-T5QU6KSB.mjs} +5 -1
  11. package/dist/chunk-T5QU6KSB.mjs.map +1 -0
  12. package/dist/{chunk-BPU3FDT4.mjs → chunk-Y44VLEUH.mjs} +30 -11
  13. package/dist/chunk-Y44VLEUH.mjs.map +1 -0
  14. package/dist/components/chat/Chat.d.ts +32 -2
  15. package/dist/components/chat/Chat.js +1084 -865
  16. package/dist/components/chat/Chat.js.map +1 -1
  17. package/dist/components/chat/Chat.mjs +7 -6
  18. package/dist/components/chat/Messages.d.ts +1 -1
  19. package/dist/components/chat/Messages.js +984 -23
  20. package/dist/components/chat/Messages.js.map +1 -1
  21. package/dist/components/chat/Messages.mjs +9 -1
  22. package/dist/components/chat/Modal.js +1107 -875
  23. package/dist/components/chat/Modal.js.map +1 -1
  24. package/dist/components/chat/Modal.mjs +8 -7
  25. package/dist/components/chat/Popup.js +1109 -877
  26. package/dist/components/chat/Popup.js.map +1 -1
  27. package/dist/components/chat/Popup.mjs +9 -8
  28. package/dist/components/chat/Sidebar.js +1109 -877
  29. package/dist/components/chat/Sidebar.js.map +1 -1
  30. package/dist/components/chat/Sidebar.mjs +9 -8
  31. package/dist/components/chat/index.js +1111 -879
  32. package/dist/components/chat/index.js.map +1 -1
  33. package/dist/components/chat/index.mjs +16 -15
  34. package/dist/components/chat/messages/LegacyRenderMessage.d.ts +28 -0
  35. package/dist/components/chat/messages/LegacyRenderMessage.js +980 -0
  36. package/dist/components/chat/messages/LegacyRenderMessage.js.map +1 -0
  37. package/dist/components/chat/messages/LegacyRenderMessage.mjs +17 -0
  38. package/dist/components/chat/messages/LegacyRenderMessage.mjs.map +1 -0
  39. package/dist/components/chat/messages/RenderMessage.js +4 -0
  40. package/dist/components/chat/messages/RenderMessage.js.map +1 -1
  41. package/dist/components/chat/messages/RenderMessage.mjs +1 -1
  42. package/dist/components/chat/props.d.ts +55 -1
  43. package/dist/components/chat/props.js.map +1 -1
  44. package/dist/components/index.js +1111 -879
  45. package/dist/components/index.js.map +1 -1
  46. package/dist/components/index.mjs +16 -15
  47. package/dist/index.js +1113 -881
  48. package/dist/index.js.map +1 -1
  49. package/dist/index.mjs +16 -15
  50. package/package.json +4 -4
  51. package/src/components/chat/Chat.tsx +144 -21
  52. package/src/components/chat/Messages.tsx +56 -3
  53. package/src/components/chat/Modal.tsx +24 -3
  54. package/src/components/chat/messages/LegacyRenderMessage.tsx +143 -0
  55. package/src/components/chat/messages/RenderMessage.tsx +3 -0
  56. package/src/components/chat/props.ts +64 -1
  57. package/dist/chunk-3DVMCBME.mjs.map +0 -1
  58. package/dist/chunk-BPU3FDT4.mjs.map +0 -1
  59. package/dist/chunk-JHUTTP5C.mjs.map +0 -1
  60. package/dist/chunk-U5ATIGWH.mjs.map +0 -1
  61. /package/dist/{chunk-KLV4ERV6.mjs.map → chunk-GBP47ONN.mjs.map} +0 -0
  62. /package/dist/{chunk-APLX7E54.mjs.map → chunk-J5ZZR6YB.mjs.map} +0 -0
@@ -1036,559 +1036,137 @@ var Header = ({}) => {
1036
1036
  };
1037
1037
 
1038
1038
  // src/components/chat/Messages.tsx
1039
- var import_react6 = require("react");
1039
+ var import_react10 = require("react");
1040
1040
  var import_react_core5 = require("@copilotkit/react-core");
1041
+
1042
+ // src/components/chat/messages/UserMessage.tsx
1041
1043
  var import_jsx_runtime10 = require("react/jsx-runtime");
1042
- var Messages = ({
1043
- inProgress,
1044
- children,
1045
- RenderMessage: RenderMessage2,
1046
- AssistantMessage: AssistantMessage2,
1047
- UserMessage: UserMessage2,
1048
- onRegenerate,
1049
- onCopy,
1050
- onThumbsUp,
1051
- onThumbsDown,
1052
- markdownTagRenderers
1053
- }) => {
1054
- const { labels } = useChatContext();
1055
- const { visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
1056
- const initialMessages = (0, import_react6.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
1057
- const messages = [...initialMessages, ...visibleMessages];
1058
- const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
1059
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [
1060
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitMessagesContainer", children: [
1061
- messages.map((message, index) => {
1062
- const isCurrentMessage = index === messages.length - 1;
1063
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1064
- RenderMessage2,
1065
- {
1066
- message,
1067
- inProgress,
1068
- index,
1069
- isCurrentMessage,
1070
- AssistantMessage: AssistantMessage2,
1071
- UserMessage: UserMessage2,
1072
- onRegenerate,
1073
- onCopy,
1074
- onThumbsUp,
1075
- onThumbsDown,
1076
- markdownTagRenderers
1077
- },
1078
- index
1079
- );
1080
- }),
1081
- interrupt
1082
- ] }),
1083
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("footer", { className: "copilotKitMessagesFooter", ref: messagesEndRef, children })
1084
- ] });
1085
- };
1086
- function makeInitialMessages(initial) {
1087
- if (!initial)
1088
- return [];
1089
- if (Array.isArray(initial)) {
1090
- return initial.map((message) => {
1091
- return {
1092
- id: message,
1093
- role: "assistant",
1094
- content: message
1095
- };
1096
- });
1044
+ var UserMessage = (props) => {
1045
+ const { message, ImageRenderer: ImageRenderer2 } = props;
1046
+ const isImageMessage = message && "image" in message && message.image;
1047
+ if (isImageMessage) {
1048
+ const imageMessage = message;
1049
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ImageRenderer2, { image: imageMessage.image, content: imageMessage.content }) });
1097
1050
  }
1098
- return [
1099
- {
1100
- id: initial,
1101
- role: "system",
1102
- content: initial
1103
- }
1104
- ];
1105
- }
1106
- function useScrollToBottom(messages) {
1107
- const messagesEndRef = (0, import_react6.useRef)(null);
1108
- const messagesContainerRef = (0, import_react6.useRef)(null);
1109
- const isProgrammaticScrollRef = (0, import_react6.useRef)(false);
1110
- const isUserScrollUpRef = (0, import_react6.useRef)(false);
1111
- const scrollToBottom = () => {
1112
- if (messagesContainerRef.current && messagesEndRef.current) {
1113
- isProgrammaticScrollRef.current = true;
1114
- messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;
1115
- }
1116
- };
1117
- const handleScroll = () => {
1118
- if (isProgrammaticScrollRef.current) {
1119
- isProgrammaticScrollRef.current = false;
1051
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message == null ? void 0 : message.content });
1052
+ };
1053
+
1054
+ // src/components/chat/Markdown.tsx
1055
+ var import_react7 = require("react");
1056
+ var import_react_markdown = __toESM(require("react-markdown"));
1057
+
1058
+ // src/components/chat/CodeBlock.tsx
1059
+ var import_react6 = require("react");
1060
+ var import_react_syntax_highlighter = require("react-syntax-highlighter");
1061
+
1062
+ // src/hooks/use-copy-to-clipboard.tsx
1063
+ var React5 = __toESM(require("react"));
1064
+ function useCopyToClipboard({ timeout = 2e3 }) {
1065
+ const [isCopied, setIsCopied] = React5.useState(false);
1066
+ const copyToClipboard = (value) => {
1067
+ var _a;
1068
+ if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
1120
1069
  return;
1121
1070
  }
1122
- if (messagesContainerRef.current) {
1123
- const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
1124
- isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
1125
- }
1126
- };
1127
- (0, import_react6.useEffect)(() => {
1128
- const container = messagesContainerRef.current;
1129
- if (container) {
1130
- container.addEventListener("scroll", handleScroll);
1131
- }
1132
- return () => {
1133
- if (container) {
1134
- container.removeEventListener("scroll", handleScroll);
1135
- }
1136
- };
1137
- }, []);
1138
- (0, import_react6.useEffect)(() => {
1139
- const container = messagesContainerRef.current;
1140
- if (!container) {
1071
+ if (!value) {
1141
1072
  return;
1142
1073
  }
1143
- const mutationObserver = new MutationObserver(() => {
1144
- if (!isUserScrollUpRef.current) {
1145
- scrollToBottom();
1146
- }
1147
- });
1148
- mutationObserver.observe(container, {
1149
- childList: true,
1150
- subtree: true,
1151
- characterData: true
1074
+ navigator.clipboard.writeText(value).then(() => {
1075
+ setIsCopied(true);
1076
+ setTimeout(() => {
1077
+ setIsCopied(false);
1078
+ }, timeout);
1152
1079
  });
1153
- return () => {
1154
- mutationObserver.disconnect();
1155
- };
1156
- }, []);
1157
- (0, import_react6.useEffect)(() => {
1158
- isUserScrollUpRef.current = false;
1159
- scrollToBottom();
1160
- }, [messages.filter((m) => m.role === "user").length]);
1161
- return { messagesEndRef, messagesContainerRef };
1080
+ };
1081
+ return { isCopied, copyToClipboard };
1162
1082
  }
1163
1083
 
1164
- // src/components/chat/Input.tsx
1165
- var import_react9 = require("react");
1166
-
1167
- // src/components/chat/Textarea.tsx
1168
- var import_react7 = require("react");
1084
+ // src/components/chat/CodeBlock.tsx
1169
1085
  var import_jsx_runtime11 = require("react/jsx-runtime");
1170
- var AutoResizingTextarea = (0, import_react7.forwardRef)(
1171
- ({
1172
- maxRows = 1,
1173
- placeholder,
1174
- value,
1175
- onChange,
1176
- onKeyDown,
1177
- onCompositionStart,
1178
- onCompositionEnd,
1179
- autoFocus
1180
- }, ref) => {
1181
- const internalTextareaRef = (0, import_react7.useRef)(null);
1182
- const [maxHeight, setMaxHeight] = (0, import_react7.useState)(0);
1183
- (0, import_react7.useImperativeHandle)(ref, () => internalTextareaRef.current);
1184
- (0, import_react7.useEffect)(() => {
1185
- const calculateMaxHeight = () => {
1186
- const textarea = internalTextareaRef.current;
1187
- if (textarea) {
1188
- textarea.style.height = "auto";
1189
- const singleRowHeight = textarea.scrollHeight;
1190
- setMaxHeight(singleRowHeight * maxRows);
1191
- if (autoFocus) {
1192
- textarea.focus();
1193
- }
1194
- }
1195
- };
1196
- calculateMaxHeight();
1197
- }, [maxRows]);
1198
- (0, import_react7.useEffect)(() => {
1199
- const textarea = internalTextareaRef.current;
1200
- if (textarea) {
1201
- textarea.style.height = "auto";
1202
- textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
1203
- }
1204
- }, [value, maxHeight]);
1205
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1206
- "textarea",
1086
+ var programmingLanguages = {
1087
+ javascript: ".js",
1088
+ python: ".py",
1089
+ java: ".java",
1090
+ c: ".c",
1091
+ cpp: ".cpp",
1092
+ "c++": ".cpp",
1093
+ "c#": ".cs",
1094
+ ruby: ".rb",
1095
+ php: ".php",
1096
+ swift: ".swift",
1097
+ "objective-c": ".m",
1098
+ kotlin: ".kt",
1099
+ typescript: ".ts",
1100
+ go: ".go",
1101
+ perl: ".pl",
1102
+ rust: ".rs",
1103
+ scala: ".scala",
1104
+ haskell: ".hs",
1105
+ lua: ".lua",
1106
+ shell: ".sh",
1107
+ sql: ".sql",
1108
+ html: ".html",
1109
+ css: ".css"
1110
+ // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
1111
+ };
1112
+ var generateRandomString = (length, lowercase = false) => {
1113
+ const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
1114
+ let result = "";
1115
+ for (let i = 0; i < length; i++) {
1116
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
1117
+ }
1118
+ return lowercase ? result.toLowerCase() : result;
1119
+ };
1120
+ var CodeBlock = (0, import_react6.memo)(({ language, value }) => {
1121
+ const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
1122
+ const downloadAsFile = () => {
1123
+ if (typeof window === "undefined") {
1124
+ return;
1125
+ }
1126
+ const fileExtension = programmingLanguages[language] || ".file";
1127
+ const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;
1128
+ const fileName = window.prompt("Enter file name", suggestedFileName);
1129
+ if (!fileName) {
1130
+ return;
1131
+ }
1132
+ const blob = new Blob([value], { type: "text/plain" });
1133
+ const url = URL.createObjectURL(blob);
1134
+ const link = document.createElement("a");
1135
+ link.download = fileName;
1136
+ link.href = url;
1137
+ link.style.display = "none";
1138
+ document.body.appendChild(link);
1139
+ link.click();
1140
+ document.body.removeChild(link);
1141
+ URL.revokeObjectURL(url);
1142
+ };
1143
+ const onCopy = () => {
1144
+ if (isCopied)
1145
+ return;
1146
+ copyToClipboard(value);
1147
+ };
1148
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "copilotKitCodeBlock", children: [
1149
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "copilotKitCodeBlockToolbar", children: [
1150
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
1151
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
1152
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: downloadAsFile, children: DownloadIcon }),
1153
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: isCopied ? CheckIcon : CopyIcon })
1154
+ ] })
1155
+ ] }),
1156
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1157
+ import_react_syntax_highlighter.Prism,
1207
1158
  {
1208
- ref: internalTextareaRef,
1209
- value,
1210
- onChange,
1211
- onKeyDown,
1212
- onCompositionStart,
1213
- onCompositionEnd,
1214
- placeholder,
1215
- style: {
1216
- overflow: "auto",
1217
- resize: "none",
1218
- maxHeight: `${maxHeight}px`
1159
+ language,
1160
+ style: highlightStyle,
1161
+ PreTag: "div",
1162
+ customStyle: {
1163
+ margin: 0,
1164
+ borderBottomLeftRadius: "0.375rem",
1165
+ borderBottomRightRadius: "0.375rem"
1219
1166
  },
1220
- rows: 1
1167
+ children: value
1221
1168
  }
1222
- );
1223
- }
1224
- );
1225
- var Textarea_default = AutoResizingTextarea;
1226
-
1227
- // src/hooks/use-push-to-talk.tsx
1228
- var import_react_core6 = require("@copilotkit/react-core");
1229
- var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1230
- var import_react8 = require("react");
1231
- var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
1232
- if (!mediaStreamRef.current || !audioContextRef.current) {
1233
- mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
1234
- audioContextRef.current = new window.AudioContext();
1235
- yield audioContextRef.current.resume();
1236
- }
1237
- mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
1238
- mediaRecorderRef.current.start(1e3);
1239
- mediaRecorderRef.current.ondataavailable = (event) => {
1240
- recordedChunks.push(event.data);
1241
- };
1242
- mediaRecorderRef.current.onstop = onStop;
1243
- });
1244
- var stopRecording = (mediaRecorderRef) => {
1245
- if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
1246
- mediaRecorderRef.current.stop();
1247
- }
1248
- };
1249
- var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
1250
- const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
1251
- const formData = new FormData();
1252
- formData.append("file", completeBlob, "recording.mp4");
1253
- const response = yield fetch(transcribeAudioUrl, {
1254
- method: "POST",
1255
- body: formData
1256
- });
1257
- if (!response.ok) {
1258
- throw new Error(`Error: ${response.statusText}`);
1259
- }
1260
- const transcription = yield response.json();
1261
- return transcription.text;
1262
- });
1263
- var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
1264
- const encodedText = encodeURIComponent(text);
1265
- const url = `${textToSpeechUrl}?text=${encodedText}`;
1266
- fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
1267
- const source = audioContext.createBufferSource();
1268
- source.buffer = audioBuffer;
1269
- source.connect(audioContext.destination);
1270
- source.start(0);
1271
- }).catch((error) => {
1272
- console.error("Error with decoding audio data", error);
1273
- });
1274
- };
1275
- var usePushToTalk = ({
1276
- sendFunction,
1277
- inProgress
1278
- }) => {
1279
- const [pushToTalkState, setPushToTalkState] = (0, import_react8.useState)("idle");
1280
- const mediaStreamRef = (0, import_react8.useRef)(null);
1281
- const audioContextRef = (0, import_react8.useRef)(null);
1282
- const mediaRecorderRef = (0, import_react8.useRef)(null);
1283
- const recordedChunks = (0, import_react8.useRef)([]);
1284
- const generalContext = (0, import_react_core6.useCopilotContext)();
1285
- const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
1286
- const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
1287
- const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react8.useState)(null);
1288
- (0, import_react8.useEffect)(() => {
1289
- if (pushToTalkState === "recording") {
1290
- startRecording(
1291
- mediaStreamRef,
1292
- mediaRecorderRef,
1293
- audioContextRef,
1294
- recordedChunks.current,
1295
- () => {
1296
- setPushToTalkState("transcribing");
1297
- }
1298
- );
1299
- } else {
1300
- stopRecording(mediaRecorderRef);
1301
- if (pushToTalkState === "transcribing") {
1302
- transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
1303
- (transcription) => __async(void 0, null, function* () {
1304
- recordedChunks.current = [];
1305
- setPushToTalkState("idle");
1306
- const message = yield sendFunction(transcription);
1307
- setStartReadingFromMessageId(message.id);
1308
- })
1309
- );
1310
- }
1311
- }
1312
- return () => {
1313
- stopRecording(mediaRecorderRef);
1314
- };
1315
- }, [pushToTalkState]);
1316
- (0, import_react8.useEffect)(() => {
1317
- if (inProgress === false && startReadingFromMessageId) {
1318
- const lastMessageIndex = context.messages.findIndex(
1319
- (message) => message.id === startReadingFromMessageId
1320
- );
1321
- const aguiMessages = (0, import_runtime_client_gql.gqlToAGUI)(context.messages);
1322
- const messagesAfterLast = aguiMessages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant");
1323
- const text = messagesAfterLast.map((message) => message.content).join("\n");
1324
- playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
1325
- setStartReadingFromMessageId(null);
1326
- }
1327
- }, [startReadingFromMessageId, inProgress]);
1328
- return { pushToTalkState, setPushToTalkState };
1329
- };
1330
-
1331
- // src/components/chat/Input.tsx
1332
- var import_react_core7 = require("@copilotkit/react-core");
1333
-
1334
- // src/hooks/use-dark-mode.ts
1335
- var useDarkMode = () => {
1336
- if (typeof window === "undefined")
1337
- return false;
1338
- return document.documentElement.classList.contains("dark") || document.body.classList.contains("dark") || document.documentElement.getAttribute("data-theme") === "dark" || document.body.getAttribute("data-theme") === "dark" || window.matchMedia("(prefers-color-scheme: dark)").matches;
1339
- };
1340
-
1341
- // src/components/chat/PoweredByTag.tsx
1342
- var import_jsx_runtime12 = require("react/jsx-runtime");
1343
- function PoweredByTag({ showPoweredBy = true }) {
1344
- const isDark = useDarkMode();
1345
- if (!showPoweredBy) {
1346
- return null;
1347
- }
1348
- const poweredByStyle = {
1349
- visibility: "visible",
1350
- display: "block",
1351
- position: "static",
1352
- textAlign: "center",
1353
- fontSize: "12px",
1354
- padding: "3px 0",
1355
- color: isDark ? "rgb(69, 69, 69)" : "rgb(214, 214, 214)"
1356
- };
1357
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "poweredBy", style: poweredByStyle, children: "Powered by CopilotKit" }) });
1358
- }
1359
-
1360
- // src/components/chat/Input.tsx
1361
- var import_jsx_runtime13 = require("react/jsx-runtime");
1362
- var MAX_NEWLINES = 6;
1363
- var Input = ({
1364
- inProgress,
1365
- onSend,
1366
- isVisible = false,
1367
- onStop,
1368
- onUpload,
1369
- hideStopButton = false
1370
- }) => {
1371
- var _a, _b;
1372
- const context = useChatContext();
1373
- const copilotContext = (0, import_react_core7.useCopilotContext)();
1374
- const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
1375
- const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
1376
- const textareaRef = (0, import_react9.useRef)(null);
1377
- const [isComposing, setIsComposing] = (0, import_react9.useState)(false);
1378
- const handleDivClick = (event) => {
1379
- var _a2;
1380
- const target = event.target;
1381
- if (target.closest("button"))
1382
- return;
1383
- if (target.tagName === "TEXTAREA")
1384
- return;
1385
- (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
1386
- };
1387
- const [text, setText] = (0, import_react9.useState)("");
1388
- const send = () => {
1389
- var _a2;
1390
- if (inProgress)
1391
- return;
1392
- onSend(text);
1393
- setText("");
1394
- (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
1395
- };
1396
- const { pushToTalkState, setPushToTalkState } = usePushToTalk({
1397
- sendFunction: onSend,
1398
- inProgress
1399
- });
1400
- const isInProgress = inProgress || pushToTalkState === "transcribing";
1401
- const buttonIcon = isInProgress && !hideStopButton ? context.icons.stopIcon : context.icons.sendIcon;
1402
- const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
1403
- const canSend = (0, import_react9.useMemo)(() => {
1404
- var _a2;
1405
- const interruptEvent = (_a2 = copilotContext.langGraphInterruptAction) == null ? void 0 : _a2.event;
1406
- const interruptInProgress = (interruptEvent == null ? void 0 : interruptEvent.name) === "LangGraphInterruptEvent" && !(interruptEvent == null ? void 0 : interruptEvent.response);
1407
- return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interruptInProgress;
1408
- }, [(_b = copilotContext.langGraphInterruptAction) == null ? void 0 : _b.event, isInProgress, text, pushToTalkState]);
1409
- const canStop = (0, import_react9.useMemo)(() => {
1410
- return isInProgress && !hideStopButton;
1411
- }, [isInProgress, hideStopButton]);
1412
- const sendDisabled = !canSend && !canStop;
1413
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `copilotKitInputContainer ${showPoweredBy ? "poweredByContainer" : ""}`, children: [
1414
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
1415
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1416
- Textarea_default,
1417
- {
1418
- ref: textareaRef,
1419
- placeholder: context.labels.placeholder,
1420
- autoFocus: false,
1421
- maxRows: MAX_NEWLINES,
1422
- value: text,
1423
- onChange: (event) => setText(event.target.value),
1424
- onCompositionStart: () => setIsComposing(true),
1425
- onCompositionEnd: () => setIsComposing(false),
1426
- onKeyDown: (event) => {
1427
- if (event.key === "Enter" && !event.shiftKey && !isComposing) {
1428
- event.preventDefault();
1429
- if (canSend) {
1430
- send();
1431
- }
1432
- }
1433
- }
1434
- }
1435
- ),
1436
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "copilotKitInputControls", children: [
1437
- onUpload && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { onClick: onUpload, className: "copilotKitInputControlButton", children: context.icons.uploadIcon }),
1438
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { flexGrow: 1 } }),
1439
- showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1440
- "button",
1441
- {
1442
- onClick: () => setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing"),
1443
- className: pushToTalkState === "recording" ? "copilotKitInputControlButton copilotKitPushToTalkRecording" : "copilotKitInputControlButton",
1444
- children: context.icons.pushToTalkIcon
1445
- }
1446
- ),
1447
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1448
- "button",
1449
- {
1450
- disabled: sendDisabled,
1451
- onClick: isInProgress && !hideStopButton ? onStop : send,
1452
- "data-copilotkit-in-progress": inProgress,
1453
- "data-test-id": inProgress ? "copilot-chat-request-in-progress" : "copilot-chat-ready",
1454
- className: "copilotKitInputControlButton",
1455
- children: buttonIcon
1456
- }
1457
- )
1458
- ] })
1459
- ] }),
1460
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(PoweredByTag, { showPoweredBy })
1461
- ] });
1462
- };
1463
-
1464
- // src/components/chat/messages/UserMessage.tsx
1465
- var import_jsx_runtime14 = require("react/jsx-runtime");
1466
- var UserMessage = (props) => {
1467
- const { message, ImageRenderer: ImageRenderer2 } = props;
1468
- const isImageMessage = message && "image" in message && message.image;
1469
- if (isImageMessage) {
1470
- const imageMessage = message;
1471
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ImageRenderer2, { image: imageMessage.image, content: imageMessage.content }) });
1472
- }
1473
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "copilotKitMessage copilotKitUserMessage", children: message == null ? void 0 : message.content });
1474
- };
1475
-
1476
- // src/components/chat/Markdown.tsx
1477
- var import_react11 = require("react");
1478
- var import_react_markdown = __toESM(require("react-markdown"));
1479
-
1480
- // src/components/chat/CodeBlock.tsx
1481
- var import_react10 = require("react");
1482
- var import_react_syntax_highlighter = require("react-syntax-highlighter");
1483
-
1484
- // src/hooks/use-copy-to-clipboard.tsx
1485
- var React7 = __toESM(require("react"));
1486
- function useCopyToClipboard({ timeout = 2e3 }) {
1487
- const [isCopied, setIsCopied] = React7.useState(false);
1488
- const copyToClipboard = (value) => {
1489
- var _a;
1490
- if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
1491
- return;
1492
- }
1493
- if (!value) {
1494
- return;
1495
- }
1496
- navigator.clipboard.writeText(value).then(() => {
1497
- setIsCopied(true);
1498
- setTimeout(() => {
1499
- setIsCopied(false);
1500
- }, timeout);
1501
- });
1502
- };
1503
- return { isCopied, copyToClipboard };
1504
- }
1505
-
1506
- // src/components/chat/CodeBlock.tsx
1507
- var import_jsx_runtime15 = require("react/jsx-runtime");
1508
- var programmingLanguages = {
1509
- javascript: ".js",
1510
- python: ".py",
1511
- java: ".java",
1512
- c: ".c",
1513
- cpp: ".cpp",
1514
- "c++": ".cpp",
1515
- "c#": ".cs",
1516
- ruby: ".rb",
1517
- php: ".php",
1518
- swift: ".swift",
1519
- "objective-c": ".m",
1520
- kotlin: ".kt",
1521
- typescript: ".ts",
1522
- go: ".go",
1523
- perl: ".pl",
1524
- rust: ".rs",
1525
- scala: ".scala",
1526
- haskell: ".hs",
1527
- lua: ".lua",
1528
- shell: ".sh",
1529
- sql: ".sql",
1530
- html: ".html",
1531
- css: ".css"
1532
- // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
1533
- };
1534
- var generateRandomString = (length, lowercase = false) => {
1535
- const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
1536
- let result = "";
1537
- for (let i = 0; i < length; i++) {
1538
- result += chars.charAt(Math.floor(Math.random() * chars.length));
1539
- }
1540
- return lowercase ? result.toLowerCase() : result;
1541
- };
1542
- var CodeBlock = (0, import_react10.memo)(({ language, value }) => {
1543
- const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
1544
- const downloadAsFile = () => {
1545
- if (typeof window === "undefined") {
1546
- return;
1547
- }
1548
- const fileExtension = programmingLanguages[language] || ".file";
1549
- const suggestedFileName = `file-${generateRandomString(3, true)}${fileExtension}`;
1550
- const fileName = window.prompt("Enter file name", suggestedFileName);
1551
- if (!fileName) {
1552
- return;
1553
- }
1554
- const blob = new Blob([value], { type: "text/plain" });
1555
- const url = URL.createObjectURL(blob);
1556
- const link = document.createElement("a");
1557
- link.download = fileName;
1558
- link.href = url;
1559
- link.style.display = "none";
1560
- document.body.appendChild(link);
1561
- link.click();
1562
- document.body.removeChild(link);
1563
- URL.revokeObjectURL(url);
1564
- };
1565
- const onCopy = () => {
1566
- if (isCopied)
1567
- return;
1568
- copyToClipboard(value);
1569
- };
1570
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "copilotKitCodeBlock", children: [
1571
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "copilotKitCodeBlockToolbar", children: [
1572
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "copilotKitCodeBlockToolbarLanguage", children: language }),
1573
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "copilotKitCodeBlockToolbarButtons", children: [
1574
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: downloadAsFile, children: DownloadIcon }),
1575
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { className: "copilotKitCodeBlockToolbarButton", onClick: onCopy, children: isCopied ? CheckIcon : CopyIcon })
1576
- ] })
1577
- ] }),
1578
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1579
- import_react_syntax_highlighter.Prism,
1580
- {
1581
- language,
1582
- style: highlightStyle,
1583
- PreTag: "div",
1584
- customStyle: {
1585
- margin: 0,
1586
- borderBottomLeftRadius: "0.375rem",
1587
- borderBottomRightRadius: "0.375rem"
1588
- },
1589
- children: value
1590
- }
1591
- )
1169
+ )
1592
1170
  ] });
1593
1171
  });
1594
1172
  CodeBlock.displayName = "CodeBlock";
@@ -1873,308 +1451,887 @@ var highlightStyle = {
1873
1451
  boxShadow: "inset 5px 0 0 #f7d87c",
1874
1452
  zIndex: "0"
1875
1453
  }
1876
- };
1454
+ };
1455
+
1456
+ // src/components/chat/Markdown.tsx
1457
+ var import_remark_gfm = __toESM(require("remark-gfm"));
1458
+ var import_remark_math = __toESM(require("remark-math"));
1459
+ var import_rehype_raw = __toESM(require("rehype-raw"));
1460
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1461
+ var defaultComponents = {
1462
+ a(_a) {
1463
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
1464
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("a", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { target: "_blank", rel: "noopener noreferrer", children }));
1465
+ },
1466
+ // @ts-expect-error -- inline
1467
+ code(_c) {
1468
+ var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
1469
+ if (Array.isArray(children) && children.length) {
1470
+ if (children[0] == "\u258D") {
1471
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1472
+ "span",
1473
+ {
1474
+ style: {
1475
+ animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
1476
+ marginTop: "0.25rem"
1477
+ },
1478
+ children: "\u258D"
1479
+ }
1480
+ );
1481
+ }
1482
+ children[0] = (children == null ? void 0 : children[0]).replace("`\u258D`", "\u258D");
1483
+ }
1484
+ const match = /language-(\w+)/.exec(className || "");
1485
+ const hasLanguage = match && match[1];
1486
+ const content = String(children);
1487
+ const hasNewlines = content.includes("\n");
1488
+ const isInline = !hasLanguage && !hasNewlines;
1489
+ if (isInline) {
1490
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1491
+ "code",
1492
+ __spreadProps(__spreadValues({
1493
+ className: `copilotKitMarkdownElement copilotKitInlineCode ${className || ""}`
1494
+ }, props), {
1495
+ children
1496
+ })
1497
+ );
1498
+ }
1499
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1500
+ CodeBlock,
1501
+ __spreadValues({
1502
+ language: match && match[1] || "",
1503
+ value: String(children).replace(/\n$/, "")
1504
+ }, props),
1505
+ Math.random()
1506
+ );
1507
+ },
1508
+ h1: (_e) => {
1509
+ var _f = _e, { children } = _f, props = __objRest(_f, ["children"]);
1510
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h1", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1511
+ },
1512
+ h2: (_g) => {
1513
+ var _h = _g, { children } = _h, props = __objRest(_h, ["children"]);
1514
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h2", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1515
+ },
1516
+ h3: (_i) => {
1517
+ var _j = _i, { children } = _j, props = __objRest(_j, ["children"]);
1518
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h3", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1519
+ },
1520
+ h4: (_k) => {
1521
+ var _l = _k, { children } = _l, props = __objRest(_l, ["children"]);
1522
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h4", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1523
+ },
1524
+ h5: (_m) => {
1525
+ var _n = _m, { children } = _n, props = __objRest(_n, ["children"]);
1526
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h5", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1527
+ },
1528
+ h6: (_o) => {
1529
+ var _p = _o, { children } = _p, props = __objRest(_p, ["children"]);
1530
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h6", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1531
+ },
1532
+ p: (_q) => {
1533
+ var _r = _q, { children } = _r, props = __objRest(_r, ["children"]);
1534
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1535
+ },
1536
+ pre: (_s) => {
1537
+ var _t = _s, { children } = _t, props = __objRest(_t, ["children"]);
1538
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("pre", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1539
+ },
1540
+ blockquote: (_u) => {
1541
+ var _v = _u, { children } = _v, props = __objRest(_v, ["children"]);
1542
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("blockquote", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1543
+ },
1544
+ ul: (_w) => {
1545
+ var _x = _w, { children } = _x, props = __objRest(_x, ["children"]);
1546
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("ul", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1547
+ },
1548
+ li: (_y) => {
1549
+ var _z = _y, { children } = _z, props = __objRest(_z, ["children"]);
1550
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1551
+ }
1552
+ };
1553
+ var MemoizedReactMarkdown = (0, import_react7.memo)(
1554
+ import_react_markdown.default,
1555
+ (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
1556
+ );
1557
+ var Markdown = ({ content, components }) => {
1558
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1559
+ MemoizedReactMarkdown,
1560
+ {
1561
+ components: __spreadValues(__spreadValues({}, defaultComponents), components),
1562
+ remarkPlugins: [import_remark_gfm.default, import_remark_math.default],
1563
+ rehypePlugins: [import_rehype_raw.default],
1564
+ children: content
1565
+ }
1566
+ ) });
1567
+ };
1568
+
1569
+ // src/components/chat/messages/AssistantMessage.tsx
1570
+ var import_react8 = require("react");
1571
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1572
+ var AssistantMessage = (props) => {
1573
+ var _a;
1574
+ const { icons, labels } = useChatContext();
1575
+ const {
1576
+ message,
1577
+ isLoading,
1578
+ onRegenerate,
1579
+ onCopy,
1580
+ onThumbsUp,
1581
+ onThumbsDown,
1582
+ isCurrentMessage,
1583
+ markdownTagRenderers
1584
+ } = props;
1585
+ const [copied, setCopied] = (0, import_react8.useState)(false);
1586
+ const handleCopy = () => {
1587
+ const content2 = (message == null ? void 0 : message.content) || "";
1588
+ if (content2 && onCopy) {
1589
+ navigator.clipboard.writeText(content2);
1590
+ setCopied(true);
1591
+ onCopy(content2);
1592
+ setTimeout(() => setCopied(false), 2e3);
1593
+ } else if (content2) {
1594
+ navigator.clipboard.writeText(content2);
1595
+ setCopied(true);
1596
+ setTimeout(() => setCopied(false), 2e3);
1597
+ }
1598
+ };
1599
+ const handleRegenerate = () => {
1600
+ if (onRegenerate)
1601
+ onRegenerate();
1602
+ };
1603
+ const handleThumbsUp = () => {
1604
+ if (onThumbsUp && message)
1605
+ onThumbsUp(message);
1606
+ };
1607
+ const handleThumbsDown = () => {
1608
+ if (onThumbsDown && message)
1609
+ onThumbsDown(message);
1610
+ };
1611
+ const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: icons.activityIcon });
1612
+ const content = (message == null ? void 0 : message.content) || "";
1613
+ const subComponent = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message);
1614
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
1615
+ content && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
1616
+ content && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Markdown, { content, components: markdownTagRenderers }),
1617
+ content && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
1618
+ "div",
1619
+ {
1620
+ className: `copilotKitMessageControls ${isCurrentMessage ? "currentMessage" : ""}`,
1621
+ children: [
1622
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1623
+ "button",
1624
+ {
1625
+ className: "copilotKitMessageControlButton",
1626
+ onClick: handleRegenerate,
1627
+ "aria-label": labels.regenerateResponse,
1628
+ title: labels.regenerateResponse,
1629
+ children: icons.regenerateIcon
1630
+ }
1631
+ ),
1632
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1633
+ "button",
1634
+ {
1635
+ className: "copilotKitMessageControlButton",
1636
+ onClick: handleCopy,
1637
+ "aria-label": labels.copyToClipboard,
1638
+ title: labels.copyToClipboard,
1639
+ children: copied ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { style: { fontSize: "10px", fontWeight: "bold" }, children: "\u2713" }) : icons.copyIcon
1640
+ }
1641
+ ),
1642
+ onThumbsUp && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1643
+ "button",
1644
+ {
1645
+ className: "copilotKitMessageControlButton",
1646
+ onClick: handleThumbsUp,
1647
+ "aria-label": labels.thumbsUp,
1648
+ title: labels.thumbsUp,
1649
+ children: icons.thumbsUpIcon
1650
+ }
1651
+ ),
1652
+ onThumbsDown && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1653
+ "button",
1654
+ {
1655
+ className: "copilotKitMessageControlButton",
1656
+ onClick: handleThumbsDown,
1657
+ "aria-label": labels.thumbsDown,
1658
+ title: labels.thumbsDown,
1659
+ children: icons.thumbsDownIcon
1660
+ }
1661
+ )
1662
+ ]
1663
+ }
1664
+ )
1665
+ ] }),
1666
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }),
1667
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(LoadingIcon, {})
1668
+ ] });
1669
+ };
1670
+
1671
+ // src/components/chat/messages/ImageRenderer.tsx
1672
+ var import_react9 = require("react");
1673
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1674
+ var ImageRenderer = ({ image, content, className = "" }) => {
1675
+ const [imageError, setImageError] = (0, import_react9.useState)(false);
1676
+ const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
1677
+ const altText = content || "User uploaded image";
1678
+ const handleImageError = () => {
1679
+ setImageError(true);
1680
+ };
1681
+ if (imageError) {
1682
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: `copilotKitImageRendering copilotKitImageRenderingError ${className}`, children: [
1683
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "copilotKitImageRenderingErrorMessage", children: "Failed to load image" }),
1684
+ content && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "copilotKitImageRenderingContent", children: content })
1685
+ ] });
1686
+ }
1687
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: `copilotKitImageRendering ${className}`, children: [
1688
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1689
+ "img",
1690
+ {
1691
+ src: imageSrc,
1692
+ alt: altText,
1693
+ className: "copilotKitImageRenderingImage",
1694
+ onError: handleImageError
1695
+ }
1696
+ ),
1697
+ content && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "copilotKitImageRenderingContent", children: content })
1698
+ ] });
1699
+ };
1700
+
1701
+ // src/components/chat/messages/RenderMessage.tsx
1702
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1703
+ function RenderMessage(_a) {
1704
+ var _b = _a, {
1705
+ UserMessage: UserMessage2 = UserMessage,
1706
+ AssistantMessage: AssistantMessage2 = AssistantMessage,
1707
+ ImageRenderer: ImageRenderer2 = ImageRenderer
1708
+ } = _b, props = __objRest(_b, [
1709
+ "UserMessage",
1710
+ "AssistantMessage",
1711
+ "ImageRenderer"
1712
+ ]);
1713
+ var _a2;
1714
+ const {
1715
+ message,
1716
+ inProgress,
1717
+ index,
1718
+ isCurrentMessage,
1719
+ onRegenerate,
1720
+ onCopy,
1721
+ onThumbsUp,
1722
+ onThumbsDown,
1723
+ markdownTagRenderers
1724
+ } = props;
1725
+ switch (message.role) {
1726
+ case "user":
1727
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1728
+ UserMessage2,
1729
+ {
1730
+ rawData: message,
1731
+ "data-message-role": "user",
1732
+ message,
1733
+ ImageRenderer: ImageRenderer2
1734
+ },
1735
+ index
1736
+ );
1737
+ case "assistant":
1738
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1739
+ AssistantMessage2,
1740
+ {
1741
+ "data-message-role": "assistant",
1742
+ subComponent: (_a2 = message.generativeUI) == null ? void 0 : _a2.call(message),
1743
+ rawData: message,
1744
+ message,
1745
+ isLoading: inProgress && isCurrentMessage && !message.content,
1746
+ isGenerating: inProgress && isCurrentMessage && !!message.content,
1747
+ isCurrentMessage,
1748
+ onRegenerate: () => onRegenerate == null ? void 0 : onRegenerate(message.id),
1749
+ onCopy,
1750
+ onThumbsUp,
1751
+ onThumbsDown,
1752
+ markdownTagRenderers,
1753
+ ImageRenderer: ImageRenderer2
1754
+ },
1755
+ index
1756
+ );
1757
+ }
1758
+ }
1759
+
1760
+ // src/components/chat/messages/LegacyRenderMessage.tsx
1761
+ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1762
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1763
+ var LegacyRenderMessage = ({
1764
+ message,
1765
+ inProgress,
1766
+ index,
1767
+ isCurrentMessage,
1768
+ actionResult,
1769
+ AssistantMessage: AssistantMessage2,
1770
+ UserMessage: UserMessage2,
1771
+ ImageRenderer: ImageRenderer2,
1772
+ onRegenerate,
1773
+ onCopy,
1774
+ onThumbsUp,
1775
+ onThumbsDown,
1776
+ markdownTagRenderers,
1777
+ legacyProps
1778
+ }) => {
1779
+ var _a;
1780
+ const {
1781
+ RenderTextMessage,
1782
+ RenderActionExecutionMessage,
1783
+ RenderAgentStateMessage,
1784
+ RenderResultMessage,
1785
+ RenderImageMessage
1786
+ } = legacyProps;
1787
+ const deprecatedMessage = (_a = (0, import_runtime_client_gql.aguiToGQL)(message)[0]) != null ? _a : void 0;
1788
+ if (deprecatedMessage.isTextMessage() && RenderTextMessage) {
1789
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1790
+ RenderTextMessage,
1791
+ {
1792
+ message,
1793
+ inProgress,
1794
+ index,
1795
+ isCurrentMessage,
1796
+ AssistantMessage: AssistantMessage2,
1797
+ UserMessage: UserMessage2,
1798
+ onRegenerate,
1799
+ onCopy,
1800
+ onThumbsUp,
1801
+ onThumbsDown,
1802
+ markdownTagRenderers
1803
+ }
1804
+ );
1805
+ }
1806
+ if (deprecatedMessage.isActionExecutionMessage() && RenderActionExecutionMessage) {
1807
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1808
+ RenderActionExecutionMessage,
1809
+ {
1810
+ message,
1811
+ inProgress,
1812
+ index,
1813
+ isCurrentMessage,
1814
+ actionResult,
1815
+ AssistantMessage: AssistantMessage2,
1816
+ UserMessage: UserMessage2
1817
+ }
1818
+ );
1819
+ }
1820
+ if (deprecatedMessage.isAgentStateMessage() && RenderAgentStateMessage) {
1821
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1822
+ RenderAgentStateMessage,
1823
+ {
1824
+ message,
1825
+ inProgress,
1826
+ index,
1827
+ isCurrentMessage,
1828
+ AssistantMessage: AssistantMessage2,
1829
+ UserMessage: UserMessage2
1830
+ }
1831
+ );
1832
+ }
1833
+ if (deprecatedMessage.isResultMessage() && RenderResultMessage) {
1834
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1835
+ RenderResultMessage,
1836
+ {
1837
+ message,
1838
+ inProgress,
1839
+ index,
1840
+ isCurrentMessage,
1841
+ AssistantMessage: AssistantMessage2,
1842
+ UserMessage: UserMessage2
1843
+ }
1844
+ );
1845
+ }
1846
+ if (deprecatedMessage.isImageMessage() && RenderImageMessage) {
1847
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1848
+ RenderImageMessage,
1849
+ {
1850
+ message,
1851
+ inProgress,
1852
+ index,
1853
+ isCurrentMessage,
1854
+ AssistantMessage: AssistantMessage2,
1855
+ UserMessage: UserMessage2
1856
+ }
1857
+ );
1858
+ }
1859
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1860
+ RenderMessage,
1861
+ {
1862
+ message,
1863
+ inProgress,
1864
+ index,
1865
+ isCurrentMessage,
1866
+ AssistantMessage: AssistantMessage2,
1867
+ UserMessage: UserMessage2,
1868
+ ImageRenderer: ImageRenderer2,
1869
+ onRegenerate,
1870
+ onCopy,
1871
+ onThumbsUp,
1872
+ onThumbsDown,
1873
+ markdownTagRenderers
1874
+ }
1875
+ );
1876
+ };
1877
+
1878
+ // src/components/chat/Messages.tsx
1879
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1880
+ var Messages = ({
1881
+ inProgress,
1882
+ children,
1883
+ RenderMessage: RenderMessage2,
1884
+ AssistantMessage: AssistantMessage2,
1885
+ UserMessage: UserMessage2,
1886
+ ImageRenderer: ImageRenderer2,
1887
+ onRegenerate,
1888
+ onCopy,
1889
+ onThumbsUp,
1890
+ onThumbsDown,
1891
+ markdownTagRenderers,
1892
+ // Legacy props
1893
+ RenderTextMessage,
1894
+ RenderActionExecutionMessage,
1895
+ RenderAgentStateMessage,
1896
+ RenderResultMessage,
1897
+ RenderImageMessage
1898
+ }) => {
1899
+ const { labels } = useChatContext();
1900
+ const { messages: visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
1901
+ const initialMessages = (0, import_react10.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
1902
+ const messages = [...initialMessages, ...visibleMessages];
1903
+ const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
1904
+ const hasLegacyProps = !!(RenderTextMessage || RenderActionExecutionMessage || RenderAgentStateMessage || RenderResultMessage || RenderImageMessage);
1905
+ (0, import_react10.useEffect)(() => {
1906
+ if (hasLegacyProps) {
1907
+ console.warn(
1908
+ "[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"
1909
+ );
1910
+ }
1911
+ }, [hasLegacyProps]);
1912
+ const legacyProps = (0, import_react10.useMemo)(
1913
+ () => ({
1914
+ RenderTextMessage,
1915
+ RenderActionExecutionMessage,
1916
+ RenderAgentStateMessage,
1917
+ RenderResultMessage,
1918
+ RenderImageMessage
1919
+ }),
1920
+ [
1921
+ RenderTextMessage,
1922
+ RenderActionExecutionMessage,
1923
+ RenderAgentStateMessage,
1924
+ RenderResultMessage,
1925
+ RenderImageMessage
1926
+ ]
1927
+ );
1928
+ const MessageRenderer = hasLegacyProps ? (props) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(LegacyRenderMessage, __spreadProps(__spreadValues({}, props), { legacyProps })) : RenderMessage2;
1929
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [
1930
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "copilotKitMessagesContainer", children: [
1931
+ messages.map((message, index) => {
1932
+ const isCurrentMessage = index === messages.length - 1;
1933
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1934
+ MessageRenderer,
1935
+ {
1936
+ message,
1937
+ inProgress,
1938
+ index,
1939
+ isCurrentMessage,
1940
+ AssistantMessage: AssistantMessage2,
1941
+ UserMessage: UserMessage2,
1942
+ ImageRenderer: ImageRenderer2,
1943
+ onRegenerate,
1944
+ onCopy,
1945
+ onThumbsUp,
1946
+ onThumbsDown,
1947
+ markdownTagRenderers
1948
+ },
1949
+ index
1950
+ );
1951
+ }),
1952
+ interrupt
1953
+ ] }),
1954
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("footer", { className: "copilotKitMessagesFooter", ref: messagesEndRef, children })
1955
+ ] });
1956
+ };
1957
+ function makeInitialMessages(initial) {
1958
+ if (!initial)
1959
+ return [];
1960
+ if (Array.isArray(initial)) {
1961
+ return initial.map((message) => {
1962
+ return {
1963
+ id: message,
1964
+ role: "assistant",
1965
+ content: message
1966
+ };
1967
+ });
1968
+ }
1969
+ return [
1970
+ {
1971
+ id: initial,
1972
+ role: "assistant",
1973
+ content: initial
1974
+ }
1975
+ ];
1976
+ }
1977
+ function useScrollToBottom(messages) {
1978
+ const messagesEndRef = (0, import_react10.useRef)(null);
1979
+ const messagesContainerRef = (0, import_react10.useRef)(null);
1980
+ const isProgrammaticScrollRef = (0, import_react10.useRef)(false);
1981
+ const isUserScrollUpRef = (0, import_react10.useRef)(false);
1982
+ const scrollToBottom = () => {
1983
+ if (messagesContainerRef.current && messagesEndRef.current) {
1984
+ isProgrammaticScrollRef.current = true;
1985
+ messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;
1986
+ }
1987
+ };
1988
+ const handleScroll = () => {
1989
+ if (isProgrammaticScrollRef.current) {
1990
+ isProgrammaticScrollRef.current = false;
1991
+ return;
1992
+ }
1993
+ if (messagesContainerRef.current) {
1994
+ const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
1995
+ isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
1996
+ }
1997
+ };
1998
+ (0, import_react10.useEffect)(() => {
1999
+ const container = messagesContainerRef.current;
2000
+ if (container) {
2001
+ container.addEventListener("scroll", handleScroll);
2002
+ }
2003
+ return () => {
2004
+ if (container) {
2005
+ container.removeEventListener("scroll", handleScroll);
2006
+ }
2007
+ };
2008
+ }, []);
2009
+ (0, import_react10.useEffect)(() => {
2010
+ const container = messagesContainerRef.current;
2011
+ if (!container) {
2012
+ return;
2013
+ }
2014
+ const mutationObserver = new MutationObserver(() => {
2015
+ if (!isUserScrollUpRef.current) {
2016
+ scrollToBottom();
2017
+ }
2018
+ });
2019
+ mutationObserver.observe(container, {
2020
+ childList: true,
2021
+ subtree: true,
2022
+ characterData: true
2023
+ });
2024
+ return () => {
2025
+ mutationObserver.disconnect();
2026
+ };
2027
+ }, []);
2028
+ (0, import_react10.useEffect)(() => {
2029
+ isUserScrollUpRef.current = false;
2030
+ scrollToBottom();
2031
+ }, [messages.filter((m) => m.role === "user").length]);
2032
+ return { messagesEndRef, messagesContainerRef };
2033
+ }
2034
+
2035
+ // src/components/chat/Input.tsx
2036
+ var import_react13 = require("react");
2037
+
2038
+ // src/components/chat/Textarea.tsx
2039
+ var import_react11 = require("react");
2040
+ var import_jsx_runtime18 = require("react/jsx-runtime");
2041
+ var AutoResizingTextarea = (0, import_react11.forwardRef)(
2042
+ ({
2043
+ maxRows = 1,
2044
+ placeholder,
2045
+ value,
2046
+ onChange,
2047
+ onKeyDown,
2048
+ onCompositionStart,
2049
+ onCompositionEnd,
2050
+ autoFocus
2051
+ }, ref) => {
2052
+ const internalTextareaRef = (0, import_react11.useRef)(null);
2053
+ const [maxHeight, setMaxHeight] = (0, import_react11.useState)(0);
2054
+ (0, import_react11.useImperativeHandle)(ref, () => internalTextareaRef.current);
2055
+ (0, import_react11.useEffect)(() => {
2056
+ const calculateMaxHeight = () => {
2057
+ const textarea = internalTextareaRef.current;
2058
+ if (textarea) {
2059
+ textarea.style.height = "auto";
2060
+ const singleRowHeight = textarea.scrollHeight;
2061
+ setMaxHeight(singleRowHeight * maxRows);
2062
+ if (autoFocus) {
2063
+ textarea.focus();
2064
+ }
2065
+ }
2066
+ };
2067
+ calculateMaxHeight();
2068
+ }, [maxRows]);
2069
+ (0, import_react11.useEffect)(() => {
2070
+ const textarea = internalTextareaRef.current;
2071
+ if (textarea) {
2072
+ textarea.style.height = "auto";
2073
+ textarea.style.height = `${Math.min(textarea.scrollHeight, maxHeight)}px`;
2074
+ }
2075
+ }, [value, maxHeight]);
2076
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2077
+ "textarea",
2078
+ {
2079
+ ref: internalTextareaRef,
2080
+ value,
2081
+ onChange,
2082
+ onKeyDown,
2083
+ onCompositionStart,
2084
+ onCompositionEnd,
2085
+ placeholder,
2086
+ style: {
2087
+ overflow: "auto",
2088
+ resize: "none",
2089
+ maxHeight: `${maxHeight}px`
2090
+ },
2091
+ rows: 1
2092
+ }
2093
+ );
2094
+ }
2095
+ );
2096
+ var Textarea_default = AutoResizingTextarea;
1877
2097
 
1878
- // src/components/chat/Markdown.tsx
1879
- var import_remark_gfm = __toESM(require("remark-gfm"));
1880
- var import_remark_math = __toESM(require("remark-math"));
1881
- var import_rehype_raw = __toESM(require("rehype-raw"));
1882
- var import_jsx_runtime16 = require("react/jsx-runtime");
1883
- var defaultComponents = {
1884
- a(_a) {
1885
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
1886
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("a", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { target: "_blank", rel: "noopener noreferrer", children }));
1887
- },
1888
- // @ts-expect-error -- inline
1889
- code(_c) {
1890
- var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
1891
- if (Array.isArray(children) && children.length) {
1892
- if (children[0] == "\u258D") {
1893
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1894
- "span",
1895
- {
1896
- style: {
1897
- animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
1898
- marginTop: "0.25rem"
1899
- },
1900
- children: "\u258D"
1901
- }
2098
+ // src/hooks/use-push-to-talk.tsx
2099
+ var import_react_core6 = require("@copilotkit/react-core");
2100
+ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
2101
+ var import_react12 = require("react");
2102
+ var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
2103
+ if (!mediaStreamRef.current || !audioContextRef.current) {
2104
+ mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
2105
+ audioContextRef.current = new window.AudioContext();
2106
+ yield audioContextRef.current.resume();
2107
+ }
2108
+ mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
2109
+ mediaRecorderRef.current.start(1e3);
2110
+ mediaRecorderRef.current.ondataavailable = (event) => {
2111
+ recordedChunks.push(event.data);
2112
+ };
2113
+ mediaRecorderRef.current.onstop = onStop;
2114
+ });
2115
+ var stopRecording = (mediaRecorderRef) => {
2116
+ if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
2117
+ mediaRecorderRef.current.stop();
2118
+ }
2119
+ };
2120
+ var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
2121
+ const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
2122
+ const formData = new FormData();
2123
+ formData.append("file", completeBlob, "recording.mp4");
2124
+ const response = yield fetch(transcribeAudioUrl, {
2125
+ method: "POST",
2126
+ body: formData
2127
+ });
2128
+ if (!response.ok) {
2129
+ throw new Error(`Error: ${response.statusText}`);
2130
+ }
2131
+ const transcription = yield response.json();
2132
+ return transcription.text;
2133
+ });
2134
+ var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
2135
+ const encodedText = encodeURIComponent(text);
2136
+ const url = `${textToSpeechUrl}?text=${encodedText}`;
2137
+ fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
2138
+ const source = audioContext.createBufferSource();
2139
+ source.buffer = audioBuffer;
2140
+ source.connect(audioContext.destination);
2141
+ source.start(0);
2142
+ }).catch((error) => {
2143
+ console.error("Error with decoding audio data", error);
2144
+ });
2145
+ };
2146
+ var usePushToTalk = ({
2147
+ sendFunction,
2148
+ inProgress
2149
+ }) => {
2150
+ const [pushToTalkState, setPushToTalkState] = (0, import_react12.useState)("idle");
2151
+ const mediaStreamRef = (0, import_react12.useRef)(null);
2152
+ const audioContextRef = (0, import_react12.useRef)(null);
2153
+ const mediaRecorderRef = (0, import_react12.useRef)(null);
2154
+ const recordedChunks = (0, import_react12.useRef)([]);
2155
+ const generalContext = (0, import_react_core6.useCopilotContext)();
2156
+ const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
2157
+ const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
2158
+ const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react12.useState)(null);
2159
+ (0, import_react12.useEffect)(() => {
2160
+ if (pushToTalkState === "recording") {
2161
+ startRecording(
2162
+ mediaStreamRef,
2163
+ mediaRecorderRef,
2164
+ audioContextRef,
2165
+ recordedChunks.current,
2166
+ () => {
2167
+ setPushToTalkState("transcribing");
2168
+ }
2169
+ );
2170
+ } else {
2171
+ stopRecording(mediaRecorderRef);
2172
+ if (pushToTalkState === "transcribing") {
2173
+ transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
2174
+ (transcription) => __async(void 0, null, function* () {
2175
+ recordedChunks.current = [];
2176
+ setPushToTalkState("idle");
2177
+ const message = yield sendFunction(transcription);
2178
+ setStartReadingFromMessageId(message.id);
2179
+ })
1902
2180
  );
1903
2181
  }
1904
- children[0] = (children == null ? void 0 : children[0]).replace("`\u258D`", "\u258D");
1905
2182
  }
1906
- const match = /language-(\w+)/.exec(className || "");
1907
- const hasLanguage = match && match[1];
1908
- const content = String(children);
1909
- const hasNewlines = content.includes("\n");
1910
- const isInline = !hasLanguage && !hasNewlines;
1911
- if (isInline) {
1912
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1913
- "code",
1914
- __spreadProps(__spreadValues({
1915
- className: `copilotKitMarkdownElement copilotKitInlineCode ${className || ""}`
1916
- }, props), {
1917
- children
1918
- })
2183
+ return () => {
2184
+ stopRecording(mediaRecorderRef);
2185
+ };
2186
+ }, [pushToTalkState]);
2187
+ (0, import_react12.useEffect)(() => {
2188
+ if (inProgress === false && startReadingFromMessageId) {
2189
+ const lastMessageIndex = context.messages.findIndex(
2190
+ (message) => message.id === startReadingFromMessageId
1919
2191
  );
2192
+ const aguiMessages = (0, import_runtime_client_gql2.gqlToAGUI)(context.messages);
2193
+ const messagesAfterLast = aguiMessages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant");
2194
+ const text = messagesAfterLast.map((message) => message.content).join("\n");
2195
+ playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
2196
+ setStartReadingFromMessageId(null);
1920
2197
  }
1921
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1922
- CodeBlock,
1923
- __spreadValues({
1924
- language: match && match[1] || "",
1925
- value: String(children).replace(/\n$/, "")
1926
- }, props),
1927
- Math.random()
1928
- );
1929
- },
1930
- h1: (_e) => {
1931
- var _f = _e, { children } = _f, props = __objRest(_f, ["children"]);
1932
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("h1", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1933
- },
1934
- h2: (_g) => {
1935
- var _h = _g, { children } = _h, props = __objRest(_h, ["children"]);
1936
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("h2", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1937
- },
1938
- h3: (_i) => {
1939
- var _j = _i, { children } = _j, props = __objRest(_j, ["children"]);
1940
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("h3", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1941
- },
1942
- h4: (_k) => {
1943
- var _l = _k, { children } = _l, props = __objRest(_l, ["children"]);
1944
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("h4", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1945
- },
1946
- h5: (_m) => {
1947
- var _n = _m, { children } = _n, props = __objRest(_n, ["children"]);
1948
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("h5", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1949
- },
1950
- h6: (_o) => {
1951
- var _p = _o, { children } = _p, props = __objRest(_p, ["children"]);
1952
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("h6", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1953
- },
1954
- p: (_q) => {
1955
- var _r = _q, { children } = _r, props = __objRest(_r, ["children"]);
1956
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("p", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1957
- },
1958
- pre: (_s) => {
1959
- var _t = _s, { children } = _t, props = __objRest(_t, ["children"]);
1960
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("pre", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1961
- },
1962
- blockquote: (_u) => {
1963
- var _v = _u, { children } = _v, props = __objRest(_v, ["children"]);
1964
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("blockquote", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1965
- },
1966
- ul: (_w) => {
1967
- var _x = _w, { children } = _x, props = __objRest(_x, ["children"]);
1968
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("ul", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1969
- },
1970
- li: (_y) => {
1971
- var _z = _y, { children } = _z, props = __objRest(_z, ["children"]);
1972
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("li", __spreadProps(__spreadValues({ className: "copilotKitMarkdownElement" }, props), { children }));
1973
- }
2198
+ }, [startReadingFromMessageId, inProgress]);
2199
+ return { pushToTalkState, setPushToTalkState };
1974
2200
  };
1975
- var MemoizedReactMarkdown = (0, import_react11.memo)(
1976
- import_react_markdown.default,
1977
- (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
1978
- );
1979
- var Markdown = ({ content, components }) => {
1980
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1981
- MemoizedReactMarkdown,
1982
- {
1983
- components: __spreadValues(__spreadValues({}, defaultComponents), components),
1984
- remarkPlugins: [import_remark_gfm.default, import_remark_math.default],
1985
- rehypePlugins: [import_rehype_raw.default],
1986
- children: content
1987
- }
1988
- ) });
2201
+
2202
+ // src/components/chat/Input.tsx
2203
+ var import_react_core7 = require("@copilotkit/react-core");
2204
+
2205
+ // src/hooks/use-dark-mode.ts
2206
+ var useDarkMode = () => {
2207
+ if (typeof window === "undefined")
2208
+ return false;
2209
+ return document.documentElement.classList.contains("dark") || document.body.classList.contains("dark") || document.documentElement.getAttribute("data-theme") === "dark" || document.body.getAttribute("data-theme") === "dark" || window.matchMedia("(prefers-color-scheme: dark)").matches;
1989
2210
  };
1990
2211
 
1991
- // src/components/chat/messages/AssistantMessage.tsx
1992
- var import_react12 = require("react");
1993
- var import_jsx_runtime17 = require("react/jsx-runtime");
1994
- var AssistantMessage = (props) => {
1995
- var _a;
1996
- const { icons, labels } = useChatContext();
1997
- const {
1998
- message,
1999
- isLoading,
2000
- onRegenerate,
2001
- onCopy,
2002
- onThumbsUp,
2003
- onThumbsDown,
2004
- isCurrentMessage,
2005
- markdownTagRenderers
2006
- } = props;
2007
- const [copied, setCopied] = (0, import_react12.useState)(false);
2008
- const handleCopy = () => {
2009
- const content2 = (message == null ? void 0 : message.content) || "";
2010
- if (content2 && onCopy) {
2011
- navigator.clipboard.writeText(content2);
2012
- setCopied(true);
2013
- onCopy(content2);
2014
- setTimeout(() => setCopied(false), 2e3);
2015
- } else if (content2) {
2016
- navigator.clipboard.writeText(content2);
2017
- setCopied(true);
2018
- setTimeout(() => setCopied(false), 2e3);
2019
- }
2020
- };
2021
- const handleRegenerate = () => {
2022
- if (onRegenerate)
2023
- onRegenerate();
2212
+ // src/components/chat/PoweredByTag.tsx
2213
+ var import_jsx_runtime19 = require("react/jsx-runtime");
2214
+ function PoweredByTag({ showPoweredBy = true }) {
2215
+ const isDark = useDarkMode();
2216
+ if (!showPoweredBy) {
2217
+ return null;
2218
+ }
2219
+ const poweredByStyle = {
2220
+ visibility: "visible",
2221
+ display: "block",
2222
+ position: "static",
2223
+ textAlign: "center",
2224
+ fontSize: "12px",
2225
+ padding: "3px 0",
2226
+ color: isDark ? "rgb(69, 69, 69)" : "rgb(214, 214, 214)"
2024
2227
  };
2025
- const handleThumbsUp = () => {
2026
- if (onThumbsUp && message)
2027
- onThumbsUp(message);
2228
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "poweredBy", style: poweredByStyle, children: "Powered by CopilotKit" }) });
2229
+ }
2230
+
2231
+ // src/components/chat/Input.tsx
2232
+ var import_jsx_runtime20 = require("react/jsx-runtime");
2233
+ var MAX_NEWLINES = 6;
2234
+ var Input = ({
2235
+ inProgress,
2236
+ onSend,
2237
+ isVisible = false,
2238
+ onStop,
2239
+ onUpload,
2240
+ hideStopButton = false
2241
+ }) => {
2242
+ var _a, _b;
2243
+ const context = useChatContext();
2244
+ const copilotContext = (0, import_react_core7.useCopilotContext)();
2245
+ const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
2246
+ const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
2247
+ const textareaRef = (0, import_react13.useRef)(null);
2248
+ const [isComposing, setIsComposing] = (0, import_react13.useState)(false);
2249
+ const handleDivClick = (event) => {
2250
+ var _a2;
2251
+ const target = event.target;
2252
+ if (target.closest("button"))
2253
+ return;
2254
+ if (target.tagName === "TEXTAREA")
2255
+ return;
2256
+ (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
2028
2257
  };
2029
- const handleThumbsDown = () => {
2030
- if (onThumbsDown && message)
2031
- onThumbsDown(message);
2258
+ const [text, setText] = (0, import_react13.useState)("");
2259
+ const send = () => {
2260
+ var _a2;
2261
+ if (inProgress)
2262
+ return;
2263
+ onSend(text);
2264
+ setText("");
2265
+ (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
2032
2266
  };
2033
- const LoadingIcon = () => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { children: icons.activityIcon });
2034
- const content = (message == null ? void 0 : message.content) || "";
2035
- const subComponent = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message);
2036
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
2037
- content && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
2038
- content && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Markdown, { content, components: markdownTagRenderers }),
2039
- content && !isLoading && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
2040
- "div",
2267
+ const { pushToTalkState, setPushToTalkState } = usePushToTalk({
2268
+ sendFunction: onSend,
2269
+ inProgress
2270
+ });
2271
+ const isInProgress = inProgress || pushToTalkState === "transcribing";
2272
+ const buttonIcon = isInProgress && !hideStopButton ? context.icons.stopIcon : context.icons.sendIcon;
2273
+ const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
2274
+ const canSend = (0, import_react13.useMemo)(() => {
2275
+ var _a2;
2276
+ const interruptEvent = (_a2 = copilotContext.langGraphInterruptAction) == null ? void 0 : _a2.event;
2277
+ const interruptInProgress = (interruptEvent == null ? void 0 : interruptEvent.name) === "LangGraphInterruptEvent" && !(interruptEvent == null ? void 0 : interruptEvent.response);
2278
+ return !isInProgress && text.trim().length > 0 && pushToTalkState === "idle" && !interruptInProgress;
2279
+ }, [(_b = copilotContext.langGraphInterruptAction) == null ? void 0 : _b.event, isInProgress, text, pushToTalkState]);
2280
+ const canStop = (0, import_react13.useMemo)(() => {
2281
+ return isInProgress && !hideStopButton;
2282
+ }, [isInProgress, hideStopButton]);
2283
+ const sendDisabled = !canSend && !canStop;
2284
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: `copilotKitInputContainer ${showPoweredBy ? "poweredByContainer" : ""}`, children: [
2285
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
2286
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2287
+ Textarea_default,
2041
2288
  {
2042
- className: `copilotKitMessageControls ${isCurrentMessage ? "currentMessage" : ""}`,
2043
- children: [
2044
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2045
- "button",
2046
- {
2047
- className: "copilotKitMessageControlButton",
2048
- onClick: handleRegenerate,
2049
- "aria-label": labels.regenerateResponse,
2050
- title: labels.regenerateResponse,
2051
- children: icons.regenerateIcon
2052
- }
2053
- ),
2054
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2055
- "button",
2056
- {
2057
- className: "copilotKitMessageControlButton",
2058
- onClick: handleCopy,
2059
- "aria-label": labels.copyToClipboard,
2060
- title: labels.copyToClipboard,
2061
- children: copied ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { style: { fontSize: "10px", fontWeight: "bold" }, children: "\u2713" }) : icons.copyIcon
2062
- }
2063
- ),
2064
- onThumbsUp && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2065
- "button",
2066
- {
2067
- className: "copilotKitMessageControlButton",
2068
- onClick: handleThumbsUp,
2069
- "aria-label": labels.thumbsUp,
2070
- title: labels.thumbsUp,
2071
- children: icons.thumbsUpIcon
2072
- }
2073
- ),
2074
- onThumbsDown && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2075
- "button",
2076
- {
2077
- className: "copilotKitMessageControlButton",
2078
- onClick: handleThumbsDown,
2079
- "aria-label": labels.thumbsDown,
2080
- title: labels.thumbsDown,
2081
- children: icons.thumbsDownIcon
2289
+ ref: textareaRef,
2290
+ placeholder: context.labels.placeholder,
2291
+ autoFocus: false,
2292
+ maxRows: MAX_NEWLINES,
2293
+ value: text,
2294
+ onChange: (event) => setText(event.target.value),
2295
+ onCompositionStart: () => setIsComposing(true),
2296
+ onCompositionEnd: () => setIsComposing(false),
2297
+ onKeyDown: (event) => {
2298
+ if (event.key === "Enter" && !event.shiftKey && !isComposing) {
2299
+ event.preventDefault();
2300
+ if (canSend) {
2301
+ send();
2082
2302
  }
2083
- )
2084
- ]
2303
+ }
2304
+ }
2085
2305
  }
2086
- )
2306
+ ),
2307
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "copilotKitInputControls", children: [
2308
+ onUpload && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { onClick: onUpload, className: "copilotKitInputControlButton", children: context.icons.uploadIcon }),
2309
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { style: { flexGrow: 1 } }),
2310
+ showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2311
+ "button",
2312
+ {
2313
+ onClick: () => setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing"),
2314
+ className: pushToTalkState === "recording" ? "copilotKitInputControlButton copilotKitPushToTalkRecording" : "copilotKitInputControlButton",
2315
+ children: context.icons.pushToTalkIcon
2316
+ }
2317
+ ),
2318
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2319
+ "button",
2320
+ {
2321
+ disabled: sendDisabled,
2322
+ onClick: isInProgress && !hideStopButton ? onStop : send,
2323
+ "data-copilotkit-in-progress": inProgress,
2324
+ "data-test-id": inProgress ? "copilot-chat-request-in-progress" : "copilot-chat-ready",
2325
+ className: "copilotKitInputControlButton",
2326
+ children: buttonIcon
2327
+ }
2328
+ )
2329
+ ] })
2087
2330
  ] }),
2088
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { style: { marginBottom: "0.5rem" }, children: subComponent }),
2089
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(LoadingIcon, {})
2090
- ] });
2091
- };
2092
-
2093
- // src/components/chat/messages/ImageRenderer.tsx
2094
- var import_react13 = require("react");
2095
- var import_jsx_runtime18 = require("react/jsx-runtime");
2096
- var ImageRenderer = ({ image, content, className = "" }) => {
2097
- const [imageError, setImageError] = (0, import_react13.useState)(false);
2098
- const imageSrc = `data:image/${image.format};base64,${image.bytes}`;
2099
- const altText = content || "User uploaded image";
2100
- const handleImageError = () => {
2101
- setImageError(true);
2102
- };
2103
- if (imageError) {
2104
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: `copilotKitImageRendering copilotKitImageRenderingError ${className}`, children: [
2105
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "copilotKitImageRenderingErrorMessage", children: "Failed to load image" }),
2106
- content && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "copilotKitImageRenderingContent", children: content })
2107
- ] });
2108
- }
2109
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: `copilotKitImageRendering ${className}`, children: [
2110
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2111
- "img",
2112
- {
2113
- src: imageSrc,
2114
- alt: altText,
2115
- className: "copilotKitImageRenderingImage",
2116
- onError: handleImageError
2117
- }
2118
- ),
2119
- content && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "copilotKitImageRenderingContent", children: content })
2331
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(PoweredByTag, { showPoweredBy })
2120
2332
  ] });
2121
2333
  };
2122
2334
 
2123
- // src/components/chat/messages/RenderMessage.tsx
2124
- var import_jsx_runtime19 = require("react/jsx-runtime");
2125
- function RenderMessage(_a) {
2126
- var _b = _a, {
2127
- UserMessage: UserMessage2 = UserMessage,
2128
- AssistantMessage: AssistantMessage2 = AssistantMessage,
2129
- ImageRenderer: ImageRenderer2 = ImageRenderer
2130
- } = _b, props = __objRest(_b, [
2131
- "UserMessage",
2132
- "AssistantMessage",
2133
- "ImageRenderer"
2134
- ]);
2135
- const {
2136
- message,
2137
- inProgress,
2138
- index,
2139
- isCurrentMessage,
2140
- onRegenerate,
2141
- onCopy,
2142
- onThumbsUp,
2143
- onThumbsDown,
2144
- markdownTagRenderers
2145
- } = props;
2146
- switch (message.role) {
2147
- case "user":
2148
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2149
- UserMessage2,
2150
- {
2151
- "data-message-role": "user",
2152
- message,
2153
- ImageRenderer: ImageRenderer2
2154
- },
2155
- index
2156
- );
2157
- case "assistant":
2158
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2159
- AssistantMessage2,
2160
- {
2161
- "data-message-role": "assistant",
2162
- message,
2163
- isLoading: inProgress && isCurrentMessage && !message.content,
2164
- isGenerating: inProgress && isCurrentMessage && !!message.content,
2165
- isCurrentMessage,
2166
- onRegenerate: () => onRegenerate == null ? void 0 : onRegenerate(message.id),
2167
- onCopy,
2168
- onThumbsUp,
2169
- onThumbsDown,
2170
- markdownTagRenderers,
2171
- ImageRenderer: ImageRenderer2
2172
- },
2173
- index
2174
- );
2175
- }
2176
- }
2177
-
2178
2335
  // src/components/chat/Chat.tsx
2179
2336
  var import_react14 = __toESM(require("react"));
2180
2337
  var import_react_core9 = require("@copilotkit/react-core");
@@ -2183,7 +2340,7 @@ var import_shared4 = require("@copilotkit/shared");
2183
2340
  var import_react_core10 = require("@copilotkit/react-core");
2184
2341
 
2185
2342
  // src/components/chat/ImageUploadQueue.tsx
2186
- var import_jsx_runtime20 = require("react/jsx-runtime");
2343
+ var import_jsx_runtime21 = require("react/jsx-runtime");
2187
2344
  var ImageUploadQueue = ({
2188
2345
  images,
2189
2346
  onRemoveImage,
@@ -2191,7 +2348,7 @@ var ImageUploadQueue = ({
2191
2348
  }) => {
2192
2349
  if (images.length === 0)
2193
2350
  return null;
2194
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2351
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2195
2352
  "div",
2196
2353
  {
2197
2354
  className: `copilotKitImageUploadQueue ${className}`,
@@ -2202,7 +2359,7 @@ var ImageUploadQueue = ({
2202
2359
  margin: "8px",
2203
2360
  padding: "8px"
2204
2361
  },
2205
- children: images.map((image, index) => /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
2362
+ children: images.map((image, index) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
2206
2363
  "div",
2207
2364
  {
2208
2365
  className: "copilotKitImageUploadQueueItem",
@@ -2215,7 +2372,7 @@ var ImageUploadQueue = ({
2215
2372
  overflow: "hidden"
2216
2373
  },
2217
2374
  children: [
2218
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2375
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2219
2376
  "img",
2220
2377
  {
2221
2378
  src: `data:${image.contentType};base64,${image.bytes}`,
@@ -2227,7 +2384,7 @@ var ImageUploadQueue = ({
2227
2384
  }
2228
2385
  }
2229
2386
  ),
2230
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2387
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2231
2388
  "button",
2232
2389
  {
2233
2390
  onClick: () => onRemoveImage(index),
@@ -2262,12 +2419,12 @@ var ImageUploadQueue = ({
2262
2419
 
2263
2420
  // src/components/chat/Suggestion.tsx
2264
2421
  var import_react_core8 = require("@copilotkit/react-core");
2265
- var import_jsx_runtime21 = require("react/jsx-runtime");
2422
+ var import_jsx_runtime22 = require("react/jsx-runtime");
2266
2423
  function Suggestion({ title, onClick, partial, className }) {
2267
2424
  if (!title)
2268
2425
  return null;
2269
2426
  const { isLoading } = (0, import_react_core8.useCopilotChatInternal)();
2270
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2427
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2271
2428
  "button",
2272
2429
  {
2273
2430
  disabled: partial || isLoading,
@@ -2277,15 +2434,15 @@ function Suggestion({ title, onClick, partial, className }) {
2277
2434
  },
2278
2435
  className: className || (partial ? "suggestion loading" : "suggestion"),
2279
2436
  "data-test-id": "suggestion",
2280
- children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { children: title })
2437
+ children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { children: title })
2281
2438
  }
2282
2439
  );
2283
2440
  }
2284
2441
 
2285
2442
  // src/components/chat/Suggestions.tsx
2286
- var import_jsx_runtime22 = require("react/jsx-runtime");
2443
+ var import_jsx_runtime23 = require("react/jsx-runtime");
2287
2444
  function Suggestions({ suggestions, onSuggestionClick }) {
2288
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "suggestions", children: suggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2445
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "suggestions", children: suggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2289
2446
  Suggestion,
2290
2447
  {
2291
2448
  title: suggestion.title,
@@ -2299,7 +2456,7 @@ function Suggestions({ suggestions, onSuggestionClick }) {
2299
2456
  }
2300
2457
 
2301
2458
  // src/components/chat/Chat.tsx
2302
- var import_jsx_runtime23 = require("react/jsx-runtime");
2459
+ var import_jsx_runtime24 = require("react/jsx-runtime");
2303
2460
  function CopilotChat({
2304
2461
  instructions,
2305
2462
  suggestions = "auto",
@@ -2326,17 +2483,26 @@ function CopilotChat({
2326
2483
  imageUploadsEnabled,
2327
2484
  inputFileAccept = "image/*",
2328
2485
  hideStopButton,
2329
- observabilityHooks
2486
+ observabilityHooks,
2487
+ renderError,
2488
+ // Legacy props - deprecated
2489
+ RenderTextMessage,
2490
+ RenderActionExecutionMessage,
2491
+ RenderAgentStateMessage,
2492
+ RenderResultMessage,
2493
+ RenderImageMessage
2330
2494
  }) {
2331
2495
  const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
2496
+ const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
2332
2497
  const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
2498
+ const [chatError, setChatError] = (0, import_react14.useState)(null);
2333
2499
  const fileInputRef = (0, import_react14.useRef)(null);
2334
2500
  const triggerObservabilityHook = (0, import_react14.useCallback)(
2335
2501
  (hookName, ...args) => {
2336
- if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2502
+ if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2337
2503
  observabilityHooks[hookName](...args);
2338
2504
  }
2339
- if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !copilotApiConfig.publicApiKey) {
2505
+ if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !publicApiKey) {
2340
2506
  setBannerError(
2341
2507
  new import_shared3.CopilotKitError({
2342
2508
  message: "observabilityHooks requires a publicApiKey to function.",
@@ -2348,7 +2514,50 @@ function CopilotChat({
2348
2514
  import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks");
2349
2515
  }
2350
2516
  },
2351
- [copilotApiConfig.publicApiKey, observabilityHooks]
2517
+ [publicApiKey, observabilityHooks, setBannerError]
2518
+ );
2519
+ const triggerChatError = (0, import_react14.useCallback)(
2520
+ (error, operation, originalError) => {
2521
+ const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
2522
+ setChatError({
2523
+ message: errorMessage,
2524
+ operation,
2525
+ timestamp: Date.now()
2526
+ });
2527
+ if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks.onError)) {
2528
+ const errorEvent = {
2529
+ type: "error",
2530
+ timestamp: Date.now(),
2531
+ context: {
2532
+ source: "ui",
2533
+ request: {
2534
+ operation,
2535
+ url: chatApiEndpoint,
2536
+ startTime: Date.now()
2537
+ },
2538
+ technical: {
2539
+ environment: "browser",
2540
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
2541
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
2542
+ }
2543
+ },
2544
+ error
2545
+ };
2546
+ observabilityHooks.onError(errorEvent);
2547
+ }
2548
+ if ((observabilityHooks == null ? void 0 : observabilityHooks.onError) && !publicApiKey) {
2549
+ setBannerError(
2550
+ new import_shared3.CopilotKitError({
2551
+ message: "observabilityHooks.onError requires a publicApiKey to function.",
2552
+ code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
2553
+ severity: import_shared3.Severity.CRITICAL,
2554
+ visibility: import_shared3.ErrorVisibility.BANNER
2555
+ })
2556
+ );
2557
+ import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks.onError");
2558
+ }
2559
+ },
2560
+ [publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
2352
2561
  );
2353
2562
  (0, import_react14.useEffect)(() => {
2354
2563
  if (!imageUploadsEnabled)
@@ -2389,12 +2598,13 @@ function CopilotChat({
2389
2598
  const loadedImages = (yield Promise.all(imagePromises)).filter((img) => img !== null);
2390
2599
  setSelectedImages((prev) => [...prev, ...loadedImages]);
2391
2600
  } catch (error) {
2601
+ triggerChatError(error, "processClipboardImages", error);
2392
2602
  console.error("Error processing pasted images:", error);
2393
2603
  }
2394
2604
  });
2395
2605
  document.addEventListener("paste", handlePaste);
2396
2606
  return () => document.removeEventListener("paste", handlePaste);
2397
- }, [imageUploadsEnabled]);
2607
+ }, [imageUploadsEnabled, triggerChatError]);
2398
2608
  (0, import_react14.useEffect)(() => {
2399
2609
  if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
2400
2610
  setChatInstructions(instructions || "");
@@ -2408,7 +2618,7 @@ function CopilotChat({
2408
2618
  setChatInstructions(combinedAdditionalInstructions.join("\n") || "");
2409
2619
  }, [instructions, additionalInstructions]);
2410
2620
  const {
2411
- visibleMessages,
2621
+ messages,
2412
2622
  isLoading,
2413
2623
  sendMessage,
2414
2624
  stopGeneration,
@@ -2485,6 +2695,7 @@ function CopilotChat({
2485
2695
  const loadedImages = yield Promise.all(fileReadPromises);
2486
2696
  setSelectedImages((prev) => [...prev, ...loadedImages]);
2487
2697
  } catch (error) {
2698
+ triggerChatError(error, "processUploadedImages", error);
2488
2699
  console.error("Error reading files:", error);
2489
2700
  }
2490
2701
  });
@@ -2503,14 +2714,20 @@ function CopilotChat({
2503
2714
  }
2504
2715
  triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
2505
2716
  };
2506
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2507
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2717
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2718
+ chatError && renderError && renderError(__spreadProps(__spreadValues({}, chatError), {
2719
+ onDismiss: () => setChatError(null),
2720
+ onRetry: () => {
2721
+ setChatError(null);
2722
+ }
2723
+ })),
2724
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2508
2725
  Messages2,
2509
2726
  {
2510
2727
  AssistantMessage: AssistantMessage2,
2511
2728
  UserMessage: UserMessage2,
2512
2729
  RenderMessage: RenderMessage2,
2513
- messages: visibleMessages,
2730
+ messages,
2514
2731
  inProgress: isLoading,
2515
2732
  onRegenerate: handleRegenerate,
2516
2733
  onCopy: handleCopy,
@@ -2518,7 +2735,12 @@ function CopilotChat({
2518
2735
  onThumbsDown: handleThumbsDown,
2519
2736
  markdownTagRenderers,
2520
2737
  ImageRenderer: ImageRenderer2,
2521
- children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2738
+ RenderTextMessage,
2739
+ RenderActionExecutionMessage,
2740
+ RenderAgentStateMessage,
2741
+ RenderResultMessage,
2742
+ RenderImageMessage,
2743
+ children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2522
2744
  RenderSuggestionsList,
2523
2745
  {
2524
2746
  onSuggestionClick: handleSendMessage,
@@ -2527,9 +2749,9 @@ function CopilotChat({
2527
2749
  )
2528
2750
  }
2529
2751
  ),
2530
- imageUploadsEnabled && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
2531
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ImageUploadQueue, { images: selectedImages, onRemoveImage: removeSelectedImage }),
2532
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2752
+ imageUploadsEnabled && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
2753
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ImageUploadQueue, { images: selectedImages, onRemoveImage: removeSelectedImage }),
2754
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2533
2755
  "input",
2534
2756
  {
2535
2757
  type: "file",
@@ -2541,7 +2763,7 @@ function CopilotChat({
2541
2763
  }
2542
2764
  )
2543
2765
  ] }),
2544
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2766
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2545
2767
  Input2,
2546
2768
  {
2547
2769
  inProgress: isLoading,
@@ -2565,16 +2787,16 @@ function WrappedCopilotChat({
2565
2787
  }) {
2566
2788
  const chatContext = import_react14.default.useContext(ChatContext);
2567
2789
  if (!chatContext) {
2568
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
2569
- }, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
2790
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
2791
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
2570
2792
  }
2571
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_jsx_runtime23.Fragment, { children });
2793
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_jsx_runtime24.Fragment, { children });
2572
2794
  }
2573
2795
  var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
2574
2796
  var _a;
2575
2797
  const {
2576
- visibleMessages,
2577
- appendMessage,
2798
+ messages,
2799
+ sendMessage,
2578
2800
  setMessages,
2579
2801
  reloadMessages: defaultReloadMessages,
2580
2802
  stopGeneration: defaultStopGeneration,
@@ -2620,12 +2842,12 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2620
2842
  if (Object.keys(generalContext.chatSuggestionConfiguration).length === 0) {
2621
2843
  return;
2622
2844
  }
2623
- if (visibleMessages.length === 0 && !hasGeneratedInitialSuggestions.current) {
2845
+ if (messages.length === 0 && !hasGeneratedInitialSuggestions.current) {
2624
2846
  hasGeneratedInitialSuggestions.current = true;
2625
2847
  generateSuggestionsWithErrorHandling("initial");
2626
2848
  return;
2627
2849
  }
2628
- if (visibleMessages.length > 0 && suggestions.length === 0) {
2850
+ if (messages.length > 0 && suggestions.length === 0) {
2629
2851
  generateSuggestionsWithErrorHandling("post-message");
2630
2852
  return;
2631
2853
  }
@@ -2633,7 +2855,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2633
2855
  chatSuggestions,
2634
2856
  isLoadingSuggestions,
2635
2857
  suggestionsFailed,
2636
- visibleMessages.length,
2858
+ messages.length,
2637
2859
  isLoading,
2638
2860
  suggestions.length,
2639
2861
  Object.keys(generalContext.chatSuggestionConfiguration).join(","),
@@ -2663,7 +2885,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2663
2885
  (0, import_react14.useEffect)(() => {
2664
2886
  onInProgress == null ? void 0 : onInProgress(isLoading);
2665
2887
  }, [onInProgress, isLoading]);
2666
- const sendMessage = (messageContent, imagesToUse) => __async(void 0, null, function* () {
2888
+ const safelySendMessage = (messageContent, imagesToUse) => __async(void 0, null, function* () {
2667
2889
  const images = imagesToUse || [];
2668
2890
  if (chatSuggestions === "auto" || chatSuggestions === "manual") {
2669
2891
  setSuggestions([]);
@@ -2682,7 +2904,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2682
2904
  console.error("Error in onSubmitMessage:", error);
2683
2905
  }
2684
2906
  }
2685
- yield appendMessage(textMessage, {
2907
+ yield sendMessage(textMessage, {
2686
2908
  followUp: images.length === 0,
2687
2909
  clearSuggestions: chatSuggestions === "auto" || chatSuggestions === "manual"
2688
2910
  });
@@ -2700,7 +2922,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2700
2922
  bytes: images[i].bytes
2701
2923
  }
2702
2924
  };
2703
- yield appendMessage(imageMessage, { followUp: i === images.length - 1 });
2925
+ yield sendMessage(imageMessage, { followUp: i === images.length - 1 });
2704
2926
  if (!firstMessage) {
2705
2927
  firstMessage = imageMessage;
2706
2928
  }
@@ -2711,7 +2933,6 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2711
2933
  }
2712
2934
  return firstMessage;
2713
2935
  });
2714
- const messages = visibleMessages;
2715
2936
  const currentAgentName = (_a = generalContext.agentSession) == null ? void 0 : _a.agentName;
2716
2937
  const restartCurrentAgent = (hint) => __async(void 0, null, function* () {
2717
2938
  if (generalContext.agentSession) {
@@ -2736,9 +2957,8 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2736
2957
  generalContext.agentSession.agentName,
2737
2958
  stableContext,
2738
2959
  messagesContext.messages,
2739
- appendMessage,
2740
- runChatCompletion,
2741
- hint
2960
+ sendMessage,
2961
+ runChatCompletion
2742
2962
  );
2743
2963
  }
2744
2964
  });
@@ -2794,10 +3014,9 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2794
3014
  }
2795
3015
  return {
2796
3016
  messages,
2797
- visibleMessages,
2798
3017
  isLoading,
2799
3018
  suggestions,
2800
- sendMessage,
3019
+ sendMessage: safelySendMessage,
2801
3020
  stopGeneration,
2802
3021
  reloadMessages,
2803
3022
  resetSuggestions,
@@ -2808,7 +3027,8 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2808
3027
 
2809
3028
  // src/components/chat/Modal.tsx
2810
3029
  var import_react_core11 = require("@copilotkit/react-core");
2811
- var import_jsx_runtime24 = require("react/jsx-runtime");
3030
+ var import_shared5 = require("@copilotkit/shared");
3031
+ var import_jsx_runtime25 = require("react/jsx-runtime");
2812
3032
  var CopilotModalInner = (_a) => {
2813
3033
  var _b = _a, {
2814
3034
  observabilityHooks,
@@ -2833,14 +3053,26 @@ var CopilotModalInner = (_a) => {
2833
3053
  "Button",
2834
3054
  "Header"
2835
3055
  ]);
2836
- const { copilotApiConfig } = (0, import_react_core11.useCopilotContext)();
3056
+ const { copilotApiConfig, setBannerError } = (0, import_react_core11.useCopilotContext)();
3057
+ const { publicApiKey } = copilotApiConfig;
2837
3058
  const triggerObservabilityHook = (0, import_react15.useCallback)(
2838
3059
  (hookName, ...args) => {
2839
- if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
3060
+ if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2840
3061
  observabilityHooks[hookName](...args);
2841
3062
  }
3063
+ if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !publicApiKey) {
3064
+ setBannerError(
3065
+ new import_shared5.CopilotKitError({
3066
+ message: "observabilityHooks requires a publicApiKey to function.",
3067
+ code: import_shared5.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
3068
+ severity: import_shared5.Severity.CRITICAL,
3069
+ visibility: import_shared5.ErrorVisibility.BANNER
3070
+ })
3071
+ );
3072
+ import_shared5.styledConsole.publicApiKeyRequired("observabilityHooks");
3073
+ }
2842
3074
  },
2843
- [copilotApiConfig.publicApiKey, observabilityHooks]
3075
+ [publicApiKey, observabilityHooks, setBannerError]
2844
3076
  );
2845
3077
  const { open } = useChatContext();
2846
3078
  const prevOpen = (0, import_react15.useRef)(open);
@@ -2855,13 +3087,13 @@ var CopilotModalInner = (_a) => {
2855
3087
  prevOpen.current = open;
2856
3088
  }
2857
3089
  }, [open, onSetOpen, triggerObservabilityHook]);
2858
- const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
3090
+ const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}), [Header2]);
2859
3091
  const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2860
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
3092
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
2861
3093
  memoizedChildren,
2862
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2863
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2864
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
3094
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className, children: [
3095
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Button2, {}),
3096
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
2865
3097
  Window2,
2866
3098
  {
2867
3099
  clickOutsideToClose,
@@ -2869,7 +3101,7 @@ var CopilotModalInner = (_a) => {
2869
3101
  hitEscapeToClose,
2870
3102
  children: [
2871
3103
  memoizedHeader,
2872
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
3104
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
2873
3105
  ]
2874
3106
  }
2875
3107
  )
@@ -2937,7 +3169,7 @@ var CopilotModal = (_a) => {
2937
3169
  "observabilityHooks"
2938
3170
  ]);
2939
3171
  const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
2940
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3172
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
2941
3173
  CopilotModalInner,
2942
3174
  __spreadProps(__spreadValues({
2943
3175
  observabilityHooks,
@@ -2971,17 +3203,17 @@ var CopilotModal = (_a) => {
2971
3203
  };
2972
3204
 
2973
3205
  // src/components/chat/Popup.tsx
2974
- var import_jsx_runtime25 = require("react/jsx-runtime");
3206
+ var import_jsx_runtime26 = require("react/jsx-runtime");
2975
3207
  function CopilotPopup(props) {
2976
3208
  props = __spreadProps(__spreadValues({}, props), {
2977
3209
  className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup"
2978
3210
  });
2979
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CopilotModal, __spreadProps(__spreadValues({}, props), { children: props.children }));
3211
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(CopilotModal, __spreadProps(__spreadValues({}, props), { children: props.children }));
2980
3212
  }
2981
3213
 
2982
3214
  // src/components/chat/Sidebar.tsx
2983
3215
  var import_react16 = require("react");
2984
- var import_jsx_runtime26 = require("react/jsx-runtime");
3216
+ var import_jsx_runtime27 = require("react/jsx-runtime");
2985
3217
  function CopilotSidebar(props) {
2986
3218
  props = __spreadProps(__spreadValues({}, props), {
2987
3219
  className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
@@ -2994,7 +3226,7 @@ function CopilotSidebar(props) {
2994
3226
  (_a = props.onSetOpen) == null ? void 0 : _a.call(props, open);
2995
3227
  setExpandedClassName(open ? "sidebarExpanded" : "");
2996
3228
  };
2997
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: `copilotKitSidebarContentWrapper ${expandedClassName}`, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(CopilotModal, __spreadProps(__spreadValues(__spreadValues({}, props), { onSetOpen }), { children: props.children })) });
3229
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: `copilotKitSidebarContentWrapper ${expandedClassName}`, children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(CopilotModal, __spreadProps(__spreadValues(__spreadValues({}, props), { onSetOpen }), { children: props.children })) });
2998
3230
  }
2999
3231
  // Annotate the CommonJS export names for ESM import in node:
3000
3232
  0 && (module.exports = {