@copilotkit/react-ui 0.36.0-mme-push-to-talk.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 +174 -167
- package/CHANGELOG.md +12 -0
- package/dist/{chunk-DMAQBCTX.mjs → chunk-4MKP23AD.mjs} +6 -4
- package/dist/chunk-4MKP23AD.mjs.map +1 -0
- package/dist/{chunk-UVMROYDT.mjs → chunk-6XLZXLM5.mjs} +5 -5
- package/dist/{chunk-UVMROYDT.mjs.map → chunk-6XLZXLM5.mjs.map} +1 -1
- package/dist/{chunk-XYM43AHP.mjs → chunk-7FES2IQA.mjs} +3 -3
- package/dist/chunk-ANO23V2M.mjs +135 -0
- package/dist/chunk-ANO23V2M.mjs.map +1 -0
- package/dist/{chunk-DRNCOXZO.mjs → chunk-BL65ZC6L.mjs} +28 -7
- package/dist/chunk-BL65ZC6L.mjs.map +1 -0
- package/dist/{chunk-PGZDQT74.mjs → chunk-CE7PJAAO.mjs} +2 -2
- package/dist/{chunk-FWTPMPSN.mjs → chunk-FZC7X5PK.mjs} +23 -3
- package/dist/{chunk-FWTPMPSN.mjs.map → chunk-FZC7X5PK.mjs.map} +1 -1
- package/dist/{chunk-Z45ZEXJW.mjs → chunk-LTCJCXCP.mjs} +5 -8
- package/dist/chunk-LTCJCXCP.mjs.map +1 -0
- package/dist/chunk-MRFF7GSQ.mjs +1 -0
- package/dist/{chunk-SKC7AJIV.mjs → chunk-MRXNTQOX.mjs} +1 -3
- package/dist/{chunk-MWFHYCQB.mjs → chunk-PAQWLSA4.mjs} +2 -2
- package/dist/chunk-RT2XG2T7.mjs +25 -0
- package/dist/chunk-RT2XG2T7.mjs.map +1 -0
- package/dist/chunk-T3JTSIHT.mjs +93 -0
- package/dist/chunk-T3JTSIHT.mjs.map +1 -0
- package/dist/{chunk-A7J4KGLP.mjs → chunk-UPTB2MVO.mjs} +2 -2
- package/dist/{chunk-KZME7C5S.mjs → chunk-VUZA5AFH.mjs} +8 -11
- package/dist/chunk-VUZA5AFH.mjs.map +1 -0
- package/dist/{chunk-XWWMYJJF.mjs → chunk-XRODMID5.mjs} +5 -5
- package/dist/{chunk-XWWMYJJF.mjs.map → chunk-XRODMID5.mjs.map} +1 -1
- package/dist/{chunk-ZKLK3M77.mjs → chunk-YQ3D5IQV.mjs} +3 -3
- 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.d.ts +1 -1
- package/dist/components/chat/Button.js +2 -30
- package/dist/components/chat/Button.js.map +1 -1
- package/dist/components/chat/Button.mjs +4 -4
- package/dist/components/chat/Chat.d.ts +66 -47
- package/dist/components/chat/Chat.js +274 -430
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +16 -17
- package/dist/components/chat/ChatContext.d.ts +17 -22
- package/dist/components/chat/ChatContext.js +23 -8
- package/dist/components/chat/ChatContext.js.map +1 -1
- package/dist/components/chat/ChatContext.mjs +3 -3
- package/dist/components/chat/CodeBlock.js.map +1 -1
- package/dist/components/chat/CodeBlock.mjs +3 -3
- package/dist/components/chat/Header.js.map +1 -1
- package/dist/components/chat/Header.mjs +4 -4
- package/dist/components/chat/Icons.d.ts +6 -5
- package/dist/components/chat/Icons.js +21 -0
- package/dist/components/chat/Icons.js.map +1 -1
- package/dist/components/chat/Icons.mjs +4 -2
- package/dist/components/chat/Input.js +147 -9
- package/dist/components/chat/Input.js.map +1 -1
- package/dist/components/chat/Input.mjs +6 -5
- package/dist/components/chat/Markdown.js.map +1 -1
- package/dist/components/chat/Markdown.mjs +4 -4
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +6 -6
- 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/Popup.d.ts +6 -5
- package/dist/components/chat/Popup.js +288 -249
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +16 -15
- package/dist/components/chat/Response.js.map +1 -1
- package/dist/components/chat/Response.mjs +4 -4
- package/dist/components/chat/Sidebar.d.ts +6 -5
- package/dist/components/chat/Sidebar.js +290 -251
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +16 -15
- package/dist/components/chat/Suggestion.d.ts +1 -2
- package/dist/components/chat/Suggestion.js.map +1 -1
- package/dist/components/chat/Suggestion.mjs +3 -3
- 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 +2 -2
- package/dist/components/chat/Window.mjs +1 -1
- package/dist/components/chat/index.d.ts +2 -1
- package/dist/components/chat/index.js +294 -253
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +23 -19
- package/dist/components/chat/props.d.ts +1 -3
- package/dist/components/chat/props.js.map +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +294 -253
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +23 -19
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +6 -31
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +2 -22
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +26 -4
- package/dist/hooks/use-copilot-chat-suggestions.js +6 -31
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -1
- package/dist/hooks/use-copilot-chat-suggestions.mjs +2 -22
- package/dist/hooks/use-copy-to-clipboard.mjs +1 -1
- 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 +60 -8
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +300 -258
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -24
- package/dist/lib/utils.mjs +1 -1
- package/dist/types/suggestions.d.ts +1 -21
- package/dist/types/suggestions.js.map +1 -1
- package/package.json +6 -6
- package/src/components/chat/Button.tsx +2 -35
- package/src/components/chat/Chat.tsx +126 -255
- package/src/components/chat/ChatContext.tsx +8 -22
- package/src/components/chat/Icons.tsx +17 -0
- package/src/components/chat/Input.tsx +37 -5
- package/src/components/chat/Modal.tsx +115 -0
- package/src/components/chat/Popup.tsx +3 -3
- package/src/components/chat/Sidebar.tsx +4 -4
- package/src/components/chat/Suggestion.tsx +6 -2
- package/src/components/chat/Textarea.tsx +1 -1
- package/src/components/chat/index.tsx +1 -0
- package/src/components/chat/props.ts +1 -3
- package/src/css/input.css +18 -8
- package/src/css/panel.css +38 -0
- package/src/css/window.css +3 -1
- package/src/hooks/use-copilot-chat-suggestions.tsx +31 -5
- package/src/hooks/use-push-to-talk.tsx +162 -0
- package/src/styles.css +1 -0
- package/src/types/suggestions.ts +0 -24
- package/dist/chunk-5ASYNEHX.mjs +0 -53
- package/dist/chunk-5ASYNEHX.mjs.map +0 -1
- package/dist/chunk-DMAQBCTX.mjs.map +0 -1
- package/dist/chunk-DRNCOXZO.mjs.map +0 -1
- package/dist/chunk-JPX5ODUX.mjs +0 -266
- package/dist/chunk-JPX5ODUX.mjs.map +0 -1
- package/dist/chunk-KZME7C5S.mjs.map +0 -1
- package/dist/chunk-PEDSZYHE.mjs +0 -36
- package/dist/chunk-PEDSZYHE.mjs.map +0 -1
- package/dist/chunk-UGQQ4WEQ.mjs +0 -1
- package/dist/chunk-Z45ZEXJW.mjs.map +0 -1
- package/dist/components/chat/audio.d.ts +0 -7
- package/dist/components/chat/audio.js +0 -77
- package/dist/components/chat/audio.js.map +0 -1
- package/dist/components/chat/audio.mjs +0 -10
- package/src/components/chat/audio.ts +0 -26
- /package/dist/{chunk-XYM43AHP.mjs.map → chunk-7FES2IQA.mjs.map} +0 -0
- /package/dist/{chunk-PGZDQT74.mjs.map → chunk-CE7PJAAO.mjs.map} +0 -0
- /package/dist/{chunk-SKC7AJIV.mjs.map → chunk-MRFF7GSQ.mjs.map} +0 -0
- /package/dist/{chunk-UGQQ4WEQ.mjs.map → chunk-MRXNTQOX.mjs.map} +0 -0
- /package/dist/{chunk-MWFHYCQB.mjs.map → chunk-PAQWLSA4.mjs.map} +0 -0
- /package/dist/{chunk-A7J4KGLP.mjs.map → chunk-UPTB2MVO.mjs.map} +0 -0
- /package/dist/{chunk-ZKLK3M77.mjs.map → chunk-YQ3D5IQV.mjs.map} +0 -0
- /package/dist/components/chat/{audio.mjs.map → Modal.mjs.map} +0 -0
|
@@ -22,7 +22,6 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __restKey = (key) => typeof key === "symbol" ? key : key + "";
|
|
26
25
|
var __objRest = (source, exclude) => {
|
|
27
26
|
var target = {};
|
|
28
27
|
for (var prop in source)
|
|
@@ -84,8 +83,8 @@ __export(Popup_exports, {
|
|
|
84
83
|
});
|
|
85
84
|
module.exports = __toCommonJS(Popup_exports);
|
|
86
85
|
|
|
87
|
-
// src/components/chat/
|
|
88
|
-
var
|
|
86
|
+
// src/components/chat/Modal.tsx
|
|
87
|
+
var import_react10 = __toESM(require("react"));
|
|
89
88
|
|
|
90
89
|
// src/components/chat/ChatContext.tsx
|
|
91
90
|
var import_react = __toESM(require("react"));
|
|
@@ -310,6 +309,25 @@ var RegenerateIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
|
310
309
|
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" })
|
|
311
310
|
}
|
|
312
311
|
);
|
|
312
|
+
var PushToTalkIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
313
|
+
"svg",
|
|
314
|
+
{
|
|
315
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
316
|
+
fill: "none",
|
|
317
|
+
viewBox: "0 0 24 24",
|
|
318
|
+
strokeWidth: 1.5,
|
|
319
|
+
stroke: "currentColor",
|
|
320
|
+
className: "w-6 h-6",
|
|
321
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
322
|
+
"path",
|
|
323
|
+
{
|
|
324
|
+
strokeLinecap: "round",
|
|
325
|
+
strokeLinejoin: "round",
|
|
326
|
+
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"
|
|
327
|
+
}
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
);
|
|
313
331
|
|
|
314
332
|
// src/components/chat/ChatContext.tsx
|
|
315
333
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -331,16 +349,13 @@ var ChatContextProvider = ({
|
|
|
331
349
|
icons,
|
|
332
350
|
children,
|
|
333
351
|
open,
|
|
334
|
-
setOpen
|
|
335
|
-
addChatSuggestionConfiguration,
|
|
336
|
-
removeChatSuggestionConfiguration
|
|
352
|
+
setOpen
|
|
337
353
|
}) => {
|
|
338
354
|
const context = {
|
|
339
355
|
labels: __spreadValues(__spreadValues({}, {
|
|
340
356
|
initial: "",
|
|
341
357
|
title: "CopilotKit",
|
|
342
358
|
placeholder: "Type a message...",
|
|
343
|
-
thinking: "Thinking...",
|
|
344
359
|
error: "\u274C An error occurred. Please try again.",
|
|
345
360
|
stopGenerating: "Stop generating",
|
|
346
361
|
regenerateResponse: "Regenerate response"
|
|
@@ -353,21 +368,17 @@ var ChatContextProvider = ({
|
|
|
353
368
|
activityIcon: ActivityIcon,
|
|
354
369
|
spinnerIcon: SpinnerIcon,
|
|
355
370
|
stopIcon: StopIcon,
|
|
356
|
-
regenerateIcon: RegenerateIcon
|
|
371
|
+
regenerateIcon: RegenerateIcon,
|
|
372
|
+
pushToTalkIcon: PushToTalkIcon
|
|
357
373
|
}), {
|
|
358
374
|
icons
|
|
359
375
|
}),
|
|
360
376
|
open,
|
|
361
|
-
setOpen
|
|
362
|
-
addChatSuggestionConfiguration,
|
|
363
|
-
removeChatSuggestionConfiguration
|
|
377
|
+
setOpen
|
|
364
378
|
};
|
|
365
379
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChatContext.Provider, { value: context, children });
|
|
366
380
|
};
|
|
367
381
|
|
|
368
|
-
// src/components/chat/Chat.tsx
|
|
369
|
-
var import_react_core3 = require("@copilotkit/react-core");
|
|
370
|
-
|
|
371
382
|
// src/components/chat/Window.tsx
|
|
372
383
|
var import_react2 = __toESM(require("react"));
|
|
373
384
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
@@ -475,38 +486,10 @@ function isMacOS() {
|
|
|
475
486
|
}
|
|
476
487
|
|
|
477
488
|
// src/components/chat/Button.tsx
|
|
478
|
-
var import_react3 = require("react");
|
|
479
489
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
480
|
-
var Button = ({ open, setOpen
|
|
490
|
+
var Button = ({ open, setOpen }) => {
|
|
481
491
|
const context = useChatContext();
|
|
482
|
-
|
|
483
|
-
const [isLongPress, setIsLongPress] = (0, import_react3.useState)(false);
|
|
484
|
-
const handleMouseDown = () => {
|
|
485
|
-
timerRef.current = setTimeout(() => {
|
|
486
|
-
setPushToTalk(true);
|
|
487
|
-
setIsLongPress(true);
|
|
488
|
-
}, 500);
|
|
489
|
-
};
|
|
490
|
-
const handleMouseUp = () => {
|
|
491
|
-
if (timerRef.current) {
|
|
492
|
-
clearTimeout(timerRef.current);
|
|
493
|
-
setPushToTalk(false);
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
const handleClick = () => {
|
|
497
|
-
if (!isLongPress) {
|
|
498
|
-
setOpen(!open);
|
|
499
|
-
} else {
|
|
500
|
-
setIsLongPress(false);
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
(0, import_react3.useEffect)(() => {
|
|
504
|
-
document.addEventListener("mouseup", handleMouseUp);
|
|
505
|
-
return () => {
|
|
506
|
-
document.removeEventListener("mouseup", handleMouseUp);
|
|
507
|
-
};
|
|
508
|
-
}, []);
|
|
509
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { onClick: handleClick, onMouseDown: handleMouseDown, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
492
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { onClick: () => setOpen(!open), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
510
493
|
"button",
|
|
511
494
|
{
|
|
512
495
|
className: `copilotKitButton ${open ? "open" : ""}`,
|
|
@@ -530,16 +513,16 @@ var Header = ({ setOpen }) => {
|
|
|
530
513
|
};
|
|
531
514
|
|
|
532
515
|
// src/components/chat/Messages.tsx
|
|
533
|
-
var
|
|
516
|
+
var import_react5 = __toESM(require("react"));
|
|
534
517
|
var import_nanoid = require("nanoid");
|
|
535
518
|
var import_shared = require("@copilotkit/shared");
|
|
536
519
|
|
|
537
520
|
// src/components/chat/Markdown.tsx
|
|
538
|
-
var
|
|
521
|
+
var import_react4 = require("react");
|
|
539
522
|
var import_react_markdown = __toESM(require("react-markdown"));
|
|
540
523
|
|
|
541
524
|
// src/components/chat/CodeBlock.tsx
|
|
542
|
-
var
|
|
525
|
+
var import_react3 = require("react");
|
|
543
526
|
var import_react_syntax_highlighter = require("react-syntax-highlighter");
|
|
544
527
|
|
|
545
528
|
// src/hooks/use-copy-to-clipboard.tsx
|
|
@@ -600,7 +583,7 @@ var generateRandomString = (length, lowercase = false) => {
|
|
|
600
583
|
}
|
|
601
584
|
return lowercase ? result.toLowerCase() : result;
|
|
602
585
|
};
|
|
603
|
-
var CodeBlock = (0,
|
|
586
|
+
var CodeBlock = (0, import_react3.memo)(({ language, value }) => {
|
|
604
587
|
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
|
|
605
588
|
const downloadAsFile = () => {
|
|
606
589
|
if (typeof window === "undefined") {
|
|
@@ -946,7 +929,7 @@ var highlightStyle = {
|
|
|
946
929
|
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
947
930
|
var import_remark_math = __toESM(require("remark-math"));
|
|
948
931
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
949
|
-
var MemoizedReactMarkdown = (0,
|
|
932
|
+
var MemoizedReactMarkdown = (0, import_react4.memo)(
|
|
950
933
|
import_react_markdown.default,
|
|
951
934
|
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
|
|
952
935
|
);
|
|
@@ -1008,7 +991,7 @@ var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
|
1008
991
|
var Messages = ({ messages, inProgress, children }) => {
|
|
1009
992
|
const { chatComponentsCache } = (0, import_react_core.useCopilotContext)();
|
|
1010
993
|
const context = useChatContext();
|
|
1011
|
-
const initialMessages = (0,
|
|
994
|
+
const initialMessages = (0, import_react5.useMemo)(
|
|
1012
995
|
() => makeInitialMessages(context.labels.initial),
|
|
1013
996
|
[context.labels.initial]
|
|
1014
997
|
);
|
|
@@ -1022,7 +1005,7 @@ var Messages = ({ messages, inProgress, children }) => {
|
|
|
1022
1005
|
}
|
|
1023
1006
|
}
|
|
1024
1007
|
}
|
|
1025
|
-
const messagesEndRef =
|
|
1008
|
+
const messagesEndRef = import_react5.default.useRef(null);
|
|
1026
1009
|
const scrollToBottom = () => {
|
|
1027
1010
|
if (messagesEndRef.current) {
|
|
1028
1011
|
messagesEndRef.current.scrollIntoView({
|
|
@@ -1030,7 +1013,7 @@ var Messages = ({ messages, inProgress, children }) => {
|
|
|
1030
1013
|
});
|
|
1031
1014
|
}
|
|
1032
1015
|
};
|
|
1033
|
-
(0,
|
|
1016
|
+
(0, import_react5.useEffect)(() => {
|
|
1034
1017
|
scrollToBottom();
|
|
1035
1018
|
}, [messages]);
|
|
1036
1019
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
@@ -1114,14 +1097,14 @@ function makeInitialMessages(initial) {
|
|
|
1114
1097
|
var import_react8 = require("react");
|
|
1115
1098
|
|
|
1116
1099
|
// src/components/chat/Textarea.tsx
|
|
1117
|
-
var
|
|
1100
|
+
var import_react6 = require("react");
|
|
1118
1101
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1119
|
-
var AutoResizingTextarea = (0,
|
|
1102
|
+
var AutoResizingTextarea = (0, import_react6.forwardRef)(
|
|
1120
1103
|
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
1121
|
-
const internalTextareaRef = (0,
|
|
1122
|
-
const [maxHeight, setMaxHeight] = (0,
|
|
1123
|
-
(0,
|
|
1124
|
-
(0,
|
|
1104
|
+
const internalTextareaRef = (0, import_react6.useRef)(null);
|
|
1105
|
+
const [maxHeight, setMaxHeight] = (0, import_react6.useState)(0);
|
|
1106
|
+
(0, import_react6.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
1107
|
+
(0, import_react6.useEffect)(() => {
|
|
1125
1108
|
const calculateMaxHeight = () => {
|
|
1126
1109
|
const textarea = internalTextareaRef.current;
|
|
1127
1110
|
if (textarea) {
|
|
@@ -1135,7 +1118,7 @@ var AutoResizingTextarea = (0, import_react7.forwardRef)(
|
|
|
1135
1118
|
};
|
|
1136
1119
|
calculateMaxHeight();
|
|
1137
1120
|
}, [maxRows]);
|
|
1138
|
-
(0,
|
|
1121
|
+
(0, import_react6.useEffect)(() => {
|
|
1139
1122
|
const textarea = internalTextareaRef.current;
|
|
1140
1123
|
if (textarea) {
|
|
1141
1124
|
textarea.style.height = "auto";
|
|
@@ -1151,7 +1134,7 @@ var AutoResizingTextarea = (0, import_react7.forwardRef)(
|
|
|
1151
1134
|
onKeyDown,
|
|
1152
1135
|
placeholder,
|
|
1153
1136
|
style: {
|
|
1154
|
-
overflow: "
|
|
1137
|
+
overflow: "auto",
|
|
1155
1138
|
resize: "none",
|
|
1156
1139
|
maxHeight: `${maxHeight}px`
|
|
1157
1140
|
},
|
|
@@ -1162,10 +1145,113 @@ var AutoResizingTextarea = (0, import_react7.forwardRef)(
|
|
|
1162
1145
|
);
|
|
1163
1146
|
var Textarea_default = AutoResizingTextarea;
|
|
1164
1147
|
|
|
1148
|
+
// src/hooks/use-push-to-talk.tsx
|
|
1149
|
+
var import_react_core2 = require("@copilotkit/react-core");
|
|
1150
|
+
var import_react7 = require("react");
|
|
1151
|
+
var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
|
|
1152
|
+
if (!mediaStreamRef.current || !audioContextRef.current) {
|
|
1153
|
+
mediaStreamRef.current = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1154
|
+
audioContextRef.current = new window.AudioContext();
|
|
1155
|
+
yield audioContextRef.current.resume();
|
|
1156
|
+
}
|
|
1157
|
+
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
1158
|
+
mediaRecorderRef.current.start(1e3);
|
|
1159
|
+
mediaRecorderRef.current.ondataavailable = (event) => {
|
|
1160
|
+
recordedChunks.push(event.data);
|
|
1161
|
+
};
|
|
1162
|
+
mediaRecorderRef.current.onstop = onStop;
|
|
1163
|
+
});
|
|
1164
|
+
var stopRecording = (mediaRecorderRef) => {
|
|
1165
|
+
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
1166
|
+
mediaRecorderRef.current.stop();
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
var transcribeAudio = (recordedChunks, transcribeAudioUrl) => __async(void 0, null, function* () {
|
|
1170
|
+
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
1171
|
+
const formData = new FormData();
|
|
1172
|
+
formData.append("file", completeBlob, "recording.mp4");
|
|
1173
|
+
const response = yield fetch(transcribeAudioUrl, {
|
|
1174
|
+
method: "POST",
|
|
1175
|
+
body: formData
|
|
1176
|
+
});
|
|
1177
|
+
if (!response.ok) {
|
|
1178
|
+
throw new Error(`Error: ${response.statusText}`);
|
|
1179
|
+
}
|
|
1180
|
+
const transcription = yield response.json();
|
|
1181
|
+
return transcription.text;
|
|
1182
|
+
});
|
|
1183
|
+
var playAudioResponse = (text, textToSpeechUrl, audioContext) => {
|
|
1184
|
+
const encodedText = encodeURIComponent(text);
|
|
1185
|
+
const url = `${textToSpeechUrl}?text=${encodedText}`;
|
|
1186
|
+
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContext.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
1187
|
+
const source = audioContext.createBufferSource();
|
|
1188
|
+
source.buffer = audioBuffer;
|
|
1189
|
+
source.connect(audioContext.destination);
|
|
1190
|
+
source.start(0);
|
|
1191
|
+
}).catch((error) => {
|
|
1192
|
+
console.error("Error with decoding audio data", error);
|
|
1193
|
+
});
|
|
1194
|
+
};
|
|
1195
|
+
var usePushToTalk = ({
|
|
1196
|
+
sendFunction,
|
|
1197
|
+
inProgress
|
|
1198
|
+
}) => {
|
|
1199
|
+
const [pushToTalkState, setPushToTalkState] = (0, import_react7.useState)("idle");
|
|
1200
|
+
const mediaStreamRef = (0, import_react7.useRef)(null);
|
|
1201
|
+
const audioContextRef = (0, import_react7.useRef)(null);
|
|
1202
|
+
const mediaRecorderRef = (0, import_react7.useRef)(null);
|
|
1203
|
+
const recordedChunks = (0, import_react7.useRef)([]);
|
|
1204
|
+
const context = (0, import_react_core2.useCopilotContext)();
|
|
1205
|
+
const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react7.useState)(null);
|
|
1206
|
+
(0, import_react7.useEffect)(() => {
|
|
1207
|
+
if (pushToTalkState === "recording") {
|
|
1208
|
+
startRecording(
|
|
1209
|
+
mediaStreamRef,
|
|
1210
|
+
mediaRecorderRef,
|
|
1211
|
+
audioContextRef,
|
|
1212
|
+
recordedChunks.current,
|
|
1213
|
+
() => {
|
|
1214
|
+
setPushToTalkState("transcribing");
|
|
1215
|
+
}
|
|
1216
|
+
);
|
|
1217
|
+
} else {
|
|
1218
|
+
stopRecording(mediaRecorderRef);
|
|
1219
|
+
if (pushToTalkState === "transcribing") {
|
|
1220
|
+
transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(
|
|
1221
|
+
(transcription) => __async(void 0, null, function* () {
|
|
1222
|
+
recordedChunks.current = [];
|
|
1223
|
+
setPushToTalkState("idle");
|
|
1224
|
+
const message = yield sendFunction(transcription);
|
|
1225
|
+
setStartReadingFromMessageId(message.id);
|
|
1226
|
+
})
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
return () => {
|
|
1231
|
+
stopRecording(mediaRecorderRef);
|
|
1232
|
+
};
|
|
1233
|
+
}, [pushToTalkState]);
|
|
1234
|
+
(0, import_react7.useEffect)(() => {
|
|
1235
|
+
if (inProgress === false && startReadingFromMessageId) {
|
|
1236
|
+
const lastMessageIndex = context.messages.findIndex(
|
|
1237
|
+
(message) => message.id === startReadingFromMessageId
|
|
1238
|
+
);
|
|
1239
|
+
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant" && message.content);
|
|
1240
|
+
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
1241
|
+
playAudioResponse(text, context.copilotApiConfig.textToSpeechUrl, audioContextRef.current);
|
|
1242
|
+
setStartReadingFromMessageId(null);
|
|
1243
|
+
}
|
|
1244
|
+
}, [startReadingFromMessageId, inProgress]);
|
|
1245
|
+
return { pushToTalkState, setPushToTalkState };
|
|
1246
|
+
};
|
|
1247
|
+
|
|
1165
1248
|
// src/components/chat/Input.tsx
|
|
1249
|
+
var import_react_core3 = require("@copilotkit/react-core");
|
|
1166
1250
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1167
1251
|
var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
1168
1252
|
const context = useChatContext();
|
|
1253
|
+
const copilotContext = (0, import_react_core3.useCopilotContext)();
|
|
1254
|
+
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
1169
1255
|
const textareaRef = (0, import_react8.useRef)(null);
|
|
1170
1256
|
const handleDivClick = (event) => {
|
|
1171
1257
|
var _a;
|
|
@@ -1188,10 +1274,14 @@ var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
|
1188
1274
|
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1189
1275
|
}
|
|
1190
1276
|
}, [isVisible]);
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1277
|
+
const { pushToTalkState, setPushToTalkState } = usePushToTalk({
|
|
1278
|
+
sendFunction: onSend,
|
|
1279
|
+
inProgress
|
|
1280
|
+
});
|
|
1281
|
+
const sendIcon = inProgress || pushToTalkState === "transcribing" ? context.icons.activityIcon : context.icons.sendIcon;
|
|
1282
|
+
const showPushToTalk = pushToTalkConfigured && (pushToTalkState === "idle" || pushToTalkState === "recording") && !inProgress;
|
|
1283
|
+
const sendDisabled = inProgress || text.length === 0 || pushToTalkState !== "idle";
|
|
1193
1284
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
|
|
1194
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: "copilotKitSendButton", disabled, onClick: send, children: icon }),
|
|
1195
1285
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1196
1286
|
Textarea_default,
|
|
1197
1287
|
{
|
|
@@ -1208,13 +1298,21 @@ var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
|
1208
1298
|
}
|
|
1209
1299
|
}
|
|
1210
1300
|
}
|
|
1211
|
-
)
|
|
1301
|
+
),
|
|
1302
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitInputControls", children: [
|
|
1303
|
+
showPushToTalk && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1304
|
+
"button",
|
|
1305
|
+
{
|
|
1306
|
+
onClick: () => setPushToTalkState(pushToTalkState === "idle" ? "recording" : "transcribing"),
|
|
1307
|
+
className: pushToTalkState === "recording" ? "copilotKitPushToTalkRecording" : "",
|
|
1308
|
+
children: context.icons.pushToTalkIcon
|
|
1309
|
+
}
|
|
1310
|
+
),
|
|
1311
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { disabled: sendDisabled, onClick: send, children: sendIcon })
|
|
1312
|
+
] })
|
|
1212
1313
|
] });
|
|
1213
1314
|
};
|
|
1214
1315
|
|
|
1215
|
-
// src/components/chat/Chat.tsx
|
|
1216
|
-
var import_nanoid2 = require("nanoid");
|
|
1217
|
-
|
|
1218
1316
|
// src/components/chat/Response.tsx
|
|
1219
1317
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1220
1318
|
var ResponseButton = ({ onClick, inProgress }) => {
|
|
@@ -1226,7 +1324,7 @@ var ResponseButton = ({ onClick, inProgress }) => {
|
|
|
1226
1324
|
};
|
|
1227
1325
|
|
|
1228
1326
|
// src/components/chat/Suggestion.tsx
|
|
1229
|
-
var
|
|
1327
|
+
var import_react_core4 = require("@copilotkit/react-core");
|
|
1230
1328
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1231
1329
|
function Suggestion({ title, message, onClick, partial, className }) {
|
|
1232
1330
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
@@ -1252,7 +1350,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1252
1350
|
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
1253
1351
|
try {
|
|
1254
1352
|
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.`;
|
|
1255
|
-
const result = yield (0,
|
|
1353
|
+
const result = yield (0, import_react_core4.extract)({
|
|
1256
1354
|
context,
|
|
1257
1355
|
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. " + config.instructions + "\n\n" + numOfSuggestionsInstructions,
|
|
1258
1356
|
data: "Available tools: " + tools + "\n\n",
|
|
@@ -1308,50 +1406,64 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1308
1406
|
}
|
|
1309
1407
|
});
|
|
1310
1408
|
|
|
1311
|
-
// src/components/chat/audio.ts
|
|
1312
|
-
var requestMicAndPlaybackPermission = () => __async(void 0, null, function* () {
|
|
1313
|
-
try {
|
|
1314
|
-
const stream = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1315
|
-
const audioContext = new window.AudioContext();
|
|
1316
|
-
yield audioContext.resume();
|
|
1317
|
-
return { stream, audioContext };
|
|
1318
|
-
} catch (err) {
|
|
1319
|
-
console.error("Error requesting microphone and playback permissions", err);
|
|
1320
|
-
return null;
|
|
1321
|
-
}
|
|
1322
|
-
});
|
|
1323
|
-
|
|
1324
1409
|
// src/components/chat/Chat.tsx
|
|
1410
|
+
var import_react9 = __toESM(require("react"));
|
|
1411
|
+
var import_react_core5 = require("@copilotkit/react-core");
|
|
1412
|
+
var import_nanoid2 = require("nanoid");
|
|
1325
1413
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1326
|
-
|
|
1327
|
-
var CopilotChat = ({
|
|
1414
|
+
function CopilotChat({
|
|
1328
1415
|
instructions,
|
|
1329
|
-
defaultOpen = false,
|
|
1330
|
-
clickOutsideToClose = true,
|
|
1331
|
-
hitEscapeToClose = true,
|
|
1332
|
-
onSetOpen,
|
|
1333
1416
|
onSubmitMessage,
|
|
1334
|
-
shortcut = "/",
|
|
1335
1417
|
icons,
|
|
1336
1418
|
labels,
|
|
1337
1419
|
makeSystemMessage,
|
|
1338
1420
|
showResponseButton = true,
|
|
1339
1421
|
onInProgress,
|
|
1340
|
-
Window: Window2 = Window,
|
|
1341
|
-
Button: Button2 = Button,
|
|
1342
|
-
Header: Header2 = Header,
|
|
1343
1422
|
Messages: Messages2 = Messages,
|
|
1344
1423
|
Input: Input2 = Input,
|
|
1345
1424
|
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1346
|
-
className
|
|
1347
|
-
|
|
1348
|
-
}
|
|
1349
|
-
const
|
|
1425
|
+
className
|
|
1426
|
+
}) {
|
|
1427
|
+
const { visibleMessages, isLoading, currentSuggestions, sendMessage, stop, reload } = useCopilotChatLogic(instructions, makeSystemMessage, onInProgress, onSubmitMessage);
|
|
1428
|
+
const context = import_react9.default.useContext(ChatContext);
|
|
1429
|
+
let open = true;
|
|
1430
|
+
let setOpen = () => {
|
|
1431
|
+
};
|
|
1432
|
+
if (context) {
|
|
1433
|
+
icons = context.icons;
|
|
1434
|
+
labels = context.labels;
|
|
1435
|
+
open = context.open;
|
|
1436
|
+
setOpen = context.setOpen;
|
|
1437
|
+
}
|
|
1438
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ChatContextProvider, { icons, labels, open, setOpen, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `copilotKitPanel ${className}`, children: [
|
|
1439
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Messages2, { messages: visibleMessages, inProgress: isLoading, children: [
|
|
1440
|
+
currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { children: [
|
|
1441
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("h6", { children: "Suggested:" }),
|
|
1442
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "suggestions", children: currentSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1443
|
+
Suggestion,
|
|
1444
|
+
{
|
|
1445
|
+
title: suggestion.title,
|
|
1446
|
+
message: suggestion.message,
|
|
1447
|
+
partial: suggestion.partial,
|
|
1448
|
+
className: suggestion.className,
|
|
1449
|
+
onClick: (message) => sendMessage(message)
|
|
1450
|
+
},
|
|
1451
|
+
index
|
|
1452
|
+
)) })
|
|
1453
|
+
] }),
|
|
1454
|
+
showResponseButton && visibleMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ResponseButton2, { onClick: isLoading ? stop : reload, inProgress: isLoading })
|
|
1455
|
+
] }),
|
|
1456
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Input2, { inProgress: isLoading, onSend: sendMessage, isVisible: true })
|
|
1457
|
+
] }) });
|
|
1458
|
+
}
|
|
1459
|
+
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
1460
|
+
var useCopilotChatLogic = (instructions, makeSystemMessage, onInProgress, onSubmitMessage) => {
|
|
1461
|
+
const { visibleMessages, append, reload, stop, isLoading, input, setInput } = (0, import_react_core5.useCopilotChat)({
|
|
1350
1462
|
id: (0, import_nanoid2.nanoid)(),
|
|
1351
1463
|
makeSystemMessage,
|
|
1352
1464
|
additionalInstructions: instructions
|
|
1353
1465
|
});
|
|
1354
|
-
const [currentSuggestions, setCurrentSuggestions] = import_react9.
|
|
1466
|
+
const [currentSuggestions, setCurrentSuggestions] = (0, import_react9.useState)([]);
|
|
1355
1467
|
const suggestionsAbortControllerRef = (0, import_react9.useRef)(null);
|
|
1356
1468
|
const debounceTimerRef = (0, import_react9.useRef)();
|
|
1357
1469
|
const abortSuggestions = () => {
|
|
@@ -1359,27 +1471,17 @@ var CopilotChat = ({
|
|
|
1359
1471
|
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
1360
1472
|
suggestionsAbortControllerRef.current = null;
|
|
1361
1473
|
};
|
|
1362
|
-
const context = (0,
|
|
1363
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react9.useState)({});
|
|
1364
|
-
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
1365
|
-
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
1366
|
-
};
|
|
1367
|
-
const removeChatSuggestion = (id) => {
|
|
1368
|
-
setChatSuggestionConfiguration((prev) => {
|
|
1369
|
-
const _a = prev, { [id]: _ } = _a, rest = __objRest(_a, [__restKey(id)]);
|
|
1370
|
-
return rest;
|
|
1371
|
-
});
|
|
1372
|
-
};
|
|
1474
|
+
const context = (0, import_react_core5.useCopilotContext)();
|
|
1373
1475
|
(0, import_react9.useEffect)(() => {
|
|
1374
1476
|
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
1375
1477
|
abortSuggestions();
|
|
1376
1478
|
debounceTimerRef.current = setTimeout(
|
|
1377
1479
|
() => {
|
|
1378
|
-
if (!isLoading && Object.keys(chatSuggestionConfiguration).length !== 0) {
|
|
1480
|
+
if (!isLoading && Object.keys(context.chatSuggestionConfiguration).length !== 0) {
|
|
1379
1481
|
suggestionsAbortControllerRef.current = new AbortController();
|
|
1380
1482
|
reloadSuggestions(
|
|
1381
1483
|
context,
|
|
1382
|
-
chatSuggestionConfiguration,
|
|
1484
|
+
context.chatSuggestionConfiguration,
|
|
1383
1485
|
setCurrentSuggestions,
|
|
1384
1486
|
suggestionsAbortControllerRef
|
|
1385
1487
|
);
|
|
@@ -1390,11 +1492,7 @@ var CopilotChat = ({
|
|
|
1390
1492
|
return () => {
|
|
1391
1493
|
clearTimeout(debounceTimerRef.current);
|
|
1392
1494
|
};
|
|
1393
|
-
}, [isLoading, chatSuggestionConfiguration]);
|
|
1394
|
-
const setOpen = (open) => {
|
|
1395
|
-
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
1396
|
-
setOpenState(open);
|
|
1397
|
-
};
|
|
1495
|
+
}, [isLoading, context.chatSuggestionConfiguration]);
|
|
1398
1496
|
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
1399
1497
|
abortSuggestions();
|
|
1400
1498
|
setCurrentSuggestions([]);
|
|
@@ -1407,147 +1505,88 @@ var CopilotChat = ({
|
|
|
1407
1505
|
append(message);
|
|
1408
1506
|
return message;
|
|
1409
1507
|
});
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
setPushToTalkState(false);
|
|
1421
|
-
requestMicAndPlaybackPermission().then((res) => {
|
|
1422
|
-
if (res) {
|
|
1423
|
-
mediaStreamRef.current = res.stream;
|
|
1424
|
-
audioContextRef.current = res.audioContext;
|
|
1425
|
-
}
|
|
1426
|
-
});
|
|
1427
|
-
} else {
|
|
1428
|
-
console.log("Recording started");
|
|
1429
|
-
const recordedChunks = [];
|
|
1430
|
-
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
1431
|
-
mediaRecorderRef.current.start(1e3);
|
|
1432
|
-
mediaRecorderRef.current.ondataavailable = (event) => __async(void 0, null, function* () {
|
|
1433
|
-
console.log("Recorded audio: ", event.data);
|
|
1434
|
-
recordedChunks.push(event.data);
|
|
1435
|
-
});
|
|
1436
|
-
mediaRecorderRef.current.onstop = () => __async(void 0, null, function* () {
|
|
1437
|
-
console.log("Recording stopped");
|
|
1438
|
-
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
1439
|
-
const formData = new FormData();
|
|
1440
|
-
formData.append("file", completeBlob, "recording.mp4");
|
|
1441
|
-
const response = yield fetch(context.copilotApiConfig.transcribeAudioUrl, {
|
|
1442
|
-
method: "POST",
|
|
1443
|
-
body: formData
|
|
1444
|
-
});
|
|
1445
|
-
if (!response.ok) {
|
|
1446
|
-
throw new Error(`Error: ${response.statusText}`);
|
|
1447
|
-
}
|
|
1448
|
-
const transcription = yield response.json();
|
|
1449
|
-
const message = yield sendMessage(transcription.text);
|
|
1450
|
-
setLastMessageIdBeforeAudio(message.id);
|
|
1451
|
-
});
|
|
1452
|
-
}
|
|
1453
|
-
} else {
|
|
1454
|
-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
1455
|
-
mediaRecorderRef.current.stop();
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
return () => {
|
|
1459
|
-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
1460
|
-
mediaRecorderRef.current.stop();
|
|
1461
|
-
}
|
|
1462
|
-
};
|
|
1463
|
-
}, [pushToTalkState]);
|
|
1464
|
-
(0, import_react9.useEffect)(() => {
|
|
1465
|
-
if (lastMessageIdBeforeAudio && !isLoading) {
|
|
1466
|
-
if (audioContextRef.current) {
|
|
1467
|
-
const lastMessageIndex = context.messages.findIndex(
|
|
1468
|
-
(message) => message.id === lastMessageIdBeforeAudio
|
|
1469
|
-
);
|
|
1470
|
-
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant" && message.content);
|
|
1471
|
-
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
1472
|
-
const encodedText = encodeURIComponent(text);
|
|
1473
|
-
const url = `${context.copilotApiConfig.textToSpeechUrl}?text=${encodedText}`;
|
|
1474
|
-
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContextRef.current.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
1475
|
-
const source = audioContextRef.current.createBufferSource();
|
|
1476
|
-
source.buffer = audioBuffer;
|
|
1477
|
-
source.connect(audioContextRef.current.destination);
|
|
1478
|
-
source.start(0);
|
|
1479
|
-
}).catch((error) => {
|
|
1480
|
-
console.error("Error with decoding audio data", error);
|
|
1481
|
-
});
|
|
1482
|
-
setLastMessageIdBeforeAudio(null);
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
}, [isLoading]);
|
|
1486
|
-
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
1487
|
-
ChatContextProvider,
|
|
1488
|
-
{
|
|
1489
|
-
icons,
|
|
1490
|
-
labels,
|
|
1491
|
-
open: openState,
|
|
1492
|
-
setOpen: setOpenState,
|
|
1493
|
-
addChatSuggestionConfiguration,
|
|
1494
|
-
removeChatSuggestionConfiguration: removeChatSuggestion,
|
|
1495
|
-
children: [
|
|
1496
|
-
children,
|
|
1497
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className, children: [
|
|
1498
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1499
|
-
Button2,
|
|
1500
|
-
{
|
|
1501
|
-
open: openState,
|
|
1502
|
-
setOpen,
|
|
1503
|
-
pushToTalk: pushToTalkState,
|
|
1504
|
-
setPushToTalk: setPushToTalkState
|
|
1505
|
-
}
|
|
1506
|
-
),
|
|
1507
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
1508
|
-
Window2,
|
|
1509
|
-
{
|
|
1510
|
-
open: openState,
|
|
1511
|
-
setOpen,
|
|
1512
|
-
clickOutsideToClose,
|
|
1513
|
-
shortcut,
|
|
1514
|
-
hitEscapeToClose,
|
|
1515
|
-
children: [
|
|
1516
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Header2, { open: openState, setOpen }),
|
|
1517
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Messages2, { messages: visibleMessages, inProgress: isLoading, children: [
|
|
1518
|
-
currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { children: [
|
|
1519
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("h6", { children: "Suggested:" }),
|
|
1520
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "suggestions", children: currentSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1521
|
-
Suggestion,
|
|
1522
|
-
{
|
|
1523
|
-
title: suggestion.title,
|
|
1524
|
-
message: suggestion.message,
|
|
1525
|
-
partial: suggestion.partial,
|
|
1526
|
-
className: suggestion.className,
|
|
1527
|
-
onClick: (message) => sendMessage(message)
|
|
1528
|
-
},
|
|
1529
|
-
index
|
|
1530
|
-
)) })
|
|
1531
|
-
] }),
|
|
1532
|
-
showResponseButton && visibleMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ResponseButton2, { onClick: isLoading ? stop : reload, inProgress: isLoading })
|
|
1533
|
-
] }),
|
|
1534
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Input2, { inProgress: isLoading, onSend: sendMessage, isVisible: openState })
|
|
1535
|
-
]
|
|
1536
|
-
}
|
|
1537
|
-
)
|
|
1538
|
-
] })
|
|
1539
|
-
]
|
|
1540
|
-
}
|
|
1541
|
-
);
|
|
1508
|
+
return {
|
|
1509
|
+
visibleMessages,
|
|
1510
|
+
isLoading,
|
|
1511
|
+
currentSuggestions,
|
|
1512
|
+
sendMessage,
|
|
1513
|
+
stop,
|
|
1514
|
+
reload,
|
|
1515
|
+
input,
|
|
1516
|
+
setInput
|
|
1517
|
+
};
|
|
1542
1518
|
};
|
|
1543
1519
|
|
|
1544
|
-
// src/components/chat/
|
|
1520
|
+
// src/components/chat/Modal.tsx
|
|
1545
1521
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1522
|
+
var CopilotModal = ({
|
|
1523
|
+
instructions,
|
|
1524
|
+
defaultOpen = false,
|
|
1525
|
+
clickOutsideToClose = true,
|
|
1526
|
+
hitEscapeToClose = true,
|
|
1527
|
+
onSetOpen,
|
|
1528
|
+
onSubmitMessage,
|
|
1529
|
+
shortcut = "/",
|
|
1530
|
+
icons,
|
|
1531
|
+
labels,
|
|
1532
|
+
makeSystemMessage,
|
|
1533
|
+
showResponseButton = true,
|
|
1534
|
+
onInProgress,
|
|
1535
|
+
Window: Window2 = Window,
|
|
1536
|
+
Button: Button2 = Button,
|
|
1537
|
+
Header: Header2 = Header,
|
|
1538
|
+
Messages: Messages2 = Messages,
|
|
1539
|
+
Input: Input2 = Input,
|
|
1540
|
+
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1541
|
+
className,
|
|
1542
|
+
children
|
|
1543
|
+
}) => {
|
|
1544
|
+
const [openState, setOpenState] = import_react10.default.useState(defaultOpen);
|
|
1545
|
+
const setOpen = (open) => {
|
|
1546
|
+
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
1547
|
+
setOpenState(open);
|
|
1548
|
+
};
|
|
1549
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: [
|
|
1550
|
+
children,
|
|
1551
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className, children: [
|
|
1552
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Button2, { open: openState, setOpen }),
|
|
1553
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
1554
|
+
Window2,
|
|
1555
|
+
{
|
|
1556
|
+
open: openState,
|
|
1557
|
+
setOpen,
|
|
1558
|
+
clickOutsideToClose,
|
|
1559
|
+
shortcut,
|
|
1560
|
+
hitEscapeToClose,
|
|
1561
|
+
children: [
|
|
1562
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Header2, { open: openState, setOpen }),
|
|
1563
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1564
|
+
CopilotChat,
|
|
1565
|
+
{
|
|
1566
|
+
instructions,
|
|
1567
|
+
makeSystemMessage,
|
|
1568
|
+
onInProgress,
|
|
1569
|
+
onSubmitMessage,
|
|
1570
|
+
showResponseButton,
|
|
1571
|
+
Messages: Messages2,
|
|
1572
|
+
Input: Input2,
|
|
1573
|
+
ResponseButton: ResponseButton2
|
|
1574
|
+
}
|
|
1575
|
+
)
|
|
1576
|
+
]
|
|
1577
|
+
}
|
|
1578
|
+
)
|
|
1579
|
+
] })
|
|
1580
|
+
] });
|
|
1581
|
+
};
|
|
1582
|
+
|
|
1583
|
+
// src/components/chat/Popup.tsx
|
|
1584
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1546
1585
|
function CopilotPopup(props) {
|
|
1547
1586
|
props = __spreadProps(__spreadValues({}, props), {
|
|
1548
1587
|
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup"
|
|
1549
1588
|
});
|
|
1550
|
-
return /* @__PURE__ */ (0,
|
|
1589
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CopilotModal, __spreadProps(__spreadValues({}, props), { children: props.children }));
|
|
1551
1590
|
}
|
|
1552
1591
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1553
1592
|
0 && (module.exports = {
|