@copilotkit/react-core 1.9.2-next.9 → 1.9.3-next.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 +191 -0
- package/dist/{chunk-ERXWDCY6.mjs → chunk-36MGCCPZ.mjs} +2 -2
- package/dist/{chunk-UBNRUXEK.mjs → chunk-5BSUSFHM.mjs} +2 -2
- package/dist/{chunk-G7LYGERN.mjs → chunk-6ZLSC4KB.mjs} +124 -73
- package/dist/chunk-6ZLSC4KB.mjs.map +1 -0
- package/dist/{chunk-JDEWNLNP.mjs → chunk-BSAVFYRQ.mjs} +11 -11
- package/dist/{chunk-JDEWNLNP.mjs.map → chunk-BSAVFYRQ.mjs.map} +1 -1
- package/dist/{chunk-JPMIAGI6.mjs → chunk-BVK7PLK6.mjs} +2 -2
- package/dist/{chunk-FXK6RQIN.mjs → chunk-CUAFWKTQ.mjs} +4 -4
- package/dist/{chunk-XFOTNHYA.mjs → chunk-DKZTPL66.mjs} +2 -2
- package/dist/{chunk-XFOTNHYA.mjs.map → chunk-DKZTPL66.mjs.map} +1 -1
- package/dist/{chunk-EF5BNM34.mjs → chunk-FN3UA2ZE.mjs} +3 -3
- package/dist/{chunk-EXU7GWLC.mjs → chunk-GEE5AMYL.mjs} +9 -9
- package/dist/{chunk-WOGURSAL.mjs → chunk-GIMSRCVW.mjs} +64 -23
- package/dist/chunk-GIMSRCVW.mjs.map +1 -0
- package/dist/{chunk-55QZ2SVJ.mjs → chunk-JWAXDYOW.mjs} +8 -8
- package/dist/chunk-JWAXDYOW.mjs.map +1 -0
- package/dist/{chunk-3YHYWAHK.mjs → chunk-KIXKBJUV.mjs} +2 -2
- package/dist/{chunk-ADIITPD2.mjs → chunk-KLENTCQV.mjs} +34 -8
- package/dist/{chunk-ADIITPD2.mjs.map → chunk-KLENTCQV.mjs.map} +1 -1
- package/dist/{chunk-OF4SZTLL.mjs → chunk-NGQN3JRJ.mjs} +3 -3
- package/dist/{chunk-NQVCZQ5T.mjs → chunk-NJA5ZLAZ.mjs} +27 -8
- package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
- package/dist/{chunk-SJJNFYGQ.mjs → chunk-SGF6C7I6.mjs} +4 -4
- package/dist/{chunk-CMQV4XNY.mjs → chunk-VDADWRS3.mjs} +2 -2
- package/dist/components/copilot-provider/copilot-messages.js +7 -7
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
- package/dist/components/copilot-provider/copilotkit-props.d.ts +14 -9
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +70 -29
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +9 -9
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +70 -29
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -9
- package/dist/components/error-boundary/error-boundary.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +70 -29
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -9
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +1 -1
- 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 +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +4 -4
- package/dist/{copilot-context-3da805ab.d.ts → copilot-context-3ab4fdf5.d.ts} +3 -3
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +179 -83
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +23 -23
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +220 -169
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -4
- package/dist/hooks/use-coagent-state-render.js +1 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +154 -77
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -14
- package/dist/hooks/use-copilot-action.js +26 -7
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.js +1 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +26 -7
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +128 -77
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -13
- package/dist/hooks/use-copilot-readable.js +1 -1
- 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.d.ts +2 -2
- package/dist/hooks/use-copilot-runtime-client.js +7 -7
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +128 -77
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
- package/dist/hooks/use-make-copilot-document-readable.js +1 -1
- 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 +1 -1
- package/dist/index.js +240 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -27
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -11
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -11
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.js +26 -0
- package/dist/setupTests.js.map +1 -0
- package/dist/setupTests.mjs +24 -0
- package/dist/setupTests.mjs.map +1 -0
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +9 -9
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +10 -10
- package/jest.config.js +4 -0
- package/package.json +6 -3
- package/src/components/copilot-provider/__tests__/{copilotkit-trace.test.tsx → copilotkit-error.test.tsx} +17 -17
- package/src/components/copilot-provider/copilot-messages.tsx +7 -7
- package/src/components/copilot-provider/copilotkit-props.tsx +13 -8
- package/src/components/copilot-provider/copilotkit.tsx +61 -19
- package/src/context/copilot-context.tsx +4 -4
- package/src/hooks/__tests__/use-coagent-config.test.ts +284 -0
- package/src/hooks/use-chat.ts +149 -61
- package/src/hooks/use-coagent.ts +36 -0
- package/src/hooks/use-copilot-action.ts +51 -9
- package/src/hooks/use-copilot-runtime-client.ts +11 -12
- package/src/setupTests.ts +26 -0
- package/tsconfig.json +5 -2
- package/dist/chunk-55QZ2SVJ.mjs.map +0 -1
- package/dist/chunk-G7LYGERN.mjs.map +0 -1
- package/dist/chunk-NQVCZQ5T.mjs.map +0 -1
- package/dist/chunk-WOGURSAL.mjs.map +0 -1
- /package/dist/{chunk-ERXWDCY6.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
- /package/dist/{chunk-UBNRUXEK.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
- /package/dist/{chunk-JPMIAGI6.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
- /package/dist/{chunk-FXK6RQIN.mjs.map → chunk-CUAFWKTQ.mjs.map} +0 -0
- /package/dist/{chunk-EF5BNM34.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
- /package/dist/{chunk-EXU7GWLC.mjs.map → chunk-GEE5AMYL.mjs.map} +0 -0
- /package/dist/{chunk-3YHYWAHK.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
- /package/dist/{chunk-OF4SZTLL.mjs.map → chunk-NGQN3JRJ.mjs.map} +0 -0
- /package/dist/{chunk-SJJNFYGQ.mjs.map → chunk-SGF6C7I6.mjs.map} +0 -0
- /package/dist/{chunk-CMQV4XNY.mjs.map → chunk-VDADWRS3.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -184,7 +184,7 @@ var emptyCopilotContext = {
|
|
|
184
184
|
langGraphInterruptAction: null,
|
|
185
185
|
setLangGraphInterruptAction: () => null,
|
|
186
186
|
removeLangGraphInterruptAction: () => null,
|
|
187
|
-
|
|
187
|
+
onError: void 0
|
|
188
188
|
};
|
|
189
189
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
190
190
|
function useCopilotContext() {
|
|
@@ -738,11 +738,11 @@ function CopilotMessages({ children }) {
|
|
|
738
738
|
const lastLoadedThreadId = (0, import_react6.useRef)();
|
|
739
739
|
const lastLoadedAgentName = (0, import_react6.useRef)();
|
|
740
740
|
const lastLoadedMessages = (0, import_react6.useRef)();
|
|
741
|
-
const { threadId, agentSession, runtimeClient, showDevConsole,
|
|
741
|
+
const { threadId, agentSession, runtimeClient, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
|
|
742
742
|
const { setBannerError } = useToast();
|
|
743
743
|
const traceUIError = (0, import_react6.useCallback)(
|
|
744
744
|
(error, originalError) => __async(this, null, function* () {
|
|
745
|
-
if (!
|
|
745
|
+
if (!onError || !copilotApiConfig.publicApiKey)
|
|
746
746
|
return;
|
|
747
747
|
try {
|
|
748
748
|
const traceEvent = {
|
|
@@ -763,12 +763,12 @@ function CopilotMessages({ children }) {
|
|
|
763
763
|
},
|
|
764
764
|
error
|
|
765
765
|
};
|
|
766
|
-
yield
|
|
766
|
+
yield onError(traceEvent);
|
|
767
767
|
} catch (traceError) {
|
|
768
|
-
console.error("Error in CopilotMessages
|
|
768
|
+
console.error("Error in CopilotMessages onError handler:", traceError);
|
|
769
769
|
}
|
|
770
770
|
}),
|
|
771
|
-
[
|
|
771
|
+
[onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
|
|
772
772
|
);
|
|
773
773
|
const createStructuredError2 = (gqlError) => {
|
|
774
774
|
const extensions = gqlError.extensions;
|
|
@@ -873,7 +873,7 @@ function CopilotMessages({ children }) {
|
|
|
873
873
|
}
|
|
874
874
|
});
|
|
875
875
|
void fetchMessages();
|
|
876
|
-
}, [threadId, agentSession == null ? void 0 : agentSession.agentName
|
|
876
|
+
}, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
|
|
877
877
|
const memoizedChildren = (0, import_react6.useMemo)(() => children, [children]);
|
|
878
878
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
879
879
|
CopilotMessagesContext.Provider,
|
|
@@ -893,13 +893,13 @@ var import_react7 = require("react");
|
|
|
893
893
|
var import_shared5 = require("@copilotkit/shared");
|
|
894
894
|
var useCopilotRuntimeClient = (options) => {
|
|
895
895
|
const { setBannerError } = useToast();
|
|
896
|
-
const _a = options, { showDevConsole,
|
|
896
|
+
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
897
897
|
const lastStructuredErrorRef = (0, import_react7.useRef)(null);
|
|
898
898
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
899
|
-
if (!
|
|
899
|
+
if (!onError || !runtimeOptions.publicApiKey)
|
|
900
900
|
return;
|
|
901
901
|
try {
|
|
902
|
-
const
|
|
902
|
+
const errorEvent = {
|
|
903
903
|
type: "error",
|
|
904
904
|
timestamp: Date.now(),
|
|
905
905
|
context: {
|
|
@@ -917,9 +917,9 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
917
917
|
},
|
|
918
918
|
error
|
|
919
919
|
};
|
|
920
|
-
yield
|
|
921
|
-
} catch (
|
|
922
|
-
console.error("Error in
|
|
920
|
+
yield onError(errorEvent);
|
|
921
|
+
} catch (error2) {
|
|
922
|
+
console.error("Error in onError handler:", error2);
|
|
923
923
|
}
|
|
924
924
|
});
|
|
925
925
|
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
@@ -983,7 +983,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
983
983
|
setBannerError(warningError);
|
|
984
984
|
}
|
|
985
985
|
}));
|
|
986
|
-
}, [runtimeOptions, setBannerError, showDevConsole,
|
|
986
|
+
}, [runtimeOptions, setBannerError, showDevConsole, onError]);
|
|
987
987
|
return runtimeClient;
|
|
988
988
|
};
|
|
989
989
|
function createStructuredError(gqlError) {
|
|
@@ -1899,18 +1899,24 @@ ${nonDocumentStrings}`;
|
|
|
1899
1899
|
headers,
|
|
1900
1900
|
credentials: copilotApiConfig.credentials,
|
|
1901
1901
|
showDevConsole: (_b = props.showDevConsole) != null ? _b : false,
|
|
1902
|
-
|
|
1902
|
+
onError: props.onError
|
|
1903
1903
|
});
|
|
1904
1904
|
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
|
|
1905
|
-
const addChatSuggestionConfiguration = (
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
setChatSuggestionConfiguration
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1905
|
+
const addChatSuggestionConfiguration = (0, import_react10.useCallback)(
|
|
1906
|
+
(id, suggestion) => {
|
|
1907
|
+
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
1908
|
+
},
|
|
1909
|
+
[setChatSuggestionConfiguration]
|
|
1910
|
+
);
|
|
1911
|
+
const removeChatSuggestionConfiguration = (0, import_react10.useCallback)(
|
|
1912
|
+
(id) => {
|
|
1913
|
+
setChatSuggestionConfiguration((prev) => {
|
|
1914
|
+
const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
|
|
1915
|
+
return rest;
|
|
1916
|
+
});
|
|
1917
|
+
},
|
|
1918
|
+
[setChatSuggestionConfiguration]
|
|
1919
|
+
);
|
|
1914
1920
|
const [availableAgents, setAvailableAgents] = (0, import_react10.useState)([]);
|
|
1915
1921
|
const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
|
|
1916
1922
|
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
@@ -1990,6 +1996,41 @@ ${nonDocumentStrings}`;
|
|
|
1990
1996
|
setLangGraphInterruptAction(null);
|
|
1991
1997
|
}, []);
|
|
1992
1998
|
const memoizedChildren = (0, import_react10.useMemo)(() => children, [children]);
|
|
1999
|
+
const agentLock = (0, import_react10.useMemo)(() => {
|
|
2000
|
+
var _a2;
|
|
2001
|
+
return (_a2 = props.agent) != null ? _a2 : null;
|
|
2002
|
+
}, [props.agent]);
|
|
2003
|
+
const forwardedParameters = (0, import_react10.useMemo)(
|
|
2004
|
+
() => {
|
|
2005
|
+
var _a2;
|
|
2006
|
+
return (_a2 = props.forwardedParameters) != null ? _a2 : {};
|
|
2007
|
+
},
|
|
2008
|
+
[props.forwardedParameters]
|
|
2009
|
+
);
|
|
2010
|
+
const updateExtensions = (0, import_react10.useCallback)(
|
|
2011
|
+
(newExtensions) => {
|
|
2012
|
+
setExtensions((prev) => {
|
|
2013
|
+
const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
|
|
2014
|
+
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
2015
|
+
const isEqual = isSameLength && // @ts-ignore
|
|
2016
|
+
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
2017
|
+
return isEqual ? prev : resolved;
|
|
2018
|
+
});
|
|
2019
|
+
},
|
|
2020
|
+
[setExtensions]
|
|
2021
|
+
);
|
|
2022
|
+
const updateAuthStates = (0, import_react10.useCallback)(
|
|
2023
|
+
(newAuthStates) => {
|
|
2024
|
+
setAuthStates((prev) => {
|
|
2025
|
+
const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
|
|
2026
|
+
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
2027
|
+
const isEqual = isSameLength && // @ts-ignore
|
|
2028
|
+
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
2029
|
+
return isEqual ? prev : resolved;
|
|
2030
|
+
});
|
|
2031
|
+
},
|
|
2032
|
+
[setAuthStates]
|
|
2033
|
+
);
|
|
1993
2034
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1994
2035
|
CopilotContext.Provider,
|
|
1995
2036
|
{
|
|
@@ -2027,8 +2068,8 @@ ${nonDocumentStrings}`;
|
|
|
2027
2068
|
agentSession,
|
|
2028
2069
|
setAgentSession,
|
|
2029
2070
|
runtimeClient,
|
|
2030
|
-
forwardedParameters
|
|
2031
|
-
agentLock
|
|
2071
|
+
forwardedParameters,
|
|
2072
|
+
agentLock,
|
|
2032
2073
|
threadId: internalThreadId,
|
|
2033
2074
|
setThreadId,
|
|
2034
2075
|
runId,
|
|
@@ -2037,13 +2078,13 @@ ${nonDocumentStrings}`;
|
|
|
2037
2078
|
availableAgents,
|
|
2038
2079
|
authConfig_c: props.authConfig_c,
|
|
2039
2080
|
authStates_c: authStates,
|
|
2040
|
-
setAuthStates_c:
|
|
2081
|
+
setAuthStates_c: updateAuthStates,
|
|
2041
2082
|
extensions,
|
|
2042
|
-
setExtensions,
|
|
2083
|
+
setExtensions: updateExtensions,
|
|
2043
2084
|
langGraphInterruptAction,
|
|
2044
2085
|
setLangGraphInterruptAction,
|
|
2045
2086
|
removeLangGraphInterruptAction,
|
|
2046
|
-
|
|
2087
|
+
onError: props.onError
|
|
2047
2088
|
},
|
|
2048
2089
|
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children: memoizedChildren })
|
|
2049
2090
|
}
|
|
@@ -2096,6 +2137,7 @@ var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
|
2096
2137
|
|
|
2097
2138
|
// src/hooks/use-chat.ts
|
|
2098
2139
|
var import_react11 = require("react");
|
|
2140
|
+
var import_react_dom2 = require("react-dom");
|
|
2099
2141
|
var import_shared12 = require("@copilotkit/shared");
|
|
2100
2142
|
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
2101
2143
|
|
|
@@ -2155,9 +2197,9 @@ function useChat(options) {
|
|
|
2155
2197
|
const runChatCompletionRef = (0, import_react11.useRef)();
|
|
2156
2198
|
const addErrorToast = useErrorToast();
|
|
2157
2199
|
const { setBannerError } = useToast();
|
|
2158
|
-
const {
|
|
2200
|
+
const { onError } = useCopilotContext();
|
|
2159
2201
|
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
2160
|
-
if (!
|
|
2202
|
+
if (!onError || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
|
|
2161
2203
|
return;
|
|
2162
2204
|
try {
|
|
2163
2205
|
const traceEvent = {
|
|
@@ -2178,9 +2220,9 @@ function useChat(options) {
|
|
|
2178
2220
|
},
|
|
2179
2221
|
error
|
|
2180
2222
|
};
|
|
2181
|
-
yield
|
|
2223
|
+
yield onError(traceEvent);
|
|
2182
2224
|
} catch (traceError) {
|
|
2183
|
-
console.error("Error in use-chat
|
|
2225
|
+
console.error("Error in use-chat onError handler:", traceError);
|
|
2184
2226
|
}
|
|
2185
2227
|
});
|
|
2186
2228
|
const agentSessionRef = (0, import_react11.useRef)(agentSession);
|
|
@@ -2402,17 +2444,22 @@ function useChat(options) {
|
|
|
2402
2444
|
lastAgentStateMessage.state.messages
|
|
2403
2445
|
);
|
|
2404
2446
|
}
|
|
2405
|
-
setCoagentStatesWithRef((prevAgentStates) =>
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2447
|
+
setCoagentStatesWithRef((prevAgentStates) => {
|
|
2448
|
+
var _a2;
|
|
2449
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
2450
|
+
[lastAgentStateMessage.agentName]: {
|
|
2451
|
+
name: lastAgentStateMessage.agentName,
|
|
2452
|
+
state: lastAgentStateMessage.state,
|
|
2453
|
+
running: lastAgentStateMessage.running,
|
|
2454
|
+
active: lastAgentStateMessage.active,
|
|
2455
|
+
threadId: lastAgentStateMessage.threadId,
|
|
2456
|
+
nodeName: lastAgentStateMessage.nodeName,
|
|
2457
|
+
runId: lastAgentStateMessage.runId,
|
|
2458
|
+
// Preserve existing config from previous state
|
|
2459
|
+
config: (_a2 = prevAgentStates[lastAgentStateMessage.agentName]) == null ? void 0 : _a2.config
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
});
|
|
2416
2463
|
if (lastAgentStateMessage.running) {
|
|
2417
2464
|
setAgentSession({
|
|
2418
2465
|
threadId: lastAgentStateMessage.threadId,
|
|
@@ -2442,6 +2489,39 @@ function useChat(options) {
|
|
|
2442
2489
|
newMessages
|
|
2443
2490
|
);
|
|
2444
2491
|
let didExecuteAction = false;
|
|
2492
|
+
const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
|
|
2493
|
+
var _a2;
|
|
2494
|
+
const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
|
|
2495
|
+
followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
|
|
2496
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
2497
|
+
currentAction._setActivatingMessageId(actionMessage.id);
|
|
2498
|
+
}
|
|
2499
|
+
const resultMessage = yield executeAction({
|
|
2500
|
+
onFunctionCall,
|
|
2501
|
+
message: actionMessage,
|
|
2502
|
+
chatAbortControllerRef,
|
|
2503
|
+
onError: (error) => {
|
|
2504
|
+
addErrorToast([error]);
|
|
2505
|
+
console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
|
|
2506
|
+
},
|
|
2507
|
+
setMessages,
|
|
2508
|
+
getFinalMessages: () => finalMessages,
|
|
2509
|
+
isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
|
|
2510
|
+
});
|
|
2511
|
+
didExecuteAction = true;
|
|
2512
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
|
|
2513
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
2514
|
+
if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
|
|
2515
|
+
const messagesForImmediateUpdate = [...finalMessages];
|
|
2516
|
+
(0, import_react_dom2.flushSync)(() => {
|
|
2517
|
+
setMessages(messagesForImmediateUpdate);
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
2521
|
+
currentAction._setActivatingMessageId(null);
|
|
2522
|
+
}
|
|
2523
|
+
return resultMessage;
|
|
2524
|
+
});
|
|
2445
2525
|
if (onFunctionCall) {
|
|
2446
2526
|
const lastMessages = [];
|
|
2447
2527
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
@@ -2458,37 +2538,28 @@ function useChat(options) {
|
|
|
2458
2538
|
(action2) => action2.name === message.name
|
|
2459
2539
|
);
|
|
2460
2540
|
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
2461
|
-
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
2462
|
-
var _a2;
|
|
2463
|
-
const isInterruptAction = interruptMessages.find((m) => m.id === message2.id);
|
|
2464
|
-
followUp = (_a2 = action2 == null ? void 0 : action2.followUp) != null ? _a2 : !isInterruptAction;
|
|
2465
|
-
const resultMessage = yield executeAction({
|
|
2466
|
-
onFunctionCall,
|
|
2467
|
-
previousMessages,
|
|
2468
|
-
message: message2,
|
|
2469
|
-
chatAbortControllerRef,
|
|
2470
|
-
onError: (error) => {
|
|
2471
|
-
addErrorToast([error]);
|
|
2472
|
-
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
2473
|
-
}
|
|
2474
|
-
});
|
|
2475
|
-
didExecuteAction = true;
|
|
2476
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
2477
|
-
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
2478
|
-
return resultMessage;
|
|
2479
|
-
});
|
|
2480
2541
|
if (action && message.isActionExecutionMessage()) {
|
|
2481
|
-
const
|
|
2482
|
-
const
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2542
|
+
const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
|
|
2543
|
+
const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
|
|
2544
|
+
(fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
|
|
2545
|
+
);
|
|
2546
|
+
if (alreadyProcessed) {
|
|
2547
|
+
} else {
|
|
2548
|
+
const resultMessage = yield executeActionFromMessage(
|
|
2549
|
+
action,
|
|
2550
|
+
message
|
|
2551
|
+
);
|
|
2552
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
2553
|
+
if (pairedFeAction) {
|
|
2554
|
+
const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
|
|
2555
|
+
name: pairedFeAction.name,
|
|
2556
|
+
arguments: (0, import_shared12.parseJson)(resultMessage.result, resultMessage.result),
|
|
2557
|
+
status: message.status,
|
|
2558
|
+
createdAt: message.createdAt,
|
|
2559
|
+
parentMessageId: message.parentMessageId
|
|
2560
|
+
});
|
|
2561
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
2562
|
+
}
|
|
2492
2563
|
}
|
|
2493
2564
|
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
2494
2565
|
const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
|
|
@@ -2506,13 +2577,9 @@ function useChat(options) {
|
|
|
2506
2577
|
}
|
|
2507
2578
|
setMessages(finalMessages);
|
|
2508
2579
|
}
|
|
2509
|
-
if (
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
(didExecuteAction || // the last message is a server side result
|
|
2513
|
-
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
2514
|
-
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)
|
|
2515
|
-
) {
|
|
2580
|
+
if (followUp !== false && (didExecuteAction || // the last message is a server side result
|
|
2581
|
+
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
2582
|
+
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
|
|
2516
2583
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
2517
2584
|
return yield runChatCompletionRef.current(finalMessages);
|
|
2518
2585
|
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
@@ -2620,21 +2687,35 @@ function useChat(options) {
|
|
|
2620
2687
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
2621
2688
|
);
|
|
2622
2689
|
const reload = useAsyncCallback(
|
|
2623
|
-
(
|
|
2690
|
+
(reloadMessageId) => __async(this, null, function* () {
|
|
2624
2691
|
if (isLoading || messages.length === 0) {
|
|
2625
2692
|
return;
|
|
2626
2693
|
}
|
|
2627
|
-
const
|
|
2628
|
-
if (
|
|
2629
|
-
console.warn(`Message with id ${
|
|
2694
|
+
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
2695
|
+
if (reloadMessageIndex === -1) {
|
|
2696
|
+
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
2630
2697
|
return;
|
|
2631
2698
|
}
|
|
2632
|
-
|
|
2633
|
-
if (
|
|
2634
|
-
|
|
2699
|
+
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
2700
|
+
if (reloadMessageRole !== import_runtime_client_gql6.MessageRole.Assistant) {
|
|
2701
|
+
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
2702
|
+
return;
|
|
2635
2703
|
}
|
|
2636
|
-
|
|
2637
|
-
|
|
2704
|
+
let historyCutoff = [];
|
|
2705
|
+
if (messages.length > 2) {
|
|
2706
|
+
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
|
|
2707
|
+
(msg) => (
|
|
2708
|
+
// @ts-expect-error -- message has role
|
|
2709
|
+
msg.role === import_runtime_client_gql6.MessageRole.User
|
|
2710
|
+
)
|
|
2711
|
+
);
|
|
2712
|
+
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
2713
|
+
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
2714
|
+
);
|
|
2715
|
+
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
2716
|
+
}
|
|
2717
|
+
setMessages(historyCutoff);
|
|
2718
|
+
return runChatCompletionAndHandleFunctionCall(historyCutoff);
|
|
2638
2719
|
}),
|
|
2639
2720
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
2640
2721
|
);
|
|
@@ -2669,20 +2750,31 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
2669
2750
|
function executeAction(_0) {
|
|
2670
2751
|
return __async(this, arguments, function* ({
|
|
2671
2752
|
onFunctionCall,
|
|
2672
|
-
previousMessages,
|
|
2673
2753
|
message,
|
|
2674
2754
|
chatAbortControllerRef,
|
|
2675
|
-
onError
|
|
2755
|
+
onError,
|
|
2756
|
+
setMessages,
|
|
2757
|
+
getFinalMessages,
|
|
2758
|
+
isRenderAndWait
|
|
2676
2759
|
}) {
|
|
2677
2760
|
let result;
|
|
2678
2761
|
let error = null;
|
|
2762
|
+
const currentMessagesForHandler = getFinalMessages();
|
|
2763
|
+
const handlerReturnedPromise = onFunctionCall({
|
|
2764
|
+
messages: currentMessagesForHandler,
|
|
2765
|
+
name: message.name,
|
|
2766
|
+
args: message.arguments
|
|
2767
|
+
});
|
|
2768
|
+
if (isRenderAndWait) {
|
|
2769
|
+
const currentMessagesForRender = getFinalMessages();
|
|
2770
|
+
(0, import_react_dom2.flushSync)(() => {
|
|
2771
|
+
setMessages([...currentMessagesForRender]);
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2679
2774
|
try {
|
|
2680
2775
|
result = yield Promise.race([
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
name: message.name,
|
|
2684
|
-
args: message.arguments
|
|
2685
|
-
}),
|
|
2776
|
+
handlerReturnedPromise,
|
|
2777
|
+
// Await the promise returned by the handler
|
|
2686
2778
|
new Promise(
|
|
2687
2779
|
(resolve) => {
|
|
2688
2780
|
var _a;
|
|
@@ -2949,6 +3041,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
2949
3041
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
2950
3042
|
const idRef = (0, import_react13.useRef)((0, import_shared13.randomId)());
|
|
2951
3043
|
const renderAndWaitRef = (0, import_react13.useRef)(null);
|
|
3044
|
+
const activatingMessageIdRef = (0, import_react13.useRef)(null);
|
|
2952
3045
|
const { addToast } = useToast();
|
|
2953
3046
|
action = __spreadValues({}, action);
|
|
2954
3047
|
if (
|
|
@@ -2956,30 +3049,48 @@ function useCopilotAction(action, dependencies) {
|
|
|
2956
3049
|
isFrontendAction(action) && // check if renderAndWaitForResponse is set
|
|
2957
3050
|
(action.renderAndWait || action.renderAndWaitForResponse)
|
|
2958
3051
|
) {
|
|
3052
|
+
action._isRenderAndWait = true;
|
|
2959
3053
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
2960
3054
|
action.renderAndWait = void 0;
|
|
2961
3055
|
action.renderAndWaitForResponse = void 0;
|
|
3056
|
+
action._setActivatingMessageId = (id) => {
|
|
3057
|
+
activatingMessageIdRef.current = id;
|
|
3058
|
+
};
|
|
2962
3059
|
action.handler = useAsyncCallback(() => __async(this, null, function* () {
|
|
3060
|
+
const currentActivatingId = activatingMessageIdRef.current;
|
|
2963
3061
|
let resolve;
|
|
2964
3062
|
let reject;
|
|
2965
3063
|
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
2966
3064
|
resolve = resolvePromise;
|
|
2967
3065
|
reject = rejectPromise;
|
|
2968
3066
|
});
|
|
2969
|
-
renderAndWaitRef.current = {
|
|
2970
|
-
|
|
3067
|
+
renderAndWaitRef.current = {
|
|
3068
|
+
promise,
|
|
3069
|
+
resolve,
|
|
3070
|
+
reject,
|
|
3071
|
+
messageId: currentActivatingId
|
|
3072
|
+
};
|
|
3073
|
+
const result = yield promise;
|
|
3074
|
+
return result;
|
|
2971
3075
|
}), []);
|
|
2972
3076
|
action.render = (props) => {
|
|
3077
|
+
const currentRenderMessageId = props.messageId;
|
|
2973
3078
|
let status = props.status;
|
|
2974
|
-
if (props.status === "executing"
|
|
2975
|
-
|
|
3079
|
+
if (props.status === "executing") {
|
|
3080
|
+
if (!renderAndWaitRef.current || !renderAndWaitRef.current.promise) {
|
|
3081
|
+
status = "inProgress";
|
|
3082
|
+
} else if (renderAndWaitRef.current.messageId !== currentRenderMessageId && activatingMessageIdRef.current !== currentRenderMessageId) {
|
|
3083
|
+
status = "inProgress";
|
|
3084
|
+
}
|
|
2976
3085
|
}
|
|
2977
3086
|
const waitProps = {
|
|
2978
3087
|
status,
|
|
2979
3088
|
args: props.args,
|
|
2980
3089
|
result: props.result,
|
|
2981
|
-
handler
|
|
2982
|
-
|
|
3090
|
+
// handler and respond should only be provided if this is the truly active instance
|
|
3091
|
+
// and its promise infrastructure is ready.
|
|
3092
|
+
handler: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0,
|
|
3093
|
+
respond: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0
|
|
2983
3094
|
};
|
|
2984
3095
|
const isNoArgsRenderWait = (_fn) => {
|
|
2985
3096
|
var _a;
|
|
@@ -3248,6 +3359,32 @@ function useCoAgent(options) {
|
|
|
3248
3359
|
// reset initialstate on reset
|
|
3249
3360
|
coagentStates[name] === void 0
|
|
3250
3361
|
]);
|
|
3362
|
+
(0, import_react17.useEffect)(() => {
|
|
3363
|
+
const newConfig = options.config ? options.config : options.configurable ? { configurable: options.configurable } : void 0;
|
|
3364
|
+
if (newConfig === void 0)
|
|
3365
|
+
return;
|
|
3366
|
+
setCoagentStatesWithRef((prev) => {
|
|
3367
|
+
var _a;
|
|
3368
|
+
const existing = (_a = prev[name]) != null ? _a : {
|
|
3369
|
+
name,
|
|
3370
|
+
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
3371
|
+
config: {},
|
|
3372
|
+
running: false,
|
|
3373
|
+
active: false,
|
|
3374
|
+
threadId: void 0,
|
|
3375
|
+
nodeName: void 0,
|
|
3376
|
+
runId: void 0
|
|
3377
|
+
};
|
|
3378
|
+
if (JSON.stringify(existing.config) === JSON.stringify(newConfig)) {
|
|
3379
|
+
return prev;
|
|
3380
|
+
}
|
|
3381
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
3382
|
+
[name]: __spreadProps(__spreadValues({}, existing), {
|
|
3383
|
+
config: newConfig
|
|
3384
|
+
})
|
|
3385
|
+
});
|
|
3386
|
+
});
|
|
3387
|
+
}, [JSON.stringify(options.config), JSON.stringify(options.configurable)]);
|
|
3251
3388
|
const runAgentCallback = useAsyncCallback(
|
|
3252
3389
|
(hint) => __async(this, null, function* () {
|
|
3253
3390
|
yield runAgent(name, context, appendMessage, runChatCompletion, hint);
|