55 lines
2.8 KiB
TypeScript
55 lines
2.8 KiB
TypeScript
export type TVstarMessage = {
|
||
id: string;
|
||
role: "user" | "assistant";
|
||
content: string;
|
||
createdAt: number;
|
||
};
|
||
|
||
export function tvstarAllowsGeneration(instruction: string) {
|
||
const text = instruction.replace(/\s+/g, "");
|
||
return !/(?:只|仅)(?:做|要|进行|需要)?(?:分析|规划|出方案|写方案|写分镜|列步骤)|(?:不要|先不|暂不|无需|别|不)(?:提交|启动|运行|执行)(?:任何|所有)?(?:生成|制作|剪辑)?任务|(?:不要|先不|暂不|无需|别|不)(?:执行|运行|启动)(?:任何|所有)?(?:图片|视频|音频|媒体|成片|内容|、|和|或|及)*(?:生成|制作|剪辑)|(?:不要|先不|暂不|无需|别)(?:生成|制作|渲染|剪辑)(?:图片|视频|媒体|成片|内容)?|(?:不|不要)扣费|待运行|未运行/.test(text);
|
||
}
|
||
|
||
export function tvstarWantsDraftNodes(instruction: string) {
|
||
const text = instruction.replace(/\s+/g, "");
|
||
if (/(?:不要|无需|别|不)(?:创建|建立|搭建|添加)(?:任何|所有)?(?:画布|节点|工作流)/.test(text)) return false;
|
||
return /(?:创建|建立|搭建|添加|放入)/.test(text) && /(?:画布|节点|工作流)/.test(text);
|
||
}
|
||
|
||
export function tvstarRequestsRunExisting(instruction: string) {
|
||
const text = instruction.replace(/\s+/g, "");
|
||
return text.length <= 36 && tvstarAllowsGeneration(instruction) &&
|
||
!/(?:修改|改成|增加|删除|替换|换成|重做|重新|调整|优化|不要|先不)/.test(text) &&
|
||
/(?:开始|执行|运行|提交)(?:生成|制作|运行|执行|画布|分镜|工作流|节点|视频|成片|任务|这些|现有|吧|了|。|,)*$/.test(text);
|
||
}
|
||
|
||
type RevisionContext = {
|
||
goal: string;
|
||
plan?: { summary: string };
|
||
shots?: Array<{
|
||
shot: string;
|
||
duration: string;
|
||
sceneDescription: string;
|
||
cameraMovement: string;
|
||
}>;
|
||
messages?: TVstarMessage[];
|
||
};
|
||
|
||
export function buildTVstarRevisionPrompt(session: RevisionContext, instruction: string) {
|
||
const priorShots = (session.shots || []).map((shot) =>
|
||
`${shot.shot}(${shot.duration}):${shot.sceneDescription};运镜:${shot.cameraMovement}`,
|
||
);
|
||
const recentTurns = (session.messages || []).slice(-8).map((message) =>
|
||
`${message.role === "user" ? "用户" : "TVstar"}:${message.content.slice(0, 1200)}`,
|
||
);
|
||
return [
|
||
"这是同一个视频画布中的连续对话。请依据最新指令修改现有方案,不要把它当作全新项目。",
|
||
`最初目标:${session.goal}`,
|
||
session.plan?.summary ? `当前规划:${session.plan.summary}` : "",
|
||
priorShots.length ? `当前分镜:\n${priorShots.join("\n")}` : "",
|
||
recentTurns.length ? `最近对话:\n${recentTurns.join("\n")}` : "",
|
||
`最新用户指令:${instruction.trim()}`,
|
||
"如果最新指令没有要求修改的部分,请保持原有镜头、人物、风格、时长和画面比例。输出更新后的完整方案。",
|
||
].filter(Boolean).join("\n\n").slice(0, 16000);
|
||
}
|