@copilotkit/react-core 1.82.0 → 1.84.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/dist/{MarkdownSurfaces-DGpjmPaB.mjs → MarkdownSurfaces-DV9P0Gi9.mjs} +55 -13
- package/dist/MarkdownSurfaces-DV9P0Gi9.mjs.map +1 -0
- package/dist/{MarkdownSurfaces-FF5za2kU.cjs → MarkdownSurfaces-IUaWSJ0E.cjs} +54 -12
- package/dist/MarkdownSurfaces-IUaWSJ0E.cjs.map +1 -0
- package/dist/{copilotkit-CVvbU9lV.cjs → copilotkit-BOTf5RHF.cjs} +296 -291
- package/dist/copilotkit-BOTf5RHF.cjs.map +1 -0
- package/dist/{copilotkit-wqaNanhw.d.cts → copilotkit-C3mvJexb.d.cts} +31 -8
- package/dist/copilotkit-C3mvJexb.d.cts.map +1 -0
- package/dist/{copilotkit-DDReN1Px.mjs → copilotkit-CKnD8GeM.mjs} +300 -295
- package/dist/copilotkit-CKnD8GeM.mjs.map +1 -0
- package/dist/{copilotkit-C765tOUi.d.mts → copilotkit-CnYo662V.d.mts} +31 -8
- package/dist/copilotkit-CnYo662V.d.mts.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.umd.js +199 -289
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/generative-ui.cjs +33 -54
- package/dist/v2/generative-ui.cjs.map +1 -1
- package/dist/v2/generative-ui.d.cts +118 -118
- package/dist/v2/generative-ui.d.mts +118 -118
- package/dist/v2/generative-ui.mjs +33 -54
- package/dist/v2/generative-ui.mjs.map +1 -1
- package/dist/v2/headless.cjs +32 -16
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +2 -0
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +2 -0
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +33 -17
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +14 -2
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +3 -3
- package/dist/v2/index.umd.js +359 -300
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +8 -8
- package/dist/MarkdownSurfaces-DGpjmPaB.mjs.map +0 -1
- package/dist/MarkdownSurfaces-FF5za2kU.cjs.map +0 -1
- package/dist/copilotkit-C765tOUi.d.mts.map +0 -1
- package/dist/copilotkit-CVvbU9lV.cjs.map +0 -1
- package/dist/copilotkit-DDReN1Px.mjs.map +0 -1
- package/dist/copilotkit-wqaNanhw.d.cts.map +0 -1
package/dist/v2/headless.cjs
CHANGED
|
@@ -112,6 +112,7 @@ const CopilotChatDefaultLabels = {
|
|
|
112
112
|
chatToggleOpenLabel: "Open chat",
|
|
113
113
|
chatToggleCloseLabel: "Close chat",
|
|
114
114
|
chatScrollToBottomLabel: "Scroll to bottom",
|
|
115
|
+
chatConnectingLabel: "Loading conversation",
|
|
115
116
|
modalHeaderTitle: "CopilotKit Chat",
|
|
116
117
|
welcomeMessageText: "How can I help you today?",
|
|
117
118
|
reasoningMessageThinkingLabel: "Thinking…",
|
|
@@ -951,6 +952,7 @@ const INTERRUPT_EVENT_NAME = "on_interrupt";
|
|
|
951
952
|
|
|
952
953
|
//#endregion
|
|
953
954
|
//#region src/v2/hooks/use-interrupt.tsx
|
|
955
|
+
/** Recognize thenables returned by interrupt preprocessing handlers. */
|
|
954
956
|
function isPromiseLike(value) {
|
|
955
957
|
return (typeof value === "object" || typeof value === "function") && value !== null && typeof Reflect.get(value, "then") === "function";
|
|
956
958
|
}
|
|
@@ -1001,7 +1003,6 @@ function useInterrupt(config) {
|
|
|
1001
1003
|
const [handlerResult, setHandlerResult] = (0, react.useState)(null);
|
|
1002
1004
|
const interruptStateRef = (0, react.useRef)(new _copilotkit_core.ɵInterruptState());
|
|
1003
1005
|
(0, react.useEffect)(() => {
|
|
1004
|
-
const interruptState = interruptStateRef.current;
|
|
1005
1006
|
let localLegacy = null;
|
|
1006
1007
|
let localStandard = null;
|
|
1007
1008
|
const subscription = agent.subscribe({
|
|
@@ -1014,19 +1015,21 @@ function useInterrupt(config) {
|
|
|
1014
1015
|
onRunFinishedEvent: (params) => {
|
|
1015
1016
|
if (params.outcome === "interrupt") localStandard = params.interrupts;
|
|
1016
1017
|
},
|
|
1017
|
-
onRunStartedEvent: () => {
|
|
1018
|
+
onRunStartedEvent: (params) => {
|
|
1019
|
+
if (!agent.pendingInterrupts?.length || params?.input?.resume !== void 0) (0, _copilotkit_core.ɵclearAgentInterruptState)(agent);
|
|
1018
1020
|
localLegacy = null;
|
|
1019
1021
|
localStandard = null;
|
|
1020
|
-
|
|
1022
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1021
1023
|
setPending(null);
|
|
1022
1024
|
},
|
|
1023
1025
|
onRunFinalized: () => {
|
|
1024
1026
|
if (localStandard && localStandard.length > 0) {
|
|
1025
|
-
|
|
1026
|
-
setPending(
|
|
1027
|
+
interruptStateRef.current = (0, _copilotkit_core.ɵgetAgentInterruptState)(agent, localStandard);
|
|
1028
|
+
setPending(interruptStateRef.current.pending);
|
|
1027
1029
|
} else if (localLegacy) {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1031
|
+
interruptStateRef.current.setLegacy(localLegacy);
|
|
1032
|
+
setPending(interruptStateRef.current.pending);
|
|
1030
1033
|
}
|
|
1031
1034
|
localLegacy = null;
|
|
1032
1035
|
localStandard = null;
|
|
@@ -1034,20 +1037,27 @@ function useInterrupt(config) {
|
|
|
1034
1037
|
onRunFailed: () => {
|
|
1035
1038
|
localLegacy = null;
|
|
1036
1039
|
localStandard = null;
|
|
1037
|
-
|
|
1040
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1038
1041
|
setPending(null);
|
|
1039
1042
|
}
|
|
1040
1043
|
});
|
|
1044
|
+
interruptStateRef.current = agent.pendingInterrupts?.length ? (0, _copilotkit_core.ɵgetAgentInterruptState)(agent) : new _copilotkit_core.ɵInterruptState();
|
|
1045
|
+
setPending(interruptStateRef.current.pending);
|
|
1041
1046
|
return () => {
|
|
1042
1047
|
subscription.unsubscribe();
|
|
1043
|
-
|
|
1048
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1044
1049
|
};
|
|
1045
1050
|
}, [agent]);
|
|
1051
|
+
/** Record an explicit answer and resume once the complete batch is addressed. */
|
|
1046
1052
|
const resolve = (0, react.useCallback)(async (payload, interruptId) => {
|
|
1047
1053
|
const current = pendingRef.current;
|
|
1048
1054
|
if (!current) return;
|
|
1049
1055
|
if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
|
|
1050
|
-
|
|
1056
|
+
if (interruptStateRef.current.isCompletedToolCall(interruptId, agent.messages)) {
|
|
1057
|
+
console.warn("[CopilotKit] useInterrupt: ignoring an answer for an already completed frontend tool call.");
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
const decision = interruptStateRef.current.resolve(payload, interruptId, agent.messages);
|
|
1051
1061
|
if (decision.kind === "legacy-resume") try {
|
|
1052
1062
|
return await copilotkit.runAgent({
|
|
1053
1063
|
agent,
|
|
@@ -1063,7 +1073,7 @@ function useInterrupt(config) {
|
|
|
1063
1073
|
}
|
|
1064
1074
|
if (decision.kind === "expired") {
|
|
1065
1075
|
console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
|
|
1066
|
-
interruptStateRef.current
|
|
1076
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1067
1077
|
setPending(null);
|
|
1068
1078
|
return;
|
|
1069
1079
|
}
|
|
@@ -1081,25 +1091,30 @@ function useInterrupt(config) {
|
|
|
1081
1091
|
});
|
|
1082
1092
|
} catch (err) {
|
|
1083
1093
|
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
1084
|
-
interruptStateRef.current
|
|
1094
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1085
1095
|
setPending(null);
|
|
1086
1096
|
throw err;
|
|
1087
1097
|
}
|
|
1088
1098
|
}, [agent, copilotkit]);
|
|
1099
|
+
/** Cancel a standard interrupt or dismiss a legacy interrupt locally. */
|
|
1089
1100
|
const cancel = (0, react.useCallback)(async (interruptId) => {
|
|
1090
1101
|
const current = pendingRef.current;
|
|
1091
1102
|
if (!current) return;
|
|
1092
1103
|
if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
|
|
1093
|
-
|
|
1104
|
+
if (interruptStateRef.current.isCompletedToolCall(interruptId, agent.messages)) {
|
|
1105
|
+
console.warn("[CopilotKit] useInterrupt: ignoring an answer for an already completed frontend tool call.");
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
const decision = interruptStateRef.current.cancel(interruptId, agent.messages);
|
|
1094
1109
|
if (decision.kind === "dismiss") {
|
|
1095
1110
|
console.warn("[CopilotKit] useInterrupt: cancel() is not supported for legacy on_interrupt interrupts; dismissing.");
|
|
1096
|
-
interruptStateRef.current
|
|
1111
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1097
1112
|
setPending(null);
|
|
1098
1113
|
return;
|
|
1099
1114
|
}
|
|
1100
1115
|
if (decision.kind === "expired") {
|
|
1101
1116
|
console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
|
|
1102
|
-
interruptStateRef.current
|
|
1117
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1103
1118
|
setPending(null);
|
|
1104
1119
|
return;
|
|
1105
1120
|
}
|
|
@@ -1117,7 +1132,7 @@ function useInterrupt(config) {
|
|
|
1117
1132
|
});
|
|
1118
1133
|
} catch (err) {
|
|
1119
1134
|
console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
|
|
1120
|
-
interruptStateRef.current
|
|
1135
|
+
interruptStateRef.current = new _copilotkit_core.ɵInterruptState();
|
|
1121
1136
|
setPending(null);
|
|
1122
1137
|
throw err;
|
|
1123
1138
|
}
|
|
@@ -1132,6 +1147,7 @@ function useInterrupt(config) {
|
|
|
1132
1147
|
resolveRef.current = resolve;
|
|
1133
1148
|
const cancelRef = (0, react.useRef)(cancel);
|
|
1134
1149
|
cancelRef.current = cancel;
|
|
1150
|
+
/** Evaluate the consumer filter, logging failures and disabling their UI. */
|
|
1135
1151
|
const isEnabled = (event) => {
|
|
1136
1152
|
const predicate = enabledRef.current;
|
|
1137
1153
|
if (!predicate) return true;
|