@resolveio/server-lib 22.2.16 → 22.2.18

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.
@@ -183,6 +183,10 @@ export declare function buildDisplayTable(docs: any[], options?: {
183
183
  export declare function formatDisplayTableMarkdown(display: AiAssistantDisplayTable): string;
184
184
  export declare function resolveAssistantReadDisplayMaxRows(limit: number | undefined, rowCount: number): number;
185
185
  export declare function normalizeAssistantNowExprPlaceholders(value: any): any;
186
+ export declare function repairAssistantPositionalPathSegmentsInPipeline(pipeline: Array<Record<string, any>>): {
187
+ pipeline: Array<Record<string, any>>;
188
+ changed: boolean;
189
+ };
186
190
  export declare function repairAssistantFieldPathReferenceInPipeline(pipeline: Array<Record<string, any>>, fieldPath: string): {
187
191
  pipeline: Array<Record<string, any>>;
188
192
  changed: boolean;
@@ -195,6 +199,19 @@ export declare function stripScopedFieldsFromPipeline(pipeline: any[], fieldsToS
195
199
  export declare function rewriteEmbeddedMatchObjects(query: any): any;
196
200
  export declare function resolveAssistantAppCollectionHintCandidates(message: string, appId?: string): string[];
197
201
  export declare function isAssistantDeterministicHeuristicEnabledForApp(heuristicId: string, appId?: string): boolean;
202
+ export declare function resolveCollectionOverrideWithContextForTesting(params: {
203
+ message: string;
204
+ collectionRanking: Record<string, any> | null;
205
+ requestedCollection: string;
206
+ permissionView?: string;
207
+ collectionNames: string[];
208
+ }): {
209
+ from: string;
210
+ to: string;
211
+ fromScore: number;
212
+ toScore: number;
213
+ reason: string;
214
+ } | null;
198
215
  export declare function resolveAssistantCollectionOverride(collectionRanking: Record<string, any> | null, currentCollection: string): {
199
216
  from: string;
200
217
  to: string;
@@ -121,6 +121,7 @@ exports.buildDisplayTable = buildDisplayTable;
121
121
  exports.formatDisplayTableMarkdown = formatDisplayTableMarkdown;
122
122
  exports.resolveAssistantReadDisplayMaxRows = resolveAssistantReadDisplayMaxRows;
123
123
  exports.normalizeAssistantNowExprPlaceholders = normalizeAssistantNowExprPlaceholders;
124
+ exports.repairAssistantPositionalPathSegmentsInPipeline = repairAssistantPositionalPathSegmentsInPipeline;
124
125
  exports.repairAssistantFieldPathReferenceInPipeline = repairAssistantFieldPathReferenceInPipeline;
125
126
  exports.rewriteMatchExpressionsToExpr = rewriteMatchExpressionsToExpr;
126
127
  exports.normalizeAssistantMonthlyCalendarWindowPipeline = normalizeAssistantMonthlyCalendarWindowPipeline;
@@ -130,6 +131,7 @@ exports.stripScopedFieldsFromPipeline = stripScopedFieldsFromPipeline;
130
131
  exports.rewriteEmbeddedMatchObjects = rewriteEmbeddedMatchObjects;
131
132
  exports.resolveAssistantAppCollectionHintCandidates = resolveAssistantAppCollectionHintCandidates;
132
133
  exports.isAssistantDeterministicHeuristicEnabledForApp = isAssistantDeterministicHeuristicEnabledForApp;
134
+ exports.resolveCollectionOverrideWithContextForTesting = resolveCollectionOverrideWithContextForTesting;
133
135
  exports.resolveAssistantCollectionOverride = resolveAssistantCollectionOverride;
134
136
  exports.resolveAssistantCrossCollectionFallbackCandidates = resolveAssistantCrossCollectionFallbackCandidates;
135
137
  exports.resolveAssistantAvailableCrossCollectionFallbacksFromNames = resolveAssistantAvailableCrossCollectionFallbacksFromNames;
@@ -4157,7 +4159,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
4157
4159
  : { readPreference: AI_ASSISTANT_READ_PREFERENCE };
4158
4160
  };
4159
4161
  runAggregateWithRepair = function (pipeline, stage) { return __awaiter(_this, void 0, void 0, function () {
4160
- var aggregateOptions, docs, error_9, isDateRepair, isRankSortByRepair, isDottedOutputFieldRepair, repaired, dottedFieldPath, dottedFieldReferenceRepairUsed, pathReferenceRepair, docs;
4162
+ var aggregateOptions, docs, error_9, isDateRepair, isRankSortByRepair, isDottedOutputFieldRepair, isPositionalPathRepair, repaired, dottedFieldPath, dottedFieldReferenceRepairUsed, pathReferenceRepair, docs;
4161
4163
  return __generator(this, function (_a) {
4162
4164
  switch (_a.label) {
4163
4165
  case 0:
@@ -4179,14 +4181,17 @@ function executeAiAssistantMongoAggregate(payload, context) {
4179
4181
  isDateRepair = isAssistantDateArithmeticArgumentError(error_9);
4180
4182
  isRankSortByRepair = isAssistantRankSortByError(error_9);
4181
4183
  isDottedOutputFieldRepair = isAssistantDottedOutputFieldError(error_9);
4182
- if (!isDateRepair && !isRankSortByRepair && !isDottedOutputFieldRepair) {
4184
+ isPositionalPathRepair = isAssistantPositionalPathError(error_9);
4185
+ if (!isDateRepair && !isRankSortByRepair && !isDottedOutputFieldRepair && !isPositionalPathRepair) {
4183
4186
  throw error_9;
4184
4187
  }
4185
4188
  repaired = isDateRepair
4186
4189
  ? repairAssistantDateArithmeticInPipeline(pipeline)
4187
4190
  : isRankSortByRepair
4188
4191
  ? repairAssistantRankSortByInPipeline(pipeline)
4189
- : repairAssistantDottedOutputFieldNamesInPipeline(pipeline);
4192
+ : isDottedOutputFieldRepair
4193
+ ? repairAssistantDottedOutputFieldNamesInPipeline(pipeline)
4194
+ : repairAssistantPositionalPathSegmentsInPipeline(pipeline);
4190
4195
  dottedFieldPath = null;
4191
4196
  dottedFieldReferenceRepairUsed = false;
4192
4197
  if (isDottedOutputFieldRepair) {
@@ -4237,6 +4242,14 @@ function executeAiAssistantMongoAggregate(payload, context) {
4237
4242
  fieldPath: dottedFieldPath || undefined
4238
4243
  };
4239
4244
  }
4245
+ if (isPositionalPathRepair) {
4246
+ fallbackMeta.positionalPath = {
4247
+ attempted: true,
4248
+ used: true,
4249
+ stage: stage,
4250
+ reason: 'removed_positional_path_segments'
4251
+ };
4252
+ }
4240
4253
  return [2 /*return*/, { documents: docs, pipeline: repaired.pipeline }];
4241
4254
  case 5: return [2 /*return*/];
4242
4255
  }
@@ -5902,6 +5915,41 @@ function buildAssistantInvoiceCustomerLabelExpr() {
5902
5915
  }
5903
5916
  };
5904
5917
  }
5918
+ function buildAssistantWorkOrderCustomerLabelExpr() {
5919
+ return {
5920
+ $let: {
5921
+ vars: {
5922
+ customer_name: buildAssistantTrimmedStringExpr('$customer_name'),
5923
+ customer_fullname: buildAssistantTrimmedStringExpr('$customer.fullname'),
5924
+ customer_nested_name: buildAssistantTrimmedStringExpr('$customer.name'),
5925
+ customer_scalar: buildAssistantTrimmedStringExpr('$customer'),
5926
+ client_name: buildAssistantTrimmedStringExpr('$client_name'),
5927
+ client_fullname: buildAssistantTrimmedStringExpr('$client.fullname'),
5928
+ client_nested_name: buildAssistantTrimmedStringExpr('$client.name'),
5929
+ client_scalar: buildAssistantTrimmedStringExpr('$client'),
5930
+ id_customer: buildAssistantTrimmedStringExpr('$id_customer'),
5931
+ id_client: buildAssistantTrimmedStringExpr('$id_client')
5932
+ },
5933
+ in: {
5934
+ $switch: {
5935
+ branches: [
5936
+ { case: { $gt: [{ $strLenCP: '$$customer_name' }, 0] }, then: '$$customer_name' },
5937
+ { case: { $gt: [{ $strLenCP: '$$customer_fullname' }, 0] }, then: '$$customer_fullname' },
5938
+ { case: { $gt: [{ $strLenCP: '$$customer_nested_name' }, 0] }, then: '$$customer_nested_name' },
5939
+ { case: { $gt: [{ $strLenCP: '$$customer_scalar' }, 0] }, then: '$$customer_scalar' },
5940
+ { case: { $gt: [{ $strLenCP: '$$client_name' }, 0] }, then: '$$client_name' },
5941
+ { case: { $gt: [{ $strLenCP: '$$client_fullname' }, 0] }, then: '$$client_fullname' },
5942
+ { case: { $gt: [{ $strLenCP: '$$client_nested_name' }, 0] }, then: '$$client_nested_name' },
5943
+ { case: { $gt: [{ $strLenCP: '$$client_scalar' }, 0] }, then: '$$client_scalar' },
5944
+ { case: { $gt: [{ $strLenCP: '$$id_customer' }, 0] }, then: '$$id_customer' },
5945
+ { case: { $gt: [{ $strLenCP: '$$id_client' }, 0] }, then: '$$id_client' }
5946
+ ],
5947
+ default: 'Unknown Customer'
5948
+ }
5949
+ }
5950
+ }
5951
+ };
5952
+ }
5905
5953
  var AI_ASSISTANT_NUMBER_WORDS = {
5906
5954
  one: 1,
5907
5955
  two: 2,
@@ -7727,47 +7775,141 @@ function buildAssistantWorkOrderTopCustomersDirective(message, collectionHints,
7727
7775
  {
7728
7776
  $addFields: {
7729
7777
  effective_date: {
7730
- $ifNull: [
7731
- '$date_created',
7732
- { $ifNull: ['$date_create', '$createdAt'] }
7733
- ]
7778
+ $convert: {
7779
+ input: {
7780
+ $ifNull: [
7781
+ '$date_created',
7782
+ { $ifNull: ['$date_create', '$createdAt'] }
7783
+ ]
7784
+ },
7785
+ to: 'date',
7786
+ onError: null,
7787
+ onNull: null
7788
+ }
7734
7789
  },
7735
- customer_label: {
7736
- $ifNull: [
7737
- '$customer',
7790
+ customer_label: buildAssistantWorkOrderCustomerLabelExpr(),
7791
+ deleted_flag: { $ifNull: ['$deleted.is_deleted', false] }
7792
+ }
7793
+ },
7794
+ {
7795
+ $match: {
7796
+ $expr: {
7797
+ $and: [
7798
+ { $ne: ['$effective_date', null] },
7738
7799
  {
7739
- $ifNull: [
7740
- '$customer_name',
7800
+ $gte: [
7801
+ '$effective_date',
7741
7802
  {
7742
- $ifNull: [
7743
- '$client_name',
7744
- {
7745
- $ifNull: [
7746
- { $toString: '$id_customer' },
7747
- { $ifNull: ['$qb_ListID_class', 'Unknown'] }
7748
- ]
7749
- }
7750
- ]
7803
+ $dateSubtract: {
7804
+ startDate: '$$NOW',
7805
+ unit: 'month',
7806
+ amount: months
7807
+ }
7751
7808
  }
7752
7809
  ]
7753
- }
7810
+ },
7811
+ { $lt: ['$effective_date', '$$NOW'] },
7812
+ { $ne: ['$deleted_flag', true] }
7754
7813
  ]
7755
7814
  }
7756
7815
  }
7757
7816
  },
7758
7817
  {
7759
- $match: {
7760
- effective_date: {
7761
- $gte: {
7762
- $dateSubtract: {
7763
- startDate: '$$NOW',
7764
- unit: 'month',
7765
- amount: months
7766
- }
7767
- },
7768
- $lt: '$$NOW'
7818
+ $group: {
7819
+ _id: '$customer_label',
7820
+ work_order_count: { $sum: 1 }
7821
+ }
7822
+ },
7823
+ {
7824
+ $sort: {
7825
+ work_order_count: -1,
7826
+ _id: 1
7827
+ }
7828
+ },
7829
+ {
7830
+ $limit: topN
7831
+ },
7832
+ {
7833
+ $project: {
7834
+ _id: 0,
7835
+ customer: '$_id',
7836
+ work_order_count: 1
7837
+ }
7838
+ }
7839
+ ],
7840
+ options: {
7841
+ allowDiskUse: true,
7842
+ limit: topN
7843
+ }
7844
+ },
7845
+ cleaned: '',
7846
+ rawLine: 'HEURISTIC_AGG(work-order-top-customers-window)'
7847
+ };
7848
+ }
7849
+ function buildAssistantWorkOrdersThisWeekByCustomerDirective(message, collectionHints, collectionNames) {
7850
+ var text = normalizeOptionalString(message).toLowerCase();
7851
+ if (!text) {
7852
+ return null;
7853
+ }
7854
+ if (!hasAssistantWorkOrderAliasTerms(text)) {
7855
+ return null;
7856
+ }
7857
+ if (!/\bthis\s+week\b/.test(text)) {
7858
+ return null;
7859
+ }
7860
+ var hasCustomerBreakdown = /\b(by|per)\s+(?:each\s+)?(customers?|clients?|accounts?)\b/.test(text)
7861
+ || /\b(customers?|clients?|accounts?)\s+breakdown\b/.test(text);
7862
+ if (!hasCustomerBreakdown) {
7863
+ return null;
7864
+ }
7865
+ var limit = resolveAssistantNaturalNumberFromPattern(text, /\btop\s+([a-z0-9]+)\b/i, 100, 1, AI_ASSISTANT_MONGO_MAX_LIMIT);
7866
+ var collection = resolveAssistantHeuristicCollectionFromCandidates(collectionHints, AI_ASSISTANT_WORK_ORDER_HINT_CANDIDATES, collectionNames);
7867
+ if (!collection) {
7868
+ return null;
7869
+ }
7870
+ var startOfWeekExpr = {
7871
+ $dateTrunc: {
7872
+ date: '$$NOW',
7873
+ unit: 'week',
7874
+ startOfWeek: 'monday',
7875
+ timezone: 'UTC'
7876
+ }
7877
+ };
7878
+ return {
7879
+ type: 'aggregate',
7880
+ payload: {
7881
+ collection: collection,
7882
+ permissionView: resolveDefaultAssistantPermissionView(collection),
7883
+ pipeline: [
7884
+ {
7885
+ $addFields: {
7886
+ effective_created_at: {
7887
+ $convert: {
7888
+ input: {
7889
+ $ifNull: [
7890
+ '$date_created',
7891
+ { $ifNull: ['$date_create', '$createdAt'] }
7892
+ ]
7893
+ },
7894
+ to: 'date',
7895
+ onError: null,
7896
+ onNull: null
7897
+ }
7769
7898
  },
7770
- 'deleted.date': { $exists: false }
7899
+ customer_label: buildAssistantWorkOrderCustomerLabelExpr(),
7900
+ deleted_flag: { $ifNull: ['$deleted.is_deleted', false] }
7901
+ }
7902
+ },
7903
+ {
7904
+ $match: {
7905
+ $expr: {
7906
+ $and: [
7907
+ { $ne: ['$effective_created_at', null] },
7908
+ { $gte: ['$effective_created_at', startOfWeekExpr] },
7909
+ { $lte: ['$effective_created_at', '$$NOW'] },
7910
+ { $ne: ['$deleted_flag', true] }
7911
+ ]
7912
+ }
7771
7913
  }
7772
7914
  },
7773
7915
  {
@@ -7783,7 +7925,7 @@ function buildAssistantWorkOrderTopCustomersDirective(message, collectionHints,
7783
7925
  }
7784
7926
  },
7785
7927
  {
7786
- $limit: topN
7928
+ $limit: limit
7787
7929
  },
7788
7930
  {
7789
7931
  $project: {
@@ -7795,11 +7937,11 @@ function buildAssistantWorkOrderTopCustomersDirective(message, collectionHints,
7795
7937
  ],
7796
7938
  options: {
7797
7939
  allowDiskUse: true,
7798
- limit: topN
7940
+ limit: limit
7799
7941
  }
7800
7942
  },
7801
7943
  cleaned: '',
7802
- rawLine: 'HEURISTIC_AGG(work-order-top-customers-window)'
7944
+ rawLine: 'HEURISTIC_AGG(work-order-this-week-customer-breakdown)'
7803
7945
  };
7804
7946
  }
7805
7947
  function buildAssistantCompletedWorkOrderDeliveryBreakdownDirective(message, collectionHints, collectionNames) {
@@ -8829,6 +8971,7 @@ function isAssistantBlendDomainHeuristicDirective(directive) {
8829
8971
  function isAssistantWorkOrderHeuristicDirective(directive) {
8830
8972
  var rawLine = normalizeOptionalString(directive === null || directive === void 0 ? void 0 : directive.rawLine).toLowerCase();
8831
8973
  return rawLine.includes('heuristic_agg(work-order-created-this-week-status)')
8974
+ || rawLine.includes('heuristic_agg(work-order-this-week-customer-breakdown)')
8832
8975
  || rawLine.includes('heuristic_agg(work-order-completed-per-day)')
8833
8976
  || rawLine.includes('heuristic_agg(work-order-completed-delivery-breakdown)')
8834
8977
  || rawLine.includes('heuristic_agg(work-order-top-customers-window)');
@@ -8956,6 +9099,12 @@ function buildAssistantHeuristicDirective(message, collectionHints, collectionNa
8956
9099
  if (blendUserWindowDirective) {
8957
9100
  return blendUserWindowDirective;
8958
9101
  }
9102
+ var workOrderWeekCustomerBreakdownDirective = resolveAssistantDeterministicHeuristicEnabled(AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_WEEK_CUSTOMER_BREAKDOWN, appId)
9103
+ ? buildAssistantWorkOrdersThisWeekByCustomerDirective(message, collectionHints, collectionNames)
9104
+ : null;
9105
+ if (workOrderWeekCustomerBreakdownDirective) {
9106
+ return workOrderWeekCustomerBreakdownDirective;
9107
+ }
8959
9108
  var workOrderCreatedWeekDirective = resolveAssistantDeterministicHeuristicEnabled(AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_CREATED_WEEK_STATUS, appId)
8960
9109
  ? buildAssistantWorkOrderCreatedThisWeekStatusDirective(message, collectionHints, collectionNames)
8961
9110
  : null;
@@ -13329,6 +13478,76 @@ function normalizeAssistantNowExprPlaceholdersDeep(value) {
13329
13478
  function normalizeAssistantNowExprPlaceholders(value) {
13330
13479
  return normalizeAssistantNowExprPlaceholdersDeep(value);
13331
13480
  }
13481
+ function stripAssistantPositionalPathSegments(path) {
13482
+ var normalized = normalizeOptionalString(path);
13483
+ if (!normalized || !normalized.includes('.$')) {
13484
+ return normalized;
13485
+ }
13486
+ return normalized.replace(/\.\$(?=\.|$)/g, '');
13487
+ }
13488
+ function repairAssistantPositionalPathSegmentsDeep(value) {
13489
+ var changed = false;
13490
+ var rewriteValue = function (current) {
13491
+ if (Array.isArray(current)) {
13492
+ return current.map(function (entry) { return rewriteValue(entry); });
13493
+ }
13494
+ if (!current || typeof current !== 'object' || current instanceof Date || current instanceof RegExp || isMongoObjectId(current)) {
13495
+ if (typeof current === 'string' && current.startsWith('$') && !current.startsWith('$$')) {
13496
+ var strippedPath = stripAssistantPositionalPathSegments(current.slice(1));
13497
+ if (strippedPath && strippedPath !== current.slice(1)) {
13498
+ changed = true;
13499
+ return "$".concat(strippedPath);
13500
+ }
13501
+ }
13502
+ return current;
13503
+ }
13504
+ var next = {};
13505
+ Object.keys(current).forEach(function (key) {
13506
+ var nextKey = key;
13507
+ if (!key.startsWith('$')) {
13508
+ var strippedKey = stripAssistantPositionalPathSegments(key);
13509
+ if (strippedKey && strippedKey !== key) {
13510
+ nextKey = strippedKey;
13511
+ changed = true;
13512
+ }
13513
+ }
13514
+ next[nextKey] = rewriteValue(current[key]);
13515
+ });
13516
+ return next;
13517
+ };
13518
+ return {
13519
+ value: rewriteValue(value),
13520
+ changed: changed
13521
+ };
13522
+ }
13523
+ function repairAssistantPositionalPathSegmentsInQuery(query) {
13524
+ var repaired = repairAssistantPositionalPathSegmentsDeep(query);
13525
+ var normalizedQuery = (repaired.value && typeof repaired.value === 'object' && !Array.isArray(repaired.value))
13526
+ ? repaired.value
13527
+ : query;
13528
+ return {
13529
+ query: normalizedQuery,
13530
+ changed: repaired.changed
13531
+ };
13532
+ }
13533
+ function repairAssistantPositionalPathSegmentsInPipeline(pipeline) {
13534
+ var repaired = repairAssistantPositionalPathSegmentsDeep(pipeline);
13535
+ var normalizedPipeline = Array.isArray(repaired.value)
13536
+ ? repaired.value
13537
+ : pipeline;
13538
+ return {
13539
+ pipeline: normalizedPipeline,
13540
+ changed: repaired.changed
13541
+ };
13542
+ }
13543
+ function isAssistantPositionalPathError(error) {
13544
+ var message = normalizeOptionalString(error === null || error === void 0 ? void 0 : error.message).toLowerCase();
13545
+ if (!message) {
13546
+ return false;
13547
+ }
13548
+ return message.includes('positional operator')
13549
+ && message.includes('middle of a path');
13550
+ }
13332
13551
  function isAssistantDateArithmeticArgumentError(error) {
13333
13552
  var message = normalizeOptionalString(error === null || error === void 0 ? void 0 : error.message).toLowerCase();
13334
13553
  if (!message) {
@@ -14354,7 +14573,8 @@ function normalizeAssistantAggregatePipeline(pipeline, collection, originalMessa
14354
14573
  if (next.$setWindowFields && typeof next.$setWindowFields === 'object' && !Array.isArray(next.$setWindowFields)) {
14355
14574
  next.$setWindowFields = normalizeAssistantSetWindowFieldsRankSortBy(next.$setWindowFields);
14356
14575
  }
14357
- return normalizeAssistantNowExprPlaceholdersDeep(next);
14576
+ var nowNormalized = normalizeAssistantNowExprPlaceholdersDeep(next);
14577
+ return repairAssistantPositionalPathSegmentsInQuery(nowNormalized).query;
14358
14578
  });
14359
14579
  var stableSortPipeline = normalizeAssistantSortTieBreakersForLimit(normalizedPipeline);
14360
14580
  var recordLimitedPipeline = normalizeAssistantRecentGroupedLimitBeforeGroup(stableSortPipeline, originalMessage);
@@ -16305,7 +16525,8 @@ function normalizeMongoQuery(query) {
16305
16525
  }
16306
16526
  var rewritten = rewriteEmbeddedMatchObjects(normalized);
16307
16527
  var exprRewritten = rewriteMatchExpressionsToExpr(rewritten);
16308
- var nowNormalized = normalizeAssistantNowExprPlaceholdersDeep(exprRewritten);
16528
+ var positionalRepaired = repairAssistantPositionalPathSegmentsInQuery(exprRewritten).query;
16529
+ var nowNormalized = normalizeAssistantNowExprPlaceholdersDeep(positionalRepaired);
16309
16530
  return applyAssistantNameRegexToQuery(nowNormalized);
16310
16531
  }
16311
16532
  function shouldApplyAssistantNameRegex(field) {
@@ -17138,6 +17359,7 @@ var AI_ASSISTANT_HEURISTIC_ID_ACTIVE_CLIENTS_COUNT = 'active_clients_count';
17138
17359
  var AI_ASSISTANT_HEURISTIC_ID_ACTIVE_HOLDS_COUNT = 'active_holds_count';
17139
17360
  var AI_ASSISTANT_HEURISTIC_ID_INVENTORY_CHEMICAL_QUANTITY = 'inventory_chemical_quantity';
17140
17361
  var AI_ASSISTANT_HEURISTIC_ID_BLEND_USER_WINDOW_COUNT = 'blend_user_window_count';
17362
+ var AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_WEEK_CUSTOMER_BREAKDOWN = 'work_order_week_customer_breakdown';
17141
17363
  var AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_CREATED_WEEK_STATUS = 'work_order_created_week_status';
17142
17364
  var AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_COMPLETED_PER_DAY = 'work_order_completed_per_day';
17143
17365
  var AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_TOP_CUSTOMERS_WINDOW = 'work_order_top_customers_window';
@@ -17790,6 +18012,19 @@ function resolveCollectionOverrideWithContext(params) {
17790
18012
  var allowVersions = shouldAllowVersionCollections(params.message);
17791
18013
  var collectionNames = Array.isArray(params.collectionNames) ? params.collectionNames : [];
17792
18014
  var permissionView = normalizeOptionalString(params.permissionView);
18015
+ var routeHintCollections = permissionView
18016
+ ? resolveCollectionHintsFromRoute(permissionView, collectionNames)
18017
+ : [];
18018
+ var isCollectionInHintFamilies = function (collection, hintCollections) {
18019
+ var candidateFamily = normalizeAssistantCollectionFamilyName(collection);
18020
+ if (!candidateFamily) {
18021
+ return false;
18022
+ }
18023
+ return (hintCollections || []).some(function (hintCollection) {
18024
+ var hintFamily = normalizeAssistantCollectionFamilyName(hintCollection);
18025
+ return !!(hintFamily && hintFamily === candidateFamily);
18026
+ });
18027
+ };
17793
18028
  if (permissionView) {
17794
18029
  var reportPreferred = resolveReportCollectionName(permissionView, collectionNames, requested);
17795
18030
  if (reportPreferred && reportPreferred !== requested) {
@@ -17816,6 +18051,16 @@ function resolveCollectionOverrideWithContext(params) {
17816
18051
  }
17817
18052
  var rankingOverride = resolveAssistantCollectionOverride(params.collectionRanking, requested);
17818
18053
  if (rankingOverride) {
18054
+ var requestedMatchesRouteHints = isCollectionInHintFamilies(requested, routeHintCollections);
18055
+ var overrideMatchesRouteHints = isCollectionInHintFamilies(rankingOverride.to, routeHintCollections);
18056
+ if (requestedMatchesRouteHints && !overrideMatchesRouteHints) {
18057
+ return null;
18058
+ }
18059
+ var rankingOverrideTarget = normalizeAssistantCollectionOverrideName(rankingOverride.to);
18060
+ var requestedIsWorkOrder = isAssistantWorkOrderCollectionOverrideCandidate(requested);
18061
+ if (rankingOverrideTarget === 'orders' && requestedIsWorkOrder && hasAssistantWorkOrderAliasTerms(params.message)) {
18062
+ return null;
18063
+ }
17819
18064
  if (!allowVersions && isVersionCollectionName(rankingOverride.to)) {
17820
18065
  var base = stripVersionSuffix(rankingOverride.to);
17821
18066
  if (base && collectionNames.includes(base)) {
@@ -17832,6 +18077,16 @@ function resolveCollectionOverrideWithContext(params) {
17832
18077
  }
17833
18078
  return null;
17834
18079
  }
18080
+ function resolveCollectionOverrideWithContextForTesting(params) {
18081
+ return resolveCollectionOverrideWithContext(params);
18082
+ }
18083
+ function isAssistantWorkOrderCollectionOverrideCandidate(value) {
18084
+ var normalized = normalizeAssistantCollectionOverrideName(value);
18085
+ return normalized === 'work-order-dynamics'
18086
+ || normalized === 'work-orders'
18087
+ || normalized === 'maintenance-orders'
18088
+ || normalized === 'repair-orders';
18089
+ }
17835
18090
  function pickPreferredCollectionCandidate(ranked) {
17836
18091
  if (!Array.isArray(ranked) || !ranked.length) {
17837
18092
  return null;
@@ -17927,6 +18182,11 @@ function resolveAssistantCollectionOverride(collectionRanking, currentCollection
17927
18182
  && isAssistantCollectionRefinementOf(current, top.name)) {
17928
18183
  return null;
17929
18184
  }
18185
+ if (currentScore >= AI_ASSISTANT_COLLECTION_OVERRIDE_MIN_SCORE
18186
+ && normalizeAssistantCollectionOverrideName(top.name) === 'orders'
18187
+ && isAssistantWorkOrderCollectionOverrideCandidate(current)) {
18188
+ return null;
18189
+ }
17930
18190
  var scoreGap = top.score - currentScore;
17931
18191
  var currentIsVersion = isVersionCollectionName(current);
17932
18192
  var topIsVersion = isVersionCollectionName(top.name);