@resolveio/server-lib 22.1.13 → 22.1.15
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 +1121 -422
- 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;
|
|
@@ -5566,62 +5603,613 @@ function buildAssistantGenericHoursDirective(message, collectionHints) {
|
|
|
5566
5603
|
$group: (_a = {
|
|
5567
5604
|
_id: bucketExpr
|
|
5568
5605
|
},
|
|
5569
|
-
_a[totalMetricKey] = { $sum: '$metric_value' },
|
|
5570
|
-
_a)
|
|
5571
|
-
}
|
|
5572
|
-
];
|
|
5573
|
-
if (intent.averageOverWindow) {
|
|
5574
|
-
var avgColumnName = grain === 'month' ? 'avg_monthly_hours' : "avg_".concat(grain, "_hours");
|
|
5575
|
-
pipeline.push({
|
|
5576
|
-
$group: {
|
|
5577
|
-
_id: null,
|
|
5578
|
-
total_hours: { $sum: "$".concat(totalMetricKey) }
|
|
5579
|
-
}
|
|
5580
|
-
}, {
|
|
5581
|
-
$project: (_b = {
|
|
5582
|
-
_id: 0
|
|
5606
|
+
_a[totalMetricKey] = { $sum: '$metric_value' },
|
|
5607
|
+
_a)
|
|
5608
|
+
}
|
|
5609
|
+
];
|
|
5610
|
+
if (intent.averageOverWindow) {
|
|
5611
|
+
var avgColumnName = grain === 'month' ? 'avg_monthly_hours' : "avg_".concat(grain, "_hours");
|
|
5612
|
+
pipeline.push({
|
|
5613
|
+
$group: {
|
|
5614
|
+
_id: null,
|
|
5615
|
+
total_hours: { $sum: "$".concat(totalMetricKey) }
|
|
5616
|
+
}
|
|
5617
|
+
}, {
|
|
5618
|
+
$project: (_b = {
|
|
5619
|
+
_id: 0
|
|
5620
|
+
},
|
|
5621
|
+
_b[avgColumnName] = { $divide: ['$total_hours', divisor] },
|
|
5622
|
+
_b)
|
|
5623
|
+
});
|
|
5624
|
+
}
|
|
5625
|
+
else {
|
|
5626
|
+
var dateFormat = grain === 'day' || grain === 'week'
|
|
5627
|
+
? '%Y-%m-%d'
|
|
5628
|
+
: grain === 'year'
|
|
5629
|
+
? '%Y'
|
|
5630
|
+
: '%Y-%m';
|
|
5631
|
+
pipeline.push({
|
|
5632
|
+
$project: (_c = {
|
|
5633
|
+
_id: 0
|
|
5634
|
+
},
|
|
5635
|
+
_c[grain] = {
|
|
5636
|
+
$dateToString: {
|
|
5637
|
+
format: dateFormat,
|
|
5638
|
+
date: '$_id'
|
|
5639
|
+
}
|
|
5640
|
+
},
|
|
5641
|
+
_c[totalMetricKey] = 1,
|
|
5642
|
+
_c)
|
|
5643
|
+
}, {
|
|
5644
|
+
$sort: (_d = {},
|
|
5645
|
+
_d[grain] = 1,
|
|
5646
|
+
_d)
|
|
5647
|
+
});
|
|
5648
|
+
}
|
|
5649
|
+
return {
|
|
5650
|
+
type: 'aggregate',
|
|
5651
|
+
payload: {
|
|
5652
|
+
collection: selected.collection,
|
|
5653
|
+
permissionView: resolveDefaultAssistantPermissionView(selected.collection),
|
|
5654
|
+
pipeline: pipeline,
|
|
5655
|
+
options: {
|
|
5656
|
+
allowDiskUse: true,
|
|
5657
|
+
limit: intent.averageOverWindow ? 20 : 400
|
|
5658
|
+
}
|
|
5659
|
+
},
|
|
5660
|
+
cleaned: '',
|
|
5661
|
+
rawLine: 'HEURISTIC_AGG(schema-hours-user-time)'
|
|
5662
|
+
};
|
|
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
|
+
}
|
|
5583
6072
|
},
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
$project: (_c = {
|
|
5596
|
-
_id: 0
|
|
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
|
+
}
|
|
5597
6084
|
},
|
|
5598
|
-
|
|
5599
|
-
$
|
|
5600
|
-
|
|
5601
|
-
date: '$_id'
|
|
6085
|
+
{
|
|
6086
|
+
$sort: {
|
|
6087
|
+
_id: 1
|
|
5602
6088
|
}
|
|
5603
6089
|
},
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
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;
|
|
5611
6130
|
}
|
|
5612
6131
|
return {
|
|
5613
6132
|
type: 'aggregate',
|
|
5614
6133
|
payload: {
|
|
5615
|
-
collection:
|
|
5616
|
-
permissionView: resolveDefaultAssistantPermissionView(
|
|
5617
|
-
pipeline:
|
|
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
|
+
],
|
|
5618
6206
|
options: {
|
|
5619
6207
|
allowDiskUse: true,
|
|
5620
|
-
limit:
|
|
6208
|
+
limit: topN
|
|
5621
6209
|
}
|
|
5622
6210
|
},
|
|
5623
6211
|
cleaned: '',
|
|
5624
|
-
rawLine: 'HEURISTIC_AGG(
|
|
6212
|
+
rawLine: 'HEURISTIC_AGG(work-order-top-customers-window)'
|
|
5625
6213
|
};
|
|
5626
6214
|
}
|
|
5627
6215
|
function isAssistantSchemaHoursHeuristicDirective(directive) {
|
|
@@ -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
|
}
|
|
@@ -8941,9 +9567,10 @@ function applyAssistantDisplayTableToResponse(value, display) {
|
|
|
8941
9567
|
: resolveAssistantEmptyDisplayColumns(cleaned_1 || value);
|
|
8942
9568
|
var normalizedColumns = fallbackColumns.length === 1
|
|
8943
9569
|
? __spreadArray(__spreadArray([], __read(fallbackColumns), false), ['Value'], false) : fallbackColumns;
|
|
8944
|
-
var rowSummary =
|
|
8945
|
-
|
|
8946
|
-
|
|
9570
|
+
var rowSummary = [(_a = {},
|
|
9571
|
+
_a[normalizedColumns[0]] = rowCount > 0 ? 'Rows matched' : 'No rows matched',
|
|
9572
|
+
_a[normalizedColumns[1]] = rowCount,
|
|
9573
|
+
_a)];
|
|
8947
9574
|
var tableDisplay = {
|
|
8948
9575
|
columns: normalizedColumns,
|
|
8949
9576
|
rows: rowSummary,
|
|
@@ -8955,10 +9582,19 @@ function applyAssistantDisplayTableToResponse(value, display) {
|
|
|
8955
9582
|
if (!emptyTable) {
|
|
8956
9583
|
return cleaned_1 || value;
|
|
8957
9584
|
}
|
|
9585
|
+
var noRowsNote = rowCount > 0 ? '' : 'No rows matched your request.';
|
|
9586
|
+
var base = cleaned_1
|
|
9587
|
+
? (noRowsNote && !/\bno rows? matched\b/i.test(cleaned_1)
|
|
9588
|
+
? "".concat(cleaned_1.trim(), "\n\n").concat(noRowsNote).trim()
|
|
9589
|
+
: cleaned_1.trim())
|
|
9590
|
+
: noRowsNote;
|
|
8958
9591
|
if (!cleaned_1) {
|
|
8959
|
-
|
|
9592
|
+
if (!base) {
|
|
9593
|
+
return emptyTable;
|
|
9594
|
+
}
|
|
9595
|
+
return "".concat(base, "\n\n").concat(emptyTable).trim();
|
|
8960
9596
|
}
|
|
8961
|
-
return "".concat(
|
|
9597
|
+
return "".concat(base, "\n\n").concat(emptyTable).trim();
|
|
8962
9598
|
}
|
|
8963
9599
|
var table = formatDisplayTableMarkdown(normalizedDisplay);
|
|
8964
9600
|
if (!table) {
|
|
@@ -9515,6 +10151,18 @@ function normalizeAssistantDateArithmeticArgs(expression) {
|
|
|
9515
10151
|
if (expression instanceof Date || expression instanceof RegExp || isMongoObjectId(expression)) {
|
|
9516
10152
|
return expression;
|
|
9517
10153
|
}
|
|
10154
|
+
var looksLikeDateOperand = function (candidate) {
|
|
10155
|
+
if (candidate instanceof Date) {
|
|
10156
|
+
return true;
|
|
10157
|
+
}
|
|
10158
|
+
if (typeof candidate === 'string') {
|
|
10159
|
+
return candidate.startsWith('$$') || candidate.startsWith('$');
|
|
10160
|
+
}
|
|
10161
|
+
if (candidate && typeof candidate === 'object' && !Array.isArray(candidate)) {
|
|
10162
|
+
return Object.keys(candidate).some(function (op) { return op.startsWith('$'); });
|
|
10163
|
+
}
|
|
10164
|
+
return false;
|
|
10165
|
+
};
|
|
9518
10166
|
var normalizeOperatorArgs = function (operator) {
|
|
9519
10167
|
if (!Object.prototype.hasOwnProperty.call(expression, operator)) {
|
|
9520
10168
|
return;
|
|
@@ -9690,6 +10338,54 @@ function normalizeAssistantDateArithmeticArgs(expression) {
|
|
|
9690
10338
|
});
|
|
9691
10339
|
expression.$dateTrunc = nextArgs;
|
|
9692
10340
|
};
|
|
10341
|
+
var normalizeDateToStringArgs = function () {
|
|
10342
|
+
if (!Object.prototype.hasOwnProperty.call(expression, '$dateToString')) {
|
|
10343
|
+
return;
|
|
10344
|
+
}
|
|
10345
|
+
var rawArgs = expression.$dateToString;
|
|
10346
|
+
if (!rawArgs || typeof rawArgs !== 'object' || Array.isArray(rawArgs)) {
|
|
10347
|
+
return;
|
|
10348
|
+
}
|
|
10349
|
+
if (rawArgs instanceof Date || rawArgs instanceof RegExp || isMongoObjectId(rawArgs)) {
|
|
10350
|
+
return;
|
|
10351
|
+
}
|
|
10352
|
+
var nextArgs = __assign({}, rawArgs);
|
|
10353
|
+
if (!Object.prototype.hasOwnProperty.call(nextArgs, 'date')) {
|
|
10354
|
+
if (Object.prototype.hasOwnProperty.call(nextArgs, 'startDate')) {
|
|
10355
|
+
nextArgs.date = nextArgs.startDate;
|
|
10356
|
+
}
|
|
10357
|
+
else if (Object.prototype.hasOwnProperty.call(nextArgs, 'start')) {
|
|
10358
|
+
nextArgs.date = nextArgs.start;
|
|
10359
|
+
}
|
|
10360
|
+
else {
|
|
10361
|
+
var dateCandidateKey = Object.keys(nextArgs).find(function (key) {
|
|
10362
|
+
if (key === 'format' || key === 'timezone' || key === 'onNull' || key === 'onError') {
|
|
10363
|
+
return false;
|
|
10364
|
+
}
|
|
10365
|
+
return looksLikeDateOperand(nextArgs[key]);
|
|
10366
|
+
});
|
|
10367
|
+
if (dateCandidateKey) {
|
|
10368
|
+
nextArgs.date = nextArgs[dateCandidateKey];
|
|
10369
|
+
delete nextArgs[dateCandidateKey];
|
|
10370
|
+
}
|
|
10371
|
+
}
|
|
10372
|
+
}
|
|
10373
|
+
delete nextArgs.startDate;
|
|
10374
|
+
delete nextArgs.start;
|
|
10375
|
+
if (!Object.prototype.hasOwnProperty.call(nextArgs, 'date')) {
|
|
10376
|
+
nextArgs.date = '$$NOW';
|
|
10377
|
+
}
|
|
10378
|
+
if (!Object.prototype.hasOwnProperty.call(nextArgs, 'format')) {
|
|
10379
|
+
nextArgs.format = '%Y-%m-%d';
|
|
10380
|
+
}
|
|
10381
|
+
var allowedKeys = new Set(['date', 'format', 'timezone', 'onNull']);
|
|
10382
|
+
Object.keys(nextArgs).forEach(function (key) {
|
|
10383
|
+
if (!allowedKeys.has(key)) {
|
|
10384
|
+
delete nextArgs[key];
|
|
10385
|
+
}
|
|
10386
|
+
});
|
|
10387
|
+
expression.$dateToString = nextArgs;
|
|
10388
|
+
};
|
|
9693
10389
|
var normalizeLetArgs = function () {
|
|
9694
10390
|
if (!Object.prototype.hasOwnProperty.call(expression, '$let')) {
|
|
9695
10391
|
return;
|
|
@@ -9727,18 +10423,6 @@ function normalizeAssistantDateArithmeticArgs(expression) {
|
|
|
9727
10423
|
};
|
|
9728
10424
|
var normalizeDatePartArgs = function () {
|
|
9729
10425
|
var operators = ['$year', '$month', '$week', '$isoWeek', '$isoWeekYear', '$dayOfMonth', '$dayOfYear'];
|
|
9730
|
-
var looksLikeDateOperand = function (candidate) {
|
|
9731
|
-
if (candidate instanceof Date) {
|
|
9732
|
-
return true;
|
|
9733
|
-
}
|
|
9734
|
-
if (typeof candidate === 'string') {
|
|
9735
|
-
return candidate.startsWith('$$') || candidate.startsWith('$');
|
|
9736
|
-
}
|
|
9737
|
-
if (candidate && typeof candidate === 'object' && !Array.isArray(candidate)) {
|
|
9738
|
-
return Object.keys(candidate).some(function (op) { return op.startsWith('$'); });
|
|
9739
|
-
}
|
|
9740
|
-
return false;
|
|
9741
|
-
};
|
|
9742
10426
|
operators.forEach(function (operator) {
|
|
9743
10427
|
if (!Object.prototype.hasOwnProperty.call(expression, operator)) {
|
|
9744
10428
|
return;
|
|
@@ -9780,6 +10464,7 @@ function normalizeAssistantDateArithmeticArgs(expression) {
|
|
|
9780
10464
|
normalizeOperatorArgs('$dateAdd');
|
|
9781
10465
|
normalizeOperatorArgs('$dateSubtract');
|
|
9782
10466
|
normalizeDateTruncArgs();
|
|
10467
|
+
normalizeDateToStringArgs();
|
|
9783
10468
|
normalizeLetArgs();
|
|
9784
10469
|
normalizeDatePartArgs();
|
|
9785
10470
|
return expression;
|
|
@@ -9814,6 +10499,7 @@ function isAssistantDateArithmeticArgumentError(error) {
|
|
|
9814
10499
|
return message.includes('unrecognized argument to $datesubtract:')
|
|
9815
10500
|
|| message.includes('unrecognized argument to $dateadd:')
|
|
9816
10501
|
|| message.includes('unrecognized argument to $datetrunc:')
|
|
10502
|
+
|| message.includes('unrecognized argument to $datetostring:')
|
|
9817
10503
|
|| message.includes('unrecognized option to $year:')
|
|
9818
10504
|
|| message.includes('unrecognized option to $month:')
|
|
9819
10505
|
|| message.includes('unrecognized option to $week:')
|
|
@@ -9827,6 +10513,8 @@ function isAssistantDateArithmeticArgumentError(error) {
|
|
|
9827
10513
|
|| message.includes("missing 'date' parameter to $datetrunc")
|
|
9828
10514
|
|| message.includes("requires 'unit' parameter to $datetrunc")
|
|
9829
10515
|
|| message.includes("requires 'date' parameter to $datetrunc")
|
|
10516
|
+
|| message.includes("requires 'date' parameter to $datetostring")
|
|
10517
|
+
|| message.includes("missing 'date' parameter to $datetostring")
|
|
9830
10518
|
|| message.includes('$datesubtract requires startdate, unit, and amount to be present')
|
|
9831
10519
|
|| message.includes('$dateadd requires startdate, unit, and amount to be present')
|
|
9832
10520
|
|| message.includes('undefined variable: now_start_of_month')
|
|
@@ -9859,13 +10547,19 @@ function isAssistantDottedOutputFieldError(error) {
|
|
|
9859
10547
|
if (!message) {
|
|
9860
10548
|
return false;
|
|
9861
10549
|
}
|
|
9862
|
-
return message.includes("fieldpath field names may not contain '.'")
|
|
10550
|
+
return message.includes("fieldpath field names may not contain '.'")
|
|
10551
|
+
|| (message.includes("field name '") && message.includes("cannot contain '.'"));
|
|
9863
10552
|
}
|
|
9864
10553
|
function extractAssistantDottedFieldPathFromError(error) {
|
|
9865
10554
|
var message = normalizeOptionalString(error === null || error === void 0 ? void 0 : error.message);
|
|
9866
10555
|
if (!message) {
|
|
9867
10556
|
return null;
|
|
9868
10557
|
}
|
|
10558
|
+
var fieldNameMatch = message.match(/field name\s+'([^']+)'/i);
|
|
10559
|
+
if (fieldNameMatch === null || fieldNameMatch === void 0 ? void 0 : fieldNameMatch[1]) {
|
|
10560
|
+
var normalized = normalizeOptionalString(fieldNameMatch[1]);
|
|
10561
|
+
return normalized.includes('.') ? normalized : null;
|
|
10562
|
+
}
|
|
9869
10563
|
var quotedMatch = message.match(/given\s+'([^']+)'/i);
|
|
9870
10564
|
if (quotedMatch && quotedMatch[1]) {
|
|
9871
10565
|
var normalized = normalizeOptionalString(quotedMatch[1]);
|
|
@@ -10281,7 +10975,7 @@ function flattenAssistantExprClauses(expr) {
|
|
|
10281
10975
|
return [expr];
|
|
10282
10976
|
}
|
|
10283
10977
|
function detectAssistantMonthWindowInExpr(expr, allowedDateFields) {
|
|
10284
|
-
var
|
|
10978
|
+
var e_18, _a;
|
|
10285
10979
|
var clauses = flattenAssistantExprClauses(expr);
|
|
10286
10980
|
if (!clauses.length) {
|
|
10287
10981
|
return null;
|
|
@@ -10332,7 +11026,7 @@ function detectAssistantMonthWindowInExpr(expr, allowedDateFields) {
|
|
|
10332
11026
|
upperClauses.push({ index: index, field: field, mode: 'full_month' });
|
|
10333
11027
|
}
|
|
10334
11028
|
});
|
|
10335
|
-
var
|
|
11029
|
+
var _loop_9 = function (lower) {
|
|
10336
11030
|
var upper = upperClauses.find(function (candidate) { return (candidate.field === lower.field
|
|
10337
11031
|
&& candidate.mode === lower.mode); });
|
|
10338
11032
|
if (!upper) {
|
|
@@ -10350,17 +11044,17 @@ function detectAssistantMonthWindowInExpr(expr, allowedDateFields) {
|
|
|
10350
11044
|
try {
|
|
10351
11045
|
for (var lowerClauses_1 = __values(lowerClauses), lowerClauses_1_1 = lowerClauses_1.next(); !lowerClauses_1_1.done; lowerClauses_1_1 = lowerClauses_1.next()) {
|
|
10352
11046
|
var lower = lowerClauses_1_1.value;
|
|
10353
|
-
var
|
|
10354
|
-
if (typeof
|
|
10355
|
-
return
|
|
11047
|
+
var state_7 = _loop_9(lower);
|
|
11048
|
+
if (typeof state_7 === "object")
|
|
11049
|
+
return state_7.value;
|
|
10356
11050
|
}
|
|
10357
11051
|
}
|
|
10358
|
-
catch (
|
|
11052
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
10359
11053
|
finally {
|
|
10360
11054
|
try {
|
|
10361
11055
|
if (lowerClauses_1_1 && !lowerClauses_1_1.done && (_a = lowerClauses_1.return)) _a.call(lowerClauses_1);
|
|
10362
11056
|
}
|
|
10363
|
-
finally { if (
|
|
11057
|
+
finally { if (e_18) throw e_18.error; }
|
|
10364
11058
|
}
|
|
10365
11059
|
return null;
|
|
10366
11060
|
}
|
|
@@ -10423,7 +11117,7 @@ function resolveAssistantMonthlyGroupDateFields(pipeline) {
|
|
|
10423
11117
|
return fields;
|
|
10424
11118
|
}
|
|
10425
11119
|
function detectAssistantMonthWindowFromPipeline(pipeline) {
|
|
10426
|
-
var
|
|
11120
|
+
var e_19, _a;
|
|
10427
11121
|
var _b;
|
|
10428
11122
|
var monthlyFields = resolveAssistantMonthlyGroupDateFields(pipeline);
|
|
10429
11123
|
var scanMatch = function (match) {
|
|
@@ -10451,12 +11145,12 @@ function detectAssistantMonthWindowFromPipeline(pipeline) {
|
|
|
10451
11145
|
}
|
|
10452
11146
|
}
|
|
10453
11147
|
}
|
|
10454
|
-
catch (
|
|
11148
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
10455
11149
|
finally {
|
|
10456
11150
|
try {
|
|
10457
11151
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
10458
11152
|
}
|
|
10459
|
-
finally { if (
|
|
11153
|
+
finally { if (e_19) throw e_19.error; }
|
|
10460
11154
|
}
|
|
10461
11155
|
return null;
|
|
10462
11156
|
}
|
|
@@ -10736,7 +11430,7 @@ function normalizeAssistantCustomerLookupProjectionPipeline(pipeline) {
|
|
|
10736
11430
|
var nextProject = __assign({}, project);
|
|
10737
11431
|
var stageChanged = false;
|
|
10738
11432
|
Object.keys(nextProject).forEach(function (field) {
|
|
10739
|
-
var
|
|
11433
|
+
var e_20, _a;
|
|
10740
11434
|
var expression = nextProject[field];
|
|
10741
11435
|
if (typeof expression !== 'string') {
|
|
10742
11436
|
return;
|
|
@@ -10772,12 +11466,12 @@ function normalizeAssistantCustomerLookupProjectionPipeline(pipeline) {
|
|
|
10772
11466
|
break;
|
|
10773
11467
|
}
|
|
10774
11468
|
}
|
|
10775
|
-
catch (
|
|
11469
|
+
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
10776
11470
|
finally {
|
|
10777
11471
|
try {
|
|
10778
11472
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
10779
11473
|
}
|
|
10780
|
-
finally { if (
|
|
11474
|
+
finally { if (e_20) throw e_20.error; }
|
|
10781
11475
|
}
|
|
10782
11476
|
});
|
|
10783
11477
|
if (stageChanged) {
|
|
@@ -10945,7 +11639,7 @@ function matchContainsField(value, field) {
|
|
|
10945
11639
|
});
|
|
10946
11640
|
}
|
|
10947
11641
|
function resolveAggregateCompletionFallback(pipeline) {
|
|
10948
|
-
var
|
|
11642
|
+
var e_21, _a;
|
|
10949
11643
|
if (!Array.isArray(pipeline)) {
|
|
10950
11644
|
return null;
|
|
10951
11645
|
}
|
|
@@ -10958,7 +11652,7 @@ function resolveAggregateCompletionFallback(pipeline) {
|
|
|
10958
11652
|
}
|
|
10959
11653
|
var addFields = stage.$addFields;
|
|
10960
11654
|
try {
|
|
10961
|
-
for (var _b = (
|
|
11655
|
+
for (var _b = (e_21 = void 0, __values(Object.keys(addFields))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
10962
11656
|
var key = _c.value;
|
|
10963
11657
|
if (!isCompletionFieldName(key)) {
|
|
10964
11658
|
continue;
|
|
@@ -10972,12 +11666,12 @@ function resolveAggregateCompletionFallback(pipeline) {
|
|
|
10972
11666
|
}
|
|
10973
11667
|
}
|
|
10974
11668
|
}
|
|
10975
|
-
catch (
|
|
11669
|
+
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
10976
11670
|
finally {
|
|
10977
11671
|
try {
|
|
10978
11672
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
10979
11673
|
}
|
|
10980
|
-
finally { if (
|
|
11674
|
+
finally { if (e_21) throw e_21.error; }
|
|
10981
11675
|
}
|
|
10982
11676
|
if (candidateField) {
|
|
10983
11677
|
break;
|
|
@@ -11133,7 +11827,7 @@ function buildCompletionFallbackSources(field) {
|
|
|
11133
11827
|
]);
|
|
11134
11828
|
}
|
|
11135
11829
|
function resolveAggregateCompletionExprFallback(pipeline) {
|
|
11136
|
-
var
|
|
11830
|
+
var e_22, _a;
|
|
11137
11831
|
if (!Array.isArray(pipeline)) {
|
|
11138
11832
|
return null;
|
|
11139
11833
|
}
|
|
@@ -11153,7 +11847,7 @@ function resolveAggregateCompletionExprFallback(pipeline) {
|
|
|
11153
11847
|
}
|
|
11154
11848
|
if (!candidateField) {
|
|
11155
11849
|
try {
|
|
11156
|
-
for (var _b = (
|
|
11850
|
+
for (var _b = (e_22 = void 0, __values(Object.keys(matchStage))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
11157
11851
|
var key = _c.value;
|
|
11158
11852
|
if (key.startsWith('$')) {
|
|
11159
11853
|
continue;
|
|
@@ -11168,12 +11862,12 @@ function resolveAggregateCompletionExprFallback(pipeline) {
|
|
|
11168
11862
|
}
|
|
11169
11863
|
}
|
|
11170
11864
|
}
|
|
11171
|
-
catch (
|
|
11865
|
+
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
11172
11866
|
finally {
|
|
11173
11867
|
try {
|
|
11174
11868
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
11175
11869
|
}
|
|
11176
|
-
finally { if (
|
|
11870
|
+
finally { if (e_22) throw e_22.error; }
|
|
11177
11871
|
}
|
|
11178
11872
|
}
|
|
11179
11873
|
if (!candidateField) {
|
|
@@ -11281,7 +11975,7 @@ function resolveAssistantAggregateDimensionFieldHints(pipeline) {
|
|
|
11281
11975
|
}
|
|
11282
11976
|
hints.push(normalized);
|
|
11283
11977
|
};
|
|
11284
|
-
var
|
|
11978
|
+
var _loop_10 = function (index) {
|
|
11285
11979
|
var stage = pipeline[index];
|
|
11286
11980
|
if (!stage || typeof stage !== 'object' || Array.isArray(stage) || !stage.$project || typeof stage.$project !== 'object') {
|
|
11287
11981
|
return "continue";
|
|
@@ -11302,7 +11996,7 @@ function resolveAssistantAggregateDimensionFieldHints(pipeline) {
|
|
|
11302
11996
|
});
|
|
11303
11997
|
};
|
|
11304
11998
|
for (var index = groupIndex + 1; index < pipeline.length; index += 1) {
|
|
11305
|
-
|
|
11999
|
+
_loop_10(index);
|
|
11306
12000
|
}
|
|
11307
12001
|
return hints.slice(0, 6);
|
|
11308
12002
|
}
|
|
@@ -11375,7 +12069,7 @@ function hasAssistantDateGroupingOperator(value) {
|
|
|
11375
12069
|
return Object.keys(value).some(function (key) { return hasAssistantDateGroupingOperator(value[key]); });
|
|
11376
12070
|
}
|
|
11377
12071
|
function isGroupFieldDerivedFromDateExpression(pipeline, groupIndex, groupPaths) {
|
|
11378
|
-
var
|
|
12072
|
+
var e_23, _a, e_24, _b;
|
|
11379
12073
|
if (!Array.isArray(pipeline) || groupIndex <= 0 || !groupPaths.length) {
|
|
11380
12074
|
return false;
|
|
11381
12075
|
}
|
|
@@ -11401,14 +12095,14 @@ function isGroupFieldDerivedFromDateExpression(pipeline, groupIndex, groupPaths)
|
|
|
11401
12095
|
continue;
|
|
11402
12096
|
}
|
|
11403
12097
|
try {
|
|
11404
|
-
for (var stageKeys_1 = (
|
|
12098
|
+
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
12099
|
var stageKey = stageKeys_1_1.value;
|
|
11406
12100
|
var payload = stage[stageKey];
|
|
11407
12101
|
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
11408
12102
|
continue;
|
|
11409
12103
|
}
|
|
11410
12104
|
try {
|
|
11411
|
-
for (var groupFields_1 = (
|
|
12105
|
+
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
12106
|
var groupField = groupFields_1_1.value;
|
|
11413
12107
|
if (!Object.prototype.hasOwnProperty.call(payload, groupField)) {
|
|
11414
12108
|
continue;
|
|
@@ -11418,21 +12112,21 @@ function isGroupFieldDerivedFromDateExpression(pipeline, groupIndex, groupPaths)
|
|
|
11418
12112
|
}
|
|
11419
12113
|
}
|
|
11420
12114
|
}
|
|
11421
|
-
catch (
|
|
12115
|
+
catch (e_24_1) { e_24 = { error: e_24_1 }; }
|
|
11422
12116
|
finally {
|
|
11423
12117
|
try {
|
|
11424
12118
|
if (groupFields_1_1 && !groupFields_1_1.done && (_b = groupFields_1.return)) _b.call(groupFields_1);
|
|
11425
12119
|
}
|
|
11426
|
-
finally { if (
|
|
12120
|
+
finally { if (e_24) throw e_24.error; }
|
|
11427
12121
|
}
|
|
11428
12122
|
}
|
|
11429
12123
|
}
|
|
11430
|
-
catch (
|
|
12124
|
+
catch (e_23_1) { e_23 = { error: e_23_1 }; }
|
|
11431
12125
|
finally {
|
|
11432
12126
|
try {
|
|
11433
12127
|
if (stageKeys_1_1 && !stageKeys_1_1.done && (_a = stageKeys_1.return)) _a.call(stageKeys_1);
|
|
11434
12128
|
}
|
|
11435
|
-
finally { if (
|
|
12129
|
+
finally { if (e_23) throw e_23.error; }
|
|
11436
12130
|
}
|
|
11437
12131
|
}
|
|
11438
12132
|
return false;
|
|
@@ -11539,7 +12233,7 @@ function isRegexMatchCondition(value) {
|
|
|
11539
12233
|
return false;
|
|
11540
12234
|
}
|
|
11541
12235
|
function findRegexMatchInMatchObject(match, prefix) {
|
|
11542
|
-
var
|
|
12236
|
+
var e_25, _a, e_26, _b;
|
|
11543
12237
|
if (prefix === void 0) { prefix = ''; }
|
|
11544
12238
|
if (Array.isArray(match)) {
|
|
11545
12239
|
try {
|
|
@@ -11551,12 +12245,12 @@ function findRegexMatchInMatchObject(match, prefix) {
|
|
|
11551
12245
|
}
|
|
11552
12246
|
}
|
|
11553
12247
|
}
|
|
11554
|
-
catch (
|
|
12248
|
+
catch (e_25_1) { e_25 = { error: e_25_1 }; }
|
|
11555
12249
|
finally {
|
|
11556
12250
|
try {
|
|
11557
12251
|
if (match_1_1 && !match_1_1.done && (_a = match_1.return)) _a.call(match_1);
|
|
11558
12252
|
}
|
|
11559
|
-
finally { if (
|
|
12253
|
+
finally { if (e_25) throw e_25.error; }
|
|
11560
12254
|
}
|
|
11561
12255
|
return null;
|
|
11562
12256
|
}
|
|
@@ -11587,12 +12281,12 @@ function findRegexMatchInMatchObject(match, prefix) {
|
|
|
11587
12281
|
}
|
|
11588
12282
|
}
|
|
11589
12283
|
}
|
|
11590
|
-
catch (
|
|
12284
|
+
catch (e_26_1) { e_26 = { error: e_26_1 }; }
|
|
11591
12285
|
finally {
|
|
11592
12286
|
try {
|
|
11593
12287
|
if (keys_2_1 && !keys_2_1.done && (_b = keys_2.return)) _b.call(keys_2);
|
|
11594
12288
|
}
|
|
11595
|
-
finally { if (
|
|
12289
|
+
finally { if (e_26) throw e_26.error; }
|
|
11596
12290
|
}
|
|
11597
12291
|
return null;
|
|
11598
12292
|
}
|
|
@@ -11816,7 +12510,7 @@ function collectMatchFieldsByCondition(match, predicate, prefix) {
|
|
|
11816
12510
|
return results;
|
|
11817
12511
|
}
|
|
11818
12512
|
function findMatchConditionForField(match, targetField, prefix) {
|
|
11819
|
-
var
|
|
12513
|
+
var e_27, _a, e_28, _b;
|
|
11820
12514
|
if (prefix === void 0) { prefix = ''; }
|
|
11821
12515
|
if (!match || typeof match !== 'object') {
|
|
11822
12516
|
return undefined;
|
|
@@ -11831,12 +12525,12 @@ function findMatchConditionForField(match, targetField, prefix) {
|
|
|
11831
12525
|
}
|
|
11832
12526
|
}
|
|
11833
12527
|
}
|
|
11834
|
-
catch (
|
|
12528
|
+
catch (e_27_1) { e_27 = { error: e_27_1 }; }
|
|
11835
12529
|
finally {
|
|
11836
12530
|
try {
|
|
11837
12531
|
if (match_2_1 && !match_2_1.done && (_a = match_2.return)) _a.call(match_2);
|
|
11838
12532
|
}
|
|
11839
|
-
finally { if (
|
|
12533
|
+
finally { if (e_27) throw e_27.error; }
|
|
11840
12534
|
}
|
|
11841
12535
|
return undefined;
|
|
11842
12536
|
}
|
|
@@ -11863,12 +12557,12 @@ function findMatchConditionForField(match, targetField, prefix) {
|
|
|
11863
12557
|
}
|
|
11864
12558
|
}
|
|
11865
12559
|
}
|
|
11866
|
-
catch (
|
|
12560
|
+
catch (e_28_1) { e_28 = { error: e_28_1 }; }
|
|
11867
12561
|
finally {
|
|
11868
12562
|
try {
|
|
11869
12563
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
11870
12564
|
}
|
|
11871
|
-
finally { if (
|
|
12565
|
+
finally { if (e_28) throw e_28.error; }
|
|
11872
12566
|
}
|
|
11873
12567
|
return undefined;
|
|
11874
12568
|
}
|
|
@@ -12014,7 +12708,7 @@ function detectIdLikeValue(value) {
|
|
|
12014
12708
|
return false;
|
|
12015
12709
|
}
|
|
12016
12710
|
function detectChemicalIdFromProbe(probeDocs, fields) {
|
|
12017
|
-
var
|
|
12711
|
+
var e_29, _a, e_30, _b;
|
|
12018
12712
|
if (!Array.isArray(probeDocs) || !probeDocs.length) {
|
|
12019
12713
|
return false;
|
|
12020
12714
|
}
|
|
@@ -12026,7 +12720,7 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
|
|
|
12026
12720
|
for (var probeDocs_1 = __values(probeDocs), probeDocs_1_1 = probeDocs_1.next(); !probeDocs_1_1.done; probeDocs_1_1 = probeDocs_1.next()) {
|
|
12027
12721
|
var doc = probeDocs_1_1.value;
|
|
12028
12722
|
try {
|
|
12029
|
-
for (var targets_1 = (
|
|
12723
|
+
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
12724
|
var field = targets_1_1.value;
|
|
12031
12725
|
var value = getValueAtPath(doc, field);
|
|
12032
12726
|
if (Array.isArray(value)) {
|
|
@@ -12039,21 +12733,21 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
|
|
|
12039
12733
|
}
|
|
12040
12734
|
}
|
|
12041
12735
|
}
|
|
12042
|
-
catch (
|
|
12736
|
+
catch (e_30_1) { e_30 = { error: e_30_1 }; }
|
|
12043
12737
|
finally {
|
|
12044
12738
|
try {
|
|
12045
12739
|
if (targets_1_1 && !targets_1_1.done && (_b = targets_1.return)) _b.call(targets_1);
|
|
12046
12740
|
}
|
|
12047
|
-
finally { if (
|
|
12741
|
+
finally { if (e_30) throw e_30.error; }
|
|
12048
12742
|
}
|
|
12049
12743
|
}
|
|
12050
12744
|
}
|
|
12051
|
-
catch (
|
|
12745
|
+
catch (e_29_1) { e_29 = { error: e_29_1 }; }
|
|
12052
12746
|
finally {
|
|
12053
12747
|
try {
|
|
12054
12748
|
if (probeDocs_1_1 && !probeDocs_1_1.done && (_a = probeDocs_1.return)) _a.call(probeDocs_1);
|
|
12055
12749
|
}
|
|
12056
|
-
finally { if (
|
|
12750
|
+
finally { if (e_29) throw e_29.error; }
|
|
12057
12751
|
}
|
|
12058
12752
|
return false;
|
|
12059
12753
|
}
|
|
@@ -12274,8 +12968,8 @@ function buildChemicalIdFieldCandidates(field) {
|
|
|
12274
12968
|
}
|
|
12275
12969
|
function applyChemicalNameLookupFallbackToQuery(params) {
|
|
12276
12970
|
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
|
|
12971
|
+
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;
|
|
12972
|
+
var e_31, _a;
|
|
12279
12973
|
var _b;
|
|
12280
12974
|
return __generator(this, function (_c) {
|
|
12281
12975
|
switch (_c.label) {
|
|
@@ -12299,7 +12993,7 @@ function applyChemicalNameLookupFallbackToQuery(params) {
|
|
|
12299
12993
|
case 1:
|
|
12300
12994
|
collectionNames = _c.sent();
|
|
12301
12995
|
candidates = resolveIdLookupCandidates('chemical', collectionNames);
|
|
12302
|
-
|
|
12996
|
+
_loop_11 = function (candidate) {
|
|
12303
12997
|
var candidateHasClientScope, _d, candidateProbe, lookup, idFields, baseMatch, orConditions, nextMatch;
|
|
12304
12998
|
return __generator(this, function (_e) {
|
|
12305
12999
|
switch (_e.label) {
|
|
@@ -12377,25 +13071,25 @@ function applyChemicalNameLookupFallbackToQuery(params) {
|
|
|
12377
13071
|
case 3:
|
|
12378
13072
|
if (!!candidates_1_1.done) return [3 /*break*/, 6];
|
|
12379
13073
|
candidate = candidates_1_1.value;
|
|
12380
|
-
return [5 /*yield**/,
|
|
13074
|
+
return [5 /*yield**/, _loop_11(candidate)];
|
|
12381
13075
|
case 4:
|
|
12382
|
-
|
|
12383
|
-
if (typeof
|
|
12384
|
-
return [2 /*return*/,
|
|
13076
|
+
state_8 = _c.sent();
|
|
13077
|
+
if (typeof state_8 === "object")
|
|
13078
|
+
return [2 /*return*/, state_8.value];
|
|
12385
13079
|
_c.label = 5;
|
|
12386
13080
|
case 5:
|
|
12387
13081
|
candidates_1_1 = candidates_1.next();
|
|
12388
13082
|
return [3 /*break*/, 3];
|
|
12389
13083
|
case 6: return [3 /*break*/, 9];
|
|
12390
13084
|
case 7:
|
|
12391
|
-
|
|
12392
|
-
|
|
13085
|
+
e_31_1 = _c.sent();
|
|
13086
|
+
e_31 = { error: e_31_1 };
|
|
12393
13087
|
return [3 /*break*/, 9];
|
|
12394
13088
|
case 8:
|
|
12395
13089
|
try {
|
|
12396
13090
|
if (candidates_1_1 && !candidates_1_1.done && (_a = candidates_1.return)) _a.call(candidates_1);
|
|
12397
13091
|
}
|
|
12398
|
-
finally { if (
|
|
13092
|
+
finally { if (e_31) throw e_31.error; }
|
|
12399
13093
|
return [7 /*endfinally*/];
|
|
12400
13094
|
case 9: return [2 /*return*/, null];
|
|
12401
13095
|
}
|
|
@@ -12489,8 +13183,8 @@ function lookupIdsForNameMatch(params) {
|
|
|
12489
13183
|
}
|
|
12490
13184
|
function applyIdLookupFallbackToQuery(params) {
|
|
12491
13185
|
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
|
|
13186
|
+
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;
|
|
13187
|
+
var e_33, _c, e_32, _d;
|
|
12494
13188
|
var _e;
|
|
12495
13189
|
return __generator(this, function (_f) {
|
|
12496
13190
|
switch (_f.label) {
|
|
@@ -12560,7 +13254,7 @@ function applyIdLookupFallbackToQuery(params) {
|
|
|
12560
13254
|
_f.label = 5;
|
|
12561
13255
|
case 5:
|
|
12562
13256
|
_f.trys.push([5, 14, 15, 16]);
|
|
12563
|
-
candidates_2 = (
|
|
13257
|
+
candidates_2 = (e_32 = void 0, __values(candidates)), candidates_2_1 = candidates_2.next();
|
|
12564
13258
|
_f.label = 6;
|
|
12565
13259
|
case 6:
|
|
12566
13260
|
if (!!candidates_2_1.done) return [3 /*break*/, 13];
|
|
@@ -12627,28 +13321,28 @@ function applyIdLookupFallbackToQuery(params) {
|
|
|
12627
13321
|
return [3 /*break*/, 6];
|
|
12628
13322
|
case 13: return [3 /*break*/, 16];
|
|
12629
13323
|
case 14:
|
|
12630
|
-
|
|
12631
|
-
|
|
13324
|
+
e_32_1 = _f.sent();
|
|
13325
|
+
e_32 = { error: e_32_1 };
|
|
12632
13326
|
return [3 /*break*/, 16];
|
|
12633
13327
|
case 15:
|
|
12634
13328
|
try {
|
|
12635
13329
|
if (candidates_2_1 && !candidates_2_1.done && (_d = candidates_2.return)) _d.call(candidates_2);
|
|
12636
13330
|
}
|
|
12637
|
-
finally { if (
|
|
13331
|
+
finally { if (e_32) throw e_32.error; }
|
|
12638
13332
|
return [7 /*endfinally*/];
|
|
12639
13333
|
case 16:
|
|
12640
13334
|
conditions_1_1 = conditions_1.next();
|
|
12641
13335
|
return [3 /*break*/, 4];
|
|
12642
13336
|
case 17: return [3 /*break*/, 20];
|
|
12643
13337
|
case 18:
|
|
12644
|
-
|
|
12645
|
-
|
|
13338
|
+
e_33_1 = _f.sent();
|
|
13339
|
+
e_33 = { error: e_33_1 };
|
|
12646
13340
|
return [3 /*break*/, 20];
|
|
12647
13341
|
case 19:
|
|
12648
13342
|
try {
|
|
12649
13343
|
if (conditions_1_1 && !conditions_1_1.done && (_c = conditions_1.return)) _c.call(conditions_1);
|
|
12650
13344
|
}
|
|
12651
|
-
finally { if (
|
|
13345
|
+
finally { if (e_33) throw e_33.error; }
|
|
12652
13346
|
return [7 /*endfinally*/];
|
|
12653
13347
|
case 20: return [2 /*return*/, null];
|
|
12654
13348
|
}
|
|
@@ -13071,8 +13765,8 @@ function resolveAssistantSurfaceFileCandidates(baseName) {
|
|
|
13071
13765
|
}
|
|
13072
13766
|
function readFirstAssistantSurfaceFile(candidates) {
|
|
13073
13767
|
return __awaiter(this, void 0, void 0, function () {
|
|
13074
|
-
var candidates_3, candidates_3_1, candidate, normalized, _a,
|
|
13075
|
-
var
|
|
13768
|
+
var candidates_3, candidates_3_1, candidate, normalized, _a, e_34_1;
|
|
13769
|
+
var e_34, _b;
|
|
13076
13770
|
return __generator(this, function (_c) {
|
|
13077
13771
|
switch (_c.label) {
|
|
13078
13772
|
case 0:
|
|
@@ -13099,14 +13793,14 @@ function readFirstAssistantSurfaceFile(candidates) {
|
|
|
13099
13793
|
return [3 /*break*/, 1];
|
|
13100
13794
|
case 6: return [3 /*break*/, 9];
|
|
13101
13795
|
case 7:
|
|
13102
|
-
|
|
13103
|
-
|
|
13796
|
+
e_34_1 = _c.sent();
|
|
13797
|
+
e_34 = { error: e_34_1 };
|
|
13104
13798
|
return [3 /*break*/, 9];
|
|
13105
13799
|
case 8:
|
|
13106
13800
|
try {
|
|
13107
13801
|
if (candidates_3_1 && !candidates_3_1.done && (_b = candidates_3.return)) _b.call(candidates_3);
|
|
13108
13802
|
}
|
|
13109
|
-
finally { if (
|
|
13803
|
+
finally { if (e_34) throw e_34.error; }
|
|
13110
13804
|
return [7 /*endfinally*/];
|
|
13111
13805
|
case 9: return [2 /*return*/, ''];
|
|
13112
13806
|
}
|
|
@@ -14180,7 +14874,10 @@ var AI_ASSISTANT_BRIDGE_COLLECTION_ALIAS_OPTIONS = {
|
|
|
14180
14874
|
purchaseorder: AI_ASSISTANT_PURCHASE_COLLECTION_ALIAS_CANDIDATES,
|
|
14181
14875
|
purchaseorders: AI_ASSISTANT_PURCHASE_COLLECTION_ALIAS_CANDIDATES
|
|
14182
14876
|
};
|
|
14183
|
-
var AI_ASSISTANT_DIRECT_COLLECTION_FALLBACK_ALLOWLIST = new Set([
|
|
14877
|
+
var AI_ASSISTANT_DIRECT_COLLECTION_FALLBACK_ALLOWLIST = new Set([
|
|
14878
|
+
'customers',
|
|
14879
|
+
'clients'
|
|
14880
|
+
]);
|
|
14184
14881
|
var AI_ASSISTANT_SUPPORT_COLLECTION_FALLBACKS = [
|
|
14185
14882
|
'support-tickets',
|
|
14186
14883
|
'supporttickets',
|
|
@@ -14330,7 +15027,7 @@ function resolveAssistantRelationshipFallbackCandidates(collection, collectionNa
|
|
|
14330
15027
|
var depthByFamily = new Map();
|
|
14331
15028
|
var queue = [{ family: currentFamily, depth: 0 }];
|
|
14332
15029
|
depthByFamily.set(currentFamily, 0);
|
|
14333
|
-
var
|
|
15030
|
+
var _loop_12 = function () {
|
|
14334
15031
|
var current = queue.shift();
|
|
14335
15032
|
if (!current) {
|
|
14336
15033
|
return "continue";
|
|
@@ -14363,7 +15060,7 @@ function resolveAssistantRelationshipFallbackCandidates(collection, collectionNa
|
|
|
14363
15060
|
});
|
|
14364
15061
|
};
|
|
14365
15062
|
while (queue.length) {
|
|
14366
|
-
|
|
15063
|
+
_loop_12();
|
|
14367
15064
|
}
|
|
14368
15065
|
var preferredCollections = Array.from(familyScores.entries())
|
|
14369
15066
|
.map(function (_a) {
|
|
@@ -14851,7 +15548,7 @@ function resolveAssistantNestedPrefixCollectionCandidates(params) {
|
|
|
14851
15548
|
function resolveAssistantNestedAggregateFallbacks(params) {
|
|
14852
15549
|
return __awaiter(this, void 0, void 0, function () {
|
|
14853
15550
|
var prefixes, collectionNames, fallbacks, seen, prefixes_1, prefixes_1_1, prefix, rewrite, candidates, candidates_4, candidates_4_1, candidate, normalizedPipeline, key;
|
|
14854
|
-
var
|
|
15551
|
+
var e_35, _a, e_36, _b;
|
|
14855
15552
|
return __generator(this, function (_c) {
|
|
14856
15553
|
switch (_c.label) {
|
|
14857
15554
|
case 0:
|
|
@@ -14881,7 +15578,7 @@ function resolveAssistantNestedAggregateFallbacks(params) {
|
|
|
14881
15578
|
triedCollections: params.triedCollections
|
|
14882
15579
|
});
|
|
14883
15580
|
try {
|
|
14884
|
-
for (candidates_4 = (
|
|
15581
|
+
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
15582
|
candidate = candidates_4_1.value;
|
|
14886
15583
|
normalizedPipeline = normalizeAssistantAggregatePipeline(rewrite.pipeline, candidate);
|
|
14887
15584
|
if (!normalizedPipeline.length || containsForbiddenMongoOperators(normalizedPipeline)) {
|
|
@@ -14903,21 +15600,21 @@ function resolveAssistantNestedAggregateFallbacks(params) {
|
|
|
14903
15600
|
}
|
|
14904
15601
|
}
|
|
14905
15602
|
}
|
|
14906
|
-
catch (
|
|
15603
|
+
catch (e_36_1) { e_36 = { error: e_36_1 }; }
|
|
14907
15604
|
finally {
|
|
14908
15605
|
try {
|
|
14909
15606
|
if (candidates_4_1 && !candidates_4_1.done && (_b = candidates_4.return)) _b.call(candidates_4);
|
|
14910
15607
|
}
|
|
14911
|
-
finally { if (
|
|
15608
|
+
finally { if (e_36) throw e_36.error; }
|
|
14912
15609
|
}
|
|
14913
15610
|
}
|
|
14914
15611
|
}
|
|
14915
|
-
catch (
|
|
15612
|
+
catch (e_35_1) { e_35 = { error: e_35_1 }; }
|
|
14916
15613
|
finally {
|
|
14917
15614
|
try {
|
|
14918
15615
|
if (prefixes_1_1 && !prefixes_1_1.done && (_a = prefixes_1.return)) _a.call(prefixes_1);
|
|
14919
15616
|
}
|
|
14920
|
-
finally { if (
|
|
15617
|
+
finally { if (e_35) throw e_35.error; }
|
|
14921
15618
|
}
|
|
14922
15619
|
return [2 /*return*/, fallbacks];
|
|
14923
15620
|
}
|
|
@@ -14979,8 +15676,8 @@ function doesAssistantCollectionExistInDb(db, collection) {
|
|
|
14979
15676
|
}
|
|
14980
15677
|
function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
14981
15678
|
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
|
|
15679
|
+
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;
|
|
15680
|
+
var e_38, _b, e_37, _c, e_39, _d;
|
|
14984
15681
|
var _e;
|
|
14985
15682
|
if (dbName === void 0) { dbName = ''; }
|
|
14986
15683
|
return __generator(this, function (_f) {
|
|
@@ -15022,12 +15719,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
15022
15719
|
}
|
|
15023
15720
|
}
|
|
15024
15721
|
}
|
|
15025
|
-
catch (
|
|
15722
|
+
catch (e_38_1) { e_38 = { error: e_38_1 }; }
|
|
15026
15723
|
finally {
|
|
15027
15724
|
try {
|
|
15028
15725
|
if (candidates_5_1 && !candidates_5_1.done && (_b = candidates_5.return)) _b.call(candidates_5);
|
|
15029
15726
|
}
|
|
15030
|
-
finally { if (
|
|
15727
|
+
finally { if (e_38) throw e_38.error; }
|
|
15031
15728
|
}
|
|
15032
15729
|
}
|
|
15033
15730
|
if (!(db && dbName)) return [3 /*break*/, 4];
|
|
@@ -15073,14 +15770,14 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
15073
15770
|
return [3 /*break*/, 6];
|
|
15074
15771
|
case 9: return [3 /*break*/, 12];
|
|
15075
15772
|
case 10:
|
|
15076
|
-
|
|
15077
|
-
|
|
15773
|
+
e_37_1 = _f.sent();
|
|
15774
|
+
e_37 = { error: e_37_1 };
|
|
15078
15775
|
return [3 /*break*/, 12];
|
|
15079
15776
|
case 11:
|
|
15080
15777
|
try {
|
|
15081
15778
|
if (candidates_6_1 && !candidates_6_1.done && (_c = candidates_6.return)) _c.call(candidates_6);
|
|
15082
15779
|
}
|
|
15083
|
-
finally { if (
|
|
15780
|
+
finally { if (e_37) throw e_37.error; }
|
|
15084
15781
|
return [7 /*endfinally*/];
|
|
15085
15782
|
case 12:
|
|
15086
15783
|
try {
|
|
@@ -15091,12 +15788,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
15091
15788
|
}
|
|
15092
15789
|
}
|
|
15093
15790
|
}
|
|
15094
|
-
catch (
|
|
15791
|
+
catch (e_39_1) { e_39 = { error: e_39_1 }; }
|
|
15095
15792
|
finally {
|
|
15096
15793
|
try {
|
|
15097
15794
|
if (candidates_7_1 && !candidates_7_1.done && (_d = candidates_7.return)) _d.call(candidates_7);
|
|
15098
15795
|
}
|
|
15099
|
-
finally { if (
|
|
15796
|
+
finally { if (e_39) throw e_39.error; }
|
|
15100
15797
|
}
|
|
15101
15798
|
throw new Error('AI assistant report builder bridge: No queryable collection could be resolved.');
|
|
15102
15799
|
}
|
|
@@ -15104,7 +15801,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
15104
15801
|
});
|
|
15105
15802
|
}
|
|
15106
15803
|
function findQueryDateField(query) {
|
|
15107
|
-
var
|
|
15804
|
+
var e_40, _a, e_41, _b;
|
|
15108
15805
|
if (!query || typeof query !== 'object') {
|
|
15109
15806
|
return null;
|
|
15110
15807
|
}
|
|
@@ -15118,12 +15815,12 @@ function findQueryDateField(query) {
|
|
|
15118
15815
|
}
|
|
15119
15816
|
}
|
|
15120
15817
|
}
|
|
15121
|
-
catch (
|
|
15818
|
+
catch (e_40_1) { e_40 = { error: e_40_1 }; }
|
|
15122
15819
|
finally {
|
|
15123
15820
|
try {
|
|
15124
15821
|
if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
|
|
15125
15822
|
}
|
|
15126
|
-
finally { if (
|
|
15823
|
+
finally { if (e_40) throw e_40.error; }
|
|
15127
15824
|
}
|
|
15128
15825
|
return null;
|
|
15129
15826
|
}
|
|
@@ -15142,12 +15839,12 @@ function findQueryDateField(query) {
|
|
|
15142
15839
|
}
|
|
15143
15840
|
}
|
|
15144
15841
|
}
|
|
15145
|
-
catch (
|
|
15842
|
+
catch (e_41_1) { e_41 = { error: e_41_1 }; }
|
|
15146
15843
|
finally {
|
|
15147
15844
|
try {
|
|
15148
15845
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
15149
15846
|
}
|
|
15150
|
-
finally { if (
|
|
15847
|
+
finally { if (e_41) throw e_41.error; }
|
|
15151
15848
|
}
|
|
15152
15849
|
return null;
|
|
15153
15850
|
}
|
|
@@ -15330,7 +16027,7 @@ function expandAggregateDateMatchFallback(pipeline, schemaFields) {
|
|
|
15330
16027
|
if (!Array.isArray(pipeline)) {
|
|
15331
16028
|
return null;
|
|
15332
16029
|
}
|
|
15333
|
-
var
|
|
16030
|
+
var _loop_13 = function (i) {
|
|
15334
16031
|
var stage = pipeline[i];
|
|
15335
16032
|
if (!stage || typeof stage !== 'object' || !stage.$match || typeof stage.$match !== 'object') {
|
|
15336
16033
|
return "continue";
|
|
@@ -15378,9 +16075,9 @@ function expandAggregateDateMatchFallback(pipeline, schemaFields) {
|
|
|
15378
16075
|
return { value: { pipeline: updated, fields: Array.from(addedFields) } };
|
|
15379
16076
|
};
|
|
15380
16077
|
for (var i = 0; i < pipeline.length; i += 1) {
|
|
15381
|
-
var
|
|
15382
|
-
if (typeof
|
|
15383
|
-
return
|
|
16078
|
+
var state_9 = _loop_13(i);
|
|
16079
|
+
if (typeof state_9 === "object")
|
|
16080
|
+
return state_9.value;
|
|
15384
16081
|
}
|
|
15385
16082
|
return null;
|
|
15386
16083
|
}
|
|
@@ -15396,7 +16093,7 @@ function resolveQueryDateFieldFallback(query) {
|
|
|
15396
16093
|
return { from: dateField, to: fallback };
|
|
15397
16094
|
}
|
|
15398
16095
|
function containsForbiddenMongoOperators(value) {
|
|
15399
|
-
var
|
|
16096
|
+
var e_42, _a;
|
|
15400
16097
|
if (!value || typeof value !== 'object') {
|
|
15401
16098
|
return false;
|
|
15402
16099
|
}
|
|
@@ -15415,12 +16112,12 @@ function containsForbiddenMongoOperators(value) {
|
|
|
15415
16112
|
}
|
|
15416
16113
|
}
|
|
15417
16114
|
}
|
|
15418
|
-
catch (
|
|
16115
|
+
catch (e_42_1) { e_42 = { error: e_42_1 }; }
|
|
15419
16116
|
finally {
|
|
15420
16117
|
try {
|
|
15421
16118
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
15422
16119
|
}
|
|
15423
|
-
finally { if (
|
|
16120
|
+
finally { if (e_42) throw e_42.error; }
|
|
15424
16121
|
}
|
|
15425
16122
|
return false;
|
|
15426
16123
|
}
|
|
@@ -15835,8 +16532,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
|
|
|
15835
16532
|
}
|
|
15836
16533
|
function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
15837
16534
|
return __awaiter(this, void 0, void 0, function () {
|
|
15838
|
-
var _a, _b, _c, _d, message, payload, status_1,
|
|
15839
|
-
var _e,
|
|
16535
|
+
var _a, _b, _c, _d, message, payload, status_1, e_43_1;
|
|
16536
|
+
var _e, e_43, _f, _g;
|
|
15840
16537
|
return __generator(this, function (_h) {
|
|
15841
16538
|
switch (_h.label) {
|
|
15842
16539
|
case 0:
|
|
@@ -15863,8 +16560,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
15863
16560
|
return [3 /*break*/, 1];
|
|
15864
16561
|
case 4: return [3 /*break*/, 11];
|
|
15865
16562
|
case 5:
|
|
15866
|
-
|
|
15867
|
-
|
|
16563
|
+
e_43_1 = _h.sent();
|
|
16564
|
+
e_43 = { error: e_43_1 };
|
|
15868
16565
|
return [3 /*break*/, 11];
|
|
15869
16566
|
case 6:
|
|
15870
16567
|
_h.trys.push([6, , 9, 10]);
|
|
@@ -15875,7 +16572,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
15875
16572
|
_h.label = 8;
|
|
15876
16573
|
case 8: return [3 /*break*/, 10];
|
|
15877
16574
|
case 9:
|
|
15878
|
-
if (
|
|
16575
|
+
if (e_43) throw e_43.error;
|
|
15879
16576
|
return [7 /*endfinally*/];
|
|
15880
16577
|
case 10: return [7 /*endfinally*/];
|
|
15881
16578
|
case 11: throw new CodexWorkerBootstrapError('Codex worker exited before completing.');
|
|
@@ -15885,7 +16582,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
15885
16582
|
}
|
|
15886
16583
|
function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler) {
|
|
15887
16584
|
return __awaiter(this, void 0, void 0, function () {
|
|
15888
|
-
var streamedOptions, codexClient, workerPath, codexClient,
|
|
16585
|
+
var streamedOptions, codexClient, workerPath, codexClient, error_10, codexClient;
|
|
15889
16586
|
return __generator(this, function (_a) {
|
|
15890
16587
|
switch (_a.label) {
|
|
15891
16588
|
case 0:
|
|
@@ -15906,11 +16603,11 @@ function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler)
|
|
|
15906
16603
|
return [4 /*yield*/, runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config, streamStatusHandler)];
|
|
15907
16604
|
case 6: return [2 /*return*/, _a.sent()];
|
|
15908
16605
|
case 7:
|
|
15909
|
-
|
|
15910
|
-
if (!(
|
|
15911
|
-
throw
|
|
16606
|
+
error_10 = _a.sent();
|
|
16607
|
+
if (!(error_10 instanceof CodexWorkerBootstrapError)) {
|
|
16608
|
+
throw error_10;
|
|
15912
16609
|
}
|
|
15913
|
-
console.error('Codex worker bootstrap failed, falling back to in-process run.',
|
|
16610
|
+
console.error('Codex worker bootstrap failed, falling back to in-process run.', error_10);
|
|
15914
16611
|
codexClient = getAssistantCodexClient(config);
|
|
15915
16612
|
return [4 /*yield*/, codexClient.run(prompt, streamedOptions)];
|
|
15916
16613
|
case 8: return [2 /*return*/, _a.sent()];
|
|
@@ -15948,7 +16645,7 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
15948
16645
|
timeoutMs = ((sanitizedOptions === null || sanitizedOptions === void 0 ? void 0 : sanitizedOptions.timeoutMs) || resolveCodexTimeoutMs()) + 15000;
|
|
15949
16646
|
timeoutController = new AbortController();
|
|
15950
16647
|
timeoutPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
15951
|
-
var
|
|
16648
|
+
var error_11;
|
|
15952
16649
|
return __generator(this, function (_a) {
|
|
15953
16650
|
switch (_a.label) {
|
|
15954
16651
|
case 0:
|
|
@@ -15958,11 +16655,11 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
15958
16655
|
_a.sent();
|
|
15959
16656
|
return [2 /*return*/, { type: 'timeout' }];
|
|
15960
16657
|
case 2:
|
|
15961
|
-
|
|
15962
|
-
if ((
|
|
16658
|
+
error_11 = _a.sent();
|
|
16659
|
+
if ((error_11 === null || error_11 === void 0 ? void 0 : error_11.name) === 'AbortError') {
|
|
15963
16660
|
return [2 /*return*/, { type: 'aborted' }];
|
|
15964
16661
|
}
|
|
15965
|
-
throw
|
|
16662
|
+
throw error_11;
|
|
15966
16663
|
case 3: return [2 /*return*/];
|
|
15967
16664
|
}
|
|
15968
16665
|
});
|
|
@@ -16207,8 +16904,8 @@ function buildAssistantWorkspaceRootCandidates(params) {
|
|
|
16207
16904
|
}
|
|
16208
16905
|
function resolveAssistantWorkspaceRoot() {
|
|
16209
16906
|
return __awaiter(this, void 0, void 0, function () {
|
|
16210
|
-
var candidates, firstExisting, candidates_8, candidates_8_1, candidate, _a, gitRoot,
|
|
16211
|
-
var
|
|
16907
|
+
var candidates, firstExisting, candidates_8, candidates_8_1, candidate, _a, gitRoot, e_44_1;
|
|
16908
|
+
var e_44, _b;
|
|
16212
16909
|
return __generator(this, function (_c) {
|
|
16213
16910
|
switch (_c.label) {
|
|
16214
16911
|
case 0:
|
|
@@ -16247,14 +16944,14 @@ function resolveAssistantWorkspaceRoot() {
|
|
|
16247
16944
|
return [3 /*break*/, 2];
|
|
16248
16945
|
case 7: return [3 /*break*/, 10];
|
|
16249
16946
|
case 8:
|
|
16250
|
-
|
|
16251
|
-
|
|
16947
|
+
e_44_1 = _c.sent();
|
|
16948
|
+
e_44 = { error: e_44_1 };
|
|
16252
16949
|
return [3 /*break*/, 10];
|
|
16253
16950
|
case 9:
|
|
16254
16951
|
try {
|
|
16255
16952
|
if (candidates_8_1 && !candidates_8_1.done && (_b = candidates_8.return)) _b.call(candidates_8);
|
|
16256
16953
|
}
|
|
16257
|
-
finally { if (
|
|
16954
|
+
finally { if (e_44) throw e_44.error; }
|
|
16258
16955
|
return [7 /*endfinally*/];
|
|
16259
16956
|
case 10:
|
|
16260
16957
|
if (firstExisting) {
|
|
@@ -16654,7 +17351,7 @@ var AI_ASSISTANT_BREAKDOWN_DIMENSION_STOPWORDS = new Set([
|
|
|
16654
17351
|
'by'
|
|
16655
17352
|
]);
|
|
16656
17353
|
function normalizeAssistantBreakdownDimension(value) {
|
|
16657
|
-
var
|
|
17354
|
+
var e_45, _a;
|
|
16658
17355
|
var normalized = normalizeOptionalString(value)
|
|
16659
17356
|
.toLowerCase()
|
|
16660
17357
|
.replace(/[^a-z0-9_\s-]+/g, ' ')
|
|
@@ -16686,12 +17383,12 @@ function normalizeAssistantBreakdownDimension(value) {
|
|
|
16686
17383
|
}
|
|
16687
17384
|
}
|
|
16688
17385
|
}
|
|
16689
|
-
catch (
|
|
17386
|
+
catch (e_45_1) { e_45 = { error: e_45_1 }; }
|
|
16690
17387
|
finally {
|
|
16691
17388
|
try {
|
|
16692
17389
|
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
|
|
16693
17390
|
}
|
|
16694
|
-
finally { if (
|
|
17391
|
+
finally { if (e_45) throw e_45.error; }
|
|
16695
17392
|
}
|
|
16696
17393
|
if (!kept.length) {
|
|
16697
17394
|
return '';
|
|
@@ -16889,7 +17586,7 @@ function resolveAssistantPlannerEnabled() {
|
|
|
16889
17586
|
return raw === undefined ? true : raw === true;
|
|
16890
17587
|
}
|
|
16891
17588
|
function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
|
|
16892
|
-
var
|
|
17589
|
+
var e_46, _a;
|
|
16893
17590
|
var _b;
|
|
16894
17591
|
if (isSuperAdmin === void 0) { isSuperAdmin = false; }
|
|
16895
17592
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
@@ -16903,12 +17600,12 @@ function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
|
|
|
16903
17600
|
}
|
|
16904
17601
|
}
|
|
16905
17602
|
}
|
|
16906
|
-
catch (
|
|
17603
|
+
catch (e_46_1) { e_46 = { error: e_46_1 }; }
|
|
16907
17604
|
finally {
|
|
16908
17605
|
try {
|
|
16909
17606
|
if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
|
|
16910
17607
|
}
|
|
16911
|
-
finally { if (
|
|
17608
|
+
finally { if (e_46) throw e_46.error; }
|
|
16912
17609
|
}
|
|
16913
17610
|
var normalizedRoutes = Array.from(unique);
|
|
16914
17611
|
var allowedRoutes = collectAssistantAllowedRoutesForUser(user, normalizedRoutes, isSuperAdmin);
|
|
@@ -17170,7 +17867,7 @@ function normalizeRouteMatchKey(value) {
|
|
|
17170
17867
|
return normalizeRouteKey(value).toLowerCase();
|
|
17171
17868
|
}
|
|
17172
17869
|
function buildClientRouteIndex() {
|
|
17173
|
-
var
|
|
17870
|
+
var e_47, _a;
|
|
17174
17871
|
var _b;
|
|
17175
17872
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
17176
17873
|
var set = new Set();
|
|
@@ -17189,12 +17886,12 @@ function buildClientRouteIndex() {
|
|
|
17189
17886
|
}
|
|
17190
17887
|
}
|
|
17191
17888
|
}
|
|
17192
|
-
catch (
|
|
17889
|
+
catch (e_47_1) { e_47 = { error: e_47_1 }; }
|
|
17193
17890
|
finally {
|
|
17194
17891
|
try {
|
|
17195
17892
|
if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
|
|
17196
17893
|
}
|
|
17197
|
-
finally { if (
|
|
17894
|
+
finally { if (e_47) throw e_47.error; }
|
|
17198
17895
|
}
|
|
17199
17896
|
return { set: set, map: map, size: routes.length };
|
|
17200
17897
|
}
|
|
@@ -17564,6 +18261,8 @@ var AI_ASSISTANT_CHANGE_HISTORY_PATTERNS = [
|
|
|
17564
18261
|
/\bwhat\s+did\s+(?:the\s+)?last\s+(?:system\s+)?update\s+(?:just\s+)?do\b/i,
|
|
17565
18262
|
/\blast\s+system\s+update\b[\s\S]{0,40}\bdo\b/i,
|
|
17566
18263
|
/\bhow\s+long\b.*\bbeen\s+(this|that)\s+way\b/i,
|
|
18264
|
+
/\bhow\s+long\b[\s\S]{0,120}\bbeen\s+on\s+(?:this|that|the)\s+(?:page|screen|dashboard|menu|route)\b/i,
|
|
18265
|
+
/\bhow\s+long\b[\s\S]{0,120}\bbeen\s+on\s+here\b/i,
|
|
17567
18266
|
/\bhow\s+long\b[\s\S]{0,80}\bbeen\s+around\b/i,
|
|
17568
18267
|
/\bsince\s+when\b/i,
|
|
17569
18268
|
/\bwhen\s+was\b[\s\S]{0,80}\bintroduced\b/i,
|
|
@@ -17972,8 +18671,8 @@ function shouldSkipAssistantGitDiscoveryDirectory(name) {
|
|
|
17972
18671
|
}
|
|
17973
18672
|
function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
17974
18673
|
return __awaiter(this, void 0, void 0, function () {
|
|
17975
|
-
var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b,
|
|
17976
|
-
var
|
|
18674
|
+
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;
|
|
18675
|
+
var e_48, _e, e_49, _f;
|
|
17977
18676
|
var _g;
|
|
17978
18677
|
return __generator(this, function (_h) {
|
|
17979
18678
|
switch (_h.label) {
|
|
@@ -18018,14 +18717,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
18018
18717
|
return [3 /*break*/, 3];
|
|
18019
18718
|
case 6: return [3 /*break*/, 9];
|
|
18020
18719
|
case 7:
|
|
18021
|
-
|
|
18022
|
-
|
|
18720
|
+
e_48_1 = _h.sent();
|
|
18721
|
+
e_48 = { error: e_48_1 };
|
|
18023
18722
|
return [3 /*break*/, 9];
|
|
18024
18723
|
case 8:
|
|
18025
18724
|
try {
|
|
18026
18725
|
if (configuredRoots_1_1 && !configuredRoots_1_1.done && (_e = configuredRoots_1.return)) _e.call(configuredRoots_1);
|
|
18027
18726
|
}
|
|
18028
|
-
finally { if (
|
|
18727
|
+
finally { if (e_48) throw e_48.error; }
|
|
18029
18728
|
return [7 /*endfinally*/];
|
|
18030
18729
|
case 9:
|
|
18031
18730
|
queue = [];
|
|
@@ -18065,7 +18764,7 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
18065
18764
|
return [3 /*break*/, 14];
|
|
18066
18765
|
case 14:
|
|
18067
18766
|
_h.trys.push([14, 21, 22, 23]);
|
|
18068
|
-
entries_1 = (
|
|
18767
|
+
entries_1 = (e_49 = void 0, __values(entries)), entries_1_1 = entries_1.next();
|
|
18069
18768
|
_h.label = 15;
|
|
18070
18769
|
case 15:
|
|
18071
18770
|
if (!!entries_1_1.done) return [3 /*break*/, 20];
|
|
@@ -18104,14 +18803,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
|
|
|
18104
18803
|
return [3 /*break*/, 15];
|
|
18105
18804
|
case 20: return [3 /*break*/, 23];
|
|
18106
18805
|
case 21:
|
|
18107
|
-
|
|
18108
|
-
|
|
18806
|
+
e_49_1 = _h.sent();
|
|
18807
|
+
e_49 = { error: e_49_1 };
|
|
18109
18808
|
return [3 /*break*/, 23];
|
|
18110
18809
|
case 22:
|
|
18111
18810
|
try {
|
|
18112
18811
|
if (entries_1_1 && !entries_1_1.done && (_f = entries_1.return)) _f.call(entries_1);
|
|
18113
18812
|
}
|
|
18114
|
-
finally { if (
|
|
18813
|
+
finally { if (e_49) throw e_49.error; }
|
|
18115
18814
|
return [7 /*endfinally*/];
|
|
18116
18815
|
case 23: return [3 /*break*/, 10];
|
|
18117
18816
|
case 24: return [2 /*return*/, roots];
|
|
@@ -18408,8 +19107,8 @@ function syncAssistantGitMirror(repoUrl) {
|
|
|
18408
19107
|
}
|
|
18409
19108
|
function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
18410
19109
|
return __awaiter(this, void 0, void 0, function () {
|
|
18411
|
-
var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot,
|
|
18412
|
-
var
|
|
19110
|
+
var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot, e_50_1;
|
|
19111
|
+
var e_50, _a;
|
|
18413
19112
|
return __generator(this, function (_b) {
|
|
18414
19113
|
switch (_b.label) {
|
|
18415
19114
|
case 0: return [4 /*yield*/, resolveAssistantWorkspaceGitRoots(workspaceRoot)];
|
|
@@ -18443,14 +19142,14 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
|
18443
19142
|
return [3 /*break*/, 3];
|
|
18444
19143
|
case 6: return [3 /*break*/, 9];
|
|
18445
19144
|
case 7:
|
|
18446
|
-
|
|
18447
|
-
|
|
19145
|
+
e_50_1 = _b.sent();
|
|
19146
|
+
e_50 = { error: e_50_1 };
|
|
18448
19147
|
return [3 /*break*/, 9];
|
|
18449
19148
|
case 8:
|
|
18450
19149
|
try {
|
|
18451
19150
|
if (repoUrls_1_1 && !repoUrls_1_1.done && (_a = repoUrls_1.return)) _a.call(repoUrls_1);
|
|
18452
19151
|
}
|
|
18453
|
-
finally { if (
|
|
19152
|
+
finally { if (e_50) throw e_50.error; }
|
|
18454
19153
|
return [7 /*endfinally*/];
|
|
18455
19154
|
case 9: return [2 /*return*/, mirroredRoots];
|
|
18456
19155
|
}
|
|
@@ -18459,8 +19158,8 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
|
|
|
18459
19158
|
}
|
|
18460
19159
|
function resolveAssistantChangeHistoryFastPathResponse(params) {
|
|
18461
19160
|
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
|
|
19161
|
+
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;
|
|
19162
|
+
var e_51, _f;
|
|
18464
19163
|
return __generator(this, function (_g) {
|
|
18465
19164
|
switch (_g.label) {
|
|
18466
19165
|
case 0:
|
|
@@ -18582,14 +19281,14 @@ function resolveAssistantChangeHistoryFastPathResponse(params) {
|
|
|
18582
19281
|
return [3 /*break*/, 7];
|
|
18583
19282
|
case 20: return [3 /*break*/, 23];
|
|
18584
19283
|
case 21:
|
|
18585
|
-
|
|
18586
|
-
|
|
19284
|
+
e_51_1 = _g.sent();
|
|
19285
|
+
e_51 = { error: e_51_1 };
|
|
18587
19286
|
return [3 /*break*/, 23];
|
|
18588
19287
|
case 22:
|
|
18589
19288
|
try {
|
|
18590
19289
|
if (gitRoots_1_1 && !gitRoots_1_1.done && (_f = gitRoots_1.return)) _f.call(gitRoots_1);
|
|
18591
19290
|
}
|
|
18592
|
-
finally { if (
|
|
19291
|
+
finally { if (e_51) throw e_51.error; }
|
|
18593
19292
|
return [7 /*endfinally*/];
|
|
18594
19293
|
case 23:
|
|
18595
19294
|
if (bestFallback) {
|
|
@@ -18770,7 +19469,7 @@ function sanitizeAssistantResponse(value) {
|
|
|
18770
19469
|
return normalizeAssistantRoutes(normalizedCurrency);
|
|
18771
19470
|
}
|
|
18772
19471
|
function evaluateAssistantGuardrails(message) {
|
|
18773
|
-
var
|
|
19472
|
+
var e_52, _a;
|
|
18774
19473
|
var normalized = String(message || '').toLowerCase();
|
|
18775
19474
|
var patterns = [
|
|
18776
19475
|
{
|
|
@@ -18816,12 +19515,12 @@ function evaluateAssistantGuardrails(message) {
|
|
|
18816
19515
|
}
|
|
18817
19516
|
}
|
|
18818
19517
|
}
|
|
18819
|
-
catch (
|
|
19518
|
+
catch (e_52_1) { e_52 = { error: e_52_1 }; }
|
|
18820
19519
|
finally {
|
|
18821
19520
|
try {
|
|
18822
19521
|
if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
|
|
18823
19522
|
}
|
|
18824
|
-
finally { if (
|
|
19523
|
+
finally { if (e_52) throw e_52.error; }
|
|
18825
19524
|
}
|
|
18826
19525
|
return null;
|
|
18827
19526
|
}
|
|
@@ -18936,7 +19635,7 @@ function tokenizeArithmeticExpression(expression) {
|
|
|
18936
19635
|
return tokens;
|
|
18937
19636
|
}
|
|
18938
19637
|
function evaluateArithmeticExpression(expression) {
|
|
18939
|
-
var
|
|
19638
|
+
var e_53, _a, e_54, _b;
|
|
18940
19639
|
var tokens = tokenizeArithmeticExpression(expression);
|
|
18941
19640
|
if (!tokens || !tokens.length) {
|
|
18942
19641
|
return null;
|
|
@@ -18993,12 +19692,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
18993
19692
|
prevToken = token;
|
|
18994
19693
|
}
|
|
18995
19694
|
}
|
|
18996
|
-
catch (
|
|
19695
|
+
catch (e_53_1) { e_53 = { error: e_53_1 }; }
|
|
18997
19696
|
finally {
|
|
18998
19697
|
try {
|
|
18999
19698
|
if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
|
|
19000
19699
|
}
|
|
19001
|
-
finally { if (
|
|
19700
|
+
finally { if (e_53) throw e_53.error; }
|
|
19002
19701
|
}
|
|
19003
19702
|
while (ops.length) {
|
|
19004
19703
|
var op = ops.pop();
|
|
@@ -19038,12 +19737,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
19038
19737
|
stack.push(Number(token));
|
|
19039
19738
|
}
|
|
19040
19739
|
}
|
|
19041
|
-
catch (
|
|
19740
|
+
catch (e_54_1) { e_54 = { error: e_54_1 }; }
|
|
19042
19741
|
finally {
|
|
19043
19742
|
try {
|
|
19044
19743
|
if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
|
|
19045
19744
|
}
|
|
19046
|
-
finally { if (
|
|
19745
|
+
finally { if (e_54) throw e_54.error; }
|
|
19047
19746
|
}
|
|
19048
19747
|
if (stack.length !== 1 || Number.isNaN(stack[0])) {
|
|
19049
19748
|
return null;
|
|
@@ -19227,8 +19926,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
|
|
|
19227
19926
|
}
|
|
19228
19927
|
function readAttachmentContents(attachments) {
|
|
19229
19928
|
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
|
|
19929
|
+
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;
|
|
19930
|
+
var e_55, _b;
|
|
19232
19931
|
return __generator(this, function (_c) {
|
|
19233
19932
|
switch (_c.label) {
|
|
19234
19933
|
case 0:
|
|
@@ -19307,14 +20006,14 @@ function readAttachmentContents(attachments) {
|
|
|
19307
20006
|
return [3 /*break*/, 2];
|
|
19308
20007
|
case 10: return [3 /*break*/, 13];
|
|
19309
20008
|
case 11:
|
|
19310
|
-
|
|
19311
|
-
|
|
20009
|
+
e_55_1 = _c.sent();
|
|
20010
|
+
e_55 = { error: e_55_1 };
|
|
19312
20011
|
return [3 /*break*/, 13];
|
|
19313
20012
|
case 12:
|
|
19314
20013
|
try {
|
|
19315
20014
|
if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
|
|
19316
20015
|
}
|
|
19317
|
-
finally { if (
|
|
20016
|
+
finally { if (e_55) throw e_55.error; }
|
|
19318
20017
|
return [7 /*endfinally*/];
|
|
19319
20018
|
case 13: return [2 /*return*/, {
|
|
19320
20019
|
promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
|
|
@@ -19469,7 +20168,7 @@ function resolveAssistantDatabaseNameForSystemCollections() {
|
|
|
19469
20168
|
}
|
|
19470
20169
|
function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
19471
20170
|
return __awaiter(this, void 0, void 0, function () {
|
|
19472
|
-
var
|
|
20171
|
+
var error_12, dbName, _a;
|
|
19473
20172
|
return __generator(this, function (_b) {
|
|
19474
20173
|
switch (_b.label) {
|
|
19475
20174
|
case 0:
|
|
@@ -19484,9 +20183,9 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
19484
20183
|
_b.sent();
|
|
19485
20184
|
return [2 /*return*/];
|
|
19486
20185
|
case 3:
|
|
19487
|
-
|
|
19488
|
-
if (!isAssistantTransactionCommittedError(
|
|
19489
|
-
throw
|
|
20186
|
+
error_12 = _b.sent();
|
|
20187
|
+
if (!isAssistantTransactionCommittedError(error_12)) {
|
|
20188
|
+
throw error_12;
|
|
19490
20189
|
}
|
|
19491
20190
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
19492
20191
|
_b.label = 4;
|
|
@@ -19516,7 +20215,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
19516
20215
|
}
|
|
19517
20216
|
function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
19518
20217
|
return __awaiter(this, void 0, void 0, function () {
|
|
19519
|
-
var update,
|
|
20218
|
+
var update, error_13, dbName;
|
|
19520
20219
|
return __generator(this, function (_a) {
|
|
19521
20220
|
switch (_a.label) {
|
|
19522
20221
|
case 0:
|
|
@@ -19535,9 +20234,9 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
19535
20234
|
_a.sent();
|
|
19536
20235
|
return [2 /*return*/];
|
|
19537
20236
|
case 3:
|
|
19538
|
-
|
|
19539
|
-
if (!isAssistantTransactionCommittedError(
|
|
19540
|
-
throw
|
|
20237
|
+
error_13 = _a.sent();
|
|
20238
|
+
if (!isAssistantTransactionCommittedError(error_13)) {
|
|
20239
|
+
throw error_13;
|
|
19541
20240
|
}
|
|
19542
20241
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
19543
20242
|
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoConnection()
|
|
@@ -19638,7 +20337,7 @@ function estimateUsage(messages, responseText, model) {
|
|
|
19638
20337
|
};
|
|
19639
20338
|
}
|
|
19640
20339
|
function evaluateGuardrails(message) {
|
|
19641
|
-
var
|
|
20340
|
+
var e_56, _a;
|
|
19642
20341
|
var normalized = String(message || '').toLowerCase();
|
|
19643
20342
|
var patterns = [
|
|
19644
20343
|
{ 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 +20359,12 @@ function evaluateGuardrails(message) {
|
|
|
19660
20359
|
}
|
|
19661
20360
|
}
|
|
19662
20361
|
}
|
|
19663
|
-
catch (
|
|
20362
|
+
catch (e_56_1) { e_56 = { error: e_56_1 }; }
|
|
19664
20363
|
finally {
|
|
19665
20364
|
try {
|
|
19666
20365
|
if (patterns_3_1 && !patterns_3_1.done && (_a = patterns_3.return)) _a.call(patterns_3);
|
|
19667
20366
|
}
|
|
19668
|
-
finally { if (
|
|
20367
|
+
finally { if (e_56) throw e_56.error; }
|
|
19669
20368
|
}
|
|
19670
20369
|
return null;
|
|
19671
20370
|
}
|