@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
@@ -522,9 +522,7 @@ var Button = ({}) => {
522
522
 
523
523
  // src/components/dev-console/utils.ts
524
524
  var import_react_core2 = require("@copilotkit/react-core");
525
- function shouldShowDevConsole(showDevConsole) {
526
- return showDevConsole;
527
- }
525
+ var import_react_core3 = require("@copilotkit/react-core");
528
526
  function getPublishedCopilotKitVersion(current, forceCheck = false) {
529
527
  return __async(this, null, function* () {
530
528
  const LOCAL_STORAGE_KEY = "__copilotkit_version_check__";
@@ -644,7 +642,7 @@ function logMessages(context) {
644
642
  }
645
643
 
646
644
  // src/components/dev-console/console.tsx
647
- var import_react_core3 = require("@copilotkit/react-core");
645
+ var import_react_core4 = require("@copilotkit/react-core");
648
646
  var import_react4 = require("react");
649
647
 
650
648
  // src/components/dev-console/icons.tsx
@@ -834,10 +832,10 @@ function CopilotKitHelpModal() {
834
832
  var import_jsx_runtime8 = require("react/jsx-runtime");
835
833
  function CopilotDevConsole() {
836
834
  const currentVersion = import_shared2.COPILOTKIT_VERSION;
837
- const context = (0, import_react_core3.useCopilotContext)();
835
+ const context = (0, import_react_core4.useCopilotContext)();
838
836
  const [showDevConsole, setShowDevConsole] = (0, import_react4.useState)(false);
839
837
  (0, import_react4.useEffect)(() => {
840
- setShowDevConsole(shouldShowDevConsole(context.showDevConsole));
838
+ setShowDevConsole((0, import_react_core3.shouldShowDevConsole)(context.showDevConsole));
841
839
  }, [context.showDevConsole]);
842
840
  const dontRunTwiceInDevMode = (0, import_react4.useRef)(false);
843
841
  const [versionStatus, setVersionStatus] = (0, import_react4.useState)("unknown");
@@ -963,8 +961,8 @@ function DebugMenuButton({
963
961
  checkForUpdates,
964
962
  mode
965
963
  }) {
966
- const context = (0, import_react_core3.useCopilotContext)();
967
- const messagesContext = (0, import_react_core3.useCopilotMessagesContext)();
964
+ const context = (0, import_react_core4.useCopilotContext)();
965
+ const messagesContext = (0, import_react_core4.useCopilotMessagesContext)();
968
966
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react5.Menu, { children: [
969
967
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
970
968
  import_react5.MenuButton,
@@ -1026,7 +1024,7 @@ var Header = ({}) => {
1026
1024
 
1027
1025
  // src/components/chat/Messages.tsx
1028
1026
  var import_react6 = require("react");
1029
- var import_react_core4 = require("@copilotkit/react-core");
1027
+ var import_react_core5 = require("@copilotkit/react-core");
1030
1028
  var import_jsx_runtime10 = require("react/jsx-runtime");
1031
1029
  var Messages = ({
1032
1030
  inProgress,
@@ -1041,7 +1039,7 @@ var Messages = ({
1041
1039
  markdownTagRenderers
1042
1040
  }) => {
1043
1041
  const { labels } = useChatContext();
1044
- const { visibleMessages, interrupt } = (0, import_react_core4.useCopilotChat)();
1042
+ const { visibleMessages, interrupt } = (0, import_react_core5.useCopilotChatInternal)();
1045
1043
  const initialMessages = (0, import_react6.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]);
1046
1044
  const messages = [...initialMessages, ...visibleMessages];
1047
1045
  const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);
@@ -1214,7 +1212,7 @@ var AutoResizingTextarea = (0, import_react7.forwardRef)(
1214
1212
  var Textarea_default = AutoResizingTextarea;
1215
1213
 
1216
1214
  // src/hooks/use-push-to-talk.tsx
1217
- var import_react_core5 = require("@copilotkit/react-core");
1215
+ var import_react_core6 = require("@copilotkit/react-core");
1218
1216
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
1219
1217
  var import_react8 = require("react");
1220
1218
  var startRecording = (mediaStreamRef, mediaRecorderRef, audioContextRef, recordedChunks, onStop) => __async(void 0, null, function* () {
@@ -1270,8 +1268,8 @@ var usePushToTalk = ({
1270
1268
  const audioContextRef = (0, import_react8.useRef)(null);
1271
1269
  const mediaRecorderRef = (0, import_react8.useRef)(null);
1272
1270
  const recordedChunks = (0, import_react8.useRef)([]);
1273
- const generalContext = (0, import_react_core5.useCopilotContext)();
1274
- const messagesContext = (0, import_react_core5.useCopilotMessagesContext)();
1271
+ const generalContext = (0, import_react_core6.useCopilotContext)();
1272
+ const messagesContext = (0, import_react_core6.useCopilotMessagesContext)();
1275
1273
  const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
1276
1274
  const [startReadingFromMessageId, setStartReadingFromMessageId] = (0, import_react8.useState)(null);
1277
1275
  (0, import_react8.useEffect)(() => {
@@ -1318,7 +1316,7 @@ var usePushToTalk = ({
1318
1316
  };
1319
1317
 
1320
1318
  // src/components/chat/Input.tsx
1321
- var import_react_core6 = require("@copilotkit/react-core");
1319
+ var import_react_core7 = require("@copilotkit/react-core");
1322
1320
 
1323
1321
  // src/hooks/use-dark-mode.ts
1324
1322
  var useDarkMode = () => {
@@ -1359,7 +1357,7 @@ var Input = ({
1359
1357
  }) => {
1360
1358
  var _a, _b;
1361
1359
  const context = useChatContext();
1362
- const copilotContext = (0, import_react_core6.useCopilotContext)();
1360
+ const copilotContext = (0, import_react_core7.useCopilotContext)();
1363
1361
  const showPoweredBy = !((_a = copilotContext.copilotApiConfig) == null ? void 0 : _a.publicApiKey);
1364
1362
  const pushToTalkConfigured = copilotContext.copilotApiConfig.textToSpeechUrl !== void 0 && copilotContext.copilotApiConfig.transcribeAudioUrl !== void 0;
1365
1363
  const textareaRef = (0, import_react9.useRef)(null);
@@ -2166,9 +2164,10 @@ function RenderMessage(_a) {
2166
2164
 
2167
2165
  // src/components/chat/Chat.tsx
2168
2166
  var import_react14 = __toESM(require("react"));
2169
- var import_react_core8 = require("@copilotkit/react-core");
2170
- var import_shared3 = require("@copilotkit/shared");
2171
2167
  var import_react_core9 = require("@copilotkit/react-core");
2168
+ var import_shared3 = require("@copilotkit/shared");
2169
+ var import_shared4 = require("@copilotkit/shared");
2170
+ var import_react_core10 = require("@copilotkit/react-core");
2172
2171
 
2173
2172
  // src/components/chat/ImageUploadQueue.tsx
2174
2173
  var import_jsx_runtime20 = require("react/jsx-runtime");
@@ -2249,12 +2248,12 @@ var ImageUploadQueue = ({
2249
2248
  };
2250
2249
 
2251
2250
  // src/components/chat/Suggestion.tsx
2252
- var import_react_core7 = require("@copilotkit/react-core");
2251
+ var import_react_core8 = require("@copilotkit/react-core");
2253
2252
  var import_jsx_runtime21 = require("react/jsx-runtime");
2254
2253
  function Suggestion({ title, onClick, partial, className }) {
2255
2254
  if (!title)
2256
2255
  return null;
2257
- const { isLoading } = (0, import_react_core7.useCopilotChat)();
2256
+ const { isLoading } = (0, import_react_core8.useCopilotChatInternal)();
2258
2257
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2259
2258
  "button",
2260
2259
  {
@@ -2313,11 +2312,31 @@ function CopilotChat({
2313
2312
  ImageRenderer: ImageRenderer2 = ImageRenderer,
2314
2313
  imageUploadsEnabled,
2315
2314
  inputFileAccept = "image/*",
2316
- hideStopButton
2315
+ hideStopButton,
2316
+ observabilityHooks
2317
2317
  }) {
2318
- const { additionalInstructions, setChatInstructions } = (0, import_react_core8.useCopilotContext)();
2318
+ const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
2319
2319
  const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
2320
2320
  const fileInputRef = (0, import_react14.useRef)(null);
2321
+ const triggerObservabilityHook = (0, import_react14.useCallback)(
2322
+ (hookName, ...args) => {
2323
+ if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2324
+ observabilityHooks[hookName](...args);
2325
+ }
2326
+ if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !copilotApiConfig.publicApiKey) {
2327
+ setBannerError(
2328
+ new import_shared3.CopilotKitError({
2329
+ message: "observabilityHooks requires a publicApiKey to function.",
2330
+ code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
2331
+ severity: import_shared3.Severity.CRITICAL,
2332
+ visibility: import_shared3.ErrorVisibility.BANNER
2333
+ })
2334
+ );
2335
+ import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks");
2336
+ }
2337
+ },
2338
+ [copilotApiConfig.publicApiKey, observabilityHooks]
2339
+ );
2321
2340
  (0, import_react14.useEffect)(() => {
2322
2341
  if (!imageUploadsEnabled)
2323
2342
  return;
@@ -2390,12 +2409,24 @@ function CopilotChat({
2390
2409
  onStopGeneration,
2391
2410
  onReloadMessages
2392
2411
  );
2412
+ const prevIsLoading = (0, import_react14.useRef)(isLoading);
2413
+ (0, import_react14.useEffect)(() => {
2414
+ if (prevIsLoading.current !== isLoading) {
2415
+ if (isLoading) {
2416
+ triggerObservabilityHook("onChatStarted");
2417
+ } else {
2418
+ triggerObservabilityHook("onChatStopped");
2419
+ }
2420
+ prevIsLoading.current = isLoading;
2421
+ }
2422
+ }, [isLoading, triggerObservabilityHook]);
2393
2423
  const handleSendMessage = (text) => {
2394
2424
  const images = selectedImages;
2395
2425
  setSelectedImages([]);
2396
2426
  if (fileInputRef.current) {
2397
2427
  fileInputRef.current.value = "";
2398
2428
  }
2429
+ triggerObservabilityHook("onMessageSent", text);
2399
2430
  return sendMessage(text, images);
2400
2431
  };
2401
2432
  const chatContext = import_react14.default.useContext(ChatContext);
@@ -2404,12 +2435,14 @@ function CopilotChat({
2404
2435
  if (onRegenerate) {
2405
2436
  onRegenerate(messageId);
2406
2437
  }
2438
+ triggerObservabilityHook("onMessageRegenerated", messageId);
2407
2439
  reloadMessages(messageId);
2408
2440
  };
2409
2441
  const handleCopy = (message) => {
2410
2442
  if (onCopy) {
2411
2443
  onCopy(message);
2412
2444
  }
2445
+ triggerObservabilityHook("onMessageCopied", message);
2413
2446
  };
2414
2447
  const handleImageUpload = (event) => __async(this, null, function* () {
2415
2448
  if (!event.target.files || event.target.files.length === 0) {
@@ -2445,6 +2478,18 @@ function CopilotChat({
2445
2478
  const removeSelectedImage = (index) => {
2446
2479
  setSelectedImages((prev) => prev.filter((_, i) => i !== index));
2447
2480
  };
2481
+ const handleThumbsUp = (message) => {
2482
+ if (onThumbsUp) {
2483
+ onThumbsUp(message);
2484
+ }
2485
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
2486
+ };
2487
+ const handleThumbsDown = (message) => {
2488
+ if (onThumbsDown) {
2489
+ onThumbsDown(message);
2490
+ }
2491
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
2492
+ };
2448
2493
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2449
2494
  /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2450
2495
  Messages2,
@@ -2456,8 +2501,8 @@ function CopilotChat({
2456
2501
  inProgress: isLoading,
2457
2502
  onRegenerate: handleRegenerate,
2458
2503
  onCopy: handleCopy,
2459
- onThumbsUp,
2460
- onThumbsDown,
2504
+ onThumbsUp: handleThumbsUp,
2505
+ onThumbsDown: handleThumbsDown,
2461
2506
  markdownTagRenderers,
2462
2507
  ImageRenderer: ImageRenderer2,
2463
2508
  children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
@@ -2527,11 +2572,11 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2527
2572
  generateSuggestions,
2528
2573
  resetSuggestions: resetSuggestionsFromHook,
2529
2574
  isLoadingSuggestions
2530
- } = (0, import_react_core8.useCopilotChat)({
2575
+ } = (0, import_react_core9.useCopilotChatInternal)({
2531
2576
  makeSystemMessage
2532
2577
  });
2533
- const generalContext = (0, import_react_core8.useCopilotContext)();
2534
- const messagesContext = (0, import_react_core8.useCopilotMessagesContext)();
2578
+ const generalContext = (0, import_react_core9.useCopilotContext)();
2579
+ const messagesContext = (0, import_react_core9.useCopilotMessagesContext)();
2535
2580
  const { actions } = generalContext;
2536
2581
  const [suggestionsFailed, setSuggestionsFailed] = (0, import_react14.useState)(false);
2537
2582
  const hasGeneratedInitialSuggestions = (0, import_react14.useRef)(false);
@@ -2613,7 +2658,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2613
2658
  let firstMessage = null;
2614
2659
  if (messageContent.trim().length > 0) {
2615
2660
  const textMessage = {
2616
- id: (0, import_shared3.randomId)(),
2661
+ id: (0, import_shared4.randomId)(),
2617
2662
  role: "user",
2618
2663
  content: messageContent
2619
2664
  };
@@ -2635,7 +2680,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2635
2680
  if (images.length > 0) {
2636
2681
  for (let i = 0; i < images.length; i++) {
2637
2682
  const imageMessage = {
2638
- id: (0, import_shared3.randomId)(),
2683
+ id: (0, import_shared4.randomId)(),
2639
2684
  role: "user",
2640
2685
  image: {
2641
2686
  format: images[i].contentType.replace("image/", ""),
@@ -2649,7 +2694,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2649
2694
  }
2650
2695
  }
2651
2696
  if (!firstMessage) {
2652
- return { role: "user", content: "", id: (0, import_shared3.randomId)() };
2697
+ return { role: "user", content: "", id: (0, import_shared4.randomId)() };
2653
2698
  }
2654
2699
  return firstMessage;
2655
2700
  });
@@ -2674,7 +2719,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2674
2719
  });
2675
2720
  const runCurrentAgent = (hint) => __async(void 0, null, function* () {
2676
2721
  if (generalContext.agentSession) {
2677
- yield (0, import_react_core9.runAgent)(
2722
+ yield (0, import_react_core10.runAgent)(
2678
2723
  generalContext.agentSession.agentName,
2679
2724
  stableContext,
2680
2725
  appendMessage,
@@ -2685,7 +2730,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2685
2730
  });
2686
2731
  const stopCurrentAgent = () => {
2687
2732
  if (generalContext.agentSession) {
2688
- (0, import_react_core9.stopAgent)(generalContext.agentSession.agentName, stableContext);
2733
+ (0, import_react_core10.stopAgent)(generalContext.agentSession.agentName, stableContext);
2689
2734
  }
2690
2735
  };
2691
2736
  const setCurrentAgentState = (state) => {
@@ -2748,7 +2793,75 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2748
2793
  };
2749
2794
 
2750
2795
  // src/components/chat/Modal.tsx
2796
+ var import_react_core11 = require("@copilotkit/react-core");
2751
2797
  var import_jsx_runtime24 = require("react/jsx-runtime");
2798
+ var CopilotModalInner = (_a) => {
2799
+ var _b = _a, {
2800
+ observabilityHooks,
2801
+ onSetOpen,
2802
+ clickOutsideToClose,
2803
+ hitEscapeToClose,
2804
+ shortcut,
2805
+ className,
2806
+ children,
2807
+ Window: Window2,
2808
+ Button: Button2,
2809
+ Header: Header2
2810
+ } = _b, chatProps = __objRest(_b, [
2811
+ "observabilityHooks",
2812
+ "onSetOpen",
2813
+ "clickOutsideToClose",
2814
+ "hitEscapeToClose",
2815
+ "shortcut",
2816
+ "className",
2817
+ "children",
2818
+ "Window",
2819
+ "Button",
2820
+ "Header"
2821
+ ]);
2822
+ const { copilotApiConfig } = (0, import_react_core11.useCopilotContext)();
2823
+ const triggerObservabilityHook = (0, import_react15.useCallback)(
2824
+ (hookName, ...args) => {
2825
+ if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2826
+ observabilityHooks[hookName](...args);
2827
+ }
2828
+ },
2829
+ [copilotApiConfig.publicApiKey, observabilityHooks]
2830
+ );
2831
+ const { open } = useChatContext();
2832
+ const prevOpen = (0, import_react15.useRef)(open);
2833
+ (0, import_react15.useEffect)(() => {
2834
+ if (prevOpen.current !== open) {
2835
+ onSetOpen == null ? void 0 : onSetOpen(open);
2836
+ if (open) {
2837
+ triggerObservabilityHook("onChatExpanded");
2838
+ } else {
2839
+ triggerObservabilityHook("onChatMinimized");
2840
+ }
2841
+ prevOpen.current = open;
2842
+ }
2843
+ }, [open, onSetOpen, triggerObservabilityHook]);
2844
+ const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
2845
+ const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2846
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
2847
+ memoizedChildren,
2848
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2849
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2850
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2851
+ Window2,
2852
+ {
2853
+ clickOutsideToClose,
2854
+ shortcut,
2855
+ hitEscapeToClose,
2856
+ children: [
2857
+ memoizedHeader,
2858
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
2859
+ ]
2860
+ }
2861
+ )
2862
+ ] })
2863
+ ] });
2864
+ };
2752
2865
  var CopilotModal = (_a) => {
2753
2866
  var _b = _a, {
2754
2867
  instructions,
@@ -2777,7 +2890,8 @@ var CopilotModal = (_a) => {
2777
2890
  onRegenerate,
2778
2891
  markdownTagRenderers,
2779
2892
  className,
2780
- children
2893
+ children,
2894
+ observabilityHooks
2781
2895
  } = _b, props = __objRest(_b, [
2782
2896
  "instructions",
2783
2897
  "defaultOpen",
@@ -2805,52 +2919,41 @@ var CopilotModal = (_a) => {
2805
2919
  "onRegenerate",
2806
2920
  "markdownTagRenderers",
2807
2921
  "className",
2808
- "children"
2922
+ "children",
2923
+ "observabilityHooks"
2809
2924
  ]);
2810
2925
  const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
2811
- const setOpen = (open) => {
2812
- onSetOpen == null ? void 0 : onSetOpen(open);
2813
- setOpenState(open);
2814
- };
2815
- const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
2816
- const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2817
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen, children: [
2818
- memoizedChildren,
2819
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2820
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2821
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2822
- Window2,
2823
- {
2824
- clickOutsideToClose,
2825
- shortcut,
2826
- hitEscapeToClose,
2827
- children: [
2828
- memoizedHeader,
2829
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2830
- CopilotChat,
2831
- __spreadProps(__spreadValues({}, props), {
2832
- instructions,
2833
- onSubmitMessage,
2834
- onStopGeneration,
2835
- onReloadMessages,
2836
- makeSystemMessage,
2837
- onInProgress,
2838
- Messages: Messages2,
2839
- Input: Input2,
2840
- AssistantMessage: AssistantMessage2,
2841
- UserMessage: UserMessage2,
2842
- onThumbsUp,
2843
- onThumbsDown,
2844
- onCopy,
2845
- onRegenerate,
2846
- markdownTagRenderers
2847
- })
2848
- )
2849
- ]
2850
- }
2851
- )
2852
- ] })
2853
- ] });
2926
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2927
+ CopilotModalInner,
2928
+ __spreadProps(__spreadValues({
2929
+ observabilityHooks,
2930
+ onSetOpen,
2931
+ clickOutsideToClose: clickOutsideToClose != null ? clickOutsideToClose : true,
2932
+ hitEscapeToClose: hitEscapeToClose != null ? hitEscapeToClose : true,
2933
+ shortcut: shortcut != null ? shortcut : "/",
2934
+ className,
2935
+ Window: Window2,
2936
+ Button: Button2,
2937
+ Header: Header2,
2938
+ instructions,
2939
+ onSubmitMessage,
2940
+ onStopGeneration,
2941
+ onReloadMessages,
2942
+ makeSystemMessage,
2943
+ onInProgress,
2944
+ Messages: Messages2,
2945
+ Input: Input2,
2946
+ AssistantMessage: AssistantMessage2,
2947
+ UserMessage: UserMessage2,
2948
+ onThumbsUp,
2949
+ onThumbsDown,
2950
+ onCopy,
2951
+ onRegenerate,
2952
+ markdownTagRenderers
2953
+ }, props), {
2954
+ children
2955
+ })
2956
+ ) });
2854
2957
  };
2855
2958
  // Annotate the CommonJS export names for ESM import in node:
2856
2959
  0 && (module.exports = {