From f9ade481dae05bdbb0ef876939bcd3e5b7d02da4 Mon Sep 17 00:00:00 2001 From: AlexRV12 <71396855+AlexRV12@users.noreply.github.com> Date: Tue, 24 Nov 2026 11:45:48 +0100 Subject: [PATCH] fix: generate branch predicates from the branch node (#12623) --- .../components/copilot/PredicateGen.svelte | 31 ++++++++++--------- .../content/BranchPredicateEditor.svelte | 1 + 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/frontend/src/lib/components/copilot/PredicateGen.svelte b/frontend/src/lib/components/copilot/PredicateGen.svelte index 6f003524f4..3b5040be18 100644 --- a/frontend/src/lib/components/copilot/PredicateGen.svelte +++ b/frontend/src/lib/components/copilot/PredicateGen.svelte @@ -22,10 +22,12 @@ let loading = $state(false) interface Props { + /** Id of the branching step, which isn't the selected id when a branch node is selected. */ + moduleId: string pickableProperties?: PickableProperties | undefined } - let { pickableProperties = undefined }: Props = $props() + let { moduleId, pickableProperties = undefined }: Props = $props() let instructions = $state('') let instructionsField: HTMLInputElement | undefined = $state(undefined) @@ -34,31 +36,32 @@ }) let abortController = $state(new AbortController()) - const { flowStore, selectionManager } = getContext('FlowEditorContext') + const { flowStore } = getContext('FlowEditorContext') const dispatch = createEventDispatcher() async function generatePredicate() { abortController = new AbortController() loading = true - const flow: Flow = JSON.parse(JSON.stringify(flowStore.val)) - const idOrders = dfs(flow.value.modules, (x) => x.id) - const upToIndex = idOrders.indexOf(selectionManager.getSelectedId()) - if (upToIndex === -1) { - throw new Error('Could not find the selected id in the flow') - } - - const flowDetails = - 'Take into account the following information for never tested results:\n\n' + - yamlStringifyExceptKeys(sliceModules(flow.value.modules, upToIndex, idOrders), ['lock']) + - '' try { + const flow: Flow = JSON.parse(JSON.stringify(flowStore.val)) + const idOrders = dfs(flow.value.modules, (x) => x.id) + const upToIndex = idOrders.indexOf(moduleId) + if (upToIndex === -1) { + throw new Error('Could not find the branching step in the flow') + } + + const flowDetails = + 'Take into account the following information for never tested results:\n\n' + + yamlStringifyExceptKeys(sliceModules(flow.value.modules, upToIndex, idOrders), ['lock']) + + '' + const availableData = { results: pickableProperties?.priorIds, flow_input: pickableProperties?.flow_input } const user = `I'm building a workflow which is a DAG of script steps. -The current step is ${selectionManager.getSelectedId()} and is a branching step (if-else). +The current step is ${moduleId} and is a branching step (if-else). The user wants to generate a predicate for the branching condition. Here's the user's request: ${instructions} You can find the details of all the steps below: diff --git a/frontend/src/lib/components/flows/content/BranchPredicateEditor.svelte b/frontend/src/lib/components/flows/content/BranchPredicateEditor.svelte index 949862632a..07a841cb49 100644 --- a/frontend/src/lib/components/flows/content/BranchPredicateEditor.svelte +++ b/frontend/src/lib/components/flows/content/BranchPredicateEditor.svelte @@ -73,6 +73,7 @@ {#snippet aiGen()} {#if enableAi} { branch.expr = e.detail // Monaco owns its buffer once mounted: writing the value alone leaves