@dudousxd/nestjs-catalog-react 0.18.0 → 0.19.0-preview.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/CatalogManager.d.ts +23 -1
  2. package/dist/CatalogManager.js +76 -13
  3. package/dist/ConnectionPanel.js +15 -123
  4. package/dist/LoadedBySection.d.ts +39 -0
  5. package/dist/LoadedBySection.js +143 -0
  6. package/dist/WorkflowCanvas.d.ts +16 -0
  7. package/dist/WorkflowCanvas.js +705 -77
  8. package/dist/connection-form.d.ts +241 -0
  9. package/dist/connection-form.js +235 -0
  10. package/dist/context.d.ts +78 -4
  11. package/dist/context.js +11 -0
  12. package/dist/index.d.ts +5 -1
  13. package/dist/index.js +23 -0
  14. package/dist/routes.d.ts +30 -0
  15. package/dist/routes.js +2 -0
  16. package/dist/schema-discovery.d.ts +17 -1
  17. package/dist/schema-discovery.js +3 -3
  18. package/dist/source-connection.d.ts +82 -0
  19. package/dist/source-connection.js +176 -0
  20. package/dist/source-fields.d.ts +15 -2
  21. package/dist/source-fields.js +15 -2
  22. package/dist/ui/combobox.d.ts +97 -0
  23. package/dist/ui/combobox.js +80 -0
  24. package/dist/workflow/edges.d.ts +110 -0
  25. package/dist/workflow/edges.js +112 -0
  26. package/dist/workflow/graph.d.ts +39 -1
  27. package/dist/workflow/graph.js +181 -43
  28. package/dist/workflow/index.d.ts +7 -1
  29. package/dist/workflow/index.js +10 -5
  30. package/dist/workflow/lifecycle.d.ts +0 -29
  31. package/dist/workflow/lifecycle.js +2 -35
  32. package/dist/workflow/model.d.ts +17 -3
  33. package/dist/workflow/model.js +7 -2
  34. package/dist/workflow/nodes.d.ts +4 -1
  35. package/dist/workflow/nodes.js +190 -11
  36. package/dist/workflow/templates.js +10 -0
  37. package/dist/workflow/validate.js +11 -0
  38. package/dist/workflow/wiring.d.ts +84 -0
  39. package/dist/workflow/wiring.js +254 -0
  40. package/package.json +9 -9
@@ -7,27 +7,32 @@ import { Background, BackgroundVariant, ConnectionLineType, Controls, MiniMap, N
7
7
  // See src/styles.d.ts for why `tsc` tolerates this import.
8
8
  import '@xyflow/react/dist/style.css';
9
9
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
10
- import { ArrowRight, CircleAlert, CircleDashed, Code2, Database, ExternalLink, LayoutGrid, Link2, Loader2, Plug, Plus, Repeat, Save, Trash2, TriangleAlert, Unplug, } from 'lucide-react';
10
+ import { ArrowRight, CircleAlert, CircleDashed, Code2, Database, ExternalLink, GitBranch, LayoutGrid, Link2, Loader2, Plug, Plus, Repeat, Save, Trash2, TriangleAlert, Unplug, } from 'lucide-react';
11
+ import { useReducedMotion } from 'motion/react';
11
12
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
12
13
  import { connectionOptionsFor } from './ConnectionPanel';
13
14
  import { TransformEditor } from './TransformEditor';
14
15
  import { cn } from './cn';
15
16
  import { catalogQueryKeys, useCatalogClient } from './context';
16
17
  import { SchemaDiscoveryPanel, narrowDiscovery, } from './schema-discovery';
18
+ import { SourceConnectionCreator } from './source-connection';
17
19
  import { INLINE_CONNECTION, KIND_OPTIONS, ReadModeFields, SourceFields, readsIncrementally, sourceConfigFrom, sourceDraftFrom, toConnectorKind, usesConnection, } from './source-fields';
18
20
  import { Button } from './ui/button';
21
+ import { ComboboxField } from './ui/combobox';
19
22
  import { ConfirmDialog } from './ui/dialog';
20
23
  import { TextAreaField, TextField } from './ui/field';
21
24
  import { Select, SelectField } from './ui/select';
22
25
  import { Sheet } from './ui/sheet';
23
26
  import { Tooltip, TooltipProvider } from './ui/tooltip';
24
- import { NODE_HEIGHT, NODE_WIDTH, defaultLabel, layout, layoutIfUnarranged, nextPosition, toFlowEdges, toFlowNodes, } from './workflow/graph';
25
- import { AdoptionNote, PublishControls, RunControls, SchedulePanel, ShrinkRefusalNote, WorkflowStatusBadge, } from './workflow/lifecycle';
26
- import { WORKFLOW_NODE_KINDS, describeDurability, isWorkflowNodeKind, newLocalId, nodeName, producedTypes, } from './workflow/model';
27
+ import { WorkflowEdgeProvider, workflowEdgeTypes } from './workflow/edges';
28
+ import { NODE_HEIGHT, NODE_WIDTH, defaultLabel, flowingEdgeIds, layout, layoutIfUnarranged, nextPosition, toFlowEdges, toFlowNodes, } from './workflow/graph';
29
+ import { PublishControls, RunControls, SchedulePanel, ShrinkRefusalNote, WorkflowStatusBadge, } from './workflow/lifecycle';
30
+ import { WORKFLOW_BRANCH_LABELS, WORKFLOW_NODE_KINDS, callableWorkflowBlock, describeDurability, isWorkflowBranchLabel, isWorkflowNodeKind, isWorkflowPredicateKind, newLocalId, nodeName, producedTypes, unreachableNodeKind, unreachablePredicateKind, } from './workflow/model';
27
31
  import { WORKFLOW_NAME } from './workflow/name';
28
32
  import { WorkflowNodeProvider, workflowNodeTypes } from './workflow/nodes';
29
33
  import { RunsAsPanel } from './workflow/runs';
30
34
  import { canConnect, edgeId, hasBlockingProblem, problemsByNode, validateWorkflow, } from './workflow/validate';
35
+ import { PendingWireLine, WiringHint, useClickWiring, } from './workflow/wiring';
31
36
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
32
37
  const RULE = 'border-zinc-200 dark:border-zinc-800';
33
38
  const PANEL = 'bg-white dark:bg-zinc-900';
@@ -145,7 +150,49 @@ function newNodeOfKind(kind, id, position, name) {
145
150
  // version 1 in whatever deployment this graph is promoted into.
146
151
  return { id, name, kind: 'call', callName: '', callVersion: '', config: {}, position };
147
152
  }
148
- return { id, name, kind: 'sink', targetType: '', position };
153
+ if (kind === 'if') {
154
+ // No variable, so the graph is invalid until somebody names one. There is
155
+ // nothing to guess: which variable tells this deployment apart from another
156
+ // is the entire content of the node, and a default would be a decision the
157
+ // graph appears to make and nobody authored.
158
+ //
159
+ // The *kind* of test does get a default, and it is the deployment one,
160
+ // because a predicate has to be one of them and an empty variable name is a
161
+ // gate that visibly refuses to publish. A row-count gate with its default
162
+ // threshold would publish happily while testing something nobody chose.
163
+ return { id, name, kind: 'if', predicate: { kind: 'env', envVar: '' }, position };
164
+ }
165
+ if (kind === 'sink') {
166
+ return { id, name, kind: 'sink', targetType: '', position };
167
+ }
168
+ return unreachableNodeKind(kind, 'newNodeOfKind');
169
+ }
170
+ /**
171
+ * A wire, with its branch already decided when it leaves an `if`.
172
+ *
173
+ * Assigned here rather than left blank for somebody to fill in, because a blank
174
+ * one is refused by `validateWorkflow` and the refusal would fire on the very
175
+ * first wire out of a node somebody just created — the premature-error problem
176
+ * `partitionProblems` exists to describe, arrived at from a different direction.
177
+ *
178
+ * The first wire out of a gate is the `then`, the second is the `else`, and
179
+ * after that it is `then` again. That ordering is not arbitrary: those are the
180
+ * two somebody is drawing when they draw a gate, in that order, and a third wire
181
+ * is fan-out on a side they then choose in the inspector. Every one of them is
182
+ * editable there, so this is a default and never a decision.
183
+ */
184
+ function newEdge(nodes, edges, from, to) {
185
+ const source = nodes.find((node) => node.id === from);
186
+ if (source?.kind !== 'if')
187
+ return { from, to };
188
+ const taken = edges.filter((edge) => edge.from === from).map((edge) => edge.branch);
189
+ const free = WORKFLOW_BRANCH_LABELS.find((label) => !taken.includes(label));
190
+ return { from, to, branch: free ?? 'then' };
191
+ }
192
+ /** The same graph with one wire moved onto the other side of its gate. */
193
+ function edgeOnBranch(edges, moving, branch) {
194
+ const id = edgeId(moving);
195
+ return edges.map((edge) => (edgeId(edge) === id ? { ...edge, branch } : edge));
149
196
  }
150
197
  /**
151
198
  * The code a transform created from this canvas starts as: the batch, unchanged.
@@ -382,6 +429,11 @@ const TODO_FOR = {
382
429
  'missing-transform': 'choose a transform that still exists',
383
430
  'source-has-input': 'unwire whatever feeds it — a source reads, it is not fed',
384
431
  'sink-has-output': 'unwire what it feeds — nothing runs after a sink',
432
+ 'if-not-named': 'name the environment variable it decides on',
433
+ 'if-threshold-invalid': 'give it a whole number of rows, 1 or more, to branch on',
434
+ 'if-needs-one-input': 'leave it one input — a gate carries one stream through',
435
+ 'branch-not-labelled': 'say whether that wire is the "then" or the "else"',
436
+ 'branch-on-plain-edge': 'remove the branch label — only an if node branches',
385
437
  };
386
438
  function todoFor(problem) {
387
439
  return TODO_FOR[problem.code] ?? 'finish setting it up';
@@ -469,7 +521,7 @@ function CanvasActions({ draft, stored, canEdit, blocked, unfinished, saving, ru
469
521
  }
470
522
  /** The four things that can be put on the canvas, and the button that tidies them. */
471
523
  function AddNodeBar({ refreshing, onAdd, onTidy, }) {
472
- return (_jsxs("div", { className: "flex shrink-0 flex-wrap items-center gap-2 px-6 pt-3", children: [_jsx(AddButton, { icon: Plug, label: "Source", hint: "Reads records out of a system: a kind, an optional named connection, and a config.", onClick: () => onAdd('source') }), _jsx(AddButton, { icon: Repeat, label: "Transform", hint: "Code that reshapes whatever is wired into it.", onClick: () => onAdd('transform') }), _jsx(AddButton, { icon: Database, label: "Sink", hint: "Writes and commits one object type. Several are fine \u2014 each commits independently.", onClick: () => onAdd('sink') }), _jsx(AddButton, { icon: ExternalLink, label: "Call", hint: "Hands this step to a durable workflow that already exists, by name and pinned version. It runs as a child of this load, with its own retries.", onClick: () => onAdd('call') }), _jsx(Tooltip, { content: "Lay the nodes out left to right by dependency, with every sink in the last column.", children: _jsxs("button", { type: "button", onClick: onTidy, className: cn('flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs', RULE, MUTED, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(LayoutGrid, { size: 12 }), "Tidy"] }) }), refreshing && (
524
+ return (_jsxs("div", { className: "flex shrink-0 flex-wrap items-center gap-2 px-6 pt-3", children: [_jsx(AddButton, { icon: Plug, label: "Source", hint: "Reads records out of a system: a kind, an optional named connection, and a config.", onClick: () => onAdd('source') }), _jsx(AddButton, { icon: Repeat, label: "Transform", hint: "Code that reshapes whatever is wired into it.", onClick: () => onAdd('transform') }), _jsx(AddButton, { icon: Database, label: "Sink", hint: "Writes and commits one object type. Several are fine \u2014 each commits independently.", onClick: () => onAdd('sink') }), _jsx(AddButton, { icon: ExternalLink, label: "Call", hint: "Hands this step to a durable workflow that already exists, by name and pinned version. It runs as a child of this load, with its own retries.", onClick: () => onAdd('call') }), _jsx(AddButton, { icon: GitBranch, label: "If", hint: "Sends the rows down one of two branches, depending on an environment variable where the load runs. The other branch is skipped \u2014 a sink on it commits nothing and leaves what is published alone.", onClick: () => onAdd('if') }), _jsx(Tooltip, { content: "Lay the nodes out left to right by dependency, with every sink in the last column.", children: _jsxs("button", { type: "button", onClick: onTidy, className: cn('flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs', RULE, MUTED, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(LayoutGrid, { size: 12 }), "Tidy"] }) }), refreshing && (
473
525
  // A background refetch says so without replacing anything: the graph on
474
526
  // screen stays exactly where it is.
475
527
  _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: "refreshing\u2026" }))] }));
@@ -510,6 +562,11 @@ function miniMapColor(data) {
510
562
  // and the canvas agree about which boxes are somebody else's workflow.
511
563
  if (kind === 'call')
512
564
  return '#f59e0b';
565
+ // Fuchsia-500, the gate's own accent, and deliberately not the violet a
566
+ // transform gets: the overview is where somebody looks to find the branch in
567
+ // a graph too big to read, so it is the one place the two must not blur.
568
+ if (kind === 'if')
569
+ return '#d946ef';
513
570
  return '#8b5cf6';
514
571
  }
515
572
  /**
@@ -519,12 +576,18 @@ function miniMapColor(data) {
519
576
  * place of the screen, so the header and its controls stay put while a refetch
520
577
  * resolves — and a failed read never looks like an empty workflow.
521
578
  */
522
- function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNodes, flowEdges, onInspect, onEditCode, onNodesChange, onEdgesChange, onConnect, isValidConnection, onConnectEnd, onNodeEnter, onNodeLeave, onPaneClick, nodeMenu, }) {
523
- return (_jsxs("div", { className: cn('relative h-[55vh] min-h-[15rem] shrink-0 overflow-hidden rounded-lg border', 'lg:h-auto lg:min-h-0 lg:flex-1 lg:shrink', RULE), children: [loading && _jsx(CanvasSkeleton, {}), failed && _jsx(CanvasFailure, { error: error, onRetry: onRetry }), !loading && !failed && (_jsx(WorkflowNodeProvider, { handlers: { onInspect, onEditCode, canEdit }, children: _jsxs(ReactFlow, { className: CANVAS_THEME, nodes: flowNodes, edges: flowEdges, nodeTypes: workflowNodeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: onConnectEnd, onNodeMouseEnter: (_event, node) => onNodeEnter(node.id), onNodeMouseLeave: onNodeLeave, onPaneClick: onPaneClick, connectionLineType: ConnectionLineType.SmoothStep, nodesDraggable: canEdit, nodesConnectable: canEdit, elementsSelectable: true, nodesFocusable: true, edgesFocusable: true, deleteKeyCode: canEdit ? ['Delete', 'Backspace'] : null,
524
- // A wider drop zone than the 20px default, because these handles are
525
- // the only drop target on the screen and missing one reads as the
526
- // canvas ignoring you.
527
- connectionRadius: 28, proOptions: { hideAttribution: false }, ariaLabelConfig: ARIA_LABELS, "aria-label": `${WORKFLOW_NAME.title} canvas. ${draft.nodes.length} nodes, ${draft.edges.length} connections.`, fitView: true, children: [_jsx(Background, { variant: BackgroundVariant.Dots, gap: 18, size: 1 }), _jsx(Controls, { showInteractive: false }), _jsx(MiniMap, { pannable: true, zoomable: true, nodeColor: (node) => miniMapColor(node.data) }), nodeMenu] }) }))] }));
579
+ function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNodes, flowEdges, onInspect, onEditCode, onNodesChange, onEdgesChange, onConnect, isValidConnection, onConnectEnd, onNodeEnter, onNodeLeave, onPaneClick, onDisconnect, wiring, wiringRefusal, nodeMenu, }) {
580
+ return (_jsxs("div", { className: cn('relative h-[55vh] min-h-[15rem] shrink-0 overflow-hidden rounded-lg border', 'lg:h-auto lg:min-h-0 lg:flex-1 lg:shrink', RULE), children: [loading && _jsx(CanvasSkeleton, {}), failed && _jsx(CanvasFailure, { error: error, onRetry: onRetry }), !loading && !failed && (_jsx(WorkflowNodeProvider, { handlers: { onInspect, onEditCode, canEdit, wiring }, children: _jsx(WorkflowEdgeProvider, { handlers: { onDisconnect, canEdit }, children: _jsxs(ReactFlow, { className: CANVAS_THEME, nodes: flowNodes, edges: flowEdges, nodeTypes: workflowNodeTypes, edgeTypes: workflowEdgeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: onConnectEnd, onNodeMouseEnter: (_event, node) => onNodeEnter(node.id), onNodeMouseLeave: onNodeLeave, onPaneClick: onPaneClick, connectionLineType: ConnectionLineType.SmoothStep,
581
+ // Off, so there is exactly ONE click path through a handle and it
582
+ // is the one in `workflow/wiring.tsx`. React Flow's own click
583
+ // wiring connects but draws nothing while it is open and cannot
584
+ // say why it refused — running both would mean two states
585
+ // disagreeing about whether a wire is in flight.
586
+ connectOnClick: false, nodesDraggable: canEdit, nodesConnectable: canEdit, elementsSelectable: true, nodesFocusable: true, edgesFocusable: true, deleteKeyCode: canEdit ? ['Delete', 'Backspace'] : null,
587
+ // A wider drop zone than the 20px default, because these handles are
588
+ // the only drop target on the screen and missing one reads as the
589
+ // canvas ignoring you.
590
+ connectionRadius: 28, proOptions: { hideAttribution: false }, ariaLabelConfig: ARIA_LABELS, "aria-label": `${WORKFLOW_NAME.title} canvas. ${draft.nodes.length} nodes, ${draft.edges.length} connections.`, fitView: true, children: [_jsx(Background, { variant: BackgroundVariant.Dots, gap: 18, size: 1 }), _jsx(Controls, { showInteractive: false, className: "!overflow-hidden !rounded-lg !border !border-zinc-200 !shadow-sm dark:!border-zinc-800 [&>button]:!border-none" }), _jsx(MiniMap, { pannable: true, zoomable: true, nodeColor: (node) => miniMapColor(node.data), className: "!overflow-hidden !rounded-lg !border !border-zinc-200 !shadow-sm dark:!border-zinc-800" }), _jsx(PendingWireLine, { pending: wiring.pending }), _jsx(WiringHint, { pending: wiring.pending, refusal: wiringRefusal, nodes: draft.nodes, onCancel: wiring.cancel }), nodeMenu] }) }) }))] }));
528
591
  }
529
592
  /**
530
593
  * The wiring control that lives on a node, and the menu behind it.
@@ -732,17 +795,6 @@ function storedWorkflow(list, id) {
732
795
  return undefined;
733
796
  return list?.find((workflow) => workflow.id === id);
734
797
  }
735
- /**
736
- * Whether a source node can be asked what its columns are, and why not.
737
- *
738
- * Discovery reads the node the SERVER has, so the two states it cannot run in
739
- * are "never saved" and "saved, but not like this". **Neither of them is
740
- * "unpublished"**, and that is the whole point of the route: a sink cannot
741
- * commit into a type that does not exist, so requiring a published graph would
742
- * require publishing a graph whose target type cannot be created until it is.
743
- * The reasons therefore name saving and never publishing — a reader told to
744
- * publish first would go and do it, and find they cannot.
745
- */
746
798
  function discoveryTarget(draft) {
747
799
  if (!draft.id) {
748
800
  return {
@@ -779,7 +831,7 @@ function readsDifferently(before, after) {
779
831
  before.mode !== after.mode ||
780
832
  JSON.stringify(before.config ?? {}) !== JSON.stringify(after.config ?? {}));
781
833
  }
782
- function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intro = 'Wire sources through transforms into sinks. Each sink commits its own object type independently, so one expensive read can feed several outputs.', canEdit = true, }) {
834
+ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intro = 'Wire sources through transforms into sinks. Each sink commits its own object type independently, so one expensive read can feed several outputs.', canEdit = true, modelHref, }) {
783
835
  const client = useCatalogClient();
784
836
  const queryClient = useQueryClient();
785
837
  const { fitView } = useReactFlow();
@@ -959,13 +1011,18 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
959
1011
  selected: selectedIds.has(node.id),
960
1012
  }));
961
1013
  }, [draft.nodes, draft.edges, describe, problemsFor, runFor, selectedNodeIds]);
1014
+ // `useReducedMotion` returns null until it has asked, which is neither yes nor
1015
+ // no; coerced here because every consumer of it wants the boolean, and the
1016
+ // safe reading of "has not answered yet" is "do not animate".
1017
+ const reducedMotion = useReducedMotion() !== false;
1018
+ const flowing = useMemo(() => flowingEdgeIds(draft.edges, run?.nodes ?? [], { reducedMotion }), [draft.edges, run, reducedMotion]);
962
1019
  const flowEdges = useMemo(() => {
963
1020
  const selectedIds = new Set(selectedEdgeIds);
964
- return toFlowEdges(draft.edges, draft.nodes, brokenEdgeIds).map((edge) => ({
1021
+ return toFlowEdges(draft.edges, draft.nodes, brokenEdgeIds, flowing).map((edge) => ({
965
1022
  ...edge,
966
1023
  selected: selectedIds.has(edge.id),
967
1024
  }));
968
- }, [draft.edges, draft.nodes, brokenEdgeIds, selectedEdgeIds]);
1025
+ }, [draft.edges, draft.nodes, brokenEdgeIds, selectedEdgeIds, flowing]);
969
1026
  /**
970
1027
  * React Flow's changes, applied to the stored model rather than to a second
971
1028
  * copy of the graph.
@@ -1056,6 +1113,19 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1056
1113
  markStarted(edge.from, edge.to);
1057
1114
  setAnnouncement('Connection removed.');
1058
1115
  }, [edit, markStarted]);
1116
+ /**
1117
+ * Put a wire on the other side of its gate.
1118
+ *
1119
+ * Announced, like every other wiring change on this screen, because the only
1120
+ * visible effect is a word on a line the reader may not be looking at — and
1121
+ * moving a wire from `then` to `else` is one of the largest changes anybody
1122
+ * can make here: it inverts which half of the pipeline runs.
1123
+ */
1124
+ const setBranch = useCallback((edge, branch) => {
1125
+ edit((current) => ({ ...current, edges: edgeOnBranch(current.edges, edge, branch) }));
1126
+ markStarted(edge.from, edge.to);
1127
+ setAnnouncement(`${nodeLabelIn(draft.nodes, edge.to)} is now on the "${branch}" branch of ${nodeLabelIn(draft.nodes, edge.from)}.`);
1128
+ }, [draft.nodes, edit, markStarted]);
1059
1129
  const connect = useCallback((from, to) => {
1060
1130
  const verdict = canConnect(draft.nodes, draft.edges, from, to);
1061
1131
  if (!verdict.ok) {
@@ -1065,7 +1135,10 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1065
1135
  // Appended rather than inserted anywhere else: a node with several inbound
1066
1136
  // edges receives its inputs in the order the edges appear in this array,
1067
1137
  // and that order is part of what the graph produces.
1068
- edit((current) => ({ ...current, edges: [...current.edges, { from, to }] }));
1138
+ edit((current) => ({
1139
+ ...current,
1140
+ edges: [...current.edges, newEdge(current.nodes, current.edges, from, to)],
1141
+ }));
1069
1142
  markStarted(from, to);
1070
1143
  setAnnouncement(`${nodeLabelIn(draft.nodes, from)} now feeds ${nodeLabelIn(draft.nodes, to)}.`);
1071
1144
  }, [draft.nodes, draft.edges, edit, markStarted]);
@@ -1109,6 +1182,22 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1109
1182
  return false;
1110
1183
  return canConnect(draft.nodes, draft.edges, candidate.source, candidate.target).ok;
1111
1184
  }, [draft.nodes, draft.edges]);
1185
+ /**
1186
+ * Wiring by clicking twice, which is the gesture people actually reach for.
1187
+ *
1188
+ * Built on the same `connect` the menu, the rail and the drag all end in, so
1189
+ * there is one place a connection is made and one place it is refused. Why
1190
+ * React Flow's own `connectOnClick` is turned off in favour of this — it
1191
+ * connects but draws nothing, and cannot say why it refused — is written out
1192
+ * at the top of `workflow/wiring.tsx`.
1193
+ */
1194
+ const { wiring, refusal: wiringRefusal } = useClickWiring({
1195
+ canEdit,
1196
+ nodes: draft.nodes,
1197
+ edges: draft.edges,
1198
+ onConnect: connect,
1199
+ onSay: setAnnouncement,
1200
+ });
1112
1201
  const save = useMutation({
1113
1202
  mutationFn: () => client.saveWorkflow({
1114
1203
  id: draft.id,
@@ -1247,7 +1336,7 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1247
1336
  edit((current) => ({
1248
1337
  ...current,
1249
1338
  nodes: [...current.nodes, node],
1250
- edges: [...current.edges, { from: fromId, to: node.id }],
1339
+ edges: [...current.edges, newEdge(current.nodes, current.edges, fromId, node.id)],
1251
1340
  }));
1252
1341
  setUnstarted((current) => new Set([...current, node.id]));
1253
1342
  menu.close();
@@ -1375,10 +1464,18 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1375
1464
  * not save that: it fits the graph into a box, and half the box was off
1376
1465
  * screen. See `QueryConsole` for the same pattern.
1377
1466
  */
1378
- _jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "shrink-0 px-6 pt-5", children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-x-3 gap-y-1", children: [_jsx("p", { className: cn('font-mono text-[11px] uppercase tracking-[0.18em]', MUTED), children: eyebrow }), _jsx("h1", { className: "text-xl font-semibold tracking-tight", children: title }), stored && _jsx(WorkflowStatusBadge, { workflow: stored }), _jsx(CommitsBadge, { produces: produces })] }), _jsx("p", { className: "mt-0.5 max-w-3xl text-xs text-zinc-500 dark:text-zinc-400", children: intro }), _jsx(DurabilityBanner, { durability: durability }), stored && _jsx(AdoptionNote, { workflow: stored }), _jsxs("div", { className: "mt-2.5 grid gap-3 sm:grid-cols-2 lg:grid-cols-3", children: [_jsx(SelectField, { label: WORKFLOW_NAME.title, ariaLabel: `Which ${WORKFLOW_NAME.singular} to edit`, value: selected, onValueChange: (value) => {
1467
+ _jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "shrink-0 px-6 pt-5", children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-x-3 gap-y-1", children: [_jsx("p", { className: cn('font-mono text-[11px] uppercase tracking-[0.18em]', MUTED), children: eyebrow }), _jsx("h1", { className: "text-xl font-semibold tracking-tight", children: title }), stored && _jsx(WorkflowStatusBadge, { workflow: stored }), _jsx(CommitsBadge, { produces: produces })] }), _jsx("p", { className: "mt-0.5 max-w-3xl text-xs text-zinc-500 dark:text-zinc-400", children: intro }), _jsx(DurabilityBanner, { durability: durability }), workflows.isSuccess && workflows.data.length === 0 && _jsx(NothingDrawnYet, {}), _jsxs("div", { className: "mt-2.5 grid gap-3 sm:grid-cols-2 lg:grid-cols-3", children: [_jsx(SelectField, { label: WORKFLOW_NAME.title, ariaLabel: `Which ${WORKFLOW_NAME.singular} to edit`, value: selected, onValueChange: (value) => {
1379
1468
  loadedRef.current = null;
1380
1469
  setSelected(value);
1381
- }, options: workflowOptions, disabled: workflows.isPending }), _jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => edit((current) => ({ ...current, name })), placeholder: "Fleet readiness", disabled: !canEdit }), _jsx(CanvasActions, { draft: draft, stored: stored, canEdit: canEdit, blocked: blocked, unfinished: unfinished, saving: save.isPending, running: runIt.isPending, durabilityDetail: durability.detail, acknowledging: acknowledging, onAcknowledgingChange: setAcknowledging, onSave: saveNow, onRun: runNow, onLifecycleChange: onLifecycleChange, onAskDelete: () => setConfirmingDelete(true) })] }), save.error && _jsx(RefusalNote, { lead: "The server refused it:", error: save.error }), runIt.error && _jsx(RefusalNote, { lead: "The run could not start:", error: runIt.error }), _jsx(ShrinkRefusalNote, { run: run, error: runIt.error, onAcknowledge: () => setAcknowledging(true) })] }), canEdit && (_jsx(AddNodeBar, { refreshing: workflows.isFetching && !workflows.isPending, onAdd: addNode, onTidy: tidy })), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-6 pb-5 pt-3 lg:flex-row lg:overflow-hidden", children: [_jsx(GraphSurface, { loading: workflows.isPending, failed: workflows.isError, error: workflows.error, onRetry: () => workflows.refetch(), canEdit: canEdit, draft: draft, flowNodes: flowNodes, flowEdges: flowEdges, onInspect: setInspecting, onEditCode: setEditingCodeFor, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: announceRefusedDrop, onNodeEnter: menu.onNodeEnter, onNodeLeave: menu.onNodeLeave, onPaneClick: menu.close, nodeMenu: _jsx(NodeWiringMenu, { node: menu.anchor, draft: draft, canEdit: canEdit, open: menu.open, onOpenChange: menu.onOpenChange, onHoverChange: menu.onHoverChange, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect }) }), _jsx(WiringRail, { draft: draft, problems: live, pending: pending, run: run, canEdit: canEdit, onInspect: setInspecting, onDisconnect: disconnect, children: stored && (_jsxs(_Fragment, { children: [_jsx(SchedulePanel, { workflow: stored, canEdit: canEdit, onScheduled: onLifecycleChange }, stored.id), _jsx(RunsAsPanel, { workflowId: stored.id, status: stored.status, transforms: graphTransforms })] })) })] }), _jsx("output", { "aria-live": "polite", className: "sr-only", children: announcement }), _jsx(NodeInspector, { node: inspectingNode, draft: draft, transforms: transforms, connections: connections, typeOptions: typeOptions, canEdit: canEdit, problems: problemsOf(problemsFor, inspectingNode), pending: problemsOf(pendingFor, inspectingNode), discovery: discovery, discoverable: discoveryTarget(draft), onDiscovered: rememberShape, onClose: () => setInspecting(null), onChange: (next) => {
1470
+ }, options: workflowOptions, disabled: workflows.isPending }), _jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => edit((current) => ({ ...current, name })), placeholder: "Fleet readiness", disabled: !canEdit }), _jsx(CanvasActions, { draft: draft, stored: stored, canEdit: canEdit, blocked: blocked, unfinished: unfinished, saving: save.isPending, running: runIt.isPending, durabilityDetail: durability.detail, acknowledging: acknowledging, onAcknowledgingChange: setAcknowledging, onSave: saveNow, onRun: runNow, onLifecycleChange: onLifecycleChange, onAskDelete: () => setConfirmingDelete(true) })] }), save.error && _jsx(RefusalNote, { lead: "The server refused it:", error: save.error }), runIt.error && _jsx(RefusalNote, { lead: "The run could not start:", error: runIt.error }), _jsx(ShrinkRefusalNote, { run: run, error: runIt.error, onAcknowledge: () => setAcknowledging(true) })] }), canEdit && (_jsx(AddNodeBar, { refreshing: workflows.isFetching && !workflows.isPending, onAdd: addNode, onTidy: tidy })), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-6 pb-5 pt-3 lg:flex-row lg:overflow-hidden", children: [_jsx(GraphSurface, { loading: workflows.isPending, failed: workflows.isError, error: workflows.error, onRetry: () => workflows.refetch(), canEdit: canEdit, draft: draft, flowNodes: flowNodes, flowEdges: flowEdges, onInspect: setInspecting, onEditCode: setEditingCodeFor, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: announceRefusedDrop, onNodeEnter: menu.onNodeEnter, onNodeLeave: menu.onNodeLeave,
1471
+ // Clicking empty canvas puts away everything that is half-open: the
1472
+ // wiring menu, and a wire that was started and never landed. React
1473
+ // Flow only fires this for clicks on the pane ITSELF, so finishing a
1474
+ // wire on a handle does not also cancel it on the way past.
1475
+ onPaneClick: () => {
1476
+ menu.close();
1477
+ wiring.cancel();
1478
+ }, onDisconnect: disconnect, wiring: wiring, wiringRefusal: wiringRefusal, nodeMenu: _jsx(NodeWiringMenu, { node: menu.anchor, draft: draft, canEdit: canEdit, open: menu.open, onOpenChange: menu.onOpenChange, onHoverChange: menu.onHoverChange, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect }) }), _jsx(WiringRail, { draft: draft, problems: live, pending: pending, run: run, canEdit: canEdit, onInspect: setInspecting, onDisconnect: disconnect, children: stored && (_jsxs(_Fragment, { children: [_jsx(SchedulePanel, { workflow: stored, canEdit: canEdit, onScheduled: onLifecycleChange }, stored.id), _jsx(RunsAsPanel, { workflowId: stored.id, status: stored.status, transforms: graphTransforms })] })) })] }), _jsx("output", { "aria-live": "polite", className: "sr-only", children: announcement }), _jsx(NodeInspector, { node: inspectingNode, draft: draft, transforms: transforms, connections: connections, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, problems: problemsOf(problemsFor, inspectingNode), pending: problemsOf(pendingFor, inspectingNode), discovery: discovery, discoverable: { ...discoveryTarget(draft), onSave: saveNow, saving: save.isPending }, onDiscovered: rememberShape, onClose: () => setInspecting(null), onChange: (next) => {
1382
1479
  // Editing any field is the clearest statement there is that somebody
1383
1480
  // is working on this node rather than looking at one they just made.
1384
1481
  markStarted(next.id);
@@ -1401,7 +1498,7 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1401
1498
  ...current,
1402
1499
  nodes: current.nodes.map((node) => (node.id === next.id ? next : node)),
1403
1500
  }));
1404
- }, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect, onCreateTransform: (nodeId) => createTransform.mutate(nodeId), creatingTransform: createTransform.isPending, createTransformError: createTransform.error, onDelete: (nodeId) => {
1501
+ }, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect, onBranch: setBranch, onCreateTransform: (nodeId) => createTransform.mutate(nodeId), creatingTransform: createTransform.isPending, createTransformError: createTransform.error, onDelete: (nodeId) => {
1405
1502
  edit((current) => ({
1406
1503
  ...current,
1407
1504
  nodes: current.nodes.filter((node) => node.id !== nodeId),
@@ -1450,6 +1547,29 @@ function DurabilityBanner({ durability, }) {
1450
1547
  function CanvasSkeleton() {
1451
1548
  return (_jsx("div", { className: "flex h-full w-full items-center justify-center bg-zinc-50 dark:bg-zinc-950", children: _jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "h-16 w-48 animate-pulse rounded-lg bg-zinc-200 dark:bg-zinc-800" }), _jsx(ArrowRight, { size: 14, className: MUTED }), _jsx("div", { className: "h-16 w-48 animate-pulse rounded-lg bg-zinc-200 dark:bg-zinc-800" }), _jsx(ArrowRight, { size: 14, className: MUTED }), _jsx("div", { className: "h-16 w-48 animate-pulse rounded-lg bg-zinc-200 dark:bg-zinc-800" })] }) }));
1452
1549
  }
1550
+ /**
1551
+ * That there are none, said rather than drawn as a blank canvas.
1552
+ *
1553
+ * The zero case used to be nearly unreachable: a deployment that had connectors
1554
+ * got them wrapped into graphs at boot, so `#workflows` opened onto thirteen of
1555
+ * them. Nothing wraps anything now — a graph exists because somebody drew one —
1556
+ * so a deployment that has never drawn one opens onto an empty canvas, which is
1557
+ * pixel-identical to a workflow whose nodes have all been deleted and to a list
1558
+ * that failed to load in a way the query did not notice.
1559
+ *
1560
+ * So it says which of the three it is, and what to do about it. The distinction
1561
+ * this file already draws between {@link CanvasSkeleton} and
1562
+ * {@link CanvasFailure} is the same one, for the same reason: three states that
1563
+ * render identically and mean different things need one of them to speak.
1564
+ *
1565
+ * It carries no button. The control that creates a workflow is the `New
1566
+ * workflow` option already selected in the picker three lines below this note,
1567
+ * and a second affordance pointing at the same act is how somebody ends up
1568
+ * wondering whether the two do different things.
1569
+ */
1570
+ function NothingDrawnYet() {
1571
+ return (_jsxs("div", { className: cn('mt-2.5 flex flex-wrap items-baseline gap-x-2 rounded-md border border-dashed px-2.5 py-1.5', RULE), children: [_jsxs("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: ["No ", WORKFLOW_NAME.plural, " yet"] }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["Nothing is missing \u2014 this deployment has never had one drawn. Add a source, wire it into a sink and save, and it becomes the first. If this deployment has connectors already loading data, they are not shown here and nothing turns them into ", WORKFLOW_NAME.plural, "automatically."] })] }));
1572
+ }
1453
1573
  function CanvasFailure({ error, onRetry, }) {
1454
1574
  return (_jsx("div", { className: "flex h-full w-full items-center justify-center bg-red-50 px-6 dark:bg-red-950/30", children: _jsxs("div", { className: "max-w-md text-center", children: [_jsx(CircleAlert, { size: 18, className: "mx-auto text-red-600" }), _jsxs("p", { className: "mt-2 text-sm text-red-700 dark:text-red-300", children: ["The ", WORKFLOW_NAME.plural, " could not be read, so nothing below is drawn. This is not an empty ", WORKFLOW_NAME.singular, "."] }), _jsx("p", { className: "mt-1 font-mono text-[11px] text-red-600 dark:text-red-400", children: error instanceof Error ? error.message : 'No reason was given.' }), _jsx("button", { type: "button", onClick: onRetry, className: "mt-3 rounded-md border border-red-300 px-3 py-1 text-xs text-red-700 dark:border-red-800 dark:text-red-300", children: "Try again" })] }) }));
1455
1575
  }
@@ -1514,8 +1634,21 @@ function PendingWork({ pending, label, onInspect, }) {
1514
1634
  * description of it. Only which end of the edge to name, and how removing it is
1515
1635
  * announced, differ; `children` carries whatever belongs under the list.
1516
1636
  */
1517
- function WiringList({ title, edges, otherEnd, describeRemoval, canEdit, onDisconnect, children, }) {
1518
- return (_jsxs("section", { children: [_jsx("h3", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: title }), edges.length === 0 ? (_jsx("p", { className: cn('mt-1 text-[11px]', MUTED), children: "Nothing yet." })) : (_jsx("ul", { className: "mt-1 space-y-1", children: edges.map((edge) => (_jsxs("li", { className: "flex items-center gap-1.5 text-[11px]", children: [_jsx("span", { className: "truncate", children: otherEnd(edge) }), canEdit && (_jsx(Tooltip, { content: "Remove this connection.", children: _jsx("button", { type: "button", onClick: () => onDisconnect(edge), "aria-label": describeRemoval(otherEnd(edge)), className: "ml-auto rounded p-0.5 text-zinc-400 hover:text-red-600", children: _jsx(Unplug, { size: 11 }) }) }))] }, edgeId(edge)))) })), children] }));
1637
+ function WiringList({ title, edges, otherEnd, describeRemoval, canEdit, onDisconnect, onBranch, children, }) {
1638
+ return (_jsxs("section", { children: [_jsx("h3", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: title }), edges.length === 0 ? (_jsx("p", { className: cn('mt-1 text-[11px]', MUTED), children: "Nothing yet." })) : (_jsx("ul", { className: "mt-1 space-y-1", children: edges.map((edge) => (_jsxs("li", { className: "flex items-center gap-1.5 text-[11px]", children: [_jsx("span", { className: "truncate", children: otherEnd(edge) }), onBranch && (
1639
+ // Beside the wire it belongs to rather than as two lists headed
1640
+ // "Then" and "Else", because the branch is a property of the
1641
+ // wire: splitting the list would mean a wire changing sides has
1642
+ // to move between two controls, and the order the wires were
1643
+ // drawn in — which is what the canvas draws — would be lost.
1644
+ _jsx("div", { className: "ml-auto w-28 shrink-0", children: _jsx(Select, { ariaLabel: `Which branch feeds ${otherEnd(edge)}`, value: edge.branch ?? '', onValueChange: (branch) => {
1645
+ if (!isWorkflowBranchLabel(branch))
1646
+ return;
1647
+ onBranch(edge, branch);
1648
+ }, options: WORKFLOW_BRANCH_LABELS.map((label) => ({
1649
+ value: label,
1650
+ label,
1651
+ })), placeholder: "branch?", disabled: !canEdit }) })), canEdit && (_jsx(Tooltip, { content: "Remove this connection.", children: _jsx("button", { type: "button", onClick: () => onDisconnect(edge), "aria-label": describeRemoval(otherEnd(edge)), className: "ml-auto rounded p-0.5 text-zinc-400 hover:text-red-600", children: _jsx(Unplug, { size: 11 }) }) }))] }, edgeId(edge)))) })), children] }));
1519
1652
  }
1520
1653
  /**
1521
1654
  * Which code runs here, and a way into it.
@@ -1561,9 +1694,23 @@ function TransformInspector({ node, transforms, canEdit, creating, createError,
1561
1694
  *
1562
1695
  * The type is set here, on the node that commits it, rather than once for the
1563
1696
  * whole graph — several sinks may write several types.
1697
+ *
1698
+ * ## The way out to the type
1699
+ *
1700
+ * This inspector is the one place in the whole canvas that names an object type,
1701
+ * so it is the only honest place for a link to the model screen. It sits under
1702
+ * the picker rather than in the header, and it names the type rather than saying
1703
+ * "Open the model": the destination is that type's page, and a link whose label
1704
+ * describes a screen rather than a thing gives no clue what pressing it shows.
1705
+ *
1706
+ * Rendered only when a type is actually chosen. A fresh sink's `targetType` is
1707
+ * the empty string, and `#model?type=` names nothing — it would land on the
1708
+ * model screen's first type and look, exactly, like a link that worked.
1564
1709
  */
1565
- function SinkInspector({ node, typeOptions, canEdit, onChange, }) {
1566
- return (_jsxs("div", { className: "space-y-3", children: [_jsx(SelectField, { label: "Commits", ariaLabel: "Which object type this sink writes", value: node.targetType, onValueChange: (targetType) => onChange({ ...node, targetType }), options: typeOptions, placeholder: "Choose one type\u2026", disabled: !canEdit, hint: "The type is set here, on the node that commits it, rather than once for the whole graph \u2014 several sinks may write several types." }), _jsx(SelectField, { label: "Commit mode", ariaLabel: "Whether this sink replaces the dataset or merges into it", value: node.mode ?? 'full', onValueChange: (mode) => onChange({
1710
+ function SinkInspector({ node, typeOptions, canEdit, modelHref, onChange, }) {
1711
+ const target = node.targetType.trim();
1712
+ const href = target.length > 0 ? modelHref?.(target) : undefined;
1713
+ return (_jsxs("div", { className: "space-y-3", children: [_jsx(SelectField, { label: "Commits", ariaLabel: "Which object type this sink writes", value: node.targetType, onValueChange: (targetType) => onChange({ ...node, targetType }), options: typeOptions, placeholder: "Choose one type\u2026", disabled: !canEdit, hint: "The type is set here, on the node that commits it, rather than once for the whole graph \u2014 several sinks may write several types." }), href && (_jsxs("a", { href: href, "aria-label": `Open ${target} on the model screen`, className: cn('inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs outline-none', RULE, 'hover:bg-zinc-50 focus-visible:ring-2 focus-visible:ring-sky-500/40 dark:hover:bg-zinc-800'), children: [_jsx(Database, { size: 12, "aria-hidden": true }), "Open ", target, _jsx(ExternalLink, { size: 12, "aria-hidden": true, className: MUTED })] })), _jsx(SelectField, { label: "Commit mode", ariaLabel: "Whether this sink replaces the dataset or merges into it", value: node.mode ?? 'full', onValueChange: (mode) => onChange({
1567
1714
  ...node,
1568
1715
  mode: mode === 'incremental' ? 'incremental' : 'full',
1569
1716
  }), options: [
@@ -1574,32 +1721,101 @@ function SinkInspector({ node, typeOptions, canEdit, onChange, }) {
1574
1721
  /**
1575
1722
  * Which workflow this node hands its step to, and what it hands it.
1576
1723
  *
1577
- * ## Two fields, typed, and no picker
1578
- *
1579
- * The obvious design is a dropdown of the workflows this deployment has, and it
1580
- * cannot be built honestly today: nothing can enumerate them. The durable
1581
- * engine answers `workflowBody(name, version)` for the process asking and
1582
- * nothing else, and a missing body means *either* "not registered" *or* "its
1583
- * body is in another SDK" *or* "it is a group resolved against a live worker" —
1584
- * so a list inferred from it would omit precisely the cross-SDK workflows this
1585
- * node exists to call, and would omit them silently. A picker that quietly
1586
- * hides the thing you are looking for is worse than a text box.
1587
- *
1588
- * So: text, and `CallableWorkflowRef` in core is the shape to hand this
1589
- * component the day a deployment can announce its registrations. One entry per
1590
- * name **and version**, never per name — a picker that chose the version for
1591
- * you would undo the pin below.
1724
+ * ## There is a picker now, and there was not before
1725
+ *
1726
+ * This used to be two text fields and a docblock explaining why a dropdown
1727
+ * could not be built honestly, and that explanation is worth keeping because it
1728
+ * is still what the picker has to be careful about. Nothing could enumerate a
1729
+ * deployment's registrations: the durable engine answered
1730
+ * `workflowBody(name, version)` for the process asking and nothing else, and a
1731
+ * missing body meant *either* "not registered" *or* "its body is in another SDK
1732
+ * behind `registerRemote`" *or* "it is a group resolved by convention against a
1733
+ * live worker". A list inferred from that would have omitted precisely the
1734
+ * cross-SDK workflows this node exists to call, and omitted them silently — a
1735
+ * picker that quietly hides the thing you are looking for is worse than a text
1736
+ * box.
1737
+ *
1738
+ * `@dudousxd/nestjs-durable-core` **0.65.0** added
1739
+ * `WorkflowEngine.announcedWorkflows()`, which is not an inference: live workers
1740
+ * publish what they can execute on the descriptor keyspace and every pod folds
1741
+ * the same statements. `GET pipeline/callable-workflows` serves it as
1742
+ * `CallableWorkflowRef`s, and the two fields below offer them. Three properties
1743
+ * of that aggregate are load-bearing here and none of them may be flattened:
1744
+ *
1745
+ * - **It lists what is runnable now, not what is known about.** The announcer is
1746
+ * always the queue's consumer, so it is neither a superset nor a subset of any
1747
+ * registry. A workflow missing from it may be perfectly real.
1748
+ * - **It is a snapshot about one heartbeat wide.** Liveness is a TTL on the
1749
+ * descriptor key, so a worker that dies takes its entries with it within about
1750
+ * half a minute. Hence the ten-second `staleTime` below, the refetch on mount,
1751
+ * and the time printed under the field. It is never cached like
1752
+ * `capabilities`, which is stale-forever and correctly so.
1753
+ * - **Disagreements are surfaced, never resolved.** Two workers claiming one
1754
+ * `name@version` from two groups mean nobody can say which queue a run would
1755
+ * land on, so `callableWorkflowBlock` — core's rule, shared with the server —
1756
+ * refuses the entry. It is still SHOWN, greyed, with the reason: an entry
1757
+ * silently dropped from a picker is the failure the old docblock was about.
1758
+ *
1759
+ * The same rule refuses a bare, unversioned announcement, which is what an
1760
+ * un-upgraded worker of any SDK publishes. A name with no version cannot satisfy
1761
+ * the pin, and offering it as though it could would be a lie the node then
1762
+ * carries.
1763
+ *
1764
+ * ## Two searchable fields, not one select over `name@version`
1765
+ *
1766
+ * The first shape of this was a single `SelectField` listing combined
1767
+ * `name@version` keys, with the two text fields left underneath it. Three things
1768
+ * were wrong with that and all three are fixed here.
1769
+ *
1770
+ * - **A popup with no search is unusable at fleet size.** A deployment
1771
+ * announcing three hundred workflows renders three hundred rows, and the only
1772
+ * gesture over them is "scroll until you see it". Both fields are `Combobox`
1773
+ * now: type to narrow, on the name, the group and the description.
1774
+ * - **Name and version are two questions and read as two.** Choosing the
1775
+ * workflow and choosing which of its versions to pin are separate decisions,
1776
+ * and a list of `billing.reconcile@1`, `billing.reconcile@2`,
1777
+ * `billing.reconcile@3` makes the *name* list three times longer to answer a
1778
+ * question about versions. The name field lists names; the version field
1779
+ * lists the versions announced for the name that was chosen.
1780
+ * - **Three controls for two values is one too many.** The select and the text
1781
+ * fields said the same two things twice, and a select that could not express
1782
+ * what somebody typed had to be shown next to a box that could.
1783
+ *
1784
+ * ## Typing something the fleet never announced still works
1785
+ *
1786
+ * That is why these are `Combobox`es and not `Select`s, and it is the property
1787
+ * the whole node depends on. A deployment whose workers have not been upgraded
1788
+ * announces little or nothing, and a picker that became the only path would make
1789
+ * this node unusable there. Base UI's `Autocomplete` has no *selected value* at
1790
+ * all — the input's text is the value and the list is a suggestion over it — so
1791
+ * both fields remain typeable at all times, including when the list is empty,
1792
+ * unavailable, or simply does not contain what somebody is pointing at.
1793
+ *
1794
+ * ## Both halves, or neither
1795
+ *
1796
+ * Splitting one select into two raised the failure the single select could not
1797
+ * have: a name committed on its own, leaving a node that looks configured and
1798
+ * runs whatever is newest on the day it runs. See {@link CallInspector}'s
1799
+ * `chooseName` — choosing a name writes the version in the SAME update whenever
1800
+ * the fleet announces exactly one, which is the common case and stays one
1801
+ * action, and blanks it rather than guessing when it does not. Blank is refused
1802
+ * by `callIsUnnamed`, and the note under the field says so before the save does.
1592
1803
  *
1593
1804
  * ## Why the version is a required field and not a convenience
1594
1805
  *
1595
1806
  * Without it the load would run whichever version is registered on the day it
1596
1807
  * runs, so the person who owns that workflow could change what this pipeline
1597
1808
  * does by deploying theirs. With it, a mismatch stops the load and says so.
1598
- * What it cannot do is *prevent* the wrong version starting: the engine starts
1599
- * the newest registered version and takes no version argument, so the check
1600
- * happens immediately after the start and cancels. The note below says that in
1601
- * the room where somebody is typing the version, rather than only in a
1602
- * docblock they will never open.
1809
+ * What it still cannot do is *prevent* the wrong version starting. `engine.start`
1810
+ * takes a pinned `version` as of durable 0.65.0, but the catalog does not pass
1811
+ * one, and that is a decision rather than an oversight: a pinned start is
1812
+ * refused outright on the two SYNTHESIZED registration paths — a child
1813
+ * inheriting a remote ancestor's routing, and convention routing to a live
1814
+ * worker group — which are exactly how a cross-SDK workflow is reached. Pinning
1815
+ * at the start would therefore break the calls this node exists for. So the
1816
+ * check still happens immediately after the start, and cancels. The note under
1817
+ * the fields says that in the room where somebody is typing the version, rather
1818
+ * than only in a docblock they will never open.
1603
1819
  */
1604
1820
  function CallInspector({ node, canEdit, onChange, }) {
1605
1821
  // Held locally, pushed up when it parses — the same rule `SourceInspector`
@@ -1608,6 +1824,22 @@ function CallInspector({ node, canEdit, onChange, }) {
1608
1824
  // that reformats mid-keystroke is unusable.
1609
1825
  const [text, setText] = useState(() => configText(node.config));
1610
1826
  const [invalid, setInvalid] = useState(false);
1827
+ const client = useCatalogClient();
1828
+ // Asked here rather than by the canvas and threaded down, because this is the
1829
+ // only component that wants it and a call node is a small minority of the
1830
+ // nodes anybody draws — a canvas-level query would ask every deployment for
1831
+ // its fleet on every page load to serve a field most graphs never open.
1832
+ const announced = useQuery({
1833
+ queryKey: catalogQueryKeys.callableWorkflows,
1834
+ queryFn: () => client.listCallableWorkflows(),
1835
+ // Ten seconds, against the descriptor TTL of about thirty-five. Long enough
1836
+ // that opening and closing the sheet does not re-ask, short enough that a
1837
+ // worker which died while somebody was reading is gone before they choose.
1838
+ // Emphatically NOT `Infinity`, which is right for `capabilities` and would
1839
+ // here pin the list to whatever the fleet looked like when the tab opened.
1840
+ staleTime: 10_000,
1841
+ retry: false,
1842
+ });
1611
1843
  const pushConfig = (next) => {
1612
1844
  setText(next);
1613
1845
  const parsed = parseConfigText(next);
@@ -1615,10 +1847,392 @@ function CallInspector({ node, canEdit, onChange, }) {
1615
1847
  if (parsed !== undefined)
1616
1848
  onChange({ ...node, config: parsed });
1617
1849
  };
1618
- return (_jsxs("div", { className: "space-y-3", children: [_jsx(TextField, { label: "Workflow", value: node.callName, onChange: (callName) => onChange({ ...node, callName }), placeholder: "billing.reconcile", disabled: !canEdit, hint: "The name it is registered under in this deployment, exactly. Its body may be in another language \u2014 that is the point of calling it rather than writing it here." }), _jsx(TextField, { label: "Version", value: node.callVersion, onChange: (callVersion) => onChange({ ...node, callVersion }), placeholder: "1", disabled: !canEdit, hint: "Pinned, and part of what this graph is. Registered without a version, a workflow is version 1. Repointing this at another version is an edit to this graph, and shows up as one." }), _jsx(TextAreaField, { label: "Parameters", value: text, onChange: pushConfig, rows: 5, mono: true, placeholder: "{}", disabled: !canEdit, hint: invalid
1850
+ const refs = announced.data?.workflows ?? [];
1851
+ const name = node.callName.trim();
1852
+ const version = node.callVersion.trim();
1853
+ // Every announcement of the name currently in the box — including the blocked
1854
+ // ones, which is the point. What the version field offers is derived from
1855
+ // this, so an entry that cannot be pinned appears there greyed rather than
1856
+ // vanishing between the two fields.
1857
+ const forName = refs.filter((ref) => ref.name === name);
1858
+ const nameOptions = callableNameOptions(refs);
1859
+ const versionOptions = callableVersionOptions(forName);
1860
+ // The one announcement this node is pinned to, when it is pinned to one at
1861
+ // all. A node pointing at something the fleet is not announcing gets no
1862
+ // confirmation line rather than a nearest match — saying "a live worker
1863
+ // announces this" about an entry nobody announced is the lie the whole
1864
+ // component is arranged against.
1865
+ //
1866
+ // A blocked entry can never be it, however exactly the two strings line up:
1867
+ // an `ambiguous-group` entry is not a pin anybody can act on, and an entry
1868
+ // with no version cannot be one at all, however empty the version field
1869
+ // happens to be.
1870
+ const chosen = forName.find((ref) => ref.version !== undefined && ref.version === version && !callableWorkflowBlock(ref));
1871
+ const blocked = refs
1872
+ .map((ref) => ({ ref, block: callableWorkflowBlock(ref) }))
1873
+ .filter((entry) => Boolean(entry.block));
1874
+ // Announced, pinnable and not yet chosen: the state where the name is settled
1875
+ // and the version is a real question. Worth a sentence of its own because it
1876
+ // is the ONLY way this pair of fields can leave a node half-pinned, and the
1877
+ // person who just picked a name is the one who can finish it.
1878
+ const undecided = name.length > 0 && version.length === 0 && versionOptions.length > 0;
1879
+ // Two different silences, and telling somebody the wrong one is worse than
1880
+ // telling them nothing. An empty aggregate is a fact about the DEPLOYMENT and
1881
+ // the server's own sentence explains it; an empty aggregate is not what a
1882
+ // search that matched none of three hundred announcements means, and printing
1883
+ // "no durable engine resolved" over that would be a diagnosis of the wrong
1884
+ // thing entirely.
1885
+ let noNames;
1886
+ if (announced.isPending)
1887
+ noNames = 'Asking the live workers what they can execute…';
1888
+ else if (refs.length > 0)
1889
+ noNames =
1890
+ 'No live worker announces a workflow by that name. Type it anyway if you know it is there — a worker too old to publish its registrations still runs the workflow.';
1891
+ else
1892
+ noNames =
1893
+ announced.data?.detail ??
1894
+ 'Nothing here could be asked what this deployment can execute, so there is no list to choose from. Type the workflow name and the version to pin.';
1895
+ /**
1896
+ * Commit a name, and the version with it whenever the fleet leaves no choice.
1897
+ *
1898
+ * Splitting one `name@version` select into two fields is what makes this
1899
+ * function necessary: a name committed on its own leaves a node that looks
1900
+ * configured and runs whatever is newest on the day it runs, which is the
1901
+ * single failure the pin exists to prevent. So the version moves in the SAME
1902
+ * update, by three rules, in order:
1903
+ *
1904
+ * 1. **The version already held is announced for the new name** — keep it.
1905
+ * Re-picking the same name must not disturb a settled node, and a version
1906
+ * two workflows share is not a coincidence worth punishing.
1907
+ * 2. **The version is blank, or was the old name's** — replace it. Blank is
1908
+ * the fresh node; the old name's version is now stale, and leaving it would
1909
+ * produce a pin nobody announced while looking like one somebody chose. It
1910
+ * becomes the one pinnable version when there is exactly one — the common
1911
+ * case, and it stays one action — and blank otherwise, because a guess
1912
+ * between two versions is the thing the pin exists to stop. Blank is
1913
+ * refused by `callIsUnnamed` and said out loud under the field.
1914
+ * 3. **Anything else** — leave it. A version somebody typed that the fleet
1915
+ * never offered is theirs, and this field has no standing to erase it.
1916
+ *
1917
+ * `callableWorkflowBlock` decides what counts as pinnable throughout, here at
1918
+ * the moment of commit and not only where rows are greyed. A disabled row is a
1919
+ * rendering decision; the rule about what may be written onto the graph is not
1920
+ * one, and a Base UI item that stopped honouring `disabled` must not be able
1921
+ * to get round it.
1922
+ */
1923
+ const chooseName = (option) => {
1924
+ const offered = pinnableVersions(refs, option.value);
1925
+ if (offered.length === 0)
1926
+ return;
1927
+ if (offered.includes(version)) {
1928
+ onChange({ ...node, callName: option.value });
1929
+ return;
1930
+ }
1931
+ const ours = version.length === 0 || pinnableVersions(refs, name).includes(version);
1932
+ const only = offered.length === 1 ? offered[0] : undefined;
1933
+ onChange({ ...node, callName: option.value, callVersion: ours ? (only ?? '') : version });
1934
+ };
1935
+ /**
1936
+ * Commit a version, against the name in the box.
1937
+ *
1938
+ * Looked up as an announcement rather than taken as a string, for the same
1939
+ * reason `chooseName` re-checks: the row carries a claim, and the claim is
1940
+ * what `callableWorkflowBlock` gets to refuse.
1941
+ */
1942
+ const chooseVersion = (option) => {
1943
+ const ref = forName.find((candidate) => candidate.version === option.value);
1944
+ if (!ref || ref.version === undefined || callableWorkflowBlock(ref))
1945
+ return;
1946
+ onChange({ ...node, callName: ref.name, callVersion: ref.version });
1947
+ };
1948
+ return (_jsxs("div", { className: "space-y-3", children: [_jsx(ComboboxField, { label: "Workflow", value: node.callName, onValueChange: (callName) => onChange({ ...node, callName }), onSelect: chooseName, options: nameOptions, placeholder: "billing.reconcile", disabled: !canEdit, emptyMessage: noNames, hint: _jsxs(_Fragment, { children: ["The name it is registered under in this deployment, exactly. Type to search what a live worker says it can execute right now, read at ", readTime(announced.data?.observedAt), " \u2014 a snapshot, not a registry, so a worker that stops beating drops off it within about half a minute and one too old to announce its registrations was never on it. Anything you type is accepted whether or not it is on the list; its body may be in another language, which is the point of calling it rather than writing it here."] }) }), _jsx(ComboboxField, { label: "Version", value: node.callVersion, onValueChange: (callVersion) => onChange({ ...node, callVersion }), onSelect: chooseVersion, options: versionOptions, placeholder: "1", disabled: !canEdit, emptyMessage: name.length === 0
1949
+ ? 'Name a workflow first, and the versions announced for it are listed here.'
1950
+ : `No live worker announces a version of "${name}". Type the one you mean.`, hint: "Pinned, and part of what this graph is. Registered without a version, a workflow is version 1. Repointing this at another version is an edit to this graph, and shows up as one." }), undecided && (_jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["The fleet announces more than one version of \u201C", name, "\u201D, so nothing here picked one for you. Until you do, this node names half of what it needs and the graph will not save."] })), chosen && (_jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["This exact pin is announced right now: ", chosen.name, "@", chosen.version, chosen.group ? `, on group ${chosen.group}` : '', chosen.workers === 1 ? ' — by one worker, so it is a single point of failure.' : '.'] })), blocked.length > 0 && (_jsx("div", { className: cn('space-y-1 text-[11px] leading-relaxed', MUTED), children: blocked.map(({ ref, block }) => (_jsx("p", { children: block.message }, callableKey(ref)))) })), _jsx(TextAreaField, { label: "Parameters", value: text, onChange: pushConfig, rows: 5, mono: true, placeholder: "{}", disabled: !canEdit, hint: invalid
1619
1951
  ? 'That is not valid JSON yet, so it has not been saved onto the node.'
1620
1952
  : 'A JSON object, handed to the workflow as `input`. Beside it, under `catalog`, it also gets this run’s id and the staged rows of whatever feeds this node — handles, never the rows themselves. Not a place for a password: name an env var the callee already reads.' }), _jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "This runs as a child of the load, with its own retries, and the load waits for it. If it fails, this node fails and nothing after it runs. Cancelling the load cancels it; letting the load time out does not, so a workflow you call should carry its own execution timeout." }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["Whether two loads calling it can overlap is decided by how ", _jsx("em", { children: "it" }), " was registered, not by this graph \u2014 and on the path a workflow in another language is reached by, that declaration may not be visible to the engine at all, so assume it can run alongside itself."] })] }));
1621
1953
  }
1954
+ /**
1955
+ * What identifies one announced entry among the others.
1956
+ *
1957
+ * `name@version`, and the bare name when nobody announced a version — the same
1958
+ * key the durable aggregate sorts on, and the reason it can identify a row at
1959
+ * all: the fleet reports one entry per `name@version`, so two entries can never
1960
+ * collide. A key of the name alone would collapse the versions into one, which
1961
+ * is the picker undoing the pin.
1962
+ */
1963
+ function callableKey(ref) {
1964
+ return ref.version === undefined ? ref.name : `${ref.name}@${ref.version}`;
1965
+ }
1966
+ /**
1967
+ * The announced names, one row each, for the workflow field.
1968
+ *
1969
+ * One row per NAME here and one row per version in the field below, which is the
1970
+ * split this pair of fields exists to make. A single list of `name@version` keys
1971
+ * answers the version question inside the name question: a workflow with eight
1972
+ * versions takes eight rows of a list somebody is scanning for a name, and the
1973
+ * name they want is eight times harder to find because of versions they have not
1974
+ * been asked about yet.
1975
+ *
1976
+ * A name is refused only when EVERY announcement under it is refused — one
1977
+ * unpinnable version among four pinnable ones says nothing about the name. The
1978
+ * refusals themselves are per entry and belong to the version field, which shows
1979
+ * them; this line only reports that there is nothing pinnable left.
1980
+ */
1981
+ function callableNameOptions(refs) {
1982
+ const names = [...new Set(refs.map((ref) => ref.name))].sort();
1983
+ return names.map((name) => callableNameOption(name, refs.filter((ref) => ref.name === name)));
1984
+ }
1985
+ /** One name, folded across every announcement of it. */
1986
+ function callableNameOption(name, forName) {
1987
+ const pinnable = forName.filter((ref) => callableWorkflowBlock(ref) === undefined);
1988
+ const groups = [...new Set(forName.flatMap(groupsOf))].sort();
1989
+ const description = forName.find((ref) => ref.description !== undefined)?.description;
1990
+ const workers = forName.reduce((most, ref) => Math.max(most, ref.workers ?? 0), 0);
1991
+ const facts = pinnable.length === 0 ? refusalFacts(forName) : [countOf(pinnable.length, 'version')];
1992
+ // The group is the single most useful fact here — the only signal
1993
+ // distinguishing "this body lives in another process, in another language"
1994
+ // from "this one is local", which is precisely what a missing `workflowBody`
1995
+ // could never tell apart.
1996
+ if (groups.length === 1)
1997
+ facts.push(`group ${groups[0]}`);
1998
+ if (groups.length > 1)
1999
+ facts.push(`groups ${groups.join(', ')}`);
2000
+ if (description)
2001
+ facts.push(description);
2002
+ // One worker is a single point of failure, and a graph built on it should say
2003
+ // so before the day it matters.
2004
+ if (workers > 0)
2005
+ facts.push(countOf(workers, 'worker'));
2006
+ return {
2007
+ value: name,
2008
+ label: name,
2009
+ hint: facts.join(' · '),
2010
+ // Searched but not shown. Somebody hunting the Python half of the fleet
2011
+ // types the group, and somebody who half-remembers what a workflow does
2012
+ // types that — a search over the name alone answers both with "nothing".
2013
+ keywords: [...groups, description ?? ''].join(' '),
2014
+ disabled: pinnable.length === 0,
2015
+ };
2016
+ }
2017
+ /**
2018
+ * Why nothing under a name can be pinned, in the few words a popup row has.
2019
+ *
2020
+ * Short deliberately: this line truncates inside the popup, and the full
2021
+ * sentences `callableWorkflowBlock` writes are printed under the fields, where
2022
+ * nothing truncates them.
2023
+ */
2024
+ function refusalFacts(forName) {
2025
+ const codes = new Set(forName.map((ref) => callableWorkflowBlock(ref)?.code));
2026
+ const facts = [];
2027
+ if (codes.has('no-version'))
2028
+ facts.push('no version announced — cannot be pinned');
2029
+ if (codes.has('ambiguous-group'))
2030
+ facts.push('claimed by two groups — ambiguous');
2031
+ return facts;
2032
+ }
2033
+ /**
2034
+ * The versions announced for one name, one row each.
2035
+ *
2036
+ * Every announcement of that name, including the ones that cannot be chosen. A
2037
+ * bare, unversioned announcement — what an un-upgraded worker of any SDK
2038
+ * publishes — is a row here too, greyed and labelled as having no version: it is
2039
+ * a real thing the fleet said about this name, and the alternative is a picker
2040
+ * that quietly disagrees with the sentence printed underneath it.
2041
+ */
2042
+ function callableVersionOptions(forName) {
2043
+ return forName
2044
+ .map(callableVersionOption)
2045
+ .sort((left, right) => left.label.localeCompare(right.label, undefined, { numeric: true }));
2046
+ }
2047
+ function callableVersionOption(ref) {
2048
+ const block = callableWorkflowBlock(ref);
2049
+ const facts = [];
2050
+ if (block?.code === 'no-version')
2051
+ facts.push('no version announced — cannot be pinned');
2052
+ if (block?.code === 'ambiguous-group')
2053
+ facts.push(`two groups (${groupsOf(ref).join(', ')}) — ambiguous`);
2054
+ if (ref.group)
2055
+ facts.push(`group ${ref.group}`);
2056
+ if (ref.description)
2057
+ facts.push(ref.description);
2058
+ if (ref.workers !== undefined)
2059
+ facts.push(countOf(ref.workers, 'worker'));
2060
+ return {
2061
+ // The fleet folds one entry per `name@version`, so within one name the
2062
+ // versions are distinct and at most one entry is bare — which makes the
2063
+ // empty string a safe identity for that one rather than a collision.
2064
+ value: ref.version ?? '',
2065
+ label: ref.version ?? 'no version announced',
2066
+ hint: facts.join(' · '),
2067
+ keywords: [ref.group ?? '', ref.description ?? ''].join(' '),
2068
+ disabled: block !== undefined,
2069
+ };
2070
+ }
2071
+ /** "1 worker" / "3 workers". A count whose plural is not left to the reader. */
2072
+ function countOf(count, noun) {
2073
+ return count === 1 ? `1 ${noun}` : `${count} ${noun}s`;
2074
+ }
2075
+ /**
2076
+ * The versions of one name that may actually be pinned.
2077
+ *
2078
+ * `callableWorkflowBlock` is the authority, not the presence of a version
2079
+ * string: an `ambiguous-group` entry has a perfectly good version and still may
2080
+ * not be committed.
2081
+ */
2082
+ function pinnableVersions(refs, name) {
2083
+ const versions = [];
2084
+ for (const ref of refs) {
2085
+ if (ref.name !== name || ref.version === undefined)
2086
+ continue;
2087
+ if (callableWorkflowBlock(ref) === undefined)
2088
+ versions.push(ref.version);
2089
+ }
2090
+ return versions;
2091
+ }
2092
+ /**
2093
+ * Every group named in one announcement.
2094
+ *
2095
+ * `group` is set when the announcers agree on exactly one, and left unset when
2096
+ * they disagree — in which case the values are in `disagreements` and both are
2097
+ * worth showing. Silence contributes nothing, because silence is not a claim.
2098
+ */
2099
+ function groupsOf(ref) {
2100
+ if (ref.group !== undefined)
2101
+ return [ref.group];
2102
+ return ref.disagreements?.find((entry) => entry.axis === 'group')?.values ?? [];
2103
+ }
2104
+ /**
2105
+ * When the fleet was asked, as a clock time.
2106
+ *
2107
+ * Printed at all because this list is a snapshot roughly one heartbeat wide, and
2108
+ * a screen that showed it with no time attached would be presenting a moment as
2109
+ * a standing fact. Falls back to the plain string rather than to nothing when
2110
+ * the server sends something unparseable — a server that answered is a server
2111
+ * that answered, and hiding its timestamp because the format surprised us would
2112
+ * remove the one caveat this field is here to carry.
2113
+ */
2114
+ function readTime(observedAt) {
2115
+ if (!observedAt)
2116
+ return 'an unknown time';
2117
+ const at = new Date(observedAt);
2118
+ return Number.isNaN(at.getTime()) ? observedAt : at.toLocaleTimeString();
2119
+ }
2120
+ /**
2121
+ * What this gate decides on, and what the decision costs.
2122
+ *
2123
+ * ## The kind of test comes first, and switching it replaces the test
2124
+ *
2125
+ * A gate tests one thing — a variable where the load runs, or how many rows
2126
+ * reached it — and the model says so with a union rather than with two sets of
2127
+ * optional fields. The form is built the same way round: pick the kind, then
2128
+ * fill in the fields that kind has. Switching the picker hands back a whole new
2129
+ * predicate rather than merging the old one's fields into it, which does discard
2130
+ * a variable name somebody typed — deliberately, because the alternative is a
2131
+ * node quietly carrying the leftovers of a test it is no longer making, and the
2132
+ * next reader cannot tell which of the two it will actually do.
2133
+ *
2134
+ * ## No picker for the variable, for a different reason than the call node's
2135
+ *
2136
+ * A call node has no picker because nothing can enumerate the workflows. This
2137
+ * one has no picker because the list would be *wrong*: the variables that matter
2138
+ * are the ones this deployment has and the other one does not, so a list built
2139
+ * from what the console's own process can see would offer exactly the wrong set
2140
+ * — the ones present everywhere — and quietly omit the one somebody is looking
2141
+ * for. Text, and the graph is refused until it is filled in.
2142
+ *
2143
+ * ## What is said out loud here and nowhere else
2144
+ *
2145
+ * That the value never leaves the machine, because somebody typing
2146
+ * `CLICKHOUSE_URL` into a form is entitled to know whether they have just put a
2147
+ * password on a screen. That the test runs where the *load* runs rather than
2148
+ * here, because a variable set in the console's pod and not in the worker's is
2149
+ * the way this goes wrong. And that the branch is decided once and recorded, so
2150
+ * a resumed run cannot change its mind — which is the sentence that makes the
2151
+ * run panel's "took the then branch" trustworthy.
2152
+ */
2153
+ function IfInspector({ node, canEdit, onChange, }) {
2154
+ const setPredicate = (predicate) => onChange({ ...node, predicate });
2155
+ return (_jsxs("div", { className: "space-y-3", children: [_jsx(SelectField, { label: "Decide on", ariaLabel: "What this gate branches on", value: node.predicate.kind, onValueChange: (kind) => {
2156
+ // Narrowed rather than trusted, because `onValueChange` hands back a
2157
+ // string and the model wants one of two. An unrecognised one is
2158
+ // dropped: a gate is never left holding a test nothing can evaluate.
2159
+ if (!isWorkflowPredicateKind(kind))
2160
+ return;
2161
+ setPredicate(freshPredicate(kind));
2162
+ }, options: [
2163
+ { value: 'env', label: 'An environment variable', hint: 'where the load runs' },
2164
+ {
2165
+ value: 'rowCount',
2166
+ label: 'How many rows reached it',
2167
+ hint: 'off the run’s own record',
2168
+ },
2169
+ ], disabled: !canEdit, hint: "A variable tells one deployment apart from another. A row count tells a load that found data apart from one that found none \u2014 which is how a sink is kept from committing an empty snapshot over what is live." }), _jsx(PredicateFields, { predicate: node.predicate, canEdit: canEdit, onChange: setPredicate }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["The wires out of this node are labelled ", _jsx("strong", { children: "then" }), " and ", _jsx("strong", { children: "else" }), ", under \u201CFeeds\u201D below. To invert the test, swap which one is which \u2014 there is no \u201Cnot\u201D, because two ways to say one thing is two places to look when a load goes the way you did not expect."] }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["Everything reachable only through the branch that is not taken is ", _jsx("em", { children: "skipped" }), ", never failed. A sink on that side commits nothing, so whatever it publishes stays exactly as it was \u2014 that is the point, and the run panel says so rather than leaving a blank."] }), _jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "The branch is decided once, at the moment this node runs, and recorded on the run. A load that is resumed after a crash reads the decision back instead of asking again, so it cannot take one branch on the way in and the other on the way back." })] }));
2170
+ }
2171
+ /**
2172
+ * The test a freshly picked kind starts as.
2173
+ *
2174
+ * An env test starts blank, so the graph refuses to publish until somebody names
2175
+ * a variable — there is nothing to guess. A row-count test starts at 1, which is
2176
+ * not a guess but the *only* threshold that means "did anything arrive at all",
2177
+ * which is the case the predicate was built for; a bigger number is a claim
2178
+ * about a particular pipeline and is typed.
2179
+ */
2180
+ function freshPredicate(kind) {
2181
+ if (kind === 'env')
2182
+ return { kind: 'env', envVar: '' };
2183
+ if (kind === 'rowCount')
2184
+ return { kind: 'rowCount', atLeast: 1 };
2185
+ return unreachablePredicateKind(kind, 'freshPredicate');
2186
+ }
2187
+ /**
2188
+ * The fields one kind of test has, and none of the fields the other has.
2189
+ *
2190
+ * Split per kind and ending in a refusal, so a predicate kind added to the model
2191
+ * without a form here stops the build naming this file — the same rule
2192
+ * `KindInspector` follows for node kinds, and for the same reason: the failure
2193
+ * it prevents is a node somebody can select, that shows nothing to configure,
2194
+ * and that runs anyway.
2195
+ */
2196
+ function PredicateFields({ predicate, canEdit, onChange, }) {
2197
+ if (predicate.kind === 'env') {
2198
+ return _jsx(EnvPredicateFields, { predicate: predicate, canEdit: canEdit, onChange: onChange });
2199
+ }
2200
+ if (predicate.kind === 'rowCount') {
2201
+ return _jsx(RowCountPredicateFields, { predicate: predicate, canEdit: canEdit, onChange: onChange });
2202
+ }
2203
+ return unreachablePredicateKind(predicate, 'PredicateFields');
2204
+ }
2205
+ function EnvPredicateFields({ predicate, canEdit, onChange, }) {
2206
+ // Whether to compare against a value at all is a *mode*, not an empty text
2207
+ // box: `equals: ''` is a real test ("set, but blank") and `equals: undefined`
2208
+ // is a different one ("set to anything"), and a single field could not express
2209
+ // both — clearing the box would silently switch which question is being asked.
2210
+ const comparing = predicate.equals !== undefined;
2211
+ return (_jsxs(_Fragment, { children: [_jsx(TextField, { label: "Environment variable", value: predicate.envVar, onChange: (envVar) => onChange({ ...predicate, envVar }), placeholder: "CLICKHOUSE_URL", disabled: !canEdit, hint: "The name of a variable on the machine that runs the load \u2014 not on this one. Only its name is stored, and only \u201Cset\u201D or \u201Cnot set\u201D is ever written to the run log, so naming one that holds a credential is safe." }), _jsx(SelectField, { label: "Test", ariaLabel: "What this gate tests the variable for", value: comparing ? 'equals' : 'set', onValueChange: (mode) => onChange(mode === 'equals' ? { ...predicate, equals: '' } : { ...predicate, equals: undefined }), options: [
2212
+ { value: 'set', label: 'Is set to anything' },
2213
+ { value: 'equals', label: 'Equals a particular value' },
2214
+ ], disabled: !canEdit, hint: "\u201CIs set\u201D is the deployment test: a deployment that has a ClickHouse has its URL and one that does not has nothing. Compare against a value when the variable exists everywhere and only its contents differ." }), comparing && (_jsx(TextField, { label: "Equals", value: predicate.equals ?? '', onChange: (equals) => onChange({ ...predicate, equals }), placeholder: "local", disabled: !canEdit, hint: "Compared exactly, with no trimming. An empty value here means \u201Cset, but blank\u201D, which is a different test from \u201Cis set to anything\u201D." }))] }));
2215
+ }
2216
+ /**
2217
+ * One threshold, and the sentence that says what it is for.
2218
+ *
2219
+ * A text box with a numeric keypad rather than `type="number"`, which is the
2220
+ * rule `ObjectExplorer` already writes down: that control drops what it cannot
2221
+ * parse and answers a scroll wheel, so a number somebody typed can change while
2222
+ * they are reading the form. Non-digits are stripped here instead, and an empty
2223
+ * box is stored as 0 — which the validator refuses by name, so a half-filled
2224
+ * gate says so on the canvas rather than publishing a test that always passes.
2225
+ */
2226
+ function RowCountPredicateFields({ predicate, canEdit, onChange, }) {
2227
+ const digits = Number.isInteger(predicate.atLeast) && predicate.atLeast > 0;
2228
+ return (_jsxs(_Fragment, { children: [_jsx(TextField, { label: "At least this many rows", value: digits ? String(predicate.atLeast) : '', onChange: (typed) => {
2229
+ const cleaned = typed.replace(/[^0-9]/g, '');
2230
+ onChange({
2231
+ ...predicate,
2232
+ atLeast: cleaned.length === 0 ? 0 : Number.parseInt(cleaned, 10),
2233
+ });
2234
+ }, inputMode: "numeric", placeholder: "1", disabled: !canEdit, hint: "1 is \u201Cdid anything arrive at all\u201D. A larger number is for a load whose export is never legitimately small \u2014 under it, treat the upstream as broken rather than as data." }), _jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "The count is the one on the single wire feeding this node, taken from what that node recorded \u2014 nothing is re-counted, and nothing is read out of the staged rows." })] }));
2235
+ }
1622
2236
  /**
1623
2237
  * The parameter box's two directions, kept together because they are inverses.
1624
2238
  *
@@ -1660,7 +2274,7 @@ function parseConfigText(text) {
1660
2274
  * a kind added without a branch here shows up as a node with a name and nothing
1661
2275
  * to configure, which is visible on the screen rather than silent.
1662
2276
  */
1663
- function KindInspector({ node, transforms, connections, typeOptions, canEdit, discovery, discoverable, onDiscovered, onChange, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
2277
+ function KindInspector({ node, transforms, connections, typeOptions, canEdit, modelHref, discovery, discoverable, onDiscovered, onChange, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
1664
2278
  if (node.kind === 'transform') {
1665
2279
  return (_jsx(TransformInspector, { node: node, transforms: transforms, canEdit: canEdit, creating: creatingTransform, createError: createTransformError, onChange: onChange, onEditCode: onEditCode, onCreate: onCreateTransform }));
1666
2280
  }
@@ -1677,9 +2291,19 @@ function KindInspector({ node, transforms, connections, typeOptions, canEdit, di
1677
2291
  // being pointed at a different node.
1678
2292
  return _jsx(CallInspector, { node: node, canEdit: canEdit, onChange: onChange }, node.id);
1679
2293
  }
1680
- return (_jsx(SinkInspector, { node: node, typeOptions: typeOptions, canEdit: canEdit, onChange: onChange }));
2294
+ if (node.kind === 'if') {
2295
+ return _jsx(IfInspector, { node: node, canEdit: canEdit, onChange: onChange }, node.id);
2296
+ }
2297
+ if (node.kind === 'sink') {
2298
+ return (_jsx(SinkInspector, { node: node, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, onChange: onChange }));
2299
+ }
2300
+ // The chain ends in a refusal rather than a fallthrough, so a kind added to
2301
+ // core without a form here is a type error naming this file — which is the
2302
+ // whole reason the docblock above says a missing branch shows up as "a node
2303
+ // with a name and nothing to configure". It no longer can.
2304
+ return unreachableNodeKind(node, 'KindInspector');
1681
2305
  }
1682
- function NodeInspector({ node, draft, transforms, connections, typeOptions, canEdit, problems, pending, discovery, discoverable, onDiscovered, onClose, onChange, onConnect, onConnectToNew, onDisconnect, onDelete, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
2306
+ function NodeInspector({ node, draft, transforms, connections, typeOptions, canEdit, modelHref, problems, pending, discovery, discoverable, onDiscovered, onClose, onChange, onConnect, onConnectToNew, onDisconnect, onBranch, onDelete, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
1683
2307
  const [pendingTarget, setPendingTarget] = useState('');
1684
2308
  const label = (id) => {
1685
2309
  const found = draft.nodes.find((n) => n.id === id);
@@ -1720,7 +2344,11 @@ function NodeInspector({ node, draft, transforms, connections, typeOptions, canE
1720
2344
  return (_jsx(Sheet, { open: node !== null, onOpenChange: (open) => {
1721
2345
  if (!open)
1722
2346
  onClose();
1723
- }, title: node ? nodeName(node) : '', description: node ? `${node.kind} node` : undefined, children: node && (_jsxs("div", { className: "space-y-4", children: [problems.length > 0 && (_jsx("ul", { className: "space-y-1.5 rounded-md border border-red-200 bg-red-50 p-2 dark:border-red-900 dark:bg-red-950/40", children: problems.map((problem) => (_jsx("li", { className: "text-[11px] leading-relaxed text-red-700 dark:text-red-300", children: problem.message }, problem.code))) })), pending.length > 0 && (_jsxs("div", { className: cn('rounded-md border p-2', RULE), children: [_jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Still to do" }), _jsx("ul", { className: "mt-1 space-y-0.5", children: pending.map((problem) => (_jsx("li", { className: "text-[11px] leading-relaxed", children: todoFor(problem) }, problem.code))) })] })), _jsx(TextField, { label: "Name", value: node.name, onChange: (name) => onChange({ ...node, name }), placeholder: node.kind, disabled: !canEdit, hint: "What it is called on the canvas and in the wiring list. Renaming it does not change what the graph does, so it does not bump the version." }), _jsx(KindInspector, { node: node, transforms: transforms, connections: connections, typeOptions: typeOptions, canEdit: canEdit, discovery: discovery, discoverable: discoverable, onDiscovered: onDiscovered, onChange: onChange, onEditCode: onEditCode, onCreateTransform: onCreateTransform, creatingTransform: creatingTransform, createTransformError: createTransformError }), _jsx(WiringList, { title: "Fed by", edges: incoming, otherEnd: (edge) => label(edge.from), describeRemoval: (name) => `Stop ${name} feeding this node`, canEdit: canEdit, onDisconnect: onDisconnect, children: incoming.length > 1 && (_jsx("p", { className: cn('mt-1 text-[11px] leading-relaxed', MUTED), children: "Inputs arrive in this order, and the order is part of what the graph produces \u2014 a transform joining two feeds sees them exactly like this." })) }), _jsxs(WiringList, { title: "Feeds", edges: outgoing, otherEnd: (edge) => label(edge.to), describeRemoval: (name) => `Stop this node feeding ${name}`, canEdit: canEdit, onDisconnect: onDisconnect, children: [canEdit && (_jsxs("div", { className: "mt-2 flex items-end gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(Select, { ariaLabel: "Send this node's output to", value: pendingTarget, onValueChange: setPendingTarget, options: eligible, placeholder: eligible.length === 0
2347
+ }, title: node ? nodeName(node) : '', description: node ? `${node.kind} node` : undefined, children: node && (_jsxs("div", { className: "space-y-4", children: [problems.length > 0 && (_jsx("ul", { className: "space-y-1.5 rounded-md border border-red-200 bg-red-50 p-2 dark:border-red-900 dark:bg-red-950/40", children: problems.map((problem) => (_jsx("li", { className: "text-[11px] leading-relaxed text-red-700 dark:text-red-300", children: problem.message }, problem.code))) })), pending.length > 0 && (_jsxs("div", { className: cn('rounded-md border p-2', RULE), children: [_jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Still to do" }), _jsx("ul", { className: "mt-1 space-y-0.5", children: pending.map((problem) => (_jsx("li", { className: "text-[11px] leading-relaxed", children: todoFor(problem) }, problem.code))) })] })), _jsx(TextField, { label: "Name", value: node.name, onChange: (name) => onChange({ ...node, name }), placeholder: node.kind, disabled: !canEdit, hint: "What it is called on the canvas and in the wiring list. Renaming it does not change what the graph does, so it does not bump the version." }), _jsx(KindInspector, { node: node, transforms: transforms, connections: connections, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, discovery: discovery, discoverable: discoverable, onDiscovered: onDiscovered, onChange: onChange, onEditCode: onEditCode, onCreateTransform: onCreateTransform, creatingTransform: creatingTransform, createTransformError: createTransformError }), _jsx(WiringList, { title: "Fed by", edges: incoming, otherEnd: (edge) => label(edge.from), describeRemoval: (name) => `Stop ${name} feeding this node`, canEdit: canEdit, onDisconnect: onDisconnect, children: incoming.length > 1 && (_jsx("p", { className: cn('mt-1 text-[11px] leading-relaxed', MUTED), children: "Inputs arrive in this order, and the order is part of what the graph produces \u2014 a transform joining two feeds sees them exactly like this." })) }), _jsxs(WiringList, { title: "Feeds", edges: outgoing, otherEnd: (edge) => label(edge.to), describeRemoval: (name) => `Stop this node feeding ${name}`, canEdit: canEdit, onDisconnect: onDisconnect,
2348
+ // Only a gate's wires have a side to be on. `validateWorkflow`
2349
+ // refuses a label on any other wire, so offering the control there
2350
+ // would be offering a change the server will not take.
2351
+ onBranch: node.kind === 'if' ? onBranch : undefined, children: [canEdit && (_jsxs("div", { className: "mt-2 flex items-end gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(Select, { ariaLabel: "Send this node's output to", value: pendingTarget, onValueChange: setPendingTarget, options: eligible, placeholder: eligible.length === 0
1724
2352
  ? 'Nothing can be wired from here'
1725
2353
  : 'Send its output to…', disabled: eligible.length === 0 }) }), _jsx("button", { type: "button", onClick: () => {
1726
2354
  if (!pendingTarget)
@@ -1781,21 +2409,21 @@ function SourceInspector({ node, connections, canEdit, discovery, discoverable,
1781
2409
  // The connection goes with the kind it belonged to. Keeping it would
1782
2410
  // point an S3 source at a SQL address.
1783
2411
  push(source, { sourceKind, connectionId: undefined });
1784
- }, options: KIND_OPTIONS, disabled: !canEdit }), usesConnection(kind) && (_jsx(SelectField, { label: "Read through", ariaLabel: "Connection", value: chosen, onValueChange: (value) => push(source, {
1785
- // Omitted, never sent empty: an empty string is a connection id
1786
- // the server would look up and fail to find, where absent means
1787
- // "this source carries its own address".
1788
- connectionId: value === INLINE_CONNECTION ? undefined : value,
1789
- }), options: [
1790
- {
1791
- value: INLINE_CONNECTION,
1792
- label: 'Configure the address here',
1793
- hint: 'This source alone',
1794
- },
1795
- ...options,
1796
- ], disabled: !canEdit, hint: options.length === 0
1797
- ? 'No connections of this kind yet. One is worth making when a second source needs the same address.'
1798
- : viaConnection
1799
- ? 'The connection supplies the address and the credential. What stays below is only what is specific to this load.'
1800
- : undefined })), _jsx(SourceFields, { kind: kind, draft: source, onChange: update, viaConnection: viaConnection, disabled: !canEdit }), _jsx(ReadModeFields, { kind: kind, mode: mode, onModeChange: (next) => push(source, { mode: next }), draft: source, onChange: update, disabled: !canEdit }), incremental && (_jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "A watermark is kept per node, so two sources in the same graph reading incrementally do not overwrite each other's position." })), _jsx(SchemaDiscoveryPanel, { workflowId: discoverable.workflowId ?? '', nodeId: node.id, bridge: discovery, onDiscovered: onDiscovered, ...(discoverable.workflowId === undefined ? { disabledReason: discoverable.because } : {}) })] }));
2412
+ }, options: KIND_OPTIONS, disabled: !canEdit }), usesConnection(kind) && (_jsxs(_Fragment, { children: [_jsx(SelectField, { label: "Read through", ariaLabel: "Connection", value: chosen, onValueChange: (value) => push(source, {
2413
+ // Omitted, never sent empty: an empty string is a connection id
2414
+ // the server would look up and fail to find, where absent means
2415
+ // "this source carries its own address".
2416
+ connectionId: value === INLINE_CONNECTION ? undefined : value,
2417
+ }), options: [
2418
+ {
2419
+ value: INLINE_CONNECTION,
2420
+ label: 'Configure the address here',
2421
+ hint: 'This source alone',
2422
+ },
2423
+ ...options,
2424
+ ], disabled: !canEdit, hint: options.length === 0
2425
+ ? 'No connections of this kind yet. One is worth making when a second source needs the same address.'
2426
+ : viaConnection
2427
+ ? 'The connection supplies the address and the credential. What stays below is only what is specific to this load.'
2428
+ : undefined }), _jsx(SourceConnectionCreator, { kind: kind, canEdit: canEdit, hasOptions: options.length > 0, onCreated: (connection) => push(source, { connectionId: connection.id }) })] })), _jsx(SourceFields, { kind: kind, draft: source, onChange: update, viaConnection: viaConnection, disabled: !canEdit }), _jsx(ReadModeFields, { kind: kind, mode: mode, onModeChange: (next) => push(source, { mode: next }), draft: source, onChange: update, disabled: !canEdit }), incremental && (_jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "A watermark is kept per node, so two sources in the same graph reading incrementally do not overwrite each other's position." })), _jsx(SchemaDiscoveryPanel, { workflowId: discoverable.workflowId ?? '', nodeId: node.id, bridge: discovery, onDiscovered: onDiscovered, onSave: discoverable.onSave, saving: discoverable.saving, ...(discoverable.workflowId === undefined ? { disabledReason: discoverable.because } : {}) })] }));
1801
2429
  }