UNPKG

@copilotkit/react-core

Version:

<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />

47 lines (45 loc) 1.38 kB
import { useCopilotContext } from "./chunk-YHT6CWIY.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-QF3Q5LUN.mjs.map