45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import type { CanvasCapabilityClientCommand } from "@/lib/canvas/capabilities/client-command";
|
|
import type { CanvasCapabilityDefinition } from "@/lib/canvas/capabilities/types";
|
|
|
|
function hasCompleteRect(args: Record<string, unknown>) {
|
|
return [args.x, args.y, args.width, args.height].every((value) =>
|
|
Number.isFinite(Number(value))
|
|
);
|
|
}
|
|
|
|
export function shouldExecuteCanvasCapabilityHeadlessly(params: {
|
|
capability: CanvasCapabilityDefinition;
|
|
command: CanvasCapabilityClientCommand;
|
|
}) {
|
|
const { capability, command } = params;
|
|
if (capability.executionMode === "headless") return true;
|
|
if (capability.executionMode === "interactive" || capability.executionMode === "local") {
|
|
return false;
|
|
}
|
|
|
|
switch (capability.id) {
|
|
case "image.ai_wash":
|
|
case "image.prompt_regenerate":
|
|
return Boolean(String(command.args.prompt || "").trim());
|
|
case "image.box_cutout":
|
|
return hasCompleteRect(command.args);
|
|
case "image.resize":
|
|
return (
|
|
Number.isFinite(Number(command.args.width)) &&
|
|
Number.isFinite(Number(command.args.height))
|
|
);
|
|
case "image.multi_angle":
|
|
case "image.generate_3d_model":
|
|
case "image.generate_3d_world":
|
|
return command.source === "agent" || command.source === "mcp";
|
|
case "image.rename":
|
|
return Boolean(String(command.args.title || "").trim());
|
|
case "image.note":
|
|
return Boolean(String(command.args.text || "").trim());
|
|
case "image.delete":
|
|
return command.confirmed === true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|