@valerypopoff/rivet2-core 2.27.0 → 2.28.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.
@@ -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
- knownCostUsd: knownCosts.reduce((sum, value) => sum + value, 0),
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
  /**
@@ -21,7 +21,7 @@ export function applyGraphBoundaryPortOrder(boundaryItems, portOrder) {
21
21
  if (!portOrder?.length) {
22
22
  return [...boundaryItems];
23
23
  }
24
- const itemsById = new Map(boundaryItems.map((item) => [item.id, item]));
24
+ const itemsById = new Map(boundaryItems.map((item) => [item.portId ?? item.id, item]));
25
25
  const usedIds = new Set();
26
26
  const orderedItems = [];
27
27
  for (const id of portOrder) {
@@ -36,7 +36,7 @@ export function applyGraphBoundaryPortOrder(boundaryItems, portOrder) {
36
36
  usedIds.add(id);
37
37
  }
38
38
  for (const item of boundaryItems) {
39
- if (!usedIds.has(item.id)) {
39
+ if (!usedIds.has(item.portId ?? item.id)) {
40
40
  orderedItems.push(item);
41
41
  }
42
42
  }
@@ -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] ?? defaults?.[input.id];
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 (!node.disabled && node.type === 'nodePrefabInstance')
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('Invalid Subgraph project version.');
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 ${node.title || node.id} has no selected project.`);
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
- /** 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}`);
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 { getSubgraphTargetBoundaryChange, reconcileSubgraphTargetBoundary } from './nodes/SubGraphNode.js';
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 || getSubgraphTargetBoundaryChange(caller.data.targetBoundary, 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({ id: watchId, type: 'watchStreamingOutput', title: 'Probe watch', data: {}, visualData: { x: 0, y: 0 } });
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
- /** A saved cross-project boundary is the wire contract until the user explicitly selects a new target. */
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.map((port) => {
45
- const saved = expected.inputs.find((candidate) => candidate.nodeId ? candidate.nodeId === port.nodeId : candidate.portId === port.portId);
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
- export function getSubgraphTargetBoundaryIssue(expected, actual) {
55
- const change = getSubgraphTargetBoundaryChange(expected, actual);
56
- return change
57
- ? `The selected project's graph changed its ${change.side} "${change.id}". Re-select the graph and review its connections.`
58
- : null;
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
- return ((target && this.getBoundary(target, definitionContext)) ??
126
- (this.data.targetProjectId ? this.data.targetBoundary : undefined));
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 targetNames = new Set(boundary.outputs.map((output) => output.id));
327
- const outputs = Object.fromEntries(Object.entries(graphOutputs).filter(([name]) => !targetNames.has(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
- if (!boundary.outputs.some((output) => output.id === 'cost')) {
332
+ const ownedNames = getSubgraphOutputNames(boundary);
333
+ if (!ownedNames.has('cost')) {
357
334
  outputs['cost'] = graphOutputs['cost'] ?? { type: 'number', value: 0 };
358
335
  }
359
- if (!boundary.outputs.some((output) => output.id === 'costBreakdown') && graphOutputs['costBreakdown']) {
336
+ if (!ownedNames.has('costBreakdown') && graphOutputs['costBreakdown']) {
360
337
  outputs['costBreakdown'] = graphOutputs['costBreakdown'];
361
338
  }
362
- if (!boundary.outputs.some((output) => output.id === 'duration')) {
339
+ if (!ownedNames.has('duration')) {
363
340
  outputs['duration'] = { type: 'number', value: duration };
364
341
  }
365
342
  return outputs;
@@ -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;
@@ -26,8 +26,9 @@ export type GraphBoundaryCache = WeakMap<NodeGraph, GraphBoundary>;
26
26
  export declare function getGraphBoundary(project: Project, graphId: GraphId | undefined, cache?: GraphBoundaryCache): GraphBoundary | undefined;
27
27
  export declare function applyGraphBoundaryPortOrder<T extends {
28
28
  id: string;
29
+ portId?: string;
29
30
  }>(boundaryItems: readonly T[], portOrder: readonly string[] | undefined): T[];
30
31
  export declare function getGraphBoundaryInputDefinitions(boundary: GraphBoundary, inputPortOrder?: readonly string[]): NodeInputDefinition[];
31
32
  export declare function getGraphBoundaryOutputDefinitions(boundary: GraphBoundary, outputPortOrder?: readonly string[]): NodeOutputDefinition[];
32
- 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;
33
34
  export declare function buildExcludedGraphBoundaryOutputs(boundary: GraphBoundary): Outputs;
@@ -1,5 +1,5 @@
1
1
  import type { Project } from './Project.js';
2
- import { type GraphBoundary } from './GraphBoundaryCache.js';
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
- /** Uses the same saved wire contract as runtime execution, without running any nodes. */
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
- /** Last selected boundary keeps existing wires visible while a hosted preview reloads. */
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
- /** A saved cross-project boundary is the wire contract until the user explicitly selects a new target. */
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[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerypopoff/rivet2-core",
3
- "version": "2.27.0",
3
+ "version": "2.28.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/bundle.cjs",
6
6
  "module": "dist/esm/index.js",