@resolveio/server-lib 22.1.13 → 22.1.14
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/methods/ai-terminal.js +1001 -361
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -1695,7 +1695,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1695
1695
|
insertResult = _e.sent();
|
|
1696
1696
|
assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
|
|
1697
1697
|
enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1698
|
-
var runStart, steps, recordStep, progressTracker, streamProgress, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, termHints, collectionHints, fieldHints, methodHints, publicationHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerEnabled, plannerUsed, plannerSkipReason, plannerOutput, plannerRaw, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, surfaceHints, _a, allowedRoutes, rankedAllowedRoutes, routeHints, rankedCollectionHints, rankedCollections, hintCollections, assistantContext, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, cleanedResponseText, effectiveDirective, toolRequest, toolStart, toolResponse, _h, toolPayload, skipFollowupCodex, followupPrompt, followupStart, followupText, _j, error_3, error_4, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload;
|
|
1698
|
+
var runStart, steps, recordStep, progressTracker, streamProgress, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, termHints, collectionHints, fieldHints, methodHints, publicationHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerEnabled, plannerUsed, plannerSkipReason, plannerOutput, plannerRaw, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, surfaceHints, _a, allowedRoutes, rankedAllowedRoutes, routeHints, rankedCollectionHints, rankedCollections, hintCollections, assistantContext, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, effectiveDirective, toolRequest, toolStart, toolResponse, _h, toolPayload, skipFollowupCodex, followupPrompt, followupStart, followupText, _j, error_3, error_4, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload;
|
|
1699
1699
|
var _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
|
|
1700
1700
|
return __generator(this, function (_13) {
|
|
1701
1701
|
switch (_13.label) {
|
|
@@ -1882,7 +1882,9 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
1882
1882
|
publicationHints: publicationHints,
|
|
1883
1883
|
recentToolError: recentToolError
|
|
1884
1884
|
});
|
|
1885
|
-
heuristicDirectivePrecomputed = dataQuestion
|
|
1885
|
+
heuristicDirectivePrecomputed = dataQuestion
|
|
1886
|
+
? buildAssistantHeuristicDirective(message, collectionHints, collectionNames)
|
|
1887
|
+
: null;
|
|
1886
1888
|
hasDeterministicHeuristicFastPath = dataQuestion
|
|
1887
1889
|
&& isAssistantExecutableDirective(heuristicDirectivePrecomputed)
|
|
1888
1890
|
&& isAssistantDeterministicHeuristicDirective(heuristicDirectivePrecomputed);
|
|
@@ -2004,7 +2006,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2004
2006
|
directiveText = '';
|
|
2005
2007
|
directive = null;
|
|
2006
2008
|
heuristicDirectiveFastPath = dataQuestion
|
|
2007
|
-
? (heuristicDirectivePrecomputed || buildAssistantHeuristicDirective(message, collectionHints))
|
|
2009
|
+
? (heuristicDirectivePrecomputed || buildAssistantHeuristicDirective(message, collectionHints, collectionNames))
|
|
2008
2010
|
: null;
|
|
2009
2011
|
if (dataQuestion
|
|
2010
2012
|
&& isAssistantExecutableDirective(heuristicDirectiveFastPath)
|
|
@@ -2256,7 +2258,7 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2256
2258
|
return [3 /*break*/, 37];
|
|
2257
2259
|
case 37:
|
|
2258
2260
|
if (!directive && dataQuestion) {
|
|
2259
|
-
heuristicDirective = buildAssistantHeuristicDirective(message, collectionHints);
|
|
2261
|
+
heuristicDirective = buildAssistantHeuristicDirective(message, collectionHints, collectionNames);
|
|
2260
2262
|
if (isAssistantExecutableDirective(heuristicDirective)) {
|
|
2261
2263
|
directive = heuristicDirective;
|
|
2262
2264
|
directiveSource = 'forced';
|
|
@@ -2272,13 +2274,16 @@ function executeAiAssistantCodexRun(payload, context) {
|
|
|
2272
2274
|
}
|
|
2273
2275
|
if (directive) {
|
|
2274
2276
|
requestedCollection = normalizeOptionalString((_11 = directive.payload) === null || _11 === void 0 ? void 0 : _11.collection);
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2277
|
+
allowCollectionOverride = !isAssistantDeterministicHeuristicDirective(directive);
|
|
2278
|
+
collectionOverride = allowCollectionOverride
|
|
2279
|
+
? resolveCollectionOverrideWithContext({
|
|
2280
|
+
message: message,
|
|
2281
|
+
collectionRanking: collectionRanking,
|
|
2282
|
+
requestedCollection: requestedCollection,
|
|
2283
|
+
permissionView: normalizeOptionalString((_12 = directive.payload) === null || _12 === void 0 ? void 0 : _12.permissionView) || contextRoute,
|
|
2284
|
+
collectionNames: collectionNames
|
|
2285
|
+
})
|
|
2286
|
+
: null;
|
|
2282
2287
|
if (collectionOverride) {
|
|
2283
2288
|
recordStep('Planning: collection override', {
|
|
2284
2289
|
from: collectionOverride.from || undefined,
|
|
@@ -2666,7 +2671,7 @@ function executeAiAssistantReportIssue(payload, context) {
|
|
|
2666
2671
|
}
|
|
2667
2672
|
function executeAiAssistantMongoRead(payload, context) {
|
|
2668
2673
|
return __awaiter(this, void 0, void 0, function () {
|
|
2669
|
-
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, 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, e_1_1, nameFields, dateFields, diagnostics, 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;
|
|
2674
|
+
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, 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, 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;
|
|
2670
2675
|
var e_1, _p;
|
|
2671
2676
|
var _this = this;
|
|
2672
2677
|
var _q, _r;
|
|
@@ -2768,7 +2773,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2768
2773
|
normalized = normalizeAssistantFindOptions(input.options);
|
|
2769
2774
|
findOptions = __assign(__assign({}, normalized.findOptions), { readPreference: AI_ASSISTANT_READ_PREFERENCE });
|
|
2770
2775
|
runFindWithRepair = function (query, stage) { return __awaiter(_this, void 0, void 0, function () {
|
|
2771
|
-
var docs,
|
|
2776
|
+
var docs, error_6, repaired, docs;
|
|
2772
2777
|
return __generator(this, function (_a) {
|
|
2773
2778
|
switch (_a.label) {
|
|
2774
2779
|
case 0:
|
|
@@ -2778,13 +2783,13 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2778
2783
|
docs = _a.sent();
|
|
2779
2784
|
return [2 /*return*/, { documents: docs, query: query }];
|
|
2780
2785
|
case 2:
|
|
2781
|
-
|
|
2782
|
-
if (!isAssistantDateArithmeticArgumentError(
|
|
2783
|
-
throw
|
|
2786
|
+
error_6 = _a.sent();
|
|
2787
|
+
if (!isAssistantDateArithmeticArgumentError(error_6)) {
|
|
2788
|
+
throw error_6;
|
|
2784
2789
|
}
|
|
2785
2790
|
repaired = repairAssistantDateArithmeticInQuery(query);
|
|
2786
2791
|
if (!repaired.changed || containsForbiddenMongoOperators(repaired.query)) {
|
|
2787
|
-
throw
|
|
2792
|
+
throw error_6;
|
|
2788
2793
|
}
|
|
2789
2794
|
return [4 /*yield*/, db.collection(collection).find(repaired.query, findOptions).toArray()];
|
|
2790
2795
|
case 3:
|
|
@@ -3052,13 +3057,13 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3052
3057
|
_s.label = 34;
|
|
3053
3058
|
case 34:
|
|
3054
3059
|
hasActiveStatusFilters = collectAssistantActiveMatchFields(executedQuery).length > 0;
|
|
3055
|
-
if (!(!documents.length && crossCollectionRetryEnabled && !hasActiveStatusFilters)) return [3 /*break*/,
|
|
3060
|
+
if (!(!documents.length && crossCollectionRetryEnabled && !hasActiveStatusFilters)) return [3 /*break*/, 46];
|
|
3056
3061
|
return [4 /*yield*/, resolveAssistantAvailableCrossCollectionFallbacks(db, dbName, collection, triedCollections, {
|
|
3057
3062
|
fieldHints: extractQueryFieldPaths(executedQuery || {})
|
|
3058
3063
|
})];
|
|
3059
3064
|
case 35:
|
|
3060
3065
|
crossCollectionCandidates = _s.sent();
|
|
3061
|
-
if (!crossCollectionCandidates.length) return [3 /*break*/,
|
|
3066
|
+
if (!crossCollectionCandidates.length) return [3 /*break*/, 45];
|
|
3062
3067
|
fallbackMeta.collectionRetry = {
|
|
3063
3068
|
from: collection,
|
|
3064
3069
|
root: retryRootCollection,
|
|
@@ -3068,19 +3073,22 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3068
3073
|
};
|
|
3069
3074
|
_s.label = 36;
|
|
3070
3075
|
case 36:
|
|
3071
|
-
_s.trys.push([36,
|
|
3076
|
+
_s.trys.push([36, 43, 44, 45]);
|
|
3072
3077
|
crossCollectionCandidates_1 = __values(crossCollectionCandidates), crossCollectionCandidates_1_1 = crossCollectionCandidates_1.next();
|
|
3073
3078
|
_s.label = 37;
|
|
3074
3079
|
case 37:
|
|
3075
|
-
if (!!crossCollectionCandidates_1_1.done) return [3 /*break*/,
|
|
3080
|
+
if (!!crossCollectionCandidates_1_1.done) return [3 /*break*/, 42];
|
|
3076
3081
|
candidateCollection = crossCollectionCandidates_1_1.value;
|
|
3077
3082
|
addAssistantCollectionToTriedSet(triedCollections, candidateCollection);
|
|
3078
3083
|
fallbackPayload = __assign(__assign({}, input), { collection: candidateCollection, __assistantRetryState: buildAssistantRetryState(retryState, triedCollections, {
|
|
3079
3084
|
rootCollection: retryRootCollection,
|
|
3080
3085
|
disableCrossCollectionRetry: true
|
|
3081
3086
|
}) });
|
|
3082
|
-
|
|
3087
|
+
_s.label = 38;
|
|
3083
3088
|
case 38:
|
|
3089
|
+
_s.trys.push([38, 40, , 41]);
|
|
3090
|
+
return [4 /*yield*/, executeAiAssistantMongoRead(fallbackPayload, context)];
|
|
3091
|
+
case 39:
|
|
3084
3092
|
fallbackResult = _s.sent();
|
|
3085
3093
|
fallbackDocs = Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) ? fallbackResult.documents : [];
|
|
3086
3094
|
if (fallbackDocs.length && shouldAcceptAssistantFallbackDocuments(fallbackDocs)) {
|
|
@@ -3108,23 +3116,36 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3108
3116
|
});
|
|
3109
3117
|
fallbackMeta.collectionRetry.rejectedQuality = rejectedQuality;
|
|
3110
3118
|
}
|
|
3111
|
-
|
|
3112
|
-
case
|
|
3119
|
+
return [3 /*break*/, 41];
|
|
3120
|
+
case 40:
|
|
3121
|
+
error_5 = _s.sent();
|
|
3122
|
+
if (fallbackMeta.collectionRetry && typeof fallbackMeta.collectionRetry === 'object') {
|
|
3123
|
+
existingErrors = Array.isArray(fallbackMeta.collectionRetry.errors)
|
|
3124
|
+
? fallbackMeta.collectionRetry.errors
|
|
3125
|
+
: [];
|
|
3126
|
+
existingErrors.push({
|
|
3127
|
+
collection: candidateCollection,
|
|
3128
|
+
error: normalizeOptionalString(error_5 === null || error_5 === void 0 ? void 0 : error_5.message) || 'Unknown error'
|
|
3129
|
+
});
|
|
3130
|
+
fallbackMeta.collectionRetry.errors = existingErrors;
|
|
3131
|
+
}
|
|
3132
|
+
return [3 /*break*/, 41];
|
|
3133
|
+
case 41:
|
|
3113
3134
|
crossCollectionCandidates_1_1 = crossCollectionCandidates_1.next();
|
|
3114
3135
|
return [3 /*break*/, 37];
|
|
3115
|
-
case
|
|
3116
|
-
case
|
|
3136
|
+
case 42: return [3 /*break*/, 45];
|
|
3137
|
+
case 43:
|
|
3117
3138
|
e_1_1 = _s.sent();
|
|
3118
3139
|
e_1 = { error: e_1_1 };
|
|
3119
|
-
return [3 /*break*/,
|
|
3120
|
-
case
|
|
3140
|
+
return [3 /*break*/, 45];
|
|
3141
|
+
case 44:
|
|
3121
3142
|
try {
|
|
3122
3143
|
if (crossCollectionCandidates_1_1 && !crossCollectionCandidates_1_1.done && (_p = crossCollectionCandidates_1.return)) _p.call(crossCollectionCandidates_1);
|
|
3123
3144
|
}
|
|
3124
3145
|
finally { if (e_1) throw e_1.error; }
|
|
3125
3146
|
return [7 /*endfinally*/];
|
|
3126
|
-
case
|
|
3127
|
-
case
|
|
3147
|
+
case 45: return [3 /*break*/, 47];
|
|
3148
|
+
case 46:
|
|
3128
3149
|
if (!documents.length && crossCollectionRetryEnabled && hasActiveStatusFilters && isSuperAdmin) {
|
|
3129
3150
|
fallbackMeta.collectionRetry = {
|
|
3130
3151
|
from: collection,
|
|
@@ -3134,9 +3155,9 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3134
3155
|
reason: 'active_status_query_preserved'
|
|
3135
3156
|
};
|
|
3136
3157
|
}
|
|
3137
|
-
_s.label =
|
|
3138
|
-
case
|
|
3139
|
-
if (!(!documents.length && isSuperAdmin)) return [3 /*break*/,
|
|
3158
|
+
_s.label = 47;
|
|
3159
|
+
case 47:
|
|
3160
|
+
if (!(!documents.length && isSuperAdmin)) return [3 /*break*/, 64];
|
|
3140
3161
|
nameFields = collectMatchFieldsByCondition(executedQuery, function (field, condition) { return isRegexMatchCondition(condition)
|
|
3141
3162
|
|| (typeof condition === 'string' && shouldApplyAssistantNameRegex(field)); });
|
|
3142
3163
|
dateFields = collectMatchFieldsByCondition(executedQuery, function (_field, condition) { return isDateCondition(condition); });
|
|
@@ -3144,36 +3165,36 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3144
3165
|
nameFields: nameFields.length ? nameFields : undefined,
|
|
3145
3166
|
dateFields: dateFields.length ? dateFields : undefined
|
|
3146
3167
|
};
|
|
3147
|
-
_s.label =
|
|
3148
|
-
case
|
|
3149
|
-
_s.trys.push([
|
|
3150
|
-
if (!nameFields.length) return [3 /*break*/,
|
|
3168
|
+
_s.label = 48;
|
|
3169
|
+
case 48:
|
|
3170
|
+
_s.trys.push([48, 53, , 54]);
|
|
3171
|
+
if (!nameFields.length) return [3 /*break*/, 50];
|
|
3151
3172
|
queryNoName = stripMatchFields(executedQuery, nameFields);
|
|
3152
3173
|
_g = diagnostics;
|
|
3153
3174
|
return [4 /*yield*/, db.collection(collection).countDocuments(queryNoName, {
|
|
3154
3175
|
readPreference: AI_ASSISTANT_READ_PREFERENCE
|
|
3155
3176
|
})];
|
|
3156
|
-
case
|
|
3177
|
+
case 49:
|
|
3157
3178
|
_g.recentCount = _s.sent();
|
|
3158
|
-
_s.label =
|
|
3159
|
-
case
|
|
3160
|
-
if (!dateFields.length) return [3 /*break*/,
|
|
3179
|
+
_s.label = 50;
|
|
3180
|
+
case 50:
|
|
3181
|
+
if (!dateFields.length) return [3 /*break*/, 52];
|
|
3161
3182
|
queryNoDate = stripMatchFields(executedQuery, dateFields);
|
|
3162
3183
|
_h = diagnostics;
|
|
3163
3184
|
return [4 /*yield*/, db.collection(collection).countDocuments(queryNoDate, {
|
|
3164
3185
|
readPreference: AI_ASSISTANT_READ_PREFERENCE
|
|
3165
3186
|
})];
|
|
3166
|
-
case 49:
|
|
3167
|
-
_h.nameMatchCount = _s.sent();
|
|
3168
|
-
_s.label = 50;
|
|
3169
|
-
case 50: return [3 /*break*/, 52];
|
|
3170
3187
|
case 51:
|
|
3188
|
+
_h.nameMatchCount = _s.sent();
|
|
3189
|
+
_s.label = 52;
|
|
3190
|
+
case 52: return [3 /*break*/, 54];
|
|
3191
|
+
case 53:
|
|
3171
3192
|
_j = _s.sent();
|
|
3172
|
-
return [3 /*break*/,
|
|
3173
|
-
case
|
|
3174
|
-
_s.trys.push([
|
|
3193
|
+
return [3 /*break*/, 54];
|
|
3194
|
+
case 54:
|
|
3195
|
+
_s.trys.push([54, 57, , 58]);
|
|
3175
3196
|
_k = probeDocs;
|
|
3176
|
-
if (_k) return [3 /*break*/,
|
|
3197
|
+
if (_k) return [3 /*break*/, 56];
|
|
3177
3198
|
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
3178
3199
|
db: db,
|
|
3179
3200
|
collection: collection,
|
|
@@ -3182,56 +3203,56 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3182
3203
|
isSuperAdmin: isSuperAdmin,
|
|
3183
3204
|
includeClientScope: shouldScopeByClient
|
|
3184
3205
|
})];
|
|
3185
|
-
case
|
|
3206
|
+
case 55:
|
|
3186
3207
|
_k = (_s.sent());
|
|
3187
|
-
_s.label =
|
|
3188
|
-
case
|
|
3208
|
+
_s.label = 56;
|
|
3209
|
+
case 56:
|
|
3189
3210
|
probeDocs = _k;
|
|
3190
3211
|
if (probeDocs.length && nameFields.length) {
|
|
3191
3212
|
diagnostics.chemicalIdDetected = detectChemicalIdFromProbe(probeDocs, nameFields);
|
|
3192
3213
|
}
|
|
3193
|
-
return [3 /*break*/,
|
|
3194
|
-
case
|
|
3214
|
+
return [3 /*break*/, 58];
|
|
3215
|
+
case 57:
|
|
3195
3216
|
_l = _s.sent();
|
|
3196
|
-
return [3 /*break*/,
|
|
3197
|
-
case
|
|
3198
|
-
_s.trys.push([
|
|
3217
|
+
return [3 /*break*/, 58];
|
|
3218
|
+
case 58:
|
|
3219
|
+
_s.trys.push([58, 62, , 63]);
|
|
3199
3220
|
return [4 /*yield*/, listAssistantCollections(db, dbName)];
|
|
3200
|
-
case
|
|
3221
|
+
case 59:
|
|
3201
3222
|
allCollections = _s.sent();
|
|
3202
3223
|
base = stripVersionSuffix(collection.startsWith('report-') ? collection.slice('report-'.length) : collection);
|
|
3203
3224
|
alt = collection.startsWith('report-') ? base : "report-".concat(base);
|
|
3204
|
-
if (!(alt && alt !== collection && allCollections.includes(alt))) return [3 /*break*/,
|
|
3225
|
+
if (!(alt && alt !== collection && allCollections.includes(alt))) return [3 /*break*/, 61];
|
|
3205
3226
|
return [4 /*yield*/, db.collection(alt).countDocuments({}, { readPreference: AI_ASSISTANT_READ_PREFERENCE })];
|
|
3206
|
-
case
|
|
3227
|
+
case 60:
|
|
3207
3228
|
altCount = _s.sent();
|
|
3208
3229
|
diagnostics.alternateCollection = alt;
|
|
3209
3230
|
diagnostics.alternateCollectionCount = altCount;
|
|
3210
|
-
_s.label =
|
|
3211
|
-
case
|
|
3212
|
-
case
|
|
3231
|
+
_s.label = 61;
|
|
3232
|
+
case 61: return [3 /*break*/, 63];
|
|
3233
|
+
case 62:
|
|
3213
3234
|
_m = _s.sent();
|
|
3214
|
-
return [3 /*break*/,
|
|
3215
|
-
case
|
|
3235
|
+
return [3 /*break*/, 63];
|
|
3236
|
+
case 63:
|
|
3216
3237
|
fallbackMeta.zeroDiagnostics = diagnostics;
|
|
3217
|
-
_s.label =
|
|
3218
|
-
case
|
|
3238
|
+
_s.label = 64;
|
|
3239
|
+
case 64:
|
|
3219
3240
|
total = null;
|
|
3220
|
-
if (!normalized.includeTotal) return [3 /*break*/,
|
|
3241
|
+
if (!normalized.includeTotal) return [3 /*break*/, 66];
|
|
3221
3242
|
return [4 /*yield*/, db.collection(collection).countDocuments(executedQuery, { readPreference: AI_ASSISTANT_READ_PREFERENCE })];
|
|
3222
|
-
case
|
|
3243
|
+
case 65:
|
|
3223
3244
|
total = _s.sent();
|
|
3224
|
-
_s.label =
|
|
3225
|
-
case
|
|
3245
|
+
_s.label = 66;
|
|
3246
|
+
case 66:
|
|
3226
3247
|
sanitizedDocuments = isSuperAdmin
|
|
3227
3248
|
? documents
|
|
3228
3249
|
: documents.map(function (doc) { return redactSensitiveFields((0, common_1.deepCopy)(doc)); });
|
|
3229
3250
|
requestedFields = resolveProjectionRequestedFields(findOptions.projection);
|
|
3230
|
-
if (!(sanitizedDocuments.length && requestedFields.length)) return [3 /*break*/,
|
|
3251
|
+
if (!(sanitizedDocuments.length && requestedFields.length)) return [3 /*break*/, 70];
|
|
3231
3252
|
missingFields = requestedFields.filter(function (field) { return !hasNonEmptyValue(sanitizedDocuments, field, { treatObjectLikeAsEmpty: true }); });
|
|
3232
|
-
if (!missingFields.length) return [3 /*break*/,
|
|
3253
|
+
if (!missingFields.length) return [3 /*break*/, 70];
|
|
3233
3254
|
_o = probeDocs;
|
|
3234
|
-
if (_o) return [3 /*break*/,
|
|
3255
|
+
if (_o) return [3 /*break*/, 68];
|
|
3235
3256
|
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
3236
3257
|
db: db,
|
|
3237
3258
|
collection: collection,
|
|
@@ -3240,25 +3261,25 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3240
3261
|
isSuperAdmin: isSuperAdmin,
|
|
3241
3262
|
includeClientScope: shouldScopeByClient
|
|
3242
3263
|
})];
|
|
3243
|
-
case
|
|
3264
|
+
case 67:
|
|
3244
3265
|
_o = (_s.sent());
|
|
3245
|
-
_s.label =
|
|
3246
|
-
case
|
|
3266
|
+
_s.label = 68;
|
|
3267
|
+
case 68:
|
|
3247
3268
|
probeDocs = _o;
|
|
3248
|
-
if (!probeDocs.length) return [3 /*break*/,
|
|
3269
|
+
if (!probeDocs.length) return [3 /*break*/, 70];
|
|
3249
3270
|
projectionAliases = resolveFieldAliases(probeDocs, missingFields, schemaFields);
|
|
3250
|
-
if (!Object.keys(projectionAliases).length) return [3 /*break*/,
|
|
3271
|
+
if (!Object.keys(projectionAliases).length) return [3 /*break*/, 70];
|
|
3251
3272
|
fallbackMeta.projectionAliases = {
|
|
3252
3273
|
aliases: projectionAliases,
|
|
3253
3274
|
attempted: true,
|
|
3254
3275
|
used: false
|
|
3255
3276
|
};
|
|
3256
3277
|
expandedProjection = expandProjectionWithAliases(findOptions.projection, projectionAliases);
|
|
3257
|
-
if (!(expandedProjection && expandedProjection !== findOptions.projection)) return [3 /*break*/,
|
|
3278
|
+
if (!(expandedProjection && expandedProjection !== findOptions.projection)) return [3 /*break*/, 70];
|
|
3258
3279
|
findOptions = __assign(__assign({}, findOptions), { projection: expandedProjection });
|
|
3259
3280
|
normalized.findOptions.projection = expandedProjection;
|
|
3260
3281
|
return [4 /*yield*/, db.collection(collection).find(executedQuery, findOptions).toArray()];
|
|
3261
|
-
case
|
|
3282
|
+
case 69:
|
|
3262
3283
|
refreshedDocs = _s.sent();
|
|
3263
3284
|
if (refreshedDocs.length) {
|
|
3264
3285
|
documents = refreshedDocs;
|
|
@@ -3267,8 +3288,8 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3267
3288
|
: refreshedDocs.map(function (doc) { return redactSensitiveFields((0, common_1.deepCopy)(doc)); });
|
|
3268
3289
|
fallbackMeta.projectionAliases.used = true;
|
|
3269
3290
|
}
|
|
3270
|
-
_s.label =
|
|
3271
|
-
case
|
|
3291
|
+
_s.label = 70;
|
|
3292
|
+
case 70:
|
|
3272
3293
|
includeIds = ((_r = input.options) === null || _r === void 0 ? void 0 : _r.includeIds) === true;
|
|
3273
3294
|
fieldAliases = resolveFieldAliases(sanitizedDocuments, requestedFields, schemaFields);
|
|
3274
3295
|
displayDocs = Object.keys(fieldAliases).length
|
|
@@ -3283,7 +3304,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3283
3304
|
idCustomer: customerId,
|
|
3284
3305
|
isSuperAdmin: isSuperAdmin
|
|
3285
3306
|
})];
|
|
3286
|
-
case
|
|
3307
|
+
case 71:
|
|
3287
3308
|
idLookupDisplay = _s.sent();
|
|
3288
3309
|
if (idLookupDisplay === null || idLookupDisplay === void 0 ? void 0 : idLookupDisplay.docs) {
|
|
3289
3310
|
displayDocs = idLookupDisplay.docs;
|
|
@@ -3329,7 +3350,7 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
3329
3350
|
}
|
|
3330
3351
|
function executeAiAssistantMongoAggregate(payload, context) {
|
|
3331
3352
|
return __awaiter(this, void 0, void 0, function () {
|
|
3332
|
-
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, executedPipeline, dateField, aggregateOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks,
|
|
3353
|
+
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, executedPipeline, dateField, aggregateOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks, error_7, errorMessage, existingErrors, e_2_1, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, fallbackAcceptanceOptions, crossCollectionCandidates, crossCollectionCandidates_2, crossCollectionCandidates_2_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, fallbackQuality, existingFallbacks, rejectedQuality, error_8, existingErrors, e_3_1, matchStages, diagnostics, combinedMatch, nameFields, dateFields, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, verification, sanitizedDocuments, includeIds, displayDocs, idLookupDisplay, display;
|
|
3333
3354
|
var e_2, _o, e_3, _p;
|
|
3334
3355
|
var _this = this;
|
|
3335
3356
|
var _q, _r;
|
|
@@ -3440,7 +3461,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3440
3461
|
}
|
|
3441
3462
|
aggregateOptions = __assign(__assign({}, normalizedOptions.aggregateOptions), { readPreference: AI_ASSISTANT_READ_PREFERENCE });
|
|
3442
3463
|
runAggregateWithRepair = function (pipeline, stage) { return __awaiter(_this, void 0, void 0, function () {
|
|
3443
|
-
var docs,
|
|
3464
|
+
var docs, error_9, isDateRepair, isRankSortByRepair, isDottedOutputFieldRepair, repaired, dottedFieldPath, dottedFieldReferenceRepairUsed, pathReferenceRepair, docs;
|
|
3444
3465
|
return __generator(this, function (_a) {
|
|
3445
3466
|
switch (_a.label) {
|
|
3446
3467
|
case 0:
|
|
@@ -3452,12 +3473,12 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3452
3473
|
docs = _a.sent();
|
|
3453
3474
|
return [2 /*return*/, { documents: docs, pipeline: pipeline }];
|
|
3454
3475
|
case 2:
|
|
3455
|
-
|
|
3456
|
-
isDateRepair = isAssistantDateArithmeticArgumentError(
|
|
3457
|
-
isRankSortByRepair = isAssistantRankSortByError(
|
|
3458
|
-
isDottedOutputFieldRepair = isAssistantDottedOutputFieldError(
|
|
3476
|
+
error_9 = _a.sent();
|
|
3477
|
+
isDateRepair = isAssistantDateArithmeticArgumentError(error_9);
|
|
3478
|
+
isRankSortByRepair = isAssistantRankSortByError(error_9);
|
|
3479
|
+
isDottedOutputFieldRepair = isAssistantDottedOutputFieldError(error_9);
|
|
3459
3480
|
if (!isDateRepair && !isRankSortByRepair && !isDottedOutputFieldRepair) {
|
|
3460
|
-
throw
|
|
3481
|
+
throw error_9;
|
|
3461
3482
|
}
|
|
3462
3483
|
repaired = isDateRepair
|
|
3463
3484
|
? repairAssistantDateArithmeticInPipeline(pipeline)
|
|
@@ -3467,7 +3488,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3467
3488
|
dottedFieldPath = null;
|
|
3468
3489
|
dottedFieldReferenceRepairUsed = false;
|
|
3469
3490
|
if (isDottedOutputFieldRepair) {
|
|
3470
|
-
dottedFieldPath = extractAssistantDottedFieldPathFromError(
|
|
3491
|
+
dottedFieldPath = extractAssistantDottedFieldPathFromError(error_9);
|
|
3471
3492
|
if (dottedFieldPath) {
|
|
3472
3493
|
pathReferenceRepair = repairAssistantFieldPathReferenceInPipeline(repaired.pipeline, dottedFieldPath);
|
|
3473
3494
|
if (pathReferenceRepair.changed) {
|
|
@@ -3480,7 +3501,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3480
3501
|
}
|
|
3481
3502
|
}
|
|
3482
3503
|
if (!repaired.changed || containsForbiddenMongoOperators(repaired.pipeline)) {
|
|
3483
|
-
throw
|
|
3504
|
+
throw error_9;
|
|
3484
3505
|
}
|
|
3485
3506
|
return [4 /*yield*/, db.collection(collection)
|
|
3486
3507
|
.aggregate(repaired.pipeline, aggregateOptions)
|
|
@@ -3948,8 +3969,8 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3948
3969
|
}
|
|
3949
3970
|
return [3 /*break*/, 49];
|
|
3950
3971
|
case 48:
|
|
3951
|
-
|
|
3952
|
-
errorMessage = normalizeOptionalString(
|
|
3972
|
+
error_7 = _s.sent();
|
|
3973
|
+
errorMessage = normalizeOptionalString(error_7 === null || error_7 === void 0 ? void 0 : error_7.message) || 'Unknown error';
|
|
3953
3974
|
existingErrors = Array.isArray(fallbackMeta.relationshipRetry.errors)
|
|
3954
3975
|
? fallbackMeta.relationshipRetry.errors
|
|
3955
3976
|
: [];
|
|
@@ -4004,14 +4025,14 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4004
4025
|
}
|
|
4005
4026
|
_s.label = 56;
|
|
4006
4027
|
case 56:
|
|
4007
|
-
if (!(!documents.length && crossCollectionRetryEnabled)) return [3 /*break*/,
|
|
4028
|
+
if (!(!documents.length && crossCollectionRetryEnabled)) return [3 /*break*/, 67];
|
|
4008
4029
|
fallbackAcceptanceOptions = buildAssistantAggregateFallbackAcceptanceOptions(executedPipeline || []);
|
|
4009
4030
|
return [4 /*yield*/, resolveAssistantAvailableCrossCollectionFallbacks(db, dbName, collection, triedCollections, {
|
|
4010
4031
|
fieldHints: collectAggregateReferencedFieldPaths(executedPipeline || [])
|
|
4011
4032
|
})];
|
|
4012
4033
|
case 57:
|
|
4013
4034
|
crossCollectionCandidates = _s.sent();
|
|
4014
|
-
if (!crossCollectionCandidates.length) return [3 /*break*/,
|
|
4035
|
+
if (!crossCollectionCandidates.length) return [3 /*break*/, 67];
|
|
4015
4036
|
fallbackMeta.collectionRetry = {
|
|
4016
4037
|
from: collection,
|
|
4017
4038
|
root: retryRootCollection,
|
|
@@ -4021,19 +4042,22 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4021
4042
|
};
|
|
4022
4043
|
_s.label = 58;
|
|
4023
4044
|
case 58:
|
|
4024
|
-
_s.trys.push([58,
|
|
4045
|
+
_s.trys.push([58, 65, 66, 67]);
|
|
4025
4046
|
crossCollectionCandidates_2 = __values(crossCollectionCandidates), crossCollectionCandidates_2_1 = crossCollectionCandidates_2.next();
|
|
4026
4047
|
_s.label = 59;
|
|
4027
4048
|
case 59:
|
|
4028
|
-
if (!!crossCollectionCandidates_2_1.done) return [3 /*break*/,
|
|
4049
|
+
if (!!crossCollectionCandidates_2_1.done) return [3 /*break*/, 64];
|
|
4029
4050
|
candidateCollection = crossCollectionCandidates_2_1.value;
|
|
4030
4051
|
addAssistantCollectionToTriedSet(triedCollections, candidateCollection);
|
|
4031
4052
|
fallbackPayload = __assign(__assign({}, input), { collection: candidateCollection, __assistantRetryState: buildAssistantRetryState(retryState, triedCollections, {
|
|
4032
4053
|
rootCollection: retryRootCollection,
|
|
4033
4054
|
disableCrossCollectionRetry: true
|
|
4034
4055
|
}) });
|
|
4035
|
-
|
|
4056
|
+
_s.label = 60;
|
|
4036
4057
|
case 60:
|
|
4058
|
+
_s.trys.push([60, 62, , 63]);
|
|
4059
|
+
return [4 /*yield*/, executeAiAssistantMongoAggregate(fallbackPayload, context)];
|
|
4060
|
+
case 61:
|
|
4037
4061
|
fallbackResult = _s.sent();
|
|
4038
4062
|
fallbackDocs = Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) ? fallbackResult.documents : [];
|
|
4039
4063
|
fallbackQuality = evaluateAssistantFallbackDocumentsQuality(fallbackDocs, fallbackAcceptanceOptions);
|
|
@@ -4067,62 +4091,75 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4067
4091
|
});
|
|
4068
4092
|
fallbackMeta.collectionRetry.rejectedQuality = rejectedQuality;
|
|
4069
4093
|
}
|
|
4070
|
-
|
|
4071
|
-
case
|
|
4094
|
+
return [3 /*break*/, 63];
|
|
4095
|
+
case 62:
|
|
4096
|
+
error_8 = _s.sent();
|
|
4097
|
+
if (fallbackMeta.collectionRetry && typeof fallbackMeta.collectionRetry === 'object') {
|
|
4098
|
+
existingErrors = Array.isArray(fallbackMeta.collectionRetry.errors)
|
|
4099
|
+
? fallbackMeta.collectionRetry.errors
|
|
4100
|
+
: [];
|
|
4101
|
+
existingErrors.push({
|
|
4102
|
+
collection: candidateCollection,
|
|
4103
|
+
error: normalizeOptionalString(error_8 === null || error_8 === void 0 ? void 0 : error_8.message) || 'Unknown error'
|
|
4104
|
+
});
|
|
4105
|
+
fallbackMeta.collectionRetry.errors = existingErrors;
|
|
4106
|
+
}
|
|
4107
|
+
return [3 /*break*/, 63];
|
|
4108
|
+
case 63:
|
|
4072
4109
|
crossCollectionCandidates_2_1 = crossCollectionCandidates_2.next();
|
|
4073
4110
|
return [3 /*break*/, 59];
|
|
4074
|
-
case
|
|
4075
|
-
case
|
|
4111
|
+
case 64: return [3 /*break*/, 67];
|
|
4112
|
+
case 65:
|
|
4076
4113
|
e_3_1 = _s.sent();
|
|
4077
4114
|
e_3 = { error: e_3_1 };
|
|
4078
|
-
return [3 /*break*/,
|
|
4079
|
-
case
|
|
4115
|
+
return [3 /*break*/, 67];
|
|
4116
|
+
case 66:
|
|
4080
4117
|
try {
|
|
4081
4118
|
if (crossCollectionCandidates_2_1 && !crossCollectionCandidates_2_1.done && (_p = crossCollectionCandidates_2.return)) _p.call(crossCollectionCandidates_2);
|
|
4082
4119
|
}
|
|
4083
4120
|
finally { if (e_3) throw e_3.error; }
|
|
4084
4121
|
return [7 /*endfinally*/];
|
|
4085
|
-
case
|
|
4086
|
-
if (!(!documents.length && isSuperAdmin)) return [3 /*break*/,
|
|
4122
|
+
case 67:
|
|
4123
|
+
if (!(!documents.length && isSuperAdmin)) return [3 /*break*/, 84];
|
|
4087
4124
|
matchStages = (executedPipeline || []).filter(function (stage) { return stage && typeof stage === 'object' && stage.$match && typeof stage.$match === 'object'; });
|
|
4088
4125
|
diagnostics = {};
|
|
4089
|
-
if (!matchStages.length) return [3 /*break*/,
|
|
4126
|
+
if (!matchStages.length) return [3 /*break*/, 84];
|
|
4090
4127
|
combinedMatch = matchStages.reduce(function (acc, stage) { return ({ $and: __spreadArray(__spreadArray([], __read((acc.$and || [])), false), [stage.$match], false) }); }, { $and: [] });
|
|
4091
4128
|
nameFields = collectMatchFieldsByCondition(combinedMatch, function (field, condition) { return isRegexMatchCondition(condition)
|
|
4092
4129
|
|| (typeof condition === 'string' && shouldApplyAssistantNameRegex(field)); });
|
|
4093
4130
|
dateFields = collectMatchFieldsByCondition(combinedMatch, function (_field, condition) { return isDateCondition(condition); });
|
|
4094
4131
|
diagnostics.nameFields = nameFields.length ? nameFields : undefined;
|
|
4095
4132
|
diagnostics.dateFields = dateFields.length ? dateFields : undefined;
|
|
4096
|
-
_s.label =
|
|
4097
|
-
case
|
|
4098
|
-
_s.trys.push([
|
|
4099
|
-
if (!nameFields.length) return [3 /*break*/,
|
|
4133
|
+
_s.label = 68;
|
|
4134
|
+
case 68:
|
|
4135
|
+
_s.trys.push([68, 73, , 74]);
|
|
4136
|
+
if (!nameFields.length) return [3 /*break*/, 70];
|
|
4100
4137
|
queryNoName = stripMatchFields(combinedMatch, nameFields);
|
|
4101
4138
|
_g = diagnostics;
|
|
4102
4139
|
return [4 /*yield*/, db.collection(collection).countDocuments(queryNoName, {
|
|
4103
4140
|
readPreference: AI_ASSISTANT_READ_PREFERENCE
|
|
4104
4141
|
})];
|
|
4105
|
-
case
|
|
4142
|
+
case 69:
|
|
4106
4143
|
_g.recentCount = _s.sent();
|
|
4107
|
-
_s.label =
|
|
4108
|
-
case
|
|
4109
|
-
if (!dateFields.length) return [3 /*break*/,
|
|
4144
|
+
_s.label = 70;
|
|
4145
|
+
case 70:
|
|
4146
|
+
if (!dateFields.length) return [3 /*break*/, 72];
|
|
4110
4147
|
queryNoDate = stripMatchFields(combinedMatch, dateFields);
|
|
4111
4148
|
_h = diagnostics;
|
|
4112
4149
|
return [4 /*yield*/, db.collection(collection).countDocuments(queryNoDate, {
|
|
4113
4150
|
readPreference: AI_ASSISTANT_READ_PREFERENCE
|
|
4114
4151
|
})];
|
|
4115
|
-
case 69:
|
|
4116
|
-
_h.nameMatchCount = _s.sent();
|
|
4117
|
-
_s.label = 70;
|
|
4118
|
-
case 70: return [3 /*break*/, 72];
|
|
4119
4152
|
case 71:
|
|
4153
|
+
_h.nameMatchCount = _s.sent();
|
|
4154
|
+
_s.label = 72;
|
|
4155
|
+
case 72: return [3 /*break*/, 74];
|
|
4156
|
+
case 73:
|
|
4120
4157
|
_j = _s.sent();
|
|
4121
|
-
return [3 /*break*/,
|
|
4122
|
-
case
|
|
4123
|
-
_s.trys.push([
|
|
4158
|
+
return [3 /*break*/, 74];
|
|
4159
|
+
case 74:
|
|
4160
|
+
_s.trys.push([74, 77, , 78]);
|
|
4124
4161
|
_k = probeDocs;
|
|
4125
|
-
if (_k) return [3 /*break*/,
|
|
4162
|
+
if (_k) return [3 /*break*/, 76];
|
|
4126
4163
|
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
4127
4164
|
db: db,
|
|
4128
4165
|
collection: collection,
|
|
@@ -4131,47 +4168,47 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4131
4168
|
isSuperAdmin: isSuperAdmin,
|
|
4132
4169
|
includeClientScope: shouldScopeByClient
|
|
4133
4170
|
})];
|
|
4134
|
-
case
|
|
4171
|
+
case 75:
|
|
4135
4172
|
_k = (_s.sent());
|
|
4136
|
-
_s.label =
|
|
4137
|
-
case
|
|
4173
|
+
_s.label = 76;
|
|
4174
|
+
case 76:
|
|
4138
4175
|
probeDocs = _k;
|
|
4139
4176
|
if (probeDocs.length && nameFields.length) {
|
|
4140
4177
|
diagnostics.chemicalIdDetected = detectChemicalIdFromProbe(probeDocs, nameFields);
|
|
4141
4178
|
}
|
|
4142
|
-
return [3 /*break*/,
|
|
4143
|
-
case
|
|
4179
|
+
return [3 /*break*/, 78];
|
|
4180
|
+
case 77:
|
|
4144
4181
|
_l = _s.sent();
|
|
4145
|
-
return [3 /*break*/,
|
|
4146
|
-
case
|
|
4147
|
-
_s.trys.push([
|
|
4182
|
+
return [3 /*break*/, 78];
|
|
4183
|
+
case 78:
|
|
4184
|
+
_s.trys.push([78, 82, , 83]);
|
|
4148
4185
|
return [4 /*yield*/, listAssistantCollections(db, dbName)];
|
|
4149
|
-
case
|
|
4186
|
+
case 79:
|
|
4150
4187
|
allCollections = _s.sent();
|
|
4151
4188
|
base = stripVersionSuffix(collection.startsWith('report-') ? collection.slice('report-'.length) : collection);
|
|
4152
4189
|
alt = collection.startsWith('report-') ? base : "report-".concat(base);
|
|
4153
|
-
if (!(alt && alt !== collection && allCollections.includes(alt))) return [3 /*break*/,
|
|
4190
|
+
if (!(alt && alt !== collection && allCollections.includes(alt))) return [3 /*break*/, 81];
|
|
4154
4191
|
return [4 /*yield*/, db.collection(alt).countDocuments({}, { readPreference: AI_ASSISTANT_READ_PREFERENCE })];
|
|
4155
|
-
case
|
|
4192
|
+
case 80:
|
|
4156
4193
|
altCount = _s.sent();
|
|
4157
4194
|
diagnostics.alternateCollection = alt;
|
|
4158
4195
|
diagnostics.alternateCollectionCount = altCount;
|
|
4159
|
-
_s.label =
|
|
4160
|
-
case
|
|
4161
|
-
case
|
|
4196
|
+
_s.label = 81;
|
|
4197
|
+
case 81: return [3 /*break*/, 83];
|
|
4198
|
+
case 82:
|
|
4162
4199
|
_m = _s.sent();
|
|
4163
|
-
return [3 /*break*/,
|
|
4164
|
-
case
|
|
4200
|
+
return [3 /*break*/, 83];
|
|
4201
|
+
case 83:
|
|
4165
4202
|
fallbackMeta.zeroDiagnostics = diagnostics;
|
|
4166
|
-
_s.label =
|
|
4167
|
-
case
|
|
4203
|
+
_s.label = 84;
|
|
4204
|
+
case 84: return [4 /*yield*/, verifyAssistantAggregateReliability({
|
|
4168
4205
|
db: db,
|
|
4169
4206
|
collection: collection,
|
|
4170
4207
|
pipeline: executedPipeline,
|
|
4171
4208
|
documents: documents,
|
|
4172
4209
|
aggregateOptions: aggregateOptions
|
|
4173
4210
|
})];
|
|
4174
|
-
case
|
|
4211
|
+
case 85:
|
|
4175
4212
|
verification = _s.sent();
|
|
4176
4213
|
sanitizedDocuments = isSuperAdmin
|
|
4177
4214
|
? documents
|
|
@@ -4190,7 +4227,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
4190
4227
|
idCustomer: customerId,
|
|
4191
4228
|
isSuperAdmin: isSuperAdmin
|
|
4192
4229
|
})];
|
|
4193
|
-
case
|
|
4230
|
+
case 86:
|
|
4194
4231
|
idLookupDisplay = _s.sent();
|
|
4195
4232
|
if (idLookupDisplay === null || idLookupDisplay === void 0 ? void 0 : idLookupDisplay.docs) {
|
|
4196
4233
|
displayDocs = idLookupDisplay.docs;
|
|
@@ -5624,6 +5661,557 @@ function buildAssistantGenericHoursDirective(message, collectionHints) {
|
|
|
5624
5661
|
rawLine: 'HEURISTIC_AGG(schema-hours-user-time)'
|
|
5625
5662
|
};
|
|
5626
5663
|
}
|
|
5664
|
+
function parseAssistantNaturalNumber(value) {
|
|
5665
|
+
var normalized = normalizeOptionalString(value).toLowerCase();
|
|
5666
|
+
if (!normalized) {
|
|
5667
|
+
return null;
|
|
5668
|
+
}
|
|
5669
|
+
var numeric = Number(normalized);
|
|
5670
|
+
if (Number.isFinite(numeric) && numeric > 0) {
|
|
5671
|
+
return (0, common_1.round)(numeric);
|
|
5672
|
+
}
|
|
5673
|
+
var wordMap = {
|
|
5674
|
+
one: 1,
|
|
5675
|
+
two: 2,
|
|
5676
|
+
three: 3,
|
|
5677
|
+
four: 4,
|
|
5678
|
+
five: 5,
|
|
5679
|
+
six: 6,
|
|
5680
|
+
seven: 7,
|
|
5681
|
+
eight: 8,
|
|
5682
|
+
nine: 9,
|
|
5683
|
+
ten: 10,
|
|
5684
|
+
eleven: 11,
|
|
5685
|
+
twelve: 12,
|
|
5686
|
+
thirteen: 13,
|
|
5687
|
+
fourteen: 14,
|
|
5688
|
+
fifteen: 15,
|
|
5689
|
+
sixteen: 16,
|
|
5690
|
+
seventeen: 17,
|
|
5691
|
+
eighteen: 18,
|
|
5692
|
+
nineteen: 19,
|
|
5693
|
+
twenty: 20
|
|
5694
|
+
};
|
|
5695
|
+
return wordMap[normalized] || null;
|
|
5696
|
+
}
|
|
5697
|
+
function resolveAssistantNaturalNumberFromPattern(message, pattern, fallback, min, max) {
|
|
5698
|
+
var normalizedMessage = normalizeOptionalString(message).toLowerCase();
|
|
5699
|
+
if (!normalizedMessage) {
|
|
5700
|
+
return fallback;
|
|
5701
|
+
}
|
|
5702
|
+
var match = normalizedMessage.match(pattern);
|
|
5703
|
+
var parsed = parseAssistantNaturalNumber(String((match === null || match === void 0 ? void 0 : match[1]) || ''));
|
|
5704
|
+
if (!parsed) {
|
|
5705
|
+
return fallback;
|
|
5706
|
+
}
|
|
5707
|
+
return Math.min(Math.max(parsed, min), max);
|
|
5708
|
+
}
|
|
5709
|
+
function resolveAssistantHeuristicCollectionFromCandidates(collectionHints, candidates, collectionNames) {
|
|
5710
|
+
var e_5, _a, e_6, _b, e_7, _c;
|
|
5711
|
+
if (collectionNames === void 0) { collectionNames = []; }
|
|
5712
|
+
var hints = mergeAssistantHintValues(collectionHints || []);
|
|
5713
|
+
var preferred = mergeAssistantHintValues(candidates || []);
|
|
5714
|
+
var availableCollections = mergeAssistantHintValues(collectionNames || []);
|
|
5715
|
+
var reportBuilderCollections = mergeAssistantHintValues(listAssistantReportBuilderCollectionsFromManager());
|
|
5716
|
+
var effectiveAvailableCollections = reportBuilderCollections.length
|
|
5717
|
+
? reportBuilderCollections
|
|
5718
|
+
: availableCollections;
|
|
5719
|
+
var _loop_3 = function (candidate) {
|
|
5720
|
+
var candidateFamily = normalizeAssistantCollectionFamilyName(candidate);
|
|
5721
|
+
if (!candidateFamily) {
|
|
5722
|
+
return "continue";
|
|
5723
|
+
}
|
|
5724
|
+
var matchedCollection = effectiveAvailableCollections.find(function (name) { return normalizeAssistantCollectionFamilyName(name) === candidateFamily; });
|
|
5725
|
+
if (matchedCollection) {
|
|
5726
|
+
return { value: matchedCollection };
|
|
5727
|
+
}
|
|
5728
|
+
};
|
|
5729
|
+
try {
|
|
5730
|
+
for (var preferred_1 = __values(preferred), preferred_1_1 = preferred_1.next(); !preferred_1_1.done; preferred_1_1 = preferred_1.next()) {
|
|
5731
|
+
var candidate = preferred_1_1.value;
|
|
5732
|
+
var state_3 = _loop_3(candidate);
|
|
5733
|
+
if (typeof state_3 === "object")
|
|
5734
|
+
return state_3.value;
|
|
5735
|
+
}
|
|
5736
|
+
}
|
|
5737
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
5738
|
+
finally {
|
|
5739
|
+
try {
|
|
5740
|
+
if (preferred_1_1 && !preferred_1_1.done && (_a = preferred_1.return)) _a.call(preferred_1);
|
|
5741
|
+
}
|
|
5742
|
+
finally { if (e_5) throw e_5.error; }
|
|
5743
|
+
}
|
|
5744
|
+
var _loop_4 = function (candidate) {
|
|
5745
|
+
var candidateFamily = normalizeAssistantCollectionFamilyName(candidate);
|
|
5746
|
+
if (!candidateFamily) {
|
|
5747
|
+
return "continue";
|
|
5748
|
+
}
|
|
5749
|
+
var matchedCollection = availableCollections.find(function (name) { return normalizeAssistantCollectionFamilyName(name) === candidateFamily; });
|
|
5750
|
+
if (matchedCollection) {
|
|
5751
|
+
return { value: matchedCollection };
|
|
5752
|
+
}
|
|
5753
|
+
};
|
|
5754
|
+
try {
|
|
5755
|
+
for (var preferred_2 = __values(preferred), preferred_2_1 = preferred_2.next(); !preferred_2_1.done; preferred_2_1 = preferred_2.next()) {
|
|
5756
|
+
var candidate = preferred_2_1.value;
|
|
5757
|
+
var state_4 = _loop_4(candidate);
|
|
5758
|
+
if (typeof state_4 === "object")
|
|
5759
|
+
return state_4.value;
|
|
5760
|
+
}
|
|
5761
|
+
}
|
|
5762
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
5763
|
+
finally {
|
|
5764
|
+
try {
|
|
5765
|
+
if (preferred_2_1 && !preferred_2_1.done && (_b = preferred_2.return)) _b.call(preferred_2);
|
|
5766
|
+
}
|
|
5767
|
+
finally { if (e_6) throw e_6.error; }
|
|
5768
|
+
}
|
|
5769
|
+
var _loop_5 = function (candidate) {
|
|
5770
|
+
var candidateFamily = normalizeAssistantCollectionFamilyName(candidate);
|
|
5771
|
+
if (!candidateFamily) {
|
|
5772
|
+
return "continue";
|
|
5773
|
+
}
|
|
5774
|
+
var matchedHint = hints.find(function (hint) { return normalizeAssistantCollectionFamilyName(hint) === candidateFamily; });
|
|
5775
|
+
if (matchedHint) {
|
|
5776
|
+
return { value: matchedHint };
|
|
5777
|
+
}
|
|
5778
|
+
};
|
|
5779
|
+
try {
|
|
5780
|
+
for (var preferred_3 = __values(preferred), preferred_3_1 = preferred_3.next(); !preferred_3_1.done; preferred_3_1 = preferred_3.next()) {
|
|
5781
|
+
var candidate = preferred_3_1.value;
|
|
5782
|
+
var state_5 = _loop_5(candidate);
|
|
5783
|
+
if (typeof state_5 === "object")
|
|
5784
|
+
return state_5.value;
|
|
5785
|
+
}
|
|
5786
|
+
}
|
|
5787
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
5788
|
+
finally {
|
|
5789
|
+
try {
|
|
5790
|
+
if (preferred_3_1 && !preferred_3_1.done && (_c = preferred_3.return)) _c.call(preferred_3);
|
|
5791
|
+
}
|
|
5792
|
+
finally { if (e_7) throw e_7.error; }
|
|
5793
|
+
}
|
|
5794
|
+
if (!effectiveAvailableCollections.length && !hints.length) {
|
|
5795
|
+
return normalizeOptionalString(preferred[0]) || '';
|
|
5796
|
+
}
|
|
5797
|
+
return normalizeOptionalString(effectiveAvailableCollections[0])
|
|
5798
|
+
|| normalizeOptionalString(availableCollections[0])
|
|
5799
|
+
|| normalizeOptionalString(hints[0])
|
|
5800
|
+
|| normalizeOptionalString(preferred[0])
|
|
5801
|
+
|| '';
|
|
5802
|
+
}
|
|
5803
|
+
function buildAssistantActiveClientsCountDirective(message, collectionHints, collectionNames) {
|
|
5804
|
+
var text = normalizeOptionalString(message).toLowerCase();
|
|
5805
|
+
if (!text) {
|
|
5806
|
+
return null;
|
|
5807
|
+
}
|
|
5808
|
+
if (!/\bactive\b/i.test(text)) {
|
|
5809
|
+
return null;
|
|
5810
|
+
}
|
|
5811
|
+
if (!/\b(clients?|customers?)\b/i.test(text)) {
|
|
5812
|
+
return null;
|
|
5813
|
+
}
|
|
5814
|
+
if (!/\b(how\s+many|count|number|total|show|list)\b/i.test(text)) {
|
|
5815
|
+
return null;
|
|
5816
|
+
}
|
|
5817
|
+
if (/\binactive\b/i.test(text)) {
|
|
5818
|
+
return null;
|
|
5819
|
+
}
|
|
5820
|
+
var reportBuilderCollections = mergeAssistantHintValues(listAssistantReportBuilderCollectionsFromManager());
|
|
5821
|
+
var knownCollections = mergeAssistantHintValues(collectionNames || [], reportBuilderCollections);
|
|
5822
|
+
var selectCollection = function (candidates) {
|
|
5823
|
+
var candidateFamilies = new Set(mergeAssistantHintValues(candidates || [])
|
|
5824
|
+
.map(function (candidate) { return normalizeAssistantCollectionFamilyName(candidate); })
|
|
5825
|
+
.filter(Boolean));
|
|
5826
|
+
if (!candidateFamilies.size) {
|
|
5827
|
+
return '';
|
|
5828
|
+
}
|
|
5829
|
+
var resolved = resolveAssistantHeuristicCollectionFromCandidates(collectionHints, candidates, collectionNames);
|
|
5830
|
+
var resolvedFamily = normalizeAssistantCollectionFamilyName(resolved);
|
|
5831
|
+
if (!resolvedFamily || !candidateFamilies.has(resolvedFamily)) {
|
|
5832
|
+
return '';
|
|
5833
|
+
}
|
|
5834
|
+
if (knownCollections.length) {
|
|
5835
|
+
var knownMatch = knownCollections.some(function (name) { return normalizeAssistantCollectionFamilyName(name) === resolvedFamily; });
|
|
5836
|
+
if (!knownMatch) {
|
|
5837
|
+
return '';
|
|
5838
|
+
}
|
|
5839
|
+
}
|
|
5840
|
+
return resolved;
|
|
5841
|
+
};
|
|
5842
|
+
var collection = selectCollection(['customers', 'clients']);
|
|
5843
|
+
if (!collection) {
|
|
5844
|
+
var rbSupportsUsers = reportBuilderCollections.some(function (name) { return normalizeAssistantCollectionFamilyName(name) === 'users'; });
|
|
5845
|
+
if (rbSupportsUsers) {
|
|
5846
|
+
collection = selectCollection(['users']);
|
|
5847
|
+
}
|
|
5848
|
+
}
|
|
5849
|
+
if (!collection) {
|
|
5850
|
+
return null;
|
|
5851
|
+
}
|
|
5852
|
+
var matchAnd = [
|
|
5853
|
+
{
|
|
5854
|
+
$or: [
|
|
5855
|
+
{ active: true },
|
|
5856
|
+
{ is_active: true },
|
|
5857
|
+
{ isactive: true },
|
|
5858
|
+
{ enabled: true },
|
|
5859
|
+
{ is_enabled: true },
|
|
5860
|
+
{ isenabled: true },
|
|
5861
|
+
{ status: { $regex: '^active$', $options: 'i' } },
|
|
5862
|
+
{ state: { $regex: '^active$', $options: 'i' } }
|
|
5863
|
+
]
|
|
5864
|
+
}
|
|
5865
|
+
];
|
|
5866
|
+
var collectionFamily = normalizeAssistantCollectionFamilyName(collection);
|
|
5867
|
+
if (collectionFamily === 'users') {
|
|
5868
|
+
matchAnd.push({
|
|
5869
|
+
$or: [
|
|
5870
|
+
{ 'other.id_customer': { $exists: true, $ne: null } },
|
|
5871
|
+
{ id_customer: { $exists: true, $ne: null } },
|
|
5872
|
+
{ customer: { $exists: true, $ne: null } }
|
|
5873
|
+
]
|
|
5874
|
+
});
|
|
5875
|
+
matchAnd.push({
|
|
5876
|
+
$or: [
|
|
5877
|
+
{ 'other.id_client': { $exists: true, $ne: null } },
|
|
5878
|
+
{ id_client: { $exists: true, $ne: null } }
|
|
5879
|
+
]
|
|
5880
|
+
});
|
|
5881
|
+
matchAnd.push({ 'roles.super_admin': { $ne: true } });
|
|
5882
|
+
}
|
|
5883
|
+
return {
|
|
5884
|
+
type: 'aggregate',
|
|
5885
|
+
payload: {
|
|
5886
|
+
collection: collection,
|
|
5887
|
+
permissionView: '/client/list',
|
|
5888
|
+
pipeline: [
|
|
5889
|
+
{
|
|
5890
|
+
$match: {
|
|
5891
|
+
$and: matchAnd
|
|
5892
|
+
}
|
|
5893
|
+
},
|
|
5894
|
+
{
|
|
5895
|
+
$group: {
|
|
5896
|
+
_id: null,
|
|
5897
|
+
active_clients: { $sum: 1 }
|
|
5898
|
+
}
|
|
5899
|
+
},
|
|
5900
|
+
{
|
|
5901
|
+
$project: {
|
|
5902
|
+
_id: 0,
|
|
5903
|
+
active_clients: 1
|
|
5904
|
+
}
|
|
5905
|
+
}
|
|
5906
|
+
],
|
|
5907
|
+
options: {
|
|
5908
|
+
allowDiskUse: true,
|
|
5909
|
+
limit: 1
|
|
5910
|
+
}
|
|
5911
|
+
},
|
|
5912
|
+
cleaned: '',
|
|
5913
|
+
rawLine: 'HEURISTIC_AGG(active-clients-count)'
|
|
5914
|
+
};
|
|
5915
|
+
}
|
|
5916
|
+
function buildAssistantWorkOrderCreatedThisWeekStatusDirective(message, collectionHints, collectionNames) {
|
|
5917
|
+
var text = normalizeOptionalString(message).toLowerCase();
|
|
5918
|
+
if (!text) {
|
|
5919
|
+
return null;
|
|
5920
|
+
}
|
|
5921
|
+
if (!hasAssistantWorkOrderAliasTerms(text)) {
|
|
5922
|
+
return null;
|
|
5923
|
+
}
|
|
5924
|
+
if (!/\bthis\s+week\b/i.test(text)) {
|
|
5925
|
+
return null;
|
|
5926
|
+
}
|
|
5927
|
+
if (!/\b(group(?:ed)?\s+by\s+status|by\s+status)\b/i.test(text)) {
|
|
5928
|
+
return null;
|
|
5929
|
+
}
|
|
5930
|
+
var limit = resolveAssistantNaturalNumberFromPattern(text, /\blast\s+([a-z0-9]+)\b/i, 20, 1, AI_ASSISTANT_MONGO_MAX_LIMIT);
|
|
5931
|
+
var collection = resolveAssistantHeuristicCollectionFromCandidates(collectionHints, AI_ASSISTANT_WORK_ORDER_HINT_CANDIDATES, collectionNames);
|
|
5932
|
+
if (!collection) {
|
|
5933
|
+
return null;
|
|
5934
|
+
}
|
|
5935
|
+
var startOfWeekExpr = {
|
|
5936
|
+
$dateTrunc: {
|
|
5937
|
+
date: '$$NOW',
|
|
5938
|
+
unit: 'week',
|
|
5939
|
+
startOfWeek: 'monday',
|
|
5940
|
+
timezone: 'UTC'
|
|
5941
|
+
}
|
|
5942
|
+
};
|
|
5943
|
+
return {
|
|
5944
|
+
type: 'aggregate',
|
|
5945
|
+
payload: {
|
|
5946
|
+
collection: collection,
|
|
5947
|
+
permissionView: resolveDefaultAssistantPermissionView(collection),
|
|
5948
|
+
pipeline: [
|
|
5949
|
+
{
|
|
5950
|
+
$match: {
|
|
5951
|
+
$expr: {
|
|
5952
|
+
$or: [
|
|
5953
|
+
{
|
|
5954
|
+
$and: [
|
|
5955
|
+
{ $gte: ['$date_created', startOfWeekExpr] },
|
|
5956
|
+
{ $lt: ['$date_created', '$$NOW'] }
|
|
5957
|
+
]
|
|
5958
|
+
},
|
|
5959
|
+
{
|
|
5960
|
+
$and: [
|
|
5961
|
+
{ $gte: ['$createdAt', startOfWeekExpr] },
|
|
5962
|
+
{ $lt: ['$createdAt', '$$NOW'] }
|
|
5963
|
+
]
|
|
5964
|
+
}
|
|
5965
|
+
]
|
|
5966
|
+
}
|
|
5967
|
+
}
|
|
5968
|
+
},
|
|
5969
|
+
{
|
|
5970
|
+
$addFields: {
|
|
5971
|
+
effective_created_at: { $ifNull: ['$date_created', '$createdAt'] }
|
|
5972
|
+
}
|
|
5973
|
+
},
|
|
5974
|
+
{
|
|
5975
|
+
$sort: {
|
|
5976
|
+
effective_created_at: -1
|
|
5977
|
+
}
|
|
5978
|
+
},
|
|
5979
|
+
{
|
|
5980
|
+
$limit: limit
|
|
5981
|
+
},
|
|
5982
|
+
{
|
|
5983
|
+
$group: {
|
|
5984
|
+
_id: { $ifNull: ['$status', { $ifNull: ['$state', 'Unknown'] }] },
|
|
5985
|
+
work_order_count: { $sum: 1 }
|
|
5986
|
+
}
|
|
5987
|
+
},
|
|
5988
|
+
{
|
|
5989
|
+
$sort: {
|
|
5990
|
+
work_order_count: -1,
|
|
5991
|
+
_id: 1
|
|
5992
|
+
}
|
|
5993
|
+
},
|
|
5994
|
+
{
|
|
5995
|
+
$project: {
|
|
5996
|
+
_id: 0,
|
|
5997
|
+
status: '$_id',
|
|
5998
|
+
work_order_count: 1
|
|
5999
|
+
}
|
|
6000
|
+
}
|
|
6001
|
+
],
|
|
6002
|
+
options: {
|
|
6003
|
+
allowDiskUse: true,
|
|
6004
|
+
limit: limit
|
|
6005
|
+
}
|
|
6006
|
+
},
|
|
6007
|
+
cleaned: '',
|
|
6008
|
+
rawLine: 'HEURISTIC_AGG(work-order-created-this-week-status)'
|
|
6009
|
+
};
|
|
6010
|
+
}
|
|
6011
|
+
function buildAssistantCompletedWorkOrdersPerDayDirective(message, collectionHints, collectionNames) {
|
|
6012
|
+
var text = normalizeOptionalString(message).toLowerCase();
|
|
6013
|
+
if (!text) {
|
|
6014
|
+
return null;
|
|
6015
|
+
}
|
|
6016
|
+
if (!hasAssistantWorkOrderAliasTerms(text)) {
|
|
6017
|
+
return null;
|
|
6018
|
+
}
|
|
6019
|
+
if (!/\b(completed|closed)\b/i.test(text)) {
|
|
6020
|
+
return null;
|
|
6021
|
+
}
|
|
6022
|
+
if (!/\b(by|per)\s+day\b/i.test(text)) {
|
|
6023
|
+
return null;
|
|
6024
|
+
}
|
|
6025
|
+
var days = resolveAssistantNaturalNumberFromPattern(text, /\b(?:last|past)\s+([a-z0-9]+)\s+days?\b/i, 30, 1, 365);
|
|
6026
|
+
var collection = resolveAssistantHeuristicCollectionFromCandidates(collectionHints, AI_ASSISTANT_WORK_ORDER_HINT_CANDIDATES, collectionNames);
|
|
6027
|
+
if (!collection) {
|
|
6028
|
+
return null;
|
|
6029
|
+
}
|
|
6030
|
+
return {
|
|
6031
|
+
type: 'aggregate',
|
|
6032
|
+
payload: {
|
|
6033
|
+
collection: collection,
|
|
6034
|
+
permissionView: resolveDefaultAssistantPermissionView(collection),
|
|
6035
|
+
pipeline: [
|
|
6036
|
+
{
|
|
6037
|
+
$addFields: {
|
|
6038
|
+
effective_completed_at: {
|
|
6039
|
+
$ifNull: [
|
|
6040
|
+
'$date_completed',
|
|
6041
|
+
{
|
|
6042
|
+
$ifNull: [
|
|
6043
|
+
'$completedAt',
|
|
6044
|
+
'$date_closed'
|
|
6045
|
+
]
|
|
6046
|
+
}
|
|
6047
|
+
]
|
|
6048
|
+
}
|
|
6049
|
+
}
|
|
6050
|
+
},
|
|
6051
|
+
{
|
|
6052
|
+
$match: {
|
|
6053
|
+
$expr: {
|
|
6054
|
+
$and: [
|
|
6055
|
+
{ $ne: ['$effective_completed_at', null] },
|
|
6056
|
+
{
|
|
6057
|
+
$gte: [
|
|
6058
|
+
'$effective_completed_at',
|
|
6059
|
+
{
|
|
6060
|
+
$dateSubtract: {
|
|
6061
|
+
startDate: '$$NOW',
|
|
6062
|
+
unit: 'day',
|
|
6063
|
+
amount: days
|
|
6064
|
+
}
|
|
6065
|
+
}
|
|
6066
|
+
]
|
|
6067
|
+
},
|
|
6068
|
+
{ $lt: ['$effective_completed_at', '$$NOW'] }
|
|
6069
|
+
]
|
|
6070
|
+
}
|
|
6071
|
+
}
|
|
6072
|
+
},
|
|
6073
|
+
{
|
|
6074
|
+
$group: {
|
|
6075
|
+
_id: {
|
|
6076
|
+
$dateToString: {
|
|
6077
|
+
format: '%Y-%m-%d',
|
|
6078
|
+
date: '$effective_completed_at',
|
|
6079
|
+
timezone: 'UTC'
|
|
6080
|
+
}
|
|
6081
|
+
},
|
|
6082
|
+
completed_work_orders: { $sum: 1 }
|
|
6083
|
+
}
|
|
6084
|
+
},
|
|
6085
|
+
{
|
|
6086
|
+
$sort: {
|
|
6087
|
+
_id: 1
|
|
6088
|
+
}
|
|
6089
|
+
},
|
|
6090
|
+
{
|
|
6091
|
+
$project: {
|
|
6092
|
+
_id: 0,
|
|
6093
|
+
day_utc: '$_id',
|
|
6094
|
+
completed_work_orders: 1
|
|
6095
|
+
}
|
|
6096
|
+
}
|
|
6097
|
+
],
|
|
6098
|
+
options: {
|
|
6099
|
+
allowDiskUse: true,
|
|
6100
|
+
limit: Math.min(days + 10, AI_ASSISTANT_MONGO_MAX_LIMIT)
|
|
6101
|
+
}
|
|
6102
|
+
},
|
|
6103
|
+
cleaned: '',
|
|
6104
|
+
rawLine: 'HEURISTIC_AGG(work-order-completed-per-day)'
|
|
6105
|
+
};
|
|
6106
|
+
}
|
|
6107
|
+
function buildAssistantWorkOrderTopCustomersDirective(message, collectionHints, collectionNames) {
|
|
6108
|
+
var text = normalizeOptionalString(message).toLowerCase();
|
|
6109
|
+
if (!text) {
|
|
6110
|
+
return null;
|
|
6111
|
+
}
|
|
6112
|
+
if (!hasAssistantWorkOrderAliasTerms(text)) {
|
|
6113
|
+
return null;
|
|
6114
|
+
}
|
|
6115
|
+
if (!/\b(customers?|clients?|accounts?)\b/i.test(text)) {
|
|
6116
|
+
return null;
|
|
6117
|
+
}
|
|
6118
|
+
if (!/\btop\b/i.test(text)) {
|
|
6119
|
+
return null;
|
|
6120
|
+
}
|
|
6121
|
+
var hasMonthWindow = /\b(?:last|past)\s+[a-z0-9]+\s+months?\b/i.test(text);
|
|
6122
|
+
if (!hasMonthWindow) {
|
|
6123
|
+
return null;
|
|
6124
|
+
}
|
|
6125
|
+
var topN = resolveAssistantNaturalNumberFromPattern(text, /\btop\s+([a-z0-9]+)\b/i, 10, 1, 100);
|
|
6126
|
+
var months = resolveAssistantNaturalNumberFromPattern(text, /\b(?:last|past)\s+([a-z0-9]+)\s+months?\b/i, 6, 1, 24);
|
|
6127
|
+
var collection = resolveAssistantHeuristicCollectionFromCandidates(collectionHints, AI_ASSISTANT_WORK_ORDER_HINT_CANDIDATES, collectionNames);
|
|
6128
|
+
if (!collection) {
|
|
6129
|
+
return null;
|
|
6130
|
+
}
|
|
6131
|
+
return {
|
|
6132
|
+
type: 'aggregate',
|
|
6133
|
+
payload: {
|
|
6134
|
+
collection: collection,
|
|
6135
|
+
permissionView: resolveDefaultAssistantPermissionView(collection),
|
|
6136
|
+
pipeline: [
|
|
6137
|
+
{
|
|
6138
|
+
$addFields: {
|
|
6139
|
+
effective_date: {
|
|
6140
|
+
$ifNull: [
|
|
6141
|
+
'$date_created',
|
|
6142
|
+
{ $ifNull: ['$date_create', '$createdAt'] }
|
|
6143
|
+
]
|
|
6144
|
+
},
|
|
6145
|
+
customer_label: {
|
|
6146
|
+
$ifNull: [
|
|
6147
|
+
'$customer',
|
|
6148
|
+
{
|
|
6149
|
+
$ifNull: [
|
|
6150
|
+
'$customer_name',
|
|
6151
|
+
{
|
|
6152
|
+
$ifNull: [
|
|
6153
|
+
'$client_name',
|
|
6154
|
+
{
|
|
6155
|
+
$ifNull: [
|
|
6156
|
+
{ $toString: '$id_customer' },
|
|
6157
|
+
{ $ifNull: ['$qb_ListID_class', 'Unknown'] }
|
|
6158
|
+
]
|
|
6159
|
+
}
|
|
6160
|
+
]
|
|
6161
|
+
}
|
|
6162
|
+
]
|
|
6163
|
+
}
|
|
6164
|
+
]
|
|
6165
|
+
}
|
|
6166
|
+
}
|
|
6167
|
+
},
|
|
6168
|
+
{
|
|
6169
|
+
$match: {
|
|
6170
|
+
effective_date: {
|
|
6171
|
+
$gte: {
|
|
6172
|
+
$dateSubtract: {
|
|
6173
|
+
startDate: '$$NOW',
|
|
6174
|
+
unit: 'month',
|
|
6175
|
+
amount: months
|
|
6176
|
+
}
|
|
6177
|
+
},
|
|
6178
|
+
$lt: '$$NOW'
|
|
6179
|
+
},
|
|
6180
|
+
'deleted.date': { $exists: false }
|
|
6181
|
+
}
|
|
6182
|
+
},
|
|
6183
|
+
{
|
|
6184
|
+
$group: {
|
|
6185
|
+
_id: '$customer_label',
|
|
6186
|
+
work_order_count: { $sum: 1 }
|
|
6187
|
+
}
|
|
6188
|
+
},
|
|
6189
|
+
{
|
|
6190
|
+
$sort: {
|
|
6191
|
+
work_order_count: -1,
|
|
6192
|
+
_id: 1
|
|
6193
|
+
}
|
|
6194
|
+
},
|
|
6195
|
+
{
|
|
6196
|
+
$limit: topN
|
|
6197
|
+
},
|
|
6198
|
+
{
|
|
6199
|
+
$project: {
|
|
6200
|
+
_id: 0,
|
|
6201
|
+
customer: '$_id',
|
|
6202
|
+
work_order_count: 1
|
|
6203
|
+
}
|
|
6204
|
+
}
|
|
6205
|
+
],
|
|
6206
|
+
options: {
|
|
6207
|
+
allowDiskUse: true,
|
|
6208
|
+
limit: topN
|
|
6209
|
+
}
|
|
6210
|
+
},
|
|
6211
|
+
cleaned: '',
|
|
6212
|
+
rawLine: 'HEURISTIC_AGG(work-order-top-customers-window)'
|
|
6213
|
+
};
|
|
6214
|
+
}
|
|
5627
6215
|
function isAssistantSchemaHoursHeuristicDirective(directive) {
|
|
5628
6216
|
var rawLine = normalizeOptionalString(directive === null || directive === void 0 ? void 0 : directive.rawLine).toLowerCase();
|
|
5629
6217
|
return rawLine.includes('heuristic_agg(schema-hours-user-time)');
|
|
@@ -5632,11 +6220,24 @@ function isAssistantBlendThroughputHeuristicDirective(directive) {
|
|
|
5632
6220
|
var rawLine = normalizeOptionalString(directive === null || directive === void 0 ? void 0 : directive.rawLine).toLowerCase();
|
|
5633
6221
|
return rawLine.includes('heuristic_agg(blend-throughput-day-window)');
|
|
5634
6222
|
}
|
|
6223
|
+
function isAssistantWorkOrderHeuristicDirective(directive) {
|
|
6224
|
+
var rawLine = normalizeOptionalString(directive === null || directive === void 0 ? void 0 : directive.rawLine).toLowerCase();
|
|
6225
|
+
return rawLine.includes('heuristic_agg(work-order-created-this-week-status)')
|
|
6226
|
+
|| rawLine.includes('heuristic_agg(work-order-completed-per-day)')
|
|
6227
|
+
|| rawLine.includes('heuristic_agg(work-order-top-customers-window)');
|
|
6228
|
+
}
|
|
6229
|
+
function isAssistantActiveClientsHeuristicDirective(directive) {
|
|
6230
|
+
var rawLine = normalizeOptionalString(directive === null || directive === void 0 ? void 0 : directive.rawLine).toLowerCase();
|
|
6231
|
+
return rawLine.includes('heuristic_agg(active-clients-count)');
|
|
6232
|
+
}
|
|
5635
6233
|
function isAssistantDeterministicHeuristicDirective(directive) {
|
|
5636
6234
|
return isAssistantSchemaHoursHeuristicDirective(directive)
|
|
5637
|
-
|| isAssistantBlendThroughputHeuristicDirective(directive)
|
|
6235
|
+
|| isAssistantBlendThroughputHeuristicDirective(directive)
|
|
6236
|
+
|| isAssistantWorkOrderHeuristicDirective(directive)
|
|
6237
|
+
|| isAssistantActiveClientsHeuristicDirective(directive);
|
|
5638
6238
|
}
|
|
5639
|
-
function buildAssistantHeuristicDirective(message, collectionHints) {
|
|
6239
|
+
function buildAssistantHeuristicDirective(message, collectionHints, collectionNames) {
|
|
6240
|
+
if (collectionNames === void 0) { collectionNames = []; }
|
|
5640
6241
|
if (!normalizeOptionalString(message)) {
|
|
5641
6242
|
return null;
|
|
5642
6243
|
}
|
|
@@ -5644,6 +6245,22 @@ function buildAssistantHeuristicDirective(message, collectionHints) {
|
|
|
5644
6245
|
if (blendThroughputDirective) {
|
|
5645
6246
|
return blendThroughputDirective;
|
|
5646
6247
|
}
|
|
6248
|
+
var activeClientsDirective = buildAssistantActiveClientsCountDirective(message, collectionHints, collectionNames);
|
|
6249
|
+
if (activeClientsDirective) {
|
|
6250
|
+
return activeClientsDirective;
|
|
6251
|
+
}
|
|
6252
|
+
var workOrderCreatedWeekDirective = buildAssistantWorkOrderCreatedThisWeekStatusDirective(message, collectionHints, collectionNames);
|
|
6253
|
+
if (workOrderCreatedWeekDirective) {
|
|
6254
|
+
return workOrderCreatedWeekDirective;
|
|
6255
|
+
}
|
|
6256
|
+
var completedWorkOrdersPerDayDirective = buildAssistantCompletedWorkOrdersPerDayDirective(message, collectionHints, collectionNames);
|
|
6257
|
+
if (completedWorkOrdersPerDayDirective) {
|
|
6258
|
+
return completedWorkOrdersPerDayDirective;
|
|
6259
|
+
}
|
|
6260
|
+
var workOrderTopCustomersDirective = buildAssistantWorkOrderTopCustomersDirective(message, collectionHints, collectionNames);
|
|
6261
|
+
if (workOrderTopCustomersDirective) {
|
|
6262
|
+
return workOrderTopCustomersDirective;
|
|
6263
|
+
}
|
|
5647
6264
|
var schemaHoursDirective = buildAssistantGenericHoursDirective(message, collectionHints);
|
|
5648
6265
|
if (schemaHoursDirective) {
|
|
5649
6266
|
return schemaHoursDirective;
|
|
@@ -5679,9 +6296,18 @@ function resolveDefaultAssistantPermissionView(collection) {
|
|
|
5679
6296
|
if (base.startsWith('client')) {
|
|
5680
6297
|
return '/client/list';
|
|
5681
6298
|
}
|
|
6299
|
+
if (base.startsWith('customer')) {
|
|
6300
|
+
return '/client/list';
|
|
6301
|
+
}
|
|
5682
6302
|
if (base.startsWith('employee')) {
|
|
5683
6303
|
return '/employee/list';
|
|
5684
6304
|
}
|
|
6305
|
+
if (/work[-_/ ]?orders?|maintenance[-_/ ]?orders?|repair[-_/ ]?orders?/.test(base)) {
|
|
6306
|
+
return '/order/list';
|
|
6307
|
+
}
|
|
6308
|
+
if (base === 'orders' || base.startsWith('order-') || base.startsWith('orders-')) {
|
|
6309
|
+
return '/order/list';
|
|
6310
|
+
}
|
|
5685
6311
|
if (base.startsWith('support-ticket') || base.startsWith('supportticket')) {
|
|
5686
6312
|
return '/support-ticket/list';
|
|
5687
6313
|
}
|
|
@@ -5765,7 +6391,7 @@ function ensureAssistantDisplayColumns(display, requestedColumns) {
|
|
|
5765
6391
|
return __assign(__assign({}, display), { columns: columns, rows: rows });
|
|
5766
6392
|
}
|
|
5767
6393
|
function resolveAssistantPipelineTimeGrain(pipeline) {
|
|
5768
|
-
var
|
|
6394
|
+
var e_8, _a;
|
|
5769
6395
|
if (!Array.isArray(pipeline) || !pipeline.length) {
|
|
5770
6396
|
return null;
|
|
5771
6397
|
}
|
|
@@ -5827,12 +6453,12 @@ function resolveAssistantPipelineTimeGrain(pipeline) {
|
|
|
5827
6453
|
}
|
|
5828
6454
|
}
|
|
5829
6455
|
}
|
|
5830
|
-
catch (
|
|
6456
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
5831
6457
|
finally {
|
|
5832
6458
|
try {
|
|
5833
6459
|
if (priority_1_1 && !priority_1_1.done && (_a = priority_1.return)) _a.call(priority_1);
|
|
5834
6460
|
}
|
|
5835
|
-
finally { if (
|
|
6461
|
+
finally { if (e_8) throw e_8.error; }
|
|
5836
6462
|
}
|
|
5837
6463
|
return null;
|
|
5838
6464
|
}
|
|
@@ -6535,7 +7161,7 @@ function applyAssistantDatedReportWindow(value, toolResult) {
|
|
|
6535
7161
|
return "".concat(line, "\n\n").concat(content).trim();
|
|
6536
7162
|
}
|
|
6537
7163
|
function resolveAssistantDatedReportWindow(toolResult) {
|
|
6538
|
-
var
|
|
7164
|
+
var e_9, _a;
|
|
6539
7165
|
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
6540
7166
|
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;
|
|
6541
7167
|
var verificationStart = normalizeOptionalString(verificationWindow === null || verificationWindow === void 0 ? void 0 : verificationWindow.startDate);
|
|
@@ -6601,12 +7227,12 @@ function resolveAssistantDatedReportWindow(toolResult) {
|
|
|
6601
7227
|
};
|
|
6602
7228
|
}
|
|
6603
7229
|
}
|
|
6604
|
-
catch (
|
|
7230
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
6605
7231
|
finally {
|
|
6606
7232
|
try {
|
|
6607
7233
|
if (pipelineCandidates_1_1 && !pipelineCandidates_1_1.done && (_a = pipelineCandidates_1.return)) _a.call(pipelineCandidates_1);
|
|
6608
7234
|
}
|
|
6609
|
-
finally { if (
|
|
7235
|
+
finally { if (e_9) throw e_9.error; }
|
|
6610
7236
|
}
|
|
6611
7237
|
return null;
|
|
6612
7238
|
}
|
|
@@ -7238,7 +7864,7 @@ function getValueAtPath(obj, path) {
|
|
|
7238
7864
|
return walk(obj, 0);
|
|
7239
7865
|
}
|
|
7240
7866
|
function hasArrayValueAtPath(docs, path) {
|
|
7241
|
-
var
|
|
7867
|
+
var e_10, _a;
|
|
7242
7868
|
if (!Array.isArray(docs) || !docs.length || !path) {
|
|
7243
7869
|
return false;
|
|
7244
7870
|
}
|
|
@@ -7251,17 +7877,17 @@ function hasArrayValueAtPath(docs, path) {
|
|
|
7251
7877
|
}
|
|
7252
7878
|
}
|
|
7253
7879
|
}
|
|
7254
|
-
catch (
|
|
7880
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
7255
7881
|
finally {
|
|
7256
7882
|
try {
|
|
7257
7883
|
if (docs_1_1 && !docs_1_1.done && (_a = docs_1.return)) _a.call(docs_1);
|
|
7258
7884
|
}
|
|
7259
|
-
finally { if (
|
|
7885
|
+
finally { if (e_10) throw e_10.error; }
|
|
7260
7886
|
}
|
|
7261
7887
|
return false;
|
|
7262
7888
|
}
|
|
7263
7889
|
function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
|
|
7264
|
-
var
|
|
7890
|
+
var e_11, _a, e_12, _b;
|
|
7265
7891
|
if (!Array.isArray(docs) || !fieldPath) {
|
|
7266
7892
|
return 'unknown';
|
|
7267
7893
|
}
|
|
@@ -7274,7 +7900,7 @@ function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
|
|
|
7274
7900
|
: doc === null || doc === void 0 ? void 0 : doc[fieldPath];
|
|
7275
7901
|
var queue = Array.isArray(value) ? value : [value];
|
|
7276
7902
|
try {
|
|
7277
|
-
for (var queue_1 = (
|
|
7903
|
+
for (var queue_1 = (e_12 = void 0, __values(queue)), queue_1_1 = queue_1.next(); !queue_1_1.done; queue_1_1 = queue_1.next()) {
|
|
7278
7904
|
var entry = queue_1_1.value;
|
|
7279
7905
|
if (entry === null || entry === undefined) {
|
|
7280
7906
|
continue;
|
|
@@ -7287,21 +7913,21 @@ function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
|
|
|
7287
7913
|
}
|
|
7288
7914
|
}
|
|
7289
7915
|
}
|
|
7290
|
-
catch (
|
|
7916
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
7291
7917
|
finally {
|
|
7292
7918
|
try {
|
|
7293
7919
|
if (queue_1_1 && !queue_1_1.done && (_b = queue_1.return)) _b.call(queue_1);
|
|
7294
7920
|
}
|
|
7295
|
-
finally { if (
|
|
7921
|
+
finally { if (e_12) throw e_12.error; }
|
|
7296
7922
|
}
|
|
7297
7923
|
}
|
|
7298
7924
|
}
|
|
7299
|
-
catch (
|
|
7925
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
7300
7926
|
finally {
|
|
7301
7927
|
try {
|
|
7302
7928
|
if (docs_2_1 && !docs_2_1.done && (_a = docs_2.return)) _a.call(docs_2);
|
|
7303
7929
|
}
|
|
7304
|
-
finally { if (
|
|
7930
|
+
finally { if (e_11) throw e_11.error; }
|
|
7305
7931
|
}
|
|
7306
7932
|
return sawString ? 'string' : 'unknown';
|
|
7307
7933
|
}
|
|
@@ -7396,7 +8022,7 @@ function normalizeLookupKeyValue(value) {
|
|
|
7396
8022
|
return '';
|
|
7397
8023
|
}
|
|
7398
8024
|
function collectTopLevelIdFieldValues(docs, options) {
|
|
7399
|
-
var
|
|
8025
|
+
var e_13, _a, e_14, _b;
|
|
7400
8026
|
if (!Array.isArray(docs) || !docs.length) {
|
|
7401
8027
|
return [];
|
|
7402
8028
|
}
|
|
@@ -7414,7 +8040,7 @@ function collectTopLevelIdFieldValues(docs, options) {
|
|
|
7414
8040
|
continue;
|
|
7415
8041
|
}
|
|
7416
8042
|
var keys = Object.keys(doc);
|
|
7417
|
-
var
|
|
8043
|
+
var _loop_6 = function (key) {
|
|
7418
8044
|
if (!key || key === '_id' || key === '__v') {
|
|
7419
8045
|
return "continue";
|
|
7420
8046
|
}
|
|
@@ -7444,26 +8070,26 @@ function collectTopLevelIdFieldValues(docs, options) {
|
|
|
7444
8070
|
});
|
|
7445
8071
|
};
|
|
7446
8072
|
try {
|
|
7447
|
-
for (var keys_1 = (
|
|
8073
|
+
for (var keys_1 = (e_14 = void 0, __values(keys)), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
|
|
7448
8074
|
var key = keys_1_1.value;
|
|
7449
|
-
|
|
8075
|
+
_loop_6(key);
|
|
7450
8076
|
}
|
|
7451
8077
|
}
|
|
7452
|
-
catch (
|
|
8078
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
7453
8079
|
finally {
|
|
7454
8080
|
try {
|
|
7455
8081
|
if (keys_1_1 && !keys_1_1.done && (_b = keys_1.return)) _b.call(keys_1);
|
|
7456
8082
|
}
|
|
7457
|
-
finally { if (
|
|
8083
|
+
finally { if (e_14) throw e_14.error; }
|
|
7458
8084
|
}
|
|
7459
8085
|
}
|
|
7460
8086
|
}
|
|
7461
|
-
catch (
|
|
8087
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
7462
8088
|
finally {
|
|
7463
8089
|
try {
|
|
7464
8090
|
if (docs_3_1 && !docs_3_1.done && (_a = docs_3.return)) _a.call(docs_3);
|
|
7465
8091
|
}
|
|
7466
|
-
finally { if (
|
|
8092
|
+
finally { if (e_13) throw e_13.error; }
|
|
7467
8093
|
}
|
|
7468
8094
|
return Array.from(fieldMap.entries()).map(function (_a) {
|
|
7469
8095
|
var _b = __read(_a, 2), field = _b[0], values = _b[1];
|
|
@@ -7582,8 +8208,8 @@ function resolveLookupMappingsForField(field, mappings) {
|
|
|
7582
8208
|
}
|
|
7583
8209
|
function applyIdLookupDisplayEnrichment(params) {
|
|
7584
8210
|
return __awaiter(this, void 0, void 0, function () {
|
|
7585
|
-
var docs, collection, db, dbName, idClient, idCustomer, isSuperAdmin, idFields, lookupMappings, allCollections, collectionProbeCache, collectionSchemaCache, lookupMeta, enrichedDocs,
|
|
7586
|
-
var
|
|
8211
|
+
var docs, collection, db, dbName, idClient, idCustomer, isSuperAdmin, idFields, lookupMappings, allCollections, collectionProbeCache, collectionSchemaCache, lookupMeta, enrichedDocs, _loop_7, idFields_1, idFields_1_1, fieldEntry, e_15_1;
|
|
8212
|
+
var e_15, _a;
|
|
7587
8213
|
return __generator(this, function (_b) {
|
|
7588
8214
|
switch (_b.label) {
|
|
7589
8215
|
case 0:
|
|
@@ -7606,9 +8232,9 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
7606
8232
|
collectionSchemaCache = new Map();
|
|
7607
8233
|
lookupMeta = [];
|
|
7608
8234
|
enrichedDocs = docs.map(function (doc) { return (__assign({}, doc)); });
|
|
7609
|
-
|
|
7610
|
-
var values, baseToken, mappingMatches, candidateCollections, filteredCandidates,
|
|
7611
|
-
var
|
|
8235
|
+
_loop_7 = function (fieldEntry) {
|
|
8236
|
+
var values, baseToken, mappingMatches, candidateCollections, filteredCandidates, _loop_8, filteredCandidates_1, filteredCandidates_1_1, candidate, state_6, e_16_1;
|
|
8237
|
+
var e_16, _c;
|
|
7612
8238
|
return __generator(this, function (_d) {
|
|
7613
8239
|
switch (_d.label) {
|
|
7614
8240
|
case 0:
|
|
@@ -7633,7 +8259,7 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
7633
8259
|
if (!filteredCandidates.length) {
|
|
7634
8260
|
return [2 /*return*/, "continue"];
|
|
7635
8261
|
}
|
|
7636
|
-
|
|
8262
|
+
_loop_8 = function (candidate) {
|
|
7637
8263
|
var probeDocs, candidateHasClientScope, _e, schemaFields, nameFieldCandidates, mapping, lookupKey, idsForQuery, query, candidateHasClientScope, _f, projection, lookupDocs, bestLookupField, nameField, nameMap, displayField;
|
|
7638
8264
|
var _g, _h;
|
|
7639
8265
|
return __generator(this, function (_j) {
|
|
@@ -7770,15 +8396,15 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
7770
8396
|
_d.label = 1;
|
|
7771
8397
|
case 1:
|
|
7772
8398
|
_d.trys.push([1, 6, 7, 8]);
|
|
7773
|
-
filteredCandidates_1 = (
|
|
8399
|
+
filteredCandidates_1 = (e_16 = void 0, __values(filteredCandidates)), filteredCandidates_1_1 = filteredCandidates_1.next();
|
|
7774
8400
|
_d.label = 2;
|
|
7775
8401
|
case 2:
|
|
7776
8402
|
if (!!filteredCandidates_1_1.done) return [3 /*break*/, 5];
|
|
7777
8403
|
candidate = filteredCandidates_1_1.value;
|
|
7778
|
-
return [5 /*yield**/,
|
|
8404
|
+
return [5 /*yield**/, _loop_8(candidate)];
|
|
7779
8405
|
case 3:
|
|
7780
|
-
|
|
7781
|
-
if (
|
|
8406
|
+
state_6 = _d.sent();
|
|
8407
|
+
if (state_6 === "break")
|
|
7782
8408
|
return [3 /*break*/, 5];
|
|
7783
8409
|
_d.label = 4;
|
|
7784
8410
|
case 4:
|
|
@@ -7786,14 +8412,14 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
7786
8412
|
return [3 /*break*/, 2];
|
|
7787
8413
|
case 5: return [3 /*break*/, 8];
|
|
7788
8414
|
case 6:
|
|
7789
|
-
|
|
7790
|
-
|
|
8415
|
+
e_16_1 = _d.sent();
|
|
8416
|
+
e_16 = { error: e_16_1 };
|
|
7791
8417
|
return [3 /*break*/, 8];
|
|
7792
8418
|
case 7:
|
|
7793
8419
|
try {
|
|
7794
8420
|
if (filteredCandidates_1_1 && !filteredCandidates_1_1.done && (_c = filteredCandidates_1.return)) _c.call(filteredCandidates_1);
|
|
7795
8421
|
}
|
|
7796
|
-
finally { if (
|
|
8422
|
+
finally { if (e_16) throw e_16.error; }
|
|
7797
8423
|
return [7 /*endfinally*/];
|
|
7798
8424
|
case 8: return [2 /*return*/];
|
|
7799
8425
|
}
|
|
@@ -7807,7 +8433,7 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
7807
8433
|
case 3:
|
|
7808
8434
|
if (!!idFields_1_1.done) return [3 /*break*/, 6];
|
|
7809
8435
|
fieldEntry = idFields_1_1.value;
|
|
7810
|
-
return [5 /*yield**/,
|
|
8436
|
+
return [5 /*yield**/, _loop_7(fieldEntry)];
|
|
7811
8437
|
case 4:
|
|
7812
8438
|
_b.sent();
|
|
7813
8439
|
_b.label = 5;
|
|
@@ -7816,14 +8442,14 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
7816
8442
|
return [3 /*break*/, 3];
|
|
7817
8443
|
case 6: return [3 /*break*/, 9];
|
|
7818
8444
|
case 7:
|
|
7819
|
-
|
|
7820
|
-
|
|
8445
|
+
e_15_1 = _b.sent();
|
|
8446
|
+
e_15 = { error: e_15_1 };
|
|
7821
8447
|
return [3 /*break*/, 9];
|
|
7822
8448
|
case 8:
|
|
7823
8449
|
try {
|
|
7824
8450
|
if (idFields_1_1 && !idFields_1_1.done && (_a = idFields_1.return)) _a.call(idFields_1);
|
|
7825
8451
|
}
|
|
7826
|
-
finally { if (
|
|
8452
|
+
finally { if (e_15) throw e_15.error; }
|
|
7827
8453
|
return [7 /*endfinally*/];
|
|
7828
8454
|
case 9:
|
|
7829
8455
|
if (!lookupMeta.length) {
|
|
@@ -7842,7 +8468,7 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
7842
8468
|
});
|
|
7843
8469
|
}
|
|
7844
8470
|
function hasNonEmptyValue(docs, fieldPath, options) {
|
|
7845
|
-
var
|
|
8471
|
+
var e_17, _a;
|
|
7846
8472
|
if (!Array.isArray(docs) || !fieldPath) {
|
|
7847
8473
|
return false;
|
|
7848
8474
|
}
|
|
@@ -7859,12 +8485,12 @@ function hasNonEmptyValue(docs, fieldPath, options) {
|
|
|
7859
8485
|
}
|
|
7860
8486
|
}
|
|
7861
8487
|
}
|
|
7862
|
-
catch (
|
|
8488
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
7863
8489
|
finally {
|
|
7864
8490
|
try {
|
|
7865
8491
|
if (docs_4_1 && !docs_4_1.done && (_a = docs_4.return)) _a.call(docs_4);
|
|
7866
8492
|
}
|
|
7867
|
-
finally { if (
|
|
8493
|
+
finally { if (e_17) throw e_17.error; }
|
|
7868
8494
|
}
|
|
7869
8495
|
return false;
|
|
7870
8496
|
}
|
|
@@ -8936,6 +9562,15 @@ function applyAssistantDisplayTableToResponse(value, display) {
|
|
|
8936
9562
|
var rowCount = typeof normalizedDisplay.rowCount === 'number' && normalizedDisplay.rowCount > 0
|
|
8937
9563
|
? normalizedDisplay.rowCount
|
|
8938
9564
|
: 0;
|
|
9565
|
+
if (rowCount <= 0) {
|
|
9566
|
+
if (!cleaned_1) {
|
|
9567
|
+
return 'No rows matched your request.';
|
|
9568
|
+
}
|
|
9569
|
+
if (/\bno rows? matched\b/i.test(cleaned_1)) {
|
|
9570
|
+
return cleaned_1;
|
|
9571
|
+
}
|
|
9572
|
+
return "".concat(cleaned_1.trim(), "\n\nNo rows matched your request.").trim();
|
|
9573
|
+
}
|
|
8939
9574
|
var fallbackColumns = Array.isArray(normalizedDisplay.columns) && normalizedDisplay.columns.length
|
|
8940
9575
|
? normalizedDisplay.columns
|
|
8941
9576
|
: resolveAssistantEmptyDisplayColumns(cleaned_1 || value);
|
|
@@ -10281,7 +10916,7 @@ function flattenAssistantExprClauses(expr) {
|
|
|
10281
10916
|
return [expr];
|
|
10282
10917
|
}
|
|
10283
10918
|
function detectAssistantMonthWindowInExpr(expr, allowedDateFields) {
|
|
10284
|
-
var
|
|
10919
|
+
var e_18, _a;
|
|
10285
10920
|
var clauses = flattenAssistantExprClauses(expr);
|
|
10286
10921
|
if (!clauses.length) {
|
|
10287
10922
|
return null;
|
|
@@ -10332,7 +10967,7 @@ function detectAssistantMonthWindowInExpr(expr, allowedDateFields) {
|
|
|
10332
10967
|
upperClauses.push({ index: index, field: field, mode: 'full_month' });
|
|
10333
10968
|
}
|
|
10334
10969
|
});
|
|
10335
|
-
var
|
|
10970
|
+
var _loop_9 = function (lower) {
|
|
10336
10971
|
var upper = upperClauses.find(function (candidate) { return (candidate.field === lower.field
|
|
10337
10972
|
&& candidate.mode === lower.mode); });
|
|
10338
10973
|
if (!upper) {
|
|
@@ -10350,17 +10985,17 @@ function detectAssistantMonthWindowInExpr(expr, allowedDateFields) {
|
|
|
10350
10985
|
try {
|
|
10351
10986
|
for (var lowerClauses_1 = __values(lowerClauses), lowerClauses_1_1 = lowerClauses_1.next(); !lowerClauses_1_1.done; lowerClauses_1_1 = lowerClauses_1.next()) {
|
|
10352
10987
|
var lower = lowerClauses_1_1.value;
|
|
10353
|
-
var
|
|
10354
|
-
if (typeof
|
|
10355
|
-
return
|
|
10988
|
+
var state_7 = _loop_9(lower);
|
|
10989
|
+
if (typeof state_7 === "object")
|
|
10990
|
+
return state_7.value;
|
|
10356
10991
|
}
|
|
10357
10992
|
}
|
|
10358
|
-
catch (
|
|
10993
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
10359
10994
|
finally {
|
|
10360
10995
|
try {
|
|
10361
10996
|
if (lowerClauses_1_1 && !lowerClauses_1_1.done && (_a = lowerClauses_1.return)) _a.call(lowerClauses_1);
|
|
10362
10997
|
}
|
|
10363
|
-
finally { if (
|
|
10998
|
+
finally { if (e_18) throw e_18.error; }
|
|
10364
10999
|
}
|
|
10365
11000
|
return null;
|
|
10366
11001
|
}
|
|
@@ -10423,7 +11058,7 @@ function resolveAssistantMonthlyGroupDateFields(pipeline) {
|
|
|
10423
11058
|
return fields;
|
|
10424
11059
|
}
|
|
10425
11060
|
function detectAssistantMonthWindowFromPipeline(pipeline) {
|
|
10426
|
-
var
|
|
11061
|
+
var e_19, _a;
|
|
10427
11062
|
var _b;
|
|
10428
11063
|
var monthlyFields = resolveAssistantMonthlyGroupDateFields(pipeline);
|
|
10429
11064
|
var scanMatch = function (match) {
|
|
@@ -10451,12 +11086,12 @@ function detectAssistantMonthWindowFromPipeline(pipeline) {
|
|
|
10451
11086
|
}
|
|
10452
11087
|
}
|
|
10453
11088
|
}
|
|
10454
|
-
catch (
|
|
11089
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
10455
11090
|
finally {
|
|
10456
11091
|
try {
|
|
10457
11092
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
10458
11093
|
}
|
|
10459
|
-
finally { if (
|
|
11094
|
+
finally { if (e_19) throw e_19.error; }
|
|
10460
11095
|
}
|
|
10461
11096
|
return null;
|
|
10462
11097
|
}
|
|
@@ -10736,7 +11371,7 @@ function normalizeAssistantCustomerLookupProjectionPipeline(pipeline) {
|
|
|
10736
11371
|
var nextProject = __assign({}, project);
|
|
10737
11372
|
var stageChanged = false;
|
|
10738
11373
|
Object.keys(nextProject).forEach(function (field) {
|
|
10739
|
-
var
|
|
11374
|
+
var e_20, _a;
|
|
10740
11375
|
var expression = nextProject[field];
|
|
10741
11376
|
if (typeof expression !== 'string') {
|
|
10742
11377
|
return;
|
|
@@ -10772,12 +11407,12 @@ function normalizeAssistantCustomerLookupProjectionPipeline(pipeline) {
|
|
|
10772
11407
|
break;
|
|
10773
11408
|
}
|
|
10774
11409
|
}
|
|
10775
|
-
catch (
|
|
11410
|
+
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
10776
11411
|
finally {
|
|
10777
11412
|
try {
|
|
10778
11413
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
10779
11414
|
}
|
|
10780
|
-
finally { if (
|
|
11415
|
+
finally { if (e_20) throw e_20.error; }
|
|
10781
11416
|
}
|
|
10782
11417
|
});
|
|
10783
11418
|
if (stageChanged) {
|
|
@@ -10945,7 +11580,7 @@ function matchContainsField(value, field) {
|
|
|
10945
11580
|
});
|
|
10946
11581
|
}
|
|
10947
11582
|
function resolveAggregateCompletionFallback(pipeline) {
|
|
10948
|
-
var
|
|
11583
|
+
var e_21, _a;
|
|
10949
11584
|
if (!Array.isArray(pipeline)) {
|
|
10950
11585
|
return null;
|
|
10951
11586
|
}
|
|
@@ -10958,7 +11593,7 @@ function resolveAggregateCompletionFallback(pipeline) {
|
|
|
10958
11593
|
}
|
|
10959
11594
|
var addFields = stage.$addFields;
|
|
10960
11595
|
try {
|
|
10961
|
-
for (var _b = (
|
|
11596
|
+
for (var _b = (e_21 = void 0, __values(Object.keys(addFields))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
10962
11597
|
var key = _c.value;
|
|
10963
11598
|
if (!isCompletionFieldName(key)) {
|
|
10964
11599
|
continue;
|
|
@@ -10972,12 +11607,12 @@ function resolveAggregateCompletionFallback(pipeline) {
|
|
|
10972
11607
|
}
|
|
10973
11608
|
}
|
|
10974
11609
|
}
|
|
10975
|
-
catch (
|
|
11610
|
+
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
10976
11611
|
finally {
|
|
10977
11612
|
try {
|
|
10978
11613
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
10979
11614
|
}
|
|
10980
|
-
finally { if (
|
|
11615
|
+
finally { if (e_21) throw e_21.error; }
|
|
10981
11616
|
}
|
|
10982
11617
|
if (candidateField) {
|
|
10983
11618
|
break;
|
|
@@ -11133,7 +11768,7 @@ function buildCompletionFallbackSources(field) {
|
|
|
11133
11768
|
]);
|
|
11134
11769
|
}
|
|
11135
11770
|
function resolveAggregateCompletionExprFallback(pipeline) {
|
|
11136
|
-
var
|
|
11771
|
+
var e_22, _a;
|
|
11137
11772
|
if (!Array.isArray(pipeline)) {
|
|
11138
11773
|
return null;
|
|
11139
11774
|
}
|
|
@@ -11153,7 +11788,7 @@ function resolveAggregateCompletionExprFallback(pipeline) {
|
|
|
11153
11788
|
}
|
|
11154
11789
|
if (!candidateField) {
|
|
11155
11790
|
try {
|
|
11156
|
-
for (var _b = (
|
|
11791
|
+
for (var _b = (e_22 = void 0, __values(Object.keys(matchStage))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
11157
11792
|
var key = _c.value;
|
|
11158
11793
|
if (key.startsWith('$')) {
|
|
11159
11794
|
continue;
|
|
@@ -11168,12 +11803,12 @@ function resolveAggregateCompletionExprFallback(pipeline) {
|
|
|
11168
11803
|
}
|
|
11169
11804
|
}
|
|
11170
11805
|
}
|
|
11171
|
-
catch (
|
|
11806
|
+
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
11172
11807
|
finally {
|
|
11173
11808
|
try {
|
|
11174
11809
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
11175
11810
|
}
|
|
11176
|
-
finally { if (
|
|
11811
|
+
finally { if (e_22) throw e_22.error; }
|
|
11177
11812
|
}
|
|
11178
11813
|
}
|
|
11179
11814
|
if (!candidateField) {
|
|
@@ -11281,7 +11916,7 @@ function resolveAssistantAggregateDimensionFieldHints(pipeline) {
|
|
|
11281
11916
|
}
|
|
11282
11917
|
hints.push(normalized);
|
|
11283
11918
|
};
|
|
11284
|
-
var
|
|
11919
|
+
var _loop_10 = function (index) {
|
|
11285
11920
|
var stage = pipeline[index];
|
|
11286
11921
|
if (!stage || typeof stage !== 'object' || Array.isArray(stage) || !stage.$project || typeof stage.$project !== 'object') {
|
|
11287
11922
|
return "continue";
|
|
@@ -11302,7 +11937,7 @@ function resolveAssistantAggregateDimensionFieldHints(pipeline) {
|
|
|
11302
11937
|
});
|
|
11303
11938
|
};
|
|
11304
11939
|
for (var index = groupIndex + 1; index < pipeline.length; index += 1) {
|
|
11305
|
-
|
|
11940
|
+
_loop_10(index);
|
|
11306
11941
|
}
|
|
11307
11942
|
return hints.slice(0, 6);
|
|
11308
11943
|
}
|
|
@@ -11375,7 +12010,7 @@ function hasAssistantDateGroupingOperator(value) {
|
|
|
11375
12010
|
return Object.keys(value).some(function (key) { return hasAssistantDateGroupingOperator(value[key]); });
|
|
11376
12011
|
}
|
|
11377
12012
|
function isGroupFieldDerivedFromDateExpression(pipeline, groupIndex, groupPaths) {
|
|
11378
|
-
var
|
|
12013
|
+
var e_23, _a, e_24, _b;
|
|
11379
12014
|
if (!Array.isArray(pipeline) || groupIndex <= 0 || !groupPaths.length) {
|
|
11380
12015
|
return false;
|
|
11381
12016
|
}
|
|
@@ -11401,14 +12036,14 @@ function isGroupFieldDerivedFromDateExpression(pipeline, groupIndex, groupPaths)
|
|
|
11401
12036
|
continue;
|
|
11402
12037
|
}
|
|
11403
12038
|
try {
|
|
11404
|
-
for (var stageKeys_1 = (
|
|
12039
|
+
for (var stageKeys_1 = (e_23 = void 0, __values(stageKeys)), stageKeys_1_1 = stageKeys_1.next(); !stageKeys_1_1.done; stageKeys_1_1 = stageKeys_1.next()) {
|
|
11405
12040
|
var stageKey = stageKeys_1_1.value;
|
|
11406
12041
|
var payload = stage[stageKey];
|
|
11407
12042
|
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
11408
12043
|
continue;
|
|
11409
12044
|
}
|
|
11410
12045
|
try {
|
|
11411
|
-
for (var groupFields_1 = (
|
|
12046
|
+
for (var groupFields_1 = (e_24 = void 0, __values(groupFields)), groupFields_1_1 = groupFields_1.next(); !groupFields_1_1.done; groupFields_1_1 = groupFields_1.next()) {
|
|
11412
12047
|
var groupField = groupFields_1_1.value;
|
|
11413
12048
|
if (!Object.prototype.hasOwnProperty.call(payload, groupField)) {
|
|
11414
12049
|
continue;
|
|
@@ -11418,21 +12053,21 @@ function isGroupFieldDerivedFromDateExpression(pipeline, groupIndex, groupPaths)
|
|
|
11418
12053
|
}
|
|
11419
12054
|
}
|
|
11420
12055
|
}
|
|
11421
|
-
catch (
|
|
12056
|
+
catch (e_24_1) { e_24 = { error: e_24_1 }; }
|
|
11422
12057
|
finally {
|
|
11423
12058
|
try {
|
|
11424
12059
|
if (groupFields_1_1 && !groupFields_1_1.done && (_b = groupFields_1.return)) _b.call(groupFields_1);
|
|
11425
12060
|
}
|
|
11426
|
-
finally { if (
|
|
12061
|
+
finally { if (e_24) throw e_24.error; }
|
|
11427
12062
|
}
|
|
11428
12063
|
}
|
|
11429
12064
|
}
|
|
11430
|
-
catch (
|
|
12065
|
+
catch (e_23_1) { e_23 = { error: e_23_1 }; }
|
|
11431
12066
|
finally {
|
|
11432
12067
|
try {
|
|
11433
12068
|
if (stageKeys_1_1 && !stageKeys_1_1.done && (_a = stageKeys_1.return)) _a.call(stageKeys_1);
|
|
11434
12069
|
}
|
|
11435
|
-
finally { if (
|
|
12070
|
+
finally { if (e_23) throw e_23.error; }
|
|
11436
12071
|
}
|
|
11437
12072
|
}
|
|
11438
12073
|
return false;
|
|
@@ -11539,7 +12174,7 @@ function isRegexMatchCondition(value) {
|
|
|
11539
12174
|
return false;
|
|
11540
12175
|
}
|
|
11541
12176
|
function findRegexMatchInMatchObject(match, prefix) {
|
|
11542
|
-
var
|
|
12177
|
+
var e_25, _a, e_26, _b;
|
|
11543
12178
|
if (prefix === void 0) { prefix = ''; }
|
|
11544
12179
|
if (Array.isArray(match)) {
|
|
11545
12180
|
try {
|
|
@@ -11551,12 +12186,12 @@ function findRegexMatchInMatchObject(match, prefix) {
|
|
|
11551
12186
|
}
|
|
11552
12187
|
}
|
|
11553
12188
|
}
|
|
11554
|
-
catch (
|
|
12189
|
+
catch (e_25_1) { e_25 = { error: e_25_1 }; }
|
|
11555
12190
|
finally {
|
|
11556
12191
|
try {
|
|
11557
12192
|
if (match_1_1 && !match_1_1.done && (_a = match_1.return)) _a.call(match_1);
|
|
11558
12193
|
}
|
|
11559
|
-
finally { if (
|
|
12194
|
+
finally { if (e_25) throw e_25.error; }
|
|
11560
12195
|
}
|
|
11561
12196
|
return null;
|
|
11562
12197
|
}
|
|
@@ -11587,12 +12222,12 @@ function findRegexMatchInMatchObject(match, prefix) {
|
|
|
11587
12222
|
}
|
|
11588
12223
|
}
|
|
11589
12224
|
}
|
|
11590
|
-
catch (
|
|
12225
|
+
catch (e_26_1) { e_26 = { error: e_26_1 }; }
|
|
11591
12226
|
finally {
|
|
11592
12227
|
try {
|
|
11593
12228
|
if (keys_2_1 && !keys_2_1.done && (_b = keys_2.return)) _b.call(keys_2);
|
|
11594
12229
|
}
|
|
11595
|
-
finally { if (
|
|
12230
|
+
finally { if (e_26) throw e_26.error; }
|
|
11596
12231
|
}
|
|
11597
12232
|
return null;
|
|
11598
12233
|
}
|
|
@@ -11816,7 +12451,7 @@ function collectMatchFieldsByCondition(match, predicate, prefix) {
|
|
|
11816
12451
|
return results;
|
|
11817
12452
|
}
|
|
11818
12453
|
function findMatchConditionForField(match, targetField, prefix) {
|
|
11819
|
-
var
|
|
12454
|
+
var e_27, _a, e_28, _b;
|
|
11820
12455
|
if (prefix === void 0) { prefix = ''; }
|
|
11821
12456
|
if (!match || typeof match !== 'object') {
|
|
11822
12457
|
return undefined;
|
|
@@ -11831,12 +12466,12 @@ function findMatchConditionForField(match, targetField, prefix) {
|
|
|
11831
12466
|
}
|
|
11832
12467
|
}
|
|
11833
12468
|
}
|
|
11834
|
-
catch (
|
|
12469
|
+
catch (e_27_1) { e_27 = { error: e_27_1 }; }
|
|
11835
12470
|
finally {
|
|
11836
12471
|
try {
|
|
11837
12472
|
if (match_2_1 && !match_2_1.done && (_a = match_2.return)) _a.call(match_2);
|
|
11838
12473
|
}
|
|
11839
|
-
finally { if (
|
|
12474
|
+
finally { if (e_27) throw e_27.error; }
|
|
11840
12475
|
}
|
|
11841
12476
|
return undefined;
|
|
11842
12477
|
}
|
|
@@ -11863,12 +12498,12 @@ function findMatchConditionForField(match, targetField, prefix) {
|
|
|
11863
12498
|
}
|
|
11864
12499
|
}
|
|
11865
12500
|
}
|
|
11866
|
-
catch (
|
|
12501
|
+
catch (e_28_1) { e_28 = { error: e_28_1 }; }
|
|
11867
12502
|
finally {
|
|
11868
12503
|
try {
|
|
11869
12504
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
11870
12505
|
}
|
|
11871
|
-
finally { if (
|
|
12506
|
+
finally { if (e_28) throw e_28.error; }
|
|
11872
12507
|
}
|
|
11873
12508
|
return undefined;
|
|
11874
12509
|
}
|
|
@@ -12014,7 +12649,7 @@ function detectIdLikeValue(value) {
|
|
|
12014
12649
|
return false;
|
|
12015
12650
|
}
|
|
12016
12651
|
function detectChemicalIdFromProbe(probeDocs, fields) {
|
|
12017
|
-
var
|
|
12652
|
+
var e_29, _a, e_30, _b;
|
|
12018
12653
|
if (!Array.isArray(probeDocs) || !probeDocs.length) {
|
|
12019
12654
|
return false;
|
|
12020
12655
|
}
|
|
@@ -12026,7 +12661,7 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
|
|
|
12026
12661
|
for (var probeDocs_1 = __values(probeDocs), probeDocs_1_1 = probeDocs_1.next(); !probeDocs_1_1.done; probeDocs_1_1 = probeDocs_1.next()) {
|
|
12027
12662
|
var doc = probeDocs_1_1.value;
|
|
12028
12663
|
try {
|
|
12029
|
-
for (var targets_1 = (
|
|
12664
|
+
for (var targets_1 = (e_30 = void 0, __values(targets)), targets_1_1 = targets_1.next(); !targets_1_1.done; targets_1_1 = targets_1.next()) {
|
|
12030
12665
|
var field = targets_1_1.value;
|
|
12031
12666
|
var value = getValueAtPath(doc, field);
|
|
12032
12667
|
if (Array.isArray(value)) {
|
|
@@ -12039,21 +12674,21 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
|
|
|
12039
12674
|
}
|
|
12040
12675
|
}
|
|
12041
12676
|
}
|
|
12042
|
-
catch (
|
|
12677
|
+
catch (e_30_1) { e_30 = { error: e_30_1 }; }
|
|
12043
12678
|
finally {
|
|
12044
12679
|
try {
|
|
12045
12680
|
if (targets_1_1 && !targets_1_1.done && (_b = targets_1.return)) _b.call(targets_1);
|
|
12046
12681
|
}
|
|
12047
|
-
finally { if (
|
|
12682
|
+
finally { if (e_30) throw e_30.error; }
|
|
12048
12683
|
}
|
|
12049
12684
|
}
|
|
12050
12685
|
}
|
|
12051
|
-
catch (
|
|
12686
|
+
catch (e_29_1) { e_29 = { error: e_29_1 }; }
|
|
12052
12687
|
finally {
|
|
12053
12688
|
try {
|
|
12054
12689
|
if (probeDocs_1_1 && !probeDocs_1_1.done && (_a = probeDocs_1.return)) _a.call(probeDocs_1);
|
|
12055
12690
|
}
|
|
12056
|
-
finally { if (
|
|
12691
|
+
finally { if (e_29) throw e_29.error; }
|
|
12057
12692
|
}
|
|
12058
12693
|
return false;
|
|
12059
12694
|
}
|
|
@@ -12274,8 +12909,8 @@ function buildChemicalIdFieldCandidates(field) {
|
|
|
12274
12909
|
}
|
|
12275
12910
|
function applyChemicalNameLookupFallbackToQuery(params) {
|
|
12276
12911
|
return __awaiter(this, void 0, void 0, function () {
|
|
12277
|
-
var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, chemicalFields, targetField, condition, regex, sampleDocs, collectionNames, candidates,
|
|
12278
|
-
var
|
|
12912
|
+
var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, chemicalFields, targetField, condition, regex, sampleDocs, collectionNames, candidates, _loop_11, candidates_1, candidates_1_1, candidate, state_8, e_31_1;
|
|
12913
|
+
var e_31, _a;
|
|
12279
12914
|
var _b;
|
|
12280
12915
|
return __generator(this, function (_c) {
|
|
12281
12916
|
switch (_c.label) {
|
|
@@ -12299,7 +12934,7 @@ function applyChemicalNameLookupFallbackToQuery(params) {
|
|
|
12299
12934
|
case 1:
|
|
12300
12935
|
collectionNames = _c.sent();
|
|
12301
12936
|
candidates = resolveIdLookupCandidates('chemical', collectionNames);
|
|
12302
|
-
|
|
12937
|
+
_loop_11 = function (candidate) {
|
|
12303
12938
|
var candidateHasClientScope, _d, candidateProbe, lookup, idFields, baseMatch, orConditions, nextMatch;
|
|
12304
12939
|
return __generator(this, function (_e) {
|
|
12305
12940
|
switch (_e.label) {
|
|
@@ -12377,25 +13012,25 @@ function applyChemicalNameLookupFallbackToQuery(params) {
|
|
|
12377
13012
|
case 3:
|
|
12378
13013
|
if (!!candidates_1_1.done) return [3 /*break*/, 6];
|
|
12379
13014
|
candidate = candidates_1_1.value;
|
|
12380
|
-
return [5 /*yield**/,
|
|
13015
|
+
return [5 /*yield**/, _loop_11(candidate)];
|
|
12381
13016
|
case 4:
|
|
12382
|
-
|
|
12383
|
-
if (typeof
|
|
12384
|
-
return [2 /*return*/,
|
|
13017
|
+
state_8 = _c.sent();
|
|
13018
|
+
if (typeof state_8 === "object")
|
|
13019
|
+
return [2 /*return*/, state_8.value];
|
|
12385
13020
|
_c.label = 5;
|
|
12386
13021
|
case 5:
|
|
12387
13022
|
candidates_1_1 = candidates_1.next();
|
|
12388
13023
|
return [3 /*break*/, 3];
|
|
12389
13024
|
case 6: return [3 /*break*/, 9];
|
|
12390
13025
|
case 7:
|
|
12391
|
-
|
|
12392
|
-
|
|
13026
|
+
e_31_1 = _c.sent();
|
|
13027
|
+
e_31 = { error: e_31_1 };
|
|
12393
13028
|
return [3 /*break*/, 9];
|
|
12394
13029
|
case 8:
|
|
12395
13030
|
try {
|
|
12396
13031
|
if (candidates_1_1 && !candidates_1_1.done && (_a = candidates_1.return)) _a.call(candidates_1);
|
|
12397
13032
|
}
|
|
12398
|
-
finally { if (
|
|
13033
|
+
finally { if (e_31) throw e_31.error; }
|
|
12399
13034
|
return [7 /*endfinally*/];
|
|
12400
13035
|
case 9: return [2 /*return*/, null];
|
|
12401
13036
|
}
|
|
@@ -12489,8 +13124,8 @@ function lookupIdsForNameMatch(params) {
|
|
|
12489
13124
|
}
|
|
12490
13125
|
function applyIdLookupFallbackToQuery(params) {
|
|
12491
13126
|
return __awaiter(this, void 0, void 0, function () {
|
|
12492
|
-
var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, conditions, collectionNames, _a, conditions_1, conditions_1_1, condition, regex, baseToken, targetFieldType, nextValue, localNameField, candidates, candidates_2, candidates_2_1, candidate, candidateHasClientScope, _b, candidateProbe, lookup, targetFieldType, normalizedIds, idsForQuery,
|
|
12493
|
-
var
|
|
13127
|
+
var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, conditions, collectionNames, _a, conditions_1, conditions_1_1, condition, regex, baseToken, targetFieldType, nextValue, localNameField, candidates, candidates_2, candidates_2_1, candidate, candidateHasClientScope, _b, candidateProbe, lookup, targetFieldType, normalizedIds, idsForQuery, e_32_1, e_33_1;
|
|
13128
|
+
var e_33, _c, e_32, _d;
|
|
12494
13129
|
var _e;
|
|
12495
13130
|
return __generator(this, function (_f) {
|
|
12496
13131
|
switch (_f.label) {
|
|
@@ -12560,7 +13195,7 @@ function applyIdLookupFallbackToQuery(params) {
|
|
|
12560
13195
|
_f.label = 5;
|
|
12561
13196
|
case 5:
|
|
12562
13197
|
_f.trys.push([5, 14, 15, 16]);
|
|
12563
|
-
candidates_2 = (
|
|
13198
|
+
candidates_2 = (e_32 = void 0, __values(candidates)), candidates_2_1 = candidates_2.next();
|
|
12564
13199
|
_f.label = 6;
|
|
12565
13200
|
case 6:
|
|
12566
13201
|
if (!!candidates_2_1.done) return [3 /*break*/, 13];
|
|
@@ -12627,28 +13262,28 @@ function applyIdLookupFallbackToQuery(params) {
|
|
|
12627
13262
|
return [3 /*break*/, 6];
|
|
12628
13263
|
case 13: return [3 /*break*/, 16];
|
|
12629
13264
|
case 14:
|
|
12630
|
-
|
|
12631
|
-
|
|
13265
|
+
e_32_1 = _f.sent();
|
|
13266
|
+
e_32 = { error: e_32_1 };
|
|
12632
13267
|
return [3 /*break*/, 16];
|
|
12633
13268
|
case 15:
|
|
12634
13269
|
try {
|
|
12635
13270
|
if (candidates_2_1 && !candidates_2_1.done && (_d = candidates_2.return)) _d.call(candidates_2);
|
|
12636
13271
|
}
|
|
12637
|
-
finally { if (
|
|
13272
|
+
finally { if (e_32) throw e_32.error; }
|
|
12638
13273
|
return [7 /*endfinally*/];
|
|
12639
13274
|
case 16:
|
|
12640
13275
|
conditions_1_1 = conditions_1.next();
|
|
12641
13276
|
return [3 /*break*/, 4];
|
|
12642
13277
|
case 17: return [3 /*break*/, 20];
|
|
12643
13278
|
case 18:
|
|
12644
|
-
|
|
12645
|
-
|
|
13279
|
+
e_33_1 = _f.sent();
|
|
13280
|
+
e_33 = { error: e_33_1 };
|
|
12646
13281
|
return [3 /*break*/, 20];
|
|
12647
13282
|
case 19:
|
|
12648
13283
|
try {
|
|
12649
13284
|
if (conditions_1_1 && !conditions_1_1.done && (_c = conditions_1.return)) _c.call(conditions_1);
|
|
12650
13285
|
}
|
|
12651
|
-
finally { if (
|
|
13286
|
+
finally { if (e_33) throw e_33.error; }
|
|
12652
13287
|
return [7 /*endfinally*/];
|
|
12653
13288
|
case 20: return [2 /*return*/, null];
|
|
12654
13289
|
}
|
|
@@ -13071,8 +13706,8 @@ function resolveAssistantSurfaceFileCandidates(baseName) {
|
|
|
13071
13706
|
}
|
|
13072
13707
|
function readFirstAssistantSurfaceFile(candidates) {
|
|
13073
13708
|
return __awaiter(this, void 0, void 0, function () {
|
|
13074
|
-
var candidates_3, candidates_3_1, candidate, normalized, _a,
|
|
13075
|
-
var
|
|
13709
|
+
var candidates_3, candidates_3_1, candidate, normalized, _a, e_34_1;
|
|
13710
|
+
var e_34, _b;
|
|
13076
13711
|
return __generator(this, function (_c) {
|
|
13077
13712
|
switch (_c.label) {
|
|
13078
13713
|
case 0:
|
|
@@ -13099,14 +13734,14 @@ function readFirstAssistantSurfaceFile(candidates) {
|
|
|
13099
13734
|
return [3 /*break*/, 1];
|
|
13100
13735
|
case 6: return [3 /*break*/, 9];
|
|
13101
13736
|
case 7:
|
|
13102
|
-
|
|
13103
|
-
|
|
13737
|
+
e_34_1 = _c.sent();
|
|
13738
|
+
e_34 = { error: e_34_1 };
|
|
13104
13739
|
return [3 /*break*/, 9];
|
|
13105
13740
|
case 8:
|
|
13106
13741
|
try {
|
|
13107
13742
|
if (candidates_3_1 && !candidates_3_1.done && (_b = candidates_3.return)) _b.call(candidates_3);
|
|
13108
13743
|
}
|
|
13109
|
-
finally { if (
|
|
13744
|
+
finally { if (e_34) throw e_34.error; }
|
|
13110
13745
|
return [7 /*endfinally*/];
|
|
13111
13746
|
case 9: return [2 /*return*/, ''];
|
|
13112
13747
|
}
|
|
@@ -14180,7 +14815,10 @@ var AI_ASSISTANT_BRIDGE_COLLECTION_ALIAS_OPTIONS = {
|
|
|
14180
14815
|
purchaseorder: AI_ASSISTANT_PURCHASE_COLLECTION_ALIAS_CANDIDATES,
|
|
14181
14816
|
purchaseorders: AI_ASSISTANT_PURCHASE_COLLECTION_ALIAS_CANDIDATES
|
|
14182
14817
|
};
|
|
14183
|
-
var AI_ASSISTANT_DIRECT_COLLECTION_FALLBACK_ALLOWLIST = new Set([
|
|
14818
|
+
var AI_ASSISTANT_DIRECT_COLLECTION_FALLBACK_ALLOWLIST = new Set([
|
|
14819
|
+
'customers',
|
|
14820
|
+
'clients'
|
|
14821
|
+
]);
|
|
14184
14822
|
var AI_ASSISTANT_SUPPORT_COLLECTION_FALLBACKS = [
|
|
14185
14823
|
'support-tickets',
|
|
14186
14824
|
'supporttickets',
|
|
@@ -14330,7 +14968,7 @@ function resolveAssistantRelationshipFallbackCandidates(collection, collectionNa
|
|
|
14330
14968
|
var depthByFamily = new Map();
|
|
14331
14969
|
var queue = [{ family: currentFamily, depth: 0 }];
|
|
14332
14970
|
depthByFamily.set(currentFamily, 0);
|
|
14333
|
-
var
|
|
14971
|
+
var _loop_12 = function () {
|
|
14334
14972
|
var current = queue.shift();
|
|
14335
14973
|
if (!current) {
|
|
14336
14974
|
return "continue";
|
|
@@ -14363,7 +15001,7 @@ function resolveAssistantRelationshipFallbackCandidates(collection, collectionNa
|
|
|
14363
15001
|
});
|
|
14364
15002
|
};
|
|
14365
15003
|
while (queue.length) {
|
|
14366
|
-
|
|
15004
|
+
_loop_12();
|
|
14367
15005
|
}
|
|
14368
15006
|
var preferredCollections = Array.from(familyScores.entries())
|
|
14369
15007
|
.map(function (_a) {
|
|
@@ -14851,7 +15489,7 @@ function resolveAssistantNestedPrefixCollectionCandidates(params) {
|
|
|
14851
15489
|
function resolveAssistantNestedAggregateFallbacks(params) {
|
|
14852
15490
|
return __awaiter(this, void 0, void 0, function () {
|
|
14853
15491
|
var prefixes, collectionNames, fallbacks, seen, prefixes_1, prefixes_1_1, prefix, rewrite, candidates, candidates_4, candidates_4_1, candidate, normalizedPipeline, key;
|
|
14854
|
-
var
|
|
15492
|
+
var e_35, _a, e_36, _b;
|
|
14855
15493
|
return __generator(this, function (_c) {
|
|
14856
15494
|
switch (_c.label) {
|
|
14857
15495
|
case 0:
|
|
@@ -14881,7 +15519,7 @@ function resolveAssistantNestedAggregateFallbacks(params) {
|
|
|
14881
15519
|
triedCollections: params.triedCollections
|
|
14882
15520
|
});
|
|
14883
15521
|
try {
|
|
14884
|
-
for (candidates_4 = (
|
|
15522
|
+
for (candidates_4 = (e_36 = void 0, __values(candidates)), candidates_4_1 = candidates_4.next(); !candidates_4_1.done; candidates_4_1 = candidates_4.next()) {
|
|
14885
15523
|
candidate = candidates_4_1.value;
|
|
14886
15524
|
normalizedPipeline = normalizeAssistantAggregatePipeline(rewrite.pipeline, candidate);
|
|
14887
15525
|
if (!normalizedPipeline.length || containsForbiddenMongoOperators(normalizedPipeline)) {
|
|
@@ -14903,21 +15541,21 @@ function resolveAssistantNestedAggregateFallbacks(params) {
|
|
|
14903
15541
|
}
|
|
14904
15542
|
}
|
|
14905
15543
|
}
|
|
14906
|
-
catch (
|
|
15544
|
+
catch (e_36_1) { e_36 = { error: e_36_1 }; }
|
|
14907
15545
|
finally {
|
|
14908
15546
|
try {
|
|
14909
15547
|
if (candidates_4_1 && !candidates_4_1.done && (_b = candidates_4.return)) _b.call(candidates_4);
|
|
14910
15548
|
}
|
|
14911
|
-
finally { if (
|
|
15549
|
+
finally { if (e_36) throw e_36.error; }
|
|
14912
15550
|
}
|
|
14913
15551
|
}
|
|
14914
15552
|
}
|
|
14915
|
-
catch (
|
|
15553
|
+
catch (e_35_1) { e_35 = { error: e_35_1 }; }
|
|
14916
15554
|
finally {
|
|
14917
15555
|
try {
|
|
14918
15556
|
if (prefixes_1_1 && !prefixes_1_1.done && (_a = prefixes_1.return)) _a.call(prefixes_1);
|
|
14919
15557
|
}
|
|
14920
|
-
finally { if (
|
|
15558
|
+
finally { if (e_35) throw e_35.error; }
|
|
14921
15559
|
}
|
|
14922
15560
|
return [2 /*return*/, fallbacks];
|
|
14923
15561
|
}
|
|
@@ -14979,8 +15617,8 @@ function doesAssistantCollectionExistInDb(db, collection) {
|
|
|
14979
15617
|
}
|
|
14980
15618
|
function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
14981
15619
|
return __awaiter(this, arguments, void 0, function (collection, db, dbName) {
|
|
14982
|
-
var normalized, aliasCandidates, alias, manager, hasManager, candidates, pushCandidate, base, reportCandidate, candidates_5, candidates_5_1, candidate, model, resolved, resolvedName, resolvedModel, _a, candidates_6, candidates_6_1, candidate,
|
|
14983
|
-
var
|
|
15620
|
+
var normalized, aliasCandidates, alias, manager, hasManager, candidates, pushCandidate, base, reportCandidate, candidates_5, candidates_5_1, candidate, model, resolved, resolvedName, resolvedModel, _a, candidates_6, candidates_6_1, candidate, e_37_1, candidates_7, candidates_7_1, candidate;
|
|
15621
|
+
var e_38, _b, e_37, _c, e_39, _d;
|
|
14984
15622
|
var _e;
|
|
14985
15623
|
if (dbName === void 0) { dbName = ''; }
|
|
14986
15624
|
return __generator(this, function (_f) {
|
|
@@ -15022,12 +15660,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
15022
15660
|
}
|
|
15023
15661
|
}
|
|
15024
15662
|
}
|
|
15025
|
-
catch (
|
|
15663
|
+
catch (e_38_1) { e_38 = { error: e_38_1 }; }
|
|
15026
15664
|
finally {
|
|
15027
15665
|
try {
|
|
15028
15666
|
if (candidates_5_1 && !candidates_5_1.done && (_b = candidates_5.return)) _b.call(candidates_5);
|
|
15029
15667
|
}
|
|
15030
|
-
finally { if (
|
|
15668
|
+
finally { if (e_38) throw e_38.error; }
|
|
15031
15669
|
}
|
|
15032
15670
|
}
|
|
15033
15671
|
if (!(db && dbName)) return [3 /*break*/, 4];
|
|
@@ -15073,14 +15711,14 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
15073
15711
|
return [3 /*break*/, 6];
|
|
15074
15712
|
case 9: return [3 /*break*/, 12];
|
|
15075
15713
|
case 10:
|
|
15076
|
-
|
|
15077
|
-
|
|
15714
|
+
e_37_1 = _f.sent();
|
|
15715
|
+
e_37 = { error: e_37_1 };
|
|
15078
15716
|
return [3 /*break*/, 12];
|
|
15079
15717
|
case 11:
|
|
15080
15718
|
try {
|
|
15081
15719
|
if (candidates_6_1 && !candidates_6_1.done && (_c = candidates_6.return)) _c.call(candidates_6);
|
|
15082
15720
|
}
|
|
15083
|
-
finally { if (
|
|
15721
|
+
finally { if (e_37) throw e_37.error; }
|
|
15084
15722
|
return [7 /*endfinally*/];
|
|
15085
15723
|
case 12:
|
|
15086
15724
|
try {
|
|
@@ -15091,12 +15729,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
15091
15729
|
}
|
|
15092
15730
|
}
|
|
15093
15731
|
}
|
|
15094
|
-
catch (
|
|
15732
|
+
catch (e_39_1) { e_39 = { error: e_39_1 }; }
|
|
15095
15733
|
finally {
|
|
15096
15734
|
try {
|
|
15097
15735
|
if (candidates_7_1 && !candidates_7_1.done && (_d = candidates_7.return)) _d.call(candidates_7);
|
|
15098
15736
|
}
|
|
15099
|
-
finally { if (
|
|
15737
|
+
finally { if (e_39) throw e_39.error; }
|
|
15100
15738
|
}
|
|
15101
15739
|
throw new Error('AI assistant report builder bridge: No queryable collection could be resolved.');
|
|
15102
15740
|
}
|
|
@@ -15104,7 +15742,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
15104
15742
|
});
|
|
15105
15743
|
}
|
|
15106
15744
|
function findQueryDateField(query) {
|
|
15107
|
-
var
|
|
15745
|
+
var e_40, _a, e_41, _b;
|
|
15108
15746
|
if (!query || typeof query !== 'object') {
|
|
15109
15747
|
return null;
|
|
15110
15748
|
}
|
|
@@ -15118,12 +15756,12 @@ function findQueryDateField(query) {
|
|
|
15118
15756
|
}
|
|
15119
15757
|
}
|
|
15120
15758
|
}
|
|
15121
|
-
catch (
|
|
15759
|
+
catch (e_40_1) { e_40 = { error: e_40_1 }; }
|
|
15122
15760
|
finally {
|
|
15123
15761
|
try {
|
|
15124
15762
|
if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
|
|
15125
15763
|
}
|
|
15126
|
-
finally { if (
|
|
15764
|
+
finally { if (e_40) throw e_40.error; }
|
|
15127
15765
|
}
|
|
15128
15766
|
return null;
|
|
15129
15767
|
}
|
|
@@ -15142,12 +15780,12 @@ function findQueryDateField(query) {
|
|
|
15142
15780
|
}
|
|
15143
15781
|
}
|
|
15144
15782
|
}
|
|
15145
|
-
catch (
|
|
15783
|
+
catch (e_41_1) { e_41 = { error: e_41_1 }; }
|
|
15146
15784
|
finally {
|
|
15147
15785
|
try {
|
|
15148
15786
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
15149
15787
|
}
|
|
15150
|
-
finally { if (
|
|
15788
|
+
finally { if (e_41) throw e_41.error; }
|
|
15151
15789
|
}
|
|
15152
15790
|
return null;
|
|
15153
15791
|
}
|
|
@@ -15330,7 +15968,7 @@ function expandAggregateDateMatchFallback(pipeline, schemaFields) {
|
|
|
15330
15968
|
if (!Array.isArray(pipeline)) {
|
|
15331
15969
|
return null;
|
|
15332
15970
|
}
|
|
15333
|
-
var
|
|
15971
|
+
var _loop_13 = function (i) {
|
|
15334
15972
|
var stage = pipeline[i];
|
|
15335
15973
|
if (!stage || typeof stage !== 'object' || !stage.$match || typeof stage.$match !== 'object') {
|
|
15336
15974
|
return "continue";
|
|
@@ -15378,9 +16016,9 @@ function expandAggregateDateMatchFallback(pipeline, schemaFields) {
|
|
|
15378
16016
|
return { value: { pipeline: updated, fields: Array.from(addedFields) } };
|
|
15379
16017
|
};
|
|
15380
16018
|
for (var i = 0; i < pipeline.length; i += 1) {
|
|
15381
|
-
var
|
|
15382
|
-
if (typeof
|
|
15383
|
-
return
|
|
16019
|
+
var state_9 = _loop_13(i);
|
|
16020
|
+
if (typeof state_9 === "object")
|
|
16021
|
+
return state_9.value;
|
|
15384
16022
|
}
|
|
15385
16023
|
return null;
|
|
15386
16024
|
}
|
|
@@ -15396,7 +16034,7 @@ function resolveQueryDateFieldFallback(query) {
|
|
|
15396
16034
|
return { from: dateField, to: fallback };
|
|
15397
16035
|
}
|
|
15398
16036
|
function containsForbiddenMongoOperators(value) {
|
|
15399
|
-
var
|
|
16037
|
+
var e_42, _a;
|
|
15400
16038
|
if (!value || typeof value !== 'object') {
|
|
15401
16039
|
return false;
|
|
15402
16040
|
}
|
|
@@ -15415,12 +16053,12 @@ function containsForbiddenMongoOperators(value) {
|
|
|
15415
16053
|
}
|
|
15416
16054
|
}
|
|
15417
16055
|
}
|
|
15418
|
-
catch (
|
|
16056
|
+
catch (e_42_1) { e_42 = { error: e_42_1 }; }
|
|
15419
16057
|
finally {
|
|
15420
16058
|
try {
|
|
15421
16059
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
15422
16060
|
}
|
|
15423
|
-
finally { if (
|
|
16061
|
+
finally { if (e_42) throw e_42.error; }
|
|
15424
16062
|
}
|
|
15425
16063
|
return false;
|
|
15426
16064
|
}
|
|
@@ -15835,8 +16473,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
|
|
|
15835
16473
|
}
|
|
15836
16474
|
function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
15837
16475
|
return __awaiter(this, void 0, void 0, function () {
|
|
15838
|
-
var _a, _b, _c, _d, message, payload, status_1,
|
|
15839
|
-
var _e,
|
|
16476
|
+
var _a, _b, _c, _d, message, payload, status_1, e_43_1;
|
|
16477
|
+
var _e, e_43, _f, _g;
|
|
15840
16478
|
return __generator(this, function (_h) {
|
|
15841
16479
|
switch (_h.label) {
|
|
15842
16480
|
case 0:
|
|
@@ -15863,8 +16501,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
15863
16501
|
return [3 /*break*/, 1];
|
|
15864
16502
|
case 4: return [3 /*break*/, 11];
|
|
15865
16503
|
case 5:
|
|
15866
|
-
|
|
15867
|
-
|
|
16504
|
+
e_43_1 = _h.sent();
|
|
16505
|
+
e_43 = { error: e_43_1 };
|
|
15868
16506
|
return [3 /*break*/, 11];
|
|
15869
16507
|
case 6:
|
|
15870
16508
|
_h.trys.push([6, , 9, 10]);
|
|
@@ -15875,7 +16513,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
15875
16513
|
_h.label = 8;
|
|
15876
16514
|
case 8: return [3 /*break*/, 10];
|
|
15877
16515
|
case 9:
|
|
15878
|
-
if (
|
|
16516
|
+
if (e_43) throw e_43.error;
|
|
15879
16517
|
return [7 /*endfinally*/];
|
|
15880
16518
|
case 10: return [7 /*endfinally*/];
|
|
15881
16519
|
case 11: throw new CodexWorkerBootstrapError('Codex worker exited before completing.');
|
|
@@ -15885,7 +16523,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
15885
16523
|
}
|
|
15886
16524
|
function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler) {
|
|
15887
16525
|
return __awaiter(this, void 0, void 0, function () {
|
|
15888
|
-
var streamedOptions, codexClient, workerPath, codexClient,
|
|
16526
|
+
var streamedOptions, codexClient, workerPath, codexClient, error_10, codexClient;
|
|
15889
16527
|
return __generator(this, function (_a) {
|
|
15890
16528
|
switch (_a.label) {
|
|
15891
16529
|
case 0:
|
|
@@ -15906,11 +16544,11 @@ function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler)
|
|
|
15906
16544
|
return [4 /*yield*/, runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config, streamStatusHandler)];
|
|
15907
16545
|
case 6: return [2 /*return*/, _a.sent()];
|
|
15908
16546
|
case 7:
|
|
15909
|
-
|
|
15910
|
-
if (!(
|
|
15911
|
-
throw
|
|
16547
|
+
error_10 = _a.sent();
|
|
16548
|
+
if (!(error_10 instanceof CodexWorkerBootstrapError)) {
|
|
16549
|
+
throw error_10;
|
|
15912
16550
|
}
|
|
15913
|
-
console.error('Codex worker bootstrap failed, falling back to in-process run.',
|
|
16551
|
+
console.error('Codex worker bootstrap failed, falling back to in-process run.', error_10);
|
|
15914
16552
|
codexClient = getAssistantCodexClient(config);
|
|
15915
16553
|
return [4 /*yield*/, codexClient.run(prompt, streamedOptions)];
|
|
15916
16554
|
case 8: return [2 /*return*/, _a.sent()];
|
|
@@ -15948,7 +16586,7 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
15948
16586
|
timeoutMs = ((sanitizedOptions === null || sanitizedOptions === void 0 ? void 0 : sanitizedOptions.timeoutMs) || resolveCodexTimeoutMs()) + 15000;
|
|
15949
16587
|
timeoutController = new AbortController();
|
|
15950
16588
|
timeoutPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
15951
|
-
var
|
|
16589
|
+
var error_11;
|
|
15952
16590
|
return __generator(this, function (_a) {
|
|
15953
16591
|
switch (_a.label) {
|
|
15954
16592
|
case 0:
|
|
@@ -15958,11 +16596,11 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
15958
16596
|
_a.sent();
|
|
15959
16597
|
return [2 /*return*/, { type: 'timeout' }];
|
|
15960
16598
|
case 2:
|
|
15961
|
-
|
|
15962
|
-
if ((
|
|
16599
|
+
error_11 = _a.sent();
|
|
16600
|
+
if ((error_11 === null || error_11 === void 0 ? void 0 : error_11.name) === 'AbortError') {
|
|
15963
16601
|
return [2 /*return*/, { type: 'aborted' }];
|
|
15964
16602
|
}
|
|
15965
|
-
throw
|
|
16603
|
+
throw error_11;
|
|
15966
16604
|
case 3: return [2 /*return*/];
|
|
15967
16605
|
}
|
|
15968
16606
|
});
|
|
@@ -16207,8 +16845,8 @@ function buildAssistantWorkspaceRootCandidates(params) {
|
|
|
16207
16845
|
}
|
|
16208
16846
|
function resolveAssistantWorkspaceRoot() {
|
|
16209
16847
|
return __awaiter(this, void 0, void 0, function () {
|
|
16210
|
-
var candidates, firstExisting, candidates_8, candidates_8_1, candidate, _a, gitRoot,
|
|
16211
|
-
var
|
|
16848
|
+
var candidates, firstExisting, candidates_8, candidates_8_1, candidate, _a, gitRoot, e_44_1;
|
|
16849
|
+
var e_44, _b;
|
|
16212
16850
|
return __generator(this, function (_c) {
|
|
16213
16851
|
switch (_c.label) {
|
|
16214
16852
|
case 0:
|
|
@@ -16247,14 +16885,14 @@ function resolveAssistantWorkspaceRoot() {
|
|
|
16247
16885
|
return [3 /*break*/, 2];
|
|
16248
16886
|
case 7: return [3 /*break*/, 10];
|
|
16249
16887
|
case 8:
|
|
16250
|
-
|
|
16251
|
-
|
|
16888
|
+
e_44_1 = _c.sent();
|
|
16889
|
+
e_44 = { error: e_44_1 };
|
|
16252
16890
|
return [3 /*break*/, 10];
|
|
16253
16891
|
case 9:
|
|
16254
16892
|
try {
|
|
16255
16893
|
if (candidates_8_1 && !candidates_8_1.done && (_b = candidates_8.return)) _b.call(candidates_8);
|
|
16256
16894
|
}
|
|
16257
|
-
finally { if (
|
|
16895
|
+
finally { if (e_44) throw e_44.error; }
|
|
16258
16896
|
return [7 /*endfinally*/];
|
|
16259
16897
|
case 10:
|
|
16260
16898
|
if (firstExisting) {
|
|
@@ -16654,7 +17292,7 @@ var AI_ASSISTANT_BREAKDOWN_DIMENSION_STOPWORDS = new Set([
|
|
|
16654
17292
|
'by'
|
|
16655
17293
|
]);
|
|
16656
17294
|
function normalizeAssistantBreakdownDimension(value) {
|
|
16657
|
-
var
|
|
17295
|
+
var e_45, _a;
|
|
16658
17296
|
var normalized = normalizeOptionalString(value)
|
|
16659
17297
|
.toLowerCase()
|
|
16660
17298
|
.replace(/[^a-z0-9_\s-]+/g, ' ')
|
|
@@ -16686,12 +17324,12 @@ function normalizeAssistantBreakdownDimension(value) {
|
|
|
16686
17324
|
}
|
|
16687
17325
|
}
|
|
16688
17326
|
}
|
|
16689
|
-
catch (
|
|
17327
|
+
catch (e_45_1) { e_45 = { error: e_45_1 }; }
|
|
16690
17328
|
finally {
|
|
16691
17329
|
try {
|
|
16692
17330
|
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
|
|
16693
17331
|
}
|
|
16694
|
-
finally { if (
|
|
17332
|
+
finally { if (e_45) throw e_45.error; }
|
|
16695
17333
|
}
|
|
16696
17334
|
if (!kept.length) {
|
|
16697
17335
|
return '';
|
|
@@ -16889,7 +17527,7 @@ function resolveAssistantPlannerEnabled() {
|
|
|
16889
17527
|
return raw === undefined ? true : raw === true;
|
|
16890
17528
|
}
|
|
16891
17529
|
function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
|
|
16892
|
-
var
|
|
17530
|
+
var e_46, _a;
|
|
16893
17531
|
var _b;
|
|
16894
17532
|
if (isSuperAdmin === void 0) { isSuperAdmin = false; }
|
|
16895
17533
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
@@ -16903,12 +17541,12 @@ function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
|
|
|
16903
17541
|
}
|
|
16904
17542
|
}
|
|
16905
17543
|
}
|
|
16906
|
-
catch (
|
|
17544
|
+
catch (e_46_1) { e_46 = { error: e_46_1 }; }
|
|
16907
17545
|
finally {
|
|
16908
17546
|
try {
|
|
16909
17547
|
if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
|
|
16910
17548
|
}
|
|
16911
|
-
finally { if (
|
|
17549
|
+
finally { if (e_46) throw e_46.error; }
|
|
16912
17550
|
}
|
|
16913
17551
|
var normalizedRoutes = Array.from(unique);
|
|
16914
17552
|
var allowedRoutes = collectAssistantAllowedRoutesForUser(user, normalizedRoutes, isSuperAdmin);
|
|
@@ -17170,7 +17808,7 @@ function normalizeRouteMatchKey(value) {
|
|
|
17170
17808
|
return normalizeRouteKey(value).toLowerCase();
|
|
17171
17809
|
}
|
|
17172
17810
|
function buildClientRouteIndex() {
|
|
17173
|
-
var
|
|
17811
|
+
var e_47, _a;
|
|
17174
17812
|
var _b;
|
|
17175
17813
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
17176
17814
|
var set = new Set();
|
|
@@ -17189,12 +17827,12 @@ function buildClientRouteIndex() {
|
|
|
17189
17827
|
}
|
|
17190
17828
|
}
|
|
17191
17829
|
}
|
|
17192
|
-
catch (
|
|
17830
|
+
catch (e_47_1) { e_47 = { error: e_47_1 }; }
|
|
17193
17831
|
finally {
|
|
17194
17832
|
try {
|
|
17195
17833
|
if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
|
|
17196
17834
|
}
|
|
17197
|
-
finally { if (
|
|
17835
|
+
finally { if (e_47) throw e_47.error; }
|
|
17198
17836
|
}
|
|
17199
17837
|
return { set: set, map: map, size: routes.length };
|
|
17200
17838
|
}
|
|
@@ -17564,6 +18202,8 @@ var AI_ASSISTANT_CHANGE_HISTORY_PATTERNS = [
|
|
|
17564
18202
|
/\bwhat\s+did\s+(?:the\s+)?last\s+(?:system\s+)?update\s+(?:just\s+)?do\b/i,
|
|
17565
18203
|
/\blast\s+system\s+update\b[\s\S]{0,40}\bdo\b/i,
|
|
17566
18204
|
/\bhow\s+long\b.*\bbeen\s+(this|that)\s+way\b/i,
|
|
18205
|
+
/\bhow\s+long\b[\s\S]{0,120}\bbeen\s+on\s+(?:this|that|the)\s+(?:page|screen|dashboard|menu|route)\b/i,
|
|
18206
|
+
/\bhow\s+long\b[\s\S]{0,120}\bbeen\s+on\s+here\b/i,
|
|
17567
18207
|
/\bhow\s+long\b[\s\S]{0,80}\bbeen\s+around\b/i,
|
|
17568
18208
|
/\bsince\s+when\b/i,
|
|
17569
18209
|
/\bwhen\s+was\b[\s\S]{0,80}\bintroduced\b/i,
|
|
@@ -17972,8 +18612,8 @@ function shouldSkipAssistantGitDiscoveryDirectory(name) {
|
|
|
17972
18612
|
}
|
|
17973
18613
|
function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
17974
18614
|
return __awaiter(this, void 0, void 0, function () {
|
|
17975
|
-
var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b,
|
|
17976
|
-
var
|
|
18615
|
+
var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b, e_48_1, queue, queued, enqueue, next, entries, _c, entries_1, entries_1_1, entry, childName, candidate, gitPath, _d, e_49_1;
|
|
18616
|
+
var e_48, _e, e_49, _f;
|
|
17977
18617
|
var _g;
|
|
17978
18618
|
return __generator(this, function (_h) {
|
|
17979
18619
|
switch (_h.label) {
|
|
@@ -18018,14 +18658,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
18018
18658
|
return [3 /*break*/, 3];
|
|
18019
18659
|
case 6: return [3 /*break*/, 9];
|
|
18020
18660
|
case 7:
|
|
18021
|
-
|
|
18022
|
-
|
|
18661
|
+
e_48_1 = _h.sent();
|
|
18662
|
+
e_48 = { error: e_48_1 };
|
|
18023
18663
|
return [3 /*break*/, 9];
|
|
18024
18664
|
case 8:
|
|
18025
18665
|
try {
|
|
18026
18666
|
if (configuredRoots_1_1 && !configuredRoots_1_1.done && (_e = configuredRoots_1.return)) _e.call(configuredRoots_1);
|
|
18027
18667
|
}
|
|
18028
|
-
finally { if (
|
|
18668
|
+
finally { if (e_48) throw e_48.error; }
|
|
18029
18669
|
return [7 /*endfinally*/];
|
|
18030
18670
|
case 9:
|
|
18031
18671
|
queue = [];
|
|
@@ -18065,7 +18705,7 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
18065
18705
|
return [3 /*break*/, 14];
|
|
18066
18706
|
case 14:
|
|
18067
18707
|
_h.trys.push([14, 21, 22, 23]);
|
|
18068
|
-
entries_1 = (
|
|
18708
|
+
entries_1 = (e_49 = void 0, __values(entries)), entries_1_1 = entries_1.next();
|
|
18069
18709
|
_h.label = 15;
|
|
18070
18710
|
case 15:
|
|
18071
18711
|
if (!!entries_1_1.done) return [3 /*break*/, 20];
|
|
@@ -18104,14 +18744,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
18104
18744
|
return [3 /*break*/, 15];
|
|
18105
18745
|
case 20: return [3 /*break*/, 23];
|
|
18106
18746
|
case 21:
|
|
18107
|
-
|
|
18108
|
-
|
|
18747
|
+
e_49_1 = _h.sent();
|
|
18748
|
+
e_49 = { error: e_49_1 };
|
|
18109
18749
|
return [3 /*break*/, 23];
|
|
18110
18750
|
case 22:
|
|
18111
18751
|
try {
|
|
18112
18752
|
if (entries_1_1 && !entries_1_1.done && (_f = entries_1.return)) _f.call(entries_1);
|
|
18113
18753
|
}
|
|
18114
|
-
finally { if (
|
|
18754
|
+
finally { if (e_49) throw e_49.error; }
|
|
18115
18755
|
return [7 /*endfinally*/];
|
|
18116
18756
|
case 23: return [3 /*break*/, 10];
|
|
18117
18757
|
case 24: return [2 /*return*/, roots];
|
|
@@ -18408,8 +19048,8 @@ function syncAssistantGitMirror(repoUrl) {
|
|
|
18408
19048
|
}
|
|
18409
19049
|
function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
18410
19050
|
return __awaiter(this, void 0, void 0, function () {
|
|
18411
|
-
var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot,
|
|
18412
|
-
var
|
|
19051
|
+
var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot, e_50_1;
|
|
19052
|
+
var e_50, _a;
|
|
18413
19053
|
return __generator(this, function (_b) {
|
|
18414
19054
|
switch (_b.label) {
|
|
18415
19055
|
case 0: return [4 /*yield*/, resolveAssistantWorkspaceGitRoots(workspaceRoot)];
|
|
@@ -18443,14 +19083,14 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
|
18443
19083
|
return [3 /*break*/, 3];
|
|
18444
19084
|
case 6: return [3 /*break*/, 9];
|
|
18445
19085
|
case 7:
|
|
18446
|
-
|
|
18447
|
-
|
|
19086
|
+
e_50_1 = _b.sent();
|
|
19087
|
+
e_50 = { error: e_50_1 };
|
|
18448
19088
|
return [3 /*break*/, 9];
|
|
18449
19089
|
case 8:
|
|
18450
19090
|
try {
|
|
18451
19091
|
if (repoUrls_1_1 && !repoUrls_1_1.done && (_a = repoUrls_1.return)) _a.call(repoUrls_1);
|
|
18452
19092
|
}
|
|
18453
|
-
finally { if (
|
|
19093
|
+
finally { if (e_50) throw e_50.error; }
|
|
18454
19094
|
return [7 /*endfinally*/];
|
|
18455
19095
|
case 9: return [2 /*return*/, mirroredRoots];
|
|
18456
19096
|
}
|
|
@@ -18459,8 +19099,8 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
|
18459
19099
|
}
|
|
18460
19100
|
function resolveAssistantChangeHistoryFastPathResponse(params) {
|
|
18461
19101
|
return __awaiter(this, void 0, void 0, function () {
|
|
18462
|
-
var workspaceRoot, _a, gitRoots, featureKeywords, sawExecutionError, bestFallback, gitRoots_1, gitRoots_1_1, gitRoot, _b, branch, _c, _d, limit, historyDepth, rawHistory, commits, summary, hasKeywordMatches, _e,
|
|
18463
|
-
var
|
|
19102
|
+
var workspaceRoot, _a, gitRoots, featureKeywords, sawExecutionError, bestFallback, gitRoots_1, gitRoots_1_1, gitRoot, _b, branch, _c, _d, limit, historyDepth, rawHistory, commits, summary, hasKeywordMatches, _e, e_51_1;
|
|
19103
|
+
var e_51, _f;
|
|
18464
19104
|
return __generator(this, function (_g) {
|
|
18465
19105
|
switch (_g.label) {
|
|
18466
19106
|
case 0:
|
|
@@ -18582,14 +19222,14 @@ function resolveAssistantChangeHistoryFastPathResponse(params) {
|
|
|
18582
19222
|
return [3 /*break*/, 7];
|
|
18583
19223
|
case 20: return [3 /*break*/, 23];
|
|
18584
19224
|
case 21:
|
|
18585
|
-
|
|
18586
|
-
|
|
19225
|
+
e_51_1 = _g.sent();
|
|
19226
|
+
e_51 = { error: e_51_1 };
|
|
18587
19227
|
return [3 /*break*/, 23];
|
|
18588
19228
|
case 22:
|
|
18589
19229
|
try {
|
|
18590
19230
|
if (gitRoots_1_1 && !gitRoots_1_1.done && (_f = gitRoots_1.return)) _f.call(gitRoots_1);
|
|
18591
19231
|
}
|
|
18592
|
-
finally { if (
|
|
19232
|
+
finally { if (e_51) throw e_51.error; }
|
|
18593
19233
|
return [7 /*endfinally*/];
|
|
18594
19234
|
case 23:
|
|
18595
19235
|
if (bestFallback) {
|
|
@@ -18770,7 +19410,7 @@ function sanitizeAssistantResponse(value) {
|
|
|
18770
19410
|
return normalizeAssistantRoutes(normalizedCurrency);
|
|
18771
19411
|
}
|
|
18772
19412
|
function evaluateAssistantGuardrails(message) {
|
|
18773
|
-
var
|
|
19413
|
+
var e_52, _a;
|
|
18774
19414
|
var normalized = String(message || '').toLowerCase();
|
|
18775
19415
|
var patterns = [
|
|
18776
19416
|
{
|
|
@@ -18816,12 +19456,12 @@ function evaluateAssistantGuardrails(message) {
|
|
|
18816
19456
|
}
|
|
18817
19457
|
}
|
|
18818
19458
|
}
|
|
18819
|
-
catch (
|
|
19459
|
+
catch (e_52_1) { e_52 = { error: e_52_1 }; }
|
|
18820
19460
|
finally {
|
|
18821
19461
|
try {
|
|
18822
19462
|
if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
|
|
18823
19463
|
}
|
|
18824
|
-
finally { if (
|
|
19464
|
+
finally { if (e_52) throw e_52.error; }
|
|
18825
19465
|
}
|
|
18826
19466
|
return null;
|
|
18827
19467
|
}
|
|
@@ -18936,7 +19576,7 @@ function tokenizeArithmeticExpression(expression) {
|
|
|
18936
19576
|
return tokens;
|
|
18937
19577
|
}
|
|
18938
19578
|
function evaluateArithmeticExpression(expression) {
|
|
18939
|
-
var
|
|
19579
|
+
var e_53, _a, e_54, _b;
|
|
18940
19580
|
var tokens = tokenizeArithmeticExpression(expression);
|
|
18941
19581
|
if (!tokens || !tokens.length) {
|
|
18942
19582
|
return null;
|
|
@@ -18993,12 +19633,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
18993
19633
|
prevToken = token;
|
|
18994
19634
|
}
|
|
18995
19635
|
}
|
|
18996
|
-
catch (
|
|
19636
|
+
catch (e_53_1) { e_53 = { error: e_53_1 }; }
|
|
18997
19637
|
finally {
|
|
18998
19638
|
try {
|
|
18999
19639
|
if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
|
|
19000
19640
|
}
|
|
19001
|
-
finally { if (
|
|
19641
|
+
finally { if (e_53) throw e_53.error; }
|
|
19002
19642
|
}
|
|
19003
19643
|
while (ops.length) {
|
|
19004
19644
|
var op = ops.pop();
|
|
@@ -19038,12 +19678,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
19038
19678
|
stack.push(Number(token));
|
|
19039
19679
|
}
|
|
19040
19680
|
}
|
|
19041
|
-
catch (
|
|
19681
|
+
catch (e_54_1) { e_54 = { error: e_54_1 }; }
|
|
19042
19682
|
finally {
|
|
19043
19683
|
try {
|
|
19044
19684
|
if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
|
|
19045
19685
|
}
|
|
19046
|
-
finally { if (
|
|
19686
|
+
finally { if (e_54) throw e_54.error; }
|
|
19047
19687
|
}
|
|
19048
19688
|
if (stack.length !== 1 || Number.isNaN(stack[0])) {
|
|
19049
19689
|
return null;
|
|
@@ -19227,8 +19867,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
|
|
|
19227
19867
|
}
|
|
19228
19868
|
function readAttachmentContents(attachments) {
|
|
19229
19869
|
return __awaiter(this, void 0, void 0, function () {
|
|
19230
|
-
var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a,
|
|
19231
|
-
var
|
|
19870
|
+
var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_55_1;
|
|
19871
|
+
var e_55, _b;
|
|
19232
19872
|
return __generator(this, function (_c) {
|
|
19233
19873
|
switch (_c.label) {
|
|
19234
19874
|
case 0:
|
|
@@ -19307,14 +19947,14 @@ function readAttachmentContents(attachments) {
|
|
|
19307
19947
|
return [3 /*break*/, 2];
|
|
19308
19948
|
case 10: return [3 /*break*/, 13];
|
|
19309
19949
|
case 11:
|
|
19310
|
-
|
|
19311
|
-
|
|
19950
|
+
e_55_1 = _c.sent();
|
|
19951
|
+
e_55 = { error: e_55_1 };
|
|
19312
19952
|
return [3 /*break*/, 13];
|
|
19313
19953
|
case 12:
|
|
19314
19954
|
try {
|
|
19315
19955
|
if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
|
|
19316
19956
|
}
|
|
19317
|
-
finally { if (
|
|
19957
|
+
finally { if (e_55) throw e_55.error; }
|
|
19318
19958
|
return [7 /*endfinally*/];
|
|
19319
19959
|
case 13: return [2 /*return*/, {
|
|
19320
19960
|
promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
|
|
@@ -19469,7 +20109,7 @@ function resolveAssistantDatabaseNameForSystemCollections() {
|
|
|
19469
20109
|
}
|
|
19470
20110
|
function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
19471
20111
|
return __awaiter(this, void 0, void 0, function () {
|
|
19472
|
-
var
|
|
20112
|
+
var error_12, dbName, _a;
|
|
19473
20113
|
return __generator(this, function (_b) {
|
|
19474
20114
|
switch (_b.label) {
|
|
19475
20115
|
case 0:
|
|
@@ -19484,9 +20124,9 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
19484
20124
|
_b.sent();
|
|
19485
20125
|
return [2 /*return*/];
|
|
19486
20126
|
case 3:
|
|
19487
|
-
|
|
19488
|
-
if (!isAssistantTransactionCommittedError(
|
|
19489
|
-
throw
|
|
20127
|
+
error_12 = _b.sent();
|
|
20128
|
+
if (!isAssistantTransactionCommittedError(error_12)) {
|
|
20129
|
+
throw error_12;
|
|
19490
20130
|
}
|
|
19491
20131
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
19492
20132
|
_b.label = 4;
|
|
@@ -19516,7 +20156,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
19516
20156
|
}
|
|
19517
20157
|
function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
19518
20158
|
return __awaiter(this, void 0, void 0, function () {
|
|
19519
|
-
var update,
|
|
20159
|
+
var update, error_13, dbName;
|
|
19520
20160
|
return __generator(this, function (_a) {
|
|
19521
20161
|
switch (_a.label) {
|
|
19522
20162
|
case 0:
|
|
@@ -19535,9 +20175,9 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
19535
20175
|
_a.sent();
|
|
19536
20176
|
return [2 /*return*/];
|
|
19537
20177
|
case 3:
|
|
19538
|
-
|
|
19539
|
-
if (!isAssistantTransactionCommittedError(
|
|
19540
|
-
throw
|
|
20178
|
+
error_13 = _a.sent();
|
|
20179
|
+
if (!isAssistantTransactionCommittedError(error_13)) {
|
|
20180
|
+
throw error_13;
|
|
19541
20181
|
}
|
|
19542
20182
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
19543
20183
|
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoConnection()
|
|
@@ -19638,7 +20278,7 @@ function estimateUsage(messages, responseText, model) {
|
|
|
19638
20278
|
};
|
|
19639
20279
|
}
|
|
19640
20280
|
function evaluateGuardrails(message) {
|
|
19641
|
-
var
|
|
20281
|
+
var e_56, _a;
|
|
19642
20282
|
var normalized = String(message || '').toLowerCase();
|
|
19643
20283
|
var patterns = [
|
|
19644
20284
|
{ 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.' },
|
|
@@ -19660,12 +20300,12 @@ function evaluateGuardrails(message) {
|
|
|
19660
20300
|
}
|
|
19661
20301
|
}
|
|
19662
20302
|
}
|
|
19663
|
-
catch (
|
|
20303
|
+
catch (e_56_1) { e_56 = { error: e_56_1 }; }
|
|
19664
20304
|
finally {
|
|
19665
20305
|
try {
|
|
19666
20306
|
if (patterns_3_1 && !patterns_3_1.done && (_a = patterns_3.return)) _a.call(patterns_3);
|
|
19667
20307
|
}
|
|
19668
|
-
finally { if (
|
|
20308
|
+
finally { if (e_56) throw e_56.error; }
|
|
19669
20309
|
}
|
|
19670
20310
|
return null;
|
|
19671
20311
|
}
|