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:
+182
-19
@@ -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} 处参数或端口`);
|
||||
|
||||
Reference in New Issue
Block a user