forked from longtao.wu/droboticflow
✨ Connect native annotation workflow gate
This commit is contained in:
parent
d482ac015e
commit
8aaa50fe3f
@ -22,6 +22,35 @@
|
||||
|
||||
模板必须发布后才能创建任务。时间段必须位于 clip 范围内、不能重叠,置信度必须位于 `[0, 1]`。质检或验收拒绝会把任务转为 `rework` 并指向下一 revision,不在工作流 DAG 中建立环。
|
||||
|
||||
## 原生工作流 Annotation Gate
|
||||
|
||||
人工审核节点配置 `REVIEW_MODE=annotation` 后成为原生标注门,另外需要:
|
||||
|
||||
- `ANNOTATION_TEMPLATE_ID`:当前项目中已发布的模板。
|
||||
- `ANNOTATION_WORKGROUP_ID`:目标供应商分组。
|
||||
- `ANNOTATION_ASSIGNED_USER_ID`:可选的首轮标注员。
|
||||
|
||||
Worker 到达该节点后不会启动 Kubernetes Job,也不会创建通用 AuditTask。它会从上游 `clips-manifest.json`、视频 artifact 和预标 JSON 自动按片段创建 AnnotationTask,并写入 `projectId`、`dataTaskId`、`workflowId`、`runId`、`nodeId`、`artifactId`。Run 保持 `waiting_for_audit`,直到该节点下所有任务完成首轮 revision、质检和最终验收。
|
||||
|
||||
最终验收通过后,Worker 生成 `droboticflow.annotation.accepted/v1` 的 `annotations-manifest.json`,记录模板版本、人工 revision、片段、artifact 和 Run lineage,然后从节点 `approved` 输出恢复同一个 Run。未选择的分支标记为跳过,不启动空上传 Job;质检或验收打回仅创建新 revision。
|
||||
|
||||
`/annotation-operations` 支持通过以下参数从项目或监控页深链进入:
|
||||
|
||||
`projectId`、`dataTaskId`、`workflowId`、`runId`、`nodeId`、`artifactId`、`taskId`。
|
||||
|
||||
## 时间轴交互
|
||||
|
||||
标注任务使用真实 artifact 视频预览,并提供:
|
||||
|
||||
- 拖动整个语义片段;
|
||||
- 拖动左右把手调整起止时间;
|
||||
- 默认 0.1 秒吸附、方向键微调、Shift 加速;
|
||||
- 播放头与视频时间同步;
|
||||
- 1–8 倍横向缩放;
|
||||
- 选中后独立删除,避免点击片段即删除。
|
||||
|
||||
拖动和缩放在相邻片段及 clip 边界内自动限位,提交 revision 时仍由后端执行范围、重叠和置信度校验。
|
||||
|
||||
## 工作量口径
|
||||
|
||||
首次 revision 产生 `outputDelta=1`;返工 revision 记录工时和返工次数,但 `outputDelta=0`,因此不会重复增加正式产出。质检、验收及拒绝原因分别记录为不可变工作量事件,汇总可按用户、供应商、分组和模板版本查询。
|
||||
|
||||
@ -405,8 +405,10 @@ func (server *server) handleAnnotationTemplatePublish(writer http.ResponseWriter
|
||||
|
||||
type annotationTaskInput struct {
|
||||
ProjectID string `json:"projectId"`
|
||||
DataTaskID string `json:"dataTaskId,omitempty"`
|
||||
WorkflowID string `json:"workflowId,omitempty"`
|
||||
RunID string `json:"runId,omitempty"`
|
||||
NodeID string `json:"nodeId,omitempty"`
|
||||
ArtifactID string `json:"artifactId,omitempty"`
|
||||
SourceVideo string `json:"sourceVideo"`
|
||||
ClipStart float64 `json:"clipStart"`
|
||||
@ -421,6 +423,10 @@ func (server *server) handleAnnotationTasksList(writer http.ResponseWriter, requ
|
||||
status := domain.AnnotationTaskStatus(strings.TrimSpace(request.URL.Query().Get("status")))
|
||||
workgroupID := strings.TrimSpace(request.URL.Query().Get("workgroupId"))
|
||||
vendorID := strings.TrimSpace(request.URL.Query().Get("vendorId"))
|
||||
workflowID := strings.TrimSpace(request.URL.Query().Get("workflowId"))
|
||||
runID := strings.TrimSpace(request.URL.Query().Get("runId"))
|
||||
nodeID := strings.TrimSpace(request.URL.Query().Get("nodeId"))
|
||||
artifactID := strings.TrimSpace(request.URL.Query().Get("artifactId"))
|
||||
items, err := server.store.ListAnnotationTasks(request.Context(), server.requestOrganizationID(request), projectID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
@ -446,6 +452,18 @@ func (server *server) handleAnnotationTasksList(writer http.ResponseWriter, requ
|
||||
if vendorID != "" && item.VendorID != vendorID {
|
||||
continue
|
||||
}
|
||||
if workflowID != "" && item.WorkflowID != workflowID {
|
||||
continue
|
||||
}
|
||||
if runID != "" && item.RunID != runID {
|
||||
continue
|
||||
}
|
||||
if nodeID != "" && item.NodeID != nodeID {
|
||||
continue
|
||||
}
|
||||
if artifactID != "" && item.ArtifactID != artifactID {
|
||||
continue
|
||||
}
|
||||
if !annotationManager(principal) && !membershipAllowsTask(memberships, item) {
|
||||
continue
|
||||
}
|
||||
@ -482,6 +500,11 @@ func (server *server) handleAnnotationTaskCreate(writer http.ResponseWriter, req
|
||||
return
|
||||
}
|
||||
payload.ProjectID = strings.TrimSpace(payload.ProjectID)
|
||||
payload.DataTaskID = strings.TrimSpace(payload.DataTaskID)
|
||||
payload.WorkflowID = strings.TrimSpace(payload.WorkflowID)
|
||||
payload.RunID = strings.TrimSpace(payload.RunID)
|
||||
payload.NodeID = strings.TrimSpace(payload.NodeID)
|
||||
payload.ArtifactID = strings.TrimSpace(payload.ArtifactID)
|
||||
payload.SourceVideo = strings.TrimSpace(payload.SourceVideo)
|
||||
payload.TemplateID = strings.TrimSpace(payload.TemplateID)
|
||||
payload.WorkgroupID = strings.TrimSpace(payload.WorkgroupID)
|
||||
@ -508,9 +531,11 @@ func (server *server) handleAnnotationTaskCreate(writer http.ResponseWriter, req
|
||||
ID: domain.NewID("annotation-task"),
|
||||
OrganizationID: project.OrganizationID,
|
||||
ProjectID: project.ID,
|
||||
WorkflowID: strings.TrimSpace(payload.WorkflowID),
|
||||
RunID: strings.TrimSpace(payload.RunID),
|
||||
ArtifactID: strings.TrimSpace(payload.ArtifactID),
|
||||
DataTaskID: payload.DataTaskID,
|
||||
WorkflowID: payload.WorkflowID,
|
||||
RunID: payload.RunID,
|
||||
NodeID: payload.NodeID,
|
||||
ArtifactID: payload.ArtifactID,
|
||||
SourceVideo: payload.SourceVideo,
|
||||
ClipStart: payload.ClipStart,
|
||||
ClipEnd: payload.ClipEnd,
|
||||
@ -646,6 +671,39 @@ type annotationReviewInput struct {
|
||||
DurationSeconds int64 `json:"durationSeconds,omitempty"`
|
||||
}
|
||||
|
||||
func (server *server) queueAcceptedAnnotationGateRun(ctx context.Context, task domain.AnnotationTaskRecord) error {
|
||||
if task.Status != domain.AnnotationTaskStatusAccepted || strings.TrimSpace(task.RunID) == "" || strings.TrimSpace(task.NodeID) == "" {
|
||||
return nil
|
||||
}
|
||||
tasks, err := server.store.ListAnnotationTasks(ctx, task.OrganizationID, task.ProjectID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
matched := 0
|
||||
for _, candidate := range tasks {
|
||||
if candidate.RunID != task.RunID || candidate.NodeID != task.NodeID {
|
||||
continue
|
||||
}
|
||||
matched++
|
||||
if candidate.Status != domain.AnnotationTaskStatusAccepted {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if matched == 0 {
|
||||
return nil
|
||||
}
|
||||
run, err := server.store.GetRun(ctx, task.RunID)
|
||||
if err != nil || run == nil {
|
||||
return err
|
||||
}
|
||||
if run.Status != domain.RunStatusWaitingForAudit || run.CurrentNodeID != task.NodeID {
|
||||
return nil
|
||||
}
|
||||
run.Status = domain.RunStatusQueued
|
||||
run.UpdatedAt = nowISO()
|
||||
return server.store.UpsertRun(ctx, *run)
|
||||
}
|
||||
|
||||
func (server *server) handleAnnotationReviewCreate(writer http.ResponseWriter, request *http.Request) {
|
||||
task, err := server.store.GetAnnotationTask(request.Context(), chi.URLParam(request, "id"))
|
||||
if err != nil {
|
||||
@ -716,6 +774,10 @@ func (server *server) handleAnnotationReviewCreate(writer http.ResponseWriter, r
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if err := server.queueAcceptedAnnotationGateRun(request.Context(), *task); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, fmt.Errorf("resume annotation workflow: %w", err))
|
||||
return
|
||||
}
|
||||
eventType := string(payload.Stage) + "_" + string(payload.Decision)
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID,
|
||||
|
||||
@ -112,6 +112,61 @@ func TestCollectionTaskAcceptsFileCountOnlyTarget(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAcceptedAnnotationGateQueuesRunOnlyAfterAllTasksAccepted(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
project, err := dataStore.CreateProject(ctx, domain.CreateProjectInput{Name: "Annotation Gate"})
|
||||
if err != nil {
|
||||
t.Fatalf("create project: %v", err)
|
||||
}
|
||||
workflow, err := dataStore.CreateWorkflow(ctx, domain.CreateWorkflowInput{
|
||||
ProjectID: project.ID,
|
||||
Name: "Annotation Gate",
|
||||
Type: domain.WorkflowTypeBatch,
|
||||
Nodes: []domain.WorkflowNode{{ID: "annotation-gate", Type: "operator", Data: domain.WorkflowNodeData{Label: "逐段语义标注"}}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create workflow: %v", err)
|
||||
}
|
||||
run, err := dataStore.CreateRun(ctx, workflow.ID, domain.RunTriggerManual)
|
||||
if err != nil {
|
||||
t.Fatalf("create run: %v", err)
|
||||
}
|
||||
run.Status = domain.RunStatusWaitingForAudit
|
||||
run.CurrentNodeID = "annotation-gate"
|
||||
if err := dataStore.UpsertRun(ctx, *run); err != nil {
|
||||
t.Fatalf("upsert waiting run: %v", err)
|
||||
}
|
||||
tasks := []domain.AnnotationTaskRecord{
|
||||
{ID: "annotation-1", OrganizationID: project.OrganizationID, ProjectID: project.ID, RunID: run.ID, NodeID: "annotation-gate", Status: domain.AnnotationTaskStatusAccepted},
|
||||
{ID: "annotation-2", OrganizationID: project.OrganizationID, ProjectID: project.ID, RunID: run.ID, NodeID: "annotation-gate", Status: domain.AnnotationTaskStatusPendingAcceptance},
|
||||
}
|
||||
for _, item := range tasks {
|
||||
if err := dataStore.UpsertAnnotationTask(ctx, item); err != nil {
|
||||
t.Fatalf("upsert annotation task: %v", err)
|
||||
}
|
||||
}
|
||||
server := &server{store: dataStore}
|
||||
if err := server.queueAcceptedAnnotationGateRun(ctx, tasks[0]); err != nil {
|
||||
t.Fatalf("queue with pending sibling: %v", err)
|
||||
}
|
||||
stillWaiting, _ := dataStore.GetRun(ctx, run.ID)
|
||||
if stillWaiting.Status != domain.RunStatusWaitingForAudit {
|
||||
t.Fatalf("run should wait for every task, got %s", stillWaiting.Status)
|
||||
}
|
||||
tasks[1].Status = domain.AnnotationTaskStatusAccepted
|
||||
if err := dataStore.UpsertAnnotationTask(ctx, tasks[1]); err != nil {
|
||||
t.Fatalf("accept final annotation task: %v", err)
|
||||
}
|
||||
if err := server.queueAcceptedAnnotationGateRun(ctx, tasks[1]); err != nil {
|
||||
t.Fatalf("queue accepted gate: %v", err)
|
||||
}
|
||||
queued, _ := dataStore.GetRun(ctx, run.ID)
|
||||
if queued.Status != domain.RunStatusQueued {
|
||||
t.Fatalf("all accepted tasks should queue the run, got %s", queued.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacySourceCollectionsProduceEstimatedTrajectoryMetrics(t *testing.T) {
|
||||
metrics := legacyMetricsFromExecution(
|
||||
domain.RunRecord{CreatedAt: "2026-07-23T01:00:00Z"},
|
||||
|
||||
@ -111,8 +111,10 @@ type AnnotationTaskRecord struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId,omitempty" bson:"organizationId,omitempty"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
DataTaskID string `json:"dataTaskId,omitempty" bson:"dataTaskId,omitempty"`
|
||||
WorkflowID string `json:"workflowId,omitempty" bson:"workflowId,omitempty"`
|
||||
RunID string `json:"runId,omitempty" bson:"runId,omitempty"`
|
||||
NodeID string `json:"nodeId,omitempty" bson:"nodeId,omitempty"`
|
||||
ArtifactID string `json:"artifactId,omitempty" bson:"artifactId,omitempty"`
|
||||
SourceVideo string `json:"sourceVideo" bson:"sourceVideo"`
|
||||
ClipStart float64 `json:"clipStart" bson:"clipStart"`
|
||||
|
||||
@ -608,6 +608,7 @@ type LightweightOperatorCodeManifest struct {
|
||||
type RunMetadata struct {
|
||||
LightweightOperatorCodeManifests map[string]LightweightOperatorCodeManifest `json:"lightweightOperatorCodeManifests,omitempty" bson:"lightweightOperatorCodeManifests,omitempty"`
|
||||
TrainingInputs []TrainingInputRecord `json:"trainingInputs,omitempty" bson:"trainingInputs,omitempty"`
|
||||
AnnotationTaskIDsByNode map[string][]string `json:"annotationTaskIdsByNode,omitempty" bson:"annotationTaskIdsByNode,omitempty"`
|
||||
}
|
||||
|
||||
// RunFailure is the machine-readable counterpart to RunRecord.Error. Error is
|
||||
|
||||
@ -299,7 +299,22 @@ func GetDecisionOutgoingEdges(edges []WorkflowEdge, nodeID string, decision Audi
|
||||
return outgoing
|
||||
}
|
||||
|
||||
func NodeRequiresAnnotation(node WorkflowNode) bool {
|
||||
if strings.EqualFold(strings.TrimSpace(node.Data.OperatorID), "operator-builtin-annotation-gate") {
|
||||
return true
|
||||
}
|
||||
for _, item := range node.Data.Hyperparams {
|
||||
if strings.EqualFold(strings.TrimSpace(item.Key), "REVIEW_MODE") && strings.EqualFold(strings.TrimSpace(item.Value), "annotation") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func NodeRequiresAudit(node WorkflowNode) bool {
|
||||
if NodeRequiresAnnotation(node) {
|
||||
return false
|
||||
}
|
||||
label := strings.ToLower(node.Data.Label)
|
||||
return node.Data.Category == "HUMAN" || strings.Contains(label, "human review") || strings.Contains(node.Data.Label, "人工审核")
|
||||
}
|
||||
|
||||
19
internal/domain/workflow_annotation_test.go
Normal file
19
internal/domain/workflow_annotation_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
package domain
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestAnnotationReviewModeUsesNativeAnnotationGate(t *testing.T) {
|
||||
node := WorkflowNode{Data: WorkflowNodeData{
|
||||
Label: "逐段语义标注",
|
||||
Category: "HUMAN",
|
||||
Hyperparams: []HyperParam{
|
||||
{Key: "REVIEW_MODE", Value: "annotation"},
|
||||
},
|
||||
}}
|
||||
if !NodeRequiresAnnotation(node) {
|
||||
t.Fatal("annotation review mode should be handled by the native annotation gate")
|
||||
}
|
||||
if NodeRequiresAudit(node) {
|
||||
t.Fatal("annotation gate must not create a generic audit task")
|
||||
}
|
||||
}
|
||||
528
internal/worker/annotation_gate.go
Normal file
528
internal/worker/annotation_gate.go
Normal file
@ -0,0 +1,528 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
type annotationGateConfig struct {
|
||||
TemplateID string
|
||||
WorkgroupID string
|
||||
AssignedUserID string
|
||||
}
|
||||
|
||||
func annotationGateConfigFromNode(node domain.WorkflowNode) annotationGateConfig {
|
||||
params := nodeHyperparamsMap(node)
|
||||
return annotationGateConfig{
|
||||
TemplateID: strings.TrimSpace(params["ANNOTATION_TEMPLATE_ID"]),
|
||||
WorkgroupID: strings.TrimSpace(params["ANNOTATION_WORKGROUP_ID"]),
|
||||
AssignedUserID: strings.TrimSpace(params["ANNOTATION_ASSIGNED_USER_ID"]),
|
||||
}
|
||||
}
|
||||
|
||||
func annotationNumber(value any) (float64, bool) {
|
||||
switch typed := value.(type) {
|
||||
case float64:
|
||||
return typed, true
|
||||
case float32:
|
||||
return float64(typed), true
|
||||
case int:
|
||||
return float64(typed), true
|
||||
case int64:
|
||||
return float64(typed), true
|
||||
case json.Number:
|
||||
parsed, err := typed.Float64()
|
||||
return parsed, err == nil
|
||||
case string:
|
||||
parsed, err := strconv.ParseFloat(strings.TrimSpace(typed), 64)
|
||||
return parsed, err == nil
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func annotationArtifactPayload(artifact domain.ExecutionArtifact) map[string]any {
|
||||
path := strings.TrimSpace(artifact.Path)
|
||||
if path != "" && !strings.Contains(path, "://") && strings.HasSuffix(strings.ToLower(path), ".json") {
|
||||
if payload, err := os.ReadFile(path); err == nil {
|
||||
var decoded map[string]any
|
||||
decoder := json.NewDecoder(strings.NewReader(string(payload)))
|
||||
decoder.UseNumber()
|
||||
if err := decoder.Decode(&decoded); err == nil {
|
||||
return decoded
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(artifact.Data) > 0 {
|
||||
return artifact.Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func annotationClipItems(inputs []domain.ExecutionArtifact) map[string]map[string]any {
|
||||
items := map[string]map[string]any{}
|
||||
for _, artifact := range inputs {
|
||||
if artifact.Name != "clips-manifest.json" {
|
||||
continue
|
||||
}
|
||||
payload := annotationArtifactPayload(artifact)
|
||||
for _, raw := range anySlice(payload["items"]) {
|
||||
item, ok := raw.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
name := strings.TrimSpace(fmt.Sprint(item["clipName"]))
|
||||
if name != "" {
|
||||
items[name] = item
|
||||
}
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func anySlice(value any) []any {
|
||||
switch typed := value.(type) {
|
||||
case []any:
|
||||
return typed
|
||||
case []map[string]any:
|
||||
items := make([]any, 0, len(typed))
|
||||
for _, item := range typed {
|
||||
items = append(items, item)
|
||||
}
|
||||
return items
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func annotationLabel(template domain.AnnotationTemplateRecord, label string) (string, string) {
|
||||
normalized := strings.TrimSpace(label)
|
||||
for _, item := range template.Labels {
|
||||
if strings.EqualFold(strings.TrimSpace(item.Name), normalized) || strings.EqualFold(strings.TrimSpace(item.ID), normalized) {
|
||||
return item.ID, item.Name
|
||||
}
|
||||
for _, alias := range item.Aliases {
|
||||
if strings.EqualFold(strings.TrimSpace(alias), normalized) {
|
||||
return item.ID, item.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
if normalized == "" {
|
||||
return "unlabeled", "未标注"
|
||||
}
|
||||
id := strings.ToLower(normalized)
|
||||
id = strings.NewReplacer(" ", "-", "_", "-", "/", "-").Replace(id)
|
||||
return id, normalized
|
||||
}
|
||||
|
||||
func annotationSegmentsFromActions(actions any, template domain.AnnotationTemplateRecord) []domain.AnnotationSegment {
|
||||
segments := make([]domain.AnnotationSegment, 0)
|
||||
for index, raw := range anySlice(actions) {
|
||||
item, ok := raw.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
start, startOK := annotationNumber(item["start"])
|
||||
end, endOK := annotationNumber(item["end"])
|
||||
if !startOK || !endOK || end <= start {
|
||||
continue
|
||||
}
|
||||
labelID, label := annotationLabel(template, fmt.Sprint(item["label"]))
|
||||
confidence, _ := annotationNumber(item["confidence"])
|
||||
phrases := make([]string, 0)
|
||||
for _, phrase := range anySlice(item["phrases"]) {
|
||||
if text := strings.TrimSpace(fmt.Sprint(phrase)); text != "" {
|
||||
phrases = append(phrases, text)
|
||||
}
|
||||
}
|
||||
segments = append(segments, domain.AnnotationSegment{
|
||||
ID: fmt.Sprintf("prelabel-%03d", index+1),
|
||||
LabelID: labelID,
|
||||
Label: label,
|
||||
Start: start,
|
||||
End: end,
|
||||
Confidence: confidence,
|
||||
Phrases: phrases,
|
||||
Source: "workflow-prelabel",
|
||||
})
|
||||
}
|
||||
return segments
|
||||
}
|
||||
|
||||
func annotationPrelabels(inputs []domain.ExecutionArtifact, template domain.AnnotationTemplateRecord) map[string][]domain.AnnotationSegment {
|
||||
result := map[string][]domain.AnnotationSegment{}
|
||||
for _, artifact := range inputs {
|
||||
payload := annotationArtifactPayload(artifact)
|
||||
if payload == nil {
|
||||
continue
|
||||
}
|
||||
if actions := payload["actions"]; actions != nil {
|
||||
clipID := strings.TrimSpace(fmt.Sprint(payload["clipId"]))
|
||||
if clipID == "" {
|
||||
clipID = strings.TrimSuffix(artifact.Name, filepath.Ext(artifact.Name))
|
||||
clipID = strings.TrimSuffix(clipID, "_annotation")
|
||||
}
|
||||
result[clipID] = annotationSegmentsFromActions(actions, template)
|
||||
}
|
||||
for _, raw := range anySlice(payload["items"]) {
|
||||
item, ok := raw.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
clipID := strings.TrimSpace(fmt.Sprint(item["clipId"]))
|
||||
annotation, _ := item["annotation"].(map[string]any)
|
||||
if clipID != "" && annotation != nil {
|
||||
result[clipID] = annotationSegmentsFromActions(annotation["actions"], template)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func annotationClipRange(item map[string]any, artifact domain.ExecutionArtifact) (float64, float64) {
|
||||
start, _ := annotationNumber(item["startSecond"])
|
||||
end, endOK := annotationNumber(item["endSecond"])
|
||||
if !endOK {
|
||||
if duration, ok := annotationNumber(item["duration"]); ok {
|
||||
end = start + duration
|
||||
endOK = true
|
||||
}
|
||||
}
|
||||
if !endOK && artifact.Data != nil {
|
||||
if preview, ok := artifact.Data["preview"].(map[string]any); ok {
|
||||
if duration, durationOK := annotationNumber(preview["duration"]); durationOK {
|
||||
end = start + duration
|
||||
}
|
||||
}
|
||||
}
|
||||
return start, end
|
||||
}
|
||||
|
||||
func annotationGateTasksForRun(ctx context.Context, runtime *Runtime, run *domain.RunRecord, node domain.WorkflowNode) ([]domain.AnnotationTaskRecord, error) {
|
||||
if runtime == nil || runtime.store == nil || run == nil {
|
||||
return nil, fmt.Errorf("annotation gate runtime is not initialized")
|
||||
}
|
||||
items, err := runtime.store.ListAnnotationTasks(ctx, run.OrganizationID, run.ProjectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filtered := make([]domain.AnnotationTaskRecord, 0)
|
||||
for _, item := range items {
|
||||
if item.RunID == run.ID && item.NodeID == node.ID {
|
||||
filtered = append(filtered, item)
|
||||
}
|
||||
}
|
||||
sort.Slice(filtered, func(left, right int) bool { return filtered[left].ArtifactID < filtered[right].ArtifactID })
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
func (runtime *Runtime) createAnnotationGateTasks(
|
||||
ctx context.Context,
|
||||
run *domain.RunRecord,
|
||||
node domain.WorkflowNode,
|
||||
inputs []domain.ExecutionArtifact,
|
||||
) ([]domain.AnnotationTaskRecord, error) {
|
||||
config := annotationGateConfigFromNode(node)
|
||||
if config.TemplateID == "" || config.WorkgroupID == "" {
|
||||
return nil, fmt.Errorf("annotation gate requires ANNOTATION_TEMPLATE_ID and ANNOTATION_WORKGROUP_ID")
|
||||
}
|
||||
template, err := runtime.store.GetAnnotationTemplate(ctx, config.TemplateID)
|
||||
if err != nil || template == nil {
|
||||
return nil, fmt.Errorf("load annotation template %s: %w", config.TemplateID, err)
|
||||
}
|
||||
group, err := runtime.store.GetAnnotationWorkgroup(ctx, config.WorkgroupID)
|
||||
if err != nil || group == nil {
|
||||
return nil, fmt.Errorf("load annotation workgroup %s: %w", config.WorkgroupID, err)
|
||||
}
|
||||
if template.ProjectID != run.ProjectID || template.Status != domain.AnnotationTemplatePublished || template.OrganizationID != run.OrganizationID || group.OrganizationID != run.OrganizationID {
|
||||
return nil, fmt.Errorf("annotation gate template/workgroup does not belong to the run project and organization")
|
||||
}
|
||||
existing, err := annotationGateTasksForRun(ctx, runtime, run, node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(existing) > 0 {
|
||||
return existing, nil
|
||||
}
|
||||
clips := annotationClipItems(inputs)
|
||||
prelabels := annotationPrelabels(inputs, *template)
|
||||
tasks := make([]domain.AnnotationTaskRecord, 0)
|
||||
for _, artifact := range inputs {
|
||||
if artifact.Type != domain.PortTypeVideo {
|
||||
continue
|
||||
}
|
||||
clipItem, expectedClip := clips[artifact.Name]
|
||||
if len(clips) > 0 && !expectedClip {
|
||||
continue
|
||||
}
|
||||
clipID := strings.TrimSpace(fmt.Sprint(clipItem["clipId"]))
|
||||
if clipID == "" {
|
||||
clipID = strings.TrimSuffix(artifact.Name, filepath.Ext(artifact.Name))
|
||||
}
|
||||
clipStart, clipEnd := annotationClipRange(clipItem, artifact)
|
||||
if clipEnd <= clipStart {
|
||||
return nil, fmt.Errorf("annotation gate cannot resolve clip duration for %s", artifact.Name)
|
||||
}
|
||||
task := domain.AnnotationTaskRecord{
|
||||
ID: domain.NewID("annotation-task"),
|
||||
OrganizationID: run.OrganizationID,
|
||||
ProjectID: run.ProjectID,
|
||||
DataTaskID: run.TaskID,
|
||||
WorkflowID: run.WorkflowID,
|
||||
RunID: run.ID,
|
||||
NodeID: node.ID,
|
||||
ArtifactID: artifact.ID,
|
||||
SourceVideo: fmt.Sprintf("/api/runs/%s/artifacts/%s/content", url.PathEscape(run.ID), url.PathEscape(artifact.ID)),
|
||||
ClipStart: clipStart,
|
||||
ClipEnd: clipEnd,
|
||||
TemplateID: template.ID,
|
||||
TemplateVersion: template.Version,
|
||||
WorkgroupID: group.ID,
|
||||
VendorID: group.VendorID,
|
||||
AssignedUserID: config.AssignedUserID,
|
||||
Status: domain.AnnotationTaskStatusPendingAnnotation,
|
||||
CurrentRevision: 0,
|
||||
CreatedAt: nowISO(),
|
||||
}
|
||||
if err := runtime.store.UpsertAnnotationTask(ctx, task); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
segments := prelabels[clipID]
|
||||
if len(segments) > 0 {
|
||||
if err := runtime.store.UpsertAnnotationRevision(ctx, domain.AnnotationRevisionRecord{
|
||||
ID: domain.NewID("annotation-revision"), OrganizationID: run.OrganizationID, TaskID: task.ID,
|
||||
Revision: 0, TemplateVersion: template.Version, Segments: segments,
|
||||
AuthorUserID: "system", ChangeReason: "workflow prelabel", IsRework: false, CountsAsOutput: false, CreatedAt: nowISO(),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
_ = runtime.store.UpsertAnnotationWorklogEvent(ctx, domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: run.OrganizationID, ProjectID: run.ProjectID,
|
||||
TaskID: task.ID, UserID: config.AssignedUserID, WorkgroupID: group.ID, VendorID: group.VendorID,
|
||||
EventType: "workflow_assigned", TemplateVersion: template.Version, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
})
|
||||
tasks = append(tasks, task)
|
||||
}
|
||||
if len(tasks) == 0 {
|
||||
return nil, fmt.Errorf("annotation gate requires at least one upstream clip video artifact")
|
||||
}
|
||||
if run.Metadata == nil {
|
||||
run.Metadata = &domain.RunMetadata{}
|
||||
}
|
||||
if run.Metadata.AnnotationTaskIDsByNode == nil {
|
||||
run.Metadata.AnnotationTaskIDsByNode = map[string][]string{}
|
||||
}
|
||||
taskIDs := make([]string, 0, len(tasks))
|
||||
for _, task := range tasks {
|
||||
taskIDs = append(taskIDs, task.ID)
|
||||
}
|
||||
run.Metadata.AnnotationTaskIDsByNode[node.ID] = taskIDs
|
||||
return tasks, nil
|
||||
}
|
||||
|
||||
func annotationRevisionActions(revision domain.AnnotationRevisionRecord) ([]map[string]any, []string) {
|
||||
actions := make([]map[string]any, 0, len(revision.Segments))
|
||||
objects := make([]string, 0)
|
||||
seenObjects := map[string]struct{}{}
|
||||
for _, segment := range revision.Segments {
|
||||
actions = append(actions, map[string]any{
|
||||
"id": segment.ID, "labelId": segment.LabelID, "label": segment.Label,
|
||||
"start": segment.Start, "end": segment.End, "confidence": segment.Confidence,
|
||||
"phrases": segment.Phrases, "source": segment.Source,
|
||||
})
|
||||
for _, phrase := range segment.Phrases {
|
||||
if _, exists := seenObjects[phrase]; exists || strings.TrimSpace(phrase) == "" {
|
||||
continue
|
||||
}
|
||||
seenObjects[phrase] = struct{}{}
|
||||
objects = append(objects, phrase)
|
||||
}
|
||||
}
|
||||
return actions, objects
|
||||
}
|
||||
|
||||
func annotationGateOutputPort(node domain.WorkflowNode) (string, string) {
|
||||
for _, output := range node.Data.Outputs {
|
||||
if output.ID == "approved" {
|
||||
return output.ID, output.Name
|
||||
}
|
||||
}
|
||||
if len(node.Data.Outputs) > 0 {
|
||||
return node.Data.Outputs[0].ID, node.Data.Outputs[0].Name
|
||||
}
|
||||
return "approved", "approved"
|
||||
}
|
||||
|
||||
func annotationArtifactSize(size int64) string {
|
||||
if size < 1024 {
|
||||
return fmt.Sprintf("%d B", size)
|
||||
}
|
||||
return fmt.Sprintf("%.1f KiB", float64(size)/1024)
|
||||
}
|
||||
|
||||
func (runtime *Runtime) acceptedAnnotationGateArtifacts(
|
||||
ctx context.Context,
|
||||
run *domain.RunRecord,
|
||||
node domain.WorkflowNode,
|
||||
execution domain.NodeExecutionRecord,
|
||||
) ([]domain.ExecutionArtifact, bool, error) {
|
||||
tasks, err := annotationGateTasksForRun(ctx, runtime, run, node)
|
||||
if err != nil || len(tasks) == 0 {
|
||||
return nil, false, err
|
||||
}
|
||||
for _, task := range tasks {
|
||||
if task.Status != domain.AnnotationTaskStatusAccepted {
|
||||
return nil, false, nil
|
||||
}
|
||||
}
|
||||
clips := annotationClipItems(execution.InputArtifacts)
|
||||
items := make([]map[string]any, 0, len(tasks))
|
||||
for _, task := range tasks {
|
||||
revisions, err := runtime.store.ListAnnotationRevisions(ctx, task.OrganizationID, task.ID)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
var acceptedRevision *domain.AnnotationRevisionRecord
|
||||
for index := range revisions {
|
||||
if revisions[index].Revision == task.CurrentRevision {
|
||||
acceptedRevision = &revisions[index]
|
||||
}
|
||||
}
|
||||
if acceptedRevision == nil || acceptedRevision.Revision <= 0 {
|
||||
return nil, false, fmt.Errorf("accepted annotation task %s has no accepted revision", task.ID)
|
||||
}
|
||||
var sourceArtifact *domain.ExecutionArtifact
|
||||
for index := range execution.InputArtifacts {
|
||||
if execution.InputArtifacts[index].ID == task.ArtifactID {
|
||||
sourceArtifact = &execution.InputArtifacts[index]
|
||||
break
|
||||
}
|
||||
}
|
||||
if sourceArtifact == nil {
|
||||
return nil, false, fmt.Errorf("annotation task %s source artifact is unavailable", task.ID)
|
||||
}
|
||||
base := map[string]any{}
|
||||
for key, value := range clips[sourceArtifact.Name] {
|
||||
base[key] = value
|
||||
}
|
||||
clipID := strings.TrimSpace(fmt.Sprint(base["clipId"]))
|
||||
if clipID == "" {
|
||||
clipID = strings.TrimSuffix(sourceArtifact.Name, filepath.Ext(sourceArtifact.Name))
|
||||
}
|
||||
actions, objects := annotationRevisionActions(*acceptedRevision)
|
||||
base["clipId"] = clipID
|
||||
base["clipName"] = sourceArtifact.Name
|
||||
base["clipPath"] = sourceArtifact.Path
|
||||
base["startSecond"] = task.ClipStart
|
||||
base["endSecond"] = task.ClipEnd
|
||||
base["duration"] = task.ClipEnd - task.ClipStart
|
||||
base["annotationFile"] = clipID + "_annotation.json"
|
||||
base["annotation"] = map[string]any{
|
||||
"schemaVersion": "droboticflow.annotation.revision/v1",
|
||||
"taskId": task.ID, "revision": acceptedRevision.Revision, "templateVersion": acceptedRevision.TemplateVersion,
|
||||
"clipId": clipID, "sourceVideo": sourceArtifact.Name, "duration": task.ClipEnd - task.ClipStart,
|
||||
"actions": actions, "objects": objects,
|
||||
}
|
||||
items = append(items, base)
|
||||
}
|
||||
manifest := map[string]any{
|
||||
"schemaVersion": "droboticflow.annotation.accepted/v1",
|
||||
"datasetType": "x-platform-annotations",
|
||||
"annotationCount": len(items),
|
||||
"projectId": run.ProjectID, "dataTaskId": run.TaskID, "workflowId": run.WorkflowID, "runId": run.ID, "nodeId": node.ID,
|
||||
"items": items,
|
||||
}
|
||||
workspace, err := prepareNodeWorkspace(runtime.workspaceRoot, run.ID, node.ID)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
payload, err := json.MarshalIndent(manifest, "", " ")
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
payload = append(payload, '\n')
|
||||
manifestPath := filepath.Join(workspace.OutputDir, "annotations-manifest.json")
|
||||
if err := os.WriteFile(manifestPath, payload, 0o644); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
digest := sha256.Sum256(payload)
|
||||
portID, portName := annotationGateOutputPort(node)
|
||||
accepted := make([]domain.ExecutionArtifact, 0, len(execution.InputArtifacts)+1)
|
||||
for _, artifact := range execution.InputArtifacts {
|
||||
if artifact.Name == "annotations-manifest.json" || strings.HasSuffix(artifact.Name, "_annotation.json") {
|
||||
continue
|
||||
}
|
||||
copy := cloneArtifact(artifact)
|
||||
copy.PortID = portID
|
||||
copy.PortName = portName
|
||||
accepted = append(accepted, copy)
|
||||
}
|
||||
accepted = append(accepted, domain.ExecutionArtifact{
|
||||
ID: fmt.Sprintf("%s-%s-%s-annotations-manifest.json", run.ID, node.ID, portID),
|
||||
RunID: run.ID, NodeID: node.ID, PortID: portID, PortName: portName,
|
||||
Name: "annotations-manifest.json", Type: domain.PortTypeJSON,
|
||||
Size: annotationArtifactSize(int64(len(payload))), SizeBytes: int64(len(payload)), Path: manifestPath,
|
||||
Metadata: &domain.ArtifactMetadata{SHA256: hex.EncodeToString(digest[:]), MimeType: "application/json"},
|
||||
Data: manifest,
|
||||
})
|
||||
return accepted, true, nil
|
||||
}
|
||||
|
||||
func (runtime *Runtime) resolveAcceptedAnnotationGate(
|
||||
ctx context.Context,
|
||||
workflow domain.WorkflowRecord,
|
||||
run *domain.RunRecord,
|
||||
node domain.WorkflowNode,
|
||||
executionMap map[string]domain.NodeExecutionRecord,
|
||||
allowed map[string]struct{},
|
||||
) (bool, []string, *domain.NodeExecutionRecord, error) {
|
||||
execution := executionMap[node.ID]
|
||||
artifacts, accepted, err := runtime.acceptedAnnotationGateArtifacts(ctx, run, node, execution)
|
||||
if err != nil || !accepted {
|
||||
return false, nil, nil, err
|
||||
}
|
||||
execution.NodeID = node.ID
|
||||
execution.NodeLabel = node.Data.Label
|
||||
execution.Status = domain.NodeExecutionStatusCompleted
|
||||
execution.EndedAt = nowISO()
|
||||
execution.Artifacts = artifacts
|
||||
execution.Logs = append(execution.Logs, logEntry("INFO", "All annotation tasks accepted; resuming workflow", node.Data.Label))
|
||||
tasks, err := annotationGateTasksForRun(ctx, runtime, run, node)
|
||||
if err != nil {
|
||||
return false, nil, nil, err
|
||||
}
|
||||
count := int64(len(tasks))
|
||||
duration := 0.0
|
||||
for _, task := range tasks {
|
||||
duration += task.ClipEnd - task.ClipStart
|
||||
}
|
||||
execution.DataMetrics = &domain.DataMetricsRecord{
|
||||
SchemaVersion: 1,
|
||||
Stage: domain.DataMetricStageAnnotate,
|
||||
Input: domain.DataVolume{TrajectoryCount: &count},
|
||||
Output: domain.DataVolume{TrajectoryCount: &count, DurationSeconds: &duration},
|
||||
TrainReady: domain.DataVolume{TrajectoryCount: &count, DurationSeconds: &duration},
|
||||
Quality: domain.DataMetricQualityExact,
|
||||
OccurredAt: execution.EndedAt,
|
||||
}
|
||||
decisionEdges := domain.GetDecisionOutgoingEdges(workflow.Edges, node.ID, domain.AuditStatusApproved)
|
||||
executionMap[node.ID] = execution
|
||||
applyExecution(run, execution)
|
||||
markUnselectedAuditBranchesCompleted(workflow, executionMap, run, node.ID, decisionEdges, domain.AuditStatusApproved, allowed)
|
||||
run.Status = domain.RunStatusRunning
|
||||
syncCurrentNodeID(run)
|
||||
run.UpdatedAt = nowISO()
|
||||
return true, edgeTargets(decisionEdges), &execution, nil
|
||||
}
|
||||
@ -2634,57 +2634,76 @@ func (runtime *Runtime) processRun(ctx context.Context, claimed *domain.RunRecor
|
||||
auditQueue := make([]string, 0)
|
||||
|
||||
if currentRun.CurrentNodeID != "" {
|
||||
tasks, err := runtime.store.ListAuditTasks(ctx, "all")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, task := range tasks {
|
||||
if task.RunID == currentRun.ID && task.NodeID == currentRun.CurrentNodeID && task.Status != domain.AuditStatusPending {
|
||||
node := domain.GetNodeByID(workflow.Nodes, currentRun.CurrentNodeID)
|
||||
if node != nil {
|
||||
execution := executionMap[node.ID]
|
||||
execution.NodeID = node.ID
|
||||
execution.NodeLabel = node.Data.Label
|
||||
execution.Status = domain.NodeExecutionStatusCompleted
|
||||
execution.EndedAt = nowISO()
|
||||
execution.Logs = append(execution.Logs, logEntry("INFO", fmt.Sprintf("Audit decision: %s", task.Status), node.Data.Label))
|
||||
resolvedNode := runtime.resolveNodeBusinessStage(ctx, currentRun, *node)
|
||||
if resolvedNode.Data.BusinessStage == domain.DataMetricStageAudit {
|
||||
volume := upstreamBusinessVolume(*workflow, executionMap, node.ID)
|
||||
execution.DataMetrics = &domain.DataMetricsRecord{
|
||||
SchemaVersion: 1,
|
||||
Stage: domain.DataMetricStageAudit,
|
||||
Input: volume,
|
||||
Output: volume,
|
||||
Quality: domain.DataMetricQualityExact,
|
||||
OccurredAt: execution.EndedAt,
|
||||
}
|
||||
if task.Status == domain.AuditStatusApproved {
|
||||
execution.DataMetrics.TrainReady = volume
|
||||
} else {
|
||||
execution.DataMetrics.Output = domain.DataVolume{}
|
||||
execution.DataMetrics.Rejected = volume
|
||||
execution.DataMetrics.RejectionReasons = map[string]int64{"人工审核拒绝": 1}
|
||||
}
|
||||
}
|
||||
decisionEdges := domain.GetDecisionOutgoingEdges(workflow.Edges, node.ID, task.Status)
|
||||
execution.Artifacts = routeAuditArtifacts(*node, execution.InputArtifacts, decisionEdges)
|
||||
executionMap[node.ID] = execution
|
||||
applyExecution(currentRun, execution)
|
||||
markUnselectedAuditBranchesCompleted(*workflow, executionMap, currentRun, node.ID, decisionEdges, task.Status, allowedNodes)
|
||||
for _, target := range edgeTargets(decisionEdges) {
|
||||
queueNodeIfReady(*workflow, executionMap, &readyQueue, readySet, allowedNodes, target)
|
||||
}
|
||||
currentRun.Status = domain.RunStatusRunning
|
||||
syncCurrentNodeID(currentRun)
|
||||
currentRun.UpdatedAt = nowISO()
|
||||
if err := runtime.store.UpsertRun(ctx, *currentRun); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
runtime.materializeNodeMetricsBestEffort(ctx, currentRun, &execution)
|
||||
executionMap[node.ID] = execution
|
||||
node := domain.GetNodeByID(workflow.Nodes, currentRun.CurrentNodeID)
|
||||
if node != nil && domain.NodeRequiresAnnotation(*node) {
|
||||
resolved, targets, execution, resolveErr := runtime.resolveAcceptedAnnotationGate(ctx, *workflow, currentRun, *node, executionMap, allowedNodes)
|
||||
if resolveErr != nil {
|
||||
return nil, resolveErr
|
||||
}
|
||||
if resolved {
|
||||
for _, target := range targets {
|
||||
queueNodeIfReady(*workflow, executionMap, &readyQueue, readySet, allowedNodes, target)
|
||||
}
|
||||
if err := runtime.store.UpsertRun(ctx, *currentRun); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if execution != nil {
|
||||
runtime.materializeNodeMetricsBestEffort(ctx, currentRun, execution)
|
||||
executionMap[node.ID] = *execution
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tasks, err := runtime.store.ListAuditTasks(ctx, "all")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, task := range tasks {
|
||||
if task.RunID == currentRun.ID && task.NodeID == currentRun.CurrentNodeID && task.Status != domain.AuditStatusPending {
|
||||
if node != nil {
|
||||
execution := executionMap[node.ID]
|
||||
execution.NodeID = node.ID
|
||||
execution.NodeLabel = node.Data.Label
|
||||
execution.Status = domain.NodeExecutionStatusCompleted
|
||||
execution.EndedAt = nowISO()
|
||||
execution.Logs = append(execution.Logs, logEntry("INFO", fmt.Sprintf("Audit decision: %s", task.Status), node.Data.Label))
|
||||
resolvedNode := runtime.resolveNodeBusinessStage(ctx, currentRun, *node)
|
||||
if resolvedNode.Data.BusinessStage == domain.DataMetricStageAudit {
|
||||
volume := upstreamBusinessVolume(*workflow, executionMap, node.ID)
|
||||
execution.DataMetrics = &domain.DataMetricsRecord{
|
||||
SchemaVersion: 1,
|
||||
Stage: domain.DataMetricStageAudit,
|
||||
Input: volume,
|
||||
Output: volume,
|
||||
Quality: domain.DataMetricQualityExact,
|
||||
OccurredAt: execution.EndedAt,
|
||||
}
|
||||
if task.Status == domain.AuditStatusApproved {
|
||||
execution.DataMetrics.TrainReady = volume
|
||||
} else {
|
||||
execution.DataMetrics.Output = domain.DataVolume{}
|
||||
execution.DataMetrics.Rejected = volume
|
||||
execution.DataMetrics.RejectionReasons = map[string]int64{"人工审核拒绝": 1}
|
||||
}
|
||||
}
|
||||
decisionEdges := domain.GetDecisionOutgoingEdges(workflow.Edges, node.ID, task.Status)
|
||||
execution.Artifacts = routeAuditArtifacts(*node, execution.InputArtifacts, decisionEdges)
|
||||
executionMap[node.ID] = execution
|
||||
applyExecution(currentRun, execution)
|
||||
markUnselectedAuditBranchesCompleted(*workflow, executionMap, currentRun, node.ID, decisionEdges, task.Status, allowedNodes)
|
||||
for _, target := range edgeTargets(decisionEdges) {
|
||||
queueNodeIfReady(*workflow, executionMap, &readyQueue, readySet, allowedNodes, target)
|
||||
}
|
||||
currentRun.Status = domain.RunStatusRunning
|
||||
syncCurrentNodeID(currentRun)
|
||||
currentRun.UpdatedAt = nowISO()
|
||||
if err := runtime.store.UpsertRun(ctx, *currentRun); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
runtime.materializeNodeMetricsBestEffort(ctx, currentRun, &execution)
|
||||
executionMap[node.ID] = execution
|
||||
}
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2802,7 +2821,7 @@ func (runtime *Runtime) processRun(ctx context.Context, claimed *domain.RunRecor
|
||||
if !dependenciesComplete(*workflow, executionMap, node.ID) {
|
||||
continue
|
||||
}
|
||||
if domain.NodeRequiresAudit(*node) {
|
||||
if domain.NodeRequiresAudit(*node) || domain.NodeRequiresAnnotation(*node) {
|
||||
auditQueue = append(auditQueue, node.ID)
|
||||
continue
|
||||
}
|
||||
@ -2927,30 +2946,39 @@ func (runtime *Runtime) processRun(ctx context.Context, claimed *domain.RunRecor
|
||||
}
|
||||
}
|
||||
applyNodeExecutionSnapshot(&execution, *node, inputArtifacts, inputLineage)
|
||||
task := domain.AuditTaskRecord{
|
||||
ID: domain.NewID("audit"),
|
||||
OrganizationID: currentRun.OrganizationID,
|
||||
RunID: currentRun.ID,
|
||||
WorkflowID: workflow.ID,
|
||||
ProjectID: workflow.ProjectID,
|
||||
NodeID: node.ID,
|
||||
WorkflowName: workflow.Name,
|
||||
ProjectName: currentRun.ProjectName,
|
||||
OperatorName: node.Data.Label,
|
||||
CreatedAt: nowISO(),
|
||||
UpdatedAt: nowISO(),
|
||||
Status: domain.AuditStatusPending,
|
||||
Data: createAuditPayload(*node, inputArtifacts),
|
||||
}
|
||||
if _, err := runtime.store.CreateAuditTask(ctx, task); err != nil {
|
||||
return nil, err
|
||||
waitingMessage := "Node is waiting for human review"
|
||||
if domain.NodeRequiresAnnotation(*node) {
|
||||
tasks, createErr := runtime.createAnnotationGateTasks(ctx, currentRun, *node, inputArtifacts)
|
||||
if createErr != nil {
|
||||
return nil, createErr
|
||||
}
|
||||
waitingMessage = fmt.Sprintf("Node is waiting for %d annotation task(s)", len(tasks))
|
||||
} else {
|
||||
task := domain.AuditTaskRecord{
|
||||
ID: domain.NewID("audit"),
|
||||
OrganizationID: currentRun.OrganizationID,
|
||||
RunID: currentRun.ID,
|
||||
WorkflowID: workflow.ID,
|
||||
ProjectID: workflow.ProjectID,
|
||||
NodeID: node.ID,
|
||||
WorkflowName: workflow.Name,
|
||||
ProjectName: currentRun.ProjectName,
|
||||
OperatorName: node.Data.Label,
|
||||
CreatedAt: nowISO(),
|
||||
UpdatedAt: nowISO(),
|
||||
Status: domain.AuditStatusPending,
|
||||
Data: createAuditPayload(*node, inputArtifacts),
|
||||
}
|
||||
if _, err := runtime.store.CreateAuditTask(ctx, task); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
execution.Status = domain.NodeExecutionStatusWaitingForAudit
|
||||
execution.EndedAt = nowISO()
|
||||
execution.Artifacts = cloneArtifacts(inputArtifacts)
|
||||
execution.InputArtifacts = cloneArtifacts(inputArtifacts)
|
||||
execution.InputLineage = cloneInputLineage(inputLineage)
|
||||
execution.Logs = append(execution.Logs, logEntry("WARN", "Node is waiting for human review", node.Data.Label))
|
||||
execution.Logs = append(execution.Logs, logEntry("WARN", waitingMessage, node.Data.Label))
|
||||
executionMap[node.ID] = execution
|
||||
applyExecution(currentRun, execution)
|
||||
currentRun.Status = domain.RunStatusWaitingForAudit
|
||||
|
||||
@ -2028,6 +2028,148 @@ func TestRuntimeRoutesArtifactsAcrossSequentialHumanReviews(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeAnnotationGateCreatesTasksAndReturnsAcceptedRevisionArtifact(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
project, err := dataStore.CreateProject(ctx, domain.CreateProjectInput{OrganizationID: domain.DefaultOrganizationID, Name: "Native Annotation"})
|
||||
if err != nil {
|
||||
t.Fatalf("create project: %v", err)
|
||||
}
|
||||
template := domain.AnnotationTemplateRecord{
|
||||
ID: "template-1", OrganizationID: project.OrganizationID, ProjectID: project.ID,
|
||||
Name: "动作模板", Version: 1, Status: domain.AnnotationTemplatePublished,
|
||||
Labels: []domain.SemanticLabelDefinition{{ID: "steady", Name: "平稳活动"}, {ID: "fast", Name: "快速移动"}},
|
||||
}
|
||||
group := domain.AnnotationWorkgroupRecord{ID: "group-1", OrganizationID: project.OrganizationID, Name: "供应商 A", VendorID: "vendor-a", Status: "active"}
|
||||
if err := dataStore.UpsertAnnotationTemplate(ctx, template); err != nil {
|
||||
t.Fatalf("upsert template: %v", err)
|
||||
}
|
||||
if err := dataStore.UpsertAnnotationWorkgroup(ctx, group); err != nil {
|
||||
t.Fatalf("upsert group: %v", err)
|
||||
}
|
||||
workflow, err := dataStore.CreateWorkflow(ctx, domain.CreateWorkflowInput{
|
||||
OrganizationID: project.OrganizationID,
|
||||
ProjectID: project.ID,
|
||||
Name: "Native Annotation",
|
||||
Type: domain.WorkflowTypeBatch,
|
||||
Nodes: []domain.WorkflowNode{
|
||||
{ID: "source", Type: "operator", Data: domain.WorkflowNodeData{Label: "source", Outputs: []domain.PortDefinition{{ID: "out-1", Name: "clips", Type: domain.PortTypeJSON}}}},
|
||||
{ID: "annotation-gate", Type: "operator", Data: domain.WorkflowNodeData{
|
||||
Label: "逐段语义标注", Category: "HUMAN",
|
||||
Inputs: []domain.PortDefinition{{ID: "in-1", Name: "clips", Type: domain.PortTypeJSON}},
|
||||
Outputs: []domain.PortDefinition{{ID: "approved", Name: "approved", Type: domain.PortTypeJSON}},
|
||||
Hyperparams: []domain.HyperParam{
|
||||
{Key: "REVIEW_MODE", Value: "annotation"},
|
||||
{Key: "ANNOTATION_TEMPLATE_ID", Value: template.ID},
|
||||
{Key: "ANNOTATION_WORKGROUP_ID", Value: group.ID},
|
||||
},
|
||||
}},
|
||||
},
|
||||
Edges: []domain.WorkflowEdge{{ID: "source-gate", Source: "source", SourceHandle: "out-1", Target: "annotation-gate", TargetHandle: "in-1"}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create workflow: %v", err)
|
||||
}
|
||||
run, err := dataStore.CreateRun(ctx, workflow.ID, domain.RunTriggerManual)
|
||||
if err != nil {
|
||||
t.Fatalf("create run: %v", err)
|
||||
}
|
||||
root := t.TempDir()
|
||||
videoPath := filepath.Join(root, "clip001.mp4")
|
||||
if err := os.WriteFile(videoPath, []byte("real-clip-placeholder"), 0o644); err != nil {
|
||||
t.Fatalf("write video fixture: %v", err)
|
||||
}
|
||||
clipsPath := filepath.Join(root, "clips-manifest.json")
|
||||
clipsPayload := map[string]any{
|
||||
"clipCount": 1,
|
||||
"items": []any{map[string]any{
|
||||
"clipId": "clip001", "clipName": "clip001.mp4", "clipPath": videoPath,
|
||||
"startSecond": 0.0, "endSecond": 10.0, "duration": 10.0,
|
||||
}},
|
||||
}
|
||||
clipsBytes, _ := json.Marshal(clipsPayload)
|
||||
if err := os.WriteFile(clipsPath, clipsBytes, 0o644); err != nil {
|
||||
t.Fatalf("write clips manifest: %v", err)
|
||||
}
|
||||
prelabelPath := filepath.Join(root, "clip001_annotation.json")
|
||||
prelabelPayload := map[string]any{
|
||||
"clipId": "clip001",
|
||||
"actions": []any{map[string]any{"label": "平稳活动", "start": 0.0, "end": 10.0, "confidence": 0.8}},
|
||||
}
|
||||
prelabelBytes, _ := json.Marshal(prelabelPayload)
|
||||
if err := os.WriteFile(prelabelPath, prelabelBytes, 0o644); err != nil {
|
||||
t.Fatalf("write prelabel: %v", err)
|
||||
}
|
||||
run.Status = domain.RunStatusQueued
|
||||
run.CurrentNodeID = ""
|
||||
run.NodeExecutions = []domain.NodeExecutionRecord{{
|
||||
NodeID: "source", NodeLabel: "source", Attempt: 1, Status: domain.NodeExecutionStatusCompleted,
|
||||
StartedAt: nowISO(), EndedAt: nowISO(), Logs: []domain.LogEntryRecord{}, ResourceSeries: []domain.ResourceSample{},
|
||||
Artifacts: []domain.ExecutionArtifact{
|
||||
{ID: "artifact-video", RunID: run.ID, NodeID: "source", PortID: "out-1", Name: "clip001.mp4", Type: domain.PortTypeVideo, Path: videoPath, Data: map[string]any{"preview": map[string]any{"duration": 10.0}}},
|
||||
{ID: "artifact-clips", RunID: run.ID, NodeID: "source", PortID: "out-1", Name: "clips-manifest.json", Type: domain.PortTypeJSON, Path: clipsPath, Data: clipsPayload},
|
||||
{ID: "artifact-prelabel", RunID: run.ID, NodeID: "source", PortID: "out-1", Name: "clip001_annotation.json", Type: domain.PortTypeJSON, Path: prelabelPath, Data: prelabelPayload},
|
||||
},
|
||||
}}
|
||||
if err := dataStore.UpsertRun(ctx, *run); err != nil {
|
||||
t.Fatalf("upsert seeded run: %v", err)
|
||||
}
|
||||
runtime := newTestRuntimeWithLauncher(t, dataStore, testLauncher{launch: func(context.Context, k8s.LaunchInput) (*k8s.LaunchResult, error) {
|
||||
return nil, fmt.Errorf("annotation gate should not launch a Kubernetes job")
|
||||
}})
|
||||
runtime.workspaceRoot = root
|
||||
if _, err := runtime.ProcessOnce(ctx); err != nil {
|
||||
t.Fatalf("process to annotation gate: %v", err)
|
||||
}
|
||||
waiting, err := dataStore.GetRun(ctx, run.ID)
|
||||
if err != nil || waiting == nil || waiting.Status != domain.RunStatusWaitingForAudit {
|
||||
t.Fatalf("annotation gate did not pause run: run=%#v err=%v", waiting, err)
|
||||
}
|
||||
tasks, err := dataStore.ListAnnotationTasks(ctx, project.OrganizationID, project.ID)
|
||||
if err != nil || len(tasks) != 1 {
|
||||
t.Fatalf("annotation tasks = %#v err=%v", tasks, err)
|
||||
}
|
||||
if tasks[0].RunID != run.ID || tasks[0].NodeID != "annotation-gate" || tasks[0].ArtifactID != "artifact-video" || tasks[0].DataTaskID != run.TaskID {
|
||||
t.Fatalf("annotation task linkage = %#v", tasks[0])
|
||||
}
|
||||
revisions, err := dataStore.ListAnnotationRevisions(ctx, project.OrganizationID, tasks[0].ID)
|
||||
if err != nil || len(revisions) != 1 || revisions[0].Revision != 0 || len(revisions[0].Segments) != 1 {
|
||||
t.Fatalf("prelabel revision = %#v err=%v", revisions, err)
|
||||
}
|
||||
acceptedSegments := []domain.AnnotationSegment{{ID: "segment-1", LabelID: "fast", Label: "快速移动", Start: 0, End: 10, Confidence: 1, Source: "manual"}}
|
||||
if err := dataStore.UpsertAnnotationRevision(ctx, domain.AnnotationRevisionRecord{
|
||||
ID: "revision-accepted", OrganizationID: project.OrganizationID, TaskID: tasks[0].ID,
|
||||
Revision: 1, TemplateVersion: 1, Segments: acceptedSegments, AuthorUserID: "annotator", CountsAsOutput: true, CreatedAt: nowISO(),
|
||||
}); err != nil {
|
||||
t.Fatalf("upsert accepted revision: %v", err)
|
||||
}
|
||||
tasks[0].CurrentRevision = 1
|
||||
tasks[0].Status = domain.AnnotationTaskStatusAccepted
|
||||
if err := dataStore.UpsertAnnotationTask(ctx, tasks[0]); err != nil {
|
||||
t.Fatalf("accept annotation task: %v", err)
|
||||
}
|
||||
waiting.Status = domain.RunStatusQueued
|
||||
if err := dataStore.UpsertRun(ctx, *waiting); err != nil {
|
||||
t.Fatalf("queue accepted annotation run: %v", err)
|
||||
}
|
||||
if _, err := runtime.ProcessOnce(ctx); err != nil {
|
||||
t.Fatalf("resume accepted annotation run: %v", err)
|
||||
}
|
||||
completed, err := dataStore.GetRun(ctx, run.ID)
|
||||
if err != nil || completed == nil || completed.Status != domain.RunStatusCompleted {
|
||||
t.Fatalf("completed annotation run = %#v err=%v", completed, err)
|
||||
}
|
||||
gateExecution := mustNodeExecution(t, completed, "annotation-gate")
|
||||
manifest := mustArtifact(t, gateExecution, "annotations-manifest.json")
|
||||
if manifest.Metadata == nil || manifest.Metadata.SHA256 == "" || manifest.PortID != "approved" {
|
||||
t.Fatalf("accepted annotation artifact = %#v", manifest)
|
||||
}
|
||||
manifestItems := anySlice(manifest.Data["items"])
|
||||
if len(manifestItems) != 1 {
|
||||
t.Fatalf("accepted manifest items = %#v", manifest.Data["items"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeRoutesArtifactsByOutputHandle(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
|
||||
248
src/components/AnnotationTimelineEditor.tsx
Normal file
248
src/components/AnnotationTimelineEditor.tsx
Normal file
@ -0,0 +1,248 @@
|
||||
import React, { useMemo, useRef, useState } from "react";
|
||||
import { Minus, Plus, Trash2, ZoomIn } from "lucide-react";
|
||||
import type { AnnotationSegment, SemanticLabelDefinition } from "../types";
|
||||
import {
|
||||
annotationSegmentPosition,
|
||||
editAnnotationSegment,
|
||||
} from "../lib/annotation-operations.js";
|
||||
import { buildBrowserPlayableVideoURL } from "../lib/video-preview.js";
|
||||
|
||||
type DragMode = "move" | "resize-start" | "resize-end";
|
||||
|
||||
type DragState = {
|
||||
segmentId: string;
|
||||
mode: DragMode;
|
||||
pointerId: number;
|
||||
originX: number;
|
||||
initialSegments: AnnotationSegment[];
|
||||
};
|
||||
|
||||
type AnnotationTimelineEditorProps = {
|
||||
videoSource: string;
|
||||
clipStart: number;
|
||||
clipEnd: number;
|
||||
segments: AnnotationSegment[];
|
||||
labels: SemanticLabelDefinition[];
|
||||
onChange: (segments: AnnotationSegment[]) => void;
|
||||
readOnly?: boolean;
|
||||
snapSeconds?: number;
|
||||
};
|
||||
|
||||
const formatSeconds = (value: number) => `${Math.max(0, value).toFixed(2)}s`;
|
||||
|
||||
export default function AnnotationTimelineEditor({
|
||||
videoSource,
|
||||
clipStart,
|
||||
clipEnd,
|
||||
segments,
|
||||
labels,
|
||||
onChange,
|
||||
readOnly = false,
|
||||
snapSeconds = 0.1,
|
||||
}: AnnotationTimelineEditorProps) {
|
||||
const videoRef = useRef<HTMLVideoElement>(null);
|
||||
const timelineRef = useRef<HTMLDivElement>(null);
|
||||
const dragRef = useRef<DragState | null>(null);
|
||||
const [selectedSegmentId, setSelectedSegmentId] = useState("");
|
||||
const [currentTime, setCurrentTime] = useState(clipStart);
|
||||
const [zoom, setZoom] = useState(1);
|
||||
const duration = Math.max(clipEnd - clipStart, 0.001);
|
||||
const playableSource = buildBrowserPlayableVideoURL(videoSource);
|
||||
const labelColors = useMemo(() => new Map(labels.map((label) => [label.id, label.color || "#2563eb"])), [labels]);
|
||||
const selectedSegment = segments.find((segment) => segment.id === selectedSegmentId);
|
||||
|
||||
const beginDrag = (event: React.PointerEvent<HTMLElement>, segmentId: string, mode: DragMode) => {
|
||||
if (readOnly) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
dragRef.current = {
|
||||
segmentId,
|
||||
mode,
|
||||
pointerId: event.pointerId,
|
||||
originX: event.clientX,
|
||||
initialSegments: segments.map((segment) => ({ ...segment })),
|
||||
};
|
||||
setSelectedSegmentId(segmentId);
|
||||
};
|
||||
|
||||
const moveDrag = (event: React.PointerEvent<HTMLDivElement>) => {
|
||||
const drag = dragRef.current;
|
||||
const timeline = timelineRef.current;
|
||||
if (!drag || !timeline || drag.pointerId !== event.pointerId) return;
|
||||
const rect = timeline.getBoundingClientRect();
|
||||
const deltaSeconds = ((event.clientX - drag.originX) / Math.max(rect.width, 1)) * duration;
|
||||
onChange(
|
||||
editAnnotationSegment(
|
||||
drag.initialSegments,
|
||||
drag.segmentId,
|
||||
drag.mode,
|
||||
deltaSeconds,
|
||||
clipStart,
|
||||
clipEnd,
|
||||
snapSeconds,
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const endDrag = (event: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (dragRef.current?.pointerId === event.pointerId) dragRef.current = null;
|
||||
};
|
||||
|
||||
const seek = (event: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (dragRef.current || event.target !== event.currentTarget) return;
|
||||
const rect = event.currentTarget.getBoundingClientRect();
|
||||
const next = clipStart + ((event.clientX - rect.left) / Math.max(rect.width, 1)) * duration;
|
||||
const clamped = Math.max(clipStart, Math.min(clipEnd, next));
|
||||
setCurrentTime(clamped);
|
||||
if (videoRef.current) videoRef.current.currentTime = Math.max(0, clamped - clipStart);
|
||||
};
|
||||
|
||||
const editSelected = (mode: DragMode, delta: number) => {
|
||||
if (!selectedSegmentId || readOnly) return;
|
||||
onChange(editAnnotationSegment(segments, selectedSegmentId, mode, delta, clipStart, clipEnd, snapSeconds));
|
||||
};
|
||||
|
||||
const handleSegmentKey = (event: React.KeyboardEvent<HTMLButtonElement>, segmentId: string) => {
|
||||
if (readOnly || (event.key !== "ArrowLeft" && event.key !== "ArrowRight")) return;
|
||||
event.preventDefault();
|
||||
const direction = event.key === "ArrowLeft" ? -1 : 1;
|
||||
const amount = direction * snapSeconds * (event.shiftKey ? 10 : 1);
|
||||
onChange(editAnnotationSegment(segments, segmentId, "move", amount, clipStart, clipEnd, snapSeconds));
|
||||
};
|
||||
|
||||
const removeSelected = () => {
|
||||
if (!selectedSegmentId || readOnly) return;
|
||||
onChange(segments.filter((segment) => segment.id !== selectedSegmentId));
|
||||
setSelectedSegmentId("");
|
||||
};
|
||||
|
||||
const playhead = annotationSegmentPosition(
|
||||
{ start: currentTime, end: currentTime + Math.max(duration / 1000, 0.001) },
|
||||
clipStart,
|
||||
clipEnd,
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-4" data-testid="annotation-timeline-editor">
|
||||
<div className="overflow-hidden rounded-xl border border-[#2a2b2f] bg-black">
|
||||
{playableSource ? (
|
||||
<video
|
||||
ref={videoRef}
|
||||
className="aspect-video max-h-[460px] w-full bg-black object-contain"
|
||||
src={playableSource}
|
||||
controls
|
||||
preload="metadata"
|
||||
onLoadedMetadata={(event) => {
|
||||
const mediaDuration = Number.isFinite(event.currentTarget.duration) ? event.currentTarget.duration : duration;
|
||||
setCurrentTime(clipStart + Math.min(mediaDuration, duration, event.currentTarget.currentTime));
|
||||
}}
|
||||
onTimeUpdate={(event) => setCurrentTime(Math.min(clipEnd, clipStart + event.currentTarget.currentTime))}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex aspect-video items-center justify-center text-sm text-gray-500">没有可播放的视频 artifact</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 text-xs text-gray-400">
|
||||
<div>
|
||||
播放头 <span className="font-mono text-gray-200">{formatSeconds(currentTime)}</span> · 吸附 {snapSeconds.toFixed(1)}s
|
||||
</div>
|
||||
<label className="flex items-center gap-2">
|
||||
<ZoomIn className="h-4 w-4" />
|
||||
时间轴缩放
|
||||
<input
|
||||
aria-label="时间轴缩放"
|
||||
type="range"
|
||||
min={1}
|
||||
max={8}
|
||||
step={0.5}
|
||||
value={zoom}
|
||||
onChange={(event) => setZoom(Number(event.target.value))}
|
||||
/>
|
||||
<span className="w-8 text-right">{zoom.toFixed(1)}×</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto rounded-xl border border-[#2a2b2f] bg-[#090a0c]">
|
||||
<div
|
||||
ref={timelineRef}
|
||||
className="relative h-28 min-w-full touch-none select-none"
|
||||
style={{ width: `${zoom * 100}%` }}
|
||||
onPointerDown={seek}
|
||||
onPointerMove={moveDrag}
|
||||
onPointerUp={endDrag}
|
||||
onPointerCancel={endDrag}
|
||||
data-testid="annotation-timeline-track"
|
||||
>
|
||||
<div className="pointer-events-none absolute inset-x-0 top-0 flex justify-between px-2 py-1 text-[10px] text-gray-600">
|
||||
<span>{formatSeconds(clipStart)}</span>
|
||||
<span>{formatSeconds(clipEnd)}</span>
|
||||
</div>
|
||||
<div
|
||||
className="pointer-events-none absolute bottom-2 top-6 z-20 w-px bg-white/80"
|
||||
style={{ left: `${playhead.left}%` }}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{segments.map((segment) => {
|
||||
const position = annotationSegmentPosition(segment, clipStart, clipEnd);
|
||||
const selected = segment.id === selectedSegmentId;
|
||||
return (
|
||||
<div
|
||||
key={segment.id}
|
||||
className={`absolute top-9 h-14 overflow-hidden rounded-lg border text-white shadow-sm ${selected ? "z-10 border-white ring-2 ring-blue-400/70" : "border-white/15"}`}
|
||||
style={{ left: `${position.left}%`, width: `${position.width}%`, backgroundColor: labelColors.get(segment.labelId) || "#2563eb" }}
|
||||
data-testid={`annotation-segment-${segment.id}`}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute inset-y-0 left-0 w-3 cursor-ew-resize bg-black/20 hover:bg-white/30"
|
||||
aria-label={`调整 ${segment.label} 开始时间`}
|
||||
onPointerDown={(event) => beginDrag(event, segment.id, "resize-start")}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute inset-y-0 left-3 right-3 cursor-grab overflow-hidden px-1 text-left active:cursor-grabbing"
|
||||
aria-label={`拖动片段 ${segment.label}`}
|
||||
title={`${segment.label} ${segment.start}-${segment.end}s`}
|
||||
onPointerDown={(event) => beginDrag(event, segment.id, "move")}
|
||||
onClick={() => setSelectedSegmentId(segment.id)}
|
||||
onKeyDown={(event) => handleSegmentKey(event, segment.id)}
|
||||
>
|
||||
<span className="block truncate text-xs font-medium">{segment.label}</span>
|
||||
<span className="block truncate text-[10px] opacity-75">
|
||||
{segment.start.toFixed(1)}–{segment.end.toFixed(1)}s
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute inset-y-0 right-0 w-3 cursor-ew-resize bg-black/20 hover:bg-white/30"
|
||||
aria-label={`调整 ${segment.label} 结束时间`}
|
||||
onPointerDown={(event) => beginDrag(event, segment.id, "resize-end")}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{selectedSegment ? (
|
||||
<div className="flex flex-wrap items-center gap-2 rounded-lg border border-[#2a2b2f] bg-[#101114] px-3 py-2 text-xs text-gray-300">
|
||||
<span className="mr-2 font-medium text-white">{selectedSegment.label}</span>
|
||||
<button type="button" onClick={() => editSelected("move", -snapSeconds)} className="rounded border border-[#34363b] p-1" aria-label="片段左移">
|
||||
<Minus className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<button type="button" onClick={() => editSelected("move", snapSeconds)} className="rounded border border-[#34363b] p-1" aria-label="片段右移">
|
||||
<Plus className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<span className="font-mono">{selectedSegment.start.toFixed(2)}–{selectedSegment.end.toFixed(2)}s</span>
|
||||
{!readOnly ? (
|
||||
<button type="button" onClick={removeSelected} className="ml-auto inline-flex items-center gap-1 rounded border border-red-500/30 px-2 py-1 text-red-300">
|
||||
<Trash2 className="h-3.5 w-3.5" /> 删除片段
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -33,6 +33,51 @@ export function annotationSegmentPosition(segment, clipStart, clipEnd) {
|
||||
return { left, width };
|
||||
}
|
||||
|
||||
function clamp(value, minimum, maximum) {
|
||||
return Math.max(minimum, Math.min(maximum, value));
|
||||
}
|
||||
|
||||
function snap(value, clipStart, step) {
|
||||
const size = Math.max(Number(step) || 0.1, 0.001);
|
||||
return Number((Number(clipStart || 0) + Math.round((value - Number(clipStart || 0)) / size) * size).toFixed(6));
|
||||
}
|
||||
|
||||
export function editAnnotationSegment(
|
||||
segments,
|
||||
segmentId,
|
||||
mode,
|
||||
deltaSeconds,
|
||||
clipStart,
|
||||
clipEnd,
|
||||
stepSeconds = 0.1,
|
||||
) {
|
||||
const normalized = normalizeAnnotationSegments(segments, clipStart, clipEnd);
|
||||
const index = normalized.findIndex((item) => item.id === segmentId);
|
||||
if (index < 0) return normalized;
|
||||
const segment = normalized[index];
|
||||
const minimum = Number(clipStart) || 0;
|
||||
const maximum = Number(clipEnd) || minimum;
|
||||
const step = Math.max(Number(stepSeconds) || 0.1, 0.001);
|
||||
const previousEnd = index > 0 ? normalized[index - 1].end : minimum;
|
||||
const nextStart = index < normalized.length - 1 ? normalized[index + 1].start : maximum;
|
||||
const delta = Number(deltaSeconds) || 0;
|
||||
let start = segment.start;
|
||||
let end = segment.end;
|
||||
|
||||
if (mode === "move") {
|
||||
const duration = segment.end - segment.start;
|
||||
start = clamp(snap(segment.start + delta, minimum, step), previousEnd, nextStart - duration);
|
||||
end = start + duration;
|
||||
} else if (mode === "resize-start") {
|
||||
start = clamp(snap(segment.start + delta, minimum, step), previousEnd, segment.end - step);
|
||||
} else if (mode === "resize-end") {
|
||||
end = clamp(snap(segment.end + delta, minimum, step), segment.start + step, nextStart);
|
||||
}
|
||||
|
||||
normalized[index] = { ...segment, start: Number(start.toFixed(6)), end: Number(end.toFixed(6)), source: "manual" };
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function summarizeAnnotationWorkload(items) {
|
||||
return (Array.isArray(items) ? items : []).reduce(
|
||||
(summary, item) => ({
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import {
|
||||
CheckCircle2,
|
||||
ClipboardCheck,
|
||||
@ -28,12 +29,12 @@ import { useTimeZone } from "../context/TimeZoneContext";
|
||||
import { annotationOperationsApi } from "../services/api/annotation-operations";
|
||||
import { projectsApi } from "../services/api/projects";
|
||||
import {
|
||||
annotationSegmentPosition,
|
||||
normalizeAnnotationSegments,
|
||||
summarizeAnnotationWorkload,
|
||||
} from "../lib/annotation-operations.js";
|
||||
import { formatCompactDateTime } from "../lib/datetime";
|
||||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||||
import AnnotationTimelineEditor from "../components/AnnotationTimelineEditor";
|
||||
|
||||
type Tab = "queue" | "templates" | "groups" | "workload";
|
||||
|
||||
@ -69,6 +70,14 @@ const inputClass =
|
||||
export default function AnnotationOperations() {
|
||||
const { users, role } = useUser();
|
||||
const { timeZone } = useTimeZone();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const requestedProjectId = searchParams.get("projectId")?.trim() || "";
|
||||
const requestedDataTaskId = searchParams.get("dataTaskId")?.trim() || "";
|
||||
const requestedWorkflowId = searchParams.get("workflowId")?.trim() || "";
|
||||
const requestedRunId = searchParams.get("runId")?.trim() || "";
|
||||
const requestedNodeId = searchParams.get("nodeId")?.trim() || "";
|
||||
const requestedArtifactId = searchParams.get("artifactId")?.trim() || "";
|
||||
const requestedTaskId = searchParams.get("taskId")?.trim() || "";
|
||||
const [tab, setTab] = useState<Tab>("queue");
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
const [projectId, setProjectId] = useState("");
|
||||
@ -106,13 +115,15 @@ export default function AnnotationOperations() {
|
||||
]);
|
||||
setProjects(nextProjects);
|
||||
setWorkgroups(nextGroups);
|
||||
setProjectId((current) => current || nextProjects[0]?.id || "");
|
||||
setProjectId((current) =>
|
||||
current || nextProjects.find((item) => item.id === requestedProjectId)?.id || nextProjects[0]?.id || "",
|
||||
);
|
||||
} catch (loadError) {
|
||||
setError(getActionErrorMessage(loadError, "加载标注运营基础数据失败"));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
}, [requestedProjectId]);
|
||||
|
||||
const loadProject = useCallback(async () => {
|
||||
if (!projectId) {
|
||||
@ -128,22 +139,30 @@ export default function AnnotationOperations() {
|
||||
const [nextMemberships, nextTemplates, nextTasks, nextWorkload] = await Promise.all([
|
||||
annotationOperationsApi.listMemberships(projectId),
|
||||
annotationOperationsApi.listTemplates(projectId),
|
||||
annotationOperationsApi.listTasks({ projectId }),
|
||||
annotationOperationsApi.listTasks({
|
||||
projectId,
|
||||
workflowId: requestedWorkflowId || undefined,
|
||||
runId: requestedRunId || undefined,
|
||||
nodeId: requestedNodeId || undefined,
|
||||
artifactId: requestedArtifactId || undefined,
|
||||
}),
|
||||
annotationOperationsApi.workloadSummary(projectId),
|
||||
]);
|
||||
setMemberships(nextMemberships);
|
||||
setTemplates(nextTemplates);
|
||||
setTasks(nextTasks);
|
||||
setWorkload(nextWorkload);
|
||||
setSelectedTaskId((current) =>
|
||||
nextTasks.some((item) => item.id === current) ? current : nextTasks[0]?.id || "",
|
||||
);
|
||||
setSelectedTaskId((current) => {
|
||||
if (nextTasks.some((item) => item.id === current)) return current;
|
||||
if (nextTasks.some((item) => item.id === requestedTaskId)) return requestedTaskId;
|
||||
return nextTasks[0]?.id || "";
|
||||
});
|
||||
} catch (loadError) {
|
||||
setError(getActionErrorMessage(loadError, "加载项目标注运营数据失败"));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [projectId]);
|
||||
}, [projectId, requestedArtifactId, requestedNodeId, requestedRunId, requestedTaskId, requestedWorkflowId]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadBase();
|
||||
@ -295,6 +314,11 @@ export default function AnnotationOperations() {
|
||||
try {
|
||||
await annotationOperationsApi.createTask({
|
||||
projectId,
|
||||
dataTaskId: requestedDataTaskId || undefined,
|
||||
workflowId: requestedWorkflowId || undefined,
|
||||
runId: requestedRunId || undefined,
|
||||
nodeId: requestedNodeId || undefined,
|
||||
artifactId: requestedArtifactId || undefined,
|
||||
sourceVideo: taskDraft.sourceVideo,
|
||||
clipStart: Number(taskDraft.clipStart),
|
||||
clipEnd: Number(taskDraft.clipEnd),
|
||||
@ -311,6 +335,23 @@ export default function AnnotationOperations() {
|
||||
}
|
||||
};
|
||||
|
||||
const selectProject = (nextProjectId: string) => {
|
||||
setProjectId(nextProjectId);
|
||||
const next = new URLSearchParams(searchParams);
|
||||
if (nextProjectId) next.set("projectId", nextProjectId);
|
||||
else next.delete("projectId");
|
||||
next.delete("taskId");
|
||||
setSearchParams(next, { replace: true });
|
||||
};
|
||||
|
||||
const selectTask = (taskId: string) => {
|
||||
setSelectedTaskId(taskId);
|
||||
const next = new URLSearchParams(searchParams);
|
||||
if (taskId) next.set("taskId", taskId);
|
||||
else next.delete("taskId");
|
||||
setSearchParams(next, { replace: true });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
@ -322,7 +363,7 @@ export default function AnnotationOperations() {
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<select className={inputClass} value={projectId} onChange={(event) => setProjectId(event.target.value)}>
|
||||
<select className={inputClass} value={projectId} onChange={(event) => selectProject(event.target.value)}>
|
||||
<option value="">选择项目</option>
|
||||
{projects.map((project) => (
|
||||
<option key={project.id} value={project.id}>
|
||||
@ -376,7 +417,7 @@ export default function AnnotationOperations() {
|
||||
<button
|
||||
key={task.id}
|
||||
type="button"
|
||||
onClick={() => setSelectedTaskId(task.id)}
|
||||
onClick={() => selectTask(task.id)}
|
||||
className={`w-full rounded-xl border p-3 text-left ${selectedTaskId === task.id ? "border-blue-500 bg-blue-500/10" : "border-[#2a2b2f] bg-[#0f1012]"}`}
|
||||
>
|
||||
<div className="truncate text-sm font-medium text-white">{task.sourceVideo}</div>
|
||||
@ -386,6 +427,7 @@ export default function AnnotationOperations() {
|
||||
</span>
|
||||
<span>{statusLabels[task.status] || task.status}</span>
|
||||
</div>
|
||||
{task.runId ? <div className="mt-1 truncate font-mono text-[10px] text-blue-300/70">Run {task.runId}</div> : null}
|
||||
</button>
|
||||
))}
|
||||
{tasks.length === 0 ? <div className="py-8 text-center text-sm text-gray-500">暂无可见任务</div> : null}
|
||||
@ -470,44 +512,34 @@ export default function AnnotationOperations() {
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<div className="text-lg font-semibold text-white">{detail.task.sourceVideo}</div>
|
||||
<div className="text-lg font-semibold text-white">{detail.task.artifactId || detail.task.sourceVideo}</div>
|
||||
<div className="mt-1 text-sm text-gray-500">
|
||||
模板 v{detail.task.templateVersion} · {statusLabels[detail.task.status]}
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap gap-3 text-xs text-gray-500">
|
||||
{detail.task.runId ? (
|
||||
<Link className="text-blue-300 hover:text-blue-200" to={`/monitoring?runId=${encodeURIComponent(detail.task.runId)}`}>
|
||||
返回 Run 监控
|
||||
</Link>
|
||||
) : null}
|
||||
{detail.task.workflowId ? <span className="font-mono">Workflow {detail.task.workflowId}</span> : null}
|
||||
{detail.task.dataTaskId ? <span className="font-mono">DataTask {detail.task.dataTaskId}</span> : null}
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-full border border-blue-500/30 bg-blue-500/10 px-3 py-1 text-xs text-blue-200">
|
||||
Revision {detail.task.currentRevision}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="mb-2 flex justify-between text-xs text-gray-500">
|
||||
<span>{detail.task.clipStart.toFixed(2)}s</span>
|
||||
<span>{detail.task.clipEnd.toFixed(2)}s</span>
|
||||
</div>
|
||||
<div className="relative h-20 overflow-hidden rounded-xl border border-[#2a2b2f] bg-[#090a0c]">
|
||||
{segments.map((segment) => {
|
||||
const position = annotationSegmentPosition(segment, detail.task.clipStart, detail.task.clipEnd);
|
||||
const color =
|
||||
selectedTemplate?.labels.find((item) => item.id === segment.labelId)?.color || "#2563eb";
|
||||
return (
|
||||
<button
|
||||
key={segment.id}
|
||||
type="button"
|
||||
title={`${segment.label} ${segment.start}-${segment.end}s`}
|
||||
onClick={() => setSegments((current) => current.filter((item) => item.id !== segment.id))}
|
||||
className="absolute top-3 h-12 overflow-hidden rounded-lg border border-white/10 px-2 text-left text-xs text-white"
|
||||
style={{ left: `${position.left}%`, width: `${position.width}%`, backgroundColor: color }}
|
||||
>
|
||||
<span className="block truncate font-medium">{segment.label}</span>
|
||||
<span className="text-[10px] opacity-70">
|
||||
{segment.start.toFixed(1)}–{segment.end.toFixed(1)}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<AnnotationTimelineEditor
|
||||
videoSource={detail.task.sourceVideo}
|
||||
clipStart={detail.task.clipStart}
|
||||
clipEnd={detail.task.clipEnd}
|
||||
segments={segments}
|
||||
labels={selectedTemplate?.labels || []}
|
||||
onChange={setSegments}
|
||||
readOnly={detail.task.status !== "pending_annotation" && detail.task.status !== "rework"}
|
||||
/>
|
||||
|
||||
<div className="grid gap-3 rounded-xl border border-[#2a2b2f] bg-[#101114] p-4 md:grid-cols-[1.2fr_1fr_1fr_auto]">
|
||||
<select
|
||||
|
||||
@ -45,6 +45,7 @@ import {
|
||||
FileBox,
|
||||
FileText,
|
||||
RotateCcw,
|
||||
Tags,
|
||||
} from "lucide-react";
|
||||
import { cn } from "../lib/utils";
|
||||
import {
|
||||
@ -1661,6 +1662,17 @@ export default function Monitoring() {
|
||||
>
|
||||
<GitBranch className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 hover:bg-violet-500/10 rounded text-gray-400 hover:text-violet-300"
|
||||
title="打开关联标注任务"
|
||||
onClick={() =>
|
||||
navigate(
|
||||
`/annotation-operations?projectId=${encodeURIComponent(run.projectId)}&workflowId=${encodeURIComponent(run.workflowId)}&runId=${encodeURIComponent(run.id)}`,
|
||||
)
|
||||
}
|
||||
>
|
||||
<Tags className="w-4 h-4" />
|
||||
</button>
|
||||
{(run.status === "running" || run.status === "waiting_for_audit") && (
|
||||
<button
|
||||
className="p-1.5 hover:bg-amber-500/10 rounded text-amber-300 hover:text-amber-100 disabled:opacity-50"
|
||||
|
||||
@ -780,6 +780,18 @@ export default function ProjectDetail() {
|
||||
>
|
||||
<Database className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
className="p-2 hover:bg-violet-500/10 rounded-md text-gray-500 hover:text-violet-300 transition-colors"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
const params = new URLSearchParams({ projectId: project.id, workflowId: wf.id });
|
||||
if (wf.lastRunId) params.set("runId", wf.lastRunId);
|
||||
navigate(`/annotation-operations?${params.toString()}`);
|
||||
}}
|
||||
title="打开项目标注闭环"
|
||||
>
|
||||
<Sparkles className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
className="p-2 hover:bg-blue-500/10 rounded-md text-gray-500 hover:text-blue-400 transition-colors"
|
||||
onClick={(e) => {
|
||||
|
||||
@ -46,13 +46,26 @@ export const annotationOperationsApi = {
|
||||
}) => apiRequest<AnnotationTemplate>("/api/annotation-templates", { method: "POST" }, payload),
|
||||
publishTemplate: (id: string) =>
|
||||
apiRequest<AnnotationTemplate>(`/api/annotation-templates/${id}/publish`, { method: "POST" }),
|
||||
listTasks: async (filters: { projectId?: string; status?: string; workgroupId?: string; vendorId?: string } = {}) =>
|
||||
listTasks: async (
|
||||
filters: {
|
||||
projectId?: string;
|
||||
status?: string;
|
||||
workgroupId?: string;
|
||||
vendorId?: string;
|
||||
workflowId?: string;
|
||||
runId?: string;
|
||||
nodeId?: string;
|
||||
artifactId?: string;
|
||||
} = {},
|
||||
) =>
|
||||
(await apiRequest<{ items: AnnotationTaskRecord[] }>(`/api/annotation-tasks${query(filters)}`)).items,
|
||||
getTask: (id: string) => apiRequest<AnnotationTaskDetail>(`/api/annotation-tasks/${id}`),
|
||||
createTask: (payload: {
|
||||
projectId: string;
|
||||
dataTaskId?: string;
|
||||
workflowId?: string;
|
||||
runId?: string;
|
||||
nodeId?: string;
|
||||
artifactId?: string;
|
||||
sourceVideo: string;
|
||||
clipStart: number;
|
||||
|
||||
@ -633,6 +633,7 @@ export interface LightweightOperatorCodeManifest {
|
||||
export interface ExecutionRunMetadata {
|
||||
lightweightOperatorCodeManifests?: Record<string, LightweightOperatorCodeManifest>;
|
||||
trainingInputs?: TrainingInput[];
|
||||
annotationTaskIdsByNode?: Record<string, string[]>;
|
||||
}
|
||||
|
||||
export interface ScanConfig {
|
||||
@ -1313,8 +1314,10 @@ export interface AnnotationTaskRecord {
|
||||
id: string;
|
||||
organizationId?: string;
|
||||
projectId: string;
|
||||
dataTaskId?: string;
|
||||
workflowId?: string;
|
||||
runId?: string;
|
||||
nodeId?: string;
|
||||
artifactId?: string;
|
||||
sourceVideo: string;
|
||||
clipStart: number;
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
annotationSegmentPosition,
|
||||
editAnnotationSegment,
|
||||
normalizeAnnotationSegments,
|
||||
summarizeAnnotationWorkload,
|
||||
} from "../../src/lib/annotation-operations.js";
|
||||
@ -24,6 +26,21 @@ test("annotation timeline normalization rejects invalid ranges and sorts segment
|
||||
assert.deepEqual(annotationSegmentPosition(segments[1], 0, 20), { left: 50, width: 50 });
|
||||
});
|
||||
|
||||
test("annotation timeline supports snapped move and edge resize without overlap", () => {
|
||||
const segments = [
|
||||
{ id: "first", labelId: "steady", label: "平稳活动", start: 0, end: 5 },
|
||||
{ id: "second", labelId: "fast", label: "快速移动", start: 6, end: 10 },
|
||||
];
|
||||
const moved = editAnnotationSegment(segments, "first", "move", 2.26, 0, 10, 0.1);
|
||||
assert.equal(moved[0].start, 1);
|
||||
assert.equal(moved[0].end, 6);
|
||||
|
||||
const resized = editAnnotationSegment(moved, "second", "resize-start", -0.44, 0, 10, 0.1);
|
||||
assert.equal(resized[1].start, 6);
|
||||
const shortened = editAnnotationSegment(resized, "second", "resize-end", -1.24, 0, 10, 0.1);
|
||||
assert.equal(shortened[1].end, 8.8);
|
||||
});
|
||||
|
||||
test("rework does not increase formal output count", () => {
|
||||
const summary = summarizeAnnotationWorkload([
|
||||
{ outputCount: 1, reworkCount: 0, qualityApproved: 1, acceptanceApproved: 0, durationSeconds: 60 },
|
||||
@ -33,3 +50,15 @@ test("rework does not increase formal output count", () => {
|
||||
assert.equal(summary.reworkCount, 1);
|
||||
assert.equal(summary.durationSeconds, 90);
|
||||
});
|
||||
|
||||
test("annotation operations uses the draggable video timeline and workflow deep links", () => {
|
||||
const page = fs.readFileSync(new URL("../../src/pages/AnnotationOperations.tsx", import.meta.url), "utf8");
|
||||
const timeline = fs.readFileSync(new URL("../../src/components/AnnotationTimelineEditor.tsx", import.meta.url), "utf8");
|
||||
assert.match(page, /AnnotationTimelineEditor/);
|
||||
assert.match(page, /requestedRunId/);
|
||||
assert.match(page, /返回 Run 监控/);
|
||||
assert.match(timeline, /resize-start/);
|
||||
assert.match(timeline, /resize-end/);
|
||||
assert.match(timeline, /拖动片段/);
|
||||
assert.match(timeline, /buildBrowserPlayableVideoURL/);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user