Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(create): validateWorkflowJson akzeptiert nur noch API-Format (R2-32)

purple6c51e0c57560
diff --git a/src/api/__tests__/workflows-validation.test.ts b/src/api/__tests__/workflows-validation.test.ts
index 252e9d1a..cedaf9cc 100644
--- a/src/api/__tests__/workflows-validation.test.ts
+++ b/src/api/__tests__/workflows-validation.test.ts
@@ -14,7 +14,7 @@ describe('workflows — pure functions', () => {
expect(validateWorkflowJson(wf)).toBe(true)
})
- it('accepts valid Web/UI format (nodes array with type)', () => {
+ it('R2-32: rejects Web/UI canvas format (nodes array with type), no caller reads that shape', () => {
const wf = {
nodes: [
{ id: 1, type: 'CheckpointLoaderSimple', widgets_values: [] },
@@ -22,7 +22,7 @@ describe('workflows — pure functions', () => {
],
links: [],
}
- expect(validateWorkflowJson(wf)).toBe(true)
+ expect(validateWorkflowJson(wf)).toBe(false)
})
it('rejects object with no nodes (no class_type or nodes array)', () => {
@@ -49,11 +49,11 @@ describe('workflows — pure functions', () => {
expect(validateWorkflowJson(undefined)).toBe(false)
})
- it('accepts web format even without links key', () => {
+ it('R2-32: rejects web format even without links key (still not API shape)', () => {
const wf = {
nodes: [{ id: 1, type: 'SaveImage' }],
}
- expect(validateWorkflowJson(wf)).toBe(true)
+ expect(validateWorkflowJson(wf)).toBe(false)
})
it('rejects nodes array with objects missing type field', () => {
diff --git a/src/api/workflows.ts b/src/api/workflows.ts
index 5eb06b5a..fb31e947 100644
--- a/src/api/workflows.ts
+++ b/src/api/workflows.ts
@@ -12,7 +12,7 @@ import type {
ComfyApiGraph, ComfyApiNode, ComfyInputValue, ComfyNodeInputs,
} from '../types/comfy-graph'
import {
- apiNodes, isComfyApiGraph, isComfyWebGraph,
+ apiNodes, isComfyApiGraph,
inputNumber, linkTarget,
} from '../types/comfy-graph'
@@ -23,22 +23,20 @@ import {
// types/comfy-graph.ts; nothing below reads a field it has not narrowed first.
/**
- * Accepts either ComfyUI graph format. Kept as a predicate over the API shape
- * because that is what every caller goes on to build.
+ * Accepts ONLY the ComfyUI API graph format ({ "1": { class_type, inputs }, ... }).
*
- * A web-format file passes here and is stored as it came: the converter that
- * used to stand beside this went with the CivitAI workflow fetcher it was the
- * only caller of (3.0.0). Nothing in the app ever called it, because the Import
- * button in WorkflowsModal hands this JSON straight to `parseImportedWorkflow`,
- * so removing it changed no behaviour, and the modal already says what to do:
- * "Export it from ComfyUI using Save (API Format)".
+ * R2-32: this used to accept the Web/UI export format too ({ nodes: [...],
+ * links: [...] }), but every caller downstream (parameterMap detection,
+ * parameter injection, apiNodes) reads `class_type`/`inputs`, fields the
+ * Web/UI format does not carry. A Web/UI export therefore passed validation
+ * and then failed silently later, with the modal's own advice ("Export it
+ * from ComfyUI using Save (API Format)") never shown because validation had
+ * already said yes. Narrowed to the one shape every caller actually needs.
*/
export function validateWorkflowJson(json: unknown): json is ComfyApiGraph {
if (!json || typeof json !== 'object' || Array.isArray(json)) return false
// API format: { "1": { class_type: "...", inputs: {...} }, ... }
- if (isComfyApiGraph(json)) return true
- // Web/UI format: { nodes: [...], links: [...] }
- return isComfyWebGraph(json)
+ return isComfyApiGraph(json)
}
// ─── Smart Search Terms ───
diff --git a/src/types/comfy-graph.ts b/src/types/comfy-graph.ts
index dd791340..c0457e34 100644
--- a/src/types/comfy-graph.ts
+++ b/src/types/comfy-graph.ts
@@ -1,25 +1,23 @@
/**
- * The two ComfyUI graph formats, plus the guards that turn a downloaded or
- * user-picked JSON file into one of them.
+ * The ComfyUI API graph format, plus the guards that turn a downloaded or
+ * user-picked JSON file into one.
*
* This is foreign data in the strongest sense in this app: a `.json` the user
* dropped in, a CivitAI download, a `.png` with a workflow in its metadata.
* Nothing about its shape is guaranteed, so every walk over a graph narrows
* through the guards below before it reads a field.
*
- * Two formats exist and they are NOT interchangeable:
+ * API format is what `/prompt` accepts and what this app builds:
+ * `{ "3": { class_type: "KSampler", inputs: { seed: 1, model: ["4", 0] } } }`.
+ * Node ids are the object keys (strings), and an input is either a literal
+ * or a `[sourceNodeId, slotIndex]` link.
*
- * - **API format** — what `/prompt` accepts and what this app builds:
- * `{ "3": { class_type: "KSampler", inputs: { seed: 1, model: ["4", 0] } } }`.
- * Node ids are the object keys (strings), and an input is either a literal
- * or a `[sourceNodeId, slotIndex]` link.
+ * The ComfyUI canvas can also save a Web/UI format (`{ nodes: [...],
+ * links: [...] }`, numeric node ids, positional `widgets_values`), but
+ * nothing in this app reads that shape (R2-32), so it is not modelled here;
+ * the Import dialog tells the user to re-export with Save (API Format).
*
- * - **Web/UI format** — what the ComfyUI canvas saves: `{ nodes: [...],
- * links: [...] }`, node ids numeric, inputs positional
- * (`widgets_values`) and connections in a separate link table.
- * `convertWebToApiFormat` in api/workflows.ts turns one into the other.
- *
- * Type-only plus pure guards, no imports — a leaf module that cannot join an
+ * Type-only plus pure guards, no imports, a leaf module that cannot join an
* import cycle.
*/
@@ -74,38 +72,13 @@ export interface ComfyApiNode {
*/
export type ComfyApiGraph = Record<string, ComfyApiNode>
-// ── Web / UI format ─────────────────────────────────────────────
-
-/** One declared input socket of a canvas node. */
-export interface ComfyWebInput {
- name: string
- type?: string
- /** Link id into the graph's `links` table, or null when unconnected. */
- link?: number | null
-}
-
-export interface ComfyWebNode {
- id: number
- type: string
- inputs?: ComfyWebInput[]
- /** Positional widget state — order is per node class and undocumented.
- * Plain parsed JSON, hence ComfyInputValue rather than unknown. */
- widgets_values?: ComfyInputValue[]
- /** Named widget slots, when the canvas saved them — lets an unknown node
- * type still have its widget values mapped by name. */
- widgets?: { name?: string }[]
- title?: string
-}
-
-/** `[linkId, sourceNodeId, sourceSlot, targetNodeId, targetSlot, type]`. */
-export type ComfyWebLink = [number, number, number, number, number, string?]
-
-export interface ComfyWebGraph {
- nodes: ComfyWebNode[]
- links?: unknown[]
-}
-
-
+// R2-32: the Web/UI canvas-save format (ComfyWebGraph/ComfyWebNode/ComfyWebInput/
+// ComfyWebLink, plus the isComfyWebGraph/isComfyWebNode guards) used to live
+// here so validateWorkflowJson could accept it, but nothing downstream reads
+// its shape (parameterMap detection, injection and apiNodes all need
+// class_type/inputs), so a Web/UI export passed validation and then failed
+// silently. Removed with the acceptance in workflows.ts; deleted rather than
+// left unused (Hausregel: toter Code wird ganz geloescht).
// ── Guards ──────────────────────────────────────────────────────
@@ -154,23 +127,6 @@ export function isComfyApiGraph(v: unknown): v is ComfyApiGraph {
return isPlainObject(v) && Object.values(v).some(isComfyApiNode)
}
-/** One canvas node — a numeric id and a class name. */
-export function isComfyWebNode(v: unknown): v is ComfyWebNode {
- return isPlainObject(v) && typeof v.type === 'string' && typeof v.id === 'number'
-}
-
-/**
- * Is this the canvas save format? Matches the historical check exactly: a
- * `nodes` array holding at least one entry with a string `type`. (Node ids are
- * verified per node by `isComfyWebNode` at conversion time, because a graph
- * with one malformed node should still convert the rest.)
- */
-export function isComfyWebGraph(v: unknown): v is ComfyWebGraph {
- return isPlainObject(v)
- && Array.isArray(v.nodes)
- && v.nodes.some((n) => isPlainObject(n) && typeof n.type === 'string')
-}
-
/** Read one input of a node without asserting anything about its type. */
export function nodeInput(node: ComfyApiNode | undefined, key: string): ComfyInputValue | undefined {
const inputs = node?.inputs