@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
@@ -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,13 +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),
1623
+ getInputDefinitions: (n) => this.#definitions[n.id]?.inputs ?? [],
1579
1624
  isExcludedDueToControlFlow: (n, inputs, pid) => this.#excludedDueToControlFlow(n, inputs, pid) !== false,
1580
- 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),
1581
1626
  splitRunConcurrency: this.#concurrency.splitRunConcurrency,
1582
1627
  accumulateCost: (output) => this.#accumulateCost(output),
1583
1628
  setNodeResults: (nodeId, outputs) => this.#nodeResults.set(nodeId, outputs),
1584
1629
  markNodeVisited: (nodeId) => this.#visitedNodes.add(nodeId),
1585
- 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),
1586
1631
  isAborted: () => this.#lifecycle.isAborted,
1587
1632
  getAbortError: () => createGraphAbortErrorFromSignal(this.#abortController.signal),
1588
1633
  emit: (event, data) => {
@@ -1606,7 +1651,13 @@ export class GraphProcessor {
1606
1651
  });
1607
1652
  }
1608
1653
  async #processFrozenNode(node, processId, inputValues, outputValues) {
1609
- 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
+ }));
1610
1661
  const timingStart = this.#startNodeTiming();
1611
1662
  this.#nodeResults.set(node.id, outputValues);
1612
1663
  this.#visitedNodes.add(node.id);
@@ -1616,6 +1667,7 @@ export class GraphProcessor {
1616
1667
  node,
1617
1668
  outputs: outputValues,
1618
1669
  processId,
1670
+ resultOrigin: 'frozen',
1619
1671
  }, this.#finishNodeTiming(timingStart))));
1620
1672
  }
1621
1673
  async #applyFrozenNodeDataflowEffects(node, outputValues, processId) {
@@ -1633,10 +1685,19 @@ export class GraphProcessor {
1633
1685
  async #processNormalNode(node, processId, inputValues) {
1634
1686
  // Use awaited emit (not emitDetached) so that listeners can yield to the
1635
1687
  // macrotask queue, giving the browser a chance to repaint during execution.
1636
- 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
+ }));
1637
1695
  const timingStart = this.#startNodeTiming();
1696
+ let resultOrigin = 'executed';
1638
1697
  try {
1639
- 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
+ });
1640
1701
  this.#nodeResults.set(node.id, outputValues);
1641
1702
  this.#visitedNodes.add(node.id);
1642
1703
  this.#accumulateCost(outputValues);
@@ -1644,26 +1705,27 @@ export class GraphProcessor {
1644
1705
  node,
1645
1706
  outputs: outputValues,
1646
1707
  processId,
1708
+ resultOrigin,
1647
1709
  }, this.#finishNodeTiming(timingStart))));
1648
1710
  }
1649
1711
  catch (error) {
1650
- await this.#nodeErrored(node, error, processId, this.#finishNodeTiming(timingStart));
1712
+ await this.#nodeErrored(node, error, processId, this.#finishNodeTiming(timingStart), undefined, resultOrigin);
1651
1713
  }
1652
1714
  }
1653
- async #nodeErrored(node, e, processId, durationMs, splitRunDurationMs) {
1715
+ async #nodeErrored(node, e, processId, durationMs, splitRunDurationMs, resultOrigin = 'executed') {
1654
1716
  const error = getError(e);
1655
1717
  const exclusionReason = this.#getErrorExclusionReason(node, error, processId);
1656
1718
  if (exclusionReason) {
1657
- await this.#emitNodeExcluded(node, processId, this.#getInputValuesForNode(node), exclusionReason);
1719
+ await this.#emitNodeExcluded(node, processId, this.#getInputValuesForNode(node), exclusionReason, resultOrigin);
1658
1720
  this.#emitTraceEvent(`Node ${node.title} (${node.id}-${processId}) was excluded: ${exclusionReason}`);
1659
1721
  return;
1660
1722
  }
1661
1723
  this.#erroredNodes.set(node.id, error);
1662
- 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)));
1663
1725
  this.#emitTraceEvent(`Node ${node.title} (${node.id}-${processId}) errored: ${error.stack}`);
1664
1726
  }
1665
1727
  #emitNodePartialOutput(node, outputs, index, processId) {
1666
- emitDetached(this.#emitter, 'partialOutput', this.#withExecution({ node, outputs, index, processId }));
1728
+ emitDetached(this.#emitter, 'partialOutput', this.#withExecution({ node, outputs, index, processId, resultOrigin: 'executed' }));
1667
1729
  }
1668
1730
  #getErrorExclusionReason(node, error, processId) {
1669
1731
  if (this.#getAttachedDataTo(node).races?.completed) {
@@ -1766,7 +1828,7 @@ export class GraphProcessor {
1766
1828
  this.#abortNodeControllersForNode(nodeId, undefined, reason);
1767
1829
  }
1768
1830
  }
1769
- async #processNodeWithInputData(node, inputValues, index, processId, partialOutput) {
1831
+ async #processNodeWithInputData(node, inputValues, index, processId, partialOutput, markResultAsEditorCacheHit) {
1770
1832
  const instance = this.#nodeInstances[node.id];
1771
1833
  const nodeAbortController = this.#newAbortController();
1772
1834
  this.#registerNodeAbortController(node.id, nodeAbortController);
@@ -1778,7 +1840,7 @@ export class GraphProcessor {
1778
1840
  const createContextProfileStart = this.#startRuntimeProfile();
1779
1841
  let context;
1780
1842
  try {
1781
- context = this.#createNodeProcessContext(node, inputValues, index, processId, nodeAbortController, partialOutput);
1843
+ context = this.#createNodeProcessContext(node, inputValues, index, processId, nodeAbortController, partialOutput, undefined, markResultAsEditorCacheHit);
1782
1844
  }
1783
1845
  finally {
1784
1846
  this.#finishRuntimeProfile('createNodeProcessContext', createContextProfileStart);
@@ -1816,7 +1878,7 @@ export class GraphProcessor {
1816
1878
  #getTokenizer() {
1817
1879
  return this.#context.tokenizer;
1818
1880
  }
1819
- #createNodeProcessContext(node, inputValues, index, processId, nodeAbortController, partialOutput) {
1881
+ #createNodeProcessContext(node, inputValues, index, processId, nodeAbortController, partialOutput, toolCallTraceSource, markResultAsEditorCacheHit) {
1820
1882
  const plugin = this.#registry.getPluginFor(node.type);
1821
1883
  const toolCallContinuation = this.#getToolCallContinuationContext(node, nodeAbortController.signal, processId, index);
1822
1884
  return buildNodeProcessContext({
@@ -1828,6 +1890,7 @@ export class GraphProcessor {
1828
1890
  externalFunctions: this.#externalFunctions,
1829
1891
  getPluginConfig: (name) => getPluginConfig(plugin, this.#context.settings, name),
1830
1892
  isDirectRunTarget: this.runToNodeIds?.includes(node.id) ?? false,
1893
+ markResultAsEditorCacheHit,
1831
1894
  node,
1832
1895
  nodeAbortController,
1833
1896
  onPartialOutputs: (partialOutputs) => {
@@ -1847,6 +1910,7 @@ export class GraphProcessor {
1847
1910
  emitDetached(this.#emitter, 'globalSet', this.#withExecution({ id, value, processId }));
1848
1911
  },
1849
1912
  toolCallContinuation,
1913
+ toolCallTraceSource,
1850
1914
  waitEvent: async (event) => {
1851
1915
  return new Promise((resolve, reject) => {
1852
1916
  const abortListener = () => {
@@ -1880,51 +1944,46 @@ export class GraphProcessor {
1880
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.`);
1881
1945
  }
1882
1946
  const delegateNode = resolution.delegateNode;
1883
- const invocationKey = this.#getToolCallContinuationInvocationKey(processId, index);
1884
- const invocation = {
1947
+ return this.#connectedToolContinuationHost.begin({
1948
+ key: this.#getToolCallContinuationInvocationKey(processId, index),
1885
1949
  delegateNode,
1886
- latestOutputs: new Map(),
1887
1950
  llmNodeId: node.id,
1888
- released: false,
1889
- };
1890
- this.#toolCallContinuationInvocations.set(invocationKey, invocation);
1891
- return {
1892
- run: (toolCalls, assistantMessage) => this.#runToolCallContinuationRound(node, invocation, toolCalls, assistantMessage, llmSignal),
1893
- release: () => {
1894
- invocation.released = true;
1895
- },
1896
- };
1951
+ llmProcessId: processId,
1952
+ run: (invocation, toolCalls, assistantMessage) => this.#runToolCallContinuationRound(node, invocation, toolCalls, assistantMessage, llmSignal),
1953
+ });
1897
1954
  }
1898
1955
  #getToolCallContinuationInvocationKey(processId, index) {
1899
1956
  return `${processId}:${index}`;
1900
1957
  }
1901
1958
  #finalizeToolCallContinuation(processId, index, nodeOutputs) {
1902
- const invocationKey = this.#getToolCallContinuationInvocationKey(processId, index);
1903
- const invocation = this.#toolCallContinuationInvocations.get(invocationKey);
1904
- this.#toolCallContinuationInvocations.delete(invocationKey);
1905
- if (!invocation || invocation.released) {
1906
- return;
1907
- }
1908
- if (invocation.latestOutputs.size === 0) {
1909
- const replayedCalls = nodeOutputs['function-calls'];
1910
- if (replayedCalls?.type === 'object[]' &&
1911
- replayedCalls.value.length > 0 &&
1912
- replayedCalls.value.every(isDelegatedToolCallRecord)) {
1913
- invocation.latestOutputs.set(invocation.delegateNode.id, buildDelegatedToolCallOutputs(replayedCalls.value));
1914
- }
1915
- }
1916
- for (const [nodeId, outputs] of invocation.latestOutputs) {
1917
- this.#nodeResults.set(nodeId, outputs);
1918
- this.#visitedNodes.add(nodeId);
1919
- this.#remainingNodes.delete(nodeId);
1920
- this.#continuationCompletionOwnerByNodeId.set(nodeId, invocation.llmNodeId);
1921
- }
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
+ });
1922
1981
  }
1923
1982
  #discardToolCallContinuation(processId, index) {
1924
- this.#toolCallContinuationInvocations.delete(this.#getToolCallContinuationInvocationKey(processId, index));
1983
+ this.#connectedToolContinuationHost.discard(this.#getToolCallContinuationInvocationKey(processId, index));
1925
1984
  }
1926
1985
  async #runToolCallContinuationRound(llmNode, invocation, toolCalls, assistantMessage, llmSignal) {
1927
- const round = await new ToolCallContinuationCoordinator(this.#createToolCallContinuationCoordinatorAdapter()).run({
1986
+ const round = await new ToolCallContinuationCoordinator(this.#createToolCallContinuationCoordinatorAdapter(llmNode.id, invocation.llmProcessId)).run({
1928
1987
  assistantMessage,
1929
1988
  delegateNode: invocation.delegateNode,
1930
1989
  llmNode,
@@ -1942,7 +2001,7 @@ export class GraphProcessor {
1942
2001
  }
1943
2002
  return [...round.results];
1944
2003
  }
1945
- #createToolCallContinuationCoordinatorAdapter() {
2004
+ #createToolCallContinuationCoordinatorAdapter(sourceNodeId, sourceProcessId) {
1946
2005
  return {
1947
2006
  accumulateCost: (outputs) => this.#accumulateCost(outputs),
1948
2007
  createBranchAdapter: () => {
@@ -1955,7 +2014,7 @@ export class GraphProcessor {
1955
2014
  },
1956
2015
  };
1957
2016
  },
1958
- 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 }),
1959
2018
  createNodeAbortController: () => this.#newAbortController(),
1960
2019
  emitDelegateError: (node, error, processId, timingStart) => this.#nodeErrored(node, error, processId, this.#finishNodeTiming(timingStart)),
1961
2020
  emitDelegateFinish: async (node, outputs, processId, timingStart) => {
@@ -1963,10 +2022,17 @@ export class GraphProcessor {
1963
2022
  node,
1964
2023
  outputs,
1965
2024
  processId,
2025
+ resultOrigin: 'executed',
1966
2026
  }, this.#finishNodeTiming(timingStart))));
1967
2027
  },
1968
2028
  emitDelegatePartialOutput: (node, outputs, processId) => this.#emitNodePartialOutput(node, outputs, 0, processId),
1969
- 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
+ })),
1970
2036
  getActiveOutputPortIds: (node) => this.#getActiveOutputPortIds(node),
1971
2037
  getContinuationBranchBoundaryNodeIds: (llmNode) => new Set([llmNode.id, ...this.#currentlyProcessing]),
1972
2038
  hasPreloadedOrFrozenDelegateOutput: (node, inputs, processId) => this.#nodeResults.has(node.id) || this.#resolveFrozenNodeOutputs(node, inputs, processId) != null,
@@ -2374,6 +2440,7 @@ export class GraphProcessor {
2374
2440
  node: executorNode,
2375
2441
  outputs: partialOutputs,
2376
2442
  processId: this.#executor.processId,
2443
+ resultOrigin: 'executed',
2377
2444
  execution: parentExecution,
2378
2445
  });
2379
2446
  }
@@ -2510,10 +2577,10 @@ export class GraphProcessor {
2510
2577
  #markAsExcluded(node, processId, inputValues, reason) {
2511
2578
  emitDetached(this.#emitter, 'nodeExcluded', this.#createNodeExcludedEvent(node, processId, inputValues, reason));
2512
2579
  }
2513
- async #emitNodeExcluded(node, processId, inputValues, reason) {
2514
- 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));
2515
2582
  }
2516
- #createNodeExcludedEvent(node, processId, inputValues, reason) {
2583
+ #createNodeExcludedEvent(node, processId, inputValues, reason, resultOrigin = 'executed') {
2517
2584
  const outputs = createExcludedNodeOutputs(node, this.#definitions[node.id].outputs);
2518
2585
  this.#nodeResults.set(node.id, outputs);
2519
2586
  return this.#withExecution({
@@ -2522,6 +2589,7 @@ export class GraphProcessor {
2522
2589
  inputs: inputValues,
2523
2590
  outputs,
2524
2591
  reason,
2592
+ resultOrigin,
2525
2593
  });
2526
2594
  }
2527
2595
  #getInputValuesForNode(node) {
@@ -2538,6 +2606,16 @@ export class GraphProcessor {
2538
2606
  return values;
2539
2607
  }, {});
2540
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
+ }
2541
2619
  get #executionState() {
2542
2620
  return {
2543
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
  }