import type { FlowModule, Job } from '$lib/gen' import type { GraphModuleState } from './graph' import { buildNestedRestartPath, type NestedRestartStep } from './restartFromStepPath' import { emptyString } from '$lib/utils' export type { NestedRestartStep } /** * Reactive state shared by the run page and the editor's flow preview to drive * the "restart flow at step" UI. Given the currently selected step, the * completed flow job, the graph's per-module display state, and any expanded * subflow definitions, derives: * * - `selectedJobStepIsTopLevel` — whether the selected step appears in the * parent flow's top-level `flow_status.modules` * - `selectedJobStepType` — `single` / `forloop` / `branchall`, used by the * popup to decide which controls to render for the OUTER container * - `restartBranchNames` — for top-level BranchAll steps, the labels for the * branch picker * - `nestedRestartTopStepId` / `nestedRestartTopBranchOrIterationN` / * `nestedRestartPath` — the API request shape when restarting at a nested * step (single source of truth for both call sites) * - `nestedRestartSupported` — gate for showing the button when the selected * step is nested (subflow expansion or BranchOne / sequential ForLoop) * - `topLevelLoopIteration` — when the selected step IS a top-level ForLoop, * the iteration the user is currently viewing (pre-fills the popup input) * - `iterationCounts` — map of step id → number of recorded iterations, * so the popup can render an iteration `