feat(image): 以插件声明统一图片参数、尺寸选择与定价合同 (#760)

* feat(image): 图片参数 - 统一插件声明配置与生成合同

* docs(image): 图片参数 - 说明声明合同与验证边界

* fix(plugins): 图片声明 - 保留内联素材支持并同步制品文档

* fix(image): 参数合同 - 对齐审批意图和尺寸预检调用方

* fix(image): 调用链 - 保留公开意图并接通独立分辨率

* fix(image): 图片参数 - 补齐分辨率接线与目录价格投影
This commit is contained in:
huiku authored and GitHub committed 2026-10-13 19:18:21 +08:00
1 parent 88de4ce422
commit 7466119867
104 files changed
+6013 -568

No files matched your search

@@ -3,6 +3,7 @@
package app
import (
"strconv"
"strings"
"yingce/backend/internal/model"
@@ -27,6 +28,10 @@ func DefaultImageCapabilityConfig(protocol string, modelName string) *ImageCapab
MaxOutputs: 15,
}
switch model.ChannelInterfaceType(protocol) {
case model.ChannelInterfaceOpenAIImage:
// OpenAI Images 只收 WIDTHxHEIGHT:默认配置声明了 1K/2K/4K,就必须自带档位换算表,
// 否则运行时换算会被静默跳过(见 imageSizePresetMissing),实际出图档位与所选档位不一致。
image.Size.Presets = openAIImageDefaultSizePresets()
case "km-kemei-seedream":
image.References.MaxImages = 10
image.References.MaskSupported = false
@@ -45,7 +50,8 @@ func DefaultImageCapabilityConfig(protocol string, modelName string) *ImageCapab
image.References.MaskSupported = false
// grok2api / xAI Imagine:size→aspect_ratio,quality→resolution(1k/2k)。
image.Size = ImageSizeConfig{Parameter: "aspect_ratio", Values: []string{"1:1", "3:4", "4:3", "9:16", "16:9", "2:3", "3:2"}, Default: "1:1", AllowCustom: false}
image.Quality = ImageQualityConfig{Supported: true, Values: []string{"1k", "2k"}, Default: "2k"}
image.Resolution = ImageResolutionConfig{Supported: true, Values: []string{"1k", "2k"}, Default: "2k"}
image.Quality = ImageQualityConfig{Supported: false, Default: "auto"}
image.TransparentBackground = VideoBooleanConfig{Supported: false, Default: false}
image.ResponseFormat = ParameterSupport{Supported: true}
image.OutputFormat = ParameterSupport{Supported: false}
@@ -71,12 +77,14 @@ func DefaultImageCapabilityConfig(protocol string, modelName string) *ImageCapab
image.ResponseFormat.Supported = false
image.OutputFormat.Supported = false
image.MaxOutputs = 4
image.ResolutionUsesQuality = true
}
if model.ChannelInterfaceType(protocol) != model.ChannelInterfaceGrokImage && strings.HasPrefix(strings.ToLower(strings.TrimSpace(modelName)), "grok-imagine-image") {
image.References.MaxImages = 0
image.References.MaskSupported = false
image.Size = ImageSizeConfig{Parameter: "aspect_ratio", Values: []string{"1:1", "3:4", "4:3", "9:16", "16:9", "2:3", "3:2"}, Default: "1:1", AllowCustom: false}
image.Quality = ImageQualityConfig{Supported: true, Values: []string{"1k", "2k"}, Default: "2k"}
image.Resolution = ImageResolutionConfig{Supported: true, Values: []string{"1k", "2k"}, Default: "2k"}
image.Quality = ImageQualityConfig{Supported: false, Default: "auto"}
image.TransparentBackground = VideoBooleanConfig{Supported: false, Default: false}
image.ResponseFormat = ParameterSupport{Supported: true}
image.OutputFormat = ParameterSupport{Supported: false}
@@ -94,6 +102,45 @@ func defaultImageSizeValues() []string {
}
}
// openAIImageDefaultSizeTable 是 openai-image 默认能力配置的档位换算表(比例 × 1K/2K/4K)。
// 像素值与库内 openai-image 线路实际使用的预设逐项一致(gpt-image-2 / 2.5 / 4k 的 1K/2K/4K 全部命中),
// 且都在 defaultImageSizeValues() 里,不引入未声明的尺寸。
var openAIImageDefaultSizeTable = []struct {
ratio string
tierSizes [3]string
}{
{"1:1", [3]string{"1024x1024", "2048x2048", "2880x2880"}},
{"16:9", [3]string{"1824x1024", "2752x1536", "3840x2160"}},
{"9:16", [3]string{"1024x1824", "1536x2752", "2160x3840"}},
{"4:3", [3]string{"1360x1024", "2304x1728", "3264x2448"}},
{"3:4", [3]string{"1024x1360", "1728x2304", "2448x3264"}},
{"3:2", [3]string{"1536x1024", "2496x1664", "3504x2336"}},
{"2:3", [3]string{"1024x1536", "1664x2496", "2336x3504"}},
{"4:5", [3]string{"1024x1280", "1792x2240", "2560x3200"}},
{"5:4", [3]string{"1280x1024", "2240x1792", "3200x2560"}},
{"21:9", [3]string{"2048x878", "3136x1344", "3808x1632"}},
}
// openAIImageDefaultSizePresets 把上面的表展开成 3 个档位 × 10 个比例的预设。
// 像素值都来自 defaultImageSizeValues(),validateImageCapabilityConfig 会校验与支持值一致。
func openAIImageDefaultSizePresets() []ImageSizePreset {
tiers := []string{"1k", "2k", "4k"}
presets := make([]ImageSizePreset, 0, len(openAIImageDefaultSizeTable)*len(tiers))
for _, entry := range openAIImageDefaultSizeTable {
for index, tier := range tiers {
size := entry.tierSizes[index]
widthText, heightText, found := strings.Cut(size, "x")
width, widthErr := strconv.Atoi(widthText)
height, heightErr := strconv.Atoi(heightText)
if !found || widthErr != nil || heightErr != nil {
continue
}
presets = append(presets, ImageSizePreset{Tier: tier, Ratio: entry.ratio, Size: size, Width: width, Height: height})
}
}
return presets
}
// legacyImageSizeValues 用于修复旧数据中仅保存了 "*" 的图片尺寸能力。
// 这组值是前后台共同展示的基础预设,不能让历史通配符配置继续污染用户生成参数。
func legacyImageSizeValues() []string {