@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,7 +1,7 @@
1
1
  import {
2
2
  CopilotSidebar
3
- } from "../../chunk-2TABXABK.mjs";
4
- import "../../chunk-QKDRZ7WA.mjs";
3
+ } from "../../chunk-MYWIJSW6.mjs";
4
+ import "../../chunk-BY42E5VF.mjs";
5
5
  import "../../chunk-C3GSYRC3.mjs";
6
6
  import "../../chunk-GDSZGYCE.mjs";
7
7
  import "../../chunk-V7W6IM2V.mjs";
@@ -12,7 +12,7 @@ import "../../chunk-KXE2JCUH.mjs";
12
12
  import "../../chunk-NRA3CFEE.mjs";
13
13
  import "../../chunk-BH6PCAAL.mjs";
14
14
  import "../../chunk-UFN2VWSR.mjs";
15
- import "../../chunk-P6O2MZGT.mjs";
15
+ import "../../chunk-K344MVUT.mjs";
16
16
  import "../../chunk-JHUTTP5C.mjs";
17
17
  import "../../chunk-GCKKSSBU.mjs";
18
18
  import "../../chunk-DBKRAOH7.mjs";
@@ -1,4 +1,4 @@
1
- export { AssistantMessageProps, ButtonProps, ComponentsMap, HeaderProps, ImageRendererProps, InputProps, MessagesProps, RenderMessageProps, RenderSuggestionsListProps, Renderer, SuggestionsProps, UserMessageProps, WindowProps } from './props.js';
1
+ export { AssistantMessageProps, ButtonProps, ComponentsMap, CopilotObservabilityHooks, HeaderProps, ImageRendererProps, InputProps, MessagesProps, RenderMessageProps, RenderSuggestionsListProps, Renderer, SuggestionsProps, UserMessageProps, WindowProps } from './props.js';
2
2
  export { CopilotPopup } from './Popup.js';
3
3
  export { CopilotSidebar } from './Sidebar.js';
4
4
  export { CopilotChat } from './Chat.js';
@@ -2177,6 +2177,7 @@ function RenderMessage(_a) {
2177
2177
  var import_react14 = __toESM(require("react"));
2178
2178
  var import_react_core9 = require("@copilotkit/react-core");
2179
2179
  var import_shared3 = require("@copilotkit/shared");
2180
+ var import_shared4 = require("@copilotkit/shared");
2180
2181
  var import_react_core10 = require("@copilotkit/react-core");
2181
2182
 
2182
2183
  // src/components/chat/ImageUploadQueue.tsx
@@ -2322,11 +2323,31 @@ function CopilotChat({
2322
2323
  ImageRenderer: ImageRenderer2 = ImageRenderer,
2323
2324
  imageUploadsEnabled,
2324
2325
  inputFileAccept = "image/*",
2325
- hideStopButton
2326
+ hideStopButton,
2327
+ observabilityHooks
2326
2328
  }) {
2327
- const { additionalInstructions, setChatInstructions } = (0, import_react_core9.useCopilotContext)();
2329
+ const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
2328
2330
  const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
2329
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
+ );
2330
2351
  (0, import_react14.useEffect)(() => {
2331
2352
  if (!imageUploadsEnabled)
2332
2353
  return;
@@ -2399,12 +2420,24 @@ function CopilotChat({
2399
2420
  onStopGeneration,
2400
2421
  onReloadMessages
2401
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]);
2402
2434
  const handleSendMessage = (text) => {
2403
2435
  const images = selectedImages;
2404
2436
  setSelectedImages([]);
2405
2437
  if (fileInputRef.current) {
2406
2438
  fileInputRef.current.value = "";
2407
2439
  }
2440
+ triggerObservabilityHook("onMessageSent", text);
2408
2441
  return sendMessage(text, images);
2409
2442
  };
2410
2443
  const chatContext = import_react14.default.useContext(ChatContext);
@@ -2413,12 +2446,14 @@ function CopilotChat({
2413
2446
  if (onRegenerate) {
2414
2447
  onRegenerate(messageId);
2415
2448
  }
2449
+ triggerObservabilityHook("onMessageRegenerated", messageId);
2416
2450
  reloadMessages(messageId);
2417
2451
  };
2418
2452
  const handleCopy = (message) => {
2419
2453
  if (onCopy) {
2420
2454
  onCopy(message);
2421
2455
  }
2456
+ triggerObservabilityHook("onMessageCopied", message);
2422
2457
  };
2423
2458
  const handleImageUpload = (event) => __async(this, null, function* () {
2424
2459
  if (!event.target.files || event.target.files.length === 0) {
@@ -2454,6 +2489,18 @@ function CopilotChat({
2454
2489
  const removeSelectedImage = (index) => {
2455
2490
  setSelectedImages((prev) => prev.filter((_, i) => i !== index));
2456
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
+ };
2457
2504
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2458
2505
  /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2459
2506
  Messages2,
@@ -2465,8 +2512,8 @@ function CopilotChat({
2465
2512
  inProgress: isLoading,
2466
2513
  onRegenerate: handleRegenerate,
2467
2514
  onCopy: handleCopy,
2468
- onThumbsUp,
2469
- onThumbsDown,
2515
+ onThumbsUp: handleThumbsUp,
2516
+ onThumbsDown: handleThumbsDown,
2470
2517
  markdownTagRenderers,
2471
2518
  ImageRenderer: ImageRenderer2,
2472
2519
  children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
@@ -2622,7 +2669,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2622
2669
  let firstMessage = null;
2623
2670
  if (messageContent.trim().length > 0) {
2624
2671
  const textMessage = {
2625
- id: (0, import_shared3.randomId)(),
2672
+ id: (0, import_shared4.randomId)(),
2626
2673
  role: "user",
2627
2674
  content: messageContent
2628
2675
  };
@@ -2644,7 +2691,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2644
2691
  if (images.length > 0) {
2645
2692
  for (let i = 0; i < images.length; i++) {
2646
2693
  const imageMessage = {
2647
- id: (0, import_shared3.randomId)(),
2694
+ id: (0, import_shared4.randomId)(),
2648
2695
  role: "user",
2649
2696
  image: {
2650
2697
  format: images[i].contentType.replace("image/", ""),
@@ -2658,7 +2705,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2658
2705
  }
2659
2706
  }
2660
2707
  if (!firstMessage) {
2661
- return { role: "user", content: "", id: (0, import_shared3.randomId)() };
2708
+ return { role: "user", content: "", id: (0, import_shared4.randomId)() };
2662
2709
  }
2663
2710
  return firstMessage;
2664
2711
  });
@@ -2757,7 +2804,75 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2757
2804
  };
2758
2805
 
2759
2806
  // src/components/chat/Modal.tsx
2807
+ var import_react_core11 = require("@copilotkit/react-core");
2760
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
+ };
2761
2876
  var CopilotModal = (_a) => {
2762
2877
  var _b = _a, {
2763
2878
  instructions,
@@ -2786,7 +2901,8 @@ var CopilotModal = (_a) => {
2786
2901
  onRegenerate,
2787
2902
  markdownTagRenderers,
2788
2903
  className,
2789
- children
2904
+ children,
2905
+ observabilityHooks
2790
2906
  } = _b, props = __objRest(_b, [
2791
2907
  "instructions",
2792
2908
  "defaultOpen",
@@ -2814,52 +2930,41 @@ var CopilotModal = (_a) => {
2814
2930
  "onRegenerate",
2815
2931
  "markdownTagRenderers",
2816
2932
  "className",
2817
- "children"
2933
+ "children",
2934
+ "observabilityHooks"
2818
2935
  ]);
2819
2936
  const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
2820
- const setOpen = (open) => {
2821
- onSetOpen == null ? void 0 : onSetOpen(open);
2822
- setOpenState(open);
2823
- };
2824
- const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
2825
- const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2826
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen, children: [
2827
- memoizedChildren,
2828
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2829
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2830
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2831
- Window2,
2832
- {
2833
- clickOutsideToClose,
2834
- shortcut,
2835
- hitEscapeToClose,
2836
- children: [
2837
- memoizedHeader,
2838
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2839
- CopilotChat,
2840
- __spreadProps(__spreadValues({}, props), {
2841
- instructions,
2842
- onSubmitMessage,
2843
- onStopGeneration,
2844
- onReloadMessages,
2845
- makeSystemMessage,
2846
- onInProgress,
2847
- Messages: Messages2,
2848
- Input: Input2,
2849
- AssistantMessage: AssistantMessage2,
2850
- UserMessage: UserMessage2,
2851
- onThumbsUp,
2852
- onThumbsDown,
2853
- onCopy,
2854
- onRegenerate,
2855
- markdownTagRenderers
2856
- })
2857
- )
2858
- ]
2859
- }
2860
- )
2861
- ] })
2862
- ] });
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
+ ) });
2863
2968
  };
2864
2969
 
2865
2970
  // src/components/chat/Popup.tsx