Queued workflows are at app level
This commit is contained in:
parent
27d19732b8
commit
f02b398cef
5 changed files with 425 additions and 137 deletions
|
|
@ -2,6 +2,7 @@ import { Routes, Route, Navigate } from 'react-router-dom'
|
|||
import { ProjectProvider } from './context/ProjectContext'
|
||||
import { SettingsProvider } from './context/SettingsContext'
|
||||
import { NotificationProvider } from './context/NotificationContext'
|
||||
import { WorkflowJobsProvider } from './context/WorkflowJobsContext'
|
||||
import ProjectsPage from './pages/ProjectsPage'
|
||||
import ProjectWorkspacePage from './pages/ProjectWorkspacePage'
|
||||
import AssetsPage from './pages/AssetsPage'
|
||||
|
|
@ -32,7 +33,9 @@ export default function App() {
|
|||
<NotificationProvider>
|
||||
<SettingsProvider>
|
||||
<ProjectProvider>
|
||||
<AppRoutes />
|
||||
<WorkflowJobsProvider>
|
||||
<AppRoutes />
|
||||
</WorkflowJobsProvider>
|
||||
</ProjectProvider>
|
||||
</SettingsProvider>
|
||||
</NotificationProvider>
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ export default function KanbanImageCard({
|
|||
handleDeleteCustomAttribute
|
||||
}) {
|
||||
const runtimeState = getCardRuntimeState(card)
|
||||
const cardLocked = runtimeState?.status === 'processing'
|
||||
const cardLocked = runtimeState?.status === 'processing' || runtimeState?.status === 'queued'
|
||||
const canFetchAsyncResult = canFetchTencentMeshResult(runtimeState) || canFetchTripoMeshResult(runtimeState)
|
||||
const displaySourceLabel = runtimeState?.source
|
||||
? String(runtimeState.source).toUpperCase()
|
||||
|
|
|
|||
201
src/context/WorkflowJobsContext.jsx
Normal file
201
src/context/WorkflowJobsContext.jsx
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
/* eslint-disable react-refresh/only-export-components */
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
||||
import { useProjects } from './ProjectContext'
|
||||
import { useNotifications } from './NotificationContext'
|
||||
|
||||
const WorkflowJobsContext = createContext(null)
|
||||
|
||||
// App-level registry of in-flight ComfyUI workflow jobs. It owns the SSE
|
||||
// progress connection for each job so progress keeps flowing while the user
|
||||
// navigates between pages/projects, and fires a global notification when a job
|
||||
// finishes. Pages register a job when they start a workflow and report the
|
||||
// terminal status; they observe live progress by reading `jobs`.
|
||||
function createJobsStore() {
|
||||
const jobsById = new Map()
|
||||
let snapshot = []
|
||||
const listeners = new Set()
|
||||
|
||||
const rebuild = () => {
|
||||
snapshot = Array.from(jobsById.values())
|
||||
}
|
||||
|
||||
return {
|
||||
getSnapshot: () => snapshot,
|
||||
subscribe: (listener) => {
|
||||
listeners.add(listener)
|
||||
return () => listeners.delete(listener)
|
||||
},
|
||||
emit: () => {
|
||||
rebuild()
|
||||
listeners.forEach(listener => listener())
|
||||
},
|
||||
get: (id) => jobsById.get(id),
|
||||
has: (id) => jobsById.has(id),
|
||||
set: (id, job) => jobsById.set(id, job),
|
||||
delete: (id) => jobsById.delete(id),
|
||||
values: () => Array.from(jobsById.values())
|
||||
}
|
||||
}
|
||||
|
||||
export function WorkflowJobsProvider({ children }) {
|
||||
const { subscribeToComfyWorkflowProgress } = useProjects()
|
||||
const { addNotification } = useNotifications()
|
||||
|
||||
const [store] = useState(createJobsStore)
|
||||
const subscriptionsRef = useRef(new Map())
|
||||
|
||||
const closeSubscription = useCallback((id) => {
|
||||
subscriptionsRef.current.get(id)?.()
|
||||
subscriptionsRef.current.delete(id)
|
||||
}, [])
|
||||
|
||||
const registerJob = useCallback((init = {}) => {
|
||||
const id = init.id
|
||||
if (!id) {
|
||||
return null
|
||||
}
|
||||
|
||||
// Re-registering the same promptId (e.g. a retry) replaces the old job.
|
||||
closeSubscription(id)
|
||||
|
||||
store.set(id, {
|
||||
id,
|
||||
projectId: init.projectId ?? null,
|
||||
projectName: init.projectName ?? '',
|
||||
page: init.page ?? '',
|
||||
targetId: init.targetId != null ? String(init.targetId) : null,
|
||||
kind: init.kind ?? '',
|
||||
label: init.label || 'Workflow',
|
||||
status: 'queued',
|
||||
progressPercent: 0,
|
||||
detail: init.detail || 'Waiting for ComfyUI execution to start',
|
||||
currentNodeLabel: null,
|
||||
error: null,
|
||||
createdAt: Date.now(),
|
||||
completedAt: null
|
||||
})
|
||||
store.emit()
|
||||
|
||||
const unsubscribe = subscribeToComfyWorkflowProgress(id, {
|
||||
onMessage: (payload) => {
|
||||
const current = store.get(id)
|
||||
if (!current || current.status === 'completed' || current.status === 'error') {
|
||||
return
|
||||
}
|
||||
store.set(id, {
|
||||
...current,
|
||||
status: payload?.status === 'error' ? 'error' : 'processing',
|
||||
progressPercent: Math.max(current.progressPercent || 0, Number(payload?.progressPercent) || 0),
|
||||
detail: payload?.detail || current.detail,
|
||||
currentNodeLabel: payload?.currentNodeLabel || current.currentNodeLabel
|
||||
})
|
||||
store.emit()
|
||||
},
|
||||
onError: () => {}
|
||||
})
|
||||
subscriptionsRef.current.set(id, unsubscribe)
|
||||
|
||||
return id
|
||||
}, [store, closeSubscription, subscribeToComfyWorkflowProgress])
|
||||
|
||||
const completeJob = useCallback((id, result = {}) => {
|
||||
closeSubscription(id)
|
||||
|
||||
const current = store.get(id)
|
||||
const status = result.status === 'error' ? 'error' : 'completed'
|
||||
const label = current?.label || result.label || 'Workflow'
|
||||
const projectName = current?.projectName || result.projectName || ''
|
||||
const suffix = projectName ? ` — ${projectName}` : ''
|
||||
|
||||
if (current) {
|
||||
store.set(id, {
|
||||
...current,
|
||||
status,
|
||||
progressPercent: status === 'completed' ? 100 : current.progressPercent,
|
||||
detail: result.detail || current.detail,
|
||||
error: status === 'error' ? (result.error || current.error || 'Workflow failed') : null,
|
||||
completedAt: Date.now()
|
||||
})
|
||||
store.emit()
|
||||
}
|
||||
|
||||
if (status === 'completed') {
|
||||
addNotification({
|
||||
title: 'Workflow completed',
|
||||
message: `${label}${suffix}`,
|
||||
source: 'ComfyUI',
|
||||
tone: 'success'
|
||||
})
|
||||
} else {
|
||||
addNotification({
|
||||
title: 'Workflow failed',
|
||||
message: `${result.error || label}${suffix}`,
|
||||
source: 'ComfyUI',
|
||||
tone: 'error'
|
||||
})
|
||||
}
|
||||
}, [store, closeSubscription, addNotification])
|
||||
|
||||
const removeJob = useCallback((id) => {
|
||||
closeSubscription(id)
|
||||
if (store.has(id)) {
|
||||
store.delete(id)
|
||||
store.emit()
|
||||
}
|
||||
}, [store, closeSubscription])
|
||||
|
||||
const removeJobsForTarget = useCallback((projectId, targetId) => {
|
||||
const target = targetId != null ? String(targetId) : null
|
||||
let changed = false
|
||||
store.values().forEach(job => {
|
||||
if (job.projectId === projectId && job.targetId === target) {
|
||||
closeSubscription(job.id)
|
||||
store.delete(job.id)
|
||||
changed = true
|
||||
}
|
||||
})
|
||||
if (changed) {
|
||||
store.emit()
|
||||
}
|
||||
}, [store, closeSubscription])
|
||||
|
||||
// Close every open connection only when the whole app unmounts.
|
||||
useEffect(() => {
|
||||
const subscriptions = subscriptionsRef.current
|
||||
return () => {
|
||||
subscriptions.forEach(unsubscribe => unsubscribe?.())
|
||||
subscriptions.clear()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const value = useMemo(() => ({
|
||||
store,
|
||||
registerJob,
|
||||
completeJob,
|
||||
removeJob,
|
||||
removeJobsForTarget
|
||||
}), [store, registerJob, completeJob, removeJob, removeJobsForTarget])
|
||||
|
||||
return (
|
||||
<WorkflowJobsContext.Provider value={value}>
|
||||
{children}
|
||||
</WorkflowJobsContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useWorkflowJobs() {
|
||||
const context = useContext(WorkflowJobsContext)
|
||||
if (!context) {
|
||||
throw new Error('useWorkflowJobs must be used within WorkflowJobsProvider')
|
||||
}
|
||||
|
||||
const jobs = useSyncExternalStore(context.store.subscribe, context.store.getSnapshot)
|
||||
|
||||
return {
|
||||
jobs,
|
||||
registerJob: context.registerJob,
|
||||
completeJob: context.completeJob,
|
||||
removeJob: context.removeJob,
|
||||
removeJobsForTarget: context.removeJobsForTarget
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import SettingsModal from '../components/SettingsModal'
|
|||
import { useProjects } from '../context/ProjectContext'
|
||||
import { useSettings } from '../context/SettingsContext.shared'
|
||||
import { useNotifications } from '../context/NotificationContext'
|
||||
import { useWorkflowJobs } from '../context/WorkflowJobsContext'
|
||||
import { createMeshThumbnailFile } from '../utils/meshThumbnail'
|
||||
import '@xyflow/react/dist/style.css'
|
||||
import './KanbanPage.css'
|
||||
|
|
@ -123,7 +124,6 @@ export default function GraphPage({ project }) {
|
|||
getComfyWorkflows,
|
||||
updateComfyWorkflow,
|
||||
runComfyWorkflow,
|
||||
subscribeToComfyWorkflowProgress,
|
||||
runImageEditApi,
|
||||
runImageEditComfy,
|
||||
runMeshGenerationApi,
|
||||
|
|
@ -132,6 +132,7 @@ export default function GraphPage({ project }) {
|
|||
} = useProjects()
|
||||
const { settings } = useSettings()
|
||||
const { addNotification } = useNotifications()
|
||||
const { jobs: workflowJobs, registerJob, completeJob, removeJobsForTarget } = useWorkflowJobs()
|
||||
|
||||
const [showSettings, setShowSettings] = useState(false)
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
|
@ -154,7 +155,6 @@ export default function GraphPage({ project }) {
|
|||
const pendingUploadNodeIdRef = useRef(null)
|
||||
const pendingConnectionRef = useRef(null)
|
||||
const skipNextPaneClickRef = useRef(false)
|
||||
const progressSubscriptionsRef = useRef(new Map())
|
||||
const libraryLoadedRef = useRef(false)
|
||||
const workflowsLoadedRef = useRef(false)
|
||||
const graphCanvasRef = useRef(null)
|
||||
|
|
@ -379,11 +379,6 @@ export default function GraphPage({ project }) {
|
|||
}
|
||||
}, [meshGenerationApis, meshGenerationWorkflows])
|
||||
|
||||
const closeNodeProgressSubscription = useCallback((nodeId) => {
|
||||
progressSubscriptionsRef.current.get(String(nodeId))?.()
|
||||
progressSubscriptionsRef.current.delete(String(nodeId))
|
||||
}, [])
|
||||
|
||||
const replaceFlowNodeData = useCallback((updatedNode) => {
|
||||
setNodes(currentNodes => currentNodes.map(node => (
|
||||
node.id === String(updatedNode.id)
|
||||
|
|
@ -494,16 +489,59 @@ export default function GraphPage({ project }) {
|
|||
}
|
||||
}, [nodes, project.id, replaceFlowNodeData, setNodes, updateProjectNode])
|
||||
|
||||
// Live workflow progress is owned by the app-level WorkflowJobs store so it
|
||||
// survives navigating away from this page. While the page is mounted, mirror
|
||||
// the progress of any in-flight job onto its node for display.
|
||||
useEffect(() => {
|
||||
const subscriptions = progressSubscriptionsRef.current
|
||||
return () => {
|
||||
subscriptions.forEach(unsubscribe => unsubscribe?.())
|
||||
subscriptions.clear()
|
||||
if (!project?.id) {
|
||||
return
|
||||
}
|
||||
}, [])
|
||||
const activeJobs = workflowJobs.filter(job => (
|
||||
job.projectId === project.id
|
||||
&& job.page === 'graph'
|
||||
&& job.targetId
|
||||
&& (job.status === 'queued' || job.status === 'processing')
|
||||
))
|
||||
if (activeJobs.length === 0) {
|
||||
return
|
||||
}
|
||||
setNodes(current => {
|
||||
let changed = false
|
||||
const next = current.map(item => {
|
||||
const job = activeJobs.find(candidate => candidate.targetId === item.id)
|
||||
if (!job) {
|
||||
return item
|
||||
}
|
||||
const nextStatus = job.status === 'error' ? 'error' : 'processing'
|
||||
const nextProgress = Math.max(Number(item.data.progress) || 0, Number(job.progressPercent) || 0)
|
||||
const nextDetail = job.detail || item.data.progressDetail || null
|
||||
const nextLabel = job.currentNodeLabel || item.data.currentNodeLabel || null
|
||||
if (
|
||||
item.data.status === nextStatus
|
||||
&& item.data.progress === nextProgress
|
||||
&& item.data.progressDetail === nextDetail
|
||||
&& item.data.currentNodeLabel === nextLabel
|
||||
) {
|
||||
return item
|
||||
}
|
||||
changed = true
|
||||
return {
|
||||
...item,
|
||||
data: {
|
||||
...item.data,
|
||||
status: nextStatus,
|
||||
progress: nextProgress,
|
||||
progressDetail: nextDetail,
|
||||
currentNodeLabel: nextLabel
|
||||
}
|
||||
}
|
||||
})
|
||||
return changed ? next : current
|
||||
})
|
||||
}, [workflowJobs, project?.id, setNodes])
|
||||
|
||||
const handleDeleteNode = useCallback(async (nodeId) => {
|
||||
closeNodeProgressSubscription(nodeId)
|
||||
removeJobsForTarget(project.id, nodeId)
|
||||
await deleteProjectNode(project.id, Number(nodeId))
|
||||
setNodes(currentNodes => currentNodes.filter(node => node.id !== String(nodeId)))
|
||||
setEdges(currentEdges => currentEdges.filter(edge => edge.source !== String(nodeId) && edge.target !== String(nodeId)))
|
||||
|
|
@ -512,7 +550,7 @@ export default function GraphPage({ project }) {
|
|||
delete nextDrafts[String(nodeId)]
|
||||
return nextDrafts
|
||||
})
|
||||
}, [closeNodeProgressSubscription, deleteProjectNode, project.id, setEdges, setNodes])
|
||||
}, [removeJobsForTarget, deleteProjectNode, project.id, setEdges, setNodes])
|
||||
|
||||
const ensureGeneratedMeshThumbnail = useCallback(async (asset) => {
|
||||
if (!asset || asset.type !== 'mesh' || asset.thumbnail) {
|
||||
|
|
@ -1241,26 +1279,15 @@ export default function GraphPage({ project }) {
|
|||
const promptId = createComfyExecutionId('graph-text-prompt')
|
||||
const clientId = createComfyExecutionId('graph-text-client')
|
||||
setActionDraftsByNodeId({})
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
progressSubscriptionsRef.current.set(String(targetNodeId), subscribeToComfyWorkflowProgress(promptId, {
|
||||
onMessage: payload => {
|
||||
setNodes(current => current.map(item => (
|
||||
item.id === String(targetNodeId)
|
||||
? {
|
||||
...item,
|
||||
data: {
|
||||
...item.data,
|
||||
status: payload?.status === 'error' ? 'error' : 'processing',
|
||||
progress: Math.max(Number(item.data.progress) || 0, Number(payload?.progressPercent) || 0),
|
||||
progressDetail: payload?.detail || item.data.progressDetail || null,
|
||||
currentNodeLabel: payload?.currentNodeLabel || item.data.currentNodeLabel || null
|
||||
}
|
||||
}
|
||||
: item
|
||||
)))
|
||||
},
|
||||
onError: () => {}
|
||||
}))
|
||||
registerJob({
|
||||
id: promptId,
|
||||
projectId: project.id,
|
||||
projectName: project.name,
|
||||
page: 'graph',
|
||||
targetId: targetNodeId,
|
||||
kind: 'text',
|
||||
label: targetNode.data.name || workflow.name
|
||||
})
|
||||
|
||||
await setProcessingState('processing', 0, { processingSource: 'ComfyUI', promptId }, {
|
||||
progressDetail: 'Preparing ComfyUI workflow',
|
||||
|
|
@ -1305,10 +1332,10 @@ export default function GraphPage({ project }) {
|
|||
progressDetail: null,
|
||||
currentNodeLabel: null
|
||||
})
|
||||
completeJob(promptId, { status: 'completed' })
|
||||
} catch (err) {
|
||||
await setProcessingState('error', null, { error: err.message || 'ComfyUI workflow failed', promptId })
|
||||
} finally {
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
completeJob(promptId, { status: 'error', error: err.message || 'ComfyUI workflow failed' })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -1392,26 +1419,15 @@ export default function GraphPage({ project }) {
|
|||
const promptId = createComfyExecutionId('graph-image-prompt')
|
||||
const clientId = createComfyExecutionId('graph-image-client')
|
||||
setActionDraftsByNodeId({})
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
progressSubscriptionsRef.current.set(String(targetNodeId), subscribeToComfyWorkflowProgress(promptId, {
|
||||
onMessage: payload => {
|
||||
setNodes(current => current.map(item => (
|
||||
item.id === String(targetNodeId)
|
||||
? {
|
||||
...item,
|
||||
data: {
|
||||
...item.data,
|
||||
status: payload?.status === 'error' ? 'error' : 'processing',
|
||||
progress: Math.max(Number(item.data.progress) || 0, Number(payload?.progressPercent) || 0),
|
||||
progressDetail: payload?.detail || item.data.progressDetail || null,
|
||||
currentNodeLabel: payload?.currentNodeLabel || item.data.currentNodeLabel || null
|
||||
}
|
||||
}
|
||||
: item
|
||||
)))
|
||||
},
|
||||
onError: () => {}
|
||||
}))
|
||||
registerJob({
|
||||
id: promptId,
|
||||
projectId: project.id,
|
||||
projectName: project.name,
|
||||
page: 'graph',
|
||||
targetId: targetNodeId,
|
||||
kind: 'image',
|
||||
label: targetDraft.name.trim() || workflow.name
|
||||
})
|
||||
|
||||
await setProcessingState('processing', 0, { processingSource: 'ComfyUI', promptId }, {
|
||||
progressDetail: 'Preparing ComfyUI workflow',
|
||||
|
|
@ -1448,10 +1464,10 @@ export default function GraphPage({ project }) {
|
|||
await spawnAdditionalResultNodes('Image', imageAssets.slice(1))
|
||||
}
|
||||
await persistWorkflowDefaultsIfRequested(targetDraft, workflow, inputValues)
|
||||
completeJob(promptId, { status: 'completed' })
|
||||
} catch (err) {
|
||||
await setProcessingState('error', null, { error: err.message || 'ComfyUI workflow failed', promptId })
|
||||
} finally {
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
completeJob(promptId, { status: 'error', error: err.message || 'ComfyUI workflow failed' })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -1552,26 +1568,15 @@ export default function GraphPage({ project }) {
|
|||
const promptId = createComfyExecutionId('graph-image-edit-prompt')
|
||||
const clientId = createComfyExecutionId('graph-image-edit-client')
|
||||
setActionDraftsByNodeId({})
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
progressSubscriptionsRef.current.set(String(targetNodeId), subscribeToComfyWorkflowProgress(promptId, {
|
||||
onMessage: payload => {
|
||||
setNodes(current => current.map(item => (
|
||||
item.id === String(targetNodeId)
|
||||
? {
|
||||
...item,
|
||||
data: {
|
||||
...item.data,
|
||||
status: payload?.status === 'error' ? 'error' : 'processing',
|
||||
progress: Math.max(Number(item.data.progress) || 0, Number(payload?.progressPercent) || 0),
|
||||
progressDetail: payload?.detail || item.data.progressDetail || null,
|
||||
currentNodeLabel: payload?.currentNodeLabel || item.data.currentNodeLabel || null
|
||||
}
|
||||
}
|
||||
: item
|
||||
)))
|
||||
},
|
||||
onError: () => {}
|
||||
}))
|
||||
registerJob({
|
||||
id: promptId,
|
||||
projectId: project.id,
|
||||
projectName: project.name,
|
||||
page: 'graph',
|
||||
targetId: targetNodeId,
|
||||
kind: 'imageEdit',
|
||||
label: targetDraft.name.trim() || 'Image edit'
|
||||
})
|
||||
|
||||
await setProcessingState('processing', 0, { processingSource: 'ComfyUI', promptId }, {
|
||||
progressDetail: 'Preparing ComfyUI image edit',
|
||||
|
|
@ -1613,10 +1618,10 @@ export default function GraphPage({ project }) {
|
|||
})))
|
||||
}
|
||||
await persistWorkflowDefaultsIfRequested(targetDraft, workflow, inputValues)
|
||||
completeJob(promptId, { status: 'completed' })
|
||||
} catch (err) {
|
||||
await setProcessingState('error', null, { error: err.message || 'ComfyUI image edit failed', promptId })
|
||||
} finally {
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
completeJob(promptId, { status: 'error', error: err.message || 'ComfyUI image edit failed' })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -1985,26 +1990,15 @@ export default function GraphPage({ project }) {
|
|||
const promptId = createComfyExecutionId('graph-mesh-gen-prompt')
|
||||
const clientId = createComfyExecutionId('graph-mesh-gen-client')
|
||||
setActionDraftsByNodeId({})
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
progressSubscriptionsRef.current.set(String(targetNodeId), subscribeToComfyWorkflowProgress(promptId, {
|
||||
onMessage: payload => {
|
||||
setNodes(current => current.map(item => (
|
||||
item.id === String(targetNodeId)
|
||||
? {
|
||||
...item,
|
||||
data: {
|
||||
...item.data,
|
||||
status: payload?.status === 'error' ? 'error' : 'processing',
|
||||
progress: Math.max(Number(item.data.progress) || 0, Number(payload?.progressPercent) || 0),
|
||||
progressDetail: payload?.detail || item.data.progressDetail || null,
|
||||
currentNodeLabel: payload?.currentNodeLabel || item.data.currentNodeLabel || null
|
||||
}
|
||||
}
|
||||
: item
|
||||
)))
|
||||
},
|
||||
onError: () => {}
|
||||
}))
|
||||
registerJob({
|
||||
id: promptId,
|
||||
projectId: project.id,
|
||||
projectName: project.name,
|
||||
page: 'graph',
|
||||
targetId: targetNodeId,
|
||||
kind: 'mesh',
|
||||
label: targetDraft.name.trim() || workflow.name
|
||||
})
|
||||
|
||||
await setProcessingState('processing', 0, { processingSource: 'ComfyUI', promptId }, {
|
||||
progressDetail: 'Preparing ComfyUI mesh generation',
|
||||
|
|
@ -2046,10 +2040,10 @@ export default function GraphPage({ project }) {
|
|||
await spawnAdditionalResultNodes('Mesh Gen', meshAssets.slice(1))
|
||||
}
|
||||
await persistWorkflowDefaultsIfRequested(targetDraft, workflow, inputValues)
|
||||
completeJob(promptId, { status: 'completed' })
|
||||
} catch (err) {
|
||||
await setProcessingState('error', null, { error: err.message || 'ComfyUI mesh generation failed', promptId })
|
||||
} finally {
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
completeJob(promptId, { status: 'error', error: err.message || 'ComfyUI mesh generation failed' })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -2143,26 +2137,15 @@ export default function GraphPage({ project }) {
|
|||
const promptId = createComfyExecutionId('graph-image-edit-prompt')
|
||||
const clientId = createComfyExecutionId('graph-image-edit-client')
|
||||
setActionDraftsByNodeId({})
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
progressSubscriptionsRef.current.set(String(targetNodeId), subscribeToComfyWorkflowProgress(promptId, {
|
||||
onMessage: payload => {
|
||||
setNodes(current => current.map(item => (
|
||||
item.id === String(targetNodeId)
|
||||
? {
|
||||
...item,
|
||||
data: {
|
||||
...item.data,
|
||||
status: payload?.status === 'error' ? 'error' : 'processing',
|
||||
progress: Math.max(Number(item.data.progress) || 0, Number(payload?.progressPercent) || 0),
|
||||
progressDetail: payload?.detail || item.data.progressDetail || null,
|
||||
currentNodeLabel: payload?.currentNodeLabel || item.data.currentNodeLabel || null
|
||||
}
|
||||
}
|
||||
: item
|
||||
)))
|
||||
},
|
||||
onError: () => {}
|
||||
}))
|
||||
registerJob({
|
||||
id: promptId,
|
||||
projectId: project.id,
|
||||
projectName: project.name,
|
||||
page: 'graph',
|
||||
targetId: targetNodeId,
|
||||
kind: 'imageEdit',
|
||||
label: targetDraft.name.trim() || 'Image edit'
|
||||
})
|
||||
|
||||
await setProcessingState('processing', 0, { processingSource: 'ComfyUI', promptId }, {
|
||||
progressDetail: 'Preparing ComfyUI image edit',
|
||||
|
|
@ -2198,10 +2181,10 @@ export default function GraphPage({ project }) {
|
|||
name: edit.name || targetDraft.name.trim()
|
||||
})))
|
||||
}
|
||||
completeJob(promptId, { status: 'completed' })
|
||||
} catch (err) {
|
||||
await setProcessingState('error', null, { error: err.message || 'ComfyUI image edit failed', promptId })
|
||||
} finally {
|
||||
closeNodeProgressSubscription(targetNodeId)
|
||||
completeJob(promptId, { status: 'error', error: err.message || 'ComfyUI image edit failed' })
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -2384,7 +2367,7 @@ export default function GraphPage({ project }) {
|
|||
},
|
||||
onCloseAction: () => setActionDraftsByNodeId({})
|
||||
}
|
||||
})}), [actionDraftsByNodeId, attachExistingAsset, closeNodeProgressSubscription, comfyLoading, createImageEditNodeDraft, createImageNodeDraft, createMeshGenNodeDraft, createTextNodeDraft, createProjectConnection, edges, ensureComfyWorkflowsLoaded, ensureGeneratedMeshThumbnails, ensureLibraryLoaded, generateImage, getConnectedInputAssetFrom, handleCreateNode, handleNodeNameChange, handleNodeNameCommit, handleNodeOutputValueChange, handleNodeOutputValueCommit, handleOpenAssetSelector, imageEditApis, imageEditWorkflows, imageGenerationApis, imageGenerationWorkflows, libraryImageOptions, libraryLoading, libraryMeshOptions, meshGenerationApis, meshGenerationWorkflows, textGenerationWorkflows, nodes, openActionDraft, project.id, pushExternalApiFailureNotification, pushMeshGenerationFailureNotification, queryTencentMeshGenerationResult, queryTripoMeshGenerationResult, replaceFlowNodeData, runComfyWorkflow, runImageEditApi, runImageEditComfy, runMeshGenerationApi, persistWorkflowDefaultsIfRequested, setEdges, setNodeTransientData, setNodes, subscribeToComfyWorkflowProgress, updateProjectNode])
|
||||
})}), [actionDraftsByNodeId, attachExistingAsset, comfyLoading, completeJob, createImageEditNodeDraft, createImageNodeDraft, createMeshGenNodeDraft, createTextNodeDraft, createProjectConnection, edges, ensureComfyWorkflowsLoaded, ensureGeneratedMeshThumbnails, ensureLibraryLoaded, generateImage, getConnectedInputAssetFrom, handleCreateNode, handleNodeNameChange, handleNodeNameCommit, handleNodeOutputValueChange, handleNodeOutputValueCommit, handleOpenAssetSelector, imageEditApis, imageEditWorkflows, imageGenerationApis, imageGenerationWorkflows, libraryImageOptions, libraryLoading, libraryMeshOptions, meshGenerationApis, meshGenerationWorkflows, textGenerationWorkflows, nodes, openActionDraft, project.id, project.name, pushExternalApiFailureNotification, pushMeshGenerationFailureNotification, queryTencentMeshGenerationResult, queryTripoMeshGenerationResult, registerJob, replaceFlowNodeData, runComfyWorkflow, runImageEditApi, runImageEditComfy, runMeshGenerationApi, persistWorkflowDefaultsIfRequested, setEdges, setNodeTransientData, setNodes, updateProjectNode])
|
||||
|
||||
const handleFileUpload = useCallback(async (event) => {
|
||||
const file = event.target.files?.[0]
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { useParams, useNavigate } from 'react-router-dom'
|
|||
import { useProjects } from '../context/ProjectContext'
|
||||
import { useSettings } from '../context/SettingsContext.shared'
|
||||
import { useNotifications } from '../context/NotificationContext'
|
||||
import { useWorkflowJobs } from '../context/WorkflowJobsContext'
|
||||
import Header from '../components/Header'
|
||||
import Footer from '../components/Footer'
|
||||
import Viewer from '../components/Viewer'
|
||||
|
|
@ -86,7 +87,8 @@ export default function KanbanPage() {
|
|||
} = useProjects()
|
||||
const { settings } = useSettings()
|
||||
const { addNotification } = useNotifications()
|
||||
|
||||
const { jobs: workflowJobs, registerJob, completeJob } = useWorkflowJobs()
|
||||
|
||||
const [project, setProject] = useState(null)
|
||||
const [assets, setAssets] = useState([])
|
||||
const [projectCards, setProjectCards] = useState([])
|
||||
|
|
@ -507,10 +509,11 @@ export default function KanbanPage() {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const comfyClientId = createComfyExecutionId('comfy-client')
|
||||
const promptId = createComfyExecutionId('comfy-prompt')
|
||||
const cardId = draft.cardId || createImageCardId()
|
||||
const comfyClientId = createComfyExecutionId('comfy-client')
|
||||
const promptId = createComfyExecutionId('comfy-prompt')
|
||||
|
||||
try {
|
||||
setPendingImageGeneration({
|
||||
title: workflow.name,
|
||||
source: 'ComfyUI',
|
||||
|
|
@ -521,11 +524,20 @@ export default function KanbanPage() {
|
|||
})
|
||||
setImageDraft(null)
|
||||
setLoading(true)
|
||||
registerJob({
|
||||
id: promptId,
|
||||
projectId,
|
||||
projectName: project?.name || '',
|
||||
page: 'kanban',
|
||||
targetId: cardId,
|
||||
kind: 'image',
|
||||
label: workflow.name
|
||||
})
|
||||
openPendingComfyProgressSubscription(promptId)
|
||||
await runComfyWorkflow(projectId, {
|
||||
workflowId: draft.workflowId,
|
||||
inputs: draft.inputs || {},
|
||||
cardId: draft.cardId || createImageCardId(),
|
||||
cardId,
|
||||
clientId: comfyClientId,
|
||||
promptId
|
||||
})
|
||||
|
|
@ -537,10 +549,12 @@ export default function KanbanPage() {
|
|||
} : prev)
|
||||
await persistWorkflowDefaultsIfRequested(draft, workflow)
|
||||
await refreshProjectAssets()
|
||||
completeJob(promptId, { status: 'completed' })
|
||||
} catch (err) {
|
||||
console.error('ComfyUI workflow failed:', err)
|
||||
setImageDraft(draft)
|
||||
showStatusMessage(err.message || 'ComfyUI workflow failed', 'error')
|
||||
completeJob(promptId, { status: 'error', error: err.message || 'ComfyUI workflow failed' })
|
||||
await refreshProjectAssets().catch(refreshErr => {
|
||||
console.error('Failed to refresh project assets after ComfyUI workflow error:', refreshErr)
|
||||
})
|
||||
|
|
@ -841,6 +855,27 @@ export default function KanbanPage() {
|
|||
})
|
||||
}, [imageCards, imageEditProgressByCardId, projectId, getProjectAssets, getProjectCards, subscribeToComfyWorkflowProgress])
|
||||
|
||||
// A workflow tracked by the app-level store may finish while this page is
|
||||
// unmounted (or after returning to it). When one reaches a terminal state,
|
||||
// refresh the board once so the persisted "processing" snapshot clears, the
|
||||
// card unlocks, and the new result is shown.
|
||||
const handledTerminalJobsRef = useRef(new Set())
|
||||
useEffect(() => {
|
||||
const finished = workflowJobs.filter(job => (
|
||||
job.page === 'kanban'
|
||||
&& job.projectId === projectId
|
||||
&& (job.status === 'completed' || job.status === 'error')
|
||||
&& !handledTerminalJobsRef.current.has(job.id)
|
||||
))
|
||||
if (finished.length === 0) {
|
||||
return
|
||||
}
|
||||
finished.forEach(job => handledTerminalJobsRef.current.add(job.id))
|
||||
refreshProjectAssets().catch(err => {
|
||||
console.error('Failed to refresh project assets after workflow completion:', err)
|
||||
})
|
||||
}, [workflowJobs, projectId, refreshProjectAssets])
|
||||
|
||||
const cardAttributesByCardId = useMemo(() => {
|
||||
return cardAttributes.reduce((accumulator, attribute) => {
|
||||
if (!accumulator[attribute.cardId]) {
|
||||
|
|
@ -1073,11 +1108,10 @@ export default function KanbanPage() {
|
|||
}
|
||||
|
||||
const cardId = draft.cardId || createImageCardId()
|
||||
const comfyClientId = createComfyExecutionId('comfy-client')
|
||||
const promptId = createComfyExecutionId('comfy-prompt')
|
||||
|
||||
try {
|
||||
const comfyClientId = createComfyExecutionId('comfy-client')
|
||||
const promptId = createComfyExecutionId('comfy-prompt')
|
||||
|
||||
setPendingMeshGeneration({
|
||||
title: workflow.name,
|
||||
source: 'ComfyUI',
|
||||
|
|
@ -1088,6 +1122,15 @@ export default function KanbanPage() {
|
|||
})
|
||||
setMeshDraft(null)
|
||||
setLoading(true)
|
||||
registerJob({
|
||||
id: promptId,
|
||||
projectId,
|
||||
projectName: project?.name || '',
|
||||
page: 'kanban',
|
||||
targetId: cardId,
|
||||
kind: 'mesh',
|
||||
label: workflow.name
|
||||
})
|
||||
openPendingMeshProgressSubscription(promptId)
|
||||
const generatedMeshes = await runComfyWorkflow(projectId, {
|
||||
workflowId: draft.workflowId,
|
||||
|
|
@ -1106,10 +1149,12 @@ export default function KanbanPage() {
|
|||
await moveCardToMeshGen(cardId)
|
||||
await ensureGeneratedMeshThumbnails(generatedMeshes)
|
||||
await refreshProjectAssets()
|
||||
completeJob(promptId, { status: 'completed' })
|
||||
} catch (err) {
|
||||
console.error('ComfyUI mesh workflow failed:', err)
|
||||
setMeshDraft(draft)
|
||||
showStatusMessage(err.message || 'ComfyUI workflow failed', 'error')
|
||||
completeJob(promptId, { status: 'error', error: err.message || 'ComfyUI workflow failed' })
|
||||
await refreshProjectAssets().catch(refreshErr => {
|
||||
console.error('Failed to refresh project assets after ComfyUI workflow error:', refreshErr)
|
||||
})
|
||||
|
|
@ -1989,6 +2034,7 @@ export default function KanbanPage() {
|
|||
const existingSourceChildCount = selectedImageSourceGroup ? getAssetChildren(selectedImageSourceGroup.asset).length : 0
|
||||
|
||||
let keepRuntimeState = false
|
||||
let comfyEditPromptId = null
|
||||
|
||||
try {
|
||||
setImageEditPendingCardId(card.id)
|
||||
|
|
@ -2277,6 +2323,17 @@ export default function KanbanPage() {
|
|||
|
||||
const promptId = createComfyExecutionId('comfy-edit-prompt')
|
||||
const clientId = createComfyExecutionId('comfy-edit-client')
|
||||
comfyEditPromptId = promptId
|
||||
|
||||
registerJob({
|
||||
id: promptId,
|
||||
projectId,
|
||||
projectName: project?.name || '',
|
||||
page: 'kanban',
|
||||
targetId: card.id,
|
||||
kind: isMeshWorkflowCard ? 'mesh' : 'imageEdit',
|
||||
label: name || actionLabel
|
||||
})
|
||||
|
||||
setImageEditProgressByCardId(prev => ({
|
||||
...prev,
|
||||
|
|
@ -2386,6 +2443,9 @@ export default function KanbanPage() {
|
|||
|
||||
await refreshProjectAssets()
|
||||
closeImageEditActionMenu()
|
||||
if (comfyEditPromptId) {
|
||||
completeJob(comfyEditPromptId, { status: 'completed' })
|
||||
}
|
||||
showStatusMessage(isMeshGenCard
|
||||
? 'Mesh generation completed successfully.'
|
||||
: isMeshEditCard
|
||||
|
|
@ -2408,6 +2468,10 @@ export default function KanbanPage() {
|
|||
|
||||
showStatusMessage(failureMessage, 'error')
|
||||
|
||||
if (comfyEditPromptId) {
|
||||
completeJob(comfyEditPromptId, { status: 'error', error: failureMessage })
|
||||
}
|
||||
|
||||
if (imageEditDraft?.mode === 'api') {
|
||||
if (isMeshGenCard) {
|
||||
pushExternalApiFailureNotification(
|
||||
|
|
@ -2456,16 +2520,53 @@ export default function KanbanPage() {
|
|||
}
|
||||
}
|
||||
|
||||
// ComfyUI jobs still running in the app-level store, keyed by the card they
|
||||
// belong to. This survives leaving and returning to the page, so a card stays
|
||||
// locked until its workflow finishes even though the page-local progress
|
||||
// state was discarded on unmount.
|
||||
const activeStoreJobsByCardId = useMemo(() => {
|
||||
const map = new Map()
|
||||
workflowJobs.forEach(job => {
|
||||
if (
|
||||
job.page === 'kanban'
|
||||
&& job.projectId === projectId
|
||||
&& job.targetId
|
||||
&& (job.status === 'queued' || job.status === 'processing')
|
||||
) {
|
||||
map.set(String(job.targetId), job)
|
||||
}
|
||||
})
|
||||
return map
|
||||
}, [workflowJobs, projectId])
|
||||
|
||||
const getCardRuntimeState = (card) => {
|
||||
const liveState = imageEditProgressByCardId[card.id]
|
||||
if (liveState?.status === 'completed') {
|
||||
return null
|
||||
}
|
||||
|
||||
return liveState || card.processing || null
|
||||
if (liveState) {
|
||||
return liveState
|
||||
}
|
||||
|
||||
const storeJob = activeStoreJobsByCardId.get(String(card.id))
|
||||
if (storeJob) {
|
||||
return {
|
||||
status: 'processing',
|
||||
source: 'ComfyUI',
|
||||
progressPercent: storeJob.progressPercent,
|
||||
detail: storeJob.detail,
|
||||
currentNodeLabel: storeJob.currentNodeLabel
|
||||
}
|
||||
}
|
||||
|
||||
return card.processing || null
|
||||
}
|
||||
|
||||
const isCardLocked = (card) => getCardRuntimeState(card)?.status === 'processing'
|
||||
const isCardLocked = (card) => {
|
||||
const status = getCardRuntimeState(card)?.status
|
||||
return status === 'processing' || status === 'queued'
|
||||
}
|
||||
|
||||
const getCardInsertPosition = (cardId, destinationColumnId, destinationIndex) => {
|
||||
const sourceColumnId = draggedCard?.columnId
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue