@copilotkit/react-ui 1.0.8 → 1.0.9-mme-modify-append-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.
- package/CHANGELOG.md +10 -0
- package/dist/{chunk-I3WXFPLM.mjs → chunk-6TWACO5V.mjs} +2 -2
- package/dist/{chunk-CTQJBYFS.mjs → chunk-IN42MBI2.mjs} +2 -2
- package/dist/{chunk-I2SHVGZG.mjs → chunk-NS5XXT5G.mjs} +2 -2
- package/dist/{chunk-MGUNADV2.mjs → chunk-VPUIM2ZY.mjs} +8 -2
- package/dist/chunk-VPUIM2ZY.mjs.map +1 -0
- package/dist/components/chat/Chat.d.ts +1 -1
- package/dist/components/chat/Chat.js +7 -1
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +1 -1
- package/dist/components/chat/Modal.js +7 -1
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +2 -2
- package/dist/components/chat/Popup.js +7 -1
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +3 -3
- package/dist/components/chat/Sidebar.js +7 -1
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +3 -3
- package/dist/components/chat/index.js +7 -1
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +4 -4
- package/dist/components/index.js +7 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -4
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/package.json +7 -7
- package/src/components/chat/Chat.tsx +8 -2
- package/dist/chunk-MGUNADV2.mjs.map +0 -1
- /package/dist/{chunk-I3WXFPLM.mjs.map → chunk-6TWACO5V.mjs.map} +0 -0
- /package/dist/{chunk-CTQJBYFS.mjs.map → chunk-IN42MBI2.mjs.map} +0 -0
- /package/dist/{chunk-I2SHVGZG.mjs.map → chunk-NS5XXT5G.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 1.0.9-mme-modify-append-message.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modify appendMessage to replace current message when in progress
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @copilotkit/react-core@1.0.9-mme-modify-append-message.0
|
|
10
|
+
- @copilotkit/runtime-client-gql@1.0.9-mme-modify-append-message.0
|
|
11
|
+
- @copilotkit/shared@1.0.9-mme-modify-append-message.0
|
|
12
|
+
|
|
3
13
|
## 1.0.8
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "./chunk-UC3Y7MWX.mjs";
|
|
10
10
|
import {
|
|
11
11
|
CopilotChat
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-VPUIM2ZY.mjs";
|
|
13
13
|
import {
|
|
14
14
|
Input
|
|
15
15
|
} from "./chunk-U6J5DGOE.mjs";
|
|
@@ -90,4 +90,4 @@ var CopilotModal = ({
|
|
|
90
90
|
export {
|
|
91
91
|
CopilotModal
|
|
92
92
|
};
|
|
93
|
-
//# sourceMappingURL=chunk-
|
|
93
|
+
//# sourceMappingURL=chunk-6TWACO5V.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotModal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6TWACO5V.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-
|
|
30
|
+
//# sourceMappingURL=chunk-IN42MBI2.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotModal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6TWACO5V.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-
|
|
21
|
+
//# sourceMappingURL=chunk-NS5XXT5G.mjs.map
|
|
@@ -135,7 +135,13 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
135
135
|
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
136
136
|
abortSuggestions();
|
|
137
137
|
setCurrentSuggestions([]);
|
|
138
|
-
|
|
138
|
+
if (onSubmitMessage) {
|
|
139
|
+
try {
|
|
140
|
+
yield onSubmitMessage(messageContent);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error("Error in onSubmitMessage:", error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
139
145
|
const message = new TextMessage({
|
|
140
146
|
content: messageContent,
|
|
141
147
|
role: Role.User
|
|
@@ -158,4 +164,4 @@ export {
|
|
|
158
164
|
WrappedCopilotChat,
|
|
159
165
|
useCopilotChatLogic
|
|
160
166
|
};
|
|
161
|
-
//# sourceMappingURL=chunk-
|
|
167
|
+
//# sourceMappingURL=chunk-VPUIM2ZY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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 | 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 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 if (onSubmitMessage) {\n try {\n await onSubmitMessage(messageContent);\n } catch (error) {\n console.error(\"Error in onSubmitMessage:\", error);\n }\n }\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,yB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AuC;AACvC,kCAA8B,UAAU;AAAA,EAC1C;AAEA,QAAM,UAAU,kBAAkB;AAElC,YAAU,MAAM;AACd,iDAAe;AAEf,qBAAiB;AAEjB,qBAAiB,UAAU;AAAA,MACzB,MAAM;AACJ,YAAI,CAAC,aAAa,OAAO,KAAK,QAAQ,2BAA2B,EAAE,WAAW,GAAG;AAC/E,wCAA8B,UAAU,IAAI,gBAAgB;AAC5D;AAAA,YACE;AAAA,YACA,QAAQ;AAAA,YACR;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,mBAAmB,UAAU,IAAI,IAAI;AAAA,IACvC;AAEA,WAAO,MAAM;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;AACxB,QAAI,iBAAiB;AACnB,UAAI;AACF,cAAM,gBAAgB,cAAc;AAAA,MACtC,SAAS,OAAP;AACA,gBAAQ,MAAM,6BAA6B,KAAK;AAAA,MAClD;AAAA,IACF;AACA,UAAM,UAAmB,IAAI,YAAY;AAAA,MACvC,SAAS;AAAA,MACT,MAAM,KAAK;AAAA,IACb,CAAC;AACD,kBAAc,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["Messages","Input","ResponseButton"]}
|
|
@@ -71,7 +71,7 @@ interface CopilotChatProps {
|
|
|
71
71
|
/**
|
|
72
72
|
* A callback that gets called when a new message it submitted.
|
|
73
73
|
*/
|
|
74
|
-
onSubmitMessage?: (message: string) => void
|
|
74
|
+
onSubmitMessage?: (message: string) => void | Promise<void>;
|
|
75
75
|
/**
|
|
76
76
|
* Icons can be used to set custom icons for the chat window.
|
|
77
77
|
*/
|
|
@@ -1745,7 +1745,13 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
1745
1745
|
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
1746
1746
|
abortSuggestions();
|
|
1747
1747
|
setCurrentSuggestions([]);
|
|
1748
|
-
|
|
1748
|
+
if (onSubmitMessage) {
|
|
1749
|
+
try {
|
|
1750
|
+
yield onSubmitMessage(messageContent);
|
|
1751
|
+
} catch (error) {
|
|
1752
|
+
console.error("Error in onSubmitMessage:", error);
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1749
1755
|
const message = new import_runtime_client_gql4.TextMessage({
|
|
1750
1756
|
content: messageContent,
|
|
1751
1757
|
role: import_runtime_client_gql4.Role.User
|