dsh-mo-image 0.7.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1055 @@
1
+ /**
2
+ * 尺寸与质量「模型规则」表。
3
+ *
4
+ * 协议只描述请求地址与传输方式;「这个模型认哪些值、参数叫什么」搬到这里,
5
+ * 按模型名(必要时加主机)模糊匹配。条目形状与模型选项里的用户覆盖共用一套:
6
+ *
7
+ * { match: /正则/i, host?: '正则',
8
+ * size: { mode, field, separator, second, control? },
9
+ * domain: { multiple, allowed, aspects, tiers, minPixels, maxPixels, minSide, maxSide, default, ... } }
10
+ *
11
+ * { match: /正则/i, host?: '正则',
12
+ * quality: { field, options, map, default } }
13
+ *
14
+ * { match: /正则/i, host?: '正则',
15
+ * fields: { prompt: 模板|null, negative: 模板|null, model: 模板|null, n: 模板|null,
16
+ * image: 模板|null, quality: 模板|null } }
17
+ *
18
+ * { match: /正则/i, host?: '正则',
19
+ * constants: { response_format?, watermark? } }
20
+ *
21
+ * 第四段 `constants` 是**请求常量**:不描述「字段叫什么」,只描述这家网关要的固定值
22
+ * (响应形态 response_format、输出格式 output_format、水印开关 watermark)。它原来是协议上的
23
+ * 静态属性(`adapter.responseFormat` / `adapter.outputFormat` / `adapter.watermark`),协议按 id
24
+ * 合并成 `openai-images` 之后没有 id 可挂了,改成按「模型 + 主机」判断——这几条本来就是
25
+ * 主机/模型的性质,不是协议地址的性质。同样没有兜底条目:认不出就不发这几个键。
26
+ *
27
+ * 第三段 `fields` 是字段模板的模型级微调(模板形状见 lib/field-templates.js):只写
28
+ * 「这个模型族怎么发」与预设不同的地方。它与尺寸/质量一样按「模型 + 主机」先、
29
+ * 只按模型后匹配,但**故意没有兜底条目**——字段名正是预设要区分的东西,一条通配规则
30
+ * 会把所有预设盖掉,认不出就返回 null 让调用方回落到预设。
31
+ * 合并顺序是 用户覆盖 > 规则 > 预设,逐字段取第一个有定义的层,所以一条规则**可以只写
32
+ * 它要改的那几个字段**(省略 = 跟随预设);整条写 null = 显式不发,后面的层盖不掉它。
33
+ *
34
+ * mode(怎么发):
35
+ * 'wh-string' —— 一个字段写 "1024x1024"(separator 决定分隔符)
36
+ * 'wh-fields' —— width / height 两个字段
37
+ * 'aspect' —— 只发比例(aspect_ratio)
38
+ * 'tier' —— 发档位名("2K"),tierLabels 语义
39
+ * 'prompt' —— 尺寸只能写进提示词
40
+ * 'none' —— 该模型不发尺寸字段
41
+ *
42
+ * `control`(可选)只覆盖"面板给哪种控件",不影响线上写法:默认由 mode + domain.allowed
43
+ * 推导(有白名单 → 预设芯片,没有 → 宽高输入框),个别模型需要另一种组合时才点名。
44
+ *
45
+ * `second`(第二个尺寸字段,形如 { from: 'tier', field: 'imageSize' }):
46
+ * xAI 的 `resolution` 用它(`{ from: 'tier', field: 'resolution' }`,档位 1k/2k 直接发);
47
+ * Gemini 的 imageSize、BFL 的 resolution 仍硬编码在各自 execute / build 里
48
+ * (它们跟比例一起发、或大小写要转,模板层看不出这个差别)。
49
+ *
50
+ * 匹配顺序:先「模型 + 主机」,再「只按模型」,命中第一条即返回;都不命中返回 null。
51
+ * 主机指纹压过模型指纹——同一个模型名在不同网关字段不同(qwen-image 在硅基流动是
52
+ * image_size、在百炼是 size 且用 `*`),只看模型名一定会串。
53
+ *
54
+ * 最后一条是**兜底规则**(`host` 为空、`match` 匹配任意非空模型名):认不出的模型
55
+ * 按 OpenAI 兼容发 `size`,因为通用网关(openai-images / localai)的尺寸本来就跟
56
+ * 模型名无关。所以 `detectSizeRule()` 对非空模型 id 实际上总会命中一条;"不发尺寸"
57
+ * 由 `mode: 'none'` 表达(模型规则或用户覆盖),不是靠"没命中"。
58
+ *
59
+ * 条目逐条抄自 lib/adapters.js、lib/adapters/{cn,async,openai}.js 的
60
+ * `size` / `quality` / `sizeByModel` 声明,以及原来按模型名兜底的 SIZE_FAMILIES;
61
+ * 数值一律照抄,不在这里新增或调整取值域。迁移对应关系:
62
+ * style 'string' → mode 'wh-string'
63
+ * style 'width-height' → mode 'wh-fields'
64
+ * style 'aspect' → mode 'aspect'
65
+ * tierLabels: true → mode 'tier'
66
+ * control 'prompt' → mode 'prompt'
67
+ * wire: [](noSizeField)→ mode 'none'
68
+ * domain 沿用现有策略里的键名(multiple/allowed/aspects/tiers/minPixels/maxPixels/
69
+ * minSide/maxSide/default/allowCustom/custom/hint),这样规则与用户覆盖能用同一个
70
+ * 合并器叠加。
71
+ *
72
+ * 不收录:a1111 / comfyui / swarmui —— 宽高写在 sdapi 参数或工作流占位符里,
73
+ * 由 workflowParamsOf() 管,不走规则。fal / replicate / openai-responses 现在没有
74
+ * 自己的尺寸或质量声明(fal、replicate 由模型 schema 决定),它们落到兜底规则上,
75
+ * 与原来 encodeSizePrimary 拿默认参数名兜出的 `{ size }` 一致。
76
+ */
77
+
78
+ function endpointOf(baseUrl) {
79
+ const text = String(baseUrl || '').trim();
80
+ if (!text) return null;
81
+ try { return new URL(/^[a-z][a-z\d+.-]*:\/\//i.test(text) ? text : 'https://' + text); }
82
+ catch (_error) { return null; }
83
+ }
84
+
85
+ const hostCache = new Map();
86
+
87
+ function hostMatches(pattern, host) {
88
+ if (!host) return false;
89
+ let compiled = hostCache.get(pattern);
90
+ if (!compiled) {
91
+ try {
92
+ compiled = new RegExp(pattern, 'i');
93
+ } catch (_error) {
94
+ return false;
95
+ }
96
+ hostCache.set(pattern, compiled);
97
+ }
98
+ compiled.lastIndex = 0;
99
+ return compiled.test(host);
100
+ }
101
+
102
+ function modelMatches(pattern, model) {
103
+ if (!(pattern instanceof RegExp)) return false;
104
+ pattern.lastIndex = 0;
105
+ return pattern.test(model);
106
+ }
107
+
108
+ function detect(rules, model, baseUrl, adapterId) {
109
+ const id = String(model || '').trim();
110
+ if (!id) return null;
111
+ const endpoint = endpointOf(baseUrl);
112
+ const matches = (rule) => {
113
+ if (adapterId !== undefined && rule.adapters && !rule.adapters.includes(adapterId)) return false;
114
+ if (rule.basePath && (!endpoint || !rule.basePath.test(endpoint.pathname))) return false;
115
+ return modelMatches(rule.match, id);
116
+ };
117
+ // 第一轮:模型与主机同时命中。网关差异优先于模型家族。
118
+ for (const rule of rules) {
119
+ if (!rule.host || !hostMatches(rule.host, endpoint?.hostname)) continue;
120
+ if (!matches(rule)) continue;
121
+ return rule;
122
+ }
123
+ // 第二轮:只看模型名。
124
+ for (const rule of rules) {
125
+ if (rule.host || !matches(rule)) continue;
126
+ return rule;
127
+ }
128
+ return null;
129
+ }
130
+
131
+ /* ------------------------------------------------------- 档位表(复用) */
132
+
133
+ const TIERS_1K_2K_4K = [
134
+ { value: '1K', pixels: 1048576 }, { value: '2K', pixels: 4194304 }, { value: '4K', pixels: 16777216 }
135
+ ];
136
+ const TIERS_1K_15K_2K = [
137
+ { value: '1K', pixels: 1048576 }, { value: '1.5K', pixels: 2359296 }, { value: '2K', pixels: 4194304 }
138
+ ];
139
+ const GEMINI_IMAGE_SIZE = {
140
+ mode: 'aspect',
141
+ field: 'generationConfig.imageConfig.aspectRatio',
142
+ second: { from: 'tier', field: 'generationConfig.imageConfig.imageSize' }
143
+ };
144
+ const GPT_IMAGE = /gpt[-_.]?image/i;
145
+ const GLM_IMAGE = /glm-?image/i;
146
+ const BIGMODEL_HOST = '^open\\.bigmodel\\.cn$';
147
+ const GEMINI_IMAGE = /gemini[^ ]*image|nano[-_.]banana/i;
148
+ export const GEMINI_25_IMAGE = /2[._-]5[-_.]flash[-_.]image/i;
149
+ export const isGeminiImageModel = (model) => GEMINI_IMAGE.test(model);
150
+ export const STABILITY_SD3_MODEL = /sd3(?:\.5)?-(?:large(?:-turbo)?|medium|flash)/i;
151
+ export const IDEOGRAM_45 = /^ideogram-4-5$/i;
152
+ export const IDEOGRAM_46 = /^ideogram-4-6$/i;
153
+ export const IDEOGRAM_EDIT = /^ideogram-4-[56]$/i;
154
+ const IDEOGRAM_2K_SIZES = [
155
+ '2048x2048', '1440x2880', '2880x1440', '1664x2496', '2496x1664', '1792x2240', '2240x1792',
156
+ '1440x2560', '2560x1440', '1600x2560', '2560x1600', '1728x2304', '2304x1728', '1296x3168',
157
+ '3168x1296', '1152x2944', '2944x1152', '1248x3328', '3328x1248', '1280x3072', '3072x1280',
158
+ '1024x3072', '3072x1024', '1024x1024', '896x1120', '1120x896', '864x1152', '1152x864',
159
+ '832x1248', '1248x832', '800x1280', '1280x800', '720x1280', '1280x720', '720x1440', '1440x720'
160
+ ];
161
+ const IDEOGRAM_LEGACY_QUALITY = { turbo: 'low', default: 'medium', quality: 'high' };
162
+ const SEEDREAM_5_LITE = /seedream-?5[.-]?0-lite/i;
163
+ const SEEDREAM_5 = /seedream-?5[.-]?[05]/i;
164
+ const SEEDREAM_45 = /seedream-?4[.-]?5/i;
165
+ const SEEDREAM_40 = /seedream-?4[.-]?0/i;
166
+ export const WAN_26_T2I = /\bwan2\.6-t2i\b/i;
167
+ export const WAN_27_IMAGE = /\bwan2\.7-image\b/i;
168
+ export const WAN_27_IMAGE_PRO = /\bwan2\.7-image-pro\b/i;
169
+ const TIERS_2K_4K = [{ value: '2K', pixels: 4194304 }, { value: '4K', pixels: 16777216 }];
170
+ const TIERS_2K_3K_4K = [
171
+ { value: '2K', pixels: 4194304 }, { value: '3K', pixels: 9437184 }, { value: '4K', pixels: 16777216 }
172
+ ];
173
+ const TIERS_512_1K_2K_4K = [
174
+ { value: '512', pixels: 262144 }, { value: '1K', pixels: 1048576 },
175
+ { value: '2K', pixels: 4194304 }, { value: '4K', pixels: 16777216 }
176
+ ];
177
+
178
+ const GEMINI_STANDARD_ASPECTS = ['1:1', '2:3', '3:2', '3:4', '4:3', '4:5', '5:4', '9:16', '16:9', '21:9'];
179
+ const GEMINI_ASPECTS = [...GEMINI_STANDARD_ASPECTS, '1:4', '4:1', '1:8', '8:1'];
180
+
181
+ /* ------------------------------------------------------------ 尺寸规则 */
182
+
183
+ export const SIZE_RULES = [
184
+ /* ---- BFL:FLUX 2 是 width/height,FLUX 3 换成比例 + 小写档位 ---- */
185
+ {
186
+ match: /flux-?3/i,
187
+ host: 'bfl\\.ai',
188
+ size: { mode: 'aspect', field: 'aspect_ratio' },
189
+ domain: {
190
+ aspects: ['21:9', '2:1', '16:9', '3:2', '7:5', '4:3', '5:4', '1:1', '4:5', '3:4', '5:7', '2:3', '9:16', '1:2', '9:21', 'auto'],
191
+ tiers: [
192
+ { value: '768sq', pixels: 589824 }, { value: '1k', pixels: 1048576 }, { value: '1.5k', pixels: 2359296 },
193
+ { value: '2k', pixels: 4194304 }, { value: '4k', pixels: 16777216 }
194
+ ],
195
+ minSide: 256, maxSide: 6256, maxPixels: 16822272
196
+ }
197
+ },
198
+ {
199
+ // BFL 的提交体只认 width / height(FLUX 3 除外,见上一条)。
200
+ match: /.*/,
201
+ host: 'bfl\\.ai',
202
+ size: { mode: 'wh-fields' },
203
+ domain: { minSide: 64, maxPixels: 4194304 }
204
+ },
205
+
206
+ /* ---- OpenRouter:默认比例;gemini 系另有 resolution 档位 ---- */
207
+ {
208
+ match: /gemini/i,
209
+ host: 'openrouter\\.ai',
210
+ size: { mode: 'aspect', field: 'aspect_ratio' },
211
+ domain: { tiers: TIERS_512_1K_2K_4K, default: '1024x1024' }
212
+ },
213
+ {
214
+ match: /.*/,
215
+ host: 'openrouter\\.ai',
216
+ size: { mode: 'aspect', field: 'aspect_ratio' },
217
+ domain: { default: '1024x1024' }
218
+ },
219
+
220
+ /* ---- Together AI:所有模型都是宽高两个字段 ---- */
221
+ {
222
+ match: /.*/,
223
+ host: 'api\\.together\\.xyz',
224
+ size: { mode: 'wh-fields' },
225
+ domain: { default: '1024x1024' }
226
+ },
227
+
228
+ /* ---- Stability AI:只有比例;三个端点像素都固定 ---- */
229
+ {
230
+ match: /.*/,
231
+ host: 'stability\\.ai',
232
+ size: { mode: 'aspect', field: 'aspect_ratio' },
233
+ domain: {
234
+ aspects: ['21:9', '16:9', '3:2', '5:4', '1:1', '4:5', '2:3', '9:16', '9:21'],
235
+ default: '1024x1024',
236
+ hint: 'fixedPixels'
237
+ }
238
+ },
239
+
240
+ /* ---- xAI Grok Imagine:比例 + 小写两档,档位另写一个 resolution 字段 ---- */
241
+ {
242
+ match: /.*/,
243
+ host: 'api\\.x\\.ai',
244
+ size: { mode: 'aspect', field: 'aspect_ratio', second: { from: 'tier', field: 'resolution' } },
245
+ domain: {
246
+ aspects: ['1:1', '16:9', '9:16', '4:3', '3:4', '3:2', '2:3', '2:1', '1:2', '19.5:9', '9:19.5', '20:9', '9:20', '21:9', '5:2'],
247
+ tiers: [{ value: '1k', pixels: 1048576 }, { value: '2k', pixels: 4194304 }],
248
+ default: '1024x1024'
249
+ }
250
+ },
251
+
252
+ /* ---- Foundry MAI:部署名可以自定义,未识别版本时采用两代都接受的尺寸域 ---- */
253
+ {
254
+ match: /mai[-_. ]image[-_. ]2[.-]6/i,
255
+ host: '(?:^|\\.)services\\.ai\\.azure\\.com$',
256
+ basePath: /^\/mai\/v1(?:\/|$)/i,
257
+ adapters: ['custom'],
258
+ size: { mode: 'wh-fields', field: 'width' },
259
+ domain: { minSide: 768, maxPixels: 2359296, default: '1024x1024' }
260
+ },
261
+ {
262
+ match: /.*/,
263
+ host: '(?:^|\\.)services\\.ai\\.azure\\.com$',
264
+ basePath: /^\/mai\/v1(?:\/|$)/i,
265
+ adapters: ['custom'],
266
+ generic: true,
267
+ size: { mode: 'wh-fields', field: 'width' },
268
+ domain: { minSide: 768, maxPixels: 1048576, default: '1024x1024' }
269
+ },
270
+
271
+ /* ---- Azure OpenAI:路径与鉴权不同,尺寸域跟自家 gpt-image 一致 ---- */
272
+ {
273
+ match: /.*/,
274
+ host: 'openai\\.azure\\.com|services\\.ai\\.azure\\.com',
275
+ adapters: ['openai-images'],
276
+ size: { mode: 'wh-string', field: 'size' },
277
+ domain: { multiple: 16, minPixels: 655360, maxPixels: 8294400, default: '1024x1024' }
278
+ },
279
+
280
+ /* ---- 硅基流动:image_size;Qwen-Image-Edit 系列明确不收 ---- */
281
+ {
282
+ match: /qwen-image-edit/i,
283
+ host: 'api\\.siliconflow\\.cn',
284
+ size: { mode: 'none' },
285
+ domain: { hint: 'noSizeField' }
286
+ },
287
+ {
288
+ match: /qwen-image/i,
289
+ host: 'api\\.siliconflow\\.cn',
290
+ size: { mode: 'wh-string', field: 'image_size' },
291
+ domain: {
292
+ allowed: ['1328x1328', '1664x928', '928x1664', '1472x1140', '1140x1472', '1584x1056', '1056x1584'],
293
+ allowCustom: true,
294
+ custom: true
295
+ }
296
+ },
297
+ {
298
+ match: /.*/,
299
+ host: 'api\\.siliconflow\\.cn',
300
+ size: { mode: 'wh-string', field: 'image_size' },
301
+ domain: {
302
+ allowed: ['1024x1024', '960x1280', '768x1024', '720x1440', '720x1280'],
303
+ allowCustom: true,
304
+ custom: true
305
+ }
306
+ },
307
+
308
+ /* ---- 阿里云百炼 · Qwen-Image:size 用星号分隔 ---- */
309
+ {
310
+ match: /qwen-image/i,
311
+ host: 'dashscope\\.aliyuncs\\.com',
312
+ size: { mode: 'wh-string', field: 'size', separator: '*' },
313
+ domain: { allowCustom: true, minPixels: 262144, maxPixels: 4194304, hint: 'modelDecides' }
314
+ },
315
+
316
+ /* ---- 魔搭:网关按每边 [64, 2048] 校验,模型族上限另算 ---- */
317
+ {
318
+ match: /flux/i,
319
+ host: 'api-inference\\.modelscope\\.(cn|ai)',
320
+ size: { mode: 'wh-string', field: 'size' },
321
+ domain: { multiple: 16, minSide: 64, maxSide: 1024, default: '1024x1024' }
322
+ },
323
+ {
324
+ match: /qwen-image/i,
325
+ host: 'api-inference\\.modelscope\\.(cn|ai)',
326
+ size: { mode: 'wh-string', field: 'size' },
327
+ domain: { multiple: 16, minSide: 64, maxSide: 1664, default: '1024x1024' }
328
+ },
329
+ {
330
+ match: /z-image/i,
331
+ host: 'api-inference\\.modelscope\\.(cn|ai)',
332
+ size: { mode: 'wh-string', field: 'size' },
333
+ domain: { multiple: 16, minSide: 512, maxSide: 2048, default: '1024x1024' }
334
+ },
335
+ {
336
+ match: /.*/,
337
+ host: 'api-inference\\.modelscope\\.(cn|ai)',
338
+ size: { mode: 'wh-string', field: 'size' },
339
+ domain: { multiple: 16, minSide: 64, maxSide: 2048, default: '1024x1024' }
340
+ },
341
+
342
+ /* ---- 火山方舟:线上发档位名,档位集合按 seedream 版本分叉 ---- */
343
+ {
344
+ match: SEEDREAM_5_LITE,
345
+ host: 'volces\\.com',
346
+ size: { mode: 'tier', field: 'size' },
347
+ domain: { tiers: TIERS_2K_3K_4K, minPixels: 3686400, maxPixels: 16777216, default: '1024x1024', custom: true }
348
+ },
349
+ {
350
+ match: SEEDREAM_5,
351
+ host: 'volces\\.com',
352
+ size: { mode: 'tier', field: 'size' },
353
+ domain: { tiers: TIERS_1K_15K_2K, minPixels: 921600, maxPixels: 4624220, default: '1024x1024', custom: true }
354
+ },
355
+ {
356
+ match: SEEDREAM_45,
357
+ host: 'volces\\.com',
358
+ size: { mode: 'tier', field: 'size' },
359
+ domain: { tiers: TIERS_2K_4K, minPixels: 3686400, maxPixels: 16777216, default: '1024x1024', custom: true }
360
+ },
361
+ {
362
+ match: SEEDREAM_40,
363
+ host: 'volces\\.com',
364
+ size: { mode: 'tier', field: 'size' },
365
+ domain: { tiers: TIERS_1K_2K_4K, minPixels: 921600, maxPixels: 16777216, default: '1024x1024', custom: true }
366
+ },
367
+ {
368
+ match: /.*/,
369
+ host: 'volces\\.com',
370
+ size: { mode: 'tier', field: 'size' },
371
+ domain: { tiers: TIERS_2K_3K_4K, default: '1024x1024', custom: true }
372
+ },
373
+
374
+ /* ---- GPT-Image:任意 W×H,16 的倍数、1:3–3:1 ---- */
375
+ {
376
+ match: GPT_IMAGE,
377
+ size: { mode: 'wh-string', field: 'size' },
378
+ domain: { multiple: 16, minPixels: 655360, maxPixels: 8294400, default: '1024x1024' }
379
+ },
380
+
381
+ /* ---- DALL·E 3:三个固定尺寸 ---- */
382
+ {
383
+ match: /dall-?e-?3/i,
384
+ size: { mode: 'wh-string', field: 'size' },
385
+ domain: { allowed: ['1024x1024', '1792x1024', '1024x1792'], default: '1024x1024' }
386
+ },
387
+
388
+ /* ---- Gemini / Nano Banana:比例 + 档位(imageSize 大小写敏感,512 只有 3.1-flash 认) ---- */
389
+ {
390
+ match: /3[._-]1[-_.]flash[-_.]image/i,
391
+ adapters: ['google-gemini'],
392
+ size: GEMINI_IMAGE_SIZE,
393
+ domain: { aspects: GEMINI_ASPECTS, tiers: TIERS_512_1K_2K_4K, default: '1024x1024' }
394
+ },
395
+ {
396
+ match: /3[._-]1[-_.]flash[-_.]lite[-_.]image|nano[-_.]banana[-_.]2[-_.]lite/i,
397
+ adapters: ['google-gemini'],
398
+ size: GEMINI_IMAGE_SIZE,
399
+ domain: { aspects: GEMINI_STANDARD_ASPECTS, tiers: TIERS_1K_2K_4K.slice(0, 1), default: '1024x1024' }
400
+ },
401
+ {
402
+ match: /nano[-_.]banana/i,
403
+ adapters: ['google-gemini'],
404
+ size: GEMINI_IMAGE_SIZE,
405
+ domain: { aspects: GEMINI_ASPECTS, tiers: TIERS_1K_2K_4K, default: '1024x1024' }
406
+ },
407
+ {
408
+ match: GEMINI_25_IMAGE,
409
+ adapters: ['google-gemini'],
410
+ size: { mode: 'none' },
411
+ domain: { hint: 'noSizeField' }
412
+ },
413
+ {
414
+ match: /gemini[^ ]*image|3[-_.]pro[-_.]image/i,
415
+ adapters: ['google-gemini'],
416
+ size: GEMINI_IMAGE_SIZE,
417
+ domain: { aspects: GEMINI_STANDARD_ASPECTS, tiers: TIERS_1K_2K_4K, default: '1024x1024' }
418
+ },
419
+
420
+ /* ---- seedream:通过中转站时按档位算像素预算,线上仍发 WxH ---- */
421
+ {
422
+ match: SEEDREAM_5_LITE,
423
+ size: { mode: 'wh-string', field: 'size' },
424
+ domain: { tiers: TIERS_2K_3K_4K, minPixels: 3686400, maxPixels: 16777216, custom: true }
425
+ },
426
+ {
427
+ match: SEEDREAM_5,
428
+ size: { mode: 'wh-string', field: 'size' },
429
+ domain: { tiers: TIERS_1K_15K_2K, minPixels: 921600, maxPixels: 4624220, custom: true }
430
+ },
431
+ {
432
+ match: SEEDREAM_45,
433
+ size: { mode: 'wh-string', field: 'size' },
434
+ domain: { tiers: TIERS_2K_4K, minPixels: 3686400, maxPixels: 16777216, custom: true }
435
+ },
436
+ {
437
+ match: SEEDREAM_40,
438
+ size: { mode: 'wh-string', field: 'size' },
439
+ domain: { tiers: TIERS_1K_2K_4K, minPixels: 921600, maxPixels: 16777216, custom: true }
440
+ },
441
+
442
+ /* ---- Ideogram ---- */
443
+ {
444
+ // 透明背景:比例 + 小写档位(按 v2 端点的小写来发)。
445
+ match: /ideogram-4-transparent/i,
446
+ size: { mode: 'aspect', field: 'aspect_ratio' },
447
+ domain: {
448
+ aspects: ['auto', '1x4', '1x3', '1x2', '9x16', '10x16', '2x3', '3x4', '4x5', '1x1', '5x4', '4x3', '3x2', '16x10', '16x9', '2x1', '3x1', '4x1'],
449
+ tiers: [
450
+ { value: '1k', pixels: 1048576 }, { value: '2k', pixels: 4194304 },
451
+ { value: '4k', pixels: 16777216 }, { value: '8k', pixels: 67108864 }
452
+ ],
453
+ default: '1024x1024'
454
+ }
455
+ },
456
+ {
457
+ // 没有参考图时只接受 1K / 2K 的预设尺寸,与图生图共用模型尺寸选择器。
458
+ match: IDEOGRAM_45,
459
+ adapters: ['ideogram'],
460
+ size: { mode: 'wh-string', field: 'size' },
461
+ domain: {
462
+ allowed: IDEOGRAM_2K_SIZES,
463
+ default: '1024x1024'
464
+ }
465
+ },
466
+ {
467
+ match: IDEOGRAM_46,
468
+ adapters: ['ideogram'],
469
+ size: { mode: 'wh-string', field: 'size' },
470
+ domain: {
471
+ allowCustom: true, multiple: 32, minSide: 256, maxSide: 8192, maxPixels: 4096 ** 2, maxAspect: 6,
472
+ default: '1024x1024'
473
+ }
474
+ },
475
+ {
476
+ // ideogram-4 只收 resolution 像素枚举,没有 aspect_ratio。
477
+ match: /ideogram-4/i,
478
+ size: { mode: 'wh-string', field: 'resolution' },
479
+ domain: {
480
+ aspects: ['auto', '1x3', '3x1', '1x2', '2x1', '9x16', '16x9', '10x16', '16x10', '2x3', '3x2', '3x4', '4x3', '4x5', '5x4', '1x1'],
481
+ default: '1024x1024',
482
+ allowed: [...IDEOGRAM_2K_SIZES, '512x1536', '1536x512'],
483
+ allowCustom: false
484
+ }
485
+ },
486
+ {
487
+ // ideogram-3:比例是字母 x(16x9),不是冒号。
488
+ match: /ideogram/i,
489
+ size: { mode: 'aspect', field: 'aspect_ratio' },
490
+ domain: {
491
+ aspects: ['auto', '1x3', '3x1', '1x2', '2x1', '9x16', '16x9', '10x16', '16x10', '2x3', '3x2', '3x4', '4x3', '4x5', '5x4', '1x1'],
492
+ default: '1024x1024'
493
+ }
494
+ },
495
+
496
+ /* ---- Recraft:三族像素表完全不同,表外值直接 400 ---- */
497
+ {
498
+ // 原声明是 `/_pro$/i`,但它只活在 recraft 适配器的 sizeByModel 里(模型 id 必然是
499
+ // recraft 的);搬进全局表后必须带上厂商前缀,否则 fal 的 `fal-ai/flux-2-pro`、
500
+ // replicate 的 `black-forest-labs/flux-2-pro` 也会命中 recraft 的 2K 像素表,
501
+ // 1024x1024 会被吸附成 2048x2048。前缀写法不限制主机:recraft 模型走中转照旧命中。
502
+ match: /recraft.*_pro(?![a-z0-9])/i,
503
+ size: { mode: 'wh-string', field: 'size' },
504
+ domain: {
505
+ allowed: [
506
+ '2048x2048', '3072x1536', '1536x3072', '2560x1664', '1664x2560', '2432x1792', '1792x2432',
507
+ '2304x1792', '1792x2304', '1664x2688', '2560x1792', '1792x2560', '2688x1536', '1536x2688'
508
+ ],
509
+ allowCustom: false
510
+ }
511
+ },
512
+ {
513
+ match: /recraftv[23]|v[23]_/i,
514
+ size: { mode: 'wh-string', field: 'size' },
515
+ domain: {
516
+ allowed: [
517
+ '1024x1024', '2048x1024', '1024x2048', '1536x1024', '1024x1536', '1365x1024', '1024x1365',
518
+ '1280x1024', '1024x1280', '1024x1707', '1434x1024', '1024x1434', '1820x1024', '1024x1820'
519
+ ],
520
+ allowCustom: false
521
+ }
522
+ },
523
+ {
524
+ // 向量模型:面板给比例(control:'aspect'),但线上发的仍是 `size:"1024x1024"` 像素串。
525
+ // 单看 mode 表达不了这个组合,所以规则里额外点名 control(wire 形状仍按 wh-string)。
526
+ match: /_vector/i,
527
+ size: { mode: 'wh-string', field: 'size', control: 'aspect' },
528
+ domain: {
529
+ aspects: ['1:1', '2:1', '1:2', '3:2', '2:3', '4:3', '3:4', '5:4', '4:5', '16:9', '9:16'],
530
+ // 像素白名单是从 recraft 基础声明继承下来的(向量模型没重写),落位仍按它取整。
531
+ allowed: [
532
+ '1024x1024', '1536x768', '768x1536', '1280x832', '832x1280', '1216x896', '896x1216',
533
+ '1152x896', '896x1152', '832x1344', '1280x896', '896x1280', '1344x768', '768x1344'
534
+ ],
535
+ allowCustom: false
536
+ }
537
+ },
538
+ {
539
+ match: /recraft/i,
540
+ size: { mode: 'wh-string', field: 'size' },
541
+ domain: {
542
+ allowed: [
543
+ '1024x1024', '1536x768', '768x1536', '1280x832', '832x1280', '1216x896', '896x1216',
544
+ '1152x896', '896x1152', '832x1344', '1280x896', '896x1280', '1344x768', '768x1344'
545
+ ],
546
+ allowCustom: false
547
+ }
548
+ },
549
+
550
+ /* ---- 智谱 BigModel:glm-image 与 cogview 的限制不一样 ---- */
551
+ {
552
+ match: /cogview/i,
553
+ size: { mode: 'wh-string', field: 'size' },
554
+ domain: { allowCustom: true, multiple: 16, minSide: 512, maxSide: 2048, maxPixels: 2097152 }
555
+ },
556
+ {
557
+ match: GLM_IMAGE,
558
+ size: { mode: 'wh-string', field: 'size' },
559
+ domain: { allowCustom: true, multiple: 32, minSide: 1024, maxSide: 2048, maxPixels: 4194304 }
560
+ },
561
+
562
+ /* ---- 通义万相:只有 wan2.7 认档位缩写,pro 的上限另一套;像素白名单/默认值沿用基础声明 ---- */
563
+ {
564
+ match: WAN_27_IMAGE_PRO,
565
+ size: { mode: 'tier', field: 'parameters.size', separator: '*' },
566
+ domain: {
567
+ tiers: TIERS_1K_2K_4K, minPixels: 589824, maxPixels: 16777216,
568
+ allowed: ['1280x1280', '1696x960', '960x1696', '1472x1104', '1104x1472'],
569
+ allowCustom: true, custom: true, default: '1280x1280', hint: 'modelDecides'
570
+ }
571
+ },
572
+ {
573
+ match: WAN_27_IMAGE,
574
+ size: { mode: 'tier', field: 'parameters.size', separator: '*' },
575
+ domain: {
576
+ tiers: TIERS_1K_2K_4K.slice(0, 2), minPixels: 589824, maxPixels: 4194304,
577
+ allowed: ['1280x1280', '1696x960', '960x1696', '1472x1104', '1104x1472'],
578
+ allowCustom: true, custom: true, default: '1280x1280', hint: 'modelDecides'
579
+ }
580
+ },
581
+ {
582
+ // 万相的模型 id 有两种写法:wanx2.1-* 与 wan2.6/2.7-image(后者才算得上"模型名")。
583
+ match: /wanx|wan[0-9]/i,
584
+ size: { mode: 'tier', field: 'parameters.size', separator: '*' },
585
+ domain: {
586
+ allowed: ['1280x1280', '1696x960', '960x1696', '1472x1104', '1104x1472'],
587
+ allowCustom: true,
588
+ custom: true,
589
+ default: '1280x1280',
590
+ hint: 'modelDecides'
591
+ }
592
+ },
593
+
594
+ /* ---- MiniMax H3-Image:比例 + area 档位,**不能**同时发 size ----
595
+ *
596
+ * H3 的尺寸是"二选一"的两套写法(官方 Text-to-Image / Image Edit 两个 OpenAPI 都这么写):
597
+ *
598
+ * - `size: "WIDTHxHEIGHT"`,此时传 `aspect_ratio` / `area` 会 400(传 `auto` 也算传);
599
+ * - `size` 省略或 `auto`,宽高由 `aspect_ratio`(X:Y,1:3–3:1)和 `area`(1K/2K/4K)算出来。
600
+ *
601
+ * 这里选第二套:`mode: 'aspect'` 只发 `aspect_ratio`(不发 `size`),档位另写 `area`。
602
+ * 这样任何用户选出来的尺寸都落在合法区间里(W×H 那套一旦超出 655,360–20,000,000 像素
603
+ * 或 1:3–3:1 就 400,而且服务端不会自动缩放),档位语义也正好对上 H3 的 1K/2K/4K
604
+ * 目标面积 1024²/2048²/4096²。
605
+ *
606
+ * 比例表来自官方文档:示例值 16:9 / 3:4 / 21:9 / 3:1,尺寸表里还有 1:1 / 4:3 / 9:16,
607
+ * 合法区间是 1:3–3:1(含边界)。不带 host:官方两个域名(api.minimax.io / api.minimax.cn)
608
+ * 是同一套接口,中转站上的 H3 也一样。
609
+ */
610
+ {
611
+ match: /h3[-_ ]?image/i,
612
+ size: { mode: 'aspect', field: 'aspect_ratio', second: { from: 'tier', field: 'area' } },
613
+ domain: {
614
+ aspects: ['1:1', '4:3', '3:4', '3:2', '2:3', '16:9', '9:16', '21:9', '3:1', '1:3'],
615
+ tiers: TIERS_1K_2K_4K,
616
+ default: '1024x1024'
617
+ }
618
+ },
619
+
620
+ /* ---- OpenAI 兼容网关上的 FLUX:直连 BFL 是 width/height(上面那条 host 规则),
621
+ * 走兼容网关就是普通的 `size`。和兜底那条形状完全相同,但**算「认出了这个模型」**:
622
+ * 一键配置据此写一条覆盖并锁上,而不是当成「规则表里没有它」跳过。
623
+ */
624
+ {
625
+ match: /flux/i,
626
+ size: { mode: 'wh-string', field: 'size' },
627
+ domain: { multiple: 1 }
628
+ },
629
+
630
+ /* ---- 兜底(必须是最后一条)-----------------------------------------------------
631
+ *
632
+ * 认不出的模型按 OpenAI 兼容发 `size`,而不是"不发尺寸"。
633
+ *
634
+ * 理由(见设计文档「兜底规则」):`openai-images` / `localai` 这类通用协议的尺寸
635
+ * 声明本来就与模型名无关,规则表表达不了;没有这条,所有中转站会突然从"发尺寸"
636
+ * 变成"不发尺寸",而那是最大的一群人。真要"不发",用 `mode: 'none'`(模型规则
637
+ * 或用户覆盖)——这个语义修正写在设计文档里。
638
+ *
639
+ * 位置很重要:detect() 第二轮按数组顺序只看模型名,这条 `.*` 必须在所有具体规则
640
+ * 之后,否则会抢先命中一切。`generic` 标记告诉调用方:命中它≠认出了这个模型。
641
+ */
642
+ {
643
+ match: /.*/,
644
+ generic: true,
645
+ size: { mode: 'wh-string', field: 'size' },
646
+ domain: { multiple: 1 }
647
+ }
648
+ ];
649
+
650
+ /* ------------------------------------------------------------ 质量规则 */
651
+
652
+ export const QUALITY_RULES = [
653
+ {
654
+ match: GLM_IMAGE,
655
+ host: BIGMODEL_HOST,
656
+ adapters: ['openai-images'],
657
+ quality: { field: 'quality', options: ['hd'], default: 'hd' }
658
+ },
659
+ {
660
+ match: /cogview[-_.]?(?:4(?!\d)|3[-_.]flash)/i,
661
+ host: BIGMODEL_HOST,
662
+ adapters: ['openai-images'],
663
+ quality: { field: 'quality', options: ['standard', 'hd'], default: 'standard' }
664
+ },
665
+ /* ---- Azure OpenAI:主机决定用哪套质量枚举(没有 xhigh / max) ---- */
666
+ {
667
+ match: /.*/,
668
+ host: 'openai\\.azure\\.com|services\\.ai\\.azure\\.com',
669
+ adapters: ['openai-images'],
670
+ quality: { field: 'quality', options: ['low', 'medium', 'high', 'auto'], default: 'high' }
671
+ },
672
+
673
+ /* ---- GPT Image 2.5 / 2.6 的 sunburst 与 flare 多两档 ---- */
674
+ {
675
+ match: /gpt[-_.]?image[-_.]2[._-][56][-_.](sunburst|flare)/i,
676
+ adapters: ['openai-images'],
677
+ quality: { field: 'quality', options: ['low', 'medium', 'high', 'xhigh', 'max', 'auto'], default: 'high' }
678
+ },
679
+
680
+ /* ---- GPT-Image ---- */
681
+ {
682
+ match: GPT_IMAGE,
683
+ adapters: ['openai-images'],
684
+ quality: { field: 'quality', options: ['low', 'medium', 'high', 'auto'], default: 'high' }
685
+ },
686
+
687
+ /* ---- DALL·E 3 ---- */
688
+ {
689
+ match: /dall-?e-?3/i,
690
+ quality: { field: 'quality', options: ['standard', 'hd'], default: 'standard' }
691
+ },
692
+
693
+ /* ---- Ideogram 4.5/4.6 用 quality,较早的版本用 rendering_speed ---- */
694
+ {
695
+ match: IDEOGRAM_45,
696
+ adapters: ['ideogram'],
697
+ quality: { field: 'quality', options: ['low', 'medium', 'high'], map: IDEOGRAM_LEGACY_QUALITY, default: 'medium' }
698
+ },
699
+ {
700
+ match: IDEOGRAM_46,
701
+ adapters: ['ideogram'],
702
+ quality: { field: 'quality', options: ['very_low', 'low', 'medium', 'high'], map: IDEOGRAM_LEGACY_QUALITY, default: 'medium' }
703
+ },
704
+ {
705
+ match: /ideogram/i,
706
+ quality: {
707
+ field: 'rendering_speed',
708
+ options: ['turbo', 'default', 'quality'],
709
+ map: { turbo: 'TURBO', default: 'DEFAULT', quality: 'QUALITY' },
710
+ default: 'default'
711
+ }
712
+ }
713
+ ];
714
+
715
+ /* ------------------------------------------------------------ 字段规则 */
716
+
717
+ /**
718
+ * 字段模板的模型级微调。字段名逐条抄自协议代码,不在这里新造:
719
+ *
720
+ * - 主机型条目抄「这家网关的接口形状」:BFL 的多图是 input_image / input_image_2..N
721
+ * (FLUX 3 例外,收 images 数组)、百炼 Qwen-Image 是 input.messages[0].content[]、
722
+ * 硅基流动是扁平的 prompt / negative_prompt / image、火山方舟是 prompt/size/image。
723
+ * - 模型型条目抄「这个模型家族自己的 API」:gpt-image / dall-e-3 没有 negative prompt;
724
+ * ideogram 的模型名在路径里、张数叫 num_images、4 的 JSON 体没有 negative_prompt。
725
+ *
726
+ * 表达不了的一律写 null,把那段留在协议的 execute()/async.build() 里(红线:不给模板
727
+ * 加第七种能力):
728
+ * - gemini 的参考图是 { inlineData: { mimeType, data } } 这种带额外键的对象;
729
+ * - fal 的单图用 image_url、多图用 image_urls,选哪个由端点决定;
730
+ * - replicate 的字段名由模型 Input schema 决定;
731
+ * - openrouter 的参考图是 input_references[] 里的 { type, image_url } 对象。
732
+ *
733
+ * 没有兜底条目(区别于 SIZE_RULES 的最后一条):认不出的模型返回 null,回落到预设。
734
+ */
735
+ export const FIELD_RULES = [
736
+ {
737
+ match: STABILITY_SD3_MODEL,
738
+ adapters: ['stability'],
739
+ fields: { model: { path: 'model' } }
740
+ },
741
+ /* ---- BFL:FLUX 3 与 FLUX.2 / kontext 的参考图字段不同,模型名进的是提交路径 ---- */
742
+ {
743
+ match: /flux-?3/i,
744
+ host: 'bfl\\.ai',
745
+ fields: {
746
+ prompt: { path: 'prompt' },
747
+ negative: { appendToPrompt: '\n\nAvoid: ' },
748
+ model: null,
749
+ n: null,
750
+ image: { path: 'images[]', as: 'dataUrl' }
751
+ }
752
+ },
753
+ {
754
+ match: /.*/,
755
+ host: 'bfl\\.ai',
756
+ fields: {
757
+ prompt: { path: 'prompt' },
758
+ negative: { appendToPrompt: '\n\nAvoid: ' },
759
+ model: null,
760
+ n: null,
761
+ image: { numbered: 'input_image', as: 'dataUrl' }
762
+ }
763
+ },
764
+
765
+ /* ---- OpenRouter:比例 + input_references 对象,六种能力表达不了参考图 ---- */
766
+ {
767
+ match: /.*/,
768
+ host: 'openrouter\\.ai',
769
+ fields: {
770
+ prompt: { path: 'prompt' },
771
+ negative: { appendToPrompt: '\n\nAvoid: ' },
772
+ model: { path: 'model' },
773
+ n: { path: 'n' },
774
+ image: null
775
+ }
776
+ },
777
+
778
+ /* ---- Gemini 原生:内容追加进 contents[0].parts[],模型名在 URL 的 :generateContent 前 ---- */
779
+ {
780
+ match: GEMINI_IMAGE,
781
+ adapters: ['google-gemini'],
782
+ fields: {
783
+ prompt: { path: 'contents[0].parts[]', wrap: 'text' },
784
+ negative: { appendToPrompt: '\n\nAvoid: ' },
785
+ model: null,
786
+ n: null,
787
+ image: null
788
+ }
789
+ },
790
+
791
+ /* ---- xAI Grok Imagine:负面词拼进提示词,没有参考图字段、没有质量参数 ---- */
792
+ {
793
+ match: /.*/,
794
+ host: 'api\\.x\\.ai',
795
+ fields: {
796
+ prompt: { path: 'prompt' },
797
+ negative: { appendToPrompt: '\n\nAvoid: ' },
798
+ model: { path: 'model' },
799
+ n: { path: 'n' },
800
+ image: null
801
+ }
802
+ },
803
+
804
+ /* ---- 智谱 BigModel:形状像 OpenAI,但不收 n / response_format,负面词拼进提示词 ---- */
805
+ {
806
+ match: /.*/,
807
+ host: 'bigmodel\\.cn',
808
+ fields: {
809
+ prompt: { path: 'prompt' },
810
+ negative: { appendToPrompt: '\n\nAvoid: ' },
811
+ model: { path: 'model' },
812
+ n: null,
813
+ image: null,
814
+ quality: { path: 'quality' }
815
+ }
816
+ },
817
+
818
+ /* ---- 硅基流动:扁平的 prompt / negative_prompt / image ---- */
819
+ {
820
+ match: /.*/,
821
+ host: 'api\\.siliconflow\\.cn',
822
+ fields: {
823
+ prompt: { path: 'prompt' },
824
+ negative: { path: 'negative_prompt' },
825
+ model: { path: 'model' },
826
+ n: null,
827
+ image: { path: 'image', as: 'dataUrl' }
828
+ }
829
+ },
830
+
831
+ /* ---- 阿里云百炼:同一个 qwen-image,原生多模态接口与万相异步接口的字段完全不同 ---- */
832
+ {
833
+ match: /qwen-image/i,
834
+ host: 'dashscope\\.aliyuncs\\.com',
835
+ fields: {
836
+ prompt: { path: 'input.messages[0].content[]', wrap: 'text' },
837
+ negative: { path: 'parameters.negative_prompt' },
838
+ model: { path: 'model' },
839
+ n: { path: 'parameters.n' },
840
+ image: { path: 'input.messages[0].content[]', wrap: 'image', as: 'dataUrl' }
841
+ }
842
+ },
843
+ {
844
+ match: /wanx|wan[0-9](?!\.6-t2i\b|\.7-image\b)/i,
845
+ host: 'dashscope\\.aliyuncs\\.com',
846
+ fields: {
847
+ prompt: { path: 'input.prompt' },
848
+ negative: { path: 'input.negative_prompt' },
849
+ model: { path: 'model' },
850
+ n: { path: 'parameters.n' },
851
+ image: null
852
+ }
853
+ },
854
+ {
855
+ match: WAN_26_T2I,
856
+ adapters: ['dashscope-wanx'],
857
+ fields: {
858
+ prompt: { path: 'input.messages[0].content[]', wrap: 'text' },
859
+ negative: { path: 'parameters.negative_prompt' },
860
+ model: { path: 'model' },
861
+ n: { path: 'parameters.n' },
862
+ image: null
863
+ }
864
+ },
865
+ {
866
+ match: WAN_27_IMAGE,
867
+ adapters: ['dashscope-wanx'],
868
+ fields: {
869
+ prompt: { path: 'input.messages[0].content[]', wrap: 'text' },
870
+ negative: { appendToPrompt: '\n\nAvoid: ' },
871
+ model: { path: 'model' },
872
+ n: { path: 'parameters.n' },
873
+ image: { path: 'input.messages[0].content[]', wrap: 'image', as: 'dataUrl' }
874
+ }
875
+ },
876
+
877
+ /* ---- 火山方舟:seedream 一族不收负面词,参考图是 data URL 的 image ---- */
878
+ {
879
+ match: /.*/,
880
+ host: 'volces\\.com',
881
+ fields: {
882
+ prompt: { path: 'prompt' },
883
+ negative: null,
884
+ model: { path: 'model' },
885
+ n: { path: 'n' },
886
+ image: { path: 'image', as: 'dataUrl' }
887
+ }
888
+ },
889
+
890
+ /* ---- Ideogram:模型名在路径里,只有旧模型收单独的负面词 ---- */
891
+ {
892
+ match: IDEOGRAM_EDIT,
893
+ adapters: ['ideogram'],
894
+ fields: {
895
+ prompt: { path: 'prompt' },
896
+ negative: { appendToPrompt: '\n\nAvoid: ' },
897
+ model: null,
898
+ n: { path: 'num_images' },
899
+ image: { multipart: 'images' },
900
+ quality: { path: 'quality' }
901
+ }
902
+ },
903
+ {
904
+ match: /ideogram-4(?![.\d]|-(?:\d|transparent))/i,
905
+ fields: {
906
+ prompt: { path: 'prompt' },
907
+ negative: null,
908
+ model: null,
909
+ n: { path: 'num_images' },
910
+ image: null
911
+ }
912
+ },
913
+ {
914
+ match: /ideogram/i,
915
+ fields: {
916
+ prompt: { path: 'prompt' },
917
+ negative: { path: 'negative_prompt' },
918
+ model: null,
919
+ n: { path: 'num_images' },
920
+ image: null
921
+ }
922
+ },
923
+
924
+ /* ---- OpenAI 自家的两个模型家族:官方端点没有 negative prompt 这个参数 ----
925
+ *
926
+ * 只有官方主机(api.openai.com / *.openai.azure.com)写 negative: null;不带 host 的
927
+ * 那条保留预设的 negative_prompt —— 中转站上的 gpt-image 一直都收负面词,别因为上游
928
+ * 对未知参数 400 就把所有网关都当成官方端点。
929
+ * 两条都不写 quality:收不收质量由预设(openai / azure)的 fields.quality 决定,
930
+ * 而 openai-chat / openai-responses 这类自己拼 body、没有预设的协议不该凭空多出档位。
931
+ */
932
+ {
933
+ match: GPT_IMAGE,
934
+ adapters: ['openai-images'],
935
+ host: 'api\\.openai\\.com|openai\\.azure\\.com',
936
+ fields: {
937
+ prompt: { path: 'prompt' },
938
+ negative: null,
939
+ model: { path: 'model' },
940
+ n: { path: 'n' },
941
+ image: { multipart: 'image[]' }
942
+ }
943
+ },
944
+ {
945
+ match: GPT_IMAGE,
946
+ adapters: ['openai-images'],
947
+ fields: {
948
+ prompt: { path: 'prompt' },
949
+ negative: { path: 'negative_prompt' },
950
+ model: { path: 'model' },
951
+ n: { path: 'n' },
952
+ image: { multipart: 'image[]' }
953
+ }
954
+ },
955
+ {
956
+ match: /dall-?e-?3/i,
957
+ host: 'api\\.openai\\.com|openai\\.azure\\.com',
958
+ fields: {
959
+ prompt: { path: 'prompt' },
960
+ negative: null,
961
+ model: { path: 'model' },
962
+ n: { path: 'n' },
963
+ image: { multipart: 'image[]' }
964
+ }
965
+ },
966
+ {
967
+ match: /dall-?e-?3/i,
968
+ fields: {
969
+ prompt: { path: 'prompt' },
970
+ negative: { path: 'negative_prompt' },
971
+ model: { path: 'model' },
972
+ n: { path: 'n' },
973
+ image: { multipart: 'image[]' }
974
+ }
975
+ }
976
+ ];
977
+
978
+ /* ---------------------------------------------------------- 请求常量规则 */
979
+
980
+ /**
981
+ * 请求常量:与「字段叫什么」无关,只描述这家网关要的固定值。
982
+ *
983
+ * 这几条原来长在协议对象上(`responseFormat` / `outputFormat` / `watermark`),
984
+ * 协议合并成 `openai-images` 之后按 id 区分不了,但值本身是真的(火山方舟的 `watermark`
985
+ * 默认是 true,不发这个键出来的图会带水印),所以按「模型 + 主机」留下来:
986
+ *
987
+ * - 火山方舟:关水印 + 要 URL(几十 MB 的 base64 走 JSON 太贵);
988
+ * - Together:只要 URL;
989
+ * - DALL·E 3:响应认 b64_json(官方两种都收,插件一直发这个,别改线上形态);
990
+ * - Azure:生成体一直带 output_format=png(原来挂在 azure-openai 协议的 outputFormat 上,
991
+ * 协议并进 openai-images 后没有 id 可挂;host 就是它,别让线上 body 少一个键)。
992
+ *
993
+ * 与 FIELD_RULES 一样**没有兜底条目**:认不出的模型不额外发常量。
994
+ */
995
+ export const CONSTANT_RULES = [
996
+ {
997
+ match: GLM_IMAGE,
998
+ host: BIGMODEL_HOST,
999
+ adapters: ['openai-images'],
1000
+ constants: { watermark_enabled: false }
1001
+ },
1002
+ {
1003
+ match: /.*/,
1004
+ host: 'volces\\.com',
1005
+ constants: { response_format: 'url', watermark: false }
1006
+ },
1007
+ {
1008
+ match: /.*/,
1009
+ host: 'api\\.together\\.xyz',
1010
+ constants: { response_format: 'url' }
1011
+ },
1012
+ {
1013
+ // xAI Grok Imagine 要 URL(原来挂在 xai-imagine 协议的 execute 里)。
1014
+ match: /.*/,
1015
+ host: 'api\\.x\\.ai',
1016
+ constants: { response_format: 'url' }
1017
+ },
1018
+ {
1019
+ match: /.*/,
1020
+ host: 'openai\\.azure\\.com|services\\.ai\\.azure\\.com',
1021
+ constants: { output_format: 'png' }
1022
+ },
1023
+ {
1024
+ match: /dall-?e-?3/i,
1025
+ constants: { response_format: 'b64_json' }
1026
+ }
1027
+ ];
1028
+
1029
+ /* ---------------------------------------------------------------- 探测 */
1030
+
1031
+ /** 按模型名 + 可选主机找尺寸规则;都没有返回 null(调用方据此不发尺寸字段)。 */
1032
+ export function detectSizeRule(model, baseUrl, adapterId) {
1033
+ return detect(SIZE_RULES, model, baseUrl, adapterId);
1034
+ }
1035
+
1036
+ /** 按模型名 + 可选主机找质量规则;都没有返回 null(调用方按 off 语义不发质量字段)。 */
1037
+ export function detectQualityRule(model, baseUrl, adapterId) {
1038
+ return detect(QUALITY_RULES, model, baseUrl, adapterId);
1039
+ }
1040
+
1041
+ /**
1042
+ * 按模型名 + 可选主机找字段模板规则;都没有返回 null(调用方回落到预设)。
1043
+ * 与尺寸/质量不同,这里没有兜底条目:认不出的模型就该由预设决定怎么发。
1044
+ */
1045
+ export function detectFieldRule(model, baseUrl, adapterId) {
1046
+ return detect(FIELD_RULES, model, baseUrl, adapterId);
1047
+ }
1048
+
1049
+ /**
1050
+ * 按模型名 + 可选主机找请求常量规则;都没有返回 null(调用方不额外发常量)。
1051
+ * 与尺寸/质量不同,这里没有兜底条目:常量是网关个性,认不出就别乱发。
1052
+ */
1053
+ export function detectConstantRule(model, baseUrl, adapterId) {
1054
+ return detect(CONSTANT_RULES, model, baseUrl, adapterId);
1055
+ }