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
+10 -5
View File
@@ -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. 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.
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 internal prompt/manifest widgets hidden in both renderers, while the released parameter widgets remain visible for LiteGraph's native rows; the native seed widget is replaced by one compact DOM row so its randomizer stays beside the value. Reapply capability visibility when renderer options are replaced, and do not change the relative order of schema widgets. Serialize only ordered backend values so the DOM panel and hidden internal fields cannot shift later settings. Set `widget.serialize = false` on hidden `control_after_generate` widgets before restoration; keep the backend seed value serializable even though its visual widget is replaced. `options.serialize:false` alone only excludes API prompts. Cover panel identity/action placement, native parameter 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.
@@ -66,7 +66,9 @@ In automatic multimodal mode, render reference images, videos, and audio cards i
The video generator defaults new nodes to multimodal mode. Its custom panel is created before saved widget values may be applied, so restore every visible control and material track from the configured node state in `onConfigure`; `loadedGraphNode` must repeat that restoration after graph loading. Never let panel initialization write defaults over a returning workflow's prompt, parameters, manual asset IDs, or `o1keyVideoMedia` properties.
Keep source/target batching behind the append-only `批量出图` switch. The visible panel must use the industry-neutral names `素材图`, `目标图`, `整组素材 → 多个目标`, `全匹配(素材 × 目标)`, and `单图批量(每张素材独立)`; the historical widget and first two mode values remain compatibility identifiers. Render references as a `102 × 102` horizontal card track with upload and canvas-picker actions in the track header. Every track must retain a trailing add card after its uploaded and pending thumbnails; both that card and the complete track accept external image-file drops. Stop accepted file-drop propagation before ComfyUI's canvas handler while leaving internal thumbnail sorting drags untouched. A drop handled by a nested upload card must clear the `drag` class from both that card and its parent track; the track must not retain a coloured background or outline after the file is released. Track images must use the bounded `/o1key/image/thumbnail` representation, must not decode pending local blobs, and must retain the original `/view` descriptor only for the lightbox; never substitute thumbnail bytes into manifests, prompt optimization, or provider requests. Normal mode shows one `参考图` track; paired batch modes show separate `素材图` and `目标图` tracks, while single-reference mode hides the target track. Header hints must include the current manifest count and the active participation rule. Make the complete thumbnail the pointer drag target rather than rendering a separate handle. During a drag, dim and scale the source card, label it `移动中`, highlight its track, and use a thick insertion edge plus target displacement; suppress the immediate post-drag preview click. Keep `Alt + Arrow/Home/End` ordering on the focused thumbnail as the keyboard path. With the switch off, ignore the stored target manifest and preserve the historical reference/prompt path. With it on, use `expand_image_generation_tasks` as the shared ordering authority for direct and background execution: prompts first, then pairings or source indexes, then per-pair copies. Batch manifests cap at fifty images, but provider requests remain capped at ten references: group mode therefore allows nine sources plus one target, while its target manifest may hold fifty; Cartesian and single-reference source manifests may hold fifty because each task selects one source. Snapshot only manifests used by the active mode, never serialize file paths into a workflow, and reconstruct task-specific references from validated indexes. Load large batch manifests only for active tasks, serialize reference preprocessing to bound full-resolution decode pressure while preserving request order, and release task-local images/tensors immediately after their last consumer. A failed-slot retry must flatten only that slot's exact references into a one-task normal-mode request. Keep request-position thumbnail badges derived from the same ordering. Treat ordered manifests as the source of truth for sorting and persist moves immediately. Uploaded thumbnails must reuse ComfyUI's `MediaLightbox` interaction contract; do not expose signed URLs or open a browser tab. Keep the batch summary hidden until all inputs required by the active mode are present, then show the exact task count, per-item count, prompt multiplier, and total.
Keep source/target batching behind the append-only `批量出图` switch. The visible panel must use the industry-neutral names `素材图`, `目标图`, `整组素材→多个目标`, `每张素材×每张目标`, and `每张素材单独出图`; those three strings are the serialized `批量模式` values in both the backend combo and the panel select, so renaming them requires a matching entry in `IMAGE_BATCH_MODE_ALIASES` and in the `migrateUnifiedBatchModeLabels` workflow migration. The widget name `模特图清单` remains a compatibility identifier and is never shown to users. Render references as a `102 × 102` horizontal card track. The track header carries only the lane title and the `画布取图` button; there is no header upload button, and the trailing add card is the single upload entry point (it calls `requestReferenceUpload`, which opens the hidden file input kept beside the track). Every track must retain a trailing add card after its uploaded and pending thumbnails; both that card and the complete track accept external image-file drops. Stop accepted file-drop propagation before ComfyUI's canvas handler while leaving internal thumbnail sorting drags untouched. A drop handled by a nested upload card must clear the `drag` class from both that card and its parent track; the track must not retain a coloured background or outline after the file is released. Track images must use the bounded `/o1key/image/thumbnail` representation, must not decode pending local blobs, and must retain the original `/view` descriptor only for the lightbox; never substitute thumbnail bytes into manifests, prompt optimization, or provider requests. Normal mode shows one `参考图` track; paired batch modes show separate `素材图` and `目标图` tracks, while single-reference mode hides the target track. Header hints show the manifest count only in normal mode (`N 张 · 最多 10 张`); with batching on they are hidden through the `hidden` class because the preview row below the tracks already reports the counts. Make the complete thumbnail the pointer drag target rather than rendering a separate handle. During a drag, dim and scale the source card, label it `移动中`, highlight its track, and use a thick insertion edge plus target displacement; suppress the immediate post-drag preview click. Keep `Alt + Arrow/Home/End` ordering on the focused thumbnail as the keyboard path. With the switch off, ignore the stored target manifest and preserve the historical reference/prompt path. With it on, use `expand_image_generation_tasks` as the shared ordering authority for direct and background execution: prompts first, then pairings or source indexes, then per-pair copies. Batch manifests cap at fifty images, but provider requests remain capped at ten references: group mode therefore allows nine sources plus one target, while its target manifest may hold fifty; Cartesian and single-reference source manifests may hold fifty because each task selects one source. Snapshot only manifests used by the active mode, never serialize file paths into a workflow, and reconstruct task-specific references from validated indexes. Load large batch manifests only for active tasks, serialize reference preprocessing to bound full-resolution decode pressure while preserving request order, and release task-local images/tensors immediately after their last consumer. A failed-slot retry must flatten only that slot's exact references into a one-task normal-mode request. Keep request-position thumbnail badges derived from the same ordering. Treat ordered manifests as the source of truth for sorting and persist moves immediately. Uploaded thumbnails must reuse ComfyUI's `MediaLightbox` interaction contract; do not expose signed URLs or open a browser tab. Keep the batch summary hidden until all inputs required by the active mode are present, then show the pairing detail and the total on one line, in the form `整组 3 张素材 × 4 个目标 = 4 组 · 每组 2 张 · 2 条提示词` plus a highlighted `共 16 张`. `batchGenerationPreview` is the only place that computes this total, and the row must refresh on reference/target changes, mode switches, `生图数量` changes, and prompt edits.
The generator node's height has exactly one source of truth: `fitNode` plus the dragged-out delta `properties.o1keyPanelExtraHeight`. A `setSize()` that the engine fires on its own (node creation, workflow restore, or the Vue body re-measuring after rows appear) must never move that delta, so `onResize` only treats a resize as a drag when the node has settled **and** the press started on this node's DOM subtree. Use `document.elementFromPoint` for that check on Vue nodes: their DOM box and `canvas.ds.offset` disagree, and the geometry fallback both rejected real grip drags and accepted presses on menus. `onConfigure` has to call `resetCanvasPointerGesture()`, because a press swallowed by a menu row (重启 / 设置) never delivers its `pointerup` and the stale flag then reads every following re-layout as a drag. Bound the accepted pointer travel with `GENERATOR_DRAG_OVERSHOOT` so a stale press cannot fold a screen-wide mouse jump into the panel height. Finally, keep the `GENERATOR_FIT_TOLERANCE` dead zone in `fitNode`: `computeSize` re-derives its number from the laid-out DOM and is noisy by ~18 px, so without a tolerance the node has no fixed point and flips between two heights forever, which reads as the node growing on its own.
Keep reference-image editing frontend-only and descriptor-based. The top-left thumbnail action may crop and flatten visual mask/brush/arrow marks plus one transformed upper sticker layer into a new PNG, but it must not create a `MASK` value or mutate the GPT mask widget. Keep sticker placement and arrow endpoints in source-image coordinates so preview resizing cannot alter the exported geometry; the arrow tip must remain the exact pointer-release position. Compose annotations above the sticker and never export selection handles. Revoke local sticker object URLs on close and never serialize them. Save through the shared serialized native upload queue with `overwrite=false`, replace the original descriptor only after upload succeeds, and leave the source file untouched. Keep crop math, sticker fit/hit geometry, arrow-head geometry, and filename normalization independently testable in `tests/test_o1key_reference_image_editor.mjs`; run that test together with `test_o1key_image_generator_frontend.mjs` after editor changes.
@@ -74,7 +76,10 @@ When changing `O1keyImageSave`, preserve the mutually-exclusive preview rules do
When adding a model to `O1keyImageGenerator`, update `utils/o1key_image_catalog.py`, the frontend model descriptions/capability switch, the job payload validator, and the model-family executor together. Preserve the existing route values even when their labels change. Provider-specific multi-image parameters must not bypass the unified scheduler: each selected output image is one concurrent provider request, and GPT Image always receives `n=1`. Keep GPT-only controls appended after the original generator widgets so old workflow arrays do not shift.
`utils/nano_banana_models.py` owns the shared Nano Banana model list and route IDs for `NanoBanana`, `BatchNanoBananaPro`, and unified image generation. `Nano Banana 2.1` is first in the model lists and the default in all three schemas, the unified execution method, and frontend fallbacks. Its `畅速 / 直连 / 专线` IDs are `gemini-nano-banana-2.1-sp / gemini-nano-banana-2.1-sd / gemini-nano-banana-2.1`; it shares Nano Banana 2's thinking, online-search, and extended-aspect-ratio support. Keep saved model selections intact, and include every new model in the migration model-recognition set without changing widget order. Verify model IDs, defaults, and parameter forwarding with the Nano Banana dynamic-input, unified image-generator, image-job, and image-generator frontend tests.
GPT Image 2.6's `复杂度` remains the last widget in both standalone schemas and at index 23 in the unified schema. Keep its catalog resolver shared by direct execution, background-job normalization/execution and the client. Older models omit `complexity` even if the hidden widget retains a value. SVG/GIF stay gated to GPT Image 2.6 via catalog helpers and frontend format menus; keep append-only `帧数` / `帧时长ms` after `复杂度`. Preserve GIF dual delivery (IMAGE frames + original bytes/path) and SVG path + raster preview. Run `test_gpt_image_nodes.py`, `test_o1key_image_generator.py`, `test_o1key_image_jobs.py`, `test_gpt_image_quality_frontend.mjs` and `test_o1key_image_generator_frontend.mjs`; preserve the nested-graph migration and complexity-value copy/paste cases.
`utils/nano_banana_models.py` owns the shared Nano Banana model list and route IDs for `NanoBanana` and `BatchNanoBananaPro`; the unified image generator publishes the supported first three entries from that list. `Nano Banana 2.1` is first in the model lists and the default in all three schemas, the unified execution method, and frontend fallbacks. Its `畅速 / 直连 / 专线` IDs are `gemini-nano-banana-2.1-sp / gemini-nano-banana-2.1-sd / gemini-nano-banana-2.1`; it shares Nano Banana 2's thinking, online-search, and extended-aspect-ratio support. The unified node migrates retired `Nano Banana 2 Lite` and `Nano Banana` workflow values to `Nano Banana 2` before ComfyUI restores widgets; legacy standalone nodes keep recognizing their released values. Verify model IDs, defaults, migration, and parameter forwarding with the Nano Banana dynamic-input, unified image-generator, image-job, and image-generator frontend tests.
For Seedream, keep the stable workflow value `Seedream 5.0 Pro` separate from API model ID `dola-seedream-5-0-pro-260628-ep`. Treat the unified panel's default `智能` resolution as an omitted provider `size`; resolve explicit `1K / 2K` plus aspect ratio through the catalog's exact size matrix, submit one image per async task with `n=1`, pass the selected `png / jpeg` as `output_format`, and always send `watermark=false` without adding a widget. Upload ordered references through `{base_url}/v1/o1key/uploads` and submit only the returned HTTPS URL strings; never log those temporary URLs. Layer decomposition is the exception to the normal size/prompt rules: accept exactly one reference, optional prompt text, `智能 / 1K / 1.5K / 2K`, forced PNG, and no batching. Keep all returned images in `z_index` order, preserve transparent provider bytes, expose alpha as MASK in direct execution, and sanitize metadata before it reaches descriptors, history, or workflows.
@@ -82,11 +87,11 @@ Keep batch-prompt behavior model-independent. A `---` line is the only prompt se
Do not add a download semaphore or an independent download-concurrency limit to `O1keyImageGenerator`. Ready result URLs must download immediately; the active provider-task scheduler is the only natural bound. The shared Nano transport may retain its optional semaphore for other released nodes, but unified direct and background paths must pass no limiter.
For GPT Image, keep resolution/aspect-ratio pairs in the catalog size matrix rather than duplicating exact pixel labels in the panel. `智能` is the first and default unified resolution for every model; it must become `None` at the provider boundary so Nano Banana, GPT Image, and Seedream request builders omit `size` entirely. Explicit tiers retain their existing mappings. Keep active user controls in one persistent vertical list with labels on the left and controls on the right, but apply the model capability matrix when synchronizing the model: thinking level and online search are available to Nano Banana 2 and 2.1, resize mode is shared by Nano and GPT Image, and quality, background, API output format, plus mask are GPT Image-only. Online search defaults to `关闭`; omit `google_search` unless it is `打开`, then submit top-level `google_search: true`. The local `格式` field is visible only for Banana models; `命名规则`, `filename_prefix`, and `保存位置` are shared. Hide unsupported fields in place instead of rebuilding them so values and listeners survive model switching. Display `JPEG` but serialize and submit lowercase `jpeg`; new GPT panel selections use `png` while saved values remain intact. Reject `transparent + jpeg` before any paid request and keep JPEG out of the frontend list while transparency is active.
For GPT Image, keep resolution/aspect-ratio pairs in the catalog size matrix rather than duplicating exact pixel labels in the panel. `智能` is the first and default unified resolution for every model; it must become `None` at the provider boundary so Nano Banana, GPT Image, and Seedream request builders omit `size` entirely. Explicit tiers retain their existing mappings. New unified image-generator nodes default to `思考等级=高` and `缩放图片=智能缩放`; saved widget values remain unchanged when a workflow is restored. The unified node leaves prompt/reference interactions in its custom DOM panel but lets LiteGraph render the parameter widgets natively; do not duplicate those native controls in the panel. Apply the model capability matrix when synchronizing the model: thinking level and online search are available to Nano Banana 2 and 2.1, resize mode is shared by Nano and GPT Image, and quality, background, API output format, plus mask are GPT Image-only. Online search defaults to `关闭`; omit `google_search` unless it is `打开`, then submit top-level `google_search: true`. The local `格式` field is visible only for Banana models; `命名规则`, `filename_prefix`, and `保存位置` are shared. Hide unsupported fields in place instead of rebuilding them so values and listeners survive model switching. Display `JPEG` but serialize and submit lowercase `jpeg`; new GPT panel selections use `png` while saved values remain intact. The closed select control shows only the selected value; descriptions remain available in the expanded menu. Reject `transparent + jpeg` before any paid request and keep JPEG out of the frontend list while transparency is active.
Keep prompt writing behind dedicated server routes. The unified image and video prompt actions must retain both the magic-wand icon and the visible `AI帮写` label so their purpose is understandable without hover; the image compatibility route remains `/o1key/image/prompt-optimize`, while video uses `/o1key/video/prompt-write` and a separate video-only system preset. The frontend must submit input descriptors rather than API credentials or filesystem paths. The server must enforce the input-root boundary, preserve reference order, cap the exact multimodal request body, use `gpt-5.6-sol` with high reasoning, and return only the optimized prompt. Tests must mock the upstream completion call and generate reference images at runtime; never add encoded reference fixtures or log complete data URLs.
Keep unified-generator post-processing, batch, and save widgets in their established order; migrate any removed middle widget before ComfyUI restores saved values. The retired `色彩纠正` value is removed from legacy index 13 before later values are mapped; `背景` occupies index 13; the retired `内容审查强度` value is removed from legacy index 14 after the old-layout migrations. Batch fields occupy indexes 14–16, generator save fields 17–20, `在线搜索` index 21, and Seedream `图层拆分` index 22. `migrateWorkflow.js` must first remove the retired value and fill older generator defaults, then move the connected legacy save node's four positional values into those slots, append later defaults, and clear the old save-node array idempotently. The original `IMAGE` output remains first; new provider-specific outputs must be appended. Display-only collapsing of provider-specific outputs must restore them when their mode is enabled and must never hide a connected output. Layer-decomposition background generation must save the returned descriptors once, then route the base descriptor to the output-0 save node and the remaining descriptors to its paired output-1 layer save node. The frontend, direct V3 execution path, and background job payload must use the same save settings; GPT forces local `格式=原始`.
Keep unified-generator post-processing, batch, and save widgets in their established order; migrate any removed middle widget before ComfyUI restores saved values. The retired `色彩纠正` value is removed from legacy index 13 before later values are mapped; `背景` occupies index 13; the retired `内容审查强度` value is removed from legacy index 14 after the old-layout migrations. Batch fields occupy indexes 14–16, generator save fields 17–19, `保存位置` index 20, and Seedream `图层拆分` index 21; the retired `在线搜索` value is removed right after the saved value at index 21 (a string) followed by the `图层拆分` flag. `migrateWorkflow.js` must first remove the retired value and fill older generator defaults, then move the connected legacy save node's four positional values into those slots, append later defaults, and clear the old save-node array idempotently. The original `IMAGE` output remains first; new provider-specific outputs must be appended. Display-only collapsing of provider-specific outputs must restore them when their mode is enabled and must never hide a connected output. Layer-decomposition background generation must save the returned descriptors once, then route the base descriptor to the output-0 save node and the remaining descriptors to its paired output-1 layer save node. The frontend, direct V3 execution path, and background job payload must use the same save settings; GPT forces local `格式=原始`.
Keep the unified generator's canvas-image picker descriptor-based. Discover current-graph images from public execution outputs and native preview descriptors, fetch them through `/view`, and reuse the serialized `/upload/image` queue before adding them to a reference role. Do not pass `output` or `temp` descriptors to the image-job API, do not serialize picker state, and keep candidate text and filenames out of `innerHTML`.