@copilotkit/react-ui 0.22.0 → 0.36.0-mme-pre.1
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/.turbo/turbo-build.log +211 -178
- package/CHANGELOG.md +24 -0
- package/dist/chunk-4MKP23AD.mjs +97 -0
- package/dist/chunk-4MKP23AD.mjs.map +1 -0
- package/dist/{chunk-T3WYKWNC.mjs → chunk-6XLZXLM5.mjs} +6 -6
- package/dist/chunk-6XLZXLM5.mjs.map +1 -0
- package/dist/{chunk-73EBDGYK.mjs → chunk-7FES2IQA.mjs} +5 -5
- package/dist/chunk-7FES2IQA.mjs.map +1 -0
- package/dist/chunk-ANO23V2M.mjs +135 -0
- package/dist/chunk-ANO23V2M.mjs.map +1 -0
- package/dist/chunk-BL65ZC6L.mjs +83 -0
- package/dist/chunk-BL65ZC6L.mjs.map +1 -0
- package/dist/{chunk-YEHO5VMA.mjs → chunk-CE7PJAAO.mjs} +2 -2
- package/dist/{chunk-7YXG7D47.mjs → chunk-FZC7X5PK.mjs} +57 -2
- package/dist/chunk-FZC7X5PK.mjs.map +1 -0
- package/dist/chunk-LTCJCXCP.mjs +29 -0
- package/dist/chunk-LTCJCXCP.mjs.map +1 -0
- package/dist/chunk-MRFF7GSQ.mjs +1 -0
- package/dist/{chunk-7JYUCW7H.mjs → chunk-PAQWLSA4.mjs} +2 -2
- package/dist/{chunk-YTIGBBTC.mjs → chunk-RT2XG2T7.mjs} +2 -2
- package/dist/chunk-RT2XG2T7.mjs.map +1 -0
- package/dist/chunk-T26KLXLH.mjs +1 -0
- package/dist/{chunk-6U3O2JZP.mjs → chunk-T3JTSIHT.mjs} +32 -39
- package/dist/chunk-T3JTSIHT.mjs.map +1 -0
- package/dist/{chunk-MBYUBR3F.mjs → chunk-UPTB2MVO.mjs} +2 -2
- package/dist/chunk-VUZA5AFH.mjs +73 -0
- package/dist/chunk-VUZA5AFH.mjs.map +1 -0
- package/dist/{chunk-YAORLSQ3.mjs → chunk-XRODMID5.mjs} +6 -6
- package/dist/chunk-XRODMID5.mjs.map +1 -0
- package/dist/{chunk-WDHLWSSU.mjs → chunk-YQ3D5IQV.mjs} +2 -2
- package/dist/{chunk-WM6BS77F.mjs → chunk-YQFVRDNC.mjs} +2 -2
- package/dist/{chunk-WM6BS77F.mjs.map → chunk-YQFVRDNC.mjs.map} +1 -1
- package/dist/chunk-ZO3GLN23.mjs +137 -0
- package/dist/chunk-ZO3GLN23.mjs.map +1 -0
- package/dist/components/chat/Button.js.map +1 -1
- package/dist/components/chat/Button.mjs +3 -3
- package/dist/components/chat/Chat.d.ts +66 -46
- package/dist/components/chat/Chat.js +433 -278
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +15 -14
- package/dist/components/chat/ChatContext.d.ts +16 -16
- package/dist/components/chat/ChatContext.js +43 -27
- package/dist/components/chat/ChatContext.js.map +1 -1
- package/dist/components/chat/ChatContext.mjs +2 -2
- package/dist/components/chat/CodeBlock.js.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +2 -2
- package/dist/components/chat/Header.js.map +1 -1
- package/dist/components/chat/Header.mjs +3 -3
- package/dist/components/chat/Icons.d.ts +7 -5
- package/dist/components/chat/Icons.js +57 -0
- package/dist/components/chat/Icons.js.map +1 -1
- package/dist/components/chat/Icons.mjs +5 -1
- package/dist/components/chat/Input.d.ts +1 -1
- package/dist/components/chat/Input.js +148 -11
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +5 -4
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +3 -3
- package/dist/components/chat/Messages.d.ts +1 -1
- package/dist/components/chat/Messages.js +2 -2
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +5 -5
- package/dist/components/chat/Modal.d.ts +50 -0
- package/dist/components/chat/Modal.js +1584 -0
- package/dist/components/chat/Modal.js.map +1 -0
- package/dist/components/chat/Modal.mjs +23 -0
- package/dist/components/chat/Modal.mjs.map +1 -0
- package/dist/components/chat/Popup.d.ts +56 -4
- package/dist/components/chat/Popup.js +428 -78
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +15 -12
- package/dist/components/chat/Response.js.map +1 -1
- package/dist/components/chat/Response.mjs +3 -3
- package/dist/components/chat/Sidebar.d.ts +7 -8
- package/dist/components/chat/Sidebar.js +430 -80
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +15 -12
- package/dist/components/chat/Suggestion.d.ts +13 -0
- package/dist/components/chat/Suggestion.js +172 -0
- package/dist/components/chat/Suggestion.js.map +1 -0
- package/dist/components/chat/Suggestion.mjs +11 -0
- package/dist/components/chat/Suggestion.mjs.map +1 -0
- package/dist/components/chat/Textarea.d.ts +4 -4
- package/dist/components/chat/Textarea.js +1 -1
- package/dist/components/chat/Textarea.js.map +1 -1
- package/dist/components/chat/Textarea.mjs +1 -1
- package/dist/components/chat/index.d.ts +4 -2
- package/dist/components/chat/index.js +436 -84
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +22 -16
- package/dist/components/chat/props.d.ts +10 -3
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +4 -2
- package/dist/components/index.js +436 -84
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +22 -16
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +36 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +8 -1
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +87 -0
- package/dist/hooks/use-copilot-chat-suggestions.js +53 -0
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-push-to-talk.d.ts +19 -0
- package/dist/hooks/use-push-to-talk.js +177 -0
- package/dist/hooks/use-push-to-talk.js.map +1 -0
- package/dist/hooks/use-push-to-talk.mjs +12 -0
- package/dist/hooks/use-push-to-talk.mjs.map +1 -0
- package/dist/index.css +101 -13
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +465 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -19
- package/dist/types/suggestions.d.ts +8 -0
- package/dist/types/suggestions.js +19 -0
- package/dist/types/suggestions.js.map +1 -0
- package/dist/types/suggestions.mjs +1 -0
- package/dist/types/suggestions.mjs.map +1 -0
- package/package.json +6 -6
- package/src/components/chat/Button.tsx +1 -2
- package/src/components/chat/Chat.tsx +163 -104
- package/src/components/chat/ChatContext.tsx +36 -38
- package/src/components/chat/Icons.tsx +44 -0
- package/src/components/chat/Input.tsx +38 -7
- package/src/components/chat/Messages.tsx +3 -3
- package/src/components/chat/Modal.tsx +115 -0
- package/src/components/chat/Popup.tsx +53 -7
- package/src/components/chat/Sidebar.tsx +62 -9
- package/src/components/chat/Suggestion.tsx +109 -0
- package/src/components/chat/Textarea.tsx +1 -1
- package/src/components/chat/index.tsx +1 -0
- package/src/components/chat/props.ts +10 -2
- package/src/css/input.css +18 -8
- package/src/css/messages.css +7 -1
- package/src/css/panel.css +38 -0
- package/src/css/response.css +1 -4
- package/src/css/suggestions.css +35 -0
- package/src/css/window.css +3 -1
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-copilot-chat-suggestions.tsx +117 -0
- package/src/hooks/use-push-to-talk.tsx +162 -0
- package/src/styles.css +2 -0
- package/src/types/suggestions.ts +6 -0
- package/typedoc.json +4 -0
- package/dist/chunk-6U3O2JZP.mjs.map +0 -1
- package/dist/chunk-73EBDGYK.mjs.map +0 -1
- package/dist/chunk-7LMXXGJT.mjs +0 -75
- package/dist/chunk-7LMXXGJT.mjs.map +0 -1
- package/dist/chunk-7YXG7D47.mjs.map +0 -1
- package/dist/chunk-H4VKQGVU.mjs +0 -1
- package/dist/chunk-KE3N45ZY.mjs +0 -63
- package/dist/chunk-KE3N45ZY.mjs.map +0 -1
- package/dist/chunk-T3WYKWNC.mjs.map +0 -1
- package/dist/chunk-UGQQ4WEQ.mjs +0 -1
- package/dist/chunk-YAORLSQ3.mjs.map +0 -1
- package/dist/chunk-YTIGBBTC.mjs.map +0 -1
- /package/dist/{chunk-YEHO5VMA.mjs.map → chunk-CE7PJAAO.mjs.map} +0 -0
- /package/dist/{chunk-H4VKQGVU.mjs.map → chunk-MRFF7GSQ.mjs.map} +0 -0
- /package/dist/{chunk-7JYUCW7H.mjs.map → chunk-PAQWLSA4.mjs.map} +0 -0
- /package/dist/{chunk-UGQQ4WEQ.mjs.map → chunk-T26KLXLH.mjs.map} +0 -0
- /package/dist/{chunk-MBYUBR3F.mjs.map → chunk-UPTB2MVO.mjs.map} +0 -0
- /package/dist/{chunk-WDHLWSSU.mjs.map → chunk-YQ3D5IQV.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -80,14 +80,16 @@ var __async = (__this, __arguments, generator) => {
|
|
|
80
80
|
// src/index.tsx
|
|
81
81
|
var src_exports = {};
|
|
82
82
|
__export(src_exports, {
|
|
83
|
+
CopilotChat: () => CopilotChat,
|
|
83
84
|
CopilotPopup: () => CopilotPopup,
|
|
84
85
|
CopilotSidebar: () => CopilotSidebar,
|
|
85
|
-
useChatContext: () => useChatContext
|
|
86
|
+
useChatContext: () => useChatContext,
|
|
87
|
+
useCopilotChatSuggestions: () => useCopilotChatSuggestions
|
|
86
88
|
});
|
|
87
89
|
module.exports = __toCommonJS(src_exports);
|
|
88
90
|
|
|
89
|
-
// src/components/chat/
|
|
90
|
-
var
|
|
91
|
+
// src/components/chat/Modal.tsx
|
|
92
|
+
var import_react10 = __toESM(require("react"));
|
|
91
93
|
|
|
92
94
|
// src/components/chat/ChatContext.tsx
|
|
93
95
|
var import_react = __toESM(require("react"));
|
|
@@ -193,6 +195,40 @@ var SpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
|
193
195
|
]
|
|
194
196
|
}
|
|
195
197
|
);
|
|
198
|
+
var SmallSpinnerIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
199
|
+
"svg",
|
|
200
|
+
{
|
|
201
|
+
style: {
|
|
202
|
+
animation: "copilotKitSpinAnimation 1s linear infinite"
|
|
203
|
+
},
|
|
204
|
+
width: "13",
|
|
205
|
+
height: "13",
|
|
206
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
207
|
+
fill: "none",
|
|
208
|
+
viewBox: "0 0 24 24",
|
|
209
|
+
children: [
|
|
210
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
211
|
+
"circle",
|
|
212
|
+
{
|
|
213
|
+
style: { opacity: 0.25 },
|
|
214
|
+
cx: "12",
|
|
215
|
+
cy: "12",
|
|
216
|
+
r: "10",
|
|
217
|
+
stroke: "currentColor",
|
|
218
|
+
strokeWidth: "4"
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
222
|
+
"path",
|
|
223
|
+
{
|
|
224
|
+
style: { opacity: 0.75 },
|
|
225
|
+
fill: "currentColor",
|
|
226
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
);
|
|
196
232
|
var ActivityIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
197
233
|
"svg",
|
|
198
234
|
{
|
|
@@ -278,6 +314,25 @@ var RegenerateIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
|
278
314
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M197.67 186.37a8 8 0 0 1 0 11.29C196.58 198.73 170.82 224 128 224c-37.39 0-64.53-22.4-80-39.85V208a8 8 0 0 1-16 0v-48a8 8 0 0 1 8-8h48a8 8 0 0 1 0 16H55.44C67.76 183.35 93 208 128 208c36 0 58.14-21.46 58.36-21.68a8 8 0 0 1 11.31.05ZM216 40a8 8 0 0 0-8 8v23.85C192.53 54.4 165.39 32 128 32c-42.82 0-68.58 25.27-69.66 26.34a8 8 0 0 0 11.3 11.34C69.86 69.46 92 48 128 48c35 0 60.24 24.65 72.56 40H168a8 8 0 0 0 0 16h48a8 8 0 0 0 8-8V48a8 8 0 0 0-8-8Z" })
|
|
279
315
|
}
|
|
280
316
|
);
|
|
317
|
+
var PushToTalkIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
318
|
+
"svg",
|
|
319
|
+
{
|
|
320
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
321
|
+
fill: "none",
|
|
322
|
+
viewBox: "0 0 24 24",
|
|
323
|
+
strokeWidth: 1.5,
|
|
324
|
+
stroke: "currentColor",
|
|
325
|
+
className: "w-6 h-6",
|
|
326
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
327
|
+
"path",
|
|
328
|
+
{
|
|
329
|
+
strokeLinecap: "round",
|
|
330
|
+
strokeLinejoin: "round",
|
|
331
|
+
d: "M12 18.75a6 6 0 0 0 6-6v-1.5m-6 7.5a6 6 0 0 1-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 0 1-3-3V4.5a3 3 0 1 1 6 0v8.25a3 3 0 0 1-3 3Z"
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
);
|
|
281
336
|
|
|
282
337
|
// src/components/chat/ChatContext.tsx
|
|
283
338
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -301,40 +356,34 @@ var ChatContextProvider = ({
|
|
|
301
356
|
open,
|
|
302
357
|
setOpen
|
|
303
358
|
}) => {
|
|
304
|
-
const context =
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
icons
|
|
326
|
-
}),
|
|
327
|
-
open,
|
|
328
|
-
setOpen
|
|
359
|
+
const context = {
|
|
360
|
+
labels: __spreadValues(__spreadValues({}, {
|
|
361
|
+
initial: "",
|
|
362
|
+
title: "CopilotKit",
|
|
363
|
+
placeholder: "Type a message...",
|
|
364
|
+
error: "\u274C An error occurred. Please try again.",
|
|
365
|
+
stopGenerating: "Stop generating",
|
|
366
|
+
regenerateResponse: "Regenerate response"
|
|
367
|
+
}), labels),
|
|
368
|
+
icons: __spreadProps(__spreadValues({}, {
|
|
369
|
+
openIcon: OpenIcon,
|
|
370
|
+
closeIcon: CloseIcon,
|
|
371
|
+
headerCloseIcon: HeaderCloseIcon,
|
|
372
|
+
sendIcon: SendIcon,
|
|
373
|
+
activityIcon: ActivityIcon,
|
|
374
|
+
spinnerIcon: SpinnerIcon,
|
|
375
|
+
stopIcon: StopIcon,
|
|
376
|
+
regenerateIcon: RegenerateIcon,
|
|
377
|
+
pushToTalkIcon: PushToTalkIcon
|
|
378
|
+
}), {
|
|
379
|
+
icons
|
|
329
380
|
}),
|
|
330
|
-
|
|
331
|
-
|
|
381
|
+
open,
|
|
382
|
+
setOpen
|
|
383
|
+
};
|
|
332
384
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChatContext.Provider, { value: context, children });
|
|
333
385
|
};
|
|
334
386
|
|
|
335
|
-
// src/components/chat/Chat.tsx
|
|
336
|
-
var import_react_core2 = require("@copilotkit/react-core");
|
|
337
|
-
|
|
338
387
|
// src/components/chat/Window.tsx
|
|
339
388
|
var import_react2 = __toESM(require("react"));
|
|
340
389
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
@@ -944,7 +993,7 @@ var components = {
|
|
|
944
993
|
// src/components/chat/Messages.tsx
|
|
945
994
|
var import_react_core = require("@copilotkit/react-core");
|
|
946
995
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
947
|
-
var Messages = ({ messages, inProgress }) => {
|
|
996
|
+
var Messages = ({ messages, inProgress, children }) => {
|
|
948
997
|
const { chatComponentsCache } = (0, import_react_core.useCopilotContext)();
|
|
949
998
|
const context = useChatContext();
|
|
950
999
|
const initialMessages = (0, import_react5.useMemo)(
|
|
@@ -1030,7 +1079,7 @@ var Messages = ({ messages, inProgress }) => {
|
|
|
1030
1079
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Markdown, { content: message.content }) }, index);
|
|
1031
1080
|
}
|
|
1032
1081
|
}),
|
|
1033
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("
|
|
1082
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("footer", { ref: messagesEndRef, children })
|
|
1034
1083
|
] });
|
|
1035
1084
|
};
|
|
1036
1085
|
function makeInitialMessages(initial) {
|
|
@@ -1050,7 +1099,7 @@ function makeInitialMessages(initial) {
|
|
|
1050
1099
|
}
|
|
1051
1100
|
|
|
1052
1101
|
// src/components/chat/Input.tsx
|
|
1053
|
-
var
|
|
1102
|
+
var import_react8 = require("react");
|
|
1054
1103
|
|
|
1055
1104
|
// src/components/chat/Textarea.tsx
|
|
1056
1105
|
var import_react6 = require("react");
|
|
@@ -1090,7 +1139,7 @@ var AutoResizingTextarea = (0, import_react6.forwardRef)(
|
|
|
1090
1139
|
onKeyDown,
|
|
1091
1140
|
placeholder,
|
|
1092
1141
|
style: {
|
|
1093
|
-
overflow: "
|
|
1142
|
+
overflow: "auto",
|
|
1094
1143
|
resize: "none",
|
|
1095
1144
|
maxHeight: `${maxHeight}px`
|
|
1096
1145
|
},
|
|
@@ -1101,18 +1150,121 @@ var AutoResizingTextarea = (0, import_react6.forwardRef)(
|
|
|
1101
1150
|
);
|
|
1102
1151
|
var Textarea_default = AutoResizingTextarea;
|
|
1103
1152
|
|
|
1153
|
+
// src/hooks/use-push-to-talk.tsx
|
|
1154
|
+
var import_react_core2 = require("@copilotkit/react-core");
|
|
1155
|
+
var import_react7 = require("react");
|
|
1156
|
+
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
1157
|
+
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
1158
|
+
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1159
|
+
audioContextRef.current = new window.AudioContext();
|
|
1160
|
+
yield audioContextRef.current.resume();
|
|
1161
|
+
}
|
|
1162
|
+
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
1163
|
+
mediaRecorderRef.current.start(1e3);
|
|
1164
|
+
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
1165
|
+
recordedChunks.push(event.data);
|
|
1166
|
+
};
|
|
1167
|
+
mediaRecorderRef.current.onstop = onStop;
|
|
1168
|
+
});
|
|
1169
|
+
var stopRecording = (mediaRecorderRef) => {
|
|
1170
|
+
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
1171
|
+
mediaRecorderRef.current.stop();
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
|
|
1175
|
+
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
1176
|
+
const formData = new FormData();
|
|
1177
|
+
formData.append("file", completeBlob, "recording.mp4");
|
|
1178
|
+
const response = yield fetch(transcribeAudioUrl, {
|
|
1179
|
+
method: "POST",
|
|
1180
|
+
body: formData
|
|
1181
|
+
});
|
|
1182
|
+
if (!response.ok) {
|
|
1183
|
+
throw new Error(`Error: ${response.statusText}`);
|
|
1184
|
+
}
|
|
1185
|
+
const transcription = yield response.json();
|
|
1186
|
+
return transcription.text;
|
|
1187
|
+
});
|
|
1188
|
+
var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
|
|
1189
|
+
const encodedText = encodeURIComponent(text);
|
|
1190
|
+
const url = `${textToSpeechUrl}?text=${encodedText}`;
|
|
1191
|
+
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
1192
|
+
const source = audioContext.createBufferSource();
|
|
1193
|
+
source.buffer = audioBuffer;
|
|
1194
|
+
source.connect(audioContext.destination);
|
|
1195
|
+
source.start(0);
|
|
1196
|
+
}).catch((error) => {
|
|
1197
|
+
console.error("Error with decoding audio data", error);
|
|
1198
|
+
});
|
|
1199
|
+
};
|
|
1200
|
+
var usePushToTalk = ({
|
|
1201
|
+
sendFunction,
|
|
1202
|
+
inProgress
|
|
1203
|
+
}) => {
|
|
1204
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react7.useState)("idle");
|
|
1205
|
+
const mediaStreamRef = (0, import_react7.useRef)(null);
|
|
1206
|
+
const audioContextRef = (0, import_react7.useRef)(null);
|
|
1207
|
+
const mediaRecorderRef = (0, import_react7.useRef)(null);
|
|
1208
|
+
const recordedChunks = (0, import_react7.useRef)([]);
|
|
1209
|
+
const context = (0, import_react_core2.useCopilotContext)();
|
|
1210
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react7.useState)(null);
|
|
1211
|
+
(0, import_react7.useEffect)(() => {
|
|
1212
|
+
if (pushToTalkState === "recording") {
|
|
1213
|
+
startRecording(
|
|
1214
|
+
mediaStreamRef,
|
|
1215
|
+
mediaRecorderRef,
|
|
1216
|
+
audioContextRef,
|
|
1217
|
+
recordedChunks.current,
|
|
1218
|
+
() => {
|
|
1219
|
+
setPushToTalkState("transcribing");
|
|
1220
|
+
}
|
|
1221
|
+
);
|
|
1222
|
+
} else {
|
|
1223
|
+
stopRecording(mediaRecorderRef);
|
|
1224
|
+
if (pushToTalkState === "transcribing") {
|
|
1225
|
+
transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
|
|
1226
|
+
(transcription) => __async(void 0, null, function* () {
|
|
1227
|
+
recordedChunks.current = [];
|
|
1228
|
+
setPushToTalkState("idle");
|
|
1229
|
+
const message = yield sendFunction(transcription);
|
|
1230
|
+
setStartReadingFromMessageId(message.id);
|
|
1231
|
+
})
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
return () => {
|
|
1236
|
+
stopRecording(mediaRecorderRef);
|
|
1237
|
+
};
|
|
1238
|
+
}, [pushToTalkState]);
|
|
1239
|
+
(0, import_react7.useEffect)(() => {
|
|
1240
|
+
if (inProgress === false && startReadingFromMessageId) {
|
|
1241
|
+
const lastMessageIndex = context.messages.findIndex(
|
|
1242
|
+
(message) => message.id === startReadingFromMessageId
|
|
1243
|
+
);
|
|
1244
|
+
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant" && message.content);
|
|
1245
|
+
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
1246
|
+
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
1247
|
+
setStartReadingFromMessageId(null);
|
|
1248
|
+
}
|
|
1249
|
+
}, [startReadingFromMessageId, inProgress]);
|
|
1250
|
+
return { pushToTalkState, setPushToTalkState };
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1104
1253
|
// src/components/chat/Input.tsx
|
|
1254
|
+
var import_react_core3 = require("@copilotkit/react-core");
|
|
1105
1255
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1106
|
-
var Input = ({ inProgress, onSend,
|
|
1256
|
+
var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
1107
1257
|
const context = useChatContext();
|
|
1108
|
-
const
|
|
1258
|
+
const copilotContext = (0, import_react_core3.useCopilotContext)();
|
|
1259
|
+
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
1260
|
+
const textareaRef = (0, import_react8.useRef)(null);
|
|
1109
1261
|
const handleDivClick = (event) => {
|
|
1110
1262
|
var _a;
|
|
1111
1263
|
if (event.target !== event.currentTarget)
|
|
1112
1264
|
return;
|
|
1113
1265
|
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1114
1266
|
};
|
|
1115
|
-
const [text, setText] = (0,
|
|
1267
|
+
const [text, setText] = (0, import_react8.useState)("");
|
|
1116
1268
|
const send = () => {
|
|
1117
1269
|
var _a;
|
|
1118
1270
|
if (inProgress)
|
|
@@ -1121,17 +1273,20 @@ var Input = ({ inProgress, onSend, children, isVisible = false }) => {
|
|
|
1121
1273
|
setText("");
|
|
1122
1274
|
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1123
1275
|
};
|
|
1124
|
-
(0,
|
|
1276
|
+
(0, import_react8.useEffect)(() => {
|
|
1125
1277
|
var _a;
|
|
1126
1278
|
if (isVisible) {
|
|
1127
1279
|
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1128
1280
|
}
|
|
1129
1281
|
}, [isVisible]);
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1282
|
+
const { pushToTalkState, setPushToTalkState } = usePushToTalk({
|
|
1283
|
+
sendFunction: onSend,
|
|
1284
|
+
inProgress
|
|
1285
|
+
});
|
|
1286
|
+
const sendIcon = inProgress || pushToTalkState === "transcribing" ? context.icons.activityIcon : context.icons.sendIcon;
|
|
1287
|
+
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
1288
|
+
const sendDisabled = inProgress || text.length === 0 || pushToTalkState !== "idle";
|
|
1132
1289
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
|
|
1133
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children }),
|
|
1134
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: "copilotKitSendButton", disabled, onClick: send, children: icon }),
|
|
1135
1290
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1136
1291
|
Textarea_default,
|
|
1137
1292
|
{
|
|
@@ -1148,13 +1303,21 @@ var Input = ({ inProgress, onSend, children, isVisible = false }) => {
|
|
|
1148
1303
|
}
|
|
1149
1304
|
}
|
|
1150
1305
|
}
|
|
1151
|
-
)
|
|
1306
|
+
),
|
|
1307
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitInputControls", children: [
|
|
1308
|
+
showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1309
|
+
"button",
|
|
1310
|
+
{
|
|
1311
|
+
onClick: () => setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing"),
|
|
1312
|
+
className: pushToTalkState === "recording" ? "copilotKitPushToTalkRecording" : "",
|
|
1313
|
+
children: context.icons.pushToTalkIcon
|
|
1314
|
+
}
|
|
1315
|
+
),
|
|
1316
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { disabled: sendDisabled, onClick: send, children: sendIcon })
|
|
1317
|
+
] })
|
|
1152
1318
|
] });
|
|
1153
1319
|
};
|
|
1154
1320
|
|
|
1155
|
-
// src/components/chat/Chat.tsx
|
|
1156
|
-
var import_nanoid2 = require("nanoid");
|
|
1157
|
-
|
|
1158
1321
|
// src/components/chat/Response.tsx
|
|
1159
1322
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1160
1323
|
var ResponseButton = ({ onClick, inProgress }) => {
|
|
@@ -1165,9 +1328,203 @@ var ResponseButton = ({ onClick, inProgress }) => {
|
|
|
1165
1328
|
] });
|
|
1166
1329
|
};
|
|
1167
1330
|
|
|
1168
|
-
// src/components/chat/
|
|
1331
|
+
// src/components/chat/Suggestion.tsx
|
|
1332
|
+
var import_react_core4 = require("@copilotkit/react-core");
|
|
1169
1333
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1170
|
-
|
|
1334
|
+
function Suggestion({ title, message, onClick, partial, className }) {
|
|
1335
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
1336
|
+
"button",
|
|
1337
|
+
{
|
|
1338
|
+
disabled: partial,
|
|
1339
|
+
onClick: (e) => {
|
|
1340
|
+
e.preventDefault();
|
|
1341
|
+
onClick(message);
|
|
1342
|
+
},
|
|
1343
|
+
className: className || "suggestion",
|
|
1344
|
+
children: [
|
|
1345
|
+
partial && SmallSpinnerIcon,
|
|
1346
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { children: title })
|
|
1347
|
+
]
|
|
1348
|
+
}
|
|
1349
|
+
);
|
|
1350
|
+
}
|
|
1351
|
+
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1352
|
+
const abortController = abortControllerRef.current;
|
|
1353
|
+
const tools = JSON.stringify(context.getChatCompletionFunctionDescriptions(context.entryPoints));
|
|
1354
|
+
const allSuggestions = [];
|
|
1355
|
+
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
1356
|
+
try {
|
|
1357
|
+
const numOfSuggestionsInstructions = config.minSuggestions === 0 ? `Produce up to ${config.maxSuggestions} suggestions. If there are no highly relevant suggestions you can think of, provide an empty array.` : `Produce between ${config.minSuggestions} and ${config.maxSuggestions} suggestions.`;
|
|
1358
|
+
const result = yield (0, import_react_core4.extract)({
|
|
1359
|
+
context,
|
|
1360
|
+
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. " + config.instructions + "\n\n" + numOfSuggestionsInstructions,
|
|
1361
|
+
data: "Available tools: " + tools + "\n\n",
|
|
1362
|
+
parameters: [
|
|
1363
|
+
{
|
|
1364
|
+
name: "suggestions",
|
|
1365
|
+
type: "object[]",
|
|
1366
|
+
attributes: [
|
|
1367
|
+
{
|
|
1368
|
+
name: "title",
|
|
1369
|
+
description: "The title of the suggestion. This is shown as a button and should be short.",
|
|
1370
|
+
type: "string"
|
|
1371
|
+
},
|
|
1372
|
+
{
|
|
1373
|
+
name: "message",
|
|
1374
|
+
description: "The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.",
|
|
1375
|
+
type: "string"
|
|
1376
|
+
}
|
|
1377
|
+
]
|
|
1378
|
+
}
|
|
1379
|
+
],
|
|
1380
|
+
include: {
|
|
1381
|
+
messages: true,
|
|
1382
|
+
readable: true
|
|
1383
|
+
},
|
|
1384
|
+
abortSignal: abortController == null ? void 0 : abortController.signal,
|
|
1385
|
+
stream: ({ status, args }) => {
|
|
1386
|
+
const suggestions = args.suggestions || [];
|
|
1387
|
+
const newSuggestions = [];
|
|
1388
|
+
for (let i = 0; i < suggestions.length; i++) {
|
|
1389
|
+
if (config.maxSuggestions !== void 0 && i >= config.maxSuggestions) {
|
|
1390
|
+
break;
|
|
1391
|
+
}
|
|
1392
|
+
const { title, message } = suggestions[i];
|
|
1393
|
+
const partial = i == suggestions.length - 1 && status !== "complete";
|
|
1394
|
+
newSuggestions.push({
|
|
1395
|
+
title,
|
|
1396
|
+
message,
|
|
1397
|
+
partial,
|
|
1398
|
+
className: config.className
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
setCurrentSuggestions([...allSuggestions, ...newSuggestions]);
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
allSuggestions.push(...result.suggestions);
|
|
1405
|
+
} catch (error) {
|
|
1406
|
+
console.error("Error loading suggestions", error);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
if (abortControllerRef.current === abortController) {
|
|
1410
|
+
abortControllerRef.current = null;
|
|
1411
|
+
}
|
|
1412
|
+
});
|
|
1413
|
+
|
|
1414
|
+
// src/components/chat/Chat.tsx
|
|
1415
|
+
var import_react9 = __toESM(require("react"));
|
|
1416
|
+
var import_react_core5 = require("@copilotkit/react-core");
|
|
1417
|
+
var import_nanoid2 = require("nanoid");
|
|
1418
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1419
|
+
function CopilotChat({
|
|
1420
|
+
instructions,
|
|
1421
|
+
onSubmitMessage,
|
|
1422
|
+
icons,
|
|
1423
|
+
labels,
|
|
1424
|
+
makeSystemMessage,
|
|
1425
|
+
showResponseButton = true,
|
|
1426
|
+
onInProgress,
|
|
1427
|
+
Messages: Messages2 = Messages,
|
|
1428
|
+
Input: Input2 = Input,
|
|
1429
|
+
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1430
|
+
className
|
|
1431
|
+
}) {
|
|
1432
|
+
const { visibleMessages, isLoading, currentSuggestions, sendMessage, stop, reload } = useCopilotChatLogic(instructions, makeSystemMessage, onInProgress, onSubmitMessage);
|
|
1433
|
+
const context = import_react9.default.useContext(ChatContext);
|
|
1434
|
+
let open = true;
|
|
1435
|
+
let setOpen = () => {
|
|
1436
|
+
};
|
|
1437
|
+
if (context) {
|
|
1438
|
+
icons = context.icons;
|
|
1439
|
+
labels = context.labels;
|
|
1440
|
+
open = context.open;
|
|
1441
|
+
setOpen = context.setOpen;
|
|
1442
|
+
}
|
|
1443
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ChatContextProvider, { icons, labels, open, setOpen, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `copilotKitPanel ${className}`, children: [
|
|
1444
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Messages2, { messages: visibleMessages, inProgress: isLoading, children: [
|
|
1445
|
+
currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { children: [
|
|
1446
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("h6", { children: "Suggested:" }),
|
|
1447
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "suggestions", children: currentSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1448
|
+
Suggestion,
|
|
1449
|
+
{
|
|
1450
|
+
title: suggestion.title,
|
|
1451
|
+
message: suggestion.message,
|
|
1452
|
+
partial: suggestion.partial,
|
|
1453
|
+
className: suggestion.className,
|
|
1454
|
+
onClick: (message) => sendMessage(message)
|
|
1455
|
+
},
|
|
1456
|
+
index
|
|
1457
|
+
)) })
|
|
1458
|
+
] }),
|
|
1459
|
+
showResponseButton && visibleMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ResponseButton2, { onClick: isLoading ? stop : reload, inProgress: isLoading })
|
|
1460
|
+
] }),
|
|
1461
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Input2, { inProgress: isLoading, onSend: sendMessage, isVisible: true })
|
|
1462
|
+
] }) });
|
|
1463
|
+
}
|
|
1464
|
+
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
1465
|
+
var useCopilotChatLogic = (instructions, makeSystemMessage, onInProgress, onSubmitMessage) => {
|
|
1466
|
+
const { visibleMessages, append, reload, stop, isLoading, input, setInput } = (0, import_react_core5.useCopilotChat)({
|
|
1467
|
+
id: (0, import_nanoid2.nanoid)(),
|
|
1468
|
+
makeSystemMessage,
|
|
1469
|
+
additionalInstructions: instructions
|
|
1470
|
+
});
|
|
1471
|
+
const [currentSuggestions, setCurrentSuggestions] = (0, import_react9.useState)([]);
|
|
1472
|
+
const suggestionsAbortControllerRef = (0, import_react9.useRef)(null);
|
|
1473
|
+
const debounceTimerRef = (0, import_react9.useRef)();
|
|
1474
|
+
const abortSuggestions = () => {
|
|
1475
|
+
var _a;
|
|
1476
|
+
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
1477
|
+
suggestionsAbortControllerRef.current = null;
|
|
1478
|
+
};
|
|
1479
|
+
const context = (0, import_react_core5.useCopilotContext)();
|
|
1480
|
+
(0, import_react9.useEffect)(() => {
|
|
1481
|
+
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
1482
|
+
abortSuggestions();
|
|
1483
|
+
debounceTimerRef.current = setTimeout(
|
|
1484
|
+
() => {
|
|
1485
|
+
if (!isLoading && Object.keys(context.chatSuggestionConfiguration).length !== 0) {
|
|
1486
|
+
suggestionsAbortControllerRef.current = new AbortController();
|
|
1487
|
+
reloadSuggestions(
|
|
1488
|
+
context,
|
|
1489
|
+
context.chatSuggestionConfiguration,
|
|
1490
|
+
setCurrentSuggestions,
|
|
1491
|
+
suggestionsAbortControllerRef
|
|
1492
|
+
);
|
|
1493
|
+
}
|
|
1494
|
+
},
|
|
1495
|
+
currentSuggestions.length == 0 ? 0 : SUGGESTIONS_DEBOUNCE_TIMEOUT
|
|
1496
|
+
);
|
|
1497
|
+
return () => {
|
|
1498
|
+
clearTimeout(debounceTimerRef.current);
|
|
1499
|
+
};
|
|
1500
|
+
}, [isLoading, context.chatSuggestionConfiguration]);
|
|
1501
|
+
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
1502
|
+
abortSuggestions();
|
|
1503
|
+
setCurrentSuggestions([]);
|
|
1504
|
+
onSubmitMessage == null ? void 0 : onSubmitMessage(messageContent);
|
|
1505
|
+
const message = {
|
|
1506
|
+
id: (0, import_nanoid2.nanoid)(),
|
|
1507
|
+
content: messageContent,
|
|
1508
|
+
role: "user"
|
|
1509
|
+
};
|
|
1510
|
+
append(message);
|
|
1511
|
+
return message;
|
|
1512
|
+
});
|
|
1513
|
+
return {
|
|
1514
|
+
visibleMessages,
|
|
1515
|
+
isLoading,
|
|
1516
|
+
currentSuggestions,
|
|
1517
|
+
sendMessage,
|
|
1518
|
+
stop,
|
|
1519
|
+
reload,
|
|
1520
|
+
input,
|
|
1521
|
+
setInput
|
|
1522
|
+
};
|
|
1523
|
+
};
|
|
1524
|
+
|
|
1525
|
+
// src/components/chat/Modal.tsx
|
|
1526
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1527
|
+
var CopilotModal = ({
|
|
1171
1528
|
instructions,
|
|
1172
1529
|
defaultOpen = false,
|
|
1173
1530
|
clickOutsideToClose = true,
|
|
@@ -1189,32 +1546,16 @@ var CopilotChat = ({
|
|
|
1189
1546
|
className,
|
|
1190
1547
|
children
|
|
1191
1548
|
}) => {
|
|
1192
|
-
const
|
|
1193
|
-
id: (0, import_nanoid2.nanoid)(),
|
|
1194
|
-
makeSystemMessage,
|
|
1195
|
-
additionalInstructions: instructions
|
|
1196
|
-
});
|
|
1197
|
-
(0, import_react8.useEffect)(() => {
|
|
1198
|
-
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
1199
|
-
}, [isLoading]);
|
|
1200
|
-
const [openState, setOpenState] = import_react8.default.useState(defaultOpen);
|
|
1549
|
+
const [openState, setOpenState] = import_react10.default.useState(defaultOpen);
|
|
1201
1550
|
const setOpen = (open) => {
|
|
1202
1551
|
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
1203
1552
|
setOpenState(open);
|
|
1204
1553
|
};
|
|
1205
|
-
|
|
1206
|
-
onSubmitMessage == null ? void 0 : onSubmitMessage(message);
|
|
1207
|
-
append({
|
|
1208
|
-
id: (0, import_nanoid2.nanoid)(),
|
|
1209
|
-
content: message,
|
|
1210
|
-
role: "user"
|
|
1211
|
-
});
|
|
1212
|
-
});
|
|
1213
|
-
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: [
|
|
1554
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: [
|
|
1214
1555
|
children,
|
|
1215
|
-
/* @__PURE__ */ (0,
|
|
1216
|
-
/* @__PURE__ */ (0,
|
|
1217
|
-
/* @__PURE__ */ (0,
|
|
1556
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className, children: [
|
|
1557
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Button2, { open: openState, setOpen }),
|
|
1558
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
1218
1559
|
Window2,
|
|
1219
1560
|
{
|
|
1220
1561
|
open: openState,
|
|
@@ -1223,9 +1564,20 @@ var CopilotChat = ({
|
|
|
1223
1564
|
shortcut,
|
|
1224
1565
|
hitEscapeToClose,
|
|
1225
1566
|
children: [
|
|
1226
|
-
/* @__PURE__ */ (0,
|
|
1227
|
-
/* @__PURE__ */ (0,
|
|
1228
|
-
|
|
1567
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Header2, { open: openState, setOpen }),
|
|
1568
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1569
|
+
CopilotChat,
|
|
1570
|
+
{
|
|
1571
|
+
instructions,
|
|
1572
|
+
makeSystemMessage,
|
|
1573
|
+
onInProgress,
|
|
1574
|
+
onSubmitMessage,
|
|
1575
|
+
showResponseButton,
|
|
1576
|
+
Messages: Messages2,
|
|
1577
|
+
Input: Input2,
|
|
1578
|
+
ResponseButton: ResponseButton2
|
|
1579
|
+
}
|
|
1580
|
+
)
|
|
1229
1581
|
]
|
|
1230
1582
|
}
|
|
1231
1583
|
)
|
|
@@ -1234,22 +1586,22 @@ var CopilotChat = ({
|
|
|
1234
1586
|
};
|
|
1235
1587
|
|
|
1236
1588
|
// src/components/chat/Popup.tsx
|
|
1237
|
-
var
|
|
1238
|
-
|
|
1589
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1590
|
+
function CopilotPopup(props) {
|
|
1239
1591
|
props = __spreadProps(__spreadValues({}, props), {
|
|
1240
1592
|
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup"
|
|
1241
1593
|
});
|
|
1242
|
-
return /* @__PURE__ */ (0,
|
|
1243
|
-
}
|
|
1594
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CopilotModal, __spreadProps(__spreadValues({}, props), { children: props.children }));
|
|
1595
|
+
}
|
|
1244
1596
|
|
|
1245
1597
|
// src/components/chat/Sidebar.tsx
|
|
1246
|
-
var
|
|
1247
|
-
var
|
|
1248
|
-
|
|
1598
|
+
var import_react11 = require("react");
|
|
1599
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1600
|
+
function CopilotSidebar(props) {
|
|
1249
1601
|
props = __spreadProps(__spreadValues({}, props), {
|
|
1250
1602
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
1251
1603
|
});
|
|
1252
|
-
const [expandedClassName, setExpandedClassName] = (0,
|
|
1604
|
+
const [expandedClassName, setExpandedClassName] = (0, import_react11.useState)(
|
|
1253
1605
|
props.defaultOpen ? "sidebarExpanded" : ""
|
|
1254
1606
|
);
|
|
1255
1607
|
const onSetOpen = (open) => {
|
|
@@ -1257,12 +1609,39 @@ var CopilotSidebar = (props) => {
|
|
|
1257
1609
|
(_a = props.onSetOpen) == null ? void 0 : _a.call(props, open);
|
|
1258
1610
|
setExpandedClassName(open ? "sidebarExpanded" : "");
|
|
1259
1611
|
};
|
|
1260
|
-
return /* @__PURE__ */ (0,
|
|
1261
|
-
}
|
|
1612
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: `copilotKitSidebarContentWrapper ${expandedClassName}`, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(CopilotModal, __spreadProps(__spreadValues(__spreadValues({}, props), { onSetOpen }), { children: props.children })) });
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
1616
|
+
var import_react12 = require("react");
|
|
1617
|
+
var import_nanoid3 = require("nanoid");
|
|
1618
|
+
var import_react_core6 = require("@copilotkit/react-core");
|
|
1619
|
+
function useCopilotChatSuggestions({
|
|
1620
|
+
instructions,
|
|
1621
|
+
className,
|
|
1622
|
+
minSuggestions = 1,
|
|
1623
|
+
maxSuggestions = 3
|
|
1624
|
+
}, dependencies = []) {
|
|
1625
|
+
const context = (0, import_react_core6.useCopilotContext)();
|
|
1626
|
+
(0, import_react12.useEffect)(() => {
|
|
1627
|
+
const id = (0, import_nanoid3.nanoid)();
|
|
1628
|
+
context.addChatSuggestionConfiguration(id, {
|
|
1629
|
+
instructions,
|
|
1630
|
+
minSuggestions,
|
|
1631
|
+
maxSuggestions,
|
|
1632
|
+
className
|
|
1633
|
+
});
|
|
1634
|
+
return () => {
|
|
1635
|
+
context.removeChatSuggestionConfiguration(id);
|
|
1636
|
+
};
|
|
1637
|
+
}, dependencies);
|
|
1638
|
+
}
|
|
1262
1639
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1263
1640
|
0 && (module.exports = {
|
|
1641
|
+
CopilotChat,
|
|
1264
1642
|
CopilotPopup,
|
|
1265
1643
|
CopilotSidebar,
|
|
1266
|
-
useChatContext
|
|
1644
|
+
useChatContext,
|
|
1645
|
+
useCopilotChatSuggestions
|
|
1267
1646
|
});
|
|
1268
1647
|
//# sourceMappingURL=index.js.map
|