@resolveio/server-lib 22.2.29 → 22.2.31

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.
@@ -10013,6 +10013,9 @@ function applyAssistantDatedReportWindow(value, toolResult) {
10013
10013
  if (!startDate || !endDate) {
10014
10014
  return content || value || '';
10015
10015
  }
10016
+ var dateDisplayFormat = resolveAssistantDisplayDateFormatPreference();
10017
+ var startDateDisplay = formatAssistantDateValue(startDate, dateDisplayFormat);
10018
+ var endDateDisplay = formatAssistantDateValue(endDate, dateDisplayFormat);
10016
10019
  var mode = normalizeOptionalString(window === null || window === void 0 ? void 0 : window.mode).toLowerCase();
10017
10020
  var months = normalizeOptionalNumber(window === null || window === void 0 ? void 0 : window.months);
10018
10021
  var monthsText = '';
@@ -10025,9 +10028,11 @@ function applyAssistantDatedReportWindow(value, toolResult) {
10025
10028
  monthsText = "; rolling last ".concat(count, " month").concat(count === 1 ? '' : 's');
10026
10029
  }
10027
10030
  }
10028
- var line = "Report date range (UTC): ".concat(startDate, " to ").concat(endDate).concat(monthsText, ".");
10031
+ var line = "Report date range (UTC): ".concat(startDateDisplay, " to ").concat(endDateDisplay).concat(monthsText, ".");
10029
10032
  var normalizedLower = String(content || '').toLowerCase();
10030
- if (normalizedLower.includes(startDate.toLowerCase()) && normalizedLower.includes(endDate.toLowerCase())) {
10033
+ var hasRawDates = normalizedLower.includes(startDate.toLowerCase()) && normalizedLower.includes(endDate.toLowerCase());
10034
+ var hasDisplayDates = normalizedLower.includes(startDateDisplay.toLowerCase()) && normalizedLower.includes(endDateDisplay.toLowerCase());
10035
+ if (hasRawDates || hasDisplayDates) {
10031
10036
  return content || value || '';
10032
10037
  }
10033
10038
  if (!content) {
@@ -11030,7 +11035,9 @@ function resolveLookupDisplayFieldCandidates(baseToken, probeDocs, schemaFields)
11030
11035
  }
11031
11036
  return !/(^|\.)(id|code|number|count|qty|quantity|total)(\.|_|$)/.test(normalized);
11032
11037
  });
11033
- return normalizeAggregateFieldList(__spreadArray(__spreadArray(__spreadArray([], __read(seededCandidates), false), __read(schemaCandidates), false), __read(probeCandidates), false)).slice(0, 24);
11038
+ var normalizedCandidates = normalizeAggregateFieldList(__spreadArray(__spreadArray(__spreadArray([], __read(seededCandidates), false), __read(schemaCandidates), false), __read(probeCandidates), false).map(function (field) { return normalizeLookupPath(field) || normalizeOptionalString(field); }));
11039
+ var safeCandidates = normalizedCandidates.filter(function (field) { return isAssistantProjectionKeyAllowed(field); });
11040
+ return safeCandidates.slice(0, 24);
11034
11041
  }
11035
11042
  function scoreLookupDisplayFieldFromDocs(field, lookupDocs) {
11036
11043
  var docs = Array.isArray(lookupDocs) ? lookupDocs : [];
@@ -11154,7 +11161,7 @@ function applyIdLookupDisplayEnrichment(params) {
11154
11161
  return [2 /*return*/, "continue"];
11155
11162
  }
11156
11163
  _loop_8 = function (candidate) {
11157
- var probeDocs, candidateHasClientScope, _e, schemaFields, nameFieldCandidates, mapping, lookupKey, idsForQuery, query, candidateHasClientScope, _f, projection, lookupDocs, bestLookupField, nameField, nameMap, displayField;
11164
+ var probeDocs, candidateHasClientScope, _e, schemaFields, nameFieldCandidates, mapping, lookupKey, idsForQuery, normalizedNameFieldCandidates, query, candidateHasClientScope, _f, rawProjection, projection, lookupDocs, bestLookupField, nameField, nameMap, displayField;
11158
11165
  var _g, _h;
11159
11166
  return __generator(this, function (_j) {
11160
11167
  switch (_j.label) {
@@ -11192,11 +11199,19 @@ function applyIdLookupDisplayEnrichment(params) {
11192
11199
  return [2 /*return*/, "continue"];
11193
11200
  }
11194
11201
  mapping = mappingMatches.find(function (entry) { return entry.lookupCollection === candidate; });
11195
- lookupKey = normalizeOptionalString(mapping === null || mapping === void 0 ? void 0 : mapping.lookupKey) || '_id';
11202
+ lookupKey = normalizeLookupPath((mapping === null || mapping === void 0 ? void 0 : mapping.lookupKey) || '') || '_id';
11196
11203
  idsForQuery = normalizeIdsForTargetField(values, probeDocs, lookupKey);
11197
11204
  if (!idsForQuery.length) {
11198
11205
  return [2 /*return*/, "continue"];
11199
11206
  }
11207
+ normalizedNameFieldCandidates = normalizeAggregateFieldList(nameFieldCandidates
11208
+ .map(function (field) { return normalizeLookupPath(field) || normalizeOptionalString(field); })
11209
+ .filter(Boolean))
11210
+ .filter(function (field) { return field !== lookupKey; })
11211
+ .filter(function (field) { return isAssistantProjectionKeyAllowed(field); });
11212
+ if (!normalizedNameFieldCandidates.length) {
11213
+ return [2 /*return*/, "continue"];
11214
+ }
11200
11215
  query = (_g = {}, _g[lookupKey] = { $in: idsForQuery }, _g);
11201
11216
  if (!!isSuperAdmin) return [3 /*break*/, 9];
11202
11217
  if (!idClient) return [3 /*break*/, 7];
@@ -11215,10 +11230,14 @@ function applyIdLookupDisplayEnrichment(params) {
11215
11230
  query = applyCustomerScopeFilter(query, candidate, idCustomer, isSuperAdmin);
11216
11231
  _j.label = 9;
11217
11232
  case 9:
11218
- projection = (_h = {}, _h[lookupKey] = 1, _h);
11219
- nameFieldCandidates.forEach(function (field) {
11220
- projection[field] = 1;
11233
+ rawProjection = (_h = {}, _h[lookupKey] = 1, _h);
11234
+ normalizedNameFieldCandidates.forEach(function (field) {
11235
+ rawProjection[field] = 1;
11221
11236
  });
11237
+ projection = sanitizeAssistantProjection(rawProjection);
11238
+ if (!projection || !Object.keys(projection).length) {
11239
+ return [2 /*return*/, "continue"];
11240
+ }
11222
11241
  return [4 /*yield*/, db.collection(candidate).find(query, {
11223
11242
  projection: projection,
11224
11243
  limit: AI_ASSISTANT_ID_DISPLAY_LOOKUP_MAX_IDS,
@@ -11229,7 +11248,7 @@ function applyIdLookupDisplayEnrichment(params) {
11229
11248
  if (!lookupDocs.length) {
11230
11249
  return [2 /*return*/, "continue"];
11231
11250
  }
11232
- bestLookupField = resolveBestLookupDisplayFieldFromDocs(nameFieldCandidates, lookupDocs);
11251
+ bestLookupField = resolveBestLookupDisplayFieldFromDocs(normalizedNameFieldCandidates, lookupDocs);
11233
11252
  if (!(bestLookupField === null || bestLookupField === void 0 ? void 0 : bestLookupField.field)) {
11234
11253
  return [2 /*return*/, "continue"];
11235
11254
  }
@@ -11278,7 +11297,7 @@ function applyIdLookupDisplayEnrichment(params) {
11278
11297
  nameField: nameField,
11279
11298
  nameFieldFillRate: (0, common_1.round)(bestLookupField.fillRate * 100, 2),
11280
11299
  nameFieldUniqueValues: bestLookupField.uniqueCount,
11281
- candidateFieldsTested: nameFieldCandidates.length,
11300
+ candidateFieldsTested: normalizedNameFieldCandidates.length,
11282
11301
  idCount: values.length,
11283
11302
  matched: nameMap.size,
11284
11303
  strategy: mapping ? 'schema' : 'token'
@@ -12186,28 +12205,38 @@ function isAssistantLikelyDateValue(value) {
12186
12205
  }
12187
12206
  return false;
12188
12207
  }
12189
- function formatAssistantDateValue(value) {
12208
+ function resolveAssistantDisplayDateFormatPreference() {
12209
+ var profile = resolveAssistantAppHeuristicProfile();
12210
+ return profile.displayDateFormat || 'mdy';
12211
+ }
12212
+ function formatAssistantDateValue(value, dateDisplayFormat) {
12213
+ if (dateDisplayFormat === void 0) { dateDisplayFormat = 'iso'; }
12190
12214
  var dateValue = value instanceof Date ? value : new Date(value);
12191
12215
  if (Number.isNaN(dateValue.getTime())) {
12192
12216
  return String(value);
12193
12217
  }
12194
- var iso = dateValue.toISOString();
12195
- var _a = __read(iso.split('T'), 2), datePart = _a[0], timePart = _a[1];
12196
- if (!timePart) {
12197
- return datePart || iso;
12198
- }
12199
- var trimmed = timePart.replace('Z', '');
12200
- if (trimmed.startsWith('00:00:00')) {
12218
+ var year = dateValue.getUTCFullYear();
12219
+ var month = "".concat(dateValue.getUTCMonth() + 1).padStart(2, '0');
12220
+ var day = "".concat(dateValue.getUTCDate()).padStart(2, '0');
12221
+ var datePart = dateDisplayFormat === 'mdy'
12222
+ ? "".concat(month, "/").concat(day, "/").concat(year)
12223
+ : "".concat(year, "-").concat(month, "-").concat(day);
12224
+ var hours = "".concat(dateValue.getUTCHours()).padStart(2, '0');
12225
+ var minutes = "".concat(dateValue.getUTCMinutes()).padStart(2, '0');
12226
+ var seconds = "".concat(dateValue.getUTCSeconds()).padStart(2, '0');
12227
+ var millis = dateValue.getUTCMilliseconds();
12228
+ if (hours === '00' && minutes === '00' && seconds === '00' && millis === 0) {
12201
12229
  return datePart;
12202
12230
  }
12203
- return "".concat(datePart, " ").concat(trimmed.slice(0, 5));
12231
+ return "".concat(datePart, " ").concat(hours, ":").concat(minutes);
12204
12232
  }
12205
- function formatAssistantDisplayCell(value, column) {
12233
+ function formatAssistantDisplayCell(value, column, dateDisplayFormat) {
12234
+ if (dateDisplayFormat === void 0) { dateDisplayFormat = 'iso'; }
12206
12235
  if (value === null || value === undefined || value === '') {
12207
12236
  return '';
12208
12237
  }
12209
12238
  if (Array.isArray(value)) {
12210
- return value.map(function (item) { return formatAssistantDisplayCell(item, column); }).filter(Boolean).join(', ');
12239
+ return value.map(function (item) { return formatAssistantDisplayCell(item, column, dateDisplayFormat); }).filter(Boolean).join(', ');
12211
12240
  }
12212
12241
  if (typeof value === 'string') {
12213
12242
  var normalizedCurrency = normalizeAssistantCurrencyText(value);
@@ -12223,7 +12252,7 @@ function formatAssistantDisplayCell(value, column) {
12223
12252
  }
12224
12253
  }
12225
12254
  if (isAssistantDateColumn(columnKey) && isAssistantLikelyDateValue(value)) {
12226
- return formatAssistantDateValue(value);
12255
+ return formatAssistantDateValue(value, dateDisplayFormat);
12227
12256
  }
12228
12257
  var numericValue = resolveAssistantNumericValue(value);
12229
12258
  if (numericValue !== null) {
@@ -12252,7 +12281,7 @@ function formatAssistantDisplayCell(value, column) {
12252
12281
  }
12253
12282
  }
12254
12283
  if (isAssistantLikelyDateValue(value) && isAssistantDateColumn(columnKey)) {
12255
- return formatAssistantDateValue(value);
12284
+ return formatAssistantDateValue(value, dateDisplayFormat);
12256
12285
  }
12257
12286
  return String(value);
12258
12287
  }
@@ -12267,12 +12296,13 @@ function formatDisplayTableMarkdown(display) {
12267
12296
  if (!display || !Array.isArray(display.columns) || !display.columns.length) {
12268
12297
  return '';
12269
12298
  }
12299
+ var dateDisplayFormat = resolveAssistantDisplayDateFormatPreference();
12270
12300
  var header = "| ".concat(display.columns.join(' | '), " |");
12271
12301
  var separator = "| ".concat(display.columns.map(function () { return '---'; }).join(' | '), " |");
12272
12302
  var rows = (display.rows || []).map(function (row) {
12273
12303
  var cells = display.columns.map(function (column) {
12274
12304
  var rawValue = row === null || row === void 0 ? void 0 : row[column];
12275
- var formatted = formatAssistantDisplayCell(rawValue, column);
12305
+ var formatted = formatAssistantDisplayCell(rawValue, column, dateDisplayFormat);
12276
12306
  return escapeMarkdownCell(formatted);
12277
12307
  });
12278
12308
  return "| ".concat(cells.join(' | '), " |");
@@ -16195,12 +16225,14 @@ function buildNameLookupFields(baseToken, docs) {
16195
16225
  }
16196
16226
  function lookupIdsForNameMatch(params) {
16197
16227
  return __awaiter(this, void 0, void 0, function () {
16198
- var db, dbName, collection, baseToken, regex, idClient, idCustomer, isSuperAdmin, probeDocs, fields, query, hasClient, normalizedCustomer, hasCustomer, projection, docs, ids;
16228
+ var db, dbName, collection, baseToken, regex, idClient, idCustomer, isSuperAdmin, probeDocs, fields, query, hasClient, normalizedCustomer, hasCustomer, rawProjection, projection, docs, ids;
16199
16229
  return __generator(this, function (_a) {
16200
16230
  switch (_a.label) {
16201
16231
  case 0:
16202
16232
  db = params.db, dbName = params.dbName, collection = params.collection, baseToken = params.baseToken, regex = params.regex, idClient = params.idClient, idCustomer = params.idCustomer, isSuperAdmin = params.isSuperAdmin, probeDocs = params.probeDocs;
16203
- fields = buildNameLookupFields(baseToken, probeDocs);
16233
+ fields = normalizeAggregateFieldList(buildNameLookupFields(baseToken, probeDocs)
16234
+ .map(function (field) { return normalizeLookupPath(field) || normalizeOptionalString(field); })
16235
+ .filter(Boolean)).filter(function (field) { return isAssistantProjectionKeyAllowed(field); });
16204
16236
  if (!fields.length) {
16205
16237
  return [2 /*return*/, null];
16206
16238
  }
@@ -16225,10 +16257,14 @@ function lookupIdsForNameMatch(params) {
16225
16257
  }
16226
16258
  _a.label = 3;
16227
16259
  case 3:
16228
- projection = { _id: 1 };
16260
+ rawProjection = { _id: 1 };
16229
16261
  fields.forEach(function (field) {
16230
- projection[field] = 1;
16262
+ rawProjection[field] = 1;
16231
16263
  });
16264
+ projection = sanitizeAssistantProjection(rawProjection);
16265
+ if (!projection || !Object.keys(projection).length) {
16266
+ return [2 /*return*/, null];
16267
+ }
16232
16268
  return [4 /*yield*/, db.collection(collection)
16233
16269
  .find(query, {
16234
16270
  projection: projection,
@@ -17401,7 +17437,8 @@ function cloneAssistantHeuristicProfile(profile) {
17401
17437
  }); })
17402
17438
  : [],
17403
17439
  enabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.enabledDeterministicHeuristics) || [])),
17404
- disabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.disabledDeterministicHeuristics) || []))
17440
+ disabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.disabledDeterministicHeuristics) || [])),
17441
+ displayDateFormat: profile === null || profile === void 0 ? void 0 : profile.displayDateFormat
17405
17442
  };
17406
17443
  }
17407
17444
  function mergeAssistantHeuristicProfiles(base, override) {
@@ -17428,8 +17465,28 @@ function mergeAssistantHeuristicProfiles(base, override) {
17428
17465
  merged.collectionTermHints = __spreadArray(__spreadArray([], __read(merged.collectionTermHints), false), __read((Array.isArray(override.collectionTermHints) ? override.collectionTermHints : [])), false);
17429
17466
  Array.from(override.enabledDeterministicHeuristics || []).forEach(function (value) { return merged.enabledDeterministicHeuristics.add(value); });
17430
17467
  Array.from(override.disabledDeterministicHeuristics || []).forEach(function (value) { return merged.disabledDeterministicHeuristics.add(value); });
17468
+ if (override.displayDateFormat) {
17469
+ merged.displayDateFormat = override.displayDateFormat;
17470
+ }
17431
17471
  return merged;
17432
17472
  }
17473
+ function normalizeAssistantDisplayDateFormat(value) {
17474
+ var normalized = normalizeOptionalString(value).toLowerCase();
17475
+ if (!normalized) {
17476
+ return undefined;
17477
+ }
17478
+ var compact = normalized.replace(/[^a-z0-9]/g, '');
17479
+ if (!compact) {
17480
+ return undefined;
17481
+ }
17482
+ if (compact === 'iso' || compact === 'isodate' || compact === 'yearfirst' || compact === 'yyyymmdd') {
17483
+ return 'iso';
17484
+ }
17485
+ if (compact === 'mdy' || compact === 'short' || compact === 'shortdate' || compact === 'mmddyyyy' || compact === 'datepipeshort') {
17486
+ return 'mdy';
17487
+ }
17488
+ return undefined;
17489
+ }
17433
17490
  function normalizeAssistantHeuristicStringList(value) {
17434
17491
  if (Array.isArray(value)) {
17435
17492
  return mergeAssistantHintValues(value.map(function (entry) { return normalizeOptionalString(entry).toLowerCase(); }));
@@ -17510,6 +17567,12 @@ function normalizeAssistantAppHeuristicProfile(value) {
17510
17567
  || value.collectionTermHints
17511
17568
  || value.term_hints
17512
17569
  || value.termHints);
17570
+ profile.displayDateFormat = normalizeAssistantDisplayDateFormat(value.display_date_format
17571
+ || value.displayDateFormat
17572
+ || value.date_display_format
17573
+ || value.dateDisplayFormat
17574
+ || value.table_date_format
17575
+ || value.tableDateFormat);
17513
17576
  var enabled = normalizeAssistantHeuristicStringList(value.enabled_deterministic_heuristics
17514
17577
  || value.enabledDeterministicHeuristics
17515
17578
  || value.enabled_heuristics