Skip to content

Routes

builder_browse() async

Loads the list of Workflows available for editing.

Returns:

Name Type Description
FileResponse

The HTML file containing the list of workflows.

Source code in inference/core/interfaces/http/builder/routes.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@router.get(
    "",
    summary="Workflow Builder List",
    description="Loads the list of Workflows available for editing",
)
@with_route_exceptions
async def builder_browse():
    """
    Loads the list of Workflows available for editing.

    Returns:
        FileResponse: The HTML file containing the list of workflows.
    """
    base_path = Path(__file__).parent
    file_path = base_path / "editor.html"
    content = file_path.read_text(encoding="utf-8")
    content = content.replace("{{BUILDER_ORIGIN}}", BUILDER_ORIGIN)

    return HTMLResponse(content)

builder_edit(workflow_id) async

Loads a specific workflow for editing.

Parameters:

Name Type Description Default
workflow_id str

The ID of the workflow to be edited.

required

Returns:

Name Type Description
FileResponse

The HTML file containing the workflow editor.

Source code in inference/core/interfaces/http/builder/routes.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@router.get(
    "/edit/{workflow_id}",
    summary="Workflow Builder",
    description="Loads a specific workflow for editing",
)
@with_route_exceptions
async def builder_edit(workflow_id: str):
    """
    Loads a specific workflow for editing.

    Args:
        workflow_id (str): The ID of the workflow to be edited.

    Returns:
        FileResponse: The HTML file containing the workflow editor.
    """
    base_path = Path(__file__).parent
    file_path = base_path / "editor.html"
    content = file_path.read_text(encoding="utf-8")
    content = content.replace("{{BUILDER_ORIGIN}}", BUILDER_ORIGIN)

    return HTMLResponse(content)

builder_maybe_redirect(workflow_id) async

If the workflow_id.json file exists, redirect to /build/edit/{workflow_id}. Otherwise, redirect back to /build.

Source code in inference/core/interfaces/http/builder/routes.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
@router.get("/{workflow_id}")
@with_route_exceptions
async def builder_maybe_redirect(workflow_id: str):
    """
    If the workflow_id.json file exists, redirect to /build/edit/{workflow_id}.
    Otherwise, redirect back to /build.
    """
    # Sanitize workflow_id to prevent path traversal
    if not re.match(r"^[\w\-]+$", workflow_id):
        # If it's invalid, just redirect home (or raise 400)
        return RedirectResponse(url="/build", status_code=302)

    file_path = workflow_local_dir / f"{workflow_id}.json"
    if file_path.exists():
        return RedirectResponse(url=f"/build/edit/{workflow_id}", status_code=302)
    else:
        return RedirectResponse(url="/build", status_code=302)

get_all_workflows() async

Returns JSON info about all .json files in {MODEL_CACHE_DIR}/workflow/local.

Source code in inference/core/interfaces/http/builder/routes.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
@router.get("/api")
@with_route_exceptions
async def get_all_workflows():
    """
    Returns JSON info about all .json files in {MODEL_CACHE_DIR}/workflow/local.
    """
    data = {}
    for json_file in workflow_local_dir.glob("*.json"):
        stat_info = json_file.stat()
        try:
            with json_file.open("r", encoding="utf-8") as f:
                config_contents = json.load(f)
        except json.JSONDecodeError as e:
            logger.error(f"Error decoding JSON from {json_file}: {e}")
            continue

        data[json_file.stem] = {
            "createTime": int(stat_info.st_ctime),
            "updateTime": int(stat_info.st_mtime),
            "config": config_contents,
        }

    return Response(
        content=json.dumps({"data": data}, indent=4),
        media_type="application/json",
        status_code=200,
    )

get_workflow(workflow_id) async

Return JSON for workflow_id.json, or { "error": "not found" } with 404 if missing.

Source code in inference/core/interfaces/http/builder/routes.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
@router.get("/api/{workflow_id}")
@with_route_exceptions
async def get_workflow(workflow_id: str):
    """
    Return JSON for workflow_id.json, or { "error": "not found" } with 404 if missing.
    """
    if not re.match(r"^[\w\-]+$", workflow_id):
        return JSONResponse({"error": "invalid id"}, status_code=HTTP_400_BAD_REQUEST)

    file_path = workflow_local_dir / f"{workflow_id}.json"
    if not file_path.exists():
        # Return the structure you specifically asked for
        return JSONResponse({"error": "not found"}, status_code=HTTP_404_NOT_FOUND)

    stat_info = file_path.stat()
    try:
        with file_path.open("r", encoding="utf-8") as f:
            config_contents = json.load(f)
    except json.JSONDecodeError as e:
        logger.error(f"Error reading JSON from {file_path}: {e}")
        # You can also do a 400 or 500 if you prefer:
        return JSONResponse({"error": "invalid JSON"}, status_code=500)

    return Response(
        content=json.dumps(
            {
                "data": {
                    "createTime": int(stat_info.st_ctime),
                    "updateTime": int(stat_info.st_mtime),
                    "config": config_contents,
                }
            },
            indent=4,
        ),
        media_type="application/json",
        status_code=200,
    )