Skip to content

feat(sdk) Variable enhancement - #76

Merged
librowski merged 106 commits into
mainfrom
feat/WB-139-variables
Nov 27, 2026
Merged

librowski merged 106 commits into
mainfrom
feat/WB-139-variables

Conversation

@szymon-t-sc

Copy link
Copy Markdown
Member

Workflow Builder introduced variable support some time ago, allowing sidebar controls to use variables from previous nodes or global variables.

This PR enhances the feature with the missing logic to make variable usage more robust and flexible.

Main changes

Variables provided by nodes to downstream nodes can now depend on:

  • selected type in the sidebar - for example, selecting a time-based trigger returns schedule information, while selecting an event-based trigger returns information about the event type
  • sourceHandle - if a node has success and error source handles, it can provide the actual node output to the success branch and the error output to the error-handling branch
Nagranie.z.ekranu.2026-08-14.o.18.32.10.mov

Node variables store:

Previously, variables from previous nodes were calculated when the control was mounted. We traversed the graph and calculated their values at the same time - now we keep nodes variables in the store and only collect them:

  • The list of variables further down the flow is calculated faster, as we only collect the variables that are available
  • It's now easier to check which variables are available from a node, and we can easily add a plugin to display them
obraz

New single variable control (previously used in conditions)

Nagranie.z.ekranu.2026-08-14.o.18.28.48.mov

It shows a date picker with {} when date variables are available.

Fixes

  • When an edge was added or removed, we sometimes had incorrect highlighting of values in controls. This is now fixed thanks to totalVariables
  • Global variables cannot be added in read-only mode

It's worth noting that the majority of the changes are encapsulated in packages/sdk/src/features/variables/. So while reviewing, we can identify what is used externally as a useful public API and note the core functions that could be valuable to expose.

@szymon-t-sc
szymon-t-sc marked this pull request as draft August 27, 2026 09:46
szymon-t-sc and others added 11 commits November 3, 2026 12:19
Validation: a variable reference in a nested property no longer leaves
type, format or pattern errors; blank text is read as missing in nested
objects too; the date, datetime and time validator reports values that
are not dates or clocks; property names are matched as text, never as a
regex; message matching is limited to the properties and required
keywords, so a format "email" error is not read as the email property.

Variables: the common-suggestion placeholder is anchored on the
nodes.<id>. prefix; VariableDynamic offers the compatible types from one
map and renders the picker toggle for string fields; the toggle keeps
the typed value; chips carry the numbered label of same-name ancestors;
a variant rule accepts a boolean value; VariableText keys with a counter
instead of crypto.randomUUID(), which needs a secure context.

Editor: the conditions editor is read-only when the editor is; an edge
label edit is one undo step per focus session.

Worker: isEqual and isNotEqual compare clocks like isBefore and isAfter.

Docs: variablesTypes, the global namespace, where the picker is wired,
the read-only settings modal, JSDoc for useNodeVariables, the changeset
and the validation decision log.
@Jacek-Synergy

Copy link
Copy Markdown
Contributor

Review follow-up: pushed 6cf980ed (fix(sdk): close the review findings of the variables feature). It addresses the findings from both reviews; nothing in the PR description changes.

Validation

  • A variable reference in a nested property no longer leaves type/format/pattern errors (the demo Trigger's starts.date/starts.time with a {{global.…}} reference was always in error). A missing nested required property is still reported.
  • Blank text counts as a missing value in nested objects too, so a fresh Trigger no longer shows red HH:mm fields.
  • getValidationForCustomTypes now works: date/datetime/time values that are not a date ('not a date', '5', 2024-02-30) or a clock are reported as type errors at #/<name>; a missing key stays the standard required. Decision log § 2 updated.
  • Property names are matched as text, never as a regex (to) no longer throws). Message-text matching is limited to the properties and required keywords, so a format "email" error of emailBackup is not dropped by a reference in email.

Variables

  • Common-suggestion placeholder is anchored on the nodes.<id>. prefix (ids like node, s broke other nodes' references).
  • COMPATIBLE_VARIABLE_TYPES_BY_PRIMITIVE in constants.ts drives both useNodeVariables and the {} picker of VariableDynamic, so string offers number/date/datetime/time as the docs say. The string branch of DynamicTypedInput also never rendered the {} toggle (it dropped endAdornment); fixed.
  • The {} toggle keeps the typed value and restores it on the way back.
  • Chips carry the (2) label of same-name ancestors; onlyIfPropertyNameEquals.value accepts boolean.
  • VariableText keys with a counter instead of crypto.randomUUID(), which only exists in secure contexts.
  • Invalid text in a number field stays visible with its error state instead of vanishing.

Editor / worker

  • Conditions editor respects read-only: X, operator, Remove, Add condition disabled, Confirm only closes; branch Remove disabled.
  • Edge label: one trackFutureChange per focus session, so one undo step per edit.
  • Decision executor: isEqual/isNotEqual compare clocks like isBefore/isAfter (09:07 equals 09:07:00+00:00).

Docs

  • variablesTypes documented for VariableText/VariableTextArea; "Where it works" table updated; new global.<id> namespace section (incl. the note that the reference backend submits global: {}); openSettings read-only sentences corrected; JSDoc on useNodeVariables; changeset sdk-validator-blank-text.md extended (nested blanks, custom types, globalControls scope change).

Tests: 18 new cases (validator, store placeholder, ancestors display, dynamic-typed-variable-or-input.spec.tsx, edge-properties.spec.tsx, worker clock equality). Full pnpm test, pnpm check (except the pre-existing docs astro check failure, same on main) and pnpm build:lib pass.

Left out on purpose (design decisions, tracked separately): backend mapping of globalVariables → global, typed resolution of single references in execution-core, wall-time vs instant in datetime, and the HH:mm:00+00:00 shape of time. SchemaBuilder and modals/control are unused today but kept.

# Conflicts:
#	DECISION-LOGS.md
#	apps/ai-studio/README.md
#	packages/mcp-server/scripts/smoke.ts
compareClocks returned false for both sides when a value started with
HH:mm but was not a clock ("10:30 standup"), so isEqual on such text
took the wrong branch. It now falls back to the plain comparison.

The docs sidebar gets the "Variables" entry that the new @category tag
on useNodeVariables requires; the sidebar parity check failed without it.
@Jacek-Synergy

Copy link
Copy Markdown
Contributor

Follow-up on the two points raised against 6cf980ed, fixed in f02259a1:

  • Docs build. The red job was the sidebar parity check, not astro check: the new @category Variables on useNodeVariables had no matching sidebar entry. Added { label: 'Variables', collapsed: true, autogenerate: { directory: 'api/Variables' } } to apps/docs/astro.config.mjs; check-sidebar-categories.mjs and the full docs build pass locally.
  • Worker regression. compareClocks treated any text starting with HH:mm as a clock and answered false on both sides when it was not one, so isEqual("10:30 standup", "10:30 standup") took the wrong branch. It now returns undefined unless both sides parse as clocks, and the caller falls back to the plain comparison (=== for equality, new Date() for before/after, as on main). Test added for isEqual and isNotEqual on such text.

…ped inputs

DynamicTypedInput and DynamicTypedVariableOrInput no longer filter the
suggestions they receive; the prop is now suggestionGroupsForType and the
caller passes a list already narrowed to the field type. VariableDynamic
gets that list from useNodeVariables(includeTypes), the conditions row
narrows to the left operand's type itself. Removes the compatibleTypes
prop and the double filtering.
The MessageOnError entry moved from #/properties/missingPreviousVariable
to #/properties/customError; a 3.0 app whose custom errors use the old
instancePath loses its panel message. Own major changeset with the
migration step, and a section in the 4.0 upgrade guide.
The time picker saved HH:mm:00+00:00 only to pass JSON Schema format: 'time';
the suffix meant nothing. The value is now the bare clock, and node schemas
declare picker-bound properties as type: 'date' / 'datetime' / 'time', which
the SDK validator now checks inside nested objects as well (the demo trigger
keeps them under timeSchedule).

The worker compared date and datetime through new Date(text), so a set value
against an upstream instant depended on the worker's zone. compareDateTime in
execution-core reads a zone-less value from its digits with Date.UTC (the
workflow zone, UTC for now), compares a bare time by clock and a bare date by
day, and is covered under TZ=Europe/Warsaw because CI runs in UTC.
piotrblaszczyk and others added 3 commits November 26, 2026 13:16
…variable

A VariableDynamic field whose stored reference no longer matches any
variable the node can reach fell back to a plain input showing the raw
{{nodes...}} text. It now stays in the picker, which labels the
reference "Missing variable" or "Missing node"; the pencil button
switches back to typing a value.
@librowski
librowski force-pushed the feat/WB-139-variables branch from 14ef41e to 3b4061a Compare November 27, 2026 11:48
@librowski
librowski merged commit 60e8555 into main Nov 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants