mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 16:06:22 +00:00
fix: steps inside expanded subflows on the flow detail and run pages (#12591)
* 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 <noreply@anthropic.com> * fix: drop the approval section from the step panel Approvers will be shown in a separate change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * fix: render script and subflow paths in the step panel as the same accent link Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: step panel path links use the graph's step icon and an external link icon Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * feat: link the script or subflow path from a graph node's tooltip Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3ceff81e72
commit
a5c7dd4f69
@@ -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<string, ExpandedSubflow> = $state({})
|
||||
|
||||
if (provideTriggerContext && !hasContext('TriggerContext')) {
|
||||
const triggersCount = writable<TriggersCount | undefined>(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' : ''
|
||||
)}
|
||||
>
|
||||
<FlowGraphViewerStep schema={flow?.schema} {stepDetail} {hideDefaultInputs} {workspace} />
|
||||
<FlowGraphViewerStep
|
||||
schema={flow?.schema}
|
||||
{stepDetail}
|
||||
{subflowPathChain}
|
||||
{hideDefaultInputs}
|
||||
{workspace}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import HighlightCode from './HighlightCode.svelte'
|
||||
import InputTransformsViewer from './InputTransformsViewer.svelte'
|
||||
import IconedPath from './IconedPath.svelte'
|
||||
import FlowModuleIcon from './flows/FlowModuleIcon.svelte'
|
||||
import type { FlowModule } from '$lib/gen'
|
||||
import { Badge, Button, Drawer, DrawerContent } from './common'
|
||||
import { Link } from 'lucide-svelte'
|
||||
@@ -10,13 +10,13 @@
|
||||
import typescript from 'svelte-highlight/languages/typescript'
|
||||
import FlowPathViewer from './flows/content/FlowPathViewer.svelte'
|
||||
import SchemaViewer from './SchemaViewer.svelte'
|
||||
import { scriptPathToHref } from '$lib/scripts'
|
||||
import { cleanExpr, copyToClipboard } from '$lib/utils'
|
||||
import { flowPathToHref, scriptPathToHref } from '$lib/scripts'
|
||||
import { cleanExpr } from '$lib/utils'
|
||||
import { hubBaseUrlStore } from '$lib/stores'
|
||||
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import FlowModuleScript from './flows/content/FlowModuleScript.svelte'
|
||||
import { Copy, Expand } from 'lucide-svelte'
|
||||
import { ChevronRight, Expand, ExternalLink } from 'lucide-svelte'
|
||||
import HighlightTheme from './HighlightTheme.svelte'
|
||||
import LanguageIcon from './common/languageIcons/LanguageIcon.svelte'
|
||||
import FlowGraphViewerStepHeader from './FlowGraphViewerStepHeader.svelte'
|
||||
@@ -34,6 +34,9 @@
|
||||
workspace?: string
|
||||
/** Given, the step header starts with a back control that calls it. */
|
||||
onBack?: () => void
|
||||
/** For a step inside an inline-expanded subflow: path of each subflow crossed, outermost
|
||||
* first. */
|
||||
subflowPathChain?: string[]
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -42,27 +45,43 @@
|
||||
jobScriptHash = undefined,
|
||||
hideDefaultInputs = false,
|
||||
workspace = undefined,
|
||||
onBack = undefined
|
||||
onBack = undefined,
|
||||
subflowPathChain = undefined
|
||||
}: Props = $props()
|
||||
let ws = $derived(workspace ?? $operatingWorkspace)
|
||||
function flowHref(path: string): string {
|
||||
return path.startsWith('hub/')
|
||||
? flowPathToHref(path)
|
||||
: `/flows/get/${path}?workspace=${encodeURIComponent(ws ?? '')}`
|
||||
}
|
||||
let codeViewer: Drawer | undefined = $state()
|
||||
</script>
|
||||
|
||||
<HighlightTheme />
|
||||
|
||||
{#snippet pathLink(href: string, module: FlowModule, path: string)}
|
||||
<a
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
{href}
|
||||
class="inline-flex min-w-0 items-center gap-1.5 text-xs text-accent hover:underline"
|
||||
>
|
||||
<FlowModuleIcon {module} size={14} />
|
||||
<span class="truncate">{path}</span>
|
||||
<ExternalLink size={12} class="shrink-0" />
|
||||
</a>
|
||||
{/snippet}
|
||||
|
||||
<Drawer bind:this={codeViewer} size="900px">
|
||||
<DrawerContent title={'Expanded Code'} on:close={codeViewer?.closeDrawer}>
|
||||
{#if stepDetail && typeof stepDetail != 'string'}
|
||||
{#if stepDetail.value.type == 'script'}
|
||||
<div class="mb-4">
|
||||
<a
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
href={scriptPathToHref(stepDetail?.value?.path ?? '', $hubBaseUrlStore)}
|
||||
class=""
|
||||
>
|
||||
<IconedPath path={stepDetail?.value?.path ?? ''} />
|
||||
</a>
|
||||
{@render pathLink(
|
||||
scriptPathToHref(stepDetail.value.path, $hubBaseUrlStore),
|
||||
stepDetail,
|
||||
stepDetail.value.path
|
||||
)}
|
||||
</div>
|
||||
<div class="text-xs mb-4 mt-2">
|
||||
<h3 class="mb-1 text-xs font-semibold text-emphasis">Step inputs</h3>
|
||||
@@ -124,17 +143,30 @@
|
||||
<!-- A direct child of the scrolling root: a sticky row can only hold within its parent's
|
||||
box, so wrapped with the path link below it would scroll away with that wrapper. -->
|
||||
<FlowGraphViewerStepHeader {stepDetail} {onBack} />
|
||||
{#if subflowPathChain?.length}
|
||||
<div class="flex flex-wrap items-center gap-1 pb-2 text-xs text-secondary">
|
||||
<span>In</span>
|
||||
{#each subflowPathChain as path, i (i)}
|
||||
{#if i > 0}
|
||||
<ChevronRight size={12} class="shrink-0" />
|
||||
{/if}
|
||||
<a
|
||||
class="text-accent hover:underline"
|
||||
href={flowHref(path)}
|
||||
target="_blank"
|
||||
rel="noreferrer">{path}</a
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="">
|
||||
{#if stepDetail.value.type == 'script'}
|
||||
<div class="pb-2">
|
||||
<a
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
href={scriptPathToHref(stepDetail?.value?.path ?? '', $hubBaseUrlStore)}
|
||||
class=""
|
||||
>
|
||||
<IconedPath path={stepDetail?.value?.path ?? ''} />
|
||||
</a>
|
||||
{@render pathLink(
|
||||
scriptPathToHref(stepDetail.value.path, $hubBaseUrlStore),
|
||||
stepDetail,
|
||||
stepDetail.value.path
|
||||
)}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -280,25 +312,8 @@
|
||||
{/each}
|
||||
</div>
|
||||
{:else if stepDetail.value.type == 'flow'}
|
||||
<div class="text-sm mb-1 flex justify-between flex-row items-center">
|
||||
<span class="text-xs font-normal text-secondary"
|
||||
>Flow path: <span class="text-emphasis">{stepDetail.value.path}</span>
|
||||
</span>
|
||||
<Button
|
||||
unifiedSize="sm"
|
||||
startIcon={{ icon: Copy }}
|
||||
variant="subtle"
|
||||
on:click={() => {
|
||||
if (typeof stepDetail !== 'string') {
|
||||
const val = stepDetail?.value
|
||||
if (val?.type == 'flow') {
|
||||
copyToClipboard(val.path)
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
Copy path
|
||||
</Button>
|
||||
<div class="pb-2">
|
||||
{@render pathLink(flowHref(stepDetail.value.path), stepDetail, stepDetail.value.path)}
|
||||
</div>
|
||||
<FlowPathViewer noSide path={stepDetail.value.path} />
|
||||
{/if}
|
||||
|
||||
@@ -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<number, Job> = $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 @@
|
||||
</div>
|
||||
{:else if rightColumnSelect == 'node_definition'}
|
||||
{@const node = selectedNode ? localModuleStates[selectedNode] : undefined}
|
||||
<FlowGraphViewerStep {stepDetail} jobScriptHash={node?.script_hash} />
|
||||
<FlowGraphViewerStep
|
||||
{stepDetail}
|
||||
{subflowPathChain}
|
||||
jobScriptHash={node?.script_hash}
|
||||
/>
|
||||
{:else if rightColumnSelect == 'user_states'}
|
||||
<div class="p-2">
|
||||
<JobArgs argLabel="Key" args={job?.flow_status?.user_states ?? {}} />
|
||||
|
||||
@@ -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}
|
||||
<FlowGraphViewerStep schema={flow.schema} {stepDetail} {onBack} />
|
||||
<FlowGraphViewerStep schema={flow.schema} {stepDetail} {subflowPathChain} {onBack} />
|
||||
{/if}
|
||||
{/if}
|
||||
{/snippet}
|
||||
@@ -1057,6 +1059,7 @@
|
||||
triggerNode={true}
|
||||
download
|
||||
{flow}
|
||||
bind:subflowPathChain
|
||||
noSide={true}
|
||||
noBorder
|
||||
minHeight={flowGraphHeight}
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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<string, { modules: FlowModule[] }>
|
||||
): 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 @@
|
||||
<FlowModuleSchemaItemViewer
|
||||
{label}
|
||||
{path}
|
||||
{pathHref}
|
||||
{id}
|
||||
{bold}
|
||||
bind:editId
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
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 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Popover
|
||||
<Tooltip
|
||||
class="absolute left-1/2 transform -translate-x-1/2 center-center"
|
||||
style="max-width: calc(100% - {marginLeft}px)"
|
||||
>
|
||||
@@ -59,15 +62,23 @@
|
||||
{label}
|
||||
</div>
|
||||
{#snippet text()}
|
||||
<div>
|
||||
<div>{label}</div>
|
||||
{#if path != ''}<div>{path}</div>{/if}
|
||||
{#if showExploreHint}
|
||||
<div class="mt-1 text-tertiary">double click, or click again, to explore</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if !pathHref || path != label}<div>{label}</div>{/if}
|
||||
{#if pathHref}
|
||||
<a
|
||||
href={pathHref}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
class="inline-flex items-center gap-1 text-accent hover:underline"
|
||||
>{path}<ExternalLink size={12} class="shrink-0" /></a
|
||||
>
|
||||
{:else if path != '' && path != label}
|
||||
<div class="text-secondary">{path}</div>
|
||||
{/if}
|
||||
{#if showExploreHint}
|
||||
<div class="mt-1 text-hint">double click, or click again, to explore</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Popover>
|
||||
</Tooltip>
|
||||
|
||||
<div class="flex items-center space-x-2 relative" bind:clientWidth={idBadgeWidth}>
|
||||
<!-- A saved agent's run is that one step, already named by the run page. -->
|
||||
@@ -98,10 +109,25 @@
|
||||
</span>
|
||||
</Badge>
|
||||
{:else if id?.startsWith('subflow:')}
|
||||
<Badge color="blue" wrapperClass="max-w-full" baseClass="!px-1" title={id}>
|
||||
<!-- The step's own id: its subflow path is in the title, and would crowd out the summary. -->
|
||||
<span class="block max-w-12 text-2xs truncate">{id.split(':').at(-1)}</span></Badge
|
||||
>
|
||||
<!-- The step's own id: the subflow steps it sits in would crowd out the summary, so they
|
||||
are in the badge's tooltip. -->
|
||||
<Tooltip class="max-w-full">
|
||||
<Badge color="blue" wrapperClass="max-w-full" baseClass="!px-1">
|
||||
<span class="block max-w-12 text-2xs truncate">{id.split(':').at(-1)}</span></Badge
|
||||
>
|
||||
{#snippet text()}
|
||||
<div class="flex flex-wrap items-center gap-1">
|
||||
{#each id.slice('subflow:'.length).split(':') as step, i (i)}
|
||||
{#if i > 0}
|
||||
<ChevronRight size={12} class="shrink-0 text-hint" />
|
||||
{/if}
|
||||
<Badge color="blue" baseClass="!px-1">
|
||||
<span class="text-2xs">{step}</span>
|
||||
</Badge>
|
||||
{/each}
|
||||
</div>
|
||||
{/snippet}
|
||||
</Tooltip>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
|
||||
@@ -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<G extends { start_id: string; end_id: string }>(
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user