@resolveio/server-lib 22.2.31 → 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.
- package/collections/cron-job.collection.js +4 -0
- package/collections/cron-job.collection.js.map +1 -1
- package/managers/cron.manager.js +66 -50
- package/managers/cron.manager.js.map +1 -1
- package/methods/ai-terminal.d.ts +6 -0
- package/methods/ai-terminal.js +405 -181
- package/methods/ai-terminal.js.map +1 -1
- package/models/cron-job.model.d.ts +1 -0
- package/models/cron-job.model.js.map +1 -1
- package/package.json +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -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,
|
|
3293
|
-
var e_1,
|
|
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
|
|
3296
|
-
return __generator(this, function (
|
|
3297
|
-
switch (
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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((
|
|
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 =
|
|
3417
|
+
_b = _t.sent();
|
|
3399
3418
|
return [3 /*break*/, 6];
|
|
3400
3419
|
case 5:
|
|
3401
3420
|
_b = false;
|
|
3402
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
3550
|
+
_t.label = 13;
|
|
3532
3551
|
case 13:
|
|
3533
|
-
if (!!documents.length) return [3 /*break*/,
|
|
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 = (
|
|
3547
|
-
|
|
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
|
|
3560
|
-
chemicalLookup =
|
|
3561
|
-
if (!chemicalLookup) return [3 /*break*/,
|
|
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
|
|
3565
|
-
fallbackRead =
|
|
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
|
-
|
|
3573
|
-
case
|
|
3574
|
-
if (!!documents.length) return [3 /*break*/,
|
|
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*/,
|
|
3577
|
-
|
|
3578
|
-
if (
|
|
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
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
case
|
|
3592
|
-
probeDocs =
|
|
3593
|
-
if (!probeDocs.length) return [3 /*break*/,
|
|
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*/,
|
|
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
|
|
3608
|
-
fallbackRead =
|
|
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
|
-
|
|
3616
|
-
case
|
|
3617
|
-
if (!!documents.length) return [3 /*break*/,
|
|
3618
|
-
|
|
3619
|
-
if (
|
|
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
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
case
|
|
3633
|
-
probeDocs =
|
|
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*/,
|
|
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
|
|
3644
|
-
fallbackRead =
|
|
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
|
-
|
|
3652
|
-
case
|
|
3653
|
-
if (!!documents.length) return [3 /*break*/,
|
|
3654
|
-
|
|
3655
|
-
if (
|
|
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
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
case
|
|
3669
|
-
probeDocs =
|
|
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
|
|
3680
|
-
idLookup =
|
|
3681
|
-
if (!idLookup) return [3 /*break*/,
|
|
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
|
|
3685
|
-
fallbackRead =
|
|
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
|
-
|
|
3693
|
-
case
|
|
3694
|
-
if (!(!documents.length && hasReadRuntimeBudget('report_fallback'))) return [3 /*break*/,
|
|
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
|
|
3697
|
-
baseCollection =
|
|
3698
|
-
if (!(baseCollection && baseCollection !== collection)) return [3 /*break*/,
|
|
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
|
|
3705
|
-
fallbackResult =
|
|
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
|
-
|
|
3723
|
-
case
|
|
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*/,
|
|
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
|
|
3730
|
-
crossCollectionCandidates =
|
|
3731
|
-
if (!crossCollectionCandidates.length) return [3 /*break*/,
|
|
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
|
-
|
|
3740
|
-
case
|
|
3741
|
-
|
|
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
|
-
|
|
3744
|
-
case
|
|
3745
|
-
if (!!crossCollectionCandidates_1_1.done) return [3 /*break*/,
|
|
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
|
-
|
|
3753
|
-
case
|
|
3754
|
-
|
|
3808
|
+
_t.label = 42;
|
|
3809
|
+
case 42:
|
|
3810
|
+
_t.trys.push([42, 44, , 45]);
|
|
3755
3811
|
return [4 /*yield*/, executeAiAssistantMongoRead(fallbackPayload, context)];
|
|
3756
|
-
case
|
|
3757
|
-
fallbackResult =
|
|
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*/,
|
|
3785
|
-
case
|
|
3786
|
-
error_5 =
|
|
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*/,
|
|
3798
|
-
case
|
|
3853
|
+
return [3 /*break*/, 45];
|
|
3854
|
+
case 45:
|
|
3799
3855
|
crossCollectionCandidates_1_1 = crossCollectionCandidates_1.next();
|
|
3800
|
-
return [3 /*break*/,
|
|
3801
|
-
case
|
|
3802
|
-
case
|
|
3803
|
-
e_1_1 =
|
|
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*/,
|
|
3806
|
-
case
|
|
3861
|
+
return [3 /*break*/, 49];
|
|
3862
|
+
case 48:
|
|
3807
3863
|
try {
|
|
3808
|
-
if (crossCollectionCandidates_1_1 && !crossCollectionCandidates_1_1.done && (
|
|
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
|
|
3813
|
-
case
|
|
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
|
-
|
|
3824
|
-
case
|
|
3825
|
-
if (!(!documents.length && canViewDebug && hasReadRuntimeBudget('zero_diagnostics', 20))) return [3 /*break*/,
|
|
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
|
-
|
|
3834
|
-
case
|
|
3835
|
-
|
|
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*/,
|
|
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(
|
|
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
|
-
|
|
3855
|
-
|
|
3898
|
+
_h.recentCount = _t.sent();
|
|
3899
|
+
_t.label = 54;
|
|
3856
3900
|
case 54:
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
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
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
case
|
|
3873
|
-
probeDocs =
|
|
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*/,
|
|
3878
|
-
case
|
|
3879
|
-
|
|
3880
|
-
return [3 /*break*/,
|
|
3881
|
-
case
|
|
3882
|
-
|
|
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
|
|
3885
|
-
allCollections =
|
|
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*/,
|
|
3944
|
+
if (!(alt && alt !== collection && allCollections.includes(alt))) return [3 /*break*/, 65];
|
|
3889
3945
|
return [4 /*yield*/, db.collection(alt).countDocuments({}, buildCountOptions())];
|
|
3890
|
-
case
|
|
3891
|
-
altCount =
|
|
3946
|
+
case 64:
|
|
3947
|
+
altCount = _t.sent();
|
|
3892
3948
|
diagnostics.alternateCollection = alt;
|
|
3893
3949
|
diagnostics.alternateCollectionCount = altCount;
|
|
3894
|
-
|
|
3895
|
-
case
|
|
3896
|
-
case
|
|
3897
|
-
|
|
3898
|
-
return [3 /*break*/,
|
|
3899
|
-
case
|
|
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
|
-
|
|
3902
|
-
case
|
|
3957
|
+
_t.label = 68;
|
|
3958
|
+
case 68:
|
|
3903
3959
|
total = null;
|
|
3904
|
-
if (!(normalized.includeTotal && hasReadRuntimeBudget('total_count', 20))) return [3 /*break*/,
|
|
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
|
|
3907
|
-
total =
|
|
3908
|
-
|
|
3909
|
-
case
|
|
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*/,
|
|
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*/,
|
|
3917
|
-
|
|
3918
|
-
if (
|
|
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
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
case
|
|
3932
|
-
probeDocs =
|
|
3933
|
-
if (!probeDocs.length) return [3 /*break*/,
|
|
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*/,
|
|
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*/,
|
|
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
|
|
3947
|
-
refreshedDocs =
|
|
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
|
-
|
|
3956
|
-
case
|
|
3957
|
-
includeIds = ((
|
|
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
|
|
3972
|
-
idLookupDisplay =
|
|
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/,
|