@resolveio/server-lib 22.1.4 → 22.1.6
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.d.ts +1 -0
- package/methods/ai-terminal.js +450 -277
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
- package/services/codex-client.d.ts +3 -0
- package/services/codex-client.js +70 -5
- package/services/codex-client.js.map +1 -1
- package/workers/codex-runner.worker.js +21 -2
- package/workers/codex-runner.worker.js.map +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -111,6 +111,7 @@ exports.executeAiAssistantMongoAggregate = executeAiAssistantMongoAggregate;
|
|
|
111
111
|
exports.extractAssistantMongoDirective = extractAssistantMongoDirective;
|
|
112
112
|
exports.buildAssistantInvoiceCustomerLabelExpr = buildAssistantInvoiceCustomerLabelExpr;
|
|
113
113
|
exports.buildAssistantDatedPivotDisplay = buildAssistantDatedPivotDisplay;
|
|
114
|
+
exports.deriveAssistantCommandExecutionStatus = deriveAssistantCommandExecutionStatus;
|
|
114
115
|
exports.normalizeIdsForTargetField = normalizeIdsForTargetField;
|
|
115
116
|
exports.serializeMongoValue = serializeMongoValue;
|
|
116
117
|
exports.flattenForTable = flattenForTable;
|
|
@@ -463,6 +464,9 @@ var AI_ASSISTANT_REPORT_BUILDER_EXPERT_PLAYBOOK = [
|
|
|
463
464
|
'- Re-check collection and date fields (date_created/createdAt/date_completed/date_paid variants).',
|
|
464
465
|
'- Run tiny probe (limit 1-3) to validate shape before concluding "no data".',
|
|
465
466
|
'- For name filters, verify date-only first; then apply tokenized regex and id/name lookup fallback.',
|
|
467
|
+
'- If the user is super admin OR has permission for the requested module/view, continue best-effort retries across related collections, aliases, and field/date fallbacks before failing.',
|
|
468
|
+
'- Treat "collection not configured" as a retry signal, not a terminal result. Keep searching relatable collections until retry candidates are exhausted.',
|
|
469
|
+
'- Only stop retrying when candidate collections, scoped probes, and schema/date/name fallback paths are exhausted.',
|
|
466
470
|
'',
|
|
467
471
|
'7) Output behavior after bridge response.',
|
|
468
472
|
'- Summarize the answer first in plain language.',
|
|
@@ -493,6 +497,7 @@ var AI_ASSISTANT_SYSTEM_PROMPT = [
|
|
|
493
497
|
'- Do not guess or invent collections/fields. If unsure, verify in the codebase or run a small REPORT_BUILDER_READ probe (limit 1-5) to learn the shape.',
|
|
494
498
|
'- Prefer running a small REPORT_BUILDER_READ probe over asking multiple questions.',
|
|
495
499
|
'- For any data request (counts, lists, breakdowns, recent/last items), you MUST run a REPORT_BUILDER_READ or REPORT_BUILDER_AGG before answering.',
|
|
500
|
+
'- If the user is super admin or has permission for the requested data scope, keep attempting related collection/field fallbacks and probe reads until retry paths are exhausted; do not stop on first collection mismatch.',
|
|
496
501
|
'- Ask at most one clarifying question only when required to run a query or resolve missing details.',
|
|
497
502
|
'- If a field starts with id_ and refers to another collection, treat it as a foreign key and look up the related record when needed.',
|
|
498
503
|
'- When resolving id_* fields, prefer lookup definitions from collection schemas/report-builder lookup tables to choose the target collection and name fields.',
|
|
@@ -563,6 +568,7 @@ var AI_ASSISTANT_SYSTEM_PROMPT = [
|
|
|
563
568
|
'- Use REPORT_BUILDER_READ/REPORT_BUILDER_AGG only to produce summaries/snapshots/health checks (not raw dumps) when permitted.',
|
|
564
569
|
'- If the user explicitly asks for IDs, set options.includeIds: true.',
|
|
565
570
|
'- If a data question returns zero results, verify the collection/date field with a tiny read (limit 1-5) or a date field fallback before concluding there is no data.',
|
|
571
|
+
'- Never return "dataset not configured" as the final answer when data access is allowed; continue retries and only report failure after accessible retry paths are exhausted.',
|
|
566
572
|
'- Keep responses concise and use the configured reasoning effort level (default low).',
|
|
567
573
|
'- Never show internal placeholders like $$NOW in user-facing text; always use concrete dates.',
|
|
568
574
|
'',
|
|
@@ -587,6 +593,7 @@ var AI_ASSISTANT_PLANNER_SYSTEM_PROMPT = [
|
|
|
587
593
|
' - customer_portal: apply customer scope (id_customer or other.id_customer) to all data plans.',
|
|
588
594
|
' - client_user: apply client scope (id_client) to all data plans.',
|
|
589
595
|
' - Never propose querying blocked/sensitive collections if the user lacks permission.',
|
|
596
|
+
' - If permission allows a data request, plan best-effort retrieval with preferred + fallback collections and schema/date/name validation steps before concluding failure.',
|
|
590
597
|
'',
|
|
591
598
|
'4) PERMISSION MATCHING:',
|
|
592
599
|
' - Do NOT hardcode invoice access to "/report-builder/*".',
|
|
@@ -2535,8 +2542,9 @@ function executeAiAssistantReportIssue(payload, context) {
|
|
|
2535
2542
|
}
|
|
2536
2543
|
function executeAiAssistantMongoRead(payload, context) {
|
|
2537
2544
|
return __awaiter(this, void 0, void 0, function () {
|
|
2538
|
-
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackDocs, expanded, fallbackDocs, nameFallback, fallbackDocs, _c, chemicalLookup, fallbackDocs, queryFields, _d, aliases, rewrittenQuery, fallbackDocs, _e, activeFallback, fallbackDocs, _f, idLookup, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, existingFallbacks, e_1_1, nameFields, dateFields, diagnostics, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, total, sanitizedDocuments, requestedFields, missingFields, _o, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
|
|
2545
|
+
var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _d, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _e, activeFallback, fallbackRead, fallbackDocs, _f, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, existingFallbacks, e_1_1, nameFields, dateFields, diagnostics, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, total, sanitizedDocuments, requestedFields, missingFields, _o, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
|
|
2539
2546
|
var e_1, _p;
|
|
2547
|
+
var _this = this;
|
|
2540
2548
|
var _q, _r;
|
|
2541
2549
|
return __generator(this, function (_s) {
|
|
2542
2550
|
switch (_s.label) {
|
|
@@ -2635,22 +2643,60 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2635
2643
|
scopedQuery = applyCustomerScopeFilter(clientScopedQuery, collection, customerId, isSuperAdmin);
|
|
2636
2644
|
normalized = normalizeAssistantFindOptions(input.options);
|
|
2637
2645
|
findOptions = __assign(__assign({}, normalized.findOptions), { readPreference: AI_ASSISTANT_READ_PREFERENCE });
|
|
2638
|
-
|
|
2646
|
+
runFindWithRepair = function (query, stage) { return __awaiter(_this, void 0, void 0, function () {
|
|
2647
|
+
var docs, error_5, repaired, docs;
|
|
2648
|
+
return __generator(this, function (_a) {
|
|
2649
|
+
switch (_a.label) {
|
|
2650
|
+
case 0:
|
|
2651
|
+
_a.trys.push([0, 2, , 4]);
|
|
2652
|
+
return [4 /*yield*/, db.collection(collection).find(query, findOptions).toArray()];
|
|
2653
|
+
case 1:
|
|
2654
|
+
docs = _a.sent();
|
|
2655
|
+
return [2 /*return*/, { documents: docs, query: query }];
|
|
2656
|
+
case 2:
|
|
2657
|
+
error_5 = _a.sent();
|
|
2658
|
+
if (!isAssistantDateArithmeticArgumentError(error_5)) {
|
|
2659
|
+
throw error_5;
|
|
2660
|
+
}
|
|
2661
|
+
repaired = repairAssistantDateArithmeticInQuery(query);
|
|
2662
|
+
if (!repaired.changed || containsForbiddenMongoOperators(repaired.query)) {
|
|
2663
|
+
throw error_5;
|
|
2664
|
+
}
|
|
2665
|
+
return [4 /*yield*/, db.collection(collection).find(repaired.query, findOptions).toArray()];
|
|
2666
|
+
case 3:
|
|
2667
|
+
docs = _a.sent();
|
|
2668
|
+
fallbackMeta.dateArithmetic = {
|
|
2669
|
+
attempted: true,
|
|
2670
|
+
used: true,
|
|
2671
|
+
stage: stage,
|
|
2672
|
+
reason: 'normalized_date_operator_args'
|
|
2673
|
+
};
|
|
2674
|
+
return [2 /*return*/, {
|
|
2675
|
+
documents: docs,
|
|
2676
|
+
query: repaired.query
|
|
2677
|
+
}];
|
|
2678
|
+
case 4: return [2 /*return*/];
|
|
2679
|
+
}
|
|
2680
|
+
});
|
|
2681
|
+
}); };
|
|
2682
|
+
return [4 /*yield*/, runFindWithRepair(scopedQuery, 'initial')];
|
|
2639
2683
|
case 7:
|
|
2640
|
-
|
|
2641
|
-
|
|
2684
|
+
initialRead = _s.sent();
|
|
2685
|
+
documents = initialRead.documents;
|
|
2686
|
+
executedQuery = initialRead.query;
|
|
2642
2687
|
probeDocs = null;
|
|
2643
2688
|
if (!!documents.length) return [3 /*break*/, 9];
|
|
2644
2689
|
dateFallback = resolveQueryDateFieldFallback(scopedQuery);
|
|
2645
2690
|
if (!dateFallback) return [3 /*break*/, 9];
|
|
2646
2691
|
fallbackQuery = replaceQueryField(scopedQuery, dateFallback.from, dateFallback.to);
|
|
2647
2692
|
fallbackMeta.dateField = __assign(__assign({}, dateFallback), { attempted: true, used: false });
|
|
2648
|
-
return [4 /*yield*/,
|
|
2693
|
+
return [4 /*yield*/, runFindWithRepair(fallbackQuery, 'date_field_fallback')];
|
|
2649
2694
|
case 8:
|
|
2650
|
-
|
|
2695
|
+
fallbackRead = _s.sent();
|
|
2696
|
+
fallbackDocs = fallbackRead.documents;
|
|
2651
2697
|
if (fallbackDocs.length) {
|
|
2652
2698
|
documents = fallbackDocs;
|
|
2653
|
-
executedQuery =
|
|
2699
|
+
executedQuery = fallbackRead.query;
|
|
2654
2700
|
fallbackMeta.dateField.used = true;
|
|
2655
2701
|
}
|
|
2656
2702
|
_s.label = 9;
|
|
@@ -2663,12 +2709,13 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2663
2709
|
attempted: true,
|
|
2664
2710
|
used: false
|
|
2665
2711
|
};
|
|
2666
|
-
return [4 /*yield*/,
|
|
2712
|
+
return [4 /*yield*/, runFindWithRepair(expanded.query, 'date_fields_expanded')];
|
|
2667
2713
|
case 10:
|
|
2668
|
-
|
|
2714
|
+
fallbackRead = _s.sent();
|
|
2715
|
+
fallbackDocs = fallbackRead.documents;
|
|
2669
2716
|
if (fallbackDocs.length) {
|
|
2670
2717
|
documents = fallbackDocs;
|
|
2671
|
-
executedQuery =
|
|
2718
|
+
executedQuery = fallbackRead.query;
|
|
2672
2719
|
fallbackMeta.dateFieldsExpanded.used = true;
|
|
2673
2720
|
}
|
|
2674
2721
|
_s.label = 11;
|
|
@@ -2682,12 +2729,13 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2682
2729
|
attempted: true,
|
|
2683
2730
|
used: false
|
|
2684
2731
|
};
|
|
2685
|
-
return [4 /*yield*/,
|
|
2732
|
+
return [4 /*yield*/, runFindWithRepair(nameFallback.query, 'name_match')];
|
|
2686
2733
|
case 12:
|
|
2687
|
-
|
|
2734
|
+
fallbackRead = _s.sent();
|
|
2735
|
+
fallbackDocs = fallbackRead.documents;
|
|
2688
2736
|
if (fallbackDocs.length) {
|
|
2689
2737
|
documents = fallbackDocs;
|
|
2690
|
-
executedQuery =
|
|
2738
|
+
executedQuery = fallbackRead.query;
|
|
2691
2739
|
fallbackMeta.nameMatch.used = true;
|
|
2692
2740
|
}
|
|
2693
2741
|
_s.label = 13;
|
|
@@ -2721,12 +2769,13 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2721
2769
|
chemicalLookup = _s.sent();
|
|
2722
2770
|
if (!chemicalLookup) return [3 /*break*/, 18];
|
|
2723
2771
|
fallbackMeta.chemicalLookup = __assign(__assign({}, chemicalLookup.meta), { attempted: true, used: false });
|
|
2724
|
-
return [4 /*yield*/,
|
|
2772
|
+
return [4 /*yield*/, runFindWithRepair(chemicalLookup.query, 'chemical_lookup')];
|
|
2725
2773
|
case 17:
|
|
2726
|
-
|
|
2774
|
+
fallbackRead = _s.sent();
|
|
2775
|
+
fallbackDocs = fallbackRead.documents;
|
|
2727
2776
|
if (fallbackDocs.length) {
|
|
2728
2777
|
documents = fallbackDocs;
|
|
2729
|
-
executedQuery =
|
|
2778
|
+
executedQuery = fallbackRead.query;
|
|
2730
2779
|
fallbackMeta.chemicalLookup.used = true;
|
|
2731
2780
|
}
|
|
2732
2781
|
_s.label = 18;
|
|
@@ -2762,12 +2811,13 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2762
2811
|
var _b = __read(_a, 2), from = _b[0], to = _b[1];
|
|
2763
2812
|
return replaceFieldPathDeep(acc, from, to);
|
|
2764
2813
|
}, executedQuery);
|
|
2765
|
-
return [4 /*yield*/,
|
|
2814
|
+
return [4 /*yield*/, runFindWithRepair(rewrittenQuery, 'query_field_aliases')];
|
|
2766
2815
|
case 21:
|
|
2767
|
-
|
|
2816
|
+
fallbackRead = _s.sent();
|
|
2817
|
+
fallbackDocs = fallbackRead.documents;
|
|
2768
2818
|
if (fallbackDocs.length) {
|
|
2769
2819
|
documents = fallbackDocs;
|
|
2770
|
-
executedQuery =
|
|
2820
|
+
executedQuery = fallbackRead.query;
|
|
2771
2821
|
fallbackMeta.queryFieldAliases.used = true;
|
|
2772
2822
|
}
|
|
2773
2823
|
_s.label = 22;
|
|
@@ -2796,12 +2846,13 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2796
2846
|
used: false,
|
|
2797
2847
|
reason: 'active_fields_missing_in_collection'
|
|
2798
2848
|
};
|
|
2799
|
-
return [4 /*yield*/,
|
|
2849
|
+
return [4 /*yield*/, runFindWithRepair(activeFallback.query, 'active_status')];
|
|
2800
2850
|
case 25:
|
|
2801
|
-
|
|
2851
|
+
fallbackRead = _s.sent();
|
|
2852
|
+
fallbackDocs = fallbackRead.documents;
|
|
2802
2853
|
if (fallbackDocs.length) {
|
|
2803
2854
|
documents = fallbackDocs;
|
|
2804
|
-
executedQuery =
|
|
2855
|
+
executedQuery = fallbackRead.query;
|
|
2805
2856
|
fallbackMeta.activeStatus.used = true;
|
|
2806
2857
|
}
|
|
2807
2858
|
_s.label = 26;
|
|
@@ -2835,12 +2886,13 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2835
2886
|
idLookup = _s.sent();
|
|
2836
2887
|
if (!idLookup) return [3 /*break*/, 31];
|
|
2837
2888
|
fallbackMeta.idLookup = __assign(__assign({}, idLookup.meta), { attempted: true, used: false });
|
|
2838
|
-
return [4 /*yield*/,
|
|
2889
|
+
return [4 /*yield*/, runFindWithRepair(idLookup.query, 'id_lookup')];
|
|
2839
2890
|
case 30:
|
|
2840
|
-
|
|
2891
|
+
fallbackRead = _s.sent();
|
|
2892
|
+
fallbackDocs = fallbackRead.documents;
|
|
2841
2893
|
if (fallbackDocs.length) {
|
|
2842
2894
|
documents = fallbackDocs;
|
|
2843
|
-
executedQuery =
|
|
2895
|
+
executedQuery = fallbackRead.query;
|
|
2844
2896
|
fallbackMeta.idLookup.used = true;
|
|
2845
2897
|
}
|
|
2846
2898
|
_s.label = 31;
|
|
@@ -3238,7 +3290,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3238
3290
|
}
|
|
3239
3291
|
aggregateOptions = __assign(__assign({}, normalizedOptions.aggregateOptions), { readPreference: AI_ASSISTANT_READ_PREFERENCE });
|
|
3240
3292
|
runAggregateWithRepair = function (pipeline, stage) { return __awaiter(_this, void 0, void 0, function () {
|
|
3241
|
-
var docs,
|
|
3293
|
+
var docs, error_6, isDateRepair, isRankSortByRepair, repaired, docs;
|
|
3242
3294
|
return __generator(this, function (_a) {
|
|
3243
3295
|
switch (_a.label) {
|
|
3244
3296
|
case 0:
|
|
@@ -3250,17 +3302,17 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
3250
3302
|
docs = _a.sent();
|
|
3251
3303
|
return [2 /*return*/, { documents: docs, pipeline: pipeline }];
|
|
3252
3304
|
case 2:
|
|
3253
|
-
|
|
3254
|
-
isDateRepair = isAssistantDateArithmeticArgumentError(
|
|
3255
|
-
isRankSortByRepair = isAssistantRankSortByError(
|
|
3305
|
+
error_6 = _a.sent();
|
|
3306
|
+
isDateRepair = isAssistantDateArithmeticArgumentError(error_6);
|
|
3307
|
+
isRankSortByRepair = isAssistantRankSortByError(error_6);
|
|
3256
3308
|
if (!isDateRepair && !isRankSortByRepair) {
|
|
3257
|
-
throw
|
|
3309
|
+
throw error_6;
|
|
3258
3310
|
}
|
|
3259
3311
|
repaired = isDateRepair
|
|
3260
3312
|
? repairAssistantDateArithmeticInPipeline(pipeline)
|
|
3261
3313
|
: repairAssistantRankSortByInPipeline(pipeline);
|
|
3262
3314
|
if (!repaired.changed || containsForbiddenMongoOperators(repaired.pipeline)) {
|
|
3263
|
-
throw
|
|
3315
|
+
throw error_6;
|
|
3264
3316
|
}
|
|
3265
3317
|
return [4 /*yield*/, db.collection(collection)
|
|
3266
3318
|
.aggregate(repaired.pipeline, aggregateOptions)
|
|
@@ -6906,8 +6958,11 @@ function buildAssistantToolErrorMessage(error) {
|
|
|
6906
6958
|
if (normalized.includes('unrecognized argument to $datesubtract:') || normalized.includes('unrecognized argument to $dateadd:')) {
|
|
6907
6959
|
return 'The data query failed because of an invalid date expression argument. Please retry; date arithmetic arguments are now normalized automatically.';
|
|
6908
6960
|
}
|
|
6961
|
+
if (normalized.includes('no queryable collection could be resolved')) {
|
|
6962
|
+
return 'I tried all accessible related datasets but could not resolve a queryable source for this request.';
|
|
6963
|
+
}
|
|
6909
6964
|
if (normalized.includes('report builder bridge') && normalized.includes('not configured')) {
|
|
6910
|
-
return '
|
|
6965
|
+
return 'I tried all accessible related datasets but could not resolve a queryable source for this request.';
|
|
6911
6966
|
}
|
|
6912
6967
|
if (normalized.includes('collection is required')) {
|
|
6913
6968
|
return 'I need a valid collection to read from. Please specify which screen or dataset you want.';
|
|
@@ -6917,8 +6972,27 @@ function buildAssistantToolErrorMessage(error) {
|
|
|
6917
6972
|
}
|
|
6918
6973
|
return 'I couldn\'t run the requested data query.';
|
|
6919
6974
|
}
|
|
6975
|
+
function deriveAssistantCommandExecutionStatus(commandValue) {
|
|
6976
|
+
var command = normalizeOptionalString(commandValue).toLowerCase();
|
|
6977
|
+
if (!command) {
|
|
6978
|
+
return 'Running command';
|
|
6979
|
+
}
|
|
6980
|
+
if (/\b(rg|grep|ripgrep|ag|ack)\b/.test(command)) {
|
|
6981
|
+
return 'Searching files';
|
|
6982
|
+
}
|
|
6983
|
+
if (/\bfind\b/.test(command)) {
|
|
6984
|
+
return 'Finding files';
|
|
6985
|
+
}
|
|
6986
|
+
if (/\b(cat|sed|awk|head|tail|less|more)\b/.test(command)) {
|
|
6987
|
+
return 'Opening files';
|
|
6988
|
+
}
|
|
6989
|
+
if (/\b(ls|tree)\b/.test(command)) {
|
|
6990
|
+
return 'Scanning files';
|
|
6991
|
+
}
|
|
6992
|
+
return 'Running command';
|
|
6993
|
+
}
|
|
6920
6994
|
function deriveAssistantStreamStatus(event) {
|
|
6921
|
-
var _a;
|
|
6995
|
+
var _a, _b;
|
|
6922
6996
|
if (!event || !event.type) {
|
|
6923
6997
|
return null;
|
|
6924
6998
|
}
|
|
@@ -6937,10 +7011,10 @@ function deriveAssistantStreamStatus(event) {
|
|
|
6937
7011
|
return 'Planning';
|
|
6938
7012
|
}
|
|
6939
7013
|
if (itemType === 'command_execution') {
|
|
6940
|
-
return
|
|
7014
|
+
return deriveAssistantCommandExecutionStatus((_b = event === null || event === void 0 ? void 0 : event.item) === null || _b === void 0 ? void 0 : _b.command);
|
|
6941
7015
|
}
|
|
6942
7016
|
if (itemType === 'web_search') {
|
|
6943
|
-
return '
|
|
7017
|
+
return 'Searching references';
|
|
6944
7018
|
}
|
|
6945
7019
|
if (itemType === 'file_change') {
|
|
6946
7020
|
return 'Drafting response';
|
|
@@ -7007,7 +7081,7 @@ function updateAssistantProgress(messageId, progress) {
|
|
|
7007
7081
|
'metadata.progress': normalized,
|
|
7008
7082
|
updatedAt: new Date()
|
|
7009
7083
|
}
|
|
7010
|
-
})];
|
|
7084
|
+
}, undefined, false, false, true)];
|
|
7011
7085
|
case 2:
|
|
7012
7086
|
_b.sent();
|
|
7013
7087
|
return [3 /*break*/, 4];
|
|
@@ -9222,10 +9296,17 @@ function normalizeAssistantNowExprOperand(value) {
|
|
|
9222
9296
|
if (trimmed === '$$NOW') {
|
|
9223
9297
|
return '$$NOW';
|
|
9224
9298
|
}
|
|
9225
|
-
var
|
|
9299
|
+
var normalizedTokenRaw = trimmed.replace(/^\$+/, '').toUpperCase();
|
|
9300
|
+
var normalizedToken = normalizedTokenRaw.replace(/_(UTC|GMT|Z)$/, '');
|
|
9226
9301
|
if (normalizedToken === 'NOW_START_OF_MONTH') {
|
|
9227
9302
|
return createAssistantNowMonthStartExpr();
|
|
9228
9303
|
}
|
|
9304
|
+
if (normalizedToken === 'NOW_START_OF_WEEK' || normalizedToken === 'START_OF_WEEK') {
|
|
9305
|
+
return createAssistantNowWeekStartExpr();
|
|
9306
|
+
}
|
|
9307
|
+
if (normalizedToken === 'NOW_START_OF_DAY' || normalizedToken === 'START_OF_DAY' || normalizedToken === 'START_OF_TODAY') {
|
|
9308
|
+
return createAssistantNowDayStartExpr();
|
|
9309
|
+
}
|
|
9229
9310
|
if (normalizedToken === 'NOW_START_OF_LAST_MONTH') {
|
|
9230
9311
|
return {
|
|
9231
9312
|
$dateSubtract: {
|
|
@@ -9259,6 +9340,12 @@ function normalizeAssistantNowExprOperand(value) {
|
|
|
9259
9340
|
}
|
|
9260
9341
|
};
|
|
9261
9342
|
}
|
|
9343
|
+
if (normalizedToken === 'NOW_END_OF_WEEK' || normalizedToken === 'END_OF_WEEK') {
|
|
9344
|
+
return createAssistantNowWeekEndExpr();
|
|
9345
|
+
}
|
|
9346
|
+
if (normalizedToken === 'NOW_END_OF_DAY' || normalizedToken === 'END_OF_DAY' || normalizedToken === 'END_OF_TODAY') {
|
|
9347
|
+
return createAssistantNowDayEndExpr();
|
|
9348
|
+
}
|
|
9262
9349
|
var parsed = parseAssistantNowRelativeToken(trimmed);
|
|
9263
9350
|
if (!parsed) {
|
|
9264
9351
|
return value;
|
|
@@ -9604,7 +9691,19 @@ function isAssistantDateArithmeticArgumentError(error) {
|
|
|
9604
9691
|
|| message.includes('undefined variable: now_start_of_month')
|
|
9605
9692
|
|| message.includes('undefined variable: now_start_of_last_month')
|
|
9606
9693
|
|| message.includes('undefined variable: now_start_of_next_month')
|
|
9607
|
-
|| message.includes('undefined variable: now_end_of_month')
|
|
9694
|
+
|| message.includes('undefined variable: now_end_of_month')
|
|
9695
|
+
|| message.includes('undefined variable: start_of_week')
|
|
9696
|
+
|| message.includes('undefined variable: start_of_week_utc')
|
|
9697
|
+
|| message.includes('undefined variable: end_of_week')
|
|
9698
|
+
|| message.includes('undefined variable: end_of_week_utc')
|
|
9699
|
+
|| message.includes('undefined variable: start_of_day')
|
|
9700
|
+
|| message.includes('undefined variable: start_of_day_utc')
|
|
9701
|
+
|| message.includes('undefined variable: end_of_day')
|
|
9702
|
+
|| message.includes('undefined variable: end_of_day_utc')
|
|
9703
|
+
|| message.includes('undefined variable: start_of_today')
|
|
9704
|
+
|| message.includes('undefined variable: start_of_today_utc')
|
|
9705
|
+
|| message.includes('undefined variable: end_of_today')
|
|
9706
|
+
|| message.includes('undefined variable: end_of_today_utc');
|
|
9608
9707
|
}
|
|
9609
9708
|
function isAssistantRankSortByError(error) {
|
|
9610
9709
|
var message = normalizeOptionalString(error === null || error === void 0 ? void 0 : error.message).toLowerCase();
|
|
@@ -9632,6 +9731,16 @@ function repairAssistantDateArithmeticInPipeline(pipeline) {
|
|
|
9632
9731
|
changed: didAssistantValueChange(pipeline, repaired)
|
|
9633
9732
|
};
|
|
9634
9733
|
}
|
|
9734
|
+
function repairAssistantDateArithmeticInQuery(query) {
|
|
9735
|
+
var repairedRaw = normalizeAssistantNowExprPlaceholdersDeep(query);
|
|
9736
|
+
var repaired = (repairedRaw && typeof repairedRaw === 'object' && !Array.isArray(repairedRaw))
|
|
9737
|
+
? repairedRaw
|
|
9738
|
+
: query;
|
|
9739
|
+
return {
|
|
9740
|
+
query: repaired,
|
|
9741
|
+
changed: didAssistantValueChange(query, repaired)
|
|
9742
|
+
};
|
|
9743
|
+
}
|
|
9635
9744
|
function repairAssistantRankSortByInPipeline(pipeline) {
|
|
9636
9745
|
var repaired = Array.isArray(pipeline)
|
|
9637
9746
|
? pipeline.map(function (stage) {
|
|
@@ -9818,6 +9927,55 @@ function createAssistantNowMonthStartExpr() {
|
|
|
9818
9927
|
}
|
|
9819
9928
|
};
|
|
9820
9929
|
}
|
|
9930
|
+
function createAssistantNowWeekStartExpr() {
|
|
9931
|
+
return {
|
|
9932
|
+
$dateTrunc: {
|
|
9933
|
+
date: '$$NOW',
|
|
9934
|
+
unit: 'week',
|
|
9935
|
+
startOfWeek: 'monday',
|
|
9936
|
+
timezone: 'UTC'
|
|
9937
|
+
}
|
|
9938
|
+
};
|
|
9939
|
+
}
|
|
9940
|
+
function createAssistantNowDayStartExpr() {
|
|
9941
|
+
return {
|
|
9942
|
+
$dateTrunc: {
|
|
9943
|
+
date: '$$NOW',
|
|
9944
|
+
unit: 'day',
|
|
9945
|
+
timezone: 'UTC'
|
|
9946
|
+
}
|
|
9947
|
+
};
|
|
9948
|
+
}
|
|
9949
|
+
function createAssistantNowWeekEndExpr() {
|
|
9950
|
+
return {
|
|
9951
|
+
$dateSubtract: {
|
|
9952
|
+
startDate: {
|
|
9953
|
+
$dateAdd: {
|
|
9954
|
+
startDate: createAssistantNowWeekStartExpr(),
|
|
9955
|
+
unit: 'week',
|
|
9956
|
+
amount: 1
|
|
9957
|
+
}
|
|
9958
|
+
},
|
|
9959
|
+
unit: 'millisecond',
|
|
9960
|
+
amount: 1
|
|
9961
|
+
}
|
|
9962
|
+
};
|
|
9963
|
+
}
|
|
9964
|
+
function createAssistantNowDayEndExpr() {
|
|
9965
|
+
return {
|
|
9966
|
+
$dateSubtract: {
|
|
9967
|
+
startDate: {
|
|
9968
|
+
$dateAdd: {
|
|
9969
|
+
startDate: createAssistantNowDayStartExpr(),
|
|
9970
|
+
unit: 'day',
|
|
9971
|
+
amount: 1
|
|
9972
|
+
}
|
|
9973
|
+
},
|
|
9974
|
+
unit: 'millisecond',
|
|
9975
|
+
amount: 1
|
|
9976
|
+
}
|
|
9977
|
+
};
|
|
9978
|
+
}
|
|
9821
9979
|
function isAssistantNowMonthStartExpr(value) {
|
|
9822
9980
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
9823
9981
|
return false;
|
|
@@ -10121,6 +10279,26 @@ function normalizeAssistantSetWindowFieldsRankSortBy(setWindowFields) {
|
|
|
10121
10279
|
_a[primarySortKey] = sortBy[primarySortKey],
|
|
10122
10280
|
_a) });
|
|
10123
10281
|
}
|
|
10282
|
+
function normalizeAssistantSortTieBreakersForLimit(pipeline) {
|
|
10283
|
+
return pipeline.map(function (stage, index) {
|
|
10284
|
+
if (!stage || typeof stage !== 'object' || Array.isArray(stage)) {
|
|
10285
|
+
return stage;
|
|
10286
|
+
}
|
|
10287
|
+
var sort = stage.$sort;
|
|
10288
|
+
if (!sort || typeof sort !== 'object' || Array.isArray(sort)) {
|
|
10289
|
+
return stage;
|
|
10290
|
+
}
|
|
10291
|
+
var nextStage = pipeline[index + 1];
|
|
10292
|
+
if (!nextStage || typeof nextStage !== 'object' || Array.isArray(nextStage) || typeof nextStage.$limit !== 'number') {
|
|
10293
|
+
return stage;
|
|
10294
|
+
}
|
|
10295
|
+
var sortKeys = Object.keys(sort).filter(function (key) { return String(key || '').trim(); });
|
|
10296
|
+
if (sortKeys.length !== 1 || sortKeys[0] === '_id') {
|
|
10297
|
+
return stage;
|
|
10298
|
+
}
|
|
10299
|
+
return __assign(__assign({}, stage), { $sort: __assign(__assign({}, sort), { _id: 1 }) });
|
|
10300
|
+
});
|
|
10301
|
+
}
|
|
10124
10302
|
function normalizeAssistantAggregatePipeline(pipeline, collection) {
|
|
10125
10303
|
if (!Array.isArray(pipeline)) {
|
|
10126
10304
|
return [];
|
|
@@ -10147,7 +10325,8 @@ function normalizeAssistantAggregatePipeline(pipeline, collection) {
|
|
|
10147
10325
|
}
|
|
10148
10326
|
return normalizeAssistantNowExprPlaceholdersDeep(next);
|
|
10149
10327
|
});
|
|
10150
|
-
|
|
10328
|
+
var stableSortPipeline = normalizeAssistantSortTieBreakersForLimit(normalizedPipeline);
|
|
10329
|
+
return normalizeAssistantMonthlyCalendarWindowPipeline(stableSortPipeline);
|
|
10151
10330
|
}
|
|
10152
10331
|
function buildAssistantAggregatePipeline(query, pipeline) {
|
|
10153
10332
|
var _a;
|
|
@@ -12280,7 +12459,7 @@ function listAssistantReportBuilderCollectionsFromManager() {
|
|
|
12280
12459
|
}
|
|
12281
12460
|
function listAssistantCollections(db, dbName) {
|
|
12282
12461
|
return __awaiter(this, void 0, void 0, function () {
|
|
12283
|
-
var cacheKey, cached, now,
|
|
12462
|
+
var cacheKey, cached, now, seen, merged, pushName, collections, _a, names;
|
|
12284
12463
|
return __generator(this, function (_b) {
|
|
12285
12464
|
switch (_b.label) {
|
|
12286
12465
|
case 0:
|
|
@@ -12290,26 +12469,39 @@ function listAssistantCollections(db, dbName) {
|
|
|
12290
12469
|
if (cached && now - cached.updatedAt < AI_ASSISTANT_COLLECTION_CACHE_TTL_MS) {
|
|
12291
12470
|
return [2 /*return*/, cached.names];
|
|
12292
12471
|
}
|
|
12293
|
-
|
|
12294
|
-
|
|
12295
|
-
|
|
12296
|
-
|
|
12297
|
-
|
|
12472
|
+
seen = new Set();
|
|
12473
|
+
merged = [];
|
|
12474
|
+
pushName = function (name) {
|
|
12475
|
+
var normalized = normalizeOptionalString(name);
|
|
12476
|
+
if (!normalized || seen.has(normalized)) {
|
|
12477
|
+
return;
|
|
12478
|
+
}
|
|
12479
|
+
seen.add(normalized);
|
|
12480
|
+
merged.push(normalized);
|
|
12481
|
+
};
|
|
12482
|
+
listAssistantReportBuilderCollectionsFromManager().forEach(pushName);
|
|
12298
12483
|
_b.label = 1;
|
|
12299
12484
|
case 1:
|
|
12300
12485
|
_b.trys.push([1, 3, , 4]);
|
|
12301
12486
|
return [4 /*yield*/, db.listCollections({}, { nameOnly: true }).toArray()];
|
|
12302
12487
|
case 2:
|
|
12303
12488
|
collections = _b.sent();
|
|
12304
|
-
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12489
|
+
if (Array.isArray(collections)) {
|
|
12490
|
+
collections.forEach(function (entry) {
|
|
12491
|
+
pushName(normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.name));
|
|
12492
|
+
});
|
|
12493
|
+
}
|
|
12494
|
+
return [3 /*break*/, 4];
|
|
12309
12495
|
case 3:
|
|
12310
12496
|
_a = _b.sent();
|
|
12497
|
+
return [3 /*break*/, 4];
|
|
12498
|
+
case 4:
|
|
12499
|
+
names = merged.sort(function (a, b) { return a.localeCompare(b); });
|
|
12500
|
+
if (names.length) {
|
|
12501
|
+
AI_ASSISTANT_COLLECTION_CACHE.set(cacheKey, { names: names, updatedAt: now });
|
|
12502
|
+
return [2 /*return*/, names];
|
|
12503
|
+
}
|
|
12311
12504
|
return [2 /*return*/, (cached === null || cached === void 0 ? void 0 : cached.names) || []];
|
|
12312
|
-
case 4: return [2 /*return*/];
|
|
12313
12505
|
}
|
|
12314
12506
|
});
|
|
12315
12507
|
});
|
|
@@ -12793,6 +12985,16 @@ var AI_ASSISTANT_BRIDGE_COLLECTION_ALIASES = {
|
|
|
12793
12985
|
supporttickets: 'support-tickets',
|
|
12794
12986
|
ticket: 'support-tickets',
|
|
12795
12987
|
tickets: 'support-tickets',
|
|
12988
|
+
timeentry: 'time_entries',
|
|
12989
|
+
timeentries: 'time_entries',
|
|
12990
|
+
timeentrylog: 'time_entries',
|
|
12991
|
+
timeentrylogs: 'time_entries',
|
|
12992
|
+
timeentryrecord: 'time_entries',
|
|
12993
|
+
timeentryrecords: 'time_entries',
|
|
12994
|
+
timesheet: 'timesheets',
|
|
12995
|
+
timesheets: 'timesheets',
|
|
12996
|
+
payrollentry: 'payroll_entries',
|
|
12997
|
+
payrollentries: 'payroll_entries',
|
|
12796
12998
|
invoice: 'invoices',
|
|
12797
12999
|
client: 'customers',
|
|
12798
13000
|
clients: 'customers',
|
|
@@ -12809,7 +13011,20 @@ var AI_ASSISTANT_DIRECT_COLLECTION_FALLBACK_ALLOWLIST = new Set([
|
|
|
12809
13011
|
'duplicate-deliveries',
|
|
12810
13012
|
'third-party-drivers',
|
|
12811
13013
|
'customers',
|
|
12812
|
-
'support-tickets'
|
|
13014
|
+
'support-tickets',
|
|
13015
|
+
'time_entries',
|
|
13016
|
+
'time-entries',
|
|
13017
|
+
'timeentries',
|
|
13018
|
+
'timesheets',
|
|
13019
|
+
'timesheet-entries',
|
|
13020
|
+
'employee-time',
|
|
13021
|
+
'employee_time',
|
|
13022
|
+
'employee-time-entries',
|
|
13023
|
+
'employee_time_entries',
|
|
13024
|
+
'payroll_entries',
|
|
13025
|
+
'payroll-entries',
|
|
13026
|
+
'billing_entries',
|
|
13027
|
+
'billing-entries'
|
|
12813
13028
|
]);
|
|
12814
13029
|
var AI_ASSISTANT_ORDER_COLLECTION_FALLBACKS = [
|
|
12815
13030
|
'work-order-dynamics',
|
|
@@ -12835,6 +13050,21 @@ var AI_ASSISTANT_INVOICE_COLLECTION_FALLBACKS = [
|
|
|
12835
13050
|
'billings',
|
|
12836
13051
|
'sales-taxes'
|
|
12837
13052
|
];
|
|
13053
|
+
var AI_ASSISTANT_TIME_COLLECTION_FALLBACKS = [
|
|
13054
|
+
'time_entries',
|
|
13055
|
+
'time-entries',
|
|
13056
|
+
'timeentries',
|
|
13057
|
+
'timesheets',
|
|
13058
|
+
'timesheet-entries',
|
|
13059
|
+
'employee-time',
|
|
13060
|
+
'employee_time',
|
|
13061
|
+
'employee-time-entries',
|
|
13062
|
+
'employee_time_entries',
|
|
13063
|
+
'payroll_entries',
|
|
13064
|
+
'payroll-entries',
|
|
13065
|
+
'billing_entries',
|
|
13066
|
+
'billing-entries'
|
|
13067
|
+
];
|
|
12838
13068
|
function normalizeAssistantCollectionFamilyName(value) {
|
|
12839
13069
|
var normalized = normalizeOptionalString(value).toLowerCase();
|
|
12840
13070
|
if (!normalized) {
|
|
@@ -12900,6 +13130,13 @@ function resolveAssistantCrossCollectionFallbackCandidates(collection) {
|
|
|
12900
13130
|
else if (AI_ASSISTANT_INVOICE_COLLECTION_FALLBACKS.includes(normalized) || normalized.includes('invoice') || normalized.includes('billing')) {
|
|
12901
13131
|
candidates = AI_ASSISTANT_INVOICE_COLLECTION_FALLBACKS;
|
|
12902
13132
|
}
|
|
13133
|
+
else if (AI_ASSISTANT_TIME_COLLECTION_FALLBACKS.includes(normalized)
|
|
13134
|
+
|| normalized.includes('time')
|
|
13135
|
+
|| normalized.includes('sheet')
|
|
13136
|
+
|| normalized.includes('hour')
|
|
13137
|
+
|| normalized.includes('payroll')) {
|
|
13138
|
+
candidates = AI_ASSISTANT_TIME_COLLECTION_FALLBACKS;
|
|
13139
|
+
}
|
|
12903
13140
|
var deduped = [];
|
|
12904
13141
|
candidates.forEach(function (candidate) {
|
|
12905
13142
|
if (!candidate || deduped.includes(candidate)) {
|
|
@@ -12970,28 +13207,48 @@ function isAssistantDirectCollectionFallbackAllowed(collection) {
|
|
|
12970
13207
|
}
|
|
12971
13208
|
return AI_ASSISTANT_DIRECT_COLLECTION_FALLBACK_ALLOWLIST.has(normalized);
|
|
12972
13209
|
}
|
|
13210
|
+
function doesAssistantCollectionExistInDb(db, collection) {
|
|
13211
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
13212
|
+
var normalized, collections, _a;
|
|
13213
|
+
return __generator(this, function (_b) {
|
|
13214
|
+
switch (_b.label) {
|
|
13215
|
+
case 0:
|
|
13216
|
+
normalized = normalizeOptionalString(collection);
|
|
13217
|
+
if (!normalized || !db || typeof db.listCollections !== 'function') {
|
|
13218
|
+
return [2 /*return*/, false];
|
|
13219
|
+
}
|
|
13220
|
+
_b.label = 1;
|
|
13221
|
+
case 1:
|
|
13222
|
+
_b.trys.push([1, 3, , 4]);
|
|
13223
|
+
return [4 /*yield*/, db.listCollections({ name: normalized }, { nameOnly: true }).toArray()];
|
|
13224
|
+
case 2:
|
|
13225
|
+
collections = _b.sent();
|
|
13226
|
+
return [2 /*return*/, Array.isArray(collections)
|
|
13227
|
+
&& collections.some(function (entry) { return normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.name) === normalized; })];
|
|
13228
|
+
case 3:
|
|
13229
|
+
_a = _b.sent();
|
|
13230
|
+
return [2 /*return*/, false];
|
|
13231
|
+
case 4: return [2 /*return*/];
|
|
13232
|
+
}
|
|
13233
|
+
});
|
|
13234
|
+
});
|
|
13235
|
+
}
|
|
12973
13236
|
function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
12974
13237
|
return __awaiter(this, arguments, void 0, function (collection, db, dbName) {
|
|
12975
|
-
var normalized, alias, manager,
|
|
12976
|
-
var
|
|
12977
|
-
var
|
|
13238
|
+
var normalized, alias, manager, hasManager, candidates, pushCandidate, base, reportCandidate, candidates_4, candidates_4_1, candidate, model, resolved, resolvedName, resolvedModel, _a, candidates_5, candidates_5_1, candidate, e_30_1, candidates_6, candidates_6_1, candidate;
|
|
13239
|
+
var e_31, _b, e_30, _c, e_32, _d;
|
|
13240
|
+
var _e;
|
|
12978
13241
|
if (dbName === void 0) { dbName = ''; }
|
|
12979
|
-
return __generator(this, function (
|
|
12980
|
-
switch (
|
|
13242
|
+
return __generator(this, function (_f) {
|
|
13243
|
+
switch (_f.label) {
|
|
12981
13244
|
case 0:
|
|
12982
13245
|
normalized = normalizeOptionalString(collection);
|
|
12983
13246
|
if (!normalized) {
|
|
12984
13247
|
throw new Error('AI assistant report builder bridge: Collection is required.');
|
|
12985
13248
|
}
|
|
12986
13249
|
alias = resolveAssistantBridgeCollectionAlias(normalized);
|
|
12987
|
-
manager = (
|
|
12988
|
-
|
|
12989
|
-
fallback = alias || normalized;
|
|
12990
|
-
if (isAssistantDirectCollectionFallbackAllowed(fallback)) {
|
|
12991
|
-
return [2 /*return*/, __assign({ collection: fallback }, (fallback !== normalized ? { fallbackFrom: normalized } : {}))];
|
|
12992
|
-
}
|
|
12993
|
-
throw new Error('AI assistant report builder bridge: Mongo manager unavailable.');
|
|
12994
|
-
}
|
|
13250
|
+
manager = (_e = resolveio_server_app_1.ResolveIOServer.getMongoManager) === null || _e === void 0 ? void 0 : _e.call(resolveio_server_app_1.ResolveIOServer);
|
|
13251
|
+
hasManager = !!(manager && typeof manager.collection === 'function');
|
|
12995
13252
|
candidates = [];
|
|
12996
13253
|
pushCandidate = function (name) {
|
|
12997
13254
|
var value = normalizeOptionalString(name);
|
|
@@ -13012,64 +13269,99 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
13012
13269
|
if (reportCandidate && reportCandidate !== normalized) {
|
|
13013
13270
|
pushCandidate(reportCandidate);
|
|
13014
13271
|
}
|
|
13015
|
-
|
|
13016
|
-
|
|
13017
|
-
|
|
13018
|
-
|
|
13019
|
-
|
|
13020
|
-
|
|
13272
|
+
if (hasManager) {
|
|
13273
|
+
try {
|
|
13274
|
+
for (candidates_4 = __values(candidates), candidates_4_1 = candidates_4.next(); !candidates_4_1.done; candidates_4_1 = candidates_4.next()) {
|
|
13275
|
+
candidate = candidates_4_1.value;
|
|
13276
|
+
model = manager.collection(candidate);
|
|
13277
|
+
if (model === null || model === void 0 ? void 0 : model.useRB) {
|
|
13278
|
+
return [2 /*return*/, __assign({ collection: candidate }, (candidate !== normalized ? { fallbackFrom: normalized } : {}))];
|
|
13279
|
+
}
|
|
13021
13280
|
}
|
|
13022
13281
|
}
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
|
|
13027
|
-
|
|
13282
|
+
catch (e_31_1) { e_31 = { error: e_31_1 }; }
|
|
13283
|
+
finally {
|
|
13284
|
+
try {
|
|
13285
|
+
if (candidates_4_1 && !candidates_4_1.done && (_b = candidates_4.return)) _b.call(candidates_4);
|
|
13286
|
+
}
|
|
13287
|
+
finally { if (e_31) throw e_31.error; }
|
|
13028
13288
|
}
|
|
13029
|
-
finally { if (e_30) throw e_30.error; }
|
|
13030
13289
|
}
|
|
13031
13290
|
if (!(db && dbName)) return [3 /*break*/, 4];
|
|
13032
|
-
|
|
13291
|
+
_f.label = 1;
|
|
13033
13292
|
case 1:
|
|
13034
|
-
|
|
13293
|
+
_f.trys.push([1, 3, , 4]);
|
|
13035
13294
|
return [4 /*yield*/, resolveAssistantCollectionName(db, dbName, alias || normalized)];
|
|
13036
13295
|
case 2:
|
|
13037
|
-
resolved =
|
|
13296
|
+
resolved = _f.sent();
|
|
13038
13297
|
resolvedName = normalizeOptionalString(resolved === null || resolved === void 0 ? void 0 : resolved.name);
|
|
13039
13298
|
if (resolvedName) {
|
|
13040
13299
|
pushCandidate(resolvedName);
|
|
13041
|
-
|
|
13042
|
-
if ((
|
|
13300
|
+
resolvedModel = hasManager ? manager.collection(resolvedName) : null;
|
|
13301
|
+
if ((resolvedModel === null || resolvedModel === void 0 ? void 0 : resolvedModel.useRB) || isAssistantDirectCollectionFallbackAllowed(resolvedName)) {
|
|
13043
13302
|
return [2 /*return*/, __assign({ collection: resolvedName }, (resolvedName !== normalized ? { fallbackFrom: normalized } : {}))];
|
|
13044
13303
|
}
|
|
13045
13304
|
}
|
|
13046
13305
|
return [3 /*break*/, 4];
|
|
13047
13306
|
case 3:
|
|
13048
|
-
_a =
|
|
13307
|
+
_a = _f.sent();
|
|
13049
13308
|
return [3 /*break*/, 4];
|
|
13050
13309
|
case 4:
|
|
13310
|
+
if (!db) return [3 /*break*/, 12];
|
|
13311
|
+
_f.label = 5;
|
|
13312
|
+
case 5:
|
|
13313
|
+
_f.trys.push([5, 10, 11, 12]);
|
|
13314
|
+
candidates_5 = __values(candidates), candidates_5_1 = candidates_5.next();
|
|
13315
|
+
_f.label = 6;
|
|
13316
|
+
case 6:
|
|
13317
|
+
if (!!candidates_5_1.done) return [3 /*break*/, 9];
|
|
13318
|
+
candidate = candidates_5_1.value;
|
|
13319
|
+
if (AI_ASSISTANT_BLOCKED_COLLECTIONS.has(candidate)) {
|
|
13320
|
+
return [3 /*break*/, 8];
|
|
13321
|
+
}
|
|
13322
|
+
return [4 /*yield*/, doesAssistantCollectionExistInDb(db, candidate)];
|
|
13323
|
+
case 7:
|
|
13324
|
+
if (_f.sent()) {
|
|
13325
|
+
return [2 /*return*/, __assign({ collection: candidate }, (candidate !== normalized ? { fallbackFrom: normalized } : {}))];
|
|
13326
|
+
}
|
|
13327
|
+
_f.label = 8;
|
|
13328
|
+
case 8:
|
|
13329
|
+
candidates_5_1 = candidates_5.next();
|
|
13330
|
+
return [3 /*break*/, 6];
|
|
13331
|
+
case 9: return [3 /*break*/, 12];
|
|
13332
|
+
case 10:
|
|
13333
|
+
e_30_1 = _f.sent();
|
|
13334
|
+
e_30 = { error: e_30_1 };
|
|
13335
|
+
return [3 /*break*/, 12];
|
|
13336
|
+
case 11:
|
|
13051
13337
|
try {
|
|
13052
|
-
|
|
13053
|
-
|
|
13338
|
+
if (candidates_5_1 && !candidates_5_1.done && (_c = candidates_5.return)) _c.call(candidates_5);
|
|
13339
|
+
}
|
|
13340
|
+
finally { if (e_30) throw e_30.error; }
|
|
13341
|
+
return [7 /*endfinally*/];
|
|
13342
|
+
case 12:
|
|
13343
|
+
try {
|
|
13344
|
+
for (candidates_6 = __values(candidates), candidates_6_1 = candidates_6.next(); !candidates_6_1.done; candidates_6_1 = candidates_6.next()) {
|
|
13345
|
+
candidate = candidates_6_1.value;
|
|
13054
13346
|
if (isAssistantDirectCollectionFallbackAllowed(candidate)) {
|
|
13055
13347
|
return [2 /*return*/, __assign({ collection: candidate }, (candidate !== normalized ? { fallbackFrom: normalized } : {}))];
|
|
13056
13348
|
}
|
|
13057
13349
|
}
|
|
13058
13350
|
}
|
|
13059
|
-
catch (
|
|
13351
|
+
catch (e_32_1) { e_32 = { error: e_32_1 }; }
|
|
13060
13352
|
finally {
|
|
13061
13353
|
try {
|
|
13062
|
-
if (
|
|
13354
|
+
if (candidates_6_1 && !candidates_6_1.done && (_d = candidates_6.return)) _d.call(candidates_6);
|
|
13063
13355
|
}
|
|
13064
|
-
finally { if (
|
|
13356
|
+
finally { if (e_32) throw e_32.error; }
|
|
13065
13357
|
}
|
|
13066
|
-
throw new Error('AI assistant report builder bridge:
|
|
13358
|
+
throw new Error('AI assistant report builder bridge: No queryable collection could be resolved.');
|
|
13067
13359
|
}
|
|
13068
13360
|
});
|
|
13069
13361
|
});
|
|
13070
13362
|
}
|
|
13071
13363
|
function findQueryDateField(query) {
|
|
13072
|
-
var
|
|
13364
|
+
var e_33, _a, e_34, _b;
|
|
13073
13365
|
if (!query || typeof query !== 'object') {
|
|
13074
13366
|
return null;
|
|
13075
13367
|
}
|
|
@@ -13083,12 +13375,12 @@ function findQueryDateField(query) {
|
|
|
13083
13375
|
}
|
|
13084
13376
|
}
|
|
13085
13377
|
}
|
|
13086
|
-
catch (
|
|
13378
|
+
catch (e_33_1) { e_33 = { error: e_33_1 }; }
|
|
13087
13379
|
finally {
|
|
13088
13380
|
try {
|
|
13089
13381
|
if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
|
|
13090
13382
|
}
|
|
13091
|
-
finally { if (
|
|
13383
|
+
finally { if (e_33) throw e_33.error; }
|
|
13092
13384
|
}
|
|
13093
13385
|
return null;
|
|
13094
13386
|
}
|
|
@@ -13107,12 +13399,12 @@ function findQueryDateField(query) {
|
|
|
13107
13399
|
}
|
|
13108
13400
|
}
|
|
13109
13401
|
}
|
|
13110
|
-
catch (
|
|
13402
|
+
catch (e_34_1) { e_34 = { error: e_34_1 }; }
|
|
13111
13403
|
finally {
|
|
13112
13404
|
try {
|
|
13113
13405
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
13114
13406
|
}
|
|
13115
|
-
finally { if (
|
|
13407
|
+
finally { if (e_34) throw e_34.error; }
|
|
13116
13408
|
}
|
|
13117
13409
|
return null;
|
|
13118
13410
|
}
|
|
@@ -13361,7 +13653,7 @@ function resolveQueryDateFieldFallback(query) {
|
|
|
13361
13653
|
return { from: dateField, to: fallback };
|
|
13362
13654
|
}
|
|
13363
13655
|
function containsForbiddenMongoOperators(value) {
|
|
13364
|
-
var
|
|
13656
|
+
var e_35, _a;
|
|
13365
13657
|
if (!value || typeof value !== 'object') {
|
|
13366
13658
|
return false;
|
|
13367
13659
|
}
|
|
@@ -13380,12 +13672,12 @@ function containsForbiddenMongoOperators(value) {
|
|
|
13380
13672
|
}
|
|
13381
13673
|
}
|
|
13382
13674
|
}
|
|
13383
|
-
catch (
|
|
13675
|
+
catch (e_35_1) { e_35 = { error: e_35_1 }; }
|
|
13384
13676
|
finally {
|
|
13385
13677
|
try {
|
|
13386
13678
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
13387
13679
|
}
|
|
13388
|
-
finally { if (
|
|
13680
|
+
finally { if (e_35) throw e_35.error; }
|
|
13389
13681
|
}
|
|
13390
13682
|
return false;
|
|
13391
13683
|
}
|
|
@@ -13828,8 +14120,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
|
|
|
13828
14120
|
}
|
|
13829
14121
|
function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
13830
14122
|
return __awaiter(this, void 0, void 0, function () {
|
|
13831
|
-
var _a, _b, _c, _d, message, payload, status_1,
|
|
13832
|
-
var _e,
|
|
14123
|
+
var _a, _b, _c, _d, message, payload, status_1, e_36_1;
|
|
14124
|
+
var _e, e_36, _f, _g;
|
|
13833
14125
|
return __generator(this, function (_h) {
|
|
13834
14126
|
switch (_h.label) {
|
|
13835
14127
|
case 0:
|
|
@@ -13856,8 +14148,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
13856
14148
|
return [3 /*break*/, 1];
|
|
13857
14149
|
case 4: return [3 /*break*/, 11];
|
|
13858
14150
|
case 5:
|
|
13859
|
-
|
|
13860
|
-
|
|
14151
|
+
e_36_1 = _h.sent();
|
|
14152
|
+
e_36 = { error: e_36_1 };
|
|
13861
14153
|
return [3 /*break*/, 11];
|
|
13862
14154
|
case 6:
|
|
13863
14155
|
_h.trys.push([6, , 9, 10]);
|
|
@@ -13868,7 +14160,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
13868
14160
|
_h.label = 8;
|
|
13869
14161
|
case 8: return [3 /*break*/, 10];
|
|
13870
14162
|
case 9:
|
|
13871
|
-
if (
|
|
14163
|
+
if (e_36) throw e_36.error;
|
|
13872
14164
|
return [7 /*endfinally*/];
|
|
13873
14165
|
case 10: return [7 /*endfinally*/];
|
|
13874
14166
|
case 11: throw new CodexWorkerBootstrapError('Codex worker exited before completing.');
|
|
@@ -13878,7 +14170,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
13878
14170
|
}
|
|
13879
14171
|
function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler) {
|
|
13880
14172
|
return __awaiter(this, void 0, void 0, function () {
|
|
13881
|
-
var streamedOptions, codexClient, workerPath, codexClient,
|
|
14173
|
+
var streamedOptions, codexClient, workerPath, codexClient, error_7, codexClient;
|
|
13882
14174
|
return __generator(this, function (_a) {
|
|
13883
14175
|
switch (_a.label) {
|
|
13884
14176
|
case 0:
|
|
@@ -13899,11 +14191,11 @@ function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler)
|
|
|
13899
14191
|
return [4 /*yield*/, runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config, streamStatusHandler)];
|
|
13900
14192
|
case 6: return [2 /*return*/, _a.sent()];
|
|
13901
14193
|
case 7:
|
|
13902
|
-
|
|
13903
|
-
if (!(
|
|
13904
|
-
throw
|
|
14194
|
+
error_7 = _a.sent();
|
|
14195
|
+
if (!(error_7 instanceof CodexWorkerBootstrapError)) {
|
|
14196
|
+
throw error_7;
|
|
13905
14197
|
}
|
|
13906
|
-
console.error('Codex worker bootstrap failed, falling back to in-process run.',
|
|
14198
|
+
console.error('Codex worker bootstrap failed, falling back to in-process run.', error_7);
|
|
13907
14199
|
codexClient = getAssistantCodexClient(config);
|
|
13908
14200
|
return [4 /*yield*/, codexClient.run(prompt, streamedOptions)];
|
|
13909
14201
|
case 8: return [2 /*return*/, _a.sent()];
|
|
@@ -13941,7 +14233,7 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
13941
14233
|
timeoutMs = ((sanitizedOptions === null || sanitizedOptions === void 0 ? void 0 : sanitizedOptions.timeoutMs) || resolveCodexTimeoutMs()) + 15000;
|
|
13942
14234
|
timeoutController = new AbortController();
|
|
13943
14235
|
timeoutPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
13944
|
-
var
|
|
14236
|
+
var error_8;
|
|
13945
14237
|
return __generator(this, function (_a) {
|
|
13946
14238
|
switch (_a.label) {
|
|
13947
14239
|
case 0:
|
|
@@ -13951,11 +14243,11 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
|
|
|
13951
14243
|
_a.sent();
|
|
13952
14244
|
return [2 /*return*/, { type: 'timeout' }];
|
|
13953
14245
|
case 2:
|
|
13954
|
-
|
|
13955
|
-
if ((
|
|
14246
|
+
error_8 = _a.sent();
|
|
14247
|
+
if ((error_8 === null || error_8 === void 0 ? void 0 : error_8.name) === 'AbortError') {
|
|
13956
14248
|
return [2 /*return*/, { type: 'aborted' }];
|
|
13957
14249
|
}
|
|
13958
|
-
throw
|
|
14250
|
+
throw error_8;
|
|
13959
14251
|
case 3: return [2 /*return*/];
|
|
13960
14252
|
}
|
|
13961
14253
|
});
|
|
@@ -14131,145 +14423,26 @@ function directoryExists(target) {
|
|
|
14131
14423
|
});
|
|
14132
14424
|
});
|
|
14133
14425
|
}
|
|
14134
|
-
function
|
|
14135
|
-
if (!target || !root) {
|
|
14136
|
-
return false;
|
|
14137
|
-
}
|
|
14138
|
-
var relative = path.relative(root, target);
|
|
14139
|
-
if (!relative) {
|
|
14140
|
-
return true;
|
|
14141
|
-
}
|
|
14142
|
-
return !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
14143
|
-
}
|
|
14144
|
-
function isAssistantProjectRoot(candidate) {
|
|
14426
|
+
function resolveAssistantWorkspaceRoot() {
|
|
14145
14427
|
return __awaiter(this, void 0, void 0, function () {
|
|
14146
|
-
var
|
|
14428
|
+
var candidate, stat, _a;
|
|
14147
14429
|
return __generator(this, function (_b) {
|
|
14148
14430
|
switch (_b.label) {
|
|
14149
14431
|
case 0:
|
|
14150
|
-
|
|
14151
|
-
|
|
14152
|
-
|
|
14153
|
-
return [4 /*yield*/, directoryExists(candidate)];
|
|
14154
|
-
case 1:
|
|
14155
|
-
if (!(_b.sent())) {
|
|
14156
|
-
return [2 /*return*/, false];
|
|
14157
|
-
}
|
|
14158
|
-
serverPath = path.join(candidate, 'server');
|
|
14159
|
-
angularPath = path.join(candidate, 'angular');
|
|
14160
|
-
return [4 /*yield*/, directoryExists(serverPath)];
|
|
14161
|
-
case 2:
|
|
14162
|
-
_a = (_b.sent());
|
|
14163
|
-
if (!_a) return [3 /*break*/, 4];
|
|
14164
|
-
return [4 /*yield*/, directoryExists(angularPath)];
|
|
14165
|
-
case 3:
|
|
14166
|
-
_a = (_b.sent());
|
|
14167
|
-
_b.label = 4;
|
|
14168
|
-
case 4:
|
|
14169
|
-
if (_a) {
|
|
14170
|
-
return [2 /*return*/, true];
|
|
14171
|
-
}
|
|
14172
|
-
return [4 /*yield*/, directoryExists(serverPath)];
|
|
14173
|
-
case 5:
|
|
14174
|
-
hasServer = _b.sent();
|
|
14175
|
-
return [4 /*yield*/, pathExists(path.join(candidate, 'package.json'))];
|
|
14176
|
-
case 6:
|
|
14177
|
-
hasPackage = _b.sent();
|
|
14178
|
-
return [2 /*return*/, hasServer && hasPackage];
|
|
14179
|
-
}
|
|
14180
|
-
});
|
|
14181
|
-
});
|
|
14182
|
-
}
|
|
14183
|
-
function resolveAssistantProjectRoot(clientDir) {
|
|
14184
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
14185
|
-
var normalized, resolved, root, parts, i, candidate;
|
|
14186
|
-
return __generator(this, function (_a) {
|
|
14187
|
-
switch (_a.label) {
|
|
14188
|
-
case 0:
|
|
14189
|
-
normalized = normalizeOptionalString(clientDir);
|
|
14190
|
-
if (!normalized) {
|
|
14191
|
-
return [2 /*return*/, ''];
|
|
14192
|
-
}
|
|
14193
|
-
resolved = path.resolve(normalized);
|
|
14194
|
-
root = path.parse(resolved).root || path.sep;
|
|
14195
|
-
parts = resolved.slice(root.length).split(path.sep).filter(Boolean);
|
|
14196
|
-
if (!parts.length) {
|
|
14197
|
-
return [2 /*return*/, ''];
|
|
14198
|
-
}
|
|
14199
|
-
i = parts.length;
|
|
14200
|
-
_a.label = 1;
|
|
14201
|
-
case 1:
|
|
14202
|
-
if (!(i >= 1)) return [3 /*break*/, 4];
|
|
14203
|
-
candidate = path.join.apply(path, __spreadArray([root], __read(parts.slice(0, i)), false));
|
|
14204
|
-
return [4 /*yield*/, isAssistantProjectRoot(candidate)];
|
|
14205
|
-
case 2:
|
|
14206
|
-
if (_a.sent()) {
|
|
14207
|
-
return [2 /*return*/, candidate];
|
|
14208
|
-
}
|
|
14209
|
-
_a.label = 3;
|
|
14210
|
-
case 3:
|
|
14211
|
-
i -= 1;
|
|
14212
|
-
return [3 /*break*/, 1];
|
|
14213
|
-
case 4: return [2 /*return*/, ''];
|
|
14214
|
-
}
|
|
14215
|
-
});
|
|
14216
|
-
});
|
|
14217
|
-
}
|
|
14218
|
-
function resolveAssistantWorkspaceRoot() {
|
|
14219
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
14220
|
-
var config, configured, configuredRoot, clientDir, resolvedClientDir, projectRoot, _a, candidate, stat, _b;
|
|
14221
|
-
return __generator(this, function (_c) {
|
|
14222
|
-
switch (_c.label) {
|
|
14223
|
-
case 0:
|
|
14224
|
-
config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
14225
|
-
configured = normalizeOptionalString(config['AI_ASSISTANT_WORKSPACE_ROOT']
|
|
14226
|
-
|| process.env.AI_ASSISTANT_WORKSPACE_ROOT
|
|
14227
|
-
|| config['CODEX_WORKSPACE_ROOT']
|
|
14228
|
-
|| process.env.CODEX_WORKSPACE_ROOT);
|
|
14229
|
-
configuredRoot = configured ? path.resolve(configured) : '';
|
|
14230
|
-
clientDir = normalizeOptionalString(resolveio_server_app_1.ResolveIOServer.getClientDir());
|
|
14231
|
-
resolvedClientDir = clientDir ? path.resolve(clientDir) : '';
|
|
14232
|
-
if (!resolvedClientDir) return [3 /*break*/, 2];
|
|
14233
|
-
return [4 /*yield*/, resolveAssistantProjectRoot(resolvedClientDir)];
|
|
14432
|
+
candidate = '/var/app/current';
|
|
14433
|
+
stat = null;
|
|
14434
|
+
_b.label = 1;
|
|
14234
14435
|
case 1:
|
|
14235
|
-
|
|
14236
|
-
return [
|
|
14436
|
+
_b.trys.push([1, 3, , 4]);
|
|
14437
|
+
return [4 /*yield*/, fs_1.promises.stat(candidate)];
|
|
14237
14438
|
case 2:
|
|
14238
|
-
|
|
14239
|
-
|
|
14439
|
+
stat = _b.sent();
|
|
14440
|
+
return [3 /*break*/, 4];
|
|
14240
14441
|
case 3:
|
|
14241
|
-
|
|
14242
|
-
candidate = configuredRoot || projectRoot || resolvedClientDir || process.cwd();
|
|
14243
|
-
if (configuredRoot) {
|
|
14244
|
-
if (projectRoot && isAssistantPathUnderRoot(projectRoot, configuredRoot)) {
|
|
14245
|
-
candidate = projectRoot;
|
|
14246
|
-
}
|
|
14247
|
-
else if (projectRoot && isAssistantPathUnderRoot(configuredRoot, projectRoot)) {
|
|
14248
|
-
candidate = configuredRoot;
|
|
14249
|
-
}
|
|
14250
|
-
else {
|
|
14251
|
-
candidate = configuredRoot;
|
|
14252
|
-
}
|
|
14253
|
-
}
|
|
14254
|
-
else if (projectRoot) {
|
|
14255
|
-
candidate = projectRoot;
|
|
14256
|
-
}
|
|
14257
|
-
else if (resolvedClientDir) {
|
|
14258
|
-
candidate = resolvedClientDir;
|
|
14259
|
-
}
|
|
14442
|
+
_a = _b.sent();
|
|
14260
14443
|
stat = null;
|
|
14261
|
-
|
|
14444
|
+
return [3 /*break*/, 4];
|
|
14262
14445
|
case 4:
|
|
14263
|
-
_c.trys.push([4, 6, , 7]);
|
|
14264
|
-
return [4 /*yield*/, fs_1.promises.stat(candidate)];
|
|
14265
|
-
case 5:
|
|
14266
|
-
stat = _c.sent();
|
|
14267
|
-
return [3 /*break*/, 7];
|
|
14268
|
-
case 6:
|
|
14269
|
-
_b = _c.sent();
|
|
14270
|
-
stat = null;
|
|
14271
|
-
return [3 /*break*/, 7];
|
|
14272
|
-
case 7:
|
|
14273
14446
|
if (!stat || !stat.isDirectory()) {
|
|
14274
14447
|
throw new Error('AI assistant workspace root not found.');
|
|
14275
14448
|
}
|
|
@@ -14649,7 +14822,7 @@ var AI_ASSISTANT_BREAKDOWN_DIMENSION_STOPWORDS = new Set([
|
|
|
14649
14822
|
'by'
|
|
14650
14823
|
]);
|
|
14651
14824
|
function normalizeAssistantBreakdownDimension(value) {
|
|
14652
|
-
var
|
|
14825
|
+
var e_37, _a;
|
|
14653
14826
|
var normalized = normalizeOptionalString(value)
|
|
14654
14827
|
.toLowerCase()
|
|
14655
14828
|
.replace(/[^a-z0-9_\s-]+/g, ' ')
|
|
@@ -14681,12 +14854,12 @@ function normalizeAssistantBreakdownDimension(value) {
|
|
|
14681
14854
|
}
|
|
14682
14855
|
}
|
|
14683
14856
|
}
|
|
14684
|
-
catch (
|
|
14857
|
+
catch (e_37_1) { e_37 = { error: e_37_1 }; }
|
|
14685
14858
|
finally {
|
|
14686
14859
|
try {
|
|
14687
14860
|
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
|
|
14688
14861
|
}
|
|
14689
|
-
finally { if (
|
|
14862
|
+
finally { if (e_37) throw e_37.error; }
|
|
14690
14863
|
}
|
|
14691
14864
|
if (!kept.length) {
|
|
14692
14865
|
return '';
|
|
@@ -14873,7 +15046,7 @@ function resolveAssistantPlannerEnabled() {
|
|
|
14873
15046
|
return raw === undefined ? true : raw === true;
|
|
14874
15047
|
}
|
|
14875
15048
|
function resolveAssistantPlannerKnownRoutes() {
|
|
14876
|
-
var
|
|
15049
|
+
var e_38, _a;
|
|
14877
15050
|
var _b;
|
|
14878
15051
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
14879
15052
|
var unique = new Set();
|
|
@@ -14886,12 +15059,12 @@ function resolveAssistantPlannerKnownRoutes() {
|
|
|
14886
15059
|
}
|
|
14887
15060
|
}
|
|
14888
15061
|
}
|
|
14889
|
-
catch (
|
|
15062
|
+
catch (e_38_1) { e_38 = { error: e_38_1 }; }
|
|
14890
15063
|
finally {
|
|
14891
15064
|
try {
|
|
14892
15065
|
if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
|
|
14893
15066
|
}
|
|
14894
|
-
finally { if (
|
|
15067
|
+
finally { if (e_38) throw e_38.error; }
|
|
14895
15068
|
}
|
|
14896
15069
|
return Array.from(unique).slice(0, AI_ASSISTANT_PLANNER_MAX_ROUTES);
|
|
14897
15070
|
}
|
|
@@ -15134,7 +15307,7 @@ function normalizeRouteMatchKey(value) {
|
|
|
15134
15307
|
return normalizeRouteKey(value).toLowerCase();
|
|
15135
15308
|
}
|
|
15136
15309
|
function buildClientRouteIndex() {
|
|
15137
|
-
var
|
|
15310
|
+
var e_39, _a;
|
|
15138
15311
|
var _b;
|
|
15139
15312
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
15140
15313
|
var set = new Set();
|
|
@@ -15153,12 +15326,12 @@ function buildClientRouteIndex() {
|
|
|
15153
15326
|
}
|
|
15154
15327
|
}
|
|
15155
15328
|
}
|
|
15156
|
-
catch (
|
|
15329
|
+
catch (e_39_1) { e_39 = { error: e_39_1 }; }
|
|
15157
15330
|
finally {
|
|
15158
15331
|
try {
|
|
15159
15332
|
if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
|
|
15160
15333
|
}
|
|
15161
|
-
finally { if (
|
|
15334
|
+
finally { if (e_39) throw e_39.error; }
|
|
15162
15335
|
}
|
|
15163
15336
|
return { set: set, map: map, size: routes.length };
|
|
15164
15337
|
}
|
|
@@ -16189,7 +16362,7 @@ function sanitizeAssistantResponse(value) {
|
|
|
16189
16362
|
return normalizeAssistantRoutes(normalizedCurrency);
|
|
16190
16363
|
}
|
|
16191
16364
|
function evaluateAssistantGuardrails(message) {
|
|
16192
|
-
var
|
|
16365
|
+
var e_40, _a;
|
|
16193
16366
|
var normalized = String(message || '').toLowerCase();
|
|
16194
16367
|
var patterns = [
|
|
16195
16368
|
{
|
|
@@ -16235,12 +16408,12 @@ function evaluateAssistantGuardrails(message) {
|
|
|
16235
16408
|
}
|
|
16236
16409
|
}
|
|
16237
16410
|
}
|
|
16238
|
-
catch (
|
|
16411
|
+
catch (e_40_1) { e_40 = { error: e_40_1 }; }
|
|
16239
16412
|
finally {
|
|
16240
16413
|
try {
|
|
16241
16414
|
if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
|
|
16242
16415
|
}
|
|
16243
|
-
finally { if (
|
|
16416
|
+
finally { if (e_40) throw e_40.error; }
|
|
16244
16417
|
}
|
|
16245
16418
|
return null;
|
|
16246
16419
|
}
|
|
@@ -16355,7 +16528,7 @@ function tokenizeArithmeticExpression(expression) {
|
|
|
16355
16528
|
return tokens;
|
|
16356
16529
|
}
|
|
16357
16530
|
function evaluateArithmeticExpression(expression) {
|
|
16358
|
-
var
|
|
16531
|
+
var e_41, _a, e_42, _b;
|
|
16359
16532
|
var tokens = tokenizeArithmeticExpression(expression);
|
|
16360
16533
|
if (!tokens || !tokens.length) {
|
|
16361
16534
|
return null;
|
|
@@ -16412,12 +16585,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
16412
16585
|
prevToken = token;
|
|
16413
16586
|
}
|
|
16414
16587
|
}
|
|
16415
|
-
catch (
|
|
16588
|
+
catch (e_41_1) { e_41 = { error: e_41_1 }; }
|
|
16416
16589
|
finally {
|
|
16417
16590
|
try {
|
|
16418
16591
|
if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
|
|
16419
16592
|
}
|
|
16420
|
-
finally { if (
|
|
16593
|
+
finally { if (e_41) throw e_41.error; }
|
|
16421
16594
|
}
|
|
16422
16595
|
while (ops.length) {
|
|
16423
16596
|
var op = ops.pop();
|
|
@@ -16457,12 +16630,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
16457
16630
|
stack.push(Number(token));
|
|
16458
16631
|
}
|
|
16459
16632
|
}
|
|
16460
|
-
catch (
|
|
16633
|
+
catch (e_42_1) { e_42 = { error: e_42_1 }; }
|
|
16461
16634
|
finally {
|
|
16462
16635
|
try {
|
|
16463
16636
|
if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
|
|
16464
16637
|
}
|
|
16465
|
-
finally { if (
|
|
16638
|
+
finally { if (e_42) throw e_42.error; }
|
|
16466
16639
|
}
|
|
16467
16640
|
if (stack.length !== 1 || Number.isNaN(stack[0])) {
|
|
16468
16641
|
return null;
|
|
@@ -16646,8 +16819,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
|
|
|
16646
16819
|
}
|
|
16647
16820
|
function readAttachmentContents(attachments) {
|
|
16648
16821
|
return __awaiter(this, void 0, void 0, function () {
|
|
16649
|
-
var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a,
|
|
16650
|
-
var
|
|
16822
|
+
var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_43_1;
|
|
16823
|
+
var e_43, _b;
|
|
16651
16824
|
return __generator(this, function (_c) {
|
|
16652
16825
|
switch (_c.label) {
|
|
16653
16826
|
case 0:
|
|
@@ -16726,14 +16899,14 @@ function readAttachmentContents(attachments) {
|
|
|
16726
16899
|
return [3 /*break*/, 2];
|
|
16727
16900
|
case 10: return [3 /*break*/, 13];
|
|
16728
16901
|
case 11:
|
|
16729
|
-
|
|
16730
|
-
|
|
16902
|
+
e_43_1 = _c.sent();
|
|
16903
|
+
e_43 = { error: e_43_1 };
|
|
16731
16904
|
return [3 /*break*/, 13];
|
|
16732
16905
|
case 12:
|
|
16733
16906
|
try {
|
|
16734
16907
|
if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
|
|
16735
16908
|
}
|
|
16736
|
-
finally { if (
|
|
16909
|
+
finally { if (e_43) throw e_43.error; }
|
|
16737
16910
|
return [7 /*endfinally*/];
|
|
16738
16911
|
case 13: return [2 /*return*/, {
|
|
16739
16912
|
promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
|
|
@@ -16888,7 +17061,7 @@ function resolveAssistantDatabaseNameForSystemCollections() {
|
|
|
16888
17061
|
}
|
|
16889
17062
|
function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
16890
17063
|
return __awaiter(this, void 0, void 0, function () {
|
|
16891
|
-
var
|
|
17064
|
+
var error_9, dbName, _a;
|
|
16892
17065
|
return __generator(this, function (_b) {
|
|
16893
17066
|
switch (_b.label) {
|
|
16894
17067
|
case 0:
|
|
@@ -16898,14 +17071,14 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
16898
17071
|
_b.label = 1;
|
|
16899
17072
|
case 1:
|
|
16900
17073
|
_b.trys.push([1, 3, , 10]);
|
|
16901
|
-
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.updateOne({ _id: messageId }, { $set: setPayload })];
|
|
17074
|
+
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.updateOne({ _id: messageId }, { $set: setPayload }, undefined, false, false, true)];
|
|
16902
17075
|
case 2:
|
|
16903
17076
|
_b.sent();
|
|
16904
17077
|
return [2 /*return*/];
|
|
16905
17078
|
case 3:
|
|
16906
|
-
|
|
16907
|
-
if (!isAssistantTransactionCommittedError(
|
|
16908
|
-
throw
|
|
17079
|
+
error_9 = _b.sent();
|
|
17080
|
+
if (!isAssistantTransactionCommittedError(error_9)) {
|
|
17081
|
+
throw error_9;
|
|
16909
17082
|
}
|
|
16910
17083
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
16911
17084
|
_b.label = 4;
|
|
@@ -16924,7 +17097,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
16924
17097
|
case 7: return [4 /*yield*/, (0, promises_1.setTimeout)(15)];
|
|
16925
17098
|
case 8:
|
|
16926
17099
|
_b.sent();
|
|
16927
|
-
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.updateOne({ _id: messageId }, { $set: setPayload })];
|
|
17100
|
+
return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.updateOne({ _id: messageId }, { $set: setPayload }, undefined, false, false, true)];
|
|
16928
17101
|
case 9:
|
|
16929
17102
|
_b.sent();
|
|
16930
17103
|
return [3 /*break*/, 10];
|
|
@@ -16935,7 +17108,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
16935
17108
|
}
|
|
16936
17109
|
function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
16937
17110
|
return __awaiter(this, void 0, void 0, function () {
|
|
16938
|
-
var update,
|
|
17111
|
+
var update, error_10, dbName;
|
|
16939
17112
|
return __generator(this, function (_a) {
|
|
16940
17113
|
switch (_a.label) {
|
|
16941
17114
|
case 0:
|
|
@@ -16949,14 +17122,14 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
16949
17122
|
_a.label = 1;
|
|
16950
17123
|
case 1:
|
|
16951
17124
|
_a.trys.push([1, 3, , 5]);
|
|
16952
|
-
return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.updateOne({ _id: idConversation }, { $set: update })];
|
|
17125
|
+
return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.updateOne({ _id: idConversation }, { $set: update }, undefined, false, false, true)];
|
|
16953
17126
|
case 2:
|
|
16954
17127
|
_a.sent();
|
|
16955
17128
|
return [2 /*return*/];
|
|
16956
17129
|
case 3:
|
|
16957
|
-
|
|
16958
|
-
if (!isAssistantTransactionCommittedError(
|
|
16959
|
-
throw
|
|
17130
|
+
error_10 = _a.sent();
|
|
17131
|
+
if (!isAssistantTransactionCommittedError(error_10)) {
|
|
17132
|
+
throw error_10;
|
|
16960
17133
|
}
|
|
16961
17134
|
dbName = resolveAssistantDatabaseNameForSystemCollections();
|
|
16962
17135
|
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoConnection()
|
|
@@ -17057,7 +17230,7 @@ function estimateUsage(messages, responseText, model) {
|
|
|
17057
17230
|
};
|
|
17058
17231
|
}
|
|
17059
17232
|
function evaluateGuardrails(message) {
|
|
17060
|
-
var
|
|
17233
|
+
var e_44, _a;
|
|
17061
17234
|
var normalized = String(message || '').toLowerCase();
|
|
17062
17235
|
var patterns = [
|
|
17063
17236
|
{ pattern: /\b(source\s*code|full\s*code|entire\s*code|repo\s*dump|repository|git\s*clone)\b/i, reason: 'Code access is restricted.' },
|
|
@@ -17079,12 +17252,12 @@ function evaluateGuardrails(message) {
|
|
|
17079
17252
|
}
|
|
17080
17253
|
}
|
|
17081
17254
|
}
|
|
17082
|
-
catch (
|
|
17255
|
+
catch (e_44_1) { e_44 = { error: e_44_1 }; }
|
|
17083
17256
|
finally {
|
|
17084
17257
|
try {
|
|
17085
17258
|
if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
|
|
17086
17259
|
}
|
|
17087
|
-
finally { if (
|
|
17260
|
+
finally { if (e_44) throw e_44.error; }
|
|
17088
17261
|
}
|
|
17089
17262
|
return null;
|
|
17090
17263
|
}
|