@resolveio/server-lib 20.15.4 → 20.15.5

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.
@@ -144,6 +144,7 @@ var AI_ASSISTANT_DISPLAY_PREVIEW_MAX_ROWS = 20;
144
144
  var AI_ASSISTANT_DISPLAY_STRING_LIMIT = 160;
145
145
  var AI_ASSISTANT_PROGRESS_PLACEHOLDER = 'Thinking...';
146
146
  var AI_ASSISTANT_PROGRESS_TICK_MS = 5000;
147
+ var AI_ASSISTANT_READ_PREFERENCE = 'secondary';
147
148
  var AI_ASSISTANT_PROGRESS_TICKS = [
148
149
  'Drafting response'
149
150
  ];
@@ -307,6 +308,7 @@ var AI_ASSISTANT_SYSTEM_PROMPT = [
307
308
  '- Only request data when the user has permission for that module; invoice data requires invoice view access.',
308
309
  '- If the user lacks permission, answer without data and explain how to view it in the app or request access.',
309
310
  '- For simple counts or time-range totals, use MONGO_READ (includeTotal). For breakdowns, rankings, or sums grouped by a field, use MONGO_AGG.',
311
+ '- For completion metrics (ex: "completed per day"), filter by completed status when applicable and use completion date fields; if completion dates are missing, fall back to createdAt/date_created and note the fallback.',
310
312
  '- Before issuing MONGO_READ or MONGO_AGG, verify the collection name and key fields by checking collection/model definitions in the current app (look for "collectionName:" and date fields like date_created/date_completed/createdAt). Do not invent collection names.',
311
313
  '- For creation-date questions when both date_created and createdAt exist, match both with $or so results are not missed.',
312
314
  '- When grouping by fields that can be arrays (drivers, deliveries, routes, chemicals), $unwind first and group by both id and name when available.',
@@ -1144,7 +1146,7 @@ function executeAiAssistantCodexRun(payload, context) {
1144
1146
  }
1145
1147
  function executeAiAssistantMongoRead(payload, context) {
1146
1148
  return __awaiter(this, void 0, void 0, function () {
1147
- var input, rawCollection, dbName, db, collectionResolution, collection, _a, user, isSuperAdmin, customerId, baseQuery, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalized, documents, executedQuery, fallbackMeta, dateFallback, fallbackQuery, fallbackDocs, total, sanitizedDocuments, includeIds, display;
1149
+ var input, rawCollection, dbName, db, collectionResolution, collection, _a, user, isSuperAdmin, customerId, baseQuery, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalized, findOptions, documents, executedQuery, fallbackMeta, dateFallback, fallbackQuery, fallbackDocs, total, sanitizedDocuments, includeIds, display;
1148
1150
  var _c, _d;
1149
1151
  return __generator(this, function (_e) {
1150
1152
  switch (_e.label) {
@@ -1193,7 +1195,8 @@ function executeAiAssistantMongoRead(payload, context) {
1193
1195
  : baseQuery;
1194
1196
  scopedQuery = applyCustomerScopeFilter(clientScopedQuery, collection, customerId, isSuperAdmin);
1195
1197
  normalized = normalizeAssistantFindOptions(input.options);
1196
- return [4 /*yield*/, db.collection(collection).find(scopedQuery, normalized.findOptions).toArray()];
1198
+ findOptions = __assign(__assign({}, normalized.findOptions), { readPreference: AI_ASSISTANT_READ_PREFERENCE });
1199
+ return [4 /*yield*/, db.collection(collection).find(scopedQuery, findOptions).toArray()];
1197
1200
  case 6:
1198
1201
  documents = _e.sent();
1199
1202
  executedQuery = scopedQuery;
@@ -1203,7 +1206,7 @@ function executeAiAssistantMongoRead(payload, context) {
1203
1206
  if (!dateFallback) return [3 /*break*/, 8];
1204
1207
  fallbackQuery = replaceQueryField(scopedQuery, dateFallback.from, dateFallback.to);
1205
1208
  fallbackMeta.dateField = __assign(__assign({}, dateFallback), { attempted: true, used: false });
1206
- return [4 /*yield*/, db.collection(collection).find(fallbackQuery, normalized.findOptions).toArray()];
1209
+ return [4 /*yield*/, db.collection(collection).find(fallbackQuery, findOptions).toArray()];
1207
1210
  case 7:
1208
1211
  fallbackDocs = _e.sent();
1209
1212
  if (fallbackDocs.length) {
@@ -1215,7 +1218,7 @@ function executeAiAssistantMongoRead(payload, context) {
1215
1218
  case 8:
1216
1219
  total = null;
1217
1220
  if (!normalized.includeTotal) return [3 /*break*/, 10];
1218
- return [4 /*yield*/, db.collection(collection).countDocuments(executedQuery)];
1221
+ return [4 /*yield*/, db.collection(collection).countDocuments(executedQuery, { readPreference: AI_ASSISTANT_READ_PREFERENCE })];
1219
1222
  case 9:
1220
1223
  total = _e.sent();
1221
1224
  _e.label = 10;
@@ -1253,7 +1256,7 @@ function executeAiAssistantMongoRead(payload, context) {
1253
1256
  }
1254
1257
  function executeAiAssistantMongoAggregate(payload, context) {
1255
1258
  return __awaiter(this, void 0, void 0, function () {
1256
- var input, rawCollection, dbName, db, collectionResolution, collection, _a, user, isSuperAdmin, customerId, baseQuery, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, dateField, documents, executedPipeline, fallbackMeta, fallback, fallbackPipeline, fallbackDocs, createdFallback, createdPipeline, createdDocs, unwindFallback, fallbackPipeline, fallbackDocs, sanitizedDocuments, includeIds, display;
1259
+ var input, rawCollection, dbName, db, collectionResolution, collection, _a, user, isSuperAdmin, customerId, baseQuery, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, dateField, aggregateOptions, documents, executedPipeline, fallbackMeta, fallback, fallbackPipeline, fallbackDocs, createdFallback, createdPipeline, createdDocs, completionFallback, fallbackPipeline, fallbackDocs, unwindFallback, fallbackPipeline, fallbackDocs, sanitizedDocuments, includeIds, display;
1257
1260
  var _c, _d;
1258
1261
  return __generator(this, function (_e) {
1259
1262
  switch (_e.label) {
@@ -1309,8 +1312,9 @@ function executeAiAssistantMongoAggregate(payload, context) {
1309
1312
  if (containsForbiddenMongoOperators(limitedPipeline)) {
1310
1313
  throw new Error('AI assistant mongo aggregate: Pipeline contains restricted operators.');
1311
1314
  }
1315
+ aggregateOptions = __assign(__assign({}, normalizedOptions.aggregateOptions), { readPreference: AI_ASSISTANT_READ_PREFERENCE });
1312
1316
  return [4 /*yield*/, db.collection(collection)
1313
- .aggregate(limitedPipeline, normalizedOptions.aggregateOptions)
1317
+ .aggregate(limitedPipeline, aggregateOptions)
1314
1318
  .toArray()];
1315
1319
  case 6:
1316
1320
  documents = _e.sent();
@@ -1323,7 +1327,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
1323
1327
  fallbackPipeline = replaceAggregateDateField(limitedPipeline, fallback.from, fallback.to);
1324
1328
  if (!!containsForbiddenMongoOperators(fallbackPipeline)) return [3 /*break*/, 8];
1325
1329
  return [4 /*yield*/, db.collection(collection)
1326
- .aggregate(fallbackPipeline, normalizedOptions.aggregateOptions)
1330
+ .aggregate(fallbackPipeline, aggregateOptions)
1327
1331
  .toArray()];
1328
1332
  case 7:
1329
1333
  fallbackDocs = _e.sent();
@@ -1340,7 +1344,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
1340
1344
  fallbackMeta.dateFieldCreatedAt = createdFallback;
1341
1345
  if (!!containsForbiddenMongoOperators(createdPipeline)) return [3 /*break*/, 10];
1342
1346
  return [4 /*yield*/, db.collection(collection)
1343
- .aggregate(createdPipeline, normalizedOptions.aggregateOptions)
1347
+ .aggregate(createdPipeline, aggregateOptions)
1344
1348
  .toArray()];
1345
1349
  case 9:
1346
1350
  createdDocs = _e.sent();
@@ -1351,24 +1355,48 @@ function executeAiAssistantMongoAggregate(payload, context) {
1351
1355
  }
1352
1356
  _e.label = 10;
1353
1357
  case 10:
1354
- if (!(documents.length <= 1)) return [3 /*break*/, 12];
1358
+ if (!!documents.length) return [3 /*break*/, 12];
1359
+ completionFallback = resolveAggregateCompletionFallback(executedPipeline);
1360
+ if (!completionFallback) return [3 /*break*/, 12];
1361
+ fallbackMeta.completion = {
1362
+ field: completionFallback.field,
1363
+ sources: completionFallback.sources,
1364
+ attempted: true,
1365
+ used: false,
1366
+ statusFilter: !!completionFallback.statusFilter
1367
+ };
1368
+ fallbackPipeline = buildAggregateCompletionFallbackPipeline(executedPipeline, completionFallback);
1369
+ if (!(fallbackPipeline.length && !containsForbiddenMongoOperators(fallbackPipeline))) return [3 /*break*/, 12];
1370
+ return [4 /*yield*/, db.collection(collection)
1371
+ .aggregate(fallbackPipeline, aggregateOptions)
1372
+ .toArray()];
1373
+ case 11:
1374
+ fallbackDocs = _e.sent();
1375
+ if (fallbackDocs.length) {
1376
+ documents = fallbackDocs;
1377
+ executedPipeline = fallbackPipeline;
1378
+ fallbackMeta.completion.used = true;
1379
+ }
1380
+ _e.label = 12;
1381
+ case 12:
1382
+ if (!(documents.length <= 1)) return [3 /*break*/, 14];
1355
1383
  unwindFallback = resolveAggregateUnwindFallback(executedPipeline);
1356
- if (!unwindFallback) return [3 /*break*/, 12];
1384
+ if (!unwindFallback) return [3 /*break*/, 14];
1357
1385
  fallbackMeta.unwind = { path: unwindFallback.path, attempted: true, used: false };
1358
1386
  fallbackPipeline = buildAggregateUnwindFallbackPipeline(executedPipeline, unwindFallback);
1359
- if (!!containsForbiddenMongoOperators(fallbackPipeline)) return [3 /*break*/, 12];
1387
+ if (!!containsForbiddenMongoOperators(fallbackPipeline)) return [3 /*break*/, 14];
1360
1388
  return [4 /*yield*/, db.collection(collection)
1361
- .aggregate(fallbackPipeline, normalizedOptions.aggregateOptions)
1389
+ .aggregate(fallbackPipeline, aggregateOptions)
1362
1390
  .toArray()];
1363
- case 11:
1391
+ case 13:
1364
1392
  fallbackDocs = _e.sent();
1365
1393
  if (fallbackDocs.length > documents.length) {
1366
1394
  documents = fallbackDocs;
1367
1395
  executedPipeline = fallbackPipeline;
1368
1396
  fallbackMeta.unwind.used = true;
1369
1397
  }
1370
- _e.label = 12;
1371
- case 12:
1398
+ _e.label = 14;
1399
+ case 14:
1372
1400
  sanitizedDocuments = isSuperAdmin
1373
1401
  ? documents
1374
1402
  : documents.map(function (doc) { return redactSensitiveFields((0, common_1.deepCopy)(doc)); });
@@ -2338,6 +2366,172 @@ function resolveAggregateDateFieldFallback(pipeline) {
2338
2366
  }
2339
2367
  return { from: dateField, to: fallback };
2340
2368
  }
2369
+ function normalizeAggregateFieldList(values) {
2370
+ var seen = new Set();
2371
+ var result = [];
2372
+ values.forEach(function (value) {
2373
+ var normalized = normalizeOptionalString(value);
2374
+ if (!normalized) {
2375
+ return;
2376
+ }
2377
+ if (seen.has(normalized)) {
2378
+ return;
2379
+ }
2380
+ seen.add(normalized);
2381
+ result.push(normalized);
2382
+ });
2383
+ return result;
2384
+ }
2385
+ function isCompletionFieldName(value) {
2386
+ return String(value || '').toLowerCase().includes('complete');
2387
+ }
2388
+ function isDateLikeFieldName(value) {
2389
+ var normalized = String(value || '').toLowerCase();
2390
+ return normalized.includes('date') || normalized.endsWith('_at') || normalized.endsWith('at');
2391
+ }
2392
+ function matchContainsField(value, field) {
2393
+ if (!value || typeof value !== 'object') {
2394
+ return false;
2395
+ }
2396
+ if (Array.isArray(value)) {
2397
+ return value.some(function (entry) { return matchContainsField(entry, field); });
2398
+ }
2399
+ return Object.keys(value).some(function (key) {
2400
+ if (key === field) {
2401
+ return true;
2402
+ }
2403
+ if (key.startsWith('$')) {
2404
+ return matchContainsField(value[key], field);
2405
+ }
2406
+ if (value[key] && typeof value[key] === 'object') {
2407
+ return matchContainsField(value[key], field);
2408
+ }
2409
+ return false;
2410
+ });
2411
+ }
2412
+ function resolveAggregateCompletionFallback(pipeline) {
2413
+ var e_1, _a;
2414
+ if (!Array.isArray(pipeline)) {
2415
+ return null;
2416
+ }
2417
+ var candidateField = '';
2418
+ var candidateSources = [];
2419
+ for (var i = 0; i < pipeline.length; i += 1) {
2420
+ var stage = pipeline[i];
2421
+ if (!stage || typeof stage !== 'object' || !stage.$addFields || typeof stage.$addFields !== 'object') {
2422
+ continue;
2423
+ }
2424
+ var addFields = stage.$addFields;
2425
+ try {
2426
+ for (var _b = (e_1 = void 0, __values(Object.keys(addFields))), _c = _b.next(); !_c.done; _c = _b.next()) {
2427
+ var key = _c.value;
2428
+ if (!isCompletionFieldName(key)) {
2429
+ continue;
2430
+ }
2431
+ var sources = extractExpressionFieldPaths(addFields[key])
2432
+ .filter(function (field) { return isDateLikeFieldName(field); });
2433
+ if (sources.length) {
2434
+ candidateField = key;
2435
+ candidateSources = sources;
2436
+ break;
2437
+ }
2438
+ }
2439
+ }
2440
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2441
+ finally {
2442
+ try {
2443
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2444
+ }
2445
+ finally { if (e_1) throw e_1.error; }
2446
+ }
2447
+ if (candidateField) {
2448
+ break;
2449
+ }
2450
+ }
2451
+ if (!candidateField || !candidateSources.length) {
2452
+ return null;
2453
+ }
2454
+ var matchIndex = -1;
2455
+ var matchCondition = null;
2456
+ var matchStage = null;
2457
+ for (var i = 0; i < pipeline.length; i += 1) {
2458
+ var stage = pipeline[i];
2459
+ if (!stage || typeof stage !== 'object' || !stage.$match || typeof stage.$match !== 'object') {
2460
+ continue;
2461
+ }
2462
+ if (Object.prototype.hasOwnProperty.call(stage.$match, candidateField)) {
2463
+ matchIndex = i;
2464
+ matchCondition = stage.$match[candidateField];
2465
+ matchStage = stage.$match;
2466
+ break;
2467
+ }
2468
+ }
2469
+ if (matchIndex === -1 || !matchStage) {
2470
+ return null;
2471
+ }
2472
+ var normalizedSources = normalizeAggregateFieldList(__spreadArray(__spreadArray([], __read(candidateSources), false), [
2473
+ 'createdAt',
2474
+ 'date_created'
2475
+ ], false));
2476
+ if (!normalizedSources.length) {
2477
+ return null;
2478
+ }
2479
+ var hasStatus = matchContainsField(matchStage, 'status') || matchContainsField(matchStage, 'state');
2480
+ var statusFilter = !hasStatus && isCompletionFieldName(candidateField)
2481
+ ? { $or: [{ status: { $regex: 'complete', $options: 'i' } }, { state: { $regex: 'complete', $options: 'i' } }] }
2482
+ : null;
2483
+ return {
2484
+ matchIndex: matchIndex,
2485
+ field: candidateField,
2486
+ sources: normalizedSources,
2487
+ matchCondition: matchCondition,
2488
+ statusFilter: statusFilter
2489
+ };
2490
+ }
2491
+ function buildAggregateCompletionFallbackPipeline(pipeline, fallback) {
2492
+ var _a;
2493
+ var buildIfNullChain = function (fields) {
2494
+ if (!fields.length) {
2495
+ return null;
2496
+ }
2497
+ var expr = "$".concat(fields[fields.length - 1]);
2498
+ for (var i = fields.length - 2; i >= 0; i -= 1) {
2499
+ expr = { $ifNull: ["$".concat(fields[i]), expr] };
2500
+ }
2501
+ return expr;
2502
+ };
2503
+ var matchStage = (_a = pipeline[fallback.matchIndex]) === null || _a === void 0 ? void 0 : _a.$match;
2504
+ if (!matchStage || typeof matchStage !== 'object') {
2505
+ return pipeline;
2506
+ }
2507
+ var orConditions = fallback.sources.map(function (field) {
2508
+ var _a;
2509
+ return (_a = {}, _a[field] = fallback.matchCondition, _a);
2510
+ });
2511
+ var nextMatch = __assign({}, matchStage);
2512
+ delete nextMatch[fallback.field];
2513
+ var andParts = [];
2514
+ if (Object.keys(nextMatch).length) {
2515
+ andParts.push(nextMatch);
2516
+ }
2517
+ andParts.push({ $or: orConditions });
2518
+ if (fallback.statusFilter) {
2519
+ andParts.push(fallback.statusFilter);
2520
+ }
2521
+ var mergedMatch = andParts.length === 1 ? andParts[0] : { $and: andParts };
2522
+ return pipeline.map(function (stage, index) {
2523
+ var _a;
2524
+ if (index === fallback.matchIndex) {
2525
+ return { $match: mergedMatch };
2526
+ }
2527
+ if (stage && typeof stage === 'object' && stage.$addFields && typeof stage.$addFields === 'object') {
2528
+ if (Object.prototype.hasOwnProperty.call(stage.$addFields, fallback.field)) {
2529
+ return __assign(__assign({}, stage), { $addFields: __assign(__assign({}, stage.$addFields), (_a = {}, _a[fallback.field] = buildIfNullChain(fallback.sources), _a)) });
2530
+ }
2531
+ }
2532
+ return stage;
2533
+ });
2534
+ }
2341
2535
  function resolveAggregateUnwindFallback(pipeline) {
2342
2536
  var groupIndex = findAggregateGroupIndex(pipeline);
2343
2537
  if (groupIndex === -1) {
@@ -2746,7 +2940,7 @@ function resolveAssistantCollectionHints(message, dbName, db) {
2746
2940
  });
2747
2941
  }
2748
2942
  function findQueryDateField(query) {
2749
- var e_1, _a, e_2, _b;
2943
+ var e_2, _a, e_3, _b;
2750
2944
  if (!query || typeof query !== 'object') {
2751
2945
  return null;
2752
2946
  }
@@ -2760,12 +2954,12 @@ function findQueryDateField(query) {
2760
2954
  }
2761
2955
  }
2762
2956
  }
2763
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2957
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2764
2958
  finally {
2765
2959
  try {
2766
2960
  if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
2767
2961
  }
2768
- finally { if (e_1) throw e_1.error; }
2962
+ finally { if (e_2) throw e_2.error; }
2769
2963
  }
2770
2964
  return null;
2771
2965
  }
@@ -2784,12 +2978,12 @@ function findQueryDateField(query) {
2784
2978
  }
2785
2979
  }
2786
2980
  }
2787
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
2981
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
2788
2982
  finally {
2789
2983
  try {
2790
2984
  if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2791
2985
  }
2792
- finally { if (e_2) throw e_2.error; }
2986
+ finally { if (e_3) throw e_3.error; }
2793
2987
  }
2794
2988
  return null;
2795
2989
  }
@@ -2819,7 +3013,7 @@ function resolveQueryDateFieldFallback(query) {
2819
3013
  return { from: dateField, to: fallback };
2820
3014
  }
2821
3015
  function containsForbiddenMongoOperators(value) {
2822
- var e_3, _a;
3016
+ var e_4, _a;
2823
3017
  if (!value || typeof value !== 'object') {
2824
3018
  return false;
2825
3019
  }
@@ -2838,12 +3032,12 @@ function containsForbiddenMongoOperators(value) {
2838
3032
  }
2839
3033
  }
2840
3034
  }
2841
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
3035
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
2842
3036
  finally {
2843
3037
  try {
2844
3038
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2845
3039
  }
2846
- finally { if (e_3) throw e_3.error; }
3040
+ finally { if (e_4) throw e_4.error; }
2847
3041
  }
2848
3042
  return false;
2849
3043
  }
@@ -3077,8 +3271,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
3077
3271
  }
3078
3272
  function waitForCodexWorkerMessage(worker, streamStatusHandler) {
3079
3273
  return __awaiter(this, void 0, void 0, function () {
3080
- var _a, _b, _c, _d, message, payload, status_1, e_4_1;
3081
- var _e, e_4, _f, _g;
3274
+ var _a, _b, _c, _d, message, payload, status_1, e_5_1;
3275
+ var _e, e_5, _f, _g;
3082
3276
  return __generator(this, function (_h) {
3083
3277
  switch (_h.label) {
3084
3278
  case 0:
@@ -3105,8 +3299,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
3105
3299
  return [3 /*break*/, 1];
3106
3300
  case 4: return [3 /*break*/, 11];
3107
3301
  case 5:
3108
- e_4_1 = _h.sent();
3109
- e_4 = { error: e_4_1 };
3302
+ e_5_1 = _h.sent();
3303
+ e_5 = { error: e_5_1 };
3110
3304
  return [3 /*break*/, 11];
3111
3305
  case 6:
3112
3306
  _h.trys.push([6, , 9, 10]);
@@ -3117,7 +3311,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
3117
3311
  _h.label = 8;
3118
3312
  case 8: return [3 /*break*/, 10];
3119
3313
  case 9:
3120
- if (e_4) throw e_4.error;
3314
+ if (e_5) throw e_5.error;
3121
3315
  return [7 /*endfinally*/];
3122
3316
  case 10: return [7 /*endfinally*/];
3123
3317
  case 11: throw new CodexWorkerBootstrapError('Codex worker exited before completing.');
@@ -3499,7 +3693,7 @@ function normalizeRouteMatchKey(value) {
3499
3693
  return normalizeRouteKey(value).toLowerCase();
3500
3694
  }
3501
3695
  function buildClientRouteIndex() {
3502
- var e_5, _a;
3696
+ var e_6, _a;
3503
3697
  var _b;
3504
3698
  var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
3505
3699
  var set = new Set();
@@ -3518,12 +3712,12 @@ function buildClientRouteIndex() {
3518
3712
  }
3519
3713
  }
3520
3714
  }
3521
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
3715
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
3522
3716
  finally {
3523
3717
  try {
3524
3718
  if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
3525
3719
  }
3526
- finally { if (e_5) throw e_5.error; }
3720
+ finally { if (e_6) throw e_6.error; }
3527
3721
  }
3528
3722
  return { set: set, map: map, size: routes.length };
3529
3723
  }
@@ -3649,7 +3843,7 @@ function sanitizeAssistantResponse(value) {
3649
3843
  return normalizeAssistantRoutes(normalizedCurrency);
3650
3844
  }
3651
3845
  function evaluateAssistantGuardrails(message) {
3652
- var e_6, _a;
3846
+ var e_7, _a;
3653
3847
  var normalized = String(message || '').toLowerCase();
3654
3848
  var patterns = [
3655
3849
  {
@@ -3695,12 +3889,12 @@ function evaluateAssistantGuardrails(message) {
3695
3889
  }
3696
3890
  }
3697
3891
  }
3698
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
3892
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
3699
3893
  finally {
3700
3894
  try {
3701
3895
  if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
3702
3896
  }
3703
- finally { if (e_6) throw e_6.error; }
3897
+ finally { if (e_7) throw e_7.error; }
3704
3898
  }
3705
3899
  return null;
3706
3900
  }
@@ -3864,8 +4058,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
3864
4058
  }
3865
4059
  function readAttachmentContents(attachments) {
3866
4060
  return __awaiter(this, void 0, void 0, function () {
3867
- var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_7_1;
3868
- var e_7, _b;
4061
+ var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_8_1;
4062
+ var e_8, _b;
3869
4063
  return __generator(this, function (_c) {
3870
4064
  switch (_c.label) {
3871
4065
  case 0:
@@ -3944,14 +4138,14 @@ function readAttachmentContents(attachments) {
3944
4138
  return [3 /*break*/, 2];
3945
4139
  case 10: return [3 /*break*/, 13];
3946
4140
  case 11:
3947
- e_7_1 = _c.sent();
3948
- e_7 = { error: e_7_1 };
4141
+ e_8_1 = _c.sent();
4142
+ e_8 = { error: e_8_1 };
3949
4143
  return [3 /*break*/, 13];
3950
4144
  case 12:
3951
4145
  try {
3952
4146
  if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
3953
4147
  }
3954
- finally { if (e_7) throw e_7.error; }
4148
+ finally { if (e_8) throw e_8.error; }
3955
4149
  return [7 /*endfinally*/];
3956
4150
  case 13: return [2 /*return*/, {
3957
4151
  promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
@@ -4128,7 +4322,7 @@ function estimateUsage(messages, responseText, model) {
4128
4322
  };
4129
4323
  }
4130
4324
  function evaluateGuardrails(message) {
4131
- var e_8, _a;
4325
+ var e_9, _a;
4132
4326
  var normalized = String(message || '').toLowerCase();
4133
4327
  var patterns = [
4134
4328
  { 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.' },
@@ -4150,12 +4344,12 @@ function evaluateGuardrails(message) {
4150
4344
  }
4151
4345
  }
4152
4346
  }
4153
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
4347
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
4154
4348
  finally {
4155
4349
  try {
4156
4350
  if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
4157
4351
  }
4158
- finally { if (e_8) throw e_8.error; }
4352
+ finally { if (e_9) throw e_9.error; }
4159
4353
  }
4160
4354
  return null;
4161
4355
  }