dsh-image-gen 0.8.0 → 0.8.6

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.
package/lib/index.js CHANGED
@@ -5596,6 +5596,8 @@ const INSPIRATION_ROUTE = "/plugins/dsh-image-gen/inspiration";
5596
5596
  const SAVE_WORKSPACE_ROUTE = "/plugins/dsh-image-gen/save-workspace";
5597
5597
  /** Browser route the settings card probes provider connectivity through. */
5598
5598
  const TEST_CONNECTION_ROUTE = "/plugins/dsh-image-gen/test";
5599
+ /** Non-secret settings capability probe, available even when the host cannot serve a form. */
5600
+ const SETTINGS_HEALTH_ROUTE = "/plugins/dsh-image-gen/settings-health";
5599
5601
  /** Browser route the workbench infinite canvas pushes live state through. */
5600
5602
  const CANVAS_STATE_ROUTE = "/plugins/dsh-image-gen/canvas-state";
5601
5603
  /** Upload a selected canvas original to the host attachment store. */
@@ -5809,7 +5811,7 @@ function mergeComfyUIPrompt(preset, user) {
5809
5811
  const DEFAULT_SUBSCRIPTION_MODELS = {
5810
5812
  "chatgpt-sub": "gpt-image-2.5-flare",
5811
5813
  "grok-sub": "grok-imagine-image-2.0",
5812
- "google-sub": "gemini-3-pro-image"
5814
+ "google-sub": "gemini-3.1-flash-image"
5813
5815
  };
5814
5816
  DEFAULT_SUBSCRIPTION_MODELS["chatgpt-sub"], DEFAULT_SUBSCRIPTION_MODELS["grok-sub"], DEFAULT_SUBSCRIPTION_MODELS["google-sub"];
5815
5817
  //#endregion
@@ -5817,21 +5819,6 @@ DEFAULT_SUBSCRIPTION_MODELS["chatgpt-sub"], DEFAULT_SUBSCRIPTION_MODELS["grok-su
5817
5819
  /** User-facing configuration for supported image providers. */
5818
5820
  /** Default workspace subfolder that receives generated image files. */
5819
5821
  const DEFAULT_WORKSPACE_FOLDER = "dsh-image-gen";
5820
- /** Google tool-level controls. */
5821
- const ASPECT_RATIOS$1 = [
5822
- "1:1",
5823
- "3:2",
5824
- "2:3",
5825
- "4:3",
5826
- "3:4",
5827
- "16:9",
5828
- "9:16"
5829
- ];
5830
- const IMAGE_SIZES = [
5831
- "1K",
5832
- "2K",
5833
- "4K"
5834
- ];
5835
5822
  /**
5836
5823
  * Mark a schema field live for DSH 0.1.7+: the host serves a plugin's settings
5837
5824
  * form only for `.volatile()` fields and hands `apply` a `Volatile` box per
@@ -7995,15 +7982,39 @@ async function generateOpenAICompatibleImage(input) {
7995
7982
  body: JSON.stringify({
7996
7983
  model: input.model,
7997
7984
  prompt: input.prompt,
7998
- size: input.size,
7985
+ ...input.size === void 0 ? {} : { size: input.size },
7986
+ ...input.quality === void 0 ? {} : { quality: input.quality },
7999
7987
  ...input.provider === "seedream" ? {
8000
7988
  response_format: "url",
8001
7989
  ...arkOutputBody(input.arkOptions, { background: false })
8002
- } : {}
7990
+ } : {},
7991
+ ...input.extraBody ?? {}
8003
7992
  })
8004
7993
  }), input.provider, input);
8005
7994
  }
8006
7995
  async function editOpenAICompatibleImage(input) {
7996
+ if (input.editFormat === "xaiJson") {
7997
+ const references = input.sourceImages.map((image) => ({
7998
+ type: "image_url",
7999
+ url: toDataUrl$2(image)
8000
+ }));
8001
+ return parseImageResponse(await fetch(imageEndpoint$1(input.baseURL, "edits"), {
8002
+ method: "POST",
8003
+ redirect: "error",
8004
+ signal: input.signal,
8005
+ headers: {
8006
+ authorization: `Bearer ${input.apiKey}`,
8007
+ "content-type": "application/json"
8008
+ },
8009
+ body: JSON.stringify({
8010
+ model: input.model,
8011
+ prompt: input.prompt,
8012
+ ...references.length === 1 ? { image: references[0] } : { images: references },
8013
+ ...input.quality === void 0 ? {} : { quality: input.quality },
8014
+ ...input.extraBody ?? {}
8015
+ })
8016
+ }), "xai", input);
8017
+ }
8007
8018
  if (input.editFormat === "jsonImageUrlArray") {
8008
8019
  const body = {
8009
8020
  model: input.model,
@@ -8012,7 +8023,9 @@ async function editOpenAICompatibleImage(input) {
8012
8023
  n: 1,
8013
8024
  size: "auto",
8014
8025
  response_format: "url",
8015
- ...input.editExtra ?? {}
8026
+ ...input.quality === void 0 ? {} : { quality: input.quality },
8027
+ ...input.editExtra ?? {},
8028
+ ...input.extraBody ?? {}
8016
8029
  };
8017
8030
  return parseImageResponse(await fetch(imageEndpoint$1(input.baseURL, "edits"), {
8018
8031
  method: "POST",
@@ -8030,6 +8043,8 @@ async function editOpenAICompatibleImage(input) {
8030
8043
  form.append("model", input.model);
8031
8044
  form.append("prompt", input.prompt);
8032
8045
  if (input.size !== void 0 && input.size.length > 0) form.append("size", input.size);
8046
+ if (input.quality !== void 0) form.append("quality", input.quality);
8047
+ for (const [key, value] of Object.entries(input.extraBody ?? {})) form.append(key, String(value));
8033
8048
  form.append("response_format", "b64_json");
8034
8049
  form.append("reference_images", JSON.stringify(input.sourceImages.map((sourceImage) => Buffer.from(sourceImage.data).toString("base64"))));
8035
8050
  return parseImageResponse(await fetch(imageEndpoint$1(input.baseURL, "edits"), {
@@ -8051,6 +8066,8 @@ async function editOpenAICompatibleImage(input) {
8051
8066
  form.append("prompt", input.prompt);
8052
8067
  form.append("model", input.model);
8053
8068
  if (input.size !== void 0 && input.size.length > 0) form.append("size", input.size);
8069
+ if (input.quality !== void 0) form.append("quality", input.quality);
8070
+ for (const [key, value] of Object.entries(input.extraBody ?? {})) form.append(key, String(value));
8054
8071
  return parseImageResponse(await fetch(imageEndpoint$1(input.baseURL, "edits"), {
8055
8072
  method: "POST",
8056
8073
  redirect: "error",
@@ -8406,8 +8423,8 @@ async function formTokenRequest(url, params, fetchImpl) {
8406
8423
  * lib/loopback.js — same protocol (first matching request wins, server shuts
8407
8424
  * down, 10-minute cap), restated in TypeScript with this bundle's style.
8408
8425
  */
8409
- const OK_HTML = "<!doctype html><meta charset=\"utf-8\"><title>dsh-image-gen</title><p>登录成功,可以关闭此页返回设置。</p>";
8410
- const ERR_HTML = "<!doctype html><meta charset=\"utf-8\"><title>dsh-image-gen</title><p>登录失败,请返回设置重试。</p>";
8426
+ const OK_HTML = "<!doctype html><meta charset=\"utf-8\"><title>dsh-image-gen</title><p lang=\"zh-CN\">登录成功,可以关闭此页返回设置。</p><p lang=\"en\">Sign-in successful. You can close this page and return to settings.</p>";
8427
+ const ERR_HTML = "<!doctype html><meta charset=\"utf-8\"><title>dsh-image-gen</title><p lang=\"zh-CN\">登录失败,请返回设置重试。</p><p lang=\"en\">Sign-in failed. Return to settings and try again.</p><p lang=\"zh-CN\">需要代理时,请在重新登录前开启代理软件的 TUN(虚拟网卡)模式。普通系统代理可能无法覆盖 DSH 后端请求,导致网页授权后登录失败。</p><p lang=\"en\">If you need a proxy, enable TUN (virtual network adapter) mode before trying again. A system proxy alone may not cover DSH backend requests, causing sign-in to fail after browser authorization.</p>";
8411
8428
  /**
8412
8429
  * Loopback addresses accepted by the request handler. On dual-stack systems
8413
8430
  * Node reports IPv4-mapped IPv6 addresses as `::ffff:127.0.0.1`, so we must
@@ -8703,14 +8720,14 @@ async function grokRefresh(blob) {
8703
8720
  //#endregion
8704
8721
  //#region lib/types/subscription/vendors/antigravity.js
8705
8722
  /**
8706
- * Google Antigravity (Nano Banana Pro) subscription image vendor.
8723
+ * Google Antigravity (Nano Banana 2) subscription image vendor.
8707
8724
  *
8708
8725
  * Protocol adapted from opencode-antigravity-auth-remix (MIT,
8709
8726
  * (c) 2026 Darkstarrd-dev, based on NoeFabris/opencode-antigravity-auth):
8710
8727
  * Google OAuth with the Antigravity CLI's public client credentials, managed
8711
8728
  * project discovery via loadCodeAssist, and image generation through the
8712
- * v1internal:streamGenerateContent endpoint with the gemini-3-pro-image
8713
- * model. Reference: dist/src/constants.js, dist/src/plugin/image.js,
8729
+ * v1internal:streamGenerateContent endpoint. Reference:
8730
+ * dist/src/constants.js, dist/src/plugin/image.js,
8714
8731
  * dist/src/plugin/project.js.
8715
8732
  *
8716
8733
  * The dsh-subscriptions antigravity vendor left the OAuth client empty
@@ -8746,8 +8763,8 @@ const LOAD_ENDPOINTS = [
8746
8763
  "https://daily-cloudcode-pa.sandbox.googleapis.com",
8747
8764
  "https://autopush-cloudcode-pa.sandbox.googleapis.com"
8748
8765
  ];
8749
- /** The image model served through this channel: Nano Banana Pro. */
8750
- const ANTIGRAVITY_IMAGE_MODEL = "gemini-3-pro-image";
8766
+ /** The image model served through this channel: Nano Banana 2. */
8767
+ const ANTIGRAVITY_IMAGE_MODEL = DEFAULT_SUBSCRIPTION_MODELS["google-sub"];
8751
8768
  /**
8752
8769
  * Antigravity client version carried in the browser User-Agent. Google's
8753
8770
  * backend routes by this: a non-Antigravity or outdated UA lands in the
@@ -8790,13 +8807,17 @@ async function fetchVersionText(url, maxChars) {
8790
8807
  const DEFAULT_PROJECT_ID = "rising-fact-p41fc";
8791
8808
  /** Generation timeout mirroring the reference implementation. */
8792
8809
  const IMAGE_TIMEOUT_MS = 12e4;
8793
- /** Aspect ratios the generationConfig.imageConfig accepts. */
8810
+ /** Aspect ratios the generationConfig.imageConfig accepts (gemini-3.1-flash-image). */
8794
8811
  const ASPECT_RATIOS = [
8795
8812
  "1:1",
8796
- "16:9",
8797
- "9:16",
8798
- "4:3",
8813
+ "2:3",
8814
+ "3:2",
8799
8815
  "3:4",
8816
+ "4:3",
8817
+ "4:5",
8818
+ "5:4",
8819
+ "9:16",
8820
+ "16:9",
8800
8821
  "21:9"
8801
8822
  ];
8802
8823
  /** Safety settings the image endpoint requires to not block benign prompts. */
@@ -8976,7 +8997,8 @@ function platformOf() {
8976
8997
  * before the text part, mirroring the reference implementation.
8977
8998
  */
8978
8999
  function antigravityImageBody(options) {
8979
- const imageConfig = { aspectRatio: options.aspectRatio !== void 0 && ASPECT_RATIOS.includes(options.aspectRatio) ? options.aspectRatio : "1:1" };
9000
+ const ratio = options.aspectRatio !== void 0 && ASPECT_RATIOS.includes(options.aspectRatio) ? options.aspectRatio : void 0;
9001
+ const imageConfig = ratio === void 0 ? {} : { aspectRatio: ratio };
8980
9002
  if (options.hd === true) imageConfig.imageSize = "4K";
8981
9003
  const parts = [];
8982
9004
  for (const image of options.referenceImages ?? []) parts.push({ inlineData: {
@@ -9098,6 +9120,54 @@ function parseSseError(text) {
9098
9120
  }
9099
9121
  }
9100
9122
  //#endregion
9123
+ //#region lib/types/xai-params.js
9124
+ /** xAI's image routes use aspect_ratio/resolution rather than OpenAI's size. */
9125
+ const RATIOS = /* @__PURE__ */ new Set([
9126
+ "auto",
9127
+ "1:1",
9128
+ "16:9",
9129
+ "9:16",
9130
+ "4:3",
9131
+ "3:4",
9132
+ "3:2",
9133
+ "2:3",
9134
+ "2:1",
9135
+ "1:2",
9136
+ "19.5:9",
9137
+ "9:19.5",
9138
+ "20:9",
9139
+ "9:20",
9140
+ "21:9",
9141
+ "5:2"
9142
+ ]);
9143
+ function xaiToolParameters(options) {
9144
+ let ratio = options.aspectRatio;
9145
+ if (options.size !== void 0) {
9146
+ const match = /^(\d+)x(\d+)$/.exec(options.size);
9147
+ if (match === null) throw new Error("xAI size 请使用 WIDTHxHEIGHT;也可直接传 aspect_ratio");
9148
+ const width = Number(match[1]);
9149
+ const height = Number(match[2]);
9150
+ if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width <= 0 || height <= 0) throw new Error("xAI size 必须是正整数宽高");
9151
+ let divisor = width;
9152
+ let remainder = height;
9153
+ while (remainder !== 0) {
9154
+ const next = divisor % remainder;
9155
+ divisor = remainder;
9156
+ remainder = next;
9157
+ }
9158
+ const fromSize = `${String(width / divisor)}:${String(height / divisor)}`;
9159
+ if (ratio !== void 0 && ratio !== fromSize) throw new Error("xAI size 与 aspect_ratio 不一致");
9160
+ ratio = fromSize;
9161
+ }
9162
+ if (ratio !== void 0 && !RATIOS.has(ratio)) throw new Error(`xAI 不支持比例 ${ratio}`);
9163
+ const resolution = options.imageSize?.toLowerCase();
9164
+ if (resolution !== void 0 && resolution !== "1k" && resolution !== "2k") throw new Error(`xAI 不支持清晰度 ${options.imageSize}`);
9165
+ return {
9166
+ ...ratio === void 0 || ratio === "auto" ? {} : { aspect_ratio: ratio },
9167
+ ...resolution === void 0 ? {} : { resolution }
9168
+ };
9169
+ }
9170
+ //#endregion
9101
9171
  //#region lib/types/subscription/manager.js
9102
9172
  /**
9103
9173
  * Subscription account manager: login flows, blob storage through the DSH
@@ -9106,7 +9176,7 @@ function parseSseError(text) {
9106
9176
  *
9107
9177
  * The account store pattern follows @goodandready/dsh-subscriptions (MIT,
9108
9178
  * (c) 2026 GooDAnDReaDY) lib/accounts.js, trimmed to one account per vendor
9109
- * (no rotation, no cooldowns) because this bundle has exactly two vendors
9179
+ * (no rotation, no cooldowns) because this bundle has one account per vendor
9110
9180
  * and no chat adapter to protect.
9111
9181
  *
9112
9182
  * Isolation invariants (project rules):
@@ -9192,7 +9262,7 @@ var SubscriptionManager = class {
9192
9262
  this.pending.delete(state);
9193
9263
  const blob = vendor === "codex" ? await codexExchangeCode(codexConfig(), row.pkce, code) : vendor === "antigravity" ? await antigravityExchangeCode(antigravityConfig(), row.pkce, code) : await grokExchangeCode(grokConfig(), row.pkce, code);
9194
9264
  await this.saveBlob(vendor, blob);
9195
- return `<!doctype html><meta charset="utf-8"><title>dsh-image-gen</title><p>${providerNameOf(vendor)} 登录成功(${escapeHtml(blob.email)}),可以关闭此页返回设置。</p>`;
9265
+ return `<!doctype html><meta charset="utf-8"><title>dsh-image-gen</title><p lang="zh-CN">${providerNameOf(vendor)} 登录成功(${escapeHtml(blob.email)}),可以关闭此页返回设置。</p><p lang="en">${providerNameOf(vendor)} sign-in successful (${escapeHtml(blob.email)}). You can close this page and return to settings.</p>`;
9196
9266
  }
9197
9267
  /** Sign out: clear the blob and the caches. No other setting changes. */
9198
9268
  async logout(vendor) {
@@ -9259,7 +9329,7 @@ var SubscriptionManager = class {
9259
9329
  url = references.length > 0 ? CODEX_IMAGE_EDIT_URL : CODEX_IMAGE_URL;
9260
9330
  headers = codexIdentityHeaders(session);
9261
9331
  body = {
9262
- prompt: text,
9332
+ prompt: codexPromptWithSize(text, options.size),
9263
9333
  model: CODEX_IMAGE_MODEL,
9264
9334
  ...references.length > 0 ? { images: references.map((image) => ({ image_url: toDataUrl(image) })) } : {},
9265
9335
  ...options.size !== void 0 && options.size.length > 0 ? { size: options.size } : {},
@@ -9268,22 +9338,23 @@ var SubscriptionManager = class {
9268
9338
  } else {
9269
9339
  url = references.length > 0 ? GROK_IMAGE_EDIT_URL : GROK_IMAGE_URL;
9270
9340
  headers = grokIdentityHeaders(session);
9271
- const aspect = {
9272
- "1024x1024": "1:1",
9273
- "1024x1536": "2:3",
9274
- "1536x1024": "3:2",
9275
- auto: "auto"
9276
- };
9341
+ const xaiParams = xaiToolParameters({
9342
+ ...options.size === void 0 ? {} : options.size === "auto" || options.size.includes(":") ? { aspectRatio: options.size } : { size: options.size },
9343
+ ...options.quality === "1k" || options.quality === "2k" ? { imageSize: options.quality } : {}
9344
+ });
9277
9345
  const level = options.quality === "low" ? "low" : options.quality === "medium" || options.quality === "high" ? "medium" : void 0;
9278
9346
  body = {
9279
9347
  prompt: text,
9280
9348
  model: GROK_IMAGE_MODEL,
9281
9349
  response_format: "b64_json",
9282
- ...references.length > 0 ? { images: references.map((image) => ({
9350
+ ...references.length === 1 ? { image: {
9283
9351
  type: "image_url",
9284
- image_url: toDataUrl(image)
9352
+ url: toDataUrl(references[0])
9353
+ } } : references.length > 1 ? { images: references.map((image) => ({
9354
+ type: "image_url",
9355
+ url: toDataUrl(image)
9285
9356
  })) } : {},
9286
- ...options.size !== void 0 && aspect[options.size] !== void 0 ? { aspect_ratio: aspect[options.size] } : {},
9357
+ ...xaiParams,
9287
9358
  ...level !== void 0 ? { quality: level } : {}
9288
9359
  };
9289
9360
  }
@@ -9314,6 +9385,26 @@ var SubscriptionManager = class {
9314
9385
  return projectId;
9315
9386
  }
9316
9387
  };
9388
+ /** The private Codex backend can ignore size while following a canvas ratio in
9389
+ * the prompt (live checks: 16:9 -> 1672x941, 9:16 -> 941x1672). Keep size too;
9390
+ * this is best-effort composition guidance, not an exact-pixel guarantee. */
9391
+ function codexPromptWithSize(prompt, size) {
9392
+ const dimensions = /^(\d+)x(\d+)$/.exec(size ?? "");
9393
+ if (dimensions === null) return prompt;
9394
+ const width = Number(dimensions[1]);
9395
+ const height = Number(dimensions[2]);
9396
+ if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width <= 0 || height <= 0) return prompt;
9397
+ let divisor = width;
9398
+ let remainder = height;
9399
+ while (remainder !== 0) {
9400
+ const next = divisor % remainder;
9401
+ divisor = remainder;
9402
+ remainder = next;
9403
+ }
9404
+ const ratio = `${String(width / divisor)}:${String(height / divisor)}`;
9405
+ const orientation = width > height ? "横向宽屏" : width < height ? "竖向" : "正方形";
9406
+ return `${prompt}\n\n输出图片的画布宽高比必须为${ratio},${orientation}构图,完整画面铺满${orientation}画布。`;
9407
+ }
9317
9408
  /** Map an OpenAI-style size onto the aspect ratio Antigravity accepts. */
9318
9409
  function antigravityAspectRatioOf(size) {
9319
9410
  const table = {
@@ -9321,10 +9412,10 @@ function antigravityAspectRatioOf(size) {
9321
9412
  "1024x1536": "2:3",
9322
9413
  "1536x1024": "3:2",
9323
9414
  "768x1398": "9:16",
9324
- "1398x768": "16:9",
9325
- auto: "1:1"
9415
+ "1398x768": "16:9"
9326
9416
  };
9327
9417
  if (size === void 0) return void 0;
9418
+ if (size === "auto") return void 0;
9328
9419
  const mapped = table[size];
9329
9420
  if (mapped !== void 0) return mapped;
9330
9421
  return /^\d+:\d+$/.test(size) ? size : "1:1";
@@ -9333,11 +9424,12 @@ function antigravityAspectRatioOf(size) {
9333
9424
  function toDataUrl(image) {
9334
9425
  return `data:${image.mediaType};base64,${Buffer.from(image.data).toString("base64")}`;
9335
9426
  }
9336
- /** Response parsing: both vendors reply in the same `{data:[{b64_json}]}` shape. */
9427
+ /** Response parsing: Codex and Grok reply in the same `{data:[{b64_json}]}` shape. */
9337
9428
  function parseImages(payload) {
9338
9429
  const body = typeof payload === "object" && payload !== null ? payload : {};
9339
9430
  const rows = Array.isArray(body.data) ? body.data : [];
9340
9431
  const images = [];
9432
+ const reportedQuality = typeof body.quality === "string" && body.quality.length > 0 ? body.quality : void 0;
9341
9433
  for (const row of rows) {
9342
9434
  if (typeof row !== "object" || row === null) continue;
9343
9435
  const b64 = row.b64_json;
@@ -9345,7 +9437,8 @@ function parseImages(payload) {
9345
9437
  const revised = row.revised_prompt;
9346
9438
  images.push({
9347
9439
  b64_json: b64,
9348
- ...typeof revised === "string" && revised.length > 0 ? { revisedPrompt: revised } : {}
9440
+ ...typeof revised === "string" && revised.length > 0 ? { revisedPrompt: revised } : {},
9441
+ ...reportedQuality !== void 0 ? { reportedQuality } : {}
9349
9442
  });
9350
9443
  }
9351
9444
  if (images.length === 0) throw new Error("response contains no images");
@@ -9373,6 +9466,223 @@ function escapeHtml(value) {
9373
9466
  })[ch] ?? ch);
9374
9467
  }
9375
9468
  //#endregion
9469
+ //#region lib/types/capabilities.js
9470
+ /** zh labels shared by the server-side profiles; the client re-localizes. */
9471
+ const RATIO_LABELS = {
9472
+ auto: "自动",
9473
+ "1:1": "1:1 方形",
9474
+ "3:2": "3:2 横向",
9475
+ "2:3": "2:3 肖像",
9476
+ "4:3": "4:3 横向",
9477
+ "3:4": "3:4 竖向",
9478
+ "4:5": "4:5 肖像",
9479
+ "5:4": "5:4 横向",
9480
+ "3:1": "3:1 全景",
9481
+ "1:3": "1:3 长条",
9482
+ "21:9": "21:9 超宽",
9483
+ "9:21": "9:21 超高"
9484
+ };
9485
+ function ratioOption(value) {
9486
+ return {
9487
+ value,
9488
+ label: RATIO_LABELS[value] ?? value
9489
+ };
9490
+ }
9491
+ /** 16-divisible pixel sizes for the OpenAI-shape free-size contract. */
9492
+ const OPENAI_SIZE_TABLE = {
9493
+ "1:1": "1024x1024",
9494
+ "3:2": "1536x1024",
9495
+ "2:3": "1024x1536",
9496
+ "4:3": "1152x864",
9497
+ "3:4": "864x1152",
9498
+ "16:9": "1536x864",
9499
+ "9:16": "864x1536"
9500
+ };
9501
+ /** Official Seedream 5.0 tier × ratio table (volcengine docs 82379/1824121). */
9502
+ const SEEDREAM_SIZE_TABLE = {
9503
+ "1:1": {
9504
+ "2K": "2048x2048",
9505
+ "3K": "3072x3072",
9506
+ "4K": "4096x4096"
9507
+ },
9508
+ "4:3": {
9509
+ "2K": "2304x1728",
9510
+ "3K": "3456x2592",
9511
+ "4K": "4704x3520"
9512
+ },
9513
+ "3:4": {
9514
+ "2K": "1728x2304",
9515
+ "3K": "2592x3456",
9516
+ "4K": "3520x4704"
9517
+ },
9518
+ "16:9": {
9519
+ "2K": "2848x1600",
9520
+ "3K": "4096x2304",
9521
+ "4K": "5504x3040"
9522
+ },
9523
+ "9:16": {
9524
+ "2K": "1600x2848",
9525
+ "3K": "2304x4096",
9526
+ "4K": "3040x5504"
9527
+ },
9528
+ "3:2": {
9529
+ "2K": "2496x1664",
9530
+ "3K": "3744x2496",
9531
+ "4K": "4992x3328"
9532
+ },
9533
+ "2:3": {
9534
+ "2K": "1664x2496",
9535
+ "3K": "2496x3744",
9536
+ "4K": "3328x4992"
9537
+ },
9538
+ "21:9": {
9539
+ "2K": "3136x1344",
9540
+ "3K": "4704x2016",
9541
+ "4K": "6240x2656"
9542
+ }
9543
+ };
9544
+ /** qwen-image-3.0 pixel sizes within the documented 512*512–2048*2048 area. */
9545
+ const DASHSCOPE_SIZE_TABLE = {
9546
+ "1:1": "1024x1024",
9547
+ "3:2": "1536x1024",
9548
+ "2:3": "1024x1536",
9549
+ "4:3": "1152x864",
9550
+ "3:4": "864x1152",
9551
+ "16:9": "1664x928",
9552
+ "9:16": "928x1664"
9553
+ };
9554
+ /** glm-image recommended sizes (32-divisible, ≤2^22 px). */
9555
+ const ZHIPU_SIZE_TABLE = {
9556
+ "1:1": "1280x1280",
9557
+ "3:2": "1568x1056",
9558
+ "2:3": "1056x1568",
9559
+ "4:3": "1472x1088",
9560
+ "3:4": "1088x1472",
9561
+ "16:9": "1728x960",
9562
+ "9:16": "960x1728"
9563
+ };
9564
+ function capability(ratios, qualities, defaultRatio, defaultQuality, sizeFor) {
9565
+ return {
9566
+ ratioOptions: ratios.map(ratioOption),
9567
+ qualityOptions: qualities,
9568
+ defaultRatio,
9569
+ defaultQuality,
9570
+ ...sizeFor === void 0 ? {} : { sizeFor }
9571
+ };
9572
+ }
9573
+ const AUTO = {
9574
+ value: "auto",
9575
+ label: "自动"
9576
+ };
9577
+ const STANDARD = {
9578
+ value: "standard",
9579
+ label: "标准(推荐)"
9580
+ };
9581
+ const CLOUD_CAPABILITIES = {
9582
+ google: capability([
9583
+ "1:1",
9584
+ "3:2",
9585
+ "2:3",
9586
+ "4:3",
9587
+ "3:4",
9588
+ "4:5",
9589
+ "5:4",
9590
+ "16:9",
9591
+ "9:16",
9592
+ "21:9"
9593
+ ], [
9594
+ "1K",
9595
+ "2K",
9596
+ "4K"
9597
+ ].map((value) => ({
9598
+ value,
9599
+ label: value
9600
+ })), "1:1", "1K"),
9601
+ openai: capability(Object.keys(OPENAI_SIZE_TABLE), [AUTO, ...[
9602
+ "low",
9603
+ "medium",
9604
+ "high"
9605
+ ].map((value) => ({
9606
+ value,
9607
+ label: value
9608
+ }))], "1:1", "auto", (ratio) => OPENAI_SIZE_TABLE[ratio] ?? "1024x1024"),
9609
+ seedream: capability(["auto", ...Object.keys(SEEDREAM_SIZE_TABLE)], [
9610
+ "2K",
9611
+ "3K",
9612
+ "4K"
9613
+ ].map((value) => ({
9614
+ value,
9615
+ label: value
9616
+ })), "auto", "2K", (ratio, quality) => ratio === "auto" ? quality : SEEDREAM_SIZE_TABLE[ratio]?.[quality] ?? quality),
9617
+ dashscope: capability(Object.keys(DASHSCOPE_SIZE_TABLE), [STANDARD], "1:1", "standard", (ratio) => DASHSCOPE_SIZE_TABLE[ratio] ?? "1024x1024"),
9618
+ xai: capability([
9619
+ "auto",
9620
+ "1:1",
9621
+ "3:2",
9622
+ "2:3",
9623
+ "4:3",
9624
+ "3:4",
9625
+ "16:9",
9626
+ "9:16",
9627
+ "21:9"
9628
+ ], [{
9629
+ value: "1k",
9630
+ label: "1K"
9631
+ }, {
9632
+ value: "2k",
9633
+ label: "2K"
9634
+ }], "auto", "1k"),
9635
+ zhipu: capability(Object.keys(ZHIPU_SIZE_TABLE), [{
9636
+ value: "hd",
9637
+ label: "高清"
9638
+ }], "1:1", "hd", (ratio) => ZHIPU_SIZE_TABLE[ratio] ?? "1280x1280")
9639
+ };
9640
+ const SUBSCRIPTION_CAPABILITIES = {
9641
+ "chatgpt-sub": capability(["auto", ...Object.keys(OPENAI_SIZE_TABLE)], [AUTO, ...[
9642
+ "low",
9643
+ "medium",
9644
+ "high",
9645
+ "xhigh",
9646
+ "max"
9647
+ ].map((value) => ({
9648
+ value,
9649
+ label: value
9650
+ }))], "auto", "auto", (ratio) => ratio === "auto" ? void 0 : OPENAI_SIZE_TABLE[ratio] ?? "1024x1024"),
9651
+ "grok-sub": capability([
9652
+ "auto",
9653
+ "1:1",
9654
+ "3:2",
9655
+ "2:3",
9656
+ "4:3",
9657
+ "3:4",
9658
+ "16:9",
9659
+ "9:16",
9660
+ "21:9"
9661
+ ], [{
9662
+ value: "1k",
9663
+ label: "1K"
9664
+ }, {
9665
+ value: "2k",
9666
+ label: "2K"
9667
+ }], "auto", "1k"),
9668
+ "google-sub": capability([
9669
+ "auto",
9670
+ "1:1",
9671
+ "3:2",
9672
+ "2:3",
9673
+ "4:3",
9674
+ "3:4",
9675
+ "4:5",
9676
+ "5:4",
9677
+ "16:9",
9678
+ "9:16",
9679
+ "21:9"
9680
+ ], [STANDARD, {
9681
+ value: "hd",
9682
+ label: "高清(4K)"
9683
+ }], "auto", "standard")
9684
+ };
9685
+ //#endregion
9376
9686
  //#region lib/types/subscription/subscription-route.js
9377
9687
  const MAX_BODY_BYTES$1 = 16384;
9378
9688
  /** The vendor each subscription provider logs in as. */
@@ -9477,6 +9787,24 @@ function jsonError$3(res, status, code) {
9477
9787
  }
9478
9788
  //#endregion
9479
9789
  //#region lib/types/subscription.js
9790
+ /** Translate image tool options into each subscription channel's wire inputs. */
9791
+ function subscriptionToolParameters(provider, options) {
9792
+ if (options.size !== void 0 && options.aspectRatio !== void 0) throw new Error("size 与 aspect_ratio 请只选一个");
9793
+ const ratio = options.aspectRatio;
9794
+ if (ratio !== void 0 && !SUBSCRIPTION_CAPABILITIES[provider].ratioOptions.some((option) => option.value === ratio)) throw new Error(`${provider} 不支持比例 ${ratio}`);
9795
+ const size = options.size ?? (ratio === void 0 ? void 0 : provider === "chatgpt-sub" ? SUBSCRIPTION_CAPABILITIES[provider].sizeFor?.(ratio, "auto") : ratio);
9796
+ let quality;
9797
+ if (options.imageSize !== void 0) {
9798
+ if (provider === "grok-sub" && (options.imageSize === "1K" || options.imageSize === "2K")) quality = options.imageSize.toLowerCase();
9799
+ else if (provider === "google-sub" && options.imageSize === "4K") quality = "hd";
9800
+ else if (provider === "google-sub" && options.imageSize === "1K") quality = void 0;
9801
+ else throw new Error(`${provider} 不支持清晰度 ${options.imageSize}`);
9802
+ }
9803
+ return {
9804
+ ...size === void 0 ? {} : { size },
9805
+ ...quality === void 0 ? {} : { quality }
9806
+ };
9807
+ }
9480
9808
  /**
9481
9809
  * Generate one image through a logged-in subscription account. Returns the
9482
9810
  * same `{ data, mediaType }` contract as the API-key adapters so the caller
@@ -9486,11 +9814,13 @@ function jsonError$3(res, status, code) {
9486
9814
  async function generateSubscriptionImage(options) {
9487
9815
  const { manager, provider, prompt, maxBytes, signal } = options;
9488
9816
  const size = options.size?.trim();
9817
+ const quality = options.quality?.trim();
9489
9818
  const sourceImages = options.sourceImages ?? [];
9490
9819
  const result = await withTimeout(manager.generate({
9491
9820
  vendor: vendorOf(provider),
9492
9821
  prompt,
9493
9822
  ...size !== void 0 && size.length > 0 ? { size } : {},
9823
+ ...quality !== void 0 && quality.length > 0 ? { quality } : {},
9494
9824
  ...sourceImages.length > 0 ? { referenceImages: sourceImages } : {},
9495
9825
  signal
9496
9826
  }), signal);
@@ -9503,7 +9833,8 @@ async function generateSubscriptionImage(options) {
9503
9833
  return {
9504
9834
  data: bytes,
9505
9835
  mediaType,
9506
- ...typeof first.revisedPrompt === "string" && first.revisedPrompt.length > 0 ? { revisedPrompt: first.revisedPrompt } : {}
9836
+ ...typeof first.revisedPrompt === "string" && first.revisedPrompt.length > 0 ? { revisedPrompt: first.revisedPrompt } : {},
9837
+ ...typeof first.reportedQuality === "string" && first.reportedQuality.length > 0 ? { reportedQuality: first.reportedQuality } : {}
9507
9838
  };
9508
9839
  }
9509
9840
  /** Run one promise with the subscription timeout and the call's abort signal. */
@@ -26857,23 +27188,6 @@ async function clearDiskCache() {
26857
27188
  }
26858
27189
  //#endregion
26859
27190
  //#region lib/types/studio.js
26860
- const RATIO_LABELS = {
26861
- auto: "自动",
26862
- "1:1": "1:1 方形",
26863
- "3:2": "3:2 横向",
26864
- "2:3": "2:3 肖像",
26865
- "4:3": "4:3 横向",
26866
- "3:4": "3:4 竖向",
26867
- "16:9": "16:9 宽屏",
26868
- "9:16": "9:16 竖屏",
26869
- "4:5": "4:5 肖像",
26870
- "5:4": "5:4 横向",
26871
- "3:1": "3:1 全景",
26872
- "1:3": "1:3 长条",
26873
- "21:9": "21:9 超宽",
26874
- "9:21": "9:21 超高"
26875
- };
26876
- /** Built-in OpenAI-shape size trio used when no relay table is configured. */
26877
27191
  const LEGACY_OPENAI_TABLE = {
26878
27192
  "1:1": { "1K": "1024x1024" },
26879
27193
  "3:2": { "1K": "1536x1024" },
@@ -27007,22 +27321,19 @@ async function describeStudio(ctx, config, subscriptions) {
27007
27321
  function isStudioPreferred(preferred) {
27008
27322
  return preferred !== void 0 && CLOUD_IMAGE_PROVIDERS.includes(preferred) || preferred !== void 0 && SUBSCRIPTION_PROVIDERS.includes(preferred);
27009
27323
  }
27010
- /** Fixed parameter shape for subscription channels: one "channel default" pair. */
27324
+ /** Subscription profiles come from the shared capability table (see capabilities.ts). */
27011
27325
  function subscriptionStudioProfile(provider, signedIn) {
27012
- const channelDefault = {
27013
- value: "auto",
27014
- label: "通道默认"
27015
- };
27326
+ const cap = SUBSCRIPTION_CAPABILITIES[provider];
27016
27327
  return {
27017
27328
  provider,
27018
27329
  label: SUBSCRIPTION_DISPLAY_LABELS[provider],
27019
27330
  model: DEFAULT_SUBSCRIPTION_MODELS[provider],
27020
27331
  configured: signedIn,
27021
27332
  supportsEditing: true,
27022
- ratioOptions: [channelDefault],
27023
- qualityOptions: [channelDefault],
27024
- defaultRatio: "auto",
27025
- defaultQuality: "auto"
27333
+ ratioOptions: cap.ratioOptions,
27334
+ qualityOptions: cap.qualityOptions,
27335
+ defaultRatio: cap.defaultRatio,
27336
+ defaultQuality: cap.defaultQuality
27026
27337
  };
27027
27338
  }
27028
27339
  /** Short display names for the workbench subscription rows. */
@@ -27076,33 +27387,43 @@ async function generateFromStudio(ctx, config, input, signal, fallbackWorkspaceR
27076
27387
  });
27077
27388
  output = `${aspectRatio}, ${imageSize}`;
27078
27389
  } else if (wired.provider === "openai" || wired.provider === "openai-compat" || wired.provider === "xai" || wired.provider === "zhipu") {
27079
- const size = wired.provider === "openai-compat" ? openAIRequestSize(config, input.ratio, input.quality) : openAISize(input.ratio);
27390
+ const p = wired.provider;
27391
+ const size = p === "openai-compat" ? openAIRequestSize(config, input.ratio, input.quality) : p === "xai" ? void 0 : CLOUD_CAPABILITIES[p].sizeFor?.(input.ratio, input.quality);
27392
+ const quality = p === "openai" ? input.quality === "auto" ? void 0 : input.quality : p === "zhipu" ? "hd" : void 0;
27393
+ const extraBody = p === "xai" ? {
27394
+ aspect_ratio: input.ratio,
27395
+ resolution: input.quality
27396
+ } : void 0;
27080
27397
  generated = input.mode === "edit" ? await editOpenAICompatibleImage({
27081
27398
  apiKey: credential,
27082
27399
  baseURL: wired.baseURL,
27083
27400
  model: wired.model,
27084
27401
  prompt: input.prompt,
27085
27402
  sourceImages,
27086
- size,
27403
+ ...size === void 0 ? {} : { size },
27087
27404
  maxBytes: ctx.attachments.imageLimits.maxImageBytes,
27088
27405
  signal,
27089
- ...wired.provider === "openai-compat" ? {
27406
+ ...quality === void 0 ? {} : { quality },
27407
+ ...extraBody === void 0 ? {} : { extraBody },
27408
+ ...p === "openai-compat" ? {
27090
27409
  editFormat: wired.editFormat,
27091
27410
  editExtra: wired.editExtra
27092
- } : {}
27411
+ } : p === "xai" ? { editFormat: "xaiJson" } : {}
27093
27412
  }) : await generateOpenAICompatibleImage({
27094
- provider: wired.provider,
27413
+ provider: p,
27095
27414
  apiKey: credential,
27096
27415
  baseURL: wired.baseURL,
27097
27416
  model: wired.model,
27098
27417
  prompt: input.prompt,
27099
- size,
27418
+ ...size === void 0 ? {} : { size },
27100
27419
  maxBytes: ctx.attachments.imageLimits.maxImageBytes,
27101
- signal
27420
+ signal,
27421
+ ...quality === void 0 ? {} : { quality },
27422
+ ...extraBody === void 0 ? {} : { extraBody }
27102
27423
  });
27103
- output = size;
27424
+ output = size ?? `${input.ratio}, ${input.quality}`;
27104
27425
  } else if (wired.provider === "seedream") {
27105
- const size = input.quality;
27426
+ const size = CLOUD_CAPABILITIES.seedream.sizeFor?.(input.ratio, input.quality) ?? input.quality;
27106
27427
  generated = input.mode === "edit" ? await editSeedreamImage({
27107
27428
  apiKey: credential,
27108
27429
  baseURL: wired.baseURL,
@@ -27127,7 +27448,7 @@ async function generateFromStudio(ctx, config, input, signal, fallbackWorkspaceR
27127
27448
  output = size;
27128
27449
  } else {
27129
27450
  if (input.mode === "edit" && sourceImages.length > 3) throw new Error("DashScope (通义万相) 图生图目前最多支持 3 张参考图,请精简后重试");
27130
- const size = dashScopeSize(input.ratio);
27451
+ const size = CLOUD_CAPABILITIES.dashscope.sizeFor?.(input.ratio, input.quality) ?? "1024x1024";
27131
27452
  generated = input.mode === "edit" ? await editDashScopeImage({
27132
27453
  apiKey: credential,
27133
27454
  endpoint: wired.endpoint,
@@ -27242,23 +27563,30 @@ async function generateSubscriptionFromStudio(ctx, subscriptions, input, signal)
27242
27563
  const sourceImages = input.mode === "edit" ? await Promise.all(rawRefs.map((ref) => readStudioReference(ctx, ref, signal))) : [];
27243
27564
  const startedAt = Date.now();
27244
27565
  const count = input.count ?? 1;
27566
+ const subCap = SUBSCRIPTION_CAPABILITIES[provider];
27567
+ const wireSize = provider === "chatgpt-sub" ? subCap.sizeFor?.(input.ratio, input.quality) : input.ratio;
27568
+ const wireQuality = input.quality === "auto" || input.quality === "standard" ? void 0 : input.quality;
27569
+ const requestedOutput = input.ratio === "auto" && wireQuality === void 0 ? "通道默认" : `${input.ratio}, ${input.quality}`;
27245
27570
  const generateSingle = async (index) => {
27246
27571
  const generated = await generateSubscriptionImage({
27247
27572
  manager: subscriptions,
27248
27573
  provider,
27249
27574
  prompt: input.prompt,
27575
+ ...wireSize === void 0 || wireSize.length === 0 ? {} : { size: wireSize },
27576
+ ...wireQuality === void 0 ? {} : { quality: wireQuality },
27250
27577
  ...sourceImages.length > 0 ? { sourceImages } : {},
27251
27578
  maxBytes: ctx.attachments.imageLimits.maxImageBytes,
27252
27579
  signal
27253
27580
  });
27254
27581
  if (!ctx.attachments.imageLimits.mediaTypes.includes(generated.mediaType)) throw new Error(`当前 DSH 不支持保存 ${generated.mediaType} 图片`);
27582
+ const attachment = await ctx.attachments.saveImage({
27583
+ data: generated.data,
27584
+ mediaType: generated.mediaType,
27585
+ name: count > 1 ? `studio-image-${index + 1}` : "studio-image"
27586
+ });
27255
27587
  return {
27256
- attachment: await ctx.attachments.saveImage({
27257
- data: generated.data,
27258
- mediaType: generated.mediaType,
27259
- name: count > 1 ? `studio-image-${index + 1}` : "studio-image"
27260
- }),
27261
- output: "通道默认"
27588
+ attachment,
27589
+ output: subscriptionOutput(input.ratio, input.quality, requestedOutput, attachment.width, attachment.height, generated.reportedQuality)
27262
27590
  };
27263
27591
  };
27264
27592
  if (count === 1) {
@@ -27283,6 +27611,16 @@ async function generateSubscriptionFromStudio(ctx, subscriptions, input, signal)
27283
27611
  const first = successes[0];
27284
27612
  return subscriptionResponse(input, startedAt, count, errors.length, successes, first, errors);
27285
27613
  }
27614
+ /** Describe what the subscription returned without presenting requested settings as actual output. */
27615
+ function subscriptionOutput(ratio, quality, fallback, width, height, reportedQuality) {
27616
+ const qualityReport = reportedQuality === void 0 ? "" : ` · 服务端回报清晰度 ${reportedQuality}`;
27617
+ if (width === void 0 || height === void 0 || width <= 0 || height <= 0) return `${fallback}${qualityReport}`;
27618
+ const actual = `实际 ${String(width)}×${String(height)}`;
27619
+ if (ratio === "auto") return `请求 ${ratio}, ${quality}${qualityReport} · ${actual}`;
27620
+ const parts = ratio.split(":").map(Number);
27621
+ const requested = parts.length === 2 && parts[0] > 0 && parts[1] > 0 ? parts[0] / parts[1] : void 0;
27622
+ return `请求 ${ratio}, ${quality}${qualityReport} · ${actual}${requested !== void 0 && Math.abs(width / height / requested - 1) > .12 ? "(比例未生效)" : ""}`;
27623
+ }
27286
27624
  /** Assemble the subscription workbench response with exactOptionalPropertyTypes-safe spreads. */
27287
27625
  function subscriptionResponse(input, startedAt, requestedCount, failedCount, items, primary, errors) {
27288
27626
  return {
@@ -27316,10 +27654,10 @@ function studioProfile(config, provider, configured) {
27316
27654
  }
27317
27655
  if (active.provider === "comfyui") throw new Error("Invalid cloud provider profile");
27318
27656
  const model = active.model;
27319
- if (provider === "google") return profile(provider, model, configured, ASPECT_RATIOS$1.map(option), IMAGE_SIZES.map((value) => ({
27320
- value,
27321
- label: value
27322
- })), "1:1", "1K");
27657
+ if (provider === "google") {
27658
+ const cap = CLOUD_CAPABILITIES.google;
27659
+ return profile(provider, model, configured, cap.ratioOptions, cap.qualityOptions, cap.defaultRatio, cap.defaultQuality);
27660
+ }
27323
27661
  if (provider === "openai-compat") {
27324
27662
  if (config.openaiCompatSizes === void 0 || Object.keys(config.openaiCompatSizes).length === 0) return profile(provider, model, configured, [
27325
27663
  "1:1",
@@ -27331,35 +27669,8 @@ function studioProfile(config, provider, configured) {
27331
27669
  }], "1:1", "standard");
27332
27670
  return openAICompatStudioProfile(config, model, configured);
27333
27671
  }
27334
- if (provider === "openai" || provider === "xai" || provider === "zhipu") return profile(provider, model, configured, [
27335
- "1:1",
27336
- "3:2",
27337
- "2:3"
27338
- ].map(option), [{
27339
- value: "standard",
27340
- label: "标准(推荐)"
27341
- }], "1:1", "standard");
27342
- if (provider === "seedream") return profile(provider, model, configured, [{
27343
- value: "auto",
27344
- label: "模型自动"
27345
- }], [
27346
- "1K",
27347
- "2K",
27348
- "4K"
27349
- ].map((value) => ({
27350
- value,
27351
- label: value
27352
- })), "auto", "2K");
27353
- return profile(provider, model, configured, [
27354
- "1:1",
27355
- "3:2",
27356
- "2:3",
27357
- "16:9",
27358
- "9:16"
27359
- ].map(option), [{
27360
- value: "standard",
27361
- label: "标准(推荐)"
27362
- }], "1:1", "standard");
27672
+ const cap = CLOUD_CAPABILITIES[provider];
27673
+ return profile(provider, model, configured, cap.ratioOptions, cap.qualityOptions, cap.defaultRatio, cap.defaultQuality);
27363
27674
  }
27364
27675
  function profile(provider, model, configured, ratioOptions, qualityOptions, defaultRatio, defaultQuality) {
27365
27676
  return {
@@ -27423,20 +27734,6 @@ function decodeCanonicalBase64(value) {
27423
27734
  if (data.byteLength === 0 || data.toString("base64") !== value) throw new Error("参考图编码无效");
27424
27735
  return new Uint8Array(data);
27425
27736
  }
27426
- function openAISize(ratio) {
27427
- if (ratio === "3:2") return "1536x1024";
27428
- if (ratio === "2:3") return "1024x1536";
27429
- return "1024x1024";
27430
- }
27431
- function dashScopeSize(ratio) {
27432
- return {
27433
- "1:1": "1024*1024",
27434
- "3:2": "1536*1024",
27435
- "2:3": "1024*1536",
27436
- "16:9": "1664*928",
27437
- "9:16": "928*1664"
27438
- }[ratio] ?? "1024*1024";
27439
- }
27440
27737
  //#endregion
27441
27738
  //#region lib/types/studio-route.js
27442
27739
  /** Serve workbench capabilities and generation requests without exposing provider credentials. */
@@ -27950,6 +28247,27 @@ function jsonError(res, status, code) {
27950
28247
  json(res, status, { error: code });
27951
28248
  }
27952
28249
  //#endregion
28250
+ //#region lib/types/settings-health.js
28251
+ function describeSettingsHealth(settings, schema) {
28252
+ const service = settings;
28253
+ const fields = Object.values(schema.dict ?? {});
28254
+ return {
28255
+ settings: typeof service?.installSection === "function" ? "legacy" : typeof service?.describe === "function" ? "live" : "unavailable",
28256
+ liveSchema: fields.length > 0 && fields.every((field) => field.meta.volatile === true)
28257
+ };
28258
+ }
28259
+ function serveSettingsHealth(req, res, health) {
28260
+ res.setHeader("cache-control", "no-store");
28261
+ if (req.method !== "GET") {
28262
+ res.statusCode = 405;
28263
+ res.setHeader("allow", "GET");
28264
+ res.end();
28265
+ return;
28266
+ }
28267
+ res.setHeader("content-type", "application/json; charset=utf-8");
28268
+ res.end(JSON.stringify(health));
28269
+ }
28270
+ //#endregion
27953
28271
  //#region lib/types/index.js
27954
28272
  const name = "dsh-image-gen";
27955
28273
  const inject = [
@@ -27975,12 +28293,17 @@ function apply(ctx, config = {}) {
27975
28293
  const canvasMirror = new CanvasMirror();
27976
28294
  const subscriptionManager = new SubscriptionManager(ctx);
27977
28295
  registerSubscriptionRoutes(ctx, subscriptionManager);
27978
- installImageSettings(ctx, current(), {
28296
+ const settingsHealth = installImageSettings(ctx, current(), {
27979
28297
  setSource: (source) => {
27980
28298
  current = () => migrateOpenAICompatConfig(plainConfig(source()));
27981
28299
  },
27982
28300
  onChange: () => {}
27983
28301
  });
28302
+ ctx.effect(() => ctx.webServer.register({
28303
+ kind: "exact",
28304
+ path: SETTINGS_HEALTH_ROUTE,
28305
+ handler: (req, res) => serveSettingsHealth(req, res, settingsHealth())
28306
+ }), "dsh-image-gen: settings health");
27984
28307
  ctx.effect(() => ctx.webServer.register({
27985
28308
  kind: "exact",
27986
28309
  path: IMAGE_ROUTE,
@@ -28117,14 +28440,21 @@ function apply(ctx, config = {}) {
28117
28440
  signal: exec.signal
28118
28441
  }), active.provider, workflow.name, "API workflow", current(), exec, knownWorkspaceRoots);
28119
28442
  }
28120
- if (active.provider === "chatgpt-sub" || active.provider === "grok-sub" || active.provider === "google-sub") return saveGenerated(ctx, await generateSubscriptionImage({
28121
- manager: subscriptionManager,
28122
- provider: active.provider,
28123
- prompt: args.prompt,
28124
- ...args.size !== void 0 ? { size: args.size } : {},
28125
- maxBytes: ctx.attachments.imageLimits.maxImageBytes,
28126
- signal: exec.signal
28127
- }), active.provider, active.model, "subscription", current(), exec, knownWorkspaceRoots);
28443
+ if (active.provider === "chatgpt-sub" || active.provider === "grok-sub" || active.provider === "google-sub") {
28444
+ const subscriptionParams = subscriptionToolParameters(active.provider, {
28445
+ ...args.size !== void 0 ? { size: args.size } : {},
28446
+ ...args.aspect_ratio !== void 0 ? { aspectRatio: args.aspect_ratio } : {},
28447
+ ...args.image_size !== void 0 ? { imageSize: args.image_size } : {}
28448
+ });
28449
+ return saveGenerated(ctx, await generateSubscriptionImage({
28450
+ manager: subscriptionManager,
28451
+ provider: active.provider,
28452
+ prompt: args.prompt,
28453
+ ...subscriptionParams,
28454
+ maxBytes: ctx.attachments.imageLimits.maxImageBytes,
28455
+ signal: exec.signal
28456
+ }), active.provider, active.model, "subscription", current(), exec, knownWorkspaceRoots);
28457
+ }
28128
28458
  const credential = await requireApiKey(ctx, active.provider, "generate_image");
28129
28459
  if (active.provider === "google") {
28130
28460
  const aspectRatio = args.aspect_ratio ?? active.aspectRatio;
@@ -28152,6 +28482,23 @@ function apply(ctx, config = {}) {
28152
28482
  signal: exec.signal
28153
28483
  }), active.provider, active.model, size, current(), exec, knownWorkspaceRoots);
28154
28484
  }
28485
+ if (active.provider === "xai") {
28486
+ const extraBody = xaiToolParameters({
28487
+ ...args.aspect_ratio !== void 0 ? { aspectRatio: args.aspect_ratio } : {},
28488
+ ...args.image_size !== void 0 ? { imageSize: args.image_size } : {},
28489
+ ...args.size !== void 0 ? { size: args.size } : {}
28490
+ });
28491
+ return saveGenerated(ctx, await generateOpenAICompatibleImage({
28492
+ provider: "xai",
28493
+ apiKey: credential,
28494
+ baseURL: active.baseURL,
28495
+ model: active.model,
28496
+ prompt: args.prompt,
28497
+ extraBody,
28498
+ maxBytes: ctx.attachments.imageLimits.maxImageBytes,
28499
+ signal: exec.signal
28500
+ }), active.provider, active.model, extraBody.aspect_ratio ?? "auto", current(), exec, knownWorkspaceRoots);
28501
+ }
28155
28502
  const size = args.size ?? active.imageSize;
28156
28503
  const arkOptions = active.provider === "seedream" ? active.arkOptions : void 0;
28157
28504
  return saveGenerated(ctx, await generateOpenAICompatibleImage({
@@ -28204,10 +28551,13 @@ function apply(ctx, config = {}) {
28204
28551
  "2:3",
28205
28552
  "4:3",
28206
28553
  "3:4",
28554
+ "4:5",
28555
+ "5:4",
28207
28556
  "16:9",
28208
- "9:16"
28557
+ "9:16",
28558
+ "21:9"
28209
28559
  ],
28210
- description: "Optional output aspect ratio for Google Gemini."
28560
+ description: "Optional output aspect ratio for Google Gemini, xAI Grok, and subscription channels."
28211
28561
  },
28212
28562
  image_size: {
28213
28563
  type: "string",
@@ -28216,11 +28566,11 @@ function apply(ctx, config = {}) {
28216
28566
  "2K",
28217
28567
  "4K"
28218
28568
  ],
28219
- description: "Optional output resolution for Google Gemini."
28569
+ description: "Optional output resolution for Google Gemini, xAI Grok, Grok subscription (1K/2K), or Google subscription (1K/4K)."
28220
28570
  },
28221
28571
  size: {
28222
28572
  type: "string",
28223
- description: "Optional dimensions or size tier for OpenAI, Seedream, or DashScope."
28573
+ description: "Optional dimensions or size tier for OpenAI, Seedream, or DashScope; WIDTHxHEIGHT maps to aspect_ratio for xAI Grok."
28224
28574
  },
28225
28575
  workflow: {
28226
28576
  type: "string",
@@ -28272,10 +28622,13 @@ function apply(ctx, config = {}) {
28272
28622
  "2:3",
28273
28623
  "4:3",
28274
28624
  "3:4",
28625
+ "4:5",
28626
+ "5:4",
28275
28627
  "16:9",
28276
- "9:16"
28628
+ "9:16",
28629
+ "21:9"
28277
28630
  ],
28278
- description: "Optional output aspect ratio for Google Gemini."
28631
+ description: "Optional output aspect ratio for Google Gemini, xAI Grok, and subscription channels."
28279
28632
  },
28280
28633
  image_size: {
28281
28634
  type: "string",
@@ -28284,11 +28637,11 @@ function apply(ctx, config = {}) {
28284
28637
  "2K",
28285
28638
  "4K"
28286
28639
  ],
28287
- description: "Optional output resolution for Google Gemini."
28640
+ description: "Optional output resolution for Google Gemini, xAI Grok, Grok subscription (1K/2K), or Google subscription (1K/4K)."
28288
28641
  },
28289
28642
  size: {
28290
28643
  type: "string",
28291
- description: "Optional dimensions or size tier for OpenAI, Seedream, or DashScope."
28644
+ description: "Optional dimensions or size tier for OpenAI, Seedream, or DashScope; WIDTHxHEIGHT maps to aspect_ratio for xAI Grok."
28292
28645
  },
28293
28646
  workflow: {
28294
28647
  type: "string",
@@ -28331,7 +28684,21 @@ function apply(ctx, config = {}) {
28331
28684
  type: "integer",
28332
28685
  required: true
28333
28686
  },
28334
- name: { type: "string" }
28687
+ name: { type: "string" },
28688
+ originalDimensions: {
28689
+ type: "object",
28690
+ additionalProperties: false,
28691
+ properties: {
28692
+ width: {
28693
+ type: "integer",
28694
+ required: true
28695
+ },
28696
+ height: {
28697
+ type: "integer",
28698
+ required: true
28699
+ }
28700
+ }
28701
+ }
28335
28702
  }
28336
28703
  },
28337
28704
  provider: {
@@ -28348,6 +28715,7 @@ function apply(ctx, config = {}) {
28348
28715
  },
28349
28716
  savedTo: { type: "string" },
28350
28717
  saveError: { type: "string" },
28718
+ seed: { type: "integer" },
28351
28719
  prompt: {
28352
28720
  type: "string",
28353
28721
  required: true
@@ -28380,8 +28748,15 @@ function apply(ctx, config = {}) {
28380
28748
  },
28381
28749
  render: (_args, value) => [{
28382
28750
  type: "text",
28383
- text: `Generated ${String(value.images.length)} of ${String(value.images.length + value.failures.length)} images.\n${[...value.images.map((image) => `${String(image.prompt).slice(0, 80)} — attachment ${String(image.attachment.attachmentId)}${typeof image.savedTo === "string" ? `, saved to ${image.savedTo}` : ""}`), ...value.failures.map((failure) => `${failure.prompt.slice(0, 80)} — failed: ${failure.error}`)].join("\n")}\nEach generated image is attached to the conversation; respond without reading or searching for them.`
28384
- }]
28751
+ text: `Generated ${String(value.images.length)} of ${String(value.images.length + value.failures.length)} images.\n${value.failures.map((failure) => `${failure.prompt.slice(0, 80)} — failed: ${failure.error}`).join("\n")}`
28752
+ }, ...value.images.flatMap((image) => imageOutput("Generated").render({}, image).map((block) => block.type === "text" ? {
28753
+ ...block,
28754
+ text: `${block.text}\nImage prompt: ${image.prompt}`
28755
+ } : block))],
28756
+ presentationMeta: (_args, value) => ({
28757
+ kind: "dsh-image-gen-batch",
28758
+ images: value.images.map((image) => imageOutput("Generated").presentationMeta({ prompt: image.prompt }, image))
28759
+ })
28385
28760
  },
28386
28761
  async execute(args, exec) {
28387
28762
  if (args.prompts.length === 0) throw new Error("generate_images requires at least one prompt");
@@ -28408,12 +28783,7 @@ function apply(ctx, config = {}) {
28408
28783
  ...args.workflow !== void 0 ? { workflow: args.workflow } : {}
28409
28784
  }, exec);
28410
28785
  images.push({
28411
- attachment: value.attachment,
28412
- provider: value.provider,
28413
- model: value.model,
28414
- output: value.output,
28415
- ...typeof value.savedTo === "string" ? { savedTo: value.savedTo } : {},
28416
- ...typeof value.saveError === "string" ? { saveError: value.saveError } : {},
28786
+ ...value,
28417
28787
  prompt
28418
28788
  });
28419
28789
  } catch (error) {
@@ -28428,7 +28798,8 @@ function apply(ctx, config = {}) {
28428
28798
  images,
28429
28799
  failures
28430
28800
  };
28431
- }
28801
+ },
28802
+ presentResult: (_args, result) => imagePresentation(result)
28432
28803
  }));
28433
28804
  ctx.tools.register(defineTool({
28434
28805
  name: "edit_image",
@@ -28491,10 +28862,13 @@ function apply(ctx, config = {}) {
28491
28862
  "2:3",
28492
28863
  "4:3",
28493
28864
  "3:4",
28865
+ "4:5",
28866
+ "5:4",
28494
28867
  "16:9",
28495
- "9:16"
28868
+ "9:16",
28869
+ "21:9"
28496
28870
  ],
28497
- description: "Optional output aspect ratio for Google Gemini."
28871
+ description: "Optional output aspect ratio for Google Gemini, xAI Grok, and subscription channels."
28498
28872
  },
28499
28873
  image_size: {
28500
28874
  type: "string",
@@ -28503,11 +28877,11 @@ function apply(ctx, config = {}) {
28503
28877
  "2K",
28504
28878
  "4K"
28505
28879
  ],
28506
- description: "Optional output resolution for Google Gemini."
28880
+ description: "Optional output resolution for Google Gemini, xAI Grok, Grok subscription (1K/2K), or Google subscription (1K/4K)."
28507
28881
  },
28508
28882
  size: {
28509
28883
  type: "string",
28510
- description: "Optional output size for OpenAI, Seedream, or DashScope."
28884
+ description: "Optional output size for OpenAI, Seedream, or DashScope; WIDTHxHEIGHT maps to aspect_ratio for xAI Grok."
28511
28885
  },
28512
28886
  workflow: {
28513
28887
  type: "string",
@@ -28555,12 +28929,17 @@ function apply(ctx, config = {}) {
28555
28929
  }
28556
28930
  if (active.provider === "chatgpt-sub" || active.provider === "grok-sub" || active.provider === "google-sub") {
28557
28931
  if (sourceImages.length === 0) throw new Error("edit_image requires a reference image");
28932
+ const subscriptionParams = subscriptionToolParameters(active.provider, {
28933
+ ...args.size !== void 0 ? { size: args.size } : {},
28934
+ ...args.aspect_ratio !== void 0 ? { aspectRatio: args.aspect_ratio } : {},
28935
+ ...args.image_size !== void 0 ? { imageSize: args.image_size } : {}
28936
+ });
28558
28937
  return saveGenerated(ctx, await generateSubscriptionImage({
28559
28938
  manager: subscriptionManager,
28560
28939
  provider: active.provider,
28561
28940
  prompt: args.prompt,
28562
28941
  sourceImages,
28563
- ...args.size !== void 0 ? { size: args.size } : {},
28942
+ ...subscriptionParams,
28564
28943
  maxBytes: ctx.attachments.imageLimits.maxImageBytes,
28565
28944
  signal: exec.signal
28566
28945
  }), active.provider, active.model, "subscription edit", current(), exec, knownWorkspaceRoots);
@@ -28582,20 +28961,30 @@ function apply(ctx, config = {}) {
28582
28961
  }), active.provider, active.model, `${aspectRatio}, ${imageSize}`, current(), exec, knownWorkspaceRoots);
28583
28962
  }
28584
28963
  const size = args.size ?? active.imageSize;
28585
- if (active.provider === "openai" || active.provider === "openai-compat" || active.provider === "xai" || active.provider === "zhipu") return saveGenerated(ctx, await editOpenAICompatibleImage({
28586
- apiKey: credential,
28587
- baseURL: active.baseURL,
28588
- model: active.model,
28589
- prompt: args.prompt,
28590
- sourceImages,
28591
- size,
28592
- maxBytes: ctx.attachments.imageLimits.maxImageBytes,
28593
- signal: exec.signal,
28594
- ...active.provider === "openai-compat" ? {
28595
- editFormat: active.editFormat,
28596
- editExtra: active.editExtra
28597
- } : {}
28598
- }), active.provider, active.model, size, current(), exec, knownWorkspaceRoots);
28964
+ if (active.provider === "openai" || active.provider === "openai-compat" || active.provider === "xai" || active.provider === "zhipu") {
28965
+ const xaiExtraBody = active.provider === "xai" ? xaiToolParameters({
28966
+ ...args.aspect_ratio !== void 0 ? { aspectRatio: args.aspect_ratio } : {},
28967
+ ...args.image_size !== void 0 ? { imageSize: args.image_size } : {},
28968
+ ...args.size !== void 0 ? { size: args.size } : {}
28969
+ }) : void 0;
28970
+ return saveGenerated(ctx, await editOpenAICompatibleImage({
28971
+ apiKey: credential,
28972
+ baseURL: active.baseURL,
28973
+ model: active.model,
28974
+ prompt: args.prompt,
28975
+ sourceImages,
28976
+ ...active.provider === "xai" ? {} : { size },
28977
+ maxBytes: ctx.attachments.imageLimits.maxImageBytes,
28978
+ signal: exec.signal,
28979
+ ...active.provider === "openai-compat" ? {
28980
+ editFormat: active.editFormat,
28981
+ editExtra: active.editExtra
28982
+ } : active.provider === "xai" ? {
28983
+ editFormat: "xaiJson",
28984
+ ...xaiExtraBody === void 0 ? {} : { extraBody: xaiExtraBody }
28985
+ } : {}
28986
+ }), active.provider, active.model, active.provider === "xai" ? xaiExtraBody?.aspect_ratio ?? "auto" : size, current(), exec, knownWorkspaceRoots);
28987
+ }
28599
28988
  if (active.provider === "seedream") return saveGenerated(ctx, await editSeedreamImage({
28600
28989
  apiKey: credential,
28601
28990
  baseURL: active.baseURL,
@@ -28845,6 +29234,21 @@ async function saveGenerated(ctx, generated, provider, model, output, config, ex
28845
29234
  return value;
28846
29235
  }
28847
29236
  function imagePresentation(result) {
29237
+ const meta = result.meta;
29238
+ if (typeof meta === "object" && meta !== null && !Array.isArray(meta) && meta.kind === "dsh-image-gen-batch" && Array.isArray(meta.images)) {
29239
+ const content = meta.images.flatMap((image) => {
29240
+ const attachment = imageAttachmentFromMeta(image);
29241
+ return attachment === void 0 ? [] : [{
29242
+ type: "image",
29243
+ attachment
29244
+ }];
29245
+ });
29246
+ return content.length === 0 ? void 0 : {
29247
+ card: "generic",
29248
+ title: "Generated images",
29249
+ content
29250
+ };
29251
+ }
28848
29252
  const attachment = imageAttachmentFromMeta(result.meta);
28849
29253
  return attachment === void 0 ? void 0 : {
28850
29254
  card: "generic",
@@ -28864,14 +29268,22 @@ function imagePresentation(result) {
28864
29268
  * on the service, so the namespace registers through it; DSH 0.1.7 replaced it
28865
29269
  * with schema-derived forms served by the loader itself (keyed by entry id),
28866
29270
  * so its service carries no installer and a host without any settings service
28867
- * simply never runs the callback — both stay silent instead of warning.
29271
+ * simply never runs the callback. A modern host with an unmarked schema is
29272
+ * incompatible and must be diagnosed, while old hosts keep their installer.
28868
29273
  */
28869
29274
  function installImageSettings(ctx, config, hooks) {
29275
+ let service;
28870
29276
  ctx.inject(["settings"], (settingsCtx) => {
28871
29277
  const settings = settingsCtx.settings;
28872
- if (typeof settings.installSection !== "function") return;
28873
- settings.installSection(ctx, IMAGE_GENERATION_NAMESPACE, Config, config, hooks);
29278
+ service = settings;
29279
+ const health = describeSettingsHealth(settings, Config);
29280
+ if (health.settings === "live" && !health.liveSchema) ctx.logger.warn("dsh-image-gen: the loaded schema lacks volatile fields required by this DSH settings service. Install @deepseek-ai/schemastery >=3.18.4 <4 in the plugin profile and check which copy the plugin resolves; settings cannot be saved with this schema.");
29281
+ if (typeof settings.installSection === "function") settings.installSection(ctx, IMAGE_GENERATION_NAMESPACE, Config, config, hooks);
29282
+ return () => {
29283
+ service = void 0;
29284
+ };
28874
29285
  });
29286
+ return () => describeSettingsHealth(service, Config);
28875
29287
  }
28876
29288
  //#endregion
28877
29289
  export { CANVAS_STATE_ROUTE, Config, DELETE_ROUTE, IMAGE_ROUTE, IMPORT_ROUTE, INSPIRATION_ROUTE, SAVE_WORKSPACE_ROUTE, STUDIO_ROUTE, TEST_CONNECTION_ROUTE, apply, imageAttachmentFromMeta, inject, name };