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