diff --git a/README.md b/README.md index a101f83..75445e8 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,8 @@ pip install -r requirements.txt --upgrade 「o1key 图片生成」的提示词仅在节点内的多行编辑框填写,不显示提示词 `STRING` 输入端口。旧工作流加载时会移除原有的外部提示词连线,保留节点内已保存的提示词;如原先完全依赖上游字符串,请在面板内补填提示词。 +参考图上传完成后,复制、粘贴节点或保存后重新加载工作流,会保留参考图顺序、批量目标图、蒙版和参数。图片清单引用当前 ComfyUI 的本地文件;复制后可独立调整清单。 + 模型列表新增 `GPT Image 2.5 Sunburst`(最新,高质量)和 `GPT Image 2.5 Flare`(快速,日常)。两者与 GPT Image 2 使用相同的「智能 / 1K / 2K / 4K」分辨率和「智能、1:1、3:2、2:3、4:3、3:4、16:9、9:16」宽高比;特价、优质、企业线路分别调用模型 ID 的 `-sp`、`-sd` 和无后缀版本。下文的 GPT Image 2 参数说明也适用于这两个 GPT Image 2.5 模型。 面板式图片生成节点统一支持 Nano Banana 系列、GPT Image 2 与 Seedream 5.0 Pro。提示词右下角使用带 `✨` 图标的「AI帮写」按钮;独立 Nano Banana 节点不再提供提示词优化按钮。参数区按“生成参数”和“保存设置”分组,采用单列参数列表,标签在左、控件在右;保留顶部批量开关、参考图区、提示词内 AI 帮写、种子右侧随机按钮和底部开始生成,控件颜色沿用当前 ComfyUI 主题,按钮不使用独立强调色;提示词独立显示为“画面描述”区域,随机种子按钮仍内嵌在种子输入框右侧。ComfyUI Nodes 1.0 因识别到 `seed` 输入而自动添加的「生成后控制」与该按钮功能重复,因此会由面板隐藏,不占用节点顶部空间。模型、线路、分辨率、宽高比、生图数量和种子常显;模型专属参数会随模型动态切换:仅 Nano Banana 2 / 2.1 显示「思考等级」和「在线搜索」,GPT Image 2 / 2.5 显示「质量」「背景」和「蒙版」,GPT Image 2 / 2.5 与 Seedream 5.0 Pro 都显示作为 API 参数的「输出格式」。在线搜索默认为「关闭」,关闭时不发送相关参数;选择「打开」时,请求体顶层发送 `google_search: true`。这些参数不收进高级设置弹层;切换模型只隐藏不适用参数,不会清空已选值。分辨率新增默认值「智能」;选择它时,Nano Banana、GPT Image 和 Seedream 的上游请求都不发送 `size`,由模型决定输出尺寸。选择具体档位时,GPT Image 2 会把分辨率与宽高比映射为具体像素尺寸;宽高比选择「智能」时按正方形映射为 `1024x1024 / 2048x2048 / 2880x2880`。背景支持自动、透明和不透明,输出格式支持 JPEG、PNG 和 WebP;新建 GPT 设置默认 PNG,已有工作流保留保存的格式,其中透明背景只能搭配 PNG 或 WebP。所有模型每次请求最多使用 10 张参考图。GPT Image 新选项支持每条提示词生成 1–8 张,旧工作流中的 9 张仍可执行;其余模型保持 `1 / 2 / 4 / 9`。GPT Image 2.5 的质量另支持「超高 / 最高」,分别发送 `xhigh / max`;GPT Image 2 仅支持原有四档。提示词支持用独占一行的 `---` 分隔多条内容;所有模型和执行入口都会按“提示词数量 × 生图数量”生成任务,任务排列为同一提示词的所选张数在前、下一条提示词随后,单次最多 1000 个任务。任务会按受控并发分批执行,GPT Image 与 Seedream 请求中的 `n` 固定为 `1`。模型线路在面板中显示为「特价(便宜)/ 优质(小贵)/ 企业(贵)」,工作流内部仍保存兼容值「畅速 / 直连 / 专线」;思考等级默认为「低」,显示为「低(耗时低,智力低)/ 高(耗时高,智力高)」;缩放图片显示为「不缩放(无大图)/ 智能缩放(有大图)」。带标签的下拉参数在菜单收起后也会显示当前选项的标签。 同一面板支持 Nodes 1.0 / 2.0 切换,参数、参考图和操作位置保持不变。 diff --git a/docs/architecture.md b/docs/architecture.md index 25b32d4..3cd0228 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -152,7 +152,7 @@ The panel displays model-route labels as `特价 / 优质 / 企业`, but seriali The unified image generator retains its DOM panel, grouped sections, top batch controls, reference upload/canvas-picker header, empty add-reference tile, prompt-local AI writing action, inline seed randomizer, and bottom generate action. The released schema widgets remain hidden and provide the stable execution/serialization boundary. CSS presents generation/save parameters in one vertical list with left labels and right controls. Nodes 1.0 uses ComfyUI input theme tokens; inside the Nodes 2.0 widget host it uses component-node tokens. All buttons use the same neutral theme surface as the inputs. Switching renderers retains the same panel and values; it does not replace the panel with native schema widgets or append action rows. -LiteGraph includes `serialize:false` UI widgets in workflow arrays, even though prompt serialization omits them. The generator serializes only its ordered backend widget values, excluding the hidden automatic seed control and the panel widget. The seed randomizer remains inside its input row. Old hidden `control_after_generate` values after `seed` and the full-layout trailing empty panel value are removed by narrow idempotent migrations, including inside subgraphs. Node/input/output IDs and provider payloads stay unchanged. [ADR 0015](decisions/0015-image-generator-workflow-values.md) records this compatibility boundary. +LiteGraph includes UI widgets with `options.serialize:false` in workflow arrays, even though prompt serialization omits them. The generator serializes only its ordered backend widget values, excluding the hidden automatic seed control and the panel widget. Hidden automatic seed controls also set `widget.serialize = false` during panel creation and restoration: LiteGraph checks that widget-level flag when assigning saved values, so references, masks, batch settings, and save settings remain aligned after copy/paste or workflow loading. The seed randomizer remains inside its input row. Old hidden `control_after_generate` values after `seed` and the full-layout trailing empty panel value are removed by narrow idempotent migrations, including inside subgraphs. Node/input/output IDs and provider payloads stay unchanged. [ADR 0015](decisions/0015-image-generator-workflow-values.md) records this compatibility boundary. The panel's `prompt` remains a socketless, serialized widget value edited in the node. The removed `external_prompt` input is not part of the V3 schema or execution signature. Before loading an older workflow, the frontend migration removes that input and its exact graph link from the generator, the link table, and the source output while retaining the saved panel prompt text. It is idempotent and applies inside subgraph definitions as well as the root graph. diff --git a/docs/decisions/0015-image-generator-workflow-values.md b/docs/decisions/0015-image-generator-workflow-values.md index a0bba60..934773d 100644 --- a/docs/decisions/0015-image-generator-workflow-values.md +++ b/docs/decisions/0015-image-generator-workflow-values.md @@ -6,16 +6,18 @@ ## Context -The image generator uses a custom panel over hidden schema widgets. LiteGraph includes hidden automatic seed controls and the panel value in positional workflow arrays, even for UI widgets marked non-serialized. These values can shift reference manifests and later save settings while restoring workflows. +The image generator uses a custom panel over hidden schema widgets. LiteGraph includes hidden automatic seed controls and the panel value in positional workflow arrays when only `options.serialize:false` is set. That option excludes API prompts; LiteGraph's workflow restoration checks `widget.serialize` instead. These values can shift reference manifests and later save settings while restoring workflows. ## Decision Keep the existing panel, interaction hierarchy, node IDs, and input order. Serialize only ordered backend widget values. Before existing workflow migrations run, remove an automatic seed-control value only when it follows the numeric seed and precedes a reference-list string. Remove the trailing empty panel value only from the recognized full 24-value layout. Repeat these checks inside subgraphs. +Set `widget.serialize = false` on hidden automatic seed controls before saved values are restored. This keeps LiteGraph's restoration order aligned with the canonical backend-only workflow array for both copy/paste and workflow loading. + ## Consequences Panel controls and their positions remain unchanged. Newly saved workflows have exactly the schema's 23 values. Older panel workflows and workflows saved during the native-widget revision restore the same parameters, reference manifests, and save settings. ## Validation -Offline tests cover panel action placement, idempotent creation, canonical serialization, and repeated root/subgraph migration. Browser checks retain parameters and references across both renderers without paid generation. +Offline tests cover panel action placement, idempotent creation, canonical serialization, and repeated root/subgraph migration. Upload-to-copy/paste round trips use LiteGraph's widget-level restoration loop and cover ordinary and prefixed seed controls, ordered references, target references, masks, later parameters, save settings, legacy layouts, and independent copied lists. Browser checks retain parameters and references across both renderers without paid generation. diff --git a/docs/development.md b/docs/development.md index ed0ea21..daa03a9 100644 --- a/docs/development.md +++ b/docs/development.md @@ -54,7 +54,7 @@ For Omni Flash, keep `O1keyOmniFlashVideo` as the sole node ID. Its `execute` va - Add or extend a Node-based test for logic that can run without a browser. - For display-only Combo aliases, set `widget.options.getOptionLabel` in an idempotent frontend extension; keep the actual option values unchanged so prompt payloads and saved workflows remain compatible. -For the image generator, preserve the existing DOM panel and its interaction hierarchy. Keep batch controls and reference upload actions at the top, AI writing inside the prompt area, the randomizer inside the seed row, and generation at the bottom. Restrict style requests to CSS: a single parameter column with left labels/right controls and current ComfyUI theme colours, without button accents. Use legacy input tokens outside the Nodes 2.0 widget host and component-node tokens inside it. Keep backend widgets hidden in both renderers, reapply visibility when renderer options are replaced, and never reorder schema widgets. Serialize only ordered backend values so hidden seed controls and the panel cannot shift later settings. Cover panel identity/action placement, renderer visibility, model switching, and root/subgraph migration with the offline frontend test; compare both renderers and themes using a disposable browser workflow. +For the image generator, preserve the existing DOM panel and its interaction hierarchy. Keep batch controls and reference upload actions at the top, AI writing inside the prompt area, the randomizer inside the seed row, and generation at the bottom. Restrict style requests to CSS: a single parameter column with left labels/right controls and current ComfyUI theme colours, without button accents. Use legacy input tokens outside the Nodes 2.0 widget host and component-node tokens inside it. Keep backend widgets hidden in both renderers, reapply visibility when renderer options are replaced, and never reorder schema widgets. Serialize only ordered backend values so hidden seed controls and the panel cannot shift later settings. Set `widget.serialize = false` on hidden seed controls before restoration; `options.serialize:false` alone only excludes API prompts. Cover panel identity/action placement, renderer visibility, model switching, upload-to-copy/paste round trips using LiteGraph's restoration loop, and root/subgraph migration with the offline frontend test; compare both renderers and themes using a disposable browser workflow. Panel-triggered image batches must be represented in ComfyUI's native task queue, not by task-state text or a cancel action inside `O1keyImageGenerator`. Keep the jobs API bridge idempotent, retain a distinct queue item and expected-output count per batch, route native single and bulk cancellation to `/o1key/image/jobs/{batch_id}/cancel`, and leave the generator action available for consecutive submissions. Preserve native queue/history records returned by ComfyUI when merging o1key records, hydrate persisted terminal summaries before returning the first history page, and keep queue clearing semantics limited to waiting batches. History persistence must remain bounded, atomic, credential-free, and synchronized with native delete/clear actions; a persistence failure must never change the result of a paid generation or successful image save. diff --git a/tests/test_o1key_image_generator_frontend.mjs b/tests/test_o1key_image_generator_frontend.mjs index a1584be..78fb0b8 100644 --- a/tests/test_o1key_image_generator_frontend.mjs +++ b/tests/test_o1key_image_generator_frontend.mjs @@ -437,6 +437,134 @@ function createRecoveryNodes(batchId, generatorId, saveNodeId) { assert.equal(saved.widgets_values[7], 123); assert.equal(saved.widgets_values[18], "kept-prefix"); assert.equal(saved.widgets_values[20], "kept-location"); + + // ComfyUI inserts this UI widget after seed. Its options.serialize flag + // excludes API prompts, while LiteGraph restores using widget.serialize. + function WorkflowGenerator() {} + WorkflowGenerator.prototype.computeSize = () => [500, 1025]; + await app.extension.beforeRegisterNodeDef(WorkflowGenerator, { name: "O1keyImageGenerator" }); + const createWorkflowGenerator = (controlName) => { + const generator = Object.assign(new WorkflowGenerator(), { + comfyClass: "O1keyImageGenerator", + widgets: names.map((name, index) => ({ name, value: values[index], options: {} })), + size: [560, 1035], + outputs: [], + properties: {}, + addDOMWidget(name, type, element, options) { + const widget = { name, type, element, options, serialize: options.serialize }; + this.widgets.push(widget); + return widget; + }, + setSize(size) { this.size = size; }, + setDirtyCanvas() {}, + }); + generator.widgets.splice(8, 0, { + name: controlName, + value: "randomize", + options: { serialize: false, values: ["fixed", "increment", "decrement", "randomize"] }, + }); + generator.onNodeCreated(); + return generator; + }; + const pasteWorkflowGenerator = (data, controlName) => { + const generator = createWorkflowGenerator(controlName); + let index = 0; + // Match the bundled LiteGraph configure loop, including UI widgets. + for (const widget of generator.widgets) { + if (widget.serialize === false) continue; + if (index >= data.widgets_values.length) break; + widget.value = data.widgets_values[index++]; + } + generator.onConfigure(data); + return generator; + }; + let workflowMigration; + vm.runInNewContext(migrationSource.replace(/^import .*;\s*$/gm, ""), { + app: { registerExtension(extension) { workflowMigration = extension; } }, + console: { log() {}, warn() {} }, + }); + const originalFetchApi = api.fetchApi; + api.fetchApi = async (url, options) => { + assert.equal(url, "/upload/image", "Copy/paste tests only mock local image uploads"); + const file = options.body.get("image"); + return { + ok: true, + json: async () => ({ name: file.name, subfolder: "copy-test", type: "input" }), + }; + }; + try { + for (const controlName of ["control_after_generate", "O1keyImageGenerator control_after_generate"]) { + const original = createWorkflowGenerator(controlName); + await acceptFiles(original, [ + new File(["offline reference"], "reference-a.png", { type: "image/png" }), + new File(["offline reference"], "reference-b.png", { type: "image/png" }), + ]); + const normalSerialized = {}; + original.onSerialize(normalSerialized); + const normalPasted = pasteWorkflowGenerator(JSON.parse(JSON.stringify(normalSerialized)), controlName); + assert.equal(normalPasted._o1igBatchEnabled, false); + assert.deepEqual(JSON.parse(JSON.stringify(normalPasted._o1igReferences)), + JSON.parse(normalSerialized.widgets_values[8]), "Normal generation retains uploaded references"); + const normalResaved = {}; + normalPasted.onSerialize(normalResaved); + assert.deepEqual(normalResaved.widgets_values, normalSerialized.widgets_values); + original._o1igBatchToggle.dispatch("click"); + await acceptFiles(original, [ + new File(["offline target"], "target.png", { type: "image/png" }), + ], "models"); + original.widgets.find(widget => widget.name === "蒙版清单").value = JSON.stringify({ + name: "mask.png", subfolder: "copy-test", type: "input", + }); + restorePanelFromWidgets(original); + const serialized = {}; + original.onSerialize(serialized); + assert.equal(serialized.widgets_values.length, names.length); + assert.equal(JSON.parse(serialized.widgets_values[8]).length, 2); + assert.equal(JSON.parse(serialized.widgets_values[16]).length, 1); + + const legacyValues = [...serialized.widgets_values]; + legacyValues.splice(8, 0, "randomize"); + legacyValues.push(""); + const legacyGraph = { nodes: [{ type: "O1keyImageGenerator", widgets_values: legacyValues }] }; + workflowMigration.beforeConfigureGraph(legacyGraph); + workflowMigration.beforeConfigureGraph(legacyGraph); + assert.deepEqual(legacyValues, serialized.widgets_values); + + for (const data of [serialized, legacyGraph.nodes[0]]) { + const pasted = pasteWorkflowGenerator(JSON.parse(JSON.stringify(data)), controlName); + assert.deepEqual( + JSON.parse(JSON.stringify(pasted._o1igReferences)), + JSON.parse(serialized.widgets_values[8]), + "Copy/paste and migrated workflows retain uploaded references in order", + ); + assert.deepEqual( + JSON.parse(JSON.stringify(pasted._o1igModelReferences)), + JSON.parse(serialized.widgets_values[16]), + ); + assert.deepEqual( + JSON.parse(JSON.stringify(pasted._o1igMask)), + JSON.parse(serialized.widgets_values[11]), + ); + const resaved = {}; + pasted.onSerialize(resaved); + assert.deepEqual(resaved.widgets_values, serialized.widgets_values, + "Seed, later parameters, and save settings survive the complete round trip"); + assert.equal(pasted.widgets.find(widget => widget.name === controlName).serialize, false); + const pastedPanel = pasted._o1igPanel; + const pastedWidgetCount = pasted.widgets.length; + pasted.onConfigure(JSON.parse(JSON.stringify(data))); + assert.equal(pasted._o1igPanel, pastedPanel); + assert.equal(pasted.widgets.length, pastedWidgetCount); + assert.equal(pasted._o1igReferences.length, 2); + pasted._o1igReferences.pop(); + pasted._o1igModelReferences.pop(); + assert.equal(original._o1igReferences.length, 2, "Pasted reference lists are independent"); + assert.equal(original._o1igModelReferences.length, 1); + } + } + } finally { + api.fetchApi = originalFetchApi; + } 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/); diff --git a/web/js/o1keyImageGenerator.js b/web/js/o1keyImageGenerator.js index 0378418..7e014e8 100644 --- a/web/js/o1keyImageGenerator.js +++ b/web/js/o1keyImageGenerator.js @@ -338,7 +338,11 @@ function hideBackendWidgets(node) { hideBackendWidget(findWidget(node, name)); } for (const widget of node?.widgets || []) { - if (isGeneratedSeedControl(widget)) hideBackendWidget(widget); + if (isGeneratedSeedControl(widget)) { + hideBackendWidget(widget); + // LiteGraph restores by widget.serialize; options.serialize only excludes API prompts. + widget.serialize = false; + } } } @@ -4744,7 +4748,7 @@ function restorePanelFromWidgets(node) { } function serializeGeneratorWidgets(node, data) { - // LiteGraph stores even serialize:false UI widgets in workflows. Keep only schema widgets. + // options.serialize:false excludes prompts, not workflow values. Keep only schema widgets. data.widgets_values = (node.widgets || []) .filter(widget => BACKEND_WIDGETS.includes(widget.name) && widget.name !== "内容审查强度") .map(widget => widget.value);