@resolveio/server-lib 22.1.5 → 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.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/*".',
|
|
@@ -6951,8 +6958,11 @@ function buildAssistantToolErrorMessage(error) {
|
|
|
6951
6958
|
if (normalized.includes('unrecognized argument to $datesubtract:') || normalized.includes('unrecognized argument to $dateadd:')) {
|
|
6952
6959
|
return 'The data query failed because of an invalid date expression argument. Please retry; date arithmetic arguments are now normalized automatically.';
|
|
6953
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
|
+
}
|
|
6954
6964
|
if (normalized.includes('report builder bridge') && normalized.includes('not configured')) {
|
|
6955
|
-
return '
|
|
6965
|
+
return 'I tried all accessible related datasets but could not resolve a queryable source for this request.';
|
|
6956
6966
|
}
|
|
6957
6967
|
if (normalized.includes('collection is required')) {
|
|
6958
6968
|
return 'I need a valid collection to read from. Please specify which screen or dataset you want.';
|
|
@@ -6962,8 +6972,27 @@ function buildAssistantToolErrorMessage(error) {
|
|
|
6962
6972
|
}
|
|
6963
6973
|
return 'I couldn\'t run the requested data query.';
|
|
6964
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
|
+
}
|
|
6965
6994
|
function deriveAssistantStreamStatus(event) {
|
|
6966
|
-
var _a;
|
|
6995
|
+
var _a, _b;
|
|
6967
6996
|
if (!event || !event.type) {
|
|
6968
6997
|
return null;
|
|
6969
6998
|
}
|
|
@@ -6982,10 +7011,10 @@ function deriveAssistantStreamStatus(event) {
|
|
|
6982
7011
|
return 'Planning';
|
|
6983
7012
|
}
|
|
6984
7013
|
if (itemType === 'command_execution') {
|
|
6985
|
-
return
|
|
7014
|
+
return deriveAssistantCommandExecutionStatus((_b = event === null || event === void 0 ? void 0 : event.item) === null || _b === void 0 ? void 0 : _b.command);
|
|
6986
7015
|
}
|
|
6987
7016
|
if (itemType === 'web_search') {
|
|
6988
|
-
return '
|
|
7017
|
+
return 'Searching references';
|
|
6989
7018
|
}
|
|
6990
7019
|
if (itemType === 'file_change') {
|
|
6991
7020
|
return 'Drafting response';
|
|
@@ -7052,7 +7081,7 @@ function updateAssistantProgress(messageId, progress) {
|
|
|
7052
7081
|
'metadata.progress': normalized,
|
|
7053
7082
|
updatedAt: new Date()
|
|
7054
7083
|
}
|
|
7055
|
-
})];
|
|
7084
|
+
}, undefined, false, false, true)];
|
|
7056
7085
|
case 2:
|
|
7057
7086
|
_b.sent();
|
|
7058
7087
|
return [3 /*break*/, 4];
|
|
@@ -12430,7 +12459,7 @@ function listAssistantReportBuilderCollectionsFromManager() {
|
|
|
12430
12459
|
}
|
|
12431
12460
|
function listAssistantCollections(db, dbName) {
|
|
12432
12461
|
return __awaiter(this, void 0, void 0, function () {
|
|
12433
|
-
var cacheKey, cached, now,
|
|
12462
|
+
var cacheKey, cached, now, seen, merged, pushName, collections, _a, names;
|
|
12434
12463
|
return __generator(this, function (_b) {
|
|
12435
12464
|
switch (_b.label) {
|
|
12436
12465
|
case 0:
|
|
@@ -12440,26 +12469,39 @@ function listAssistantCollections(db, dbName) {
|
|
|
12440
12469
|
if (cached && now - cached.updatedAt < AI_ASSISTANT_COLLECTION_CACHE_TTL_MS) {
|
|
12441
12470
|
return [2 /*return*/, cached.names];
|
|
12442
12471
|
}
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
|
|
12446
|
-
|
|
12447
|
-
|
|
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);
|
|
12448
12483
|
_b.label = 1;
|
|
12449
12484
|
case 1:
|
|
12450
12485
|
_b.trys.push([1, 3, , 4]);
|
|
12451
12486
|
return [4 /*yield*/, db.listCollections({}, { nameOnly: true }).toArray()];
|
|
12452
12487
|
case 2:
|
|
12453
12488
|
collections = _b.sent();
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
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];
|
|
12459
12495
|
case 3:
|
|
12460
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
|
+
}
|
|
12461
12504
|
return [2 /*return*/, (cached === null || cached === void 0 ? void 0 : cached.names) || []];
|
|
12462
|
-
case 4: return [2 /*return*/];
|
|
12463
12505
|
}
|
|
12464
12506
|
});
|
|
12465
12507
|
});
|
|
@@ -12943,6 +12985,16 @@ var AI_ASSISTANT_BRIDGE_COLLECTION_ALIASES = {
|
|
|
12943
12985
|
supporttickets: 'support-tickets',
|
|
12944
12986
|
ticket: 'support-tickets',
|
|
12945
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',
|
|
12946
12998
|
invoice: 'invoices',
|
|
12947
12999
|
client: 'customers',
|
|
12948
13000
|
clients: 'customers',
|
|
@@ -12959,7 +13011,20 @@ var AI_ASSISTANT_DIRECT_COLLECTION_FALLBACK_ALLOWLIST = new Set([
|
|
|
12959
13011
|
'duplicate-deliveries',
|
|
12960
13012
|
'third-party-drivers',
|
|
12961
13013
|
'customers',
|
|
12962
|
-
'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'
|
|
12963
13028
|
]);
|
|
12964
13029
|
var AI_ASSISTANT_ORDER_COLLECTION_FALLBACKS = [
|
|
12965
13030
|
'work-order-dynamics',
|
|
@@ -12985,6 +13050,21 @@ var AI_ASSISTANT_INVOICE_COLLECTION_FALLBACKS = [
|
|
|
12985
13050
|
'billings',
|
|
12986
13051
|
'sales-taxes'
|
|
12987
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
|
+
];
|
|
12988
13068
|
function normalizeAssistantCollectionFamilyName(value) {
|
|
12989
13069
|
var normalized = normalizeOptionalString(value).toLowerCase();
|
|
12990
13070
|
if (!normalized) {
|
|
@@ -13050,6 +13130,13 @@ function resolveAssistantCrossCollectionFallbackCandidates(collection) {
|
|
|
13050
13130
|
else if (AI_ASSISTANT_INVOICE_COLLECTION_FALLBACKS.includes(normalized) || normalized.includes('invoice') || normalized.includes('billing')) {
|
|
13051
13131
|
candidates = AI_ASSISTANT_INVOICE_COLLECTION_FALLBACKS;
|
|
13052
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
|
+
}
|
|
13053
13140
|
var deduped = [];
|
|
13054
13141
|
candidates.forEach(function (candidate) {
|
|
13055
13142
|
if (!candidate || deduped.includes(candidate)) {
|
|
@@ -13120,28 +13207,48 @@ function isAssistantDirectCollectionFallbackAllowed(collection) {
|
|
|
13120
13207
|
}
|
|
13121
13208
|
return AI_ASSISTANT_DIRECT_COLLECTION_FALLBACK_ALLOWLIST.has(normalized);
|
|
13122
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
|
+
}
|
|
13123
13236
|
function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
13124
13237
|
return __awaiter(this, arguments, void 0, function (collection, db, dbName) {
|
|
13125
|
-
var normalized, alias, manager,
|
|
13126
|
-
var
|
|
13127
|
-
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;
|
|
13128
13241
|
if (dbName === void 0) { dbName = ''; }
|
|
13129
|
-
return __generator(this, function (
|
|
13130
|
-
switch (
|
|
13242
|
+
return __generator(this, function (_f) {
|
|
13243
|
+
switch (_f.label) {
|
|
13131
13244
|
case 0:
|
|
13132
13245
|
normalized = normalizeOptionalString(collection);
|
|
13133
13246
|
if (!normalized) {
|
|
13134
13247
|
throw new Error('AI assistant report builder bridge: Collection is required.');
|
|
13135
13248
|
}
|
|
13136
13249
|
alias = resolveAssistantBridgeCollectionAlias(normalized);
|
|
13137
|
-
manager = (
|
|
13138
|
-
|
|
13139
|
-
fallback = alias || normalized;
|
|
13140
|
-
if (isAssistantDirectCollectionFallbackAllowed(fallback)) {
|
|
13141
|
-
return [2 /*return*/, __assign({ collection: fallback }, (fallback !== normalized ? { fallbackFrom: normalized } : {}))];
|
|
13142
|
-
}
|
|
13143
|
-
throw new Error('AI assistant report builder bridge: Mongo manager unavailable.');
|
|
13144
|
-
}
|
|
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');
|
|
13145
13252
|
candidates = [];
|
|
13146
13253
|
pushCandidate = function (name) {
|
|
13147
13254
|
var value = normalizeOptionalString(name);
|
|
@@ -13162,64 +13269,99 @@ function resolveAssistantReportBuilderBridgeCollection(collection_1, db_1) {
|
|
|
13162
13269
|
if (reportCandidate && reportCandidate !== normalized) {
|
|
13163
13270
|
pushCandidate(reportCandidate);
|
|
13164
13271
|
}
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
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
|
+
}
|
|
13171
13280
|
}
|
|
13172
13281
|
}
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
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; }
|
|
13178
13288
|
}
|
|
13179
|
-
finally { if (e_30) throw e_30.error; }
|
|
13180
13289
|
}
|
|
13181
13290
|
if (!(db && dbName)) return [3 /*break*/, 4];
|
|
13182
|
-
|
|
13291
|
+
_f.label = 1;
|
|
13183
13292
|
case 1:
|
|
13184
|
-
|
|
13293
|
+
_f.trys.push([1, 3, , 4]);
|
|
13185
13294
|
return [4 /*yield*/, resolveAssistantCollectionName(db, dbName, alias || normalized)];
|
|
13186
13295
|
case 2:
|
|
13187
|
-
resolved =
|
|
13296
|
+
resolved = _f.sent();
|
|
13188
13297
|
resolvedName = normalizeOptionalString(resolved === null || resolved === void 0 ? void 0 : resolved.name);
|
|
13189
13298
|
if (resolvedName) {
|
|
13190
13299
|
pushCandidate(resolvedName);
|
|
13191
|
-
|
|
13192
|
-
if ((
|
|
13300
|
+
resolvedModel = hasManager ? manager.collection(resolvedName) : null;
|
|
13301
|
+
if ((resolvedModel === null || resolvedModel === void 0 ? void 0 : resolvedModel.useRB) || isAssistantDirectCollectionFallbackAllowed(resolvedName)) {
|
|
13193
13302
|
return [2 /*return*/, __assign({ collection: resolvedName }, (resolvedName !== normalized ? { fallbackFrom: normalized } : {}))];
|
|
13194
13303
|
}
|
|
13195
13304
|
}
|
|
13196
13305
|
return [3 /*break*/, 4];
|
|
13197
13306
|
case 3:
|
|
13198
|
-
_a =
|
|
13307
|
+
_a = _f.sent();
|
|
13199
13308
|
return [3 /*break*/, 4];
|
|
13200
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:
|
|
13201
13337
|
try {
|
|
13202
|
-
|
|
13203
|
-
|
|
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;
|
|
13204
13346
|
if (isAssistantDirectCollectionFallbackAllowed(candidate)) {
|
|
13205
13347
|
return [2 /*return*/, __assign({ collection: candidate }, (candidate !== normalized ? { fallbackFrom: normalized } : {}))];
|
|
13206
13348
|
}
|
|
13207
13349
|
}
|
|
13208
13350
|
}
|
|
13209
|
-
catch (
|
|
13351
|
+
catch (e_32_1) { e_32 = { error: e_32_1 }; }
|
|
13210
13352
|
finally {
|
|
13211
13353
|
try {
|
|
13212
|
-
if (
|
|
13354
|
+
if (candidates_6_1 && !candidates_6_1.done && (_d = candidates_6.return)) _d.call(candidates_6);
|
|
13213
13355
|
}
|
|
13214
|
-
finally { if (
|
|
13356
|
+
finally { if (e_32) throw e_32.error; }
|
|
13215
13357
|
}
|
|
13216
|
-
throw new Error('AI assistant report builder bridge:
|
|
13358
|
+
throw new Error('AI assistant report builder bridge: No queryable collection could be resolved.');
|
|
13217
13359
|
}
|
|
13218
13360
|
});
|
|
13219
13361
|
});
|
|
13220
13362
|
}
|
|
13221
13363
|
function findQueryDateField(query) {
|
|
13222
|
-
var
|
|
13364
|
+
var e_33, _a, e_34, _b;
|
|
13223
13365
|
if (!query || typeof query !== 'object') {
|
|
13224
13366
|
return null;
|
|
13225
13367
|
}
|
|
@@ -13233,12 +13375,12 @@ function findQueryDateField(query) {
|
|
|
13233
13375
|
}
|
|
13234
13376
|
}
|
|
13235
13377
|
}
|
|
13236
|
-
catch (
|
|
13378
|
+
catch (e_33_1) { e_33 = { error: e_33_1 }; }
|
|
13237
13379
|
finally {
|
|
13238
13380
|
try {
|
|
13239
13381
|
if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
|
|
13240
13382
|
}
|
|
13241
|
-
finally { if (
|
|
13383
|
+
finally { if (e_33) throw e_33.error; }
|
|
13242
13384
|
}
|
|
13243
13385
|
return null;
|
|
13244
13386
|
}
|
|
@@ -13257,12 +13399,12 @@ function findQueryDateField(query) {
|
|
|
13257
13399
|
}
|
|
13258
13400
|
}
|
|
13259
13401
|
}
|
|
13260
|
-
catch (
|
|
13402
|
+
catch (e_34_1) { e_34 = { error: e_34_1 }; }
|
|
13261
13403
|
finally {
|
|
13262
13404
|
try {
|
|
13263
13405
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
13264
13406
|
}
|
|
13265
|
-
finally { if (
|
|
13407
|
+
finally { if (e_34) throw e_34.error; }
|
|
13266
13408
|
}
|
|
13267
13409
|
return null;
|
|
13268
13410
|
}
|
|
@@ -13511,7 +13653,7 @@ function resolveQueryDateFieldFallback(query) {
|
|
|
13511
13653
|
return { from: dateField, to: fallback };
|
|
13512
13654
|
}
|
|
13513
13655
|
function containsForbiddenMongoOperators(value) {
|
|
13514
|
-
var
|
|
13656
|
+
var e_35, _a;
|
|
13515
13657
|
if (!value || typeof value !== 'object') {
|
|
13516
13658
|
return false;
|
|
13517
13659
|
}
|
|
@@ -13530,12 +13672,12 @@ function containsForbiddenMongoOperators(value) {
|
|
|
13530
13672
|
}
|
|
13531
13673
|
}
|
|
13532
13674
|
}
|
|
13533
|
-
catch (
|
|
13675
|
+
catch (e_35_1) { e_35 = { error: e_35_1 }; }
|
|
13534
13676
|
finally {
|
|
13535
13677
|
try {
|
|
13536
13678
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
13537
13679
|
}
|
|
13538
|
-
finally { if (
|
|
13680
|
+
finally { if (e_35) throw e_35.error; }
|
|
13539
13681
|
}
|
|
13540
13682
|
return false;
|
|
13541
13683
|
}
|
|
@@ -13978,8 +14120,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
|
|
|
13978
14120
|
}
|
|
13979
14121
|
function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
13980
14122
|
return __awaiter(this, void 0, void 0, function () {
|
|
13981
|
-
var _a, _b, _c, _d, message, payload, status_1,
|
|
13982
|
-
var _e,
|
|
14123
|
+
var _a, _b, _c, _d, message, payload, status_1, e_36_1;
|
|
14124
|
+
var _e, e_36, _f, _g;
|
|
13983
14125
|
return __generator(this, function (_h) {
|
|
13984
14126
|
switch (_h.label) {
|
|
13985
14127
|
case 0:
|
|
@@ -14006,8 +14148,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
14006
14148
|
return [3 /*break*/, 1];
|
|
14007
14149
|
case 4: return [3 /*break*/, 11];
|
|
14008
14150
|
case 5:
|
|
14009
|
-
|
|
14010
|
-
|
|
14151
|
+
e_36_1 = _h.sent();
|
|
14152
|
+
e_36 = { error: e_36_1 };
|
|
14011
14153
|
return [3 /*break*/, 11];
|
|
14012
14154
|
case 6:
|
|
14013
14155
|
_h.trys.push([6, , 9, 10]);
|
|
@@ -14018,7 +14160,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
14018
14160
|
_h.label = 8;
|
|
14019
14161
|
case 8: return [3 /*break*/, 10];
|
|
14020
14162
|
case 9:
|
|
14021
|
-
if (
|
|
14163
|
+
if (e_36) throw e_36.error;
|
|
14022
14164
|
return [7 /*endfinally*/];
|
|
14023
14165
|
case 10: return [7 /*endfinally*/];
|
|
14024
14166
|
case 11: throw new CodexWorkerBootstrapError('Codex worker exited before completing.');
|
|
@@ -14680,7 +14822,7 @@ var AI_ASSISTANT_BREAKDOWN_DIMENSION_STOPWORDS = new Set([
|
|
|
14680
14822
|
'by'
|
|
14681
14823
|
]);
|
|
14682
14824
|
function normalizeAssistantBreakdownDimension(value) {
|
|
14683
|
-
var
|
|
14825
|
+
var e_37, _a;
|
|
14684
14826
|
var normalized = normalizeOptionalString(value)
|
|
14685
14827
|
.toLowerCase()
|
|
14686
14828
|
.replace(/[^a-z0-9_\s-]+/g, ' ')
|
|
@@ -14712,12 +14854,12 @@ function normalizeAssistantBreakdownDimension(value) {
|
|
|
14712
14854
|
}
|
|
14713
14855
|
}
|
|
14714
14856
|
}
|
|
14715
|
-
catch (
|
|
14857
|
+
catch (e_37_1) { e_37 = { error: e_37_1 }; }
|
|
14716
14858
|
finally {
|
|
14717
14859
|
try {
|
|
14718
14860
|
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
|
|
14719
14861
|
}
|
|
14720
|
-
finally { if (
|
|
14862
|
+
finally { if (e_37) throw e_37.error; }
|
|
14721
14863
|
}
|
|
14722
14864
|
if (!kept.length) {
|
|
14723
14865
|
return '';
|
|
@@ -14904,7 +15046,7 @@ function resolveAssistantPlannerEnabled() {
|
|
|
14904
15046
|
return raw === undefined ? true : raw === true;
|
|
14905
15047
|
}
|
|
14906
15048
|
function resolveAssistantPlannerKnownRoutes() {
|
|
14907
|
-
var
|
|
15049
|
+
var e_38, _a;
|
|
14908
15050
|
var _b;
|
|
14909
15051
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
14910
15052
|
var unique = new Set();
|
|
@@ -14917,12 +15059,12 @@ function resolveAssistantPlannerKnownRoutes() {
|
|
|
14917
15059
|
}
|
|
14918
15060
|
}
|
|
14919
15061
|
}
|
|
14920
|
-
catch (
|
|
15062
|
+
catch (e_38_1) { e_38 = { error: e_38_1 }; }
|
|
14921
15063
|
finally {
|
|
14922
15064
|
try {
|
|
14923
15065
|
if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
|
|
14924
15066
|
}
|
|
14925
|
-
finally { if (
|
|
15067
|
+
finally { if (e_38) throw e_38.error; }
|
|
14926
15068
|
}
|
|
14927
15069
|
return Array.from(unique).slice(0, AI_ASSISTANT_PLANNER_MAX_ROUTES);
|
|
14928
15070
|
}
|
|
@@ -15165,7 +15307,7 @@ function normalizeRouteMatchKey(value) {
|
|
|
15165
15307
|
return normalizeRouteKey(value).toLowerCase();
|
|
15166
15308
|
}
|
|
15167
15309
|
function buildClientRouteIndex() {
|
|
15168
|
-
var
|
|
15310
|
+
var e_39, _a;
|
|
15169
15311
|
var _b;
|
|
15170
15312
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
15171
15313
|
var set = new Set();
|
|
@@ -15184,12 +15326,12 @@ function buildClientRouteIndex() {
|
|
|
15184
15326
|
}
|
|
15185
15327
|
}
|
|
15186
15328
|
}
|
|
15187
|
-
catch (
|
|
15329
|
+
catch (e_39_1) { e_39 = { error: e_39_1 }; }
|
|
15188
15330
|
finally {
|
|
15189
15331
|
try {
|
|
15190
15332
|
if (routes_2_1 && !routes_2_1.done && (_a = routes_2.return)) _a.call(routes_2);
|
|
15191
15333
|
}
|
|
15192
|
-
finally { if (
|
|
15334
|
+
finally { if (e_39) throw e_39.error; }
|
|
15193
15335
|
}
|
|
15194
15336
|
return { set: set, map: map, size: routes.length };
|
|
15195
15337
|
}
|
|
@@ -16220,7 +16362,7 @@ function sanitizeAssistantResponse(value) {
|
|
|
16220
16362
|
return normalizeAssistantRoutes(normalizedCurrency);
|
|
16221
16363
|
}
|
|
16222
16364
|
function evaluateAssistantGuardrails(message) {
|
|
16223
|
-
var
|
|
16365
|
+
var e_40, _a;
|
|
16224
16366
|
var normalized = String(message || '').toLowerCase();
|
|
16225
16367
|
var patterns = [
|
|
16226
16368
|
{
|
|
@@ -16266,12 +16408,12 @@ function evaluateAssistantGuardrails(message) {
|
|
|
16266
16408
|
}
|
|
16267
16409
|
}
|
|
16268
16410
|
}
|
|
16269
|
-
catch (
|
|
16411
|
+
catch (e_40_1) { e_40 = { error: e_40_1 }; }
|
|
16270
16412
|
finally {
|
|
16271
16413
|
try {
|
|
16272
16414
|
if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
|
|
16273
16415
|
}
|
|
16274
|
-
finally { if (
|
|
16416
|
+
finally { if (e_40) throw e_40.error; }
|
|
16275
16417
|
}
|
|
16276
16418
|
return null;
|
|
16277
16419
|
}
|
|
@@ -16386,7 +16528,7 @@ function tokenizeArithmeticExpression(expression) {
|
|
|
16386
16528
|
return tokens;
|
|
16387
16529
|
}
|
|
16388
16530
|
function evaluateArithmeticExpression(expression) {
|
|
16389
|
-
var
|
|
16531
|
+
var e_41, _a, e_42, _b;
|
|
16390
16532
|
var tokens = tokenizeArithmeticExpression(expression);
|
|
16391
16533
|
if (!tokens || !tokens.length) {
|
|
16392
16534
|
return null;
|
|
@@ -16443,12 +16585,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
16443
16585
|
prevToken = token;
|
|
16444
16586
|
}
|
|
16445
16587
|
}
|
|
16446
|
-
catch (
|
|
16588
|
+
catch (e_41_1) { e_41 = { error: e_41_1 }; }
|
|
16447
16589
|
finally {
|
|
16448
16590
|
try {
|
|
16449
16591
|
if (tokens_2_1 && !tokens_2_1.done && (_a = tokens_2.return)) _a.call(tokens_2);
|
|
16450
16592
|
}
|
|
16451
|
-
finally { if (
|
|
16593
|
+
finally { if (e_41) throw e_41.error; }
|
|
16452
16594
|
}
|
|
16453
16595
|
while (ops.length) {
|
|
16454
16596
|
var op = ops.pop();
|
|
@@ -16488,12 +16630,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
16488
16630
|
stack.push(Number(token));
|
|
16489
16631
|
}
|
|
16490
16632
|
}
|
|
16491
|
-
catch (
|
|
16633
|
+
catch (e_42_1) { e_42 = { error: e_42_1 }; }
|
|
16492
16634
|
finally {
|
|
16493
16635
|
try {
|
|
16494
16636
|
if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
|
|
16495
16637
|
}
|
|
16496
|
-
finally { if (
|
|
16638
|
+
finally { if (e_42) throw e_42.error; }
|
|
16497
16639
|
}
|
|
16498
16640
|
if (stack.length !== 1 || Number.isNaN(stack[0])) {
|
|
16499
16641
|
return null;
|
|
@@ -16677,8 +16819,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
|
|
|
16677
16819
|
}
|
|
16678
16820
|
function readAttachmentContents(attachments) {
|
|
16679
16821
|
return __awaiter(this, void 0, void 0, function () {
|
|
16680
|
-
var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a,
|
|
16681
|
-
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;
|
|
16682
16824
|
return __generator(this, function (_c) {
|
|
16683
16825
|
switch (_c.label) {
|
|
16684
16826
|
case 0:
|
|
@@ -16757,14 +16899,14 @@ function readAttachmentContents(attachments) {
|
|
|
16757
16899
|
return [3 /*break*/, 2];
|
|
16758
16900
|
case 10: return [3 /*break*/, 13];
|
|
16759
16901
|
case 11:
|
|
16760
|
-
|
|
16761
|
-
|
|
16902
|
+
e_43_1 = _c.sent();
|
|
16903
|
+
e_43 = { error: e_43_1 };
|
|
16762
16904
|
return [3 /*break*/, 13];
|
|
16763
16905
|
case 12:
|
|
16764
16906
|
try {
|
|
16765
16907
|
if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
|
|
16766
16908
|
}
|
|
16767
|
-
finally { if (
|
|
16909
|
+
finally { if (e_43) throw e_43.error; }
|
|
16768
16910
|
return [7 /*endfinally*/];
|
|
16769
16911
|
case 13: return [2 /*return*/, {
|
|
16770
16912
|
promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
|
|
@@ -16929,7 +17071,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
16929
17071
|
_b.label = 1;
|
|
16930
17072
|
case 1:
|
|
16931
17073
|
_b.trys.push([1, 3, , 10]);
|
|
16932
|
-
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)];
|
|
16933
17075
|
case 2:
|
|
16934
17076
|
_b.sent();
|
|
16935
17077
|
return [2 /*return*/];
|
|
@@ -16955,7 +17097,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
|
|
|
16955
17097
|
case 7: return [4 /*yield*/, (0, promises_1.setTimeout)(15)];
|
|
16956
17098
|
case 8:
|
|
16957
17099
|
_b.sent();
|
|
16958
|
-
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)];
|
|
16959
17101
|
case 9:
|
|
16960
17102
|
_b.sent();
|
|
16961
17103
|
return [3 /*break*/, 10];
|
|
@@ -16980,7 +17122,7 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
|
|
|
16980
17122
|
_a.label = 1;
|
|
16981
17123
|
case 1:
|
|
16982
17124
|
_a.trys.push([1, 3, , 5]);
|
|
16983
|
-
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)];
|
|
16984
17126
|
case 2:
|
|
16985
17127
|
_a.sent();
|
|
16986
17128
|
return [2 /*return*/];
|
|
@@ -17088,7 +17230,7 @@ function estimateUsage(messages, responseText, model) {
|
|
|
17088
17230
|
};
|
|
17089
17231
|
}
|
|
17090
17232
|
function evaluateGuardrails(message) {
|
|
17091
|
-
var
|
|
17233
|
+
var e_44, _a;
|
|
17092
17234
|
var normalized = String(message || '').toLowerCase();
|
|
17093
17235
|
var patterns = [
|
|
17094
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.' },
|
|
@@ -17110,12 +17252,12 @@ function evaluateGuardrails(message) {
|
|
|
17110
17252
|
}
|
|
17111
17253
|
}
|
|
17112
17254
|
}
|
|
17113
|
-
catch (
|
|
17255
|
+
catch (e_44_1) { e_44 = { error: e_44_1 }; }
|
|
17114
17256
|
finally {
|
|
17115
17257
|
try {
|
|
17116
17258
|
if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
|
|
17117
17259
|
}
|
|
17118
|
-
finally { if (
|
|
17260
|
+
finally { if (e_44) throw e_44.error; }
|
|
17119
17261
|
}
|
|
17120
17262
|
return null;
|
|
17121
17263
|
}
|