@valerypopoff/rivet2-core 2.1.8 → 2.1.10

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 (168) hide show
  1. package/dist/cjs/bundle.cjs +4457 -1809
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/webAppRuntime.cjs +298 -21
  4. package/dist/cjs/webAppRuntime.cjs.map +4 -4
  5. package/dist/esm/exports.js +1 -0
  6. package/dist/esm/model/AgentResponseTrace.js +448 -0
  7. package/dist/esm/model/ConnectedToolContinuationHost.js +33 -0
  8. package/dist/esm/model/GraphProcessor.js +152 -74
  9. package/dist/esm/model/NodeImpl.js +6 -0
  10. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  11. package/dist/esm/model/RecordingPlayer.js +164 -22
  12. package/dist/esm/model/SplitRunProcessor.js +68 -18
  13. package/dist/esm/model/SubprocessorBridge.js +2 -0
  14. package/dist/esm/model/ToolCallContinuationCoordinator.js +13 -4
  15. package/dist/esm/model/UiGraph.js +21 -0
  16. package/dist/esm/model/UiGraphActionProtocol.js +2 -0
  17. package/dist/esm/model/UiGraphBrowserRuntime.js +133 -4
  18. package/dist/esm/model/UiGraphRendererStyles.js +221 -0
  19. package/dist/esm/model/UiGraphRuntimeModel.js +9 -3
  20. package/dist/esm/model/UiGraphSchema.js +7 -1
  21. package/dist/esm/model/chat/aiSdkMessages.js +8 -0
  22. package/dist/esm/model/chat/aiSdkTools.js +3 -2
  23. package/dist/esm/model/chat-v2/chatV2CallObserver.js +11 -5
  24. package/dist/esm/model/chat-v2/chatV2EditorCache.js +58 -10
  25. package/dist/esm/model/chat-v2/chatV2Errors.js +7 -19
  26. package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
  27. package/dist/esm/model/chat-v2/chatV2Outputs.js +56 -106
  28. package/dist/esm/model/chat-v2/chatV2Pipeline.js +142 -149
  29. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +9 -2
  30. package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
  31. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +5 -5
  32. package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +55 -0
  33. package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +8 -4
  34. package/dist/esm/model/chat-v2/chatV2Retry.js +4 -3
  35. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +6 -1
  36. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -6
  37. package/dist/esm/model/chat-v2/chatV2Types.js +7 -1
  38. package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
  39. package/dist/esm/model/chat-v2/customProviderApi.js +42 -0
  40. package/dist/esm/model/chat-v2/developerMessageRoles.js +45 -0
  41. package/dist/esm/model/chat-v2/index.js +12 -0
  42. package/dist/esm/model/chat-v2/llmChatV2Body.js +281 -0
  43. package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
  44. package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +20 -0
  45. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +8 -54
  46. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +41 -20
  47. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
  48. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +178 -94
  49. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +60 -0
  50. package/dist/esm/model/chat-v2/llmInvocationDecision.js +11 -0
  51. package/dist/esm/model/chat-v2/llmInvocationJournal.js +43 -0
  52. package/dist/esm/model/chat-v2/llmInvocationPlan.js +68 -0
  53. package/dist/esm/model/chat-v2/llmInvocationProjections.js +5 -0
  54. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +48 -0
  55. package/dist/esm/model/chat-v2/llmModelCandidate.js +75 -0
  56. package/dist/esm/model/chat-v2/llmProfile.js +31 -65
  57. package/dist/esm/model/chat-v2/llmProfileBody.js +183 -0
  58. package/dist/esm/model/chat-v2/llmProfileFallback.js +244 -0
  59. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +67 -0
  60. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +3 -0
  61. package/dist/esm/model/chat-v2/llmProfileTypes.js +1 -18
  62. package/dist/esm/model/chat-v2/llmResponseMaterializer.js +42 -0
  63. package/dist/esm/model/chat-v2/messageConverter.js +14 -0
  64. package/dist/esm/model/chat-v2/modelRegistry.js +54 -4
  65. package/dist/esm/model/chat-v2/parallelToolCalls.js +9 -2
  66. package/dist/esm/model/chat-v2/providerOptions.js +120 -21
  67. package/dist/esm/model/chat-v2/rivetToolRegistry.js +9 -0
  68. package/dist/esm/model/chat-v2/toolCallCodec.js +52 -0
  69. package/dist/esm/model/chat-v2/toolContinuation.js +72 -39
  70. package/dist/esm/model/chat-v2/toolHandlerResolver.js +23 -0
  71. package/dist/esm/model/chat-v2/toolRoundExecutor.js +12 -0
  72. package/dist/esm/model/nodes/AssembleMessageNode.js +6 -0
  73. package/dist/esm/model/nodes/ChatNode.js +6 -0
  74. package/dist/esm/model/nodes/ChatNodeBase.js +1 -0
  75. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +26 -1
  76. package/dist/esm/model/nodes/LLMChatV2Node.js +131 -144
  77. package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
  78. package/dist/esm/model/nodes/PromptNode.js +16 -2
  79. package/dist/esm/model/nodes/ToolNode.js +7 -0
  80. package/dist/esm/model/nodes/toolCallDelegation.js +193 -110
  81. package/dist/esm/plugins/anthropic/anthropic.js +4 -4
  82. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +29 -28
  83. package/dist/esm/plugins/google/google.js +25 -18
  84. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +21 -7
  85. package/dist/esm/recording/ExecutionRecorder.js +13 -5
  86. package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +4 -0
  87. package/dist/esm/utils/emitDetached.js +6 -3
  88. package/dist/esm/utils/openai.js +60 -16
  89. package/dist/esm/utils/serialization/serialization.js +2 -0
  90. package/dist/esm/webAppRuntime.js +3 -2
  91. package/dist/types/exports.d.ts +1 -0
  92. package/dist/types/model/AgentResponseTrace.d.ts +110 -0
  93. package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
  94. package/dist/types/model/DataValue.d.ts +7 -1
  95. package/dist/types/model/ExecutorProtocol.d.ts +25 -7
  96. package/dist/types/model/GraphProcessor.d.ts +27 -5
  97. package/dist/types/model/NodeBase.d.ts +6 -0
  98. package/dist/types/model/NodeImpl.d.ts +18 -1
  99. package/dist/types/model/Nodes.d.ts +2 -2
  100. package/dist/types/model/ProcessContext.d.ts +51 -0
  101. package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
  102. package/dist/types/model/RecordingPlayer.d.ts +6 -0
  103. package/dist/types/model/SplitRunProcessor.d.ts +11 -3
  104. package/dist/types/model/UiGraph.d.ts +8 -0
  105. package/dist/types/model/UiGraphActionProtocol.d.ts +2 -0
  106. package/dist/types/model/UiGraphBrowserRuntime.d.ts +11 -2
  107. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  108. package/dist/types/model/UiGraphRuntimeModel.d.ts +2 -0
  109. package/dist/types/model/UiGraphSchema.d.ts +1 -0
  110. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +2 -0
  111. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +3 -1
  112. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +7 -17
  113. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +29 -0
  114. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +5 -0
  115. package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +8 -0
  116. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  117. package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +19 -0
  118. package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +3 -2
  119. package/dist/types/model/chat-v2/chatV2Retry.d.ts +2 -0
  120. package/dist/types/model/chat-v2/chatV2Shared.d.ts +0 -1
  121. package/dist/types/model/chat-v2/chatV2Types.d.ts +35 -1
  122. package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
  123. package/dist/types/model/chat-v2/customProviderApi.d.ts +23 -0
  124. package/dist/types/model/chat-v2/developerMessageRoles.d.ts +10 -0
  125. package/dist/types/model/chat-v2/index.d.ts +12 -0
  126. package/dist/types/model/chat-v2/llmChatV2Body.d.ts +24 -0
  127. package/dist/types/model/chat-v2/llmChatV2CacheBoundary.d.ts +10 -0
  128. package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +13 -0
  129. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +13 -3
  130. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
  131. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +18 -4
  132. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +16 -0
  133. package/dist/types/model/chat-v2/llmInvocationDecision.d.ts +21 -0
  134. package/dist/types/model/chat-v2/llmInvocationJournal.d.ts +38 -0
  135. package/dist/types/model/chat-v2/llmInvocationPlan.d.ts +41 -0
  136. package/dist/types/model/chat-v2/llmInvocationProjections.d.ts +3 -0
  137. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +26 -0
  138. package/dist/types/model/chat-v2/llmModelCandidate.d.ts +18 -0
  139. package/dist/types/model/chat-v2/llmProfile.d.ts +7 -0
  140. package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
  141. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +47 -0
  142. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +189 -0
  143. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +1 -1
  144. package/dist/types/model/chat-v2/llmResponseMaterializer.d.ts +20 -0
  145. package/dist/types/model/chat-v2/modelRegistry.d.ts +17 -187
  146. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +3 -1
  147. package/dist/types/model/chat-v2/providerOptions.d.ts +11 -0
  148. package/dist/types/model/chat-v2/rivetToolRegistry.d.ts +11 -0
  149. package/dist/types/model/chat-v2/toolCallCodec.d.ts +7 -0
  150. package/dist/types/model/chat-v2/toolContinuation.d.ts +3 -3
  151. package/dist/types/model/chat-v2/toolHandlerResolver.d.ts +25 -0
  152. package/dist/types/model/chat-v2/toolRoundExecutor.d.ts +18 -0
  153. package/dist/types/model/nodes/AssembleMessageNode.d.ts +2 -1
  154. package/dist/types/model/nodes/ChatNode.d.ts +2 -1
  155. package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +2 -1
  156. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  157. package/dist/types/model/nodes/LLMProfileNode.d.ts +2 -1
  158. package/dist/types/model/nodes/PromptNode.d.ts +6 -3
  159. package/dist/types/model/nodes/ToolNode.d.ts +2 -1
  160. package/dist/types/model/nodes/toolCallDelegation.d.ts +10 -3
  161. package/dist/types/plugins/anthropic/anthropic.d.ts +1 -0
  162. package/dist/types/plugins/google/google.d.ts +14 -9
  163. package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +2 -1
  164. package/dist/types/recording/RecordedEvents.d.ts +6 -0
  165. package/dist/types/utils/emitDetached.d.ts +3 -2
  166. package/dist/types/utils/openai.d.ts +49 -0
  167. package/dist/types/webAppRuntime.d.ts +4 -2
  168. package/package.json +2 -2
@@ -9,7 +9,7 @@ function withOptionalDuration(payload, durationMs, splitRunDurationMs) {
9
9
  };
10
10
  }
11
11
  export async function replayExecutionRecording(options) {
12
- const { emitter, erroredNodes, graphOutputs, project, recorder, recordingPlaybackChatLatency, setContextValues, setGraphInputs, setGraphOutputs, setRunning, visitedNodes, waitUntilUnpaused, nodeResults, isAborted, } = options;
12
+ const { emitter, erroredNodes, graphOutputs, fallbackGraphId, initialReplayExecution, project, recorder, recordingPlaybackChatLatency, setContextValues, setGraphInputs, setGraphOutputs, setRunning, visitedNodes, waitUntilUnpaused, nodeResults, isAborted, } = options;
13
13
  const nodesByIdAllGraphs = {};
14
14
  const graphIdByNodeId = {};
15
15
  for (const graph of Object.values(project.graphs)) {
@@ -18,7 +18,57 @@ export async function replayExecutionRecording(options) {
18
18
  graphIdByNodeId[node.id] = graph.metadata.id;
19
19
  }
20
20
  }
21
- const rootGraphId = (project.metadata.mainGraphId ?? Object.keys(project.graphs)[0]);
21
+ let hasEmittedRunActivityExecution = false;
22
+ let getFallbackExecution;
23
+ const getReplayFallbackGraph = () => {
24
+ const replayTargetGraph = fallbackGraphId == null ? undefined : project.graphs[fallbackGraphId];
25
+ const projectMainGraph = project.metadata.mainGraphId == null ? undefined : project.graphs[project.metadata.mainGraphId];
26
+ return replayTargetGraph ?? projectMainGraph ?? Object.values(project.graphs)[0];
27
+ };
28
+ const emitReplayExecutionEvent = (event, data) => {
29
+ // Run Activity can materialize a root only from an execution-bearing
30
+ // lifecycle or observability event. Remember emitted events so a later
31
+ // playback error remains attached to that root instead of synthesizing a
32
+ // second one.
33
+ hasEmittedRunActivityExecution = true;
34
+ emitDetached(emitter, event, data);
35
+ };
36
+ const emitFallbackRootTerminal = (status, data) => {
37
+ // Older recordings and preflight-error recordings can contain only the
38
+ // unscoped processor terminal. Materialize the current project's root
39
+ // graph once so Run Activity has exact execution identity to attach that
40
+ // terminal confirmation to. Do not add a duplicate when any ordinary
41
+ // graph/node event has already established the replay root.
42
+ if (hasEmittedRunActivityExecution || !getFallbackExecution)
43
+ return;
44
+ const fallbackGraph = getReplayFallbackGraph();
45
+ const fallbackGraphMetadataId = fallbackGraph?.metadata?.id;
46
+ if (!fallbackGraph || !fallbackGraphMetadataId)
47
+ return;
48
+ const execution = getFallbackExecution(fallbackGraphMetadataId);
49
+ if (status === 'completed') {
50
+ emitReplayExecutionEvent('graphFinish', {
51
+ graph: fallbackGraph,
52
+ outputs: data.outputs ?? {},
53
+ execution,
54
+ });
55
+ return;
56
+ }
57
+ if (status === 'error') {
58
+ emitReplayExecutionEvent('graphError', {
59
+ graph: fallbackGraph,
60
+ error: data.error ?? 'Recording replay failed before graph execution began.',
61
+ execution,
62
+ });
63
+ return;
64
+ }
65
+ emitReplayExecutionEvent('graphAbort', {
66
+ graph: fallbackGraph,
67
+ error: data.error,
68
+ successful: data.successful ?? false,
69
+ execution,
70
+ });
71
+ };
22
72
  const getGraph = (graphId) => {
23
73
  const graph = project.graphs[graphId];
24
74
  if (!graph) {
@@ -41,12 +91,20 @@ export async function replayExecutionRecording(options) {
41
91
  return graphId;
42
92
  };
43
93
  try {
44
- const legacyRootRunId = nanoid();
94
+ const legacyRootRunId = initialReplayExecution?.rootRunId ?? nanoid();
45
95
  const legacyGraphRunsByGraphId = new Map();
96
+ const replayRootRunIds = new Map();
97
+ const replayGraphRunIdsByRoot = new Map();
46
98
  const nodeStartTimestamps = new Map();
47
99
  const getExecution = (graphId, recordedExecution) => {
48
100
  if (recordedExecution) {
49
- return recordedExecution;
101
+ return getReplayExecution(recordedExecution);
102
+ }
103
+ // Legacy recordings have no execution metadata. Keep the processor's
104
+ // already-allocated selected-graph identity so an external abort during
105
+ // replay terminates the same root instead of creating a second one.
106
+ if (initialReplayExecution?.graphId === graphId) {
107
+ return initialReplayExecution;
50
108
  }
51
109
  let graphRunId = legacyGraphRunsByGraphId.get(graphId);
52
110
  if (!graphRunId) {
@@ -59,6 +117,44 @@ export async function replayExecutionRecording(options) {
59
117
  rootRunId: legacyRootRunId,
60
118
  };
61
119
  };
120
+ getFallbackExecution = (graphId) => getExecution(graphId);
121
+ // A recording describes a past execution, but replay is a new editor run.
122
+ // Reusing recorded identities makes a second playback collide with the
123
+ // journal's terminal root and can leave Run Activity showing stale state.
124
+ // Keep its graph hierarchy intact while assigning fresh replay identity.
125
+ const getReplayExecution = (recordedExecution) => {
126
+ let replayRootRunId = replayRootRunIds.get(recordedExecution.rootRunId);
127
+ if (replayRootRunId == null) {
128
+ // The first recorded root belongs to this playback processor. Later
129
+ // roots remain distinct in malformed or concatenated recordings.
130
+ replayRootRunId =
131
+ replayRootRunIds.size === 0 && initialReplayExecution
132
+ ? initialReplayExecution.rootRunId
133
+ : nanoid();
134
+ replayRootRunIds.set(recordedExecution.rootRunId, replayRootRunId);
135
+ }
136
+ const getReplayGraphRunId = (recordedGraphRunId) => {
137
+ let graphRunIds = replayGraphRunIdsByRoot.get(recordedExecution.rootRunId);
138
+ if (graphRunIds == null) {
139
+ graphRunIds = new Map();
140
+ replayGraphRunIdsByRoot.set(recordedExecution.rootRunId, graphRunIds);
141
+ }
142
+ const replayGraphRunId = graphRunIds.get(recordedGraphRunId) ?? nanoid();
143
+ graphRunIds.set(recordedGraphRunId, replayGraphRunId);
144
+ return replayGraphRunId;
145
+ };
146
+ const { rootRunId: _recordedRootRunId, graphRunId, parentGraphRunId, ...rest } = recordedExecution;
147
+ const isInitialRootGraph = initialReplayExecution != null &&
148
+ replayRootRunId === initialReplayExecution.rootRunId &&
149
+ parentGraphRunId == null &&
150
+ rest.graphId === initialReplayExecution.graphId;
151
+ return {
152
+ ...rest,
153
+ rootRunId: replayRootRunId,
154
+ graphRunId: isInitialRootGraph ? initialReplayExecution.graphRunId : getReplayGraphRunId(graphRunId),
155
+ ...(parentGraphRunId == null ? {} : { parentGraphRunId: getReplayGraphRunId(parentGraphRunId) }),
156
+ };
157
+ };
62
158
  const getNodeRunKey = (execution, nodeId, processId) => `${execution.rootRunId}:${execution.graphRunId}:${nodeId}:${processId}`;
63
159
  const getRecordedDuration = (recordedDuration, execution, nodeId, processId, terminalTs) => {
64
160
  if (recordedDuration !== undefined) {
@@ -75,7 +171,7 @@ export async function replayExecutionRecording(options) {
75
171
  switch (event.type) {
76
172
  case 'start': {
77
173
  const { data } = event;
78
- emitDetached(emitter, 'start', {
174
+ emitReplayExecutionEvent('start', {
79
175
  project,
80
176
  contextValues: data.contextValues,
81
177
  inputs: data.inputs,
@@ -87,28 +183,42 @@ export async function replayExecutionRecording(options) {
87
183
  break;
88
184
  }
89
185
  case 'abort': {
186
+ emitFallbackRootTerminal('aborted', event.data);
90
187
  emitDetached(emitter, 'abort', event.data);
91
188
  break;
92
189
  }
93
- case 'pause':
190
+ case 'pause': {
191
+ // A replay does not automatically stop at a historical pause, but
192
+ // observers still need the original lifecycle event to faithfully
193
+ // project the recorded run (including Run Activity's paused state).
194
+ emitDetached(emitter, 'pause', { isReplay: true });
195
+ break;
196
+ }
94
197
  case 'resume': {
198
+ emitDetached(emitter, 'resume', { isReplay: true });
95
199
  break;
96
200
  }
97
201
  case 'done': {
202
+ emitFallbackRootTerminal('completed', { outputs: event.data.results });
98
203
  emitDetached(emitter, 'done', event.data);
99
204
  setGraphOutputs(event.data.results);
100
205
  setRunning(false);
101
206
  break;
102
207
  }
103
208
  case 'error': {
209
+ emitFallbackRootTerminal('error', event.data);
104
210
  emitDetached(emitter, 'error', event.data);
105
211
  break;
106
212
  }
107
213
  case 'globalSet': {
108
214
  const { data } = event;
215
+ const legacyGraphId = data.execution?.graphId ?? getReplayFallbackGraph()?.metadata?.id;
216
+ if (legacyGraphId == null) {
217
+ throw new Error('Cannot replay a global value event because the current project has no graph to attach it to.');
218
+ }
109
219
  emitDetached(emitter, 'globalSet', {
110
220
  ...data,
111
- execution: getExecution(data.execution?.graphId ?? rootGraphId, data.execution),
221
+ execution: getExecution(legacyGraphId, data.execution),
112
222
  });
113
223
  break;
114
224
  }
@@ -120,7 +230,7 @@ export async function replayExecutionRecording(options) {
120
230
  const { data } = event;
121
231
  const execution = getExecution(data.graphId, data.execution);
122
232
  legacyGraphRunsByGraphId.set(data.graphId, execution.graphRunId);
123
- emitDetached(emitter, 'graphStart', {
233
+ emitReplayExecutionEvent('graphStart', {
124
234
  graph: getGraph(data.graphId),
125
235
  inputs: data.inputs,
126
236
  execution,
@@ -129,7 +239,7 @@ export async function replayExecutionRecording(options) {
129
239
  }
130
240
  case 'graphFinish': {
131
241
  const { data } = event;
132
- emitDetached(emitter, 'graphFinish', {
242
+ emitReplayExecutionEvent('graphFinish', {
133
243
  graph: getGraph(data.graphId),
134
244
  outputs: data.outputs,
135
245
  execution: getExecution(data.graphId, data.execution),
@@ -138,7 +248,7 @@ export async function replayExecutionRecording(options) {
138
248
  }
139
249
  case 'graphOutputsReady': {
140
250
  const { data } = event;
141
- emitDetached(emitter, 'graphOutputsReady', {
251
+ emitReplayExecutionEvent('graphOutputsReady', {
142
252
  graph: getGraph(data.graphId),
143
253
  outputs: data.outputs,
144
254
  execution: getExecution(data.graphId, data.execution),
@@ -147,7 +257,7 @@ export async function replayExecutionRecording(options) {
147
257
  }
148
258
  case 'graphError': {
149
259
  const { data } = event;
150
- emitDetached(emitter, 'graphError', {
260
+ emitReplayExecutionEvent('graphError', {
151
261
  graph: getGraph(data.graphId),
152
262
  error: data.error,
153
263
  execution: getExecution(data.graphId, data.execution),
@@ -156,7 +266,7 @@ export async function replayExecutionRecording(options) {
156
266
  }
157
267
  case 'graphAbort': {
158
268
  const { data } = event;
159
- emitDetached(emitter, 'graphAbort', {
269
+ emitReplayExecutionEvent('graphAbort', {
160
270
  graph: getGraph(data.graphId),
161
271
  error: data.error,
162
272
  successful: data.successful,
@@ -169,10 +279,12 @@ export async function replayExecutionRecording(options) {
169
279
  const node = getNode(data.nodeId);
170
280
  const execution = getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution);
171
281
  nodeStartTimestamps.set(getNodeRunKey(execution, data.nodeId, data.processId), event.ts);
172
- emitDetached(emitter, 'nodeStart', {
282
+ emitReplayExecutionEvent('nodeStart', {
173
283
  node,
174
284
  inputs: data.inputs,
285
+ ...(data.inputConnections === undefined ? {} : { inputConnections: data.inputConnections }),
175
286
  processId: data.processId,
287
+ ...(data.resultOrigin === undefined ? {} : { resultOrigin: data.resultOrigin }),
176
288
  execution,
177
289
  });
178
290
  if (node.type === 'chat') {
@@ -184,10 +296,11 @@ export async function replayExecutionRecording(options) {
184
296
  const { data } = event;
185
297
  const node = getNode(data.nodeId);
186
298
  const execution = getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution);
187
- emitDetached(emitter, 'nodeFinish', withOptionalDuration({
299
+ emitReplayExecutionEvent('nodeFinish', withOptionalDuration({
188
300
  node,
189
301
  outputs: data.outputs,
190
302
  processId: data.processId,
303
+ ...(data.resultOrigin === undefined ? {} : { resultOrigin: data.resultOrigin }),
191
304
  execution,
192
305
  }, getRecordedDuration(data.durationMs, execution, data.nodeId, data.processId, event.ts), data.splitRunDurationMs));
193
306
  nodeResults.set(data.nodeId, data.outputs);
@@ -198,10 +311,11 @@ export async function replayExecutionRecording(options) {
198
311
  const { data } = event;
199
312
  const node = getNode(data.nodeId);
200
313
  const execution = getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution);
201
- emitDetached(emitter, 'nodeError', withOptionalDuration({
314
+ emitReplayExecutionEvent('nodeError', withOptionalDuration({
202
315
  node,
203
316
  error: data.error,
204
317
  processId: data.processId,
318
+ ...(data.resultOrigin === undefined ? {} : { resultOrigin: data.resultOrigin }),
205
319
  execution,
206
320
  }, getRecordedDuration(data.durationMs, execution, data.nodeId, data.processId, event.ts), data.splitRunDurationMs));
207
321
  erroredNodes.set(data.nodeId, data.error);
@@ -211,12 +325,13 @@ export async function replayExecutionRecording(options) {
211
325
  case 'nodeExcluded': {
212
326
  const { data } = event;
213
327
  const node = getNode(data.nodeId);
214
- emitDetached(emitter, 'nodeExcluded', {
328
+ emitReplayExecutionEvent('nodeExcluded', {
215
329
  node,
216
330
  processId: data.processId,
217
331
  inputs: data.inputs,
218
332
  outputs: data.outputs,
219
333
  reason: data.reason,
334
+ ...(data.resultOrigin === undefined ? {} : { resultOrigin: data.resultOrigin }),
220
335
  execution: getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution),
221
336
  });
222
337
  visitedNodes.add(data.nodeId);
@@ -228,7 +343,7 @@ export async function replayExecutionRecording(options) {
228
343
  if (data.processId == null) {
229
344
  nodeResults.delete(data.nodeId);
230
345
  }
231
- emitDetached(emitter, 'nodeOutputsCleared', {
346
+ emitReplayExecutionEvent('nodeOutputsCleared', {
232
347
  node,
233
348
  processId: data.processId,
234
349
  execution: getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution),
@@ -238,18 +353,19 @@ export async function replayExecutionRecording(options) {
238
353
  case 'partialOutput': {
239
354
  const { data } = event;
240
355
  const node = getNode(data.nodeId);
241
- emitDetached(emitter, 'partialOutput', {
356
+ emitReplayExecutionEvent('partialOutput', {
242
357
  node,
243
358
  outputs: data.outputs,
244
359
  index: data.index,
245
360
  processId: data.processId,
361
+ ...(data.resultOrigin === undefined ? {} : { resultOrigin: data.resultOrigin }),
246
362
  execution: getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution),
247
363
  });
248
364
  break;
249
365
  }
250
366
  case 'progress': {
251
367
  const { data } = event;
252
- emitDetached(emitter, 'progress', {
368
+ emitReplayExecutionEvent('progress', {
253
369
  node: getNode(data.nodeId),
254
370
  processId: data.processId,
255
371
  progress: data.progress,
@@ -257,13 +373,33 @@ export async function replayExecutionRecording(options) {
257
373
  });
258
374
  break;
259
375
  }
376
+ case 'llmCallFinished': {
377
+ const { data } = event;
378
+ emitReplayExecutionEvent('llmCallFinished', {
379
+ ...data,
380
+ execution: getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution),
381
+ });
382
+ break;
383
+ }
384
+ case 'toolCallFinished': {
385
+ const { data } = event;
386
+ emitReplayExecutionEvent('toolCallFinished', {
387
+ ...data,
388
+ execution: getExecution(data.execution?.graphId ?? getGraphIdForNode(data.sourceNodeId), data.execution),
389
+ });
390
+ break;
391
+ }
260
392
  case 'userInput': {
261
393
  const { data } = event;
262
394
  const node = getNode(data.nodeId);
263
- emitDetached(emitter, 'userInput', {
264
- callback: undefined,
395
+ emitReplayExecutionEvent('userInput', {
396
+ // A replayed prompt is historical and must not wait for a new
397
+ // answer, but listeners still receive a safe callback-shaped
398
+ // event for compatibility with ordinary user-input observers.
399
+ callback: () => undefined,
265
400
  inputStrings: data.inputStrings,
266
401
  inputs: data.inputs,
402
+ isReplay: true,
267
403
  node,
268
404
  processId: data.processId,
269
405
  renderingType: data.renderingType,
@@ -292,7 +428,13 @@ export async function replayExecutionRecording(options) {
292
428
  }
293
429
  }
294
430
  catch (error) {
295
- emitDetached(emitter, 'error', { error: getError(error) });
431
+ const replayError = getError(error);
432
+ // A recording can fail before its first graph/node event, for example when
433
+ // it refers to a graph that no longer exists in the loaded project. The
434
+ // normal root-level `error` event is intentionally unscoped, so Run
435
+ // Activity has no active root to attach it to in that case.
436
+ emitFallbackRootTerminal('error', { error: replayError });
437
+ emitDetached(emitter, 'error', { error: replayError });
296
438
  }
297
439
  finally {
298
440
  setRunning(false);
@@ -4,7 +4,7 @@ import {} from './NodeBase.js';
4
4
  import { getGraphAbortReasonFromError, isAbortLikeError } from './GraphAbortReasons.js';
5
5
  import { getError } from '../utils/errors.js';
6
6
  import PQueue from '../utils/pQueueCompat.js';
7
- import { entries, fromEntries, values } from '../utils/typeSafety.js';
7
+ import { entries, fromEntries } from '../utils/typeSafety.js';
8
8
  function withOptionalDuration(payload, durationMs, splitRunDurationMs) {
9
9
  return {
10
10
  ...payload,
@@ -17,17 +17,28 @@ export async function processSplitRunNode(node, processId, deps) {
17
17
  if (deps.isExcludedDueToControlFlow(node, inputValues, processId)) {
18
18
  return;
19
19
  }
20
- const splittingAmount = Math.min(max(values(inputValues).map((value) => (Array.isArray(value?.value) ? value?.value.length : 1))) ?? 1, node.splitRunMax ?? 10);
21
- await deps.emit('nodeStart', { node, inputs: inputValues, processId });
20
+ const inputDefinitionsById = new Map(deps.getInputDefinitions(node).map((definition) => [definition.id, definition]));
21
+ const splittingAmount = Math.min(max(entries(inputValues).map(([portId, value]) => inputDefinitionsById.get(portId)?.splitRunBehavior === 'preserve-array'
22
+ ? 1
23
+ : Array.isArray(value?.value)
24
+ ? value.value.length
25
+ : 1)) ?? 1, node.splitRunMax ?? 10);
26
+ await deps.emit('nodeStart', {
27
+ node,
28
+ inputs: inputValues,
29
+ inputConnections: deps.getInputConnections(node),
30
+ processId,
31
+ resultOrigin: 'executed',
32
+ });
22
33
  const timingStart = deps.startNodeTiming?.();
23
34
  let splitRunDurationMs;
35
+ let results = [];
24
36
  try {
25
- let results;
26
37
  if (node.isSplitSequential) {
27
- results = await runSequential(node, inputValues, splittingAmount, processId, deps);
38
+ results = await runSequential(node, inputValues, inputDefinitionsById, splittingAmount, processId, deps);
28
39
  }
29
40
  else {
30
- results = await runParallel(node, inputValues, splittingAmount, processId, deps);
41
+ results = await runParallel(node, inputValues, inputDefinitionsById, splittingAmount, processId, deps);
31
42
  }
32
43
  splitRunDurationMs = getSplitRunDurationMs(results);
33
44
  const errors = results.filter((r) => r.type === 'error').map((r) => r.error);
@@ -47,53 +58,83 @@ export async function processSplitRunNode(node, processId, deps) {
47
58
  node,
48
59
  outputs: aggregateResults,
49
60
  processId,
61
+ resultOrigin: getSplitRunResultOrigin(results),
50
62
  }, deps.finishNodeTiming?.(timingStart), splitRunDurationMs));
51
63
  }
52
64
  catch (error) {
53
- await deps.nodeErrored(node, error, processId, deps.finishNodeTiming?.(timingStart), splitRunDurationMs);
65
+ await deps.nodeErrored(node, error, processId, deps.finishNodeTiming?.(timingStart), splitRunDurationMs, getSplitRunResultOrigin(results));
54
66
  }
55
67
  }
56
- async function runSequential(node, inputValues, splittingAmount, processId, deps) {
68
+ async function runSequential(node, inputValues, inputDefinitionsById, splittingAmount, processId, deps) {
57
69
  const results = [];
58
70
  for (let i = 0; i < splittingAmount; i++) {
59
71
  if (deps.isAborted()) {
60
72
  throw deps.getAbortError();
61
73
  }
62
- const inputs = splitInputsAtIndex(inputValues, i);
74
+ const inputs = splitInputsAtIndex(inputValues, inputDefinitionsById, i);
63
75
  const splitTimingStart = deps.startNodeTiming?.();
76
+ let resultOrigin = 'executed';
64
77
  try {
65
78
  const output = await deps.processNodeWithInputData(node, inputs, i, processId, (n, partialOutputs, index) => {
66
- deps.emit('partialOutput', { node: n, outputs: partialOutputs, index, processId });
79
+ deps.emit('partialOutput', {
80
+ node: n,
81
+ outputs: partialOutputs,
82
+ index,
83
+ processId,
84
+ resultOrigin: 'executed',
85
+ });
86
+ }, () => {
87
+ resultOrigin = 'editor-cache';
67
88
  });
68
89
  deps.accumulateCost(output);
69
- results.push({ type: 'output', output, durationMs: deps.finishNodeTiming?.(splitTimingStart) });
90
+ results.push({ type: 'output', output, resultOrigin, durationMs: deps.finishNodeTiming?.(splitTimingStart) });
70
91
  }
71
92
  catch (error) {
72
- results.push({ type: 'error', error: getError(error), durationMs: deps.finishNodeTiming?.(splitTimingStart) });
93
+ results.push({
94
+ type: 'error',
95
+ error: getError(error),
96
+ resultOrigin,
97
+ durationMs: deps.finishNodeTiming?.(splitTimingStart),
98
+ });
73
99
  }
74
100
  }
75
101
  return results;
76
102
  }
77
- async function runParallel(node, inputValues, splittingAmount, processId, deps) {
103
+ async function runParallel(node, inputValues, inputDefinitionsById, splittingAmount, processId, deps) {
78
104
  const queue = new PQueue({ concurrency: getParallelSplitRunConcurrency(node, deps.splitRunConcurrency) });
79
105
  return Promise.all(range(0, splittingAmount).map(async (i) => {
80
106
  const result = await queue.add(async () => {
81
107
  const splitTimingStart = deps.startNodeTiming?.();
108
+ let resultOrigin = 'executed';
82
109
  try {
83
110
  if (deps.isAborted()) {
84
111
  throw deps.getAbortError();
85
112
  }
86
- const inputs = splitInputsAtIndex(inputValues, i);
113
+ const inputs = splitInputsAtIndex(inputValues, inputDefinitionsById, i);
87
114
  const output = await deps.processNodeWithInputData(node, inputs, i, processId, (n, partialOutputs, index) => {
88
- deps.emit('partialOutput', { node: n, outputs: partialOutputs, index, processId });
115
+ deps.emit('partialOutput', {
116
+ node: n,
117
+ outputs: partialOutputs,
118
+ index,
119
+ processId,
120
+ resultOrigin: 'executed',
121
+ });
122
+ }, () => {
123
+ resultOrigin = 'editor-cache';
89
124
  });
90
125
  deps.accumulateCost(output);
91
- return { type: 'output', output, durationMs: deps.finishNodeTiming?.(splitTimingStart) };
126
+ return {
127
+ type: 'output',
128
+ output,
129
+ resultOrigin,
130
+ durationMs: deps.finishNodeTiming?.(splitTimingStart),
131
+ };
92
132
  }
93
133
  catch (error) {
94
134
  return {
95
135
  type: 'error',
96
136
  error: getError(error),
137
+ resultOrigin,
97
138
  durationMs: deps.finishNodeTiming?.(splitTimingStart),
98
139
  };
99
140
  }
@@ -104,14 +145,23 @@ async function runParallel(node, inputValues, splittingAmount, processId, deps)
104
145
  return result;
105
146
  }));
106
147
  }
148
+ function getSplitRunResultOrigin(results) {
149
+ return results.length > 0 && results.every((result) => result.resultOrigin === 'editor-cache')
150
+ ? 'editor-cache'
151
+ : 'executed';
152
+ }
107
153
  function getParallelSplitRunConcurrency(node, defaultConcurrency) {
108
154
  const value = node.splitRunConcurrency;
109
155
  return typeof value === 'number' && Number.isFinite(value) && value >= 2 ? Math.floor(value) : defaultConcurrency;
110
156
  }
111
- function splitInputsAtIndex(inputValues, index) {
157
+ function splitInputsAtIndex(inputValues, inputDefinitionsById, index) {
112
158
  return fromEntries(entries(inputValues).map(([port, value]) => [
113
159
  port,
114
- isArrayDataValue(value) ? arrayizeDataValue(value)[index] ?? undefined : value,
160
+ inputDefinitionsById.get(port)?.splitRunBehavior === 'preserve-array'
161
+ ? value
162
+ : isArrayDataValue(value)
163
+ ? arrayizeDataValue(value)[index] ?? undefined
164
+ : value,
115
165
  ]));
116
166
  }
117
167
  function aggregateOutputs(results) {
@@ -29,6 +29,8 @@ export function wireSubprocessorEvents(processor, parentEmitter, parentState) {
29
29
  processor.on('nodeFinish', (event) => parentEmitter.emit('nodeFinish', event)),
30
30
  processor.on('partialOutput', (event) => parentEmitter.emit('partialOutput', event)),
31
31
  processor.on('progress', (event) => parentEmitter.emit('progress', event)),
32
+ processor.on('llmCallFinished', (event) => parentEmitter.emit('llmCallFinished', event)),
33
+ processor.on('toolCallFinished', (event) => parentEmitter.emit('toolCallFinished', event)),
32
34
  processor.on('nodeExcluded', (event) => parentEmitter.emit('nodeExcluded', event)),
33
35
  processor.on('nodeStart', (event) => parentEmitter.emit('nodeStart', event)),
34
36
  processor.on('graphAbort', (event) => parentEmitter.emit('graphAbort', event)),
@@ -63,8 +63,11 @@ export class ToolCallContinuationCoordinator {
63
63
  const continuationBranchBoundaries = new Set(this.#adapter.getContinuationBranchBoundaryNodeIds(llmNode));
64
64
  // Validate the complete round before parallel calls can cause side effects.
65
65
  // The first invocation still produces a real Delegate error run for diagnostics.
66
+ let invalidInvocationIndex = 0;
66
67
  try {
67
- if (this.#adapter.hasPreloadedOrFrozenDelegateOutput(delegateNode, inputsByCall[0], processIds[0])) {
68
+ const frozenInvocationIndex = inputsByCall.findIndex((inputs, index) => this.#adapter.hasPreloadedOrFrozenDelegateOutput(delegateNode, inputs, processIds[index]));
69
+ if (frozenInvocationIndex >= 0) {
70
+ invalidInvocationIndex = frozenInvocationIndex;
68
71
  throw new Error(`Delegate Tool Call "${delegateNode.title}" is the active auto-continuation handler and cannot use preloaded or frozen outputs. Clear its preload or unfreeze it before running this graph.`);
69
72
  }
70
73
  if (hasActivePreToolBranch) {
@@ -80,8 +83,8 @@ export class ToolCallContinuationCoordinator {
80
83
  }
81
84
  }
82
85
  catch (error) {
83
- const processId = processIds[0];
84
- const inputs = inputsByCall[0];
86
+ const processId = processIds[invalidInvocationIndex];
87
+ const inputs = inputsByCall[invalidInvocationIndex];
85
88
  await this.#adapter.emitDelegateStart(delegateNode, inputs, processId);
86
89
  await this.#adapter.emitDelegateError(delegateNode, error, processId, this.#adapter.startNodeTiming());
87
90
  throw error;
@@ -153,7 +156,13 @@ export class ToolCallContinuationCoordinator {
153
156
  delegateFinished = true;
154
157
  const finalBranch = canRunContinuationBranches
155
158
  ? await branchAdapter.runOutputBranch({
156
- activeOutputPortIds: new Set(['output', 'message']),
159
+ activeOutputPortIds: new Set([
160
+ 'tool-name',
161
+ 'tool-arguments',
162
+ 'output',
163
+ 'execution-time',
164
+ 'message',
165
+ ]),
157
166
  availableNodeOutputs: preToolBranch.nodeOutputs,
158
167
  deferGraphOutputCommit: true,
159
168
  excludedNodeIds: continuationBranchBoundaries,
@@ -156,6 +156,27 @@ export function createUiGraphChatPinStatePatch(componentId, state, messageIndex)
156
156
  : [...pinnedIndexes, messageIndex].sort((left, right) => left - right),
157
157
  };
158
158
  }
159
+ /**
160
+ * Removes one persisted Chat message and keeps pinned assistant indexes aligned
161
+ * with the remaining history. Removing a pinned response unpins it.
162
+ */
163
+ export function createUiGraphChatMessageRemovalStatePatch(componentId, state, messageIndex) {
164
+ const messages = getUiGraphChatMessages(componentId, state);
165
+ if (!Number.isSafeInteger(messageIndex) || messageIndex < 0 || messageIndex >= messages.length) {
166
+ return undefined;
167
+ }
168
+ const pinsStateKey = getUiGraphChatPinsStateKey(componentId);
169
+ const pinnedIndexes = getUiGraphChatPins(componentId, state).map((pin) => pin.messageIndex);
170
+ const remainingPinnedIndexes = pinnedIndexes.flatMap((pinnedIndex) => {
171
+ if (pinnedIndex === messageIndex)
172
+ return [];
173
+ return [pinnedIndex > messageIndex ? pinnedIndex - 1 : pinnedIndex];
174
+ });
175
+ return {
176
+ [getUiGraphChatMessagesStateKey(componentId)]: messages.filter((_message, index) => index !== messageIndex),
177
+ [pinsStateKey]: remainingPinnedIndexes,
178
+ };
179
+ }
159
180
  /** Clears a Chat's conversation and pins without discarding an unsent draft. */
160
181
  export function createUiGraphChatHistoryFlushStatePatch(componentId) {
161
182
  return {
@@ -1,4 +1,5 @@
1
1
  import { normalizeGraphProgress } from './GraphProgress.js';
2
+ import { isAgentResponseTrace } from './AgentResponseTrace.js';
2
3
  export const RIVET_WEB_APP_ACTION_PROTOCOL_VERSION = 1;
3
4
  export function parseRivetWebAppClientMessage(value) {
4
5
  if (!isRecord(value) || typeof value.type !== 'string')
@@ -93,6 +94,7 @@ export function parseRivetWebAppServerMessage(value) {
93
94
  ...base,
94
95
  statePatch: value.statePatch,
95
96
  ...(isRecord(value.storagePatch) ? { storagePatch: value.storagePatch } : {}),
97
+ ...(isAgentResponseTrace(value.responseTrace) ? { responseTrace: value.responseTrace } : {}),
96
98
  }
97
99
  : undefined;
98
100
  case 'action.failed':