| | |
| | | # -*- coding: utf-8 -*- |
| | | # -*- coding: utf-8 -*- |
| | | """ |
| | | 核心编排器 / 工作流引擎 |
| | | 管理六阶段状态机,协调各智能体执行,支持用户在任意阶段介入 |
| | |
| | | "image_t2i_model", |
| | | "image_it2i_model", |
| | | "video_model", |
| | | "video_first_frame_model", |
| | | "video_start_end_model", |
| | | "video_reference_model", |
| | | "video_generation_mode", |
| | | "video_style", |
| | | "enable_concurrency", |
| | | "web_search", |
| | |
| | | nested_meta = data.get("meta") |
| | | if isinstance(nested_meta, dict): |
| | | meta.update({k: _normalize_meta_value(v) for k, v in nested_meta.items() if v is not None}) |
| | | # Legacy session compatibility: old session JSON stored these fields at the root instead of under meta. |
| | | for key in SESSION_META_KEYS: |
| | | if key not in meta and key in data and data[key] is not None: |
| | | meta[key] = _normalize_meta_value(data[key]) |
| | |
| | | state.status[stage.value] = "pending" |
| | | elif isinstance(loaded_status, dict): |
| | | state.status = loaded_status |
| | | # Scrub running and waiting statuses because this is loading from a restart/crash |
| | | for k, v in state.status.items(): |
| | | if v == "running": |
| | | state.status[k] = "error" |
| | | state.error = "服务意外中断,任务已停止" |
| | | elif v == "waiting": |
| | | state.status[k] = "pending" |
| | | |
| | | state.artifacts = data.get('artifacts', {}) |
| | | # Scrub running and waiting artifact items |
| | | for stage, artifact in state.artifacts.items(): |
| | | if not isinstance(artifact, dict): |
| | | continue |
| | | for key in ["clips", "images", "scenes", "characters", "settings"]: |
| | | items = artifact.get(key) |
| | | if isinstance(items, list): |
| | | for item in items: |
| | | if isinstance(item, dict): |
| | | if item.get("status") == "running": |
| | | item["status"] = "failed" |
| | | elif item.get("status") == "waiting": |
| | | item["status"] = "pending" |
| | | |
| | | state.stage_progress = data.get('stage_progress', {}) |
| | | state.meta = _extract_session_meta(data) |
| | | state.updated_at = data.get('updated_at', 0) |
| | |
| | | if "created_at" not in data: |
| | | data["created_at"] = time.time() |
| | | |
| | | # 会话级生成参数统一保存在 meta 中;清理旧版本遗留的根字段。 |
| | | # Legacy session compatibility: clean root-level generation fields left by old session JSON. |
| | | for key in SESSION_META_KEYS: |
| | | data.pop(key, None) |
| | | |
| | |
| | | state.status[stage.value] = "pending" |
| | | elif isinstance(old_status, dict): |
| | | state.status = old_status |
| | | # Scrub running and waiting statuses |
| | | for k, v in state.status.items(): |
| | | if v == "running": |
| | | state.status[k] = "error" |
| | | state.error = "服务意外中断,任务已停止" |
| | | elif v == "waiting": |
| | | state.status[k] = "pending" |
| | | |
| | | state.artifacts = data.get("artifacts", {}) |
| | | # Scrub artifact running/waiting items |
| | | for stage, artifact in state.artifacts.items(): |
| | | if not isinstance(artifact, dict): |
| | | continue |
| | | for key in ["clips", "images", "scenes", "characters", "settings"]: |
| | | items = artifact.get(key) |
| | | if isinstance(items, list): |
| | | for item in items: |
| | | if isinstance(item, dict): |
| | | if item.get("status") == "running": |
| | | item["status"] = "failed" |
| | | elif item.get("status") == "waiting": |
| | | item["status"] = "pending" |
| | | state.stage_progress = data.get("stage_progress", {}) |
| | | state.error = data.get("error") |
| | | state.updated_at = data.get("updated_at", 0) |