MCPcopy
hub / github.com/lightningpixel/modly / run

Function run

src/areas/workflows/workflowRunStore.ts:405–512  ·  view source on GitHub ↗
(workflow, allExtensions, overrideImageData?)

Source from the content-addressed store, hash-verified

403 runningBranchId: null,
404
405 async run(workflow, allExtensions, overrideImageData?) {
406 _cancel.current = false
407
408 const appState = useAppStore.getState()
409 const apiUrl = appState.apiUrl
410
411 const { preExecExtNodes, branches, waitIds, parentWait, ordered } = identifyBranches(workflow)
412 const branchSteps = waitIds.reduce((acc, w) => acc + (branches.get(w)?.length ?? 0), 0)
413 const totalSteps = preExecExtNodes.length + branchSteps
414
415 const selectedImagePath = appState.selectedImagePath ?? undefined
416 const selectedImageData = overrideImageData ?? appState.selectedImageData ?? undefined
417 const currentMeshUrl = appState.currentJob?.outputUrl
418
419 set({
420 activeWorkflowId: workflow.id,
421 nodeImageOutputs: {},
422 // Top-level Waits are pending; nested Waits start blocked until their parent finishes.
423 waitStates: Object.fromEntries(waitIds.map((id) => [id, parentWait.get(id) ? 'blocked' as WaitState : 'pending' as WaitState])),
424 runningBranchId: null,
425 runState: {
426 status: 'running', blockIndex: 0, blockTotal: totalSteps,
427 blockProgress: 0, blockStep: 'Starting…',
428 },
429 })
430
431 appState.setCurrentJob({
432 id: crypto.randomUUID(),
433 imageFile: selectedImagePath ?? '__workflow__',
434 status: 'generating',
435 progress: 0,
436 createdAt: Date.now(),
437 })
438
439 try {
440 const client = axios.create({ baseURL: apiUrl })
441 const settings = await window.electron.settings.get()
442 const workspaceDir = settings.workspaceDir.replace(/\\/g, '/')
443
444 const tmpAbsPath = settings.workspaceDir.replace(/[\\/]+$/, '') + '/tmp'
445 window.electron.fs.deleteDirectory(tmpAbsPath).catch(() => {})
446
447 const nodeOutputs = new Map<string, NodeOutput>()
448 const nodeMap = new Map(workflow.nodes.map((n) => [n.id, n]))
449
450 // Pre-populate source nodes
451 for (const node of ordered) {
452 if (node.type === 'imageNode') {
453 const fp = node.data.params?.filePath as string | undefined
454 const resolvedPath = overrideImageData ? undefined : (fp ?? selectedImagePath ?? undefined)
455 nodeOutputs.set(node.id, { filePath: resolvedPath, outputType: 'image' })
456 }
457 if (node.type === 'textNode') {
458 nodeOutputs.set(node.id, { text: node.data.params?.text as string | undefined })
459 }
460 if (node.type === 'meshNode') {
461 const source = node.data.params?.source as 'file' | 'current' | undefined
462 if (source === 'current' && currentMeshUrl) {

Callers 2

withWorkspaceFunction · 0.85
EmbeddedCanvasFunction · 0.85

Calls 3

identifyBranchesFunction · 0.85
executeExtensionNodeFunction · 0.85
finalizeFunction · 0.85

Tested by 1

withWorkspaceFunction · 0.68