@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.
@@ -496,8 +496,6 @@ __export(src_exports, {
496
496
  getSingleNodeStream: () => getSingleNodeStream,
497
497
  getStoredValueNode: () => getStoredValueNode,
498
498
  getSubgraphProjectKey: () => getSubgraphProjectKey,
499
- getSubgraphTargetBoundaryChange: () => getSubgraphTargetBoundaryChange,
500
- getSubgraphTargetBoundaryIssue: () => getSubgraphTargetBoundaryIssue,
501
499
  getToolNodeBodyPreview: () => getToolNodeBodyPreview,
502
500
  getUiGraphActionComponent: () => getUiGraphActionComponent,
503
501
  getUiGraphActionInputBindings: () => getUiGraphActionInputBindings,
@@ -801,6 +799,7 @@ __export(src_exports, {
801
799
  subGraphNode: () => subGraphNode,
802
800
  subqClassifierProvider: () => subqClassifierProvider,
803
801
  summarizeAgentResponseCalls: () => summarizeAgentResponseCalls,
802
+ summarizeAgentResponseCosts: () => summarizeAgentResponseCosts,
804
803
  summarizeChatV2RequestPlan: () => summarizeChatV2RequestPlan,
805
804
  summarizeDataValueForLog: () => summarizeDataValueForLog,
806
805
  summarizeErrorForLog: () => summarizeErrorForLog,
@@ -1308,8 +1307,6 @@ __export(exports_exports, {
1308
1307
  getSingleNodeStream: () => getSingleNodeStream,
1309
1308
  getStoredValueNode: () => getStoredValueNode,
1310
1309
  getSubgraphProjectKey: () => getSubgraphProjectKey,
1311
- getSubgraphTargetBoundaryChange: () => getSubgraphTargetBoundaryChange,
1312
- getSubgraphTargetBoundaryIssue: () => getSubgraphTargetBoundaryIssue,
1313
1310
  getToolNodeBodyPreview: () => getToolNodeBodyPreview,
1314
1311
  getUiGraphActionComponent: () => getUiGraphActionComponent,
1315
1312
  getUiGraphActionInputBindings: () => getUiGraphActionInputBindings,
@@ -1613,6 +1610,7 @@ __export(exports_exports, {
1613
1610
  subGraphNode: () => subGraphNode,
1614
1611
  subqClassifierProvider: () => subqClassifierProvider,
1615
1612
  summarizeAgentResponseCalls: () => summarizeAgentResponseCalls,
1613
+ summarizeAgentResponseCosts: () => summarizeAgentResponseCosts,
1616
1614
  summarizeChatV2RequestPlan: () => summarizeChatV2RequestPlan,
1617
1615
  summarizeDataValueForLog: () => summarizeDataValueForLog,
1618
1616
  summarizeErrorForLog: () => summarizeErrorForLog,
@@ -6313,6 +6311,26 @@ function compareConnections(beforeConnections, afterConnections) {
6313
6311
  );
6314
6312
  }
6315
6313
 
6314
+ // src/utils/projectComparison/identity.ts
6315
+ function comparisonProjectIdentity(id, side, identity) {
6316
+ const index = identity.pairs.findIndex((p) => (side === "before" ? p.beforeProjectId : p.afterProjectId) === id);
6317
+ return JSON.stringify(index < 0 ? ["project", id] : ["pair", index]);
6318
+ }
6319
+ function comparisonNodeIdentity(node, side, identity) {
6320
+ if (!identity || node.type !== "subGraph" && node.type !== "referencedGraphAlias") return node;
6321
+ const field2 = node.type === "subGraph" ? "targetProjectId" : "projectId";
6322
+ const data = (value) => {
6323
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
6324
+ const record4 = value;
6325
+ return typeof record4[field2] === "string" ? { ...record4, [field2]: comparisonProjectIdentity(record4[field2], side, identity) } : value;
6326
+ };
6327
+ return {
6328
+ ...node,
6329
+ data: data(node.data),
6330
+ ...node.variants ? { variants: node.variants.map((v) => ({ ...v, data: data(v.data) })) } : {}
6331
+ };
6332
+ }
6333
+
6316
6334
  // src/utils/projectComparison/nodes.ts
6317
6335
  function getProjectNodeFieldComparisons(comparison) {
6318
6336
  const before = comparison.before;
@@ -6320,12 +6338,22 @@ function getProjectNodeFieldComparisons(comparison) {
6320
6338
  if (!before || !after) {
6321
6339
  return [];
6322
6340
  }
6323
- return getChangedValueComparisons([], getComparableNodeRecord(before), getComparableNodeRecord(after));
6341
+ const rawBefore = getComparableNodeRecord(before);
6342
+ const rawAfter = getComparableNodeRecord(after);
6343
+ const at = (record4, path) => path.reduce(
6344
+ (value, key) => value && typeof value === "object" ? value[key] : void 0,
6345
+ record4
6346
+ );
6347
+ return getChangedValueComparisons(
6348
+ [],
6349
+ getComparableNodeRecord(comparisonNodeIdentity(before, "before", comparison.identity)),
6350
+ getComparableNodeRecord(comparisonNodeIdentity(after, "after", comparison.identity))
6351
+ ).map((change) => ({ ...change, before: at(rawBefore, change.path), after: at(rawAfter, change.path) }));
6324
6352
  }
6325
6353
  function getComparableGraphNodes(nodes) {
6326
6354
  return nodes.filter((node) => node.type !== "comment");
6327
6355
  }
6328
- function compareNodes(beforeNodes, afterNodes) {
6356
+ function compareNodes(beforeNodes, afterNodes, identity) {
6329
6357
  const beforeById = new Map(beforeNodes.map((node) => [node.id, node]));
6330
6358
  const afterById = new Map(afterNodes.map((node) => [node.id, node]));
6331
6359
  const nodeIds = unionKeys(Object.fromEntries(beforeById), Object.fromEntries(afterById));
@@ -6343,9 +6371,13 @@ function compareNodes(beforeNodes, afterNodes) {
6343
6371
  nodeId,
6344
6372
  {
6345
6373
  id: nodeId,
6346
- kind: areComparisonNodesEqual(before, after) ? "unchanged" : "changed",
6374
+ kind: areComparisonNodesEqual(
6375
+ before && comparisonNodeIdentity(before, "before", identity),
6376
+ after && comparisonNodeIdentity(after, "after", identity)
6377
+ ) ? "unchanged" : "changed",
6347
6378
  before,
6348
- after
6379
+ after,
6380
+ ...identity ? { identity } : {}
6349
6381
  }
6350
6382
  ];
6351
6383
  })
@@ -6425,7 +6457,7 @@ function createEmptyProjectSummary() {
6425
6457
  }
6426
6458
 
6427
6459
  // src/utils/projectComparison/graphs.ts
6428
- function compareGraphs(id, before, after) {
6460
+ function compareGraphs(id, before, after, identity) {
6429
6461
  if (!before && after) {
6430
6462
  return createOneSidedGraphComparison(id, after, "added");
6431
6463
  }
@@ -6435,7 +6467,7 @@ function compareGraphs(id, before, after) {
6435
6467
  if (!before || !after) {
6436
6468
  throw new Error(`Cannot compare missing graph ${id}`);
6437
6469
  }
6438
- const nodes = compareNodes(getComparableGraphNodes(before.nodes), getComparableGraphNodes(after.nodes));
6470
+ const nodes = compareNodes(getComparableGraphNodes(before.nodes), getComparableGraphNodes(after.nodes), identity);
6439
6471
  const connections = compareConnections(
6440
6472
  getComparableGraphConnections(before.connections, before.nodes),
6441
6473
  getComparableGraphConnections(after.connections, after.nodes)
@@ -6486,24 +6518,30 @@ function createOneSidedConnectionComparisons(connections, kind) {
6486
6518
  }
6487
6519
 
6488
6520
  // src/utils/projectComparison.ts
6489
- function compareProjects(before, after) {
6521
+ function compareProjects(before, after, identity) {
6490
6522
  const graphIds = unionKeys(before.graphs, after.graphs);
6491
6523
  const graphs = Object.fromEntries(
6492
- graphIds.map((graphId2) => [graphId2, compareGraphs(graphId2, before.graphs[graphId2], after.graphs[graphId2])])
6524
+ graphIds.map((graphId2) => [
6525
+ graphId2,
6526
+ compareGraphs(graphId2, before.graphs[graphId2], after.graphs[graphId2], identity)
6527
+ ])
6493
6528
  );
6494
- const nodePrefabs = compareNodePrefabs(before.nodePrefabs ?? {}, after.nodePrefabs ?? {});
6529
+ const nodePrefabs = compareNodePrefabs(before.nodePrefabs ?? {}, after.nodePrefabs ?? {}, identity);
6495
6530
  const uiGraphs = compareUiGraphs(before.uiGraphs ?? {}, after.uiGraphs ?? {});
6496
6531
  return {
6497
6532
  beforeProjectId: before.metadata.id,
6498
6533
  afterProjectId: after.metadata.id,
6499
- metadataChanged: !areComparisonValuesEqual(before.metadata, after.metadata),
6534
+ metadataChanged: !areComparisonValuesEqual(
6535
+ identity ? { ...before.metadata, id: comparisonProjectIdentity(before.metadata.id, "before", identity), path: void 0 } : before.metadata,
6536
+ identity ? { ...after.metadata, id: comparisonProjectIdentity(after.metadata.id, "after", identity), path: void 0 } : after.metadata
6537
+ ),
6500
6538
  graphs,
6501
6539
  nodePrefabs,
6502
6540
  uiGraphs,
6503
6541
  summary: summarizeProjectComparison(graphs, nodePrefabs, uiGraphs)
6504
6542
  };
6505
6543
  }
6506
- function compareNodePrefabs(before, after) {
6544
+ function compareNodePrefabs(before, after, identity) {
6507
6545
  const prefabIds = unionKeys(before, after);
6508
6546
  return Object.fromEntries(
6509
6547
  prefabIds.map((prefabId) => {
@@ -6518,7 +6556,9 @@ function compareNodePrefabs(before, after) {
6518
6556
  if (!beforePrefab || !afterPrefab) {
6519
6557
  throw new Error(`Cannot compare missing library node ${prefabId}`);
6520
6558
  }
6521
- const sourceNodeComparison = Object.values(compareNodes([beforePrefab.sourceNode], [afterPrefab.sourceNode]))[0];
6559
+ const sourceNodeComparison = Object.values(
6560
+ compareNodes([beforePrefab.sourceNode], [afterPrefab.sourceNode], identity)
6561
+ )[0];
6522
6562
  return [
6523
6563
  prefabId,
6524
6564
  {
@@ -8163,15 +8203,18 @@ function getGraphBoundaryOutputDefinitions(boundary, outputPortOrder) {
8163
8203
  })
8164
8204
  );
8165
8205
  }
8166
- function buildGraphBoundaryInputData(boundary, inputs, defaults) {
8206
+ function buildGraphBoundaryInputData(boundary, inputs, defaults, previousBoundary) {
8167
8207
  const inputData = {};
8208
+ const callerPortIds = new Set(boundary.inputs.map((input) => input.portId));
8168
8209
  for (const input of boundary.inputs) {
8169
8210
  const inputValue = inputs[input.portId];
8170
8211
  if (inputValue != null) {
8171
8212
  inputData[input.portId] = inputValue;
8172
8213
  continue;
8173
8214
  }
8174
- const defaultValue = (defaults == null ? void 0 : defaults[input.portId]) ?? (defaults == null ? void 0 : defaults[input.id]);
8215
+ const defaultValue = (defaults == null ? void 0 : defaults[input.portId]) ?? (!callerPortIds.has(input.id) && !(previousBoundary == null ? void 0 : previousBoundary.inputs.some(
8216
+ (previous) => previous.portId !== input.portId && (previous.portId === input.id || previous.id === input.id)
8217
+ )) ? defaults == null ? void 0 : defaults[input.id] : void 0);
8175
8218
  if (defaultValue != null) {
8176
8219
  inputData[input.portId] = defaultValue;
8177
8220
  }
@@ -11942,51 +11985,32 @@ function getEventProjectScope(data) {
11942
11985
  }
11943
11986
 
11944
11987
  // src/model/nodes/SubGraphNode.ts
11945
- function getSubgraphTargetBoundaryChange(expected, actual) {
11946
- if (!expected) return null;
11947
- for (const side of ["inputs", "outputs"]) {
11948
- for (const port of expected[side]) {
11949
- const match9 = actual[side].find(
11950
- (candidate) => port.nodeId ? candidate.nodeId === port.nodeId : candidate.portId === port.portId
11951
- );
11952
- if ((match9 == null ? void 0 : match9.dataType) !== port.dataType) {
11953
- return { side: side === "inputs" ? "input" : "output", id: port.id };
11954
- }
11955
- }
11956
- const callerIds = /* @__PURE__ */ new Set();
11957
- for (const port of actual[side]) {
11958
- const saved = expected[side].find(
11959
- (candidate) => candidate.nodeId ? candidate.nodeId === port.nodeId : candidate.portId === port.portId
11960
- );
11961
- const callerId = (saved == null ? void 0 : saved.portId) ?? port.portId;
11962
- if (callerIds.has(callerId)) {
11963
- return { side: side === "inputs" ? "input" : "output", id: port.id };
11964
- }
11965
- callerIds.add(callerId);
11966
- }
11967
- }
11968
- return null;
11969
- }
11970
11988
  function reconcileSubgraphTargetBoundary(expected, actual) {
11971
11989
  if (!expected) return actual;
11972
11990
  return {
11973
- inputs: actual.inputs.map((port) => {
11974
- const saved = expected.inputs.find(
11975
- (candidate) => candidate.nodeId ? candidate.nodeId === port.nodeId : candidate.portId === port.portId
11976
- );
11977
- return saved && saved.dataType === port.dataType ? { ...port, portId: saved.portId } : port;
11978
- }),
11979
- outputs: actual.outputs.map((port) => {
11980
- const saved = expected.outputs.find(
11981
- (candidate) => candidate.nodeId ? candidate.nodeId === port.nodeId : candidate.portId === port.portId
11982
- );
11983
- return saved && saved.dataType === port.dataType ? { ...port, portId: saved.portId } : port;
11984
- })
11991
+ inputs: reconcileSubgraphPorts(expected.inputs, actual.inputs),
11992
+ outputs: reconcileSubgraphPorts(expected.outputs, actual.outputs)
11985
11993
  };
11986
11994
  }
11987
- function getSubgraphTargetBoundaryIssue(expected, actual) {
11988
- const change = getSubgraphTargetBoundaryChange(expected, actual);
11989
- return change ? `The selected project's graph changed its ${change.side} "${change.id}". Re-select the graph and review its connections.` : null;
11995
+ function reconcileSubgraphPorts(expected, actual) {
11996
+ const matches = actual.map(
11997
+ (port) => expected.find((saved) => saved.nodeId ? saved.nodeId === port.nodeId : saved.portId === port.portId)
11998
+ );
11999
+ const reserved = new Set(matches.flatMap((saved) => saved ? [saved.portId] : []));
12000
+ const used = /* @__PURE__ */ new Set();
12001
+ return actual.map((port, index) => {
12002
+ const saved = matches[index];
12003
+ let portId = (saved == null ? void 0 : saved.portId) ?? port.portId;
12004
+ if (used.has(portId) || !saved && reserved.has(portId)) {
12005
+ const base = port.nodeId ?? port.portId;
12006
+ portId = base;
12007
+ for (let suffix = 2; used.has(portId) || reserved.has(portId); suffix++) {
12008
+ portId = `${base}:${suffix}`;
12009
+ }
12010
+ }
12011
+ used.add(portId);
12012
+ return portId === port.portId ? port : { ...port, portId };
12013
+ });
11990
12014
  }
11991
12015
  var SubGraphNodeImpl = class extends NodeImpl {
11992
12016
  static create() {
@@ -12040,13 +12064,10 @@ var SubGraphNodeImpl = class extends NodeImpl {
12040
12064
  })];
12041
12065
  }
12042
12066
  getTargetBoundary(project, referencedProjects, definitionContext) {
12043
- if (this.data.targetProjectId && this.data.targetBoundary) {
12044
- const target2 = this.getTargetProject(project, referencedProjects);
12045
- const actual = target2 && this.getBoundary(target2, definitionContext);
12046
- return actual && !getSubgraphTargetBoundaryChange(this.data.targetBoundary, actual) ? reconcileSubgraphTargetBoundary(this.data.targetBoundary, actual) : this.data.targetBoundary;
12047
- }
12048
12067
  const target = this.getTargetProject(project, referencedProjects);
12049
- return (target && this.getBoundary(target, definitionContext)) ?? (this.data.targetProjectId ? this.data.targetBoundary : void 0);
12068
+ const actual = target && this.getBoundary(target, definitionContext);
12069
+ if (!this.data.targetProjectId) return actual;
12070
+ return actual ? reconcileSubgraphTargetBoundary(this.data.targetBoundary, actual) : this.data.targetBoundary;
12050
12071
  }
12051
12072
  getEditors(context) {
12052
12073
  const definitions = [
@@ -12118,12 +12139,13 @@ var SubGraphNodeImpl = class extends NodeImpl {
12118
12139
  throw new Error(`SubGraphNode requires a graph with id ${this.data.graphId} to be present in the project.`);
12119
12140
  }
12120
12141
  const boundary = ((_a = context.getGraphBoundary) == null ? void 0 : _a.call(context, target, this.data.graphId)) ?? getGraphBoundary(target, this.data.graphId);
12121
- if (this.data.targetProjectId) {
12122
- const boundaryIssue = getSubgraphTargetBoundaryIssue(this.data.targetBoundary, boundary);
12123
- if (boundaryIssue) throw new Error(boundaryIssue);
12124
- }
12125
12142
  const callerBoundary = this.data.targetProjectId ? reconcileSubgraphTargetBoundary(this.data.targetBoundary, boundary) : boundary;
12126
- const callerInputData = buildGraphBoundaryInputData(callerBoundary, inputs, this.data.inputData);
12143
+ const callerInputData = buildGraphBoundaryInputData(
12144
+ callerBoundary,
12145
+ inputs,
12146
+ this.data.inputData,
12147
+ this.data.targetProjectId ? this.data.targetBoundary : void 0
12148
+ );
12127
12149
  const inputData = this.data.targetProjectId ? {} : callerInputData;
12128
12150
  if (this.data.targetProjectId) {
12129
12151
  for (const input of callerBoundary.inputs) {
@@ -12198,7 +12220,7 @@ var SubGraphNodeImpl = class extends NodeImpl {
12198
12220
  value: void 0
12199
12221
  };
12200
12222
  }
12201
- if (outputs["duration"] == null) {
12223
+ if (!getSubgraphOutputNames(callerBoundary).has("duration") && outputs["duration"] == null) {
12202
12224
  outputs["duration"] = {
12203
12225
  type: "number",
12204
12226
  value: duration
@@ -12239,10 +12261,13 @@ var SubGraphNodeImpl = class extends NodeImpl {
12239
12261
  }
12240
12262
  };
12241
12263
  var subGraphNode = nodeDefinition(SubGraphNodeImpl, "Subgraph");
12264
+ function getSubgraphOutputNames(boundary) {
12265
+ return new Set(boundary.outputs.flatMap((output) => [output.id, output.portId]));
12266
+ }
12242
12267
  function mapSubgraphTargetOutputs(boundary, graphOutputs) {
12243
- const targetNames = new Set(boundary.outputs.map((output) => output.id));
12268
+ const ownedNames = getSubgraphOutputNames(boundary);
12244
12269
  const outputs = Object.fromEntries(
12245
- Object.entries(graphOutputs).filter(([name]) => !targetNames.has(name))
12270
+ Object.entries(graphOutputs).filter(([name]) => !ownedNames.has(name))
12246
12271
  );
12247
12272
  for (const output of boundary.outputs) {
12248
12273
  if (Object.hasOwn(graphOutputs, output.id)) outputs[output.portId] = graphOutputs[output.id];
@@ -12266,13 +12291,14 @@ function buildOptimizedSubgraphOutputs(boundary, requestedOutputIds, graphOutput
12266
12291
  value: void 0
12267
12292
  };
12268
12293
  }
12269
- if (!boundary.outputs.some((output) => output.id === "cost")) {
12294
+ const ownedNames = getSubgraphOutputNames(boundary);
12295
+ if (!ownedNames.has("cost")) {
12270
12296
  outputs["cost"] = graphOutputs["cost"] ?? { type: "number", value: 0 };
12271
12297
  }
12272
- if (!boundary.outputs.some((output) => output.id === "costBreakdown") && graphOutputs["costBreakdown"]) {
12298
+ if (!ownedNames.has("costBreakdown") && graphOutputs["costBreakdown"]) {
12273
12299
  outputs["costBreakdown"] = graphOutputs["costBreakdown"];
12274
12300
  }
12275
- if (!boundary.outputs.some((output) => output.id === "duration")) {
12301
+ if (!ownedNames.has("duration")) {
12276
12302
  outputs["duration"] = { type: "number", value: duration };
12277
12303
  }
12278
12304
  return outputs;
@@ -12310,7 +12336,7 @@ function getCallerProject(owner, caller, projects) {
12310
12336
  function getCallerBoundary(caller, target) {
12311
12337
  if (caller.type !== "subGraph") return void 0;
12312
12338
  const actual = getGraphBoundary(target, caller.data.graphId);
12313
- if (!actual || getSubgraphTargetBoundaryChange(caller.data.targetBoundary, actual)) return void 0;
12339
+ if (!actual) return void 0;
12314
12340
  return reconcileSubgraphTargetBoundary(caller.data.targetBoundary, actual);
12315
12341
  }
12316
12342
  function canForwardGraphCallerOutputPartials(node) {
@@ -12432,7 +12458,8 @@ function getProjectStreamingOutputWatchConnections({
12432
12458
  const watchInputs = [];
12433
12459
  for (const [candidate, context] of contexts) {
12434
12460
  for (const node of Object.values(context.nodes)) {
12435
- if (node.type !== "watchStreamingOutput" && node.type !== "catchStreamingChunks" || node.disabled || isFrozen(context.project, candidate, node)) continue;
12461
+ if (node.type !== "watchStreamingOutput" && node.type !== "catchStreamingChunks" || node.disabled || isFrozen(context.project, candidate, node))
12462
+ continue;
12436
12463
  const inputs = context.incoming(node.id).filter((edge) => edge.inputId === "stream");
12437
12464
  if (inputs.length === 1) watchInputs.push({ graph: candidate, edge: inputs[0] });
12438
12465
  }
@@ -12530,7 +12557,13 @@ function getProjectStreamableGraphOutputNodeIdsByGraph({
12530
12557
  nodes.push({ id: callerId, type: "subGraph", title: "Probe", data: { graphId: graphId2 }, visualData: { x: 0, y: 0 } });
12531
12558
  for (const output of boundary.outputs) {
12532
12559
  const watchId = (0, import_non_secure9.nanoid)();
12533
- nodes.push({ id: watchId, type: "watchStreamingOutput", title: "Probe watch", data: {}, visualData: { x: 0, y: 0 } });
12560
+ nodes.push({
12561
+ id: watchId,
12562
+ type: "watchStreamingOutput",
12563
+ title: "Probe watch",
12564
+ data: {},
12565
+ visualData: { x: 0, y: 0 }
12566
+ });
12534
12567
  probes.push({
12535
12568
  graphId: graphId2,
12536
12569
  outputNodeId: output.nodeId,
@@ -19050,11 +19083,32 @@ function toProfileAttemptTrace(event) {
19050
19083
  const { type: _type, execution: _execution, ...trace } = event;
19051
19084
  return trace;
19052
19085
  }
19086
+ function summarizeAgentResponseCosts(modelCalls, profileAttempts) {
19087
+ var _a;
19088
+ let knownCostUsd = 0;
19089
+ let knownCount = 0;
19090
+ let callCount = 0;
19091
+ const add = (cost) => {
19092
+ callCount++;
19093
+ if (cost != null && Number.isFinite(cost) && cost >= 0) {
19094
+ knownCostUsd += cost;
19095
+ knownCount++;
19096
+ }
19097
+ };
19098
+ for (const call of modelCalls) add(call.pricing.status === "known" ? call.pricing.costUsd : void 0);
19099
+ for (const attempt of profileAttempts) {
19100
+ if (attempt.family === "classifier" && attempt.attemptIndex != null) add((_a = attempt.classifierUsage) == null ? void 0 : _a.estimatedCostUsd);
19101
+ }
19102
+ if (!Number.isFinite(knownCostUsd)) return { knownCostUsd: 0, costStatus: "unknown" };
19103
+ return {
19104
+ knownCostUsd,
19105
+ costStatus: knownCount === 0 ? "unknown" : knownCount < callCount ? "partial" : "known"
19106
+ };
19107
+ }
19053
19108
  function summarizeAgentResponseCalls(modelCalls, profileAttempts, toolCalls) {
19054
19109
  const classifierCalls = profileAttempts.filter(
19055
19110
  (attempt) => attempt.family === "classifier" && attempt.attemptIndex != null
19056
19111
  );
19057
- const accountedCallCount = modelCalls.length + classifierCalls.length;
19058
19112
  const usageKeys = ["promptTokens", "completionTokens", "totalTokens", "cachedTokens", "reasoningTokens"];
19059
19113
  const usage = Object.fromEntries(
19060
19114
  usageKeys.flatMap((key) => {
@@ -19072,19 +19126,6 @@ function summarizeAgentResponseCalls(modelCalls, profileAttempts, toolCalls) {
19072
19126
  return values2.length === 0 ? [] : [[key, values2.reduce((sum, value) => sum + value, 0)]];
19073
19127
  })
19074
19128
  );
19075
- const knownCosts = [
19076
- ...modelCalls.map((call) => call.pricing.costUsd).filter((value) => value != null && Number.isFinite(value)),
19077
- ...classifierCalls.flatMap(
19078
- (attempt) => {
19079
- var _a;
19080
- return ((_a = attempt.classifierUsage) == null ? void 0 : _a.estimatedCostUsd) == null ? [] : [attempt.classifierUsage.estimatedCostUsd];
19081
- }
19082
- )
19083
- ];
19084
- const unknownCostCount = modelCalls.filter((call) => call.pricing.status === "unknown" || !Number.isFinite(call.pricing.costUsd)).length + classifierCalls.filter((attempt) => {
19085
- var _a;
19086
- return ((_a = attempt.classifierUsage) == null ? void 0 : _a.estimatedCostUsd) == null;
19087
- }).length;
19088
19129
  const profileTransitions = countProfileFallbacks(modelCalls, profileAttempts);
19089
19130
  return {
19090
19131
  modelCallCount: modelCalls.length,
@@ -19093,8 +19134,7 @@ function summarizeAgentResponseCalls(modelCalls, profileAttempts, toolCalls) {
19093
19134
  retryCount: modelCalls.filter((call) => call.attemptIndex > 0).length + classifierCalls.filter((attempt) => attempt.attemptIndex > 0).length,
19094
19135
  fallbackCount: profileTransitions,
19095
19136
  ...usage,
19096
- knownCostUsd: knownCosts.reduce((sum, value) => sum + value, 0),
19097
- costStatus: accountedCallCount === 0 || unknownCostCount === accountedCallCount ? "unknown" : unknownCostCount > 0 ? "partial" : "known"
19137
+ ...summarizeAgentResponseCosts(modelCalls, profileAttempts)
19098
19138
  };
19099
19139
  }
19100
19140
  function countProfileFallbacks(modelCalls, profileAttempts) {
@@ -48324,50 +48364,66 @@ function samePluginRequirement(left, right) {
48324
48364
  return left.package === right.package && left.tag === right.tag;
48325
48365
  return left.type === "uri" && right.type === "uri" && left.uri === right.uri;
48326
48366
  }
48367
+ function describeBundleCallSource(source) {
48368
+ return `node "${source.nodeTitle}" (${source.nodeId}) in graph "${source.graphName}" of project "${source.projectName}"`;
48369
+ }
48327
48370
  function* projectSubgraphs(project) {
48371
+ var _a;
48328
48372
  for (const [sourceGraphId, graph] of Object.entries(project.graphs)) {
48329
48373
  for (const authored of graph.nodes) {
48330
48374
  const node = resolveNodePrefabInstance(project, authored);
48331
- if (!node.disabled && node.type === "nodePrefabInstance")
48332
- throw new ProjectBundleError(`Bundle contains an unresolved library node ${node.id}.`);
48333
- if (node.disabled || node.type !== "subGraph") continue;
48375
+ if (node.disabled || node.type !== "subGraph" && node.type !== "nodePrefabInstance") continue;
48376
+ const source = {
48377
+ projectName: project.metadata.title || project.metadata.id,
48378
+ graphName: ((_a = graph.metadata) == null ? void 0 : _a.name) || sourceGraphId,
48379
+ nodeId: authored.id,
48380
+ nodeTitle: node.title || "Subgraph"
48381
+ };
48382
+ if (node.type === "nodePrefabInstance")
48383
+ throw new ProjectBundleError(`Bundle contains an unresolved library ${describeBundleCallSource(source)}.`);
48334
48384
  const data = node.data;
48335
48385
  if (data.targetProjectId) {
48336
48386
  if (data.targetVersion !== void 0 && data.targetVersion !== "latest" && data.targetVersion !== "published")
48337
- throw new ProjectBundleError("Invalid Subgraph project version.");
48387
+ throw new ProjectBundleError(
48388
+ `Invalid Subgraph project version. Check Subgraph ${describeBundleCallSource(source)}.`
48389
+ );
48338
48390
  } else if (data.targetScope) {
48339
- throw new ProjectBundleError(`Subgraph ${node.title || node.id} has no selected project.`);
48391
+ throw new ProjectBundleError(
48392
+ `Subgraph has no selected project. Check Subgraph ${describeBundleCallSource(source)}.`
48393
+ );
48340
48394
  }
48341
- yield { sourceGraphId, data };
48395
+ yield { sourceGraphId, data, source };
48342
48396
  }
48343
48397
  }
48344
48398
  }
48345
48399
  function listProjectBundleCalls(project) {
48346
48400
  const calls = [];
48347
- for (const { data } of projectSubgraphs(project)) {
48401
+ for (const { data, source } of projectSubgraphs(project)) {
48348
48402
  if (data.targetProjectId)
48349
48403
  calls.push({
48350
48404
  projectId: data.targetProjectId,
48351
48405
  version: data.targetVersion ?? "latest",
48352
48406
  graphId: data.graphId,
48353
- boundary: data.targetBoundary
48407
+ boundary: data.targetBoundary,
48408
+ source
48354
48409
  });
48355
48410
  }
48356
48411
  return calls;
48357
48412
  }
48358
- function validateProjectBundleCall(call, target) {
48359
- if (!Object.hasOwn(target.graphs, call.graphId))
48360
- throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}.`);
48361
- const boundary = getGraphBoundary(target, call.graphId);
48362
- if (!boundary) throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}.`);
48363
- const issue = getSubgraphTargetBoundaryIssue(call.boundary, boundary);
48364
- if (issue) throw new ProjectBundleError(`Subgraph dependency has an incompatible boundary. ${issue}`);
48413
+ function validateProjectBundleCall(call, target, selectedVersion) {
48414
+ const graph = Object.hasOwn(target.graphs, call.graphId) ? target.graphs[call.graphId] : void 0;
48415
+ if (graph) return;
48416
+ const source = call.source ? `Check Subgraph ${describeBundleCallSource(call.source)}. ` : "";
48417
+ const version = selectedVersion ? ` (${selectedVersion === "published" ? "Published" : "Saved latest"})` : "";
48418
+ const location = `${source}Target: graph "${call.graphId}" in project "${target.metadata.title || target.metadata.id}"${version}.`;
48419
+ throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}. ${location}`);
48365
48420
  }
48366
48421
  function validateProjectBundleProjects(manifest, projects) {
48367
48422
  const targets = new Map(manifest.targets.map((t) => [projectBundleTargetKey(t.projectId, t.version), t.artifact]));
48368
48423
  const references = new Map(manifest.references.map((r) => [r.projectId, r.artifact]));
48369
48424
  const plugins2 = new Map(manifest.plugins.map((plugin) => [plugin.id, plugin]));
48370
48425
  const members = manifest.workspace ? new Set(manifest.workspace.members.map((m) => m.projectId)) : void 0;
48426
+ const versions = new Map(manifest.artifacts.map((artifact) => [artifact.id, artifact.version]));
48371
48427
  const vertices = /* @__PURE__ */ new Map();
48372
48428
  const graphKey = (artifact, graph) => JSON.stringify([artifact, graph]);
48373
48429
  for (const artifact of manifest.artifacts) {
@@ -48383,7 +48439,7 @@ function validateProjectBundleProjects(manifest, projects) {
48383
48439
  }
48384
48440
  for (const artifact of manifest.artifacts) {
48385
48441
  const project = projects.get(artifact.id);
48386
- for (const { sourceGraphId, data } of projectSubgraphs(project)) {
48442
+ for (const { sourceGraphId, data, source } of projectSubgraphs(project)) {
48387
48443
  let targetId = artifact.id;
48388
48444
  if (data.targetProjectId) {
48389
48445
  if ((members == null ? void 0 : members.has(data.targetProjectId)) && !members.has(project.metadata.id))
@@ -48394,13 +48450,16 @@ function validateProjectBundleProjects(manifest, projects) {
48394
48450
  projectId: data.targetProjectId,
48395
48451
  version: data.targetVersion ?? "latest",
48396
48452
  graphId: data.graphId,
48397
- boundary: data.targetBoundary
48453
+ boundary: data.targetBoundary,
48454
+ source
48398
48455
  };
48399
48456
  const id = targets.get(projectBundleTargetKey(call.projectId, call.version));
48400
48457
  const target2 = id && projects.get(id);
48401
48458
  if (!id || !target2)
48402
- throw new ProjectBundleError(`Bundle is missing Subgraph ${call.projectId}:${call.version}:${call.graphId}`);
48403
- validateProjectBundleCall(call, target2);
48459
+ throw new ProjectBundleError(
48460
+ `Bundle is missing Subgraph ${call.projectId}:${call.version}:${call.graphId}. Check Subgraph ${describeBundleCallSource(source)}.`
48461
+ );
48462
+ validateProjectBundleCall(call, target2, versions.get(id));
48404
48463
  targetId = id;
48405
48464
  }
48406
48465
  const target = vertices.get(graphKey(targetId, data.graphId));
@@ -56465,8 +56524,6 @@ var Rivet = void 0;
56465
56524
  getSingleNodeStream,
56466
56525
  getStoredValueNode,
56467
56526
  getSubgraphProjectKey,
56468
- getSubgraphTargetBoundaryChange,
56469
- getSubgraphTargetBoundaryIssue,
56470
56527
  getToolNodeBodyPreview,
56471
56528
  getUiGraphActionComponent,
56472
56529
  getUiGraphActionInputBindings,
@@ -56770,6 +56827,7 @@ var Rivet = void 0;
56770
56827
  subGraphNode,
56771
56828
  subqClassifierProvider,
56772
56829
  summarizeAgentResponseCalls,
56830
+ summarizeAgentResponseCosts,
56773
56831
  summarizeChatV2RequestPlan,
56774
56832
  summarizeDataValueForLog,
56775
56833
  summarizeErrorForLog,