forked from longtao.wu/droboticflow
1184 lines
79 KiB
Go
1184 lines
79 KiB
Go
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"
|
||
|
||
func fanyuLegacyPorts(operatorID string, inputs []domain.PortDefinition, outputs []domain.PortDefinition) ([]domain.PortDefinition, []domain.PortDefinition) {
|
||
legacy := func(id, name string, typ domain.PortType, required bool) domain.PortDefinition {
|
||
return domain.PortDefinition{ID: id, Name: name, Type: typ, Required: required, Transmission: "bus"}
|
||
}
|
||
switch operatorID {
|
||
case "operator-builtin-directory-scan":
|
||
return []domain.PortDefinition{legacy("in-1", "input", domain.PortTypeFile, true)}, []domain.PortDefinition{legacy("out-1", "manifest", domain.PortTypeJSON, false)}
|
||
case "operator-builtin-orbbec-data-normalize":
|
||
return []domain.PortDefinition{legacy("in-1", "input", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("out-1", "dataset", domain.PortTypeJSON, false)}
|
||
case "operator-builtin-video-face-blur":
|
||
return []domain.PortDefinition{legacy("in-1", "input", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("out-1", "blurredVideo", domain.PortTypeJSON, false)}
|
||
case "operator-builtin-qwen-behavior-rough-cut":
|
||
return []domain.PortDefinition{legacy("video", "video", domain.PortTypeJSON, true), legacy("metadata", "metadata", domain.PortTypeJSON, true)}, []domain.PortDefinition{legacy("out-1", "roughCuts", domain.PortTypeJSON, false)}
|
||
case "operator-builtin-annotation-gate":
|
||
return []domain.PortDefinition{legacy("clips", "clips", domain.PortTypeJSON, false), legacy("prelabels", "prelabels", domain.PortTypeJSON, false), legacy("validEvents", "validEvents", domain.PortTypeJSON, false), legacy("headpose", "headpose", domain.PortTypeJSON, false), legacy("handpose", "handpose", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("approved", "approved", domain.PortTypeJSON, false), legacy("rejected", "rejected", domain.PortTypeJSON, false)}
|
||
case "operator-builtin-package":
|
||
return []domain.PortDefinition{legacy("in-1", "annotations", domain.PortTypeJSON, true), legacy("in-2", "headpose", domain.PortTypeJSON, false), legacy("in-3", "handpose", domain.PortTypeJSON, false)}, []domain.PortDefinition{legacy("out-1", "packages", domain.PortTypeJSON, false)}
|
||
default:
|
||
return inputs, outputs
|
||
}
|
||
}
|
||
|
||
func fanyuNode(id string, label string, operator domain.OperatorRecord, x float64, y float64) domain.WorkflowNode {
|
||
cpu, memory, gpu, sharedMemory := "", "", "", ""
|
||
if operator.Resources != nil {
|
||
cpu = operator.Resources.CPULimit
|
||
memory = operator.Resources.MemoryLimit
|
||
gpu = operator.Resources.GPULimit
|
||
sharedMemory = operator.Resources.SharedMemorySize
|
||
}
|
||
inputs, outputs := fanyuLegacyPorts(operator.ID, operator.Inputs, operator.Outputs)
|
||
return domain.WorkflowNode{ID: id, Type: "operator", Position: domain.Position{X: x, Y: y}, Data: domain.WorkflowNodeData{
|
||
Label: label, Category: operator.Category, Description: operator.Description, Inputs: inputs, Outputs: outputs,
|
||
OperatorID: operator.ID, OperatorVersion: operator.Version, OperatorImageID: operator.ImageID, Image: operator.Image,
|
||
ContainerCommand: operator.ContainerCommand, ContainerArgs: operator.ContainerArgs, RuntimeContract: operator.RuntimeContract,
|
||
SkillDefinition: operator.SkillDefinition, PublicationStatus: operator.PublicationStatus, GenerationSource: operator.GenerationSource,
|
||
PublicationEvidence: operator.PublicationEvidence, Hyperparams: operator.Hyperparams, CPU: cpu, Memory: memory, GPU: gpu,
|
||
SharedMemorySize: sharedMemory,
|
||
}}
|
||
}
|
||
|
||
func fanyuMultiportNode(id string, label string, operator domain.OperatorRecord, x float64, y float64) domain.WorkflowNode {
|
||
cpu, memory, gpu, sharedMemory := "", "", "", ""
|
||
if operator.Resources != nil {
|
||
cpu = operator.Resources.CPULimit
|
||
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 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 (server *server) ensureFanyuDeliveryTemplate(ctx context.Context, organizationID string) error {
|
||
organizationID = normalizedOrganizationID(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
|
||
}
|
||
return server.ensureFanyuConvenienceStoreAnnotationTemplates(ctx, organizationID)
|
||
}
|
||
|
||
func (server *server) ensureFanyuConvenienceStoreAnnotationTemplates(ctx context.Context, organizationID string) error {
|
||
organizationID = normalizedOrganizationID(organizationID)
|
||
for version := 1; version <= 5; 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)
|
||
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
|
||
}
|
||
// 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
|
||
}
|
||
|
||
// 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))
|
||
annotationWorkgroupID := strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID"))
|
||
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_WORKGROUP_ID": annotationWorkgroupID, "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 strings.TrimSpace(annotationWorkgroupID) == "" {
|
||
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)
|
||
annotationWorkgroupID := strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID"))
|
||
nodes := []domain.WorkflowNode{
|
||
fanyuMultiportNode("fanyu-v54-directory", "目录读取(多端口)", operators[operatorIDs[0]], 0, 260),
|
||
fanyuMultiportNodeWithHyperparams("fanyu-v54-normalize", "Orbbec Ego 左相机标准化(多端口)", operators[operatorIDs[1]], 260, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
|
||
fanyuMultiportNodeWithHyperparams("fanyu-v54-face-blur", "人脸脱敏(多端口)", operators[operatorIDs[2]], 550, 260, map[string]string{"PRESERVE_AUDIO": "true", "PRESERVE_PTS": "true", "REQUIRE_DETECTIONS": "true"}),
|
||
fanyuMultiportNodeWithHyperparams("fanyu-v54-rough-cut", "Qwen3-VL 手部行为语义粗切(多端口)", operators[operatorIDs[3]], 820, 260, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "18", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
|
||
fanyuMultiportNodeWithHyperparams("fanyu-v54-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认(多端口)", operators[operatorIDs[4]], 1110, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_WORKGROUP_ID": annotationWorkgroupID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
|
||
fanyuMultiportNodeWithHyperparams("fanyu-v54-package", "人工聚合确认后打包(多端口)", operators[operatorIDs[5]], 1400, 260, map[string]string{"REQUIRE_HEADPOSE": "false", "POSE_FREE": "true", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
|
||
}
|
||
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 annotationWorkgroupID == "" || len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
|
||
return nil
|
||
}
|
||
release := domain.WorkflowReleaseRecord{ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 4, Name: template.Name, Description: template.Description, Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, Capabilities: []string{"directory_input", "multiport_artifact_contract", "qwen3vl_behavior_rough_cut", "human_cut_adjustment", "human_cut_review", "human_semantic_annotation", "human_semantic_review", "human_acceptance", "final_segment_package"}, RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template), ReleaseNotes: "v5.4 explicit multiport data contract; PTS-grounded Qwen and four-stage human loop; pose-free direct package", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now}
|
||
return server.store.UpsertWorkflowRelease(ctx, release)
|
||
}
|
||
|
||
// 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)
|
||
annotationWorkgroupID := strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID"))
|
||
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_WORKGROUP_ID": annotationWorkgroupID, "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 annotationWorkgroupID == "" || 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)
|
||
annotationWorkgroupID := strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID"))
|
||
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": "true",
|
||
}
|
||
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_WORKGROUP_ID": annotationWorkgroupID, "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 annotationWorkgroupID == "" || 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 corrects the business meaning of the pose
|
||
// branches: WiLoR is hand-annotation prelabel evidence (标手辅助), while
|
||
// 6DRepNet is a rendered HeadPose prelabel. Both are reviewed in the human gate
|
||
// before their per-segment data is included in the delivery package.
|
||
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 手部预标(标手辅助)"
|
||
node.Data.Description = "使用 WiLoR 生成手部位置与姿态预标和叠加视频,结果必须进入人工质检,不能直接作为最终标手结果。"
|
||
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 = "人工调切→语义/标手质检→聚合确认"
|
||
node.Data.Description = "人工完成调切、剪切审核和语义标注,并对 HeadPose 与手部预标渲染结果进行质检后聚合确认。"
|
||
case "fanyu-v56-package":
|
||
node.Data.Label = "双目同步裁切 + 已质检预标交付"
|
||
}
|
||
}
|
||
edges := append([]domain.WorkflowEdge(nil), base.Edges...)
|
||
edges = append(edges,
|
||
fanyuEdge("fanyu-v57-e22", "fanyu-v56-headpose", "out-1", "fanyu-v56-human", "headpose"),
|
||
fanyuEdge("fanyu-v57-e23", "fanyu-v56-handpose", "out-1", "fanyu-v56-human", "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-双目裁切与手/头预标质检交付-v5.7",
|
||
Description: "左右相机去畸变和脱敏后同步裁切;6DRepNet HeadPose 与 WiLoR 手部预标(标手辅助)生成可视化证据并进入人工质检,通过后再按最终边界裁切预标数据进入交付包。",
|
||
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
|
||
}
|
||
for _, node := range nodes {
|
||
if node.ID != "fanyu-v56-human" {
|
||
continue
|
||
}
|
||
for _, parameter := range node.Data.Hyperparams {
|
||
if parameter.Key == "ANNOTATION_WORKGROUP_ID" && strings.TrimSpace(fmt.Sprint(parameter.Value)) == "" {
|
||
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_prelabel_render", "hand_annotation_prelabel", "human_prelabel_review", "human_semantic_review", "human_acceptance", "stereo_synchronized_crop", "stereo_reviewed_prelabel_package"},
|
||
RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template),
|
||
ReleaseNotes: "v5.7 reclassifies WiLoR as hand-annotation prelabel evidence, adds browser-rendered HeadPose evidence, and routes both prelabels through human quality review before packaging",
|
||
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)
|
||
}
|