@copilotkit/react-ui 1.10.0-next.9 → 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 +118 -0
- package/dist/{chunk-U5ATIGWH.mjs → chunk-BJHJBS5M.mjs} +45 -5
- package/dist/chunk-BJHJBS5M.mjs.map +1 -0
- package/dist/{chunk-TW4LLLTE.mjs → chunk-GBP47ONN.mjs} +2 -2
- package/dist/{chunk-2KG77MAY.mjs → chunk-GJ4SX4JE.mjs} +38 -29
- package/dist/chunk-GJ4SX4JE.mjs.map +1 -0
- package/dist/{chunk-6C3YVF5W.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-7K2X77PW.mjs → chunk-Y44VLEUH.mjs} +8 -8
- package/dist/components/chat/Chat.d.ts +21 -2
- package/dist/components/chat/Chat.js +1022 -856
- 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 +1030 -864
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +8 -7
- package/dist/components/chat/Popup.js +1032 -866
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +9 -8
- package/dist/components/chat/Sidebar.js +1032 -866
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +9 -8
- package/dist/components/chat/index.js +1034 -868
- 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 +49 -0
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.js +1034 -868
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +16 -15
- package/dist/index.js +1034 -868
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -15
- package/package.json +4 -4
- package/src/components/chat/Chat.tsx +50 -14
- package/src/components/chat/Messages.tsx +56 -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 +57 -0
- package/dist/chunk-2KG77MAY.mjs.map +0 -1
- package/dist/chunk-JHUTTP5C.mjs.map +0 -1
- package/dist/chunk-U5ATIGWH.mjs.map +0 -1
- /package/dist/{chunk-TW4LLLTE.mjs.map → chunk-GBP47ONN.mjs.map} +0 -0
- /package/dist/{chunk-6C3YVF5W.mjs.map → chunk-J5ZZR6YB.mjs.map} +0 -0
- /package/dist/{chunk-7K2X77PW.mjs.map → chunk-Y44VLEUH.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1038,557 +1038,135 @@ 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
|
-
|
|
1223
|
-
}
|
|
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
|
|
1169
|
+
children: value
|
|
1592
1170
|
}
|
|
1593
1171
|
)
|
|
1594
1172
|
] });
|
|
@@ -1877,306 +1455,885 @@ var highlightStyle = {
|
|
|
1877
1455
|
}
|
|
1878
1456
|
};
|
|
1879
1457
|
|
|
1880
|
-
// src/components/chat/Markdown.tsx
|
|
1881
|
-
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
1882
|
-
var import_remark_math = __toESM(require("remark-math"));
|
|
1883
|
-
var import_rehype_raw = __toESM(require("rehype-raw"));
|
|
1884
|
-
var
|
|
1885
|
-
var defaultComponents = {
|
|
1886
|
-
a(_a) {
|
|
1887
|
-
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
1888
|
-
return /* @__PURE__ */ (0,
|
|
1889
|
-
},
|
|
1890
|
-
// @ts-expect-error -- inline
|
|
1891
|
-
code(_c) {
|
|
1892
|
-
var _d = _c, { children, className, inline } = _d, props = __objRest(_d, ["children", "className", "inline"]);
|
|
1893
|
-
if (Array.isArray(children) && children.length) {
|
|
1894
|
-
if (children[0] == "\u258D") {
|
|
1895
|
-
return /* @__PURE__ */ (0,
|
|
1896
|
-
"span",
|
|
1897
|
-
{
|
|
1898
|
-
style: {
|
|
1899
|
-
animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
1900
|
-
marginTop: "0.25rem"
|
|
1901
|
-
},
|
|
1902
|
-
children: "\u258D"
|
|
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();
|
|
1903
2066
|
}
|
|
1904
|
-
|
|
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
|
|
1905
2094
|
}
|
|
1906
|
-
children[0] = (children == null ? void 0 : children[0]).replace("`\u258D`", "\u258D");
|
|
1907
|
-
}
|
|
1908
|
-
const match = /language-(\w+)/.exec(className || "");
|
|
1909
|
-
const hasLanguage = match && match[1];
|
|
1910
|
-
const content = String(children);
|
|
1911
|
-
const hasNewlines = content.includes("\n");
|
|
1912
|
-
const isInline = !hasLanguage && !hasNewlines;
|
|
1913
|
-
if (isInline) {
|
|
1914
|
-
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1915
|
-
"code",
|
|
1916
|
-
__spreadProps(__spreadValues({
|
|
1917
|
-
className: `copilotKitMarkdownElement copilotKitInlineCode ${className || ""}`
|
|
1918
|
-
}, props), {
|
|
1919
|
-
children
|
|
1920
|
-
})
|
|
1921
|
-
);
|
|
1922
|
-
}
|
|
1923
|
-
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1924
|
-
CodeBlock,
|
|
1925
|
-
__spreadValues({
|
|
1926
|
-
language: match && match[1] || "",
|
|
1927
|
-
value: String(children).replace(/\n$/, "")
|
|
1928
|
-
}, props),
|
|
1929
|
-
Math.random()
|
|
1930
2095
|
);
|
|
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
2096
|
}
|
|
1976
|
-
};
|
|
1977
|
-
var MemoizedReactMarkdown = (0, import_react11.memo)(
|
|
1978
|
-
import_react_markdown.default,
|
|
1979
|
-
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components
|
|
1980
2097
|
);
|
|
1981
|
-
var
|
|
1982
|
-
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "copilotKitMarkdown", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1983
|
-
MemoizedReactMarkdown,
|
|
1984
|
-
{
|
|
1985
|
-
components: __spreadValues(__spreadValues({}, defaultComponents), components),
|
|
1986
|
-
remarkPlugins: [import_remark_gfm.default, import_remark_math.default],
|
|
1987
|
-
rehypePlugins: [import_rehype_raw.default],
|
|
1988
|
-
children: content
|
|
1989
|
-
}
|
|
1990
|
-
) });
|
|
1991
|
-
};
|
|
2098
|
+
var Textarea_default = AutoResizingTextarea;
|
|
1992
2099
|
|
|
1993
|
-
// src/
|
|
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");
|
|
1994
2103
|
var import_react12 = require("react");
|
|
1995
|
-
var
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
onThumbsDown,
|
|
2006
|
-
isCurrentMessage,
|
|
2007
|
-
markdownTagRenderers
|
|
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
|
-
}
|
|
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);
|
|
2022
2114
|
};
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
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
|
+
})
|
|
2182
|
+
);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
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
|
|
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);
|
|
2199
|
+
}
|
|
2200
|
+
}, [startReadingFromMessageId, inProgress]);
|
|
2201
|
+
return { pushToTalkState, setPushToTalkState };
|
|
2202
|
+
};
|
|
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;
|
|
2212
|
+
};
|
|
2213
|
+
|
|
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, {})
|
|
2333
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(PoweredByTag, { showPoweredBy })
|
|
2092
2334
|
] });
|
|
2093
2335
|
};
|
|
2094
2336
|
|
|
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 })
|
|
2122
|
-
] });
|
|
2123
|
-
};
|
|
2124
|
-
|
|
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",
|
|
@@ -2329,7 +2486,13 @@ function CopilotChat({
|
|
|
2329
2486
|
inputFileAccept = "image/*",
|
|
2330
2487
|
hideStopButton,
|
|
2331
2488
|
observabilityHooks,
|
|
2332
|
-
renderError
|
|
2489
|
+
renderError,
|
|
2490
|
+
// Legacy props - deprecated
|
|
2491
|
+
RenderTextMessage,
|
|
2492
|
+
RenderActionExecutionMessage,
|
|
2493
|
+
RenderAgentStateMessage,
|
|
2494
|
+
RenderResultMessage,
|
|
2495
|
+
RenderImageMessage
|
|
2333
2496
|
}) {
|
|
2334
2497
|
const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
|
|
2335
2498
|
const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
|
|
@@ -2457,7 +2620,7 @@ function CopilotChat({
|
|
|
2457
2620
|
setChatInstructions(combinedAdditionalInstructions.join("\n") || "");
|
|
2458
2621
|
}, [instructions, additionalInstructions]);
|
|
2459
2622
|
const {
|
|
2460
|
-
|
|
2623
|
+
messages,
|
|
2461
2624
|
isLoading,
|
|
2462
2625
|
sendMessage,
|
|
2463
2626
|
stopGeneration,
|
|
@@ -2553,20 +2716,20 @@ function CopilotChat({
|
|
|
2553
2716
|
}
|
|
2554
2717
|
triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
|
|
2555
2718
|
};
|
|
2556
|
-
return /* @__PURE__ */ (0,
|
|
2719
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
|
|
2557
2720
|
chatError && renderError && renderError(__spreadProps(__spreadValues({}, chatError), {
|
|
2558
2721
|
onDismiss: () => setChatError(null),
|
|
2559
2722
|
onRetry: () => {
|
|
2560
2723
|
setChatError(null);
|
|
2561
2724
|
}
|
|
2562
2725
|
})),
|
|
2563
|
-
/* @__PURE__ */ (0,
|
|
2726
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2564
2727
|
Messages2,
|
|
2565
2728
|
{
|
|
2566
2729
|
AssistantMessage: AssistantMessage2,
|
|
2567
2730
|
UserMessage: UserMessage2,
|
|
2568
2731
|
RenderMessage: RenderMessage2,
|
|
2569
|
-
messages
|
|
2732
|
+
messages,
|
|
2570
2733
|
inProgress: isLoading,
|
|
2571
2734
|
onRegenerate: handleRegenerate,
|
|
2572
2735
|
onCopy: handleCopy,
|
|
@@ -2574,7 +2737,12 @@ function CopilotChat({
|
|
|
2574
2737
|
onThumbsDown: handleThumbsDown,
|
|
2575
2738
|
markdownTagRenderers,
|
|
2576
2739
|
ImageRenderer: ImageRenderer2,
|
|
2577
|
-
|
|
2740
|
+
RenderTextMessage,
|
|
2741
|
+
RenderActionExecutionMessage,
|
|
2742
|
+
RenderAgentStateMessage,
|
|
2743
|
+
RenderResultMessage,
|
|
2744
|
+
RenderImageMessage,
|
|
2745
|
+
children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2578
2746
|
RenderSuggestionsList,
|
|
2579
2747
|
{
|
|
2580
2748
|
onSuggestionClick: handleSendMessage,
|
|
@@ -2583,9 +2751,9 @@ function CopilotChat({
|
|
|
2583
2751
|
)
|
|
2584
2752
|
}
|
|
2585
2753
|
),
|
|
2586
|
-
imageUploadsEnabled && /* @__PURE__ */ (0,
|
|
2587
|
-
/* @__PURE__ */ (0,
|
|
2588
|
-
/* @__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)(
|
|
2589
2757
|
"input",
|
|
2590
2758
|
{
|
|
2591
2759
|
type: "file",
|
|
@@ -2597,7 +2765,7 @@ function CopilotChat({
|
|
|
2597
2765
|
}
|
|
2598
2766
|
)
|
|
2599
2767
|
] }),
|
|
2600
|
-
/* @__PURE__ */ (0,
|
|
2768
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
2601
2769
|
Input2,
|
|
2602
2770
|
{
|
|
2603
2771
|
inProgress: isLoading,
|
|
@@ -2621,16 +2789,16 @@ function WrappedCopilotChat({
|
|
|
2621
2789
|
}) {
|
|
2622
2790
|
const chatContext = import_react14.default.useContext(ChatContext);
|
|
2623
2791
|
if (!chatContext) {
|
|
2624
|
-
return /* @__PURE__ */ (0,
|
|
2625
|
-
}, 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 }) });
|
|
2626
2794
|
}
|
|
2627
|
-
return /* @__PURE__ */ (0,
|
|
2795
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_jsx_runtime24.Fragment, { children });
|
|
2628
2796
|
}
|
|
2629
2797
|
var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
|
|
2630
2798
|
var _a;
|
|
2631
2799
|
const {
|
|
2632
|
-
|
|
2633
|
-
|
|
2800
|
+
messages,
|
|
2801
|
+
sendMessage,
|
|
2634
2802
|
setMessages,
|
|
2635
2803
|
reloadMessages: defaultReloadMessages,
|
|
2636
2804
|
stopGeneration: defaultStopGeneration,
|
|
@@ -2676,12 +2844,12 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2676
2844
|
if (Object.keys(generalContext.chatSuggestionConfiguration).length === 0) {
|
|
2677
2845
|
return;
|
|
2678
2846
|
}
|
|
2679
|
-
if (
|
|
2847
|
+
if (messages.length === 0 && !hasGeneratedInitialSuggestions.current) {
|
|
2680
2848
|
hasGeneratedInitialSuggestions.current = true;
|
|
2681
2849
|
generateSuggestionsWithErrorHandling("initial");
|
|
2682
2850
|
return;
|
|
2683
2851
|
}
|
|
2684
|
-
if (
|
|
2852
|
+
if (messages.length > 0 && suggestions.length === 0) {
|
|
2685
2853
|
generateSuggestionsWithErrorHandling("post-message");
|
|
2686
2854
|
return;
|
|
2687
2855
|
}
|
|
@@ -2689,7 +2857,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2689
2857
|
chatSuggestions,
|
|
2690
2858
|
isLoadingSuggestions,
|
|
2691
2859
|
suggestionsFailed,
|
|
2692
|
-
|
|
2860
|
+
messages.length,
|
|
2693
2861
|
isLoading,
|
|
2694
2862
|
suggestions.length,
|
|
2695
2863
|
Object.keys(generalContext.chatSuggestionConfiguration).join(","),
|
|
@@ -2719,7 +2887,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2719
2887
|
(0, import_react14.useEffect)(() => {
|
|
2720
2888
|
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
2721
2889
|
}, [onInProgress, isLoading]);
|
|
2722
|
-
const
|
|
2890
|
+
const safelySendMessage = (messageContent, imagesToUse) => __async(void 0, null, function* () {
|
|
2723
2891
|
const images = imagesToUse || [];
|
|
2724
2892
|
if (chatSuggestions === "auto" || chatSuggestions === "manual") {
|
|
2725
2893
|
setSuggestions([]);
|
|
@@ -2738,7 +2906,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2738
2906
|
console.error("Error in onSubmitMessage:", error);
|
|
2739
2907
|
}
|
|
2740
2908
|
}
|
|
2741
|
-
yield
|
|
2909
|
+
yield sendMessage(textMessage, {
|
|
2742
2910
|
followUp: images.length === 0,
|
|
2743
2911
|
clearSuggestions: chatSuggestions === "auto" || chatSuggestions === "manual"
|
|
2744
2912
|
});
|
|
@@ -2756,7 +2924,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2756
2924
|
bytes: images[i].bytes
|
|
2757
2925
|
}
|
|
2758
2926
|
};
|
|
2759
|
-
yield
|
|
2927
|
+
yield sendMessage(imageMessage, { followUp: i === images.length - 1 });
|
|
2760
2928
|
if (!firstMessage) {
|
|
2761
2929
|
firstMessage = imageMessage;
|
|
2762
2930
|
}
|
|
@@ -2767,7 +2935,6 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2767
2935
|
}
|
|
2768
2936
|
return firstMessage;
|
|
2769
2937
|
});
|
|
2770
|
-
const messages = visibleMessages;
|
|
2771
2938
|
const currentAgentName = (_a = generalContext.agentSession) == null ? void 0 : _a.agentName;
|
|
2772
2939
|
const restartCurrentAgent = (hint) => __async(void 0, null, function* () {
|
|
2773
2940
|
if (generalContext.agentSession) {
|
|
@@ -2792,7 +2959,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2792
2959
|
generalContext.agentSession.agentName,
|
|
2793
2960
|
stableContext,
|
|
2794
2961
|
messagesContext.messages,
|
|
2795
|
-
|
|
2962
|
+
sendMessage,
|
|
2796
2963
|
runChatCompletion
|
|
2797
2964
|
);
|
|
2798
2965
|
}
|
|
@@ -2849,10 +3016,9 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2849
3016
|
}
|
|
2850
3017
|
return {
|
|
2851
3018
|
messages,
|
|
2852
|
-
visibleMessages,
|
|
2853
3019
|
isLoading,
|
|
2854
3020
|
suggestions,
|
|
2855
|
-
sendMessage,
|
|
3021
|
+
sendMessage: safelySendMessage,
|
|
2856
3022
|
stopGeneration,
|
|
2857
3023
|
reloadMessages,
|
|
2858
3024
|
resetSuggestions,
|
|
@@ -2864,7 +3030,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
|
|
|
2864
3030
|
// src/components/chat/Modal.tsx
|
|
2865
3031
|
var import_react_core11 = require("@copilotkit/react-core");
|
|
2866
3032
|
var import_shared5 = require("@copilotkit/shared");
|
|
2867
|
-
var
|
|
3033
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2868
3034
|
var CopilotModalInner = (_a) => {
|
|
2869
3035
|
var _b = _a, {
|
|
2870
3036
|
observabilityHooks,
|
|
@@ -2923,13 +3089,13 @@ var CopilotModalInner = (_a) => {
|
|
|
2923
3089
|
prevOpen.current = open;
|
|
2924
3090
|
}
|
|
2925
3091
|
}, [open, onSetOpen, triggerObservabilityHook]);
|
|
2926
|
-
const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0,
|
|
3092
|
+
const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Header2, {}), [Header2]);
|
|
2927
3093
|
const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
|
|
2928
|
-
return /* @__PURE__ */ (0,
|
|
3094
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
2929
3095
|
memoizedChildren,
|
|
2930
|
-
/* @__PURE__ */ (0,
|
|
2931
|
-
/* @__PURE__ */ (0,
|
|
2932
|
-
/* @__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)(
|
|
2933
3099
|
Window2,
|
|
2934
3100
|
{
|
|
2935
3101
|
clickOutsideToClose,
|
|
@@ -2937,7 +3103,7 @@ var CopilotModalInner = (_a) => {
|
|
|
2937
3103
|
hitEscapeToClose,
|
|
2938
3104
|
children: [
|
|
2939
3105
|
memoizedHeader,
|
|
2940
|
-
/* @__PURE__ */ (0,
|
|
3106
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
|
|
2941
3107
|
]
|
|
2942
3108
|
}
|
|
2943
3109
|
)
|
|
@@ -3005,7 +3171,7 @@ var CopilotModal = (_a) => {
|
|
|
3005
3171
|
"observabilityHooks"
|
|
3006
3172
|
]);
|
|
3007
3173
|
const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
|
|
3008
|
-
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)(
|
|
3009
3175
|
CopilotModalInner,
|
|
3010
3176
|
__spreadProps(__spreadValues({
|
|
3011
3177
|
observabilityHooks,
|
|
@@ -3039,17 +3205,17 @@ var CopilotModal = (_a) => {
|
|
|
3039
3205
|
};
|
|
3040
3206
|
|
|
3041
3207
|
// src/components/chat/Popup.tsx
|
|
3042
|
-
var
|
|
3208
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
3043
3209
|
function CopilotPopup(props) {
|
|
3044
3210
|
props = __spreadProps(__spreadValues({}, props), {
|
|
3045
3211
|
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup"
|
|
3046
3212
|
});
|
|
3047
|
-
return /* @__PURE__ */ (0,
|
|
3213
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(CopilotModal, __spreadProps(__spreadValues({}, props), { children: props.children }));
|
|
3048
3214
|
}
|
|
3049
3215
|
|
|
3050
3216
|
// src/components/chat/Sidebar.tsx
|
|
3051
3217
|
var import_react16 = require("react");
|
|
3052
|
-
var
|
|
3218
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
3053
3219
|
function CopilotSidebar(props) {
|
|
3054
3220
|
props = __spreadProps(__spreadValues({}, props), {
|
|
3055
3221
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
@@ -3062,7 +3228,7 @@ function CopilotSidebar(props) {
|
|
|
3062
3228
|
(_a = props.onSetOpen) == null ? void 0 : _a.call(props, open);
|
|
3063
3229
|
setExpandedClassName(open ? "sidebarExpanded" : "");
|
|
3064
3230
|
};
|
|
3065
|
-
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 })) });
|
|
3066
3232
|
}
|
|
3067
3233
|
|
|
3068
3234
|
// src/hooks/use-copilot-chat-suggestions.tsx
|