@valerypopoff/rivet2-core 2.1.7 → 2.1.9

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 (115) hide show
  1. package/dist/cjs/bundle.cjs +4911 -2546
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/createProcessor.js +45 -4
  4. package/dist/esm/exports.js +2 -0
  5. package/dist/esm/integrations/KnowledgeStoreFieldPolicy.js +216 -0
  6. package/dist/esm/integrations/KnowledgeStoreProvider.js +14 -90
  7. package/dist/esm/integrations/ManagedKnowledgeStore.js +0 -8
  8. package/dist/esm/model/DataBusPorts.js +26 -0
  9. package/dist/esm/model/DataBusTopology.js +207 -0
  10. package/dist/esm/model/DataValue.js +22 -7
  11. package/dist/esm/model/GraphPreprocessor.js +9 -3
  12. package/dist/esm/model/GraphProcessor.js +164 -366
  13. package/dist/esm/model/NodeIO.js +1 -0
  14. package/dist/esm/model/NodePrefabResolver.js +16 -0
  15. package/dist/esm/model/Nodes.js +7 -0
  16. package/dist/esm/model/SplitRunProcessor.js +19 -10
  17. package/dist/esm/model/ToolCallContinuationBranchPlanner.js +165 -0
  18. package/dist/esm/model/ToolCallContinuationCoordinator.js +206 -0
  19. package/dist/esm/model/chat/aiSdkMessages.js +8 -0
  20. package/dist/esm/model/chat-v2/chatV2CallObserver.js +142 -0
  21. package/dist/esm/model/chat-v2/chatV2EditorCache.js +22 -0
  22. package/dist/esm/model/chat-v2/chatV2Errors.js +23 -6
  23. package/dist/esm/model/chat-v2/chatV2Outputs.js +41 -31
  24. package/dist/esm/model/chat-v2/chatV2Pipeline.js +167 -56
  25. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +1 -0
  26. package/dist/esm/model/chat-v2/chatV2ProviderTypes.js +1 -0
  27. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +6 -5
  28. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +2 -2
  29. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -6
  30. package/dist/esm/model/chat-v2/chatV2Types.js +11 -1
  31. package/dist/esm/model/chat-v2/developerMessageRoles.js +45 -0
  32. package/dist/esm/model/chat-v2/index.js +1 -0
  33. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +53 -3
  34. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +53 -19
  35. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +232 -68
  36. package/dist/esm/model/chat-v2/llmProfile.js +212 -0
  37. package/dist/esm/model/chat-v2/llmProfileFallback.js +288 -0
  38. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +73 -0
  39. package/dist/esm/model/chat-v2/llmProfileTypes.js +45 -0
  40. package/dist/esm/model/chat-v2/messageConverter.js +14 -0
  41. package/dist/esm/model/chat-v2/providerOptions.js +44 -11
  42. package/dist/esm/model/chat-v2/toolContinuation.js +0 -4
  43. package/dist/esm/model/nodes/AssembleMessageNode.js +6 -0
  44. package/dist/esm/model/nodes/DataBusNode.js +81 -0
  45. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -0
  46. package/dist/esm/model/nodes/GetGlobalNode.js +7 -11
  47. package/dist/esm/model/nodes/GetKnowledgeSourceStatusNode.js +1 -1
  48. package/dist/esm/model/nodes/LLMChatV2Node.js +156 -18
  49. package/dist/esm/model/nodes/LLMProfileNode.js +132 -0
  50. package/dist/esm/model/nodes/PassthroughNode.js +1 -11
  51. package/dist/esm/model/nodes/PromptNode.js +9 -2
  52. package/dist/esm/model/nodes/SearchKnowledgeNode.js +1 -1
  53. package/dist/esm/model/nodes/SetGlobalNode.js +6 -6
  54. package/dist/esm/model/nodes/SyncKnowledgeSourceNode.js +0 -1
  55. package/dist/esm/model/nodes/toolCallDelegation.js +31 -4
  56. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +22 -28
  57. package/dist/esm/plugins/google/google.js +20 -9
  58. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +17 -6
  59. package/dist/esm/plugins/pinecone/PineconeKnowledgeStore.js +0 -4
  60. package/dist/esm/plugins/pinecone/plugin.js +1 -1
  61. package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +4 -0
  62. package/dist/esm/utils/coerceType.js +84 -41
  63. package/dist/esm/utils/expectType.js +45 -8
  64. package/dist/esm/utils/fetchEventSource.js +18 -0
  65. package/dist/esm/utils/serialization/serialization.js +37 -7
  66. package/dist/esm/vendor/fnv1a.js +6 -3
  67. package/dist/types/api/createProcessor.d.ts +2 -0
  68. package/dist/types/exports.d.ts +2 -0
  69. package/dist/types/integrations/KnowledgeStore.d.ts +0 -2
  70. package/dist/types/integrations/KnowledgeStoreFieldPolicy.d.ts +38 -0
  71. package/dist/types/integrations/KnowledgeStoreProvider.d.ts +6 -3
  72. package/dist/types/model/DataBusPorts.d.ts +6 -0
  73. package/dist/types/model/DataBusTopology.d.ts +16 -0
  74. package/dist/types/model/DataValue.d.ts +22 -6
  75. package/dist/types/model/GraphPreprocessor.d.ts +2 -1
  76. package/dist/types/model/GraphProcessor.d.ts +4 -3
  77. package/dist/types/model/NodeBase.d.ts +6 -0
  78. package/dist/types/model/NodeIO.d.ts +5 -0
  79. package/dist/types/model/NodePrefabResolver.d.ts +9 -0
  80. package/dist/types/model/Nodes.d.ts +5 -2
  81. package/dist/types/model/ProcessContext.d.ts +64 -0
  82. package/dist/types/model/SplitRunProcessor.d.ts +2 -1
  83. package/dist/types/model/ToolCallContinuationBranchPlanner.d.ts +43 -0
  84. package/dist/types/model/ToolCallContinuationCoordinator.d.ts +70 -0
  85. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +10 -0
  86. package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +4 -0
  87. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +5 -5
  88. package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +33 -0
  89. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +1 -0
  90. package/dist/types/model/chat-v2/chatV2ProviderTypes.d.ts +1 -0
  91. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
  92. package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +8 -0
  93. package/dist/types/model/chat-v2/chatV2Shared.d.ts +0 -1
  94. package/dist/types/model/chat-v2/chatV2Types.d.ts +27 -3
  95. package/dist/types/model/chat-v2/developerMessageRoles.d.ts +10 -0
  96. package/dist/types/model/chat-v2/index.d.ts +1 -0
  97. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +10 -1
  98. package/dist/types/model/chat-v2/llmChatV2NodeEditors.d.ts +5 -1
  99. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +18 -2
  100. package/dist/types/model/chat-v2/llmProfile.d.ts +10 -0
  101. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +79 -0
  102. package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +9 -0
  103. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +18 -0
  104. package/dist/types/model/chat-v2/providerOptions.d.ts +1 -0
  105. package/dist/types/model/nodes/AssembleMessageNode.d.ts +2 -1
  106. package/dist/types/model/nodes/DataBusNode.d.ts +19 -0
  107. package/dist/types/model/nodes/LLMProfileNode.d.ts +20 -0
  108. package/dist/types/model/nodes/PassthroughNode.d.ts +2 -15
  109. package/dist/types/model/nodes/PromptNode.d.ts +2 -2
  110. package/dist/types/model/nodes/SetGlobalNode.d.ts +2 -2
  111. package/dist/types/model/nodes/toolCallDelegation.d.ts +9 -0
  112. package/dist/types/plugins/google/google.d.ts +12 -1
  113. package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +2 -1
  114. package/dist/types/vendor/fnv1a.d.ts +5 -5
  115. package/package.json +1 -1
@@ -23,10 +23,14 @@ import { normalizeGraphProgress } from './GraphProgress.js';
23
23
  import { RIVET_WEB_APP_STATUS_FUNCTION_NAME, rivetWebAppStatusExternalFunction } from './UiGraphWebAppStatus.js';
24
24
  import { RivetStoredValueController } from './StoredValueStore.js';
25
25
  import { createExcludedNodeOutputs, getControlFlowExclusionDecision, getMissingRequiredInputExclusion, } from './NodeExclusionPolicy.js';
26
- import { DELEGATE_TOOL_CALL_INPUT_ID, resolveToolContinuationConnection, } from './chat-v2/toolContinuationConnection.js';
27
- import { buildDelegatedToolCallOutputs, delegateToolCall, isDelegatedToolCallRecord, } from './nodes/toolCallDelegation.js';
26
+ import { resolveToolContinuationConnection } from './chat-v2/toolContinuationConnection.js';
27
+ import { buildDelegatedToolCallOutputs, isDelegatedToolCallRecord } from './nodes/toolCallDelegation.js';
28
+ import { ToolCallContinuationCoordinator, } from './ToolCallContinuationCoordinator.js';
29
+ import { createToolCallContinuationBranchPlanner, } from './ToolCallContinuationBranchPlanner.js';
28
30
  import { ManagedAsyncBranches } from './ManagedAsyncBranches.js';
29
31
  import { KnowledgeStoreController } from '../integrations/KnowledgeStoreProvider.js';
32
+ import { isDataBusTopologyNode } from './DataBusTopology.js';
33
+ import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
30
34
  // eslint-disable-next-line import/no-cycle -- There has to be a cycle because CodeRunner needs to import the entirety of Rivet
31
35
  import { IsomorphicCodeRunner } from '../integrations/CodeRunner.js';
32
36
  const graphProcessorGraphOverride = Symbol('graphProcessorGraphOverride');
@@ -212,6 +216,7 @@ export class GraphProcessor {
212
216
  #managedAsyncBranchFailures = [];
213
217
  #runCompletionPromise;
214
218
  #nodesNotInCycle = undefined;
219
+ #executionGraphNodes = undefined;
215
220
  #nodeAbortControllers = new Map();
216
221
  #graphInputNodeValues = {};
217
222
  /** User input nodes that are pending user input. */
@@ -299,10 +304,12 @@ export class GraphProcessor {
299
304
  this.#useSeededExecutionPlanOnNextRun = true;
300
305
  }
301
306
  }
302
- #preprocessGraph() {
307
+ #preprocessGraph(options = {}) {
303
308
  const profileStart = this.#startRuntimeProfile();
304
309
  try {
305
- const runtimeCache = this.#canUseRuntimeExecutionPlanCache() ? this.#runtimeCache : undefined;
310
+ const runtimeCache = options.allowRuntimeExecutionPlanCache === false || !this.#canUseRuntimeExecutionPlanCache()
311
+ ? undefined
312
+ : this.#runtimeCache;
306
313
  const shouldUseRuntimeCache = runtimeCache != null;
307
314
  const cachedPlan = runtimeCache?.executionPlans?.get(this.#graph);
308
315
  if (cachedPlan && runtimeCache?.executionPlanNodePrefabs?.get(this.#graph) === this.#project.nodePrefabs) {
@@ -358,9 +365,7 @@ export class GraphProcessor {
358
365
  }
359
366
  #applyPreprocessedGraph(preprocessedGraph, options = {}) {
360
367
  const nodeInstances = options.recreateNodeInstances || !('nodeInstances' in preprocessedGraph)
361
- ? this.#createNodeInstances(isGraphExecutionPlan(preprocessedGraph)
362
- ? preprocessedGraph.graphNodes
363
- : Object.values(preprocessedGraph.nodesById))
368
+ ? this.#createNodeInstances(preprocessedGraph.graphNodes)
364
369
  : preprocessedGraph.nodeInstances;
365
370
  replaceRecordContents(this.#nodeInstances, nodeInstances);
366
371
  replaceRecordContents(this.#nodesById, preprocessedGraph.nodesById);
@@ -368,6 +373,8 @@ export class GraphProcessor {
368
373
  this.#definitions = preprocessedGraph.definitions;
369
374
  this.#scc = preprocessedGraph.stronglyConnectedComponents;
370
375
  this.#nodesNotInCycle = preprocessedGraph.nodesNotInCycle;
376
+ this.#executionGraphNodes = preprocessedGraph.graphNodes;
377
+ this.#remainingNodes = new Set(this.#executionGraphNodes.map((node) => node.id));
371
378
  this.#graphExecutionPlan = isGraphExecutionPlan(preprocessedGraph) ? preprocessedGraph : undefined;
372
379
  }
373
380
  #seededExecutionPlanForNextRun() {
@@ -522,6 +529,13 @@ export class GraphProcessor {
522
529
  }
523
530
  }
524
531
  preloadNodeData(nodeId, data) {
532
+ // Preloading is deliberately permitted before a run starts. Do not
533
+ // preprocess here: referenced-project ports are loaded by processGraph,
534
+ // and caching a plan before that point would preserve an empty boundary.
535
+ const effectiveNode = this.#getEffectiveAuthoredNode(nodeId);
536
+ if (isDataBusTopologyNode(effectiveNode)) {
537
+ throw new Error(`Cannot preload Data Bus "${effectiveNode.title}". Data Bus channels are compiled topology, not node outputs.`);
538
+ }
525
539
  for (const value of Object.values(data)) {
526
540
  if (!value || !('type' in value) || !value.type) {
527
541
  throw new Error(`Invalid data value for node ${nodeId}, must be a DataValue`);
@@ -541,6 +555,10 @@ export class GraphProcessor {
541
555
  }
542
556
  /** Gets all node IDs that a given node ID depends on being complete before the given node ID can start. */
543
557
  getDependencyNodesDeep(nodeId) {
558
+ const effectiveNode = this.#getEffectiveAuthoredNode(nodeId);
559
+ if (isDataBusTopologyNode(effectiveNode)) {
560
+ throw new Error(`Cannot get dependencies for Data Bus "${effectiveNode.title}". Data Bus channels are compiled topology, not executable nodes.`);
561
+ }
544
562
  this.#ensureGraphPreprocessed();
545
563
  const dependencyNodes = new Set();
546
564
  this.#collectDependencyNodesDeep(nodeId, dependencyNodes);
@@ -551,7 +569,14 @@ export class GraphProcessor {
551
569
  return;
552
570
  }
553
571
  this.#loadedProjects ??= {};
554
- this.#preprocessGraph();
572
+ // This synchronous inspection API can be called before processGraph has
573
+ // loaded references. Its provisional definitions must never be reused as
574
+ // a runtime plan for a later fully loaded invocation.
575
+ this.#preprocessGraph({ allowRuntimeExecutionPlanCache: false });
576
+ }
577
+ #getEffectiveAuthoredNode(nodeId) {
578
+ const authoredNode = this.#graph.nodes.find((node) => node.id === nodeId);
579
+ return authoredNode ? resolveNodePrefabInstance(this.#project, authoredNode) : undefined;
555
580
  }
556
581
  #collectDependencyNodesDeep(nodeId, dependencyNodes) {
557
582
  if (dependencyNodes.has(nodeId)) {
@@ -606,8 +631,11 @@ export class GraphProcessor {
606
631
  this.#hasPreloadedData = this.#preloadedNodeResults.size > 0;
607
632
  this.#erroredNodes = new Map();
608
633
  this.#currentlyProcessing = new Set();
609
- const seededExecutionPlan = this.#seededExecutionPlanForNextRun();
610
- this.#remainingNodes = new Set(seededExecutionPlan ? seededExecutionPlan.nodeIds : this.#graph.nodes.map((node) => node.id));
634
+ // A processor may be constructed with a reusable execution plan. In that
635
+ // case preprocessing happened before this run, so retain the compiled
636
+ // execution-node set rather than restoring the authored graph nodes (which
637
+ // may include topology-only Data Bus nodes).
638
+ this.#remainingNodes = new Set(this.#seededExecutionPlanForNextRun()?.nodeIds ?? []);
611
639
  this.#pendingUserInputs = {};
612
640
  this.#processingQueue = new PQueue({ concurrency: this.#concurrency.nodeConcurrency });
613
641
  this.#graphOutputs = this.#sharedRunStateOverride?.graphOutputs ?? {};
@@ -675,10 +703,24 @@ export class GraphProcessor {
675
703
  this.#profileRuntimeSync('prepareNodeProcessContextBase', () => this.#prepareNodeProcessContextBase());
676
704
  const shouldUseSeededExecutionPlan = this.#seededExecutionPlanForNextRun() != null;
677
705
  this.#useSeededExecutionPlanOnNextRun = false;
678
- if (!shouldUseSeededExecutionPlan) {
679
- this.#preprocessGraph();
706
+ try {
707
+ if (!shouldUseSeededExecutionPlan) {
708
+ this.#preprocessGraph();
709
+ }
710
+ this.#assertNoDataBusRunTargets();
711
+ this.#prepareAsyncBranchTopology();
712
+ }
713
+ catch (error) {
714
+ 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
+ }
722
+ throw normalizedError;
680
723
  }
681
- this.#prepareAsyncBranchTopology();
682
724
  await this.#profileRuntimeAsync('emitGraphStart', () => this.#emitGraphStart());
683
725
  await this.#profileRuntimeAsync('emitPreloadedNodeResults', () => this.#emitPreloadedNodeResults());
684
726
  await this.#profileRuntimeAsync('waitUntilUnpaused', () => this.#waitUntilUnpaused());
@@ -826,7 +868,7 @@ export class GraphProcessor {
826
868
  if (!this.#hasPreloadedData) {
827
869
  return;
828
870
  }
829
- for (const node of this.#graph.nodes) {
871
+ for (const node of this.#executionGraphNodes) {
830
872
  if (!this.#nodeResults.has(node.id)) {
831
873
  continue;
832
874
  }
@@ -854,7 +896,7 @@ export class GraphProcessor {
854
896
  }
855
897
  }
856
898
  async #processCompatibleGraph() {
857
- await this.#queueStartNodes(getStartNodes(this.#executionState, this.#graph.nodes, this.runToNodeIds));
899
+ await this.#queueStartNodes(getStartNodes(this.#executionState, this.#executionGraphNodes, this.runToNodeIds));
858
900
  await this.#processingQueue.onIdle();
859
901
  this.#markUnqueuedNodesIgnored();
860
902
  }
@@ -865,13 +907,13 @@ export class GraphProcessor {
865
907
  if (this.#hasPreloadedData || this.runToNodeIds || this.slowMode || this.#includeTrace) {
866
908
  return false;
867
909
  }
868
- if (this.#nodesNotInCycle.length !== this.#graph.nodes.length) {
910
+ if (this.#nodesNotInCycle.length !== this.#executionGraphNodes.length) {
869
911
  return false;
870
912
  }
871
- if (this.#graph.connections.some((connection) => connection.inputNodeId === connection.outputNodeId)) {
913
+ if (this.#getEffectiveConnections().some((connection) => connection.inputNodeId === connection.outputNodeId)) {
872
914
  return false;
873
915
  }
874
- return this.#graph.nodes.every((node) => {
916
+ return this.#executionGraphNodes.every((node) => {
875
917
  if (node.isSplitRun) {
876
918
  return false;
877
919
  }
@@ -880,7 +922,7 @@ export class GraphProcessor {
880
922
  }
881
923
  async #processFastAcyclicGraph() {
882
924
  const relevantNodeIds = new Set();
883
- const nodesToVisit = [...getStartNodes(this.#executionState, this.#graph.nodes)];
925
+ const nodesToVisit = [...getStartNodes(this.#executionState, this.#executionGraphNodes)];
884
926
  for (let index = 0; index < nodesToVisit.length; index += 1) {
885
927
  const node = nodesToVisit[index];
886
928
  if (relevantNodeIds.has(node.id)) {
@@ -893,7 +935,7 @@ export class GraphProcessor {
893
935
  const remainingInputsByNode = new Map();
894
936
  const readyNodes = [];
895
937
  const queuedNodeIds = new Set();
896
- for (const node of this.#graph.nodes) {
938
+ for (const node of this.#executionGraphNodes) {
897
939
  if (!relevantNodeIds.has(node.id)) {
898
940
  continue;
899
941
  }
@@ -964,7 +1006,7 @@ export class GraphProcessor {
964
1006
  if (!this.runToNodeIds) {
965
1007
  return;
966
1008
  }
967
- for (const node of this.#graph.nodes) {
1009
+ for (const node of this.#executionGraphNodes) {
968
1010
  if (this.#queuedNodes.has(node.id) === false) {
969
1011
  this.#ignoreNodes.add(node.id);
970
1012
  }
@@ -1534,6 +1576,7 @@ export class GraphProcessor {
1534
1576
  async #processSplitRunNode(node, processId) {
1535
1577
  return processSplitRunNode(node, processId, {
1536
1578
  getInputValues: (n) => this.#getInputValuesForNode(n),
1579
+ getInputDefinitions: (n) => this.#definitions[n.id]?.inputs ?? [],
1537
1580
  isExcludedDueToControlFlow: (n, inputs, pid) => this.#excludedDueToControlFlow(n, inputs, pid) !== false,
1538
1581
  processNodeWithInputData: (n, inputs, idx, pid, partial) => this.#processNodeWithInputData(n, inputs, idx, pid, partial),
1539
1582
  splitRunConcurrency: this.#concurrency.splitRunConcurrency,
@@ -1882,194 +1925,64 @@ export class GraphProcessor {
1882
1925
  this.#toolCallContinuationInvocations.delete(this.#getToolCallContinuationInvocationKey(processId, index));
1883
1926
  }
1884
1927
  async #runToolCallContinuationRound(llmNode, invocation, toolCalls, assistantMessage, llmSignal) {
1885
- if (toolCalls.length === 0) {
1886
- return [];
1887
- }
1888
- if (this.#abortController.signal.aborted) {
1889
- throw createGraphAbortErrorFromSignal(this.#abortController.signal);
1890
- }
1891
- const { delegateNode } = invocation;
1892
- const processIds = toolCalls.map(() => nanoid());
1893
- const inputValuesByCall = toolCalls.map((toolCall) => ({
1894
- [DELEGATE_TOOL_CALL_INPUT_ID]: {
1895
- type: 'object',
1896
- value: toolCall,
1897
- },
1898
- }));
1899
- const nodeAbortControllers = toolCalls.map(() => this.#newAbortController());
1900
- nodeAbortControllers.forEach((controller) => this.#registerNodeAbortController(delegateNode.id, controller));
1901
- const abortAllCalls = (reason) => {
1902
- for (const controller of nodeAbortControllers) {
1903
- if (!controller.signal.aborted) {
1904
- controller.abort(reason);
1905
- }
1906
- }
1907
- };
1908
- const abortFromLLM = () => {
1909
- abortAllCalls(getAbortSignalReason(llmSignal));
1910
- };
1911
- llmSignal.addEventListener('abort', abortFromLLM, { once: true });
1912
- if (this.#abortController.signal.aborted) {
1913
- abortAllCalls(getAbortSignalReason(this.#abortController.signal));
1914
- }
1915
- else if (llmSignal.aborted) {
1916
- abortFromLLM();
1917
- }
1918
- try {
1919
- await this.#waitUntilUnpaused();
1920
- const abortedController = nodeAbortControllers.find((controller) => controller.signal.aborted);
1921
- if (abortedController) {
1922
- throw createGraphAbortErrorFromSignal(abortedController.signal, 'Delegate Tool Call aborted');
1923
- }
1924
- const hasAssistantMessage = assistantMessage.trim().length > 0;
1925
- const branchContext = this.#createContinuationBranchContext();
1926
- const canRunContinuationBranches = !branchContext.unsafeNodeIds.has(llmNode.id) && !branchContext.unsafeNodeIds.has(delegateNode.id);
1927
- const assistantOutputs = {
1928
- ['assistant-message']: {
1929
- type: 'string',
1930
- value: assistantMessage,
1931
- },
1932
- };
1933
- const preToolOutputPorts = new Set(['assistant-message']);
1934
- const hasActivePreToolBranch = hasAssistantMessage && this.#getActiveOutputPortIds(delegateNode).has('assistant-message');
1935
- const continuationBranchBoundaries = new Set([llmNode.id, ...this.#currentlyProcessing]);
1936
- // Validate round-level configuration before any of the parallel calls can
1937
- // start side effects. Preserve one real Delegate error run for diagnostics.
1938
- try {
1939
- if (this.#nodeResults.has(delegateNode.id) ||
1940
- this.#resolveFrozenNodeOutputs(delegateNode, inputValuesByCall[0], processIds[0])) {
1941
- throw new Error(`Delegate Tool Call "${delegateNode.title}" is the active auto-continuation handler and cannot use preloaded or frozen outputs. Clear its preload or unfreeze it before running this graph.`);
1942
- }
1943
- if (hasActivePreToolBranch) {
1944
- if (!canRunContinuationBranches) {
1945
- throw new Error(`Delegate Tool Call "${delegateNode.title}" cannot fire its pre-tool Message branch because the LLM/Delegate continuation is inside an unsupported cycle, race, or loop.`);
1946
- }
1947
- this.#buildContinuationBranchPlan(delegateNode, assistantOutputs, preToolOutputPorts, new Map(), continuationBranchBoundaries, branchContext, true);
1948
- }
1949
- }
1950
- catch (error) {
1951
- const processId = processIds[0];
1952
- const inputValues = inputValuesByCall[0];
1953
- await this.#emitter.emit('nodeStart', this.#withExecution({ node: delegateNode, inputs: inputValues, processId }));
1954
- const timingStart = this.#startNodeTiming();
1955
- await this.#nodeErrored(delegateNode, error, processId, this.#finishNodeTiming(timingStart));
1956
- throw error;
1957
- }
1958
- let firstFailure;
1959
- let hasFailure = false;
1960
- const abortSiblingOnFailure = async (work) => {
1961
- try {
1962
- return await work;
1963
- }
1964
- catch (error) {
1965
- if (!hasFailure) {
1966
- hasFailure = true;
1967
- firstFailure = error;
1968
- }
1969
- abortAllCalls(error);
1970
- throw error;
1971
- }
1972
- };
1973
- const runInvocation = async (toolCall, toolCallIndex) => {
1974
- const processId = processIds[toolCallIndex];
1975
- const inputValues = inputValuesByCall[toolCallIndex];
1976
- const nodeAbortController = nodeAbortControllers[toolCallIndex];
1977
- let timingStart;
1978
- let delegateStarted = false;
1979
- let delegateFinished = false;
1980
- try {
1981
- await this.#waitUntilUnpaused();
1982
- if (nodeAbortController.signal.aborted) {
1983
- throw createGraphAbortErrorFromSignal(nodeAbortController.signal, 'Delegate Tool Call aborted');
1984
- }
1985
- await this.#emitter.emit('nodeStart', this.#withExecution({ node: delegateNode, inputs: inputValues, processId }));
1986
- delegateStarted = true;
1987
- timingStart = this.#startNodeTiming();
1988
- const delegateContext = this.#createNodeProcessContext(delegateNode, inputValues, 0, processId, nodeAbortController, (node, partialOutputs, index) => this.#emitNodePartialOutput(node, partialOutputs, index, processId));
1989
- if (hasAssistantMessage) {
1990
- emitDetached(this.#emitter, 'partialOutput', this.#withExecution({
1991
- node: delegateNode,
1992
- outputs: assistantOutputs,
1993
- index: 0,
1994
- processId,
1995
- }));
1996
- }
1997
- let preToolBranchPromise;
1998
- if (hasActivePreToolBranch) {
1999
- preToolBranchPromise = this.#runContinuationOutputBranch(delegateNode, assistantOutputs, preToolOutputPorts, nodeAbortController.signal, new Map(), continuationBranchBoundaries, branchContext, true, true);
2000
- }
2001
- // Start tool work without waiting for the early Message branch. The
2002
- // branch and every sibling Delegate invocation remain independent.
2003
- const invocationWork = await Promise.allSettled([
2004
- abortSiblingOnFailure(delegateToolCall(toolCall, delegateContext, delegateNode.data)),
2005
- abortSiblingOnFailure(preToolBranchPromise ?? Promise.resolve({ graphOutputWrites: {}, nodeOutputs: new Map() })),
2006
- ]);
2007
- const toolOutcome = invocationWork[0];
2008
- const preToolBranchOutcome = invocationWork[1];
2009
- if (toolOutcome.status === 'rejected')
2010
- throw toolOutcome.reason;
2011
- if (preToolBranchOutcome.status === 'rejected')
2012
- throw preToolBranchOutcome.reason;
2013
- const toolResult = toolOutcome.value;
2014
- const preToolBranch = preToolBranchOutcome.value;
2015
- if (nodeAbortController.signal.aborted) {
2016
- throw createGraphAbortErrorFromSignal(nodeAbortController.signal, 'Delegate Tool Call aborted');
2017
- }
2018
- const outputs = buildDelegatedToolCallOutputs([toolResult.record], hasAssistantMessage ? assistantMessage : undefined, toolResult.cost);
2019
- this.#accumulateCost(outputs);
2020
- await this.#emitter.emit('nodeFinish', this.#withExecution(withOptionalDuration({
2021
- node: delegateNode,
2022
- outputs,
2023
- processId,
2024
- }, this.#finishNodeTiming(timingStart))));
2025
- delegateFinished = true;
2026
- const finalOutputPorts = new Set(['output', 'message']);
2027
- const finalBranch = canRunContinuationBranches
2028
- ? await this.#runContinuationOutputBranch(delegateNode, outputs, finalOutputPorts, nodeAbortController.signal, preToolBranch.nodeOutputs, continuationBranchBoundaries, branchContext, false, true)
2029
- : { graphOutputWrites: {}, nodeOutputs: new Map() };
2030
- return { finalBranch, outputs, preToolBranch, toolResult };
2031
- }
2032
- catch (error) {
2033
- if (delegateStarted && !delegateFinished) {
2034
- await this.#nodeErrored(delegateNode, error, processId, this.#finishNodeTiming(timingStart));
2035
- }
2036
- throw error;
2037
- }
2038
- };
2039
- const toolWorkOutcomes = await Promise.allSettled(toolCalls.map((toolCall, toolCallIndex) => abortSiblingOnFailure(runInvocation(toolCall, toolCallIndex))));
2040
- if (hasFailure) {
2041
- throw firstFailure;
2042
- }
2043
- const invocationResults = toolWorkOutcomes.map((outcome) => {
2044
- if (outcome.status === 'rejected') {
2045
- throw outcome.reason;
2046
- }
2047
- return outcome.value;
2048
- });
2049
- for (const result of invocationResults) {
2050
- invocation.latestOutputs.set(delegateNode.id, result.outputs);
2051
- for (const branch of [result.preToolBranch, result.finalBranch]) {
2052
- this.#commitContinuationGraphOutputs(branch.graphOutputWrites);
2053
- for (const [nodeId, outputs] of branch.nodeOutputs) {
2054
- invocation.latestOutputs.set(nodeId, outputs);
2055
- }
1928
+ const round = await new ToolCallContinuationCoordinator(this.#createToolCallContinuationCoordinatorAdapter()).run({
1929
+ assistantMessage,
1930
+ delegateNode: invocation.delegateNode,
1931
+ llmNode,
1932
+ llmSignal,
1933
+ toolCalls,
1934
+ });
1935
+ for (const result of round.invocations) {
1936
+ invocation.latestOutputs.set(invocation.delegateNode.id, result.outputs);
1937
+ for (const branch of [result.preToolBranch, result.finalBranch]) {
1938
+ this.#commitContinuationGraphOutputs(branch.graphOutputWrites);
1939
+ for (const [nodeId, outputs] of branch.nodeOutputs) {
1940
+ invocation.latestOutputs.set(nodeId, outputs);
2056
1941
  }
2057
1942
  }
2058
- return invocationResults.map(({ toolResult }) => ({
2059
- message: toolResult.message,
2060
- record: toolResult.record,
2061
- }));
2062
- }
2063
- finally {
2064
- llmSignal.removeEventListener('abort', abortFromLLM);
2065
- nodeAbortControllers.forEach((controller) => this.#unregisterNodeAbortController(delegateNode.id, controller));
2066
1943
  }
1944
+ return [...round.results];
1945
+ }
1946
+ #createToolCallContinuationCoordinatorAdapter() {
1947
+ return {
1948
+ accumulateCost: (outputs) => this.#accumulateCost(outputs),
1949
+ createBranchAdapter: () => {
1950
+ const branchPlanner = this.#createToolCallContinuationBranchPlanner();
1951
+ return {
1952
+ canRunContinuationBranches: (llmNode, delegateNode) => !branchPlanner.unsafeNodeIds.has(llmNode.id) && !branchPlanner.unsafeNodeIds.has(delegateNode.id),
1953
+ runOutputBranch: (request) => this.#runContinuationOutputBranch(request.sourceNode, request.sourceOutputs, request.activeOutputPortIds, request.signal, request.availableNodeOutputs, request.excludedNodeIds, branchPlanner, request.failOnUnsafeReadyNode, request.deferGraphOutputCommit),
1954
+ validatePreToolBranch: (request) => {
1955
+ this.#planToolCallContinuationBranch(request.sourceNode, request.sourceOutputs, request.activeOutputPortIds, new Map(), request.excludedNodeIds, branchPlanner, true);
1956
+ },
1957
+ };
1958
+ },
1959
+ createDelegateProcessContext: (node, inputs, processId, nodeAbortController) => this.#createNodeProcessContext(node, inputs, 0, processId, nodeAbortController, (partialNode, partialOutputs, index) => this.#emitNodePartialOutput(partialNode, partialOutputs, index, processId)),
1960
+ createNodeAbortController: () => this.#newAbortController(),
1961
+ emitDelegateError: (node, error, processId, timingStart) => this.#nodeErrored(node, error, processId, this.#finishNodeTiming(timingStart)),
1962
+ emitDelegateFinish: async (node, outputs, processId, timingStart) => {
1963
+ await this.#emitter.emit('nodeFinish', this.#withExecution(withOptionalDuration({
1964
+ node,
1965
+ outputs,
1966
+ processId,
1967
+ }, this.#finishNodeTiming(timingStart))));
1968
+ },
1969
+ emitDelegatePartialOutput: (node, outputs, processId) => this.#emitNodePartialOutput(node, outputs, 0, processId),
1970
+ emitDelegateStart: (node, inputs, processId) => this.#emitter.emit('nodeStart', this.#withExecution({ node, inputs, processId })),
1971
+ getActiveOutputPortIds: (node) => this.#getActiveOutputPortIds(node),
1972
+ getContinuationBranchBoundaryNodeIds: (llmNode) => new Set([llmNode.id, ...this.#currentlyProcessing]),
1973
+ hasPreloadedOrFrozenDelegateOutput: (node, inputs, processId) => this.#nodeResults.has(node.id) || this.#resolveFrozenNodeOutputs(node, inputs, processId) != null,
1974
+ registerNodeAbortController: (nodeId, controller) => this.#registerNodeAbortController(nodeId, controller),
1975
+ rootAbortSignal: this.#abortController.signal,
1976
+ unregisterNodeAbortController: (nodeId, controller) => this.#unregisterNodeAbortController(nodeId, controller),
1977
+ startNodeTiming: () => this.#startNodeTiming(),
1978
+ waitUntilUnpaused: () => this.#waitUntilUnpaused(),
1979
+ };
2067
1980
  }
2068
- async #runContinuationOutputBranch(sourceNode, sourceOutputs, activeOutputPortIds, signal, availableNodeOutputs, excludedNodeIds, branchContext, failOnUnsafeReadyNode = false, deferGraphOutputCommit = false) {
1981
+ async #runContinuationOutputBranch(sourceNode, sourceOutputs, activeOutputPortIds, signal, availableNodeOutputs, excludedNodeIds, branchPlanner, failOnUnsafeReadyNode = false, deferGraphOutputCommit = false) {
2069
1982
  if (signal.aborted) {
2070
1983
  throw createGraphAbortErrorFromSignal(signal, 'Tool continuation branch aborted');
2071
1984
  }
2072
- const branchPlan = this.#buildContinuationBranchPlan(sourceNode, sourceOutputs, activeOutputPortIds, availableNodeOutputs, excludedNodeIds, branchContext, failOnUnsafeReadyNode);
1985
+ const branchPlan = this.#planToolCallContinuationBranch(sourceNode, sourceOutputs, activeOutputPortIds, availableNodeOutputs, excludedNodeIds, branchPlanner, failOnUnsafeReadyNode);
2073
1986
  if (!branchPlan) {
2074
1987
  return { graphOutputWrites: {}, nodeOutputs: new Map() };
2075
1988
  }
@@ -2190,175 +2103,49 @@ export class GraphProcessor {
2190
2103
  }
2191
2104
  return results;
2192
2105
  }
2193
- #buildContinuationBranchPlan(sourceNode, sourceOutputs, activeOutputPortIds, availableNodeOutputs, excludedNodeIds, branchContext, failOnUnsafeReadyNode = false) {
2194
- const { connections, unsafeNodeIds } = branchContext;
2195
- const hasAvailableSourceOutput = (outputId) => {
2196
- const output = sourceOutputs[outputId];
2197
- return output != null && output.type !== 'control-flow-excluded';
2198
- };
2199
- const getAvailableNodeOutputs = (nodeId) => {
2200
- if (excludedNodeIds.has(nodeId) || unsafeNodeIds.has(nodeId) || this.#erroredNodes.has(nodeId)) {
2201
- return undefined;
2202
- }
2203
- return availableNodeOutputs.get(nodeId) ?? this.#nodeResults.get(nodeId);
2204
- };
2205
- const runToRelevantNodeIds = this.#getRunToRelevantNodeIds();
2206
- const canConsiderNode = (nodeId) => {
2207
- const node = this.#nodesById[nodeId];
2208
- return (node != null &&
2209
- !node.disabled &&
2210
- !this.#visitedNodes.has(nodeId) &&
2211
- (!runToRelevantNodeIds || runToRelevantNodeIds.has(nodeId)));
2212
- };
2213
- const isUnsafeNode = (nodeId) => excludedNodeIds.has(nodeId) || unsafeNodeIds.has(nodeId);
2214
- const outgoingConnectionsByNode = new Map();
2215
- const incomingConnectionsByNode = new Map();
2216
- for (const connection of connections) {
2217
- const outgoing = outgoingConnectionsByNode.get(connection.outputNodeId);
2218
- if (outgoing) {
2219
- outgoing.push(connection);
2220
- }
2221
- else {
2222
- outgoingConnectionsByNode.set(connection.outputNodeId, [connection]);
2223
- }
2224
- const incoming = incomingConnectionsByNode.get(connection.inputNodeId);
2225
- if (incoming) {
2226
- incoming.push(connection);
2227
- }
2228
- else {
2229
- incomingConnectionsByNode.set(connection.inputNodeId, [connection]);
2230
- }
2231
- }
2232
- const reachableNodeIds = new Set();
2233
- const candidateNodeIds = new Set();
2234
- for (const connection of outgoingConnectionsByNode.get(sourceNode.id) ?? []) {
2235
- if (activeOutputPortIds.has(connection.outputId) && canConsiderNode(connection.inputNodeId)) {
2236
- candidateNodeIds.add(connection.inputNodeId);
2237
- }
2238
- }
2239
- const boundaryNodeIds = new Set();
2240
- let addedNode = true;
2241
- while (addedNode) {
2242
- addedNode = false;
2243
- for (const candidateNodeId of [...candidateNodeIds]) {
2244
- const incomingConnections = incomingConnectionsByNode.get(candidateNodeId) ?? [];
2245
- const isReady = incomingConnections.every((connection) => {
2246
- if (connection.outputNodeId === sourceNode.id) {
2247
- return activeOutputPortIds.has(connection.outputId) || hasAvailableSourceOutput(connection.outputId);
2248
- }
2249
- return (reachableNodeIds.has(connection.outputNodeId) || getAvailableNodeOutputs(connection.outputNodeId) != null);
2250
- });
2251
- if (!isReady) {
2252
- continue;
2253
- }
2254
- candidateNodeIds.delete(candidateNodeId);
2255
- if (isUnsafeNode(candidateNodeId)) {
2256
- if (failOnUnsafeReadyNode) {
2257
- const unsafeNode = this.#nodesById[candidateNodeId];
2258
- throw new Error(`Delegate Tool Call "${sourceNode.title}" cannot fire its pre-tool Message branch through unsupported node "${unsafeNode.title}". Move cycles, races, loops, and foreground rejoin points outside that branch.`);
2259
- }
2260
- continue;
2261
- }
2262
- reachableNodeIds.add(candidateNodeId);
2263
- addedNode = true;
2264
- for (const connection of incomingConnections) {
2265
- if (connection.outputNodeId !== sourceNode.id &&
2266
- !reachableNodeIds.has(connection.outputNodeId) &&
2267
- getAvailableNodeOutputs(connection.outputNodeId) != null) {
2268
- boundaryNodeIds.add(connection.outputNodeId);
2269
- }
2270
- }
2271
- if (this.#nodesById[candidateNodeId]?.type === 'startBackgroundBranch') {
2272
- continue;
2273
- }
2274
- for (const connection of outgoingConnectionsByNode.get(candidateNodeId) ?? []) {
2275
- if (connection.inputNodeId !== sourceNode.id &&
2276
- !reachableNodeIds.has(connection.inputNodeId) &&
2277
- canConsiderNode(connection.inputNodeId)) {
2278
- candidateNodeIds.add(connection.inputNodeId);
2279
- }
2280
- }
2281
- }
2282
- }
2283
- if (reachableNodeIds.size === 0) {
2284
- return undefined;
2285
- }
2286
- const includedNodeIds = new Set([sourceNode.id, ...reachableNodeIds, ...boundaryNodeIds]);
2287
- const asyncBranchConnections = [];
2288
- for (const nodeId of reachableNodeIds) {
2289
- if (this.#nodesById[nodeId]?.type !== 'startBackgroundBranch') {
2290
- continue;
2291
- }
2292
- const asyncPlan = this.#asyncBranchPlansByTriggerNodeId.get(nodeId);
2293
- if (!asyncPlan) {
2294
- continue;
2295
- }
2296
- for (const node of asyncPlan.graph.nodes) {
2297
- includedNodeIds.add(node.id);
2298
- }
2299
- asyncBranchConnections.push(...asyncPlan.graph.connections);
2300
- }
2301
- const foregroundBranchConnections = connections.filter((connection) => {
2302
- if (!reachableNodeIds.has(connection.inputNodeId)) {
2303
- return false;
2304
- }
2305
- if (connection.outputNodeId === sourceNode.id) {
2306
- return activeOutputPortIds.has(connection.outputId) || hasAvailableSourceOutput(connection.outputId);
2307
- }
2308
- return includedNodeIds.has(connection.outputNodeId);
2106
+ #planToolCallContinuationBranch(sourceNode, sourceOutputs, activeOutputPortIds, availableNodeOutputs, excludedNodeIds, branchPlanner, failOnUnsafeReadyNode = false) {
2107
+ return branchPlanner.plan({
2108
+ activeOutputPortIds,
2109
+ availableNodeOutputs,
2110
+ excludedNodeIds,
2111
+ failOnUnsafeReadyNode,
2112
+ sourceNode,
2113
+ sourceOutputs,
2114
+ state: {
2115
+ erroredNodeIds: new Set(this.#erroredNodes.keys()),
2116
+ nodeOutputs: this.#nodeResults,
2117
+ runToRelevantNodeIds: this.#getRunToRelevantNodeIds(),
2118
+ visitedNodeIds: this.#visitedNodes,
2119
+ },
2309
2120
  });
2310
- const seenConnections = new Set();
2311
- const branchConnections = [...foregroundBranchConnections, ...asyncBranchConnections].filter((connection) => {
2312
- const key = `${connection.outputNodeId}:${connection.outputId}:${connection.inputNodeId}:${connection.inputId}`;
2313
- if (seenConnections.has(key)) {
2314
- return false;
2315
- }
2316
- seenConnections.add(key);
2317
- return true;
2121
+ }
2122
+ #createToolCallContinuationBranchPlanner() {
2123
+ return createToolCallContinuationBranchPlanner({
2124
+ asyncBranchPlansByTriggerNodeId: this.#asyncBranchPlansByTriggerNodeId,
2125
+ attachedNodeDataByNodeId: this.#attachedNodeData,
2126
+ effectiveConnections: this.#getEffectiveConnections(),
2127
+ graph: this.#getExecutionGraph(),
2128
+ isDefinitionValidConnection: (connection) => this.#isDefinitionValidConnection(connection),
2129
+ nodesById: this.#nodesById,
2130
+ stronglyConnectedComponents: this.#scc,
2318
2131
  });
2319
- const graph = {
2320
- metadata: this.#graph.metadata ? { ...this.#graph.metadata } : undefined,
2321
- nodes: Object.values(this.#nodesById).filter((node) => includedNodeIds.has(node.id)),
2322
- connections: branchConnections,
2323
- };
2324
- const preloadedOutputs = new Map([[sourceNode.id, sourceOutputs]]);
2325
- for (const nodeId of boundaryNodeIds) {
2326
- preloadedOutputs.set(nodeId, getAvailableNodeOutputs(nodeId));
2327
- }
2328
- return { graph, preloadedOutputs };
2329
2132
  }
2330
- #createContinuationBranchContext() {
2331
- const connections = this.#getEffectiveConnections();
2133
+ /**
2134
+ * Graph-owned metadata is retained, but every scheduler-facing consumer
2135
+ * receives the preprocessed topology. In particular, a Data Bus is not an
2136
+ * executable intermediate node for tool-continuation discovery.
2137
+ */
2138
+ #getExecutionGraph() {
2332
2139
  return {
2333
- connections,
2334
- unsafeNodeIds: this.#getUnsafeContinuationBranchNodeIds(),
2140
+ metadata: this.#graph.metadata ? { ...this.#graph.metadata } : undefined,
2141
+ nodes: this.#executionGraphNodes,
2142
+ // Keep every preprocessed connection here, rather than the scheduler's
2143
+ // one-provider-per-input execution projection. The continuation planner
2144
+ // needs to see otherwise-shadowed valid edges to reject unsafe cycles
2145
+ // before it starts a pre-tool branch.
2146
+ connections: [...new Set(Object.values(this.#connections).flat())],
2335
2147
  };
2336
2148
  }
2337
- #getUnsafeContinuationBranchNodeIds() {
2338
- const unsafeNodeIds = new Set();
2339
- for (const component of this.#scc) {
2340
- if (component.length > 1) {
2341
- component.forEach((node) => unsafeNodeIds.add(node.id));
2342
- }
2343
- }
2344
- for (const node of Object.values(this.#nodesById)) {
2345
- const attachedData = this.#attachedNodeData.get(node.id);
2346
- if (node.type === 'loopController' ||
2347
- node.type === 'raceInputs' ||
2348
- (attachedData != null && Object.values(attachedData).some(Boolean))) {
2349
- unsafeNodeIds.add(node.id);
2350
- }
2351
- }
2352
- // SCC preprocessing sees every persisted edge, including secondary edges
2353
- // that still participate in scheduler readiness. Preserve the same view
2354
- // when detecting a one-node cycle.
2355
- for (const connection of this.#graph.connections) {
2356
- if (connection.inputNodeId === connection.outputNodeId && this.#isDefinitionValidConnection(connection)) {
2357
- unsafeNodeIds.add(connection.inputNodeId);
2358
- }
2359
- }
2360
- return unsafeNodeIds;
2361
- }
2362
2149
  #getEffectiveConnections() {
2363
2150
  if (this.#effectiveConnectionsForRun) {
2364
2151
  return this.#effectiveConnectionsForRun;
@@ -2454,7 +2241,7 @@ export class GraphProcessor {
2454
2241
  const includedNodeIds = new Set([triggerNode.id, ...nodeIds, ...inputAnchorNodeIds]);
2455
2242
  const graph = {
2456
2243
  metadata: this.#graph.metadata ? { ...this.#graph.metadata } : undefined,
2457
- nodes: this.#graph.nodes.filter((node) => includedNodeIds.has(node.id)),
2244
+ nodes: this.#executionGraphNodes.filter((node) => includedNodeIds.has(node.id)),
2458
2245
  connections: connections.filter((connection) => connection.inputNodeId === triggerNode.id ||
2459
2246
  (nodeIds.has(connection.inputNodeId) &&
2460
2247
  (connection.outputNodeId === triggerNode.id || nodeIds.has(connection.outputNodeId)))),
@@ -2539,6 +2326,17 @@ export class GraphProcessor {
2539
2326
  }
2540
2327
  return activeOutputPortIds;
2541
2328
  }
2329
+ #assertNoDataBusRunTargets() {
2330
+ for (const nodeId of this.runToNodeIds ?? []) {
2331
+ if (this.#nodesById[nodeId]) {
2332
+ continue;
2333
+ }
2334
+ const effectiveNode = this.#getEffectiveAuthoredNode(nodeId);
2335
+ if (isDataBusTopologyNode(effectiveNode)) {
2336
+ throw new Error(`Cannot run to Data Bus "${effectiveNode.title}". Data Bus channels are compiled topology, not executable nodes.`);
2337
+ }
2338
+ }
2339
+ }
2542
2340
  #getRunToRelevantNodeIds() {
2543
2341
  if (!this.runToNodeIds) {
2544
2342
  return undefined;