@copilotkit/react-ui 1.4.8 → 1.5.0-coagents-v0-3.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 +15 -0
- package/dist/{chunk-CVHT5XCA.mjs → chunk-375NVWZM.mjs} +2 -2
- package/dist/{chunk-OMTPWC7T.mjs → chunk-3E7HY2UN.mjs} +5 -4
- package/dist/chunk-3E7HY2UN.mjs.map +1 -0
- package/dist/{chunk-RKPANT3F.mjs → chunk-7II4YL7R.mjs} +2 -6
- package/dist/chunk-7II4YL7R.mjs.map +1 -0
- package/dist/{chunk-46UJJGXP.mjs → chunk-DCNCY2PL.mjs} +113 -10
- package/dist/chunk-DCNCY2PL.mjs.map +1 -0
- package/dist/{chunk-DVMTTXGZ.mjs → chunk-F2W5FD7L.mjs} +2 -2
- package/dist/{chunk-4FIGRRFS.mjs → chunk-PNQVKBPN.mjs} +2 -2
- package/dist/{chunk-4FIGRRFS.mjs.map → chunk-PNQVKBPN.mjs.map} +1 -1
- package/dist/{chunk-752NGHCE.mjs → chunk-UWVGLGFQ.mjs} +7 -3
- package/dist/chunk-UWVGLGFQ.mjs.map +1 -0
- package/dist/{chunk-PNKBFDUI.mjs → chunk-WSMMTZCM.mjs} +2 -2
- package/dist/components/chat/Chat.d.ts +50 -5
- package/dist/components/chat/Chat.js +115 -12
- package/dist/components/chat/Chat.js.map +1 -1
- package/dist/components/chat/Chat.mjs +5 -5
- package/dist/components/chat/Messages.d.ts +3 -3
- package/dist/components/chat/Messages.js.map +1 -1
- package/dist/components/chat/Messages.mjs +1 -1
- package/dist/components/chat/Modal.d.ts +1 -1
- package/dist/components/chat/Modal.js +119 -12
- package/dist/components/chat/Modal.js.map +1 -1
- package/dist/components/chat/Modal.mjs +6 -6
- package/dist/components/chat/Popup.js +119 -12
- package/dist/components/chat/Popup.js.map +1 -1
- package/dist/components/chat/Popup.mjs +7 -7
- package/dist/components/chat/Sidebar.js +119 -12
- package/dist/components/chat/Sidebar.js.map +1 -1
- package/dist/components/chat/Sidebar.mjs +7 -7
- package/dist/components/chat/index.js +119 -12
- package/dist/components/chat/index.js.map +1 -1
- package/dist/components/chat/index.mjs +8 -8
- package/dist/components/chat/messages/RenderActionExecutionMessage.js +4 -3
- package/dist/components/chat/messages/RenderActionExecutionMessage.js.map +1 -1
- package/dist/components/chat/messages/RenderActionExecutionMessage.mjs +1 -1
- package/dist/components/dev-console/console.js +1 -1
- package/dist/components/dev-console/console.js.map +1 -1
- package/dist/components/dev-console/console.mjs +2 -2
- package/dist/components/dev-console/index.js +1 -1
- package/dist/components/dev-console/index.js.map +1 -1
- package/dist/components/dev-console/index.mjs +2 -2
- package/dist/components/dev-console/utils.js +1 -1
- package/dist/components/dev-console/utils.js.map +1 -1
- package/dist/components/dev-console/utils.mjs +1 -1
- package/dist/components/index.js +119 -12
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +8 -8
- package/dist/index.js +121 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -8
- package/package.json +4 -4
- package/src/components/chat/Chat.tsx +173 -7
- package/src/components/chat/Messages.tsx +2 -9
- package/src/components/chat/Modal.tsx +4 -0
- package/src/components/chat/messages/RenderActionExecutionMessage.tsx +10 -3
- package/src/components/dev-console/utils.ts +1 -1
- package/dist/chunk-46UJJGXP.mjs.map +0 -1
- package/dist/chunk-752NGHCE.mjs.map +0 -1
- package/dist/chunk-OMTPWC7T.mjs.map +0 -1
- package/dist/chunk-RKPANT3F.mjs.map +0 -1
- /package/dist/{chunk-CVHT5XCA.mjs.map → chunk-375NVWZM.mjs.map} +0 -0
- /package/dist/{chunk-DVMTTXGZ.mjs.map → chunk-F2W5FD7L.mjs.map} +0 -0
- /package/dist/{chunk-PNKBFDUI.mjs.map → chunk-WSMMTZCM.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# ui
|
|
2
2
|
|
|
3
|
+
## 1.5.0-coagents-v0-3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Synchronize LangGraph messages with CopilotKit
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- e66bce4: CoAgents v0.3 prerelease
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies [e66bce4]
|
|
14
|
+
- @copilotkit/runtime-client-gql@1.5.0-coagents-v0-3.0
|
|
15
|
+
- @copilotkit/react-core@1.5.0-coagents-v0-3.0
|
|
16
|
+
- @copilotkit/shared@1.5.0-coagents-v0-3.0
|
|
17
|
+
|
|
3
18
|
## 1.4.8
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotModal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UWVGLGFQ.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-375NVWZM.mjs.map
|
|
@@ -11,8 +11,8 @@ function RenderActionExecutionMessage(props) {
|
|
|
11
11
|
const { chatComponentsCache } = useCopilotContext();
|
|
12
12
|
const { icons } = useChatContext();
|
|
13
13
|
if (message.isActionExecutionMessage()) {
|
|
14
|
-
if (chatComponentsCache.current !== null && chatComponentsCache.current.actions[message.name]) {
|
|
15
|
-
const render = chatComponentsCache.current.actions[message.name];
|
|
14
|
+
if (chatComponentsCache.current !== null && (chatComponentsCache.current.actions[message.name] || chatComponentsCache.current.actions["*"])) {
|
|
15
|
+
const render = chatComponentsCache.current.actions[message.name] || chatComponentsCache.current.actions["*"];
|
|
16
16
|
if (typeof render === "string") {
|
|
17
17
|
if (isCurrentMessage && inProgress) {
|
|
18
18
|
return /* @__PURE__ */ jsxs("div", { className: `copilotKitMessage copilotKitAssistantMessage`, children: [
|
|
@@ -35,7 +35,8 @@ function RenderActionExecutionMessage(props) {
|
|
|
35
35
|
const toRender = render({
|
|
36
36
|
status,
|
|
37
37
|
args,
|
|
38
|
-
result: actionResult
|
|
38
|
+
result: actionResult,
|
|
39
|
+
name: message.name
|
|
39
40
|
});
|
|
40
41
|
if (!toRender && status === "complete") {
|
|
41
42
|
return null;
|
|
@@ -81,4 +82,4 @@ function RenderActionExecutionMessage(props) {
|
|
|
81
82
|
export {
|
|
82
83
|
RenderActionExecutionMessage
|
|
83
84
|
};
|
|
84
|
-
//# sourceMappingURL=chunk-
|
|
85
|
+
//# sourceMappingURL=chunk-3E7HY2UN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/messages/RenderActionExecutionMessage.tsx"],"sourcesContent":["import { MessageStatusCode } from \"@copilotkit/runtime-client-gql\";\nimport { RenderMessageProps } from \"../props\";\nimport { useChatContext } from \"../ChatContext\";\nimport { RenderFunctionStatus, useCopilotContext } from \"@copilotkit/react-core\";\n\nexport function RenderActionExecutionMessage(props: RenderMessageProps) {\n const { message, inProgress, index, isCurrentMessage, actionResult } = props;\n const { chatComponentsCache } = useCopilotContext();\n const { icons } = useChatContext();\n\n if (message.isActionExecutionMessage()) {\n if (\n chatComponentsCache.current !== null &&\n (chatComponentsCache.current.actions[message.name] ||\n chatComponentsCache.current.actions[\"*\"])\n ) {\n const render =\n chatComponentsCache.current.actions[message.name] ||\n chatComponentsCache.current.actions[\"*\"];\n // render a static string\n if (typeof render === \"string\") {\n // when render is static, we show it only when in progress\n if (isCurrentMessage && inProgress) {\n return (\n <div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>\n {icons.spinnerIcon} <span className=\"inProgressLabel\">{render}</span>\n </div>\n );\n }\n // Done - silent by default to avoid a series of \"done\" messages\n else {\n return null;\n }\n }\n // render is a function\n else {\n const args = message.arguments;\n\n let status: RenderFunctionStatus = \"inProgress\";\n\n if (actionResult !== undefined) {\n status = \"complete\";\n } else if (message.status.code !== MessageStatusCode.Pending) {\n status = \"executing\";\n }\n\n try {\n const toRender = render({\n status: status as any,\n args,\n result: actionResult,\n name: message.name,\n });\n // No result and complete: stay silent\n if (!toRender && status === \"complete\") {\n return null;\n }\n if (typeof toRender === \"string\") {\n return (\n <div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>\n {isCurrentMessage && inProgress && icons.spinnerIcon} {toRender}\n </div>\n );\n } else {\n return (\n <div\n key={index}\n data-message-type=\"action-render\"\n className=\"copilotKitCustomAssistantMessage\"\n >\n {toRender}\n </div>\n );\n }\n } catch (e) {\n console.error(`Error executing render function for action ${message.name}: ${e}`);\n return (\n <div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>\n {isCurrentMessage && inProgress && icons.spinnerIcon}\n <b>❌ Error executing render: {message.name}</b>\n <br />\n {e instanceof Error ? e.message : String(e)}\n </div>\n );\n }\n }\n }\n // No render function found- show the default message\n else if (!inProgress || !isCurrentMessage) {\n // Done - silent by default to avoid a series of \"done\" messages\n return null;\n } else {\n // In progress\n return (\n <div key={index} className={`copilotKitMessage copilotKitAssistantMessage`}>\n {icons.spinnerIcon}\n </div>\n );\n }\n }\n}\n"],"mappings":";;;;;AAAA,SAAS,yBAAyB;AAGlC,SAA+B,yBAAyB;AAqB5C,SACsB,KADtB;AAnBL,SAAS,6BAA6B,OAA2B;AACtE,QAAM,EAAE,SAAS,YAAY,OAAO,kBAAkB,aAAa,IAAI;AACvE,QAAM,EAAE,oBAAoB,IAAI,kBAAkB;AAClD,QAAM,EAAE,MAAM,IAAI,eAAe;AAEjC,MAAI,QAAQ,yBAAyB,GAAG;AACtC,QACE,oBAAoB,YAAY,SAC/B,oBAAoB,QAAQ,QAAQ,QAAQ,IAAI,KAC/C,oBAAoB,QAAQ,QAAQ,GAAG,IACzC;AACA,YAAM,SACJ,oB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;AAAA,QAEJ;AAAA,MACF;AAAA,IACF,WAES,CAAC,cAAc,CAAC,kBAAkB;AAEzC,aAAO;AAAA,IACT,OAAO;AAEL,aACE,oBAAC,SAAgB,WAAW,gDACzB,gBAAM,eADC,KAEV;AAAA,IAEJ;AAAA,EACF;AACF;","names":[]}
|
|
@@ -4,11 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/components/chat/Messages.tsx
|
|
6
6
|
import { useEffect, useMemo, useRef } from "react";
|
|
7
|
-
import {
|
|
8
|
-
ResultMessage,
|
|
9
|
-
TextMessage,
|
|
10
|
-
Role
|
|
11
|
-
} from "@copilotkit/runtime-client-gql";
|
|
7
|
+
import { ResultMessage, TextMessage, Role } from "@copilotkit/runtime-client-gql";
|
|
12
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
9
|
var Messages = ({
|
|
14
10
|
messages,
|
|
@@ -171,4 +167,4 @@ export {
|
|
|
171
167
|
Messages,
|
|
172
168
|
useScrollToBottom
|
|
173
169
|
};
|
|
174
|
-
//# sourceMappingURL=chunk-
|
|
170
|
+
//# sourceMappingURL=chunk-7II4YL7R.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/chat/Messages.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport { MessagesProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport { Message, ResultMessage, TextMessage, Role } 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,SAAS,WAAW,SAAS,cAAc;AAG3C,SAAkB,eAAe,aAAa,YAAY;AAoCtD,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;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,WAAO,MAAM;AACX,uBAAiB,WAAW;AAAA,IAC9B;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,sBAAkB,UAAU;AAC5B,mBAAe;AAAA,EACjB,GAAG,CAAC,SAAS,OAAO,CAAC,MAAM,EAAE,cAAc,KAAK,EAAE,SAAS,KAAK,IAAI,EAAE,MAAM,CAAC;AAE7E,SAAO,EAAE,gBAAgB,qBAAqB;AAChD;","names":[]}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-RU73BEZM.mjs";
|
|
7
7
|
import {
|
|
8
8
|
RenderActionExecutionMessage
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-3E7HY2UN.mjs";
|
|
10
10
|
import {
|
|
11
11
|
RenderAgentStateMessage
|
|
12
12
|
} from "./chunk-ZABXREBH.mjs";
|
|
@@ -16,13 +16,13 @@ import {
|
|
|
16
16
|
} from "./chunk-RJCZRKTV.mjs";
|
|
17
17
|
import {
|
|
18
18
|
CopilotDevConsole
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-F2W5FD7L.mjs";
|
|
20
20
|
import {
|
|
21
21
|
Input
|
|
22
22
|
} from "./chunk-EMQEEXUB.mjs";
|
|
23
23
|
import {
|
|
24
24
|
Messages
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-7II4YL7R.mjs";
|
|
26
26
|
import {
|
|
27
27
|
ResponseButton
|
|
28
28
|
} from "./chunk-3XAXY2Z3.mjs";
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from "./chunk-CBBFRI3Q.mjs";
|
|
33
33
|
import {
|
|
34
34
|
__async,
|
|
35
|
+
__spreadProps,
|
|
35
36
|
__spreadValues
|
|
36
37
|
} from "./chunk-MRXNTQOX.mjs";
|
|
37
38
|
|
|
@@ -44,6 +45,7 @@ import {
|
|
|
44
45
|
} from "@copilotkit/react-core";
|
|
45
46
|
import { Role, TextMessage } from "@copilotkit/runtime-client-gql";
|
|
46
47
|
import { randomId } from "@copilotkit/shared";
|
|
48
|
+
import { runAgent, stopAgent } from "@copilotkit/react-core";
|
|
47
49
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
48
50
|
function CopilotChat({
|
|
49
51
|
instructions,
|
|
@@ -51,6 +53,8 @@ function CopilotChat({
|
|
|
51
53
|
makeSystemMessage,
|
|
52
54
|
showResponseButton = true,
|
|
53
55
|
onInProgress,
|
|
56
|
+
onStopGeneration,
|
|
57
|
+
onReloadMessages,
|
|
54
58
|
Messages: Messages2 = Messages,
|
|
55
59
|
RenderTextMessage: RenderTextMessage2 = RenderTextMessage,
|
|
56
60
|
RenderActionExecutionMessage: RenderActionExecutionMessage2 = RenderActionExecutionMessage,
|
|
@@ -73,7 +77,13 @@ function CopilotChat({
|
|
|
73
77
|
sendMessage,
|
|
74
78
|
stopGeneration,
|
|
75
79
|
reloadMessages
|
|
76
|
-
} = useCopilotChatLogic(
|
|
80
|
+
} = useCopilotChatLogic(
|
|
81
|
+
makeSystemMessage,
|
|
82
|
+
onInProgress,
|
|
83
|
+
onSubmitMessage,
|
|
84
|
+
onStopGeneration,
|
|
85
|
+
onReloadMessages
|
|
86
|
+
);
|
|
77
87
|
const chatContext = React.useContext(ChatContext);
|
|
78
88
|
const isVisible = chatContext ? chatContext.open : true;
|
|
79
89
|
return /* @__PURE__ */ jsxs(WrappedCopilotChat, { icons, labels, className, children: [
|
|
@@ -129,8 +139,16 @@ function WrappedCopilotChat({
|
|
|
129
139
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
130
140
|
}
|
|
131
141
|
var SUGGESTIONS_DEBOUNCE_TIMEOUT = 1e3;
|
|
132
|
-
var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) => {
|
|
133
|
-
|
|
142
|
+
var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
|
|
143
|
+
var _a;
|
|
144
|
+
const {
|
|
145
|
+
visibleMessages,
|
|
146
|
+
appendMessage,
|
|
147
|
+
reloadMessages: defaultReloadMessages,
|
|
148
|
+
stopGeneration: defaultStopGeneration,
|
|
149
|
+
runChatCompletion,
|
|
150
|
+
isLoading
|
|
151
|
+
} = useCopilotChat({
|
|
134
152
|
id: randomId(),
|
|
135
153
|
makeSystemMessage
|
|
136
154
|
});
|
|
@@ -138,8 +156,8 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
138
156
|
const suggestionsAbortControllerRef = useRef(null);
|
|
139
157
|
const debounceTimerRef = useRef();
|
|
140
158
|
const abortSuggestions = () => {
|
|
141
|
-
var
|
|
142
|
-
(
|
|
159
|
+
var _a2;
|
|
160
|
+
(_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort();
|
|
143
161
|
suggestionsAbortControllerRef.current = null;
|
|
144
162
|
};
|
|
145
163
|
const generalContext = useCopilotContext();
|
|
@@ -165,7 +183,13 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
165
183
|
return () => {
|
|
166
184
|
clearTimeout(debounceTimerRef.current);
|
|
167
185
|
};
|
|
168
|
-
}, [
|
|
186
|
+
}, [
|
|
187
|
+
isLoading,
|
|
188
|
+
context.chatSuggestionConfiguration,
|
|
189
|
+
// hackish way to trigger suggestions reload on reset, but better than moving suggestions to the
|
|
190
|
+
// global context
|
|
191
|
+
visibleMessages.length == 0
|
|
192
|
+
]);
|
|
169
193
|
const sendMessage = (messageContent) => __async(void 0, null, function* () {
|
|
170
194
|
abortSuggestions();
|
|
171
195
|
setCurrentSuggestions([]);
|
|
@@ -183,6 +207,85 @@ var useCopilotChatLogic = (makeSystemMessage, onInProgress, onSubmitMessage) =>
|
|
|
183
207
|
appendMessage(message);
|
|
184
208
|
return message;
|
|
185
209
|
});
|
|
210
|
+
const messages = visibleMessages;
|
|
211
|
+
const { setMessages } = messagesContext;
|
|
212
|
+
const currentAgentName = (_a = generalContext.agentSession) == null ? void 0 : _a.agentName;
|
|
213
|
+
const restartCurrentAgent = (hint) => __async(void 0, null, function* () {
|
|
214
|
+
if (generalContext.agentSession) {
|
|
215
|
+
generalContext.setAgentSession(__spreadProps(__spreadValues({}, generalContext.agentSession), {
|
|
216
|
+
nodeName: void 0,
|
|
217
|
+
threadId: void 0
|
|
218
|
+
}));
|
|
219
|
+
generalContext.setCoagentStates((prevAgentStates) => {
|
|
220
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
221
|
+
[generalContext.agentSession.agentName]: __spreadProps(__spreadValues({}, prevAgentStates[generalContext.agentSession.agentName]), {
|
|
222
|
+
threadId: void 0,
|
|
223
|
+
nodeName: void 0,
|
|
224
|
+
runId: void 0
|
|
225
|
+
})
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
const runCurrentAgent = (hint) => __async(void 0, null, function* () {
|
|
231
|
+
if (generalContext.agentSession) {
|
|
232
|
+
yield runAgent(
|
|
233
|
+
generalContext.agentSession.agentName,
|
|
234
|
+
context,
|
|
235
|
+
appendMessage,
|
|
236
|
+
runChatCompletion,
|
|
237
|
+
hint
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
const stopCurrentAgent = () => {
|
|
242
|
+
if (generalContext.agentSession) {
|
|
243
|
+
stopAgent(generalContext.agentSession.agentName, context);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const setCurrentAgentState = (state) => {
|
|
247
|
+
if (generalContext.agentSession) {
|
|
248
|
+
generalContext.setCoagentStates((prevAgentStates) => {
|
|
249
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
250
|
+
[generalContext.agentSession.agentName]: {
|
|
251
|
+
state
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
function stopGeneration() {
|
|
258
|
+
if (onStopGeneration) {
|
|
259
|
+
onStopGeneration({
|
|
260
|
+
messages,
|
|
261
|
+
setMessages,
|
|
262
|
+
stopGeneration: defaultStopGeneration,
|
|
263
|
+
currentAgentName,
|
|
264
|
+
restartCurrentAgent,
|
|
265
|
+
stopCurrentAgent,
|
|
266
|
+
runCurrentAgent,
|
|
267
|
+
setCurrentAgentState
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
defaultStopGeneration();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function reloadMessages() {
|
|
274
|
+
if (onReloadMessages) {
|
|
275
|
+
onReloadMessages({
|
|
276
|
+
messages,
|
|
277
|
+
setMessages,
|
|
278
|
+
stopGeneration: defaultStopGeneration,
|
|
279
|
+
currentAgentName,
|
|
280
|
+
restartCurrentAgent,
|
|
281
|
+
stopCurrentAgent,
|
|
282
|
+
runCurrentAgent,
|
|
283
|
+
setCurrentAgentState
|
|
284
|
+
});
|
|
285
|
+
} else {
|
|
286
|
+
defaultReloadMessages();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
186
289
|
return {
|
|
187
290
|
visibleMessages,
|
|
188
291
|
isLoading,
|
|
@@ -198,4 +301,4 @@ export {
|
|
|
198
301
|
WrappedCopilotChat,
|
|
199
302
|
useCopilotChatLogic
|
|
200
303
|
};
|
|
201
|
-
//# sourceMappingURL=chunk-
|
|
304
|
+
//# sourceMappingURL=chunk-DCNCY2PL.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\";\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 runChatCompletion,\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(\n generalContext.agentSession.agentName,\n context,\n appendMessage,\n runChatCompletion,\n hint,\n );\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,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,eAAe,aAAa;AAAA,QAC5B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,QAAM,mBAAmB,MAAM;AAC7B,QAAI,eAAe,cAAc;AAC/B,gBAAU,eAAe,aAAa,WAAW,OAAO;AAAA,IAC1D;AAAA,EACF;AACA,QAAM,uBAAuB,CAAC,UAAe;AAC3C,QAAI,eAAe,cAAc;AAC/B,qBAAe,iBAAiB,CAAC,oBAAoB;AACnD,eAAO,iCACF,kBADE;AAAA,UAEL,CAAC,eAAe,aAAc,SAAS,GAAG;AAAA,YACxC;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,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;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"]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
logMessages,
|
|
5
5
|
logReadables,
|
|
6
6
|
shouldShowDevConsole
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-PNQVKBPN.mjs";
|
|
8
8
|
import {
|
|
9
9
|
CopilotKitHelpModal
|
|
10
10
|
} from "./chunk-TI7SY2RI.mjs";
|
|
@@ -229,4 +229,4 @@ export {
|
|
|
229
229
|
CopilotDevConsole,
|
|
230
230
|
DebugMenuButton
|
|
231
231
|
};
|
|
232
|
-
//# sourceMappingURL=chunk-
|
|
232
|
+
//# sourceMappingURL=chunk-F2W5FD7L.mjs.map
|
|
@@ -110,7 +110,7 @@ function logMessages(context) {
|
|
|
110
110
|
type: "ActionExecutionMessage",
|
|
111
111
|
role: void 0,
|
|
112
112
|
name: message.name,
|
|
113
|
-
scope: message.
|
|
113
|
+
scope: message.parentMessageId,
|
|
114
114
|
content: message.arguments
|
|
115
115
|
};
|
|
116
116
|
} else if (message.isResultMessage()) {
|
|
@@ -143,4 +143,4 @@ export {
|
|
|
143
143
|
logActions,
|
|
144
144
|
logMessages
|
|
145
145
|
};
|
|
146
|
-
//# sourceMappingURL=chunk-
|
|
146
|
+
//# sourceMappingURL=chunk-PNQVKBPN.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/dev-console/utils.ts"],"sourcesContent":["import {\n CopilotContextParams,\n CopilotMessagesContextParams,\n defaultCopilotContextCategories,\n} from \"@copilotkit/react-core\";\nimport { CopilotKitVersion } from \"./types\";\nimport { ActionExecutionMessage, ResultMessage, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { AgentStateMessage } from \"@copilotkit/runtime-client-gql\";\n\nexport function shouldShowDevConsole(showDevConsole: boolean | \"auto\"): boolean {\n if (typeof showDevConsole === \"boolean\") {\n return showDevConsole;\n }\n return (\n getHostname() === \"localhost\" ||\n getHostname() === \"127.0.0.1\" ||\n getHostname() === \"0.0.0.0\" ||\n getHostname() === \"::1\"\n );\n}\n\nfunction getHostname(): string {\n if (typeof window !== \"undefined\" && window.location) {\n return window.location.hostname;\n }\n return \"\";\n}\n\nexport async function getPublishedCopilotKitVersion(\n current: string,\n forceCheck: boolean = false,\n): Promise<CopilotKitVersion> {\n const LOCAL_STORAGE_KEY = \"__copilotkit_version_check__\";\n const serializedVersion = localStorage.getItem(LOCAL_STORAGE_KEY);\n if (serializedVersion && !forceCheck) {\n try {\n const parsedVersion: CopilotKitVersion = JSON.parse(serializedVersion);\n const oneHour = 60 * 60 * 1000;\n const now = new Date().getTime();\n\n if (\n parsedVersion.current === current &&\n now - new Date(parsedVersion.lastChecked).getTime() < oneHour\n ) {\n return parsedVersion;\n }\n } catch (error) {\n console.error(\"Failed to parse CopilotKitVersion from localStorage\", error);\n }\n }\n\n try {\n const response = await fetch(\"https://api.cloud.stagingcopilotkit.ai/check-for-updates\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n packages: [\n {\n packageName: \"@copilotkit/shared\",\n packageVersion: current,\n },\n ],\n }),\n });\n\n const data = await response.json();\n\n const version: CopilotKitVersion = {\n current,\n lastChecked: new Date().getTime(),\n latest: data.packages[0].latestVersion,\n severity: data.packages[0].severity,\n advisory: data.packages[0].advisory || null,\n };\n\n localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(version));\n return version;\n } catch (error) {\n console.error(\"Failed to check for updates\", error);\n throw error;\n }\n}\n\nexport function logReadables(context: CopilotContextParams) {\n console.log(\"%cCurrent Readables:\", \"font-size: 16px; font-weight: bold;\");\n\n const readables = context.getContextString([], defaultCopilotContextCategories).trim();\n if (readables.length === 0) {\n console.log(\"No readables found\");\n return;\n }\n console.log(readables);\n}\n\nexport function logActions(context: CopilotContextParams) {\n console.log(\"%cCurrent Actions:\", \"font-size: 16px; font-weight: bold;\");\n\n if (Object.values(context.actions).length === 0) {\n console.log(\"No actions found\");\n return;\n }\n for (const action of Object.values(context.actions)) {\n console.group(action.name);\n console.log(\"name\", action.name);\n console.log(\"description\", action.description);\n console.log(\"parameters\", action.parameters);\n\n console.groupEnd();\n }\n}\n\nexport function logMessages(context: CopilotMessagesContextParams) {\n console.log(\"%cCurrent Messages:\", \"font-size: 16px; font-weight: bold;\");\n\n if (context.messages.length === 0) {\n console.log(\"No messages found\");\n return;\n }\n\n const tableData = context.messages.map((message) => {\n if (message.isTextMessage()) {\n return {\n id: message.id,\n type: \"TextMessage\",\n role: message.role,\n name: undefined,\n scope: undefined,\n content: message.content,\n };\n } else if (message.isActionExecutionMessage()) {\n return {\n id: message.id,\n type: \"ActionExecutionMessage\",\n role: undefined,\n name: message.name,\n scope: message.
|
|
1
|
+
{"version":3,"sources":["../src/components/dev-console/utils.ts"],"sourcesContent":["import {\n CopilotContextParams,\n CopilotMessagesContextParams,\n defaultCopilotContextCategories,\n} from \"@copilotkit/react-core\";\nimport { CopilotKitVersion } from \"./types\";\nimport { ActionExecutionMessage, ResultMessage, TextMessage } from \"@copilotkit/runtime-client-gql\";\nimport { AgentStateMessage } from \"@copilotkit/runtime-client-gql\";\n\nexport function shouldShowDevConsole(showDevConsole: boolean | \"auto\"): boolean {\n if (typeof showDevConsole === \"boolean\") {\n return showDevConsole;\n }\n return (\n getHostname() === \"localhost\" ||\n getHostname() === \"127.0.0.1\" ||\n getHostname() === \"0.0.0.0\" ||\n getHostname() === \"::1\"\n );\n}\n\nfunction getHostname(): string {\n if (typeof window !== \"undefined\" && window.location) {\n return window.location.hostname;\n }\n return \"\";\n}\n\nexport async function getPublishedCopilotKitVersion(\n current: string,\n forceCheck: boolean = false,\n): Promise<CopilotKitVersion> {\n const LOCAL_STORAGE_KEY = \"__copilotkit_version_check__\";\n const serializedVersion = localStorage.getItem(LOCAL_STORAGE_KEY);\n if (serializedVersion && !forceCheck) {\n try {\n const parsedVersion: CopilotKitVersion = JSON.parse(serializedVersion);\n const oneHour = 60 * 60 * 1000;\n const now = new Date().getTime();\n\n if (\n parsedVersion.current === current &&\n now - new Date(parsedVersion.lastChecked).getTime() < oneHour\n ) {\n return parsedVersion;\n }\n } catch (error) {\n console.error(\"Failed to parse CopilotKitVersion from localStorage\", error);\n }\n }\n\n try {\n const response = await fetch(\"https://api.cloud.stagingcopilotkit.ai/check-for-updates\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n packages: [\n {\n packageName: \"@copilotkit/shared\",\n packageVersion: current,\n },\n ],\n }),\n });\n\n const data = await response.json();\n\n const version: CopilotKitVersion = {\n current,\n lastChecked: new Date().getTime(),\n latest: data.packages[0].latestVersion,\n severity: data.packages[0].severity,\n advisory: data.packages[0].advisory || null,\n };\n\n localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(version));\n return version;\n } catch (error) {\n console.error(\"Failed to check for updates\", error);\n throw error;\n }\n}\n\nexport function logReadables(context: CopilotContextParams) {\n console.log(\"%cCurrent Readables:\", \"font-size: 16px; font-weight: bold;\");\n\n const readables = context.getContextString([], defaultCopilotContextCategories).trim();\n if (readables.length === 0) {\n console.log(\"No readables found\");\n return;\n }\n console.log(readables);\n}\n\nexport function logActions(context: CopilotContextParams) {\n console.log(\"%cCurrent Actions:\", \"font-size: 16px; font-weight: bold;\");\n\n if (Object.values(context.actions).length === 0) {\n console.log(\"No actions found\");\n return;\n }\n for (const action of Object.values(context.actions)) {\n console.group(action.name);\n console.log(\"name\", action.name);\n console.log(\"description\", action.description);\n console.log(\"parameters\", action.parameters);\n\n console.groupEnd();\n }\n}\n\nexport function logMessages(context: CopilotMessagesContextParams) {\n console.log(\"%cCurrent Messages:\", \"font-size: 16px; font-weight: bold;\");\n\n if (context.messages.length === 0) {\n console.log(\"No messages found\");\n return;\n }\n\n const tableData = context.messages.map((message) => {\n if (message.isTextMessage()) {\n return {\n id: message.id,\n type: \"TextMessage\",\n role: message.role,\n name: undefined,\n scope: undefined,\n content: message.content,\n };\n } else if (message.isActionExecutionMessage()) {\n return {\n id: message.id,\n type: \"ActionExecutionMessage\",\n role: undefined,\n name: message.name,\n scope: message.parentMessageId,\n content: message.arguments,\n };\n } else if (message.isResultMessage()) {\n return {\n id: message.id,\n type: \"ResultMessage\",\n role: undefined,\n name: message.actionName,\n scope: message.actionExecutionId,\n content: message.result,\n };\n } else if (message.isAgentStateMessage()) {\n return {\n id: message.id,\n type: `AgentStateMessage (running: ${message.running})`,\n role: message.role,\n name: undefined,\n scope: message.threadId,\n content: message.state,\n };\n }\n });\n console.table(tableData);\n}\n"],"mappings":";;;;;AAAA;AAAA,EAGE;AAAA,OACK;AAKA,SAAS,qBAAqB,gBAA2C;AAC9E,MAAI,OAAO,mBAAmB,WAAW;AACvC,WAAO;AAAA,EACT;AACA,SACE,YAAY,MAAM,eAClB,YAAY,MAAM,eAClB,YAAY,MAAM,aAClB,YAAY,MAAM;AAEtB;AAEA,SAAS,cAAsB;AAC7B,MAAI,OAAO,WAAW,eAAe,OAAO,UAAU;AACpD,WAAO,OAAO,SAAS;AAAA,EACzB;AACA,SAAO;AACT;AAEA,SAAsB,8BACpB,SACA,aAAsB,OACM;AAAA;AAC5B,UAAM,oBAAoB;AAC1B,UAAM,oBAAoB,aAAa,QAAQ,iBAAiB;AAChE,QAAI,qBAAqB,CAAC,YAAY;AACpC,UAAI;AACF,cAAM,gBAAmC,KAAK,MAAM,iBAAiB;AACrE,cAAM,UAAU,KAAK,KAAK;AAC1B,cAAM,OAAM,oBAAI,KAAK,GAAE,QAAQ;AAE/B,YACE,cAAc,YAAY,WAC1B,MAAM,IAAI,KAAK,cAAc,WAAW,EAAE,QAAQ,IAAI,SACtD;AACA,iBAAO;AAAA,QACT;AAAA,MACF,SAAS,OAAP;AACA,gBAAQ,MAAM,uDAAuD,KAAK;AAAA,MAC5E;AAAA,IACF;AAEA,QAAI;AACF,YAAM,WAAW,MAAM,MAAM,4DAA4D;AAAA,QACvF,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,QAClB;AAAA,QACA,MAAM,KAAK,UAAU;AAAA,UACnB,UAAU;AAAA,YACR;AAAA,cACE,aAAa;AAAA,cACb,gBAAgB;AAAA,YAClB;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAED,YAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,YAAM,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3B,aAAO;AAAA,QACL,IAAI,QAAQ;AAAA,QACZ,MAAM;AAAA,QACN,MAAM,QAAQ;AAAA,QACd,MAAM;AAAA,QACN,OAAO;AAAA,QACP,SAAS,QAAQ;AAAA,MACnB;AAAA,IACF,WAAW,QAAQ,yBAAyB,GAAG;AAC7C,aAAO;AAAA,QACL,IAAI,QAAQ;AAAA,QACZ,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM,QAAQ;AAAA,QACd,OAAO,QAAQ;AAAA,QACf,SAAS,QAAQ;AAAA,MACnB;AAAA,IACF,WAAW,QAAQ,gBAAgB,GAAG;AACpC,aAAO;AAAA,QACL,IAAI,QAAQ;AAAA,QACZ,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM,QAAQ;AAAA,QACd,OAAO,QAAQ;AAAA,QACf,SAAS,QAAQ;AAAA,MACnB;AAAA,IACF,WAAW,QAAQ,oBAAoB,GAAG;AACxC,aAAO;AAAA,QACL,IAAI,QAAQ;AAAA,QACZ,MAAM,+BAA+B,QAAQ;AAAA,QAC7C,MAAM,QAAQ;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,SAAS,QAAQ;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACD,UAAQ,MAAM,SAAS;AACzB;","names":[]}
|
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
} from "./chunk-RQNJNK2W.mjs";
|
|
10
10
|
import {
|
|
11
11
|
CopilotChat
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-DCNCY2PL.mjs";
|
|
13
13
|
import {
|
|
14
14
|
Input
|
|
15
15
|
} from "./chunk-EMQEEXUB.mjs";
|
|
16
16
|
import {
|
|
17
17
|
Messages
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-7II4YL7R.mjs";
|
|
19
19
|
import {
|
|
20
20
|
ResponseButton
|
|
21
21
|
} from "./chunk-3XAXY2Z3.mjs";
|
|
@@ -33,6 +33,8 @@ var CopilotModal = ({
|
|
|
33
33
|
hitEscapeToClose = true,
|
|
34
34
|
onSetOpen,
|
|
35
35
|
onSubmitMessage,
|
|
36
|
+
onStopGeneration,
|
|
37
|
+
onReloadMessages,
|
|
36
38
|
shortcut = "/",
|
|
37
39
|
icons,
|
|
38
40
|
labels,
|
|
@@ -70,6 +72,8 @@ var CopilotModal = ({
|
|
|
70
72
|
{
|
|
71
73
|
instructions,
|
|
72
74
|
onSubmitMessage,
|
|
75
|
+
onStopGeneration,
|
|
76
|
+
onReloadMessages,
|
|
73
77
|
makeSystemMessage,
|
|
74
78
|
showResponseButton,
|
|
75
79
|
onInProgress,
|
|
@@ -88,4 +92,4 @@ var CopilotModal = ({
|
|
|
88
92
|
export {
|
|
89
93
|
CopilotModal
|
|
90
94
|
};
|
|
91
|
-
//# sourceMappingURL=chunk-
|
|
95
|
+
//# sourceMappingURL=chunk-UWVGLGFQ.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 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,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CopilotModal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UWVGLGFQ.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-WSMMTZCM.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { CopilotChatIcons, CopilotChatLabels } from './ChatContext.js';
|
|
3
3
|
import React__default from 'react';
|
|
4
|
-
import { SystemMessageFunction } from '@copilotkit/react-core';
|
|
4
|
+
import { SystemMessageFunction, HintFunction } 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,6 +27,14 @@ 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;
|
|
30
38
|
/**
|
|
31
39
|
* Icons can be used to set custom icons for the chat window.
|
|
32
40
|
*/
|
|
@@ -84,20 +92,57 @@ interface CopilotChatProps {
|
|
|
84
92
|
*/
|
|
85
93
|
children?: React__default.ReactNode;
|
|
86
94
|
}
|
|
87
|
-
|
|
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;
|
|
88
133
|
declare function WrappedCopilotChat({ children, icons, labels, className, }: {
|
|
89
134
|
children: React__default.ReactNode;
|
|
90
135
|
icons?: CopilotChatIcons;
|
|
91
136
|
labels?: CopilotChatLabels;
|
|
92
137
|
className?: string;
|
|
93
138
|
}): react_jsx_runtime.JSX.Element;
|
|
94
|
-
declare const useCopilotChatLogic: (makeSystemMessage?: SystemMessageFunction, onInProgress?: (isLoading: boolean) => void, onSubmitMessage?: (messageContent: string) => Promise<void> | void) => {
|
|
139
|
+
declare const useCopilotChatLogic: (makeSystemMessage?: SystemMessageFunction, onInProgress?: (isLoading: boolean) => void, onSubmitMessage?: (messageContent: string) => Promise<void> | void, onStopGeneration?: OnStopGeneration, onReloadMessages?: OnReloadMessages) => {
|
|
95
140
|
visibleMessages: Message[];
|
|
96
141
|
isLoading: boolean;
|
|
97
142
|
currentSuggestions: CopilotChatSuggestion[];
|
|
98
143
|
sendMessage: (messageContent: string) => Promise<Message>;
|
|
99
144
|
stopGeneration: () => void;
|
|
100
|
-
reloadMessages: () =>
|
|
145
|
+
reloadMessages: () => void;
|
|
101
146
|
};
|
|
102
147
|
|
|
103
|
-
export { CopilotChat, CopilotChatProps, WrappedCopilotChat, useCopilotChatLogic };
|
|
148
|
+
export { CopilotChat, CopilotChatProps, OnReloadMessages, OnReloadMessagesArguments, OnStopGeneration, WrappedCopilotChat, useCopilotChatLogic };
|