✨ Add explicit multiport Fanyu contracts

This commit is contained in:
eust-w 2026-08-22 19:46:05 +08:00
parent 961f439b3d
commit a9d00279cc
33 changed files with 2550 additions and 73 deletions

View File

@ -6,7 +6,7 @@ from typing import Any, Callable
HelperMap = dict[str, Callable[..., Any]]
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: Any,
@ -42,3 +42,65 @@ def run(
output=helpers["output_binding"](node_data),
)
]
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
params = helpers["hyperparams"](node_data)
template_id = params.get("ANNOTATION_TEMPLATE_ID", "").strip()
workgroup_id = params.get("ANNOTATION_WORKGROUP_ID", "").strip()
if not template_id or not workgroup_id:
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID 和 ANNOTATION_WORKGROUP_ID")
clips = [item for item in inputs if str(item.get("portId") or item.get("portName") or "") == "clips" or str(item.get("type", "")) == "video"]
if not clips:
raise RuntimeError("原生视频标注 Gate 多端口路径需要 clips 视频集合")
for clip in clips:
clip["portId"] = str((_output(node_data, helpers, "approvedVideos") or {}).get("id", ""))
clip["portName"] = str((_output(node_data, helpers, "approvedVideos") or {}).get("name", ""))
payloads = helpers["payloads_from_inputs"](inputs)
prelabels = []
boundaries = []
for payload in payloads:
if isinstance(payload.get("items"), list):
prelabels.extend(payload["items"])
if isinstance(payload.get("boundaries"), list):
boundaries.extend(payload["boundaries"])
write = helpers["write_json_artifact"]
annotations = {
"datasetType": "annotation-gate-input",
"templateId": template_id,
"workgroupId": workgroup_id,
"itemCount": len(clips),
"items": prelabels,
}
rejected = {"datasetType": "annotation-gate-rejected", "itemCount": 0, "items": []}
summary = {"clipCount": len(clips), "prelabelCount": len(prelabels), "boundaryCount": len(boundaries), "templateId": template_id, "workgroupId": workgroup_id}
return [
*clips,
write(run_id, node_id, output_dir, "annotation-gate-annotations-dataset.json", annotations, output=_output(node_data, helpers, "annotations")),
write(run_id, node_id, output_dir, "annotation-gate-rejected-dataset.json", rejected, output=_output(node_data, helpers, "rejected")),
write(run_id, node_id, output_dir, "annotation-gate-aggregate-summary.json", summary, output=_output(node_data, helpers, "aggregateSummary")),
]
def run(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "approvedVideos") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -7,6 +7,8 @@ from typing import Any, Callable
HelperMap = dict[str, Callable[..., Any]]
VIDEO_SUFFIXES = {".mp4", ".mov", ".m4v", ".avi", ".mkv", ".webm"}
IMAGE_SUFFIXES = {".jpg", ".jpeg", ".png", ".bmp", ".webp", ".gif"}
def _directory_ref(inputs: list[dict[str, Any]]) -> tuple[str, str] | None:
@ -73,7 +75,7 @@ def _bos_entries(
return entries
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: Any,
@ -152,3 +154,138 @@ def run(
output=helpers["output_binding"](node_data),
)
]
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _entry_path(entry: dict[str, Any], bucket: str = "", prefix: str = "", helpers: HelperMap | None = None) -> str:
source = entry.get("source") if isinstance(entry.get("source"), dict) else {}
raw = str(source.get("path") or entry.get("path") or entry.get("relativePath") or entry.get("name") or "").strip()
if raw.startswith("bos://") or not bucket:
return raw
relative = raw.lstrip("/")
combined = "/".join(part for part in (prefix.strip("/"), relative) if part)
if helpers is not None:
return str(helpers["canonical_bos_path"](bucket, combined))
return f"bos://{bucket}/{combined}"
def _directory_input(inputs: list[dict[str, Any]]) -> dict[str, Any] | None:
for artifact in inputs:
payload = artifact.get("payload") if isinstance(artifact.get("payload"), dict) else {}
ref = payload.get("ref") if isinstance(payload.get("ref"), dict) else {}
if str(ref.get("kind", "")).strip().lower() == "directory":
return artifact
return None
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
params = helpers["hyperparams"](node_data)
pattern = str(params.get("PATTERN", "")).strip()
directory_input = _directory_input(inputs)
bucket = ""
prefix = ""
entries: list[dict[str, Any]] = []
root_path = ""
if directory_input is not None:
payload = directory_input.get("payload") if isinstance(directory_input.get("payload"), dict) else {}
ref = payload.get("ref") if isinstance(payload.get("ref"), dict) else {}
bucket = str(ref.get("bucket", "")).strip()
prefix = str(ref.get("prefix", "")).strip().strip("/")
if bucket:
entries = _bos_entries(bucket, prefix, pattern, params, helpers)
root_path = str(helpers["canonical_bos_path"](bucket, prefix))
else:
root_path = str(directory_input.get("path", "")).strip()
if not entries and not root_path:
source_path = helpers["resolve_source_path"](params, inputs)
if source_path is None:
raise RuntimeError("目录读取需要必填目录输入或 SOURCE_PATH 指向真实目录")
root = source_path if source_path.is_dir() else source_path.parent
root_path = str(source_path)
entries = [
{
**item,
"source": {"path": str(root / pathlib.PurePosixPath(str(item.get("path", ""))))},
}
for item in helpers["list_source_entries"](root, pattern)
]
artifacts: list[dict[str, Any]] = []
directory_output = _output(node_data, helpers, "directory")
if directory_output is not None:
directory_artifact = helpers["build_virtual_artifact"](
run_id,
node_id,
"directory.index",
root_path,
"file",
sum(int(item.get("sizeBytes", 0) or 0) for item in entries),
data={"fileCount": len(entries), "datasetType": "directory"},
output=directory_output,
)
if directory_input is not None and isinstance(directory_input.get("payload"), dict):
directory_artifact["payload"] = dict(directory_input["payload"])
artifacts.append(directory_artifact)
media_outputs = {
"videos": (VIDEO_SUFFIXES, "video"),
"images": (IMAGE_SUFFIXES, "image"),
"files": (set(), "file"),
}
for output_name, (suffixes, artifact_type) in media_outputs.items():
binding = _output(node_data, helpers, output_name)
if binding is None:
continue
for entry in entries:
relative = str(entry.get("path") or entry.get("relativePath") or entry.get("name") or "").strip()
suffix = pathlib.PurePosixPath(relative).suffix.lower()
if output_name == "files":
if suffix in VIDEO_SUFFIXES or suffix in IMAGE_SUFFIXES:
continue
elif suffix not in suffixes:
continue
artifacts.append(
helpers["build_virtual_artifact"](
run_id,
node_id,
pathlib.PurePosixPath(relative).name or f"{output_name}.bin",
_entry_path(entry, bucket, prefix, helpers),
artifact_type,
int(entry.get("sizeBytes", 0) or 0),
data={"collectionId": pathlib.PurePosixPath(relative).parts[0] if pathlib.PurePosixPath(relative).parts else "", "relativeName": pathlib.PurePosixPath(relative).name},
output=binding,
)
)
summary = {
"fileCount": len(entries),
"videoCount": sum(1 for item in entries if pathlib.PurePosixPath(str(item.get("path") or item.get("name") or "")).suffix.lower() in VIDEO_SUFFIXES),
"imageCount": sum(1 for item in entries if pathlib.PurePosixPath(str(item.get("path") or item.get("name") or "")).suffix.lower() in IMAGE_SUFFIXES),
"totalBytes": sum(int(item.get("sizeBytes", 0) or 0) for item in entries),
"dataSource": "BOS" if bucket else "FILESYSTEM",
}
artifacts.append(helpers["write_json_artifact"](run_id, node_id, output_dir, "directory-summary.json", summary, output=_output(node_data, helpers, "summary")))
return artifacts
def run(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "directory") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -2,6 +2,8 @@ from __future__ import annotations
import pathlib
import re
import os
import json
from typing import Any, Callable
@ -28,7 +30,7 @@ def _camera_side(path: str) -> str:
return matched.group("side").lower() if matched else ""
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: Any,
@ -129,3 +131,148 @@ def run(
output=helpers["output_binding"](node_data),
)
]
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _entry_source_path(entry: dict[str, Any], source_path: str) -> str:
source = entry.get("source") if isinstance(entry.get("source"), dict) else {}
value = str(source.get("path") or entry.get("path") or entry.get("relativePath") or "").strip()
if value.startswith("bos://") or not source_path.startswith("bos://"):
return value
return source_path.rstrip("/") + "/" + value.lstrip("/")
def _directory_entries(inputs: list[dict[str, Any]], helpers: HelperMap) -> tuple[list[dict[str, Any]], str]:
for artifact in inputs:
data = artifact.get("data") if isinstance(artifact.get("data"), dict) else {}
if isinstance(data.get("entries"), list):
return [item for item in data["entries"] if isinstance(item, dict)], str(data.get("sourcePath", ""))
for artifact in inputs:
payload = artifact.get("payload") if isinstance(artifact.get("payload"), dict) else {}
ref = payload.get("ref") if isinstance(payload.get("ref"), dict) else {}
if str(ref.get("kind", "")).strip().lower() != "directory":
continue
bucket = str(ref.get("bucket", "")).strip()
prefix = str(ref.get("prefix", "")).strip().strip("/")
if bucket:
endpoint = os.getenv("BOS_ENDPOINT", "").strip()
access_key_id = os.getenv("BOS_ACCESS_KEY_ID", "").strip()
secret_access_key = os.getenv("BOS_SECRET_ACCESS_KEY", "").strip()
if not endpoint or not access_key_id or not secret_access_key:
raise RuntimeError("Orbbec 多端口标准化需要目录引用对应的 BOS 凭证")
entries = helpers["list_bos_entries"](bucket, prefix, "", endpoint, access_key_id, secret_access_key)
source_path = str(helpers["canonical_bos_path"](bucket, prefix))
return [
{
**item,
"source": {"path": _entry_source_path(item, source_path)},
}
for item in entries
if isinstance(item, dict)
], source_path
local_path = pathlib.Path(str(artifact.get("path", "")).strip())
if local_path.exists():
root = local_path if local_path.is_dir() else local_path.parent
entries = helpers["list_source_entries"](root, "")
return [
{
**item,
"source": {"path": str(root / pathlib.PurePosixPath(str(item.get("path", ""))))},
}
for item in entries
if isinstance(item, dict)
], str(local_path)
return [], ""
def _paired_source_path(value: str, source_path: str) -> str:
if not value:
return ""
if value.startswith("bos://") or not source_path.startswith("bos://"):
return value
return source_path.rstrip("/") + "/" + value.lstrip("/")
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
entries, source_path = _directory_entries(inputs, helpers)
if not entries:
raise RuntimeError("Orbbec Ego 数据标准化需要 directory/dataset 引用或 legacy entries")
synthetic_inputs = [{"name": "directory-technical-index.json", "data": {"entries": entries, "sourcePath": source_path}}, *inputs]
_run_legacy(run_id, node_id, output_dir, node_data, synthetic_inputs, helpers)
manifest_path = pathlib.Path(output_dir) / "orbbec-normalized-manifest.json"
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
artifacts: list[dict[str, Any]] = []
seen_files: set[tuple[str, str]] = set()
for item in manifest.get("items", []):
if not isinstance(item, dict):
continue
side = str(item.get("cameraSide", "")).strip().lower()
output_name = "leftVideos" if side == "left" else "rightVideos" if side == "right" else ""
binding = _output(node_data, helpers, output_name)
source = item.get("source") if isinstance(item.get("source"), dict) else {}
video_path = str(source.get("path") or item.get("path") or "")
if binding is not None and video_path:
artifacts.append(
helpers["build_virtual_artifact"](
run_id,
node_id,
str(item.get("filename") or pathlib.PurePosixPath(video_path).name),
video_path,
"video",
int(item.get("sizeBytes", 0) or 0),
data={"collectionId": item.get("collectionId", ""), "cameraSide": side},
output=binding,
)
)
paired = item.get("pairedFiles") if isinstance(item.get("pairedFiles"), dict) else {}
for pair_key, output_name in (("pts", "videoPts"), ("audio", "audio"), ("imu", "imu"), ("cameraCalibration", "calibrations"), ("imuCalibration", "calibrations")):
pair = _paired_source_path(str(paired.get(pair_key, "")).strip(), source_path)
binding = _output(node_data, helpers, output_name)
key = (output_name, pair)
if not pair or binding is None or key in seen_files:
continue
seen_files.add(key)
artifacts.append(
helpers["build_virtual_artifact"](
run_id,
node_id,
pathlib.PurePosixPath(pair).name,
pair,
"file",
0,
data={"role": pair_key, "collectionId": item.get("collectionId", "")},
output=binding,
)
)
summary = {
"collectionCount": int(manifest.get("collectionCount", 0) or 0),
"videoCount": int(manifest.get("videoCount", 0) or 0),
"leftVideoCount": sum(1 for item in manifest.get("items", []) if isinstance(item, dict) and item.get("cameraSide") == "left"),
"rightVideoCount": sum(1 for item in manifest.get("items", []) if isinstance(item, dict) and item.get("cameraSide") == "right"),
"datasetType": "orbbec-ego",
}
artifacts.append(helpers["write_json_artifact"](run_id, node_id, output_dir, "orbbec-normalize-summary.json", summary, output=_output(node_data, helpers, "summary")))
return artifacts
def run(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "leftVideos") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -349,8 +349,85 @@ def _run_legacy(run_id: str, node_id: str, output_dir: Any, node_data: dict[str,
return artifacts
def run(run_id: str, node_id: str, output_dir: Any, node_data: dict[str, Any], inputs: list[dict[str, Any]], helpers: HelperMap) -> list[dict[str, Any]]:
def _run_existing_contract(run_id: str, node_id: str, output_dir: Any, node_data: dict[str, Any], inputs: list[dict[str, Any]], helpers: HelperMap) -> list[dict[str, Any]]:
params = helpers["hyperparams"](node_data)
if not _bool(params, "REQUIRE_FINAL_ACCEPTANCE", False) and not _bool(params, "GENERATE_SEGMENT_MP4", False):
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_fanyu_v5(run_id, node_id, output_dir, node_data, inputs, helpers)
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _port(artifact: dict[str, Any]) -> str:
return str(artifact.get("portId") or artifact.get("portName") or "").strip()
def _materialize_annotation_payload(artifact: dict[str, Any], output: pathlib.Path, helpers: HelperMap) -> dict[str, Any]:
data = artifact.get("data") if isinstance(artifact.get("data"), dict) else {}
if isinstance(data.get("items"), list):
return data
materialize = helpers.get("source_path_from_item")
source_ref = helpers.get("source_ref_from_artifact")
if not callable(materialize):
raise RuntimeError("成品打包无法物化 annotations 引用")
source = source_ref(artifact) if callable(source_ref) else {}
path = materialize({"path": str(artifact.get("path", "")), "source": source if isinstance(source, dict) else {}}, str(artifact.get("name", "annotations.json")), output, {})
decoded = json.loads(pathlib.Path(path).read_text(encoding="utf-8"))
if not isinstance(decoded, dict) or not isinstance(decoded.get("items"), list):
raise RuntimeError("annotations 引用不是可打包的 accepted annotation collection")
return decoded
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
output = pathlib.Path(output_dir)
approved = [item for item in inputs if _port(item) == "approvedVideos" or str(item.get("type", "")) == "video"]
annotation_artifact = next((item for item in inputs if _port(item) == "annotations"), None)
if not approved or annotation_artifact is None:
# A newly published package image must still execute historical graphs
# that supply one legacy annotations/manifest input.
return _run_existing_contract(run_id, node_id, output_dir, node_data, inputs, helpers)
accepted = _materialize_annotation_payload(annotation_artifact, output, helpers)
# Existing precise Fanyu packager owns ffmpeg cutting and acceptance
# validation. Feed it a local technical adapter only; business outputs are
# rebound below by their real media/file role.
_run_fanyu_v5(run_id, node_id, output, node_data, [{"name": "accepted-annotations-index.json", "data": accepted}, *approved], helpers)
packages_root = output / "packages"
package_binding = _output(node_data, helpers, "packageDirectory")
result: list[dict[str, Any]] = []
if package_binding is not None:
result.append(helpers["build_virtual_artifact"](run_id, node_id, "delivery-package-directory", str(packages_root), "file", 0, data={"packageCount": len([path for path in packages_root.iterdir() if path.is_dir()])}, output=package_binding))
files = helpers["collect_output_artifacts"](run_id, node_id, packages_root, node_data=node_data)
for artifact in files:
name = str(artifact.get("name", "")).lower()
binding = None
if name.endswith(".mp4"):
binding = _output(node_data, helpers, "finalVideos")
elif name == "semantic.json" or name.endswith("_annotation.json"):
binding = _output(node_data, helpers, "semanticFiles")
elif name == "segment.json" or name.endswith("_segment.json"):
binding = _output(node_data, helpers, "segmentFiles")
if binding is None:
continue
artifact["portId"] = str(binding.get("id", ""))
artifact["portName"] = str(binding.get("name", ""))
result.append(artifact)
manifest_path = output / "packages-manifest.json"
manifest = json.loads(manifest_path.read_text(encoding="utf-8")) if manifest_path.exists() else {}
summary = {"packageCount": int(manifest.get("packageCount", 0) or 0), "trainingEnabled": False, "poseFree": True, "finalAcceptanceRequired": _bool(helpers["hyperparams"](node_data), "REQUIRE_FINAL_ACCEPTANCE", False)}
result.append(helpers["write_json_artifact"](run_id, node_id, output, "delivery-summary.json", summary, output=_output(node_data, helpers, "deliverySummary")))
return result
def run(run_id: str, node_id: str, output_dir: Any, node_data: dict[str, Any], inputs: list[dict[str, Any]], helpers: HelperMap) -> list[dict[str, Any]]:
if _output(node_data, helpers, "packageDirectory") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_existing_contract(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -813,7 +813,7 @@ def _source_contexts(
return contexts
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: Any,
@ -1150,3 +1150,105 @@ def run(
write(run_id, node_id, output, "clips-manifest.json", manifest, output=binding if isinstance(binding, dict) else None),
*virtual_artifacts,
]
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
binding_fn = helpers.get("output_binding")
return binding_fn(node_data, name=name) if callable(binding_fn) else None
def _port(artifact: dict[str, Any]) -> str:
return str(artifact.get("portId") or artifact.get("portName") or "").strip()
def _multiport_inputs(inputs: list[dict[str, Any]]) -> list[dict[str, Any]]:
videos = [item for item in inputs if _port(item) == "videos" or pathlib.PurePosixPath(str(item.get("name", ""))).suffix.lower() in VIDEO_SUFFIXES]
timestamps = [item for item in inputs if _port(item) == "timestamps" or str(item.get("name", "")).lower().endswith("_pts.csv")]
if not videos:
raise RuntimeError("Qwen 行为粗切多端口路径需要 videos 视频集合")
pts_by_stem = {
pathlib.PurePosixPath(str(item.get("name", ""))).stem.removesuffix("_pts"): item
for item in timestamps
if str(item.get("name", ""))
}
blur_items: list[dict[str, Any]] = []
for artifact in videos:
sanitized = _basename(artifact.get("name") or artifact.get("path"))
original = sanitized[len("blurred_") :] if sanitized.startswith("blurred_") else sanitized
pts = pts_by_stem.get(pathlib.PurePosixPath(original).stem)
blur_items.append(
{
"sanitizedFilename": sanitized,
"filename": sanitized,
"sourceVideo": original,
"sanitizedVideoPath": str(artifact.get("path", "")),
"pairedFiles": {"pts": str(pts.get("path", "")) if isinstance(pts, dict) else ""},
}
)
return [
{"name": "multiport-blur-technical-index.json", "data": {"schemaVersion": "droboticflow.video_face_blur.manifest/v1", "items": blur_items}},
{"name": "multiport-orbbec-technical-index.json", "data": {"schemaVersion": "droboticflow.orbbec.normalized/v1", "datasetType": "orbbec-ego", "entries": []}},
*inputs,
]
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
artifacts = _run_legacy(run_id, node_id, output_dir, node_data, _multiport_inputs(inputs), helpers)
manifest_path = pathlib.Path(output_dir) / "clips-manifest.json"
if not manifest_path.exists():
raise RuntimeError("Qwen 行为粗切没有写入技术 clips manifest")
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
clips_binding = _output(node_data, helpers, "clips")
result: list[dict[str, Any]] = []
for artifact in artifacts:
if pathlib.PurePosixPath(str(artifact.get("name", ""))).suffix.lower() not in VIDEO_SUFFIXES:
continue
if clips_binding is not None:
artifact["portId"] = str(clips_binding.get("id", ""))
artifact["portName"] = str(clips_binding.get("name", ""))
result.append(artifact)
clip_items = [item for item in manifest.get("items", []) if isinstance(item, dict)]
prelabels = {
"datasetType": "qwen3vl-rough-prelabels",
"clipCount": len(clip_items),
"items": [item.get("annotation", {}) for item in clip_items],
}
boundaries = {
"clipCount": len(clip_items),
"boundaries": [
{"clipId": item.get("clipId", ""), "startSecond": item.get("startSecond"), "endSecond": item.get("endSecond"), "rawPTS": item.get("rawPTS", {})}
for item in clip_items
],
}
summary = {
"clipCount": len(clip_items),
"rawBehaviorEventCount": len(manifest.get("rawBehaviorEvents", []) if isinstance(manifest.get("rawBehaviorEvents"), list) else []),
"technicalBlockCount": len(manifest.get("technicalBlocks", []) if isinstance(manifest.get("technicalBlocks"), list) else []),
"model": str((manifest.get("provenance") or {}).get("modelId", "")) if isinstance(manifest.get("provenance"), dict) else "",
"timeSource": "PTS_US overlay",
}
write = helpers["write_json_artifact"]
result.append(write(run_id, node_id, output_dir, "rough-prelabels-dataset.json", prelabels, output=_output(node_data, helpers, "prelabels")))
result.append(write(run_id, node_id, output_dir, "rough-boundaries.json", boundaries, output=_output(node_data, helpers, "boundaries")))
result.append(write(run_id, node_id, output_dir, "rough-inference-summary.json", summary, output=_output(node_data, helpers, "inferenceSummary")))
return result
def run(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "clips") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -267,7 +267,7 @@ def _process_video_stream(
}
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: pathlib.Path,
@ -475,3 +475,89 @@ def run(
helpers["collect_output_artifacts"](run_id, node_id, output_blurred_dir, node_data=node_data, output=binding)
)
return artifacts
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _artifact_port(artifact: dict[str, Any]) -> str:
return str(artifact.get("portId") or artifact.get("portName") or "").strip()
def _is_video_artifact(artifact: dict[str, Any]) -> bool:
return str(artifact.get("type", "")).lower() == "video" or pathlib.PurePosixPath(str(artifact.get("name", ""))).suffix.lower() in VIDEO_SUFFIXES
def _run_multiport(
run_id: str,
node_id: str,
output_dir: pathlib.Path,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
videos = [artifact for artifact in inputs if _artifact_port(artifact) == "videos" or _is_video_artifact(artifact)]
timestamps = [artifact for artifact in inputs if _artifact_port(artifact) == "timestamps" or str(artifact.get("name", "")).lower().endswith("_pts.csv")]
if not videos:
raise RuntimeError("视频人脸脱敏多端口路径需要 videos 视频集合")
timestamp_by_stem = {
pathlib.PurePosixPath(str(item.get("name", ""))).stem.removesuffix("_pts"): item
for item in timestamps
if str(item.get("name", ""))
}
items: list[dict[str, Any]] = []
for artifact in videos:
name = str(artifact.get("name", "")).strip() or "video.mp4"
stem = pathlib.PurePosixPath(name).stem.removeprefix("blurred_")
pts = timestamp_by_stem.get(stem)
items.append(
{
"filename": name,
"path": str(artifact.get("path", "")),
"source": {"path": str(artifact.get("path", ""))},
"sizeBytes": int(artifact.get("sizeBytes", 0) or 0),
"pairedFiles": {"pts": str(pts.get("path", "")) if isinstance(pts, dict) else ""},
}
)
synthetic_inputs = [{"name": "multiport-videos-adapter.json", "data": {"datasetType": "video-collection", "items": items}}, *inputs]
legacy_artifacts = _run_legacy(run_id, node_id, output_dir, node_data, synthetic_inputs, helpers)
video_binding = _output(node_data, helpers, "blurredVideos")
output: list[dict[str, Any]] = []
for artifact in legacy_artifacts:
if not _is_video_artifact(artifact):
continue
if video_binding is not None:
artifact["portId"] = str(video_binding.get("id", ""))
artifact["portName"] = str(video_binding.get("name", ""))
output.append(artifact)
manifest_path = output_dir / "blurred-manifest.json"
manifest: dict[str, Any] = {}
if manifest_path.exists():
try:
import json
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
except Exception:
manifest = {}
summary = {
"itemCount": int(manifest.get("itemCount", len(output)) or len(output)),
"totalFramesProcessed": int(manifest.get("totalFramesProcessed", 0) or 0),
"totalFacesDetected": int(manifest.get("totalFacesDetected", 0) or 0),
"detectionMethod": str((manifest.get("method") or {}).get("detectionMethod", "")) if isinstance(manifest.get("method"), dict) else "",
"preservePts": bool((manifest.get("method") or {}).get("preservePts", False)) if isinstance(manifest.get("method"), dict) else False,
}
output.append(helpers["write_json_artifact"](run_id, node_id, output_dir, "face-blur-summary.json", summary, output=_output(node_data, helpers, "detectionSummary")))
return output
def run(
run_id: str,
node_id: str,
output_dir: pathlib.Path,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "blurredVideos") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -55,6 +55,9 @@ type GeneratedWorkflow struct {
type GeneratedOperatorPort struct {
Name string `json:"name"`
Type string `json:"type"`
Container string `json:"container,omitempty"`
PayloadMode string `json:"payloadMode,omitempty"`
Role string `json:"role,omitempty"`
Transmission string `json:"transmission"`
Description string `json:"description,omitempty"`
}
@ -328,6 +331,9 @@ func (client *client) GenerateWorkflow(ctx context.Context, description string,
type portContext struct {
Name string `json:"name"`
Type string `json:"type"`
Container string `json:"container,omitempty"`
PayloadMode string `json:"payloadMode,omitempty"`
Role string `json:"role,omitempty"`
Transmission string `json:"transmission,omitempty"`
}
type hyperparamContext struct {
@ -353,6 +359,9 @@ func (client *client) GenerateWorkflow(ctx context.Context, description string,
inputs = append(inputs, portContext{
Name: strings.TrimSpace(port.Name),
Type: string(port.Type),
Container: string(domain.EffectivePortContract(port).Container),
PayloadMode: string(domain.EffectivePortContract(port).PayloadMode),
Role: strings.TrimSpace(port.Role),
Transmission: strings.TrimSpace(port.Transmission),
})
}
@ -361,6 +370,9 @@ func (client *client) GenerateWorkflow(ctx context.Context, description string,
outputs = append(outputs, portContext{
Name: strings.TrimSpace(port.Name),
Type: string(port.Type),
Container: string(domain.EffectivePortContract(port).Container),
PayloadMode: string(domain.EffectivePortContract(port).PayloadMode),
Role: strings.TrimSpace(port.Role),
Transmission: strings.TrimSpace(port.Transmission),
})
}
@ -489,12 +501,12 @@ func (client *client) GenerateOperator(ctx context.Context, description string)
systemPrompt := strings.TrimSpace(`
You are a Drobodata operator designer. Return one compact JSON object only, no markdown, no reasoning, no explanations. Keep skillDefinition under 600 Chinese chars and hyperparams under 10 items.
Allowed categories: IO, CV, AI, MATH, HUMAN, FLOW. Allowed port types: json, image, video, tensor, file. Allowed transmission values: bus, oss, shm, stream.
Allowed categories: IO, CV, AI, MATH, HUMAN, FLOW. Allowed port types: json, image, video, tensor, file. Port containers: single, collection, directory, dataset. Payload modes: inline, ref. Role is optional semantic metadata (video, pts, audio, imu, calibration, annotation, boundary, summary), never a transport type. Allowed legacy transmission values: bus, oss, shm, stream.
Design a production-ready external container operator contract, not just a card label.
Use oss transmission for video/file artifacts, stream for tensors, bus only for compact JSON.
Use ref for external/video/file/collection/directory/dataset artifacts and inline only for compact single JSON. Transmission is compatibility-only; prefer explicit container and payloadMode.
Leave image and imageId empty unless the user explicitly provided a registry image or digest; never invent a built image.
Add enough typed hyperparams and resource defaults for a real K8s Job. Hyperparam value must always be a string.
Schema: {"name":"short operator name","category":"AI|IO|CV|MATH|HUMAN|FLOW","description":"1 sentence","version":"v1.0.0","image":"optional existing registry image","imageId":"optional digest image","containerCommand":["python","/app/src/operator.py"],"containerArgs":[],"resources":{"cpuRequest":"500m","cpuLimit":"2","memoryRequest":"1Gi","memoryLimit":"4Gi","gpuType":"","gpuLimit":"","sharedMemorySize":"optional Kubernetes quantity such as 8Gi"},"runtimeContract":{"protocol":"droboticflow.external-operator/v1","implementationStatus":"requires-build-and-registry-push"},"inputs":[{"name":"input","type":"json|image|video|tensor|file","transmission":"bus|oss|shm|stream","description":"optional"}],"outputs":[{"name":"result","type":"json|image|video|tensor|file","transmission":"bus|oss|shm|stream","description":"optional"}],"hyperparams":[{"key":"ENV_KEY","value":"default","type":"string|number|integer|boolean|path|json","description":"what it controls"}],"skillDefinition":"detailed usage, inputs, outputs, limits, failure modes, acceptance"}`)
Schema: {"name":"short operator name","category":"AI|IO|CV|MATH|HUMAN|FLOW","description":"1 sentence","version":"v1.0.0","image":"optional existing registry image","imageId":"optional digest image","containerCommand":["python","/app/src/operator.py"],"containerArgs":[],"resources":{"cpuRequest":"500m","cpuLimit":"2","memoryRequest":"1Gi","memoryLimit":"4Gi","gpuType":"","gpuLimit":"","sharedMemorySize":"optional Kubernetes quantity such as 8Gi"},"runtimeContract":{"protocol":"droboticflow.external-operator/v1","implementationStatus":"requires-build-and-registry-push"},"inputs":[{"name":"input","type":"json|image|video|tensor|file","container":"single|collection|directory|dataset","payloadMode":"inline|ref","role":"optional semantic role","transmission":"bus|oss|shm|stream","description":"optional"}],"outputs":[{"name":"result","type":"json|image|video|tensor|file","container":"single|collection|directory|dataset","payloadMode":"inline|ref","role":"optional semantic role","transmission":"bus|oss|shm|stream","description":"optional"}],"hyperparams":[{"key":"ENV_KEY","value":"default","type":"string|number|integer|boolean|path|json","description":"what it controls"}],"skillDefinition":"detailed usage, inputs, outputs, limits, failure modes, acceptance"}`)
var generated GeneratedOperator
if err := client.generateJSON(ctx, systemPrompt, strings.TrimSpace(description), operatorMaxTokens, &generated); err != nil {
@ -614,11 +626,24 @@ func normalizeGeneratedPorts(ports []GeneratedOperatorPort) {
for index := range ports {
ports[index].Name = strings.TrimSpace(ports[index].Name)
ports[index].Type = strings.ToLower(strings.TrimSpace(ports[index].Type))
ports[index].Container = strings.ToLower(strings.TrimSpace(ports[index].Container))
ports[index].PayloadMode = strings.ToLower(strings.TrimSpace(ports[index].PayloadMode))
ports[index].Role = strings.ToLower(strings.TrimSpace(ports[index].Role))
ports[index].Transmission = strings.ToLower(strings.TrimSpace(ports[index].Transmission))
ports[index].Description = strings.TrimSpace(ports[index].Description)
if ports[index].Transmission == "" {
ports[index].Transmission = defaultTransmissionForPortType(ports[index].Type)
}
if ports[index].Container == "" {
ports[index].Container = "single"
}
if ports[index].PayloadMode == "" {
if ports[index].Type == "json" && ports[index].Container == "single" {
ports[index].PayloadMode = "inline"
} else {
ports[index].PayloadMode = "ref"
}
}
}
}
@ -1719,6 +1744,12 @@ func validateGeneratedPorts(ports []GeneratedOperatorPort) error {
if !validPortType(port.Type) {
return fmt.Errorf("unsupported port type %q", port.Type)
}
if !domain.ValidPortContainer(domain.PortContainer(strings.ToLower(strings.TrimSpace(port.Container)))) {
return fmt.Errorf("unsupported port container %q", port.Container)
}
if !domain.ValidPortPayloadMode(domain.ArtifactTransferMode(strings.ToLower(strings.TrimSpace(port.PayloadMode)))) {
return fmt.Errorf("unsupported port payload mode %q", port.PayloadMode)
}
if !validTransmission(port.Transmission) {
return fmt.Errorf("unsupported transmission %q", port.Transmission)
}

View File

@ -83,9 +83,23 @@ func TestBuiltinCatalogIncludesNativeAnnotationGateContract(t *testing.T) {
if item == nil {
t.Fatal("expected native annotation gate in builtin catalog")
}
if item.Category != "HUMAN" || len(item.Inputs) != 5 || len(item.Outputs) != 2 {
if item.Category != "HUMAN" || len(item.Inputs) != 3 || len(item.Outputs) != 4 {
t.Fatalf("unexpected annotation gate ports: %#v", item)
}
for _, portID := range []string{"clips", "prelabels", "boundaries", "approvedVideos", "annotations", "rejected", "aggregateSummary"} {
found := false
for _, port := range append(append([]domain.PortDefinition{}, item.Inputs...), item.Outputs...) {
if port.ID == portID {
found = true
if port.Container == "" || port.PayloadMode == "" {
t.Fatalf("annotation gate port %s lacks explicit contract: %#v", portID, port)
}
}
}
if !found {
t.Fatalf("annotation gate port %s is missing", portID)
}
}
keys := map[string]bool{}
for _, hyperparam := range item.Hyperparams {
keys[hyperparam.Key] = true

View File

@ -16,8 +16,50 @@ const fanyuOrbbecDeliveryTemplateID = "template-fanyu-right-camera-delivery-v2-o
const fanyuDeliveryTemplateV3ID = "template-fanyu-right-camera-delivery-v3"
const fanyuDeliveryTemplateV4ID = "template-fanyu-right-camera-delivery-v4"
const fanyuDeliveryTemplateV5ID = "template-fanyu-left-camera-delivery-v5"
const fanyuDeliveryTemplateV54ID = "template-fanyu-left-camera-delivery-v5-4"
func fanyuLegacyPorts(operatorID string, inputs []domain.PortDefinition, outputs []domain.PortDefinition) ([]domain.PortDefinition, []domain.PortDefinition) {
legacy := func(id, name string, typ domain.PortType, required bool) domain.PortDefinition {
return domain.PortDefinition{ID: id, Name: name, Type: typ, Required: required, Transmission: "bus"}
}
switch operatorID {
case "operator-builtin-directory-scan":
return []domain.PortDefinition{legacy("in-1", "input", domain.PortTypeFile, true)}, []domain.PortDefinition{legacy("out-1", "manifest", domain.PortTypeJSON, false)}
case "operator-builtin-orbbec-data-normalize":
return []domain.PortDefinition{legacy("in-1", "input", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("out-1", "dataset", domain.PortTypeJSON, false)}
case "operator-builtin-video-face-blur":
return []domain.PortDefinition{legacy("in-1", "input", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("out-1", "blurredVideo", domain.PortTypeJSON, false)}
case "operator-builtin-qwen-behavior-rough-cut":
return []domain.PortDefinition{legacy("video", "video", domain.PortTypeJSON, true), legacy("metadata", "metadata", domain.PortTypeJSON, true)}, []domain.PortDefinition{legacy("out-1", "roughCuts", domain.PortTypeJSON, false)}
case "operator-builtin-annotation-gate":
return []domain.PortDefinition{legacy("clips", "clips", domain.PortTypeJSON, false), legacy("prelabels", "prelabels", domain.PortTypeJSON, false), legacy("validEvents", "validEvents", domain.PortTypeJSON, false), legacy("headpose", "headpose", domain.PortTypeJSON, false), legacy("handpose", "handpose", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("approved", "approved", domain.PortTypeJSON, false), legacy("rejected", "rejected", domain.PortTypeJSON, false)}
case "operator-builtin-package":
return []domain.PortDefinition{legacy("in-1", "annotations", domain.PortTypeJSON, true), legacy("in-2", "headpose", domain.PortTypeJSON, false), legacy("in-3", "handpose", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("out-1", "packages", domain.PortTypeJSON, false)}
default:
return inputs, outputs
}
}
func fanyuNode(id string, label string, operator domain.OperatorRecord, x float64, y float64) domain.WorkflowNode {
cpu, memory, gpu, sharedMemory := "", "", "", ""
if operator.Resources != nil {
cpu = operator.Resources.CPULimit
memory = operator.Resources.MemoryLimit
gpu = operator.Resources.GPULimit
sharedMemory = operator.Resources.SharedMemorySize
}
inputs, outputs := fanyuLegacyPorts(operator.ID, operator.Inputs, operator.Outputs)
return domain.WorkflowNode{ID: id, Type: "operator", Position: domain.Position{X: x, Y: y}, Data: domain.WorkflowNodeData{
Label: label, Category: operator.Category, Description: operator.Description, Inputs: inputs, Outputs: outputs,
OperatorID: operator.ID, OperatorVersion: operator.Version, OperatorImageID: operator.ImageID, Image: operator.Image,
ContainerCommand: operator.ContainerCommand, ContainerArgs: operator.ContainerArgs, RuntimeContract: operator.RuntimeContract,
SkillDefinition: operator.SkillDefinition, PublicationStatus: operator.PublicationStatus, GenerationSource: operator.GenerationSource,
PublicationEvidence: operator.PublicationEvidence, Hyperparams: operator.Hyperparams, CPU: cpu, Memory: memory, GPU: gpu,
SharedMemorySize: sharedMemory,
}}
}
func fanyuMultiportNode(id string, label string, operator domain.OperatorRecord, x float64, y float64) domain.WorkflowNode {
cpu, memory, gpu, sharedMemory := "", "", "", ""
if operator.Resources != nil {
cpu = operator.Resources.CPULimit
@ -60,6 +102,31 @@ func fanyuNodeWithHyperparams(id string, label string, operator domain.OperatorR
return node
}
func fanyuMultiportNodeWithHyperparams(id string, label string, operator domain.OperatorRecord, x float64, y float64, overrides map[string]string) domain.WorkflowNode {
node := fanyuMultiportNode(id, label, operator, x, y)
node.Data.Hyperparams = append([]domain.HyperParam(nil), operator.Hyperparams...)
remaining := make(map[string]string, len(overrides))
for key, value := range overrides {
remaining[key] = value
}
for index := range node.Data.Hyperparams {
key := node.Data.Hyperparams[index].Key
if value, ok := remaining[key]; ok {
node.Data.Hyperparams[index].Value = value
delete(remaining, key)
}
}
keys := make([]string, 0, len(remaining))
for key := range remaining {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
node.Data.Hyperparams = append(node.Data.Hyperparams, domain.HyperParam{Key: key, Value: remaining[key]})
}
return node
}
func fanyuEdge(id string, source string, sourceHandle string, target string, targetHandle string) domain.WorkflowEdge {
return domain.WorkflowEdge{ID: id, Source: source, SourceHandle: sourceHandle, Target: target, TargetHandle: targetHandle, Animated: true}
}
@ -81,6 +148,9 @@ func (server *server) ensureFanyuDeliveryTemplate(ctx context.Context, organizat
if err := server.ensureFanyuDeliveryTemplateV5(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuDeliveryTemplateV54(ctx, organizationID); err != nil {
return err
}
return server.ensureFanyuConvenienceStoreAnnotationTemplates(ctx, organizationID)
}
@ -218,6 +288,116 @@ func (server *server) ensureFanyuDeliveryTemplateV5(ctx context.Context, organiz
return server.store.UpsertWorkflowRelease(ctx, release)
}
// ensureFanyuDeliveryTemplateV54 is the multiport successor of v5. It never
// mutates the released v5.3 workflow: each business value has a named port and
// the old JSON manifests remain internal technical indexes only.
func (server *server) ensureFanyuDeliveryTemplateV54(ctx context.Context, organizationID string) error {
organizationID = normalizedOrganizationID(organizationID)
templateID := fanyuDeliveryTemplateV54ID + "-" + organizationID
releaseID := "workflow-release-fanyu-v5-4-" + organizationID
operatorIDs := []string{
"operator-builtin-directory-scan", "operator-builtin-orbbec-data-normalize", "operator-builtin-video-face-blur",
"operator-builtin-qwen-behavior-rough-cut", "operator-builtin-annotation-gate", "operator-builtin-package",
}
operators := map[string]domain.OperatorRecord{}
for _, operatorID := range operatorIDs {
operator, err := server.store.GetOperator(ctx, operatorID)
if err != nil {
return err
}
if operator == nil {
return fmt.Errorf("fanyu v5.4 template requires builtin operator %s", operatorID)
}
operators[operatorID] = *operator
}
// Older persisted builtin records may still expose the one-manifest v5
// surface while their images are being migrated. Keep v5.4 fail-closed
// until all named ports are present; v1-v5 remain usable through legacy
// adapters in the meantime.
requiredPorts := map[string][]string{
"operator-builtin-directory-scan": {"sourceDirectory", "directory", "videos", "summary"},
"operator-builtin-orbbec-data-normalize": {"directory", "leftVideos", "videoPts", "summary"},
"operator-builtin-video-face-blur": {"videos", "blurredVideos", "detectionSummary"},
"operator-builtin-qwen-behavior-rough-cut": {"videos", "timestamps", "clips", "prelabels", "boundaries", "inferenceSummary"},
"operator-builtin-annotation-gate": {"clips", "prelabels", "boundaries", "approvedVideos", "annotations", "aggregateSummary"},
"operator-builtin-package": {"approvedVideos", "annotations", "packageDirectory", "finalVideos", "deliverySummary"},
}
for operatorID, ports := range requiredPorts {
operator := operators[operatorID]
for _, portID := range ports {
if _, found := domain.FindPort(operator.Inputs, portID); !found {
if _, found := domain.FindPort(operator.Outputs, portID); !found {
return nil
}
}
}
}
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
annotationWorkgroupID := strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID"))
nodes := []domain.WorkflowNode{
fanyuMultiportNode("fanyu-v54-directory", "目录读取(多端口)", operators[operatorIDs[0]], 0, 260),
fanyuMultiportNodeWithHyperparams("fanyu-v54-normalize", "Orbbec Ego 左相机标准化(多端口)", operators[operatorIDs[1]], 260, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v54-face-blur", "人脸脱敏(多端口)", operators[operatorIDs[2]], 550, 260, map[string]string{"PRESERVE_AUDIO": "true", "PRESERVE_PTS": "true", "REQUIRE_DETECTIONS": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v54-rough-cut", "Qwen3-VL 手部行为语义粗切(多端口)", operators[operatorIDs[3]], 820, 260, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "18", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v54-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认(多端口)", operators[operatorIDs[4]], 1110, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_WORKGROUP_ID": annotationWorkgroupID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v54-package", "人工聚合确认后打包(多端口)", operators[operatorIDs[5]], 1400, 260, map[string]string{"REQUIRE_HEADPOSE": "false", "POSE_FREE": "true", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
}
edges := []domain.WorkflowEdge{
fanyuEdge("fanyu-v54-e1", "fanyu-v54-directory", "directory", "fanyu-v54-normalize", "directory"),
fanyuEdge("fanyu-v54-e2", "fanyu-v54-normalize", "leftVideos", "fanyu-v54-face-blur", "videos"),
fanyuEdge("fanyu-v54-e3", "fanyu-v54-normalize", "videoPts", "fanyu-v54-face-blur", "timestamps"),
fanyuEdge("fanyu-v54-e4", "fanyu-v54-normalize", "videoPts", "fanyu-v54-rough-cut", "timestamps"),
fanyuEdge("fanyu-v54-e5", "fanyu-v54-face-blur", "blurredVideos", "fanyu-v54-rough-cut", "videos"),
fanyuEdge("fanyu-v54-e6", "fanyu-v54-rough-cut", "clips", "fanyu-v54-human", "clips"),
fanyuEdge("fanyu-v54-e7", "fanyu-v54-rough-cut", "prelabels", "fanyu-v54-human", "prelabels"),
fanyuEdge("fanyu-v54-e8", "fanyu-v54-rough-cut", "boundaries", "fanyu-v54-human", "boundaries"),
fanyuEdge("fanyu-v54-e9", "fanyu-v54-human", "approvedVideos", "fanyu-v54-package", "approvedVideos"),
fanyuEdge("fanyu-v54-e10", "fanyu-v54-human", "annotations", "fanyu-v54-package", "annotations"),
}
workflowInputs := []domain.WorkflowInputDefinition{{
ID: "sourceDirectory", Name: "sourceDirectory", Description: "本次运行要处理的 Orbbec Ego BOS 目录(必填,非增量扫描)",
Type: domain.PortTypeFile, Container: domain.PortContainerDirectory, PayloadMode: domain.ArtifactTransferModeRef, Role: "directory", Required: true,
Bindings: []domain.WorkflowInputTarget{{NodeID: "fanyu-v54-directory", TargetPortID: "sourceDirectory"}},
}}
now := nowISO()
createdAt := now
if existing, err := server.store.GetTemplate(ctx, templateID); err != nil {
return err
} else if existing != nil && strings.TrimSpace(existing.CreatedAt) != "" {
createdAt = existing.CreatedAt
}
template := domain.TemplateRecord{
ID: templateID, OrganizationID: organizationID, Name: "01-左相机多端口语义粗切标注质检-v5.4",
Description: "目录、视频、PTS、预标、边界、人工审核与交付均使用显式多端口;manifest 仅为内部技术索引。无增量扫描、固定时长切片、200秒定位、LoRA、HeadPose 或 HandPose。",
Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindStandard, ExecutionScope: domain.WorkflowExecutionScopeProduction,
DefinitionState: domain.WorkflowDefinitionStateDraft, DefinitionVersion: 4, DefinitionFamilyID: fanyuDeliveryTemplateV5ID + "-" + organizationID, SupersedesTemplateID: fanyuDeliveryTemplateV5ID + "-" + organizationID,
MaxConcurrentRuns: 1, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, CreatedAt: createdAt, UpdatedAt: now,
}
if issues := validateWorkflowTopology(nodes, edges); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.4 template: %s", strings.TrimSpace(issues[0].Message))
}
if issues := validateWorkflowInputContract(nodes, edges, workflowInputs, true); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.4 input contract: %s", strings.TrimSpace(issues[0].Message))
}
if err := server.store.UpsertTemplate(ctx, template); err != nil {
return err
}
existingRelease, err := server.store.GetWorkflowRelease(ctx, releaseID)
if err != nil || existingRelease != nil {
return err
}
for _, operator := range operators {
if effectiveOperatorPublicationStatus(operator) != domain.OperatorPublicationStatusPublished || !operatorImageDigestPattern.MatchString(strings.TrimSpace(operator.ImageID)) {
return nil
}
}
if annotationWorkgroupID == "" || len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
return nil
}
release := domain.WorkflowReleaseRecord{ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 4, Name: template.Name, Description: template.Description, Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, Capabilities: []string{"directory_input", "multiport_artifact_contract", "qwen3vl_behavior_rough_cut", "human_cut_adjustment", "human_cut_review", "human_semantic_annotation", "human_semantic_review", "human_acceptance", "final_segment_package"}, RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template), ReleaseNotes: "v5.4 explicit multiport data contract; PTS-grounded Qwen and four-stage human loop; pose-free direct package", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now}
return server.store.UpsertWorkflowRelease(ctx, release)
}
func (server *server) ensureFanyuDeliveryTemplateV3(ctx context.Context, organizationID string) error {
templateID := fanyuDeliveryTemplateV3ID + "-" + normalizedOrganizationID(organizationID)
releaseID := "workflow-release-fanyu-v3-" + normalizedOrganizationID(organizationID)

View File

@ -168,6 +168,50 @@ func TestEnsureFanyuDeliveryTemplateCreatesLeftCameraV5AsFailClosedDraft(t *test
}
}
func TestEnsureFanyuDeliveryTemplateCreatesMultiportV54WithoutMutatingV5(t *testing.T) {
ctx := context.Background()
dataStore := store.NewMemoryStore()
items, err := builtinOperatorRecords("2026-08-22T00:00:00Z", "registry.example/droboticflow-operator-runner:test")
if err != nil {
t.Fatal(err)
}
for _, item := range items {
if err := dataStore.UpsertOperator(ctx, item); err != nil {
t.Fatal(err)
}
}
server := &server{store: dataStore}
if err := server.ensureFanyuDeliveryTemplate(ctx, "org-v54"); err != nil {
t.Fatal(err)
}
template, err := dataStore.GetTemplate(ctx, fanyuDeliveryTemplateV54ID+"-org-v54")
if err != nil || template == nil {
t.Fatalf("v5.4 template=%#v err=%v", template, err)
}
if template.DefinitionVersion != 4 || template.SupersedesTemplateID != fanyuDeliveryTemplateV5ID+"-org-v54" || len(template.Nodes) != 6 || len(template.Edges) != 10 {
t.Fatalf("unexpected v5.4 definition: %#v", template)
}
if issues := validateWorkflowTopology(template.Nodes, template.Edges); len(issues) > 0 {
t.Fatalf("v5.4 topology issues: %#v", issues)
}
for _, unwanted := range []string{"fanyu-v54-headpose", "fanyu-v54-handpose", "fanyu-v54-train"} {
if fanyuTestNode(template.Nodes, unwanted) != nil {
t.Fatalf("v5.4 must exclude %s", unwanted)
}
}
normalize := fanyuTestNode(template.Nodes, "fanyu-v54-normalize")
if normalize == nil || len(normalize.Data.Outputs) == 0 || normalize.Data.Outputs[0].Container == "" {
t.Fatalf("v5.4 must retain explicit port contracts: %#v", normalize)
}
packageNode := fanyuTestNode(template.Nodes, "fanyu-v54-package")
if packageNode == nil || len(packageNode.Data.Inputs) != 2 || packageNode.Data.Inputs[0].ID != "approvedVideos" || packageNode.Data.Inputs[1].ID != "annotations" {
t.Fatalf("v5.4 package inputs=%#v", packageNode)
}
if release, releaseErr := dataStore.GetWorkflowRelease(ctx, "workflow-release-fanyu-v5-4-org-v54"); releaseErr != nil || release != nil {
t.Fatalf("unpublished builtin images must keep v5.4 release fail-closed: %#v err=%v", release, releaseErr)
}
}
func TestEnsureFanyuV5RefreshesEditableTemplateWithoutMutatingExistingRelease(t *testing.T) {
ctx := context.Background()
dataStore := store.NewMemoryStore()

View File

@ -3432,6 +3432,7 @@ func (server *server) handleProjectWorkflowsCreate(writer http.ResponseWriter, r
if !decodeJSON(writer, request, &payload) {
return
}
payload.Nodes = normalizeWorkflowNodePorts(payload.Nodes)
payload.ProjectID = chi.URLParam(request, "id")
project, err := server.store.GetProject(request.Context(), payload.ProjectID)
if err != nil {
@ -3508,6 +3509,7 @@ func (server *server) handleProjectWorkflowsCreate(writer http.ResponseWriter, r
payload.Edges = scaffold.Edges
}
}
payload.Nodes = normalizeWorkflowNodePorts(payload.Nodes)
if issues := server.validateNodeConnectionReferences(request.Context(), payload.Nodes); len(issues) > 0 {
renderValidationError(writer, issues...)
return
@ -3938,8 +3940,21 @@ func validateWorkflowGraphTopology(nodes []domain.WorkflowNode, edges []domain.W
func validateWorkflowTopology(nodes []domain.WorkflowNode, edges []domain.WorkflowEdge) []validationIssue {
issues := validateWorkflowNodeResources(nodes)
issues = append(issues, validateWorkflowPortDefinitions(nodes)...)
issues = append(issues, validateInputPortConnectionTopology(nodes, edges)...)
issues = append(issues, validateWorkflowGraphTopology(nodes, edges)...)
for _, issue := range domain.ValidateWorkflowPortCompatibility(nodes, edges) {
issues = append(issues, validationIssue{
Field: "edges",
Code: "workflow_port_contract_incompatible",
Message: fmt.Sprintf(
"连线“%s:%s → %s:%s”端口契约不兼容:%s(上游 %s/%s/%s,下游 %s/%s/%s)。",
issue.SourceNodeID, issue.SourcePortID, issue.TargetNodeID, issue.TargetPortID, issue.Message,
issue.SourceContract.Type, issue.SourceContract.Container, issue.SourceContract.PayloadMode,
issue.TargetContract.Type, issue.TargetContract.Container, issue.TargetContract.PayloadMode,
),
})
}
return issues
}
@ -4189,7 +4204,7 @@ func (server *server) handleWorkflowsUpdate(writer http.ResponseWriter, request
}
}
if payload.Nodes != nil {
item.Nodes = *payload.Nodes
item.Nodes = normalizeWorkflowNodePorts(*payload.Nodes)
}
if payload.Edges != nil {
item.Edges = *payload.Edges
@ -4904,6 +4919,7 @@ func (server *server) handleTemplatesCreate(writer http.ResponseWriter, request
if !decodeJSON(writer, request, &payload) {
return
}
payload.Nodes = normalizeWorkflowNodePorts(payload.Nodes)
payload.Name = strings.TrimSpace(payload.Name)
payload.Type = normalizeWorkflowType(payload.Type)
payload.Kind = normalizeWorkflowKind(payload.Kind)
@ -4954,6 +4970,7 @@ func (server *server) handleTemplatesCreate(writer http.ResponseWriter, request
payload.Type = normalizedScanWorkflowType(payload.ScanConfig)
payload.MaxConcurrentRuns = normalizedScanMaxConcurrentRuns(payload.MaxConcurrentRuns)
}
payload.Nodes = normalizeWorkflowNodePorts(payload.Nodes)
if issues := validateWorkflowTopology(payload.Nodes, payload.Edges); len(issues) > 0 {
renderValidationError(writer, issues...)
return
@ -5112,7 +5129,7 @@ func (server *server) handleTemplatesUpdate(writer http.ResponseWriter, request
}
}
if payload.Nodes != nil {
item.Nodes = *payload.Nodes
item.Nodes = normalizeWorkflowNodePorts(*payload.Nodes)
}
if payload.Edges != nil {
item.Edges = *payload.Edges
@ -5393,21 +5410,60 @@ func validPortTransmission(value string) bool {
}
}
func normalizePortDefinitions(items []domain.PortDefinition) []domain.PortDefinition {
normalized := make([]domain.PortDefinition, 0, len(items))
for _, item := range items {
normalized = append(normalized, domain.PortDefinition{
ID: strings.TrimSpace(item.ID),
Name: strings.TrimSpace(item.Name),
Type: domain.PortType(strings.ToLower(strings.TrimSpace(string(item.Type)))),
Required: item.Required,
Description: strings.TrimSpace(item.Description),
Transmission: strings.ToLower(strings.TrimSpace(item.Transmission)),
})
func normalizeWorkflowNodePorts(items []domain.WorkflowNode) []domain.WorkflowNode {
if items == nil {
return nil
}
normalized := make([]domain.WorkflowNode, len(items))
copy(normalized, items)
for index := range normalized {
normalized[index].Data.Inputs = normalizeWorkflowPortDefinitions(normalized[index].Data.Inputs)
normalized[index].Data.Outputs = normalizeWorkflowPortDefinitions(normalized[index].Data.Outputs)
}
return normalized
}
func normalizeWorkflowPortDefinitions(items []domain.PortDefinition) []domain.PortDefinition {
if items == nil {
return nil
}
normalized := make([]domain.PortDefinition, 0, len(items))
for _, item := range items {
item.ID = strings.TrimSpace(item.ID)
item.Name = strings.TrimSpace(item.Name)
item.Type = domain.PortType(strings.ToLower(strings.TrimSpace(string(item.Type))))
item.Description = strings.TrimSpace(item.Description)
item.Transmission = strings.ToLower(strings.TrimSpace(item.Transmission))
item.Container = domain.PortContainer(strings.ToLower(strings.TrimSpace(string(item.Container))))
item.PayloadMode = domain.ArtifactTransferMode(strings.ToLower(strings.TrimSpace(string(item.PayloadMode))))
item.Role = strings.ToLower(strings.TrimSpace(item.Role))
normalized = append(normalized, item)
}
return normalized
}
func validateWorkflowPortDefinitions(nodes []domain.WorkflowNode) []validationIssue {
issues := make([]validationIssue, 0)
for nodeIndex, node := range nodes {
for direction, ports := range map[string][]domain.PortDefinition{"inputs": node.Data.Inputs, "outputs": node.Data.Outputs} {
for portIndex, port := range ports {
prefix := fmt.Sprintf("nodes[%d].data.%s[%d]", nodeIndex, direction, portIndex)
if strings.TrimSpace(string(port.Container)) != "" && !domain.ValidPortContainer(port.Container) {
issues = append(issues, validationIssue{Field: prefix + ".container", Code: "workflow_port_container_invalid", Message: "container must be single, collection, directory, or dataset"})
}
if strings.TrimSpace(string(port.PayloadMode)) != "" && !domain.ValidPortPayloadMode(port.PayloadMode) {
issues = append(issues, validationIssue{Field: prefix + ".payloadMode", Code: "workflow_port_payload_mode_invalid", Message: "payloadMode must be inline or ref"})
}
}
}
}
return issues
}
func normalizePortDefinitions(items []domain.PortDefinition) []domain.PortDefinition {
return domain.NormalizePortDefinitions(items)
}
func validatePortDefinitions(field string, items []domain.PortDefinition) []validationIssue {
issues := make([]validationIssue, 0)
seenIDs := make(map[string]struct{}, len(items))
@ -5426,6 +5482,12 @@ func validatePortDefinitions(field string, items []domain.PortDefinition) []vali
if !validPortType(item.Type) {
issues = append(issues, validationIssue{Field: prefix + ".type", Message: "type must be json, image, video, tensor, or file"})
}
if !domain.ValidPortContainer(item.Container) {
issues = append(issues, validationIssue{Field: prefix + ".container", Message: "container must be single, collection, directory, or dataset"})
}
if !domain.ValidPortPayloadMode(item.PayloadMode) {
issues = append(issues, validationIssue{Field: prefix + ".payloadMode", Message: "payloadMode must be inline or ref"})
}
if !validPortTransmission(item.Transmission) {
issues = append(issues, validationIssue{Field: prefix + ".transmission", Message: "transmission must be bus, oss, shm, or stream"})
}

View File

@ -0,0 +1,227 @@
package domain
import (
"fmt"
"strings"
)
// PortContract is the effective transport-facing view of a PortDefinition.
// Old persisted workflows did not carry Container or PayloadMode, so callers
// should use EffectivePortContract instead of reading those optional fields
// directly when they need to reason about a legacy graph.
type PortContract struct {
Type PortType
Container PortContainer
PayloadMode ArtifactTransferMode
Role string
Legacy bool
}
type PortCompatibilityIssue struct {
EdgeID string
SourceNodeID string
SourcePortID string
TargetNodeID string
TargetPortID string
SourceContract PortContract
TargetContract PortContract
Message string
}
func validPortContainer(value PortContainer) bool {
switch value {
case PortContainerSingle, PortContainerCollection, PortContainerDirectory, PortContainerDataset:
return true
default:
return false
}
}
func validPortPayloadMode(value ArtifactTransferMode) bool {
return value == ArtifactTransferModeInline || value == ArtifactTransferModeRef
}
func normalizedPortWords(port PortDefinition) string {
return strings.ToLower(strings.Join([]string{port.ID, port.Name, port.Description, port.Role}, " "))
}
func legacyPortContainer(port PortDefinition) PortContainer {
words := normalizedPortWords(port)
if strings.Contains(words, "directory") || strings.Contains(words, "目录") {
return PortContainerDirectory
}
if strings.Contains(words, "dataset") || strings.Contains(words, "数据集") {
return PortContainerDataset
}
for _, token := range []string{"manifest", "collection", "集合", "清单", "videos", "clips", "annotations", "prelabels", "approved", "rejected", "packages"} {
if strings.Contains(words, token) {
return PortContainerCollection
}
}
return PortContainerSingle
}
func legacyPortPayloadMode(port PortDefinition, container PortContainer) ArtifactTransferMode {
if strings.EqualFold(strings.TrimSpace(port.Transmission), "oss") {
return ArtifactTransferModeRef
}
if port.Type != PortTypeJSON || container != PortContainerSingle {
return ArtifactTransferModeRef
}
return ArtifactTransferModeInline
}
// EffectivePortContract supplies deterministic compatibility defaults without
// rewriting old database records. A port is legacy whenever either new
// orthogonal field is absent; such ports retain the historical permissive edge
// behaviour while still have a useful UI label.
func EffectivePortContract(port PortDefinition) PortContract {
container := port.Container
if !validPortContainer(container) {
container = legacyPortContainer(port)
}
mode := port.PayloadMode
if !validPortPayloadMode(mode) {
mode = legacyPortPayloadMode(port, container)
}
return PortContract{
Type: port.Type,
Container: container,
PayloadMode: mode,
Role: strings.ToLower(strings.TrimSpace(port.Role)),
Legacy: !validPortContainer(port.Container) || !validPortPayloadMode(port.PayloadMode),
}
}
// NormalizePortDefinition is used for newly authored operator definitions.
// It retains Transmission for compatibility, while serialising explicit modern
// fields so future graphs are strict and self-describing.
func NormalizePortDefinition(port PortDefinition) PortDefinition {
port.ID = strings.TrimSpace(port.ID)
port.Name = strings.TrimSpace(port.Name)
port.Type = PortType(strings.ToLower(strings.TrimSpace(string(port.Type))))
port.Description = strings.TrimSpace(port.Description)
port.Transmission = strings.ToLower(strings.TrimSpace(port.Transmission))
port.Role = strings.ToLower(strings.TrimSpace(port.Role))
contract := EffectivePortContract(port)
port.Container = contract.Container
port.PayloadMode = contract.PayloadMode
return port
}
func NormalizePortDefinitions(items []PortDefinition) []PortDefinition {
if items == nil {
return nil
}
result := make([]PortDefinition, 0, len(items))
for _, item := range items {
result = append(result, NormalizePortDefinition(item))
}
return result
}
func ValidPortContainer(value PortContainer) bool { return validPortContainer(value) }
func ValidPortPayloadMode(value ArtifactTransferMode) bool { return validPortPayloadMode(value) }
func FindPort(items []PortDefinition, portID string) (PortDefinition, bool) {
for _, item := range items {
if strings.TrimSpace(item.ID) == strings.TrimSpace(portID) {
return item, true
}
}
return PortDefinition{}, false
}
func PortContractsCompatible(source PortDefinition, target PortDefinition) (bool, string) {
sourceContract := EffectivePortContract(source)
targetContract := EffectivePortContract(target)
// Old graph records did not have a cardinality/payload contract. Do not
// invalidate them merely because the new system can infer one. New graphs
// receive the strict checks below because the API normaliser persists both
// fields for authored ports.
if sourceContract.Legacy || targetContract.Legacy {
return true, ""
}
if sourceContract.Type != targetContract.Type {
return false, fmt.Sprintf("type %s cannot connect to %s", sourceContract.Type, targetContract.Type)
}
if sourceContract.PayloadMode != targetContract.PayloadMode {
return false, fmt.Sprintf("payloadMode %s cannot connect to %s", sourceContract.PayloadMode, targetContract.PayloadMode)
}
if sourceContract.Container == targetContract.Container {
return true, ""
}
// The normalizer's source is an actual directory while its normalized view
// is a dataset-shaped file collection. This is an intentional adapter, not
// a JSON-manifest escape hatch.
if sourceContract.Type == PortTypeFile && sourceContract.PayloadMode == ArtifactTransferModeRef &&
sourceContract.Container == PortContainerDirectory && targetContract.Container == PortContainerDataset {
return true, ""
}
return false, fmt.Sprintf("container %s cannot connect to %s", sourceContract.Container, targetContract.Container)
}
func ValidateWorkflowPortCompatibility(nodes []WorkflowNode, edges []WorkflowEdge) []PortCompatibilityIssue {
byID := make(map[string]WorkflowNode, len(nodes))
for _, node := range nodes {
byID[node.ID] = node
}
issues := make([]PortCompatibilityIssue, 0)
for _, edge := range edges {
source, sourceOK := byID[edge.Source]
target, targetOK := byID[edge.Target]
if !sourceOK || !targetOK || strings.TrimSpace(edge.SourceHandle) == "" || strings.TrimSpace(edge.TargetHandle) == "" {
continue
}
sourcePort, sourcePortOK := FindPort(source.Data.Outputs, edge.SourceHandle)
targetPort, targetPortOK := FindPort(target.Data.Inputs, edge.TargetHandle)
if !sourcePortOK || !targetPortOK {
continue
}
if compatible, message := PortContractsCompatible(sourcePort, targetPort); !compatible {
issues = append(issues, PortCompatibilityIssue{
EdgeID: edge.ID, SourceNodeID: edge.Source, SourcePortID: edge.SourceHandle,
TargetNodeID: edge.Target, TargetPortID: edge.TargetHandle,
SourceContract: EffectivePortContract(sourcePort), TargetContract: EffectivePortContract(targetPort), Message: message,
})
}
}
return issues
}
func PortDisplayLabel(port PortDefinition) string {
contract := EffectivePortContract(port)
switch contract.Container {
case PortContainerDirectory:
if contract.Type == PortTypeImage {
return "图片目录"
}
return "通用目录"
case PortContainerDataset:
return "数据集"
case PortContainerCollection:
switch contract.Type {
case PortTypeVideo:
return "视频集合"
case PortTypeImage:
return "图片集合"
case PortTypeFile:
return "文件集合"
default:
return "结构化集合"
}
default:
switch contract.Type {
case PortTypeVideo:
return "单视频"
case PortTypeImage:
return "单图片"
case PortTypeJSON:
return "结构化值"
case PortTypeTensor:
return "张量"
default:
return "单文件"
}
}
}

View File

@ -0,0 +1,46 @@
package domain
import "testing"
func TestEffectivePortContractInfersLegacyManifestReference(t *testing.T) {
port := PortDefinition{ID: "out-1", Name: "dataset manifest", Type: PortTypeJSON, Transmission: "bus"}
contract := EffectivePortContract(port)
if !contract.Legacy || contract.Container != PortContainerDataset || contract.PayloadMode != ArtifactTransferModeRef {
t.Fatalf("unexpected legacy contract: %#v", contract)
}
}
func TestPortContractsRejectIncompatibleExplicitPayloadModes(t *testing.T) {
source := PortDefinition{ID: "videos", Name: "videos", Type: PortTypeVideo, Container: PortContainerCollection, PayloadMode: ArtifactTransferModeRef}
target := PortDefinition{ID: "videos", Name: "videos", Type: PortTypeVideo, Container: PortContainerCollection, PayloadMode: ArtifactTransferModeInline}
if ok, message := PortContractsCompatible(source, target); ok || message == "" {
t.Fatalf("expected explicit payload-mode rejection, ok=%v message=%q", ok, message)
}
}
func TestPortContractsAllowDirectoryToDatasetNormalizerAdapter(t *testing.T) {
source := PortDefinition{ID: "directory", Name: "directory", Type: PortTypeFile, Container: PortContainerDirectory, PayloadMode: ArtifactTransferModeRef}
target := PortDefinition{ID: "directory", Name: "directory", Type: PortTypeFile, Container: PortContainerDataset, PayloadMode: ArtifactTransferModeRef}
if ok, message := PortContractsCompatible(source, target); !ok || message != "" {
t.Fatalf("expected directory dataset adapter, ok=%v message=%q", ok, message)
}
}
func TestPortContractsKeepLegacyEdgesCompatible(t *testing.T) {
legacy := PortDefinition{ID: "out-1", Name: "manifest", Type: PortTypeJSON, Transmission: "bus"}
modern := PortDefinition{ID: "input", Name: "input", Type: PortTypeJSON, Container: PortContainerSingle, PayloadMode: ArtifactTransferModeInline}
if ok, message := PortContractsCompatible(legacy, modern); !ok || message != "" {
t.Fatalf("legacy adapter must remain compatible, ok=%v message=%q", ok, message)
}
}
func TestValidateWorkflowPortCompatibilityReportsNamedEdge(t *testing.T) {
nodes := []WorkflowNode{
{ID: "source", Data: WorkflowNodeData{Outputs: []PortDefinition{{ID: "out", Name: "out", Type: PortTypeVideo, Container: PortContainerCollection, PayloadMode: ArtifactTransferModeRef}}}},
{ID: "target", Data: WorkflowNodeData{Inputs: []PortDefinition{{ID: "in", Name: "in", Type: PortTypeImage, Container: PortContainerCollection, PayloadMode: ArtifactTransferModeRef}}}},
}
issues := ValidateWorkflowPortCompatibility(nodes, []WorkflowEdge{{ID: "edge-video-image", Source: "source", SourceHandle: "out", Target: "target", TargetHandle: "in"}})
if len(issues) != 1 || issues[0].EdgeID != "edge-video-image" || issues[0].Message == "" {
t.Fatalf("unexpected issues: %#v", issues)
}
}

View File

@ -56,6 +56,19 @@ const (
PortTypeFile PortType = "file"
)
// PortContainer describes the shape of the value at a port. It is
// deliberately independent from PortType: a video collection is still made
// of video values, while a directory/dataset is a file reference with a
// different cardinality and materialisation contract.
type PortContainer string
const (
PortContainerSingle PortContainer = "single"
PortContainerCollection PortContainer = "collection"
PortContainerDirectory PortContainer = "directory"
PortContainerDataset PortContainer = "dataset"
)
type WorkflowStatus string
const (
@ -166,12 +179,18 @@ type Position struct {
}
type PortDefinition struct {
ID string `json:"id" bson:"id"`
Name string `json:"name" bson:"name"`
Type PortType `json:"type" bson:"type"`
Required bool `json:"required" bson:"required"`
Description string `json:"description,omitempty" bson:"description,omitempty"`
Transmission string `json:"transmission,omitempty" bson:"transmission,omitempty"`
ID string `json:"id" bson:"id"`
Name string `json:"name" bson:"name"`
Type PortType `json:"type" bson:"type"`
Container PortContainer `json:"container,omitempty" bson:"container,omitempty"`
PayloadMode ArtifactTransferMode `json:"payloadMode,omitempty" bson:"payloadMode,omitempty"`
Role string `json:"role,omitempty" bson:"role,omitempty"`
Required bool `json:"required" bson:"required"`
Description string `json:"description,omitempty" bson:"description,omitempty"`
// Transmission is a legacy runtime-routing hint (bus/oss/shm/stream). New
// UI and operator contracts use PayloadMode; keep it for persisted graph
// compatibility and worker adapters.
Transmission string `json:"transmission,omitempty" bson:"transmission,omitempty"`
}
type WorkflowDefinitionState string
@ -230,6 +249,9 @@ type WorkflowInputDefinition struct {
Name string `json:"name" bson:"name"`
Description string `json:"description,omitempty" bson:"description,omitempty"`
Type PortType `json:"type" bson:"type"`
Container PortContainer `json:"container,omitempty" bson:"container,omitempty"`
PayloadMode ArtifactTransferMode `json:"payloadMode,omitempty" bson:"payloadMode,omitempty"`
Role string `json:"role,omitempty" bson:"role,omitempty"`
Required bool `json:"required" bson:"required"`
DefaultPayload *ArtifactPayload `json:"defaultPayload,omitempty" bson:"defaultPayload,omitempty"`
Bindings []WorkflowInputTarget `json:"bindings" bson:"bindings"`

View File

@ -152,6 +152,9 @@ func ValidateWorkflowInputContract(nodes []WorkflowNode, edges []WorkflowEdge, d
if err := ValidateArtifactPayload(*definition.DefaultPayload, definition.Type); err != nil {
issues = append(issues, WorkflowInputContractIssue{Field: field + ".defaultPayload", Code: "workflow_input_payload_invalid", Message: err.Error()})
}
if ValidPortPayloadMode(definition.PayloadMode) && definition.DefaultPayload.Mode != definition.PayloadMode {
issues = append(issues, WorkflowInputContractIssue{Field: field + ".defaultPayload", Code: "workflow_input_payload_mode_mismatch", Message: "workflow input default payload mode must match payloadMode"})
}
}
if len(definition.Bindings) == 0 {
issues = append(issues, WorkflowInputContractIssue{Field: field + ".bindings", Code: "workflow_input_binding_required", Message: "workflow input requires at least one root-node binding"})
@ -174,6 +177,15 @@ func ValidateWorkflowInputContract(nodes []WorkflowNode, edges []WorkflowEdge, d
if port.Type != definition.Type {
issues = append(issues, WorkflowInputContractIssue{Field: bindingField + ".targetPortId", Code: "workflow_input_type_mismatch", Message: "workflow input type must match target port type"})
}
if ValidPortContainer(definition.Container) && !EffectivePortContract(*port).Legacy && definition.Container != EffectivePortContract(*port).Container {
issues = append(issues, WorkflowInputContractIssue{Field: bindingField + ".targetPortId", Code: "workflow_input_container_mismatch", Message: "workflow input container must match target port container"})
}
if ValidPortPayloadMode(definition.PayloadMode) && !EffectivePortContract(*port).Legacy && definition.PayloadMode != EffectivePortContract(*port).PayloadMode {
issues = append(issues, WorkflowInputContractIssue{Field: bindingField + ".targetPortId", Code: "workflow_input_payload_mode_mismatch", Message: "workflow input payloadMode must match target port payloadMode"})
}
if strings.TrimSpace(definition.Role) != "" && strings.TrimSpace(port.Role) != "" && !strings.EqualFold(strings.TrimSpace(definition.Role), strings.TrimSpace(port.Role)) {
issues = append(issues, WorkflowInputContractIssue{Field: bindingField + ".targetPortId", Code: "workflow_input_role_mismatch", Message: "workflow input role must match target port role"})
}
if port.Required && !definition.Required {
issues = append(issues, WorkflowInputContractIssue{Field: field + ".required", Code: "workflow_input_required_mismatch", Message: "a required target port cannot be exposed as optional"})
}
@ -245,6 +257,9 @@ func ResolveWorkflowRunInputs(workflow WorkflowRecord, provided map[string]Artif
if err := ValidateArtifactPayload(payload, definition.Type); err != nil {
return nil, nil, fmt.Errorf("workflow input %q: %w", definition.ID, err)
}
if ValidPortPayloadMode(definition.PayloadMode) && payload.Mode != definition.PayloadMode {
return nil, nil, fmt.Errorf("workflow input %q: payload mode %s must match %s", definition.ID, payload.Mode, definition.PayloadMode)
}
resolvedInputs[definition.ID] = payload
for _, target := range definition.Bindings {
bindings = append(bindings, ResolvedInputBinding{

View File

@ -129,6 +129,17 @@ func annotationArtifactPayload(artifact domain.ExecutionArtifact) map[string]any
func annotationClipItems(inputs []domain.ExecutionArtifact) map[string]map[string]any {
items := map[string]map[string]any{}
for _, artifact := range inputs {
// v5.4 carries virtual clips as a video collection port. Their compact
// per-artifact metadata is the business payload; a manifest is only an
// internal index and is intentionally not required on the graph edge.
if artifact.Type == domain.PortTypeVideo && strings.TrimSpace(fmt.Sprint(artifact.Data["clipId"])) != "" {
copy := map[string]any{}
for key, value := range artifact.Data {
copy[key] = value
}
copy["clipName"] = artifact.Name
items[artifact.Name] = copy
}
if artifact.Name != "clips-manifest.json" {
continue
}
@ -632,18 +643,34 @@ func annotationRevisionActions(revision domain.AnnotationRevisionRecord) ([]map[
return actions, objects
}
func annotationGateOutputPort(node domain.WorkflowNode) (string, string) {
func annotationGateOutputPortNamed(node domain.WorkflowNode, requested string) (string, string) {
for _, output := range node.Data.Outputs {
if output.ID == "approved" {
if output.ID == requested {
return output.ID, output.Name
}
}
return "", ""
}
func annotationGateOutputPort(node domain.WorkflowNode) (string, string) {
if portID, portName := annotationGateOutputPortNamed(node, "approvedVideos"); portID != "" {
return portID, portName
}
if portID, portName := annotationGateOutputPortNamed(node, "approved"); portID != "" {
return portID, portName
}
if len(node.Data.Outputs) > 0 {
return node.Data.Outputs[0].ID, node.Data.Outputs[0].Name
}
return "approved", "approved"
}
func annotationGateUsesMultiportContract(node domain.WorkflowNode) bool {
approved, _ := annotationGateOutputPortNamed(node, "approvedVideos")
annotations, _ := annotationGateOutputPortNamed(node, "annotations")
return approved != "" && annotations != ""
}
func fanyuV5PrePackageAcceptanceEvidence(ctx context.Context, runtime *Runtime, sourceBatch *domain.HumanBatchRecord) (map[string]any, error) {
if sourceBatch == nil || !sourceBatch.RequirePrePackageAcceptance {
return map[string]any{"confirmed": true, "legacy": true}, nil
@ -730,7 +757,15 @@ func (runtime *Runtime) releasePartitionArtifacts(
}
clips := annotationClipItems(execution.InputArtifacts)
manifestItems := make([]map[string]any, 0, len(selected))
portID, portName := annotationGateOutputPort(node)
videoPortID, videoPortName := annotationGateOutputPort(node)
annotationPortID, annotationPortName := videoPortID, videoPortName
summaryPortID, summaryPortName := "", ""
multiport := annotationGateUsesMultiportContract(node)
if multiport {
videoPortID, videoPortName = annotationGateOutputPortNamed(node, "approvedVideos")
annotationPortID, annotationPortName = annotationGateOutputPortNamed(node, "annotations")
summaryPortID, summaryPortName = annotationGateOutputPortNamed(node, "aggregateSummary")
}
artifacts := make([]domain.ExecutionArtifact, 0, len(selected)+1)
emittedSourceArtifacts := map[string]bool{}
for _, itemID := range partition.ItemIDs {
@ -848,8 +883,8 @@ func (runtime *Runtime) releasePartitionArtifacts(
manifestItems = append(manifestItems, itemBase)
}
if !emittedSourceArtifacts[sourceArtifact.ID] {
sourceArtifact.PortID = portID
sourceArtifact.PortName = portName
sourceArtifact.PortID = videoPortID
sourceArtifact.PortName = videoPortName
artifacts = append(artifacts, *sourceArtifact)
emittedSourceArtifacts[sourceArtifact.ID] = true
}
@ -870,8 +905,8 @@ func (runtime *Runtime) releasePartitionArtifacts(
continue
}
copy := cloneArtifact(artifact)
copy.PortID = portID
copy.PortName = portName
copy.PortID = videoPortID
copy.PortName = videoPortName
artifacts = append(artifacts, copy)
emittedSourceArtifacts[artifact.ID] = true
}
@ -897,10 +932,20 @@ func (runtime *Runtime) releasePartitionArtifacts(
digest := sha256.Sum256(payload)
artifacts = append(artifacts, domain.ExecutionArtifact{
ID: fmt.Sprintf("%s-%s-%s", run.ID, node.ID, name), RunID: run.ID, NodeID: node.ID,
PortID: portID, PortName: portName, Name: "annotations-manifest.json", Type: domain.PortTypeJSON,
PortID: annotationPortID, PortName: annotationPortName, Name: "annotations-manifest.json", Type: domain.PortTypeJSON,
Size: annotationArtifactSize(int64(len(payload))), SizeBytes: int64(len(payload)), Path: manifestPath,
Metadata: &domain.ArtifactMetadata{SHA256: hex.EncodeToString(digest[:]), MimeType: "application/json"}, Data: manifest,
})
if multiport && summaryPortID != "" {
summary := map[string]any{"annotationCount": len(manifestItems), "partitionSequence": partition.Sequence, "aggregateConfirmed": batch.RequirePrePackageAcceptance}
encoded, _ := json.Marshal(summary)
artifacts = append(artifacts, domain.ExecutionArtifact{
ID: fmt.Sprintf("%s-%s-aggregate-summary", run.ID, node.ID), RunID: run.ID, NodeID: node.ID,
PortID: summaryPortID, PortName: summaryPortName, Name: "annotation-aggregate-summary.json", Type: domain.PortTypeJSON,
Size: annotationArtifactSize(int64(len(encoded))), SizeBytes: int64(len(encoded)), Data: summary,
Payload: &domain.ArtifactPayload{Mode: domain.ArtifactTransferModeInline, Type: domain.PortTypeJSON, Inline: summary},
})
}
return artifacts, nil
}
@ -1004,25 +1049,46 @@ func (runtime *Runtime) acceptedAnnotationGateArtifacts(
return nil, false, err
}
digest := sha256.Sum256(payload)
portID, portName := annotationGateOutputPort(node)
videoPortID, videoPortName := annotationGateOutputPort(node)
annotationPortID, annotationPortName := videoPortID, videoPortName
summaryPortID, summaryPortName := "", ""
multiport := annotationGateUsesMultiportContract(node)
if multiport {
videoPortID, videoPortName = annotationGateOutputPortNamed(node, "approvedVideos")
annotationPortID, annotationPortName = annotationGateOutputPortNamed(node, "annotations")
summaryPortID, summaryPortName = annotationGateOutputPortNamed(node, "aggregateSummary")
}
accepted := make([]domain.ExecutionArtifact, 0, len(execution.InputArtifacts)+1)
for _, artifact := range execution.InputArtifacts {
if artifact.Name == "annotations-manifest.json" || strings.HasSuffix(artifact.Name, "_annotation.json") {
continue
}
if multiport && artifact.Type != domain.PortTypeVideo {
continue
}
copy := cloneArtifact(artifact)
copy.PortID = portID
copy.PortName = portName
copy.PortID = videoPortID
copy.PortName = videoPortName
accepted = append(accepted, copy)
}
accepted = append(accepted, domain.ExecutionArtifact{
ID: fmt.Sprintf("%s-%s-%s-annotations-manifest.json", run.ID, node.ID, portID),
RunID: run.ID, NodeID: node.ID, PortID: portID, PortName: portName,
ID: fmt.Sprintf("%s-%s-%s-annotations-manifest.json", run.ID, node.ID, annotationPortID),
RunID: run.ID, NodeID: node.ID, PortID: annotationPortID, PortName: annotationPortName,
Name: "annotations-manifest.json", Type: domain.PortTypeJSON,
Size: annotationArtifactSize(int64(len(payload))), SizeBytes: int64(len(payload)), Path: manifestPath,
Metadata: &domain.ArtifactMetadata{SHA256: hex.EncodeToString(digest[:]), MimeType: "application/json"},
Data: manifest,
})
if multiport && summaryPortID != "" {
summary := map[string]any{"annotationCount": len(items), "aggregateConfirmed": false}
encoded, _ := json.Marshal(summary)
accepted = append(accepted, domain.ExecutionArtifact{
ID: fmt.Sprintf("%s-%s-aggregate-summary", run.ID, node.ID), RunID: run.ID, NodeID: node.ID,
PortID: summaryPortID, PortName: summaryPortName, Name: "annotation-aggregate-summary.json", Type: domain.PortTypeJSON,
Size: annotationArtifactSize(int64(len(encoded))), SizeBytes: int64(len(encoded)), Data: summary,
Payload: &domain.ArtifactPayload{Mode: domain.ArtifactTransferModeInline, Type: domain.PortTypeJSON, Inline: summary},
})
}
return accepted, true, nil
}

View File

@ -45,7 +45,16 @@ func compactArtifactData(data map[string]any) map[string]any {
}
compact := map[string]any{}
for key, value := range data {
if key == "preview" || key == "reportSummary" || key == "dataRef" || key == "count" || key == "schemaVersion" || key == "datasetType" || key == "kind" || strings.HasSuffix(key, "Count") {
// These fields are required by downstream port-aware adapters (notably
// virtual Qwen clips and human-release packaging) but do not themselves
// contain a storage locator. Response sanitisation still removes any
// nested source/ref/path values before they reach the browser.
switch key {
case "preview", "reportSummary", "dataRef", "count", "schemaVersion", "datasetType", "kind", "clipId", "clipName", "sourceIsFullVideo", "startSecond", "endSecond", "sourceDurationSeconds", "behavior", "objectChange", "rawPTS", "annotation", "collectionId", "cameraSide", "role":
compact[key] = value
continue
}
if strings.HasSuffix(key, "Count") {
compact[key] = value
}
}
@ -231,9 +240,10 @@ func putArtifactFile(ctx context.Context, publisher objectsync.Publisher, connec
return meta, sha, err
}
func (runtime *Runtime) externalizeDirectory(ctx context.Context, publisher objectsync.Publisher, connection domain.StorageConnectionRecord, policy domain.ArtifactStoragePolicy, run *domain.RunRecord, nodeID string, artifact domain.ExecutionArtifact) (domain.ExecutionArtifact, error) {
func (runtime *Runtime) externalizeDirectory(ctx context.Context, publisher objectsync.Publisher, connection domain.StorageConnectionRecord, policy domain.ArtifactStoragePolicy, run *domain.RunRecord, nodeID string, artifact domain.ExecutionArtifact) (domain.ExecutionArtifact, map[string]domain.ArtifactReference, error) {
basePrefix := artifactPrefix(policy, run, nodeID) + "/" + artifactSlug(artifact.ID)
entries := make([]directoryManifestEntry, 0)
sharedRefs := map[string]domain.ArtifactReference{}
var totalBytes int64
err := filepath.WalkDir(artifact.Path, func(path string, entry os.DirEntry, walkErr error) error {
if walkErr != nil {
@ -252,29 +262,33 @@ func (runtime *Runtime) externalizeDirectory(ctx context.Context, publisher obje
return err
}
entries = append(entries, directoryManifestEntry{Path: filepath.ToSlash(relative), Key: key, SizeBytes: meta.SizeBytes, SHA256: sha})
sharedRefs[filepath.Clean(path)] = domain.ArtifactReference{
Provider: connection.Provider, ConnectionID: policy.ConnectionID, Bucket: policy.Bucket, Key: key,
VersionID: meta.VersionID, ETag: meta.ETag, SizeBytes: meta.SizeBytes, SHA256: sha, Kind: domain.ArtifactRefKindObject,
}
totalBytes += meta.SizeBytes
return nil
})
if err != nil {
return artifact, err
return artifact, nil, err
}
sort.Slice(entries, func(i, j int) bool { return entries[i].Path < entries[j].Path })
manifest := directoryManifest{SchemaVersion: 1, Kind: "directory", FileCount: len(entries), TotalBytes: totalBytes, Entries: entries}
payload, err := json.Marshal(manifest)
if err != nil {
return artifact, err
return artifact, nil, err
}
manifestKey := basePrefix + "/manifest.json"
meta, err := publisher.PutInternal(ctx, connection, policy.Bucket, manifestKey, bytes.NewReader(payload), int64(len(payload)), "application/json", nil)
if err != nil {
return artifact, err
return artifact, nil, err
}
ref := &domain.ArtifactReference{Provider: domain.StorageProviderBOS, ConnectionID: policy.ConnectionID, Bucket: policy.Bucket, Prefix: basePrefix + "/files", ManifestKey: manifestKey, VersionID: meta.VersionID, ETag: meta.ETag, SizeBytes: totalBytes, Kind: domain.ArtifactRefKindDirectory}
artifact.Path = "bos://" + policy.Bucket + "/" + ref.Prefix
artifact.SizeBytes = totalBytes
artifact.Payload = &domain.ArtifactPayload{Mode: domain.ArtifactTransferModeRef, Type: artifact.Type, Ref: ref}
artifact.Data = compactArtifactData(artifact.Data)
return artifact, nil
return artifact, sharedRefs, nil
}
func (runtime *Runtime) normalizeOutputArtifacts(ctx context.Context, workflow *domain.WorkflowRecord, run *domain.RunRecord, nodeID string, artifacts []domain.ExecutionArtifact) ([]domain.ExecutionArtifact, error) {
@ -292,6 +306,11 @@ func (runtime *Runtime) normalizeOutputArtifacts(ctx context.Context, workflow *
publisher = runtime.outputArtifactPublisher()
}
result := make([]domain.ExecutionArtifact, len(artifacts))
// A package directory and its visible MP4/JSON members are often returned
// together. Externalise the directory once, then bind member artifacts to
// the exact already-uploaded object refs instead of copying every byte a
// second time.
sharedDirectoryFileRefs := map[string]domain.ArtifactReference{}
for index, artifact := range artifacts {
result[index] = artifact
if artifact.Payload != nil && artifact.Payload.Mode == domain.ArtifactTransferModeRef {
@ -361,12 +380,25 @@ func (runtime *Runtime) normalizeOutputArtifacts(ctx context.Context, workflow *
}
continue
}
if info.Mode().IsRegular() {
if shared, exists := sharedDirectoryFileRefs[filepath.Clean(artifact.Path)]; exists {
ref := shared
result[index].Path = "bos://" + ref.Bucket + "/" + ref.Key
result[index].SizeBytes = ref.SizeBytes
result[index].Payload = &domain.ArtifactPayload{Mode: domain.ArtifactTransferModeRef, Type: artifact.Type, Ref: &ref}
result[index].Data = compactArtifactData(artifact.Data)
continue
}
}
if info.IsDir() {
externalized, externalizeErr := runtime.externalizeDirectory(ctx, publisher, *connection, *policy, run, nodeID, artifact)
externalized, refs, externalizeErr := runtime.externalizeDirectory(ctx, publisher, *connection, *policy, run, nodeID, artifact)
if externalizeErr != nil {
return nil, fmt.Errorf("artifact_externalization_failed: %w", externalizeErr)
}
result[index] = externalized
for path, ref := range refs {
sharedDirectoryFileRefs[path] = ref
}
continue
}
key := artifactPrefix(*policy, run, nodeID) + "/" + artifactSlug(artifact.ID) + "/" + artifactSlug(filepath.Base(artifact.Path))

View File

@ -2,6 +2,7 @@ package worker
import (
"context"
"encoding/json"
"io"
"os"
"path/filepath"
@ -154,6 +155,61 @@ func TestNormalizeOutputArtifactsExternalizesSmallStructuredJSONReferences(t *te
}
}
func TestNormalizeOutputArtifactsReusesDirectoryMemberObjectRefs(t *testing.T) {
ctx := context.Background()
dataStore := store.NewMemoryStore()
publisher := &memoryArtifactPublisher{}
runtime, err := newTestRuntime(t, dataStore)
if err != nil {
t.Fatalf("new runtime: %v", err)
}
runtime.artifactPublisher = publisher
connection := domain.StorageConnectionRecord{ID: "artifact-bos", OrganizationID: "org-artifacts", Provider: domain.StorageProviderBOS, Bucket: "artifact-bucket", Endpoint: "https://bos.example.test"}
if err := dataStore.UpsertStorageConnection(ctx, connection); err != nil {
t.Fatalf("upsert storage connection: %v", err)
}
workflow := &domain.WorkflowRecord{ID: "workflow-artifacts", OrganizationID: "org-artifacts", ArtifactStorage: &domain.ArtifactStoragePolicy{ConnectionID: connection.ID, Bucket: connection.Bucket, PrefixTemplate: "artifacts/{runId}/{nodeId}"}}
run := &domain.RunRecord{ID: "run-artifacts", OrganizationID: workflow.OrganizationID, WorkflowID: workflow.ID}
root := t.TempDir()
videoPath := filepath.Join(root, "final.mp4")
semanticPath := filepath.Join(root, "semantic.json")
if err := os.WriteFile(videoPath, []byte("real-mp4-bytes"), 0o644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(semanticPath, []byte(`{"actions":[]}`), 0o644); err != nil {
t.Fatal(err)
}
artifacts, err := runtime.normalizeOutputArtifacts(ctx, workflow, run, "package", []domain.ExecutionArtifact{
{ID: "package-directory", RunID: run.ID, NodeID: "package", Name: "package-directory", Type: domain.PortTypeFile, Path: root},
{ID: "final-video", RunID: run.ID, NodeID: "package", Name: "final.mp4", Type: domain.PortTypeVideo, Path: videoPath},
{ID: "semantic-file", RunID: run.ID, NodeID: "package", Name: "semantic.json", Type: domain.PortTypeFile, Path: semanticPath},
})
if err != nil {
t.Fatalf("normalize artifacts: %v", err)
}
if len(publisher.puts) != 3 {
t.Fatalf("directory files plus one manifest should upload once each, puts=%#v", publisher.puts)
}
directoryRef := artifacts[0].Payload.Ref
if directoryRef == nil || directoryRef.Kind != domain.ArtifactRefKindDirectory {
t.Fatalf("missing directory ref: %#v", artifacts[0].Payload)
}
var manifest directoryManifest
if err := json.Unmarshal(publisher.objects[publisher.objectID(connection.Bucket, directoryRef.ManifestKey)], &manifest); err != nil {
t.Fatalf("decode directory manifest: %v", err)
}
keys := map[string]string{}
for _, entry := range manifest.Entries {
keys[entry.Path] = entry.Key
}
if artifacts[1].Payload == nil || artifacts[1].Payload.Ref == nil || artifacts[1].Payload.Ref.Key != keys["final.mp4"] {
t.Fatalf("video must reuse directory object ref: artifact=%#v keys=%#v", artifacts[1], keys)
}
if artifacts[2].Payload == nil || artifacts[2].Payload.Ref == nil || artifacts[2].Payload.Ref.Key != keys["semantic.json"] {
t.Fatalf("semantic file must reuse directory object ref: artifact=%#v keys=%#v", artifacts[2], keys)
}
}
func TestArtifactStoragePolicyUsesWorkflowOrganizationDefault(t *testing.T) {
dataStore := store.NewMemoryStore()
runtime, err := newTestRuntime(t, dataStore)

View File

@ -34,10 +34,21 @@ func humanReleaseTarget(workflow *domain.WorkflowRecord, gateNodeID string) (str
return "", fmt.Errorf("human release workflow is missing")
}
edges := domain.GetDecisionOutgoingEdges(workflow.Edges, gateNodeID, domain.AuditStatusApproved)
if len(edges) != 1 {
return "", fmt.Errorf("human release gate %s must have exactly one approved downstream edge", gateNodeID)
targets := make([]string, 0, len(edges))
seen := map[string]struct{}{}
for _, edge := range edges {
if _, exists := seen[edge.Target]; exists {
continue
}
seen[edge.Target] = struct{}{}
targets = append(targets, edge.Target)
}
return edges[0].Target, nil
// A multiport human gate may provide approved videos and annotation JSON to
// the same package node. It is still one downstream execution target.
if len(targets) != 1 {
return "", fmt.Errorf("human release gate %s must have exactly one approved downstream target", gateNodeID)
}
return targets[0], nil
}
func humanReleaseBaseline(workflow domain.WorkflowRecord, parent domain.RunRecord, gateNodeID string, targetNodeID string, artifacts []domain.ExecutionArtifact) []domain.NodeExecutionRecord {

View File

@ -19,6 +19,18 @@ func TestHumanReleaseTargetUsesApprovedGateEdge(t *testing.T) {
}
}
func TestHumanReleaseTargetAllowsMultiportApprovedEdgesToOnePackage(t *testing.T) {
workflow := &domain.WorkflowRecord{Edges: []domain.WorkflowEdge{
{ID: "approved-videos", Source: "gate", SourceHandle: "approvedVideos", Target: "package"},
{ID: "annotations", Source: "gate", SourceHandle: "annotations", Target: "package"},
{ID: "rejected", Source: "gate", SourceHandle: "rejected", Target: "quarantine"},
}}
target, err := humanReleaseTarget(workflow, "gate")
if err != nil || target != "package" {
t.Fatalf("target=%q err=%v", target, err)
}
}
func TestHumanReleaseBaselineCompletesGateWithPartitionArtifacts(t *testing.T) {
workflow := domain.WorkflowRecord{
Nodes: []domain.WorkflowNode{{ID: "source"}, {ID: "gate"}, {ID: "package"}},

View File

@ -6,7 +6,7 @@ from typing import Any, Callable
HelperMap = dict[str, Callable[..., Any]]
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: Any,
@ -42,3 +42,65 @@ def run(
output=helpers["output_binding"](node_data),
)
]
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
params = helpers["hyperparams"](node_data)
template_id = params.get("ANNOTATION_TEMPLATE_ID", "").strip()
workgroup_id = params.get("ANNOTATION_WORKGROUP_ID", "").strip()
if not template_id or not workgroup_id:
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID 和 ANNOTATION_WORKGROUP_ID")
clips = [item for item in inputs if str(item.get("portId") or item.get("portName") or "") == "clips" or str(item.get("type", "")) == "video"]
if not clips:
raise RuntimeError("原生视频标注 Gate 多端口路径需要 clips 视频集合")
for clip in clips:
clip["portId"] = str((_output(node_data, helpers, "approvedVideos") or {}).get("id", ""))
clip["portName"] = str((_output(node_data, helpers, "approvedVideos") or {}).get("name", ""))
payloads = helpers["payloads_from_inputs"](inputs)
prelabels = []
boundaries = []
for payload in payloads:
if isinstance(payload.get("items"), list):
prelabels.extend(payload["items"])
if isinstance(payload.get("boundaries"), list):
boundaries.extend(payload["boundaries"])
write = helpers["write_json_artifact"]
annotations = {
"datasetType": "annotation-gate-input",
"templateId": template_id,
"workgroupId": workgroup_id,
"itemCount": len(clips),
"items": prelabels,
}
rejected = {"datasetType": "annotation-gate-rejected", "itemCount": 0, "items": []}
summary = {"clipCount": len(clips), "prelabelCount": len(prelabels), "boundaryCount": len(boundaries), "templateId": template_id, "workgroupId": workgroup_id}
return [
*clips,
write(run_id, node_id, output_dir, "annotation-gate-annotations-dataset.json", annotations, output=_output(node_data, helpers, "annotations")),
write(run_id, node_id, output_dir, "annotation-gate-rejected-dataset.json", rejected, output=_output(node_data, helpers, "rejected")),
write(run_id, node_id, output_dir, "annotation-gate-aggregate-summary.json", summary, output=_output(node_data, helpers, "aggregateSummary")),
]
def run(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "approvedVideos") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -7,6 +7,8 @@ from typing import Any, Callable
HelperMap = dict[str, Callable[..., Any]]
VIDEO_SUFFIXES = {".mp4", ".mov", ".m4v", ".avi", ".mkv", ".webm"}
IMAGE_SUFFIXES = {".jpg", ".jpeg", ".png", ".bmp", ".webp", ".gif"}
def _directory_ref(inputs: list[dict[str, Any]]) -> tuple[str, str] | None:
@ -73,7 +75,7 @@ def _bos_entries(
return entries
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: Any,
@ -152,3 +154,138 @@ def run(
output=helpers["output_binding"](node_data),
)
]
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _entry_path(entry: dict[str, Any], bucket: str = "", prefix: str = "", helpers: HelperMap | None = None) -> str:
source = entry.get("source") if isinstance(entry.get("source"), dict) else {}
raw = str(source.get("path") or entry.get("path") or entry.get("relativePath") or entry.get("name") or "").strip()
if raw.startswith("bos://") or not bucket:
return raw
relative = raw.lstrip("/")
combined = "/".join(part for part in (prefix.strip("/"), relative) if part)
if helpers is not None:
return str(helpers["canonical_bos_path"](bucket, combined))
return f"bos://{bucket}/{combined}"
def _directory_input(inputs: list[dict[str, Any]]) -> dict[str, Any] | None:
for artifact in inputs:
payload = artifact.get("payload") if isinstance(artifact.get("payload"), dict) else {}
ref = payload.get("ref") if isinstance(payload.get("ref"), dict) else {}
if str(ref.get("kind", "")).strip().lower() == "directory":
return artifact
return None
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
params = helpers["hyperparams"](node_data)
pattern = str(params.get("PATTERN", "")).strip()
directory_input = _directory_input(inputs)
bucket = ""
prefix = ""
entries: list[dict[str, Any]] = []
root_path = ""
if directory_input is not None:
payload = directory_input.get("payload") if isinstance(directory_input.get("payload"), dict) else {}
ref = payload.get("ref") if isinstance(payload.get("ref"), dict) else {}
bucket = str(ref.get("bucket", "")).strip()
prefix = str(ref.get("prefix", "")).strip().strip("/")
if bucket:
entries = _bos_entries(bucket, prefix, pattern, params, helpers)
root_path = str(helpers["canonical_bos_path"](bucket, prefix))
else:
root_path = str(directory_input.get("path", "")).strip()
if not entries and not root_path:
source_path = helpers["resolve_source_path"](params, inputs)
if source_path is None:
raise RuntimeError("目录读取需要必填目录输入或 SOURCE_PATH 指向真实目录")
root = source_path if source_path.is_dir() else source_path.parent
root_path = str(source_path)
entries = [
{
**item,
"source": {"path": str(root / pathlib.PurePosixPath(str(item.get("path", ""))))},
}
for item in helpers["list_source_entries"](root, pattern)
]
artifacts: list[dict[str, Any]] = []
directory_output = _output(node_data, helpers, "directory")
if directory_output is not None:
directory_artifact = helpers["build_virtual_artifact"](
run_id,
node_id,
"directory.index",
root_path,
"file",
sum(int(item.get("sizeBytes", 0) or 0) for item in entries),
data={"fileCount": len(entries), "datasetType": "directory"},
output=directory_output,
)
if directory_input is not None and isinstance(directory_input.get("payload"), dict):
directory_artifact["payload"] = dict(directory_input["payload"])
artifacts.append(directory_artifact)
media_outputs = {
"videos": (VIDEO_SUFFIXES, "video"),
"images": (IMAGE_SUFFIXES, "image"),
"files": (set(), "file"),
}
for output_name, (suffixes, artifact_type) in media_outputs.items():
binding = _output(node_data, helpers, output_name)
if binding is None:
continue
for entry in entries:
relative = str(entry.get("path") or entry.get("relativePath") or entry.get("name") or "").strip()
suffix = pathlib.PurePosixPath(relative).suffix.lower()
if output_name == "files":
if suffix in VIDEO_SUFFIXES or suffix in IMAGE_SUFFIXES:
continue
elif suffix not in suffixes:
continue
artifacts.append(
helpers["build_virtual_artifact"](
run_id,
node_id,
pathlib.PurePosixPath(relative).name or f"{output_name}.bin",
_entry_path(entry, bucket, prefix, helpers),
artifact_type,
int(entry.get("sizeBytes", 0) or 0),
data={"collectionId": pathlib.PurePosixPath(relative).parts[0] if pathlib.PurePosixPath(relative).parts else "", "relativeName": pathlib.PurePosixPath(relative).name},
output=binding,
)
)
summary = {
"fileCount": len(entries),
"videoCount": sum(1 for item in entries if pathlib.PurePosixPath(str(item.get("path") or item.get("name") or "")).suffix.lower() in VIDEO_SUFFIXES),
"imageCount": sum(1 for item in entries if pathlib.PurePosixPath(str(item.get("path") or item.get("name") or "")).suffix.lower() in IMAGE_SUFFIXES),
"totalBytes": sum(int(item.get("sizeBytes", 0) or 0) for item in entries),
"dataSource": "BOS" if bucket else "FILESYSTEM",
}
artifacts.append(helpers["write_json_artifact"](run_id, node_id, output_dir, "directory-summary.json", summary, output=_output(node_data, helpers, "summary")))
return artifacts
def run(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "directory") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -2,6 +2,8 @@ from __future__ import annotations
import pathlib
import re
import os
import json
from typing import Any, Callable
@ -28,7 +30,7 @@ def _camera_side(path: str) -> str:
return matched.group("side").lower() if matched else ""
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: Any,
@ -129,3 +131,148 @@ def run(
output=helpers["output_binding"](node_data),
)
]
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _entry_source_path(entry: dict[str, Any], source_path: str) -> str:
source = entry.get("source") if isinstance(entry.get("source"), dict) else {}
value = str(source.get("path") or entry.get("path") or entry.get("relativePath") or "").strip()
if value.startswith("bos://") or not source_path.startswith("bos://"):
return value
return source_path.rstrip("/") + "/" + value.lstrip("/")
def _directory_entries(inputs: list[dict[str, Any]], helpers: HelperMap) -> tuple[list[dict[str, Any]], str]:
for artifact in inputs:
data = artifact.get("data") if isinstance(artifact.get("data"), dict) else {}
if isinstance(data.get("entries"), list):
return [item for item in data["entries"] if isinstance(item, dict)], str(data.get("sourcePath", ""))
for artifact in inputs:
payload = artifact.get("payload") if isinstance(artifact.get("payload"), dict) else {}
ref = payload.get("ref") if isinstance(payload.get("ref"), dict) else {}
if str(ref.get("kind", "")).strip().lower() != "directory":
continue
bucket = str(ref.get("bucket", "")).strip()
prefix = str(ref.get("prefix", "")).strip().strip("/")
if bucket:
endpoint = os.getenv("BOS_ENDPOINT", "").strip()
access_key_id = os.getenv("BOS_ACCESS_KEY_ID", "").strip()
secret_access_key = os.getenv("BOS_SECRET_ACCESS_KEY", "").strip()
if not endpoint or not access_key_id or not secret_access_key:
raise RuntimeError("Orbbec 多端口标准化需要目录引用对应的 BOS 凭证")
entries = helpers["list_bos_entries"](bucket, prefix, "", endpoint, access_key_id, secret_access_key)
source_path = str(helpers["canonical_bos_path"](bucket, prefix))
return [
{
**item,
"source": {"path": _entry_source_path(item, source_path)},
}
for item in entries
if isinstance(item, dict)
], source_path
local_path = pathlib.Path(str(artifact.get("path", "")).strip())
if local_path.exists():
root = local_path if local_path.is_dir() else local_path.parent
entries = helpers["list_source_entries"](root, "")
return [
{
**item,
"source": {"path": str(root / pathlib.PurePosixPath(str(item.get("path", ""))))},
}
for item in entries
if isinstance(item, dict)
], str(local_path)
return [], ""
def _paired_source_path(value: str, source_path: str) -> str:
if not value:
return ""
if value.startswith("bos://") or not source_path.startswith("bos://"):
return value
return source_path.rstrip("/") + "/" + value.lstrip("/")
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
entries, source_path = _directory_entries(inputs, helpers)
if not entries:
raise RuntimeError("Orbbec Ego 数据标准化需要 directory/dataset 引用或 legacy entries")
synthetic_inputs = [{"name": "directory-technical-index.json", "data": {"entries": entries, "sourcePath": source_path}}, *inputs]
_run_legacy(run_id, node_id, output_dir, node_data, synthetic_inputs, helpers)
manifest_path = pathlib.Path(output_dir) / "orbbec-normalized-manifest.json"
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
artifacts: list[dict[str, Any]] = []
seen_files: set[tuple[str, str]] = set()
for item in manifest.get("items", []):
if not isinstance(item, dict):
continue
side = str(item.get("cameraSide", "")).strip().lower()
output_name = "leftVideos" if side == "left" else "rightVideos" if side == "right" else ""
binding = _output(node_data, helpers, output_name)
source = item.get("source") if isinstance(item.get("source"), dict) else {}
video_path = str(source.get("path") or item.get("path") or "")
if binding is not None and video_path:
artifacts.append(
helpers["build_virtual_artifact"](
run_id,
node_id,
str(item.get("filename") or pathlib.PurePosixPath(video_path).name),
video_path,
"video",
int(item.get("sizeBytes", 0) or 0),
data={"collectionId": item.get("collectionId", ""), "cameraSide": side},
output=binding,
)
)
paired = item.get("pairedFiles") if isinstance(item.get("pairedFiles"), dict) else {}
for pair_key, output_name in (("pts", "videoPts"), ("audio", "audio"), ("imu", "imu"), ("cameraCalibration", "calibrations"), ("imuCalibration", "calibrations")):
pair = _paired_source_path(str(paired.get(pair_key, "")).strip(), source_path)
binding = _output(node_data, helpers, output_name)
key = (output_name, pair)
if not pair or binding is None or key in seen_files:
continue
seen_files.add(key)
artifacts.append(
helpers["build_virtual_artifact"](
run_id,
node_id,
pathlib.PurePosixPath(pair).name,
pair,
"file",
0,
data={"role": pair_key, "collectionId": item.get("collectionId", "")},
output=binding,
)
)
summary = {
"collectionCount": int(manifest.get("collectionCount", 0) or 0),
"videoCount": int(manifest.get("videoCount", 0) or 0),
"leftVideoCount": sum(1 for item in manifest.get("items", []) if isinstance(item, dict) and item.get("cameraSide") == "left"),
"rightVideoCount": sum(1 for item in manifest.get("items", []) if isinstance(item, dict) and item.get("cameraSide") == "right"),
"datasetType": "orbbec-ego",
}
artifacts.append(helpers["write_json_artifact"](run_id, node_id, output_dir, "orbbec-normalize-summary.json", summary, output=_output(node_data, helpers, "summary")))
return artifacts
def run(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "leftVideos") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -349,8 +349,85 @@ def _run_legacy(run_id: str, node_id: str, output_dir: Any, node_data: dict[str,
return artifacts
def run(run_id: str, node_id: str, output_dir: Any, node_data: dict[str, Any], inputs: list[dict[str, Any]], helpers: HelperMap) -> list[dict[str, Any]]:
def _run_existing_contract(run_id: str, node_id: str, output_dir: Any, node_data: dict[str, Any], inputs: list[dict[str, Any]], helpers: HelperMap) -> list[dict[str, Any]]:
params = helpers["hyperparams"](node_data)
if not _bool(params, "REQUIRE_FINAL_ACCEPTANCE", False) and not _bool(params, "GENERATE_SEGMENT_MP4", False):
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_fanyu_v5(run_id, node_id, output_dir, node_data, inputs, helpers)
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _port(artifact: dict[str, Any]) -> str:
return str(artifact.get("portId") or artifact.get("portName") or "").strip()
def _materialize_annotation_payload(artifact: dict[str, Any], output: pathlib.Path, helpers: HelperMap) -> dict[str, Any]:
data = artifact.get("data") if isinstance(artifact.get("data"), dict) else {}
if isinstance(data.get("items"), list):
return data
materialize = helpers.get("source_path_from_item")
source_ref = helpers.get("source_ref_from_artifact")
if not callable(materialize):
raise RuntimeError("成品打包无法物化 annotations 引用")
source = source_ref(artifact) if callable(source_ref) else {}
path = materialize({"path": str(artifact.get("path", "")), "source": source if isinstance(source, dict) else {}}, str(artifact.get("name", "annotations.json")), output, {})
decoded = json.loads(pathlib.Path(path).read_text(encoding="utf-8"))
if not isinstance(decoded, dict) or not isinstance(decoded.get("items"), list):
raise RuntimeError("annotations 引用不是可打包的 accepted annotation collection")
return decoded
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
output = pathlib.Path(output_dir)
approved = [item for item in inputs if _port(item) == "approvedVideos" or str(item.get("type", "")) == "video"]
annotation_artifact = next((item for item in inputs if _port(item) == "annotations"), None)
if not approved or annotation_artifact is None:
# A newly published package image must still execute historical graphs
# that supply one legacy annotations/manifest input.
return _run_existing_contract(run_id, node_id, output_dir, node_data, inputs, helpers)
accepted = _materialize_annotation_payload(annotation_artifact, output, helpers)
# Existing precise Fanyu packager owns ffmpeg cutting and acceptance
# validation. Feed it a local technical adapter only; business outputs are
# rebound below by their real media/file role.
_run_fanyu_v5(run_id, node_id, output, node_data, [{"name": "accepted-annotations-index.json", "data": accepted}, *approved], helpers)
packages_root = output / "packages"
package_binding = _output(node_data, helpers, "packageDirectory")
result: list[dict[str, Any]] = []
if package_binding is not None:
result.append(helpers["build_virtual_artifact"](run_id, node_id, "delivery-package-directory", str(packages_root), "file", 0, data={"packageCount": len([path for path in packages_root.iterdir() if path.is_dir()])}, output=package_binding))
files = helpers["collect_output_artifacts"](run_id, node_id, packages_root, node_data=node_data)
for artifact in files:
name = str(artifact.get("name", "")).lower()
binding = None
if name.endswith(".mp4"):
binding = _output(node_data, helpers, "finalVideos")
elif name == "semantic.json" or name.endswith("_annotation.json"):
binding = _output(node_data, helpers, "semanticFiles")
elif name == "segment.json" or name.endswith("_segment.json"):
binding = _output(node_data, helpers, "segmentFiles")
if binding is None:
continue
artifact["portId"] = str(binding.get("id", ""))
artifact["portName"] = str(binding.get("name", ""))
result.append(artifact)
manifest_path = output / "packages-manifest.json"
manifest = json.loads(manifest_path.read_text(encoding="utf-8")) if manifest_path.exists() else {}
summary = {"packageCount": int(manifest.get("packageCount", 0) or 0), "trainingEnabled": False, "poseFree": True, "finalAcceptanceRequired": _bool(helpers["hyperparams"](node_data), "REQUIRE_FINAL_ACCEPTANCE", False)}
result.append(helpers["write_json_artifact"](run_id, node_id, output, "delivery-summary.json", summary, output=_output(node_data, helpers, "deliverySummary")))
return result
def run(run_id: str, node_id: str, output_dir: Any, node_data: dict[str, Any], inputs: list[dict[str, Any]], helpers: HelperMap) -> list[dict[str, Any]]:
if _output(node_data, helpers, "packageDirectory") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_existing_contract(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -813,7 +813,7 @@ def _source_contexts(
return contexts
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: Any,
@ -1150,3 +1150,105 @@ def run(
write(run_id, node_id, output, "clips-manifest.json", manifest, output=binding if isinstance(binding, dict) else None),
*virtual_artifacts,
]
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
binding_fn = helpers.get("output_binding")
return binding_fn(node_data, name=name) if callable(binding_fn) else None
def _port(artifact: dict[str, Any]) -> str:
return str(artifact.get("portId") or artifact.get("portName") or "").strip()
def _multiport_inputs(inputs: list[dict[str, Any]]) -> list[dict[str, Any]]:
videos = [item for item in inputs if _port(item) == "videos" or pathlib.PurePosixPath(str(item.get("name", ""))).suffix.lower() in VIDEO_SUFFIXES]
timestamps = [item for item in inputs if _port(item) == "timestamps" or str(item.get("name", "")).lower().endswith("_pts.csv")]
if not videos:
raise RuntimeError("Qwen 行为粗切多端口路径需要 videos 视频集合")
pts_by_stem = {
pathlib.PurePosixPath(str(item.get("name", ""))).stem.removesuffix("_pts"): item
for item in timestamps
if str(item.get("name", ""))
}
blur_items: list[dict[str, Any]] = []
for artifact in videos:
sanitized = _basename(artifact.get("name") or artifact.get("path"))
original = sanitized[len("blurred_") :] if sanitized.startswith("blurred_") else sanitized
pts = pts_by_stem.get(pathlib.PurePosixPath(original).stem)
blur_items.append(
{
"sanitizedFilename": sanitized,
"filename": sanitized,
"sourceVideo": original,
"sanitizedVideoPath": str(artifact.get("path", "")),
"pairedFiles": {"pts": str(pts.get("path", "")) if isinstance(pts, dict) else ""},
}
)
return [
{"name": "multiport-blur-technical-index.json", "data": {"schemaVersion": "droboticflow.video_face_blur.manifest/v1", "items": blur_items}},
{"name": "multiport-orbbec-technical-index.json", "data": {"schemaVersion": "droboticflow.orbbec.normalized/v1", "datasetType": "orbbec-ego", "entries": []}},
*inputs,
]
def _run_multiport(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
artifacts = _run_legacy(run_id, node_id, output_dir, node_data, _multiport_inputs(inputs), helpers)
manifest_path = pathlib.Path(output_dir) / "clips-manifest.json"
if not manifest_path.exists():
raise RuntimeError("Qwen 行为粗切没有写入技术 clips manifest")
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
clips_binding = _output(node_data, helpers, "clips")
result: list[dict[str, Any]] = []
for artifact in artifacts:
if pathlib.PurePosixPath(str(artifact.get("name", ""))).suffix.lower() not in VIDEO_SUFFIXES:
continue
if clips_binding is not None:
artifact["portId"] = str(clips_binding.get("id", ""))
artifact["portName"] = str(clips_binding.get("name", ""))
result.append(artifact)
clip_items = [item for item in manifest.get("items", []) if isinstance(item, dict)]
prelabels = {
"datasetType": "qwen3vl-rough-prelabels",
"clipCount": len(clip_items),
"items": [item.get("annotation", {}) for item in clip_items],
}
boundaries = {
"clipCount": len(clip_items),
"boundaries": [
{"clipId": item.get("clipId", ""), "startSecond": item.get("startSecond"), "endSecond": item.get("endSecond"), "rawPTS": item.get("rawPTS", {})}
for item in clip_items
],
}
summary = {
"clipCount": len(clip_items),
"rawBehaviorEventCount": len(manifest.get("rawBehaviorEvents", []) if isinstance(manifest.get("rawBehaviorEvents"), list) else []),
"technicalBlockCount": len(manifest.get("technicalBlocks", []) if isinstance(manifest.get("technicalBlocks"), list) else []),
"model": str((manifest.get("provenance") or {}).get("modelId", "")) if isinstance(manifest.get("provenance"), dict) else "",
"timeSource": "PTS_US overlay",
}
write = helpers["write_json_artifact"]
result.append(write(run_id, node_id, output_dir, "rough-prelabels-dataset.json", prelabels, output=_output(node_data, helpers, "prelabels")))
result.append(write(run_id, node_id, output_dir, "rough-boundaries.json", boundaries, output=_output(node_data, helpers, "boundaries")))
result.append(write(run_id, node_id, output_dir, "rough-inference-summary.json", summary, output=_output(node_data, helpers, "inferenceSummary")))
return result
def run(
run_id: str,
node_id: str,
output_dir: Any,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "clips") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -267,7 +267,7 @@ def _process_video_stream(
}
def run(
def _run_legacy(
run_id: str,
node_id: str,
output_dir: pathlib.Path,
@ -475,3 +475,89 @@ def run(
helpers["collect_output_artifacts"](run_id, node_id, output_blurred_dir, node_data=node_data, output=binding)
)
return artifacts
def _output(node_data: dict[str, Any], helpers: HelperMap, name: str) -> dict[str, Any] | None:
return helpers["output_binding"](node_data, name=name)
def _artifact_port(artifact: dict[str, Any]) -> str:
return str(artifact.get("portId") or artifact.get("portName") or "").strip()
def _is_video_artifact(artifact: dict[str, Any]) -> bool:
return str(artifact.get("type", "")).lower() == "video" or pathlib.PurePosixPath(str(artifact.get("name", ""))).suffix.lower() in VIDEO_SUFFIXES
def _run_multiport(
run_id: str,
node_id: str,
output_dir: pathlib.Path,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
videos = [artifact for artifact in inputs if _artifact_port(artifact) == "videos" or _is_video_artifact(artifact)]
timestamps = [artifact for artifact in inputs if _artifact_port(artifact) == "timestamps" or str(artifact.get("name", "")).lower().endswith("_pts.csv")]
if not videos:
raise RuntimeError("视频人脸脱敏多端口路径需要 videos 视频集合")
timestamp_by_stem = {
pathlib.PurePosixPath(str(item.get("name", ""))).stem.removesuffix("_pts"): item
for item in timestamps
if str(item.get("name", ""))
}
items: list[dict[str, Any]] = []
for artifact in videos:
name = str(artifact.get("name", "")).strip() or "video.mp4"
stem = pathlib.PurePosixPath(name).stem.removeprefix("blurred_")
pts = timestamp_by_stem.get(stem)
items.append(
{
"filename": name,
"path": str(artifact.get("path", "")),
"source": {"path": str(artifact.get("path", ""))},
"sizeBytes": int(artifact.get("sizeBytes", 0) or 0),
"pairedFiles": {"pts": str(pts.get("path", "")) if isinstance(pts, dict) else ""},
}
)
synthetic_inputs = [{"name": "multiport-videos-adapter.json", "data": {"datasetType": "video-collection", "items": items}}, *inputs]
legacy_artifacts = _run_legacy(run_id, node_id, output_dir, node_data, synthetic_inputs, helpers)
video_binding = _output(node_data, helpers, "blurredVideos")
output: list[dict[str, Any]] = []
for artifact in legacy_artifacts:
if not _is_video_artifact(artifact):
continue
if video_binding is not None:
artifact["portId"] = str(video_binding.get("id", ""))
artifact["portName"] = str(video_binding.get("name", ""))
output.append(artifact)
manifest_path = output_dir / "blurred-manifest.json"
manifest: dict[str, Any] = {}
if manifest_path.exists():
try:
import json
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
except Exception:
manifest = {}
summary = {
"itemCount": int(manifest.get("itemCount", len(output)) or len(output)),
"totalFramesProcessed": int(manifest.get("totalFramesProcessed", 0) or 0),
"totalFacesDetected": int(manifest.get("totalFacesDetected", 0) or 0),
"detectionMethod": str((manifest.get("method") or {}).get("detectionMethod", "")) if isinstance(manifest.get("method"), dict) else "",
"preservePts": bool((manifest.get("method") or {}).get("preservePts", False)) if isinstance(manifest.get("method"), dict) else False,
}
output.append(helpers["write_json_artifact"](run_id, node_id, output_dir, "face-blur-summary.json", summary, output=_output(node_data, helpers, "detectionSummary")))
return output
def run(
run_id: str,
node_id: str,
output_dir: pathlib.Path,
node_data: dict[str, Any],
inputs: list[dict[str, Any]],
helpers: HelperMap,
) -> list[dict[str, Any]]:
if _output(node_data, helpers, "blurredVideos") is not None:
return _run_multiport(run_id, node_id, output_dir, node_data, inputs, helpers)
return _run_legacy(run_id, node_id, output_dir, node_data, inputs, helpers)

View File

@ -1,6 +1,8 @@
const operatorTypes = new Set(["builtin", "custom", "lightweight"]);
const portTypes = new Set(["json", "image", "video", "tensor", "file"]);
const portTransmissions = new Set(["", "bus", "oss", "shm", "stream"]);
const portContainers = new Set(["single", "collection", "directory", "dataset"]);
const portPayloadModes = new Set(["inline", "ref"]);
const businessStages = new Set(["", "collect", "process", "clean", "validate", "annotate", "audit", "train"]);
const positiveInteger = /^[1-9]\d*$/;
const positiveResourceQuantity = /^(?:[1-9]\d*(?:\.\d+)?|0\.\d+)(?:(?:[eE][+-]?\d+)|(?:[numkKMGTP](?:i)?))?$/;
@ -22,14 +24,22 @@ function normalizeOperatorType(value) {
function normalizePorts(items) {
return Array.isArray(items)
? items.map((item) => ({
...item,
id: trimString(item?.id),
name: trimString(item?.name),
type: trimString(item?.type).toLowerCase(),
description: trimString(item?.description),
transmission: trimString(item?.transmission).toLowerCase(),
}))
? items.map((item) => {
const container = trimString(item?.container).toLowerCase();
const payloadMode = trimString(item?.payloadMode).toLowerCase();
const role = trimString(item?.role).toLowerCase();
return {
...item,
id: trimString(item?.id),
name: trimString(item?.name),
type: trimString(item?.type).toLowerCase(),
...(container ? { container } : {}),
...(payloadMode ? { payloadMode } : {}),
...(role ? { role } : {}),
description: trimString(item?.description),
transmission: trimString(item?.transmission).toLowerCase(),
};
})
: [];
}
@ -95,6 +105,12 @@ function validatePorts(field, items) {
if (!portTypes.has(item.type)) {
return `${prefix}.type must be json, image, video, tensor, or file`;
}
if (item.container && !portContainers.has(item.container)) {
return `${prefix}.container must be single, collection, directory, or dataset`;
}
if (item.payloadMode && !portPayloadModes.has(item.payloadMode)) {
return `${prefix}.payloadMode must be inline or ref`;
}
if (!portTransmissions.has(item.transmission || "")) {
return `${prefix}.transmission must be bus, oss, shm, or stream`;
}

49
src/lib/port-contract.js Normal file
View File

@ -0,0 +1,49 @@
const containers = new Set(["single", "collection", "directory", "dataset"]);
const modes = new Set(["inline", "ref"]);
function words(port = {}) {
return [port.id, port.name, port.description, port.role].filter(Boolean).join(" ").toLowerCase();
}
function legacyContainer(port = {}) {
const value = words(port);
if (value.includes("directory") || value.includes("目录")) return "directory";
if (value.includes("dataset") || value.includes("数据集")) return "dataset";
if (["manifest", "collection", "集合", "清单", "videos", "clips", "annotations", "prelabels", "approved", "rejected", "packages"].some((token) => value.includes(token))) return "collection";
return "single";
}
export function effectivePortContract(port = {}) {
const explicitContainer = String(port.container || "").trim().toLowerCase();
const container = containers.has(explicitContainer) ? explicitContainer : legacyContainer(port);
const explicitPayloadMode = String(port.payloadMode || "").trim().toLowerCase();
const payloadMode = modes.has(explicitPayloadMode)
? explicitPayloadMode
: String(port.transmission || "").trim().toLowerCase() === "oss" || port.type !== "json" || container !== "single"
? "ref"
: "inline";
return {
type: String(port.type || "json").trim().toLowerCase(),
container,
payloadMode,
role: String(port.role || "").trim().toLowerCase(),
legacy: !containers.has(explicitContainer) || !modes.has(explicitPayloadMode),
};
}
export function portDisplayLabel(port = {}) {
const contract = effectivePortContract(port);
if (contract.container === "directory") return contract.type === "image" ? "图片目录" : "通用目录";
if (contract.container === "dataset") return "数据集";
if (contract.container === "collection") {
if (contract.type === "video") return "视频集合";
if (contract.type === "image") return "图片集合";
if (contract.type === "file") return "文件集合";
return "结构化集合";
}
if (contract.type === "video") return "单视频";
if (contract.type === "image") return "单图片";
if (contract.type === "json") return "结构化值";
if (contract.type === "tensor") return "张量";
return "单文件";
}

View File

@ -2,6 +2,17 @@ function normalize(value) {
return String(value || "").trim();
}
function portContractFields(port, fallback = {}) {
const container = normalize(port?.container) || normalize(fallback?.container);
const payloadMode = normalize(port?.payloadMode) || normalize(fallback?.payloadMode);
const role = normalize(port?.role) || normalize(fallback?.role);
return {
...(container ? { container } : {}),
...(payloadMode ? { payloadMode } : {}),
...(role ? { role } : {}),
};
}
export function rootNodeIds(nodes, edges) {
const roots = new Set((nodes || []).map((node) => normalize(node?.id)).filter(Boolean));
for (const edge of edges || []) {
@ -59,9 +70,10 @@ export function syncRootWorkflowInputs(nodes, edges, existingInputs = []) {
const targetKey = `${nodeId}::${portId}`;
const current = existingByTarget.get(targetKey);
if (current && !consumed.has(current.id)) {
result.push({
...current,
type: port.type,
result.push({
...current,
type: port.type,
...portContractFields(port, current),
required: Boolean(port.required || current.required),
bindings: (current.bindings || []).filter((binding) => {
const boundNode = (nodes || []).find((candidate) => candidate.id === binding.nodeId);
@ -76,6 +88,7 @@ export function syncRootWorkflowInputs(nodes, edges, existingInputs = []) {
name: normalize(port.name) || `${node?.data?.label || nodeId} / ${portId}`,
description: port.description || "",
type: port.type,
...portContractFields(port),
required: Boolean(port.required),
bindings: [{ nodeId, targetPortId: portId }],
});
@ -120,6 +133,10 @@ export function parseWorkflowRunInputs(definitions, drafts) {
continue;
}
if (draft.mode === "inline") {
if (definition.payloadMode === "ref") {
throw new Error(`输入“${definition.name}”必须使用引用(ref)方式`);
}
if (!String(draft.inlineText || "").trim()) {
if (definition.required && !definition.defaultPayload) {
throw new Error(`必填输入“${definition.name}”不能为空`);
@ -149,6 +166,9 @@ export function parseWorkflowRunInputs(definitions, drafts) {
if (!connectionId || !bucket || (kind === "object" ? !key : !prefix)) {
throw new Error(`输入“${definition.name}”的对象存储引用不完整`);
}
if (definition.payloadMode === "inline") {
throw new Error(`输入“${definition.name}”必须使用内联(inline)方式`);
}
inputs[definition.id] = {
mode: "ref",
type: definition.type,

View File

@ -85,6 +85,7 @@ import { buildWorkflowCapabilityPath, canAccessWorkflowCapability } from "../lib
import { cn } from "../lib/utils";
import { getActionErrorMessage } from "../lib/action-errors.js";
import { artifactTransferMode, inlineArtifactEntries, inlineArtifactValue, isCollectionArtifact } from "../lib/artifact-presentation.js";
import { effectivePortContract, portDisplayLabel } from "../lib/port-contract.js";
import { formatClockTime, formatCompactDateTime } from "../lib/datetime";
import { buildDataAssetsPath, DATA_ASSET_PACKAGES_TAB, DATA_ASSET_SOURCE_TAB } from "../lib/data-assets.js";
import { getWorkflowGPUCapacityBlocker, gpuCapacityStatus, hasPositiveGPURequest } from "../lib/gpu-capacity.js";
@ -239,6 +240,53 @@ function InlineArtifactPreview({ artifact }: { artifact: ExecutionData }) {
);
}
function PortContractFields({
port,
onChange,
disabled = false,
}: {
port: PortDefinition;
onChange: (patch: Partial<PortDefinition>) => void;
disabled?: boolean;
}) {
const contract = effectivePortContract(port);
return (
<>
<select
aria-label={`${port.name || port.id} 容器`}
className="bg-transparent text-[10px] text-gray-500 focus:outline-none"
value={contract.container}
onChange={(event) => onChange({ container: event.target.value as PortDefinition["container"] })}
disabled={disabled}
>
<option value="single">单项</option>
<option value="collection">集合</option>
<option value="directory">目录</option>
<option value="dataset">数据集</option>
</select>
<select
aria-label={`${port.name || port.id} 载荷方式`}
className="bg-transparent text-[10px] text-gray-500 focus:outline-none"
value={contract.payloadMode}
onChange={(event) => onChange({ payloadMode: event.target.value as PortDefinition["payloadMode"] })}
disabled={disabled}
>
<option value="inline">inline</option>
<option value="ref">ref</option>
</select>
<input
aria-label={`${port.name || port.id} 角色`}
className="w-16 bg-transparent text-[10px] text-gray-500 placeholder:text-gray-700 focus:outline-none"
value={port.role || ""}
placeholder="角色"
onChange={(event) => onChange({ role: event.target.value })}
readOnly={disabled}
disabled={disabled}
/>
</>
);
}
type ReferencePickerTarget = {
scope: "workflow-default" | "run" | "production-run" | "debug-run";
inputId: string;
@ -499,7 +547,9 @@ const OperatorNode = memo(({ data, selected }: NodeProps<OperatorNodeData>) => {
{port.name}
{port.required ? <span className="ml-0.5 text-red-400">*</span> : null}
</span>
<span className="text-[8px] text-gray-500 uppercase mt-0.5">{port.type}</span>
<span className="text-[8px] text-gray-500 uppercase mt-0.5">
{portDisplayLabel(port)} · {effectivePortContract(port).payloadMode}{port.role ? ` · ${port.role}` : ""}
</span>
</div>
</div>
))}
@ -511,7 +561,9 @@ const OperatorNode = memo(({ data, selected }: NodeProps<OperatorNodeData>) => {
<div key={port.id || `out-${i}`} className="flex items-center justify-end gap-2 relative text-right">
<div className="flex flex-col">
<span className="text-[10px] text-gray-300 font-medium leading-none">{port.name}</span>
<span className="text-[8px] text-gray-500 uppercase mt-0.5">{port.type}</span>
<span className="text-[8px] text-gray-500 uppercase mt-0.5">
{portDisplayLabel(port)} · {effectivePortContract(port).payloadMode}{port.role ? ` · ${port.role}` : ""}
</span>
</div>
<Handle
type="source"
@ -7737,6 +7789,8 @@ export default function WorkflowEditor() {
id: `in-${Date.now()}`,
name: "new_input",
type: "json",
container: "single",
payloadMode: "inline",
required: true,
},
];
@ -7776,6 +7830,7 @@ export default function WorkflowEditor() {
newInputs[idx] = {
...port,
type: e.target.value,
payloadMode: e.target.value === "json" ? effectivePortContract(port).payloadMode : "ref",
};
updateNodeData({ inputs: newInputs });
}}
@ -7787,6 +7842,15 @@ export default function WorkflowEditor() {
<option value="tensor">Tensor</option>
<option value="file">File</option>
</select>
<PortContractFields
port={port}
disabled={isReadOnly}
onChange={(patch) => {
const newInputs = [...selectedNode.data.inputs];
newInputs[idx] = { ...port, ...patch };
updateNodeData({ inputs: newInputs });
}}
/>
<label className="flex items-center gap-1 text-[9px] text-gray-500">
<input
type="checkbox"
@ -7834,6 +7898,8 @@ export default function WorkflowEditor() {
id: `out-${Date.now()}`,
name: "new_output",
type: "json",
container: "single",
payloadMode: "inline",
},
];
updateNodeData({ outputs: newOutputs });
@ -7874,6 +7940,7 @@ export default function WorkflowEditor() {
newOutputs[idx] = {
...port,
type: e.target.value,
payloadMode: e.target.value === "json" ? effectivePortContract(port).payloadMode : "ref",
};
updateNodeData({
outputs: newOutputs,
@ -7887,6 +7954,15 @@ export default function WorkflowEditor() {
<option value="tensor">Tensor</option>
<option value="file">File</option>
</select>
<PortContractFields
port={port}
disabled={isReadOnly}
onChange={(patch) => {
const newOutputs = [...selectedNode.data.outputs];
newOutputs[idx] = { ...port, ...patch };
updateNodeData({ outputs: newOutputs });
}}
/>
{!isReadOnly && (
<button
onClick={() => {

View File

@ -2,6 +2,7 @@ import { apiRequest } from "./client";
import type { Edge, Node } from "reactflow";
import type {
HyperParam,
PortContainer,
PortTransmission,
PortType,
ScanConfig,
@ -60,8 +61,8 @@ export interface GeneratedOperator {
gpuLimit?: string;
sharedMemorySize?: string;
};
inputs: { name: string; type: PortType; transmission: PortTransmission; description?: string }[];
outputs: { name: string; type: PortType; transmission: PortTransmission; description?: string }[];
inputs: { name: string; type: PortType; container?: PortContainer; payloadMode?: "inline" | "ref"; role?: string; transmission: PortTransmission; description?: string }[];
outputs: { name: string; type: PortType; container?: PortContainer; payloadMode?: "inline" | "ref"; role?: string; transmission: PortTransmission; description?: string }[];
hyperparams: { key: string; value: string; description?: string; type?: string }[];
skillDefinition: string;
publicationStatus?: "draft" | "built" | "verified" | "published";

View File

@ -243,11 +243,15 @@ export interface Project {
export type PortType = "json" | "image" | "video" | "tensor" | "file";
export type PortTransmission = "bus" | "oss" | "shm" | "stream";
export type PortContainer = "single" | "collection" | "directory" | "dataset";
export interface PortDefinition {
id: string;
name: string;
type: PortType;
container?: PortContainer;
payloadMode?: ArtifactTransferMode;
role?: string;
required?: boolean;
description?: string;
transmission?: PortTransmission; // Data transfer strategy
@ -288,6 +292,9 @@ export interface WorkflowInputDefinition {
name: string;
description?: string;
type: PortType;
container?: PortContainer;
payloadMode?: ArtifactTransferMode;
role?: string;
required: boolean;
defaultPayload?: ArtifactPayload;
bindings: WorkflowInputTarget[];

View File

@ -2,6 +2,11 @@ import json
from pathlib import Path
from backend.operators.builtin.orbbec_data_normalize import operator as orbbec_operator
from backend.operators.builtin.directory_scan import operator as directory_operator
from backend.operators.builtin.video_face_blur import operator as blur_operator
from backend.operators.builtin.qwen_behavior_rough_cut import operator as qwen_operator
from backend.operators.builtin.annotation_gate import operator as annotation_gate_operator
from backend.operators.builtin.package import operator as package_operator
from backend.operators.builtin.semantic_prelabel import operator as semantic_operator
@ -76,6 +81,269 @@ def test_orbbec_normalizer_pairs_real_capture_files(tmp_path):
assert all(item["pairedFiles"]["imu"].endswith("_imu.csv") for item in payload["items"])
def test_directory_reader_multiport_emits_real_collection_artifacts(tmp_path):
source = tmp_path / "capture"
source.mkdir()
for name in ("left.mp4", "frame.jpg", "calibration.yaml"):
(source / name).write_bytes(b"fixture")
def output_binding(node_data, index=0, name=""):
for output in node_data["outputs"]:
if output["id"] == name or output["name"] == name:
return output
return node_data["outputs"][index]
def build_virtual_artifact(run_id, node_id, name, path, artifact_type, size_bytes, data=None, metadata=None, output=None):
return {
"id": f"{run_id}-{node_id}-{name}",
"name": name,
"path": str(path),
"type": artifact_type,
"sizeBytes": size_bytes,
"data": data or {},
"portId": output.get("id", "") if output else "",
"portName": output.get("name", "") if output else "",
}
def write_json_artifact(run_id, node_id, output_dir, name, payload, output=None):
path = Path(output_dir) / name
path.write_text(json.dumps(payload), encoding="utf-8")
return build_virtual_artifact(run_id, node_id, name, path, "json", path.stat().st_size, payload, output=output)
def list_source_entries(root, _pattern):
return [
{"path": item.name, "sizeBytes": item.stat().st_size, "mimeType": "application/octet-stream"}
for item in sorted(Path(root).iterdir())
if item.is_file()
]
node_data = {
"hyperparams": [{"key": "SOURCE_PATH", "value": str(source)}],
"outputs": [
{"id": "directory", "name": "directory"},
{"id": "videos", "name": "videos"},
{"id": "images", "name": "images"},
{"id": "files", "name": "files"},
{"id": "summary", "name": "summary"},
],
}
artifacts = directory_operator.run(
"run-directory",
"directory",
tmp_path,
node_data,
[],
{
"hyperparams": lambda data: {item["key"]: item.get("value", "") for item in data.get("hyperparams", [])},
"resolve_source_path": lambda params, _inputs: Path(params["SOURCE_PATH"]),
"list_source_entries": list_source_entries,
"output_binding": output_binding,
"build_virtual_artifact": build_virtual_artifact,
"write_json_artifact": write_json_artifact,
"canonical_bos_path": lambda bucket, key: f"bos://{bucket}/{key}",
},
)
by_port = {}
for artifact in artifacts:
by_port.setdefault(artifact["portId"], []).append(artifact)
assert {"directory", "videos", "images", "files", "summary"}.issubset(by_port)
assert by_port["videos"][0]["name"] == "left.mp4"
assert by_port["images"][0]["name"] == "frame.jpg"
assert by_port["files"][0]["name"] == "calibration.yaml"
assert by_port["summary"][0]["data"]["videoCount"] == 1
assert all("manifest" not in artifact["name"] for artifact in artifacts)
def test_orbbec_normalizer_multiport_binds_camera_and_pts_outputs(tmp_path):
capture = "Orbbec_Ego_AZER76400GG_19700102_061040"
entries = []
for suffix, mime in [
("camera_left_part0001.mp4", "video/mp4"),
("camera_left_part0001_pts.csv", "text/csv"),
("camera_right_part0001.mp4", "video/mp4"),
("camera_right_part0001_pts.csv", "text/csv"),
("audio.wav", "audio/x-wav"),
("imu.csv", "text/csv"),
("calibration_camera.yaml", "application/x-yaml"),
]:
path = f"{capture}/{capture}_{suffix}"
entries.append({"path": path, "sizeBytes": 128, "mimeType": mime, "source": {"path": f"bos://testxyz/fanyu/{path}"}})
outputs = [
{"id": "leftVideos", "name": "leftVideos"}, {"id": "rightVideos", "name": "rightVideos"},
{"id": "videoPts", "name": "videoPts"}, {"id": "audio", "name": "audio"},
{"id": "imu", "name": "imu"}, {"id": "calibrations", "name": "calibrations"},
{"id": "summary", "name": "summary"},
]
def output_binding(_node_data, index=0, name=""):
return next((item for item in outputs if item["id"] == name or item["name"] == name), outputs[index])
def virtual(run_id, node_id, name, path, artifact_type, size_bytes, data=None, metadata=None, output=None):
return {"id": f"{run_id}-{node_id}-{name}", "name": name, "path": path, "type": artifact_type, "sizeBytes": size_bytes, "data": data or {}, "portId": output["id"], "portName": output["name"]}
def write(run_id, node_id, output_dir, name, payload, output=None):
path = Path(output_dir) / name
path.write_text(json.dumps(payload), encoding="utf-8")
return virtual(run_id, node_id, name, str(path), "json", path.stat().st_size, payload, output=output)
artifacts = orbbec_operator.run(
"run-multi",
"normalize",
tmp_path,
{"hyperparams": [{"key": "CAMERA_SIDE", "value": "both"}, {"key": "REQUIRE_STEREO", "value": "true"}], "outputs": outputs},
[{"data": {"sourcePath": "bos://testxyz/fanyu", "entries": entries}}],
{"hyperparams": lambda data: {item["key"]: item.get("value", "") for item in data.get("hyperparams", [])}, "first_payload_with_keys": helpers(tmp_path)["first_payload_with_keys"], "output_binding": output_binding, "build_virtual_artifact": virtual, "write_json_artifact": write},
)
ports = {item["portId"] for item in artifacts}
assert {"leftVideos", "rightVideos", "videoPts", "audio", "imu", "calibrations", "summary"}.issubset(ports)
assert all("manifest" not in item["name"] for item in artifacts)
def test_face_blur_multiport_rebinds_videos_and_summary(tmp_path):
outputs = [{"id": "blurredVideos", "name": "blurredVideos"}, {"id": "detectionSummary", "name": "detectionSummary"}]
def output_binding(_node_data, index=0, name=""):
return next((item for item in outputs if item["id"] == name or item["name"] == name), outputs[index])
def write(run_id, node_id, output_dir, name, payload, output=None):
path = Path(output_dir) / name
path.write_text(json.dumps(payload), encoding="utf-8")
return {"id": f"{run_id}-{name}", "name": name, "path": str(path), "type": "json", "data": payload, "portId": output["id"], "portName": output["name"]}
original = blur_operator._run_legacy
def fake_legacy(run_id, node_id, output_dir, node_data, inputs, helpers):
video_path = Path(output_dir) / "blurred" / "blurred_left.mp4"
video_path.parent.mkdir(parents=True, exist_ok=True)
video_path.write_bytes(b"video")
(Path(output_dir) / "blurred-manifest.json").write_text(json.dumps({"itemCount": 1, "totalFramesProcessed": 4, "totalFacesDetected": 2, "method": {"detectionMethod": "haar", "preservePts": True}}), encoding="utf-8")
return [
{"name": "blurred-manifest.json", "path": str(Path(output_dir) / "blurred-manifest.json"), "type": "json", "portId": "out-1"},
{"name": "blurred_left.mp4", "path": str(video_path), "type": "video", "portId": "out-1"},
]
blur_operator._run_legacy = fake_legacy
try:
artifacts = blur_operator.run(
"run-blur",
"blur",
tmp_path,
{"outputs": outputs},
[{"name": "left.mp4", "path": str(tmp_path / "left.mp4"), "type": "video", "portId": "videos"}],
{"output_binding": output_binding, "write_json_artifact": write},
)
finally:
blur_operator._run_legacy = original
assert [item["portId"] for item in artifacts] == ["blurredVideos", "detectionSummary"]
assert artifacts[-1]["data"]["totalFacesDetected"] == 2
def test_qwen_multiport_rebinds_clips_prelabels_boundaries_and_summary(tmp_path):
outputs = [
{"id": "clips", "name": "clips"}, {"id": "prelabels", "name": "prelabels"},
{"id": "boundaries", "name": "boundaries"}, {"id": "inferenceSummary", "name": "inferenceSummary"},
]
def output_binding(_node_data, index=0, name=""):
return next((item for item in outputs if item["id"] == name or item["name"] == name), outputs[index])
def write(run_id, node_id, output_dir, name, payload, output=None):
path = Path(output_dir) / name
path.write_text(json.dumps(payload), encoding="utf-8")
return {"id": f"{run_id}-{name}", "name": name, "path": str(path), "type": "json", "data": payload, "portId": output["id"], "portName": output["name"]}
original = qwen_operator._run_legacy
def fake_legacy(run_id, node_id, output_dir, node_data, inputs, helpers):
manifest = {
"items": [{"clipId": "clip-1", "clipName": "clip-1.mp4", "startSecond": 1.0, "endSecond": 3.0, "rawPTS": {"startTimestampUs": 100}, "annotation": {"actions": []}}],
"rawBehaviorEvents": [{}], "technicalBlocks": [{}], "provenance": {"modelId": "Qwen/Qwen3-VL-8B-Instruct"},
}
(Path(output_dir) / "clips-manifest.json").write_text(json.dumps(manifest), encoding="utf-8")
return [{"name": "clips-manifest.json", "type": "json", "portId": "out-1"}, {"name": "clip-1.mp4", "type": "video", "path": "bos://testxyz/blurred.mp4", "portId": "out-1"}]
qwen_operator._run_legacy = fake_legacy
try:
artifacts = qwen_operator.run(
"run-qwen", "qwen", tmp_path, {"outputs": outputs},
[{"name": "blurred_left.mp4", "path": "bos://testxyz/blurred_left.mp4", "type": "video", "portId": "videos"}, {"name": "left_pts.csv", "path": "bos://testxyz/left_pts.csv", "type": "file", "portId": "timestamps"}],
{"output_binding": output_binding, "write_json_artifact": write},
)
finally:
qwen_operator._run_legacy = original
assert [item["portId"] for item in artifacts] == ["clips", "prelabels", "boundaries", "inferenceSummary"]
assert artifacts[1]["data"]["items"][0]["actions"] == []
assert artifacts[2]["data"]["boundaries"][0]["clipId"] == "clip-1"
def test_annotation_gate_multiport_binds_approved_annotations_rejected_and_summary(tmp_path):
outputs = [
{"id": "approvedVideos", "name": "approvedVideos"}, {"id": "annotations", "name": "annotations"},
{"id": "rejected", "name": "rejected"}, {"id": "aggregateSummary", "name": "aggregateSummary"},
]
def output_binding(_node_data, index=0, name=""):
return next((item for item in outputs if item["id"] == name or item["name"] == name), outputs[index])
def write(run_id, node_id, output_dir, name, payload, output=None):
path = Path(output_dir) / name
path.write_text(json.dumps(payload), encoding="utf-8")
return {"id": f"{run_id}-{name}", "name": name, "path": str(path), "type": "json", "data": payload, "portId": output["id"], "portName": output["name"]}
artifacts = annotation_gate_operator.run(
"run-human", "human", tmp_path,
{"outputs": outputs, "hyperparams": [{"key": "ANNOTATION_TEMPLATE_ID", "value": "template"}, {"key": "ANNOTATION_WORKGROUP_ID", "value": "workgroup"}]},
[{"name": "clip.mp4", "type": "video", "portId": "clips"}, {"name": "prelabels.json", "type": "json", "portId": "prelabels", "data": {"items": [{"actions": []}]}}, {"name": "boundaries.json", "type": "json", "portId": "boundaries", "data": {"boundaries": [{"clipId": "clip"}]}}],
{"hyperparams": lambda data: {item["key"]: item.get("value", "") for item in data.get("hyperparams", [])}, "output_binding": output_binding, "payloads_from_inputs": lambda items: [item.get("data", {}) for item in items], "write_json_artifact": write},
)
assert [item["portId"] for item in artifacts] == ["approvedVideos", "annotations", "rejected", "aggregateSummary"]
assert artifacts[-1]["data"]["clipCount"] == 1
def test_package_multiport_binds_directory_media_semantic_segment_and_summary(tmp_path):
outputs = [
{"id": "packageDirectory", "name": "packageDirectory"}, {"id": "finalVideos", "name": "finalVideos"},
{"id": "semanticFiles", "name": "semanticFiles"}, {"id": "segmentFiles", "name": "segmentFiles"},
{"id": "deliverySummary", "name": "deliverySummary"},
]
def output_binding(_node_data, index=0, name=""):
return next((item for item in outputs if item["id"] == name or item["name"] == name), outputs[index])
def build_virtual(run_id, node_id, name, path, artifact_type, size_bytes, data=None, metadata=None, output=None):
return {"id": f"{run_id}-{name}", "name": name, "path": path, "type": artifact_type, "data": data or {}, "portId": output["id"], "portName": output["name"]}
def write(run_id, node_id, output_dir, name, payload, output=None):
path = Path(output_dir) / name
path.write_text(json.dumps(payload), encoding="utf-8")
return {"id": f"{run_id}-{name}", "name": name, "path": str(path), "type": "json", "data": payload, "portId": output["id"], "portName": output["name"]}
original = package_operator._run_fanyu_v5
def fake_v5(run_id, node_id, output_dir, node_data, inputs, helpers):
root = Path(output_dir) / "packages" / "clip-1_package"
root.mkdir(parents=True, exist_ok=True)
for name in ("clip-1.mp4", "semantic.json", "segment.json"):
(root / name).write_bytes(b"fixture")
(Path(output_dir) / "packages-manifest.json").write_text(json.dumps({"packageCount": 1}), encoding="utf-8")
return []
def collect(_run, _node, root, node_data=None):
return [{"name": item.name, "path": str(item), "type": "video" if item.suffix == ".mp4" else "json"} for item in Path(root).rglob("*") if item.is_file()]
package_operator._run_fanyu_v5 = fake_v5
try:
artifacts = package_operator.run(
"run-package", "package", tmp_path, {"outputs": outputs, "hyperparams": [{"key": "REQUIRE_FINAL_ACCEPTANCE", "value": "true"}]},
[{"name": "clip-1.mp4", "type": "video", "portId": "approvedVideos"}, {"name": "annotations-manifest.json", "type": "json", "portId": "annotations", "data": {"items": [{"clipId": "clip-1"}]}}],
{"output_binding": output_binding, "build_virtual_artifact": build_virtual, "write_json_artifact": write, "collect_output_artifacts": collect, "hyperparams": lambda data: {item["key"]: item.get("value", "") for item in data.get("hyperparams", [])}},
)
finally:
package_operator._run_fanyu_v5 = original
assert {item["portId"] for item in artifacts} == {"packageDirectory", "finalVideos", "semanticFiles", "segmentFiles", "deliverySummary"}
def test_semantic_prelabel_maps_actions_to_template_version(tmp_path):
annotations = {
"annotationCount": 1,