@valerypopoff/rivet2-core 2.27.1 → 2.29.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 +173 -115
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/webAppRuntime.cjs.map +2 -2
- package/dist/esm/model/AgentResponseTrace.js +27 -15
- package/dist/esm/model/GraphBoundaryCache.js +7 -2
- package/dist/esm/model/ProjectBundle.js +33 -22
- package/dist/esm/model/StreamingWatchTopology.js +11 -5
- package/dist/esm/model/nodes/SubGraphNode.js +38 -61
- package/dist/esm/utils/projectComparison/graphs.js +2 -2
- package/dist/esm/utils/projectComparison/identity.js +23 -0
- package/dist/esm/utils/projectComparison/nodes.js +10 -3
- package/dist/esm/utils/projectComparison.js +14 -6
- package/dist/types/model/AgentResponseTrace.d.ts +2 -0
- package/dist/types/model/GraphBoundaryCache.d.ts +1 -1
- package/dist/types/model/ProjectBundle.d.ts +12 -3
- package/dist/types/model/nodes/SubGraphNode.d.ts +2 -8
- package/dist/types/utils/projectComparison/graphs.d.ts +2 -1
- package/dist/types/utils/projectComparison/identity.d.ts +11 -0
- package/dist/types/utils/projectComparison/nodes.d.ts +2 -1
- package/dist/types/utils/projectComparison.d.ts +4 -1
- package/package.json +1 -1
|
@@ -198,10 +198,35 @@ function toProfileAttemptTrace(event) {
|
|
|
198
198
|
const { type: _type, execution: _execution, ...trace } = event;
|
|
199
199
|
return trace;
|
|
200
200
|
}
|
|
201
|
+
/** Cost-only projection shared by trace totals and activity-family subtotals. */
|
|
202
|
+
export function summarizeAgentResponseCosts(modelCalls, profileAttempts) {
|
|
203
|
+
let knownCostUsd = 0;
|
|
204
|
+
let knownCount = 0;
|
|
205
|
+
let callCount = 0;
|
|
206
|
+
const add = (cost) => {
|
|
207
|
+
callCount++;
|
|
208
|
+
if (cost != null && Number.isFinite(cost) && cost >= 0) {
|
|
209
|
+
knownCostUsd += cost;
|
|
210
|
+
knownCount++;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
for (const call of modelCalls)
|
|
214
|
+
add(call.pricing.status === 'known' ? call.pricing.costUsd : undefined);
|
|
215
|
+
for (const attempt of profileAttempts) {
|
|
216
|
+
if (attempt.family === 'classifier' && attempt.attemptIndex != null)
|
|
217
|
+
add(attempt.classifierUsage?.estimatedCostUsd);
|
|
218
|
+
}
|
|
219
|
+
// Keep the retained summary serializable even when individually finite estimates overflow.
|
|
220
|
+
if (!Number.isFinite(knownCostUsd))
|
|
221
|
+
return { knownCostUsd: 0, costStatus: 'unknown' };
|
|
222
|
+
return {
|
|
223
|
+
knownCostUsd,
|
|
224
|
+
costStatus: knownCount === 0 ? 'unknown' : knownCount < callCount ? 'partial' : 'known',
|
|
225
|
+
};
|
|
226
|
+
}
|
|
201
227
|
/** Shared metadata accounting for response inspectors and the bounded activity journal. */
|
|
202
228
|
export function summarizeAgentResponseCalls(modelCalls, profileAttempts, toolCalls) {
|
|
203
229
|
const classifierCalls = profileAttempts.filter((attempt) => attempt.family === 'classifier' && attempt.attemptIndex != null);
|
|
204
|
-
const accountedCallCount = modelCalls.length + classifierCalls.length;
|
|
205
230
|
const usageKeys = ['promptTokens', 'completionTokens', 'totalTokens', 'cachedTokens', 'reasoningTokens'];
|
|
206
231
|
const usage = Object.fromEntries(usageKeys.flatMap((key) => {
|
|
207
232
|
const values = modelCalls.map((call) => call.usage?.[key]).filter((value) => value != null);
|
|
@@ -218,14 +243,6 @@ export function summarizeAgentResponseCalls(modelCalls, profileAttempts, toolCal
|
|
|
218
243
|
}
|
|
219
244
|
return values.length === 0 ? [] : [[key, values.reduce((sum, value) => sum + value, 0)]];
|
|
220
245
|
}));
|
|
221
|
-
const knownCosts = [
|
|
222
|
-
...modelCalls
|
|
223
|
-
.map((call) => call.pricing.costUsd)
|
|
224
|
-
.filter((value) => value != null && Number.isFinite(value)),
|
|
225
|
-
...classifierCalls.flatMap((attempt) => attempt.classifierUsage?.estimatedCostUsd == null ? [] : [attempt.classifierUsage.estimatedCostUsd]),
|
|
226
|
-
];
|
|
227
|
-
const unknownCostCount = modelCalls.filter((call) => call.pricing.status === 'unknown' || !Number.isFinite(call.pricing.costUsd)).length +
|
|
228
|
-
classifierCalls.filter((attempt) => attempt.classifierUsage?.estimatedCostUsd == null).length;
|
|
229
246
|
const profileTransitions = countProfileFallbacks(modelCalls, profileAttempts);
|
|
230
247
|
return {
|
|
231
248
|
modelCallCount: modelCalls.length,
|
|
@@ -237,12 +254,7 @@ export function summarizeAgentResponseCalls(modelCalls, profileAttempts, toolCal
|
|
|
237
254
|
classifierCalls.filter((attempt) => attempt.attemptIndex > 0).length,
|
|
238
255
|
fallbackCount: profileTransitions,
|
|
239
256
|
...usage,
|
|
240
|
-
|
|
241
|
-
costStatus: accountedCallCount === 0 || unknownCostCount === accountedCallCount
|
|
242
|
-
? 'unknown'
|
|
243
|
-
: unknownCostCount > 0
|
|
244
|
-
? 'partial'
|
|
245
|
-
: 'known',
|
|
257
|
+
...summarizeAgentResponseCosts(modelCalls, profileAttempts),
|
|
246
258
|
};
|
|
247
259
|
}
|
|
248
260
|
/**
|
|
@@ -56,15 +56,20 @@ export function getGraphBoundaryOutputDefinitions(boundary, outputPortOrder) {
|
|
|
56
56
|
dataType: output.dataType,
|
|
57
57
|
}));
|
|
58
58
|
}
|
|
59
|
-
export function buildGraphBoundaryInputData(boundary, inputs, defaults) {
|
|
59
|
+
export function buildGraphBoundaryInputData(boundary, inputs, defaults, previousBoundary) {
|
|
60
60
|
const inputData = {};
|
|
61
|
+
const callerPortIds = new Set(boundary.inputs.map((input) => input.portId));
|
|
61
62
|
for (const input of boundary.inputs) {
|
|
62
63
|
const inputValue = inputs[input.portId];
|
|
63
64
|
if (inputValue != null) {
|
|
64
65
|
inputData[input.portId] = inputValue;
|
|
65
66
|
continue;
|
|
66
67
|
}
|
|
67
|
-
const defaultValue = defaults?.[input.portId] ??
|
|
68
|
+
const defaultValue = defaults?.[input.portId] ??
|
|
69
|
+
(!callerPortIds.has(input.id) &&
|
|
70
|
+
!previousBoundary?.inputs.some((previous) => previous.portId !== input.portId && (previous.portId === input.id || previous.id === input.id))
|
|
71
|
+
? defaults?.[input.id]
|
|
72
|
+
: undefined);
|
|
68
73
|
if (defaultValue != null) {
|
|
69
74
|
inputData[input.portId] = defaultValue;
|
|
70
75
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { getSubgraphTargetBoundaryIssue } from './nodes/SubGraphNode.js';
|
|
2
|
-
import { getGraphBoundary } from './GraphBoundaryCache.js';
|
|
3
1
|
import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
|
|
4
2
|
import { findStronglyConnectedComponents } from './CycleDetector.js';
|
|
5
3
|
/** Deliberate, user-facing bundle validation failures; never raw storage errors. */
|
|
@@ -24,49 +22,60 @@ function samePluginRequirement(left, right) {
|
|
|
24
22
|
return left.package === right.package && left.tag === right.tag;
|
|
25
23
|
return left.type === 'uri' && right.type === 'uri' && left.uri === right.uri;
|
|
26
24
|
}
|
|
25
|
+
function describeBundleCallSource(source) {
|
|
26
|
+
return `node "${source.nodeTitle}" (${source.nodeId}) in graph "${source.graphName}" of project "${source.projectName}"`;
|
|
27
|
+
}
|
|
27
28
|
function* projectSubgraphs(project) {
|
|
28
29
|
for (const [sourceGraphId, graph] of Object.entries(project.graphs)) {
|
|
29
30
|
for (const authored of graph.nodes) {
|
|
30
31
|
const node = resolveNodePrefabInstance(project, authored);
|
|
31
|
-
if (
|
|
32
|
-
throw new ProjectBundleError(`Bundle contains an unresolved library node ${node.id}.`);
|
|
33
|
-
if (node.disabled || node.type !== 'subGraph')
|
|
32
|
+
if (node.disabled || (node.type !== 'subGraph' && node.type !== 'nodePrefabInstance'))
|
|
34
33
|
continue;
|
|
34
|
+
const source = {
|
|
35
|
+
projectName: project.metadata.title || project.metadata.id,
|
|
36
|
+
graphName: graph.metadata?.name || sourceGraphId,
|
|
37
|
+
nodeId: authored.id,
|
|
38
|
+
nodeTitle: node.title || 'Subgraph',
|
|
39
|
+
};
|
|
40
|
+
if (node.type === 'nodePrefabInstance')
|
|
41
|
+
throw new ProjectBundleError(`Bundle contains an unresolved library ${describeBundleCallSource(source)}.`);
|
|
35
42
|
const data = node.data;
|
|
36
43
|
if (data.targetProjectId) {
|
|
37
44
|
if (data.targetVersion !== undefined && data.targetVersion !== 'latest' && data.targetVersion !== 'published')
|
|
38
|
-
throw new ProjectBundleError(
|
|
45
|
+
throw new ProjectBundleError(`Invalid Subgraph project version. Check Subgraph ${describeBundleCallSource(source)}.`);
|
|
39
46
|
}
|
|
40
47
|
else if (data.targetScope) {
|
|
41
|
-
throw new ProjectBundleError(`Subgraph
|
|
48
|
+
throw new ProjectBundleError(`Subgraph has no selected project. Check Subgraph ${describeBundleCallSource(source)}.`);
|
|
42
49
|
}
|
|
43
|
-
yield { sourceGraphId, data };
|
|
50
|
+
yield { sourceGraphId, data, source };
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
export function listProjectBundleCalls(project) {
|
|
48
55
|
const calls = [];
|
|
49
|
-
for (const { data } of projectSubgraphs(project)) {
|
|
56
|
+
for (const { data, source } of projectSubgraphs(project)) {
|
|
50
57
|
if (data.targetProjectId)
|
|
51
58
|
calls.push({
|
|
52
59
|
projectId: data.targetProjectId,
|
|
53
60
|
version: data.targetVersion ?? 'latest',
|
|
54
61
|
graphId: data.graphId,
|
|
55
62
|
boundary: data.targetBoundary,
|
|
63
|
+
source,
|
|
56
64
|
});
|
|
57
65
|
}
|
|
58
66
|
return calls;
|
|
59
67
|
}
|
|
60
|
-
/**
|
|
61
|
-
export function validateProjectBundleCall(call, target) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
/** Validate the target without running nodes; execution adopts its current ports. */
|
|
69
|
+
export function validateProjectBundleCall(call, target, selectedVersion) {
|
|
70
|
+
const graph = Object.hasOwn(target.graphs, call.graphId)
|
|
71
|
+
? target.graphs[call.graphId]
|
|
72
|
+
: undefined;
|
|
73
|
+
if (graph)
|
|
74
|
+
return;
|
|
75
|
+
const source = call.source ? `Check Subgraph ${describeBundleCallSource(call.source)}. ` : '';
|
|
76
|
+
const version = selectedVersion ? ` (${selectedVersion === 'published' ? 'Published' : 'Saved latest'})` : '';
|
|
77
|
+
const location = `${source}Target: graph "${call.graphId}" in project "${target.metadata.title || target.metadata.id}"${version}.`;
|
|
78
|
+
throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}. ${location}`);
|
|
70
79
|
}
|
|
71
80
|
/** Reject missing bindings and cross-project dependency cycles before executing any graph. */
|
|
72
81
|
export function validateProjectBundleProjects(manifest, projects) {
|
|
@@ -74,6 +83,7 @@ export function validateProjectBundleProjects(manifest, projects) {
|
|
|
74
83
|
const references = new Map(manifest.references.map((r) => [r.projectId, r.artifact]));
|
|
75
84
|
const plugins = new Map(manifest.plugins.map((plugin) => [plugin.id, plugin]));
|
|
76
85
|
const members = manifest.workspace ? new Set(manifest.workspace.members.map((m) => m.projectId)) : undefined;
|
|
86
|
+
const versions = new Map(manifest.artifacts.map((artifact) => [artifact.id, artifact.version]));
|
|
77
87
|
const vertices = new Map();
|
|
78
88
|
const graphKey = (artifact, graph) => JSON.stringify([artifact, graph]);
|
|
79
89
|
for (const artifact of manifest.artifacts) {
|
|
@@ -90,7 +100,7 @@ export function validateProjectBundleProjects(manifest, projects) {
|
|
|
90
100
|
}
|
|
91
101
|
for (const artifact of manifest.artifacts) {
|
|
92
102
|
const project = projects.get(artifact.id);
|
|
93
|
-
for (const { sourceGraphId, data } of projectSubgraphs(project)) {
|
|
103
|
+
for (const { sourceGraphId, data, source } of projectSubgraphs(project)) {
|
|
94
104
|
let targetId = artifact.id;
|
|
95
105
|
if (data.targetProjectId) {
|
|
96
106
|
if (members?.has(data.targetProjectId) && !members.has(project.metadata.id))
|
|
@@ -100,12 +110,13 @@ export function validateProjectBundleProjects(manifest, projects) {
|
|
|
100
110
|
version: data.targetVersion ?? 'latest',
|
|
101
111
|
graphId: data.graphId,
|
|
102
112
|
boundary: data.targetBoundary,
|
|
113
|
+
source,
|
|
103
114
|
};
|
|
104
115
|
const id = targets.get(projectBundleTargetKey(call.projectId, call.version));
|
|
105
116
|
const target = id && projects.get(id);
|
|
106
117
|
if (!id || !target)
|
|
107
|
-
throw new ProjectBundleError(`Bundle is missing Subgraph ${call.projectId}:${call.version}:${call.graphId}
|
|
108
|
-
validateProjectBundleCall(call, target);
|
|
118
|
+
throw new ProjectBundleError(`Bundle is missing Subgraph ${call.projectId}:${call.version}:${call.graphId}. Check Subgraph ${describeBundleCallSource(source)}.`);
|
|
119
|
+
validateProjectBundleCall(call, target, versions.get(id));
|
|
109
120
|
targetId = id;
|
|
110
121
|
}
|
|
111
122
|
const target = vertices.get(graphKey(targetId, data.graphId));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { canRenderDataBusNode, getDataBusInputChannelIndex, getDataBusOutputChannelIndex } from './DataBusTopology.js';
|
|
2
2
|
import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
|
|
3
|
-
import {
|
|
3
|
+
import { reconcileSubgraphTargetBoundary } from './nodes/SubGraphNode.js';
|
|
4
4
|
import { getGraphBoundary } from './GraphBoundaryCache.js';
|
|
5
5
|
import { createGraphOutputSelection } from './GraphOutputSelection.js';
|
|
6
6
|
import { getSubgraphProjectKey } from './SubgraphProjectTarget.js';
|
|
@@ -12,8 +12,8 @@ function canEmitStreamingOutput(node, outputId) {
|
|
|
12
12
|
case 'streamValue':
|
|
13
13
|
return outputId === 'value';
|
|
14
14
|
case 'llmChatV2':
|
|
15
|
-
return data.useAsGraphPartialOutput === true &&
|
|
16
|
-
['response', 'in-messages', 'all-messages', 'function-calls', 'reasoning'].includes(outputId);
|
|
15
|
+
return (data.useAsGraphPartialOutput === true &&
|
|
16
|
+
['response', 'in-messages', 'all-messages', 'function-calls', 'reasoning'].includes(outputId));
|
|
17
17
|
case 'chatAnthropic':
|
|
18
18
|
return ['response', 'all-messages', 'function-calls', 'citations'].includes(outputId);
|
|
19
19
|
case 'chatGoogle':
|
|
@@ -40,7 +40,7 @@ function getCallerBoundary(caller, target) {
|
|
|
40
40
|
if (caller.type !== 'subGraph')
|
|
41
41
|
return undefined;
|
|
42
42
|
const actual = getGraphBoundary(target, caller.data.graphId);
|
|
43
|
-
if (!actual
|
|
43
|
+
if (!actual)
|
|
44
44
|
return undefined;
|
|
45
45
|
return reconcileSubgraphTargetBoundary(caller.data.targetBoundary, actual);
|
|
46
46
|
}
|
|
@@ -301,7 +301,13 @@ export function getProjectStreamableGraphOutputNodeIdsByGraph({ project, referen
|
|
|
301
301
|
nodes.push({ id: callerId, type: 'subGraph', title: 'Probe', data: { graphId }, visualData: { x: 0, y: 0 } });
|
|
302
302
|
for (const output of boundary.outputs) {
|
|
303
303
|
const watchId = nanoid();
|
|
304
|
-
nodes.push({
|
|
304
|
+
nodes.push({
|
|
305
|
+
id: watchId,
|
|
306
|
+
type: 'watchStreamingOutput',
|
|
307
|
+
title: 'Probe watch',
|
|
308
|
+
data: {},
|
|
309
|
+
visualData: { x: 0, y: 0 },
|
|
310
|
+
});
|
|
305
311
|
probes.push({
|
|
306
312
|
graphId,
|
|
307
313
|
outputNodeId: output.nodeId,
|
|
@@ -13,49 +13,34 @@ import { getError } from '../../utils/errors.js';
|
|
|
13
13
|
import { getSubgraphProjectKey } from '../SubgraphProjectTarget.js';
|
|
14
14
|
import { ExecutionRecorder } from '../../recording/ExecutionRecorder.js';
|
|
15
15
|
import { applyGraphBoundaryPortOrder, buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, } from '../GraphBoundaryCache.js';
|
|
16
|
-
/**
|
|
17
|
-
export function getSubgraphTargetBoundaryChange(expected, actual) {
|
|
18
|
-
if (!expected)
|
|
19
|
-
return null;
|
|
20
|
-
for (const side of ['inputs', 'outputs']) {
|
|
21
|
-
for (const port of expected[side]) {
|
|
22
|
-
const match = actual[side].find((candidate) => port.nodeId ? candidate.nodeId === port.nodeId : candidate.portId === port.portId);
|
|
23
|
-
if (match?.dataType !== port.dataType) {
|
|
24
|
-
return { side: side === 'inputs' ? 'input' : 'output', id: port.id };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const callerIds = new Set();
|
|
28
|
-
for (const port of actual[side]) {
|
|
29
|
-
const saved = expected[side].find((candidate) => candidate.nodeId ? candidate.nodeId === port.nodeId : candidate.portId === port.portId);
|
|
30
|
-
const callerId = saved?.portId ?? port.portId;
|
|
31
|
-
if (callerIds.has(callerId)) {
|
|
32
|
-
return { side: side === 'inputs' ? 'input' : 'output', id: port.id };
|
|
33
|
-
}
|
|
34
|
-
callerIds.add(callerId);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
/** Keep the caller's saved wire IDs while adopting current target names and metadata. */
|
|
16
|
+
/** Adopt current ports and types while preserving the IDs of surviving wired ports. */
|
|
40
17
|
export function reconcileSubgraphTargetBoundary(expected, actual) {
|
|
41
18
|
if (!expected)
|
|
42
19
|
return actual;
|
|
43
20
|
return {
|
|
44
|
-
inputs: actual.inputs
|
|
45
|
-
|
|
46
|
-
return saved && saved.dataType === port.dataType ? { ...port, portId: saved.portId } : port;
|
|
47
|
-
}),
|
|
48
|
-
outputs: actual.outputs.map((port) => {
|
|
49
|
-
const saved = expected.outputs.find((candidate) => candidate.nodeId ? candidate.nodeId === port.nodeId : candidate.portId === port.portId);
|
|
50
|
-
return saved && saved.dataType === port.dataType ? { ...port, portId: saved.portId } : port;
|
|
51
|
-
}),
|
|
21
|
+
inputs: reconcileSubgraphPorts(expected.inputs, actual.inputs),
|
|
22
|
+
outputs: reconcileSubgraphPorts(expected.outputs, actual.outputs),
|
|
52
23
|
};
|
|
53
24
|
}
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
25
|
+
function reconcileSubgraphPorts(expected, actual) {
|
|
26
|
+
const matches = actual.map((port) => expected.find((saved) => (saved.nodeId ? saved.nodeId === port.nodeId : saved.portId === port.portId)));
|
|
27
|
+
const reserved = new Set(matches.flatMap((saved) => (saved ? [saved.portId] : [])));
|
|
28
|
+
const used = new Set();
|
|
29
|
+
return actual.map((port, index) => {
|
|
30
|
+
const saved = matches[index];
|
|
31
|
+
let portId = saved?.portId ?? port.portId;
|
|
32
|
+
// A new port can reuse a renamed port's old name. Keep their wires distinct;
|
|
33
|
+
// the new port's stable node ID is a deterministic fallback, not a new name.
|
|
34
|
+
if (used.has(portId) || (!saved && reserved.has(portId))) {
|
|
35
|
+
const base = port.nodeId ?? port.portId;
|
|
36
|
+
portId = base;
|
|
37
|
+
for (let suffix = 2; used.has(portId) || reserved.has(portId); suffix++) {
|
|
38
|
+
portId = `${base}:${suffix}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
used.add(portId);
|
|
42
|
+
return portId === port.portId ? port : { ...port, portId };
|
|
43
|
+
});
|
|
59
44
|
}
|
|
60
45
|
export class SubGraphNodeImpl extends NodeImpl {
|
|
61
46
|
static create() {
|
|
@@ -111,19 +96,12 @@ export class SubGraphNodeImpl extends NodeImpl {
|
|
|
111
96
|
})];
|
|
112
97
|
}
|
|
113
98
|
getTargetBoundary(project, referencedProjects, definitionContext) {
|
|
114
|
-
// Keep the authored port contract visible even after a referenced project
|
|
115
|
-
// changes. Execution checks it against the resolved graph and fails with a
|
|
116
|
-
// reviewable error; replacing it here would hide existing wires in the UI.
|
|
117
|
-
if (this.data.targetProjectId && this.data.targetBoundary) {
|
|
118
|
-
const target = this.getTargetProject(project, referencedProjects);
|
|
119
|
-
const actual = target && this.getBoundary(target, definitionContext);
|
|
120
|
-
return actual && !getSubgraphTargetBoundaryChange(this.data.targetBoundary, actual)
|
|
121
|
-
? reconcileSubgraphTargetBoundary(this.data.targetBoundary, actual)
|
|
122
|
-
: this.data.targetBoundary;
|
|
123
|
-
}
|
|
124
99
|
const target = this.getTargetProject(project, referencedProjects);
|
|
125
|
-
|
|
126
|
-
|
|
100
|
+
const actual = target && this.getBoundary(target, definitionContext);
|
|
101
|
+
if (!this.data.targetProjectId)
|
|
102
|
+
return actual;
|
|
103
|
+
// Missing preview data is not evidence that a port was deleted.
|
|
104
|
+
return actual ? reconcileSubgraphTargetBoundary(this.data.targetBoundary, actual) : this.data.targetBoundary;
|
|
127
105
|
}
|
|
128
106
|
getEditors(context) {
|
|
129
107
|
const definitions = [
|
|
@@ -197,15 +175,10 @@ export class SubGraphNodeImpl extends NodeImpl {
|
|
|
197
175
|
throw new Error(`SubGraphNode requires a graph with id ${this.data.graphId} to be present in the project.`);
|
|
198
176
|
}
|
|
199
177
|
const boundary = context.getGraphBoundary?.(target, this.data.graphId) ?? getGraphBoundary(target, this.data.graphId);
|
|
200
|
-
if (this.data.targetProjectId) {
|
|
201
|
-
const boundaryIssue = getSubgraphTargetBoundaryIssue(this.data.targetBoundary, boundary);
|
|
202
|
-
if (boundaryIssue)
|
|
203
|
-
throw new Error(boundaryIssue);
|
|
204
|
-
}
|
|
205
178
|
const callerBoundary = this.data.targetProjectId
|
|
206
179
|
? reconcileSubgraphTargetBoundary(this.data.targetBoundary, boundary)
|
|
207
180
|
: boundary;
|
|
208
|
-
const callerInputData = buildGraphBoundaryInputData(callerBoundary, inputs, this.data.inputData);
|
|
181
|
+
const callerInputData = buildGraphBoundaryInputData(callerBoundary, inputs, this.data.inputData, this.data.targetProjectId ? this.data.targetBoundary : undefined);
|
|
209
182
|
const inputData = this.data.targetProjectId ? {} : callerInputData;
|
|
210
183
|
if (this.data.targetProjectId) {
|
|
211
184
|
for (const input of callerBoundary.inputs) {
|
|
@@ -275,7 +248,7 @@ export class SubGraphNodeImpl extends NodeImpl {
|
|
|
275
248
|
value: undefined,
|
|
276
249
|
};
|
|
277
250
|
}
|
|
278
|
-
if (outputs['duration'] == null) {
|
|
251
|
+
if (!getSubgraphOutputNames(callerBoundary).has('duration') && outputs['duration'] == null) {
|
|
279
252
|
outputs['duration'] = {
|
|
280
253
|
type: 'number',
|
|
281
254
|
value: duration,
|
|
@@ -322,9 +295,12 @@ export class SubGraphNodeImpl extends NodeImpl {
|
|
|
322
295
|
}
|
|
323
296
|
}
|
|
324
297
|
export const subGraphNode = nodeDefinition(SubGraphNodeImpl, 'Subgraph');
|
|
298
|
+
function getSubgraphOutputNames(boundary) {
|
|
299
|
+
return new Set(boundary.outputs.flatMap((output) => [output.id, output.portId]));
|
|
300
|
+
}
|
|
325
301
|
function mapSubgraphTargetOutputs(boundary, graphOutputs) {
|
|
326
|
-
const
|
|
327
|
-
const outputs = Object.fromEntries(Object.entries(graphOutputs).filter(([name]) => !
|
|
302
|
+
const ownedNames = getSubgraphOutputNames(boundary);
|
|
303
|
+
const outputs = Object.fromEntries(Object.entries(graphOutputs).filter(([name]) => !ownedNames.has(name)));
|
|
328
304
|
for (const output of boundary.outputs) {
|
|
329
305
|
if (Object.hasOwn(graphOutputs, output.id))
|
|
330
306
|
outputs[output.portId] = graphOutputs[output.id];
|
|
@@ -353,13 +329,14 @@ function buildOptimizedSubgraphOutputs(boundary, requestedOutputIds, graphOutput
|
|
|
353
329
|
// Authored boundary values retain ownership of metric-named ports, including
|
|
354
330
|
// exclusions. An unrequested Graph Output may still run as another output's
|
|
355
331
|
// dependency, so do not copy arbitrary child results into the caller map.
|
|
356
|
-
|
|
332
|
+
const ownedNames = getSubgraphOutputNames(boundary);
|
|
333
|
+
if (!ownedNames.has('cost')) {
|
|
357
334
|
outputs['cost'] = graphOutputs['cost'] ?? { type: 'number', value: 0 };
|
|
358
335
|
}
|
|
359
|
-
if (!
|
|
336
|
+
if (!ownedNames.has('costBreakdown') && graphOutputs['costBreakdown']) {
|
|
360
337
|
outputs['costBreakdown'] = graphOutputs['costBreakdown'];
|
|
361
338
|
}
|
|
362
|
-
if (!
|
|
339
|
+
if (!ownedNames.has('duration')) {
|
|
363
340
|
outputs['duration'] = { type: 'number', value: duration };
|
|
364
341
|
}
|
|
365
342
|
return outputs;
|
|
@@ -2,7 +2,7 @@ import { compareConnections, getComparableGraphConnections, getProjectConnection
|
|
|
2
2
|
import { compareNodes, getComparableGraphNodes } from './nodes.js';
|
|
3
3
|
import { summarizeGraphComparison } from './summaries.js';
|
|
4
4
|
import { areComparisonValuesEqual } from './values.js';
|
|
5
|
-
export function compareGraphs(id, before, after) {
|
|
5
|
+
export function compareGraphs(id, before, after, identity) {
|
|
6
6
|
if (!before && after) {
|
|
7
7
|
return createOneSidedGraphComparison(id, after, 'added');
|
|
8
8
|
}
|
|
@@ -12,7 +12,7 @@ export function compareGraphs(id, before, after) {
|
|
|
12
12
|
if (!before || !after) {
|
|
13
13
|
throw new Error(`Cannot compare missing graph ${id}`);
|
|
14
14
|
}
|
|
15
|
-
const nodes = compareNodes(getComparableGraphNodes(before.nodes), getComparableGraphNodes(after.nodes));
|
|
15
|
+
const nodes = compareNodes(getComparableGraphNodes(before.nodes), getComparableGraphNodes(after.nodes), identity);
|
|
16
16
|
const connections = compareConnections(getComparableGraphConnections(before.connections, before.nodes), getComparableGraphConnections(after.connections, after.nodes));
|
|
17
17
|
const summary = summarizeGraphComparison(nodes, connections);
|
|
18
18
|
const metadataChanged = !areComparisonValuesEqual(before.metadata, after.metadata);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Side-specific tagged identities cannot equate a stale opposite-bundle link. */
|
|
2
|
+
export function comparisonProjectIdentity(id, side, identity) {
|
|
3
|
+
const index = identity.pairs.findIndex((p) => (side === 'before' ? p.beforeProjectId : p.afterProjectId) === id);
|
|
4
|
+
return JSON.stringify(index < 0 ? ['project', id] : ['pair', index]);
|
|
5
|
+
}
|
|
6
|
+
export function comparisonNodeIdentity(node, side, identity) {
|
|
7
|
+
if (!identity || (node.type !== 'subGraph' && node.type !== 'referencedGraphAlias'))
|
|
8
|
+
return node;
|
|
9
|
+
const field = node.type === 'subGraph' ? 'targetProjectId' : 'projectId';
|
|
10
|
+
const data = (value) => {
|
|
11
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
12
|
+
return value;
|
|
13
|
+
const record = value;
|
|
14
|
+
return typeof record[field] === 'string'
|
|
15
|
+
? { ...record, [field]: comparisonProjectIdentity(record[field], side, identity) }
|
|
16
|
+
: value;
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
...node,
|
|
20
|
+
data: data(node.data),
|
|
21
|
+
...(node.variants ? { variants: node.variants.map((v) => ({ ...v, data: data(v.data) })) } : {}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { areComparisonValuesEqual, getChangedValueComparisons, isComparisonRecord, unionKeys } from './values.js';
|
|
2
|
+
import { comparisonNodeIdentity } from './identity.js';
|
|
2
3
|
export function getProjectNodeFieldComparisons(comparison) {
|
|
3
4
|
const before = comparison.before;
|
|
4
5
|
const after = comparison.after;
|
|
5
6
|
if (!before || !after) {
|
|
6
7
|
return [];
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
const rawBefore = getComparableNodeRecord(before);
|
|
10
|
+
const rawAfter = getComparableNodeRecord(after);
|
|
11
|
+
const at = (record, path) => path.reduce((value, key) => (value && typeof value === 'object' ? value[key] : undefined), record);
|
|
12
|
+
return getChangedValueComparisons([], getComparableNodeRecord(comparisonNodeIdentity(before, 'before', comparison.identity)), getComparableNodeRecord(comparisonNodeIdentity(after, 'after', comparison.identity))).map((change) => ({ ...change, before: at(rawBefore, change.path), after: at(rawAfter, change.path) }));
|
|
9
13
|
}
|
|
10
14
|
export function getComparableGraphNodes(nodes) {
|
|
11
15
|
return nodes.filter((node) => node.type !== 'comment');
|
|
12
16
|
}
|
|
13
|
-
export function compareNodes(beforeNodes, afterNodes) {
|
|
17
|
+
export function compareNodes(beforeNodes, afterNodes, identity) {
|
|
14
18
|
const beforeById = new Map(beforeNodes.map((node) => [node.id, node]));
|
|
15
19
|
const afterById = new Map(afterNodes.map((node) => [node.id, node]));
|
|
16
20
|
const nodeIds = unionKeys(Object.fromEntries(beforeById), Object.fromEntries(afterById));
|
|
@@ -27,9 +31,12 @@ export function compareNodes(beforeNodes, afterNodes) {
|
|
|
27
31
|
nodeId,
|
|
28
32
|
{
|
|
29
33
|
id: nodeId,
|
|
30
|
-
kind: areComparisonNodesEqual(before
|
|
34
|
+
kind: areComparisonNodesEqual(before && comparisonNodeIdentity(before, 'before', identity), after && comparisonNodeIdentity(after, 'after', identity))
|
|
35
|
+
? 'unchanged'
|
|
36
|
+
: 'changed',
|
|
31
37
|
before,
|
|
32
38
|
after,
|
|
39
|
+
...(identity ? { identity } : {}),
|
|
33
40
|
},
|
|
34
41
|
];
|
|
35
42
|
}));
|
|
@@ -2,24 +2,32 @@ import { compareGraphs } from './projectComparison/graphs.js';
|
|
|
2
2
|
import { summarizeProjectComparison } from './projectComparison/summaries.js';
|
|
3
3
|
import { compareNodes } from './projectComparison/nodes.js';
|
|
4
4
|
import { areComparisonValuesEqual, unionKeys } from './projectComparison/values.js';
|
|
5
|
+
import { comparisonProjectIdentity } from './projectComparison/identity.js';
|
|
5
6
|
export { getProjectConnectionComparisonKey } from './projectComparison/connections.js';
|
|
6
7
|
export { getProjectNodeFieldComparisons } from './projectComparison/nodes.js';
|
|
7
|
-
export function compareProjects(before, after) {
|
|
8
|
+
export function compareProjects(before, after, identity) {
|
|
8
9
|
const graphIds = unionKeys(before.graphs, after.graphs);
|
|
9
|
-
const graphs = Object.fromEntries(graphIds.map((graphId) => [
|
|
10
|
-
|
|
10
|
+
const graphs = Object.fromEntries(graphIds.map((graphId) => [
|
|
11
|
+
graphId,
|
|
12
|
+
compareGraphs(graphId, before.graphs[graphId], after.graphs[graphId], identity),
|
|
13
|
+
]));
|
|
14
|
+
const nodePrefabs = compareNodePrefabs(before.nodePrefabs ?? {}, after.nodePrefabs ?? {}, identity);
|
|
11
15
|
const uiGraphs = compareUiGraphs(before.uiGraphs ?? {}, after.uiGraphs ?? {});
|
|
12
16
|
return {
|
|
13
17
|
beforeProjectId: before.metadata.id,
|
|
14
18
|
afterProjectId: after.metadata.id,
|
|
15
|
-
metadataChanged: !areComparisonValuesEqual(
|
|
19
|
+
metadataChanged: !areComparisonValuesEqual(identity
|
|
20
|
+
? { ...before.metadata, id: comparisonProjectIdentity(before.metadata.id, 'before', identity), path: undefined }
|
|
21
|
+
: before.metadata, identity
|
|
22
|
+
? { ...after.metadata, id: comparisonProjectIdentity(after.metadata.id, 'after', identity), path: undefined }
|
|
23
|
+
: after.metadata),
|
|
16
24
|
graphs,
|
|
17
25
|
nodePrefabs,
|
|
18
26
|
uiGraphs,
|
|
19
27
|
summary: summarizeProjectComparison(graphs, nodePrefabs, uiGraphs),
|
|
20
28
|
};
|
|
21
29
|
}
|
|
22
|
-
function compareNodePrefabs(before, after) {
|
|
30
|
+
function compareNodePrefabs(before, after, identity) {
|
|
23
31
|
const prefabIds = unionKeys(before, after);
|
|
24
32
|
return Object.fromEntries(prefabIds.map((prefabId) => {
|
|
25
33
|
const beforePrefab = before[prefabId];
|
|
@@ -33,7 +41,7 @@ function compareNodePrefabs(before, after) {
|
|
|
33
41
|
if (!beforePrefab || !afterPrefab) {
|
|
34
42
|
throw new Error(`Cannot compare missing library node ${prefabId}`);
|
|
35
43
|
}
|
|
36
|
-
const sourceNodeComparison = Object.values(compareNodes([beforePrefab.sourceNode], [afterPrefab.sourceNode]))[0];
|
|
44
|
+
const sourceNodeComparison = Object.values(compareNodes([beforePrefab.sourceNode], [afterPrefab.sourceNode], identity))[0];
|
|
37
45
|
return [
|
|
38
46
|
prefabId,
|
|
39
47
|
{
|
|
@@ -121,6 +121,8 @@ export declare function mergeAgentModelCall<T extends ChatV2CallTraceEvent>(exis
|
|
|
121
121
|
}, incoming: T): T;
|
|
122
122
|
/** Merge one identified attempt, retaining additive metadata omitted by older transports. */
|
|
123
123
|
export declare function mergeAgentProfileAttempt<T extends LLMProfileAttemptTraceEvent>(existing: LLMProfileAttemptTraceEvent, incoming: T): T;
|
|
124
|
+
/** Cost-only projection shared by trace totals and activity-family subtotals. */
|
|
125
|
+
export declare function summarizeAgentResponseCosts(modelCalls: readonly AgentModelCallTrace[], profileAttempts: readonly AgentLLMProfileAttemptTrace[]): Pick<AgentResponseTrace['summary'], 'knownCostUsd' | 'costStatus'>;
|
|
124
126
|
/** Shared metadata accounting for response inspectors and the bounded activity journal. */
|
|
125
127
|
export declare function summarizeAgentResponseCalls(modelCalls: readonly AgentModelCallTrace[], profileAttempts: readonly AgentLLMProfileAttemptTrace[], toolCalls: readonly AgentToolCallTrace[]): AgentResponseTrace['summary'];
|
|
126
128
|
export declare function isAgentResponseTrace(value: unknown): value is AgentResponseTrace;
|
|
@@ -30,5 +30,5 @@ export declare function applyGraphBoundaryPortOrder<T extends {
|
|
|
30
30
|
}>(boundaryItems: readonly T[], portOrder: readonly string[] | undefined): T[];
|
|
31
31
|
export declare function getGraphBoundaryInputDefinitions(boundary: GraphBoundary, inputPortOrder?: readonly string[]): NodeInputDefinition[];
|
|
32
32
|
export declare function getGraphBoundaryOutputDefinitions(boundary: GraphBoundary, outputPortOrder?: readonly string[]): NodeOutputDefinition[];
|
|
33
|
-
export declare function buildGraphBoundaryInputData(boundary: GraphBoundary, inputs: Inputs, defaults: Record<string, DataValue> | undefined): Inputs;
|
|
33
|
+
export declare function buildGraphBoundaryInputData(boundary: GraphBoundary, inputs: Inputs, defaults: Record<string, DataValue> | undefined, previousBoundary?: GraphBoundary): Inputs;
|
|
34
34
|
export declare function buildExcludedGraphBoundaryOutputs(boundary: GraphBoundary): Outputs;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Project } from './Project.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { GraphBoundary } from './GraphBoundaryCache.js';
|
|
3
3
|
import type { PluginLoadSpec } from './PluginLoadSpec.js';
|
|
4
4
|
/** Deliberate, user-facing bundle validation failures; never raw storage errors. */
|
|
5
5
|
export declare class ProjectBundleError extends Error {
|
|
@@ -55,14 +55,23 @@ export declare const PROJECT_BUNDLE_MANIFEST = "rivet-bundle.json";
|
|
|
55
55
|
export declare const PROJECT_BUNDLE_MAX_ARTIFACTS = 256;
|
|
56
56
|
export declare const PROJECT_BUNDLE_MAX_MANIFEST_BYTES: number;
|
|
57
57
|
export declare function projectBundleTargetKey(projectId: string, version: string): string;
|
|
58
|
+
type ProjectBundleCallSource = {
|
|
59
|
+
projectName: string;
|
|
60
|
+
graphName: string;
|
|
61
|
+
nodeId: string;
|
|
62
|
+
nodeTitle: string;
|
|
63
|
+
};
|
|
58
64
|
export declare function listProjectBundleCalls(project: Project): {
|
|
59
65
|
projectId: string;
|
|
60
66
|
version: 'latest' | 'published';
|
|
61
67
|
graphId: string;
|
|
62
68
|
boundary?: GraphBoundary;
|
|
69
|
+
/** Advisory repair location; not part of the saved wire contract. */
|
|
70
|
+
source?: ProjectBundleCallSource;
|
|
63
71
|
}[];
|
|
64
|
-
/**
|
|
65
|
-
export declare function validateProjectBundleCall(call: ReturnType<typeof listProjectBundleCalls>[number], target: Project): void;
|
|
72
|
+
/** Validate the target without running nodes; execution adopts its current ports. */
|
|
73
|
+
export declare function validateProjectBundleCall(call: ReturnType<typeof listProjectBundleCalls>[number], target: Project, selectedVersion?: 'latest' | 'published'): void;
|
|
66
74
|
/** Reject missing bindings and cross-project dependency cycles before executing any graph. */
|
|
67
75
|
export declare function validateProjectBundleProjects(manifest: ProjectBundleManifest, projects: ReadonlyMap<string, Project>): void;
|
|
68
76
|
export declare function validateProjectBundleManifest(value: unknown): ProjectBundleManifest;
|
|
77
|
+
export {};
|
|
@@ -18,7 +18,7 @@ export type SubGraphNode = ChartNode & {
|
|
|
18
18
|
/** Retains the hosted picker mode before an external project is selected. */
|
|
19
19
|
targetScope?: 'other-projects' | 'same-bundle';
|
|
20
20
|
targetVersion?: SubgraphProjectVersion;
|
|
21
|
-
/**
|
|
21
|
+
/** Remembered port IDs preserve wires across renames and while a target preview reloads. */
|
|
22
22
|
targetBoundary?: GraphBoundary;
|
|
23
23
|
useErrorOutput?: boolean;
|
|
24
24
|
useAsGraphPartialOutput?: boolean;
|
|
@@ -30,14 +30,8 @@ export type SubGraphNode = ChartNode & {
|
|
|
30
30
|
outputPortOrder?: string[];
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
|
-
/**
|
|
34
|
-
export declare function getSubgraphTargetBoundaryChange(expected: GraphBoundary | undefined, actual: GraphBoundary): {
|
|
35
|
-
side: 'input' | 'output';
|
|
36
|
-
id: string;
|
|
37
|
-
} | null;
|
|
38
|
-
/** Keep the caller's saved wire IDs while adopting current target names and metadata. */
|
|
33
|
+
/** Adopt current ports and types while preserving the IDs of surviving wired ports. */
|
|
39
34
|
export declare function reconcileSubgraphTargetBoundary(expected: GraphBoundary | undefined, actual: GraphBoundary): GraphBoundary;
|
|
40
|
-
export declare function getSubgraphTargetBoundaryIssue(expected: GraphBoundary | undefined, actual: GraphBoundary): string | null;
|
|
41
35
|
export declare class SubGraphNodeImpl extends NodeImpl<SubGraphNode> {
|
|
42
36
|
static create(): SubGraphNode;
|
|
43
37
|
getInputDefinitions(_connections: NodeConnection[], _nodes: Record<NodeId, ChartNode>, project: Project, referencedProjects: Record<ProjectId, Project>, definitionContext?: NodeDefinitionContext): NodeInputDefinition[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { GraphId, NodeGraph } from '../../model/NodeGraph.js';
|
|
2
2
|
import type { ProjectGraphComparison } from '../projectComparison.js';
|
|
3
|
-
|
|
3
|
+
import type { ProjectComparisonIdentity } from './identity.js';
|
|
4
|
+
export declare function compareGraphs(id: GraphId, before: NodeGraph | undefined, after: NodeGraph | undefined, identity?: ProjectComparisonIdentity): ProjectGraphComparison;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChartNode } from '../../model/NodeBase.js';
|
|
2
|
+
export type ProjectComparisonIdentity = {
|
|
3
|
+
pairs: readonly {
|
|
4
|
+
beforeProjectId: string;
|
|
5
|
+
afterProjectId: string;
|
|
6
|
+
}[];
|
|
7
|
+
};
|
|
8
|
+
export type ProjectComparisonSide = 'before' | 'after';
|
|
9
|
+
/** Side-specific tagged identities cannot equate a stale opposite-bundle link. */
|
|
10
|
+
export declare function comparisonProjectIdentity(id: string, side: ProjectComparisonSide, identity: ProjectComparisonIdentity): string;
|
|
11
|
+
export declare function comparisonNodeIdentity(node: ChartNode, side: ProjectComparisonSide, identity?: ProjectComparisonIdentity): ChartNode;
|