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;" />

37 lines (30 loc) 1.3 kB
import { useContext, useEffect, useMemo } from "react"; import { CopilotContext } from "../context/copilot-context"; import { LangGraphInterruptRender } from "../types/interrupt-action"; import { useToast } from "../components/toast/toast-provider"; import { dataToUUID } from "@copilotkit/shared"; export function useLangGraphInterrupt<TEventValue = any>( action: Omit<LangGraphInterruptRender<TEventValue>, "id">, dependencies?: any[], ) { const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = useContext(CopilotContext); const { addToast } = useToast(); const actionId = dataToUUID(action, "lgAction"); useEffect(() => { if (!action) return; // if (!action.enabled) { // TODO: if there are any other actions registered, we need to warn the user that a current action without "enabled" might render for everything // addToast({ // type: "warning", // message: "An action is already registered for the interrupt event", // }); // return; // } setInterruptAction({ ...action, id: actionId }); // Cleanup: remove action on unmount return () => { removeInterruptAction(actionId); }; }, [setInterruptAction, removeInterruptAction, threadId, actionId, ...(dependencies || [])]); }