Yuchen Yuan commited on
Commit
74b7708
·
1 Parent(s): 10b580f

Plugin protocol Phase 4: full UI integration

Browse files

* lib/nodeCatalog.ts — `synthesizePluginSpec(manifest)` builds a
NodeSpec on the fly from a backend-served PluginManifest.
`resolveNodeSpec(kind, plugins)` is the new single source of
truth for spec lookups: returns the built-in spec if available,
otherwise the synthesized plugin spec, otherwise undefined.
Adds PluginNodeSpec (NodeSpec + isPlugin/initials/pluginColor).

* UploadPluginModal.tsx — drag-drop or click-to-pick .zip, posts
to /api/plugins/upload with the browser's anonymous user_id,
surfaces backend validation errors verbatim, refreshes the in-
store plugin list on success. Inline docs spell out the manifest
+ handler.py contract.

* NodePalette — new "Upload" button next to "Add blocks"; merges
plugin specs with NODE_CATALOG before filtering by search /
family chips. Plugin tiles render with the manifest's color +
first-letter badge instead of a Lucide icon, and grow an X
delete affordance on hover (with confirm dialog).

* BlockPicker — same merge. Plugin entries get a "plugin" pill
next to the label and the colored initials badge in place of the
built-in Lucide icon.

* QNode — canvas-side block tile: plugin nodes get the colored
initials badge + a "plugin" pill in the label row, so users can
tell at a glance which blocks are their own.

* FlowCanvas — drop handler + pendingBlockKinds dispatch now go
through resolveNodeSpec, so plugin kinds are valid drop targets.
RunRequest carries the anonymous user_id so the backend can
dispatch plugin nodes.

* autoConnect.ts — accepts an optional `plugins` argument so it
can resolve plugin families when classifying source / backend /
algorithm / metric / sink for chain ordering and warnings.

* ResultsPane — StepCard now resolves the spec via plugins too and
renders the plugin badge instead of a Lucide icon for plugin
step results.

Frontend now has all the affordances needed. Phase 5 (next commit)
is the SDK doc + a demo plugin + the comprehensive audit pass.

frontend/src/components/BlockPicker.tsx CHANGED
@@ -1,6 +1,12 @@
1
  import { useEffect, useMemo, useRef, useState } from "react";
2
  import { Check, Plus, Search, X } from "lucide-react";
3
- import { NODE_CATALOG, type NodeKind, type NodeSpec } from "../lib/nodeCatalog";
 
 
 
 
 
 
4
  import { useApp } from "../lib/store";
5
 
6
  /**
@@ -71,17 +77,25 @@ export function BlockPicker({
71
  }
72
  }, [open]);
73
 
 
 
 
 
 
 
 
 
74
  const filtered = useMemo(() => {
75
- if (!search.trim()) return NODE_CATALOG;
76
  const q = search.toLowerCase();
77
- return NODE_CATALOG.filter(
78
  (n) =>
79
  n.label.toLowerCase().includes(q) ||
80
  n.tagline.toLowerCase().includes(q) ||
81
  n.family.toLowerCase().includes(q) ||
82
  n.kind.toLowerCase().includes(q),
83
  );
84
- }, [search]);
85
 
86
  const toggle = (kind: NodeKind) =>
87
  setChecked((s) => {
@@ -92,9 +106,11 @@ export function BlockPicker({
92
 
93
  const addSelected = () => {
94
  if (checked.size === 0) return;
95
- const ordered = NODE_CATALOG.filter((n) => checked.has(n.kind)).map(
96
- (n) => n.kind,
97
- );
 
 
98
  addBlocksToCanvas(ordered);
99
  setChecked(new Set());
100
  setOpen(false);
@@ -160,14 +176,15 @@ export function BlockPicker({
160
  </div>
161
  </div>
162
  {items.map((n) => {
163
- const isChecked = checked.has(n.kind);
164
- const onCanvas = canvasKinds.has(n.kind);
 
165
  const Icon = n.icon;
166
  return (
167
  <button
168
  key={n.kind}
169
  type="button"
170
- onClick={() => toggle(n.kind)}
171
  className={`w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left transition-colors ${
172
  isChecked
173
  ? "bg-accent/10"
@@ -186,16 +203,34 @@ export function BlockPicker({
186
  <Check className="w-2.5 h-2.5" strokeWidth={3} />
187
  )}
188
  </span>
189
- {/* Icon */}
190
- <span
191
- className={`shrink-0 w-5 h-5 rounded border ${n.accentRing} bg-surface flex items-center justify-center ${n.accent}`}
192
- >
193
- <Icon className="w-2.5 h-2.5" strokeWidth={2} />
194
- </span>
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  {/* Label + tagline */}
196
  <span className="flex-1 min-w-0">
197
  <span className="text-[11px] text-ink block truncate">
198
  {n.label}
 
 
 
 
 
199
  </span>
200
  <span className="text-[9px] text-mute block truncate">
201
  {n.tagline}
 
1
  import { useEffect, useMemo, useRef, useState } from "react";
2
  import { Check, Plus, Search, X } from "lucide-react";
3
+ import {
4
+ NODE_CATALOG,
5
+ synthesizePluginSpec,
6
+ type NodeKind,
7
+ type NodeSpec,
8
+ type PluginNodeSpec,
9
+ } from "../lib/nodeCatalog";
10
  import { useApp } from "../lib/store";
11
 
12
  /**
 
77
  }
78
  }, [open]);
79
 
80
+ // Merge built-in catalog with the user's plugin manifests so the
81
+ // picker shows everything in one list, grouped by family.
82
+ const plugins = useApp((s) => s.plugins);
83
+ const combined: (NodeSpec | PluginNodeSpec)[] = useMemo(
84
+ () => [...NODE_CATALOG, ...plugins.map(synthesizePluginSpec)],
85
+ [plugins],
86
+ );
87
+
88
  const filtered = useMemo(() => {
89
+ if (!search.trim()) return combined;
90
  const q = search.toLowerCase();
91
+ return combined.filter(
92
  (n) =>
93
  n.label.toLowerCase().includes(q) ||
94
  n.tagline.toLowerCase().includes(q) ||
95
  n.family.toLowerCase().includes(q) ||
96
  n.kind.toLowerCase().includes(q),
97
  );
98
+ }, [search, combined]);
99
 
100
  const toggle = (kind: NodeKind) =>
101
  setChecked((s) => {
 
106
 
107
  const addSelected = () => {
108
  if (checked.size === 0) return;
109
+ // Preserve catalog order (built-ins first, then plugins) so
110
+ // auto-connect lays them out left-to-right sensibly.
111
+ const ordered = combined
112
+ .filter((n) => checked.has(n.kind as NodeKind))
113
+ .map((n) => n.kind as NodeKind);
114
  addBlocksToCanvas(ordered);
115
  setChecked(new Set());
116
  setOpen(false);
 
176
  </div>
177
  </div>
178
  {items.map((n) => {
179
+ const isChecked = checked.has(n.kind as NodeKind);
180
+ const onCanvas = canvasKinds.has(n.kind as NodeKind);
181
+ const isPlugin = "isPlugin" in n && n.isPlugin;
182
  const Icon = n.icon;
183
  return (
184
  <button
185
  key={n.kind}
186
  type="button"
187
+ onClick={() => toggle(n.kind as NodeKind)}
188
  className={`w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left transition-colors ${
189
  isChecked
190
  ? "bg-accent/10"
 
203
  <Check className="w-2.5 h-2.5" strokeWidth={3} />
204
  )}
205
  </span>
206
+ {/* Icon — built-in uses Lucide; plugin uses
207
+ initials badge with custom color so users
208
+ can tell theirs apart. */}
209
+ {isPlugin ? (
210
+ <span
211
+ className="shrink-0 w-5 h-5 rounded flex items-center justify-center text-[9px] font-bold text-white"
212
+ style={{
213
+ backgroundColor: (n as PluginNodeSpec).pluginColor,
214
+ }}
215
+ >
216
+ {(n as PluginNodeSpec).initials}
217
+ </span>
218
+ ) : (
219
+ <span
220
+ className={`shrink-0 w-5 h-5 rounded border ${n.accentRing} bg-surface flex items-center justify-center ${n.accent}`}
221
+ >
222
+ <Icon className="w-2.5 h-2.5" strokeWidth={2} />
223
+ </span>
224
+ )}
225
  {/* Label + tagline */}
226
  <span className="flex-1 min-w-0">
227
  <span className="text-[11px] text-ink block truncate">
228
  {n.label}
229
+ {isPlugin && (
230
+ <span className="ml-1 text-[8px] uppercase tracking-wider text-mute/60">
231
+ plugin
232
+ </span>
233
+ )}
234
  </span>
235
  <span className="text-[9px] text-mute block truncate">
236
  {n.tagline}
frontend/src/components/FlowCanvas.tsx CHANGED
@@ -30,7 +30,7 @@ import {
30
  } from "lucide-react";
31
  import { copyToClipboard } from "../lib/clipboard";
32
  import { generatePythonScript } from "../lib/exportPython";
33
- import { NODE_BY_KIND, type NodeKind } from "../lib/nodeCatalog";
34
  import {
35
  DEFAULT_PRESET_KEY,
36
  PRESET_BY_KEY,
@@ -170,19 +170,23 @@ export function FlowCanvas() {
170
  );
171
  const startX = nodes.length === 0 ? 80 : maxX + 60;
172
 
173
- const newNodes: RFNode[] = kinds.map((kind, i) => ({
174
- id: `n${Date.now().toString(36)}${i}`,
175
- type: "qnode",
176
- position: { x: startX + i * SPACING_X, y: Y },
177
- data: {
178
- kind,
179
- params: { ...(NODE_BY_KIND[kind].defaultData ?? {}) },
180
- },
181
- }));
 
 
 
 
182
 
183
  setNodes((ns) => {
184
  const merged = [...ns, ...newNodes];
185
- const result = autoConnect(merged, []);
186
  if (result.connected) {
187
  setEdges(result.edges);
188
  setNotice(
@@ -245,15 +249,21 @@ export function FlowCanvas() {
245
  const onDrop = useCallback(
246
  (e: React.DragEvent) => {
247
  e.preventDefault();
248
- const kind = e.dataTransfer.getData("application/reactflow") as NodeKind;
249
- if (!kind || !NODE_BY_KIND[kind]) return;
 
 
 
250
  const position = screenToFlowPosition({ x: e.clientX, y: e.clientY });
251
  const id = `n${Date.now().toString(36)}`;
252
  const node: RFNode = {
253
  id,
254
  type: "qnode",
255
  position,
256
- data: { kind, params: { ...(NODE_BY_KIND[kind].defaultData ?? {}) } },
 
 
 
257
  };
258
  setNodes((ns) => ns.concat(node));
259
  },
@@ -346,7 +356,7 @@ export function FlowCanvas() {
346
  };
347
 
348
  const runAutoConnect = () => {
349
- const result = autoConnect(nodes, edges);
350
  if (!result.connected) {
351
  // Nothing to wire (empty/single/all-unknown canvas): just surface
352
  // the advisory without touching the edges.
 
30
  } from "lucide-react";
31
  import { copyToClipboard } from "../lib/clipboard";
32
  import { generatePythonScript } from "../lib/exportPython";
33
+ import { NODE_BY_KIND, resolveNodeSpec, type NodeKind } from "../lib/nodeCatalog";
34
  import {
35
  DEFAULT_PRESET_KEY,
36
  PRESET_BY_KEY,
 
170
  );
171
  const startX = nodes.length === 0 ? 80 : maxX + 60;
172
 
173
+ const plugins = useApp.getState().plugins;
174
+ const newNodes: RFNode[] = kinds.map((kind, i) => {
175
+ const spec = resolveNodeSpec(kind, plugins);
176
+ return {
177
+ id: `n${Date.now().toString(36)}${i}`,
178
+ type: "qnode",
179
+ position: { x: startX + i * SPACING_X, y: Y },
180
+ data: {
181
+ kind,
182
+ params: { ...((spec?.defaultData as Record<string, unknown>) ?? {}) },
183
+ },
184
+ };
185
+ });
186
 
187
  setNodes((ns) => {
188
  const merged = [...ns, ...newNodes];
189
+ const result = autoConnect(merged, [], useApp.getState().plugins);
190
  if (result.connected) {
191
  setEdges(result.edges);
192
  setNotice(
 
249
  const onDrop = useCallback(
250
  (e: React.DragEvent) => {
251
  e.preventDefault();
252
+ const kind = e.dataTransfer.getData("application/reactflow");
253
+ if (!kind) return;
254
+ const plugins = useApp.getState().plugins;
255
+ const spec = resolveNodeSpec(kind, plugins);
256
+ if (!spec) return;
257
  const position = screenToFlowPosition({ x: e.clientX, y: e.clientY });
258
  const id = `n${Date.now().toString(36)}`;
259
  const node: RFNode = {
260
  id,
261
  type: "qnode",
262
  position,
263
+ data: {
264
+ kind: kind as NodeKind,
265
+ params: { ...((spec.defaultData as Record<string, unknown>) ?? {}) },
266
+ },
267
  };
268
  setNodes((ns) => ns.concat(node));
269
  },
 
356
  };
357
 
358
  const runAutoConnect = () => {
359
+ const result = autoConnect(nodes, edges, useApp.getState().plugins);
360
  if (!result.connected) {
361
  // Nothing to wire (empty/single/all-unknown canvas): just surface
362
  // the advisory without touching the edges.
frontend/src/components/NodePalette.tsx CHANGED
@@ -1,7 +1,17 @@
1
  import { useState, useMemo } from "react";
2
- import { ChevronDown, FileText, Search, X } from "lucide-react";
3
- import { NODE_CATALOG, type NodeKind, type NodeSpec } from "../lib/nodeCatalog";
 
 
 
 
 
 
 
 
 
4
  import { BlockPicker } from "./BlockPicker";
 
5
 
6
  /**
7
  * Categorised block catalog above the canvas.
@@ -43,25 +53,49 @@ export function NodePalette({
43
  } = {}) {
44
  const [search, setSearch] = useState("");
45
  const [expanded, setExpanded] = useState(true);
 
46
  // null = show all families; a family key = show only that family.
47
  const [activeFamily, setActiveFamily] = useState<NodeSpec["family"] | null>(null);
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  const toggleFamily = (fam: NodeSpec["family"]) =>
50
  setActiveFamily((cur) => (cur === fam ? null : fam));
51
 
 
 
 
 
 
 
 
 
 
 
52
  const filtered = useMemo(() => {
53
- if (!search.trim()) return NODE_CATALOG;
54
  const q = search.toLowerCase();
55
- return NODE_CATALOG.filter(
56
  (n) =>
57
  n.label.toLowerCase().includes(q) ||
58
  n.tagline.toLowerCase().includes(q) ||
59
  n.family.toLowerCase().includes(q) ||
60
  n.kind.toLowerCase().includes(q),
61
  );
62
- }, [search]);
63
 
64
- const totalCount = NODE_CATALOG.length;
65
 
66
  if (!expanded) {
67
  return (
@@ -86,6 +120,16 @@ export function NodePalette({
86
  <div className="px-3 pt-2 pb-1 flex items-center gap-2">
87
  {/* Multi-select dropdown picker */}
88
  <BlockPicker canvasKinds={canvasKinds} />
 
 
 
 
 
 
 
 
 
 
89
  {/* Search */}
90
  <div className="relative flex-1 max-w-[200px]">
91
  <Search className="absolute left-2 top-1/2 -translate-y-1/2 w-3 h-3 text-mute pointer-events-none" />
@@ -171,7 +215,15 @@ export function NodePalette({
171
  </button>
172
  <div className="flex items-center gap-1 flex-wrap">
173
  {items.map((n) => (
174
- <PaletteTile key={n.kind} spec={n} />
 
 
 
 
 
 
 
 
175
  ))}
176
  </div>
177
  {/* Divider between visible families (not after the last) */}
@@ -187,11 +239,21 @@ export function NodePalette({
187
  </div>
188
  )}
189
  </div>
 
190
  </div>
191
  );
192
  }
193
 
194
- function PaletteTile({ spec }: { spec: NodeSpec }) {
 
 
 
 
 
 
 
 
 
195
  const Icon = spec.icon;
196
  function onDragStart(e: React.DragEvent) {
197
  e.dataTransfer.setData("application/reactflow", spec.kind);
@@ -201,10 +263,15 @@ function PaletteTile({ spec }: { spec: NodeSpec }) {
201
  <div
202
  draggable
203
  onDragStart={onDragStart}
204
- className="group relative shrink-0 cursor-grab active:cursor-grabbing flex flex-col items-center justify-center gap-0.5 w-[108px] h-[76px] rounded-md border border-edge/60 hover:border-edge hover:bg-surfaceAlt transition-colors text-center px-1.5 py-1.5"
 
 
 
 
205
  title={spec.description}
206
  >
207
- {spec.paper && (
 
208
  <a
209
  href={spec.paper.url}
210
  target="_blank"
@@ -219,11 +286,36 @@ function PaletteTile({ spec }: { spec: NodeSpec }) {
219
  <FileText className="w-2.5 h-2.5" strokeWidth={2} />
220
  </a>
221
  )}
222
- <span
223
- className={`w-6 h-6 rounded-md border ${spec.accentRing} bg-surface flex items-center justify-center ${spec.accent}`}
224
- >
225
- <Icon className="w-3 h-3" strokeWidth={2} />
226
- </span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  <span className="text-[10px] text-ink truncate max-w-full leading-tight">
228
  {spec.label}
229
  </span>
 
1
  import { useState, useMemo } from "react";
2
+ import { ChevronDown, FileText, Search, Upload, X } from "lucide-react";
3
+ import { api } from "../lib/api";
4
+ import {
5
+ NODE_CATALOG,
6
+ synthesizePluginSpec,
7
+ type NodeKind,
8
+ type NodeSpec,
9
+ type PluginNodeSpec,
10
+ } from "../lib/nodeCatalog";
11
+ import { useApp } from "../lib/store";
12
+ import { getUserId } from "../lib/userId";
13
  import { BlockPicker } from "./BlockPicker";
14
+ import { UploadPluginModal } from "./UploadPluginModal";
15
 
16
  /**
17
  * Categorised block catalog above the canvas.
 
53
  } = {}) {
54
  const [search, setSearch] = useState("");
55
  const [expanded, setExpanded] = useState(true);
56
+ const [uploadOpen, setUploadOpen] = useState(false);
57
  // null = show all families; a family key = show only that family.
58
  const [activeFamily, setActiveFamily] = useState<NodeSpec["family"] | null>(null);
59
 
60
+ // Plugin manifests this browser has uploaded — merged with NODE_CATALOG
61
+ // so plugins show up under their declared family alongside built-ins.
62
+ const plugins = useApp((s) => s.plugins);
63
+ const setPlugins = useApp((s) => s.setPlugins);
64
+ const pluginSpecs: PluginNodeSpec[] = useMemo(
65
+ () => plugins.map(synthesizePluginSpec),
66
+ [plugins],
67
+ );
68
+ const combined: (NodeSpec | PluginNodeSpec)[] = useMemo(
69
+ () => [...NODE_CATALOG, ...pluginSpecs],
70
+ [pluginSpecs],
71
+ );
72
+
73
  const toggleFamily = (fam: NodeSpec["family"]) =>
74
  setActiveFamily((cur) => (cur === fam ? null : fam));
75
 
76
+ const handleDeletePlugin = async (kind: string) => {
77
+ try {
78
+ await api.deletePlugin(getUserId(), kind);
79
+ const fresh = await api.listPlugins(getUserId());
80
+ setPlugins(fresh);
81
+ } catch {
82
+ /* silent — the tile staying around is harmless */
83
+ }
84
+ };
85
+
86
  const filtered = useMemo(() => {
87
+ if (!search.trim()) return combined;
88
  const q = search.toLowerCase();
89
+ return combined.filter(
90
  (n) =>
91
  n.label.toLowerCase().includes(q) ||
92
  n.tagline.toLowerCase().includes(q) ||
93
  n.family.toLowerCase().includes(q) ||
94
  n.kind.toLowerCase().includes(q),
95
  );
96
+ }, [search, combined]);
97
 
98
+ const totalCount = combined.length;
99
 
100
  if (!expanded) {
101
  return (
 
120
  <div className="px-3 pt-2 pb-1 flex items-center gap-2">
121
  {/* Multi-select dropdown picker */}
122
  <BlockPicker canvasKinds={canvasKinds} />
123
+ <button
124
+ type="button"
125
+ onClick={() => setUploadOpen(true)}
126
+ className="inline-flex items-center gap-1.5 px-2 py-1 rounded-md text-[11px] font-medium border border-edge text-mute hover:border-accent/40 hover:text-ink transition-colors whitespace-nowrap"
127
+ title="Upload your own plugin block (.zip)"
128
+ aria-label="Upload plugin"
129
+ >
130
+ <Upload className="w-3 h-3" />
131
+ <span className="hidden lg:inline">Upload</span>
132
+ </button>
133
  {/* Search */}
134
  <div className="relative flex-1 max-w-[200px]">
135
  <Search className="absolute left-2 top-1/2 -translate-y-1/2 w-3 h-3 text-mute pointer-events-none" />
 
215
  </button>
216
  <div className="flex items-center gap-1 flex-wrap">
217
  {items.map((n) => (
218
+ <PaletteTile
219
+ key={n.kind}
220
+ spec={n}
221
+ onDelete={
222
+ "isPlugin" in n && n.isPlugin
223
+ ? () => handleDeletePlugin(n.kind)
224
+ : undefined
225
+ }
226
+ />
227
  ))}
228
  </div>
229
  {/* Divider between visible families (not after the last) */}
 
239
  </div>
240
  )}
241
  </div>
242
+ <UploadPluginModal open={uploadOpen} onClose={() => setUploadOpen(false)} />
243
  </div>
244
  );
245
  }
246
 
247
+ function PaletteTile({
248
+ spec,
249
+ onDelete,
250
+ }: {
251
+ spec: NodeSpec | PluginNodeSpec;
252
+ /** When set, shows a red × in the corner that calls back on click —
253
+ * used for user-uploaded plugins. */
254
+ onDelete?: () => void;
255
+ }) {
256
+ const isPlugin = "isPlugin" in spec && spec.isPlugin;
257
  const Icon = spec.icon;
258
  function onDragStart(e: React.DragEvent) {
259
  e.dataTransfer.setData("application/reactflow", spec.kind);
 
263
  <div
264
  draggable
265
  onDragStart={onDragStart}
266
+ className={`group relative shrink-0 cursor-grab active:cursor-grabbing flex flex-col items-center justify-center gap-0.5 w-[108px] h-[76px] rounded-md border transition-colors text-center px-1.5 py-1.5 ${
267
+ isPlugin
268
+ ? "border-edge bg-surface/60 hover:bg-surfaceAlt"
269
+ : "border-edge/60 hover:border-edge hover:bg-surfaceAlt"
270
+ }`}
271
  title={spec.description}
272
  >
273
+ {/* Top-right corner badge: paper link, delete button, or nothing */}
274
+ {spec.paper && !isPlugin && (
275
  <a
276
  href={spec.paper.url}
277
  target="_blank"
 
286
  <FileText className="w-2.5 h-2.5" strokeWidth={2} />
287
  </a>
288
  )}
289
+ {isPlugin && onDelete && (
290
+ <button
291
+ type="button"
292
+ draggable={false}
293
+ onDragStart={(e) => e.stopPropagation()}
294
+ onClick={(e) => {
295
+ e.stopPropagation();
296
+ if (window.confirm(`Delete plugin "${spec.label}"?`)) onDelete();
297
+ }}
298
+ className="absolute top-1 right-1 w-4 h-4 rounded-full border border-edge bg-surface text-mute hover:text-danger hover:border-danger/60 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10"
299
+ title={`Delete plugin ${spec.label}`}
300
+ aria-label={`Delete plugin ${spec.label}`}
301
+ >
302
+ <X className="w-2.5 h-2.5" strokeWidth={2.5} />
303
+ </button>
304
+ )}
305
+ {isPlugin ? (
306
+ <span
307
+ className="w-6 h-6 rounded-md flex items-center justify-center text-[10px] font-bold text-white"
308
+ style={{ backgroundColor: (spec as PluginNodeSpec).pluginColor }}
309
+ >
310
+ {(spec as PluginNodeSpec).initials}
311
+ </span>
312
+ ) : (
313
+ <span
314
+ className={`w-6 h-6 rounded-md border ${spec.accentRing} bg-surface flex items-center justify-center ${spec.accent}`}
315
+ >
316
+ <Icon className="w-3 h-3" strokeWidth={2} />
317
+ </span>
318
+ )}
319
  <span className="text-[10px] text-ink truncate max-w-full leading-tight">
320
  {spec.label}
321
  </span>
frontend/src/components/QNode.tsx CHANGED
@@ -8,10 +8,11 @@ import {
8
  X,
9
  } from "lucide-react";
10
  import {
11
- NODE_BY_KIND,
12
  type NodeKind,
13
  type NodeParamSpec,
14
  type NodeSpec,
 
15
  } from "../lib/nodeCatalog";
16
  import { NodeParamEditor } from "./NodeParamEditor";
17
  import { TipIcon } from "./TipIcon";
@@ -52,7 +53,6 @@ export interface QNodeData extends Record<string, unknown> {
52
  */
53
  export function QNode({ id, data, selected }: NodeProps) {
54
  const d = data as QNodeData;
55
- const spec = NODE_BY_KIND[d.kind];
56
  const flow = useReactFlow();
57
  const { deleteElements } = flow;
58
  // Subscribe to the active circuit so source/algorithm blocks can
@@ -63,6 +63,10 @@ export function QNode({ id, data, selected }: NodeProps) {
63
  // shallow comparison keeps the cost cheap.
64
  const circuit = useApp((s) => s.circuit);
65
  const sampleKey = useApp((s) => s.sampleKey);
 
 
 
 
66
  // Per-instance disclosure state for the param editor. Default to
67
  // collapsed so the canvas stays scannable; users click the chevron
68
  // to reveal the controls. State lives in component-local React
@@ -115,13 +119,36 @@ export function QNode({ id, data, selected }: NodeProps) {
115
  </a>
116
  )}
117
  <div className="flex items-center gap-2">
118
- <span
119
- className={`w-7 h-7 rounded-md border ${spec.accentRing} bg-surface flex items-center justify-center ${spec.accent} shrink-0`}
120
- >
121
- <Icon className="w-3.5 h-3.5" strokeWidth={2} />
122
- </span>
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  <div className="min-w-0 flex-1">
124
- <div className="font-medium text-ink text-sm">{spec.label}</div>
 
 
 
 
 
 
 
 
 
 
125
  <div className="text-[10px] text-mute uppercase tracking-wider flex items-center gap-1">
126
  <span>{spec.family}</span>
127
  <TipIcon hint={FAMILY_HINTS[spec.family]} size={10} />
 
8
  X,
9
  } from "lucide-react";
10
  import {
11
+ resolveNodeSpec,
12
  type NodeKind,
13
  type NodeParamSpec,
14
  type NodeSpec,
15
+ type PluginNodeSpec,
16
  } from "../lib/nodeCatalog";
17
  import { NodeParamEditor } from "./NodeParamEditor";
18
  import { TipIcon } from "./TipIcon";
 
53
  */
54
  export function QNode({ id, data, selected }: NodeProps) {
55
  const d = data as QNodeData;
 
56
  const flow = useReactFlow();
57
  const { deleteElements } = flow;
58
  // Subscribe to the active circuit so source/algorithm blocks can
 
63
  // shallow comparison keeps the cost cheap.
64
  const circuit = useApp((s) => s.circuit);
65
  const sampleKey = useApp((s) => s.sampleKey);
66
+ const plugins = useApp((s) => s.plugins);
67
+ // Spec resolution — built-in OR user plugin. Hook order requires
68
+ // this stay above any early return.
69
+ const spec = resolveNodeSpec(d.kind, plugins);
70
  // Per-instance disclosure state for the param editor. Default to
71
  // collapsed so the canvas stays scannable; users click the chevron
72
  // to reveal the controls. State lives in component-local React
 
119
  </a>
120
  )}
121
  <div className="flex items-center gap-2">
122
+ {"isPlugin" in spec && spec.isPlugin ? (
123
+ // Plugin badge: filled square in plugin's chosen color +
124
+ // first-letter(s) so users can distinguish multiple plugins
125
+ // at a glance.
126
+ <span
127
+ className="w-7 h-7 rounded-md flex items-center justify-center shrink-0 text-[11px] font-bold text-white"
128
+ style={{ backgroundColor: (spec as PluginNodeSpec).pluginColor }}
129
+ title={`User plugin (${spec.kind})`}
130
+ >
131
+ {(spec as PluginNodeSpec).initials}
132
+ </span>
133
+ ) : (
134
+ <span
135
+ className={`w-7 h-7 rounded-md border ${spec.accentRing} bg-surface flex items-center justify-center ${spec.accent} shrink-0`}
136
+ >
137
+ <Icon className="w-3.5 h-3.5" strokeWidth={2} />
138
+ </span>
139
+ )}
140
  <div className="min-w-0 flex-1">
141
+ <div className="font-medium text-ink text-sm flex items-center gap-1">
142
+ <span className="truncate">{spec.label}</span>
143
+ {"isPlugin" in spec && spec.isPlugin && (
144
+ <span
145
+ className="text-[9px] px-1 py-0.5 rounded border border-edge text-mute/70 shrink-0"
146
+ title="User-uploaded plugin"
147
+ >
148
+ plugin
149
+ </span>
150
+ )}
151
+ </div>
152
  <div className="text-[10px] text-mute uppercase tracking-wider flex items-center gap-1">
153
  <span>{spec.family}</span>
154
  <TipIcon hint={FAMILY_HINTS[spec.family]} size={10} />
frontend/src/components/ResultsPane.tsx CHANGED
@@ -6,7 +6,10 @@
6
 
7
  import { useApp } from "../lib/store";
8
  import type { StepResult } from "../lib/api";
9
- import { NODE_BY_KIND, type NodeKind } from "../lib/nodeCatalog";
 
 
 
10
  import {
11
  AlertCircle,
12
  Check,
@@ -128,7 +131,9 @@ function NextStepsHint() {
128
  }
129
 
130
  function StepCard({ step }: { step: StepResult }) {
131
- const spec = NODE_BY_KIND[step.node_type as NodeKind];
 
 
132
  const Icon = spec?.icon ?? CircleDot;
133
  const dur = step.finished_at - step.started_at;
134
 
@@ -146,13 +151,23 @@ function StepCard({ step }: { step: StepResult }) {
146
  return (
147
  <div className="panel-alt p-3">
148
  <div className="flex items-center gap-2">
149
- <span
150
- className={`w-7 h-7 rounded-md border bg-surface flex items-center justify-center shrink-0 ${
151
- spec?.accent ?? "text-mute"
152
- } ${spec?.accentRing ?? "border-edge"}`}
153
- >
154
- <Icon className="w-3.5 h-3.5" strokeWidth={2} />
155
- </span>
 
 
 
 
 
 
 
 
 
 
156
  <div className="min-w-0 flex-1">
157
  <div className="flex items-center gap-2">
158
  <span className="font-medium text-ink text-sm">{step.label}</span>
 
6
 
7
  import { useApp } from "../lib/store";
8
  import type { StepResult } from "../lib/api";
9
+ import {
10
+ resolveNodeSpec,
11
+ type PluginNodeSpec,
12
+ } from "../lib/nodeCatalog";
13
  import {
14
  AlertCircle,
15
  Check,
 
131
  }
132
 
133
  function StepCard({ step }: { step: StepResult }) {
134
+ const plugins = useApp((s) => s.plugins);
135
+ const spec = resolveNodeSpec(step.node_type, plugins);
136
+ const isPlugin = spec && "isPlugin" in spec && spec.isPlugin;
137
  const Icon = spec?.icon ?? CircleDot;
138
  const dur = step.finished_at - step.started_at;
139
 
 
151
  return (
152
  <div className="panel-alt p-3">
153
  <div className="flex items-center gap-2">
154
+ {isPlugin ? (
155
+ <span
156
+ className="w-7 h-7 rounded-md flex items-center justify-center shrink-0 text-[11px] font-bold text-white"
157
+ style={{ backgroundColor: (spec as PluginNodeSpec).pluginColor }}
158
+ title={`User plugin (${step.node_type})`}
159
+ >
160
+ {(spec as PluginNodeSpec).initials}
161
+ </span>
162
+ ) : (
163
+ <span
164
+ className={`w-7 h-7 rounded-md border bg-surface flex items-center justify-center shrink-0 ${
165
+ spec?.accent ?? "text-mute"
166
+ } ${spec?.accentRing ?? "border-edge"}`}
167
+ >
168
+ <Icon className="w-3.5 h-3.5" strokeWidth={2} />
169
+ </span>
170
+ )}
171
  <div className="min-w-0 flex-1">
172
  <div className="flex items-center gap-2">
173
  <span className="font-medium text-ink text-sm">{step.label}</span>
frontend/src/components/UploadPluginModal.tsx ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { Loader2, Upload, X } from "lucide-react";
3
+ import { api } from "../lib/api";
4
+ import { getUserId } from "../lib/userId";
5
+ import { useApp } from "../lib/store";
6
+
7
+ /**
8
+ * Plugin upload modal. Accepts a .zip drag-drop or click-to-select,
9
+ * POSTs it to /api/plugins/upload, refreshes the in-store plugin list
10
+ * on success.
11
+ *
12
+ * Validation errors from the backend are surfaced verbatim (they're
13
+ * already written for an end user: "Zip is X bytes; max is Y",
14
+ * "kind 'input_circuit' collides with a built-in block", etc).
15
+ */
16
+
17
+ export function UploadPluginModal({
18
+ open,
19
+ onClose,
20
+ }: {
21
+ open: boolean;
22
+ onClose: () => void;
23
+ }) {
24
+ const setPlugins = useApp((s) => s.setPlugins);
25
+ const [busy, setBusy] = useState(false);
26
+ const [error, setError] = useState<string | null>(null);
27
+ const [success, setSuccess] = useState<string | null>(null);
28
+ const [dragOver, setDragOver] = useState(false);
29
+ const inputRef = useRef<HTMLInputElement | null>(null);
30
+
31
+ // Reset transient state every time the modal reopens.
32
+ useEffect(() => {
33
+ if (open) {
34
+ setError(null);
35
+ setSuccess(null);
36
+ setBusy(false);
37
+ setDragOver(false);
38
+ }
39
+ }, [open]);
40
+
41
+ // Escape closes the modal.
42
+ useEffect(() => {
43
+ if (!open) return;
44
+ const onKey = (e: KeyboardEvent) => {
45
+ if (e.key === "Escape" && !busy) onClose();
46
+ };
47
+ document.addEventListener("keydown", onKey);
48
+ return () => document.removeEventListener("keydown", onKey);
49
+ }, [open, busy, onClose]);
50
+
51
+ if (!open) return null;
52
+
53
+ const handleFile = async (file: File) => {
54
+ if (busy) return;
55
+ setError(null);
56
+ setSuccess(null);
57
+
58
+ // Light client-side checks so the user doesn't have to wait for
59
+ // an HTTP round trip for obviously-wrong inputs.
60
+ if (!file.name.toLowerCase().endsWith(".zip")) {
61
+ setError("Please pick a .zip file.");
62
+ return;
63
+ }
64
+ if (file.size > 1 * 1024 * 1024) {
65
+ setError(`File is ${(file.size / 1024).toFixed(0)} KB; max is 1024 KB.`);
66
+ return;
67
+ }
68
+
69
+ setBusy(true);
70
+ try {
71
+ const userId = getUserId();
72
+ const manifest = await api.uploadPlugin(userId, file);
73
+ setSuccess(`Installed ${manifest.label} (kind=${manifest.kind}).`);
74
+ // Refresh the global plugin list so NodePalette + BlockPicker
75
+ // pick the new block up immediately.
76
+ const list = await api.listPlugins(userId);
77
+ setPlugins(list);
78
+ } catch (err) {
79
+ setError(err instanceof Error ? err.message : String(err));
80
+ } finally {
81
+ setBusy(false);
82
+ }
83
+ };
84
+
85
+ const onDrop = (e: React.DragEvent) => {
86
+ e.preventDefault();
87
+ setDragOver(false);
88
+ const file = e.dataTransfer.files[0];
89
+ if (file) handleFile(file);
90
+ };
91
+
92
+ return (
93
+ <div
94
+ role="dialog"
95
+ aria-modal="true"
96
+ aria-label="Upload plugin"
97
+ className="fixed inset-0 z-50 bg-canvas/70 backdrop-blur-sm flex items-center justify-center p-4"
98
+ onClick={() => !busy && onClose()}
99
+ >
100
+ <div
101
+ className="bg-surface border border-edge rounded-xl shadow-2xl w-full max-w-md flex flex-col overflow-hidden"
102
+ onClick={(e) => e.stopPropagation()}
103
+ >
104
+ <div className="px-4 py-3 border-b border-edge flex items-center justify-between">
105
+ <div>
106
+ <div className="text-sm font-semibold text-ink">Upload plugin</div>
107
+ <div className="text-[11px] text-mute">
108
+ Drop a .zip that contains manifest.json + handler.py.
109
+ </div>
110
+ </div>
111
+ <button
112
+ type="button"
113
+ onClick={onClose}
114
+ disabled={busy}
115
+ className="text-mute hover:text-ink p-1 rounded disabled:opacity-50"
116
+ aria-label="Close upload dialog"
117
+ >
118
+ <X className="w-4 h-4" />
119
+ </button>
120
+ </div>
121
+
122
+ <div className="p-4 space-y-3">
123
+ <label
124
+ onDragOver={(e) => {
125
+ e.preventDefault();
126
+ setDragOver(true);
127
+ }}
128
+ onDragLeave={() => setDragOver(false)}
129
+ onDrop={onDrop}
130
+ className={`block border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${
131
+ dragOver
132
+ ? "border-accent bg-accent/5"
133
+ : "border-edge hover:border-accent/60 hover:bg-surfaceAlt"
134
+ } ${busy ? "opacity-60 pointer-events-none" : ""}`}
135
+ >
136
+ <input
137
+ ref={inputRef}
138
+ type="file"
139
+ accept=".zip,application/zip"
140
+ className="hidden"
141
+ disabled={busy}
142
+ onChange={(e) => {
143
+ const f = e.target.files?.[0];
144
+ if (f) handleFile(f);
145
+ e.target.value = "";
146
+ }}
147
+ />
148
+ {busy ? (
149
+ <div className="flex flex-col items-center gap-2 text-mute">
150
+ <Loader2 className="w-6 h-6 animate-spin" />
151
+ <span className="text-sm">Uploading and validating…</span>
152
+ </div>
153
+ ) : (
154
+ <div className="flex flex-col items-center gap-2 text-mute">
155
+ <Upload className="w-6 h-6" />
156
+ <span className="text-sm">
157
+ Drop your <span className="text-ink font-medium">.zip</span> here,
158
+ or click to browse.
159
+ </span>
160
+ <span className="text-[10px] text-mute/70">
161
+ Max 1 MB · up to 5 plugins per browser
162
+ </span>
163
+ </div>
164
+ )}
165
+ </label>
166
+
167
+ {error && (
168
+ <div className="text-[12px] text-danger panel-alt p-2 border-danger/40 whitespace-pre-line">
169
+ {error}
170
+ </div>
171
+ )}
172
+ {success && (
173
+ <div className="text-[12px] text-ok panel-alt p-2 border-ok/40">
174
+ {success}
175
+ </div>
176
+ )}
177
+
178
+ <details className="text-[11px] text-mute">
179
+ <summary className="cursor-pointer hover:text-ink">
180
+ What's in a plugin .zip?
181
+ </summary>
182
+ <div className="mt-2 space-y-2 leading-relaxed">
183
+ <p>Two files at the top level of the zip:</p>
184
+ <ul className="list-disc list-inside ml-1 space-y-1">
185
+ <li>
186
+ <span className="text-ink font-mono">manifest.json</span> —
187
+ block name, family (source/backend/algorithm/metric/sink),
188
+ color, tunable parameters.
189
+ </li>
190
+ <li>
191
+ <span className="text-ink font-mono">handler.py</span> —
192
+ defines{" "}
193
+ <span className="font-mono text-ink">
194
+ def run(inputs, params): ...
195
+ </span>
196
+ ; the subprocess that runs it can take up to 10 min, uses
197
+ ≤ 1 GB RAM, and never sees IBM secrets.
198
+ </li>
199
+ </ul>
200
+ <p>
201
+ See <span className="text-ink font-mono">PLUGIN_SDK.md</span>{" "}
202
+ in the GitHub repo for the full spec + an example.
203
+ </p>
204
+ </div>
205
+ </details>
206
+ </div>
207
+ </div>
208
+ </div>
209
+ );
210
+ }
frontend/src/lib/autoConnect.ts CHANGED
@@ -35,7 +35,13 @@
35
 
36
  import type { Edge, Node } from "@xyflow/react";
37
  import type { QNodeData } from "../components/QNode";
38
- import { NODE_BY_KIND, type NodeKind, type NodeSpec } from "./nodeCatalog";
 
 
 
 
 
 
39
 
40
  type Family = NodeSpec["family"];
41
 
@@ -98,6 +104,7 @@ export interface AutoConnectResult {
98
  export function autoConnect(
99
  nodes: Node<QNodeData>[],
100
  existingEdges: Edge[],
 
101
  ): AutoConnectResult {
102
  const warnings: string[] = [];
103
  const replacedCount = existingEdges.length;
@@ -130,11 +137,12 @@ export function autoConnect(
130
  };
131
  const unknown: Node<QNodeData>[] = [];
132
  for (const n of nodes) {
133
- const spec = NODE_BY_KIND[n.data.kind];
134
  if (!spec) {
135
  // Forward-compat: unrecognised kinds (e.g. a node kind added in a
136
- // newer build loaded via a stale share link) are preserved on the
137
- // canvas but left out of the chain rather than silently dropped.
 
138
  unknown.push(n);
139
  continue;
140
  }
@@ -263,8 +271,8 @@ export function autoConnect(
263
  for (let i = 0; i < chain.length - 1; i++) {
264
  const src = chain[i];
265
  const dst = chain[i + 1];
266
- const srcFamily = NODE_BY_KIND[src.data.kind]?.family;
267
- const dstFamily = NODE_BY_KIND[dst.data.kind]?.family;
268
  const isNoiseSidechain =
269
  srcFamily === "backend" &&
270
  dstFamily === "algorithm" &&
 
35
 
36
  import type { Edge, Node } from "@xyflow/react";
37
  import type { QNodeData } from "../components/QNode";
38
+ import {
39
+ NODE_BY_KIND,
40
+ resolveNodeSpec,
41
+ type NodeKind,
42
+ type NodeSpec,
43
+ } from "./nodeCatalog";
44
+ import type { PluginManifest } from "./api";
45
 
46
  type Family = NodeSpec["family"];
47
 
 
104
  export function autoConnect(
105
  nodes: Node<QNodeData>[],
106
  existingEdges: Edge[],
107
+ plugins: PluginManifest[] = [],
108
  ): AutoConnectResult {
109
  const warnings: string[] = [];
110
  const replacedCount = existingEdges.length;
 
137
  };
138
  const unknown: Node<QNodeData>[] = [];
139
  for (const n of nodes) {
140
+ const spec = resolveNodeSpec(n.data.kind, plugins);
141
  if (!spec) {
142
  // Forward-compat: unrecognised kinds (e.g. a node kind added in a
143
+ // newer build loaded via a stale share link, or a plugin missing
144
+ // from this browser) are preserved on the canvas but left out of
145
+ // the chain rather than silently dropped.
146
  unknown.push(n);
147
  continue;
148
  }
 
271
  for (let i = 0; i < chain.length - 1; i++) {
272
  const src = chain[i];
273
  const dst = chain[i + 1];
274
+ const srcFamily = resolveNodeSpec(src.data.kind, plugins)?.family;
275
+ const dstFamily = resolveNodeSpec(dst.data.kind, plugins)?.family;
276
  const isNoiseSidechain =
277
  srcFamily === "backend" &&
278
  dstFamily === "algorithm" &&
frontend/src/lib/nodeCatalog.ts CHANGED
@@ -322,3 +322,95 @@ export const NODE_CATALOG: NodeSpec[] = [
322
  export const NODE_BY_KIND = Object.fromEntries(
323
  NODE_CATALOG.map((n) => [n.kind, n]),
324
  ) as Record<NodeKind, NodeSpec>;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  export const NODE_BY_KIND = Object.fromEntries(
323
  NODE_CATALOG.map((n) => [n.kind, n]),
324
  ) as Record<NodeKind, NodeSpec>;
325
+
326
+ // ---------------------------------------------------------------------
327
+ // User-plugin support
328
+ // ---------------------------------------------------------------------
329
+ //
330
+ // Plugin manifests come from the backend at runtime; we synthesize a
331
+ // NodeSpec on the fly so the rest of the UI can treat them like a
332
+ // built-in block.
333
+
334
+ import { Package } from "lucide-react";
335
+ import type { PluginManifest } from "./api";
336
+
337
+ /** A NodeSpec extension marker so render code knows this is user-
338
+ * uploaded (renders generic icon + first-letter badge with the
339
+ * plugin's chosen color, and shows a "delete" affordance). */
340
+ export interface PluginNodeSpec extends NodeSpec {
341
+ isPlugin: true;
342
+ /** First letter or two of the label, shown as a colored badge. */
343
+ initials: string;
344
+ /** Plugin's chosen accent colour (raw hex). */
345
+ pluginColor: string;
346
+ }
347
+
348
+ /** Build a NodeSpec from a backend-served plugin manifest. The
349
+ * resulting spec slots into NODE_CATALOG-shaped consumers without
350
+ * conditionals at the call site — only render code that wants the
351
+ * plugin badge needs to check ``isPlugin``. */
352
+ export function synthesizePluginSpec(m: PluginManifest): PluginNodeSpec {
353
+ const initials = m.label
354
+ .replace(/[^A-Za-z0-9]/g, "")
355
+ .slice(0, 2)
356
+ .toUpperCase() || "?";
357
+ // We deliberately don't carry the plugin's colour through the
358
+ // existing Tailwind ``accent``/``accentRing`` slots (those expect
359
+ // class names); instead the QNode render uses ``pluginColor``
360
+ // directly as an inline style on the badge.
361
+ return {
362
+ kind: m.kind as NodeKind,
363
+ label: m.label,
364
+ family: m.family,
365
+ tagline: m.tagline,
366
+ description: m.description || `User plugin (${m.kind}).`,
367
+ icon: Package,
368
+ accent: "text-ink",
369
+ accentRing: "border-edge",
370
+ // Plugin manifest params share the same shape as NodeParamSpec.
371
+ params: m.params.length > 0 ? (m.params as NodeParamSpec[]) : undefined,
372
+ defaultData: {},
373
+ isPlugin: true,
374
+ initials,
375
+ pluginColor: m.color,
376
+ };
377
+ }
378
+
379
+ /** Look up the spec for a node kind, falling back to a synthesized
380
+ * plugin spec if it's user-uploaded. Returns undefined for unknown
381
+ * kinds (so callers can show an "orphan plugin" state — e.g. the
382
+ * user opened a share-link that references a plugin they don't
383
+ * have installed). */
384
+ export function resolveNodeSpec(
385
+ kind: string,
386
+ plugins: PluginManifest[],
387
+ ): NodeSpec | PluginNodeSpec | undefined {
388
+ const builtin = NODE_BY_KIND[kind as NodeKind];
389
+ if (builtin) return builtin;
390
+ const m = plugins.find((p) => p.kind === kind);
391
+ return m ? synthesizePluginSpec(m) : undefined;
392
+ }
393
+
394
+ /** Same as resolveNodeSpec but never returns undefined — produces a
395
+ * best-effort "missing plugin" placeholder so render code doesn't
396
+ * have to handle nulls. */
397
+ export function resolveNodeSpecOrPlaceholder(
398
+ kind: string,
399
+ plugins: PluginManifest[],
400
+ ): NodeSpec | PluginNodeSpec {
401
+ const found = resolveNodeSpec(kind, plugins);
402
+ if (found) return found;
403
+ return {
404
+ kind: kind as NodeKind,
405
+ label: kind,
406
+ family: "algorithm",
407
+ tagline: "missing plugin",
408
+ description: `No plugin with kind="${kind}" is installed in this browser.`,
409
+ icon: Package,
410
+ accent: "text-danger",
411
+ accentRing: "border-danger/40",
412
+ isPlugin: true,
413
+ initials: "?",
414
+ pluginColor: "#dc2626",
415
+ } as PluginNodeSpec;
416
+ }