forked from longtao.wu/droboticflow
🏷️ Track custom operator versions
This commit is contained in:
parent
47983d35f1
commit
a73e2b2d2b
10
docs/api.md
10
docs/api.md
@ -219,23 +219,24 @@ The built-in catalog includes the original workflow primitives plus:
|
||||
"type": "custom",
|
||||
"category": "AI",
|
||||
"description": "执行图像分割",
|
||||
"version": "1.0.0",
|
||||
"inputs": [{ "id": "in-1", "name": "图像", "type": "image" }],
|
||||
"outputs": [{ "id": "out-1", "name": "结果", "type": "json" }],
|
||||
"image": "ccr.example.com/dataflow/custom-seg:latest"
|
||||
}
|
||||
```
|
||||
|
||||
`POST /api/operators` registers custom operators only. Operator names, categories, descriptions, images, skill definitions, port IDs, and port names are trimmed before persistence. Operator `type` is immutable after creation and accepts only `builtin` or `custom`; registration requires `custom`. Port `type` accepts only `json`, `image`, `video`, `tensor`, or `file`, and non-empty `transmission` accepts only `bus`, `oss`, `shm`, or `stream`. Operator CPU/MEM resource values must be positive Kubernetes resource quantities, and GPU must be a positive integer when present.
|
||||
`POST /api/operators` registers custom operators only. Operator names, categories, descriptions, versions, images, image IDs, skill definitions, port IDs, and port names are trimmed before persistence. Operator `version` defaults to `v1` when omitted and must match `[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}`; use it as the business/runtime version visible to workflow authors. `imageId` is the digest-pinned image reference when available and defaults to `image` for directly registered image references. Operator `type` is immutable after creation and accepts only `builtin` or `custom`; registration requires `custom`. Port `type` accepts only `json`, `image`, `video`, `tensor`, or `file`, and non-empty `transmission` accepts only `bus`, `oss`, `shm`, or `stream`. Operator CPU/MEM resource values must be positive Kubernetes resource quantities, and GPU must be a positive integer when present.
|
||||
|
||||
`POST /api/operators/image-archives/import`
|
||||
|
||||
Multipart upload endpoint for a pre-built Docker/OCI image archive. The API stores the archive on the shared workspace PVC, starts a Kubernetes import Job using `CUSTOM_OPERATOR_IMAGE_IMPORTER_IMAGE`, pushes the image to `CUSTOM_OPERATOR_IMAGE_REGISTRY`, reads the pushed digest, and creates a `custom` operator whose `image` is pinned to `repo@sha256:...`.
|
||||
Multipart upload endpoint for a pre-built Docker/OCI image archive. The API stores the archive on the shared workspace PVC, starts a Kubernetes import Job using `CUSTOM_OPERATOR_IMAGE_IMPORTER_IMAGE`, pushes the image to `CUSTOM_OPERATOR_IMAGE_REGISTRY`, reads the pushed digest, and creates a `custom` operator whose `image` and `imageId` are pinned to `repo@sha256:...`.
|
||||
|
||||
Form fields:
|
||||
|
||||
- `file`: required `.tar`, `.tar.gz`, or `.tgz` image archive from `docker save` or an OCI archive tool.
|
||||
- `archiveFormat`: optional, `docker` by default; accepts `docker` or `oci`.
|
||||
- `name`, `type`, `category`, `description`, `inputs`, `outputs`, `configSchema`, `hyperparams`, `resources`, `skillDefinition`: same operator metadata as `POST /api/operators`; JSON fields are passed as JSON strings.
|
||||
- `name`, `type`, `category`, `description`, `version`, `inputs`, `outputs`, `configSchema`, `hyperparams`, `resources`, `skillDefinition`: same operator metadata as `POST /api/operators`; JSON fields are passed as JSON strings. When `version` is omitted, it defaults to the final import `tag`.
|
||||
- `repository`: optional repository suffix under `CUSTOM_OPERATOR_IMAGE_REGISTRY`; defaults to a sanitized operator name.
|
||||
- `tag`: optional tag; defaults to an import timestamp.
|
||||
|
||||
@ -249,10 +250,11 @@ curl -X POST "$API_BASE/api/operators/image-archives/import" \
|
||||
-F 'type=custom' \
|
||||
-F 'category=AI' \
|
||||
-F 'description=执行图像分割' \
|
||||
-F 'version=1.0.0' \
|
||||
-F 'outputs=[{"id":"out-1","name":"结果","type":"json"}]'
|
||||
```
|
||||
|
||||
The response includes `image` for the pushed tag, `imageId` for the digest-pinned reference, `digest`, `job`, and the created `operator`.
|
||||
The response includes `version`, `image` for the pushed tag, `imageId` for the digest-pinned reference, `digest`, `job`, and the created `operator`.
|
||||
|
||||
### Runs and Monitoring
|
||||
|
||||
|
||||
@ -134,15 +134,26 @@
|
||||
- 主要输入
|
||||
- 主要输出
|
||||
|
||||
### 3.4 image
|
||||
### 3.4 version / image / imageId
|
||||
|
||||
`version` 是平台侧展示给工作流作者和审计人员看的算子版本。它不是随便写的备注字段,应该和镜像构建、测试验收、上线记录对应起来。
|
||||
|
||||
推荐约束:
|
||||
|
||||
- 新算子首次注册使用明确版本,例如 `v1`、`1.0.0`、`2026.06.25`
|
||||
- 每次镜像行为或输入输出契约发生变化,都应升级 `version`
|
||||
- 不要把不同实现复用同一个版本号
|
||||
- 版本号只能包含字母、数字、下划线、点和短横线,长度不超过 128
|
||||
|
||||
工作流节点会保存添加节点时的 `operatorVersion` 和 `operatorImageId`,用于后续排障和验收追踪。
|
||||
|
||||
`image` 字段表示“运行这个自定义算子时实际拉起的容器镜像”。
|
||||
|
||||
当前平台的责任边界很明确:
|
||||
|
||||
- 平台不会帮你构建自定义镜像
|
||||
- 平台不会帮你推送镜像到仓库
|
||||
- 平台只会保存你填写的镜像地址,并在运行时直接用它启动 Kubernetes Job
|
||||
- 如果你直接填写镜像地址,平台只会保存并在运行时直接用它启动 Kubernetes Job
|
||||
- 如果你上传 Docker/OCI 镜像归档,平台会把归档导入到 POC 配置的 CCR 仓库,并把算子运行镜像固定到 digest 引用
|
||||
|
||||
因此,自定义镜像的标准流程是:
|
||||
|
||||
@ -150,6 +161,12 @@
|
||||
2. 用户把完整镜像地址填写到算子的 `image` 字段
|
||||
3. 工作流运行时,平台直接拉取这个地址执行
|
||||
|
||||
上传镜像归档的标准流程是:
|
||||
|
||||
1. 用户用 `docker save` 或 OCI 工具导出真实镜像归档
|
||||
2. 在算子管理页选择“上传归档”,填写目标仓库、tag 和版本
|
||||
3. 平台导入镜像后保存 `imageId=repo@sha256:...`,工作流节点也会记录该 digest
|
||||
|
||||
填写要求:
|
||||
|
||||
- 必须填写完整镜像引用,格式建议为 `<registry>/<namespace>/<image>:<tag>`
|
||||
@ -499,6 +516,7 @@ path = artifact["path"]
|
||||
3. 有最小测试或脚本级验证
|
||||
4. 有一次真实工作流回归
|
||||
5. 有外部副作用核验证据
|
||||
6. 版本号、镜像 tag、digest 和验收记录能对应起来
|
||||
|
||||
建议证据:
|
||||
|
||||
|
||||
@ -198,10 +198,6 @@ func (server *server) handleOperatorImageArchiveImport(writer http.ResponseWrite
|
||||
renderValidationError(writer, issues...)
|
||||
return
|
||||
}
|
||||
if issues := validateOperatorMetadata(payload.Name, payload.Type, payload.Category, payload.Description, payload.Inputs, payload.Outputs, payload.Resources); len(issues) > 0 {
|
||||
renderValidationError(writer, issues...)
|
||||
return
|
||||
}
|
||||
if payload.Type != "custom" {
|
||||
renderValidationError(writer, validationIssue{Field: "type", Message: "type must be custom when importing an operator image archive"})
|
||||
return
|
||||
@ -241,6 +237,11 @@ func (server *server) handleOperatorImageArchiveImport(writer http.ResponseWrite
|
||||
renderValidationError(writer, validationIssue{Field: "tag", Message: "tag must match [A-Za-z0-9_][A-Za-z0-9_.-]{0,127}"})
|
||||
return
|
||||
}
|
||||
payload.Version = normalizeOperatorVersion(payload.Version, tag)
|
||||
if issues := validateOperatorMetadata(payload.Name, payload.Type, payload.Category, payload.Description, payload.Version, payload.Inputs, payload.Outputs, payload.Resources); len(issues) > 0 {
|
||||
renderValidationError(writer, issues...)
|
||||
return
|
||||
}
|
||||
|
||||
imageRepository := strings.TrimRight(server.customOperatorImageRegistry, "/") + "/" + repository
|
||||
destinationImage := imageRepository + ":" + tag
|
||||
@ -288,6 +289,7 @@ func (server *server) handleOperatorImageArchiveImport(writer http.ResponseWrite
|
||||
|
||||
imageID := imageRepository + "@" + strings.TrimSpace(importResult.Digest)
|
||||
payload.Image = imageID
|
||||
payload.ImageID = imageID
|
||||
server.assignTenant(request, &payload.OrganizationID)
|
||||
item, err := server.store.CreateOperator(request.Context(), payload)
|
||||
if err != nil {
|
||||
@ -299,6 +301,7 @@ func (server *server) handleOperatorImageArchiveImport(writer http.ResponseWrite
|
||||
"importId": importID,
|
||||
"repository": repository,
|
||||
"tag": tag,
|
||||
"version": payload.Version,
|
||||
"image": destinationImage,
|
||||
"imageId": imageID,
|
||||
"digest": strings.TrimSpace(importResult.Digest),
|
||||
@ -317,6 +320,7 @@ func parseOperatorArchiveImportPayload(request *http.Request) (domain.CreateOper
|
||||
Type: normalizeOperatorType(request.FormValue("type")),
|
||||
Category: strings.TrimSpace(request.FormValue("category")),
|
||||
Description: strings.TrimSpace(request.FormValue("description")),
|
||||
Version: strings.TrimSpace(request.FormValue("version")),
|
||||
SkillDefinition: strings.TrimSpace(request.FormValue("skillDefinition")),
|
||||
OrganizationID: strings.TrimSpace(request.FormValue("organizationId")),
|
||||
}
|
||||
|
||||
@ -2508,6 +2508,26 @@ func normalizeOperatorType(value string) string {
|
||||
return strings.ToLower(strings.TrimSpace(value))
|
||||
}
|
||||
|
||||
var operatorVersionPattern = regexp.MustCompile(`^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$`)
|
||||
|
||||
func normalizeOperatorVersion(value string, fallback string) string {
|
||||
normalized := strings.TrimSpace(value)
|
||||
if normalized != "" {
|
||||
return normalized
|
||||
}
|
||||
return strings.TrimSpace(fallback)
|
||||
}
|
||||
|
||||
func validateOperatorVersion(version string) []validationIssue {
|
||||
if version == "" {
|
||||
return nil
|
||||
}
|
||||
if !operatorVersionPattern.MatchString(version) {
|
||||
return []validationIssue{{Field: "version", Message: "version must match [A-Za-z0-9_][A-Za-z0-9_.-]{0,127}"}}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validOperatorType(value string) bool {
|
||||
return value == "builtin" || value == "custom"
|
||||
}
|
||||
@ -2605,7 +2625,7 @@ func validateOperatorResources(resources *domain.OperatorResources) []validation
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateOperatorMetadata(name string, operatorType string, category string, description string, inputs []domain.PortDefinition, outputs []domain.PortDefinition, resources *domain.OperatorResources) []validationIssue {
|
||||
func validateOperatorMetadata(name string, operatorType string, category string, description string, version string, inputs []domain.PortDefinition, outputs []domain.PortDefinition, resources *domain.OperatorResources) []validationIssue {
|
||||
issues := make([]validationIssue, 0)
|
||||
if name == "" {
|
||||
issues = append(issues, validationIssue{Field: "name", Message: "name is required"})
|
||||
@ -2619,6 +2639,7 @@ func validateOperatorMetadata(name string, operatorType string, category string,
|
||||
if description == "" {
|
||||
issues = append(issues, validationIssue{Field: "description", Message: "description is required"})
|
||||
}
|
||||
issues = append(issues, validateOperatorVersion(version)...)
|
||||
issues = append(issues, validatePortDefinitions("inputs", inputs)...)
|
||||
issues = append(issues, validatePortDefinitions("outputs", outputs)...)
|
||||
issues = append(issues, validateOperatorResources(resources)...)
|
||||
@ -2639,10 +2660,15 @@ func (server *server) handleOperatorsCreate(writer http.ResponseWriter, request
|
||||
payload.Description = strings.TrimSpace(payload.Description)
|
||||
payload.Inputs = normalizePortDefinitions(payload.Inputs)
|
||||
payload.Outputs = normalizePortDefinitions(payload.Outputs)
|
||||
payload.Version = normalizeOperatorVersion(payload.Version, "v1")
|
||||
payload.Image = strings.TrimSpace(payload.Image)
|
||||
payload.ImageID = strings.TrimSpace(payload.ImageID)
|
||||
payload.SkillDefinition = strings.TrimSpace(payload.SkillDefinition)
|
||||
payload.Resources = normalizeOperatorResources(payload.Resources)
|
||||
if issues := validateOperatorMetadata(payload.Name, payload.Type, payload.Category, payload.Description, payload.Inputs, payload.Outputs, payload.Resources); len(issues) > 0 {
|
||||
if payload.ImageID == "" {
|
||||
payload.ImageID = payload.Image
|
||||
}
|
||||
if issues := validateOperatorMetadata(payload.Name, payload.Type, payload.Category, payload.Description, payload.Version, payload.Inputs, payload.Outputs, payload.Resources); len(issues) > 0 {
|
||||
renderValidationError(writer, issues...)
|
||||
return
|
||||
}
|
||||
@ -2683,7 +2709,9 @@ type operatorPatch struct {
|
||||
Inputs *[]domain.PortDefinition `json:"inputs"`
|
||||
Outputs *[]domain.PortDefinition `json:"outputs"`
|
||||
ConfigSchema *map[string]any `json:"configSchema"`
|
||||
Version *string `json:"version"`
|
||||
Image *string `json:"image"`
|
||||
ImageID *string `json:"imageId"`
|
||||
SkillDefinition *string `json:"skillDefinition"`
|
||||
Hyperparams *[]domain.HyperParam `json:"hyperparams"`
|
||||
Resources *domain.OperatorResources `json:"resources"`
|
||||
@ -2737,9 +2765,17 @@ func (server *server) handleOperatorsUpdate(writer http.ResponseWriter, request
|
||||
if payload.ConfigSchema != nil {
|
||||
next.ConfigSchema = *payload.ConfigSchema
|
||||
}
|
||||
if payload.Version != nil {
|
||||
next.Version = normalizeOperatorVersion(*payload.Version, "")
|
||||
}
|
||||
if payload.Image != nil {
|
||||
next.Image = strings.TrimSpace(*payload.Image)
|
||||
}
|
||||
if payload.ImageID != nil {
|
||||
next.ImageID = strings.TrimSpace(*payload.ImageID)
|
||||
} else if payload.Image != nil && next.ImageID == "" {
|
||||
next.ImageID = next.Image
|
||||
}
|
||||
if payload.SkillDefinition != nil {
|
||||
next.SkillDefinition = strings.TrimSpace(*payload.SkillDefinition)
|
||||
}
|
||||
@ -2749,7 +2785,13 @@ func (server *server) handleOperatorsUpdate(writer http.ResponseWriter, request
|
||||
if payload.Resources != nil {
|
||||
next.Resources = normalizeOperatorResources(payload.Resources)
|
||||
}
|
||||
if issues := validateOperatorMetadata(next.Name, next.Type, next.Category, next.Description, next.Inputs, next.Outputs, next.Resources); len(issues) > 0 {
|
||||
if normalizeOperatorType(next.Type) == "custom" {
|
||||
next.Version = normalizeOperatorVersion(next.Version, "v1")
|
||||
if next.ImageID == "" {
|
||||
next.ImageID = next.Image
|
||||
}
|
||||
}
|
||||
if issues := validateOperatorMetadata(next.Name, next.Type, next.Category, next.Description, next.Version, next.Inputs, next.Outputs, next.Resources); len(issues) > 0 {
|
||||
renderValidationError(writer, issues...)
|
||||
return
|
||||
}
|
||||
|
||||
@ -4830,6 +4830,12 @@ func TestOperatorMetadataValidationAndNormalization(t *testing.T) {
|
||||
if created.Image != "registry.example.com/custom/operator:v1" {
|
||||
t.Fatalf("expected trimmed image, got %q", created.Image)
|
||||
}
|
||||
if created.Version != "v1" {
|
||||
t.Fatalf("expected default operator version v1, got %q", created.Version)
|
||||
}
|
||||
if created.ImageID != created.Image {
|
||||
t.Fatalf("expected imageId to default to image, got %q", created.ImageID)
|
||||
}
|
||||
if len(created.Inputs) != 1 || created.Inputs[0].ID != "in-1" || created.Inputs[0].Name != "input" || created.Inputs[0].Type != domain.PortTypeJSON || created.Inputs[0].Transmission != "bus" {
|
||||
t.Fatalf("expected normalized input port, got %#v", created.Inputs)
|
||||
}
|
||||
@ -4869,6 +4875,7 @@ func TestOperatorMetadataValidationAndNormalization(t *testing.T) {
|
||||
{name: "invalid output transmission", payload: `{"outputs":[{"id":"out-1","name":"result","type":"json","transmission":"mailbox"}]}`},
|
||||
{name: "duplicate output ids", payload: `{"outputs":[{"id":"dup","name":"one","type":"json"},{"id":"dup","name":"two","type":"json"}]}`},
|
||||
{name: "invalid resources", payload: `{"resources":{"gpuLimit":"half"}}`},
|
||||
{name: "invalid version", payload: `{"version":"bad version"}`},
|
||||
} {
|
||||
recorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(
|
||||
@ -4896,6 +4903,7 @@ func TestOperatorMetadataValidationAndNormalization(t *testing.T) {
|
||||
"type":" CUSTOM ",
|
||||
"category":" AI ",
|
||||
"description":" Updated description ",
|
||||
"version":" 2.0.0 ",
|
||||
"outputs":[{"id":"out-2","name":" tensor result ","type":" TENSOR ","transmission":" STREAM "}],
|
||||
"resources":{"cpuLimit":" 750m ","memoryLimit":" 2Gi "}
|
||||
}`))),
|
||||
@ -4910,6 +4918,9 @@ func TestOperatorMetadataValidationAndNormalization(t *testing.T) {
|
||||
if updated.Name != "Updated Operator" || updated.Type != "custom" || updated.Category != "AI" || updated.Description != "Updated description" {
|
||||
t.Fatalf("expected normalized operator update, got %#v", updated)
|
||||
}
|
||||
if updated.Version != "2.0.0" {
|
||||
t.Fatalf("expected normalized operator version, got %q", updated.Version)
|
||||
}
|
||||
if len(updated.Outputs) != 1 || updated.Outputs[0].ID != "out-2" || updated.Outputs[0].Name != "tensor result" || updated.Outputs[0].Type != domain.PortTypeTensor || updated.Outputs[0].Transmission != "stream" {
|
||||
t.Fatalf("expected normalized updated output port, got %#v", updated.Outputs)
|
||||
}
|
||||
@ -5267,6 +5278,7 @@ func TestOperatorImageArchiveImportCreatesOperatorWithDigestImage(t *testing.T)
|
||||
var response struct {
|
||||
Repository string `json:"repository"`
|
||||
Tag string `json:"tag"`
|
||||
Version string `json:"version"`
|
||||
Image string `json:"image"`
|
||||
ImageID string `json:"imageId"`
|
||||
Digest string `json:"digest"`
|
||||
@ -5278,6 +5290,9 @@ func TestOperatorImageArchiveImportCreatesOperatorWithDigestImage(t *testing.T)
|
||||
if response.Repository != "team-vision/segment-operator" || response.Tag != "v1_test" {
|
||||
t.Fatalf("unexpected repository/tag: %#v", response)
|
||||
}
|
||||
if response.Version != "v1_test" {
|
||||
t.Fatalf("expected version to default to tag, got %#v", response)
|
||||
}
|
||||
expectedTaggedImage := "ccr.example/dataflow-poc/custom-operators/team-vision/segment-operator:v1_test"
|
||||
expectedImageID := "ccr.example/dataflow-poc/custom-operators/team-vision/segment-operator@" + digest
|
||||
if response.Image != expectedTaggedImage || response.ImageID != expectedImageID || response.Digest != digest {
|
||||
@ -5293,6 +5308,9 @@ func TestOperatorImageArchiveImportCreatesOperatorWithDigestImage(t *testing.T)
|
||||
if stored == nil || stored.Image != expectedImageID {
|
||||
t.Fatalf("expected imported operator to use digest image %q, got %#v", expectedImageID, stored)
|
||||
}
|
||||
if stored.ImageID != expectedImageID || stored.Version != "v1_test" {
|
||||
t.Fatalf("expected imported operator to persist imageId/version, got %#v", stored)
|
||||
}
|
||||
if stored.Name != "Archive Import Operator" || stored.Type != "custom" || stored.Category != "AI" {
|
||||
t.Fatalf("expected normalized operator metadata, got %#v", stored)
|
||||
}
|
||||
|
||||
@ -149,6 +149,9 @@ type WorkflowNodeData struct {
|
||||
Description string `json:"description" bson:"description"`
|
||||
Inputs []PortDefinition `json:"inputs" bson:"inputs"`
|
||||
Outputs []PortDefinition `json:"outputs" bson:"outputs"`
|
||||
OperatorID string `json:"operatorId,omitempty" bson:"operatorId,omitempty"`
|
||||
OperatorVersion string `json:"operatorVersion,omitempty" bson:"operatorVersion,omitempty"`
|
||||
OperatorImageID string `json:"operatorImageId,omitempty" bson:"operatorImageId,omitempty"`
|
||||
Image string `json:"image,omitempty" bson:"image,omitempty"`
|
||||
SkillDefinition string `json:"skillDefinition,omitempty" bson:"skillDefinition,omitempty"`
|
||||
Hyperparams []HyperParam `json:"hyperparams,omitempty" bson:"hyperparams,omitempty"`
|
||||
@ -207,7 +210,9 @@ type OperatorRecord struct {
|
||||
Inputs []PortDefinition `json:"inputs" bson:"inputs"`
|
||||
Outputs []PortDefinition `json:"outputs" bson:"outputs"`
|
||||
ConfigSchema map[string]any `json:"configSchema,omitempty" bson:"configSchema,omitempty"`
|
||||
Version string `json:"version,omitempty" bson:"version,omitempty"`
|
||||
Image string `json:"image,omitempty" bson:"image,omitempty"`
|
||||
ImageID string `json:"imageId,omitempty" bson:"imageId,omitempty"`
|
||||
SkillDefinition string `json:"skillDefinition,omitempty" bson:"skillDefinition,omitempty"`
|
||||
Hyperparams []HyperParam `json:"hyperparams,omitempty" bson:"hyperparams,omitempty"`
|
||||
Resources *OperatorResources `json:"resources,omitempty" bson:"resources,omitempty"`
|
||||
@ -690,7 +695,9 @@ type CreateOperatorInput struct {
|
||||
Inputs []PortDefinition `json:"inputs"`
|
||||
Outputs []PortDefinition `json:"outputs"`
|
||||
ConfigSchema map[string]any `json:"configSchema,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Image string `json:"image,omitempty"`
|
||||
ImageID string `json:"imageId,omitempty"`
|
||||
SkillDefinition string `json:"skillDefinition,omitempty"`
|
||||
Hyperparams []HyperParam `json:"hyperparams,omitempty"`
|
||||
Resources *OperatorResources `json:"resources,omitempty"`
|
||||
|
||||
@ -473,7 +473,9 @@ func (store *MemoryStore) CreateOperator(_ context.Context, input domain.CreateO
|
||||
Inputs: clone(input.Inputs),
|
||||
Outputs: clone(input.Outputs),
|
||||
ConfigSchema: clone(input.ConfigSchema),
|
||||
Version: input.Version,
|
||||
Image: input.Image,
|
||||
ImageID: input.ImageID,
|
||||
SkillDefinition: input.SkillDefinition,
|
||||
Hyperparams: clone(input.Hyperparams),
|
||||
Resources: clone(input.Resources),
|
||||
|
||||
@ -333,7 +333,9 @@ func (store *MongoStore) CreateOperator(ctx context.Context, input domain.Create
|
||||
Inputs: input.Inputs,
|
||||
Outputs: input.Outputs,
|
||||
ConfigSchema: input.ConfigSchema,
|
||||
Version: input.Version,
|
||||
Image: input.Image,
|
||||
ImageID: input.ImageID,
|
||||
SkillDefinition: input.SkillDefinition,
|
||||
Hyperparams: input.Hyperparams,
|
||||
Resources: input.Resources,
|
||||
|
||||
@ -43,7 +43,9 @@ export function buildOperatorPayload(source = {}, overrides = {}) {
|
||||
inputs: normalizePorts(overrides.inputs ?? source.inputs),
|
||||
outputs: normalizePorts(overrides.outputs ?? source.outputs),
|
||||
configSchema: deepClone(overrides.configSchema ?? source.configSchema),
|
||||
version: trimString(overrides.version ?? source.version),
|
||||
image: trimString(overrides.image ?? source.image),
|
||||
imageId: trimString(overrides.imageId ?? source.imageId),
|
||||
skillDefinition: trimString(overrides.skillDefinition ?? source.skillDefinition),
|
||||
hyperparams: deepClone(overrides.hyperparams ?? source.hyperparams ?? []),
|
||||
resources: deepClone(overrides.resources ?? source.resources),
|
||||
@ -88,5 +90,8 @@ export function getOperatorPayloadIssue(source = {}, overrides = {}) {
|
||||
if (!payload.description) {
|
||||
return "算子描述不能为空";
|
||||
}
|
||||
if (payload.version && !/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/.test(payload.version)) {
|
||||
return "算子版本只能包含字母、数字、下划线、点和短横线,长度不超过 128";
|
||||
}
|
||||
return validatePorts("inputs", payload.inputs) || validatePorts("outputs", payload.outputs);
|
||||
}
|
||||
|
||||
@ -70,6 +70,7 @@ export default function Operators() {
|
||||
const [newOp, setNewOp] = useState<Partial<Operator>>({
|
||||
type: "custom",
|
||||
category: "CV",
|
||||
version: "v1",
|
||||
inputs: [],
|
||||
outputs: [],
|
||||
hyperparams: [],
|
||||
@ -169,7 +170,15 @@ export default function Operators() {
|
||||
setIsModalOpen(false);
|
||||
setEditingOpId(null);
|
||||
setActiveTab("basic");
|
||||
setNewOp({ type: "custom", category: "CV", inputs: [], outputs: [], hyperparams: [], skillDefinition: "" });
|
||||
setNewOp({
|
||||
type: "custom",
|
||||
category: "CV",
|
||||
version: "v1",
|
||||
inputs: [],
|
||||
outputs: [],
|
||||
hyperparams: [],
|
||||
skillDefinition: "",
|
||||
});
|
||||
resetArchiveUpload();
|
||||
};
|
||||
setActionError("");
|
||||
@ -339,6 +348,7 @@ export default function Operators() {
|
||||
setNewOp({
|
||||
type: "custom",
|
||||
category: "CV",
|
||||
version: "v1",
|
||||
inputs: [],
|
||||
outputs: [],
|
||||
hyperparams: [],
|
||||
@ -431,6 +441,11 @@ export default function Operators() {
|
||||
>
|
||||
{op.type === "builtin" ? "Built-in" : "Custom"}
|
||||
</span>
|
||||
{op.version && (
|
||||
<span className="text-[10px] px-2 py-0.5 rounded-full font-mono uppercase tracking-wider bg-amber-500/10 text-amber-400 border border-amber-500/20">
|
||||
{op.version}
|
||||
</span>
|
||||
)}
|
||||
{op.skillDefinition && (
|
||||
<span className="text-[10px] px-2 py-0.5 rounded-full font-mono uppercase tracking-wider bg-green-500/10 text-green-500 border border-green-500/20 flex items-center gap-1">
|
||||
<Layers className="w-2.5 h-2.5" />
|
||||
@ -615,6 +630,17 @@ export default function Operators() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-xs font-medium text-gray-400 uppercase tracking-wider">算子版本</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder={imageSourceMode === "archive" ? "留空时默认使用镜像 tag" : "v1"}
|
||||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded-md px-4 py-2 text-sm focus:outline-none focus:border-blue-500"
|
||||
value={newOp.version || ""}
|
||||
onChange={(e) => setNewOp({ ...newOp, version: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-xs font-medium text-gray-400 uppercase tracking-wider">描述</label>
|
||||
<textarea
|
||||
@ -631,7 +657,10 @@ export default function Operators() {
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setImageSourceMode("reference")}
|
||||
onClick={() => {
|
||||
setImageSourceMode("reference");
|
||||
setNewOp((current) => ({ ...current, version: current.version || "v1" }));
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-center justify-center gap-2 rounded-md border px-3 py-2 text-xs font-medium transition-colors",
|
||||
imageSourceMode === "reference"
|
||||
@ -644,7 +673,13 @@ export default function Operators() {
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setImageSourceMode("archive")}
|
||||
onClick={() => {
|
||||
setImageSourceMode("archive");
|
||||
setNewOp((current) => ({
|
||||
...current,
|
||||
version: current.version === "v1" ? "" : current.version,
|
||||
}));
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-center justify-center gap-2 rounded-md border px-3 py-2 text-xs font-medium transition-colors",
|
||||
imageSourceMode === "archive"
|
||||
|
||||
@ -172,6 +172,9 @@ interface OperatorNodeData {
|
||||
description?: string;
|
||||
inputs?: PortDefinition[];
|
||||
outputs?: PortDefinition[];
|
||||
operatorId?: string;
|
||||
operatorVersion?: string;
|
||||
operatorImageId?: string;
|
||||
image?: string;
|
||||
hyperparams?: HyperParam[];
|
||||
cpu?: string;
|
||||
@ -1759,6 +1762,9 @@ export default function WorkflowEditor() {
|
||||
description: op.description,
|
||||
inputs: op.inputs,
|
||||
outputs: op.outputs,
|
||||
operatorId: op.id,
|
||||
operatorVersion: op.version,
|
||||
operatorImageId: op.imageId || op.image,
|
||||
image: op.image,
|
||||
hyperparams: op.hyperparams || [],
|
||||
cpu: op.resources?.cpuLimit || "",
|
||||
@ -5251,6 +5257,39 @@ export default function WorkflowEditor() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{(selectedNode.data.operatorVersion || selectedNode.data.operatorImageId) && (
|
||||
<div className="grid grid-cols-1 gap-2">
|
||||
{selectedNode.data.operatorVersion && (
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] text-gray-500 uppercase font-mono">
|
||||
算子版本 (Pinned Version)
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs text-amber-300 disabled:opacity-80"
|
||||
value={selectedNode.data.operatorVersion}
|
||||
readOnly
|
||||
disabled
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{selectedNode.data.operatorImageId && (
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] text-gray-500 uppercase font-mono">
|
||||
镜像 Digest (Image ID)
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
className="w-full bg-[#0a0a0a] border border-[#2a2b2f] rounded px-2 py-1 text-xs text-gray-400 disabled:opacity-80"
|
||||
value={selectedNode.data.operatorImageId}
|
||||
readOnly
|
||||
disabled
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] text-gray-500 uppercase font-mono">资源限制 (CPU)</label>
|
||||
|
||||
@ -13,6 +13,7 @@ export interface OperatorImageArchiveImportResult {
|
||||
importId: string;
|
||||
repository: string;
|
||||
tag: string;
|
||||
version: string;
|
||||
image: string;
|
||||
imageId: string;
|
||||
digest: string;
|
||||
@ -37,6 +38,7 @@ export const operatorsApi = {
|
||||
form.append("type", payload.operator.type || "custom");
|
||||
form.append("category", payload.operator.category || "");
|
||||
form.append("description", payload.operator.description || "");
|
||||
form.append("version", payload.operator.version || "");
|
||||
form.append("skillDefinition", payload.operator.skillDefinition || "");
|
||||
form.append("archiveFormat", payload.archiveFormat || "docker");
|
||||
if (payload.repository) form.append("repository", payload.repository);
|
||||
|
||||
@ -230,7 +230,9 @@ export interface Operator {
|
||||
inputs: PortDefinition[];
|
||||
outputs: PortDefinition[];
|
||||
configSchema?: Record<string, unknown>;
|
||||
version?: string; // Operator business/runtime version
|
||||
image?: string; // Docker image for custom operators
|
||||
imageId?: string; // Digest-pinned image reference when available
|
||||
skillDefinition?: string; // AI-readable description for workflow generation
|
||||
hyperparams?: HyperParam[]; // K8s Job environment variables
|
||||
resources?: {
|
||||
|
||||
@ -9,7 +9,9 @@ test("buildOperatorPayload trims operator metadata and normalizes ports", () =>
|
||||
type: " CUSTOM ",
|
||||
category: " CV ",
|
||||
description: " 提升视频清晰度 ",
|
||||
version: " 1.2.3 ",
|
||||
image: " registry.example.test/video-sharpen:v1 ",
|
||||
imageId: " registry.example.test/video-sharpen@sha256:abc ",
|
||||
skillDefinition: " ### 使用说明 ",
|
||||
inputs: [{ id: " in-1 ", name: " 输入视频 ", type: " VIDEO ", transmission: " OSS " }],
|
||||
outputs: [{ id: " out-1 ", name: " 输出视频 ", type: " FILE ", transmission: " STREAM " }],
|
||||
@ -22,7 +24,9 @@ test("buildOperatorPayload trims operator metadata and normalizes ports", () =>
|
||||
assert.equal(payload.type, "custom");
|
||||
assert.equal(payload.category, "CV");
|
||||
assert.equal(payload.description, "提升视频清晰度");
|
||||
assert.equal(payload.version, "1.2.3");
|
||||
assert.equal(payload.image, "registry.example.test/video-sharpen:v1");
|
||||
assert.equal(payload.imageId, "registry.example.test/video-sharpen@sha256:abc");
|
||||
assert.equal(payload.skillDefinition, "### 使用说明");
|
||||
assert.deepEqual(payload.inputs[0], {
|
||||
id: "in-1",
|
||||
@ -57,6 +61,18 @@ test("operator payload validation rejects missing metadata and invalid ports", (
|
||||
getOperatorPayloadIssue({ name: "ok", type: "external", description: "ok" }),
|
||||
"type must be builtin or custom",
|
||||
);
|
||||
assert.match(
|
||||
getOperatorPayloadIssue({
|
||||
name: "ok",
|
||||
type: "custom",
|
||||
category: "CV",
|
||||
description: "ok",
|
||||
version: "bad version",
|
||||
inputs: [],
|
||||
outputs: [],
|
||||
}),
|
||||
/算子版本/,
|
||||
);
|
||||
assert.match(
|
||||
getOperatorPayloadIssue({
|
||||
name: "ok",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user