@resolveio/server-lib 22.2.55 → 22.2.57

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.
@@ -110,15 +110,18 @@ exports.executeAiAssistantMongoRead = executeAiAssistantMongoRead;
110
110
  exports.executeAiAssistantMongoAggregate = executeAiAssistantMongoAggregate;
111
111
  exports.extractAssistantMongoDirective = extractAssistantMongoDirective;
112
112
  exports.buildAssistantToolRequest = buildAssistantToolRequest;
113
+ exports.shouldPreserveAssistantProbeCollectionForTesting = shouldPreserveAssistantProbeCollectionForTesting;
113
114
  exports.buildAssistantInvoiceCustomerLabelExpr = buildAssistantInvoiceCustomerLabelExpr;
114
115
  exports.resolveAssistantHeuristicDirectiveForTesting = resolveAssistantHeuristicDirectiveForTesting;
115
116
  exports.buildAssistantDatedPivotDisplay = buildAssistantDatedPivotDisplay;
117
+ exports.buildAssistantToolFallbackResponseForTesting = buildAssistantToolFallbackResponseForTesting;
116
118
  exports.deriveAssistantCommandExecutionStatus = deriveAssistantCommandExecutionStatus;
117
119
  exports.normalizeIdsForTargetField = normalizeIdsForTargetField;
118
120
  exports.serializeMongoValue = serializeMongoValue;
119
121
  exports.flattenForTable = flattenForTable;
120
122
  exports.buildDisplayTable = buildDisplayTable;
121
123
  exports.formatDisplayTableMarkdown = formatDisplayTableMarkdown;
124
+ exports.applyAssistantDisplayTableToResponseForTesting = applyAssistantDisplayTableToResponseForTesting;
122
125
  exports.resolveAssistantReadDisplayMaxRows = resolveAssistantReadDisplayMaxRows;
123
126
  exports.normalizeAssistantNowExprPlaceholders = normalizeAssistantNowExprPlaceholders;
124
127
  exports.repairAssistantPositionalPathSegmentsInPipeline = repairAssistantPositionalPathSegmentsInPipeline;
@@ -134,6 +137,8 @@ exports.resolveAssistantAppCollectionHintCandidates = resolveAssistantAppCollect
134
137
  exports.isAssistantDeterministicHeuristicEnabledForApp = isAssistantDeterministicHeuristicEnabledForApp;
135
138
  exports.resolveCollectionOverrideWithContextForTesting = resolveCollectionOverrideWithContextForTesting;
136
139
  exports.resolveAssistantCollectionOverride = resolveAssistantCollectionOverride;
140
+ exports.resolveAssistantCollectionNameForTesting = resolveAssistantCollectionNameForTesting;
141
+ exports.shouldLockAssistantRequestedCollectionForExecutionForTesting = shouldLockAssistantRequestedCollectionForExecutionForTesting;
137
142
  exports.resolveAssistantCrossCollectionFallbackCandidates = resolveAssistantCrossCollectionFallbackCandidates;
138
143
  exports.resolveAssistantAvailableCrossCollectionFallbacksFromNames = resolveAssistantAvailableCrossCollectionFallbacksFromNames;
139
144
  exports.evaluateAssistantFallbackDocumentsQuality = evaluateAssistantFallbackDocumentsQuality;
@@ -563,6 +568,8 @@ var AI_ASSISTANT_REPORT_BUILDER_EXPERT_PLAYBOOK = [
563
568
  '- Do not include extra directive lines or mixed directive types in one response.'
564
569
  ].join('\n');
565
570
  var AI_ASSISTANT_PLATFORM_EXTRA_RULES = [
571
+ 'Use the shared ResolveIO intelligence loop everywhere: inspect relevant workspace evidence, form a hypothesis, verify with code/data/logs/tests, then answer or implement.',
572
+ 'ResolveIO platform knowledge and repository evidence override generic model defaults.',
566
573
  'Never share proprietary code or file contents verbatim unless product policy explicitly allows it.',
567
574
  'You may read files, inspect the workspace, run non-destructive commands, and make targeted code changes when the user is asking for debugging, implementation, or fixes.',
568
575
  'Use the provided read-only data bridge for database validation (REPORT_BUILDER_READ/REPORT_BUILDER_AGG). Do not improvise unsafe credential or secret access.',
@@ -609,6 +616,7 @@ function buildAssistantSystemPromptText(platformPrompt) {
609
616
  '- If a report-* collection is unavailable, keep using REPORT_BUILDER_READ/REPORT_BUILDER_AGG with the best-matched collection family; the bridge can safely fall back to direct collection access.',
610
617
  '- Map user wording to internal collections/fields yourself. Do not ask for property names unless required to run a query.',
611
618
  '- Use app heuristics and context hints as weak signals only. Verify collection and field guesses before relying on them.',
619
+ '- Distinguish the root business object from related measured details. Example: if the user asks for jobs and chemicals sent, jobs/work orders are the root and chemicals are joined detail, not necessarily the root collection.',
612
620
  '- Do not guess or invent collections/fields. If unsure, verify in the codebase or run a small REPORT_BUILDER_READ probe (limit 1-5) to learn the shape.',
613
621
  '- Prefer running a small REPORT_BUILDER_READ probe over asking multiple questions.',
614
622
  '- Form a concrete hypothesis about collection/field/date mapping, then verify it with codebase context or a tiny probe before answering.',
@@ -678,6 +686,7 @@ function buildAssistantSystemPromptText(platformPrompt) {
678
686
  '- For performance, keep pipelines minimal: avoid $push arrays or large fields unless the user explicitly asks for them.',
679
687
  '- For completion metrics (ex: "completed per day"), filter by completed status when applicable and use completion date fields; if completion dates are missing, fall back to createdAt/date_created and note the fallback.',
680
688
  '- Before issuing REPORT_BUILDER_READ or REPORT_BUILDER_AGG, verify the collection name and key fields by checking collection/model definitions in the current app (look for "collectionName:" and date fields like date_created/date_completed/createdAt). Do not invent collection names.',
689
+ '- When a request names multiple business concepts, root the query in the concept being counted/listed/summarized, then use $lookup/$unwind for related detail concepts.',
681
690
  '- For creation-date questions when both date_created and createdAt exist, match both with $or so results are not missed.',
682
691
  '- When grouping by fields that can be arrays (drivers, deliveries, routes, chemicals), $unwind first and group by both id and name when available.',
683
692
  '- Use REPORT_BUILDER_READ/REPORT_BUILDER_AGG only to produce summaries/snapshots/health checks (not raw dumps) when permitted.',
@@ -1891,7 +1900,7 @@ function executeAiAssistantCodexRun(payload, context) {
1891
1900
  insertResult = _d.sent();
1892
1901
  assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
1893
1902
  enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
1894
- var runStart, fastModeEnabled, alwaysAllowProbeEnabled, plannerEnabled, runBudgetMs, assistantMongoMaxTimeMs, assistantSystemPrompt, runDeadlineMs, steps, recordStep, progressTracker, streamProgress, remainingRunBudgetMs, hasRunBudget, applyCodexStageBudget, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, 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, 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, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerBudgetAvailable, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, deniedModuleByIntent, permissionLabel, effectiveDirective, rankedCollections_1, directiveHintsBase_1, buildToolRequestForDirective, executionDirective, probeFieldHints, probeEnabled, probeBudgetAllowed, probeDirective, probeRequest, probeStart, probeResponse, _h, probeDurationMs, probeRowCount, probeRewrite, probeError_1, probeDurationMs, probeErrorMessage, toolRequest, requestedToolCollection, toolStart, toolResponse, _j, toolDurationMs, toolPayload, resolvedToolCollection, zeroRowResult, skipFollowupCodex, followupPrompt, followupStart, followupText, _k, error_3, errorMessage, existingFinal, error_4, runBudgetExceeded, includeToolExecutionTelemetry, toolExecutionTelemetry, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload, finalizeError_1, failedAt, fallbackContent, failureMetadata, persistError_1, _l;
1903
+ var runStart, fastModeEnabled, alwaysAllowProbeEnabled, plannerEnabled, runBudgetMs, assistantMongoMaxTimeMs, assistantSystemPrompt, runDeadlineMs, steps, recordStep, progressTracker, streamProgress, remainingRunBudgetMs, hasRunBudget, applyCodexStageBudget, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, 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, 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, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerBudgetAvailable, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, deniedModuleByIntent, permissionLabel, effectiveDirective, rankedCollections_1, directiveHintsBase_1, buildToolRequestForDirective, executionDirective, probeFieldHints, aggregateProbeDisabled, probeEnabled, probeBudgetAllowed, probeDirective, probeRequest, probeStart, probeResponse, _h, probeDurationMs, probeRowCount, probeRewrite, probeError_1, probeDurationMs, probeErrorMessage, toolRequest, requestedToolCollection, toolStart, toolResponse, _j, toolDurationMs, toolPayload, resolvedToolCollection, zeroRowResult, followupCodexEnabled, skipFollowupCodex, followupPrompt, followupStart, followupText, _k, error_3, errorMessage, existingFinal, error_4, runBudgetExceeded, includeToolExecutionTelemetry, toolExecutionTelemetry, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload, finalizeError_1, failedAt, fallbackContent, failureMetadata, persistError_1, _l;
1895
1904
  var _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, _21;
1896
1905
  return __generator(this, function (_22) {
1897
1906
  switch (_22.label) {
@@ -2107,7 +2116,7 @@ function executeAiAssistantCodexRun(payload, context) {
2107
2116
  }, 8);
2108
2117
  rankedCollectionHints = resolveCollectionHintsFromRanking(collectionRanking, 5);
2109
2118
  if (rankedCollectionHints.length) {
2110
- collectionHints = mergeAssistantHintValues(rankedCollectionHints, collectionHints);
2119
+ collectionHints = mergeAssistantHintValues(collectionHints, rankedCollectionHints);
2111
2120
  }
2112
2121
  rankedCollections = Array.isArray(collectionRanking === null || collectionRanking === void 0 ? void 0 : collectionRanking.ranked)
2113
2122
  ? collectionRanking === null || collectionRanking === void 0 ? void 0 : collectionRanking.ranked.map(function (entry) { return entry.name; })
@@ -2554,7 +2563,8 @@ function executeAiAssistantCodexRun(payload, context) {
2554
2563
  collectionRanking: collectionRanking,
2555
2564
  requestedCollection: requestedCollection,
2556
2565
  permissionView: normalizeOptionalString((_14 = directive.payload) === null || _14 === void 0 ? void 0 : _14.permissionView) || contextRoute,
2557
- collectionNames: collectionNames
2566
+ collectionNames: collectionNames,
2567
+ collectionHints: collectionHints
2558
2568
  })
2559
2569
  : null;
2560
2570
  if (collectionOverride) {
@@ -2637,7 +2647,8 @@ function executeAiAssistantCodexRun(payload, context) {
2637
2647
  };
2638
2648
  return [3 /*break*/, 63];
2639
2649
  case 40:
2640
- probeEnabled = AI_ASSISTANT_TOOL_MAX_STEPS > 1;
2650
+ aggregateProbeDisabled = executionDirective.type === 'aggregate' && !alwaysAllowProbeEnabled;
2651
+ probeEnabled = AI_ASSISTANT_TOOL_MAX_STEPS > 1 && !aggregateProbeDisabled;
2641
2652
  probeBudgetAllowed = alwaysAllowProbeEnabled
2642
2653
  || hasRunBudget('Grabbing Data: probe', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS);
2643
2654
  if (!(probeEnabled && probeBudgetAllowed)) return [3 /*break*/, 50];
@@ -2724,6 +2735,12 @@ function executeAiAssistantCodexRun(payload, context) {
2724
2735
  skippedReason: 'run_budget_exhausted'
2725
2736
  };
2726
2737
  }
2738
+ else if (aggregateProbeDisabled) {
2739
+ toolTelemetry.probe = {
2740
+ attempted: false,
2741
+ skippedReason: 'aggregate_probe_disabled'
2742
+ };
2743
+ }
2727
2744
  _22.label = 51;
2728
2745
  case 51:
2729
2746
  if (!(!alwaysAllowProbeEnabled && !hasRunBudget('Grabbing Data: final', AI_ASSISTANT_MONGO_MIN_STAGE_BUDGET_MS))) return [3 /*break*/, 52];
@@ -2790,14 +2807,18 @@ function executeAiAssistantCodexRun(payload, context) {
2790
2807
  progressTracker.push('Drafting response');
2791
2808
  zeroRowResult = toolPayload.result.output.rowCount <= 0;
2792
2809
  toolTelemetry.outcome = zeroRowResult ? { zeroRows: true } : undefined;
2793
- skipFollowupCodex = usedDeterministicHeuristicFastPath
2810
+ followupCodexEnabled = resolveAssistantFollowupCodexEnabled(input.config);
2811
+ skipFollowupCodex = !followupCodexEnabled
2812
+ || usedDeterministicHeuristicFastPath
2794
2813
  || isAssistantDeterministicHeuristicDirective(executionDirective)
2795
2814
  || zeroRowResult;
2796
2815
  if (!skipFollowupCodex) return [3 /*break*/, 57];
2797
2816
  recordStep('Drafting response: deterministic summary', {
2798
2817
  reason: zeroRowResult
2799
2818
  ? 'zero_rows'
2800
- : (normalizeOptionalString(executionDirective.rawLine) || 'deterministic_heuristic')
2819
+ : (!followupCodexEnabled
2820
+ ? 'followup_disabled'
2821
+ : (normalizeOptionalString(executionDirective.rawLine) || 'deterministic_heuristic'))
2801
2822
  });
2802
2823
  assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
2803
2824
  assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
@@ -3314,7 +3335,7 @@ function executeAiAssistantReportIssue(payload, context) {
3314
3335
  }
3315
3336
  function executeAiAssistantMongoRead(payload, context) {
3316
3337
  return __awaiter(this, void 0, void 0, function () {
3317
- var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, idApp, requestHints, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasReadRuntimeBudget, resolveReadMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, buildFindOptions, buildCountOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, multiTermFallback, fallbackRead, fallbackDocs, _d, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _e, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _f, activeFallback, fallbackRead, fallbackDocs, _g, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality, error_5, existingErrors, e_1_1, nameFields, dateFields, diagnostics, countOptions, queryNoName, _h, queryNoDate, _j, _k, _l, _m, allCollections, base, alt, altCount, _o, total, sanitizedDocuments, requestedFields, missingFields, _p, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
3338
+ var input, rawCollection, retryState, triedCollections, dbName, db, idApp, requestHints, lockRequestedCollection, crossCollectionRetryEnabled, collectionResolution, collection, preservePrimaryHintCollection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasReadRuntimeBudget, resolveReadMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, buildFindOptions, buildCountOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, multiTermFallback, fallbackRead, fallbackDocs, _d, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _e, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _f, activeFallback, fallbackRead, fallbackDocs, _g, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality, error_5, existingErrors, e_1_1, nameFields, dateFields, diagnostics, countOptions, queryNoName, _h, queryNoDate, _j, _k, _l, _m, allCollections, base, alt, altCount, _o, total, sanitizedDocuments, requestedFields, missingFields, _p, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
3318
3339
  var e_1, _q;
3319
3340
  var _this = this;
3320
3341
  var _r, _s;
@@ -3331,15 +3352,20 @@ function executeAiAssistantMongoRead(payload, context) {
3331
3352
  : {};
3332
3353
  triedCollections = buildAssistantTriedCollectionSet(retryState.triedCollections);
3333
3354
  addAssistantCollectionToTriedSet(triedCollections, rawCollection);
3334
- crossCollectionRetryEnabled = retryState.disableCrossCollectionRetry !== true;
3335
3355
  dbName = resolveAssistantDatabaseName(input.database, input.mongo);
3336
3356
  db = resolveio_server_app_1.ResolveIOServer.getMongoConnection().db(dbName);
3337
3357
  idApp = normalizeOptionalString(input.id_app);
3338
3358
  requestHints = normalizeAssistantDirectiveHints(input.__assistantHints);
3359
+ lockRequestedCollection = shouldLockAssistantRequestedCollectionForExecution(rawCollection, input.permissionView, requestHints);
3360
+ crossCollectionRetryEnabled = retryState.disableCrossCollectionRetry !== true && !lockRequestedCollection;
3339
3361
  return [4 /*yield*/, resolveAssistantCollectionName(db, dbName, rawCollection, idApp)];
3340
3362
  case 1:
3341
3363
  collectionResolution = _t.sent();
3342
3364
  collection = collectionResolution.name || rawCollection;
3365
+ preservePrimaryHintCollection = shouldPreserveAssistantPrimaryHintCollection(rawCollection, collection, requestHints);
3366
+ if (preservePrimaryHintCollection) {
3367
+ collection = rawCollection;
3368
+ }
3343
3369
  return [4 /*yield*/, resolveAssistantReportBuilderBridgeCollection(collection, db, dbName, {
3344
3370
  requestHints: requestHints,
3345
3371
  appId: idApp
@@ -4055,7 +4081,7 @@ function executeAiAssistantMongoRead(payload, context) {
4055
4081
  fallbackMeta.fieldAliases = fieldAliases;
4056
4082
  }
4057
4083
  return [2 /*return*/, __assign({ documents: sanitizedDocuments, total: total, display: display }, (canViewDebug ? {
4058
- debug: __assign(__assign({ collection: collection, collectionRequested: rawCollection, collectionResolved: collection, collectionMatched: collectionResolution.matched, collectionCandidates: collectionResolution.candidates, collectionScore: collectionResolution.score, bridge: bridgeCollection.mode === 'report-builder' ? 'report-builder' : 'direct-mongo', bridgeResolution: {
4084
+ debug: __assign(__assign({ collection: collection, collectionRequested: rawCollection, collectionResolved: collection, collectionMatched: preservePrimaryHintCollection ? true : collectionResolution.matched, collectionCandidates: preservePrimaryHintCollection ? [] : collectionResolution.candidates, collectionScore: preservePrimaryHintCollection ? 100 : collectionResolution.score, bridge: bridgeCollection.mode === 'report-builder' ? 'report-builder' : 'direct-mongo', bridgeResolution: {
4059
4085
  mode: bridgeCollection.mode,
4060
4086
  fallbackFrom: bridgeCollection.fallbackFrom || undefined,
4061
4087
  path: bridgeCollection.resolutionPath
@@ -4067,7 +4093,7 @@ function executeAiAssistantMongoRead(payload, context) {
4067
4093
  }
4068
4094
  function executeAiAssistantMongoAggregate(payload, context) {
4069
4095
  return __awaiter(this, void 0, void 0, function () {
4070
- var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, idApp, requestHints, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasAggregateRuntimeBudget, resolveAggregateMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, executedPipeline, dateField, buildAggregateOptions, buildAggregateCountOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _g, activeFallback, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks, error_7, errorMessage, existingErrors, e_2_1, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, fallbackAcceptanceOptions, crossCollectionCandidates, crossCollectionCandidates_2, crossCollectionCandidates_2_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, fallbackQuality, existingFallbacks, rejectedQuality, error_8, existingErrors, e_3_1, matchStages, diagnostics, combinedMatch, nameFields, dateFields, countOptions, queryNoName, _h, queryNoDate, _j, _k, _l, _m, allCollections, base, alt, altCount, _o, verification, _p, sanitizedDocuments, includeIds, displayDocs, idLookupDisplay, display;
4096
+ var input, rawCollection, retryState, triedCollections, dbName, db, idApp, requestHints, lockRequestedCollection, crossCollectionRetryEnabled, collectionResolution, collection, preservePrimaryHintCollection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, runtimeControl, runtimeFastMode, activeRuntimeControl, hasAggregateRuntimeBudget, resolveAggregateMaxTimeMS, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, executedPipeline, dateField, buildAggregateOptions, buildAggregateCountOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _g, activeFallback, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks, error_7, errorMessage, existingErrors, e_2_1, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, fallbackAcceptanceOptions, crossCollectionCandidates, crossCollectionCandidates_2, crossCollectionCandidates_2_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, fallbackQuality, existingFallbacks, rejectedQuality, error_8, existingErrors, e_3_1, matchStages, diagnostics, combinedMatch, nameFields, dateFields, countOptions, queryNoName, _h, queryNoDate, _j, _k, _l, _m, allCollections, base, alt, altCount, _o, verification, _p, sanitizedDocuments, includeIds, displayDocs, idLookupDisplay, display;
4071
4097
  var e_2, _q, e_3, _r;
4072
4098
  var _this = this;
4073
4099
  var _s, _t;
@@ -4084,15 +4110,20 @@ function executeAiAssistantMongoAggregate(payload, context) {
4084
4110
  : {};
4085
4111
  triedCollections = buildAssistantTriedCollectionSet(retryState.triedCollections);
4086
4112
  addAssistantCollectionToTriedSet(triedCollections, rawCollection);
4087
- crossCollectionRetryEnabled = retryState.disableCrossCollectionRetry !== true;
4088
4113
  dbName = resolveAssistantDatabaseName(input.database, input.mongo);
4089
4114
  db = resolveio_server_app_1.ResolveIOServer.getMongoConnection().db(dbName);
4090
4115
  idApp = normalizeOptionalString(input.id_app);
4091
4116
  requestHints = normalizeAssistantDirectiveHints(input.__assistantHints);
4117
+ lockRequestedCollection = shouldLockAssistantRequestedCollectionForExecution(rawCollection, input.permissionView, requestHints);
4118
+ crossCollectionRetryEnabled = retryState.disableCrossCollectionRetry !== true && !lockRequestedCollection;
4092
4119
  return [4 /*yield*/, resolveAssistantCollectionName(db, dbName, rawCollection, idApp)];
4093
4120
  case 1:
4094
4121
  collectionResolution = _u.sent();
4095
4122
  collection = collectionResolution.name || rawCollection;
4123
+ preservePrimaryHintCollection = shouldPreserveAssistantPrimaryHintCollection(rawCollection, collection, requestHints);
4124
+ if (preservePrimaryHintCollection) {
4125
+ collection = rawCollection;
4126
+ }
4096
4127
  return [4 /*yield*/, resolveAssistantReportBuilderBridgeCollection(collection, db, dbName, {
4097
4128
  requestHints: requestHints,
4098
4129
  appId: idApp
@@ -5073,7 +5104,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
5073
5104
  includeGroupFromId: false
5074
5105
  });
5075
5106
  return [2 /*return*/, __assign(__assign({ documents: sanitizedDocuments, display: display }, (verification ? { verification: verification } : {})), (canViewDebug ? {
5076
- debug: __assign(__assign(__assign({ collection: collection, collectionRequested: rawCollection, collectionResolved: collection, collectionMatched: collectionResolution.matched, collectionCandidates: collectionResolution.candidates, collectionScore: collectionResolution.score, bridge: bridgeCollection.mode === 'report-builder' ? 'report-builder' : 'direct-mongo', bridgeResolution: {
5107
+ debug: __assign(__assign(__assign({ collection: collection, collectionRequested: rawCollection, collectionResolved: collection, collectionMatched: preservePrimaryHintCollection ? true : collectionResolution.matched, collectionCandidates: preservePrimaryHintCollection ? [] : collectionResolution.candidates, collectionScore: preservePrimaryHintCollection ? 100 : collectionResolution.score, bridge: bridgeCollection.mode === 'report-builder' ? 'report-builder' : 'direct-mongo', bridgeResolution: {
5077
5108
  mode: bridgeCollection.mode,
5078
5109
  fallbackFrom: bridgeCollection.fallbackFrom || undefined,
5079
5110
  path: bridgeCollection.resolutionPath
@@ -5874,6 +5905,38 @@ function applyAssistantSortFieldAliases(sort, aliases) {
5874
5905
  });
5875
5906
  return next;
5876
5907
  }
5908
+ function doesAssistantPermissionRouteMatchCollection(permissionView, collection) {
5909
+ var routeKey = normalizeCollectionKey(permissionView);
5910
+ var collectionFamily = normalizeAssistantCollectionFamilyName(collection);
5911
+ var collectionKey = normalizeCollectionKey(collectionFamily || collection);
5912
+ if (!routeKey || !collectionKey || collectionKey.length < 5) {
5913
+ return false;
5914
+ }
5915
+ var collectionKeys = [collectionKey];
5916
+ if (collectionKey.endsWith('s') && collectionKey.length > 5) {
5917
+ collectionKeys.push(collectionKey.slice(0, -1));
5918
+ }
5919
+ return collectionKeys.some(function (key) { return key.length >= 5 && (routeKey.includes(key) || key.includes(routeKey)); });
5920
+ }
5921
+ function shouldPreserveAssistantProbeCollection(directive, resolvedCollection, probeResponse) {
5922
+ var _a, _b, _c;
5923
+ var requestedCollection = normalizeOptionalString((_a = directive === null || directive === void 0 ? void 0 : directive.payload) === null || _a === void 0 ? void 0 : _a.collection);
5924
+ var resolved = normalizeOptionalString(resolvedCollection);
5925
+ if (!requestedCollection || !resolved || requestedCollection === resolved) {
5926
+ return false;
5927
+ }
5928
+ var probeHints = normalizeAssistantDirectiveHints((_b = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _b === void 0 ? void 0 : _b.requestHints);
5929
+ if (shouldPreserveAssistantPrimaryHintCollection(requestedCollection, resolved, probeHints)) {
5930
+ return true;
5931
+ }
5932
+ var permissionView = normalizeOptionalString((_c = directive === null || directive === void 0 ? void 0 : directive.payload) === null || _c === void 0 ? void 0 : _c.permissionView);
5933
+ return !!(permissionView
5934
+ && doesAssistantPermissionRouteMatchCollection(permissionView, requestedCollection)
5935
+ && !doesAssistantPermissionRouteMatchCollection(permissionView, resolved));
5936
+ }
5937
+ function shouldPreserveAssistantProbeCollectionForTesting(directive, resolvedCollection, probeResponse) {
5938
+ return shouldPreserveAssistantProbeCollection(directive, resolvedCollection, probeResponse);
5939
+ }
5877
5940
  function rewriteAssistantDirectiveWithProbe(directive, probeResponse) {
5878
5941
  var _a, _b;
5879
5942
  if (!(directive === null || directive === void 0 ? void 0 : directive.payload) || typeof directive.payload !== 'object') {
@@ -5887,7 +5950,9 @@ function rewriteAssistantDirectiveWithProbe(directive, probeResponse) {
5887
5950
  var notes = [];
5888
5951
  var resolvedCollection = normalizeOptionalString(((_a = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _a === void 0 ? void 0 : _a.collectionResolved)
5889
5952
  || ((_b = probeResponse === null || probeResponse === void 0 ? void 0 : probeResponse.debug) === null || _b === void 0 ? void 0 : _b.collection));
5890
- if (resolvedCollection && resolvedCollection !== normalizeOptionalString(payload.collection)) {
5953
+ if (resolvedCollection
5954
+ && resolvedCollection !== normalizeOptionalString(payload.collection)
5955
+ && !shouldPreserveAssistantProbeCollection(directive, resolvedCollection, probeResponse)) {
5891
5956
  payload.collection = resolvedCollection;
5892
5957
  notes.push("collection:".concat(resolvedCollection));
5893
5958
  }
@@ -6589,10 +6654,10 @@ function isAssistantDeterministicHeuristicDirective(directive) {
6589
6654
  }
6590
6655
  function buildAssistantHeuristicDirective(message, collectionHints, collectionNames, appId) {
6591
6656
  if (collectionNames === void 0) { collectionNames = []; }
6592
- void collectionNames;
6593
6657
  if (!normalizeOptionalString(message)) {
6594
6658
  return null;
6595
6659
  }
6660
+ void collectionNames;
6596
6661
  var schemaHoursDirective = resolveAssistantDeterministicHeuristicEnabled(AI_ASSISTANT_HEURISTIC_ID_SCHEMA_HOURS_USER_TIME, appId)
6597
6662
  ? buildAssistantGenericHoursDirective(message, collectionHints, appId)
6598
6663
  : null;
@@ -6640,6 +6705,9 @@ function resolveDefaultAssistantPermissionView(collection) {
6640
6705
  if (base.startsWith('employee')) {
6641
6706
  return '/employee/list';
6642
6707
  }
6708
+ if (base === 'jobs' || base === 'job' || base.startsWith('job-') || base.startsWith('jobs-')) {
6709
+ return '/job/list';
6710
+ }
6643
6711
  if (/work[-_/ ]?orders?|maintenance[-_/ ]?orders?|repair[-_/ ]?orders?/.test(base)) {
6644
6712
  return '/order/list';
6645
6713
  }
@@ -7367,22 +7435,135 @@ function buildAssistantCodexToolFollowupPrompt(message, attachmentText, historyT
7367
7435
  var instruction = '\n\nInstruction:\nNow answer the user. Do NOT output another REPORT_BUILDER_* directive. Output plain Markdown. Summarize first, then include a Markdown table. If the Tool Result includes verification warnings that materially affect interpretation (partial periods, mixed metric/date basis, failed cross-check), mention them briefly and call out the metric/date basis used. Include explicit UTC date boundaries and never show placeholders like $$NOW.';
7368
7436
  return "System:\n".concat(systemPromptText).concat(contextBlock).concat(historyBlock, "\n\nUser:\n").concat(message).concat(attachmentText || '').concat(toolBlock).concat(instruction).trim();
7369
7437
  }
7438
+ function formatAssistantDisplayValueForSentence(value) {
7439
+ if (value === null || value === undefined) {
7440
+ return '';
7441
+ }
7442
+ if (typeof value === 'number' && Number.isFinite(value)) {
7443
+ return new Intl.NumberFormat('en-US', {
7444
+ maximumFractionDigits: Math.abs(value) >= 100 ? 0 : 2
7445
+ }).format(value);
7446
+ }
7447
+ if (value instanceof Date) {
7448
+ return value.toISOString();
7449
+ }
7450
+ var normalized = normalizeOptionalString(value);
7451
+ return normalized.length > 80 ? "".concat(normalized.slice(0, 77), "...") : normalized;
7452
+ }
7453
+ function isAssistantMetricDisplayColumn(column, value) {
7454
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
7455
+ return false;
7456
+ }
7457
+ var normalized = normalizeOptionalString(column).toLowerCase();
7458
+ if (!normalized || /\b(id|number|zip|phone)\b/.test(normalized)) {
7459
+ return false;
7460
+ }
7461
+ return true;
7462
+ }
7463
+ function getAssistantMetricDisplayColumnPriority(column) {
7464
+ var normalized = normalizeOptionalString(column)
7465
+ .toLowerCase()
7466
+ .replace(/[_-]+/g, ' ')
7467
+ .replace(/\s+/g, ' ')
7468
+ .trim();
7469
+ if (!normalized) {
7470
+ return 0;
7471
+ }
7472
+ if (/\bwork\s*orders?\b/.test(normalized)) {
7473
+ return 100;
7474
+ }
7475
+ if (/\borders?\b/.test(normalized)) {
7476
+ return 95;
7477
+ }
7478
+ if (/\b(total|count|rows?)\b/.test(normalized)) {
7479
+ return 90;
7480
+ }
7481
+ if (/\b(revenue|amount|price|cost|margin|balance)\b/.test(normalized)) {
7482
+ return 85;
7483
+ }
7484
+ if (/\b(hours?|volume|quantity|qty|deliveries|invoices)\b/.test(normalized)) {
7485
+ return 80;
7486
+ }
7487
+ if (/\b(active|completed|reviewed|closed|canceled|cancelled|inactive|open|pending)\b/.test(normalized)) {
7488
+ return 20;
7489
+ }
7490
+ return 50;
7491
+ }
7492
+ function buildAssistantDisplayLeadSummary(display) {
7493
+ var rows = Array.isArray(display === null || display === void 0 ? void 0 : display.rows) ? (display === null || display === void 0 ? void 0 : display.rows) || [] : [];
7494
+ var columns = Array.isArray(display === null || display === void 0 ? void 0 : display.columns) ? (display === null || display === void 0 ? void 0 : display.columns) || [] : [];
7495
+ var firstRow = rows[0];
7496
+ if (!firstRow || typeof firstRow !== 'object' || !columns.length) {
7497
+ return '';
7498
+ }
7499
+ var visibleColumns = columns
7500
+ .map(function (column) { return normalizeOptionalString(column); })
7501
+ .filter(Boolean)
7502
+ .filter(function (column) { return !shouldRedactField(column); });
7503
+ if (!visibleColumns.length) {
7504
+ return '';
7505
+ }
7506
+ var labelColumn = visibleColumns.find(function (column) {
7507
+ var value = firstRow[column];
7508
+ return typeof value === 'string' && !!normalizeOptionalString(value);
7509
+ }) || visibleColumns[0];
7510
+ var metricColumn = visibleColumns
7511
+ .filter(function (column) { return column !== labelColumn && isAssistantMetricDisplayColumn(column, firstRow[column]); })
7512
+ .sort(function (a, b) {
7513
+ var priorityDelta = getAssistantMetricDisplayColumnPriority(b) - getAssistantMetricDisplayColumnPriority(a);
7514
+ return priorityDelta || visibleColumns.indexOf(a) - visibleColumns.indexOf(b);
7515
+ })[0];
7516
+ var labelValue = formatAssistantDisplayValueForSentence(firstRow[labelColumn]);
7517
+ if (labelValue && metricColumn) {
7518
+ var metricValue = formatAssistantDisplayValueForSentence(firstRow[metricColumn]);
7519
+ if (metricValue) {
7520
+ return rows.length > 1
7521
+ ? "Top row: ".concat(labelColumn, " ").concat(labelValue, ", ").concat(metricColumn, " ").concat(metricValue, ".")
7522
+ : "Result: ".concat(labelColumn, " ").concat(labelValue, ", ").concat(metricColumn, " ").concat(metricValue, ".");
7523
+ }
7524
+ }
7525
+ var details = visibleColumns
7526
+ .slice(0, 4)
7527
+ .map(function (column) {
7528
+ var value = formatAssistantDisplayValueForSentence(firstRow[column]);
7529
+ return value ? "".concat(column, " ").concat(value) : '';
7530
+ })
7531
+ .filter(Boolean);
7532
+ if (!details.length) {
7533
+ return '';
7534
+ }
7535
+ return rows.length > 1
7536
+ ? "First row: ".concat(details.join(', '), ".")
7537
+ : "Result: ".concat(details.join(', '), ".");
7538
+ }
7370
7539
  function buildAssistantToolFallbackResponse(result) {
7371
7540
  var _a, _b;
7372
- var lines = ['Here is a data snapshot based on the tool result:'];
7373
- if (result.output.collection) {
7374
- lines.push("- Collection: ".concat(result.output.collection));
7375
- }
7376
- lines.push("- Rows returned: ".concat(result.output.rowCount));
7541
+ var rowCount = Math.max(0, Number(result.output.rowCount || 0));
7542
+ var source = normalizeOptionalString(result.output.collection);
7543
+ var lines = rowCount > 0
7544
+ ? ["I found ".concat(rowCount === 1 ? '1 matching row' : "".concat(rowCount, " matching rows")).concat(source ? " from ".concat(source) : '', ".")]
7545
+ : ["The query ran successfully".concat(source ? " against ".concat(source) : '', ", but no matching rows were returned.")];
7546
+ if (source) {
7547
+ lines.push("- Source: ".concat(source));
7548
+ }
7549
+ lines.push("- Rows returned: ".concat(rowCount));
7377
7550
  if (typeof result.output.total === 'number') {
7378
7551
  lines.push("- Total: ".concat(result.output.total));
7379
7552
  }
7553
+ var leadSummary = buildAssistantDisplayLeadSummary(result.output.display);
7554
+ if (leadSummary) {
7555
+ lines.push('');
7556
+ lines.push(leadSummary);
7557
+ }
7380
7558
  if ((_b = (_a = result.output.display) === null || _a === void 0 ? void 0 : _a.rows) === null || _b === void 0 ? void 0 : _b.length) {
7381
7559
  lines.push('');
7382
7560
  lines.push(formatDisplayTableMarkdown(result.output.display));
7383
7561
  }
7384
7562
  return lines.join('\n').trim();
7385
7563
  }
7564
+ function buildAssistantToolFallbackResponseForTesting(result) {
7565
+ return buildAssistantToolFallbackResponse(result);
7566
+ }
7386
7567
  function didAssistantRequestLotOrBatch(message) {
7387
7568
  var normalized = normalizeOptionalString(message).toLowerCase();
7388
7569
  if (!normalized) {
@@ -9914,30 +10095,7 @@ function applyAssistantDisplayColumnHints(value, display) {
9914
10095
  }
9915
10096
  return renameAssistantDisplayColumn(display, display.columns[0], labelHint);
9916
10097
  }
9917
- function resolveAssistantEmptyDisplayColumns(value) {
9918
- var labelHint = resolveAssistantDisplayTemporalLabelHint(value);
9919
- if (labelHint) {
9920
- if (labelHint === 'Customer') {
9921
- var requestedMonths = resolveAssistantRequestedMonthBucketsFromMessage(value);
9922
- if (requestedMonths.length >= 3) {
9923
- return __spreadArray([labelHint], __read(requestedMonths), false);
9924
- }
9925
- var looseMonthMatch = value.match(/\b(?:last|past|previous|over\s+the\s+last)\s+(\d+)\s+(?:full\s+calendar\s+|calendar\s+|full\s+)?months?\b/i);
9926
- var looseMonthCount = (looseMonthMatch === null || looseMonthMatch === void 0 ? void 0 : looseMonthMatch[1]) ? Number(looseMonthMatch[1]) : Number.NaN;
9927
- if (Number.isFinite(looseMonthCount) && looseMonthCount > 0) {
9928
- var inferred = buildAssistantExpectedMonthBuckets((0, common_1.round)(looseMonthCount), 'full_month');
9929
- if (inferred.length >= 3) {
9930
- return __spreadArray([labelHint], __read(inferred), false);
9931
- }
9932
- }
9933
- return [labelHint, 'Details'];
9934
- }
9935
- return [labelHint, 'Total Revenue'];
9936
- }
9937
- return ['Result', 'Details'];
9938
- }
9939
10098
  function applyAssistantDisplayTableToResponse(value, display) {
9940
- var _a;
9941
10099
  if (!display || !Array.isArray(display.rows)) {
9942
10100
  return value;
9943
10101
  }
@@ -9947,39 +10105,14 @@ function applyAssistantDisplayTableToResponse(value, display) {
9947
10105
  var rowCount = typeof normalizedDisplay.rowCount === 'number' && normalizedDisplay.rowCount > 0
9948
10106
  ? normalizedDisplay.rowCount
9949
10107
  : 0;
9950
- var fallbackColumns = Array.isArray(normalizedDisplay.columns) && normalizedDisplay.columns.length
9951
- ? normalizedDisplay.columns
9952
- : resolveAssistantEmptyDisplayColumns(cleaned_1 || value);
9953
- var normalizedColumns = fallbackColumns.length === 1
9954
- ? __spreadArray(__spreadArray([], __read(fallbackColumns), false), ['Value'], false) : fallbackColumns;
9955
- var rowSummary = [(_a = {},
9956
- _a[normalizedColumns[0]] = rowCount > 0 ? 'Rows matched' : 'No rows matched',
9957
- _a[normalizedColumns[1]] = rowCount,
9958
- _a)];
9959
- var tableDisplay = {
9960
- columns: normalizedColumns,
9961
- rows: rowSummary,
9962
- rowCount: rowCount,
9963
- truncated: false,
9964
- includeIds: false
9965
- };
9966
- var emptyTable = formatDisplayTableMarkdown(tableDisplay);
9967
- if (!emptyTable) {
9968
- return cleaned_1 || value;
9969
- }
9970
10108
  var noRowsNote = rowCount > 0 ? '' : 'No rows matched your request.';
10109
+ var alreadyExplainsNoRows = /\bno (?:matching )?rows?(?: matched| were returned)?\b/i.test(cleaned_1);
9971
10110
  var base = cleaned_1
9972
- ? (noRowsNote && !/\bno rows? matched\b/i.test(cleaned_1)
10111
+ ? (noRowsNote && !alreadyExplainsNoRows
9973
10112
  ? "".concat(cleaned_1.trim(), "\n\n").concat(noRowsNote).trim()
9974
10113
  : cleaned_1.trim())
9975
10114
  : noRowsNote;
9976
- if (!cleaned_1) {
9977
- if (!base) {
9978
- return emptyTable;
9979
- }
9980
- return "".concat(base, "\n\n").concat(emptyTable).trim();
9981
- }
9982
- return "".concat(base, "\n\n").concat(emptyTable).trim();
10115
+ return base || value;
9983
10116
  }
9984
10117
  var table = formatDisplayTableMarkdown(normalizedDisplay);
9985
10118
  if (!table) {
@@ -9991,6 +10124,9 @@ function applyAssistantDisplayTableToResponse(value, display) {
9991
10124
  }
9992
10125
  return "".concat(cleaned.trim(), "\n\n").concat(table).trim();
9993
10126
  }
10127
+ function applyAssistantDisplayTableToResponseForTesting(value, display) {
10128
+ return applyAssistantDisplayTableToResponse(value, display);
10129
+ }
9994
10130
  function escapeMarkdownCell(value) {
9995
10131
  var raw = value === null || value === undefined ? '' : String(value);
9996
10132
  return raw.replace(/\|/g, '\\|').replace(/\r?\n/g, ' ').trim();
@@ -14558,6 +14694,27 @@ function listAssistantReportBuilderCollectionsFromManager() {
14558
14694
  });
14559
14695
  return names;
14560
14696
  }
14697
+ function listAssistantConfiguredCollectionsFromManager() {
14698
+ var _a;
14699
+ var manager = (_a = resolveio_server_app_1.ResolveIOServer.getMongoManager) === null || _a === void 0 ? void 0 : _a.call(resolveio_server_app_1.ResolveIOServer);
14700
+ var collectionModels = manager && typeof manager.collections === 'function'
14701
+ ? manager.collections()
14702
+ : [];
14703
+ if (!Array.isArray(collectionModels) || !collectionModels.length) {
14704
+ return [];
14705
+ }
14706
+ var seen = new Set();
14707
+ var names = [];
14708
+ collectionModels.forEach(function (model) {
14709
+ var name = normalizeOptionalString(model === null || model === void 0 ? void 0 : model.collectionName);
14710
+ if (!name || seen.has(name)) {
14711
+ return;
14712
+ }
14713
+ seen.add(name);
14714
+ names.push(name);
14715
+ });
14716
+ return names;
14717
+ }
14561
14718
  function resolveAssistantSurfaceFileCandidates(baseName) {
14562
14719
  var fileNames = ["".concat(baseName, ".ts"), "".concat(baseName, ".js")];
14563
14720
  var roots = [
@@ -14788,15 +14945,21 @@ function resolveAssistantSurfaceHints(message, contextRoute, collectionNames) {
14788
14945
  }
14789
14946
  function listAssistantCollections(db, dbName) {
14790
14947
  return __awaiter(this, void 0, void 0, function () {
14791
- var cacheKey, cached, now, seen, merged, pushName, collections, _a, names;
14948
+ var cacheKey, cached, now, managerCollectionNames, mergedCachedNames, seen, merged, pushName, collections, _a, names;
14792
14949
  return __generator(this, function (_b) {
14793
14950
  switch (_b.label) {
14794
14951
  case 0:
14795
14952
  cacheKey = normalizeOptionalString(dbName) || 'default';
14796
14953
  cached = AI_ASSISTANT_COLLECTION_CACHE.get(cacheKey);
14797
14954
  now = Date.now();
14955
+ managerCollectionNames = mergeAssistantHintValues(listAssistantConfiguredCollectionsFromManager(), listAssistantReportBuilderCollectionsFromManager());
14798
14956
  if (cached && now - cached.updatedAt < AI_ASSISTANT_COLLECTION_CACHE_TTL_MS) {
14799
- return [2 /*return*/, cached.names];
14957
+ mergedCachedNames = mergeAssistantHintValues(managerCollectionNames, cached.names)
14958
+ .sort(function (a, b) { return a.localeCompare(b); });
14959
+ if (mergedCachedNames.length !== cached.names.length) {
14960
+ AI_ASSISTANT_COLLECTION_CACHE.set(cacheKey, { names: mergedCachedNames, updatedAt: now });
14961
+ }
14962
+ return [2 /*return*/, mergedCachedNames];
14800
14963
  }
14801
14964
  seen = new Set();
14802
14965
  merged = [];
@@ -14808,7 +14971,7 @@ function listAssistantCollections(db, dbName) {
14808
14971
  seen.add(normalized);
14809
14972
  merged.push(normalized);
14810
14973
  };
14811
- listAssistantReportBuilderCollectionsFromManager().forEach(pushName);
14974
+ managerCollectionNames.forEach(pushName);
14812
14975
  _b.label = 1;
14813
14976
  case 1:
14814
14977
  _b.trys.push([1, 3, , 4]);
@@ -15703,20 +15866,13 @@ function resolveCollectionOverrideWithContext(params) {
15703
15866
  var requested = normalizeOptionalString(params.requestedCollection);
15704
15867
  var allowVersions = shouldAllowVersionCollections(params.message);
15705
15868
  var collectionNames = Array.isArray(params.collectionNames) ? params.collectionNames : [];
15869
+ var collectionHints = Array.isArray(params.collectionHints)
15870
+ ? params.collectionHints.map(function (value) { return normalizeOptionalString(value); }).filter(Boolean)
15871
+ : [];
15706
15872
  var permissionView = normalizeOptionalString(params.permissionView);
15707
15873
  var routeHintCollections = permissionView
15708
15874
  ? resolveCollectionHintsFromRoute(permissionView, collectionNames)
15709
15875
  : [];
15710
- var isCollectionInHintFamilies = function (collection, hintCollections) {
15711
- var candidateFamily = normalizeAssistantCollectionFamilyName(collection);
15712
- if (!candidateFamily) {
15713
- return false;
15714
- }
15715
- return (hintCollections || []).some(function (hintCollection) {
15716
- var hintFamily = normalizeAssistantCollectionFamilyName(hintCollection);
15717
- return !!(hintFamily && hintFamily === candidateFamily);
15718
- });
15719
- };
15720
15876
  if (permissionView) {
15721
15877
  var reportPreferred = resolveReportCollectionName(permissionView, collectionNames, requested);
15722
15878
  if (reportPreferred && reportPreferred !== requested) {
@@ -15728,6 +15884,24 @@ function resolveCollectionOverrideWithContext(params) {
15728
15884
  reason: 'report builder route preference'
15729
15885
  };
15730
15886
  }
15887
+ var routePreferred = routeHintCollections.find(function (collection) {
15888
+ return collectionNames.includes(collection) && !isVersionCollectionName(collection);
15889
+ });
15890
+ if (routePreferred
15891
+ && requested
15892
+ && !isAssistantCollectionInHintFamilies(requested, [routePreferred])) {
15893
+ var routePreferredName = normalizeAssistantCollectionOverrideName(routePreferred);
15894
+ var requestedIsWorkOrder = isAssistantWorkOrderCollectionOverrideCandidate(requested);
15895
+ if (!(routePreferredName === 'orders' && requestedIsWorkOrder && hasAssistantWorkOrderAliasTerms(params.message))) {
15896
+ return {
15897
+ from: requested,
15898
+ to: routePreferred,
15899
+ fromScore: 0,
15900
+ toScore: 0,
15901
+ reason: 'permission route collection match'
15902
+ };
15903
+ }
15904
+ }
15731
15905
  }
15732
15906
  if (!allowVersions && isVersionCollectionName(requested)) {
15733
15907
  var base = stripVersionSuffix(requested);
@@ -15741,10 +15915,55 @@ function resolveCollectionOverrideWithContext(params) {
15741
15915
  };
15742
15916
  }
15743
15917
  }
15918
+ var primaryCollectionHint = collectionHints[0] || '';
15919
+ var requestedMatchesPermissionRoute = !!(requested
15920
+ && permissionView
15921
+ && (isAssistantCollectionInHintFamilies(requested, routeHintCollections)
15922
+ || doesAssistantPermissionRouteMatchCollection(permissionView, requested)));
15923
+ var primaryHintMatchesPermissionRoute = !!(primaryCollectionHint
15924
+ && permissionView
15925
+ && (isAssistantCollectionInHintFamilies(primaryCollectionHint, routeHintCollections)
15926
+ || doesAssistantPermissionRouteMatchCollection(permissionView, primaryCollectionHint)));
15927
+ if (requestedMatchesPermissionRoute && !primaryHintMatchesPermissionRoute) {
15928
+ return null;
15929
+ }
15930
+ var requestedHintIndex = requested
15931
+ ? collectionHints.findIndex(function (collection) { return isAssistantCollectionInHintFamilies(requested, [collection]); })
15932
+ : -1;
15933
+ if (requestedHintIndex > 0
15934
+ && primaryCollectionHint
15935
+ && !primaryHintMatchesPermissionRoute) {
15936
+ var requestedScore = resolveAssistantCollectionScore(params.collectionRanking, requested);
15937
+ var primaryScore = resolveAssistantCollectionScore(params.collectionRanking, primaryCollectionHint);
15938
+ var scoreGap = primaryScore - requestedScore;
15939
+ if (requestedScore >= AI_ASSISTANT_COLLECTION_OVERRIDE_MIN_SCORE
15940
+ && primaryScore >= AI_ASSISTANT_COLLECTION_OVERRIDE_MIN_SCORE
15941
+ && scoreGap <= AI_ASSISTANT_COLLECTION_OVERRIDE_SCORE_GAP) {
15942
+ return null;
15943
+ }
15944
+ }
15945
+ if (primaryCollectionHint
15946
+ && requested
15947
+ && !isAssistantCollectionInHintFamilies(requested, [primaryCollectionHint])
15948
+ && (isAssistantCollectionInHintFamilies(requested, collectionHints.slice(1))
15949
+ || routeHintCollections.length > 0)) {
15950
+ return {
15951
+ from: requested,
15952
+ to: primaryCollectionHint,
15953
+ fromScore: 0,
15954
+ toScore: 0,
15955
+ reason: 'ordered collection hint preference'
15956
+ };
15957
+ }
15958
+ if (primaryCollectionHint
15959
+ && requested
15960
+ && isAssistantCollectionInHintFamilies(requested, [primaryCollectionHint])) {
15961
+ return null;
15962
+ }
15744
15963
  var rankingOverride = resolveAssistantCollectionOverride(params.collectionRanking, requested);
15745
15964
  if (rankingOverride) {
15746
- var requestedMatchesRouteHints = isCollectionInHintFamilies(requested, routeHintCollections);
15747
- var overrideMatchesRouteHints = isCollectionInHintFamilies(rankingOverride.to, routeHintCollections);
15965
+ var requestedMatchesRouteHints = isAssistantCollectionInHintFamilies(requested, routeHintCollections);
15966
+ var overrideMatchesRouteHints = isAssistantCollectionInHintFamilies(rankingOverride.to, routeHintCollections);
15748
15967
  if (requestedMatchesRouteHints && !overrideMatchesRouteHints) {
15749
15968
  return null;
15750
15969
  }
@@ -15946,6 +16165,13 @@ function resolveAssistantCollectionName(db, dbName, requested, appId) {
15946
16165
  });
15947
16166
  });
15948
16167
  }
16168
+ function resolveAssistantCollectionNameForTesting(db, dbName, requested, appId) {
16169
+ return __awaiter(this, void 0, void 0, function () {
16170
+ return __generator(this, function (_a) {
16171
+ return [2 /*return*/, resolveAssistantCollectionName(db, dbName, requested, appId)];
16172
+ });
16173
+ });
16174
+ }
15949
16175
  var AI_ASSISTANT_BRIDGE_COLLECTION_ALIASES = {};
15950
16176
  var AI_ASSISTANT_BRIDGE_COLLECTION_ALIAS_OPTIONS = {};
15951
16177
  var AI_ASSISTANT_DIRECT_COLLECTION_FALLBACK_ALLOWLIST = new Set([
@@ -15960,6 +16186,44 @@ function normalizeAssistantCollectionFamilyName(value) {
15960
16186
  var withoutReport = normalized.startsWith('report-') ? normalized.slice('report-'.length) : normalized;
15961
16187
  return stripVersionSuffix(withoutReport);
15962
16188
  }
16189
+ function isAssistantCollectionInHintFamilies(collection, hintCollections) {
16190
+ var candidateFamily = normalizeAssistantCollectionFamilyName(collection);
16191
+ if (!candidateFamily) {
16192
+ return false;
16193
+ }
16194
+ return (hintCollections || []).some(function (hintCollection) {
16195
+ var hintFamily = normalizeAssistantCollectionFamilyName(hintCollection);
16196
+ return !!(hintFamily && hintFamily === candidateFamily);
16197
+ });
16198
+ }
16199
+ function shouldPreserveAssistantPrimaryHintCollection(requestedCollection, resolvedCollection, requestHints) {
16200
+ var _a;
16201
+ var requested = normalizeOptionalString(requestedCollection);
16202
+ var resolved = normalizeOptionalString(resolvedCollection);
16203
+ if (!requested || !resolved || requested === resolved || AI_ASSISTANT_BLOCKED_COLLECTIONS.has(requested)) {
16204
+ return false;
16205
+ }
16206
+ var primaryCollectionHint = normalizeOptionalString((_a = requestHints === null || requestHints === void 0 ? void 0 : requestHints.collectionHints) === null || _a === void 0 ? void 0 : _a[0]);
16207
+ return !!(primaryCollectionHint
16208
+ && isAssistantCollectionInHintFamilies(requested, [primaryCollectionHint]));
16209
+ }
16210
+ function shouldLockAssistantRequestedCollectionForExecution(requestedCollection, permissionView, requestHints) {
16211
+ var _a;
16212
+ var requested = normalizeOptionalString(requestedCollection);
16213
+ if (!requested || AI_ASSISTANT_BLOCKED_COLLECTIONS.has(requested)) {
16214
+ return false;
16215
+ }
16216
+ var primaryCollectionHint = normalizeOptionalString((_a = requestHints === null || requestHints === void 0 ? void 0 : requestHints.collectionHints) === null || _a === void 0 ? void 0 : _a[0]);
16217
+ if (primaryCollectionHint && isAssistantCollectionInHintFamilies(requested, [primaryCollectionHint])) {
16218
+ return true;
16219
+ }
16220
+ var normalizedPermissionView = normalizeOptionalString(permissionView);
16221
+ return !!(normalizedPermissionView
16222
+ && doesAssistantPermissionRouteMatchCollection(normalizedPermissionView, requested));
16223
+ }
16224
+ function shouldLockAssistantRequestedCollectionForExecutionForTesting(requestedCollection, permissionView, requestHints) {
16225
+ return shouldLockAssistantRequestedCollectionForExecution(requestedCollection, permissionView, normalizeAssistantDirectiveHints(requestHints));
16226
+ }
15963
16227
  function addAssistantCollectionToTriedSet(tried, collection) {
15964
16228
  var normalized = normalizeOptionalString(collection);
15965
16229
  if (normalized) {
@@ -16810,12 +17074,12 @@ function resolveAssistantBridgeCollectionHintCandidates(requestedCollection, req
16810
17074
  }
16811
17075
  function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
16812
17076
  return __awaiter(this, arguments, void 0, function (collection, db, dbName, options) {
16813
- var normalized, resolutionPath, pushResolutionStep, finalizeResolution, requestHints, appId, requestedTokens, requestedTokenWeights, aliasCandidates, hintCandidates, alias, manager, hasManager, candidates, pushCandidate, base, reportCandidate, candidates_5, candidates_5_1, candidate, model, resolverTargets, resolverErrorLogged, resolverTargets_1, resolverTargets_1_1, resolverTarget, resolved, resolvedName, resolvedScore, resolvedModel, _a, e_34_1, candidates_6, candidates_6_1, candidate, e_35_1, candidates_7, candidates_7_1, candidate;
16814
- var e_36, _b, e_34, _c, e_35, _d, e_37, _e;
16815
- var _f;
17077
+ 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_34_1, candidates_7, candidates_7_1, candidate, e_35_1, candidates_8, candidates_8_1, candidate;
17078
+ var e_36, _b, e_37, _c, e_34, _d, e_35, _e, e_38, _f;
17079
+ var _g, _h;
16816
17080
  if (dbName === void 0) { dbName = ''; }
16817
- return __generator(this, function (_g) {
16818
- switch (_g.label) {
17081
+ return __generator(this, function (_j) {
17082
+ switch (_j.label) {
16819
17083
  case 0:
16820
17084
  normalized = normalizeOptionalString(collection);
16821
17085
  if (!normalized) {
@@ -16849,8 +17113,13 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
16849
17113
  pushResolutionStep("hints:".concat(hintCandidates.slice(0, 6).join(',')));
16850
17114
  }
16851
17115
  alias = aliasCandidates[0] || '';
16852
- manager = (_f = resolveio_server_app_1.ResolveIOServer.getMongoManager) === null || _f === void 0 ? void 0 : _f.call(resolveio_server_app_1.ResolveIOServer);
17116
+ manager = (_g = resolveio_server_app_1.ResolveIOServer.getMongoManager) === null || _g === void 0 ? void 0 : _g.call(resolveio_server_app_1.ResolveIOServer);
16853
17117
  hasManager = !!(manager && typeof manager.collection === 'function');
17118
+ configuredCollectionNames = listAssistantConfiguredCollectionsFromManager();
17119
+ isConfiguredCollection = function (name) {
17120
+ var value = normalizeOptionalString(name);
17121
+ return !!value && configuredCollectionNames.includes(value);
17122
+ };
16854
17123
  candidates = [];
16855
17124
  pushCandidate = function (name) {
16856
17125
  var value = normalizeOptionalString(name);
@@ -16888,23 +17157,49 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
16888
17157
  finally { if (e_36) throw e_36.error; }
16889
17158
  }
16890
17159
  }
17160
+ if (configuredCollectionNames.length) {
17161
+ try {
17162
+ for (candidates_6 = __values(candidates), candidates_6_1 = candidates_6.next(); !candidates_6_1.done; candidates_6_1 = candidates_6.next()) {
17163
+ candidate = candidates_6_1.value;
17164
+ if (AI_ASSISTANT_BLOCKED_COLLECTIONS.has(candidate)) {
17165
+ continue;
17166
+ }
17167
+ if (isConfiguredCollection(candidate)) {
17168
+ return [2 /*return*/, finalizeResolution(candidate, 'direct-mongo', "manager.configured:".concat(candidate))];
17169
+ }
17170
+ }
17171
+ }
17172
+ catch (e_37_1) { e_37 = { error: e_37_1 }; }
17173
+ finally {
17174
+ try {
17175
+ if (candidates_6_1 && !candidates_6_1.done && (_c = candidates_6.return)) _c.call(candidates_6);
17176
+ }
17177
+ finally { if (e_37) throw e_37.error; }
17178
+ }
17179
+ }
17180
+ primaryCollectionHint = normalizeOptionalString((_h = requestHints === null || requestHints === void 0 ? void 0 : requestHints.collectionHints) === null || _h === void 0 ? void 0 : _h[0]);
17181
+ if (primaryCollectionHint
17182
+ && !AI_ASSISTANT_BLOCKED_COLLECTIONS.has(normalized)
17183
+ && isAssistantCollectionInHintFamilies(normalized, [primaryCollectionHint])) {
17184
+ return [2 /*return*/, finalizeResolution(normalized, 'direct-mongo', "hints.primary:".concat(primaryCollectionHint))];
17185
+ }
16891
17186
  if (!(db && dbName)) return [3 /*break*/, 10];
16892
17187
  resolverTargets = mergeAssistantHintValues(alias ? [alias] : [], [normalized], hintCandidates).slice(0, 10);
16893
17188
  resolverErrorLogged = false;
16894
- _g.label = 1;
17189
+ _j.label = 1;
16895
17190
  case 1:
16896
- _g.trys.push([1, 8, 9, 10]);
17191
+ _j.trys.push([1, 8, 9, 10]);
16897
17192
  resolverTargets_1 = __values(resolverTargets), resolverTargets_1_1 = resolverTargets_1.next();
16898
- _g.label = 2;
17193
+ _j.label = 2;
16899
17194
  case 2:
16900
17195
  if (!!resolverTargets_1_1.done) return [3 /*break*/, 7];
16901
17196
  resolverTarget = resolverTargets_1_1.value;
16902
- _g.label = 3;
17197
+ _j.label = 3;
16903
17198
  case 3:
16904
- _g.trys.push([3, 5, , 6]);
17199
+ _j.trys.push([3, 5, , 6]);
16905
17200
  return [4 /*yield*/, resolveAssistantCollectionName(db, dbName, resolverTarget, appId)];
16906
17201
  case 4:
16907
- resolved = _g.sent();
17202
+ resolved = _j.sent();
16908
17203
  resolvedName = normalizeOptionalString(resolved === null || resolved === void 0 ? void 0 : resolved.name);
16909
17204
  if (!resolvedName) {
16910
17205
  return [3 /*break*/, 6];
@@ -16929,7 +17224,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
16929
17224
  }
16930
17225
  return [3 /*break*/, 6];
16931
17226
  case 5:
16932
- _a = _g.sent();
17227
+ _a = _j.sent();
16933
17228
  if (!resolverErrorLogged) {
16934
17229
  pushResolutionStep('resolver:error');
16935
17230
  resolverErrorLogged = true;
@@ -16940,63 +17235,63 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
16940
17235
  return [3 /*break*/, 2];
16941
17236
  case 7: return [3 /*break*/, 10];
16942
17237
  case 8:
16943
- e_34_1 = _g.sent();
17238
+ e_34_1 = _j.sent();
16944
17239
  e_34 = { error: e_34_1 };
16945
17240
  return [3 /*break*/, 10];
16946
17241
  case 9:
16947
17242
  try {
16948
- if (resolverTargets_1_1 && !resolverTargets_1_1.done && (_c = resolverTargets_1.return)) _c.call(resolverTargets_1);
17243
+ if (resolverTargets_1_1 && !resolverTargets_1_1.done && (_d = resolverTargets_1.return)) _d.call(resolverTargets_1);
16949
17244
  }
16950
17245
  finally { if (e_34) throw e_34.error; }
16951
17246
  return [7 /*endfinally*/];
16952
17247
  case 10:
16953
17248
  if (!db) return [3 /*break*/, 18];
16954
- _g.label = 11;
17249
+ _j.label = 11;
16955
17250
  case 11:
16956
- _g.trys.push([11, 16, 17, 18]);
16957
- candidates_6 = __values(candidates), candidates_6_1 = candidates_6.next();
16958
- _g.label = 12;
17251
+ _j.trys.push([11, 16, 17, 18]);
17252
+ candidates_7 = __values(candidates), candidates_7_1 = candidates_7.next();
17253
+ _j.label = 12;
16959
17254
  case 12:
16960
- if (!!candidates_6_1.done) return [3 /*break*/, 15];
16961
- candidate = candidates_6_1.value;
17255
+ if (!!candidates_7_1.done) return [3 /*break*/, 15];
17256
+ candidate = candidates_7_1.value;
16962
17257
  if (AI_ASSISTANT_BLOCKED_COLLECTIONS.has(candidate)) {
16963
17258
  return [3 /*break*/, 14];
16964
17259
  }
16965
17260
  return [4 /*yield*/, doesAssistantCollectionExistInDb(db, candidate)];
16966
17261
  case 13:
16967
- if (_g.sent()) {
17262
+ if (_j.sent()) {
16968
17263
  return [2 /*return*/, finalizeResolution(candidate, 'direct-mongo', "db.exists:".concat(candidate))];
16969
17264
  }
16970
- _g.label = 14;
17265
+ _j.label = 14;
16971
17266
  case 14:
16972
- candidates_6_1 = candidates_6.next();
17267
+ candidates_7_1 = candidates_7.next();
16973
17268
  return [3 /*break*/, 12];
16974
17269
  case 15: return [3 /*break*/, 18];
16975
17270
  case 16:
16976
- e_35_1 = _g.sent();
17271
+ e_35_1 = _j.sent();
16977
17272
  e_35 = { error: e_35_1 };
16978
17273
  return [3 /*break*/, 18];
16979
17274
  case 17:
16980
17275
  try {
16981
- if (candidates_6_1 && !candidates_6_1.done && (_d = candidates_6.return)) _d.call(candidates_6);
17276
+ if (candidates_7_1 && !candidates_7_1.done && (_e = candidates_7.return)) _e.call(candidates_7);
16982
17277
  }
16983
17278
  finally { if (e_35) throw e_35.error; }
16984
17279
  return [7 /*endfinally*/];
16985
17280
  case 18:
16986
17281
  try {
16987
- for (candidates_7 = __values(candidates), candidates_7_1 = candidates_7.next(); !candidates_7_1.done; candidates_7_1 = candidates_7.next()) {
16988
- candidate = candidates_7_1.value;
17282
+ for (candidates_8 = __values(candidates), candidates_8_1 = candidates_8.next(); !candidates_8_1.done; candidates_8_1 = candidates_8.next()) {
17283
+ candidate = candidates_8_1.value;
16989
17284
  if (isAssistantDirectCollectionFallbackAllowed(candidate)) {
16990
17285
  return [2 /*return*/, finalizeResolution(candidate, 'direct-mongo', "allowlist:".concat(candidate))];
16991
17286
  }
16992
17287
  }
16993
17288
  }
16994
- catch (e_37_1) { e_37 = { error: e_37_1 }; }
17289
+ catch (e_38_1) { e_38 = { error: e_38_1 }; }
16995
17290
  finally {
16996
17291
  try {
16997
- if (candidates_7_1 && !candidates_7_1.done && (_e = candidates_7.return)) _e.call(candidates_7);
17292
+ if (candidates_8_1 && !candidates_8_1.done && (_f = candidates_8.return)) _f.call(candidates_8);
16998
17293
  }
16999
- finally { if (e_37) throw e_37.error; }
17294
+ finally { if (e_38) throw e_38.error; }
17000
17295
  }
17001
17296
  throw new Error('AI assistant report builder bridge: No queryable collection could be resolved.');
17002
17297
  }
@@ -17004,7 +17299,7 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
17004
17299
  });
17005
17300
  }
17006
17301
  function findQueryDateField(query) {
17007
- var e_38, _a, e_39, _b;
17302
+ var e_39, _a, e_40, _b;
17008
17303
  if (!query || typeof query !== 'object') {
17009
17304
  return null;
17010
17305
  }
@@ -17018,12 +17313,12 @@ function findQueryDateField(query) {
17018
17313
  }
17019
17314
  }
17020
17315
  }
17021
- catch (e_38_1) { e_38 = { error: e_38_1 }; }
17316
+ catch (e_39_1) { e_39 = { error: e_39_1 }; }
17022
17317
  finally {
17023
17318
  try {
17024
17319
  if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
17025
17320
  }
17026
- finally { if (e_38) throw e_38.error; }
17321
+ finally { if (e_39) throw e_39.error; }
17027
17322
  }
17028
17323
  return null;
17029
17324
  }
@@ -17042,12 +17337,12 @@ function findQueryDateField(query) {
17042
17337
  }
17043
17338
  }
17044
17339
  }
17045
- catch (e_39_1) { e_39 = { error: e_39_1 }; }
17340
+ catch (e_40_1) { e_40 = { error: e_40_1 }; }
17046
17341
  finally {
17047
17342
  try {
17048
17343
  if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
17049
17344
  }
17050
- finally { if (e_39) throw e_39.error; }
17345
+ finally { if (e_40) throw e_40.error; }
17051
17346
  }
17052
17347
  return null;
17053
17348
  }
@@ -17335,7 +17630,7 @@ function resolveQueryDateFieldFallback(query) {
17335
17630
  return { from: dateField, to: fallback };
17336
17631
  }
17337
17632
  function containsForbiddenMongoOperators(value) {
17338
- var e_40, _a;
17633
+ var e_41, _a;
17339
17634
  if (!value || typeof value !== 'object') {
17340
17635
  return false;
17341
17636
  }
@@ -17354,12 +17649,12 @@ function containsForbiddenMongoOperators(value) {
17354
17649
  }
17355
17650
  }
17356
17651
  }
17357
- catch (e_40_1) { e_40 = { error: e_40_1 }; }
17652
+ catch (e_41_1) { e_41 = { error: e_41_1 }; }
17358
17653
  finally {
17359
17654
  try {
17360
17655
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
17361
17656
  }
17362
- finally { if (e_40) throw e_40.error; }
17657
+ finally { if (e_41) throw e_41.error; }
17363
17658
  }
17364
17659
  return false;
17365
17660
  }
@@ -17544,7 +17839,7 @@ function splitAssistantPermissionTokenSets(value) {
17544
17839
  };
17545
17840
  }
17546
17841
  function isAssistantTokenSetSubset(subset, superset) {
17547
- var e_41, _a;
17842
+ var e_42, _a;
17548
17843
  if (!subset.size) {
17549
17844
  return false;
17550
17845
  }
@@ -17556,12 +17851,12 @@ function isAssistantTokenSetSubset(subset, superset) {
17556
17851
  }
17557
17852
  }
17558
17853
  }
17559
- catch (e_41_1) { e_41 = { error: e_41_1 }; }
17854
+ catch (e_42_1) { e_42 = { error: e_42_1 }; }
17560
17855
  finally {
17561
17856
  try {
17562
17857
  if (subset_1_1 && !subset_1_1.done && (_a = subset_1.return)) _a.call(subset_1);
17563
17858
  }
17564
- finally { if (e_41) throw e_41.error; }
17859
+ finally { if (e_42) throw e_42.error; }
17565
17860
  }
17566
17861
  return true;
17567
17862
  }
@@ -17945,7 +18240,7 @@ function normalizeCodexThoughtLevel(value) {
17945
18240
  function resolveConfiguredCodexAutoThoughtLevel(kind) {
17946
18241
  var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
17947
18242
  var levelKey = kind === 'simple' ? 'SIMPLE' : 'COMPLEX';
17948
- var fallbackLevel = kind === 'simple' ? 'medium' : 'high';
18243
+ var fallbackLevel = kind === 'simple' ? 'low' : 'high';
17949
18244
  var configured = normalizeCodexThoughtLevel(config["AI_ASSISTANT_CODEX_".concat(levelKey, "_THOUGHT_LEVEL")]
17950
18245
  || process.env["AI_ASSISTANT_CODEX_".concat(levelKey, "_THOUGHT_LEVEL")]
17951
18246
  || config["AI_TERMINAL_CODEX_".concat(levelKey, "_THOUGHT_LEVEL")]
@@ -17966,7 +18261,12 @@ function resolveCodexThoughtLevel(params) {
17966
18261
  var explicitLevel = normalizeCodexThoughtLevel(normalized);
17967
18262
  var isBugIssueRequest = (params === null || params === void 0 ? void 0 : params.requestType) === 'bug_issue';
17968
18263
  if (!isBugIssueRequest) {
17969
- return 'medium';
18264
+ if (explicitLevel) {
18265
+ return explicitLevel === 'high' || explicitLevel === 'xhigh'
18266
+ ? 'medium'
18267
+ : explicitLevel;
18268
+ }
18269
+ return resolveConfiguredCodexAutoThoughtLevel('simple');
17970
18270
  }
17971
18271
  if (explicitLevel) {
17972
18272
  return explicitLevel;
@@ -17986,6 +18286,18 @@ function resolveCodexSettings(options) {
17986
18286
  var fallbackModels = resolveCodexFallbackModels({ fallbackModels: options === null || options === void 0 ? void 0 : options.fallbackModels }, model);
17987
18287
  return __assign(__assign(__assign({ apiKey: apiKey, baseUrl: (serverConfig['OPENAI_BASE_URL'] || process.env.OPENAI_BASE_URL || '').trim() || undefined }, (model ? { model: model } : {})), (fallbackModels.length ? { fallbackModel: fallbackModels[0], fallbackModels: fallbackModels } : {})), { maxRetries: normalizeOptionalNumber(serverConfig['OPENAI_MAX_RETRIES'] || process.env.OPENAI_MAX_RETRIES), retryDelayMs: normalizeOptionalNumber(serverConfig['OPENAI_RETRY_DELAY_MS'] || process.env.OPENAI_RETRY_DELAY_MS) });
17988
18288
  }
18289
+ function resolveAssistantFollowupCodexEnabled(config) {
18290
+ var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
18291
+ var raw = normalizeOptionalBoolean((config === null || config === void 0 ? void 0 : config.followup_enabled)
18292
+ || (config === null || config === void 0 ? void 0 : config.followupEnabled)
18293
+ || serverConfig['AI_ASSISTANT_CODEX_FOLLOWUP_ENABLED']
18294
+ || process.env.AI_ASSISTANT_CODEX_FOLLOWUP_ENABLED
18295
+ || serverConfig['AI_TERMINAL_CODEX_FOLLOWUP_ENABLED']
18296
+ || process.env.AI_TERMINAL_CODEX_FOLLOWUP_ENABLED
18297
+ || serverConfig['AI_DASHBOARD_CODEX_FOLLOWUP_ENABLED']
18298
+ || process.env.AI_DASHBOARD_CODEX_FOLLOWUP_ENABLED);
18299
+ return raw === true;
18300
+ }
17989
18301
  function buildAssistantCodexClientCacheKey(config) {
17990
18302
  var _a, _b;
17991
18303
  return JSON.stringify({
@@ -18046,8 +18358,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
18046
18358
  }
18047
18359
  function waitForCodexWorkerMessage(worker, streamStatusHandler) {
18048
18360
  return __awaiter(this, void 0, void 0, function () {
18049
- var _a, _b, _c, _d, message, payload, status_1, e_42_1;
18050
- var _e, e_42, _f, _g;
18361
+ var _a, _b, _c, _d, message, payload, status_1, e_43_1;
18362
+ var _e, e_43, _f, _g;
18051
18363
  return __generator(this, function (_h) {
18052
18364
  switch (_h.label) {
18053
18365
  case 0:
@@ -18074,8 +18386,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
18074
18386
  return [3 /*break*/, 1];
18075
18387
  case 4: return [3 /*break*/, 11];
18076
18388
  case 5:
18077
- e_42_1 = _h.sent();
18078
- e_42 = { error: e_42_1 };
18389
+ e_43_1 = _h.sent();
18390
+ e_43 = { error: e_43_1 };
18079
18391
  return [3 /*break*/, 11];
18080
18392
  case 6:
18081
18393
  _h.trys.push([6, , 9, 10]);
@@ -18086,7 +18398,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
18086
18398
  _h.label = 8;
18087
18399
  case 8: return [3 /*break*/, 10];
18088
18400
  case 9:
18089
- if (e_42) throw e_42.error;
18401
+ if (e_43) throw e_43.error;
18090
18402
  return [7 /*endfinally*/];
18091
18403
  case 10: return [7 /*endfinally*/];
18092
18404
  case 11: throw new CodexWorkerBootstrapError('AI worker exited before completing.');
@@ -18430,8 +18742,8 @@ function buildAssistantWorkspaceRootCandidates(params) {
18430
18742
  }
18431
18743
  function resolveAssistantWorkspaceRoot() {
18432
18744
  return __awaiter(this, void 0, void 0, function () {
18433
- var candidates, firstExisting, firstNestedGitRoot, candidates_8, candidates_8_1, candidate, _a, gitRoot, nestedGitRoots, e_43_1;
18434
- var e_43, _b;
18745
+ var candidates, firstExisting, firstNestedGitRoot, candidates_9, candidates_9_1, candidate, _a, gitRoot, nestedGitRoots, e_44_1;
18746
+ var e_44, _b;
18435
18747
  return __generator(this, function (_c) {
18436
18748
  switch (_c.label) {
18437
18749
  case 0:
@@ -18441,11 +18753,11 @@ function resolveAssistantWorkspaceRoot() {
18441
18753
  _c.label = 1;
18442
18754
  case 1:
18443
18755
  _c.trys.push([1, 9, 10, 11]);
18444
- candidates_8 = __values(candidates), candidates_8_1 = candidates_8.next();
18756
+ candidates_9 = __values(candidates), candidates_9_1 = candidates_9.next();
18445
18757
  _c.label = 2;
18446
18758
  case 2:
18447
- if (!!candidates_8_1.done) return [3 /*break*/, 8];
18448
- candidate = candidates_8_1.value;
18759
+ if (!!candidates_9_1.done) return [3 /*break*/, 8];
18760
+ candidate = candidates_9_1.value;
18449
18761
  _a = !candidate;
18450
18762
  if (_a) return [3 /*break*/, 4];
18451
18763
  return [4 /*yield*/, directoryExists(candidate)];
@@ -18474,18 +18786,18 @@ function resolveAssistantWorkspaceRoot() {
18474
18786
  }
18475
18787
  _c.label = 7;
18476
18788
  case 7:
18477
- candidates_8_1 = candidates_8.next();
18789
+ candidates_9_1 = candidates_9.next();
18478
18790
  return [3 /*break*/, 2];
18479
18791
  case 8: return [3 /*break*/, 11];
18480
18792
  case 9:
18481
- e_43_1 = _c.sent();
18482
- e_43 = { error: e_43_1 };
18793
+ e_44_1 = _c.sent();
18794
+ e_44 = { error: e_44_1 };
18483
18795
  return [3 /*break*/, 11];
18484
18796
  case 10:
18485
18797
  try {
18486
- if (candidates_8_1 && !candidates_8_1.done && (_b = candidates_8.return)) _b.call(candidates_8);
18798
+ if (candidates_9_1 && !candidates_9_1.done && (_b = candidates_9.return)) _b.call(candidates_9);
18487
18799
  }
18488
- finally { if (e_43) throw e_43.error; }
18800
+ finally { if (e_44) throw e_44.error; }
18489
18801
  return [7 /*endfinally*/];
18490
18802
  case 11:
18491
18803
  if (firstNestedGitRoot) {
@@ -18891,7 +19203,7 @@ var AI_ASSISTANT_BREAKDOWN_DIMENSION_STOPWORDS = new Set([
18891
19203
  'by'
18892
19204
  ]);
18893
19205
  function normalizeAssistantBreakdownDimension(value) {
18894
- var e_44, _a;
19206
+ var e_45, _a;
18895
19207
  var normalized = normalizeOptionalString(value)
18896
19208
  .toLowerCase()
18897
19209
  .replace(/[^a-z0-9_\s-]+/g, ' ')
@@ -18923,12 +19235,12 @@ function normalizeAssistantBreakdownDimension(value) {
18923
19235
  }
18924
19236
  }
18925
19237
  }
18926
- catch (e_44_1) { e_44 = { error: e_44_1 }; }
19238
+ catch (e_45_1) { e_45 = { error: e_45_1 }; }
18927
19239
  finally {
18928
19240
  try {
18929
19241
  if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
18930
19242
  }
18931
- finally { if (e_44) throw e_44.error; }
19243
+ finally { if (e_45) throw e_45.error; }
18932
19244
  }
18933
19245
  if (!kept.length) {
18934
19246
  return '';
@@ -19133,7 +19445,7 @@ function resolveAssistantPlannerEnabled(config) {
19133
19445
  return raw === undefined ? false : raw === true;
19134
19446
  }
19135
19447
  function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
19136
- var e_45, _a;
19448
+ var e_46, _a;
19137
19449
  var _b;
19138
19450
  if (isSuperAdmin === void 0) { isSuperAdmin = false; }
19139
19451
  var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
@@ -19147,12 +19459,12 @@ function resolveAssistantPlannerKnownRoutes(user, isSuperAdmin) {
19147
19459
  }
19148
19460
  }
19149
19461
  }
19150
- catch (e_45_1) { e_45 = { error: e_45_1 }; }
19462
+ catch (e_46_1) { e_46 = { error: e_46_1 }; }
19151
19463
  finally {
19152
19464
  try {
19153
19465
  if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
19154
19466
  }
19155
- finally { if (e_45) throw e_45.error; }
19467
+ finally { if (e_46) throw e_46.error; }
19156
19468
  }
19157
19469
  var normalizedRoutes = Array.from(unique);
19158
19470
  var allowedRoutes = collectAssistantAllowedRoutesForUser(user, normalizedRoutes, isSuperAdmin);
@@ -19247,6 +19559,7 @@ function buildAssistantContext(input, userContext) {
19247
19559
  : [];
19248
19560
  if (collectionHints.length) {
19249
19561
  lines.push("Collection hints: ".concat(collectionHints.join(', ')));
19562
+ lines.push('Collection hints are candidate roots and related collections; the first hint can be a measured/detail collection. Choose the root collection that owns the primary business object in the request, then join related collections for details/metrics.');
19250
19563
  }
19251
19564
  var termHints = Array.isArray(userContext === null || userContext === void 0 ? void 0 : userContext.termHints)
19252
19565
  ? userContext === null || userContext === void 0 ? void 0 : userContext.termHints.filter(Boolean)
@@ -19462,7 +19775,7 @@ function normalizeRouteMatchKey(value) {
19462
19775
  return normalizeRouteKey(value).toLowerCase();
19463
19776
  }
19464
19777
  function buildClientRouteIndex() {
19465
- var e_46, _a;
19778
+ var e_47, _a;
19466
19779
  var _b;
19467
19780
  var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
19468
19781
  var set = new Set();
@@ -19481,12 +19794,12 @@ function buildClientRouteIndex() {
19481
19794
  }
19482
19795
  }
19483
19796
  }
19484
- catch (e_46_1) { e_46 = { error: e_46_1 }; }
19797
+ catch (e_47_1) { e_47 = { error: e_47_1 }; }
19485
19798
  finally {
19486
19799
  try {
19487
19800
  if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
19488
19801
  }
19489
- finally { if (e_46) throw e_46.error; }
19802
+ finally { if (e_47) throw e_47.error; }
19490
19803
  }
19491
19804
  return { set: set, map: map, size: routes.length };
19492
19805
  }
@@ -20265,8 +20578,8 @@ function shouldSkipAssistantGitDiscoveryDirectory(name) {
20265
20578
  }
20266
20579
  function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
20267
20580
  return __awaiter(this, void 0, void 0, function () {
20268
- var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b, e_47_1, queue, queued, enqueue, next, entries, _c, entries_1, entries_1_1, entry, childName, candidate, gitPath, _d, e_48_1;
20269
- var e_47, _e, e_48, _f;
20581
+ var roots, seen, push, _a, configuredRoots, configuredRoots_1, configuredRoots_1_1, configuredRoot, _b, e_48_1, queue, queued, enqueue, next, entries, _c, entries_1, entries_1_1, entry, childName, candidate, gitPath, _d, e_49_1;
20582
+ var e_48, _e, e_49, _f;
20270
20583
  var _g;
20271
20584
  return __generator(this, function (_h) {
20272
20585
  switch (_h.label) {
@@ -20311,14 +20624,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
20311
20624
  return [3 /*break*/, 3];
20312
20625
  case 6: return [3 /*break*/, 9];
20313
20626
  case 7:
20314
- e_47_1 = _h.sent();
20315
- e_47 = { error: e_47_1 };
20627
+ e_48_1 = _h.sent();
20628
+ e_48 = { error: e_48_1 };
20316
20629
  return [3 /*break*/, 9];
20317
20630
  case 8:
20318
20631
  try {
20319
20632
  if (configuredRoots_1_1 && !configuredRoots_1_1.done && (_e = configuredRoots_1.return)) _e.call(configuredRoots_1);
20320
20633
  }
20321
- finally { if (e_47) throw e_47.error; }
20634
+ finally { if (e_48) throw e_48.error; }
20322
20635
  return [7 /*endfinally*/];
20323
20636
  case 9:
20324
20637
  queue = [];
@@ -20358,7 +20671,7 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
20358
20671
  return [3 /*break*/, 14];
20359
20672
  case 14:
20360
20673
  _h.trys.push([14, 21, 22, 23]);
20361
- entries_1 = (e_48 = void 0, __values(entries)), entries_1_1 = entries_1.next();
20674
+ entries_1 = (e_49 = void 0, __values(entries)), entries_1_1 = entries_1.next();
20362
20675
  _h.label = 15;
20363
20676
  case 15:
20364
20677
  if (!!entries_1_1.done) return [3 /*break*/, 20];
@@ -20397,14 +20710,14 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
20397
20710
  return [3 /*break*/, 15];
20398
20711
  case 20: return [3 /*break*/, 23];
20399
20712
  case 21:
20400
- e_48_1 = _h.sent();
20401
- e_48 = { error: e_48_1 };
20713
+ e_49_1 = _h.sent();
20714
+ e_49 = { error: e_49_1 };
20402
20715
  return [3 /*break*/, 23];
20403
20716
  case 22:
20404
20717
  try {
20405
20718
  if (entries_1_1 && !entries_1_1.done && (_f = entries_1.return)) _f.call(entries_1);
20406
20719
  }
20407
- finally { if (e_48) throw e_48.error; }
20720
+ finally { if (e_49) throw e_49.error; }
20408
20721
  return [7 /*endfinally*/];
20409
20722
  case 23: return [3 /*break*/, 10];
20410
20723
  case 24: return [2 /*return*/, roots];
@@ -20744,8 +21057,8 @@ function syncAssistantGitMirror(repoUrl) {
20744
21057
  }
20745
21058
  function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
20746
21059
  return __awaiter(this, void 0, void 0, function () {
20747
- var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot, e_49_1;
20748
- var e_49, _a;
21060
+ var roots, repoUrls, mirroredRoots, repoUrls_1, repoUrls_1_1, repoUrl, mirrorRoot, e_50_1;
21061
+ var e_50, _a;
20749
21062
  return __generator(this, function (_b) {
20750
21063
  switch (_b.label) {
20751
21064
  case 0: return [4 /*yield*/, resolveAssistantWorkspaceGitRoots(workspaceRoot)];
@@ -20779,14 +21092,14 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
20779
21092
  return [3 /*break*/, 3];
20780
21093
  case 6: return [3 /*break*/, 9];
20781
21094
  case 7:
20782
- e_49_1 = _b.sent();
20783
- e_49 = { error: e_49_1 };
21095
+ e_50_1 = _b.sent();
21096
+ e_50 = { error: e_50_1 };
20784
21097
  return [3 /*break*/, 9];
20785
21098
  case 8:
20786
21099
  try {
20787
21100
  if (repoUrls_1_1 && !repoUrls_1_1.done && (_a = repoUrls_1.return)) _a.call(repoUrls_1);
20788
21101
  }
20789
- finally { if (e_49) throw e_49.error; }
21102
+ finally { if (e_50) throw e_50.error; }
20790
21103
  return [7 /*endfinally*/];
20791
21104
  case 9: return [2 /*return*/, mirroredRoots];
20792
21105
  }
@@ -20795,8 +21108,8 @@ function resolveAssistantChangeHistoryGitRoots(workspaceRoot) {
20795
21108
  }
20796
21109
  function resolveAssistantChangeHistoryFastPathResponse(params) {
20797
21110
  return __awaiter(this, void 0, void 0, function () {
20798
- 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_50_1;
20799
- var e_50, _f;
21111
+ var workspaceRoot, _a, gitRoots, featureKeywords, sawExecutionError, bestFallback, gitRoots_1, gitRoots_1_1, gitRoot, _b, branch, _c, _d, limit, historyDepth, rawHistory, commits, summary, hasKeywordMatches, _e, e_51_1;
21112
+ var e_51, _f;
20800
21113
  return __generator(this, function (_g) {
20801
21114
  switch (_g.label) {
20802
21115
  case 0:
@@ -20918,14 +21231,14 @@ function resolveAssistantChangeHistoryFastPathResponse(params) {
20918
21231
  return [3 /*break*/, 7];
20919
21232
  case 20: return [3 /*break*/, 23];
20920
21233
  case 21:
20921
- e_50_1 = _g.sent();
20922
- e_50 = { error: e_50_1 };
21234
+ e_51_1 = _g.sent();
21235
+ e_51 = { error: e_51_1 };
20923
21236
  return [3 /*break*/, 23];
20924
21237
  case 22:
20925
21238
  try {
20926
21239
  if (gitRoots_1_1 && !gitRoots_1_1.done && (_f = gitRoots_1.return)) _f.call(gitRoots_1);
20927
21240
  }
20928
- finally { if (e_50) throw e_50.error; }
21241
+ finally { if (e_51) throw e_51.error; }
20929
21242
  return [7 /*endfinally*/];
20930
21243
  case 23:
20931
21244
  if (bestFallback) {
@@ -21106,7 +21419,7 @@ function sanitizeAssistantResponse(value) {
21106
21419
  return normalizeAssistantRoutes(normalizedCurrency);
21107
21420
  }
21108
21421
  function evaluateAssistantGuardrails(message) {
21109
- var e_51, _a;
21422
+ var e_52, _a;
21110
21423
  var normalized = String(message || '').toLowerCase();
21111
21424
  var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
21112
21425
  if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
@@ -21151,12 +21464,12 @@ function evaluateAssistantGuardrails(message) {
21151
21464
  }
21152
21465
  }
21153
21466
  }
21154
- catch (e_51_1) { e_51 = { error: e_51_1 }; }
21467
+ catch (e_52_1) { e_52 = { error: e_52_1 }; }
21155
21468
  finally {
21156
21469
  try {
21157
21470
  if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
21158
21471
  }
21159
- finally { if (e_51) throw e_51.error; }
21472
+ finally { if (e_52) throw e_52.error; }
21160
21473
  }
21161
21474
  return null;
21162
21475
  }
@@ -21261,7 +21574,7 @@ function tokenizeArithmeticExpression(expression) {
21261
21574
  return tokens;
21262
21575
  }
21263
21576
  function evaluateArithmeticExpression(expression) {
21264
- var e_52, _a, e_53, _b;
21577
+ var e_53, _a, e_54, _b;
21265
21578
  var tokens = tokenizeArithmeticExpression(expression);
21266
21579
  if (!tokens || !tokens.length) {
21267
21580
  return null;
@@ -21318,12 +21631,12 @@ function evaluateArithmeticExpression(expression) {
21318
21631
  prevToken = token;
21319
21632
  }
21320
21633
  }
21321
- catch (e_52_1) { e_52 = { error: e_52_1 }; }
21634
+ catch (e_53_1) { e_53 = { error: e_53_1 }; }
21322
21635
  finally {
21323
21636
  try {
21324
21637
  if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
21325
21638
  }
21326
- finally { if (e_52) throw e_52.error; }
21639
+ finally { if (e_53) throw e_53.error; }
21327
21640
  }
21328
21641
  while (ops.length) {
21329
21642
  var op = ops.pop();
@@ -21363,12 +21676,12 @@ function evaluateArithmeticExpression(expression) {
21363
21676
  stack.push(Number(token));
21364
21677
  }
21365
21678
  }
21366
- catch (e_53_1) { e_53 = { error: e_53_1 }; }
21679
+ catch (e_54_1) { e_54 = { error: e_54_1 }; }
21367
21680
  finally {
21368
21681
  try {
21369
21682
  if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
21370
21683
  }
21371
- finally { if (e_53) throw e_53.error; }
21684
+ finally { if (e_54) throw e_54.error; }
21372
21685
  }
21373
21686
  if (stack.length !== 1 || Number.isNaN(stack[0])) {
21374
21687
  return null;
@@ -21552,8 +21865,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
21552
21865
  }
21553
21866
  function readAttachmentContents(attachments) {
21554
21867
  return __awaiter(this, void 0, void 0, function () {
21555
- var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_54_1;
21556
- var e_54, _b;
21868
+ var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_55_1;
21869
+ var e_55, _b;
21557
21870
  return __generator(this, function (_c) {
21558
21871
  switch (_c.label) {
21559
21872
  case 0:
@@ -21632,14 +21945,14 @@ function readAttachmentContents(attachments) {
21632
21945
  return [3 /*break*/, 2];
21633
21946
  case 10: return [3 /*break*/, 13];
21634
21947
  case 11:
21635
- e_54_1 = _c.sent();
21636
- e_54 = { error: e_54_1 };
21948
+ e_55_1 = _c.sent();
21949
+ e_55 = { error: e_55_1 };
21637
21950
  return [3 /*break*/, 13];
21638
21951
  case 12:
21639
21952
  try {
21640
21953
  if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
21641
21954
  }
21642
- finally { if (e_54) throw e_54.error; }
21955
+ finally { if (e_55) throw e_55.error; }
21643
21956
  return [7 /*endfinally*/];
21644
21957
  case 13: return [2 /*return*/, {
21645
21958
  promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
@@ -22050,7 +22363,7 @@ function sanitizeAssistantMessageSetPayload(setPayload) {
22050
22363
  return next;
22051
22364
  }
22052
22365
  function sanitizeMongoSafeObject(value) {
22053
- var e_55, _a;
22366
+ var e_56, _a;
22054
22367
  if (value === null || value === undefined) {
22055
22368
  return value;
22056
22369
  }
@@ -22074,17 +22387,17 @@ function sanitizeMongoSafeObject(value) {
22074
22387
  out[key] = sanitizeMongoSafeObject(rawValue);
22075
22388
  }
22076
22389
  }
22077
- catch (e_55_1) { e_55 = { error: e_55_1 }; }
22390
+ catch (e_56_1) { e_56 = { error: e_56_1 }; }
22078
22391
  finally {
22079
22392
  try {
22080
22393
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
22081
22394
  }
22082
- finally { if (e_55) throw e_55.error; }
22395
+ finally { if (e_56) throw e_56.error; }
22083
22396
  }
22084
22397
  return out;
22085
22398
  }
22086
22399
  function restoreMongoSafeObject(value) {
22087
- var e_56, _a;
22400
+ var e_57, _a;
22088
22401
  if (value === null || value === undefined) {
22089
22402
  return value;
22090
22403
  }
@@ -22108,12 +22421,12 @@ function restoreMongoSafeObject(value) {
22108
22421
  out[key] = restoreMongoSafeObject(rawValue);
22109
22422
  }
22110
22423
  }
22111
- catch (e_56_1) { e_56 = { error: e_56_1 }; }
22424
+ catch (e_57_1) { e_57 = { error: e_57_1 }; }
22112
22425
  finally {
22113
22426
  try {
22114
22427
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
22115
22428
  }
22116
- finally { if (e_56) throw e_56.error; }
22429
+ finally { if (e_57) throw e_57.error; }
22117
22430
  }
22118
22431
  return out;
22119
22432
  }
@@ -22228,7 +22541,7 @@ function estimateUsage(messages, responseText, model) {
22228
22541
  };
22229
22542
  }
22230
22543
  function evaluateGuardrails(message) {
22231
- var e_57, _a;
22544
+ var e_58, _a;
22232
22545
  var normalized = String(message || '').toLowerCase();
22233
22546
  var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
22234
22547
  if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
@@ -22254,12 +22567,12 @@ function evaluateGuardrails(message) {
22254
22567
  }
22255
22568
  }
22256
22569
  }
22257
- catch (e_57_1) { e_57 = { error: e_57_1 }; }
22570
+ catch (e_58_1) { e_58 = { error: e_58_1 }; }
22258
22571
  finally {
22259
22572
  try {
22260
22573
  if (patterns_3_1 && !patterns_3_1.done && (_a = patterns_3.return)) _a.call(patterns_3);
22261
22574
  }
22262
- finally { if (e_57) throw e_57.error; }
22575
+ finally { if (e_58) throw e_58.error; }
22263
22576
  }
22264
22577
  return null;
22265
22578
  }