@valerypopoff/rivet2-core 2.3.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/cjs/bundle.cjs +1947 -765
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/interpolationRuntime.cjs +1578 -0
  4. package/dist/cjs/interpolationRuntime.cjs.map +7 -0
  5. package/dist/cjs/interpolationSyntax.cjs +186 -0
  6. package/dist/cjs/interpolationSyntax.cjs.map +7 -0
  7. package/dist/cjs/webAppRuntime.cjs +1537 -121
  8. package/dist/cjs/webAppRuntime.cjs.map +4 -4
  9. package/dist/esm/api/createProcessor.js +2 -0
  10. package/dist/esm/exports.js +4 -1
  11. package/dist/esm/integrations/CodeRunner.js +5 -0
  12. package/dist/esm/integrations/mcp/MCPBase.js +16 -6
  13. package/dist/esm/interpolationRuntime.js +5 -0
  14. package/dist/esm/model/AgentResponseTrace.js +16 -0
  15. package/dist/esm/model/GraphBoundaryCache.js +0 -6
  16. package/dist/esm/model/GraphBoundaryEffects.js +5 -1
  17. package/dist/esm/model/GraphOutputSelection.js +34 -0
  18. package/dist/esm/model/GraphProcessor.js +150 -44
  19. package/dist/esm/model/NodeExclusionPolicy.js +9 -1
  20. package/dist/esm/model/ProcessContextBuilder.js +4 -1
  21. package/dist/esm/model/RecordingPlayer.js +19 -6
  22. package/dist/esm/model/StoredValueStore.js +4 -3
  23. package/dist/esm/model/SubprocessorBridge.js +1 -0
  24. package/dist/esm/model/UiGraphActionProtocol.js +46 -4
  25. package/dist/esm/model/UiGraphBrowserRuntime.js +15 -1
  26. package/dist/esm/model/UiGraphIndexedDbPersistence.js +523 -0
  27. package/dist/esm/model/UiGraphRendererStyles.js +14 -0
  28. package/dist/esm/model/WebAppBrowserStorage.js +653 -0
  29. package/dist/esm/model/WebAppBrowserStorageRpc.js +200 -0
  30. package/dist/esm/model/chat-v2/chatV2CallObserver.js +1 -0
  31. package/dist/esm/model/chat-v2/chatV2EditorCache.js +2 -33
  32. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +1 -0
  33. package/dist/esm/model/chat-v2/llmChatV2OutputClone.js +42 -0
  34. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +31 -2
  35. package/dist/esm/model/chat-v2/llmProfile.js +17 -1
  36. package/dist/esm/model/chat-v2/llmProfileFallback.js +17 -5
  37. package/dist/esm/model/chat-v2/llmProfileHealthStore.js +2 -0
  38. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +4 -0
  39. package/dist/esm/model/chat-v2/toolContinuation.js +27 -1
  40. package/dist/esm/model/nodes/CodeNewNode.js +16 -16
  41. package/dist/esm/model/nodes/DestructureNode.js +2 -2
  42. package/dist/esm/model/nodes/ExpressionNode.js +16 -16
  43. package/dist/esm/model/nodes/ExtractObjectPathNode.js +2 -2
  44. package/dist/esm/model/nodes/ExtractYamlNode.js +5 -5
  45. package/dist/esm/model/nodes/JSFilterNode.js +3 -1
  46. package/dist/esm/model/nodes/JSMapNode.js +3 -1
  47. package/dist/esm/model/nodes/LLMChatV2Node.js +21 -2
  48. package/dist/esm/model/nodes/MCPGetPromptNode.js +6 -2
  49. package/dist/esm/model/nodes/MCPToolCallNode.js +6 -2
  50. package/dist/esm/model/nodes/ObjectNode.js +19 -20
  51. package/dist/esm/model/nodes/PromptNode.js +10 -11
  52. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +2 -40
  53. package/dist/esm/model/nodes/SubGraphNode.js +40 -26
  54. package/dist/esm/model/nodes/TextNode.js +11 -32
  55. package/dist/esm/model/nodes/ToTreeNode.js +6 -13
  56. package/dist/esm/model/nodes/ToolNode.js +33 -16
  57. package/dist/esm/model/nodes/jsListCallbackHelpers.js +19 -15
  58. package/dist/esm/model/nodes/jsValueInterpolation.js +83 -30
  59. package/dist/esm/model/nodes/nodeBodyPreview.js +23 -0
  60. package/dist/esm/plugins/openai/nodes/ThreadMessageNode.js +14 -11
  61. package/dist/esm/recording/ExecutionRecorder.js +1 -0
  62. package/dist/esm/utils/index.js +2 -0
  63. package/dist/esm/utils/interpolation.js +478 -221
  64. package/dist/esm/utils/interpolationSyntax.js +175 -0
  65. package/dist/esm/utils/jsonPath.js +129 -0
  66. package/dist/esm/webAppRuntime.js +5 -2
  67. package/dist/types/api/createProcessor.d.ts +2 -0
  68. package/dist/types/exports.d.ts +5 -1
  69. package/dist/types/integrations/CodeRunnerOptions.d.ts +9 -0
  70. package/dist/types/integrations/mcp/MCPBase.d.ts +3 -1
  71. package/dist/types/interpolationRuntime.d.ts +5 -0
  72. package/dist/types/model/AgentResponseTrace.d.ts +1 -0
  73. package/dist/types/model/ExecutorProtocol.d.ts +9 -1
  74. package/dist/types/model/GraphBoundaryCache.d.ts +0 -2
  75. package/dist/types/model/GraphOutputSelection.d.ts +8 -0
  76. package/dist/types/model/GraphProcessor.d.ts +7 -4
  77. package/dist/types/model/NodeExclusionPolicy.d.ts +6 -0
  78. package/dist/types/model/ProcessContext.d.ts +36 -2
  79. package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
  80. package/dist/types/model/UiGraphActionProtocol.d.ts +8 -3
  81. package/dist/types/model/UiGraphBrowserRuntime.d.ts +6 -0
  82. package/dist/types/model/UiGraphIndexedDbPersistence.d.ts +50 -0
  83. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  84. package/dist/types/model/WebAppBrowserStorage.d.ts +90 -0
  85. package/dist/types/model/WebAppBrowserStorageRpc.d.ts +85 -0
  86. package/dist/types/model/chat-v2/chatV2Types.d.ts +3 -1
  87. package/dist/types/model/chat-v2/llmChatV2OutputClone.d.ts +3 -0
  88. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +5 -1
  89. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +4 -0
  90. package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +10 -0
  91. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +6 -0
  92. package/dist/types/model/chat-v2/toolContinuation.d.ts +14 -0
  93. package/dist/types/model/nodes/ObjectNode.d.ts +1 -1
  94. package/dist/types/model/nodes/SubGraphNode.d.ts +2 -0
  95. package/dist/types/model/nodes/ToTreeNode.d.ts +5 -2
  96. package/dist/types/model/nodes/ToolNode.d.ts +13 -1
  97. package/dist/types/model/nodes/jsValueInterpolation.d.ts +16 -8
  98. package/dist/types/model/nodes/nodeBodyPreview.d.ts +7 -0
  99. package/dist/types/recording/RecordedEvents.d.ts +11 -0
  100. package/dist/types/utils/index.d.ts +2 -0
  101. package/dist/types/utils/interpolation.d.ts +93 -8
  102. package/dist/types/utils/interpolationSyntax.d.ts +21 -0
  103. package/dist/types/utils/jsonPath.d.ts +15 -0
  104. package/dist/types/webAppRuntime.d.ts +8 -2
  105. package/package.json +11 -1
@@ -11,6 +11,14 @@ const nodesAllowedToConsumeExcludedValue = new Set([
11
11
  'raceInputs',
12
12
  'loopController',
13
13
  ]);
14
+ /**
15
+ * Whether a node intentionally handles an input that was excluded by control
16
+ * flow. Most nodes are excluded themselves in that situation; these nodes
17
+ * implement their own fallback, branching, or aggregation behavior instead.
18
+ */
19
+ export function canConsumeControlFlowExcludedInput(node) {
20
+ return nodesAllowedToConsumeExcludedValue.has(node.type);
21
+ }
14
22
  function isControlFlowExcluded(value) {
15
23
  return value != null && getScalarTypeOf(value.type) === 'control-flow-excluded';
16
24
  }
@@ -34,7 +42,7 @@ export function getControlFlowExclusionDecision({ inputValues, node, typeOfExclu
34
42
  }
35
43
  const controlFlowExcludedValues = entries(inputValues).filter(([, value]) => isControlFlowExcluded(value) && (typeOfExclusion === undefined || value.value === typeOfExclusion));
36
44
  const isWaitingForLoop = controlFlowExcludedValues.some(([, value]) => value?.value === LOOP_NOT_BROKEN_SENTINEL);
37
- const allowedToConsumeExcludedValue = nodesAllowedToConsumeExcludedValue.has(node.type) && !isWaitingForLoop;
45
+ const allowedToConsumeExcludedValue = canConsumeControlFlowExcludedInput(node) && !isWaitingForLoop;
38
46
  if (controlFlowExcludedValues.length === 0 || allowedToConsumeExcludedValue) {
39
47
  return { action: 'continue' };
40
48
  }
@@ -1,5 +1,5 @@
1
1
  export function buildNodeProcessContext(options) {
2
- const { attachedData, activeOutputPortIds, base, createSubProcessor, execution, externalFunctions, getPluginConfig, isDirectRunTarget, markResultAsEditorCacheHit, node, nodeAbortController, onPartialOutputs, processId, requestUserInput, reportProgress, setGlobal, toolCallContinuation, toolCallTraceSource, waitEvent, } = options;
2
+ const { attachedData, activeOutputPortIds, base, createSubProcessor, execution, externalFunctions, getPluginConfig, isDirectRunTarget, markResultAsEditorCacheHit, node, nodeAbortController, onPartialOutputs, processId, requestUserInput, reportProgress, setGlobal, splitIndex, toolCallContinuation, toolCallTraceSource, waitEvent, } = options;
3
3
  return {
4
4
  ...base,
5
5
  node,
@@ -8,10 +8,13 @@ export function buildNodeProcessContext(options) {
8
8
  isDirectRunTarget,
9
9
  markResultAsEditorCacheHit,
10
10
  waitEvent,
11
+ waitForGlobal: (id, signal = nodeAbortController.signal) => base.waitForGlobal(id, signal),
12
+ waitForStoredValue: (key, signal = nodeAbortController.signal) => base.waitForStoredValue(key, signal),
11
13
  externalFunctions: { ...externalFunctions },
12
14
  onPartialOutputs,
13
15
  signal: nodeAbortController.signal,
14
16
  processId,
17
+ splitIndex,
15
18
  setGlobal,
16
19
  createSubProcessor: createSubProcessor,
17
20
  getPluginConfig,
@@ -34,7 +34,8 @@ const REPLAY_TIMED_LIFECYCLE_EVENTS = new Set([
34
34
  'nodeOutputsCleared',
35
35
  ]);
36
36
  export async function replayExecutionRecording(options) {
37
- const { emitter, erroredNodes, graphOutputs, fallbackGraphId, initialReplayExecution, project, recorder, recordingPlaybackChatLatency, setContextValues, setGraphInputs, setGraphOutputs, setRunning, visitedNodes, waitUntilUnpaused, nodeResults, isAborted, } = options;
37
+ const { emitter, erroredNodes, fallbackGraphId, initialReplayExecution, project, recorder, recordingPlaybackChatLatency, setContextValues, setGraphInputs, setGraphOutputs, setRunning, visitedNodes, waitUntilUnpaused, nodeResults, isAborted, } = options;
38
+ let graphOutputs = options.graphOutputs;
38
39
  const nodesByIdAllGraphs = {};
39
40
  const graphIdByNodeId = {};
40
41
  for (const graph of Object.values(project.graphs)) {
@@ -165,13 +166,13 @@ export async function replayExecutionRecording(options) {
165
166
  : nanoid();
166
167
  replayRootRunIds.set(recordedExecution.rootRunId, replayRootRunId);
167
168
  }
168
- const getReplayGraphRunId = (recordedGraphRunId) => {
169
+ const getReplayGraphRunId = (recordedGraphRunId, initialGraphRunId) => {
169
170
  let graphRunIds = replayGraphRunIdsByRoot.get(recordedExecution.rootRunId);
170
171
  if (graphRunIds == null) {
171
172
  graphRunIds = new Map();
172
173
  replayGraphRunIdsByRoot.set(recordedExecution.rootRunId, graphRunIds);
173
174
  }
174
- const replayGraphRunId = graphRunIds.get(recordedGraphRunId) ?? nanoid();
175
+ const replayGraphRunId = initialGraphRunId ?? graphRunIds.get(recordedGraphRunId) ?? nanoid();
175
176
  graphRunIds.set(recordedGraphRunId, replayGraphRunId);
176
177
  return replayGraphRunId;
177
178
  };
@@ -183,7 +184,9 @@ export async function replayExecutionRecording(options) {
183
184
  return {
184
185
  ...rest,
185
186
  rootRunId: replayRootRunId,
186
- graphRunId: isInitialRootGraph ? initialReplayExecution.graphRunId : getReplayGraphRunId(graphRunId),
187
+ // Seed the root mapping too, so child parentGraphRunId references resolve
188
+ // to the same identity already allocated by the playback processor.
189
+ graphRunId: getReplayGraphRunId(graphRunId, isInitialRootGraph ? initialReplayExecution.graphRunId : undefined),
187
190
  ...(parentGraphRunId == null ? {} : { parentGraphRunId: getReplayGraphRunId(parentGraphRunId) }),
188
191
  };
189
192
  };
@@ -234,8 +237,10 @@ export async function replayExecutionRecording(options) {
234
237
  case 'done': {
235
238
  emitFallbackRootTerminal('completed', { outputs: event.data.results });
236
239
  emitReplayTerminalEvent('done', event.data);
237
- setGraphOutputs(event.data.results);
238
- setRunning(false);
240
+ graphOutputs = event.data.results;
241
+ setGraphOutputs(graphOutputs);
242
+ // Keep ownership until playback drains, just like a live graph run.
243
+ // A done listener must not start work that final cleanup could clobber.
239
244
  break;
240
245
  }
241
246
  case 'error': {
@@ -414,6 +419,14 @@ export async function replayExecutionRecording(options) {
414
419
  });
415
420
  break;
416
421
  }
422
+ case 'llmChatOutputSnapshot': {
423
+ const { data } = event;
424
+ emitReplayExecutionEvent('llmChatOutputSnapshot', {
425
+ ...data,
426
+ execution: getExecution(data.execution?.graphId ?? getGraphIdForNode(data.nodeId), data.execution),
427
+ });
428
+ break;
429
+ }
417
430
  case 'llmProfileAttempt': {
418
431
  const { data } = event;
419
432
  emitReplayExecutionEvent('llmProfileAttempt', {
@@ -87,10 +87,11 @@ export class RivetStoredValueController {
87
87
  }
88
88
  });
89
89
  });
90
+ // Observe the registered wait before checking cancellation again, or an
91
+ // abort while the key lock releases can orphan its rejected promise.
92
+ const value = waiterPromise === undefined ? immediateValue : await waiterPromise;
90
93
  signal?.throwIfAborted();
91
- if (immediateValue !== undefined)
92
- return immediateValue;
93
- return await waiterPromise;
94
+ return value;
94
95
  }
95
96
  async #getUnlocked(key) {
96
97
  const cached = this.#cache.get(key);
@@ -30,6 +30,7 @@ export function wireSubprocessorEvents(processor, parentEmitter, parentState) {
30
30
  processor.on('partialOutput', (event) => parentEmitter.emit('partialOutput', event)),
31
31
  processor.on('progress', (event) => parentEmitter.emit('progress', event)),
32
32
  processor.on('llmCallFinished', (event) => parentEmitter.emit('llmCallFinished', event)),
33
+ processor.on('llmChatOutputSnapshot', (event) => parentEmitter.emit('llmChatOutputSnapshot', event)),
33
34
  processor.on('llmProfileAttempt', (event) => parentEmitter.emit('llmProfileAttempt', event)),
34
35
  processor.on('toolCallFinished', (event) => parentEmitter.emit('toolCallFinished', event)),
35
36
  processor.on('nodeExcluded', (event) => parentEmitter.emit('nodeExcluded', event)),
@@ -1,13 +1,21 @@
1
1
  import { normalizeGraphProgress } from './GraphProgress.js';
2
2
  import { isAgentResponseTrace } from './AgentResponseTrace.js';
3
+ import { RIVET_WEB_APP_BROWSER_STORAGE_DEFAULT_TRANSFER_TIMEOUT_MS, parseRivetWebAppBrowserStorageClientMessage, parseRivetWebAppBrowserStorageServerMessage, } from './WebAppBrowserStorageRpc.js';
3
4
  export const RIVET_WEB_APP_ACTION_PROTOCOL_VERSION = 1;
4
5
  export function parseRivetWebAppClientMessage(value) {
5
6
  if (!isRecord(value) || typeof value.type !== 'string')
6
7
  return undefined;
8
+ const storageMessage = parseRivetWebAppBrowserStorageClientMessage(value);
9
+ if (storageMessage)
10
+ return storageMessage;
7
11
  switch (value.type) {
8
12
  case 'client.hello':
9
13
  return value.protocolVersion === RIVET_WEB_APP_ACTION_PROTOCOL_VERSION
10
- ? { type: value.type, protocolVersion: value.protocolVersion }
14
+ ? {
15
+ type: value.type,
16
+ protocolVersion: value.protocolVersion,
17
+ ...(isStringArray(value.capabilities) ? { capabilities: value.capabilities } : {}),
18
+ }
11
19
  : undefined;
12
20
  case 'action.start':
13
21
  return isNonEmptyString(value.requestId) &&
@@ -22,6 +30,7 @@ export function parseRivetWebAppClientMessage(value) {
22
30
  state: value.state,
23
31
  ...(isRecord(value.storage) ? { storage: value.storage } : {}),
24
32
  ...(typeof value.revisionKey === 'string' ? { revisionKey: value.revisionKey } : {}),
33
+ ...(value.storageRpcVersion === 2 ? { storageRpcVersion: 2 } : {}),
25
34
  }
26
35
  : undefined;
27
36
  case 'action.cancel':
@@ -40,10 +49,21 @@ export function parseRivetWebAppClientMessage(value) {
40
49
  export function parseRivetWebAppServerMessage(value) {
41
50
  if (!isRecord(value) || typeof value.type !== 'string')
42
51
  return undefined;
52
+ const storageMessage = parseRivetWebAppBrowserStorageServerMessage(value);
53
+ if (storageMessage)
54
+ return storageMessage;
43
55
  if (value.type === 'server.ready') {
44
- return value.protocolVersion === RIVET_WEB_APP_ACTION_PROTOCOL_VERSION
45
- ? { type: value.type, protocolVersion: value.protocolVersion }
46
- : undefined;
56
+ if (value.protocolVersion !== RIVET_WEB_APP_ACTION_PROTOCOL_VERSION)
57
+ return undefined;
58
+ const browserStorageRpcLimits = parseBrowserStorageRpcLimits(value.browserStorageRpcLimits);
59
+ if (value.browserStorageRpcLimits != null && !browserStorageRpcLimits)
60
+ return undefined;
61
+ return {
62
+ type: value.type,
63
+ protocolVersion: value.protocolVersion,
64
+ ...(isStringArray(value.capabilities) ? { capabilities: value.capabilities } : {}),
65
+ ...(browserStorageRpcLimits ? { browserStorageRpcLimits } : {}),
66
+ };
47
67
  }
48
68
  if (value.type === 'server.draining')
49
69
  return { type: value.type };
@@ -129,6 +149,28 @@ function hasRunEventBase(value) {
129
149
  function isRecord(value) {
130
150
  return typeof value === 'object' && value != null && !Array.isArray(value);
131
151
  }
152
+ function parseBrowserStorageRpcLimits(value) {
153
+ if (!isRecord(value))
154
+ return undefined;
155
+ if (!isPositiveSafeInteger(value.maxActionBytes) ||
156
+ !isPositiveSafeInteger(value.maxValueBytes) ||
157
+ value.maxValueBytes > value.maxActionBytes) {
158
+ return undefined;
159
+ }
160
+ if (value.transferTimeoutMs != null && !isPositiveSafeInteger(value.transferTimeoutMs))
161
+ return undefined;
162
+ return {
163
+ maxActionBytes: value.maxActionBytes,
164
+ maxValueBytes: value.maxValueBytes,
165
+ transferTimeoutMs: value.transferTimeoutMs ?? RIVET_WEB_APP_BROWSER_STORAGE_DEFAULT_TRANSFER_TIMEOUT_MS,
166
+ };
167
+ }
168
+ function isPositiveSafeInteger(value) {
169
+ return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
170
+ }
132
171
  function isNonEmptyString(value) {
133
172
  return typeof value === 'string' && value.length > 0;
134
173
  }
174
+ function isStringArray(value) {
175
+ return (Array.isArray(value) && value.length <= 16 && value.every((item) => typeof item === 'string' && item.length <= 100));
176
+ }
@@ -144,7 +144,7 @@ export function getUiGraphWebAppStorageKey(uiGraph, location = getDefaultUiGraph
144
144
  encodeURIComponent(uiGraph.id),
145
145
  ].join(':');
146
146
  }
147
- function getUiGraphResponseTraceStorageKey(uiGraph, componentId, location = getDefaultUiGraphStorageLocation()) {
147
+ export function getUiGraphResponseTraceStorageKey(uiGraph, componentId, location = getDefaultUiGraphStorageLocation()) {
148
148
  if (!location?.origin)
149
149
  return undefined;
150
150
  const pathname = location.pathname.replace(/\/+$/, '') || '/';
@@ -296,6 +296,20 @@ export function applyUiGraphWebAppStorageActionPatch(patch, actionNumber, applie
296
296
  appliedActionByKey.set(key, actionNumber);
297
297
  return applicablePatch;
298
298
  }
299
+ /**
300
+ * Async equivalent used by IndexedDB-backed clients. Ordering metadata is
301
+ * advanced only after the durable commit succeeds.
302
+ */
303
+ export async function applyUiGraphWebAppStorageActionPatchAsync(patch, actionNumber, appliedActionByKey, persist) {
304
+ const applicablePatch = Object.fromEntries(Object.entries(patch).filter(([key]) => actionNumber >= (appliedActionByKey.get(key) ?? 0)));
305
+ const applicableKeys = Object.keys(applicablePatch);
306
+ if (applicableKeys.length === 0)
307
+ return applicablePatch;
308
+ await persist(applicablePatch);
309
+ for (const key of applicableKeys)
310
+ appliedActionByKey.set(key, actionNumber);
311
+ return applicablePatch;
312
+ }
299
313
  /** Selects and validates the private browser-persisted state of Chat components only. */
300
314
  export function getUiGraphChatPersistentState(uiGraph, state) {
301
315
  const persistentState = {};