@valerypopoff/rivet2-core 2.7.0 → 2.8.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.
@@ -1811,13 +1811,15 @@ export class GraphProcessor {
1811
1811
  emitDetached(this.#emitter, event, this.#withExecution(data));
1812
1812
  return;
1813
1813
  }
1814
- return this.#emitter.emit(event, this.#withExecution(data)).then(() => {
1815
- if (event === 'nodeFinish') {
1816
- // SplitRunDeps exposes overloaded event payloads; the runtime event
1817
- // discriminator guarantees this is the terminal-output shape.
1818
- this.#commitStreamingWatchStop(node, data.outputs);
1819
- }
1820
- });
1814
+ // SplitRunDeps exposes overloaded event payloads; the runtime event
1815
+ // discriminator guarantees this is the terminal-output shape.
1816
+ const stopClaim = event === 'nodeFinish'
1817
+ ? this.#claimStreamingWatchStopFromInvocation(node, data.outputs)
1818
+ : undefined;
1819
+ const eventData = event === 'nodeFinish' && stopClaim
1820
+ ? { ...data, streamingWatchTerminal: true }
1821
+ : data;
1822
+ return this.#emitter.emit(event, this.#withExecution(eventData)).then(() => stopClaim?.commit());
1821
1823
  },
1822
1824
  startNodeTiming: this.#captureNodeTimings ? () => this.#startNodeTiming() : undefined,
1823
1825
  finishNodeTiming: this.#captureNodeTimings ? (start) => this.#finishNodeTiming(start) : undefined,
@@ -1886,14 +1888,16 @@ export class GraphProcessor {
1886
1888
  this.#visitedNodes.add(node.id);
1887
1889
  this.#accumulateCost(outputValues);
1888
1890
  this.#assertStreamingOutputWatchFinalOutputs(node, outputValues);
1891
+ const stopClaim = this.#claimStreamingWatchStopFromInvocation(node, outputValues);
1889
1892
  await this.#emitter.emit('nodeFinish', this.#withExecution(withOptionalDuration({
1890
1893
  node,
1891
1894
  outputs: outputValues,
1892
1895
  processId,
1893
1896
  resultOrigin,
1897
+ ...(stopClaim ? { streamingWatchTerminal: true } : {}),
1894
1898
  }, this.#finishNodeTiming(timingStart))));
1895
1899
  this.#finishStreamingOutputWatches(node, outputValues);
1896
- this.#commitStreamingWatchStop(node, outputValues);
1900
+ stopClaim?.commit();
1897
1901
  }
1898
1902
  catch (error) {
1899
1903
  await this.#nodeErrored(node, error, processId, this.#finishNodeTiming(timingStart), undefined, resultOrigin, this.#takeFailureOutputs(processId, 0));
@@ -2962,7 +2966,7 @@ export class GraphProcessor {
2962
2966
  processor.#streamingWatchInvocation = {
2963
2967
  plan,
2964
2968
  historyIteration,
2965
- acceptStop: (value) => this.#acceptStreamingWatchStop(plan, historyIteration, value, snapshot.updateIndex),
2969
+ claimStop: (value) => this.#claimAcceptedStreamingWatchStop(plan, historyIteration, value, snapshot.updateIndex),
2966
2970
  stopReached: false,
2967
2971
  };
2968
2972
  processor.preloadNodeData(plan.watchNode.id, this.#materializeStreamingOutputWatchSnapshot(snapshot));
@@ -3043,24 +3047,25 @@ export class GraphProcessor {
3043
3047
  root.#subprocessors.delete(processor);
3044
3048
  }
3045
3049
  }
3046
- #commitStreamingWatchStop(node, outputs) {
3050
+ #claimStreamingWatchStopFromInvocation(node, outputs) {
3047
3051
  const invocation = this.#streamingWatchInvocation;
3048
3052
  const completedValue = outputs['value'];
3049
3053
  if (invocation?.plan.stopNodeId === node.id &&
3050
3054
  invocation.stopReached &&
3051
3055
  completedValue !== undefined &&
3052
3056
  !this.#getUnhandledErroredNodes().length) {
3053
- invocation.acceptStop(completedValue);
3057
+ return invocation.claimStop(completedValue);
3054
3058
  }
3059
+ return undefined;
3055
3060
  }
3056
- #acceptStreamingWatchStop(plan, historyIteration, value, updateIndex) {
3061
+ #claimAcceptedStreamingWatchStop(plan, historyIteration, value, updateIndex) {
3057
3062
  const stopNodeId = plan.stopNodeId;
3058
3063
  if (!stopNodeId) {
3059
- return;
3064
+ return undefined;
3060
3065
  }
3061
3066
  const watch = this.#streamingOutputWatches.get(plan.watchNode.id);
3062
3067
  if (!watch || watch.stopped) {
3063
- return;
3068
+ return undefined;
3064
3069
  }
3065
3070
  plan.history.acceptStop(historyIteration);
3066
3071
  watch.stop(updateIndex);
@@ -3069,13 +3074,21 @@ export class GraphProcessor {
3069
3074
  throw new Error(`Watch Streaming Output "${plan.watchNode.title}" lost its Stop Watching Streaming Output node.`);
3070
3075
  }
3071
3076
  const acceptedValue = cloneExecutionOutputs({ ['value']: value })['value'];
3072
- this.#nodeResults.set(stopNode.id, { ['value']: acceptedValue });
3073
- this.#visitedNodes.add(stopNode.id);
3074
- this.#remainingNodes.delete(stopNode.id);
3075
- const attachedData = this.#getAttachedDataTo(stopNode);
3076
- const outputNodes = getOutputNodesFrom(this.#executionState, stopNode);
3077
- this.#propagateAttachedDataToOutputNodes(stopNode, attachedData, outputNodes.connectionsToNodes);
3078
- this.#queueOutputNodes(stopNode, outputNodes.nodes);
3077
+ let committed = false;
3078
+ return {
3079
+ commit: () => {
3080
+ if (committed)
3081
+ return;
3082
+ committed = true;
3083
+ this.#nodeResults.set(stopNode.id, { ['value']: acceptedValue });
3084
+ this.#visitedNodes.add(stopNode.id);
3085
+ this.#remainingNodes.delete(stopNode.id);
3086
+ const attachedData = this.#getAttachedDataTo(stopNode);
3087
+ const outputNodes = getOutputNodesFrom(this.#executionState, stopNode);
3088
+ this.#propagateAttachedDataToOutputNodes(stopNode, attachedData, outputNodes.connectionsToNodes);
3089
+ this.#queueOutputNodes(stopNode, outputNodes.nodes);
3090
+ },
3091
+ };
3079
3092
  }
3080
3093
  #cancelStreamingOutputWatchesForSource(nodeId) {
3081
3094
  for (const plan of this.#streamingWatchPlansBySourceNodeId.get(nodeId) ?? []) {
@@ -356,6 +356,7 @@ export async function replayExecutionRecording(options) {
356
356
  outputs: data.outputs,
357
357
  processId: data.processId,
358
358
  ...(data.resultOrigin === undefined ? {} : { resultOrigin: data.resultOrigin }),
359
+ ...(data.streamingWatchTerminal ? { streamingWatchTerminal: true } : {}),
359
360
  execution,
360
361
  }, getRecordedDuration(data.durationMs, execution, data.nodeId, data.processId, getRecordedEventOccurrenceAt(event)), data.splitRunDurationMs));
361
362
  nodeResults.set(data.nodeId, data.outputs);
@@ -409,10 +410,27 @@ export async function replayExecutionRecording(options) {
409
410
  }
410
411
  case 'streamingOutputWatchSummary': {
411
412
  const { data } = event;
413
+ const execution = getExecution(data.execution?.graphId ?? getGraphIdForNode(data.watchNodeId), data.execution);
414
+ // Watch summaries identify one retained child branch as terminal.
415
+ // A replay creates fresh graph-run IDs, so remap that child identity
416
+ // with the same root-scoped map used for its retained node events.
417
+ const selectedIteration = data.summary.selectedIteration;
418
+ const summary = selectedIteration?.graphRunId != null && data.execution != null
419
+ ? {
420
+ ...data.summary,
421
+ selectedIteration: {
422
+ ...selectedIteration,
423
+ graphRunId: getReplayExecution({
424
+ ...data.execution,
425
+ graphRunId: selectedIteration.graphRunId,
426
+ }).graphRunId,
427
+ },
428
+ }
429
+ : data.summary;
412
430
  emitReplayExecutionEvent('streamingOutputWatchSummary', {
413
431
  watchNode: getNode(data.watchNodeId),
414
- summary: data.summary,
415
- execution: getExecution(data.execution?.graphId ?? getGraphIdForNode(data.watchNodeId), data.execution),
432
+ summary,
433
+ execution,
416
434
  });
417
435
  break;
418
436
  }
@@ -147,6 +147,7 @@ export class StreamingOutputWatchHistory {
147
147
  selectedIteration: selected == null
148
148
  ? undefined
149
149
  : {
150
+ graphRunId: selected.graphRunId,
150
151
  updateIndex: selected.updateIndex,
151
152
  reason: selected === this.#firstFailure ? 'failure' : selected === this.#stopWinner ? 'stop' : 'latest',
152
153
  },
@@ -7,11 +7,13 @@ import { dedent } from 'ts-dedent';
7
7
  import { nodeDefinition } from '../NodeDefinition.js';
8
8
  import { ChatNodeBase } from './ChatNodeBase.js';
9
9
  import { coerceType } from '../../utils/coerceType.js';
10
+ /** Display-only label; the persisted node type remains the stable `chatLoop`. */
11
+ export const chatLoopLegacyDisplayName = 'Chat Loop (legacy)';
10
12
  export class ChatLoopNodeImpl extends NodeImpl {
11
13
  static create() {
12
14
  const chartNode = {
13
15
  type: 'chatLoop',
14
- title: 'Chat Loop',
16
+ title: chatLoopLegacyDisplayName,
15
17
  id: nanoid(),
16
18
  visualData: {
17
19
  x: 0,
@@ -54,8 +56,8 @@ export class ChatLoopNodeImpl extends NodeImpl {
54
56
 
55
57
  The conversation history is maintained and sent with each new message.
56
58
  `,
57
- contextMenuTitle: 'Chat Loop',
58
- infoBoxTitle: 'Chat Loop Node',
59
+ contextMenuTitle: chatLoopLegacyDisplayName,
60
+ infoBoxTitle: `${chatLoopLegacyDisplayName} Node`,
59
61
  group: ['Convenience'],
60
62
  };
61
63
  }
@@ -147,4 +149,6 @@ export class ChatLoopNodeImpl extends NodeImpl {
147
149
  };
148
150
  }
149
151
  }
150
- export const chatLoopNode = nodeDefinition(ChatLoopNodeImpl, 'Chat Loop');
152
+ // The persisted `chatLoop` type is intentionally unchanged: the legacy
153
+ // marker is display-only, so projects saved before this rename still load.
154
+ export const chatLoopNode = nodeDefinition(ChatLoopNodeImpl, chatLoopLegacyDisplayName);
@@ -141,7 +141,7 @@ export class CodeNewNodeImpl extends NodeImpl {
141
141
  `,
142
142
  infoBoxTitle: 'Code Node',
143
143
  contextMenuTitle: 'Code',
144
- group: ['Advanced'],
144
+ group: ['Code'],
145
145
  };
146
146
  }
147
147
  async process(inputs, context) {
@@ -110,7 +110,7 @@ export class ExpressionNodeImpl extends NodeImpl {
110
110
  `,
111
111
  infoBoxTitle: 'Expression Node',
112
112
  contextMenuTitle: 'Expression',
113
- group: ['Advanced'],
113
+ group: ['Code'],
114
114
  };
115
115
  }
116
116
  async process(inputs, context) {
@@ -9,11 +9,13 @@ import { dedent } from 'ts-dedent';
9
9
  import {} from '../../index.js';
10
10
  import { entries } from '../../utils/typeSafety.js';
11
11
  import { getHighestVariadicPortIndex } from './variadicPortIndex.js';
12
+ /** Display-only label; persisted projects keep the stable `loopController` type. */
13
+ export const loopControllerLegacyDisplayName = 'Loop Controller (legacy)';
12
14
  export class LoopControllerNodeImpl extends NodeImpl {
13
15
  static create() {
14
16
  const chartNode = {
15
17
  type: 'loopController',
16
- title: 'Loop Controller',
18
+ title: loopControllerLegacyDisplayName,
17
19
  id: nanoid(),
18
20
  visualData: {
19
21
  x: 0,
@@ -119,8 +121,8 @@ export class LoopControllerNodeImpl extends NodeImpl {
119
121
 
120
122
  If the "continue" input is falsey, then the "break" output will run.
121
123
  `,
122
- infoBoxTitle: 'Loop Controller Node',
123
- contextMenuTitle: 'Loop Controller',
124
+ infoBoxTitle: `${loopControllerLegacyDisplayName} Node`,
125
+ contextMenuTitle: loopControllerLegacyDisplayName,
124
126
  group: ['Logic'],
125
127
  };
126
128
  }
@@ -192,4 +194,4 @@ export class LoopControllerNodeImpl extends NodeImpl {
192
194
  return output;
193
195
  }
194
196
  }
195
- export const loopControllerNode = nodeDefinition(LoopControllerNodeImpl, 'Loop Controller');
197
+ export const loopControllerNode = nodeDefinition(LoopControllerNodeImpl, loopControllerLegacyDisplayName);
@@ -31,11 +31,12 @@ const toRecordedEventMap = {
31
31
  processId,
32
32
  ...(resultOrigin === undefined ? {} : { resultOrigin }),
33
33
  }, execution),
34
- nodeFinish: ({ node, outputs, processId, resultOrigin, durationMs, splitRunDurationMs, execution }) => withExecution(withDuration({
34
+ nodeFinish: ({ node, outputs, processId, resultOrigin, durationMs, splitRunDurationMs, streamingWatchTerminal, execution }) => withExecution(withDuration({
35
35
  nodeId: node.id,
36
36
  outputs,
37
37
  processId,
38
38
  ...(resultOrigin === undefined ? {} : { resultOrigin }),
39
+ ...(streamingWatchTerminal ? { streamingWatchTerminal: true } : {}),
39
40
  }, durationMs, splitRunDurationMs), execution),
40
41
  nodeError: ({ node, error, processId, outputs, splitOutputs, resultOrigin, durationMs, splitRunDurationMs, execution }) => withExecution(withDuration({
41
42
  nodeId: node.id,
@@ -67,6 +67,7 @@ export type SerializedProcessEventMap = {
67
67
  resultOrigin?: NodeResultOrigin;
68
68
  durationMs?: number;
69
69
  splitRunDurationMs?: Record<number, number>;
70
+ streamingWatchTerminal?: boolean;
70
71
  }>;
71
72
  nodeError: WithExecution<{
72
73
  node: ChartNode;
@@ -88,6 +88,8 @@ export type ProcessEvents = {
88
88
  resultOrigin?: NodeResultOrigin;
89
89
  durationMs?: number;
90
90
  splitRunDurationMs?: Record<number, number>;
91
+ /** True only for the one Stop result accepted by a repeated Watch branch. */
92
+ streamingWatchTerminal?: boolean;
91
93
  }>;
92
94
  /** Called when a node has errored during processing. */
93
95
  nodeError: WithExecution<{
@@ -10,6 +10,8 @@ export type StreamingOutputWatchHistorySummary = StreamingOutputWatchRuntimeSumm
10
10
  omittedIterations: number;
11
11
  retainedIterationUpdateIndexes: number[];
12
12
  selectedIteration?: {
13
+ /** The retained child run that is presented as the Watch terminal page. */
14
+ graphRunId?: GraphRunId;
13
15
  updateIndex: number;
14
16
  reason: 'failure' | 'stop' | 'latest';
15
17
  };
@@ -5,6 +5,8 @@ import { type InternalProcessContext } from '../ProcessContext.js';
5
5
  import { type EditorDefinition } from '../../index.js';
6
6
  import { type ChatNodeData } from './ChatNodeBase.js';
7
7
  export type ChatLoopNode = ChartNode<'chatLoop', ChatLoopNodeData>;
8
+ /** Display-only label; the persisted node type remains the stable `chatLoop`. */
9
+ export declare const chatLoopLegacyDisplayName = "Chat Loop (legacy)";
8
10
  export type ChatLoopNodeData = ChatNodeData & {
9
11
  userPrompt: string;
10
12
  renderingFormat?: 'text' | 'markdown';
@@ -4,6 +4,8 @@ import { type Inputs, type Outputs } from '../GraphProcessor.js';
4
4
  import { type InternalProcessContext } from '../ProcessContext.js';
5
5
  import { type EditorDefinition } from '../../index.js';
6
6
  export type LoopControllerNode = ChartNode<'loopController', LoopControllerNodeData>;
7
+ /** Display-only label; persisted projects keep the stable `loopController` type. */
8
+ export declare const loopControllerLegacyDisplayName = "Loop Controller (legacy)";
7
9
  export type LoopControllerNodeData = {
8
10
  maxIterations?: number;
9
11
  atMaxIterationsAction?: 'break' | 'error';
@@ -54,6 +54,7 @@ export type RecordedEventsMap = OverrideProperties<ProcessEvents, {
54
54
  resultOrigin?: ProcessEvents['nodeFinish']['resultOrigin'];
55
55
  durationMs?: number;
56
56
  splitRunDurationMs?: Record<number, number>;
57
+ streamingWatchTerminal?: boolean;
57
58
  }>;
58
59
  /** Called when a node has errored during processing. */
59
60
  nodeError: WithOptionalExecution<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerypopoff/rivet2-core",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/bundle.cjs",
6
6
  "module": "dist/esm/index.js",