@copilotkit/react-ui 1.10.0-next.4 → 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 (48) hide show
  1. package/CHANGELOG.md +10 -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,12 +2,12 @@ import "../chunk-MMVDU6DF.mjs";
2
2
  import "../chunk-SC6JRFAJ.mjs";
3
3
  import {
4
4
  CopilotSidebar
5
- } from "../chunk-2TABXABK.mjs";
5
+ } from "../chunk-MYWIJSW6.mjs";
6
6
  import "../chunk-WB3YULQ4.mjs";
7
7
  import {
8
8
  CopilotPopup
9
- } from "../chunk-WYEGK6BP.mjs";
10
- import "../chunk-QKDRZ7WA.mjs";
9
+ } from "../chunk-BXX6RM44.mjs";
10
+ import "../chunk-BY42E5VF.mjs";
11
11
  import "../chunk-C3GSYRC3.mjs";
12
12
  import "../chunk-GDSZGYCE.mjs";
13
13
  import "../chunk-V7W6IM2V.mjs";
@@ -24,7 +24,7 @@ import "../chunk-BH6PCAAL.mjs";
24
24
  import "../chunk-UFN2VWSR.mjs";
25
25
  import {
26
26
  CopilotChat
27
- } from "../chunk-P6O2MZGT.mjs";
27
+ } from "../chunk-K344MVUT.mjs";
28
28
  import "../chunk-JHUTTP5C.mjs";
29
29
  import {
30
30
  AssistantMessage
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AssistantMessageProps, ButtonProps, ComponentsMap, HeaderProps, ImageRendererProps, InputProps, MessagesProps, RenderMessageProps, RenderSuggestionsListProps, Renderer, SuggestionsProps, UserMessageProps, WindowProps } from './components/chat/props.js';
1
+ export { AssistantMessageProps, ButtonProps, ComponentsMap, CopilotObservabilityHooks, HeaderProps, ImageRendererProps, InputProps, MessagesProps, RenderMessageProps, RenderSuggestionsListProps, Renderer, SuggestionsProps, UserMessageProps, WindowProps } from './components/chat/props.js';
2
2
  export { CopilotPopup } from './components/chat/Popup.js';
3
3
  export { CopilotSidebar } from './components/chat/Sidebar.js';
4
4
  export { CopilotChat } from './components/chat/Chat.js';
package/dist/index.js CHANGED
@@ -2181,6 +2181,7 @@ function RenderMessage(_a) {
2181
2181
  var import_react14 = __toESM(require("react"));
2182
2182
  var import_react_core9 = require("@copilotkit/react-core");
2183
2183
  var import_shared3 = require("@copilotkit/shared");
2184
+ var import_shared4 = require("@copilotkit/shared");
2184
2185
  var import_react_core10 = require("@copilotkit/react-core");
2185
2186
 
2186
2187
  // src/components/chat/ImageUploadQueue.tsx
@@ -2326,11 +2327,31 @@ function CopilotChat({
2326
2327
  ImageRenderer: ImageRenderer2 = ImageRenderer,
2327
2328
  imageUploadsEnabled,
2328
2329
  inputFileAccept = "image/*",
2329
- hideStopButton
2330
+ hideStopButton,
2331
+ observabilityHooks
2330
2332
  }) {
2331
- const { additionalInstructions, setChatInstructions } = (0, import_react_core9.useCopilotContext)();
2333
+ const { additionalInstructions, setChatInstructions, copilotApiConfig, setBannerError } = (0, import_react_core9.useCopilotContext)();
2332
2334
  const [selectedImages, setSelectedImages] = (0, import_react14.useState)([]);
2333
2335
  const fileInputRef = (0, import_react14.useRef)(null);
2336
+ const triggerObservabilityHook = (0, import_react14.useCallback)(
2337
+ (hookName, ...args) => {
2338
+ if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2339
+ observabilityHooks[hookName](...args);
2340
+ }
2341
+ if ((observabilityHooks == null ? void 0 : observabilityHooks[hookName]) && !copilotApiConfig.publicApiKey) {
2342
+ setBannerError(
2343
+ new import_shared3.CopilotKitError({
2344
+ message: "observabilityHooks requires a publicApiKey to function.",
2345
+ code: import_shared3.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
2346
+ severity: import_shared3.Severity.CRITICAL,
2347
+ visibility: import_shared3.ErrorVisibility.BANNER
2348
+ })
2349
+ );
2350
+ import_shared3.styledConsole.publicApiKeyRequired("observabilityHooks");
2351
+ }
2352
+ },
2353
+ [copilotApiConfig.publicApiKey, observabilityHooks]
2354
+ );
2334
2355
  (0, import_react14.useEffect)(() => {
2335
2356
  if (!imageUploadsEnabled)
2336
2357
  return;
@@ -2403,12 +2424,24 @@ function CopilotChat({
2403
2424
  onStopGeneration,
2404
2425
  onReloadMessages
2405
2426
  );
2427
+ const prevIsLoading = (0, import_react14.useRef)(isLoading);
2428
+ (0, import_react14.useEffect)(() => {
2429
+ if (prevIsLoading.current !== isLoading) {
2430
+ if (isLoading) {
2431
+ triggerObservabilityHook("onChatStarted");
2432
+ } else {
2433
+ triggerObservabilityHook("onChatStopped");
2434
+ }
2435
+ prevIsLoading.current = isLoading;
2436
+ }
2437
+ }, [isLoading, triggerObservabilityHook]);
2406
2438
  const handleSendMessage = (text) => {
2407
2439
  const images = selectedImages;
2408
2440
  setSelectedImages([]);
2409
2441
  if (fileInputRef.current) {
2410
2442
  fileInputRef.current.value = "";
2411
2443
  }
2444
+ triggerObservabilityHook("onMessageSent", text);
2412
2445
  return sendMessage(text, images);
2413
2446
  };
2414
2447
  const chatContext = import_react14.default.useContext(ChatContext);
@@ -2417,12 +2450,14 @@ function CopilotChat({
2417
2450
  if (onRegenerate) {
2418
2451
  onRegenerate(messageId);
2419
2452
  }
2453
+ triggerObservabilityHook("onMessageRegenerated", messageId);
2420
2454
  reloadMessages(messageId);
2421
2455
  };
2422
2456
  const handleCopy = (message) => {
2423
2457
  if (onCopy) {
2424
2458
  onCopy(message);
2425
2459
  }
2460
+ triggerObservabilityHook("onMessageCopied", message);
2426
2461
  };
2427
2462
  const handleImageUpload = (event) => __async(this, null, function* () {
2428
2463
  if (!event.target.files || event.target.files.length === 0) {
@@ -2458,6 +2493,18 @@ function CopilotChat({
2458
2493
  const removeSelectedImage = (index) => {
2459
2494
  setSelectedImages((prev) => prev.filter((_, i) => i !== index));
2460
2495
  };
2496
+ const handleThumbsUp = (message) => {
2497
+ if (onThumbsUp) {
2498
+ onThumbsUp(message);
2499
+ }
2500
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsUp");
2501
+ };
2502
+ const handleThumbsDown = (message) => {
2503
+ if (onThumbsDown) {
2504
+ onThumbsDown(message);
2505
+ }
2506
+ triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
2507
+ };
2461
2508
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2462
2509
  /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2463
2510
  Messages2,
@@ -2469,8 +2516,8 @@ function CopilotChat({
2469
2516
  inProgress: isLoading,
2470
2517
  onRegenerate: handleRegenerate,
2471
2518
  onCopy: handleCopy,
2472
- onThumbsUp,
2473
- onThumbsDown,
2519
+ onThumbsUp: handleThumbsUp,
2520
+ onThumbsDown: handleThumbsDown,
2474
2521
  markdownTagRenderers,
2475
2522
  ImageRenderer: ImageRenderer2,
2476
2523
  children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
@@ -2626,7 +2673,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2626
2673
  let firstMessage = null;
2627
2674
  if (messageContent.trim().length > 0) {
2628
2675
  const textMessage = {
2629
- id: (0, import_shared3.randomId)(),
2676
+ id: (0, import_shared4.randomId)(),
2630
2677
  role: "user",
2631
2678
  content: messageContent
2632
2679
  };
@@ -2648,7 +2695,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2648
2695
  if (images.length > 0) {
2649
2696
  for (let i = 0; i < images.length; i++) {
2650
2697
  const imageMessage = {
2651
- id: (0, import_shared3.randomId)(),
2698
+ id: (0, import_shared4.randomId)(),
2652
2699
  role: "user",
2653
2700
  image: {
2654
2701
  format: images[i].contentType.replace("image/", ""),
@@ -2662,7 +2709,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2662
2709
  }
2663
2710
  }
2664
2711
  if (!firstMessage) {
2665
- return { role: "user", content: "", id: (0, import_shared3.randomId)() };
2712
+ return { role: "user", content: "", id: (0, import_shared4.randomId)() };
2666
2713
  }
2667
2714
  return firstMessage;
2668
2715
  });
@@ -2761,7 +2808,75 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, onInProgress, onS
2761
2808
  };
2762
2809
 
2763
2810
  // src/components/chat/Modal.tsx
2811
+ var import_react_core11 = require("@copilotkit/react-core");
2764
2812
  var import_jsx_runtime24 = require("react/jsx-runtime");
2813
+ var CopilotModalInner = (_a) => {
2814
+ var _b = _a, {
2815
+ observabilityHooks,
2816
+ onSetOpen,
2817
+ clickOutsideToClose,
2818
+ hitEscapeToClose,
2819
+ shortcut,
2820
+ className,
2821
+ children,
2822
+ Window: Window2,
2823
+ Button: Button2,
2824
+ Header: Header2
2825
+ } = _b, chatProps = __objRest(_b, [
2826
+ "observabilityHooks",
2827
+ "onSetOpen",
2828
+ "clickOutsideToClose",
2829
+ "hitEscapeToClose",
2830
+ "shortcut",
2831
+ "className",
2832
+ "children",
2833
+ "Window",
2834
+ "Button",
2835
+ "Header"
2836
+ ]);
2837
+ const { copilotApiConfig } = (0, import_react_core11.useCopilotContext)();
2838
+ const triggerObservabilityHook = (0, import_react15.useCallback)(
2839
+ (hookName, ...args) => {
2840
+ if (copilotApiConfig.publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
2841
+ observabilityHooks[hookName](...args);
2842
+ }
2843
+ },
2844
+ [copilotApiConfig.publicApiKey, observabilityHooks]
2845
+ );
2846
+ const { open } = useChatContext();
2847
+ const prevOpen = (0, import_react15.useRef)(open);
2848
+ (0, import_react15.useEffect)(() => {
2849
+ if (prevOpen.current !== open) {
2850
+ onSetOpen == null ? void 0 : onSetOpen(open);
2851
+ if (open) {
2852
+ triggerObservabilityHook("onChatExpanded");
2853
+ } else {
2854
+ triggerObservabilityHook("onChatMinimized");
2855
+ }
2856
+ prevOpen.current = open;
2857
+ }
2858
+ }, [open, onSetOpen, triggerObservabilityHook]);
2859
+ const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
2860
+ const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2861
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
2862
+ memoizedChildren,
2863
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2864
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2865
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2866
+ Window2,
2867
+ {
2868
+ clickOutsideToClose,
2869
+ shortcut,
2870
+ hitEscapeToClose,
2871
+ children: [
2872
+ memoizedHeader,
2873
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(CopilotChat, __spreadProps(__spreadValues({}, chatProps), { observabilityHooks }))
2874
+ ]
2875
+ }
2876
+ )
2877
+ ] })
2878
+ ] });
2879
+ };
2765
2880
  var CopilotModal = (_a) => {
2766
2881
  var _b = _a, {
2767
2882
  instructions,
@@ -2790,7 +2905,8 @@ var CopilotModal = (_a) => {
2790
2905
  onRegenerate,
2791
2906
  markdownTagRenderers,
2792
2907
  className,
2793
- children
2908
+ children,
2909
+ observabilityHooks
2794
2910
  } = _b, props = __objRest(_b, [
2795
2911
  "instructions",
2796
2912
  "defaultOpen",
@@ -2818,52 +2934,41 @@ var CopilotModal = (_a) => {
2818
2934
  "onRegenerate",
2819
2935
  "markdownTagRenderers",
2820
2936
  "className",
2821
- "children"
2937
+ "children",
2938
+ "observabilityHooks"
2822
2939
  ]);
2823
2940
  const [openState, setOpenState] = import_react15.default.useState(defaultOpen);
2824
- const setOpen = (open) => {
2825
- onSetOpen == null ? void 0 : onSetOpen(open);
2826
- setOpenState(open);
2827
- };
2828
- const memoizedHeader = (0, import_react15.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Header2, {}), [Header2]);
2829
- const memoizedChildren = (0, import_react15.useMemo)(() => children, [children]);
2830
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(ChatContextProvider, { icons, labels, open: openState, setOpen, children: [
2831
- memoizedChildren,
2832
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className, children: [
2833
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Button2, {}),
2834
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2835
- Window2,
2836
- {
2837
- clickOutsideToClose,
2838
- shortcut,
2839
- hitEscapeToClose,
2840
- children: [
2841
- memoizedHeader,
2842
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2843
- CopilotChat,
2844
- __spreadProps(__spreadValues({}, props), {
2845
- instructions,
2846
- onSubmitMessage,
2847
- onStopGeneration,
2848
- onReloadMessages,
2849
- makeSystemMessage,
2850
- onInProgress,
2851
- Messages: Messages2,
2852
- Input: Input2,
2853
- AssistantMessage: AssistantMessage2,
2854
- UserMessage: UserMessage2,
2855
- onThumbsUp,
2856
- onThumbsDown,
2857
- onCopy,
2858
- onRegenerate,
2859
- markdownTagRenderers
2860
- })
2861
- )
2862
- ]
2863
- }
2864
- )
2865
- ] })
2866
- ] });
2941
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ChatContextProvider, { icons, labels, open: openState, setOpen: setOpenState, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2942
+ CopilotModalInner,
2943
+ __spreadProps(__spreadValues({
2944
+ observabilityHooks,
2945
+ onSetOpen,
2946
+ clickOutsideToClose: clickOutsideToClose != null ? clickOutsideToClose : true,
2947
+ hitEscapeToClose: hitEscapeToClose != null ? hitEscapeToClose : true,
2948
+ shortcut: shortcut != null ? shortcut : "/",
2949
+ className,
2950
+ Window: Window2,
2951
+ Button: Button2,
2952
+ Header: Header2,
2953
+ instructions,
2954
+ onSubmitMessage,
2955
+ onStopGeneration,
2956
+ onReloadMessages,
2957
+ makeSystemMessage,
2958
+ onInProgress,
2959
+ Messages: Messages2,
2960
+ Input: Input2,
2961
+ AssistantMessage: AssistantMessage2,
2962
+ UserMessage: UserMessage2,
2963
+ onThumbsUp,
2964
+ onThumbsDown,
2965
+ onCopy,
2966
+ onRegenerate,
2967
+ markdownTagRenderers
2968
+ }, props), {
2969
+ children
2970
+ })
2971
+ ) });
2867
2972
  };
2868
2973
 
2869
2974
  // src/components/chat/Popup.tsx
@@ -2895,8 +3000,8 @@ function CopilotSidebar(props) {
2895
3000
 
2896
3001
  // src/hooks/use-copilot-chat-suggestions.tsx
2897
3002
  var import_react17 = require("react");
2898
- var import_react_core11 = require("@copilotkit/react-core");
2899
- var import_shared4 = require("@copilotkit/shared");
3003
+ var import_react_core12 = require("@copilotkit/react-core");
3004
+ var import_shared5 = require("@copilotkit/shared");
2900
3005
  function useCopilotChatSuggestions({
2901
3006
  available = "enabled",
2902
3007
  instructions,
@@ -2904,11 +3009,11 @@ function useCopilotChatSuggestions({
2904
3009
  minSuggestions = 1,
2905
3010
  maxSuggestions = 3
2906
3011
  }, dependencies = []) {
2907
- const context = (0, import_react_core11.useCopilotContext)();
3012
+ const context = (0, import_react_core12.useCopilotContext)();
2908
3013
  (0, import_react17.useEffect)(() => {
2909
3014
  if (available === "disabled")
2910
3015
  return;
2911
- const id = (0, import_shared4.randomId)();
3016
+ const id = (0, import_shared5.randomId)();
2912
3017
  context.addChatSuggestionConfiguration(id, {
2913
3018
  instructions,
2914
3019
  minSuggestions,