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 (36 loc) 1.14 kB
// src/hooks/use-copilot-readable.ts import { useCopilotKit } from "@copilotkitnext/react"; import { useEffect, useRef } from "react"; function useCopilotReadable({ description, value, convert, available }, dependencies) { const { copilotkit } = useCopilotKit(); const ctxIdRef = useRef(void 0); useEffect(() => { if (!copilotkit) return; const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => { return JSON.stringify({ description, value }) == JSON.stringify(ctxItem); }); if (found) { ctxIdRef.current = found[0]; if (available === "disabled") copilotkit.removeContext(ctxIdRef.current); return; } if (!found && available === "disabled") return; ctxIdRef.current = copilotkit.addContext({ description, value: (convert != null ? convert : JSON.stringify)(value) }); return () => { if (!ctxIdRef.current) return; copilotkit.removeContext(ctxIdRef.current); }; }, [description, value, convert]); return ctxIdRef.current; } export { useCopilotReadable }; //# sourceMappingURL=chunk-Z6JV2LRY.mjs.map