@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;" />
80 lines (78 loc) • 2.11 kB
JavaScript
import {
useRenderToolCall
} from "./chunk-NBK4KBLX.mjs";
import {
useFrontendTool
} from "./chunk-CDUIA2WM.mjs";
import {
useHumanInTheLoop
} from "./chunk-7DTB7S5V.mjs";
import {
__spreadProps,
__spreadValues
} from "./chunk-SKC7AJIV.mjs";
// src/hooks/use-copilot-action.ts
import { useState } from "react";
function getActionConfig(action) {
if (action.name === "*") {
return {
type: "render",
action
};
}
if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
let render = action.render;
if (!render && "renderAndWaitForResponse" in action) {
render = action.renderAndWaitForResponse;
}
if (!render && "renderAndWait" in action) {
render = action.renderAndWait;
}
return {
type: "hitl",
action: __spreadProps(__spreadValues({}, action), { render })
};
}
if ("available" in action) {
if (action.available === "enabled" || action.available === "remote") {
return {
type: "frontend",
action
};
}
if (action.available === "frontend" || action.available === "disabled") {
return {
type: "render",
action
};
}
}
if ("handler" in action) {
return {
type: "frontend",
action
};
}
throw new Error("Invalid action configuration");
}
function useCopilotAction(action, dependencies) {
const [initialActionConfig] = useState(getActionConfig(action));
const currentActionConfig = getActionConfig(action);
if (initialActionConfig.type !== currentActionConfig.type) {
throw new Error("Action configuration changed between renders");
}
switch (currentActionConfig.type) {
case "render":
return useRenderToolCall(currentActionConfig.action, dependencies);
case "hitl":
return useHumanInTheLoop(currentActionConfig.action, dependencies);
case "frontend":
return useFrontendTool(currentActionConfig.action, dependencies);
default:
throw new Error("Invalid action configuration");
}
}
export {
useCopilotAction
};
//# sourceMappingURL=chunk-GPEJNVE5.mjs.map