@valerypopoff/rivet2-core 2.13.0 → 2.17.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.
- package/dist/cjs/bundle.cjs +28167 -23834
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/interpolationRuntime.cjs +22 -3
- package/dist/cjs/interpolationRuntime.cjs.map +3 -3
- package/dist/cjs/interpolationSyntax.cjs +9 -5
- package/dist/cjs/interpolationSyntax.cjs.map +2 -2
- package/dist/esm/api/createProcessor.js +10 -2
- package/dist/esm/api/processSettings.js +1 -0
- package/dist/esm/exports.js +6 -0
- package/dist/esm/model/GraphBoundaryCache.js +2 -1
- package/dist/esm/model/GraphProcessor.js +278 -22
- package/dist/esm/model/MarkdownSanitizationPolicy.js +2 -0
- package/dist/esm/model/NodeImpl.js +1 -1
- package/dist/esm/model/Nodes.js +16 -0
- package/dist/esm/model/ProjectBundle.js +235 -0
- package/dist/esm/model/SplitRunProcessor.js +28 -7
- package/dist/esm/model/StreamingWatchTopology.js +211 -64
- package/dist/esm/model/SubgraphProjectTarget.js +7 -0
- package/dist/esm/model/chat-v2/aiSdkBridge.js +7 -5
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +13 -8
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +19 -1
- package/dist/esm/model/chat-v2/chatV2Shared.js +2 -1
- package/dist/esm/model/chat-v2/llmChatV2Body.js +11 -8
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +2 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +15 -1
- package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +22 -2
- package/dist/esm/model/chat-v2/llmProfile.js +3 -0
- package/dist/esm/model/chat-v2/llmProfileBody.js +2 -2
- package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +1 -1
- package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +1 -1
- package/dist/esm/model/chat-v2/temperature.js +9 -0
- package/dist/esm/model/classifier/credentials.js +107 -0
- package/dist/esm/model/classifier/images.js +176 -0
- package/dist/esm/model/classifier/json.js +57 -0
- package/dist/esm/model/classifier/limits.js +270 -0
- package/dist/esm/model/classifier/migration.js +97 -0
- package/dist/esm/model/classifier/openai.js +118 -0
- package/dist/esm/model/classifier/preparation.js +74 -0
- package/dist/esm/model/classifier/providers.js +422 -0
- package/dist/esm/model/classifier/questionHelpers.js +109 -0
- package/dist/esm/model/classifier/questions.js +53 -0
- package/dist/esm/model/classifier/response.js +75 -0
- package/dist/esm/model/classifier/state.js +204 -0
- package/dist/esm/model/classifier/types.js +1 -0
- package/dist/esm/model/nodeBodyMarkdown.js +37 -0
- package/dist/esm/model/nodeRunFailure.js +47 -0
- package/dist/esm/model/nodes/CatchStreamingChunksNode.js +42 -0
- package/dist/esm/model/nodes/ClassifierEvaluateNode.js +432 -0
- package/dist/esm/model/nodes/ClassifierQuestionNode.js +613 -0
- package/dist/esm/model/nodes/CodeNewNode.js +33 -9
- package/dist/esm/model/nodes/GetGlobalNode.js +2 -2
- package/dist/esm/model/nodes/HttpCallNode.js +44 -75
- package/dist/esm/model/nodes/ImageNode.js +44 -3
- package/dist/esm/model/nodes/LLMChatV2Node.js +27 -15
- package/dist/esm/model/nodes/LLMProfileNode.js +6 -12
- package/dist/esm/model/nodes/MatchCaseNode.js +76 -1
- package/dist/esm/model/nodes/MatchCaseNodeBase.js +24 -2
- package/dist/esm/model/nodes/ObjectNode.js +68 -50
- package/dist/esm/model/nodes/PassthroughNode.js +1 -1
- package/dist/esm/model/nodes/PromptNode.js +2 -1
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +4 -1
- package/dist/esm/model/nodes/SetGlobalNode.js +5 -3
- package/dist/esm/model/nodes/StopWatchingStreamingOutputNode.js +8 -8
- package/dist/esm/model/nodes/StreamValueNode.js +38 -0
- package/dist/esm/model/nodes/SubGraphNode.js +196 -35
- package/dist/esm/model/nodes/ToBase64Node.js +106 -0
- package/dist/esm/model/nodes/WatchStreamingOutputNode.js +7 -7
- package/dist/esm/model/nodes/codeOutputInference.js +292 -0
- package/dist/esm/recording/ExecutionRecorder.js +26 -0
- package/dist/esm/utils/base64.js +18 -15
- package/dist/esm/utils/errors.js +41 -0
- package/dist/esm/utils/interpolation.js +44 -22
- package/dist/esm/utils/interpolationSyntax.js +15 -6
- package/dist/esm/utils/serialization/serialization.js +7 -2
- package/dist/esm/utils/serialization/serializationUtils.js +6 -0
- package/dist/esm/utils/serialization/serialization_v4.js +15 -3
- package/dist/types/api/createProcessor.d.ts +7 -1
- package/dist/types/exports.d.ts +6 -0
- package/dist/types/model/CycleDetector.d.ts +1 -2
- package/dist/types/model/EditorDefinition.d.ts +24 -0
- package/dist/types/model/ExecutorProtocol.d.ts +2 -0
- package/dist/types/model/GraphBoundaryCache.d.ts +2 -0
- package/dist/types/model/GraphProcessor.d.ts +1 -0
- package/dist/types/model/MarkdownSanitizationPolicy.d.ts +1 -1
- package/dist/types/model/NodeImpl.d.ts +3 -1
- package/dist/types/model/Nodes.d.ts +10 -4
- package/dist/types/model/ProcessContext.d.ts +12 -0
- package/dist/types/model/ProjectBundle.d.ts +54 -0
- package/dist/types/model/ProjectReferenceLoader.d.ts +3 -0
- package/dist/types/model/Settings.d.ts +4 -0
- package/dist/types/model/StreamingWatchTopology.d.ts +17 -1
- package/dist/types/model/SubgraphProjectTarget.d.ts +38 -0
- package/dist/types/model/chat-v2/chatV2Shared.d.ts +1 -1
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +3 -1
- package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +3 -1
- package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +6 -6
- package/dist/types/model/chat-v2/temperature.d.ts +2 -0
- package/dist/types/model/classifier/credentials.d.ts +26 -0
- package/dist/types/model/classifier/images.d.ts +18 -0
- package/dist/types/model/classifier/json.d.ts +19 -0
- package/dist/types/model/classifier/limits.d.ts +42 -0
- package/dist/types/model/classifier/migration.d.ts +18 -0
- package/dist/types/model/classifier/openai.d.ts +5 -0
- package/dist/types/model/classifier/preparation.d.ts +16 -0
- package/dist/types/model/classifier/providers.d.ts +136 -0
- package/dist/types/model/classifier/questionHelpers.d.ts +33 -0
- package/dist/types/model/classifier/questions.d.ts +4 -0
- package/dist/types/model/classifier/response.d.ts +4 -0
- package/dist/types/model/classifier/state.d.ts +37 -0
- package/dist/types/model/classifier/types.d.ts +60 -0
- package/dist/types/model/nodeBodyMarkdown.d.ts +19 -0
- package/dist/types/model/nodeRunFailure.d.ts +13 -0
- package/dist/types/model/nodes/CatchStreamingChunksNode.d.ts +20 -0
- package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +50 -0
- package/dist/types/model/nodes/ClassifierQuestionNode.d.ts +60 -0
- package/dist/types/model/nodes/CodeNewNode.d.ts +6 -0
- package/dist/types/model/nodes/GetGlobalNode.d.ts +7 -0
- package/dist/types/model/nodes/ImageNode.d.ts +4 -0
- package/dist/types/model/nodes/LLMChatV2Node.d.ts +1 -0
- package/dist/types/model/nodes/MatchCaseNode.d.ts +8 -1
- package/dist/types/model/nodes/MatchCaseNodeBase.d.ts +13 -1
- package/dist/types/model/nodes/ObjectNode.d.ts +6 -0
- package/dist/types/model/nodes/StreamValueNode.d.ts +14 -0
- package/dist/types/model/nodes/SubGraphNode.d.ts +21 -2
- package/dist/types/model/nodes/ToBase64Node.d.ts +12 -0
- package/dist/types/model/nodes/codeOutputInference.d.ts +31 -0
- package/dist/types/recording/ExecutionRecorder.d.ts +8 -2
- package/dist/types/utils/base64.d.ts +1 -1
- package/dist/types/utils/errors.d.ts +4 -0
- package/dist/types/utils/interpolation.d.ts +13 -2
- package/dist/types/utils/interpolationSyntax.d.ts +1 -1
- package/dist/types/utils/serialization/serialization.d.ts +3 -1
- package/dist/types/utils/serialization/serializationUtils.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,235 @@
|
|
|
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 function projectBundleTargetKey(projectId, version) {
|
|
15
|
+
return JSON.stringify([projectId, version]);
|
|
16
|
+
}
|
|
17
|
+
function samePluginRequirement(left, right) {
|
|
18
|
+
if (left.id !== right.id || left.type !== right.type)
|
|
19
|
+
return false;
|
|
20
|
+
if (left.type === 'built-in')
|
|
21
|
+
return true; // Display names are not runtime identity.
|
|
22
|
+
if (left.type === 'package' && right.type === 'package')
|
|
23
|
+
return left.package === right.package && left.tag === right.tag;
|
|
24
|
+
return left.type === 'uri' && right.type === 'uri' && left.uri === right.uri;
|
|
25
|
+
}
|
|
26
|
+
function* projectSubgraphs(project) {
|
|
27
|
+
for (const [sourceGraphId, graph] of Object.entries(project.graphs)) {
|
|
28
|
+
for (const authored of graph.nodes) {
|
|
29
|
+
const node = resolveNodePrefabInstance(project, authored);
|
|
30
|
+
if (!node.disabled && node.type === 'nodePrefabInstance')
|
|
31
|
+
throw new ProjectBundleError(`Bundle contains an unresolved library node ${node.id}.`);
|
|
32
|
+
if (node.disabled || node.type !== 'subGraph')
|
|
33
|
+
continue;
|
|
34
|
+
const data = node.data;
|
|
35
|
+
if (data.targetProjectId) {
|
|
36
|
+
if (data.targetVersion !== undefined && data.targetVersion !== 'latest' && data.targetVersion !== 'published')
|
|
37
|
+
throw new ProjectBundleError('Invalid Subgraph project version.');
|
|
38
|
+
}
|
|
39
|
+
else if (data.targetScope === 'other-projects') {
|
|
40
|
+
throw new ProjectBundleError(`Subgraph ${node.title || node.id} has no selected project.`);
|
|
41
|
+
}
|
|
42
|
+
yield { sourceGraphId, data };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function listProjectBundleCalls(project) {
|
|
47
|
+
const calls = [];
|
|
48
|
+
for (const { data } of projectSubgraphs(project)) {
|
|
49
|
+
if (data.targetProjectId)
|
|
50
|
+
calls.push({
|
|
51
|
+
projectId: data.targetProjectId,
|
|
52
|
+
version: data.targetVersion ?? 'latest',
|
|
53
|
+
graphId: data.graphId,
|
|
54
|
+
boundary: data.targetBoundary,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return calls;
|
|
58
|
+
}
|
|
59
|
+
/** Uses the same saved wire contract as runtime execution, without running any nodes. */
|
|
60
|
+
export function validateProjectBundleCall(call, target) {
|
|
61
|
+
if (!Object.hasOwn(target.graphs, call.graphId))
|
|
62
|
+
throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}.`);
|
|
63
|
+
const boundary = getGraphBoundary(target, call.graphId);
|
|
64
|
+
if (!boundary)
|
|
65
|
+
throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}.`);
|
|
66
|
+
const issue = getSubgraphTargetBoundaryIssue(call.boundary, boundary);
|
|
67
|
+
if (issue)
|
|
68
|
+
throw new ProjectBundleError(`Subgraph dependency has an incompatible boundary. ${issue}`);
|
|
69
|
+
}
|
|
70
|
+
/** Reject missing bindings and cross-project dependency cycles before executing any graph. */
|
|
71
|
+
export function validateProjectBundleProjects(manifest, projects) {
|
|
72
|
+
const targets = new Map(manifest.targets.map((t) => [projectBundleTargetKey(t.projectId, t.version), t.artifact]));
|
|
73
|
+
const references = new Map(manifest.references.map((r) => [r.projectId, r.artifact]));
|
|
74
|
+
const plugins = new Map(manifest.plugins.map((plugin) => [plugin.id, plugin]));
|
|
75
|
+
const vertices = new Map();
|
|
76
|
+
const graphKey = (artifact, graph) => JSON.stringify([artifact, graph]);
|
|
77
|
+
for (const artifact of manifest.artifacts) {
|
|
78
|
+
const project = projects.get(artifact.id);
|
|
79
|
+
if (!project || project.metadata.id !== artifact.projectId)
|
|
80
|
+
throw new ProjectBundleError('Bundle project identity mismatch.');
|
|
81
|
+
for (const requirement of project.plugins ?? []) {
|
|
82
|
+
const declared = plugins.get(requirement.id);
|
|
83
|
+
if (!declared || !samePluginRequirement(declared, requirement))
|
|
84
|
+
throw new ProjectBundleError(`Bundle is missing the required plugin declaration ${requirement.id}.`);
|
|
85
|
+
}
|
|
86
|
+
for (const graphId of Object.keys(project.graphs))
|
|
87
|
+
vertices.set(graphKey(artifact.id, graphId), { edges: [] });
|
|
88
|
+
}
|
|
89
|
+
for (const artifact of manifest.artifacts) {
|
|
90
|
+
const project = projects.get(artifact.id);
|
|
91
|
+
for (const { sourceGraphId, data } of projectSubgraphs(project)) {
|
|
92
|
+
let targetId = artifact.id;
|
|
93
|
+
if (data.targetProjectId) {
|
|
94
|
+
const call = {
|
|
95
|
+
projectId: data.targetProjectId,
|
|
96
|
+
version: data.targetVersion ?? 'latest',
|
|
97
|
+
graphId: data.graphId,
|
|
98
|
+
boundary: data.targetBoundary,
|
|
99
|
+
};
|
|
100
|
+
const id = targets.get(projectBundleTargetKey(call.projectId, call.version));
|
|
101
|
+
const target = id && projects.get(id);
|
|
102
|
+
if (!id || !target)
|
|
103
|
+
throw new ProjectBundleError(`Bundle is missing Subgraph ${call.projectId}:${call.version}:${call.graphId}`);
|
|
104
|
+
validateProjectBundleCall(call, target);
|
|
105
|
+
targetId = id;
|
|
106
|
+
}
|
|
107
|
+
const target = vertices.get(graphKey(targetId, data.graphId));
|
|
108
|
+
if (target)
|
|
109
|
+
vertices.get(graphKey(artifact.id, sourceGraphId)).edges.push({
|
|
110
|
+
target,
|
|
111
|
+
crossProject: Boolean(data.targetProjectId),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
for (const reference of project.references ?? []) {
|
|
115
|
+
if (!references.has(reference.id))
|
|
116
|
+
throw new ProjectBundleError(`Bundle is missing referenced project ${reference.id}`);
|
|
117
|
+
}
|
|
118
|
+
for (const [sourceGraphId, graph] of Object.entries(project.graphs)) {
|
|
119
|
+
for (const authored of graph.nodes) {
|
|
120
|
+
const node = resolveNodePrefabInstance(project, authored);
|
|
121
|
+
if (node.disabled || node.type !== 'referencedGraphAlias')
|
|
122
|
+
continue;
|
|
123
|
+
const { projectId, graphId } = node.data;
|
|
124
|
+
const targetId = references.get(projectId);
|
|
125
|
+
const target = targetId && vertices.get(graphKey(targetId, graphId));
|
|
126
|
+
if (!target)
|
|
127
|
+
throw new ProjectBundleError(`Bundle is missing referenced graph ${projectId}:${graphId}`);
|
|
128
|
+
// Legacy-only recursion keeps its existing semantics, but aliases can
|
|
129
|
+
// participate in a cycle containing an explicit cross-project call.
|
|
130
|
+
vertices.get(graphKey(artifact.id, sourceGraphId)).edges.push({ target, crossProject: false });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Project-level cycles can be legitimate: A/main → B/main → A/helper.
|
|
135
|
+
// Reject only a recursive graph-call component containing a cross-project edge.
|
|
136
|
+
for (const component of findStronglyConnectedComponents([...vertices.values()], (v) => v.edges.map((e) => e.target))) {
|
|
137
|
+
const members = new Set(component);
|
|
138
|
+
if (component.some((v) => v.edges.some((e) => e.crossProject && members.has(e.target))))
|
|
139
|
+
throw new ProjectBundleError('Subgraph cross-project dependency cycle in bundle.');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function validateProjectBundleManifest(value) {
|
|
143
|
+
const fail = (message) => {
|
|
144
|
+
throw new ProjectBundleError(`Invalid project bundle: ${message}`);
|
|
145
|
+
};
|
|
146
|
+
const object = (v) => v !== null && typeof v === 'object' && !Array.isArray(v) ? v : fail('expected object');
|
|
147
|
+
const string = (v) => typeof v === 'string' && v.length > 0 && v.length <= 4096 ? v : fail('expected nonempty string');
|
|
148
|
+
const array = (v) => Array.isArray(v) && v.length <= PROJECT_BUNDLE_MAX_ARTIFACTS ? v : fail('invalid or oversized list');
|
|
149
|
+
const version = (v) => v === 'latest' || v === 'published' ? v : fail('unknown project version');
|
|
150
|
+
const paths = new Set();
|
|
151
|
+
const file = (v) => {
|
|
152
|
+
const obj = object(v), path = string(obj.path);
|
|
153
|
+
if (path.includes('\\') ||
|
|
154
|
+
path.includes(':') ||
|
|
155
|
+
path.includes('\0') ||
|
|
156
|
+
path.startsWith('/') ||
|
|
157
|
+
path.split('/').some((part) => !part || part === '.' || part === '..') ||
|
|
158
|
+
paths.has(path.toLowerCase()))
|
|
159
|
+
fail('unsafe or duplicate artifact path');
|
|
160
|
+
paths.add(path.toLowerCase());
|
|
161
|
+
if (!Number.isSafeInteger(obj.bytes) || obj.bytes < 0 || obj.bytes > 64 * 1024 * 1024)
|
|
162
|
+
fail('invalid artifact size (maximum 64 MiB per file)');
|
|
163
|
+
if (typeof obj.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(obj.sha256))
|
|
164
|
+
fail('invalid checksum');
|
|
165
|
+
return { path, bytes: obj.bytes, sha256: obj.sha256 };
|
|
166
|
+
};
|
|
167
|
+
const obj = object(value);
|
|
168
|
+
if (obj.format !== 'rivet-project-bundle' || obj.schemaVersion !== 1 || obj.requiredLoaderVersion !== 1)
|
|
169
|
+
fail('unsupported format or loader version; update @valerypopoff/rivet2-node');
|
|
170
|
+
const artifacts = array(obj.artifacts).map((v) => {
|
|
171
|
+
const a = object(v);
|
|
172
|
+
return {
|
|
173
|
+
id: string(a.id),
|
|
174
|
+
projectId: string(a.projectId),
|
|
175
|
+
title: string(a.title),
|
|
176
|
+
version: version(a.version),
|
|
177
|
+
revision: string(a.revision),
|
|
178
|
+
project: file(a.project),
|
|
179
|
+
...(a.datasets === undefined ? {} : { datasets: file(a.datasets) }),
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
const byId = new Map(artifacts.map((a) => [a.id, a]));
|
|
183
|
+
if (!artifacts.length || byId.size !== artifacts.length)
|
|
184
|
+
fail('empty or duplicate artifacts');
|
|
185
|
+
if (new Set(artifacts.map((a) => projectBundleTargetKey(a.projectId, a.version))).size !== artifacts.length)
|
|
186
|
+
fail('duplicate project/version artifacts');
|
|
187
|
+
const rootArtifact = string(obj.rootArtifact);
|
|
188
|
+
if (!byId.has(rootArtifact))
|
|
189
|
+
fail('missing root artifact');
|
|
190
|
+
const targetKeys = new Set(), referenceIds = new Set();
|
|
191
|
+
const targets = array(obj.targets).map((v) => {
|
|
192
|
+
const t = object(v), projectId = string(t.projectId), selectedVersion = version(t.version), artifact = string(t.artifact);
|
|
193
|
+
const key = projectBundleTargetKey(projectId, selectedVersion), a = byId.get(artifact);
|
|
194
|
+
if (targetKeys.has(key) || !a || a.projectId !== projectId || a.version !== selectedVersion)
|
|
195
|
+
fail('invalid or duplicate target binding');
|
|
196
|
+
targetKeys.add(key);
|
|
197
|
+
return { projectId, version: selectedVersion, artifact };
|
|
198
|
+
});
|
|
199
|
+
const references = array(obj.references).map((v) => {
|
|
200
|
+
const r = object(v), projectId = string(r.projectId), artifact = string(r.artifact);
|
|
201
|
+
if (referenceIds.has(projectId) || byId.get(artifact)?.projectId !== projectId)
|
|
202
|
+
fail('invalid or duplicate reference binding');
|
|
203
|
+
referenceIds.add(projectId);
|
|
204
|
+
return { projectId, artifact };
|
|
205
|
+
});
|
|
206
|
+
const pluginSpecs = array(obj.plugins).map((v) => {
|
|
207
|
+
const p = object(v), id = string(p.id);
|
|
208
|
+
if (p.type === 'built-in')
|
|
209
|
+
return { type: p.type, id, name: string(p.name) };
|
|
210
|
+
if (p.type === 'package')
|
|
211
|
+
return { type: p.type, id, package: string(p.package), tag: string(p.tag) };
|
|
212
|
+
if (p.type === 'uri')
|
|
213
|
+
return { type: p.type, id, uri: string(p.uri) };
|
|
214
|
+
return fail('invalid plugin requirement');
|
|
215
|
+
});
|
|
216
|
+
const pluginsById = new Map();
|
|
217
|
+
for (const plugin of pluginSpecs) {
|
|
218
|
+
const previous = pluginsById.get(plugin.id);
|
|
219
|
+
if (previous && !samePluginRequirement(previous, plugin))
|
|
220
|
+
fail(`conflicting requirements for plugin ${plugin.id}`);
|
|
221
|
+
if (!previous)
|
|
222
|
+
pluginsById.set(plugin.id, plugin);
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
format: 'rivet-project-bundle',
|
|
226
|
+
schemaVersion: 1,
|
|
227
|
+
requiredLoaderVersion: 1,
|
|
228
|
+
exportingRuntimeVersion: string(obj.exportingRuntimeVersion),
|
|
229
|
+
rootArtifact,
|
|
230
|
+
artifacts,
|
|
231
|
+
targets,
|
|
232
|
+
references,
|
|
233
|
+
plugins: [...pluginsById.values()],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { max, range } from 'lodash-es';
|
|
2
|
-
import { isArrayDataValue, arrayizeDataValue
|
|
2
|
+
import { isArrayDataValue, arrayizeDataValue } from './DataValue.js';
|
|
3
3
|
import {} from './NodeBase.js';
|
|
4
4
|
import { getGraphAbortReasonFromError, isAbortLikeError } from './GraphAbortReasons.js';
|
|
5
5
|
import { getError } from '../utils/errors.js';
|
|
@@ -84,7 +84,13 @@ async function runSequential(node, inputValues, inputDefinitionsById, splittingA
|
|
|
84
84
|
resultOrigin = 'editor-cache';
|
|
85
85
|
});
|
|
86
86
|
deps.accumulateCost(output);
|
|
87
|
-
results.push({
|
|
87
|
+
results.push({
|
|
88
|
+
type: 'output',
|
|
89
|
+
index: i,
|
|
90
|
+
output,
|
|
91
|
+
resultOrigin,
|
|
92
|
+
durationMs: deps.finishNodeTiming?.(splitTimingStart),
|
|
93
|
+
});
|
|
88
94
|
}
|
|
89
95
|
catch (error) {
|
|
90
96
|
results.push({
|
|
@@ -183,13 +189,28 @@ function splitInputsAtIndex(inputValues, inputDefinitionsById, index) {
|
|
|
183
189
|
]));
|
|
184
190
|
}
|
|
185
191
|
function aggregateOutputs(results) {
|
|
186
|
-
|
|
192
|
+
const ports = new Map();
|
|
193
|
+
results.forEach((result, index) => {
|
|
187
194
|
for (const [portId, value] of entries(result.output)) {
|
|
188
|
-
|
|
189
|
-
|
|
195
|
+
const id = portId;
|
|
196
|
+
const aggregate = ports.get(id) ?? { values: [] };
|
|
197
|
+
// Exclusion is not a value type. Infer from a real item regardless of
|
|
198
|
+
// whether the first split item succeeded or returned a caught failure.
|
|
199
|
+
if (value?.type !== 'control-flow-excluded')
|
|
200
|
+
aggregate.type ??= value?.type;
|
|
201
|
+
aggregate.values[index] = value?.value;
|
|
202
|
+
ports.set(id, aggregate);
|
|
190
203
|
}
|
|
191
|
-
|
|
192
|
-
|
|
204
|
+
});
|
|
205
|
+
return fromEntries([...ports].map(([id, aggregate]) => [
|
|
206
|
+
id,
|
|
207
|
+
aggregate.type == null
|
|
208
|
+
? { type: 'control-flow-excluded', value: undefined }
|
|
209
|
+
: {
|
|
210
|
+
type: `${aggregate.type}[]`,
|
|
211
|
+
value: Array.from({ length: results.length }, (_, index) => aggregate.values[index]),
|
|
212
|
+
},
|
|
213
|
+
]));
|
|
193
214
|
}
|
|
194
215
|
function isSplitOutputResult(result) {
|
|
195
216
|
return result.type === 'output';
|
|
@@ -1,13 +1,60 @@
|
|
|
1
1
|
import { canRenderDataBusNode, getDataBusInputChannelIndex, getDataBusOutputChannelIndex } from './DataBusTopology.js';
|
|
2
2
|
import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
|
|
3
|
+
import { getSubgraphTargetBoundaryChange, reconcileSubgraphTargetBoundary } from './nodes/SubGraphNode.js';
|
|
4
|
+
import { getGraphBoundary } from './GraphBoundaryCache.js';
|
|
3
5
|
import { createGraphOutputSelection } from './GraphOutputSelection.js';
|
|
4
|
-
|
|
6
|
+
import { getSubgraphProjectKey } from './SubgraphProjectTarget.js';
|
|
7
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
8
|
+
/** Only ports that can publish live partials receive streaming wire markers. */
|
|
9
|
+
function canEmitStreamingOutput(node, outputId) {
|
|
10
|
+
const data = node.data;
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'streamValue':
|
|
13
|
+
return outputId === 'value';
|
|
14
|
+
case 'llmChatV2':
|
|
15
|
+
return data.useAsGraphPartialOutput === true &&
|
|
16
|
+
['response', 'in-messages', 'all-messages', 'function-calls', 'reasoning'].includes(outputId);
|
|
17
|
+
case 'chatAnthropic':
|
|
18
|
+
return ['response', 'all-messages', 'function-calls', 'citations'].includes(outputId);
|
|
19
|
+
case 'chatGoogle':
|
|
20
|
+
return ['response', 'function-calls'].includes(outputId);
|
|
21
|
+
case 'chatHuggingFace':
|
|
22
|
+
return outputId === 'output';
|
|
23
|
+
case 'loopUntil':
|
|
24
|
+
return outputId !== 'iteration' && outputId !== 'completed';
|
|
25
|
+
default:
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getCallerProject(owner, caller, projects) {
|
|
30
|
+
if (caller.type === 'referencedGraphAlias')
|
|
31
|
+
return projects[caller.data.projectId];
|
|
32
|
+
if (!caller.data.targetProjectId)
|
|
33
|
+
return owner;
|
|
34
|
+
return projects[getSubgraphProjectKey({
|
|
35
|
+
projectId: caller.data.targetProjectId,
|
|
36
|
+
version: caller.data.targetVersion ?? 'latest',
|
|
37
|
+
})];
|
|
38
|
+
}
|
|
39
|
+
function getCallerBoundary(caller, target) {
|
|
40
|
+
if (caller.type !== 'subGraph')
|
|
41
|
+
return undefined;
|
|
42
|
+
const actual = getGraphBoundary(target, caller.data.graphId);
|
|
43
|
+
if (!actual || getSubgraphTargetBoundaryChange(caller.data.targetBoundary, actual))
|
|
44
|
+
return undefined;
|
|
45
|
+
return reconcileSubgraphTargetBoundary(caller.data.targetBoundary, actual);
|
|
46
|
+
}
|
|
47
|
+
/** An executing caller may forward outputs after its condition has passed. */
|
|
48
|
+
export function canForwardGraphCallerOutputPartials(node) {
|
|
5
49
|
return ((node.type === 'subGraph' || node.type === 'referencedGraphAlias') &&
|
|
6
50
|
!node.disabled &&
|
|
7
|
-
!node.isConditional &&
|
|
8
51
|
!node.isSplitRun &&
|
|
9
52
|
!node.data.useErrorOutput);
|
|
10
53
|
}
|
|
54
|
+
/** Early input delivery must not bypass the caller's ordinary readiness/condition gate. */
|
|
55
|
+
export function canStreamThroughGraphCaller(node) {
|
|
56
|
+
return canForwardGraphCallerOutputPartials(node) && !node.isConditional;
|
|
57
|
+
}
|
|
11
58
|
export function canStreamThroughGraphInput(node) {
|
|
12
59
|
return (node.type === 'graphInput' &&
|
|
13
60
|
!node.disabled &&
|
|
@@ -15,8 +62,17 @@ export function canStreamThroughGraphInput(node) {
|
|
|
15
62
|
!node.isSplitRun &&
|
|
16
63
|
!node.data.useDefaultValueInput);
|
|
17
64
|
}
|
|
65
|
+
/** A named output may forward only when one direct producer determines its terminal value. */
|
|
66
|
+
export function canForwardGraphOutputPartials(graphOutput, sourceNode, graphOutputIsFrozen) {
|
|
67
|
+
return (graphOutput.type === 'graphOutput' &&
|
|
68
|
+
!graphOutput.disabled &&
|
|
69
|
+
!graphOutput.isConditional &&
|
|
70
|
+
!graphOutput.isSplitRun &&
|
|
71
|
+
!sourceNode.isSplitRun &&
|
|
72
|
+
!graphOutputIsFrozen);
|
|
73
|
+
}
|
|
18
74
|
/** Trace Watch demand through named boundaries without making ordinary nodes repeatable. */
|
|
19
|
-
export function getProjectStreamingOutputWatchConnections({ project, graph, referencedProjects, registry, frozenNodeOutputs = {}, isNodeFrozen, fullGraphCallers, }) {
|
|
75
|
+
export function getProjectStreamingOutputWatchConnections({ project, graph, referencedProjects, registry, frozenNodeOutputs = {}, isNodeFrozen, fullGraphCallers, getPreviewGraphOutputStreamingCapability, onlyStreamCapableSources = false, }) {
|
|
20
76
|
// Unsaved active graph edits must take precedence over the stored project graph.
|
|
21
77
|
const currentProject = {
|
|
22
78
|
...project,
|
|
@@ -83,7 +139,7 @@ export function getProjectStreamingOutputWatchConnections({ project, graph, refe
|
|
|
83
139
|
if (node.disabled || isFrozen(context.project, parent, node) || !canStreamThroughGraphCaller(node))
|
|
84
140
|
continue;
|
|
85
141
|
const caller = node;
|
|
86
|
-
const owner =
|
|
142
|
+
const owner = getCallerProject(context.project, caller, projects);
|
|
87
143
|
const child = owner?.graphs[caller.data.graphId];
|
|
88
144
|
if (!child)
|
|
89
145
|
continue;
|
|
@@ -93,12 +149,13 @@ export function getProjectStreamingOutputWatchConnections({ project, graph, refe
|
|
|
93
149
|
!caller.data.useAsGraphPartialOutput &&
|
|
94
150
|
!(parent === graph && fullGraphCallers?.has(caller.id))) {
|
|
95
151
|
const childContext = contexts.get(child);
|
|
152
|
+
const callerBoundary = getCallerBoundary(caller, owner);
|
|
96
153
|
const outputNames = new Set(Object.values(childContext.nodes)
|
|
97
154
|
.filter((node) => node.type === 'graphOutput')
|
|
98
155
|
.map((node) => node.data.id));
|
|
99
156
|
const outputs = parent.connections
|
|
100
157
|
.filter((edge) => edge.outputNodeId === caller.id)
|
|
101
|
-
.map((edge) => edge.outputId)
|
|
158
|
+
.map((edge) => callerBoundary?.outputs.find((output) => output.portId === edge.outputId)?.id ?? edge.outputId)
|
|
102
159
|
.filter((id) => outputNames.has(id));
|
|
103
160
|
try {
|
|
104
161
|
selected = createGraphOutputSelection({ ...child, nodes: Object.values(childContext.nodes) }, outputs, (node) => childContext.incoming(node.id).map((edge) => childContext.nodes[edge.outputNodeId])).nodeIds;
|
|
@@ -112,80 +169,170 @@ export function getProjectStreamingOutputWatchConnections({ project, graph, refe
|
|
|
112
169
|
callers.set(child, entries);
|
|
113
170
|
}
|
|
114
171
|
}
|
|
115
|
-
const
|
|
172
|
+
const watchInputs = [];
|
|
116
173
|
for (const [candidate, context] of contexts) {
|
|
117
174
|
for (const node of Object.values(context.nodes)) {
|
|
118
|
-
if (node.type !== 'watchStreamingOutput'
|
|
175
|
+
if ((node.type !== 'watchStreamingOutput' && node.type !== 'catchStreamingChunks') ||
|
|
176
|
+
node.disabled ||
|
|
177
|
+
isFrozen(context.project, candidate, node))
|
|
119
178
|
continue;
|
|
120
179
|
const inputs = context.incoming(node.id).filter((edge) => edge.inputId === 'stream');
|
|
121
180
|
// Multiple providers are rejected by the Watch scheduler, not multiple streams.
|
|
122
181
|
if (inputs.length === 1)
|
|
123
|
-
|
|
182
|
+
watchInputs.push({ graph: candidate, edge: inputs[0] });
|
|
124
183
|
}
|
|
125
184
|
}
|
|
126
|
-
|
|
127
|
-
|
|
185
|
+
const visiting = new Map();
|
|
186
|
+
const trace = (candidate, edge) => {
|
|
128
187
|
const context = contexts.get(candidate);
|
|
129
188
|
if (context.marked.has(edge))
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
189
|
+
return true;
|
|
190
|
+
const graphVisiting = visiting.get(candidate) ?? new Set();
|
|
191
|
+
if (graphVisiting.has(edge))
|
|
192
|
+
return false;
|
|
193
|
+
graphVisiting.add(edge);
|
|
194
|
+
visiting.set(candidate, graphVisiting);
|
|
195
|
+
try {
|
|
196
|
+
const source = context.nodes[edge.outputNodeId];
|
|
197
|
+
if (!source || source.disabled || source.isSplitRun || isFrozen(context.project, candidate, source))
|
|
198
|
+
return false;
|
|
199
|
+
if (canRenderDataBusNode(source)) {
|
|
200
|
+
const channel = getDataBusOutputChannelIndex(edge.outputId);
|
|
201
|
+
if (channel == null)
|
|
202
|
+
return false;
|
|
203
|
+
const providers = context
|
|
204
|
+
.incoming(source.id)
|
|
205
|
+
.filter((input) => getDataBusInputChannelIndex(input.inputId) === channel);
|
|
206
|
+
if (providers.length !== 1 || !trace(candidate, providers[0]))
|
|
207
|
+
return false;
|
|
208
|
+
context.marked.add(edge);
|
|
209
|
+
return true;
|
|
142
210
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (parent.selected && !parent.selected.has(edge.inputNodeId))
|
|
161
|
-
continue;
|
|
162
|
-
for (const input of contexts.get(parent.graph).incoming(parent.node.id)) {
|
|
163
|
-
if (input.inputId === inputName)
|
|
164
|
-
pending.push({ graph: parent.graph, edge: input });
|
|
211
|
+
if (source.type === 'graphInput' && edge.outputId === 'data') {
|
|
212
|
+
if (!canStreamThroughGraphInput(source))
|
|
213
|
+
return false;
|
|
214
|
+
const inputName = source.data.id;
|
|
215
|
+
let foundSource = false;
|
|
216
|
+
for (const parent of callers.get(candidate) ?? []) {
|
|
217
|
+
if (parent.selected && !parent.selected.has(edge.inputNodeId))
|
|
218
|
+
continue;
|
|
219
|
+
const callerPortId = getCallerBoundary(parent.node, context.project)?.inputs.find((input) => input.nodeId === source.id)?.portId ?? inputName;
|
|
220
|
+
const inputs = contexts
|
|
221
|
+
.get(parent.graph)
|
|
222
|
+
.incoming(parent.node.id)
|
|
223
|
+
.filter((input) => input.inputId === callerPortId);
|
|
224
|
+
// Ambiguous authored inputs stay final-only even though ordinary
|
|
225
|
+
// execution retains its established first-provider projection.
|
|
226
|
+
if (inputs.length === 1 && trace(parent.graph, inputs[0]))
|
|
227
|
+
foundSource = true;
|
|
165
228
|
}
|
|
229
|
+
if (!foundSource)
|
|
230
|
+
return false;
|
|
231
|
+
context.marked.add(edge);
|
|
232
|
+
return true;
|
|
166
233
|
}
|
|
167
|
-
|
|
234
|
+
if (source.type !== 'subGraph' && source.type !== 'referencedGraphAlias') {
|
|
235
|
+
if (onlyStreamCapableSources && !canEmitStreamingOutput(source, edge.outputId))
|
|
236
|
+
return false;
|
|
237
|
+
context.marked.add(edge);
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
if (!canForwardGraphCallerOutputPartials(source))
|
|
241
|
+
return false;
|
|
242
|
+
const caller = source;
|
|
243
|
+
const childProject = getCallerProject(context.project, caller, projects);
|
|
244
|
+
const child = childProject?.graphs[caller.data.graphId];
|
|
245
|
+
const childContext = child && contexts.get(child);
|
|
246
|
+
if (!childProject || !child || !childContext)
|
|
247
|
+
return false;
|
|
248
|
+
const targetOutputId = getCallerBoundary(caller, childProject)?.outputs.find((output) => output.portId === edge.outputId)?.id ??
|
|
249
|
+
edge.outputId;
|
|
250
|
+
const outputs = Object.values(childContext.nodes).filter((node) => node.type === 'graphOutput' && !node.disabled && node.data.id === targetOutputId);
|
|
251
|
+
// Duplicate names have first-final-winner semantics, so cannot relay partials.
|
|
252
|
+
if (outputs.length !== 1)
|
|
253
|
+
return false;
|
|
254
|
+
const output = outputs[0];
|
|
255
|
+
const outputIsFrozen = isFrozen(childProject, child, output);
|
|
256
|
+
const previewCapability = getPreviewGraphOutputStreamingCapability?.(childProject, child, output.id);
|
|
257
|
+
if (previewCapability !== undefined) {
|
|
258
|
+
if (previewCapability && !outputIsFrozen && !output.isConditional && !output.isSplitRun) {
|
|
259
|
+
context.marked.add(edge);
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
const providers = childContext.incoming(output.id).filter((input) => input.inputId === 'value');
|
|
265
|
+
// As in GraphProcessor's effective connection projection, the first
|
|
266
|
+
// valid provider owns a single-input Graph Output in a malformed graph.
|
|
267
|
+
// Never mark a shadowed provider that cannot determine the final value.
|
|
268
|
+
const provider = providers[0];
|
|
269
|
+
const providerNode = provider && childContext.nodes[provider.outputNodeId];
|
|
270
|
+
if (!provider ||
|
|
271
|
+
!providerNode ||
|
|
272
|
+
!canForwardGraphOutputPartials(output, providerNode, outputIsFrozen) ||
|
|
273
|
+
!trace(child, provider))
|
|
274
|
+
return false;
|
|
275
|
+
context.marked.add(edge);
|
|
276
|
+
return true;
|
|
168
277
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
278
|
+
finally {
|
|
279
|
+
graphVisiting.delete(edge);
|
|
280
|
+
if (graphVisiting.size === 0)
|
|
281
|
+
visiting.delete(candidate);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
for (const { graph: candidate, edge } of watchInputs)
|
|
285
|
+
trace(candidate, edge);
|
|
286
|
+
return contexts.get(graph)?.marked ?? new Set();
|
|
287
|
+
}
|
|
288
|
+
/** Derive safe boundary capability hints for every graph in one topology pass. */
|
|
289
|
+
export function getProjectStreamableGraphOutputNodeIdsByGraph({ project, referencedProjects, registry, }) {
|
|
290
|
+
// Graph IDs come from project files; keep unusual keys such as __proto__
|
|
291
|
+
// as data rather than assigning through Object.prototype.
|
|
292
|
+
const result = Object.create(null);
|
|
293
|
+
const nodes = [];
|
|
294
|
+
const probes = [];
|
|
295
|
+
for (const [graphId] of Object.entries(project.graphs)) {
|
|
296
|
+
result[graphId] = [];
|
|
297
|
+
const boundary = getGraphBoundary(project, graphId);
|
|
298
|
+
if (!boundary?.outputs.length)
|
|
183
299
|
continue;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
300
|
+
const callerId = nanoid();
|
|
301
|
+
nodes.push({ id: callerId, type: 'subGraph', title: 'Probe', data: { graphId }, visualData: { x: 0, y: 0 } });
|
|
302
|
+
for (const output of boundary.outputs) {
|
|
303
|
+
const watchId = nanoid();
|
|
304
|
+
nodes.push({ id: watchId, type: 'watchStreamingOutput', title: 'Probe watch', data: {}, visualData: { x: 0, y: 0 } });
|
|
305
|
+
probes.push({
|
|
306
|
+
graphId,
|
|
307
|
+
outputNodeId: output.nodeId,
|
|
308
|
+
connection: {
|
|
309
|
+
outputNodeId: callerId,
|
|
310
|
+
outputId: output.portId,
|
|
311
|
+
inputNodeId: watchId,
|
|
312
|
+
inputId: 'stream',
|
|
313
|
+
},
|
|
314
|
+
});
|
|
188
315
|
}
|
|
189
316
|
}
|
|
190
|
-
|
|
317
|
+
if (probes.length === 0)
|
|
318
|
+
return result;
|
|
319
|
+
const probeGraphId = nanoid();
|
|
320
|
+
const probeGraph = {
|
|
321
|
+
metadata: { id: probeGraphId, name: 'Streaming preview probe' },
|
|
322
|
+
nodes,
|
|
323
|
+
connections: probes.map(({ connection }) => connection),
|
|
324
|
+
};
|
|
325
|
+
const probeProject = { ...project, graphs: { ...project.graphs, [probeGraphId]: probeGraph } };
|
|
326
|
+
const marked = getProjectStreamingOutputWatchConnections({
|
|
327
|
+
project: probeProject,
|
|
328
|
+
graph: probeGraph,
|
|
329
|
+
referencedProjects,
|
|
330
|
+
registry,
|
|
331
|
+
onlyStreamCapableSources: true,
|
|
332
|
+
});
|
|
333
|
+
for (const { graphId, outputNodeId, connection } of probes) {
|
|
334
|
+
if (marked.has(connection))
|
|
335
|
+
result[graphId].push(outputNodeId);
|
|
336
|
+
}
|
|
337
|
+
return result;
|
|
191
338
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Internal definition key; not a project metadata ID or a persisted reference. */
|
|
2
|
+
export function getSubgraphProjectKey(target) {
|
|
3
|
+
return `\u0000rivet-subgraph:${target.version}:${encodeURIComponent(target.projectId)}`;
|
|
4
|
+
}
|
|
5
|
+
export function isSubgraphProjectKey(key) {
|
|
6
|
+
return key.startsWith('\u0000rivet-subgraph:');
|
|
7
|
+
}
|