@particle-academy/fancy-flow 0.45.0 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +29 -0
  2. package/dist/{ConfigFieldRenderer-Dzy4f6rG.d.cts → ConfigFieldRenderer-Cyir8-B8.d.cts} +2 -2
  3. package/dist/{ConfigFieldRenderer-WqJr-td_.d.ts → ConfigFieldRenderer-iMkZj0VK.d.ts} +2 -2
  4. package/dist/{FlowViewer-BbbUJe2b.d.cts → FlowViewer-CY3_vHSg.d.cts} +1 -1
  5. package/dist/{FlowViewer-csuaTL5t.d.ts → FlowViewer-DGW6t-80.d.ts} +1 -1
  6. package/dist/{capabilities-Brn74URS.d.ts → capabilities-DMUhnyZD.d.ts} +1 -1
  7. package/dist/{capabilities-CYCeIx6I.d.cts → capabilities-Dmd26aAs.d.cts} +1 -1
  8. package/dist/chunk-BHM5HGXH.js +79 -0
  9. package/dist/chunk-BHM5HGXH.js.map +1 -0
  10. package/dist/chunk-DR3GWVDG.js +196 -0
  11. package/dist/chunk-DR3GWVDG.js.map +1 -0
  12. package/dist/{chunk-3BKU4SQZ.js → chunk-ISXRQELT.js} +3 -4
  13. package/dist/chunk-ISXRQELT.js.map +1 -0
  14. package/dist/{chunk-OWENS2H5.js → chunk-NDEX655E.js} +1603 -36
  15. package/dist/chunk-NDEX655E.js.map +1 -0
  16. package/dist/{chunk-QZTGV3ZL.js → chunk-QVFVL5LQ.js} +3 -3
  17. package/dist/{chunk-QZTGV3ZL.js.map → chunk-QVFVL5LQ.js.map} +1 -1
  18. package/dist/{chunk-DHUFUDEX.js → chunk-Z2GRNYR2.js} +7 -6
  19. package/dist/chunk-Z2GRNYR2.js.map +1 -0
  20. package/dist/{chunk-A6RFLGWV.js → chunk-ZKJJWBDJ.js} +3 -5
  21. package/dist/chunk-ZKJJWBDJ.js.map +1 -0
  22. package/dist/durable/index.d.cts +490 -0
  23. package/dist/durable/index.d.ts +490 -0
  24. package/dist/durable.cjs +10991 -0
  25. package/dist/durable.cjs.map +1 -0
  26. package/dist/durable.js +552 -0
  27. package/dist/durable.js.map +1 -0
  28. package/dist/engine.cjs +10223 -47
  29. package/dist/engine.cjs.map +1 -1
  30. package/dist/engine.d.cts +9 -7
  31. package/dist/engine.d.ts +9 -7
  32. package/dist/engine.js +4 -6
  33. package/dist/engine.js.map +1 -1
  34. package/dist/fields/react-fancy.d.cts +4 -3
  35. package/dist/fields/react-fancy.d.ts +4 -3
  36. package/dist/index.cjs +336 -194
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +12 -10
  39. package/dist/index.d.ts +12 -10
  40. package/dist/index.js +15 -93
  41. package/dist/index.js.map +1 -1
  42. package/dist/layout/index.d.cts +1 -1
  43. package/dist/layout/index.d.ts +1 -1
  44. package/dist/llm/prism.d.cts +2 -2
  45. package/dist/llm/prism.d.ts +2 -2
  46. package/dist/llm/vercel-ai.d.cts +2 -2
  47. package/dist/llm/vercel-ai.d.ts +2 -2
  48. package/dist/pause-9iT4tCEV.d.cts +96 -0
  49. package/dist/pause-9iT4tCEV.d.ts +96 -0
  50. package/dist/registry/index.d.cts +7 -6
  51. package/dist/registry/index.d.ts +7 -6
  52. package/dist/{registry-Budds73w.d.cts → registry-Bt55f63_.d.ts} +21 -2
  53. package/dist/{registry-D0I20HJ3.d.ts → registry-CkcSwmfR.d.cts} +21 -2
  54. package/dist/registry.cjs +3961 -3821
  55. package/dist/registry.cjs.map +1 -1
  56. package/dist/registry.js +3 -6
  57. package/dist/{run-cohort-CV7EcwGG.d.ts → run-cohort-Cyeny2Uu.d.ts} +3 -34
  58. package/dist/{run-cohort-DitsaYgS.d.cts → run-cohort-DdPPowJ3.d.cts} +3 -34
  59. package/dist/run-flow-1KiXhy59.d.cts +55 -0
  60. package/dist/run-flow-CQvTDBYk.d.ts +55 -0
  61. package/dist/runtime/index.d.cts +5 -3
  62. package/dist/runtime/index.d.ts +5 -3
  63. package/dist/runtime.cjs +1712 -430
  64. package/dist/runtime.cjs.map +1 -1
  65. package/dist/runtime.js +5 -6
  66. package/dist/schema/index.d.cts +1 -1
  67. package/dist/schema/index.d.ts +1 -1
  68. package/dist/schema.cjs +10369 -24
  69. package/dist/schema.cjs.map +1 -1
  70. package/dist/schema.js +4 -3
  71. package/dist/screens.cjs +1366 -38
  72. package/dist/screens.cjs.map +1 -1
  73. package/dist/screens.d.cts +2 -2
  74. package/dist/screens.d.ts +2 -2
  75. package/dist/screens.js +5 -8
  76. package/dist/screens.js.map +1 -1
  77. package/dist/{types-D6ZSKBly.d.ts → types--S2Kzx7w.d.cts} +3 -97
  78. package/dist/{types-nQOA8jpk.d.cts → types-ChkCRonF.d.ts} +3 -97
  79. package/dist/types-Jx1TwehV.d.cts +247 -0
  80. package/dist/types-Jx1TwehV.d.ts +247 -0
  81. package/dist/ux.cjs +10363 -2
  82. package/dist/ux.cjs.map +1 -1
  83. package/dist/ux.d.cts +3 -2
  84. package/dist/ux.d.ts +3 -2
  85. package/dist/ux.js +3 -1
  86. package/dist/ux.js.map +1 -1
  87. package/package.json +17 -3
  88. package/dist/chunk-3BKU4SQZ.js.map +0 -1
  89. package/dist/chunk-A6RFLGWV.js.map +0 -1
  90. package/dist/chunk-DHUFUDEX.js.map +0 -1
  91. package/dist/chunk-OWENS2H5.js.map +0 -1
  92. package/dist/chunk-PVROYW7C.js +0 -187
  93. package/dist/chunk-PVROYW7C.js.map +0 -1
  94. package/dist/chunk-TITD5W4Y.js +0 -26
  95. package/dist/chunk-TITD5W4Y.js.map +0 -1
  96. package/dist/chunk-VLATLVGH.js +0 -158
  97. package/dist/chunk-VLATLVGH.js.map +0 -1
  98. package/dist/chunk-WBXGZVLB.js +0 -1268
  99. package/dist/chunk-WBXGZVLB.js.map +0 -1
  100. package/dist/types-CMSrWVYM.d.cts +0 -109
  101. package/dist/types-CMSrWVYM.d.ts +0 -109
@@ -1,7 +1,27 @@
1
+ import { RichInputPreview } from './chunk-F5RPRB7A.js';
2
+ import { getLlmClient, getWorkflowResolver, isResolutionFailure } from './chunk-USL4FMFU.js';
3
+ import ReactExports, { createContext, forwardRef, memo, useMemo, useState, useRef, useEffect, useCallback, useContext, createElement, useSyncExternalStore, useDebugValue, useLayoutEffect } from 'react';
1
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import ReactExports, { createContext, forwardRef, memo, useMemo, useState, useRef, useEffect, useCallback, useContext, useSyncExternalStore, useDebugValue, useLayoutEffect } from 'react';
3
5
  import { createPortal } from 'react-dom';
4
6
 
7
+ // node_modules/classcat/index.js
8
+ function cc(names) {
9
+ if (typeof names === "string" || typeof names === "number") return "" + names;
10
+ let out = "";
11
+ if (Array.isArray(names)) {
12
+ for (let i = 0, tmp; i < names.length; i++) {
13
+ if ((tmp = cc(names[i])) !== "") {
14
+ out += (out && " ") + tmp;
15
+ }
16
+ }
17
+ } else {
18
+ for (let k in names) {
19
+ if (names[k]) out += (out && " ") + k;
20
+ }
21
+ }
22
+ return out;
23
+ }
24
+
5
25
  // node_modules/d3-dispatch/src/dispatch.js
6
26
  var noop = { value: () => {
7
27
  } };
@@ -973,7 +993,7 @@ function defaultTouchable() {
973
993
  return navigator.maxTouchPoints || "ontouchstart" in this;
974
994
  }
975
995
  function drag_default() {
976
- var filter2 = defaultFilter, container = defaultContainer, subject = defaultSubject, touchable = defaultTouchable, gestures = {}, listeners = dispatch_default("start", "drag", "end"), active = 0, mousedownx, mousedowny, mousemoving, touchending, clickDistance2 = 0;
996
+ var filter2 = defaultFilter, container = defaultContainer, subject = defaultSubject, touchable = defaultTouchable, gestures = {}, listeners2 = dispatch_default("start", "drag", "end"), active = 0, mousedownx, mousedowny, mousemoving, touchending, clickDistance2 = 0;
977
997
  function drag(selection2) {
978
998
  selection2.on("mousedown.drag", mousedowned).filter(touchable).on("touchstart.drag", touchstarted).on("touchmove.drag", touchmoved, nonpassive).on("touchend.drag touchcancel.drag", touchended).style("touch-action", "none").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
979
999
  }
@@ -1036,7 +1056,7 @@ function drag_default() {
1036
1056
  }
1037
1057
  }
1038
1058
  function beforestart(that, container2, event, d, identifier, touch) {
1039
- var dispatch2 = listeners.copy(), p = pointer_default(touch || event, container2), dx, dy, s;
1059
+ var dispatch2 = listeners2.copy(), p = pointer_default(touch || event, container2), dx, dy, s;
1040
1060
  if ((s = subject.call(that, new DragEvent("beforestart", {
1041
1061
  sourceEvent: event,
1042
1062
  target: drag,
@@ -1095,8 +1115,8 @@ function drag_default() {
1095
1115
  return arguments.length ? (touchable = typeof _ === "function" ? _ : constant_default2(!!_), drag) : touchable;
1096
1116
  };
1097
1117
  drag.on = function() {
1098
- var value = listeners.on.apply(listeners, arguments);
1099
- return value === listeners ? drag : value;
1118
+ var value = listeners2.on.apply(listeners2, arguments);
1119
+ return value === listeners2 ? drag : value;
1100
1120
  };
1101
1121
  drag.clickDistance = function(_) {
1102
1122
  return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
@@ -2650,7 +2670,7 @@ function defaultConstrain(transform2, extent, translateExtent) {
2650
2670
  );
2651
2671
  }
2652
2672
  function zoom_default2() {
2653
- var filter2 = defaultFilter2, extent = defaultExtent, constrain = defaultConstrain, wheelDelta2 = defaultWheelDelta, touchable = defaultTouchable2, scaleExtent = [0, Infinity], translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]], duration = 250, interpolate = zoom_default, listeners = dispatch_default("start", "zoom", "end"), touchstarting, touchfirst, touchending, touchDelay = 500, wheelDelay = 150, clickDistance2 = 0, tapDistance = 10;
2673
+ var filter2 = defaultFilter2, extent = defaultExtent, constrain = defaultConstrain, wheelDelta2 = defaultWheelDelta, touchable = defaultTouchable2, scaleExtent = [0, Infinity], translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]], duration = 250, interpolate = zoom_default, listeners2 = dispatch_default("start", "zoom", "end"), touchstarting, touchfirst, touchending, touchDelay = 500, wheelDelay = 150, clickDistance2 = 0, tapDistance = 10;
2654
2674
  function zoom(selection2) {
2655
2675
  selection2.property("__zoom", defaultTransform).on("wheel.zoom", wheeled, { passive: false }).on("mousedown.zoom", mousedowned).on("dblclick.zoom", dblclicked).filter(touchable).on("touchstart.zoom", touchstarted).on("touchmove.zoom", touchmoved).on("touchend.zoom touchcancel.zoom", touchended).style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
2656
2676
  }
@@ -2762,14 +2782,14 @@ function zoom_default2() {
2762
2782
  },
2763
2783
  emit: function(type) {
2764
2784
  var d = select_default2(this.that).datum();
2765
- listeners.call(
2785
+ listeners2.call(
2766
2786
  type,
2767
2787
  this.that,
2768
2788
  new ZoomEvent(type, {
2769
2789
  sourceEvent: this.sourceEvent,
2770
2790
  target: zoom,
2771
2791
  transform: this.that.__zoom,
2772
- dispatch: listeners
2792
+ dispatch: listeners2
2773
2793
  }),
2774
2794
  d
2775
2795
  );
@@ -2919,8 +2939,8 @@ function zoom_default2() {
2919
2939
  return arguments.length ? (interpolate = _, zoom) : interpolate;
2920
2940
  };
2921
2941
  zoom.on = function() {
2922
- var value = listeners.on.apply(listeners, arguments);
2923
- return value === listeners ? zoom : value;
2942
+ var value = listeners2.on.apply(listeners2, arguments);
2943
+ return value === listeners2 ? zoom : value;
2924
2944
  };
2925
2945
  zoom.clickDistance = function(_) {
2926
2946
  return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
@@ -5591,24 +5611,6 @@ function XYResizer({ domNode, nodeId, getStoreItems, onChange, onEnd }) {
5591
5611
  destroy
5592
5612
  };
5593
5613
  }
5594
-
5595
- // node_modules/classcat/index.js
5596
- function cc(names) {
5597
- if (typeof names === "string" || typeof names === "number") return "" + names;
5598
- let out = "";
5599
- if (Array.isArray(names)) {
5600
- for (let i = 0, tmp; i < names.length; i++) {
5601
- if ((tmp = cc(names[i])) !== "") {
5602
- out += (out && " ") + tmp;
5603
- }
5604
- }
5605
- } else {
5606
- for (let k in names) {
5607
- if (names[k]) out += (out && " ") + k;
5608
- }
5609
- }
5610
- return out;
5611
- }
5612
5614
  function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector2, isEqual) {
5613
5615
  const instRef = useRef(null);
5614
5616
  let inst;
@@ -5669,20 +5671,20 @@ var use_sync_external_store_with_selector_default = { useSyncExternalStoreWithSe
5669
5671
  // node_modules/zustand/esm/vanilla.mjs
5670
5672
  var createStoreImpl = (createState) => {
5671
5673
  let state;
5672
- const listeners = /* @__PURE__ */ new Set();
5674
+ const listeners2 = /* @__PURE__ */ new Set();
5673
5675
  const setState = (partial, replace) => {
5674
5676
  const nextState = typeof partial === "function" ? partial(state) : partial;
5675
5677
  if (!Object.is(nextState, state)) {
5676
5678
  const previousState = state;
5677
5679
  state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
5678
- listeners.forEach((listener) => listener(state, previousState));
5680
+ listeners2.forEach((listener) => listener(state, previousState));
5679
5681
  }
5680
5682
  };
5681
5683
  const getState = () => state;
5682
5684
  const getInitialState2 = () => initialState;
5683
5685
  const subscribe = (listener) => {
5684
- listeners.add(listener);
5685
- return () => listeners.delete(listener);
5686
+ listeners2.add(listener);
5687
+ return () => listeners2.delete(listener);
5686
5688
  };
5687
5689
  const destroy = () => {
5688
5690
  if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
@@ -5690,7 +5692,7 @@ var createStoreImpl = (createState) => {
5690
5692
  "[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
5691
5693
  );
5692
5694
  }
5693
- listeners.clear();
5695
+ listeners2.clear();
5694
5696
  };
5695
5697
  const api = { setState, getState, getInitialState: getInitialState2, subscribe, destroy };
5696
5698
  const initialState = state = createState(setState, getState, api);
@@ -9035,7 +9037,1572 @@ function NodeToolbar({ nodeId, children: children2, className, style: style2, is
9035
9037
  };
9036
9038
  return jsx(NodeToolbarPortal, { children: jsx("div", { style: wrapperStyle2, className: cc(["react-flow__node-toolbar", className]), ...rest, "data-id": nodesArray.reduce((acc, node) => `${acc}${node.id} `, "").trim(), children: children2 }) });
9037
9039
  }
9040
+ var FlowEditorContext = createContext(null);
9041
+ var FlowEditorProvider = FlowEditorContext.Provider;
9042
+ function useFlowEditor() {
9043
+ const api = useContext(FlowEditorContext);
9044
+ if (api === null) {
9045
+ throw new Error("useFlowEditor() must be called inside <FlowEditor>.");
9046
+ }
9047
+ return api;
9048
+ }
9049
+ function useFlowEditorOptional() {
9050
+ return useContext(FlowEditorContext);
9051
+ }
9052
+ var NOTE_COLORS = {
9053
+ amber: { bg: "rgba(234, 179, 8, 0.14)", border: "rgba(234, 179, 8, 0.55)", title: "#a16207" },
9054
+ sky: { bg: "rgba(14, 165, 233, 0.12)", border: "rgba(14, 165, 233, 0.5)", title: "#0369a1" },
9055
+ violet: { bg: "rgba(139, 92, 246, 0.13)", border: "rgba(139, 92, 246, 0.5)", title: "#6d28d9" },
9056
+ emerald: { bg: "rgba(16, 185, 129, 0.13)", border: "rgba(16, 185, 129, 0.5)", title: "#047857" },
9057
+ rose: { bg: "rgba(244, 63, 94, 0.12)", border: "rgba(244, 63, 94, 0.5)", title: "#be123c" },
9058
+ slate: { bg: "rgba(100, 116, 139, 0.12)", border: "rgba(100, 116, 139, 0.5)", title: "#475569" }
9059
+ };
9060
+ function coerceColor(v) {
9061
+ return typeof v === "string" && v in NOTE_COLORS ? v : "amber";
9062
+ }
9063
+ function NoteNodeInner(props) {
9064
+ const data = props.data;
9065
+ const config = data.config ?? {};
9066
+ const api = useFlowEditorOptional();
9067
+ const hasConfigText = typeof config.text === "string" && config.text.length > 0;
9068
+ const text = hasConfigText ? String(config.text) : typeof data.body === "string" ? data.body : typeof data.text === "string" ? data.text : "";
9069
+ const title = typeof config.title === "string" && config.title || (!hasConfigText && typeof data.body === "string" && typeof data.label === "string" ? data.label : "");
9070
+ const skin = NOTE_COLORS[coerceColor(config.color)];
9071
+ const [editing, setEditing] = useState(false);
9072
+ const [draft, setDraft] = useState(text);
9073
+ const areaRef = useRef(null);
9074
+ useEffect(() => {
9075
+ if (editing && areaRef.current) {
9076
+ const el = areaRef.current;
9077
+ el.focus();
9078
+ el.setSelectionRange(el.value.length, el.value.length);
9079
+ }
9080
+ }, [editing]);
9081
+ const commit = () => {
9082
+ setEditing(false);
9083
+ if (!api || draft === text) return;
9084
+ const current = api.nodes.find((n) => n.id === props.id);
9085
+ if (!current) return;
9086
+ api.updateNode({
9087
+ ...current,
9088
+ data: { ...current.data, config: { ...config, text: draft } }
9089
+ });
9090
+ };
9091
+ return /* @__PURE__ */ jsxs(
9092
+ "div",
9093
+ {
9094
+ className: ["ff-note", props.selected ? "ff-note--selected" : ""].filter(Boolean).join(" "),
9095
+ style: { background: skin.bg, borderColor: skin.border },
9096
+ onDoubleClick: api ? () => {
9097
+ setDraft(text);
9098
+ setEditing(true);
9099
+ } : void 0,
9100
+ children: [
9101
+ /* @__PURE__ */ jsx(NodeResizer, { isVisible: props.selected ?? false, color: skin.border, minWidth: 140, minHeight: 80 }),
9102
+ title && /* @__PURE__ */ jsx("div", { className: "ff-note__title", style: { color: skin.title }, children: title }),
9103
+ editing ? /* @__PURE__ */ jsx(
9104
+ "textarea",
9105
+ {
9106
+ ref: areaRef,
9107
+ className: "ff-note__input nodrag nowheel",
9108
+ value: draft,
9109
+ onChange: (e) => setDraft(e.target.value),
9110
+ onBlur: commit,
9111
+ onKeyDown: (e) => {
9112
+ if (e.key === "Escape") setEditing(false);
9113
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) commit();
9114
+ }
9115
+ }
9116
+ ) : /* @__PURE__ */ jsx("div", { className: "ff-note__body", children: text || /* @__PURE__ */ jsx("span", { className: "ff-note__placeholder", children: api ? "Double-click to write a note\u2026" : "Note" }) })
9117
+ ]
9118
+ }
9119
+ );
9120
+ }
9121
+ var NoteNode = memo(NoteNodeInner);
9122
+
9123
+ // src/registry/llm-router.ts
9124
+ function declaredRoutes(config) {
9125
+ const raw = config.routes;
9126
+ if (!Array.isArray(raw)) return [];
9127
+ return raw.map((r) => ({ port: String(r?.port ?? "").trim(), description: r?.description })).filter((r) => r.port !== "");
9128
+ }
9129
+ function resolveFallbackPort(routes, fallbackEnabled) {
9130
+ if (fallbackEnabled) return "fallback";
9131
+ return routes[0]?.port ?? "out";
9132
+ }
9133
+ var llmRouterExecutor = async (ctx) => {
9134
+ const config = ctx.node.data?.config ?? {};
9135
+ const routes = declaredRoutes(config);
9136
+ if (routes.length === 0) {
9137
+ ctx.abort("llm_router has no routes configured");
9138
+ }
9139
+ const client = getLlmClient();
9140
+ if (!client) {
9141
+ ctx.abort(
9142
+ "No LLM client registered. Call registerLlmClient() with your provider adapter \u2014 fancy-flow ships the routing, not the model call."
9143
+ );
9144
+ }
9145
+ const fallbackEnabled = config.fallback !== false;
9146
+ const choice = await client.chooseRoute({
9147
+ system: typeof config.system === "string" ? config.system : void 0,
9148
+ prompt: String(config.prompt ?? ctx.inputs ?? ""),
9149
+ routes,
9150
+ provider: typeof config.provider === "string" ? config.provider : void 0,
9151
+ model: typeof config.model === "string" ? config.model : void 0,
9152
+ credential: typeof config.credential === "string" ? config.credential : void 0
9153
+ });
9154
+ const offered = new Set(routes.map((r) => r.port));
9155
+ let port = choice?.port ?? "";
9156
+ let reason = choice?.reason;
9157
+ if (!offered.has(port)) {
9158
+ const safe = resolveFallbackPort(routes, fallbackEnabled);
9159
+ ctx.emit({
9160
+ type: "log",
9161
+ nodeId: ctx.node.id,
9162
+ level: "warn",
9163
+ message: `llm_router: model returned "${port || "(nothing)"}", which is not a declared route. Routing to "${safe}".`
9164
+ });
9165
+ reason = reason ?? `unrecognised route "${port}"`;
9166
+ port = safe;
9167
+ }
9168
+ return { __port: port, value: { route: port, reason, input: ctx.inputs } };
9169
+ };
9170
+
9171
+ // src/registry/ports.ts
9172
+ function resolvePortSpec(spec, config) {
9173
+ if (spec === void 0) return void 0;
9174
+ if (typeof spec !== "function") return spec;
9175
+ try {
9176
+ const resolved = spec(config);
9177
+ return Array.isArray(resolved) ? resolved : void 0;
9178
+ } catch {
9179
+ return void 0;
9180
+ }
9181
+ }
9182
+ function nodeConfig(node) {
9183
+ return node.data?.config ?? {};
9184
+ }
9185
+ function resolveNodePorts(node, kind) {
9186
+ const config = nodeConfig(node);
9187
+ const data = node.data;
9188
+ return {
9189
+ inputs: data?.inputs ?? resolvePortSpec(kind?.inputs, config),
9190
+ outputs: data?.outputs ?? resolvePortSpec(kind?.outputs, config)
9191
+ };
9192
+ }
9193
+
9194
+ // src/runtime/run-identity.ts
9195
+ function escapeSegment(value) {
9196
+ return value.replace(/%/g, "%25").replace(/\//g, "%2F").replace(/#/g, "%23");
9197
+ }
9198
+ function renderSegment(value, occurrence) {
9199
+ const escaped = escapeSegment(value);
9200
+ return occurrence === void 0 || occurrence === null ? escaped : `${escaped}#${occurrence}`;
9201
+ }
9202
+ function instant(value) {
9203
+ const ms = Date.parse(value);
9204
+ if (Number.isNaN(ms)) {
9205
+ throw new Error(
9206
+ `RunIdentity: firstAttemptAt is not a parseable timestamp: ${JSON.stringify(value)}`
9207
+ );
9208
+ }
9209
+ return ms;
9210
+ }
9211
+ var RunIdentity = class _RunIdentity {
9212
+ constructor(runKey, path = [], attempt = 1, firstAttemptAt = (/* @__PURE__ */ new Date()).toISOString()) {
9213
+ if (!runKey || runKey.trim() === "") {
9214
+ throw new Error("RunIdentity: runKey must be a non-empty string.");
9215
+ }
9216
+ this.runKey = runKey;
9217
+ this.path = Object.freeze([...path]);
9218
+ this.attempt = Math.max(1, Math.trunc(attempt));
9219
+ this.firstAttemptAt = firstAttemptAt;
9220
+ Object.freeze(this);
9221
+ }
9222
+ /**
9223
+ * The identity of one execution of one node — stable across retries of that
9224
+ * execution, distinct from every other execution of the same node.
9225
+ *
9226
+ * Pass `occurrence` when an executor runs the same node more than once at the
9227
+ * same level (a loop body, one item of a fan-out it drives itself).
9228
+ */
9229
+ stepKey(nodeId, occurrence) {
9230
+ return `${this.runKey}:${[...this.path, renderSegment(nodeId, occurrence)].join("/")}`;
9231
+ }
9232
+ /**
9233
+ * A child identity for work nested inside this step.
9234
+ *
9235
+ * `subflow` pushes the invoking node's id, so a node inside the child graph
9236
+ * cannot collide with a same-named node in the parent. Attempt and
9237
+ * `firstAttemptAt` are carried down unchanged: the nested work happens inside
9238
+ * this step's attempt, and shares its clock.
9239
+ */
9240
+ descend(segment, occurrence) {
9241
+ return new _RunIdentity(
9242
+ this.runKey,
9243
+ [...this.path, renderSegment(segment, occurrence)],
9244
+ this.attempt,
9245
+ this.firstAttemptAt
9246
+ );
9247
+ }
9248
+ /** A copy on a different attempt, first-attempt clock preserved. */
9249
+ withAttempt(attempt, firstAttemptAt) {
9250
+ return new _RunIdentity(
9251
+ this.runKey,
9252
+ this.path,
9253
+ attempt,
9254
+ firstAttemptAt ?? this.firstAttemptAt
9255
+ );
9256
+ }
9257
+ /**
9258
+ * May this attempt reuse the step key and still be deduplicated?
9259
+ *
9260
+ * Providers forget idempotency keys — Stripe after 24 hours. Past that
9261
+ * window, resending the key creates a second charge and sending a fresh one
9262
+ * creates a second charge, so **the caller must refuse rather than pick
9263
+ * between them**: a loud stuck run beats a silent double write.
9264
+ *
9265
+ * `true` on attempt 1 whatever the elapsed time — nothing was sent on an
9266
+ * earlier attempt, so there is nothing for the provider to have forgotten.
9267
+ * That is what lets a run park on a human gate for a week and then write.
9268
+ *
9269
+ * `windowSeconds: null` means the provider does not expire keys. `0` means
9270
+ * it does not dedupe at all, so no retry may reuse a key — it is a real
9271
+ * window, not an absent one, and the two must not be conflated: reading `0`
9272
+ * as `null` turns "this provider does not dedupe" into "this provider
9273
+ * dedupes forever", which is the more dangerous of the two by a distance.
9274
+ */
9275
+ isReplaySafe(windowSeconds, now2 = /* @__PURE__ */ new Date()) {
9276
+ if (this.attempt <= 1) return true;
9277
+ if (windowSeconds === null || windowSeconds === void 0) return true;
9278
+ if (windowSeconds <= 0) return false;
9279
+ const nowMs = typeof now2 === "string" ? instant(now2) : now2.getTime();
9280
+ const elapsedSeconds = Math.max(0, (nowMs - instant(this.firstAttemptAt)) / 1e3);
9281
+ return elapsedSeconds <= windowSeconds;
9282
+ }
9283
+ toJSON() {
9284
+ return {
9285
+ runKey: this.runKey,
9286
+ path: [...this.path],
9287
+ attempt: this.attempt,
9288
+ firstAttemptAt: this.firstAttemptAt
9289
+ };
9290
+ }
9291
+ /** Rebuild from a queue payload. */
9292
+ static from(value) {
9293
+ if (value instanceof _RunIdentity) return value;
9294
+ if (typeof value === "string") return new _RunIdentity(value);
9295
+ return new _RunIdentity(
9296
+ value.runKey,
9297
+ value.path ?? [],
9298
+ value.attempt ?? 1,
9299
+ value.firstAttemptAt ?? (/* @__PURE__ */ new Date()).toISOString()
9300
+ );
9301
+ }
9302
+ };
9303
+
9304
+ // src/runtime/run-flow.ts
9305
+ async function runFlow(graph, executors, onEvent = () => {
9306
+ }, options = {}) {
9307
+ const { signal, initialInputs = {}, timeoutMs, depth = 0, resumeOutputs = {} } = options;
9308
+ const run = options.run === void 0 ? void 0 : RunIdentity.from(options.run);
9309
+ const outputs = {};
9310
+ const portValues = /* @__PURE__ */ new Map();
9311
+ const completed = /* @__PURE__ */ new Set();
9312
+ const errors = [];
9313
+ const order = topoSort(graph);
9314
+ if (order === null) {
9315
+ const msg = "Cycle detected in flow graph \u2014 aborting.";
9316
+ onEvent({ type: "run-error", error: msg });
9317
+ return { ok: false, outputs, error: msg };
9318
+ }
9319
+ const incomingByNode = indexIncoming(graph.edges);
9320
+ const timer2 = timeoutMs ? setTimeout(() => errors.push(`Run timed out after ${timeoutMs}ms`), timeoutMs) : null;
9321
+ onEvent({ type: "run-start" });
9322
+ try {
9323
+ for (const node of order) {
9324
+ if (signal?.aborted) throw new Error("aborted");
9325
+ if (errors.length) break;
9326
+ if (Object.prototype.hasOwnProperty.call(resumeOutputs, node.id)) {
9327
+ const stored = resumeOutputs[node.id];
9328
+ outputs[node.id] = stored;
9329
+ const activated = activatedPorts(node, stored);
9330
+ for (const portId of activated.ports) {
9331
+ portValues.set(`${node.id}:${portId}`, activated.value);
9332
+ onEvent({ type: "node-output", nodeId: node.id, portId, value: activated.value });
9333
+ }
9334
+ completed.add(node.id);
9335
+ onEvent({ type: "node-status", nodeId: node.id, status: "done", text: "resumed" });
9336
+ continue;
9337
+ }
9338
+ const incoming = incomingByNode.get(node.id) ?? [];
9339
+ if (incoming.length > 0) {
9340
+ const anyActive = incoming.some((e) => portValues.has(`${e.source}:${e.sourceHandle ?? "out"}`));
9341
+ if (!anyActive) {
9342
+ onEvent({ type: "node-status", nodeId: node.id, status: "idle", text: "skipped" });
9343
+ continue;
9344
+ }
9345
+ }
9346
+ const visualKind = getNodeKind(node.type ?? "");
9347
+ const isLayout = visualKind?.category === "layout";
9348
+ const isAnnotation = node.type === "note" || visualKind?.category === "annotation";
9349
+ if (isLayout || isAnnotation) {
9350
+ onEvent({
9351
+ type: "node-status",
9352
+ nodeId: node.id,
9353
+ status: "idle",
9354
+ text: isLayout ? "lane" : "annotation"
9355
+ });
9356
+ continue;
9357
+ }
9358
+ onEvent({ type: "node-status", nodeId: node.id, status: "running" });
9359
+ const inputs = collectInputs(node, incoming, portValues, initialInputs);
9360
+ const exec = pickExecutor(executors, node);
9361
+ if (!exec) {
9362
+ const msg = `No executor registered for kind=${node.type}`;
9363
+ errors.push(msg);
9364
+ onEvent({ type: "node-status", nodeId: node.id, status: "error", text: msg });
9365
+ onEvent({ type: "log", nodeId: node.id, level: "error", message: msg });
9366
+ break;
9367
+ }
9368
+ try {
9369
+ const result = await Promise.resolve(
9370
+ exec({
9371
+ node,
9372
+ inputs,
9373
+ abort: (reason) => {
9374
+ throw new Error(reason ?? "aborted");
9375
+ },
9376
+ emit: onEvent,
9377
+ depth,
9378
+ run
9379
+ })
9380
+ );
9381
+ outputs[node.id] = result;
9382
+ const activated = activatedPorts(node, result);
9383
+ for (const portId of activated.ports) {
9384
+ portValues.set(`${node.id}:${portId}`, activated.value);
9385
+ onEvent({ type: "node-output", nodeId: node.id, portId, value: activated.value });
9386
+ }
9387
+ completed.add(node.id);
9388
+ onEvent({ type: "node-status", nodeId: node.id, status: "done" });
9389
+ } catch (e) {
9390
+ const msg = e instanceof Error ? e.message : String(e);
9391
+ errors.push(msg);
9392
+ onEvent({ type: "node-status", nodeId: node.id, status: "error", text: msg });
9393
+ onEvent({ type: "log", nodeId: node.id, level: "error", message: msg });
9394
+ break;
9395
+ }
9396
+ }
9397
+ } finally {
9398
+ if (timer2) clearTimeout(timer2);
9399
+ }
9400
+ const ok = errors.length === 0;
9401
+ onEvent({ type: "run-end", ok });
9402
+ return ok ? { ok, outputs } : { ok, outputs, error: errors[0] };
9403
+ }
9404
+ function indexIncoming(edges) {
9405
+ const map = /* @__PURE__ */ new Map();
9406
+ for (const e of edges) {
9407
+ const list = map.get(e.target) ?? [];
9408
+ list.push(e);
9409
+ map.set(e.target, list);
9410
+ }
9411
+ return map;
9412
+ }
9413
+ function topoSort(graph) {
9414
+ const inDegree = /* @__PURE__ */ new Map();
9415
+ for (const n of graph.nodes) inDegree.set(n.id, 0);
9416
+ for (const e of graph.edges) inDegree.set(e.target, (inDegree.get(e.target) ?? 0) + 1);
9417
+ const queue = [];
9418
+ for (const [id2, d] of inDegree) if (d === 0) queue.push(id2);
9419
+ const ordered = [];
9420
+ while (queue.length) {
9421
+ const id2 = queue.shift();
9422
+ ordered.push(id2);
9423
+ for (const e of graph.edges) {
9424
+ if (e.source !== id2) continue;
9425
+ const next = (inDegree.get(e.target) ?? 0) - 1;
9426
+ inDegree.set(e.target, next);
9427
+ if (next === 0) queue.push(e.target);
9428
+ }
9429
+ }
9430
+ if (ordered.length !== graph.nodes.length) return null;
9431
+ const byId = new Map(graph.nodes.map((n) => [n.id, n]));
9432
+ return ordered.map((id2) => byId.get(id2)).filter(Boolean);
9433
+ }
9434
+ function collectInputs(node, incoming, portValues, initial) {
9435
+ const inputs = { ...initial[node.id] ?? {} };
9436
+ for (const e of incoming) {
9437
+ const portId = e.targetHandle ?? "in";
9438
+ const key = `${e.source}:${e.sourceHandle ?? "out"}`;
9439
+ if (!portValues.has(key)) continue;
9440
+ inputs[portId] = portValues.get(key);
9441
+ }
9442
+ return inputs;
9443
+ }
9444
+ function pickExecutor(executors, node) {
9445
+ if (executors[node.id]) return executors[node.id];
9446
+ if (node.type && executors[node.type]) return executors[node.type];
9447
+ const kind = node.type ? getNodeKind(node.type) : null;
9448
+ if (kind) {
9449
+ for (const id2 of kindIds(kind)) {
9450
+ if (executors[id2]) return executors[id2];
9451
+ }
9452
+ }
9453
+ return executors["*"];
9454
+ }
9455
+ function activatedPorts(node, result) {
9456
+ if (result && typeof result === "object") {
9457
+ const r = result;
9458
+ if (typeof r.__port === "string") {
9459
+ return { ports: [r.__port], value: r.value };
9460
+ }
9461
+ if (typeof r.branch === "string") {
9462
+ return { ports: [r.branch], value: r.value ?? r };
9463
+ }
9464
+ }
9465
+ const kind = getNodeKind(node.data?.kind ?? node.type ?? "") ?? void 0;
9466
+ const declared = resolveNodePorts(node, kind).outputs?.map((p) => p.id);
9467
+ return { ports: declared?.length ? declared : ["out"], value: result };
9468
+ }
9469
+
9470
+ // src/registry/subflow.ts
9471
+ var DEFAULT_MAX_DEPTH = 8;
9472
+ function subflowMode(config) {
9473
+ const mode = config.mode;
9474
+ return mode === "stream" || mode === "both" ? mode : "output";
9475
+ }
9476
+ function subflowPorts(config) {
9477
+ const mode = subflowMode(config);
9478
+ const ports = [{ id: "out", label: "result" }];
9479
+ if (mode === "stream" || mode === "both") ports.unshift({ id: "stream", label: "stream" });
9480
+ return ports;
9481
+ }
9482
+ var subflowExecutor = async (ctx) => {
9483
+ const config = ctx.node.data?.config ?? {};
9484
+ const ref = String(config.workflow ?? "").trim();
9485
+ if (!ref) ctx.abort("subflow has no workflow reference configured");
9486
+ const resolver = getWorkflowResolver();
9487
+ if (!resolver) {
9488
+ ctx.abort(
9489
+ "No workflow resolver registered. Call registerWorkflowResolver() so subflow can find the workflow it references."
9490
+ );
9491
+ }
9492
+ const maxDepth = Number.isFinite(config.maxDepth) ? Number(config.maxDepth) : DEFAULT_MAX_DEPTH;
9493
+ const depth = ctx.depth ?? 0;
9494
+ if (depth + 1 > maxDepth) {
9495
+ ctx.abort(
9496
+ `subflow depth limit reached (${maxDepth}) at "${ref}" \u2014 a workflow is referencing itself, directly or through a chain.`
9497
+ );
9498
+ }
9499
+ const pinned = config.version === void 0 || config.version === "" ? void 0 : Number(config.version);
9500
+ if (pinned !== void 0 && !Number.isInteger(pinned)) {
9501
+ ctx.abort(`subflow "${ref}" has a non-integer version pin (${String(config.version)}).`);
9502
+ }
9503
+ const resolved = await resolver(ref, pinned);
9504
+ const child = isResolutionFailure(resolved) ? ctx.abort(
9505
+ resolved.reason === "version-mismatch" ? resolved.message ?? `subflow "${ref}" is pinned to version ${pinned}, but the host has ${resolved.available ?? "a different version"}.` : resolved.message ?? `subflow could not resolve workflow "${ref}"`
9506
+ ) : resolved;
9507
+ if (!child) ctx.abort(`subflow could not resolve workflow "${ref}"`);
9508
+ const mode = subflowMode(config);
9509
+ const streaming = mode === "stream" || mode === "both";
9510
+ const forward = (event) => {
9511
+ if (!streaming) return;
9512
+ const detail = event.type === "node-status" ? `${event.nodeId} ${event.status}` : event.type === "run-end" ? `finished (${event.ok ? "ok" : "failed"})` : event.type;
9513
+ ctx.emit({
9514
+ type: "log",
9515
+ nodeId: ctx.node.id,
9516
+ level: "info",
9517
+ message: `[${ref}] ${detail}`
9518
+ });
9519
+ };
9520
+ const result = await runFlow(
9521
+ child,
9522
+ config.executors ?? {},
9523
+ forward,
9524
+ {
9525
+ initialInputs: config.inputs ?? {
9526
+ // With no explicit mapping, hand the parent's inputs to the child's
9527
+ // entry points — the obvious default, and it makes the simple case
9528
+ // require no configuration at all.
9529
+ __parent: ctx.inputs
9530
+ },
9531
+ depth: depth + 1,
9532
+ // Push THIS node onto the identity path, so a node inside the child graph
9533
+ // cannot share an idempotency key with a same-named node in the parent —
9534
+ // or with the same child graph invoked from a different parent node.
9535
+ // Attempt and the first-attempt clock ride down unchanged: the child's
9536
+ // work happens inside this node's attempt.
9537
+ run: ctx.run?.descend(ctx.node.id)
9538
+ }
9539
+ );
9540
+ if (!result.ok) {
9541
+ ctx.abort(`subflow "${ref}" failed: ${result.error ?? "unknown error"}`);
9542
+ }
9543
+ if (mode === "stream") {
9544
+ return { __port: "stream", value: result.outputs };
9545
+ }
9546
+ if (mode === "both") {
9547
+ return result.outputs;
9548
+ }
9549
+ return { __port: "out", value: result.outputs };
9550
+ };
9551
+
9552
+ // src/registry/builtin.ts
9553
+ function casePorts(cases) {
9554
+ const byPort = /* @__PURE__ */ new Map();
9555
+ if (cases && typeof cases === "object" && !Array.isArray(cases)) {
9556
+ for (const [match, port] of Object.entries(cases)) {
9557
+ if (typeof port !== "string" || port === "" || port === "default") continue;
9558
+ const matches = byPort.get(port) ?? [];
9559
+ matches.push(match);
9560
+ byPort.set(port, matches);
9561
+ }
9562
+ }
9563
+ const ports = [...byPort].map(([id2, matches]) => ({
9564
+ id: id2,
9565
+ label: matches.join("|")
9566
+ }));
9567
+ return [...ports, { id: "default", label: "default" }];
9568
+ }
9569
+ function routePorts(routes, fallback) {
9570
+ const ports = [];
9571
+ const seen = /* @__PURE__ */ new Set();
9572
+ if (Array.isArray(routes)) {
9573
+ for (const route of routes) {
9574
+ const id2 = route?.port;
9575
+ if (typeof id2 !== "string" || id2.trim() === "" || seen.has(id2)) continue;
9576
+ seen.add(id2);
9577
+ ports.push({ id: id2, label: id2 });
9578
+ }
9579
+ }
9580
+ if (fallback !== false && !seen.has("fallback")) {
9581
+ ports.push({ id: "fallback", label: "fallback" });
9582
+ }
9583
+ if (ports.length === 0) ports.push({ id: "out" });
9584
+ return ports;
9585
+ }
9586
+ var HTTP_METHODS = [
9587
+ { type: "select", key: "method", label: "Method", options: [
9588
+ { value: "GET", label: "GET" },
9589
+ { value: "POST", label: "POST" },
9590
+ { value: "PUT", label: "PUT" },
9591
+ { value: "PATCH", label: "PATCH" },
9592
+ { value: "DELETE", label: "DELETE" }
9593
+ ], default: "GET", required: true }
9594
+ ];
9595
+ var KINDS = [
9596
+ // ───────────── Triggers ─────────────
9597
+ {
9598
+ name: "@particle-academy/manual_trigger",
9599
+ aliases: ["manual_trigger", "@fancy/manual_trigger"],
9600
+ category: "trigger",
9601
+ label: "Manual",
9602
+ description: "Entry point fired when the user clicks Run.",
9603
+ icon: "\u26A1",
9604
+ inputs: [],
9605
+ outputs: [{ id: "out" }]
9606
+ },
9607
+ {
9608
+ name: "@particle-academy/webhook_trigger",
9609
+ aliases: ["webhook_trigger", "@fancy/webhook_trigger"],
9610
+ category: "trigger",
9611
+ label: "Webhook",
9612
+ description: "Triggered by an inbound HTTP request to a host-provided URL.",
9613
+ icon: "\u{1F4E1}",
9614
+ inputs: [],
9615
+ outputs: [{ id: "out", label: "payload" }],
9616
+ configSchema: [
9617
+ { type: "text", key: "path", label: "Path", placeholder: "/hooks/my-flow", required: true },
9618
+ { type: "select", key: "method", label: "Method", options: [
9619
+ { value: "POST", label: "POST" },
9620
+ { value: "GET", label: "GET" }
9621
+ ], default: "POST" },
9622
+ { type: "credential", key: "secret", label: "Verifying secret", credentialType: "webhook_secret" }
9623
+ ]
9624
+ },
9625
+ {
9626
+ name: "@particle-academy/schedule_trigger",
9627
+ aliases: ["schedule_trigger", "@fancy/schedule_trigger"],
9628
+ category: "trigger",
9629
+ label: "Schedule",
9630
+ description: "Fires on a cron schedule (host-implemented).",
9631
+ icon: "\u23F1",
9632
+ inputs: [],
9633
+ outputs: [{ id: "out" }],
9634
+ configSchema: [
9635
+ {
9636
+ type: "text",
9637
+ key: "cron",
9638
+ label: "Cron",
9639
+ placeholder: "*/5 * * * *",
9640
+ required: true,
9641
+ description: "Standard 5-field cron expression."
9642
+ },
9643
+ { type: "text", key: "timezone", label: "Timezone", placeholder: "UTC", default: "UTC" }
9644
+ ]
9645
+ },
9646
+ {
9647
+ name: "@particle-academy/user_input",
9648
+ // The keys an author declared on THIS node — the case a static list cannot
9649
+ // express, and the one issue #5 named.
9650
+ outputShape: (config) => (config.fields ?? []).filter((f) => typeof f.key === "string" && f.key !== "").map((f) => ({ path: f.key, type: "string", description: f.label })),
9651
+ aliases: ["user_input", "@fancy/user_input"],
9652
+ pausesForHuman: "input",
9653
+ category: "human",
9654
+ label: "User Input",
9655
+ description: "Pause the flow until the user submits the configured form.",
9656
+ icon: "\u270E",
9657
+ inputs: [{ id: "in" }],
9658
+ outputs: [{ id: "out", label: "values" }],
9659
+ configSchema: [
9660
+ { type: "text", key: "title", label: "Form title", default: "Need your input" },
9661
+ {
9662
+ type: "repeater",
9663
+ key: "fields",
9664
+ label: "Fields",
9665
+ description: "The form the run pauses on.",
9666
+ titleKey: "label",
9667
+ addLabel: "Add field",
9668
+ minItems: 1,
9669
+ fields: [
9670
+ { type: "text", key: "key", label: "Key", required: true, placeholder: "answer" },
9671
+ { type: "text", key: "label", label: "Label", required: true, placeholder: "Your answer" },
9672
+ {
9673
+ type: "select",
9674
+ key: "type",
9675
+ label: "Type",
9676
+ default: "text",
9677
+ options: [
9678
+ { value: "text", label: "Text" },
9679
+ { value: "textarea", label: "Long text" },
9680
+ { value: "number", label: "Number" },
9681
+ { value: "select", label: "Select" },
9682
+ { value: "switch", label: "Switch" }
9683
+ ]
9684
+ },
9685
+ { type: "switch", key: "required", label: "Required", default: false }
9686
+ ],
9687
+ default: [{ key: "answer", label: "Your answer", type: "textarea", required: true }]
9688
+ }
9689
+ ]
9690
+ },
9691
+ {
9692
+ name: "@particle-academy/rich_user_input",
9693
+ aliases: ["rich_user_input", "@fancy/rich_user_input"],
9694
+ pausesForHuman: "input",
9695
+ category: "human",
9696
+ label: "Rich User Input",
9697
+ description: "Pause the flow on a fully authored page \u2014 content, required reading, multi-section forms.",
9698
+ icon: "\u25A4",
9699
+ inputs: [{ id: "in" }],
9700
+ outputs: [{ id: "out", label: "values" }],
9701
+ configSchema: [
9702
+ { type: "text", key: "title", label: "Step title", default: "Please review" },
9703
+ {
9704
+ type: "document",
9705
+ key: "document",
9706
+ label: "Page content",
9707
+ documentType: "stages",
9708
+ description: "Authored with the host's document editor (fancy-cms Stages)."
9709
+ },
9710
+ { type: "switch", key: "requireConfirm", label: "Require explicit confirmation", default: true },
9711
+ { type: "text", key: "submitLabel", label: "Submit button", default: "Continue" }
9712
+ ],
9713
+ // Preview the authored page inside a FauxClient frame, so the canvas shows
9714
+ // what the person hitting this step will actually see.
9715
+ renderBody: (ctx) => createElement(RichInputPreview, { config: ctx.config ?? {} })
9716
+ },
9717
+ {
9718
+ name: "@particle-academy/subflow",
9719
+ aliases: ["subflow", "@fancy/subflow"],
9720
+ category: "logic",
9721
+ label: "SubFlow",
9722
+ description: "Run another workflow and bring its result \u2014 or its live progress \u2014 back into this one.",
9723
+ icon: "\u29C9",
9724
+ inputs: [{ id: "in" }],
9725
+ // The stream port only exists when something actually streams.
9726
+ outputs: (config) => subflowPorts(config ?? {}),
9727
+ // Core, not marketplace: it runs a child graph through this same engine and
9728
+ // needs nothing from outside except where workflows live.
9729
+ executor: subflowExecutor,
9730
+ configSchema: [
9731
+ {
9732
+ type: "text",
9733
+ key: "workflow",
9734
+ label: "Workflow",
9735
+ required: true,
9736
+ placeholder: "onboarding-v2",
9737
+ description: "Reference resolved by the host's registerWorkflowResolver()."
9738
+ },
9739
+ {
9740
+ type: "number",
9741
+ key: "version",
9742
+ label: "Pin to version",
9743
+ description: "Optional. Leave blank to always run the child's current version. Pinning fails the run loudly if the child has moved on \u2014 without it, someone edits the child and this flow silently runs different logic."
9744
+ },
9745
+ {
9746
+ type: "select",
9747
+ key: "mode",
9748
+ label: "Return",
9749
+ default: "output",
9750
+ options: [
9751
+ { value: "output", label: "Output when it finishes" },
9752
+ { value: "stream", label: "Stream progress as it runs" },
9753
+ { value: "both", label: "Both \u2014 stream, then output" }
9754
+ ],
9755
+ description: "Streaming adds a second port so a parent can show progress instead of a spinner."
9756
+ },
9757
+ {
9758
+ type: "keyvalue",
9759
+ key: "inputs",
9760
+ label: "Input mapping",
9761
+ description: "Values handed to the child's entry points. Omit to pass this node's inputs straight through.",
9762
+ keyLabel: "Name",
9763
+ valueLabel: "Value",
9764
+ addLabel: "Add input"
9765
+ },
9766
+ {
9767
+ type: "number",
9768
+ key: "maxDepth",
9769
+ label: "Max nesting depth",
9770
+ default: DEFAULT_MAX_DEPTH,
9771
+ min: 1,
9772
+ max: 32,
9773
+ description: "Guards against a workflow referencing itself."
9774
+ }
9775
+ ]
9776
+ },
9777
+ // ───────────── Logic ─────────────
9778
+ {
9779
+ name: "@particle-academy/branch",
9780
+ aliases: ["branch", "@fancy/branch"],
9781
+ category: "logic",
9782
+ label: "Branch",
9783
+ description: "Multi-way branch on a condition or value.",
9784
+ icon: "\u25C7",
9785
+ inputs: [{ id: "in" }],
9786
+ outputs: [{ id: "true", label: "true" }, { id: "false", label: "false" }],
9787
+ configSchema: [
9788
+ {
9789
+ type: "select",
9790
+ key: "match",
9791
+ label: "Match",
9792
+ default: "all",
9793
+ options: [
9794
+ { value: "all", label: "All conditions (AND)" },
9795
+ { value: "any", label: "Any condition (OR)" }
9796
+ ]
9797
+ },
9798
+ {
9799
+ type: "repeater",
9800
+ key: "conditions",
9801
+ label: "Conditions",
9802
+ description: "Routes to `true` when these match, otherwise `false`.",
9803
+ titleKey: "left",
9804
+ addLabel: "Add condition",
9805
+ minItems: 1,
9806
+ fields: [
9807
+ { type: "expression", key: "left", label: "Value", example: "{{ $json.status }}", required: true },
9808
+ {
9809
+ type: "select",
9810
+ key: "operator",
9811
+ label: "Is",
9812
+ default: "eq",
9813
+ options: [
9814
+ { value: "eq", label: "equal to" },
9815
+ { value: "neq", label: "not equal to" },
9816
+ { value: "contains", label: "contains" },
9817
+ { value: "not_contains", label: "does not contain" },
9818
+ { value: "gt", label: "greater than" },
9819
+ { value: "gte", label: "greater than or equal to" },
9820
+ { value: "lt", label: "less than" },
9821
+ { value: "lte", label: "less than or equal to" },
9822
+ { value: "truthy", label: "true" },
9823
+ { value: "falsy", label: "false" },
9824
+ { value: "empty", label: "empty" },
9825
+ { value: "not_empty", label: "not empty" }
9826
+ ]
9827
+ },
9828
+ { type: "text", key: "right", label: "Compared to", placeholder: "active" }
9829
+ ],
9830
+ default: [{ left: "", operator: "eq", right: "" }]
9831
+ },
9832
+ {
9833
+ type: "expression",
9834
+ key: "condition",
9835
+ label: "Raw expression (advanced)",
9836
+ example: "{{ $json.active && $json.score > 10 }}",
9837
+ description: "Escape hatch for logic the builder can't express. Overrides the conditions above when set."
9838
+ }
9839
+ ]
9840
+ },
9841
+ {
9842
+ name: "@particle-academy/switch_case",
9843
+ aliases: ["switch_case", "@fancy/switch_case"],
9844
+ category: "logic",
9845
+ label: "Switch",
9846
+ description: "Route to one of N labelled outputs based on a key.",
9847
+ icon: "\u2933",
9848
+ inputs: [{ id: "in" }],
9849
+ // Ports ARE the config: every distinct port a case routes to becomes an
9850
+ // output handle, plus the always-present `default`. Editing the cases map
9851
+ // moves the ports on the canvas and the ports the runtime activates.
9852
+ outputs: (config) => casePorts(config?.cases),
9853
+ configSchema: [
9854
+ { type: "expression", key: "value", label: "Switch on", example: "{{ $json.kind }}", required: true },
9855
+ {
9856
+ type: "keyvalue",
9857
+ key: "cases",
9858
+ label: "Cases",
9859
+ description: "Match value \u2192 output port. Unmatched input takes `default`.",
9860
+ keyLabel: "When value is",
9861
+ valueLabel: "Route to port",
9862
+ keyPlaceholder: "a",
9863
+ valuePlaceholder: "case_a",
9864
+ addLabel: "Add case",
9865
+ default: { a: "case_a", b: "case_b" }
9866
+ }
9867
+ ]
9868
+ },
9869
+ {
9870
+ name: "@particle-academy/for_each",
9871
+ outputShape: [
9872
+ { path: "items", type: "array" },
9873
+ { path: "count", type: "number" }
9874
+ ],
9875
+ aliases: ["for_each", "@fancy/for_each"],
9876
+ category: "logic",
9877
+ label: "For Each",
9878
+ description: "Iterate over a list, emitting each item on `item`.",
9879
+ icon: "\u21BB",
9880
+ inputs: [{ id: "in" }],
9881
+ outputs: [{ id: "item", label: "item" }, { id: "done", label: "done" }],
9882
+ configSchema: [
9883
+ { type: "expression", key: "source", label: "List", example: "{{ $json.users }}", required: true },
9884
+ { type: "number", key: "concurrency", label: "Concurrency", default: 1, min: 1, max: 50 }
9885
+ ]
9886
+ },
9887
+ {
9888
+ name: "@particle-academy/merge",
9889
+ aliases: ["merge", "@fancy/merge"],
9890
+ category: "logic",
9891
+ label: "Merge",
9892
+ description: "Combine multiple inputs into one object or array.",
9893
+ icon: "\u2295",
9894
+ inputs: [{ id: "a" }, { id: "b" }],
9895
+ outputs: [{ id: "out" }],
9896
+ configSchema: [
9897
+ {
9898
+ type: "select",
9899
+ key: "mode",
9900
+ label: "Mode",
9901
+ default: "merge",
9902
+ options: [{ value: "merge", label: "Object merge" }, { value: "concat", label: "Array concat" }]
9903
+ }
9904
+ ]
9905
+ },
9906
+ {
9907
+ name: "@particle-academy/wait",
9908
+ aliases: ["wait", "@fancy/wait"],
9909
+ category: "logic",
9910
+ label: "Wait",
9911
+ description: "Sleep or wait for an external event.",
9912
+ icon: "\u23F8",
9913
+ configSchema: [
9914
+ {
9915
+ type: "select",
9916
+ key: "mode",
9917
+ label: "Mode",
9918
+ default: "duration",
9919
+ options: [{ value: "duration", label: "Duration" }, { value: "until", label: "Until timestamp" }, { value: "event", label: "External event" }]
9920
+ },
9921
+ { type: "text", key: "duration", label: "Duration", placeholder: "5s, 10m, 1h", description: "Used when mode = duration." }
9922
+ ]
9923
+ },
9924
+ {
9925
+ name: "@particle-academy/transform",
9926
+ aliases: ["transform", "@fancy/transform"],
9927
+ category: "logic",
9928
+ label: "Transform",
9929
+ description: "Reshape data with an expression.",
9930
+ icon: "\u0192",
9931
+ configSchema: [
9932
+ {
9933
+ type: "select",
9934
+ key: "mode",
9935
+ label: "Build the output",
9936
+ default: "fields",
9937
+ options: [
9938
+ { value: "fields", label: "Field by field" },
9939
+ { value: "expression", label: "One expression" }
9940
+ ]
9941
+ },
9942
+ {
9943
+ type: "repeater",
9944
+ key: "fields",
9945
+ label: "Output fields",
9946
+ description: "Each row becomes a key on the result.",
9947
+ titleKey: "key",
9948
+ addLabel: "Add field",
9949
+ fields: [
9950
+ { type: "text", key: "key", label: "Key", required: true, placeholder: "name" },
9951
+ { type: "expression", key: "value", label: "Value", example: "{{ $json.first }}", required: true }
9952
+ ],
9953
+ default: [{ key: "", value: "" }]
9954
+ },
9955
+ {
9956
+ type: "expression",
9957
+ key: "expression",
9958
+ label: "Expression (advanced)",
9959
+ example: "{{ { id: $json.id, name: $json.first + ' ' + $json.last } }}",
9960
+ description: "Used when the mode above is set to one expression."
9961
+ }
9962
+ ]
9963
+ },
9964
+ // ───────────── Data ─────────────
9965
+ {
9966
+ name: "@particle-academy/memory_store",
9967
+ aliases: ["memory_store", "@fancy/memory_store"],
9968
+ category: "data",
9969
+ label: "Memory Store",
9970
+ description: "Read or write per-conversation memory.",
9971
+ icon: "\u{1F9E0}",
9972
+ configSchema: [
9973
+ {
9974
+ type: "select",
9975
+ key: "operation",
9976
+ label: "Operation",
9977
+ required: true,
9978
+ default: "read",
9979
+ options: [{ value: "read", label: "Read" }, { value: "write", label: "Write" }, { value: "append", label: "Append" }]
9980
+ },
9981
+ { type: "text", key: "key", label: "Key", placeholder: "user.preferences", required: true },
9982
+ { type: "expression", key: "value", label: "Value (write/append only)", example: "{{ $json }}" },
9983
+ { type: "credential", key: "store", label: "Memory store", credentialType: "memory_store" }
9984
+ ]
9985
+ },
9986
+ {
9987
+ name: "@particle-academy/data_store",
9988
+ aliases: ["data_store", "@fancy/data_store"],
9989
+ category: "data",
9990
+ label: "Data Store",
9991
+ description: "Key-value or table read/write against a host store.",
9992
+ icon: "\u{1F5C3}",
9993
+ configSchema: [
9994
+ {
9995
+ type: "select",
9996
+ key: "operation",
9997
+ label: "Operation",
9998
+ required: true,
9999
+ default: "get",
10000
+ options: [
10001
+ { value: "get", label: "Get" },
10002
+ { value: "set", label: "Set" },
10003
+ { value: "delete", label: "Delete" },
10004
+ { value: "query", label: "Query" },
10005
+ { value: "list", label: "List" }
10006
+ ]
10007
+ },
10008
+ { type: "text", key: "table", label: "Table / collection", required: true },
10009
+ { type: "text", key: "key", label: "Key" },
10010
+ {
10011
+ type: "keyvalue",
10012
+ key: "where",
10013
+ label: "Where",
10014
+ description: "Field/value pairs to match. For query and list operations.",
10015
+ keyLabel: "Field",
10016
+ valueLabel: "Equals",
10017
+ addLabel: "Add filter"
10018
+ },
10019
+ { type: "expression", key: "value", label: "Value (set only)", example: "{{ $json }}" },
10020
+ { type: "credential", key: "store", label: "Data store", credentialType: "data_store" }
10021
+ ]
10022
+ },
10023
+ {
10024
+ name: "@particle-academy/variable",
10025
+ aliases: ["variable", "@fancy/variable"],
10026
+ category: "data",
10027
+ label: "Variable",
10028
+ description: "Workflow-scoped value used by other nodes.",
10029
+ icon: "\u{1D4CD}",
10030
+ configSchema: [
10031
+ { type: "text", key: "name", label: "Name", required: true },
10032
+ { type: "expression", key: "value", label: "Value", required: true }
10033
+ ]
10034
+ },
10035
+ // ───────────── AI ─────────────
10036
+ {
10037
+ name: "@particle-academy/llm_call",
10038
+ // LlmClient::complete() -> array{text:string,data?:mixed,usage?:array,raw?:mixed}
10039
+ //
10040
+ // A FUNCTION of config, because `data` exists only when this node was asked
10041
+ // for a schema. Declaring it statically would offer `{{ $json.data }}` on
10042
+ // every llm_call in the kit, including the ones that emit nothing of the
10043
+ // sort — and a suggestion that resolves to null at runtime is worse than no
10044
+ // suggestion, since the picker is exactly what gave the author confidence.
10045
+ outputShape: (config) => {
10046
+ const asked = config?.response_schema != null && config.response_schema !== "" && !(Array.isArray(config.response_schema) && config.response_schema.length === 0);
10047
+ return [
10048
+ { path: "text", type: "string", description: "The model's completion." },
10049
+ ...asked ? [{ path: "data", type: "unknown", description: "The parsed, schema-checked result." }] : [],
10050
+ { path: "usage", type: "object", description: "Token counts, when the provider reports them." },
10051
+ { path: "raw", type: "unknown", description: "The provider's untouched response." }
10052
+ ];
10053
+ },
10054
+ aliases: ["llm_call", "@fancy/llm_call"],
10055
+ category: "ai",
10056
+ label: "LLM Call",
10057
+ description: "Send a prompt + context to a model and receive a response.",
10058
+ icon: "\u2726",
10059
+ configSchema: [
10060
+ {
10061
+ type: "select",
10062
+ key: "provider",
10063
+ label: "Provider",
10064
+ default: "anthropic",
10065
+ options: [
10066
+ { value: "anthropic", label: "Anthropic" },
10067
+ { value: "openai", label: "OpenAI" },
10068
+ { value: "custom", label: "Custom" }
10069
+ ]
10070
+ },
10071
+ { type: "text", key: "model", label: "Model", placeholder: "claude-sonnet-4-5", required: true },
10072
+ { type: "textarea", key: "system", label: "System prompt", rows: 4 },
10073
+ { type: "expression", key: "prompt", label: "User prompt", example: "{{ $json.question }}", required: true },
10074
+ { type: "number", key: "temperature", label: "Temperature", min: 0, max: 2, step: 0.1, default: 0.7 },
10075
+ { type: "number", key: "max_tokens", label: "Max tokens", min: 1, max: 8192, default: 1024 },
10076
+ {
10077
+ type: "repeater",
10078
+ key: "tools",
10079
+ label: "Tools",
10080
+ description: "Tools the model may call.",
10081
+ titleKey: "name",
10082
+ addLabel: "Add tool",
10083
+ fields: [
10084
+ { type: "text", key: "name", label: "Name", required: true, placeholder: "search_index" },
10085
+ { type: "text", key: "description", label: "When to use it" },
10086
+ {
10087
+ type: "json",
10088
+ key: "input_schema",
10089
+ label: "Input schema",
10090
+ description: "JSON Schema for the tool's arguments."
10091
+ }
10092
+ ]
10093
+ },
10094
+ {
10095
+ type: "json",
10096
+ key: "response_schema",
10097
+ label: "Response schema",
10098
+ description: "Optional JSON Schema. When set, the runtime asks the provider for schema-valid JSON and the node emits the parsed value as `data` \u2014 reference it as {{ $json.data }}. A response that cannot be parsed or does not match FAILS the node rather than passing an empty value downstream."
10099
+ },
10100
+ { type: "credential", key: "credential", label: "API credential", credentialType: "llm_credential" }
10101
+ ]
10102
+ },
10103
+ {
10104
+ name: "@particle-academy/llm_router",
10105
+ // Every id this node has ever shipped under keeps resolving — MOIC's saved
10106
+ // flows carry the bare `llm_branch`.
10107
+ aliases: ["llm_router", "llm_branch", "@fancy/llm_branch", "@fancy/llm_router"],
10108
+ category: "ai",
10109
+ label: "LLM Router",
10110
+ description: "Let a model choose which route the flow takes.",
10111
+ icon: "\u2727",
10112
+ inputs: [{ id: "in" }],
10113
+ // Each declared route is a port. The executor returns `{ __port: id }`
10114
+ // (or `Port.only(id)` on the PHP runtime) to pick one.
10115
+ outputs: (config) => routePorts(config?.routes, config?.fallback),
10116
+ // A shuttle, not an engine: it carries the routes out to whatever LLM
10117
+ // client the host registered and carries the choice back. No provider SDK
10118
+ // reaches core, so this stays a builtin without adding a dependency.
10119
+ executor: llmRouterExecutor,
10120
+ configSchema: [
10121
+ {
10122
+ type: "textarea",
10123
+ key: "system",
10124
+ label: "System prompt",
10125
+ rows: 3,
10126
+ description: "Optional framing for the routing decision."
10127
+ },
10128
+ {
10129
+ type: "expression",
10130
+ key: "prompt",
10131
+ label: "What to route on",
10132
+ example: "{{ $json.message }}",
10133
+ required: true
10134
+ },
10135
+ {
10136
+ type: "repeater",
10137
+ key: "routes",
10138
+ label: "Routes",
10139
+ description: "The model picks exactly one. Descriptions are what it chooses between \u2014 make them distinct.",
10140
+ titleKey: "port",
10141
+ addLabel: "Add route",
10142
+ minItems: 2,
10143
+ fields: [
10144
+ { type: "text", key: "port", label: "Port", required: true, placeholder: "billing" },
10145
+ {
10146
+ type: "text",
10147
+ key: "description",
10148
+ label: "When to choose it",
10149
+ required: true,
10150
+ placeholder: "The user is asking about an invoice, refund, or payment."
10151
+ }
10152
+ ],
10153
+ default: [
10154
+ { port: "a", description: "Describe when the model should pick this route." },
10155
+ { port: "b", description: "Describe when the model should pick this route." }
10156
+ ]
10157
+ },
10158
+ {
10159
+ type: "select",
10160
+ key: "provider",
10161
+ label: "Provider",
10162
+ default: "anthropic",
10163
+ options: [
10164
+ { value: "anthropic", label: "Anthropic" },
10165
+ { value: "openai", label: "OpenAI" },
10166
+ { value: "custom", label: "Custom" }
10167
+ ]
10168
+ },
10169
+ { type: "text", key: "model", label: "Model", placeholder: "claude-sonnet-4-5" },
10170
+ {
10171
+ type: "switch",
10172
+ key: "fallback",
10173
+ label: "Add a `fallback` port",
10174
+ default: true,
10175
+ description: "Where the flow goes if the model returns no usable route."
10176
+ },
10177
+ { type: "credential", key: "credential", label: "API credential", credentialType: "llm_credential" }
10178
+ ]
10179
+ },
10180
+ {
10181
+ name: "@particle-academy/tool_use",
10182
+ aliases: ["tool_use", "@fancy/tool_use"],
10183
+ category: "ai",
10184
+ label: "Tool Use",
10185
+ description: "Hand control to a host-registered tool by name.",
10186
+ icon: "\u{1F6E0}",
10187
+ configSchema: [
10188
+ { type: "text", key: "tool", label: "Tool name", placeholder: "search_index", required: true },
10189
+ { type: "expression", key: "args", label: "Arguments", example: "{{ { query: $json.q } }}" }
10190
+ ]
10191
+ },
10192
+ {
10193
+ name: "@particle-academy/embed_search",
10194
+ outputShape: [
10195
+ { path: "query", type: "string" },
10196
+ { path: "matches", type: "array", description: "Ranked results from the vector store." }
10197
+ ],
10198
+ aliases: ["embed_search", "@fancy/embed_search"],
10199
+ category: "ai",
10200
+ label: "Embed & Search",
10201
+ description: "Embed a query and search a vector store.",
10202
+ icon: "\u273A",
10203
+ configSchema: [
10204
+ { type: "expression", key: "query", label: "Query", required: true, example: "{{ $json.question }}" },
10205
+ { type: "number", key: "topK", label: "Top K", default: 5, min: 1, max: 50 },
10206
+ { type: "credential", key: "vectorStore", label: "Vector store", credentialType: "vector_store" }
10207
+ ]
10208
+ },
10209
+ // ───────────── IO ─────────────
10210
+ {
10211
+ name: "@particle-academy/api_request",
10212
+ // HttpClient::send() -> array{status:int,headers:array,body:mixed}
10213
+ outputShape: [
10214
+ { path: "status", type: "number", description: "HTTP status code." },
10215
+ { path: "headers", type: "object" },
10216
+ { path: "body", type: "unknown", description: "Decoded JSON when the response is JSON, otherwise the raw body." }
10217
+ ],
10218
+ aliases: ["api_request", "@fancy/api_request"],
10219
+ category: "io",
10220
+ label: "API Request",
10221
+ description: "HTTP request to any URL.",
10222
+ icon: "\u2194",
10223
+ configSchema: [
10224
+ ...HTTP_METHODS,
10225
+ { type: "text", key: "url", label: "URL", placeholder: "https://api.example.com/...", required: true },
10226
+ {
10227
+ type: "keyvalue",
10228
+ key: "headers",
10229
+ label: "Headers",
10230
+ keyLabel: "Header",
10231
+ valueLabel: "Value",
10232
+ keyPlaceholder: "content-type",
10233
+ valuePlaceholder: "application/json",
10234
+ addLabel: "Add header",
10235
+ default: { "content-type": "application/json" }
10236
+ },
10237
+ { type: "json", key: "body", label: "Body" },
10238
+ { type: "credential", key: "auth", label: "Auth", credentialType: "api_credential" }
10239
+ ]
10240
+ },
10241
+ {
10242
+ name: "@particle-academy/webhook_out",
10243
+ aliases: ["webhook_out", "@fancy/webhook_out"],
10244
+ category: "io",
10245
+ label: "Send Webhook",
10246
+ description: "POST a payload to a configured URL.",
10247
+ icon: "\u2197",
10248
+ configSchema: [
10249
+ { type: "text", key: "url", label: "URL", required: true },
10250
+ {
10251
+ type: "keyvalue",
10252
+ key: "headers",
10253
+ label: "Headers",
10254
+ keyLabel: "Header",
10255
+ valueLabel: "Value",
10256
+ addLabel: "Add header"
10257
+ },
10258
+ { type: "expression", key: "payload", label: "Payload", required: true, example: "{{ $json }}" }
10259
+ ]
10260
+ },
10261
+ // ───────────── Human ─────────────
10262
+ {
10263
+ name: "@particle-academy/human_approval",
10264
+ aliases: ["human_approval", "@fancy/human_approval"],
10265
+ pausesForHuman: "approval",
10266
+ category: "human",
10267
+ label: "Human Approval",
10268
+ description: "Pause until a human approves or denies.",
10269
+ icon: "\u2713",
10270
+ inputs: [{ id: "in" }],
10271
+ outputs: [{ id: "approved", label: "approved" }, { id: "denied", label: "denied" }],
10272
+ configSchema: [
10273
+ { type: "text", key: "title", label: "Approval title", default: "Approve action" },
10274
+ { type: "textarea", key: "description", label: "Description for approver", rows: 3 },
10275
+ { type: "credential", key: "channel", label: "Notify channel", credentialType: "notify_channel" }
10276
+ ]
10277
+ },
10278
+ {
10279
+ name: "@particle-academy/notify",
10280
+ aliases: ["notify", "@fancy/notify"],
10281
+ category: "human",
10282
+ label: "Notify",
10283
+ description: "Send a message via Slack / email / SMS / etc.",
10284
+ icon: "\u{1F514}",
10285
+ configSchema: [
10286
+ {
10287
+ type: "select",
10288
+ key: "channel",
10289
+ label: "Channel",
10290
+ default: "slack",
10291
+ options: [
10292
+ { value: "slack", label: "Slack" },
10293
+ { value: "email", label: "Email" },
10294
+ { value: "sms", label: "SMS" },
10295
+ { value: "discord", label: "Discord" }
10296
+ ]
10297
+ },
10298
+ { type: "text", key: "to", label: "To", required: true },
10299
+ { type: "expression", key: "message", label: "Message", required: true, example: "{{ $json.summary }}" }
10300
+ ]
10301
+ },
10302
+ // ───────────── Output ─────────────
10303
+ {
10304
+ name: "@particle-academy/output",
10305
+ aliases: ["output", "@fancy/output"],
10306
+ category: "output",
10307
+ label: "Output",
10308
+ description: "Terminal node \u2014 captures the workflow's result.",
10309
+ icon: "\u25CF",
10310
+ inputs: [{ id: "in" }],
10311
+ outputs: []
10312
+ },
10313
+ {
10314
+ name: "@particle-academy/log",
10315
+ aliases: ["log", "@fancy/log"],
10316
+ category: "output",
10317
+ label: "Log",
10318
+ description: "Send to the run feed.",
10319
+ icon: "\u2261",
10320
+ inputs: [{ id: "in" }],
10321
+ outputs: [],
10322
+ configSchema: [
10323
+ {
10324
+ type: "select",
10325
+ key: "level",
10326
+ label: "Level",
10327
+ default: "info",
10328
+ options: [{ value: "info", label: "info" }, { value: "warn", label: "warn" }, { value: "error", label: "error" }]
10329
+ },
10330
+ { type: "expression", key: "message", label: "Message", required: true, example: "{{ $json }}" }
10331
+ ]
10332
+ },
10333
+ {
10334
+ // Swimlane — a portless, resizable container. Child nodes are parented into
10335
+ // it; it never runs (the runtime skips the `layout` category). Uses its own
10336
+ // renderer (LaneNode) instead of the default card.
10337
+ name: "@particle-academy/lane",
10338
+ aliases: ["lane", "@fancy/lane"],
10339
+ category: "layout",
10340
+ label: "Lane",
10341
+ description: "A resizable swimlane \u2014 drop nodes into it to group them.",
10342
+ icon: "\u25A4",
10343
+ inputs: [],
10344
+ outputs: [],
10345
+ configSchema: [
10346
+ { type: "text", key: "title", label: "Title", default: "Lane" },
10347
+ {
10348
+ type: "select",
10349
+ key: "orientation",
10350
+ label: "Orientation",
10351
+ default: "horizontal",
10352
+ options: [{ value: "horizontal", label: "Row" }, { value: "vertical", label: "Column" }]
10353
+ }
10354
+ ],
10355
+ defaultConfig: { title: "Lane", orientation: "horizontal" },
10356
+ resizable: { minWidth: 160, minHeight: 72 },
10357
+ component: LaneNode
10358
+ },
10359
+ {
10360
+ // Note — a sticky-note annotation. Portless + visual-only: the runtime skips
10361
+ // the `annotation` category, so a note's text NEVER reaches a runner — it
10362
+ // rides in the document purely for people, editors, and MCP tools. Uses its
10363
+ // own renderer (NoteNode); double-click on the canvas to edit in place.
10364
+ name: "@particle-academy/note",
10365
+ aliases: ["note", "@fancy/note"],
10366
+ category: "annotation",
10367
+ label: "Note",
10368
+ description: "A sticky note that documents the canvas. Never runs \u2014 editor + agent only.",
10369
+ icon: "\u{1F5D2}",
10370
+ inputs: [],
10371
+ outputs: [],
10372
+ configSchema: [
10373
+ { type: "text", key: "title", label: "Title", placeholder: "Optional heading" },
10374
+ { type: "textarea", key: "text", label: "Note", rows: 5, placeholder: "What does this part of the flow do?" },
10375
+ { type: "select", key: "color", label: "Color", default: "amber", options: [
10376
+ { value: "amber", label: "Amber" },
10377
+ { value: "sky", label: "Sky" },
10378
+ { value: "violet", label: "Violet" },
10379
+ { value: "emerald", label: "Emerald" },
10380
+ { value: "rose", label: "Rose" },
10381
+ { value: "slate", label: "Slate" }
10382
+ ] }
10383
+ ],
10384
+ defaultConfig: { text: "", color: "amber" },
10385
+ resizable: { minWidth: 140, minHeight: 80 },
10386
+ component: NoteNode
10387
+ }
10388
+ ];
10389
+ function registerBuiltinKinds() {
10390
+ for (const k of KINDS) registerNodeKind(k);
10391
+ }
10392
+ var BUILTIN_KINDS = KINDS;
10393
+
10394
+ // src/registry/registry.ts
10395
+ var kinds = /* @__PURE__ */ new Map();
10396
+ var aliases = /* @__PURE__ */ new Map();
10397
+ var listeners = /* @__PURE__ */ new Set();
10398
+ var overrides = /* @__PURE__ */ new Map();
10399
+ var builtinsEnsured = false;
10400
+ function ensureBuiltinKinds() {
10401
+ if (builtinsEnsured) return;
10402
+ builtinsEnsured = true;
10403
+ registerBuiltinKinds();
10404
+ }
10405
+ function registerNodeKind(definition) {
10406
+ ensureBuiltinKinds();
10407
+ kinds.set(definition.name, definition);
10408
+ for (const alias of definition.aliases ?? []) aliases.set(alias, definition.name);
10409
+ notify();
10410
+ return () => {
10411
+ if (kinds.get(definition.name) === definition) {
10412
+ kinds.delete(definition.name);
10413
+ for (const alias of definition.aliases ?? []) {
10414
+ if (aliases.get(alias) === definition.name) aliases.delete(alias);
10415
+ }
10416
+ notify();
10417
+ }
10418
+ };
10419
+ }
10420
+ function resolveKindId(id2) {
10421
+ ensureBuiltinKinds();
10422
+ if (kinds.has(id2)) return id2;
10423
+ const canonical = aliases.get(id2);
10424
+ return canonical && kinds.has(canonical) ? canonical : null;
10425
+ }
10426
+ function overrideNodeKind(name, patch) {
10427
+ const canonical = resolveKindId(name) ?? name;
10428
+ const previous = overrides.get(canonical);
10429
+ overrides.set(canonical, { ...previous, ...patch });
10430
+ notify();
10431
+ return () => {
10432
+ if (previous) {
10433
+ overrides.set(canonical, previous);
10434
+ } else {
10435
+ overrides.delete(canonical);
10436
+ }
10437
+ notify();
10438
+ };
10439
+ }
10440
+ function clearNodeKindOverrides() {
10441
+ if (overrides.size === 0) return;
10442
+ overrides.clear();
10443
+ notify();
10444
+ }
10445
+ function withOverride(kind) {
10446
+ if (!kind) return null;
10447
+ const patch = overrides.get(kind.name);
10448
+ return patch ? { ...kind, ...patch } : kind;
10449
+ }
10450
+ function getNodeKind(name) {
10451
+ const canonical = resolveKindId(name);
10452
+ return canonical ? withOverride(kinds.get(canonical)) : null;
10453
+ }
10454
+ function kindIds(kind) {
10455
+ return [kind.name, ...kind.aliases ?? []];
10456
+ }
10457
+ function listNodeKinds(category) {
10458
+ ensureBuiltinKinds();
10459
+ const all = Array.from(kinds.values()).map(
10460
+ (k) => withOverride(k)
10461
+ );
10462
+ return category ? all.filter((k) => k.category === category) : all;
10463
+ }
10464
+ function onNodeKindsChanged(listener) {
10465
+ listeners.add(listener);
10466
+ return () => listeners.delete(listener);
10467
+ }
10468
+ function notify() {
10469
+ for (const l of listeners) l();
10470
+ }
10471
+ function defaultConfigFor(kind) {
10472
+ const fromKind = kind.defaultConfig ? { ...kind.defaultConfig } : {};
10473
+ for (const field of kind.configSchema ?? []) {
10474
+ if (fromKind[field.key] !== void 0) continue;
10475
+ if ("default" in field && field.default !== void 0) {
10476
+ fromKind[field.key] = field.default;
10477
+ }
10478
+ }
10479
+ return fromKind;
10480
+ }
10481
+ function validateConfig(kind, config) {
10482
+ const issues = [];
10483
+ for (const field of kind.configSchema ?? []) {
10484
+ const value = config[field.key];
10485
+ if (field.required && (value === void 0 || value === null || value === "")) {
10486
+ issues.push({ key: field.key, message: `${field.label} is required` });
10487
+ continue;
10488
+ }
10489
+ if (value === void 0 || value === null) continue;
10490
+ const issue = validateField(field, value);
10491
+ if (issue) issues.push({ key: field.key, message: issue });
10492
+ }
10493
+ return issues;
10494
+ }
10495
+ function validateField(field, value) {
10496
+ switch (field.type) {
10497
+ case "text":
10498
+ case "textarea":
10499
+ case "expression":
10500
+ case "credential":
10501
+ return typeof value === "string" ? null : `${field.label} must be a string`;
10502
+ case "number": {
10503
+ if (typeof value !== "number" || !Number.isFinite(value)) return `${field.label} must be a number`;
10504
+ if (field.min !== void 0 && value < field.min) return `${field.label} must be >= ${field.min}`;
10505
+ if (field.max !== void 0 && value > field.max) return `${field.label} must be <= ${field.max}`;
10506
+ return null;
10507
+ }
10508
+ case "switch":
10509
+ return typeof value === "boolean" ? null : `${field.label} must be a boolean`;
10510
+ case "select": {
10511
+ const allowed = field.options.map((o) => o.value);
10512
+ return allowed.includes(String(value)) ? null : `${field.label} must be one of ${allowed.join(", ")}`;
10513
+ }
10514
+ case "json":
10515
+ return null;
10516
+ // permissive — just JSON-shaped
10517
+ case "repeater": {
10518
+ if (!Array.isArray(value)) return `${field.label} must be a list`;
10519
+ if (field.minItems !== void 0 && value.length < field.minItems) {
10520
+ return `${field.label} needs at least ${field.minItems}`;
10521
+ }
10522
+ if (field.maxItems !== void 0 && value.length > field.maxItems) {
10523
+ return `${field.label} allows at most ${field.maxItems}`;
10524
+ }
10525
+ for (let i = 0; i < value.length; i++) {
10526
+ const row = value[i];
10527
+ if (!row || typeof row !== "object" || Array.isArray(row)) {
10528
+ return `${field.label} item ${i + 1} must be an object`;
10529
+ }
10530
+ for (const sub of field.fields) {
10531
+ const cell = row[sub.key];
10532
+ if (sub.required && (cell === void 0 || cell === null || cell === "")) {
10533
+ return `${field.label} item ${i + 1}: ${sub.label} is required`;
10534
+ }
10535
+ if (cell === void 0 || cell === null) continue;
10536
+ const issue = validateField(sub, cell);
10537
+ if (issue) return `${field.label} item ${i + 1}: ${issue}`;
10538
+ }
10539
+ }
10540
+ return null;
10541
+ }
10542
+ case "keyvalue": {
10543
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
10544
+ return `${field.label} must be a key/value map`;
10545
+ }
10546
+ const allowed = field.valueOptions?.map((o) => o.value);
10547
+ for (const [k, v] of Object.entries(value)) {
10548
+ if (typeof v !== "string") return `${field.label}: "${k}" must be a string`;
10549
+ if (allowed && !allowed.includes(v)) {
10550
+ return `${field.label}: "${k}" must be one of ${allowed.join(", ")}`;
10551
+ }
10552
+ }
10553
+ return null;
10554
+ }
10555
+ case "document":
10556
+ return null;
10557
+ // opaque to fancy-flow — the host's editor owns its shape
10558
+ default:
10559
+ return null;
10560
+ }
10561
+ }
10562
+ function categoryAccent(category) {
10563
+ switch (category) {
10564
+ case "trigger":
10565
+ return "#10b981";
10566
+ case "logic":
10567
+ return "#f59e0b";
10568
+ case "data":
10569
+ return "#0ea5e9";
10570
+ case "ai":
10571
+ return "#8b5cf6";
10572
+ case "io":
10573
+ return "#3b82f6";
10574
+ case "human":
10575
+ return "#ec4899";
10576
+ case "output":
10577
+ return "#a855f7";
10578
+ case "layout":
10579
+ return "#64748b";
10580
+ case "annotation":
10581
+ return "#eab308";
10582
+ default:
10583
+ return "#71717a";
10584
+ }
10585
+ }
10586
+ function LaneNodeInner(props) {
10587
+ const data = props.data;
10588
+ const config = data.config ?? {};
10589
+ const title = config.title ?? data.label ?? "Lane";
10590
+ const orientation = config.orientation ?? "horizontal";
10591
+ const accent = config.color ?? data.color ?? categoryAccent("layout");
10592
+ return /* @__PURE__ */ jsxs(
10593
+ "div",
10594
+ {
10595
+ className: ["ff-lane", `ff-lane--${orientation}`, props.selected ? "ff-lane--selected" : ""].filter(Boolean).join(" "),
10596
+ style: { borderColor: props.selected ? accent : void 0 },
10597
+ children: [
10598
+ /* @__PURE__ */ jsx(NodeResizer, { isVisible: props.selected ?? false, color: accent, minWidth: 160, minHeight: 72 }),
10599
+ /* @__PURE__ */ jsx("div", { className: "ff-lane__header", style: { background: accent }, children: /* @__PURE__ */ jsx("span", { className: "ff-lane__title", children: title }) })
10600
+ ]
10601
+ }
10602
+ );
10603
+ }
10604
+ var LaneNode = memo(LaneNodeInner);
9038
10605
 
9039
- export { Background, BackgroundVariant, Controls, Handle, MiniMap, NodeResizer, NodeToolbar, Position, ReactFlowProvider, ViewportPortal, addEdge2 as addEdge, applyEdgeChanges, applyNodeChanges, index, reconnectEdge2 as reconnectEdge, useReactFlow };
9040
- //# sourceMappingURL=chunk-OWENS2H5.js.map
9041
- //# sourceMappingURL=chunk-OWENS2H5.js.map
10606
+ export { BUILTIN_KINDS, Background, BackgroundVariant, Controls, DEFAULT_MAX_DEPTH, FlowEditorProvider, Handle, LaneNode, MiniMap, NodeResizer, NodeToolbar, NoteNode, Position, ReactFlowProvider, RunIdentity, ViewportPortal, addEdge2 as addEdge, applyEdgeChanges, applyNodeChanges, categoryAccent, clearNodeKindOverrides, declaredRoutes, defaultConfigFor, ensureBuiltinKinds, escapeSegment, getNodeKind, index, kindIds, listNodeKinds, llmRouterExecutor, nodeConfig, onNodeKindsChanged, overrideNodeKind, reconnectEdge2 as reconnectEdge, registerBuiltinKinds, registerNodeKind, resolveFallbackPort, resolveKindId, resolveNodePorts, resolvePortSpec, runFlow, subflowExecutor, subflowMode, subflowPorts, useFlowEditor, useFlowEditorOptional, useReactFlow, validateConfig };
10607
+ //# sourceMappingURL=chunk-NDEX655E.js.map
10608
+ //# sourceMappingURL=chunk-NDEX655E.js.map