19 lines
1.8 KiB
TypeScript
19 lines
1.8 KiB
TypeScript
import type { AgentRunSnapshot } from "./protocol";
|
|
import { finalResultNodeIds } from "./results";
|
|
|
|
/** Only a complete, single-purpose cutout may finish on file evidence alone. */
|
|
export function isCompletedSimpleCutout(snapshot: AgentRunSnapshot): boolean {
|
|
if (snapshot.workspace === "video") return false;
|
|
const request = [snapshot.objective, ...snapshot.inputs.map(input => input.text)].join("\n");
|
|
if (!/抠图|抠出|扣出|去背|去(?:掉|除)?背景|移除背景|删除背景|remove\s+(?:the\s+)?background/i.test(request)) return false;
|
|
if (/生成|换背景|更换背景|改.{0,8}(?:颜色|色彩|蓝|绿|红)|变.{0,5}色|排版|拼图|增强|修复|裁剪|尺寸|比例|下载|导出|检查|分析|对比|边缘|白边|毛边|光晕|发丝|锯齿|精细|generate|resize|export|inspect|enhance/i.test(request)) return false;
|
|
if (!snapshot.calls.length || snapshot.calls.some(call => call.status !== "succeeded" || call.uncertain || call.rejected)) return false;
|
|
if (snapshot.calls.some(call => !["planCanvasTask", "readCanvas", "removeBackground", "analyzeCanvasImages", "listCanvasCapabilities"].includes(call.name))) return false;
|
|
const writes = snapshot.calls.filter(call => call.name === "removeBackground");
|
|
if (!writes.length || writes.some(call => call.output?.status !== "succeeded" || !Array.isArray(call.output.createdNodeIds) || !call.output.createdNodeIds.length)) return false;
|
|
const plan = snapshot.calls.filter(call => call.name === "planCanvasTask").at(-1)?.output;
|
|
const count = snapshot.requirements?.expectedImageCount ?? plan?.expectedImageCount;
|
|
const ids = finalResultNodeIds(snapshot);
|
|
return typeof count === "number" && count > 0 && ids.length === count && ids.every(id => writes.some(call => (call.output!.createdNodeIds as unknown[]).includes(id)));
|
|
}
|