83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
"""HEL-892 isolated browser host: production workflow router, no execution worker.
|
|
|
|
From repo root: calliope-backend/.venv/bin/python e2e/wanplus-document-server.py
|
|
Run Vite on 5173 alongside it. No remote ComfyUI endpoint is configured.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from pathlib import Path
|
|
|
|
import uvicorn
|
|
from calliope.comfyui.companions import load_companions
|
|
from calliope.comfyui.library import import_library
|
|
from calliope.config import settings
|
|
from calliope.db import get_db, migrate_db
|
|
from calliope.routers import workflows
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import JSONResponse
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DATA = ROOT / ".local-evidence" / "wanplus-document-server"
|
|
settings.data_dir = DATA
|
|
settings.db_name = "library.db"
|
|
settings.assets_dir = DATA / "assets"
|
|
settings.comfyui_endpoints = []
|
|
settings.comfyui_base_url = "http://127.0.0.1:1"
|
|
app = FastAPI()
|
|
app.include_router(workflows.router, prefix="/api/workflows")
|
|
|
|
|
|
@app.middleware("http")
|
|
async def read_only(request, call_next):
|
|
if request.method != "GET":
|
|
return JSONResponse({"detail": "隔离说明服务仅允许GET"}, status_code=405)
|
|
return await call_next(request)
|
|
|
|
|
|
@app.get("/api/settings")
|
|
def get_settings():
|
|
return {"comfyui_endpoints": [], "comfyui_active_id": None}
|
|
|
|
|
|
def prepare():
|
|
DATA.mkdir(parents=True, exist_ok=True)
|
|
asyncio.run(migrate_db(settings.db_path))
|
|
conn = get_db(settings.db_path)
|
|
try:
|
|
report = import_library(
|
|
conn,
|
|
ROOT / "example_ComfyUI_workflows",
|
|
source_commit="ui-browser",
|
|
companions=load_companions(ROOT / "docs/hel-892/supplied-api/manifest.json"),
|
|
)
|
|
print({"counts": report["counts"], "states": report["states"]})
|
|
for name, document in [
|
|
("旧工作流回退(隔离测试夹具)", None),
|
|
("空说明回退(隔离测试夹具)", "{}"),
|
|
]:
|
|
if conn.execute("SELECT id FROM workflows WHERE name=?", (name,)).fetchone():
|
|
continue
|
|
conn.execute(
|
|
"INSERT INTO workflows(name,kind,workflow_json,input_schema,description,"
|
|
"is_enabled,doc_json) VALUES (?,?,?,?,?,?,?)",
|
|
(
|
|
name,
|
|
"image",
|
|
"{}",
|
|
"[]",
|
|
"隔离库旧条目回退测试;不代表真实工作流。",
|
|
0,
|
|
document,
|
|
),
|
|
)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
prepare()
|
|
uvicorn.run(app, host="127.0.0.1", port=8247)
|