@resolveio/server-lib 22.2.17 → 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
  }
@@ -13465,6 +13478,76 @@ function normalizeAssistantNowExprPlaceholdersDeep(value) {
13465
13478
  function normalizeAssistantNowExprPlaceholders(value) {
13466
13479
  return normalizeAssistantNowExprPlaceholdersDeep(value);
13467
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
+ }
13468
13551
  function isAssistantDateArithmeticArgumentError(error) {
13469
13552
  var message = normalizeOptionalString(error === null || error === void 0 ? void 0 : error.message).toLowerCase();
13470
13553
  if (!message) {
@@ -14490,7 +14573,8 @@ function normalizeAssistantAggregatePipeline(pipeline, collection, originalMessa
14490
14573
  if (next.$setWindowFields && typeof next.$setWindowFields === 'object' && !Array.isArray(next.$setWindowFields)) {
14491
14574
  next.$setWindowFields = normalizeAssistantSetWindowFieldsRankSortBy(next.$setWindowFields);
14492
14575
  }
14493
- return normalizeAssistantNowExprPlaceholdersDeep(next);
14576
+ var nowNormalized = normalizeAssistantNowExprPlaceholdersDeep(next);
14577
+ return repairAssistantPositionalPathSegmentsInQuery(nowNormalized).query;
14494
14578
  });
14495
14579
  var stableSortPipeline = normalizeAssistantSortTieBreakersForLimit(normalizedPipeline);
14496
14580
  var recordLimitedPipeline = normalizeAssistantRecentGroupedLimitBeforeGroup(stableSortPipeline, originalMessage);
@@ -16441,7 +16525,8 @@ function normalizeMongoQuery(query) {
16441
16525
  }
16442
16526
  var rewritten = rewriteEmbeddedMatchObjects(normalized);
16443
16527
  var exprRewritten = rewriteMatchExpressionsToExpr(rewritten);
16444
- var nowNormalized = normalizeAssistantNowExprPlaceholdersDeep(exprRewritten);
16528
+ var positionalRepaired = repairAssistantPositionalPathSegmentsInQuery(exprRewritten).query;
16529
+ var nowNormalized = normalizeAssistantNowExprPlaceholdersDeep(positionalRepaired);
16445
16530
  return applyAssistantNameRegexToQuery(nowNormalized);
16446
16531
  }
16447
16532
  function shouldApplyAssistantNameRegex(field) {
@@ -17927,6 +18012,19 @@ function resolveCollectionOverrideWithContext(params) {
17927
18012
  var allowVersions = shouldAllowVersionCollections(params.message);
17928
18013
  var collectionNames = Array.isArray(params.collectionNames) ? params.collectionNames : [];
17929
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
+ };
17930
18028
  if (permissionView) {
17931
18029
  var reportPreferred = resolveReportCollectionName(permissionView, collectionNames, requested);
17932
18030
  if (reportPreferred && reportPreferred !== requested) {
@@ -17953,6 +18051,11 @@ function resolveCollectionOverrideWithContext(params) {
17953
18051
  }
17954
18052
  var rankingOverride = resolveAssistantCollectionOverride(params.collectionRanking, requested);
17955
18053
  if (rankingOverride) {
18054
+ var requestedMatchesRouteHints = isCollectionInHintFamilies(requested, routeHintCollections);
18055
+ var overrideMatchesRouteHints = isCollectionInHintFamilies(rankingOverride.to, routeHintCollections);
18056
+ if (requestedMatchesRouteHints && !overrideMatchesRouteHints) {
18057
+ return null;
18058
+ }
17956
18059
  var rankingOverrideTarget = normalizeAssistantCollectionOverrideName(rankingOverride.to);
17957
18060
  var requestedIsWorkOrder = isAssistantWorkOrderCollectionOverrideCandidate(requested);
17958
18061
  if (rankingOverrideTarget === 'orders' && requestedIsWorkOrder && hasAssistantWorkOrderAliasTerms(params.message)) {
@@ -17974,6 +18077,9 @@ function resolveCollectionOverrideWithContext(params) {
17974
18077
  }
17975
18078
  return null;
17976
18079
  }
18080
+ function resolveCollectionOverrideWithContextForTesting(params) {
18081
+ return resolveCollectionOverrideWithContext(params);
18082
+ }
17977
18083
  function isAssistantWorkOrderCollectionOverrideCandidate(value) {
17978
18084
  var normalized = normalizeAssistantCollectionOverrideName(value);
17979
18085
  return normalized === 'work-order-dynamics'