| | |
| | | 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; |
| | |
| | | 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, |
| | |
| | | const result = await startProject({ |
| | | idea: params.idea, |
| | | style: params.style, |
| | | video_ratio: params.video_ratio, |
| | | llm_model: params.llm_model, |
| | | vlm_model: params.vlm_model, |
| | | image_t2i_model: params.image_t2i_model, |
| | | image_it2i_model: params.image_it2i_model, |
| | | video_model: params.video_model, |
| | | enable_concurrency: params.enable_concurrency, |
| | | web_search: params.web_search, |
| | | expand_idea: params.expand_idea, |
| | | }); |
| | | setSessionId(result.session_id); |
| | | |
| | |
| | | idea: params.idea, |
| | | session_id: result.session_id, |
| | | style: params.style, |
| | | video_ratio: params.video_ratio, |
| | | llm_model: params.llm_model, |
| | | vlm_model: params.vlm_model, |
| | | image_t2i_model: params.image_t2i_model, |
| | |
| | | image_t2i_model: projectParams?.image_t2i_model, |
| | | image_it2i_model: projectParams?.image_it2i_model, |
| | | video_model: projectParams?.video_model, |
| | | video_ratio: projectParams?.video_ratio, |
| | | video_sound: videoSound, |
| | | video_shot_type: videoShotType, |
| | | }; |
| | |
| | | // ── 用户介入修改 ── |
| | | const handleIntervene = async (stageId: string, modifications: Record<string, any>) => { |
| | | if (!sessionId) return; |
| | | |
| | | // 构建完整的 inputData 传给后端,确保比例等参数能传递 |
| | | const inputData: Record<string, any> = { |
| | | ...modifications, |
| | | session_id: sessionId, |
| | | style: projectParams?.style, |
| | | video_ratio: projectParams?.video_ratio, |
| | | llm_model: projectParams?.llm_model, |
| | | vlm_model: projectParams?.vlm_model, |
| | | image_t2i_model: projectParams?.image_t2i_model, |
| | | image_it2i_model: projectParams?.image_it2i_model, |
| | | video_model: projectParams?.video_model, |
| | | }; |
| | | |
| | | // 设置 running 状态以便显示进度条(如 Logline 选择后生成剧本) |
| | | // 若选择了 Logline,将其保存到 artifact 以便 ScriptStage 在生成期间展示 |
| | | // 若选择了模式,保留已选 Logline 并设置 generating 状态 |
| | |
| | | setIsRunning(true); |
| | | updateStageState(stageId, { status: 'running', progress: 0, progressMessage: '处理中...', ...(artifactPatch ? { artifact: artifactPatch } : {}) }); |
| | | try { |
| | | const response = await intervene(sessionId, stageId, modifications); |
| | | const response = await intervene(sessionId, stageId, inputData); |
| | | for await (const event of parseStreamEvents(response)) { |
| | | if (event.type === 'progress') { |
| | | updateStageState(stageId, { |
| | |
| | | image_t2i_model: projectParams?.image_t2i_model, |
| | | image_it2i_model: projectParams?.image_it2i_model, |
| | | video_model: projectParams?.video_model, |
| | | video_sound: videoSound, |
| | | video_shot_type: videoShotType, |
| | | video_ratio: projectParams?.video_ratio, |
| | | }; |
| | | |
| | | // 尝试获取场景数 |
| | |
| | | } catch { /* ignore */ } |
| | | } |
| | | |
| | | // 如果 current_stage 不在 completedStages 中,也需要显示(可能是 stage_completed 或 running 状态) |
| | | // 如果 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: status.status === 'waiting_in_stage' ? 'waiting' : (status.status === 'stage_completed' ? 'completed' : 'running'), |
| | | status: isError ? 'error' : (isWaiting ? 'waiting' : (isCompleted ? 'completed' : (isStopped ? 'stopped' : 'running'))), |
| | | progress: 100, |
| | | progressMessage: status.status === 'waiting_in_stage' ? '等待确认' : (status.status === 'stage_completed' ? '已完成' : '进行中'), |
| | | progressMessage: isError ? '执行失败' : (isWaiting ? '等待确认' : (isCompleted ? '已完成' : (isStopped ? '已停止' : '进行中'))), |
| | | artifact: null, |
| | | error: null, |
| | | error: isError ? (status.error || '执行出错') : (isStopped ? '手动停止' : null), |
| | | }; |
| | | try { |
| | | const artResult = await getArtifact(sid, currentStage); |
| | |
| | | video_model: s.video_model || '', |
| | | expand_idea: s.expand_idea || false, |
| | | enable_concurrency: s.enable_concurrency || false, |
| | | web_search: s.web_search || false, |
| | | }); |
| | | } |
| | | |
| | |
| | | }; |
| | | |
| | | // ── 删除历史记录 ── |
| | | 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); |
| | | } |
| | | }; |
| | | |
| | |
| | | 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, |
| | | } |
| | | : undefined; |
| | | |
| | |
| | | } else { |
| | | // current_stage 本身:根据 stageStates 判断 |
| | | stageStatuses[s] = stageStates[s]?.status || 'pending'; |
| | | if (stageStatuses[s] === 'stopped') stageStatuses[s] = 'stopped'; |
| | | } |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | ? 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} |
| | |
| | | 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; |
| | | }, {})} |
| | | /> |
| | | ); |
| | | }; |