dsh-mo-image 0.6.0 → 0.7.0

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.
@@ -1,7 +1,7 @@
1
1
  /**
2
- * 异步队列型协议:BFL / fal.ai / Replicate。
2
+ * 异步队列型协议:BFL / fal.ai / Replicate / 魔搭 ModelScope。
3
3
  *
4
- * 三个平台的共同点是「提交 → 轮询 → 拿一个会过期的 URL」,差异全部收敛到
4
+ * 这些平台的共同点是「提交 → 轮询 → 拿一个会过期的 URL」,差异全部收敛到
5
5
  * async 描述符:build / submitPath / pollUrl / pollHeaders / statusOf / resolve。
6
6
  * 拿到 URL 必须立刻下载,不能交给上层。
7
7
  */
@@ -14,6 +14,56 @@ function hostOf(provider) {
14
14
  return String((provider && provider.baseUrl) || '').replace(/^https?:\/\//i, '').split('/')[0].toLowerCase();
15
15
  }
16
16
 
17
+ /* ------------------------------------------------------- 结果地址的凭据范围 */
18
+
19
+ /**
20
+ * 结果地址不一定是「自己家」的接口:队列服务常常直接给一个对象存储/CDN 的
21
+ * 预签名地址。预签名本来就带授权,不需要我们的 Key;反过来,把 Key 发给
22
+ * 一个没见过的主机就是凭据泄漏。所以默认只对同源带凭据,跨源必须显式声明。
23
+ */
24
+ function originOf(url) {
25
+ try {
26
+ return new URL(String(url)).origin;
27
+ } catch (_error) {
28
+ return '';
29
+ }
30
+ }
31
+
32
+ /** 同源比较的是 origin(协议 + 主机 + 端口):http→https 或换端口都算换了目标。 */
33
+ function isSameOrigin(url, provider) {
34
+ const origin = originOf(url);
35
+ if (!origin) return false;
36
+ const base = originOf(baseUrlOf(provider));
37
+ return !!base && origin === base;
38
+ }
39
+
40
+ /**
41
+ * 描述符可以用 resultAuthOrigins 声明确实需要凭据的跨源结果域名;
42
+ * 元素可以是完整 origin(https://api.example.com),也可以是 hostname。
43
+ */
44
+ function isDeclaredResultOrigin(url, origins) {
45
+ const list = Array.isArray(origins) ? origins : [];
46
+ if (!list.length) return false;
47
+ let parsed;
48
+ try {
49
+ parsed = new URL(String(url));
50
+ } catch (_error) {
51
+ return false;
52
+ }
53
+ return list.some((entry) => {
54
+ const text = String(entry || '').trim();
55
+ if (!text) return false;
56
+ if (/^https?:\/\//i.test(text)) return text.replace(/\/+$/, '') === parsed.origin;
57
+ return text.toLowerCase() === parsed.hostname.toLowerCase();
58
+ });
59
+ }
60
+
61
+ /** 下载/解析结果地址时该带什么头:同源或已声明才带该适配器的鉴权头,否则裸请求。 */
62
+ function resultHeaders(provider, url, authHeader, origins) {
63
+ if (!isSameOrigin(url, provider) && !isDeclaredResultOrigin(url, origins)) return {};
64
+ return authHeaders(provider, { authHeader: authHeader });
65
+ }
66
+
17
67
  function promptWithNegative(input) {
18
68
  const prompt = String((input && input.prompt) || '');
19
69
  const negative = String((input && input.negativePrompt) || '').trim();
@@ -29,7 +79,7 @@ function sizeOf(input) {
29
79
  const fitted = input && input.fitted;
30
80
  if (!fitted || fitted.omit || fitted.size === 'none' || fitted.size === 'auto') return null;
31
81
  if (!fitted.width || !fitted.height) return null;
32
- return { width: fitted.width, height: fitted.height };
82
+ return { width: fitted.width, height: fitted.height, aspect: fitted.aspect || '', tier: fitted.tier || '' };
33
83
  }
34
84
 
35
85
  /* ------------------------------------------------------------------ BFL */
@@ -47,8 +97,8 @@ function bflBuild(input) {
47
97
 
48
98
  // FLUX 3 只认 aspect_ratio / resolution / images,未知字段直接 422。
49
99
  if (/^flux-3/i.test(model)) {
50
- body.aspect_ratio = nearestAspect(size.width, size.height);
51
- body.resolution = resolutionFor(size.width, size.height);
100
+ body.aspect_ratio = size.aspect || nearestAspect(size.width, size.height);
101
+ if (size.tier) body.resolution = String(size.tier);
52
102
  if (images.length) body.images = images.slice(0, 10).map(dataUrlOf);
53
103
  return body;
54
104
  }
@@ -99,11 +149,14 @@ function falBuild(input) {
99
149
  /* -------------------------------------------------------------- Replicate */
100
150
 
101
151
  const schemaCache = new Map();
152
+ /** 进行中的 schema 请求:同一模型的并发 build 只发一次,别让参考图和尺寸各查一遍。 */
153
+ const schemaInflight = new Map();
102
154
  const SCHEMA_TTL = 10 * 60 * 1000;
103
155
 
104
- /** 测试用:清掉模型 schema 缓存。 */
156
+ /** 测试用:清掉模型 schema 缓存与进行中的请求占位。 */
105
157
  export function resetAsyncSchemaCache() {
106
158
  schemaCache.clear();
159
+ schemaInflight.clear();
107
160
  }
108
161
 
109
162
  function replicateName(model) {
@@ -112,36 +165,65 @@ function replicateName(model) {
112
165
 
113
166
  const SCHEMA_CACHE_LIMIT = 100;
114
167
 
168
+ /**
169
+ * 凭据版本引用:换了 Key 之后能访问的模型可能不同(私有模型),所以凭据要参与缓存键;
170
+ * 但键会长期留在内存里,不能出现明文 Key。这里只留长度 + FNV-1a 哈希做版本引用。
171
+ *
172
+ * 这个函数在 adapters.js 里也有一份:本文件被 adapters.js import,反向 import 会成环,
173
+ * 而这段逻辑只有十来行,复制一份比制造循环依赖安全。
174
+ */
175
+ function credentialRef(provider) {
176
+ const key = String((provider && provider.key) || '');
177
+ if (!key) return 'anon';
178
+ let hash = 0x811c9dc5;
179
+ for (let i = 0; i < key.length; i++) {
180
+ hash ^= key.charCodeAt(i);
181
+ hash = Math.imul(hash, 0x01000193) >>> 0;
182
+ }
183
+ return key.length + ':' + hash.toString(16);
184
+ }
185
+
115
186
  /** 读模型 Input schema;失败就返回 null,且不缓存失败(瞬时 503 不该让后面 10 分钟都退化)。 */
116
187
  async function inputSchemaOf(provider, model, signal) {
117
188
  const name = replicateName(model);
118
189
  if (!name.includes('/')) return null;
119
- const key = baseUrlOf(provider) + '|' + name;
190
+ const key = baseUrlOf(provider) + '|' + name + '|' + credentialRef(provider);
120
191
  const cached = schemaCache.get(key);
121
192
  if (cached && Date.now() - cached.at < SCHEMA_TTL) return cached.value;
122
- try {
123
- const response = await request(baseUrlOf(provider) + '/models/' + name, {
124
- headers: headersFor(provider, false), signal: signal
125
- });
126
- if (!response.ok) throw new Error('schema ' + response.status);
127
- const payload = await readJsonResponse(response, 5 * 1024 * 1024);
128
- const schema = payload
129
- && payload.latest_version
130
- && payload.latest_version.openapi_schema
131
- && payload.latest_version.openapi_schema.components
132
- && payload.latest_version.openapi_schema.components.schemas
133
- && payload.latest_version.openapi_schema.components.schemas.Input;
134
- const properties = schema && schema.properties ? schema.properties : null;
135
- if (!properties) return null;
136
- if (schemaCache.size >= SCHEMA_CACHE_LIMIT) {
137
- const oldest = schemaCache.keys().next().value;
138
- if (oldest) schemaCache.delete(oldest);
193
+ const pending = schemaInflight.get(key);
194
+ if (pending) return pending;
195
+ const task = (async () => {
196
+ try {
197
+ const response = await request(baseUrlOf(provider) + '/models/' + name, {
198
+ headers: headersFor(provider, false), signal: signal
199
+ });
200
+ if (!response.ok) throw new Error('schema ' + response.status);
201
+ const payload = await readJsonResponse(response, 5 * 1024 * 1024);
202
+ const schema = payload
203
+ && payload.latest_version
204
+ && payload.latest_version.openapi_schema
205
+ && payload.latest_version.openapi_schema.components
206
+ && payload.latest_version.openapi_schema.components.schemas
207
+ && payload.latest_version.openapi_schema.components.schemas.Input;
208
+ const properties = schema && schema.properties ? schema.properties : null;
209
+ if (!properties) return null;
210
+ if (schemaCache.size >= SCHEMA_CACHE_LIMIT) {
211
+ const oldest = schemaCache.keys().next().value;
212
+ if (oldest) schemaCache.delete(oldest);
213
+ }
214
+ schemaCache.set(key, { at: Date.now(), value: properties });
215
+ return properties;
216
+ } catch (_error) {
217
+ return null;
139
218
  }
140
- schemaCache.set(key, { at: Date.now(), value: properties });
141
- return properties;
142
- } catch (_error) {
143
- return null;
144
- }
219
+ })();
220
+ // 失败同样经过 finally:占位必须清掉,下一次 build 才能重新请求(失败不缓存)。
221
+ let tracked;
222
+ tracked = task.finally(() => {
223
+ if (schemaInflight.get(key) === tracked) schemaInflight.delete(key);
224
+ });
225
+ schemaInflight.set(key, tracked);
226
+ return tracked;
145
227
  }
146
228
 
147
229
  const SCALAR_IMAGE_FIELDS = ['input_image', 'image', 'image_url'];
@@ -206,14 +288,83 @@ async function replicateBuild(input, provider, signal) {
206
288
  if (size) {
207
289
  const sizeFields = sizeFieldsOf(properties, size);
208
290
  if (sizeFields) Object.assign(payload, sizeFields);
209
- else notes.push('未识别模型的尺寸字段,已省略尺寸');
291
+ else notes.push('未识别模型的尺寸字段,已省略尺寸;要锁定尺寸请开启严格模式');
210
292
  }
211
293
 
212
294
  return notes.length ? { body: { input: payload }, note: notes.join(';') } : { body: { input: payload } };
213
295
  }
214
296
 
297
+ /* ------------------------------------------------------------ ModelScope */
298
+
299
+ const MODELSCOPE_SUCCESS = new Set(['SUCCEED', 'SUCCEEDED', 'SUCCESS']);
300
+ const MODELSCOPE_FAILURE = new Set(['FAILED', 'CANCELED', 'CANCELLED', 'ERROR']);
301
+
302
+ /** 魔搭的 OpenAI 兼容地址可能带 /v1,也可能只给站点根;统一到站点根再拼 /v1/...。 */
303
+ function modelscopeRoot(provider) {
304
+ return baseUrlOf(provider).replace(/\/v1$/i, '');
305
+ }
306
+
307
+ /**
308
+ * 魔搭的失败载荷可能是 message 字符串、errors:{message} 对象或 errors[] 数组,
309
+ * 逐层挖出第一句可读文本,别把 [object Object] 抛给用户。
310
+ */
311
+ function firstMessage(value, depth = 0) {
312
+ if (depth > 4 || value === null || value === undefined) return '';
313
+ if (typeof value === 'string') return value.trim();
314
+ if (typeof value !== 'object') return '';
315
+ if (Array.isArray(value)) {
316
+ for (const item of value) {
317
+ const text = firstMessage(item, depth + 1);
318
+ if (text) return text;
319
+ }
320
+ return '';
321
+ }
322
+ for (const key of ['message', 'msg', 'detail', 'error', 'errors', 'reason', 'logs']) {
323
+ if (value[key] === undefined) continue;
324
+ const text = firstMessage(value[key], depth + 1);
325
+ if (text) return text;
326
+ }
327
+ return '';
328
+ }
329
+
330
+ function modelscopeBuild(input) {
331
+ const body = {
332
+ model: String((input && input.model) || ''),
333
+ prompt: String((input && input.prompt) || '')
334
+ };
335
+ // 魔搭原生支持 negative_prompt:照字段发,不要像不支持的平台那样拼进 prompt。
336
+ const negative = String((input && input.negativePrompt) || '').trim();
337
+ if (negative) body.negative_prompt = negative;
338
+ const size = sizeOf(input);
339
+ if (size) body.size = size.width + 'x' + size.height;
340
+ const images = imagesOf(input);
341
+ if (images.length) {
342
+ // 图片字段是 image_url:一张发字符串、多张发数组;网关吃 data URI。
343
+ const urls = images.slice(0, 10).map(dataUrlOf);
344
+ body.image_url = urls.length === 1 ? urls[0] : urls;
345
+ }
346
+ return body;
347
+ }
348
+
349
+ function modelscopePollUrl(submission, provider) {
350
+ const taskId = String((submission && submission.task_id) || '');
351
+ if (!taskId) {
352
+ throw new Error('ModelScope 提交后没有返回 task_id:'
353
+ + JSON.stringify(submission || {}).slice(0, 200));
354
+ }
355
+ return modelscopeRoot(provider) + '/v1/tasks/' + encodeURIComponent(taskId);
356
+ }
357
+
215
358
  /* ----------------------------------------------------------------- 描述符 */
216
359
 
360
+ /**
361
+ * fal 的 response_url 正常就是 queue.fal.run 上的接口地址(同源时不需要这里声明),
362
+ * 结果图则落在 v3.fal.media 这类 CDN 上——那是预签名地址,不需要 Key。
363
+ * 这里只列 fal 自家确实要凭据的跨源域名:把 baseUrl 配成 fal.run 时,
364
+ * response_url 仍会落在 queue.fal.run,丢掉 Key 反而会让结果读不出来。
365
+ */
366
+ const FAL_RESULT_AUTH_ORIGINS = ['https://queue.fal.run'];
367
+
217
368
  export const ASYNC_ADAPTERS = [
218
369
  {
219
370
  id: 'bfl',
@@ -225,6 +376,22 @@ export const ASYNC_ADAPTERS = [
225
376
  transport: { generate: 'json', edit: 'json' },
226
377
  editFields: [],
227
378
  maxN: 1,
379
+ // FLUX.2 只吃 width/height;FLUX 3 换成「比例 + 小写档位」,两代 schema 不能共用。
380
+ size: { control: 'wh', style: 'width-height', minSide: 64, maxPixels: 4194304 },
381
+ sizeByModel: [
382
+ {
383
+ match: /flux-?3/i,
384
+ size: {
385
+ control: 'aspect', style: 'aspect', field: 'aspect_ratio',
386
+ 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'],
387
+ tiers: [
388
+ { value: '768sq', pixels: 589824 }, { value: '1k', pixels: 1048576 },
389
+ { value: '1.5k', pixels: 2359296 }, { value: '2k', pixels: 4194304 }, { value: '4k', pixels: 16777216 }
390
+ ],
391
+ minSide: 256, maxSide: 6256, maxPixels: 16822272
392
+ }
393
+ }
394
+ ],
228
395
  async listModels() {
229
396
  return [
230
397
  'flux-2-pro', 'flux-2-max', 'flux-2-flex', 'flux-2-klein-9b', 'flux-2-klein-4b',
@@ -261,6 +428,8 @@ export const ASYNC_ADAPTERS = [
261
428
  match: (provider) => /(^|\.)(queue\.)?fal(run)?\.(run|com)$/i.test(hostOf(provider)),
262
429
  authHeader: 'fal-key',
263
430
  local: false,
431
+ // 跨源结果地址的白名单;resolve() 与下载侧都按同一个声明判断能不能带 Key。
432
+ resultAuthOrigins: FAL_RESULT_AUTH_ORIGINS,
264
433
  endpoints: { generate: '/', edit: '/' },
265
434
  transport: { generate: 'json', edit: 'json' },
266
435
  editFields: [],
@@ -294,7 +463,9 @@ export const ASYNC_ADAPTERS = [
294
463
  resolve: async (payload, provider, signal, submission) => {
295
464
  const url = (submission && submission.response_url) || (payload && payload.response_url);
296
465
  if (!url) throw new Error('fal 任务完成了但没有 response_url');
297
- const response = await request(url, { headers: authHeaders(provider, { authHeader: 'fal-key' }), signal: signal });
466
+ // response_url 可能是同源的队列接口,也可能是第三方 CDN;后者不该收到 Key。
467
+ const headers = resultHeaders(provider, url, 'fal-key', FAL_RESULT_AUTH_ORIGINS);
468
+ const response = await request(url, { headers: headers, signal: signal });
298
469
  const result = await readJsonResponse(response, 64 * 1024 * 1024);
299
470
  const first = result && Array.isArray(result.images) ? result.images[0] : null;
300
471
  if (!first || !first.url) throw new Error('fal 没有返回图片');
@@ -347,5 +518,61 @@ export const ASYNC_ADAPTERS = [
347
518
  intervalMs: 1000,
348
519
  timeoutMs: 300000
349
520
  }
521
+ },
522
+ {
523
+ id: 'modelscope',
524
+ label: '魔搭 ModelScope',
525
+ match: (provider) => /(^|\.)api-inference\.modelscope\.(cn|ai)$/i.test(hostOf(provider)),
526
+ authHeader: 'bearer',
527
+ local: false,
528
+ endpoints: { generate: '/v1/images/generations', edit: '/v1/images/generations' },
529
+ transport: { generate: 'json', edit: 'json' },
530
+ // 图片生成是任务制:不带这个头拿不到 task_id。
531
+ headers: { 'X-ModelScope-Async-Mode': 'true' },
532
+ editFields: [],
533
+ maxN: 1,
534
+ // 网关按每边 [64, 2048] 校验;再对齐到 16 的倍数,减少模型侧的取整与拒绝。
535
+ // 但不同模型族上限差很多(Qwen-Image 只到 1664),按模型覆盖。
536
+ size: {
537
+ style: 'string', field: 'size', multiple: 16, minSide: 64, maxSide: 2048,
538
+ default: '1024x1024', onUnsupported: 'nearest'
539
+ },
540
+ sizeByModel: [
541
+ { match: /flux/i, size: { style: 'string', field: 'size', multiple: 16, minSide: 64, maxSide: 1024, default: '1024x1024' } },
542
+ { match: /qwen-image/i, size: { style: 'string', field: 'size', multiple: 16, minSide: 64, maxSide: 1664, default: '1024x1024' } },
543
+ { match: /z-image/i, size: { style: 'string', field: 'size', multiple: 16, minSide: 512, maxSide: 2048, default: '1024x1024' } }
544
+ ],
545
+ async: {
546
+ edit: true,
547
+ build: modelscopeBuild,
548
+ submitPath: (input, provider) => modelscopeRoot(provider) + '/v1/images/generations',
549
+ pollUrl: modelscopePollUrl,
550
+ // 轮询要声明任务类型,图片生成是 image_generation(视频是另一套)。
551
+ pollHeaders: (provider) => Object.assign(
552
+ { 'X-ModelScope-Task-Type': 'image_generation' },
553
+ authHeaders(provider, { authHeader: 'bearer' })
554
+ ),
555
+ statusOf: (payload) => {
556
+ const status = String((payload && payload.task_status) || '').toUpperCase();
557
+ if (MODELSCOPE_SUCCESS.has(status)) return { state: 'success', status: status };
558
+ if (MODELSCOPE_FAILURE.has(status)) {
559
+ return { state: 'failure', status: status, message: firstMessage(payload) || status };
560
+ }
561
+ return { state: 'pending', status: status };
562
+ },
563
+ // 提交响应可能提前回 SUCCEED 但还没有图,所以结果只认轮询到的 output_images。
564
+ resolve: async (payload) => {
565
+ const images = Array.isArray(payload && payload.output_images) ? payload.output_images : [];
566
+ for (const item of images) {
567
+ const url = typeof item === 'string' ? item : (item && (item.url || item.image_url));
568
+ if (url) return { url: String(url) };
569
+ }
570
+ const first = payload && Array.isArray(payload.data) ? payload.data[0] : null;
571
+ if (first && first.url) return { url: String(first.url) };
572
+ throw new Error('ModelScope 任务完成了但没有返回图片');
573
+ },
574
+ intervalMs: 2000,
575
+ timeoutMs: 300000
576
+ }
350
577
  }
351
578
  ];
@@ -34,6 +34,11 @@ export const CN_ADAPTERS = [
34
34
  transport: { generate: 'json', edit: 'json' },
35
35
  maxN: 6,
36
36
  editFields: [],
37
+ // 百炼原生:size 用星号分隔,512²–2048²,比例 1:8–8:1。
38
+ size: {
39
+ control: 'wh', style: 'string', field: 'size', separator: '*', allowCustom: true,
40
+ minPixels: 262144, maxPixels: 4194304, hint: 'modelDecides'
41
+ },
37
42
  async execute(kind, provider, input, signal) {
38
43
  if (kind === 'edit') throw new Error('百炼 Qwen-Image 暂未支持参考图编辑;请换用支持编辑的模型。');
39
44
  const fitted = input.fitted && !input.fitted.omit ? input.fitted : { width: 1024, height: 1024 };
@@ -69,6 +74,14 @@ export const CN_ADAPTERS = [
69
74
  transport: { generate: 'json', edit: 'json' },
70
75
  maxN: 1,
71
76
  editFields: [],
77
+ // glm-image 与 cogview 的限制不一样:前者 1024–2048 且 32 的倍数,后者 512–2048 且 16 的倍数。
78
+ size: { control: 'wh', style: 'string', field: 'size', allowCustom: true, multiple: 32, minSide: 1024, maxSide: 2048, maxPixels: 4194304 },
79
+ sizeByModel: [
80
+ {
81
+ match: /cogview/i,
82
+ size: { control: 'wh', style: 'string', field: 'size', allowCustom: true, multiple: 16, minSide: 512, maxSide: 2048, maxPixels: 2097152 }
83
+ }
84
+ ],
72
85
  async execute(kind, provider, input, signal) {
73
86
  if (kind === 'edit') throw new Error('智谱 BigModel 暂未支持参考图编辑;请换用支持编辑的模型。');
74
87
  const body = { model: input.model, prompt: promptOf(input) };
@@ -8,7 +8,8 @@
8
8
  */
9
9
  import { request } from '../net.js';
10
10
  import {
11
- baseUrlOf, headersFor, readJsonResponse, dataUrlOf, base64ToImage, nearestAspect, decodeImagePayload, fetchImageUrl
11
+ baseUrlOf, headersFor, readJsonResponse, dataUrlOf, base64ToImage, nearestAspect,
12
+ decodeImagePayload, fetchImageUrl
12
13
  } from '../adapter-kit.js';
13
14
 
14
15
  function hostOf(provider) {
@@ -143,6 +144,20 @@ export const OPENAI_ADAPTERS = [
143
144
  local: false,
144
145
  endpoints: { generate: '/images', edit: '/images' },
145
146
  transport: { generate: 'json', edit: 'json' },
147
+ // 各家底层模型能力不同:gemini 系有 resolution,gpt-image / flux.2 只有比例。
148
+ size: { control: 'aspect', style: 'aspect', field: 'aspect_ratio', default: '1024x1024', onUnsupported: 'nearest' },
149
+ sizeByModel: [
150
+ {
151
+ match: /gemini/i,
152
+ size: {
153
+ control: 'aspect', style: 'aspect', field: 'aspect_ratio',
154
+ tiers: [
155
+ { value: '512', pixels: 262144 }, { value: '1K', pixels: 1048576 },
156
+ { value: '2K', pixels: 4194304 }, { value: '4K', pixels: 16777216 }
157
+ ]
158
+ }
159
+ }
160
+ ],
146
161
  maxN: 10,
147
162
  editFields: [],
148
163
  async listModels(provider, signal) {
@@ -163,7 +178,9 @@ export const OPENAI_ADAPTERS = [
163
178
  output_format: 'png'
164
179
  };
165
180
  if (input.fitted && !input.fitted.omit && input.fitted.width && input.fitted.height) {
166
- body.aspect_ratio = nearestAspect(input.fitted.width, input.fitted.height);
181
+ body.aspect_ratio = input.fitted.aspect || nearestAspect(input.fitted.width, input.fitted.height);
182
+ // 只有认 resolution 的底层模型才发档位(fitSize 已经填好 tier);发错了 provider 会 400。
183
+ if (input.fitted.tier) body.resolution = String(input.fitted.tier);
167
184
  }
168
185
  const quality = String(input.quality || '').trim().toLowerCase();
169
186
  if (quality && quality !== 'off' && quality !== 'auto') body.quality = quality;
@@ -205,6 +222,8 @@ export const OPENAI_ADAPTERS = [
205
222
  local: false,
206
223
  endpoints: { generate: '/chat/completions', edit: '/chat/completions' },
207
224
  transport: { generate: 'json', edit: 'json' },
225
+ // 这个协议没有尺寸字段:尺寸只能写进提示词(stitch),面板仍给宽高输入框。
226
+ size: { control: 'prompt', stitch: true, wire: [], style: 'string', field: 'size', default: '1024x1024' },
208
227
  maxN: 1,
209
228
  editFields: [],
210
229
  async execute(kind, provider, input, signal) {