Add Nano Banana 2.1 and preserve image workflow values

This commit is contained in:
Jony
2026-10-07 13:33:40 +08:00
parent 10a8700589
commit 5212a59047
18 changed files with 480 additions and 295 deletions
+156 -7
View File
@@ -88,6 +88,7 @@ class Element {
append(...items) { this.children.push(...items); }
prepend(...items) { this.children.unshift(...items); }
replaceChildren(...items) { this.children = [...items]; }
contains(element) { return this === element || this.children.some(child => child.contains?.(element)); }
addEventListener(type, listener) { this.listeners.set(type, listener); }
setAttribute(name, value) { this[name] = value; }
dispatch(type, event = { stopPropagation() {} }) { return this.listeners.get(type)?.(event); }
@@ -231,6 +232,9 @@ vm.runInContext(source, context, { filename: sourcePath.pathname });
}
const setStatus = vm.runInContext("setStatus", context);
const buildPanel = vm.runInContext("buildPanel", context);
const restorePanelFromWidgets = vm.runInContext("restorePanelFromWidgets", context);
const serializeGeneratorWidgets = vm.runInContext("serializeGeneratorWidgets", context);
const makeDropdown = vm.runInContext("makeDropdown", context);
const isGeneratedSeedControl = vm.runInContext("isGeneratedSeedControl", context);
const hideBackendWidgets = vm.runInContext("hideBackendWidgets", context);
@@ -372,6 +376,72 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) {
assert.equal(unrelatedControl.hidden, undefined);
}
{
const names = [
"prompt", "模型", "模型线路", "思考等级", "分辨率", "宽高比", "生图数量", "seed",
"参考图清单", "质量", "输出格式", "蒙版清单", "缩放图片", "背景", "批量出图",
"批量模式", "模特图清单", "命名规则", "filename_prefix", "格式", "保存位置", "在线搜索", "图层拆分",
];
const values = [
"saved panel prompt", "Nano Banana 2.1", "专线", "高", "2K", "1:8", "4", 123,
"[]", "自动", "jpeg", "{}", "不缩放", "auto", false,
"一组搭配+多模特", "[]", "自定义前缀", "kept-prefix", "原始", "kept-location", "打开", false,
];
const widgets = names.map((name, index) => ({ name, value: values[index], options: {} }));
const node = {
comfyClass: "O1keyImageGenerator", widgets, size: [560, 1035], outputs: [],
addDOMWidget(name, type, element, options) {
const widget = { name, type, element, options };this.widgets.push(widget);return widget;
},
computeSize() { return [500, 1025]; },
setSize(size) { this.size = size; },
setDirtyCanvas() {},
};
buildPanel(node);
const panel = node._o1igPanel;
const count = node.widgets.length;
buildPanel(node);
assert.equal(node._o1igPanel, panel);
assert.equal(node.widgets.length, count);
assert.equal(panel.className, "o1ig-panel");
assert.equal(node.widgets.length, names.length + 1, "Keep one panel rather than appending native action rows");
assert.deepEqual(node.widgets.slice(0, names.length).map(widget => widget.name), names);
assert.equal(node._o1igPrompt.tagName, "TEXTAREA");
assert.equal(node._o1igGenerate.tagName, "BUTTON");
assert.equal(node._o1igGenerate.className, "o1ig-generate");
assert.equal(panel.children.at(-1), node._o1igGenerate, "Start generation stays at the bottom of the panel");
const promptWrap = panel.children.find(child => child.className === "o1ig-prompt-wrap");
assert.ok(promptWrap.children.includes(node._o1igPromptOptimize), "AI writing remains inside the prompt area");
const seedField = node._o1igToolbar.children.find(child => child.children[1]?.className === "o1ig-seed");
assert.equal(seedField.children[1].children[0], node._o1igSeed);
assert.equal(seedField.children[1].children[1].title, "随机种子");
assert.ok(node._o1igReferenceHeader.contains(node._o1igAdd));
assert.ok(node._o1igReferenceHeader.contains(node._o1igCanvasPick));
assert.equal(node._o1igRefs.children[0].className, "o1ig-empty-reference");
node._o1igBatchToggle.dispatch("click");
assert.equal(node._o1igBatchEnabled, true);
assert.equal(node._o1igModelAssets.classList.contains("visible"), true);
node._o1igBatchToggle.dispatch("click");
assert.equal(node._o1igBatchEnabled, false);
const computeSize = widgets[0].computeSize;
widgets[0].options = {};widgets[0].hidden = false;
restorePanelFromWidgets(node);
assert.equal(widgets[0].options.hidden, true, "Keep backend fields hidden after a renderer switch");
assert.equal(widgets[0].computeSize, computeSize);
assert.equal(node._o1igModel.value, "Nano Banana 2.1");
assert.equal(node._o1igSeed.value, "123");
assert.equal(node._o1igFilenamePrefix.value, "kept-prefix");
assert.equal(node._o1igSaveLocation.value, "kept-location");
const saved = {};serializeGeneratorWidgets(node, saved);
assert.equal(saved.widgets_values.length, names.length);
assert.equal(saved.widgets_values[7], 123);
assert.equal(saved.widgets_values[18], "kept-prefix");
assert.equal(saved.widgets_values[20], "kept-location");
const panelCss = source.slice(source.indexOf("const CSS"), source.indexOf(".o1igs-progress-host"));
assert.doesNotMatch(panelCss, /#[0-9a-f]{3,8}\b|rgba?\(/i, "Use ComfyUI theme colours for every panel control and button");
assert.doesNotMatch(source, /function nativeAction|function bindNativeWidget|_o1igNativeWidgetsReady/);
}
{
const linkId = 8800;
const generator = {
@@ -961,6 +1031,7 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) {
styled: button.classList.contains("has-description"),
}));
assert.deepEqual(JSON.parse(JSON.stringify(descriptions)), [
{ model: "Nano Banana 2.1", description: "快速,批量", styled: true },
{ model: "Nano Banana 2", description: "快速,批量", styled: true },
{ model: "Nano Banana Pro", description: "高质量资产", styled: true },
{ model: "GPT Image 2", description: "高质量,编辑", styled: true },
@@ -1119,6 +1190,18 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) {
assert.equal(node._o1igSaveFormatField.style.display, "");
assert.equal(node._o1igResizeWarning.classList.contains("visible"), true);
node._o1igModel.value = "Nano Banana 2.1";
syncModelOptions(node);
assert.deepEqual(
JSON.parse(JSON.stringify(node._o1igResolution._o1igOptions.map(option => option.value))),
["智能", "1K", "2K", "4K"],
);
assert.equal(node._o1igRatio._o1igOptions.some(option => option.value === "1:8"), true);
assert.equal(node._o1igThinkingField.style.display, "");
assert.equal(node._o1igOnlineSearchField.style.display, "");
assert.equal(node._o1igSaveFormatField.style.display, "");
assert.equal(widgets.find((widget) => widget.name === "模型").value, "Nano Banana 2.1");
node._o1igModel.value = "Nano Banana 2 Lite";
syncModelOptions(node);
assert.equal(node._o1igResolution._o1igOptions.some((option) => option.value === "512"), true);
@@ -2702,7 +2785,7 @@ assert.doesNotMatch(savePanelSource, /addDOMWidget/);
assert.doesNotMatch(savePanelSource, /prefixWidget\.hidden = true/);
assert.doesNotMatch(source, /installNativeMinimumSize\(nodeType, SAVE_NODE_LAYOUT_SIZE\)/);
assert.match(source, /lucide--download.*lucide--refresh-cw/);
assert.match(source, /font-size:12px;font-weight:500;line-height:1\.4;letter-spacing:\.035em/);
assert.match(source, /--o1ig-surface:var\(--component-node-widget-background,var\(--comfy-input-bg\)\)/);
assert.match(source, /o1ig-select-caret svg\{display:block;width:12px;height:12px/);
assert.match(source, /const GENERATOR_DEFAULT_SIZE = \[560, 1035\]/);
assert.doesNotMatch(source, /o1key-save-custom-prefix/);
@@ -2717,7 +2800,7 @@ assert.match(source, /delete nodeData\.input\.optional\.external_prompt/);
assert.doesNotMatch(source, /app\.queuePrompt\(0, 1, \[saveNode\.id\]\)/);
assert.match(source, /\.o1ig-refs\{[\s\S]*?flex:0 0 109px[\s\S]*?min-height:109px/);
assert.match(source, /\.o1ig-thumb\{[\s\S]*?flex:0 0 102px;height:102px/);
assert.match(source, /\.o1ig-thumb img\{[\s\S]*?object-fit:contain;background:#111/);
assert.match(source, /\.o1ig-thumb img\{[\s\S]*?object-fit:contain;background:var\(--o1ig-surface\)/);
assert.match(source, /referenceActions\.append\(add, canvasPick\)/);
assert.match(source, /modelActions\.append\(modelAdd, modelCanvasPick\)/);
assert.match(source, /window\.o1keyCanvasImagePicker = Object\.freeze/);
@@ -2732,16 +2815,16 @@ assert.match(source, /\.o1ig-thumb\.o1ig-dragging::before\{[\s\S]*?content:"移
assert.match(source, /\.o1ig-refs\.o1ig-reordering\{/);
assert.match(source, /\.o1ig-thumb\.o1ig-drop-before\{transform:translateX\(7px\)/);
assert.match(source, /\.o1ig-empty-reference:hover,\.o1ig-empty-reference\.drag\{/);
assert.match(source, /\.o1ig-toolbar\{[^\n]*grid-template-columns:repeat\(2,minmax\(0,1fr\)\)/);
assert.match(source, /\.o1ig-field\{display:flex;flex-direction:column/);
assert.match(source, /\.o1ig-toolbar\{[^\n]*grid-template-columns:minmax\(0,1fr\)/);
assert.match(source, /\.o1ig-field\{display:grid;grid-template-columns:104px minmax\(0,1fr\)/);
assert.match(source, /makePanelSectionTitle\("画面描述"\)/);
assert.match(source, /makePanelSectionTitle\("生成参数"\)/);
assert.match(source, /makePanelSectionTitle\("保存设置"\)/);
assert.match(source, /filenamePrefixField\.classList\.add\("o1ig-field-wide"\)/);
assert.match(source, /saveLocationField\.classList\.add\("o1ig-field-wide"\)/);
assert.match(source, /o1ig-resize-warning\{display:none;color:#d5aa62/);
assert.match(source, /o1ig-resize-warning\{display:none;grid-column:2;color:var\(--o1ig-muted\)/);
assert.match(source, /o1ig-resize-warning\.visible\{display:block/);
assert.match(source, /o1ig-seed\{[\s\S]*grid-template-columns:minmax\(0,1fr\) 34px;gap:0/);
assert.match(source, /o1ig-seed\{[\s\S]*grid-template-columns:minmax\(0,1fr\) 28px;gap:0/);
assert.match(source, /o1ig-seed button\{[\s\S]*border-left:1px solid/);
assert.match(source, /className = "o1ig-prompt-optimize"/);
assert.match(source, /className = "o1ig-prompt-optimize-status"/);
@@ -2895,7 +2978,7 @@ assert.match(source, /jobPayload\.google_search = true/);
assert.match(source, /jobPayload\.layer_decomposition = true/);
assert.match(source, /if \(layerDecomposition\) \{\s*layerSaveNode = acquireLayerSaveNodeForBatch\(node, saveNode\);/);
assert.match(source, /layerDecomposition,\s*retrySlotIndex,/);
assert.match(source, /node\._o1igModel\.value === "Nano Banana 2"/);
assert.match(source, /\["Nano Banana 2\.1", "Nano Banana 2"\]\.includes\(node\._o1igModel\.value\)/);
assert.match(source, /node\._o1igOnlineSearch\.value === "打开"/);
assert.match(source, /batch_enabled: retryTask \? false : Boolean\(node\._o1igBatchEnabled\)/);
assert.match(source, /model_references: retryTask \|\| node\._o1igBatchMode\.value === BATCH_MODE_SINGLE_REFERENCES/);
@@ -2969,6 +3052,27 @@ assert.match(migrationSource, /原生 seed 参数/);
migrationContext,
);
const legacyRedCastValues = [1.0, 8.0, 0.1, "", 62.0, 15.0];
const nativeValues = [
"legacy native prompt", "Nano Banana 2.1", "专线", "高", "2K", "1:8", "4", 678803244,
"[]", "最高", "png", "{}", "智能缩放", "transparent", false,
"一组搭配+多模特", "[]", "自定义前缀", "legacy-prefix", "原始", "relative-save", "打开", false,
];
const oldPanelValues = [...nativeValues];
oldPanelValues.splice(8, 0, "randomize");
oldPanelValues.push("");
const nativeGraph = {
nodes: [{ type: "O1keyImageGenerator", widgets_values: oldPanelValues }],
definitions: { subgraphs: [{
nodes: [{ type: "O1keyImageGenerator", widgets_values: [...oldPanelValues] }],
}] },
};
migrationExtension.beforeConfigureGraph(nativeGraph);
assert.deepEqual(nativeGraph.nodes[0].widgets_values, nativeValues);
assert.deepEqual(nativeGraph.definitions.subgraphs[0].nodes[0].widgets_values, nativeValues);
migrationExtension.beforeConfigureGraph(nativeGraph);
assert.deepEqual(nativeGraph.nodes[0].widgets_values, nativeValues);
assert.deepEqual(nativeGraph.definitions.subgraphs[0].nodes[0].widgets_values, nativeValues);
const legacyRedCastGraph = {
nodes: [{ type: "O1keyAutoRedCast", widgets_values: legacyRedCastValues }],
};
@@ -3182,6 +3286,22 @@ assert.match(migrationSource, /原生 seed 参数/);
"不缩放", "原始", 95, "和原始图片名保持一致", "", 0,
]);
for (const [type, original] of [
["NanoBanana", legacyNanoValues],
["BatchNanoBananaPro", legacyBatchNanoValues],
["O1keyImageGenerator", movedGeneratorValues],
]) {
for (const model of ["Nano Banana 2.1", "Nano Banana 2"]) {
const values = [...original];
values[1] = model;
const expected = [...values];
const graph = { nodes: [{ type, widgets_values: values }] };
migrationExtension.beforeConfigureGraph(graph);
migrationExtension.beforeConfigureGraph(graph);
assert.deepEqual(values, expected);
}
}
const stringQualityValues = [
"prompt", "Nano Banana 2", "畅速", "高", "2K", "1:1",
"1个路径", "D:\\images", "关闭", 0, "JPEG", "95",
@@ -4033,3 +4153,32 @@ assert.match(migrationSource, /原生 seed 参数/);
}
console.log("o1key image generator frontend tests passed");
const nanoThinkingSource = fs.readFileSync(new URL("../web/js/nanoBananaThinkingLevel.js", import.meta.url), "utf8");
{
let thinkingExtension;
vm.runInNewContext(nanoThinkingSource.replace(/^import .*;\s*$/gm, ""), {
app: { registerExtension(extension) { thinkingExtension = extension; } },
requestAnimationFrame(callback) { callback(); },
});
for (const comfyClass of ["NanoBanana", "BatchNanoBananaPro"]) {
const model = { name: "模型", value: "Nano Banana 2.1", callback() { return "model-changed"; } };
const computeSize = () => [100, 20];
const thinking = { name: "思考等级", value: "高", computeSize };
const node = { comfyClass, widgets: [model, thinking], setDirtyCanvas() {} };
thinkingExtension.nodeCreated(node);
assert.equal(thinking.hidden, false);
assert.equal(thinking.options.hidden, false);
for (const value of ["Nano Banana Pro", "Nano Banana 2 Lite", "Nano Banana 2", "Nano Banana 2.1"]) {
model.value = value;
assert.equal(model.callback(), "model-changed");
assert.equal(thinking.hidden, !["Nano Banana 2", "Nano Banana 2.1"].includes(value));
assert.equal(thinking.value, "高");
}
assert.equal(thinking.computeSize, computeSize);
const callback = model.callback;
thinkingExtension.loadedGraphNode(node);
assert.equal(model.callback, callback);
}
}