@copilotkit/react-ui 1.10.0-next.4 → 1.10.0-next.6

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 (48) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{chunk-WYEGK6BP.mjs → chunk-BXX6RM44.mjs} +2 -2
  3. package/dist/chunk-BXX6RM44.mjs.map +1 -0
  4. package/dist/chunk-BY42E5VF.mjs +203 -0
  5. package/dist/chunk-BY42E5VF.mjs.map +1 -0
  6. package/dist/{chunk-P6O2MZGT.mjs → chunk-K344MVUT.mjs} +58 -5
  7. package/dist/chunk-K344MVUT.mjs.map +1 -0
  8. package/dist/{chunk-2TABXABK.mjs → chunk-MYWIJSW6.mjs} +2 -2
  9. package/dist/chunk-MYWIJSW6.mjs.map +1 -0
  10. package/dist/components/chat/Chat.d.ts +10 -5
  11. package/dist/components/chat/Chat.js +54 -7
  12. package/dist/components/chat/Chat.js.map +1 -1
  13. package/dist/components/chat/Chat.mjs +1 -1
  14. package/dist/components/chat/Modal.d.ts +1 -1
  15. package/dist/components/chat/Modal.js +157 -52
  16. package/dist/components/chat/Modal.js.map +1 -1
  17. package/dist/components/chat/Modal.mjs +2 -2
  18. package/dist/components/chat/Popup.js +157 -52
  19. package/dist/components/chat/Popup.js.map +1 -1
  20. package/dist/components/chat/Popup.mjs +3 -3
  21. package/dist/components/chat/Sidebar.js +157 -52
  22. package/dist/components/chat/Sidebar.js.map +1 -1
  23. package/dist/components/chat/Sidebar.mjs +3 -3
  24. package/dist/components/chat/index.d.ts +1 -1
  25. package/dist/components/chat/index.js +157 -52
  26. package/dist/components/chat/index.js.map +1 -1
  27. package/dist/components/chat/index.mjs +4 -4
  28. package/dist/components/chat/props.d.ts +39 -1
  29. package/dist/components/chat/props.js.map +1 -1
  30. package/dist/components/index.d.ts +1 -1
  31. package/dist/components/index.js +157 -52
  32. package/dist/components/index.js.map +1 -1
  33. package/dist/components/index.mjs +4 -4
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.js +161 -56
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.mjs +4 -4
  38. package/package.json +4 -4
  39. package/src/components/chat/Chat.tsx +98 -4
  40. package/src/components/chat/Modal.tsx +107 -41
  41. package/src/components/chat/Popup.tsx +20 -0
  42. package/src/components/chat/Sidebar.tsx +22 -0
  43. package/src/components/chat/props.ts +46 -0
  44. package/dist/chunk-2TABXABK.mjs.map +0 -1
  45. package/dist/chunk-P6O2MZGT.mjs.map +0 -1
  46. package/dist/chunk-QKDRZ7WA.mjs +0 -144
  47. package/dist/chunk-QKDRZ7WA.mjs.map +0 -1
  48. package/dist/chunk-WYEGK6BP.mjs.map +0 -1
@@ -1,12 +1,12 @@
1
1
  import "../../chunk-SC6JRFAJ.mjs";
2
2
  import {
3
3
  CopilotSidebar
4
- } from "../../chunk-2TABXABK.mjs";
4
+ } from "../../chunk-MYWIJSW6.mjs";
5
5
  import "../../chunk-WB3YULQ4.mjs";
6
6
  import {
7
7
  CopilotPopup
8
- } from "../../chunk-WYEGK6BP.mjs";
9
- import "../../chunk-QKDRZ7WA.mjs";
8
+ } from "../../chunk-BXX6RM44.mjs";
9
+ import "../../chunk-BY42E5VF.mjs";
10
10
  import "../../chunk-C3GSYRC3.mjs";
11
11
  import "../../chunk-GDSZGYCE.mjs";
12
12
  import "../../chunk-V7W6IM2V.mjs";
@@ -19,7 +19,7 @@ import "../../chunk-BH6PCAAL.mjs";
19
19
  import "../../chunk-UFN2VWSR.mjs";
20
20
  import {
21
21
  CopilotChat
22
- } from "../../chunk-P6O2MZGT.mjs";
22
+ } from "../../chunk-K344MVUT.mjs";
23
23
  import "../../chunk-JHUTTP5C.mjs";
24
24
  import {
25
25
  AssistantMessage
@@ -2,6 +2,44 @@ import { Message, UserMessage, AIMessage, ImageData } from '@copilotkit/shared';
2
2
  import { CopilotChatSuggestion } from '../../types/suggestions.js';
3
3
  import { ReactNode } from 'react';
4
4
 
5
+ /**
6
+ * Event hooks for CopilotKit chat events.
7
+ * These hooks only work when publicApiKey is provided.
8
+ */
9
+ interface CopilotObservabilityHooks {
10
+ /**
11
+ * Called when a message is sent by the user
12
+ */
13
+ onMessageSent?: (message: string) => void;
14
+ /**
15
+ * Called when the chat is minimized/closed
16
+ */
17
+ onChatMinimized?: () => void;
18
+ /**
19
+ * Called when the chat is expanded/opened
20
+ */
21
+ onChatExpanded?: () => void;
22
+ /**
23
+ * Called when a message is regenerated
24
+ */
25
+ onMessageRegenerated?: (messageId: string) => void;
26
+ /**
27
+ * Called when a message is copied
28
+ */
29
+ onMessageCopied?: (content: string) => void;
30
+ /**
31
+ * Called when feedback is given (thumbs up/down)
32
+ */
33
+ onFeedbackGiven?: (messageId: string, type: "thumbsUp" | "thumbsDown") => void;
34
+ /**
35
+ * Called when chat generation starts
36
+ */
37
+ onChatStarted?: () => void;
38
+ /**
39
+ * Called when chat generation stops
40
+ */
41
+ onChatStopped?: () => void;
42
+ }
5
43
  interface ButtonProps {
6
44
  }
7
45
  interface WindowProps {
@@ -162,4 +200,4 @@ interface ImageRendererProps {
162
200
  className?: string;
163
201
  }
164
202
 
165
- export { AssistantMessageProps, ButtonProps, ComponentsMap, HeaderProps, ImageRendererProps, InputProps, MessagesProps, RenderMessageProps, RenderSuggestionsListProps, Renderer, SuggestionsProps, UserMessageProps, WindowProps };
203
+ export { AssistantMessageProps, ButtonProps, ComponentsMap, CopilotObservabilityHooks, HeaderProps, ImageRendererProps, InputProps, MessagesProps, RenderMessageProps, RenderSuggestionsListProps, Renderer, SuggestionsProps, UserMessageProps, WindowProps };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/chat/props.ts"],"sourcesContent":["import { AIMessage, Message, UserMessage } from \"@copilotkit/shared\";\nimport { CopilotChatSuggestion } from \"../../types/suggestions\";\nimport { ReactNode } from \"react\";\nimport { ImageData } from \"@copilotkit/shared\";\n\nexport interface ButtonProps {}\n\nexport interface WindowProps {\n clickOutsideToClose: boolean;\n hitEscapeToClose: boolean;\n shortcut: string;\n children?: React.ReactNode;\n}\n\nexport interface HeaderProps {}\n\nexport interface SuggestionsProps {\n title: string;\n message: string;\n partial?: boolean;\n className?: string;\n onClick: (message: string) => void;\n}\n\nexport type ComponentsMap<T extends Record<string, object> = Record<string, object>> = {\n [K in keyof T]: React.FC<{ children?: ReactNode } & T[K]>;\n};\n\nexport interface MessagesProps {\n messages: Message[];\n inProgress: boolean;\n children?: React.ReactNode;\n AssistantMessage: React.ComponentType<AssistantMessageProps>;\n UserMessage: React.ComponentType<UserMessageProps>;\n RenderMessage: React.ComponentType<RenderMessageProps>;\n ImageRenderer: React.ComponentType<ImageRendererProps>;\n\n /**\n * Callback function to regenerate the assistant's response\n */\n onRegenerate?: (messageId: string) => void;\n\n /**\n * Callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * Callback function for thumbs up feedback\n */\n onThumbsUp?: (message: Message) => void;\n\n /**\n * Callback function for thumbs down feedback\n */\n onThumbsDown?: (message: Message) => void;\n\n /**\n * A list of markdown components to render in assistant message.\n * Useful when you want to render custom elements in the message (e.g a reference tag element)\n */\n markdownTagRenderers?: ComponentsMap;\n}\n\nexport interface Renderer {\n content: string;\n}\n\nexport interface UserMessageProps {\n message?: UserMessage;\n ImageRenderer: React.ComponentType<ImageRendererProps>;\n}\n\nexport interface AssistantMessageProps {\n /**\n * The message content from the assistant\n */\n\n message?: AIMessage;\n\n /**\n * Indicates if this is the last message\n */\n isCurrentMessage?: boolean;\n\n /**\n * Whether a response is loading, this is when the LLM is thinking of a response but hasn't finished yet.\n */\n isLoading: boolean;\n\n /**\n * Whether a response is generating, this is when the LLM is actively generating and streaming content.\n */\n isGenerating: boolean;\n\n /**\n * Callback function to regenerate the assistant's response\n */\n onRegenerate?: () => void;\n\n /**\n * Callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * Callback function for thumbs up feedback\n */\n onThumbsUp?: (message: Message) => void;\n\n /**\n * Callback function for thumbs down feedback\n */\n onThumbsDown?: (message: Message) => void;\n\n /**\n * A list of markdown components to render in assistant message.\n * Useful when you want to render custom elements in the message (e.g a reference tag element)\n */\n markdownTagRenderers?: ComponentsMap;\n\n /**\n * A custom image rendering component to use instead of the default.\n */\n ImageRenderer?: React.ComponentType<ImageRendererProps>;\n}\n\nexport interface RenderMessageProps {\n message: Message;\n inProgress: boolean;\n index: number;\n isCurrentMessage: boolean;\n actionResult?: string;\n AssistantMessage?: React.ComponentType<AssistantMessageProps>;\n UserMessage?: React.ComponentType<UserMessageProps>;\n ImageRenderer?: React.ComponentType<ImageRendererProps>;\n\n /**\n * Callback function to regenerate the assistant's response\n */\n onRegenerate?: (messageId: string) => void;\n\n /**\n * Callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * Callback function for thumbs up feedback\n */\n onThumbsUp?: (message: Message) => void;\n\n /**\n * Callback function for thumbs down feedback\n */\n onThumbsDown?: (message: Message) => void;\n\n /**\n * A list of markdown components to render in assistant message.\n * Useful when you want to render custom elements in the message (e.g a reference tag element)\n */\n markdownTagRenderers?: ComponentsMap;\n}\n\nexport interface InputProps {\n inProgress: boolean;\n onSend: (text: string) => Promise<Message>;\n isVisible?: boolean;\n onStop?: () => void;\n onUpload?: () => void;\n hideStopButton?: boolean;\n}\n\nexport interface RenderSuggestionsListProps {\n suggestions: CopilotChatSuggestion[];\n onSuggestionClick: (message: string) => void;\n}\n\nexport interface ImageRendererProps {\n /**\n * The image data containing format and bytes\n */\n image: ImageData;\n\n /**\n * Optional content to display alongside the image\n */\n content?: string;\n\n /**\n * Additional CSS class name for styling\n */\n className?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/chat/props.ts"],"sourcesContent":["import { AIMessage, Message, UserMessage } from \"@copilotkit/shared\";\nimport { CopilotChatSuggestion } from \"../../types/suggestions\";\nimport { ReactNode } from \"react\";\nimport { ImageData } from \"@copilotkit/shared\";\n\n/**\n * Event hooks for CopilotKit chat events.\n * These hooks only work when publicApiKey is provided.\n */\nexport interface CopilotObservabilityHooks {\n /**\n * Called when a message is sent by the user\n */\n onMessageSent?: (message: string) => void;\n\n /**\n * Called when the chat is minimized/closed\n */\n onChatMinimized?: () => void;\n\n /**\n * Called when the chat is expanded/opened\n */\n onChatExpanded?: () => void;\n\n /**\n * Called when a message is regenerated\n */\n onMessageRegenerated?: (messageId: string) => void;\n\n /**\n * Called when a message is copied\n */\n onMessageCopied?: (content: string) => void;\n\n /**\n * Called when feedback is given (thumbs up/down)\n */\n onFeedbackGiven?: (messageId: string, type: \"thumbsUp\" | \"thumbsDown\") => void;\n\n /**\n * Called when chat generation starts\n */\n onChatStarted?: () => void;\n\n /**\n * Called when chat generation stops\n */\n onChatStopped?: () => void;\n}\n\nexport interface ButtonProps {}\n\nexport interface WindowProps {\n clickOutsideToClose: boolean;\n hitEscapeToClose: boolean;\n shortcut: string;\n children?: React.ReactNode;\n}\n\nexport interface HeaderProps {}\n\nexport interface SuggestionsProps {\n title: string;\n message: string;\n partial?: boolean;\n className?: string;\n onClick: (message: string) => void;\n}\n\nexport type ComponentsMap<T extends Record<string, object> = Record<string, object>> = {\n [K in keyof T]: React.FC<{ children?: ReactNode } & T[K]>;\n};\n\nexport interface MessagesProps {\n messages: Message[];\n inProgress: boolean;\n children?: React.ReactNode;\n AssistantMessage: React.ComponentType<AssistantMessageProps>;\n UserMessage: React.ComponentType<UserMessageProps>;\n RenderMessage: React.ComponentType<RenderMessageProps>;\n ImageRenderer: React.ComponentType<ImageRendererProps>;\n\n /**\n * Callback function to regenerate the assistant's response\n */\n onRegenerate?: (messageId: string) => void;\n\n /**\n * Callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * Callback function for thumbs up feedback\n */\n onThumbsUp?: (message: Message) => void;\n\n /**\n * Callback function for thumbs down feedback\n */\n onThumbsDown?: (message: Message) => void;\n\n /**\n * A list of markdown components to render in assistant message.\n * Useful when you want to render custom elements in the message (e.g a reference tag element)\n */\n markdownTagRenderers?: ComponentsMap;\n}\n\nexport interface Renderer {\n content: string;\n}\n\nexport interface UserMessageProps {\n message?: UserMessage;\n ImageRenderer: React.ComponentType<ImageRendererProps>;\n}\n\nexport interface AssistantMessageProps {\n /**\n * The message content from the assistant\n */\n\n message?: AIMessage;\n\n /**\n * Indicates if this is the last message\n */\n isCurrentMessage?: boolean;\n\n /**\n * Whether a response is loading, this is when the LLM is thinking of a response but hasn't finished yet.\n */\n isLoading: boolean;\n\n /**\n * Whether a response is generating, this is when the LLM is actively generating and streaming content.\n */\n isGenerating: boolean;\n\n /**\n * Callback function to regenerate the assistant's response\n */\n onRegenerate?: () => void;\n\n /**\n * Callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * Callback function for thumbs up feedback\n */\n onThumbsUp?: (message: Message) => void;\n\n /**\n * Callback function for thumbs down feedback\n */\n onThumbsDown?: (message: Message) => void;\n\n /**\n * A list of markdown components to render in assistant message.\n * Useful when you want to render custom elements in the message (e.g a reference tag element)\n */\n markdownTagRenderers?: ComponentsMap;\n\n /**\n * A custom image rendering component to use instead of the default.\n */\n ImageRenderer?: React.ComponentType<ImageRendererProps>;\n}\n\nexport interface RenderMessageProps {\n message: Message;\n inProgress: boolean;\n index: number;\n isCurrentMessage: boolean;\n actionResult?: string;\n AssistantMessage?: React.ComponentType<AssistantMessageProps>;\n UserMessage?: React.ComponentType<UserMessageProps>;\n ImageRenderer?: React.ComponentType<ImageRendererProps>;\n\n /**\n * Callback function to regenerate the assistant's response\n */\n onRegenerate?: (messageId: string) => void;\n\n /**\n * Callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * Callback function for thumbs up feedback\n */\n onThumbsUp?: (message: Message) => void;\n\n /**\n * Callback function for thumbs down feedback\n */\n onThumbsDown?: (message: Message) => void;\n\n /**\n * A list of markdown components to render in assistant message.\n * Useful when you want to render custom elements in the message (e.g a reference tag element)\n */\n markdownTagRenderers?: ComponentsMap;\n}\n\nexport interface InputProps {\n inProgress: boolean;\n onSend: (text: string) => Promise<Message>;\n isVisible?: boolean;\n onStop?: () => void;\n onUpload?: () => void;\n hideStopButton?: boolean;\n}\n\nexport interface RenderSuggestionsListProps {\n suggestions: CopilotChatSuggestion[];\n onSuggestionClick: (message: string) => void;\n}\n\nexport interface ImageRendererProps {\n /**\n * The image data containing format and bytes\n */\n image: ImageData;\n\n /**\n * Optional content to display alongside the image\n */\n content?: string;\n\n /**\n * Additional CSS class name for styling\n */\n className?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,4 +1,4 @@
1
- export { AssistantMessageProps, ButtonProps, ComponentsMap, HeaderProps, ImageRendererProps, InputProps, MessagesProps, RenderMessageProps, RenderSuggestionsListProps, Renderer, SuggestionsProps, UserMessageProps, WindowProps } from './chat/props.js';
1
+ export { AssistantMessageProps, ButtonProps, ComponentsMap, CopilotObservabilityHooks, HeaderProps, ImageRendererProps, InputProps, MessagesProps, RenderMessageProps, RenderSuggestionsListProps, Renderer, SuggestionsProps, UserMessageProps, WindowProps } from './chat/props.js';
2
2
  export { CopilotPopup } from './chat/Popup.js';
3
3
  export { CopilotSidebar } from './chat/Sidebar.js';
4
4
  export { CopilotChat } from './chat/Chat.js';
@@ -2179,6 +2179,7 @@ function RenderMessage(_a) {
2179
2179
  var import_react14 = __toESM(require("react"));
2180
2180
  var import_react_core9 = require("@copilotkit/react-core");
2181
2181
  var import_shared3 = require("@copilotkit/shared");
2182
+ var import_shared4 = require("@copilotkit/shared");
2182
2183
  var import_react_core10 = require("@copilotkit/react-core");
2183
2184
 
2184
2185
  // src/components/chat/ImageUploadQueue.tsx
@@ -2324,11 +2325,31 @@ function CopilotChat({
2324
2325
  ImageRenderer: ImageRenderer2 = ImageRenderer,
2325
2326
  imageUploadsEnabled,
2326
2327
  inputFileAccept = "image/*",
2327
- hideStopButton
2328
+ hideStopButton,
2329
+ observabilityHooks
2328
2330
  }) {
2329
- const { additionalInstructions, setChatInstructions } = (0, import_react_core9.useCopilotContext)();
2331
+ const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
2330
2332
  const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
2331
2333
  const fileInputRef = (0, import_react14.useRef)(null);
2334
+ const triggerObservabilityHook = (0, import_react14.useCallback)(
2335
+ (hookName, ...args) => {
2336
+ if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2337
+ observabilityHooks[hookName](...args);
2338
+ }
2339
+ if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !copilotApiConfig.publicApiKey) {
2340
+ setBannerError(
2341
+ new import_shared3.CopilotKitError({
2342
+ message: "observabilityHooks requires a publicApiKey to function.",
2343
+ code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
2344
+ severity: import_shared3.Severity.CRITICAL,
2345
+ visibility: import_shared3.ErrorVisibility.BANNER
2346
+ })
2347
+ );
2348
+ import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks");
2349
+ }
2350
+ },
2351
+ [copilotApiConfig.publicApiKey, observabilityHooks]
2352
+ );
2332
2353
  (0, import_react14.useEffect)(() => {
2333
2354
  if (!imageUploadsEnabled)
2334
2355
  return;
@@ -2401,12 +2422,24 @@ function CopilotChat({
2401
2422
  onStopGeneration,
2402
2423
  onReloadMessages
2403
2424
  );
2425
+ const prevIsLoading = (0, import_react14.useRef)(isLoading);
2426
+ (0, import_react14.useEffect)(() => {
2427
+ if (prevIsLoading.current !== isLoading) {
2428
+ if (isLoading) {
2429
+ triggerObservabilityHook("onChatStarted");
2430
+ } else {
2431
+ triggerObservabilityHook("onChatStopped");
2432
+ }
2433
+ prevIsLoading.current = isLoading;
2434
+ }
2435
+ }, [isLoading, triggerObservabilityHook]);
2404
2436
  const handleSendMessage = (text) => {
2405
2437
  const images = selectedImages;
2406
2438
  setSelectedImages([]);
2407
2439
  if (fileInputRef.current) {
2408
2440
  fileInputRef.current.value = "";
2409
2441
  }
2442
+ triggerObservabilityHook("onMessageSent", text);
2410
2443
  return sendMessage(text, images);
2411
2444
  };
2412
2445
  const chatContext = import_react14.default.useContext(ChatContext);
@@ -2415,12 +2448,14 @@ function CopilotChat({
2415
2448
  if (onRegenerate) {
2416
2449
  onRegenerate(messageId);
2417
2450
  }
2451
+ triggerObservabilityHook("onMessageRegenerated", messageId);
2418
2452
  reloadMessages(messageId);
2419
2453
  };
2420
2454
  const handleCopy = (message) => {
2421
2455
  if (onCopy) {
2422
2456
  onCopy(message);
2423
2457
  }
2458
+ triggerObservabilityHook("onMessageCopied", message);
2424
2459
  };
2425
2460
  const handleImageUpload = (event) => __async(this, null, function* () {
2426
2461
  if (!event.target.files || event.target.files.length === 0) {
@@ -2456,6 +2491,18 @@ function CopilotChat({
2456
2491
  const removeSelectedImage = (index) => {
2457
2492
  setSelectedImages((prev) => prev.filter((_, i) => i !== index));
2458
2493
  };
2494
+ const handleThumbsUp = (message) => {
2495
+ if (onThumbsUp) {
2496
+ onThumbsUp(message);
2497
+ }
2498
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
2499
+ };
2500
+ const handleThumbsDown = (message) => {
2501
+ if (onThumbsDown) {
2502
+ onThumbsDown(message);
2503
+ }
2504
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
2505
+ };
2459
2506
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2460
2507
  /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2461
2508
  Messages2,
@@ -2467,8 +2514,8 @@ function CopilotChat({
2467
2514
  inProgress: isLoading,
2468
2515
  onRegenerate: handleRegenerate,
2469
2516
  onCopy: handleCopy,
2470
- onThumbsUp,
2471
- onThumbsDown,
2517
+ onThumbsUp: handleThumbsUp,
2518
+ onThumbsDown: handleThumbsDown,
2472
2519
  markdownTagRenderers,
2473
2520
  ImageRenderer: ImageRenderer2,
2474
2521
  children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
@@ -2624,7 +2671,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2624
2671
  let firstMessage = null;
2625
2672
  if (messageContent.trim().length > 0) {
2626
2673
  const textMessage = {
2627
- id: (0, import_shared3.randomId)(),
2674
+ id: (0, import_shared4.randomId)(),
2628
2675
  role: "user",
2629
2676
  content: messageContent
2630
2677
  };
@@ -2646,7 +2693,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2646
2693
  if (images.length > 0) {
2647
2694
  for (let i = 0; i < images.length; i++) {
2648
2695
  const imageMessage = {
2649
- id: (0, import_shared3.randomId)(),
2696
+ id: (0, import_shared4.randomId)(),
2650
2697
  role: "user",
2651
2698
  image: {
2652
2699
  format: images[i].contentType.replace("image/", ""),
@@ -2660,7 +2707,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2660
2707
  }
2661
2708
  }
2662
2709
  if (!firstMessage) {
2663
- return { role: "user", content: "", id: (0, import_shared3.randomId)() };
2710
+ return { role: "user", content: "", id: (0, import_shared4.randomId)() };
2664
2711
  }
2665
2712
  return firstMessage;
2666
2713
  });
@@ -2759,7 +2806,75 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2759
2806
  };
2760
2807
 
2761
2808
  // src/components/chat/Modal.tsx
2809
+ var import_react_core11 = require("@copilotkit/react-core");
2762
2810
  var import_jsx_runtime24 = require("react/jsx-runtime");
2811
+ var CopilotModalInner = (_a) => {
2812
+ var _b = _a, {
2813
+ observabilityHooks,
2814
+ onSetOpen,
2815
+ clickOutsideToClose,
2816
+ hitEscapeToClose,
2817
+ shortcut,
2818
+ className,
2819
+ children,
2820
+ Window: Window2,
2821
+ Button: Button2,
2822
+ Header: Header2
2823
+ } = _b, chatProps = __objRest(_b, [
2824
+ "observabilityHooks",
2825
+ "onSetOpen",
2826
+ "clickOutsideToClose",
2827
+ "hitEscapeToClose",
2828
+ "shortcut",
2829
+ "className",
2830
+ "children",
2831
+ "Window",
2832
+ "Button",
2833
+ "Header"
2834
+ ]);
2835
+ const { copilotApiConfig } = (0, import_react_core11.useCopilotContext)();
2836
+ const triggerObservabilityHook = (0, import_react15.useCallback)(
2837
+ (hookName, ...args) => {
2838
+ if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2839
+ observabilityHooks[hookName](...args);
2840
+ }
2841
+ },
2842
+ [copilotApiConfig.publicApiKey, observabilityHooks]
2843
+ );
2844
+ const { open } = useChatContext();
2845
+ const prevOpen = (0, import_react15.useRef)(open);
2846
+ (0, import_react15.useEffect)(() => {
2847
+ if (prevOpen.current !== open) {
2848
+ onSetOpen == null ? void 0 : onSetOpen(open);
2849
+ if (open) {
2850
+ triggerObservabilityHook("onChatExpanded");
2851
+ } else {
2852
+ triggerObservabilityHook("onChatMinimized");
2853
+ }
2854
+ prevOpen.current = open;
2855
+ }
2856
+ }, [open, onSetOpen, triggerObservabilityHook]);
2857
+ const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
2858
+ const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2859
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
2860
+ memoizedChildren,
2861
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2862
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2863
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2864
+ Window2,
2865
+ {
2866
+ clickOutsideToClose,
2867
+ shortcut,
2868
+ hitEscapeToClose,
2869
+ children: [
2870
+ memoizedHeader,
2871
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
2872
+ ]
2873
+ }
2874
+ )
2875
+ ] })
2876
+ ] });
2877
+ };
2763
2878
  var CopilotModal = (_a) => {
2764
2879
  var _b = _a, {
2765
2880
  instructions,
@@ -2788,7 +2903,8 @@ var CopilotModal = (_a) => {
2788
2903
  onRegenerate,
2789
2904
  markdownTagRenderers,
2790
2905
  className,
2791
- children
2906
+ children,
2907
+ observabilityHooks
2792
2908
  } = _b, props = __objRest(_b, [
2793
2909
  "instructions",
2794
2910
  "defaultOpen",
@@ -2816,52 +2932,41 @@ var CopilotModal = (_a) => {
2816
2932
  "onRegenerate",
2817
2933
  "markdownTagRenderers",
2818
2934
  "className",
2819
- "children"
2935
+ "children",
2936
+ "observabilityHooks"
2820
2937
  ]);
2821
2938
  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
- ] });
2939
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2940
+ CopilotModalInner,
2941
+ __spreadProps(__spreadValues({
2942
+ observabilityHooks,
2943
+ onSetOpen,
2944
+ clickOutsideToClose: clickOutsideToClose != null ? clickOutsideToClose : true,
2945
+ hitEscapeToClose: hitEscapeToClose != null ? hitEscapeToClose : true,
2946
+ shortcut: shortcut != null ? shortcut : "/",
2947
+ className,
2948
+ Window: Window2,
2949
+ Button: Button2,
2950
+ Header: Header2,
2951
+ instructions,
2952
+ onSubmitMessage,
2953
+ onStopGeneration,
2954
+ onReloadMessages,
2955
+ makeSystemMessage,
2956
+ onInProgress,
2957
+ Messages: Messages2,
2958
+ Input: Input2,
2959
+ AssistantMessage: AssistantMessage2,
2960
+ UserMessage: UserMessage2,
2961
+ onThumbsUp,
2962
+ onThumbsDown,
2963
+ onCopy,
2964
+ onRegenerate,
2965
+ markdownTagRenderers
2966
+ }, props), {
2967
+ children
2968
+ })
2969
+ ) });
2865
2970
  };
2866
2971
 
2867
2972
  // src/components/chat/Popup.tsx