@resolveio/server-lib 22.0.19 → 22.0.20

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.
@@ -3151,7 +3151,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
3151
3151
  }
3152
3152
  function verifyAssistantAggregateReliability(params) {
3153
3153
  return __awaiter(this, void 0, void 0, function () {
3154
- var collection, collectionBase, monthKey, amountKey, baseMap, groupIndex, groupPaths, dateField, mergedMatch, dateFieldsInMatch, baseMatchNoDate, primaryDateCondition, verifyPipeline, verifyDocs, _a, verifyMap, comparedMonths, paidCloserCount, grandCloserCount, sumPaidDiffPct, sumGrandDiffPct, maxPaidDiffPct, maxGrandDiffPct, sumPaidGrandGapPct, highVarianceMonths, checks, warnings, avgPaidDiffPct, avgGrandDiffPct, avgPaidGrandGapPct, baselineMetric, rollingWindow, fullMonthWindow, rollingWindowBounds, fullMonthWindowBounds, verificationWindow, rollingStart, rollingEnd, fullMonthStart, fullMonthEndExclusive, fullMonthStart, fullMonthEndExclusive, fullMonthEndInclusiveDate, fullMonthEnd, normalizedMetric, bounds, fullMonthMatch, fullMonthDocs, fullMonthMap, fullMonthDiff, _b, alternateDateField, alternateDateCondition, bounds, bounds, alternateMatch, alternateDocs, alternateMap, alternateDiff, _c;
3154
+ var collection, collectionBase, monthKey, amountKey, baseMap, groupIndex, groupPaths, dateField, mergedMatch, dateFieldsInMatch, baseMatchNoDate, primaryDateCondition, verifyPipeline, verifyDocs, _a, verifyMap, comparedMonths, paidCloserCount, grandCloserCount, sumPaidDiffPct, sumGrandDiffPct, maxPaidDiffPct, maxGrandDiffPct, sumPaidGrandGapPct, highVarianceMonths, checks, warnings, avgPaidDiffPct, avgGrandDiffPct, avgPaidGrandGapPct, usesPaidGrandFallbackMetric, baselineMetric, rollingWindow, fullMonthWindow, rollingWindowBounds, fullMonthWindowBounds, verificationWindow, rollingStart, rollingEnd, fullMonthStart, fullMonthEndExclusive, fullMonthStart, fullMonthEndExclusive, fullMonthEndInclusiveDate, fullMonthEnd, normalizedMetric, bounds, fullMonthMatch, fullMonthDocs, fullMonthMap, fullMonthDiff, _b, alternateDateField, alternateDateCondition, bounds, bounds, alternateMatch, alternateDocs, alternateMap, alternateDiff, _c;
3155
3155
  var _d, _e;
3156
3156
  var _f;
3157
3157
  return __generator(this, function (_g) {
@@ -3252,6 +3252,7 @@ function verifyAssistantAggregateReliability(params) {
3252
3252
  avgPaidDiffPct = comparedMonths ? (sumPaidDiffPct / comparedMonths) : 0;
3253
3253
  avgGrandDiffPct = comparedMonths ? (sumGrandDiffPct / comparedMonths) : 0;
3254
3254
  avgPaidGrandGapPct = comparedMonths ? (sumPaidGrandGapPct / comparedMonths) : 0;
3255
+ usesPaidGrandFallbackMetric = hasAssistantPaidGrandFallbackExpr(params.pipeline || []);
3255
3256
  baselineMetric = 'unknown';
3256
3257
  if (comparedMonths) {
3257
3258
  if (paidCloserCount > grandCloserCount) {
@@ -3275,10 +3276,12 @@ function verifyAssistantAggregateReliability(params) {
3275
3276
  else {
3276
3277
  checks.push({
3277
3278
  name: 'Metric alignment',
3278
- status: baselineMetric === 'mixed' ? 'warn' : 'pass',
3279
- details: "Result aligns most with ".concat(baselineMetric, ".")
3279
+ status: baselineMetric === 'mixed' && !usesPaidGrandFallbackMetric ? 'warn' : 'pass',
3280
+ details: baselineMetric === 'mixed' && usesPaidGrandFallbackMetric
3281
+ ? 'Result uses explicit paid_total fallback grand_total logic.'
3282
+ : "Result aligns most with ".concat(baselineMetric, ".")
3280
3283
  });
3281
- if (baselineMetric === 'mixed') {
3284
+ if (baselineMetric === 'mixed' && !usesPaidGrandFallbackMetric) {
3282
3285
  warnings.push('Revenue appears to mix definitions across months (paid_total vs grand_total).');
3283
3286
  }
3284
3287
  checks.push({
@@ -3552,6 +3555,24 @@ function mapAssistantRevenueByMonth(documents, monthKey, valueKey) {
3552
3555
  });
3553
3556
  return mapped;
3554
3557
  }
3558
+ function hasAssistantPaidGrandFallbackExpr(value) {
3559
+ if (Array.isArray(value)) {
3560
+ return value.some(function (entry) { return hasAssistantPaidGrandFallbackExpr(entry); });
3561
+ }
3562
+ if (!value || typeof value !== 'object') {
3563
+ return false;
3564
+ }
3565
+ var ifNull = value.$ifNull;
3566
+ if (Array.isArray(ifNull) && ifNull.length >= 2) {
3567
+ var first = normalizeOptionalString(ifNull[0]).replace(/^\$/, '');
3568
+ var second = normalizeOptionalString(ifNull[1]).replace(/^\$/, '');
3569
+ var pair = new Set([first, second]);
3570
+ if (pair.has('paid_total') && pair.has('grand_total')) {
3571
+ return true;
3572
+ }
3573
+ }
3574
+ return Object.keys(value).some(function (key) { return hasAssistantPaidGrandFallbackExpr(value[key]); });
3575
+ }
3555
3576
  function mergeAssistantPreGroupMatchStages(pipeline, groupIndex) {
3556
3577
  var matches = [];
3557
3578
  for (var i = 0; i < groupIndex; i += 1) {