@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
package/CHANGELOG.md CHANGED
@@ -1,19 +1,17 @@
1
1
  # ui
2
2
 
3
- ## 1.3.16-mme-reset-chat.10
3
+ ## 1.3.16-mme-revert-rxjs-changes.10
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - f6fab28: update tsup config
8
8
  - f6fab28: update entry
9
9
  - f6fab28: export langchain module
10
- - c4b9f95: Improve LangSmith support
11
- - 164ce73: Add reset and threadId to useCopilotChat
10
+ - 8a77944: Improve LangSmith support
12
11
  - f6fab28: Ensure intermediate state config is sent as snake case
13
12
  - f6fab28: update entry in tsup config
14
- - Add custom stop/reload
15
- - af119bf: Ensure the last message is sent to LangSmith
16
- - c7df09a: Move threadId to context
13
+ - 8a77944: Ensure the last message is sent to LangSmith
14
+ - Revert rxjs changes
17
15
  - f6fab28: update entry
18
16
  - f6fab28: Update exports
19
17
  - f6fab28: Update exports
@@ -23,62 +21,20 @@
23
21
  - Updated dependencies [f6fab28]
24
22
  - Updated dependencies [f6fab28]
25
23
  - Updated dependencies [f6fab28]
26
- - Updated dependencies [c4b9f95]
27
- - Updated dependencies [164ce73]
24
+ - Updated dependencies [8a77944]
28
25
  - Updated dependencies [f6fab28]
29
26
  - Updated dependencies [f6fab28]
27
+ - Updated dependencies [8a77944]
30
28
  - Updated dependencies
31
- - Updated dependencies [af119bf]
32
- - Updated dependencies [c7df09a]
33
29
  - Updated dependencies [f6fab28]
34
30
  - Updated dependencies [f6fab28]
35
31
  - Updated dependencies [f6fab28]
36
32
  - Updated dependencies [332d744]
37
33
  - Updated dependencies [f6fab28]
38
34
  - Updated dependencies [f6fab28]
39
- - @copilotkit/runtime-client-gql@1.3.16-mme-reset-chat.10
40
- - @copilotkit/react-core@1.3.16-mme-reset-chat.10
41
- - @copilotkit/shared@1.3.16-mme-reset-chat.10
42
-
43
- ## 1.3.16-mme-reset-chat.3
44
-
45
- ### Patch Changes
46
-
47
- - Move threadId to context
48
- - Updated dependencies
49
- - @copilotkit/runtime-client-gql@1.3.16-mme-reset-chat.3
50
- - @copilotkit/react-core@1.3.16-mme-reset-chat.3
51
- - @copilotkit/shared@1.3.16-mme-reset-chat.3
52
-
53
- ## 1.3.16-mme-reset-chat.2
54
-
55
- ### Patch Changes
56
-
57
- - Add reset and threadId to useCopilotChat
58
- - Updated dependencies
59
- - @copilotkit/runtime-client-gql@1.3.16-mme-reset-chat.2
60
- - @copilotkit/react-core@1.3.16-mme-reset-chat.2
61
- - @copilotkit/shared@1.3.16-mme-reset-chat.2
62
-
63
- ## 1.3.16-mme-improve-langsmith.1
64
-
65
- ### Patch Changes
66
-
67
- - Ensure the last message is sent to LangSmith
68
- - Updated dependencies
69
- - @copilotkit/runtime-client-gql@1.3.16-mme-improve-langsmith.1
70
- - @copilotkit/react-core@1.3.16-mme-improve-langsmith.1
71
- - @copilotkit/shared@1.3.16-mme-improve-langsmith.1
72
-
73
- ## 1.3.16-mme-improve-langsmith.0
74
-
75
- ### Patch Changes
76
-
77
- - Improve LangSmith support
78
- - Updated dependencies
79
- - @copilotkit/react-core@1.3.16-mme-improve-langsmith.0
80
- - @copilotkit/runtime-client-gql@1.3.16-mme-improve-langsmith.0
81
- - @copilotkit/shared@1.3.16-mme-improve-langsmith.0
35
+ - @copilotkit/runtime-client-gql@1.3.16-mme-revert-rxjs-changes.10
36
+ - @copilotkit/react-core@1.3.16-mme-revert-rxjs-changes.10
37
+ - @copilotkit/shared@1.3.16-mme-revert-rxjs-changes.10
82
38
 
83
39
  ## 1.3.15
84
40
 
@@ -9,13 +9,13 @@ import {
9
9
  } from "./chunk-RQNJNK2W.mjs";
10
10
  import {
11
11
  CopilotChat
12
- } from "./chunk-3QOICFXX.mjs";
12
+ } from "./chunk-ORHE7FYT.mjs";
13
13
  import {
14
14
  Input
15
15
  } from "./chunk-4LUMV4YO.mjs";
16
16
  import {
17
17
  Messages
18
- } from "./chunk-CPMIEVKK.mjs";
18
+ } from "./chunk-RKPANT3F.mjs";
19
19
  import {
20
20
  ResponseButton
21
21
  } from "./chunk-3XAXY2Z3.mjs";
@@ -33,8 +33,6 @@ var CopilotModal = ({
33
33
  hitEscapeToClose = true,
34
34
  onSetOpen,
35
35
  onSubmitMessage,
36
- onStopGeneration,
37
- onReloadMessages,
38
36
  shortcut = "/",
39
37
  icons,
40
38
  labels,
@@ -72,8 +70,6 @@ var CopilotModal = ({
72
70
  {
73
71
  instructions,
74
72
  onSubmitMessage,
75
- onStopGeneration,
76
- onReloadMessages,
77
73
  makeSystemMessage,
78
74
  showResponseButton,
79
75
  onInProgress,
@@ -92,4 +88,4 @@ var CopilotModal = ({
92
88
  export {
93
89
  CopilotModal
94
90
  };
95
- //# sourceMappingURL=chunk-H7LLXN6X.mjs.map
91
+ //# sourceMappingURL=chunk-H5CXJBR5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/chat/Modal.tsx"],"sourcesContent":["import React from \"react\";\nimport { ChatContextProvider } from \"./ChatContext\";\nimport { ButtonProps, HeaderProps, WindowProps } from \"./props\";\nimport { Window as DefaultWindow } from \"./Window\";\nimport { Button as DefaultButton } from \"./Button\";\nimport { Header as DefaultHeader } from \"./Header\";\nimport { Messages as DefaultMessages } from \"./Messages\";\nimport { Input as DefaultInput } from \"./Input\";\nimport { ResponseButton as DefaultResponseButton } from \"./Response\";\nimport { CopilotChat, CopilotChatProps } from \"./Chat\";\n\nexport interface CopilotModalProps extends CopilotChatProps {\n /**\n * Whether the chat window should be open by default.\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * If the chat window should close when the user clicks outside of it.\n * @default true\n */\n clickOutsideToClose?: boolean;\n\n /**\n * If the chat window should close when the user hits the Escape key.\n * @default true\n */\n hitEscapeToClose?: boolean;\n\n /**\n * The shortcut key to open the chat window.\n * Uses Command-[shortcut] on a Mac and Ctrl-[shortcut] on Windows.\n * @default '/'\n */\n shortcut?: string;\n\n /**\n * A callback that gets called when the chat window opens or closes.\n */\n onSetOpen?: (open: boolean) => void;\n\n /**\n * A custom Window component to use instead of the default.\n */\n Window?: React.ComponentType<WindowProps>;\n\n /**\n * A custom Button component to use instead of the default.\n */\n Button?: React.ComponentType<ButtonProps>;\n\n /**\n * A custom Header component to use instead of the default.\n */\n Header?: React.ComponentType<HeaderProps>;\n}\n\nexport const CopilotModal = ({\n instructions,\n defaultOpen = false,\n clickOutsideToClose = true,\n hitEscapeToClose = true,\n onSetOpen,\n onSubmitMessage,\n shortcut = \"/\",\n icons,\n labels,\n makeSystemMessage,\n showResponseButton = true,\n onInProgress,\n Window = DefaultWindow,\n Button = DefaultButton,\n Header = DefaultHeader,\n Messages = DefaultMessages,\n Input = DefaultInput,\n ResponseButton = DefaultResponseButton,\n className,\n children,\n}: CopilotModalProps) => {\n const [openState, setOpenState] = React.useState(defaultOpen);\n\n const setOpen = (open: boolean) => {\n onSetOpen?.(open);\n setOpenState(open);\n };\n\n return (\n <ChatContextProvider icons={icons} labels={labels} open={openState} setOpen={setOpen}>\n {children}\n <div className={className}>\n <Button></Button>\n <Window\n clickOutsideToClose={clickOutsideToClose}\n shortcut={shortcut}\n hitEscapeToClose={hitEscapeToClose}\n >\n <Header />\n <CopilotChat\n instructions={instructions}\n onSubmitMessage={onSubmitMessage}\n makeSystemMessage={makeSystemMessage}\n showResponseButton={showResponseButton}\n onInProgress={onInProgress}\n Messages={Messages}\n Input={Input}\n ResponseButton={ResponseButton}\n />\n </Window>\n </div>\n </ChatContextProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,WAAW;AA2FV,cACA,YADA;AAjCD,IAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,mBAAmB;AAAA,EACnB;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EACA,QAAAA,UAAS;AAAA,EACT,QAAAC,UAAS;AAAA,EACT,QAAAC,UAAS;AAAA,EACT,UAAAC,YAAW;AAAA,EACX,OAAAC,SAAQ;AAAA,EACR,gBAAAC,kBAAiB;AAAA,EACjB;AAAA,EACA;AACF,MAAyB;AACvB,QAAM,CAAC,WAAW,YAAY,IAAI,MAAM,SAAS,WAAW;AAE5D,QAAM,UAAU,CAAC,SAAkB;AACjC,2CAAY;AACZ,iBAAa,IAAI;AAAA,EACnB;AAEA,SACE,qBAAC,uBAAoB,OAAc,QAAgB,MAAM,WAAW,SACjE;AAAA;AAAA,IACD,qBAAC,SAAI,WACH;AAAA,0BAACJ,SAAA,EAAO;AAAA,MACR;AAAA,QAACD;AAAA,QAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UAEA;AAAA,gCAACE,SAAA,EAAO;AAAA,YACR;AAAA,cAAC;AAAA;AAAA,gBACC;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA,UAAUC;AAAA,gBACV,OAAOC;AAAA,gBACP,gBAAgBC;AAAA;AAAA,YAClB;AAAA;AAAA;AAAA,MACF;AAAA,OACF;AAAA,KACF;AAEJ;","names":["Window","Button","Header","Messages","Input","ResponseButton"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotModal
3
- } from "./chunk-H7LLXN6X.mjs";
3
+ } from "./chunk-H5CXJBR5.mjs";
4
4
  import {
5
5
  __spreadProps,
6
6
  __spreadValues
@@ -27,4 +27,4 @@ function CopilotSidebar(props) {
27
27
  export {
28
28
  CopilotSidebar
29
29
  };
30
- //# sourceMappingURL=chunk-P54DK2TL.mjs.map
30
+ //# sourceMappingURL=chunk-M2NVAJQA.mjs.map
@@ -22,7 +22,7 @@ import {
22
22
  } from "./chunk-4LUMV4YO.mjs";
23
23
  import {
24
24
  Messages
25
- } from "./chunk-CPMIEVKK.mjs";
25
+ } from "./chunk-RKPANT3F.mjs";
26
26
  import {
27
27
  ResponseButton
28
28
  } from "./chunk-3XAXY2Z3.mjs";
@@ -32,7 +32,6 @@ import {
32
32
  } from "./chunk-CBBFRI3Q.mjs";
33
33
  import {
34
34
  __async,
35
- __spreadProps,
36
35
  __spreadValues
37
36
  } from "./chunk-MRXNTQOX.mjs";
38
37
 
@@ -45,7 +44,6 @@ import {
45
44
  } from "@copilotkit/react-core";
46
45
  import { Role, TextMessage } from "@copilotkit/runtime-client-gql";
47
46
  import { randomId } from "@copilotkit/shared";
48
- import { runAgent, stopAgent } from "@copilotkit/react-core";
49
47
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
50
48
  function CopilotChat({
51
49
  instructions,
@@ -53,8 +51,6 @@ function CopilotChat({
53
51
  makeSystemMessage,
54
52
  showResponseButton = true,
55
53
  onInProgress,
56
- onStopGeneration,
57
- onReloadMessages,
58
54
  Messages: Messages2 = Messages,
59
55
  RenderTextMessage: RenderTextMessage2 = RenderTextMessage,
60
56
  RenderActionExecutionMessage: RenderActionExecutionMessage2 = RenderActionExecutionMessage,
@@ -77,13 +73,7 @@ function CopilotChat({
77
73
  sendMessage,
78
74
  stopGeneration,
79
75
  reloadMessages
80
- } = useCopilotChatLogic(
81
- makeSystemMessage,
82
- onInProgress,
83
- onSubmitMessage,
84
- onStopGeneration,
85
- onReloadMessages
86
- );
76
+ } = useCopilotChatLogic(makeSystemMessage, onInProgress, onSubmitMessage);
87
77
  const chatContext = React.useContext(ChatContext);
88
78
  const isVisible = chatContext ? chatContext.open : true;
89
79
  return /* @__PURE__ */ jsxs(WrappedCopilotChat, { icons, labels, className, children: [
@@ -139,15 +129,8 @@ function WrappedCopilotChat({
139
129
  return /* @__PURE__ */ jsx(Fragment, { children });
140
130
  }
141
131
  var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
142
- var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
143
- var _a;
144
- const {
145
- visibleMessages,
146
- appendMessage,
147
- reloadMessages: defaultReloadMessages,
148
- stopGeneration: defaultStopGeneration,
149
- isLoading
150
- } = useCopilotChat({
132
+ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) => {
133
+ const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } = useCopilotChat({
151
134
  id: randomId(),
152
135
  makeSystemMessage
153
136
  });
@@ -155,8 +138,8 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onS
155
138
  const suggestionsAbortControllerRef = useRef(null);
156
139
  const debounceTimerRef = useRef();
157
140
  const abortSuggestions = () => {
158
- var _a2;
159
- (_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort();
141
+ var _a;
142
+ (_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
160
143
  suggestionsAbortControllerRef.current = null;
161
144
  };
162
145
  const generalContext = useCopilotContext();
@@ -182,13 +165,7 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onS
182
165
  return () => {
183
166
  clearTimeout(debounceTimerRef.current);
184
167
  };
185
- }, [
186
- isLoading,
187
- context.chatSuggestionConfiguration,
188
- // hackish way to trigger suggestions reload on reset, but better than moving suggestions to the
189
- // global context
190
- visibleMessages.length == 0
191
- ]);
168
+ }, [isLoading, context.chatSuggestionConfiguration]);
192
169
  const sendMessage = (messageContent) => __async(void 0, null, function* () {
193
170
  abortSuggestions();
194
171
  setCurrentSuggestions([]);
@@ -206,79 +183,6 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onS
206
183
  appendMessage(message);
207
184
  return message;
208
185
  });
209
- const messages = visibleMessages;
210
- const { setMessages } = messagesContext;
211
- const currentAgentName = (_a = generalContext.agentSession) == null ? void 0 : _a.agentName;
212
- const restartCurrentAgent = (hint) => __async(void 0, null, function* () {
213
- if (generalContext.agentSession) {
214
- generalContext.setAgentSession(__spreadProps(__spreadValues({}, generalContext.agentSession), {
215
- nodeName: void 0,
216
- threadId: void 0
217
- }));
218
- generalContext.setCoagentStates((prevAgentStates) => {
219
- return __spreadProps(__spreadValues({}, prevAgentStates), {
220
- [generalContext.agentSession.agentName]: __spreadProps(__spreadValues({}, prevAgentStates[generalContext.agentSession.agentName]), {
221
- threadId: void 0,
222
- nodeName: void 0,
223
- runId: void 0
224
- })
225
- });
226
- });
227
- }
228
- });
229
- const runCurrentAgent = (hint) => __async(void 0, null, function* () {
230
- if (generalContext.agentSession) {
231
- yield runAgent(generalContext.agentSession.agentName, context, appendMessage, hint);
232
- }
233
- });
234
- const stopCurrentAgent = () => {
235
- if (generalContext.agentSession) {
236
- stopAgent(generalContext.agentSession.agentName, context);
237
- }
238
- };
239
- const setCurrentAgentState = (state) => {
240
- if (generalContext.agentSession) {
241
- generalContext.setCoagentStates((prevAgentStates) => {
242
- return __spreadProps(__spreadValues({}, prevAgentStates), {
243
- [generalContext.agentSession.agentName]: {
244
- state
245
- }
246
- });
247
- });
248
- }
249
- };
250
- function stopGeneration() {
251
- if (onStopGeneration) {
252
- onStopGeneration({
253
- messages,
254
- setMessages,
255
- stopGeneration: defaultStopGeneration,
256
- currentAgentName,
257
- restartCurrentAgent,
258
- stopCurrentAgent,
259
- runCurrentAgent,
260
- setCurrentAgentState
261
- });
262
- } else {
263
- defaultStopGeneration();
264
- }
265
- }
266
- function reloadMessages() {
267
- if (onReloadMessages) {
268
- onReloadMessages({
269
- messages,
270
- setMessages,
271
- stopGeneration: defaultStopGeneration,
272
- currentAgentName,
273
- restartCurrentAgent,
274
- stopCurrentAgent,
275
- runCurrentAgent,
276
- setCurrentAgentState
277
- });
278
- } else {
279
- defaultReloadMessages();
280
- }
281
- }
282
186
  return {
283
187
  visibleMessages,
284
188
  isLoading,
@@ -294,4 +198,4 @@ export {
294
198
  WrappedCopilotChat,
295
199
  useCopilotChatLogic
296
200
  };
297
- //# sourceMappingURL=chunk-3QOICFXX.mjs.map
201
+ //# sourceMappingURL=chunk-ORHE7FYT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/chat/Chat.tsx"],"sourcesContent":["/**\n * <br/>\n * <img src=\"/images/CopilotChat.gif\" width=\"500\" />\n *\n * A chatbot panel component for the CopilotKit framework. The component allows for a high degree\n * of customization through various props and custom CSS.\n *\n * ## Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ## Usage\n *\n * ```tsx\n * import { CopilotChat } from \"@copilotkit/react-ui\";\n * import \"@copilotkit/react-ui/styles.css\";\n *\n * <CopilotChat\n * labels={{\n * title: \"Your Assistant\",\n * initial: \"Hi! 👋 How can I assist you today?\",\n * }}\n * />\n * ```\n *\n * ### Look & Feel\n *\n * By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:\n * ```tsx title=\"YourRootComponent.tsx\"\n * ...\n * import \"@copilotkit/react-ui/styles.css\"; // [!code highlight]\n *\n * export function YourRootComponent() {\n * return (\n * <CopilotKit>\n * ...\n * </CopilotKit>\n * );\n * }\n * ```\n * For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.\n */\n\nimport {\n ChatContext,\n ChatContextProvider,\n CopilotChatIcons,\n CopilotChatLabels,\n} from \"./ChatContext\";\nimport { Messages as DefaultMessages } from \"./Messages\";\nimport { Input as DefaultInput } from \"./Input\";\nimport { ResponseButton as DefaultResponseButton } from \"./Response\";\nimport { RenderTextMessage as DefaultRenderTextMessage } from \"./messages/RenderTextMessage\";\nimport { RenderActionExecutionMessage as DefaultRenderActionExecutionMessage } from \"./messages/RenderActionExecutionMessage\";\nimport { RenderResultMessage as DefaultRenderResultMessage } from \"./messages/RenderResultMessage\";\nimport { RenderAgentStateMessage as DefaultRenderAgentStateMessage } from \"./messages/RenderAgentStateMessage\";\nimport { Suggestion } from \"./Suggestion\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport {\n SystemMessageFunction,\n useCopilotChat,\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"@copilotkit/react-core\";\nimport { reloadSuggestions } from \"./Suggestion\";\nimport { CopilotChatSuggestion } from \"../../types/suggestions\";\nimport { Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { InputProps, MessagesProps, RenderMessageProps, ResponseButtonProps } from \"./props\";\nimport { randomId } from \"@copilotkit/shared\";\n\nimport { CopilotDevConsole } from \"../dev-console\";\n\n/**\n * Props for CopilotChat component.\n */\nexport interface CopilotChatProps {\n /**\n * Custom instructions to be added to the system message. Use this property to\n * provide additional context or guidance to the language model, influencing\n * its responses. These instructions can include specific directions,\n * preferences, or criteria that the model should consider when generating\n * its output, thereby tailoring the conversation more precisely to the\n * user's needs or the application's requirements.\n */\n instructions?: string;\n\n /**\n * A callback that gets called when the in progress state changes.\n */\n onInProgress?: (inProgress: boolean) => void;\n\n /**\n * A callback that gets called when a new message it submitted.\n */\n onSubmitMessage?: (message: string) => void | Promise<void>;\n\n /**\n * Icons can be used to set custom icons for the chat window.\n */\n icons?: CopilotChatIcons;\n\n /**\n * Labels can be used to set custom labels for the chat window.\n */\n labels?: CopilotChatLabels;\n\n /**\n * A function that takes in context string and instructions and returns\n * the system message to include in the chat request.\n * Use this to completely override the system message, when providing\n * instructions is not enough.\n */\n makeSystemMessage?: SystemMessageFunction;\n\n /**\n * Whether to show the response button.\n * @default true\n */\n showResponseButton?: boolean;\n\n /**\n * A custom Messages component to use instead of the default.\n */\n Messages?: React.ComponentType<MessagesProps>;\n\n /**\n * A custom RenderTextMessage component to use instead of the default.\n */\n RenderTextMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * A custom RenderActionExecutionMessage component to use instead of the default.\n */\n RenderActionExecutionMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * A custom RenderAgentStateMessage component to use instead of the default.\n */\n RenderAgentStateMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * A custom RenderResultMessage component to use instead of the default.\n */\n RenderResultMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * A custom Input component to use instead of the default.\n */\n Input?: React.ComponentType<InputProps>;\n\n /**\n * A custom ResponseButton component to use instead of the default.\n */\n ResponseButton?: React.ComponentType<ResponseButtonProps>;\n\n /**\n * A class name to apply to the root element.\n */\n className?: string;\n\n /**\n * Children to render.\n */\n children?: React.ReactNode;\n}\n\nexport function CopilotChat({\n instructions,\n onSubmitMessage,\n makeSystemMessage,\n showResponseButton = true,\n onInProgress,\n Messages = DefaultMessages,\n RenderTextMessage = DefaultRenderTextMessage,\n RenderActionExecutionMessage = DefaultRenderActionExecutionMessage,\n RenderAgentStateMessage = DefaultRenderAgentStateMessage,\n RenderResultMessage = DefaultRenderResultMessage,\n Input = DefaultInput,\n ResponseButton = DefaultResponseButton,\n className,\n icons,\n labels,\n}: CopilotChatProps) {\n const context = useCopilotContext();\n\n useEffect(() => {\n context.setChatInstructions(instructions || \"\");\n }, [instructions]);\n\n const {\n visibleMessages,\n isLoading,\n currentSuggestions,\n sendMessage,\n stopGeneration,\n reloadMessages,\n } = useCopilotChatLogic(makeSystemMessage, onInProgress, onSubmitMessage);\n\n const chatContext = React.useContext(ChatContext);\n const isVisible = chatContext ? chatContext.open : true;\n\n return (\n <WrappedCopilotChat icons={icons} labels={labels} className={className}>\n <CopilotDevConsole />\n <Messages\n RenderTextMessage={RenderTextMessage}\n RenderActionExecutionMessage={RenderActionExecutionMessage}\n RenderAgentStateMessage={RenderAgentStateMessage}\n RenderResultMessage={RenderResultMessage}\n messages={visibleMessages}\n inProgress={isLoading}\n >\n {currentSuggestions.length > 0 && (\n <div>\n <h6>Suggested:</h6>\n <div className=\"suggestions\">\n {currentSuggestions.map((suggestion, index) => (\n <Suggestion\n key={index}\n title={suggestion.title}\n message={suggestion.message}\n partial={suggestion.partial}\n className={suggestion.className}\n onClick={(message) => sendMessage(message)}\n />\n ))}\n </div>\n </div>\n )}\n {showResponseButton && visibleMessages.length > 0 && (\n <ResponseButton\n onClick={isLoading ? stopGeneration : reloadMessages}\n inProgress={isLoading}\n />\n )}\n </Messages>\n <Input inProgress={isLoading} onSend={sendMessage} isVisible={isVisible} />\n </WrappedCopilotChat>\n );\n}\n\nexport function WrappedCopilotChat({\n children,\n icons,\n labels,\n className,\n}: {\n children: React.ReactNode;\n icons?: CopilotChatIcons;\n labels?: CopilotChatLabels;\n className?: string;\n}) {\n const chatContext = React.useContext(ChatContext);\n if (!chatContext) {\n return (\n <ChatContextProvider icons={icons} labels={labels} open={true} setOpen={() => {}}>\n <div className={`copilotKitChat ${className}`}>{children}</div>\n </ChatContextProvider>\n );\n }\n return <>{children}</>;\n}\n\nconst SUGGESTIONS_DEBOUNCE_TIMEOUT = 1000;\n\nexport const useCopilotChatLogic = (\n makeSystemMessage?: SystemMessageFunction,\n onInProgress?: (isLoading: boolean) => void,\n onSubmitMessage?: (messageContent: string) => Promise<void> | void,\n) => {\n const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } =\n useCopilotChat({\n id: randomId(),\n makeSystemMessage,\n });\n\n const [currentSuggestions, setCurrentSuggestions] = useState<CopilotChatSuggestion[]>([]);\n const suggestionsAbortControllerRef = useRef<AbortController | null>(null);\n const debounceTimerRef = useRef<any>();\n\n const abortSuggestions = () => {\n suggestionsAbortControllerRef.current?.abort();\n suggestionsAbortControllerRef.current = null;\n };\n\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n\n useEffect(() => {\n onInProgress?.(isLoading);\n\n abortSuggestions();\n\n debounceTimerRef.current = setTimeout(\n () => {\n if (!isLoading && Object.keys(context.chatSuggestionConfiguration).length !== 0) {\n suggestionsAbortControllerRef.current = new AbortController();\n reloadSuggestions(\n context,\n context.chatSuggestionConfiguration,\n setCurrentSuggestions,\n suggestionsAbortControllerRef,\n );\n }\n },\n currentSuggestions.length == 0 ? 0 : SUGGESTIONS_DEBOUNCE_TIMEOUT,\n );\n\n return () => {\n clearTimeout(debounceTimerRef.current);\n };\n }, [isLoading, context.chatSuggestionConfiguration]);\n\n const sendMessage = async (messageContent: string) => {\n abortSuggestions();\n setCurrentSuggestions([]);\n\n const message: Message = new TextMessage({\n content: messageContent,\n role: Role.User,\n });\n\n if (onSubmitMessage) {\n try {\n await onSubmitMessage(messageContent);\n } catch (error) {\n console.error(\"Error in onSubmitMessage:\", error);\n }\n }\n // this needs to happen after onSubmitMessage, because it will trigger submission\n // of the message to the endpoint. Some users depend on performing some actions\n // before the message is submitted.\n appendMessage(message);\n\n return message;\n };\n\n return {\n visibleMessages,\n isLoading,\n currentSuggestions,\n sendMessage,\n stopGeneration,\n reloadMessages,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,OAAO,SAAS,WAAW,QAAQ,gBAAgB;AACnD;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAkB,MAAM,mBAAmB;AAE3C,SAAS,gBAAgB;AAuInB,SAyDG,UAzDH,KAUI,YAVJ;AArCC,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EACA,UAAAA,YAAW;AAAA,EACX,mBAAAC,qBAAoB;AAAA,EAC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AM;AACX,mBAAa,iBAAiB,OAAO;AAAA,IACvC;AAAA,EACF,GAAG,CAAC,WAAW,QAAQ,2BAA2B,CAAC;AAEnD,QAAM,cAAc,CAAO,mBAA2B;AACpD,qBAAiB;AACjB,0BAAsB,CAAC,CAAC;AAExB,UAAM,UAAmB,IAAI,YAAY;AAAA,MACvC,SAAS;AAAA,MACT,MAAM,KAAK;AAAA,IACb,CAAC;AAED,QAAI,iBAAiB;AACnB,UAAI;AACF,cAAM,gBAAgB,cAAc;AAAA,MACtC,SAAS,OAAP;AACA,gBAAQ,MAAM,6BAA6B,KAAK;AAAA,MAClD;AAAA,IACF;AAIA,kBAAc,OAAO;AAErB,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["Messages","RenderTextMessage","RenderActionExecutionMessage","RenderAgentStateMessage","RenderResultMessage","Input","ResponseButton"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotModal
3
- } from "./chunk-H7LLXN6X.mjs";
3
+ } from "./chunk-H5CXJBR5.mjs";
4
4
  import {
5
5
  __spreadProps,
6
6
  __spreadValues
@@ -18,4 +18,4 @@ function CopilotPopup(props) {
18
18
  export {
19
19
  CopilotPopup
20
20
  };
21
- //# sourceMappingURL=chunk-SEY3XSCD.mjs.map
21
+ //# sourceMappingURL=chunk-PY7YBFPA.mjs.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-CBBFRI3Q.mjs";
4
4
 
5
5
  // src/components/chat/Messages.tsx
6
- import React, { useEffect, useMemo } from "react";
6
+ import { useEffect, useMemo, useRef } from "react";
7
7
  import {
8
8
  ResultMessage,
9
9
  TextMessage,
@@ -37,18 +37,8 @@ var Messages = ({
37
37
  }
38
38
  }
39
39
  }
40
- const messagesEndRef = React.useRef(null);
41
- const scrollToBottom = () => {
42
- if (messagesEndRef.current) {
43
- messagesEndRef.current.scrollIntoView({
44
- behavior: "auto"
45
- });
46
- }
47
- };
48
- useEffect(() => {
49
- scrollToBottom();
50
- }, [messages]);
51
- return /* @__PURE__ */ jsxs("div", { className: "copilotKitMessages", children: [
40
+ const { messagesEndRef, messagesContainerRef } = useScrollToBottom(messages);
41
+ return /* @__PURE__ */ jsxs("div", { className: "copilotKitMessages", ref: messagesContainerRef, children: [
52
42
  messages.map((message, index) => {
53
43
  const isCurrentMessage = index === messages.length - 1;
54
44
  if (message.isTextMessage()) {
@@ -117,8 +107,68 @@ function makeInitialMessages(initial) {
117
107
  })
118
108
  );
119
109
  }
110
+ function useScrollToBottom(messages) {
111
+ const messagesEndRef = useRef(null);
112
+ const messagesContainerRef = useRef(null);
113
+ const isProgrammaticScrollRef = useRef(false);
114
+ const isUserScrollUpRef = useRef(false);
115
+ const scrollToBottom = () => {
116
+ if (messagesEndRef.current) {
117
+ isProgrammaticScrollRef.current = true;
118
+ messagesEndRef.current.scrollIntoView({
119
+ behavior: "auto"
120
+ });
121
+ }
122
+ };
123
+ const handleScroll = () => {
124
+ if (isProgrammaticScrollRef.current) {
125
+ isProgrammaticScrollRef.current = false;
126
+ return;
127
+ }
128
+ if (messagesContainerRef.current) {
129
+ const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;
130
+ isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;
131
+ }
132
+ };
133
+ useEffect(() => {
134
+ const container = messagesContainerRef.current;
135
+ if (container) {
136
+ container.addEventListener("scroll", handleScroll);
137
+ }
138
+ return () => {
139
+ if (container) {
140
+ container.removeEventListener("scroll", handleScroll);
141
+ }
142
+ };
143
+ }, []);
144
+ useEffect(() => {
145
+ const container = messagesContainerRef.current;
146
+ if (!container) {
147
+ return;
148
+ }
149
+ const mutationObserver = new MutationObserver(() => {
150
+ if (!isUserScrollUpRef.current) {
151
+ scrollToBottom();
152
+ }
153
+ });
154
+ mutationObserver.observe(container, {
155
+ childList: true,
156
+ subtree: true,
157
+ characterData: true
158
+ });
159
+ return () => {
160
+ mutationObserver.disconnect();
161
+ };
162
+ }, []);
163
+ useEffect(() => {
164
+ isUserScrollUpRef.current = false;
165
+ scrollToBottom();
166
+ }, [messages.filter((m) => m.isTextMessage() && m.role === Role.User).length]);
167
+ return { messagesEndRef, messagesContainerRef };
168
+ }
120
169
 
121
170
  export {
122
- Messages
171
+ Messages,
172
+ useScrollToBottom
123
173
  };
124
- //# sourceMappingURL=chunk-CPMIEVKK.mjs.map
174
+ //# sourceMappingURL=chunk-RKPANT3F.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/chat/Messages.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useRef } from \"react\";\nimport { MessagesProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport {\n ActionExecutionMessage,\n Message,\n ResultMessage,\n TextMessage,\n Role,\n AgentStateMessage,\n} from \"@copilotkit/runtime-client-gql\";\n\nexport const Messages = ({\n messages,\n inProgress,\n children,\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n}: MessagesProps) => {\n const context = useChatContext();\n const initialMessages = useMemo(\n () => makeInitialMessages(context.labels.initial),\n [context.labels.initial],\n );\n messages = [...initialMessages, ...messages];\n\n const actionResults: Record<string, string> = {};\n\n for (let i = 0; i < messages.length; i++) {\n if (messages[i].isActionExecutionMessage()) {\n const id = messages[i].id;\n const resultMessage: ResultMessage | undefined = messages.find(\n (message) => message.isResultMessage() && message.actionExecutionId === id,\n ) as ResultMessage | undefined;\n\n if (resultMessage) {\n actionResults[id] = ResultMessage.decodeResult(resultMessage.result || \"\");\n }\n }\n }\n\n const { messagesEndRef, messagesContainerRef } = useScrollToBottom(messages);\n\n return (\n <div className=\"copilotKitMessages\" ref={messagesContainerRef}>\n {messages.map((message, index) => {\n const isCurrentMessage = index === messages.length - 1;\n\n if (message.isTextMessage()) {\n return (\n <RenderTextMessage\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n />\n );\n } else if (message.isActionExecutionMessage()) {\n return (\n <RenderActionExecutionMessage\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n actionResult={actionResults[message.id]}\n />\n );\n } else if (message.isAgentStateMessage()) {\n return (\n <RenderAgentStateMessage\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n />\n );\n } else if (message.isResultMessage()) {\n return (\n <RenderResultMessage\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n />\n );\n }\n })}\n <footer ref={messagesEndRef}>{children}</footer>\n </div>\n );\n};\n\nfunction makeInitialMessages(initial?: string | string[]): Message[] {\n let initialArray: string[] = [];\n if (initial) {\n if (Array.isArray(initial)) {\n initialArray.push(...initial);\n } else {\n initialArray.push(initial);\n }\n }\n\n return initialArray.map(\n (message) =>\n new TextMessage({\n role: Role.Assistant,\n content: message,\n }),\n );\n}\nexport function useScrollToBottom(messages: any[]) {\n const messagesEndRef = useRef<HTMLDivElement>(null);\n const messagesContainerRef = useRef<HTMLDivElement | null>(null);\n const isProgrammaticScrollRef = useRef(false);\n const isUserScrollUpRef = useRef(false);\n\n const scrollToBottom = () => {\n if (messagesEndRef.current) {\n isProgrammaticScrollRef.current = true;\n messagesEndRef.current.scrollIntoView({\n behavior: \"auto\",\n });\n }\n };\n\n const handleScroll = () => {\n if (isProgrammaticScrollRef.current) {\n isProgrammaticScrollRef.current = false;\n return;\n }\n\n if (messagesContainerRef.current) {\n const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;\n isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;\n }\n };\n\n useEffect(() => {\n const container = messagesContainerRef.current;\n if (container) {\n container.addEventListener(\"scroll\", handleScroll);\n }\n return () => {\n if (container) {\n container.removeEventListener(\"scroll\", handleScroll);\n }\n };\n }, []);\n\n useEffect(() => {\n const container = messagesContainerRef.current;\n if (!container) {\n return;\n }\n\n const mutationObserver = new MutationObserver(() => {\n if (!isUserScrollUpRef.current) {\n scrollToBottom();\n }\n });\n\n mutationObserver.observe(container, {\n childList: true,\n subtree: true,\n characterData: true,\n });\n\n return () => {\n mutationObserver.disconnect();\n };\n }, []);\n\n useEffect(() => {\n isUserScrollUpRef.current = false;\n scrollToBottom();\n }, [messages.filter((m) => m.isTextMessage() && m.role === Role.User).length]);\n\n return { messagesEndRef, messagesContainerRef };\n}\n"],"mappings":";;;;;AAAA,SAAgB,WAAW,SAAS,cAAc;AAGlD;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAoCH,SAMQ,KANR;AAlCG,IAAM,WAAW,CAAC;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAqB;AACnB,QAAM,UAAU,eAAe;AAC/B,QAAM,kBAAkB;AAAA,IACtB,MAAM,oBAAoB,QAAQ,OAAO,OAAO;AAAA,IAChD,CAAC,QAAQ,OAAO,OAAO;AAAA,EACzB;AACA,aAAW,CAAC,GAAG,iBAAiB,GAAG,QAAQ;AAE3C,QAAM,gBAAwC,CAAC;AAE/C,WAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,QAAI,SAAS,CAAC,EAAE,yBAAyB,GAAG;AAC1C,YAAM,KAAK,SAAS,CAAC,EAAE;AACvB,YAAM,gBAA2C,SAAS;AAAA,QACxD,CAAC,YAAY,QAAQ,gBAAgB,KAAK,QAAQ,sBAAsB;AAAA,MAC1E;AAEA,UAAI,eAAe;AACjB,sBAAc,EAAE,IAAI,cAAc,aAAa,cAAc,UAAU,EAAE;AAAA,MAC3E;AAAA,IACF;AAAA,EACF;AAEA,QAAM,EAAE,gBAAgB,qBAAqB,IAAI,kBAAkB,QAAQ;AAE3E,SACE,qBAAC,SAAI,WAAU,sBAAqB,KAAK,sBACtC;AAAA,aAAS,IAAI,CAAC,SAAS,UAAU;AAChC,YAAM,m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2
2
  import { CopilotChatIcons, CopilotChatLabels } from './ChatContext.js';
3
3
  import React__default from 'react';
4
- import { SystemMessageFunction, HintFunction } from '@copilotkit/react-core';
4
+ import { SystemMessageFunction } from '@copilotkit/react-core';
5
5
  import { CopilotChatSuggestion } from '../../types/suggestions.js';
6
6
  import { Message } from '@copilotkit/runtime-client-gql';
7
7
  import { MessagesProps, RenderMessageProps, InputProps, ResponseButtonProps } from './props.js';
@@ -27,14 +27,6 @@ interface CopilotChatProps {
27
27
  * A callback that gets called when a new message it submitted.
28
28
  */
29
29
  onSubmitMessage?: (message: string) => void | Promise<void>;
30
- /**
31
- * A custom stop generation function.
32
- */
33
- onStopGeneration?: OnStopGeneration;
34
- /**
35
- * A custom reload messages function.
36
- */
37
- onReloadMessages?: OnReloadMessages;
38
30
  /**
39
31
  * Icons can be used to set custom icons for the chat window.
40
32
  */
@@ -92,57 +84,20 @@ interface CopilotChatProps {
92
84
  */
93
85
  children?: React__default.ReactNode;
94
86
  }
95
- interface OnStopGenerationArguments {
96
- /**
97
- * The name of the currently executing agent.
98
- */
99
- currentAgentName: string | undefined;
100
- /**
101
- * The messages in the chat.
102
- */
103
- messages: Message[];
104
- /**
105
- * Set the messages in the chat.
106
- */
107
- setMessages: (messages: Message[]) => void;
108
- /**
109
- * Stop chat generation.
110
- */
111
- stopGeneration: () => void;
112
- /**
113
- * Restart the currently executing agent.
114
- */
115
- restartCurrentAgent: () => void;
116
- /**
117
- * Stop the currently executing agent.
118
- */
119
- stopCurrentAgent: () => void;
120
- /**
121
- * Run the currently executing agent.
122
- */
123
- runCurrentAgent: (hint?: HintFunction) => Promise<void>;
124
- /**
125
- * Set the state of the currently executing agent.
126
- */
127
- setCurrentAgentState: (state: any) => void;
128
- }
129
- type OnReloadMessagesArguments = OnStopGenerationArguments;
130
- type OnStopGeneration = (args: OnStopGenerationArguments) => void;
131
- type OnReloadMessages = (args: OnReloadMessagesArguments) => void;
132
- declare function CopilotChat({ instructions, onSubmitMessage, makeSystemMessage, showResponseButton, onInProgress, onStopGeneration, onReloadMessages, Messages, RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, Input, ResponseButton, className, icons, labels, }: CopilotChatProps): react_jsx_runtime.JSX.Element;
87
+ declare function CopilotChat({ instructions, onSubmitMessage, makeSystemMessage, showResponseButton, onInProgress, Messages, RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, Input, ResponseButton, className, icons, labels, }: CopilotChatProps): react_jsx_runtime.JSX.Element;
133
88
  declare function WrappedCopilotChat({ children, icons, labels, className, }: {
134
89
  children: React__default.ReactNode;
135
90
  icons?: CopilotChatIcons;
136
91
  labels?: CopilotChatLabels;
137
92
  className?: string;
138
93
  }): react_jsx_runtime.JSX.Element;
139
- declare const useCopilotChatLogic: (makeSystemMessage?: SystemMessageFunction, onInProgress?: (isLoading: boolean) => void, onSubmitMessage?: (messageContent: string) => Promise<void> | void, onStopGeneration?: OnStopGeneration, onReloadMessages?: OnReloadMessages) => {
94
+ declare const useCopilotChatLogic: (makeSystemMessage?: SystemMessageFunction, onInProgress?: (isLoading: boolean) => void, onSubmitMessage?: (messageContent: string) => Promise<void> | void) => {
140
95
  visibleMessages: Message[];
141
96
  isLoading: boolean;
142
97
  currentSuggestions: CopilotChatSuggestion[];
143
98
  sendMessage: (messageContent: string) => Promise<Message>;
144
99
  stopGeneration: () => void;
145
- reloadMessages: () => void;
100
+ reloadMessages: () => Promise<void>;
146
101
  };
147
102
 
148
- export { CopilotChat, CopilotChatProps, OnReloadMessages, OnReloadMessagesArguments, OnStopGeneration, WrappedCopilotChat, useCopilotChatLogic };
103
+ export { CopilotChat, CopilotChatProps, WrappedCopilotChat, useCopilotChatLogic };