@resolveio/server-lib 22.2.16 → 22.2.17
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.
- package/methods/ai-terminal.js +187 -33
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -5902,6 +5902,41 @@ function buildAssistantInvoiceCustomerLabelExpr() {
|
|
|
5902
5902
|
}
|
|
5903
5903
|
};
|
|
5904
5904
|
}
|
|
5905
|
+
function buildAssistantWorkOrderCustomerLabelExpr() {
|
|
5906
|
+
return {
|
|
5907
|
+
$let: {
|
|
5908
|
+
vars: {
|
|
5909
|
+
customer_name: buildAssistantTrimmedStringExpr('$customer_name'),
|
|
5910
|
+
customer_fullname: buildAssistantTrimmedStringExpr('$customer.fullname'),
|
|
5911
|
+
customer_nested_name: buildAssistantTrimmedStringExpr('$customer.name'),
|
|
5912
|
+
customer_scalar: buildAssistantTrimmedStringExpr('$customer'),
|
|
5913
|
+
client_name: buildAssistantTrimmedStringExpr('$client_name'),
|
|
5914
|
+
client_fullname: buildAssistantTrimmedStringExpr('$client.fullname'),
|
|
5915
|
+
client_nested_name: buildAssistantTrimmedStringExpr('$client.name'),
|
|
5916
|
+
client_scalar: buildAssistantTrimmedStringExpr('$client'),
|
|
5917
|
+
id_customer: buildAssistantTrimmedStringExpr('$id_customer'),
|
|
5918
|
+
id_client: buildAssistantTrimmedStringExpr('$id_client')
|
|
5919
|
+
},
|
|
5920
|
+
in: {
|
|
5921
|
+
$switch: {
|
|
5922
|
+
branches: [
|
|
5923
|
+
{ case: { $gt: [{ $strLenCP: '$$customer_name' }, 0] }, then: '$$customer_name' },
|
|
5924
|
+
{ case: { $gt: [{ $strLenCP: '$$customer_fullname' }, 0] }, then: '$$customer_fullname' },
|
|
5925
|
+
{ case: { $gt: [{ $strLenCP: '$$customer_nested_name' }, 0] }, then: '$$customer_nested_name' },
|
|
5926
|
+
{ case: { $gt: [{ $strLenCP: '$$customer_scalar' }, 0] }, then: '$$customer_scalar' },
|
|
5927
|
+
{ case: { $gt: [{ $strLenCP: '$$client_name' }, 0] }, then: '$$client_name' },
|
|
5928
|
+
{ case: { $gt: [{ $strLenCP: '$$client_fullname' }, 0] }, then: '$$client_fullname' },
|
|
5929
|
+
{ case: { $gt: [{ $strLenCP: '$$client_nested_name' }, 0] }, then: '$$client_nested_name' },
|
|
5930
|
+
{ case: { $gt: [{ $strLenCP: '$$client_scalar' }, 0] }, then: '$$client_scalar' },
|
|
5931
|
+
{ case: { $gt: [{ $strLenCP: '$$id_customer' }, 0] }, then: '$$id_customer' },
|
|
5932
|
+
{ case: { $gt: [{ $strLenCP: '$$id_client' }, 0] }, then: '$$id_client' }
|
|
5933
|
+
],
|
|
5934
|
+
default: 'Unknown Customer'
|
|
5935
|
+
}
|
|
5936
|
+
}
|
|
5937
|
+
}
|
|
5938
|
+
};
|
|
5939
|
+
}
|
|
5905
5940
|
var AI_ASSISTANT_NUMBER_WORDS = {
|
|
5906
5941
|
one: 1,
|
|
5907
5942
|
two: 2,
|
|
@@ -7727,47 +7762,141 @@ function buildAssistantWorkOrderTopCustomersDirective(message, collectionHints,
|
|
|
7727
7762
|
{
|
|
7728
7763
|
$addFields: {
|
|
7729
7764
|
effective_date: {
|
|
7730
|
-
$
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7765
|
+
$convert: {
|
|
7766
|
+
input: {
|
|
7767
|
+
$ifNull: [
|
|
7768
|
+
'$date_created',
|
|
7769
|
+
{ $ifNull: ['$date_create', '$createdAt'] }
|
|
7770
|
+
]
|
|
7771
|
+
},
|
|
7772
|
+
to: 'date',
|
|
7773
|
+
onError: null,
|
|
7774
|
+
onNull: null
|
|
7775
|
+
}
|
|
7734
7776
|
},
|
|
7735
|
-
customer_label:
|
|
7736
|
-
|
|
7737
|
-
|
|
7777
|
+
customer_label: buildAssistantWorkOrderCustomerLabelExpr(),
|
|
7778
|
+
deleted_flag: { $ifNull: ['$deleted.is_deleted', false] }
|
|
7779
|
+
}
|
|
7780
|
+
},
|
|
7781
|
+
{
|
|
7782
|
+
$match: {
|
|
7783
|
+
$expr: {
|
|
7784
|
+
$and: [
|
|
7785
|
+
{ $ne: ['$effective_date', null] },
|
|
7738
7786
|
{
|
|
7739
|
-
$
|
|
7740
|
-
'$
|
|
7787
|
+
$gte: [
|
|
7788
|
+
'$effective_date',
|
|
7741
7789
|
{
|
|
7742
|
-
$
|
|
7743
|
-
'
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
{ $ifNull: ['$qb_ListID_class', 'Unknown'] }
|
|
7748
|
-
]
|
|
7749
|
-
}
|
|
7750
|
-
]
|
|
7790
|
+
$dateSubtract: {
|
|
7791
|
+
startDate: '$$NOW',
|
|
7792
|
+
unit: 'month',
|
|
7793
|
+
amount: months
|
|
7794
|
+
}
|
|
7751
7795
|
}
|
|
7752
7796
|
]
|
|
7753
|
-
}
|
|
7797
|
+
},
|
|
7798
|
+
{ $lt: ['$effective_date', '$$NOW'] },
|
|
7799
|
+
{ $ne: ['$deleted_flag', true] }
|
|
7754
7800
|
]
|
|
7755
7801
|
}
|
|
7756
7802
|
}
|
|
7757
7803
|
},
|
|
7758
7804
|
{
|
|
7759
|
-
$
|
|
7760
|
-
|
|
7761
|
-
|
|
7762
|
-
|
|
7763
|
-
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7805
|
+
$group: {
|
|
7806
|
+
_id: '$customer_label',
|
|
7807
|
+
work_order_count: { $sum: 1 }
|
|
7808
|
+
}
|
|
7809
|
+
},
|
|
7810
|
+
{
|
|
7811
|
+
$sort: {
|
|
7812
|
+
work_order_count: -1,
|
|
7813
|
+
_id: 1
|
|
7814
|
+
}
|
|
7815
|
+
},
|
|
7816
|
+
{
|
|
7817
|
+
$limit: topN
|
|
7818
|
+
},
|
|
7819
|
+
{
|
|
7820
|
+
$project: {
|
|
7821
|
+
_id: 0,
|
|
7822
|
+
customer: '$_id',
|
|
7823
|
+
work_order_count: 1
|
|
7824
|
+
}
|
|
7825
|
+
}
|
|
7826
|
+
],
|
|
7827
|
+
options: {
|
|
7828
|
+
allowDiskUse: true,
|
|
7829
|
+
limit: topN
|
|
7830
|
+
}
|
|
7831
|
+
},
|
|
7832
|
+
cleaned: '',
|
|
7833
|
+
rawLine: 'HEURISTIC_AGG(work-order-top-customers-window)'
|
|
7834
|
+
};
|
|
7835
|
+
}
|
|
7836
|
+
function buildAssistantWorkOrdersThisWeekByCustomerDirective(message, collectionHints, collectionNames) {
|
|
7837
|
+
var text = normalizeOptionalString(message).toLowerCase();
|
|
7838
|
+
if (!text) {
|
|
7839
|
+
return null;
|
|
7840
|
+
}
|
|
7841
|
+
if (!hasAssistantWorkOrderAliasTerms(text)) {
|
|
7842
|
+
return null;
|
|
7843
|
+
}
|
|
7844
|
+
if (!/\bthis\s+week\b/.test(text)) {
|
|
7845
|
+
return null;
|
|
7846
|
+
}
|
|
7847
|
+
var hasCustomerBreakdown = /\b(by|per)\s+(?:each\s+)?(customers?|clients?|accounts?)\b/.test(text)
|
|
7848
|
+
|| /\b(customers?|clients?|accounts?)\s+breakdown\b/.test(text);
|
|
7849
|
+
if (!hasCustomerBreakdown) {
|
|
7850
|
+
return null;
|
|
7851
|
+
}
|
|
7852
|
+
var limit = resolveAssistantNaturalNumberFromPattern(text, /\btop\s+([a-z0-9]+)\b/i, 100, 1, AI_ASSISTANT_MONGO_MAX_LIMIT);
|
|
7853
|
+
var collection = resolveAssistantHeuristicCollectionFromCandidates(collectionHints, AI_ASSISTANT_WORK_ORDER_HINT_CANDIDATES, collectionNames);
|
|
7854
|
+
if (!collection) {
|
|
7855
|
+
return null;
|
|
7856
|
+
}
|
|
7857
|
+
var startOfWeekExpr = {
|
|
7858
|
+
$dateTrunc: {
|
|
7859
|
+
date: '$$NOW',
|
|
7860
|
+
unit: 'week',
|
|
7861
|
+
startOfWeek: 'monday',
|
|
7862
|
+
timezone: 'UTC'
|
|
7863
|
+
}
|
|
7864
|
+
};
|
|
7865
|
+
return {
|
|
7866
|
+
type: 'aggregate',
|
|
7867
|
+
payload: {
|
|
7868
|
+
collection: collection,
|
|
7869
|
+
permissionView: resolveDefaultAssistantPermissionView(collection),
|
|
7870
|
+
pipeline: [
|
|
7871
|
+
{
|
|
7872
|
+
$addFields: {
|
|
7873
|
+
effective_created_at: {
|
|
7874
|
+
$convert: {
|
|
7875
|
+
input: {
|
|
7876
|
+
$ifNull: [
|
|
7877
|
+
'$date_created',
|
|
7878
|
+
{ $ifNull: ['$date_create', '$createdAt'] }
|
|
7879
|
+
]
|
|
7880
|
+
},
|
|
7881
|
+
to: 'date',
|
|
7882
|
+
onError: null,
|
|
7883
|
+
onNull: null
|
|
7884
|
+
}
|
|
7769
7885
|
},
|
|
7770
|
-
|
|
7886
|
+
customer_label: buildAssistantWorkOrderCustomerLabelExpr(),
|
|
7887
|
+
deleted_flag: { $ifNull: ['$deleted.is_deleted', false] }
|
|
7888
|
+
}
|
|
7889
|
+
},
|
|
7890
|
+
{
|
|
7891
|
+
$match: {
|
|
7892
|
+
$expr: {
|
|
7893
|
+
$and: [
|
|
7894
|
+
{ $ne: ['$effective_created_at', null] },
|
|
7895
|
+
{ $gte: ['$effective_created_at', startOfWeekExpr] },
|
|
7896
|
+
{ $lte: ['$effective_created_at', '$$NOW'] },
|
|
7897
|
+
{ $ne: ['$deleted_flag', true] }
|
|
7898
|
+
]
|
|
7899
|
+
}
|
|
7771
7900
|
}
|
|
7772
7901
|
},
|
|
7773
7902
|
{
|
|
@@ -7783,7 +7912,7 @@ function buildAssistantWorkOrderTopCustomersDirective(message, collectionHints,
|
|
|
7783
7912
|
}
|
|
7784
7913
|
},
|
|
7785
7914
|
{
|
|
7786
|
-
$limit:
|
|
7915
|
+
$limit: limit
|
|
7787
7916
|
},
|
|
7788
7917
|
{
|
|
7789
7918
|
$project: {
|
|
@@ -7795,11 +7924,11 @@ function buildAssistantWorkOrderTopCustomersDirective(message, collectionHints,
|
|
|
7795
7924
|
],
|
|
7796
7925
|
options: {
|
|
7797
7926
|
allowDiskUse: true,
|
|
7798
|
-
limit:
|
|
7927
|
+
limit: limit
|
|
7799
7928
|
}
|
|
7800
7929
|
},
|
|
7801
7930
|
cleaned: '',
|
|
7802
|
-
rawLine: 'HEURISTIC_AGG(work-order-
|
|
7931
|
+
rawLine: 'HEURISTIC_AGG(work-order-this-week-customer-breakdown)'
|
|
7803
7932
|
};
|
|
7804
7933
|
}
|
|
7805
7934
|
function buildAssistantCompletedWorkOrderDeliveryBreakdownDirective(message, collectionHints, collectionNames) {
|
|
@@ -8829,6 +8958,7 @@ function isAssistantBlendDomainHeuristicDirective(directive) {
|
|
|
8829
8958
|
function isAssistantWorkOrderHeuristicDirective(directive) {
|
|
8830
8959
|
var rawLine = normalizeOptionalString(directive === null || directive === void 0 ? void 0 : directive.rawLine).toLowerCase();
|
|
8831
8960
|
return rawLine.includes('heuristic_agg(work-order-created-this-week-status)')
|
|
8961
|
+
|| rawLine.includes('heuristic_agg(work-order-this-week-customer-breakdown)')
|
|
8832
8962
|
|| rawLine.includes('heuristic_agg(work-order-completed-per-day)')
|
|
8833
8963
|
|| rawLine.includes('heuristic_agg(work-order-completed-delivery-breakdown)')
|
|
8834
8964
|
|| rawLine.includes('heuristic_agg(work-order-top-customers-window)');
|
|
@@ -8956,6 +9086,12 @@ function buildAssistantHeuristicDirective(message, collectionHints, collectionNa
|
|
|
8956
9086
|
if (blendUserWindowDirective) {
|
|
8957
9087
|
return blendUserWindowDirective;
|
|
8958
9088
|
}
|
|
9089
|
+
var workOrderWeekCustomerBreakdownDirective = resolveAssistantDeterministicHeuristicEnabled(AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_WEEK_CUSTOMER_BREAKDOWN, appId)
|
|
9090
|
+
? buildAssistantWorkOrdersThisWeekByCustomerDirective(message, collectionHints, collectionNames)
|
|
9091
|
+
: null;
|
|
9092
|
+
if (workOrderWeekCustomerBreakdownDirective) {
|
|
9093
|
+
return workOrderWeekCustomerBreakdownDirective;
|
|
9094
|
+
}
|
|
8959
9095
|
var workOrderCreatedWeekDirective = resolveAssistantDeterministicHeuristicEnabled(AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_CREATED_WEEK_STATUS, appId)
|
|
8960
9096
|
? buildAssistantWorkOrderCreatedThisWeekStatusDirective(message, collectionHints, collectionNames)
|
|
8961
9097
|
: null;
|
|
@@ -17138,6 +17274,7 @@ var AI_ASSISTANT_HEURISTIC_ID_ACTIVE_CLIENTS_COUNT = 'active_clients_count';
|
|
|
17138
17274
|
var AI_ASSISTANT_HEURISTIC_ID_ACTIVE_HOLDS_COUNT = 'active_holds_count';
|
|
17139
17275
|
var AI_ASSISTANT_HEURISTIC_ID_INVENTORY_CHEMICAL_QUANTITY = 'inventory_chemical_quantity';
|
|
17140
17276
|
var AI_ASSISTANT_HEURISTIC_ID_BLEND_USER_WINDOW_COUNT = 'blend_user_window_count';
|
|
17277
|
+
var AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_WEEK_CUSTOMER_BREAKDOWN = 'work_order_week_customer_breakdown';
|
|
17141
17278
|
var AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_CREATED_WEEK_STATUS = 'work_order_created_week_status';
|
|
17142
17279
|
var AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_COMPLETED_PER_DAY = 'work_order_completed_per_day';
|
|
17143
17280
|
var AI_ASSISTANT_HEURISTIC_ID_WORK_ORDER_TOP_CUSTOMERS_WINDOW = 'work_order_top_customers_window';
|
|
@@ -17816,6 +17953,11 @@ function resolveCollectionOverrideWithContext(params) {
|
|
|
17816
17953
|
}
|
|
17817
17954
|
var rankingOverride = resolveAssistantCollectionOverride(params.collectionRanking, requested);
|
|
17818
17955
|
if (rankingOverride) {
|
|
17956
|
+
var rankingOverrideTarget = normalizeAssistantCollectionOverrideName(rankingOverride.to);
|
|
17957
|
+
var requestedIsWorkOrder = isAssistantWorkOrderCollectionOverrideCandidate(requested);
|
|
17958
|
+
if (rankingOverrideTarget === 'orders' && requestedIsWorkOrder && hasAssistantWorkOrderAliasTerms(params.message)) {
|
|
17959
|
+
return null;
|
|
17960
|
+
}
|
|
17819
17961
|
if (!allowVersions && isVersionCollectionName(rankingOverride.to)) {
|
|
17820
17962
|
var base = stripVersionSuffix(rankingOverride.to);
|
|
17821
17963
|
if (base && collectionNames.includes(base)) {
|
|
@@ -17832,6 +17974,13 @@ function resolveCollectionOverrideWithContext(params) {
|
|
|
17832
17974
|
}
|
|
17833
17975
|
return null;
|
|
17834
17976
|
}
|
|
17977
|
+
function isAssistantWorkOrderCollectionOverrideCandidate(value) {
|
|
17978
|
+
var normalized = normalizeAssistantCollectionOverrideName(value);
|
|
17979
|
+
return normalized === 'work-order-dynamics'
|
|
17980
|
+
|| normalized === 'work-orders'
|
|
17981
|
+
|| normalized === 'maintenance-orders'
|
|
17982
|
+
|| normalized === 'repair-orders';
|
|
17983
|
+
}
|
|
17835
17984
|
function pickPreferredCollectionCandidate(ranked) {
|
|
17836
17985
|
if (!Array.isArray(ranked) || !ranked.length) {
|
|
17837
17986
|
return null;
|
|
@@ -17927,6 +18076,11 @@ function resolveAssistantCollectionOverride(collectionRanking, currentCollection
|
|
|
17927
18076
|
&& isAssistantCollectionRefinementOf(current, top.name)) {
|
|
17928
18077
|
return null;
|
|
17929
18078
|
}
|
|
18079
|
+
if (currentScore >= AI_ASSISTANT_COLLECTION_OVERRIDE_MIN_SCORE
|
|
18080
|
+
&& normalizeAssistantCollectionOverrideName(top.name) === 'orders'
|
|
18081
|
+
&& isAssistantWorkOrderCollectionOverrideCandidate(current)) {
|
|
18082
|
+
return null;
|
|
18083
|
+
}
|
|
17930
18084
|
var scoreGap = top.score - currentScore;
|
|
17931
18085
|
var currentIsVersion = isVersionCollectionName(current);
|
|
17932
18086
|
var topIsVersion = isVersionCollectionName(top.name);
|