Add MJ image node, GIF save, and Kling/image generator updates

Ship o1key MJ图片生成 with content/style refs and prompt flags, save-GIF with preview, Kling 4.0 helpers, plus GPT/unified image node polish and docs.
This commit is contained in:
Jony
2026-11-09 09:11:12 +08:00
parent ff1cf830fa
commit a181cc1768
40 changed files with 6711 additions and 675 deletions
+240
View File
@@ -0,0 +1,240 @@
import { app } from "../../../scripts/app.js";
import { api } from "../../../scripts/api.js";
/**
* 「保存 GIF」emits custom UI key ``o1key_gif`` (NOT ``images``).
*
* ComfyUI core ``unsafeUpdatePreviews`` only hydrates canvas / video
* previews from ``getNodeOutputs(node).images``. Feeding SavedImages made
* core stack ``$$canvas-image-preview`` (static frame + "W x H") under our
* DOM <img>. Stripping ``message.images`` in onExecuted does not clear the
* live ``app.nodeOutputs`` entry, so the canvas widget kept coming back.
*
* Fix: Python emits ``o1key_gif`` only; this extension mounts one <img>.
* gpt image intentionally emits no GIF node preview.
*/
const NODE_TYPES = new Set(["O1keySaveGIF"]);
const WIDGET_NAME = "o1key_gif_preview_widget";
const UI_KEY = "o1key_gif";
const CANVAS_PREVIEW_NAME = "$$canvas-image-preview";
const EXT_NAME = "comfyui_o1key.gifPreview";
function isGifEntry(entry) {
const name = String(entry?.filename || entry?.name || "");
return /\.gif$/i.test(name);
}
function buildViewUrl(entry) {
if (!entry) return "";
const filename = String(entry.filename || entry.name || "");
if (!filename) return "";
const params = new URLSearchParams();
params.set("filename", filename);
const subfolder = String(entry.subfolder || "");
if (subfolder) params.set("subfolder", subfolder);
params.set("type", String(entry.type || "output"));
return api.apiURL(`/view?${params.toString()}`);
}
function pickGifEntry(message) {
const custom = Array.isArray(message?.[UI_KEY]) ? message[UI_KEY] : [];
const fromCustom = custom.find(isGifEntry) || custom[0];
if (fromCustom) return fromCustom;
// Legacy SavedImages payloads (pre-custom-key) — still show one <img>,
// but clear live nodeOutputs.images so core cannot remount IMAGE_PREVIEW.
const images = Array.isArray(message?.images) ? message.images : [];
return images.find(isGifEntry) || null;
}
/**
* Remove core ``images`` from the LIVE outputs store for this node.
* History snapshots already copied the payload; mutating the live entry
* only stops ``updatePreviews`` from driving ImagePreviewWidget.
*/
function clearLiveCoreImages(node) {
const store = app.nodeOutputs;
if (!store || node?.id == null) return;
const idKeys = new Set([String(node.id), node.id]);
for (const key of Object.keys(store)) {
if (!idKeys.has(key) && !idKeys.has(String(key))) {
// Locator ids are usually the plain node id string; also match
// trailing ":id" / "id" forms used by execution-id helpers.
const asStr = String(key);
if (![...idKeys].some((id) => asStr === String(id) || asStr.endsWith(`:${id}`))) {
continue;
}
}
const entry = store[key];
if (!entry || typeof entry !== "object") continue;
if ("images" in entry) delete entry.images;
if ("animated" in entry) delete entry.animated;
}
}
function removeCoreCanvasPreview(node) {
node.imgs = undefined;
node.images = undefined;
node.imageIndex = undefined;
node.overIndex = undefined;
node.animatedImages = undefined;
if (node.videoContainer) {
try {
node.videoContainer.replaceChildren();
} catch (_err) {
/* ignore */
}
node.videoContainer = undefined;
}
if (!Array.isArray(node.widgets)) return;
for (let i = node.widgets.length - 1; i >= 0; i--) {
const widget = node.widgets[i];
if (!widget) continue;
const name = String(widget.name || "");
const type = String(widget.type || "");
const isOurs = name === WIDGET_NAME;
const isCore =
!isOurs &&
(name === CANVAS_PREVIEW_NAME ||
type === "IMAGE_PREVIEW" ||
type === "image" ||
type === "imagecompare" ||
type === "video" ||
/canvas-image-preview/i.test(name));
if (!isCore) continue;
try {
widget.onRemove?.();
} catch (_err) {
/* ignore */
}
node.widgets.splice(i, 1);
}
}
function ensureGifWidget(node) {
if (node._o1keyGifContainer && node.widgets?.some((w) => w.name === WIDGET_NAME)) {
return node._o1keyGifContainer;
}
const container = document.createElement("div");
container.style.cssText =
"width:100%;display:flex;flex-direction:column;align-items:center;" +
"padding:4px;box-sizing:border-box;";
const img = document.createElement("img");
img.alt = "GIF preview";
img.style.cssText =
"width:100%;display:block;border-radius:4px;background:#111;" +
"object-fit:contain;max-height:480px;";
const label = document.createElement("div");
label.style.cssText =
"font-size:10px;color:#aaa;margin-top:2px;text-align:center;word-break:break-all;";
container.appendChild(img);
container.appendChild(label);
node._o1keyGifContainer = container;
node._o1keyGifImg = img;
node._o1keyGifLabel = label;
if (!node.widgets?.some((w) => w.name === WIDGET_NAME)) {
const widget = node.addDOMWidget(WIDGET_NAME, "img", container, {
serialize: false,
hideOnZoom: false,
});
widget.serializeValue = () => undefined;
widget.computeSize = function (width) {
const w = width ?? node.size?.[0] ?? 320;
const naturalW = img.naturalWidth || 0;
const naturalH = img.naturalHeight || 0;
if (naturalW > 0 && naturalH > 0) {
const innerW = Math.max(w - 16, 10);
const h = Math.round((innerW * naturalH) / naturalW);
return [w, Math.min(h, 480) + 28];
}
return [w, 260];
};
}
img.addEventListener("load", () => {
const w = Math.max(node.size?.[0] || 0, 320);
const naturalW = img.naturalWidth || 1;
const naturalH = img.naturalHeight || 1;
const innerW = Math.max(w - 16, 10);
const h = Math.min(Math.round((innerW * naturalH) / naturalW), 480) + 70;
node.setSize([w, Math.max(node.size?.[1] || 0, h)]);
node.setDirtyCanvas(true, true);
});
return container;
}
function showGifPreview(node, entry) {
const url = buildViewUrl(entry);
if (!url) return;
clearLiveCoreImages(node);
removeCoreCanvasPreview(node);
ensureGifWidget(node);
if (node._o1keyGifImg) {
node._o1keyGifImg.src = url;
}
if (node._o1keyGifLabel) {
node._o1keyGifLabel.textContent = String(entry.filename || entry.name || "");
}
// Keep heuristics sane, but never leave imgs populated for IMAGE_PREVIEW.
node.previewMediaType = "image";
removeCoreCanvasPreview(node);
node.setDirtyCanvas(true, true);
}
app.registerExtension({
name: EXT_NAME,
async beforeRegisterNodeDef(nodeType, nodeData) {
if (!NODE_TYPES.has(nodeData?.name)) return;
const origOnExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function (message) {
const gif = pickGifEntry(message);
// Always strip live core image previews for this node type —
// new payloads have no ``images``; legacy ones must be cleared
// from app.nodeOutputs so updatePreviews cannot remount.
clearLiveCoreImages(this);
if (gif) {
if (origOnExecuted) {
const rest = Object.assign({}, message);
delete rest.images;
delete rest.animated;
origOnExecuted.call(this, rest);
}
showGifPreview(this, gif);
return;
}
if (origOnExecuted) {
origOnExecuted.apply(this, arguments);
}
};
},
/**
* History / queue restore updates nodeOutputs then may redraw before
* onExecuted; clear any stale ``images`` left from older SavedImages runs.
*/
async nodeCreated(node) {
if (!NODE_TYPES.has(node?.comfyClass || node?.type)) return;
// Light one-shot: if outputs already present without our key, ignore.
// Real preview is applied in onExecuted (also fired on history load).
clearLiveCoreImages(node);
},
});
+100 -7
View File
@@ -4,19 +4,66 @@ const NODE_TYPES = new Set(["O1keyGPTImage", "O1keyGPTImageBatch"]);
const BASE_QUALITY_OPTIONS = ["高", "中", "低", "自动"];
const GPT_IMAGE_25_QUALITY_OPTIONS = [...BASE_QUALITY_OPTIONS, "超高", "最高"];
const QUALITY_FALLBACK = "自动";
const RASTER_FORMATS = ["png", "jpeg", "webp"];
const FORMAT_26 = [...RASTER_FORMATS, "svg", "gif"];
const BATCH_RASTER = ["原始", "JPEG", "PNG", "WebP"];
const BATCH_26 = [...BATCH_RASTER, "SVG", "GIF"];
function findWidget(node, name) {
return node.widgets?.find((widget) => widget.name === name);
}
function setWidgetHidden(widget, hidden) {
if (!widget) return;
if (!("__o1keyOriginalComputeSize" in widget)) {
widget.__o1keyOriginalComputeSize = widget.computeSize;
}
widget.hidden = hidden;
widget.options ??= {};
widget.options.hidden = hidden;
if (hidden) widget.computeSize = () => [0, -4];
else if (widget.__o1keyOriginalComputeSize) {
widget.computeSize = widget.__o1keyOriginalComputeSize;
} else delete widget.computeSize;
}
function hasReferenceOrMask(node) {
if (findWidget(node, "遮罩")?.value) return true;
const widgets = node.widgets || [];
for (const widget of widgets) {
if (/^参考图/.test(widget.name) && widget.value) return true;
}
// Connected inputs on modern nodes are not always mirrored into widget values.
const inputs = node.inputs || [];
for (const input of inputs) {
if (!input || input.link == null) continue;
if (input.name === "遮罩" || /^参考图/.test(input.name) || input.name === "参考图组") {
return true;
}
}
return false;
}
function normalizeStandaloneFormat(value) {
return String(value || "png").trim().toLowerCase();
}
function normalizeBatchFormat(value) {
const raw = String(value || "原始");
if (["svg", "SVG"].includes(raw)) return "SVG";
if (["gif", "GIF"].includes(raw)) return "GIF";
return raw;
}
function updateQualityOptions(node) {
const modelWidget = findWidget(node, "模型");
const qualityWidget = findWidget(node, "质量");
if (!modelWidget || !qualityWidget) return;
const supports25Quality =
typeof modelWidget.value === "string" && modelWidget.value.startsWith("gpt-image-2.5-");
const allowedOptions = supports25Quality ? GPT_IMAGE_25_QUALITY_OPTIONS : BASE_QUALITY_OPTIONS;
const model = String(modelWidget.value || "");
const supportsExtendedQuality = /^gpt-image-2\.[56]-/.test(model);
const is26 = /^gpt-image-2\.6-/.test(model);
const allowedOptions = supportsExtendedQuality ? GPT_IMAGE_25_QUALITY_OPTIONS : BASE_QUALITY_OPTIONS;
qualityWidget.options ??= {};
qualityWidget.options.values = [...allowedOptions];
@@ -25,6 +72,33 @@ function updateQualityOptions(node) {
qualityWidget.callback?.(QUALITY_FALLBACK);
}
setWidgetHidden(findWidget(node, "复杂度"), !is26);
const formatWidget = findWidget(node, "输出格式") || findWidget(node, "图片输出格式");
const isBatch = (node.comfyClass || node.type) === "O1keyGPTImageBatch";
if (formatWidget) {
const blocked = hasReferenceOrMask(node);
let values = isBatch
? (is26 ? BATCH_26 : BATCH_RASTER)
: (is26 ? FORMAT_26 : RASTER_FORMATS);
if (is26 && blocked) {
values = values.filter((value) => !/^(svg|gif|SVG|GIF)$/i.test(value));
}
formatWidget.options ??= {};
formatWidget.options.values = [...values];
if (!values.includes(formatWidget.value)) {
formatWidget.value = isBatch ? "PNG" : "png";
formatWidget.callback?.(formatWidget.value);
}
}
const formatValue = isBatch
? normalizeBatchFormat(formatWidget?.value)
: normalizeStandaloneFormat(formatWidget?.value);
const showFrames = is26 && (formatValue === "gif" || formatValue === "GIF");
setWidgetHidden(findWidget(node, "帧数"), !showFrames);
setWidgetHidden(findWidget(node, "帧时长ms"), !showFrames);
node.setDirtyCanvas?.(true, true);
}
@@ -35,10 +109,29 @@ function guardNode(node) {
if (!modelWidget || !qualityWidget) return;
node.__o1keyGptImageQuality = true;
const originalModelCallback = modelWidget.callback;
modelWidget.callback = function () {
const result = originalModelCallback?.apply(this, arguments);
updateQualityOptions(node);
const watch = ["模型", "输出格式", "图片输出格式", "遮罩"];
for (const name of watch) {
const widget = findWidget(node, name);
if (!widget) continue;
const original = widget.callback;
widget.callback = function () {
const result = original?.apply(this, arguments);
updateQualityOptions(node);
return result;
};
}
const originalOnConfigure = node.onConfigure;
node.onConfigure = function () {
const result = originalOnConfigure?.apply(this, arguments);
updateQualityOptions(this);
return result;
};
const originalOnConnectionsChange = node.onConnectionsChange;
node.onConnectionsChange = function () {
const result = originalOnConnectionsChange?.apply(this, arguments);
updateQualityOptions(this);
return result;
};
+182 -19
View File
@@ -13,9 +13,11 @@ const GPT_IMAGE_ROUTE_ALIASES = new Map([
]);
const GPT_IMAGE_NODE_TYPES = new Set(["O1keyGPTImage", "O1keyGPTImageBatch"]);
const GPT_IMAGE_MODELS = new Set([
"gpt-image-2",
"gpt-image-2.6-sunburst",
"gpt-image-2.6-flare",
"gpt-image-2.5-sunburst",
"gpt-image-2.5-flare",
"gpt-image-2",
]);
const GPT_IMAGE_ROUTES = new Set(["畅速", "直连", "专线"]);
const GPT_IMAGE_RESIZE_MODES = new Set(["不缩放", "智能缩放"]);
@@ -23,6 +25,35 @@ const GPT_IMAGE_COLOR_CORRECTION_MODES = new Set(["不纠正", "智能纠正"]);
const UNIFIED_COLOR_CORRECTION_MODES = new Set(["不纠正", "智能纠正"]);
const GPT_IMAGE_BACKGROUNDS = new Set(["auto", "transparent", "opaque"]);
const GPT_IMAGE_MODERATION_MODES = new Set(["自动", "低"]);
const GPT_IMAGE_COMPLEXITY_VALUES = new Set(["low", "medium", "high", "低", "中", "高"]);
const GPT_IMAGE_COMPLEXITY_TO_LABEL = Object.freeze({
low: "低",
medium: "中",
high: "高",
低: "低",
中: "中",
高: "高",
});
function normalizeGptImageComplexityLabel(value) {
if (value == null) return "高";
return GPT_IMAGE_COMPLEXITY_TO_LABEL[value] ?? GPT_IMAGE_COMPLEXITY_TO_LABEL[String(value).toLowerCase()] ?? "高";
}
function placeGptImageComplexity(wv, complexity) {
// Returns true when widgets_values changed.
if (GPT_IMAGE_COMPLEXITY_VALUES.has(wv[3])) {
const normalized = normalizeGptImageComplexityLabel(wv[3]);
if (wv[3] !== normalized) {
wv[3] = normalized;
return true;
}
return false;
}
const label = normalizeGptImageComplexityLabel(complexity === undefined ? "高" : complexity);
// Old layouts stored complexity on the tail; new schema keeps it after 模型线路.
wv.splice(3, 0, label);
return true;
}
const GPT_IMAGE_CONTROL_AFTER_GENERATE = new Set(["fixed", "increment", "decrement", "randomize"]);
const GPT_IMAGE_BATCH_OUTPUT_FORMATS = new Set(["原始", "JPEG", "PNG", "WebP"]);
const GPT_IMAGE_BATCH_NAMING_RULES = new Set(["和原始图片名保持一致", "自然数字"]);
@@ -33,12 +64,25 @@ function findLastIndex(values, predicate) {
return -1;
}
function batchGPTImagePathCountIndex(wv) {
// Current schema inserts 复杂度 after 模型线路, shifting "N个路径" from 6 -> 7.
if (/^([1-5])个路径$/.test(String(wv[7] ?? "")) && GPT_IMAGE_COMPLEXITY_VALUES.has(wv[3])) {
return 7;
}
if (/^([1-5])个路径$/.test(String(wv[6] ?? ""))) {
return 6;
}
return -1;
}
function batchGPTImageRandomSelectionIndex(wv) {
const match = /^([1-5])个路径$/.exec(String(wv[6] ?? ""));
const pathCountIndex = batchGPTImagePathCountIndex(wv);
if (pathCountIndex < 0) return -1;
const match = /^([1-5])个路径$/.exec(String(wv[pathCountIndex] ?? ""));
if (!match) return -1;
const pathCount = Number(match[1]);
const pairingWidgetCount = pathCount >= 2 ? 1 : 0;
return 7 + pathCount + pairingWidgetCount;
return pathCountIndex + 1 + pathCount + pairingWidgetCount;
}
function batchGPTImageConcurrencyIndex(wv) {
@@ -113,6 +157,10 @@ function findLegacySeedanceAssetWidgets(wv) {
const NANO_BANANA_MODELS = new Set([
"Nano Banana Pro", "Nano Banana 2 Lite", "Nano Banana 2.1", "Nano Banana 2", "Nano Banana",
]);
const RETIRED_UNIFIED_IMAGE_MODELS = new Map([
["Nano Banana 2 Lite", "Nano Banana 2"],
["Nano Banana", "Nano Banana 2"],
]);
const NANO_BANANA_ROUTE_ALIASES = new Map([
["特价", "畅速"],
["官方", "专线"],
@@ -143,13 +191,18 @@ function isCurrentGPTImageBatchWidgetLayout(wv) {
const resizeIndex = namingIndex + 2;
const seedIndex = namingIndex + 3;
const randomSelectionIndex = batchGPTImageRandomSelectionIndex(wv);
const hasFrameTail = (
Number.isInteger(wv[seedIndex + 1])
&& Number.isInteger(wv[seedIndex + 2])
&& seedIndex + 2 === wv.length - 1
);
return GPT_IMAGE_BATCH_OUTPUT_FORMATS.has(wv[formatIndex])
&& GPT_IMAGE_BACKGROUNDS.has(wv[backgroundIndex])
&& typeof wv[savePathIndex] === "string"
&& GPT_IMAGE_RESIZE_MODES.has(wv[resizeIndex])
&& Number.isInteger(wv[seedIndex])
&& formatIndex === randomSelectionIndex
&& seedIndex === wv.length - 1;
&& (seedIndex === wv.length - 1 || hasFrameTail);
}
function isGPTImageBatchWidgetLayoutWithRandomSelection(wv) {
@@ -238,6 +291,16 @@ const MIGRATIONS = [
&& typeof wv[9] === "string" && /^\s*\[/.test(wv[9]),
apply: (wv) => wv.splice(8, 1),
},
{
type: "O1keyImageGenerator",
note: "将统一图片生成节点已下线的 Nano Banana 模型迁移到 Nano Banana 2",
when: (wv) => RETIRED_UNIFIED_IMAGE_MODELS.has(wv[1]),
apply: (wv) => {
const retiredModel = wv[1];
wv[1] = RETIRED_UNIFIED_IMAGE_MODELS.get(retiredModel);
if (retiredModel === "Nano Banana 2 Lite" && wv[4] === "512") wv[4] = "1K";
},
},
{
type: "O1keyAutoRedCast",
note: "为旧版自动红偏校正补齐末尾 seed 参数",
@@ -320,7 +383,7 @@ const MIGRATIONS = [
note: "为统一图片生成节点补齐可选批量出图字段",
when: (wv) => wv.length >= 15 && wv.length < 18,
apply: (wv) => {
const appendedDefaults = [false, "一组搭配+多模特", "[]"];
const appendedDefaults = [false, "整组素材→多个目标", "[]"];
while (wv.length < 18) wv.push(appendedDefaults[wv.length - 15]);
},
},
@@ -1380,6 +1443,8 @@ function migrateUnifiedSaveSettings(container) {
const nodes = Array.isArray(container?.nodes) ? container.nodes : [];
const nodesById = new Map(nodes.map((node) => [String(node?.id), node]));
const defaults = ["自定义前缀", "o1key", "原始", ""];
// 保存位置 是这份补齐序列的终点;老存档若还带着已停用的内容审查强度,就要多补一格。
const saveSettingsTarget = (values) => (GPT_IMAGE_MODERATION_MODES.has(values[14]) ? 22 : 21);
let migrated = 0;
for (const saveNode of nodes.filter((node) => node?.type === "O1keyImageSave")) {
@@ -1395,7 +1460,7 @@ function migrateUnifiedSaveSettings(container) {
if (generatorValues.length === 18) {
generatorValues.push(legacy[3], legacy[0], legacy[1], legacy[2]);
} else {
while (generatorValues.length < 22) {
while (generatorValues.length < saveSettingsTarget(generatorValues)) {
generatorValues.push(defaults[generatorValues.length - 18]);
}
}
@@ -1407,34 +1472,73 @@ function migrateUnifiedSaveSettings(container) {
const values = generator?.widgets_values;
if (!Array.isArray(values) || values.length < 18) continue;
const before = values.length;
while (values.length < 22) values.push(defaults[values.length - 18]);
while (values.length < saveSettingsTarget(values)) values.push(defaults[values.length - 18]);
if (values.length !== before) migrated++;
}
return migrated;
}
function migrateUnifiedOnlineSearch(container) {
const RETIRED_ONLINE_SEARCH_VALUES = new Set(["关闭", "打开"]);
// 批量模式 used model-centric labels before the industry-neutral rename.
const RETIRED_BATCH_MODE_LABELS = new Map([
["一组搭配+多模特", "整组素材→多个目标"],
["全部搭配×全部模特", "每张素材×每张目标"],
["单图素材批量", "每张素材单独出图"],
]);
function migrateUnifiedBatchModeLabels(container) {
const nodes = Array.isArray(container?.nodes) ? container.nodes : [];
let migrated = 0;
for (const node of nodes.filter((item) => item?.type === "O1keyImageGenerator")) {
const values = node?.widgets_values;
if (!Array.isArray(values)) continue;
const expectedLength = GPT_IMAGE_MODERATION_MODES.has(values[14]) ? 22 : 21;
if (values.length !== expectedLength) continue;
values.push("关闭");
// Match by label instead of index so the rewrite survives every array shape.
const index = values.findIndex((value) => RETIRED_BATCH_MODE_LABELS.has(value));
if (index < 0) continue;
values[index] = RETIRED_BATCH_MODE_LABELS.get(values[index]);
migrated++;
}
return migrated;
}
function migrateRetiredOnlineSearch(container) {
const nodes = Array.isArray(container?.nodes) ? container.nodes : [];
let migrated = 0;
for (const node of nodes.filter((item) => item?.type === "O1keyImageGenerator")) {
const values = node?.widgets_values;
if (!Array.isArray(values) || values.length < 23) continue;
// 在线搜索 sat between 保存位置 and 图层拆分; the layer flag and the complexity label
// right behind it identify the slot without trusting a fixed index.
// Index 20 is 保存位置 in the current schema, so only the slots after it can be the
// retired field. The layer flag right behind it pins the position down.
for (let index = 21; index < values.length - 1; index += 1) {
if (!RETIRED_ONLINE_SEARCH_VALUES.has(values[index])) continue;
if (typeof values[index + 1] !== "boolean") continue;
const next = values[index + 2];
const tailLike = next === undefined
|| GPT_IMAGE_COMPLEXITY_VALUES.has(next)
|| Number.isInteger(next);
if (!tailLike) continue;
values.splice(index, 1);
migrated++;
break;
}
}
return migrated;
}
function migrateUnifiedLayerDecomposition(container) {
const nodes = Array.isArray(container?.nodes) ? container.nodes : [];
let migrated = 0;
for (const node of nodes.filter((item) => item?.type === "O1keyImageGenerator")) {
const values = node?.widgets_values;
if (!Array.isArray(values)) continue;
const expectedLength = GPT_IMAGE_MODERATION_MODES.has(values[14]) ? 23 : 22;
const expectedLength = GPT_IMAGE_MODERATION_MODES.has(values[14]) ? 22 : 21;
if (values.length !== expectedLength) continue;
// A graph that already carries 图层拆分 ends on a boolean; only the pre-layers shape
// ends on 保存位置, so this keeps the rule idempotent.
if (typeof values.at(-1) === "boolean") continue;
values.push(false);
migrated++;
}
@@ -1469,6 +1573,51 @@ app.registerExtension({
migrated += migrateGrokVideoInputNames(node);
const wv = node?.widgets_values;
if (!Array.isArray(wv)) continue;
// GPT Image: peel append-only tails before legacy end-based rules.
// Current widget order: ..., 模型线路, 复杂度, 分辨率, ... seed, control?, 帧数?, 帧时长ms?
// Older graphs kept 复杂度 on the tail after seed/control; peel it and reinsert at index 3.
let frameDuration;
let frameCount;
let complexity;
let controlAfterGenerate;
if (GPT_IMAGE_NODE_TYPES.has(node.type)) {
const maybeDuration = wv.at(-1);
const maybeCount = wv.at(-2);
const maybeComplexity = wv.at(-3);
if (
Number.isInteger(maybeDuration)
&& Number.isInteger(maybeCount)
&& GPT_IMAGE_COMPLEXITY_VALUES.has(maybeComplexity)
) {
// Old tail: ..., complexity, frame_count, frame_duration_ms
frameDuration = wv.pop();
frameCount = wv.pop();
complexity = wv.pop();
} else if (
Number.isInteger(maybeDuration)
&& Number.isInteger(maybeCount)
) {
// New tail (complexity already mid-list): ..., control?/seed, frame_count, frame_duration_ms
frameDuration = wv.pop();
frameCount = wv.pop();
} else if (["low", "medium", "high"].includes(String(wv.at(-1)).toLowerCase())) {
// Old tails stored English complexity. Chinese 低 overlaps moderation — do not peel it.
complexity = wv.pop();
}
// Repair graphs already scrambled by the pre-fix migration:
// [..., seed, control, 智能缩放, auto, (complexity...)] → drop bogus resize/bg after control.
if (
GPT_IMAGE_CONTROL_AFTER_GENERATE.has(wv.at(-3))
&& GPT_IMAGE_RESIZE_MODES.has(wv.at(-2))
&& GPT_IMAGE_BACKGROUNDS.has(wv.at(-1))
) {
wv.splice(wv.length - 2, 2);
migrated++;
}
if (GPT_IMAGE_CONTROL_AFTER_GENERATE.has(wv.at(-1))) {
controlAfterGenerate = wv.pop();
}
}
for (const rule of MIGRATIONS) {
if (rule.type !== "*" && node.type !== rule.type) continue;
try {
@@ -1480,23 +1629,37 @@ app.registerExtension({
console.warn(`[o1key] 工作流迁移失败: ${rule.note}`, e);
}
}
if (controlAfterGenerate !== undefined) wv.push(controlAfterGenerate);
if (GPT_IMAGE_NODE_TYPES.has(node.type)) {
// Keep 复杂度 at index 3 (after 模型线路). Missing => default 高.
if (placeGptImageComplexity(wv, complexity)) migrated++;
} else if (complexity !== undefined) {
wv.push(complexity);
}
if (frameCount !== undefined) wv.push(frameCount);
if (frameDuration !== undefined) wv.push(frameDuration);
}
for (const container of collectGraphContainers(graphData)) {
migrated += migrateBatchNanoRandomInput(container);
migrated += migrateUnifiedExternalPromptInput(container);
migrated += migrateUnifiedSaveSettings(container);
migrated += migrateUnifiedOnlineSearch(container);
migrated += migrateUnifiedBatchModeLabels(container);
migrated += migrateUnifiedLayerDecomposition(container);
migrated += migrateUnifiedModeration(container);
for (const node of container?.nodes || []) {
const values = node?.widgets_values;
if (node?.type === "O1keyImageGenerator" && Array.isArray(values)
&& values.length === 24 && values[23] === ""
&& ["关闭", "打开"].includes(values[21]) && typeof values[22] === "boolean") {
values.pop(); // Retired non-serialized HTML panel value.
migrated++;
}
if (node?.type !== "O1keyImageGenerator" || !Array.isArray(values)) continue;
// A retired non-serialized HTML panel value can linger on the tail. Every real
// widget ends on a boolean or a number there (保存位置 also holds "" but always
// sits behind 格式), so an empty string on the tail is never a real value.
if (values.length < 22 || values.at(-1) !== "") continue;
const previous = values.at(-2);
if (typeof previous !== "boolean" && !Number.isInteger(previous)) continue;
values.pop();
migrated++;
}
// Runs last: the trailing-value repair above still relies on the old index.
migrated += migrateRetiredOnlineSearch(container);
}
if (migrated > 0) {
console.log(`[o1key] 工作流参数迁移:已修复 ${migrated} 处参数或端口`);
File diff suppressed because it is too large Load Diff