@valerypopoff/rivet2-core 2.24.0 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/bundle.cjs +273 -28
  2. package/dist/cjs/bundle.cjs.map +3 -3
  3. package/dist/cjs/interpolationRuntime.cjs +23 -0
  4. package/dist/cjs/interpolationRuntime.cjs.map +3 -3
  5. package/dist/cjs/serialization.cjs +1 -0
  6. package/dist/cjs/serialization.cjs.map +2 -2
  7. package/dist/esm/exports.js +3 -0
  8. package/dist/esm/model/DatasetOwnership.js +9 -0
  9. package/dist/esm/model/GraphExecutionState.js +3 -0
  10. package/dist/esm/model/GraphProcessor.js +62 -1
  11. package/dist/esm/model/RunCostLedger.js +58 -0
  12. package/dist/esm/model/chat-v2/chatV2CallObserver.js +2 -2
  13. package/dist/esm/model/chat-v2/chatV2Outputs.js +1 -1
  14. package/dist/esm/model/chat-v2/chatV2Pipeline.js +5 -0
  15. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +3 -0
  16. package/dist/esm/model/chat-v2/llmModelCandidate.js +3 -0
  17. package/dist/esm/model/chat-v2/llmProfile.js +2 -0
  18. package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +1 -0
  19. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +2 -1
  20. package/dist/esm/model/chat-v2/modelRegistry.js +12 -3
  21. package/dist/esm/model/classifier/profile.js +11 -3
  22. package/dist/esm/model/classifier/profileExecution.js +2 -1
  23. package/dist/esm/model/classifier/providers.js +25 -14
  24. package/dist/esm/model/nodes/ClassifierEvaluateNode.js +16 -5
  25. package/dist/esm/model/nodes/ClassifierProfileNode.js +2 -0
  26. package/dist/esm/model/tokenPricing.js +52 -0
  27. package/dist/esm/model/tokenPricingEditor.js +9 -0
  28. package/dist/types/exports.d.ts +3 -0
  29. package/dist/types/model/DatasetOwnership.d.ts +5 -0
  30. package/dist/types/model/GraphExecutionState.d.ts +2 -0
  31. package/dist/types/model/GraphProcessor.d.ts +3 -0
  32. package/dist/types/model/RunCostLedger.d.ts +19 -0
  33. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +1 -1
  34. package/dist/types/model/chat-v2/chatV2Types.d.ts +2 -0
  35. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +3 -1
  36. package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +7 -5
  37. package/dist/types/model/chat-v2/modelRegistry.d.ts +7 -1
  38. package/dist/types/model/classifier/profile.d.ts +3 -1
  39. package/dist/types/model/classifier/profileExecution.d.ts +1 -0
  40. package/dist/types/model/classifier/providers.d.ts +4 -1
  41. package/dist/types/model/tokenPricing.d.ts +18 -0
  42. package/dist/types/model/tokenPricingEditor.d.ts +4 -0
  43. package/package.json +1 -1
@@ -278,6 +278,7 @@ __export(src_exports, {
278
278
  calculateChatV2Cost: () => calculateChatV2Cost,
279
279
  calculateChatV2UsageCost: () => calculateChatV2UsageCost,
280
280
  calculateClassifierUsageCost: () => calculateClassifierUsageCost,
281
+ calculateTokenUsageCost: () => calculateTokenUsageCost,
281
282
  callGraphNode: () => callGraphNode,
282
283
  canBeCoerced: () => canBeCoerced,
283
284
  canBeCoercedAny: () => canBeCoercedAny,
@@ -428,6 +429,7 @@ __export(src_exports, {
428
429
  getChatV2ModelRegistry: () => getChatV2ModelRegistry,
429
430
  getChatV2ProviderCapabilities: () => getChatV2ProviderCapabilities,
430
431
  getChatV2ProviderLabel: () => getChatV2ProviderLabel,
432
+ getChatV2SystemTokenPricing: () => getChatV2SystemTokenPricing,
431
433
  getClassifierCredentialNamesForDisplay: () => getClassifierCredentialNamesForDisplay,
432
434
  getClassifierEvaluateBodySections: () => getClassifierEvaluateBodySections,
433
435
  getClassifierModelEditor: () => getClassifierModelEditor,
@@ -435,6 +437,7 @@ __export(src_exports, {
435
437
  getClassifierProviderEnvironmentVariableNames: () => getClassifierProviderEnvironmentVariableNames,
436
438
  getClassifierQuestionBodySections: () => getClassifierQuestionBodySections,
437
439
  getClassifierRequestCount: () => getClassifierRequestCount,
440
+ getClassifierSystemTokenPricing: () => getClassifierSystemTokenPricing,
438
441
  getCodeOutputFields: () => getCodeOutputFields,
439
442
  getCodeOutputKeys: () => getCodeOutputKeys,
440
443
  getCommonChatV2Editors: () => getCommonChatV2Editors,
@@ -570,6 +573,7 @@ __export(src_exports, {
570
573
  isLLMChatV2StructuredResponseFormat: () => isLLMChatV2StructuredResponseFormat,
571
574
  isNodePrefabInstanceNode: () => isNodePrefabInstanceNode,
572
575
  isNotFunctionDataValue: () => isNotFunctionDataValue,
576
+ isReportedTokenCount: () => isReportedTokenCount,
573
577
  isReservedKnowledgeObjectKey: () => isReservedKnowledgeObjectKey,
574
578
  isRivetWebAppRunTerminalEvent: () => isRivetWebAppRunTerminalEvent,
575
579
  isRuntimeDebugLoggingEnabled: () => isRuntimeDebugLoggingEnabled,
@@ -713,6 +717,7 @@ __export(src_exports, {
713
717
  registerIntegration: () => registerIntegration,
714
718
  registerKnowledgeStoreProvider: () => registerKnowledgeStoreProvider,
715
719
  registerPluginsIntoRegistry: () => registerPluginsIntoRegistry,
720
+ remapOwnedDatasets: () => remapOwnedDatasets,
716
721
  removeKnowledgeStoreConnectionCredentials: () => removeKnowledgeStoreConnectionCredentials,
717
722
  renderUiGraphOutputValue: () => renderUiGraphOutputValue,
718
723
  replaceDatasetNode: () => replaceDatasetNode,
@@ -804,6 +809,7 @@ __export(src_exports, {
804
809
  validateProjectGlobalVariables: () => validateProjectGlobalVariables,
805
810
  validateProjectUiGraphActionBindings: () => validateProjectUiGraphActionBindings,
806
811
  validateProjectUiGraphButtonBindings: () => validateProjectUiGraphButtonBindings,
812
+ validateTokenPricing: () => validateTokenPricing,
807
813
  validateUiGraphActionBindings: () => validateUiGraphActionBindings,
808
814
  validateUiGraphButtonBindings: () => validateUiGraphButtonBindings,
809
815
  vectorNearestNeighborsNode: () => vectorNearestNeighborsNode,
@@ -1066,6 +1072,7 @@ __export(exports_exports, {
1066
1072
  calculateChatV2Cost: () => calculateChatV2Cost,
1067
1073
  calculateChatV2UsageCost: () => calculateChatV2UsageCost,
1068
1074
  calculateClassifierUsageCost: () => calculateClassifierUsageCost,
1075
+ calculateTokenUsageCost: () => calculateTokenUsageCost,
1069
1076
  callGraphNode: () => callGraphNode,
1070
1077
  canBeCoerced: () => canBeCoerced,
1071
1078
  canBeCoercedAny: () => canBeCoercedAny,
@@ -1216,6 +1223,7 @@ __export(exports_exports, {
1216
1223
  getChatV2ModelRegistry: () => getChatV2ModelRegistry,
1217
1224
  getChatV2ProviderCapabilities: () => getChatV2ProviderCapabilities,
1218
1225
  getChatV2ProviderLabel: () => getChatV2ProviderLabel,
1226
+ getChatV2SystemTokenPricing: () => getChatV2SystemTokenPricing,
1219
1227
  getClassifierCredentialNamesForDisplay: () => getClassifierCredentialNamesForDisplay,
1220
1228
  getClassifierEvaluateBodySections: () => getClassifierEvaluateBodySections,
1221
1229
  getClassifierModelEditor: () => getClassifierModelEditor,
@@ -1223,6 +1231,7 @@ __export(exports_exports, {
1223
1231
  getClassifierProviderEnvironmentVariableNames: () => getClassifierProviderEnvironmentVariableNames,
1224
1232
  getClassifierQuestionBodySections: () => getClassifierQuestionBodySections,
1225
1233
  getClassifierRequestCount: () => getClassifierRequestCount,
1234
+ getClassifierSystemTokenPricing: () => getClassifierSystemTokenPricing,
1226
1235
  getCodeOutputFields: () => getCodeOutputFields,
1227
1236
  getCodeOutputKeys: () => getCodeOutputKeys,
1228
1237
  getCommonChatV2Editors: () => getCommonChatV2Editors,
@@ -1358,6 +1367,7 @@ __export(exports_exports, {
1358
1367
  isLLMChatV2StructuredResponseFormat: () => isLLMChatV2StructuredResponseFormat,
1359
1368
  isNodePrefabInstanceNode: () => isNodePrefabInstanceNode,
1360
1369
  isNotFunctionDataValue: () => isNotFunctionDataValue,
1370
+ isReportedTokenCount: () => isReportedTokenCount,
1361
1371
  isReservedKnowledgeObjectKey: () => isReservedKnowledgeObjectKey,
1362
1372
  isRivetWebAppRunTerminalEvent: () => isRivetWebAppRunTerminalEvent,
1363
1373
  isRuntimeDebugLoggingEnabled: () => isRuntimeDebugLoggingEnabled,
@@ -1501,6 +1511,7 @@ __export(exports_exports, {
1501
1511
  registerIntegration: () => registerIntegration,
1502
1512
  registerKnowledgeStoreProvider: () => registerKnowledgeStoreProvider,
1503
1513
  registerPluginsIntoRegistry: () => registerPluginsIntoRegistry,
1514
+ remapOwnedDatasets: () => remapOwnedDatasets,
1504
1515
  removeKnowledgeStoreConnectionCredentials: () => removeKnowledgeStoreConnectionCredentials,
1505
1516
  renderUiGraphOutputValue: () => renderUiGraphOutputValue,
1506
1517
  replaceDatasetNode: () => replaceDatasetNode,
@@ -1592,6 +1603,7 @@ __export(exports_exports, {
1592
1603
  validateProjectGlobalVariables: () => validateProjectGlobalVariables,
1593
1604
  validateProjectUiGraphActionBindings: () => validateProjectUiGraphActionBindings,
1594
1605
  validateProjectUiGraphButtonBindings: () => validateProjectUiGraphButtonBindings,
1606
+ validateTokenPricing: () => validateTokenPricing,
1595
1607
  validateUiGraphActionBindings: () => validateUiGraphActionBindings,
1596
1608
  validateUiGraphButtonBindings: () => validateUiGraphButtonBindings,
1597
1609
  vectorNearestNeighborsNode: () => vectorNearestNeighborsNode,
@@ -1958,6 +1970,7 @@ async function waitForLLMChatV2RetryCooldown(cooldownMs, signal) {
1958
1970
 
1959
1971
  // src/model/chat-v2/llmProfileFieldRegistry.ts
1960
1972
  var llmProfileFieldSpecs = [
1973
+ { key: "tokenPricing" },
1961
1974
  { key: "model", inputId: "model", valueKind: "string" },
1962
1975
  { key: "useModelInput", valueKind: "boolean", resolvedInputToggle: true },
1963
1976
  { key: "temperature", inputId: "temperature", valueKind: "optional-number" },
@@ -3366,6 +3379,47 @@ function normalizeTemperature(value, label = "Temperature") {
3366
3379
  return value;
3367
3380
  }
3368
3381
 
3382
+ // src/model/tokenPricing.ts
3383
+ function isReportedTokenCount(value) {
3384
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
3385
+ }
3386
+ function validateTokenPricing(value) {
3387
+ if (value === void 0) return void 0;
3388
+ if (value === null || typeof value !== "object" || Array.isArray(value))
3389
+ throw new Error("Token pricing override must be an object.");
3390
+ const result = {};
3391
+ for (const key of [
3392
+ "inputPerMillionTokens",
3393
+ "outputPerMillionTokens",
3394
+ "cacheReadPerMillionTokens",
3395
+ "cacheWritePerMillionTokens"
3396
+ ]) {
3397
+ const rate = value[key];
3398
+ if (rate === void 0 && key.startsWith("cache")) continue;
3399
+ if (typeof rate !== "number" || !Number.isFinite(rate) || rate < 0)
3400
+ throw new Error(`Token pricing ${key} must be a finite, non-negative USD rate.`);
3401
+ result[key] = rate;
3402
+ }
3403
+ return result;
3404
+ }
3405
+ function calculateTokenUsageCost(pricing, usage) {
3406
+ try {
3407
+ const validated = validateTokenPricing(pricing);
3408
+ if (!validated) return void 0;
3409
+ pricing = validated;
3410
+ } catch {
3411
+ return void 0;
3412
+ }
3413
+ const { inputTokens, outputTokens, inputTokenDetails } = usage ?? {};
3414
+ const read = (inputTokenDetails == null ? void 0 : inputTokenDetails.cacheReadTokens) === void 0 ? 0 : inputTokenDetails.cacheReadTokens;
3415
+ const write = (inputTokenDetails == null ? void 0 : inputTokenDetails.cacheWriteTokens) === void 0 ? 0 : inputTokenDetails.cacheWriteTokens;
3416
+ if (!isReportedTokenCount(inputTokens) || !isReportedTokenCount(outputTokens) || !isReportedTokenCount(read) || !isReportedTokenCount(write))
3417
+ return void 0;
3418
+ if (read + write > inputTokens) return void 0;
3419
+ const total = ((inputTokens - read - write) * pricing.inputPerMillionTokens + read * (pricing.cacheReadPerMillionTokens ?? pricing.inputPerMillionTokens) + write * (pricing.cacheWritePerMillionTokens ?? pricing.inputPerMillionTokens) + outputTokens * pricing.outputPerMillionTokens) / 1e6;
3420
+ return Number.isFinite(total) && total >= 0 ? total : void 0;
3421
+ }
3422
+
3369
3423
  // src/model/chat-v2/llmProfile.ts
3370
3424
  var credentialSources = /* @__PURE__ */ new Set([
3371
3425
  "input",
@@ -3453,6 +3507,7 @@ function scopeLLMProfileHealthIdentity(profile, fallback) {
3453
3507
  }
3454
3508
  function normalizeConfiguration(data) {
3455
3509
  var _a, _b;
3510
+ data = { ...data, tokenPricing: validateTokenPricing(data.tokenPricing) };
3456
3511
  for (const field2 of llmProfileStringDataKeys) {
3457
3512
  if (typeof data[field2] !== "string") {
3458
3513
  throw new Error(`LLM Profile ${field2} must be a string.`);
@@ -6783,6 +6838,56 @@ function evaluateJsonPath(value, path, wrap = false) {
6783
6838
  });
6784
6839
  }
6785
6840
 
6841
+ // src/model/RunCostLedger.ts
6842
+ var RunCostLedger = class {
6843
+ #calls = /* @__PURE__ */ new Map();
6844
+ #hasUnobservedWork = false;
6845
+ observeChat(event) {
6846
+ if (typeof event.callId !== "string" || !event.callId) {
6847
+ this.markUnobserved();
6848
+ return;
6849
+ }
6850
+ this.#record(`llm:${event.callId}`, event.pricing.status === "known" ? event.pricing.costUsd : void 0);
6851
+ }
6852
+ observeClassifier(event) {
6853
+ var _a;
6854
+ if (event.family !== "classifier" || event.attemptIndex === void 0) return;
6855
+ if (typeof event.eventId !== "string" || !event.eventId || !Number.isSafeInteger(event.attemptIndex) || event.attemptIndex < 0) {
6856
+ this.markUnobserved();
6857
+ return;
6858
+ }
6859
+ this.#record(`decision:${event.eventId}`, (_a = event.classifierUsage) == null ? void 0 : _a.estimatedCostUsd);
6860
+ }
6861
+ /** Legacy Chat does not expose complete per-attempt accounting. */
6862
+ observeLegacy(key, value) {
6863
+ if (typeof value === "number" && Number.isFinite(value) && value > 0) this.#record(`legacy:${key}`, value);
6864
+ this.markUnobserved();
6865
+ }
6866
+ markUnobserved() {
6867
+ this.#hasUnobservedWork = true;
6868
+ }
6869
+ snapshot(executionPending = false) {
6870
+ let known = 0;
6871
+ let knownCount = 0;
6872
+ let hasUnknownCost = this.#hasUnobservedWork || executionPending;
6873
+ for (const cost of this.#calls.values()) {
6874
+ if (cost === null) hasUnknownCost = true;
6875
+ else {
6876
+ known += cost;
6877
+ knownCount++;
6878
+ }
6879
+ }
6880
+ if (!Number.isFinite(known)) return { status: "unknown", knownCostUsd: null };
6881
+ if (!hasUnknownCost) return { status: "complete", knownCostUsd: known };
6882
+ if (knownCount === 0) return { status: "unknown", knownCostUsd: null };
6883
+ return { status: "partial", knownCostUsd: known };
6884
+ }
6885
+ #record(id, value) {
6886
+ if (this.#calls.has(id)) return;
6887
+ this.#calls.set(id, typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null);
6888
+ }
6889
+ };
6890
+
6786
6891
  // src/model/GraphExecutionState.ts
6787
6892
  var GraphInvocationState = class {
6788
6893
  rootRunId = void 0;
@@ -6809,6 +6914,7 @@ var GraphInvocationState = class {
6809
6914
  successfulAbortTerminalProcessIds = void 0;
6810
6915
  totalCost = 0;
6811
6916
  costBreakdown;
6917
+ costLedger = new RunCostLedger();
6812
6918
  ignoreNodes = void 0;
6813
6919
  hasPreloadedData = false;
6814
6920
  loadedProjects = void 0;
@@ -6845,6 +6951,7 @@ var GraphInvocationState = class {
6845
6951
  this.successfulAbortTerminalProcessIds = /* @__PURE__ */ new Set();
6846
6952
  this.totalCost = 0;
6847
6953
  this.costBreakdown = void 0;
6954
+ this.costLedger = new RunCostLedger();
6848
6955
  this.nodeAbortControllers = /* @__PURE__ */ new Map();
6849
6956
  this.loadedProjects = options2.loadedProjects;
6850
6957
  this.graphInputNodeValues = ((_c = options2.sharedOverride) == null ? void 0 : _c.graphInputNodeValues) ?? {};
@@ -14455,6 +14562,7 @@ var GraphProcessor = class _GraphProcessor {
14455
14562
  const hostChatV2Observer = this.getRootProcessor().#run.context.onChatV2CallFinished;
14456
14563
  const hostLLMChatOutputSnapshotObserver = this.getRootProcessor().#run.context.onLLMChatOutputSnapshot;
14457
14564
  const hostLLMProfileAttemptObserver = this.getRootProcessor().#run.context.onLLMProfileAttempt;
14565
+ const costLedger = this.getRootProcessor().#run.costLedger;
14458
14566
  this.#run.nodeProcessContextBase = {
14459
14567
  ...this.#run.context,
14460
14568
  abortGraph: (error) => {
@@ -14474,6 +14582,11 @@ var GraphProcessor = class _GraphProcessor {
14474
14582
  graphOutputs: this.#run.graphOutputs,
14475
14583
  graphCallPath: this.#graphCallPath,
14476
14584
  onChatV2CallFinished: (event) => {
14585
+ try {
14586
+ costLedger.observeChat(event);
14587
+ } catch {
14588
+ costLedger.markUnobserved();
14589
+ }
14477
14590
  try {
14478
14591
  const observerResult = hostChatV2Observer == null ? void 0 : hostChatV2Observer(event);
14479
14592
  if (observerResult != null && typeof observerResult.then === "function") {
@@ -14495,6 +14608,11 @@ var GraphProcessor = class _GraphProcessor {
14495
14608
  emitDetached(this.#emitter, "llmChatOutputSnapshot", this.#withExecution(event));
14496
14609
  },
14497
14610
  onLLMProfileAttempt: (event) => {
14611
+ try {
14612
+ costLedger.observeClassifier(event);
14613
+ } catch {
14614
+ costLedger.markUnobserved();
14615
+ }
14498
14616
  try {
14499
14617
  const observerResult = hostLLMProfileAttemptObserver == null ? void 0 : hostLLMProfileAttemptObserver(event);
14500
14618
  if (observerResult != null && typeof observerResult.then === "function") {
@@ -15719,6 +15837,11 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
15719
15837
  }
15720
15838
  return processor;
15721
15839
  }
15840
+ /** Snapshot the root execution's observed provider estimates after completion. */
15841
+ getRunCostSnapshot() {
15842
+ const root = this.getRootProcessor();
15843
+ return root.#run.costLedger.snapshot(root.isRunning);
15844
+ }
15722
15845
  #getEnclosingStreamingWatchInvocation() {
15723
15846
  let processor = this;
15724
15847
  while (processor) {
@@ -15814,6 +15937,12 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
15814
15937
  nodeAbortController.abort(getAbortSignalReason(this.#run.abortController.signal));
15815
15938
  }
15816
15939
  let continuationFinalized = false;
15940
+ const costLedger = this.getRootProcessor().#run.costLedger;
15941
+ const accountingKey = `${this.#run.graphRunId}:${processId}:${index}`;
15942
+ let accountingEntered = false;
15943
+ let observedPhysicalCall = false;
15944
+ let cacheHit = false;
15945
+ let accountingOutputs;
15817
15946
  try {
15818
15947
  const createContextProfileStart = this.#startRuntimeProfile();
15819
15948
  let context;
@@ -15826,7 +15955,10 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
15826
15955
  nodeAbortController,
15827
15956
  partialOutput,
15828
15957
  void 0,
15829
- markResultAsEditorCacheHit
15958
+ markResultAsEditorCacheHit ? () => {
15959
+ cacheHit = true;
15960
+ markResultAsEditorCacheHit();
15961
+ } : void 0
15830
15962
  );
15831
15963
  } finally {
15832
15964
  this.#finishRuntimeProfile("createNodeProcessContext", createContextProfileStart);
@@ -15835,10 +15967,25 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
15835
15967
  if (nodeAbortController.signal.aborted) {
15836
15968
  throw createGraphAbortErrorFromSignal(nodeAbortController.signal);
15837
15969
  }
15970
+ if (node.type === "llmChatV2") {
15971
+ const observer = context.onChatV2CallFinished;
15972
+ context.onChatV2CallFinished = (event) => {
15973
+ observedPhysicalCall = true;
15974
+ observer == null ? void 0 : observer(event);
15975
+ };
15976
+ } else if (node.type === "classifierEvaluate") {
15977
+ const observer = context.onLLMProfileAttempt;
15978
+ context.onLLMProfileAttempt = (event) => {
15979
+ if (event.family === "classifier" && event.attemptIndex !== void 0) observedPhysicalCall = true;
15980
+ observer == null ? void 0 : observer(event);
15981
+ };
15982
+ }
15838
15983
  const implementationProfileStart = this.#startRuntimeProfile();
15839
15984
  let results;
15840
15985
  try {
15986
+ accountingEntered = true;
15841
15987
  results = await instance.process(inputValues, context);
15988
+ accountingOutputs = results;
15842
15989
  } finally {
15843
15990
  this.#finishRuntimeProfile("nodeImplementation", implementationProfileStart);
15844
15991
  }
@@ -15857,6 +16004,18 @@ ${errors.map(({ node }) => `- ${node.title} (${node.id})`).join("\n")}`;
15857
16004
  this.#discardFailureOutputs(processId, index);
15858
16005
  return results;
15859
16006
  } finally {
16007
+ if (accountingEntered && !cacheHit) {
16008
+ try {
16009
+ if (["chat", "chatLoop", "chatGoogle", "chatAnthropic", "chatHuggingFace", "getEmbedding"].includes(node.type)) {
16010
+ const cost = accountingOutputs == null ? void 0 : accountingOutputs["cost"];
16011
+ costLedger.observeLegacy(accountingKey, (cost == null ? void 0 : cost.type) === "number" ? cost.value : void 0);
16012
+ } else if ((node.type === "llmChatV2" || node.type === "classifierEvaluate") && !observedPhysicalCall) {
16013
+ costLedger.markUnobserved();
16014
+ }
16015
+ } catch {
16016
+ costLedger.markUnobserved();
16017
+ }
16018
+ }
15860
16019
  if (!continuationFinalized) {
15861
16020
  this.#discardToolCallContinuation(processId, index);
15862
16021
  }
@@ -23688,6 +23847,16 @@ var profileSuspensionHints = {
23688
23847
  duration: "Time to suspend this profile before one recovery attempt."
23689
23848
  };
23690
23849
 
23850
+ // src/model/tokenPricingEditor.ts
23851
+ function getTokenPricingEditor() {
23852
+ return {
23853
+ type: "group",
23854
+ label: "Token pricing",
23855
+ defaultOpen: false,
23856
+ editors: [{ type: "custom", label: "Token pricing", customEditorId: "AIProfilePricing" }]
23857
+ };
23858
+ }
23859
+
23691
23860
  // src/model/chat-v2/providerOptions.ts
23692
23861
  var import_anthropic2 = require("@ai-sdk/anthropic");
23693
23862
  var import_google2 = require("@ai-sdk/google");
@@ -24194,22 +24363,28 @@ function getChatV2ModelInfo(provider, modelId) {
24194
24363
  const providerModels = chatV2ModelRegistry[provider];
24195
24364
  return providerModels[modelId];
24196
24365
  }
24366
+ function getChatV2SystemTokenPricing(provider, modelId) {
24367
+ var _a;
24368
+ const cost = (_a = getChatV2ModelInfo(provider, modelId.trim())) == null ? void 0 : _a.cost;
24369
+ return cost == null ? void 0 : { inputPerMillionTokens: cost.prompt * 1e6, outputPerMillionTokens: cost.completion * 1e6 };
24370
+ }
24197
24371
  function calculateChatV2Cost(provider, modelId, promptTokens, completionTokens) {
24198
24372
  const model = getChatV2ModelInfo(provider, modelId);
24199
- if ((model == null ? void 0 : model.cost) == null || !isFiniteNonNegative(promptTokens) || !isFiniteNonNegative(completionTokens)) {
24373
+ if ((model == null ? void 0 : model.cost) == null || !isReportedTokenCount(promptTokens) || !isReportedTokenCount(completionTokens)) {
24200
24374
  return void 0;
24201
24375
  }
24202
24376
  const cost = model.cost.prompt * promptTokens + model.cost.completion * completionTokens;
24203
24377
  return isFiniteNonNegative(cost) ? cost : void 0;
24204
24378
  }
24205
- function calculateChatV2UsageCost(provider, modelId, usage, providerMetadata) {
24379
+ function calculateChatV2UsageCost(provider, modelId, usage, providerMetadata, tokenPricing) {
24206
24380
  var _a;
24381
+ if (tokenPricing !== void 0) return calculateTokenUsageCost(tokenPricing, usage);
24207
24382
  if (provider === "openrouter") {
24208
24383
  const reportedUsage = (_a = providerMetadata == null ? void 0 : providerMetadata.openrouter) == null ? void 0 : _a.usage;
24209
24384
  const cost = reportedUsage != null && typeof reportedUsage === "object" ? reportedUsage.cost : void 0;
24210
24385
  return isFiniteNonNegative(cost) ? cost : void 0;
24211
24386
  }
24212
- if (!isFiniteNonNegative(usage == null ? void 0 : usage.inputTokens) || !isFiniteNonNegative(usage.outputTokens)) {
24387
+ if ((usage == null ? void 0 : usage.inputTokens) == null || usage.outputTokens == null) {
24213
24388
  return void 0;
24214
24389
  }
24215
24390
  return calculateChatV2Cost(provider, modelId, usage.inputTokens, usage.outputTokens);
@@ -25266,6 +25441,7 @@ async function getLLMChatV2Editors(data, context) {
25266
25441
  },
25267
25442
  ...!usesProfile ? [
25268
25443
  getModelEditors(await getResolvedModelOptions(data, context)),
25444
+ getTokenPricingEditor(),
25269
25445
  ...getProviderEditors(),
25270
25446
  getParameterEditors(),
25271
25447
  ...data.provider === "custom" ? [] : [getReasoningEditors()]
@@ -25281,6 +25457,7 @@ async function getLLMProfileEditors(data, context) {
25281
25457
  const profileData = data;
25282
25458
  return [
25283
25459
  getModelEditors(await getResolvedModelOptions(profileData, context)),
25460
+ getTokenPricingEditor(),
25284
25461
  ...getProviderEditors(),
25285
25462
  getParameterEditors(),
25286
25463
  ...profileData.provider === "custom" ? [] : [getReasoningEditors()],
@@ -26397,11 +26574,17 @@ function notifyChatV2CallFinished(options2, params) {
26397
26574
  const calculatedCost = safelyRead(
26398
26575
  () => {
26399
26576
  var _a2;
26400
- return calculateChatV2UsageCost(options2.provider, options2.modelId, rawUsage, (_a2 = params.result) == null ? void 0 : _a2.providerMetadata);
26577
+ return calculateChatV2UsageCost(
26578
+ options2.provider,
26579
+ options2.modelId,
26580
+ resultUsage ?? errorUsage,
26581
+ (_a2 = params.result) == null ? void 0 : _a2.providerMetadata,
26582
+ options2.tokenPricing
26583
+ );
26401
26584
  }
26402
26585
  );
26403
26586
  const costUsd = toUsageNumber(calculatedCost);
26404
- const hasKnownPricing = (modelInfo == null ? void 0 : modelInfo.cost) != null || options2.provider === "openrouter" && costUsd != null;
26587
+ const hasKnownPricing = options2.tokenPricing != null || (modelInfo == null ? void 0 : modelInfo.cost) != null || options2.provider === "openrouter" && costUsd != null;
26405
26588
  const finishReason = safelyRead(() => {
26406
26589
  var _a2;
26407
26590
  return (_a2 = params.result) == null ? void 0 : _a2.finishReason;
@@ -27070,7 +27253,13 @@ function normalizeChatV2Usage(usage, options2, providerMetadata) {
27070
27253
  totalTokens,
27071
27254
  cachedTokens,
27072
27255
  reasoningTokens,
27073
- totalCost: calculateChatV2UsageCost(options2.provider, options2.modelId, usage, providerMetadata)
27256
+ totalCost: calculateChatV2UsageCost(
27257
+ options2.provider,
27258
+ options2.modelId,
27259
+ usage,
27260
+ providerMetadata,
27261
+ options2.tokenPricing
27262
+ )
27074
27263
  };
27075
27264
  }
27076
27265
  function createChatV2ResponseOutput2(response, structuredOutput, responseFormat) {
@@ -27224,6 +27413,7 @@ async function runChatV2WithRetry(options2, chatOptions, retryPlan, signal, tran
27224
27413
  const callId = createObservedChatV2CallId(options2);
27225
27414
  const callStartedAt = Date.now();
27226
27415
  let callWasObserved = false;
27416
+ let completedResponse;
27227
27417
  let acceptsResponseEvidence = true;
27228
27418
  const retireResponseEvidence = () => {
27229
27419
  acceptsResponseEvidence = false;
@@ -27264,6 +27454,7 @@ async function runChatV2WithRetry(options2, chatOptions, retryPlan, signal, tran
27264
27454
  onResponseReceived: reportResponseEvidence
27265
27455
  };
27266
27456
  const result = transportMode === "generate" ? await generateChatV2(attemptChatOptions) : await streamChatV2(attemptChatOptions);
27457
+ completedResponse = result;
27267
27458
  signal.throwIfAborted();
27268
27459
  await ((_a = options2.responseBodyCapture) == null ? void 0 : _a.flush());
27269
27460
  signal.throwIfAborted();
@@ -27305,6 +27496,7 @@ async function runChatV2WithRetry(options2, chatOptions, retryPlan, signal, tran
27305
27496
  callId,
27306
27497
  attemptIndex: attempt,
27307
27498
  outcome: signal.aborted ? "aborted" : "provider-failure",
27499
+ result: completedResponse,
27308
27500
  error,
27309
27501
  startedAt: callStartedAt,
27310
27502
  durationMs: Math.max(0, Date.now() - callStartedAt)
@@ -28953,6 +29145,7 @@ async function resolveLLMModelCandidate(params) {
28953
29145
  var _a;
28954
29146
  const { plan, profile } = params;
28955
29147
  const effectiveData = profile ? applyLLMProfileToNodeData(plan.data, profile) : plan.data;
29148
+ const tokenPricing = validateTokenPricing(effectiveData.tokenPricing);
28956
29149
  if (hasLLMChatV2ToolResponseFormatConflict(effectiveData)) {
28957
29150
  throw new Error(LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY.paragraphs[0]);
28958
29151
  }
@@ -29004,6 +29197,7 @@ async function resolveLLMModelCandidate(params) {
29004
29197
  requestBodyOverlay,
29005
29198
  runOptions: {
29006
29199
  ...baseRunOptions,
29200
+ tokenPricing,
29007
29201
  provider,
29008
29202
  model: resolvedProvider.model,
29009
29203
  modelId,
@@ -30016,7 +30210,7 @@ function resolveLLMProfileNodeValue(params) {
30016
30210
  return {
30017
30211
  version: LLM_PROFILE_VALUE_VERSION,
30018
30212
  credential,
30019
- configuration,
30213
+ configuration: { ...configuration, tokenPricing: validateTokenPricing(configuration.tokenPricing) },
30020
30214
  ...profileName === "" ? {} : { profileName },
30021
30215
  ...projectId == null ? {} : {
30022
30216
  healthIdentity: createRivetLLMProfileHealthIdentity({
@@ -46144,7 +46338,11 @@ function createClassifierProvider(spec) {
46144
46338
  const evaluate = async (input) => {
46145
46339
  var _a, _b, _c;
46146
46340
  if ("images" in input) throw new Error("Pass image evidence through State, not a separate images field.");
46147
- const args = { ...input, fetchImplementation: input.fetchImplementation ?? fetch };
46341
+ const args = {
46342
+ ...input,
46343
+ tokenPricing: validateTokenPricing(input.tokenPricing),
46344
+ fetchImplementation: input.fetchImplementation ?? fetch
46345
+ };
46148
46346
  const operation = createOperation(args, provider.label);
46149
46347
  operation.check();
46150
46348
  if (typeof args.model !== "string") throw new Error("Decision AI model must be a nonblank string.");
@@ -46223,6 +46421,11 @@ function createClassifierProvider(spec) {
46223
46421
  function normalizeModelPricing(provider) {
46224
46422
  return provider.modelPricing ?? (provider.pricing && provider.defaultModel ? [{ models: [provider.defaultModel], pricing: provider.pricing }] : []);
46225
46423
  }
46424
+ function getClassifierSystemTokenPricing(providerId, model) {
46425
+ var _a;
46426
+ const provider = getClassifierProvider(providerId);
46427
+ return (_a = normalizeModelPricing(provider).find((entry) => entry.models.includes((model == null ? void 0 : model.trim()) || provider.defaultModel))) == null ? void 0 : _a.pricing;
46428
+ }
46226
46429
  function getClassifierProvider(id) {
46227
46430
  const provider = classifierProviders.find((candidate) => candidate.id === (id || jevClassifierProvider.id));
46228
46431
  if (!provider) throw new Error(`Unknown Decision AI provider '${id}'.`);
@@ -46231,7 +46434,12 @@ function getClassifierProvider(id) {
46231
46434
  function getClassifierProviderEnvironmentVariableNames() {
46232
46435
  return [...new Set(classifierProviders.map((provider) => provider.credentialNames.environmentVariableName))];
46233
46436
  }
46234
- function calculateClassifierUsageCost(provider, usage, models) {
46437
+ function calculateClassifierUsageCost(provider, usage, models, tokenPricing) {
46438
+ if (tokenPricing !== void 0)
46439
+ return calculateTokenUsageCost(tokenPricing, {
46440
+ inputTokens: usage.input_tokens,
46441
+ outputTokens: usage.output_tokens
46442
+ });
46235
46443
  if (!models) return void 0;
46236
46444
  const entries2 = normalizeModelPricing(provider);
46237
46445
  const entry = entries2.find(
@@ -46240,7 +46448,7 @@ function calculateClassifierUsageCost(provider, usage, models) {
46240
46448
  const base = entry == null ? void 0 : entry.pricing;
46241
46449
  const tier = base == null ? void 0 : base.longContext;
46242
46450
  const validRates = (rates) => Number.isFinite(rates.inputPerMillionTokens) && rates.inputPerMillionTokens >= 0 && Number.isFinite(rates.outputPerMillionTokens) && rates.outputPerMillionTokens >= 0;
46243
- if (base == null || !validRates(base) || tier != null && (!Number.isSafeInteger(tier.aboveInputTokens) || tier.aboveInputTokens < 0 || !validRates(tier)) || !Number.isSafeInteger(usage.input_tokens) || usage.input_tokens < 0 || !Number.isSafeInteger(usage.output_tokens) || usage.output_tokens < 0) {
46451
+ if (base == null || !validRates(base) || tier != null && (!Number.isSafeInteger(tier.aboveInputTokens) || tier.aboveInputTokens < 0 || !validRates(tier)) || !isReportedTokenCount(usage.input_tokens) || !isReportedTokenCount(usage.output_tokens)) {
46244
46452
  return void 0;
46245
46453
  }
46246
46454
  const pricing = tier && usage.input_tokens > tier.aboveInputTokens ? tier : base;
@@ -46460,7 +46668,7 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
46460
46668
  "failure",
46461
46669
  response.status,
46462
46670
  "response-validation",
46463
- classifierAttemptUsage(body, spec, args.model),
46671
+ classifierAttemptUsage(body, spec, args.model, args.tokenPricing),
46464
46672
  error instanceof Error ? error.message : `${providerLabel} returned an invalid Decision AI response.`
46465
46673
  );
46466
46674
  throw new ClassifierProviderError(
@@ -46470,7 +46678,7 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
46470
46678
  { cause: error }
46471
46679
  );
46472
46680
  }
46473
- report("success", response.status, void 0, classifierAttemptUsage(body, spec, args.model));
46681
+ report("success", response.status, void 0, classifierAttemptUsage(body, spec, args.model, args.tokenPricing));
46474
46682
  return {
46475
46683
  // Preserve the direct-provider result contract, but graph runs with the
46476
46684
  // diagnostic disabled never allocate this second representation.
@@ -46487,12 +46695,12 @@ async function callClassifierHttp(args, spec, prepared, buildRequest, operation)
46487
46695
  };
46488
46696
  }
46489
46697
  }
46490
- function classifierAttemptUsage(body, provider, requestedModel) {
46698
+ function classifierAttemptUsage(body, provider, requestedModel, tokenPricing) {
46491
46699
  if (!body || typeof body !== "object" || Array.isArray(body) || !Object.hasOwn(body, "usage")) return;
46492
46700
  const { usage, model } = body;
46493
- if (!usage || typeof usage !== "object" || Array.isArray(usage) || !Object.hasOwn(usage, "input_tokens") || !Object.hasOwn(usage, "output_tokens") || !Number.isSafeInteger(usage.input_tokens) || usage.input_tokens < 0 || !Number.isSafeInteger(usage.output_tokens) || usage.output_tokens < 0)
46701
+ if (!usage || typeof usage !== "object" || Array.isArray(usage) || !Object.hasOwn(usage, "input_tokens") || !Object.hasOwn(usage, "output_tokens") || !isReportedTokenCount(usage.input_tokens) || !isReportedTokenCount(usage.output_tokens))
46494
46702
  return;
46495
- const estimatedCostUsd = typeof model === "string" && Object.hasOwn(body, "model") ? calculateClassifierUsageCost(provider, usage, { requestedModel, responseModel: model }) : void 0;
46703
+ const estimatedCostUsd = typeof model === "string" && Object.hasOwn(body, "model") ? calculateClassifierUsageCost(provider, usage, { requestedModel, responseModel: model }, tokenPricing) : void 0;
46496
46704
  return {
46497
46705
  inputTokens: usage.input_tokens,
46498
46706
  outputTokens: usage.output_tokens,
@@ -46587,6 +46795,7 @@ var DEFAULT_CLASSIFIER_PROFILE_FAILURE_WINDOW_MS = 3e5;
46587
46795
  var DEFAULT_CLASSIFIER_PROFILE_OPEN_DURATION_MS = 3e5;
46588
46796
  var classifierProfileInputIds = ["model", "apiKey"];
46589
46797
  var classifierProfileDataKeys = [
46798
+ "tokenPricing",
46590
46799
  "provider",
46591
46800
  "model",
46592
46801
  "useModelInput",
@@ -46663,11 +46872,12 @@ function normalizeDetachedProfile(value) {
46663
46872
  throw new Error("Unknown Decision AI API key source.");
46664
46873
  classifierProfileResponseTimeout(configuration);
46665
46874
  classifierProfileHealthPolicy(configuration);
46875
+ configuration.tokenPricing = validateTokenPricing(configuration.tokenPricing);
46666
46876
  return {
46667
46877
  version: 1,
46668
- sourceNodeId: profile.sourceNodeId,
46878
+ ...profile.sourceNodeId === void 0 ? {} : { sourceNodeId: profile.sourceNodeId },
46669
46879
  // Blank names are absent, but authored whitespace must survive exact-default display aliases.
46670
- profileName: ((_a = profile.profileName) == null ? void 0 : _a.trim()) ? profile.profileName : void 0,
46880
+ ...((_a = profile.profileName) == null ? void 0 : _a.trim()) ? { profileName: profile.profileName } : {},
46671
46881
  credential: credential.value === void 0 ? {} : { value: credential.value.trim() },
46672
46882
  configuration: {
46673
46883
  ...pickClassifierProfileData(configuration),
@@ -46703,7 +46913,12 @@ function resolveClassifierProfile(data, inputs, context) {
46703
46913
  }
46704
46914
  return normalizeClassifierProfileValue({
46705
46915
  version: 1,
46706
- configuration: { ...pickClassifierProfileData(data), provider: provider.id, model, useModelInput: false },
46916
+ configuration: {
46917
+ ...pickClassifierProfileData({ ...data, tokenPricing: validateTokenPricing(data.tokenPricing) }),
46918
+ provider: provider.id,
46919
+ model,
46920
+ useModelInput: false
46921
+ },
46707
46922
  credential: value === void 0 ? {} : { value },
46708
46923
  profileName: context.node.title,
46709
46924
  sourceNodeId: context.node.id
@@ -47000,6 +47215,7 @@ async function runClassifierProfiles(input) {
47000
47215
  ...input.state,
47001
47216
  questions: input.questions,
47002
47217
  apiKey: profile.credential.value,
47218
+ tokenPricing: profile.configuration.tokenPricing,
47003
47219
  model,
47004
47220
  ...Number.isFinite(timeoutMs) ? { timeoutMs } : {},
47005
47221
  deadline: input.deadline,
@@ -47039,7 +47255,7 @@ async function runClassifierProfiles(input) {
47039
47255
  skipReason: "unreached"
47040
47256
  });
47041
47257
  }
47042
- return { result, provider, model };
47258
+ return { result, provider, model, tokenPricing: profile.configuration.tokenPricing };
47043
47259
  } catch (error) {
47044
47260
  lastError = error;
47045
47261
  const providerError = error instanceof ClassifierProviderError ? error : void 0;
@@ -47185,6 +47401,10 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
47185
47401
  return [
47186
47402
  { type: "custom", label: "Configuration", customEditorId: "ClassifierConfiguration" },
47187
47403
  { ...getClassifierModelEditor(), hideIf: (data) => data.configurationMode === "profile" },
47404
+ {
47405
+ ...getTokenPricingEditor(),
47406
+ hideIf: (data) => data.configurationMode === "profile"
47407
+ },
47188
47408
  {
47189
47409
  type: "group",
47190
47410
  label: "Outputs",
@@ -47193,7 +47413,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
47193
47413
  type: "toggle",
47194
47414
  label: "Usage details",
47195
47415
  dataKey: "outputUsage",
47196
- helperMessage: "Adds estimated totalCost to Usage only for recognized requested/returned models. Unknown pricing is omitted. Provider-specific premiums are not included."
47416
+ helperMessage: "Adds estimated totalCost to Usage using explicit token prices or known model rates. Unknown pricing is omitted. Provider-specific premiums are not included."
47197
47417
  },
47198
47418
  {
47199
47419
  type: "toggle",
@@ -47341,6 +47561,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
47341
47561
  checkPreparation();
47342
47562
  if (this.data.configurationMode === "profile")
47343
47563
  return this.processProfiles(inputs, context, checkPreparation, attempts, diagnostics);
47564
+ const tokenPricing = validateTokenPricing(this.data.tokenPricing);
47344
47565
  const provider = getClassifierProvider(this.data.provider);
47345
47566
  if (!provider.browserExecutionSupported && context.executor === "browser") {
47346
47567
  throw new Error(
@@ -47383,6 +47604,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
47383
47604
  if (questions.length === 0) throw new Error("Decision AI run requires at least one question.");
47384
47605
  const result = await (provider.evaluateInput ?? provider.evaluate).call(provider, {
47385
47606
  apiKey,
47607
+ tokenPricing,
47386
47608
  model: modelValue,
47387
47609
  questions,
47388
47610
  retryOnNon200: this.data.retryOnNon200,
@@ -47413,13 +47635,21 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
47413
47635
  }
47414
47636
  });
47415
47637
  checkPreparation();
47416
- return { ...this.projectResult(provider, modelValue, result, checkPreparation), ...this.profileEvidence(attempts) };
47638
+ return {
47639
+ ...this.projectResult(provider, modelValue, result, checkPreparation, tokenPricing),
47640
+ ...this.profileEvidence(attempts)
47641
+ };
47417
47642
  }
47418
- projectResult(provider, modelValue, result, checkPreparation) {
47419
- const totalCost = calculateClassifierUsageCost(provider, result.response.usage, {
47420
- requestedModel: modelValue,
47421
- responseModel: result.response.model
47422
- });
47643
+ projectResult(provider, modelValue, result, checkPreparation, tokenPricing) {
47644
+ const totalCost = calculateClassifierUsageCost(
47645
+ provider,
47646
+ result.response.usage,
47647
+ {
47648
+ requestedModel: modelValue,
47649
+ responseModel: result.response.model
47650
+ },
47651
+ tokenPricing
47652
+ );
47423
47653
  const usage = !this.data.outputUsage || totalCost === void 0 ? result.response.usage : { ...result.response.usage, totalCost };
47424
47654
  const outputs = {
47425
47655
  ["answers"]: { type: "object", value: result.response.answers },
@@ -47491,7 +47721,7 @@ var ClassifierEvaluateNodeImpl = class extends NodeImpl {
47491
47721
  });
47492
47722
  check();
47493
47723
  return {
47494
- ...this.projectResult(selected.provider, selected.model, selected.result, check),
47724
+ ...this.projectResult(selected.provider, selected.model, selected.result, check, selected.tokenPricing),
47495
47725
  ...this.profileEvidence(attempts, classifierProfileSummary(profiles, attempts))
47496
47726
  };
47497
47727
  }
@@ -47645,6 +47875,7 @@ var ClassifierProfileNodeImpl = class extends NodeImpl {
47645
47875
  getEditors() {
47646
47876
  return [
47647
47877
  getClassifierModelEditor(),
47878
+ getTokenPricingEditor(),
47648
47879
  {
47649
47880
  type: "group",
47650
47881
  label: "Decision AI profile suspension",
@@ -55075,6 +55306,14 @@ async function assembleRegistry(specs, loadPlugin) {
55075
55306
  return { registry, results: { loaded, failed } };
55076
55307
  }
55077
55308
 
55309
+ // src/model/DatasetOwnership.ts
55310
+ function remapOwnedDatasets(datasets, sourceId, targetId) {
55311
+ return datasets.map((dataset) => {
55312
+ if (dataset.meta.projectId !== sourceId) throw new Error("Dataset ownership does not match the source project.");
55313
+ return { ...dataset, meta: { ...dataset.meta, projectId: targetId } };
55314
+ });
55315
+ }
55316
+
55078
55317
  // src/api/streaming.ts
55079
55318
  async function* getProcessorEvents(processor, spec) {
55080
55319
  var _a, _b, _c, _d, _e, _f;
@@ -55712,6 +55951,7 @@ var Rivet = void 0;
55712
55951
  calculateChatV2Cost,
55713
55952
  calculateChatV2UsageCost,
55714
55953
  calculateClassifierUsageCost,
55954
+ calculateTokenUsageCost,
55715
55955
  callGraphNode,
55716
55956
  canBeCoerced,
55717
55957
  canBeCoercedAny,
@@ -55862,6 +56102,7 @@ var Rivet = void 0;
55862
56102
  getChatV2ModelRegistry,
55863
56103
  getChatV2ProviderCapabilities,
55864
56104
  getChatV2ProviderLabel,
56105
+ getChatV2SystemTokenPricing,
55865
56106
  getClassifierCredentialNamesForDisplay,
55866
56107
  getClassifierEvaluateBodySections,
55867
56108
  getClassifierModelEditor,
@@ -55869,6 +56110,7 @@ var Rivet = void 0;
55869
56110
  getClassifierProviderEnvironmentVariableNames,
55870
56111
  getClassifierQuestionBodySections,
55871
56112
  getClassifierRequestCount,
56113
+ getClassifierSystemTokenPricing,
55872
56114
  getCodeOutputFields,
55873
56115
  getCodeOutputKeys,
55874
56116
  getCommonChatV2Editors,
@@ -56004,6 +56246,7 @@ var Rivet = void 0;
56004
56246
  isLLMChatV2StructuredResponseFormat,
56005
56247
  isNodePrefabInstanceNode,
56006
56248
  isNotFunctionDataValue,
56249
+ isReportedTokenCount,
56007
56250
  isReservedKnowledgeObjectKey,
56008
56251
  isRivetWebAppRunTerminalEvent,
56009
56252
  isRuntimeDebugLoggingEnabled,
@@ -56147,6 +56390,7 @@ var Rivet = void 0;
56147
56390
  registerIntegration,
56148
56391
  registerKnowledgeStoreProvider,
56149
56392
  registerPluginsIntoRegistry,
56393
+ remapOwnedDatasets,
56150
56394
  removeKnowledgeStoreConnectionCredentials,
56151
56395
  renderUiGraphOutputValue,
56152
56396
  replaceDatasetNode,
@@ -56238,6 +56482,7 @@ var Rivet = void 0;
56238
56482
  validateProjectGlobalVariables,
56239
56483
  validateProjectUiGraphActionBindings,
56240
56484
  validateProjectUiGraphButtonBindings,
56485
+ validateTokenPricing,
56241
56486
  validateUiGraphActionBindings,
56242
56487
  validateUiGraphButtonBindings,
56243
56488
  vectorNearestNeighborsNode,