| | |
| | | }); |
| | | } |
| | | |
| | | function mergeAssetVersions(current?: string[], incoming?: string[]): string[] { |
| | | const merged: string[] = []; |
| | | [...(Array.isArray(current) ? current : []), ...(Array.isArray(incoming) ? incoming : [])].forEach(path => { |
| | | if (path && !merged.includes(path)) merged.push(path); |
| | | }); |
| | | return merged; |
| | | } |
| | | |
| | | function mergeAssetUpdateItem(item: any, assetUpdate: any): any { |
| | | const hasExistingSelection = Boolean(item?.selected); |
| | | const nextStatus = hasExistingSelection && ['done', 'failed'].includes(assetUpdate.status) |
| | | ? 'done' |
| | | : (assetUpdate.status ?? item.status); |
| | | return { |
| | | ...item, |
| | | status: nextStatus, |
| | | selected: hasExistingSelection |
| | | ? item.selected |
| | | : (assetUpdate.selected || item.selected), |
| | | versions: assetUpdate.versions |
| | | ? mergeAssetVersions(item.versions, assetUpdate.versions) |
| | | : item.versions, |
| | | }; |
| | | } |
| | | |
| | | function getStageProgressSnapshot(status: any, stageId: string): Partial<StageState> { |
| | | const snapshot = status?.stage_progress?.[stageId]; |
| | | if (!snapshot || typeof snapshot !== 'object') return {}; |
| | |
| | | const [history, setHistory] = useState<HistoryItem[]>([]); |
| | | const [projectParams, setProjectParams] = useState<ProjectParams | null>(null); |
| | | const [autoMode, setAutoMode] = useState(false); |
| | | const [videoSound, setVideoSound] = useState('on'); |
| | | const [videoShotType, setVideoShotType] = useState('multi'); |
| | | // 用于顶栏流程图状态判断 |
| | | const [currentStageFromSession, setCurrentStageFromSession] = useState<string | null>(null); |
| | | const [completedStagesFromSession, setCompletedStagesFromSession] = useState<string[]>([]); |
| | | |
| | | const abortRef = useRef<AbortController | null>(null); |
| | | const stoppedRef = useRef(false); |
| | | const autoModeRef = useRef(autoMode); |
| | | const pollRef = useRef<Set<string>>(new Set()); |
| | | |
| | | useEffect(() => { |
| | | autoModeRef.current = autoMode; |
| | | }, [autoMode]); |
| | | |
| | | const handleAutoModeChange = useCallback((nextAutoMode: boolean) => { |
| | | autoModeRef.current = nextAutoMode; |
| | | setAutoMode(nextAutoMode); |
| | | }, []); |
| | | |
| | | // 清理轮询 |
| | | useEffect(() => { |
| | |
| | | const items = [...(prevArt[key] || [])]; |
| | | const idx = items.findIndex((item: any) => item.id === assetUpdate.id); |
| | | if (idx >= 0) { |
| | | items[idx] = { |
| | | ...items[idx], |
| | | status: assetUpdate.status, |
| | | selected: assetUpdate.selected || items[idx].selected, |
| | | versions: assetUpdate.versions || items[idx].versions, |
| | | }; |
| | | items[idx] = mergeAssetUpdateItem(items[idx], assetUpdate); |
| | | } |
| | | return { |
| | | ...prev, |
| | |
| | | if (isRunning) return; |
| | | stoppedRef.current = false; |
| | | const useAutoMode = autoOverride !== undefined ? autoOverride : autoMode; |
| | | if (autoOverride !== undefined) setAutoMode(autoOverride); |
| | | if (autoOverride !== undefined) handleAutoModeChange(autoOverride); |
| | | setIsRunning(true); |
| | | setStageStates(initStageStates()); |
| | | setProjectParams(params); |
| | |
| | | vlm_model: params.vlm_model, |
| | | image_t2i_model: params.image_t2i_model, |
| | | image_it2i_model: params.image_it2i_model, |
| | | video_generation_mode: params.video_generation_mode, |
| | | video_first_frame_model: params.video_first_frame_model, |
| | | video_start_end_model: params.video_start_end_model, |
| | | video_reference_model: params.video_reference_model, |
| | | video_model: params.video_model, |
| | | enable_concurrency: params.enable_concurrency, |
| | | web_search: params.web_search, |
| | |
| | | vlm_model: params.vlm_model, |
| | | image_t2i_model: params.image_t2i_model, |
| | | image_it2i_model: params.image_it2i_model, |
| | | video_generation_mode: params.video_generation_mode, |
| | | video_first_frame_model: params.video_first_frame_model, |
| | | video_start_end_model: params.video_start_end_model, |
| | | video_reference_model: params.video_reference_model, |
| | | video_model: params.video_model, |
| | | scene_number: result.params?.scene_number, |
| | | expand_idea: params.expand_idea, |
| | |
| | | // waiting: 等待用户介入(如选择角色/图片),不能自动 continue |
| | | // completed: 阶段完成,等待确认进入下一阶段 |
| | | if (stageStatus === 'completed' || stageStatus === 'session_completed') { |
| | | if (useAutoMode) { |
| | | if (autoModeRef.current) { |
| | | // 代理模式:自动确认并继续 |
| | | await continueWorkflow(result.session_id); |
| | | updateStageState(stageId, { status: 'completed', progressMessage: '已自动确认' }); |
| | |
| | | vlm_model: projectParams?.vlm_model, |
| | | image_t2i_model: projectParams?.image_t2i_model, |
| | | image_it2i_model: projectParams?.image_it2i_model, |
| | | video_generation_mode: projectParams?.video_generation_mode, |
| | | video_first_frame_model: projectParams?.video_first_frame_model, |
| | | video_start_end_model: projectParams?.video_start_end_model, |
| | | video_reference_model: projectParams?.video_reference_model, |
| | | video_model: projectParams?.video_model, |
| | | video_ratio: projectParams?.video_ratio, |
| | | video_resolution: projectParams?.video_resolution, |
| | | video_sound: videoSound, |
| | | video_shot_type: videoShotType, |
| | | video_sound: 'on', |
| | | video_shot_type: 'multi', |
| | | }; |
| | | // 从剧本产物获取实际场景数 |
| | | try { |
| | |
| | | // waiting: 等待用户介入(如选择角色/图片),不能自动 continue |
| | | // completed: 阶段完成,等待确认进入下一阶段,可以自动 continue |
| | | if (nStageStatus === 'completed' || nStageStatus === 'session_completed') { |
| | | if (autoMode) { |
| | | if (autoModeRef.current) { |
| | | await continueWorkflow(sessionId); |
| | | updateStageState(nextStage, { status: 'completed', progressMessage: '已自动确认' }); |
| | | setCompletedStagesFromSession(prev => [...prev, nextStage]); |
| | |
| | | vlm_model: projectParams?.vlm_model, |
| | | image_t2i_model: projectParams?.image_t2i_model, |
| | | image_it2i_model: projectParams?.image_it2i_model, |
| | | video_generation_mode: projectParams?.video_generation_mode, |
| | | video_first_frame_model: projectParams?.video_first_frame_model, |
| | | video_start_end_model: projectParams?.video_start_end_model, |
| | | video_reference_model: projectParams?.video_reference_model, |
| | | video_model: projectParams?.video_model, |
| | | video_sound: videoSound, |
| | | video_shot_type: videoShotType, |
| | | video_sound: 'on', |
| | | video_shot_type: 'multi', |
| | | }; |
| | | |
| | | // 设置 running 状态以便显示进度条(如 Logline 选择后生成剧本) |
| | |
| | | const items = [...(prevArt[key] || [])]; |
| | | const idx = items.findIndex((item: any) => item.id === assetUpdate.id); |
| | | if (idx >= 0) { |
| | | items[idx] = { |
| | | ...items[idx], |
| | | status: assetUpdate.status, |
| | | selected: assetUpdate.selected || items[idx].selected, |
| | | versions: assetUpdate.versions || items[idx].versions, |
| | | }; |
| | | items[idx] = mergeAssetUpdateItem(items[idx], assetUpdate); |
| | | } |
| | | return { |
| | | ...prev, |
| | |
| | | // 剧本阶段:直接保存整个 data 覆盖 artifact |
| | | patch = selections; |
| | | } else if (stageId === 'character_design') { |
| | | const chars = (art.characters || []).map((c: any) => ({ ...c, selected: selections[c.id] || c.selected })); |
| | | const sets = (art.settings || []).map((s: any) => ({ ...s, selected: selections[s.id] || s.selected })); |
| | | const { _editDescs, ...restSelections } = selections; |
| | | const chars = (art.characters || []).map((c: any) => ({ |
| | | ...c, |
| | | selected: restSelections[c.id] || c.selected, |
| | | description: _editDescs?.characters?.[c.id] ?? c.description, |
| | | })); |
| | | const sets = (art.settings || []).map((s: any) => ({ |
| | | ...s, |
| | | selected: restSelections[s.id] || s.selected, |
| | | description: _editDescs?.settings?.[s.id] ?? s.description, |
| | | })); |
| | | patch = { characters: chars, settings: sets }; |
| | | } else if (stageId === 'storyboard') { |
| | | // 分镜阶段:保存 shots 数据(排除 original_shots,只保留 artifact 需要的字段) |
| | |
| | | vlm_model: projectParams?.vlm_model, |
| | | image_t2i_model: projectParams?.image_t2i_model, |
| | | image_it2i_model: projectParams?.image_it2i_model, |
| | | video_generation_mode: projectParams?.video_generation_mode, |
| | | video_first_frame_model: projectParams?.video_first_frame_model, |
| | | video_start_end_model: projectParams?.video_start_end_model, |
| | | video_reference_model: projectParams?.video_reference_model, |
| | | video_model: projectParams?.video_model, |
| | | video_ratio: projectParams?.video_ratio, |
| | | video_resolution: projectParams?.video_resolution, |
| | |
| | | const meta = ((status as any).meta || {}) as any; |
| | | const s = Object.keys(meta).length > 0 ? meta : (status as any); |
| | | if (s.idea || s.user_textbox_input) { |
| | | // Legacy session compatibility: old sessions only stored one video_model, so hydrate it as the first-frame model. |
| | | const restoredFirstFrameVideoModel = s.video_first_frame_model || s.video_model || ''; |
| | | setProjectParams({ |
| | | idea: s.idea || s.user_textbox_input || '', |
| | | style: s.style || '', |
| | |
| | | vlm_model: s.vlm_model || '', |
| | | image_t2i_model: s.image_t2i_model || '', |
| | | image_it2i_model: s.image_it2i_model || '', |
| | | video_generation_mode: s.video_generation_mode || 'first_frame', |
| | | video_first_frame_model: restoredFirstFrameVideoModel, |
| | | video_start_end_model: s.video_start_end_model || 'wan2.7-i2v', |
| | | video_reference_model: s.video_reference_model || 'wan2.7-r2v', |
| | | video_model: s.video_model || '', |
| | | expand_idea: s.expand_idea || false, |
| | | enable_concurrency: s.enable_concurrency || false, |
| | |
| | | vlm_model: projectParams.vlm_model, |
| | | image_t2i_model: projectParams.image_t2i_model, |
| | | image_it2i_model: projectParams.image_it2i_model, |
| | | // Legacy session compatibility: projectParams may come from an old session with only video_model. |
| | | video_generation_mode: projectParams.video_generation_mode || 'first_frame', |
| | | video_first_frame_model: projectParams.video_first_frame_model || projectParams.video_model, |
| | | video_start_end_model: projectParams.video_start_end_model || 'wan2.7-i2v', |
| | | video_reference_model: projectParams.video_reference_model || 'wan2.7-r2v', |
| | | video_model: projectParams.video_model, |
| | | video_ratio: projectParams.video_ratio, |
| | | video_resolution: projectParams.video_resolution || '720P', |
| | |
| | | } |
| | | |
| | | // ── 计算项目状态 ── |
| | | // 后端状态: pending, running, waiting, completed, completed, error |
| | | // 后端阶段状态: pending, running, waiting, completed, stopped, error |
| | | // 前端 StageStatus: pending, running, waiting, completed, error |
| | | const hasRunning = Object.values(stageStates).some(s => s.status === 'running'); |
| | | const hasWaiting = Object.values(stageStates).some(s => s.status === 'waiting'); |
| | |
| | | isRunning={effectiveIsRunning} |
| | | hasPendingItems={hasPendingItems} |
| | | hasNextStageStarted={hasNextStageStarted} |
| | | videoSound={videoSound} |
| | | videoShotType={videoShotType} |
| | | onVideoParamsChange={(params: { videoSound?: string; videoShotType?: string }) => { |
| | | if (params.videoSound !== undefined) setVideoSound(params.videoSound); |
| | | if (params.videoShotType !== undefined) setVideoShotType(params.videoShotType); |
| | | }} |
| | | referenceArtifact={referenceArtifact} |
| | | scriptArtifact={scriptArtifact} |
| | | artifacts={Object.keys(stageStates).reduce((acc: any, key) => { |
| | |
| | | isRunning={effectiveIsRunning} |
| | | onStop={handleStop} |
| | | autoMode={autoMode} |
| | | onAutoModeChange={setAutoMode} |
| | | onAutoModeChange={handleAutoModeChange} |
| | | modelConfig={modelConfig} |
| | | onModelConfigChange={handleModelConfigChange} |
| | | projectStatus={projectStatus} |