@particle-academy/fancy-flow 0.14.0 → 0.15.1

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 (42) hide show
  1. package/README.md +48 -0
  2. package/dist/{capabilities-D-V9Rxv1.d.cts → capabilities-BEbLqnJU.d.cts} +1 -1
  3. package/dist/{capabilities-B6r1Snfj.d.ts → capabilities-CI3gw0C7.d.ts} +1 -1
  4. package/dist/chunk-UEOE6B52.js +39 -0
  5. package/dist/chunk-UEOE6B52.js.map +1 -0
  6. package/dist/{chunk-7U3EP4Q5.js → chunk-ZQBWPYTI.js} +5 -2
  7. package/dist/chunk-ZQBWPYTI.js.map +1 -0
  8. package/dist/engine.cjs +299 -0
  9. package/dist/engine.cjs.map +1 -1
  10. package/dist/engine.d.cts +205 -27
  11. package/dist/engine.d.ts +205 -27
  12. package/dist/engine.js +258 -2
  13. package/dist/engine.js.map +1 -1
  14. package/dist/index.cjs +45 -0
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +7 -6
  17. package/dist/index.d.ts +7 -6
  18. package/dist/index.js +3 -2
  19. package/dist/index.js.map +1 -1
  20. package/dist/llm/vercel-ai.d.cts +2 -2
  21. package/dist/llm/vercel-ai.d.ts +2 -2
  22. package/dist/pause-9iT4tCEV.d.cts +96 -0
  23. package/dist/pause-9iT4tCEV.d.ts +96 -0
  24. package/dist/registry/index.d.cts +6 -5
  25. package/dist/registry/index.d.ts +6 -5
  26. package/dist/registry.cjs +45 -0
  27. package/dist/registry.cjs.map +1 -1
  28. package/dist/registry.js +2 -1
  29. package/dist/run-flow-ChBi6q-W.d.ts +35 -0
  30. package/dist/run-flow-VKm57Hcj.d.cts +35 -0
  31. package/dist/runtime/index.d.cts +3 -3
  32. package/dist/runtime/index.d.ts +3 -3
  33. package/dist/schema/index.d.cts +1 -1
  34. package/dist/schema/index.d.ts +1 -1
  35. package/dist/{types-H60tQAxr.d.cts → types-D_jOR3Z2.d.cts} +12 -1
  36. package/dist/{types-CnnKPnpt.d.ts → types-NerkPtHS.d.ts} +12 -1
  37. package/dist/{types-fc0fFKkf.d.cts → types-sOmpCitB.d.cts} +1 -1
  38. package/dist/{types-fc0fFKkf.d.ts → types-sOmpCitB.d.ts} +1 -1
  39. package/dist/ux.d.cts +3 -2
  40. package/dist/ux.d.ts +3 -2
  41. package/package.json +1 -1
  42. package/dist/chunk-7U3EP4Q5.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { LanguageModel } from 'ai';
2
- import { L as LlmRouteRequest, a as LlmClient } from '../capabilities-D-V9Rxv1.cjs';
3
- import '../types-fc0fFKkf.cjs';
2
+ import { L as LlmRouteRequest, a as LlmClient } from '../capabilities-BEbLqnJU.cjs';
3
+ import '../types-sOmpCitB.cjs';
4
4
  import '@xyflow/react';
5
5
 
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import { LanguageModel } from 'ai';
2
- import { L as LlmRouteRequest, a as LlmClient } from '../capabilities-B6r1Snfj.js';
3
- import '../types-fc0fFKkf.js';
2
+ import { L as LlmRouteRequest, a as LlmClient } from '../capabilities-CI3gw0C7.js';
3
+ import '../types-sOmpCitB.js';
4
4
  import '@xyflow/react';
5
5
 
6
6
  /**
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The human-pause contract.
3
+ *
4
+ * A workflow that waits for a person is not an error, but it travels the same
5
+ * channel as one: the executor aborts, the engine records a reason string, and
6
+ * the durable runner decides whether that string meant "failed" or "waiting".
7
+ *
8
+ * That seam existed before this module, as two `str_starts_with` checks in the
9
+ * Laravel run job against constants owned by two BUILTIN executors. It worked,
10
+ * and it was invisible: a third-party human-input node had no way to announce
11
+ * that it pauses, and nothing stopped a refactor from removing the mechanism
12
+ * out from under published packages. Reported by the MOIC Suite consumer, who
13
+ * needed exactly that and had to reach for a private constant to get it.
14
+ *
15
+ * So the encoding is now public, typed, and versioned by prefix rather than
16
+ * implied. The wire format stays a plain string on purpose — it survives the
17
+ * existing abort → `RunResult.error` path unchanged, crosses a queue boundary,
18
+ * and decodes identically in PHP, none of which a thrown class would do.
19
+ *
20
+ * @see decodePause — the one function a durable runner needs.
21
+ */
22
+ /**
23
+ * What the run is waiting for.
24
+ *
25
+ * `approval` and `input` are the shapes both runtimes ship. The type stays open
26
+ * because the whole point is that a marketplace node can define its own —
27
+ * a signature step, a payment confirmation, a review queue — and a runner that
28
+ * does not recognise one should report it rather than guess.
29
+ */
30
+ type PauseAwaiting = "approval" | "input" | (string & {});
31
+ /** A run halted, waiting for a person. */
32
+ type PauseSignal = {
33
+ /** The node that paused — where a submission gets injected on resume. */
34
+ nodeId: string;
35
+ awaiting: PauseAwaiting;
36
+ /**
37
+ * Kind-supplied context for whoever renders the wait — a form schema, the
38
+ * question being asked, a diff to approve. Must be JSON-serializable: it
39
+ * crosses a queue boundary and, for durable runs, a database column.
40
+ */
41
+ detail?: unknown;
42
+ };
43
+ /** Marks a reason string as a pause rather than a failure. */
44
+ declare const PAUSE_PREFIX = "fancy-flow:pause:";
45
+ /**
46
+ * Reason prefixes shipped before this contract, kept decodable forever.
47
+ *
48
+ * These are what `DurableApprovalExecutor` and `DurableUserInputExecutor`
49
+ * emitted, and they are written into the `error` column of every run that
50
+ * paused under an older version. Dropping them would strand those runs
51
+ * mid-flight — a resume path that only works for new runs is not a resume path.
52
+ */
53
+ declare const LEGACY_PAUSE_PREFIXES: ReadonlyArray<readonly [string, PauseAwaiting]>;
54
+ /**
55
+ * Encode a pause as the reason string an executor aborts with.
56
+ *
57
+ * The payload is JSON rather than delimited fields because a node id may
58
+ * contain a colon, and a positional encoding that breaks on user data is the
59
+ * kind of bug that only shows up in someone else's graph.
60
+ */
61
+ declare function encodePause(signal: PauseSignal): string;
62
+ /**
63
+ * Decode a run's error reason into a pause, or null if it was a real failure.
64
+ *
65
+ * This is the whole contract from a runner's side: call it on `result.error`,
66
+ * and if it returns non-null, persist the run as waiting on `signal.nodeId`
67
+ * instead of failing it. Accepts the legacy prefixes, so a runner written
68
+ * against this handles runs that paused under an older version.
69
+ */
70
+ declare function decodePause(reason: string | null | undefined): PauseSignal | null;
71
+ /** True when a run's error reason is actually a pause. */
72
+ declare function isPause(reason: string | null | undefined): boolean;
73
+ /**
74
+ * Abort the current node as a pause.
75
+ *
76
+ * Called from inside an executor with its own context. Node authors should
77
+ * reach for this rather than hand-encoding a reason, so the format stays ours
78
+ * to change:
79
+ *
80
+ * ```ts
81
+ * const values = ctx.inputs.values;
82
+ * if (values === undefined) pauseForHuman(ctx, "input", { fields });
83
+ * return values;
84
+ * ```
85
+ *
86
+ * Note the `undefined` check — an empty submission (`{}`) is a real answer and
87
+ * must resume. Truthiness here pauses forever on an empty form.
88
+ */
89
+ declare function pauseForHuman(ctx: {
90
+ node: {
91
+ id: string;
92
+ };
93
+ abort: (reason?: string) => never;
94
+ }, awaiting: PauseAwaiting, detail?: unknown): never;
95
+
96
+ export { LEGACY_PAUSE_PREFIXES as L, type PauseAwaiting as P, PAUSE_PREFIX as a, type PauseSignal as b, decodePause as d, encodePause as e, isPause as i, pauseForHuman as p };
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The human-pause contract.
3
+ *
4
+ * A workflow that waits for a person is not an error, but it travels the same
5
+ * channel as one: the executor aborts, the engine records a reason string, and
6
+ * the durable runner decides whether that string meant "failed" or "waiting".
7
+ *
8
+ * That seam existed before this module, as two `str_starts_with` checks in the
9
+ * Laravel run job against constants owned by two BUILTIN executors. It worked,
10
+ * and it was invisible: a third-party human-input node had no way to announce
11
+ * that it pauses, and nothing stopped a refactor from removing the mechanism
12
+ * out from under published packages. Reported by the MOIC Suite consumer, who
13
+ * needed exactly that and had to reach for a private constant to get it.
14
+ *
15
+ * So the encoding is now public, typed, and versioned by prefix rather than
16
+ * implied. The wire format stays a plain string on purpose — it survives the
17
+ * existing abort → `RunResult.error` path unchanged, crosses a queue boundary,
18
+ * and decodes identically in PHP, none of which a thrown class would do.
19
+ *
20
+ * @see decodePause — the one function a durable runner needs.
21
+ */
22
+ /**
23
+ * What the run is waiting for.
24
+ *
25
+ * `approval` and `input` are the shapes both runtimes ship. The type stays open
26
+ * because the whole point is that a marketplace node can define its own —
27
+ * a signature step, a payment confirmation, a review queue — and a runner that
28
+ * does not recognise one should report it rather than guess.
29
+ */
30
+ type PauseAwaiting = "approval" | "input" | (string & {});
31
+ /** A run halted, waiting for a person. */
32
+ type PauseSignal = {
33
+ /** The node that paused — where a submission gets injected on resume. */
34
+ nodeId: string;
35
+ awaiting: PauseAwaiting;
36
+ /**
37
+ * Kind-supplied context for whoever renders the wait — a form schema, the
38
+ * question being asked, a diff to approve. Must be JSON-serializable: it
39
+ * crosses a queue boundary and, for durable runs, a database column.
40
+ */
41
+ detail?: unknown;
42
+ };
43
+ /** Marks a reason string as a pause rather than a failure. */
44
+ declare const PAUSE_PREFIX = "fancy-flow:pause:";
45
+ /**
46
+ * Reason prefixes shipped before this contract, kept decodable forever.
47
+ *
48
+ * These are what `DurableApprovalExecutor` and `DurableUserInputExecutor`
49
+ * emitted, and they are written into the `error` column of every run that
50
+ * paused under an older version. Dropping them would strand those runs
51
+ * mid-flight — a resume path that only works for new runs is not a resume path.
52
+ */
53
+ declare const LEGACY_PAUSE_PREFIXES: ReadonlyArray<readonly [string, PauseAwaiting]>;
54
+ /**
55
+ * Encode a pause as the reason string an executor aborts with.
56
+ *
57
+ * The payload is JSON rather than delimited fields because a node id may
58
+ * contain a colon, and a positional encoding that breaks on user data is the
59
+ * kind of bug that only shows up in someone else's graph.
60
+ */
61
+ declare function encodePause(signal: PauseSignal): string;
62
+ /**
63
+ * Decode a run's error reason into a pause, or null if it was a real failure.
64
+ *
65
+ * This is the whole contract from a runner's side: call it on `result.error`,
66
+ * and if it returns non-null, persist the run as waiting on `signal.nodeId`
67
+ * instead of failing it. Accepts the legacy prefixes, so a runner written
68
+ * against this handles runs that paused under an older version.
69
+ */
70
+ declare function decodePause(reason: string | null | undefined): PauseSignal | null;
71
+ /** True when a run's error reason is actually a pause. */
72
+ declare function isPause(reason: string | null | undefined): boolean;
73
+ /**
74
+ * Abort the current node as a pause.
75
+ *
76
+ * Called from inside an executor with its own context. Node authors should
77
+ * reach for this rather than hand-encoding a reason, so the format stays ours
78
+ * to change:
79
+ *
80
+ * ```ts
81
+ * const values = ctx.inputs.values;
82
+ * if (values === undefined) pauseForHuman(ctx, "input", { fields });
83
+ * return values;
84
+ * ```
85
+ *
86
+ * Note the `undefined` check — an empty submission (`{}`) is a real answer and
87
+ * must resume. Truthiness here pauses forever on an empty form.
88
+ */
89
+ declare function pauseForHuman(ctx: {
90
+ node: {
91
+ id: string;
92
+ };
93
+ abort: (reason?: string) => never;
94
+ }, awaiting: PauseAwaiting, detail?: unknown): never;
95
+
96
+ export { LEGACY_PAUSE_PREFIXES as L, type PauseAwaiting as P, PAUSE_PREFIX as a, type PauseSignal as b, decodePause as d, encodePause as e, isPause as i, pauseForHuman as p };
@@ -1,8 +1,9 @@
1
- import { a as NodeKindDefinition, P as PortSpec } from '../types-H60tQAxr.cjs';
2
- export { C as ConfigField, b as CredentialConfigField, D as DocumentConfigField, E as ExpressionConfigField, J as JsonConfigField, K as KeyValueConfigField, N as NodeCategory, c as NumberConfigField, R as RenderBodyContext, d as RepeaterConfigField, e as RepeaterRowField, S as SelectConfigField, f as SwitchConfigField, T as TextConfigField, g as TextareaConfigField } from '../types-H60tQAxr.cjs';
3
- import { a as FlowNode, P as PortDescriptor, N as NodeExecutor } from '../types-fc0fFKkf.cjs';
4
- import { b as LlmRoute } from '../capabilities-D-V9Rxv1.cjs';
5
- export { C as CapabilityId, a as LlmClient, c as LlmRouteChoice, L as LlmRouteRequest, W as WorkflowResolver, d as capabilityStatus, g as getLlmClient, e as getWorkflowResolver, r as registerLlmClient, f as registerWorkflowResolver } from '../capabilities-D-V9Rxv1.cjs';
1
+ import { a as NodeKindDefinition, P as PortSpec } from '../types-D_jOR3Z2.cjs';
2
+ export { C as ConfigField, b as CredentialConfigField, D as DocumentConfigField, E as ExpressionConfigField, J as JsonConfigField, K as KeyValueConfigField, N as NodeCategory, c as NumberConfigField, R as RenderBodyContext, d as RepeaterConfigField, e as RepeaterRowField, S as SelectConfigField, f as SwitchConfigField, T as TextConfigField, g as TextareaConfigField } from '../types-D_jOR3Z2.cjs';
3
+ import { b as FlowNode, P as PortDescriptor, N as NodeExecutor } from '../types-sOmpCitB.cjs';
4
+ import { b as LlmRoute } from '../capabilities-BEbLqnJU.cjs';
5
+ export { C as CapabilityId, a as LlmClient, c as LlmRouteChoice, L as LlmRouteRequest, W as WorkflowResolver, d as capabilityStatus, g as getLlmClient, e as getWorkflowResolver, r as registerLlmClient, f as registerWorkflowResolver } from '../capabilities-BEbLqnJU.cjs';
6
+ export { L as LEGACY_PAUSE_PREFIXES, a as PAUSE_PREFIX, P as PauseAwaiting, b as PauseSignal, d as decodePause, e as encodePause, i as isPause, p as pauseForHuman } from '../pause-9iT4tCEV.cjs';
6
7
  import * as react from 'react';
7
8
  import { ComponentType, ReactNode } from 'react';
8
9
  import { NodeProps, NodeTypes } from '@xyflow/react';
@@ -1,8 +1,9 @@
1
- import { a as NodeKindDefinition, P as PortSpec } from '../types-CnnKPnpt.js';
2
- export { C as ConfigField, b as CredentialConfigField, D as DocumentConfigField, E as ExpressionConfigField, J as JsonConfigField, K as KeyValueConfigField, N as NodeCategory, c as NumberConfigField, R as RenderBodyContext, d as RepeaterConfigField, e as RepeaterRowField, S as SelectConfigField, f as SwitchConfigField, T as TextConfigField, g as TextareaConfigField } from '../types-CnnKPnpt.js';
3
- import { a as FlowNode, P as PortDescriptor, N as NodeExecutor } from '../types-fc0fFKkf.js';
4
- import { b as LlmRoute } from '../capabilities-B6r1Snfj.js';
5
- export { C as CapabilityId, a as LlmClient, c as LlmRouteChoice, L as LlmRouteRequest, W as WorkflowResolver, d as capabilityStatus, g as getLlmClient, e as getWorkflowResolver, r as registerLlmClient, f as registerWorkflowResolver } from '../capabilities-B6r1Snfj.js';
1
+ import { a as NodeKindDefinition, P as PortSpec } from '../types-NerkPtHS.js';
2
+ export { C as ConfigField, b as CredentialConfigField, D as DocumentConfigField, E as ExpressionConfigField, J as JsonConfigField, K as KeyValueConfigField, N as NodeCategory, c as NumberConfigField, R as RenderBodyContext, d as RepeaterConfigField, e as RepeaterRowField, S as SelectConfigField, f as SwitchConfigField, T as TextConfigField, g as TextareaConfigField } from '../types-NerkPtHS.js';
3
+ import { b as FlowNode, P as PortDescriptor, N as NodeExecutor } from '../types-sOmpCitB.js';
4
+ import { b as LlmRoute } from '../capabilities-CI3gw0C7.js';
5
+ export { C as CapabilityId, a as LlmClient, c as LlmRouteChoice, L as LlmRouteRequest, W as WorkflowResolver, d as capabilityStatus, g as getLlmClient, e as getWorkflowResolver, r as registerLlmClient, f as registerWorkflowResolver } from '../capabilities-CI3gw0C7.js';
6
+ export { L as LEGACY_PAUSE_PREFIXES, a as PAUSE_PREFIX, P as PauseAwaiting, b as PauseSignal, d as decodePause, e as encodePause, i as isPause, p as pauseForHuman } from '../pause-9iT4tCEV.js';
6
7
  import * as react from 'react';
7
8
  import { ComponentType, ReactNode } from 'react';
8
9
  import { NodeProps, NodeTypes } from '@xyflow/react';
package/dist/registry.cjs CHANGED
@@ -66,6 +66,42 @@ function capabilityStatus() {
66
66
  };
67
67
  }
68
68
 
69
+ // src/registry/pause.ts
70
+ var PAUSE_PREFIX = "fancy-flow:pause:";
71
+ var LEGACY_PAUSE_PREFIXES = [
72
+ ["awaiting-approval:", "approval"],
73
+ ["awaiting-input:", "input"]
74
+ ];
75
+ function encodePause(signal) {
76
+ const { nodeId, awaiting, detail } = signal;
77
+ return PAUSE_PREFIX + JSON.stringify(detail === void 0 ? { nodeId, awaiting } : { nodeId, awaiting, detail });
78
+ }
79
+ function decodePause(reason) {
80
+ if (typeof reason !== "string") return null;
81
+ if (reason.startsWith(PAUSE_PREFIX)) {
82
+ const body = reason.slice(PAUSE_PREFIX.length);
83
+ try {
84
+ const parsed = JSON.parse(body);
85
+ if (typeof parsed?.nodeId !== "string" || typeof parsed?.awaiting !== "string") return null;
86
+ return "detail" in parsed ? { nodeId: parsed.nodeId, awaiting: parsed.awaiting, detail: parsed.detail } : { nodeId: parsed.nodeId, awaiting: parsed.awaiting };
87
+ } catch {
88
+ return null;
89
+ }
90
+ }
91
+ for (const [prefix, awaiting] of LEGACY_PAUSE_PREFIXES) {
92
+ if (reason.startsWith(prefix)) {
93
+ return { nodeId: reason.slice(prefix.length), awaiting };
94
+ }
95
+ }
96
+ return null;
97
+ }
98
+ function isPause(reason) {
99
+ return decodePause(reason) !== null;
100
+ }
101
+ function pauseForHuman(ctx, awaiting, detail) {
102
+ return ctx.abort(encodePause({ nodeId: ctx.node.id, awaiting, detail }));
103
+ }
104
+
69
105
  // src/registry/registry.ts
70
106
  var kinds = /* @__PURE__ */ new Map();
71
107
  var aliases = /* @__PURE__ */ new Map();
@@ -9636,6 +9672,7 @@ var KINDS = [
9636
9672
  {
9637
9673
  name: "@particle-academy/user_input",
9638
9674
  aliases: ["user_input", "@fancy/user_input"],
9675
+ pausesForHuman: "input",
9639
9676
  category: "human",
9640
9677
  label: "User Input",
9641
9678
  description: "Pause the flow until the user submits the configured form.",
@@ -9677,6 +9714,7 @@ var KINDS = [
9677
9714
  {
9678
9715
  name: "@particle-academy/rich_user_input",
9679
9716
  aliases: ["rich_user_input", "@fancy/rich_user_input"],
9717
+ pausesForHuman: "input",
9680
9718
  category: "human",
9681
9719
  label: "Rich User Input",
9682
9720
  description: "Pause the flow on a fully authored page \u2014 content, required reading, multi-section forms.",
@@ -10205,6 +10243,7 @@ var KINDS = [
10205
10243
  {
10206
10244
  name: "@particle-academy/human_approval",
10207
10245
  aliases: ["human_approval", "@fancy/human_approval"],
10246
+ pausesForHuman: "approval",
10208
10247
  category: "human",
10209
10248
  label: "Human Approval",
10210
10249
  description: "Pause until a human approves or denies.",
@@ -10289,17 +10328,22 @@ function buildNodeTypes() {
10289
10328
 
10290
10329
  exports.BUILTIN_KINDS = BUILTIN_KINDS;
10291
10330
  exports.DEFAULT_MAX_DEPTH = DEFAULT_MAX_DEPTH;
10331
+ exports.LEGACY_PAUSE_PREFIXES = LEGACY_PAUSE_PREFIXES;
10332
+ exports.PAUSE_PREFIX = PAUSE_PREFIX;
10292
10333
  exports.RegistryNode = RegistryNode;
10293
10334
  exports.RichInputPreview = RichInputPreview;
10294
10335
  exports.buildNodeTypes = buildNodeTypes;
10295
10336
  exports.capabilityStatus = capabilityStatus;
10296
10337
  exports.categoryAccent = categoryAccent;
10297
10338
  exports.declaredRoutes = declaredRoutes;
10339
+ exports.decodePause = decodePause;
10298
10340
  exports.defaultConfigFor = defaultConfigFor;
10341
+ exports.encodePause = encodePause;
10299
10342
  exports.getLlmClient = getLlmClient;
10300
10343
  exports.getNodeKind = getNodeKind;
10301
10344
  exports.getRichInputAdapter = getRichInputAdapter;
10302
10345
  exports.getWorkflowResolver = getWorkflowResolver;
10346
+ exports.isPause = isPause;
10303
10347
  exports.isRichInputEnabled = isRichInputEnabled;
10304
10348
  exports.kindIds = kindIds;
10305
10349
  exports.listNodeKinds = listNodeKinds;
@@ -10308,6 +10352,7 @@ exports.llmRouterExecutor = llmRouterExecutor;
10308
10352
  exports.nodeConfig = nodeConfig;
10309
10353
  exports.onNodeKindsChanged = onNodeKindsChanged;
10310
10354
  exports.onRichInputAdapterChanged = onRichInputAdapterChanged;
10355
+ exports.pauseForHuman = pauseForHuman;
10311
10356
  exports.registerBuiltinKinds = registerBuiltinKinds;
10312
10357
  exports.registerLlmClient = registerLlmClient;
10313
10358
  exports.registerNodeKind = registerNodeKind;