@resolveio/server-lib 22.2.32 → 22.2.33

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.
@@ -126,6 +126,7 @@ exports.repairAssistantFieldPathReferenceInPipeline = repairAssistantFieldPathRe
126
126
  exports.rewriteMatchExpressionsToExpr = rewriteMatchExpressionsToExpr;
127
127
  exports.normalizeAssistantMonthlyCalendarWindowPipeline = normalizeAssistantMonthlyCalendarWindowPipeline;
128
128
  exports.normalizeAssistantAggregatePipeline = normalizeAssistantAggregatePipeline;
129
+ exports.resolveReadMultiTermJobRegexFallbackForTesting = resolveReadMultiTermJobRegexFallbackForTesting;
129
130
  exports.stripQueryFieldPathsDeep = stripQueryFieldPathsDeep;
130
131
  exports.stripScopedFieldsFromPipeline = stripScopedFieldsFromPipeline;
131
132
  exports.rewriteEmbeddedMatchObjects = rewriteEmbeddedMatchObjects;
@@ -201,6 +202,7 @@ var AI_ASSISTANT_COLLECTION_OVERRIDE_MIN_SCORE = 20;
201
202
  var AI_ASSISTANT_ID_LOOKUP_MAX_RESULTS = 20;
202
203
  var AI_ASSISTANT_ID_LOOKUP_CANDIDATE_LIMIT = 4;
203
204
  var AI_ASSISTANT_NAME_MATCH_FALLBACK_MAX_FIELDS = 12;
205
+ var AI_ASSISTANT_MULTI_TERM_NAME_FALLBACK_MAX_TERMS = 4;
204
206
  var AI_ASSISTANT_CONTEXT_MAX_COLLECTIONS = 3;
205
207
  var AI_ASSISTANT_CONTEXT_MAX_FIELDS_PER_COLLECTION = 24;
206
208
  var AI_ASSISTANT_CONTEXT_MAX_SCHEMA_COLLECTIONS = 5;
@@ -245,6 +247,23 @@ var AI_ASSISTANT_DATE_FALLBACKS = {
245
247
  date_treated: 'date_scheduled',
246
248
  date_scheduled: 'date_treated'
247
249
  };
250
+ var AI_ASSISTANT_JOB_LIKE_FIELD_TOKENS = new Set([
251
+ 'job',
252
+ 'bid',
253
+ 'jca',
254
+ 'well',
255
+ 'pad'
256
+ ]);
257
+ var AI_ASSISTANT_JOB_TEXT_FALLBACK_FIELDS = [
258
+ 'job',
259
+ 'job_number_string',
260
+ 'job_number',
261
+ 'bid',
262
+ 'jca',
263
+ 'pad',
264
+ 'well',
265
+ 'wells.well'
266
+ ];
248
267
  var AI_ASSISTANT_DATE_EXPANSION_FIELDS = [
249
268
  'date',
250
269
  'date_start',
@@ -3289,12 +3308,12 @@ function executeAiAssistantReportIssue(payload, context) {
3289
3308
  }
3290
3309
  function executeAiAssistantMongoRead(payload, context) {
3291
3310
  return __awaiter(this, void 0, void 0, function () {
3292
- var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, idApp, requestHints, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasReadRuntimeBudget, resolveReadMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, buildFindOptions, buildCountOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _d, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _e, activeFallback, fallbackRead, fallbackDocs, _f, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality, error_5, existingErrors, e_1_1, nameFields, dateFields, diagnostics, countOptions, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, total, sanitizedDocuments, requestedFields, missingFields, _o, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
3293
- var e_1, _p;
3311
+ var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, idApp, requestHints, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasReadRuntimeBudget, resolveReadMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, buildFindOptions, buildCountOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, multiTermFallback, fallbackRead, fallbackDocs, _d, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _e, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _f, activeFallback, fallbackRead, fallbackDocs, _g, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality, error_5, existingErrors, e_1_1, nameFields, dateFields, diagnostics, countOptions, queryNoName, _h, queryNoDate, _j, _k, _l, _m, allCollections, base, alt, altCount, _o, total, sanitizedDocuments, requestedFields, missingFields, _p, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
3312
+ var e_1, _q;
3294
3313
  var _this = this;
3295
- var _q, _r;
3296
- return __generator(this, function (_s) {
3297
- switch (_s.label) {
3314
+ var _r, _s;
3315
+ return __generator(this, function (_t) {
3316
+ switch (_t.label) {
3298
3317
  case 0:
3299
3318
  input = payload || {};
3300
3319
  rawCollection = normalizeOptionalString(input.collection);
@@ -3313,14 +3332,14 @@ function executeAiAssistantMongoRead(payload, context) {
3313
3332
  requestHints = normalizeAssistantDirectiveHints(input.__assistantHints);
3314
3333
  return [4 /*yield*/, resolveAssistantCollectionName(db, dbName, rawCollection, idApp)];
3315
3334
  case 1:
3316
- collectionResolution = _s.sent();
3335
+ collectionResolution = _t.sent();
3317
3336
  collection = collectionResolution.name || rawCollection;
3318
3337
  return [4 /*yield*/, resolveAssistantReportBuilderBridgeCollection(collection, db, dbName, {
3319
3338
  requestHints: requestHints,
3320
3339
  appId: idApp
3321
3340
  })];
3322
3341
  case 2:
3323
- bridgeCollection = _s.sent();
3342
+ bridgeCollection = _t.sent();
3324
3343
  if (bridgeCollection.fallbackFrom) {
3325
3344
  collection = bridgeCollection.collection;
3326
3345
  }
@@ -3332,11 +3351,11 @@ function executeAiAssistantMongoRead(payload, context) {
3332
3351
  : input.permissionView;
3333
3352
  return [4 /*yield*/, ensureAssistantReadAccess(context, effectivePermissionView, collection)];
3334
3353
  case 3:
3335
- _a = _s.sent(), user = _a.user, isSuperAdmin = _a.isSuperAdmin, canViewDebug = _a.canViewDebug;
3354
+ _a = _t.sent(), user = _a.user, isSuperAdmin = _a.isSuperAdmin, canViewDebug = _a.canViewDebug;
3336
3355
  if (!isSuperAdmin && AI_ASSISTANT_BLOCKED_COLLECTIONS.has(collection)) {
3337
3356
  throw new Error('AI assistant report builder bridge: Access denied.');
3338
3357
  }
3339
- customerId = normalizeOptionalString((_q = user === null || user === void 0 ? void 0 : user.other) === null || _q === void 0 ? void 0 : _q.id_customer);
3358
+ customerId = normalizeOptionalString((_r = user === null || user === void 0 ? void 0 : user.other) === null || _r === void 0 ? void 0 : _r.id_customer);
3340
3359
  fallbackMeta = {};
3341
3360
  runtimeControl = normalizeAssistantRuntimeControl(input.__assistantRuntime);
3342
3361
  runtimeFastMode = (runtimeControl === null || runtimeControl === void 0 ? void 0 : runtimeControl.fastMode) === undefined
@@ -3395,11 +3414,11 @@ function executeAiAssistantMongoRead(payload, context) {
3395
3414
  if (!(!isSuperAdmin && normalizedClient)) return [3 /*break*/, 5];
3396
3415
  return [4 /*yield*/, collectionHasClientIndex(db, dbName, collection)];
3397
3416
  case 4:
3398
- _b = _s.sent();
3417
+ _b = _t.sent();
3399
3418
  return [3 /*break*/, 6];
3400
3419
  case 5:
3401
3420
  _b = false;
3402
- _s.label = 6;
3421
+ _t.label = 6;
3403
3422
  case 6:
3404
3423
  shouldScopeByClient = _b;
3405
3424
  if (!isSuperAdmin && shouldScopeByClient) {
@@ -3471,7 +3490,7 @@ function executeAiAssistantMongoRead(payload, context) {
3471
3490
  }); };
3472
3491
  return [4 /*yield*/, runFindWithRepair(scopedQuery, 'initial')];
3473
3492
  case 7:
3474
- initialRead = _s.sent();
3493
+ initialRead = _t.sent();
3475
3494
  documents = initialRead.documents;
3476
3495
  executedQuery = initialRead.query;
3477
3496
  probeDocs = null;
@@ -3482,14 +3501,14 @@ function executeAiAssistantMongoRead(payload, context) {
3482
3501
  fallbackMeta.dateField = __assign(__assign({}, dateFallback), { attempted: true, used: false });
3483
3502
  return [4 /*yield*/, runFindWithRepair(fallbackQuery, 'date_field_fallback')];
3484
3503
  case 8:
3485
- fallbackRead = _s.sent();
3504
+ fallbackRead = _t.sent();
3486
3505
  fallbackDocs = fallbackRead.documents;
3487
3506
  if (fallbackDocs.length) {
3488
3507
  documents = fallbackDocs;
3489
3508
  executedQuery = fallbackRead.query;
3490
3509
  fallbackMeta.dateField.used = true;
3491
3510
  }
3492
- _s.label = 9;
3511
+ _t.label = 9;
3493
3512
  case 9:
3494
3513
  if (!!documents.length) return [3 /*break*/, 11];
3495
3514
  expanded = expandQueryDateFallbacks(executedQuery, schemaFields);
@@ -3501,14 +3520,14 @@ function executeAiAssistantMongoRead(payload, context) {
3501
3520
  };
3502
3521
  return [4 /*yield*/, runFindWithRepair(expanded.query, 'date_fields_expanded')];
3503
3522
  case 10:
3504
- fallbackRead = _s.sent();
3523
+ fallbackRead = _t.sent();
3505
3524
  fallbackDocs = fallbackRead.documents;
3506
3525
  if (fallbackDocs.length) {
3507
3526
  documents = fallbackDocs;
3508
3527
  executedQuery = fallbackRead.query;
3509
3528
  fallbackMeta.dateFieldsExpanded.used = true;
3510
3529
  }
3511
- _s.label = 11;
3530
+ _t.label = 11;
3512
3531
  case 11:
3513
3532
  if (!!documents.length) return [3 /*break*/, 13];
3514
3533
  nameFallback = resolveReadNameMatchFallback(executedQuery);
@@ -3521,16 +3540,16 @@ function executeAiAssistantMongoRead(payload, context) {
3521
3540
  };
3522
3541
  return [4 /*yield*/, runFindWithRepair(nameFallback.query, 'name_match')];
3523
3542
  case 12:
3524
- fallbackRead = _s.sent();
3543
+ fallbackRead = _t.sent();
3525
3544
  fallbackDocs = fallbackRead.documents;
3526
3545
  if (fallbackDocs.length) {
3527
3546
  documents = fallbackDocs;
3528
3547
  executedQuery = fallbackRead.query;
3529
3548
  fallbackMeta.nameMatch.used = true;
3530
3549
  }
3531
- _s.label = 13;
3550
+ _t.label = 13;
3532
3551
  case 13:
3533
- if (!!documents.length) return [3 /*break*/, 18];
3552
+ if (!!documents.length) return [3 /*break*/, 17];
3534
3553
  _c = probeDocs;
3535
3554
  if (_c) return [3 /*break*/, 15];
3536
3555
  return [4 /*yield*/, fetchAssistantProbeDocs({
@@ -3543,10 +3562,47 @@ function executeAiAssistantMongoRead(payload, context) {
3543
3562
  maxTimeMS: resolveReadMaxTimeMS()
3544
3563
  })];
3545
3564
  case 14:
3546
- _c = (_s.sent());
3547
- _s.label = 15;
3565
+ _c = (_t.sent());
3566
+ _t.label = 15;
3548
3567
  case 15:
3549
3568
  probeDocs = _c;
3569
+ multiTermFallback = resolveReadMultiTermJobRegexFallback(executedQuery, probeDocs || [], schemaFields);
3570
+ if (!multiTermFallback) return [3 /*break*/, 17];
3571
+ fallbackMeta.multiTermNameMatch = {
3572
+ sourceFields: multiTermFallback.sourceFields,
3573
+ fields: multiTermFallback.fields,
3574
+ terms: multiTermFallback.terms,
3575
+ attempted: true,
3576
+ used: false
3577
+ };
3578
+ return [4 /*yield*/, runFindWithRepair(multiTermFallback.query, 'multi_term_name_match')];
3579
+ case 16:
3580
+ fallbackRead = _t.sent();
3581
+ fallbackDocs = fallbackRead.documents;
3582
+ if (fallbackDocs.length) {
3583
+ documents = fallbackDocs;
3584
+ executedQuery = fallbackRead.query;
3585
+ fallbackMeta.multiTermNameMatch.used = true;
3586
+ }
3587
+ _t.label = 17;
3588
+ case 17:
3589
+ if (!!documents.length) return [3 /*break*/, 22];
3590
+ _d = probeDocs;
3591
+ if (_d) return [3 /*break*/, 19];
3592
+ return [4 /*yield*/, fetchAssistantProbeDocs({
3593
+ db: db,
3594
+ collection: collection,
3595
+ idClient: normalizedClient,
3596
+ idCustomer: customerId,
3597
+ isSuperAdmin: isSuperAdmin,
3598
+ includeClientScope: shouldScopeByClient,
3599
+ maxTimeMS: resolveReadMaxTimeMS()
3600
+ })];
3601
+ case 18:
3602
+ _d = (_t.sent());
3603
+ _t.label = 19;
3604
+ case 19:
3605
+ probeDocs = _d;
3550
3606
  return [4 /*yield*/, applyChemicalNameLookupFallbackToQuery({
3551
3607
  query: executedQuery,
3552
3608
  db: db,
@@ -3556,26 +3612,26 @@ function executeAiAssistantMongoRead(payload, context) {
3556
3612
  isSuperAdmin: isSuperAdmin,
3557
3613
  probeDocs: probeDocs || undefined
3558
3614
  })];
3559
- case 16:
3560
- chemicalLookup = _s.sent();
3561
- if (!chemicalLookup) return [3 /*break*/, 18];
3615
+ case 20:
3616
+ chemicalLookup = _t.sent();
3617
+ if (!chemicalLookup) return [3 /*break*/, 22];
3562
3618
  fallbackMeta.chemicalLookup = __assign(__assign({}, chemicalLookup.meta), { attempted: true, used: false });
3563
3619
  return [4 /*yield*/, runFindWithRepair(chemicalLookup.query, 'chemical_lookup')];
3564
- case 17:
3565
- fallbackRead = _s.sent();
3620
+ case 21:
3621
+ fallbackRead = _t.sent();
3566
3622
  fallbackDocs = fallbackRead.documents;
3567
3623
  if (fallbackDocs.length) {
3568
3624
  documents = fallbackDocs;
3569
3625
  executedQuery = fallbackRead.query;
3570
3626
  fallbackMeta.chemicalLookup.used = true;
3571
3627
  }
3572
- _s.label = 18;
3573
- case 18:
3574
- if (!!documents.length) return [3 /*break*/, 22];
3628
+ _t.label = 22;
3629
+ case 22:
3630
+ if (!!documents.length) return [3 /*break*/, 26];
3575
3631
  queryFields = extractQueryFieldPaths(executedQuery).filter(function (field) { return !isAssistantIdField(field); });
3576
- if (!queryFields.length) return [3 /*break*/, 22];
3577
- _d = probeDocs;
3578
- if (_d) return [3 /*break*/, 20];
3632
+ if (!queryFields.length) return [3 /*break*/, 26];
3633
+ _e = probeDocs;
3634
+ if (_e) return [3 /*break*/, 24];
3579
3635
  return [4 /*yield*/, fetchAssistantProbeDocs({
3580
3636
  db: db,
3581
3637
  collection: collection,
@@ -3585,14 +3641,14 @@ function executeAiAssistantMongoRead(payload, context) {
3585
3641
  includeClientScope: shouldScopeByClient,
3586
3642
  maxTimeMS: resolveReadMaxTimeMS()
3587
3643
  })];
3588
- case 19:
3589
- _d = (_s.sent());
3590
- _s.label = 20;
3591
- case 20:
3592
- probeDocs = _d;
3593
- if (!probeDocs.length) return [3 /*break*/, 22];
3644
+ case 23:
3645
+ _e = (_t.sent());
3646
+ _t.label = 24;
3647
+ case 24:
3648
+ probeDocs = _e;
3649
+ if (!probeDocs.length) return [3 /*break*/, 26];
3594
3650
  aliases = resolveFieldAliases(probeDocs, queryFields, schemaFields);
3595
- if (!Object.keys(aliases).length) return [3 /*break*/, 22];
3651
+ if (!Object.keys(aliases).length) return [3 /*break*/, 26];
3596
3652
  fallbackMeta.queryFieldAliases = {
3597
3653
  aliases: aliases,
3598
3654
  attempted: true,
@@ -3604,19 +3660,19 @@ function executeAiAssistantMongoRead(payload, context) {
3604
3660
  return replaceFieldPathDeep(acc, from, to);
3605
3661
  }, executedQuery);
3606
3662
  return [4 /*yield*/, runFindWithRepair(rewrittenQuery, 'query_field_aliases')];
3607
- case 21:
3608
- fallbackRead = _s.sent();
3663
+ case 25:
3664
+ fallbackRead = _t.sent();
3609
3665
  fallbackDocs = fallbackRead.documents;
3610
3666
  if (fallbackDocs.length) {
3611
3667
  documents = fallbackDocs;
3612
3668
  executedQuery = fallbackRead.query;
3613
3669
  fallbackMeta.queryFieldAliases.used = true;
3614
3670
  }
3615
- _s.label = 22;
3616
- case 22:
3617
- if (!!documents.length) return [3 /*break*/, 26];
3618
- _e = probeDocs;
3619
- if (_e) return [3 /*break*/, 24];
3671
+ _t.label = 26;
3672
+ case 26:
3673
+ if (!!documents.length) return [3 /*break*/, 30];
3674
+ _f = probeDocs;
3675
+ if (_f) return [3 /*break*/, 28];
3620
3676
  return [4 /*yield*/, fetchAssistantProbeDocs({
3621
3677
  db: db,
3622
3678
  collection: collection,
@@ -3626,13 +3682,13 @@ function executeAiAssistantMongoRead(payload, context) {
3626
3682
  includeClientScope: shouldScopeByClient,
3627
3683
  maxTimeMS: resolveReadMaxTimeMS()
3628
3684
  })];
3629
- case 23:
3630
- _e = (_s.sent());
3631
- _s.label = 24;
3632
- case 24:
3633
- probeDocs = _e;
3685
+ case 27:
3686
+ _f = (_t.sent());
3687
+ _t.label = 28;
3688
+ case 28:
3689
+ probeDocs = _f;
3634
3690
  activeFallback = resolveReadActiveStatusFallback(executedQuery, probeDocs || [], schemaFields);
3635
- if (!activeFallback) return [3 /*break*/, 26];
3691
+ if (!activeFallback) return [3 /*break*/, 30];
3636
3692
  fallbackMeta.activeStatus = {
3637
3693
  fields: activeFallback.fields,
3638
3694
  attempted: true,
@@ -3640,19 +3696,19 @@ function executeAiAssistantMongoRead(payload, context) {
3640
3696
  reason: 'active_fields_missing_in_collection'
3641
3697
  };
3642
3698
  return [4 /*yield*/, runFindWithRepair(activeFallback.query, 'active_status')];
3643
- case 25:
3644
- fallbackRead = _s.sent();
3699
+ case 29:
3700
+ fallbackRead = _t.sent();
3645
3701
  fallbackDocs = fallbackRead.documents;
3646
3702
  if (fallbackDocs.length) {
3647
3703
  documents = fallbackDocs;
3648
3704
  executedQuery = fallbackRead.query;
3649
3705
  fallbackMeta.activeStatus.used = true;
3650
3706
  }
3651
- _s.label = 26;
3652
- case 26:
3653
- if (!!documents.length) return [3 /*break*/, 31];
3654
- _f = probeDocs;
3655
- if (_f) return [3 /*break*/, 28];
3707
+ _t.label = 30;
3708
+ case 30:
3709
+ if (!!documents.length) return [3 /*break*/, 35];
3710
+ _g = probeDocs;
3711
+ if (_g) return [3 /*break*/, 32];
3656
3712
  return [4 /*yield*/, fetchAssistantProbeDocs({
3657
3713
  db: db,
3658
3714
  collection: collection,
@@ -3662,11 +3718,11 @@ function executeAiAssistantMongoRead(payload, context) {
3662
3718
  includeClientScope: shouldScopeByClient,
3663
3719
  maxTimeMS: resolveReadMaxTimeMS()
3664
3720
  })];
3665
- case 27:
3666
- _f = (_s.sent());
3667
- _s.label = 28;
3668
- case 28:
3669
- probeDocs = _f;
3721
+ case 31:
3722
+ _g = (_t.sent());
3723
+ _t.label = 32;
3724
+ case 32:
3725
+ probeDocs = _g;
3670
3726
  return [4 /*yield*/, applyIdLookupFallbackToQuery({
3671
3727
  query: executedQuery,
3672
3728
  db: db,
@@ -3676,33 +3732,33 @@ function executeAiAssistantMongoRead(payload, context) {
3676
3732
  isSuperAdmin: isSuperAdmin,
3677
3733
  probeDocs: probeDocs || undefined
3678
3734
  })];
3679
- case 29:
3680
- idLookup = _s.sent();
3681
- if (!idLookup) return [3 /*break*/, 31];
3735
+ case 33:
3736
+ idLookup = _t.sent();
3737
+ if (!idLookup) return [3 /*break*/, 35];
3682
3738
  fallbackMeta.idLookup = __assign(__assign({}, idLookup.meta), { attempted: true, used: false });
3683
3739
  return [4 /*yield*/, runFindWithRepair(idLookup.query, 'id_lookup')];
3684
- case 30:
3685
- fallbackRead = _s.sent();
3740
+ case 34:
3741
+ fallbackRead = _t.sent();
3686
3742
  fallbackDocs = fallbackRead.documents;
3687
3743
  if (fallbackDocs.length) {
3688
3744
  documents = fallbackDocs;
3689
3745
  executedQuery = fallbackRead.query;
3690
3746
  fallbackMeta.idLookup.used = true;
3691
3747
  }
3692
- _s.label = 31;
3693
- case 31:
3694
- if (!(!documents.length && hasReadRuntimeBudget('report_fallback'))) return [3 /*break*/, 34];
3748
+ _t.label = 35;
3749
+ case 35:
3750
+ if (!(!documents.length && hasReadRuntimeBudget('report_fallback'))) return [3 /*break*/, 38];
3695
3751
  return [4 /*yield*/, resolveBaseCollectionFromReport(db, dbName, collection)];
3696
- case 32:
3697
- baseCollection = _s.sent();
3698
- if (!(baseCollection && baseCollection !== collection)) return [3 /*break*/, 34];
3752
+ case 36:
3753
+ baseCollection = _t.sent();
3754
+ if (!(baseCollection && baseCollection !== collection)) return [3 /*break*/, 38];
3699
3755
  addAssistantCollectionToTriedSet(triedCollections, baseCollection);
3700
3756
  fallbackPayload = __assign(__assign({}, input), { collection: baseCollection, __assistantRetryState: buildAssistantRetryState(retryState, triedCollections, {
3701
3757
  rootCollection: retryRootCollection
3702
3758
  }) });
3703
3759
  return [4 /*yield*/, executeAiAssistantMongoRead(fallbackPayload, context)];
3704
- case 33:
3705
- fallbackResult = _s.sent();
3760
+ case 37:
3761
+ fallbackResult = _t.sent();
3706
3762
  if (Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) && fallbackResult.documents.length) {
3707
3763
  if (canViewDebug && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
3708
3764
  existingFallbacks = fallbackResult.debug.fallbacks && typeof fallbackResult.debug.fallbacks === 'object'
@@ -3719,16 +3775,16 @@ function executeAiAssistantMongoRead(payload, context) {
3719
3775
  if (canViewDebug) {
3720
3776
  fallbackMeta.reportFallback = { from: collection, to: baseCollection, attempted: true, used: false };
3721
3777
  }
3722
- _s.label = 34;
3723
- case 34:
3778
+ _t.label = 38;
3779
+ case 38:
3724
3780
  hasActiveStatusFilters = collectAssistantActiveMatchFields(executedQuery).length > 0;
3725
- if (!(!documents.length && crossCollectionRetryEnabled && !hasActiveStatusFilters && hasReadRuntimeBudget('collection_retry'))) return [3 /*break*/, 46];
3781
+ if (!(!documents.length && crossCollectionRetryEnabled && !hasActiveStatusFilters && hasReadRuntimeBudget('collection_retry'))) return [3 /*break*/, 50];
3726
3782
  return [4 /*yield*/, resolveAssistantAvailableCrossCollectionFallbacks(db, dbName, collection, triedCollections, {
3727
3783
  fieldHints: extractQueryFieldPaths(executedQuery || {})
3728
3784
  })];
3729
- case 35:
3730
- crossCollectionCandidates = _s.sent();
3731
- if (!crossCollectionCandidates.length) return [3 /*break*/, 45];
3785
+ case 39:
3786
+ crossCollectionCandidates = _t.sent();
3787
+ if (!crossCollectionCandidates.length) return [3 /*break*/, 49];
3732
3788
  fallbackMeta.collectionRetry = {
3733
3789
  from: collection,
3734
3790
  root: retryRootCollection,
@@ -3736,25 +3792,25 @@ function executeAiAssistantMongoRead(payload, context) {
3736
3792
  attempted: true,
3737
3793
  used: false
3738
3794
  };
3739
- _s.label = 36;
3740
- case 36:
3741
- _s.trys.push([36, 43, 44, 45]);
3795
+ _t.label = 40;
3796
+ case 40:
3797
+ _t.trys.push([40, 47, 48, 49]);
3742
3798
  crossCollectionCandidates_1 = __values(crossCollectionCandidates), crossCollectionCandidates_1_1 = crossCollectionCandidates_1.next();
3743
- _s.label = 37;
3744
- case 37:
3745
- if (!!crossCollectionCandidates_1_1.done) return [3 /*break*/, 42];
3799
+ _t.label = 41;
3800
+ case 41:
3801
+ if (!!crossCollectionCandidates_1_1.done) return [3 /*break*/, 46];
3746
3802
  candidateCollection = crossCollectionCandidates_1_1.value;
3747
3803
  addAssistantCollectionToTriedSet(triedCollections, candidateCollection);
3748
3804
  fallbackPayload = __assign(__assign({}, input), { collection: candidateCollection, __assistantRetryState: buildAssistantRetryState(retryState, triedCollections, {
3749
3805
  rootCollection: retryRootCollection,
3750
3806
  disableCrossCollectionRetry: true
3751
3807
  }) });
3752
- _s.label = 38;
3753
- case 38:
3754
- _s.trys.push([38, 40, , 41]);
3808
+ _t.label = 42;
3809
+ case 42:
3810
+ _t.trys.push([42, 44, , 45]);
3755
3811
  return [4 /*yield*/, executeAiAssistantMongoRead(fallbackPayload, context)];
3756
- case 39:
3757
- fallbackResult = _s.sent();
3812
+ case 43:
3813
+ fallbackResult = _t.sent();
3758
3814
  fallbackDocs = Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) ? fallbackResult.documents : [];
3759
3815
  if (fallbackDocs.length && shouldAcceptAssistantFallbackDocuments(fallbackDocs)) {
3760
3816
  if (canViewDebug && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
@@ -3781,9 +3837,9 @@ function executeAiAssistantMongoRead(payload, context) {
3781
3837
  });
3782
3838
  fallbackMeta.collectionRetry.rejectedQuality = rejectedQuality;
3783
3839
  }
3784
- return [3 /*break*/, 41];
3785
- case 40:
3786
- error_5 = _s.sent();
3840
+ return [3 /*break*/, 45];
3841
+ case 44:
3842
+ error_5 = _t.sent();
3787
3843
  if (fallbackMeta.collectionRetry && typeof fallbackMeta.collectionRetry === 'object') {
3788
3844
  existingErrors = Array.isArray(fallbackMeta.collectionRetry.errors)
3789
3845
  ? fallbackMeta.collectionRetry.errors
@@ -3794,23 +3850,23 @@ function executeAiAssistantMongoRead(payload, context) {
3794
3850
  });
3795
3851
  fallbackMeta.collectionRetry.errors = existingErrors;
3796
3852
  }
3797
- return [3 /*break*/, 41];
3798
- case 41:
3853
+ return [3 /*break*/, 45];
3854
+ case 45:
3799
3855
  crossCollectionCandidates_1_1 = crossCollectionCandidates_1.next();
3800
- return [3 /*break*/, 37];
3801
- case 42: return [3 /*break*/, 45];
3802
- case 43:
3803
- e_1_1 = _s.sent();
3856
+ return [3 /*break*/, 41];
3857
+ case 46: return [3 /*break*/, 49];
3858
+ case 47:
3859
+ e_1_1 = _t.sent();
3804
3860
  e_1 = { error: e_1_1 };
3805
- return [3 /*break*/, 45];
3806
- case 44:
3861
+ return [3 /*break*/, 49];
3862
+ case 48:
3807
3863
  try {
3808
- if (crossCollectionCandidates_1_1 && !crossCollectionCandidates_1_1.done && (_p = crossCollectionCandidates_1.return)) _p.call(crossCollectionCandidates_1);
3864
+ if (crossCollectionCandidates_1_1 && !crossCollectionCandidates_1_1.done && (_q = crossCollectionCandidates_1.return)) _q.call(crossCollectionCandidates_1);
3809
3865
  }
3810
3866
  finally { if (e_1) throw e_1.error; }
3811
3867
  return [7 /*endfinally*/];
3812
- case 45: return [3 /*break*/, 47];
3813
- case 46:
3868
+ case 49: return [3 /*break*/, 51];
3869
+ case 50:
3814
3870
  if (!documents.length && crossCollectionRetryEnabled && hasActiveStatusFilters && canViewDebug) {
3815
3871
  fallbackMeta.collectionRetry = {
3816
3872
  from: collection,
@@ -3820,9 +3876,9 @@ function executeAiAssistantMongoRead(payload, context) {
3820
3876
  reason: 'active_status_query_preserved'
3821
3877
  };
3822
3878
  }
3823
- _s.label = 47;
3824
- case 47:
3825
- if (!(!documents.length && canViewDebug && hasReadRuntimeBudget('zero_diagnostics', 20))) return [3 /*break*/, 64];
3879
+ _t.label = 51;
3880
+ case 51:
3881
+ if (!(!documents.length && canViewDebug && hasReadRuntimeBudget('zero_diagnostics', 20))) return [3 /*break*/, 68];
3826
3882
  nameFields = collectMatchFieldsByCondition(executedQuery, function (field, condition) { return isRegexMatchCondition(condition)
3827
3883
  || (typeof condition === 'string' && shouldApplyAssistantNameRegex(field)); });
3828
3884
  dateFields = collectMatchFieldsByCondition(executedQuery, function (_field, condition) { return isDateCondition(condition); });
@@ -3830,33 +3886,33 @@ function executeAiAssistantMongoRead(payload, context) {
3830
3886
  nameFields: nameFields.length ? nameFields : undefined,
3831
3887
  dateFields: dateFields.length ? dateFields : undefined
3832
3888
  };
3833
- _s.label = 48;
3834
- case 48:
3835
- _s.trys.push([48, 53, , 54]);
3889
+ _t.label = 52;
3890
+ case 52:
3891
+ _t.trys.push([52, 57, , 58]);
3836
3892
  countOptions = buildCountOptions();
3837
- if (!nameFields.length) return [3 /*break*/, 50];
3893
+ if (!nameFields.length) return [3 /*break*/, 54];
3838
3894
  queryNoName = stripMatchFields(executedQuery, nameFields);
3839
- _g = diagnostics;
3840
- return [4 /*yield*/, db.collection(collection).countDocuments(queryNoName, countOptions)];
3841
- case 49:
3842
- _g.recentCount = _s.sent();
3843
- _s.label = 50;
3844
- case 50:
3845
- if (!dateFields.length) return [3 /*break*/, 52];
3846
- queryNoDate = stripMatchFields(executedQuery, dateFields);
3847
3895
  _h = diagnostics;
3848
- return [4 /*yield*/, db.collection(collection).countDocuments(queryNoDate, countOptions)];
3849
- case 51:
3850
- _h.nameMatchCount = _s.sent();
3851
- _s.label = 52;
3852
- case 52: return [3 /*break*/, 54];
3896
+ return [4 /*yield*/, db.collection(collection).countDocuments(queryNoName, countOptions)];
3853
3897
  case 53:
3854
- _j = _s.sent();
3855
- return [3 /*break*/, 54];
3898
+ _h.recentCount = _t.sent();
3899
+ _t.label = 54;
3856
3900
  case 54:
3857
- _s.trys.push([54, 57, , 58]);
3858
- _k = probeDocs;
3859
- if (_k) return [3 /*break*/, 56];
3901
+ if (!dateFields.length) return [3 /*break*/, 56];
3902
+ queryNoDate = stripMatchFields(executedQuery, dateFields);
3903
+ _j = diagnostics;
3904
+ return [4 /*yield*/, db.collection(collection).countDocuments(queryNoDate, countOptions)];
3905
+ case 55:
3906
+ _j.nameMatchCount = _t.sent();
3907
+ _t.label = 56;
3908
+ case 56: return [3 /*break*/, 58];
3909
+ case 57:
3910
+ _k = _t.sent();
3911
+ return [3 /*break*/, 58];
3912
+ case 58:
3913
+ _t.trys.push([58, 61, , 62]);
3914
+ _l = probeDocs;
3915
+ if (_l) return [3 /*break*/, 60];
3860
3916
  return [4 /*yield*/, fetchAssistantProbeDocs({
3861
3917
  db: db,
3862
3918
  collection: collection,
@@ -3866,56 +3922,56 @@ function executeAiAssistantMongoRead(payload, context) {
3866
3922
  includeClientScope: shouldScopeByClient,
3867
3923
  maxTimeMS: resolveReadMaxTimeMS()
3868
3924
  })];
3869
- case 55:
3870
- _k = (_s.sent());
3871
- _s.label = 56;
3872
- case 56:
3873
- probeDocs = _k;
3925
+ case 59:
3926
+ _l = (_t.sent());
3927
+ _t.label = 60;
3928
+ case 60:
3929
+ probeDocs = _l;
3874
3930
  if (probeDocs.length && nameFields.length) {
3875
3931
  diagnostics.chemicalIdDetected = detectChemicalIdFromProbe(probeDocs, nameFields);
3876
3932
  }
3877
- return [3 /*break*/, 58];
3878
- case 57:
3879
- _l = _s.sent();
3880
- return [3 /*break*/, 58];
3881
- case 58:
3882
- _s.trys.push([58, 62, , 63]);
3933
+ return [3 /*break*/, 62];
3934
+ case 61:
3935
+ _m = _t.sent();
3936
+ return [3 /*break*/, 62];
3937
+ case 62:
3938
+ _t.trys.push([62, 66, , 67]);
3883
3939
  return [4 /*yield*/, listAssistantCollections(db, dbName)];
3884
- case 59:
3885
- allCollections = _s.sent();
3940
+ case 63:
3941
+ allCollections = _t.sent();
3886
3942
  base = stripVersionSuffix(collection.startsWith('report-') ? collection.slice('report-'.length) : collection);
3887
3943
  alt = collection.startsWith('report-') ? base : "report-".concat(base);
3888
- if (!(alt && alt !== collection && allCollections.includes(alt))) return [3 /*break*/, 61];
3944
+ if (!(alt && alt !== collection && allCollections.includes(alt))) return [3 /*break*/, 65];
3889
3945
  return [4 /*yield*/, db.collection(alt).countDocuments({}, buildCountOptions())];
3890
- case 60:
3891
- altCount = _s.sent();
3946
+ case 64:
3947
+ altCount = _t.sent();
3892
3948
  diagnostics.alternateCollection = alt;
3893
3949
  diagnostics.alternateCollectionCount = altCount;
3894
- _s.label = 61;
3895
- case 61: return [3 /*break*/, 63];
3896
- case 62:
3897
- _m = _s.sent();
3898
- return [3 /*break*/, 63];
3899
- case 63:
3950
+ _t.label = 65;
3951
+ case 65: return [3 /*break*/, 67];
3952
+ case 66:
3953
+ _o = _t.sent();
3954
+ return [3 /*break*/, 67];
3955
+ case 67:
3900
3956
  fallbackMeta.zeroDiagnostics = diagnostics;
3901
- _s.label = 64;
3902
- case 64:
3957
+ _t.label = 68;
3958
+ case 68:
3903
3959
  total = null;
3904
- if (!(normalized.includeTotal && hasReadRuntimeBudget('total_count', 20))) return [3 /*break*/, 66];
3960
+ if (!(normalized.includeTotal && hasReadRuntimeBudget('total_count', 20))) return [3 /*break*/, 70];
3905
3961
  return [4 /*yield*/, db.collection(collection).countDocuments(executedQuery, buildCountOptions())];
3906
- case 65:
3907
- total = _s.sent();
3908
- _s.label = 66;
3909
- case 66:
3962
+ case 69:
3963
+ total = _t.sent();
3964
+ _t.label = 70;
3965
+ case 70:
3910
3966
  sanitizedDocuments = isSuperAdmin
3911
3967
  ? documents
3912
3968
  : documents.map(function (doc) { return redactSensitiveFields((0, common_1.deepCopy)(doc)); });
3913
3969
  requestedFields = resolveProjectionRequestedFields(findOptions.projection);
3914
- if (!(sanitizedDocuments.length && requestedFields.length)) return [3 /*break*/, 70];
3970
+ if (!(sanitizedDocuments.length && requestedFields.length)) return [3 /*break*/, 74];
3915
3971
  missingFields = requestedFields.filter(function (field) { return !hasNonEmptyValue(sanitizedDocuments, field, { treatObjectLikeAsEmpty: true }); });
3916
- if (!missingFields.length) return [3 /*break*/, 70];
3917
- _o = probeDocs;
3918
- if (_o) return [3 /*break*/, 68];
3972
+ if (!missingFields.length) return [3 /*break*/, 74];
3973
+ _p = probeDocs;
3974
+ if (_p) return [3 /*break*/, 72];
3919
3975
  return [4 /*yield*/, fetchAssistantProbeDocs({
3920
3976
  db: db,
3921
3977
  collection: collection,
@@ -3925,26 +3981,26 @@ function executeAiAssistantMongoRead(payload, context) {
3925
3981
  includeClientScope: shouldScopeByClient,
3926
3982
  maxTimeMS: resolveReadMaxTimeMS()
3927
3983
  })];
3928
- case 67:
3929
- _o = (_s.sent());
3930
- _s.label = 68;
3931
- case 68:
3932
- probeDocs = _o;
3933
- if (!probeDocs.length) return [3 /*break*/, 70];
3984
+ case 71:
3985
+ _p = (_t.sent());
3986
+ _t.label = 72;
3987
+ case 72:
3988
+ probeDocs = _p;
3989
+ if (!probeDocs.length) return [3 /*break*/, 74];
3934
3990
  projectionAliases = resolveFieldAliases(probeDocs, missingFields, schemaFields);
3935
- if (!Object.keys(projectionAliases).length) return [3 /*break*/, 70];
3991
+ if (!Object.keys(projectionAliases).length) return [3 /*break*/, 74];
3936
3992
  fallbackMeta.projectionAliases = {
3937
3993
  aliases: projectionAliases,
3938
3994
  attempted: true,
3939
3995
  used: false
3940
3996
  };
3941
3997
  expandedProjection = expandProjectionWithAliases(findOptions.projection, projectionAliases);
3942
- if (!(expandedProjection && expandedProjection !== findOptions.projection)) return [3 /*break*/, 70];
3998
+ if (!(expandedProjection && expandedProjection !== findOptions.projection)) return [3 /*break*/, 74];
3943
3999
  findOptions = __assign(__assign({}, findOptions), { projection: expandedProjection });
3944
4000
  normalized.findOptions.projection = expandedProjection;
3945
4001
  return [4 /*yield*/, db.collection(collection).find(executedQuery, buildFindOptions()).toArray()];
3946
- case 69:
3947
- refreshedDocs = _s.sent();
4002
+ case 73:
4003
+ refreshedDocs = _t.sent();
3948
4004
  if (refreshedDocs.length) {
3949
4005
  documents = refreshedDocs;
3950
4006
  sanitizedDocuments = isSuperAdmin
@@ -3952,9 +4008,9 @@ function executeAiAssistantMongoRead(payload, context) {
3952
4008
  : refreshedDocs.map(function (doc) { return redactSensitiveFields((0, common_1.deepCopy)(doc)); });
3953
4009
  fallbackMeta.projectionAliases.used = true;
3954
4010
  }
3955
- _s.label = 70;
3956
- case 70:
3957
- includeIds = ((_r = input.options) === null || _r === void 0 ? void 0 : _r.includeIds) === true;
4011
+ _t.label = 74;
4012
+ case 74:
4013
+ includeIds = ((_s = input.options) === null || _s === void 0 ? void 0 : _s.includeIds) === true;
3958
4014
  fieldAliases = resolveFieldAliases(sanitizedDocuments, requestedFields, schemaFields);
3959
4015
  displayDocs = Object.keys(fieldAliases).length
3960
4016
  ? applyFieldAliasesForDisplay(sanitizedDocuments, fieldAliases)
@@ -3968,8 +4024,8 @@ function executeAiAssistantMongoRead(payload, context) {
3968
4024
  idCustomer: customerId,
3969
4025
  isSuperAdmin: isSuperAdmin
3970
4026
  })];
3971
- case 71:
3972
- idLookupDisplay = _s.sent();
4027
+ case 75:
4028
+ idLookupDisplay = _t.sent();
3973
4029
  if (idLookupDisplay === null || idLookupDisplay === void 0 ? void 0 : idLookupDisplay.docs) {
3974
4030
  displayDocs = idLookupDisplay.docs;
3975
4031
  }
@@ -15521,6 +15577,171 @@ function resolveReadNameMatchFallback(query) {
15521
15577
  fields: fields
15522
15578
  };
15523
15579
  }
15580
+ function collectRegexFieldConditions(match, prefix) {
15581
+ if (prefix === void 0) { prefix = ''; }
15582
+ var results = [];
15583
+ var visit = function (value, currentPrefix) {
15584
+ if (Array.isArray(value)) {
15585
+ value.forEach(function (entry) { return visit(entry, currentPrefix); });
15586
+ return;
15587
+ }
15588
+ if (!value || typeof value !== 'object') {
15589
+ return;
15590
+ }
15591
+ Object.keys(value).forEach(function (key) {
15592
+ var entry = value[key];
15593
+ if (key.startsWith('$')) {
15594
+ visit(entry, currentPrefix);
15595
+ return;
15596
+ }
15597
+ var currentPath = currentPrefix ? "".concat(currentPrefix, ".").concat(key) : key;
15598
+ if (isRegexMatchCondition(entry)) {
15599
+ results.push({
15600
+ field: currentPath,
15601
+ condition: entry
15602
+ });
15603
+ }
15604
+ if (entry && typeof entry === 'object') {
15605
+ visit(entry, currentPath);
15606
+ }
15607
+ });
15608
+ };
15609
+ visit(match, prefix);
15610
+ return results;
15611
+ }
15612
+ function isAssistantJobLikeFieldPath(field) {
15613
+ var normalized = normalizeLookupPath(field) || normalizeOptionalString(field);
15614
+ if (!normalized || isAssistantIdField(normalized)) {
15615
+ return false;
15616
+ }
15617
+ var tokens = tokenizeFieldKey(normalized);
15618
+ if (tokens.some(function (token) { return AI_ASSISTANT_JOB_LIKE_FIELD_TOKENS.has(token); })) {
15619
+ return true;
15620
+ }
15621
+ var leaf = normalized.split('.').pop() || normalized;
15622
+ var leafLower = leaf.toLowerCase();
15623
+ return leafLower.startsWith('job_') || leafLower.includes('jobnumber');
15624
+ }
15625
+ function extractRegexConditionTokens(condition) {
15626
+ var regex = buildRegexFromCondition(condition);
15627
+ if (!regex) {
15628
+ return [];
15629
+ }
15630
+ var source = normalizeOptionalString(regex.source).toLowerCase();
15631
+ if (!source) {
15632
+ return [];
15633
+ }
15634
+ var rawTokens = source
15635
+ .replace(/\\u[0-9a-f]{4}/gi, ' ')
15636
+ .replace(/\\x[0-9a-f]{2}/gi, ' ')
15637
+ .replace(/\\./g, ' ')
15638
+ .split(/[^a-z0-9]+/g)
15639
+ .map(function (token) { return token.trim(); })
15640
+ .filter(Boolean)
15641
+ .filter(function (token) {
15642
+ if (/^\d+$/.test(token)) {
15643
+ return true;
15644
+ }
15645
+ if (token.length < 2) {
15646
+ return false;
15647
+ }
15648
+ return !AI_ASSISTANT_COLLECTION_STOPWORDS.has(token);
15649
+ });
15650
+ return Array.from(new Set(rawTokens)).slice(0, AI_ASSISTANT_MULTI_TERM_NAME_FALLBACK_MAX_TERMS);
15651
+ }
15652
+ function resolveReadMultiTermRegexFallbackFields(sourceFields, probeDocs, schemaFields) {
15653
+ var normalizedSchemaFields = new Set((Array.isArray(schemaFields) ? schemaFields : [])
15654
+ .map(function (field) { return normalizeLookupPath(field) || normalizeOptionalString(field); })
15655
+ .filter(Boolean));
15656
+ var candidates = [];
15657
+ var seen = new Set();
15658
+ var addCandidate = function (value) {
15659
+ var normalized = normalizeLookupPath(value) || normalizeOptionalString(value);
15660
+ if (!normalized || seen.has(normalized) || isAssistantIdField(normalized)) {
15661
+ return;
15662
+ }
15663
+ seen.add(normalized);
15664
+ candidates.push(normalized);
15665
+ };
15666
+ sourceFields.forEach(function (field) {
15667
+ addCandidate(field);
15668
+ expandNameFieldCandidates(field).forEach(addCandidate);
15669
+ });
15670
+ AI_ASSISTANT_JOB_TEXT_FALLBACK_FIELDS.forEach(addCandidate);
15671
+ var withProbeData = candidates.filter(function (field) { return hasNonEmptyValue(probeDocs || [], field, { treatObjectLikeAsEmpty: true }); });
15672
+ if (withProbeData.length) {
15673
+ return withProbeData.slice(0, AI_ASSISTANT_NAME_MATCH_FALLBACK_MAX_FIELDS);
15674
+ }
15675
+ var withSchema = candidates.filter(function (field) { return normalizedSchemaFields.has(field); });
15676
+ if (withSchema.length) {
15677
+ return withSchema.slice(0, AI_ASSISTANT_NAME_MATCH_FALLBACK_MAX_FIELDS);
15678
+ }
15679
+ return candidates.slice(0, AI_ASSISTANT_NAME_MATCH_FALLBACK_MAX_FIELDS);
15680
+ }
15681
+ function resolveReadMultiTermJobRegexFallback(query, probeDocs, schemaFields) {
15682
+ if (!query || typeof query !== 'object') {
15683
+ return null;
15684
+ }
15685
+ var regexConditions = collectRegexFieldConditions(query)
15686
+ .filter(function (entry) { return isAssistantJobLikeFieldPath(entry.field); });
15687
+ if (regexConditions.length < 2) {
15688
+ return null;
15689
+ }
15690
+ var sourceFields = Array.from(new Set(regexConditions
15691
+ .map(function (entry) { return normalizeLookupPath(entry.field) || normalizeOptionalString(entry.field); })
15692
+ .filter(Boolean)));
15693
+ if (!sourceFields.length) {
15694
+ return null;
15695
+ }
15696
+ var orderedTerms = [];
15697
+ var seenTerms = new Set();
15698
+ regexConditions.forEach(function (entry) {
15699
+ extractRegexConditionTokens(entry.condition).forEach(function (token) {
15700
+ if (!token || seenTerms.has(token)) {
15701
+ return;
15702
+ }
15703
+ seenTerms.add(token);
15704
+ orderedTerms.push(token);
15705
+ });
15706
+ });
15707
+ var terms = orderedTerms.slice(0, AI_ASSISTANT_MULTI_TERM_NAME_FALLBACK_MAX_TERMS);
15708
+ if (terms.length < 2) {
15709
+ return null;
15710
+ }
15711
+ var fields = resolveReadMultiTermRegexFallbackFields(sourceFields, probeDocs, schemaFields)
15712
+ .filter(function (field) { return !isAssistantIdField(field); });
15713
+ if (!fields.length) {
15714
+ return null;
15715
+ }
15716
+ var baseMatch = stripMatchFields(query, sourceFields);
15717
+ var termClauses = terms.map(function (token) { return ({
15718
+ $or: fields.map(function (field) {
15719
+ var _a;
15720
+ return (_a = {},
15721
+ _a[field] = {
15722
+ $regex: escapeRegexValue(token),
15723
+ $options: 'i'
15724
+ },
15725
+ _a);
15726
+ })
15727
+ }); });
15728
+ if (!termClauses.length) {
15729
+ return null;
15730
+ }
15731
+ var nextMatch = isEmptyMatchValue(baseMatch)
15732
+ ? (termClauses.length === 1 ? termClauses[0] : { $and: termClauses })
15733
+ : { $and: __spreadArray([baseMatch], __read(termClauses), false) };
15734
+ return {
15735
+ query: nextMatch,
15736
+ fields: fields,
15737
+ sourceFields: sourceFields,
15738
+ terms: terms
15739
+ };
15740
+ }
15741
+ function resolveReadMultiTermJobRegexFallbackForTesting(query, probeDocs, schemaFields) {
15742
+ if (probeDocs === void 0) { probeDocs = []; }
15743
+ return resolveReadMultiTermJobRegexFallback(query, probeDocs, schemaFields);
15744
+ }
15524
15745
  function isEmptyMatchValue(value) {
15525
15746
  if (value === null || value === undefined) {
15526
15747
  return true;
@@ -21037,6 +21258,9 @@ function resolveAssistantWorkspaceRoot() {
21037
21258
  var AI_ASSISTANT_DATA_REQUEST_PATTERNS = [
21038
21259
  /\bshow\b/,
21039
21260
  /\blist\b/,
21261
+ /\bsummarize\b/,
21262
+ /\bsummary\b/,
21263
+ /\bsnapshot\b/,
21040
21264
  /\bhow many\b/,
21041
21265
  /\bcount\b/,
21042
21266
  /\btotal\b/,