@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
@@ -2,7 +2,7 @@ import {
2
2
  CopilotChat,
3
3
  WrappedCopilotChat,
4
4
  useCopilotChatLogic
5
- } from "../../chunk-P6O2MZGT.mjs";
5
+ } from "../../chunk-K344MVUT.mjs";
6
6
  import "../../chunk-JHUTTP5C.mjs";
7
7
  import "../../chunk-GCKKSSBU.mjs";
8
8
  import "../../chunk-DBKRAOH7.mjs";
@@ -51,6 +51,6 @@ interface CopilotModalProps extends CopilotChatProps {
51
51
  */
52
52
  Header?: React__default.ComponentType<HeaderProps>;
53
53
  }
54
- declare const CopilotModal: ({ instructions, defaultOpen, clickOutsideToClose, hitEscapeToClose, onSetOpen, onSubmitMessage, onStopGeneration, onReloadMessages, shortcut, icons, labels, makeSystemMessage, onInProgress, Window, Button, Header, Messages, Input, AssistantMessage, UserMessage, onThumbsUp, onThumbsDown, onCopy, onRegenerate, markdownTagRenderers, className, children, ...props }: CopilotModalProps) => react_jsx_runtime.JSX.Element;
54
+ declare const CopilotModal: ({ instructions, defaultOpen, clickOutsideToClose, hitEscapeToClose, onSetOpen, onSubmitMessage, onStopGeneration, onReloadMessages, shortcut, icons, labels, makeSystemMessage, onInProgress, Window, Button, Header, Messages, Input, AssistantMessage, UserMessage, onThumbsUp, onThumbsDown, onCopy, onRegenerate, markdownTagRenderers, className, children, observabilityHooks, ...props }: CopilotModalProps) => react_jsx_runtime.JSX.Element;
55
55
 
56
56
  export { CopilotModal, CopilotModalProps };
@@ -2166,6 +2166,7 @@ function RenderMessage(_a) {
2166
2166
  var import_react14 = __toESM(require("react"));
2167
2167
  var import_react_core9 = require("@copilotkit/react-core");
2168
2168
  var import_shared3 = require("@copilotkit/shared");
2169
+ var import_shared4 = require("@copilotkit/shared");
2169
2170
  var import_react_core10 = require("@copilotkit/react-core");
2170
2171
 
2171
2172
  // src/components/chat/ImageUploadQueue.tsx
@@ -2311,11 +2312,31 @@ function CopilotChat({
2311
2312
  ImageRenderer: ImageRenderer2 = ImageRenderer,
2312
2313
  imageUploadsEnabled,
2313
2314
  inputFileAccept = "image/*",
2314
- hideStopButton
2315
+ hideStopButton,
2316
+ observabilityHooks
2315
2317
  }) {
2316
- const { additionalInstructions, setChatInstructions } = (0, import_react_core9.useCopilotContext)();
2318
+ const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
2317
2319
  const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
2318
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
+ );
2319
2340
  (0, import_react14.useEffect)(() => {
2320
2341
  if (!imageUploadsEnabled)
2321
2342
  return;
@@ -2388,12 +2409,24 @@ function CopilotChat({
2388
2409
  onStopGeneration,
2389
2410
  onReloadMessages
2390
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]);
2391
2423
  const handleSendMessage = (text) => {
2392
2424
  const images = selectedImages;
2393
2425
  setSelectedImages([]);
2394
2426
  if (fileInputRef.current) {
2395
2427
  fileInputRef.current.value = "";
2396
2428
  }
2429
+ triggerObservabilityHook("onMessageSent", text);
2397
2430
  return sendMessage(text, images);
2398
2431
  };
2399
2432
  const chatContext = import_react14.default.useContext(ChatContext);
@@ -2402,12 +2435,14 @@ function CopilotChat({
2402
2435
  if (onRegenerate) {
2403
2436
  onRegenerate(messageId);
2404
2437
  }
2438
+ triggerObservabilityHook("onMessageRegenerated", messageId);
2405
2439
  reloadMessages(messageId);
2406
2440
  };
2407
2441
  const handleCopy = (message) => {
2408
2442
  if (onCopy) {
2409
2443
  onCopy(message);
2410
2444
  }
2445
+ triggerObservabilityHook("onMessageCopied", message);
2411
2446
  };
2412
2447
  const handleImageUpload = (event) => __async(this, null, function* () {
2413
2448
  if (!event.target.files || event.target.files.length === 0) {
@@ -2443,6 +2478,18 @@ function CopilotChat({
2443
2478
  const removeSelectedImage = (index) => {
2444
2479
  setSelectedImages((prev) => prev.filter((_, i) => i !== index));
2445
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
+ };
2446
2493
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2447
2494
  /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2448
2495
  Messages2,
@@ -2454,8 +2501,8 @@ function CopilotChat({
2454
2501
  inProgress: isLoading,
2455
2502
  onRegenerate: handleRegenerate,
2456
2503
  onCopy: handleCopy,
2457
- onThumbsUp,
2458
- onThumbsDown,
2504
+ onThumbsUp: handleThumbsUp,
2505
+ onThumbsDown: handleThumbsDown,
2459
2506
  markdownTagRenderers,
2460
2507
  ImageRenderer: ImageRenderer2,
2461
2508
  children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
@@ -2611,7 +2658,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2611
2658
  let firstMessage = null;
2612
2659
  if (messageContent.trim().length > 0) {
2613
2660
  const textMessage = {
2614
- id: (0, import_shared3.randomId)(),
2661
+ id: (0, import_shared4.randomId)(),
2615
2662
  role: "user",
2616
2663
  content: messageContent
2617
2664
  };
@@ -2633,7 +2680,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2633
2680
  if (images.length > 0) {
2634
2681
  for (let i = 0; i < images.length; i++) {
2635
2682
  const imageMessage = {
2636
- id: (0, import_shared3.randomId)(),
2683
+ id: (0, import_shared4.randomId)(),
2637
2684
  role: "user",
2638
2685
  image: {
2639
2686
  format: images[i].contentType.replace("image/", ""),
@@ -2647,7 +2694,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2647
2694
  }
2648
2695
  }
2649
2696
  if (!firstMessage) {
2650
- return { role: "user", content: "", id: (0, import_shared3.randomId)() };
2697
+ return { role: "user", content: "", id: (0, import_shared4.randomId)() };
2651
2698
  }
2652
2699
  return firstMessage;
2653
2700
  });
@@ -2746,7 +2793,75 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2746
2793
  };
2747
2794
 
2748
2795
  // src/components/chat/Modal.tsx
2796
+ var import_react_core11 = require("@copilotkit/react-core");
2749
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
+ };
2750
2865
  var CopilotModal = (_a) => {
2751
2866
  var _b = _a, {
2752
2867
  instructions,
@@ -2775,7 +2890,8 @@ var CopilotModal = (_a) => {
2775
2890
  onRegenerate,
2776
2891
  markdownTagRenderers,
2777
2892
  className,
2778
- children
2893
+ children,
2894
+ observabilityHooks
2779
2895
  } = _b, props = __objRest(_b, [
2780
2896
  "instructions",
2781
2897
  "defaultOpen",
@@ -2803,52 +2919,41 @@ var CopilotModal = (_a) => {
2803
2919
  "onRegenerate",
2804
2920
  "markdownTagRenderers",
2805
2921
  "className",
2806
- "children"
2922
+ "children",
2923
+ "observabilityHooks"
2807
2924
  ]);
2808
2925
  const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
2809
- const setOpen = (open) => {
2810
- onSetOpen == null ? void 0 : onSetOpen(open);
2811
- setOpenState(open);
2812
- };
2813
- const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
2814
- const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2815
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen, children: [
2816
- memoizedChildren,
2817
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2818
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2819
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2820
- Window2,
2821
- {
2822
- clickOutsideToClose,
2823
- shortcut,
2824
- hitEscapeToClose,
2825
- children: [
2826
- memoizedHeader,
2827
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2828
- CopilotChat,
2829
- __spreadProps(__spreadValues({}, props), {
2830
- instructions,
2831
- onSubmitMessage,
2832
- onStopGeneration,
2833
- onReloadMessages,
2834
- makeSystemMessage,
2835
- onInProgress,
2836
- Messages: Messages2,
2837
- Input: Input2,
2838
- AssistantMessage: AssistantMessage2,
2839
- UserMessage: UserMessage2,
2840
- onThumbsUp,
2841
- onThumbsDown,
2842
- onCopy,
2843
- onRegenerate,
2844
- markdownTagRenderers
2845
- })
2846
- )
2847
- ]
2848
- }
2849
- )
2850
- ] })
2851
- ] });
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
+ ) });
2852
2957
  };
2853
2958
  // Annotate the CommonJS export names for ESM import in node:
2854
2959
  0 && (module.exports = {