@copilotkit/react-ui 1.0.8 → 1.0.9-pre-async-submit-message.0

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 (34) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/{chunk-I3WXFPLM.mjs → chunk-6TWACO5V.mjs} +2 -2
  3. package/dist/{chunk-CTQJBYFS.mjs → chunk-IN42MBI2.mjs} +2 -2
  4. package/dist/{chunk-I2SHVGZG.mjs → chunk-NS5XXT5G.mjs} +2 -2
  5. package/dist/{chunk-MGUNADV2.mjs → chunk-VPUIM2ZY.mjs} +8 -2
  6. package/dist/chunk-VPUIM2ZY.mjs.map +1 -0
  7. package/dist/components/chat/Chat.d.ts +1 -1
  8. package/dist/components/chat/Chat.js +7 -1
  9. package/dist/components/chat/Chat.js.map +1 -1
  10. package/dist/components/chat/Chat.mjs +1 -1
  11. package/dist/components/chat/Modal.js +7 -1
  12. package/dist/components/chat/Modal.js.map +1 -1
  13. package/dist/components/chat/Modal.mjs +2 -2
  14. package/dist/components/chat/Popup.js +7 -1
  15. package/dist/components/chat/Popup.js.map +1 -1
  16. package/dist/components/chat/Popup.mjs +3 -3
  17. package/dist/components/chat/Sidebar.js +7 -1
  18. package/dist/components/chat/Sidebar.js.map +1 -1
  19. package/dist/components/chat/Sidebar.mjs +3 -3
  20. package/dist/components/chat/index.js +7 -1
  21. package/dist/components/chat/index.js.map +1 -1
  22. package/dist/components/chat/index.mjs +4 -4
  23. package/dist/components/index.js +7 -1
  24. package/dist/components/index.js.map +1 -1
  25. package/dist/components/index.mjs +4 -4
  26. package/dist/index.js +7 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +4 -4
  29. package/package.json +7 -7
  30. package/src/components/chat/Chat.tsx +8 -2
  31. package/dist/chunk-MGUNADV2.mjs.map +0 -1
  32. /package/dist/{chunk-I3WXFPLM.mjs.map → chunk-6TWACO5V.mjs.map} +0 -0
  33. /package/dist/{chunk-CTQJBYFS.mjs.map → chunk-IN42MBI2.mjs.map} +0 -0
  34. /package/dist/{chunk-I2SHVGZG.mjs.map → chunk-NS5XXT5G.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -4,18 +4,18 @@ import "./chunk-JD7BAH7U.mjs";
4
4
  import "./chunk-MRFF7GSQ.mjs";
5
5
  import {
6
6
  CopilotSidebar
7
- } from "./chunk-CTQJBYFS.mjs";
7
+ } from "./chunk-IN42MBI2.mjs";
8
8
  import "./chunk-WB3YULQ4.mjs";
9
9
  import {
10
10
  CopilotPopup
11
- } from "./chunk-I2SHVGZG.mjs";
12
- import "./chunk-I3WXFPLM.mjs";
11
+ } from "./chunk-NS5XXT5G.mjs";
12
+ import "./chunk-6TWACO5V.mjs";
13
13
  import "./chunk-B7DNOYVQ.mjs";
14
14
  import "./chunk-SE6DAYSX.mjs";
15
15
  import "./chunk-UC3Y7MWX.mjs";
16
16
  import {
17
17
  CopilotChat
18
- } from "./chunk-MGUNADV2.mjs";
18
+ } from "./chunk-VPUIM2ZY.mjs";
19
19
  import "./chunk-V7W6IM2V.mjs";
20
20
  import "./chunk-KSCXPA74.mjs";
21
21
  import "./chunk-M5A56FBF.mjs";
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.0.8",
12
+ "version": "1.0.9-pre-async-submit-message.0",
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.0.2",
44
- "tailwind-config": "1.0.2",
45
- "tsconfig": "1.0.2"
43
+ "eslint-config-custom": "1.0.3-pre-async-submit-message.0",
44
+ "tsconfig": "1.0.3-pre-async-submit-message.0",
45
+ "tailwind-config": "1.0.3-pre-async-submit-message.0"
46
46
  },
47
47
  "dependencies": {
48
48
  "@headlessui/react": "^2.1.2",
@@ -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.0.8",
54
- "@copilotkit/runtime-client-gql": "1.0.8",
55
- "@copilotkit/shared": "1.0.8"
53
+ "@copilotkit/react-core": "1.0.9-pre-async-submit-message.0",
54
+ "@copilotkit/runtime-client-gql": "1.0.9-pre-async-submit-message.0",
55
+ "@copilotkit/shared": "1.0.9-pre-async-submit-message.0"
56
56
  },
57
57
  "keywords": [
58
58
  "copilotkit",
@@ -86,7 +86,7 @@ export interface CopilotChatProps {
86
86
  /**
87
87
  * A callback that gets called when a new message it submitted.
88
88
  */
89
- onSubmitMessage?: (message: string) => void;
89
+ onSubmitMessage?: (message: string) => void | Promise<void>;
90
90
 
91
91
  /**
92
92
  * Icons can be used to set custom icons for the chat window.
@@ -276,7 +276,13 @@ export const useCopilotChatLogic = (
276
276
  const sendMessage = async (messageContent: string) => {
277
277
  abortSuggestions();
278
278
  setCurrentSuggestions([]);
279
- onSubmitMessage?.(messageContent);
279
+ if (onSubmitMessage) {
280
+ try {
281
+ await onSubmitMessage(messageContent);
282
+ } catch (error) {
283
+ console.error("Error in onSubmitMessage:", error);
284
+ }
285
+ }
280
286
  const message: Message = new TextMessage({
281
287
  content: messageContent,
282
288
  role: Role.User,
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/chat/Chat.tsx"],"sourcesContent":["/**\n * An embeddable chat panel for CopilotKit.\n *\n * <img src=\"/images/CopilotChat/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 * <RequestExample>\n * ```jsx CopilotChat Example\n * import { CopilotChat } from \"@copilotkit/react-ui\";\n *\n * <CopilotChat\n * labels={{\n * title: \"Your Assistant\",\n * initial: \"Hi! 👋 How can I assist you today?\",\n * }}\n * />\n * ```\n * </RequestExample>\n *\n * ## Custom CSS\n *\n * You can customize the colors of the panel by overriding the CSS variables\n * defined in the [default styles](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-ui/src/css/colors.css).\n *\n * For example, to set the primary color to purple:\n *\n * ```jsx\n * <div style={{ \"--copilot-kit-primary-color\": \"#7D5BA6\" }}>\n * <CopilotPopup />\n * </div>\n * ```\n *\n * To further customize the panel, you can override the CSS classes defined\n * [here](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/packages/react-ui/src/css/).\n *\n * For example:\n *\n * ```css\n * .copilotKitButton {\n * border-radius: 0;\n * }\n * ```\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 { Suggestion } from \"./Suggestion\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { SystemMessageFunction, useCopilotChat, useCopilotContext } 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, 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;\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 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 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 messages={visibleMessages} inProgress={isLoading}>\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) => 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 context = useCopilotContext();\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 onSubmitMessage?.(messageContent);\n const message: Message = new TextMessage({\n content: messageContent,\n role: Role.User,\n });\n appendMessage(message);\n return message;\n };\n\n return {\n visibleMessages,\n isLoading,\n currentSuggestions,\n sendMessage,\n stopGeneration,\n reloadMessages,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,OAAO,SAAS,WAAW,QAAQ,gBAAgB;AACnD,SAAgC,gBAAgB,yBAAyB;AAGzE,SAAkB,MAAM,mBAAmB;AAE3C,SAAS,gBAAgB;AA+GnB,SAkDG,UAlDH,KAGI,YAHJ;AAjCC,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EACA,UAAAA,YAAW;AAAA,EACX,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,oBAAoB,mBAAmB,cAAc,eAAe;AAExE,QAAM,cAAc,MAAM,WAAW,WAAW;AAChD,QAAM,YAAY,cAAc,YAAY,OAAO;AAEnD,SACE,qBAAC,sBAAmB,OAAc,QAAgB,WAChD;AAAA,wBAAC,qBAAkB;AAAA,IACnB,qBAACF,WAAA,EAAS,UAAU,iBAAiB,YAAY,WAC9C;AAAA,yBAAmB,SAAS,KAC3B,qBAAC,SACC;AAAA,4BAAC,QAAG,wBAAU;AAAA,QACd,oBAAC,SAAI,WAAU,eACZ,6BAAmB,IAAI,CAAC,YAAY,UACnC;AAAA,UAAC;AAAA;AAAA,YAEC,OAAO,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