@copilotkit/react-core 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454 → 0.0.0-feat-enable-setting-recursion-limit-20250424165940
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 +796 -3
- package/dist/{chunk-LNI2Z45S.mjs → chunk-22ENANUU.mjs} +25 -17
- package/dist/chunk-22ENANUU.mjs.map +1 -0
- package/dist/{chunk-U6JICUGO.mjs → chunk-42SVH3TY.mjs} +238 -83
- package/dist/chunk-42SVH3TY.mjs.map +1 -0
- package/dist/{chunk-XERJQUHA.mjs → chunk-4CEQJ2X6.mjs} +2 -2
- package/dist/{chunk-XERJQUHA.mjs.map → chunk-4CEQJ2X6.mjs.map} +1 -1
- package/dist/chunk-534J55RX.mjs +86 -0
- package/dist/chunk-534J55RX.mjs.map +1 -0
- package/dist/{chunk-22XKTBPF.mjs → chunk-5TVV6FJD.mjs} +27 -4
- package/dist/chunk-5TVV6FJD.mjs.map +1 -0
- package/dist/chunk-6YOKPWQ7.mjs +1 -0
- package/dist/chunk-7VCWAAWC.mjs +24 -0
- package/dist/chunk-7VCWAAWC.mjs.map +1 -0
- package/dist/{chunk-6BQVZFNO.mjs → chunk-BKTARDXX.mjs} +8 -3
- package/dist/chunk-BKTARDXX.mjs.map +1 -0
- package/dist/{chunk-2KT73RVG.mjs → chunk-CMEX33KD.mjs} +100 -38
- package/dist/chunk-CMEX33KD.mjs.map +1 -0
- package/dist/chunk-CQPYJIBH.mjs +1 -0
- package/dist/chunk-D34OH4VN.mjs +201 -0
- package/dist/chunk-D34OH4VN.mjs.map +1 -0
- package/dist/chunk-DMQB35FC.mjs +47 -0
- package/dist/chunk-DMQB35FC.mjs.map +1 -0
- package/dist/{chunk-4TDYSNUD.mjs → chunk-EI2J4CP6.mjs} +26 -13
- package/dist/chunk-EI2J4CP6.mjs.map +1 -0
- package/dist/{chunk-KSPLXKSX.mjs → chunk-FGOCUTAU.mjs} +91 -50
- package/dist/chunk-FGOCUTAU.mjs.map +1 -0
- package/dist/{chunk-LHKIIAUQ.mjs → chunk-FRRPZKXW.mjs} +10 -10
- package/dist/chunk-FRRPZKXW.mjs.map +1 -0
- package/dist/chunk-FXVXAJVG.mjs +65 -0
- package/dist/chunk-FXVXAJVG.mjs.map +1 -0
- package/dist/{chunk-FQ53HQYZ.mjs → chunk-GOK4PDQO.mjs} +13 -4
- package/dist/{chunk-FQ53HQYZ.mjs.map → chunk-GOK4PDQO.mjs.map} +1 -1
- package/dist/chunk-HGZXDC4Y.mjs +63 -0
- package/dist/chunk-HGZXDC4Y.mjs.map +1 -0
- package/dist/{chunk-EWKJMQOF.mjs → chunk-JWE4IXSG.mjs} +18 -4
- package/dist/chunk-JWE4IXSG.mjs.map +1 -0
- package/dist/{chunk-HIUT2NLX.mjs → chunk-KF5SB2VB.mjs} +2 -2
- package/dist/chunk-PMAFHQ7P.mjs +65 -0
- package/dist/chunk-PMAFHQ7P.mjs.map +1 -0
- package/dist/{chunk-XOQMISG3.mjs → chunk-TWWQG3EF.mjs} +3 -3
- package/dist/{chunk-WXREY7UP.mjs → chunk-UDUFMGWQ.mjs} +11 -3
- package/dist/chunk-UDUFMGWQ.mjs.map +1 -0
- package/dist/chunk-YPBKY4KY.mjs +1 -0
- package/dist/chunk-YPBKY4KY.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.d.ts +4 -12
- package/dist/components/copilot-provider/copilot-messages.js +143 -18
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -1
- package/dist/components/copilot-provider/copilotkit-props.d.ts +37 -2
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +2 -2
- package/dist/components/copilot-provider/copilotkit.js +470 -58
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +9 -7
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +470 -58
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -7
- package/dist/components/error-boundary/error-boundary.d.ts +12 -3
- package/dist/components/error-boundary/error-boundary.js +333 -19
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +4 -2
- package/dist/components/error-boundary/error-utils.js +14 -2
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +470 -58
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -7
- package/dist/components/toast/toast-provider.js +34 -16
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/components/usage-banner.d.ts +22 -0
- package/dist/components/usage-banner.js +226 -0
- package/dist/components/usage-banner.js.map +1 -0
- package/dist/components/usage-banner.mjs +10 -0
- package/dist/components/usage-banner.mjs.map +1 -0
- package/dist/context/copilot-context.d.ts +10 -142
- package/dist/context/copilot-context.js +10 -2
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +10 -2
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +4 -4
- package/dist/copilot-context-0e923eb1.d.ts +194 -0
- package/dist/hooks/index.d.ts +5 -2
- package/dist/hooks/index.js +513 -145
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +37 -23
- package/dist/hooks/use-chat.d.ts +16 -6
- package/dist/hooks/use-chat.js +245 -79
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -4
- package/dist/hooks/use-coagent-state-render.d.ts +2 -7
- package/dist/hooks/use-coagent-state-render.js +34 -3
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -3
- package/dist/hooks/use-coagent.d.ts +20 -14
- package/dist/hooks/use-coagent.js +346 -131
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +13 -11
- package/dist/hooks/use-copilot-action.js +27 -4
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +3 -3
- package/dist/hooks/use-copilot-additional-instructions.d.ts +26 -0
- package/dist/hooks/use-copilot-additional-instructions.js +162 -0
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -0
- package/dist/hooks/use-copilot-additional-instructions.mjs +9 -0
- package/dist/hooks/use-copilot-additional-instructions.mjs.map +1 -0
- package/dist/hooks/use-copilot-authenticated-action.d.ts +12 -2
- package/dist/hooks/use-copilot-authenticated-action.js +35 -12
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +6 -6
- package/dist/hooks/use-copilot-chat.d.ts +3 -3
- package/dist/hooks/use-copilot-chat.js +264 -87
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +12 -10
- package/dist/hooks/use-copilot-readable.d.ts +5 -1
- package/dist/hooks/use-copilot-readable.js +21 -4
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.js +20 -3
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.d.ts +5 -0
- package/dist/hooks/use-langgraph-interrupt-render.js +185 -0
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -0
- package/dist/hooks/use-langgraph-interrupt-render.mjs +11 -0
- package/dist/hooks/use-langgraph-interrupt-render.mjs.map +1 -0
- package/dist/hooks/use-langgraph-interrupt.d.ts +14 -0
- package/dist/hooks/use-langgraph-interrupt.js +1154 -0
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -0
- package/dist/hooks/use-langgraph-interrupt.mjs +25 -0
- package/dist/hooks/use-langgraph-interrupt.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.js +10 -2
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +7 -3
- package/dist/index.js +998 -240
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -28
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -9
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -9
- package/dist/lib/status-checker.d.ts +17 -0
- package/dist/lib/status-checker.js +102 -0
- package/dist/lib/status-checker.js.map +1 -0
- package/dist/lib/status-checker.mjs +8 -0
- package/dist/lib/status-checker.mjs.map +1 -0
- package/dist/types/coagent-state.d.ts +4 -0
- package/dist/types/coagent-state.js.map +1 -1
- package/dist/types/crew.d.ts +79 -0
- package/dist/types/crew.js +19 -0
- package/dist/types/crew.js.map +1 -0
- package/dist/types/crew.mjs +2 -0
- package/dist/types/crew.mjs.map +1 -0
- package/dist/types/frontend-action.d.ts +2 -1
- package/dist/types/frontend-action.js +1 -1
- package/dist/types/frontend-action.js.map +1 -1
- package/dist/types/frontend-action.mjs +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +2 -1
- package/dist/types/interrupt-action.d.ts +10 -0
- package/dist/types/interrupt-action.js +19 -0
- package/dist/types/interrupt-action.js.map +1 -0
- package/dist/types/interrupt-action.mjs +1 -0
- package/dist/types/interrupt-action.mjs.map +1 -0
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +9 -7
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +9 -7
- package/package.json +5 -4
- package/src/components/copilot-provider/copilot-messages.tsx +41 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +36 -1
- package/src/components/copilot-provider/copilotkit.tsx +117 -29
- package/src/components/error-boundary/error-boundary.tsx +62 -4
- package/src/components/error-boundary/error-utils.tsx +11 -6
- package/src/components/toast/toast-provider.tsx +20 -17
- package/src/components/usage-banner.tsx +205 -0
- package/src/context/copilot-context.tsx +41 -10
- package/src/hooks/index.ts +4 -1
- package/src/hooks/use-chat.ts +288 -64
- package/src/hooks/use-coagent-state-render.ts +39 -8
- package/src/hooks/use-coagent.ts +125 -67
- package/src/hooks/use-copilot-action.ts +16 -0
- package/src/hooks/use-copilot-additional-instructions.ts +85 -0
- package/src/hooks/use-copilot-authenticated-action.ts +17 -7
- package/src/hooks/use-copilot-chat.ts +19 -5
- package/src/hooks/use-copilot-readable.ts +16 -2
- package/src/hooks/use-copilot-runtime-client.ts +6 -1
- package/src/hooks/use-langgraph-interrupt-render.ts +67 -0
- package/src/hooks/use-langgraph-interrupt.ts +61 -0
- package/src/lib/status-checker.ts +64 -0
- package/src/types/coagent-state.ts +4 -0
- package/src/types/crew.ts +89 -0
- package/src/types/frontend-action.ts +5 -2
- package/src/types/index.ts +8 -0
- package/src/types/interrupt-action.ts +39 -0
- package/dist/chunk-22XKTBPF.mjs.map +0 -1
- package/dist/chunk-2KT73RVG.mjs.map +0 -1
- package/dist/chunk-4TDYSNUD.mjs.map +0 -1
- package/dist/chunk-6BQVZFNO.mjs.map +0 -1
- package/dist/chunk-EFZPSZWO.mjs +0 -1
- package/dist/chunk-EWKJMQOF.mjs.map +0 -1
- package/dist/chunk-KSPLXKSX.mjs.map +0 -1
- package/dist/chunk-LHKIIAUQ.mjs.map +0 -1
- package/dist/chunk-LNI2Z45S.mjs.map +0 -1
- package/dist/chunk-NR2BTA6Z.mjs +0 -1
- package/dist/chunk-U6JICUGO.mjs.map +0 -1
- package/dist/chunk-VNTDIJSG.mjs +0 -37
- package/dist/chunk-VNTDIJSG.mjs.map +0 -1
- package/dist/chunk-WXREY7UP.mjs.map +0 -1
- package/dist/chunk-XXR4QFAQ.mjs +0 -29
- package/dist/chunk-XXR4QFAQ.mjs.map +0 -1
- /package/dist/{chunk-EFZPSZWO.mjs.map → chunk-6YOKPWQ7.mjs.map} +0 -0
- /package/dist/{chunk-NR2BTA6Z.mjs.map → chunk-CQPYJIBH.mjs.map} +0 -0
- /package/dist/{chunk-HIUT2NLX.mjs.map → chunk-KF5SB2VB.mjs.map} +0 -0
- /package/dist/{chunk-XOQMISG3.mjs.map → chunk-TWWQG3EF.mjs.map} +0 -0
|
@@ -26,20 +26,26 @@ function ToastProvider({
|
|
|
26
26
|
children
|
|
27
27
|
}) {
|
|
28
28
|
const [toasts, setToasts] = useState([]);
|
|
29
|
-
const addToast = useCallback(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
const addToast = useCallback(
|
|
30
|
+
(toast) => {
|
|
31
|
+
var _a;
|
|
32
|
+
if (!enabled) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
|
|
36
|
+
setToasts((currentToasts) => {
|
|
37
|
+
if (currentToasts.find((toast2) => toast2.id === id))
|
|
38
|
+
return currentToasts;
|
|
39
|
+
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
40
|
+
});
|
|
41
|
+
if (toast.duration) {
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
removeToast(id);
|
|
44
|
+
}, toast.duration);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[enabled]
|
|
48
|
+
);
|
|
43
49
|
const addGraphQLErrorsToast = useCallback((errors) => {
|
|
44
50
|
addToast({
|
|
45
51
|
type: "error",
|
|
@@ -150,11 +156,13 @@ function Toast({
|
|
|
150
156
|
}
|
|
151
157
|
|
|
152
158
|
// src/components/error-boundary/error-utils.tsx
|
|
159
|
+
import ReactMarkdown from "react-markdown";
|
|
153
160
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
154
161
|
function ErrorToast({ errors }) {
|
|
155
162
|
const errorsToRender = errors.map((error, idx) => {
|
|
156
163
|
var _a, _b, _c;
|
|
157
|
-
const
|
|
164
|
+
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
165
|
+
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
158
166
|
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
159
167
|
return /* @__PURE__ */ jsxs2(
|
|
160
168
|
"div",
|
|
@@ -179,7 +187,7 @@ function ErrorToast({ errors }) {
|
|
|
179
187
|
]
|
|
180
188
|
}
|
|
181
189
|
),
|
|
182
|
-
/* @__PURE__ */ jsx2(
|
|
190
|
+
/* @__PURE__ */ jsx2(ReactMarkdown, { children: message })
|
|
183
191
|
]
|
|
184
192
|
},
|
|
185
193
|
idx
|
|
@@ -239,4 +247,4 @@ export {
|
|
|
239
247
|
useToast,
|
|
240
248
|
ToastProvider
|
|
241
249
|
};
|
|
242
|
-
//# sourceMappingURL=chunk-
|
|
250
|
+
//# sourceMappingURL=chunk-22ENANUU.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/error-boundary/error-utils.tsx","../src/components/toast/toast-provider.tsx"],"sourcesContent":["import React, { useCallback } from \"react\";\nimport { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport { useToast } from \"../toast/toast-provider\";\nimport { ExclamationMarkIcon } from \"../toast/exclamation-mark-icon\";\nimport ReactMarkdown from \"react-markdown\";\n\ninterface OriginalError {\n message?: string;\n stack?: string;\n}\n\nexport function ErrorToast({ errors }: { errors: (Error | GraphQLError)[] }) {\n const errorsToRender = errors.map((error, idx) => {\n const originalError =\n \"extensions\" in error ? (error.extensions?.originalError as undefined | OriginalError) : {};\n const message = originalError?.message ?? error.message;\n const code = \"extensions\" in error ? (error.extensions?.code as string) : null;\n\n return (\n <div\n key={idx}\n style={{\n marginTop: idx === 0 ? 0 : 10,\n marginBottom: 14,\n }}\n >\n <ExclamationMarkIcon style={{ marginBottom: 4 }} />\n\n {code && (\n <div\n style={{\n fontWeight: \"600\",\n marginBottom: 4,\n }}\n >\n Copilot Cloud Error:{\" \"}\n <span style={{ fontFamily: \"monospace\", fontWeight: \"normal\" }}>{code}</span>\n </div>\n )}\n <ReactMarkdown>{message}</ReactMarkdown>\n </div>\n );\n });\n return (\n <div\n style={{\n fontSize: \"13px\",\n maxWidth: \"600px\",\n }}\n >\n {errorsToRender}\n <div style={{ fontSize: \"11px\", opacity: 0.75 }}>\n NOTE: This error only displays during local development.\n </div>\n </div>\n );\n}\n\nexport function useErrorToast() {\n const { addToast } = useToast();\n\n return useCallback(\n (error: (Error | GraphQLError)[]) => {\n const errorId = error\n .map((err) => {\n const message =\n \"extensions\" in err\n ? (err.extensions?.originalError as any)?.message || err.message\n : err.message;\n const stack = err.stack || \"\";\n return btoa(message + stack).slice(0, 32); // Create hash from message + stack\n })\n .join(\"|\");\n\n addToast({\n type: \"error\",\n id: errorId, // Toast libraries typically dedupe by id\n message: <ErrorToast errors={error} />,\n });\n },\n [addToast],\n );\n}\n\nexport function useAsyncCallback<T extends (...args: any[]) => Promise<any>>(\n callback: T,\n deps: Parameters<typeof useCallback>[1],\n) {\n const addErrorToast = useErrorToast();\n return useCallback(async (...args: Parameters<T>) => {\n try {\n return await callback(...args);\n } catch (error) {\n console.error(\"Error in async callback:\", error);\n // @ts-ignore\n addErrorToast([error]);\n throw error;\n }\n }, deps);\n}\n","import { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport React, { createContext, useContext, useState, useCallback } from \"react\";\nimport { ErrorToast } from \"../error-boundary/error-utils\";\nimport { PartialBy } from \"@copilotkit/shared\";\n\ninterface Toast {\n id: string;\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n duration?: number;\n}\n\ninterface ToastContextValue {\n toasts: Toast[];\n addToast: (toast: PartialBy<Toast, \"id\">) => void;\n addGraphQLErrorsToast: (errors: GraphQLError[]) => void;\n removeToast: (id: string) => void;\n enabled: boolean;\n}\n\nconst ToastContext = createContext<ToastContextValue | undefined>(undefined);\n\nexport function useToast() {\n const context = useContext(ToastContext);\n if (!context) {\n throw new Error(\"useToast must be used within a ToastProvider\");\n }\n return context;\n}\n\nexport function ToastProvider({\n enabled,\n children,\n}: {\n enabled: boolean;\n children: React.ReactNode;\n}) {\n const [toasts, setToasts] = useState<Toast[]>([]);\n const addToast = useCallback(\n (toast: PartialBy<Toast, \"id\">) => {\n // We do not display these errors unless we are in dev mode.\n if (!enabled) {\n return;\n }\n\n const id = toast.id ?? Math.random().toString(36).substring(2, 9);\n\n setToasts((currentToasts) => {\n if (currentToasts.find((toast) => toast.id === id)) return currentToasts;\n return [...currentToasts, { ...toast, id }];\n });\n\n if (toast.duration) {\n setTimeout(() => {\n removeToast(id);\n }, toast.duration);\n }\n },\n [enabled],\n );\n\n const addGraphQLErrorsToast = useCallback((errors: GraphQLError[]) => {\n addToast({\n type: \"error\",\n message: <ErrorToast errors={errors} />,\n });\n }, []);\n\n const removeToast = useCallback((id: string) => {\n setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));\n }, []);\n\n const value = {\n toasts,\n addToast,\n addGraphQLErrorsToast,\n removeToast,\n enabled,\n };\n\n return (\n <ToastContext.Provider value={value}>\n <div\n style={{\n position: \"fixed\",\n bottom: \"1rem\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n zIndex: 50,\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"0.5rem\",\n }}\n >\n {toasts.length > 1 && (\n <div style={{ textAlign: \"right\" }}>\n <button\n onClick={() => setToasts([])}\n style={{\n padding: \"4px 8px\",\n fontSize: \"12px\",\n cursor: \"pointer\",\n background: \"white\",\n border: \"1px solid rgba(0,0,0,0.2)\",\n borderRadius: \"4px\",\n }}\n >\n Close All\n </button>\n </div>\n )}\n {toasts.map((toast) => (\n <Toast\n key={toast.id}\n message={toast.message}\n type={toast.type}\n onClose={() => removeToast(toast.id)}\n />\n ))}\n </div>\n {children}\n </ToastContext.Provider>\n );\n}\n\nfunction Toast({\n message,\n type = \"info\",\n onClose,\n}: {\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n onClose: () => void;\n}) {\n const bgColors = {\n info: \"#3b82f6\",\n success: \"#22c55e\",\n warning: \"#eab308\",\n error: \"#ef4444\",\n };\n\n return (\n <div\n style={{\n backgroundColor: bgColors[type],\n color: \"white\",\n padding: \"0.5rem 1.5rem\",\n borderRadius: \"0.25rem\",\n boxShadow: \"0 2px 4px rgba(0,0,0,0.1)\",\n position: \"relative\",\n minWidth: \"200px\",\n }}\n >\n <div>{message}</div>\n <button\n onClick={onClose}\n style={{\n position: \"absolute\",\n top: \"0\",\n right: \"0\",\n background: \"none\",\n border: \"none\",\n color: \"white\",\n cursor: \"pointer\",\n padding: \"0.5rem\",\n fontSize: \"1rem\",\n }}\n >\n ✕\n </button>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAgB,eAAAA,oBAAmB;;;ACCnC,SAAgB,eAAe,YAAY,UAAU,mBAAmB;AA+DzD,cAkBT,YAlBS;AA5Cf,IAAM,eAAe,cAA6C,MAAS;AAEpE,SAAS,WAAW;AACzB,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO;AACT;AAEO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AACF,GAGG;AACD,QAA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eAAJ,mBAAgB,kBAAhB,mBAAuC,YAAW,IAAI,UACvD,IAAI;AACV,cAAM,QAAQ,IAAI,SAAS;AAC3B,eAAO,KAAK,UAAU,KAAK,EAAE,MAAM,GAAG,EAAE;AAAA,MAC1C,CAAC,EACA,KAAK,GAAG;AAEX,eAAS;AAAA,QACP,MAAM;AAAA,QACN,IAAI;AAAA;AAAA,QACJ,SAAS,gBAAAF,KAAC,cAAW,QAAQ,OAAO;AAAA,MACtC,CAAC;AAAA,IACH;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AACF;AAEO,SAAS,iBACd,UACA,MACA;AACA,QAAM,gBAAgB,cAAc;AACpC,SAAOE,aAAY,IAAU,SAAwB;AACnD,QAAI;AACF,aAAO,MAAM,SAAS,GAAG,IAAI;AAAA,IAC/B,SAAS,OAAP;AACA,cAAQ,MAAM,4BAA4B,KAAK;AAE/C,oBAAc,CAAC,KAAK,CAAC;AACrB,YAAM;AAAA,IACR;AAAA,EACF,IAAG,IAAI;AACT;","names":["useCallback","toast","jsx","jsxs","useCallback"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
processActionsForRuntimeRequest
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4CEQJ2X6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useCopilotRuntimeClient
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BKTARDXX.mjs";
|
|
7
7
|
import {
|
|
8
|
-
useAsyncCallback
|
|
9
|
-
|
|
8
|
+
useAsyncCallback,
|
|
9
|
+
useErrorToast
|
|
10
|
+
} from "./chunk-22ENANUU.mjs";
|
|
10
11
|
import {
|
|
11
12
|
__async,
|
|
12
13
|
__spreadProps,
|
|
@@ -14,10 +15,11 @@ import {
|
|
|
14
15
|
} from "./chunk-SKC7AJIV.mjs";
|
|
15
16
|
|
|
16
17
|
// src/hooks/use-chat.ts
|
|
17
|
-
import { useRef } from "react";
|
|
18
|
+
import { useCallback, useRef } from "react";
|
|
18
19
|
import {
|
|
19
20
|
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
20
|
-
randomId
|
|
21
|
+
randomId,
|
|
22
|
+
parseJson
|
|
21
23
|
} from "@copilotkit/shared";
|
|
22
24
|
import {
|
|
23
25
|
TextMessage,
|
|
@@ -30,7 +32,11 @@ import {
|
|
|
30
32
|
MessageRole,
|
|
31
33
|
Role,
|
|
32
34
|
CopilotRequestType,
|
|
33
|
-
loadMessagesFromJsonRepresentation
|
|
35
|
+
loadMessagesFromJsonRepresentation,
|
|
36
|
+
CopilotRuntimeClient,
|
|
37
|
+
langGraphInterruptEvent,
|
|
38
|
+
MetaEventName,
|
|
39
|
+
ActionExecutionMessage
|
|
34
40
|
} from "@copilotkit/runtime-client-gql";
|
|
35
41
|
function useChat(options) {
|
|
36
42
|
const {
|
|
@@ -53,15 +59,20 @@ function useChat(options) {
|
|
|
53
59
|
runId,
|
|
54
60
|
setRunId,
|
|
55
61
|
chatAbortControllerRef,
|
|
56
|
-
agentLock
|
|
62
|
+
agentLock,
|
|
63
|
+
extensions,
|
|
64
|
+
setExtensions,
|
|
65
|
+
langGraphInterruptAction,
|
|
66
|
+
setLangGraphInterruptAction
|
|
57
67
|
} = options;
|
|
58
68
|
const runChatCompletionRef = useRef();
|
|
69
|
+
const addErrorToast = useErrorToast();
|
|
59
70
|
const agentSessionRef = useRef(agentSession);
|
|
60
71
|
agentSessionRef.current = agentSession;
|
|
61
|
-
const threadIdRef = useRef(threadId);
|
|
62
|
-
threadIdRef.current = threadId;
|
|
63
72
|
const runIdRef = useRef(runId);
|
|
64
73
|
runIdRef.current = runId;
|
|
74
|
+
const extensionsRef = useRef(extensions);
|
|
75
|
+
extensionsRef.current = extensions;
|
|
65
76
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
66
77
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
67
78
|
const runtimeClient = useCopilotRuntimeClient({
|
|
@@ -72,8 +83,16 @@ function useChat(options) {
|
|
|
72
83
|
});
|
|
73
84
|
const runChatCompletion = useAsyncCallback(
|
|
74
85
|
(previousMessages) => __async(this, null, function* () {
|
|
75
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
86
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
76
87
|
setIsLoading(true);
|
|
88
|
+
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
89
|
+
if ((interruptEvent == null ? void 0 : interruptEvent.name) === MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
|
|
90
|
+
addErrorToast([
|
|
91
|
+
new Error(
|
|
92
|
+
"A message was sent while interrupt is active. This will cause failure on the agent side"
|
|
93
|
+
)
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
77
96
|
let newMessages = [
|
|
78
97
|
new TextMessage({
|
|
79
98
|
content: "",
|
|
@@ -84,6 +103,10 @@ function useChat(options) {
|
|
|
84
103
|
setMessages([...previousMessages, ...newMessages]);
|
|
85
104
|
const systemMessage = makeSystemMessageCallback();
|
|
86
105
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
106
|
+
const finalProperties = __spreadValues({}, copilotConfig.properties || {});
|
|
107
|
+
if (copilotConfig.mcpEndpoints && copilotConfig.mcpEndpoints.length > 0) {
|
|
108
|
+
finalProperties.mcpEndpoints = copilotConfig.mcpEndpoints;
|
|
109
|
+
}
|
|
87
110
|
const isAgentRun = agentSessionRef.current !== null;
|
|
88
111
|
const stream = runtimeClient.asStream(
|
|
89
112
|
runtimeClient.generateCopilotResponse({
|
|
@@ -92,8 +115,10 @@ function useChat(options) {
|
|
|
92
115
|
actions: processActionsForRuntimeRequest(actions),
|
|
93
116
|
url: window.location.href
|
|
94
117
|
},
|
|
95
|
-
threadId
|
|
118
|
+
threadId,
|
|
96
119
|
runId: runIdRef.current,
|
|
120
|
+
extensions: extensionsRef.current,
|
|
121
|
+
metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event]),
|
|
97
122
|
messages: convertMessagesToGqlInput(filterAgentStateMessages(messagesWithContext))
|
|
98
123
|
}, copilotConfig.cloud ? {
|
|
99
124
|
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
@@ -111,13 +136,17 @@ function useChat(options) {
|
|
|
111
136
|
}), agentSessionRef.current ? {
|
|
112
137
|
agentSession: agentSessionRef.current
|
|
113
138
|
} : {}), {
|
|
114
|
-
agentStates: Object.values(coagentStatesRef.current).map((state) =>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
139
|
+
agentStates: Object.values(coagentStatesRef.current).map((state) => {
|
|
140
|
+
var _a2;
|
|
141
|
+
return {
|
|
142
|
+
agentName: state.name,
|
|
143
|
+
state: JSON.stringify(state.state),
|
|
144
|
+
config: JSON.stringify((_a2 = state.config) != null ? _a2 : {})
|
|
145
|
+
};
|
|
146
|
+
}),
|
|
118
147
|
forwardedParameters: options.forwardedParameters || {}
|
|
119
148
|
}),
|
|
120
|
-
properties:
|
|
149
|
+
properties: finalProperties,
|
|
121
150
|
signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
|
|
122
151
|
})
|
|
123
152
|
);
|
|
@@ -127,6 +156,7 @@ function useChat(options) {
|
|
|
127
156
|
let followUp = void 0;
|
|
128
157
|
let messages2 = [];
|
|
129
158
|
let syncedMessages = [];
|
|
159
|
+
let interruptMessages = [];
|
|
130
160
|
try {
|
|
131
161
|
while (true) {
|
|
132
162
|
let done, value;
|
|
@@ -146,22 +176,45 @@ function useChat(options) {
|
|
|
146
176
|
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
147
177
|
continue;
|
|
148
178
|
}
|
|
149
|
-
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
150
179
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
151
|
-
|
|
180
|
+
extensionsRef.current = CopilotRuntimeClient.removeGraphQLTypename(
|
|
181
|
+
value.generateCopilotResponse.extensions || {}
|
|
182
|
+
);
|
|
152
183
|
setRunId(runIdRef.current);
|
|
184
|
+
setExtensions(extensionsRef.current);
|
|
185
|
+
let rawMessagesResponse = value.generateCopilotResponse.messages;
|
|
186
|
+
const metaEvents = (_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : [];
|
|
187
|
+
(metaEvents != null ? metaEvents : []).forEach((ev) => {
|
|
188
|
+
if (ev.name === MetaEventName.LangGraphInterruptEvent) {
|
|
189
|
+
let eventValue = langGraphInterruptEvent(ev).value;
|
|
190
|
+
eventValue = parseJson(eventValue, eventValue);
|
|
191
|
+
setLangGraphInterruptAction({
|
|
192
|
+
event: __spreadProps(__spreadValues({}, langGraphInterruptEvent(ev)), {
|
|
193
|
+
value: eventValue
|
|
194
|
+
})
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (ev.name === MetaEventName.CopilotKitLangGraphInterruptEvent) {
|
|
198
|
+
const data = ev.data;
|
|
199
|
+
rawMessagesResponse = [...rawMessagesResponse, ...data.messages];
|
|
200
|
+
interruptMessages = convertGqlOutputToMessages(
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
filterAdjacentAgentStateMessages(data.messages)
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
153
206
|
messages2 = convertGqlOutputToMessages(
|
|
154
|
-
filterAdjacentAgentStateMessages(
|
|
207
|
+
filterAdjacentAgentStateMessages(rawMessagesResponse)
|
|
155
208
|
);
|
|
156
209
|
if (messages2.length === 0) {
|
|
157
210
|
continue;
|
|
158
211
|
}
|
|
159
212
|
newMessages = [];
|
|
160
|
-
if (((
|
|
213
|
+
if (((_j = value.generateCopilotResponse.status) == null ? void 0 : _j.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
161
214
|
newMessages = [
|
|
162
215
|
new TextMessage({
|
|
163
216
|
role: MessageRole.Assistant,
|
|
164
|
-
content: ((
|
|
217
|
+
content: ((_k = value.generateCopilotResponse.status.details) == null ? void 0 : _k.guardrailsReason) || ""
|
|
165
218
|
})
|
|
166
219
|
];
|
|
167
220
|
setMessages([...previousMessages, ...newMessages]);
|
|
@@ -222,63 +275,70 @@ function useChat(options) {
|
|
|
222
275
|
setMessages([...previousMessages, ...newMessages]);
|
|
223
276
|
}
|
|
224
277
|
}
|
|
225
|
-
|
|
278
|
+
let finalMessages = constructFinalMessages(
|
|
279
|
+
[...syncedMessages, ...interruptMessages],
|
|
280
|
+
previousMessages,
|
|
281
|
+
newMessages
|
|
282
|
+
);
|
|
226
283
|
let didExecuteAction = false;
|
|
227
284
|
if (onFunctionCall) {
|
|
228
285
|
const lastMessages = [];
|
|
229
286
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
230
287
|
const message = finalMessages[i];
|
|
231
|
-
if (message.isActionExecutionMessage() && message.status.code !== MessageStatusCode.Pending) {
|
|
288
|
+
if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !== MessageStatusCode.Pending) {
|
|
232
289
|
lastMessages.unshift(message);
|
|
233
|
-
} else {
|
|
290
|
+
} else if (!message.isAgentStateMessage()) {
|
|
234
291
|
break;
|
|
235
292
|
}
|
|
236
293
|
}
|
|
237
294
|
for (const message of lastMessages) {
|
|
238
295
|
setMessages(finalMessages);
|
|
239
|
-
const action = actions.find(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
),
|
|
259
|
-
// if the user stopped generation, we also abort consecutive actions
|
|
260
|
-
new Promise((resolve) => {
|
|
261
|
-
var _a2;
|
|
262
|
-
if ((_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.aborted) {
|
|
263
|
-
resolve("Operation was aborted by the user");
|
|
264
|
-
}
|
|
265
|
-
})
|
|
266
|
-
]);
|
|
267
|
-
} catch (e) {
|
|
268
|
-
result = `Failed to execute action ${message.name}`;
|
|
269
|
-
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
270
|
-
}
|
|
296
|
+
const action = actions.find(
|
|
297
|
+
(action2) => action2.name === message.name
|
|
298
|
+
);
|
|
299
|
+
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
300
|
+
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
301
|
+
const isInterruptAction = interruptMessages.find((m) => m.id === message2.id);
|
|
302
|
+
followUp = (action2 == null ? void 0 : action2.followUp) || !isInterruptAction;
|
|
303
|
+
const resultMessage = yield executeAction({
|
|
304
|
+
onFunctionCall,
|
|
305
|
+
previousMessages,
|
|
306
|
+
message: message2,
|
|
307
|
+
chatAbortControllerRef,
|
|
308
|
+
onError: (error) => {
|
|
309
|
+
addErrorToast([error]);
|
|
310
|
+
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
271
313
|
didExecuteAction = true;
|
|
272
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id ===
|
|
273
|
-
finalMessages.splice(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
314
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
315
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
316
|
+
return resultMessage;
|
|
317
|
+
});
|
|
318
|
+
if (action && message.isActionExecutionMessage()) {
|
|
319
|
+
const resultMessage = yield executeActionFromMessage(action, message);
|
|
320
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
321
|
+
if (pairedFeAction) {
|
|
322
|
+
const newExecutionMessage = new ActionExecutionMessage({
|
|
323
|
+
name: pairedFeAction.name,
|
|
324
|
+
arguments: parseJson(resultMessage.result, resultMessage.result),
|
|
325
|
+
status: message.status,
|
|
326
|
+
createdAt: message.createdAt,
|
|
327
|
+
parentMessageId: message.parentMessageId
|
|
328
|
+
});
|
|
329
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
330
|
+
}
|
|
331
|
+
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
332
|
+
const newExecutionMessage = new ActionExecutionMessage({
|
|
333
|
+
name: currentResultMessagePairedFeAction.name,
|
|
334
|
+
arguments: parseJson(message.result, message.result),
|
|
335
|
+
status: message.status,
|
|
336
|
+
createdAt: message.createdAt
|
|
337
|
+
});
|
|
338
|
+
finalMessages.push(newExecutionMessage);
|
|
339
|
+
yield executeActionFromMessage(
|
|
340
|
+
currentResultMessagePairedFeAction,
|
|
341
|
+
newExecutionMessage
|
|
282
342
|
);
|
|
283
343
|
}
|
|
284
344
|
}
|
|
@@ -289,11 +349,11 @@ function useChat(options) {
|
|
|
289
349
|
followUp !== false && // and we executed an action
|
|
290
350
|
(didExecuteAction || // the last message is a server side result
|
|
291
351
|
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
292
|
-
!((
|
|
352
|
+
!((_l = chatAbortControllerRef.current) == null ? void 0 : _l.signal.aborted)
|
|
293
353
|
) {
|
|
294
354
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
295
355
|
return yield runChatCompletionRef.current(finalMessages);
|
|
296
|
-
} else if ((
|
|
356
|
+
} else if ((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted) {
|
|
297
357
|
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
298
358
|
if (message.isActionExecutionMessage()) {
|
|
299
359
|
return finalMessages.find(
|
|
@@ -304,7 +364,7 @@ function useChat(options) {
|
|
|
304
364
|
});
|
|
305
365
|
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
306
366
|
setMessages(repairedMessages);
|
|
307
|
-
if ((
|
|
367
|
+
if ((_n = agentSessionRef.current) == null ? void 0 : _n.nodeName) {
|
|
308
368
|
setAgentSession({
|
|
309
369
|
threadId: agentSessionRef.current.threadId,
|
|
310
370
|
agentName: agentSessionRef.current.agentName,
|
|
@@ -343,6 +403,33 @@ function useChat(options) {
|
|
|
343
403
|
}),
|
|
344
404
|
[messages]
|
|
345
405
|
);
|
|
406
|
+
const composeAndFlushMetaEventsInput = useCallback(
|
|
407
|
+
(metaEvents) => {
|
|
408
|
+
return metaEvents.reduce((acc, event) => {
|
|
409
|
+
if (!event)
|
|
410
|
+
return acc;
|
|
411
|
+
switch (event.name) {
|
|
412
|
+
case MetaEventName.LangGraphInterruptEvent:
|
|
413
|
+
if (event.response) {
|
|
414
|
+
setLangGraphInterruptAction(null);
|
|
415
|
+
const value = event.value;
|
|
416
|
+
return [
|
|
417
|
+
...acc,
|
|
418
|
+
{
|
|
419
|
+
name: event.name,
|
|
420
|
+
value: typeof value === "string" ? value : JSON.stringify(value),
|
|
421
|
+
response: typeof event.response === "string" ? event.response : JSON.stringify(event.response)
|
|
422
|
+
}
|
|
423
|
+
];
|
|
424
|
+
}
|
|
425
|
+
return acc;
|
|
426
|
+
default:
|
|
427
|
+
return acc;
|
|
428
|
+
}
|
|
429
|
+
}, []);
|
|
430
|
+
},
|
|
431
|
+
[setLangGraphInterruptAction]
|
|
432
|
+
);
|
|
346
433
|
const append = useAsyncCallback(
|
|
347
434
|
(message, options2) => __async(this, null, function* () {
|
|
348
435
|
var _a;
|
|
@@ -358,18 +445,25 @@ function useChat(options) {
|
|
|
358
445
|
}),
|
|
359
446
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
360
447
|
);
|
|
361
|
-
const reload = useAsyncCallback(
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
448
|
+
const reload = useAsyncCallback(
|
|
449
|
+
(messageId) => __async(this, null, function* () {
|
|
450
|
+
if (isLoading || messages.length === 0) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const index = messages.findIndex((msg) => msg.id === messageId);
|
|
454
|
+
if (index === -1) {
|
|
455
|
+
console.warn(`Message with id ${messageId} not found`);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
let newMessages = messages.slice(0, index);
|
|
459
|
+
if (newMessages.length > 0 && newMessages[newMessages.length - 1].isAgentStateMessage()) {
|
|
460
|
+
newMessages = newMessages.slice(0, newMessages.length - 1);
|
|
461
|
+
}
|
|
462
|
+
setMessages(newMessages);
|
|
463
|
+
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
464
|
+
}),
|
|
465
|
+
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
466
|
+
);
|
|
373
467
|
const stop = () => {
|
|
374
468
|
var _a;
|
|
375
469
|
(_a = chatAbortControllerRef.current) == null ? void 0 : _a.abort("Stop was called");
|
|
@@ -398,8 +492,69 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
398
492
|
}
|
|
399
493
|
return finalMessages;
|
|
400
494
|
}
|
|
495
|
+
function executeAction(_0) {
|
|
496
|
+
return __async(this, arguments, function* ({
|
|
497
|
+
onFunctionCall,
|
|
498
|
+
previousMessages,
|
|
499
|
+
message,
|
|
500
|
+
chatAbortControllerRef,
|
|
501
|
+
onError
|
|
502
|
+
}) {
|
|
503
|
+
let result;
|
|
504
|
+
let error = null;
|
|
505
|
+
try {
|
|
506
|
+
result = yield Promise.race([
|
|
507
|
+
onFunctionCall({
|
|
508
|
+
messages: previousMessages,
|
|
509
|
+
name: message.name,
|
|
510
|
+
args: message.arguments
|
|
511
|
+
}),
|
|
512
|
+
new Promise(
|
|
513
|
+
(resolve) => {
|
|
514
|
+
var _a;
|
|
515
|
+
return (_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.addEventListener(
|
|
516
|
+
"abort",
|
|
517
|
+
() => resolve("Operation was aborted by the user")
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
),
|
|
521
|
+
// if the user stopped generation, we also abort consecutive actions
|
|
522
|
+
new Promise((resolve) => {
|
|
523
|
+
var _a;
|
|
524
|
+
if ((_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.aborted) {
|
|
525
|
+
resolve("Operation was aborted by the user");
|
|
526
|
+
}
|
|
527
|
+
})
|
|
528
|
+
]);
|
|
529
|
+
} catch (e) {
|
|
530
|
+
onError(e);
|
|
531
|
+
}
|
|
532
|
+
return new ResultMessage({
|
|
533
|
+
id: "result-" + message.id,
|
|
534
|
+
result: ResultMessage.encodeResult(
|
|
535
|
+
error ? {
|
|
536
|
+
content: result,
|
|
537
|
+
error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
|
|
538
|
+
} : result
|
|
539
|
+
),
|
|
540
|
+
actionExecutionId: message.id,
|
|
541
|
+
actionName: message.name
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
function getPairedFeAction(actions, message) {
|
|
546
|
+
let actionName = null;
|
|
547
|
+
if (message.isActionExecutionMessage()) {
|
|
548
|
+
actionName = message.name;
|
|
549
|
+
} else if (message.isResultMessage()) {
|
|
550
|
+
actionName = message.actionName;
|
|
551
|
+
}
|
|
552
|
+
return actions.find(
|
|
553
|
+
(action) => action.name === actionName && action.available === "frontend" || action.pairedAction === actionName
|
|
554
|
+
);
|
|
555
|
+
}
|
|
401
556
|
|
|
402
557
|
export {
|
|
403
558
|
useChat
|
|
404
559
|
};
|
|
405
|
-
//# sourceMappingURL=chunk-
|
|
560
|
+
//# sourceMappingURL=chunk-42SVH3TY.mjs.map
|