Skip to content

Commit 552fc10

Browse files
authored
Merge pull request #112 from space-nuko/bughunt
Some issues fixing
2 parents 173e9aa + d9dbe89 commit 552fc10

14 files changed

+254
-106
lines changed

src/lib/ComfyGraphCanvas.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class ComfyGraphCanvas extends LGraphCanvas {
2525
activeErrors?: ComfyGraphErrors = null;
2626
blinkError: ComfyGraphErrorLocation | null = null;
2727
blinkErrorTime: number = 0;
28-
highlightNodeAndInput: [LGraphNode, number] | null = null;
28+
highlightNodeAndInput: [LGraphNode, number | null] | null = null;
2929

3030
get comfyGraph(): ComfyGraph | null {
3131
return this.graph as ComfyGraph;
@@ -104,7 +104,7 @@ export default class ComfyGraphCanvas extends LGraphCanvas {
104104
let state = get(queueState);
105105
let ss = get(selectionState);
106106

107-
const isRunningNode = node.id == state.runningNodeID
107+
const isExecuting = state.executingNodes.has(node.id);
108108
const nodeErrors = this.activeErrors?.errorsByID[node.id];
109109
const isHighlightedNode = this.highlightNodeAndInput && this.highlightNodeAndInput[0].id === node.id;
110110

@@ -133,11 +133,20 @@ export default class ComfyGraphCanvas extends LGraphCanvas {
133133
else if (isHighlightedNode) {
134134
color = "cyan";
135135
thickness = 2
136+
137+
// Blink node if no input highlighted
138+
if (this.highlightNodeAndInput[1] == null) {
139+
if (this.blinkErrorTime > 0) {
140+
if ((Math.floor(this.blinkErrorTime / 2)) % 2 === 0) {
141+
color = null;
142+
}
143+
}
144+
}
136145
}
137146
else if (ss.currentHoveredNodes.has(node.id)) {
138147
color = "lightblue";
139148
}
140-
else if (isRunningNode) {
149+
else if (isExecuting) {
141150
color = "#0f0";
142151
}
143152

@@ -153,7 +162,7 @@ export default class ComfyGraphCanvas extends LGraphCanvas {
153162
this.drawNodeOutline(node, ctx, size, mouseOver, fgColor, bgColor, color, thickness)
154163
}
155164

156-
if (isRunningNode && state.progress) {
165+
if (isExecuting && state.progress) {
157166
ctx.fillStyle = "green";
158167
ctx.fillRect(0, 0, size[0] * (state.progress.value / state.progress.max), 6);
159168
ctx.fillStyle = bgColor;
@@ -172,9 +181,11 @@ export default class ComfyGraphCanvas extends LGraphCanvas {
172181
}
173182
if (draw) {
174183
const [node, inputSlot] = this.highlightNodeAndInput;
175-
ctx.lineWidth = 2;
176-
ctx.strokeStyle = color;
177-
this.highlightNodeInput(node, inputSlot, ctx);
184+
if (inputSlot != null) {
185+
ctx.lineWidth = 2;
186+
ctx.strokeStyle = color;
187+
this.highlightNodeInput(node, inputSlot, ctx);
188+
}
178189
}
179190
}
180191
}
@@ -733,7 +744,7 @@ export default class ComfyGraphCanvas extends LGraphCanvas {
733744
this.selectNode(node);
734745
}
735746

736-
jumpToNodeAndInput(node: LGraphNode, slotIndex: number) {
747+
jumpToNodeAndInput(node: LGraphNode, slotIndex: number | null) {
737748
this.jumpToNode(node);
738749
this.highlightNodeAndInput = [node, slotIndex];
739750
this.blinkErrorTime = 20;

src/lib/ImageViewer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ export class ImageViewer {
165165

166166
let urls = ImageViewer.get_gallery_urls(galleryElem)
167167
const [_currentButton, index] = ImageViewer.selected_gallery_button(galleryElem)
168-
console.warn("Gallery!", index, urls, galleryElem)
169168

170169
this.showModal(urls, index, galleryElem)
171170
}

src/lib/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export type ComfyAPIHistoryItem = [
4545
]
4646

4747
export type ComfyAPIPromptSuccessResponse = {
48-
promptID: PromptID
48+
promptID: PromptID,
49+
number: number
4950
}
5051

5152
export type ComfyAPIPromptResponse = ComfyAPIPromptSuccessResponse | ComfyAPIPromptErrorResponse
@@ -295,7 +296,7 @@ export default class ComfyAPI {
295296
}
296297
return res.json()
297298
})
298-
.then(raw => { return { promptID: raw.prompt_id } })
299+
.then(raw => { return { promptID: raw.prompt_id, number: raw.number } })
299300
.catch(error => { return error })
300301
}
301302

src/lib/components/ComfyApp.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,11 @@ export default class ComfyApp {
728728
}
729729

730730
private requestPermissions() {
731-
if (Notification.permission === "default") {
732-
Notification.requestPermission()
733-
.then((result) => console.log("Notification status:", result));
731+
if (window.Notification != null) {
732+
if (window.Notification.permission === "default") {
733+
window.Notification.requestPermission()
734+
.then((result) => console.log("Notification status:", result));
735+
}
734736
}
735737
}
736738

@@ -939,7 +941,11 @@ export default class ComfyApp {
939941
if (workflow.attrs.queuePromptButtonRunWorkflow) {
940942
// Hold control to queue at the front
941943
const num = this.ctrlDown ? -1 : 0;
942-
this.queuePrompt(workflow, num, 1);
944+
let tag = null;
945+
if (workflow.attrs.queuePromptButtonDefaultWorkflow) {
946+
tag = workflow.attrs.queuePromptButtonDefaultWorkflow
947+
}
948+
this.queuePrompt(workflow, num, 1, tag);
943949
}
944950
}
945951

@@ -1037,11 +1043,11 @@ export default class ComfyApp {
10371043

10381044
const p = this.graphToPrompt(workflow, tag);
10391045
const wf = this.serialize(workflow)
1040-
console.debug(graphToGraphVis(workflow.graph))
1041-
console.debug(promptToGraphVis(p))
1046+
// console.debug(graphToGraphVis(workflow.graph))
1047+
// console.debug(promptToGraphVis(p))
10421048

10431049
const stdPrompt = this.stdPromptSerializer.serialize(p);
1044-
console.warn("STD", stdPrompt);
1050+
// console.warn("STD", stdPrompt);
10451051

10461052
const extraData: ComfyBoxPromptExtraData = {
10471053
extra_pnginfo: {
@@ -1074,8 +1080,8 @@ export default class ComfyApp {
10741080
workflowState.promptError(workflow.id, errorPromptID)
10751081
}
10761082
else {
1077-
queueState.afterQueued(workflow.id, response.promptID, num, p.output, extraData)
1078-
workflowState.afterQueued(workflow.id, response.promptID, p, extraData)
1083+
queueState.afterQueued(workflow.id, response.promptID, response.number, p.output, extraData)
1084+
workflowState.afterQueued(workflow.id, response.promptID)
10791085
}
10801086
} catch (err) {
10811087
errorMes = err?.toString();

src/lib/components/ComfyBoxWorkflowsView.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<script context="module" lang="ts">
2-
export const WORKFLOWS_VIEW: any = {}
2+
// workaround a vite HMR bug
3+
// shouts out to @rixo
4+
// https://github.com/sveltejs/svelte/issues/8655
5+
export const WORKFLOWS_VIEW = import.meta.hot?.data?.WORKFLOWS_VIEW || {}
6+
if (import.meta.hot?.data) {
7+
import.meta.hot.data.WORKFLOWS_VIEW = WORKFLOWS_VIEW
8+
}
39
</script>
410

511
<script lang="ts">

src/lib/components/ComfyGraphErrorList.svelte

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,36 @@
44
import Accordion from "./gradio/app/Accordion.svelte";
55
import uiState from '$lib/stores/uiState';
66
import type { ComfyNodeDefInputType } from "$lib/ComfyNodeDef";
7-
import type { INodeInputSlot, LGraphNode, Subgraph } from "@litegraph-ts/core";
8-
import { UpstreamNodeLocator } from "./ComfyPromptSerializer";
7+
import type { INodeInputSlot, LGraphNode, LLink, Subgraph } from "@litegraph-ts/core";
8+
import { UpstreamNodeLocator, getUpstreamLink, nodeHasTag } from "./ComfyPromptSerializer";
99
import JsonView from "./JsonView.svelte";
1010
1111
export let app: ComfyApp;
1212
export let errors: ComfyGraphErrors;
1313
14+
let missingTag = null;
15+
let nodeToJumpTo = null;
16+
let inputSlotToHighlight = null;
17+
let _errors = null
18+
19+
$: if (_errors != errors) {
20+
_errors = errors;
21+
if (errors.errors[0]) {
22+
jumpToError(errors.errors[0])
23+
}
24+
}
25+
1426
function closeList() {
1527
app.lCanvas.clearErrors();
1628
$uiState.activeError = null;
29+
clearState()
30+
}
31+
32+
function clearState() {
33+
_errors = null;
34+
missingTag = null;
35+
nodeToJumpTo = null;
36+
inputSlotToHighlight = null;
1737
}
1838
1939
function getParentNode(error: ComfyGraphErrorLocation): Subgraph | null {
@@ -24,36 +44,60 @@
2444
return node.graph._subgraph_node
2545
}
2646
27-
function canJumpToDisconnectedInput(error: ComfyGraphErrorLocation): boolean {
28-
return error.errorType === ComfyNodeErrorType.RequiredInputMissing && error.input != null;
47+
function jumpToFoundNode() {
48+
if (nodeToJumpTo == null) {
49+
return
50+
}
51+
52+
app.lCanvas.jumpToNodeAndInput(nodeToJumpTo, inputSlotToHighlight);
2953
}
3054
31-
function jumpToDisconnectedInput(error: ComfyGraphErrorLocation) {
55+
function detectDisconnected(error: ComfyGraphErrorLocation) {
56+
missingTag = null;
57+
nodeToJumpTo = null;
58+
inputSlotToHighlight = null;
59+
3260
if (error.errorType !== ComfyNodeErrorType.RequiredInputMissing || error.input == null) {
3361
return
3462
}
3563
3664
const node = app.lCanvas.graph.getNodeByIdRecursive(error.nodeID);
3765
38-
const inputIndex =node.findInputSlotIndexByName(error.input.name);
66+
const inputIndex = node.findInputSlotIndexByName(error.input.name);
3967
if (inputIndex === -1) {
4068
return
4169
}
4270
4371
// TODO multiple tags?
4472
const tag: string | null = error.queueEntry.extraData.extra_pnginfo.comfyBoxPrompt.subgraphs[0];
4573
46-
const test = (node: LGraphNode) => (node as any).isBackendNode
74+
const test = (node: LGraphNode, currentLink: LLink) => {
75+
if (!nodeHasTag(node, tag, true))
76+
return true;
77+
78+
const [nextGraph, nextLink, nextInputSlot, nextNode] = getUpstreamLink(node, currentLink)
79+
return nextLink == null;
80+
};
4781
const nodeLocator = new UpstreamNodeLocator(test)
48-
const [_, foundLink, foundInputSlot, foundPrevNode] = nodeLocator.locateUpstream(node, inputIndex, tag);
82+
const [foundNode, foundLink, foundInputSlot, foundPrevNode] = nodeLocator.locateUpstream(node, inputIndex, null);
4983
5084
if (foundInputSlot != null && foundPrevNode != null) {
51-
app.lCanvas.jumpToNodeAndInput(foundPrevNode, foundInputSlot);
85+
if (!nodeHasTag(foundNode, tag, true)) {
86+
nodeToJumpTo = foundNode
87+
missingTag = tag;
88+
inputSlotToHighlight = null;
89+
}
90+
else {
91+
nodeToJumpTo = foundPrevNode;
92+
inputSlotToHighlight = foundInputSlot;
93+
}
5294
}
5395
}
5496
5597
function jumpToError(error: ComfyGraphErrorLocation) {
5698
app.lCanvas.jumpToError(error);
99+
100+
detectDisconnected(error);
57101
}
58102
59103
function getInputTypeName(type: ComfyNodeDefInputType) {
@@ -88,26 +132,37 @@
88132
<div class="error-details">
89133
<button class="jump-to-error" class:execution-error={isExecutionError} on:click={() => jumpToError(error)}><span>⮎</span></button>
90134
<div class="error-details-wrapper">
91-
<span class="error-message" class:execution-error={isExecutionError}>{error.message}</span>
135+
{#if missingTag && nodeToJumpTo}
136+
<div class="error-input">
137+
<div><span class="error-message">Node "{nodeToJumpTo.title}" was missing tag used in workflow:</span><span style:padding-left="0.2rem"><b>{missingTag}</b></span></div>
138+
<div>Tags on node: <b>{(nodeToJumpTo?.properties?.tags || []).join(", ")}</b></div>
139+
</div>
140+
{:else}
141+
<span class="error-message" class:execution-error={isExecutionError}>{error.message}</span>
142+
{/if}
92143
{#if error.exceptionType}
93144
<span>({error.exceptionType})</span>
94145
{/if}
95146
{#if error.exceptionMessage && !isExecutionError}
96147
<div style:text-decoration="underline">{error.exceptionMessage}</div>
97148
{/if}
98-
{#if error.input}
149+
{#if nodeToJumpTo != null}
150+
<div style:display="flex" style:flex-direction="row">
151+
<button class="jump-to-error locate" on:click={jumpToFoundNode}><span>⮎</span></button>
152+
{#if missingTag}
153+
<span>Jump to node: {nodeToJumpTo.title}</span>
154+
{:else}
155+
<span>Find disconnected input</span>
156+
{/if}
157+
</div>
158+
{/if}
159+
{#if error.input && !missingTag}
99160
<div class="error-input">
100161
<span>Input: <b>{error.input.name}</b></span>
101162
{#if error.input.config}
102163
<span>({getInputTypeName(error.input.config[0])})</span>
103164
{/if}
104165
</div>
105-
{#if canJumpToDisconnectedInput(error)}
106-
<div style:display="flex" style:flex-direction="row">
107-
<button class="jump-to-error locate" on:click={() => jumpToDisconnectedInput(error)}><span>⮎</span></button>
108-
<span>Find disconnected input</span>
109-
</div>
110-
{/if}
111166

112167
{#if error.input.receivedValue}
113168
<div>

0 commit comments

Comments
 (0)