@valerypopoff/rivet2-core 2.15.0 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/cjs/bundle.cjs +7906 -3980
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/interpolationRuntime.cjs +62 -7
  4. package/dist/cjs/interpolationRuntime.cjs.map +3 -3
  5. package/dist/cjs/interpolationSyntax.cjs +9 -5
  6. package/dist/cjs/interpolationSyntax.cjs.map +2 -2
  7. package/dist/cjs/serialization.cjs +1880 -0
  8. package/dist/cjs/serialization.cjs.map +7 -0
  9. package/dist/cjs/webAppRuntime.cjs +168 -6
  10. package/dist/cjs/webAppRuntime.cjs.map +3 -3
  11. package/dist/esm/api/createProcessor.js +5 -2
  12. package/dist/esm/api/processSettings.js +1 -0
  13. package/dist/esm/exports.js +4 -0
  14. package/dist/esm/model/AgentResponseTrace.js +99 -34
  15. package/dist/esm/model/AgentResponseTracePresentation.js +130 -0
  16. package/dist/esm/model/DataValue.js +11 -2
  17. package/dist/esm/model/GlobalVariables.js +2 -1
  18. package/dist/esm/model/GraphBoundaryCache.js +2 -1
  19. package/dist/esm/model/GraphBoundaryEffects.js +38 -1
  20. package/dist/esm/model/GraphExecutionState.js +81 -0
  21. package/dist/esm/model/GraphProcessor.js +825 -884
  22. package/dist/esm/model/GraphSchedulerBoundaryState.js +64 -0
  23. package/dist/esm/model/Nodes.js +15 -0
  24. package/dist/esm/model/ProjectBundle.js +248 -0
  25. package/dist/esm/model/ProjectBundleRuntime.js +54 -0
  26. package/dist/esm/model/SchedulerBoundaryPlanner.js +233 -0
  27. package/dist/esm/model/SplitRunProcessor.js +28 -7
  28. package/dist/esm/model/StreamingWatchTopology.js +118 -8
  29. package/dist/esm/model/SubgraphProjectTarget.js +7 -0
  30. package/dist/esm/model/SubprocessorBridge.js +125 -87
  31. package/dist/esm/model/ToolCallContinuationCoordinator.js +1 -1
  32. package/dist/esm/model/chat-v2/aiSdkBridge.js +22 -17
  33. package/dist/esm/model/chat-v2/chatV2CallObserver.js +2 -4
  34. package/dist/esm/model/chat-v2/chatV2CredentialNames.js +5 -1
  35. package/dist/esm/model/chat-v2/chatV2Outputs.js +2 -2
  36. package/dist/esm/model/chat-v2/chatV2Pipeline.js +24 -9
  37. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +3 -2
  38. package/dist/esm/model/chat-v2/chatV2ProviderRegistry.js +46 -6
  39. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +26 -1
  40. package/dist/esm/model/chat-v2/chatV2Shared.js +2 -1
  41. package/dist/esm/model/chat-v2/chatV2UsageAccounting.js +10 -0
  42. package/dist/esm/model/chat-v2/llmChatV2Body.js +13 -10
  43. package/dist/esm/model/chat-v2/llmChatV2CacheBoundary.js +5 -2
  44. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +3 -0
  45. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +33 -9
  46. package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +22 -2
  47. package/dist/esm/model/chat-v2/llmInvocationCoordinator.js +10 -2
  48. package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +17 -0
  49. package/dist/esm/model/chat-v2/llmModelCandidate.js +2 -1
  50. package/dist/esm/model/chat-v2/llmProfile.js +5 -1
  51. package/dist/esm/model/chat-v2/llmProfileBody.js +11 -2
  52. package/dist/esm/model/chat-v2/llmProfileFallback.js +7 -4
  53. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +2 -1
  54. package/dist/esm/model/chat-v2/llmProfileHealthStore.js +16 -3
  55. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +1 -1
  56. package/dist/esm/model/chat-v2/messageConverter.js +18 -16
  57. package/dist/esm/model/chat-v2/modelRegistry.js +14 -4
  58. package/dist/esm/model/chat-v2/openRouterModel.js +73 -0
  59. package/dist/esm/model/chat-v2/parallelToolCalls.js +2 -0
  60. package/dist/esm/model/chat-v2/providerOptions.js +30 -25
  61. package/dist/esm/model/chat-v2/temperature.js +9 -0
  62. package/dist/esm/model/classifier/credentials.js +42 -6
  63. package/dist/esm/model/classifier/images.js +176 -0
  64. package/dist/esm/model/classifier/json.js +57 -0
  65. package/dist/esm/model/classifier/limits.js +300 -0
  66. package/dist/esm/model/classifier/openai.js +118 -0
  67. package/dist/esm/model/classifier/perplexity.js +63 -0
  68. package/dist/esm/model/classifier/preparation.js +74 -0
  69. package/dist/esm/model/classifier/profile.js +151 -0
  70. package/dist/esm/model/classifier/profileExecution.js +294 -0
  71. package/dist/esm/model/classifier/providers.js +454 -192
  72. package/dist/esm/model/classifier/questionHelpers.js +29 -45
  73. package/dist/esm/model/classifier/questions.js +53 -0
  74. package/dist/esm/model/classifier/response.js +75 -0
  75. package/dist/esm/model/classifier/state.js +207 -0
  76. package/dist/esm/model/classifier/types.js +11 -1
  77. package/dist/esm/model/nodeRunFailure.js +54 -0
  78. package/dist/esm/model/nodes/CallGraphNode.js +6 -0
  79. package/dist/esm/model/nodes/CatchStreamingChunksNode.js +42 -0
  80. package/dist/esm/model/nodes/ClassifierEvaluateNode.js +385 -154
  81. package/dist/esm/model/nodes/ClassifierProfileNode.js +133 -0
  82. package/dist/esm/model/nodes/ClassifierQuestionNode.js +59 -15
  83. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +1 -1
  84. package/dist/esm/model/nodes/GetGlobalNode.js +2 -2
  85. package/dist/esm/model/nodes/HttpCallNode.js +44 -75
  86. package/dist/esm/model/nodes/ImageNode.js +44 -3
  87. package/dist/esm/model/nodes/LLMChatV2Node.js +26 -4
  88. package/dist/esm/model/nodes/ObjectNode.js +29 -18
  89. package/dist/esm/model/nodes/PromptNode.js +2 -1
  90. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +4 -1
  91. package/dist/esm/model/nodes/SetGlobalNode.js +5 -3
  92. package/dist/esm/model/nodes/StopWatchingStreamingOutputNode.js +8 -8
  93. package/dist/esm/model/nodes/StreamValueNode.js +38 -0
  94. package/dist/esm/model/nodes/SubGraphNode.js +199 -35
  95. package/dist/esm/model/nodes/ToBase64Node.js +106 -0
  96. package/dist/esm/model/nodes/WatchStreamingOutputNode.js +7 -7
  97. package/dist/esm/model/nodes/toolCallDelegation.js +5 -1
  98. package/dist/esm/model/profileSuspensionHints.js +8 -0
  99. package/dist/esm/recording/ExecutionRecorder.js +26 -0
  100. package/dist/esm/serialization.js +2 -0
  101. package/dist/esm/utils/base64.js +18 -15
  102. package/dist/esm/utils/coerceType.js +11 -1
  103. package/dist/esm/utils/errors.js +41 -0
  104. package/dist/esm/utils/interpolation.js +44 -22
  105. package/dist/esm/utils/interpolationSyntax.js +15 -6
  106. package/dist/esm/utils/serialization/serialization.js +3 -2
  107. package/dist/esm/utils/serialization/serializationUtils.js +6 -0
  108. package/dist/esm/utils/serialization/serialization_v4.js +15 -3
  109. package/dist/esm/webAppRuntime.js +1 -0
  110. package/dist/types/api/createProcessor.d.ts +7 -1
  111. package/dist/types/exports.d.ts +4 -0
  112. package/dist/types/model/AgentResponseTrace.d.ts +15 -4
  113. package/dist/types/model/AgentResponseTracePresentation.d.ts +15 -0
  114. package/dist/types/model/CycleDetector.d.ts +1 -2
  115. package/dist/types/model/DataValue.d.ts +12 -8
  116. package/dist/types/model/ExecutorProtocol.d.ts +9 -0
  117. package/dist/types/model/GraphBoundaryCache.d.ts +2 -0
  118. package/dist/types/model/GraphBoundaryEffects.d.ts +10 -1
  119. package/dist/types/model/GraphExecutionState.d.ts +68 -0
  120. package/dist/types/model/GraphProcessor.d.ts +2 -0
  121. package/dist/types/model/GraphSchedulerBoundaryState.d.ts +96 -0
  122. package/dist/types/model/Nodes.d.ts +11 -4
  123. package/dist/types/model/ProcessContext.d.ts +24 -3
  124. package/dist/types/model/ProjectBundle.d.ts +59 -0
  125. package/dist/types/model/ProjectBundleRuntime.d.ts +24 -0
  126. package/dist/types/model/ProjectReferenceLoader.d.ts +3 -0
  127. package/dist/types/model/RivetUIContext.d.ts +1 -1
  128. package/dist/types/model/SchedulerBoundaryPlanner.d.ts +42 -0
  129. package/dist/types/model/Settings.d.ts +1 -0
  130. package/dist/types/model/StreamingWatchTopology.d.ts +11 -1
  131. package/dist/types/model/SubgraphProjectTarget.d.ts +38 -0
  132. package/dist/types/model/SubprocessorBridge.d.ts +2 -0
  133. package/dist/types/model/chat-v2/chatV2CredentialNames.d.ts +4 -0
  134. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +1 -1
  135. package/dist/types/model/chat-v2/chatV2ProviderRegistry.d.ts +79 -1
  136. package/dist/types/model/chat-v2/chatV2ProviderTypes.d.ts +1 -1
  137. package/dist/types/model/chat-v2/chatV2Shared.d.ts +1 -1
  138. package/dist/types/model/chat-v2/chatV2UsageAccounting.d.ts +2 -0
  139. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +4 -1
  140. package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +3 -1
  141. package/dist/types/model/chat-v2/llmInvocationCoordinator.d.ts +2 -0
  142. package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +2 -0
  143. package/dist/types/model/chat-v2/llmProfileFallback.d.ts +51 -3
  144. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +10 -7
  145. package/dist/types/model/chat-v2/llmProfileHealthStore.d.ts +6 -2
  146. package/dist/types/model/chat-v2/modelRegistry.d.ts +5 -4
  147. package/dist/types/model/chat-v2/openRouterModel.d.ts +2 -0
  148. package/dist/types/model/chat-v2/providerOptions.d.ts +2 -13
  149. package/dist/types/model/chat-v2/temperature.d.ts +2 -0
  150. package/dist/types/model/classifier/credentials.d.ts +7 -1
  151. package/dist/types/model/classifier/images.d.ts +18 -0
  152. package/dist/types/model/classifier/json.d.ts +19 -0
  153. package/dist/types/model/classifier/limits.d.ts +45 -0
  154. package/dist/types/model/classifier/openai.d.ts +5 -0
  155. package/dist/types/model/classifier/perplexity.d.ts +7 -0
  156. package/dist/types/model/classifier/preparation.d.ts +16 -0
  157. package/dist/types/model/classifier/profile.d.ts +46 -0
  158. package/dist/types/model/classifier/profileExecution.d.ts +32 -0
  159. package/dist/types/model/classifier/providers.d.ts +98 -9
  160. package/dist/types/model/classifier/questionHelpers.d.ts +6 -4
  161. package/dist/types/model/classifier/questions.d.ts +4 -0
  162. package/dist/types/model/classifier/response.d.ts +4 -0
  163. package/dist/types/model/classifier/state.d.ts +37 -0
  164. package/dist/types/model/classifier/types.d.ts +11 -0
  165. package/dist/types/model/nodeRunFailure.d.ts +13 -0
  166. package/dist/types/model/nodes/CatchStreamingChunksNode.d.ts +20 -0
  167. package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +17 -12
  168. package/dist/types/model/nodes/ClassifierProfileNode.d.ts +20 -0
  169. package/dist/types/model/nodes/GetGlobalNode.d.ts +7 -0
  170. package/dist/types/model/nodes/ImageNode.d.ts +4 -0
  171. package/dist/types/model/nodes/LLMChatV2Node.d.ts +1 -0
  172. package/dist/types/model/nodes/ObjectNode.d.ts +2 -1
  173. package/dist/types/model/nodes/StreamValueNode.d.ts +14 -0
  174. package/dist/types/model/nodes/SubGraphNode.d.ts +21 -2
  175. package/dist/types/model/nodes/ToBase64Node.d.ts +12 -0
  176. package/dist/types/model/nodes/toolCallDelegation.d.ts +3 -1
  177. package/dist/types/model/profileSuspensionHints.d.ts +8 -0
  178. package/dist/types/recording/ExecutionRecorder.d.ts +8 -2
  179. package/dist/types/serialization.d.ts +2 -0
  180. package/dist/types/utils/base64.d.ts +1 -1
  181. package/dist/types/utils/errors.d.ts +4 -0
  182. package/dist/types/utils/interpolation.d.ts +13 -2
  183. package/dist/types/utils/interpolationSyntax.d.ts +1 -1
  184. package/dist/types/utils/serialization/serialization.d.ts +3 -1
  185. package/dist/types/utils/serialization/serializationUtils.d.ts +1 -0
  186. package/dist/types/webAppRuntime.d.ts +1 -0
  187. package/package.json +7 -1
@@ -0,0 +1,64 @@
1
+ /** Invocation-owned boundary resources; no scheduling or event-emission policy. */
2
+ export class GraphSchedulerBoundaryState {
3
+ streamingWatchPlansBySourceNodeId = new Map();
4
+ streamingWatchPlansByWatchNodeId = new Map();
5
+ streamingOutputWatches = new Map();
6
+ streamingCatchPlansBySourceNodeId = new Map();
7
+ streamingCatchTasks = new Set();
8
+ graphOutputPartialBindingsBySourceNodeId = new Map();
9
+ graphInputStreams = {};
10
+ callerInputStreams = new Map();
11
+ inputStreamRoutes = new Map();
12
+ streamCallerTasks = new Set();
13
+ inputStreamDisposers = [];
14
+ pendingGraphInputFinals = new Map();
15
+ streamingWatchFailures = [];
16
+ resetTopology() {
17
+ this.streamingWatchPlansBySourceNodeId = new Map();
18
+ this.streamingWatchPlansByWatchNodeId = new Map();
19
+ this.streamingOutputWatches = new Map();
20
+ this.streamingCatchPlansBySourceNodeId = new Map();
21
+ this.streamingCatchTasks = new Set();
22
+ this.graphOutputPartialBindingsBySourceNodeId = new Map();
23
+ this.streamingWatchFailures = [];
24
+ }
25
+ /** Called after invocation initialization, before subscriptions can be admitted. */
26
+ initializeInputStreams(streams = {}) {
27
+ this.graphInputStreams = streams;
28
+ this.callerInputStreams = new Map();
29
+ this.inputStreamRoutes = new Map();
30
+ this.streamCallerTasks = new Set();
31
+ this.inputStreamDisposers = [];
32
+ this.pendingGraphInputFinals = new Map();
33
+ }
34
+ /** Release every subscription/relay, even if one host-provided disposer fails. */
35
+ releaseInputStreams() {
36
+ const failures = [];
37
+ const release = (operation) => {
38
+ try {
39
+ operation();
40
+ }
41
+ catch (error) {
42
+ failures.push(error);
43
+ }
44
+ };
45
+ for (const dispose of this.inputStreamDisposers.splice(0))
46
+ release(dispose);
47
+ this.pendingGraphInputFinals.clear();
48
+ for (const streams of this.callerInputStreams.values()) {
49
+ for (const relay of Object.values(streams))
50
+ release(() => relay.finish({ error: new Error('Graph input stream owner finished') }));
51
+ }
52
+ this.callerInputStreams.clear();
53
+ this.inputStreamRoutes.clear();
54
+ this.graphInputStreams = {};
55
+ if (failures.length)
56
+ throw new AggregateError(failures, 'Graph input stream cleanup failed');
57
+ }
58
+ async drainCatchTasks(waitForQueue) {
59
+ while (this.streamingCatchTasks.size > 0) {
60
+ await Promise.all([...this.streamingCatchTasks]);
61
+ await waitForQueue();
62
+ }
63
+ }
64
+ }
@@ -3,6 +3,7 @@ import { userInputNode } from './nodes/UserInputNode.js';
3
3
  export * from './nodes/UserInputNode.js';
4
4
  import { textNode } from './nodes/TextNode.js';
5
5
  export * from './nodes/TextNode.js';
6
+ export { buildNodeBodyPreview } from './nodes/nodeBodyPreview.js';
6
7
  import { chatNode } from './nodes/ChatNode.js';
7
8
  export * from './nodes/ChatNode.js';
8
9
  export * from './nodes/ChatNodeBase.js';
@@ -83,6 +84,10 @@ import { watchStreamingOutputNode } from './nodes/WatchStreamingOutputNode.js';
83
84
  export * from './nodes/WatchStreamingOutputNode.js';
84
85
  import { stopWatchingStreamingOutputNode } from './nodes/StopWatchingStreamingOutputNode.js';
85
86
  export * from './nodes/StopWatchingStreamingOutputNode.js';
87
+ import { streamValueNode } from './nodes/StreamValueNode.js';
88
+ export * from './nodes/StreamValueNode.js';
89
+ import { catchStreamingChunksNode } from './nodes/CatchStreamingChunksNode.js';
90
+ export * from './nodes/CatchStreamingChunksNode.js';
86
91
  import { popNode } from './nodes/PopNode.js';
87
92
  export * from './nodes/PopNode.js';
88
93
  import { setGlobalNode } from './nodes/SetGlobalNode.js';
@@ -125,6 +130,8 @@ import { raceInputsNode } from './nodes/RaceInputsNode.js';
125
130
  export * from './nodes/RaceInputsNode.js';
126
131
  import { toJsonNode } from './nodes/ToJsonNode.js';
127
132
  export * from './nodes/ToJsonNode.js';
133
+ import { toBase64Node } from './nodes/ToBase64Node.js';
134
+ export * from './nodes/ToBase64Node.js';
128
135
  import { joinNode } from './nodes/JoinNode.js';
129
136
  export * from './nodes/JoinNode.js';
130
137
  import { filterNode } from './nodes/FilterNode.js';
@@ -220,6 +227,10 @@ export * from './nodes/NodePrefabInstanceNode.js';
220
227
  import { classifierQuestionNode } from './nodes/ClassifierQuestionNode.js';
221
228
  export * from './nodes/ClassifierQuestionNode.js';
222
229
  import { classifierEvaluateNode } from './nodes/ClassifierEvaluateNode.js';
230
+ import { classifierProfileNode } from './nodes/ClassifierProfileNode.js';
231
+ export * from './nodes/ClassifierProfileNode.js';
232
+ export * from './classifier/profile.js';
233
+ export { classifierFailureKinds } from './classifier/types.js';
223
234
  export * from './nodes/ClassifierEvaluateNode.js';
224
235
  export const registerBuiltInNodes = (registry) => {
225
236
  return registry
@@ -265,6 +276,8 @@ export const registerBuiltInNodes = (registry) => {
265
276
  .register(startBackgroundBranchNode)
266
277
  .register(watchStreamingOutputNode)
267
278
  .register(stopWatchingStreamingOutputNode)
279
+ .register(streamValueNode)
280
+ .register(catchStreamingChunksNode)
268
281
  .register(popNode)
269
282
  .register(setGlobalNode)
270
283
  .register(getGlobalNode)
@@ -285,6 +298,7 @@ export const registerBuiltInNodes = (registry) => {
285
298
  .register(abortGraphNode)
286
299
  .register(raceInputsNode)
287
300
  .register(toJsonNode)
301
+ .register(toBase64Node)
288
302
  .register(joinNode)
289
303
  .register(filterNode)
290
304
  .register(jsFilterNode)
@@ -332,6 +346,7 @@ export const registerBuiltInNodes = (registry) => {
332
346
  .register(referencedGraphAliasNode)
333
347
  .register(classifierQuestionNode)
334
348
  .register(classifierEvaluateNode)
349
+ .register(classifierProfileNode)
335
350
  .register(nodePrefabInstanceNode);
336
351
  };
337
352
  let globalRivetNodeRegistry = registerBuiltInNodes(new NodeRegistration());
@@ -0,0 +1,248 @@
1
+ import { getSubgraphTargetBoundaryIssue } from './nodes/SubGraphNode.js';
2
+ import { getGraphBoundary } from './GraphBoundaryCache.js';
3
+ import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
4
+ import { findStronglyConnectedComponents } from './CycleDetector.js';
5
+ /** Deliberate, user-facing bundle validation failures; never raw storage errors. */
6
+ export class ProjectBundleError extends Error {
7
+ constructor(message, options) {
8
+ super(message, options);
9
+ this.name = 'ProjectBundleError';
10
+ }
11
+ }
12
+ export const PROJECT_BUNDLE_MANIFEST = 'rivet-bundle.json';
13
+ export const PROJECT_BUNDLE_MAX_ARTIFACTS = 256;
14
+ export const PROJECT_BUNDLE_MAX_MANIFEST_BYTES = 1024 * 1024;
15
+ export function projectBundleTargetKey(projectId, version) {
16
+ return JSON.stringify([projectId, version]);
17
+ }
18
+ function samePluginRequirement(left, right) {
19
+ if (left.id !== right.id || left.type !== right.type)
20
+ return false;
21
+ if (left.type === 'built-in')
22
+ return true; // Display names are not runtime identity.
23
+ if (left.type === 'package' && right.type === 'package')
24
+ return left.package === right.package && left.tag === right.tag;
25
+ return left.type === 'uri' && right.type === 'uri' && left.uri === right.uri;
26
+ }
27
+ function* projectSubgraphs(project) {
28
+ for (const [sourceGraphId, graph] of Object.entries(project.graphs)) {
29
+ for (const authored of graph.nodes) {
30
+ const node = resolveNodePrefabInstance(project, authored);
31
+ if (!node.disabled && node.type === 'nodePrefabInstance')
32
+ throw new ProjectBundleError(`Bundle contains an unresolved library node ${node.id}.`);
33
+ if (node.disabled || node.type !== 'subGraph')
34
+ continue;
35
+ const data = node.data;
36
+ if (data.targetProjectId) {
37
+ if (data.targetVersion !== undefined && data.targetVersion !== 'latest' && data.targetVersion !== 'published')
38
+ throw new ProjectBundleError('Invalid Subgraph project version.');
39
+ }
40
+ else if (data.targetScope === 'other-projects') {
41
+ throw new ProjectBundleError(`Subgraph ${node.title || node.id} has no selected project.`);
42
+ }
43
+ yield { sourceGraphId, data };
44
+ }
45
+ }
46
+ }
47
+ export function listProjectBundleCalls(project) {
48
+ const calls = [];
49
+ for (const { data } of projectSubgraphs(project)) {
50
+ if (data.targetProjectId)
51
+ calls.push({
52
+ projectId: data.targetProjectId,
53
+ version: data.targetVersion ?? 'latest',
54
+ graphId: data.graphId,
55
+ boundary: data.targetBoundary,
56
+ });
57
+ }
58
+ return calls;
59
+ }
60
+ /** Uses the same saved wire contract as runtime execution, without running any nodes. */
61
+ export function validateProjectBundleCall(call, target) {
62
+ if (!Object.hasOwn(target.graphs, call.graphId))
63
+ throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}.`);
64
+ const boundary = getGraphBoundary(target, call.graphId);
65
+ if (!boundary)
66
+ throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}.`);
67
+ const issue = getSubgraphTargetBoundaryIssue(call.boundary, boundary);
68
+ if (issue)
69
+ throw new ProjectBundleError(`Subgraph dependency has an incompatible boundary. ${issue}`);
70
+ }
71
+ /** Reject missing bindings and cross-project dependency cycles before executing any graph. */
72
+ export function validateProjectBundleProjects(manifest, projects) {
73
+ const targets = new Map(manifest.targets.map((t) => [projectBundleTargetKey(t.projectId, t.version), t.artifact]));
74
+ const references = new Map(manifest.references.map((r) => [r.projectId, r.artifact]));
75
+ const plugins = new Map(manifest.plugins.map((plugin) => [plugin.id, plugin]));
76
+ const vertices = new Map();
77
+ const graphKey = (artifact, graph) => JSON.stringify([artifact, graph]);
78
+ for (const artifact of manifest.artifacts) {
79
+ const project = projects.get(artifact.id);
80
+ if (!project || project.metadata.id !== artifact.projectId)
81
+ throw new ProjectBundleError('Bundle project identity mismatch.');
82
+ for (const requirement of project.plugins ?? []) {
83
+ const declared = plugins.get(requirement.id);
84
+ if (!declared || !samePluginRequirement(declared, requirement))
85
+ throw new ProjectBundleError(`Bundle is missing the required plugin declaration ${requirement.id}.`);
86
+ }
87
+ for (const graphId of Object.keys(project.graphs))
88
+ vertices.set(graphKey(artifact.id, graphId), { edges: [] });
89
+ }
90
+ for (const artifact of manifest.artifacts) {
91
+ const project = projects.get(artifact.id);
92
+ for (const { sourceGraphId, data } of projectSubgraphs(project)) {
93
+ let targetId = artifact.id;
94
+ if (data.targetProjectId) {
95
+ const call = {
96
+ projectId: data.targetProjectId,
97
+ version: data.targetVersion ?? 'latest',
98
+ graphId: data.graphId,
99
+ boundary: data.targetBoundary,
100
+ };
101
+ const id = targets.get(projectBundleTargetKey(call.projectId, call.version));
102
+ const target = id && projects.get(id);
103
+ if (!id || !target)
104
+ throw new ProjectBundleError(`Bundle is missing Subgraph ${call.projectId}:${call.version}:${call.graphId}`);
105
+ validateProjectBundleCall(call, target);
106
+ targetId = id;
107
+ }
108
+ const target = vertices.get(graphKey(targetId, data.graphId));
109
+ if (target)
110
+ vertices.get(graphKey(artifact.id, sourceGraphId)).edges.push({
111
+ target,
112
+ crossProject: Boolean(data.targetProjectId),
113
+ });
114
+ }
115
+ for (const reference of project.references ?? []) {
116
+ if (!references.has(reference.id))
117
+ throw new ProjectBundleError(`Bundle is missing referenced project ${reference.id}`);
118
+ }
119
+ for (const [sourceGraphId, graph] of Object.entries(project.graphs)) {
120
+ for (const authored of graph.nodes) {
121
+ const node = resolveNodePrefabInstance(project, authored);
122
+ if (node.disabled || node.type !== 'referencedGraphAlias')
123
+ continue;
124
+ const { projectId, graphId } = node.data;
125
+ const targetId = references.get(projectId);
126
+ const target = targetId && vertices.get(graphKey(targetId, graphId));
127
+ if (!target)
128
+ throw new ProjectBundleError(`Bundle is missing referenced graph ${projectId}:${graphId}`);
129
+ // Legacy-only recursion keeps its existing semantics, but aliases can
130
+ // participate in a cycle containing an explicit cross-project call.
131
+ vertices.get(graphKey(artifact.id, sourceGraphId)).edges.push({ target, crossProject: false });
132
+ }
133
+ }
134
+ }
135
+ // Project-level cycles can be legitimate: A/main → B/main → A/helper.
136
+ // Reject only a recursive graph-call component containing a cross-project edge.
137
+ for (const component of findStronglyConnectedComponents([...vertices.values()], (v) => v.edges.map((e) => e.target))) {
138
+ const members = new Set(component);
139
+ if (component.some((v) => v.edges.some((e) => e.crossProject && members.has(e.target))))
140
+ throw new ProjectBundleError('Subgraph cross-project dependency cycle in bundle.');
141
+ }
142
+ }
143
+ export function validateProjectBundleManifest(value) {
144
+ const fail = (message) => {
145
+ throw new ProjectBundleError(`Invalid project bundle: ${message}`);
146
+ };
147
+ const object = (v) => v !== null && typeof v === 'object' && !Array.isArray(v) ? v : fail('expected object');
148
+ const string = (v) => typeof v === 'string' && v.length > 0 && v.length <= 4096 ? v : fail('expected nonempty string');
149
+ const array = (v, limit = PROJECT_BUNDLE_MAX_ARTIFACTS) => Array.isArray(v) && v.length <= limit ? v : fail('invalid or oversized list');
150
+ const version = (v) => v === 'latest' || v === 'published' ? v : fail('unknown project version');
151
+ const paths = new Set();
152
+ const file = (v) => {
153
+ const obj = object(v), path = string(obj.path);
154
+ if (path.includes('\\') ||
155
+ path.includes(':') ||
156
+ path.includes('\0') ||
157
+ path.startsWith('/') ||
158
+ path.split('/').some((part) => !part || part === '.' || part === '..') ||
159
+ paths.has(path.toLowerCase()))
160
+ fail('unsafe or duplicate artifact path');
161
+ paths.add(path.toLowerCase());
162
+ // Old bundles carry export-time sizes/hashes. Ignore them: edited files are
163
+ // supported, and the loader enforces resource limits against actual bytes.
164
+ return { path };
165
+ };
166
+ const obj = object(value);
167
+ if (obj.format !== 'rivet-project-bundle' ||
168
+ obj.schemaVersion !== 1 ||
169
+ (obj.requiredLoaderVersion !== 1 && obj.requiredLoaderVersion !== 2 && obj.requiredLoaderVersion !== 3))
170
+ fail('unsupported format or loader version; update @valerypopoff/rivet2-node');
171
+ const versionPolicy = obj.versionPolicy === undefined ? undefined : version(obj.versionPolicy);
172
+ if (versionPolicy && obj.requiredLoaderVersion !== 3)
173
+ fail('version selection requires loader version 3');
174
+ if (obj.requiredLoaderVersion === 3 && !versionPolicy)
175
+ fail('loader version 3 requires a version selection');
176
+ const artifacts = array(obj.artifacts).map((v) => {
177
+ const a = object(v);
178
+ return {
179
+ id: string(a.id),
180
+ projectId: string(a.projectId),
181
+ title: string(a.title),
182
+ version: version(a.version),
183
+ revision: string(a.revision),
184
+ project: file(a.project),
185
+ ...(a.datasets === undefined ? {} : { datasets: file(a.datasets) }),
186
+ };
187
+ });
188
+ const byId = new Map(artifacts.map((a) => [a.id, a]));
189
+ if (!artifacts.length || byId.size !== artifacts.length)
190
+ fail('empty or duplicate artifacts');
191
+ if (new Set(artifacts.map((a) => projectBundleTargetKey(a.projectId, a.version))).size !== artifacts.length)
192
+ fail('duplicate project/version artifacts');
193
+ if (versionPolicy && new Set(artifacts.map((a) => a.projectId)).size !== artifacts.length)
194
+ fail('version-selected bundles must contain one artifact per project');
195
+ if (versionPolicy === 'latest' && artifacts.some((a) => a.version !== 'latest'))
196
+ fail('latest version policy contains a published artifact');
197
+ const rootArtifact = string(obj.rootArtifact);
198
+ if (!byId.has(rootArtifact))
199
+ fail('missing root artifact');
200
+ const targetKeys = new Set(), referenceIds = new Set();
201
+ // A version-selected artifact has both latest and published bindings. The
202
+ // project limit must not accidentally halve when those aliases are emitted.
203
+ const targets = array(obj.targets, PROJECT_BUNDLE_MAX_ARTIFACTS * 2).map((v) => {
204
+ const t = object(v), projectId = string(t.projectId), selectedVersion = version(t.version), artifact = string(t.artifact);
205
+ const key = projectBundleTargetKey(projectId, selectedVersion), a = byId.get(artifact);
206
+ if (targetKeys.has(key) || !a || a.projectId !== projectId || (!versionPolicy && a.version !== selectedVersion))
207
+ fail('invalid or duplicate target binding');
208
+ targetKeys.add(key);
209
+ return { projectId, version: selectedVersion, artifact };
210
+ });
211
+ const references = array(obj.references).map((v) => {
212
+ const r = object(v), projectId = string(r.projectId), artifact = string(r.artifact);
213
+ if (referenceIds.has(projectId) || byId.get(artifact)?.projectId !== projectId)
214
+ fail('invalid or duplicate reference binding');
215
+ referenceIds.add(projectId);
216
+ return { projectId, artifact };
217
+ });
218
+ const pluginSpecs = array(obj.plugins).map((v) => {
219
+ const p = object(v), id = string(p.id);
220
+ if (p.type === 'built-in')
221
+ return { type: p.type, id, name: string(p.name) };
222
+ if (p.type === 'package')
223
+ return { type: p.type, id, package: string(p.package), tag: string(p.tag) };
224
+ if (p.type === 'uri')
225
+ return { type: p.type, id, uri: string(p.uri) };
226
+ return fail('invalid plugin requirement');
227
+ });
228
+ const pluginsById = new Map();
229
+ for (const plugin of pluginSpecs) {
230
+ const previous = pluginsById.get(plugin.id);
231
+ if (previous && !samePluginRequirement(previous, plugin))
232
+ fail(`conflicting requirements for plugin ${plugin.id}`);
233
+ if (!previous)
234
+ pluginsById.set(plugin.id, plugin);
235
+ }
236
+ return {
237
+ format: 'rivet-project-bundle',
238
+ schemaVersion: 1,
239
+ requiredLoaderVersion: obj.requiredLoaderVersion,
240
+ ...(versionPolicy ? { versionPolicy } : {}),
241
+ exportingRuntimeVersion: string(obj.exportingRuntimeVersion),
242
+ rootArtifact,
243
+ artifacts,
244
+ targets,
245
+ references,
246
+ plugins: [...pluginsById.values()],
247
+ };
248
+ }
@@ -0,0 +1,54 @@
1
+ import { InMemoryDatasetProvider } from '../integrations/DatasetProvider.js';
2
+ import { ProjectBundleError, projectBundleTargetKey, validateProjectBundleProjects, } from './ProjectBundle.js';
3
+ /** One isolated dependency/data universe per run. The visible entry project may override its disk copy. */
4
+ export function createProjectBundleRuntime(manifest, snapshots, options = {}) {
5
+ const entryId = options.artifactId ?? manifest.rootArtifact;
6
+ const entry = manifest.artifacts.find((artifact) => artifact.id === entryId);
7
+ if (!entry)
8
+ throw new ProjectBundleError('The selected project is not a member of this bundle.');
9
+ if (options.project && options.project.metadata.id !== entry.projectId)
10
+ throw new ProjectBundleError('The open project identity no longer matches its bundle entry.');
11
+ const runtime = new Map(manifest.artifacts.map((artifact) => {
12
+ const snapshot = snapshots.get(artifact.id);
13
+ if (!snapshot)
14
+ throw new ProjectBundleError(`Bundle is missing artifact ${artifact.id}.`);
15
+ const project = structuredClone(artifact.id === entryId && options.project ? options.project : snapshot.project);
16
+ return [
17
+ artifact.id,
18
+ {
19
+ project,
20
+ sourceProjectPath: snapshot.sourceProjectPath,
21
+ datasetProvider: artifact.id === entryId && options.datasetProvider
22
+ ? options.datasetProvider
23
+ : new InMemoryDatasetProvider(structuredClone(snapshot.datasets)),
24
+ },
25
+ ];
26
+ }));
27
+ validateProjectBundleProjects(manifest, new Map([...runtime].map(([id, snapshot]) => [id, snapshot.project])));
28
+ const targets = new Map(manifest.targets.map((target) => [projectBundleTargetKey(target.projectId, target.version), target.artifact]));
29
+ const references = new Map(manifest.references.map((reference) => [reference.projectId, reference.artifact]));
30
+ const providers = new Map([...runtime.values()].map((snapshot) => [snapshot.project, snapshot.datasetProvider]));
31
+ const root = runtime.get(entryId);
32
+ return {
33
+ project: root.project,
34
+ projectPath: root.sourceProjectPath,
35
+ datasetProvider: root.datasetProvider,
36
+ projectReferenceLoader: {
37
+ getDatasetProvider: (project) => providers.get(project),
38
+ async loadProject(_path, reference) {
39
+ const id = references.get(reference.id);
40
+ if (!id)
41
+ throw new ProjectBundleError(`Bundle has no reference binding for ${reference.id}.`);
42
+ return runtime.get(id).project;
43
+ },
44
+ },
45
+ subgraphProjectLoader: {
46
+ async loadTarget(target) {
47
+ const id = targets.get(projectBundleTargetKey(target.projectId, target.version));
48
+ if (!id)
49
+ throw new ProjectBundleError(`Bundle has no target binding for ${target.projectId}:${target.version}.`);
50
+ return runtime.get(id);
51
+ },
52
+ },
53
+ };
54
+ }
@@ -0,0 +1,233 @@
1
+ function indexConnections(connections) {
2
+ const outgoingByNodeId = new Map();
3
+ const incomingByNodeId = new Map();
4
+ for (const connection of connections) {
5
+ const outgoing = outgoingByNodeId.get(connection.outputNodeId) ?? [];
6
+ outgoing.push(connection);
7
+ outgoingByNodeId.set(connection.outputNodeId, outgoing);
8
+ const incoming = incomingByNodeId.get(connection.inputNodeId) ?? [];
9
+ incoming.push(connection);
10
+ incomingByNodeId.set(connection.inputNodeId, incoming);
11
+ }
12
+ return { outgoingByNodeId, incomingByNodeId };
13
+ }
14
+ export function getAsyncBranchWatchViolation(triggerNode, enclosingWatchNode) {
15
+ if (!enclosingWatchNode)
16
+ return undefined;
17
+ return new Error(`Start Async Branch "${triggerNode.title}" cannot run inside Watch Streaming Output "${enclosingWatchNode.title}". ` +
18
+ 'A Watch invocation must keep all work within the Watch scheduler. Move Start Async Branch after Stop Watching Streaming Output, or run the work directly inside the watched branch.');
19
+ }
20
+ export function* planStreamingWatchTopology(options) {
21
+ const connections = options.connections;
22
+ const { outgoingByNodeId, incomingByNodeId } = indexConnections(connections);
23
+ const relevantNodeIds = options.relevantNodeIds;
24
+ const isRelevant = (nodeId) => !relevantNodeIds || relevantNodeIds.has(nodeId);
25
+ for (const watchNode of Object.values(options.nodesById)) {
26
+ if (watchNode.type !== 'watchStreamingOutput' || watchNode.disabled || !isRelevant(watchNode.id)) {
27
+ continue;
28
+ }
29
+ if (watchNode.id === options.consumedWatchNodeId) {
30
+ continue;
31
+ }
32
+ const enclosingWatchInvocation = options.enclosingWatchNode;
33
+ if (enclosingWatchInvocation) {
34
+ throw new Error(`Watch Streaming Output "${watchNode.title}" cannot run inside Watch Streaming Output ` +
35
+ `"${enclosingWatchInvocation.title}". A Watch branch cannot contain another Watch, including through Subgraph.`);
36
+ }
37
+ if (options.preloadedNodes.has(watchNode.id)) {
38
+ throw new Error(`Cannot preload ${watchNode.title} because a streaming boundary must be scheduled. ` +
39
+ "Run from Watch Streaming Output to reuse a producer's saved final value, or run from the producer to stream again.");
40
+ }
41
+ const incoming = incomingByNodeId.get(watchNode.id) ?? [];
42
+ if (incoming.length === 0) {
43
+ // An unattached Watch is an ordinary in-progress authoring state. Keep
44
+ // it dormant rather than making an incomplete canvas fail to run.
45
+ yield { kind: 'dormant', watchNode };
46
+ continue;
47
+ }
48
+ if (incoming.length !== 1 || incoming[0].inputId !== 'stream') {
49
+ throw new Error(`Watch Streaming Output "${watchNode.title}" must have exactly one Streaming Output input connection.`);
50
+ }
51
+ const sourceConnection = incoming[0];
52
+ const sourceNode = options.nodesById[sourceConnection.outputNodeId];
53
+ if (!sourceNode || sourceNode.disabled || !isRelevant(sourceNode.id)) {
54
+ throw new Error(`Watch Streaming Output "${watchNode.title}" has no runnable streaming source.`);
55
+ }
56
+ if (sourceNode.isSplitRun) {
57
+ throw new Error(`Watch Streaming Output "${watchNode.title}" cannot watch split-run node "${sourceNode.title}". ` +
58
+ 'Assemble a single streaming value before the watch boundary.');
59
+ }
60
+ const branchNodeIds = new Set();
61
+ const pendingNodeIds = (outgoingByNodeId.get(watchNode.id) ?? [])
62
+ .map((connection) => connection.inputNodeId)
63
+ .filter(isRelevant);
64
+ let stopNodeId;
65
+ while (pendingNodeIds.length > 0) {
66
+ const nodeId = pendingNodeIds.pop();
67
+ if (nodeId === watchNode.id) {
68
+ throw new Error(`Watch Streaming Output "${watchNode.title}" cannot reconnect to itself.`);
69
+ }
70
+ if (branchNodeIds.has(nodeId)) {
71
+ continue;
72
+ }
73
+ const node = options.nodesById[nodeId];
74
+ if (!node || !isRelevant(nodeId)) {
75
+ continue;
76
+ }
77
+ if (node.disabled) {
78
+ throw new Error(`Watch Streaming Output "${watchNode.title}" cannot include disabled node "${node.title}".`);
79
+ }
80
+ if (node.type === 'watchStreamingOutput') {
81
+ throw new Error(`Watch Streaming Output "${watchNode.title}" cannot contain another Watch Streaming Output node.`);
82
+ }
83
+ if (node.type === 'catchStreamingChunks') {
84
+ throw new Error(`Watch Streaming Output "${watchNode.title}" cannot contain Catch streaming chunks "${node.title}". ` +
85
+ 'Put Catch streaming chunks outside the repeated Watch branch.');
86
+ }
87
+ if (node.type === 'graphOutput') {
88
+ throw new Error(`Watch Streaming Output "${watchNode.title}" must reach Stop Watching Streaming Output before Graph Output "${node.title}".`);
89
+ }
90
+ if (node.type === 'startBackgroundBranch') {
91
+ throw new Error(`Watch Streaming Output "${watchNode.title}" cannot contain Start Async Branch. ` +
92
+ 'Keep watched work in the bounded watch branch instead.');
93
+ }
94
+ branchNodeIds.add(nodeId);
95
+ if (node.type === 'stopWatchingStreamingOutput') {
96
+ if (stopNodeId && stopNodeId !== nodeId) {
97
+ throw new Error(`Watch Streaming Output "${watchNode.title}" must have one Stop Watching Streaming Output boundary.`);
98
+ }
99
+ stopNodeId = nodeId;
100
+ continue;
101
+ }
102
+ for (const connection of outgoingByNodeId.get(nodeId) ?? []) {
103
+ if (isRelevant(connection.inputNodeId)) {
104
+ pendingNodeIds.push(connection.inputNodeId);
105
+ }
106
+ }
107
+ }
108
+ if (branchNodeIds.size === 0) {
109
+ // Source -> Watch is also a useful intermediate authoring state. There
110
+ // is no downstream work to schedule yet, so do not create a coordinator.
111
+ yield { kind: 'dormant', watchNode };
112
+ continue;
113
+ }
114
+ if (stopNodeId) {
115
+ const reentry = (outgoingByNodeId.get(stopNodeId) ?? []).find((connection) => connection.inputNodeId === watchNode.id || branchNodeIds.has(connection.inputNodeId));
116
+ if (reentry) {
117
+ const stopNode = options.nodesById[stopNodeId];
118
+ throw new Error(`Stop Watching Streaming Output "${stopNode.title}" cannot reconnect to its own Watch Streaming Output branch. ` +
119
+ 'Connect it only to ordinary downstream execution.');
120
+ }
121
+ }
122
+ for (const nodeId of branchNodeIds) {
123
+ const externalInput = (incomingByNodeId.get(nodeId) ?? []).find((connection) => connection.outputNodeId !== watchNode.id && !branchNodeIds.has(connection.outputNodeId));
124
+ if (externalInput) {
125
+ const node = options.nodesById[nodeId];
126
+ const externalNode = options.nodesById[externalInput.outputNodeId];
127
+ throw new Error(`Watch Streaming Output "${watchNode.title}" cannot run "${node.title}" because it also depends on ` +
128
+ `"${externalNode?.title ?? externalInput.outputNodeId}" outside the watch branch. ` +
129
+ 'Assemble every required value inside the watch boundary.');
130
+ }
131
+ }
132
+ const graph = {
133
+ metadata: options.graph.metadata ? { ...options.graph.metadata } : undefined,
134
+ nodes: options.executionNodes.filter((node) => node.id === watchNode.id || branchNodeIds.has(node.id)),
135
+ connections: connections.filter((connection) => connection.inputNodeId === watchNode.id ||
136
+ (branchNodeIds.has(connection.inputNodeId) &&
137
+ (connection.outputNodeId === watchNode.id || branchNodeIds.has(connection.outputNodeId)))),
138
+ };
139
+ yield {
140
+ kind: 'watch',
141
+ graph,
142
+ watchNode,
143
+ branchNodeIds,
144
+ sourceNodeId: sourceNode.id,
145
+ sourceOutputId: sourceConnection.outputId,
146
+ stopNodeId,
147
+ includeAllStreamedOutput: connections.some((connection) => connection.outputNodeId === watchNode.id &&
148
+ connection.outputId === 'allStreamedOutput' &&
149
+ branchNodeIds.has(connection.inputNodeId)),
150
+ };
151
+ }
152
+ }
153
+ export function* planAsyncBranchTopology(options) {
154
+ const connections = options.connections;
155
+ const { outgoingByNodeId, incomingByNodeId } = indexConnections(connections);
156
+ const relevantNodeIds = options.relevantNodeIds;
157
+ const isRelevant = (nodeId) => !relevantNodeIds || relevantNodeIds.has(nodeId);
158
+ for (const triggerNode of Object.values(options.nodesById)) {
159
+ // Input anchors describe the consumed trigger's ports, not executable work.
160
+ // A variadic anchor may itself be an outer async trigger.
161
+ if (options.inputAnchorNodeIds?.has(triggerNode.id))
162
+ continue;
163
+ if (triggerNode.type !== 'startBackgroundBranch' || triggerNode.disabled || !isRelevant(triggerNode.id)) {
164
+ continue;
165
+ }
166
+ if (triggerNode.id !== options.consumedTriggerNodeId && options.preloadedNodes.has(triggerNode.id)) {
167
+ throw new Error(`Start Async Branch "${triggerNode.title}" cannot use preloaded outputs because replaying it could repeat async side effects.`);
168
+ }
169
+ const nodeIds = new Set();
170
+ const pendingNodeIds = (outgoingByNodeId.get(triggerNode.id) ?? [])
171
+ .map((connection) => connection.inputNodeId)
172
+ .filter(isRelevant);
173
+ while (pendingNodeIds.length > 0) {
174
+ const nodeId = pendingNodeIds.pop();
175
+ if (nodeId === triggerNode.id) {
176
+ throw new Error(`Start Async Branch "${triggerNode.title}" cannot be part of a cycle or reconnect to its own inputs.`);
177
+ }
178
+ if (nodeIds.has(nodeId)) {
179
+ continue;
180
+ }
181
+ const node = options.nodesById[nodeId];
182
+ if (!node) {
183
+ continue;
184
+ }
185
+ if (node.disabled) {
186
+ continue;
187
+ }
188
+ if (node.type === 'graphOutput') {
189
+ throw new Error(`Start Async Branch "${triggerNode.title}" cannot contain Graph Output node "${node.title}". Async branches are side-effect-only.`);
190
+ }
191
+ nodeIds.add(nodeId);
192
+ for (const connection of outgoingByNodeId.get(nodeId) ?? []) {
193
+ if (isRelevant(connection.inputNodeId)) {
194
+ pendingNodeIds.push(connection.inputNodeId);
195
+ }
196
+ }
197
+ }
198
+ for (const nodeId of nodeIds) {
199
+ const externalInput = (incomingByNodeId.get(nodeId) ?? []).find((connection) => connection.outputNodeId !== triggerNode.id && !nodeIds.has(connection.outputNodeId));
200
+ if (externalInput) {
201
+ const node = options.nodesById[nodeId];
202
+ const externalNode = options.nodesById[externalInput.outputNodeId];
203
+ throw new Error(`Start Async Branch "${triggerNode.title}" cannot run "${node.title}" because it also depends on ` +
204
+ `"${externalNode?.title ?? externalInput.outputNodeId}" outside the async branch. Assemble all required values before the async trigger.`);
205
+ }
206
+ }
207
+ if (nodeIds.size === 0) {
208
+ continue;
209
+ }
210
+ const managedAsyncBranchWatchViolation = getAsyncBranchWatchViolation(triggerNode, options.enclosingWatchNode);
211
+ if (managedAsyncBranchWatchViolation) {
212
+ throw managedAsyncBranchWatchViolation;
213
+ }
214
+ const preloadedNodeId = [...nodeIds].find((nodeId) => options.preloadedNodes.has(nodeId));
215
+ if (preloadedNodeId) {
216
+ const preloadedNode = options.nodesById[preloadedNodeId];
217
+ throw new Error(`Start Async Branch "${triggerNode.title}" cannot contain preloaded node "${preloadedNode.title}". Preloading an async descendant would bypass the trigger boundary.`);
218
+ }
219
+ // The node derives its variadic output definitions from connected inputs.
220
+ // Retain shallow input anchors in the slice even though the trigger itself is preloaded.
221
+ const triggerInputConnections = connections.filter((connection) => connection.inputNodeId === triggerNode.id);
222
+ const inputAnchorNodeIds = new Set(triggerInputConnections.map((connection) => connection.outputNodeId));
223
+ const includedNodeIds = new Set([triggerNode.id, ...nodeIds, ...inputAnchorNodeIds]);
224
+ const graph = {
225
+ metadata: options.graph.metadata ? { ...options.graph.metadata } : undefined,
226
+ nodes: options.executionNodes.filter((node) => includedNodeIds.has(node.id)),
227
+ connections: connections.filter((connection) => connection.inputNodeId === triggerNode.id ||
228
+ (nodeIds.has(connection.inputNodeId) &&
229
+ (connection.outputNodeId === triggerNode.id || nodeIds.has(connection.outputNodeId)))),
230
+ };
231
+ yield { triggerNode, graph, nodeIds };
232
+ }
233
+ }