| | |
| | | } |
| | | |
| | | |
| | | def inject_user_selections(state, stage: str, data: dict): |
| | | """Inject persisted user choices into downstream stage input.""" |
| | | if stage == 'video_generation' and 'selected_images' not in data: |
| | | ref_art = state.artifacts.get('reference_generation', {}) |
| | | if isinstance(ref_art, dict): |
| | | scenes = ref_art.get('scenes', []) |
| | | selected_images = {s['id']: s['selected'] for s in scenes |
| | | if isinstance(s, dict) and s.get('id') and s.get('selected')} |
| | | if selected_images: |
| | | data['selected_images'] = selected_images |
| | | |
| | | if stage == 'video_generation' and 'clips' not in data: |
| | | vid_art = state.artifacts.get('video_generation', {}) |
| | | if isinstance(vid_art, dict): |
| | | clips = vid_art.get('clips', []) |
| | | if clips: |
| | | data['clips'] = clips |
| | | |
| | | if stage == 'post_production' and 'selected_clips' not in data: |
| | | vid_art = state.artifacts.get('video_generation', {}) |
| | | if isinstance(vid_art, dict): |
| | | clips = vid_art.get('clips', []) |
| | | selected_clips = {c['id']: c['selected'] for c in clips |
| | | if isinstance(c, dict) and c.get('id') and c.get('selected')} |
| | | if selected_clips: |
| | | data['selected_clips'] = selected_clips |
| | | |
| | | |
| | | |
| | | def build_openclaw_message(stage: str, result: Dict[str, Any]) -> str: |
| | | openclaw_msg = result.get("openclaw_hint", "") |
| | | if not openclaw_msg and result.get("requires_intervention", False): |
| | |
| | | break |
| | | |
| | | if await request.is_disconnected(): |
| | | if on_disconnect: |
| | | on_disconnect() |
| | | yield json.dumps({"type": "error", "content": "Client disconnected"}) + "\n" |
| | | workflow_engine.track_background_task(task) |
| | | return |
| | | |
| | | while not progress_events.empty(): |
| | |
| | | break |
| | | |
| | | result = task.result() |
| | | workflow_engine.save_session_to_disk(state.session_id) |
| | | status_snapshot = workflow_engine.persist_session_snapshot(state.session_id) |
| | | |
| | | payload = { |
| | | "type": "stage_complete", |
| | | "stage": stage, |
| | | "status": state.status, |
| | | "status": status_snapshot, |
| | | "requires_intervention": result.get("requires_intervention", False), |
| | | "openclaw": build_openclaw_message(stage, result), |
| | | } |
| | |
| | | |
| | | except Exception as e: |
| | | try: |
| | | workflow_engine.save_session_to_disk(state.session_id) |
| | | workflow_engine.persist_session_snapshot(state.session_id) |
| | | except Exception: |
| | | pass |
| | | yield json.dumps({"type": "error", "content": str(e)}) + "\n" |