30 lines
742 B
JavaScript
30 lines
742 B
JavaScript
import { useCopilotKit } from "../providers/CopilotKitProvider.mjs";
|
|
import { useLayoutEffect, useMemo } from "react";
|
|
|
|
//#region src/hooks/use-agent-context.tsx
|
|
function useAgentContext(context) {
|
|
const { description, value } = context;
|
|
const { copilotkit } = useCopilotKit();
|
|
const stringValue = useMemo(() => {
|
|
if (typeof value === "string") return value;
|
|
return JSON.stringify(value);
|
|
}, [value]);
|
|
useLayoutEffect(() => {
|
|
if (!copilotkit) return;
|
|
const id = copilotkit.addContext({
|
|
description,
|
|
value: stringValue
|
|
});
|
|
return () => {
|
|
copilotkit.removeContext(id);
|
|
};
|
|
}, [
|
|
description,
|
|
stringValue,
|
|
copilotkit
|
|
]);
|
|
}
|
|
|
|
//#endregion
|
|
export { useAgentContext };
|
|
//# sourceMappingURL=use-agent-context.mjs.map
|