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