@resolveio/server-lib 22.3.202 → 22.3.203

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.
@@ -7167,24 +7167,31 @@ function cleanAssistantRequestedDimensionText(value) {
7167
7167
  text = text.replace(/[^a-z0-9_ -]+/gi, ' ');
7168
7168
  return normalizeOptionalString(text.replace(/\s+/g, ' ')).toLowerCase();
7169
7169
  }
7170
- function extractAssistantRequestedBreakdownDimensionText(message) {
7170
+ function extractAssistantRequestedBreakdownDimensionTexts(message) {
7171
7171
  var e_5, _a;
7172
7172
  var text = normalizeOptionalString(message).toLowerCase();
7173
7173
  if (!text) {
7174
- return '';
7174
+ return [];
7175
+ }
7176
+ var extracted = extractAssistantRequestedBreakdownDimensions(text)
7177
+ .map(function (value) { return cleanAssistantRequestedDimensionText(value); })
7178
+ .filter(Boolean);
7179
+ if (extracted.length) {
7180
+ return mergeAssistantHintValues(extracted);
7175
7181
  }
7176
7182
  var patterns = [
7177
7183
  /\b(?:group(?:ed)?|break(?:\s*down)?|broken\s+down|split)\s+by\s+([a-z0-9][a-z0-9_ -]{0,50}?)(?=\s+(?:for|from|to|until|through|during|this|last|past|current|where|with|and|or)\b|[,.!?;]|$)/i,
7178
7184
  /\bby\s+([a-z0-9][a-z0-9_ -]{0,50}?)(?=\s+(?:for|from|to|until|through|during|this|last|past|current|where|with|and|or)\b|[,.!?;]|$)/i,
7179
7185
  /\bper\s+([a-z0-9][a-z0-9_ -]{0,50}?)(?=\s+(?:for|from|to|until|through|during|this|last|past|current|where|with|and|or)\b|[,.!?;]|$)/i
7180
7186
  ];
7187
+ var results = [];
7181
7188
  try {
7182
7189
  for (var patterns_2 = __values(patterns), patterns_2_1 = patterns_2.next(); !patterns_2_1.done; patterns_2_1 = patterns_2.next()) {
7183
7190
  var pattern = patterns_2_1.value;
7184
7191
  var match = text.match(pattern);
7185
7192
  var dimensionText = cleanAssistantRequestedDimensionText((match === null || match === void 0 ? void 0 : match[1]) || '');
7186
7193
  if (dimensionText) {
7187
- return dimensionText;
7194
+ results.push(dimensionText);
7188
7195
  }
7189
7196
  }
7190
7197
  }
@@ -7195,7 +7202,7 @@ function extractAssistantRequestedBreakdownDimensionText(message) {
7195
7202
  }
7196
7203
  finally { if (e_5) throw e_5.error; }
7197
7204
  }
7198
- return '';
7205
+ return mergeAssistantHintValues(results);
7199
7206
  }
7200
7207
  function scoreAssistantDataDimensionMatch(requestedDimensionText, dimension) {
7201
7208
  var requested = cleanAssistantRequestedDimensionText(requestedDimensionText);
@@ -7224,22 +7231,213 @@ function scoreAssistantDataDimensionMatch(requestedDimensionText, dimension) {
7224
7231
  });
7225
7232
  return score;
7226
7233
  }
7227
- function resolveAssistantRequestedDataDimension(message, intent) {
7228
- var requestedDimensionText = extractAssistantRequestedBreakdownDimensionText(message);
7229
- if (!requestedDimensionText || !Array.isArray(intent.dimensions) || !intent.dimensions.length) {
7234
+ function resolveAssistantTimeBreakdownGranularity(requestedDimensionText) {
7235
+ var requested = cleanAssistantRequestedDimensionText(requestedDimensionText);
7236
+ if (!requested) {
7237
+ return '';
7238
+ }
7239
+ if (/\b(quarter|quarters|quarterly|qtr|qtrs)\b/i.test(requested)) {
7240
+ return 'quarter';
7241
+ }
7242
+ if (/\b(month|months|monthly)\b/i.test(requested)) {
7243
+ return 'month';
7244
+ }
7245
+ if (/\b(week|weeks|weekly)\b/i.test(requested)) {
7246
+ return 'week';
7247
+ }
7248
+ if (/\b(day|days|daily|date)\b/i.test(requested)) {
7249
+ return requested === 'date' ? 'date' : 'day';
7250
+ }
7251
+ if (/\b(year|years|yearly|annual|annually)\b/i.test(requested)) {
7252
+ return 'year';
7253
+ }
7254
+ return '';
7255
+ }
7256
+ function buildAssistantTimeBreakdownGroupExpression(granularity, dateField) {
7257
+ var dateOperand = "$".concat(dateField);
7258
+ if (granularity === 'quarter') {
7259
+ return {
7260
+ $concat: [
7261
+ { $toString: { $year: dateOperand } },
7262
+ '-Q',
7263
+ { $toString: { $ceil: { $divide: [{ $month: dateOperand }, 3] } } }
7264
+ ]
7265
+ };
7266
+ }
7267
+ var format = granularity === 'year'
7268
+ ? '%Y'
7269
+ : granularity === 'week'
7270
+ ? '%Y-W%U'
7271
+ : granularity === 'day' || granularity === 'date'
7272
+ ? '%Y-%m-%d'
7273
+ : '%Y-%m';
7274
+ return {
7275
+ $dateToString: {
7276
+ format: format,
7277
+ date: dateOperand
7278
+ }
7279
+ };
7280
+ }
7281
+ function buildAssistantDataIntentTimeDimension(requestedDimensionText, intent) {
7282
+ var _a, _b, _c;
7283
+ var granularity = resolveAssistantTimeBreakdownGranularity(requestedDimensionText);
7284
+ var dateField = normalizeOptionalString(intent.dateField);
7285
+ if (!granularity || !dateField) {
7230
7286
  return null;
7231
7287
  }
7232
- var selected = null;
7233
- intent.dimensions.forEach(function (dimension) {
7234
- var score = scoreAssistantDataDimensionMatch(requestedDimensionText, dimension);
7235
- if (score <= 0) {
7288
+ var id = granularity === 'date' ? 'date' : granularity;
7289
+ return {
7290
+ id: id,
7291
+ type: 'time',
7292
+ granularity: granularity,
7293
+ requestedText: requestedDimensionText,
7294
+ terms: [id, requestedDimensionText].filter(Boolean),
7295
+ groupId: (_a = {},
7296
+ _a[id] = buildAssistantTimeBreakdownGroupExpression(granularity, dateField),
7297
+ _a),
7298
+ project: (_b = {},
7299
+ _b[id] = "$_id.".concat(id),
7300
+ _b),
7301
+ sort: (_c = {},
7302
+ _c[id] = 1,
7303
+ _c)
7304
+ };
7305
+ }
7306
+ function extractAssistantDataIntentExpressionFieldHints(value, hints) {
7307
+ if (hints === void 0) { hints = new Set(); }
7308
+ if (typeof value === 'string') {
7309
+ if (value.startsWith('$') && !value.startsWith('$$') && !value.startsWith('$_id.')) {
7310
+ var path_1 = normalizeOptionalString(value.slice(1));
7311
+ if (path_1) {
7312
+ hints.add(path_1);
7313
+ }
7314
+ }
7315
+ return Array.from(hints);
7316
+ }
7317
+ if (Array.isArray(value)) {
7318
+ value.forEach(function (entry) { return extractAssistantDataIntentExpressionFieldHints(entry, hints); });
7319
+ return Array.from(hints);
7320
+ }
7321
+ if (value && typeof value === 'object') {
7322
+ Object.keys(value).forEach(function (key) { return extractAssistantDataIntentExpressionFieldHints(value[key], hints); });
7323
+ }
7324
+ return Array.from(hints);
7325
+ }
7326
+ function buildAssistantDataRequestMeasures(intent, pipeline) {
7327
+ var _a;
7328
+ var measures = [];
7329
+ var add = function (value) {
7330
+ var normalized = normalizeOptionalString(value);
7331
+ if (normalized && !measures.includes(normalized)) {
7332
+ measures.push(normalized);
7333
+ }
7334
+ };
7335
+ var groupIndex = findAggregateGroupIndex(pipeline || []);
7336
+ if (groupIndex > -1) {
7337
+ var groupStage = (_a = pipeline[groupIndex]) === null || _a === void 0 ? void 0 : _a.$group;
7338
+ if (groupStage && typeof groupStage === 'object') {
7339
+ Object.keys(groupStage).forEach(function (key) {
7340
+ if (key === '_id') {
7341
+ return;
7342
+ }
7343
+ if (/^(first|last|min|max)_/i.test(key) || /_ids?$/i.test(key) || key === 'blend_ids') {
7344
+ return;
7345
+ }
7346
+ add(key);
7347
+ });
7348
+ }
7349
+ }
7350
+ add(intent.quantityField ? intent.quantityField.split('.').pop() || intent.quantityField : '');
7351
+ add(intent.metricField ? intent.metricField.split('.').pop() || intent.metricField : '');
7352
+ if (!measures.length) {
7353
+ add('row_count');
7354
+ }
7355
+ return measures;
7356
+ }
7357
+ function buildAssistantDataRequestUnderstanding(message, intent, dateWindow) {
7358
+ var requestedDimensionTexts = extractAssistantRequestedBreakdownDimensionTexts(message);
7359
+ var dimensions = [];
7360
+ var requestedBreakdowns = [];
7361
+ var ambiguities = [];
7362
+ var seenDimensionIds = new Set();
7363
+ var addDimension = function (dimension) {
7364
+ var id = normalizeOptionalString(dimension.id);
7365
+ if (!id || seenDimensionIds.has(id)) {
7236
7366
  return;
7237
7367
  }
7238
- if (!selected || score > selected.score) {
7239
- selected = { dimension: dimension, score: score };
7368
+ seenDimensionIds.add(id);
7369
+ dimensions.push(dimension);
7370
+ };
7371
+ requestedDimensionTexts.forEach(function (requestedDimensionText) {
7372
+ var timeDimension = buildAssistantDataIntentTimeDimension(requestedDimensionText, intent);
7373
+ if (timeDimension) {
7374
+ addDimension(timeDimension);
7375
+ requestedBreakdowns.push({
7376
+ type: 'time',
7377
+ requested_text: requestedDimensionText,
7378
+ dimension: timeDimension.id,
7379
+ granularity: timeDimension.granularity,
7380
+ field_hint: intent.dateField
7381
+ });
7382
+ return;
7383
+ }
7384
+ if (resolveAssistantTimeBreakdownGranularity(requestedDimensionText) && !intent.dateField) {
7385
+ ambiguities.push("Requested ".concat(requestedDimensionText, " breakdown, but this app data intent has no date field."));
7386
+ requestedBreakdowns.push({
7387
+ type: 'unknown',
7388
+ requested_text: requestedDimensionText,
7389
+ granularity: resolveAssistantTimeBreakdownGranularity(requestedDimensionText)
7390
+ });
7391
+ return;
7392
+ }
7393
+ var selected = null;
7394
+ (intent.dimensions || []).forEach(function (dimension) {
7395
+ var score = scoreAssistantDataDimensionMatch(requestedDimensionText, dimension);
7396
+ if (score <= 0) {
7397
+ return;
7398
+ }
7399
+ if (!selected || score > selected.score) {
7400
+ selected = { dimension: dimension, score: score };
7401
+ }
7402
+ });
7403
+ if (selected) {
7404
+ var dimension = __assign(__assign({}, selected.dimension), { type: selected.dimension.type || 'entity', requestedText: requestedDimensionText });
7405
+ addDimension(dimension);
7406
+ requestedBreakdowns.push({
7407
+ type: 'entity',
7408
+ requested_text: requestedDimensionText,
7409
+ dimension: dimension.id,
7410
+ field_hints: extractAssistantDataIntentExpressionFieldHints(dimension.groupId)
7411
+ });
7412
+ return;
7240
7413
  }
7414
+ ambiguities.push("Requested ".concat(requestedDimensionText, " breakdown did not match a configured app dimension."));
7415
+ requestedBreakdowns.push({
7416
+ type: 'unknown',
7417
+ requested_text: requestedDimensionText
7418
+ });
7241
7419
  });
7242
- return selected ? selected.dimension : null;
7420
+ var confidence = requestedBreakdowns.length && !ambiguities.length
7421
+ ? 0.9
7422
+ : requestedBreakdowns.length
7423
+ ? 0.65
7424
+ : 0.75;
7425
+ return {
7426
+ dimensions: dimensions,
7427
+ contract: {
7428
+ intent_type: 'data_summary',
7429
+ domain: intent.id || intent.collection,
7430
+ operation: 'aggregate',
7431
+ requested_breakdowns: requestedBreakdowns,
7432
+ date_range: dateWindow.start || dateWindow.end ? __assign({}, dateWindow) : null,
7433
+ measures: [],
7434
+ filters: [],
7435
+ output_format: 'collapse_table',
7436
+ ambiguities: ambiguities,
7437
+ confidence: confidence,
7438
+ source: 'fast_app_data_request_contract'
7439
+ }
7440
+ };
7243
7441
  }
7244
7442
  function extractAssistantDataIntentGroupKeys(groupId) {
7245
7443
  if (!groupId || typeof groupId !== 'object' || Array.isArray(groupId)) {
@@ -7259,8 +7457,9 @@ function applyAssistantDataIntentDimensionTemplate(dimension, params) {
7259
7457
  ? removeUndefinedAssistantPipelineValues(applyAssistantDataIntentPipelineTemplate(dimension.preGroupStages, params))
7260
7458
  : undefined });
7261
7459
  }
7262
- function applyAssistantDataIntentDimensionToPipeline(pipeline, dimension) {
7263
- if (!dimension || !Array.isArray(pipeline) || !pipeline.length) {
7460
+ function applyAssistantDataIntentDimensionsToPipeline(pipeline, dimensions) {
7461
+ var selectedDimensions = (Array.isArray(dimensions) ? dimensions : []).filter(function (dimension) { return !!(dimension === null || dimension === void 0 ? void 0 : dimension.groupId); });
7462
+ if (!selectedDimensions.length || !Array.isArray(pipeline) || !pipeline.length) {
7264
7463
  return pipeline;
7265
7464
  }
7266
7465
  var next = (0, common_1.deepCopy)(pipeline);
@@ -7268,17 +7467,25 @@ function applyAssistantDataIntentDimensionToPipeline(pipeline, dimension) {
7268
7467
  if (groupIndex === -1) {
7269
7468
  return next;
7270
7469
  }
7271
- if (Array.isArray(dimension.preGroupStages) && dimension.preGroupStages.length) {
7272
- next.splice.apply(next, __spreadArray([groupIndex, 0], __read((0, common_1.deepCopy)(dimension.preGroupStages)), false));
7273
- groupIndex += dimension.preGroupStages.length;
7274
- }
7470
+ selectedDimensions.forEach(function (dimension) {
7471
+ if (Array.isArray(dimension.preGroupStages) && dimension.preGroupStages.length) {
7472
+ next.splice.apply(next, __spreadArray([groupIndex, 0], __read((0, common_1.deepCopy)(dimension.preGroupStages)), false));
7473
+ groupIndex += dimension.preGroupStages.length;
7474
+ }
7475
+ });
7275
7476
  var groupStage = next[groupIndex];
7276
7477
  if (!(groupStage === null || groupStage === void 0 ? void 0 : groupStage.$group) || typeof groupStage.$group !== 'object') {
7277
7478
  return next;
7278
7479
  }
7279
7480
  var oldGroupKeys = new Set(extractAssistantDataIntentGroupKeys(groupStage.$group._id));
7280
- var newGroupKeys = new Set(extractAssistantDataIntentGroupKeys(dimension.groupId));
7281
- groupStage.$group._id = (0, common_1.deepCopy)(dimension.groupId);
7481
+ var combinedGroupId = {};
7482
+ selectedDimensions.forEach(function (dimension) {
7483
+ if (dimension.groupId && typeof dimension.groupId === 'object' && !Array.isArray(dimension.groupId)) {
7484
+ Object.assign(combinedGroupId, (0, common_1.deepCopy)(dimension.groupId));
7485
+ }
7486
+ });
7487
+ var newGroupKeys = new Set(extractAssistantDataIntentGroupKeys(combinedGroupId));
7488
+ groupStage.$group._id = combinedGroupId;
7282
7489
  var projectIndex = next.findIndex(function (stage, index) { return index > groupIndex && !!(stage === null || stage === void 0 ? void 0 : stage.$project); });
7283
7490
  if (projectIndex > -1 && next[projectIndex].$project && typeof next[projectIndex].$project === 'object') {
7284
7491
  var project_1 = next[projectIndex].$project;
@@ -7287,13 +7494,28 @@ function applyAssistantDataIntentDimensionToPipeline(pipeline, dimension) {
7287
7494
  delete project_1[key];
7288
7495
  }
7289
7496
  });
7290
- if (dimension.project) {
7291
- Object.assign(project_1, (0, common_1.deepCopy)(dimension.project));
7292
- }
7497
+ selectedDimensions.forEach(function (dimension) {
7498
+ if (dimension.project) {
7499
+ Object.assign(project_1, (0, common_1.deepCopy)(dimension.project));
7500
+ }
7501
+ });
7293
7502
  }
7294
7503
  var sortIndex = next.findIndex(function (stage, index) { return index > groupIndex && !!(stage === null || stage === void 0 ? void 0 : stage.$sort); });
7295
- if (sortIndex > -1 && dimension.sort) {
7296
- next[sortIndex].$sort = (0, common_1.deepCopy)(dimension.sort);
7504
+ if (sortIndex > -1) {
7505
+ var combinedSort_1 = {};
7506
+ selectedDimensions.forEach(function (dimension) {
7507
+ if (dimension.sort && typeof dimension.sort === 'object' && !Array.isArray(dimension.sort)) {
7508
+ Object.keys(dimension.sort).forEach(function (key) {
7509
+ var _a;
7510
+ if (!Object.prototype.hasOwnProperty.call(combinedSort_1, key)) {
7511
+ combinedSort_1[key] = (0, common_1.deepCopy)((_a = dimension.sort) === null || _a === void 0 ? void 0 : _a[key]);
7512
+ }
7513
+ });
7514
+ }
7515
+ });
7516
+ if (Object.keys(combinedSort_1).length) {
7517
+ next[sortIndex].$sort = combinedSort_1;
7518
+ }
7297
7519
  }
7298
7520
  return next;
7299
7521
  }
@@ -7305,10 +7527,10 @@ function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
7305
7527
  }
7306
7528
  var customerText = extractAssistantDataIntentCustomerText(message);
7307
7529
  var dateWindow = resolveAssistantDataIntentDateWindow(message);
7308
- var requestedDimension = resolveAssistantRequestedDataDimension(message, intent);
7309
- var templatedDimension = requestedDimension
7310
- ? applyAssistantDataIntentDimensionTemplate(requestedDimension, { customerText: customerText, dateWindow: dateWindow })
7311
- : null;
7530
+ var requestUnderstanding = buildAssistantDataRequestUnderstanding(message, intent, dateWindow);
7531
+ var templatedDimensions = requestUnderstanding.dimensions
7532
+ .map(function (dimension) { return applyAssistantDataIntentDimensionTemplate(dimension, { customerText: customerText, dateWindow: dateWindow }); })
7533
+ .filter(function (dimension) { return !!(dimension === null || dimension === void 0 ? void 0 : dimension.groupId); });
7312
7534
  var acknowledgementText = buildAssistantDataIntentAcknowledgement(intent, customerText, dateWindow);
7313
7535
  var progress = intent.progress.map(function (entry) {
7314
7536
  return entry
@@ -7324,10 +7546,17 @@ function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
7324
7546
  fallbackCollections: intent.fallbackCollections,
7325
7547
  customerText: customerText,
7326
7548
  dateWindow: dateWindow,
7327
- requestedDimension: templatedDimension ? {
7328
- id: templatedDimension.id,
7329
- terms: templatedDimension.terms
7330
- } : null
7549
+ requestedDimension: templatedDimensions[0] ? {
7550
+ id: templatedDimensions[0].id,
7551
+ terms: templatedDimensions[0].terms
7552
+ } : null,
7553
+ requestedDimensions: templatedDimensions.map(function (dimension) { return ({
7554
+ id: dimension.id,
7555
+ type: dimension.type || 'entity',
7556
+ granularity: dimension.granularity || undefined,
7557
+ terms: dimension.terms
7558
+ }); }),
7559
+ requestContract: requestUnderstanding.contract
7331
7560
  };
7332
7561
  var basePayload = function (pipeline) { return ({
7333
7562
  collection: intent.collection,
@@ -7339,7 +7568,8 @@ function buildAssistantAppDataIntentDirective(message, collectionNames, appId) {
7339
7568
  var pipeline = configuredPipeline.length
7340
7569
  ? configuredPipeline
7341
7570
  : buildAssistantGenericDataIntentPipeline(intent, customerText, dateWindow);
7342
- var finalPipeline = applyAssistantDataIntentDimensionToPipeline(pipeline, templatedDimension);
7571
+ var finalPipeline = applyAssistantDataIntentDimensionsToPipeline(pipeline, templatedDimensions);
7572
+ metadata.requestContract = __assign(__assign({}, requestUnderstanding.contract), { measures: buildAssistantDataRequestMeasures(intent, finalPipeline) });
7343
7573
  return { type: 'aggregate', payload: basePayload(finalPipeline), cleaned: '', rawLine: "HEURISTIC_AGG(app-data-intent:".concat(intent.id, ")"), metadata: metadata };
7344
7574
  }
7345
7575
  function isAssistantDeterministicHeuristicDirective(directive) {
@@ -8045,7 +8275,7 @@ function buildAssistantToolResultPayload(directive, toolResponse, requestMessage
8045
8275
  ? toolResponse.verification
8046
8276
  : undefined;
8047
8277
  var directiveMetadata = directive.metadata && typeof directive.metadata === 'object' ? directive.metadata : {};
8048
- var mergedDebug = __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, ((toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) && typeof toolResponse.debug === 'object' ? toolResponse.debug : {})), (normalizeOptionalString(directiveMetadata.intentId) ? { intentId: normalizeOptionalString(directiveMetadata.intentId) } : {})), (normalizeOptionalString(directiveMetadata.acknowledgementText) ? { acknowledgementText: normalizeOptionalString(directiveMetadata.acknowledgementText) } : {})), (normalizeOptionalString(directiveMetadata.recipeUsed) ? { recipeUsed: normalizeOptionalString(directiveMetadata.recipeUsed) } : {})), (normalizeOptionalString(directiveMetadata.customerText) ? { customerText: normalizeOptionalString(directiveMetadata.customerText) } : {})), (directiveMetadata.dateWindow && typeof directiveMetadata.dateWindow === 'object' ? { dateWindow: directiveMetadata.dateWindow } : {})), (Array.isArray(directiveMetadata.assumptions) && directiveMetadata.assumptions.length ? { assumptions: directiveMetadata.assumptions } : {}));
8278
+ var mergedDebug = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, ((toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) && typeof toolResponse.debug === 'object' ? toolResponse.debug : {})), (normalizeOptionalString(directiveMetadata.intentId) ? { intentId: normalizeOptionalString(directiveMetadata.intentId) } : {})), (normalizeOptionalString(directiveMetadata.acknowledgementText) ? { acknowledgementText: normalizeOptionalString(directiveMetadata.acknowledgementText) } : {})), (normalizeOptionalString(directiveMetadata.recipeUsed) ? { recipeUsed: normalizeOptionalString(directiveMetadata.recipeUsed) } : {})), (normalizeOptionalString(directiveMetadata.customerText) ? { customerText: normalizeOptionalString(directiveMetadata.customerText) } : {})), (directiveMetadata.dateWindow && typeof directiveMetadata.dateWindow === 'object' ? { dateWindow: directiveMetadata.dateWindow } : {})), (directiveMetadata.requestContract && typeof directiveMetadata.requestContract === 'object' ? { requestContract: directiveMetadata.requestContract } : {})), (Array.isArray(directiveMetadata.requestedDimensions) && directiveMetadata.requestedDimensions.length ? { requestedDimensions: directiveMetadata.requestedDimensions } : {})), (Array.isArray(directiveMetadata.assumptions) && directiveMetadata.assumptions.length ? { assumptions: directiveMetadata.assumptions } : {}));
8049
8279
  var result = {
8050
8280
  type: directive.type === 'aggregate' ? 'mongo_agg' : 'mongo_read',
8051
8281
  input: directivePayload,
@@ -8633,14 +8863,14 @@ function buildAssistantDebugPayload(params) {
8633
8863
  else {
8634
8864
  notes.push("Report builder bridge collection: ".concat(from, " -> ").concat(to, "."));
8635
8865
  }
8636
- var path_1 = Array.isArray(fallbackInfo.reportBuilderBridge.resolutionPath)
8866
+ var path_2 = Array.isArray(fallbackInfo.reportBuilderBridge.resolutionPath)
8637
8867
  ? fallbackInfo.reportBuilderBridge.resolutionPath
8638
8868
  .map(function (entry) { return normalizeOptionalString(entry); })
8639
8869
  .filter(Boolean)
8640
8870
  .join(' -> ')
8641
8871
  : '';
8642
- if (path_1) {
8643
- notes.push("Bridge resolution path: ".concat(path_1, "."));
8872
+ if (path_2) {
8873
+ notes.push("Bridge resolution path: ".concat(path_2, "."));
8644
8874
  }
8645
8875
  }
8646
8876
  if ((_w = fallbackInfo === null || fallbackInfo === void 0 ? void 0 : fallbackInfo.reportFallback) === null || _w === void 0 ? void 0 : _w.used) {
@@ -16076,6 +16306,9 @@ function cloneAssistantHeuristicProfile(profile) {
16076
16306
  dimensions: Array.isArray(entry === null || entry === void 0 ? void 0 : entry.dimensions)
16077
16307
  ? entry.dimensions.map(function (dimension) { return ({
16078
16308
  id: normalizeOptionalString(dimension === null || dimension === void 0 ? void 0 : dimension.id),
16309
+ type: normalizeAssistantAppDataDimensionType(dimension === null || dimension === void 0 ? void 0 : dimension.type),
16310
+ granularity: normalizeOptionalString(dimension === null || dimension === void 0 ? void 0 : dimension.granularity) || undefined,
16311
+ requestedText: normalizeOptionalString(dimension === null || dimension === void 0 ? void 0 : dimension.requestedText) || undefined,
16079
16312
  terms: mergeAssistantHintValues((dimension === null || dimension === void 0 ? void 0 : dimension.terms) || []).map(function (term) { return term.toLowerCase(); }),
16080
16313
  groupId: (0, common_1.deepCopy)(dimension === null || dimension === void 0 ? void 0 : dimension.groupId),
16081
16314
  project: (dimension === null || dimension === void 0 ? void 0 : dimension.project) && typeof dimension.project === 'object' && !Array.isArray(dimension.project)
@@ -16180,6 +16413,13 @@ function normalizeAssistantDisplayDateFormat(value) {
16180
16413
  }
16181
16414
  return undefined;
16182
16415
  }
16416
+ function normalizeAssistantAppDataDimensionType(value) {
16417
+ var normalized = normalizeOptionalString(value).toLowerCase();
16418
+ if (normalized === 'time' || normalized === 'entity') {
16419
+ return normalized;
16420
+ }
16421
+ return undefined;
16422
+ }
16183
16423
  function normalizeAssistantHeuristicStringList(value) {
16184
16424
  if (Array.isArray(value)) {
16185
16425
  return mergeAssistantHintValues(value.map(function (entry) { return normalizeOptionalString(entry).toLowerCase(); }));
@@ -16268,6 +16508,8 @@ function normalizeAssistantAppDataDimensions(value) {
16268
16508
  || [id]).map(function (term) { return term.toLowerCase(); });
16269
16509
  dimensions.push({
16270
16510
  id: id,
16511
+ type: normalizeAssistantAppDataDimensionType(entry.type),
16512
+ granularity: normalizeOptionalString(entry.granularity) || undefined,
16271
16513
  terms: terms.length ? terms : [id.toLowerCase()],
16272
16514
  groupId: (0, common_1.deepCopy)(groupId),
16273
16515
  project: entry.project && typeof entry.project === 'object' && !Array.isArray(entry.project)
@@ -20399,10 +20641,10 @@ function extractAssistantRequestedBreakdownDimensions(message) {
20399
20641
  results.push(normalized);
20400
20642
  };
20401
20643
  var patterns = [
20402
- /\bgroup(?:ed)?\s+by\s+([a-z0-9_-]+(?:\s+[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
20403
- /\bbreak(?:\s+up|\s*down)?\b[\s\S]{0,80}?\bby\s+([a-z0-9_-]+(?:\s+[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
20404
- /\b(?:by|per)\s+(?:each\s+)?([a-z0-9_-]+(?:\s+[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
20405
- /\bfor\s+each\s+([a-z0-9_-]+(?:\s+[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi
20644
+ /\bgroup(?:ed)?\s+by\s+([a-z0-9_-]+(?:\s+(?!(?:by|per|for|of|in|with|and|or)\b)[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
20645
+ /\bbreak(?:\s+up|\s*down)?\b[\s\S]{0,80}?\bby\s+([a-z0-9_-]+(?:\s+(?!(?:by|per|for|of|in|with|and|or)\b)[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
20646
+ /\b(?:by|per)\s+(?:each\s+)?([a-z0-9_-]+(?:\s+(?!(?:by|per|for|of|in|with|and|or)\b)[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi,
20647
+ /\bfor\s+each\s+([a-z0-9_-]+(?:\s+(?!(?:by|per|for|of|in|with|and|or)\b)[a-z0-9_-]+){0,2})(?=\s+(?:by|per|for|of|in|with|and|or)\b|[,.!?;]|$)/gi
20406
20648
  ];
20407
20649
  patterns.forEach(function (pattern) {
20408
20650
  var match = pattern.exec(text);