From 4b366db142db3b8cb6695919aefc9a935dcd267c Mon Sep 17 00:00:00 2001
From: hit-cxf <2024111082@stu.hit.edu.cn>
Date: Mon, 06 Apr 2026 17:44:55 +0800
Subject: [PATCH] 添加了设置剧集数量的功能

---
 aigc-director/aigc-claw/frontend/components/WorkflowPanel.tsx |   56 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/aigc-director/aigc-claw/frontend/components/WorkflowPanel.tsx b/aigc-director/aigc-claw/frontend/components/WorkflowPanel.tsx
index 4b23251..d393ce8 100644
--- a/aigc-director/aigc-claw/frontend/components/WorkflowPanel.tsx
+++ b/aigc-director/aigc-claw/frontend/components/WorkflowPanel.tsx
@@ -130,6 +130,15 @@
           pollRef.current = null;
           return;
         }
+        if (status.status === 'stopped') {
+          updateStageState(stageId, {
+            status: 'stopped',
+            error: '手动停止',
+            progressMessage: '已停止',
+          });
+          pollRef.current = null;
+          return;
+        }
         // 如果后端状态不再是 running,提前停止轮询(比如变成了 waiting_intervention 或已完成)
         if (status.status !== 'running') {
           pollRef.current = null;
@@ -369,6 +378,11 @@
             artifact = artResult.artifact;
           } catch { /* ignore */ }
 
+          // 如果是后处理阶段,即使 artifact 为空也尝试从事件中读取预览数据
+          if (stageId === 'post_production' && !artifact && event.data?.assets_preview) {
+            artifact = event.data.assets_preview;
+          }
+
           updateStageState(stageId, {
             status: newStatus,
             progress: 100,
@@ -443,6 +457,7 @@
         enable_concurrency: params.enable_concurrency,
         web_search: params.web_search,
         expand_idea: params.expand_idea,
+        episodes: params.episodes,
       });
       setSessionId(result.session_id);
 
@@ -977,18 +992,19 @@
         } catch { /* ignore */ }
       }
 
-      // 如果 current_stage 不在 completedStages 中,也需要显示(可能是 stage_completed、running 或 error 状态)
+      // 如果 current_stage 不在 completedStages 中,也需要显示(可能是 stage_completed、running, stopped, 或 error 状态)
       if (currentStage && !completedStages.includes(currentStage)) {
         const isError = status.status === 'error';
         const isWaiting = status.status === 'waiting_in_stage';
         const isCompleted = status.status === 'stage_completed';
+        const isStopped = status.status === 'stopped';
         
         newStates[currentStage] = {
-          status: isError ? 'error' : (isWaiting ? 'waiting' : (isCompleted ? 'completed' : 'running')),
+          status: isError ? 'error' : (isWaiting ? 'waiting' : (isCompleted ? 'completed' : (isStopped ? 'stopped' : 'running'))),
           progress: 100,
-          progressMessage: isError ? '执行失败' : (isWaiting ? '等待确认' : (isCompleted ? '已完成' : '进行中')),
+          progressMessage: isError ? '执行失败' : (isWaiting ? '等待确认' : (isCompleted ? '已完成' : (isStopped ? '已停止' : '进行中'))),
           artifact: null,
-          error: isError ? (status.error || '执行出错') : null,
+          error: isError ? (status.error || '执行出错') : (isStopped ? '手动停止' : null),
         };
         try {
           const artResult = await getArtifact(sid, currentStage);
@@ -1046,21 +1062,18 @@
   };
 
   // ── 删除历史记录 ──
-  const handleDeleteSession = async (sid: string, password: string) => {
-    await deleteSession(sid, password);
+  const handleDeleteSession = async (sid: string) => {
+    await deleteSession(sid);
     setHistory(prev => prev.filter(h => h.id !== sid));
   };
 
   // ── 模型配置变更处理 ──
   const handleModelConfigChange = (config: ModelConfig) => {
     setProjectParams(prev => prev ? { ...prev, ...config } : null);
-    // 同步到后端会话元数据(需要将 boolean 转为 string)
+    // 同步到后端会话元数据
     if (sessionId) {
-      const stringConfig: Record<string, string> = {};
-      for (const [key, value] of Object.entries(config)) {
-        stringConfig[key] = String(value);
-      }
-      updateModels(sessionId, stringConfig).catch(console.error);
+      const payload: Record<string, any> = { ...config };
+      updateModels(sessionId, payload).catch(console.error);
     }
   };
 
@@ -1074,8 +1087,8 @@
         video_model: projectParams.video_model,
         video_ratio: projectParams.video_ratio,
         enable_concurrency: projectParams.enable_concurrency || false,
-        web_search: projectParams.web_search || false,
-        expand_idea: projectParams.expand_idea || false,
+        // web_search: projectParams.web_search || false,
+        // expand_idea: projectParams.expand_idea || false,
       }
     : undefined;
 
@@ -1102,6 +1115,7 @@
     } else {
       // current_stage 本身:根据 stageStates 判断
       stageStatuses[s] = stageStates[s]?.status || 'pending';
+      if (stageStatuses[s] === 'stopped') stageStatuses[s] = 'stopped';
     }
   }
 
@@ -1117,12 +1131,14 @@
   if (hasRunning) computedStatus = 'running';
   else if (hasWaiting) computedStatus = 'waiting_in_stage';
   else if (hasError) computedStatus = 'error';
+  // Check if stopped in stageStates
+  else if (Object.values(stageStates).some(s => s.status === 'stopped')) computedStatus = 'stopped';
   else if (allCompleted && stageStates[STAGE_ORDER[STAGE_ORDER.length - 1]]?.status === 'completed') {
     computedStatus = 'session_completed';
   } else if (allCompleted) {
     computedStatus = 'stage_completed';
   } else {
-    computedStatus = 'idle';
+    computedStatus = Object.values(stageStates).some(s => s.status === 'stopped') ? 'stopped' : 'idle';
   }
 
   const projectStatus = sessionId ? computedStatus : undefined;
@@ -1170,6 +1186,11 @@
       ? stageStates['reference_generation']?.artifact
       : undefined;
 
+    // 传递第1阶段的 artifact 到第4、5、6阶段用于获取剧集标题
+    const scriptArtifact = (activeStage === 'reference_generation' || activeStage === 'video_generation' || activeStage === 'post_production')
+      ? stageStates['script_generation']?.artifact
+      : undefined;
+
     return (
       <Component
         state={state}
@@ -1190,6 +1211,11 @@
           if (params.videoShotType !== undefined) setVideoShotType(params.videoShotType);
         }}
         referenceArtifact={referenceArtifact}
+        scriptArtifact={scriptArtifact}
+        artifacts={Object.keys(stageStates).reduce((acc: any, key) => {
+          acc[key] = stageStates[key].artifact;
+          return acc;
+        }, {})}
       />
     );
   };

--
Gitblit v1.8.0