52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""Authoring pipeline: Langflow export -> canonical file -> version -> LFX deploy."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlmodel import Session
|
|
|
|
from app.models import FlowDefinition, FlowVersion
|
|
from app.settings import settings
|
|
|
|
from . import export, store, sync
|
|
from .langflow_client import LangflowClient
|
|
from .lfx_client import LfxClient
|
|
|
|
|
|
async def import_from_langflow(
|
|
session: Session,
|
|
langflow: LangflowClient,
|
|
lfx: LfxClient,
|
|
langflow_flow_id: str,
|
|
*,
|
|
name: str | None = None,
|
|
author: str = "",
|
|
deploy: bool = True,
|
|
) -> tuple[FlowDefinition, FlowVersion]:
|
|
"""Export a flow from Langflow, persist it to backend/flows, then sync.
|
|
|
|
The canonical file is written first so the directory stays the source of
|
|
truth; sync_document() derives the definition + version from it.
|
|
"""
|
|
exported = await langflow.export_flow(langflow_flow_id)
|
|
flow_name = name or exported.get("name") or f"langflow-{langflow_flow_id}"
|
|
langflow_json = {
|
|
"id": exported.get("id", langflow_flow_id),
|
|
"name": flow_name,
|
|
"description": exported.get("description") or "",
|
|
"endpoint_name": exported.get("endpoint_name"),
|
|
"data": exported.get("data", {}),
|
|
"tags": exported.get("tags", []),
|
|
"webhook": exported.get("webhook", False),
|
|
"is_component": exported.get("is_component", False),
|
|
}
|
|
path = export.write_flow_file(settings.flows_dir, langflow_json, name=flow_name)
|
|
definition, version, _action = await sync.sync_document(
|
|
session,
|
|
lfx,
|
|
langflow_json,
|
|
source_filename=path.name,
|
|
author=author,
|
|
deploy=deploy,
|
|
)
|
|
assert version is not None # sync_document always versions on import
|
|
return definition, version
|