agent-zero/plugins/_migrate_agents/api/migration_preview.py
Alessandro 7129e287c3 Add built-in Migrate Agents plugin
Bundle the five-harness migration workflow under the _migrate_agents namespace, including preview/import safeguards, tests, documentation, WebUI assets, and the corrected upload modal behavior.
2026-08-12 14:34:15 +02:00

27 lines
1 KiB
Python

from __future__ import annotations
from helpers.api import ApiHandler, Input, Output, Request, Response
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()
return preview(parse_bundle(source, uploaded_files(request)))
except ValueError as exc:
return Response(str(exc), 400)