Files
Alessandro Frau ef2dede77f Extend migration utility scope and previews
Detect populated Hermes boards and link to the Welcome Kanban Plugin Hub card when the plugin is missing.

Reuse the reviewed snapshots to import each board into its own Agent Zero project. Preserve custom lists and worker profile overrides through Welcome Kanban and reuse the same import receipts on retry.
2026-11-30 19:04:15 +01:00

38 lines
1.5 KiB
Python

from __future__ import annotations
from flask import session
from helpers import plugins
from helpers.api import ApiHandler, Input, Output, Request, Response
from plugins._migrate_agents.helpers.kanban import stage_kanban
from plugins._migrate_agents.helpers.migration import MAX_TOTAL_BYTES, Upload, parse_bundle, preview
def uploaded_files(request: Request) -> list[Upload]:
result: list[Upload] = []
total = 0
for item in request.files.getlist("files[]"):
data = item.stream.read(MAX_TOTAL_BYTES + 1)
total += len(data)
if total > MAX_TOTAL_BYTES:
raise ValueError("Upload exceeds the 256 MiB limit")
result.append(Upload(item.filename or "upload", data))
if not result:
raise ValueError("Choose at least one export file or folder")
return result
class MigrationPreview(ApiHandler):
async def process(self, input: Input, request: Request) -> Output:
try:
source = str(request.form.get("source") or "").strip().lower()
bundle = parse_bundle(source, uploaded_files(request))
result = preview(bundle)
if kanban := result["kanban"]:
kanban["installed"] = plugins.find_plugin_dir("welcome_kanban") is not None
if kanban["installed"]:
kanban["token"] = stage_kanban(session["csrf_token"], bundle.kanban_boards)
return result
except ValueError as exc:
return Response(str(exc), 400)