@copilotkit/react-core 1.52.0-next.6 → 1.52.0-next.8
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 +21 -0
- package/dist/index.cjs +88 -133
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +90 -134
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +90 -135
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -5
- package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +2 -4
- package/src/hooks/index.ts +0 -1
- package/src/hooks/use-copilot-chat_internal.ts +14 -3
- package/src/hooks/use-langgraph-interrupt.ts +97 -38
- package/src/hooks/use-langgraph-interrupt-render.ts +0 -147
package/dist/index.umd.js
CHANGED
|
@@ -2054,120 +2054,6 @@ react_markdown = __toESM(react_markdown);
|
|
|
2054
2054
|
if (cloudFeatures.length > 0 && !hasApiKey) throw new _copilotkit_shared.MissingPublicApiKeyError(`Missing required prop: 'publicApiKey' or 'publicLicenseKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`);
|
|
2055
2055
|
}
|
|
2056
2056
|
|
|
2057
|
-
//#endregion
|
|
2058
|
-
//#region src/hooks/use-agent-nodename.ts
|
|
2059
|
-
function useAgentNodeName(agentName) {
|
|
2060
|
-
const { agent } = (0, _copilotkitnext_react.useAgent)({ agentId: agentName });
|
|
2061
|
-
const nodeNameRef = (0, react.useRef)("start");
|
|
2062
|
-
(0, react.useEffect)(() => {
|
|
2063
|
-
if (!agent) return;
|
|
2064
|
-
const subscription = agent.subscribe({
|
|
2065
|
-
onStepStartedEvent: ({ event }) => {
|
|
2066
|
-
nodeNameRef.current = event.stepName;
|
|
2067
|
-
},
|
|
2068
|
-
onRunStartedEvent: () => {
|
|
2069
|
-
nodeNameRef.current = "start";
|
|
2070
|
-
},
|
|
2071
|
-
onRunFinishedEvent: () => {
|
|
2072
|
-
nodeNameRef.current = "end";
|
|
2073
|
-
}
|
|
2074
|
-
});
|
|
2075
|
-
return () => {
|
|
2076
|
-
subscription.unsubscribe();
|
|
2077
|
-
};
|
|
2078
|
-
}, [agent]);
|
|
2079
|
-
return nodeNameRef.current;
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
|
-
//#endregion
|
|
2083
|
-
//#region src/hooks/use-langgraph-interrupt-render.ts
|
|
2084
|
-
const InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
2085
|
-
return render({
|
|
2086
|
-
event,
|
|
2087
|
-
result,
|
|
2088
|
-
resolve
|
|
2089
|
-
});
|
|
2090
|
-
};
|
|
2091
|
-
function useLangGraphInterruptRender(agent) {
|
|
2092
|
-
var _existingConfig$agent;
|
|
2093
|
-
const { interruptActions, agentSession, threadId, interruptEventQueue, addInterruptEvent, resolveInterruptEvent } = useCopilotContext();
|
|
2094
|
-
const existingConfig = (0, _copilotkitnext_react.useCopilotChatConfiguration)();
|
|
2095
|
-
const nodeName = useAgentNodeName((_existingConfig$agent = existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.agentId) !== null && _existingConfig$agent !== void 0 ? _existingConfig$agent : "default");
|
|
2096
|
-
(0, react.useEffect)(() => {
|
|
2097
|
-
if (!agent) return;
|
|
2098
|
-
let localInterrupt = null;
|
|
2099
|
-
const { unsubscribe } = agent.subscribe({
|
|
2100
|
-
onCustomEvent: ({ event }) => {
|
|
2101
|
-
if (event.name === "on_interrupt") {
|
|
2102
|
-
const eventData = {
|
|
2103
|
-
name: _copilotkit_runtime_client_gql.MetaEventName.LangGraphInterruptEvent,
|
|
2104
|
-
type: event.type,
|
|
2105
|
-
value: (0, _copilotkit_shared.parseJson)(event.value, event.value)
|
|
2106
|
-
};
|
|
2107
|
-
localInterrupt = {
|
|
2108
|
-
eventId: (0, _copilotkit_shared.dataToUUID)(eventData, "interruptEvents"),
|
|
2109
|
-
threadId,
|
|
2110
|
-
event: eventData
|
|
2111
|
-
};
|
|
2112
|
-
}
|
|
2113
|
-
},
|
|
2114
|
-
onRunStartedEvent: () => {
|
|
2115
|
-
localInterrupt = null;
|
|
2116
|
-
},
|
|
2117
|
-
onRunFinalized: () => {
|
|
2118
|
-
if (localInterrupt) {
|
|
2119
|
-
addInterruptEvent(localInterrupt);
|
|
2120
|
-
localInterrupt = null;
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
});
|
|
2124
|
-
return () => {
|
|
2125
|
-
unsubscribe();
|
|
2126
|
-
};
|
|
2127
|
-
}, [agent, threadId]);
|
|
2128
|
-
const handleResolve = (0, react.useCallback)((eventId, response) => {
|
|
2129
|
-
agent === null || agent === void 0 || agent.runAgent({ forwardedProps: { command: { resume: response } } });
|
|
2130
|
-
resolveInterruptEvent(threadId, eventId, response !== null && response !== void 0 ? response : "");
|
|
2131
|
-
}, [agent, threadId]);
|
|
2132
|
-
return (0, react.useMemo)(() => {
|
|
2133
|
-
const currentQueuedEvent = (interruptEventQueue[threadId] || []).find((qe) => !qe.event.response);
|
|
2134
|
-
if (!currentQueuedEvent || !agentSession) return null;
|
|
2135
|
-
const matchingAction = Object.values(interruptActions).find((action) => {
|
|
2136
|
-
if (!action.enabled) return true;
|
|
2137
|
-
return action.enabled({
|
|
2138
|
-
eventValue: currentQueuedEvent.event.value,
|
|
2139
|
-
agentMetadata: {
|
|
2140
|
-
...agentSession,
|
|
2141
|
-
nodeName
|
|
2142
|
-
}
|
|
2143
|
-
});
|
|
2144
|
-
});
|
|
2145
|
-
if (!matchingAction) return null;
|
|
2146
|
-
const { render, handler } = matchingAction;
|
|
2147
|
-
const resolveInterrupt = (response) => {
|
|
2148
|
-
handleResolve(currentQueuedEvent.eventId, response);
|
|
2149
|
-
};
|
|
2150
|
-
let result = null;
|
|
2151
|
-
if (handler) result = handler({
|
|
2152
|
-
event: currentQueuedEvent.event,
|
|
2153
|
-
resolve: resolveInterrupt
|
|
2154
|
-
});
|
|
2155
|
-
if (!render) return null;
|
|
2156
|
-
return react.default.createElement(InterruptRenderer, {
|
|
2157
|
-
event: currentQueuedEvent.event,
|
|
2158
|
-
result,
|
|
2159
|
-
render,
|
|
2160
|
-
resolve: resolveInterrupt
|
|
2161
|
-
});
|
|
2162
|
-
}, [
|
|
2163
|
-
interruptActions,
|
|
2164
|
-
interruptEventQueue,
|
|
2165
|
-
threadId,
|
|
2166
|
-
agentSession,
|
|
2167
|
-
handleResolve
|
|
2168
|
-
]);
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
2057
|
//#endregion
|
|
2172
2058
|
//#region src/hooks/use-lazy-tool-renderer.tsx
|
|
2173
2059
|
function useLazyToolRenderer() {
|
|
@@ -2219,7 +2105,14 @@ react_markdown = __toESM(react_markdown);
|
|
|
2219
2105
|
(0, react.useEffect)(() => {
|
|
2220
2106
|
onInProgress === null || onInProgress === void 0 || onInProgress(Boolean(agent === null || agent === void 0 ? void 0 : agent.isRunning));
|
|
2221
2107
|
}, [agent === null || agent === void 0 ? void 0 : agent.isRunning, onInProgress]);
|
|
2222
|
-
const interrupt =
|
|
2108
|
+
const [interrupt, setInterrupt] = (0, react.useState)(null);
|
|
2109
|
+
(0, react.useEffect)(() => {
|
|
2110
|
+
setInterrupt(copilotkit.interruptElement);
|
|
2111
|
+
const subscription = copilotkit.subscribe({ onInterruptElementChanged: ({ interruptElement }) => {
|
|
2112
|
+
setInterrupt(interruptElement);
|
|
2113
|
+
} });
|
|
2114
|
+
return () => subscription.unsubscribe();
|
|
2115
|
+
}, [copilotkit]);
|
|
2223
2116
|
const reset = () => {
|
|
2224
2117
|
agent === null || agent === void 0 || agent.setMessages([]);
|
|
2225
2118
|
agent === null || agent === void 0 || agent.setState(null);
|
|
@@ -3366,6 +3259,31 @@ react_markdown = __toESM(react_markdown);
|
|
|
3366
3259
|
return ctxIdRef.current;
|
|
3367
3260
|
}
|
|
3368
3261
|
|
|
3262
|
+
//#endregion
|
|
3263
|
+
//#region src/hooks/use-agent-nodename.ts
|
|
3264
|
+
function useAgentNodeName(agentName) {
|
|
3265
|
+
const { agent } = (0, _copilotkitnext_react.useAgent)({ agentId: agentName });
|
|
3266
|
+
const nodeNameRef = (0, react.useRef)("start");
|
|
3267
|
+
(0, react.useEffect)(() => {
|
|
3268
|
+
if (!agent) return;
|
|
3269
|
+
const subscription = agent.subscribe({
|
|
3270
|
+
onStepStartedEvent: ({ event }) => {
|
|
3271
|
+
nodeNameRef.current = event.stepName;
|
|
3272
|
+
},
|
|
3273
|
+
onRunStartedEvent: () => {
|
|
3274
|
+
nodeNameRef.current = "start";
|
|
3275
|
+
},
|
|
3276
|
+
onRunFinishedEvent: () => {
|
|
3277
|
+
nodeNameRef.current = "end";
|
|
3278
|
+
}
|
|
3279
|
+
});
|
|
3280
|
+
return () => {
|
|
3281
|
+
subscription.unsubscribe();
|
|
3282
|
+
};
|
|
3283
|
+
}, [agent]);
|
|
3284
|
+
return nodeNameRef.current;
|
|
3285
|
+
}
|
|
3286
|
+
|
|
3369
3287
|
//#endregion
|
|
3370
3288
|
//#region src/hooks/use-coagent.ts
|
|
3371
3289
|
/**
|
|
@@ -3727,26 +3645,64 @@ react_markdown = __toESM(react_markdown);
|
|
|
3727
3645
|
|
|
3728
3646
|
//#endregion
|
|
3729
3647
|
//#region src/hooks/use-langgraph-interrupt.ts
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3648
|
+
/**
|
|
3649
|
+
* Transforms a v2 InterruptEvent into the v1 LangGraphInterruptEvent shape
|
|
3650
|
+
* expected by existing useLangGraphInterrupt callbacks.
|
|
3651
|
+
*/
|
|
3652
|
+
function toV1Event(event) {
|
|
3653
|
+
const value = typeof event.value === "string" ? (0, _copilotkit_shared.parseJson)(event.value, event.value) : event.value;
|
|
3654
|
+
return {
|
|
3655
|
+
name: _copilotkit_runtime_client_gql.MetaEventName.LangGraphInterruptEvent,
|
|
3656
|
+
type: "MetaEvent",
|
|
3657
|
+
value
|
|
3658
|
+
};
|
|
3659
|
+
}
|
|
3660
|
+
function useLangGraphInterrupt(action, _dependencies) {
|
|
3661
|
+
var _existingConfig$agent;
|
|
3662
|
+
const actionRef = (0, react.useRef)(action);
|
|
3663
|
+
actionRef.current = action;
|
|
3664
|
+
const existingConfig = (0, _copilotkitnext_react.useCopilotChatConfiguration)();
|
|
3665
|
+
const resolvedAgentId = (_existingConfig$agent = existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.agentId) !== null && _existingConfig$agent !== void 0 ? _existingConfig$agent : "default";
|
|
3666
|
+
const threadId = existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.threadId;
|
|
3667
|
+
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
3668
|
+
const metadataRef = (0, react.useRef)({
|
|
3669
|
+
agentName: resolvedAgentId,
|
|
3746
3670
|
threadId,
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3671
|
+
nodeName
|
|
3672
|
+
});
|
|
3673
|
+
metadataRef.current = {
|
|
3674
|
+
agentName: resolvedAgentId,
|
|
3675
|
+
threadId,
|
|
3676
|
+
nodeName
|
|
3677
|
+
};
|
|
3678
|
+
(0, _copilotkitnext_react.useInterrupt)({
|
|
3679
|
+
render: (0, react.useCallback)(({ event, result, resolve }) => {
|
|
3680
|
+
const renderFn = actionRef.current.render;
|
|
3681
|
+
if (!renderFn) return react.default.createElement(react.default.Fragment);
|
|
3682
|
+
const rendered = renderFn({
|
|
3683
|
+
event: toV1Event(event),
|
|
3684
|
+
result,
|
|
3685
|
+
resolve: (r) => resolve(r)
|
|
3686
|
+
});
|
|
3687
|
+
if (typeof rendered === "string") return react.default.createElement(react.default.Fragment, null, rendered);
|
|
3688
|
+
return rendered;
|
|
3689
|
+
}, []),
|
|
3690
|
+
handler: (0, react.useCallback)(({ event, resolve }) => {
|
|
3691
|
+
var _actionRef$current$ha, _actionRef$current;
|
|
3692
|
+
return (_actionRef$current$ha = (_actionRef$current = actionRef.current).handler) === null || _actionRef$current$ha === void 0 ? void 0 : _actionRef$current$ha.call(_actionRef$current, {
|
|
3693
|
+
event: toV1Event(event),
|
|
3694
|
+
resolve: (r) => resolve(r)
|
|
3695
|
+
});
|
|
3696
|
+
}, []),
|
|
3697
|
+
enabled: (0, react.useCallback)((event) => {
|
|
3698
|
+
if (!actionRef.current.enabled) return true;
|
|
3699
|
+
return actionRef.current.enabled({
|
|
3700
|
+
eventValue: toV1Event(event).value,
|
|
3701
|
+
agentMetadata: metadataRef.current
|
|
3702
|
+
});
|
|
3703
|
+
}, []),
|
|
3704
|
+
agentId: resolvedAgentId
|
|
3705
|
+
});
|
|
3750
3706
|
}
|
|
3751
3707
|
|
|
3752
3708
|
//#endregion
|
|
@@ -4066,7 +4022,6 @@ exports.useDefaultTool = useDefaultTool;
|
|
|
4066
4022
|
exports.useFrontendTool = useFrontendTool;
|
|
4067
4023
|
exports.useHumanInTheLoop = useHumanInTheLoop;
|
|
4068
4024
|
exports.useLangGraphInterrupt = useLangGraphInterrupt;
|
|
4069
|
-
exports.useLangGraphInterruptRender = useLangGraphInterruptRender;
|
|
4070
4025
|
exports.useLazyToolRenderer = useLazyToolRenderer;
|
|
4071
4026
|
exports.useMakeCopilotDocumentReadable = useMakeCopilotDocumentReadable;
|
|
4072
4027
|
exports.useRenderToolCall = useRenderToolCall;
|