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