@resolveio/server-lib 22.1.4 → 22.1.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.
@@ -2535,8 +2535,9 @@ function executeAiAssistantReportIssue(payload, context) {
2535
2535
  }
2536
2536
  function executeAiAssistantMongoRead(payload, context) {
2537
2537
  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;
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, 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
2539
  var e_1, _p;
2540
+ var _this = this;
2540
2541
  var _q, _r;
2541
2542
  return __generator(this, function (_s) {
2542
2543
  switch (_s.label) {
@@ -2635,22 +2636,60 @@ function executeAiAssistantMongoRead(payload, context) {
2635
2636
  scopedQuery = applyCustomerScopeFilter(clientScopedQuery, collection, customerId, isSuperAdmin);
2636
2637
  normalized = normalizeAssistantFindOptions(input.options);
2637
2638
  findOptions = __assign(__assign({}, normalized.findOptions), { readPreference: AI_ASSISTANT_READ_PREFERENCE });
2638
- return [4 /*yield*/, db.collection(collection).find(scopedQuery, findOptions).toArray()];
2639
+ runFindWithRepair = function (query, stage) { return __awaiter(_this, void 0, void 0, function () {
2640
+ var docs, error_5, repaired, docs;
2641
+ return __generator(this, function (_a) {
2642
+ switch (_a.label) {
2643
+ case 0:
2644
+ _a.trys.push([0, 2, , 4]);
2645
+ return [4 /*yield*/, db.collection(collection).find(query, findOptions).toArray()];
2646
+ case 1:
2647
+ docs = _a.sent();
2648
+ return [2 /*return*/, { documents: docs, query: query }];
2649
+ case 2:
2650
+ error_5 = _a.sent();
2651
+ if (!isAssistantDateArithmeticArgumentError(error_5)) {
2652
+ throw error_5;
2653
+ }
2654
+ repaired = repairAssistantDateArithmeticInQuery(query);
2655
+ if (!repaired.changed || containsForbiddenMongoOperators(repaired.query)) {
2656
+ throw error_5;
2657
+ }
2658
+ return [4 /*yield*/, db.collection(collection).find(repaired.query, findOptions).toArray()];
2659
+ case 3:
2660
+ docs = _a.sent();
2661
+ fallbackMeta.dateArithmetic = {
2662
+ attempted: true,
2663
+ used: true,
2664
+ stage: stage,
2665
+ reason: 'normalized_date_operator_args'
2666
+ };
2667
+ return [2 /*return*/, {
2668
+ documents: docs,
2669
+ query: repaired.query
2670
+ }];
2671
+ case 4: return [2 /*return*/];
2672
+ }
2673
+ });
2674
+ }); };
2675
+ return [4 /*yield*/, runFindWithRepair(scopedQuery, 'initial')];
2639
2676
  case 7:
2640
- documents = _s.sent();
2641
- executedQuery = scopedQuery;
2677
+ initialRead = _s.sent();
2678
+ documents = initialRead.documents;
2679
+ executedQuery = initialRead.query;
2642
2680
  probeDocs = null;
2643
2681
  if (!!documents.length) return [3 /*break*/, 9];
2644
2682
  dateFallback = resolveQueryDateFieldFallback(scopedQuery);
2645
2683
  if (!dateFallback) return [3 /*break*/, 9];
2646
2684
  fallbackQuery = replaceQueryField(scopedQuery, dateFallback.from, dateFallback.to);
2647
2685
  fallbackMeta.dateField = __assign(__assign({}, dateFallback), { attempted: true, used: false });
2648
- return [4 /*yield*/, db.collection(collection).find(fallbackQuery, findOptions).toArray()];
2686
+ return [4 /*yield*/, runFindWithRepair(fallbackQuery, 'date_field_fallback')];
2649
2687
  case 8:
2650
- fallbackDocs = _s.sent();
2688
+ fallbackRead = _s.sent();
2689
+ fallbackDocs = fallbackRead.documents;
2651
2690
  if (fallbackDocs.length) {
2652
2691
  documents = fallbackDocs;
2653
- executedQuery = fallbackQuery;
2692
+ executedQuery = fallbackRead.query;
2654
2693
  fallbackMeta.dateField.used = true;
2655
2694
  }
2656
2695
  _s.label = 9;
@@ -2663,12 +2702,13 @@ function executeAiAssistantMongoRead(payload, context) {
2663
2702
  attempted: true,
2664
2703
  used: false
2665
2704
  };
2666
- return [4 /*yield*/, db.collection(collection).find(expanded.query, findOptions).toArray()];
2705
+ return [4 /*yield*/, runFindWithRepair(expanded.query, 'date_fields_expanded')];
2667
2706
  case 10:
2668
- fallbackDocs = _s.sent();
2707
+ fallbackRead = _s.sent();
2708
+ fallbackDocs = fallbackRead.documents;
2669
2709
  if (fallbackDocs.length) {
2670
2710
  documents = fallbackDocs;
2671
- executedQuery = expanded.query;
2711
+ executedQuery = fallbackRead.query;
2672
2712
  fallbackMeta.dateFieldsExpanded.used = true;
2673
2713
  }
2674
2714
  _s.label = 11;
@@ -2682,12 +2722,13 @@ function executeAiAssistantMongoRead(payload, context) {
2682
2722
  attempted: true,
2683
2723
  used: false
2684
2724
  };
2685
- return [4 /*yield*/, db.collection(collection).find(nameFallback.query, findOptions).toArray()];
2725
+ return [4 /*yield*/, runFindWithRepair(nameFallback.query, 'name_match')];
2686
2726
  case 12:
2687
- fallbackDocs = _s.sent();
2727
+ fallbackRead = _s.sent();
2728
+ fallbackDocs = fallbackRead.documents;
2688
2729
  if (fallbackDocs.length) {
2689
2730
  documents = fallbackDocs;
2690
- executedQuery = nameFallback.query;
2731
+ executedQuery = fallbackRead.query;
2691
2732
  fallbackMeta.nameMatch.used = true;
2692
2733
  }
2693
2734
  _s.label = 13;
@@ -2721,12 +2762,13 @@ function executeAiAssistantMongoRead(payload, context) {
2721
2762
  chemicalLookup = _s.sent();
2722
2763
  if (!chemicalLookup) return [3 /*break*/, 18];
2723
2764
  fallbackMeta.chemicalLookup = __assign(__assign({}, chemicalLookup.meta), { attempted: true, used: false });
2724
- return [4 /*yield*/, db.collection(collection).find(chemicalLookup.query, findOptions).toArray()];
2765
+ return [4 /*yield*/, runFindWithRepair(chemicalLookup.query, 'chemical_lookup')];
2725
2766
  case 17:
2726
- fallbackDocs = _s.sent();
2767
+ fallbackRead = _s.sent();
2768
+ fallbackDocs = fallbackRead.documents;
2727
2769
  if (fallbackDocs.length) {
2728
2770
  documents = fallbackDocs;
2729
- executedQuery = chemicalLookup.query;
2771
+ executedQuery = fallbackRead.query;
2730
2772
  fallbackMeta.chemicalLookup.used = true;
2731
2773
  }
2732
2774
  _s.label = 18;
@@ -2762,12 +2804,13 @@ function executeAiAssistantMongoRead(payload, context) {
2762
2804
  var _b = __read(_a, 2), from = _b[0], to = _b[1];
2763
2805
  return replaceFieldPathDeep(acc, from, to);
2764
2806
  }, executedQuery);
2765
- return [4 /*yield*/, db.collection(collection).find(rewrittenQuery, findOptions).toArray()];
2807
+ return [4 /*yield*/, runFindWithRepair(rewrittenQuery, 'query_field_aliases')];
2766
2808
  case 21:
2767
- fallbackDocs = _s.sent();
2809
+ fallbackRead = _s.sent();
2810
+ fallbackDocs = fallbackRead.documents;
2768
2811
  if (fallbackDocs.length) {
2769
2812
  documents = fallbackDocs;
2770
- executedQuery = rewrittenQuery;
2813
+ executedQuery = fallbackRead.query;
2771
2814
  fallbackMeta.queryFieldAliases.used = true;
2772
2815
  }
2773
2816
  _s.label = 22;
@@ -2796,12 +2839,13 @@ function executeAiAssistantMongoRead(payload, context) {
2796
2839
  used: false,
2797
2840
  reason: 'active_fields_missing_in_collection'
2798
2841
  };
2799
- return [4 /*yield*/, db.collection(collection).find(activeFallback.query, findOptions).toArray()];
2842
+ return [4 /*yield*/, runFindWithRepair(activeFallback.query, 'active_status')];
2800
2843
  case 25:
2801
- fallbackDocs = _s.sent();
2844
+ fallbackRead = _s.sent();
2845
+ fallbackDocs = fallbackRead.documents;
2802
2846
  if (fallbackDocs.length) {
2803
2847
  documents = fallbackDocs;
2804
- executedQuery = activeFallback.query;
2848
+ executedQuery = fallbackRead.query;
2805
2849
  fallbackMeta.activeStatus.used = true;
2806
2850
  }
2807
2851
  _s.label = 26;
@@ -2835,12 +2879,13 @@ function executeAiAssistantMongoRead(payload, context) {
2835
2879
  idLookup = _s.sent();
2836
2880
  if (!idLookup) return [3 /*break*/, 31];
2837
2881
  fallbackMeta.idLookup = __assign(__assign({}, idLookup.meta), { attempted: true, used: false });
2838
- return [4 /*yield*/, db.collection(collection).find(idLookup.query, findOptions).toArray()];
2882
+ return [4 /*yield*/, runFindWithRepair(idLookup.query, 'id_lookup')];
2839
2883
  case 30:
2840
- fallbackDocs = _s.sent();
2884
+ fallbackRead = _s.sent();
2885
+ fallbackDocs = fallbackRead.documents;
2841
2886
  if (fallbackDocs.length) {
2842
2887
  documents = fallbackDocs;
2843
- executedQuery = idLookup.query;
2888
+ executedQuery = fallbackRead.query;
2844
2889
  fallbackMeta.idLookup.used = true;
2845
2890
  }
2846
2891
  _s.label = 31;
@@ -3238,7 +3283,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
3238
3283
  }
3239
3284
  aggregateOptions = __assign(__assign({}, normalizedOptions.aggregateOptions), { readPreference: AI_ASSISTANT_READ_PREFERENCE });
3240
3285
  runAggregateWithRepair = function (pipeline, stage) { return __awaiter(_this, void 0, void 0, function () {
3241
- var docs, error_5, isDateRepair, isRankSortByRepair, repaired, docs;
3286
+ var docs, error_6, isDateRepair, isRankSortByRepair, repaired, docs;
3242
3287
  return __generator(this, function (_a) {
3243
3288
  switch (_a.label) {
3244
3289
  case 0:
@@ -3250,17 +3295,17 @@ function executeAiAssistantMongoAggregate(payload, context) {
3250
3295
  docs = _a.sent();
3251
3296
  return [2 /*return*/, { documents: docs, pipeline: pipeline }];
3252
3297
  case 2:
3253
- error_5 = _a.sent();
3254
- isDateRepair = isAssistantDateArithmeticArgumentError(error_5);
3255
- isRankSortByRepair = isAssistantRankSortByError(error_5);
3298
+ error_6 = _a.sent();
3299
+ isDateRepair = isAssistantDateArithmeticArgumentError(error_6);
3300
+ isRankSortByRepair = isAssistantRankSortByError(error_6);
3256
3301
  if (!isDateRepair && !isRankSortByRepair) {
3257
- throw error_5;
3302
+ throw error_6;
3258
3303
  }
3259
3304
  repaired = isDateRepair
3260
3305
  ? repairAssistantDateArithmeticInPipeline(pipeline)
3261
3306
  : repairAssistantRankSortByInPipeline(pipeline);
3262
3307
  if (!repaired.changed || containsForbiddenMongoOperators(repaired.pipeline)) {
3263
- throw error_5;
3308
+ throw error_6;
3264
3309
  }
3265
3310
  return [4 /*yield*/, db.collection(collection)
3266
3311
  .aggregate(repaired.pipeline, aggregateOptions)
@@ -9222,10 +9267,17 @@ function normalizeAssistantNowExprOperand(value) {
9222
9267
  if (trimmed === '$$NOW') {
9223
9268
  return '$$NOW';
9224
9269
  }
9225
- var normalizedToken = trimmed.replace(/^\$+/, '').toUpperCase();
9270
+ var normalizedTokenRaw = trimmed.replace(/^\$+/, '').toUpperCase();
9271
+ var normalizedToken = normalizedTokenRaw.replace(/_(UTC|GMT|Z)$/, '');
9226
9272
  if (normalizedToken === 'NOW_START_OF_MONTH') {
9227
9273
  return createAssistantNowMonthStartExpr();
9228
9274
  }
9275
+ if (normalizedToken === 'NOW_START_OF_WEEK' || normalizedToken === 'START_OF_WEEK') {
9276
+ return createAssistantNowWeekStartExpr();
9277
+ }
9278
+ if (normalizedToken === 'NOW_START_OF_DAY' || normalizedToken === 'START_OF_DAY' || normalizedToken === 'START_OF_TODAY') {
9279
+ return createAssistantNowDayStartExpr();
9280
+ }
9229
9281
  if (normalizedToken === 'NOW_START_OF_LAST_MONTH') {
9230
9282
  return {
9231
9283
  $dateSubtract: {
@@ -9259,6 +9311,12 @@ function normalizeAssistantNowExprOperand(value) {
9259
9311
  }
9260
9312
  };
9261
9313
  }
9314
+ if (normalizedToken === 'NOW_END_OF_WEEK' || normalizedToken === 'END_OF_WEEK') {
9315
+ return createAssistantNowWeekEndExpr();
9316
+ }
9317
+ if (normalizedToken === 'NOW_END_OF_DAY' || normalizedToken === 'END_OF_DAY' || normalizedToken === 'END_OF_TODAY') {
9318
+ return createAssistantNowDayEndExpr();
9319
+ }
9262
9320
  var parsed = parseAssistantNowRelativeToken(trimmed);
9263
9321
  if (!parsed) {
9264
9322
  return value;
@@ -9604,7 +9662,19 @@ function isAssistantDateArithmeticArgumentError(error) {
9604
9662
  || message.includes('undefined variable: now_start_of_month')
9605
9663
  || message.includes('undefined variable: now_start_of_last_month')
9606
9664
  || message.includes('undefined variable: now_start_of_next_month')
9607
- || message.includes('undefined variable: now_end_of_month');
9665
+ || message.includes('undefined variable: now_end_of_month')
9666
+ || message.includes('undefined variable: start_of_week')
9667
+ || message.includes('undefined variable: start_of_week_utc')
9668
+ || message.includes('undefined variable: end_of_week')
9669
+ || message.includes('undefined variable: end_of_week_utc')
9670
+ || message.includes('undefined variable: start_of_day')
9671
+ || message.includes('undefined variable: start_of_day_utc')
9672
+ || message.includes('undefined variable: end_of_day')
9673
+ || message.includes('undefined variable: end_of_day_utc')
9674
+ || message.includes('undefined variable: start_of_today')
9675
+ || message.includes('undefined variable: start_of_today_utc')
9676
+ || message.includes('undefined variable: end_of_today')
9677
+ || message.includes('undefined variable: end_of_today_utc');
9608
9678
  }
9609
9679
  function isAssistantRankSortByError(error) {
9610
9680
  var message = normalizeOptionalString(error === null || error === void 0 ? void 0 : error.message).toLowerCase();
@@ -9632,6 +9702,16 @@ function repairAssistantDateArithmeticInPipeline(pipeline) {
9632
9702
  changed: didAssistantValueChange(pipeline, repaired)
9633
9703
  };
9634
9704
  }
9705
+ function repairAssistantDateArithmeticInQuery(query) {
9706
+ var repairedRaw = normalizeAssistantNowExprPlaceholdersDeep(query);
9707
+ var repaired = (repairedRaw && typeof repairedRaw === 'object' && !Array.isArray(repairedRaw))
9708
+ ? repairedRaw
9709
+ : query;
9710
+ return {
9711
+ query: repaired,
9712
+ changed: didAssistantValueChange(query, repaired)
9713
+ };
9714
+ }
9635
9715
  function repairAssistantRankSortByInPipeline(pipeline) {
9636
9716
  var repaired = Array.isArray(pipeline)
9637
9717
  ? pipeline.map(function (stage) {
@@ -9818,6 +9898,55 @@ function createAssistantNowMonthStartExpr() {
9818
9898
  }
9819
9899
  };
9820
9900
  }
9901
+ function createAssistantNowWeekStartExpr() {
9902
+ return {
9903
+ $dateTrunc: {
9904
+ date: '$$NOW',
9905
+ unit: 'week',
9906
+ startOfWeek: 'monday',
9907
+ timezone: 'UTC'
9908
+ }
9909
+ };
9910
+ }
9911
+ function createAssistantNowDayStartExpr() {
9912
+ return {
9913
+ $dateTrunc: {
9914
+ date: '$$NOW',
9915
+ unit: 'day',
9916
+ timezone: 'UTC'
9917
+ }
9918
+ };
9919
+ }
9920
+ function createAssistantNowWeekEndExpr() {
9921
+ return {
9922
+ $dateSubtract: {
9923
+ startDate: {
9924
+ $dateAdd: {
9925
+ startDate: createAssistantNowWeekStartExpr(),
9926
+ unit: 'week',
9927
+ amount: 1
9928
+ }
9929
+ },
9930
+ unit: 'millisecond',
9931
+ amount: 1
9932
+ }
9933
+ };
9934
+ }
9935
+ function createAssistantNowDayEndExpr() {
9936
+ return {
9937
+ $dateSubtract: {
9938
+ startDate: {
9939
+ $dateAdd: {
9940
+ startDate: createAssistantNowDayStartExpr(),
9941
+ unit: 'day',
9942
+ amount: 1
9943
+ }
9944
+ },
9945
+ unit: 'millisecond',
9946
+ amount: 1
9947
+ }
9948
+ };
9949
+ }
9821
9950
  function isAssistantNowMonthStartExpr(value) {
9822
9951
  if (!value || typeof value !== 'object' || Array.isArray(value)) {
9823
9952
  return false;
@@ -10121,6 +10250,26 @@ function normalizeAssistantSetWindowFieldsRankSortBy(setWindowFields) {
10121
10250
  _a[primarySortKey] = sortBy[primarySortKey],
10122
10251
  _a) });
10123
10252
  }
10253
+ function normalizeAssistantSortTieBreakersForLimit(pipeline) {
10254
+ return pipeline.map(function (stage, index) {
10255
+ if (!stage || typeof stage !== 'object' || Array.isArray(stage)) {
10256
+ return stage;
10257
+ }
10258
+ var sort = stage.$sort;
10259
+ if (!sort || typeof sort !== 'object' || Array.isArray(sort)) {
10260
+ return stage;
10261
+ }
10262
+ var nextStage = pipeline[index + 1];
10263
+ if (!nextStage || typeof nextStage !== 'object' || Array.isArray(nextStage) || typeof nextStage.$limit !== 'number') {
10264
+ return stage;
10265
+ }
10266
+ var sortKeys = Object.keys(sort).filter(function (key) { return String(key || '').trim(); });
10267
+ if (sortKeys.length !== 1 || sortKeys[0] === '_id') {
10268
+ return stage;
10269
+ }
10270
+ return __assign(__assign({}, stage), { $sort: __assign(__assign({}, sort), { _id: 1 }) });
10271
+ });
10272
+ }
10124
10273
  function normalizeAssistantAggregatePipeline(pipeline, collection) {
10125
10274
  if (!Array.isArray(pipeline)) {
10126
10275
  return [];
@@ -10147,7 +10296,8 @@ function normalizeAssistantAggregatePipeline(pipeline, collection) {
10147
10296
  }
10148
10297
  return normalizeAssistantNowExprPlaceholdersDeep(next);
10149
10298
  });
10150
- return normalizeAssistantMonthlyCalendarWindowPipeline(normalizedPipeline);
10299
+ var stableSortPipeline = normalizeAssistantSortTieBreakersForLimit(normalizedPipeline);
10300
+ return normalizeAssistantMonthlyCalendarWindowPipeline(stableSortPipeline);
10151
10301
  }
10152
10302
  function buildAssistantAggregatePipeline(query, pipeline) {
10153
10303
  var _a;
@@ -13878,7 +14028,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
13878
14028
  }
13879
14029
  function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler) {
13880
14030
  return __awaiter(this, void 0, void 0, function () {
13881
- var streamedOptions, codexClient, workerPath, codexClient, error_6, codexClient;
14031
+ var streamedOptions, codexClient, workerPath, codexClient, error_7, codexClient;
13882
14032
  return __generator(this, function (_a) {
13883
14033
  switch (_a.label) {
13884
14034
  case 0:
@@ -13899,11 +14049,11 @@ function runCodexInWorkerThread(prompt, runOptions, config, streamStatusHandler)
13899
14049
  return [4 /*yield*/, runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config, streamStatusHandler)];
13900
14050
  case 6: return [2 /*return*/, _a.sent()];
13901
14051
  case 7:
13902
- error_6 = _a.sent();
13903
- if (!(error_6 instanceof CodexWorkerBootstrapError)) {
13904
- throw error_6;
14052
+ error_7 = _a.sent();
14053
+ if (!(error_7 instanceof CodexWorkerBootstrapError)) {
14054
+ throw error_7;
13905
14055
  }
13906
- console.error('Codex worker bootstrap failed, falling back to in-process run.', error_6);
14056
+ console.error('Codex worker bootstrap failed, falling back to in-process run.', error_7);
13907
14057
  codexClient = getAssistantCodexClient(config);
13908
14058
  return [4 /*yield*/, codexClient.run(prompt, streamedOptions)];
13909
14059
  case 8: return [2 /*return*/, _a.sent()];
@@ -13941,7 +14091,7 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
13941
14091
  timeoutMs = ((sanitizedOptions === null || sanitizedOptions === void 0 ? void 0 : sanitizedOptions.timeoutMs) || resolveCodexTimeoutMs()) + 15000;
13942
14092
  timeoutController = new AbortController();
13943
14093
  timeoutPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
13944
- var error_7;
14094
+ var error_8;
13945
14095
  return __generator(this, function (_a) {
13946
14096
  switch (_a.label) {
13947
14097
  case 0:
@@ -13951,11 +14101,11 @@ function runCodexInWorkerThreadInternal(workerPath, prompt, runOptions, config,
13951
14101
  _a.sent();
13952
14102
  return [2 /*return*/, { type: 'timeout' }];
13953
14103
  case 2:
13954
- error_7 = _a.sent();
13955
- if ((error_7 === null || error_7 === void 0 ? void 0 : error_7.name) === 'AbortError') {
14104
+ error_8 = _a.sent();
14105
+ if ((error_8 === null || error_8 === void 0 ? void 0 : error_8.name) === 'AbortError') {
13956
14106
  return [2 /*return*/, { type: 'aborted' }];
13957
14107
  }
13958
- throw error_7;
14108
+ throw error_8;
13959
14109
  case 3: return [2 /*return*/];
13960
14110
  }
13961
14111
  });
@@ -14131,145 +14281,26 @@ function directoryExists(target) {
14131
14281
  });
14132
14282
  });
14133
14283
  }
14134
- function isAssistantPathUnderRoot(target, root) {
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) {
14284
+ function resolveAssistantWorkspaceRoot() {
14145
14285
  return __awaiter(this, void 0, void 0, function () {
14146
- var serverPath, angularPath, _a, hasServer, hasPackage;
14286
+ var candidate, stat, _a;
14147
14287
  return __generator(this, function (_b) {
14148
14288
  switch (_b.label) {
14149
14289
  case 0:
14150
- if (!candidate) {
14151
- return [2 /*return*/, false];
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)];
14290
+ candidate = '/var/app/current';
14291
+ stat = null;
14292
+ _b.label = 1;
14234
14293
  case 1:
14235
- _a = _c.sent();
14236
- return [3 /*break*/, 3];
14294
+ _b.trys.push([1, 3, , 4]);
14295
+ return [4 /*yield*/, fs_1.promises.stat(candidate)];
14237
14296
  case 2:
14238
- _a = '';
14239
- _c.label = 3;
14297
+ stat = _b.sent();
14298
+ return [3 /*break*/, 4];
14240
14299
  case 3:
14241
- projectRoot = _a;
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
- }
14300
+ _a = _b.sent();
14260
14301
  stat = null;
14261
- _c.label = 4;
14302
+ return [3 /*break*/, 4];
14262
14303
  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
14304
  if (!stat || !stat.isDirectory()) {
14274
14305
  throw new Error('AI assistant workspace root not found.');
14275
14306
  }
@@ -16888,7 +16919,7 @@ function resolveAssistantDatabaseNameForSystemCollections() {
16888
16919
  }
16889
16920
  function updateAssistantMessageWithFallback(messageId, setPayload) {
16890
16921
  return __awaiter(this, void 0, void 0, function () {
16891
- var error_8, dbName, _a;
16922
+ var error_9, dbName, _a;
16892
16923
  return __generator(this, function (_b) {
16893
16924
  switch (_b.label) {
16894
16925
  case 0:
@@ -16903,9 +16934,9 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
16903
16934
  _b.sent();
16904
16935
  return [2 /*return*/];
16905
16936
  case 3:
16906
- error_8 = _b.sent();
16907
- if (!isAssistantTransactionCommittedError(error_8)) {
16908
- throw error_8;
16937
+ error_9 = _b.sent();
16938
+ if (!isAssistantTransactionCommittedError(error_9)) {
16939
+ throw error_9;
16909
16940
  }
16910
16941
  dbName = resolveAssistantDatabaseNameForSystemCollections();
16911
16942
  _b.label = 4;
@@ -16935,7 +16966,7 @@ function updateAssistantMessageWithFallback(messageId, setPayload) {
16935
16966
  }
16936
16967
  function touchConversation(idConversation, timestamp, lastMessageId) {
16937
16968
  return __awaiter(this, void 0, void 0, function () {
16938
- var update, error_9, dbName;
16969
+ var update, error_10, dbName;
16939
16970
  return __generator(this, function (_a) {
16940
16971
  switch (_a.label) {
16941
16972
  case 0:
@@ -16954,9 +16985,9 @@ function touchConversation(idConversation, timestamp, lastMessageId) {
16954
16985
  _a.sent();
16955
16986
  return [2 /*return*/];
16956
16987
  case 3:
16957
- error_9 = _a.sent();
16958
- if (!isAssistantTransactionCommittedError(error_9)) {
16959
- throw error_9;
16988
+ error_10 = _a.sent();
16989
+ if (!isAssistantTransactionCommittedError(error_10)) {
16990
+ throw error_10;
16960
16991
  }
16961
16992
  dbName = resolveAssistantDatabaseNameForSystemCollections();
16962
16993
  return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoConnection()