droboticflow/internal/api/fanyu_template.go

1538 lines
98 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package api
import (
"context"
"fmt"
"os"
"sort"
"strings"
"droboticflow/internal/domain"
pluginregistry "droboticflow/internal/plugins"
)
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"
const fanyuDeliveryTemplateV4ID = "template-fanyu-right-camera-delivery-v4"
const fanyuDeliveryTemplateV5ID = "template-fanyu-left-camera-delivery-v5"
const fanyuDeliveryTemplateV54ID = "template-fanyu-left-camera-delivery-v5-4"
const fanyuDeliveryTemplateV55ID = "template-fanyu-left-camera-delivery-v5-5"
const fanyuDeliveryTemplateV56ID = "template-fanyu-stereo-pose-delivery-v5-6"
const fanyuDeliveryTemplateV57ID = "template-fanyu-stereo-prelabel-delivery-v5-7"
const fanyuDeliveryTemplateV58ID = "template-fanyu-stereo-synchronized-delivery-v5-8"
const fanyuV58QwenImage = "ccr-29eug8s3-vpc.cnc.bj.baidubce.com/fanyu/droboticflow-operator-qwen-behavior-rough-cut:c9ac1b05-fanyu-0911"
const fanyuV58QwenImageID = "ccr-29eug8s3-vpc.cnc.bj.baidubce.com/fanyu/droboticflow-operator-qwen-behavior-rough-cut@sha256:772f324e60015c2fb8a20158762275077aa4f5a0ca92fb6d600189d8538db2c3"
const fanyuV58PackageImage = "ccr-29eug8s3-vpc.cnc.bj.baidubce.com/fanyu/droboticflow-operator-package:faeeb103-unified-boundaries-0909"
const fanyuV58PackageImageID = "ccr-29eug8s3-vpc.cnc.bj.baidubce.com/fanyu/droboticflow-operator-package@sha256:73f323b774956f508b936c3a8f1f29fa54e587716e8bda595e2e570fc703cb6f"
func fanyuLegacyPorts(operatorID string, inputs []domain.PortDefinition, outputs []domain.PortDefinition) ([]domain.PortDefinition, []domain.PortDefinition) {
legacy := func(id, name string, typ domain.PortType, required bool) domain.PortDefinition {
return domain.PortDefinition{ID: id, Name: name, Type: typ, Required: required, Transmission: "bus"}
}
switch operatorID {
case "operator-builtin-directory-scan":
return []domain.PortDefinition{legacy("in-1", "input", domain.PortTypeFile, true)}, []domain.PortDefinition{legacy("out-1", "manifest", domain.PortTypeJSON, false)}
case "operator-builtin-orbbec-data-normalize":
return []domain.PortDefinition{legacy("in-1", "input", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("out-1", "dataset", domain.PortTypeJSON, false)}
case "operator-builtin-video-face-blur":
return []domain.PortDefinition{legacy("in-1", "input", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("out-1", "blurredVideo", domain.PortTypeJSON, false)}
case "operator-builtin-qwen-behavior-rough-cut":
return []domain.PortDefinition{legacy("video", "video", domain.PortTypeJSON, true), legacy("metadata", "metadata", domain.PortTypeJSON, true)}, []domain.PortDefinition{legacy("out-1", "roughCuts", domain.PortTypeJSON, false)}
case "operator-builtin-annotation-gate":
return []domain.PortDefinition{legacy("clips", "clips", domain.PortTypeJSON, false), legacy("prelabels", "prelabels", domain.PortTypeJSON, false), legacy("validEvents", "validEvents", domain.PortTypeJSON, false), legacy("headpose", "headpose", domain.PortTypeJSON, false), legacy("handpose", "handpose", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("approved", "approved", domain.PortTypeJSON, false), legacy("rejected", "rejected", domain.PortTypeJSON, false)}
case "operator-builtin-package":
return []domain.PortDefinition{legacy("in-1", "annotations", domain.PortTypeJSON, true), legacy("in-2", "headpose", domain.PortTypeJSON, false), legacy("in-3", "handpose", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("out-1", "packages", domain.PortTypeJSON, false)}
default:
return inputs, outputs
}
}
func fanyuNode(id string, label string, operator domain.OperatorRecord, x float64, y float64) domain.WorkflowNode {
cpu, memory, gpu, sharedMemory := "", "", "", ""
if operator.Resources != nil {
cpu = operator.Resources.CPULimit
memory = operator.Resources.MemoryLimit
gpu = operator.Resources.GPULimit
sharedMemory = operator.Resources.SharedMemorySize
}
inputs, outputs := fanyuLegacyPorts(operator.ID, operator.Inputs, operator.Outputs)
// fanyuNode builds the immutable v1/v2 compatibility templates. Operators
// loaded from the current catalog already carry strict modern port fields,
// but those historical graphs intentionally connected JSON manifests across
// several container shapes. Keep their copied ports legacy so the domain
// compatibility gate does not reinterpret an old edge as a newly authored
// strict multiport edge. Modern v5.x templates use fanyuMultiportNode.
inputs = append([]domain.PortDefinition(nil), inputs...)
outputs = append([]domain.PortDefinition(nil), outputs...)
for index := range inputs {
inputs[index].Container = ""
inputs[index].PayloadMode = ""
}
for index := range outputs {
outputs[index].Container = ""
outputs[index].PayloadMode = ""
}
return domain.WorkflowNode{ID: id, Type: "operator", Position: domain.Position{X: x, Y: y}, Data: domain.WorkflowNodeData{
Label: label, Category: operator.Category, Description: operator.Description, Inputs: inputs, Outputs: outputs,
OperatorID: operator.ID, OperatorVersion: operator.Version, OperatorImageID: operator.ImageID, Image: operator.Image,
ContainerCommand: operator.ContainerCommand, ContainerArgs: operator.ContainerArgs, RuntimeContract: operator.RuntimeContract,
SkillDefinition: operator.SkillDefinition, PublicationStatus: operator.PublicationStatus, GenerationSource: operator.GenerationSource,
PublicationEvidence: operator.PublicationEvidence, Hyperparams: operator.Hyperparams, CPU: cpu, Memory: memory, GPU: gpu,
SharedMemorySize: sharedMemory,
}}
}
func fanyuMultiportNode(id string, label string, operator domain.OperatorRecord, x float64, y float64) domain.WorkflowNode {
cpu, memory, gpu, sharedMemory := "", "", "", ""
if operator.Resources != nil {
cpu = operator.Resources.CPULimit
memory = operator.Resources.MemoryLimit
gpu = operator.Resources.GPULimit
sharedMemory = operator.Resources.SharedMemorySize
}
return domain.WorkflowNode{ID: id, Type: "operator", Position: domain.Position{X: x, Y: y}, Data: domain.WorkflowNodeData{
Label: label, Category: operator.Category, Description: operator.Description, Inputs: operator.Inputs, Outputs: operator.Outputs,
OperatorID: operator.ID, OperatorVersion: operator.Version, OperatorImageID: operator.ImageID, Image: operator.Image,
ContainerCommand: operator.ContainerCommand, ContainerArgs: operator.ContainerArgs, RuntimeContract: operator.RuntimeContract,
SkillDefinition: operator.SkillDefinition, PublicationStatus: operator.PublicationStatus, GenerationSource: operator.GenerationSource,
PublicationEvidence: operator.PublicationEvidence, Hyperparams: operator.Hyperparams, CPU: cpu, Memory: memory, GPU: gpu,
SharedMemorySize: sharedMemory,
}}
}
func fanyuNodeWithHyperparams(id string, label string, operator domain.OperatorRecord, x float64, y float64, overrides map[string]string) domain.WorkflowNode {
node := fanyuNode(id, label, operator, x, y)
node.Data.Hyperparams = append([]domain.HyperParam(nil), operator.Hyperparams...)
remaining := make(map[string]string, len(overrides))
for key, value := range overrides {
remaining[key] = value
}
for index := range node.Data.Hyperparams {
key := node.Data.Hyperparams[index].Key
if value, ok := remaining[key]; ok {
node.Data.Hyperparams[index].Value = value
delete(remaining, key)
}
}
keys := make([]string, 0, len(remaining))
for key := range remaining {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
node.Data.Hyperparams = append(node.Data.Hyperparams, domain.HyperParam{Key: key, Value: remaining[key]})
}
return node
}
func fanyuMultiportNodeWithHyperparams(id string, label string, operator domain.OperatorRecord, x float64, y float64, overrides map[string]string) domain.WorkflowNode {
node := fanyuMultiportNode(id, label, operator, x, y)
node.Data.Hyperparams = append([]domain.HyperParam(nil), operator.Hyperparams...)
remaining := make(map[string]string, len(overrides))
for key, value := range overrides {
remaining[key] = value
}
for index := range node.Data.Hyperparams {
key := node.Data.Hyperparams[index].Key
if value, ok := remaining[key]; ok {
node.Data.Hyperparams[index].Value = value
delete(remaining, key)
}
}
keys := make([]string, 0, len(remaining))
for key := range remaining {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
node.Data.Hyperparams = append(node.Data.Hyperparams, domain.HyperParam{Key: key, Value: remaining[key]})
}
return node
}
func fanyuRetainInputPorts(node *domain.WorkflowNode, portIDs ...string) {
if node == nil {
return
}
allowed := make(map[string]struct{}, len(portIDs))
for _, portID := range portIDs {
allowed[portID] = struct{}{}
}
inputs := make([]domain.PortDefinition, 0, len(portIDs))
for _, input := range node.Data.Inputs {
if _, ok := allowed[input.ID]; ok {
inputs = append(inputs, input)
}
}
node.Data.Inputs = inputs
}
func fanyuRetainOutputPorts(node *domain.WorkflowNode, portIDs ...string) {
if node == nil {
return
}
allowed := make(map[string]struct{}, len(portIDs))
for _, portID := range portIDs {
allowed[portID] = struct{}{}
}
outputs := make([]domain.PortDefinition, 0, len(portIDs))
for _, output := range node.Data.Outputs {
if _, ok := allowed[output.ID]; ok {
outputs = append(outputs, output)
}
}
node.Data.Outputs = outputs
}
func fanyuSetEvidenceCollectionPort(ports []domain.PortDefinition, portID string, description string) []domain.PortDefinition {
updated := append([]domain.PortDefinition(nil), ports...)
for index := range updated {
if updated[index].ID != portID {
continue
}
updated[index].Type = domain.PortTypeFile
updated[index].Container = domain.PortContainerCollection
updated[index].PayloadMode = domain.ArtifactTransferModeRef
updated[index].Role = "evidence"
updated[index].Transmission = "oss"
updated[index].Description = description
}
return updated
}
func fanyuSetRequiredPorts(ports []domain.PortDefinition, portIDs ...string) []domain.PortDefinition {
required := make(map[string]struct{}, len(portIDs))
for _, portID := range portIDs {
required[portID] = struct{}{}
}
updated := append([]domain.PortDefinition(nil), ports...)
for index := range updated {
_, ok := required[updated[index].ID]
updated[index].Required = ok
}
return updated
}
func fanyuEdge(id string, source string, sourceHandle string, target string, targetHandle string) domain.WorkflowEdge {
return domain.WorkflowEdge{ID: id, Source: source, SourceHandle: sourceHandle, Target: target, TargetHandle: targetHandle, Animated: true}
}
func fanyuUpsertHyperparam(items []domain.HyperParam, key string, value string) []domain.HyperParam {
updated := append([]domain.HyperParam(nil), items...)
for index := range updated {
if updated[index].Key == key {
updated[index].Value = value
return updated
}
}
return append(updated, domain.HyperParam{Key: key, Value: value, Type: "string"})
}
func (server *server) ensureFanyuDeliveryTemplate(ctx context.Context, organizationID string) error {
organizationID = normalizedOrganizationID(organizationID)
// Upgrade the referenced human-stage contracts before reconciling a
// workflow release. Keeping this at the end allowed the first v5.8 Run in
// a reconciliation request to observe the historical v6 four-stage
// snapshot instead of annotation_combined -> quality_review.
if err := server.ensureFanyuConvenienceStoreAnnotationTemplates(ctx, organizationID); err != nil {
return err
}
// Historical templates are bootstrap inputs, not resources that should be
// recreated after an administrator removes them from an initialized tenant.
if current, err := server.store.GetTemplate(ctx, fanyuDeliveryTemplateV58ID+"-"+organizationID); err != nil {
return err
} else if current != nil {
return server.ensureFanyuDeliveryTemplateV58(ctx, organizationID)
}
if err := server.ensureFanyuDeliveryTemplateV1(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuOrbbecDeliveryTemplateV2(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuDeliveryTemplateV3(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuDeliveryTemplateV4(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuDeliveryTemplateV5(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuDeliveryTemplateV54(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuDeliveryTemplateV55(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuDeliveryTemplateV56(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuDeliveryTemplateV57(ctx, organizationID); err != nil {
return err
}
if err := server.ensureFanyuDeliveryTemplateV58(ctx, organizationID); err != nil {
return err
}
return nil
}
func (server *server) ensureFanyuConvenienceStoreAnnotationTemplates(ctx context.Context, organizationID string) error {
organizationID = normalizedOrganizationID(organizationID)
for version := 1; version <= 6; version++ {
templateID := fmt.Sprintf("tpl-fanyu-convenience-store-v%d-%s", version, organizationID)
existing, err := server.store.GetAnnotationTemplate(ctx, templateID)
if err != nil {
return err
}
if existing == nil {
template := domain.DefaultConvenienceStoreAnnotationTemplate(organizationID, "", version)
if version == 6 {
template.HumanStages = domain.DefaultFanyuV58HumanStages()
}
now := nowISO()
template.CreatedAt = now
template.UpdatedAt = now
template.PublishedAt = now
template.PublishedByUserID = "system"
if err := server.store.UpsertAnnotationTemplate(ctx, template); err != nil {
return err
}
continue
}
if version == 6 {
if !domain.IsFanyuV58ThreeRoleHumanLoop(existing.HumanStages) {
updated := *existing
updated.HumanStages = domain.DefaultFanyuV58HumanStages()
updated.UpdatedAt = nowISO()
if err := server.store.UpsertAnnotationTemplate(ctx, updated); err != nil {
return err
}
}
// v6 is the strict v5.8 two-stage contract. Never let the generic
// v5 four-stage compatibility repair below toggle it back.
continue
}
// Early v5 POC deployments persisted a two-stage combined template
// under this system-owned ID. Upgrade only that stale stage topology;
// preserve its labels, phrases, project binding, and publication record.
if version >= 5 && !domain.IsFanyuV5FourStageHumanLoop(existing.HumanStages) {
updated := *existing
updated.HumanStages = domain.DefaultFanyuV5HumanStages()
updated.UpdatedAt = nowISO()
if err := server.store.UpsertAnnotationTemplate(ctx, updated); err != nil {
return err
}
}
}
return nil
}
// ensureFanyuDeliveryTemplateV58 publishes the confirmed three-role workflow
// and carries stereo PTS, IMU, and calibration sidecars into the final package.
// v5.7 remains immutable and readable for historical runs.
func (server *server) ensureFanyuDeliveryTemplateV58(ctx context.Context, organizationID string) error {
organizationID = normalizedOrganizationID(organizationID)
base, err := server.store.GetTemplate(ctx, fanyuDeliveryTemplateV58ID+"-"+organizationID)
if err != nil {
return err
}
if base == nil {
base, err = server.store.GetTemplate(ctx, fanyuDeliveryTemplateV57ID+"-"+organizationID)
}
if err != nil || base == nil {
return err
}
templateID := fanyuDeliveryTemplateV58ID + "-" + organizationID
releaseID := "workflow-release-fanyu-v5-8-" + organizationID
nodes := append([]domain.WorkflowNode(nil), base.Nodes...)
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v6-%s", organizationID)
for index := range nodes {
node := &nodes[index]
switch node.ID {
case "fanyu-v56-left-blur", "fanyu-v56-right-blur":
operator, operatorErr := server.store.GetOperator(ctx, "operator-builtin-video-face-blur")
if operatorErr != nil {
return operatorErr
}
if operator == nil {
return fmt.Errorf("fanyu v5.8 template requires face anonymization operator")
}
refreshed := fanyuMultiportNodeWithHyperparams(
node.ID,
node.Data.Label,
*operator,
node.Position.X,
node.Position.Y,
map[string]string{
"DETECTION_METHOD": "yunet",
"MODEL_PATH": "/app/operator-repos/builtin/video_face_blur/assets/face_detection_yunet_2023mar.onnx",
"MODEL_SHA256": "8f2383e4dd3cfbb4553ea8718107fc0423210dc964f9f4280604804ed2552fa4",
"CONFIDENCE_THRESHOLD": "0.5",
"NMS_THRESHOLD": "0.3",
"TOP_K": "5000",
"BLUR_TYPE": "mosaic",
"BLUR_EXPANSION_RATIO": "1.35",
"TRACK_HOLD_FRAMES": "4",
"TRACK_IOU_THRESHOLD": "0.2",
"PRESERVE_AUDIO": "false",
"PRESERVE_PTS": "true",
"REQUIRE_PTS": "true",
"REQUIRE_DETECTIONS": "true",
"DIAGNOSTIC_FRAME_LIMIT": "12",
"PIN_OPERATOR_IMAGE": "true",
},
)
refreshed.Data.Description = "逐帧执行 fail-closed 人脸脱敏,并输出已脱敏检测框诊断帧与结构化报告供质检定位;不保留原始人脸像素。"
fanyuRetainInputPorts(&refreshed, "videos", "timestamps")
fanyuRetainOutputPorts(&refreshed, "blurredVideos", "detectionSummary", "diagnosticFrames")
*node = refreshed
case "fanyu-v56-rough-cut":
operator, operatorErr := server.store.GetOperator(ctx, "operator-builtin-qwen-behavior-rough-cut")
if operatorErr != nil {
return operatorErr
}
if operator == nil {
return fmt.Errorf("fanyu v5.8 template requires Qwen timestamp-window operator")
}
refreshed := fanyuMultiportNodeWithHyperparams(
node.ID,
"Qwen 左相机语义粗切(仅时间窗口)",
*operator,
node.Position.X,
node.Position.Y,
map[string]string{"REQUIRE_NON_EMPTY_RESULT": "false"},
)
refreshed.Data.Hyperparams = fanyuUpsertHyperparam(refreshed.Data.Hyperparams, "TECHNICAL_BLOCK_SECONDS", "5")
refreshed.Data.Hyperparams = fanyuUpsertHyperparam(refreshed.Data.Hyperparams, "FRAMES_PER_TECHNICAL_BLOCK", "8")
refreshed.Data.Hyperparams = fanyuUpsertHyperparam(refreshed.Data.Hyperparams, "PIN_OPERATOR_IMAGE", "true")
refreshed.Data.Image = fanyuV58QwenImage
refreshed.Data.OperatorImageID = fanyuV58QwenImageID
refreshed.Data.Description = "只读取完整左目脱敏视频和绝对 PTS,输出建议的 [startTimestampUs,endTimestampUs) 窗口 JSON;不生成视频、边界集合或预标视频。"
fanyuRetainInputPorts(&refreshed, "videos", "timestamps")
fanyuRetainOutputPorts(&refreshed, "roughCutWindows")
*node = refreshed
case "fanyu-v56-headpose":
node.Data.Outputs = fanyuSetEvidenceCollectionPort(node.Data.Outputs, "out-1", "HeadPose manifest 与姿态轴渲染视频证据集合")
case "fanyu-v56-handpose":
node.Data.Hyperparams = fanyuUpsertHyperparam(node.Data.Hyperparams, "WILOR_API_BASE_URL", "http://droboticflow-wilor:8080")
node.Data.Hyperparams = fanyuUpsertHyperparam(node.Data.Hyperparams, "INPUT_URL", "")
node.Data.Hyperparams = fanyuUpsertHyperparam(node.Data.Hyperparams, "WILOR_SERVICE_IMAGE", "ccr-29eug8s3-pub.cnc.bj.baidubce.com/fanyu/droboticflow-wilor-service:f3a4957-fanyu-l20-20260826")
node.Data.Hyperparams = fanyuUpsertHyperparam(node.Data.Hyperparams, "WILOR_SERVICE_IMAGE_ID", "ccr-29eug8s3-pub.cnc.bj.baidubce.com/fanyu/droboticflow-wilor-service@sha256:be8369126716ad63ea62a93c8bc3e56425a5370cd77144e32b74254f1ff33055")
node.Data.Outputs = fanyuSetEvidenceCollectionPort(node.Data.Outputs, "out-1", "HandPose manifest、帧标注、渲染视频与诊断文件证据集合")
case "fanyu-v56-human":
// v5.7 intentionally keeps its historical human-node snapshot. v5.8
// needs the current evidence ports so HeadPose and HandPose are visible
// as inputs to aggregate acceptance instead of being misrepresented as
// approved video outputs in the child run.
operator, operatorErr := server.store.GetOperator(ctx, "operator-builtin-annotation-gate")
if operatorErr != nil {
return operatorErr
}
if operator == nil {
return fmt.Errorf("fanyu v5.8 template requires builtin annotation gate operator")
}
refreshed := fanyuMultiportNodeWithHyperparams(
node.ID,
"真实切分与语义标注→切分/标注审核→整包验收",
*operator,
node.Position.X,
node.Position.Y,
map[string]string{
"ANNOTATION_TEMPLATE_ID": annotationTemplateID,
"ANNOTATION_SUPPLIER_ID": "",
"RELEASE_POLICY": "all_accepted",
"PARTITION_MAX_ITEMS": "32",
"MAX_REWORK_ROUNDS": "5",
"REQUIRE_PREPACKAGE_ACCEPTANCE": "true",
},
)
refreshed.Data.Description = "标注员完成真实切分和语义标注;审核员统一审核;独立验收员通过独立 HeadPose/HandPose 输入证据做整包 include/exclude 决策。Pose 证据不进入 approvedVideos。"
fanyuRetainInputPorts(
&refreshed,
"fullLeftVideos",
"fullRightVideos",
"leftTimestamps",
"rightTimestamps",
"imu",
"roughCutWindows",
"headposeEvidence",
"handposeEvidence",
)
fanyuRetainOutputPorts(&refreshed, "acceptedSliceDirectory", "rejected", "acceptanceSummary")
refreshed.Data.Inputs = fanyuSetRequiredPorts(refreshed.Data.Inputs, "fullLeftVideos", "fullRightVideos", "leftTimestamps", "rightTimestamps", "imu", "roughCutWindows")
refreshed.Data.Inputs = fanyuSetEvidenceCollectionPort(refreshed.Data.Inputs, "headposeEvidence", "HeadPose manifest 与姿态轴渲染视频证据集合")
refreshed.Data.Inputs = fanyuSetEvidenceCollectionPort(refreshed.Data.Inputs, "handposeEvidence", "HandPose manifest、帧标注、渲染视频与诊断文件证据集合")
*node = refreshed
case "fanyu-v56-package":
// v5.7 intentionally carries the package port snapshot that was current
// when that historical template was created. v5.8 adds four synchronized
// sidecar inputs, so it must refresh the complete node definition from
// the currently published package operator instead of only appending
// edges to ports that may not exist in the inherited snapshot.
operator, operatorErr := server.store.GetOperator(ctx, "operator-builtin-package")
if operatorErr != nil {
return operatorErr
}
if operator == nil {
return fmt.Errorf("fanyu v5.8 template requires builtin package operator")
}
refreshed := fanyuMultiportNodeWithHyperparams(
node.ID,
"双目/PTS/IMU 同步切分与自动交付打包",
*operator,
node.Position.X,
node.Position.Y,
map[string]string{
"REQUIRE_HEADPOSE": "true",
"REQUIRE_HANDPOSE": "true",
"REQUIRE_STEREO_DELIVERY": "true",
"POSE_FREE": "false",
"REQUIRE_FINAL_ACCEPTANCE": "true",
"GENERATE_SEGMENT_MP4": "true",
"SYNCHRONIZED_SIDECARS": "true",
"ALLOW_POSE_EXCLUSION": "true",
},
)
refreshed.Data.Description = "不再执行第一次切片;只整理已验收 Revision 目录,原样复制 calibration,并按验收决定裁取或排除 Pose。"
refreshed.Data.Hyperparams = fanyuUpsertHyperparam(refreshed.Data.Hyperparams, "PIN_OPERATOR_IMAGE", "true")
refreshed.Data.Image = fanyuV58PackageImage
refreshed.Data.OperatorImageID = fanyuV58PackageImageID
fanyuRetainInputPorts(
&refreshed,
"acceptedSliceDirectory",
"acceptanceSummary",
"headpose",
"handpose",
"calibrations",
)
fanyuRetainOutputPorts(
&refreshed,
"deliveryDirectory",
"deliveryManifest",
"deliverySummary",
"deliveryPartIndex",
)
refreshed.Data.Inputs = fanyuSetRequiredPorts(refreshed.Data.Inputs, "acceptedSliceDirectory", "acceptanceSummary", "calibrations")
refreshed.Data.Inputs = fanyuSetEvidenceCollectionPort(refreshed.Data.Inputs, "headpose", "按验收策略整理的 HeadPose 证据集合")
refreshed.Data.Inputs = fanyuSetEvidenceCollectionPort(refreshed.Data.Inputs, "handpose", "按验收策略整理的 HandPose 证据集合")
*node = refreshed
}
}
edges := []domain.WorkflowEdge{
fanyuEdge("fanyu-v58-e01", "fanyu-v56-directory", "directory", "fanyu-v56-normalize", "directory"),
fanyuEdge("fanyu-v58-e02", "fanyu-v56-normalize", "leftVideos", "fanyu-v56-undistort", "leftVideos"),
fanyuEdge("fanyu-v58-e03", "fanyu-v56-normalize", "rightVideos", "fanyu-v56-undistort", "rightVideos"),
fanyuEdge("fanyu-v58-e04", "fanyu-v56-normalize", "calibrations", "fanyu-v56-undistort", "calibrations"),
fanyuEdge("fanyu-v58-e05", "fanyu-v56-undistort", "leftRectifiedVideos", "fanyu-v56-left-blur", "videos"),
fanyuEdge("fanyu-v58-e06", "fanyu-v56-undistort", "leftRectifiedTimestamps", "fanyu-v56-left-blur", "timestamps"),
fanyuEdge("fanyu-v58-e07", "fanyu-v56-undistort", "rightRectifiedVideos", "fanyu-v56-right-blur", "videos"),
fanyuEdge("fanyu-v58-e08", "fanyu-v56-undistort", "rightRectifiedTimestamps", "fanyu-v56-right-blur", "timestamps"),
fanyuEdge("fanyu-v58-e09", "fanyu-v56-left-blur", "blurredVideos", "fanyu-v56-rough-cut", "videos"),
fanyuEdge("fanyu-v58-e10", "fanyu-v56-normalize", "videoPts", "fanyu-v56-rough-cut", "timestamps"),
fanyuEdge("fanyu-v58-e11", "fanyu-v56-left-blur", "blurredVideos", "fanyu-v56-headpose", "videos"),
fanyuEdge("fanyu-v58-e12", "fanyu-v56-left-blur", "blurredVideos", "fanyu-v56-handpose", "videos"),
fanyuEdge("fanyu-v58-e13", "fanyu-v56-left-blur", "blurredVideos", "fanyu-v56-human", "fullLeftVideos"),
fanyuEdge("fanyu-v58-e14", "fanyu-v56-right-blur", "blurredVideos", "fanyu-v56-human", "fullRightVideos"),
fanyuEdge("fanyu-v58-e15", "fanyu-v56-normalize", "videoPts", "fanyu-v56-human", "leftTimestamps"),
fanyuEdge("fanyu-v58-e16", "fanyu-v56-normalize", "videoPts", "fanyu-v56-human", "rightTimestamps"),
fanyuEdge("fanyu-v58-e17", "fanyu-v56-normalize", "imu", "fanyu-v56-human", "imu"),
fanyuEdge("fanyu-v58-e18", "fanyu-v56-rough-cut", "roughCutWindows", "fanyu-v56-human", "roughCutWindows"),
fanyuEdge("fanyu-v58-e19", "fanyu-v56-headpose", "out-1", "fanyu-v56-human", "headposeEvidence"),
fanyuEdge("fanyu-v58-e20", "fanyu-v56-handpose", "out-1", "fanyu-v56-human", "handposeEvidence"),
fanyuEdge("fanyu-v58-e21", "fanyu-v56-human", "acceptedSliceDirectory", "fanyu-v56-package", "acceptedSliceDirectory"),
fanyuEdge("fanyu-v58-e22", "fanyu-v56-human", "acceptanceSummary", "fanyu-v56-package", "acceptanceSummary"),
fanyuEdge("fanyu-v58-e23", "fanyu-v56-normalize", "calibrations", "fanyu-v56-package", "calibrations"),
fanyuEdge("fanyu-v58-e24", "fanyu-v56-headpose", "out-1", "fanyu-v56-package", "headpose"),
fanyuEdge("fanyu-v58-e25", "fanyu-v56-handpose", "out-1", "fanyu-v56-package", "handpose"),
}
now := nowISO()
createdAt := now
if existing, existingErr := server.store.GetTemplate(ctx, templateID); existingErr != nil {
return existingErr
} else if existing != nil && strings.TrimSpace(existing.CreatedAt) != "" {
createdAt = existing.CreatedAt
}
template := domain.TemplateRecord{
ID: templateID, OrganizationID: organizationID, Name: "01-双目/PTS/IMU 同步切分交付-v5.8",
Description: "双目去畸变与脱敏、Qwen 仅给出绝对时间窗口、标注员提交后真实同步切片、同供应商审核、按工作流固定概率进入匿名整包验收,再由系统整理交付目录;音频不处理不交付,calibration 原样保留。",
Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindStandard, ExecutionScope: domain.WorkflowExecutionScopeProduction,
DefinitionState: domain.WorkflowDefinitionStateDraft, DefinitionVersion: 8, DefinitionFamilyID: fanyuDeliveryTemplateV5ID + "-" + organizationID, SupersedesTemplateID: fanyuDeliveryTemplateV57ID + "-" + organizationID,
MaxConcurrentRuns: domain.DefaultMaxConcurrentCaptureRuns, WorkflowInputs: append([]domain.WorkflowInputDefinition(nil), base.WorkflowInputs...), Nodes: nodes, Edges: edges, CreatedAt: createdAt, UpdatedAt: now,
}
if issues := validateWorkflowTopology(nodes, edges); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.8 template: %s", strings.TrimSpace(issues[0].Message))
}
if issues := validateWorkflowInputContract(nodes, edges, template.WorkflowInputs, true); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.8 input contract: %s", strings.TrimSpace(issues[0].Message))
}
if err := server.store.UpsertTemplate(ctx, template); err != nil {
return err
}
if _, releaseErr := server.store.GetWorkflowRelease(ctx, releaseID); releaseErr != nil {
return releaseErr
}
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
return nil
}
release := domain.WorkflowReleaseRecord{
ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 8, Name: template.Name, Description: template.Description,
Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns,
WorkflowInputs: template.WorkflowInputs, Nodes: nodes, Edges: edges,
Capabilities: []string{"directory_input", "capture_runtime_policy", "capture_probability_acceptance", "supplier_claim_binding", "stereo_opencv_undistort", "stereo_yunet_face_anonymization", "qwen3vl_timestamp_windows_only", "combined_cut_semantic_annotation", "materialize_after_annotation_submit", "combined_quality_review", "independent_full_acceptance", "stereo_pts_imu_synchronized_crop", "automatic_directory_package"},
RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template),
ReleaseNotes: "v5.8 Capture contract revision 2: two concurrent Capture Runs by default, mutable probability sampling (50% default), claim-time supplier binding, synchronized materialization, supplier quality review, anonymized platform acceptance, and audited package evidence",
PublishedByUserID: "system", PublishedAt: now, CreatedAt: now,
}
return server.store.UpsertWorkflowRelease(ctx, release)
}
// ensureFanyuDeliveryTemplateV5 adds a new immutable left-camera route and
// intentionally never mutates v1-v4. It is saved as an editable template
// until independently built images, a verified Qwen3-VL cache, and the real
// service/model provenance are configured; that fail-closed publication gate
// keeps a visual workflow from being mistaken for an executable AI pipeline.
func (server *server) ensureFanyuDeliveryTemplateV5(ctx context.Context, organizationID string) error {
templateID := fanyuDeliveryTemplateV5ID + "-" + normalizedOrganizationID(organizationID)
releaseID := "workflow-release-fanyu-v5-" + normalizedOrganizationID(organizationID)
existingRelease, err := server.store.GetWorkflowRelease(ctx, releaseID)
if err != nil {
return err
}
operatorIDs := []string{
"operator-builtin-directory-scan", "operator-builtin-orbbec-data-normalize", "operator-builtin-video-face-blur",
"operator-builtin-qwen-behavior-rough-cut", "operator-builtin-annotation-gate", "operator-builtin-package",
}
operators := map[string]domain.OperatorRecord{}
for _, operatorID := range operatorIDs {
operator, err := server.store.GetOperator(ctx, operatorID)
if err != nil {
return err
}
if operator == nil {
return fmt.Errorf("fanyu v5 template requires builtin operator %s", operatorID)
}
operators[operatorID] = *operator
}
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", normalizedOrganizationID(organizationID))
annotationSupplierID := ""
nodes := []domain.WorkflowNode{
fanyuNode("fanyu-v5-directory", "目录读取(必填)", operators[operatorIDs[0]], 0, 260),
fanyuNodeWithHyperparams("fanyu-v5-normalize", "Orbbec Ego 左相机标准化", operators[operatorIDs[1]], 240, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
fanyuNodeWithHyperparams("fanyu-v5-face-blur", "人脸脱敏(真实视频)", operators[operatorIDs[2]], 500, 260, map[string]string{"PRESERVE_AUDIO": "true", "PRESERVE_PTS": "true", "REQUIRE_DETECTIONS": "true"}),
fanyuNodeWithHyperparams("fanyu-v5-rough-cut", "Qwen3-VL 手部行为语义粗切", operators[operatorIDs[3]], 760, 260, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "18", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
fanyuNodeWithHyperparams("fanyu-v5-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认", operators[operatorIDs[4]], 1040, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_SUPPLIER_ID": annotationSupplierID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
fanyuNodeWithHyperparams("fanyu-v5-package", "人工聚合确认后打包最终 MP4、语义 JSON 与 manifest", operators[operatorIDs[5]], 1320, 260, map[string]string{"REQUIRE_HEADPOSE": "false", "POSE_FREE": "true", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
}
for nodeIndex := range nodes {
switch nodes[nodeIndex].ID {
case "fanyu-v5-package":
inputs := make([]domain.PortDefinition, 0, 1)
for _, input := range nodes[nodeIndex].Data.Inputs {
if input.ID == "in-1" {
inputs = append(inputs, input)
}
}
nodes[nodeIndex].Data.Inputs = inputs
case "fanyu-v5-human":
inputs := make([]domain.PortDefinition, 0, 1)
for _, input := range nodes[nodeIndex].Data.Inputs {
if input.ID == "clips" {
inputs = append(inputs, input)
}
}
nodes[nodeIndex].Data.Inputs = inputs
}
}
edges := []domain.WorkflowEdge{
fanyuEdge("fanyu-v5-e1", "fanyu-v5-directory", "out-1", "fanyu-v5-normalize", "in-1"),
fanyuEdge("fanyu-v5-e2", "fanyu-v5-normalize", "out-1", "fanyu-v5-face-blur", "in-1"),
fanyuEdge("fanyu-v5-e3", "fanyu-v5-face-blur", "out-1", "fanyu-v5-rough-cut", "video"),
fanyuEdge("fanyu-v5-e4", "fanyu-v5-normalize", "out-1", "fanyu-v5-rough-cut", "metadata"),
fanyuEdge("fanyu-v5-e5", "fanyu-v5-rough-cut", "out-1", "fanyu-v5-human", "clips"),
fanyuEdge("fanyu-v5-e6", "fanyu-v5-human", "approved", "fanyu-v5-package", "in-1"),
}
workflowInputs := []domain.WorkflowInputDefinition{{
ID: "sourceDirectory", Name: "sourceDirectory", Description: "本次运行要处理的 Orbbec Ego BOS 目录(必填,非增量扫描)",
Type: domain.PortTypeFile, Required: true,
Bindings: []domain.WorkflowInputTarget{{NodeID: "fanyu-v5-directory", 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-左相机切分标注质检-v5", Description: "必填目录读取、左相机标准化、人脸高斯模糊、基于真实逐帧 PTS 的 Qwen3-VL 手部行为语义粗切;随后按人工调切、剪切审核、语义标注、标注审核闭环处理,全部通过后由验收员完成人工聚合确认并直接打包最终 MP4、语义 JSON 与 manifest。不执行增量扫描、固定时长切片、200秒定位、LoRA、HeadPose 或 HandPose。", Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindStandard, 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 v5 template: %s", strings.TrimSpace(issues[0].Message))
}
if issues := validateWorkflowInputContract(nodes, edges, workflowInputs, true); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5 input contract: %s", strings.TrimSpace(issues[0].Message))
}
if err := server.store.UpsertTemplate(ctx, template); err != nil {
return err
}
// The editable template must keep following the current v5 source even
// when an older immutable release already exists. Historical releases stay
// untouched; only a new workflow/version may adopt the updated topology.
if existingRelease != nil {
return nil
}
// v5 is only released after every independent image is digest-pinned and
// every real AI dependency can be cryptographically validated. Never
// publish the visual template while any draft/pending image remains.
for _, operator := range operators {
if effectiveOperatorPublicationStatus(operator) != domain.OperatorPublicationStatusPublished || !operatorImageDigestPattern.MatchString(strings.TrimSpace(operator.ImageID)) {
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: 5, Name: template.Name, Description: template.Description, Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, Capabilities: []string{"directory_input", "qwen3vl_behavior_rough_cut", "human_cut_adjustment", "human_cut_review", "human_semantic_annotation", "human_semantic_review", "human_acceptance", "final_segment_package"}, RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template), ReleaseNotes: "Left camera v5; directory input, PTS-grounded Qwen3-VL semantic rough cut, four-stage human rework loop, aggregate confirm-only acceptance, then direct pose-free package", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now}
return server.store.UpsertWorkflowRelease(ctx, release)
}
// ensureFanyuDeliveryTemplateV54 is the multiport successor of v5. It never
// mutates the released v5.3 workflow: each business value has a named port and
// the old JSON manifests remain internal technical indexes only.
func (server *server) ensureFanyuDeliveryTemplateV54(ctx context.Context, organizationID string) error {
organizationID = normalizedOrganizationID(organizationID)
templateID := fanyuDeliveryTemplateV54ID + "-" + organizationID
releaseID := "workflow-release-fanyu-v5-4-" + organizationID
operatorIDs := []string{
"operator-builtin-directory-scan", "operator-builtin-orbbec-data-normalize", "operator-builtin-video-face-blur",
"operator-builtin-qwen-behavior-rough-cut", "operator-builtin-annotation-gate", "operator-builtin-package",
}
operators := map[string]domain.OperatorRecord{}
for _, operatorID := range operatorIDs {
operator, err := server.store.GetOperator(ctx, operatorID)
if err != nil {
return err
}
if operator == nil {
return fmt.Errorf("fanyu v5.4 template requires builtin operator %s", operatorID)
}
operators[operatorID] = *operator
}
// Older persisted builtin records may still expose the one-manifest v5
// surface while their images are being migrated. Keep v5.4 fail-closed
// until all named ports are present; v1-v5 remain usable through legacy
// adapters in the meantime.
requiredPorts := map[string][]string{
"operator-builtin-directory-scan": {"sourceDirectory", "directory", "videos", "summary"},
"operator-builtin-orbbec-data-normalize": {"directory", "leftVideos", "videoPts", "summary"},
"operator-builtin-video-face-blur": {"videos", "blurredVideos", "detectionSummary"},
"operator-builtin-qwen-behavior-rough-cut": {"videos", "timestamps", "clips", "prelabels", "boundaries", "inferenceSummary"},
"operator-builtin-annotation-gate": {"clips", "prelabels", "boundaries", "approvedVideos", "annotations", "aggregateSummary"},
"operator-builtin-package": {"approvedVideos", "annotations", "packageDirectory", "finalVideos", "deliverySummary"},
}
for operatorID, ports := range requiredPorts {
operator := operators[operatorID]
for _, portID := range ports {
if _, found := domain.FindPort(operator.Inputs, portID); !found {
if _, found := domain.FindPort(operator.Outputs, portID); !found {
return nil
}
}
}
}
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
annotationSupplierID := ""
nodes := []domain.WorkflowNode{
fanyuMultiportNode("fanyu-v54-directory", "目录读取(多端口)", operators[operatorIDs[0]], 0, 260),
fanyuMultiportNodeWithHyperparams("fanyu-v54-normalize", "Orbbec Ego 左相机标准化(多端口)", operators[operatorIDs[1]], 260, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v54-face-blur", "人脸脱敏(多端口)", operators[operatorIDs[2]], 550, 260, map[string]string{"PRESERVE_AUDIO": "true", "PRESERVE_PTS": "true", "REQUIRE_DETECTIONS": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v54-rough-cut", "Qwen3-VL 手部行为语义粗切(多端口)", operators[operatorIDs[3]], 820, 260, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "18", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v54-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认(多端口)", operators[operatorIDs[4]], 1110, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_SUPPLIER_ID": annotationSupplierID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v54-package", "人工聚合确认后打包(多端口)", operators[operatorIDs[5]], 1400, 260, map[string]string{"REQUIRE_HEADPOSE": "false", "POSE_FREE": "true", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
}
for index := range nodes {
if nodes[index].ID == "fanyu-v54-package" {
fanyuRetainInputPorts(&nodes[index], "approvedVideos", "annotations")
}
}
edges := []domain.WorkflowEdge{
fanyuEdge("fanyu-v54-e1", "fanyu-v54-directory", "directory", "fanyu-v54-normalize", "directory"),
fanyuEdge("fanyu-v54-e2", "fanyu-v54-normalize", "leftVideos", "fanyu-v54-face-blur", "videos"),
fanyuEdge("fanyu-v54-e3", "fanyu-v54-normalize", "videoPts", "fanyu-v54-face-blur", "timestamps"),
fanyuEdge("fanyu-v54-e4", "fanyu-v54-normalize", "videoPts", "fanyu-v54-rough-cut", "timestamps"),
fanyuEdge("fanyu-v54-e5", "fanyu-v54-face-blur", "blurredVideos", "fanyu-v54-rough-cut", "videos"),
fanyuEdge("fanyu-v54-e6", "fanyu-v54-rough-cut", "clips", "fanyu-v54-human", "clips"),
fanyuEdge("fanyu-v54-e7", "fanyu-v54-rough-cut", "prelabels", "fanyu-v54-human", "prelabels"),
fanyuEdge("fanyu-v54-e8", "fanyu-v54-rough-cut", "boundaries", "fanyu-v54-human", "boundaries"),
fanyuEdge("fanyu-v54-e9", "fanyu-v54-human", "approvedVideos", "fanyu-v54-package", "approvedVideos"),
fanyuEdge("fanyu-v54-e10", "fanyu-v54-human", "annotations", "fanyu-v54-package", "annotations"),
}
workflowInputs := []domain.WorkflowInputDefinition{{
ID: "sourceDirectory", Name: "sourceDirectory", Description: "本次运行要处理的 Orbbec Ego BOS 目录(必填,非增量扫描)",
Type: domain.PortTypeFile, Container: domain.PortContainerDirectory, PayloadMode: domain.ArtifactTransferModeRef, Role: "directory", Required: true,
Bindings: []domain.WorkflowInputTarget{{NodeID: "fanyu-v54-directory", TargetPortID: "sourceDirectory"}},
}}
now := nowISO()
createdAt := now
if existing, err := server.store.GetTemplate(ctx, templateID); err != nil {
return err
} else if existing != nil && strings.TrimSpace(existing.CreatedAt) != "" {
createdAt = existing.CreatedAt
}
template := domain.TemplateRecord{
ID: templateID, OrganizationID: organizationID, Name: "01-左相机多端口语义粗切标注质检-v5.4",
Description: "目录、视频、PTS、预标、边界、人工审核与交付均使用显式多端口;manifest 仅为内部技术索引。无增量扫描、固定时长切片、200秒定位、LoRA、HeadPose 或 HandPose。",
Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindStandard, ExecutionScope: domain.WorkflowExecutionScopeProduction,
DefinitionState: domain.WorkflowDefinitionStateDraft, DefinitionVersion: 4, DefinitionFamilyID: fanyuDeliveryTemplateV5ID + "-" + organizationID, SupersedesTemplateID: fanyuDeliveryTemplateV5ID + "-" + organizationID,
MaxConcurrentRuns: 1, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, CreatedAt: createdAt, UpdatedAt: now,
}
if issues := validateWorkflowTopology(nodes, edges); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.4 template: %s", strings.TrimSpace(issues[0].Message))
}
if issues := validateWorkflowInputContract(nodes, edges, workflowInputs, true); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.4 input contract: %s", strings.TrimSpace(issues[0].Message))
}
if err := server.store.UpsertTemplate(ctx, template); err != nil {
return err
}
existingRelease, err := server.store.GetWorkflowRelease(ctx, releaseID)
if err != nil || existingRelease != nil {
return err
}
for _, operator := range operators {
if effectiveOperatorPublicationStatus(operator) != domain.OperatorPublicationStatusPublished || !operatorImageDigestPattern.MatchString(strings.TrimSpace(operator.ImageID)) {
return nil
}
}
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
return nil
}
release := domain.WorkflowReleaseRecord{ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 4, Name: template.Name, Description: template.Description, Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, Capabilities: []string{"directory_input", "multiport_artifact_contract", "qwen3vl_behavior_rough_cut", "human_cut_adjustment", "human_cut_review", "human_semantic_annotation", "human_semantic_review", "human_acceptance", "final_segment_package"}, RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template), ReleaseNotes: "v5.4 explicit multiport data contract; PTS-grounded Qwen and four-stage human loop; pose-free direct package", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now}
return server.store.UpsertWorkflowRelease(ctx, release)
}
// ensureFanyuDeliveryTemplateV55 inserts calibration-grounded, OpenCV-remapped
// left-camera undistortion between normalization and face anonymization. The
// undistort node now emits a physical rectified video; pixel correction is no
// longer deferred to packaging.
func (server *server) ensureFanyuDeliveryTemplateV55(ctx context.Context, organizationID string) error {
organizationID = normalizedOrganizationID(organizationID)
templateID := fanyuDeliveryTemplateV55ID + "-" + organizationID
releaseID := "workflow-release-fanyu-v5-5-" + organizationID
operatorIDs := []string{
"operator-builtin-directory-scan", "operator-builtin-orbbec-data-normalize", "operator-builtin-orbbec-left-undistort",
"operator-builtin-video-face-blur", "operator-builtin-qwen-behavior-rough-cut", "operator-builtin-annotation-gate",
"operator-builtin-package",
}
operators := map[string]domain.OperatorRecord{}
for _, operatorID := range operatorIDs {
operator, err := server.store.GetOperator(ctx, operatorID)
if err != nil {
return err
}
if operator == nil {
return fmt.Errorf("fanyu v5.5 template requires builtin operator %s", operatorID)
}
operators[operatorID] = *operator
}
requiredPorts := map[string][]string{
"operator-builtin-directory-scan": {"sourceDirectory", "directory", "videos", "summary"},
"operator-builtin-orbbec-data-normalize": {"directory", "leftVideos", "videoPts", "calibrations", "summary"},
"operator-builtin-orbbec-left-undistort": {"leftVideos", "calibrations", "leftRectifiedVideos", "leftRectifiedTimestamps", "calibrationSpecs", "summary"},
"operator-builtin-video-face-blur": {"videos", "timestamps", "audio", "blurredVideos", "detectionSummary"},
"operator-builtin-qwen-behavior-rough-cut": {"videos", "timestamps", "clips", "prelabels", "boundaries", "inferenceSummary"},
"operator-builtin-annotation-gate": {"clips", "prelabels", "boundaries", "approvedVideos", "annotations", "aggregateSummary"},
"operator-builtin-package": {"approvedVideos", "annotations", "packageDirectory", "finalVideos", "deliverySummary"},
}
for operatorID, ports := range requiredPorts {
operator := operators[operatorID]
for _, portID := range ports {
if _, found := domain.FindPort(operator.Inputs, portID); !found {
if _, found := domain.FindPort(operator.Outputs, portID); !found {
return nil
}
}
}
}
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
annotationSupplierID := ""
nodes := []domain.WorkflowNode{
fanyuMultiportNode("fanyu-v55-directory", "目录读取(多端口)", operators[operatorIDs[0]], 0, 260),
fanyuMultiportNodeWithHyperparams("fanyu-v55-normalize", "Orbbec Ego 左相机标准化(多端口)", operators[operatorIDs[1]], 240, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v55-undistort", "左相机 OpenCV 真实去畸变(多端口)", operators[operatorIDs[2]], 480, 260, map[string]string{"UNDISTORT_ALPHA": "0", "REQUIRE_CALIBRATION": "true", "PRESERVE_AUDIO": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v55-face-blur", "YuNet 人脸真实脱敏(多端口)", operators[operatorIDs[3]], 720, 260, map[string]string{"DETECTION_METHOD": "yunet", "MODEL_PATH": "/app/operator-repos/builtin/video_face_blur/assets/face_detection_yunet_2023mar.onnx", "MODEL_SHA256": "8f2383e4dd3cfbb4553ea8718107fc0423210dc964f9f4280604804ed2552fa4", "CONFIDENCE_THRESHOLD": "0.5", "NMS_THRESHOLD": "0.3", "TOP_K": "5000", "BLUR_TYPE": "mosaic", "BLUR_EXPANSION_RATIO": "1.35", "TRACK_HOLD_FRAMES": "4", "TRACK_IOU_THRESHOLD": "0.2", "PRESERVE_AUDIO": "true", "PRESERVE_PTS": "true", "REQUIRE_PTS": "true", "REQUIRE_DETECTIONS": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v55-rough-cut", "Qwen3-VL 手部行为语义粗切(多端口)", operators[operatorIDs[4]], 960, 260, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "6", "MAX_NEW_TOKENS": "128", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v55-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认(多端口)", operators[operatorIDs[5]], 1200, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_SUPPLIER_ID": annotationSupplierID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v55-package", "人工聚合确认后打包(多端口)", operators[operatorIDs[6]], 1440, 260, map[string]string{"REQUIRE_HEADPOSE": "false", "POSE_FREE": "true", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
}
for index := range nodes {
if nodes[index].ID == "fanyu-v55-package" {
fanyuRetainInputPorts(&nodes[index], "approvedVideos", "annotations")
}
}
edges := []domain.WorkflowEdge{
fanyuEdge("fanyu-v55-e1", "fanyu-v55-directory", "directory", "fanyu-v55-normalize", "directory"),
fanyuEdge("fanyu-v55-e2", "fanyu-v55-normalize", "leftVideos", "fanyu-v55-undistort", "leftVideos"),
fanyuEdge("fanyu-v55-e3", "fanyu-v55-normalize", "calibrations", "fanyu-v55-undistort", "calibrations"),
fanyuEdge("fanyu-v55-e4", "fanyu-v55-undistort", "leftRectifiedVideos", "fanyu-v55-face-blur", "videos"),
fanyuEdge("fanyu-v55-e5", "fanyu-v55-undistort", "leftRectifiedTimestamps", "fanyu-v55-face-blur", "timestamps"),
fanyuEdge("fanyu-v55-e6", "fanyu-v55-normalize", "audio", "fanyu-v55-face-blur", "audio"),
fanyuEdge("fanyu-v55-e7", "fanyu-v55-undistort", "leftRectifiedTimestamps", "fanyu-v55-rough-cut", "timestamps"),
fanyuEdge("fanyu-v55-e8", "fanyu-v55-face-blur", "blurredVideos", "fanyu-v55-rough-cut", "videos"),
fanyuEdge("fanyu-v55-e9", "fanyu-v55-rough-cut", "clips", "fanyu-v55-human", "clips"),
fanyuEdge("fanyu-v55-e10", "fanyu-v55-rough-cut", "prelabels", "fanyu-v55-human", "prelabels"),
fanyuEdge("fanyu-v55-e11", "fanyu-v55-rough-cut", "boundaries", "fanyu-v55-human", "boundaries"),
fanyuEdge("fanyu-v55-e12", "fanyu-v55-human", "approvedVideos", "fanyu-v55-package", "approvedVideos"),
fanyuEdge("fanyu-v55-e13", "fanyu-v55-human", "annotations", "fanyu-v55-package", "annotations"),
}
workflowInputs := []domain.WorkflowInputDefinition{{
ID: "sourceDirectory", Name: "sourceDirectory", Description: "本次运行要处理的 Orbbec Ego BOS 目录(必填,非增量扫描)",
Type: domain.PortTypeFile, Container: domain.PortContainerDirectory, PayloadMode: domain.ArtifactTransferModeRef, Role: "directory", Required: true,
Bindings: []domain.WorkflowInputTarget{{NodeID: "fanyu-v55-directory", TargetPortID: "sourceDirectory"}},
}}
now := nowISO()
createdAt := now
if existing, err := server.store.GetTemplate(ctx, templateID); err != nil {
return err
} else if existing != nil && strings.TrimSpace(existing.CreatedAt) != "" {
createdAt = existing.CreatedAt
}
template := domain.TemplateRecord{
ID: templateID, OrganizationID: organizationID, Name: "01-左相机去畸变语义粗切标注质检-v5.5",
Description: "在 v5.4 多端口契约上插入 OpenCV 真实左相机去畸变,并使用固定 MIT YuNet 模型执行逐帧人脸强脱敏;缺失标定、模型、PTS、音频封装或帧数变化立即失败。其余保持 PTS 粗切、四阶段人工闭环与聚合确认后直接打包。",
Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindStandard, ExecutionScope: domain.WorkflowExecutionScopeProduction,
DefinitionState: domain.WorkflowDefinitionStateDraft, DefinitionVersion: 5, DefinitionFamilyID: fanyuDeliveryTemplateV5ID + "-" + organizationID, SupersedesTemplateID: fanyuDeliveryTemplateV54ID + "-" + organizationID,
MaxConcurrentRuns: 1, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, CreatedAt: createdAt, UpdatedAt: now,
}
if issues := validateWorkflowTopology(nodes, edges); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.5 template: %s", strings.TrimSpace(issues[0].Message))
}
if issues := validateWorkflowInputContract(nodes, edges, workflowInputs, true); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.5 input contract: %s", strings.TrimSpace(issues[0].Message))
}
if err := server.store.UpsertTemplate(ctx, template); err != nil {
return err
}
existingRelease, err := server.store.GetWorkflowRelease(ctx, releaseID)
if err != nil || existingRelease != nil {
return err
}
for _, operator := range operators {
if effectiveOperatorPublicationStatus(operator) != domain.OperatorPublicationStatusPublished || !operatorImageDigestPattern.MatchString(strings.TrimSpace(operator.ImageID)) {
return nil
}
}
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
return nil
}
release := domain.WorkflowReleaseRecord{ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 5, Name: template.Name, Description: template.Description, Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, Capabilities: []string{"directory_input", "multiport_artifact_contract", "left_camera_opencv_undistort", "yunet_face_anonymization", "qwen3vl_behavior_rough_cut", "human_cut_adjustment", "human_cut_review", "human_semantic_annotation", "human_semantic_review", "human_acceptance", "final_segment_package"}, RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template), ReleaseNotes: "v5.5 materializes OpenCV rectification and fixed-SHA MIT YuNet face anonymization before PTS rough cutting; virtual cutting and four-stage human loop unchanged", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now}
return server.store.UpsertWorkflowRelease(ctx, release)
}
// ensureFanyuDeliveryTemplateV56 preserves the accepted semantic/HITL path
// while making the delivery contract stereo and pose-complete. Both cameras
// are physically rectified and anonymized. The left camera drives semantic
// boundary review; packaging applies the accepted half-open intervals to the
// matching right camera and crops 6DRepNet/WiLoR frame results to the same
// intervals. v5.5 remains immutable for historical replay.
func (server *server) ensureFanyuDeliveryTemplateV56(ctx context.Context, organizationID string) error {
organizationID = normalizedOrganizationID(organizationID)
templateID := fanyuDeliveryTemplateV56ID + "-" + organizationID
releaseID := "workflow-release-fanyu-v5-6-" + organizationID
operatorIDs := []string{
"operator-builtin-directory-scan",
"operator-builtin-orbbec-data-normalize",
"operator-builtin-orbbec-left-undistort",
"operator-builtin-video-face-blur",
"operator-builtin-qwen-behavior-rough-cut",
"operator-builtin-annotation-gate",
"operator-builtin-head-pose",
"operator-builtin-wilor-hand-pose",
"operator-builtin-package",
}
operators := map[string]domain.OperatorRecord{}
for _, operatorID := range operatorIDs {
operator, err := server.store.GetOperator(ctx, operatorID)
if err != nil {
return err
}
if operator == nil {
return fmt.Errorf("fanyu v5.6 template requires builtin operator %s", operatorID)
}
operators[operatorID] = *operator
}
requiredPorts := map[string][]string{
"operator-builtin-directory-scan": {"sourceDirectory", "directory"},
"operator-builtin-orbbec-data-normalize": {"directory", "leftVideos", "rightVideos", "videoPts", "audio", "calibrations"},
"operator-builtin-orbbec-left-undistort": {"leftVideos", "rightVideos", "calibrations", "leftRectifiedVideos", "rightRectifiedVideos", "leftRectifiedTimestamps", "rightRectifiedTimestamps"},
"operator-builtin-video-face-blur": {"videos", "timestamps", "blurredVideos"},
"operator-builtin-qwen-behavior-rough-cut": {"videos", "timestamps", "clips", "prelabels", "boundaries"},
"operator-builtin-annotation-gate": {"clips", "prelabels", "boundaries", "approvedVideos", "annotations"},
"operator-builtin-head-pose": {"videos", "out-1"},
"operator-builtin-wilor-hand-pose": {"videos", "out-1"},
"operator-builtin-package": {"approvedVideos", "annotations", "rightVideos", "headpose", "handpose", "packageDirectory", "finalVideos", "headposeFiles", "handposeFiles", "deliverySummary"},
}
for operatorID, ports := range requiredPorts {
operator := operators[operatorID]
for _, portID := range ports {
if _, found := domain.FindPort(operator.Inputs, portID); !found {
if _, found := domain.FindPort(operator.Outputs, portID); !found {
return nil
}
}
}
}
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
annotationSupplierID := ""
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")),
"HEADPOSE_MODEL": "6DRepNet",
"FRAME_STRIDE": "3",
"MAX_FRAMES": "10000",
"REQUEST_TIMEOUT_SECONDS": "1800",
}
faceBlurParams := map[string]string{
"DETECTION_METHOD": "yunet", "MODEL_PATH": "/app/operator-repos/builtin/video_face_blur/assets/face_detection_yunet_2023mar.onnx", "MODEL_SHA256": "8f2383e4dd3cfbb4553ea8718107fc0423210dc964f9f4280604804ed2552fa4",
"CONFIDENCE_THRESHOLD": "0.5", "NMS_THRESHOLD": "0.3", "TOP_K": "5000", "BLUR_TYPE": "mosaic", "BLUR_EXPANSION_RATIO": "1.35", "TRACK_HOLD_FRAMES": "4", "TRACK_IOU_THRESHOLD": "0.2",
"PRESERVE_PTS": "true", "REQUIRE_PTS": "true", "REQUIRE_DETECTIONS": "false",
}
leftFaceBlurParams := make(map[string]string, len(faceBlurParams)+1)
rightFaceBlurParams := make(map[string]string, len(faceBlurParams)+1)
for key, value := range faceBlurParams {
leftFaceBlurParams[key] = value
rightFaceBlurParams[key] = value
}
leftFaceBlurParams["PRESERVE_AUDIO"] = "true"
rightFaceBlurParams["PRESERVE_AUDIO"] = "false"
nodes := []domain.WorkflowNode{
fanyuMultiportNode("fanyu-v56-directory", "目录读取(多端口)", operators[operatorIDs[0]], 0, 320),
fanyuMultiportNodeWithHyperparams("fanyu-v56-normalize", "Orbbec Ego 双目标准化(多端口)", operators[operatorIDs[1]], 240, 320, map[string]string{"CAMERA_SIDE": "both", "REQUIRE_STEREO": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v56-undistort", "左右相机 OpenCV 真实去畸变", operators[operatorIDs[2]], 500, 320, map[string]string{"UNDISTORT_ALPHA": "0", "REQUIRE_CALIBRATION": "true", "PRESERVE_AUDIO": "true", "REQUIRE_STEREO": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v56-left-blur", "左相机 YuNet 人脸脱敏", operators[operatorIDs[3]], 780, 140, leftFaceBlurParams),
fanyuMultiportNodeWithHyperparams("fanyu-v56-right-blur", "右相机 YuNet 人脸脱敏", operators[operatorIDs[3]], 780, 500, rightFaceBlurParams),
fanyuMultiportNodeWithHyperparams("fanyu-v56-rough-cut", "Qwen3-VL 左相机语义粗切", operators[operatorIDs[4]], 1060, 80, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "6", "MAX_NEW_TOKENS": "128", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v56-headpose", "6DRepNet HeadPose(开源)", operators[operatorIDs[6]], 1060, 320, headposeOverrides),
fanyuMultiportNodeWithHyperparams("fanyu-v56-handpose", "WiLoR HandPose(开源)", operators[operatorIDs[7]], 1060, 560, map[string]string{"INPUT_URL": "", "INPUT_PATH": "", "MEDIA_KIND": "video", "FRAME_STRIDE": "3", "MAX_FRAMES": "120", "VIDEO_CHUNK_FRAMES": "119", "REQUIRE_FULL_VIDEO_COVERAGE": "true", "DOWNLOAD_OUTPUTS": "true", "REQUEST_TIMEOUT_SECONDS": "1800"}),
fanyuMultiportNodeWithHyperparams("fanyu-v56-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认", operators[operatorIDs[5]], 1340, 80, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_SUPPLIER_ID": annotationSupplierID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
fanyuMultiportNodeWithHyperparams("fanyu-v56-package", "双目同步裁切 + 姿态结果打包交付", operators[operatorIDs[8]], 1640, 320, map[string]string{"REQUIRE_HEADPOSE": "true", "REQUIRE_HANDPOSE": "true", "REQUIRE_STEREO_DELIVERY": "true", "POSE_FREE": "false", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
}
edges := []domain.WorkflowEdge{
fanyuEdge("fanyu-v56-e1", "fanyu-v56-directory", "directory", "fanyu-v56-normalize", "directory"),
fanyuEdge("fanyu-v56-e2", "fanyu-v56-normalize", "leftVideos", "fanyu-v56-undistort", "leftVideos"),
fanyuEdge("fanyu-v56-e3", "fanyu-v56-normalize", "rightVideos", "fanyu-v56-undistort", "rightVideos"),
fanyuEdge("fanyu-v56-e4", "fanyu-v56-normalize", "calibrations", "fanyu-v56-undistort", "calibrations"),
fanyuEdge("fanyu-v56-e5", "fanyu-v56-undistort", "leftRectifiedVideos", "fanyu-v56-left-blur", "videos"),
fanyuEdge("fanyu-v56-e6", "fanyu-v56-undistort", "leftRectifiedTimestamps", "fanyu-v56-left-blur", "timestamps"),
fanyuEdge("fanyu-v56-e7", "fanyu-v56-normalize", "audio", "fanyu-v56-left-blur", "audio"),
fanyuEdge("fanyu-v56-e8", "fanyu-v56-undistort", "rightRectifiedVideos", "fanyu-v56-right-blur", "videos"),
fanyuEdge("fanyu-v56-e9", "fanyu-v56-undistort", "rightRectifiedTimestamps", "fanyu-v56-right-blur", "timestamps"),
fanyuEdge("fanyu-v56-e10", "fanyu-v56-left-blur", "blurredVideos", "fanyu-v56-rough-cut", "videos"),
fanyuEdge("fanyu-v56-e11", "fanyu-v56-undistort", "leftRectifiedTimestamps", "fanyu-v56-rough-cut", "timestamps"),
fanyuEdge("fanyu-v56-e12", "fanyu-v56-rough-cut", "clips", "fanyu-v56-human", "clips"),
fanyuEdge("fanyu-v56-e13", "fanyu-v56-rough-cut", "prelabels", "fanyu-v56-human", "prelabels"),
fanyuEdge("fanyu-v56-e14", "fanyu-v56-rough-cut", "boundaries", "fanyu-v56-human", "boundaries"),
fanyuEdge("fanyu-v56-e15", "fanyu-v56-left-blur", "blurredVideos", "fanyu-v56-headpose", "videos"),
fanyuEdge("fanyu-v56-e16", "fanyu-v56-left-blur", "blurredVideos", "fanyu-v56-handpose", "videos"),
fanyuEdge("fanyu-v56-e17", "fanyu-v56-human", "approvedVideos", "fanyu-v56-package", "approvedVideos"),
fanyuEdge("fanyu-v56-e18", "fanyu-v56-human", "annotations", "fanyu-v56-package", "annotations"),
fanyuEdge("fanyu-v56-e19", "fanyu-v56-right-blur", "blurredVideos", "fanyu-v56-package", "rightVideos"),
fanyuEdge("fanyu-v56-e20", "fanyu-v56-headpose", "out-1", "fanyu-v56-package", "headpose"),
fanyuEdge("fanyu-v56-e21", "fanyu-v56-handpose", "out-1", "fanyu-v56-package", "handpose"),
}
workflowInputs := []domain.WorkflowInputDefinition{{
ID: "sourceDirectory", Name: "sourceDirectory", Description: "本次运行要处理的 Orbbec Ego 双目 BOS 目录",
Type: domain.PortTypeFile, Container: domain.PortContainerDirectory, PayloadMode: domain.ArtifactTransferModeRef, Role: "directory", Required: true,
Bindings: []domain.WorkflowInputTarget{{NodeID: "fanyu-v56-directory", TargetPortID: "sourceDirectory"}},
}}
now := nowISO()
createdAt := now
if existing, err := server.store.GetTemplate(ctx, templateID); err != nil {
return err
} else if existing != nil && strings.TrimSpace(existing.CreatedAt) != "" {
createdAt = existing.CreatedAt
}
template := domain.TemplateRecord{
ID: templateID, OrganizationID: organizationID, Name: "01-双目去畸变同步裁切姿态交付-v5.6",
Description: "左右相机分别使用真实标定完成 OpenCV 去畸变与 YuNet 人脸脱敏;左相机执行 Qwen3-VL 粗切和人工四阶段闭环,最终边界同步裁切左右相机;6DRepNet HeadPose 与 WiLoR HandPose 逐帧结果按同一边界裁切后进入交付包。",
Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindStandard, ExecutionScope: domain.WorkflowExecutionScopeProduction,
DefinitionState: domain.WorkflowDefinitionStateDraft, DefinitionVersion: 6, DefinitionFamilyID: fanyuDeliveryTemplateV5ID + "-" + organizationID, SupersedesTemplateID: fanyuDeliveryTemplateV55ID + "-" + organizationID,
MaxConcurrentRuns: 1, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, CreatedAt: createdAt, UpdatedAt: now,
}
if issues := validateWorkflowTopology(nodes, edges); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.6 template: %s", strings.TrimSpace(issues[0].Message))
}
if issues := validateWorkflowInputContract(nodes, edges, workflowInputs, true); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.6 input contract: %s", strings.TrimSpace(issues[0].Message))
}
if err := server.store.UpsertTemplate(ctx, template); err != nil {
return err
}
existingRelease, err := server.store.GetWorkflowRelease(ctx, releaseID)
if err != nil || existingRelease != nil {
return err
}
for _, operator := range operators {
if effectiveOperatorPublicationStatus(operator) != domain.OperatorPublicationStatusPublished || !operatorImageDigestPattern.MatchString(strings.TrimSpace(operator.ImageID)) {
return nil
}
}
for _, key := range []string{"HEADPOSE_API_BASE_URL", "HEADPOSE_SERVICE_IMAGE_ID", "HEADPOSE_MODEL_SHA256", "HEADPOSE_LICENSE_ID"} {
if strings.TrimSpace(headposeOverrides[key]) == "" {
return nil
}
}
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
return nil
}
release := domain.WorkflowReleaseRecord{
ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 6, Name: template.Name, Description: template.Description,
Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns,
WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges,
Capabilities: []string{"directory_input", "multiport_artifact_contract", "stereo_opencv_undistort", "stereo_yunet_face_anonymization", "qwen3vl_behavior_rough_cut", "human_cut_adjustment", "human_cut_review", "human_semantic_annotation", "human_semantic_review", "human_acceptance", "stereo_synchronized_crop", "6drepnet_headpose", "wilor_handpose", "stereo_pose_package"},
RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template),
ReleaseNotes: "v5.6 dual-camera OpenCV rectification and YuNet anonymization; left-camera semantic/HITL boundaries synchronously crop both cameras and 6DRepNet/WiLoR pose outputs",
PublishedByUserID: "system", PublishedAt: now, CreatedAt: now,
}
return server.store.UpsertWorkflowRelease(ctx, release)
}
// ensureFanyuDeliveryTemplateV57 keeps HeadPose rendering available to human
// acceptance while treating WiLoR as an automatic 3D HandPose branch. HandPose
// bypasses human review and is cropped only after final segment boundaries are
// released to the package node.
func (server *server) ensureFanyuDeliveryTemplateV57(ctx context.Context, organizationID string) error {
organizationID = normalizedOrganizationID(organizationID)
base, err := server.store.GetTemplate(ctx, fanyuDeliveryTemplateV56ID+"-"+organizationID)
if err != nil || base == nil {
return err
}
templateID := fanyuDeliveryTemplateV57ID + "-" + organizationID
releaseID := "workflow-release-fanyu-v5-7-" + organizationID
nodes := append([]domain.WorkflowNode(nil), base.Nodes...)
for index := range nodes {
node := &nodes[index]
switch node.ID {
case "fanyu-v56-headpose":
node.Data.Label = "6DRepNet HeadPose 预标(带渲染)"
node.Data.Description = "生成逐帧 HeadPose 角度和浏览器可播放的姿态轴叠加视频,作为人工质检证据。"
if operator, operatorErr := server.store.GetOperator(ctx, "operator-builtin-head-pose"); operatorErr != nil {
return operatorErr
} else if operator != nil {
node.Data.OperatorImageID = operator.ImageID
node.Data.Image = operator.Image
node.Data.SkillDefinition = operator.SkillDefinition
node.Data.PublicationStatus = operator.PublicationStatus
}
case "fanyu-v56-handpose":
node.Data.Label = "WiLoR 3D HandPose(自动)"
node.Data.Description = "自动估计逐帧 3D 手部姿态、关键点和 MANO 手部网格;不进入人工质检,按最终切片边界裁切后直接进入交付包。"
if operator, operatorErr := server.store.GetOperator(ctx, "operator-builtin-wilor-hand-pose"); operatorErr != nil {
return operatorErr
} else if operator != nil {
node.Data.OperatorImageID = operator.ImageID
node.Data.Image = operator.Image
node.Data.SkillDefinition = operator.SkillDefinition
node.Data.PublicationStatus = operator.PublicationStatus
}
case "fanyu-v56-human":
node.Data.Label = "人工调切→语义/HeadPose质检→聚合确认"
node.Data.Description = "人工完成调切、剪切审核和语义标注,并查看 HeadPose 渲染证据;自动 HandPose 不进入人工质检。"
case "fanyu-v56-package":
node.Data.Label = "双目同步裁切 + HeadPose/HandPose 交付"
}
}
edges := append([]domain.WorkflowEdge(nil), base.Edges...)
edges = append(edges, fanyuEdge("fanyu-v57-e22", "fanyu-v56-headpose", "out-1", "fanyu-v56-human", "headpose"))
now := nowISO()
createdAt := now
if existing, existingErr := server.store.GetTemplate(ctx, templateID); existingErr != nil {
return existingErr
} else if existing != nil && strings.TrimSpace(existing.CreatedAt) != "" {
createdAt = existing.CreatedAt
}
template := domain.TemplateRecord{
ID: templateID, OrganizationID: organizationID, Name: "01-双目裁切与 HeadPose/HandPose 交付-v5.7",
Description: "左右相机去畸变和脱敏后同步裁切;6DRepNet HeadPose 提供可视化审核证据,WiLoR 自动生成真实 3D HandPose 且不进入人工质检;两类姿态数据均按最终边界裁切进入交付包。",
Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindStandard, ExecutionScope: domain.WorkflowExecutionScopeProduction,
DefinitionState: domain.WorkflowDefinitionStateDraft, DefinitionVersion: 7, DefinitionFamilyID: fanyuDeliveryTemplateV5ID + "-" + organizationID, SupersedesTemplateID: fanyuDeliveryTemplateV56ID + "-" + organizationID,
MaxConcurrentRuns: 1, WorkflowInputs: append([]domain.WorkflowInputDefinition(nil), base.WorkflowInputs...), Nodes: nodes, Edges: edges, CreatedAt: createdAt, UpdatedAt: now,
}
if issues := validateWorkflowTopology(nodes, edges); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.7 template: %s", strings.TrimSpace(issues[0].Message))
}
if issues := validateWorkflowInputContract(nodes, edges, template.WorkflowInputs, true); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v5.7 input contract: %s", strings.TrimSpace(issues[0].Message))
}
if err := server.store.UpsertTemplate(ctx, template); err != nil {
return err
}
if existingRelease, releaseErr := server.store.GetWorkflowRelease(ctx, releaseID); releaseErr != nil || existingRelease != nil {
return releaseErr
}
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
return nil
}
release := domain.WorkflowReleaseRecord{
ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 7, Name: template.Name, Description: template.Description,
Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns,
WorkflowInputs: template.WorkflowInputs, Nodes: nodes, Edges: edges,
Capabilities: []string{"directory_input", "multiport_artifact_contract", "stereo_opencv_undistort", "stereo_yunet_face_anonymization", "qwen3vl_behavior_rough_cut", "human_cut_adjustment", "human_cut_review", "human_semantic_annotation", "headpose_render", "human_headpose_review", "wilor_3d_handpose", "automatic_handpose_delivery", "human_semantic_review", "human_acceptance", "stereo_synchronized_crop", "stereo_pose_package"},
RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template),
ReleaseNotes: "v5.7 keeps browser-rendered HeadPose evidence in human review and restores WiLoR as an automatic 3D HandPose branch that bypasses human quality review",
PublishedByUserID: "system", PublishedAt: now, CreatedAt: now,
}
return server.store.UpsertWorkflowRelease(ctx, release)
}
func (server *server) ensureFanyuDeliveryTemplateV3(ctx context.Context, organizationID string) error {
templateID := fanyuDeliveryTemplateV3ID + "-" + normalizedOrganizationID(organizationID)
releaseID := "workflow-release-fanyu-v3-" + normalizedOrganizationID(organizationID)
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) ensureFanyuDeliveryTemplateV4(ctx context.Context, organizationID string) error {
templateID := fanyuDeliveryTemplateV4ID + "-" + normalizedOrganizationID(organizationID)
releaseID := "workflow-release-fanyu-v4-" + 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-face-blur", "operator-builtin-video-slice",
"operator-builtin-semantic-prelabel", "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 v4 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-v4-scan", "BOS 增量扫描", operators[operatorIDs[0]], 0, 180),
fanyuNodeWithHyperparams("fanyu-v4-normalize", "Orbbec Ego 右相机标准化", operators[operatorIDs[1]], 260, 180, map[string]string{"CAMERA_SIDE": "right", "REQUIRE_STEREO": "true"}),
fanyuNodeWithHyperparams("fanyu-v4-face-blur", "视频人脸脱敏", operators[operatorIDs[2]], 520, 180, map[string]string{"PRESERVE_AUDIO": "true", "PRESERVE_PTS": "true"}),
fanyuNode("fanyu-v4-slice", "右相机视频切片", operators[operatorIDs[3]], 780, 40),
fanyuNodeWithHyperparams("fanyu-v4-prelabel", "AI 语义预标", operators[operatorIDs[4]], 1040, 40, map[string]string{"MINIMUM_CONFIDENCE": "0.7", "TEMPLATE_VERSION": "v4"}),
fanyuNode("fanyu-v4-human", "切片校正 → 22类语义标注 → 标注质量复核", operators[operatorIDs[5]], 1300, 40),
fanyuNodeWithHyperparams("fanyu-v4-headpose", "6DRepNet Headpose(必选)", operators[operatorIDs[6]], 780, 220, headposeOverrides),
fanyuNodeWithHyperparams("fanyu-v4-handpose", "WiLoR Handpose(Run 可选)", operators[operatorIDs[7]], 1040, 360, map[string]string{"INPUT_URL": "", "INPUT_PATH": "", "MEDIA_KIND": "video"}),
fanyuNode("fanyu-v4-options", "交付选项(根输入)", operators[operatorIDs[8]], 0, 420),
fanyuNodeWithHyperparams("fanyu-v4-package", "成品打包(Headpose 必选 / Handpose 可选)", operators[operatorIDs[9]], 1600, 180, map[string]string{"REQUIRE_HEADPOSE": "true"}),
}
edges := []domain.WorkflowEdge{
fanyuEdge("fanyu-v4-e1", "fanyu-v4-scan", "out-1", "fanyu-v4-normalize", "in-1"),
fanyuEdge("fanyu-v4-e2", "fanyu-v4-normalize", "out-1", "fanyu-v4-face-blur", "in-1"),
fanyuEdge("fanyu-v4-e3", "fanyu-v4-face-blur", "out-1", "fanyu-v4-slice", "in-1"),
fanyuEdge("fanyu-v4-e4", "fanyu-v4-face-blur", "out-1", "fanyu-v4-headpose", "in-1"),
fanyuEdge("fanyu-v4-e5", "fanyu-v4-face-blur", "out-1", "fanyu-v4-handpose", "in-1"),
fanyuEdge("fanyu-v4-e6", "fanyu-v4-slice", "out-1", "fanyu-v4-prelabel", "in-1"),
fanyuEdge("fanyu-v4-e7", "fanyu-v4-slice", "out-1", "fanyu-v4-human", "clips"),
fanyuEdge("fanyu-v4-e8", "fanyu-v4-prelabel", "out-1", "fanyu-v4-human", "prelabels"),
fanyuEdge("fanyu-v4-e9", "fanyu-v4-options", "out-1", "fanyu-v4-handpose", "in-2"),
fanyuEdge("fanyu-v4-e10", "fanyu-v4-human", "approved", "fanyu-v4-package", "in-1"),
fanyuEdge("fanyu-v4-e11", "fanyu-v4-headpose", "out-1", "fanyu-v4-package", "in-2"),
fanyuEdge("fanyu-v4-e12", "fanyu-v4-handpose", "out-1", "fanyu-v4-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-v4-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-右相机切分标注质检-v4",
Description: "右相机人脸脱敏、视频切片、AI语义预标、22类人工标注质量复核、必选 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 v4 template: %s", strings.TrimSpace(issues[0].Message))
}
if issues := validateWorkflowInputContract(nodes, edges, workflowInputs, true); len(issues) > 0 {
return fmt.Errorf("invalid fanyu v4 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"]) == "" {
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: 4, Name: template.Name, Description: template.Description, Type: template.Type, Kind: template.Kind,
ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns, WorkflowInputs: workflowInputs,
Nodes: nodes, Edges: edges, Capabilities: []string{"human_annotation", "human_quality_review", "human_acceptance"},
RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template),
ReleaseNotes: "Face Blur, AI Prelabeling, 22-class taxonomy annotation gate, Headpose required, Handpose optional", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now,
}
return server.store.UpsertWorkflowRelease(ctx, release)
}
func (server *server) ensureFanyuDeliveryTemplateV1(ctx context.Context, organizationID string) error {
templateID := fanyuDeliveryTemplateID + "-" + organizationID
if existing, err := server.store.GetTemplate(ctx, templateID); err != nil || existing != nil {
return err
}
operatorIDs := []string{
"operator-builtin-bos-incremental-scan", "operator-builtin-xplatform-dataset-index", "operator-builtin-json-filter",
"operator-builtin-video-slice", "operator-builtin-annotation-gate", "operator-builtin-wilor-hand-pose",
"operator-builtin-merge", "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 delivery template requires builtin operator %s", operatorID)
}
operators[operatorID] = *operator
}
filter := operators["operator-builtin-json-filter"]
for index := range filter.Hyperparams {
if filter.Hyperparams[index].Key == "DSL" {
filter.Hyperparams[index].Value = "camera~right|右"
}
}
nodes := []domain.WorkflowNode{
fanyuNode("fanyu-scan", "BOS 增量扫描", operators[operatorIDs[0]], 0, 220),
fanyuNode("fanyu-index", "X 平台数据集索引", operators[operatorIDs[1]], 280, 220),
fanyuNode("fanyu-filter", "数据过滤(右相机)", filter, 560, 220),
fanyuNode("fanyu-slice", "视频切片", operators[operatorIDs[3]], 840, 80),
fanyuNode("fanyu-human", "切片微调 → 时间动作分割 → 质检复核", operators[operatorIDs[4]], 1120, 80),
fanyuNode("fanyu-wilor", "WiLoR 3D 手部姿态估计", operators[operatorIDs[5]], 840, 360),
fanyuNode("fanyu-join", "质检数据 + handpose 汇合", operators[operatorIDs[6]], 1400, 220),
fanyuNode("fanyu-package", "成品打包(进入最终验收)", operators[operatorIDs[7]], 1680, 220),
}
edges := []domain.WorkflowEdge{
fanyuEdge("fanyu-e1", "fanyu-scan", "out-1", "fanyu-index", "in-1"),
fanyuEdge("fanyu-e2", "fanyu-index", "out-1", "fanyu-filter", "in-1"),
fanyuEdge("fanyu-e3", "fanyu-filter", "out-1", "fanyu-slice", "in-1"),
fanyuEdge("fanyu-e4", "fanyu-filter", "out-1", "fanyu-wilor", "in-1"),
fanyuEdge("fanyu-e5", "fanyu-slice", "out-1", "fanyu-human", "clips"),
fanyuEdge("fanyu-e6", "fanyu-human", "approved", "fanyu-join", "in-1"),
fanyuEdge("fanyu-e7", "fanyu-wilor", "out-1", "fanyu-join", "in-2"),
fanyuEdge("fanyu-e8", "fanyu-join", "out-1", "fanyu-package", "in-1"),
}
now := nowISO()
template := domain.TemplateRecord{ID: templateID, OrganizationID: organizationID, Name: "01-右相机切分标注质检-v1", Description: "BOS 增量扫描、X 平台索引、右相机过滤、视频切片、切片/语义/质检人类在环、WiLoR 并行推理、数据汇合、成品打包与包级最终验收。", Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindScan, ExecutionScope: domain.WorkflowExecutionScopeProduction, MaxConcurrentRuns: 1, Nodes: nodes, Edges: edges, CreatedAt: now, UpdatedAt: now}
if issues := validateWorkflowTopology(nodes, edges); len(issues) > 0 {
return fmt.Errorf("invalid fanyu delivery template: %s", strings.TrimSpace(issues[0].Message))
}
if err := server.store.UpsertTemplate(ctx, template); err != nil {
return err
}
release := domain.WorkflowReleaseRecord{ID: "workflow-release-fanyu-v1-" + organizationID, OrganizationID: organizationID, TemplateID: template.ID, Version: 1, Name: template.Name, Description: template.Description, Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns, Nodes: nodes, Edges: edges, Capabilities: []string{"human_annotation", "human_quality_review", "human_acceptance"}, RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template), ReleaseNotes: "System Fanyu delivery baseline", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now}
return server.store.UpsertWorkflowRelease(ctx, release)
}
func (server *server) ensureFanyuOrbbecDeliveryTemplateV2(ctx context.Context, organizationID string) error {
templateID := fanyuOrbbecDeliveryTemplateID + "-" + organizationID
if existing, err := server.store.GetTemplate(ctx, templateID); 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-wilor-hand-pose",
"operator-builtin-merge",
"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 Orbbec delivery template requires builtin operator %s", operatorID)
}
operators[operatorID] = *operator
}
nodes := []domain.WorkflowNode{
fanyuNode("fanyu-scan", "BOS 增量扫描", operators[operatorIDs[0]], 0, 220),
fanyuNodeWithHyperparams("fanyu-normalize", "Orbbec Ego 右相机标准化", operators[operatorIDs[1]], 280, 220, map[string]string{
"CAMERA_SIDE": "right",
"REQUIRE_STEREO": "true",
}),
fanyuNode("fanyu-slice", "右相机视频切片", operators[operatorIDs[2]], 560, 80),
fanyuNode("fanyu-human", "切片微调 → 时间动作分割 → 质检复核 → 验收", operators[operatorIDs[3]], 840, 80),
fanyuNodeWithHyperparams("fanyu-wilor", "WiLoR 3D 手部姿态估计", operators[operatorIDs[4]], 560, 360, map[string]string{
"INPUT_URL": "",
"INPUT_PATH": "",
"MEDIA_KIND": "video",
}),
fanyuNode("fanyu-join", "标注结果 + handpose 简单汇合", operators[operatorIDs[5]], 1120, 220),
fanyuNode("fanyu-package", "简单合包(标注 + handpose)", operators[operatorIDs[6]], 1400, 220),
}
edges := []domain.WorkflowEdge{
fanyuEdge("fanyu-v2-e1", "fanyu-scan", "out-1", "fanyu-normalize", "in-1"),
fanyuEdge("fanyu-v2-e2", "fanyu-normalize", "out-1", "fanyu-slice", "in-1"),
fanyuEdge("fanyu-v2-e3", "fanyu-normalize", "out-1", "fanyu-wilor", "in-1"),
fanyuEdge("fanyu-v2-e4", "fanyu-slice", "out-1", "fanyu-human", "clips"),
fanyuEdge("fanyu-v2-e5", "fanyu-human", "approved", "fanyu-join", "in-1"),
fanyuEdge("fanyu-v2-e6", "fanyu-wilor", "out-1", "fanyu-join", "in-2"),
fanyuEdge("fanyu-v2-e7", "fanyu-join", "out-1", "fanyu-package", "in-1"),
}
now := nowISO()
template := domain.TemplateRecord{
ID: templateID, OrganizationID: organizationID, Name: "01-右相机切分标注质检-v2-Orbbec",
Description: "BOS 增量扫描、Orbbec Ego 双目完整性校验与右相机标准化、视频切片、人类标注/质检/验收、WiLoR 并行推理、标注与 handpose 简单汇合和合包。",
Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindScan, ExecutionScope: domain.WorkflowExecutionScopeProduction,
MaxConcurrentRuns: 1, Nodes: nodes, Edges: edges, CreatedAt: now, UpdatedAt: now,
}
if issues := validateWorkflowTopology(nodes, edges); len(issues) > 0 {
return fmt.Errorf("invalid fanyu Orbbec delivery template: %s", strings.TrimSpace(issues[0].Message))
}
if err := server.store.UpsertTemplate(ctx, template); err != nil {
return err
}
release := domain.WorkflowReleaseRecord{
ID: "workflow-release-fanyu-orbbec-v2-" + organizationID, OrganizationID: organizationID,
TemplateID: template.ID, Version: 2, Name: template.Name, Description: template.Description,
Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns,
Nodes: nodes, Edges: edges, Capabilities: []string{"human_annotation", "human_quality_review", "human_acceptance"},
RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template),
ReleaseNotes: "Orbbec Ego right-camera path with WiLoR, simple merge, and package", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now,
}
return server.store.UpsertWorkflowRelease(ctx, release)
}