langflower 0.2.2 → 0.3.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.
- package/README.md +9 -5
- package/dist/index.js +2812 -736
- package/docs/public/product.md +7 -2
- package/package.json +1 -1
- package/ui-dist/assets/langflower-mark.svg +33 -0
- package/ui-dist/chunk-2F7UKSIL.js +4 -0
- package/ui-dist/{chunk-IASSR2ON.js → chunk-B3D35SQ5.js} +1 -1
- package/ui-dist/index.html +2 -2
- package/ui-dist/main-TL5G57BL.js +323 -0
- package/ui-dist/styles-O74ATCGZ.css +1 -0
- package/vendor/node-sdk/dist/node-factory/define-llm-node/define-llm-node.d.ts +2 -0
- package/vendor/node-sdk/dist/node-factory/define-llm-node/define-llm-node.js +1 -0
- package/vendor/node-sdk/dist/node-factory/define-reactive-node/define-reactive-node.d.ts +1 -0
- package/vendor/node-sdk/dist/node-factory/define-reactive-node/define-reactive-node.js +3 -1
- package/vendor/node-sdk/dist/node-factory/define-reactive-node/io-helpers.d.ts +6 -0
- package/vendor/node-sdk/dist/node-factory/define-reactive-node/port-meta.d.ts +5 -0
- package/vendor/node-sdk/dist/node-factory/define-reactive-node/types.d.ts +8 -0
- package/vendor/node-sdk/dist/node-state.d.ts +28 -0
- package/vendor/node-sdk/dist/node-state.js +1 -0
- package/vendor/runtime/dist/feed-log-fold.d.ts +26 -0
- package/vendor/runtime/dist/feed-log-fold.js +113 -0
- package/vendor/runtime/dist/runtime-editor.d.ts +6 -0
- package/vendor/runtime/dist/runtime-editor.js +86 -0
- package/vendor/runtime/dist/runtime-runner.d.ts +28 -3
- package/vendor/runtime/dist/runtime-runner.js +99 -8
- package/vendor/runtime/dist/runtime.d.ts +3 -1
- package/vendor/runtime/dist/runtime.js +1 -0
- package/vendor/runtime/dist/types.d.ts +84 -4
- package/vendor/server/skeleton/instructions.md +3 -1
- package/vendor/server/skeleton/nodes/my-nodes/README.md +12 -0
- package/vendor/server/skeleton/nodes/my-nodes/review-gate.ts +5 -0
- package/vendor/server/skeleton/skills/langflower-helper/SKILL.md +121 -21
- package/vendor/server/skeleton/skills/langflower-helper/architecture.md +37 -5
- package/vendor/server/skeleton/skills/langflower-helper/layout.md +25 -13
- package/vendor/server/skeleton/skills/langflower-node-writer/SKILL.md +22 -4
- package/vendor/server/skeleton/skills/langflower-workflow-writer/SKILL.md +20 -1
- package/vendor/server/skeleton/workflows/starter.json +3 -3
- package/ui-dist/chunk-HEF6F5HN.js +0 -4
- package/ui-dist/main-66PVIOBC.js +0 -323
- package/ui-dist/styles-Y56BLXVS.css +0 -1
|
@@ -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.
|
|
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;
|
|
@@ -4,8 +4,10 @@ import type { RuntimeOptions } from './types.js';
|
|
|
4
4
|
export { bypassOutputPortId, parseBypassOutputPortId } from './bypass-ports.js';
|
|
5
5
|
export { RuntimeEditor } from './runtime-editor.js';
|
|
6
6
|
export type { GraphCluster } from './runtime-helpers.js';
|
|
7
|
+
export { foldFeedLogEvent } from './feed-log-fold.js';
|
|
8
|
+
export type { FeedLogFoldStep } from './feed-log-fold.js';
|
|
7
9
|
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';
|
|
10
|
+
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
11
|
export { isPortErrorTelemetry, isPortPendingTelemetry, isPortTelemetry, isPortValueTelemetry, isRuntimeDone, } from './types.js';
|
|
10
12
|
export type { RuntimeOptions };
|
|
11
13
|
export type { ResponseDto } from '@rx-evo/stateful-observable';
|
|
@@ -2,6 +2,7 @@ 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 { foldFeedLogEvent } from './feed-log-fold.js';
|
|
5
6
|
export { RuntimeRunner } from './runtime-runner.js';
|
|
6
7
|
export { isPortErrorTelemetry, isPortPendingTelemetry, isPortTelemetry, isPortValueTelemetry, isRuntimeDone, } from './types.js';
|
|
7
8
|
export class RuntimeFacade {
|
|
@@ -39,6 +39,11 @@ export type PortMeta = {
|
|
|
39
39
|
readonly mode?: RuntimeInputPortMode;
|
|
40
40
|
/** Passthrough source input port id — `undefined` for non-passthrough outputs. */
|
|
41
41
|
readonly fromInput?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Input port id this output continues when the node is deleted.
|
|
44
|
+
* Does not change wire-type inference (`fromInput` does).
|
|
45
|
+
*/
|
|
46
|
+
readonly rewireFrom?: string;
|
|
42
47
|
/**
|
|
43
48
|
* Design-time default for an **unconnected** input. Applied by the runner at
|
|
44
49
|
* `start` / `startNode` when no edge targets the port (see
|
|
@@ -159,6 +164,33 @@ export declare const isPortPendingTelemetry: (event: RuntimeRunnerEvent) => even
|
|
|
159
164
|
};
|
|
160
165
|
};
|
|
161
166
|
export declare const isRuntimeDone: (event: RuntimeRunnerEvent) => event is RuntimeDoneTelemetry;
|
|
167
|
+
/**
|
|
168
|
+
* Structural twin of `@langflower/node-sdk` `NodeStateJson` (ADR-027).
|
|
169
|
+
* The author package owns the type; runtime does not import it.
|
|
170
|
+
*/
|
|
171
|
+
export type NodeStateJson = null | boolean | number | string | readonly NodeStateJson[] | {
|
|
172
|
+
readonly [key: string]: NodeStateJson;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Structural twin of `@langflower/node-sdk` `NodeStateHook` (ADR-027).
|
|
176
|
+
* Optional on {@link RuntimeNode}. The runner restores it before wiring.
|
|
177
|
+
*/
|
|
178
|
+
export type NodeStateHook = {
|
|
179
|
+
/** Full JSON-safe state after each committed unit of work. */
|
|
180
|
+
readonly persist$: Observable<NodeStateJson>;
|
|
181
|
+
/**
|
|
182
|
+
* Called by the runner before wiring. `null` starts fresh.
|
|
183
|
+
* `{ ok: false }` does not throw and does not abort the run.
|
|
184
|
+
*/
|
|
185
|
+
readonly restore: (state: NodeStateJson | null) => {
|
|
186
|
+
readonly ok: true;
|
|
187
|
+
} | {
|
|
188
|
+
readonly ok: false;
|
|
189
|
+
readonly message: string;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
/** `nodeId` → JSON state supplied to `restore` for one run. */
|
|
193
|
+
export type RuntimeNodeStates = Readonly<Record<string, NodeStateJson>>;
|
|
162
194
|
/**
|
|
163
195
|
* Seed value pushed into an input port slot on {@link RuntimeRunner.start}.
|
|
164
196
|
* Plain values are wrapped in `of`; Observables are connected as the stream.
|
|
@@ -184,6 +216,11 @@ export type RuntimeResumeOptions = {
|
|
|
184
216
|
*/
|
|
185
217
|
readonly outputSnapshots: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
186
218
|
readonly initialPayload?: Readonly<Record<string, ReadonlyArray<RuntimeSeedPortValue>>>;
|
|
219
|
+
/**
|
|
220
|
+
* JSON state passed to each hooked node's `restore`. A missing id
|
|
221
|
+
* restores `null` so a stale pending restore cannot survive the run.
|
|
222
|
+
*/
|
|
223
|
+
readonly nodeStates?: RuntimeNodeStates;
|
|
187
224
|
};
|
|
188
225
|
export type RuntimeNode = {
|
|
189
226
|
readonly nodeId: NodeId;
|
|
@@ -245,6 +282,12 @@ export type RuntimeNode = {
|
|
|
245
282
|
* metadata for factories and tests.
|
|
246
283
|
*/
|
|
247
284
|
readonly emitOncePerActivation?: boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Optional JSON state hook. The runner calls `restore` before wiring
|
|
287
|
+
* and merges `persist$` into {@link RuntimeRunnerApi.nodeState$} while
|
|
288
|
+
* this node is in the active run scope.
|
|
289
|
+
*/
|
|
290
|
+
readonly state?: NodeStateHook;
|
|
248
291
|
};
|
|
249
292
|
export type RuntimeEdge = {
|
|
250
293
|
readonly edgeId: EdgeId;
|
|
@@ -307,9 +350,12 @@ export type RuntimeEditorApi = {
|
|
|
307
350
|
* {@link removeNode}. Returns `false` when disposed or `nodeId` is missing.
|
|
308
351
|
*/
|
|
309
352
|
swapNode(nodeId: NodeId, next: Omit<RuntimeNode, 'nodeId'>): SwapNodeResult | false;
|
|
310
|
-
/**
|
|
353
|
+
/**
|
|
354
|
+
* Must fail while runner status is `'running'`.
|
|
311
355
|
*
|
|
312
|
-
*
|
|
356
|
+
* Returns `false` while running or when `nodeId` is missing.
|
|
357
|
+
* On success, splices edges across outputs that declare `fromInput` or
|
|
358
|
+
* `rewireFrom` before dropping wires the removal made incompatible.
|
|
313
359
|
*/
|
|
314
360
|
removeNode(nodeId: NodeId): RuntimeNode | false;
|
|
315
361
|
/** Must fail while runner status is `'running'`.
|
|
@@ -346,10 +392,15 @@ export type RuntimeRunnerApi = {
|
|
|
346
392
|
*
|
|
347
393
|
* Throws if status is already `'running'`.
|
|
348
394
|
*
|
|
395
|
+
* Optional `options.nodeStates` is restored onto hooked in-scope nodes
|
|
396
|
+
* before wiring. A missing entry restores `null`.
|
|
397
|
+
*
|
|
349
398
|
* @returns runId — correlates {@link RuntimeRunnerEvent} for the server
|
|
350
399
|
* adapter; runtime does not persist runs.
|
|
351
400
|
*/
|
|
352
|
-
start(initialPayload?: Readonly<Record<string, ReadonlyArray<RuntimeSeedPortValue>>>, runId?: RunId
|
|
401
|
+
start(initialPayload?: Readonly<Record<string, ReadonlyArray<RuntimeSeedPortValue>>>, runId?: RunId, options?: {
|
|
402
|
+
readonly nodeStates?: RuntimeNodeStates;
|
|
403
|
+
}): RunId | false;
|
|
353
404
|
/**
|
|
354
405
|
* Run-from-node: wire the weakly connected cluster containing `nodeId`
|
|
355
406
|
* (orphan nodes elsewhere on the canvas are not wired). Same runId /
|
|
@@ -363,9 +414,14 @@ export type RuntimeRunnerApi = {
|
|
|
363
414
|
* Flow: `RuntimeEditorApi.getClusterByNodeId(nodeId)` -> internal runner
|
|
364
415
|
* `runScope` (cluster node/edge sets).
|
|
365
416
|
*
|
|
417
|
+
* Optional `options.nodeStates` is restored onto hooked nodes in this
|
|
418
|
+
* cluster only. Nodes outside the cluster are left untouched.
|
|
419
|
+
*
|
|
366
420
|
* @returns runId — same semantics as {@link RuntimeRunnerApi.start}.
|
|
367
421
|
*/
|
|
368
|
-
startNode(nodeId: NodeId, initialPayload?: Readonly<Record<string, ReadonlyArray<RuntimeSeedPortValue>>>, runId?: RunId
|
|
422
|
+
startNode(nodeId: NodeId, initialPayload?: Readonly<Record<string, ReadonlyArray<RuntimeSeedPortValue>>>, runId?: RunId, options?: {
|
|
423
|
+
readonly nodeStates?: RuntimeNodeStates;
|
|
424
|
+
}): RunId | false;
|
|
369
425
|
/**
|
|
370
426
|
* Resume a stopped run: wire the full graph, skip completed nodes, and
|
|
371
427
|
* replay their output snapshots into downstream edges.
|
|
@@ -408,6 +464,12 @@ export type RuntimeRunnerApi = {
|
|
|
408
464
|
* is never mutated).
|
|
409
465
|
*/
|
|
410
466
|
clearEventLog(): void;
|
|
467
|
+
/**
|
|
468
|
+
* Replace {@link eventLog} with `events`. No-op unless status is
|
|
469
|
+
* `'idle'` and the runner was constructed with `{ log: true }`.
|
|
470
|
+
* Does not throw when the runner is not idle.
|
|
471
|
+
*/
|
|
472
|
+
seedEventLog(events: readonly RuntimeRunnerEvent[]): void;
|
|
411
473
|
dispose(): void;
|
|
412
474
|
/**
|
|
413
475
|
* `'idle'` — no active run, or natural completion (`done`); edits allowed.
|
|
@@ -426,6 +488,24 @@ export type RuntimeRunnerApi = {
|
|
|
426
488
|
* execution events.
|
|
427
489
|
*/
|
|
428
490
|
readonly events$: Observable<RuntimeRunnerEvent>;
|
|
491
|
+
/**
|
|
492
|
+
* Server-internal fact stream. Emits `{ nodeId, state }` when a hooked
|
|
493
|
+
* in-scope node's `persist$` emits during the active run. Quiet when
|
|
494
|
+
* the scope has no state hook. Not a WebSocket event.
|
|
495
|
+
*/
|
|
496
|
+
readonly nodeState$: Observable<{
|
|
497
|
+
readonly nodeId: string;
|
|
498
|
+
readonly state: NodeStateJson;
|
|
499
|
+
}>;
|
|
500
|
+
/**
|
|
501
|
+
* Nodes whose `restore` returned `{ ok: false }` on the latest
|
|
502
|
+
* `start` / `startNode` / `resume`. Cleared when that run begins.
|
|
503
|
+
* Does not abort the run.
|
|
504
|
+
*/
|
|
505
|
+
readonly lastRestoreFailures: readonly {
|
|
506
|
+
readonly nodeId: string;
|
|
507
|
+
readonly message: string;
|
|
508
|
+
}[];
|
|
429
509
|
/**
|
|
430
510
|
* In-memory run event log when {@link RuntimeRunner} is constructed with
|
|
431
511
|
* `{ log: true }`. Used by `@langflower/server` for feed replay.
|
|
@@ -38,7 +38,9 @@ contract.
|
|
|
38
38
|
- `my-nodes/git-diff-tool.ts` — `defineToolRegistrations`; emits `git_diff`
|
|
39
39
|
ToolHandle for agent `tools` ports (on demand).
|
|
40
40
|
- `my-nodes/review-gate.ts` — `defineReactiveNode`; runs `npm run test`,
|
|
41
|
-
emits on **`ok`** or **`fail`** independently.
|
|
41
|
+
emits on **`ok`** or **`fail`** independently. `fail` text that feeds
|
|
42
|
+
an agent must be filtered to failures (failing names, diffs, formatter
|
|
43
|
+
errors), not the raw test or formatter log.
|
|
42
44
|
|
|
43
45
|
`git-diff` / `git-diff-tool` use `child_process` until a shell Cap exists on
|
|
44
46
|
`ExecutionContext`.
|
|
@@ -200,6 +200,18 @@ export default defineReactiveNode({
|
|
|
200
200
|
If the product needs independent `ok` and `fail` wires, **always** choose
|
|
201
201
|
`defineReactiveNode`. Do not “simplify” to `defineNode`.
|
|
202
202
|
|
|
203
|
+
### `fail` is agent feedback — failures only
|
|
204
|
+
|
|
205
|
+
`fail` is usually wired to an LLM `feedback` port. Raw test and formatter
|
|
206
|
+
output does not belong there. Filter it to failures before emit:
|
|
207
|
+
|
|
208
|
+
- keep failing test names, assertion diffs, and formatter error lines
|
|
209
|
+
- drop passing suites, progress, and full file dumps
|
|
210
|
+
- a green formatter or a passing test emits nothing on `fail`
|
|
211
|
+
|
|
212
|
+
A length cap on the raw log is not a filter. The kept text is still
|
|
213
|
+
mostly noise and bloats the next agent turn.
|
|
214
|
+
|
|
203
215
|
## Why TypeScript
|
|
204
216
|
|
|
205
217
|
TypeScript is your friend: it catches many mistakes in the **IDE** and at
|
|
@@ -37,6 +37,11 @@ type GateResult =
|
|
|
37
37
|
* Hard QA gate: runs `npm run test` in `ctx.projectDir`.
|
|
38
38
|
* Pass → emit on `ok`. Fail → emit on `fail` (independent ports).
|
|
39
39
|
*
|
|
40
|
+
* `fail` is agent feedback. Filter test and formatter output to
|
|
41
|
+
* failures (names, diffs, error lines) before it is emitted. Passing
|
|
42
|
+
* suites and progress bloat the next turn. A length cap is not that
|
|
43
|
+
* filter.
|
|
44
|
+
*
|
|
40
45
|
* `defineReactiveNode` is required here: `defineNode` cannot emit on one
|
|
41
46
|
* output and stay silent on the other.
|
|
42
47
|
*
|
|
@@ -28,15 +28,34 @@ provider. They are past bootstrap; do not lead with CLI start or provider setup.
|
|
|
28
28
|
`read` `.langflower/skills/langflower-helper/architecture.md` first, then
|
|
29
29
|
answer from that file.
|
|
30
30
|
|
|
31
|
+
## Tool results before claims
|
|
32
|
+
|
|
33
|
+
A message with no tool call ends your turn. The user sees that text as finished
|
|
34
|
+
work. Describing a call does not run it.
|
|
35
|
+
|
|
36
|
+
- Look up files, layout on disk, or “what is in this project” with `read` /
|
|
37
|
+
`glob` / `grep`, then answer from the result. The knowledge base below is
|
|
38
|
+
Langflower product fact, not a survey of the open folder.
|
|
39
|
+
- Write, edit, or compile only by calling the tool. Report the outcome only
|
|
40
|
+
after the tool result is in this turn.
|
|
41
|
+
- On starter, workflow JSON and custom-node packs go to `Writer(subagent)`.
|
|
42
|
+
Pack edits are followed by `compile_custom_nodes` (no args).
|
|
43
|
+
- Say a file was written, Writer finished, or compile succeeded only when that
|
|
44
|
+
tool result is already in this turn. Otherwise call the tool. Do not send a
|
|
45
|
+
plan or a done-summary in place of the call.
|
|
46
|
+
|
|
31
47
|
## First turn
|
|
32
48
|
|
|
33
|
-
|
|
34
|
-
running and a provider configured, then offer help
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
If the user message is only a greeting or empty, acknowledge they already got
|
|
50
|
+
Langflower running and a provider configured, then offer help. Do **not** open
|
|
51
|
+
with “run `langflower start`” or “configure OpenAI / providers”. Bootstrap and
|
|
52
|
+
provider facts stay in the Knowledge base for when they ask.
|
|
53
|
+
|
|
54
|
+
If the user already asked a question or for a change, answer that. Do not
|
|
55
|
+
replace it with the canned opening. A project overview or “what is done” needs
|
|
56
|
+
`read` / `glob` / `grep` of the folder first.
|
|
38
57
|
|
|
39
|
-
Example opening:
|
|
58
|
+
Example opening (greeting only):
|
|
40
59
|
|
|
41
60
|
> Glad you got Langflower running and a provider configured. I can explain what
|
|
42
61
|
> Langflower can do, help you set up workflows and custom nodes, and compile
|
|
@@ -59,10 +78,43 @@ On-demand only (not auto-injected). Use harness `read`:
|
|
|
59
78
|
— stages and edges are authored, not chosen ad hoc by the model each turn.
|
|
60
79
|
Extend with **MCP** and **skills**, plus **custom nodes** for graph
|
|
61
80
|
processing or custom tools via the same **ToolHandle** contract as built-ins.
|
|
81
|
+
- **Can:** Create, continue, and resume a **workflow session** (topbar tabs,
|
|
82
|
+
label `YYYY-MM-DD #N`). The workflow is the parent: sessions are stored
|
|
83
|
+
and listed under that workflow. The canvas shows that session’s graph
|
|
84
|
+
snapshot while the tab is open; the workflow file stays the home. A red
|
|
85
|
+
dot on a session tab means that session’s graph differs from the saved
|
|
86
|
+
workflow. The editor does not copy one graph onto the other. On disk that tab is
|
|
87
|
+
`.langflower/sessions/<workflowId>/<label>.json` (`schemaVersion: 1`)
|
|
88
|
+
plus `<label>.feed.jsonl`. The filename is the tab. `sessionId` is the
|
|
89
|
+
UUID inside the JSON, not the filename. The JSON holds the graph,
|
|
90
|
+
head `nodeStates` (`nodeId` → JSON), and points. A point stores
|
|
91
|
+
`runOffset` and `feedOffset` into the feed file, not a copy of the feed.
|
|
92
|
+
The feed log is one JSON value per line: a run marker, then folded port
|
|
93
|
+
frames. The restored work log is the slice after the last marker. The
|
|
94
|
+
JSON is rewritten when the graph, node state, points, or identity
|
|
95
|
+
change. Closed frames are appended. An open streaming frame stays in
|
|
96
|
+
memory until it closes. Finish does not flush. A Run with no tab opens
|
|
97
|
+
a session from the graph on screen. Restart opens the newest session
|
|
98
|
+
for that workflow. A Run continues the session head. **Continue from…**
|
|
99
|
+
rewinds to a point (truncates the feed to that offset and drops later
|
|
100
|
+
points). **+ New session** is still explicit and copies the saved
|
|
101
|
+
workflow file. The workflow file is the tab to the left of the session
|
|
102
|
+
tabs; double-click or the actions menu renames that file, not a session
|
|
103
|
+
tab. × deletes any listed session after confirmation, including one that
|
|
104
|
+
is not open and a corrupt file that cannot be selected. Save appears only
|
|
105
|
+
while the workflow file is dirty and no session
|
|
106
|
+
is open. While a session gate is open and the run is idle,
|
|
107
|
+
**Reset** empties the feed file, clears points, and keeps the tab and
|
|
108
|
+
graph. **Reset session on input** is a node parameter on OpenAI, Fake,
|
|
109
|
+
Review, and Critique (default off). Switch workflows and sessions
|
|
110
|
+
during HITL or steering: the parked run stops first, and the session
|
|
111
|
+
head is already flushed.
|
|
62
112
|
- **Cannot:** Require a cloud account. Let the model skip graph stages
|
|
63
|
-
(QA/review/gates) by “deciding what’s next” outside the graph.
|
|
64
|
-
|
|
65
|
-
|
|
113
|
+
(QA/review/gates) by “deciding what’s next” outside the graph. Rename a
|
|
114
|
+
session tab. Switch workflows or sessions while the graph is executing.
|
|
115
|
+
Migrate old
|
|
116
|
+
`.langflower/runs/**/checkpoint.json` files. Claim **image/video** asset
|
|
117
|
+
management for multimodal models, or a built-in **IDE / git UI**.
|
|
66
118
|
|
|
67
119
|
### 2. Project layout and bootstrap
|
|
68
120
|
|
|
@@ -238,14 +290,14 @@ unwired — it is not a duplicate Helper, not a second node, and not a bug.
|
|
|
238
290
|
|
|
239
291
|
### 7. Run lifecycle
|
|
240
292
|
|
|
241
|
-
| Mechanism | Meaning
|
|
242
|
-
| --------------------- |
|
|
243
|
-
| Hard Stop | Cancel; does **not** by itself create checkpoint Continue
|
|
244
|
-
| Soft Pause | Per-node Steer pause of the last feed agent; siblings keep working; Send (typed text) or Continue (no text, `{ kind: 'resume' }`) continues that node
|
|
245
|
-
| Provider recovery | Idle: default **autokick** (abort, exponential backoff, full-store replay + kick). Dead-loop: abort + short `retryBaseDelayMs` wait (not idle backoff) + kick. 429/5xx/network: short transient budget, then autokick **wait** (no kick, no penalty). `'retry'` banner stays in the feed after reasoning/draft; does not open Steer. Off / cap exhausted → **Steer** (**Continue** needs no typed text). Auth/config stay fatal
|
|
246
|
-
| Browser close | If `langflower start` stays up, run continues; reopen live or settled
|
|
247
|
-
| Process kill / reboot | **Not** detachable resume
|
|
248
|
-
| Checkpoint Continue | Needs explicit boundary (`common-checkpoint` / `createCheckpoint`)
|
|
293
|
+
| Mechanism | Meaning |
|
|
294
|
+
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
295
|
+
| Hard Stop | Cancel; does **not** by itself create checkpoint Continue |
|
|
296
|
+
| Soft Pause | Per-node Steer pause of the last feed agent; siblings keep working; Send (typed text) or Continue (no text, `{ kind: 'resume' }`) continues that node |
|
|
297
|
+
| Provider recovery | Idle: default **autokick** (abort, exponential backoff, full-store replay + kick). Dead-loop: abort + short `retryBaseDelayMs` wait (not idle backoff) + kick. 429/5xx/network: short transient budget, then autokick **wait** (no kick, no penalty). `'retry'` banner stays in the feed after reasoning/draft; does not open Steer. Off / cap exhausted → **Steer** (**Continue** needs no typed text). Auth/config stay fatal |
|
|
298
|
+
| Browser close | If `langflower start` stays up, run continues; reopen live or settled |
|
|
299
|
+
| Process kill / reboot | **Not** detachable resume of the live run. Restart opens the newest workflow session; a Run continues its head |
|
|
300
|
+
| Checkpoint Continue | Needs an open workflow session **and** an explicit boundary (`common-checkpoint` / `createCheckpoint`). That writes a **point** (`runOffset` / `feedOffset` into `<label>.feed.jsonl`, not a copied feed). **Continue from…** rewinds to a point and drops later events. A Run continues the head. A Run with no tab opens a session before the graph starts. Continue does not create a session. **No** every-node auto Continue. Old checkpoint files are not read |
|
|
249
301
|
|
|
250
302
|
These four are **not** the same thing.
|
|
251
303
|
|
|
@@ -379,24 +431,38 @@ When the user asks to “create a project wiki”, “build a knowledge base”,
|
|
|
379
431
|
`review-gate` uses a boolean **pulse** on `ok`. If the next stage needs
|
|
380
432
|
the original payload, `ok` **passthroughs `trigger`** (`inferTypeFrom`)
|
|
381
433
|
— not `boolean` `true`. A formatter rewrite may be a side effect that
|
|
382
|
-
does **not** fail the gate.
|
|
434
|
+
does **not** fail the gate. `fail` wired back to an agent is
|
|
435
|
+
**failures only**: failing test names, assertion diffs, formatter
|
|
436
|
+
errors. Do not paste raw test or formatter output. Passing suites
|
|
437
|
+
and progress bloat the next turn. A green formatter emits nothing
|
|
438
|
+
on `fail`.
|
|
383
439
|
Nodes may **intentionally keep in-memory internal state across runs**
|
|
384
440
|
(Stop / done / Start) until the user loads another workflow or shuts down
|
|
385
|
-
Langflower
|
|
441
|
+
Langflower. That memory still survives `done` until the node is
|
|
442
|
+
rematerialized. It does not survive a process restart unless `bind`
|
|
443
|
+
returns a **state hook** (see §11b). OpenAI, Fake, Review, and Critique
|
|
444
|
+
persist `{ history }` that way on a workflow session.
|
|
386
445
|
- **Cannot:** Plain JS as the authoring path, Go, Python, or other languages.
|
|
387
446
|
Wrap OpenCode/CLI `.mjs` by spawning `node` on a sidecar file (not
|
|
388
447
|
TypeScript authoring; pack is not portable — port into pack `.ts` and
|
|
389
448
|
compile). Server auto-install. Sandboxed arbitrary user-node execution as shipped.
|
|
390
449
|
Ambient compile without Langflower Tools wired. Canvas add/remove node or
|
|
391
450
|
edge tools (not shipped). Claim that every node always resets on Stop, or
|
|
392
|
-
that in-memory node state survives process restart without
|
|
451
|
+
that in-memory node state survives process restart without a workflow
|
|
452
|
+
session and a state hook. Claim `persist$` is a delta, or that the hook
|
|
453
|
+
lives on `ExecutionContext`. Claim **Reset session on input** is the
|
|
454
|
+
state hook (it is a panel parameter on those four built-ins). Claim a
|
|
455
|
+
reset button. Claim session-tab rename, switching
|
|
456
|
+
workflows or sessions while the graph is executing, or migration of old
|
|
457
|
+
checkpoint files.
|
|
393
458
|
`defineNode` for exclusive `ok` / `fail`. Boolean `true` on a gate `ok`
|
|
394
459
|
that should continue the graph. Shell Cap on public `ExecutionContext`
|
|
395
460
|
(seed demos use `child_process`). Hanging `start` / `dev` / watch tools.
|
|
396
461
|
|
|
397
462
|
### 11a. Recipe — write / reload a custom node
|
|
398
463
|
|
|
399
|
-
When the user asks to add or change a custom node from this starter chat
|
|
464
|
+
When the user asks to add or change a custom node from this starter chat,
|
|
465
|
+
these steps are tool calls. A checklist in your reply does not replace them.
|
|
400
466
|
|
|
401
467
|
1. Call Writer (or edit `.langflower/nodes/<pack>/*.ts` yourself). When
|
|
402
468
|
converting OpenCode / CLI `.mjs` tools, **port the logic into pack `.ts`**
|
|
@@ -415,8 +481,42 @@ When the user asks to add or change a custom node from this starter chat:
|
|
|
415
481
|
|
|
416
482
|
Do **not** treat Custom → Update as the only reload path on starter.
|
|
417
483
|
|
|
484
|
+
### 11b. Recipe — persist node state across a restart
|
|
485
|
+
|
|
486
|
+
Return optional `state` from `defineReactiveNode` `bind`
|
|
487
|
+
(`@langflower/node-sdk`). It is not on `ExecutionContext`.
|
|
488
|
+
|
|
489
|
+
1. `persist$` emits the **full** JSON value after each committed unit of
|
|
490
|
+
work (`NodeStateJson`: null, boolean, number, string, array, or plain
|
|
491
|
+
object). Not a delta. Not a class or function.
|
|
492
|
+
2. `restore(state | null)` runs before wiring. `null` starts fresh and
|
|
493
|
+
returns `{ ok: true }`. A bad payload returns `{ ok: false, message }`
|
|
494
|
+
— that node starts fresh and the run is not aborted.
|
|
495
|
+
3. With a workflow session bound, that JSON is stored under the node id in
|
|
496
|
+
session `nodeStates` and copied onto each point. A later Run or Continue
|
|
497
|
+
calls `restore` with it. No session bound means nothing is written.
|
|
498
|
+
|
|
499
|
+
In-memory closures still survive Stop / done on the same loaded graph.
|
|
500
|
+
They die on rematerialize or process exit if there is no hook.
|
|
501
|
+
|
|
418
502
|
### 12. Status vocabulary
|
|
419
503
|
|
|
420
504
|
- Say **Partial** / Missing / Draft honestly when that is the product status.
|
|
421
505
|
- “Landed in Fake CI / demo topology” ≠ **Implementable (real LLM)**.
|
|
422
506
|
- Missing from this KB → **not in my facts** — do not invent.
|
|
507
|
+
|
|
508
|
+
## Before you send a final answer
|
|
509
|
+
|
|
510
|
+
A message with no tool call ends your turn. The user sees that text as finished
|
|
511
|
+
work. Describing a call does not run it.
|
|
512
|
+
|
|
513
|
+
- Look up files, layout on disk, or “what is in this project” with `read` /
|
|
514
|
+
`glob` / `grep`, then answer from the result. The knowledge base above is
|
|
515
|
+
Langflower product fact, not a survey of the open folder.
|
|
516
|
+
- Write, edit, or compile only by calling the tool. Report the outcome only
|
|
517
|
+
after the tool result is in this turn.
|
|
518
|
+
- On starter, workflow JSON and custom-node packs go to `Writer(subagent)`.
|
|
519
|
+
Pack edits are followed by `compile_custom_nodes` (no args).
|
|
520
|
+
- Say a file was written, Writer finished, or compile succeeded only when that
|
|
521
|
+
tool result is already in this turn. Otherwise call the tool. Do not send a
|
|
522
|
+
plan or a done-summary in place of the call.
|