@valerypopoff/rivet2-core 2.1.9 → 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 (155) hide show
  1. package/dist/cjs/bundle.cjs +3596 -1745
  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 +151 -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 +49 -8
  13. package/dist/esm/model/SubprocessorBridge.js +2 -0
  14. package/dist/esm/model/ToolCallContinuationCoordinator.js +7 -3
  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/aiSdkTools.js +3 -2
  22. package/dist/esm/model/chat-v2/chatV2CallObserver.js +9 -5
  23. package/dist/esm/model/chat-v2/chatV2EditorCache.js +42 -16
  24. package/dist/esm/model/chat-v2/chatV2Errors.js +7 -19
  25. package/dist/esm/model/chat-v2/chatV2FeatureCompatibility.js +1 -1
  26. package/dist/esm/model/chat-v2/chatV2Outputs.js +48 -108
  27. package/dist/esm/model/chat-v2/chatV2Pipeline.js +61 -146
  28. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +8 -2
  29. package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +9 -0
  30. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +2 -3
  31. package/dist/esm/model/chat-v2/chatV2ResponseBodyCapture.js +55 -0
  32. package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +8 -4
  33. package/dist/esm/model/chat-v2/chatV2Retry.js +4 -3
  34. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +6 -1
  35. package/dist/esm/model/chat-v2/chatV2Types.js +5 -9
  36. package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +78 -0
  37. package/dist/esm/model/chat-v2/customProviderApi.js +42 -0
  38. package/dist/esm/model/chat-v2/index.js +12 -0
  39. package/dist/esm/model/chat-v2/llmChatV2Body.js +281 -0
  40. package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +32 -0
  41. package/dist/esm/model/chat-v2/llmChatV2CachePolicy.js +20 -0
  42. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +6 -50
  43. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +25 -13
  44. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +24 -0
  45. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +121 -193
  46. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +60 -0
  47. package/dist/esm/model/chat-v2/llmInvocationDecision.js +11 -0
  48. package/dist/esm/model/chat-v2/llmInvocationJournal.js +43 -0
  49. package/dist/esm/model/chat-v2/llmInvocationPlan.js +68 -0
  50. package/dist/esm/model/chat-v2/llmInvocationProjections.js +5 -0
  51. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +48 -0
  52. package/dist/esm/model/chat-v2/llmModelCandidate.js +75 -0
  53. package/dist/esm/model/chat-v2/llmProfile.js +10 -65
  54. package/dist/esm/model/chat-v2/llmProfileBody.js +183 -0
  55. package/dist/esm/model/chat-v2/llmProfileFallback.js +55 -99
  56. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +67 -0
  57. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +3 -0
  58. package/dist/esm/model/chat-v2/llmProfileTypes.js +1 -18
  59. package/dist/esm/model/chat-v2/llmResponseMaterializer.js +42 -0
  60. package/dist/esm/model/chat-v2/modelRegistry.js +54 -4
  61. package/dist/esm/model/chat-v2/parallelToolCalls.js +9 -2
  62. package/dist/esm/model/chat-v2/providerOptions.js +86 -20
  63. package/dist/esm/model/chat-v2/rivetToolRegistry.js +9 -0
  64. package/dist/esm/model/chat-v2/toolCallCodec.js +52 -0
  65. package/dist/esm/model/chat-v2/toolContinuation.js +72 -35
  66. package/dist/esm/model/chat-v2/toolHandlerResolver.js +23 -0
  67. package/dist/esm/model/chat-v2/toolRoundExecutor.js +12 -0
  68. package/dist/esm/model/nodes/ChatNode.js +6 -0
  69. package/dist/esm/model/nodes/ChatNodeBase.js +1 -0
  70. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +19 -6
  71. package/dist/esm/model/nodes/LLMChatV2Node.js +112 -229
  72. package/dist/esm/model/nodes/LLMProfileNode.js +27 -8
  73. package/dist/esm/model/nodes/PromptNode.js +7 -0
  74. package/dist/esm/model/nodes/ToolNode.js +7 -0
  75. package/dist/esm/model/nodes/toolCallDelegation.js +177 -110
  76. package/dist/esm/plugins/anthropic/anthropic.js +4 -4
  77. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +7 -0
  78. package/dist/esm/plugins/google/google.js +5 -9
  79. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +4 -1
  80. package/dist/esm/recording/ExecutionRecorder.js +13 -5
  81. package/dist/esm/utils/emitDetached.js +6 -3
  82. package/dist/esm/utils/openai.js +60 -16
  83. package/dist/esm/utils/serialization/serialization.js +2 -19
  84. package/dist/esm/webAppRuntime.js +3 -2
  85. package/dist/types/exports.d.ts +1 -0
  86. package/dist/types/model/AgentResponseTrace.d.ts +110 -0
  87. package/dist/types/model/ConnectedToolContinuationHost.d.ts +34 -0
  88. package/dist/types/model/ExecutorProtocol.d.ts +25 -7
  89. package/dist/types/model/GraphProcessor.d.ts +27 -5
  90. package/dist/types/model/NodeImpl.d.ts +18 -1
  91. package/dist/types/model/Nodes.d.ts +2 -2
  92. package/dist/types/model/ProcessContext.d.ts +47 -0
  93. package/dist/types/model/ProcessContextBuilder.d.ts +3 -1
  94. package/dist/types/model/RecordingPlayer.d.ts +6 -0
  95. package/dist/types/model/SplitRunProcessor.d.ts +10 -3
  96. package/dist/types/model/UiGraph.d.ts +8 -0
  97. package/dist/types/model/UiGraphActionProtocol.d.ts +2 -0
  98. package/dist/types/model/UiGraphBrowserRuntime.d.ts +11 -2
  99. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  100. package/dist/types/model/UiGraphRuntimeModel.d.ts +2 -0
  101. package/dist/types/model/UiGraphSchema.d.ts +1 -0
  102. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +2 -0
  103. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +1 -3
  104. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +6 -16
  105. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +13 -17
  106. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +4 -0
  107. package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +8 -0
  108. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  109. package/dist/types/model/chat-v2/chatV2ResponseBodyCapture.d.ts +19 -0
  110. package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +3 -2
  111. package/dist/types/model/chat-v2/chatV2Retry.d.ts +2 -0
  112. package/dist/types/model/chat-v2/chatV2Types.d.ts +20 -10
  113. package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +14 -0
  114. package/dist/types/model/chat-v2/customProviderApi.d.ts +23 -0
  115. package/dist/types/model/chat-v2/index.d.ts +12 -0
  116. package/dist/types/model/chat-v2/llmChatV2Body.d.ts +24 -0
  117. package/dist/types/model/chat-v2/llmChatV2CacheBoundary.d.ts +10 -0
  118. package/dist/types/model/chat-v2/llmChatV2CachePolicy.d.ts +13 -0
  119. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +10 -3
  120. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +8 -0
  121. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +14 -16
  122. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +16 -0
  123. package/dist/types/model/chat-v2/llmInvocationDecision.d.ts +21 -0
  124. package/dist/types/model/chat-v2/llmInvocationJournal.d.ts +38 -0
  125. package/dist/types/model/chat-v2/llmInvocationPlan.d.ts +41 -0
  126. package/dist/types/model/chat-v2/llmInvocationProjections.d.ts +3 -0
  127. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +26 -0
  128. package/dist/types/model/chat-v2/llmModelCandidate.d.ts +18 -0
  129. package/dist/types/model/chat-v2/llmProfileBody.d.ts +20 -0
  130. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +17 -49
  131. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +189 -0
  132. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +1 -1
  133. package/dist/types/model/chat-v2/llmResponseMaterializer.d.ts +20 -0
  134. package/dist/types/model/chat-v2/modelRegistry.d.ts +17 -187
  135. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +3 -1
  136. package/dist/types/model/chat-v2/providerOptions.d.ts +10 -0
  137. package/dist/types/model/chat-v2/rivetToolRegistry.d.ts +11 -0
  138. package/dist/types/model/chat-v2/toolCallCodec.d.ts +7 -0
  139. package/dist/types/model/chat-v2/toolContinuation.d.ts +3 -3
  140. package/dist/types/model/chat-v2/toolHandlerResolver.d.ts +25 -0
  141. package/dist/types/model/chat-v2/toolRoundExecutor.d.ts +18 -0
  142. package/dist/types/model/nodes/ChatNode.d.ts +2 -1
  143. package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +2 -1
  144. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  145. package/dist/types/model/nodes/LLMProfileNode.d.ts +2 -1
  146. package/dist/types/model/nodes/PromptNode.d.ts +4 -1
  147. package/dist/types/model/nodes/ToolNode.d.ts +2 -1
  148. package/dist/types/model/nodes/toolCallDelegation.d.ts +10 -3
  149. package/dist/types/plugins/anthropic/anthropic.d.ts +1 -0
  150. package/dist/types/plugins/google/google.d.ts +2 -8
  151. package/dist/types/recording/RecordedEvents.d.ts +6 -0
  152. package/dist/types/utils/emitDetached.d.ts +3 -2
  153. package/dist/types/utils/openai.d.ts +49 -0
  154. package/dist/types/webAppRuntime.d.ts +4 -2
  155. package/package.json +2 -2
@@ -31,6 +31,7 @@ import { ManagedAsyncBranches } from './ManagedAsyncBranches.js';
31
31
  import { KnowledgeStoreController } from '../integrations/KnowledgeStoreProvider.js';
32
32
  import { isDataBusTopologyNode } from './DataBusTopology.js';
33
33
  import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
34
+ import { ConnectedToolContinuationHost, } from './ConnectedToolContinuationHost.js';
34
35
  // eslint-disable-next-line import/no-cycle -- There has to be a cycle because CodeRunner needs to import the entirety of Rivet
35
36
  import { IsomorphicCodeRunner } from '../integrations/CodeRunner.js';
36
37
  const graphProcessorGraphOverride = Symbol('graphProcessorGraphOverride');
@@ -150,7 +151,7 @@ export class GraphProcessor {
150
151
  #sharedRunStateOverride;
151
152
  #suppressedPreloadedNodeIds = new Set();
152
153
  #preloadedNodeResults = new Map();
153
- #toolCallContinuationInvocations = new Map();
154
+ #connectedToolContinuationHost = new ConnectedToolContinuationHost();
154
155
  #continuationCompletionOwnerByNodeId = new Map();
155
156
  #effectiveConnectionsForRun;
156
157
  #asyncBranchPlansByTriggerNodeId = new Map();
@@ -595,12 +596,19 @@ export class GraphProcessor {
595
596
  }
596
597
  }
597
598
  async replayRecording(recorder) {
599
+ // Playback is a new root run, even though its node/graph events originate
600
+ // from a historic recording. Giving the processor a real identity here is
601
+ // essential if the user aborts while playback is in progress: abort()
602
+ // emits its own graph terminal outside RecordingPlayer's event adapter.
603
+ this.#initializeExecutionIdentity();
598
604
  this.#initProcessState();
599
605
  this.#graphOutputs = await replayExecutionRecording({
600
606
  emitter: this.#emitter,
601
607
  erroredNodes: this.#erroredNodes,
602
608
  graphInputs: this.#graphInputs,
603
609
  graphOutputs: this.#graphOutputs,
610
+ fallbackGraphId: this.#graph.metadata.id,
611
+ initialReplayExecution: this.#buildExecutionMetadata(),
604
612
  isAborted: () => this.#lifecycle.isAborted,
605
613
  nodeResults: this.#nodeResults,
606
614
  project: this.#project,
@@ -641,7 +649,7 @@ export class GraphProcessor {
641
649
  this.#graphOutputs = this.#sharedRunStateOverride?.graphOutputs ?? {};
642
650
  this.#executionCache ??= new Map();
643
651
  this.#queuedNodes = new Set();
644
- this.#toolCallContinuationInvocations = new Map();
652
+ this.#connectedToolContinuationHost.reset();
645
653
  this.#continuationCompletionOwnerByNodeId = new Map();
646
654
  this.#effectiveConnectionsForRun = undefined;
647
655
  this.#asyncBranchPlansByTriggerNodeId = new Map();
@@ -698,12 +706,12 @@ export class GraphProcessor {
698
706
  let outputsWerePublishedEarly = false;
699
707
  const completionPromise = (async () => {
700
708
  try {
701
- this.#profileRuntimeSync('initializeGraphRun', () => this.#initializeGraphRun(context, inputs, contextValues));
702
- await this.#profileRuntimeAsync('loadProjectReferences', () => this.#loadProjectReferences());
703
- this.#profileRuntimeSync('prepareNodeProcessContextBase', () => this.#prepareNodeProcessContextBase());
704
- const shouldUseSeededExecutionPlan = this.#seededExecutionPlanForNextRun() != null;
705
- this.#useSeededExecutionPlanOnNextRun = false;
706
709
  try {
710
+ this.#profileRuntimeSync('initializeGraphRun', () => this.#initializeGraphRun(context, inputs, contextValues));
711
+ await this.#profileRuntimeAsync('loadProjectReferences', () => this.#loadProjectReferences());
712
+ this.#profileRuntimeSync('prepareNodeProcessContextBase', () => this.#prepareNodeProcessContextBase());
713
+ const shouldUseSeededExecutionPlan = this.#seededExecutionPlanForNextRun() != null;
714
+ this.#useSeededExecutionPlanOnNextRun = false;
707
715
  if (!shouldUseSeededExecutionPlan) {
708
716
  this.#preprocessGraph();
709
717
  }
@@ -712,13 +720,7 @@ export class GraphProcessor {
712
720
  }
713
721
  catch (error) {
714
722
  const normalizedError = getError(error);
715
- // Preflight validation happens before graphStart/nodeStart. Emit the
716
- // ordinary root error event so every executor can present an
717
- // actionable configuration failure instead of only rejecting the
718
- // processGraph promise.
719
- if (!this.#isSubProcessor && !this.#suppressGraphLifecycleEvents) {
720
- await this.#emitter.emit('error', { error: normalizedError });
721
- }
723
+ await this.#emitRootStartupError(normalizedError);
722
724
  throw normalizedError;
723
725
  }
724
726
  await this.#profileRuntimeAsync('emitGraphStart', () => this.#emitGraphStart());
@@ -781,10 +783,19 @@ export class GraphProcessor {
781
783
  await this.#emitter.emit('finish', undefined);
782
784
  }
783
785
  #initializeGraphRun(context, inputs, contextValues) {
786
+ this.#initializeExecutionIdentity();
784
787
  this.#initProcessState();
785
788
  this.#context = context;
786
789
  this.#graphInputs = inputs;
787
790
  this.#contextValues = contextValues;
791
+ this.#cleanupTokenizerErrorListener();
792
+ const unsubscribeTokenizerError = this.#context.tokenizer.on('error', (error) => {
793
+ emitDetached(this.#emitter, 'error', { error });
794
+ });
795
+ this.#unsubscribeTokenizerError =
796
+ typeof unsubscribeTokenizerError === 'function' ? unsubscribeTokenizerError : undefined;
797
+ }
798
+ #initializeExecutionIdentity() {
788
799
  if (this.#executionIdentityOverride) {
789
800
  this.#rootRunId = this.#executionIdentityOverride.rootRunId;
790
801
  this.#graphRunId = this.#executionIdentityOverride.graphRunId;
@@ -795,14 +806,24 @@ export class GraphProcessor {
795
806
  this.#graphRunId = nanoid();
796
807
  this.#parentGraphRunId = this.#parent ? this.#parent.#graphRunId : undefined;
797
808
  }
798
- this.#cleanupTokenizerErrorListener();
799
- const unsubscribeTokenizerError = this.#context.tokenizer.on('error', (error) => {
800
- emitDetached(this.#emitter, 'error', { error });
801
- });
802
- this.#unsubscribeTokenizerError =
803
- typeof unsubscribeTokenizerError === 'function' ? unsubscribeTokenizerError : undefined;
809
+ }
810
+ async #emitRootStartupError(error) {
811
+ // Startup can fail before graphStart/nodeStart: initialization, reference
812
+ // loading, process-context construction, or graph preflight. Emit the
813
+ // same scoped graph terminal plus unscoped root confirmation as ordinary
814
+ // runtime failures so observers can establish a truthful root lifecycle.
815
+ if (this.#isSubProcessor || this.#suppressGraphLifecycleEvents) {
816
+ return;
817
+ }
818
+ await this.#emitter.emit('graphError', this.#withExecution({ graph: this.#graph, error }));
819
+ await this.#emitter.emit('error', { error });
804
820
  }
805
821
  #prepareNodeProcessContextBase() {
822
+ // Subgraphs receive their caller's InternalProcessContext, whose observer
823
+ // is already a GraphProcessor wrapper. Always resolve the original host
824
+ // observer from the root run so nested LLM calls are not emitted once by
825
+ // every ancestor before their own event is bridged to the root emitter.
826
+ const hostChatV2Observer = this.getRootProcessor().#context.onChatV2CallFinished;
806
827
  this.#nodeProcessContextBase = {
807
828
  ...this.#context,
808
829
  abortGraph: (error) => {
@@ -820,6 +841,26 @@ export class GraphProcessor {
820
841
  graphInputNodeValues: this.#graphInputNodeValues,
821
842
  graphInputs: this.#graphInputs,
822
843
  graphOutputs: this.#graphOutputs,
844
+ onChatV2CallFinished: (event) => {
845
+ try {
846
+ const observerResult = hostChatV2Observer?.(event);
847
+ if (observerResult != null && typeof observerResult.then === 'function') {
848
+ void Promise.resolve(observerResult).catch(() => undefined);
849
+ }
850
+ }
851
+ catch {
852
+ // Host observers must never change graph execution.
853
+ }
854
+ // Runtime traces carry only the normalized, provider-neutral usage
855
+ // contract. The host observer above retains its existing raw accounting
856
+ // callback, but provider-shaped usage never enters recordings or remote
857
+ // trace transport.
858
+ const { rawUsage: _rawUsage, ...traceEvent } = event;
859
+ emitDetached(this.#emitter, 'llmCallFinished', this.#withExecution(traceEvent));
860
+ },
861
+ onToolCallFinished: (event) => {
862
+ emitDetached(this.#emitter, 'toolCallFinished', this.#withExecution(event));
863
+ },
823
864
  project: this.#project,
824
865
  raiseEvent: (event, data) => {
825
866
  this.getRootProcessor().raiseEvent(event, data);
@@ -880,11 +921,13 @@ export class GraphProcessor {
880
921
  node,
881
922
  inputs: {},
882
923
  processId: 'preload',
924
+ resultOrigin: 'preloaded',
883
925
  }));
884
926
  await this.#emitter.emit('nodeFinish', this.#withExecution({
885
927
  node,
886
928
  outputs: this.#nodeResults.get(node.id),
887
929
  processId: 'preload',
930
+ resultOrigin: 'preloaded',
888
931
  }));
889
932
  }
890
933
  }
@@ -1559,7 +1602,7 @@ export class GraphProcessor {
1559
1602
  }
1560
1603
  const frozenOutputs = this.#resolveFrozenNodeOutputs(node, inputValues, processId);
1561
1604
  if (frozenOutputs && node.type === 'startBackgroundBranch') {
1562
- await this.#nodeErrored(node, new Error('Start Async Branch cannot use frozen outputs because replaying it could repeat async side effects.'), processId);
1605
+ await this.#nodeErrored(node, new Error('Start Async Branch cannot use frozen outputs because replaying it could repeat async side effects.'), processId, undefined, undefined, 'frozen');
1563
1606
  }
1564
1607
  else if (frozenOutputs) {
1565
1608
  await this.#processFrozenNode(node, processId, inputValues, frozenOutputs);
@@ -1576,14 +1619,15 @@ export class GraphProcessor {
1576
1619
  async #processSplitRunNode(node, processId) {
1577
1620
  return processSplitRunNode(node, processId, {
1578
1621
  getInputValues: (n) => this.#getInputValuesForNode(n),
1622
+ getInputConnections: (n) => this.#getInputConnectionsForNode(n),
1579
1623
  getInputDefinitions: (n) => this.#definitions[n.id]?.inputs ?? [],
1580
1624
  isExcludedDueToControlFlow: (n, inputs, pid) => this.#excludedDueToControlFlow(n, inputs, pid) !== false,
1581
- processNodeWithInputData: (n, inputs, idx, pid, partial) => this.#processNodeWithInputData(n, inputs, idx, pid, partial),
1625
+ processNodeWithInputData: (n, inputs, idx, pid, partial, markResultAsEditorCacheHit) => this.#processNodeWithInputData(n, inputs, idx, pid, partial, markResultAsEditorCacheHit),
1582
1626
  splitRunConcurrency: this.#concurrency.splitRunConcurrency,
1583
1627
  accumulateCost: (output) => this.#accumulateCost(output),
1584
1628
  setNodeResults: (nodeId, outputs) => this.#nodeResults.set(nodeId, outputs),
1585
1629
  markNodeVisited: (nodeId) => this.#visitedNodes.add(nodeId),
1586
- nodeErrored: (n, err, pid, durationMs, splitRunDurationMs) => this.#nodeErrored(n, err, pid, durationMs, splitRunDurationMs),
1630
+ nodeErrored: (n, err, pid, durationMs, splitRunDurationMs, resultOrigin) => this.#nodeErrored(n, err, pid, durationMs, splitRunDurationMs, resultOrigin),
1587
1631
  isAborted: () => this.#lifecycle.isAborted,
1588
1632
  getAbortError: () => createGraphAbortErrorFromSignal(this.#abortController.signal),
1589
1633
  emit: (event, data) => {
@@ -1607,7 +1651,13 @@ export class GraphProcessor {
1607
1651
  });
1608
1652
  }
1609
1653
  async #processFrozenNode(node, processId, inputValues, outputValues) {
1610
- await this.#emitter.emit('nodeStart', this.#withExecution({ node, inputs: inputValues, processId }));
1654
+ await this.#emitter.emit('nodeStart', this.#withExecution({
1655
+ node,
1656
+ inputs: inputValues,
1657
+ inputConnections: this.#getInputConnectionsForNode(node),
1658
+ processId,
1659
+ resultOrigin: 'frozen',
1660
+ }));
1611
1661
  const timingStart = this.#startNodeTiming();
1612
1662
  this.#nodeResults.set(node.id, outputValues);
1613
1663
  this.#visitedNodes.add(node.id);
@@ -1617,6 +1667,7 @@ export class GraphProcessor {
1617
1667
  node,
1618
1668
  outputs: outputValues,
1619
1669
  processId,
1670
+ resultOrigin: 'frozen',
1620
1671
  }, this.#finishNodeTiming(timingStart))));
1621
1672
  }
1622
1673
  async #applyFrozenNodeDataflowEffects(node, outputValues, processId) {
@@ -1634,10 +1685,19 @@ export class GraphProcessor {
1634
1685
  async #processNormalNode(node, processId, inputValues) {
1635
1686
  // Use awaited emit (not emitDetached) so that listeners can yield to the
1636
1687
  // macrotask queue, giving the browser a chance to repaint during execution.
1637
- await this.#emitter.emit('nodeStart', this.#withExecution({ node, inputs: inputValues, processId }));
1688
+ await this.#emitter.emit('nodeStart', this.#withExecution({
1689
+ node,
1690
+ inputs: inputValues,
1691
+ inputConnections: this.#getInputConnectionsForNode(node),
1692
+ processId,
1693
+ resultOrigin: 'executed',
1694
+ }));
1638
1695
  const timingStart = this.#startNodeTiming();
1696
+ let resultOrigin = 'executed';
1639
1697
  try {
1640
- const outputValues = await this.#processNodeWithInputData(node, inputValues, 0, processId, (node, partialOutputs, index) => this.#emitNodePartialOutput(node, partialOutputs, index, processId));
1698
+ const outputValues = await this.#processNodeWithInputData(node, inputValues, 0, processId, (node, partialOutputs, index) => this.#emitNodePartialOutput(node, partialOutputs, index, processId), () => {
1699
+ resultOrigin = 'editor-cache';
1700
+ });
1641
1701
  this.#nodeResults.set(node.id, outputValues);
1642
1702
  this.#visitedNodes.add(node.id);
1643
1703
  this.#accumulateCost(outputValues);
@@ -1645,26 +1705,27 @@ export class GraphProcessor {
1645
1705
  node,
1646
1706
  outputs: outputValues,
1647
1707
  processId,
1708
+ resultOrigin,
1648
1709
  }, this.#finishNodeTiming(timingStart))));
1649
1710
  }
1650
1711
  catch (error) {
1651
- await this.#nodeErrored(node, error, processId, this.#finishNodeTiming(timingStart));
1712
+ await this.#nodeErrored(node, error, processId, this.#finishNodeTiming(timingStart), undefined, resultOrigin);
1652
1713
  }
1653
1714
  }
1654
- async #nodeErrored(node, e, processId, durationMs, splitRunDurationMs) {
1715
+ async #nodeErrored(node, e, processId, durationMs, splitRunDurationMs, resultOrigin = 'executed') {
1655
1716
  const error = getError(e);
1656
1717
  const exclusionReason = this.#getErrorExclusionReason(node, error, processId);
1657
1718
  if (exclusionReason) {
1658
- await this.#emitNodeExcluded(node, processId, this.#getInputValuesForNode(node), exclusionReason);
1719
+ await this.#emitNodeExcluded(node, processId, this.#getInputValuesForNode(node), exclusionReason, resultOrigin);
1659
1720
  this.#emitTraceEvent(`Node ${node.title} (${node.id}-${processId}) was excluded: ${exclusionReason}`);
1660
1721
  return;
1661
1722
  }
1662
1723
  this.#erroredNodes.set(node.id, error);
1663
- await this.#emitter.emit('nodeError', this.#withExecution(withOptionalDuration({ node, error, processId }, durationMs, splitRunDurationMs)));
1724
+ await this.#emitter.emit('nodeError', this.#withExecution(withOptionalDuration({ node, error, processId, resultOrigin }, durationMs, splitRunDurationMs)));
1664
1725
  this.#emitTraceEvent(`Node ${node.title} (${node.id}-${processId}) errored: ${error.stack}`);
1665
1726
  }
1666
1727
  #emitNodePartialOutput(node, outputs, index, processId) {
1667
- emitDetached(this.#emitter, 'partialOutput', this.#withExecution({ node, outputs, index, processId }));
1728
+ emitDetached(this.#emitter, 'partialOutput', this.#withExecution({ node, outputs, index, processId, resultOrigin: 'executed' }));
1668
1729
  }
1669
1730
  #getErrorExclusionReason(node, error, processId) {
1670
1731
  if (this.#getAttachedDataTo(node).races?.completed) {
@@ -1767,7 +1828,7 @@ export class GraphProcessor {
1767
1828
  this.#abortNodeControllersForNode(nodeId, undefined, reason);
1768
1829
  }
1769
1830
  }
1770
- async #processNodeWithInputData(node, inputValues, index, processId, partialOutput) {
1831
+ async #processNodeWithInputData(node, inputValues, index, processId, partialOutput, markResultAsEditorCacheHit) {
1771
1832
  const instance = this.#nodeInstances[node.id];
1772
1833
  const nodeAbortController = this.#newAbortController();
1773
1834
  this.#registerNodeAbortController(node.id, nodeAbortController);
@@ -1779,7 +1840,7 @@ export class GraphProcessor {
1779
1840
  const createContextProfileStart = this.#startRuntimeProfile();
1780
1841
  let context;
1781
1842
  try {
1782
- context = this.#createNodeProcessContext(node, inputValues, index, processId, nodeAbortController, partialOutput);
1843
+ context = this.#createNodeProcessContext(node, inputValues, index, processId, nodeAbortController, partialOutput, undefined, markResultAsEditorCacheHit);
1783
1844
  }
1784
1845
  finally {
1785
1846
  this.#finishRuntimeProfile('createNodeProcessContext', createContextProfileStart);
@@ -1817,7 +1878,7 @@ export class GraphProcessor {
1817
1878
  #getTokenizer() {
1818
1879
  return this.#context.tokenizer;
1819
1880
  }
1820
- #createNodeProcessContext(node, inputValues, index, processId, nodeAbortController, partialOutput) {
1881
+ #createNodeProcessContext(node, inputValues, index, processId, nodeAbortController, partialOutput, toolCallTraceSource, markResultAsEditorCacheHit) {
1821
1882
  const plugin = this.#registry.getPluginFor(node.type);
1822
1883
  const toolCallContinuation = this.#getToolCallContinuationContext(node, nodeAbortController.signal, processId, index);
1823
1884
  return buildNodeProcessContext({
@@ -1829,6 +1890,7 @@ export class GraphProcessor {
1829
1890
  externalFunctions: this.#externalFunctions,
1830
1891
  getPluginConfig: (name) => getPluginConfig(plugin, this.#context.settings, name),
1831
1892
  isDirectRunTarget: this.runToNodeIds?.includes(node.id) ?? false,
1893
+ markResultAsEditorCacheHit,
1832
1894
  node,
1833
1895
  nodeAbortController,
1834
1896
  onPartialOutputs: (partialOutputs) => {
@@ -1848,6 +1910,7 @@ export class GraphProcessor {
1848
1910
  emitDetached(this.#emitter, 'globalSet', this.#withExecution({ id, value, processId }));
1849
1911
  },
1850
1912
  toolCallContinuation,
1913
+ toolCallTraceSource,
1851
1914
  waitEvent: async (event) => {
1852
1915
  return new Promise((resolve, reject) => {
1853
1916
  const abortListener = () => {
@@ -1881,51 +1944,46 @@ export class GraphProcessor {
1881
1944
  throw new Error(`LLM Chat "${node.title}" has ${resolution.candidates.length} connected Delegate Tool Call nodes. Auto-continue requires exactly one Delegate Tool Call connection.`);
1882
1945
  }
1883
1946
  const delegateNode = resolution.delegateNode;
1884
- const invocationKey = this.#getToolCallContinuationInvocationKey(processId, index);
1885
- const invocation = {
1947
+ return this.#connectedToolContinuationHost.begin({
1948
+ key: this.#getToolCallContinuationInvocationKey(processId, index),
1886
1949
  delegateNode,
1887
- latestOutputs: new Map(),
1888
1950
  llmNodeId: node.id,
1889
- released: false,
1890
- };
1891
- this.#toolCallContinuationInvocations.set(invocationKey, invocation);
1892
- return {
1893
- run: (toolCalls, assistantMessage) => this.#runToolCallContinuationRound(node, invocation, toolCalls, assistantMessage, llmSignal),
1894
- release: () => {
1895
- invocation.released = true;
1896
- },
1897
- };
1951
+ llmProcessId: processId,
1952
+ run: (invocation, toolCalls, assistantMessage) => this.#runToolCallContinuationRound(node, invocation, toolCalls, assistantMessage, llmSignal),
1953
+ });
1898
1954
  }
1899
1955
  #getToolCallContinuationInvocationKey(processId, index) {
1900
1956
  return `${processId}:${index}`;
1901
1957
  }
1902
1958
  #finalizeToolCallContinuation(processId, index, nodeOutputs) {
1903
- const invocationKey = this.#getToolCallContinuationInvocationKey(processId, index);
1904
- const invocation = this.#toolCallContinuationInvocations.get(invocationKey);
1905
- this.#toolCallContinuationInvocations.delete(invocationKey);
1906
- if (!invocation || invocation.released) {
1907
- return;
1908
- }
1909
- if (invocation.latestOutputs.size === 0) {
1910
- const replayedCalls = nodeOutputs['function-calls'];
1911
- if (replayedCalls?.type === 'object[]' &&
1912
- replayedCalls.value.length > 0 &&
1913
- replayedCalls.value.every(isDelegatedToolCallRecord)) {
1914
- invocation.latestOutputs.set(invocation.delegateNode.id, buildDelegatedToolCallOutputs(replayedCalls.value));
1915
- }
1916
- }
1917
- for (const [nodeId, outputs] of invocation.latestOutputs) {
1918
- this.#nodeResults.set(nodeId, outputs);
1919
- this.#visitedNodes.add(nodeId);
1920
- this.#remainingNodes.delete(nodeId);
1921
- this.#continuationCompletionOwnerByNodeId.set(nodeId, invocation.llmNodeId);
1922
- }
1959
+ this.#connectedToolContinuationHost.finalize({
1960
+ key: this.#getToolCallContinuationInvocationKey(processId, index),
1961
+ nodeOutputs,
1962
+ replay: (invocation, outputs) => {
1963
+ if (invocation.latestOutputs.size !== 0)
1964
+ return;
1965
+ const replayedCalls = outputs['function-calls'];
1966
+ if (replayedCalls?.type === 'object[]' &&
1967
+ replayedCalls.value.length > 0 &&
1968
+ replayedCalls.value.every(isDelegatedToolCallRecord)) {
1969
+ invocation.latestOutputs.set(invocation.delegateNode.id, buildDelegatedToolCallOutputs(replayedCalls.value));
1970
+ }
1971
+ },
1972
+ commit: (invocation) => {
1973
+ for (const [nodeId, outputs] of invocation.latestOutputs) {
1974
+ this.#nodeResults.set(nodeId, outputs);
1975
+ this.#visitedNodes.add(nodeId);
1976
+ this.#remainingNodes.delete(nodeId);
1977
+ this.#continuationCompletionOwnerByNodeId.set(nodeId, invocation.llmNodeId);
1978
+ }
1979
+ },
1980
+ });
1923
1981
  }
1924
1982
  #discardToolCallContinuation(processId, index) {
1925
- this.#toolCallContinuationInvocations.delete(this.#getToolCallContinuationInvocationKey(processId, index));
1983
+ this.#connectedToolContinuationHost.discard(this.#getToolCallContinuationInvocationKey(processId, index));
1926
1984
  }
1927
1985
  async #runToolCallContinuationRound(llmNode, invocation, toolCalls, assistantMessage, llmSignal) {
1928
- const round = await new ToolCallContinuationCoordinator(this.#createToolCallContinuationCoordinatorAdapter()).run({
1986
+ const round = await new ToolCallContinuationCoordinator(this.#createToolCallContinuationCoordinatorAdapter(llmNode.id, invocation.llmProcessId)).run({
1929
1987
  assistantMessage,
1930
1988
  delegateNode: invocation.delegateNode,
1931
1989
  llmNode,
@@ -1943,7 +2001,7 @@ export class GraphProcessor {
1943
2001
  }
1944
2002
  return [...round.results];
1945
2003
  }
1946
- #createToolCallContinuationCoordinatorAdapter() {
2004
+ #createToolCallContinuationCoordinatorAdapter(sourceNodeId, sourceProcessId) {
1947
2005
  return {
1948
2006
  accumulateCost: (outputs) => this.#accumulateCost(outputs),
1949
2007
  createBranchAdapter: () => {
@@ -1956,7 +2014,7 @@ export class GraphProcessor {
1956
2014
  },
1957
2015
  };
1958
2016
  },
1959
- createDelegateProcessContext: (node, inputs, processId, nodeAbortController) => this.#createNodeProcessContext(node, inputs, 0, processId, nodeAbortController, (partialNode, partialOutputs, index) => this.#emitNodePartialOutput(partialNode, partialOutputs, index, processId)),
2017
+ createDelegateProcessContext: (node, inputs, processId, nodeAbortController) => this.#createNodeProcessContext(node, inputs, 0, processId, nodeAbortController, (partialNode, partialOutputs, index) => this.#emitNodePartialOutput(partialNode, partialOutputs, index, processId), { nodeId: sourceNodeId, processId: sourceProcessId }),
1960
2018
  createNodeAbortController: () => this.#newAbortController(),
1961
2019
  emitDelegateError: (node, error, processId, timingStart) => this.#nodeErrored(node, error, processId, this.#finishNodeTiming(timingStart)),
1962
2020
  emitDelegateFinish: async (node, outputs, processId, timingStart) => {
@@ -1964,10 +2022,17 @@ export class GraphProcessor {
1964
2022
  node,
1965
2023
  outputs,
1966
2024
  processId,
2025
+ resultOrigin: 'executed',
1967
2026
  }, this.#finishNodeTiming(timingStart))));
1968
2027
  },
1969
2028
  emitDelegatePartialOutput: (node, outputs, processId) => this.#emitNodePartialOutput(node, outputs, 0, processId),
1970
- emitDelegateStart: (node, inputs, processId) => this.#emitter.emit('nodeStart', this.#withExecution({ node, inputs, processId })),
2029
+ emitDelegateStart: (node, inputs, processId) => this.#emitter.emit('nodeStart', this.#withExecution({
2030
+ node,
2031
+ inputs,
2032
+ inputConnections: this.#getInputConnectionsForNode(node),
2033
+ processId,
2034
+ resultOrigin: 'executed',
2035
+ })),
1971
2036
  getActiveOutputPortIds: (node) => this.#getActiveOutputPortIds(node),
1972
2037
  getContinuationBranchBoundaryNodeIds: (llmNode) => new Set([llmNode.id, ...this.#currentlyProcessing]),
1973
2038
  hasPreloadedOrFrozenDelegateOutput: (node, inputs, processId) => this.#nodeResults.has(node.id) || this.#resolveFrozenNodeOutputs(node, inputs, processId) != null,
@@ -2375,6 +2440,7 @@ export class GraphProcessor {
2375
2440
  node: executorNode,
2376
2441
  outputs: partialOutputs,
2377
2442
  processId: this.#executor.processId,
2443
+ resultOrigin: 'executed',
2378
2444
  execution: parentExecution,
2379
2445
  });
2380
2446
  }
@@ -2511,10 +2577,10 @@ export class GraphProcessor {
2511
2577
  #markAsExcluded(node, processId, inputValues, reason) {
2512
2578
  emitDetached(this.#emitter, 'nodeExcluded', this.#createNodeExcludedEvent(node, processId, inputValues, reason));
2513
2579
  }
2514
- async #emitNodeExcluded(node, processId, inputValues, reason) {
2515
- await this.#emitter.emit('nodeExcluded', this.#createNodeExcludedEvent(node, processId, inputValues, reason));
2580
+ async #emitNodeExcluded(node, processId, inputValues, reason, resultOrigin = 'executed') {
2581
+ await this.#emitter.emit('nodeExcluded', this.#createNodeExcludedEvent(node, processId, inputValues, reason, resultOrigin));
2516
2582
  }
2517
- #createNodeExcludedEvent(node, processId, inputValues, reason) {
2583
+ #createNodeExcludedEvent(node, processId, inputValues, reason, resultOrigin = 'executed') {
2518
2584
  const outputs = createExcludedNodeOutputs(node, this.#definitions[node.id].outputs);
2519
2585
  this.#nodeResults.set(node.id, outputs);
2520
2586
  return this.#withExecution({
@@ -2523,6 +2589,7 @@ export class GraphProcessor {
2523
2589
  inputs: inputValues,
2524
2590
  outputs,
2525
2591
  reason,
2592
+ resultOrigin,
2526
2593
  });
2527
2594
  }
2528
2595
  #getInputValuesForNode(node) {
@@ -2539,6 +2606,16 @@ export class GraphProcessor {
2539
2606
  return values;
2540
2607
  }, {});
2541
2608
  }
2609
+ #getInputConnectionsForNode(node) {
2610
+ return this.#getEffectiveConnections()
2611
+ .filter((connection) => connection.inputNodeId === node.id)
2612
+ .map(({ outputNodeId, outputId, inputNodeId, inputId }) => ({
2613
+ outputNodeId,
2614
+ outputId,
2615
+ inputNodeId,
2616
+ inputId,
2617
+ }));
2618
+ }
2542
2619
  get #executionState() {
2543
2620
  return {
2544
2621
  connections: this.#connections,
@@ -34,6 +34,9 @@ export class NodeImpl {
34
34
  getBody(_context) {
35
35
  return undefined;
36
36
  }
37
+ getRunActivityDescriptor() {
38
+ return undefined;
39
+ }
37
40
  }
38
41
  export class PluginNodeImplClass extends NodeImpl {
39
42
  impl;
@@ -56,4 +59,7 @@ export class PluginNodeImplClass extends NodeImpl {
56
59
  getBody(context) {
57
60
  return this.impl.getBody(this.data, context);
58
61
  }
62
+ getRunActivityDescriptor() {
63
+ return this.impl.getRunActivityDescriptor?.(this.data);
64
+ }
59
65
  }
@@ -1,11 +1,12 @@
1
1
  export function buildNodeProcessContext(options) {
2
- const { attachedData, activeOutputPortIds, base, createSubProcessor, execution, externalFunctions, getPluginConfig, isDirectRunTarget, node, nodeAbortController, onPartialOutputs, processId, requestUserInput, reportProgress, setGlobal, toolCallContinuation, waitEvent, } = options;
2
+ const { attachedData, activeOutputPortIds, base, createSubProcessor, execution, externalFunctions, getPluginConfig, isDirectRunTarget, markResultAsEditorCacheHit, node, nodeAbortController, onPartialOutputs, processId, requestUserInput, reportProgress, setGlobal, toolCallContinuation, toolCallTraceSource, waitEvent, } = options;
3
3
  return {
4
4
  ...base,
5
5
  node,
6
6
  attachedData,
7
7
  activeOutputPortIds,
8
8
  isDirectRunTarget,
9
+ markResultAsEditorCacheHit,
9
10
  waitEvent,
10
11
  externalFunctions: { ...externalFunctions },
11
12
  onPartialOutputs,
@@ -17,6 +18,7 @@ export function buildNodeProcessContext(options) {
17
18
  requestUserInput,
18
19
  reportProgress,
19
20
  toolCallContinuation,
21
+ toolCallTraceSource,
20
22
  execution,
21
23
  };
22
24
  }