@resolveio/server-lib 22.3.205 → 22.3.206

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.
@@ -1888,7 +1888,7 @@ function executeAiAssistantCodexRun(payload, context) {
1888
1888
  insertResult = _d.sent();
1889
1889
  assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
1890
1890
  enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
1891
- var runStart, fastModeEnabled, alwaysAllowProbeEnabled, plannerEnabled, runBudgetMs, assistantMongoMaxTimeMs, assistantSystemPrompt, runDeadlineMs, steps, recordStep, requestClassification, dataQuestion, progressTracker, streamProgress, remainingRunBudgetMs, hasRunBudget, applyCodexStageBudget, assistantContent, toolResult, assistantDebug, directiveSource, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, toolTelemetry, termHints, collectionHints, fieldHints, schemaHints, methodHints, publicationHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerUsed, plannerSkipReason, plannerOutput, plannerRaw, appDataRequestClassifierDebug, appDataRequestClassifierIntent, appDataRequestClassifierUnderstanding, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, surfaceHints, _a, allowedRoutes, rankedAllowedRoutes, routeHints, appCollectionHints, rankedCollectionHints, rankedCollections, hintCollections, schemaHintCollections, assistantContext, scoredAppDataIntentCandidates, shouldAttemptAppDataClassifier, classifierResult, classifierUsageClientId, usageError_1, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerBudgetAvailable, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, error_2, initialStart, extractedDirective, error_3, directivePrompt, forcedStart, forcedDirective, error_4, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, error_5, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, error_6, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, error_7, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, deniedModuleByIntent, permissionLabel, effectiveDirective, effectiveDirectiveMetadata, directiveAcknowledgementText, directiveProgressMessages, deterministicDataIntentDirective, rankedCollections_1, directiveHintsBase_1, buildToolRequestForDirective, executionDirective, probeFieldHints, aggregateProbeDisabled, probeEnabled, probeBudgetAllowed, probeDirective, probeRequest, probeStart, probeResponse, _c, probeDurationMs, probeRowCount, probeRewrite, probeError_1, probeDurationMs, probeErrorMessage, toolRequest, requestedToolCollection, toolStart, toolResponse, _d, toolDurationMs, toolPayload, resolvedToolCollection, zeroRowResult, followupCodexEnabled, skipFollowupCodex, followupPrompt, followupStart, followupText, _e, error_8, errorMessage, existingFinal, error_9, runBudgetExceeded, includeToolExecutionTelemetry, toolExecutionTelemetry, finishedAt, finalNow, finishedAt, codexMs, draftingMs, answerQualityEvidence, finalMetadata, finalUsage, finalUsageLedgerEntry, usageClientId, usageError_2, finalAssistantDoc, setPayload, finalizeError_1, failedAt, fallbackContent, failureMetadata, persistError_1, _f;
1891
+ var runStart, fastModeEnabled, alwaysAllowProbeEnabled, plannerEnabled, runBudgetMs, assistantMongoMaxTimeMs, assistantSystemPrompt, runDeadlineMs, steps, recordStep, requestClassification, dataQuestion, progressTracker, finalProgress, streamProgress, remainingRunBudgetMs, hasRunBudget, applyCodexStageBudget, assistantContent, toolResult, assistantDebug, directiveSource, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, toolTelemetry, termHints, collectionHints, fieldHints, schemaHints, methodHints, publicationHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerUsed, plannerSkipReason, plannerOutput, plannerRaw, appDataRequestClassifierDebug, appDataRequestClassifierIntent, appDataRequestClassifierUnderstanding, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, surfaceHints, _a, allowedRoutes, rankedAllowedRoutes, routeHints, appCollectionHints, rankedCollectionHints, rankedCollections, hintCollections, schemaHintCollections, assistantContext, scoredAppDataIntentCandidates, shouldAttemptAppDataClassifier, classifierResult, classifierUsageClientId, usageError_1, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerBudgetAvailable, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, error_2, initialStart, extractedDirective, error_3, directivePrompt, forcedStart, forcedDirective, error_4, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, error_5, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, error_6, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, error_7, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, deniedModuleByIntent, permissionLabel, effectiveDirective, effectiveDirectiveMetadata, directiveAcknowledgementText, directiveProgressMessages, deterministicDataIntentDirective, rankedCollections_1, directiveHintsBase_1, buildToolRequestForDirective, breakdownProgress, executionDirective, probeFieldHints, aggregateProbeDisabled, probeEnabled, probeBudgetAllowed, probeDirective, probeRequest, probeStart, probeResponse, _c, probeDurationMs, probeRowCount, probeRewrite, probeError_1, probeDurationMs, probeErrorMessage, toolRequest, requestedToolCollection, toolStart, toolResponse, _d, toolDurationMs, toolPayload, resolvedToolCollection, zeroRowResult, followupCodexEnabled, skipFollowupCodex, followupPrompt, followupStart, followupText, _e, error_8, errorMessage, existingFinal, error_9, runBudgetExceeded, includeToolExecutionTelemetry, toolExecutionTelemetry, finishedAt, finalNow, finishedAt, codexMs, draftingMs, answerQualityEvidence, finalMetadata, finalUsage, finalUsageLedgerEntry, usageClientId, usageError_2, finalAssistantDoc, setPayload, finalizeError_1, failedAt, fallbackContent, failureMetadata, persistError_1, _f;
1892
1892
  var _g, _h, _j, _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, _13, _14, _15, _16, _17, _18, _19, _20;
1893
1893
  return __generator(this, function (_21) {
1894
1894
  switch (_21.label) {
@@ -1931,6 +1931,7 @@ function executeAiAssistantCodexRun(payload, context) {
1931
1931
  requestClassification = classifyAssistantRequestType(message);
1932
1932
  dataQuestion = requestClassification.dataQuestion;
1933
1933
  progressTracker = createAssistantProgressTracker(assistantMessageId, initialProgress);
1934
+ finalProgress = initialProgress;
1934
1935
  streamProgress = createAssistantStreamProgressHandler(progressTracker, function () { return dataQuestion; });
1935
1936
  remainingRunBudgetMs = function () {
1936
1937
  if (!runDeadlineMs) {
@@ -2037,7 +2038,7 @@ function executeAiAssistantCodexRun(payload, context) {
2037
2038
  });
2038
2039
  _21.label = 1;
2039
2040
  case 1:
2040
- _21.trys.push([1, 76, 77, 78]);
2041
+ _21.trys.push([1, 76, 77, 79]);
2041
2042
  hintSeed = [message, contextRoute].filter(Boolean).join(' ');
2042
2043
  termExpansion = expandAssistantTermSynonyms(hintSeed);
2043
2044
  hintText = termExpansion.expanded || hintSeed;
@@ -2753,6 +2754,10 @@ function executeAiAssistantCodexRun(payload, context) {
2753
2754
  else {
2754
2755
  progressTracker.push(deterministicDataIntentDirective ? AI_ASSISTANT_PROGRESS_DATA_RUNNING : AI_ASSISTANT_PROGRESS_DATA_LOOKUP);
2755
2756
  }
2757
+ breakdownProgress = buildAssistantBreakdownProgressMessage(effectiveDirectiveMetadata.requestContract);
2758
+ if (breakdownProgress) {
2759
+ progressTracker.push(breakdownProgress);
2760
+ }
2756
2761
  directiveProgressMessages.slice(0, 2).forEach(function (messageText) { return progressTracker.push(messageText); });
2757
2762
  executionDirective = effectiveDirective;
2758
2763
  probeFieldHints = [];
@@ -2992,16 +2997,17 @@ function executeAiAssistantCodexRun(payload, context) {
2992
2997
  progressTracker.push(AI_ASSISTANT_PROGRESS_DRAFT);
2993
2998
  recordStep('Drafting response');
2994
2999
  _21.label = 75;
2995
- case 75: return [3 /*break*/, 78];
3000
+ case 75: return [3 /*break*/, 79];
2996
3001
  case 76:
2997
3002
  error_9 = _21.sent();
2998
3003
  assistantContent = buildAssistantCodexErrorMessage(error_9);
2999
3004
  recordStep('Error', { message: normalizeOptionalString(error_9 === null || error_9 === void 0 ? void 0 : error_9.message) || 'Unknown error' });
3000
- return [3 /*break*/, 78];
3001
- case 77:
3002
- progressTracker.stop();
3003
- return [7 /*endfinally*/];
3005
+ return [3 /*break*/, 79];
3006
+ case 77: return [4 /*yield*/, progressTracker.stop()];
3004
3007
  case 78:
3008
+ finalProgress = _21.sent();
3009
+ return [7 /*endfinally*/];
3010
+ case 79:
3005
3011
  runBudgetExceeded = runDeadlineMs ? Date.now() > runDeadlineMs : false;
3006
3012
  if (!assistantContent) {
3007
3013
  assistantContent = runBudgetExceeded
@@ -3045,9 +3051,9 @@ function executeAiAssistantCodexRun(payload, context) {
3045
3051
  });
3046
3052
  }
3047
3053
  finalNow = new Date();
3048
- _21.label = 79;
3049
- case 79:
3050
- _21.trys.push([79, 91, , 102]);
3054
+ _21.label = 80;
3055
+ case 80:
3056
+ _21.trys.push([80, 92, , 103]);
3051
3057
  if (canViewDebug) {
3052
3058
  finishedAt = Date.now();
3053
3059
  codexMs = timingBreakdown.directiveMs
@@ -3134,7 +3140,7 @@ function executeAiAssistantCodexRun(payload, context) {
3134
3140
  toolError: toolError,
3135
3141
  now: finalNow
3136
3142
  });
3137
- finalMetadata = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ model: codexModel }, (codexFallbackModels.length ? { model_fallbacks: codexFallbackModels } : {})), (requestId ? { request_id: requestId } : {})), { pending: false }), (fastModeEnabled ? {
3143
+ finalMetadata = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ model: codexModel }, (codexFallbackModels.length ? { model_fallbacks: codexFallbackModels } : {})), (requestId ? { request_id: requestId } : {})), { pending: false, progress: finalProgress }), (fastModeEnabled ? {
3138
3144
  fast_mode: true,
3139
3145
  run_budget_ms: runBudgetMs,
3140
3146
  run_budget_exhausted: runBudgetExceeded
@@ -3148,13 +3154,13 @@ function executeAiAssistantCodexRun(payload, context) {
3148
3154
  total_tokens: codexUsage.total_tokens
3149
3155
  } : null;
3150
3156
  finalUsageLedgerEntry = null;
3151
- if (!finalUsage) return [3 /*break*/, 84];
3157
+ if (!finalUsage) return [3 /*break*/, 85];
3152
3158
  return [4 /*yield*/, resolveClientId(conversation, input.id_client, context === null || context === void 0 ? void 0 : context.id_user)];
3153
- case 80:
3154
- usageClientId = _21.sent();
3155
- _21.label = 81;
3156
3159
  case 81:
3157
- _21.trys.push([81, 83, , 84]);
3160
+ usageClientId = _21.sent();
3161
+ _21.label = 82;
3162
+ case 82:
3163
+ _21.trys.push([82, 84, , 85]);
3158
3164
  finalUsageLedgerEntry = buildAssistantAIRunUsageLedgerEntry({
3159
3165
  idClient: usageClientId || '',
3160
3166
  model: finalUsage.model,
@@ -3174,16 +3180,16 @@ function executeAiAssistantCodexRun(payload, context) {
3174
3180
  }
3175
3181
  });
3176
3182
  return [4 /*yield*/, (0, openai_usage_ledger_manager_1.recordOpenAIUsage)(finalUsageLedgerEntry)];
3177
- case 82:
3178
- _21.sent();
3179
- return [3 /*break*/, 84];
3180
3183
  case 83:
3184
+ _21.sent();
3185
+ return [3 /*break*/, 85];
3186
+ case 84:
3181
3187
  usageError_2 = _21.sent();
3182
3188
  console.error(new Date(), 'Failed to record AI usage', usageError_2);
3183
- return [3 /*break*/, 84];
3184
- case 84:
3189
+ return [3 /*break*/, 85];
3190
+ case 85:
3185
3191
  finalAssistantDoc = __assign(__assign(__assign(__assign({}, assistantDoc), { _id: assistantMessageId, content: assistantContent, metadata: finalMetadata }), (finalUsage ? { usage: finalUsage } : {})), { updatedAt: finalNow });
3186
- if (!assistantMessageId) return [3 /*break*/, 86];
3192
+ if (!assistantMessageId) return [3 /*break*/, 87];
3187
3193
  setPayload = {
3188
3194
  content: assistantContent,
3189
3195
  metadata: finalMetadata,
@@ -3193,11 +3199,11 @@ function executeAiAssistantCodexRun(payload, context) {
3193
3199
  setPayload.usage = finalUsage;
3194
3200
  }
3195
3201
  return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, setPayload)];
3196
- case 85:
3202
+ case 86:
3197
3203
  _21.sent();
3198
- _21.label = 86;
3199
- case 86: return [4 /*yield*/, touchConversation(conversation._id, finalNow, assistantMessageId ? String(assistantMessageId) : undefined)];
3200
- case 87:
3204
+ _21.label = 87;
3205
+ case 87: return [4 /*yield*/, touchConversation(conversation._id, finalNow, assistantMessageId ? String(assistantMessageId) : undefined)];
3206
+ case 88:
3201
3207
  _21.sent();
3202
3208
  return [4 /*yield*/, recordAssistantAnswerAIRun({
3203
3209
  runId: buildAssistantAIRunId('codex_query', [conversation._id, assistantMessageId || requestId]),
@@ -3216,55 +3222,55 @@ function executeAiAssistantCodexRun(payload, context) {
3216
3222
  answerQuality: answerQualityEvidence,
3217
3223
  now: finalNow
3218
3224
  })];
3219
- case 88:
3225
+ case 89:
3220
3226
  _21.sent();
3221
- if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 90];
3227
+ if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 91];
3222
3228
  return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
3223
- case 89:
3229
+ case 90:
3224
3230
  _21.sent();
3225
- _21.label = 90;
3226
- case 90: return [2 /*return*/, finalAssistantDoc];
3227
- case 91:
3231
+ _21.label = 91;
3232
+ case 91: return [2 /*return*/, finalAssistantDoc];
3233
+ case 92:
3228
3234
  finalizeError_1 = _21.sent();
3229
3235
  failedAt = new Date();
3230
3236
  fallbackContent = assistantContent || buildAssistantCodexErrorMessage(finalizeError_1);
3231
3237
  failureMetadata = __assign(__assign(__assign(__assign(__assign({ model: codexModel }, (codexFallbackModels.length ? { model_fallbacks: codexFallbackModels } : {})), (requestId ? { request_id: requestId } : {})), { pending: false, failed: true }), (toolExecutionTelemetry ? { tool_execution: toolExecutionTelemetry } : {})), { error_message: normalizeOptionalString(finalizeError_1 === null || finalizeError_1 === void 0 ? void 0 : finalizeError_1.message) || 'Unknown error' });
3232
- _21.label = 92;
3233
- case 92:
3234
- _21.trys.push([92, 96, , 97]);
3235
- if (!assistantMessageId) return [3 /*break*/, 94];
3238
+ _21.label = 93;
3239
+ case 93:
3240
+ _21.trys.push([93, 97, , 98]);
3241
+ if (!assistantMessageId) return [3 /*break*/, 95];
3236
3242
  return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, {
3237
3243
  content: fallbackContent,
3238
3244
  metadata: failureMetadata,
3239
3245
  updatedAt: failedAt
3240
3246
  })];
3241
- case 93:
3247
+ case 94:
3242
3248
  _21.sent();
3243
- _21.label = 94;
3244
- case 94: return [4 /*yield*/, touchConversation(conversation._id, failedAt, assistantMessageId ? String(assistantMessageId) : undefined)];
3245
- case 95:
3246
- _21.sent();
3247
- return [3 /*break*/, 97];
3249
+ _21.label = 95;
3250
+ case 95: return [4 /*yield*/, touchConversation(conversation._id, failedAt, assistantMessageId ? String(assistantMessageId) : undefined)];
3248
3251
  case 96:
3252
+ _21.sent();
3253
+ return [3 /*break*/, 98];
3254
+ case 97:
3249
3255
  persistError_1 = _21.sent();
3250
3256
  console.error(new Date(), 'AI assistant finalize fallback update failed', persistError_1);
3251
- return [3 /*break*/, 97];
3252
- case 97:
3253
- if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 101];
3254
- _21.label = 98;
3257
+ return [3 /*break*/, 98];
3255
3258
  case 98:
3256
- _21.trys.push([98, 100, , 101]);
3257
- return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
3259
+ if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 102];
3260
+ _21.label = 99;
3258
3261
  case 99:
3259
- _21.sent();
3260
- return [3 /*break*/, 101];
3262
+ _21.trys.push([99, 101, , 102]);
3263
+ return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
3261
3264
  case 100:
3262
- _f = _21.sent();
3263
- return [3 /*break*/, 101];
3265
+ _21.sent();
3266
+ return [3 /*break*/, 102];
3264
3267
  case 101:
3268
+ _f = _21.sent();
3269
+ return [3 /*break*/, 102];
3270
+ case 102:
3265
3271
  console.error(new Date(), 'AI assistant run finalize failed:', finalizeError_1);
3266
3272
  return [2 /*return*/, __assign(__assign({}, assistantDoc), { _id: assistantMessageId, content: fallbackContent, metadata: failureMetadata, updatedAt: failedAt })];
3267
- case 102: return [2 /*return*/];
3273
+ case 103: return [2 /*return*/];
3268
3274
  }
3269
3275
  });
3270
3276
  }); });
@@ -7010,6 +7016,18 @@ function extractAssistantDataIntentCustomerText(message) {
7010
7016
  value = value.replace(/[^a-z0-9&.' -]+/gi, ' ');
7011
7017
  return normalizeOptionalString(value.replace(/\s+/g, ' '));
7012
7018
  }
7019
+ function doesAssistantDataIntentUseCustomerText(intent) {
7020
+ if (!Array.isArray(intent.pipeline) || !intent.pipeline.length) {
7021
+ return true;
7022
+ }
7023
+ var serialized = JSON.stringify([
7024
+ intent.pipeline,
7025
+ intent.acknowledgement,
7026
+ intent.progress,
7027
+ intent.dimensions
7028
+ ]);
7029
+ return serialized.includes('{{customer}}');
7030
+ }
7013
7031
  function resolveAssistantDataIntentDateWindow(message) {
7014
7032
  var text = normalizeOptionalString(message).toLowerCase();
7015
7033
  var now = new Date();
@@ -7623,6 +7641,17 @@ function normalizeAssistantDataRequestContract(value, intent, dateWindow, source
7623
7641
  source: source
7624
7642
  };
7625
7643
  }
7644
+ function normalizeAssistantBreakdownCandidateKey(value) {
7645
+ return cleanAssistantRequestedDimensionText(value).replace(/[_-]+/g, ' ').replace(/\s+/g, ' ').trim();
7646
+ }
7647
+ function resolveAssistantBreakdownCandidateKey(text, breakdown) {
7648
+ var granularity = normalizeAssistantBreakdownCandidateKey((breakdown === null || breakdown === void 0 ? void 0 : breakdown.granularity) || resolveAssistantTimeBreakdownGranularity(text));
7649
+ if (granularity) {
7650
+ return "time:".concat(granularity);
7651
+ }
7652
+ var dimension = normalizeAssistantBreakdownCandidateKey((breakdown === null || breakdown === void 0 ? void 0 : breakdown.dimension) || text);
7653
+ return dimension ? "entity:".concat(dimension) : '';
7654
+ }
7626
7655
  function buildAssistantRequestedBreakdownCandidates(message, classifierContract) {
7627
7656
  var candidates = [];
7628
7657
  var seen = new Set();
@@ -7631,12 +7660,7 @@ function buildAssistantRequestedBreakdownCandidates(message, classifierContract)
7631
7660
  if (!normalized) {
7632
7661
  return;
7633
7662
  }
7634
- var key = [
7635
- (breakdown === null || breakdown === void 0 ? void 0 : breakdown.type) || '',
7636
- (breakdown === null || breakdown === void 0 ? void 0 : breakdown.granularity) || '',
7637
- (breakdown === null || breakdown === void 0 ? void 0 : breakdown.dimension) || '',
7638
- normalized
7639
- ].join(':');
7663
+ var key = resolveAssistantBreakdownCandidateKey(normalized, breakdown);
7640
7664
  if (seen.has(key)) {
7641
7665
  return;
7642
7666
  }
@@ -7668,6 +7692,13 @@ function buildAssistantDataRequestClassifierCandidatePayload(candidate) {
7668
7692
  granularity: dimension.granularity || undefined,
7669
7693
  terms: (dimension.terms || []).slice(0, 12),
7670
7694
  field_hints: extractAssistantDataIntentExpressionFieldHints(dimension.groupId).slice(0, 8)
7695
+ }); }),
7696
+ filter_fields: buildAssistantAppDataFilterCandidates(intent).map(function (filterField) { return ({
7697
+ id: filterField.id,
7698
+ terms: filterField.terms.slice(0, 12),
7699
+ fields: filterField.fields.slice(0, 8),
7700
+ type: filterField.type || undefined,
7701
+ operators: filterField.operators.slice(0, 8)
7671
7702
  }); })
7672
7703
  };
7673
7704
  }
@@ -7681,6 +7712,7 @@ function buildAssistantDataRequestClassifierMessages(params) {
7681
7712
  'Interpret date phrases like "this month", "last month", "until June 12", "through May", "past 30 days", and "last 6 months" as date_range or filters when clear.',
7682
7713
  'For time breakdowns, set type="time" and granularity to one of year, quarter, month, week, day, date.',
7683
7714
  'For configured dimensions, set type="entity" and dimension to the candidate dimension id.',
7715
+ 'For filters, use only candidate filter_fields or configured dimension ids; include field/value/operator but do not invent fields.',
7684
7716
  'If unsure, include an ambiguity instead of guessing.',
7685
7717
  'Always set output_format to "collapse_table".',
7686
7718
  'Return JSON only with keys: intent_id, domain, collection, operation, requested_breakdowns, date_range, measures, filters, output_format, ambiguities, confidence.'
@@ -7731,7 +7763,7 @@ function resolveAssistantDataRequestClassifierTimeoutMs(config) {
7731
7763
  if (raw && raw > 0) {
7732
7764
  return Math.max(250, Math.min((0, common_1.round)(raw), 5000));
7733
7765
  }
7734
- return 1800;
7766
+ return 500;
7735
7767
  }
7736
7768
  function resolveAssistantDataRequestClassifierMaxTokens() {
7737
7769
  var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
@@ -7890,13 +7922,11 @@ function buildAssistantDataRequestUnderstanding(message, intent, dateWindow, cla
7890
7922
  var addDimension = function (dimension) {
7891
7923
  var id = normalizeOptionalString(dimension.id);
7892
7924
  if (!id || seenDimensionIds.has(id)) {
7893
- return;
7894
- }
7895
- if ((dimension.type || '') === 'time' && dimensions.some(function (entry) { return (entry.type || '') === 'time'; })) {
7896
- return;
7925
+ return false;
7897
7926
  }
7898
7927
  seenDimensionIds.add(id);
7899
7928
  dimensions.push(dimension);
7929
+ return true;
7900
7930
  };
7901
7931
  requestedBreakdownCandidates.forEach(function (candidate) {
7902
7932
  var _a;
@@ -7939,6 +7969,9 @@ function buildAssistantDataRequestUnderstanding(message, intent, dateWindow, cla
7939
7969
  }
7940
7970
  });
7941
7971
  if (selected) {
7972
+ if (!selected.dimension.groupId) {
7973
+ ambiguities.push("Requested ".concat(requestedDimensionText, " breakdown matched ").concat(selected.dimension.id, ", but the app dimension has no group expression."));
7974
+ }
7942
7975
  var dimension = __assign(__assign({}, selected.dimension), { type: selected.dimension.type || 'entity', requestedText: requestedDimensionText });
7943
7976
  addDimension(dimension);
7944
7977
  requestedBreakdowns.push({
@@ -7979,12 +8012,518 @@ function buildAssistantDataRequestUnderstanding(message, intent, dateWindow, cla
7979
8012
  }
7980
8013
  };
7981
8014
  }
8015
+ function inferAssistantDateWindowYear(value) {
8016
+ var e_6, _a;
8017
+ if (!value) {
8018
+ return undefined;
8019
+ }
8020
+ if (value.year) {
8021
+ return value.year;
8022
+ }
8023
+ try {
8024
+ for (var _b = __values([value.start, value.end]), _c = _b.next(); !_c.done; _c = _b.next()) {
8025
+ var dateValue = _c.value;
8026
+ var parsed = new Date(normalizeOptionalString(dateValue));
8027
+ if (!Number.isNaN(parsed.getTime())) {
8028
+ return parsed.getUTCFullYear();
8029
+ }
8030
+ }
8031
+ }
8032
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
8033
+ finally {
8034
+ try {
8035
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
8036
+ }
8037
+ finally { if (e_6) throw e_6.error; }
8038
+ }
8039
+ return undefined;
8040
+ }
8041
+ function resolveAssistantEffectiveDataIntentDateWindow(baseDateWindow, requestUnderstanding) {
8042
+ var _a;
8043
+ var contractDateRange = normalizeAssistantContractDateRange((_a = requestUnderstanding === null || requestUnderstanding === void 0 ? void 0 : requestUnderstanding.contract) === null || _a === void 0 ? void 0 : _a.date_range);
8044
+ if (!contractDateRange) {
8045
+ return baseDateWindow;
8046
+ }
8047
+ var effective = __assign(__assign({}, baseDateWindow), contractDateRange);
8048
+ var year = inferAssistantDateWindowYear(effective);
8049
+ if (year) {
8050
+ effective.year = year;
8051
+ }
8052
+ return effective;
8053
+ }
7982
8054
  function extractAssistantDataIntentGroupKeys(groupId) {
7983
8055
  if (!groupId || typeof groupId !== 'object' || Array.isArray(groupId)) {
7984
8056
  return [];
7985
8057
  }
7986
8058
  return Object.keys(groupId).filter(Boolean);
7987
8059
  }
8060
+ function normalizeAssistantGroupKeyForComparison(value) {
8061
+ return cleanAssistantRequestedDimensionText(value).replace(/[_-]+/g, ' ').replace(/\s+/g, ' ').trim();
8062
+ }
8063
+ function resolveAssistantBreakdownAppliedToGroup(breakdown, groupKeys) {
8064
+ if (!breakdown || breakdown.type === 'unknown') {
8065
+ return true;
8066
+ }
8067
+ var candidates = __spreadArray([
8068
+ breakdown.dimension,
8069
+ breakdown.granularity,
8070
+ breakdown.requested_text,
8071
+ breakdown.field_hint
8072
+ ], __read((breakdown.field_hints || [])), false).map(function (value) { return normalizeAssistantGroupKeyForComparison(normalizeOptionalString(value)); })
8073
+ .filter(Boolean);
8074
+ return candidates.some(function (candidate) { return groupKeys.has(candidate); });
8075
+ }
8076
+ function resolveAssistantDroppedBreakdownAmbiguities(requestContract, pipeline) {
8077
+ var _a;
8078
+ var requestedBreakdowns = Array.isArray(requestContract === null || requestContract === void 0 ? void 0 : requestContract.requested_breakdowns)
8079
+ ? requestContract.requested_breakdowns
8080
+ : [];
8081
+ if (!requestedBreakdowns.length) {
8082
+ return [];
8083
+ }
8084
+ var groupStage = (_a = (Array.isArray(pipeline) ? pipeline : []).find(function (stage) { return !!(stage === null || stage === void 0 ? void 0 : stage.$group); })) === null || _a === void 0 ? void 0 : _a.$group;
8085
+ var groupKeys = new Set(extractAssistantDataIntentGroupKeys(groupStage === null || groupStage === void 0 ? void 0 : groupStage._id)
8086
+ .map(function (key) { return normalizeAssistantGroupKeyForComparison(key); })
8087
+ .filter(Boolean));
8088
+ return requestedBreakdowns
8089
+ .filter(function (breakdown) { return !resolveAssistantBreakdownAppliedToGroup(breakdown, groupKeys); })
8090
+ .map(function (breakdown) {
8091
+ var label = formatAssistantRequestBreakdownLabel(breakdown) || breakdown.requested_text || 'requested';
8092
+ return "Requested ".concat(label, " breakdown was not applied to the final aggregate group.");
8093
+ });
8094
+ }
8095
+ function buildAssistantAppDataFilterCandidates(intent) {
8096
+ var candidates = [];
8097
+ var seen = new Set();
8098
+ var add = function (candidate) {
8099
+ var id = normalizeOptionalString(candidate.id);
8100
+ var fields = mergeAssistantHintValues(candidate.fields || [])
8101
+ .map(function (field) { return normalizeLookupPath(field); })
8102
+ .filter(function (field) { return !!field && isAssistantProjectionKeyAllowed(field); });
8103
+ if (!id || !fields.length) {
8104
+ return;
8105
+ }
8106
+ var key = "".concat(cleanAssistantRequestedDimensionText(id), ":").concat(fields.join('|'));
8107
+ if (seen.has(key)) {
8108
+ return;
8109
+ }
8110
+ seen.add(key);
8111
+ candidates.push({
8112
+ id: id,
8113
+ terms: mergeAssistantHintValues(__spreadArray([id], __read((candidate.terms || [])), false)).map(function (term) { return term.toLowerCase(); }),
8114
+ fields: fields,
8115
+ type: candidate.type || 'string',
8116
+ operators: mergeAssistantHintValues(candidate.operators || ['eq', 'contains', 'in']).map(function (operator) { return operator.toLowerCase(); })
8117
+ });
8118
+ };
8119
+ (intent.filterFields || []).forEach(add);
8120
+ (intent.dimensions || []).forEach(function (dimension) {
8121
+ if ((dimension.type || 'entity') === 'time') {
8122
+ return;
8123
+ }
8124
+ var fields = extractAssistantDataIntentExpressionFieldHints(dimension.groupId)
8125
+ .filter(function (field) { return isAssistantProjectionKeyAllowed(field); });
8126
+ if (!fields.length) {
8127
+ return;
8128
+ }
8129
+ add({
8130
+ id: dimension.id,
8131
+ terms: dimension.terms || [],
8132
+ fields: fields,
8133
+ type: 'string',
8134
+ operators: ['eq', 'contains', 'in']
8135
+ });
8136
+ });
8137
+ [
8138
+ { id: 'quantity', field: intent.quantityField, type: 'number' },
8139
+ { id: 'metric', field: intent.metricField, type: 'number' }
8140
+ ].forEach(function (entry) {
8141
+ var field = normalizeOptionalString(entry.field);
8142
+ if (!field) {
8143
+ return;
8144
+ }
8145
+ add({
8146
+ id: field.split('.').pop() || entry.id,
8147
+ terms: [entry.id, field],
8148
+ fields: [field],
8149
+ type: entry.type,
8150
+ operators: ['eq', 'gt', 'gte', 'lt', 'lte']
8151
+ });
8152
+ });
8153
+ return candidates;
8154
+ }
8155
+ function normalizeAssistantContractFilterToken(value) {
8156
+ return normalizeOptionalString(value).toLowerCase().replace(/[_-]+/g, ' ').replace(/\s+/g, ' ').trim();
8157
+ }
8158
+ function normalizeAssistantContractFilterOperator(value) {
8159
+ var normalized = normalizeOptionalString(value).toLowerCase().replace(/[^a-z0-9_$]+/g, '');
8160
+ if (normalized === '$eq' || normalized === 'equals' || normalized === 'is') {
8161
+ return 'eq';
8162
+ }
8163
+ if (normalized === '$in' || normalized === 'oneof' || normalized === 'anyof') {
8164
+ return 'in';
8165
+ }
8166
+ if (normalized === '$regex' || normalized === 'like' || normalized === 'contains') {
8167
+ return 'contains';
8168
+ }
8169
+ if (normalized === '$gt' || normalized === 'after' || normalized === 'greaterthan') {
8170
+ return 'gt';
8171
+ }
8172
+ if (normalized === '$gte' || normalized === 'onorafter' || normalized === 'greaterthanorequal') {
8173
+ return 'gte';
8174
+ }
8175
+ if (normalized === '$lt' || normalized === 'before' || normalized === 'lessthan') {
8176
+ return 'lt';
8177
+ }
8178
+ if (normalized === '$lte' || normalized === 'onorbefore' || normalized === 'lessthanorequal') {
8179
+ return 'lte';
8180
+ }
8181
+ return normalized || 'eq';
8182
+ }
8183
+ function extractAssistantFilterObjectValue(value) {
8184
+ var e_7, _a;
8185
+ if (!value || typeof value !== 'object' || Array.isArray(value) || value instanceof Date) {
8186
+ return {
8187
+ operator: 'eq',
8188
+ values: Array.isArray(value) ? value : [value]
8189
+ };
8190
+ }
8191
+ var operatorKeys = ['$eq', 'eq', 'equals', 'value', '$in', 'in', 'values', '$regex', 'contains', '$gt', 'gt', '$gte', 'gte', '$lt', 'lt', '$lte', 'lte'];
8192
+ try {
8193
+ for (var operatorKeys_1 = __values(operatorKeys), operatorKeys_1_1 = operatorKeys_1.next(); !operatorKeys_1_1.done; operatorKeys_1_1 = operatorKeys_1.next()) {
8194
+ var key = operatorKeys_1_1.value;
8195
+ if (!Object.prototype.hasOwnProperty.call(value, key)) {
8196
+ continue;
8197
+ }
8198
+ var rawValue = value[key];
8199
+ var operator = key === 'value' || key === 'values'
8200
+ ? (key === 'values' ? 'in' : 'eq')
8201
+ : normalizeAssistantContractFilterOperator(key);
8202
+ return {
8203
+ operator: operator,
8204
+ values: Array.isArray(rawValue) ? rawValue : [rawValue]
8205
+ };
8206
+ }
8207
+ }
8208
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
8209
+ finally {
8210
+ try {
8211
+ if (operatorKeys_1_1 && !operatorKeys_1_1.done && (_a = operatorKeys_1.return)) _a.call(operatorKeys_1);
8212
+ }
8213
+ finally { if (e_7) throw e_7.error; }
8214
+ }
8215
+ return {
8216
+ operator: 'eq',
8217
+ values: [value]
8218
+ };
8219
+ }
8220
+ function resolveAssistantContractFilterSpec(filter) {
8221
+ if (!filter || typeof filter !== 'object' || Array.isArray(filter)) {
8222
+ return null;
8223
+ }
8224
+ var field = normalizeOptionalString(filter.field
8225
+ || filter.field_hint
8226
+ || filter.fieldHint
8227
+ || filter.dimension
8228
+ || filter.key
8229
+ || filter.name);
8230
+ var operator = normalizeAssistantContractFilterOperator(filter.operator || filter.op || '');
8231
+ var rawValues = [];
8232
+ if (Object.prototype.hasOwnProperty.call(filter, 'value')) {
8233
+ rawValues = Array.isArray(filter.value) ? filter.value : [filter.value];
8234
+ }
8235
+ else if (Object.prototype.hasOwnProperty.call(filter, 'values')) {
8236
+ operator = operator === 'eq' ? 'in' : operator;
8237
+ rawValues = Array.isArray(filter.values) ? filter.values : [filter.values];
8238
+ }
8239
+ if (!field) {
8240
+ var reserved_1 = new Set(['field', 'field_hint', 'fieldHint', 'field_hints', 'fieldHints', 'dimension', 'key', 'name', 'operator', 'op', 'value', 'values']);
8241
+ var entries = Object.keys(filter).filter(function (key) { return !reserved_1.has(key) && !normalizeOptionalString(key).startsWith('$'); });
8242
+ if (entries.length !== 1) {
8243
+ return null;
8244
+ }
8245
+ field = entries[0];
8246
+ var extracted = extractAssistantFilterObjectValue(filter[field]);
8247
+ operator = extracted.operator;
8248
+ rawValues = extracted.values;
8249
+ }
8250
+ var values = rawValues
8251
+ .filter(function (value) { return value !== undefined && value !== null; })
8252
+ .slice(0, 12);
8253
+ if (!field || !values.length) {
8254
+ return null;
8255
+ }
8256
+ return {
8257
+ field: field,
8258
+ operator: operator,
8259
+ values: values,
8260
+ raw: filter
8261
+ };
8262
+ }
8263
+ function buildAssistantContractFilterSpecKey(spec) {
8264
+ return __spreadArray([
8265
+ normalizeAssistantContractFilterToken(spec.field),
8266
+ normalizeAssistantContractFilterOperator(spec.operator)
8267
+ ], __read(spec.values.map(function (value) { return normalizeAssistantContractFilterToken(value && typeof value === 'object' ? JSON.stringify(value) : value); })), false).filter(Boolean).join(':');
8268
+ }
8269
+ function resolveAssistantContractFilterKey(filter) {
8270
+ var spec = resolveAssistantContractFilterSpec(filter);
8271
+ return spec ? buildAssistantContractFilterSpecKey(spec) : normalizeAssistantContractFilterToken(formatAssistantContractFilterLabel(filter));
8272
+ }
8273
+ function collectAssistantContractFilterTokens(value, tokens) {
8274
+ if (tokens === void 0) { tokens = []; }
8275
+ if (value === undefined || value === null) {
8276
+ return tokens;
8277
+ }
8278
+ if (Array.isArray(value)) {
8279
+ value.forEach(function (entry) { return collectAssistantContractFilterTokens(entry, tokens); });
8280
+ return tokens;
8281
+ }
8282
+ if (value && typeof value === 'object') {
8283
+ Object.keys(value).forEach(function (key) {
8284
+ var normalizedKey = normalizeAssistantContractFilterToken(key);
8285
+ if (normalizedKey && !normalizedKey.startsWith('$') && !tokens.includes(normalizedKey)) {
8286
+ tokens.push(normalizedKey);
8287
+ }
8288
+ collectAssistantContractFilterTokens(value[key], tokens);
8289
+ });
8290
+ return tokens;
8291
+ }
8292
+ var normalizedValue = normalizeAssistantContractFilterToken(value);
8293
+ if (normalizedValue && !tokens.includes(normalizedValue)) {
8294
+ tokens.push(normalizedValue);
8295
+ }
8296
+ return tokens;
8297
+ }
8298
+ function formatAssistantContractFilterLabel(filter) {
8299
+ var labels = Object.keys(filter || {})
8300
+ .map(function (key) {
8301
+ var normalizedKey = normalizeAssistantContractFilterToken(key);
8302
+ var value = filter[key];
8303
+ var normalizedValue = value && typeof value === 'object'
8304
+ ? normalizeAssistantContractFilterToken(JSON.stringify(value))
8305
+ : normalizeAssistantContractFilterToken(value);
8306
+ if (!normalizedKey) {
8307
+ return '';
8308
+ }
8309
+ return normalizedValue ? "".concat(normalizedKey, "=").concat(normalizedValue) : normalizedKey;
8310
+ })
8311
+ .filter(Boolean);
8312
+ return labels.length ? labels.join(', ') : 'requested';
8313
+ }
8314
+ function scoreAssistantFilterCandidate(spec, candidate) {
8315
+ var requested = cleanAssistantRequestedDimensionText(spec.field);
8316
+ if (!requested) {
8317
+ return 0;
8318
+ }
8319
+ var score = 0;
8320
+ var candidateId = cleanAssistantRequestedDimensionText(candidate.id);
8321
+ if (requested === candidateId) {
8322
+ score += 10;
8323
+ }
8324
+ else if (candidateId && containsAssistantHeuristicTerm(requested, candidateId)) {
8325
+ score += 4;
8326
+ }
8327
+ (candidate.terms || []).forEach(function (term) {
8328
+ var normalizedTerm = cleanAssistantRequestedDimensionText(term);
8329
+ if (!normalizedTerm) {
8330
+ return;
8331
+ }
8332
+ if (requested === normalizedTerm) {
8333
+ score += normalizedTerm.includes(' ') ? 8 : 6;
8334
+ }
8335
+ else if (containsAssistantHeuristicTerm(requested, normalizedTerm)) {
8336
+ score += normalizedTerm.includes(' ') ? 4 : 2;
8337
+ }
8338
+ });
8339
+ (candidate.fields || []).forEach(function (field) {
8340
+ var normalizedField = cleanAssistantRequestedDimensionText(field);
8341
+ var leaf = cleanAssistantRequestedDimensionText(field.split('.').pop() || field);
8342
+ if (requested === normalizedField || requested === leaf) {
8343
+ score += 7;
8344
+ }
8345
+ });
8346
+ return score;
8347
+ }
8348
+ function resolveAssistantFilterCandidate(spec, intent) {
8349
+ var selected = null;
8350
+ buildAssistantAppDataFilterCandidates(intent).forEach(function (candidate) {
8351
+ var score = scoreAssistantFilterCandidate(spec, candidate);
8352
+ if (score <= 0) {
8353
+ return;
8354
+ }
8355
+ if (!selected || score > selected.score) {
8356
+ selected = { candidate: candidate, score: score };
8357
+ }
8358
+ });
8359
+ return (selected === null || selected === void 0 ? void 0 : selected.candidate) || null;
8360
+ }
8361
+ function coerceAssistantFilterValue(value, type) {
8362
+ if (type === 'number') {
8363
+ var numberValue = Number(value);
8364
+ return Number.isFinite(numberValue) ? numberValue : undefined;
8365
+ }
8366
+ if (type === 'boolean') {
8367
+ var normalized = normalizeOptionalString(value).toLowerCase();
8368
+ if (['true', 'yes', 'active', '1'].includes(normalized)) {
8369
+ return true;
8370
+ }
8371
+ if (['false', 'no', 'inactive', '0'].includes(normalized)) {
8372
+ return false;
8373
+ }
8374
+ return typeof value === 'boolean' ? value : undefined;
8375
+ }
8376
+ if (type === 'date') {
8377
+ var date = value instanceof Date ? value : new Date(normalizeOptionalString(value));
8378
+ return Number.isNaN(date.getTime()) ? undefined : date;
8379
+ }
8380
+ var text = normalizeOptionalString(value);
8381
+ return text ? text.slice(0, 160) : undefined;
8382
+ }
8383
+ function buildAssistantFieldFilterCondition(value, operator, type) {
8384
+ var normalizedOperator = normalizeAssistantContractFilterOperator(operator);
8385
+ var coerced = coerceAssistantFilterValue(value, type);
8386
+ if (coerced === undefined) {
8387
+ return undefined;
8388
+ }
8389
+ if (type === 'number' || type === 'date') {
8390
+ if (normalizedOperator === 'gt') {
8391
+ return { $gt: coerced };
8392
+ }
8393
+ if (normalizedOperator === 'gte') {
8394
+ return { $gte: coerced };
8395
+ }
8396
+ if (normalizedOperator === 'lt') {
8397
+ return { $lt: coerced };
8398
+ }
8399
+ if (normalizedOperator === 'lte') {
8400
+ return { $lte: coerced };
8401
+ }
8402
+ return coerced;
8403
+ }
8404
+ if (type === 'boolean') {
8405
+ return coerced;
8406
+ }
8407
+ var escaped = escapeRegexValue(String(coerced));
8408
+ if (!escaped) {
8409
+ return undefined;
8410
+ }
8411
+ return { $regex: escaped, $options: 'i' };
8412
+ }
8413
+ function buildAssistantContractFilterClause(spec, candidate) {
8414
+ var operator = normalizeAssistantContractFilterOperator(spec.operator);
8415
+ if (candidate.operators.length && !candidate.operators.includes(operator)) {
8416
+ return null;
8417
+ }
8418
+ var fields = (candidate.fields || []).filter(function (field) { return isAssistantProjectionKeyAllowed(field); });
8419
+ if (!fields.length) {
8420
+ return null;
8421
+ }
8422
+ var clauses = [];
8423
+ fields.forEach(function (field) {
8424
+ spec.values.forEach(function (value) {
8425
+ var _a;
8426
+ var condition = buildAssistantFieldFilterCondition(value, operator === 'in' ? 'eq' : operator, candidate.type);
8427
+ if (condition !== undefined) {
8428
+ clauses.push((_a = {}, _a[field] = condition, _a));
8429
+ }
8430
+ });
8431
+ });
8432
+ if (!clauses.length) {
8433
+ return null;
8434
+ }
8435
+ if (clauses.length === 1) {
8436
+ return clauses[0];
8437
+ }
8438
+ return { $or: clauses };
8439
+ }
8440
+ function mergeAssistantMatchClauses(existingMatch, clauses) {
8441
+ var cleanClauses = clauses.filter(function (clause) { return clause && typeof clause === 'object' && Object.keys(clause).length; });
8442
+ if (!cleanClauses.length) {
8443
+ return existingMatch;
8444
+ }
8445
+ var existingKeys = Object.keys(existingMatch || {});
8446
+ if (!existingKeys.length) {
8447
+ return cleanClauses.length === 1 ? cleanClauses[0] : { $and: cleanClauses };
8448
+ }
8449
+ return {
8450
+ $and: __spreadArray([
8451
+ (0, common_1.deepCopy)(existingMatch)
8452
+ ], __read(cleanClauses), false)
8453
+ };
8454
+ }
8455
+ function applyAssistantDataIntentContractFiltersToPipeline(pipeline, intent, requestContract) {
8456
+ var _a;
8457
+ var filters = Array.isArray(requestContract === null || requestContract === void 0 ? void 0 : requestContract.filters) ? requestContract.filters : [];
8458
+ if (!filters.length || !Array.isArray(pipeline) || !pipeline.length) {
8459
+ return { pipeline: pipeline, appliedFilterKeys: [] };
8460
+ }
8461
+ var clauses = [];
8462
+ var appliedFilterKeys = [];
8463
+ filters.forEach(function (filter) {
8464
+ var spec = resolveAssistantContractFilterSpec(filter);
8465
+ if (!spec) {
8466
+ return;
8467
+ }
8468
+ var candidate = resolveAssistantFilterCandidate(spec, intent);
8469
+ if (!candidate) {
8470
+ return;
8471
+ }
8472
+ var clause = buildAssistantContractFilterClause(spec, candidate);
8473
+ if (!clause) {
8474
+ return;
8475
+ }
8476
+ clauses.push(clause);
8477
+ appliedFilterKeys.push(buildAssistantContractFilterSpecKey(spec));
8478
+ });
8479
+ if (!clauses.length) {
8480
+ return { pipeline: pipeline, appliedFilterKeys: [] };
8481
+ }
8482
+ var next = (0, common_1.deepCopy)(pipeline);
8483
+ var groupIndex = findAggregateGroupIndex(next);
8484
+ var preGroupLimit = groupIndex > -1 ? groupIndex : next.length;
8485
+ var matchIndex = -1;
8486
+ for (var index = 0; index < preGroupLimit; index += 1) {
8487
+ if (((_a = next[index]) === null || _a === void 0 ? void 0 : _a.$match) && typeof next[index].$match === 'object') {
8488
+ matchIndex = index;
8489
+ }
8490
+ }
8491
+ if (matchIndex > -1) {
8492
+ next[matchIndex].$match = mergeAssistantMatchClauses(next[matchIndex].$match, clauses);
8493
+ }
8494
+ else {
8495
+ var insertIndex = groupIndex > -1 ? groupIndex : 0;
8496
+ next.splice(insertIndex, 0, {
8497
+ $match: clauses.length === 1 ? clauses[0] : { $and: clauses }
8498
+ });
8499
+ }
8500
+ return { pipeline: next, appliedFilterKeys: appliedFilterKeys };
8501
+ }
8502
+ function resolveAssistantDroppedFilterAmbiguities(requestContract, pipeline, appliedFilterKeys) {
8503
+ if (appliedFilterKeys === void 0) { appliedFilterKeys = []; }
8504
+ var filters = Array.isArray(requestContract === null || requestContract === void 0 ? void 0 : requestContract.filters)
8505
+ ? requestContract.filters
8506
+ : [];
8507
+ if (!filters.length) {
8508
+ return [];
8509
+ }
8510
+ var pipelineText = normalizeAssistantContractFilterToken(JSON.stringify(pipeline || []));
8511
+ var applied = new Set(appliedFilterKeys.map(function (key) { return normalizeAssistantContractFilterToken(key); }).filter(Boolean));
8512
+ return filters
8513
+ .filter(function (filter) {
8514
+ var filterKey = normalizeAssistantContractFilterToken(resolveAssistantContractFilterKey(filter));
8515
+ if (filterKey && applied.has(filterKey)) {
8516
+ return false;
8517
+ }
8518
+ var tokens = collectAssistantContractFilterTokens(filter)
8519
+ .filter(function (token) { return token.length >= 2 && !['and', 'or', 'eq', 'in', 'gte', 'lte', 'gt', 'lt'].includes(token); });
8520
+ if (!tokens.length) {
8521
+ return false;
8522
+ }
8523
+ return !tokens.every(function (token) { return pipelineText.includes(token); });
8524
+ })
8525
+ .map(function (filter) { return "Requested filter ".concat(formatAssistantContractFilterLabel(filter), " was not applied to the final aggregate pipeline."); });
8526
+ }
7988
8527
  function isAssistantProjectFieldFromGroupId(value) {
7989
8528
  return typeof value === 'string' && value.startsWith('$_id.');
7990
8529
  }
@@ -8065,10 +8604,13 @@ function buildAssistantAppDataIntentDirective(message, collectionNames, appId, o
8065
8604
  if (!intent) {
8066
8605
  return null;
8067
8606
  }
8068
- var customerText = extractAssistantDataIntentCustomerText(message);
8069
- var dateWindow = resolveAssistantDataIntentDateWindow(message);
8607
+ var customerText = doesAssistantDataIntentUseCustomerText(intent)
8608
+ ? extractAssistantDataIntentCustomerText(message)
8609
+ : '';
8610
+ var parsedDateWindow = resolveAssistantDataIntentDateWindow(message);
8070
8611
  var requestUnderstanding = (options === null || options === void 0 ? void 0 : options.appDataRequestUnderstanding)
8071
- || buildAssistantDataRequestUnderstanding(message, intent, dateWindow, (options === null || options === void 0 ? void 0 : options.appDataRequestContract) || null);
8612
+ || buildAssistantDataRequestUnderstanding(message, intent, parsedDateWindow, (options === null || options === void 0 ? void 0 : options.appDataRequestContract) || null);
8613
+ var dateWindow = resolveAssistantEffectiveDataIntentDateWindow(parsedDateWindow, requestUnderstanding);
8072
8614
  var templatedDimensions = requestUnderstanding.dimensions
8073
8615
  .map(function (dimension) { return applyAssistantDataIntentDimensionTemplate(dimension, { customerText: customerText, dateWindow: dateWindow }); })
8074
8616
  .filter(function (dimension) { return !!(dimension === null || dimension === void 0 ? void 0 : dimension.groupId); });
@@ -8097,8 +8639,15 @@ function buildAssistantAppDataIntentDirective(message, collectionNames, appId, o
8097
8639
  var pipeline = configuredPipeline.length
8098
8640
  ? configuredPipeline
8099
8641
  : buildAssistantGenericDataIntentPipeline(intent, customerText, dateWindow);
8100
- var finalPipeline = applyAssistantDataIntentDimensionsToPipeline(pipeline, templatedDimensions);
8101
- metadata.requestContract = __assign(__assign({}, requestUnderstanding.contract), { measures: buildAssistantDataRequestMeasures(intent, finalPipeline) });
8642
+ var dimensionPipeline = applyAssistantDataIntentDimensionsToPipeline(pipeline, templatedDimensions);
8643
+ var filterApplication = applyAssistantDataIntentContractFiltersToPipeline(dimensionPipeline, intent, requestUnderstanding.contract);
8644
+ var finalPipeline = filterApplication.pipeline;
8645
+ var droppedBreakdownAmbiguities = resolveAssistantDroppedBreakdownAmbiguities(requestUnderstanding.contract, finalPipeline);
8646
+ var droppedFilterAmbiguities = resolveAssistantDroppedFilterAmbiguities(requestUnderstanding.contract, finalPipeline, filterApplication.appliedFilterKeys);
8647
+ var droppedContractAmbiguities = mergeAssistantHintValues(droppedBreakdownAmbiguities, droppedFilterAmbiguities);
8648
+ metadata.requestContract = __assign(__assign({}, requestUnderstanding.contract), { measures: buildAssistantDataRequestMeasures(intent, finalPipeline), ambiguities: mergeAssistantHintValues(requestUnderstanding.contract.ambiguities || [], droppedContractAmbiguities), confidence: droppedContractAmbiguities.length
8649
+ ? Math.min(requestUnderstanding.contract.confidence || 0.65, 0.65)
8650
+ : requestUnderstanding.contract.confidence });
8102
8651
  return { type: 'aggregate', payload: basePayload(finalPipeline), cleaned: '', rawLine: "HEURISTIC_AGG(app-data-intent:".concat(intent.id, ")"), metadata: metadata };
8103
8652
  }
8104
8653
  function isAssistantDeterministicHeuristicDirective(directive) {
@@ -8263,7 +8812,7 @@ function ensureAssistantDisplayColumns(display, requestedColumns) {
8263
8812
  return __assign(__assign({}, display), { columns: columns, rows: rows });
8264
8813
  }
8265
8814
  function resolveAssistantPipelineTimeGrain(pipeline) {
8266
- var e_6, _a;
8815
+ var e_8, _a;
8267
8816
  if (!Array.isArray(pipeline) || !pipeline.length) {
8268
8817
  return null;
8269
8818
  }
@@ -8325,12 +8874,12 @@ function resolveAssistantPipelineTimeGrain(pipeline) {
8325
8874
  }
8326
8875
  }
8327
8876
  }
8328
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
8877
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
8329
8878
  finally {
8330
8879
  try {
8331
8880
  if (priority_1_1 && !priority_1_1.done && (_a = priority_1.return)) _a.call(priority_1);
8332
8881
  }
8333
- finally { if (e_6) throw e_6.error; }
8882
+ finally { if (e_8) throw e_8.error; }
8334
8883
  }
8335
8884
  return null;
8336
8885
  }
@@ -9015,6 +9564,48 @@ function formatAssistantEvidenceDate(value) {
9015
9564
  }
9016
9565
  return normalized.slice(0, 10);
9017
9566
  }
9567
+ function formatAssistantRequestBreakdownLabel(value) {
9568
+ var cleanLabel = function (label) { return normalizeOptionalString(label).replace(/[_-]+/g, ' ').replace(/\s+/g, ' ').trim(); };
9569
+ if (!value || typeof value !== 'object') {
9570
+ return cleanLabel(value);
9571
+ }
9572
+ var type = normalizeOptionalString(value.type).toLowerCase();
9573
+ if (type === 'time') {
9574
+ return cleanLabel(value.granularity)
9575
+ || cleanLabel(value.requested_text)
9576
+ || cleanLabel(value.dimension);
9577
+ }
9578
+ return cleanLabel(value.requested_text)
9579
+ || cleanLabel(value.dimension)
9580
+ || cleanLabel(value.field_hint);
9581
+ }
9582
+ function joinAssistantHumanList(values) {
9583
+ var cleaned = normalizeAssistantProgress(values).map(function (value) { return value.toLowerCase(); });
9584
+ if (!cleaned.length) {
9585
+ return '';
9586
+ }
9587
+ if (cleaned.length === 1) {
9588
+ return cleaned[0];
9589
+ }
9590
+ if (cleaned.length === 2) {
9591
+ return "".concat(cleaned[0], " and ").concat(cleaned[1]);
9592
+ }
9593
+ return "".concat(cleaned.slice(0, -1).join(', '), ", and ").concat(cleaned[cleaned.length - 1]);
9594
+ }
9595
+ function resolveAssistantRequestBreakdownSummary(requestContract) {
9596
+ var requestedBreakdowns = Array.isArray(requestContract === null || requestContract === void 0 ? void 0 : requestContract.requested_breakdowns)
9597
+ ? requestContract.requested_breakdowns
9598
+ : [];
9599
+ var labels = requestedBreakdowns
9600
+ .map(function (entry) { return formatAssistantRequestBreakdownLabel(entry); })
9601
+ .filter(Boolean);
9602
+ var joined = joinAssistantHumanList(labels);
9603
+ return joined ? "by ".concat(joined) : '';
9604
+ }
9605
+ function buildAssistantBreakdownProgressMessage(requestContract) {
9606
+ var breakdown = resolveAssistantRequestBreakdownSummary(requestContract);
9607
+ return breakdown ? "Grouping and summarizing results ".concat(breakdown) : '';
9608
+ }
9018
9609
  function buildAssistantToolFallbackResponse(result) {
9019
9610
  var _a, _b;
9020
9611
  var rowCount = Math.max(0, Number(result.output.rowCount || 0));
@@ -9038,6 +9629,10 @@ function buildAssistantToolFallbackResponse(result) {
9038
9629
  lines.push("- Source: ".concat(source));
9039
9630
  }
9040
9631
  lines.push("- Rows returned: ".concat(rowCount));
9632
+ var breakdown = resolveAssistantRequestBreakdownSummary(debug.requestContract);
9633
+ if (breakdown) {
9634
+ lines.push("- Summary breakdown: ".concat(breakdown));
9635
+ }
9041
9636
  if (customerText) {
9042
9637
  lines.push("- Filter: ".concat(customerText));
9043
9638
  }
@@ -9047,13 +9642,11 @@ function buildAssistantToolFallbackResponse(result) {
9047
9642
  if (typeof result.output.total === 'number') {
9048
9643
  lines.push("- Total: ".concat(result.output.total));
9049
9644
  }
9050
- if (rowCount <= 0) {
9051
- var assumptions = Array.isArray(debug.assumptions)
9052
- ? debug.assumptions.map(function (entry) { return normalizeOptionalString(entry); }).filter(Boolean)
9053
- : [];
9054
- if (assumptions.length) {
9055
- lines.push("- Assumptions: ".concat(assumptions.slice(0, 3).join('; ')));
9056
- }
9645
+ var assumptions = Array.isArray(debug.assumptions)
9646
+ ? debug.assumptions.map(function (entry) { return normalizeOptionalString(entry); }).filter(Boolean)
9647
+ : [];
9648
+ if (assumptions.length) {
9649
+ lines.push("- Assumptions: ".concat(assumptions.slice(0, 3).join('; ')));
9057
9650
  }
9058
9651
  var leadSummary = buildAssistantDisplayLeadSummary(result.output.display);
9059
9652
  if (leadSummary) {
@@ -9191,7 +9784,7 @@ function applyAssistantDatedReportWindow(value, toolResult) {
9191
9784
  return "".concat(line, "\n\n").concat(content).trim();
9192
9785
  }
9193
9786
  function resolveAssistantDatedReportWindow(toolResult) {
9194
- var e_7, _a;
9787
+ var e_9, _a;
9195
9788
  var _b, _c, _d, _e, _f, _g, _h, _j;
9196
9789
  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;
9197
9790
  var verificationStart = normalizeOptionalString(verificationWindow === null || verificationWindow === void 0 ? void 0 : verificationWindow.startDate);
@@ -9257,12 +9850,12 @@ function resolveAssistantDatedReportWindow(toolResult) {
9257
9850
  };
9258
9851
  }
9259
9852
  }
9260
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
9853
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
9261
9854
  finally {
9262
9855
  try {
9263
9856
  if (pipelineCandidates_1_1 && !pipelineCandidates_1_1.done && (_a = pipelineCandidates_1.return)) _a.call(pipelineCandidates_1);
9264
9857
  }
9265
- finally { if (e_7) throw e_7.error; }
9858
+ finally { if (e_9) throw e_9.error; }
9266
9859
  }
9267
9860
  return null;
9268
9861
  }
@@ -9725,9 +10318,30 @@ function createAssistantProgressTracker(messageId, initialProgress) {
9725
10318
  progress = normalizeAssistantProgress(__spreadArray(__spreadArray([], __read(progress), false), [item], false));
9726
10319
  queueProgressUpdate();
9727
10320
  },
9728
- stop: function () {
9729
- stopped = true;
9730
- }
10321
+ snapshot: function () { return __spreadArray([], __read(progress), false); },
10322
+ stop: function () { return __awaiter(_this, void 0, void 0, function () {
10323
+ var snapshot, _a;
10324
+ return __generator(this, function (_b) {
10325
+ switch (_b.label) {
10326
+ case 0:
10327
+ snapshot = __spreadArray([], __read(progress), false);
10328
+ if (!(messageId && snapshot.length)) return [3 /*break*/, 4];
10329
+ _b.label = 1;
10330
+ case 1:
10331
+ _b.trys.push([1, 3, , 4]);
10332
+ return [4 /*yield*/, updateAssistantProgress(messageId, snapshot)];
10333
+ case 2:
10334
+ _b.sent();
10335
+ return [3 /*break*/, 4];
10336
+ case 3:
10337
+ _a = _b.sent();
10338
+ return [3 /*break*/, 4];
10339
+ case 4:
10340
+ stopped = true;
10341
+ return [2 /*return*/, snapshot];
10342
+ }
10343
+ });
10344
+ }); }
9731
10345
  };
9732
10346
  }
9733
10347
  function buildAssistantCodexErrorMessage(error) {
@@ -9941,7 +10555,7 @@ function getValueAtPath(obj, path) {
9941
10555
  return walk(obj, 0);
9942
10556
  }
9943
10557
  function hasArrayValueAtPath(docs, path) {
9944
- var e_8, _a;
10558
+ var e_10, _a;
9945
10559
  if (!Array.isArray(docs) || !docs.length || !path) {
9946
10560
  return false;
9947
10561
  }
@@ -9954,17 +10568,17 @@ function hasArrayValueAtPath(docs, path) {
9954
10568
  }
9955
10569
  }
9956
10570
  }
9957
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
10571
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
9958
10572
  finally {
9959
10573
  try {
9960
10574
  if (docs_1_1 && !docs_1_1.done && (_a = docs_1.return)) _a.call(docs_1);
9961
10575
  }
9962
- finally { if (e_8) throw e_8.error; }
10576
+ finally { if (e_10) throw e_10.error; }
9963
10577
  }
9964
10578
  return false;
9965
10579
  }
9966
10580
  function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
9967
- var e_9, _a, e_10, _b;
10581
+ var e_11, _a, e_12, _b;
9968
10582
  if (!Array.isArray(docs) || !fieldPath) {
9969
10583
  return 'unknown';
9970
10584
  }
@@ -9977,7 +10591,7 @@ function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
9977
10591
  : doc === null || doc === void 0 ? void 0 : doc[fieldPath];
9978
10592
  var queue = Array.isArray(value) ? value : [value];
9979
10593
  try {
9980
- for (var queue_1 = (e_10 = void 0, __values(queue)), queue_1_1 = queue_1.next(); !queue_1_1.done; queue_1_1 = queue_1.next()) {
10594
+ 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()) {
9981
10595
  var entry = queue_1_1.value;
9982
10596
  if (entry === null || entry === undefined) {
9983
10597
  continue;
@@ -9990,21 +10604,21 @@ function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
9990
10604
  }
9991
10605
  }
9992
10606
  }
9993
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
10607
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
9994
10608
  finally {
9995
10609
  try {
9996
10610
  if (queue_1_1 && !queue_1_1.done && (_b = queue_1.return)) _b.call(queue_1);
9997
10611
  }
9998
- finally { if (e_10) throw e_10.error; }
10612
+ finally { if (e_12) throw e_12.error; }
9999
10613
  }
10000
10614
  }
10001
10615
  }
10002
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
10616
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
10003
10617
  finally {
10004
10618
  try {
10005
10619
  if (docs_2_1 && !docs_2_1.done && (_a = docs_2.return)) _a.call(docs_2);
10006
10620
  }
10007
- finally { if (e_9) throw e_9.error; }
10621
+ finally { if (e_11) throw e_11.error; }
10008
10622
  }
10009
10623
  return sawString ? 'string' : 'unknown';
10010
10624
  }
@@ -10099,7 +10713,7 @@ function normalizeLookupKeyValue(value) {
10099
10713
  return '';
10100
10714
  }
10101
10715
  function collectTopLevelIdFieldValues(docs, options) {
10102
- var e_11, _a, e_12, _b;
10716
+ var e_13, _a, e_14, _b;
10103
10717
  if (!Array.isArray(docs) || !docs.length) {
10104
10718
  return [];
10105
10719
  }
@@ -10147,26 +10761,26 @@ function collectTopLevelIdFieldValues(docs, options) {
10147
10761
  });
10148
10762
  };
10149
10763
  try {
10150
- for (var keys_1 = (e_12 = void 0, __values(keys)), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
10764
+ 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()) {
10151
10765
  var key = keys_1_1.value;
10152
10766
  _loop_3(key);
10153
10767
  }
10154
10768
  }
10155
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
10769
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
10156
10770
  finally {
10157
10771
  try {
10158
10772
  if (keys_1_1 && !keys_1_1.done && (_b = keys_1.return)) _b.call(keys_1);
10159
10773
  }
10160
- finally { if (e_12) throw e_12.error; }
10774
+ finally { if (e_14) throw e_14.error; }
10161
10775
  }
10162
10776
  }
10163
10777
  }
10164
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
10778
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
10165
10779
  finally {
10166
10780
  try {
10167
10781
  if (docs_3_1 && !docs_3_1.done && (_a = docs_3.return)) _a.call(docs_3);
10168
10782
  }
10169
- finally { if (e_11) throw e_11.error; }
10783
+ finally { if (e_13) throw e_13.error; }
10170
10784
  }
10171
10785
  return Array.from(fieldMap.entries()).map(function (_a) {
10172
10786
  var _b = __read(_a, 2), field = _b[0], values = _b[1];
@@ -10287,8 +10901,8 @@ function resolveLookupMappingsForField(field, mappings) {
10287
10901
  }
10288
10902
  function applyIdLookupDisplayEnrichment(params) {
10289
10903
  return __awaiter(this, void 0, void 0, function () {
10290
- var docs, collection, db, dbName, idClient, idCustomer, isSuperAdmin, idFields, lookupMappings, allCollections, collectionProbeCache, collectionSchemaCache, lookupMeta, enrichedDocs, _loop_4, idFields_1, idFields_1_1, fieldEntry, e_13_1;
10291
- var e_13, _a;
10904
+ var docs, collection, db, dbName, idClient, idCustomer, isSuperAdmin, idFields, lookupMappings, allCollections, collectionProbeCache, collectionSchemaCache, lookupMeta, enrichedDocs, _loop_4, idFields_1, idFields_1_1, fieldEntry, e_15_1;
10905
+ var e_15, _a;
10292
10906
  return __generator(this, function (_b) {
10293
10907
  switch (_b.label) {
10294
10908
  case 0:
@@ -10312,8 +10926,8 @@ function applyIdLookupDisplayEnrichment(params) {
10312
10926
  lookupMeta = [];
10313
10927
  enrichedDocs = docs.map(function (doc) { return (__assign({}, doc)); });
10314
10928
  _loop_4 = function (fieldEntry) {
10315
- var values, baseToken, mappingMatches, candidateCollections, filteredCandidates, _loop_5, filteredCandidates_1, filteredCandidates_1_1, candidate, state_3, e_14_1;
10316
- var e_14, _c;
10929
+ var values, baseToken, mappingMatches, candidateCollections, filteredCandidates, _loop_5, filteredCandidates_1, filteredCandidates_1_1, candidate, state_3, e_16_1;
10930
+ var e_16, _c;
10317
10931
  return __generator(this, function (_d) {
10318
10932
  switch (_d.label) {
10319
10933
  case 0:
@@ -10487,7 +11101,7 @@ function applyIdLookupDisplayEnrichment(params) {
10487
11101
  _d.label = 1;
10488
11102
  case 1:
10489
11103
  _d.trys.push([1, 6, 7, 8]);
10490
- filteredCandidates_1 = (e_14 = void 0, __values(filteredCandidates)), filteredCandidates_1_1 = filteredCandidates_1.next();
11104
+ filteredCandidates_1 = (e_16 = void 0, __values(filteredCandidates)), filteredCandidates_1_1 = filteredCandidates_1.next();
10491
11105
  _d.label = 2;
10492
11106
  case 2:
10493
11107
  if (!!filteredCandidates_1_1.done) return [3 /*break*/, 5];
@@ -10503,14 +11117,14 @@ function applyIdLookupDisplayEnrichment(params) {
10503
11117
  return [3 /*break*/, 2];
10504
11118
  case 5: return [3 /*break*/, 8];
10505
11119
  case 6:
10506
- e_14_1 = _d.sent();
10507
- e_14 = { error: e_14_1 };
11120
+ e_16_1 = _d.sent();
11121
+ e_16 = { error: e_16_1 };
10508
11122
  return [3 /*break*/, 8];
10509
11123
  case 7:
10510
11124
  try {
10511
11125
  if (filteredCandidates_1_1 && !filteredCandidates_1_1.done && (_c = filteredCandidates_1.return)) _c.call(filteredCandidates_1);
10512
11126
  }
10513
- finally { if (e_14) throw e_14.error; }
11127
+ finally { if (e_16) throw e_16.error; }
10514
11128
  return [7 /*endfinally*/];
10515
11129
  case 8: return [2 /*return*/];
10516
11130
  }
@@ -10533,14 +11147,14 @@ function applyIdLookupDisplayEnrichment(params) {
10533
11147
  return [3 /*break*/, 3];
10534
11148
  case 6: return [3 /*break*/, 9];
10535
11149
  case 7:
10536
- e_13_1 = _b.sent();
10537
- e_13 = { error: e_13_1 };
11150
+ e_15_1 = _b.sent();
11151
+ e_15 = { error: e_15_1 };
10538
11152
  return [3 /*break*/, 9];
10539
11153
  case 8:
10540
11154
  try {
10541
11155
  if (idFields_1_1 && !idFields_1_1.done && (_a = idFields_1.return)) _a.call(idFields_1);
10542
11156
  }
10543
- finally { if (e_13) throw e_13.error; }
11157
+ finally { if (e_15) throw e_15.error; }
10544
11158
  return [7 /*endfinally*/];
10545
11159
  case 9:
10546
11160
  if (!lookupMeta.length) {
@@ -10559,7 +11173,7 @@ function applyIdLookupDisplayEnrichment(params) {
10559
11173
  });
10560
11174
  }
10561
11175
  function hasNonEmptyValue(docs, fieldPath, options) {
10562
- var e_15, _a;
11176
+ var e_17, _a;
10563
11177
  if (!Array.isArray(docs) || !fieldPath) {
10564
11178
  return false;
10565
11179
  }
@@ -10576,12 +11190,12 @@ function hasNonEmptyValue(docs, fieldPath, options) {
10576
11190
  }
10577
11191
  }
10578
11192
  }
10579
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
11193
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
10580
11194
  finally {
10581
11195
  try {
10582
11196
  if (docs_4_1 && !docs_4_1.done && (_a = docs_4.return)) _a.call(docs_4);
10583
11197
  }
10584
- finally { if (e_15) throw e_15.error; }
11198
+ finally { if (e_17) throw e_17.error; }
10585
11199
  }
10586
11200
  return false;
10587
11201
  }
@@ -13197,7 +13811,7 @@ function flattenAssistantExprClauses(expr) {
13197
13811
  return [expr];
13198
13812
  }
13199
13813
  function detectAssistantMonthWindowInExpr(expr, allowedDateFields) {
13200
- var e_16, _a;
13814
+ var e_18, _a;
13201
13815
  var clauses = flattenAssistantExprClauses(expr);
13202
13816
  if (!clauses.length) {
13203
13817
  return null;
@@ -13271,12 +13885,12 @@ function detectAssistantMonthWindowInExpr(expr, allowedDateFields) {
13271
13885
  return state_4.value;
13272
13886
  }
13273
13887
  }
13274
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
13888
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
13275
13889
  finally {
13276
13890
  try {
13277
13891
  if (lowerClauses_1_1 && !lowerClauses_1_1.done && (_a = lowerClauses_1.return)) _a.call(lowerClauses_1);
13278
13892
  }
13279
- finally { if (e_16) throw e_16.error; }
13893
+ finally { if (e_18) throw e_18.error; }
13280
13894
  }
13281
13895
  return null;
13282
13896
  }
@@ -13339,7 +13953,7 @@ function resolveAssistantMonthlyGroupDateFields(pipeline) {
13339
13953
  return fields;
13340
13954
  }
13341
13955
  function detectAssistantMonthWindowFromPipeline(pipeline) {
13342
- var e_17, _a;
13956
+ var e_19, _a;
13343
13957
  var _b;
13344
13958
  var monthlyFields = resolveAssistantMonthlyGroupDateFields(pipeline);
13345
13959
  var scanMatch = function (match) {
@@ -13367,12 +13981,12 @@ function detectAssistantMonthWindowFromPipeline(pipeline) {
13367
13981
  }
13368
13982
  }
13369
13983
  }
13370
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
13984
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
13371
13985
  finally {
13372
13986
  try {
13373
13987
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
13374
13988
  }
13375
- finally { if (e_17) throw e_17.error; }
13989
+ finally { if (e_19) throw e_19.error; }
13376
13990
  }
13377
13991
  return null;
13378
13992
  }
@@ -13652,7 +14266,7 @@ function normalizeAssistantCustomerLookupProjectionPipeline(pipeline) {
13652
14266
  var nextProject = __assign({}, project);
13653
14267
  var stageChanged = false;
13654
14268
  Object.keys(nextProject).forEach(function (field) {
13655
- var e_18, _a;
14269
+ var e_20, _a;
13656
14270
  var expression = nextProject[field];
13657
14271
  if (typeof expression !== 'string') {
13658
14272
  return;
@@ -13688,12 +14302,12 @@ function normalizeAssistantCustomerLookupProjectionPipeline(pipeline) {
13688
14302
  break;
13689
14303
  }
13690
14304
  }
13691
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
14305
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
13692
14306
  finally {
13693
14307
  try {
13694
14308
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
13695
14309
  }
13696
- finally { if (e_18) throw e_18.error; }
14310
+ finally { if (e_20) throw e_20.error; }
13697
14311
  }
13698
14312
  });
13699
14313
  if (stageChanged) {
@@ -13866,7 +14480,7 @@ function matchContainsField(value, field) {
13866
14480
  });
13867
14481
  }
13868
14482
  function resolveAggregateCompletionFallback(pipeline) {
13869
- var e_19, _a;
14483
+ var e_21, _a;
13870
14484
  if (!Array.isArray(pipeline)) {
13871
14485
  return null;
13872
14486
  }
@@ -13879,7 +14493,7 @@ function resolveAggregateCompletionFallback(pipeline) {
13879
14493
  }
13880
14494
  var addFields = stage.$addFields;
13881
14495
  try {
13882
- for (var _b = (e_19 = void 0, __values(Object.keys(addFields))), _c = _b.next(); !_c.done; _c = _b.next()) {
14496
+ for (var _b = (e_21 = void 0, __values(Object.keys(addFields))), _c = _b.next(); !_c.done; _c = _b.next()) {
13883
14497
  var key = _c.value;
13884
14498
  if (!isCompletionFieldName(key)) {
13885
14499
  continue;
@@ -13893,12 +14507,12 @@ function resolveAggregateCompletionFallback(pipeline) {
13893
14507
  }
13894
14508
  }
13895
14509
  }
13896
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
14510
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
13897
14511
  finally {
13898
14512
  try {
13899
14513
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
13900
14514
  }
13901
- finally { if (e_19) throw e_19.error; }
14515
+ finally { if (e_21) throw e_21.error; }
13902
14516
  }
13903
14517
  if (candidateField) {
13904
14518
  break;
@@ -14054,7 +14668,7 @@ function buildCompletionFallbackSources(field) {
14054
14668
  ]);
14055
14669
  }
14056
14670
  function resolveAggregateCompletionExprFallback(pipeline) {
14057
- var e_20, _a;
14671
+ var e_22, _a;
14058
14672
  if (!Array.isArray(pipeline)) {
14059
14673
  return null;
14060
14674
  }
@@ -14074,7 +14688,7 @@ function resolveAggregateCompletionExprFallback(pipeline) {
14074
14688
  }
14075
14689
  if (!candidateField) {
14076
14690
  try {
14077
- for (var _b = (e_20 = void 0, __values(Object.keys(matchStage))), _c = _b.next(); !_c.done; _c = _b.next()) {
14691
+ for (var _b = (e_22 = void 0, __values(Object.keys(matchStage))), _c = _b.next(); !_c.done; _c = _b.next()) {
14078
14692
  var key = _c.value;
14079
14693
  if (key.startsWith('$')) {
14080
14694
  continue;
@@ -14089,12 +14703,12 @@ function resolveAggregateCompletionExprFallback(pipeline) {
14089
14703
  }
14090
14704
  }
14091
14705
  }
14092
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
14706
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
14093
14707
  finally {
14094
14708
  try {
14095
14709
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
14096
14710
  }
14097
- finally { if (e_20) throw e_20.error; }
14711
+ finally { if (e_22) throw e_22.error; }
14098
14712
  }
14099
14713
  }
14100
14714
  if (!candidateField) {
@@ -14296,7 +14910,7 @@ function hasAssistantDateGroupingOperator(value) {
14296
14910
  return Object.keys(value).some(function (key) { return hasAssistantDateGroupingOperator(value[key]); });
14297
14911
  }
14298
14912
  function isGroupFieldDerivedFromDateExpression(pipeline, groupIndex, groupPaths) {
14299
- var e_21, _a, e_22, _b;
14913
+ var e_23, _a, e_24, _b;
14300
14914
  if (!Array.isArray(pipeline) || groupIndex <= 0 || !groupPaths.length) {
14301
14915
  return false;
14302
14916
  }
@@ -14322,14 +14936,14 @@ function isGroupFieldDerivedFromDateExpression(pipeline, groupIndex, groupPaths)
14322
14936
  continue;
14323
14937
  }
14324
14938
  try {
14325
- for (var stageKeys_1 = (e_21 = void 0, __values(stageKeys)), stageKeys_1_1 = stageKeys_1.next(); !stageKeys_1_1.done; stageKeys_1_1 = stageKeys_1.next()) {
14939
+ 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()) {
14326
14940
  var stageKey = stageKeys_1_1.value;
14327
14941
  var payload = stage[stageKey];
14328
14942
  if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
14329
14943
  continue;
14330
14944
  }
14331
14945
  try {
14332
- for (var groupFields_1 = (e_22 = void 0, __values(groupFields)), groupFields_1_1 = groupFields_1.next(); !groupFields_1_1.done; groupFields_1_1 = groupFields_1.next()) {
14946
+ 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()) {
14333
14947
  var groupField = groupFields_1_1.value;
14334
14948
  if (!Object.prototype.hasOwnProperty.call(payload, groupField)) {
14335
14949
  continue;
@@ -14339,21 +14953,21 @@ function isGroupFieldDerivedFromDateExpression(pipeline, groupIndex, groupPaths)
14339
14953
  }
14340
14954
  }
14341
14955
  }
14342
- catch (e_22_1) { e_22 = { error: e_22_1 }; }
14956
+ catch (e_24_1) { e_24 = { error: e_24_1 }; }
14343
14957
  finally {
14344
14958
  try {
14345
14959
  if (groupFields_1_1 && !groupFields_1_1.done && (_b = groupFields_1.return)) _b.call(groupFields_1);
14346
14960
  }
14347
- finally { if (e_22) throw e_22.error; }
14961
+ finally { if (e_24) throw e_24.error; }
14348
14962
  }
14349
14963
  }
14350
14964
  }
14351
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
14965
+ catch (e_23_1) { e_23 = { error: e_23_1 }; }
14352
14966
  finally {
14353
14967
  try {
14354
14968
  if (stageKeys_1_1 && !stageKeys_1_1.done && (_a = stageKeys_1.return)) _a.call(stageKeys_1);
14355
14969
  }
14356
- finally { if (e_21) throw e_21.error; }
14970
+ finally { if (e_23) throw e_23.error; }
14357
14971
  }
14358
14972
  }
14359
14973
  return false;
@@ -14460,7 +15074,7 @@ function isRegexMatchCondition(value) {
14460
15074
  return false;
14461
15075
  }
14462
15076
  function findRegexMatchInMatchObject(match, prefix) {
14463
- var e_23, _a, e_24, _b;
15077
+ var e_25, _a, e_26, _b;
14464
15078
  if (prefix === void 0) { prefix = ''; }
14465
15079
  if (Array.isArray(match)) {
14466
15080
  try {
@@ -14472,12 +15086,12 @@ function findRegexMatchInMatchObject(match, prefix) {
14472
15086
  }
14473
15087
  }
14474
15088
  }
14475
- catch (e_23_1) { e_23 = { error: e_23_1 }; }
15089
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
14476
15090
  finally {
14477
15091
  try {
14478
15092
  if (match_1_1 && !match_1_1.done && (_a = match_1.return)) _a.call(match_1);
14479
15093
  }
14480
- finally { if (e_23) throw e_23.error; }
15094
+ finally { if (e_25) throw e_25.error; }
14481
15095
  }
14482
15096
  return null;
14483
15097
  }
@@ -14508,12 +15122,12 @@ function findRegexMatchInMatchObject(match, prefix) {
14508
15122
  }
14509
15123
  }
14510
15124
  }
14511
- catch (e_24_1) { e_24 = { error: e_24_1 }; }
15125
+ catch (e_26_1) { e_26 = { error: e_26_1 }; }
14512
15126
  finally {
14513
15127
  try {
14514
15128
  if (keys_2_1 && !keys_2_1.done && (_b = keys_2.return)) _b.call(keys_2);
14515
15129
  }
14516
- finally { if (e_24) throw e_24.error; }
15130
+ finally { if (e_26) throw e_26.error; }
14517
15131
  }
14518
15132
  return null;
14519
15133
  }
@@ -14902,7 +15516,7 @@ function collectMatchFieldsByCondition(match, predicate, prefix) {
14902
15516
  return results;
14903
15517
  }
14904
15518
  function findMatchConditionForField(match, targetField, prefix) {
14905
- var e_25, _a, e_26, _b;
15519
+ var e_27, _a, e_28, _b;
14906
15520
  if (prefix === void 0) { prefix = ''; }
14907
15521
  if (!match || typeof match !== 'object') {
14908
15522
  return undefined;
@@ -14917,12 +15531,12 @@ function findMatchConditionForField(match, targetField, prefix) {
14917
15531
  }
14918
15532
  }
14919
15533
  }
14920
- catch (e_25_1) { e_25 = { error: e_25_1 }; }
15534
+ catch (e_27_1) { e_27 = { error: e_27_1 }; }
14921
15535
  finally {
14922
15536
  try {
14923
15537
  if (match_2_1 && !match_2_1.done && (_a = match_2.return)) _a.call(match_2);
14924
15538
  }
14925
- finally { if (e_25) throw e_25.error; }
15539
+ finally { if (e_27) throw e_27.error; }
14926
15540
  }
14927
15541
  return undefined;
14928
15542
  }
@@ -14949,12 +15563,12 @@ function findMatchConditionForField(match, targetField, prefix) {
14949
15563
  }
14950
15564
  }
14951
15565
  }
14952
- catch (e_26_1) { e_26 = { error: e_26_1 }; }
15566
+ catch (e_28_1) { e_28 = { error: e_28_1 }; }
14953
15567
  finally {
14954
15568
  try {
14955
15569
  if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
14956
15570
  }
14957
- finally { if (e_26) throw e_26.error; }
15571
+ finally { if (e_28) throw e_28.error; }
14958
15572
  }
14959
15573
  return undefined;
14960
15574
  }
@@ -15187,7 +15801,7 @@ function detectIdLikeValue(value) {
15187
15801
  return false;
15188
15802
  }
15189
15803
  function detectChemicalIdFromProbe(probeDocs, fields) {
15190
- var e_27, _a, e_28, _b;
15804
+ var e_29, _a, e_30, _b;
15191
15805
  if (!Array.isArray(probeDocs) || !probeDocs.length) {
15192
15806
  return false;
15193
15807
  }
@@ -15199,7 +15813,7 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
15199
15813
  for (var probeDocs_1 = __values(probeDocs), probeDocs_1_1 = probeDocs_1.next(); !probeDocs_1_1.done; probeDocs_1_1 = probeDocs_1.next()) {
15200
15814
  var doc = probeDocs_1_1.value;
15201
15815
  try {
15202
- for (var targets_1 = (e_28 = void 0, __values(targets)), targets_1_1 = targets_1.next(); !targets_1_1.done; targets_1_1 = targets_1.next()) {
15816
+ 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()) {
15203
15817
  var field = targets_1_1.value;
15204
15818
  var value = getValueAtPath(doc, field);
15205
15819
  if (Array.isArray(value)) {
@@ -15212,21 +15826,21 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
15212
15826
  }
15213
15827
  }
15214
15828
  }
15215
- catch (e_28_1) { e_28 = { error: e_28_1 }; }
15829
+ catch (e_30_1) { e_30 = { error: e_30_1 }; }
15216
15830
  finally {
15217
15831
  try {
15218
15832
  if (targets_1_1 && !targets_1_1.done && (_b = targets_1.return)) _b.call(targets_1);
15219
15833
  }
15220
- finally { if (e_28) throw e_28.error; }
15834
+ finally { if (e_30) throw e_30.error; }
15221
15835
  }
15222
15836
  }
15223
15837
  }
15224
- catch (e_27_1) { e_27 = { error: e_27_1 }; }
15838
+ catch (e_29_1) { e_29 = { error: e_29_1 }; }
15225
15839
  finally {
15226
15840
  try {
15227
15841
  if (probeDocs_1_1 && !probeDocs_1_1.done && (_a = probeDocs_1.return)) _a.call(probeDocs_1);
15228
15842
  }
15229
- finally { if (e_27) throw e_27.error; }
15843
+ finally { if (e_29) throw e_29.error; }
15230
15844
  }
15231
15845
  return false;
15232
15846
  }
@@ -15447,8 +16061,8 @@ function buildChemicalIdFieldCandidates(field) {
15447
16061
  }
15448
16062
  function applyChemicalNameLookupFallbackToQuery(params) {
15449
16063
  return __awaiter(this, void 0, void 0, function () {
15450
- var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, chemicalFields, targetField, condition, regex, sampleDocs, collectionNames, candidates, _loop_8, candidates_1, candidates_1_1, candidate, state_5, e_29_1;
15451
- var e_29, _a;
16064
+ var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, chemicalFields, targetField, condition, regex, sampleDocs, collectionNames, candidates, _loop_8, candidates_1, candidates_1_1, candidate, state_5, e_31_1;
16065
+ var e_31, _a;
15452
16066
  var _b;
15453
16067
  return __generator(this, function (_c) {
15454
16068
  switch (_c.label) {
@@ -15561,14 +16175,14 @@ function applyChemicalNameLookupFallbackToQuery(params) {
15561
16175
  return [3 /*break*/, 3];
15562
16176
  case 6: return [3 /*break*/, 9];
15563
16177
  case 7:
15564
- e_29_1 = _c.sent();
15565
- e_29 = { error: e_29_1 };
16178
+ e_31_1 = _c.sent();
16179
+ e_31 = { error: e_31_1 };
15566
16180
  return [3 /*break*/, 9];
15567
16181
  case 8:
15568
16182
  try {
15569
16183
  if (candidates_1_1 && !candidates_1_1.done && (_a = candidates_1.return)) _a.call(candidates_1);
15570
16184
  }
15571
- finally { if (e_29) throw e_29.error; }
16185
+ finally { if (e_31) throw e_31.error; }
15572
16186
  return [7 /*endfinally*/];
15573
16187
  case 9: return [2 /*return*/, null];
15574
16188
  }
@@ -15668,8 +16282,8 @@ function lookupIdsForNameMatch(params) {
15668
16282
  }
15669
16283
  function applyIdLookupFallbackToQuery(params) {
15670
16284
  return __awaiter(this, void 0, void 0, function () {
15671
- 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_30_1, e_31_1;
15672
- var e_31, _c, e_30, _d;
16285
+ 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;
16286
+ var e_33, _c, e_32, _d;
15673
16287
  var _e;
15674
16288
  return __generator(this, function (_f) {
15675
16289
  switch (_f.label) {
@@ -15739,7 +16353,7 @@ function applyIdLookupFallbackToQuery(params) {
15739
16353
  _f.label = 5;
15740
16354
  case 5:
15741
16355
  _f.trys.push([5, 14, 15, 16]);
15742
- candidates_2 = (e_30 = void 0, __values(candidates)), candidates_2_1 = candidates_2.next();
16356
+ candidates_2 = (e_32 = void 0, __values(candidates)), candidates_2_1 = candidates_2.next();
15743
16357
  _f.label = 6;
15744
16358
  case 6:
15745
16359
  if (!!candidates_2_1.done) return [3 /*break*/, 13];
@@ -15806,28 +16420,28 @@ function applyIdLookupFallbackToQuery(params) {
15806
16420
  return [3 /*break*/, 6];
15807
16421
  case 13: return [3 /*break*/, 16];
15808
16422
  case 14:
15809
- e_30_1 = _f.sent();
15810
- e_30 = { error: e_30_1 };
16423
+ e_32_1 = _f.sent();
16424
+ e_32 = { error: e_32_1 };
15811
16425
  return [3 /*break*/, 16];
15812
16426
  case 15:
15813
16427
  try {
15814
16428
  if (candidates_2_1 && !candidates_2_1.done && (_d = candidates_2.return)) _d.call(candidates_2);
15815
16429
  }
15816
- finally { if (e_30) throw e_30.error; }
16430
+ finally { if (e_32) throw e_32.error; }
15817
16431
  return [7 /*endfinally*/];
15818
16432
  case 16:
15819
16433
  conditions_1_1 = conditions_1.next();
15820
16434
  return [3 /*break*/, 4];
15821
16435
  case 17: return [3 /*break*/, 20];
15822
16436
  case 18:
15823
- e_31_1 = _f.sent();
15824
- e_31 = { error: e_31_1 };
16437
+ e_33_1 = _f.sent();
16438
+ e_33 = { error: e_33_1 };
15825
16439
  return [3 /*break*/, 20];
15826
16440
  case 19:
15827
16441
  try {
15828
16442
  if (conditions_1_1 && !conditions_1_1.done && (_c = conditions_1.return)) _c.call(conditions_1);
15829
16443
  }
15830
- finally { if (e_31) throw e_31.error; }
16444
+ finally { if (e_33) throw e_33.error; }
15831
16445
  return [7 /*endfinally*/];
15832
16446
  case 20: return [2 /*return*/, null];
15833
16447
  }
@@ -16272,8 +16886,8 @@ function resolveAssistantSurfaceFileCandidates(baseName) {
16272
16886
  }
16273
16887
  function readFirstAssistantSurfaceFile(candidates) {
16274
16888
  return __awaiter(this, void 0, void 0, function () {
16275
- var candidates_3, candidates_3_1, candidate, normalized, _a, e_32_1;
16276
- var e_32, _b;
16889
+ var candidates_3, candidates_3_1, candidate, normalized, _a, e_34_1;
16890
+ var e_34, _b;
16277
16891
  return __generator(this, function (_c) {
16278
16892
  switch (_c.label) {
16279
16893
  case 0:
@@ -16300,14 +16914,14 @@ function readFirstAssistantSurfaceFile(candidates) {
16300
16914
  return [3 /*break*/, 1];
16301
16915
  case 6: return [3 /*break*/, 9];
16302
16916
  case 7:
16303
- e_32_1 = _c.sent();
16304
- e_32 = { error: e_32_1 };
16917
+ e_34_1 = _c.sent();
16918
+ e_34 = { error: e_34_1 };
16305
16919
  return [3 /*break*/, 9];
16306
16920
  case 8:
16307
16921
  try {
16308
16922
  if (candidates_3_1 && !candidates_3_1.done && (_b = candidates_3.return)) _b.call(candidates_3);
16309
16923
  }
16310
- finally { if (e_32) throw e_32.error; }
16924
+ finally { if (e_34) throw e_34.error; }
16311
16925
  return [7 /*endfinally*/];
16312
16926
  case 9: return [2 /*return*/, ''];
16313
16927
  }
@@ -16857,6 +17471,15 @@ function cloneAssistantHeuristicProfile(profile) {
16857
17471
  preGroupStages: Array.isArray(dimension === null || dimension === void 0 ? void 0 : dimension.preGroupStages) ? (0, common_1.deepCopy)(dimension.preGroupStages) : undefined
16858
17472
  }); }).filter(function (dimension) { return !!dimension.id && dimension.groupId !== undefined; })
16859
17473
  : [],
17474
+ filterFields: Array.isArray(entry === null || entry === void 0 ? void 0 : entry.filterFields)
17475
+ ? entry.filterFields.map(function (filterField) { return ({
17476
+ id: normalizeOptionalString(filterField === null || filterField === void 0 ? void 0 : filterField.id),
17477
+ terms: mergeAssistantHintValues((filterField === null || filterField === void 0 ? void 0 : filterField.terms) || []).map(function (term) { return term.toLowerCase(); }),
17478
+ fields: mergeAssistantHintValues((filterField === null || filterField === void 0 ? void 0 : filterField.fields) || []),
17479
+ type: normalizeAssistantAppDataFilterFieldType(filterField === null || filterField === void 0 ? void 0 : filterField.type),
17480
+ operators: mergeAssistantHintValues((filterField === null || filterField === void 0 ? void 0 : filterField.operators) || []).map(function (operator) { return operator.toLowerCase(); })
17481
+ }); }).filter(function (filterField) { return !!filterField.id && !!filterField.fields.length; })
17482
+ : [],
16860
17483
  pipeline: Array.isArray(entry === null || entry === void 0 ? void 0 : entry.pipeline) ? (0, common_1.deepCopy)(entry.pipeline) : undefined,
16861
17484
  options: (entry === null || entry === void 0 ? void 0 : entry.options) && typeof entry.options === 'object' && !Array.isArray(entry.options)
16862
17485
  ? (0, common_1.deepCopy)(entry.options)
@@ -16957,6 +17580,13 @@ function normalizeAssistantAppDataDimensionType(value) {
16957
17580
  }
16958
17581
  return undefined;
16959
17582
  }
17583
+ function normalizeAssistantAppDataFilterFieldType(value) {
17584
+ var normalized = normalizeOptionalString(value).toLowerCase();
17585
+ if (normalized === 'string' || normalized === 'number' || normalized === 'boolean' || normalized === 'date') {
17586
+ return normalized;
17587
+ }
17588
+ return undefined;
17589
+ }
16960
17590
  function normalizeAssistantHeuristicStringList(value) {
16961
17591
  if (Array.isArray(value)) {
16962
17592
  return mergeAssistantHintValues(value.map(function (entry) { return normalizeOptionalString(entry).toLowerCase(); }));
@@ -17064,6 +17694,50 @@ function normalizeAssistantAppDataDimensions(value) {
17064
17694
  });
17065
17695
  return dimensions;
17066
17696
  }
17697
+ function normalizeAssistantAppDataFilterFields(value) {
17698
+ var entries = Array.isArray(value)
17699
+ ? value.map(function (entry) { return ({ key: '', entry: entry }); })
17700
+ : value && typeof value === 'object'
17701
+ ? Object.keys(value).map(function (key) { return ({ key: key, entry: value[key] }); })
17702
+ : [];
17703
+ var fields = [];
17704
+ entries.forEach(function (_a) {
17705
+ var key = _a.key, entry = _a.entry;
17706
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
17707
+ return;
17708
+ }
17709
+ var id = normalizeOptionalString(entry.id
17710
+ || entry.filter_id
17711
+ || entry.filterId
17712
+ || key);
17713
+ var rawFilterFields = entry.fields
17714
+ || entry.field_hints
17715
+ || entry.fieldHints
17716
+ || entry.field
17717
+ || [];
17718
+ var filterFields = (Array.isArray(rawFilterFields)
17719
+ ? mergeAssistantHintValues(rawFilterFields)
17720
+ : normalizeOptionalString(rawFilterFields)
17721
+ ? [normalizeOptionalString(rawFilterFields)]
17722
+ : []).filter(function (field) { return isAssistantProjectionKeyAllowed(field); });
17723
+ if (!id || !filterFields.length) {
17724
+ return;
17725
+ }
17726
+ var terms = normalizeAssistantHeuristicStringList(entry.terms
17727
+ || entry.aliases
17728
+ || entry.phrases
17729
+ || [id]).map(function (term) { return term.toLowerCase(); });
17730
+ fields.push({
17731
+ id: id,
17732
+ terms: terms.length ? terms : [id.toLowerCase()],
17733
+ fields: filterFields,
17734
+ type: normalizeAssistantAppDataFilterFieldType(entry.type),
17735
+ operators: normalizeAssistantHeuristicStringList(entry.operators || entry.ops || [])
17736
+ .map(function (operator) { return operator.toLowerCase(); })
17737
+ });
17738
+ });
17739
+ return fields;
17740
+ }
17067
17741
  function normalizeAssistantAppDataIntents(value) {
17068
17742
  var entries = Array.isArray(value) ? value : [];
17069
17743
  var intents = [];
@@ -17098,6 +17772,10 @@ function normalizeAssistantAppDataIntents(value) {
17098
17772
  || entry.breakdown_dimensions
17099
17773
  || entry.breakdownDimensions
17100
17774
  || []),
17775
+ filterFields: normalizeAssistantAppDataFilterFields(entry.filter_fields
17776
+ || entry.filterFields
17777
+ || entry.filters
17778
+ || []),
17101
17779
  pipeline: Array.isArray(entry.pipeline) ? (0, common_1.deepCopy)(entry.pipeline) : undefined,
17102
17780
  options: entry.options && typeof entry.options === 'object' && !Array.isArray(entry.options)
17103
17781
  ? (0, common_1.deepCopy)(entry.options)
@@ -17828,7 +18506,7 @@ function doesAssistantPreserveAnyTermMatch(text, terms) {
17828
18506
  return (Array.isArray(terms) ? terms : []).some(function (term) { return doesAssistantPreserveTermMatch(text, term); });
17829
18507
  }
17830
18508
  function shouldPreserveAssistantCollectionForRouteFromRules(params) {
17831
- var e_33, _a;
18509
+ var e_35, _a;
17832
18510
  var _b, _c, _d, _e, _f, _g, _h;
17833
18511
  var routePreferred = normalizeAssistantCollectionOverrideName(params.routePreferredName);
17834
18512
  var requested = normalizeAssistantCollectionOverrideName(params.requestedCollection);
@@ -17860,12 +18538,12 @@ function shouldPreserveAssistantCollectionForRouteFromRules(params) {
17860
18538
  return true;
17861
18539
  }
17862
18540
  }
17863
- catch (e_33_1) { e_33 = { error: e_33_1 }; }
18541
+ catch (e_35_1) { e_35 = { error: e_35_1 }; }
17864
18542
  finally {
17865
18543
  try {
17866
18544
  if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
17867
18545
  }
17868
- finally { if (e_33) throw e_33.error; }
18546
+ finally { if (e_35) throw e_35.error; }
17869
18547
  }
17870
18548
  return false;
17871
18549
  }
@@ -18756,7 +19434,7 @@ function resolveAssistantNestedPrefixCollectionCandidates(params) {
18756
19434
  function resolveAssistantNestedAggregateFallbacks(params) {
18757
19435
  return __awaiter(this, void 0, void 0, function () {
18758
19436
  var prefixes, collectionNames, fallbacks, seen, prefixes_1, prefixes_1_1, prefix, rewrite, candidates, candidates_4, candidates_4_1, candidate, normalizedPipeline, key;
18759
- var e_34, _a, e_35, _b;
19437
+ var e_36, _a, e_37, _b;
18760
19438
  return __generator(this, function (_c) {
18761
19439
  switch (_c.label) {
18762
19440
  case 0:
@@ -18786,7 +19464,7 @@ function resolveAssistantNestedAggregateFallbacks(params) {
18786
19464
  triedCollections: params.triedCollections
18787
19465
  });
18788
19466
  try {
18789
- for (candidates_4 = (e_35 = void 0, __values(candidates)), candidates_4_1 = candidates_4.next(); !candidates_4_1.done; candidates_4_1 = candidates_4.next()) {
19467
+ for (candidates_4 = (e_37 = void 0, __values(candidates)), candidates_4_1 = candidates_4.next(); !candidates_4_1.done; candidates_4_1 = candidates_4.next()) {
18790
19468
  candidate = candidates_4_1.value;
18791
19469
  normalizedPipeline = normalizeAssistantAggregatePipeline(rewrite.pipeline, candidate);
18792
19470
  if (!normalizedPipeline.length || containsForbiddenMongoOperators(normalizedPipeline)) {
@@ -18808,21 +19486,21 @@ function resolveAssistantNestedAggregateFallbacks(params) {
18808
19486
  }
18809
19487
  }
18810
19488
  }
18811
- catch (e_35_1) { e_35 = { error: e_35_1 }; }
19489
+ catch (e_37_1) { e_37 = { error: e_37_1 }; }
18812
19490
  finally {
18813
19491
  try {
18814
19492
  if (candidates_4_1 && !candidates_4_1.done && (_b = candidates_4.return)) _b.call(candidates_4);
18815
19493
  }
18816
- finally { if (e_35) throw e_35.error; }
19494
+ finally { if (e_37) throw e_37.error; }
18817
19495
  }
18818
19496
  }
18819
19497
  }
18820
- catch (e_34_1) { e_34 = { error: e_34_1 }; }
19498
+ catch (e_36_1) { e_36 = { error: e_36_1 }; }
18821
19499
  finally {
18822
19500
  try {
18823
19501
  if (prefixes_1_1 && !prefixes_1_1.done && (_a = prefixes_1.return)) _a.call(prefixes_1);
18824
19502
  }
18825
- finally { if (e_34) throw e_34.error; }
19503
+ finally { if (e_36) throw e_36.error; }
18826
19504
  }
18827
19505
  return [2 /*return*/, fallbacks];
18828
19506
  }
@@ -18954,8 +19632,8 @@ function resolveAssistantBridgeCollectionHintCandidates(requestedCollection, req
18954
19632
  }
18955
19633
  function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
18956
19634
  return __awaiter(this, arguments, void 0, function (collection, db, dbName, options) {
18957
- var normalized, resolutionPath, pushResolutionStep, finalizeResolution, requestHints, appId, requestedTokens, requestedTokenWeights, aliasCandidates, hintCandidates, alias, manager, hasManager, configuredCollectionNames, isConfiguredCollection, candidates, pushCandidate, base, reportCandidate, candidates_5, candidates_5_1, candidate, model, candidates_6, candidates_6_1, candidate, primaryCollectionHint, resolverTargets, resolverErrorLogged, resolverTargets_1, resolverTargets_1_1, resolverTarget, resolved, resolvedName, resolvedScore, resolvedModel, _a, e_36_1, candidates_7, candidates_7_1, candidate, e_37_1, candidates_8, candidates_8_1, candidate;
18958
- var e_38, _b, e_39, _c, e_36, _d, e_37, _e, e_40, _f;
19635
+ var normalized, resolutionPath, pushResolutionStep, finalizeResolution, requestHints, appId, requestedTokens, requestedTokenWeights, aliasCandidates, hintCandidates, alias, manager, hasManager, configuredCollectionNames, isConfiguredCollection, candidates, pushCandidate, base, reportCandidate, candidates_5, candidates_5_1, candidate, model, candidates_6, candidates_6_1, candidate, primaryCollectionHint, resolverTargets, resolverErrorLogged, resolverTargets_1, resolverTargets_1_1, resolverTarget, resolved, resolvedName, resolvedScore, resolvedModel, _a, e_38_1, candidates_7, candidates_7_1, candidate, e_39_1, candidates_8, candidates_8_1, candidate;
19636
+ var e_40, _b, e_41, _c, e_38, _d, e_39, _e, e_42, _f;
18959
19637
  var _g, _h;
18960
19638
  if (dbName === void 0) { dbName = ''; }
18961
19639
  return __generator(this, function (_j) {
@@ -19029,12 +19707,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
19029
19707
  }
19030
19708
  }
19031
19709
  }
19032
- catch (e_38_1) { e_38 = { error: e_38_1 }; }
19710
+ catch (e_40_1) { e_40 = { error: e_40_1 }; }
19033
19711
  finally {
19034
19712
  try {
19035
19713
  if (candidates_5_1 && !candidates_5_1.done && (_b = candidates_5.return)) _b.call(candidates_5);
19036
19714
  }
19037
- finally { if (e_38) throw e_38.error; }
19715
+ finally { if (e_40) throw e_40.error; }
19038
19716
  }
19039
19717
  }
19040
19718
  if (configuredCollectionNames.length) {
@@ -19049,12 +19727,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
19049
19727
  }
19050
19728
  }
19051
19729
  }
19052
- catch (e_39_1) { e_39 = { error: e_39_1 }; }
19730
+ catch (e_41_1) { e_41 = { error: e_41_1 }; }
19053
19731
  finally {
19054
19732
  try {
19055
19733
  if (candidates_6_1 && !candidates_6_1.done && (_c = candidates_6.return)) _c.call(candidates_6);
19056
19734
  }
19057
- finally { if (e_39) throw e_39.error; }
19735
+ finally { if (e_41) throw e_41.error; }
19058
19736
  }
19059
19737
  }
19060
19738
  primaryCollectionHint = normalizeOptionalString((_h = requestHints === null || requestHints === void 0 ? void 0 : requestHints.collectionHints) === null || _h === void 0 ? void 0 : _h[0]);
@@ -19115,14 +19793,14 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
19115
19793
  return [3 /*break*/, 2];
19116
19794
  case 7: return [3 /*break*/, 10];
19117
19795
  case 8:
19118
- e_36_1 = _j.sent();
19119
- e_36 = { error: e_36_1 };
19796
+ e_38_1 = _j.sent();
19797
+ e_38 = { error: e_38_1 };
19120
19798
  return [3 /*break*/, 10];
19121
19799
  case 9:
19122
19800
  try {
19123
19801
  if (resolverTargets_1_1 && !resolverTargets_1_1.done && (_d = resolverTargets_1.return)) _d.call(resolverTargets_1);
19124
19802
  }
19125
- finally { if (e_36) throw e_36.error; }
19803
+ finally { if (e_38) throw e_38.error; }
19126
19804
  return [7 /*endfinally*/];
19127
19805
  case 10:
19128
19806
  if (!db) return [3 /*break*/, 18];
@@ -19148,14 +19826,14 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
19148
19826
  return [3 /*break*/, 12];
19149
19827
  case 15: return [3 /*break*/, 18];
19150
19828
  case 16:
19151
- e_37_1 = _j.sent();
19152
- e_37 = { error: e_37_1 };
19829
+ e_39_1 = _j.sent();
19830
+ e_39 = { error: e_39_1 };
19153
19831
  return [3 /*break*/, 18];
19154
19832
  case 17:
19155
19833
  try {
19156
19834
  if (candidates_7_1 && !candidates_7_1.done && (_e = candidates_7.return)) _e.call(candidates_7);
19157
19835
  }
19158
- finally { if (e_37) throw e_37.error; }
19836
+ finally { if (e_39) throw e_39.error; }
19159
19837
  return [7 /*endfinally*/];
19160
19838
  case 18:
19161
19839
  try {
@@ -19166,12 +19844,12 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
19166
19844
  }
19167
19845
  }
19168
19846
  }
19169
- catch (e_40_1) { e_40 = { error: e_40_1 }; }
19847
+ catch (e_42_1) { e_42 = { error: e_42_1 }; }
19170
19848
  finally {
19171
19849
  try {
19172
19850
  if (candidates_8_1 && !candidates_8_1.done && (_f = candidates_8.return)) _f.call(candidates_8);
19173
19851
  }
19174
- finally { if (e_40) throw e_40.error; }
19852
+ finally { if (e_42) throw e_42.error; }
19175
19853
  }
19176
19854
  throw new Error('AI assistant report builder bridge: No queryable collection could be resolved.');
19177
19855
  }
@@ -19179,7 +19857,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
19179
19857
  });
19180
19858
  }
19181
19859
  function findQueryDateField(query) {
19182
- var e_41, _a, e_42, _b;
19860
+ var e_43, _a, e_44, _b;
19183
19861
  if (!query || typeof query !== 'object') {
19184
19862
  return null;
19185
19863
  }
@@ -19193,12 +19871,12 @@ function findQueryDateField(query) {
19193
19871
  }
19194
19872
  }
19195
19873
  }
19196
- catch (e_41_1) { e_41 = { error: e_41_1 }; }
19874
+ catch (e_43_1) { e_43 = { error: e_43_1 }; }
19197
19875
  finally {
19198
19876
  try {
19199
19877
  if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
19200
19878
  }
19201
- finally { if (e_41) throw e_41.error; }
19879
+ finally { if (e_43) throw e_43.error; }
19202
19880
  }
19203
19881
  return null;
19204
19882
  }
@@ -19217,12 +19895,12 @@ function findQueryDateField(query) {
19217
19895
  }
19218
19896
  }
19219
19897
  }
19220
- catch (e_42_1) { e_42 = { error: e_42_1 }; }
19898
+ catch (e_44_1) { e_44 = { error: e_44_1 }; }
19221
19899
  finally {
19222
19900
  try {
19223
19901
  if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
19224
19902
  }
19225
- finally { if (e_42) throw e_42.error; }
19903
+ finally { if (e_44) throw e_44.error; }
19226
19904
  }
19227
19905
  return null;
19228
19906
  }
@@ -19510,7 +20188,7 @@ function resolveQueryDateFieldFallback(query) {
19510
20188
  return { from: dateField, to: fallback };
19511
20189
  }
19512
20190
  function containsForbiddenMongoOperators(value) {
19513
- var e_43, _a;
20191
+ var e_45, _a;
19514
20192
  if (!value || typeof value !== 'object') {
19515
20193
  return false;
19516
20194
  }
@@ -19529,12 +20207,12 @@ function containsForbiddenMongoOperators(value) {
19529
20207
  }
19530
20208
  }
19531
20209
  }
19532
- catch (e_43_1) { e_43 = { error: e_43_1 }; }
20210
+ catch (e_45_1) { e_45 = { error: e_45_1 }; }
19533
20211
  finally {
19534
20212
  try {
19535
20213
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
19536
20214
  }
19537
- finally { if (e_43) throw e_43.error; }
20215
+ finally { if (e_45) throw e_45.error; }
19538
20216
  }
19539
20217
  return false;
19540
20218
  }
@@ -19719,7 +20397,7 @@ function splitAssistantPermissionTokenSets(value) {
19719
20397
  };
19720
20398
  }
19721
20399
  function isAssistantTokenSetSubset(subset, superset) {
19722
- var e_44, _a;
20400
+ var e_46, _a;
19723
20401
  if (!subset.size) {
19724
20402
  return false;
19725
20403
  }
@@ -19731,12 +20409,12 @@ function isAssistantTokenSetSubset(subset, superset) {
19731
20409
  }
19732
20410
  }
19733
20411
  }
19734
- catch (e_44_1) { e_44 = { error: e_44_1 }; }
20412
+ catch (e_46_1) { e_46 = { error: e_46_1 }; }
19735
20413
  finally {
19736
20414
  try {
19737
20415
  if (subset_1_1 && !subset_1_1.done && (_a = subset_1.return)) _a.call(subset_1);
19738
20416
  }
19739
- finally { if (e_44) throw e_44.error; }
20417
+ finally { if (e_46) throw e_46.error; }
19740
20418
  }
19741
20419
  return true;
19742
20420
  }
@@ -20271,8 +20949,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
20271
20949
  }
20272
20950
  function waitForCodexWorkerMessage(worker, streamStatusHandler) {
20273
20951
  return __awaiter(this, void 0, void 0, function () {
20274
- var _a, _b, _c, _d, message, payload, status_1, e_45_1;
20275
- var _e, e_45, _f, _g;
20952
+ var _a, _b, _c, _d, message, payload, status_1, e_47_1;
20953
+ var _e, e_47, _f, _g;
20276
20954
  return __generator(this, function (_h) {
20277
20955
  switch (_h.label) {
20278
20956
  case 0:
@@ -20299,8 +20977,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
20299
20977
  return [3 /*break*/, 1];
20300
20978
  case 4: return [3 /*break*/, 11];
20301
20979
  case 5:
20302
- e_45_1 = _h.sent();
20303
- e_45 = { error: e_45_1 };
20980
+ e_47_1 = _h.sent();
20981
+ e_47 = { error: e_47_1 };
20304
20982
  return [3 /*break*/, 11];
20305
20983
  case 6:
20306
20984
  _h.trys.push([6, , 9, 10]);
@@ -20311,7 +20989,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
20311
20989
  _h.label = 8;
20312
20990
  case 8: return [3 /*break*/, 10];
20313
20991
  case 9:
20314
- if (e_45) throw e_45.error;
20992
+ if (e_47) throw e_47.error;
20315
20993
  return [7 /*endfinally*/];
20316
20994
  case 10: return [7 /*endfinally*/];
20317
20995
  case 11: throw new CodexWorkerBootstrapError('AI worker exited before completing.');
@@ -20655,8 +21333,8 @@ function buildAssistantWorkspaceRootCandidates(params) {
20655
21333
  }
20656
21334
  function resolveAssistantWorkspaceRoot() {
20657
21335
  return __awaiter(this, void 0, void 0, function () {
20658
- var candidates, firstExisting, firstNestedGitRoot, candidates_9, candidates_9_1, candidate, _a, gitRoot, nestedGitRoots, e_46_1;
20659
- var e_46, _b;
21336
+ var candidates, firstExisting, firstNestedGitRoot, candidates_9, candidates_9_1, candidate, _a, gitRoot, nestedGitRoots, e_48_1;
21337
+ var e_48, _b;
20660
21338
  return __generator(this, function (_c) {
20661
21339
  switch (_c.label) {
20662
21340
  case 0:
@@ -20703,14 +21381,14 @@ function resolveAssistantWorkspaceRoot() {
20703
21381
  return [3 /*break*/, 2];
20704
21382
  case 8: return [3 /*break*/, 11];
20705
21383
  case 9:
20706
- e_46_1 = _c.sent();
20707
- e_46 = { error: e_46_1 };
21384
+ e_48_1 = _c.sent();
21385
+ e_48 = { error: e_48_1 };
20708
21386
  return [3 /*break*/, 11];
20709
21387
  case 10:
20710
21388
  try {
20711
21389
  if (candidates_9_1 && !candidates_9_1.done && (_b = candidates_9.return)) _b.call(candidates_9);
20712
21390
  }
20713
- finally { if (e_46) throw e_46.error; }
21391
+ finally { if (e_48) throw e_48.error; }
20714
21392
  return [7 /*endfinally*/];
20715
21393
  case 11:
20716
21394
  if (firstNestedGitRoot) {
@@ -21118,7 +21796,7 @@ var AI_ASSISTANT_BREAKDOWN_DIMENSION_STOPWORDS = new Set([
21118
21796
  'by'
21119
21797
  ]);
21120
21798
  function normalizeAssistantBreakdownDimension(value) {
21121
- var e_47, _a;
21799
+ var e_49, _a;
21122
21800
  var normalized = normalizeOptionalString(value)
21123
21801
  .toLowerCase()
21124
21802
  .replace(/[^a-z0-9_\s-]+/g, ' ')
@@ -21150,12 +21828,12 @@ function normalizeAssistantBreakdownDimension(value) {
21150
21828
  }
21151
21829
  }
21152
21830
  }
21153
- catch (e_47_1) { e_47 = { error: e_47_1 }; }
21831
+ catch (e_49_1) { e_49 = { error: e_49_1 }; }
21154
21832
  finally {
21155
21833
  try {
21156
21834
  if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
21157
21835
  }
21158
- finally { if (e_47) throw e_47.error; }
21836
+ finally { if (e_49) throw e_49.error; }
21159
21837
  }
21160
21838
  if (!kept.length) {
21161
21839
  return '';
@@ -21360,7 +22038,7 @@ function resolveAssistantPlannerEnabled(config) {
21360
22038
  return raw === undefined ? false : raw === true;
21361
22039
  }
21362
22040
  function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
21363
- var e_48, _a;
22041
+ var e_50, _a;
21364
22042
  var _b;
21365
22043
  if (isSuperAdmin === void 0) { isSuperAdmin = false; }
21366
22044
  var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
@@ -21374,12 +22052,12 @@ function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
21374
22052
  }
21375
22053
  }
21376
22054
  }
21377
- catch (e_48_1) { e_48 = { error: e_48_1 }; }
22055
+ catch (e_50_1) { e_50 = { error: e_50_1 }; }
21378
22056
  finally {
21379
22057
  try {
21380
22058
  if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
21381
22059
  }
21382
- finally { if (e_48) throw e_48.error; }
22060
+ finally { if (e_50) throw e_50.error; }
21383
22061
  }
21384
22062
  var normalizedRoutes = Array.from(unique);
21385
22063
  var allowedRoutes = collectAssistantAllowedRoutesForUser(user, normalizedRoutes, isSuperAdmin);
@@ -21755,7 +22433,7 @@ function normalizeRouteMatchKey(value) {
21755
22433
  return normalizeRouteKey(value).toLowerCase();
21756
22434
  }
21757
22435
  function buildClientRouteIndex() {
21758
- var e_49, _a;
22436
+ var e_51, _a;
21759
22437
  var _b;
21760
22438
  var routes = mergeAssistantHintValues(((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [], AI_ASSISTANT_CORE_PUBLIC_ROUTES);
21761
22439
  var set = new Set();
@@ -21774,12 +22452,12 @@ function buildClientRouteIndex() {
21774
22452
  }
21775
22453
  }
21776
22454
  }
21777
- catch (e_49_1) { e_49 = { error: e_49_1 }; }
22455
+ catch (e_51_1) { e_51 = { error: e_51_1 }; }
21778
22456
  finally {
21779
22457
  try {
21780
22458
  if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
21781
22459
  }
21782
- finally { if (e_49) throw e_49.error; }
22460
+ finally { if (e_51) throw e_51.error; }
21783
22461
  }
21784
22462
  return { set: set, map: map, size: routes.length };
21785
22463
  }
@@ -22670,8 +23348,8 @@ function shouldSkipAssistantGitDiscoveryDirectory(name) {
22670
23348
  }
22671
23349
  function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
22672
23350
  return __awaiter(this, void 0, void 0, function () {
22673
- var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b, e_50_1, queue, queued, enqueue, next, entries, _c, entries_1, entries_1_1, entry, childName, candidate, gitPath, _d, e_51_1;
22674
- var e_50, _e, e_51, _f;
23351
+ var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b, e_52_1, queue, queued, enqueue, next, entries, _c, entries_1, entries_1_1, entry, childName, candidate, gitPath, _d, e_53_1;
23352
+ var e_52, _e, e_53, _f;
22675
23353
  var _g;
22676
23354
  return __generator(this, function (_h) {
22677
23355
  switch (_h.label) {
@@ -22716,14 +23394,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
22716
23394
  return [3 /*break*/, 3];
22717
23395
  case 6: return [3 /*break*/, 9];
22718
23396
  case 7:
22719
- e_50_1 = _h.sent();
22720
- e_50 = { error: e_50_1 };
23397
+ e_52_1 = _h.sent();
23398
+ e_52 = { error: e_52_1 };
22721
23399
  return [3 /*break*/, 9];
22722
23400
  case 8:
22723
23401
  try {
22724
23402
  if (configuredRoots_1_1 && !configuredRoots_1_1.done && (_e = configuredRoots_1.return)) _e.call(configuredRoots_1);
22725
23403
  }
22726
- finally { if (e_50) throw e_50.error; }
23404
+ finally { if (e_52) throw e_52.error; }
22727
23405
  return [7 /*endfinally*/];
22728
23406
  case 9:
22729
23407
  queue = [];
@@ -22763,7 +23441,7 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
22763
23441
  return [3 /*break*/, 14];
22764
23442
  case 14:
22765
23443
  _h.trys.push([14, 21, 22, 23]);
22766
- entries_1 = (e_51 = void 0, __values(entries)), entries_1_1 = entries_1.next();
23444
+ entries_1 = (e_53 = void 0, __values(entries)), entries_1_1 = entries_1.next();
22767
23445
  _h.label = 15;
22768
23446
  case 15:
22769
23447
  if (!!entries_1_1.done) return [3 /*break*/, 20];
@@ -22802,14 +23480,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
22802
23480
  return [3 /*break*/, 15];
22803
23481
  case 20: return [3 /*break*/, 23];
22804
23482
  case 21:
22805
- e_51_1 = _h.sent();
22806
- e_51 = { error: e_51_1 };
23483
+ e_53_1 = _h.sent();
23484
+ e_53 = { error: e_53_1 };
22807
23485
  return [3 /*break*/, 23];
22808
23486
  case 22:
22809
23487
  try {
22810
23488
  if (entries_1_1 && !entries_1_1.done && (_f = entries_1.return)) _f.call(entries_1);
22811
23489
  }
22812
- finally { if (e_51) throw e_51.error; }
23490
+ finally { if (e_53) throw e_53.error; }
22813
23491
  return [7 /*endfinally*/];
22814
23492
  case 23: return [3 /*break*/, 10];
22815
23493
  case 24: return [2 /*return*/, roots];
@@ -23149,8 +23827,8 @@ function syncAssistantGitMirror(repoUrl) {
23149
23827
  }
23150
23828
  function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
23151
23829
  return __awaiter(this, void 0, void 0, function () {
23152
- var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot, e_52_1;
23153
- var e_52, _a;
23830
+ var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot, e_54_1;
23831
+ var e_54, _a;
23154
23832
  return __generator(this, function (_b) {
23155
23833
  switch (_b.label) {
23156
23834
  case 0: return [4 /*yield*/, resolveAssistantWorkspaceGitRoots(workspaceRoot)];
@@ -23184,14 +23862,14 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
23184
23862
  return [3 /*break*/, 3];
23185
23863
  case 6: return [3 /*break*/, 9];
23186
23864
  case 7:
23187
- e_52_1 = _b.sent();
23188
- e_52 = { error: e_52_1 };
23865
+ e_54_1 = _b.sent();
23866
+ e_54 = { error: e_54_1 };
23189
23867
  return [3 /*break*/, 9];
23190
23868
  case 8:
23191
23869
  try {
23192
23870
  if (repoUrls_1_1 && !repoUrls_1_1.done && (_a = repoUrls_1.return)) _a.call(repoUrls_1);
23193
23871
  }
23194
- finally { if (e_52) throw e_52.error; }
23872
+ finally { if (e_54) throw e_54.error; }
23195
23873
  return [7 /*endfinally*/];
23196
23874
  case 9: return [2 /*return*/, mirroredRoots];
23197
23875
  }
@@ -23200,8 +23878,8 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
23200
23878
  }
23201
23879
  function resolveAssistantChangeHistoryFastPathResponse(params) {
23202
23880
  return __awaiter(this, void 0, void 0, function () {
23203
- 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_53_1;
23204
- var e_53, _f;
23881
+ 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_55_1;
23882
+ var e_55, _f;
23205
23883
  return __generator(this, function (_g) {
23206
23884
  switch (_g.label) {
23207
23885
  case 0:
@@ -23323,14 +24001,14 @@ function resolveAssistantChangeHistoryFastPathResponse(params) {
23323
24001
  return [3 /*break*/, 7];
23324
24002
  case 20: return [3 /*break*/, 23];
23325
24003
  case 21:
23326
- e_53_1 = _g.sent();
23327
- e_53 = { error: e_53_1 };
24004
+ e_55_1 = _g.sent();
24005
+ e_55 = { error: e_55_1 };
23328
24006
  return [3 /*break*/, 23];
23329
24007
  case 22:
23330
24008
  try {
23331
24009
  if (gitRoots_1_1 && !gitRoots_1_1.done && (_f = gitRoots_1.return)) _f.call(gitRoots_1);
23332
24010
  }
23333
- finally { if (e_53) throw e_53.error; }
24011
+ finally { if (e_55) throw e_55.error; }
23334
24012
  return [7 /*endfinally*/];
23335
24013
  case 23:
23336
24014
  if (bestFallback) {
@@ -23511,7 +24189,7 @@ function sanitizeAssistantResponse(value) {
23511
24189
  return normalizeAssistantRoutes(normalizedCurrency);
23512
24190
  }
23513
24191
  function evaluateAssistantGuardrails(message) {
23514
- var e_54, _a;
24192
+ var e_56, _a;
23515
24193
  var normalized = String(message || '').toLowerCase();
23516
24194
  var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
23517
24195
  if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
@@ -23556,12 +24234,12 @@ function evaluateAssistantGuardrails(message) {
23556
24234
  }
23557
24235
  }
23558
24236
  }
23559
- catch (e_54_1) { e_54 = { error: e_54_1 }; }
24237
+ catch (e_56_1) { e_56 = { error: e_56_1 }; }
23560
24238
  finally {
23561
24239
  try {
23562
24240
  if (patterns_3_1 && !patterns_3_1.done && (_a = patterns_3.return)) _a.call(patterns_3);
23563
24241
  }
23564
- finally { if (e_54) throw e_54.error; }
24242
+ finally { if (e_56) throw e_56.error; }
23565
24243
  }
23566
24244
  return null;
23567
24245
  }
@@ -23666,7 +24344,7 @@ function tokenizeArithmeticExpression(expression) {
23666
24344
  return tokens;
23667
24345
  }
23668
24346
  function evaluateArithmeticExpression(expression) {
23669
- var e_55, _a, e_56, _b;
24347
+ var e_57, _a, e_58, _b;
23670
24348
  var tokens = tokenizeArithmeticExpression(expression);
23671
24349
  if (!tokens || !tokens.length) {
23672
24350
  return null;
@@ -23723,12 +24401,12 @@ function evaluateArithmeticExpression(expression) {
23723
24401
  prevToken = token;
23724
24402
  }
23725
24403
  }
23726
- catch (e_55_1) { e_55 = { error: e_55_1 }; }
24404
+ catch (e_57_1) { e_57 = { error: e_57_1 }; }
23727
24405
  finally {
23728
24406
  try {
23729
24407
  if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
23730
24408
  }
23731
- finally { if (e_55) throw e_55.error; }
24409
+ finally { if (e_57) throw e_57.error; }
23732
24410
  }
23733
24411
  while (ops.length) {
23734
24412
  var op = ops.pop();
@@ -23768,12 +24446,12 @@ function evaluateArithmeticExpression(expression) {
23768
24446
  stack.push(Number(token));
23769
24447
  }
23770
24448
  }
23771
- catch (e_56_1) { e_56 = { error: e_56_1 }; }
24449
+ catch (e_58_1) { e_58 = { error: e_58_1 }; }
23772
24450
  finally {
23773
24451
  try {
23774
24452
  if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
23775
24453
  }
23776
- finally { if (e_56) throw e_56.error; }
24454
+ finally { if (e_58) throw e_58.error; }
23777
24455
  }
23778
24456
  if (stack.length !== 1 || Number.isNaN(stack[0])) {
23779
24457
  return null;
@@ -23957,8 +24635,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
23957
24635
  }
23958
24636
  function readAttachmentContents(attachments) {
23959
24637
  return __awaiter(this, void 0, void 0, function () {
23960
- var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_57_1;
23961
- var e_57, _b;
24638
+ var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_59_1;
24639
+ var e_59, _b;
23962
24640
  return __generator(this, function (_c) {
23963
24641
  switch (_c.label) {
23964
24642
  case 0:
@@ -24037,14 +24715,14 @@ function readAttachmentContents(attachments) {
24037
24715
  return [3 /*break*/, 2];
24038
24716
  case 10: return [3 /*break*/, 13];
24039
24717
  case 11:
24040
- e_57_1 = _c.sent();
24041
- e_57 = { error: e_57_1 };
24718
+ e_59_1 = _c.sent();
24719
+ e_59 = { error: e_59_1 };
24042
24720
  return [3 /*break*/, 13];
24043
24721
  case 12:
24044
24722
  try {
24045
24723
  if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
24046
24724
  }
24047
- finally { if (e_57) throw e_57.error; }
24725
+ finally { if (e_59) throw e_59.error; }
24048
24726
  return [7 /*endfinally*/];
24049
24727
  case 13: return [2 /*return*/, {
24050
24728
  promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
@@ -24469,7 +25147,7 @@ function sanitizeAssistantMessageSetPayload(setPayload) {
24469
25147
  return next;
24470
25148
  }
24471
25149
  function sanitizeMongoSafeObject(value) {
24472
- var e_58, _a;
25150
+ var e_60, _a;
24473
25151
  if (value === null || value === undefined) {
24474
25152
  return value;
24475
25153
  }
@@ -24493,17 +25171,17 @@ function sanitizeMongoSafeObject(value) {
24493
25171
  out[key] = sanitizeMongoSafeObject(rawValue);
24494
25172
  }
24495
25173
  }
24496
- catch (e_58_1) { e_58 = { error: e_58_1 }; }
25174
+ catch (e_60_1) { e_60 = { error: e_60_1 }; }
24497
25175
  finally {
24498
25176
  try {
24499
25177
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
24500
25178
  }
24501
- finally { if (e_58) throw e_58.error; }
25179
+ finally { if (e_60) throw e_60.error; }
24502
25180
  }
24503
25181
  return out;
24504
25182
  }
24505
25183
  function restoreMongoSafeObject(value) {
24506
- var e_59, _a;
25184
+ var e_61, _a;
24507
25185
  if (value === null || value === undefined) {
24508
25186
  return value;
24509
25187
  }
@@ -24527,12 +25205,12 @@ function restoreMongoSafeObject(value) {
24527
25205
  out[key] = restoreMongoSafeObject(rawValue);
24528
25206
  }
24529
25207
  }
24530
- catch (e_59_1) { e_59 = { error: e_59_1 }; }
25208
+ catch (e_61_1) { e_61 = { error: e_61_1 }; }
24531
25209
  finally {
24532
25210
  try {
24533
25211
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
24534
25212
  }
24535
- finally { if (e_59) throw e_59.error; }
25213
+ finally { if (e_61) throw e_61.error; }
24536
25214
  }
24537
25215
  return out;
24538
25216
  }
@@ -24710,7 +25388,7 @@ function recordAssistantAnswerAIRun(input) {
24710
25388
  });
24711
25389
  }
24712
25390
  function evaluateGuardrails(message) {
24713
- var e_60, _a;
25391
+ var e_62, _a;
24714
25392
  var normalized = String(message || '').toLowerCase();
24715
25393
  var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
24716
25394
  if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
@@ -24736,12 +25414,12 @@ function evaluateGuardrails(message) {
24736
25414
  }
24737
25415
  }
24738
25416
  }
24739
- catch (e_60_1) { e_60 = { error: e_60_1 }; }
25417
+ catch (e_62_1) { e_62 = { error: e_62_1 }; }
24740
25418
  finally {
24741
25419
  try {
24742
25420
  if (patterns_4_1 && !patterns_4_1.done && (_a = patterns_4.return)) _a.call(patterns_4);
24743
25421
  }
24744
- finally { if (e_60) throw e_60.error; }
25422
+ finally { if (e_62) throw e_62.error; }
24745
25423
  }
24746
25424
  return null;
24747
25425
  }