@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
package/dist/index.js
CHANGED
|
@@ -23,7 +23,6 @@ var __spreadValues = (a, b) => {
|
|
|
23
23
|
return a;
|
|
24
24
|
};
|
|
25
25
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
-
var __restKey = (key) => typeof key === "symbol" ? key : key + "";
|
|
27
26
|
var __objRest = (source, exclude) => {
|
|
28
27
|
var target = {};
|
|
29
28
|
for (var prop in source)
|
|
@@ -81,6 +80,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
81
80
|
// src/index.tsx
|
|
82
81
|
var src_exports = {};
|
|
83
82
|
__export(src_exports, {
|
|
83
|
+
CopilotChat: () => CopilotChat,
|
|
84
84
|
CopilotPopup: () => CopilotPopup,
|
|
85
85
|
CopilotSidebar: () => CopilotSidebar,
|
|
86
86
|
useChatContext: () => useChatContext,
|
|
@@ -88,8 +88,8 @@ __export(src_exports, {
|
|
|
88
88
|
});
|
|
89
89
|
module.exports = __toCommonJS(src_exports);
|
|
90
90
|
|
|
91
|
-
// src/components/chat/
|
|
92
|
-
var
|
|
91
|
+
// src/components/chat/Modal.tsx
|
|
92
|
+
var import_react10 = __toESM(require("react"));
|
|
93
93
|
|
|
94
94
|
// src/components/chat/ChatContext.tsx
|
|
95
95
|
var import_react = __toESM(require("react"));
|
|
@@ -314,6 +314,25 @@ var RegenerateIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
|
314
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" })
|
|
315
315
|
}
|
|
316
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
|
+
);
|
|
317
336
|
|
|
318
337
|
// src/components/chat/ChatContext.tsx
|
|
319
338
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -335,16 +354,13 @@ var ChatContextProvider = ({
|
|
|
335
354
|
icons,
|
|
336
355
|
children,
|
|
337
356
|
open,
|
|
338
|
-
setOpen
|
|
339
|
-
addChatSuggestionConfiguration,
|
|
340
|
-
removeChatSuggestionConfiguration
|
|
357
|
+
setOpen
|
|
341
358
|
}) => {
|
|
342
359
|
const context = {
|
|
343
360
|
labels: __spreadValues(__spreadValues({}, {
|
|
344
361
|
initial: "",
|
|
345
362
|
title: "CopilotKit",
|
|
346
363
|
placeholder: "Type a message...",
|
|
347
|
-
thinking: "Thinking...",
|
|
348
364
|
error: "\u274C An error occurred. Please try again.",
|
|
349
365
|
stopGenerating: "Stop generating",
|
|
350
366
|
regenerateResponse: "Regenerate response"
|
|
@@ -357,21 +373,17 @@ var ChatContextProvider = ({
|
|
|
357
373
|
activityIcon: ActivityIcon,
|
|
358
374
|
spinnerIcon: SpinnerIcon,
|
|
359
375
|
stopIcon: StopIcon,
|
|
360
|
-
regenerateIcon: RegenerateIcon
|
|
376
|
+
regenerateIcon: RegenerateIcon,
|
|
377
|
+
pushToTalkIcon: PushToTalkIcon
|
|
361
378
|
}), {
|
|
362
379
|
icons
|
|
363
380
|
}),
|
|
364
381
|
open,
|
|
365
|
-
setOpen
|
|
366
|
-
addChatSuggestionConfiguration,
|
|
367
|
-
removeChatSuggestionConfiguration
|
|
382
|
+
setOpen
|
|
368
383
|
};
|
|
369
384
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChatContext.Provider, { value: context, children });
|
|
370
385
|
};
|
|
371
386
|
|
|
372
|
-
// src/components/chat/Chat.tsx
|
|
373
|
-
var import_react_core3 = require("@copilotkit/react-core");
|
|
374
|
-
|
|
375
387
|
// src/components/chat/Window.tsx
|
|
376
388
|
var import_react2 = __toESM(require("react"));
|
|
377
389
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
@@ -479,38 +491,10 @@ function isMacOS() {
|
|
|
479
491
|
}
|
|
480
492
|
|
|
481
493
|
// src/components/chat/Button.tsx
|
|
482
|
-
var import_react3 = require("react");
|
|
483
494
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
484
|
-
var Button = ({ open, setOpen
|
|
495
|
+
var Button = ({ open, setOpen }) => {
|
|
485
496
|
const context = useChatContext();
|
|
486
|
-
|
|
487
|
-
const [isLongPress, setIsLongPress] = (0, import_react3.useState)(false);
|
|
488
|
-
const handleMouseDown = () => {
|
|
489
|
-
timerRef.current = setTimeout(() => {
|
|
490
|
-
setPushToTalk(true);
|
|
491
|
-
setIsLongPress(true);
|
|
492
|
-
}, 500);
|
|
493
|
-
};
|
|
494
|
-
const handleMouseUp = () => {
|
|
495
|
-
if (timerRef.current) {
|
|
496
|
-
clearTimeout(timerRef.current);
|
|
497
|
-
setPushToTalk(false);
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
const handleClick = () => {
|
|
501
|
-
if (!isLongPress) {
|
|
502
|
-
setOpen(!open);
|
|
503
|
-
} else {
|
|
504
|
-
setIsLongPress(false);
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
(0, import_react3.useEffect)(() => {
|
|
508
|
-
document.addEventListener("mouseup", handleMouseUp);
|
|
509
|
-
return () => {
|
|
510
|
-
document.removeEventListener("mouseup", handleMouseUp);
|
|
511
|
-
};
|
|
512
|
-
}, []);
|
|
513
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { onClick: handleClick, onMouseDown: handleMouseDown, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
497
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { onClick: () => setOpen(!open), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
514
498
|
"button",
|
|
515
499
|
{
|
|
516
500
|
className: `copilotKitButton ${open ? "open" : ""}`,
|
|
@@ -534,16 +518,16 @@ var Header = ({ setOpen }) => {
|
|
|
534
518
|
};
|
|
535
519
|
|
|
536
520
|
// src/components/chat/Messages.tsx
|
|
537
|
-
var
|
|
521
|
+
var import_react5 = __toESM(require("react"));
|
|
538
522
|
var import_nanoid = require("nanoid");
|
|
539
523
|
var import_shared = require("@copilotkit/shared");
|
|
540
524
|
|
|
541
525
|
// src/components/chat/Markdown.tsx
|
|
542
|
-
var
|
|
526
|
+
var import_react4 = require("react");
|
|
543
527
|
var import_react_markdown = __toESM(require("react-markdown"));
|
|
544
528
|
|
|
545
529
|
// src/components/chat/CodeBlock.tsx
|
|
546
|
-
var
|
|
530
|
+
var import_react3 = require("react");
|
|
547
531
|
var import_react_syntax_highlighter = require("react-syntax-highlighter");
|
|
548
532
|
|
|
549
533
|
// src/hooks/use-copy-to-clipboard.tsx
|
|
@@ -604,7 +588,7 @@ var generateRandomString = (length, lowercase = false) => {
|
|
|
604
588
|
}
|
|
605
589
|
return lowercase ? result.toLowerCase() : result;
|
|
606
590
|
};
|
|
607
|
-
var CodeBlock = (0,
|
|
591
|
+
var CodeBlock = (0, import_react3.memo)(({ language, value }) => {
|
|
608
592
|
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
|
|
609
593
|
const downloadAsFile = () => {
|
|
610
594
|
if (typeof window === "undefined") {
|
|
@@ -950,7 +934,7 @@ var highlightStyle = {
|
|
|
950
934
|
var import_remark_gfm = __toESM(require("remark-gfm"));
|
|
951
935
|
var import_remark_math = __toESM(require("remark-math"));
|
|
952
936
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
953
|
-
var MemoizedReactMarkdown = (0,
|
|
937
|
+
var MemoizedReactMarkdown = (0, import_react4.memo)(
|
|
954
938
|
import_react_markdown.default,
|
|
955
939
|
(prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.className === nextProps.className
|
|
956
940
|
);
|
|
@@ -1012,7 +996,7 @@ var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
|
1012
996
|
var Messages = ({ messages, inProgress, children }) => {
|
|
1013
997
|
const { chatComponentsCache } = (0, import_react_core.useCopilotContext)();
|
|
1014
998
|
const context = useChatContext();
|
|
1015
|
-
const initialMessages = (0,
|
|
999
|
+
const initialMessages = (0, import_react5.useMemo)(
|
|
1016
1000
|
() => makeInitialMessages(context.labels.initial),
|
|
1017
1001
|
[context.labels.initial]
|
|
1018
1002
|
);
|
|
@@ -1026,7 +1010,7 @@ var Messages = ({ messages, inProgress, children }) => {
|
|
|
1026
1010
|
}
|
|
1027
1011
|
}
|
|
1028
1012
|
}
|
|
1029
|
-
const messagesEndRef =
|
|
1013
|
+
const messagesEndRef = import_react5.default.useRef(null);
|
|
1030
1014
|
const scrollToBottom = () => {
|
|
1031
1015
|
if (messagesEndRef.current) {
|
|
1032
1016
|
messagesEndRef.current.scrollIntoView({
|
|
@@ -1034,7 +1018,7 @@ var Messages = ({ messages, inProgress, children }) => {
|
|
|
1034
1018
|
});
|
|
1035
1019
|
}
|
|
1036
1020
|
};
|
|
1037
|
-
(0,
|
|
1021
|
+
(0, import_react5.useEffect)(() => {
|
|
1038
1022
|
scrollToBottom();
|
|
1039
1023
|
}, [messages]);
|
|
1040
1024
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "copilotKitMessages", children: [
|
|
@@ -1118,14 +1102,14 @@ function makeInitialMessages(initial) {
|
|
|
1118
1102
|
var import_react8 = require("react");
|
|
1119
1103
|
|
|
1120
1104
|
// src/components/chat/Textarea.tsx
|
|
1121
|
-
var
|
|
1105
|
+
var import_react6 = require("react");
|
|
1122
1106
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1123
|
-
var AutoResizingTextarea = (0,
|
|
1107
|
+
var AutoResizingTextarea = (0, import_react6.forwardRef)(
|
|
1124
1108
|
({ maxRows = 1, placeholder, value, onChange, onKeyDown, autoFocus }, ref) => {
|
|
1125
|
-
const internalTextareaRef = (0,
|
|
1126
|
-
const [maxHeight, setMaxHeight] = (0,
|
|
1127
|
-
(0,
|
|
1128
|
-
(0,
|
|
1109
|
+
const internalTextareaRef = (0, import_react6.useRef)(null);
|
|
1110
|
+
const [maxHeight, setMaxHeight] = (0, import_react6.useState)(0);
|
|
1111
|
+
(0, import_react6.useImperativeHandle)(ref, () => internalTextareaRef.current);
|
|
1112
|
+
(0, import_react6.useEffect)(() => {
|
|
1129
1113
|
const calculateMaxHeight = () => {
|
|
1130
1114
|
const textarea = internalTextareaRef.current;
|
|
1131
1115
|
if (textarea) {
|
|
@@ -1139,7 +1123,7 @@ var AutoResizingTextarea = (0, import_react7.forwardRef)(
|
|
|
1139
1123
|
};
|
|
1140
1124
|
calculateMaxHeight();
|
|
1141
1125
|
}, [maxRows]);
|
|
1142
|
-
(0,
|
|
1126
|
+
(0, import_react6.useEffect)(() => {
|
|
1143
1127
|
const textarea = internalTextareaRef.current;
|
|
1144
1128
|
if (textarea) {
|
|
1145
1129
|
textarea.style.height = "auto";
|
|
@@ -1155,7 +1139,7 @@ var AutoResizingTextarea = (0, import_react7.forwardRef)(
|
|
|
1155
1139
|
onKeyDown,
|
|
1156
1140
|
placeholder,
|
|
1157
1141
|
style: {
|
|
1158
|
-
overflow: "
|
|
1142
|
+
overflow: "auto",
|
|
1159
1143
|
resize: "none",
|
|
1160
1144
|
maxHeight: `${maxHeight}px`
|
|
1161
1145
|
},
|
|
@@ -1166,10 +1150,113 @@ var AutoResizingTextarea = (0, import_react7.forwardRef)(
|
|
|
1166
1150
|
);
|
|
1167
1151
|
var Textarea_default = AutoResizingTextarea;
|
|
1168
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
|
+
|
|
1169
1253
|
// src/components/chat/Input.tsx
|
|
1254
|
+
var import_react_core3 = require("@copilotkit/react-core");
|
|
1170
1255
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1171
1256
|
var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
1172
1257
|
const context = useChatContext();
|
|
1258
|
+
const copilotContext = (0, import_react_core3.useCopilotContext)();
|
|
1259
|
+
const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
|
|
1173
1260
|
const textareaRef = (0, import_react8.useRef)(null);
|
|
1174
1261
|
const handleDivClick = (event) => {
|
|
1175
1262
|
var _a;
|
|
@@ -1192,10 +1279,14 @@ var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
|
1192
1279
|
(_a = textareaRef.current) == null ? void 0 : _a.focus();
|
|
1193
1280
|
}
|
|
1194
1281
|
}, [isVisible]);
|
|
1195
|
-
const
|
|
1196
|
-
|
|
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";
|
|
1197
1289
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "copilotKitInput", onClick: handleDivClick, children: [
|
|
1198
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: "copilotKitSendButton", disabled, onClick: send, children: icon }),
|
|
1199
1290
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1200
1291
|
Textarea_default,
|
|
1201
1292
|
{
|
|
@@ -1212,13 +1303,21 @@ var Input = ({ inProgress, onSend, isVisible = false }) => {
|
|
|
1212
1303
|
}
|
|
1213
1304
|
}
|
|
1214
1305
|
}
|
|
1215
|
-
)
|
|
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
|
+
] })
|
|
1216
1318
|
] });
|
|
1217
1319
|
};
|
|
1218
1320
|
|
|
1219
|
-
// src/components/chat/Chat.tsx
|
|
1220
|
-
var import_nanoid2 = require("nanoid");
|
|
1221
|
-
|
|
1222
1321
|
// src/components/chat/Response.tsx
|
|
1223
1322
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1224
1323
|
var ResponseButton = ({ onClick, inProgress }) => {
|
|
@@ -1230,7 +1329,7 @@ var ResponseButton = ({ onClick, inProgress }) => {
|
|
|
1230
1329
|
};
|
|
1231
1330
|
|
|
1232
1331
|
// src/components/chat/Suggestion.tsx
|
|
1233
|
-
var
|
|
1332
|
+
var import_react_core4 = require("@copilotkit/react-core");
|
|
1234
1333
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1235
1334
|
function Suggestion({ title, message, onClick, partial, className }) {
|
|
1236
1335
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
@@ -1256,7 +1355,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1256
1355
|
for (const config of Object.values(chatSuggestionConfiguration)) {
|
|
1257
1356
|
try {
|
|
1258
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.`;
|
|
1259
|
-
const result = yield (0,
|
|
1358
|
+
const result = yield (0, import_react_core4.extract)({
|
|
1260
1359
|
context,
|
|
1261
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,
|
|
1262
1361
|
data: "Available tools: " + tools + "\n\n",
|
|
@@ -1312,50 +1411,64 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1312
1411
|
}
|
|
1313
1412
|
});
|
|
1314
1413
|
|
|
1315
|
-
// src/components/chat/audio.ts
|
|
1316
|
-
var requestMicAndPlaybackPermission = () => __async(void 0, null, function* () {
|
|
1317
|
-
try {
|
|
1318
|
-
const stream = yield navigator.mediaDevices.getUserMedia({ audio: true });
|
|
1319
|
-
const audioContext = new window.AudioContext();
|
|
1320
|
-
yield audioContext.resume();
|
|
1321
|
-
return { stream, audioContext };
|
|
1322
|
-
} catch (err) {
|
|
1323
|
-
console.error("Error requesting microphone and playback permissions", err);
|
|
1324
|
-
return null;
|
|
1325
|
-
}
|
|
1326
|
-
});
|
|
1327
|
-
|
|
1328
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");
|
|
1329
1418
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1330
|
-
|
|
1331
|
-
var CopilotChat = ({
|
|
1419
|
+
function CopilotChat({
|
|
1332
1420
|
instructions,
|
|
1333
|
-
defaultOpen = false,
|
|
1334
|
-
clickOutsideToClose = true,
|
|
1335
|
-
hitEscapeToClose = true,
|
|
1336
|
-
onSetOpen,
|
|
1337
1421
|
onSubmitMessage,
|
|
1338
|
-
shortcut = "/",
|
|
1339
1422
|
icons,
|
|
1340
1423
|
labels,
|
|
1341
1424
|
makeSystemMessage,
|
|
1342
1425
|
showResponseButton = true,
|
|
1343
1426
|
onInProgress,
|
|
1344
|
-
Window: Window2 = Window,
|
|
1345
|
-
Button: Button2 = Button,
|
|
1346
|
-
Header: Header2 = Header,
|
|
1347
1427
|
Messages: Messages2 = Messages,
|
|
1348
1428
|
Input: Input2 = Input,
|
|
1349
1429
|
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1350
|
-
className
|
|
1351
|
-
|
|
1352
|
-
}
|
|
1353
|
-
const
|
|
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)({
|
|
1354
1467
|
id: (0, import_nanoid2.nanoid)(),
|
|
1355
1468
|
makeSystemMessage,
|
|
1356
1469
|
additionalInstructions: instructions
|
|
1357
1470
|
});
|
|
1358
|
-
const [currentSuggestions, setCurrentSuggestions] = import_react9.
|
|
1471
|
+
const [currentSuggestions, setCurrentSuggestions] = (0, import_react9.useState)([]);
|
|
1359
1472
|
const suggestionsAbortControllerRef = (0, import_react9.useRef)(null);
|
|
1360
1473
|
const debounceTimerRef = (0, import_react9.useRef)();
|
|
1361
1474
|
const abortSuggestions = () => {
|
|
@@ -1363,27 +1476,17 @@ var CopilotChat = ({
|
|
|
1363
1476
|
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
1364
1477
|
suggestionsAbortControllerRef.current = null;
|
|
1365
1478
|
};
|
|
1366
|
-
const context = (0,
|
|
1367
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react9.useState)({});
|
|
1368
|
-
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
1369
|
-
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
1370
|
-
};
|
|
1371
|
-
const removeChatSuggestion = (id) => {
|
|
1372
|
-
setChatSuggestionConfiguration((prev) => {
|
|
1373
|
-
const _a = prev, { [id]: _ } = _a, rest = __objRest(_a, [__restKey(id)]);
|
|
1374
|
-
return rest;
|
|
1375
|
-
});
|
|
1376
|
-
};
|
|
1479
|
+
const context = (0, import_react_core5.useCopilotContext)();
|
|
1377
1480
|
(0, import_react9.useEffect)(() => {
|
|
1378
1481
|
onInProgress == null ? void 0 : onInProgress(isLoading);
|
|
1379
1482
|
abortSuggestions();
|
|
1380
1483
|
debounceTimerRef.current = setTimeout(
|
|
1381
1484
|
() => {
|
|
1382
|
-
if (!isLoading && Object.keys(chatSuggestionConfiguration).length !== 0) {
|
|
1485
|
+
if (!isLoading && Object.keys(context.chatSuggestionConfiguration).length !== 0) {
|
|
1383
1486
|
suggestionsAbortControllerRef.current = new AbortController();
|
|
1384
1487
|
reloadSuggestions(
|
|
1385
1488
|
context,
|
|
1386
|
-
chatSuggestionConfiguration,
|
|
1489
|
+
context.chatSuggestionConfiguration,
|
|
1387
1490
|
setCurrentSuggestions,
|
|
1388
1491
|
suggestionsAbortControllerRef
|
|
1389
1492
|
);
|
|
@@ -1394,11 +1497,7 @@ var CopilotChat = ({
|
|
|
1394
1497
|
return () => {
|
|
1395
1498
|
clearTimeout(debounceTimerRef.current);
|
|
1396
1499
|
};
|
|
1397
|
-
}, [isLoading, chatSuggestionConfiguration]);
|
|
1398
|
-
const setOpen = (open) => {
|
|
1399
|
-
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
1400
|
-
setOpenState(open);
|
|
1401
|
-
};
|
|
1500
|
+
}, [isLoading, context.chatSuggestionConfiguration]);
|
|
1402
1501
|
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
1403
1502
|
abortSuggestions();
|
|
1404
1503
|
setCurrentSuggestions([]);
|
|
@@ -1411,157 +1510,98 @@ var CopilotChat = ({
|
|
|
1411
1510
|
append(message);
|
|
1412
1511
|
return message;
|
|
1413
1512
|
});
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
setPushToTalkState(false);
|
|
1425
|
-
requestMicAndPlaybackPermission().then((res) => {
|
|
1426
|
-
if (res) {
|
|
1427
|
-
mediaStreamRef.current = res.stream;
|
|
1428
|
-
audioContextRef.current = res.audioContext;
|
|
1429
|
-
}
|
|
1430
|
-
});
|
|
1431
|
-
} else {
|
|
1432
|
-
console.log("Recording started");
|
|
1433
|
-
const recordedChunks = [];
|
|
1434
|
-
mediaRecorderRef.current = new MediaRecorder(mediaStreamRef.current);
|
|
1435
|
-
mediaRecorderRef.current.start(1e3);
|
|
1436
|
-
mediaRecorderRef.current.ondataavailable = (event) => __async(void 0, null, function* () {
|
|
1437
|
-
console.log("Recorded audio: ", event.data);
|
|
1438
|
-
recordedChunks.push(event.data);
|
|
1439
|
-
});
|
|
1440
|
-
mediaRecorderRef.current.onstop = () => __async(void 0, null, function* () {
|
|
1441
|
-
console.log("Recording stopped");
|
|
1442
|
-
const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
|
|
1443
|
-
const formData = new FormData();
|
|
1444
|
-
formData.append("file", completeBlob, "recording.mp4");
|
|
1445
|
-
const response = yield fetch(context.copilotApiConfig.transcribeAudioUrl, {
|
|
1446
|
-
method: "POST",
|
|
1447
|
-
body: formData
|
|
1448
|
-
});
|
|
1449
|
-
if (!response.ok) {
|
|
1450
|
-
throw new Error(`Error: ${response.statusText}`);
|
|
1451
|
-
}
|
|
1452
|
-
const transcription = yield response.json();
|
|
1453
|
-
const message = yield sendMessage(transcription.text);
|
|
1454
|
-
setLastMessageIdBeforeAudio(message.id);
|
|
1455
|
-
});
|
|
1456
|
-
}
|
|
1457
|
-
} else {
|
|
1458
|
-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
1459
|
-
mediaRecorderRef.current.stop();
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
return () => {
|
|
1463
|
-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") {
|
|
1464
|
-
mediaRecorderRef.current.stop();
|
|
1465
|
-
}
|
|
1466
|
-
};
|
|
1467
|
-
}, [pushToTalkState]);
|
|
1468
|
-
(0, import_react9.useEffect)(() => {
|
|
1469
|
-
if (lastMessageIdBeforeAudio && !isLoading) {
|
|
1470
|
-
if (audioContextRef.current) {
|
|
1471
|
-
const lastMessageIndex = context.messages.findIndex(
|
|
1472
|
-
(message) => message.id === lastMessageIdBeforeAudio
|
|
1473
|
-
);
|
|
1474
|
-
const messagesAfterLast = context.messages.slice(lastMessageIndex + 1).filter((message) => message.role === "assistant" && message.content);
|
|
1475
|
-
const text = messagesAfterLast.map((message) => message.content).join("\n");
|
|
1476
|
-
const encodedText = encodeURIComponent(text);
|
|
1477
|
-
const url = `${context.copilotApiConfig.textToSpeechUrl}?text=${encodedText}`;
|
|
1478
|
-
fetch(url).then((response) => response.arrayBuffer()).then((arrayBuffer) => audioContextRef.current.decodeAudioData(arrayBuffer)).then((audioBuffer) => {
|
|
1479
|
-
const source = audioContextRef.current.createBufferSource();
|
|
1480
|
-
source.buffer = audioBuffer;
|
|
1481
|
-
source.connect(audioContextRef.current.destination);
|
|
1482
|
-
source.start(0);
|
|
1483
|
-
}).catch((error) => {
|
|
1484
|
-
console.error("Error with decoding audio data", error);
|
|
1485
|
-
});
|
|
1486
|
-
setLastMessageIdBeforeAudio(null);
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
}, [isLoading]);
|
|
1490
|
-
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
1491
|
-
ChatContextProvider,
|
|
1492
|
-
{
|
|
1493
|
-
icons,
|
|
1494
|
-
labels,
|
|
1495
|
-
open: openState,
|
|
1496
|
-
setOpen: setOpenState,
|
|
1497
|
-
addChatSuggestionConfiguration,
|
|
1498
|
-
removeChatSuggestionConfiguration: removeChatSuggestion,
|
|
1499
|
-
children: [
|
|
1500
|
-
children,
|
|
1501
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className, children: [
|
|
1502
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1503
|
-
Button2,
|
|
1504
|
-
{
|
|
1505
|
-
open: openState,
|
|
1506
|
-
setOpen,
|
|
1507
|
-
pushToTalk: pushToTalkState,
|
|
1508
|
-
setPushToTalk: setPushToTalkState
|
|
1509
|
-
}
|
|
1510
|
-
),
|
|
1511
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
1512
|
-
Window2,
|
|
1513
|
-
{
|
|
1514
|
-
open: openState,
|
|
1515
|
-
setOpen,
|
|
1516
|
-
clickOutsideToClose,
|
|
1517
|
-
shortcut,
|
|
1518
|
-
hitEscapeToClose,
|
|
1519
|
-
children: [
|
|
1520
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Header2, { open: openState, setOpen }),
|
|
1521
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Messages2, { messages: visibleMessages, inProgress: isLoading, children: [
|
|
1522
|
-
currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { children: [
|
|
1523
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("h6", { children: "Suggested:" }),
|
|
1524
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "suggestions", children: currentSuggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1525
|
-
Suggestion,
|
|
1526
|
-
{
|
|
1527
|
-
title: suggestion.title,
|
|
1528
|
-
message: suggestion.message,
|
|
1529
|
-
partial: suggestion.partial,
|
|
1530
|
-
className: suggestion.className,
|
|
1531
|
-
onClick: (message) => sendMessage(message)
|
|
1532
|
-
},
|
|
1533
|
-
index
|
|
1534
|
-
)) })
|
|
1535
|
-
] }),
|
|
1536
|
-
showResponseButton && visibleMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ResponseButton2, { onClick: isLoading ? stop : reload, inProgress: isLoading })
|
|
1537
|
-
] }),
|
|
1538
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Input2, { inProgress: isLoading, onSend: sendMessage, isVisible: openState })
|
|
1539
|
-
]
|
|
1540
|
-
}
|
|
1541
|
-
)
|
|
1542
|
-
] })
|
|
1543
|
-
]
|
|
1544
|
-
}
|
|
1545
|
-
);
|
|
1513
|
+
return {
|
|
1514
|
+
visibleMessages,
|
|
1515
|
+
isLoading,
|
|
1516
|
+
currentSuggestions,
|
|
1517
|
+
sendMessage,
|
|
1518
|
+
stop,
|
|
1519
|
+
reload,
|
|
1520
|
+
input,
|
|
1521
|
+
setInput
|
|
1522
|
+
};
|
|
1546
1523
|
};
|
|
1547
1524
|
|
|
1548
|
-
// src/components/chat/
|
|
1525
|
+
// src/components/chat/Modal.tsx
|
|
1549
1526
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1527
|
+
var CopilotModal = ({
|
|
1528
|
+
instructions,
|
|
1529
|
+
defaultOpen = false,
|
|
1530
|
+
clickOutsideToClose = true,
|
|
1531
|
+
hitEscapeToClose = true,
|
|
1532
|
+
onSetOpen,
|
|
1533
|
+
onSubmitMessage,
|
|
1534
|
+
shortcut = "/",
|
|
1535
|
+
icons,
|
|
1536
|
+
labels,
|
|
1537
|
+
makeSystemMessage,
|
|
1538
|
+
showResponseButton = true,
|
|
1539
|
+
onInProgress,
|
|
1540
|
+
Window: Window2 = Window,
|
|
1541
|
+
Button: Button2 = Button,
|
|
1542
|
+
Header: Header2 = Header,
|
|
1543
|
+
Messages: Messages2 = Messages,
|
|
1544
|
+
Input: Input2 = Input,
|
|
1545
|
+
ResponseButton: ResponseButton2 = ResponseButton,
|
|
1546
|
+
className,
|
|
1547
|
+
children
|
|
1548
|
+
}) => {
|
|
1549
|
+
const [openState, setOpenState] = import_react10.default.useState(defaultOpen);
|
|
1550
|
+
const setOpen = (open) => {
|
|
1551
|
+
onSetOpen == null ? void 0 : onSetOpen(open);
|
|
1552
|
+
setOpenState(open);
|
|
1553
|
+
};
|
|
1554
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: [
|
|
1555
|
+
children,
|
|
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)(
|
|
1559
|
+
Window2,
|
|
1560
|
+
{
|
|
1561
|
+
open: openState,
|
|
1562
|
+
setOpen,
|
|
1563
|
+
clickOutsideToClose,
|
|
1564
|
+
shortcut,
|
|
1565
|
+
hitEscapeToClose,
|
|
1566
|
+
children: [
|
|
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
|
+
)
|
|
1581
|
+
]
|
|
1582
|
+
}
|
|
1583
|
+
)
|
|
1584
|
+
] })
|
|
1585
|
+
] });
|
|
1586
|
+
};
|
|
1587
|
+
|
|
1588
|
+
// src/components/chat/Popup.tsx
|
|
1589
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1550
1590
|
function CopilotPopup(props) {
|
|
1551
1591
|
props = __spreadProps(__spreadValues({}, props), {
|
|
1552
1592
|
className: props.className ? props.className + " copilotKitPopup" : "copilotKitPopup"
|
|
1553
1593
|
});
|
|
1554
|
-
return /* @__PURE__ */ (0,
|
|
1594
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CopilotModal, __spreadProps(__spreadValues({}, props), { children: props.children }));
|
|
1555
1595
|
}
|
|
1556
1596
|
|
|
1557
1597
|
// src/components/chat/Sidebar.tsx
|
|
1558
|
-
var
|
|
1559
|
-
var
|
|
1598
|
+
var import_react11 = require("react");
|
|
1599
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1560
1600
|
function CopilotSidebar(props) {
|
|
1561
1601
|
props = __spreadProps(__spreadValues({}, props), {
|
|
1562
1602
|
className: props.className ? props.className + " copilotKitSidebar" : "copilotKitSidebar"
|
|
1563
1603
|
});
|
|
1564
|
-
const [expandedClassName, setExpandedClassName] = (0,
|
|
1604
|
+
const [expandedClassName, setExpandedClassName] = (0, import_react11.useState)(
|
|
1565
1605
|
props.defaultOpen ? "sidebarExpanded" : ""
|
|
1566
1606
|
);
|
|
1567
1607
|
const onSetOpen = (open) => {
|
|
@@ -1569,34 +1609,36 @@ function CopilotSidebar(props) {
|
|
|
1569
1609
|
(_a = props.onSetOpen) == null ? void 0 : _a.call(props, open);
|
|
1570
1610
|
setExpandedClassName(open ? "sidebarExpanded" : "");
|
|
1571
1611
|
};
|
|
1572
|
-
return /* @__PURE__ */ (0,
|
|
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 })) });
|
|
1573
1613
|
}
|
|
1574
1614
|
|
|
1575
1615
|
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
1576
|
-
var
|
|
1616
|
+
var import_react12 = require("react");
|
|
1577
1617
|
var import_nanoid3 = require("nanoid");
|
|
1618
|
+
var import_react_core6 = require("@copilotkit/react-core");
|
|
1578
1619
|
function useCopilotChatSuggestions({
|
|
1579
1620
|
instructions,
|
|
1580
1621
|
className,
|
|
1581
1622
|
minSuggestions = 1,
|
|
1582
1623
|
maxSuggestions = 3
|
|
1583
1624
|
}, dependencies = []) {
|
|
1584
|
-
const
|
|
1585
|
-
(0,
|
|
1625
|
+
const context = (0, import_react_core6.useCopilotContext)();
|
|
1626
|
+
(0, import_react12.useEffect)(() => {
|
|
1586
1627
|
const id = (0, import_nanoid3.nanoid)();
|
|
1587
|
-
|
|
1628
|
+
context.addChatSuggestionConfiguration(id, {
|
|
1588
1629
|
instructions,
|
|
1589
1630
|
minSuggestions,
|
|
1590
1631
|
maxSuggestions,
|
|
1591
1632
|
className
|
|
1592
1633
|
});
|
|
1593
1634
|
return () => {
|
|
1594
|
-
|
|
1635
|
+
context.removeChatSuggestionConfiguration(id);
|
|
1595
1636
|
};
|
|
1596
1637
|
}, dependencies);
|
|
1597
1638
|
}
|
|
1598
1639
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1599
1640
|
0 && (module.exports = {
|
|
1641
|
+
CopilotChat,
|
|
1600
1642
|
CopilotPopup,
|
|
1601
1643
|
CopilotSidebar,
|
|
1602
1644
|
useChatContext,
|