feat(image): 以插件声明统一图片参数、尺寸选择与定价合同 (#760)
* feat(image): 图片参数 - 统一插件声明配置与生成合同 * docs(image): 图片参数 - 说明声明合同与验证边界 * fix(plugins): 图片声明 - 保留内联素材支持并同步制品文档 * fix(image): 参数合同 - 对齐审批意图和尺寸预检调用方 * fix(image): 调用链 - 保留公开意图并接通独立分辨率 * fix(image): 图片参数 - 补齐分辨率接线与目录价格投影
This commit is contained in:
1 parent
88de4ce422
commit
7466119867
104 files changed
+6013
-568
No files matched your search
@@ -33,6 +33,8 @@ type ModelSelection struct {
|
||||
// node/task tags are the only mapping between the persisted canvas and task wire names.
|
||||
type Options struct {
|
||||
Size *string `json:"size,omitempty" node:"size" task:"size" modes:"image,video"`
|
||||
ImageResolution *string `json:"imageResolution,omitempty" node:"imageResolution" task:"imageResolution" modes:"image"`
|
||||
ImageParameters *string `json:"imageParameters,omitempty" node:"imageParameters" task:"imageParameters" modes:"image"`
|
||||
Quality *string `json:"quality,omitempty" node:"quality" task:"quality" modes:"image"`
|
||||
Count *int `json:"count,omitempty" node:"count" task:"count" modes:"image"`
|
||||
TransparentBackground *bool `json:"transparentBackground,omitempty" node:"transparentBackground" task:"transparentBackground" modes:"image"`
|
||||
@@ -124,6 +126,19 @@ func (s GenerationSpec) Validate() error {
|
||||
if s.Options.Count != nil && *s.Options.Count < 1 {
|
||||
return invalid("options.count", "数量必须为正整数")
|
||||
}
|
||||
if s.Options.ImageParameters != nil {
|
||||
var parameters map[string]any
|
||||
if err := json.Unmarshal([]byte(*s.Options.ImageParameters), ¶meters); err != nil || parameters == nil {
|
||||
return invalid("options.imageParameters", "图片参数必须为有效对象")
|
||||
}
|
||||
for _, value := range parameters {
|
||||
switch value.(type) {
|
||||
case string, bool, float64:
|
||||
default:
|
||||
return invalid("options.imageParameters", "图片参数仅支持文本、数字或布尔值")
|
||||
}
|
||||
}
|
||||
}
|
||||
ids := map[string]bool{}
|
||||
orders := map[int]bool{}
|
||||
for i, binding := range s.ReferenceBindings {
|
||||
@@ -189,6 +204,15 @@ func OptionsFromTaskConfig(mode string, config map[string]any) (Options, error)
|
||||
switch field.Type.Elem().Kind() {
|
||||
case reflect.String:
|
||||
text, ok := raw.(string)
|
||||
if !ok && field.Tag.Get("task") == "imageParameters" {
|
||||
if parameters, object := raw.(map[string]any); object {
|
||||
encoded, err := json.Marshal(parameters)
|
||||
if err != nil {
|
||||
return options, invalid("options.imageParameters", "参数无法序列化")
|
||||
}
|
||||
text, ok = string(encoded), true
|
||||
}
|
||||
}
|
||||
if !ok {
|
||||
return options, invalid("options."+field.Tag.Get("task"), "必须是字符串")
|
||||
}
|
||||
@@ -219,6 +243,12 @@ func (o Options) TaskConfig() map[string]any {
|
||||
result[typ.Field(i).Tag.Get("task")] = fmt.Sprint(value.Field(i).Elem().Interface())
|
||||
}
|
||||
}
|
||||
if o.ImageParameters != nil {
|
||||
var parameters map[string]any
|
||||
if json.Unmarshal([]byte(*o.ImageParameters), ¶meters) == nil && parameters != nil {
|
||||
result["imageParameters"] = parameters
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user