@valerypopoff/rivet2-core 2.1.6 → 2.1.8
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.
- package/dist/cjs/bundle.cjs +3436 -1831
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/esm/api/createProcessor.js +45 -4
- package/dist/esm/exports.js +2 -0
- package/dist/esm/integrations/KnowledgeStoreFieldPolicy.js +216 -0
- package/dist/esm/integrations/KnowledgeStoreProvider.js +14 -90
- package/dist/esm/integrations/ManagedKnowledgeStore.js +0 -8
- package/dist/esm/model/DataBusPorts.js +26 -0
- package/dist/esm/model/DataBusTopology.js +207 -0
- package/dist/esm/model/DataValue.js +22 -7
- package/dist/esm/model/GraphPreprocessor.js +9 -3
- package/dist/esm/model/GraphProcessor.js +163 -366
- package/dist/esm/model/NodeIO.js +1 -0
- package/dist/esm/model/NodePrefabResolver.js +16 -0
- package/dist/esm/model/Nodes.js +7 -0
- package/dist/esm/model/ToolCallContinuationBranchPlanner.js +165 -0
- package/dist/esm/model/ToolCallContinuationCoordinator.js +201 -0
- package/dist/esm/model/chat-v2/chatV2CallObserver.js +140 -0
- package/dist/esm/model/chat-v2/chatV2Errors.js +23 -6
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +47 -14
- package/dist/esm/model/chat-v2/chatV2ProviderTypes.js +1 -0
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +2 -2
- package/dist/esm/model/chat-v2/index.js +1 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +52 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +38 -13
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +42 -34
- package/dist/esm/model/chat-v2/llmProfile.js +191 -0
- package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +73 -0
- package/dist/esm/model/chat-v2/llmProfileTypes.js +45 -0
- package/dist/esm/model/nodes/DataBusNode.js +81 -0
- package/dist/esm/model/nodes/GetGlobalNode.js +7 -11
- package/dist/esm/model/nodes/GetKnowledgeSourceStatusNode.js +1 -1
- package/dist/esm/model/nodes/LLMChatV2Node.js +44 -10
- package/dist/esm/model/nodes/LLMProfileNode.js +132 -0
- package/dist/esm/model/nodes/PassthroughNode.js +26 -8
- package/dist/esm/model/nodes/SearchKnowledgeNode.js +1 -1
- package/dist/esm/model/nodes/SetGlobalNode.js +6 -6
- package/dist/esm/model/nodes/SyncKnowledgeSourceNode.js +0 -1
- package/dist/esm/model/nodes/toolCallDelegation.js +13 -2
- package/dist/esm/plugins/pinecone/PineconeKnowledgeStore.js +0 -4
- package/dist/esm/plugins/pinecone/plugin.js +1 -1
- package/dist/esm/utils/coerceType.js +84 -41
- package/dist/esm/utils/expectType.js +45 -8
- package/dist/esm/utils/fetchEventSource.js +18 -0
- package/dist/esm/utils/serialization/serialization.js +18 -7
- package/dist/esm/vendor/fnv1a.js +6 -3
- package/dist/types/api/createProcessor.d.ts +2 -0
- package/dist/types/exports.d.ts +2 -0
- package/dist/types/integrations/KnowledgeStore.d.ts +0 -2
- package/dist/types/integrations/KnowledgeStoreFieldPolicy.d.ts +38 -0
- package/dist/types/integrations/KnowledgeStoreProvider.d.ts +6 -3
- package/dist/types/model/DataBusPorts.d.ts +6 -0
- package/dist/types/model/DataBusTopology.d.ts +16 -0
- package/dist/types/model/DataValue.d.ts +15 -5
- package/dist/types/model/GraphPreprocessor.d.ts +2 -1
- package/dist/types/model/GraphProcessor.d.ts +4 -3
- package/dist/types/model/NodeIO.d.ts +5 -0
- package/dist/types/model/NodePrefabResolver.d.ts +9 -0
- package/dist/types/model/Nodes.d.ts +5 -2
- package/dist/types/model/ProcessContext.d.ts +60 -0
- package/dist/types/model/ToolCallContinuationBranchPlanner.d.ts +43 -0
- package/dist/types/model/ToolCallContinuationCoordinator.d.ts +70 -0
- package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +10 -0
- package/dist/types/model/chat-v2/chatV2ProviderTypes.d.ts +1 -0
- package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +8 -0
- package/dist/types/model/chat-v2/chatV2Types.d.ts +3 -3
- package/dist/types/model/chat-v2/index.d.ts +1 -0
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +6 -0
- package/dist/types/model/chat-v2/llmChatV2NodeEditors.d.ts +5 -1
- package/dist/types/model/chat-v2/llmProfile.d.ts +3 -0
- package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +9 -0
- package/dist/types/model/chat-v2/llmProfileTypes.d.ts +18 -0
- package/dist/types/model/nodes/DataBusNode.d.ts +19 -0
- package/dist/types/model/nodes/LLMProfileNode.d.ts +20 -0
- package/dist/types/model/nodes/PassthroughNode.d.ts +3 -2
- package/dist/types/model/nodes/SetGlobalNode.d.ts +2 -2
- package/dist/types/model/nodes/toolCallDelegation.d.ts +9 -0
- package/dist/types/vendor/fnv1a.d.ts +5 -5
- 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 {
|
|
27
|
-
import { buildDelegatedToolCallOutputs,
|
|
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()
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
610
|
-
|
|
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
|
-
|
|
679
|
-
|
|
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.#
|
|
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.#
|
|
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.#
|
|
910
|
+
if (this.#nodesNotInCycle.length !== this.#executionGraphNodes.length) {
|
|
869
911
|
return false;
|
|
870
912
|
}
|
|
871
|
-
if (this.#
|
|
913
|
+
if (this.#getEffectiveConnections().some((connection) => connection.inputNodeId === connection.outputNodeId)) {
|
|
872
914
|
return false;
|
|
873
915
|
}
|
|
874
|
-
return this.#
|
|
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.#
|
|
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.#
|
|
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.#
|
|
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
|
}
|
|
@@ -1882,194 +1924,64 @@ export class GraphProcessor {
|
|
|
1882
1924
|
this.#toolCallContinuationInvocations.delete(this.#getToolCallContinuationInvocationKey(processId, index));
|
|
1883
1925
|
}
|
|
1884
1926
|
async #runToolCallContinuationRound(llmNode, invocation, toolCalls, assistantMessage, llmSignal) {
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
const
|
|
1893
|
-
|
|
1894
|
-
[
|
|
1895
|
-
|
|
1896
|
-
|
|
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
|
-
}
|
|
1927
|
+
const round = await new ToolCallContinuationCoordinator(this.#createToolCallContinuationCoordinatorAdapter()).run({
|
|
1928
|
+
assistantMessage,
|
|
1929
|
+
delegateNode: invocation.delegateNode,
|
|
1930
|
+
llmNode,
|
|
1931
|
+
llmSignal,
|
|
1932
|
+
toolCalls,
|
|
1933
|
+
});
|
|
1934
|
+
for (const result of round.invocations) {
|
|
1935
|
+
invocation.latestOutputs.set(invocation.delegateNode.id, result.outputs);
|
|
1936
|
+
for (const branch of [result.preToolBranch, result.finalBranch]) {
|
|
1937
|
+
this.#commitContinuationGraphOutputs(branch.graphOutputWrites);
|
|
1938
|
+
for (const [nodeId, outputs] of branch.nodeOutputs) {
|
|
1939
|
+
invocation.latestOutputs.set(nodeId, outputs);
|
|
2056
1940
|
}
|
|
2057
1941
|
}
|
|
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
1942
|
}
|
|
1943
|
+
return [...round.results];
|
|
1944
|
+
}
|
|
1945
|
+
#createToolCallContinuationCoordinatorAdapter() {
|
|
1946
|
+
return {
|
|
1947
|
+
accumulateCost: (outputs) => this.#accumulateCost(outputs),
|
|
1948
|
+
createBranchAdapter: () => {
|
|
1949
|
+
const branchPlanner = this.#createToolCallContinuationBranchPlanner();
|
|
1950
|
+
return {
|
|
1951
|
+
canRunContinuationBranches: (llmNode, delegateNode) => !branchPlanner.unsafeNodeIds.has(llmNode.id) && !branchPlanner.unsafeNodeIds.has(delegateNode.id),
|
|
1952
|
+
runOutputBranch: (request) => this.#runContinuationOutputBranch(request.sourceNode, request.sourceOutputs, request.activeOutputPortIds, request.signal, request.availableNodeOutputs, request.excludedNodeIds, branchPlanner, request.failOnUnsafeReadyNode, request.deferGraphOutputCommit),
|
|
1953
|
+
validatePreToolBranch: (request) => {
|
|
1954
|
+
this.#planToolCallContinuationBranch(request.sourceNode, request.sourceOutputs, request.activeOutputPortIds, new Map(), request.excludedNodeIds, branchPlanner, true);
|
|
1955
|
+
},
|
|
1956
|
+
};
|
|
1957
|
+
},
|
|
1958
|
+
createDelegateProcessContext: (node, inputs, processId, nodeAbortController) => this.#createNodeProcessContext(node, inputs, 0, processId, nodeAbortController, (partialNode, partialOutputs, index) => this.#emitNodePartialOutput(partialNode, partialOutputs, index, processId)),
|
|
1959
|
+
createNodeAbortController: () => this.#newAbortController(),
|
|
1960
|
+
emitDelegateError: (node, error, processId, timingStart) => this.#nodeErrored(node, error, processId, this.#finishNodeTiming(timingStart)),
|
|
1961
|
+
emitDelegateFinish: async (node, outputs, processId, timingStart) => {
|
|
1962
|
+
await this.#emitter.emit('nodeFinish', this.#withExecution(withOptionalDuration({
|
|
1963
|
+
node,
|
|
1964
|
+
outputs,
|
|
1965
|
+
processId,
|
|
1966
|
+
}, this.#finishNodeTiming(timingStart))));
|
|
1967
|
+
},
|
|
1968
|
+
emitDelegatePartialOutput: (node, outputs, processId) => this.#emitNodePartialOutput(node, outputs, 0, processId),
|
|
1969
|
+
emitDelegateStart: (node, inputs, processId) => this.#emitter.emit('nodeStart', this.#withExecution({ node, inputs, processId })),
|
|
1970
|
+
getActiveOutputPortIds: (node) => this.#getActiveOutputPortIds(node),
|
|
1971
|
+
getContinuationBranchBoundaryNodeIds: (llmNode) => new Set([llmNode.id, ...this.#currentlyProcessing]),
|
|
1972
|
+
hasPreloadedOrFrozenDelegateOutput: (node, inputs, processId) => this.#nodeResults.has(node.id) || this.#resolveFrozenNodeOutputs(node, inputs, processId) != null,
|
|
1973
|
+
registerNodeAbortController: (nodeId, controller) => this.#registerNodeAbortController(nodeId, controller),
|
|
1974
|
+
rootAbortSignal: this.#abortController.signal,
|
|
1975
|
+
unregisterNodeAbortController: (nodeId, controller) => this.#unregisterNodeAbortController(nodeId, controller),
|
|
1976
|
+
startNodeTiming: () => this.#startNodeTiming(),
|
|
1977
|
+
waitUntilUnpaused: () => this.#waitUntilUnpaused(),
|
|
1978
|
+
};
|
|
2067
1979
|
}
|
|
2068
|
-
async #runContinuationOutputBranch(sourceNode, sourceOutputs, activeOutputPortIds, signal, availableNodeOutputs, excludedNodeIds,
|
|
1980
|
+
async #runContinuationOutputBranch(sourceNode, sourceOutputs, activeOutputPortIds, signal, availableNodeOutputs, excludedNodeIds, branchPlanner, failOnUnsafeReadyNode = false, deferGraphOutputCommit = false) {
|
|
2069
1981
|
if (signal.aborted) {
|
|
2070
1982
|
throw createGraphAbortErrorFromSignal(signal, 'Tool continuation branch aborted');
|
|
2071
1983
|
}
|
|
2072
|
-
const branchPlan = this.#
|
|
1984
|
+
const branchPlan = this.#planToolCallContinuationBranch(sourceNode, sourceOutputs, activeOutputPortIds, availableNodeOutputs, excludedNodeIds, branchPlanner, failOnUnsafeReadyNode);
|
|
2073
1985
|
if (!branchPlan) {
|
|
2074
1986
|
return { graphOutputWrites: {}, nodeOutputs: new Map() };
|
|
2075
1987
|
}
|
|
@@ -2190,175 +2102,49 @@ export class GraphProcessor {
|
|
|
2190
2102
|
}
|
|
2191
2103
|
return results;
|
|
2192
2104
|
}
|
|
2193
|
-
#
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
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);
|
|
2105
|
+
#planToolCallContinuationBranch(sourceNode, sourceOutputs, activeOutputPortIds, availableNodeOutputs, excludedNodeIds, branchPlanner, failOnUnsafeReadyNode = false) {
|
|
2106
|
+
return branchPlanner.plan({
|
|
2107
|
+
activeOutputPortIds,
|
|
2108
|
+
availableNodeOutputs,
|
|
2109
|
+
excludedNodeIds,
|
|
2110
|
+
failOnUnsafeReadyNode,
|
|
2111
|
+
sourceNode,
|
|
2112
|
+
sourceOutputs,
|
|
2113
|
+
state: {
|
|
2114
|
+
erroredNodeIds: new Set(this.#erroredNodes.keys()),
|
|
2115
|
+
nodeOutputs: this.#nodeResults,
|
|
2116
|
+
runToRelevantNodeIds: this.#getRunToRelevantNodeIds(),
|
|
2117
|
+
visitedNodeIds: this.#visitedNodes,
|
|
2118
|
+
},
|
|
2309
2119
|
});
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2120
|
+
}
|
|
2121
|
+
#createToolCallContinuationBranchPlanner() {
|
|
2122
|
+
return createToolCallContinuationBranchPlanner({
|
|
2123
|
+
asyncBranchPlansByTriggerNodeId: this.#asyncBranchPlansByTriggerNodeId,
|
|
2124
|
+
attachedNodeDataByNodeId: this.#attachedNodeData,
|
|
2125
|
+
effectiveConnections: this.#getEffectiveConnections(),
|
|
2126
|
+
graph: this.#getExecutionGraph(),
|
|
2127
|
+
isDefinitionValidConnection: (connection) => this.#isDefinitionValidConnection(connection),
|
|
2128
|
+
nodesById: this.#nodesById,
|
|
2129
|
+
stronglyConnectedComponents: this.#scc,
|
|
2318
2130
|
});
|
|
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
2131
|
}
|
|
2330
|
-
|
|
2331
|
-
|
|
2132
|
+
/**
|
|
2133
|
+
* Graph-owned metadata is retained, but every scheduler-facing consumer
|
|
2134
|
+
* receives the preprocessed topology. In particular, a Data Bus is not an
|
|
2135
|
+
* executable intermediate node for tool-continuation discovery.
|
|
2136
|
+
*/
|
|
2137
|
+
#getExecutionGraph() {
|
|
2332
2138
|
return {
|
|
2333
|
-
|
|
2334
|
-
|
|
2139
|
+
metadata: this.#graph.metadata ? { ...this.#graph.metadata } : undefined,
|
|
2140
|
+
nodes: this.#executionGraphNodes,
|
|
2141
|
+
// Keep every preprocessed connection here, rather than the scheduler's
|
|
2142
|
+
// one-provider-per-input execution projection. The continuation planner
|
|
2143
|
+
// needs to see otherwise-shadowed valid edges to reject unsafe cycles
|
|
2144
|
+
// before it starts a pre-tool branch.
|
|
2145
|
+
connections: [...new Set(Object.values(this.#connections).flat())],
|
|
2335
2146
|
};
|
|
2336
2147
|
}
|
|
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
2148
|
#getEffectiveConnections() {
|
|
2363
2149
|
if (this.#effectiveConnectionsForRun) {
|
|
2364
2150
|
return this.#effectiveConnectionsForRun;
|
|
@@ -2454,7 +2240,7 @@ export class GraphProcessor {
|
|
|
2454
2240
|
const includedNodeIds = new Set([triggerNode.id, ...nodeIds, ...inputAnchorNodeIds]);
|
|
2455
2241
|
const graph = {
|
|
2456
2242
|
metadata: this.#graph.metadata ? { ...this.#graph.metadata } : undefined,
|
|
2457
|
-
nodes: this.#
|
|
2243
|
+
nodes: this.#executionGraphNodes.filter((node) => includedNodeIds.has(node.id)),
|
|
2458
2244
|
connections: connections.filter((connection) => connection.inputNodeId === triggerNode.id ||
|
|
2459
2245
|
(nodeIds.has(connection.inputNodeId) &&
|
|
2460
2246
|
(connection.outputNodeId === triggerNode.id || nodeIds.has(connection.outputNodeId)))),
|
|
@@ -2539,6 +2325,17 @@ export class GraphProcessor {
|
|
|
2539
2325
|
}
|
|
2540
2326
|
return activeOutputPortIds;
|
|
2541
2327
|
}
|
|
2328
|
+
#assertNoDataBusRunTargets() {
|
|
2329
|
+
for (const nodeId of this.runToNodeIds ?? []) {
|
|
2330
|
+
if (this.#nodesById[nodeId]) {
|
|
2331
|
+
continue;
|
|
2332
|
+
}
|
|
2333
|
+
const effectiveNode = this.#getEffectiveAuthoredNode(nodeId);
|
|
2334
|
+
if (isDataBusTopologyNode(effectiveNode)) {
|
|
2335
|
+
throw new Error(`Cannot run to Data Bus "${effectiveNode.title}". Data Bus channels are compiled topology, not executable nodes.`);
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2542
2339
|
#getRunToRelevantNodeIds() {
|
|
2543
2340
|
if (!this.runToNodeIds) {
|
|
2544
2341
|
return undefined;
|