@copilotkit/react-ui 1.4.2-tyler-reset-chat.1 → 1.4.2

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 (37) hide show
  1. package/CHANGELOG.md +6 -15
  2. package/dist/{chunk-B6A6OMIG.mjs → chunk-63ZKP62F.mjs} +2 -6
  3. package/dist/chunk-63ZKP62F.mjs.map +1 -0
  4. package/dist/{chunk-OI5EKZPO.mjs → chunk-DHGDU64D.mjs} +7 -103
  5. package/dist/chunk-DHGDU64D.mjs.map +1 -0
  6. package/dist/{chunk-RQRK6DEW.mjs → chunk-TKFQ7VQR.mjs} +2 -2
  7. package/dist/{chunk-Z2RXDT7O.mjs → chunk-VYKDFXGS.mjs} +2 -2
  8. package/dist/components/chat/Chat.d.ts +5 -50
  9. package/dist/components/chat/Chat.js +6 -101
  10. package/dist/components/chat/Chat.js.map +1 -1
  11. package/dist/components/chat/Chat.mjs +1 -1
  12. package/dist/components/chat/Modal.d.ts +1 -1
  13. package/dist/components/chat/Modal.js +6 -105
  14. package/dist/components/chat/Modal.js.map +1 -1
  15. package/dist/components/chat/Modal.mjs +2 -2
  16. package/dist/components/chat/Popup.js +6 -105
  17. package/dist/components/chat/Popup.js.map +1 -1
  18. package/dist/components/chat/Popup.mjs +3 -3
  19. package/dist/components/chat/Sidebar.js +6 -105
  20. package/dist/components/chat/Sidebar.js.map +1 -1
  21. package/dist/components/chat/Sidebar.mjs +3 -3
  22. package/dist/components/chat/index.js +6 -105
  23. package/dist/components/chat/index.js.map +1 -1
  24. package/dist/components/chat/index.mjs +4 -4
  25. package/dist/components/index.js +6 -105
  26. package/dist/components/index.js.map +1 -1
  27. package/dist/components/index.mjs +4 -4
  28. package/dist/index.js +8 -107
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.mjs +5 -5
  31. package/package.json +7 -7
  32. package/src/components/chat/Chat.tsx +8 -167
  33. package/src/components/chat/Modal.tsx +0 -4
  34. package/dist/chunk-B6A6OMIG.mjs.map +0 -1
  35. package/dist/chunk-OI5EKZPO.mjs.map +0 -1
  36. /package/dist/{chunk-RQRK6DEW.mjs.map → chunk-TKFQ7VQR.mjs.map} +0 -0
  37. /package/dist/{chunk-Z2RXDT7O.mjs.map → chunk-VYKDFXGS.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,22 +1,21 @@
1
1
  "use client";
2
2
  import "./chunk-EFZPSZWO.mjs";
3
- import "./chunk-IU3WTXLQ.mjs";
4
3
  import "./chunk-MMVDU6DF.mjs";
5
4
  import "./chunk-MRFF7GSQ.mjs";
6
5
  import {
7
6
  CopilotSidebar
8
- } from "./chunk-RQRK6DEW.mjs";
7
+ } from "./chunk-TKFQ7VQR.mjs";
9
8
  import "./chunk-WB3YULQ4.mjs";
10
9
  import {
11
10
  CopilotPopup
12
- } from "./chunk-Z2RXDT7O.mjs";
13
- import "./chunk-B6A6OMIG.mjs";
11
+ } from "./chunk-VYKDFXGS.mjs";
12
+ import "./chunk-63ZKP62F.mjs";
14
13
  import "./chunk-YAGE7RCE.mjs";
15
14
  import "./chunk-VEC45H6Q.mjs";
16
15
  import "./chunk-RQNJNK2W.mjs";
17
16
  import {
18
17
  CopilotChat
19
- } from "./chunk-OI5EKZPO.mjs";
18
+ } from "./chunk-DHGDU64D.mjs";
20
19
  import "./chunk-6INMITFA.mjs";
21
20
  import "./chunk-RU73BEZM.mjs";
22
21
  import "./chunk-V7W6IM2V.mjs";
@@ -43,6 +42,7 @@ import {
43
42
  } from "./chunk-CBBFRI3Q.mjs";
44
43
  import "./chunk-UPTB2MVO.mjs";
45
44
  import "./chunk-FZC7X5PK.mjs";
45
+ import "./chunk-IU3WTXLQ.mjs";
46
46
  import "./chunk-T26KLXLH.mjs";
47
47
  import {
48
48
  useCopilotChatSuggestions
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.4.2-tyler-reset-chat.1",
12
+ "version": "1.4.2",
13
13
  "sideEffects": [
14
14
  "**/*.css"
15
15
  ],
@@ -40,9 +40,9 @@
40
40
  "ts-jest": "^29.1.1",
41
41
  "tsup": "^6.7.0",
42
42
  "typescript": "^5.2.3",
43
- "eslint-config-custom": "1.4.1",
44
- "tailwind-config": "1.4.1",
45
- "tsconfig": "1.4.1"
43
+ "eslint-config-custom": "1.4.2",
44
+ "tailwind-config": "1.4.2",
45
+ "tsconfig": "1.4.2"
46
46
  },
47
47
  "dependencies": {
48
48
  "@headlessui/react": "^2.1.3",
@@ -50,9 +50,9 @@
50
50
  "react-syntax-highlighter": "^15.5.0",
51
51
  "remark-gfm": "^3.0.1",
52
52
  "remark-math": "^5.1.1",
53
- "@copilotkit/react-core": "1.4.2-tyler-reset-chat.1",
54
- "@copilotkit/runtime-client-gql": "1.4.2-tyler-reset-chat.1",
55
- "@copilotkit/shared": "1.4.2-tyler-reset-chat.1"
53
+ "@copilotkit/react-core": "1.4.2",
54
+ "@copilotkit/runtime-client-gql": "1.4.2",
55
+ "@copilotkit/shared": "1.4.2"
56
56
  },
57
57
  "keywords": [
58
58
  "copilotkit",
@@ -73,7 +73,6 @@ import { InputProps, MessagesProps, RenderMessageProps, ResponseButtonProps } fr
73
73
  import { randomId } from "@copilotkit/shared";
74
74
 
75
75
  import { CopilotDevConsole } from "../dev-console";
76
- import { HintFunction, runAgent, stopAgent } from "@copilotkit/react-core";
77
76
 
78
77
  /**
79
78
  * Props for CopilotChat component.
@@ -99,16 +98,6 @@ export interface CopilotChatProps {
99
98
  */
100
99
  onSubmitMessage?: (message: string) => void | Promise<void>;
101
100
 
102
- /**
103
- * A custom stop generation function.
104
- */
105
- onStopGeneration?: OnStopGeneration;
106
-
107
- /**
108
- * A custom reload messages function.
109
- */
110
- onReloadMessages?: OnReloadMessages;
111
-
112
101
  /**
113
102
  * Icons can be used to set custom icons for the chat window.
114
103
  */
@@ -179,62 +168,12 @@ export interface CopilotChatProps {
179
168
  children?: React.ReactNode;
180
169
  }
181
170
 
182
- interface OnStopGenerationArguments {
183
- /**
184
- * The name of the currently executing agent.
185
- */
186
- currentAgentName: string | undefined;
187
-
188
- /**
189
- * The messages in the chat.
190
- */
191
- messages: Message[];
192
-
193
- /**
194
- * Set the messages in the chat.
195
- */
196
- setMessages: (messages: Message[]) => void;
197
-
198
- /**
199
- * Stop chat generation.
200
- */
201
- stopGeneration: () => void;
202
-
203
- /**
204
- * Restart the currently executing agent.
205
- */
206
- restartCurrentAgent: () => void;
207
-
208
- /**
209
- * Stop the currently executing agent.
210
- */
211
- stopCurrentAgent: () => void;
212
-
213
- /**
214
- * Run the currently executing agent.
215
- */
216
- runCurrentAgent: (hint?: HintFunction) => Promise<void>;
217
-
218
- /**
219
- * Set the state of the currently executing agent.
220
- */
221
- setCurrentAgentState: (state: any) => void;
222
- }
223
-
224
- export type OnReloadMessagesArguments = OnStopGenerationArguments;
225
-
226
- export type OnStopGeneration = (args: OnStopGenerationArguments) => void;
227
-
228
- export type OnReloadMessages = (args: OnReloadMessagesArguments) => void;
229
-
230
171
  export function CopilotChat({
231
172
  instructions,
232
173
  onSubmitMessage,
233
174
  makeSystemMessage,
234
175
  showResponseButton = true,
235
176
  onInProgress,
236
- onStopGeneration,
237
- onReloadMessages,
238
177
  Messages = DefaultMessages,
239
178
  RenderTextMessage = DefaultRenderTextMessage,
240
179
  RenderActionExecutionMessage = DefaultRenderActionExecutionMessage,
@@ -259,13 +198,7 @@ export function CopilotChat({
259
198
  sendMessage,
260
199
  stopGeneration,
261
200
  reloadMessages,
262
- } = useCopilotChatLogic(
263
- makeSystemMessage,
264
- onInProgress,
265
- onSubmitMessage,
266
- onStopGeneration,
267
- onReloadMessages,
268
- );
201
+ } = useCopilotChatLogic(makeSystemMessage, onInProgress, onSubmitMessage);
269
202
 
270
203
  const chatContext = React.useContext(ChatContext);
271
204
  const isVisible = chatContext ? chatContext.open : true;
@@ -338,19 +271,12 @@ export const useCopilotChatLogic = (
338
271
  makeSystemMessage?: SystemMessageFunction,
339
272
  onInProgress?: (isLoading: boolean) => void,
340
273
  onSubmitMessage?: (messageContent: string) => Promise<void> | void,
341
- onStopGeneration?: OnStopGeneration,
342
- onReloadMessages?: OnReloadMessages,
343
274
  ) => {
344
- const {
345
- visibleMessages,
346
- appendMessage,
347
- reloadMessages: defaultReloadMessages,
348
- stopGeneration: defaultStopGeneration,
349
- isLoading,
350
- } = useCopilotChat({
351
- id: randomId(),
352
- makeSystemMessage,
353
- });
275
+ const { visibleMessages, appendMessage, reloadMessages, stopGeneration, isLoading } =
276
+ useCopilotChat({
277
+ id: randomId(),
278
+ makeSystemMessage,
279
+ });
354
280
 
355
281
  const [currentSuggestions, setCurrentSuggestions] = useState<CopilotChatSuggestion[]>([]);
356
282
  const suggestionsAbortControllerRef = useRef<AbortController | null>(null);
@@ -387,14 +313,8 @@ export const useCopilotChatLogic = (
387
313
 
388
314
  return () => {
389
315
  clearTimeout(debounceTimerRef.current);
390
- }
391
- }, [
392
- isLoading,
393
- context.chatSuggestionConfiguration,
394
- // hackish way to trigger suggestions reload on reset, but better than moving suggestions to the
395
- // global context
396
- visibleMessages.length == 0,
397
- ]);
316
+ };
317
+ }, [isLoading, context.chatSuggestionConfiguration]);
398
318
 
399
319
  const sendMessage = async (messageContent: string) => {
400
320
  abortSuggestions();
@@ -420,85 +340,6 @@ export const useCopilotChatLogic = (
420
340
  return message;
421
341
  };
422
342
 
423
- const messages = visibleMessages;
424
- const { setMessages } = messagesContext;
425
- const currentAgentName = generalContext.agentSession?.agentName;
426
- const restartCurrentAgent = async (hint?: HintFunction) => {
427
- if (generalContext.agentSession) {
428
- generalContext.setAgentSession({
429
- ...generalContext.agentSession,
430
- nodeName: undefined,
431
- threadId: undefined,
432
- });
433
- generalContext.setCoagentStates((prevAgentStates) => {
434
- return {
435
- ...prevAgentStates,
436
- [generalContext.agentSession!.agentName]: {
437
- ...prevAgentStates[generalContext.agentSession!.agentName],
438
- threadId: undefined,
439
- nodeName: undefined,
440
- runId: undefined,
441
- },
442
- };
443
- });
444
- }
445
- };
446
- const runCurrentAgent = async (hint?: HintFunction) => {
447
- if (generalContext.agentSession) {
448
- await runAgent(generalContext.agentSession.agentName, context, appendMessage, hint);
449
- }
450
- };
451
- const stopCurrentAgent = () => {
452
- if (generalContext.agentSession) {
453
- stopAgent(generalContext.agentSession.agentName, context);
454
- }
455
- };
456
- const setCurrentAgentState = (state: any) => {
457
- if (generalContext.agentSession) {
458
- generalContext.setCoagentStates((prevAgentStates) => {
459
- return {
460
- ...prevAgentStates,
461
- [generalContext.agentSession!.agentName]: {
462
- state,
463
- },
464
- } as any;
465
- });
466
- }
467
- };
468
-
469
- function stopGeneration() {
470
- if (onStopGeneration) {
471
- onStopGeneration({
472
- messages,
473
- setMessages,
474
- stopGeneration: defaultStopGeneration,
475
- currentAgentName,
476
- restartCurrentAgent,
477
- stopCurrentAgent,
478
- runCurrentAgent,
479
- setCurrentAgentState,
480
- });
481
- } else {
482
- defaultStopGeneration();
483
- }
484
- }
485
- function reloadMessages() {
486
- if (onReloadMessages) {
487
- onReloadMessages({
488
- messages,
489
- setMessages,
490
- stopGeneration: defaultStopGeneration,
491
- currentAgentName,
492
- restartCurrentAgent,
493
- stopCurrentAgent,
494
- runCurrentAgent,
495
- setCurrentAgentState,
496
- });
497
- } else {
498
- defaultReloadMessages();
499
- }
500
- }
501
-
502
343
  return {
503
344
  visibleMessages,
504
345
  isLoading,
@@ -63,8 +63,6 @@ export const CopilotModal = ({
63
63
  hitEscapeToClose = true,
64
64
  onSetOpen,
65
65
  onSubmitMessage,
66
- onStopGeneration,
67
- onReloadMessages,
68
66
  shortcut = "/",
69
67
  icons,
70
68
  labels,
@@ -101,8 +99,6 @@ export const CopilotModal = ({
101
99
  <CopilotChat
102
100
  instructions={instructions}
103
101
  onSubmitMessage={onSubmitMessage}
104
- onStopGeneration={onStopGeneration}
105
- onReloadMessages={onReloadMessages}
106
102
  makeSystemMessage={makeSystemMessage}
107
103
  showResponseButton={showResponseButton}
108
104
  onInProgress={onInProgress}
@@ -1 +0,0 @@
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 onStopGeneration,\n onReloadMessages,\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 onStopGeneration={onStopGeneration}\n onReloadMessages={onReloadMessages}\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;AA6FV,cACA,YADA;AAnCD,IAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,mBAAmB;AAAA,EACnB;AAAA,EACA;AAAA,EACA;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;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 +0,0 @@
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\";\nimport { HintFunction, runAgent, stopAgent } from \"@copilotkit/react-core\";\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 * A custom stop generation function.\n */\n onStopGeneration?: OnStopGeneration;\n\n /**\n * A custom reload messages function.\n */\n onReloadMessages?: OnReloadMessages;\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\ninterface OnStopGenerationArguments {\n /**\n * The name of the currently executing agent.\n */\n currentAgentName: string | undefined;\n\n /**\n * The messages in the chat.\n */\n messages: Message[];\n\n /**\n * Set the messages in the chat.\n */\n setMessages: (messages: Message[]) => void;\n\n /**\n * Stop chat generation.\n */\n stopGeneration: () => void;\n\n /**\n * Restart the currently executing agent.\n */\n restartCurrentAgent: () => void;\n\n /**\n * Stop the currently executing agent.\n */\n stopCurrentAgent: () => void;\n\n /**\n * Run the currently executing agent.\n */\n runCurrentAgent: (hint?: HintFunction) => Promise<void>;\n\n /**\n * Set the state of the currently executing agent.\n */\n setCurrentAgentState: (state: any) => void;\n}\n\nexport type OnReloadMessagesArguments = OnStopGenerationArguments;\n\nexport type OnStopGeneration = (args: OnStopGenerationArguments) => void;\n\nexport type OnReloadMessages = (args: OnReloadMessagesArguments) => void;\n\nexport function CopilotChat({\n instructions,\n onSubmitMessage,\n makeSystemMessage,\n showResponseButton = true,\n onInProgress,\n onStopGeneration,\n onReloadMessages,\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(\n makeSystemMessage,\n onInProgress,\n onSubmitMessage,\n onStopGeneration,\n onReloadMessages,\n );\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 onStopGeneration?: OnStopGeneration,\n onReloadMessages?: OnReloadMessages,\n) => {\n const {\n visibleMessages,\n appendMessage,\n reloadMessages: defaultReloadMessages,\n stopGeneration: defaultStopGeneration,\n 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 }, [\n isLoading,\n context.chatSuggestionConfiguration,\n // hackish way to trigger suggestions reload on reset, but better than moving suggestions to the\n // global context\n visibleMessages.length == 0,\n ]);\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 const messages = visibleMessages;\n const { setMessages } = messagesContext;\n const currentAgentName = generalContext.agentSession?.agentName;\n const restartCurrentAgent = async (hint?: HintFunction) => {\n if (generalContext.agentSession) {\n generalContext.setAgentSession({\n ...generalContext.agentSession,\n nodeName: undefined,\n threadId: undefined,\n });\n generalContext.setCoagentStates((prevAgentStates) => {\n return {\n ...prevAgentStates,\n [generalContext.agentSession!.agentName]: {\n ...prevAgentStates[generalContext.agentSession!.agentName],\n threadId: undefined,\n nodeName: undefined,\n runId: undefined,\n },\n };\n });\n }\n };\n const runCurrentAgent = async (hint?: HintFunction) => {\n if (generalContext.agentSession) {\n await runAgent(generalContext.agentSession.agentName, context, appendMessage, hint);\n }\n };\n const stopCurrentAgent = () => {\n if (generalContext.agentSession) {\n stopAgent(generalContext.agentSession.agentName, context);\n }\n };\n const setCurrentAgentState = (state: any) => {\n if (generalContext.agentSession) {\n generalContext.setCoagentStates((prevAgentStates) => {\n return {\n ...prevAgentStates,\n [generalContext.agentSession!.agentName]: {\n state,\n },\n } as any;\n });\n }\n };\n\n function stopGeneration() {\n if (onStopGeneration) {\n onStopGeneration({\n messages,\n setMessages,\n stopGeneration: defaultStopGeneration,\n currentAgentName,\n restartCurrentAgent,\n stopCurrentAgent,\n runCurrentAgent,\n setCurrentAgentState,\n });\n } else {\n defaultStopGeneration();\n }\n }\n function reloadMessages() {\n if (onReloadMessages) {\n onReloadMessages({\n messages,\n setMessages,\n stopGeneration: defaultStopGeneration,\n currentAgentName,\n restartCurrentAgent,\n stopCurrentAgent,\n runCurrentAgent,\n setCurrentAgentState,\n });\n } else {\n defaultReloadMessages();\n }\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;AAGzB,SAAuB,UAAU,iBAAiB;AAuM5C,SAyDG,UAzDH,KAUI,YAVJ;AA7CC,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAAA,YAAW;AAAA,EACX,mBAAAC,qBAAoB;AAAA,EACpB,8BAAAC,gCAA+B;AAAA,EAC/B,yBAAAC,2BAA0B;AAAA,EAC1B,qBAAAC,uBAAsB;AAAA,EACtB,OAAAC,SAAQ;AAAA,EACR,gBAAAC,kBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AACF,GAAqB;AACnB,QAAM,UAAU,kBAAkB;AAElC,YAAU,MAAM;AACd,YAAQ,oBAAoB,gBAAgB,EAAE;AAAA,EAChD,GAAG,CAAC,YAAY,CAAC;AAEjB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,cAAc,MAAM,WAAW,WAAW;AAChD,QAAM,YAAY,cAAc,YAAY,OAAO;AAEnD,SACE,qBAAC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L,4BAAsB;AAAA,IACxB;AAAA,EACF;AACA,WAAS,iBAAiB;AACxB,QAAI,kBAAkB;AACpB,uBAAiB;AAAA,QACf;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,QAChB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,OAAO;AACL,4BAAsB;AAAA,IACxB;AAAA,EACF;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","_a"]}