@copilotkit/react-ui 1.3.16-mme-reset-chat.10 → 1.3.16-mme-revert-rxjs-changes.10

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 (45) hide show
  1. package/CHANGELOG.md +9 -53
  2. package/dist/{chunk-H7LLXN6X.mjs → chunk-H5CXJBR5.mjs} +3 -7
  3. package/dist/chunk-H5CXJBR5.mjs.map +1 -0
  4. package/dist/{chunk-P54DK2TL.mjs → chunk-M2NVAJQA.mjs} +2 -2
  5. package/dist/{chunk-3QOICFXX.mjs → chunk-ORHE7FYT.mjs} +8 -104
  6. package/dist/chunk-ORHE7FYT.mjs.map +1 -0
  7. package/dist/{chunk-SEY3XSCD.mjs → chunk-PY7YBFPA.mjs} +2 -2
  8. package/dist/{chunk-CPMIEVKK.mjs → chunk-RKPANT3F.mjs} +65 -15
  9. package/dist/chunk-RKPANT3F.mjs.map +1 -0
  10. package/dist/components/chat/Chat.d.ts +5 -50
  11. package/dist/components/chat/Chat.js +68 -114
  12. package/dist/components/chat/Chat.js.map +1 -1
  13. package/dist/components/chat/Chat.mjs +2 -2
  14. package/dist/components/chat/Messages.d.ts +6 -1
  15. package/dist/components/chat/Messages.js +66 -15
  16. package/dist/components/chat/Messages.js.map +1 -1
  17. package/dist/components/chat/Messages.mjs +5 -3
  18. package/dist/components/chat/Modal.d.ts +1 -1
  19. package/dist/components/chat/Modal.js +68 -118
  20. package/dist/components/chat/Modal.js.map +1 -1
  21. package/dist/components/chat/Modal.mjs +3 -3
  22. package/dist/components/chat/Popup.js +68 -118
  23. package/dist/components/chat/Popup.js.map +1 -1
  24. package/dist/components/chat/Popup.mjs +4 -4
  25. package/dist/components/chat/Sidebar.js +68 -118
  26. package/dist/components/chat/Sidebar.js.map +1 -1
  27. package/dist/components/chat/Sidebar.mjs +4 -4
  28. package/dist/components/chat/index.js +68 -118
  29. package/dist/components/chat/index.js.map +1 -1
  30. package/dist/components/chat/index.mjs +5 -5
  31. package/dist/components/index.js +68 -118
  32. package/dist/components/index.js.map +1 -1
  33. package/dist/components/index.mjs +5 -5
  34. package/dist/index.js +70 -120
  35. package/dist/index.js.map +1 -1
  36. package/dist/index.mjs +5 -5
  37. package/package.json +7 -7
  38. package/src/components/chat/Chat.tsx +7 -166
  39. package/src/components/chat/Messages.tsx +72 -15
  40. package/src/components/chat/Modal.tsx +0 -4
  41. package/dist/chunk-3QOICFXX.mjs.map +0 -1
  42. package/dist/chunk-CPMIEVKK.mjs.map +0 -1
  43. package/dist/chunk-H7LLXN6X.mjs.map +0 -1
  44. /package/dist/{chunk-P54DK2TL.mjs.map → chunk-M2NVAJQA.mjs.map} +0 -0
  45. /package/dist/{chunk-SEY3XSCD.mjs.map → chunk-PY7YBFPA.mjs.map} +0 -0
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  CopilotModal
3
- } from "../../chunk-H7LLXN6X.mjs";
3
+ } from "../../chunk-H5CXJBR5.mjs";
4
4
  import "../../chunk-YAGE7RCE.mjs";
5
5
  import "../../chunk-VEC45H6Q.mjs";
6
6
  import "../../chunk-RQNJNK2W.mjs";
7
- import "../../chunk-3QOICFXX.mjs";
7
+ import "../../chunk-ORHE7FYT.mjs";
8
8
  import "../../chunk-V7W6IM2V.mjs";
9
9
  import "../../chunk-OMTPWC7T.mjs";
10
10
  import "../../chunk-ZABXREBH.mjs";
@@ -17,7 +17,7 @@ import "../../chunk-OTPAZXVR.mjs";
17
17
  import "../../chunk-4LUMV4YO.mjs";
18
18
  import "../../chunk-YQFVRDNC.mjs";
19
19
  import "../../chunk-YQ3D5IQV.mjs";
20
- import "../../chunk-CPMIEVKK.mjs";
20
+ import "../../chunk-RKPANT3F.mjs";
21
21
  import "../../chunk-3XAXY2Z3.mjs";
22
22
  import "../../chunk-CBBFRI3Q.mjs";
23
23
  import "../../chunk-UPTB2MVO.mjs";
@@ -526,7 +526,7 @@ var Header = ({}) => {
526
526
  };
527
527
 
528
528
  // src/components/chat/Messages.tsx
529
- var import_react3 = __toESM(require("react"));
529
+ var import_react3 = require("react");
530
530
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
531
531
  var import_jsx_runtime6 = require("react/jsx-runtime");
532
532
  var Messages = ({
@@ -556,18 +556,8 @@ var Messages = ({
556
556
  }
557
557
  }
558
558
  }
559
- const messagesEndRef = import_react3.default.useRef(null);
560
- const scrollToBottom = () => {
561
- if (messagesEndRef.current) {
562
- messagesEndRef.current.scrollIntoView({
563
- behavior: "auto"
564
- });
565
- }
566
- };
567
- (0, import_react3.useEffect)(() => {
568
- scrollToBottom();
569
- }, [messages]);
570
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitMessages", children: [
559
+ const { messagesEndRef, messagesContainerRef } = useScrollToBottom(messages);
560
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [
571
561
  messages.map((message, index) => {
572
562
  const isCurrentMessage = index === messages.length - 1;
573
563
  if (message.isTextMessage()) {
@@ -636,6 +626,65 @@ function makeInitialMessages(initial) {
636
626
  })
637
627
  );
638
628
  }
629
+ function useScrollToBottom(messages) {
630
+ const messagesEndRef = (0, import_react3.useRef)(null);
631
+ const messagesContainerRef = (0, import_react3.useRef)(null);
632
+ const isProgrammaticScrollRef = (0, import_react3.useRef)(false);
633
+ const isUserScrollUpRef = (0, import_react3.useRef)(false);
634
+ const scrollToBottom = () => {
635
+ if (messagesEndRef.current) {
636
+ isProgrammaticScrollRef.current = true;
637
+ messagesEndRef.current.scrollIntoView({
638
+ behavior: "auto"
639
+ });
640
+ }
641
+ };
642
+ const handleScroll = () => {
643
+ if (isProgrammaticScrollRef.current) {
644
+ isProgrammaticScrollRef.current = false;
645
+ return;
646
+ }
647
+ if (messagesContainerRef.current) {
648
+ const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
649
+ isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
650
+ }
651
+ };
652
+ (0, import_react3.useEffect)(() => {
653
+ const container = messagesContainerRef.current;
654
+ if (container) {
655
+ container.addEventListener("scroll", handleScroll);
656
+ }
657
+ return () => {
658
+ if (container) {
659
+ container.removeEventListener("scroll", handleScroll);
660
+ }
661
+ };
662
+ }, []);
663
+ (0, import_react3.useEffect)(() => {
664
+ const container = messagesContainerRef.current;
665
+ if (!container) {
666
+ return;
667
+ }
668
+ const mutationObserver = new MutationObserver(() => {
669
+ if (!isUserScrollUpRef.current) {
670
+ scrollToBottom();
671
+ }
672
+ });
673
+ mutationObserver.observe(container, {
674
+ childList: true,
675
+ subtree: true,
676
+ characterData: true
677
+ });
678
+ return () => {
679
+ mutationObserver.disconnect();
680
+ };
681
+ }, []);
682
+ (0, import_react3.useEffect)(() => {
683
+ isUserScrollUpRef.current = false;
684
+ scrollToBottom();
685
+ }, [messages.filter((m) => m.isTextMessage() && m.role === import_runtime_client_gql.Role.User).length]);
686
+ return { messagesEndRef, messagesContainerRef };
687
+ }
639
688
 
640
689
  // src/components/chat/Input.tsx
641
690
  var import_react6 = require("react");
@@ -2043,7 +2092,6 @@ function DebugMenuButton({
2043
2092
  }
2044
2093
 
2045
2094
  // src/components/chat/Chat.tsx
2046
- var import_react_core9 = require("@copilotkit/react-core");
2047
2095
  var import_jsx_runtime19 = require("react/jsx-runtime");
2048
2096
  function CopilotChat({
2049
2097
  instructions,
@@ -2051,8 +2099,6 @@ function CopilotChat({
2051
2099
  makeSystemMessage,
2052
2100
  showResponseButton = true,
2053
2101
  onInProgress,
2054
- onStopGeneration,
2055
- onReloadMessages,
2056
2102
  Messages: Messages2 = Messages,
2057
2103
  RenderTextMessage: RenderTextMessage2 = RenderTextMessage,
2058
2104
  RenderActionExecutionMessage: RenderActionExecutionMessage2 = RenderActionExecutionMessage,
@@ -2075,13 +2121,7 @@ function CopilotChat({
2075
2121
  sendMessage,
2076
2122
  stopGeneration,
2077
2123
  reloadMessages
2078
- } = useCopilotChatLogic(
2079
- makeSystemMessage,
2080
- onInProgress,
2081
- onSubmitMessage,
2082
- onStopGeneration,
2083
- onReloadMessages
2084
- );
2124
+ } = useCopilotChatLogic(makeSystemMessage, onInProgress, onSubmitMessage);
2085
2125
  const chatContext = import_react11.default.useContext(ChatContext);
2086
2126
  const isVisible = chatContext ? chatContext.open : true;
2087
2127
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
@@ -2137,15 +2177,8 @@ function WrappedCopilotChat({
2137
2177
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_jsx_runtime19.Fragment, { children });
2138
2178
  }
2139
2179
  var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
2140
- var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
2141
- var _a;
2142
- const {
2143
- visibleMessages,
2144
- appendMessage,
2145
- reloadMessages: defaultReloadMessages,
2146
- stopGeneration: defaultStopGeneration,
2147
- isLoading
2148
- } = (0, import_react_core8.useCopilotChat)({
2180
+ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) => {
2181
+ const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = (0, import_react_core8.useCopilotChat)({
2149
2182
  id: (0, import_shared3.randomId)(),
2150
2183
  makeSystemMessage
2151
2184
  });
@@ -2153,8 +2186,8 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onS
2153
2186
  const suggestionsAbortControllerRef = (0, import_react11.useRef)(null);
2154
2187
  const debounceTimerRef = (0, import_react11.useRef)();
2155
2188
  const abortSuggestions = () => {
2156
- var _a2;
2157
- (_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort();
2189
+ var _a;
2190
+ (_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
2158
2191
  suggestionsAbortControllerRef.current = null;
2159
2192
  };
2160
2193
  const generalContext = (0, import_react_core8.useCopilotContext)();
@@ -2180,13 +2213,7 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onS
2180
2213
  return () => {
2181
2214
  clearTimeout(debounceTimerRef.current);
2182
2215
  };
2183
- }, [
2184
- isLoading,
2185
- context.chatSuggestionConfiguration,
2186
- // hackish way to trigger suggestions reload on reset, but better than moving suggestions to the
2187
- // global context
2188
- visibleMessages.length == 0
2189
- ]);
2216
+ }, [isLoading, context.chatSuggestionConfiguration]);
2190
2217
  const sendMessage = (messageContent) => __async(void 0, null, function* () {
2191
2218
  abortSuggestions();
2192
2219
  setCurrentSuggestions([]);
@@ -2204,79 +2231,6 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onS
2204
2231
  appendMessage(message);
2205
2232
  return message;
2206
2233
  });
2207
- const messages = visibleMessages;
2208
- const { setMessages } = messagesContext;
2209
- const currentAgentName = (_a = generalContext.agentSession) == null ? void 0 : _a.agentName;
2210
- const restartCurrentAgent = (hint) => __async(void 0, null, function* () {
2211
- if (generalContext.agentSession) {
2212
- generalContext.setAgentSession(__spreadProps(__spreadValues({}, generalContext.agentSession), {
2213
- nodeName: void 0,
2214
- threadId: void 0
2215
- }));
2216
- generalContext.setCoagentStates((prevAgentStates) => {
2217
- return __spreadProps(__spreadValues({}, prevAgentStates), {
2218
- [generalContext.agentSession.agentName]: __spreadProps(__spreadValues({}, prevAgentStates[generalContext.agentSession.agentName]), {
2219
- threadId: void 0,
2220
- nodeName: void 0,
2221
- runId: void 0
2222
- })
2223
- });
2224
- });
2225
- }
2226
- });
2227
- const runCurrentAgent = (hint) => __async(void 0, null, function* () {
2228
- if (generalContext.agentSession) {
2229
- yield (0, import_react_core9.runAgent)(generalContext.agentSession.agentName, context, appendMessage, hint);
2230
- }
2231
- });
2232
- const stopCurrentAgent = () => {
2233
- if (generalContext.agentSession) {
2234
- (0, import_react_core9.stopAgent)(generalContext.agentSession.agentName, context);
2235
- }
2236
- };
2237
- const setCurrentAgentState = (state) => {
2238
- if (generalContext.agentSession) {
2239
- generalContext.setCoagentStates((prevAgentStates) => {
2240
- return __spreadProps(__spreadValues({}, prevAgentStates), {
2241
- [generalContext.agentSession.agentName]: {
2242
- state
2243
- }
2244
- });
2245
- });
2246
- }
2247
- };
2248
- function stopGeneration() {
2249
- if (onStopGeneration) {
2250
- onStopGeneration({
2251
- messages,
2252
- setMessages,
2253
- stopGeneration: defaultStopGeneration,
2254
- currentAgentName,
2255
- restartCurrentAgent,
2256
- stopCurrentAgent,
2257
- runCurrentAgent,
2258
- setCurrentAgentState
2259
- });
2260
- } else {
2261
- defaultStopGeneration();
2262
- }
2263
- }
2264
- function reloadMessages() {
2265
- if (onReloadMessages) {
2266
- onReloadMessages({
2267
- messages,
2268
- setMessages,
2269
- stopGeneration: defaultStopGeneration,
2270
- currentAgentName,
2271
- restartCurrentAgent,
2272
- stopCurrentAgent,
2273
- runCurrentAgent,
2274
- setCurrentAgentState
2275
- });
2276
- } else {
2277
- defaultReloadMessages();
2278
- }
2279
- }
2280
2234
  return {
2281
2235
  visibleMessages,
2282
2236
  isLoading,
@@ -2296,8 +2250,6 @@ var CopilotModal = ({
2296
2250
  hitEscapeToClose = true,
2297
2251
  onSetOpen,
2298
2252
  onSubmitMessage,
2299
- onStopGeneration,
2300
- onReloadMessages,
2301
2253
  shortcut = "/",
2302
2254
  icons,
2303
2255
  labels,
@@ -2335,8 +2287,6 @@ var CopilotModal = ({
2335
2287
  {
2336
2288
  instructions,
2337
2289
  onSubmitMessage,
2338
- onStopGeneration,
2339
- onReloadMessages,
2340
2290
  makeSystemMessage,
2341
2291
  showResponseButton,
2342
2292
  onInProgress,