"""SwiftCanvas 核心模块。
将 ComfyUI 交互逻辑与界面解耦,便于 Web UI 与命令行共用。
注意:backend 采用**延迟导入**。安装脚本(scripts/install.py)在虚拟环境还没有
requests / gradio 时就要 ``from core.config import ...``,如果这里急切加载 backend,
会因为缺少尚未安装的依赖而直接崩溃。请保持 config.py / workflow.py 只依赖标准库。
"""
from .config import Config, missing_models
from .workflow import build_workflow
_BACKEND_EXPORTS = frozenset({
"ComfyUIManager",
"ComfyUIError",
"generate",
"get_manager",
"safe_filename",
})
__all__ = [
"Config",
"missing_models",
"build_workflow",
*_BACKEND_EXPORTS,
]
def __getattr__(name):
if name in _BACKEND_EXPORTS:
import importlib
module = importlib.import_module(".backend", __name__)
value = getattr(module, name)
globals()[name] = value
return value
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
def __dir__():
return sorted(set(globals()) | _BACKEND_EXPORTS)