@copilotkit/react-core 1.6.0-next.1 → 1.6.0-next.11
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 +77 -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-VMYLY5KI.mjs → chunk-4EC4JK7H.mjs} +58 -48
- package/dist/chunk-4EC4JK7H.mjs.map +1 -0
- package/dist/{chunk-ZAU4EMBM.mjs → chunk-F7O6L7C3.mjs} +4 -5
- package/dist/chunk-F7O6L7C3.mjs.map +1 -0
- package/dist/{chunk-2DPTBHGN.mjs → chunk-FUO5LKSJ.mjs} +115 -63
- package/dist/chunk-FUO5LKSJ.mjs.map +1 -0
- package/dist/{chunk-4ED56DQX.mjs → chunk-HBCP2KNA.mjs} +3 -4
- package/dist/chunk-HBCP2KNA.mjs.map +1 -0
- package/dist/{chunk-Z3U4UBG2.mjs → chunk-T4CAQC6B.mjs} +2 -2
- package/dist/{chunk-JFCNSGNU.mjs → chunk-Y2T56VSE.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -2
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -2
- package/dist/components/copilot-provider/index.d.ts +1 -2
- package/dist/components/index.d.ts +1 -2
- package/dist/context/copilot-context.d.ts +10 -148
- package/dist/context/index.d.ts +1 -2
- package/dist/copilot-context-9ae8990b.d.ts +183 -0
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +180 -123
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +6 -6
- package/dist/hooks/use-chat.d.ts +1 -2
- package/dist/hooks/use-chat.js +113 -64
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +2 -2
- package/dist/hooks/use-coagent.d.ts +1 -2
- package/dist/hooks/use-coagent.js +171 -112
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +4 -4
- package/dist/hooks/use-copilot-chat.d.ts +1 -2
- package/dist/hooks/use-copilot-chat.js +116 -67
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +3 -3
- package/dist/hooks/use-langgraph-interrupt-render.js +3 -4
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt.d.ts +9 -2
- package/dist/hooks/use-langgraph-interrupt.js +117 -69
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +4 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.js +187 -130
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/lib/copilot-task.d.ts +1 -2
- package/dist/lib/copilot-task.js +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +2 -2
- package/dist/lib/index.d.ts +1 -2
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +2 -2
- 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/interrupt-action.d.ts +10 -35
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/utils/extract.d.ts +1 -2
- package/dist/utils/index.d.ts +1 -2
- package/package.json +3 -3
- package/src/hooks/use-chat.ts +134 -61
- package/src/hooks/use-coagent.ts +70 -56
- package/src/hooks/use-langgraph-interrupt-render.ts +7 -3
- package/src/hooks/use-langgraph-interrupt.ts +1 -2
- package/src/types/frontend-action.ts +5 -2
- package/src/types/interrupt-action.ts +16 -12
- package/dist/chunk-2DPTBHGN.mjs.map +0 -1
- package/dist/chunk-4ED56DQX.mjs.map +0 -1
- package/dist/chunk-VMYLY5KI.mjs.map +0 -1
- package/dist/chunk-ZAU4EMBM.mjs.map +0 -1
- /package/dist/{chunk-Z3U4UBG2.mjs.map → chunk-T4CAQC6B.mjs.map} +0 -0
- /package/dist/{chunk-JFCNSGNU.mjs.map → chunk-Y2T56VSE.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1557,7 +1557,7 @@ function validateProps(props) {
|
|
|
1557
1557
|
|
|
1558
1558
|
// src/hooks/use-copilot-chat.ts
|
|
1559
1559
|
var import_react12 = require("react");
|
|
1560
|
-
var
|
|
1560
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1561
1561
|
|
|
1562
1562
|
// src/hooks/use-chat.ts
|
|
1563
1563
|
var import_react11 = require("react");
|
|
@@ -1569,7 +1569,7 @@ var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
|
1569
1569
|
var import_shared9 = require("@copilotkit/shared");
|
|
1570
1570
|
function processActionsForRuntimeRequest(actions) {
|
|
1571
1571
|
const filteredActions = actions.filter(
|
|
1572
|
-
(action) => action.available !== import_runtime_client_gql5.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
|
|
1572
|
+
(action) => action.available !== import_runtime_client_gql5.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
|
|
1573
1573
|
).map((action) => {
|
|
1574
1574
|
let available = import_runtime_client_gql5.ActionInputAvailability.Enabled;
|
|
1575
1575
|
if (action.disabled) {
|
|
@@ -1590,7 +1590,6 @@ function processActionsForRuntimeRequest(actions) {
|
|
|
1590
1590
|
}
|
|
1591
1591
|
|
|
1592
1592
|
// src/hooks/use-chat.ts
|
|
1593
|
-
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1594
1593
|
function useChat(options) {
|
|
1595
1594
|
const {
|
|
1596
1595
|
messages,
|
|
@@ -1639,7 +1638,7 @@ function useChat(options) {
|
|
|
1639
1638
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1640
1639
|
setIsLoading(true);
|
|
1641
1640
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
1642
|
-
if ((interruptEvent == null ? void 0 : interruptEvent.name) ===
|
|
1641
|
+
if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
|
|
1643
1642
|
addErrorToast([
|
|
1644
1643
|
new Error(
|
|
1645
1644
|
"A message was sent while interrupt is active. This will cause failure on the agent side"
|
|
@@ -1733,19 +1732,16 @@ function useChat(options) {
|
|
|
1733
1732
|
setExtensions(extensionsRef.current);
|
|
1734
1733
|
let rawMessagesResponse = value.generateCopilotResponse.messages;
|
|
1735
1734
|
((_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : []).forEach((ev) => {
|
|
1736
|
-
if (ev.name ===
|
|
1735
|
+
if (ev.name === import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent) {
|
|
1737
1736
|
let eventValue = (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev).value;
|
|
1738
|
-
|
|
1739
|
-
eventValue = JSON.parse(eventValue);
|
|
1740
|
-
} catch (e) {
|
|
1741
|
-
}
|
|
1737
|
+
eventValue = (0, import_shared10.parseJson)(eventValue, eventValue);
|
|
1742
1738
|
setLangGraphInterruptAction({
|
|
1743
1739
|
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev)), {
|
|
1744
1740
|
value: eventValue
|
|
1745
1741
|
})
|
|
1746
1742
|
});
|
|
1747
1743
|
}
|
|
1748
|
-
if (ev.name ===
|
|
1744
|
+
if (ev.name === import_runtime_client_gql6.MetaEventName.CopilotKitLangGraphInterruptEvent) {
|
|
1749
1745
|
const data = ev.data;
|
|
1750
1746
|
rawMessagesResponse = [...rawMessagesResponse, ...data.messages];
|
|
1751
1747
|
interruptMessages = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
|
|
@@ -1826,7 +1822,7 @@ function useChat(options) {
|
|
|
1826
1822
|
setMessages([...previousMessages, ...newMessages]);
|
|
1827
1823
|
}
|
|
1828
1824
|
}
|
|
1829
|
-
|
|
1825
|
+
let finalMessages = constructFinalMessages(
|
|
1830
1826
|
[...syncedMessages, ...interruptMessages],
|
|
1831
1827
|
previousMessages,
|
|
1832
1828
|
newMessages
|
|
@@ -1836,7 +1832,7 @@ function useChat(options) {
|
|
|
1836
1832
|
const lastMessages = [];
|
|
1837
1833
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
1838
1834
|
const message = finalMessages[i];
|
|
1839
|
-
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql6.MessageStatusCode.Pending) {
|
|
1835
|
+
if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !== import_runtime_client_gql6.MessageStatusCode.Pending) {
|
|
1840
1836
|
lastMessages.unshift(message);
|
|
1841
1837
|
} else {
|
|
1842
1838
|
break;
|
|
@@ -1844,59 +1840,51 @@ function useChat(options) {
|
|
|
1844
1840
|
}
|
|
1845
1841
|
for (const message of lastMessages) {
|
|
1846
1842
|
setMessages(finalMessages);
|
|
1847
|
-
const action = actions.find(
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
"abort",
|
|
1864
|
-
() => resolve("Operation was aborted by the user")
|
|
1865
|
-
);
|
|
1866
|
-
}
|
|
1867
|
-
),
|
|
1868
|
-
// if the user stopped generation, we also abort consecutive actions
|
|
1869
|
-
new Promise((resolve) => {
|
|
1870
|
-
var _a2;
|
|
1871
|
-
if ((_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.aborted) {
|
|
1872
|
-
resolve("Operation was aborted by the user");
|
|
1873
|
-
}
|
|
1874
|
-
})
|
|
1875
|
-
]);
|
|
1876
|
-
} catch (e) {
|
|
1877
|
-
error = e;
|
|
1878
|
-
addErrorToast([error]);
|
|
1879
|
-
result = `Failed to execute action ${message.name}. ${error.message}`;
|
|
1880
|
-
console.error(`Failed to execute action ${message.name}: ${error}`);
|
|
1881
|
-
}
|
|
1843
|
+
const action = actions.find(
|
|
1844
|
+
(action2) => action2.name === message.name
|
|
1845
|
+
);
|
|
1846
|
+
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
1847
|
+
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
1848
|
+
followUp = action2 == null ? void 0 : action2.followUp;
|
|
1849
|
+
const resultMessage = yield executeAction({
|
|
1850
|
+
onFunctionCall,
|
|
1851
|
+
previousMessages,
|
|
1852
|
+
message: message2,
|
|
1853
|
+
chatAbortControllerRef,
|
|
1854
|
+
onError: (error) => {
|
|
1855
|
+
addErrorToast([error]);
|
|
1856
|
+
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
1857
|
+
}
|
|
1858
|
+
});
|
|
1882
1859
|
didExecuteAction = true;
|
|
1883
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id ===
|
|
1884
|
-
finalMessages.splice(
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1860
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
1861
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
1862
|
+
return resultMessage;
|
|
1863
|
+
});
|
|
1864
|
+
if (action && message.isActionExecutionMessage()) {
|
|
1865
|
+
const resultMessage = yield executeActionFromMessage(action, message);
|
|
1866
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
1867
|
+
if (pairedFeAction) {
|
|
1868
|
+
const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
|
|
1869
|
+
name: pairedFeAction.name,
|
|
1870
|
+
arguments: (0, import_shared10.parseJson)(resultMessage.result, resultMessage.result),
|
|
1871
|
+
status: message.status,
|
|
1872
|
+
createdAt: message.createdAt,
|
|
1873
|
+
parentMessageId: message.parentMessageId
|
|
1874
|
+
});
|
|
1875
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
1876
|
+
}
|
|
1877
|
+
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
1878
|
+
const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
|
|
1879
|
+
name: currentResultMessagePairedFeAction.name,
|
|
1880
|
+
arguments: (0, import_shared10.parseJson)(message.result, message.result),
|
|
1881
|
+
status: message.status,
|
|
1882
|
+
createdAt: message.createdAt
|
|
1883
|
+
});
|
|
1884
|
+
finalMessages.push(newExecutionMessage);
|
|
1885
|
+
yield executeActionFromMessage(
|
|
1886
|
+
currentResultMessagePairedFeAction,
|
|
1887
|
+
newExecutionMessage
|
|
1900
1888
|
);
|
|
1901
1889
|
}
|
|
1902
1890
|
}
|
|
@@ -1967,7 +1955,7 @@ function useChat(options) {
|
|
|
1967
1955
|
if (!event)
|
|
1968
1956
|
return acc;
|
|
1969
1957
|
switch (event.name) {
|
|
1970
|
-
case
|
|
1958
|
+
case import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent:
|
|
1971
1959
|
if (event.response) {
|
|
1972
1960
|
setLangGraphInterruptAction(null);
|
|
1973
1961
|
const value = event.value;
|
|
@@ -2043,6 +2031,67 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
2043
2031
|
}
|
|
2044
2032
|
return finalMessages;
|
|
2045
2033
|
}
|
|
2034
|
+
function executeAction(_0) {
|
|
2035
|
+
return __async(this, arguments, function* ({
|
|
2036
|
+
onFunctionCall,
|
|
2037
|
+
previousMessages,
|
|
2038
|
+
message,
|
|
2039
|
+
chatAbortControllerRef,
|
|
2040
|
+
onError
|
|
2041
|
+
}) {
|
|
2042
|
+
let result;
|
|
2043
|
+
let error = null;
|
|
2044
|
+
try {
|
|
2045
|
+
result = yield Promise.race([
|
|
2046
|
+
onFunctionCall({
|
|
2047
|
+
messages: previousMessages,
|
|
2048
|
+
name: message.name,
|
|
2049
|
+
args: message.arguments
|
|
2050
|
+
}),
|
|
2051
|
+
new Promise(
|
|
2052
|
+
(resolve) => {
|
|
2053
|
+
var _a;
|
|
2054
|
+
return (_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.addEventListener(
|
|
2055
|
+
"abort",
|
|
2056
|
+
() => resolve("Operation was aborted by the user")
|
|
2057
|
+
);
|
|
2058
|
+
}
|
|
2059
|
+
),
|
|
2060
|
+
// if the user stopped generation, we also abort consecutive actions
|
|
2061
|
+
new Promise((resolve) => {
|
|
2062
|
+
var _a;
|
|
2063
|
+
if ((_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.aborted) {
|
|
2064
|
+
resolve("Operation was aborted by the user");
|
|
2065
|
+
}
|
|
2066
|
+
})
|
|
2067
|
+
]);
|
|
2068
|
+
} catch (e) {
|
|
2069
|
+
onError(e);
|
|
2070
|
+
}
|
|
2071
|
+
return new import_runtime_client_gql6.ResultMessage({
|
|
2072
|
+
id: "result-" + message.id,
|
|
2073
|
+
result: import_runtime_client_gql6.ResultMessage.encodeResult(
|
|
2074
|
+
error ? {
|
|
2075
|
+
content: result,
|
|
2076
|
+
error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
|
|
2077
|
+
} : result
|
|
2078
|
+
),
|
|
2079
|
+
actionExecutionId: message.id,
|
|
2080
|
+
actionName: message.name
|
|
2081
|
+
});
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
function getPairedFeAction(actions, message) {
|
|
2085
|
+
let actionName = null;
|
|
2086
|
+
if (message.isActionExecutionMessage()) {
|
|
2087
|
+
actionName = message.name;
|
|
2088
|
+
} else if (message.isResultMessage()) {
|
|
2089
|
+
actionName = message.actionName;
|
|
2090
|
+
}
|
|
2091
|
+
return actions.find(
|
|
2092
|
+
(action) => action.name === actionName && action.available === "frontend" || action.pairedAction === actionName
|
|
2093
|
+
);
|
|
2094
|
+
}
|
|
2046
2095
|
|
|
2047
2096
|
// src/hooks/use-copilot-chat.ts
|
|
2048
2097
|
function useCopilotChat(_a = {}) {
|
|
@@ -2087,9 +2136,9 @@ function useCopilotChat(_a = {}) {
|
|
|
2087
2136
|
const makeSystemMessageCallback = (0, import_react12.useCallback)(() => {
|
|
2088
2137
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
2089
2138
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
2090
|
-
return new
|
|
2139
|
+
return new import_runtime_client_gql7.TextMessage({
|
|
2091
2140
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
2092
|
-
role:
|
|
2141
|
+
role: import_runtime_client_gql7.Role.System
|
|
2093
2142
|
});
|
|
2094
2143
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
2095
2144
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -2455,15 +2504,13 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
2455
2504
|
|
|
2456
2505
|
// src/hooks/use-coagent.ts
|
|
2457
2506
|
var import_react17 = require("react");
|
|
2507
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2458
2508
|
function useCoAgent(options) {
|
|
2459
2509
|
const generalContext = useCopilotContext();
|
|
2460
2510
|
const { availableAgents } = generalContext;
|
|
2461
2511
|
const { addToast } = useToast();
|
|
2462
2512
|
const lastLoadedThreadId = (0, import_react17.useRef)();
|
|
2463
2513
|
const lastLoadedState = (0, import_react17.useRef)();
|
|
2464
|
-
const isExternalStateManagement = (options2) => {
|
|
2465
|
-
return "state" in options2 && "setState" in options2;
|
|
2466
|
-
};
|
|
2467
2514
|
const { name } = options;
|
|
2468
2515
|
(0, import_react17.useEffect)(() => {
|
|
2469
2516
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
@@ -2472,44 +2519,27 @@ function useCoAgent(options) {
|
|
|
2472
2519
|
addToast({ type: "warning", message });
|
|
2473
2520
|
}
|
|
2474
2521
|
}, [availableAgents]);
|
|
2475
|
-
const isInternalStateManagementWithInitial = (options2) => {
|
|
2476
|
-
return "initialState" in options2;
|
|
2477
|
-
};
|
|
2478
2522
|
const messagesContext = useCopilotMessagesContext();
|
|
2479
2523
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2480
2524
|
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
|
|
2481
2525
|
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
2482
|
-
const getCoagentState = (coagentStates2, name2) => {
|
|
2483
|
-
var _a;
|
|
2484
|
-
if (coagentStates2[name2]) {
|
|
2485
|
-
return coagentStates2[name2];
|
|
2486
|
-
} else {
|
|
2487
|
-
return {
|
|
2488
|
-
name: name2,
|
|
2489
|
-
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
2490
|
-
configurable: (_a = options.configurable) != null ? _a : {},
|
|
2491
|
-
running: false,
|
|
2492
|
-
active: false,
|
|
2493
|
-
threadId: void 0,
|
|
2494
|
-
nodeName: void 0,
|
|
2495
|
-
runId: void 0
|
|
2496
|
-
};
|
|
2497
|
-
}
|
|
2498
|
-
};
|
|
2499
2526
|
const runtimeClient = useCopilotRuntimeClient({
|
|
2500
2527
|
url: copilotApiConfig.chatApiEndpoint,
|
|
2501
2528
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
2502
2529
|
credentials: copilotApiConfig.credentials
|
|
2503
2530
|
});
|
|
2504
|
-
const setState = (
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2531
|
+
const setState = (0, import_react17.useCallback)(
|
|
2532
|
+
(newState) => {
|
|
2533
|
+
let coagentState = getCoagentState({ coagentStates, name, options });
|
|
2534
|
+
const updatedState = typeof newState === "function" ? newState(coagentState.state) : newState;
|
|
2535
|
+
setCoagentStatesWithRef(__spreadProps(__spreadValues({}, coagentStatesRef.current), {
|
|
2536
|
+
[name]: __spreadProps(__spreadValues({}, coagentState), {
|
|
2537
|
+
state: updatedState
|
|
2538
|
+
})
|
|
2539
|
+
}));
|
|
2540
|
+
},
|
|
2541
|
+
[coagentStates, name]
|
|
2542
|
+
);
|
|
2513
2543
|
(0, import_react17.useEffect)(() => {
|
|
2514
2544
|
const fetchAgentState = () => __async(this, null, function* () {
|
|
2515
2545
|
var _a, _b, _c, _d;
|
|
@@ -2525,13 +2555,12 @@ function useCoAgent(options) {
|
|
|
2525
2555
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
2526
2556
|
lastLoadedState.current = newState;
|
|
2527
2557
|
lastLoadedThreadId.current = threadId;
|
|
2528
|
-
const fetchedState =
|
|
2558
|
+
const fetchedState = (0, import_shared13.parseJson)(newState, {});
|
|
2529
2559
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
2530
2560
|
}
|
|
2531
2561
|
});
|
|
2532
2562
|
void fetchAgentState();
|
|
2533
2563
|
}, [threadId]);
|
|
2534
|
-
const coagentState = getCoagentState(coagentStates, name);
|
|
2535
2564
|
(0, import_react17.useEffect)(() => {
|
|
2536
2565
|
if (isExternalStateManagement(options)) {
|
|
2537
2566
|
setState(options.state);
|
|
@@ -2549,17 +2578,20 @@ function useCoAgent(options) {
|
|
|
2549
2578
|
}),
|
|
2550
2579
|
[name, context, appendMessage, runChatCompletion]
|
|
2551
2580
|
);
|
|
2552
|
-
return {
|
|
2553
|
-
name,
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2581
|
+
return (0, import_react17.useMemo)(() => {
|
|
2582
|
+
const coagentState = getCoagentState({ coagentStates, name, options });
|
|
2583
|
+
return {
|
|
2584
|
+
name,
|
|
2585
|
+
nodeName: coagentState.nodeName,
|
|
2586
|
+
threadId: coagentState.threadId,
|
|
2587
|
+
running: coagentState.running,
|
|
2588
|
+
state: coagentState.state,
|
|
2589
|
+
setState: isExternalStateManagement(options) ? options.setState : setState,
|
|
2590
|
+
start: () => startAgent(name, context),
|
|
2591
|
+
stop: () => stopAgent(name, context),
|
|
2592
|
+
run: runAgentCallback
|
|
2593
|
+
};
|
|
2594
|
+
}, [name, coagentStates, options, setState, runAgentCallback]);
|
|
2563
2595
|
}
|
|
2564
2596
|
function startAgent(name, context) {
|
|
2565
2597
|
const { setAgentSession } = context;
|
|
@@ -2615,6 +2647,33 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
2615
2647
|
}
|
|
2616
2648
|
});
|
|
2617
2649
|
}
|
|
2650
|
+
var isExternalStateManagement = (options) => {
|
|
2651
|
+
return "state" in options && "setState" in options;
|
|
2652
|
+
};
|
|
2653
|
+
var isInternalStateManagementWithInitial = (options) => {
|
|
2654
|
+
return "initialState" in options;
|
|
2655
|
+
};
|
|
2656
|
+
var getCoagentState = ({
|
|
2657
|
+
coagentStates,
|
|
2658
|
+
name,
|
|
2659
|
+
options
|
|
2660
|
+
}) => {
|
|
2661
|
+
var _a;
|
|
2662
|
+
if (coagentStates[name]) {
|
|
2663
|
+
return coagentStates[name];
|
|
2664
|
+
} else {
|
|
2665
|
+
return {
|
|
2666
|
+
name,
|
|
2667
|
+
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
2668
|
+
configurable: (_a = options.configurable) != null ? _a : {},
|
|
2669
|
+
running: false,
|
|
2670
|
+
active: false,
|
|
2671
|
+
threadId: void 0,
|
|
2672
|
+
nodeName: void 0,
|
|
2673
|
+
runId: void 0
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
};
|
|
2618
2677
|
|
|
2619
2678
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
2620
2679
|
var import_react18 = require("react");
|
|
@@ -2622,7 +2681,7 @@ var import_react19 = __toESM(require("react"));
|
|
|
2622
2681
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
2623
2682
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
2624
2683
|
const pendingActionRef = (0, import_react18.useRef)(null);
|
|
2625
|
-
const
|
|
2684
|
+
const executeAction2 = (0, import_react18.useCallback)(
|
|
2626
2685
|
(props) => {
|
|
2627
2686
|
if (typeof action.render === "function") {
|
|
2628
2687
|
return action.render(props);
|
|
@@ -2642,13 +2701,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
2642
2701
|
onSignInComplete: (authState) => {
|
|
2643
2702
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
2644
2703
|
if (pendingActionRef.current) {
|
|
2645
|
-
|
|
2704
|
+
executeAction2(pendingActionRef.current);
|
|
2646
2705
|
pendingActionRef.current = null;
|
|
2647
2706
|
}
|
|
2648
2707
|
}
|
|
2649
2708
|
}) : import_react19.default.createElement(import_react18.Fragment);
|
|
2650
2709
|
}
|
|
2651
|
-
return
|
|
2710
|
+
return executeAction2(props);
|
|
2652
2711
|
},
|
|
2653
2712
|
[action, authStates_c, setAuthStates_c]
|
|
2654
2713
|
);
|
|
@@ -2662,13 +2721,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
2662
2721
|
|
|
2663
2722
|
// src/hooks/use-langgraph-interrupt.ts
|
|
2664
2723
|
var import_react20 = require("react");
|
|
2665
|
-
var
|
|
2724
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
2666
2725
|
function useLangGraphInterrupt(action, dependencies) {
|
|
2667
2726
|
var _a;
|
|
2668
2727
|
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react20.useContext)(CopilotContext);
|
|
2669
2728
|
const { runChatCompletion } = useCopilotChat();
|
|
2670
2729
|
const { addToast } = useToast();
|
|
2671
|
-
const actionId = (0,
|
|
2730
|
+
const actionId = (0, import_shared14.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
2672
2731
|
const hasAction = (0, import_react20.useMemo)(
|
|
2673
2732
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
2674
2733
|
[langGraphInterruptAction]
|
|
@@ -2684,10 +2743,9 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
2684
2743
|
}
|
|
2685
2744
|
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
2686
2745
|
(0, import_react20.useEffect)(() => {
|
|
2687
|
-
var _a2;
|
|
2688
2746
|
if (!action)
|
|
2689
2747
|
return;
|
|
2690
|
-
if (hasAction && !isCurrentAction && !
|
|
2748
|
+
if (hasAction && !isCurrentAction && !action.enabled) {
|
|
2691
2749
|
addToast({
|
|
2692
2750
|
type: "warning",
|
|
2693
2751
|
message: "An action is already registered for the interrupt event"
|
|
@@ -2710,12 +2768,11 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
2710
2768
|
|
|
2711
2769
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
2712
2770
|
var import_react21 = __toESM(require("react"));
|
|
2713
|
-
var import_shared14 = require("@copilotkit/shared");
|
|
2714
2771
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
2715
2772
|
return render({ event, result, resolve });
|
|
2716
2773
|
};
|
|
2717
2774
|
function useLangGraphInterruptRender() {
|
|
2718
|
-
const { langGraphInterruptAction, setLangGraphInterruptAction } = useCopilotContext();
|
|
2775
|
+
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
2719
2776
|
const responseRef = import_react21.default.useRef();
|
|
2720
2777
|
const resolveInterrupt = (0, import_react21.useCallback)(
|
|
2721
2778
|
(response) => {
|
|
@@ -2728,8 +2785,8 @@ function useLangGraphInterruptRender() {
|
|
|
2728
2785
|
);
|
|
2729
2786
|
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
2730
2787
|
return null;
|
|
2731
|
-
const { render, handler, event,
|
|
2732
|
-
const conditionsMet =
|
|
2788
|
+
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
2789
|
+
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
2733
2790
|
if (!conditionsMet) {
|
|
2734
2791
|
return null;
|
|
2735
2792
|
}
|
|
@@ -2749,7 +2806,7 @@ function useLangGraphInterruptRender() {
|
|
|
2749
2806
|
}
|
|
2750
2807
|
|
|
2751
2808
|
// src/lib/copilot-task.ts
|
|
2752
|
-
var
|
|
2809
|
+
var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
|
|
2753
2810
|
var CopilotTask = class {
|
|
2754
2811
|
constructor(config) {
|
|
2755
2812
|
this.instructions = config.instructions;
|
|
@@ -2777,12 +2834,12 @@ var CopilotTask = class {
|
|
|
2777
2834
|
if (this.includeCopilotReadable) {
|
|
2778
2835
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
2779
2836
|
}
|
|
2780
|
-
const systemMessage = new
|
|
2837
|
+
const systemMessage = new import_runtime_client_gql8.TextMessage({
|
|
2781
2838
|
content: taskSystemMessage(contextString, this.instructions),
|
|
2782
|
-
role:
|
|
2839
|
+
role: import_runtime_client_gql8.Role.System
|
|
2783
2840
|
});
|
|
2784
2841
|
const messages = [systemMessage];
|
|
2785
|
-
const runtimeClient = new
|
|
2842
|
+
const runtimeClient = new import_runtime_client_gql8.CopilotRuntimeClient({
|
|
2786
2843
|
url: context.copilotApiConfig.chatApiEndpoint,
|
|
2787
2844
|
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
2788
2845
|
headers: context.copilotApiConfig.headers,
|
|
@@ -2794,9 +2851,9 @@ var CopilotTask = class {
|
|
|
2794
2851
|
actions: processActionsForRuntimeRequest(Object.values(actions)),
|
|
2795
2852
|
url: window.location.href
|
|
2796
2853
|
},
|
|
2797
|
-
messages: (0,
|
|
2854
|
+
messages: (0, import_runtime_client_gql8.convertMessagesToGqlInput)((0, import_runtime_client_gql8.filterAgentStateMessages)(messages)),
|
|
2798
2855
|
metadata: {
|
|
2799
|
-
requestType:
|
|
2856
|
+
requestType: import_runtime_client_gql8.CopilotRequestType.Task
|
|
2800
2857
|
},
|
|
2801
2858
|
forwardedParameters: __spreadProps(__spreadValues({}, (_a = this.forwardedParameters) != null ? _a : {}), {
|
|
2802
2859
|
toolChoice: "required"
|
|
@@ -2805,7 +2862,7 @@ var CopilotTask = class {
|
|
|
2805
2862
|
properties: context.copilotApiConfig.properties
|
|
2806
2863
|
}).toPromise();
|
|
2807
2864
|
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
2808
|
-
const functionCalls = (0,
|
|
2865
|
+
const functionCalls = (0, import_runtime_client_gql8.convertGqlOutputToMessages)(
|
|
2809
2866
|
((_c = (_b = response.data) == null ? void 0 : _b.generateCopilotResponse) == null ? void 0 : _c.messages) || []
|
|
2810
2867
|
).filter((m) => m.isActionExecutionMessage());
|
|
2811
2868
|
for (const functionCall of functionCalls) {
|