@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/hooks/index.js
CHANGED
|
@@ -183,7 +183,7 @@ function returnAndThrowInDebug(_value) {
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
// src/hooks/use-copilot-chat.ts
|
|
186
|
-
var
|
|
186
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
187
187
|
|
|
188
188
|
// src/hooks/use-chat.ts
|
|
189
189
|
var import_react5 = require("react");
|
|
@@ -195,7 +195,7 @@ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
|
195
195
|
var import_shared = require("@copilotkit/shared");
|
|
196
196
|
function processActionsForRuntimeRequest(actions) {
|
|
197
197
|
const filteredActions = actions.filter(
|
|
198
|
-
(action) => action.available !== import_runtime_client_gql.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
|
|
198
|
+
(action) => action.available !== import_runtime_client_gql.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
|
|
199
199
|
).map((action) => {
|
|
200
200
|
let available = import_runtime_client_gql.ActionInputAvailability.Enabled;
|
|
201
201
|
if (action.disabled) {
|
|
@@ -372,7 +372,6 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
372
372
|
};
|
|
373
373
|
|
|
374
374
|
// src/hooks/use-chat.ts
|
|
375
|
-
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
376
375
|
function useChat(options) {
|
|
377
376
|
const {
|
|
378
377
|
messages,
|
|
@@ -421,7 +420,7 @@ function useChat(options) {
|
|
|
421
420
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
422
421
|
setIsLoading(true);
|
|
423
422
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
424
|
-
if ((interruptEvent == null ? void 0 : interruptEvent.name) ===
|
|
423
|
+
if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
|
|
425
424
|
addErrorToast([
|
|
426
425
|
new Error(
|
|
427
426
|
"A message was sent while interrupt is active. This will cause failure on the agent side"
|
|
@@ -515,19 +514,16 @@ function useChat(options) {
|
|
|
515
514
|
setExtensions(extensionsRef.current);
|
|
516
515
|
let rawMessagesResponse = value.generateCopilotResponse.messages;
|
|
517
516
|
((_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : []).forEach((ev) => {
|
|
518
|
-
if (ev.name ===
|
|
517
|
+
if (ev.name === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent) {
|
|
519
518
|
let eventValue = (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev).value;
|
|
520
|
-
|
|
521
|
-
eventValue = JSON.parse(eventValue);
|
|
522
|
-
} catch (e) {
|
|
523
|
-
}
|
|
519
|
+
eventValue = (0, import_shared2.parseJson)(eventValue, eventValue);
|
|
524
520
|
setLangGraphInterruptAction({
|
|
525
521
|
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev)), {
|
|
526
522
|
value: eventValue
|
|
527
523
|
})
|
|
528
524
|
});
|
|
529
525
|
}
|
|
530
|
-
if (ev.name ===
|
|
526
|
+
if (ev.name === import_runtime_client_gql3.MetaEventName.CopilotKitLangGraphInterruptEvent) {
|
|
531
527
|
const data = ev.data;
|
|
532
528
|
rawMessagesResponse = [...rawMessagesResponse, ...data.messages];
|
|
533
529
|
interruptMessages = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
@@ -608,7 +604,7 @@ function useChat(options) {
|
|
|
608
604
|
setMessages([...previousMessages, ...newMessages]);
|
|
609
605
|
}
|
|
610
606
|
}
|
|
611
|
-
|
|
607
|
+
let finalMessages = constructFinalMessages(
|
|
612
608
|
[...syncedMessages, ...interruptMessages],
|
|
613
609
|
previousMessages,
|
|
614
610
|
newMessages
|
|
@@ -618,7 +614,7 @@ function useChat(options) {
|
|
|
618
614
|
const lastMessages = [];
|
|
619
615
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
620
616
|
const message = finalMessages[i];
|
|
621
|
-
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql3.MessageStatusCode.Pending) {
|
|
617
|
+
if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !== import_runtime_client_gql3.MessageStatusCode.Pending) {
|
|
622
618
|
lastMessages.unshift(message);
|
|
623
619
|
} else {
|
|
624
620
|
break;
|
|
@@ -626,59 +622,51 @@ function useChat(options) {
|
|
|
626
622
|
}
|
|
627
623
|
for (const message of lastMessages) {
|
|
628
624
|
setMessages(finalMessages);
|
|
629
|
-
const action = actions.find(
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
"abort",
|
|
646
|
-
() => resolve("Operation was aborted by the user")
|
|
647
|
-
);
|
|
648
|
-
}
|
|
649
|
-
),
|
|
650
|
-
// if the user stopped generation, we also abort consecutive actions
|
|
651
|
-
new Promise((resolve) => {
|
|
652
|
-
var _a2;
|
|
653
|
-
if ((_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.aborted) {
|
|
654
|
-
resolve("Operation was aborted by the user");
|
|
655
|
-
}
|
|
656
|
-
})
|
|
657
|
-
]);
|
|
658
|
-
} catch (e) {
|
|
659
|
-
error = e;
|
|
660
|
-
addErrorToast([error]);
|
|
661
|
-
result = `Failed to execute action ${message.name}. ${error.message}`;
|
|
662
|
-
console.error(`Failed to execute action ${message.name}: ${error}`);
|
|
663
|
-
}
|
|
625
|
+
const action = actions.find(
|
|
626
|
+
(action2) => action2.name === message.name
|
|
627
|
+
);
|
|
628
|
+
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
629
|
+
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
630
|
+
followUp = action2 == null ? void 0 : action2.followUp;
|
|
631
|
+
const resultMessage = yield executeAction({
|
|
632
|
+
onFunctionCall,
|
|
633
|
+
previousMessages,
|
|
634
|
+
message: message2,
|
|
635
|
+
chatAbortControllerRef,
|
|
636
|
+
onError: (error) => {
|
|
637
|
+
addErrorToast([error]);
|
|
638
|
+
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
639
|
+
}
|
|
640
|
+
});
|
|
664
641
|
didExecuteAction = true;
|
|
665
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id ===
|
|
666
|
-
finalMessages.splice(
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
642
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
643
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
644
|
+
return resultMessage;
|
|
645
|
+
});
|
|
646
|
+
if (action && message.isActionExecutionMessage()) {
|
|
647
|
+
const resultMessage = yield executeActionFromMessage(action, message);
|
|
648
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
649
|
+
if (pairedFeAction) {
|
|
650
|
+
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
651
|
+
name: pairedFeAction.name,
|
|
652
|
+
arguments: (0, import_shared2.parseJson)(resultMessage.result, resultMessage.result),
|
|
653
|
+
status: message.status,
|
|
654
|
+
createdAt: message.createdAt,
|
|
655
|
+
parentMessageId: message.parentMessageId
|
|
656
|
+
});
|
|
657
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
658
|
+
}
|
|
659
|
+
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
660
|
+
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
661
|
+
name: currentResultMessagePairedFeAction.name,
|
|
662
|
+
arguments: (0, import_shared2.parseJson)(message.result, message.result),
|
|
663
|
+
status: message.status,
|
|
664
|
+
createdAt: message.createdAt
|
|
665
|
+
});
|
|
666
|
+
finalMessages.push(newExecutionMessage);
|
|
667
|
+
yield executeActionFromMessage(
|
|
668
|
+
currentResultMessagePairedFeAction,
|
|
669
|
+
newExecutionMessage
|
|
682
670
|
);
|
|
683
671
|
}
|
|
684
672
|
}
|
|
@@ -749,7 +737,7 @@ function useChat(options) {
|
|
|
749
737
|
if (!event)
|
|
750
738
|
return acc;
|
|
751
739
|
switch (event.name) {
|
|
752
|
-
case
|
|
740
|
+
case import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent:
|
|
753
741
|
if (event.response) {
|
|
754
742
|
setLangGraphInterruptAction(null);
|
|
755
743
|
const value = event.value;
|
|
@@ -825,6 +813,67 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
825
813
|
}
|
|
826
814
|
return finalMessages;
|
|
827
815
|
}
|
|
816
|
+
function executeAction(_0) {
|
|
817
|
+
return __async(this, arguments, function* ({
|
|
818
|
+
onFunctionCall,
|
|
819
|
+
previousMessages,
|
|
820
|
+
message,
|
|
821
|
+
chatAbortControllerRef,
|
|
822
|
+
onError
|
|
823
|
+
}) {
|
|
824
|
+
let result;
|
|
825
|
+
let error = null;
|
|
826
|
+
try {
|
|
827
|
+
result = yield Promise.race([
|
|
828
|
+
onFunctionCall({
|
|
829
|
+
messages: previousMessages,
|
|
830
|
+
name: message.name,
|
|
831
|
+
args: message.arguments
|
|
832
|
+
}),
|
|
833
|
+
new Promise(
|
|
834
|
+
(resolve) => {
|
|
835
|
+
var _a;
|
|
836
|
+
return (_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.addEventListener(
|
|
837
|
+
"abort",
|
|
838
|
+
() => resolve("Operation was aborted by the user")
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
),
|
|
842
|
+
// if the user stopped generation, we also abort consecutive actions
|
|
843
|
+
new Promise((resolve) => {
|
|
844
|
+
var _a;
|
|
845
|
+
if ((_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.aborted) {
|
|
846
|
+
resolve("Operation was aborted by the user");
|
|
847
|
+
}
|
|
848
|
+
})
|
|
849
|
+
]);
|
|
850
|
+
} catch (e) {
|
|
851
|
+
onError(e);
|
|
852
|
+
}
|
|
853
|
+
return new import_runtime_client_gql3.ResultMessage({
|
|
854
|
+
id: "result-" + message.id,
|
|
855
|
+
result: import_runtime_client_gql3.ResultMessage.encodeResult(
|
|
856
|
+
error ? {
|
|
857
|
+
content: result,
|
|
858
|
+
error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
|
|
859
|
+
} : result
|
|
860
|
+
),
|
|
861
|
+
actionExecutionId: message.id,
|
|
862
|
+
actionName: message.name
|
|
863
|
+
});
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
function getPairedFeAction(actions, message) {
|
|
867
|
+
let actionName = null;
|
|
868
|
+
if (message.isActionExecutionMessage()) {
|
|
869
|
+
actionName = message.name;
|
|
870
|
+
} else if (message.isResultMessage()) {
|
|
871
|
+
actionName = message.actionName;
|
|
872
|
+
}
|
|
873
|
+
return actions.find(
|
|
874
|
+
(action) => action.name === actionName && action.available === "frontend" || action.pairedAction === actionName
|
|
875
|
+
);
|
|
876
|
+
}
|
|
828
877
|
|
|
829
878
|
// src/components/copilot-provider/copilotkit.tsx
|
|
830
879
|
var import_react7 = require("react");
|
|
@@ -895,9 +944,9 @@ function useCopilotChat(_a = {}) {
|
|
|
895
944
|
const makeSystemMessageCallback = (0, import_react8.useCallback)(() => {
|
|
896
945
|
const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
|
|
897
946
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
898
|
-
return new
|
|
947
|
+
return new import_runtime_client_gql4.TextMessage({
|
|
899
948
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
900
|
-
role:
|
|
949
|
+
role: import_runtime_client_gql4.Role.System
|
|
901
950
|
});
|
|
902
951
|
}, [getContextString, makeSystemMessage, chatInstructions]);
|
|
903
952
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -1263,15 +1312,13 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1263
1312
|
|
|
1264
1313
|
// src/hooks/use-coagent.ts
|
|
1265
1314
|
var import_react13 = require("react");
|
|
1315
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1266
1316
|
function useCoAgent(options) {
|
|
1267
1317
|
const generalContext = useCopilotContext();
|
|
1268
1318
|
const { availableAgents } = generalContext;
|
|
1269
1319
|
const { addToast } = useToast();
|
|
1270
1320
|
const lastLoadedThreadId = (0, import_react13.useRef)();
|
|
1271
1321
|
const lastLoadedState = (0, import_react13.useRef)();
|
|
1272
|
-
const isExternalStateManagement = (options2) => {
|
|
1273
|
-
return "state" in options2 && "setState" in options2;
|
|
1274
|
-
};
|
|
1275
1322
|
const { name } = options;
|
|
1276
1323
|
(0, import_react13.useEffect)(() => {
|
|
1277
1324
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
@@ -1280,44 +1327,27 @@ function useCoAgent(options) {
|
|
|
1280
1327
|
addToast({ type: "warning", message });
|
|
1281
1328
|
}
|
|
1282
1329
|
}, [availableAgents]);
|
|
1283
|
-
const isInternalStateManagementWithInitial = (options2) => {
|
|
1284
|
-
return "initialState" in options2;
|
|
1285
|
-
};
|
|
1286
1330
|
const messagesContext = useCopilotMessagesContext();
|
|
1287
1331
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
1288
1332
|
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
|
|
1289
1333
|
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
1290
|
-
const getCoagentState = (coagentStates2, name2) => {
|
|
1291
|
-
var _a;
|
|
1292
|
-
if (coagentStates2[name2]) {
|
|
1293
|
-
return coagentStates2[name2];
|
|
1294
|
-
} else {
|
|
1295
|
-
return {
|
|
1296
|
-
name: name2,
|
|
1297
|
-
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
1298
|
-
configurable: (_a = options.configurable) != null ? _a : {},
|
|
1299
|
-
running: false,
|
|
1300
|
-
active: false,
|
|
1301
|
-
threadId: void 0,
|
|
1302
|
-
nodeName: void 0,
|
|
1303
|
-
runId: void 0
|
|
1304
|
-
};
|
|
1305
|
-
}
|
|
1306
|
-
};
|
|
1307
1334
|
const runtimeClient = useCopilotRuntimeClient({
|
|
1308
1335
|
url: copilotApiConfig.chatApiEndpoint,
|
|
1309
1336
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
1310
1337
|
credentials: copilotApiConfig.credentials
|
|
1311
1338
|
});
|
|
1312
|
-
const setState = (
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1339
|
+
const setState = (0, import_react13.useCallback)(
|
|
1340
|
+
(newState) => {
|
|
1341
|
+
let coagentState = getCoagentState({ coagentStates, name, options });
|
|
1342
|
+
const updatedState = typeof newState === "function" ? newState(coagentState.state) : newState;
|
|
1343
|
+
setCoagentStatesWithRef(__spreadProps(__spreadValues({}, coagentStatesRef.current), {
|
|
1344
|
+
[name]: __spreadProps(__spreadValues({}, coagentState), {
|
|
1345
|
+
state: updatedState
|
|
1346
|
+
})
|
|
1347
|
+
}));
|
|
1348
|
+
},
|
|
1349
|
+
[coagentStates, name]
|
|
1350
|
+
);
|
|
1321
1351
|
(0, import_react13.useEffect)(() => {
|
|
1322
1352
|
const fetchAgentState = () => __async(this, null, function* () {
|
|
1323
1353
|
var _a, _b, _c, _d;
|
|
@@ -1333,13 +1363,12 @@ function useCoAgent(options) {
|
|
|
1333
1363
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
1334
1364
|
lastLoadedState.current = newState;
|
|
1335
1365
|
lastLoadedThreadId.current = threadId;
|
|
1336
|
-
const fetchedState =
|
|
1366
|
+
const fetchedState = (0, import_shared6.parseJson)(newState, {});
|
|
1337
1367
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
1338
1368
|
}
|
|
1339
1369
|
});
|
|
1340
1370
|
void fetchAgentState();
|
|
1341
1371
|
}, [threadId]);
|
|
1342
|
-
const coagentState = getCoagentState(coagentStates, name);
|
|
1343
1372
|
(0, import_react13.useEffect)(() => {
|
|
1344
1373
|
if (isExternalStateManagement(options)) {
|
|
1345
1374
|
setState(options.state);
|
|
@@ -1357,17 +1386,20 @@ function useCoAgent(options) {
|
|
|
1357
1386
|
}),
|
|
1358
1387
|
[name, context, appendMessage, runChatCompletion]
|
|
1359
1388
|
);
|
|
1360
|
-
return {
|
|
1361
|
-
name,
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1389
|
+
return (0, import_react13.useMemo)(() => {
|
|
1390
|
+
const coagentState = getCoagentState({ coagentStates, name, options });
|
|
1391
|
+
return {
|
|
1392
|
+
name,
|
|
1393
|
+
nodeName: coagentState.nodeName,
|
|
1394
|
+
threadId: coagentState.threadId,
|
|
1395
|
+
running: coagentState.running,
|
|
1396
|
+
state: coagentState.state,
|
|
1397
|
+
setState: isExternalStateManagement(options) ? options.setState : setState,
|
|
1398
|
+
start: () => startAgent(name, context),
|
|
1399
|
+
stop: () => stopAgent(name, context),
|
|
1400
|
+
run: runAgentCallback
|
|
1401
|
+
};
|
|
1402
|
+
}, [name, coagentStates, options, setState, runAgentCallback]);
|
|
1371
1403
|
}
|
|
1372
1404
|
function startAgent(name, context) {
|
|
1373
1405
|
const { setAgentSession } = context;
|
|
@@ -1423,6 +1455,33 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
1423
1455
|
}
|
|
1424
1456
|
});
|
|
1425
1457
|
}
|
|
1458
|
+
var isExternalStateManagement = (options) => {
|
|
1459
|
+
return "state" in options && "setState" in options;
|
|
1460
|
+
};
|
|
1461
|
+
var isInternalStateManagementWithInitial = (options) => {
|
|
1462
|
+
return "initialState" in options;
|
|
1463
|
+
};
|
|
1464
|
+
var getCoagentState = ({
|
|
1465
|
+
coagentStates,
|
|
1466
|
+
name,
|
|
1467
|
+
options
|
|
1468
|
+
}) => {
|
|
1469
|
+
var _a;
|
|
1470
|
+
if (coagentStates[name]) {
|
|
1471
|
+
return coagentStates[name];
|
|
1472
|
+
} else {
|
|
1473
|
+
return {
|
|
1474
|
+
name,
|
|
1475
|
+
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
1476
|
+
configurable: (_a = options.configurable) != null ? _a : {},
|
|
1477
|
+
running: false,
|
|
1478
|
+
active: false,
|
|
1479
|
+
threadId: void 0,
|
|
1480
|
+
nodeName: void 0,
|
|
1481
|
+
runId: void 0
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1426
1485
|
|
|
1427
1486
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
1428
1487
|
var import_react14 = require("react");
|
|
@@ -1430,7 +1489,7 @@ var import_react15 = __toESM(require("react"));
|
|
|
1430
1489
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
1431
1490
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
1432
1491
|
const pendingActionRef = (0, import_react14.useRef)(null);
|
|
1433
|
-
const
|
|
1492
|
+
const executeAction2 = (0, import_react14.useCallback)(
|
|
1434
1493
|
(props) => {
|
|
1435
1494
|
if (typeof action.render === "function") {
|
|
1436
1495
|
return action.render(props);
|
|
@@ -1450,13 +1509,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
1450
1509
|
onSignInComplete: (authState) => {
|
|
1451
1510
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
1452
1511
|
if (pendingActionRef.current) {
|
|
1453
|
-
|
|
1512
|
+
executeAction2(pendingActionRef.current);
|
|
1454
1513
|
pendingActionRef.current = null;
|
|
1455
1514
|
}
|
|
1456
1515
|
}
|
|
1457
1516
|
}) : import_react15.default.createElement(import_react14.Fragment);
|
|
1458
1517
|
}
|
|
1459
|
-
return
|
|
1518
|
+
return executeAction2(props);
|
|
1460
1519
|
},
|
|
1461
1520
|
[action, authStates_c, setAuthStates_c]
|
|
1462
1521
|
);
|
|
@@ -1470,13 +1529,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
1470
1529
|
|
|
1471
1530
|
// src/hooks/use-langgraph-interrupt.ts
|
|
1472
1531
|
var import_react16 = require("react");
|
|
1473
|
-
var
|
|
1532
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1474
1533
|
function useLangGraphInterrupt(action, dependencies) {
|
|
1475
1534
|
var _a;
|
|
1476
1535
|
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react16.useContext)(CopilotContext);
|
|
1477
1536
|
const { runChatCompletion } = useCopilotChat();
|
|
1478
1537
|
const { addToast } = useToast();
|
|
1479
|
-
const actionId = (0,
|
|
1538
|
+
const actionId = (0, import_shared7.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
1480
1539
|
const hasAction = (0, import_react16.useMemo)(
|
|
1481
1540
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
1482
1541
|
[langGraphInterruptAction]
|
|
@@ -1492,10 +1551,9 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
1492
1551
|
}
|
|
1493
1552
|
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
1494
1553
|
(0, import_react16.useEffect)(() => {
|
|
1495
|
-
var _a2;
|
|
1496
1554
|
if (!action)
|
|
1497
1555
|
return;
|
|
1498
|
-
if (hasAction && !isCurrentAction && !
|
|
1556
|
+
if (hasAction && !isCurrentAction && !action.enabled) {
|
|
1499
1557
|
addToast({
|
|
1500
1558
|
type: "warning",
|
|
1501
1559
|
message: "An action is already registered for the interrupt event"
|
|
@@ -1518,12 +1576,11 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
1518
1576
|
|
|
1519
1577
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
1520
1578
|
var import_react17 = __toESM(require("react"));
|
|
1521
|
-
var import_shared7 = require("@copilotkit/shared");
|
|
1522
1579
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
1523
1580
|
return render({ event, result, resolve });
|
|
1524
1581
|
};
|
|
1525
1582
|
function useLangGraphInterruptRender() {
|
|
1526
|
-
const { langGraphInterruptAction, setLangGraphInterruptAction } = useCopilotContext();
|
|
1583
|
+
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
1527
1584
|
const responseRef = import_react17.default.useRef();
|
|
1528
1585
|
const resolveInterrupt = (0, import_react17.useCallback)(
|
|
1529
1586
|
(response) => {
|
|
@@ -1536,8 +1593,8 @@ function useLangGraphInterruptRender() {
|
|
|
1536
1593
|
);
|
|
1537
1594
|
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
1538
1595
|
return null;
|
|
1539
|
-
const { render, handler, event,
|
|
1540
|
-
const conditionsMet =
|
|
1596
|
+
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
1597
|
+
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
1541
1598
|
if (!conditionsMet) {
|
|
1542
1599
|
return null;
|
|
1543
1600
|
}
|