@librechat/data-schemas 0.0.36 → 0.0.38

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/dist/index.cjs CHANGED
@@ -94,6 +94,7 @@ async function loadDefaultInterface({ config, configDefaults, }) {
94
94
  fileCitations: interfaceConfig === null || interfaceConfig === void 0 ? void 0 : interfaceConfig.fileCitations,
95
95
  peoplePicker: interfaceConfig === null || interfaceConfig === void 0 ? void 0 : interfaceConfig.peoplePicker,
96
96
  marketplace: interfaceConfig === null || interfaceConfig === void 0 ? void 0 : interfaceConfig.marketplace,
97
+ remoteAgents: interfaceConfig === null || interfaceConfig === void 0 ? void 0 : interfaceConfig.remoteAgents,
97
98
  });
98
99
  return loadedInterface;
99
100
  }
@@ -1775,6 +1776,9 @@ const conversationPreset = {
1775
1776
  thinkingBudget: {
1776
1777
  type: Number,
1777
1778
  },
1779
+ thinkingLevel: {
1780
+ type: String,
1781
+ },
1778
1782
  effort: {
1779
1783
  type: String,
1780
1784
  },
@@ -2512,6 +2516,7 @@ const transactionSchema = new mongoose.Schema({
2512
2516
  inputTokens: { type: Number },
2513
2517
  writeTokens: { type: Number },
2514
2518
  readTokens: { type: Number },
2519
+ messageId: { type: String },
2515
2520
  }, {
2516
2521
  timestamps: true,
2517
2522
  });
@@ -2739,6 +2744,7 @@ groupSchema.index({ idOnTheSource: 1, source: 1 }, {
2739
2744
  });
2740
2745
  groupSchema.index({ memberIds: 1 });
2741
2746
 
2747
+ const CANCEL_RATE = 1.15;
2742
2748
  /**
2743
2749
  * Checks if the connected MongoDB deployment supports transactions
2744
2750
  * This requires a MongoDB replica set configuration
@@ -2999,9 +3005,11 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
2999
3005
  try {
3000
3006
  // Add documents to MeiliSearch
3001
3007
  await index.addDocumentsInBatches(formattedDocs);
3002
- // Update MongoDB to mark documents as indexed
3008
+ // Update MongoDB to mark documents as indexed.
3009
+ // { timestamps: false } prevents Mongoose from touching updatedAt, preserving
3010
+ // original conversation/message timestamps (fixes sidebar chronological sort).
3003
3011
  const docsIds = documents.map((doc) => doc._id);
3004
- await this.updateMany({ _id: { $in: docsIds } }, { $set: { _meiliIndex: true } });
3012
+ await this.updateMany({ _id: { $in: docsIds } }, { $set: { _meiliIndex: true } }, { timestamps: false });
3005
3013
  }
3006
3014
  catch (error) {
3007
3015
  logger.error('[processSyncBatch] Error processing batch:', error);
@@ -7012,6 +7020,77 @@ function createShareMethods(mongoose) {
7012
7020
  };
7013
7021
  }
7014
7022
 
7023
+ function createTransactionMethods(mongoose) {
7024
+ async function updateBalance({ user, incrementValue, setValues }) {
7025
+ var _a;
7026
+ const maxRetries = 10;
7027
+ let delay = 50;
7028
+ let lastError = null;
7029
+ const Balance = mongoose.models.Balance;
7030
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
7031
+ try {
7032
+ const currentBalanceDoc = await Balance.findOne({ user }).lean();
7033
+ const currentCredits = (_a = currentBalanceDoc === null || currentBalanceDoc === void 0 ? void 0 : currentBalanceDoc.tokenCredits) !== null && _a !== void 0 ? _a : 0;
7034
+ const newCredits = Math.max(0, currentCredits + incrementValue);
7035
+ const updatePayload = {
7036
+ $set: {
7037
+ tokenCredits: newCredits,
7038
+ ...(setValues !== null && setValues !== void 0 ? setValues : {}),
7039
+ },
7040
+ };
7041
+ if (currentBalanceDoc) {
7042
+ const updatedBalance = await Balance.findOneAndUpdate({ user, tokenCredits: currentCredits }, updatePayload, { new: true }).lean();
7043
+ if (updatedBalance) {
7044
+ return updatedBalance;
7045
+ }
7046
+ lastError = new Error(`Concurrency conflict for user ${user} on attempt ${attempt}.`);
7047
+ }
7048
+ else {
7049
+ try {
7050
+ const updatedBalance = await Balance.findOneAndUpdate({ user }, updatePayload, {
7051
+ upsert: true,
7052
+ new: true,
7053
+ }).lean();
7054
+ if (updatedBalance) {
7055
+ return updatedBalance;
7056
+ }
7057
+ lastError = new Error(`Upsert race condition suspected for user ${user} on attempt ${attempt}.`);
7058
+ }
7059
+ catch (error) {
7060
+ if (error instanceof Error &&
7061
+ 'code' in error &&
7062
+ error.code === 11000) {
7063
+ lastError = error;
7064
+ }
7065
+ else {
7066
+ throw error;
7067
+ }
7068
+ }
7069
+ }
7070
+ }
7071
+ catch (error) {
7072
+ logger$1.error(`[updateBalance] Error during attempt ${attempt} for user ${user}:`, error);
7073
+ lastError = error instanceof Error ? error : new Error(String(error));
7074
+ }
7075
+ if (attempt < maxRetries) {
7076
+ const jitter = Math.random() * delay * 0.5;
7077
+ await new Promise((resolve) => setTimeout(resolve, delay + jitter));
7078
+ delay = Math.min(delay * 2, 2000);
7079
+ }
7080
+ }
7081
+ logger$1.error(`[updateBalance] Failed to update balance for user ${user} after ${maxRetries} attempts.`);
7082
+ throw (lastError !== null && lastError !== void 0 ? lastError : new Error(`Failed to update balance for user ${user} after maximum retries due to persistent conflicts.`));
7083
+ }
7084
+ /** Bypasses document middleware; all computed fields must be pre-calculated before calling. */
7085
+ async function bulkInsertTransactions(docs) {
7086
+ const Transaction = mongoose.models.Transaction;
7087
+ if (docs.length) {
7088
+ await Transaction.insertMany(docs);
7089
+ }
7090
+ }
7091
+ return { updateBalance, bulkInsertTransactions };
7092
+ }
7093
+
7015
7094
  /**
7016
7095
  * Creates all database methods for all collections
7017
7096
  * @param mongoose - Mongoose instance
@@ -7033,10 +7112,12 @@ function createMethods(mongoose) {
7033
7112
  ...createAclEntryMethods(mongoose),
7034
7113
  ...createShareMethods(mongoose),
7035
7114
  ...createPluginAuthMethods(mongoose),
7115
+ ...createTransactionMethods(mongoose),
7036
7116
  };
7037
7117
  }
7038
7118
 
7039
7119
  exports.AppService = AppService;
7120
+ exports.CANCEL_RATE = CANCEL_RATE;
7040
7121
  exports.DEFAULT_REFRESH_TOKEN_EXPIRY = DEFAULT_REFRESH_TOKEN_EXPIRY;
7041
7122
  exports.DEFAULT_SESSION_EXPIRY = DEFAULT_SESSION_EXPIRY;
7042
7123
  exports.actionSchema = Action;