@copilotkit/react-ui 1.10.0-next.3 → 1.10.0-next.5

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 (92) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-O7KTFUAN.mjs → chunk-226ZMOE3.mjs} +2 -2
  3. package/dist/{chunk-PF3QW6U5.mjs → chunk-BXX6RM44.mjs} +2 -2
  4. package/dist/chunk-BXX6RM44.mjs.map +1 -0
  5. package/dist/chunk-BY42E5VF.mjs +203 -0
  6. package/dist/chunk-BY42E5VF.mjs.map +1 -0
  7. package/dist/{chunk-SGFUVPDB.mjs → chunk-FFJHOZX6.mjs} +2 -2
  8. package/dist/{chunk-GVKA7RQQ.mjs → chunk-GDSZGYCE.mjs} +2 -2
  9. package/dist/{chunk-QN7T3GWI.mjs → chunk-JY2CSDKN.mjs} +4 -6
  10. package/dist/chunk-JY2CSDKN.mjs.map +1 -0
  11. package/dist/{chunk-7L34XQRL.mjs → chunk-K344MVUT.mjs} +61 -8
  12. package/dist/chunk-K344MVUT.mjs.map +1 -0
  13. package/dist/{chunk-QNG5G23E.mjs → chunk-MYWIJSW6.mjs} +2 -2
  14. package/dist/chunk-MYWIJSW6.mjs.map +1 -0
  15. package/dist/{chunk-WHDNKXMP.mjs → chunk-U5ATIGWH.mjs} +2 -2
  16. package/dist/chunk-U5ATIGWH.mjs.map +1 -0
  17. package/dist/{chunk-Q2467VHZ.mjs → chunk-W26XFBEG.mjs} +2 -2
  18. package/dist/chunk-W26XFBEG.mjs.map +1 -0
  19. package/dist/components/chat/Chat.d.ts +19 -12
  20. package/dist/components/chat/Chat.js +57 -10
  21. package/dist/components/chat/Chat.js.map +1 -1
  22. package/dist/components/chat/Chat.mjs +4 -4
  23. package/dist/components/chat/Header.js +6 -8
  24. package/dist/components/chat/Header.js.map +1 -1
  25. package/dist/components/chat/Header.mjs +3 -3
  26. package/dist/components/chat/Messages.js +1 -1
  27. package/dist/components/chat/Messages.js.map +1 -1
  28. package/dist/components/chat/Messages.mjs +1 -1
  29. package/dist/components/chat/Modal.d.ts +2 -2
  30. package/dist/components/chat/Modal.js +179 -76
  31. package/dist/components/chat/Modal.js.map +1 -1
  32. package/dist/components/chat/Modal.mjs +8 -8
  33. package/dist/components/chat/Popup.d.ts +1 -1
  34. package/dist/components/chat/Popup.js +179 -76
  35. package/dist/components/chat/Popup.js.map +1 -1
  36. package/dist/components/chat/Popup.mjs +9 -9
  37. package/dist/components/chat/Sidebar.d.ts +1 -1
  38. package/dist/components/chat/Sidebar.js +179 -76
  39. package/dist/components/chat/Sidebar.js.map +1 -1
  40. package/dist/components/chat/Sidebar.mjs +9 -9
  41. package/dist/components/chat/Suggestion.js +1 -1
  42. package/dist/components/chat/Suggestion.js.map +1 -1
  43. package/dist/components/chat/Suggestion.mjs +1 -1
  44. package/dist/components/chat/Suggestions.js +1 -1
  45. package/dist/components/chat/Suggestions.js.map +1 -1
  46. package/dist/components/chat/Suggestions.mjs +2 -2
  47. package/dist/components/chat/index.d.ts +2 -2
  48. package/dist/components/chat/index.js +179 -76
  49. package/dist/components/chat/index.js.map +1 -1
  50. package/dist/components/chat/index.mjs +10 -10
  51. package/dist/components/chat/props.d.ts +39 -1
  52. package/dist/components/chat/props.js.map +1 -1
  53. package/dist/components/dev-console/console.d.ts +1 -0
  54. package/dist/components/dev-console/console.js +6 -8
  55. package/dist/components/dev-console/console.js.map +1 -1
  56. package/dist/components/dev-console/console.mjs +2 -2
  57. package/dist/components/dev-console/index.d.ts +1 -3
  58. package/dist/components/dev-console/index.js +7 -9
  59. package/dist/components/dev-console/index.js.map +1 -1
  60. package/dist/components/dev-console/index.mjs +2 -2
  61. package/dist/components/dev-console/utils.d.ts +2 -2
  62. package/dist/components/dev-console/utils.js +2 -4
  63. package/dist/components/dev-console/utils.js.map +1 -1
  64. package/dist/components/dev-console/utils.mjs +1 -1
  65. package/dist/components/index.d.ts +3 -5
  66. package/dist/components/index.js +180 -77
  67. package/dist/components/index.js.map +1 -1
  68. package/dist/components/index.mjs +10 -10
  69. package/dist/index.d.ts +3 -5
  70. package/dist/index.js +184 -81
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +10 -10
  73. package/package.json +5 -5
  74. package/src/components/chat/Chat.tsx +99 -5
  75. package/src/components/chat/Messages.tsx +2 -2
  76. package/src/components/chat/Modal.tsx +107 -41
  77. package/src/components/chat/Popup.tsx +20 -0
  78. package/src/components/chat/Sidebar.tsx +22 -0
  79. package/src/components/chat/Suggestion.tsx +1 -1
  80. package/src/components/chat/props.ts +46 -0
  81. package/src/components/dev-console/utils.ts +1 -6
  82. package/dist/chunk-7L34XQRL.mjs.map +0 -1
  83. package/dist/chunk-DNSSBMAS.mjs +0 -144
  84. package/dist/chunk-DNSSBMAS.mjs.map +0 -1
  85. package/dist/chunk-PF3QW6U5.mjs.map +0 -1
  86. package/dist/chunk-Q2467VHZ.mjs.map +0 -1
  87. package/dist/chunk-QN7T3GWI.mjs.map +0 -1
  88. package/dist/chunk-QNG5G23E.mjs.map +0 -1
  89. package/dist/chunk-WHDNKXMP.mjs.map +0 -1
  90. /package/dist/{chunk-O7KTFUAN.mjs.map → chunk-226ZMOE3.mjs.map} +0 -0
  91. /package/dist/{chunk-SGFUVPDB.mjs.map → chunk-FFJHOZX6.mjs.map} +0 -0
  92. /package/dist/{chunk-GVKA7RQQ.mjs.map → chunk-GDSZGYCE.mjs.map} +0 -0
@@ -533,9 +533,7 @@ var Button = ({}) => {
533
533
 
534
534
  // src/components/dev-console/utils.ts
535
535
  var import_react_core2 = require("@copilotkit/react-core");
536
- function shouldShowDevConsole(showDevConsole) {
537
- return showDevConsole;
538
- }
536
+ var import_react_core3 = require("@copilotkit/react-core");
539
537
  function getPublishedCopilotKitVersion(current, forceCheck = false) {
540
538
  return __async(this, null, function* () {
541
539
  const LOCAL_STORAGE_KEY = "__copilotkit_version_check__";
@@ -655,7 +653,7 @@ function logMessages(context) {
655
653
  }
656
654
 
657
655
  // src/components/dev-console/console.tsx
658
- var import_react_core3 = require("@copilotkit/react-core");
656
+ var import_react_core4 = require("@copilotkit/react-core");
659
657
  var import_react4 = require("react");
660
658
 
661
659
  // src/components/dev-console/icons.tsx
@@ -845,10 +843,10 @@ function CopilotKitHelpModal() {
845
843
  var import_jsx_runtime8 = require("react/jsx-runtime");
846
844
  function CopilotDevConsole() {
847
845
  const currentVersion = import_shared2.COPILOTKIT_VERSION;
848
- const context = (0, import_react_core3.useCopilotContext)();
846
+ const context = (0, import_react_core4.useCopilotContext)();
849
847
  const [showDevConsole, setShowDevConsole] = (0, import_react4.useState)(false);
850
848
  (0, import_react4.useEffect)(() => {
851
- setShowDevConsole(shouldShowDevConsole(context.showDevConsole));
849
+ setShowDevConsole((0, import_react_core3.shouldShowDevConsole)(context.showDevConsole));
852
850
  }, [context.showDevConsole]);
853
851
  const dontRunTwiceInDevMode = (0, import_react4.useRef)(false);
854
852
  const [versionStatus, setVersionStatus] = (0, import_react4.useState)("unknown");
@@ -974,8 +972,8 @@ function DebugMenuButton({
974
972
  checkForUpdates,
975
973
  mode
976
974
  }) {
977
- const context = (0, import_react_core3.useCopilotContext)();
978
- const messagesContext = (0, import_react_core3.useCopilotMessagesContext)();
975
+ const context = (0, import_react_core4.useCopilotContext)();
976
+ const messagesContext = (0, import_react_core4.useCopilotMessagesContext)();
979
977
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react5.Menu, { children: [
980
978
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
981
979
  import_react5.MenuButton,
@@ -1037,7 +1035,7 @@ var Header = ({}) => {
1037
1035
 
1038
1036
  // src/components/chat/Messages.tsx
1039
1037
  var import_react6 = require("react");
1040
- var import_react_core4 = require("@copilotkit/react-core");
1038
+ var import_react_core5 = require("@copilotkit/react-core");
1041
1039
  var import_jsx_runtime10 = require("react/jsx-runtime");
1042
1040
  var Messages = ({
1043
1041
  inProgress,
@@ -1052,7 +1050,7 @@ var Messages = ({
1052
1050
  markdownTagRenderers
1053
1051
  }) => {
1054
1052
  const { labels } = useChatContext();
1055
- const { visibleMessages, interrupt } = (0, import_react_core4.useCopilotChat)();
1053
+ const { visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
1056
1054
  const initialMessages = (0, import_react6.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
1057
1055
  const messages = [...initialMessages, ...visibleMessages];
1058
1056
  const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
@@ -1225,7 +1223,7 @@ var AutoResizingTextarea = (0, import_react7.forwardRef)(
1225
1223
  var Textarea_default = AutoResizingTextarea;
1226
1224
 
1227
1225
  // src/hooks/use-push-to-talk.tsx
1228
- var import_react_core5 = require("@copilotkit/react-core");
1226
+ var import_react_core6 = require("@copilotkit/react-core");
1229
1227
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1230
1228
  var import_react8 = require("react");
1231
1229
  var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
@@ -1281,8 +1279,8 @@ var usePushToTalk = ({
1281
1279
  const audioContextRef = (0, import_react8.useRef)(null);
1282
1280
  const mediaRecorderRef = (0, import_react8.useRef)(null);
1283
1281
  const recordedChunks = (0, import_react8.useRef)([]);
1284
- const generalContext = (0, import_react_core5.useCopilotContext)();
1285
- const messagesContext = (0, import_react_core5.useCopilotMessagesContext)();
1282
+ const generalContext = (0, import_react_core6.useCopilotContext)();
1283
+ const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
1286
1284
  const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
1287
1285
  const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react8.useState)(null);
1288
1286
  (0, import_react8.useEffect)(() => {
@@ -1329,7 +1327,7 @@ var usePushToTalk = ({
1329
1327
  };
1330
1328
 
1331
1329
  // src/components/chat/Input.tsx
1332
- var import_react_core6 = require("@copilotkit/react-core");
1330
+ var import_react_core7 = require("@copilotkit/react-core");
1333
1331
 
1334
1332
  // src/hooks/use-dark-mode.ts
1335
1333
  var useDarkMode = () => {
@@ -1370,7 +1368,7 @@ var Input = ({
1370
1368
  }) => {
1371
1369
  var _a, _b;
1372
1370
  const context = useChatContext();
1373
- const copilotContext = (0, import_react_core6.useCopilotContext)();
1371
+ const copilotContext = (0, import_react_core7.useCopilotContext)();
1374
1372
  const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
1375
1373
  const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
1376
1374
  const textareaRef = (0, import_react9.useRef)(null);
@@ -2177,9 +2175,10 @@ function RenderMessage(_a) {
2177
2175
 
2178
2176
  // src/components/chat/Chat.tsx
2179
2177
  var import_react14 = __toESM(require("react"));
2180
- var import_react_core8 = require("@copilotkit/react-core");
2181
- var import_shared3 = require("@copilotkit/shared");
2182
2178
  var import_react_core9 = require("@copilotkit/react-core");
2179
+ var import_shared3 = require("@copilotkit/shared");
2180
+ var import_shared4 = require("@copilotkit/shared");
2181
+ var import_react_core10 = require("@copilotkit/react-core");
2183
2182
 
2184
2183
  // src/components/chat/ImageUploadQueue.tsx
2185
2184
  var import_jsx_runtime20 = require("react/jsx-runtime");
@@ -2260,12 +2259,12 @@ var ImageUploadQueue = ({
2260
2259
  };
2261
2260
 
2262
2261
  // src/components/chat/Suggestion.tsx
2263
- var import_react_core7 = require("@copilotkit/react-core");
2262
+ var import_react_core8 = require("@copilotkit/react-core");
2264
2263
  var import_jsx_runtime21 = require("react/jsx-runtime");
2265
2264
  function Suggestion({ title, onClick, partial, className }) {
2266
2265
  if (!title)
2267
2266
  return null;
2268
- const { isLoading } = (0, import_react_core7.useCopilotChat)();
2267
+ const { isLoading } = (0, import_react_core8.useCopilotChatInternal)();
2269
2268
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2270
2269
  "button",
2271
2270
  {
@@ -2324,11 +2323,31 @@ function CopilotChat({
2324
2323
  ImageRenderer: ImageRenderer2 = ImageRenderer,
2325
2324
  imageUploadsEnabled,
2326
2325
  inputFileAccept = "image/*",
2327
- hideStopButton
2326
+ hideStopButton,
2327
+ observabilityHooks
2328
2328
  }) {
2329
- const { additionalInstructions, setChatInstructions } = (0, import_react_core8.useCopilotContext)();
2329
+ const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
2330
2330
  const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
2331
2331
  const fileInputRef = (0, import_react14.useRef)(null);
2332
+ const triggerObservabilityHook = (0, import_react14.useCallback)(
2333
+ (hookName, ...args) => {
2334
+ if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2335
+ observabilityHooks[hookName](...args);
2336
+ }
2337
+ if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !copilotApiConfig.publicApiKey) {
2338
+ setBannerError(
2339
+ new import_shared3.CopilotKitError({
2340
+ message: "observabilityHooks requires a publicApiKey to function.",
2341
+ code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
2342
+ severity: import_shared3.Severity.CRITICAL,
2343
+ visibility: import_shared3.ErrorVisibility.BANNER
2344
+ })
2345
+ );
2346
+ import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks");
2347
+ }
2348
+ },
2349
+ [copilotApiConfig.publicApiKey, observabilityHooks]
2350
+ );
2332
2351
  (0, import_react14.useEffect)(() => {
2333
2352
  if (!imageUploadsEnabled)
2334
2353
  return;
@@ -2401,12 +2420,24 @@ function CopilotChat({
2401
2420
  onStopGeneration,
2402
2421
  onReloadMessages
2403
2422
  );
2423
+ const prevIsLoading = (0, import_react14.useRef)(isLoading);
2424
+ (0, import_react14.useEffect)(() => {
2425
+ if (prevIsLoading.current !== isLoading) {
2426
+ if (isLoading) {
2427
+ triggerObservabilityHook("onChatStarted");
2428
+ } else {
2429
+ triggerObservabilityHook("onChatStopped");
2430
+ }
2431
+ prevIsLoading.current = isLoading;
2432
+ }
2433
+ }, [isLoading, triggerObservabilityHook]);
2404
2434
  const handleSendMessage = (text) => {
2405
2435
  const images = selectedImages;
2406
2436
  setSelectedImages([]);
2407
2437
  if (fileInputRef.current) {
2408
2438
  fileInputRef.current.value = "";
2409
2439
  }
2440
+ triggerObservabilityHook("onMessageSent", text);
2410
2441
  return sendMessage(text, images);
2411
2442
  };
2412
2443
  const chatContext = import_react14.default.useContext(ChatContext);
@@ -2415,12 +2446,14 @@ function CopilotChat({
2415
2446
  if (onRegenerate) {
2416
2447
  onRegenerate(messageId);
2417
2448
  }
2449
+ triggerObservabilityHook("onMessageRegenerated", messageId);
2418
2450
  reloadMessages(messageId);
2419
2451
  };
2420
2452
  const handleCopy = (message) => {
2421
2453
  if (onCopy) {
2422
2454
  onCopy(message);
2423
2455
  }
2456
+ triggerObservabilityHook("onMessageCopied", message);
2424
2457
  };
2425
2458
  const handleImageUpload = (event) => __async(this, null, function* () {
2426
2459
  if (!event.target.files || event.target.files.length === 0) {
@@ -2456,6 +2489,18 @@ function CopilotChat({
2456
2489
  const removeSelectedImage = (index) => {
2457
2490
  setSelectedImages((prev) => prev.filter((_, i) => i !== index));
2458
2491
  };
2492
+ const handleThumbsUp = (message) => {
2493
+ if (onThumbsUp) {
2494
+ onThumbsUp(message);
2495
+ }
2496
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
2497
+ };
2498
+ const handleThumbsDown = (message) => {
2499
+ if (onThumbsDown) {
2500
+ onThumbsDown(message);
2501
+ }
2502
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
2503
+ };
2459
2504
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2460
2505
  /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2461
2506
  Messages2,
@@ -2467,8 +2512,8 @@ function CopilotChat({
2467
2512
  inProgress: isLoading,
2468
2513
  onRegenerate: handleRegenerate,
2469
2514
  onCopy: handleCopy,
2470
- onThumbsUp,
2471
- onThumbsDown,
2515
+ onThumbsUp: handleThumbsUp,
2516
+ onThumbsDown: handleThumbsDown,
2472
2517
  markdownTagRenderers,
2473
2518
  ImageRenderer: ImageRenderer2,
2474
2519
  children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
@@ -2538,11 +2583,11 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2538
2583
  generateSuggestions,
2539
2584
  resetSuggestions: resetSuggestionsFromHook,
2540
2585
  isLoadingSuggestions
2541
- } = (0, import_react_core8.useCopilotChat)({
2586
+ } = (0, import_react_core9.useCopilotChatInternal)({
2542
2587
  makeSystemMessage
2543
2588
  });
2544
- const generalContext = (0, import_react_core8.useCopilotContext)();
2545
- const messagesContext = (0, import_react_core8.useCopilotMessagesContext)();
2589
+ const generalContext = (0, import_react_core9.useCopilotContext)();
2590
+ const messagesContext = (0, import_react_core9.useCopilotMessagesContext)();
2546
2591
  const { actions } = generalContext;
2547
2592
  const [suggestionsFailed, setSuggestionsFailed] = (0, import_react14.useState)(false);
2548
2593
  const hasGeneratedInitialSuggestions = (0, import_react14.useRef)(false);
@@ -2624,7 +2669,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2624
2669
  let firstMessage = null;
2625
2670
  if (messageContent.trim().length > 0) {
2626
2671
  const textMessage = {
2627
- id: (0, import_shared3.randomId)(),
2672
+ id: (0, import_shared4.randomId)(),
2628
2673
  role: "user",
2629
2674
  content: messageContent
2630
2675
  };
@@ -2646,7 +2691,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2646
2691
  if (images.length > 0) {
2647
2692
  for (let i = 0; i < images.length; i++) {
2648
2693
  const imageMessage = {
2649
- id: (0, import_shared3.randomId)(),
2694
+ id: (0, import_shared4.randomId)(),
2650
2695
  role: "user",
2651
2696
  image: {
2652
2697
  format: images[i].contentType.replace("image/", ""),
@@ -2660,7 +2705,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2660
2705
  }
2661
2706
  }
2662
2707
  if (!firstMessage) {
2663
- return { role: "user", content: "", id: (0, import_shared3.randomId)() };
2708
+ return { role: "user", content: "", id: (0, import_shared4.randomId)() };
2664
2709
  }
2665
2710
  return firstMessage;
2666
2711
  });
@@ -2685,7 +2730,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2685
2730
  });
2686
2731
  const runCurrentAgent = (hint) => __async(void 0, null, function* () {
2687
2732
  if (generalContext.agentSession) {
2688
- yield (0, import_react_core9.runAgent)(
2733
+ yield (0, import_react_core10.runAgent)(
2689
2734
  generalContext.agentSession.agentName,
2690
2735
  stableContext,
2691
2736
  appendMessage,
@@ -2696,7 +2741,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2696
2741
  });
2697
2742
  const stopCurrentAgent = () => {
2698
2743
  if (generalContext.agentSession) {
2699
- (0, import_react_core9.stopAgent)(generalContext.agentSession.agentName, stableContext);
2744
+ (0, import_react_core10.stopAgent)(generalContext.agentSession.agentName, stableContext);
2700
2745
  }
2701
2746
  };
2702
2747
  const setCurrentAgentState = (state) => {
@@ -2759,7 +2804,75 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2759
2804
  };
2760
2805
 
2761
2806
  // src/components/chat/Modal.tsx
2807
+ var import_react_core11 = require("@copilotkit/react-core");
2762
2808
  var import_jsx_runtime24 = require("react/jsx-runtime");
2809
+ var CopilotModalInner = (_a) => {
2810
+ var _b = _a, {
2811
+ observabilityHooks,
2812
+ onSetOpen,
2813
+ clickOutsideToClose,
2814
+ hitEscapeToClose,
2815
+ shortcut,
2816
+ className,
2817
+ children,
2818
+ Window: Window2,
2819
+ Button: Button2,
2820
+ Header: Header2
2821
+ } = _b, chatProps = __objRest(_b, [
2822
+ "observabilityHooks",
2823
+ "onSetOpen",
2824
+ "clickOutsideToClose",
2825
+ "hitEscapeToClose",
2826
+ "shortcut",
2827
+ "className",
2828
+ "children",
2829
+ "Window",
2830
+ "Button",
2831
+ "Header"
2832
+ ]);
2833
+ const { copilotApiConfig } = (0, import_react_core11.useCopilotContext)();
2834
+ const triggerObservabilityHook = (0, import_react15.useCallback)(
2835
+ (hookName, ...args) => {
2836
+ if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2837
+ observabilityHooks[hookName](...args);
2838
+ }
2839
+ },
2840
+ [copilotApiConfig.publicApiKey, observabilityHooks]
2841
+ );
2842
+ const { open } = useChatContext();
2843
+ const prevOpen = (0, import_react15.useRef)(open);
2844
+ (0, import_react15.useEffect)(() => {
2845
+ if (prevOpen.current !== open) {
2846
+ onSetOpen == null ? void 0 : onSetOpen(open);
2847
+ if (open) {
2848
+ triggerObservabilityHook("onChatExpanded");
2849
+ } else {
2850
+ triggerObservabilityHook("onChatMinimized");
2851
+ }
2852
+ prevOpen.current = open;
2853
+ }
2854
+ }, [open, onSetOpen, triggerObservabilityHook]);
2855
+ const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
2856
+ const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2857
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
2858
+ memoizedChildren,
2859
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2860
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2861
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2862
+ Window2,
2863
+ {
2864
+ clickOutsideToClose,
2865
+ shortcut,
2866
+ hitEscapeToClose,
2867
+ children: [
2868
+ memoizedHeader,
2869
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
2870
+ ]
2871
+ }
2872
+ )
2873
+ ] })
2874
+ ] });
2875
+ };
2763
2876
  var CopilotModal = (_a) => {
2764
2877
  var _b = _a, {
2765
2878
  instructions,
@@ -2788,7 +2901,8 @@ var CopilotModal = (_a) => {
2788
2901
  onRegenerate,
2789
2902
  markdownTagRenderers,
2790
2903
  className,
2791
- children
2904
+ children,
2905
+ observabilityHooks
2792
2906
  } = _b, props = __objRest(_b, [
2793
2907
  "instructions",
2794
2908
  "defaultOpen",
@@ -2816,52 +2930,41 @@ var CopilotModal = (_a) => {
2816
2930
  "onRegenerate",
2817
2931
  "markdownTagRenderers",
2818
2932
  "className",
2819
- "children"
2933
+ "children",
2934
+ "observabilityHooks"
2820
2935
  ]);
2821
2936
  const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
2822
- const setOpen = (open) => {
2823
- onSetOpen == null ? void 0 : onSetOpen(open);
2824
- setOpenState(open);
2825
- };
2826
- const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
2827
- const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2828
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen, children: [
2829
- memoizedChildren,
2830
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2831
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2832
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2833
- Window2,
2834
- {
2835
- clickOutsideToClose,
2836
- shortcut,
2837
- hitEscapeToClose,
2838
- children: [
2839
- memoizedHeader,
2840
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2841
- CopilotChat,
2842
- __spreadProps(__spreadValues({}, props), {
2843
- instructions,
2844
- onSubmitMessage,
2845
- onStopGeneration,
2846
- onReloadMessages,
2847
- makeSystemMessage,
2848
- onInProgress,
2849
- Messages: Messages2,
2850
- Input: Input2,
2851
- AssistantMessage: AssistantMessage2,
2852
- UserMessage: UserMessage2,
2853
- onThumbsUp,
2854
- onThumbsDown,
2855
- onCopy,
2856
- onRegenerate,
2857
- markdownTagRenderers
2858
- })
2859
- )
2860
- ]
2861
- }
2862
- )
2863
- ] })
2864
- ] });
2937
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2938
+ CopilotModalInner,
2939
+ __spreadProps(__spreadValues({
2940
+ observabilityHooks,
2941
+ onSetOpen,
2942
+ clickOutsideToClose: clickOutsideToClose != null ? clickOutsideToClose : true,
2943
+ hitEscapeToClose: hitEscapeToClose != null ? hitEscapeToClose : true,
2944
+ shortcut: shortcut != null ? shortcut : "/",
2945
+ className,
2946
+ Window: Window2,
2947
+ Button: Button2,
2948
+ Header: Header2,
2949
+ instructions,
2950
+ onSubmitMessage,
2951
+ onStopGeneration,
2952
+ onReloadMessages,
2953
+ makeSystemMessage,
2954
+ onInProgress,
2955
+ Messages: Messages2,
2956
+ Input: Input2,
2957
+ AssistantMessage: AssistantMessage2,
2958
+ UserMessage: UserMessage2,
2959
+ onThumbsUp,
2960
+ onThumbsDown,
2961
+ onCopy,
2962
+ onRegenerate,
2963
+ markdownTagRenderers
2964
+ }, props), {
2965
+ children
2966
+ })
2967
+ ) });
2865
2968
  };
2866
2969
 
2867
2970
  // src/components/chat/Popup.tsx