diff --git a/frontend/src/lib/components/flows/aiDecisionBranching.ts b/frontend/src/lib/components/flows/aiDecisionBranching.ts index 187d44b62a..21bc1d16f0 100644 --- a/frontend/src/lib/components/flows/aiDecisionBranching.ts +++ b/frontend/src/lib/components/flows/aiDecisionBranching.ts @@ -19,7 +19,9 @@ const YES_THRESHOLD = 0.5 const IDENT = /^[A-Za-z_$][\w$]*$/ -function key(k: string): string { +/** `.k`, or `["k"]` when `k` is not a JS identifier: a step id pushed as YAML or through the API + * can be `step-a`, which `results.step-a` would read as a subtraction. */ +export function key(k: string): string { return IDENT.test(k) ? `.${k}` : `[${JSON.stringify(k)}]` } diff --git a/frontend/src/lib/components/flows/stepErrorBranch.ts b/frontend/src/lib/components/flows/stepErrorBranch.ts index 225e90beec..19c713ed30 100644 --- a/frontend/src/lib/components/flows/stepErrorBranch.ts +++ b/frontend/src/lib/components/flows/stepErrorBranch.ts @@ -1,12 +1,7 @@ import type { FlowEditorContext } from './types' import { getModuleArrayContainer } from './flowTree' import { insertBranchOneAfter } from './branchOneInsert' - -// The editor only creates identifier ids, but a flow pushed as YAML or through the API can name -// a step `step-a`, which `results.step-a` would read as a subtraction. -function resultKey(stepId: string): string { - return /^[A-Za-z_$][\w$]*$/.test(stepId) ? `.${stepId}` : `[${JSON.stringify(stepId)}]` -} +import { key } from './aiDecisionBranching' /** Whether `stepId` sits in a step list a Branch to one can be inserted into after it. */ export function canAddErrorBranch(ctx: FlowEditorContext, stepId: string): boolean { @@ -20,7 +15,7 @@ export function addErrorBranch(ctx: FlowEditorContext, stepId: string): Promise< step.continue_on_error = true if (inserted.value.type === 'branchone') { inserted.value.branches = [ - { summary: 'On error', expr: `!!results${resultKey(stepId)}?.error`, modules: [] } + { summary: 'On error', expr: `!!results${key(stepId)}?.error`, modules: [] } ] } })