langflower 0.2.2 → 0.4.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 (68) hide show
  1. package/README.md +34 -29
  2. package/dist/{chunk-KOS7BXAM.js → chunk-32BC3YXC.js} +1 -1
  3. package/dist/{chunk-26UB55E5.js → chunk-5B3555QF.js} +2 -0
  4. package/dist/{chunk-X3FU465E.js → chunk-P3QJHZO7.js} +1 -1
  5. package/dist/{chunk-3Z7Q6SQ5.js → chunk-VVJLF47H.js} +93 -10
  6. package/dist/index.js +5743 -2626
  7. package/docs/{public → assets/public}/README.md +8 -1
  8. package/docs/{public → assets/public}/configuration.md +7 -0
  9. package/docs/{public → assets/public}/extending.md +9 -2
  10. package/docs/{public → assets/public}/getting-started.md +11 -4
  11. package/docs/{public → assets/public}/how-it-works.md +7 -0
  12. package/docs/{public → assets/public}/launcher.md +11 -2
  13. package/docs/{public → assets/public}/product.md +17 -3
  14. package/docs/{public → assets/public}/using-the-editor.md +7 -0
  15. package/docs/{public → assets/public}/workflows.md +7 -0
  16. package/package.json +2 -2
  17. package/ui-dist/assets/langflower-mark.svg +33 -0
  18. package/ui-dist/{chunk-IASSR2ON.js → chunk-33CXNPF2.js} +1 -1
  19. package/ui-dist/chunk-SNO65Y6K.js +4 -0
  20. package/ui-dist/index.html +2 -2
  21. package/ui-dist/main-GN43PQD5.js +323 -0
  22. package/ui-dist/styles-DMRPMU4V.css +1 -0
  23. package/vendor/node-sdk/dist/node-factory/define-llm-node/default-llm-ports.d.ts +11 -1
  24. package/vendor/node-sdk/dist/node-factory/define-llm-node/define-llm-node.d.ts +3 -1
  25. package/vendor/node-sdk/dist/node-factory/define-llm-node/define-llm-node.js +1 -0
  26. package/vendor/node-sdk/dist/node-factory/define-llm-node/steer-control.d.ts +5 -2
  27. package/vendor/node-sdk/dist/node-factory/define-llm-node/steer-control.js +3 -2
  28. package/vendor/node-sdk/dist/node-factory/define-node/define-node.d.ts +2 -1
  29. package/vendor/node-sdk/dist/node-factory/define-reactive-node/capabilities.d.ts +32 -1
  30. package/vendor/node-sdk/dist/node-factory/define-reactive-node/define-reactive-node.d.ts +3 -1
  31. package/vendor/node-sdk/dist/node-factory/define-reactive-node/define-reactive-node.js +4 -1
  32. package/vendor/node-sdk/dist/node-factory/define-reactive-node/hitl-config.d.ts +14 -0
  33. package/vendor/node-sdk/dist/node-factory/define-reactive-node/hitl-config.js +24 -1
  34. package/vendor/node-sdk/dist/node-factory/define-reactive-node/io-helpers.d.ts +13 -4
  35. package/vendor/node-sdk/dist/node-factory/define-reactive-node/port-meta.d.ts +12 -2
  36. package/vendor/node-sdk/dist/node-factory/define-reactive-node/types.d.ts +8 -0
  37. package/vendor/node-sdk/dist/node-factory/define-reactive-node/ui-schema-inference.d.ts +18 -0
  38. package/vendor/node-sdk/dist/node-state.d.ts +28 -0
  39. package/vendor/node-sdk/dist/node-state.js +1 -0
  40. package/vendor/node-sdk/package.json +1 -1
  41. package/vendor/runtime/dist/feed-log-fold.d.ts +26 -0
  42. package/vendor/runtime/dist/feed-log-fold.js +113 -0
  43. package/vendor/runtime/dist/runtime-editor.d.ts +6 -0
  44. package/vendor/runtime/dist/runtime-editor.js +95 -2
  45. package/vendor/runtime/dist/runtime-runner.d.ts +28 -3
  46. package/vendor/runtime/dist/runtime-runner.js +101 -9
  47. package/vendor/runtime/dist/runtime.d.ts +5 -1
  48. package/vendor/runtime/dist/runtime.js +2 -0
  49. package/vendor/runtime/dist/types.d.ts +91 -5
  50. package/vendor/runtime/dist/wire-type.d.ts +12 -0
  51. package/vendor/runtime/dist/wire-type.js +18 -0
  52. package/vendor/server/skeleton/instructions.md +3 -1
  53. package/vendor/server/skeleton/nodes/hello-embed/README.md +1 -1
  54. package/vendor/server/skeleton/nodes/hello-embed/package.json +1 -1
  55. package/vendor/server/skeleton/nodes/my-nodes/README.md +12 -0
  56. package/vendor/server/skeleton/nodes/my-nodes/package.json +1 -1
  57. package/vendor/server/skeleton/nodes/my-nodes/review-gate.ts +5 -0
  58. package/vendor/server/skeleton/skills/langflower-helper/SKILL.md +196 -57
  59. package/vendor/server/skeleton/skills/langflower-helper/architecture.md +50 -8
  60. package/vendor/server/skeleton/skills/langflower-helper/layout.md +33 -13
  61. package/vendor/server/skeleton/skills/langflower-node-writer/SKILL.md +25 -4
  62. package/vendor/server/skeleton/skills/langflower-workflow-writer/SKILL.md +21 -2
  63. package/vendor/server/skeleton/workflows/agents-dialog.json +1 -1
  64. package/vendor/server/skeleton/workflows/kb-rag.json +1 -1
  65. package/vendor/server/skeleton/workflows/starter.json +3 -3
  66. package/ui-dist/chunk-HEF6F5HN.js +0 -4
  67. package/ui-dist/main-66PVIOBC.js +0 -323
  68. package/ui-dist/styles-Y56BLXVS.css +0 -1
@@ -0,0 +1,113 @@
1
+ import { isPortTelemetry, } from './types.js';
2
+ const GROWING_ROLES = new Set([
3
+ 'reasoning',
4
+ 'progress',
5
+ 'draft',
6
+ 'shell',
7
+ ]);
8
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
9
+ const deepEqual = (left, right) => {
10
+ if (Object.is(left, right)) {
11
+ return true;
12
+ }
13
+ if (Array.isArray(left) || Array.isArray(right)) {
14
+ if (!Array.isArray(left) || !Array.isArray(right)) {
15
+ return false;
16
+ }
17
+ if (left.length !== right.length) {
18
+ return false;
19
+ }
20
+ for (let index = 0; index < left.length; index += 1) {
21
+ if (!deepEqual(left[index], right[index])) {
22
+ return false;
23
+ }
24
+ }
25
+ return true;
26
+ }
27
+ if (!isRecord(left) || !isRecord(right)) {
28
+ return false;
29
+ }
30
+ const leftKeys = Object.keys(left);
31
+ const rightKeys = Object.keys(right);
32
+ if (leftKeys.length !== rightKeys.length) {
33
+ return false;
34
+ }
35
+ for (const key of leftKeys) {
36
+ if (!Object.prototype.hasOwnProperty.call(right, key)) {
37
+ return false;
38
+ }
39
+ if (!deepEqual(left[key], right[key])) {
40
+ return false;
41
+ }
42
+ }
43
+ return true;
44
+ };
45
+ const sameEdgeIds = (left, right) => {
46
+ if (left.length !== right.length) {
47
+ return false;
48
+ }
49
+ for (let index = 0; index < left.length; index += 1) {
50
+ if (left[index] !== right[index]) {
51
+ return false;
52
+ }
53
+ }
54
+ return true;
55
+ };
56
+ const isStringValueResponse = (response) => 'value' in response &&
57
+ typeof response.value === 'string' &&
58
+ !('pending' in response) &&
59
+ !('error' in response) &&
60
+ !('inactive' in response);
61
+ const isGrowingFeed = (feed) => feed !== null &&
62
+ feed.streaming === true &&
63
+ feed.role !== undefined &&
64
+ GROWING_ROLES.has(feed.role);
65
+ const canMergePortFrames = (tail, event) => {
66
+ if (tail[0] !== event[0] ||
67
+ tail[1] !== event[1] ||
68
+ tail[2] !== event[2] ||
69
+ tail[4] !== event[4]) {
70
+ return false;
71
+ }
72
+ if (!sameEdgeIds(tail[5], event[5]) || !deepEqual(tail[6], event[6])) {
73
+ return false;
74
+ }
75
+ if (!isGrowingFeed(tail[6]) || !isGrowingFeed(event[6])) {
76
+ return false;
77
+ }
78
+ return isStringValueResponse(tail[3]) && isStringValueResponse(event[3]);
79
+ };
80
+ const isOpenStreamingFrame = (event) => isPortTelemetry(event) &&
81
+ isGrowingFeed(event[6]) &&
82
+ isStringValueResponse(event[3]);
83
+ const mergedFrame = (tail, event) => {
84
+ const previous = tail[3];
85
+ const next = event[3];
86
+ if (!isStringValueResponse(previous) || !isStringValueResponse(next)) {
87
+ return undefined;
88
+ }
89
+ return [
90
+ tail[0],
91
+ tail[1],
92
+ tail[2],
93
+ { value: previous.value + next.value },
94
+ tail[4],
95
+ tail[5],
96
+ tail[6],
97
+ ];
98
+ };
99
+ export const foldFeedLogEvent = (tail, event) => {
100
+ if (tail !== undefined &&
101
+ isPortTelemetry(tail) &&
102
+ isPortTelemetry(event) &&
103
+ canMergePortFrames(tail, event)) {
104
+ const frame = mergedFrame(tail, event);
105
+ if (frame !== undefined) {
106
+ return { kind: 'merge', frame };
107
+ }
108
+ }
109
+ if (isOpenStreamingFrame(event)) {
110
+ return { kind: 'open', frame: event };
111
+ }
112
+ return { kind: 'closed' };
113
+ };
@@ -45,5 +45,11 @@ export declare class RuntimeEditor implements RuntimeEditorApi {
45
45
  private isEdgeWireCompatible;
46
46
  private resolveOutputEffectiveWireType;
47
47
  private resolveInputPinnedWireType;
48
+ /**
49
+ * Declared continuation channels (`fromInput` or `rewireFrom`).
50
+ * One incoming edge fans out. Several incoming edges into a single
51
+ * output are left unwired. Bypass outputs pair by slot index.
52
+ */
53
+ private planRemovalSplices;
48
54
  private cleanupInvalidEdges;
49
55
  }
@@ -1,5 +1,6 @@
1
1
  import { getBypassConnection, isBypassPort, materializeBypassNodeOnAdd, materializeBypassSlot, } from './bypass-ports.js';
2
2
  import { edgeKey, slotKey } from './port-meta.js';
3
+ import { wireTypesCompatible } from './wire-type.js';
3
4
  import { detectGraphClusters, resolveClusterForNode, } from './runtime-helpers.js';
4
5
  export class RuntimeEditor {
5
6
  /** Node ID -> node definition. */
@@ -138,12 +139,18 @@ export class RuntimeEditor {
138
139
  if (node === undefined) {
139
140
  return false;
140
141
  }
142
+ // Plan while incident edges still exist. Insert splices before
143
+ // cleanup so a downstream passthrough keeps a type pin.
144
+ const splices = this.planRemovalSplices(nodeId);
141
145
  this.nodes.delete(nodeId);
142
146
  for (const [edgeId, edge] of this.edges.entries()) {
143
147
  if (edge.fromNodeId === nodeId || edge.toNodeId === nodeId) {
144
148
  this.edges.delete(edgeId);
145
149
  }
146
150
  }
151
+ for (const splice of splices) {
152
+ this.addEdge(splice);
153
+ }
147
154
  this.cleanupInvalidEdges();
148
155
  this.refreshClusters();
149
156
  return node;
@@ -331,11 +338,17 @@ export class RuntimeEditor {
331
338
  if (sourceWireType === 'any' || inputMeta.wireType === 'any') {
332
339
  return true;
333
340
  }
334
- if (inputMeta.wireType !== 'dynamic') {
341
+ if (typeof sourceWireType === 'symbol' ||
342
+ typeof inputMeta.wireType === 'symbol') {
335
343
  return sourceWireType === inputMeta.wireType;
336
344
  }
345
+ if (inputMeta.wireType !== 'dynamic') {
346
+ return wireTypesCompatible(sourceWireType, inputMeta.wireType);
347
+ }
337
348
  const pinnedWireType = this.resolveInputPinnedWireType(edge.toNodeId, toPortId, new Set(), isBypassPort(toNode, toPortId) ? toSlotIndex : undefined);
338
- return (pinnedWireType === undefined || pinnedWireType === sourceWireType);
349
+ return (pinnedWireType === undefined ||
350
+ typeof pinnedWireType === 'symbol' ||
351
+ wireTypesCompatible(sourceWireType, pinnedWireType));
339
352
  }
340
353
  resolveOutputEffectiveWireType(nodeId, portId, slotIndex, visitedOutputKeys) {
341
354
  const outKey = slotKey(nodeId, portId, slotIndex);
@@ -426,6 +439,73 @@ export class RuntimeEditor {
426
439
  }
427
440
  return undefined;
428
441
  }
442
+ /**
443
+ * Declared continuation channels (`fromInput` or `rewireFrom`).
444
+ * One incoming edge fans out. Several incoming edges into a single
445
+ * output are left unwired. Bypass outputs pair by slot index.
446
+ */
447
+ planRemovalSplices(nodeId) {
448
+ const node = this.nodes.get(nodeId);
449
+ if (node === undefined) {
450
+ return [];
451
+ }
452
+ const channels = new Map();
453
+ for (const output of Object.values(node.outputs)) {
454
+ const sourceInput = output.meta.rewireFrom ?? output.meta.fromInput;
455
+ if (sourceInput === undefined ||
456
+ typeof output.meta.portId !== 'string') {
457
+ continue;
458
+ }
459
+ const outputPortId = output.meta.portId;
460
+ const key = `${sourceInput}\0${outputPortId}`;
461
+ if (!channels.has(key)) {
462
+ channels.set(key, { sourceInput, outputPortId });
463
+ }
464
+ }
465
+ const splices = [];
466
+ for (const channel of channels.values()) {
467
+ const inEdges = [];
468
+ const outEdges = [];
469
+ for (const edge of this.edges.values()) {
470
+ if (edge.toNodeId === nodeId &&
471
+ edge.toPort[0] === channel.sourceInput) {
472
+ inEdges.push(edge);
473
+ }
474
+ if (edge.fromNodeId === nodeId &&
475
+ edge.fromPort[0] === channel.outputPortId) {
476
+ outEdges.push(edge);
477
+ }
478
+ }
479
+ if (inEdges.length === 0 || outEdges.length === 0) {
480
+ continue;
481
+ }
482
+ if (isBypassPort(node, channel.outputPortId)) {
483
+ for (const outEdge of outEdges) {
484
+ const sources = inEdges.filter((edge) => edge.toPort[1] === outEdge.fromPort[1]);
485
+ if (sources.length !== 1) {
486
+ continue;
487
+ }
488
+ const source = sources[0];
489
+ if (source === undefined) {
490
+ continue;
491
+ }
492
+ pushSplice(splices, nodeId, source, outEdge);
493
+ }
494
+ continue;
495
+ }
496
+ if (inEdges.length !== 1) {
497
+ continue;
498
+ }
499
+ const source = inEdges[0];
500
+ if (source === undefined) {
501
+ continue;
502
+ }
503
+ for (const outEdge of outEdges) {
504
+ pushSplice(splices, nodeId, source, outEdge);
505
+ }
506
+ }
507
+ return splices;
508
+ }
429
509
  cleanupInvalidEdges() {
430
510
  const removed = [];
431
511
  let removedEdge = true;
@@ -442,3 +522,16 @@ export class RuntimeEditor {
442
522
  return removed;
443
523
  }
444
524
  }
525
+ const pushSplice = (splices, removedNodeId, incoming, outgoing) => {
526
+ if (incoming.fromNodeId === removedNodeId ||
527
+ outgoing.toNodeId === removedNodeId ||
528
+ incoming.fromNodeId === outgoing.toNodeId) {
529
+ return;
530
+ }
531
+ splices.push({
532
+ fromNodeId: incoming.fromNodeId,
533
+ fromPort: incoming.fromPort,
534
+ toNodeId: outgoing.toNodeId,
535
+ toPort: outgoing.toPort,
536
+ });
537
+ };
@@ -1,11 +1,14 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { RuntimeEditor } from './runtime-editor.js';
3
- import { RuntimeOptions, RuntimeResumeOptions, RuntimeRunnerApi, RuntimeRunnerEvent, RuntimeRunnerStatus, RuntimeSeedPortValue, type NodeId, type RunId } from './types.js';
3
+ import { RuntimeOptions, RuntimeResumeOptions, RuntimeRunnerApi, RuntimeRunnerEvent, RuntimeRunnerStatus, RuntimeSeedPortValue, type NodeStateJson, type RuntimeNodeStates, type NodeId, type RunId } from './types.js';
4
4
  export declare class RuntimeRunner implements RuntimeRunnerApi {
5
5
  private readonly editor;
6
6
  private static readonly EMPTY_EVENT_LOG;
7
7
  private readonly statusSubject;
8
8
  private readonly eventsSubject;
9
+ private readonly nodeStateSubject;
10
+ private nodeStateSub;
11
+ private readonly restoreFailures;
9
12
  private readonly logEvents;
10
13
  private readonly eventLogBuffer;
11
14
  private activeRun;
@@ -16,10 +19,22 @@ export declare class RuntimeRunner implements RuntimeRunnerApi {
16
19
  /** Synchronous snapshot of {@link status$}. */
17
20
  get status(): RuntimeRunnerStatus;
18
21
  readonly events$: Observable<RuntimeRunnerEvent>;
22
+ readonly nodeState$: Observable<{
23
+ readonly nodeId: string;
24
+ readonly state: NodeStateJson;
25
+ }>;
26
+ get lastRestoreFailures(): readonly {
27
+ readonly nodeId: string;
28
+ readonly message: string;
29
+ }[];
19
30
  readonly eventLog: readonly RuntimeRunnerEvent[];
20
31
  constructor(editor: RuntimeEditor, options?: RuntimeOptions);
21
- start(initialPayload?: Readonly<Record<string, ReadonlyArray<RuntimeSeedPortValue>>>, runId?: RunId): RunId | false;
22
- startNode(nodeId: NodeId, initialPayload?: Readonly<Record<string, ReadonlyArray<RuntimeSeedPortValue>>>, runId?: RunId): RunId | false;
32
+ start(initialPayload?: Readonly<Record<string, ReadonlyArray<RuntimeSeedPortValue>>>, runId?: RunId, options?: {
33
+ readonly nodeStates?: RuntimeNodeStates;
34
+ }): RunId | false;
35
+ startNode(nodeId: NodeId, initialPayload?: Readonly<Record<string, ReadonlyArray<RuntimeSeedPortValue>>>, runId?: RunId, options?: {
36
+ readonly nodeStates?: RuntimeNodeStates;
37
+ }): RunId | false;
23
38
  resume(options: RuntimeResumeOptions): RunId | false;
24
39
  pushIntoInput(cfg: {
25
40
  nodeId: NodeId;
@@ -30,6 +45,7 @@ export declare class RuntimeRunner implements RuntimeRunnerApi {
30
45
  /** Ends the active run with `done` when no `stopsRun` node can fire. */
31
46
  completeRun(): void;
32
47
  clearEventLog(): void;
48
+ seedEventLog(events: readonly RuntimeRunnerEvent[]): void;
33
49
  dispose(): void;
34
50
  private assertNotDisposed;
35
51
  private setStatus;
@@ -63,6 +79,15 @@ export declare class RuntimeRunner implements RuntimeRunnerApi {
63
79
  private tapInputPort;
64
80
  private finishRun;
65
81
  private assertResumeOutputSnapshots;
82
+ private clearRestoreFailures;
83
+ /**
84
+ * Restore every hooked in-scope node before wiring. A missing map entry
85
+ * is `null` so a pending restore from the previous run cannot stick.
86
+ * `{ ok: false }` is recorded and the run continues.
87
+ */
88
+ private restoreScopedNodeStates;
89
+ /** Merge `persist$` of hooked in-scope nodes for this run only. */
90
+ private subscribeScopedNodeState;
66
91
  private cancelPendingWire;
67
92
  private flushPendingWire;
68
93
  private runScope;
@@ -1,6 +1,7 @@
1
1
  import { combineStatefulObservables, serializeResponse, statefulObservable, } from '@rx-evo/stateful-observable';
2
- import { BehaviorSubject, filter, isObservable, merge, of, Subject, Subscription, tap, zip, } from 'rxjs';
2
+ import { BehaviorSubject, filter, isObservable, map, merge, of, Subject, Subscription, tap, zip, } from 'rxjs';
3
3
  import { checkpointPortIdForSlot, getBypassConnection, isBypassPort, } from './bypass-ports.js';
4
+ import { foldFeedLogEvent } from './feed-log-fold.js';
4
5
  import { normalizePortErrorValue } from './normalize-port-error-value.js';
5
6
  import { edgePortSlotKey, parseSlotKey, slotKey, } from './port-meta.js';
6
7
  import { clusterHasChatEntry, collectClusterSlotKeys, } from './runtime-helpers.js';
@@ -24,6 +25,9 @@ export class RuntimeRunner {
24
25
  static EMPTY_EVENT_LOG = [];
25
26
  statusSubject = new BehaviorSubject('idle');
26
27
  eventsSubject = new Subject();
28
+ nodeStateSubject = new Subject();
29
+ nodeStateSub;
30
+ restoreFailures = [];
27
31
  logEvents;
28
32
  eventLogBuffer = [];
29
33
  activeRun;
@@ -36,6 +40,10 @@ export class RuntimeRunner {
36
40
  return this.statusSubject.value;
37
41
  }
38
42
  events$ = this.eventsSubject.asObservable();
43
+ nodeState$ = this.nodeStateSubject.asObservable();
44
+ get lastRestoreFailures() {
45
+ return this.restoreFailures;
46
+ }
39
47
  eventLog;
40
48
  constructor(editor, options = {}) {
41
49
  this.editor = editor;
@@ -44,7 +52,7 @@ export class RuntimeRunner {
44
52
  ? this.eventLogBuffer
45
53
  : RuntimeRunner.EMPTY_EVENT_LOG;
46
54
  }
47
- start(initialPayload, runId) {
55
+ start(initialPayload, runId, options) {
48
56
  this.assertNotDisposed();
49
57
  if (this.statusSubject.value === 'running') {
50
58
  return false;
@@ -52,6 +60,7 @@ export class RuntimeRunner {
52
60
  const resolvedRunId = runId ?? crypto.randomUUID();
53
61
  const nodes = this.editor.getNodes();
54
62
  if (nodes.length === 0) {
63
+ this.clearRestoreFailures();
55
64
  this.setStatus('running');
56
65
  this.finishRun(resolvedRunId);
57
66
  return resolvedRunId;
@@ -70,14 +79,14 @@ export class RuntimeRunner {
70
79
  scopeEdgeIds.add(edgeId);
71
80
  }
72
81
  }
73
- return this.runScope(scopeNodeIds, scopeEdgeIds, initialPayload, resolvedRunId);
82
+ return this.runScope(scopeNodeIds, scopeEdgeIds, initialPayload, resolvedRunId, undefined, options?.nodeStates);
74
83
  }
75
- startNode(nodeId, initialPayload, runId) {
84
+ startNode(nodeId, initialPayload, runId, options) {
76
85
  const cluster = this.editor.getClusterByNodeId(nodeId);
77
86
  if (cluster === false) {
78
87
  return false;
79
88
  }
80
- return this.runScope(cluster.nodeIds, cluster.edgeIds, initialPayload, runId);
89
+ return this.runScope(cluster.nodeIds, cluster.edgeIds, initialPayload, runId, undefined, options?.nodeStates);
81
90
  }
82
91
  resume(options) {
83
92
  this.assertNotDisposed();
@@ -93,6 +102,7 @@ export class RuntimeRunner {
93
102
  const edges = this.editor.getEdges();
94
103
  const resolvedRunId = options.runId ?? crypto.randomUUID();
95
104
  if (nodes.some((node) => node.stopsRun === true && completedNodeIds.has(node.nodeId))) {
105
+ this.clearRestoreFailures();
96
106
  this.editor.setLocked(true);
97
107
  this.setStatus('running');
98
108
  this.activeRun = {
@@ -107,6 +117,7 @@ export class RuntimeRunner {
107
117
  return resolvedRunId;
108
118
  }
109
119
  if (nodes.length === 0) {
120
+ this.clearRestoreFailures();
110
121
  this.setStatus('running');
111
122
  this.finishRun(resolvedRunId);
112
123
  return resolvedRunId;
@@ -115,7 +126,7 @@ export class RuntimeRunner {
115
126
  return this.runScope(new Set(nodes.map((node) => node.nodeId)), new Set(edges.map((edge) => edge.edgeId)), options.initialPayload, resolvedRunId, {
116
127
  completedNodeIds,
117
128
  outputSnapshots,
118
- });
129
+ }, options.nodeStates);
119
130
  }
120
131
  pushIntoInput(cfg) {
121
132
  this.assertNotDisposed();
@@ -169,6 +180,15 @@ export class RuntimeRunner {
169
180
  this.eventLogBuffer.length = 0;
170
181
  }
171
182
  }
183
+ seedEventLog(events) {
184
+ this.assertNotDisposed();
185
+ if (!this.logEvents || this.statusSubject.value !== 'idle') {
186
+ return;
187
+ }
188
+ const next = [...events];
189
+ this.eventLogBuffer.length = 0;
190
+ this.eventLogBuffer.push(...next);
191
+ }
172
192
  dispose() {
173
193
  if (this.disposed) {
174
194
  return;
@@ -187,6 +207,9 @@ export class RuntimeRunner {
187
207
  if (!this.eventsSubject.closed) {
188
208
  this.eventsSubject.complete();
189
209
  }
210
+ if (!this.nodeStateSubject.closed) {
211
+ this.nodeStateSubject.complete();
212
+ }
190
213
  }
191
214
  assertNotDisposed() {
192
215
  if (this.disposed) {
@@ -204,7 +227,15 @@ export class RuntimeRunner {
204
227
  return;
205
228
  }
206
229
  if (this.logEvents) {
207
- this.eventLogBuffer.push(event);
230
+ const tail = this.eventLogBuffer[this.eventLogBuffer.length - 1];
231
+ const step = foldFeedLogEvent(tail, event);
232
+ if (step.kind === 'merge') {
233
+ this.eventLogBuffer[this.eventLogBuffer.length - 1] =
234
+ step.frame;
235
+ }
236
+ else {
237
+ this.eventLogBuffer.push(event);
238
+ }
208
239
  }
209
240
  this.eventsSubject.next(event);
210
241
  }
@@ -378,6 +409,55 @@ export class RuntimeRunner {
378
409
  }
379
410
  }
380
411
  }
412
+ clearRestoreFailures() {
413
+ this.restoreFailures.length = 0;
414
+ }
415
+ /**
416
+ * Restore every hooked in-scope node before wiring. A missing map entry
417
+ * is `null` so a pending restore from the previous run cannot stick.
418
+ * `{ ok: false }` is recorded and the run continues.
419
+ */
420
+ restoreScopedNodeStates(scopeNodeIds, nodeStates) {
421
+ this.clearRestoreFailures();
422
+ for (const nodeId of scopeNodeIds) {
423
+ const node = this.editor.getNode(nodeId);
424
+ if (node === false || node.state === undefined) {
425
+ continue;
426
+ }
427
+ const result = node.state.restore(nodeStates?.[nodeId] ?? null);
428
+ if (!result.ok) {
429
+ this.restoreFailures.push({
430
+ nodeId,
431
+ message: result.message,
432
+ });
433
+ }
434
+ }
435
+ }
436
+ /** Merge `persist$` of hooked in-scope nodes for this run only. */
437
+ subscribeScopedNodeState(scopeNodeIds) {
438
+ this.nodeStateSub?.unsubscribe();
439
+ this.nodeStateSub = undefined;
440
+ const streams = [];
441
+ for (const nodeId of scopeNodeIds) {
442
+ const node = this.editor.getNode(nodeId);
443
+ if (node === false || node.state === undefined) {
444
+ continue;
445
+ }
446
+ streams.push(node.state.persist$.pipe(map((state) => ({
447
+ nodeId,
448
+ state,
449
+ }))));
450
+ }
451
+ if (streams.length === 0) {
452
+ return;
453
+ }
454
+ this.nodeStateSub = merge(...streams).subscribe((event) => {
455
+ if (this.disposed || this.nodeStateSubject.closed) {
456
+ return;
457
+ }
458
+ this.nodeStateSubject.next(event);
459
+ });
460
+ }
381
461
  cancelPendingWire() {
382
462
  this.pendingWire = undefined;
383
463
  this.pendingWireRunId = undefined;
@@ -391,20 +471,29 @@ export class RuntimeRunner {
391
471
  this.pendingWireRunId = undefined;
392
472
  wire();
393
473
  }
394
- runScope(scopeNodeIds, scopeEdgeIds, initialPayload, runId, resumeOverlay) {
474
+ runScope(scopeNodeIds, scopeEdgeIds, initialPayload, runId, resumeOverlay, nodeStates) {
395
475
  this.assertNotDisposed();
396
476
  if (this.statusSubject.value === 'running') {
397
477
  return false;
398
478
  }
479
+ // Resume keeps the log so a later phase can seed it. Empty-graph
480
+ // starts never enter runScope, so they leave the log as it is.
481
+ if (resumeOverlay === undefined) {
482
+ this.eventLogBuffer.length = 0;
483
+ }
399
484
  const resolvedRunId = runId ?? crypto.randomUUID();
485
+ this.restoreScopedNodeStates(scopeNodeIds, nodeStates);
400
486
  this.setStatus('running');
401
487
  this.editor.setLocked(true);
488
+ this.subscribeScopedNodeState(scopeNodeIds);
402
489
  this.pendingWireRunId = resolvedRunId;
403
490
  this.pendingWire = () => {
404
491
  try {
405
492
  this.activeRun = this.wireScope(resolvedRunId, scopeEdgeIds, scopeNodeIds, initialPayload, resumeOverlay);
406
493
  }
407
494
  catch (error) {
495
+ this.nodeStateSub?.unsubscribe();
496
+ this.nodeStateSub = undefined;
408
497
  this.editor.setLocked(false);
409
498
  this.setStatus('idle');
410
499
  throw error;
@@ -425,6 +514,8 @@ export class RuntimeRunner {
425
514
  }
426
515
  teardownRun() {
427
516
  this.cancelPendingWire();
517
+ this.nodeStateSub?.unsubscribe();
518
+ this.nodeStateSub = undefined;
428
519
  if (this.activeRun === undefined) {
429
520
  this.editor.setLocked(false);
430
521
  return;
@@ -466,7 +557,8 @@ export class RuntimeRunner {
466
557
  : of(seed.value);
467
558
  connection.connect(source$.pipe(tap({
468
559
  next: (value) => {
469
- if (typeof seed.portId !== 'symbol') {
560
+ if (typeof seed.portId !== 'symbol' &&
561
+ seed.silent !== true) {
470
562
  this.emitPortEvent(runId, 'in', nodeId, seed.portId, seed.slotIndex, value, [], connection.meta.feed);
471
563
  }
472
564
  },
@@ -3,9 +3,13 @@ import { RuntimeRunner } from './runtime-runner.js';
3
3
  import type { RuntimeOptions } from './types.js';
4
4
  export { bypassOutputPortId, parseBypassOutputPortId } from './bypass-ports.js';
5
5
  export { RuntimeEditor } from './runtime-editor.js';
6
+ export { formatWireType, wireTypeIs, wireTypeList, wireTypesCompatible, } from './wire-type.js';
7
+ export type { WireTypeSpec } from './wire-type.js';
6
8
  export type { GraphCluster } from './runtime-helpers.js';
9
+ export { foldFeedLogEvent } from './feed-log-fold.js';
10
+ export type { FeedLogFoldStep } from './feed-log-fold.js';
7
11
  export { RuntimeRunner } from './runtime-runner.js';
8
- export type { MetaFromStatefulObservable, NodeId, EdgeId, RunId, PortMeta, RuntimeEdge, RuntimeEditorApi, RuntimeFeedPortMeta, RuntimeFeedRole, PortTelemetry, RuntimeDoneTelemetry, RuntimeNode, RuntimeResumeOptions, RuntimeRunnerApi, RuntimeRunnerEvent, RuntimeRunnerStatus, RuntimeSeedPortValue, RuntimeWireType, SwapNodeResult, } from './types.js';
12
+ export type { MetaFromStatefulObservable, NodeId, EdgeId, RunId, PortMeta, RuntimeEdge, RuntimeEditorApi, RuntimeFeedPortMeta, RuntimeFeedRole, PortTelemetry, RuntimeDoneTelemetry, NodeStateHook, NodeStateJson, RuntimeNode, RuntimeNodeStates, RuntimeResumeOptions, RuntimeRunnerApi, RuntimeRunnerEvent, RuntimeRunnerStatus, RuntimeSeedPortValue, RuntimeWireType, SwapNodeResult, } from './types.js';
9
13
  export { isPortErrorTelemetry, isPortPendingTelemetry, isPortTelemetry, isPortValueTelemetry, isRuntimeDone, } from './types.js';
10
14
  export type { RuntimeOptions };
11
15
  export type { ResponseDto } from '@rx-evo/stateful-observable';
@@ -2,6 +2,8 @@ import { RuntimeEditor } from './runtime-editor.js';
2
2
  import { RuntimeRunner } from './runtime-runner.js';
3
3
  export { bypassOutputPortId, parseBypassOutputPortId } from './bypass-ports.js';
4
4
  export { RuntimeEditor } from './runtime-editor.js';
5
+ export { formatWireType, wireTypeIs, wireTypeList, wireTypesCompatible, } from './wire-type.js';
6
+ export { foldFeedLogEvent } from './feed-log-fold.js';
5
7
  export { RuntimeRunner } from './runtime-runner.js';
6
8
  export { isPortErrorTelemetry, isPortPendingTelemetry, isPortTelemetry, isPortValueTelemetry, isRuntimeDone, } from './types.js';
7
9
  export class RuntimeFacade {