From a5c7dd4f699c85190eca5cc88717d85fcc28cfae Mon Sep 17 00:00:00 2001 From: hugocasa Date: Mon, 23 Nov 2026 21:27:40 +0100 Subject: [PATCH] fix: steps inside expanded subflows on the flow detail and run pages (#12591) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: flow detail page steps inside expanded subflows, show approvers - Resolve a step inside an expanded subflow from the expansion's modules, so its detail panel shows the step instead of a bare node id. - Key expanded subflows' groups and modules by their prefixed node ids, so expanding the same subflow at two steps no longer trips cycle detection and inner step ids no longer shadow the parent flow's steps. - Show an approval step's approvers, required approvals and timeout in the step panel. Co-Authored-By: Claude Opus 5.5 * fix: drop the approval section from the step panel Approvers will be shown in a separate change. Co-Authored-By: Claude Opus 5.5 * fix: show definitions of expanded subflow steps on the run page, link subflow paths The run page's Node definition tab looked the selected step up in the run's top-level modules only, so a step inside an expanded subflow showed nothing. Both viewers now resolve it through expandedSubflowStepOf. A subflow step's path in the step panel links to that flow. Co-Authored-By: Claude Opus 5.5 * fix: render script and subflow paths in the step panel as the same accent link Co-Authored-By: Claude Opus 5.5 * fix: step panel path links use the graph's step icon and an external link icon Co-Authored-By: Claude Opus 5.5 * fix: drop the copy path button from the subflow step panel The path is shown in full as a link, as for workspace script steps. Co-Authored-By: Claude Opus 5.5 * feat: show which subflow an expanded step belongs to The step panel of a step inside an expanded subflow names the subflows crossed to reach it, each linking to its flow, on the detail and run pages. The graph node's hover popover gives the step's full position (g › a › b) instead of the badge's slow native tooltip. Co-Authored-By: Claude Opus 5.5 * fix: graph node tooltips use the standard tooltip, step parentage on the id badge The step label's tooltip moves off the deprecated popover onto the shared Tooltip, and no longer repeats the path when it is the label. An expanded step's subflow steps show as badges in a tooltip on its id badge. Co-Authored-By: Claude Opus 5.5 * feat: link the script or subflow path from a graph node's tooltip Co-Authored-By: Claude Opus 5.5 * fix: address review findings on the step links and tooltips - No link for a script or flow step whose path is still empty. - An inline script with a path and no summary keeps its label in the tooltip. - Hub flow paths link to the hub from the step panel. - subflowPathChain uses $bindable() without a default. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../src/lib/components/FlowGraphViewer.svelte | 24 ++++- .../lib/components/FlowGraphViewerStep.svelte | 95 +++++++++++-------- .../components/FlowStatusViewerInner.svelte | 20 +++- .../lib/components/details/FlowDetail.svelte | 5 +- .../flows/expandedSubflowStep.test.ts | 21 +++- .../components/flows/expandedSubflowStep.ts | 33 +++++++ .../flows/map/FlowModuleSchemaItem.svelte | 4 + .../map/FlowModuleSchemaItemViewer.svelte | 54 ++++++++--- .../lib/components/flows/map/MapItem.svelte | 7 ++ .../lib/components/graph/FlowGraphV2.svelte | 5 +- .../components/graph/graphBuilder.svelte.ts | 29 ++++-- .../lib/components/graph/graphBuilder.test.ts | 19 ++++ 12 files changed, 246 insertions(+), 70 deletions(-) diff --git a/frontend/src/lib/components/FlowGraphViewer.svelte b/frontend/src/lib/components/FlowGraphViewer.svelte index 90862e46ac..fa08253812 100644 --- a/frontend/src/lib/components/FlowGraphViewer.svelte +++ b/frontend/src/lib/components/FlowGraphViewer.svelte @@ -14,6 +14,8 @@ import { publishLinkedAgentTools } from './flows/flowState' import { linkedToolsScope } from './flows/linkedAgentToolsStore.svelte' import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte' + import type { ExpandedSubflow } from './graph/graphBuilder.svelte' + import { resolveLoadedExpandedSubflowStep } from './flows/expandedSubflowStep' const operatingWorkspace = useOperatingWorkspace() @@ -31,6 +33,8 @@ noGraph?: boolean triggerNode?: boolean stepDetail?: FlowModule | string | undefined + /** Subflows crossed to reach `stepDetail`, set when it is inside an expanded subflow. */ + subflowPathChain?: string[] workspace?: string | undefined minHeight?: number noBorder?: boolean @@ -50,6 +54,7 @@ noGraph = false, triggerNode = false, stepDetail = $bindable(undefined), + subflowPathChain = $bindable(), workspace = $operatingWorkspace, minHeight = 400, noBorder = false, @@ -60,6 +65,7 @@ }: Props = $props() let availableHeight = $state(0) + let expandedSubflows: Record = $state({}) if (provideTriggerContext && !hasContext('TriggerContext')) { const triggersCount = writable(undefined) @@ -136,7 +142,9 @@ preprocessorModule={flow?.value?.preprocessor_module} notes={flow?.value?.notes} groups={flow?.value?.groups} + bind:expandedSubflows onSelect={(nodeId) => { + subflowPathChain = undefined if (nodeId === 'Trigger') { dispatch('triggerDetail') return @@ -144,6 +152,14 @@ stepDetail = flow?.value?.failure_module } else if (nodeId === 'preprocessor') { stepDetail = flow?.value?.preprocessor_module + } else if (typeof nodeId === 'string' && nodeId.startsWith('subflow:')) { + const resolved = resolveLoadedExpandedSubflowStep( + nodeId, + flow?.value?.modules ?? [], + expandedSubflows + ) + stepDetail = resolved?.module + subflowPathChain = resolved?.pathChain } else { stepDetail = dfs(flow?.value?.modules ?? [], (m) => m).find((m) => m?.id === nodeId) } @@ -162,7 +178,13 @@ noGraph ? 'border-0 w-max' : '' )} > - + {/if} diff --git a/frontend/src/lib/components/FlowGraphViewerStep.svelte b/frontend/src/lib/components/FlowGraphViewerStep.svelte index f662f5280c..0174685e08 100644 --- a/frontend/src/lib/components/FlowGraphViewerStep.svelte +++ b/frontend/src/lib/components/FlowGraphViewerStep.svelte @@ -1,7 +1,7 @@ +{#snippet pathLink(href: string, module: FlowModule, path: string)} + + + {path} + + +{/snippet} + {#if stepDetail && typeof stepDetail != 'string'} {#if stepDetail.value.type == 'script'}
- - - + {@render pathLink( + scriptPathToHref(stepDetail.value.path, $hubBaseUrlStore), + stepDetail, + stepDetail.value.path + )}

Step inputs

@@ -124,17 +143,30 @@ + {#if subflowPathChain?.length} +
+ In + {#each subflowPathChain as path, i (i)} + {#if i > 0} + + {/if} + {path} + {/each} +
+ {/if}
{#if stepDetail.value.type == 'script'}
- - - + {@render pathLink( + scriptPathToHref(stepDetail.value.path, $hubBaseUrlStore), + stepDetail, + stepDetail.value.path + )}
{/if}
@@ -280,25 +312,8 @@ {/each}
{:else if stepDetail.value.type == 'flow'} -
- Flow path: {stepDetail.value.path} - - +
+ {@render pathLink(flowHref(stepDetail.value.path), stepDetail, stepDetail.value.path)}
{/if} diff --git a/frontend/src/lib/components/FlowStatusViewerInner.svelte b/frontend/src/lib/components/FlowStatusViewerInner.svelte index 70784fc223..9d00cd87c4 100644 --- a/frontend/src/lib/components/FlowStatusViewerInner.svelte +++ b/frontend/src/lib/components/FlowStatusViewerInner.svelte @@ -39,6 +39,7 @@ import { deepEqual } from 'fast-equals' import FlowTimeline from './FlowTimeline.svelte' import { dfs } from './flows/dfs' + import { resolveLoadedExpandedSubflowStep } from './flows/expandedSubflowStep' import { dfs as dfsPreviousResults } from '$lib/components/flows/previousResults' import Alert from './common/alert/Alert.svelte' import FlowGraphViewerStep from './FlowGraphViewerStep.svelte' @@ -1363,6 +1364,7 @@ let flowTimeline: FlowTimeline | undefined = $state() let stepDetail: FlowModule | string | undefined = $state(undefined) + let subflowPathChain: string[] | undefined = $state(undefined) let storedListJobs: Record = $state({}) @@ -2192,6 +2194,7 @@ runDone={job?.type === 'CompletedJob'} bind:expandedSubflows onSelect={(e) => { + subflowPathChain = undefined if (rightColumnSelect != 'node_definition' && rightColumnSelect != 'tracing') { rightColumnSelect = 'node_status' } @@ -2204,10 +2207,15 @@ stepDetail = 'end' } else { const id = e.startsWith(AI_TOOL_CALL_PREFIX) ? e.split('-').pop() : e - const mod = dfs(job?.raw_flow?.modules ?? [], (m) => m).find( - (m) => m?.id === id + const resolved = resolveLoadedExpandedSubflowStep( + e, + job?.raw_flow?.modules ?? [], + expandedSubflows ?? {} ) - stepDetail = mod + stepDetail = + resolved?.module ?? + dfs(job?.raw_flow?.modules ?? [], (m) => m).find((m) => m?.id === id) + subflowPathChain = resolved?.pathChain selectedNode = e if (e.startsWith(AI_TOOL_CALL_PREFIX)) { const [_prefix, agentModuleId, j, _toolModuleId] = e.split('-') @@ -2518,7 +2526,11 @@
{:else if rightColumnSelect == 'node_definition'} {@const node = selectedNode ? localModuleStates[selectedNode] : undefined} - + {:else if rightColumnSelect == 'user_states'}
diff --git a/frontend/src/lib/components/details/FlowDetail.svelte b/frontend/src/lib/components/details/FlowDetail.svelte index 694f4529de..1cec0f72cd 100644 --- a/frontend/src/lib/components/details/FlowDetail.svelte +++ b/frontend/src/lib/components/details/FlowDetail.svelte @@ -616,6 +616,7 @@ } } let stepDetail: FlowModule | string | undefined = $state(undefined) + let subflowPathChain: string[] | undefined = $state(undefined) let rightPaneSelected = $state('saved_inputs') let savedInputsV2: SavedInputsV2 | undefined = $state(undefined) let detailLayout: DetailPageLayout | undefined = $state(undefined) @@ -984,6 +985,7 @@ triggerNode={true} download {flow} + bind:subflowPathChain noSide={true} minHeight={graphMinHeight} on:select={(e) => { @@ -1027,7 +1029,7 @@ {#snippet flow_step({ onBack }: { onBack?: () => void })} {#if flow} {#if stepDetail} - + {/if} {/if} {/snippet} @@ -1057,6 +1059,7 @@ triggerNode={true} download {flow} + bind:subflowPathChain noSide={true} noBorder minHeight={flowGraphHeight} diff --git a/frontend/src/lib/components/flows/expandedSubflowStep.test.ts b/frontend/src/lib/components/flows/expandedSubflowStep.test.ts index 33b5515850..cc203b9a23 100644 --- a/frontend/src/lib/components/flows/expandedSubflowStep.test.ts +++ b/frontend/src/lib/components/flows/expandedSubflowStep.test.ts @@ -1,6 +1,10 @@ import { describe, it, expect } from 'vitest' import type { FlowModule } from '$lib/gen' -import { expandedSubflowParentId, resolveExpandedSubflowStep } from './expandedSubflowStep' +import { + expandedSubflowParentId, + resolveExpandedSubflowStep, + resolveLoadedExpandedSubflowStep +} from './expandedSubflowStep' const script = (id: string): FlowModule => ({ id, value: { type: 'rawscript', language: 'bun', content: '', input_transforms: {} } }) as any @@ -50,3 +54,18 @@ describe('resolveExpandedSubflowStep', () => { expect(resolved?.module).toBeUndefined() }) }) + +describe('resolveLoadedExpandedSubflowStep', () => { + it('reads each boundary from the expansion the graph keys it under', () => { + const expanded = { + a: { modules: flows['f/inner'] }, + 'subflow:a:b': { modules: flows['f/innermost'] } + } + const resolved = resolveLoadedExpandedSubflowStep('subflow:a:b:leaf', rootModules, expanded) + expect(resolved?.pathChain).toEqual(['f/inner', 'f/innermost']) + expect(resolved?.module?.id).toBe('leaf') + expect( + resolveLoadedExpandedSubflowStep('subflow:a:b:leaf', rootModules, { a: expanded.a }) + ).toBeUndefined() + }) +}) diff --git a/frontend/src/lib/components/flows/expandedSubflowStep.ts b/frontend/src/lib/components/flows/expandedSubflowStep.ts index 0075897b09..9d41e4159a 100644 --- a/frontend/src/lib/components/flows/expandedSubflowStep.ts +++ b/frontend/src/lib/components/flows/expandedSubflowStep.ts @@ -60,3 +60,36 @@ export async function resolveExpandedSubflowStep( module: findStepPath(modules, parsed.leaf)?.target } } + +/** + * `resolveExpandedSubflowStep` for a graph whose expansions are already loaded: each boundary's + * modules are read from `expandedSubflows`, keyed as the graph keys them (`a`, then + * `subflow:a:b`...). `undefined` for any other node id, or when an expansion is missing. + */ +export function resolveLoadedExpandedSubflowStep( + id: string, + rootModules: FlowModule[], + expandedSubflows: Record +): ResolvedExpandedSubflowStep | undefined { + const parsed = parseExpandedSubflowId(id) + if (!parsed) { + return undefined + } + let modules = rootModules + const pathChain: string[] = [] + for (const [i, stepId] of parsed.subflowSteps.entries()) { + const value = findStepPath(modules, stepId)?.target.value + const expansion = + expandedSubflows[i == 0 ? stepId : 'subflow:' + parsed.subflowSteps.slice(0, i + 1).join(':')] + if (value?.type !== 'flow' || !expansion) { + return undefined + } + pathChain.push(value.path) + modules = expansion.modules + } + return { + containingFlowPath: pathChain[pathChain.length - 1], + pathChain, + module: findStepPath(modules, parsed.leaf)?.target + } +} diff --git a/frontend/src/lib/components/flows/map/FlowModuleSchemaItem.svelte b/frontend/src/lib/components/flows/map/FlowModuleSchemaItem.svelte index 2984650b14..2c468d9773 100644 --- a/frontend/src/lib/components/flows/map/FlowModuleSchemaItem.svelte +++ b/frontend/src/lib/components/flows/map/FlowModuleSchemaItem.svelte @@ -62,6 +62,8 @@ id?: string | undefined label: string path?: string + /** Page of the script or flow `path` names, linked from the label's tooltip. */ + pathHref?: string nodeState?: FlowNodeState retries?: number | undefined /** In a run, the attempts the retry badge picks from. */ @@ -96,6 +98,7 @@ id = undefined, label, path = '', + pathHref = undefined, nodeState, retries = undefined, attempts = undefined, @@ -347,6 +350,7 @@ - import Popover from '$lib/components/Popover.svelte' + import Tooltip from '$lib/components/meltComponents/Tooltip.svelte' + import { ChevronRight, ExternalLink } from 'lucide-svelte' import Badge from '$lib/components/common/badge/Badge.svelte' import type { FlowNodeColorClasses } from '$lib/components/graph' import { twMerge } from 'tailwind-merge' @@ -16,6 +17,7 @@ interface Props { label?: string path?: string + pathHref?: string id?: string bold?: boolean editId?: boolean @@ -28,6 +30,7 @@ let { label = '', path = '', + pathHref = undefined, id = '', bold = false, editId = $bindable(false), @@ -51,7 +54,7 @@
{/if} - @@ -59,15 +62,23 @@ {label} {#snippet text()} -
-
{label}
- {#if path != ''}
{path}
{/if} - {#if showExploreHint} -
double click, or click again, to explore
- {/if} -
+ {#if !pathHref || path != label}
{label}
{/if} + {#if pathHref} + {path} + {:else if path != '' && path != label} +
{path}
+ {/if} + {#if showExploreHint} +
double click, or click again, to explore
+ {/if} {/snippet} -
+
@@ -98,10 +109,25 @@ {:else if id?.startsWith('subflow:')} - - - {id.split(':').at(-1)} + + + + {id.split(':').at(-1)} + {#snippet text()} +
+ {#each id.slice('subflow:'.length).split(':') as step, i (i)} + {#if i > 0} + + {/if} + + {step} + + {/each} +
+ {/snippet} +
{/if}
diff --git a/frontend/src/lib/components/flows/map/MapItem.svelte b/frontend/src/lib/components/flows/map/MapItem.svelte index 003d1da9b6..e957665a6b 100644 --- a/frontend/src/lib/components/flows/map/MapItem.svelte +++ b/frontend/src/lib/components/flows/map/MapItem.svelte @@ -17,6 +17,8 @@ import { getGraphContext } from '$lib/components/graph/graphContext' import { nextMock } from '../flowMock' import { Bug } from 'lucide-svelte' + import { flowPathToHref, scriptPathToHref } from '$lib/scripts' + import { hubBaseUrlStore } from '$lib/stores' interface Props { moduleId: string @@ -315,6 +317,11 @@ ? `Inline ${prettyLanguage(mod.value.language)}` : 'To be defined')} path={`path` in mod.value ? mod.value.path : ''} + pathHref={mod.value.type === 'script' && mod.value.path + ? scriptPathToHref(mod.value.path, $hubBaseUrlStore) + : mod.value.type === 'flow' && mod.value.path + ? flowPathToHref(mod.value.path) + : undefined} alwaysShowOutputPicker={!mod.id.startsWith('subflow:') && mod.id !== 'preprocessor'} loopStatus={parentLoop ? { type: 'inside', flow: parentLoop.type } : undefined} inputTransform={mod.value.type !== 'identity' ? mod.value.input_transforms : undefined} diff --git a/frontend/src/lib/components/graph/FlowGraphV2.svelte b/frontend/src/lib/components/graph/FlowGraphV2.svelte index 6db7624cd5..92bd1dfa96 100644 --- a/frontend/src/lib/components/graph/FlowGraphV2.svelte +++ b/frontend/src/lib/components/graph/FlowGraphV2.svelte @@ -27,6 +27,7 @@ } from '@xyflow/svelte' import { expandedSubflowOf, + expandedSubflowGroup, graphBuilder, type ExpandedSubflow, type InlineScript, @@ -1102,7 +1103,9 @@ // All groups including those from expanded subflows (for overlay rendering) let allGroups = $derived.by(() => { const base = groups ?? [] - const subflowGroups = Object.values(expandedSubflows).flatMap((sf) => sf.groups ?? []) + const subflowGroups = Object.entries(expandedSubflows).flatMap(([id, sf]) => + (sf.groups ?? []).map((g) => expandedSubflowGroup(id, g)) + ) return subflowGroups.length > 0 ? [...base, ...subflowGroups] : base }) diff --git a/frontend/src/lib/components/graph/graphBuilder.svelte.ts b/frontend/src/lib/components/graph/graphBuilder.svelte.ts index 2147fbf874..bc7c0f6047 100644 --- a/frontend/src/lib/components/graph/graphBuilder.svelte.ts +++ b/frontend/src/lib/components/graph/graphBuilder.svelte.ts @@ -104,6 +104,19 @@ export function expandedSubflowOf(flow: OpenFlow): ExpandedSubflow { } } +/** + * A group of the expansion `expansionId` (an `expandedSubflows` key), its ends named by their + * graph node ids: the same subflow can be expanded at several steps, and its groups must not + * share a `groupKey` across them. + */ +export function expandedSubflowGroup( + expansionId: string, + g: G +): G { + const p = 'subflow:' + expansionId.replace(/^subflow:/, '') + ':' + return { ...g, start_id: p + g.start_id, end_id: p + g.end_id } +} + export function buildPrefix(prefix: string | undefined, id: string): string { return (prefix ?? '') + id + ':' } @@ -734,10 +747,10 @@ export function graphBuilder( if (prefix != undefined) { items.forEach((item) => { if (item.kind === 'group') return - const m = moduleMap.get(item.id) + const newId = 'subflow:' + prefix + item.id + const m = moduleMap.get(newId) if (m) { const oid = m['oid'] ?? m.id - const newId = 'subflow:' + prefix + oid const clone = { ...m, id: newId, oid } as FlowModule & { oid: string } clone['oid'] = oid moduleMap.set(newId, clone) @@ -775,7 +788,7 @@ export function graphBuilder( autocollapse: g.autocollapse, stepCount: item.moduleIds?.length ?? 0, modules: leafIds - .map((id) => moduleMap.get(id)) + .map((id) => moduleMap.get(prefix != undefined ? 'subflow:' + prefix + id : id)) .filter((m): m is FlowModule => !!m), isOwner: extra.isOwner, showNotes, @@ -1214,19 +1227,19 @@ export function graphBuilder( nodes.push(endNode) - // Register expanded subflow modules so prefix rewriting finds - // the inner modules (not the parent flow's modules with same IDs) + const subflowPrefix = buildPrefix(prefix, module['oid'] ?? module.id) + // Under their prefixed ids: a raw id would shadow a step of the drawing + // flow, or of another expansion, that shares it. for (const em of getAllModules(expandedMods)) { - moduleMap.set(em.id, em) + moduleMap.set('subflow:' + subflowPrefix + em.id, em) } const expandedGroups = (expandedData.groups ?? []).map((g) => ({ ...g, - id: groupKey(g), + id: groupKey(expandedSubflowGroup(module.id, g)), moduleIds: computeGroupModuleIds(g.start_id, g.end_id, getAllModules(expandedMods)) })) - const subflowPrefix = buildPrefix(prefix, module['oid'] ?? module.id) if (expandedData.failureModule) { failureModulesByPrefix['subflow:' + subflowPrefix] = expandedData.failureModule } diff --git a/frontend/src/lib/components/graph/graphBuilder.test.ts b/frontend/src/lib/components/graph/graphBuilder.test.ts index f0f8f962eb..d376aadfcb 100644 --- a/frontend/src/lib/components/graph/graphBuilder.test.ts +++ b/frontend/src/lib/components/graph/graphBuilder.test.ts @@ -145,3 +145,22 @@ describe('topologicalSort', () => { expect(sorted.map((n) => n.id)).toEqual(['orphan', 'b', 'a']) }) }) + +describe('graphBuilder expanded subflows', () => { + it('draws the same subflow expanded at two steps, sharing step ids with the parent', () => { + const flow = (id: string): FlowModule => ({ + id, + value: { type: 'flow', path: 'u/admin/child', input_transforms: {} } + }) + const child = { + modules: [script('x'), script('b')], + groups: [{ start_id: 'x', end_id: 'b' }] + } + const r = build([flow('a'), flow('b')], {}, { a: child, b: child }) + + expect((r as any).error).toBeUndefined() + expect(r.nodes['group:subflow:a:x:subflow:a:b']).toBeDefined() + expect(r.nodes['group:subflow:b:x:subflow:b:b']).toBeDefined() + expect(hasEdge(r.edges, 'a-subflow-end', 'b')).toBe(true) + }) +})