@resolveio/server-lib 22.0.11 → 22.0.13

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.
@@ -1818,6 +1818,7 @@ function executeAiAssistantCodexRun(payload, context) {
1818
1818
  assistantContent = buildAssistantCodexErrorMessage(null);
1819
1819
  }
1820
1820
  assistantContent = applyAssistantVerificationNotes(assistantContent, toolResult);
1821
+ assistantContent = applyAssistantDatedReportWindow(assistantContent, toolResult);
1821
1822
  assistantContent = normalizeAssistantCurrencyText(assistantContent);
1822
1823
  if (aiWorkerDebug) {
1823
1824
  finishedAt = Date.now();
@@ -3041,7 +3042,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
3041
3042
  }
3042
3043
  function verifyAssistantAggregateReliability(params) {
3043
3044
  return __awaiter(this, void 0, void 0, function () {
3044
- 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, normalizedMetric, bounds, fullMonthMatch, fullMonthDocs, fullMonthMap, fullMonthDiff, _b, alternateDateField, alternateDateCondition, bounds, alternateMatch, alternateDocs, alternateMap, alternateDiff, _c;
3045
+ 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, rollingWindowBounds, verificationWindow, rollingStart, rollingEnd, fullMonthStart, fullMonthEndExclusive, normalizedMetric, bounds, fullMonthMatch, fullMonthDocs, fullMonthMap, fullMonthDiff, _b, alternateDateField, alternateDateCondition, bounds, alternateMatch, alternateDocs, alternateMap, alternateDiff, _c;
3045
3046
  var _d, _e;
3046
3047
  var _f;
3047
3048
  return __generator(this, function (_g) {
@@ -3182,13 +3183,29 @@ function verifyAssistantAggregateReliability(params) {
3182
3183
  }
3183
3184
  }
3184
3185
  rollingWindow = detectAssistantRollingMonthWindow(params.pipeline || []);
3186
+ rollingWindowBounds = null;
3187
+ verificationWindow = null;
3185
3188
  if ((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow)) {
3189
+ rollingWindowBounds = resolveAssistantRollingWindowBounds(rollingWindow.months);
3190
+ rollingStart = formatAssistantIsoDateOnly(rollingWindowBounds.rollingStart);
3191
+ rollingEnd = formatAssistantIsoDateOnly(rollingWindowBounds.now);
3192
+ fullMonthStart = formatAssistantIsoDateOnly(rollingWindowBounds.startOfWindow);
3193
+ fullMonthEndExclusive = formatAssistantIsoDateOnly(rollingWindowBounds.startOfCurrentMonth);
3194
+ verificationWindow = {
3195
+ type: 'rolling_last_n_months',
3196
+ months: rollingWindow.months,
3197
+ startDate: rollingStart,
3198
+ endDate: rollingEnd,
3199
+ timezone: 'UTC',
3200
+ fullMonthStartDate: fullMonthStart,
3201
+ fullMonthEndDateExclusive: fullMonthEndExclusive
3202
+ };
3186
3203
  checks.push({
3187
3204
  name: 'Date window shape',
3188
3205
  status: 'warn',
3189
- details: "Query uses rolling $$NOW bounds (last ".concat(rollingWindow.months, " months), which can include partial months.")
3206
+ details: "Query uses rolling $$NOW bounds (".concat(rollingStart, " to ").concat(rollingEnd, " UTC; last ").concat(rollingWindow.months, " months), which can include partial months.")
3190
3207
  });
3191
- warnings.push("Date window is rolling (last ".concat(rollingWindow.months, " months to now), so first/current months may be partial."));
3208
+ warnings.push("Date window is rolling (".concat(rollingStart, " to ").concat(rollingEnd, " UTC; last ").concat(rollingWindow.months, " months), so first/current months may be partial."));
3192
3209
  }
3193
3210
  else {
3194
3211
  checks.push({
@@ -3198,8 +3215,8 @@ function verifyAssistantAggregateReliability(params) {
3198
3215
  });
3199
3216
  }
3200
3217
  normalizedMetric = normalizeAssistantVerificationMetric(baselineMetric);
3201
- if (!((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow))) return [3 /*break*/, 8];
3202
- bounds = resolveAssistantRollingWindowBounds(rollingWindow.months);
3218
+ if (!((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow) && rollingWindowBounds)) return [3 /*break*/, 8];
3219
+ bounds = rollingWindowBounds;
3203
3220
  fullMonthMatch = mergeAssistantMatch(baseMatchNoDate, (_d = {},
3204
3221
  _d[dateField] = {
3205
3222
  $gte: bounds.startOfWindow,
@@ -3247,8 +3264,8 @@ function verifyAssistantAggregateReliability(params) {
3247
3264
  : '';
3248
3265
  if (!alternateDateField) return [3 /*break*/, 12];
3249
3266
  alternateDateCondition = null;
3250
- if ((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow)) {
3251
- bounds = resolveAssistantRollingWindowBounds(rollingWindow.months);
3267
+ if ((rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) && (rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow) && rollingWindowBounds) {
3268
+ bounds = rollingWindowBounds;
3252
3269
  alternateDateCondition = {
3253
3270
  $gte: bounds.rollingStart,
3254
3271
  $lte: bounds.now
@@ -3296,21 +3313,57 @@ function verifyAssistantAggregateReliability(params) {
3296
3313
  type: 'invoice_revenue_monthly',
3297
3314
  checks: checks,
3298
3315
  warnings: warnings,
3299
- metrics: {
3300
- baselineField: amountKey,
3301
- dateField: dateField,
3302
- comparedMonths: comparedMonths,
3303
- avgDiffToPaidPct: (0, common_1.round)(avgPaidDiffPct * 100, 2),
3304
- avgDiffToGrandPct: (0, common_1.round)(avgGrandDiffPct * 100, 2),
3305
- maxDiffToPaidPct: (0, common_1.round)(maxPaidDiffPct * 100, 2),
3306
- maxDiffToGrandPct: (0, common_1.round)(maxGrandDiffPct * 100, 2),
3307
- avgPaidGrandGapPct: (0, common_1.round)(avgPaidGrandGapPct * 100, 2)
3308
- }
3316
+ metrics: __assign({ baselineField: amountKey, dateField: dateField, comparedMonths: comparedMonths, avgDiffToPaidPct: (0, common_1.round)(avgPaidDiffPct * 100, 2), avgDiffToGrandPct: (0, common_1.round)(avgGrandDiffPct * 100, 2), maxDiffToPaidPct: (0, common_1.round)(maxPaidDiffPct * 100, 2), maxDiffToGrandPct: (0, common_1.round)(maxGrandDiffPct * 100, 2), avgPaidGrandGapPct: (0, common_1.round)(avgPaidGrandGapPct * 100, 2) }, (verificationWindow ? { window: verificationWindow } : {}))
3309
3317
  }];
3310
3318
  }
3311
3319
  });
3312
3320
  });
3313
3321
  }
3322
+ function normalizeAssistantMonthBucket(value) {
3323
+ var _a, _b;
3324
+ if (value === null || value === undefined || value === '') {
3325
+ return '';
3326
+ }
3327
+ if (value instanceof Date) {
3328
+ if (Number.isNaN(value.getTime())) {
3329
+ return '';
3330
+ }
3331
+ return value.toISOString().slice(0, 7);
3332
+ }
3333
+ if (typeof value === 'string') {
3334
+ var trimmed = normalizeOptionalString(value);
3335
+ if (!trimmed) {
3336
+ return '';
3337
+ }
3338
+ var directMatch = trimmed.match(/^(\d{4})-(\d{2})(?:$|[^0-9])/);
3339
+ if (directMatch) {
3340
+ var month = Number(directMatch[2]);
3341
+ if (Number.isFinite(month) && month >= 1 && month <= 12) {
3342
+ return "".concat(directMatch[1], "-").concat(directMatch[2]);
3343
+ }
3344
+ }
3345
+ var parsed = Date.parse(trimmed);
3346
+ if (!Number.isNaN(parsed)) {
3347
+ return new Date(parsed).toISOString().slice(0, 7);
3348
+ }
3349
+ return '';
3350
+ }
3351
+ if (typeof value === 'object') {
3352
+ var yearRaw = (_a = value === null || value === void 0 ? void 0 : value.year) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value._year;
3353
+ var monthRaw = (_b = value === null || value === void 0 ? void 0 : value.month) !== null && _b !== void 0 ? _b : value === null || value === void 0 ? void 0 : value._month;
3354
+ var year = Number(yearRaw);
3355
+ var month = Number(monthRaw);
3356
+ if (Number.isFinite(year)
3357
+ && Number.isFinite(month)
3358
+ && month >= 1
3359
+ && month <= 12) {
3360
+ var yearText = String(Math.trunc(year)).padStart(4, '0');
3361
+ var monthText = String(Math.trunc(month)).padStart(2, '0');
3362
+ return "".concat(yearText, "-").concat(monthText);
3363
+ }
3364
+ }
3365
+ return '';
3366
+ }
3314
3367
  function resolveAssistantMonthlyKey(documents) {
3315
3368
  var first = Array.isArray(documents) ? documents.find(function (doc) { return doc && typeof doc === 'object'; }) : null;
3316
3369
  if (!first) {
@@ -3318,7 +3371,7 @@ function resolveAssistantMonthlyKey(documents) {
3318
3371
  }
3319
3372
  return Object.keys(first).find(function (key) {
3320
3373
  var value = first[key];
3321
- return typeof value === 'string' && /^\d{4}-\d{2}$/.test(value);
3374
+ return !!normalizeAssistantMonthBucket(value);
3322
3375
  }) || '';
3323
3376
  }
3324
3377
  function resolveAssistantNumericAmountKey(documents, monthKey) {
@@ -3349,8 +3402,8 @@ function resolveAssistantNumericAmountKey(documents, monthKey) {
3349
3402
  function mapAssistantRevenueByMonth(documents, monthKey, valueKey) {
3350
3403
  var mapped = new Map();
3351
3404
  (Array.isArray(documents) ? documents : []).forEach(function (doc) {
3352
- var month = normalizeOptionalString(doc === null || doc === void 0 ? void 0 : doc[monthKey]);
3353
- if (!month || !/^\d{4}-\d{2}$/.test(month)) {
3405
+ var month = normalizeAssistantMonthBucket(doc === null || doc === void 0 ? void 0 : doc[monthKey]);
3406
+ if (!month) {
3354
3407
  return;
3355
3408
  }
3356
3409
  var value = Number(doc === null || doc === void 0 ? void 0 : doc[valueKey]);
@@ -3427,8 +3480,8 @@ function buildAssistantMonthlyRevenueVerificationPipeline(match, dateField) {
3427
3480
  function mapAssistantVerificationDocsByMonth(docs) {
3428
3481
  var mapped = new Map();
3429
3482
  (Array.isArray(docs) ? docs : []).forEach(function (row) {
3430
- var month = normalizeOptionalString(row === null || row === void 0 ? void 0 : row.month);
3431
- if (!month || !/^\d{4}-\d{2}$/.test(month)) {
3483
+ var month = normalizeAssistantMonthBucket(row === null || row === void 0 ? void 0 : row.month);
3484
+ if (!month) {
3432
3485
  return;
3433
3486
  }
3434
3487
  var paid = Number(row === null || row === void 0 ? void 0 : row.paid_total_sum);
@@ -3508,6 +3561,12 @@ function resolveAssistantRollingWindowBounds(months) {
3508
3561
  startOfWindow: startOfWindow
3509
3562
  };
3510
3563
  }
3564
+ function formatAssistantIsoDateOnly(value) {
3565
+ if (!(value instanceof Date) || Number.isNaN(value.getTime())) {
3566
+ return '';
3567
+ }
3568
+ return value.toISOString().slice(0, 10);
3569
+ }
3511
3570
  function extractAssistantMongoDirective(content) {
3512
3571
  var lines = String(content || '').split('\n');
3513
3572
  var directiveIndex = -1;
@@ -3732,6 +3791,79 @@ function applyAssistantVerificationNotes(value, toolResult) {
3732
3791
  }
3733
3792
  return "".concat(content, "\n\n").concat(noteLines.join('\n')).trim();
3734
3793
  }
3794
+ function applyAssistantDatedReportWindow(value, toolResult) {
3795
+ var content = normalizeOptionalString(value);
3796
+ var window = resolveAssistantDatedReportWindow(toolResult);
3797
+ if (!window || typeof window !== 'object') {
3798
+ return content || value || '';
3799
+ }
3800
+ var startDate = normalizeOptionalString(window === null || window === void 0 ? void 0 : window.startDate);
3801
+ var endDate = normalizeOptionalString(window === null || window === void 0 ? void 0 : window.endDate);
3802
+ if (!startDate || !endDate) {
3803
+ return content || value || '';
3804
+ }
3805
+ var months = normalizeOptionalNumber(window === null || window === void 0 ? void 0 : window.months);
3806
+ var monthsText = months && months > 0 ? "; rolling last ".concat((0, common_1.round)(months), " month").concat((0, common_1.round)(months) === 1 ? '' : 's') : '';
3807
+ var line = "Report date range (UTC): ".concat(startDate, " to ").concat(endDate).concat(monthsText, ".");
3808
+ var normalizedLower = String(content || '').toLowerCase();
3809
+ if (normalizedLower.includes(startDate.toLowerCase()) && normalizedLower.includes(endDate.toLowerCase())) {
3810
+ return content || value || '';
3811
+ }
3812
+ if (!content) {
3813
+ return line;
3814
+ }
3815
+ return "".concat(line, "\n\n").concat(content).trim();
3816
+ }
3817
+ function resolveAssistantDatedReportWindow(toolResult) {
3818
+ var e_1, _a;
3819
+ var _b, _c, _d, _e, _f, _g, _h, _j;
3820
+ var verificationWindow = (_d = (_c = (_b = toolResult === null || toolResult === void 0 ? void 0 : toolResult.output) === null || _b === void 0 ? void 0 : _b.verification) === null || _c === void 0 ? void 0 : _c.metrics) === null || _d === void 0 ? void 0 : _d.window;
3821
+ var verificationStart = normalizeOptionalString(verificationWindow === null || verificationWindow === void 0 ? void 0 : verificationWindow.startDate);
3822
+ var verificationEnd = normalizeOptionalString(verificationWindow === null || verificationWindow === void 0 ? void 0 : verificationWindow.endDate);
3823
+ if (verificationStart && verificationEnd) {
3824
+ return {
3825
+ startDate: verificationStart,
3826
+ endDate: verificationEnd,
3827
+ months: normalizeOptionalNumber(verificationWindow === null || verificationWindow === void 0 ? void 0 : verificationWindow.months) || undefined
3828
+ };
3829
+ }
3830
+ var pipelineCandidates = [
3831
+ (_f = (_e = toolResult === null || toolResult === void 0 ? void 0 : toolResult.output) === null || _e === void 0 ? void 0 : _e.debug) === null || _f === void 0 ? void 0 : _f.executedPipeline,
3832
+ (_h = (_g = toolResult === null || toolResult === void 0 ? void 0 : toolResult.output) === null || _g === void 0 ? void 0 : _g.debug) === null || _h === void 0 ? void 0 : _h.originalPipeline,
3833
+ (_j = toolResult === null || toolResult === void 0 ? void 0 : toolResult.input) === null || _j === void 0 ? void 0 : _j.pipeline
3834
+ ];
3835
+ try {
3836
+ for (var pipelineCandidates_1 = __values(pipelineCandidates), pipelineCandidates_1_1 = pipelineCandidates_1.next(); !pipelineCandidates_1_1.done; pipelineCandidates_1_1 = pipelineCandidates_1.next()) {
3837
+ var candidate = pipelineCandidates_1_1.value;
3838
+ if (!Array.isArray(candidate)) {
3839
+ continue;
3840
+ }
3841
+ var rollingWindow = detectAssistantRollingMonthWindow(candidate);
3842
+ if (!(rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.months) || !(rollingWindow === null || rollingWindow === void 0 ? void 0 : rollingWindow.upperNow)) {
3843
+ continue;
3844
+ }
3845
+ var bounds = resolveAssistantRollingWindowBounds(rollingWindow.months);
3846
+ var startDate = formatAssistantIsoDateOnly(bounds.rollingStart);
3847
+ var endDate = formatAssistantIsoDateOnly(bounds.now);
3848
+ if (!startDate || !endDate) {
3849
+ continue;
3850
+ }
3851
+ return {
3852
+ startDate: startDate,
3853
+ endDate: endDate,
3854
+ months: rollingWindow.months
3855
+ };
3856
+ }
3857
+ }
3858
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3859
+ finally {
3860
+ try {
3861
+ if (pipelineCandidates_1_1 && !pipelineCandidates_1_1.done && (_a = pipelineCandidates_1.return)) _a.call(pipelineCandidates_1);
3862
+ }
3863
+ finally { if (e_1) throw e_1.error; }
3864
+ }
3865
+ return null;
3866
+ }
3735
3867
  function buildAssistantDebugPayload(params) {
3736
3868
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
3737
3869
  var notes = [];
@@ -4296,7 +4428,7 @@ function getValueAtPath(obj, path) {
4296
4428
  return walk(obj, 0);
4297
4429
  }
4298
4430
  function hasArrayValueAtPath(docs, path) {
4299
- var e_1, _a;
4431
+ var e_2, _a;
4300
4432
  if (!Array.isArray(docs) || !docs.length || !path) {
4301
4433
  return false;
4302
4434
  }
@@ -4309,17 +4441,17 @@ function hasArrayValueAtPath(docs, path) {
4309
4441
  }
4310
4442
  }
4311
4443
  }
4312
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4444
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
4313
4445
  finally {
4314
4446
  try {
4315
4447
  if (docs_1_1 && !docs_1_1.done && (_a = docs_1.return)) _a.call(docs_1);
4316
4448
  }
4317
- finally { if (e_1) throw e_1.error; }
4449
+ finally { if (e_2) throw e_2.error; }
4318
4450
  }
4319
4451
  return false;
4320
4452
  }
4321
4453
  function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
4322
- var e_2, _a, e_3, _b;
4454
+ var e_3, _a, e_4, _b;
4323
4455
  if (!Array.isArray(docs) || !fieldPath) {
4324
4456
  return 'unknown';
4325
4457
  }
@@ -4332,7 +4464,7 @@ function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
4332
4464
  : doc === null || doc === void 0 ? void 0 : doc[fieldPath];
4333
4465
  var queue = Array.isArray(value) ? value : [value];
4334
4466
  try {
4335
- for (var queue_1 = (e_3 = void 0, __values(queue)), queue_1_1 = queue_1.next(); !queue_1_1.done; queue_1_1 = queue_1.next()) {
4467
+ for (var queue_1 = (e_4 = void 0, __values(queue)), queue_1_1 = queue_1.next(); !queue_1_1.done; queue_1_1 = queue_1.next()) {
4336
4468
  var entry = queue_1_1.value;
4337
4469
  if (entry === null || entry === undefined) {
4338
4470
  continue;
@@ -4345,21 +4477,21 @@ function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
4345
4477
  }
4346
4478
  }
4347
4479
  }
4348
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
4480
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
4349
4481
  finally {
4350
4482
  try {
4351
4483
  if (queue_1_1 && !queue_1_1.done && (_b = queue_1.return)) _b.call(queue_1);
4352
4484
  }
4353
- finally { if (e_3) throw e_3.error; }
4485
+ finally { if (e_4) throw e_4.error; }
4354
4486
  }
4355
4487
  }
4356
4488
  }
4357
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
4489
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
4358
4490
  finally {
4359
4491
  try {
4360
4492
  if (docs_2_1 && !docs_2_1.done && (_a = docs_2.return)) _a.call(docs_2);
4361
4493
  }
4362
- finally { if (e_2) throw e_2.error; }
4494
+ finally { if (e_3) throw e_3.error; }
4363
4495
  }
4364
4496
  return sawString ? 'string' : 'unknown';
4365
4497
  }
@@ -4454,7 +4586,7 @@ function normalizeLookupKeyValue(value) {
4454
4586
  return '';
4455
4587
  }
4456
4588
  function collectTopLevelIdFieldValues(docs, options) {
4457
- var e_4, _a, e_5, _b;
4589
+ var e_5, _a, e_6, _b;
4458
4590
  if (!Array.isArray(docs) || !docs.length) {
4459
4591
  return [];
4460
4592
  }
@@ -4502,26 +4634,26 @@ function collectTopLevelIdFieldValues(docs, options) {
4502
4634
  });
4503
4635
  };
4504
4636
  try {
4505
- for (var keys_1 = (e_5 = void 0, __values(keys)), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
4637
+ for (var keys_1 = (e_6 = void 0, __values(keys)), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
4506
4638
  var key = keys_1_1.value;
4507
4639
  _loop_3(key);
4508
4640
  }
4509
4641
  }
4510
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
4642
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
4511
4643
  finally {
4512
4644
  try {
4513
4645
  if (keys_1_1 && !keys_1_1.done && (_b = keys_1.return)) _b.call(keys_1);
4514
4646
  }
4515
- finally { if (e_5) throw e_5.error; }
4647
+ finally { if (e_6) throw e_6.error; }
4516
4648
  }
4517
4649
  }
4518
4650
  }
4519
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
4651
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
4520
4652
  finally {
4521
4653
  try {
4522
4654
  if (docs_3_1 && !docs_3_1.done && (_a = docs_3.return)) _a.call(docs_3);
4523
4655
  }
4524
- finally { if (e_4) throw e_4.error; }
4656
+ finally { if (e_5) throw e_5.error; }
4525
4657
  }
4526
4658
  return Array.from(fieldMap.entries()).map(function (_a) {
4527
4659
  var _b = __read(_a, 2), field = _b[0], values = _b[1];
@@ -4532,7 +4664,7 @@ function collectTopLevelIdFieldValues(docs, options) {
4532
4664
  });
4533
4665
  }
4534
4666
  function resolveLookupDisplayField(baseToken, probeDocs, schemaFields) {
4535
- var e_6, _a, e_7, _b;
4667
+ var e_7, _a, e_8, _b;
4536
4668
  var normalizedBase = normalizeOptionalString(baseToken);
4537
4669
  if (!normalizedBase) {
4538
4670
  return null;
@@ -4550,12 +4682,12 @@ function resolveLookupDisplayField(baseToken, probeDocs, schemaFields) {
4550
4682
  }
4551
4683
  }
4552
4684
  }
4553
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
4685
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
4554
4686
  finally {
4555
4687
  try {
4556
4688
  if (schemaCandidates_1_1 && !schemaCandidates_1_1.done && (_a = schemaCandidates_1.return)) _a.call(schemaCandidates_1);
4557
4689
  }
4558
- finally { if (e_6) throw e_6.error; }
4690
+ finally { if (e_7) throw e_7.error; }
4559
4691
  }
4560
4692
  return schemaCandidates[0];
4561
4693
  }
@@ -4568,12 +4700,12 @@ function resolveLookupDisplayField(baseToken, probeDocs, schemaFields) {
4568
4700
  }
4569
4701
  }
4570
4702
  }
4571
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
4703
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
4572
4704
  finally {
4573
4705
  try {
4574
4706
  if (candidates_1_1 && !candidates_1_1.done && (_b = candidates_1.return)) _b.call(candidates_1);
4575
4707
  }
4576
- finally { if (e_7) throw e_7.error; }
4708
+ finally { if (e_8) throw e_8.error; }
4577
4709
  }
4578
4710
  return candidates.length ? candidates[0] : null;
4579
4711
  }
@@ -4586,8 +4718,8 @@ function resolveLookupMappingsForField(field, mappings) {
4586
4718
  }
4587
4719
  function applyIdLookupDisplayEnrichment(params) {
4588
4720
  return __awaiter(this, void 0, void 0, function () {
4589
- var docs, collection, db, dbName, idClient, idCustomer, isSuperAdmin, idFields, lookupMappings, allCollections, collectionProbeCache, collectionSchemaCache, lookupMeta, enrichedDocs, _loop_4, idFields_1, idFields_1_1, fieldEntry, e_8_1;
4590
- var e_8, _a;
4721
+ var docs, collection, db, dbName, idClient, idCustomer, isSuperAdmin, idFields, lookupMappings, allCollections, collectionProbeCache, collectionSchemaCache, lookupMeta, enrichedDocs, _loop_4, idFields_1, idFields_1_1, fieldEntry, e_9_1;
4722
+ var e_9, _a;
4591
4723
  return __generator(this, function (_b) {
4592
4724
  switch (_b.label) {
4593
4725
  case 0:
@@ -4611,8 +4743,8 @@ function applyIdLookupDisplayEnrichment(params) {
4611
4743
  lookupMeta = [];
4612
4744
  enrichedDocs = docs.map(function (doc) { return (__assign({}, doc)); });
4613
4745
  _loop_4 = function (fieldEntry) {
4614
- var values, baseToken, mappingMatches, candidateCollections, filteredCandidates, _loop_5, filteredCandidates_1, filteredCandidates_1_1, candidate, state_3, e_9_1;
4615
- var e_9, _c;
4746
+ var values, baseToken, mappingMatches, candidateCollections, filteredCandidates, _loop_5, filteredCandidates_1, filteredCandidates_1_1, candidate, state_3, e_10_1;
4747
+ var e_10, _c;
4616
4748
  return __generator(this, function (_d) {
4617
4749
  switch (_d.label) {
4618
4750
  case 0:
@@ -4761,7 +4893,7 @@ function applyIdLookupDisplayEnrichment(params) {
4761
4893
  _d.label = 1;
4762
4894
  case 1:
4763
4895
  _d.trys.push([1, 6, 7, 8]);
4764
- filteredCandidates_1 = (e_9 = void 0, __values(filteredCandidates)), filteredCandidates_1_1 = filteredCandidates_1.next();
4896
+ filteredCandidates_1 = (e_10 = void 0, __values(filteredCandidates)), filteredCandidates_1_1 = filteredCandidates_1.next();
4765
4897
  _d.label = 2;
4766
4898
  case 2:
4767
4899
  if (!!filteredCandidates_1_1.done) return [3 /*break*/, 5];
@@ -4777,14 +4909,14 @@ function applyIdLookupDisplayEnrichment(params) {
4777
4909
  return [3 /*break*/, 2];
4778
4910
  case 5: return [3 /*break*/, 8];
4779
4911
  case 6:
4780
- e_9_1 = _d.sent();
4781
- e_9 = { error: e_9_1 };
4912
+ e_10_1 = _d.sent();
4913
+ e_10 = { error: e_10_1 };
4782
4914
  return [3 /*break*/, 8];
4783
4915
  case 7:
4784
4916
  try {
4785
4917
  if (filteredCandidates_1_1 && !filteredCandidates_1_1.done && (_c = filteredCandidates_1.return)) _c.call(filteredCandidates_1);
4786
4918
  }
4787
- finally { if (e_9) throw e_9.error; }
4919
+ finally { if (e_10) throw e_10.error; }
4788
4920
  return [7 /*endfinally*/];
4789
4921
  case 8: return [2 /*return*/];
4790
4922
  }
@@ -4807,14 +4939,14 @@ function applyIdLookupDisplayEnrichment(params) {
4807
4939
  return [3 /*break*/, 3];
4808
4940
  case 6: return [3 /*break*/, 9];
4809
4941
  case 7:
4810
- e_8_1 = _b.sent();
4811
- e_8 = { error: e_8_1 };
4942
+ e_9_1 = _b.sent();
4943
+ e_9 = { error: e_9_1 };
4812
4944
  return [3 /*break*/, 9];
4813
4945
  case 8:
4814
4946
  try {
4815
4947
  if (idFields_1_1 && !idFields_1_1.done && (_a = idFields_1.return)) _a.call(idFields_1);
4816
4948
  }
4817
- finally { if (e_8) throw e_8.error; }
4949
+ finally { if (e_9) throw e_9.error; }
4818
4950
  return [7 /*endfinally*/];
4819
4951
  case 9:
4820
4952
  if (!lookupMeta.length) {
@@ -4833,7 +4965,7 @@ function applyIdLookupDisplayEnrichment(params) {
4833
4965
  });
4834
4966
  }
4835
4967
  function hasNonEmptyValue(docs, fieldPath, options) {
4836
- var e_10, _a;
4968
+ var e_11, _a;
4837
4969
  if (!Array.isArray(docs) || !fieldPath) {
4838
4970
  return false;
4839
4971
  }
@@ -4850,12 +4982,12 @@ function hasNonEmptyValue(docs, fieldPath, options) {
4850
4982
  }
4851
4983
  }
4852
4984
  }
4853
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
4985
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
4854
4986
  finally {
4855
4987
  try {
4856
4988
  if (docs_4_1 && !docs_4_1.done && (_a = docs_4.return)) _a.call(docs_4);
4857
4989
  }
4858
- finally { if (e_10) throw e_10.error; }
4990
+ finally { if (e_11) throw e_11.error; }
4859
4991
  }
4860
4992
  return false;
4861
4993
  }
@@ -5519,6 +5651,12 @@ function formatAssistantDisplayCell(value, column) {
5519
5651
  }
5520
5652
  }
5521
5653
  var columnKey = String(column || '').toLowerCase();
5654
+ if (columnKey.includes('month')) {
5655
+ var monthBucket = normalizeAssistantMonthBucket(value);
5656
+ if (monthBucket) {
5657
+ return monthBucket;
5658
+ }
5659
+ }
5522
5660
  if (isAssistantDateColumn(columnKey) && isAssistantLikelyDateValue(value)) {
5523
5661
  return formatAssistantDateValue(value);
5524
5662
  }
@@ -5581,9 +5719,49 @@ function stripAssistantMarkdownTables(value) {
5581
5719
  if (!raw) {
5582
5720
  return '';
5583
5721
  }
5584
- var tablePattern = /(^|\n)\s*\|[^\n]*\|\s*\n\s*\|[ \t:-|]+\|\s*\n(?:\s*\|[^\n]*\|\s*\n?)*/g;
5585
- var cleaned = raw.replace(tablePattern, '\n').trim();
5586
- return cleaned;
5722
+ var lines = raw.split('\n');
5723
+ var kept = [];
5724
+ for (var index = 0; index < lines.length; index += 1) {
5725
+ var line = lines[index];
5726
+ var nextLine = lines[index + 1];
5727
+ if (isAssistantMarkdownTableHeaderLine(line) && isAssistantMarkdownTableSeparatorLine(nextLine || '')) {
5728
+ index += 2;
5729
+ while (index < lines.length && isAssistantMarkdownTableRowLine(lines[index])) {
5730
+ index += 1;
5731
+ }
5732
+ while (index < lines.length && !normalizeOptionalString(lines[index])) {
5733
+ index += 1;
5734
+ }
5735
+ index -= 1;
5736
+ if (kept.length && normalizeOptionalString(kept[kept.length - 1])) {
5737
+ kept.push('');
5738
+ }
5739
+ continue;
5740
+ }
5741
+ kept.push(line);
5742
+ }
5743
+ return kept.join('\n').replace(/\n{3,}/g, '\n\n').trim();
5744
+ }
5745
+ function isAssistantMarkdownTableHeaderLine(line) {
5746
+ var trimmed = normalizeOptionalString(line);
5747
+ if (!trimmed || !trimmed.includes('|')) {
5748
+ return false;
5749
+ }
5750
+ return /^\|.+\|$/.test(trimmed);
5751
+ }
5752
+ function isAssistantMarkdownTableSeparatorLine(line) {
5753
+ var trimmed = normalizeOptionalString(line);
5754
+ if (!trimmed || !trimmed.includes('|')) {
5755
+ return false;
5756
+ }
5757
+ return /^\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(trimmed);
5758
+ }
5759
+ function isAssistantMarkdownTableRowLine(line) {
5760
+ var trimmed = normalizeOptionalString(line);
5761
+ if (!trimmed || !trimmed.includes('|')) {
5762
+ return false;
5763
+ }
5764
+ return /^\|.*\|$/.test(trimmed);
5587
5765
  }
5588
5766
  function applyAssistantDisplayTableToResponse(value, display) {
5589
5767
  if (!display || !Array.isArray(display.rows) || !display.rows.length) {
@@ -6097,7 +6275,7 @@ function matchContainsField(value, field) {
6097
6275
  });
6098
6276
  }
6099
6277
  function resolveAggregateCompletionFallback(pipeline) {
6100
- var e_11, _a;
6278
+ var e_12, _a;
6101
6279
  if (!Array.isArray(pipeline)) {
6102
6280
  return null;
6103
6281
  }
@@ -6110,7 +6288,7 @@ function resolveAggregateCompletionFallback(pipeline) {
6110
6288
  }
6111
6289
  var addFields = stage.$addFields;
6112
6290
  try {
6113
- for (var _b = (e_11 = void 0, __values(Object.keys(addFields))), _c = _b.next(); !_c.done; _c = _b.next()) {
6291
+ for (var _b = (e_12 = void 0, __values(Object.keys(addFields))), _c = _b.next(); !_c.done; _c = _b.next()) {
6114
6292
  var key = _c.value;
6115
6293
  if (!isCompletionFieldName(key)) {
6116
6294
  continue;
@@ -6124,12 +6302,12 @@ function resolveAggregateCompletionFallback(pipeline) {
6124
6302
  }
6125
6303
  }
6126
6304
  }
6127
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
6305
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
6128
6306
  finally {
6129
6307
  try {
6130
6308
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6131
6309
  }
6132
- finally { if (e_11) throw e_11.error; }
6310
+ finally { if (e_12) throw e_12.error; }
6133
6311
  }
6134
6312
  if (candidateField) {
6135
6313
  break;
@@ -6285,7 +6463,7 @@ function buildCompletionFallbackSources(field) {
6285
6463
  ]);
6286
6464
  }
6287
6465
  function resolveAggregateCompletionExprFallback(pipeline) {
6288
- var e_12, _a;
6466
+ var e_13, _a;
6289
6467
  if (!Array.isArray(pipeline)) {
6290
6468
  return null;
6291
6469
  }
@@ -6305,7 +6483,7 @@ function resolveAggregateCompletionExprFallback(pipeline) {
6305
6483
  }
6306
6484
  if (!candidateField) {
6307
6485
  try {
6308
- for (var _b = (e_12 = void 0, __values(Object.keys(matchStage))), _c = _b.next(); !_c.done; _c = _b.next()) {
6486
+ for (var _b = (e_13 = void 0, __values(Object.keys(matchStage))), _c = _b.next(); !_c.done; _c = _b.next()) {
6309
6487
  var key = _c.value;
6310
6488
  if (key.startsWith('$')) {
6311
6489
  continue;
@@ -6320,12 +6498,12 @@ function resolveAggregateCompletionExprFallback(pipeline) {
6320
6498
  }
6321
6499
  }
6322
6500
  }
6323
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
6501
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
6324
6502
  finally {
6325
6503
  try {
6326
6504
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6327
6505
  }
6328
- finally { if (e_12) throw e_12.error; }
6506
+ finally { if (e_13) throw e_13.error; }
6329
6507
  }
6330
6508
  }
6331
6509
  if (!candidateField) {
@@ -6495,7 +6673,7 @@ function isRegexMatchCondition(value) {
6495
6673
  return false;
6496
6674
  }
6497
6675
  function findRegexMatchInMatchObject(match, prefix) {
6498
- var e_13, _a, e_14, _b;
6676
+ var e_14, _a, e_15, _b;
6499
6677
  if (prefix === void 0) { prefix = ''; }
6500
6678
  if (Array.isArray(match)) {
6501
6679
  try {
@@ -6507,12 +6685,12 @@ function findRegexMatchInMatchObject(match, prefix) {
6507
6685
  }
6508
6686
  }
6509
6687
  }
6510
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
6688
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
6511
6689
  finally {
6512
6690
  try {
6513
6691
  if (match_1_1 && !match_1_1.done && (_a = match_1.return)) _a.call(match_1);
6514
6692
  }
6515
- finally { if (e_13) throw e_13.error; }
6693
+ finally { if (e_14) throw e_14.error; }
6516
6694
  }
6517
6695
  return null;
6518
6696
  }
@@ -6543,12 +6721,12 @@ function findRegexMatchInMatchObject(match, prefix) {
6543
6721
  }
6544
6722
  }
6545
6723
  }
6546
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
6724
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
6547
6725
  finally {
6548
6726
  try {
6549
6727
  if (keys_2_1 && !keys_2_1.done && (_b = keys_2.return)) _b.call(keys_2);
6550
6728
  }
6551
- finally { if (e_14) throw e_14.error; }
6729
+ finally { if (e_15) throw e_15.error; }
6552
6730
  }
6553
6731
  return null;
6554
6732
  }
@@ -6772,7 +6950,7 @@ function collectMatchFieldsByCondition(match, predicate, prefix) {
6772
6950
  return results;
6773
6951
  }
6774
6952
  function findMatchConditionForField(match, targetField, prefix) {
6775
- var e_15, _a, e_16, _b;
6953
+ var e_16, _a, e_17, _b;
6776
6954
  if (prefix === void 0) { prefix = ''; }
6777
6955
  if (!match || typeof match !== 'object') {
6778
6956
  return undefined;
@@ -6787,12 +6965,12 @@ function findMatchConditionForField(match, targetField, prefix) {
6787
6965
  }
6788
6966
  }
6789
6967
  }
6790
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
6968
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
6791
6969
  finally {
6792
6970
  try {
6793
6971
  if (match_2_1 && !match_2_1.done && (_a = match_2.return)) _a.call(match_2);
6794
6972
  }
6795
- finally { if (e_15) throw e_15.error; }
6973
+ finally { if (e_16) throw e_16.error; }
6796
6974
  }
6797
6975
  return undefined;
6798
6976
  }
@@ -6819,12 +6997,12 @@ function findMatchConditionForField(match, targetField, prefix) {
6819
6997
  }
6820
6998
  }
6821
6999
  }
6822
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
7000
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
6823
7001
  finally {
6824
7002
  try {
6825
7003
  if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
6826
7004
  }
6827
- finally { if (e_16) throw e_16.error; }
7005
+ finally { if (e_17) throw e_17.error; }
6828
7006
  }
6829
7007
  return undefined;
6830
7008
  }
@@ -6867,7 +7045,7 @@ function detectIdLikeValue(value) {
6867
7045
  return false;
6868
7046
  }
6869
7047
  function detectChemicalIdFromProbe(probeDocs, fields) {
6870
- var e_17, _a, e_18, _b;
7048
+ var e_18, _a, e_19, _b;
6871
7049
  if (!Array.isArray(probeDocs) || !probeDocs.length) {
6872
7050
  return false;
6873
7051
  }
@@ -6879,7 +7057,7 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
6879
7057
  for (var probeDocs_1 = __values(probeDocs), probeDocs_1_1 = probeDocs_1.next(); !probeDocs_1_1.done; probeDocs_1_1 = probeDocs_1.next()) {
6880
7058
  var doc = probeDocs_1_1.value;
6881
7059
  try {
6882
- for (var targets_1 = (e_18 = void 0, __values(targets)), targets_1_1 = targets_1.next(); !targets_1_1.done; targets_1_1 = targets_1.next()) {
7060
+ for (var targets_1 = (e_19 = void 0, __values(targets)), targets_1_1 = targets_1.next(); !targets_1_1.done; targets_1_1 = targets_1.next()) {
6883
7061
  var field = targets_1_1.value;
6884
7062
  var value = getValueAtPath(doc, field);
6885
7063
  if (Array.isArray(value)) {
@@ -6892,21 +7070,21 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
6892
7070
  }
6893
7071
  }
6894
7072
  }
6895
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
7073
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
6896
7074
  finally {
6897
7075
  try {
6898
7076
  if (targets_1_1 && !targets_1_1.done && (_b = targets_1.return)) _b.call(targets_1);
6899
7077
  }
6900
- finally { if (e_18) throw e_18.error; }
7078
+ finally { if (e_19) throw e_19.error; }
6901
7079
  }
6902
7080
  }
6903
7081
  }
6904
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
7082
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
6905
7083
  finally {
6906
7084
  try {
6907
7085
  if (probeDocs_1_1 && !probeDocs_1_1.done && (_a = probeDocs_1.return)) _a.call(probeDocs_1);
6908
7086
  }
6909
- finally { if (e_17) throw e_17.error; }
7087
+ finally { if (e_18) throw e_18.error; }
6910
7088
  }
6911
7089
  return false;
6912
7090
  }
@@ -7127,8 +7305,8 @@ function buildChemicalIdFieldCandidates(field) {
7127
7305
  }
7128
7306
  function applyChemicalNameLookupFallbackToQuery(params) {
7129
7307
  return __awaiter(this, void 0, void 0, function () {
7130
- var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, chemicalFields, targetField, condition, regex, sampleDocs, collectionNames, candidates, _loop_6, candidates_2, candidates_2_1, candidate, state_4, e_19_1;
7131
- var e_19, _a;
7308
+ var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, chemicalFields, targetField, condition, regex, sampleDocs, collectionNames, candidates, _loop_6, candidates_2, candidates_2_1, candidate, state_4, e_20_1;
7309
+ var e_20, _a;
7132
7310
  var _b;
7133
7311
  return __generator(this, function (_c) {
7134
7312
  switch (_c.label) {
@@ -7241,14 +7419,14 @@ function applyChemicalNameLookupFallbackToQuery(params) {
7241
7419
  return [3 /*break*/, 3];
7242
7420
  case 6: return [3 /*break*/, 9];
7243
7421
  case 7:
7244
- e_19_1 = _c.sent();
7245
- e_19 = { error: e_19_1 };
7422
+ e_20_1 = _c.sent();
7423
+ e_20 = { error: e_20_1 };
7246
7424
  return [3 /*break*/, 9];
7247
7425
  case 8:
7248
7426
  try {
7249
7427
  if (candidates_2_1 && !candidates_2_1.done && (_a = candidates_2.return)) _a.call(candidates_2);
7250
7428
  }
7251
- finally { if (e_19) throw e_19.error; }
7429
+ finally { if (e_20) throw e_20.error; }
7252
7430
  return [7 /*endfinally*/];
7253
7431
  case 9: return [2 /*return*/, null];
7254
7432
  }
@@ -7342,8 +7520,8 @@ function lookupIdsForNameMatch(params) {
7342
7520
  }
7343
7521
  function applyIdLookupFallbackToQuery(params) {
7344
7522
  return __awaiter(this, void 0, void 0, function () {
7345
- var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, conditions, collectionNames, _a, conditions_1, conditions_1_1, condition, regex, baseToken, targetFieldType, nextValue, localNameField, candidates, candidates_3, candidates_3_1, candidate, candidateHasClientScope, _b, candidateProbe, lookup, targetFieldType, normalizedIds, idsForQuery, e_20_1, e_21_1;
7346
- var e_21, _c, e_20, _d;
7523
+ var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, conditions, collectionNames, _a, conditions_1, conditions_1_1, condition, regex, baseToken, targetFieldType, nextValue, localNameField, candidates, candidates_3, candidates_3_1, candidate, candidateHasClientScope, _b, candidateProbe, lookup, targetFieldType, normalizedIds, idsForQuery, e_21_1, e_22_1;
7524
+ var e_22, _c, e_21, _d;
7347
7525
  var _e;
7348
7526
  return __generator(this, function (_f) {
7349
7527
  switch (_f.label) {
@@ -7413,7 +7591,7 @@ function applyIdLookupFallbackToQuery(params) {
7413
7591
  _f.label = 5;
7414
7592
  case 5:
7415
7593
  _f.trys.push([5, 14, 15, 16]);
7416
- candidates_3 = (e_20 = void 0, __values(candidates)), candidates_3_1 = candidates_3.next();
7594
+ candidates_3 = (e_21 = void 0, __values(candidates)), candidates_3_1 = candidates_3.next();
7417
7595
  _f.label = 6;
7418
7596
  case 6:
7419
7597
  if (!!candidates_3_1.done) return [3 /*break*/, 13];
@@ -7480,28 +7658,28 @@ function applyIdLookupFallbackToQuery(params) {
7480
7658
  return [3 /*break*/, 6];
7481
7659
  case 13: return [3 /*break*/, 16];
7482
7660
  case 14:
7483
- e_20_1 = _f.sent();
7484
- e_20 = { error: e_20_1 };
7661
+ e_21_1 = _f.sent();
7662
+ e_21 = { error: e_21_1 };
7485
7663
  return [3 /*break*/, 16];
7486
7664
  case 15:
7487
7665
  try {
7488
7666
  if (candidates_3_1 && !candidates_3_1.done && (_d = candidates_3.return)) _d.call(candidates_3);
7489
7667
  }
7490
- finally { if (e_20) throw e_20.error; }
7668
+ finally { if (e_21) throw e_21.error; }
7491
7669
  return [7 /*endfinally*/];
7492
7670
  case 16:
7493
7671
  conditions_1_1 = conditions_1.next();
7494
7672
  return [3 /*break*/, 4];
7495
7673
  case 17: return [3 /*break*/, 20];
7496
7674
  case 18:
7497
- e_21_1 = _f.sent();
7498
- e_21 = { error: e_21_1 };
7675
+ e_22_1 = _f.sent();
7676
+ e_22 = { error: e_22_1 };
7499
7677
  return [3 /*break*/, 20];
7500
7678
  case 19:
7501
7679
  try {
7502
7680
  if (conditions_1_1 && !conditions_1_1.done && (_c = conditions_1.return)) _c.call(conditions_1);
7503
7681
  }
7504
- finally { if (e_21) throw e_21.error; }
7682
+ finally { if (e_22) throw e_22.error; }
7505
7683
  return [7 /*endfinally*/];
7506
7684
  case 20: return [2 /*return*/, null];
7507
7685
  }
@@ -8353,7 +8531,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection) {
8353
8531
  throw new Error('AI assistant report builder bridge: Collection is not configured for report builder.');
8354
8532
  }
8355
8533
  function findQueryDateField(query) {
8356
- var e_22, _a, e_23, _b;
8534
+ var e_23, _a, e_24, _b;
8357
8535
  if (!query || typeof query !== 'object') {
8358
8536
  return null;
8359
8537
  }
@@ -8367,12 +8545,12 @@ function findQueryDateField(query) {
8367
8545
  }
8368
8546
  }
8369
8547
  }
8370
- catch (e_22_1) { e_22 = { error: e_22_1 }; }
8548
+ catch (e_23_1) { e_23 = { error: e_23_1 }; }
8371
8549
  finally {
8372
8550
  try {
8373
8551
  if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
8374
8552
  }
8375
- finally { if (e_22) throw e_22.error; }
8553
+ finally { if (e_23) throw e_23.error; }
8376
8554
  }
8377
8555
  return null;
8378
8556
  }
@@ -8391,12 +8569,12 @@ function findQueryDateField(query) {
8391
8569
  }
8392
8570
  }
8393
8571
  }
8394
- catch (e_23_1) { e_23 = { error: e_23_1 }; }
8572
+ catch (e_24_1) { e_24 = { error: e_24_1 }; }
8395
8573
  finally {
8396
8574
  try {
8397
8575
  if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
8398
8576
  }
8399
- finally { if (e_23) throw e_23.error; }
8577
+ finally { if (e_24) throw e_24.error; }
8400
8578
  }
8401
8579
  return null;
8402
8580
  }
@@ -8618,7 +8796,7 @@ function resolveQueryDateFieldFallback(query) {
8618
8796
  return { from: dateField, to: fallback };
8619
8797
  }
8620
8798
  function containsForbiddenMongoOperators(value) {
8621
- var e_24, _a;
8799
+ var e_25, _a;
8622
8800
  if (!value || typeof value !== 'object') {
8623
8801
  return false;
8624
8802
  }
@@ -8637,12 +8815,12 @@ function containsForbiddenMongoOperators(value) {
8637
8815
  }
8638
8816
  }
8639
8817
  }
8640
- catch (e_24_1) { e_24 = { error: e_24_1 }; }
8818
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
8641
8819
  finally {
8642
8820
  try {
8643
8821
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
8644
8822
  }
8645
- finally { if (e_24) throw e_24.error; }
8823
+ finally { if (e_25) throw e_25.error; }
8646
8824
  }
8647
8825
  return false;
8648
8826
  }
@@ -9018,8 +9196,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
9018
9196
  }
9019
9197
  function waitForCodexWorkerMessage(worker, streamStatusHandler) {
9020
9198
  return __awaiter(this, void 0, void 0, function () {
9021
- var _a, _b, _c, _d, message, payload, status_1, e_25_1;
9022
- var _e, e_25, _f, _g;
9199
+ var _a, _b, _c, _d, message, payload, status_1, e_26_1;
9200
+ var _e, e_26, _f, _g;
9023
9201
  return __generator(this, function (_h) {
9024
9202
  switch (_h.label) {
9025
9203
  case 0:
@@ -9046,8 +9224,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
9046
9224
  return [3 /*break*/, 1];
9047
9225
  case 4: return [3 /*break*/, 11];
9048
9226
  case 5:
9049
- e_25_1 = _h.sent();
9050
- e_25 = { error: e_25_1 };
9227
+ e_26_1 = _h.sent();
9228
+ e_26 = { error: e_26_1 };
9051
9229
  return [3 /*break*/, 11];
9052
9230
  case 6:
9053
9231
  _h.trys.push([6, , 9, 10]);
@@ -9058,7 +9236,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
9058
9236
  _h.label = 8;
9059
9237
  case 8: return [3 /*break*/, 10];
9060
9238
  case 9:
9061
- if (e_25) throw e_25.error;
9239
+ if (e_26) throw e_26.error;
9062
9240
  return [7 /*endfinally*/];
9063
9241
  case 10: return [7 /*endfinally*/];
9064
9242
  case 11: throw new CodexWorkerBootstrapError('Codex worker exited before completing.');
@@ -9520,7 +9698,7 @@ function resolveAssistantPlannerEnabled() {
9520
9698
  return raw === undefined ? true : raw === true;
9521
9699
  }
9522
9700
  function resolveAssistantPlannerKnownRoutes() {
9523
- var e_26, _a;
9701
+ var e_27, _a;
9524
9702
  var _b;
9525
9703
  var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
9526
9704
  var unique = new Set();
@@ -9533,12 +9711,12 @@ function resolveAssistantPlannerKnownRoutes() {
9533
9711
  }
9534
9712
  }
9535
9713
  }
9536
- catch (e_26_1) { e_26 = { error: e_26_1 }; }
9714
+ catch (e_27_1) { e_27 = { error: e_27_1 }; }
9537
9715
  finally {
9538
9716
  try {
9539
9717
  if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
9540
9718
  }
9541
- finally { if (e_26) throw e_26.error; }
9719
+ finally { if (e_27) throw e_27.error; }
9542
9720
  }
9543
9721
  return Array.from(unique).slice(0, AI_ASSISTANT_PLANNER_MAX_ROUTES);
9544
9722
  }
@@ -9781,7 +9959,7 @@ function normalizeRouteMatchKey(value) {
9781
9959
  return normalizeRouteKey(value).toLowerCase();
9782
9960
  }
9783
9961
  function buildClientRouteIndex() {
9784
- var e_27, _a;
9962
+ var e_28, _a;
9785
9963
  var _b;
9786
9964
  var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
9787
9965
  var set = new Set();
@@ -9800,12 +9978,12 @@ function buildClientRouteIndex() {
9800
9978
  }
9801
9979
  }
9802
9980
  }
9803
- catch (e_27_1) { e_27 = { error: e_27_1 }; }
9981
+ catch (e_28_1) { e_28 = { error: e_28_1 }; }
9804
9982
  finally {
9805
9983
  try {
9806
9984
  if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
9807
9985
  }
9808
- finally { if (e_27) throw e_27.error; }
9986
+ finally { if (e_28) throw e_28.error; }
9809
9987
  }
9810
9988
  return { set: set, map: map, size: routes.length };
9811
9989
  }
@@ -9946,7 +10124,7 @@ function sanitizeAssistantResponse(value) {
9946
10124
  return normalizeAssistantRoutes(normalizedCurrency);
9947
10125
  }
9948
10126
  function evaluateAssistantGuardrails(message) {
9949
- var e_28, _a;
10127
+ var e_29, _a;
9950
10128
  var normalized = String(message || '').toLowerCase();
9951
10129
  var patterns = [
9952
10130
  {
@@ -9992,12 +10170,12 @@ function evaluateAssistantGuardrails(message) {
9992
10170
  }
9993
10171
  }
9994
10172
  }
9995
- catch (e_28_1) { e_28 = { error: e_28_1 }; }
10173
+ catch (e_29_1) { e_29 = { error: e_29_1 }; }
9996
10174
  finally {
9997
10175
  try {
9998
10176
  if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
9999
10177
  }
10000
- finally { if (e_28) throw e_28.error; }
10178
+ finally { if (e_29) throw e_29.error; }
10001
10179
  }
10002
10180
  return null;
10003
10181
  }
@@ -10112,7 +10290,7 @@ function tokenizeArithmeticExpression(expression) {
10112
10290
  return tokens;
10113
10291
  }
10114
10292
  function evaluateArithmeticExpression(expression) {
10115
- var e_29, _a, e_30, _b;
10293
+ var e_30, _a, e_31, _b;
10116
10294
  var tokens = tokenizeArithmeticExpression(expression);
10117
10295
  if (!tokens || !tokens.length) {
10118
10296
  return null;
@@ -10169,12 +10347,12 @@ function evaluateArithmeticExpression(expression) {
10169
10347
  prevToken = token;
10170
10348
  }
10171
10349
  }
10172
- catch (e_29_1) { e_29 = { error: e_29_1 }; }
10350
+ catch (e_30_1) { e_30 = { error: e_30_1 }; }
10173
10351
  finally {
10174
10352
  try {
10175
10353
  if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
10176
10354
  }
10177
- finally { if (e_29) throw e_29.error; }
10355
+ finally { if (e_30) throw e_30.error; }
10178
10356
  }
10179
10357
  while (ops.length) {
10180
10358
  var op = ops.pop();
@@ -10214,12 +10392,12 @@ function evaluateArithmeticExpression(expression) {
10214
10392
  stack.push(Number(token));
10215
10393
  }
10216
10394
  }
10217
- catch (e_30_1) { e_30 = { error: e_30_1 }; }
10395
+ catch (e_31_1) { e_31 = { error: e_31_1 }; }
10218
10396
  finally {
10219
10397
  try {
10220
10398
  if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
10221
10399
  }
10222
- finally { if (e_30) throw e_30.error; }
10400
+ finally { if (e_31) throw e_31.error; }
10223
10401
  }
10224
10402
  if (stack.length !== 1 || Number.isNaN(stack[0])) {
10225
10403
  return null;
@@ -10403,8 +10581,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
10403
10581
  }
10404
10582
  function readAttachmentContents(attachments) {
10405
10583
  return __awaiter(this, void 0, void 0, function () {
10406
- var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_31_1;
10407
- var e_31, _b;
10584
+ var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_32_1;
10585
+ var e_32, _b;
10408
10586
  return __generator(this, function (_c) {
10409
10587
  switch (_c.label) {
10410
10588
  case 0:
@@ -10483,14 +10661,14 @@ function readAttachmentContents(attachments) {
10483
10661
  return [3 /*break*/, 2];
10484
10662
  case 10: return [3 /*break*/, 13];
10485
10663
  case 11:
10486
- e_31_1 = _c.sent();
10487
- e_31 = { error: e_31_1 };
10664
+ e_32_1 = _c.sent();
10665
+ e_32 = { error: e_32_1 };
10488
10666
  return [3 /*break*/, 13];
10489
10667
  case 12:
10490
10668
  try {
10491
10669
  if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
10492
10670
  }
10493
- finally { if (e_31) throw e_31.error; }
10671
+ finally { if (e_32) throw e_32.error; }
10494
10672
  return [7 /*endfinally*/];
10495
10673
  case 13: return [2 /*return*/, {
10496
10674
  promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
@@ -10678,7 +10856,7 @@ function estimateUsage(messages, responseText, model) {
10678
10856
  };
10679
10857
  }
10680
10858
  function evaluateGuardrails(message) {
10681
- var e_32, _a;
10859
+ var e_33, _a;
10682
10860
  var normalized = String(message || '').toLowerCase();
10683
10861
  var patterns = [
10684
10862
  { pattern: /\b(source\s*code|full\s*code|entire\s*code|repo\s*dump|repository|git\s*clone)\b/i, reason: 'Code access is restricted.' },
@@ -10700,12 +10878,12 @@ function evaluateGuardrails(message) {
10700
10878
  }
10701
10879
  }
10702
10880
  }
10703
- catch (e_32_1) { e_32 = { error: e_32_1 }; }
10881
+ catch (e_33_1) { e_33 = { error: e_33_1 }; }
10704
10882
  finally {
10705
10883
  try {
10706
10884
  if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
10707
10885
  }
10708
- finally { if (e_32) throw e_32.error; }
10886
+ finally { if (e_33) throw e_33.error; }
10709
10887
  }
10710
10888
  return null;
10711
10889
  }