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