import type { NodeDef } from '../../NodeRegistry'; import { currentState } from '../../sharedState'; import { machinePort } from '../../stateMachine'; import { asString } from '../../values'; import { str } from '../shared'; /** * The data side of `State branch`: two outputs, because the two uses pull apart. `name` is what * `Join` and a `Text` want to show, `id` is what a comparison should hold – a rename moves the * name, never the id. Both are empty while the machine is in no state. */ export const CurrentState: NodeDef = { type: 'CurrentState', label: 'Current state', category: 'data', description: 'The state the machine is in: its name to show, its id to compare. Empty for no state.', inputs: [machinePort()], outputs: [str('name'), str('id')], params: [], read: (ctx, _params, input, _def, lookup) => { const machine = asString(input('machine')); const id = currentState(ctx, machine); const name = (id && lookup.machine(machine)?.states.find((s) => s.id === id)?.name) || ''; return { name, id }; }, };