@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;" />
61 lines (60 loc) • 2.27 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/hooks/use-copilot-readable.ts
var use_copilot_readable_exports = {};
__export(use_copilot_readable_exports, {
useCopilotReadable: () => useCopilotReadable
});
module.exports = __toCommonJS(use_copilot_readable_exports);
var import_react = require("@copilotkitnext/react");
var import_react2 = require("react");
function useCopilotReadable({ description, value, convert, available }, dependencies) {
const { copilotkit } = (0, import_react.useCopilotKit)();
const ctxIdRef = (0, import_react2.useRef)(void 0);
(0, import_react2.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;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
useCopilotReadable
});
//# sourceMappingURL=use-copilot-readable.js.map