111 lines
3.3 KiB
TypeScript
111 lines
3.3 KiB
TypeScript
import "server-only";
|
|
|
|
import { executeConfirmedStoryboardTask } from "@/lib/video-agent/execute-storyboard-task";
|
|
import {
|
|
reviseStoryboardTaskByCommand,
|
|
resolveStoryboardRevisionCommand,
|
|
} from "@/lib/video-agent/revise-storyboard-task";
|
|
import { getVideoStoryboardTaskDetail } from "@/lib/video-agent/task-store";
|
|
import type { StoryboardProgressEvent } from "@/lib/video-agent/types";
|
|
|
|
export async function handleStoryboardWorkflowFollowup(params: {
|
|
action: "revision_requested" | "cancel_requested";
|
|
workflowId?: string;
|
|
text: string;
|
|
friendlyMessage?: string;
|
|
onProgress?: (event: StoryboardProgressEvent) => void | Promise<void>;
|
|
}) {
|
|
let replyText =
|
|
params.friendlyMessage ||
|
|
(params.action === "cancel_requested"
|
|
? "已收到取消指令,当前分镜流程不会继续自动执行。"
|
|
: "收到修改意见,我会先停在草案阶段,等待你继续调整。");
|
|
let nextWorkflowStatus = params.action === "cancel_requested" ? "cancelled" : "draft";
|
|
|
|
if (params.action === "revision_requested" && params.workflowId) {
|
|
const revisionTaskDetail = await getVideoStoryboardTaskDetail(
|
|
params.workflowId,
|
|
).catch(() => null);
|
|
const revisionResult = await reviseStoryboardTaskByCommand({
|
|
taskId: params.workflowId,
|
|
command: revisionTaskDetail
|
|
? await resolveStoryboardRevisionCommand({
|
|
text: params.text,
|
|
detail: revisionTaskDetail,
|
|
})
|
|
: null,
|
|
onProgress: params.onProgress,
|
|
});
|
|
replyText = revisionResult.message || replyText;
|
|
nextWorkflowStatus = revisionResult.ok ? "awaiting_user_confirmation" : "draft";
|
|
}
|
|
|
|
return {
|
|
replyText,
|
|
nextWorkflowStatus,
|
|
videoMetadata: params.workflowId
|
|
? ({
|
|
storyboard: {
|
|
enabled: true,
|
|
taskId: params.workflowId,
|
|
action: params.action,
|
|
},
|
|
updatedAt: Date.now(),
|
|
} as any)
|
|
: null,
|
|
};
|
|
}
|
|
|
|
export function buildStoryboardConfirmedAck(taskId: string) {
|
|
return {
|
|
acknowledgeMessage: "已收到确认,开始按分镜逐段生成视频,请稍候。",
|
|
acknowledgeMetadata: {
|
|
storyboard: {
|
|
enabled: true,
|
|
taskId,
|
|
status: "confirmed",
|
|
},
|
|
updatedAt: Date.now(),
|
|
} as any,
|
|
};
|
|
}
|
|
|
|
export function buildStoryboardExecutionVideoMetadata(params: {
|
|
taskId: string;
|
|
status: string;
|
|
successCount: number;
|
|
failedCount: number;
|
|
}) {
|
|
return {
|
|
storyboard: {
|
|
enabled: true,
|
|
taskId: params.taskId,
|
|
successCount: params.successCount,
|
|
failedCount: params.failedCount,
|
|
},
|
|
status: params.status,
|
|
updatedAt: Date.now(),
|
|
} as any;
|
|
}
|
|
|
|
export async function executeStoryboardConfirmedWorkflow(params: {
|
|
taskId: string;
|
|
onProgress?: (event: StoryboardProgressEvent) => void | Promise<void>;
|
|
}) {
|
|
const executionResult = await executeConfirmedStoryboardTask({
|
|
taskId: params.taskId,
|
|
onProgress: params.onProgress,
|
|
});
|
|
|
|
return {
|
|
executionResult,
|
|
firstVideoUrl: executionResult.videoUrls[0] || "",
|
|
finalVideoMetadata: buildStoryboardExecutionVideoMetadata({
|
|
taskId: executionResult.taskId,
|
|
status: executionResult.status,
|
|
successCount: executionResult.successCount,
|
|
failedCount: executionResult.failedCount,
|
|
}),
|
|
};
|
|
}
|