UNPKG

@copilotkit/react-core

Version:

<div align="center"> <a href="https://copilotkit.ai" target="_blank"> <img src="https://github.com/copilotkit/copilotkit/raw/main/assets/banner.png" alt="CopilotKit Logo"> </a>

47 lines (45 loc) 1.38 kB
import { useCopilotContext } from "./chunk-PTSWFERP.mjs"; // src/hooks/use-langgraph-interrupt-render.ts import React, { useCallback } from "react"; var InterruptRenderer = ({ event, result, render, resolve }) => { return render({ event, result, resolve }); }; function useLangGraphInterruptRender() { const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext(); const responseRef = React.useRef(); const resolveInterrupt = useCallback( (response) => { responseRef.current = response; setTimeout(() => { setLangGraphInterruptAction({ event: { response } }); }, 0); }, [setLangGraphInterruptAction] ); if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render) return null; const { render, handler, event, enabled } = langGraphInterruptAction; const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession }); if (!conditionsMet) { return null; } let result = null; if (handler) { result = handler({ event, resolve: resolveInterrupt }); } return React.createElement(InterruptRenderer, { event, result, render, resolve: resolveInterrupt }); } export { useLangGraphInterruptRender }; //# sourceMappingURL=chunk-7XNZHQWJ.mjs.map