forked from longtao.wu/droboticflow
130 lines
6.4 KiB
Go
130 lines
6.4 KiB
Go
package plugins
|
|
|
|
import (
|
|
"sort"
|
|
"strings"
|
|
|
|
"droboticflow/internal/domain"
|
|
)
|
|
|
|
const (
|
|
HumanLoopCoreID = "human-loop-core"
|
|
AnnotationQAID = "annotation-qa"
|
|
)
|
|
|
|
var builtin = map[string]domain.PluginManifest{
|
|
HumanLoopCoreID: {
|
|
ID: HumanLoopCoreID, Name: "Human Loop Core", Version: "1.0.0", RequiredCoreVersion: ">=0.1.0", System: true,
|
|
WorkflowCapabilities: []string{"human_approval"},
|
|
OperatorIDs: []string{"operator-builtin-human-review"},
|
|
Permissions: []string{"human.items.read", "human.items.write", "human.decisions.write"},
|
|
},
|
|
AnnotationQAID: {
|
|
ID: AnnotationQAID, Name: "Annotation QA", Version: "1.0.0", RequiredCoreVersion: ">=0.1.0",
|
|
Routes: []domain.PluginRouteContribution{
|
|
{ID: "clip", Path: "/plugins/annotation-qa/workflows/:workflowId/clip", Label: "人工调切", RequiredRoles: []string{"admin", "organization_admin", "member", "cutter"}},
|
|
{ID: "clip-quality", Path: "/plugins/annotation-qa/workflows/:workflowId/clip-quality", Label: "剪切审核", RequiredRoles: []string{"admin", "organization_admin", "member", "annotator"}},
|
|
{ID: "annotate", Path: "/plugins/annotation-qa/workflows/:workflowId/annotate", Label: "真实切分与语义标注", RequiredRoles: []string{"admin", "organization_admin", "member", "annotator"}},
|
|
{ID: "quality", Path: "/plugins/annotation-qa/workflows/:workflowId/quality", Label: "切分与标注审核", RequiredRoles: []string{"admin", "organization_admin", "member", "quality_reviewer"}},
|
|
{ID: "acceptance", Path: "/plugins/annotation-qa/workflows/:workflowId/acceptance", Label: "最终验收", RequiredRoles: []string{"admin", "organization_admin", "member", "acceptance_reviewer"}},
|
|
{ID: "item", Path: "/plugins/annotation-qa/items/:itemId", Label: "标注任务详情"},
|
|
},
|
|
Navigation: []domain.PluginNavigationContribution{
|
|
{ID: "annotate", Label: "切分与语义标注", Path: "/plugins/annotation-qa/workflows/all/annotate", Icon: "tags", Order: 10, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "organization_admin", "member", "annotator"}},
|
|
{ID: "quality", Label: "切分与标注审核", Path: "/plugins/annotation-qa/workflows/all/quality", Icon: "clipboard-check", Order: 20, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "organization_admin", "member", "quality_reviewer"}},
|
|
{ID: "acceptance", Label: "最终验收", Path: "/plugins/annotation-qa/workflows/all/acceptance", Icon: "shield-check", Order: 50, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "organization_admin", "member", "acceptance_reviewer"}},
|
|
},
|
|
WorkflowCapabilities: []string{"human_cut_adjustment", "human_cut_review", "human_annotation", "human_quality_review", "human_acceptance"},
|
|
OperatorIDs: []string{
|
|
"operator-builtin-annotation-gate",
|
|
"operator-builtin-audit-sample",
|
|
"operator-builtin-semantic-prelabel",
|
|
"operator-builtin-ms-swift-dataset-export",
|
|
},
|
|
Permissions: []string{"annotation.tasks.read", "annotation.tasks.write", "annotation.reviews.write", "annotation.acceptance.write"},
|
|
ConfigSchema: map[string]any{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"releasePolicy": map[string]any{"type": "string", "enum": []string{"accepted_partition", "all_accepted"}, "default": "accepted_partition"},
|
|
"partitionMaxItems": map[string]any{"type": "integer", "minimum": 1, "maximum": 1000, "default": 32},
|
|
"partitionMaxWaitSeconds": map[string]any{"type": "integer", "minimum": 1, "maximum": 3600, "default": 60},
|
|
"maxReworkRounds": map[string]any{"type": "integer", "minimum": 1, "maximum": 100, "default": 5},
|
|
},
|
|
},
|
|
Viewers: []domain.PluginViewerContribution{
|
|
{ID: "native-video", PreviewKinds: []string{"video"}},
|
|
{ID: "rerun", PreviewKinds: []string{"rerun", "lerobot", "mcap", "rosbag"}, Optional: true},
|
|
},
|
|
},
|
|
}
|
|
|
|
func Get(id string) (domain.PluginManifest, bool) {
|
|
item, ok := builtin[strings.TrimSpace(id)]
|
|
return item, ok
|
|
}
|
|
|
|
func List() []domain.PluginManifest {
|
|
items := make([]domain.PluginManifest, 0, len(builtin))
|
|
for _, item := range builtin {
|
|
items = append(items, item)
|
|
}
|
|
sort.Slice(items, func(i, j int) bool { return items[i].ID < items[j].ID })
|
|
return items
|
|
}
|
|
|
|
func RequiredByWorkflow(workflow domain.WorkflowRecord, pluginID string) bool {
|
|
if pluginID == HumanLoopCoreID {
|
|
for _, node := range workflow.Nodes {
|
|
if domain.NodeRequiresAudit(node) || domain.NodeRequiresAnnotation(node) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
if pluginID == AnnotationQAID {
|
|
for _, node := range workflow.Nodes {
|
|
if domain.NodeRequiresAnnotation(node) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func WorkflowCapabilities(workflow domain.WorkflowRecord, annotationEnabled bool) []domain.WorkflowCapability {
|
|
if !annotationEnabled || !RequiredByWorkflow(workflow, AnnotationQAID) {
|
|
return nil
|
|
}
|
|
base := "/plugins/annotation-qa/workflows/" + workflow.ID
|
|
if workflowUsesCombinedAnnotationQA(workflow) {
|
|
return []domain.WorkflowCapability{
|
|
{ID: "human_annotation", PluginID: AnnotationQAID, Label: "真实切分与语义标注", Path: base + "/annotate"},
|
|
{ID: "human_quality_review", PluginID: AnnotationQAID, Label: "切分与标注审核", Path: base + "/quality"},
|
|
{ID: "human_acceptance", PluginID: AnnotationQAID, Label: "整包验收", Path: base + "/acceptance"},
|
|
}
|
|
}
|
|
return []domain.WorkflowCapability{
|
|
{ID: "human_cut_adjustment", PluginID: AnnotationQAID, Label: "人工调切", Path: base + "/clip"},
|
|
{ID: "human_cut_review", PluginID: AnnotationQAID, Label: "剪切审核", Path: base + "/clip-quality"},
|
|
{ID: "human_annotation", PluginID: AnnotationQAID, Label: "人工标注", Path: base + "/annotate"},
|
|
{ID: "human_quality_review", PluginID: AnnotationQAID, Label: "人工质检", Path: base + "/quality"},
|
|
{ID: "human_acceptance", PluginID: AnnotationQAID, Label: "验收", Path: base + "/acceptance"},
|
|
}
|
|
}
|
|
|
|
func workflowUsesCombinedAnnotationQA(workflow domain.WorkflowRecord) bool {
|
|
if workflow.DefinitionVersion < 8 {
|
|
return false
|
|
}
|
|
for _, node := range workflow.Nodes {
|
|
if strings.TrimSpace(node.Data.OperatorID) != "operator-builtin-annotation-gate" {
|
|
continue
|
|
}
|
|
for _, parameter := range node.Data.Hyperparams {
|
|
if parameter.Key == "ANNOTATION_TEMPLATE_ID" && strings.Contains(strings.ToLower(strings.TrimSpace(parameter.Value)), "convenience-store-v6") {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|