@dudousxd/nestjs-catalog-react 0.17.0 → 0.18.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.
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Background, BackgroundVariant, ConnectionLineType, Controls, MiniMap, NodeToolbar, Position, ReactFlow, ReactFlowProvider, useReactFlow, } from '@xyflow/react';
3
3
  // React Flow ships its own stylesheet and renders as an unstyled pile of divs
4
4
  // without it — no edges, every node at the top-left corner. Imported by the
@@ -7,21 +7,26 @@ 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, LayoutGrid, Link2, Loader2, Play, Plug, Plus, Repeat, Save, Trash2, TriangleAlert, Unplug, } from 'lucide-react';
10
+ import { ArrowRight, CircleAlert, CircleDashed, Code2, Database, ExternalLink, LayoutGrid, Link2, Loader2, Plug, Plus, Repeat, Save, Trash2, TriangleAlert, Unplug, } from 'lucide-react';
11
11
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
12
+ import { connectionOptionsFor } from './ConnectionPanel';
12
13
  import { TransformEditor } from './TransformEditor';
13
14
  import { cn } from './cn';
14
15
  import { catalogQueryKeys, useCatalogClient } from './context';
15
- import { INLINE_CONNECTION, KIND_OPTIONS, ReadModeFields, SourceFields, connectionOptions, readsIncrementally, sourceConfigFrom, sourceDraftFrom, toConnectorKind, usesConnection, } from './source-fields';
16
+ import { SchemaDiscoveryPanel, narrowDiscovery, } from './schema-discovery';
17
+ import { INLINE_CONNECTION, KIND_OPTIONS, ReadModeFields, SourceFields, readsIncrementally, sourceConfigFrom, sourceDraftFrom, toConnectorKind, usesConnection, } from './source-fields';
18
+ import { Button } from './ui/button';
16
19
  import { ConfirmDialog } from './ui/dialog';
17
- import { TextField } from './ui/field';
20
+ import { TextAreaField, TextField } from './ui/field';
18
21
  import { Select, SelectField } from './ui/select';
19
22
  import { Sheet } from './ui/sheet';
20
23
  import { Tooltip, TooltipProvider } from './ui/tooltip';
21
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';
22
26
  import { WORKFLOW_NODE_KINDS, describeDurability, isWorkflowNodeKind, newLocalId, nodeName, producedTypes, } from './workflow/model';
23
27
  import { WORKFLOW_NAME } from './workflow/name';
24
28
  import { WorkflowNodeProvider, workflowNodeTypes } from './workflow/nodes';
29
+ import { RunsAsPanel } from './workflow/runs';
25
30
  import { canConnect, edgeId, hasBlockingProblem, problemsByNode, validateWorkflow, } from './workflow/validate';
26
31
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
27
32
  const RULE = 'border-zinc-200 dark:border-zinc-800';
@@ -132,6 +137,14 @@ function newNodeOfKind(kind, id, position, name) {
132
137
  if (kind === 'transform') {
133
138
  return { id, name, kind: 'transform', transformId: '', position };
134
139
  }
140
+ if (kind === 'call') {
141
+ // Both empty, and the graph is invalid until they are not — deliberately.
142
+ // There is no list of workflows to default from (see `CallableWorkflowRef`
143
+ // in core), and defaulting a *version* to "1" would be the one guess that
144
+ // matters: it would silently pin whichever code happens to be registered as
145
+ // version 1 in whatever deployment this graph is promoted into.
146
+ return { id, name, kind: 'call', callName: '', callVersion: '', config: {}, position };
147
+ }
135
148
  return { id, name, kind: 'sink', targetType: '', position };
136
149
  }
137
150
  /**
@@ -365,6 +378,7 @@ const TODO_FOR = {
365
378
  'dead-end': 'wire it into something that ends at a sink',
366
379
  'sink-has-no-type': 'choose the object type it commits',
367
380
  'transform-not-named': 'choose the transform it runs',
381
+ 'call-not-named': 'name the workflow it calls, and the version to pin',
368
382
  'missing-transform': 'choose a transform that still exists',
369
383
  'source-has-input': 'unwire whatever feeds it — a source reads, it is not fed',
370
384
  'sink-has-output': 'unwire what it feeds — nothing runs after a sink',
@@ -445,19 +459,17 @@ function saveHint(blocked, unfinished) {
445
459
  * list beside the canvas is empty and the real answer is "two boxes are not
446
460
  * finished", so that case gets its own sentence and names them.
447
461
  */
448
- function CanvasActions({ draft, canEdit, blocked, unfinished, saving, running, durabilityDetail, onSave, onRun, onAskDelete, }) {
462
+ function CanvasActions({ draft, stored, canEdit, blocked, unfinished, saving, running, durabilityDetail, acknowledging, onAcknowledgingChange, onSave, onRun, onLifecycleChange, onAskDelete, }) {
449
463
  return (_jsxs("div", { className: "flex flex-wrap items-start gap-2 self-end pb-1", children: [_jsx(Tooltip, { content: saveHint(blocked, unfinished), children: _jsxs("button", { type: "button", onClick: onSave, disabled: !canEdit ||
450
464
  saving ||
451
465
  draft.name.trim().length === 0 ||
452
466
  (!draft.dirty && Boolean(draft.id)), className: cn('flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs disabled:opacity-40', blocked
453
467
  ? 'bg-amber-600 text-white'
454
- : 'bg-zinc-950 text-zinc-50 dark:bg-zinc-100 dark:text-zinc-950'), children: [saving ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Save, { size: 12 }), draft.dirty ? 'Save' : 'Saved'] }) }), _jsx(Tooltip, { content: draft.dirty
455
- ? 'Save first — a run executes the stored graph, not what is on screen.'
456
- : durabilityDetail, children: _jsxs("button", { type: "button", onClick: onRun, disabled: !canEdit || !draft.id || draft.dirty || running, className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs disabled:opacity-40', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [running ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Play, { size: 12 }), "Run"] }) }), draft.id && canEdit && (_jsx(Tooltip, { content: `Delete this ${WORKFLOW_NAME.singular}.`, children: _jsx("button", { type: "button", onClick: onAskDelete, "aria-label": `Delete this ${WORKFLOW_NAME.singular}`, className: cn('rounded-md border p-1.5 text-zinc-400 hover:text-red-600', RULE), children: _jsx(Trash2, { size: 12 }) }) }))] }));
468
+ : 'bg-zinc-950 text-zinc-50 dark:bg-zinc-100 dark:text-zinc-950'), children: [saving ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Save, { size: 12 }), draft.dirty ? 'Save' : 'Saved'] }) }), stored && (_jsx(PublishControls, { workflow: stored, dirty: draft.dirty, canEdit: canEdit, onPublished: onLifecycleChange })), _jsx(RunControls, { workflowId: draft.id, dirty: draft.dirty, canEdit: canEdit, running: running, durabilityDetail: durabilityDetail, acknowledging: acknowledging, onAcknowledgingChange: onAcknowledgingChange, onRun: onRun }), draft.id && canEdit && (_jsx(Tooltip, { content: `Delete this ${WORKFLOW_NAME.singular}, and the connector it runs as with it.`, children: _jsx(Button, { variant: "outline", size: "icon", onClick: onAskDelete, "aria-label": `Delete this ${WORKFLOW_NAME.singular}`, className: "text-zinc-400 hover:text-red-600", children: _jsx(Trash2, { size: 12 }) }) }))] }));
457
469
  }
458
- /** The three things that can be put on the canvas, and the button that tidies them. */
470
+ /** The four things that can be put on the canvas, and the button that tidies them. */
459
471
  function AddNodeBar({ refreshing, onAdd, onTidy, }) {
460
- 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(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 && (
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 && (
461
473
  // A background refetch says so without replacing anything: the graph on
462
474
  // screen stays exactly where it is.
463
475
  _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: "refreshing\u2026" }))] }));
@@ -494,6 +506,10 @@ function miniMapColor(data) {
494
506
  return '#0ea5e9';
495
507
  if (kind === 'sink')
496
508
  return '#10b981';
509
+ // The same amber the node itself draws (see `KIND_STYLE`), so the overview
510
+ // and the canvas agree about which boxes are somebody else's workflow.
511
+ if (kind === 'call')
512
+ return '#f59e0b';
497
513
  return '#8b5cf6';
498
514
  }
499
515
  /**
@@ -672,6 +688,97 @@ function nodeMovesAndRemovals(changes) {
672
688
  }
673
689
  return { positions, removed };
674
690
  }
691
+ /**
692
+ * The transforms a graph actually names.
693
+ *
694
+ * Only these, because the run history's `code v3` can be turned into a
695
+ * comparison only when there is exactly one candidate: a run records ONE
696
+ * transform version, a graph may run three in a row, and picking whichever the
697
+ * screen loaded first would offer a diff against the wrong code.
698
+ */
699
+ function transformsNamedBy(nodes, transforms) {
700
+ const named = new Set(nodes.flatMap((node) => node.kind === 'transform' && node.transformId ? [node.transformId] : []));
701
+ return transforms.filter((transform) => named.has(transform.id));
702
+ }
703
+ /**
704
+ * What a run did, said out loud once.
705
+ *
706
+ * Not "succeeded or failed": a graph may commit several types at several sinks,
707
+ * each independently, so the overall status is only the headline and the reader
708
+ * is sent to the per-sink list for what actually landed.
709
+ */
710
+ function runAnnouncement(result) {
711
+ if (result.status === 'succeeded') {
712
+ return 'The run finished. Check each sink below for what it committed.';
713
+ }
714
+ return `The run ${result.status}. ${result.error ?? ''}`;
715
+ }
716
+ /** What a publish or an unpublish changed, for somebody who cannot see the badge. */
717
+ function lifecycleAnnouncement(saved) {
718
+ return saved.status === 'ready'
719
+ ? 'Published. It is now ready, and runs as a connector of its own.'
720
+ : 'Back to draft. Nothing runs it until it is published again.';
721
+ }
722
+ /**
723
+ * The stored graph behind a draft, when the draft has been stored at all.
724
+ *
725
+ * A lookup rather than state of its own, so that publishing — which changes the
726
+ * status and mints the connector everything else is keyed on — reaches the
727
+ * badge, the schedule panel and the "Runs as" panel through one path instead of
728
+ * three copies going out of step.
729
+ */
730
+ function storedWorkflow(list, id) {
731
+ if (!id)
732
+ return undefined;
733
+ return list?.find((workflow) => workflow.id === id);
734
+ }
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
+ function discoveryTarget(draft) {
747
+ if (!draft.id) {
748
+ return {
749
+ because: `Save this ${WORKFLOW_NAME.singular} first — discovery reads the stored node, and there is nothing stored yet. It does not need to be published.`,
750
+ };
751
+ }
752
+ if (draft.dirty) {
753
+ return {
754
+ because: 'Save first — discovery reads the stored node, so it would describe the source as it was before these edits.',
755
+ };
756
+ }
757
+ return { workflowId: draft.id };
758
+ }
759
+ /**
760
+ * Whether an edit changed where this node reads from, or only what it is
761
+ * called.
762
+ *
763
+ * The question a discovered shape's shelf life turns on. Everything compared
764
+ * here is part of the address the server would dial — the kind of system, the
765
+ * connection it borrows, whether it reads the lot or from a watermark, and the
766
+ * config that holds the URL or the statement. A name, a position and a
767
+ * selection are none of those, and dropping the columns for one of them would
768
+ * make the check disappear for the most ordinary edit there is.
769
+ *
770
+ * `config` is compared as JSON because it is an open record — both sides are
771
+ * built by `sourceConfigFrom`, so the key order is stable, and the failure mode
772
+ * of a false difference is silence rather than a wrong answer.
773
+ */
774
+ function readsDifferently(before, after) {
775
+ if (before?.kind !== 'source' || after.kind !== 'source')
776
+ return false;
777
+ return (before.sourceKind !== after.sourceKind ||
778
+ before.connectionId !== after.connectionId ||
779
+ before.mode !== after.mode ||
780
+ JSON.stringify(before.config ?? {}) !== JSON.stringify(after.config ?? {}));
781
+ }
675
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, }) {
676
783
  const client = useCatalogClient();
677
784
  const queryClient = useQueryClient();
@@ -711,6 +818,15 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
711
818
  const [editingCodeFor, setEditingCodeFor] = useState(null);
712
819
  const [confirmingDelete, setConfirmingDelete] = useState(false);
713
820
  const [run, setRun] = useState(null);
821
+ /**
822
+ * Whether the "this load is expected to shrink" dialog is open.
823
+ *
824
+ * Here rather than inside `RunControls` because there are two ways in and only
825
+ * one of them is a button in that row: the other is the refusal note under the
826
+ * canvas, which is where somebody who has just watched a load be turned away is
827
+ * actually looking.
828
+ */
829
+ const [acknowledging, setAcknowledging] = useState(false);
714
830
  /**
715
831
  * Nodes added in this session that nobody has done anything to yet.
716
832
  *
@@ -720,6 +836,22 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
720
836
  * somebody finished with.
721
837
  */
722
838
  const [unstarted, setUnstarted] = useState(() => new Set());
839
+ /**
840
+ * What discovery said each source node reads, for the source nodes somebody
841
+ * has actually asked about in this session.
842
+ *
843
+ * Component state for the same reason `unstarted` is, and kept HERE rather
844
+ * than inside `SchemaDiscoveryPanel` because that panel is unmounted with the
845
+ * inspector: the columns somebody just read would be gone by the time they
846
+ * looked at the Problems rail, which is where the comparison in
847
+ * `workflow/shape.ts` is drawn. The panel tells this through `onDiscovered`.
848
+ *
849
+ * Empty is the state every graph starts in, and it means "nobody asked" — not
850
+ * "nothing to report". That distinction is the whole basis of the column
851
+ * checks, and it survives here because the map is only ever written by a
852
+ * discovery somebody ran.
853
+ */
854
+ const [shapesByNode, setShapesByNode] = useState(() => new Map());
723
855
  /**
724
856
  * The last thing the canvas refused, and the last thing it did.
725
857
  *
@@ -755,6 +887,10 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
755
887
  // Everything in a freshly loaded draft came off the server, so nothing in it
756
888
  // is "not finished yet" — see `partitionProblems`.
757
889
  setUnstarted(new Set());
890
+ // A discovered shape belongs to the node it was read for, and node ids do
891
+ // not cross graphs. Keeping the map would be this screen holding one graph's
892
+ // columns while drawing another's — silence is the right state on arrival.
893
+ setShapesByNode(new Map());
758
894
  menu.reset();
759
895
  }, [workflows.data, selected, menu.reset]);
760
896
  // Fit after the graph swaps, on the frame after the new nodes have been laid
@@ -773,7 +909,32 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
773
909
  setDraft((current) => ({ ...change(current), dirty: true }));
774
910
  }, []);
775
911
  const transformIds = useMemo(() => new Set(transforms.map((transform) => transform.id)), [transforms]);
776
- const problems = useMemo(() => validateWorkflow({ nodes: draft.nodes, edges: draft.edges }, { transformIds }), [draft.nodes, draft.edges, transformIds]);
912
+ /**
913
+ * The two halves of the column check, or nothing at all.
914
+ *
915
+ * `undefined` until a discovery has actually been run on this graph, and that
916
+ * is the load-bearing part rather than an optimisation: an implementation
917
+ * whose `sourceShape` always answered `undefined` would look like an answer
918
+ * and report the same silence, and `shape.ts` is written on the assumption
919
+ * that being handed a {@link ShapeKnowledge} means somebody can answer with
920
+ * it. An empty map is "nobody asked", and it says so by being absent.
921
+ *
922
+ * The types come from the snapshot this screen already holds, so the catalog
923
+ * half costs no request. A snapshot that has not arrived yet answers nothing,
924
+ * which reads as "this console cannot see that type" for the one render
925
+ * before it does — a warning, never an error, which is exactly the outcome a
926
+ * momentarily-unknown type deserves.
927
+ */
928
+ const shapes = useMemo(() => {
929
+ if (shapesByNode.size === 0)
930
+ return undefined;
931
+ const types = new Map((snapshot?.types ?? []).map((type) => [type.name, type]));
932
+ return {
933
+ sourceShape: (nodeId) => shapesByNode.get(nodeId),
934
+ targetShape: (typeName) => types.get(typeName),
935
+ };
936
+ }, [shapesByNode, snapshot]);
937
+ const problems = useMemo(() => validateWorkflow({ nodes: draft.nodes, edges: draft.edges }, { transformIds, shapes }), [draft.nodes, draft.edges, transformIds, shapes]);
777
938
  /**
778
939
  * The same checks, split by whether the node they name is finished.
779
940
  *
@@ -862,6 +1023,30 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
862
1023
  const markStarted = useCallback((...ids) => {
863
1024
  setUnstarted((current) => without(current, ids));
864
1025
  }, []);
1026
+ /**
1027
+ * A discovery landed, so the column check has something to say about this
1028
+ * node.
1029
+ *
1030
+ * The response is stored as-is: `ConnectorSchemaDiscovery` already IS a
1031
+ * {@link SourceShape} — same `columns`, same `basis`, same `sampled` — and
1032
+ * that is not a coincidence worth papering over with a conversion. The two
1033
+ * were written against the same route. A mapping function here would be a
1034
+ * place for the two to quietly drift, and would have to invent an answer for
1035
+ * every field it did not copy.
1036
+ */
1037
+ const rememberShape = useCallback((nodeId, shape) => {
1038
+ setShapesByNode((current) => new Map(current).set(nodeId, shape));
1039
+ }, []);
1040
+ /** The columns on file stop describing this node. See the caller. */
1041
+ const forgetShape = useCallback((nodeId) => {
1042
+ setShapesByNode((current) => {
1043
+ if (!current.has(nodeId))
1044
+ return current;
1045
+ const next = new Map(current);
1046
+ next.delete(nodeId);
1047
+ return next;
1048
+ });
1049
+ }, []);
865
1050
  const disconnect = useCallback((edge) => {
866
1051
  const id = edgeId(edge);
867
1052
  edit((current) => ({
@@ -941,7 +1126,12 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
941
1126
  },
942
1127
  });
943
1128
  const runIt = useMutation({
944
- mutationFn: (id) => client.runWorkflow(id),
1129
+ // The options are the run's, not the graph's, and `expectShrink` is the one
1130
+ // that matters: it is the acknowledgement that lets a deliberately
1131
+ // collapsing load past the row-count bound, it reaches the server only
1132
+ // through this route, and it is stored nowhere — which is the only reliable
1133
+ // way to keep a one-time acknowledgement from becoming a standing one.
1134
+ mutationFn: ({ id, options }) => client.runWorkflow(id, options),
945
1135
  onSuccess: (result) => {
946
1136
  setRun(result);
947
1137
  // A run writes rows, so the catalog snapshot every other screen reads is
@@ -949,11 +1139,20 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
949
1139
  // showing yesterday's counts beside a run that just finished.
950
1140
  queryClient.invalidateQueries({ queryKey: catalogQueryKeys.snapshot });
951
1141
  queryClient.invalidateQueries({ queryKey: catalogQueryKeys.workflows });
952
- setAnnouncement(result.status === 'succeeded'
953
- ? 'The run finished. Check each sink below for what it committed.'
954
- : `The run ${result.status}. ${result.error ?? ''}`);
1142
+ // The run is recorded against the connector, which is where the history
1143
+ // and the last-run fields live. Left stale, the "Runs as" panel shows a
1144
+ // pipeline that has never run beside a run that just finished.
1145
+ queryClient.invalidateQueries({ queryKey: catalogQueryKeys.runs() });
1146
+ queryClient.invalidateQueries({ queryKey: catalogQueryKeys.connectors });
1147
+ setAnnouncement(runAnnouncement(result));
955
1148
  },
956
1149
  });
1150
+ // `id` is narrowed by the controls, which are disabled without one — the empty
1151
+ // string here is unreachable and is what keeps this a plain call rather than a
1152
+ // second guard the button already applies.
1153
+ const runNow = useCallback((options) => {
1154
+ runIt.mutate({ id: draft.id ?? '', options });
1155
+ }, [draft.id, runIt.mutate]);
957
1156
  /**
958
1157
  * Write the first transform without leaving the canvas.
959
1158
  *
@@ -1090,11 +1289,37 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1090
1289
  setUnstarted(new Set());
1091
1290
  save.mutate();
1092
1291
  }, [save]);
1292
+ /**
1293
+ * The stored graph behind the draft on screen, when there is one.
1294
+ *
1295
+ * Read out of the list rather than held in state of its own, so that
1296
+ * publishing — which changes `status`, and mints the connector everything
1297
+ * else here is keyed on — reaches the badge, the schedule panel and the
1298
+ * "Runs as" panel through one path instead of three copies going out of step.
1299
+ *
1300
+ * `loadedRef` is what makes this safe: the load effect returns early once the
1301
+ * draft has been built for an id, so a fresher list arriving here cannot throw
1302
+ * away nodes somebody has moved since.
1303
+ */
1304
+ const stored = useMemo(() => storedWorkflow(workflows.data, draft.id), [workflows.data, draft.id]);
1305
+ /**
1306
+ * A publish, an unpublish or a schedule, written straight into the list.
1307
+ *
1308
+ * Written as well as invalidated, because the status badge is the whole
1309
+ * feedback for those actions: waiting for a refetch means pressing Publish
1310
+ * and watching nothing happen for as long as the round trip takes, which is
1311
+ * exactly how somebody presses it twice.
1312
+ */
1313
+ const onLifecycleChange = useCallback((saved) => {
1314
+ queryClient.setQueryData(catalogQueryKeys.workflows, (current) => (current ?? []).map((workflow) => (workflow.id === saved.id ? saved : workflow)));
1315
+ setAnnouncement(lifecycleAnnouncement(saved));
1316
+ }, [queryClient]);
1093
1317
  const inspectingNode = draft.nodes.find((node) => node.id === inspecting) ?? null;
1094
1318
  const editingNode = draft.nodes.find((node) => node.id === editingCodeFor);
1095
1319
  const editingTransform = editingNode?.kind === 'transform'
1096
1320
  ? transforms.find((transform) => transform.id === editingNode.transformId)
1097
1321
  : undefined;
1322
+ const graphTransforms = useMemo(() => transformsNamedBy(draft.nodes, transforms), [draft.nodes, transforms]);
1098
1323
  const typeOptions = useMemo(() => (snapshot?.types ?? []).map((type) => ({
1099
1324
  value: type.name,
1100
1325
  label: type.displayName,
@@ -1109,6 +1334,34 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1109
1334
  { value: NEW_WORKFLOW, label: `New ${WORKFLOW_NAME.singular}` },
1110
1335
  ], [workflows.data]);
1111
1336
  const produces = producedTypes(draft.nodes);
1337
+ /**
1338
+ * Asking a source what its columns are, and creating the type from the answer.
1339
+ *
1340
+ * Built from the client rather than taken as a prop, and the prop that used to
1341
+ * carry it is gone with the screen it lived on. Two calls, and the second is
1342
+ * the only write: discovery reads and reports, `PUT /publish/:type/schema`
1343
+ * creates. A pipeline that created the type it loads into would grow the
1344
+ * catalog by accident, and the names it invented would come from the shape of
1345
+ * a query rather than from somebody who meant them.
1346
+ */
1347
+ const discovery = useMemo(() => ({
1348
+ discover: async (workflowId, nodeId) => narrowDiscovery(await client.discoverSourceSchema(workflowId, nodeId)),
1349
+ // `async` on purpose: `publishType` THROWS rather than rejecting when the
1350
+ // transport cannot PUT, and a bridge whose method throws synchronously
1351
+ // would escape the panel's error handling and take the screen with it.
1352
+ createType: async (draftType) => client.publishType(draftType.name, {
1353
+ // Only what a person confirmed on screen. Everything else about a type
1354
+ // — its label, its description, its units — is curation, and inventing
1355
+ // any of it here would put words nobody chose into a catalog whose
1356
+ // whole claim is that its names were chosen.
1357
+ properties: draftType.properties.map((property) => ({
1358
+ name: property.name,
1359
+ columnName: property.columnName,
1360
+ type: property.type,
1361
+ nullable: property.nullable,
1362
+ })),
1363
+ }),
1364
+ }), [client]);
1112
1365
  return (
1113
1366
  /*
1114
1367
  * The screen lives inside the viewport: a header sized to its content and a
@@ -1122,13 +1375,28 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1122
1375
  * not save that: it fits the graph into a box, and half the box was off
1123
1376
  * screen. See `QueryConsole` for the same pattern.
1124
1377
  */
1125
- _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 }), _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 }), _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) => {
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) => {
1126
1379
  loadedRef.current = null;
1127
1380
  setSelected(value);
1128
- }, 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, canEdit: canEdit, blocked: blocked, unfinished: unfinished, saving: save.isPending, running: runIt.isPending, durabilityDetail: durability.detail, onSave: saveNow, onRun: () => draft.id && runIt.mutate(draft.id), 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 })] }), 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 })] }), _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), onClose: () => setInspecting(null), onChange: (next) => {
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) => {
1129
1382
  // Editing any field is the clearest statement there is that somebody
1130
1383
  // is working on this node rather than looking at one they just made.
1131
1384
  markStarted(next.id);
1385
+ // A discovered shape describes the source as it was addressed when it
1386
+ // was read. Change where or what this node reads and the columns on
1387
+ // file stop being about this node, so they are dropped rather than
1388
+ // compared — reporting a missing column against a query somebody has
1389
+ // since rewritten would be the validator inventing a fact, which is
1390
+ // the one thing `shape.ts` refuses to do. Renaming the node keeps
1391
+ // them: a name is not an address.
1392
+ //
1393
+ // Asked out here, against the rendered draft, rather than inside the
1394
+ // updater below: an updater is called again on every re-render React
1395
+ // decides to replay, and a `setState` in one is a side effect that
1396
+ // would fire with it.
1397
+ if (readsDifferently(draft.nodes.find((node) => node.id === next.id), next)) {
1398
+ forgetShape(next.id);
1399
+ }
1132
1400
  edit((current) => ({
1133
1401
  ...current,
1134
1402
  nodes: current.nodes.map((node) => (node.id === next.id ? next : node)),
@@ -1149,7 +1417,7 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
1149
1417
  queryClient.invalidateQueries({
1150
1418
  queryKey: catalogQueryKeys.transforms,
1151
1419
  });
1152
- } })) : (_jsx("p", { className: cn('py-8 text-center text-xs', MUTED), children: "This node does not name a transform yet. Choose one in the inspector first \u2014 there is no code to open until it does." })) }), _jsx(ConfirmDialog, { open: confirmingDelete, onOpenChange: setConfirmingDelete, title: `Delete "${draft.name || WORKFLOW_NAME.singular}"?`, description: `The graph goes with it. The transforms and connections it wired together are not touched — they are shared, and other ${WORKFLOW_NAME.plural} may use them.`, confirmLabel: "Delete", pending: remove.isPending, error: remove.error instanceof Error ? remove.error.message : undefined, onConfirm: () => draft.id && remove.mutate(draft.id) })] }));
1420
+ } })) : (_jsx("p", { className: cn('py-8 text-center text-xs', MUTED), children: "This node does not name a transform yet. Choose one in the inspector first \u2014 there is no code to open until it does." })) }), _jsx(ConfirmDialog, { open: confirmingDelete, onOpenChange: setConfirmingDelete, title: `Delete "${draft.name || WORKFLOW_NAME.singular}"?`, description: `The connector it runs as goes with it, and the run history keyed on that connector goes too — including the incremental watermark, so anything rebuilt later reads its source from the beginning. The snapshots it already committed stay where they are. The transforms and connections it wired together are not touched: they are shared, and other ${WORKFLOW_NAME.plural} may use them.`, confirmLabel: "Delete", pending: remove.isPending, error: remove.error instanceof Error ? remove.error.message : undefined, onConfirm: () => draft.id && remove.mutate(draft.id) })] }));
1153
1421
  }
1154
1422
  function AddButton({ icon: Icon, label, hint, onClick, }) {
1155
1423
  return (_jsx(Tooltip, { content: hint, children: _jsxs("button", { type: "button", onClick: onClick, "aria-label": `Add a ${label.toLowerCase()} node`, className: cn('flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(Plus, { size: 11 }), _jsx(Icon, { size: 12 }), label] }) }));
@@ -1197,7 +1465,7 @@ function CanvasFailure({ error, onRetry, }) {
1197
1465
  * The problems list sits in the same rail for the same reason: a red ring
1198
1466
  * around a node off the left edge of the viewport communicates nothing.
1199
1467
  */
1200
- function WiringRail({ draft, problems, pending, run, canEdit, onInspect, onDisconnect, }) {
1468
+ function WiringRail({ draft, problems, pending, run, canEdit, onInspect, onDisconnect, children, }) {
1201
1469
  const label = (id) => {
1202
1470
  const node = draft.nodes.find((n) => n.id === id);
1203
1471
  return node ? nodeName(node) : id;
@@ -1205,7 +1473,7 @@ function WiringRail({ draft, problems, pending, run, canEdit, onInspect, onDisco
1205
1473
  const errors = problems.filter((problem) => problem.level === 'error');
1206
1474
  const warnings = problems.filter((problem) => problem.level === 'warning');
1207
1475
  const sinks = draft.nodes.filter((node) => node.kind === 'sink');
1208
- return (_jsxs("aside", { className: "flex w-full shrink-0 flex-col gap-3 lg:w-72 lg:min-h-0 lg:overflow-y-auto", "aria-label": `${WORKFLOW_NAME.title} wiring and problems`, children: [_jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Wiring" }), draft.edges.length === 0 ? (_jsx("p", { className: cn('mt-2 text-[11px]', MUTED), children: "Nothing is wired together yet." })) : (_jsx("ul", { className: "mt-2 space-y-1", children: draft.edges.map((edge) => (_jsxs("li", { className: "flex items-center gap-1.5 text-[11px]", children: [_jsx("button", { type: "button", onClick: () => onInspect(edge.from), className: "truncate hover:underline", children: label(edge.from) }), _jsx(ArrowRight, { size: 10, className: cn('shrink-0', MUTED) }), _jsx("button", { type: "button", onClick: () => onInspect(edge.to), className: "truncate hover:underline", children: label(edge.to) }), canEdit && (_jsx(Tooltip, { content: "Remove this connection.", children: _jsx("button", { type: "button", onClick: () => onDisconnect(edge), "aria-label": `Disconnect ${label(edge.from)} from ${label(edge.to)}`, className: "ml-auto shrink-0 rounded p-0.5 text-zinc-400 hover:text-red-600", children: _jsx(Unplug, { size: 11 }) }) }))] }, edgeId(edge)))) }))] }), _jsx(PendingWork, { pending: pending, label: label, onInspect: onInspect }), _jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Problems" }), problems.length === 0 ? (_jsx("p", { className: cn('mt-2 text-[11px]', MUTED), children: "Nothing to flag here. The server checks it again on save." })) : (_jsx("ul", { className: "mt-2 space-y-2", children: [...errors, ...warnings].map((problem) => (_jsxs("li", { className: "flex gap-1.5 text-[11px] leading-relaxed", children: [problem.level === 'error' ? (_jsx(CircleAlert, { size: 11, className: "mt-0.5 shrink-0 text-red-500" })) : (_jsx(TriangleAlert, { size: 11, className: "mt-0.5 shrink-0 text-amber-500" })), _jsxs("span", { children: [problem.message, problem.nodeIds.length > 0 && (_jsx("span", { className: "ml-1", children: problem.nodeIds.map((nodeId) => (_jsx("button", { type: "button", onClick: () => onInspect(nodeId), className: cn('mr-1 rounded border px-1 font-mono text-[9px]', RULE, MUTED), children: label(nodeId) }, nodeId))) }))] })] }, `${problem.code}:${problem.nodeIds.join(',')}`))) }))] }), run && (_jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Last run" }), _jsxs("p", { className: "mt-1 text-[11px]", children: [run.status, _jsx("span", { className: cn('ml-1 font-mono text-[10px]', MUTED), children: run.durable ? 'checkpointed per node' : 'ran inline, no checkpoints' })] }), sinks.length > 0 && (_jsxs("div", { className: "mt-2", children: [_jsx("h3", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Committed" }), _jsx("ul", { className: "mt-1 space-y-1", children: sinks.map((sink) => {
1476
+ return (_jsxs("aside", { className: "flex w-full shrink-0 flex-col gap-3 lg:w-72 lg:min-h-0 lg:overflow-y-auto", "aria-label": `${WORKFLOW_NAME.title} wiring and problems`, children: [_jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Wiring" }), draft.edges.length === 0 ? (_jsx("p", { className: cn('mt-2 text-[11px]', MUTED), children: "Nothing is wired together yet." })) : (_jsx("ul", { className: "mt-2 space-y-1", children: draft.edges.map((edge) => (_jsxs("li", { className: "flex items-center gap-1.5 text-[11px]", children: [_jsx("button", { type: "button", onClick: () => onInspect(edge.from), className: "truncate hover:underline", children: label(edge.from) }), _jsx(ArrowRight, { size: 10, className: cn('shrink-0', MUTED) }), _jsx("button", { type: "button", onClick: () => onInspect(edge.to), className: "truncate hover:underline", children: label(edge.to) }), canEdit && (_jsx(Tooltip, { content: "Remove this connection.", children: _jsx("button", { type: "button", onClick: () => onDisconnect(edge), "aria-label": `Disconnect ${label(edge.from)} from ${label(edge.to)}`, className: "ml-auto shrink-0 rounded p-0.5 text-zinc-400 hover:text-red-600", children: _jsx(Unplug, { size: 11 }) }) }))] }, edgeId(edge)))) }))] }), children, _jsx(PendingWork, { pending: pending, label: label, onInspect: onInspect }), _jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Problems" }), problems.length === 0 ? (_jsx("p", { className: cn('mt-2 text-[11px]', MUTED), children: "Nothing to flag here. The server checks it again on save." })) : (_jsx("ul", { className: "mt-2 space-y-2", children: [...errors, ...warnings].map((problem) => (_jsxs("li", { className: "flex gap-1.5 text-[11px] leading-relaxed", children: [problem.level === 'error' ? (_jsx(CircleAlert, { size: 11, className: "mt-0.5 shrink-0 text-red-500" })) : (_jsx(TriangleAlert, { size: 11, className: "mt-0.5 shrink-0 text-amber-500" })), _jsxs("span", { children: [problem.message, problem.nodeIds.length > 0 && (_jsx("span", { className: "ml-1", children: problem.nodeIds.map((nodeId) => (_jsx("button", { type: "button", onClick: () => onInspect(nodeId), className: cn('mr-1 rounded border px-1 font-mono text-[9px]', RULE, MUTED), children: label(nodeId) }, nodeId))) }))] })] }, `${problem.code}:${problem.nodeIds.join(',')}`))) }))] }), run && (_jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Last run" }), _jsxs("p", { className: "mt-1 text-[11px]", children: [run.status, _jsx("span", { className: cn('ml-1 font-mono text-[10px]', MUTED), children: run.durable ? 'checkpointed per node' : 'ran inline, no checkpoints' })] }), sinks.length > 0 && (_jsxs("div", { className: "mt-2", children: [_jsx("h3", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Committed" }), _jsx("ul", { className: "mt-1 space-y-1", children: sinks.map((sink) => {
1209
1477
  const outcome = run.nodes.find((node) => node.nodeId === sink.id);
1210
1478
  const type = sink.kind === 'sink' && sink.targetType ? sink.targetType : 'no type';
1211
1479
  return (_jsxs("li", { className: "flex items-center gap-1.5 text-[11px]", children: [_jsx("span", { className: "truncate font-mono text-[10px]", children: type }), _jsx("span", { className: cn('ml-auto shrink-0 font-mono text-[10px]', outcome?.status === 'failed'
@@ -1303,7 +1571,115 @@ function SinkInspector({ node, typeOptions, canEdit, onChange, }) {
1303
1571
  { value: 'incremental', label: 'Incremental — merge into it' },
1304
1572
  ], disabled: !canEdit }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["This sink commits ", node.targetType || 'its type', " on its own. Another sink in the same graph committing a different type is a separate commit \u2014 one can succeed while this one fails, and the run is reported as failed when any of them does."] })] }));
1305
1573
  }
1306
- function NodeInspector({ node, draft, transforms, connections, typeOptions, canEdit, problems, pending, onClose, onChange, onConnect, onConnectToNew, onDisconnect, onDelete, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
1574
+ /**
1575
+ * Which workflow this node hands its step to, and what it hands it.
1576
+ *
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.
1592
+ *
1593
+ * ## Why the version is a required field and not a convenience
1594
+ *
1595
+ * Without it the load would run whichever version is registered on the day it
1596
+ * runs, so the person who owns that workflow could change what this pipeline
1597
+ * 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.
1603
+ */
1604
+ function CallInspector({ node, canEdit, onChange, }) {
1605
+ // Held locally, pushed up when it parses — the same rule `SourceInspector`
1606
+ // follows for its text fields. Re-deriving the box from the stored config
1607
+ // would rewrite what somebody is halfway through typing, and a JSON editor
1608
+ // that reformats mid-keystroke is unusable.
1609
+ const [text, setText] = useState(() => configText(node.config));
1610
+ const [invalid, setInvalid] = useState(false);
1611
+ const pushConfig = (next) => {
1612
+ setText(next);
1613
+ const parsed = parseConfigText(next);
1614
+ setInvalid(parsed === undefined);
1615
+ if (parsed !== undefined)
1616
+ onChange({ ...node, config: parsed });
1617
+ };
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
1619
+ ? 'That is not valid JSON yet, so it has not been saved onto the node.'
1620
+ : '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
+ }
1622
+ /**
1623
+ * The parameter box's two directions, kept together because they are inverses.
1624
+ *
1625
+ * An empty object shows as an empty box rather than as `{}`: the node starts
1626
+ * with no parameters, and opening a fresh call node onto punctuation somebody
1627
+ * has to delete is a worse start than a placeholder.
1628
+ */
1629
+ function configText(config) {
1630
+ return Object.keys(config).length === 0 ? '' : JSON.stringify(config, null, 2);
1631
+ }
1632
+ /**
1633
+ * A JSON object, or `undefined` for anything else — including an array and
1634
+ * including `null`, both of which `JSON.parse` accepts and neither of which is
1635
+ * a parameter bag. Blank means no parameters, which is not an error.
1636
+ */
1637
+ function parseConfigText(text) {
1638
+ if (text.trim().length === 0)
1639
+ return {};
1640
+ try {
1641
+ const parsed = JSON.parse(text);
1642
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
1643
+ return undefined;
1644
+ const config = {};
1645
+ for (const key of Object.keys(parsed))
1646
+ config[key] = Reflect.get(parsed, key);
1647
+ return config;
1648
+ }
1649
+ catch {
1650
+ return undefined;
1651
+ }
1652
+ }
1653
+ /**
1654
+ * The fields that belong to one kind of node and to no other.
1655
+ *
1656
+ * Split out of `NodeInspector` rather than written inline, because that
1657
+ * function is otherwise about the things every node has — its name, its wiring,
1658
+ * its problems, deleting it — and the per-kind chain is the one part of it that
1659
+ * grows every time the vocabulary does. Narrowing is what the union is for, so
1660
+ * a kind added without a branch here shows up as a node with a name and nothing
1661
+ * to configure, which is visible on the screen rather than silent.
1662
+ */
1663
+ function KindInspector({ node, transforms, connections, typeOptions, canEdit, discovery, discoverable, onDiscovered, onChange, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
1664
+ if (node.kind === 'transform') {
1665
+ return (_jsx(TransformInspector, { node: node, transforms: transforms, canEdit: canEdit, creating: creatingTransform, createError: createTransformError, onChange: onChange, onEditCode: onEditCode, onCreate: onCreateTransform }));
1666
+ }
1667
+ if (node.kind === 'source') {
1668
+ return (_jsx(SourceInspector
1669
+ // Keyed so the text fields reset when a different source is opened.
1670
+ // Without it the draft state would survive the swap and one node's URL
1671
+ // would appear inside another.
1672
+ , { node: node, connections: connections, canEdit: canEdit, discovery: discovery, discoverable: discoverable, onDiscovered: onDiscovered, onChange: onChange }, node.id));
1673
+ }
1674
+ if (node.kind === 'call') {
1675
+ // Keyed for the same reason the source inspector is: the parameter box
1676
+ // holds text somebody is midway through typing, and it must not survive
1677
+ // being pointed at a different node.
1678
+ return _jsx(CallInspector, { node: node, canEdit: canEdit, onChange: onChange }, node.id);
1679
+ }
1680
+ return (_jsx(SinkInspector, { node: node, typeOptions: typeOptions, canEdit: canEdit, onChange: onChange }));
1681
+ }
1682
+ function NodeInspector({ node, draft, transforms, connections, typeOptions, canEdit, problems, pending, discovery, discoverable, onDiscovered, onClose, onChange, onConnect, onConnectToNew, onDisconnect, onDelete, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
1307
1683
  const [pendingTarget, setPendingTarget] = useState('');
1308
1684
  const label = (id) => {
1309
1685
  const found = draft.nodes.find((n) => n.id === id);
@@ -1344,11 +1720,7 @@ function NodeInspector({ node, draft, transforms, connections, typeOptions, canE
1344
1720
  return (_jsx(Sheet, { open: node !== null, onOpenChange: (open) => {
1345
1721
  if (!open)
1346
1722
  onClose();
1347
- }, 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." }), node.kind === 'transform' && (_jsx(TransformInspector, { node: node, transforms: transforms, canEdit: canEdit, creating: creatingTransform, createError: createTransformError, onChange: onChange, onEditCode: onEditCode, onCreate: onCreateTransform })), node.kind === 'source' && (_jsx(SourceInspector
1348
- // Keyed so the text fields reset when a different source is
1349
- // opened. Without it the draft state would survive the swap and
1350
- // one node's URL would appear inside another.
1351
- , { node: node, connections: connections, canEdit: canEdit, onChange: onChange }, node.id)), node.kind === 'sink' && (_jsx(SinkInspector, { node: node, typeOptions: typeOptions, canEdit: canEdit, onChange: onChange })), _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
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
1352
1724
  ? 'Nothing can be wired from here'
1353
1725
  : 'Send its output to…', disabled: eligible.length === 0 }) }), _jsx("button", { type: "button", onClick: () => {
1354
1726
  if (!pendingTarget)
@@ -1375,10 +1747,10 @@ function NodeInspector({ node, draft, transforms, connections, typeOptions, canE
1375
1747
  * rather than read back out of the node. Re-deriving them from the stored config
1376
1748
  * would make a half-typed number disappear the moment it stopped parsing.
1377
1749
  */
1378
- function SourceInspector({ node, connections, canEdit, onChange, }) {
1750
+ function SourceInspector({ node, connections, canEdit, discovery, discoverable, onDiscovered, onChange, }) {
1379
1751
  const [source, setSource] = useState(() => sourceDraftFrom(node.config));
1380
1752
  const kind = toConnectorKind(node.sourceKind ?? 'http');
1381
- const options = connectionOptions(kind, connections);
1753
+ const options = connectionOptionsFor(kind, connections);
1382
1754
  // A connection chosen for one kind is meaningless for another, so switching
1383
1755
  // the kind drops it rather than keeping an id the server would reject.
1384
1756
  const chosen = options.some((option) => option.value === node.connectionId)
@@ -1425,5 +1797,5 @@ function SourceInspector({ node, connections, canEdit, onChange, }) {
1425
1797
  ? 'No connections of this kind yet. One is worth making when a second source needs the same address.'
1426
1798
  : viaConnection
1427
1799
  ? 'The connection supplies the address and the credential. What stays below is only what is specific to this load.'
1428
- : 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." }))] }));
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 } : {}) })] }));
1429
1801
  }