forked from longtao.wu/droboticflow
✨ Implement Fanyu v3 task pools and pose delivery
This commit is contained in:
parent
f31fd7ae55
commit
6d6858c6c5
26
Dockerfile.headpose-service
Normal file
26
Dockerfile.headpose-service
Normal file
@ -0,0 +1,26 @@
|
||||
FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime
|
||||
|
||||
ARG HEADPOSE_MODEL_URL=https://cloud.ovgu.de/s/Q67RnLDy6JKLRWm/download/6DRepNet_300W_LP_AFLW2000.pth
|
||||
ARG HEADPOSE_MODEL_SHA256=9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive \
|
||||
HEADPOSE_MODEL_PATH=/opt/models/6DRepNet_300W_LP_AFLW2000.pth \
|
||||
HEADPOSE_MODEL_SHA256=sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018 \
|
||||
HEADPOSE_LICENSE_ID=MIT \
|
||||
HEADPOSE_OUTPUT_ROOT=/workspace/system/headpose-service \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates curl libglib2.0-0 libgl1 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY services/headpose/requirements.txt /app/services/headpose/requirements.txt
|
||||
RUN python -m pip install --no-cache-dir -r /app/services/headpose/requirements.txt \
|
||||
&& mkdir -p /opt/models \
|
||||
&& curl -L --fail --retry 5 --max-time 900 "$HEADPOSE_MODEL_URL" -o "$HEADPOSE_MODEL_PATH" \
|
||||
&& echo "$HEADPOSE_MODEL_SHA256 $HEADPOSE_MODEL_PATH" | sha256sum -c -
|
||||
|
||||
COPY services/headpose /app/services/headpose
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["python", "-m", "uvicorn", "services.headpose.app:app", "--host", "0.0.0.0", "--port", "8080", "--workers", "1"]
|
||||
@ -5312,6 +5312,8 @@ BUILTIN_HANDLER_RULES: tuple[tuple[str, tuple[str, ...]], ...] = (
|
||||
("dexycb_dataset_validate", ("dexycb 数据集", "dex-ycb", "dexycb", "ycb hand", "hand grasping object")),
|
||||
("ho3d_dataset_validate", ("ho3d 数据集", "ho-3d", "ho3d", "h2o3d", "h2o-3d", "honnotate")),
|
||||
("wilor_hand_pose", ("wilor", "wilor 手部", "手部姿态估计", "3d hand pose", "hand pose estimation")),
|
||||
("head_pose", ("headpose", "head pose", "头部姿态", "头部姿态估计")),
|
||||
("delivery_options", ("交付选项透传", "delivery options")),
|
||||
("hand_removal", ("hand removal", "视频去手", "手部移除", "去除手臂", "propainter")),
|
||||
("hand_object_pose_validate", ("手-物体姿态", "手物体姿态", "hand object pose", "dexycb", "ho3d")),
|
||||
("partnet_mobility_asset_validate", ("partnet-mobility", "partnet mobility", "sapien asset", "sapien 资产", "mobility.urdf", "可交互物体")),
|
||||
@ -5421,6 +5423,8 @@ BUILTIN_HANDLERS: dict[str, BuiltinHandler] = {
|
||||
"dexycb_dataset_validate": operator_handler('backend.operators.builtin.dexycb_dataset_validate.operator'),
|
||||
"ho3d_dataset_validate": operator_handler('backend.operators.builtin.ho3d_dataset_validate.operator'),
|
||||
"wilor_hand_pose": operator_handler('backend.operators.builtin.wilor_hand_pose.operator'),
|
||||
"head_pose": operator_handler('backend.operators.builtin.head_pose.operator'),
|
||||
"delivery_options": operator_handler('backend.operators.builtin.delivery_options.operator'),
|
||||
"hand_removal": operator_handler('backend.operators.builtin.hand_removal.operator'),
|
||||
"webdataset_shard_summary": operator_handler('backend.operators.builtin.webdataset_shard_summary.operator'),
|
||||
"umi_zarr_dataset_validate": operator_handler('backend.operators.builtin.umi_zarr_dataset_validate.operator'),
|
||||
|
||||
1
backend/operators/builtin/delivery_options/__init__.py
Normal file
1
backend/operators/builtin/delivery_options/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
|
||||
16
backend/operators/builtin/delivery_options/operator.json
Normal file
16
backend/operators/builtin/delivery_options/operator.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"id": "operator-builtin-delivery-options",
|
||||
"name": "交付选项透传",
|
||||
"category": "UTIL",
|
||||
"type": "builtin",
|
||||
"runtimeHandler": "builtin_delivery_options",
|
||||
"runtimeSource": "backend/operators/builtin/delivery_options/operator.py",
|
||||
"migrationStatus": "migrated",
|
||||
"acceptance": {
|
||||
"requiresRealInputs": true,
|
||||
"mockOnlyAccepted": false,
|
||||
"simulationOnlyAccepted": false,
|
||||
"hardcodedOutputAccepted": false,
|
||||
"shallowOnlyAccepted": false
|
||||
}
|
||||
}
|
||||
34
backend/operators/builtin/delivery_options/operator.py
Normal file
34
backend/operators/builtin/delivery_options/operator.py
Normal file
@ -0,0 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable
|
||||
|
||||
|
||||
HelperMap = dict[str, Callable[..., Any]]
|
||||
|
||||
|
||||
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]]:
|
||||
payloads = helpers["payloads_from_inputs"](inputs)
|
||||
options = payloads[0] if payloads else {}
|
||||
include_handpose = bool(options.get("includeHandpose", False))
|
||||
normalized = {
|
||||
"schemaVersion": "droboticflow.delivery-options/v1",
|
||||
"includeHeadpose": True,
|
||||
"includeHandpose": include_handpose,
|
||||
}
|
||||
return [
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
output_dir,
|
||||
"delivery-options.json",
|
||||
normalized,
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
]
|
||||
1
backend/operators/builtin/head_pose/__init__.py
Normal file
1
backend/operators/builtin/head_pose/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
|
||||
16
backend/operators/builtin/head_pose/operator.json
Normal file
16
backend/operators/builtin/head_pose/operator.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"id": "operator-builtin-head-pose",
|
||||
"name": "6DRepNet Headpose",
|
||||
"category": "AI",
|
||||
"type": "builtin",
|
||||
"runtimeHandler": "builtin_head_pose",
|
||||
"runtimeSource": "backend/operators/builtin/head_pose/operator.py",
|
||||
"migrationStatus": "migrated",
|
||||
"acceptance": {
|
||||
"requiresRealInputs": true,
|
||||
"mockOnlyAccepted": false,
|
||||
"simulationOnlyAccepted": false,
|
||||
"hardcodedOutputAccepted": false,
|
||||
"shallowOnlyAccepted": false
|
||||
}
|
||||
}
|
||||
234
backend/operators/builtin/head_pose/operator.py
Normal file
234
backend/operators/builtin/head_pose/operator.py
Normal file
@ -0,0 +1,234 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from typing import Any, Callable
|
||||
|
||||
|
||||
HelperMap = dict[str, Callable[..., Any]]
|
||||
IMAGE_DIGEST_PATTERN = re.compile(r"^\S+@sha256:[a-f0-9]{64}$")
|
||||
MODEL_DIGEST_PATTERN = re.compile(r"^sha256:[a-f0-9]{64}$")
|
||||
MEDIA_SUFFIXES = {".jpg", ".jpeg", ".png", ".bmp", ".webp", ".mp4", ".mov", ".m4v", ".avi", ".mkv", ".webm"}
|
||||
|
||||
|
||||
def _media_reference(value: Any) -> str:
|
||||
if isinstance(value, list):
|
||||
for item in value:
|
||||
found = _media_reference(item)
|
||||
if found:
|
||||
return found
|
||||
return ""
|
||||
if not isinstance(value, dict):
|
||||
return ""
|
||||
for key in ("previewURL", "previewUrl", "videoURL", "videoUrl", "imageURL", "imageUrl", "mediaURL", "mediaUrl", "url", "path"):
|
||||
candidate = str(value.get(key, "")).strip()
|
||||
suffix = pathlib.PurePosixPath(urllib.parse.urlparse(candidate).path).suffix.lower()
|
||||
if candidate and suffix in MEDIA_SUFFIXES:
|
||||
return candidate
|
||||
for key in ("source", "preview", "media", "file", "items", "entries", "rows", "data"):
|
||||
found = _media_reference(value.get(key))
|
||||
if found:
|
||||
return found
|
||||
return ""
|
||||
|
||||
|
||||
def _input_reference(inputs: list[dict[str, Any]]) -> str:
|
||||
for artifact in inputs:
|
||||
found = _media_reference(artifact)
|
||||
if found:
|
||||
return found
|
||||
for artifact in inputs:
|
||||
path = pathlib.Path(str(artifact.get("path", "")).strip())
|
||||
if path.is_file() and path.suffix.lower() == ".json":
|
||||
try:
|
||||
found = _media_reference(json.loads(path.read_text(encoding="utf-8")))
|
||||
except (OSError, UnicodeDecodeError, json.JSONDecodeError):
|
||||
found = ""
|
||||
if found:
|
||||
return found
|
||||
for artifact in inputs:
|
||||
for candidate in (
|
||||
artifact.get("previewURL"),
|
||||
artifact.get("url"),
|
||||
artifact.get("path"),
|
||||
(artifact.get("data") or {}).get("source", {}).get("path") if isinstance(artifact.get("data"), dict) else "",
|
||||
):
|
||||
value = str(candidate or "").strip()
|
||||
if value:
|
||||
return value
|
||||
return ""
|
||||
|
||||
|
||||
def _post_json(url: str, payload: dict[str, Any], timeout: int) -> dict[str, Any]:
|
||||
request = urllib.request.Request(
|
||||
url,
|
||||
data=json.dumps(payload).encode("utf-8"),
|
||||
headers={"Content-Type": "application/json", "Accept": "application/json"},
|
||||
method="POST",
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=timeout) as response:
|
||||
parsed = json.loads(response.read().decode("utf-8"))
|
||||
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError) as exc:
|
||||
raise RuntimeError(f"Headpose inference request failed: {exc}") from exc
|
||||
if not isinstance(parsed, dict):
|
||||
raise RuntimeError("Headpose inference returned a non-object payload")
|
||||
return parsed
|
||||
|
||||
|
||||
def _materialize_annotated_media(base_url: str, value: str, output_dir: pathlib.Path, timeout: int) -> pathlib.Path:
|
||||
source = value.strip()
|
||||
if not source:
|
||||
raise RuntimeError("Headpose inference did not return annotatedMediaUrl")
|
||||
parsed = urllib.parse.urlparse(source)
|
||||
suffix = pathlib.PurePosixPath(parsed.path).suffix.lower() or ".mp4"
|
||||
destination = output_dir / "headpose_outputs" / f"headpose-annotated{suffix}"
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
if parsed.scheme in {"http", "https"}:
|
||||
resolved = source
|
||||
elif parsed.scheme:
|
||||
raise RuntimeError(f"Unsupported Headpose annotated media scheme: {parsed.scheme}")
|
||||
else:
|
||||
local = pathlib.Path(source)
|
||||
if local.is_file():
|
||||
shutil.copy2(local, destination)
|
||||
return destination
|
||||
resolved = urllib.parse.urljoin(base_url.rstrip("/") + "/", source.lstrip("/"))
|
||||
try:
|
||||
with urllib.request.urlopen(resolved, timeout=timeout) as response:
|
||||
destination.write_bytes(response.read())
|
||||
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError) as exc:
|
||||
raise RuntimeError(f"Headpose annotated media download failed: {exc}") from exc
|
||||
if not destination.is_file() or destination.stat().st_size <= 0:
|
||||
raise RuntimeError("Headpose annotated media is empty")
|
||||
return destination
|
||||
|
||||
|
||||
def _summary(frames: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
def stats(key: str) -> dict[str, float]:
|
||||
values = [float(frame[key]) for frame in frames]
|
||||
return {"min": min(values), "max": max(values), "mean": sum(values) / len(values)}
|
||||
|
||||
return {
|
||||
"yawDeg": stats("yawDeg"),
|
||||
"pitchDeg": stats("pitchDeg"),
|
||||
"rollDeg": stats("rollDeg"),
|
||||
"confidenceMean": sum(float(frame["confidence"]) for frame in frames) / len(frames),
|
||||
}
|
||||
|
||||
|
||||
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]]:
|
||||
params = helpers["hyperparams"](node_data)
|
||||
base_url = str(params.get("HEADPOSE_API_BASE_URL", "")).strip().rstrip("/")
|
||||
model_image = str(params.get("HEADPOSE_SERVICE_IMAGE_ID", "")).strip()
|
||||
model_digest = str(params.get("HEADPOSE_MODEL_SHA256", "")).strip().lower()
|
||||
license_id = str(params.get("HEADPOSE_LICENSE_ID", "")).strip()
|
||||
model_name = str(params.get("HEADPOSE_MODEL", "6DRepNet")).strip() or "6DRepNet"
|
||||
if not base_url or not IMAGE_DIGEST_PATTERN.fullmatch(model_image):
|
||||
raise RuntimeError("Headpose requires HEADPOSE_API_BASE_URL and a digest-pinned HEADPOSE_SERVICE_IMAGE_ID")
|
||||
if not MODEL_DIGEST_PATTERN.fullmatch(model_digest) or not license_id:
|
||||
raise RuntimeError("Headpose requires HEADPOSE_MODEL_SHA256 and HEADPOSE_LICENSE_ID")
|
||||
source = _input_reference(inputs)
|
||||
if not source:
|
||||
raise RuntimeError("Headpose requires an upstream image or video artifact")
|
||||
frame_stride = int(params.get("FRAME_STRIDE", 3) or 3)
|
||||
max_frames = int(params.get("MAX_FRAMES", 120) or 120)
|
||||
timeout = int(params.get("REQUEST_TIMEOUT_SECONDS", 300) or 300)
|
||||
response = _post_json(
|
||||
f"{base_url}/v1/headpose/infer",
|
||||
{
|
||||
"source": source,
|
||||
"frameStride": frame_stride,
|
||||
"maxFrames": max_frames,
|
||||
"model": model_name,
|
||||
"modelSha256": model_digest,
|
||||
},
|
||||
timeout,
|
||||
)
|
||||
frames = response.get("frames")
|
||||
if not isinstance(frames, list) or not frames:
|
||||
raise RuntimeError("Headpose inference returned no frame results")
|
||||
normalized_frames = []
|
||||
previous_timestamp = -1.0
|
||||
for index, frame in enumerate(frames):
|
||||
if not isinstance(frame, dict):
|
||||
raise RuntimeError("Headpose frame result must be an object")
|
||||
timestamp = float(frame.get("timestampSeconds", frame.get("timestamp", 0)))
|
||||
normalized = {
|
||||
"frameIndex": int(frame.get("frameIndex", index)),
|
||||
"timestamp": timestamp,
|
||||
"timestampSeconds": timestamp,
|
||||
"yawDeg": float(frame.get("yawDeg")),
|
||||
"pitchDeg": float(frame.get("pitchDeg")),
|
||||
"rollDeg": float(frame.get("rollDeg")),
|
||||
"confidence": float(frame.get("confidence", 0)),
|
||||
}
|
||||
if not all(math.isfinite(float(normalized[key])) for key in ("timestamp", "yawDeg", "pitchDeg", "rollDeg", "confidence")):
|
||||
raise RuntimeError("Headpose frame values must be finite")
|
||||
if timestamp < 0 or timestamp < previous_timestamp:
|
||||
raise RuntimeError("Headpose timestamps must be non-negative and monotonic")
|
||||
if any(abs(float(normalized[key])) > 180 for key in ("yawDeg", "pitchDeg", "rollDeg")):
|
||||
raise RuntimeError("Headpose angles must be in [-180, 180] degrees")
|
||||
if not 0 <= normalized["confidence"] <= 1:
|
||||
raise RuntimeError("Headpose confidence must be in [0, 1]")
|
||||
normalized_frames.append(normalized)
|
||||
previous_timestamp = timestamp
|
||||
runtime_evidence = response.get("runtimeEvidence")
|
||||
if not isinstance(runtime_evidence, dict):
|
||||
raise RuntimeError("Headpose inference returned no runtime evidence")
|
||||
if str(runtime_evidence.get("modelSha256", "")).strip().lower() != model_digest:
|
||||
raise RuntimeError("Headpose runtime model digest does not match the configured digest")
|
||||
annotated_media = _materialize_annotated_media(
|
||||
base_url,
|
||||
str(response.get("annotatedMediaUrl", "")),
|
||||
output_dir,
|
||||
timeout,
|
||||
)
|
||||
manifest = {
|
||||
"schemaVersion": "droboticflow.headpose/v1",
|
||||
"enabled": True,
|
||||
"source": source,
|
||||
"model": model_name,
|
||||
"serviceImageId": model_image,
|
||||
"modelSha256": model_digest,
|
||||
"licenseId": license_id,
|
||||
"frameCount": len(normalized_frames),
|
||||
"frames": normalized_frames,
|
||||
"summary": _summary(normalized_frames),
|
||||
"annotatedMedia": annotated_media.name,
|
||||
"runtimeEvidence": runtime_evidence,
|
||||
}
|
||||
binding = helpers["output_binding"](node_data)
|
||||
artifacts = [
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
output_dir,
|
||||
"headpose-manifest.json",
|
||||
manifest,
|
||||
output=binding,
|
||||
)
|
||||
]
|
||||
artifacts.extend(
|
||||
helpers["collect_output_artifacts"](
|
||||
run_id,
|
||||
node_id,
|
||||
annotated_media.parent,
|
||||
node_data=node_data,
|
||||
output=binding,
|
||||
)
|
||||
)
|
||||
return artifacts
|
||||
@ -16,6 +16,18 @@ def run(
|
||||
inputs: list[dict[str, Any]],
|
||||
helpers: HelperMap,
|
||||
) -> list[dict[str, Any]]:
|
||||
payloads = helpers["payloads_from_inputs"](inputs)
|
||||
params = helpers["hyperparams"](node_data)
|
||||
require_headpose = str(params.get("REQUIRE_HEADPOSE", "false")).strip().lower() in {"1", "true", "yes", "on"}
|
||||
headpose = next((item for item in payloads if item.get("schemaVersion") == "droboticflow.headpose/v1"), None)
|
||||
handpose = next(
|
||||
(item for item in payloads if item.get("schemaVersion") == "droboticflow.wilor.hand_pose_result/v1"),
|
||||
None,
|
||||
)
|
||||
if require_headpose and (headpose is None or not headpose.get("enabled")):
|
||||
raise RuntimeError("成品打包需要必选的 droboticflow.headpose/v1 结果")
|
||||
headpose_enabled = bool(headpose and headpose.get("enabled"))
|
||||
handpose_enabled = bool(handpose and handpose.get("enabled", True))
|
||||
payload = helpers["first_payload_with_keys"](inputs, "annotationCount", "items")
|
||||
if payload is None:
|
||||
payload = helpers["first_payload_with_keys"](inputs, "clipCount", "items")
|
||||
@ -72,6 +84,13 @@ def run(
|
||||
"maxConfidence": item.get("maxConfidence", 0),
|
||||
}
|
||||
config_payload = helpers["package_config_payload"](item, payload)
|
||||
config_payload["deliveryItems"] = {
|
||||
"headpose": {"enabled": bool(headpose and headpose.get("enabled")), "frameCount": headpose.get("frameCount", 0) if headpose else 0},
|
||||
"handpose": {
|
||||
"enabled": bool(handpose and handpose.get("enabled", True)),
|
||||
"status": handpose.get("status", "missing") if handpose else "missing",
|
||||
},
|
||||
}
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
@ -80,6 +99,24 @@ def run(
|
||||
quality_payload,
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
if headpose_enabled:
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
package_dir,
|
||||
f"{clip_id}_headpose.json",
|
||||
headpose,
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
if handpose_enabled:
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
package_dir,
|
||||
f"{clip_id}_handpose.json",
|
||||
handpose,
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
@ -111,15 +148,29 @@ def run(
|
||||
"meta": item.get("meta", {}),
|
||||
"source": item.get("source", {}) if isinstance(item.get("source"), dict) else {},
|
||||
"fileCount": len(package_files),
|
||||
"pipelineTags": ["quality_v1", "slicing_v1", "annotation_v1"],
|
||||
"pipelineTags": [
|
||||
"quality_v1",
|
||||
"slicing_v1",
|
||||
"annotation_v1",
|
||||
"headpose_v1",
|
||||
*( ["handpose_v1"] if handpose_enabled else [] ),
|
||||
],
|
||||
"storagePath": str(package_dir),
|
||||
"quality": quality_payload,
|
||||
"annotation": annotation_payload,
|
||||
"deliveryItems": config_payload["deliveryItems"],
|
||||
}
|
||||
)
|
||||
manifest = {
|
||||
"datasetType": "x-platform-packages",
|
||||
"packageCount": len(packages),
|
||||
"deliveryItems": {
|
||||
"headpose": {"enabled": bool(headpose and headpose.get("enabled")), "schemaVersion": headpose.get("schemaVersion") if headpose else ""},
|
||||
"handpose": {
|
||||
"enabled": bool(handpose and handpose.get("enabled", True)),
|
||||
"schemaVersion": handpose.get("schemaVersion") if handpose else "",
|
||||
},
|
||||
},
|
||||
"items": packages,
|
||||
}
|
||||
binding = helpers["output_binding"](node_data)
|
||||
|
||||
@ -186,12 +186,18 @@ def _input_ref(params: dict[str, str], inputs: list[dict[str, Any]]) -> str:
|
||||
return value
|
||||
fallback_path = ""
|
||||
for artifact in inputs:
|
||||
data = artifact.get("data") if isinstance(artifact.get("data"), dict) else {}
|
||||
if data.get("schemaVersion") == "droboticflow.delivery-options/v1" or "includeHandpose" in data:
|
||||
continue
|
||||
path = str(artifact.get("path", "")).strip()
|
||||
if path and pathlib.Path(path).is_file() and _looks_like_media_ref(path):
|
||||
return path
|
||||
if path and pathlib.Path(path).is_file() and not fallback_path:
|
||||
fallback_path = path
|
||||
for artifact in inputs:
|
||||
data = artifact.get("data") if isinstance(artifact.get("data"), dict) else {}
|
||||
if data.get("schemaVersion") == "droboticflow.delivery-options/v1" or "includeHandpose" in data:
|
||||
continue
|
||||
preview_url = _artifact_preview_url(artifact)
|
||||
if preview_url and _looks_like_media_ref(preview_url):
|
||||
return preview_url
|
||||
@ -347,6 +353,28 @@ def run(
|
||||
helpers: dict[str, Any],
|
||||
) -> list[dict[str, Any]]:
|
||||
params = helpers["hyperparams"](node_data)
|
||||
include_handpose = True
|
||||
for payload in helpers["payloads_from_inputs"](inputs):
|
||||
if payload.get("schemaVersion") == "droboticflow.delivery-options/v1" or "includeHandpose" in payload:
|
||||
include_handpose = bool(payload.get("includeHandpose", False))
|
||||
break
|
||||
if not include_handpose:
|
||||
return [
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
output_dir,
|
||||
"handpose-manifest.json",
|
||||
{
|
||||
"schemaVersion": "droboticflow.wilor.hand_pose_result/v1",
|
||||
"operator": "wilor_hand_pose",
|
||||
"enabled": False,
|
||||
"status": "skipped_by_delivery_options",
|
||||
"items": [],
|
||||
},
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
]
|
||||
base_url = str(params.get("WILOR_API_BASE_URL") or DEFAULT_WILOR_API_BASE_URL).strip().rstrip("/")
|
||||
timeout = float(_int_param(params.get("REQUEST_TIMEOUT_SECONDS", ""), 300, 10, 3600, "REQUEST_TIMEOUT_SECONDS"))
|
||||
hand_conf = _float_param(params.get("HAND_CONFIDENCE", ""), 0.30, 0.05, 0.95, "HAND_CONFIDENCE")
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
- `annotator`:提交首轮标注或返工 revision。
|
||||
- `quality_reviewer`:对当前 revision 做质检通过或打回。
|
||||
- `acceptance_reviewer`:对质检通过的 revision 做最终验收。
|
||||
- `vendor_manager`:只聚合查看所管供应商/工作组的工作量和质量,不能读取任务媒体或执行审核。
|
||||
|
||||
每个成员关系同时绑定 `projectId`、`workgroupId` 和 `vendorId`。除管理员、流程工程师和兼容管理员外,后端只返回当前用户所在分组的任务、模板、分组和工时事件;前端隐藏不是安全边界。
|
||||
|
||||
@ -21,6 +22,7 @@
|
||||
- `POST /api/annotation-tasks/{id}/revisions`
|
||||
- `POST /api/annotation-tasks/{id}/reviews`
|
||||
- `GET /api/annotation-workload-summary`
|
||||
- `GET /api/dashboard?from=<RFC3339>&to=<RFC3339>`:管理员平台范围、供应商管理员团队范围、其他成员本人范围。
|
||||
|
||||
模板必须发布后才能创建任务。时间段必须位于 clip 范围内、不能重叠,置信度必须位于 `[0, 1]`。质检或验收拒绝会把任务转为 `rework` 并指向下一 revision,不在工作流 DAG 中建立环。
|
||||
|
||||
@ -30,11 +32,11 @@
|
||||
|
||||
- `ANNOTATION_TEMPLATE_ID`:当前项目中已发布的模板。
|
||||
- `ANNOTATION_WORKGROUP_ID`:目标供应商分组。
|
||||
- `ANNOTATION_ASSIGNED_USER_ID`:可选的首轮标注员。
|
||||
- 新任务不接受 `ANNOTATION_ASSIGNED_USER_ID` 预分配;成员从 HumanItem 待领取池主动领取。
|
||||
|
||||
Worker 到达该节点后不会启动 Kubernetes Job,也不会创建通用 AuditTask。它会从上游 `clips-manifest.json`、视频 artifact 和预标 JSON 自动按片段创建 AnnotationTask,并写入 `projectId`、`dataTaskId`、`workflowId`、`runId`、`nodeId`、`artifactId`。Run 保持 `waiting_for_audit`,直到该节点下所有任务完成首轮 revision、质检和最终验收。
|
||||
Worker 到达该节点后不会启动 Kubernetes Job,也不会创建通用 AuditTask。它会从上游 `clips-manifest.json`、视频 artifact 和预标 JSON 自动按片段创建 AnnotationTask,并写入 `projectId`、`dataTaskId`、`workflowId`、`runId`、`nodeId`、`artifactId`。Run 保持 `waiting_for_audit`,直到该节点下所有任务完成切片校正、语义标注和人工标注质量复核。独立视频质检节点不属于泛宇 v3;成品包最终验收由下游 DeliveryPackage 对应的 Acceptance HumanItem 承担。
|
||||
|
||||
最终验收通过后,Worker 生成 `droboticflow.annotation.accepted/v1` 的 `annotations-manifest.json`,记录模板版本、人工 revision、片段、artifact 和 Run lineage,然后从节点 `approved` 输出恢复同一个 Run。未选择的分支标记为跳过,不启动空上传 Job;质检或验收打回仅创建新 revision。
|
||||
质量复核通过后,Worker 生成 `droboticflow.annotation.accepted/v1` 的 `annotations-manifest.json`,记录模板版本、人工 revision、片段、artifact 和 Run lineage,然后从节点 `approved` 输出创建分区子 Run。成品打包完成后创建未分配的 Acceptance HumanItem;验收员领取后通过才记录幂等最终导出快照,拒绝则进入拒绝区。
|
||||
|
||||
`/annotation-operations` 支持通过以下参数从项目或监控页深链进入:
|
||||
|
||||
|
||||
@ -10,9 +10,9 @@ Base path: `/api`
|
||||
- `GET /api/ai/status`: returns whether server-side AI generation is enabled and which model is configured
|
||||
- `POST /api/ai/operators/generate`: generate a custom operator definition from natural language
|
||||
- `POST /api/ai/workflows/generate`: generate a workflow graph from natural language and the current operator catalog
|
||||
- `GET /api/dashboard`: aggregate counts for projects, operators, jobs, and audits
|
||||
- `GET /api/dashboard`: 管理员返回平台概览和供应商对比;`supplier_manager` 只返回其 `vendor_manager` 成员关系覆盖的团队指标,其他非管理员只返回本人工作量与质量。默认最近 30 天,`from/to` 最大 366 天。
|
||||
|
||||
When `DROBOTICFLOW_REQUIRE_SESSION_AUTH=true`, AI generation routes require an admin or operator session. Auditors can read existing workflows, runs, and status surfaces but cannot trigger model-backed generation.
|
||||
When `DROBOTICFLOW_REQUIRE_SESSION_AUTH=true`, AI generation routes require an admin or operator session. Run 列表、详情、日志、资源、通用 artifact 元数据/内容和 lineage 只允许管理员会话;机器 API token 继续用于受控自动化。标注/质检/验收通过 `/api/human-items/:id/subject-content` 读取经过工作组和阶段角色校验的媒体。
|
||||
|
||||
### Auth and Organizations
|
||||
|
||||
@ -32,7 +32,7 @@ When `DROBOTICFLOW_REQUIRE_SESSION_AUTH=true`, AI generation routes require an a
|
||||
- `DELETE /api/admin/users/:id`
|
||||
- `POST /api/admin/users/:id/reset-password`
|
||||
|
||||
Session auth uses an HttpOnly `droboticflow_session` cookie. Existing token-based local deployments remain compatible by default; set `DROBOTICFLOW_REQUIRE_SESSION_AUTH=true` to require login for business APIs. Unsafe session-authenticated requests, including `POST /api/auth/logout`, must also send `X-Droboticflow-CSRF-Token` with the value from the readable `droboticflow_csrf` cookie. Public LoadBalancer deployments require session auth so business role checks remain active. In session-auth deployments, the shared API token remains valid for run-monitoring read APIs (`GET /api/runs`, `GET /api/runs/:id`, `GET /api/runs/:id/{logs,resources,artifacts,lineage}`, `GET /api/runs/:id/artifacts/:artifactId/content`, `GET /api/artifacts/:artifactId/lineage`, and `GET /api/workflows/:id/runs`) plus explicitly documented import endpoints; ordinary business writes still require a user session with the right role.
|
||||
Session auth uses an HttpOnly `droboticflow_session` cookie. Existing token-based local deployments remain compatible by default; set `DROBOTICFLOW_REQUIRE_SESSION_AUTH=true` to require login for business APIs. Unsafe session-authenticated requests, including `POST /api/auth/logout`, must also send `X-Droboticflow-CSRF-Token` with the value from the readable `droboticflow_csrf` cookie. Public LoadBalancer deployments require session auth so business role checks remain active. In session-auth deployments, the shared API token remains valid for admin-monitoring automation and explicitly documented import endpoints; ordinary users cannot use it through the browser and business writes still require a user session with the right role.
|
||||
|
||||
`POST /api/ai/operators/generate`
|
||||
|
||||
|
||||
@ -2,11 +2,12 @@
|
||||
|
||||
## Images
|
||||
|
||||
This project deploys three images:
|
||||
The core deployment plus the泛宇 Headpose service uses these images:
|
||||
|
||||
- `droboticflow-api`
|
||||
- `droboticflow-worker`
|
||||
- `droboticflow-operator-runner`
|
||||
- `droboticflow-headpose-service`(digest-pinned 6DRepNet service)
|
||||
|
||||
Example Baidu registry naming:
|
||||
|
||||
@ -71,6 +72,9 @@ export IMAGE_TAG=20260408
|
||||
export API_IMAGE=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow/droboticflow-api:20260408
|
||||
export WORKER_IMAGE=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow/droboticflow-worker:20260408
|
||||
export OPERATOR_RUNNER_IMAGE=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow/droboticflow-operator-runner:20260408
|
||||
export HEADPOSE_SERVICE_IMAGE=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow/droboticflow-headpose-service:20260408
|
||||
export HEADPOSE_SERVICE_IMAGE_ID=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow/droboticflow-headpose-service@sha256:<64-hex-digest>
|
||||
export HEADPOSE_MODEL_SHA256=sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018
|
||||
export OPERATOR_GPU_NODE_SELECTOR=accelerator=nvidia
|
||||
export OPERATOR_GPU_TOLERATIONS_JSON='[{"key":"nvidia.com/gpu","operator":"Exists","effect":"NoSchedule"}]'
|
||||
export OPERATOR_GPU_RUNTIME_CLASS=nvidia
|
||||
@ -152,7 +156,7 @@ The deploy script performs these actions:
|
||||
6. renders `k8s/droboticflow.template.yaml`
|
||||
7. validates the rendered manifest with `kubectl apply --dry-run=client`
|
||||
8. applies the manifest to the cluster
|
||||
9. waits for API and worker rollouts
|
||||
9. waits for API, worker, and Headpose service rollouts
|
||||
|
||||
The main deployment path no longer creates a platform MongoDB Pod or Service. You must provision the backing MongoDB outside this manifest and provide its URI explicitly.
|
||||
|
||||
@ -160,6 +164,7 @@ The main deployment path no longer creates a platform MongoDB Pod or Service. Yo
|
||||
|
||||
- `droboticflow-api`: NodePort service that exposes the frontend and API
|
||||
- `droboticflow-worker`: ClusterIP service for worker health/debugging
|
||||
- `droboticflow-headpose`: ClusterIP GPU inference service; its `/health` reports model digest, license, CUDA, and GPU identity
|
||||
|
||||
Default API NodePort:
|
||||
|
||||
|
||||
38
docs/fanyu-v3-workflow.md
Normal file
38
docs/fanyu-v3-workflow.md
Normal file
@ -0,0 +1,38 @@
|
||||
# 泛宇右相机交付 v3
|
||||
|
||||
`01-右相机切分标注质检-v3` 是独立版本,不修改 v1/v2 历史 release:
|
||||
|
||||
```text
|
||||
BOS -> Orbbec 标准化 -> 视频切片 -> 切片校正 -> 语义标注 -> 标注质量复核
|
||||
|-> 6DRepNet Headpose(必选) ------------------------------|
|
||||
|-> WiLoR Handpose(每次 Run 可选) -------------------------|
|
||||
人工复核通过 ----------------------------------------------------------> 成品打包
|
||||
成品打包 -> Acceptance HumanItem 待领取池 -> approved 最终导出 / rejected 拒绝区
|
||||
```
|
||||
|
||||
流程不包含 `operator-builtin-video-quality` 或独立视频质检复核节点。`deliveryOptions` 是必填根输入,默认 Inline JSON 为:
|
||||
|
||||
```json
|
||||
{"includeHandpose": false}
|
||||
```
|
||||
|
||||
关闭时 WiLoR 不发起服务请求,输出 `enabled=false` 的合法 manifest;成品包不会把空文件记成 Handpose。Headpose 始终必选,输出 `droboticflow.headpose/v1`、逐帧 `frameIndex/timestamp/yawDeg/pitchDeg/rollDeg/confidence`、统计摘要、标注媒体和运行证据。
|
||||
|
||||
## Headpose 发布门禁
|
||||
|
||||
v3 模板始终可生成草稿,但只有以下条件同时满足时才生成不可变 WorkflowRelease:
|
||||
|
||||
- Headpose 算子镜像使用 `repository@sha256:...`;
|
||||
- `FANYU_HEADPOSE_API_BASE_URL` 指向可访问的真实服务;
|
||||
- `FANYU_HEADPOSE_SERVICE_IMAGE_ID` 是服务镜像 digest;
|
||||
- `FANYU_HEADPOSE_MODEL_SHA256` 是权重 digest;
|
||||
- `FANYU_HEADPOSE_LICENSE_ID` 已填写并与部署审查一致。
|
||||
|
||||
POC 内置服务镜像由 [Dockerfile.headpose-service](../Dockerfile.headpose-service) 构建,使用官方 `sixdrepnet==0.1.6`、MIT 许可证和固定权重 `sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018`。服务部署到 GPU Pod,启动时重新计算权重摘要;不匹配则服务和 v3 release 都不能就绪。
|
||||
|
||||
## 权限与数据面
|
||||
|
||||
- `supplier_manager + vendor_manager` 只能看授权供应商聚合指标。
|
||||
- 标注员、质检员、验收员必须领取当前阶段 HumanItem 后才能操作。
|
||||
- 非管理员不能读取通用 Run、日志、资源、artifact 元数据/内容或 lineage。
|
||||
- HumanItem 专用内容接口只返回该任务 subject artifact,不暴露 Run 详情。
|
||||
@ -14,9 +14,11 @@
|
||||
工作流画布禁止有向环并返回 `workflow_graph_cycle`。人工驳回不是重新执行已经完成的 DAG 节点,而是让一条 HumanItem 创建新的 StageAttempt 和 Revision:
|
||||
|
||||
```text
|
||||
split_annotation -> semantic_annotation -> quality_review -> acceptance
|
||||
split_annotation -> semantic_annotation -> quality_review
|
||||
^ ^ |
|
||||
+------- reject target / rework --------+
|
||||
|
||||
DeliveryPackage -> acceptance HumanItem -> approved final export / rejected area
|
||||
```
|
||||
|
||||
驳回必须携带原因码、说明和目标阶段。默认最多返工 5 轮,超限进入 `escalated`,不会静默交付。
|
||||
@ -25,7 +27,7 @@ split_annotation -> semantic_annotation -> quality_review -> acceptance
|
||||
|
||||
- 数据集或 Run 形成 HumanBatch。
|
||||
- 每个 Clip、Episode 或 Artifact 形成独立 HumanItem。
|
||||
- 人工逐条领取、保存、提交和审核。
|
||||
- 每个阶段进入 `ready` 时清空领取人;人工逐条领取、保存、提交和审核,阶段切换后重新进入待领取池。
|
||||
- 已验收条目最多 32 条或等待 60 秒形成一个 ReleasePartition。
|
||||
- ReleasePartition 通过带唯一键的 Outbox 创建 `human_release` 子 Run,从 Gate 下游继续执行。
|
||||
|
||||
@ -58,8 +60,11 @@ GET /api/organizations/:id/plugins/:pluginId
|
||||
PUT /api/organizations/:id/plugins/:pluginId
|
||||
GET /api/human-batches
|
||||
GET /api/human-items
|
||||
GET /api/human-items?pool=available|mine|all
|
||||
GET /api/human-items/:id
|
||||
GET /api/human-items/:id/subject-content
|
||||
POST /api/human-items/:id/claim
|
||||
POST /api/human-items/:id/release
|
||||
POST /api/human-items/:id/submissions
|
||||
POST /api/human-items/:id/decisions
|
||||
GET /api/human-items/:id/events
|
||||
@ -69,7 +74,9 @@ Annotation QA 新接口位于 `/api/plugins/annotation-qa/*`。原 `/api/annotat
|
||||
|
||||
## 历史数据与审计
|
||||
|
||||
插件首次启用时幂等迁移既有 AnnotationTask。HumanItem 保留 `legacyTaskId`,并继承 Revision、作者、工作组、供应商和当前状态。所有后续 claimed、submitted、approved、rejected、escalated 事件只追加不覆盖。
|
||||
插件首次启用时幂等迁移既有 AnnotationTask。HumanItem 保留 `legacyTaskId`,并继承 Revision、作者、工作组、供应商和当前状态;历史 `assignedUserId` 会转换为已领取状态,新任务不预分配。所有后续 created、claimed、released、submitted、approved、rejected、escalated 事件只追加不覆盖。
|
||||
|
||||
普通成员只能读取 `available` 和 `mine`;`all` 仅管理员可用。领取使用 `version` 乐观锁,竞争失败返回 `409 version_conflict`。领取者可在提交前释放,管理员可强制释放,不设置自动超时。
|
||||
|
||||
返工 Revision 的 `CountsAsOutput=false`,因此修改被打回数据不会重复计入正式产出。
|
||||
|
||||
|
||||
121
docs/operators/6DRepNet-Headpose.md
Normal file
121
docs/operators/6DRepNet-Headpose.md
Normal file
@ -0,0 +1,121 @@
|
||||
# 6DRepNet Headpose
|
||||
|
||||
- 算子 ID:`operator-builtin-head-pose`
|
||||
- 类别:`AI`
|
||||
- 类型:`builtin`
|
||||
|
||||
## 作用
|
||||
|
||||
调用 digest 固定的 6DRepNet 服务,对图片或视频输出逐帧头部 yaw/pitch/roll、置信度和运行证据。
|
||||
|
||||
## 定位与职责边界
|
||||
|
||||
- 该算子属于 `AI` 类,当前登记类型是 `builtin`。
|
||||
- 平台会在 `/api/operators` 中自动提供该算子元数据,运行时由 operator-runner 委派到独立算子入口。
|
||||
|
||||
## 平台语义
|
||||
|
||||
真实调用 6DRepNet 服务,输出逐帧 yaw/pitch/roll、置信度、标注媒体引用和服务镜像证据。
|
||||
|
||||
## 运行时契约
|
||||
|
||||
- Worker 会先把上游 artifact 汇总到 `INPUT_ARTIFACTS_PATH`,再把节点配置通过 `NODE_DATA_JSON` 注入运行容器。
|
||||
- 节点执行结果会写入 `OUTPUT_DIR`、`RESULT_OUTPUT_PATH` 和 `STAGE_MANIFEST_PATH` 对应的文件,再由 worker 汇总进运行记录。
|
||||
- 大文件和大 JSON 不应依赖 API 内联传输,应该通过 `artifact.path`、`dataRef.payloadPath`、共享 PVC 或对象存储引用传递。
|
||||
- 当前独立实现入口是 `operator-repos/builtin/head_pose/src/operator.py` 中的 `run(...)`,平台 runtimeHandler 为 `builtin_head_pose`。
|
||||
|
||||
## 设计边界
|
||||
|
||||
- 该算子应该只承担单一职责,不应在一个节点里同时混合索引、筛选、上传、审核等多个阶段性行为。
|
||||
- 如果一个节点要消费多个语义不同的结果,优先通过多节点拆分,而不是把所有逻辑塞进一个超大脚本。
|
||||
|
||||
## 数据流示意
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
A[上游输入或运行时注入] --> B[6DRepNet Headpose]
|
||||
B --> C[artifact / stage manifest / 外部副作用]
|
||||
```
|
||||
|
||||
## 输入端口详解
|
||||
|
||||
- `in-1` / **media** / `json` / `bus`:图片/视频 artifact 或媒体清单 作为输入端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
|
||||
## 输出端口详解
|
||||
|
||||
- `out-1` / **headpose** / `json` / `bus`:droboticflow.headpose/v1 manifest 作为输出端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
|
||||
## 关键超参数
|
||||
|
||||
- `HEADPOSE_API_BASE_URL`:类型 `string`,默认值 空字符串或由工作流显式填写。6DRepNet 服务地址 通常建议在工作流中显式配置。
|
||||
- `HEADPOSE_MODEL`:类型 `string`,默认值 `6DRepNet`。模型名称 可直接使用默认值,也可在节点级覆盖。
|
||||
- `FRAME_STRIDE`:类型 `integer`,默认值 `3`。视频抽帧间隔 可直接使用默认值,也可在节点级覆盖。
|
||||
- `MAX_FRAMES`:类型 `integer`,默认值 `120`。最多采样帧数 可直接使用默认值,也可在节点级覆盖。
|
||||
- `REQUEST_TIMEOUT_SECONDS`:类型 `integer`,默认值 `300`。请求超时秒数 可直接使用默认值,也可在节点级覆盖。
|
||||
- `HEADPOSE_SERVICE_IMAGE_ID`:类型 `string`,默认值 空字符串或由工作流显式填写。digest 固定的服务镜像 通常建议在工作流中显式配置。
|
||||
- `HEADPOSE_MODEL_SHA256`:类型 `string`,默认值 空字符串或由工作流显式填写。6DRepNet 权重 SHA-256 通常建议在工作流中显式配置。
|
||||
- `HEADPOSE_LICENSE_ID`:类型 `string`,默认值 空字符串或由工作流显式填写。模型与代码许可证标识 通常建议在工作流中显式配置。
|
||||
|
||||
## 执行前准备
|
||||
|
||||
- 先确认上下游端口类型兼容,特别是 `json`、`file`、`video` 等端口不要混接。
|
||||
- 为每个关键超参数补齐明确值,避免依赖隐式默认值进入生产工作流。
|
||||
- 对需要跨节点长期保留的产物,提前规划对象存储前缀或外部落库集合,而不是只写临时目录。
|
||||
|
||||
## 数据通信与存储路径
|
||||
|
||||
- 标准输入来自 `INPUT_ARTIFACTS_PATH` 指向的 artifact 列表文件,artifact 可同时包含 `data`、`path`、`metadata` 与 `dataRef`。
|
||||
- 标准输出写入 `OUTPUT_DIR`,并通过 `stage-manifest.json` 对外暴露产物路径、payload 引用和摘要元数据。
|
||||
|
||||
## 典型上下游编排
|
||||
|
||||
- 该算子通常位于同类数据处理节点之间,承担结构化中间层职责。
|
||||
|
||||
## 节点配置示例
|
||||
|
||||
```json
|
||||
{
|
||||
"label": "6DRepNet Headpose",
|
||||
"operatorId": "operator-builtin-head-pose",
|
||||
"type": "builtin",
|
||||
"category": "AI",
|
||||
"hyperparams": {
|
||||
"HEADPOSE_API_BASE_URL": "<按节点填写>",
|
||||
"HEADPOSE_MODEL": "6DRepNet",
|
||||
"FRAME_STRIDE": "3",
|
||||
"MAX_FRAMES": "120",
|
||||
"REQUEST_TIMEOUT_SECONDS": "300",
|
||||
"HEADPOSE_SERVICE_IMAGE_ID": "<按节点填写>",
|
||||
"HEADPOSE_MODEL_SHA256": "<按节点填写>",
|
||||
"HEADPOSE_LICENSE_ID": "<按节点填写>"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 输入输出示例
|
||||
|
||||
- 典型输入:worker 会把上游 artifact 序列化为 `INPUT_ARTIFACTS_PATH` 文件供节点读取。
|
||||
- 典型输出:节点会在 `OUTPUT_DIR` 下写业务文件,并在 `stage-manifest.json` 里登记对外可消费的结果。
|
||||
|
||||
## 成功判定
|
||||
|
||||
- 节点 execution 状态为 `completed`,且日志中没有隐藏的回退错误或重试未果记录。
|
||||
- `stage-manifest.json` 中能看到期望的 artifact 条目,且下游节点可以正常消费这些结果。
|
||||
|
||||
## 常见失败与排查
|
||||
|
||||
- 如果看不到预期结果,先检查 `OUTPUT_DIR`、`RESULT_OUTPUT_PATH` 和 `STAGE_MANIFEST_PATH` 是否真实写出。
|
||||
- 如果下游收不到数据,先检查当前节点输出 artifact 是否设置了正确的 `portId`、`portName` 和 `type`。
|
||||
- 如果日志中只有摘要没有大 payload,优先排查 `dataRef.payloadPath` 或外置文件是否存在,而不是误以为结果丢失。
|
||||
|
||||
## 验收检查清单
|
||||
|
||||
- 至少在一条真实工作流中跑通该算子,而不是只验证单元测试或空输入。
|
||||
- 确认该节点输出被下游节点实际消费,避免出现“本节点成功但链路无效”的假阳性。
|
||||
- 保留一次成功运行的示例日志、stage manifest 和关键产物路径,便于后续回归对照。
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AI 类索引](README.md)
|
||||
- [算子开发文档](../operator-authoring.md)
|
||||
- [内建算子总手册](../builtin-operators-manual.zh-CN.md)
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
当前目录按“每个内建算子一份 Markdown”组织,内容基于当前平台真实算子定义按算子名称去重生成。
|
||||
|
||||
- 当前收录数量:`106`
|
||||
- 当前收录数量:`108`
|
||||
- 文档定位:单算子详细手册,重点覆盖输入输出契约、运行时路径、配置示例、排障与验收。
|
||||
- 配套总览:[`../builtin-operators-manual.zh-CN.md`](../builtin-operators-manual.zh-CN.md)
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
|
||||
### AI
|
||||
|
||||
- [6DRepNet Headpose](6DRepNet-Headpose.md)
|
||||
- [ACT 策略训练](ACT-策略训练.md)
|
||||
- [Diffusion Policy 训练](Diffusion-Policy-训练.md)
|
||||
- [Hand Removal 视频去手](Hand-Removal-视频去手.md)
|
||||
@ -142,6 +143,7 @@
|
||||
### UTIL
|
||||
|
||||
- [Shell 命令执行](Shell-命令执行.md)
|
||||
- [交付选项透传](交付选项透传.md)
|
||||
- [文本模板渲染](文本模板渲染.md)
|
||||
|
||||
### VIDEO
|
||||
|
||||
@ -40,6 +40,7 @@ flowchart LR
|
||||
## 输入端口详解
|
||||
|
||||
- `in-1` / **media** / `json` / `bus`:图片/视频 artifact,或包含 url/path 字段的媒体清单 作为输入端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
- `in-2` / **options** / `json` / `bus`:Run 级 deliveryOptions 作为输入端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
|
||||
## 输出端口详解
|
||||
|
||||
|
||||
105
docs/operators/交付选项透传.md
Normal file
105
docs/operators/交付选项透传.md
Normal file
@ -0,0 +1,105 @@
|
||||
# 交付选项透传
|
||||
|
||||
- 算子 ID:`operator-builtin-delivery-options`
|
||||
- 类别:`UTIL`
|
||||
- 类型:`builtin`
|
||||
|
||||
## 作用
|
||||
|
||||
校验并透传每次 Run 的交付选项。
|
||||
|
||||
## 定位与职责边界
|
||||
|
||||
- 该算子属于 `UTIL` 类,当前登记类型是 `builtin`。
|
||||
- 平台会在 `/api/operators` 中自动提供该算子元数据,运行时由 operator-runner 委派到独立算子入口。
|
||||
|
||||
## 平台语义
|
||||
|
||||
读取工作流根输入并输出规范化的 includeHandpose 交付开关。
|
||||
|
||||
## 运行时契约
|
||||
|
||||
- Worker 会先把上游 artifact 汇总到 `INPUT_ARTIFACTS_PATH`,再把节点配置通过 `NODE_DATA_JSON` 注入运行容器。
|
||||
- 节点执行结果会写入 `OUTPUT_DIR`、`RESULT_OUTPUT_PATH` 和 `STAGE_MANIFEST_PATH` 对应的文件,再由 worker 汇总进运行记录。
|
||||
- 大文件和大 JSON 不应依赖 API 内联传输,应该通过 `artifact.path`、`dataRef.payloadPath`、共享 PVC 或对象存储引用传递。
|
||||
- 当前独立实现入口是 `operator-repos/builtin/delivery_options/src/operator.py` 中的 `run(...)`,平台 runtimeHandler 为 `builtin_delivery_options`。
|
||||
|
||||
## 设计边界
|
||||
|
||||
- 该算子应该只承担单一职责,不应在一个节点里同时混合索引、筛选、上传、审核等多个阶段性行为。
|
||||
- 如果一个节点要消费多个语义不同的结果,优先通过多节点拆分,而不是把所有逻辑塞进一个超大脚本。
|
||||
|
||||
## 数据流示意
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
A[上游输入或运行时注入] --> B[交付选项透传]
|
||||
B --> C[artifact / stage manifest / 外部副作用]
|
||||
```
|
||||
|
||||
## 输入端口详解
|
||||
|
||||
- `in-1` / **options** / `json` / `bus`:Run 级交付选项 作为输入端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
|
||||
## 输出端口详解
|
||||
|
||||
- `out-1` / **options** / `json` / `bus`:规范化交付选项 作为输出端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
|
||||
## 关键超参数
|
||||
|
||||
- 当前元数据未声明额外超参数。若为自定义算子,建议在注册阶段补齐。
|
||||
|
||||
## 执行前准备
|
||||
|
||||
- 先确认上下游端口类型兼容,特别是 `json`、`file`、`video` 等端口不要混接。
|
||||
- 为每个关键超参数补齐明确值,避免依赖隐式默认值进入生产工作流。
|
||||
- 对需要跨节点长期保留的产物,提前规划对象存储前缀或外部落库集合,而不是只写临时目录。
|
||||
|
||||
## 数据通信与存储路径
|
||||
|
||||
- 标准输入来自 `INPUT_ARTIFACTS_PATH` 指向的 artifact 列表文件,artifact 可同时包含 `data`、`path`、`metadata` 与 `dataRef`。
|
||||
- 标准输出写入 `OUTPUT_DIR`,并通过 `stage-manifest.json` 对外暴露产物路径、payload 引用和摘要元数据。
|
||||
|
||||
## 典型上下游编排
|
||||
|
||||
- 该算子通常位于同类数据处理节点之间,承担结构化中间层职责。
|
||||
|
||||
## 节点配置示例
|
||||
|
||||
```json
|
||||
{
|
||||
"label": "交付选项透传",
|
||||
"operatorId": "operator-builtin-delivery-options",
|
||||
"type": "builtin",
|
||||
"category": "UTIL",
|
||||
"hyperparams": {}
|
||||
}
|
||||
```
|
||||
|
||||
## 输入输出示例
|
||||
|
||||
- 典型输入:worker 会把上游 artifact 序列化为 `INPUT_ARTIFACTS_PATH` 文件供节点读取。
|
||||
- 典型输出:节点会在 `OUTPUT_DIR` 下写业务文件,并在 `stage-manifest.json` 里登记对外可消费的结果。
|
||||
|
||||
## 成功判定
|
||||
|
||||
- 节点 execution 状态为 `completed`,且日志中没有隐藏的回退错误或重试未果记录。
|
||||
- `stage-manifest.json` 中能看到期望的 artifact 条目,且下游节点可以正常消费这些结果。
|
||||
|
||||
## 常见失败与排查
|
||||
|
||||
- 如果看不到预期结果,先检查 `OUTPUT_DIR`、`RESULT_OUTPUT_PATH` 和 `STAGE_MANIFEST_PATH` 是否真实写出。
|
||||
- 如果下游收不到数据,先检查当前节点输出 artifact 是否设置了正确的 `portId`、`portName` 和 `type`。
|
||||
- 如果日志中只有摘要没有大 payload,优先排查 `dataRef.payloadPath` 或外置文件是否存在,而不是误以为结果丢失。
|
||||
|
||||
## 验收检查清单
|
||||
|
||||
- 至少在一条真实工作流中跑通该算子,而不是只验证单元测试或空输入。
|
||||
- 确认该节点输出被下游节点实际消费,避免出现“本节点成功但链路无效”的假阳性。
|
||||
- 保留一次成功运行的示例日志、stage manifest 和关键产物路径,便于后续回归对照。
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [UTIL 类索引](README.md)
|
||||
- [算子开发文档](../operator-authoring.md)
|
||||
- [内建算子总手册](../builtin-operators-manual.zh-CN.md)
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
## 作用
|
||||
|
||||
将视频切片和语义预标转换为原生逐段标注任务;质检与验收通过后恢复同一 Workflow Run。
|
||||
将视频切片和语义预标转换为待领取的原生逐段标注任务;标注质量复核通过后释放下游分区。
|
||||
|
||||
## 定位与职责边界
|
||||
|
||||
@ -44,14 +44,13 @@ flowchart LR
|
||||
|
||||
## 输出端口详解
|
||||
|
||||
- `approved` / **approved** / `json` / `bus`:已通过质检与验收的 revision artifacts 作为输出端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
- `approved` / **approved** / `json` / `bus`:已通过标注质量复核的 revision artifacts 作为输出端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
- `rejected` / **rejected** / `json` / `bus`:拒绝或返工分支 作为输出端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
|
||||
## 关键超参数
|
||||
|
||||
- `ANNOTATION_TEMPLATE_ID`:类型 `string`,默认值 空字符串或由工作流显式填写。当前项目中已发布的语义模板 ID 通常建议在工作流中显式配置。
|
||||
- `ANNOTATION_WORKGROUP_ID`:类型 `string`,默认值 空字符串或由工作流显式填写。目标供应商工作组 ID 通常建议在工作流中显式配置。
|
||||
- `ANNOTATION_ASSIGNED_USER_ID`:类型 `string`,默认值 空字符串或由工作流显式填写。可选:首轮标注员用户 ID 通常建议在工作流中显式配置。
|
||||
|
||||
## 执行前准备
|
||||
|
||||
@ -78,8 +77,7 @@ flowchart LR
|
||||
"category": "HUMAN",
|
||||
"hyperparams": {
|
||||
"ANNOTATION_TEMPLATE_ID": "<按节点填写>",
|
||||
"ANNOTATION_WORKGROUP_ID": "<按节点填写>",
|
||||
"ANNOTATION_ASSIGNED_USER_ID": "<按节点填写>"
|
||||
"ANNOTATION_WORKGROUP_ID": "<按节点填写>"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -40,7 +40,9 @@ flowchart LR
|
||||
|
||||
## 输入端口详解
|
||||
|
||||
- `in-1` / **input** / `json` / `bus`:切片/标注/质检结果 作为输入端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
- `in-1` / **annotations** / `json` / `bus`:切片与人工标注结果 作为输入端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
- `in-2` / **headpose** / `json` / `bus`:必选 Headpose manifest 作为输入端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
- `in-3` / **handpose** / `json` / `bus`:可选 Handpose manifest 作为输入端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
|
||||
## 输出端口详解
|
||||
|
||||
@ -48,7 +50,7 @@ flowchart LR
|
||||
|
||||
## 关键超参数
|
||||
|
||||
- 当前元数据未声明额外超参数。若为自定义算子,建议在注册阶段补齐。
|
||||
- `REQUIRE_HEADPOSE`:类型 `boolean`,默认值 `false`。是否强制要求 Headpose 可直接使用默认值,也可在节点级覆盖。
|
||||
|
||||
## 执行前准备
|
||||
|
||||
@ -74,7 +76,9 @@ flowchart LR
|
||||
"operatorId": "operator-builtin-package",
|
||||
"type": "builtin",
|
||||
"category": "VIDEO",
|
||||
"hyperparams": {}
|
||||
"hyperparams": {
|
||||
"REQUIRE_HEADPOSE": "false"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ func annotationPrincipalUserID(principal *authenticatedPrincipal) string {
|
||||
|
||||
func annotationRoleValid(role domain.AnnotationAssignmentRole) bool {
|
||||
switch role {
|
||||
case domain.AnnotationRoleAnnotator, domain.AnnotationRoleQualityReviewer, domain.AnnotationRoleAcceptanceReviewer:
|
||||
case domain.AnnotationRoleAnnotator, domain.AnnotationRoleQualityReviewer, domain.AnnotationRoleAcceptanceReviewer, domain.AnnotationRoleVendorManager:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@ -84,6 +84,18 @@ func membershipAllowsTask(memberships []domain.ProjectAnnotationMembershipRecord
|
||||
return false
|
||||
}
|
||||
|
||||
func membershipAllowsTaskRead(memberships []domain.ProjectAnnotationMembershipRecord, task domain.AnnotationTaskRecord) bool {
|
||||
for _, membership := range memberships {
|
||||
if membership.AssignmentRole == domain.AnnotationRoleVendorManager {
|
||||
continue
|
||||
}
|
||||
if membershipAllowsTask([]domain.ProjectAnnotationMembershipRecord{membership}, task) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func membershipHasRole(memberships []domain.ProjectAnnotationMembershipRecord, task domain.AnnotationTaskRecord, role domain.AnnotationAssignmentRole) bool {
|
||||
for _, membership := range memberships {
|
||||
if membership.AssignmentRole == role && membershipAllowsTask([]domain.ProjectAnnotationMembershipRecord{membership}, task) {
|
||||
@ -110,7 +122,7 @@ func (server *server) ensureAnnotationTaskAccess(writer http.ResponseWriter, req
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return nil, nil, false
|
||||
}
|
||||
if !membershipAllowsTask(memberships, task) {
|
||||
if !membershipAllowsTaskRead(memberships, task) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "annotation workgroup access is required"})
|
||||
return nil, nil, false
|
||||
}
|
||||
@ -502,7 +514,7 @@ func (server *server) handleAnnotationTasksList(writer http.ResponseWriter, requ
|
||||
if artifactID != "" && item.ArtifactID != artifactID {
|
||||
continue
|
||||
}
|
||||
if !annotationManager(principal) && !membershipAllowsTask(memberships, item) {
|
||||
if !annotationManager(principal) && !membershipAllowsTaskRead(memberships, item) {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, item)
|
||||
@ -586,20 +598,13 @@ func (server *server) handleAnnotationTaskCreate(writer http.ResponseWriter, req
|
||||
TemplateVersion: template.Version,
|
||||
WorkgroupID: group.ID,
|
||||
VendorID: group.VendorID,
|
||||
AssignedUserID: strings.TrimSpace(payload.AssignedUserID),
|
||||
AssignedUserID: "",
|
||||
Status: domain.AnnotationTaskStatusPendingAnnotation,
|
||||
CreatedAt: nowISO(),
|
||||
}
|
||||
if item.AssignedUserID != "" {
|
||||
memberships, membershipErr := server.annotationMembershipsForUser(request.Context(), project.OrganizationID, project.ID, item.AssignedUserID)
|
||||
if membershipErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, membershipErr)
|
||||
return
|
||||
}
|
||||
if !membershipHasRole(memberships, item, domain.AnnotationRoleAnnotator) {
|
||||
renderValidationError(writer, validationIssue{Field: "assignedUserId", Message: "assigned user must be an annotator in the selected workgroup"})
|
||||
return
|
||||
}
|
||||
if strings.TrimSpace(payload.AssignedUserID) != "" {
|
||||
renderValidationError(writer, validationIssue{Field: "assignedUserId", Message: "new tasks enter the available pool and cannot be pre-assigned"})
|
||||
return
|
||||
}
|
||||
if err := server.store.UpsertAnnotationTask(request.Context(), item); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
@ -609,7 +614,7 @@ func (server *server) handleAnnotationTaskCreate(writer http.ResponseWriter, req
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: item.OrganizationID, ProjectID: item.ProjectID,
|
||||
TaskID: item.ID, UserID: annotationPrincipalUserID(principal), WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
EventType: "assigned", TemplateVersion: item.TemplateVersion, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
EventType: "created", TemplateVersion: item.TemplateVersion, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
})
|
||||
renderJSON(writer, http.StatusCreated, item)
|
||||
}
|
||||
@ -651,6 +656,9 @@ func (server *server) handleAnnotationTaskReject(writer http.ResponseWriter, req
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "annotator assignment is required"})
|
||||
return
|
||||
}
|
||||
if _, claimed := server.requireLegacyHumanItemClaim(writer, request, *task, ""); !claimed {
|
||||
return
|
||||
}
|
||||
var payload annotationTaskRejectInput
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
@ -744,8 +752,7 @@ func (server *server) handleSliceRevisionCreate(writer http.ResponseWriter, requ
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "annotator assignment is required"})
|
||||
return
|
||||
}
|
||||
if task.AssignedUserID != "" && task.AssignedUserID != principal.User.ID && !annotationManager(principal) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "task is assigned to another annotator"})
|
||||
if _, claimed := server.requireLegacyHumanItemClaim(writer, request, *task, "split_annotation"); !claimed {
|
||||
return
|
||||
}
|
||||
var payload sliceRevisionInput
|
||||
@ -786,7 +793,8 @@ func (server *server) handleSliceRevisionCreate(writer http.ResponseWriter, requ
|
||||
previousVersion := item.Version
|
||||
item.CurrentStageID = "semantic_annotation"
|
||||
item.Status = domain.HumanItemReady
|
||||
item.AssignedUserID = principal.User.ID
|
||||
item.AssignedUserID = ""
|
||||
item.ClaimedAt = ""
|
||||
item.LatestAuthorUserID = principal.User.ID
|
||||
item.Version++
|
||||
updated, updateErr := server.store.UpdateHumanItemVersioned(request.Context(), *item, previousVersion)
|
||||
@ -844,8 +852,7 @@ func (server *server) handleAnnotationRevisionCreate(writer http.ResponseWriter,
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "annotator assignment is required"})
|
||||
return
|
||||
}
|
||||
if task.AssignedUserID != "" && task.AssignedUserID != principal.User.ID && !annotationManager(principal) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "task is assigned to another annotator"})
|
||||
if _, claimed := server.requireLegacyHumanItemClaim(writer, request, *task, "semantic_annotation"); !claimed {
|
||||
return
|
||||
}
|
||||
var payload annotationRevisionInput
|
||||
@ -1010,6 +1017,13 @@ func (server *server) handleAnnotationReviewCreate(writer http.ResponseWriter, r
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": string(requiredRole) + " assignment is required"})
|
||||
return
|
||||
}
|
||||
requiredStageID := "quality_review"
|
||||
if payload.Stage == domain.AnnotationReviewStageAcceptance {
|
||||
requiredStageID = "acceptance"
|
||||
}
|
||||
if _, claimed := server.requireLegacyHumanItemClaim(writer, request, *task, requiredStageID); !claimed {
|
||||
return
|
||||
}
|
||||
if task.CurrentRevision <= 0 {
|
||||
renderValidationError(writer, validationIssue{Field: "revision", Message: "an annotation revision is required before review"})
|
||||
return
|
||||
|
||||
@ -42,6 +42,30 @@ func TestMembershipRequiresMatchingProjectWorkgroupAndVendor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestVendorManagerIsAValidProjectMembershipRole(t *testing.T) {
|
||||
if !annotationRoleValid(domain.AnnotationRoleVendorManager) {
|
||||
t.Fatal("vendor manager membership must be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVendorManagerMembershipDoesNotGrantTaskMediaRead(t *testing.T) {
|
||||
task := domain.AnnotationTaskRecord{ProjectID: "project-a", WorkgroupID: "group-a", VendorID: "vendor-a"}
|
||||
memberships := []domain.ProjectAnnotationMembershipRecord{{
|
||||
ProjectID: task.ProjectID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID,
|
||||
AssignmentRole: domain.AnnotationRoleVendorManager,
|
||||
}}
|
||||
if membershipAllowsTaskRead(memberships, task) {
|
||||
t.Fatal("vendor manager aggregation membership must not grant task media read")
|
||||
}
|
||||
memberships = append(memberships, domain.ProjectAnnotationMembershipRecord{
|
||||
ProjectID: task.ProjectID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID,
|
||||
AssignmentRole: domain.AnnotationRoleQualityReviewer,
|
||||
})
|
||||
if !membershipAllowsTaskRead(memberships, task) {
|
||||
t.Fatal("an additional production role should grant scoped task read")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateHumanStagesAllowsDirectedReworkToEarlierStage(t *testing.T) {
|
||||
if issues := validateHumanStages(domain.DefaultAnnotationHumanStages()); len(issues) != 0 {
|
||||
t.Fatalf("default stages should be valid: %#v", issues)
|
||||
|
||||
@ -822,7 +822,7 @@ func (server *server) handleAdminOrganizationUsersCreate(writer http.ResponseWri
|
||||
return
|
||||
}
|
||||
if !validUserRole(payload.Role) {
|
||||
renderValidationError(writer, validationIssue{Field: "role", Message: "role must be admin, annotator, quality_reviewer, or acceptance_reviewer"})
|
||||
renderValidationError(writer, validationIssue{Field: "role", Message: "role must be admin, annotator, quality_reviewer, acceptance_reviewer, or supplier_manager"})
|
||||
return
|
||||
}
|
||||
passwordHash, err := hashPassword(payload.Password)
|
||||
|
||||
@ -203,6 +203,50 @@
|
||||
"skillDefinition": "统一工作流里的有状态源算子。每次 run 只产出 BOS 中新增的对象,状态由 runtime 在 run 成功后提交。",
|
||||
"type": "builtin"
|
||||
},
|
||||
{
|
||||
"category": "UTIL",
|
||||
"containerArgs": [],
|
||||
"containerCommand": ["python", "/app/backend/operator-runner/main.py"],
|
||||
"description": "校验并透传每次 Run 的交付选项。",
|
||||
"id": "operator-builtin-delivery-options",
|
||||
"image": "ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow-poc/droboticflow-operator-delivery-options:builtin",
|
||||
"inputs": [{"description": "Run 级交付选项", "id": "in-1", "name": "options", "required": true, "transmission": "bus", "type": "json"}],
|
||||
"name": "交付选项透传",
|
||||
"outputs": [{"description": "规范化交付选项", "id": "out-1", "name": "options", "transmission": "bus", "type": "json"}],
|
||||
"runtimeContract": {"schemaVersion": "droboticflow.operator.runtime/v1", "entrypoint": "/app/backend/operator-runner/main.py", "handler": "builtin_delivery_options", "operatorId": "operator-builtin-delivery-options", "operatorSlug": "delivery_options", "artifacts": {"requiresChecksum": true, "requiresLineage": true, "requiresManifest": true}, "parameters": {"source": "input", "structured": true, "commandWrapperAllowed": false, "controlledScriptAllowed": false}, "resources": {"requiresGpu": false, "minGpuCount": 0, "recommendedGpuType": ""}, "runtimeDependencies": ["json-artifacts"], "acceptance": {"requiresRealFixture": true, "requiresWorkflowTransfer": true, "requiresArtifactChecksum": true, "requiresFixtureChecksum": true, "requiresGpuEvidence": false}, "imagePolicy": {"independentFinalImage": true, "forbidsSharedOperatorRunnerFinalImage": true, "allowsSharedBaseLayer": true}},
|
||||
"runtimeHandler": "builtin_delivery_options",
|
||||
"runtimeSource": "operator-repos/builtin/delivery_options/src/operator.py",
|
||||
"runtimeDependencies": ["json-artifacts"],
|
||||
"skillDefinition": "读取工作流根输入并输出规范化的 includeHandpose 交付开关。",
|
||||
"type": "builtin"
|
||||
},
|
||||
{
|
||||
"category": "AI",
|
||||
"containerArgs": [],
|
||||
"containerCommand": ["python", "/app/backend/operator-runner/main.py"],
|
||||
"description": "调用 digest 固定的 6DRepNet 服务,对图片或视频输出逐帧头部 yaw/pitch/roll、置信度和运行证据。",
|
||||
"hyperparams": [
|
||||
{"description": "6DRepNet 服务地址", "key": "HEADPOSE_API_BASE_URL", "type": "string", "value": ""},
|
||||
{"description": "模型名称", "key": "HEADPOSE_MODEL", "type": "string", "value": "6DRepNet"},
|
||||
{"description": "视频抽帧间隔", "key": "FRAME_STRIDE", "type": "integer", "value": "3"},
|
||||
{"description": "最多采样帧数", "key": "MAX_FRAMES", "type": "integer", "value": "120"},
|
||||
{"description": "请求超时秒数", "key": "REQUEST_TIMEOUT_SECONDS", "type": "integer", "value": "300"},
|
||||
{"description": "digest 固定的服务镜像", "key": "HEADPOSE_SERVICE_IMAGE_ID", "type": "string", "value": ""},
|
||||
{"description": "6DRepNet 权重 SHA-256", "key": "HEADPOSE_MODEL_SHA256", "type": "string", "value": ""},
|
||||
{"description": "模型与代码许可证标识", "key": "HEADPOSE_LICENSE_ID", "type": "string", "value": ""}
|
||||
],
|
||||
"id": "operator-builtin-head-pose",
|
||||
"image": "ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow-poc/droboticflow-operator-head-pose:builtin",
|
||||
"inputs": [{"description": "图片/视频 artifact 或媒体清单", "id": "in-1", "name": "media", "required": true, "transmission": "bus", "type": "json"}],
|
||||
"name": "6DRepNet Headpose",
|
||||
"outputs": [{"description": "droboticflow.headpose/v1 manifest", "id": "out-1", "name": "headpose", "transmission": "bus", "type": "json"}],
|
||||
"runtimeContract": {"schemaVersion": "droboticflow.operator.runtime/v1", "entrypoint": "/app/backend/operator-runner/main.py", "handler": "builtin_head_pose", "operatorId": "operator-builtin-head-pose", "operatorSlug": "head_pose", "artifacts": {"requiresChecksum": true, "requiresLineage": true, "requiresManifest": true}, "parameters": {"source": "hyperparams", "structured": true, "commandWrapperAllowed": false, "controlledScriptAllowed": false}, "resources": {"requiresGpu": false, "minGpuCount": 0, "recommendedGpuType": "A800"}, "runtimeDependencies": ["6drepnet-service", "video-artifacts"], "acceptance": {"requiresRealFixture": true, "requiresWorkflowTransfer": true, "requiresArtifactChecksum": true, "requiresFixtureChecksum": true, "requiresGpuEvidence": true}, "imagePolicy": {"independentFinalImage": true, "forbidsSharedOperatorRunnerFinalImage": true, "allowsSharedBaseLayer": true}},
|
||||
"runtimeHandler": "builtin_head_pose",
|
||||
"runtimeSource": "operator-repos/builtin/head_pose/src/operator.py",
|
||||
"runtimeDependencies": ["6drepnet-service", "video-artifacts"],
|
||||
"skillDefinition": "真实调用 6DRepNet 服务,输出逐帧 yaw/pitch/roll、置信度、标注媒体引用和服务镜像证据。",
|
||||
"type": "builtin"
|
||||
},
|
||||
{
|
||||
"category": "AI",
|
||||
"containerArgs": [],
|
||||
@ -528,7 +572,7 @@
|
||||
"python",
|
||||
"/app/backend/operator-runner/main.py"
|
||||
],
|
||||
"description": "将视频切片和语义预标转换为原生逐段标注任务;质检与验收通过后恢复同一 Workflow Run。",
|
||||
"description": "将视频切片和语义预标转换为待领取的原生逐段标注任务;标注质量复核通过后释放下游分区。",
|
||||
"hyperparams": [
|
||||
{
|
||||
"description": "当前项目中已发布的语义模板 ID",
|
||||
@ -541,12 +585,6 @@
|
||||
"key": "ANNOTATION_WORKGROUP_ID",
|
||||
"type": "string",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"description": "可选:首轮标注员用户 ID",
|
||||
"key": "ANNOTATION_ASSIGNED_USER_ID",
|
||||
"type": "string",
|
||||
"value": ""
|
||||
}
|
||||
],
|
||||
"id": "operator-builtin-annotation-gate",
|
||||
@ -571,7 +609,7 @@
|
||||
"name": "原生视频标注 Gate",
|
||||
"outputs": [
|
||||
{
|
||||
"description": "已通过质检与验收的 revision artifacts",
|
||||
"description": "已通过标注质量复核的 revision artifacts",
|
||||
"id": "approved",
|
||||
"name": "approved",
|
||||
"transmission": "bus",
|
||||
@ -2037,13 +2075,30 @@
|
||||
"imageId": "ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow-poc/droboticflow-operator-package@sha256:c004ffa061d7b6af5b84c72fcde6ac6c10146fe8568d33fa22ce788df1854aa1",
|
||||
"inputs": [
|
||||
{
|
||||
"description": "切片/标注/质检结果",
|
||||
"description": "切片与人工标注结果",
|
||||
"id": "in-1",
|
||||
"name": "input",
|
||||
"name": "annotations",
|
||||
"required": true,
|
||||
"transmission": "bus",
|
||||
"type": "json"
|
||||
},
|
||||
{
|
||||
"description": "必选 Headpose manifest",
|
||||
"id": "in-2",
|
||||
"name": "headpose",
|
||||
"required": true,
|
||||
"transmission": "bus",
|
||||
"type": "json"
|
||||
},
|
||||
{
|
||||
"description": "可选 Handpose manifest",
|
||||
"id": "in-3",
|
||||
"name": "handpose",
|
||||
"transmission": "bus",
|
||||
"type": "json"
|
||||
}
|
||||
],
|
||||
"hyperparams": [{"description": "是否强制要求 Headpose", "key": "REQUIRE_HEADPOSE", "type": "boolean", "value": "false"}],
|
||||
"name": "成品打包",
|
||||
"outputs": [
|
||||
{
|
||||
@ -7476,6 +7531,13 @@
|
||||
"name": "media",
|
||||
"transmission": "bus",
|
||||
"type": "json"
|
||||
},
|
||||
{
|
||||
"description": "Run 级 deliveryOptions",
|
||||
"id": "in-2",
|
||||
"name": "options",
|
||||
"transmission": "bus",
|
||||
"type": "json"
|
||||
}
|
||||
],
|
||||
"name": "WiLoR 3D手部姿态估计",
|
||||
|
||||
@ -90,9 +90,12 @@ func TestBuiltinCatalogIncludesNativeAnnotationGateContract(t *testing.T) {
|
||||
for _, hyperparam := range item.Hyperparams {
|
||||
keys[hyperparam.Key] = true
|
||||
}
|
||||
for _, key := range []string{"ANNOTATION_TEMPLATE_ID", "ANNOTATION_WORKGROUP_ID", "ANNOTATION_ASSIGNED_USER_ID"} {
|
||||
for _, key := range []string{"ANNOTATION_TEMPLATE_ID", "ANNOTATION_WORKGROUP_ID"} {
|
||||
if !keys[key] {
|
||||
t.Fatalf("annotation gate is missing hyperparameter %s", key)
|
||||
}
|
||||
}
|
||||
if keys["ANNOTATION_ASSIGNED_USER_ID"] {
|
||||
t.Fatal("new annotation tasks must enter the available pool without a pre-assigned user")
|
||||
}
|
||||
}
|
||||
|
||||
136
internal/api/dashboard_workforce.go
Normal file
136
internal/api/dashboard_workforce.go
Normal file
@ -0,0 +1,136 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func dashboardWorkforceRange(requestTime time.Time, fromValue string, toValue string) (time.Time, time.Time, error) {
|
||||
to := requestTime.UTC()
|
||||
from := to.Add(-30 * 24 * time.Hour)
|
||||
var err error
|
||||
if strings.TrimSpace(toValue) != "" {
|
||||
to, err = time.Parse(time.RFC3339, strings.TrimSpace(toValue))
|
||||
if err != nil {
|
||||
return time.Time{}, time.Time{}, fmt.Errorf("to must be RFC3339")
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(fromValue) != "" {
|
||||
from, err = time.Parse(time.RFC3339, strings.TrimSpace(fromValue))
|
||||
if err != nil {
|
||||
return time.Time{}, time.Time{}, fmt.Errorf("from must be RFC3339")
|
||||
}
|
||||
}
|
||||
if !from.Before(to) || to.Sub(from) > 366*24*time.Hour {
|
||||
return time.Time{}, time.Time{}, fmt.Errorf("dashboard range must be positive and no longer than 366 days")
|
||||
}
|
||||
return from.UTC(), to.UTC(), nil
|
||||
}
|
||||
|
||||
func dashboardRate(numerator int64, denominator int64) *float64 {
|
||||
if denominator <= 0 {
|
||||
return nil
|
||||
}
|
||||
value := 100 * float64(numerator) / float64(denominator)
|
||||
return &value
|
||||
}
|
||||
|
||||
func finalizeDashboardWorkforceMetric(item *domain.DashboardWorkforceMetric) {
|
||||
item.QualityPassRate = dashboardRate(item.QualityApproved, item.QualityApproved+item.QualityRejected)
|
||||
item.AcceptancePassRate = dashboardRate(item.AcceptanceApproved, item.AcceptanceApproved+item.AcceptanceRejected)
|
||||
item.ReworkRate = dashboardRate(item.ReworkCount, item.SubmittedCount+item.ReworkCount)
|
||||
}
|
||||
|
||||
func addDashboardWorkforceEvent(item *domain.DashboardWorkforceMetric, event domain.AnnotationWorklogEventRecord) {
|
||||
item.DurationSeconds += event.DurationSeconds
|
||||
item.OutputCount += event.OutputDelta
|
||||
switch event.EventType {
|
||||
case "annotation_submitted":
|
||||
item.SubmittedCount++
|
||||
case "rework_submitted":
|
||||
item.ReworkCount++
|
||||
case "quality_approved":
|
||||
item.QualityApproved++
|
||||
case "quality_rejected":
|
||||
item.QualityRejected++
|
||||
case "acceptance_approved":
|
||||
item.AcceptanceApproved++
|
||||
case "acceptance_rejected":
|
||||
item.AcceptanceRejected++
|
||||
}
|
||||
}
|
||||
|
||||
func (server *server) populateDashboardWorkforce(ctx context.Context, requestOrganizationID string, principal *authenticatedPrincipal, from time.Time, to time.Time, summary *domain.DashboardSummary) error {
|
||||
if summary == nil {
|
||||
return nil
|
||||
}
|
||||
scope := "self"
|
||||
allowedVendors := map[string]struct{}{}
|
||||
if principal == nil || principal.User.Role == domain.UserRoleAdmin {
|
||||
scope = "platform"
|
||||
} else if principal.User.Role == domain.UserRoleSupplierManager {
|
||||
scope = "vendor"
|
||||
memberships, err := server.store.ListProjectAnnotationMemberships(ctx, requestOrganizationID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, membership := range memberships {
|
||||
if membership.UserID == principal.User.ID && membership.AssignmentRole == domain.AnnotationRoleVendorManager {
|
||||
allowedVendors[membership.VendorID] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
events, err := server.store.ListAnnotationWorklogEvents(ctx, requestOrganizationID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
type aggregateKey struct{ userID, vendorID, workgroupID string }
|
||||
aggregates := map[aggregateKey]*domain.DashboardWorkforceMetric{}
|
||||
totals := domain.DashboardWorkforceMetric{}
|
||||
for _, event := range events {
|
||||
createdAt, parseErr := time.Parse(time.RFC3339Nano, event.CreatedAt)
|
||||
if parseErr != nil || createdAt.Before(from) || !createdAt.Before(to) {
|
||||
continue
|
||||
}
|
||||
if scope == "self" && (principal == nil || event.UserID != principal.User.ID) {
|
||||
continue
|
||||
}
|
||||
if scope == "vendor" {
|
||||
if _, ok := allowedVendors[event.VendorID]; !ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
key := aggregateKey{event.UserID, event.VendorID, event.WorkgroupID}
|
||||
item := aggregates[key]
|
||||
if item == nil {
|
||||
item = &domain.DashboardWorkforceMetric{UserID: event.UserID, VendorID: event.VendorID, WorkgroupID: event.WorkgroupID}
|
||||
aggregates[key] = item
|
||||
}
|
||||
addDashboardWorkforceEvent(item, event)
|
||||
addDashboardWorkforceEvent(&totals, event)
|
||||
}
|
||||
items := make([]domain.DashboardWorkforceMetric, 0, len(aggregates))
|
||||
for _, item := range aggregates {
|
||||
if item.UserID != "" {
|
||||
if user, userErr := server.store.GetUser(ctx, item.UserID); userErr == nil && user != nil {
|
||||
item.UserName = user.Name
|
||||
}
|
||||
}
|
||||
finalizeDashboardWorkforceMetric(item)
|
||||
items = append(items, *item)
|
||||
}
|
||||
sort.Slice(items, func(left int, right int) bool {
|
||||
leftKey := items[left].VendorID + "\x00" + items[left].WorkgroupID + "\x00" + items[left].UserName + "\x00" + items[left].UserID
|
||||
rightKey := items[right].VendorID + "\x00" + items[right].WorkgroupID + "\x00" + items[right].UserName + "\x00" + items[right].UserID
|
||||
return leftKey < rightKey
|
||||
})
|
||||
finalizeDashboardWorkforceMetric(&totals)
|
||||
summary.AudienceScope = scope
|
||||
summary.Workforce = domain.DashboardWorkforceSummary{From: from.Format(time.RFC3339), To: to.Format(time.RFC3339), Totals: totals, Items: items}
|
||||
return nil
|
||||
}
|
||||
33
internal/api/dashboard_workforce_test.go
Normal file
33
internal/api/dashboard_workforce_test.go
Normal file
@ -0,0 +1,33 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func TestDashboardWorkforceRangeDefaultsAndCaps(t *testing.T) {
|
||||
now := time.Date(2026, 8, 19, 8, 0, 0, 0, time.UTC)
|
||||
from, to, err := dashboardWorkforceRange(now, "", "")
|
||||
if err != nil || to.Sub(from) != 30*24*time.Hour {
|
||||
t.Fatalf("unexpected default range from=%v to=%v err=%v", from, to, err)
|
||||
}
|
||||
if _, _, err := dashboardWorkforceRange(now, "2025-01-01T00:00:00Z", "2026-08-19T08:00:00Z"); err == nil {
|
||||
t.Fatal("expected range longer than 366 days to fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardWorkforceRatesUseDecisionDenominators(t *testing.T) {
|
||||
item := domain.DashboardWorkforceMetric{SubmittedCount: 8, ReworkCount: 2, QualityApproved: 9, QualityRejected: 1}
|
||||
finalizeDashboardWorkforceMetric(&item)
|
||||
if item.QualityPassRate == nil || *item.QualityPassRate != 90 {
|
||||
t.Fatalf("quality rate=%v", item.QualityPassRate)
|
||||
}
|
||||
if item.ReworkRate == nil || *item.ReworkRate != 20 {
|
||||
t.Fatalf("rework rate=%v", item.ReworkRate)
|
||||
}
|
||||
if item.AcceptancePassRate != nil {
|
||||
t.Fatalf("empty acceptance denominator must stay null: %v", item.AcceptancePassRate)
|
||||
}
|
||||
}
|
||||
@ -31,9 +31,129 @@ func (server *server) handleDeliveryPackagesList(writer http.ResponseWriter, req
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
for index := range items {
|
||||
if err := server.enrichDeliveryPackageAcceptance(request, &items[index]); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if !annotationManager(principal) {
|
||||
filtered := items[:0]
|
||||
for _, item := range items {
|
||||
if server.deliveryPackageReviewer(request, item) {
|
||||
filtered = append(filtered, item)
|
||||
}
|
||||
}
|
||||
items = filtered
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"items": items})
|
||||
}
|
||||
|
||||
func (server *server) enrichDeliveryPackageAcceptance(request *http.Request, item *domain.DeliveryPackageRecord) error {
|
||||
if item == nil || strings.TrimSpace(item.AcceptanceHumanItemID) == "" {
|
||||
return nil
|
||||
}
|
||||
humanItem, err := server.store.GetHumanItem(request.Context(), item.AcceptanceHumanItemID)
|
||||
if err != nil || humanItem == nil {
|
||||
return err
|
||||
}
|
||||
item.AcceptanceHumanItemVersion = humanItem.Version
|
||||
item.AssignedUserID = humanItem.AssignedUserID
|
||||
item.ClaimedAt = humanItem.ClaimedAt
|
||||
return nil
|
||||
}
|
||||
|
||||
func (server *server) deliveryPackageReviewer(request *http.Request, item domain.DeliveryPackageRecord) bool {
|
||||
principal, ok := currentPrincipal(request)
|
||||
if !ok || principal == nil {
|
||||
return false
|
||||
}
|
||||
if annotationManager(principal) {
|
||||
return true
|
||||
}
|
||||
memberships, err := server.annotationMembershipsForUser(request.Context(), item.OrganizationID, item.ProjectID, principal.User.ID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
legacy := domain.AnnotationTaskRecord{ProjectID: item.ProjectID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID}
|
||||
return membershipHasRole(memberships, legacy, domain.AnnotationRoleAcceptanceReviewer)
|
||||
}
|
||||
|
||||
func (server *server) handleDeliveryPackageClaim(writer http.ResponseWriter, request *http.Request) {
|
||||
item, err := server.store.GetDeliveryPackage(request.Context(), chi.URLParam(request, "id"))
|
||||
if err != nil || item == nil {
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "Delivery package not found"})
|
||||
}
|
||||
return
|
||||
}
|
||||
if !server.deliveryPackageReviewer(request, *item) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "acceptance reviewer membership is required"})
|
||||
return
|
||||
}
|
||||
var payload humanVersionRequest
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
if payload.Version != item.Version || item.Status != domain.DeliveryPackagePendingAcceptance || item.AssignedUserID != "" {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Delivery package claim conflict", "code": "version_conflict"})
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
previousVersion := item.Version
|
||||
item.AssignedUserID, item.ClaimedAt, item.Version = principal.User.ID, nowISO(), item.Version+1
|
||||
updated, updateErr := server.store.UpdateDeliveryPackageVersioned(request.Context(), *item, previousVersion)
|
||||
if updateErr != nil || !updated {
|
||||
if updateErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, updateErr)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Delivery package claim conflict", "code": "version_conflict"})
|
||||
}
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (server *server) handleDeliveryPackageRelease(writer http.ResponseWriter, request *http.Request) {
|
||||
item, err := server.store.GetDeliveryPackage(request.Context(), chi.URLParam(request, "id"))
|
||||
if err != nil || item == nil {
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "Delivery package not found"})
|
||||
}
|
||||
return
|
||||
}
|
||||
var payload humanVersionRequest
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
if principal == nil || (principal.User.Role != domain.UserRoleAdmin && item.AssignedUserID != principal.User.ID) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "only the claimant or administrator may release this package"})
|
||||
return
|
||||
}
|
||||
if payload.Version != item.Version || item.AssignedUserID == "" {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Delivery package release conflict", "code": "version_conflict"})
|
||||
return
|
||||
}
|
||||
previousVersion := item.Version
|
||||
item.AssignedUserID, item.ClaimedAt, item.Version = "", "", item.Version+1
|
||||
updated, updateErr := server.store.UpdateDeliveryPackageVersioned(request.Context(), *item, previousVersion)
|
||||
if updateErr != nil || !updated {
|
||||
if updateErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, updateErr)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Delivery package release conflict", "code": "version_conflict"})
|
||||
}
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (server *server) handleDeliveryPackageGet(writer http.ResponseWriter, request *http.Request) {
|
||||
item, err := server.store.GetDeliveryPackage(request.Context(), chi.URLParam(request, "id"))
|
||||
if err != nil {
|
||||
@ -47,6 +167,14 @@ func (server *server) handleDeliveryPackageGet(writer http.ResponseWriter, reque
|
||||
if !server.ensureTenantAccess(writer, request, item.OrganizationID, "Delivery package") {
|
||||
return
|
||||
}
|
||||
if !server.deliveryPackageReviewer(request, *item) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "acceptance reviewer membership is required"})
|
||||
return
|
||||
}
|
||||
if err := server.enrichDeliveryPackageAcceptance(request, item); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, item)
|
||||
}
|
||||
|
||||
@ -63,6 +191,14 @@ func (server *server) handleDeliveryPackageDecision(writer http.ResponseWriter,
|
||||
if !server.ensureTenantAccess(writer, request, item.OrganizationID, "Delivery package") {
|
||||
return
|
||||
}
|
||||
if !server.deliveryPackageReviewer(request, *item) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "acceptance reviewer membership is required"})
|
||||
return
|
||||
}
|
||||
if err := server.enrichDeliveryPackageAcceptance(request, item); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
var payload deliveryPackageDecisionRequest
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
@ -84,12 +220,29 @@ func (server *server) handleDeliveryPackageDecision(writer http.ResponseWriter,
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
if item.AssignedUserID != principal.User.ID || strings.TrimSpace(item.AcceptanceHumanItemID) == "" {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "delivery package must be claimed before decision", "code": "package_not_claimed"})
|
||||
return
|
||||
}
|
||||
acceptanceItem, acceptanceErr := server.store.GetHumanItem(request.Context(), item.AcceptanceHumanItemID)
|
||||
if acceptanceErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, acceptanceErr)
|
||||
return
|
||||
}
|
||||
if acceptanceItem == nil || acceptanceItem.AssignedUserID != principal.User.ID || (acceptanceItem.Status != domain.HumanItemClaimed && acceptanceItem.Status != domain.HumanItemInProgress) {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "delivery package acceptance item must be claimed before decision", "code": "package_not_claimed"})
|
||||
return
|
||||
}
|
||||
review := domain.DeliveryPackageAcceptanceReview{ID: domain.NewID("package-acceptance"), Decision: payload.Decision, ReviewerUserID: principal.User.ID, Comment: strings.TrimSpace(payload.Comment), VideoQuality: strings.TrimSpace(payload.VideoQuality), AnnotationAccuracy: payload.AnnotationAccuracy, AnnotationCompleteness: payload.AnnotationCompleteness, OverallGrade: strings.TrimSpace(payload.OverallGrade), ReasonCodes: payload.ReasonCodes, CreatedAt: nowISO()}
|
||||
previousVersion := item.Version
|
||||
item.Version++
|
||||
item.AcceptanceReviews = append(item.AcceptanceReviews, review)
|
||||
if payload.Decision == domain.HumanDecisionApproved {
|
||||
item.Status = domain.DeliveryPackageAccepted
|
||||
item.FinalExportArtifactIDs = append([]string(nil), item.ArtifactIDs...)
|
||||
if strings.TrimSpace(item.FinalExportedAt) == "" {
|
||||
item.FinalExportedAt = nowISO()
|
||||
}
|
||||
} else {
|
||||
item.Status = domain.DeliveryPackageRejected
|
||||
}
|
||||
@ -102,6 +255,41 @@ func (server *server) handleDeliveryPackageDecision(writer http.ResponseWriter,
|
||||
}
|
||||
return
|
||||
}
|
||||
previousHumanVersion := acceptanceItem.Version
|
||||
acceptanceItem.AssignedUserID = ""
|
||||
acceptanceItem.ClaimedAt = ""
|
||||
acceptanceItem.Version++
|
||||
if payload.Decision == domain.HumanDecisionApproved {
|
||||
acceptanceItem.Status = domain.HumanItemAccepted
|
||||
acceptanceItem.AcceptedAt = nowISO()
|
||||
} else {
|
||||
acceptanceItem.Status = domain.HumanItemRejected
|
||||
acceptanceItem.RejectedAt = nowISO()
|
||||
}
|
||||
humanUpdated, humanUpdateErr := server.store.UpdateHumanItemVersioned(request.Context(), *acceptanceItem, previousHumanVersion)
|
||||
if humanUpdateErr != nil || !humanUpdated {
|
||||
if humanUpdateErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, humanUpdateErr)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Acceptance item version conflict", "code": "version_conflict"})
|
||||
}
|
||||
return
|
||||
}
|
||||
_ = server.appendHumanEvent(request.Context(), *acceptanceItem, string(payload.Decision), principal.User.ID, map[string]any{"deliveryPackageId": item.ID})
|
||||
if acceptanceBatch, batchErr := server.store.GetHumanBatch(request.Context(), acceptanceItem.BatchID); batchErr == nil && acceptanceBatch != nil {
|
||||
if payload.Decision == domain.HumanDecisionApproved {
|
||||
acceptanceBatch.Status = domain.HumanBatchCompleted
|
||||
acceptanceBatch.AcceptedCount = 1
|
||||
} else {
|
||||
acceptanceBatch.Status = domain.HumanBatchBlocked
|
||||
}
|
||||
_ = server.store.UpsertHumanBatch(request.Context(), *acceptanceBatch)
|
||||
}
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: item.OrganizationID, ProjectID: item.ProjectID,
|
||||
TaskID: item.ID, UserID: principal.User.ID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
EventType: "acceptance_" + string(payload.Decision), OutputDelta: 0, CreatedAt: nowISO(),
|
||||
})
|
||||
if payload.Decision == domain.HumanDecisionRejected {
|
||||
_ = server.store.UpsertHumanReject(request.Context(), domain.HumanRejectRecord{OrganizationID: item.OrganizationID, BatchID: item.ReleasePartitionID, ItemID: item.ID, ProjectID: item.ProjectID, WorkflowID: item.WorkflowID, RunID: item.ChildRunID, StageID: "acceptance", AttemptRound: len(item.AcceptanceReviews) - 1, ReviewedRevision: item.Version, RejectedByUserID: principal.User.ID, ReasonCodes: payload.ReasonCodes, Comment: strings.TrimSpace(payload.Comment), AllowedReopenStages: []string{"split_annotation", "semantic_annotation", "quality_review"}, Status: domain.HumanRejectOpen})
|
||||
}
|
||||
|
||||
203
internal/api/fanyu_comment_followup_test.go
Normal file
203
internal/api/fanyu_comment_followup_test.go
Normal file
@ -0,0 +1,203 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
"droboticflow/internal/store"
|
||||
)
|
||||
|
||||
func TestHumanItemPoolClaimReleaseStageTransitionAndScopedContent(t *testing.T) {
|
||||
t.Setenv("DROBOTICFLOW_REQUIRE_SESSION_AUTH", "true")
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
handler := NewHandler(dataStore, nil)
|
||||
rootCookie := bootstrapSuperAdminSession(t, handler)
|
||||
organization := adminCreateOrganization(t, handler, rootCookie, "Pool Test", "pool-test")
|
||||
annotatorA := adminCreateUser(t, handler, rootCookie, organization.ID, "Annotator A", "pool-a@example.com", domain.UserRoleAnnotator, "correct-horse-battery-staple-a")
|
||||
annotatorB := adminCreateUser(t, handler, rootCookie, organization.ID, "Annotator B", "pool-b@example.com", domain.UserRoleAnnotator, "correct-horse-battery-staple-b")
|
||||
cookieA := loginSession(t, handler, annotatorA.Email, "correct-horse-battery-staple-a")
|
||||
cookieB := loginSession(t, handler, annotatorB.Email, "correct-horse-battery-staple-b")
|
||||
project, err := dataStore.CreateProject(ctx, domain.CreateProjectInput{OrganizationID: organization.ID, Name: "Pool Project"})
|
||||
if err != nil {
|
||||
t.Fatalf("create project: %v", err)
|
||||
}
|
||||
workgroup := domain.AnnotationWorkgroupRecord{ID: "group-pool", OrganizationID: organization.ID, Name: "Vendor A Team", VendorID: "vendor-a"}
|
||||
if err := dataStore.UpsertAnnotationWorkgroup(ctx, workgroup); err != nil {
|
||||
t.Fatalf("create workgroup: %v", err)
|
||||
}
|
||||
for _, user := range []domain.UserRecord{annotatorA, annotatorB} {
|
||||
if err := dataStore.UpsertProjectAnnotationMembership(ctx, domain.ProjectAnnotationMembershipRecord{
|
||||
OrganizationID: organization.ID, ProjectID: project.ID, UserID: user.ID, WorkgroupID: workgroup.ID,
|
||||
VendorID: workgroup.VendorID, AssignmentRole: domain.AnnotationRoleAnnotator,
|
||||
}); err != nil {
|
||||
t.Fatalf("create membership: %v", err)
|
||||
}
|
||||
}
|
||||
artifactPath := filepath.Join(t.TempDir(), "subject.json")
|
||||
if err := os.WriteFile(artifactPath, []byte(`{"ok":true}`), 0o600); err != nil {
|
||||
t.Fatalf("write subject: %v", err)
|
||||
}
|
||||
run := domain.RunRecord{
|
||||
ID: "run-pool", OrganizationID: organization.ID, ProjectID: project.ID, WorkflowID: "workflow-pool",
|
||||
Status: domain.RunStatusWaitingForHuman, Artifacts: []domain.ExecutionArtifact{{ID: "artifact-pool", RunID: "run-pool", Name: "subject.json", Path: artifactPath, Type: domain.PortTypeJSON}},
|
||||
}
|
||||
if err := dataStore.UpsertRun(ctx, run); err != nil {
|
||||
t.Fatalf("create run: %v", err)
|
||||
}
|
||||
batch := domain.HumanBatchRecord{
|
||||
ID: "batch-pool", OrganizationID: organization.ID, PluginID: "annotation-qa", ProjectID: project.ID,
|
||||
WorkflowID: run.WorkflowID, RunID: run.ID, GateNodeID: "gate", Status: domain.HumanBatchActive,
|
||||
Stages: domain.DefaultAnnotationHumanStages(),
|
||||
}
|
||||
if err := dataStore.UpsertHumanBatch(ctx, batch); err != nil {
|
||||
t.Fatalf("create batch: %v", err)
|
||||
}
|
||||
item := domain.HumanItemRecord{
|
||||
ID: "human-pool", OrganizationID: organization.ID, PluginID: "annotation-qa", BatchID: batch.ID,
|
||||
ProjectID: project.ID, WorkflowID: run.WorkflowID, RunID: run.ID, GateNodeID: batch.GateNodeID,
|
||||
Subject: domain.HumanSubjectRef{ArtifactID: "artifact-pool", ItemKey: "clip-1"}, CurrentStageID: "split_annotation",
|
||||
Status: domain.HumanItemReady, WorkgroupID: workgroup.ID, VendorID: workgroup.VendorID, Version: 1,
|
||||
}
|
||||
if err := dataStore.UpsertHumanItem(ctx, item); err != nil {
|
||||
t.Fatalf("create item: %v", err)
|
||||
}
|
||||
|
||||
start := make(chan struct{})
|
||||
results := make(chan struct {
|
||||
userID string
|
||||
code int
|
||||
}, 2)
|
||||
var wait sync.WaitGroup
|
||||
for _, claimant := range []struct {
|
||||
userID string
|
||||
cookie *http.Cookie
|
||||
}{{annotatorA.ID, cookieA}, {annotatorB.ID, cookieB}} {
|
||||
wait.Add(1)
|
||||
go func(userID string, cookie *http.Cookie) {
|
||||
defer wait.Done()
|
||||
<-start
|
||||
response := serveJSONWithCookie(handler, http.MethodPost, "/api/human-items/"+item.ID+"/claim", []byte(`{"version":1}`), cookie)
|
||||
results <- struct {
|
||||
userID string
|
||||
code int
|
||||
}{userID, response.Code}
|
||||
}(claimant.userID, claimant.cookie)
|
||||
}
|
||||
close(start)
|
||||
wait.Wait()
|
||||
close(results)
|
||||
winnerID := ""
|
||||
for result := range results {
|
||||
if result.code == http.StatusOK {
|
||||
if winnerID != "" {
|
||||
t.Fatalf("more than one claimant succeeded")
|
||||
}
|
||||
winnerID = result.userID
|
||||
} else if result.code != http.StatusConflict {
|
||||
t.Fatalf("claim status=%d", result.code)
|
||||
}
|
||||
}
|
||||
if winnerID == "" {
|
||||
t.Fatal("no claimant succeeded")
|
||||
}
|
||||
winnerCookie := cookieA
|
||||
if winnerID == annotatorB.ID {
|
||||
winnerCookie = cookieB
|
||||
}
|
||||
released := serveJSONWithCookie(handler, http.MethodPost, "/api/human-items/"+item.ID+"/release", []byte(`{"version":2}`), winnerCookie)
|
||||
if released.Code != http.StatusOK {
|
||||
t.Fatalf("release=%d body=%s", released.Code, released.Body.String())
|
||||
}
|
||||
claimedAgain := serveJSONWithCookie(handler, http.MethodPost, "/api/human-items/"+item.ID+"/claim", []byte(`{"version":3}`), winnerCookie)
|
||||
if claimedAgain.Code != http.StatusOK {
|
||||
t.Fatalf("claim again=%d body=%s", claimedAgain.Code, claimedAgain.Body.String())
|
||||
}
|
||||
submitted := serveJSONWithCookie(handler, http.MethodPost, "/api/human-items/"+item.ID+"/submissions", []byte(`{"version":4,"submissionRef":"slice-revision-1","revision":1}`), winnerCookie)
|
||||
if submitted.Code != http.StatusOK {
|
||||
t.Fatalf("submit=%d body=%s", submitted.Code, submitted.Body.String())
|
||||
}
|
||||
stored, _ := dataStore.GetHumanItem(ctx, item.ID)
|
||||
if stored == nil || stored.CurrentStageID != "semantic_annotation" || stored.Status != domain.HumanItemReady || stored.AssignedUserID != "" {
|
||||
t.Fatalf("stage transition must return to an unassigned pool: %#v", stored)
|
||||
}
|
||||
|
||||
genericContent := serveJSONWithCookie(handler, http.MethodGet, "/api/runs/"+run.ID+"/artifacts/artifact-pool/content", nil, winnerCookie)
|
||||
if genericContent.Code != http.StatusForbidden {
|
||||
t.Fatalf("generic run artifact content=%d body=%s", genericContent.Code, genericContent.Body.String())
|
||||
}
|
||||
subjectContent := serveJSONWithCookie(handler, http.MethodGet, "/api/human-items/"+item.ID+"/subject-content", nil, winnerCookie)
|
||||
if subjectContent.Code != http.StatusOK || subjectContent.Body.String() != `{"ok":true}` {
|
||||
t.Fatalf("scoped subject content=%d body=%s", subjectContent.Code, subjectContent.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupplierManagerDashboardIsVendorScopedAndMonitoringIsForbidden(t *testing.T) {
|
||||
t.Setenv("DROBOTICFLOW_REQUIRE_SESSION_AUTH", "true")
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
handler := NewHandler(dataStore, nil)
|
||||
rootCookie := bootstrapSuperAdminSession(t, handler)
|
||||
organization := adminCreateOrganization(t, handler, rootCookie, "Vendor Dashboard", "vendor-dashboard")
|
||||
manager := adminCreateUser(t, handler, rootCookie, organization.ID, "Supplier Manager", "supplier-manager@example.com", domain.UserRoleSupplierManager, "correct-horse-battery-staple-manager")
|
||||
managerCookie := loginSession(t, handler, manager.Email, "correct-horse-battery-staple-manager")
|
||||
project, err := dataStore.CreateProject(ctx, domain.CreateProjectInput{OrganizationID: organization.ID, Name: "Vendor Project"})
|
||||
if err != nil {
|
||||
t.Fatalf("create project: %v", err)
|
||||
}
|
||||
if err := dataStore.UpsertProjectAnnotationMembership(ctx, domain.ProjectAnnotationMembershipRecord{
|
||||
OrganizationID: organization.ID, ProjectID: project.ID, UserID: manager.ID, WorkgroupID: "group-a",
|
||||
VendorID: "vendor-a", AssignmentRole: domain.AnnotationRoleVendorManager,
|
||||
}); err != nil {
|
||||
t.Fatalf("create vendor manager membership: %v", err)
|
||||
}
|
||||
if err := dataStore.UpsertHumanBatch(ctx, domain.HumanBatchRecord{
|
||||
ID: "batch-vendor-private", OrganizationID: organization.ID, PluginID: "annotation-qa", ProjectID: project.ID,
|
||||
WorkflowID: "workflow-private", RunID: "run-private", GateNodeID: "gate", Stages: domain.DefaultAnnotationHumanStages(),
|
||||
}); err != nil {
|
||||
t.Fatalf("create private batch: %v", err)
|
||||
}
|
||||
if err := dataStore.UpsertHumanItem(ctx, domain.HumanItemRecord{
|
||||
ID: "human-vendor-private", OrganizationID: organization.ID, PluginID: "annotation-qa", BatchID: "batch-vendor-private",
|
||||
ProjectID: project.ID, WorkflowID: "workflow-private", RunID: "run-private", GateNodeID: "gate",
|
||||
Subject: domain.HumanSubjectRef{ItemKey: "private-media"}, CurrentStageID: "quality_review", Status: domain.HumanItemReady,
|
||||
WorkgroupID: "group-a", VendorID: "vendor-a", Version: 1,
|
||||
}); err != nil {
|
||||
t.Fatalf("create private item: %v", err)
|
||||
}
|
||||
now := time.Now().UTC().Format(time.RFC3339Nano)
|
||||
for _, event := range []domain.AnnotationWorklogEventRecord{
|
||||
{ID: "event-a", OrganizationID: organization.ID, ProjectID: project.ID, UserID: "worker-a", VendorID: "vendor-a", WorkgroupID: "group-a", EventType: "annotation_submitted", OutputDelta: 1, CreatedAt: now},
|
||||
{ID: "event-b", OrganizationID: organization.ID, ProjectID: project.ID, UserID: "worker-b", VendorID: "vendor-b", WorkgroupID: "group-b", EventType: "annotation_submitted", OutputDelta: 99, CreatedAt: now},
|
||||
} {
|
||||
if err := dataStore.UpsertAnnotationWorklogEvent(ctx, event); err != nil {
|
||||
t.Fatalf("create worklog event: %v", err)
|
||||
}
|
||||
}
|
||||
dashboard := serveJSONWithCookie(handler, http.MethodGet, "/api/dashboard", nil, managerCookie)
|
||||
if dashboard.Code != http.StatusOK {
|
||||
t.Fatalf("dashboard=%d body=%s", dashboard.Code, dashboard.Body.String())
|
||||
}
|
||||
var summary domain.DashboardSummary
|
||||
if err := json.Unmarshal(dashboard.Body.Bytes(), &summary); err != nil {
|
||||
t.Fatalf("decode dashboard: %v", err)
|
||||
}
|
||||
if summary.AudienceScope != "vendor" || len(summary.Workforce.Items) != 1 || summary.Workforce.Items[0].VendorID != "vendor-a" || summary.Workforce.Totals.OutputCount != 1 {
|
||||
t.Fatalf("vendor scope leaked cross-vendor metrics: %#v", summary.Workforce)
|
||||
}
|
||||
monitoring := serveJSONWithCookie(handler, http.MethodGet, "/api/runs", nil, managerCookie)
|
||||
if monitoring.Code != http.StatusForbidden {
|
||||
t.Fatalf("supplier manager monitoring=%d body=%s", monitoring.Code, monitoring.Body.String())
|
||||
}
|
||||
privateItem := serveJSONWithCookie(handler, http.MethodGet, "/api/human-items/human-vendor-private", nil, managerCookie)
|
||||
if privateItem.Code != http.StatusForbidden {
|
||||
t.Fatalf("supplier manager task media metadata=%d body=%s", privateItem.Code, privateItem.Body.String())
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@ -12,6 +13,7 @@ import (
|
||||
|
||||
const fanyuDeliveryTemplateID = "template-fanyu-right-camera-delivery-v1"
|
||||
const fanyuOrbbecDeliveryTemplateID = "template-fanyu-right-camera-delivery-v2-orbbec"
|
||||
const fanyuDeliveryTemplateV3ID = "template-fanyu-right-camera-delivery-v3"
|
||||
|
||||
func fanyuNode(id string, label string, operator domain.OperatorRecord, x float64, y float64) domain.WorkflowNode {
|
||||
cpu, memory, gpu, sharedMemory := "", "", "", ""
|
||||
@ -65,7 +67,115 @@ func (server *server) ensureFanyuDeliveryTemplate(ctx context.Context, organizat
|
||||
if err := server.ensureFanyuDeliveryTemplateV1(ctx, organizationID); err != nil {
|
||||
return err
|
||||
}
|
||||
return server.ensureFanyuOrbbecDeliveryTemplateV2(ctx, organizationID)
|
||||
if err := server.ensureFanyuOrbbecDeliveryTemplateV2(ctx, organizationID); err != nil {
|
||||
return err
|
||||
}
|
||||
return server.ensureFanyuDeliveryTemplateV3(ctx, organizationID)
|
||||
}
|
||||
|
||||
func (server *server) ensureFanyuDeliveryTemplateV3(ctx context.Context, organizationID string) error {
|
||||
templateID := fanyuDeliveryTemplateV3ID + "-" + normalizedOrganizationID(organizationID)
|
||||
releaseID := "workflow-release-fanyu-v3-" + normalizedOrganizationID(organizationID)
|
||||
if existing, err := server.store.GetWorkflowRelease(ctx, releaseID); err != nil || existing != nil {
|
||||
return err
|
||||
}
|
||||
operatorIDs := []string{
|
||||
"operator-builtin-bos-incremental-scan", "operator-builtin-orbbec-data-normalize", "operator-builtin-video-slice",
|
||||
"operator-builtin-annotation-gate", "operator-builtin-head-pose", "operator-builtin-wilor-hand-pose",
|
||||
"operator-builtin-delivery-options", "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 v3 template requires builtin operator %s", operatorID)
|
||||
}
|
||||
operators[operatorID] = *operator
|
||||
}
|
||||
headposeOverrides := map[string]string{
|
||||
"HEADPOSE_API_BASE_URL": strings.TrimSpace(os.Getenv("FANYU_HEADPOSE_API_BASE_URL")),
|
||||
"HEADPOSE_SERVICE_IMAGE_ID": strings.TrimSpace(os.Getenv("FANYU_HEADPOSE_SERVICE_IMAGE_ID")),
|
||||
"HEADPOSE_MODEL_SHA256": strings.TrimSpace(os.Getenv("FANYU_HEADPOSE_MODEL_SHA256")),
|
||||
"HEADPOSE_LICENSE_ID": strings.TrimSpace(os.Getenv("FANYU_HEADPOSE_LICENSE_ID")),
|
||||
}
|
||||
nodes := []domain.WorkflowNode{
|
||||
fanyuNode("fanyu-v3-scan", "BOS 增量扫描", operators[operatorIDs[0]], 0, 180),
|
||||
fanyuNodeWithHyperparams("fanyu-v3-normalize", "Orbbec Ego 右相机标准化", operators[operatorIDs[1]], 260, 180, map[string]string{"CAMERA_SIDE": "right", "REQUIRE_STEREO": "true"}),
|
||||
fanyuNode("fanyu-v3-slice", "右相机视频切片", operators[operatorIDs[2]], 520, 40),
|
||||
fanyuNode("fanyu-v3-human", "切片校正 → 语义标注 → 标注质量复核", operators[operatorIDs[3]], 800, 40),
|
||||
fanyuNodeWithHyperparams("fanyu-v3-headpose", "6DRepNet Headpose(必选)", operators[operatorIDs[4]], 520, 220, headposeOverrides),
|
||||
fanyuNodeWithHyperparams("fanyu-v3-handpose", "WiLoR Handpose(Run 可选)", operators[operatorIDs[5]], 800, 360, map[string]string{"INPUT_URL": "", "INPUT_PATH": "", "MEDIA_KIND": "video"}),
|
||||
fanyuNode("fanyu-v3-options", "交付选项(根输入)", operators[operatorIDs[6]], 0, 420),
|
||||
fanyuNodeWithHyperparams("fanyu-v3-package", "成品打包(Headpose 必选 / Handpose 可选)", operators[operatorIDs[7]], 1120, 180, map[string]string{"REQUIRE_HEADPOSE": "true"}),
|
||||
}
|
||||
edges := []domain.WorkflowEdge{
|
||||
fanyuEdge("fanyu-v3-e1", "fanyu-v3-scan", "out-1", "fanyu-v3-normalize", "in-1"),
|
||||
fanyuEdge("fanyu-v3-e2", "fanyu-v3-normalize", "out-1", "fanyu-v3-slice", "in-1"),
|
||||
fanyuEdge("fanyu-v3-e3", "fanyu-v3-slice", "out-1", "fanyu-v3-human", "clips"),
|
||||
fanyuEdge("fanyu-v3-e4", "fanyu-v3-normalize", "out-1", "fanyu-v3-headpose", "in-1"),
|
||||
fanyuEdge("fanyu-v3-e5", "fanyu-v3-normalize", "out-1", "fanyu-v3-handpose", "in-1"),
|
||||
fanyuEdge("fanyu-v3-e6", "fanyu-v3-options", "out-1", "fanyu-v3-handpose", "in-2"),
|
||||
fanyuEdge("fanyu-v3-e7", "fanyu-v3-human", "approved", "fanyu-v3-package", "in-1"),
|
||||
fanyuEdge("fanyu-v3-e8", "fanyu-v3-headpose", "out-1", "fanyu-v3-package", "in-2"),
|
||||
fanyuEdge("fanyu-v3-e9", "fanyu-v3-handpose", "out-1", "fanyu-v3-package", "in-3"),
|
||||
}
|
||||
workflowInputs := []domain.WorkflowInputDefinition{{
|
||||
ID: "deliveryOptions", Name: "deliveryOptions", Description: "每次运行选择是否包含 Handpose",
|
||||
Type: domain.PortTypeJSON, Required: true,
|
||||
DefaultPayload: &domain.ArtifactPayload{Mode: domain.ArtifactTransferModeInline, Type: domain.PortTypeJSON, Inline: map[string]any{"includeHandpose": false}},
|
||||
Bindings: []domain.WorkflowInputTarget{{NodeID: "fanyu-v3-options", TargetPortID: "in-1"}},
|
||||
}}
|
||||
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: normalizedOrganizationID(organizationID), Name: "01-右相机切分标注质检-v3",
|
||||
Description: "右相机切片、人工标注质量复核、必选 Headpose、Run 级可选 Handpose、三输入成品打包与包级最终验收。",
|
||||
Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindScan, ExecutionScope: domain.WorkflowExecutionScopeProduction,
|
||||
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 v3 template: %s", strings.TrimSpace(issues[0].Message))
|
||||
}
|
||||
if issues := validateWorkflowInputContract(nodes, edges, workflowInputs, true); len(issues) > 0 {
|
||||
return fmt.Errorf("invalid fanyu v3 input contract: %s", strings.TrimSpace(issues[0].Message))
|
||||
}
|
||||
if err := server.store.UpsertTemplate(ctx, template); err != nil {
|
||||
return err
|
||||
}
|
||||
headposeOperator := operators["operator-builtin-head-pose"]
|
||||
serviceImageID := headposeOverrides["HEADPOSE_SERVICE_IMAGE_ID"]
|
||||
modelDigest := headposeOverrides["HEADPOSE_MODEL_SHA256"]
|
||||
if effectiveOperatorPublicationStatus(headposeOperator) != domain.OperatorPublicationStatusPublished ||
|
||||
!operatorImageDigestPattern.MatchString(strings.TrimSpace(headposeOperator.ImageID)) ||
|
||||
strings.TrimSpace(headposeOverrides["HEADPOSE_API_BASE_URL"]) == "" ||
|
||||
!operatorImageDigestPattern.MatchString(serviceImageID) ||
|
||||
!imageDigestPattern.MatchString(modelDigest) ||
|
||||
strings.TrimSpace(headposeOverrides["HEADPOSE_LICENSE_ID"]) == "" {
|
||||
// Keep v3 as an editable template until both the operator image and real
|
||||
// 6DRepNet service are digest pinned. A system restart after configuring
|
||||
// the two FANYU_HEADPOSE_* values will publish the immutable release.
|
||||
return nil
|
||||
}
|
||||
if issues := server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction); len(issues) > 0 {
|
||||
return nil
|
||||
}
|
||||
release := domain.WorkflowReleaseRecord{
|
||||
ID: releaseID, OrganizationID: normalizedOrganizationID(organizationID),
|
||||
TemplateID: template.ID, Version: 3, 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{"human_annotation", "human_quality_review", "human_acceptance"},
|
||||
RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template),
|
||||
ReleaseNotes: "Headpose required, Handpose optional per Run, task-pool human workflow", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now,
|
||||
}
|
||||
return server.store.UpsertWorkflowRelease(ctx, release)
|
||||
}
|
||||
|
||||
func (server *server) ensureFanyuDeliveryTemplateV1(ctx context.Context, organizationID string) error {
|
||||
|
||||
@ -93,3 +93,65 @@ func TestEnsureFanyuDeliveryTemplatePublishesOrbbecV2WithoutMutatingV1(t *testin
|
||||
t.Fatalf("unexpected v2 release: %#v", release)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFanyuV3StaysDraftUntilRealHeadposeServiceAndDigestsAreConfigured(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
items, err := builtinOperatorRecords("2026-08-19T00: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.Fatalf("upsert operator %s: %v", item.ID, err)
|
||||
}
|
||||
}
|
||||
server := &server{store: dataStore}
|
||||
if err := server.ensureFanyuDeliveryTemplate(ctx, "org-v3"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
templateID := fanyuDeliveryTemplateV3ID + "-org-v3"
|
||||
template, err := dataStore.GetTemplate(ctx, templateID)
|
||||
if err != nil || template == nil {
|
||||
t.Fatalf("v3 template=%#v err=%v", template, err)
|
||||
}
|
||||
if len(template.Nodes) != 8 || len(template.Edges) != 9 || len(template.WorkflowInputs) != 1 {
|
||||
t.Fatalf("unexpected v3 topology: %#v", template)
|
||||
}
|
||||
for _, node := range template.Nodes {
|
||||
if node.Data.OperatorID == "operator-builtin-video-quality" {
|
||||
t.Fatalf("v3 must not contain a dedicated video-quality node: %#v", node)
|
||||
}
|
||||
}
|
||||
input := template.WorkflowInputs[0]
|
||||
if input.ID != "deliveryOptions" || input.DefaultPayload == nil || input.DefaultPayload.Mode != domain.ArtifactTransferModeInline {
|
||||
t.Fatalf("delivery options input=%#v", input)
|
||||
}
|
||||
if release, releaseErr := dataStore.GetWorkflowRelease(ctx, "workflow-release-fanyu-v3-org-v3"); releaseErr != nil || release != nil {
|
||||
t.Fatalf("v3 release must be blocked without real Headpose evidence: release=%#v err=%v", release, releaseErr)
|
||||
}
|
||||
|
||||
headpose, err := dataStore.GetOperator(ctx, "operator-builtin-head-pose")
|
||||
if err != nil || headpose == nil {
|
||||
t.Fatalf("headpose operator=%#v err=%v", headpose, err)
|
||||
}
|
||||
digest := "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
headpose.ImageID = "registry.example/droboticflow-operator-head-pose@" + digest
|
||||
if err := dataStore.UpsertOperator(ctx, *headpose); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("FANYU_HEADPOSE_API_BASE_URL", "http://headpose.droboticflow.svc.cluster.local")
|
||||
t.Setenv("FANYU_HEADPOSE_SERVICE_IMAGE_ID", "registry.example/6drepnet-service@"+digest)
|
||||
t.Setenv("FANYU_HEADPOSE_MODEL_SHA256", digest)
|
||||
t.Setenv("FANYU_HEADPOSE_LICENSE_ID", "MIT")
|
||||
if err := server.ensureFanyuDeliveryTemplate(ctx, "org-v3"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
release, err := dataStore.GetWorkflowRelease(ctx, "workflow-release-fanyu-v3-org-v3")
|
||||
if err != nil || release == nil {
|
||||
t.Fatalf("v3 release=%#v err=%v", release, err)
|
||||
}
|
||||
if release.Version != 3 || len(release.WorkflowInputs) != 1 || fanyuTestHyperparam(fanyuTestNode(release.Nodes, "fanyu-v3-headpose"), "HEADPOSE_SERVICE_IMAGE_ID") == "" {
|
||||
t.Fatalf("unexpected v3 release: %#v", release)
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,20 +77,76 @@ func (server *server) handleHumanBatchesList(writer http.ResponseWriter, request
|
||||
return
|
||||
}
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
if !annotationManager(principal) {
|
||||
filtered := make([]domain.HumanBatchRecord, 0, len(items))
|
||||
for _, batch := range items {
|
||||
batchItems, listErr := server.store.ListHumanItems(request.Context(), batch.OrganizationID, domain.HumanItemQuery{BatchID: batch.ID})
|
||||
if listErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, listErr)
|
||||
return
|
||||
}
|
||||
for _, item := range batchItems {
|
||||
if server.canAccessHumanItem(request.Context(), request, item, "") {
|
||||
filtered = append(filtered, batch)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
items = filtered
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"items": items})
|
||||
}
|
||||
|
||||
func (server *server) handleHumanItemsList(writer http.ResponseWriter, request *http.Request) {
|
||||
pool := strings.TrimSpace(request.URL.Query().Get("pool"))
|
||||
principal, _ := currentPrincipal(request)
|
||||
if pool == "" {
|
||||
if annotationManager(principal) {
|
||||
pool = "all"
|
||||
} else {
|
||||
pool = "available"
|
||||
}
|
||||
}
|
||||
if pool != "available" && pool != "mine" && pool != "all" {
|
||||
renderValidationError(writer, validationIssue{Field: "pool", Message: "pool must be available, mine, or all"})
|
||||
return
|
||||
}
|
||||
if pool == "all" && !annotationManager(principal) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "only administrators may list all human items"})
|
||||
return
|
||||
}
|
||||
items, err := server.store.ListHumanItems(request.Context(), server.requestOrganizationID(request), parseHumanItemQuery(request))
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
filtered := make([]domain.HumanItemRecord, 0, len(items))
|
||||
batchByID := map[string]*domain.HumanBatchRecord{}
|
||||
for _, item := range items {
|
||||
if server.canAccessHumanItem(request.Context(), request, item, "") {
|
||||
filtered = append(filtered, item)
|
||||
batch, loaded := batchByID[item.BatchID]
|
||||
if !loaded {
|
||||
batch, err = server.store.GetHumanBatch(request.Context(), item.BatchID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
batchByID[item.BatchID] = batch
|
||||
}
|
||||
stage, _, found := humanStage(batch, item.CurrentStageID)
|
||||
if !found || !server.canAccessHumanItem(request.Context(), request, item, annotationRoleForHumanStage(stage)) {
|
||||
continue
|
||||
}
|
||||
if pool == "mine" && (principal == nil || item.AssignedUserID != principal.User.ID) {
|
||||
continue
|
||||
}
|
||||
if pool == "available" {
|
||||
availableStatus := item.Status == domain.HumanItemReady || item.Status == domain.HumanItemRework || item.Status == domain.HumanItemSubmitted
|
||||
if item.AssignedUserID != "" || !availableStatus {
|
||||
continue
|
||||
}
|
||||
}
|
||||
filtered = append(filtered, item)
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"items": filtered})
|
||||
}
|
||||
@ -128,6 +184,18 @@ func (server *server) handleHumanItemGet(writer http.ResponseWriter, request *ht
|
||||
renderJSON(writer, http.StatusOK, detail)
|
||||
}
|
||||
|
||||
func (server *server) handleHumanItemSubjectContent(writer http.ResponseWriter, request *http.Request) {
|
||||
item, ok := server.loadHumanItemForRequest(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if strings.TrimSpace(item.RunID) == "" || strings.TrimSpace(item.Subject.ArtifactID) == "" {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "Human item subject artifact not found"})
|
||||
return
|
||||
}
|
||||
server.serveRunArtifactContent(writer, request, item.RunID, item.Subject.ArtifactID)
|
||||
}
|
||||
|
||||
func (server *server) loadHumanItemForRequest(writer http.ResponseWriter, request *http.Request) (*domain.HumanItemRecord, bool) {
|
||||
item, err := server.store.GetHumanItem(request.Context(), chi.URLParam(request, "id"))
|
||||
if err != nil {
|
||||
@ -190,7 +258,7 @@ func (server *server) canAccessHumanItem(ctx context.Context, request *http.Requ
|
||||
if requiredRole != "" {
|
||||
return membershipHasRole(memberships, legacy, requiredRole)
|
||||
}
|
||||
return membershipAllowsTask(memberships, legacy)
|
||||
return membershipAllowsTaskRead(memberships, legacy)
|
||||
}
|
||||
|
||||
func (server *server) appendHumanEvent(ctx context.Context, item domain.HumanItemRecord, eventType string, actorID string, payload map[string]any) error {
|
||||
@ -216,6 +284,37 @@ func (server *server) humanItemForLegacyTask(ctx context.Context, task domain.An
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (server *server) requireLegacyHumanItemClaim(writer http.ResponseWriter, request *http.Request, task domain.AnnotationTaskRecord, stageID string) (*domain.HumanItemRecord, bool) {
|
||||
item, err := server.humanItemForLegacyTask(request.Context(), task)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return nil, false
|
||||
}
|
||||
if item == nil {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{
|
||||
"error": "Human item is required before modifying an annotation task",
|
||||
"code": "human_item_required",
|
||||
})
|
||||
return nil, false
|
||||
}
|
||||
principal, ok := currentPrincipal(request)
|
||||
if !ok || principal == nil || item.AssignedUserID != principal.User.ID || (item.Status != domain.HumanItemClaimed && item.Status != domain.HumanItemInProgress) {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{
|
||||
"error": "Human item must be claimed by the current user before this operation",
|
||||
"code": "human_item_claim_required",
|
||||
})
|
||||
return nil, false
|
||||
}
|
||||
if strings.TrimSpace(stageID) != "" && item.CurrentStageID != stageID {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{
|
||||
"error": "Human item is not in the required stage",
|
||||
"code": "human_item_stage_conflict",
|
||||
})
|
||||
return nil, false
|
||||
}
|
||||
return item, true
|
||||
}
|
||||
|
||||
func (server *server) syncLegacyTaskFromHumanItem(ctx context.Context, item domain.HumanItemRecord) error {
|
||||
if item.LegacyTaskID == "" {
|
||||
return nil
|
||||
@ -315,6 +414,7 @@ func (server *server) syncHumanItemFromLegacyRevision(ctx context.Context, task
|
||||
item.Status = domain.HumanItemSubmitted
|
||||
item.SubmittedAt = nowISO()
|
||||
item.AssignedUserID = ""
|
||||
item.ClaimedAt = ""
|
||||
item.Version++
|
||||
updated, err := server.store.UpdateHumanItemVersioned(ctx, *item, previousVersion)
|
||||
if err != nil || !updated {
|
||||
@ -365,9 +465,8 @@ func (server *server) syncHumanItemFromLegacyReview(ctx context.Context, task do
|
||||
item.Status = domain.HumanItemRejected
|
||||
item.RejectedAt = nowISO()
|
||||
}
|
||||
if item.Status != domain.HumanItemRejected {
|
||||
item.AssignedUserID = ""
|
||||
}
|
||||
item.AssignedUserID = ""
|
||||
item.ClaimedAt = ""
|
||||
item.Version++
|
||||
updated, err := server.store.UpdateHumanItemVersioned(ctx, *item, previousVersion)
|
||||
if err != nil || !updated {
|
||||
@ -465,6 +564,54 @@ func (server *server) handleHumanItemClaim(writer http.ResponseWriter, request *
|
||||
renderJSON(writer, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (server *server) handleHumanItemRelease(writer http.ResponseWriter, request *http.Request) {
|
||||
item, ok := server.loadHumanItemForRequest(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var payload humanVersionRequest
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
if payload.Version != item.Version {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Human item version conflict", "code": "version_conflict"})
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
if principal == nil || (principal.User.Role != domain.UserRoleAdmin && item.AssignedUserID != principal.User.ID) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "only the claimant or an administrator may release this item"})
|
||||
return
|
||||
}
|
||||
if item.Status != domain.HumanItemClaimed && item.Status != domain.HumanItemInProgress {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Human item cannot be released from current status"})
|
||||
return
|
||||
}
|
||||
previousVersion := item.Version
|
||||
item.AssignedUserID = ""
|
||||
item.ClaimedAt = ""
|
||||
if item.ReviewRound > 0 {
|
||||
item.Status = domain.HumanItemRework
|
||||
} else {
|
||||
item.Status = domain.HumanItemReady
|
||||
}
|
||||
item.Version++
|
||||
updated, err := server.store.UpdateHumanItemVersioned(request.Context(), *item, previousVersion)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if !updated {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Human item version conflict", "code": "version_conflict"})
|
||||
return
|
||||
}
|
||||
_ = server.store.UpsertHumanStageAttempt(request.Context(), domain.HumanStageAttemptRecord{
|
||||
OrganizationID: item.OrganizationID, ItemID: item.ID, StageID: item.CurrentStageID, Round: item.ReviewRound,
|
||||
Status: item.Status,
|
||||
})
|
||||
_ = server.appendHumanEvent(request.Context(), *item, "released", principal.User.ID, nil)
|
||||
renderJSON(writer, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (server *server) handleHumanItemSubmission(writer http.ResponseWriter, request *http.Request) {
|
||||
item, ok := server.loadHumanItemForRequest(writer, request)
|
||||
if !ok {
|
||||
@ -493,11 +640,11 @@ func (server *server) handleHumanItemSubmission(writer http.ResponseWriter, requ
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
if !server.canAccessHumanItem(request.Context(), request, *item, annotationRoleForHumanStage(stage)) || (item.AssignedUserID != "" && item.AssignedUserID != principal.User.ID && !annotationManager(principal)) {
|
||||
if !server.canAccessHumanItem(request.Context(), request, *item, annotationRoleForHumanStage(stage)) || item.AssignedUserID != principal.User.ID {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "Human item assignee permission required"})
|
||||
return
|
||||
}
|
||||
if item.Status != domain.HumanItemClaimed && item.Status != domain.HumanItemInProgress && item.Status != domain.HumanItemRework {
|
||||
if item.Status != domain.HumanItemClaimed && item.Status != domain.HumanItemInProgress {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Human item cannot be submitted from current status"})
|
||||
return
|
||||
}
|
||||
@ -519,11 +666,9 @@ func (server *server) handleHumanItemSubmission(writer http.ResponseWriter, requ
|
||||
} else {
|
||||
item.CurrentStageID = batch.Stages[stageIndex+1].ID
|
||||
item.Status = domain.HumanItemReady
|
||||
if batch.Stages[stageIndex+1].Kind == domain.HumanStageReview || batch.Stages[stageIndex+1].Kind == domain.HumanStageAcceptance {
|
||||
item.Status = domain.HumanItemSubmitted
|
||||
}
|
||||
}
|
||||
item.AssignedUserID = ""
|
||||
item.ClaimedAt = ""
|
||||
item.Version++
|
||||
updated, err := server.store.UpdateHumanItemVersioned(request.Context(), *item, previousVersion)
|
||||
if err != nil || !updated {
|
||||
@ -600,11 +745,15 @@ func (server *server) handleHumanItemDecision(writer http.ResponseWriter, reques
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "Human review role is required"})
|
||||
return
|
||||
}
|
||||
if item.AssignedUserID != principal.User.ID {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Human item must be claimed before review", "code": "human_item_claim_required"})
|
||||
return
|
||||
}
|
||||
if item.LatestAuthorUserID != "" && item.LatestAuthorUserID == principal.User.ID {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "A submitter cannot review their own annotation", "code": "separation_of_duties"})
|
||||
return
|
||||
}
|
||||
if item.Status != domain.HumanItemSubmitted && item.Status != domain.HumanItemClaimed {
|
||||
if item.Status != domain.HumanItemClaimed && item.Status != domain.HumanItemInProgress {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Human item cannot be reviewed from current status"})
|
||||
return
|
||||
}
|
||||
@ -621,10 +770,7 @@ func (server *server) handleHumanItemDecision(writer http.ResponseWriter, reques
|
||||
item.AcceptedAt = nowISO()
|
||||
} else {
|
||||
item.CurrentStageID = batch.Stages[stageIndex+1].ID
|
||||
item.Status = domain.HumanItemSubmitted
|
||||
if batch.Stages[stageIndex+1].Kind == domain.HumanStageAnnotation {
|
||||
item.Status = domain.HumanItemReady
|
||||
}
|
||||
item.Status = domain.HumanItemReady
|
||||
}
|
||||
} else {
|
||||
if len(payload.ReasonCodes) == 0 || strings.TrimSpace(payload.Comment) == "" {
|
||||
@ -644,6 +790,8 @@ func (server *server) handleHumanItemDecision(writer http.ResponseWriter, reques
|
||||
item.Status = domain.HumanItemRejected
|
||||
item.RejectedAt = nowISO()
|
||||
}
|
||||
item.AssignedUserID = ""
|
||||
item.ClaimedAt = ""
|
||||
item.Version++
|
||||
updated, err := server.store.UpdateHumanItemVersioned(request.Context(), *item, previousVersion)
|
||||
if err != nil || !updated {
|
||||
@ -696,9 +844,28 @@ func (server *server) handleHumanRejectsList(writer http.ResponseWriter, request
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
if !annotationManager(principal) {
|
||||
filtered := make([]domain.HumanRejectRecord, 0, len(items))
|
||||
for _, reject := range items {
|
||||
if server.canAccessHumanReject(request, reject) {
|
||||
filtered = append(filtered, reject)
|
||||
}
|
||||
}
|
||||
items = filtered
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"items": items})
|
||||
}
|
||||
|
||||
func (server *server) canAccessHumanReject(request *http.Request, reject domain.HumanRejectRecord) bool {
|
||||
item, err := server.store.GetHumanItem(request.Context(), reject.ItemID)
|
||||
if err == nil && item != nil {
|
||||
return server.canAccessHumanItem(request.Context(), request, *item, "")
|
||||
}
|
||||
itemPackage, packageErr := server.store.GetDeliveryPackage(request.Context(), reject.ItemID)
|
||||
return packageErr == nil && itemPackage != nil && server.deliveryPackageReviewer(request, *itemPackage)
|
||||
}
|
||||
|
||||
func (server *server) handleHumanRejectGet(writer http.ResponseWriter, request *http.Request) {
|
||||
item, err := server.store.GetHumanReject(request.Context(), chi.URLParam(request, "id"))
|
||||
if err != nil {
|
||||
@ -712,6 +879,11 @@ func (server *server) handleHumanRejectGet(writer http.ResponseWriter, request *
|
||||
if !server.ensureTenantAccess(writer, request, item.OrganizationID, "Human reject record") {
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
if !annotationManager(principal) && !server.canAccessHumanReject(request, *item) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "human workgroup access is required"})
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, item)
|
||||
}
|
||||
|
||||
@ -782,7 +954,8 @@ func (server *server) handleHumanRejectReopen(writer http.ResponseWriter, reques
|
||||
} else {
|
||||
item.CurrentStageID = strings.TrimSpace(payload.TargetStageID)
|
||||
item.Status = domain.HumanItemRework
|
||||
item.AssignedUserID = item.LatestAuthorUserID
|
||||
item.AssignedUserID = ""
|
||||
item.ClaimedAt = ""
|
||||
reject.Status = domain.HumanRejectReopened
|
||||
}
|
||||
updated, err := server.store.UpdateHumanItemVersioned(request.Context(), *item, previousItemVersion)
|
||||
@ -864,7 +1037,8 @@ func (server *server) reopenRejectedDeliveryPackage(writer http.ResponseWriter,
|
||||
} else {
|
||||
humanItem.CurrentStageID = strings.TrimSpace(payload.TargetStageID)
|
||||
humanItem.Status = domain.HumanItemRework
|
||||
humanItem.AssignedUserID = humanItem.LatestAuthorUserID
|
||||
humanItem.AssignedUserID = ""
|
||||
humanItem.ClaimedAt = ""
|
||||
reject.Status = domain.HumanRejectReopened
|
||||
}
|
||||
updated, updateErr := server.store.UpdateHumanItemVersioned(request.Context(), *humanItem, previousVersion)
|
||||
|
||||
@ -31,7 +31,8 @@ func TestAllowedHumanReopenStagesKeepsRejectZoneSeparateFromRework(t *testing.T)
|
||||
if len(quality) != 3 || quality[0] != "split_annotation" || quality[2] != "quality_review" {
|
||||
t.Fatalf("quality reopen stages=%#v", quality)
|
||||
}
|
||||
acceptance := allowedHumanReopenStages(batch, "acceptance")
|
||||
legacyAcceptanceBatch := &domain.HumanBatchRecord{Stages: append(domain.DefaultAnnotationHumanStages(), domain.HumanStageDefinition{ID: "acceptance", Label: "最终验收", Kind: domain.HumanStageAcceptance, RequiredRole: "acceptance_reviewer"})}
|
||||
acceptance := allowedHumanReopenStages(legacyAcceptanceBatch, "acceptance")
|
||||
if len(acceptance) != 3 || containsHumanStage(acceptance, "acceptance") {
|
||||
t.Fatalf("acceptance must reopen an earlier production stage: %#v", acceptance)
|
||||
}
|
||||
|
||||
@ -185,6 +185,9 @@ func (server *server) migrateLegacyAnnotationHumanItems(ctx context.Context, org
|
||||
batchByKey[groupKey] = batch
|
||||
}
|
||||
stageID, status := humanItemStateFromLegacyTask(task)
|
||||
if _, _, found := humanStage(&batch, stageID); !found && len(batch.Stages) > 0 {
|
||||
stageID = batch.Stages[len(batch.Stages)-1].ID
|
||||
}
|
||||
authorID := ""
|
||||
revisions, err := server.store.ListAnnotationRevisions(ctx, organizationID, task.ID)
|
||||
if err != nil {
|
||||
@ -209,6 +212,10 @@ func (server *server) migrateLegacyAnnotationHumanItems(ctx context.Context, org
|
||||
if status == domain.HumanItemAccepted {
|
||||
item.AcceptedAt = task.UpdatedAt
|
||||
}
|
||||
if item.AssignedUserID != "" && (item.Status == domain.HumanItemReady || item.Status == domain.HumanItemRework || item.Status == domain.HumanItemSubmitted) {
|
||||
item.Status = domain.HumanItemClaimed
|
||||
item.ClaimedAt = task.UpdatedAt
|
||||
}
|
||||
if err := server.store.UpsertHumanItem(ctx, item); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -34,9 +34,9 @@ func TestWorkflowReleaseDigestIgnoresMutableTimestamps(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultAnnotationStagesEndAtFinalAcceptance(t *testing.T) {
|
||||
func TestDefaultAnnotationStagesEndAtQualityReview(t *testing.T) {
|
||||
stages := domain.DefaultAnnotationHumanStages()
|
||||
if len(stages) != 4 || stages[0].ID != "split_annotation" || stages[1].ID != "semantic_annotation" || stages[2].ID != "quality_review" || stages[3].ID != "acceptance" {
|
||||
if len(stages) != 3 || stages[0].ID != "split_annotation" || stages[1].ID != "semantic_annotation" || stages[2].ID != "quality_review" {
|
||||
t.Fatalf("stages=%#v", stages)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1325,7 +1325,7 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Post("/api/acceptance/poc-operator-workflows", instance.handlePocOperatorWorkflowAcceptance)
|
||||
router.Post("/api/operators/image-archives/import", instance.handleOperatorImageArchiveImport)
|
||||
})
|
||||
router.Get("/api/acceptance/poc-readiness", instance.handlePocAcceptanceReadiness)
|
||||
router.With(instance.requireAdminMonitoringAccess).Get("/api/acceptance/poc-readiness", instance.handlePocAcceptanceReadiness)
|
||||
router.Get("/api/dashboard", instance.handleDashboard)
|
||||
router.Get("/api/plugins", instance.handlePluginsList)
|
||||
router.Get("/api/organizations/{id}/plugins/{pluginId}", instance.handleOrganizationPluginGet)
|
||||
@ -1336,12 +1336,14 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Get("/api/human-batches", instance.handleHumanBatchesList)
|
||||
router.Get("/api/human-items", instance.handleHumanItemsList)
|
||||
router.Get("/api/human-items/{id}", instance.handleHumanItemGet)
|
||||
router.Get("/api/human-items/{id}/subject-content", instance.handleHumanItemSubjectContent)
|
||||
router.Get("/api/human-items/{id}/events", instance.handleHumanItemEvents)
|
||||
router.Get("/api/human-rejects", instance.handleHumanRejectsList)
|
||||
router.Get("/api/human-rejects/{id}", instance.handleHumanRejectGet)
|
||||
router.Group(func(router chi.Router) {
|
||||
router.Use(instance.requireBusinessRole(domain.UserRoleAdmin, domain.UserRoleAnnotator, domain.UserRoleQualityReviewer, domain.UserRoleAcceptanceReviewer, domain.UserRolePipelineEngineer, domain.UserRoleDataOperator, domain.UserRoleQAReviewer, domain.UserRoleAuditor, domain.UserRoleOperator))
|
||||
router.Post("/api/human-items/{id}/claim", instance.handleHumanItemClaim)
|
||||
router.Post("/api/human-items/{id}/release", instance.handleHumanItemRelease)
|
||||
router.Post("/api/human-items/{id}/submissions", instance.handleHumanItemSubmission)
|
||||
router.Post("/api/human-items/{id}/decisions", instance.handleHumanItemDecision)
|
||||
})
|
||||
@ -1410,7 +1412,7 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Get("/api/workflows/{id}", instance.handleWorkflowsGet)
|
||||
router.Get("/api/templates/{id}/releases", instance.handleTemplateReleasesList)
|
||||
router.Get("/api/workflow-releases/{id}", instance.handleWorkflowReleaseGet)
|
||||
router.Get("/api/workflows/{id}/runs", instance.handleWorkflowRunsList)
|
||||
router.With(instance.requireAdminMonitoringAccess).Get("/api/workflows/{id}/runs", instance.handleWorkflowRunsList)
|
||||
router.Get("/api/workflows/{id}/nodes/{nodeId}/source-state", instance.handleWorkflowNodeSourceStateGet)
|
||||
router.Get("/api/scan-configs", instance.handleScanConfigsList)
|
||||
router.Get("/api/scan-configs/{id}", instance.handleScanConfigsGet)
|
||||
@ -1447,6 +1449,8 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Get("/api/delivery-packages/{id}", instance.handleDeliveryPackageGet)
|
||||
router.Group(func(router chi.Router) {
|
||||
router.Use(instance.requireBusinessRole(domain.UserRoleAdmin, domain.UserRoleAcceptanceReviewer))
|
||||
router.Post("/api/delivery-packages/{id}/claim", instance.handleDeliveryPackageClaim)
|
||||
router.Post("/api/delivery-packages/{id}/release", instance.handleDeliveryPackageRelease)
|
||||
router.Post("/api/delivery-packages/{id}/decisions", instance.handleDeliveryPackageDecision)
|
||||
})
|
||||
|
||||
@ -1496,15 +1500,18 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Delete("/api/database/collections/{name}/documents/{documentId}", instance.handleDatabaseDocumentDelete)
|
||||
})
|
||||
|
||||
router.Get("/api/runs", instance.handleRunsList)
|
||||
router.Get("/api/runs/{id}", instance.handleRunsGet)
|
||||
router.Get("/api/runs/{id}/logs", instance.handleRunsLogs)
|
||||
router.Get("/api/runs/{id}/resources", instance.handleRunsResources)
|
||||
router.Get("/api/runs/{id}/artifacts", instance.handleRunsArtifacts)
|
||||
router.Get("/api/runs/{id}/artifacts/{artifactId}/content", instance.handleRunsArtifactContent)
|
||||
router.Head("/api/runs/{id}/artifacts/{artifactId}/content", instance.handleRunsArtifactContent)
|
||||
router.Get("/api/runs/{id}/lineage", instance.handleRunsLineage)
|
||||
router.Get("/api/artifacts/{artifactId}/lineage", instance.handleArtifactLineage)
|
||||
router.Group(func(router chi.Router) {
|
||||
router.Use(instance.requireAdminMonitoringAccess)
|
||||
router.Get("/api/runs", instance.handleRunsList)
|
||||
router.Get("/api/runs/{id}", instance.handleRunsGet)
|
||||
router.Get("/api/runs/{id}/logs", instance.handleRunsLogs)
|
||||
router.Get("/api/runs/{id}/resources", instance.handleRunsResources)
|
||||
router.Get("/api/runs/{id}/artifacts", instance.handleRunsArtifacts)
|
||||
router.Get("/api/runs/{id}/lineage", instance.handleRunsLineage)
|
||||
router.Get("/api/artifacts/{artifactId}/lineage", instance.handleArtifactLineage)
|
||||
router.Get("/api/runs/{id}/artifacts/{artifactId}/content", instance.handleRunsArtifactContent)
|
||||
router.Head("/api/runs/{id}/artifacts/{artifactId}/content", instance.handleRunsArtifactContent)
|
||||
})
|
||||
router.Group(func(router chi.Router) {
|
||||
router.Use(instance.requireBusinessRole(domain.UserRoleAdmin, domain.UserRolePipelineEngineer, domain.UserRoleDataOperator, domain.UserRoleOperator))
|
||||
router.Post("/api/runs/{id}/rerun-subtree", instance.handleRunsRerunSubtree)
|
||||
@ -1805,6 +1812,21 @@ func filterAIPublishedWorkflowOperators(items []domain.OperatorRecord) []domain.
|
||||
}
|
||||
|
||||
func (server *server) handleDashboard(writer http.ResponseWriter, request *http.Request) {
|
||||
from, to, rangeErr := dashboardWorkforceRange(time.Now(), request.URL.Query().Get("from"), request.URL.Query().Get("to"))
|
||||
if rangeErr != nil {
|
||||
renderValidationError(writer, validationIssue{Field: "range", Message: rangeErr.Error()})
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
if server.tenantEnforced(request) && principal != nil && principal.User.Role != domain.UserRoleAdmin {
|
||||
summary := domain.DashboardSummary{}
|
||||
if err := server.populateDashboardWorkforce(request.Context(), server.requestOrganizationID(request), principal, from, to, &summary); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, summary)
|
||||
return
|
||||
}
|
||||
if server.tenantEnforced(request) {
|
||||
projects, err := server.listProjectsForRequest(request.Context(), request)
|
||||
if err != nil {
|
||||
@ -1834,6 +1856,10 @@ func (server *server) handleDashboard(writer http.ResponseWriter, request *http.
|
||||
summary := store.BuildDashboardSummaryAt(projects, operators, runSummaries, auditTasks, settings.Timezone, time.Now())
|
||||
enrichDashboardOperatorInventory(&summary, operators)
|
||||
server.enrichDashboardHumanWork(request.Context(), request, &summary)
|
||||
if err := server.populateDashboardWorkforce(request.Context(), server.requestOrganizationID(request), principal, from, to, &summary); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
server.enrichDashboardPOC(request.Context(), request, &summary)
|
||||
renderJSON(writer, http.StatusOK, summary)
|
||||
return
|
||||
@ -1850,6 +1876,10 @@ func (server *server) handleDashboard(writer http.ResponseWriter, request *http.
|
||||
}
|
||||
enrichDashboardOperatorInventory(&summary, operators)
|
||||
server.enrichDashboardHumanWork(request.Context(), request, &summary)
|
||||
if err := server.populateDashboardWorkforce(request.Context(), server.requestOrganizationID(request), principal, from, to, &summary); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
server.enrichDashboardPOC(request.Context(), request, &summary)
|
||||
renderJSON(writer, http.StatusOK, summary)
|
||||
}
|
||||
@ -7190,7 +7220,11 @@ func (server *server) writeBOSArtifactContent(
|
||||
}
|
||||
|
||||
func (server *server) handleRunsArtifactContent(writer http.ResponseWriter, request *http.Request) {
|
||||
item, err := server.loadRun(request.Context(), chi.URLParam(request, "id"))
|
||||
server.serveRunArtifactContent(writer, request, chi.URLParam(request, "id"), chi.URLParam(request, "artifactId"))
|
||||
}
|
||||
|
||||
func (server *server) serveRunArtifactContent(writer http.ResponseWriter, request *http.Request, runID string, artifactID string) {
|
||||
item, err := server.loadRun(request.Context(), runID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
@ -7202,7 +7236,7 @@ func (server *server) handleRunsArtifactContent(writer http.ResponseWriter, requ
|
||||
if !server.ensureTenantAccess(writer, request, item.OrganizationID, "Run") {
|
||||
return
|
||||
}
|
||||
artifact := runArtifactByID(item, chi.URLParam(request, "artifactId"))
|
||||
artifact := runArtifactByID(item, artifactID)
|
||||
if artifact == nil {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "Artifact not found"})
|
||||
return
|
||||
@ -7462,7 +7496,7 @@ func (server *server) handleUsersCreate(writer http.ResponseWriter, request *htt
|
||||
return
|
||||
}
|
||||
if !validUserRole(payload.Role) {
|
||||
renderValidationError(writer, validationIssue{Field: "role", Message: "role must be admin, annotator, quality_reviewer, or acceptance_reviewer"})
|
||||
renderValidationError(writer, validationIssue{Field: "role", Message: "role must be admin, annotator, quality_reviewer, acceptance_reviewer, or supplier_manager"})
|
||||
return
|
||||
}
|
||||
if payload.Status != "" && !validUserStatus(payload.Status) {
|
||||
@ -7505,6 +7539,7 @@ func validUserRole(value domain.UserRole) bool {
|
||||
domain.UserRoleAnnotator,
|
||||
domain.UserRoleQualityReviewer,
|
||||
domain.UserRoleAcceptanceReviewer,
|
||||
domain.UserRoleSupplierManager,
|
||||
domain.UserRolePipelineEngineer,
|
||||
domain.UserRoleDataOperator,
|
||||
domain.UserRoleQAReviewer,
|
||||
@ -7562,7 +7597,7 @@ func (server *server) handleUsersUpdate(writer http.ResponseWriter, request *htt
|
||||
}
|
||||
if payload.Role != nil {
|
||||
if !validUserRole(*payload.Role) {
|
||||
renderValidationError(writer, validationIssue{Field: "role", Message: "role must be admin, annotator, quality_reviewer, or acceptance_reviewer"})
|
||||
renderValidationError(writer, validationIssue{Field: "role", Message: "role must be admin, annotator, quality_reviewer, acceptance_reviewer, or supplier_manager"})
|
||||
return
|
||||
}
|
||||
item.Role = *payload.Role
|
||||
|
||||
@ -388,6 +388,25 @@ func (server *server) requireBusinessRole(roles ...domain.UserRole) func(http.Ha
|
||||
}
|
||||
}
|
||||
|
||||
func (server *server) requireAdminMonitoringAccess(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||
if !server.requireSessionAuth || apiTokenAuthenticated(request) {
|
||||
next.ServeHTTP(writer, request)
|
||||
return
|
||||
}
|
||||
principal, ok := currentPrincipal(request)
|
||||
if !ok || principal == nil {
|
||||
renderJSON(writer, http.StatusUnauthorized, map[string]string{"error": "login is required"})
|
||||
return
|
||||
}
|
||||
if principal.User.Role != domain.UserRoleAdmin {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "run monitoring is restricted to administrators"})
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(writer, request)
|
||||
})
|
||||
}
|
||||
|
||||
func (server *server) requirePocAcceptanceImportAccess(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||
if !server.requireSessionAuth {
|
||||
|
||||
@ -175,6 +175,7 @@ func (server *server) handleTemplatePublish(writer http.ResponseWriter, request
|
||||
MaxConcurrentRuns: template.MaxConcurrentRuns, NodeTimeoutSeconds: template.NodeTimeoutSeconds,
|
||||
RunTimeoutSeconds: template.RunTimeoutSeconds, MaxRetryAttempts: template.MaxRetryAttempts,
|
||||
RetryBackoffSeconds: template.RetryBackoffSeconds, Schedule: template.Schedule, Nodes: template.Nodes, Edges: template.Edges,
|
||||
WorkflowInputs: template.WorkflowInputs, ArtifactStorage: template.ArtifactStorage,
|
||||
Capabilities: capabilities, RequiredPluginIDs: requiredPlugins, ContentDigest: digest,
|
||||
ReleaseNotes: strings.TrimSpace(payload.ReleaseNotes), PublishedByUserID: principal.User.ID, PublishedAt: now, CreatedAt: now,
|
||||
}
|
||||
@ -277,6 +278,7 @@ func (server *server) handleProjectWorkflowInstanceCreate(writer http.ResponseWr
|
||||
Hyperparams: release.Hyperparams, MaxConcurrentRuns: release.MaxConcurrentRuns, NodeTimeoutSeconds: release.NodeTimeoutSeconds,
|
||||
RunTimeoutSeconds: release.RunTimeoutSeconds, MaxRetryAttempts: release.MaxRetryAttempts,
|
||||
RetryBackoffSeconds: release.RetryBackoffSeconds, Schedule: release.Schedule, Nodes: release.Nodes, Edges: release.Edges,
|
||||
WorkflowInputs: release.WorkflowInputs, ArtifactStorage: release.ArtifactStorage,
|
||||
})
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
|
||||
@ -6,6 +6,7 @@ const (
|
||||
AnnotationRoleAnnotator AnnotationAssignmentRole = "annotator"
|
||||
AnnotationRoleQualityReviewer AnnotationAssignmentRole = "quality_reviewer"
|
||||
AnnotationRoleAcceptanceReviewer AnnotationAssignmentRole = "acceptance_reviewer"
|
||||
AnnotationRoleVendorManager AnnotationAssignmentRole = "vendor_manager"
|
||||
)
|
||||
|
||||
type AnnotationTaskStatus string
|
||||
|
||||
@ -24,23 +24,32 @@ type DeliveryPackageAcceptanceReview struct {
|
||||
}
|
||||
|
||||
type DeliveryPackageRecord struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
WorkflowID string `json:"workflowId" bson:"workflowId"`
|
||||
ParentRunID string `json:"parentRunId" bson:"parentRunId"`
|
||||
ChildRunID string `json:"childRunId" bson:"childRunId"`
|
||||
ReleasePartitionID string `json:"releasePartitionId" bson:"releasePartitionId"`
|
||||
ManifestDigest string `json:"manifestDigest" bson:"manifestDigest"`
|
||||
ItemIDs []string `json:"itemIds" bson:"itemIds"`
|
||||
ArtifactIDs []string `json:"artifactIds,omitempty" bson:"artifactIds,omitempty"`
|
||||
HandposeArtifactIDs []string `json:"handposeArtifactIds,omitempty" bson:"handposeArtifactIds,omitempty"`
|
||||
QualitySummary map[string]any `json:"qualitySummary,omitempty" bson:"qualitySummary,omitempty"`
|
||||
Status DeliveryPackageStatus `json:"status" bson:"status"`
|
||||
Version int `json:"version" bson:"version"`
|
||||
AcceptanceReviews []DeliveryPackageAcceptanceReview `json:"acceptanceReviews,omitempty" bson:"acceptanceReviews,omitempty"`
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt" bson:"updatedAt"`
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
WorkflowID string `json:"workflowId" bson:"workflowId"`
|
||||
WorkgroupID string `json:"workgroupId,omitempty" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty" bson:"vendorId,omitempty"`
|
||||
ParentRunID string `json:"parentRunId" bson:"parentRunId"`
|
||||
ChildRunID string `json:"childRunId" bson:"childRunId"`
|
||||
ReleasePartitionID string `json:"releasePartitionId" bson:"releasePartitionId"`
|
||||
ManifestDigest string `json:"manifestDigest" bson:"manifestDigest"`
|
||||
ItemIDs []string `json:"itemIds" bson:"itemIds"`
|
||||
ArtifactIDs []string `json:"artifactIds,omitempty" bson:"artifactIds,omitempty"`
|
||||
HeadposeArtifactIDs []string `json:"headposeArtifactIds,omitempty" bson:"headposeArtifactIds,omitempty"`
|
||||
HandposeArtifactIDs []string `json:"handposeArtifactIds,omitempty" bson:"handposeArtifactIds,omitempty"`
|
||||
QualitySummary map[string]any `json:"qualitySummary,omitempty" bson:"qualitySummary,omitempty"`
|
||||
Status DeliveryPackageStatus `json:"status" bson:"status"`
|
||||
AcceptanceHumanItemID string `json:"acceptanceHumanItemId,omitempty" bson:"acceptanceHumanItemId,omitempty"`
|
||||
AcceptanceHumanItemVersion int `json:"acceptanceHumanItemVersion,omitempty" bson:"-"`
|
||||
AssignedUserID string `json:"assignedUserId,omitempty" bson:"assignedUserId,omitempty"`
|
||||
ClaimedAt string `json:"claimedAt,omitempty" bson:"claimedAt,omitempty"`
|
||||
FinalExportArtifactIDs []string `json:"finalExportArtifactIds,omitempty" bson:"finalExportArtifactIds,omitempty"`
|
||||
FinalExportedAt string `json:"finalExportedAt,omitempty" bson:"finalExportedAt,omitempty"`
|
||||
Version int `json:"version" bson:"version"`
|
||||
AcceptanceReviews []DeliveryPackageAcceptanceReview `json:"acceptanceReviews,omitempty" bson:"acceptanceReviews,omitempty"`
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt" bson:"updatedAt"`
|
||||
}
|
||||
|
||||
type DeliveryPackageQuery struct {
|
||||
|
||||
@ -241,6 +241,5 @@ func DefaultAnnotationHumanStages() []HumanStageDefinition {
|
||||
{ID: "split_annotation", Label: "切分标注", Kind: HumanStageAnnotation, RequiredRole: "annotator", EditorSchema: "temporal-segments/v1"},
|
||||
{ID: "semantic_annotation", Label: "语义标注", Kind: HumanStageAnnotation, RequiredRole: "annotator", EditorSchema: "temporal-segments/v1"},
|
||||
{ID: "quality_review", Label: "人工质检", Kind: HumanStageReview, RequiredRole: "quality_reviewer", RejectTargets: []string{"split_annotation", "semantic_annotation"}},
|
||||
{ID: "acceptance", Label: "最终验收", Kind: HumanStageAcceptance, RequiredRole: "acceptance_reviewer", RejectTargets: []string{"split_annotation", "semantic_annotation", "quality_review"}},
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ const (
|
||||
UserRoleAnnotator UserRole = "annotator"
|
||||
UserRoleQualityReviewer UserRole = "quality_reviewer"
|
||||
UserRoleAcceptanceReviewer UserRole = "acceptance_reviewer"
|
||||
UserRoleSupplierManager UserRole = "supplier_manager"
|
||||
)
|
||||
|
||||
type UserStatus string
|
||||
@ -1038,7 +1039,9 @@ type SettingsView struct {
|
||||
}
|
||||
|
||||
type DashboardSummary struct {
|
||||
Projects struct {
|
||||
AudienceScope string `json:"audienceScope"`
|
||||
Workforce DashboardWorkforceSummary `json:"workforce"`
|
||||
Projects struct {
|
||||
Active int `json:"active"`
|
||||
Archived int `json:"archived"`
|
||||
} `json:"projects"`
|
||||
@ -1080,6 +1083,31 @@ type DashboardSummary struct {
|
||||
POC DashboardPOCReadiness `json:"poc"`
|
||||
}
|
||||
|
||||
type DashboardWorkforceMetric struct {
|
||||
UserID string `json:"userId,omitempty"`
|
||||
UserName string `json:"userName,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty"`
|
||||
WorkgroupID string `json:"workgroupId,omitempty"`
|
||||
OutputCount int64 `json:"outputCount"`
|
||||
SubmittedCount int64 `json:"submittedCount"`
|
||||
ReworkCount int64 `json:"reworkCount"`
|
||||
DurationSeconds int64 `json:"durationSeconds"`
|
||||
QualityApproved int64 `json:"qualityApproved"`
|
||||
QualityRejected int64 `json:"qualityRejected"`
|
||||
AcceptanceApproved int64 `json:"acceptanceApproved"`
|
||||
AcceptanceRejected int64 `json:"acceptanceRejected"`
|
||||
QualityPassRate *float64 `json:"qualityPassRate"`
|
||||
AcceptancePassRate *float64 `json:"acceptancePassRate"`
|
||||
ReworkRate *float64 `json:"reworkRate"`
|
||||
}
|
||||
|
||||
type DashboardWorkforceSummary struct {
|
||||
From string `json:"from,omitempty"`
|
||||
To string `json:"to,omitempty"`
|
||||
Totals DashboardWorkforceMetric `json:"totals"`
|
||||
Items []DashboardWorkforceMetric `json:"items"`
|
||||
}
|
||||
|
||||
type DashboardTrendPoint struct {
|
||||
Date string `json:"date"`
|
||||
RunCount int `json:"runCount"`
|
||||
|
||||
@ -1,32 +1,34 @@
|
||||
package domain
|
||||
|
||||
type WorkflowReleaseRecord struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
||||
TemplateID string `json:"templateId" bson:"templateId"`
|
||||
Version int `json:"version" bson:"version"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Type WorkflowType `json:"type" bson:"type"`
|
||||
Kind WorkflowKind `json:"kind" bson:"kind"`
|
||||
ExecutionScope WorkflowExecutionScope `json:"executionScope" bson:"executionScope"`
|
||||
ScanConfig *ScanConfig `json:"scanConfig,omitempty" bson:"scanConfig,omitempty"`
|
||||
Hyperparams []HyperParam `json:"hyperparams,omitempty" bson:"hyperparams,omitempty"`
|
||||
MaxConcurrentRuns int `json:"maxConcurrentRuns,omitempty" bson:"maxConcurrentRuns,omitempty"`
|
||||
NodeTimeoutSeconds int `json:"nodeTimeoutSeconds,omitempty" bson:"nodeTimeoutSeconds,omitempty"`
|
||||
RunTimeoutSeconds int `json:"runTimeoutSeconds,omitempty" bson:"runTimeoutSeconds,omitempty"`
|
||||
MaxRetryAttempts int `json:"maxRetryAttempts,omitempty" bson:"maxRetryAttempts,omitempty"`
|
||||
RetryBackoffSeconds int `json:"retryBackoffSeconds,omitempty" bson:"retryBackoffSeconds,omitempty"`
|
||||
Schedule *WorkflowSchedule `json:"schedule,omitempty" bson:"schedule,omitempty"`
|
||||
Nodes []WorkflowNode `json:"nodes" bson:"nodes"`
|
||||
Edges []WorkflowEdge `json:"edges" bson:"edges"`
|
||||
Capabilities []string `json:"capabilities,omitempty" bson:"capabilities,omitempty"`
|
||||
RequiredPluginIDs []string `json:"requiredPluginIds,omitempty" bson:"requiredPluginIds,omitempty"`
|
||||
ContentDigest string `json:"contentDigest" bson:"contentDigest"`
|
||||
ReleaseNotes string `json:"releaseNotes,omitempty" bson:"releaseNotes,omitempty"`
|
||||
PublishedByUserID string `json:"publishedByUserId" bson:"publishedByUserId"`
|
||||
PublishedAt string `json:"publishedAt" bson:"publishedAt"`
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"`
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
||||
TemplateID string `json:"templateId" bson:"templateId"`
|
||||
Version int `json:"version" bson:"version"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
Description string `json:"description" bson:"description"`
|
||||
Type WorkflowType `json:"type" bson:"type"`
|
||||
Kind WorkflowKind `json:"kind" bson:"kind"`
|
||||
ExecutionScope WorkflowExecutionScope `json:"executionScope" bson:"executionScope"`
|
||||
ScanConfig *ScanConfig `json:"scanConfig,omitempty" bson:"scanConfig,omitempty"`
|
||||
Hyperparams []HyperParam `json:"hyperparams,omitempty" bson:"hyperparams,omitempty"`
|
||||
MaxConcurrentRuns int `json:"maxConcurrentRuns,omitempty" bson:"maxConcurrentRuns,omitempty"`
|
||||
NodeTimeoutSeconds int `json:"nodeTimeoutSeconds,omitempty" bson:"nodeTimeoutSeconds,omitempty"`
|
||||
RunTimeoutSeconds int `json:"runTimeoutSeconds,omitempty" bson:"runTimeoutSeconds,omitempty"`
|
||||
MaxRetryAttempts int `json:"maxRetryAttempts,omitempty" bson:"maxRetryAttempts,omitempty"`
|
||||
RetryBackoffSeconds int `json:"retryBackoffSeconds,omitempty" bson:"retryBackoffSeconds,omitempty"`
|
||||
Schedule *WorkflowSchedule `json:"schedule,omitempty" bson:"schedule,omitempty"`
|
||||
WorkflowInputs []WorkflowInputDefinition `json:"workflowInputs,omitempty" bson:"workflowInputs,omitempty"`
|
||||
ArtifactStorage *ArtifactStoragePolicy `json:"artifactStorage,omitempty" bson:"artifactStorage,omitempty"`
|
||||
Nodes []WorkflowNode `json:"nodes" bson:"nodes"`
|
||||
Edges []WorkflowEdge `json:"edges" bson:"edges"`
|
||||
Capabilities []string `json:"capabilities,omitempty" bson:"capabilities,omitempty"`
|
||||
RequiredPluginIDs []string `json:"requiredPluginIds,omitempty" bson:"requiredPluginIds,omitempty"`
|
||||
ContentDigest string `json:"contentDigest" bson:"contentDigest"`
|
||||
ReleaseNotes string `json:"releaseNotes,omitempty" bson:"releaseNotes,omitempty"`
|
||||
PublishedByUserID string `json:"publishedByUserId" bson:"publishedByUserId"`
|
||||
PublishedAt string `json:"publishedAt" bson:"publishedAt"`
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"`
|
||||
}
|
||||
|
||||
type ProjectWorkflowInstanceStatus string
|
||||
|
||||
@ -167,7 +167,7 @@ func (store *MongoStore) EnsureIndexes(ctx context.Context) error {
|
||||
store.annotationWorklogEvents: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
index("organizationId_projectId_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
index("organizationId_vendorId_userId_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "vendorId", Value: 1}, {Key: "userId", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
index("organizationId_vendorId_workgroupId_userId_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "vendorId", Value: 1}, {Key: "workgroupId", Value: 1}, {Key: "userId", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
},
|
||||
store.organizationPlugins: {
|
||||
uniqueIndex("organizationId_pluginId_unique", bson.D{{Key: "organizationId", Value: 1}, {Key: "pluginId", Value: 1}}),
|
||||
@ -182,6 +182,7 @@ func (store *MongoStore) EnsureIndexes(ctx context.Context) error {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
uniqueIndex("organizationId_batchId_subjectItemKey_unique", bson.D{{Key: "organizationId", Value: 1}, {Key: "batchId", Value: 1}, {Key: "subject.itemKey", Value: 1}}),
|
||||
index("organizationId_workflowId_stage_status", bson.D{{Key: "organizationId", Value: 1}, {Key: "workflowId", Value: 1}, {Key: "currentStageId", Value: 1}, {Key: "status", Value: 1}}),
|
||||
index("organizationId_vendorId_workgroupId_stage_status_assignee", bson.D{{Key: "organizationId", Value: 1}, {Key: "vendorId", Value: 1}, {Key: "workgroupId", Value: 1}, {Key: "currentStageId", Value: 1}, {Key: "status", Value: 1}, {Key: "assignedUserId", Value: 1}}),
|
||||
},
|
||||
store.humanStageAttempts: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
@ -205,6 +206,7 @@ func (store *MongoStore) EnsureIndexes(ctx context.Context) error {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
uniqueIndex("organizationId_releasePartitionId_unique", bson.D{{Key: "organizationId", Value: 1}, {Key: "releasePartitionId", Value: 1}}),
|
||||
index("organizationId_projectId_status_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "status", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
index("organizationId_vendorId_workgroupId_status_assignee", bson.D{{Key: "organizationId", Value: 1}, {Key: "vendorId", Value: 1}, {Key: "workgroupId", Value: 1}, {Key: "status", Value: 1}, {Key: "assignedUserId", Value: 1}}),
|
||||
},
|
||||
store.users: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
|
||||
@ -19,7 +19,6 @@ import (
|
||||
type annotationGateConfig struct {
|
||||
TemplateID string
|
||||
WorkgroupID string
|
||||
AssignedUserID string
|
||||
ReleasePolicy domain.HumanReleasePolicy
|
||||
PartitionMaxItems int
|
||||
PartitionMaxWaitSeconds int
|
||||
@ -78,7 +77,6 @@ func annotationGateConfigFromNode(node domain.WorkflowNode) annotationGateConfig
|
||||
return annotationGateConfig{
|
||||
TemplateID: strings.TrimSpace(params["ANNOTATION_TEMPLATE_ID"]),
|
||||
WorkgroupID: strings.TrimSpace(params["ANNOTATION_WORKGROUP_ID"]),
|
||||
AssignedUserID: strings.TrimSpace(params["ANNOTATION_ASSIGNED_USER_ID"]),
|
||||
ReleasePolicy: releasePolicy,
|
||||
PartitionMaxItems: positiveAnnotationGateInt(params["PARTITION_MAX_ITEMS"], 32),
|
||||
PartitionMaxWaitSeconds: positiveAnnotationGateInt(params["PARTITION_MAX_WAIT_SECONDS"], 60),
|
||||
@ -354,7 +352,7 @@ func (runtime *Runtime) createAnnotationGateTasks(
|
||||
TemplateVersion: template.Version,
|
||||
WorkgroupID: group.ID,
|
||||
VendorID: group.VendorID,
|
||||
AssignedUserID: config.AssignedUserID,
|
||||
AssignedUserID: "",
|
||||
Status: domain.AnnotationTaskStatusPendingAnnotation,
|
||||
CurrentRevision: 0,
|
||||
CreatedAt: nowISO(),
|
||||
@ -374,8 +372,8 @@ func (runtime *Runtime) createAnnotationGateTasks(
|
||||
}
|
||||
_ = runtime.store.UpsertAnnotationWorklogEvent(ctx, domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: run.OrganizationID, ProjectID: run.ProjectID,
|
||||
TaskID: task.ID, UserID: config.AssignedUserID, WorkgroupID: group.ID, VendorID: group.VendorID,
|
||||
EventType: "workflow_assigned", TemplateVersion: template.Version, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
TaskID: task.ID, UserID: "system", WorkgroupID: group.ID, VendorID: group.VendorID,
|
||||
EventType: "created", TemplateVersion: template.Version, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
})
|
||||
tasks = append(tasks, task)
|
||||
}
|
||||
@ -493,7 +491,7 @@ func (runtime *Runtime) ensureAnnotationHumanBatch(
|
||||
},
|
||||
CurrentStageID: "split_annotation",
|
||||
Status: domain.HumanItemReady,
|
||||
AssignedUserID: task.AssignedUserID,
|
||||
AssignedUserID: "",
|
||||
WorkgroupID: task.WorkgroupID,
|
||||
VendorID: task.VendorID,
|
||||
MaxReworkRounds: batch.MaxReworkRounds,
|
||||
|
||||
@ -202,9 +202,15 @@ func (runtime *Runtime) syncDeliveryPackage(ctx context.Context, batch domain.Hu
|
||||
if len(packages) > 0 {
|
||||
item = packages[0]
|
||||
} else {
|
||||
workgroupID, vendorID := "", ""
|
||||
if len(partition.ItemIDs) > 0 {
|
||||
if humanItem, itemErr := runtime.store.GetHumanItem(ctx, partition.ItemIDs[0]); itemErr == nil && humanItem != nil {
|
||||
workgroupID, vendorID = humanItem.WorkgroupID, humanItem.VendorID
|
||||
}
|
||||
}
|
||||
item = domain.DeliveryPackageRecord{
|
||||
ID: "delivery-package-" + partition.ID, OrganizationID: batch.OrganizationID, ProjectID: batch.ProjectID,
|
||||
WorkflowID: batch.WorkflowID, ParentRunID: batch.RunID, ChildRunID: partition.ChildRunID,
|
||||
WorkflowID: batch.WorkflowID, WorkgroupID: workgroupID, VendorID: vendorID, ParentRunID: batch.RunID, ChildRunID: partition.ChildRunID,
|
||||
ReleasePartitionID: partition.ID, ManifestDigest: partition.ManifestDigest, ItemIDs: partition.ItemIDs,
|
||||
Status: domain.DeliveryPackageBuilding, Version: 1, CreatedAt: nowISO(), UpdatedAt: nowISO(),
|
||||
}
|
||||
@ -216,15 +222,19 @@ func (runtime *Runtime) syncDeliveryPackage(ctx context.Context, batch domain.Hu
|
||||
}
|
||||
if child != nil {
|
||||
artifactIDs := make([]string, 0, len(child.Artifacts))
|
||||
headposeIDs := make([]string, 0)
|
||||
handposeIDs := make([]string, 0)
|
||||
for _, artifact := range child.Artifacts {
|
||||
artifactIDs = append(artifactIDs, artifact.ID)
|
||||
identity := strings.ToLower(artifact.Name + " " + artifact.Path + " " + artifact.NodeID)
|
||||
if strings.Contains(identity, "handpose") || strings.Contains(identity, "wilor") {
|
||||
if strings.Contains(identity, "headpose") || strings.Contains(identity, "head-pose") {
|
||||
headposeIDs = append(headposeIDs, artifact.ID)
|
||||
} else if strings.Contains(identity, "handpose") || strings.Contains(identity, "wilor") {
|
||||
handposeIDs = append(handposeIDs, artifact.ID)
|
||||
}
|
||||
}
|
||||
item.ArtifactIDs = artifactIDs
|
||||
item.HeadposeArtifactIDs = headposeIDs
|
||||
item.HandposeArtifactIDs = handposeIDs
|
||||
switch child.Status {
|
||||
case domain.RunStatusCompleted:
|
||||
@ -236,7 +246,86 @@ func (runtime *Runtime) syncDeliveryPackage(ctx context.Context, batch domain.Hu
|
||||
}
|
||||
}
|
||||
item.UpdatedAt = nowISO()
|
||||
return runtime.store.UpsertDeliveryPackage(ctx, item)
|
||||
if err := runtime.store.UpsertDeliveryPackage(ctx, item); err != nil {
|
||||
return err
|
||||
}
|
||||
if item.Status == domain.DeliveryPackagePendingAcceptance || item.Status == domain.DeliveryPackageAccepted || item.Status == domain.DeliveryPackageRejected {
|
||||
return runtime.ensureDeliveryPackageAcceptanceItem(ctx, batch, &item)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deliveryPackageAcceptanceBatchID(batchID string) string {
|
||||
return "human-batch-delivery-acceptance-" + strings.TrimSpace(batchID)
|
||||
}
|
||||
|
||||
func deliveryPackageAcceptanceItemID(packageID string) string {
|
||||
return "human-delivery-acceptance-" + strings.TrimSpace(packageID)
|
||||
}
|
||||
|
||||
func (runtime *Runtime) ensureDeliveryPackageAcceptanceItem(ctx context.Context, sourceBatch domain.HumanBatchRecord, item *domain.DeliveryPackageRecord) error {
|
||||
if item == nil {
|
||||
return nil
|
||||
}
|
||||
batchID := deliveryPackageAcceptanceBatchID(sourceBatch.ID)
|
||||
acceptanceBatch, err := runtime.store.GetHumanBatch(ctx, batchID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if acceptanceBatch == nil {
|
||||
now := nowISO()
|
||||
acceptanceBatch = &domain.HumanBatchRecord{
|
||||
ID: batchID, OrganizationID: item.OrganizationID, PluginID: "annotation-qa", ProjectID: item.ProjectID,
|
||||
WorkflowID: item.WorkflowID, RunID: item.ChildRunID, GateNodeID: "delivery-package-acceptance",
|
||||
Status: domain.HumanBatchActive, Stages: []domain.HumanStageDefinition{{
|
||||
ID: "acceptance", Label: "成品最终验收", Kind: domain.HumanStageAcceptance, RequiredRole: "acceptance_reviewer",
|
||||
}}, MaxReworkRounds: sourceBatch.MaxReworkRounds,
|
||||
ItemCount: 1, CreatedAt: now, UpdatedAt: now,
|
||||
}
|
||||
if err := runtime.store.UpsertHumanBatch(ctx, *acceptanceBatch); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
humanItemID := deliveryPackageAcceptanceItemID(item.ID)
|
||||
humanItem, err := runtime.store.GetHumanItem(ctx, humanItemID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if humanItem == nil {
|
||||
status := domain.HumanItemReady
|
||||
if item.Status == domain.DeliveryPackageAccepted {
|
||||
status = domain.HumanItemAccepted
|
||||
} else if item.Status == domain.DeliveryPackageRejected {
|
||||
status = domain.HumanItemRejected
|
||||
}
|
||||
artifactID := ""
|
||||
if len(item.ArtifactIDs) > 0 {
|
||||
artifactID = item.ArtifactIDs[0]
|
||||
}
|
||||
now := nowISO()
|
||||
humanItem = &domain.HumanItemRecord{
|
||||
ID: humanItemID, OrganizationID: item.OrganizationID, PluginID: "annotation-qa", BatchID: batchID,
|
||||
ProjectID: item.ProjectID, WorkflowID: item.WorkflowID, RunID: item.ChildRunID, GateNodeID: "delivery-package-acceptance",
|
||||
Subject: domain.HumanSubjectRef{ArtifactID: artifactID, ItemKey: item.ID, MediaType: "application/json", Payload: map[string]any{
|
||||
"deliveryPackageId": item.ID, "artifactIds": item.ArtifactIDs, "manifestDigest": item.ManifestDigest,
|
||||
}}, CurrentStageID: "acceptance", Status: status, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
Version: 1, MaxReworkRounds: sourceBatch.MaxReworkRounds, CreatedAt: now, UpdatedAt: now,
|
||||
}
|
||||
if err := runtime.store.UpsertHumanItem(ctx, *humanItem); err != nil {
|
||||
return err
|
||||
}
|
||||
_ = runtime.store.AppendHumanEvent(ctx, domain.HumanEventRecord{
|
||||
ID: "human-event-created-" + humanItemID, OrganizationID: item.OrganizationID, BatchID: batchID,
|
||||
ItemID: humanItemID, StageID: "acceptance", EventType: "created", ActorUserID: "system",
|
||||
ItemVersion: humanItem.Version, Payload: map[string]any{"deliveryPackageId": item.ID}, CreatedAt: now,
|
||||
})
|
||||
}
|
||||
if item.AcceptanceHumanItemID != humanItemID {
|
||||
item.AcceptanceHumanItemID = humanItemID
|
||||
item.UpdatedAt = nowISO()
|
||||
return runtime.store.UpsertDeliveryPackage(ctx, *item)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func humanReleaseBatchTerminal(items []domain.HumanItemRecord) bool {
|
||||
@ -252,6 +341,9 @@ func humanReleaseBatchTerminal(items []domain.HumanItemRecord) bool {
|
||||
}
|
||||
|
||||
func (runtime *Runtime) ensureDueHumanReleasePartitions(ctx context.Context, batch *domain.HumanBatchRecord) error {
|
||||
if batch == nil || batch.ReleasePolicy == "" {
|
||||
return nil
|
||||
}
|
||||
items, err := runtime.store.ListHumanItems(ctx, batch.OrganizationID, domain.HumanItemQuery{BatchID: batch.ID})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
"droboticflow/internal/store"
|
||||
)
|
||||
|
||||
func TestHumanReleaseTargetUsesApprovedGateEdge(t *testing.T) {
|
||||
@ -58,3 +60,52 @@ func TestHumanReleaseChildRunIDIsStableAndPartitionScoped(t *testing.T) {
|
||||
t.Fatalf("child ids left=%q repeated=%q right=%q", left, repeated, right)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompletedDeliveryPackageCreatesUnassignedAcceptanceHumanItem(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
runtime := &Runtime{store: dataStore}
|
||||
batch := domain.HumanBatchRecord{
|
||||
ID: "batch-a", OrganizationID: "org-a", PluginID: "annotation-qa", ProjectID: "project-a",
|
||||
WorkflowID: "workflow-a", RunID: "run-parent", GateNodeID: "gate", Status: domain.HumanBatchActive,
|
||||
Stages: domain.DefaultAnnotationHumanStages(), ReleasePolicy: domain.HumanReleaseAcceptedPartition,
|
||||
}
|
||||
partition := domain.ReleasePartitionRecord{
|
||||
ID: "partition-a", OrganizationID: "org-a", BatchID: batch.ID, ChildRunID: "run-child",
|
||||
ManifestDigest: "digest-a", ItemIDs: []string{"human-a"}, Status: domain.ReleasePartitionDispatched,
|
||||
}
|
||||
if err := dataStore.UpsertHumanItem(ctx, domain.HumanItemRecord{
|
||||
ID: "human-a", OrganizationID: "org-a", BatchID: batch.ID, ProjectID: batch.ProjectID,
|
||||
WorkgroupID: "group-a", VendorID: "vendor-a", Subject: domain.HumanSubjectRef{ItemKey: "clip-a"},
|
||||
CurrentStageID: "quality_review", Status: domain.HumanItemAccepted, Version: 1,
|
||||
}); err != nil {
|
||||
t.Fatalf("create source item: %v", err)
|
||||
}
|
||||
if err := dataStore.UpsertRun(ctx, domain.RunRecord{
|
||||
ID: partition.ChildRunID, OrganizationID: "org-a", ProjectID: batch.ProjectID, WorkflowID: batch.WorkflowID,
|
||||
Status: domain.RunStatusCompleted, Artifacts: []domain.ExecutionArtifact{
|
||||
{ID: "artifact-headpose", Name: "headpose-manifest.json", NodeID: "headpose"},
|
||||
{ID: "artifact-handpose", Name: "handpose-manifest.json", NodeID: "wilor"},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("create child run: %v", err)
|
||||
}
|
||||
if err := runtime.syncDeliveryPackage(ctx, batch, partition); err != nil {
|
||||
t.Fatalf("sync package: %v", err)
|
||||
}
|
||||
packages, err := dataStore.ListDeliveryPackages(ctx, "org-a", domain.DeliveryPackageQuery{ReleasePartitionID: partition.ID})
|
||||
if err != nil || len(packages) != 1 {
|
||||
t.Fatalf("packages=%#v err=%v", packages, err)
|
||||
}
|
||||
item := packages[0]
|
||||
if item.Status != domain.DeliveryPackagePendingAcceptance || item.AcceptanceHumanItemID == "" || len(item.HeadposeArtifactIDs) != 1 || len(item.HandposeArtifactIDs) != 1 {
|
||||
t.Fatalf("package=%#v", item)
|
||||
}
|
||||
acceptance, err := dataStore.GetHumanItem(ctx, item.AcceptanceHumanItemID)
|
||||
if err != nil || acceptance == nil {
|
||||
t.Fatalf("acceptance item=%#v err=%v", acceptance, err)
|
||||
}
|
||||
if acceptance.CurrentStageID != "acceptance" || acceptance.Status != domain.HumanItemReady || acceptance.AssignedUserID != "" || acceptance.WorkgroupID != "group-a" || acceptance.VendorID != "vendor-a" {
|
||||
t.Fatalf("acceptance item must enter the scoped available pool: %#v", acceptance)
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,6 +164,10 @@ data:
|
||||
DROBOTICFLOW_TRUSTED_PROXY_CIDRS: "__DROBOTICFLOW_TRUSTED_PROXY_CIDRS__"
|
||||
AI_API_BASE_URL: "__AI_API_BASE_URL__"
|
||||
AI_MODEL: "__AI_MODEL__"
|
||||
FANYU_HEADPOSE_API_BASE_URL: "http://droboticflow-headpose:8080"
|
||||
FANYU_HEADPOSE_SERVICE_IMAGE_ID: "__HEADPOSE_SERVICE_IMAGE_ID__"
|
||||
FANYU_HEADPOSE_MODEL_SHA256: "__HEADPOSE_MODEL_SHA256__"
|
||||
FANYU_HEADPOSE_LICENSE_ID: "MIT"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
@ -339,6 +343,26 @@ spec:
|
||||
configMapKeyRef:
|
||||
name: droboticflow-config
|
||||
key: AI_MODEL
|
||||
- name: FANYU_HEADPOSE_API_BASE_URL
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: droboticflow-config
|
||||
key: FANYU_HEADPOSE_API_BASE_URL
|
||||
- name: FANYU_HEADPOSE_SERVICE_IMAGE_ID
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: droboticflow-config
|
||||
key: FANYU_HEADPOSE_SERVICE_IMAGE_ID
|
||||
- name: FANYU_HEADPOSE_MODEL_SHA256
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: droboticflow-config
|
||||
key: FANYU_HEADPOSE_MODEL_SHA256
|
||||
- name: FANYU_HEADPOSE_LICENSE_ID
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: droboticflow-config
|
||||
key: FANYU_HEADPOSE_LICENSE_ID
|
||||
- name: AI_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
@ -646,6 +670,89 @@ spec:
|
||||
persistentVolumeClaim:
|
||||
claimName: __WORKSPACE_PVC_NAME__
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: droboticflow-headpose
|
||||
namespace: __NAMESPACE__
|
||||
spec:
|
||||
selector:
|
||||
app: droboticflow-headpose
|
||||
ports:
|
||||
- name: http
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: droboticflow-headpose
|
||||
namespace: __NAMESPACE__
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
app: droboticflow-headpose
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: droboticflow-headpose
|
||||
spec:
|
||||
terminationGracePeriodSeconds: 30
|
||||
imagePullSecrets:
|
||||
- name: __K8S_IMAGE_PULL_SECRET_NAME__
|
||||
containers:
|
||||
- name: headpose
|
||||
image: __HEADPOSE_SERVICE_IMAGE__
|
||||
imagePullPolicy: Always
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: [ALL]
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 8080
|
||||
env:
|
||||
- name: HEADPOSE_MODEL_SHA256
|
||||
value: "__HEADPOSE_MODEL_SHA256__"
|
||||
- name: HEADPOSE_LICENSE_ID
|
||||
value: "MIT"
|
||||
- name: HEADPOSE_OUTPUT_ROOT
|
||||
value: "__WORKSPACE_MOUNT_PATH__/system/headpose-service"
|
||||
- name: HEADPOSE_GPU_ID
|
||||
value: "0"
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: http
|
||||
initialDelaySeconds: 20
|
||||
periodSeconds: 10
|
||||
failureThreshold: 12
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: http
|
||||
initialDelaySeconds: 60
|
||||
periodSeconds: 20
|
||||
resources:
|
||||
requests:
|
||||
cpu: "1"
|
||||
memory: 2Gi
|
||||
nvidia.com/gpu: "1"
|
||||
limits:
|
||||
cpu: "4"
|
||||
memory: 8Gi
|
||||
nvidia.com/gpu: "1"
|
||||
volumeMounts:
|
||||
- name: workspace
|
||||
mountPath: __WORKSPACE_MOUNT_PATH__
|
||||
volumes:
|
||||
- name: workspace
|
||||
persistentVolumeClaim:
|
||||
claimName: __WORKSPACE_PVC_NAME__
|
||||
---
|
||||
apiVersion: policy/v1
|
||||
kind: PodDisruptionBudget
|
||||
metadata:
|
||||
|
||||
12
operator-repos/builtin/delivery_options/Dockerfile
Normal file
12
operator-repos/builtin/delivery_options/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
# Generated by scripts/generate_operator_images.py. Do not edit by hand.
|
||||
ARG OPERATOR_BASE_IMAGE=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow-poc/droboticflow-operator-runner:builtin
|
||||
FROM ${OPERATOR_BASE_IMAGE}
|
||||
|
||||
ENV DROBOTICFLOW_OPERATOR_ID=operator-builtin-delivery-options \
|
||||
DROBOTICFLOW_OPERATOR_SLUG=delivery_options \
|
||||
DROBOTICFLOW_OPERATOR_SOURCE=/app/operator-repos/builtin/delivery_options/src/operator.py \
|
||||
DROBOTICFLOW_OPERATOR_REPOSITORY=/app/operator-repos/builtin/delivery_options \
|
||||
DROBOTICFLOW_OPERATOR_HANDLER=builtin_delivery_options
|
||||
|
||||
COPY operator-repos/builtin/delivery_options ./operator-repos/builtin/delivery_options
|
||||
ENTRYPOINT ["python", "/app/backend/operator-runner/main.py"]
|
||||
10
operator-repos/builtin/delivery_options/README.md
Normal file
10
operator-repos/builtin/delivery_options/README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# 交付选项透传
|
||||
|
||||
独立 builtin 算子目录。该目录是 `operator-builtin-delivery-options` 的生产运行权威来源,包含镜像构建、运行契约、源码和验收输入定义。
|
||||
|
||||
- 发布镜像:以 `release.json` 中的 digest-pinned CCR imageId 为准
|
||||
- Repository manifest:`repository.json`
|
||||
- Runtime handler:`builtin_delivery_options`
|
||||
- Source:`src/operator.py`
|
||||
|
||||
生产验收要求真实 fixture、artifact checksum、lineage 证据;不接受 mock、仿真、smoke 或空文件验收。
|
||||
16
operator-repos/builtin/delivery_options/operator.json
Normal file
16
operator-repos/builtin/delivery_options/operator.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"acceptance": {
|
||||
"hardcodedOutputAccepted": false,
|
||||
"mockOnlyAccepted": false,
|
||||
"requiresRealInputs": true,
|
||||
"shallowOnlyAccepted": false,
|
||||
"simulationOnlyAccepted": false
|
||||
},
|
||||
"category": "UTIL",
|
||||
"id": "operator-builtin-delivery-options",
|
||||
"migrationStatus": "migrated",
|
||||
"name": "交付选项透传",
|
||||
"runtimeHandler": "builtin_delivery_options",
|
||||
"runtimeSource": "operator-repos/builtin/delivery_options/src/operator.py",
|
||||
"type": "builtin"
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
{
|
||||
"acceptance": {
|
||||
"requiresArtifactChecksum": true,
|
||||
"requiresFixtureChecksum": true,
|
||||
"requiresGpuEvidence": false,
|
||||
"requiresRealFixture": true,
|
||||
"requiresWorkflowTransfer": true
|
||||
},
|
||||
"artifacts": {
|
||||
"requiresChecksum": true,
|
||||
"requiresLineage": true,
|
||||
"requiresManifest": true
|
||||
},
|
||||
"entrypoint": "/app/backend/operator-runner/main.py",
|
||||
"handler": "builtin_delivery_options",
|
||||
"imagePolicy": {
|
||||
"allowsSharedBaseLayer": true,
|
||||
"forbidsSharedOperatorRunnerFinalImage": true,
|
||||
"independentFinalImage": true
|
||||
},
|
||||
"operatorId": "operator-builtin-delivery-options",
|
||||
"operatorSlug": "delivery_options",
|
||||
"parameters": {
|
||||
"commandWrapperAllowed": false,
|
||||
"controlledScriptAllowed": false,
|
||||
"source": "input",
|
||||
"structured": true
|
||||
},
|
||||
"resources": {
|
||||
"minGpuCount": 0,
|
||||
"recommendedGpuType": "",
|
||||
"requiresGpu": false
|
||||
},
|
||||
"runtimeDependencies": [
|
||||
"json-artifacts"
|
||||
],
|
||||
"runtimeSource": "src/operator.py",
|
||||
"schemaVersion": "droboticflow.operator.runtime/v1",
|
||||
"sourceRoot": "operator-repos/builtin/delivery_options"
|
||||
}
|
||||
34
operator-repos/builtin/delivery_options/src/operator.py
Normal file
34
operator-repos/builtin/delivery_options/src/operator.py
Normal file
@ -0,0 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable
|
||||
|
||||
|
||||
HelperMap = dict[str, Callable[..., Any]]
|
||||
|
||||
|
||||
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]]:
|
||||
payloads = helpers["payloads_from_inputs"](inputs)
|
||||
options = payloads[0] if payloads else {}
|
||||
include_handpose = bool(options.get("includeHandpose", False))
|
||||
normalized = {
|
||||
"schemaVersion": "droboticflow.delivery-options/v1",
|
||||
"includeHeadpose": True,
|
||||
"includeHandpose": include_handpose,
|
||||
}
|
||||
return [
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
output_dir,
|
||||
"delivery-options.json",
|
||||
normalized,
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
]
|
||||
@ -0,0 +1,21 @@
|
||||
{
|
||||
"fixtures": [],
|
||||
"minimumEvidence": [
|
||||
"input checksum",
|
||||
"artifact checksum",
|
||||
"lineage",
|
||||
"schema validation"
|
||||
],
|
||||
"operatorId": "operator-builtin-delivery-options",
|
||||
"operatorSlug": "delivery_options",
|
||||
"rules": {
|
||||
"forbidsMock": true,
|
||||
"forbidsSimulationOnly": true,
|
||||
"forbidsSmokeOnly": true,
|
||||
"forbidsSynthetic": true,
|
||||
"requiresLicense": true,
|
||||
"requiresPublicSourceUrl": true,
|
||||
"requiresSha256": true
|
||||
},
|
||||
"schemaVersion": "droboticflow.operator.fixture/v1"
|
||||
}
|
||||
12
operator-repos/builtin/head_pose/Dockerfile
Normal file
12
operator-repos/builtin/head_pose/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
# Generated by scripts/generate_operator_images.py. Do not edit by hand.
|
||||
ARG OPERATOR_BASE_IMAGE=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow-poc/droboticflow-operator-runner:builtin
|
||||
FROM ${OPERATOR_BASE_IMAGE}
|
||||
|
||||
ENV DROBOTICFLOW_OPERATOR_ID=operator-builtin-head-pose \
|
||||
DROBOTICFLOW_OPERATOR_SLUG=head_pose \
|
||||
DROBOTICFLOW_OPERATOR_SOURCE=/app/operator-repos/builtin/head_pose/src/operator.py \
|
||||
DROBOTICFLOW_OPERATOR_REPOSITORY=/app/operator-repos/builtin/head_pose \
|
||||
DROBOTICFLOW_OPERATOR_HANDLER=builtin_head_pose
|
||||
|
||||
COPY operator-repos/builtin/head_pose ./operator-repos/builtin/head_pose
|
||||
ENTRYPOINT ["python", "/app/backend/operator-runner/main.py"]
|
||||
10
operator-repos/builtin/head_pose/README.md
Normal file
10
operator-repos/builtin/head_pose/README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# 6DRepNet Headpose
|
||||
|
||||
独立 builtin 算子目录。该目录是 `operator-builtin-head-pose` 的生产运行权威来源,包含镜像构建、运行契约、源码和验收输入定义。
|
||||
|
||||
- 发布镜像:以 `release.json` 中的 digest-pinned CCR imageId 为准
|
||||
- Repository manifest:`repository.json`
|
||||
- Runtime handler:`builtin_head_pose`
|
||||
- Source:`src/operator.py`
|
||||
|
||||
生产验收要求真实 fixture、artifact checksum、lineage 证据;不接受 mock、仿真、smoke 或空文件验收。
|
||||
16
operator-repos/builtin/head_pose/operator.json
Normal file
16
operator-repos/builtin/head_pose/operator.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"acceptance": {
|
||||
"hardcodedOutputAccepted": false,
|
||||
"mockOnlyAccepted": false,
|
||||
"requiresRealInputs": true,
|
||||
"shallowOnlyAccepted": false,
|
||||
"simulationOnlyAccepted": false
|
||||
},
|
||||
"category": "AI",
|
||||
"id": "operator-builtin-head-pose",
|
||||
"migrationStatus": "migrated",
|
||||
"name": "6DRepNet Headpose",
|
||||
"runtimeHandler": "builtin_head_pose",
|
||||
"runtimeSource": "operator-repos/builtin/head_pose/src/operator.py",
|
||||
"type": "builtin"
|
||||
}
|
||||
0
operator-repos/builtin/head_pose/requirements.txt
Normal file
0
operator-repos/builtin/head_pose/requirements.txt
Normal file
41
operator-repos/builtin/head_pose/runtime_contract.json
Normal file
41
operator-repos/builtin/head_pose/runtime_contract.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"acceptance": {
|
||||
"requiresArtifactChecksum": true,
|
||||
"requiresFixtureChecksum": true,
|
||||
"requiresGpuEvidence": true,
|
||||
"requiresRealFixture": true,
|
||||
"requiresWorkflowTransfer": true
|
||||
},
|
||||
"artifacts": {
|
||||
"requiresChecksum": true,
|
||||
"requiresLineage": true,
|
||||
"requiresManifest": true
|
||||
},
|
||||
"entrypoint": "/app/backend/operator-runner/main.py",
|
||||
"handler": "builtin_head_pose",
|
||||
"imagePolicy": {
|
||||
"allowsSharedBaseLayer": true,
|
||||
"forbidsSharedOperatorRunnerFinalImage": true,
|
||||
"independentFinalImage": true
|
||||
},
|
||||
"operatorId": "operator-builtin-head-pose",
|
||||
"operatorSlug": "head_pose",
|
||||
"parameters": {
|
||||
"commandWrapperAllowed": false,
|
||||
"controlledScriptAllowed": false,
|
||||
"source": "hyperparams",
|
||||
"structured": true
|
||||
},
|
||||
"resources": {
|
||||
"minGpuCount": 0,
|
||||
"recommendedGpuType": "A800",
|
||||
"requiresGpu": false
|
||||
},
|
||||
"runtimeDependencies": [
|
||||
"6drepnet-service",
|
||||
"video-artifacts"
|
||||
],
|
||||
"runtimeSource": "src/operator.py",
|
||||
"schemaVersion": "droboticflow.operator.runtime/v1",
|
||||
"sourceRoot": "operator-repos/builtin/head_pose"
|
||||
}
|
||||
0
operator-repos/builtin/head_pose/src/__init__.py
Normal file
0
operator-repos/builtin/head_pose/src/__init__.py
Normal file
234
operator-repos/builtin/head_pose/src/operator.py
Normal file
234
operator-repos/builtin/head_pose/src/operator.py
Normal file
@ -0,0 +1,234 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from typing import Any, Callable
|
||||
|
||||
|
||||
HelperMap = dict[str, Callable[..., Any]]
|
||||
IMAGE_DIGEST_PATTERN = re.compile(r"^\S+@sha256:[a-f0-9]{64}$")
|
||||
MODEL_DIGEST_PATTERN = re.compile(r"^sha256:[a-f0-9]{64}$")
|
||||
MEDIA_SUFFIXES = {".jpg", ".jpeg", ".png", ".bmp", ".webp", ".mp4", ".mov", ".m4v", ".avi", ".mkv", ".webm"}
|
||||
|
||||
|
||||
def _media_reference(value: Any) -> str:
|
||||
if isinstance(value, list):
|
||||
for item in value:
|
||||
found = _media_reference(item)
|
||||
if found:
|
||||
return found
|
||||
return ""
|
||||
if not isinstance(value, dict):
|
||||
return ""
|
||||
for key in ("previewURL", "previewUrl", "videoURL", "videoUrl", "imageURL", "imageUrl", "mediaURL", "mediaUrl", "url", "path"):
|
||||
candidate = str(value.get(key, "")).strip()
|
||||
suffix = pathlib.PurePosixPath(urllib.parse.urlparse(candidate).path).suffix.lower()
|
||||
if candidate and suffix in MEDIA_SUFFIXES:
|
||||
return candidate
|
||||
for key in ("source", "preview", "media", "file", "items", "entries", "rows", "data"):
|
||||
found = _media_reference(value.get(key))
|
||||
if found:
|
||||
return found
|
||||
return ""
|
||||
|
||||
|
||||
def _input_reference(inputs: list[dict[str, Any]]) -> str:
|
||||
for artifact in inputs:
|
||||
found = _media_reference(artifact)
|
||||
if found:
|
||||
return found
|
||||
for artifact in inputs:
|
||||
path = pathlib.Path(str(artifact.get("path", "")).strip())
|
||||
if path.is_file() and path.suffix.lower() == ".json":
|
||||
try:
|
||||
found = _media_reference(json.loads(path.read_text(encoding="utf-8")))
|
||||
except (OSError, UnicodeDecodeError, json.JSONDecodeError):
|
||||
found = ""
|
||||
if found:
|
||||
return found
|
||||
for artifact in inputs:
|
||||
for candidate in (
|
||||
artifact.get("previewURL"),
|
||||
artifact.get("url"),
|
||||
artifact.get("path"),
|
||||
(artifact.get("data") or {}).get("source", {}).get("path") if isinstance(artifact.get("data"), dict) else "",
|
||||
):
|
||||
value = str(candidate or "").strip()
|
||||
if value:
|
||||
return value
|
||||
return ""
|
||||
|
||||
|
||||
def _post_json(url: str, payload: dict[str, Any], timeout: int) -> dict[str, Any]:
|
||||
request = urllib.request.Request(
|
||||
url,
|
||||
data=json.dumps(payload).encode("utf-8"),
|
||||
headers={"Content-Type": "application/json", "Accept": "application/json"},
|
||||
method="POST",
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=timeout) as response:
|
||||
parsed = json.loads(response.read().decode("utf-8"))
|
||||
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError) as exc:
|
||||
raise RuntimeError(f"Headpose inference request failed: {exc}") from exc
|
||||
if not isinstance(parsed, dict):
|
||||
raise RuntimeError("Headpose inference returned a non-object payload")
|
||||
return parsed
|
||||
|
||||
|
||||
def _materialize_annotated_media(base_url: str, value: str, output_dir: pathlib.Path, timeout: int) -> pathlib.Path:
|
||||
source = value.strip()
|
||||
if not source:
|
||||
raise RuntimeError("Headpose inference did not return annotatedMediaUrl")
|
||||
parsed = urllib.parse.urlparse(source)
|
||||
suffix = pathlib.PurePosixPath(parsed.path).suffix.lower() or ".mp4"
|
||||
destination = output_dir / "headpose_outputs" / f"headpose-annotated{suffix}"
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
if parsed.scheme in {"http", "https"}:
|
||||
resolved = source
|
||||
elif parsed.scheme:
|
||||
raise RuntimeError(f"Unsupported Headpose annotated media scheme: {parsed.scheme}")
|
||||
else:
|
||||
local = pathlib.Path(source)
|
||||
if local.is_file():
|
||||
shutil.copy2(local, destination)
|
||||
return destination
|
||||
resolved = urllib.parse.urljoin(base_url.rstrip("/") + "/", source.lstrip("/"))
|
||||
try:
|
||||
with urllib.request.urlopen(resolved, timeout=timeout) as response:
|
||||
destination.write_bytes(response.read())
|
||||
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError) as exc:
|
||||
raise RuntimeError(f"Headpose annotated media download failed: {exc}") from exc
|
||||
if not destination.is_file() or destination.stat().st_size <= 0:
|
||||
raise RuntimeError("Headpose annotated media is empty")
|
||||
return destination
|
||||
|
||||
|
||||
def _summary(frames: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
def stats(key: str) -> dict[str, float]:
|
||||
values = [float(frame[key]) for frame in frames]
|
||||
return {"min": min(values), "max": max(values), "mean": sum(values) / len(values)}
|
||||
|
||||
return {
|
||||
"yawDeg": stats("yawDeg"),
|
||||
"pitchDeg": stats("pitchDeg"),
|
||||
"rollDeg": stats("rollDeg"),
|
||||
"confidenceMean": sum(float(frame["confidence"]) for frame in frames) / len(frames),
|
||||
}
|
||||
|
||||
|
||||
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]]:
|
||||
params = helpers["hyperparams"](node_data)
|
||||
base_url = str(params.get("HEADPOSE_API_BASE_URL", "")).strip().rstrip("/")
|
||||
model_image = str(params.get("HEADPOSE_SERVICE_IMAGE_ID", "")).strip()
|
||||
model_digest = str(params.get("HEADPOSE_MODEL_SHA256", "")).strip().lower()
|
||||
license_id = str(params.get("HEADPOSE_LICENSE_ID", "")).strip()
|
||||
model_name = str(params.get("HEADPOSE_MODEL", "6DRepNet")).strip() or "6DRepNet"
|
||||
if not base_url or not IMAGE_DIGEST_PATTERN.fullmatch(model_image):
|
||||
raise RuntimeError("Headpose requires HEADPOSE_API_BASE_URL and a digest-pinned HEADPOSE_SERVICE_IMAGE_ID")
|
||||
if not MODEL_DIGEST_PATTERN.fullmatch(model_digest) or not license_id:
|
||||
raise RuntimeError("Headpose requires HEADPOSE_MODEL_SHA256 and HEADPOSE_LICENSE_ID")
|
||||
source = _input_reference(inputs)
|
||||
if not source:
|
||||
raise RuntimeError("Headpose requires an upstream image or video artifact")
|
||||
frame_stride = int(params.get("FRAME_STRIDE", 3) or 3)
|
||||
max_frames = int(params.get("MAX_FRAMES", 120) or 120)
|
||||
timeout = int(params.get("REQUEST_TIMEOUT_SECONDS", 300) or 300)
|
||||
response = _post_json(
|
||||
f"{base_url}/v1/headpose/infer",
|
||||
{
|
||||
"source": source,
|
||||
"frameStride": frame_stride,
|
||||
"maxFrames": max_frames,
|
||||
"model": model_name,
|
||||
"modelSha256": model_digest,
|
||||
},
|
||||
timeout,
|
||||
)
|
||||
frames = response.get("frames")
|
||||
if not isinstance(frames, list) or not frames:
|
||||
raise RuntimeError("Headpose inference returned no frame results")
|
||||
normalized_frames = []
|
||||
previous_timestamp = -1.0
|
||||
for index, frame in enumerate(frames):
|
||||
if not isinstance(frame, dict):
|
||||
raise RuntimeError("Headpose frame result must be an object")
|
||||
timestamp = float(frame.get("timestampSeconds", frame.get("timestamp", 0)))
|
||||
normalized = {
|
||||
"frameIndex": int(frame.get("frameIndex", index)),
|
||||
"timestamp": timestamp,
|
||||
"timestampSeconds": timestamp,
|
||||
"yawDeg": float(frame.get("yawDeg")),
|
||||
"pitchDeg": float(frame.get("pitchDeg")),
|
||||
"rollDeg": float(frame.get("rollDeg")),
|
||||
"confidence": float(frame.get("confidence", 0)),
|
||||
}
|
||||
if not all(math.isfinite(float(normalized[key])) for key in ("timestamp", "yawDeg", "pitchDeg", "rollDeg", "confidence")):
|
||||
raise RuntimeError("Headpose frame values must be finite")
|
||||
if timestamp < 0 or timestamp < previous_timestamp:
|
||||
raise RuntimeError("Headpose timestamps must be non-negative and monotonic")
|
||||
if any(abs(float(normalized[key])) > 180 for key in ("yawDeg", "pitchDeg", "rollDeg")):
|
||||
raise RuntimeError("Headpose angles must be in [-180, 180] degrees")
|
||||
if not 0 <= normalized["confidence"] <= 1:
|
||||
raise RuntimeError("Headpose confidence must be in [0, 1]")
|
||||
normalized_frames.append(normalized)
|
||||
previous_timestamp = timestamp
|
||||
runtime_evidence = response.get("runtimeEvidence")
|
||||
if not isinstance(runtime_evidence, dict):
|
||||
raise RuntimeError("Headpose inference returned no runtime evidence")
|
||||
if str(runtime_evidence.get("modelSha256", "")).strip().lower() != model_digest:
|
||||
raise RuntimeError("Headpose runtime model digest does not match the configured digest")
|
||||
annotated_media = _materialize_annotated_media(
|
||||
base_url,
|
||||
str(response.get("annotatedMediaUrl", "")),
|
||||
output_dir,
|
||||
timeout,
|
||||
)
|
||||
manifest = {
|
||||
"schemaVersion": "droboticflow.headpose/v1",
|
||||
"enabled": True,
|
||||
"source": source,
|
||||
"model": model_name,
|
||||
"serviceImageId": model_image,
|
||||
"modelSha256": model_digest,
|
||||
"licenseId": license_id,
|
||||
"frameCount": len(normalized_frames),
|
||||
"frames": normalized_frames,
|
||||
"summary": _summary(normalized_frames),
|
||||
"annotatedMedia": annotated_media.name,
|
||||
"runtimeEvidence": runtime_evidence,
|
||||
}
|
||||
binding = helpers["output_binding"](node_data)
|
||||
artifacts = [
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
output_dir,
|
||||
"headpose-manifest.json",
|
||||
manifest,
|
||||
output=binding,
|
||||
)
|
||||
]
|
||||
artifacts.extend(
|
||||
helpers["collect_output_artifacts"](
|
||||
run_id,
|
||||
node_id,
|
||||
annotated_media.parent,
|
||||
node_data=node_data,
|
||||
output=binding,
|
||||
)
|
||||
)
|
||||
return artifacts
|
||||
@ -0,0 +1,21 @@
|
||||
{
|
||||
"fixtures": [],
|
||||
"minimumEvidence": [
|
||||
"input checksum",
|
||||
"artifact checksum",
|
||||
"lineage",
|
||||
"schema validation"
|
||||
],
|
||||
"operatorId": "operator-builtin-head-pose",
|
||||
"operatorSlug": "head_pose",
|
||||
"rules": {
|
||||
"forbidsMock": true,
|
||||
"forbidsSimulationOnly": true,
|
||||
"forbidsSmokeOnly": true,
|
||||
"forbidsSynthetic": true,
|
||||
"requiresLicense": true,
|
||||
"requiresPublicSourceUrl": true,
|
||||
"requiresSha256": true
|
||||
},
|
||||
"schemaVersion": "droboticflow.operator.fixture/v1"
|
||||
}
|
||||
@ -16,6 +16,18 @@ def run(
|
||||
inputs: list[dict[str, Any]],
|
||||
helpers: HelperMap,
|
||||
) -> list[dict[str, Any]]:
|
||||
payloads = helpers["payloads_from_inputs"](inputs)
|
||||
params = helpers["hyperparams"](node_data)
|
||||
require_headpose = str(params.get("REQUIRE_HEADPOSE", "false")).strip().lower() in {"1", "true", "yes", "on"}
|
||||
headpose = next((item for item in payloads if item.get("schemaVersion") == "droboticflow.headpose/v1"), None)
|
||||
handpose = next(
|
||||
(item for item in payloads if item.get("schemaVersion") == "droboticflow.wilor.hand_pose_result/v1"),
|
||||
None,
|
||||
)
|
||||
if require_headpose and (headpose is None or not headpose.get("enabled")):
|
||||
raise RuntimeError("成品打包需要必选的 droboticflow.headpose/v1 结果")
|
||||
headpose_enabled = bool(headpose and headpose.get("enabled"))
|
||||
handpose_enabled = bool(handpose and handpose.get("enabled", True))
|
||||
payload = helpers["first_payload_with_keys"](inputs, "annotationCount", "items")
|
||||
if payload is None:
|
||||
payload = helpers["first_payload_with_keys"](inputs, "clipCount", "items")
|
||||
@ -72,6 +84,13 @@ def run(
|
||||
"maxConfidence": item.get("maxConfidence", 0),
|
||||
}
|
||||
config_payload = helpers["package_config_payload"](item, payload)
|
||||
config_payload["deliveryItems"] = {
|
||||
"headpose": {"enabled": bool(headpose and headpose.get("enabled")), "frameCount": headpose.get("frameCount", 0) if headpose else 0},
|
||||
"handpose": {
|
||||
"enabled": bool(handpose and handpose.get("enabled", True)),
|
||||
"status": handpose.get("status", "missing") if handpose else "missing",
|
||||
},
|
||||
}
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
@ -80,6 +99,24 @@ def run(
|
||||
quality_payload,
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
if headpose_enabled:
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
package_dir,
|
||||
f"{clip_id}_headpose.json",
|
||||
headpose,
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
if handpose_enabled:
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
package_dir,
|
||||
f"{clip_id}_handpose.json",
|
||||
handpose,
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
@ -111,15 +148,29 @@ def run(
|
||||
"meta": item.get("meta", {}),
|
||||
"source": item.get("source", {}) if isinstance(item.get("source"), dict) else {},
|
||||
"fileCount": len(package_files),
|
||||
"pipelineTags": ["quality_v1", "slicing_v1", "annotation_v1"],
|
||||
"pipelineTags": [
|
||||
"quality_v1",
|
||||
"slicing_v1",
|
||||
"annotation_v1",
|
||||
"headpose_v1",
|
||||
*( ["handpose_v1"] if handpose_enabled else [] ),
|
||||
],
|
||||
"storagePath": str(package_dir),
|
||||
"quality": quality_payload,
|
||||
"annotation": annotation_payload,
|
||||
"deliveryItems": config_payload["deliveryItems"],
|
||||
}
|
||||
)
|
||||
manifest = {
|
||||
"datasetType": "x-platform-packages",
|
||||
"packageCount": len(packages),
|
||||
"deliveryItems": {
|
||||
"headpose": {"enabled": bool(headpose and headpose.get("enabled")), "schemaVersion": headpose.get("schemaVersion") if headpose else ""},
|
||||
"handpose": {
|
||||
"enabled": bool(handpose and handpose.get("enabled", True)),
|
||||
"schemaVersion": handpose.get("schemaVersion") if handpose else "",
|
||||
},
|
||||
},
|
||||
"items": packages,
|
||||
}
|
||||
binding = helpers["output_binding"](node_data)
|
||||
|
||||
@ -186,12 +186,18 @@ def _input_ref(params: dict[str, str], inputs: list[dict[str, Any]]) -> str:
|
||||
return value
|
||||
fallback_path = ""
|
||||
for artifact in inputs:
|
||||
data = artifact.get("data") if isinstance(artifact.get("data"), dict) else {}
|
||||
if data.get("schemaVersion") == "droboticflow.delivery-options/v1" or "includeHandpose" in data:
|
||||
continue
|
||||
path = str(artifact.get("path", "")).strip()
|
||||
if path and pathlib.Path(path).is_file() and _looks_like_media_ref(path):
|
||||
return path
|
||||
if path and pathlib.Path(path).is_file() and not fallback_path:
|
||||
fallback_path = path
|
||||
for artifact in inputs:
|
||||
data = artifact.get("data") if isinstance(artifact.get("data"), dict) else {}
|
||||
if data.get("schemaVersion") == "droboticflow.delivery-options/v1" or "includeHandpose" in data:
|
||||
continue
|
||||
preview_url = _artifact_preview_url(artifact)
|
||||
if preview_url and _looks_like_media_ref(preview_url):
|
||||
return preview_url
|
||||
@ -347,6 +353,28 @@ def run(
|
||||
helpers: dict[str, Any],
|
||||
) -> list[dict[str, Any]]:
|
||||
params = helpers["hyperparams"](node_data)
|
||||
include_handpose = True
|
||||
for payload in helpers["payloads_from_inputs"](inputs):
|
||||
if payload.get("schemaVersion") == "droboticflow.delivery-options/v1" or "includeHandpose" in payload:
|
||||
include_handpose = bool(payload.get("includeHandpose", False))
|
||||
break
|
||||
if not include_handpose:
|
||||
return [
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
output_dir,
|
||||
"handpose-manifest.json",
|
||||
{
|
||||
"schemaVersion": "droboticflow.wilor.hand_pose_result/v1",
|
||||
"operator": "wilor_hand_pose",
|
||||
"enabled": False,
|
||||
"status": "skipped_by_delivery_options",
|
||||
"items": [],
|
||||
},
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
]
|
||||
base_url = str(params.get("WILOR_API_BASE_URL") or DEFAULT_WILOR_API_BASE_URL).strip().rstrip("/")
|
||||
timeout = float(_int_param(params.get("REQUEST_TIMEOUT_SECONDS", ""), 300, 10, 3600, "REQUEST_TIMEOUT_SECONDS"))
|
||||
hand_conf = _float_param(params.get("HAND_CONFIDENCE", ""), 0.30, 0.05, 0.95, "HAND_CONFIDENCE")
|
||||
|
||||
@ -35,7 +35,7 @@ POC_KANIKO_NODE_NAME="${POC_KANIKO_NODE_NAME:-}"
|
||||
POC_KANIKO_BUILD_OPERATORS="${POC_KANIKO_BUILD_OPERATORS:-false}"
|
||||
POC_KANIKO_BUILD_OPERATOR_BASES="${POC_KANIKO_BUILD_OPERATOR_BASES:-true}"
|
||||
POC_KANIKO_OPERATOR_BASE_FILTER="${POC_KANIKO_OPERATOR_BASE_FILTER:-}"
|
||||
POC_KANIKO_COMPONENTS="${POC_KANIKO_COMPONENTS:-api,worker,drosync-coordinator,runner}"
|
||||
POC_KANIKO_COMPONENTS="${POC_KANIKO_COMPONENTS:-api,worker,drosync-coordinator,runner,headpose-service}"
|
||||
POC_KANIKO_OPERATOR_MANIFEST="${POC_KANIKO_OPERATOR_MANIFEST:-operator-images/builtin/operator-images.json}"
|
||||
POC_KANIKO_OPERATOR_FILTER="${POC_KANIKO_OPERATOR_FILTER:-}"
|
||||
POC_KANIKO_OPERATOR_CONCURRENCY="${POC_KANIKO_OPERATOR_CONCURRENCY:-4}"
|
||||
@ -52,6 +52,7 @@ fi
|
||||
POC_KANIKO_SOURCE_COMMIT="${POC_KANIKO_SOURCE_COMMIT:-$(git -C "$ROOT_DIR" rev-parse HEAD)}"
|
||||
POC_KANIKO_BUILD_TIME="${POC_KANIKO_BUILD_TIME:-}"
|
||||
POC_KANIKO_BUILD_TIME="$(droboticflow_normalize_build_time "$POC_KANIKO_BUILD_TIME")"
|
||||
HEADPOSE_SERVICE_IMAGE="${HEADPOSE_SERVICE_IMAGE:-$REGISTRY_HOST/$REGISTRY_NAMESPACE/droboticflow-headpose-service:$IMAGE_TAG}"
|
||||
|
||||
# shellcheck source=scripts/lib/image-config.sh
|
||||
source "$ROOT_DIR/scripts/lib/image-config.sh"
|
||||
@ -78,6 +79,7 @@ validate_image_reference API_IMAGE "$API_IMAGE"
|
||||
validate_image_reference WORKER_IMAGE "$WORKER_IMAGE"
|
||||
validate_image_reference DROSYNC_COORDINATOR_IMAGE "$DROSYNC_COORDINATOR_IMAGE"
|
||||
validate_image_reference OPERATOR_RUNNER_IMAGE "$OPERATOR_RUNNER_IMAGE"
|
||||
validate_image_reference HEADPOSE_SERVICE_IMAGE "$HEADPOSE_SERVICE_IMAGE"
|
||||
validate_image_reference POC_KANIKO_OPERATOR_BASE_IMAGE "$POC_KANIKO_OPERATOR_BASE_IMAGE"
|
||||
validate_image_reference POC_KANIKO_OPERATOR_GPU_BASE_IMAGE "$POC_KANIKO_OPERATOR_GPU_BASE_IMAGE"
|
||||
validate_image_reference POC_KANIKO_OPERATOR_HOLOBRAIN_BASE_IMAGE "$POC_KANIKO_OPERATOR_HOLOBRAIN_BASE_IMAGE"
|
||||
@ -355,7 +357,8 @@ enabled_platform_specs() {
|
||||
"api"$'\t'"Dockerfile.api"$'\t'"$API_IMAGE"
|
||||
"worker"$'\t'"Dockerfile.worker"$'\t'"$WORKER_IMAGE"
|
||||
"drosync-coordinator"$'\t'"Dockerfile.drosync-coordinator"$'\t'"$DROSYNC_COORDINATOR_IMAGE"
|
||||
"runner"$'\t'"Dockerfile.operator-runner"$'\t'"$OPERATOR_RUNNER_IMAGE"
|
||||
"runner"$'\t'"Dockerfile.operator-runner"$'\t'"$OPERATOR_RUNNER_IMAGE"
|
||||
"headpose-service"$'\t'"Dockerfile.headpose-service"$'\t'"$HEADPOSE_SERVICE_IMAGE"
|
||||
)
|
||||
local spec
|
||||
local component
|
||||
@ -523,6 +526,7 @@ printf 'API_IMAGE=%s\n' "$API_IMAGE"
|
||||
printf 'WORKER_IMAGE=%s\n' "$WORKER_IMAGE"
|
||||
printf 'DROSYNC_COORDINATOR_IMAGE=%s\n' "$DROSYNC_COORDINATOR_IMAGE"
|
||||
printf 'OPERATOR_RUNNER_IMAGE=%s\n' "$OPERATOR_RUNNER_IMAGE"
|
||||
printf 'HEADPOSE_SERVICE_IMAGE=%s\n' "$HEADPOSE_SERVICE_IMAGE"
|
||||
if (( operator_component_count > 0 )); then
|
||||
printf 'OPERATOR_BASE_IMAGE=%s\n' "$POC_KANIKO_OPERATOR_BASE_IMAGE"
|
||||
printf 'OPERATOR_GPU_BASE_IMAGE=%s\n' "$POC_KANIKO_OPERATOR_GPU_BASE_IMAGE"
|
||||
|
||||
@ -49,3 +49,4 @@ export CUSTOM_OPERATOR_IMAGE_ARCHIVE_MAX_MIB="${CUSTOM_OPERATOR_IMAGE_ARCHIVE_MA
|
||||
|
||||
export AI_API_BASE_URL="${AI_API_BASE_URL:-}"
|
||||
export AI_MODEL="${AI_MODEL:-}"
|
||||
export HEADPOSE_MODEL_SHA256="${HEADPOSE_MODEL_SHA256:-sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018}"
|
||||
|
||||
@ -50,6 +50,12 @@ WORKER_MISSING_JOB_MAX_RECOVERIES="${WORKER_MISSING_JOB_MAX_RECOVERIES:-3}"
|
||||
# shellcheck source=scripts/lib/image-config.sh
|
||||
source "$ROOT_DIR/scripts/lib/image-config.sh"
|
||||
droboticflow_resolve_image_configuration
|
||||
if [[ -z "${HEADPOSE_SERVICE_IMAGE:-}" && -n "$REGISTRY_HOST" && -n "$REGISTRY_NAMESPACE" ]]; then
|
||||
HEADPOSE_SERVICE_IMAGE="$REGISTRY_HOST/$REGISTRY_NAMESPACE/droboticflow-headpose-service:${IMAGE_TAG:-latest}"
|
||||
fi
|
||||
HEADPOSE_SERVICE_IMAGE="${HEADPOSE_SERVICE_IMAGE:-droboticflow-headpose-service:latest}"
|
||||
HEADPOSE_SERVICE_IMAGE_ID="${HEADPOSE_SERVICE_IMAGE_ID:-}"
|
||||
HEADPOSE_MODEL_SHA256="${HEADPOSE_MODEL_SHA256:-sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018}"
|
||||
DROBOTICFLOW_BUILD_COMMIT="${DROBOTICFLOW_BUILD_COMMIT:-$(git -C "$ROOT_DIR" rev-parse HEAD)}"
|
||||
DROBOTICFLOW_BUILD_TIME="${DROBOTICFLOW_BUILD_TIME:-}"
|
||||
OPERATOR_RUNNER_BUILD_COMMIT="${OPERATOR_RUNNER_BUILD_COMMIT:-$DROBOTICFLOW_BUILD_COMMIT}"
|
||||
@ -211,6 +217,9 @@ env \
|
||||
API_IMAGE="$API_IMAGE" \
|
||||
WORKER_IMAGE="$WORKER_IMAGE" \
|
||||
OPERATOR_RUNNER_IMAGE="$OPERATOR_RUNNER_IMAGE" \
|
||||
HEADPOSE_SERVICE_IMAGE="$HEADPOSE_SERVICE_IMAGE" \
|
||||
HEADPOSE_SERVICE_IMAGE_ID="$HEADPOSE_SERVICE_IMAGE_ID" \
|
||||
HEADPOSE_MODEL_SHA256="$HEADPOSE_MODEL_SHA256" \
|
||||
OPERATOR_RUNNER_BUILD_COMMIT="$OPERATOR_RUNNER_BUILD_COMMIT" \
|
||||
OPERATOR_RUNNER_BUILD_TIME="$OPERATOR_RUNNER_BUILD_TIME" \
|
||||
DROBOTICFLOW_BUILD_COMMIT="$DROBOTICFLOW_BUILD_COMMIT" \
|
||||
@ -255,8 +264,9 @@ fi
|
||||
|
||||
kubectl -n "$K8S_NAMESPACE" rollout status deployment/droboticflow-api --timeout=300s
|
||||
kubectl -n "$K8S_NAMESPACE" rollout status deployment/droboticflow-worker --timeout=300s
|
||||
kubectl -n "$K8S_NAMESPACE" rollout status deployment/droboticflow-headpose --timeout=900s
|
||||
|
||||
kubectl -n "$K8S_NAMESPACE" get pods -l 'app in (droboticflow-api,droboticflow-worker)'
|
||||
kubectl -n "$K8S_NAMESPACE" get pods -l 'app in (droboticflow-api,droboticflow-worker,droboticflow-headpose)'
|
||||
kubectl -n "$K8S_NAMESPACE" get svc droboticflow-api
|
||||
if boolean_true API_PUBLIC_LOAD_BALANCER "$API_PUBLIC_LOAD_BALANCER"; then
|
||||
kubectl -n "$K8S_NAMESPACE" get svc "$API_PUBLIC_SERVICE_NAME"
|
||||
|
||||
@ -35,6 +35,7 @@ RUNTIME_DEPENDENCIES: dict[str, list[str]] = {
|
||||
"dataset_split_leakage_validate": ["split-manifest-csv-json-jsonl-parquet-files", "pyarrow"],
|
||||
"dataset_split_manifest": ["json-artifacts", "csv-files"],
|
||||
"dataset_provenance_audit": ["dataset-card-files", "license-files", "pyyaml"],
|
||||
"delivery_options": ["json-artifacts"],
|
||||
"dexycb_dataset_validate": ["dexycb-dataset-files", "numpy", "npz-label-files", "rgb-depth-image-files"],
|
||||
"diffusion_policy_train": ["real-stanford-diffusion-policy", "zarr-or-lerobot-trajectory-files", "gpu-a800"],
|
||||
"directory_scan": ["filesystem"],
|
||||
@ -48,6 +49,7 @@ RUNTIME_DEPENDENCIES: dict[str, list[str]] = {
|
||||
"hf_dataset_probe": ["huggingface-dataset-viewer-api"],
|
||||
"hand_object_pose_validate": ["json-jsonl-csv-parquet-files", "image-files", "mask-files", "pyarrow"],
|
||||
"hand_removal": ["propainter-inference-service", "sam3-mask-artifacts", "image-video-files", "http-api", "gpu-a800-service"],
|
||||
"head_pose": ["6drepnet-service", "video-artifacts", "http-api"],
|
||||
"ho3d_dataset_validate": ["ho3d-h2o3d-dataset-files", "pickle", "numpy", "rgb-depth-image-files"],
|
||||
"holobrain_data_prepare": ["official-robotwin2-dataset", "huggingface-hub", "real-robotwin-files"],
|
||||
"holobrain_export": ["roboorchardlab-holobrain-export", "holobrain-checkpoint", "gpu-a800"],
|
||||
|
||||
@ -62,6 +62,9 @@ OPERATOR_COMMAND_DENYLIST_REGEX="${OPERATOR_COMMAND_DENYLIST_REGEX:-}"
|
||||
DROBOTICFLOW_REQUIRE_SESSION_AUTH="${DROBOTICFLOW_REQUIRE_SESSION_AUTH:-$API_PUBLIC_LOAD_BALANCER}"
|
||||
DROBOTICFLOW_SESSION_COOKIE_SECURE="${DROBOTICFLOW_SESSION_COOKIE_SECURE:-$API_PUBLIC_LOAD_BALANCER}"
|
||||
DROBOTICFLOW_TRUSTED_PROXY_CIDRS="${DROBOTICFLOW_TRUSTED_PROXY_CIDRS:-}"
|
||||
HEADPOSE_SERVICE_IMAGE="${HEADPOSE_SERVICE_IMAGE:-droboticflow-headpose-service:latest}"
|
||||
HEADPOSE_SERVICE_IMAGE_ID="${HEADPOSE_SERVICE_IMAGE_ID:-}"
|
||||
HEADPOSE_MODEL_SHA256="${HEADPOSE_MODEL_SHA256:-sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018}"
|
||||
# shellcheck source=scripts/lib/image-config.sh
|
||||
source "$ROOT_DIR/scripts/lib/image-config.sh"
|
||||
REGISTRY_HOST="${REGISTRY_HOST:-}"
|
||||
@ -150,7 +153,10 @@ export \
|
||||
OPERATOR_COMMAND_DENYLIST_REGEX_BLOCK \
|
||||
DROBOTICFLOW_REQUIRE_SESSION_AUTH \
|
||||
DROBOTICFLOW_SESSION_COOKIE_SECURE \
|
||||
DROBOTICFLOW_TRUSTED_PROXY_CIDRS
|
||||
DROBOTICFLOW_TRUSTED_PROXY_CIDRS \
|
||||
HEADPOSE_SERVICE_IMAGE \
|
||||
HEADPOSE_SERVICE_IMAGE_ID \
|
||||
HEADPOSE_MODEL_SHA256
|
||||
|
||||
python3 - <<'PY'
|
||||
import os
|
||||
@ -206,6 +212,9 @@ replacements = {
|
||||
"__DROBOTICFLOW_REQUIRE_SESSION_AUTH__": os.environ["DROBOTICFLOW_REQUIRE_SESSION_AUTH"],
|
||||
"__DROBOTICFLOW_SESSION_COOKIE_SECURE__": os.environ["DROBOTICFLOW_SESSION_COOKIE_SECURE"],
|
||||
"__DROBOTICFLOW_TRUSTED_PROXY_CIDRS__": os.environ["DROBOTICFLOW_TRUSTED_PROXY_CIDRS"],
|
||||
"__HEADPOSE_SERVICE_IMAGE__": os.environ["HEADPOSE_SERVICE_IMAGE"],
|
||||
"__HEADPOSE_SERVICE_IMAGE_ID__": os.environ["HEADPOSE_SERVICE_IMAGE_ID"],
|
||||
"__HEADPOSE_MODEL_SHA256__": os.environ["HEADPOSE_MODEL_SHA256"],
|
||||
}
|
||||
|
||||
rendered = template
|
||||
|
||||
1
services/headpose/__init__.py
Normal file
1
services/headpose/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
"""Digest-pinned 6DRepNet inference service."""
|
||||
245
services/headpose/app.py
Normal file
245
services/headpose/app.py
Normal file
@ -0,0 +1,245 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import importlib.metadata
|
||||
import math
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import uuid
|
||||
from typing import Any
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
import torch
|
||||
from fastapi import FastAPI, HTTPException, Request
|
||||
from fastapi.responses import FileResponse
|
||||
from pydantic import BaseModel, Field
|
||||
from sixdrepnet import SixDRepNet
|
||||
|
||||
|
||||
MODEL_PATH = pathlib.Path(os.environ.get("HEADPOSE_MODEL_PATH", "/opt/models/6DRepNet_300W_LP_AFLW2000.pth"))
|
||||
MODEL_SHA256 = os.environ.get("HEADPOSE_MODEL_SHA256", "sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018").lower()
|
||||
LICENSE_ID = os.environ.get("HEADPOSE_LICENSE_ID", "MIT")
|
||||
OUTPUT_ROOT = pathlib.Path(os.environ.get("HEADPOSE_OUTPUT_ROOT", "/workspace/system/headpose-service"))
|
||||
MAX_DOWNLOAD_BYTES = int(os.environ.get("HEADPOSE_MAX_DOWNLOAD_BYTES", str(4 * 1024 * 1024 * 1024)))
|
||||
GPU_ID = int(os.environ.get("HEADPOSE_GPU_ID", "0" if torch.cuda.is_available() else "-1"))
|
||||
STARTED_AT = time.time()
|
||||
|
||||
|
||||
def sha256_file(path: pathlib.Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as handle:
|
||||
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
||||
digest.update(chunk)
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
if not MODEL_PATH.is_file():
|
||||
raise RuntimeError(f"6DRepNet weights are missing: {MODEL_PATH}")
|
||||
if sha256_file(MODEL_PATH) != MODEL_SHA256:
|
||||
raise RuntimeError("6DRepNet model digest does not match HEADPOSE_MODEL_SHA256")
|
||||
if LICENSE_ID != "MIT":
|
||||
raise RuntimeError("6DRepNet service requires the reviewed MIT license identifier")
|
||||
|
||||
OUTPUT_ROOT.mkdir(parents=True, exist_ok=True)
|
||||
MODEL = SixDRepNet(gpu_id=GPU_ID, dict_path=str(MODEL_PATH))
|
||||
MODEL_LOCK = threading.Lock()
|
||||
FACE_DETECTOR = cv2.CascadeClassifier(str(pathlib.Path(cv2.data.haarcascades) / "haarcascade_frontalface_default.xml"))
|
||||
if FACE_DETECTOR.empty():
|
||||
raise RuntimeError("OpenCV frontal-face detector could not be loaded")
|
||||
|
||||
app = FastAPI(title="Droboticflow 6DRepNet Headpose Service", version="1.0.0")
|
||||
|
||||
|
||||
class InferenceRequest(BaseModel):
|
||||
source: str = Field(min_length=1)
|
||||
frameStride: int = Field(default=3, ge=1, le=300)
|
||||
maxFrames: int = Field(default=120, ge=1, le=10000)
|
||||
model: str = "6DRepNet"
|
||||
modelSha256: str
|
||||
|
||||
|
||||
def safe_output(request_id: str, name: str) -> pathlib.Path:
|
||||
if not request_id.replace("-", "").isalnum() or pathlib.PurePath(name).name != name:
|
||||
raise HTTPException(status_code=404, detail="artifact not found")
|
||||
target = (OUTPUT_ROOT / request_id / name).resolve()
|
||||
if OUTPUT_ROOT.resolve() not in target.parents:
|
||||
raise HTTPException(status_code=404, detail="artifact not found")
|
||||
return target
|
||||
|
||||
|
||||
def materialize_source(source: str, directory: pathlib.Path) -> pathlib.Path:
|
||||
parsed = urllib.parse.urlparse(source)
|
||||
if parsed.scheme in {"http", "https"}:
|
||||
suffix = pathlib.PurePosixPath(parsed.path).suffix or ".bin"
|
||||
destination = directory / f"input{suffix}"
|
||||
request = urllib.request.Request(source, headers={"User-Agent": "droboticflow-headpose/1.0"})
|
||||
with urllib.request.urlopen(request, timeout=300) as response, destination.open("wb") as output:
|
||||
total = 0
|
||||
while True:
|
||||
chunk = response.read(1024 * 1024)
|
||||
if not chunk:
|
||||
break
|
||||
total += len(chunk)
|
||||
if total > MAX_DOWNLOAD_BYTES:
|
||||
raise RuntimeError("input media exceeds HEADPOSE_MAX_DOWNLOAD_BYTES")
|
||||
output.write(chunk)
|
||||
return destination
|
||||
if parsed.scheme:
|
||||
raise RuntimeError(f"unsupported source scheme: {parsed.scheme}")
|
||||
local = pathlib.Path(source).resolve()
|
||||
workspace = pathlib.Path("/workspace").resolve()
|
||||
if not local.is_file() or workspace not in local.parents:
|
||||
raise RuntimeError("local source must be a readable file below /workspace")
|
||||
return local
|
||||
|
||||
|
||||
def detect_face(frame: np.ndarray) -> tuple[np.ndarray, tuple[int, int, int, int], float]:
|
||||
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
boxes, _, weights = FACE_DETECTOR.detectMultiScale3(
|
||||
gray,
|
||||
scaleFactor=1.1,
|
||||
minNeighbors=5,
|
||||
minSize=(40, 40),
|
||||
outputRejectLevels=True,
|
||||
)
|
||||
if len(boxes) == 0:
|
||||
raise RuntimeError("no face detected in sampled frame")
|
||||
best = max(range(len(boxes)), key=lambda index: float(weights[index]))
|
||||
x, y, width, height = [int(value) for value in boxes[best]]
|
||||
padding = int(max(width, height) * 0.2)
|
||||
x0, y0 = max(0, x - padding), max(0, y - padding)
|
||||
x1, y1 = min(frame.shape[1], x + width + padding), min(frame.shape[0], y + height + padding)
|
||||
crop = frame[y0:y1, x0:x1]
|
||||
confidence = 1.0 / (1.0 + math.exp(-float(weights[best])))
|
||||
return crop, (x, y, width, height), confidence
|
||||
|
||||
|
||||
def predict_frame(frame: np.ndarray) -> tuple[float, float, float, float, tuple[int, int, int, int]]:
|
||||
crop, box, confidence = detect_face(frame)
|
||||
with MODEL_LOCK, torch.inference_mode():
|
||||
pitch, yaw, roll = MODEL.predict(crop)
|
||||
return float(pitch[0]), float(yaw[0]), float(roll[0]), confidence, box
|
||||
|
||||
|
||||
def process_video(source: pathlib.Path, destination: pathlib.Path, stride: int, max_frames: int) -> list[dict[str, Any]]:
|
||||
capture = cv2.VideoCapture(str(source))
|
||||
if not capture.isOpened():
|
||||
raise RuntimeError("input video could not be opened")
|
||||
fps = float(capture.get(cv2.CAP_PROP_FPS) or 0)
|
||||
width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH))
|
||||
height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
||||
if fps <= 0 or width <= 0 or height <= 0:
|
||||
capture.release()
|
||||
raise RuntimeError("input video metadata is invalid")
|
||||
writer = cv2.VideoWriter(str(destination), cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))
|
||||
if not writer.isOpened():
|
||||
capture.release()
|
||||
raise RuntimeError("annotated video writer could not be opened")
|
||||
results: list[dict[str, Any]] = []
|
||||
frame_index = 0
|
||||
try:
|
||||
while len(results) < max_frames:
|
||||
ok, frame = capture.read()
|
||||
if not ok:
|
||||
break
|
||||
if frame_index % stride == 0:
|
||||
pitch, yaw, roll, confidence, (x, y, box_width, box_height) = predict_frame(frame)
|
||||
MODEL.draw_axis(frame, yaw, pitch, roll, x + box_width / 2, y + box_height / 2, max(40, box_width // 2))
|
||||
cv2.rectangle(frame, (x, y), (x + box_width, y + box_height), (255, 255, 0), 2)
|
||||
results.append(
|
||||
{
|
||||
"frameIndex": frame_index,
|
||||
"timestampSeconds": frame_index / fps,
|
||||
"yawDeg": yaw,
|
||||
"pitchDeg": pitch,
|
||||
"rollDeg": roll,
|
||||
"confidence": confidence,
|
||||
}
|
||||
)
|
||||
writer.write(frame)
|
||||
frame_index += 1
|
||||
finally:
|
||||
capture.release()
|
||||
writer.release()
|
||||
if not results:
|
||||
raise RuntimeError("no sampled video frame produced a headpose result")
|
||||
return results
|
||||
|
||||
|
||||
def process_image(source: pathlib.Path, destination: pathlib.Path) -> list[dict[str, Any]]:
|
||||
frame = cv2.imread(str(source))
|
||||
if frame is None:
|
||||
raise RuntimeError("input image could not be opened")
|
||||
pitch, yaw, roll, confidence, (x, y, width, height) = predict_frame(frame)
|
||||
MODEL.draw_axis(frame, yaw, pitch, roll, x + width / 2, y + height / 2, max(40, width // 2))
|
||||
cv2.rectangle(frame, (x, y), (x + width, y + height), (255, 255, 0), 2)
|
||||
if not cv2.imwrite(str(destination), frame):
|
||||
raise RuntimeError("annotated image could not be written")
|
||||
return [{"frameIndex": 0, "timestampSeconds": 0.0, "yawDeg": yaw, "pitchDeg": pitch, "rollDeg": roll, "confidence": confidence}]
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health() -> dict[str, Any]:
|
||||
return {
|
||||
"ready": True,
|
||||
"model": "6DRepNet",
|
||||
"modelSha256": MODEL_SHA256,
|
||||
"licenseId": LICENSE_ID,
|
||||
"cuda": torch.cuda.is_available(),
|
||||
"gpu": torch.cuda.get_device_name(GPU_ID) if GPU_ID >= 0 and torch.cuda.is_available() else "cpu",
|
||||
}
|
||||
|
||||
|
||||
@app.post("/v1/headpose/infer")
|
||||
def infer(payload: InferenceRequest, request: Request) -> dict[str, Any]:
|
||||
if payload.model != "6DRepNet" or payload.modelSha256.lower() != MODEL_SHA256:
|
||||
raise HTTPException(status_code=422, detail="model identity does not match the deployed 6DRepNet weights")
|
||||
request_id = uuid.uuid4().hex
|
||||
output_dir = OUTPUT_ROOT / request_id
|
||||
output_dir.mkdir(parents=True, exist_ok=False)
|
||||
started = time.time()
|
||||
try:
|
||||
with tempfile.TemporaryDirectory(prefix="headpose-input-") as temporary:
|
||||
source = materialize_source(payload.source, pathlib.Path(temporary))
|
||||
is_image = source.suffix.lower() in {".jpg", ".jpeg", ".png", ".bmp", ".webp"}
|
||||
output_name = "headpose-annotated.jpg" if is_image else "headpose-annotated.mp4"
|
||||
output_path = output_dir / output_name
|
||||
frames = process_image(source, output_path) if is_image else process_video(source, output_path, payload.frameStride, payload.maxFrames)
|
||||
except Exception as exc:
|
||||
shutil.rmtree(output_dir, ignore_errors=True)
|
||||
raise HTTPException(status_code=422, detail=str(exc)) from exc
|
||||
elapsed_ms = int((time.time() - started) * 1000)
|
||||
artifact_url = str(request.base_url).rstrip("/") + f"/artifacts/{request_id}/{output_name}"
|
||||
return {
|
||||
"frames": frames,
|
||||
"annotatedMediaUrl": artifact_url,
|
||||
"runtimeEvidence": {
|
||||
"service": "droboticflow-headpose",
|
||||
"serviceVersion": "1.0.0",
|
||||
"sixdrepnetVersion": importlib.metadata.version("sixdrepnet"),
|
||||
"torchVersion": torch.__version__,
|
||||
"cudaAvailable": torch.cuda.is_available(),
|
||||
"gpu": torch.cuda.get_device_name(GPU_ID) if GPU_ID >= 0 and torch.cuda.is_available() else "cpu",
|
||||
"modelSha256": MODEL_SHA256,
|
||||
"licenseId": LICENSE_ID,
|
||||
"sampledFrameCount": len(frames),
|
||||
"latencyMs": elapsed_ms,
|
||||
"serviceUptimeSeconds": int(time.time() - STARTED_AT),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@app.get("/artifacts/{request_id}/{name}")
|
||||
def artifact(request_id: str, name: str) -> FileResponse:
|
||||
target = safe_output(request_id, name)
|
||||
if not target.is_file():
|
||||
raise HTTPException(status_code=404, detail="artifact not found")
|
||||
media_type = "video/mp4" if target.suffix.lower() == ".mp4" else "image/jpeg"
|
||||
return FileResponse(target, media_type=media_type, filename=target.name)
|
||||
4
services/headpose/requirements.txt
Normal file
4
services/headpose/requirements.txt
Normal file
@ -0,0 +1,4 @@
|
||||
fastapi==0.116.1
|
||||
opencv-python-headless==4.10.0.84
|
||||
sixdrepnet==0.1.6
|
||||
uvicorn[standard]==0.35.0
|
||||
@ -38,7 +38,7 @@ const navItems: readonly NavigationItem[] = [
|
||||
icon: LayoutDashboard,
|
||||
label: "仪表盘",
|
||||
path: "/",
|
||||
roles: ["admin", "annotator", "quality_reviewer", "acceptance_reviewer"],
|
||||
roles: ["admin", "annotator", "quality_reviewer", "acceptance_reviewer", "supplier_manager"],
|
||||
},
|
||||
{
|
||||
icon: FolderKanban,
|
||||
|
||||
@ -18,13 +18,18 @@ export const USER_ROLE_OPTIONS: Array<{
|
||||
{
|
||||
value: "quality_reviewer",
|
||||
label: "质检员",
|
||||
description: "在授权项目内复核视频质量与标注质量",
|
||||
description: "在授权项目内执行人工标注质量复核",
|
||||
},
|
||||
{
|
||||
value: "acceptance_reviewer",
|
||||
label: "验收员",
|
||||
description: "在授权项目内执行成品数据最终验收",
|
||||
},
|
||||
{
|
||||
value: "supplier_manager",
|
||||
label: "供应商管理员",
|
||||
description: "查看授权供应商团队的工作量与工作质量,不参与任务处理",
|
||||
},
|
||||
];
|
||||
|
||||
const legacyLabels: Partial<Record<UserRole, string>> = {
|
||||
|
||||
@ -68,7 +68,6 @@ const emptyTask = {
|
||||
clipEnd: "30",
|
||||
workgroupId: "",
|
||||
templateId: "",
|
||||
assignedUserId: "",
|
||||
};
|
||||
|
||||
const panelClass = "rounded-2xl border border-[#2a2b2f] bg-[#151619]";
|
||||
@ -82,7 +81,7 @@ function taskVisibleInMode(status: string, mode: WorkspaceMode) {
|
||||
}
|
||||
|
||||
export default function AnnotationOperations() {
|
||||
const { users, role } = useUser();
|
||||
const { users, role, currentUser } = useUser();
|
||||
const { timeZone } = useTimeZone();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const location = useLocation();
|
||||
@ -278,6 +277,12 @@ export default function AnnotationOperations() {
|
||||
() => tasks.filter((task) => taskVisibleInMode(task.status, workspaceMode)),
|
||||
[tasks, workspaceMode],
|
||||
);
|
||||
const selectedHumanItem = detail?.humanItem;
|
||||
const selectedClaimedByMe = Boolean(
|
||||
selectedHumanItem &&
|
||||
selectedHumanItem.assignedUserId === currentUser?.id &&
|
||||
["claimed", "in_progress"].includes(selectedHumanItem.status),
|
||||
);
|
||||
const workspaceTitle =
|
||||
workspaceMode === "quality"
|
||||
? "人工质检工作台"
|
||||
@ -531,7 +536,6 @@ export default function AnnotationOperations() {
|
||||
clipEnd: Number(taskDraft.clipEnd),
|
||||
templateId: taskDraft.templateId,
|
||||
workgroupId: taskDraft.workgroupId,
|
||||
assignedUserId: taskDraft.assignedUserId || undefined,
|
||||
});
|
||||
setTaskDraft(emptyTask);
|
||||
await loadProject();
|
||||
@ -542,6 +546,36 @@ export default function AnnotationOperations() {
|
||||
}
|
||||
};
|
||||
|
||||
const claimSelectedTask = async () => {
|
||||
if (!detail?.humanItem) return;
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await humanLoopApi.claim(detail.humanItem.id, detail.humanItem.version);
|
||||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||||
await loadProject();
|
||||
} catch (claimError) {
|
||||
setError(getActionErrorMessage(claimError, "领取任务失败,任务可能已被其他成员领取"));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const releaseSelectedTask = async () => {
|
||||
if (!detail?.humanItem) return;
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await humanLoopApi.release(detail.humanItem.id, detail.humanItem.version);
|
||||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||||
await loadProject();
|
||||
} catch (releaseError) {
|
||||
setError(getActionErrorMessage(releaseError, "释放任务失败"));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const reopenReject = async (reject: HumanReject, targetStageId: string) => {
|
||||
setSaving(true);
|
||||
setError("");
|
||||
@ -594,6 +628,40 @@ export default function AnnotationOperations() {
|
||||
}
|
||||
};
|
||||
|
||||
const claimDeliveryPackage = async (item: DeliveryPackage) => {
|
||||
if (!item.acceptanceHumanItemId || !item.acceptanceHumanItemVersion) {
|
||||
setError("验收任务池记录尚未就绪,请稍后刷新。");
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await humanLoopApi.claim(item.acceptanceHumanItemId, item.acceptanceHumanItemVersion);
|
||||
await loadProject();
|
||||
} catch (claimError) {
|
||||
setError(getActionErrorMessage(claimError, "领取验收任务失败"));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const releaseDeliveryPackage = async (item: DeliveryPackage) => {
|
||||
if (!item.acceptanceHumanItemId || !item.acceptanceHumanItemVersion) {
|
||||
setError("验收任务池记录尚未就绪,请稍后刷新。");
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await humanLoopApi.release(item.acceptanceHumanItemId, item.acceptanceHumanItemVersion);
|
||||
await loadProject();
|
||||
} catch (releaseError) {
|
||||
setError(getActionErrorMessage(releaseError, "释放验收任务失败"));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const selectProject = (nextProjectId: string) => {
|
||||
setProjectId(nextProjectId);
|
||||
const next = new URLSearchParams(searchParams);
|
||||
@ -755,21 +823,47 @@ export default function AnnotationOperations() {
|
||||
<div className="font-mono text-xs text-blue-300">{item.id}</div>
|
||||
<div className="mt-2 text-lg font-semibold text-white">成品包 · {item.itemIds.length} 条数据</div>
|
||||
<div className="mt-1 text-xs text-gray-500">
|
||||
Partition {item.releasePartitionId} · manifest {item.manifestDigest.slice(0, 12)} · handpose{" "}
|
||||
{item.handposeArtifactIds?.length || 0}
|
||||
Partition {item.releasePartitionId} · manifest {item.manifestDigest.slice(0, 12)} · headpose{" "}
|
||||
{item.headposeArtifactIds?.length || 0} · handpose {item.handposeArtifactIds?.length || 0}
|
||||
</div>
|
||||
<Link
|
||||
className="mt-2 inline-block text-xs text-blue-300"
|
||||
to={`/monitoring?runId=${encodeURIComponent(item.childRunId)}`}
|
||||
>
|
||||
查看打包 Run 与 lineage
|
||||
</Link>
|
||||
{role === "admin" ? (
|
||||
<Link
|
||||
className="mt-2 inline-block text-xs text-blue-300"
|
||||
to={`/monitoring?runId=${encodeURIComponent(item.childRunId)}`}
|
||||
>
|
||||
查看打包 Run 与 lineage
|
||||
</Link>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="rounded-full border border-[#2a2b2f] px-3 py-1 text-xs text-gray-300">
|
||||
{item.status}
|
||||
</span>
|
||||
{item.status === "pending_acceptance" && !item.assignedUserId ? (
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving}
|
||||
onClick={() => void claimDeliveryPackage(item)}
|
||||
className="rounded-lg bg-blue-600 px-3 py-2 text-xs text-white disabled:opacity-50"
|
||||
>
|
||||
领取验收任务
|
||||
</button>
|
||||
) : null}
|
||||
{item.status === "pending_acceptance" &&
|
||||
item.assignedUserId &&
|
||||
(role === "admin" || item.assignedUserId === currentUser?.id) ? (
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving}
|
||||
onClick={() => void releaseDeliveryPackage(item)}
|
||||
className="rounded-lg border border-amber-500/40 px-3 py-2 text-xs text-amber-200 disabled:opacity-50"
|
||||
>
|
||||
释放任务
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="rounded-full border border-[#2a2b2f] px-3 py-1 text-xs text-gray-300">
|
||||
{item.status}
|
||||
</span>
|
||||
</div>
|
||||
{item.status === "pending_acceptance" ? (
|
||||
{item.status === "pending_acceptance" && item.assignedUserId === currentUser?.id ? (
|
||||
<div className="mt-4 space-y-3">
|
||||
<div className="grid gap-3 md:grid-cols-4">
|
||||
<select
|
||||
@ -932,18 +1026,9 @@ export default function AnnotationOperations() {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
className={inputClass}
|
||||
value={taskDraft.assignedUserId}
|
||||
onChange={(event) => setTaskDraft((current) => ({ ...current, assignedUserId: event.target.value }))}
|
||||
>
|
||||
<option value="">暂不指定标注员</option>
|
||||
{users.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="rounded-lg border border-blue-500/20 bg-blue-500/10 px-3 py-2 text-xs text-blue-100">
|
||||
任务创建后进入供应商工作组待领取池,不指定人员、不发送推送。
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void createTask()}
|
||||
@ -968,7 +1053,7 @@ export default function AnnotationOperations() {
|
||||
模板 v{detail.task.templateVersion} · {statusLabels[detail.task.status]}
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap gap-3 text-xs text-gray-500">
|
||||
{detail.task.runId ? (
|
||||
{detail.task.runId && role === "admin" ? (
|
||||
<Link
|
||||
className="text-blue-300 hover:text-blue-200"
|
||||
to={`/monitoring?runId=${encodeURIComponent(detail.task.runId)}`}
|
||||
@ -992,6 +1077,28 @@ export default function AnnotationOperations() {
|
||||
: "审核"}{" "}
|
||||
· Revision {detail.task.currentRevision}
|
||||
</div>
|
||||
{selectedHumanItem &&
|
||||
!selectedHumanItem.assignedUserId &&
|
||||
["ready", "rework", "submitted"].includes(selectedHumanItem.status) ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void claimSelectedTask()}
|
||||
disabled={saving}
|
||||
className="rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||||
>
|
||||
领取任务
|
||||
</button>
|
||||
) : null}
|
||||
{selectedHumanItem && selectedClaimedByMe && selectedHumanItem.assignedUserId ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void releaseSelectedTask()}
|
||||
disabled={saving}
|
||||
className="rounded-lg border border-amber-500/40 px-4 py-2 text-sm text-amber-200 disabled:opacity-50"
|
||||
>
|
||||
释放任务
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{workspaceMode === "annotate" && annotationStage === "split_annotation" ? (
|
||||
@ -1006,7 +1113,7 @@ export default function AnnotationOperations() {
|
||||
<div>
|
||||
<div className="font-medium text-white">切片边界校正</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
调整边界、拆分、合并或删除错误切片,提交后由同一标注员继续语义标注。
|
||||
调整边界、拆分、合并或删除错误切片;提交后语义标注阶段重新进入待领取池。
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
@ -1195,7 +1302,7 @@ export default function AnnotationOperations() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void submitSliceRevision()}
|
||||
disabled={saving || sliceSegments.length === 0}
|
||||
disabled={saving || sliceSegments.length === 0 || !selectedClaimedByMe}
|
||||
className="inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||||
>
|
||||
<Scissors className="h-4 w-4" /> 提交切片校正
|
||||
@ -1204,7 +1311,7 @@ export default function AnnotationOperations() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void submitRevision()}
|
||||
disabled={saving || segments.length === 0}
|
||||
disabled={saving || segments.length === 0 || !selectedClaimedByMe}
|
||||
className="inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||||
>
|
||||
<Send className="h-4 w-4" /> 提交语义标注
|
||||
@ -1215,7 +1322,7 @@ export default function AnnotationOperations() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void rejectAnnotationInput()}
|
||||
disabled={saving}
|
||||
disabled={saving || !selectedClaimedByMe}
|
||||
className="inline-flex items-center gap-2 rounded-lg border border-red-500/40 px-4 py-2 text-sm text-red-200 disabled:opacity-50"
|
||||
>
|
||||
<XCircle className="h-4 w-4" />
|
||||
@ -1227,6 +1334,7 @@ export default function AnnotationOperations() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void review("quality", "approved")}
|
||||
disabled={saving || !selectedClaimedByMe}
|
||||
className="inline-flex items-center gap-2 rounded-lg bg-emerald-600 px-4 py-2 text-sm text-white"
|
||||
>
|
||||
<CheckCircle2 className="h-4 w-4" />
|
||||
@ -1235,6 +1343,7 @@ export default function AnnotationOperations() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void review("quality", "rejected")}
|
||||
disabled={saving || !selectedClaimedByMe}
|
||||
className="inline-flex items-center gap-2 rounded-lg bg-red-600 px-4 py-2 text-sm text-white"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
@ -1442,6 +1551,7 @@ export default function AnnotationOperations() {
|
||||
<option value="annotator">标注员</option>
|
||||
<option value="quality_reviewer">质检员</option>
|
||||
<option value="acceptance_reviewer">验收员</option>
|
||||
<option value="vendor_manager">供应商管理员</option>
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@ -20,7 +20,13 @@ import { useTimeZone } from "../context/TimeZoneContext";
|
||||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||||
import { formatCompactDateTime } from "../lib/datetime";
|
||||
import { cn } from "../lib/utils";
|
||||
import type { DashboardGate, DashboardSummary, ExecutionData, ExecutionRunSummary } from "../types";
|
||||
import type {
|
||||
DashboardGate,
|
||||
DashboardSummary,
|
||||
DashboardWorkforceMetric,
|
||||
ExecutionData,
|
||||
ExecutionRunSummary,
|
||||
} from "../types";
|
||||
|
||||
type WorkbenchState = {
|
||||
running: ExecutionRunSummary[];
|
||||
@ -31,6 +37,69 @@ type WorkbenchState = {
|
||||
|
||||
const emptyWorkbench: WorkbenchState = { running: [], failed: [], waitingForAudit: [], recentArtifacts: [] };
|
||||
|
||||
const formatRate = (value: number | null | undefined) => (value == null ? "--" : `${value.toFixed(1)}%`);
|
||||
|
||||
function WorkforceSummaryPanel({ summary }: { summary: DashboardSummary | null }) {
|
||||
const workforce = summary?.workforce;
|
||||
const totals = workforce?.totals;
|
||||
const cards: Array<[string, string | number]> = [
|
||||
["正式产出", totals?.outputCount ?? 0],
|
||||
["返工率", formatRate(totals?.reworkRate)],
|
||||
["质检通过率", formatRate(totals?.qualityPassRate)],
|
||||
["验收通过率", formatRate(totals?.acceptancePassRate)],
|
||||
];
|
||||
return (
|
||||
<section className="space-y-4">
|
||||
<div>
|
||||
<h2 className="text-xl font-bold text-white">
|
||||
{summary?.audienceScope === "vendor"
|
||||
? "供应商团队工作量与质量"
|
||||
: summary?.audienceScope === "self"
|
||||
? "我的工作量与质量"
|
||||
: "供应商产出与质量"}
|
||||
</h2>
|
||||
<p className="mt-1 text-sm text-gray-500">
|
||||
统计区间:{workforce?.from || "--"} 至 {workforce?.to || "--"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
||||
{cards.map(([label, value]) => (
|
||||
<div key={label} className="rounded-xl border border-[#2a2b2f] bg-[#151619] p-4">
|
||||
<div className="text-xs text-gray-500">{label}</div>
|
||||
<div className="mt-2 text-2xl font-semibold text-white">{value}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="overflow-hidden rounded-xl border border-[#2a2b2f] bg-[#151619]">
|
||||
<div className="grid grid-cols-[1.2fr_1fr_repeat(4,0.8fr)] gap-3 border-b border-[#2a2b2f] px-4 py-3 text-xs text-gray-500">
|
||||
<span>成员</span>
|
||||
<span>供应商</span>
|
||||
<span>产出</span>
|
||||
<span>返工率</span>
|
||||
<span>质检</span>
|
||||
<span>验收</span>
|
||||
</div>
|
||||
{(workforce?.items || []).map((item: DashboardWorkforceMetric, index) => (
|
||||
<div
|
||||
key={`${item.userId}-${item.vendorId}-${item.workgroupId}-${index}`}
|
||||
className="grid grid-cols-[1.2fr_1fr_repeat(4,0.8fr)] gap-3 border-b border-[#202227] px-4 py-3 text-sm text-gray-300"
|
||||
>
|
||||
<span>{item.userName || item.userId || "系统"}</span>
|
||||
<span>{item.vendorId || "--"}</span>
|
||||
<span>{item.outputCount}</span>
|
||||
<span>{formatRate(item.reworkRate)}</span>
|
||||
<span>{formatRate(item.qualityPassRate)}</span>
|
||||
<span>{formatRate(item.acceptancePassRate)}</span>
|
||||
</div>
|
||||
))}
|
||||
{!workforce?.items?.length ? (
|
||||
<div className="px-4 py-10 text-center text-sm text-gray-500">当前统计区间暂无工作量事件</div>
|
||||
) : null}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
const gateTone = (status?: string) =>
|
||||
status === "passed" || status === "ready"
|
||||
? "border-green-500/20 bg-green-500/10 text-green-200"
|
||||
@ -69,6 +138,11 @@ export default function Dashboard() {
|
||||
}, []);
|
||||
|
||||
const loadWorkbench = useCallback(() => {
|
||||
if (currentUser?.role !== "admin") {
|
||||
setWorkbench(emptyWorkbench);
|
||||
setWorkbenchError("");
|
||||
return;
|
||||
}
|
||||
setWorkbenchError("");
|
||||
Promise.all([
|
||||
monitoringApi.listRuns({ limit: 5, status: "running" }),
|
||||
@ -103,7 +177,7 @@ export default function Dashboard() {
|
||||
console.error("Failed to load dashboard workbench", error);
|
||||
setWorkbenchError(getActionErrorMessage(error, "加载任务工作台失败"));
|
||||
});
|
||||
}, []);
|
||||
}, [currentUser?.role]);
|
||||
|
||||
const loadServices = useCallback(async () => {
|
||||
const [api, worker] = await Promise.allSettled([
|
||||
@ -121,8 +195,8 @@ export default function Dashboard() {
|
||||
useEffect(() => {
|
||||
loadSummary();
|
||||
loadWorkbench();
|
||||
void loadServices();
|
||||
}, [loadSummary, loadWorkbench, loadServices]);
|
||||
if (currentUser?.role === "admin") void loadServices();
|
||||
}, [currentUser?.role, loadSummary, loadWorkbench, loadServices]);
|
||||
|
||||
const staleAuditRuns = workbench.waitingForAudit.filter(
|
||||
(run) => Date.now() - new Date(run.createdAt).getTime() >= 24 * 60 * 60 * 1000,
|
||||
@ -147,6 +221,27 @@ export default function Dashboard() {
|
||||
};
|
||||
|
||||
const poc = summary?.poc;
|
||||
if (currentUser && currentUser.role !== "admin") {
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight text-white">Drobodata 仪表盘</h1>
|
||||
<p className="mt-1 text-gray-500">欢迎回来,{currentUser.name}。这里只展示你的授权工作量与质量范围。</p>
|
||||
</div>
|
||||
{errorMessage ? (
|
||||
<div className="rounded-xl border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-200">
|
||||
{errorMessage}
|
||||
</div>
|
||||
) : null}
|
||||
{loading && !summary ? (
|
||||
<div className="rounded-xl border border-[#2a2b2f] bg-[#151619] px-4 py-3 text-sm text-gray-400">
|
||||
正在加载工作量与质量...
|
||||
</div>
|
||||
) : null}
|
||||
<WorkforceSummaryPanel summary={summary} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const readinessGates: { title: string; gate: DashboardGate }[] = [
|
||||
{
|
||||
title: "服务可用性",
|
||||
@ -328,6 +423,8 @@ export default function Dashboard() {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<WorkforceSummaryPanel summary={summary} />
|
||||
|
||||
<section className="space-y-4">
|
||||
<div className="flex flex-wrap items-end justify-between gap-3">
|
||||
<div>
|
||||
|
||||
@ -379,6 +379,7 @@ export default function Users() {
|
||||
<option value="annotator">标注员</option>
|
||||
<option value="quality_reviewer">质检员</option>
|
||||
<option value="acceptance_reviewer">验收员</option>
|
||||
<option value="vendor_manager">供应商管理员</option>
|
||||
</select>
|
||||
</div>
|
||||
<button
|
||||
|
||||
@ -7734,6 +7734,14 @@ export default function WorkflowEditor() {
|
||||
[input.id]: { ...draft, ...patch },
|
||||
}));
|
||||
const usesInline = input.type === "json" && draft.mode === "inline";
|
||||
let includeHandpose = false;
|
||||
if (input.id === "deliveryOptions" && usesInline) {
|
||||
try {
|
||||
includeHandpose = Boolean(JSON.parse(draft.inlineText || "{}").includeHandpose);
|
||||
} catch {
|
||||
includeHandpose = false;
|
||||
}
|
||||
}
|
||||
return (
|
||||
<section key={input.id} className="space-y-3 rounded-xl border border-[#2a2b2f] bg-[#0a0a0a] p-4">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
@ -7761,13 +7769,47 @@ export default function WorkflowEditor() {
|
||||
)}
|
||||
</div>
|
||||
{usesInline ? (
|
||||
<textarea
|
||||
rows={6}
|
||||
value={draft.inlineText}
|
||||
onChange={(event) => updateDraft({ inlineText: event.target.value })}
|
||||
placeholder='{"key":"value"}'
|
||||
className="w-full resize-y rounded border border-[#2a2b2f] bg-[#111214] px-3 py-2 font-mono text-xs text-gray-200 outline-none focus:border-blue-500"
|
||||
/>
|
||||
<div className="space-y-3">
|
||||
{input.id === "deliveryOptions" ? (
|
||||
<label className="flex cursor-pointer items-center justify-between rounded-lg border border-blue-500/20 bg-blue-500/10 px-3 py-3">
|
||||
<span>
|
||||
<span className="block text-xs font-medium text-blue-100">包含 Handpose 交付</span>
|
||||
<span className="mt-1 block text-[10px] text-blue-200/60">
|
||||
关闭时不调用 WiLoR,Headpose 仍为必选交付项。
|
||||
</span>
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={includeHandpose}
|
||||
onChange={(event) => {
|
||||
let current: Record<string, unknown> = {};
|
||||
try {
|
||||
const parsed = JSON.parse(draft.inlineText || "{}");
|
||||
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
||||
current = parsed;
|
||||
} catch {
|
||||
current = {};
|
||||
}
|
||||
updateDraft({
|
||||
inlineText: JSON.stringify(
|
||||
{ ...current, includeHandpose: event.target.checked },
|
||||
null,
|
||||
2,
|
||||
),
|
||||
});
|
||||
}}
|
||||
className="h-4 w-4 accent-blue-500"
|
||||
/>
|
||||
</label>
|
||||
) : null}
|
||||
<textarea
|
||||
rows={6}
|
||||
value={draft.inlineText}
|
||||
onChange={(event) => updateDraft({ inlineText: event.target.value })}
|
||||
placeholder='{"key":"value"}'
|
||||
className="w-full resize-y rounded border border-[#2a2b2f] bg-[#111214] px-3 py-2 font-mono text-xs text-gray-200 outline-none focus:border-blue-500"
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<select
|
||||
|
||||
@ -14,6 +14,18 @@ export const deliveryPackagesApi = {
|
||||
list: async (filters: { projectId?: string; workflowId?: string; status?: DeliveryPackage["status"] } = {}) =>
|
||||
(await apiRequest<{ items: DeliveryPackage[] }>(`/api/delivery-packages${packageQuery(filters)}`)).items,
|
||||
get: (id: string) => apiRequest<DeliveryPackage>(`/api/delivery-packages/${encodeURIComponent(id)}`),
|
||||
claim: (id: string, version: number) =>
|
||||
apiRequest<DeliveryPackage>(
|
||||
`/api/delivery-packages/${encodeURIComponent(id)}/claim`,
|
||||
{ method: "POST" },
|
||||
{ version },
|
||||
),
|
||||
release: (id: string, version: number) =>
|
||||
apiRequest<DeliveryPackage>(
|
||||
`/api/delivery-packages/${encodeURIComponent(id)}/release`,
|
||||
{ method: "POST" },
|
||||
{ version },
|
||||
),
|
||||
decide: (
|
||||
id: string,
|
||||
payload: {
|
||||
|
||||
@ -9,6 +9,7 @@ type HumanItemFilters = {
|
||||
runId?: string;
|
||||
stageId?: string;
|
||||
status?: HumanItemStatus;
|
||||
pool?: "available" | "mine" | "all";
|
||||
};
|
||||
|
||||
const queryString = (filters: Record<string, string | undefined>) => {
|
||||
@ -26,6 +27,8 @@ export const humanLoopApi = {
|
||||
getItem: (id: string) => apiRequest<{ item: HumanItem }>(`/api/human-items/${encodeURIComponent(id)}`),
|
||||
claim: (id: string, version: number) =>
|
||||
apiRequest<HumanItem>(`/api/human-items/${encodeURIComponent(id)}/claim`, { method: "POST" }, { version }),
|
||||
release: (id: string, version: number) =>
|
||||
apiRequest<HumanItem>(`/api/human-items/${encodeURIComponent(id)}/release`, { method: "POST" }, { version }),
|
||||
decide: (
|
||||
id: string,
|
||||
payload: {
|
||||
|
||||
37
src/types.ts
37
src/types.ts
@ -5,6 +5,7 @@ export type UserRole =
|
||||
| "annotator"
|
||||
| "quality_reviewer"
|
||||
| "acceptance_reviewer"
|
||||
| "supplier_manager"
|
||||
| "pipeline_engineer"
|
||||
| "data_operator"
|
||||
| "qa_reviewer"
|
||||
@ -691,6 +692,13 @@ export interface DashboardPOCReadiness {
|
||||
}
|
||||
|
||||
export interface DashboardSummary {
|
||||
audienceScope: "platform" | "vendor" | "self";
|
||||
workforce: {
|
||||
from?: string;
|
||||
to?: string;
|
||||
totals: DashboardWorkforceMetric;
|
||||
items: DashboardWorkforceMetric[];
|
||||
};
|
||||
projects: {
|
||||
active: number;
|
||||
archived: number;
|
||||
@ -729,6 +737,24 @@ export interface DashboardSummary {
|
||||
poc: DashboardPOCReadiness;
|
||||
}
|
||||
|
||||
export interface DashboardWorkforceMetric {
|
||||
userId?: string;
|
||||
userName?: string;
|
||||
vendorId?: string;
|
||||
workgroupId?: string;
|
||||
outputCount: number;
|
||||
submittedCount: number;
|
||||
reworkCount: number;
|
||||
durationSeconds: number;
|
||||
qualityApproved: number;
|
||||
qualityRejected: number;
|
||||
acceptanceApproved: number;
|
||||
acceptanceRejected: number;
|
||||
qualityPassRate: number | null;
|
||||
acceptancePassRate: number | null;
|
||||
reworkRate: number | null;
|
||||
}
|
||||
|
||||
export interface LogEntry {
|
||||
timestamp: string;
|
||||
level: "INFO" | "WARN" | "ERROR" | "DEBUG";
|
||||
@ -1447,7 +1473,7 @@ export interface AuditTask {
|
||||
};
|
||||
}
|
||||
|
||||
export type AnnotationAssignmentRole = "annotator" | "quality_reviewer" | "acceptance_reviewer";
|
||||
export type AnnotationAssignmentRole = "annotator" | "quality_reviewer" | "acceptance_reviewer" | "vendor_manager";
|
||||
export type AnnotationTaskStatus =
|
||||
| "pending_annotation"
|
||||
| "pending_quality"
|
||||
@ -1709,15 +1735,24 @@ export interface DeliveryPackage {
|
||||
organizationId: string;
|
||||
projectId: string;
|
||||
workflowId: string;
|
||||
workgroupId?: string;
|
||||
vendorId?: string;
|
||||
parentRunId: string;
|
||||
childRunId: string;
|
||||
releasePartitionId: string;
|
||||
manifestDigest: string;
|
||||
itemIds: string[];
|
||||
artifactIds?: string[];
|
||||
headposeArtifactIds?: string[];
|
||||
handposeArtifactIds?: string[];
|
||||
qualitySummary?: Record<string, unknown>;
|
||||
status: "building" | "pending_acceptance" | "accepted" | "rejected" | "failed";
|
||||
acceptanceHumanItemId?: string;
|
||||
acceptanceHumanItemVersion?: number;
|
||||
assignedUserId?: string;
|
||||
claimedAt?: string;
|
||||
finalExportArtifactIds?: string[];
|
||||
finalExportedAt?: string;
|
||||
version: number;
|
||||
acceptanceReviews?: Array<{
|
||||
id: string;
|
||||
|
||||
@ -153,7 +153,7 @@ def test_poc_kaniko_build_requires_explicit_images_or_registry_configuration(tmp
|
||||
assert not calls_path.exists()
|
||||
|
||||
|
||||
def test_poc_kaniko_build_creates_four_jobs_with_registry_mirror(tmp_path):
|
||||
def test_poc_kaniko_build_creates_five_jobs_with_registry_mirror(tmp_path):
|
||||
result, calls_path, applied_dir = run_script(
|
||||
tmp_path,
|
||||
{
|
||||
@ -176,11 +176,11 @@ def test_poc_kaniko_build_creates_four_jobs_with_registry_mirror(tmp_path):
|
||||
assert "OPERATOR_RUNNER_IMAGE=registry.example.com/dataflow-poc/droboticflow-operator-runner:ce9b6a1-poc-20260623135924" in result.stdout
|
||||
|
||||
calls = calls_path.read_text(encoding="utf-8")
|
||||
assert "-n droboticflow exec -i droboticflow-api-test -- tar -xf - -C /workspace/system/builds/contexts/droboticflow-ce9b6a1-poc-20260623135924" in calls
|
||||
assert calls.count("wait --for=condition=complete") == 4
|
||||
assert "-n droboticflow exec -i droboticflow-api-test -- tar -m -xf - -C /workspace/system/builds/contexts/droboticflow-ce9b6a1-poc-20260623135924" in calls
|
||||
assert calls.count("wait --for=condition=complete") == 5
|
||||
|
||||
manifests = "\n---\n".join(path.read_text(encoding="utf-8") for path in sorted(applied_dir.glob("*.yaml")))
|
||||
assert manifests.count("kind: Job") == 4
|
||||
assert manifests.count("kind: Job") == 5
|
||||
assert "--build-arg=GOPROXY=https://goproxy.cn,direct" in manifests
|
||||
assert "--build-arg=DROBOTICFLOW_BUILD_COMMIT=0123456789abcdef" in manifests
|
||||
assert "--build-arg=DROBOTICFLOW_BUILD_TIME=2026-07-10T10:30:00Z" in manifests
|
||||
@ -190,8 +190,9 @@ def test_poc_kaniko_build_creates_four_jobs_with_registry_mirror(tmp_path):
|
||||
assert "Dockerfile.worker" in manifests
|
||||
assert "Dockerfile.drosync-coordinator" in manifests
|
||||
assert "Dockerfile.operator-runner" in manifests
|
||||
assert "Dockerfile.headpose-service" in manifests
|
||||
assert "secretName: droboticflow-registry" in manifests
|
||||
assert manifests.count("nodeName: worker-cpu-01") == 4
|
||||
assert manifests.count("nodeName: worker-cpu-01") == 5
|
||||
|
||||
|
||||
def test_poc_kaniko_build_can_create_builtin_operator_image_jobs(tmp_path):
|
||||
@ -213,7 +214,7 @@ def test_poc_kaniko_build_can_create_builtin_operator_image_jobs(tmp_path):
|
||||
|
||||
calls = calls_path.read_text(encoding="utf-8")
|
||||
operator_count = len(json.loads(OPERATOR_IMAGE_MANIFEST.read_text(encoding="utf-8"))["items"])
|
||||
expected_job_count = operator_count + 3 + 4 # builtin images + base images + platform images
|
||||
expected_job_count = operator_count + 3 + 5 # builtin images + base images + platform/service images
|
||||
assert calls.count("wait --for=condition=complete") == expected_job_count
|
||||
|
||||
manifests = "\n---\n".join(path.read_text(encoding="utf-8") for path in sorted(applied_dir.glob("*.yaml")))
|
||||
@ -289,7 +290,7 @@ def test_poc_kaniko_build_retries_platform_image_jobs(tmp_path):
|
||||
worker_job = "droboticflow-kaniko-worker-ce9b6a1-poc-20260623135924"
|
||||
assert calls.count(f"delete job {worker_job} --ignore-not-found=true") == 2
|
||||
assert calls.count(f"wait --for=condition=complete job/{worker_job} --timeout=5s") == 2
|
||||
assert len(list(applied_dir.glob("*.yaml"))) == 5
|
||||
assert len(list(applied_dir.glob("*.yaml"))) == 6
|
||||
|
||||
|
||||
def test_poc_kaniko_build_cleans_uploaded_context_when_job_fails(tmp_path):
|
||||
|
||||
@ -248,7 +248,7 @@ def test_deploy_derives_images_from_explicit_registry_configuration(tmp_path):
|
||||
assert result.returncode == 0, result.stderr + result.stdout
|
||||
calls = calls_path.read_text(encoding="utf-8")
|
||||
assert "apply --dry-run=client -f" in calls
|
||||
assert "-n droboticflow-test get pods -l app in (droboticflow-api,droboticflow-worker)" in calls
|
||||
assert "-n droboticflow-test get pods -l app in (droboticflow-api,droboticflow-worker,droboticflow-headpose)" in calls
|
||||
assert "\n-n droboticflow-test get pods\n" not in calls
|
||||
|
||||
|
||||
|
||||
106
tests/backend/test_delivery_pose_contracts.py
Normal file
106
tests/backend/test_delivery_pose_contracts.py
Normal file
@ -0,0 +1,106 @@
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.operators.builtin.delivery_options import operator as delivery_options
|
||||
from backend.operators.builtin.head_pose import operator as head_pose
|
||||
from backend.operators.builtin.package import operator as package_operator
|
||||
from backend.operators.builtin.wilor_hand_pose import operator as wilor
|
||||
|
||||
|
||||
def helpers(params=None, payloads=None):
|
||||
params = params or {}
|
||||
payloads = payloads or []
|
||||
|
||||
def write_json(run_id, node_id, output_dir, name, data, output=None):
|
||||
pathlib.Path(output_dir).mkdir(parents=True, exist_ok=True)
|
||||
return {"name": name, "data": data, "path": str(pathlib.Path(output_dir) / name)}
|
||||
|
||||
return {
|
||||
"hyperparams": lambda node_data: params,
|
||||
"payloads_from_inputs": lambda inputs: payloads,
|
||||
"output_binding": lambda node_data: None,
|
||||
"write_json_artifact": write_json,
|
||||
"first_payload_with_keys": lambda inputs, *keys: None,
|
||||
"collect_output_artifacts": lambda run_id, node_id, output_dir, **kwargs: [
|
||||
{"name": path.name, "path": str(path)} for path in pathlib.Path(output_dir).iterdir() if path.is_file()
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_delivery_options_defaults_handpose_off(tmp_path):
|
||||
artifacts = delivery_options.run("run", "node", tmp_path, {}, [], helpers(payloads=[{}]))
|
||||
assert artifacts[0]["data"] == {
|
||||
"schemaVersion": "droboticflow.delivery-options/v1",
|
||||
"includeHeadpose": True,
|
||||
"includeHandpose": False,
|
||||
}
|
||||
|
||||
|
||||
def test_wilor_disabled_does_not_resolve_media_or_call_service(tmp_path):
|
||||
artifacts = wilor.run(
|
||||
"run",
|
||||
"node",
|
||||
tmp_path,
|
||||
{},
|
||||
[],
|
||||
helpers(payloads=[{"schemaVersion": "droboticflow.delivery-options/v1", "includeHandpose": False}]),
|
||||
)
|
||||
assert artifacts[0]["data"]["enabled"] is False
|
||||
assert artifacts[0]["data"]["status"] == "skipped_by_delivery_options"
|
||||
|
||||
|
||||
def test_headpose_requires_real_service_metadata_and_validates_frames(tmp_path, monkeypatch):
|
||||
annotated = tmp_path / "annotated.mp4"
|
||||
annotated.write_bytes(b"real-annotated-video")
|
||||
monkeypatch.setattr(
|
||||
head_pose,
|
||||
"_post_json",
|
||||
lambda url, payload, timeout: {
|
||||
"frames": [
|
||||
{
|
||||
"frameIndex": 3,
|
||||
"timestampSeconds": 0.1,
|
||||
"yawDeg": 1.0,
|
||||
"pitchDeg": 2.0,
|
||||
"rollDeg": 3.0,
|
||||
"confidence": 0.9,
|
||||
}
|
||||
],
|
||||
"annotatedMediaUrl": str(annotated),
|
||||
"runtimeEvidence": {"gpu": "A800", "modelSha256": "sha256:" + "b" * 64},
|
||||
},
|
||||
)
|
||||
artifacts = head_pose.run(
|
||||
"run",
|
||||
"node",
|
||||
tmp_path,
|
||||
{},
|
||||
[{"previewURL": "https://example.test/input.mp4"}],
|
||||
helpers(
|
||||
params={
|
||||
"HEADPOSE_API_BASE_URL": "https://headpose.example.test",
|
||||
"HEADPOSE_SERVICE_IMAGE_ID": "registry/headpose@sha256:" + "a" * 64,
|
||||
"HEADPOSE_MODEL_SHA256": "sha256:" + "b" * 64,
|
||||
"HEADPOSE_LICENSE_ID": "MIT",
|
||||
}
|
||||
),
|
||||
)
|
||||
manifest = artifacts[0]["data"]
|
||||
assert manifest["schemaVersion"] == "droboticflow.headpose/v1"
|
||||
assert manifest["frames"][0]["yawDeg"] == 1.0
|
||||
assert manifest["frames"][0]["timestamp"] == 0.1
|
||||
assert manifest["summary"]["yawDeg"]["mean"] == 1.0
|
||||
assert artifacts[1]["name"] == "headpose-annotated.mp4"
|
||||
|
||||
|
||||
def test_package_v3_rejects_missing_required_headpose(tmp_path):
|
||||
with pytest.raises(RuntimeError, match="headpose"):
|
||||
package_operator.run(
|
||||
"run",
|
||||
"node",
|
||||
tmp_path,
|
||||
{},
|
||||
[],
|
||||
helpers(params={"REQUIRE_HEADPOSE": "true"}, payloads=[]),
|
||||
)
|
||||
38
tests/frontend/fanyu-comment-followup.test.mjs
Normal file
38
tests/frontend/fanyu-comment-followup.test.mjs
Normal file
@ -0,0 +1,38 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import test from "node:test";
|
||||
|
||||
const annotationURL = new URL("../../src/pages/AnnotationOperations.tsx", import.meta.url);
|
||||
const dashboardURL = new URL("../../src/pages/Dashboard.tsx", import.meta.url);
|
||||
const sidebarURL = new URL("../../src/components/Sidebar.tsx", import.meta.url);
|
||||
const workflowEditorURL = new URL("../../src/pages/WorkflowEditor.tsx", import.meta.url);
|
||||
|
||||
test("human work uses claim and release pools without manual assignment", async () => {
|
||||
const source = await readFile(annotationURL, "utf8");
|
||||
assert.match(source, /humanLoopApi\.claim/);
|
||||
assert.match(source, /humanLoopApi\.release/);
|
||||
assert.match(source, /领取任务/);
|
||||
assert.match(source, /不指定人员、不发送推送/);
|
||||
assert.doesNotMatch(source, /暂不指定标注员/);
|
||||
});
|
||||
|
||||
test("dashboard renders platform vendor and self workforce scopes", async () => {
|
||||
const source = await readFile(dashboardURL, "utf8");
|
||||
assert.match(source, /供应商团队工作量与质量/);
|
||||
assert.match(source, /我的工作量与质量/);
|
||||
assert.match(source, /WorkforceSummaryPanel/);
|
||||
assert.match(source, /currentUser\.role !== "admin"/);
|
||||
});
|
||||
|
||||
test("supplier managers see the dashboard but not monitoring navigation", async () => {
|
||||
const source = await readFile(sidebarURL, "utf8");
|
||||
assert.match(source, /supplier_manager/);
|
||||
assert.doesNotMatch(source, /执行监控/);
|
||||
});
|
||||
|
||||
test("workflow run input renders a per-run Handpose switch", async () => {
|
||||
const source = await readFile(workflowEditorURL, "utf8");
|
||||
assert.match(source, /input\.id === "deliveryOptions"/);
|
||||
assert.match(source, /包含 Handpose 交付/);
|
||||
assert.match(source, /includeHandpose: event\.target\.checked/);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user