@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.es.js CHANGED
@@ -92,6 +92,7 @@ async function loadDefaultInterface({ config, configDefaults, }) {
92
92
  fileCitations: interfaceConfig === null || interfaceConfig === void 0 ? void 0 : interfaceConfig.fileCitations,
93
93
  peoplePicker: interfaceConfig === null || interfaceConfig === void 0 ? void 0 : interfaceConfig.peoplePicker,
94
94
  marketplace: interfaceConfig === null || interfaceConfig === void 0 ? void 0 : interfaceConfig.marketplace,
95
+ remoteAgents: interfaceConfig === null || interfaceConfig === void 0 ? void 0 : interfaceConfig.remoteAgents,
95
96
  });
96
97
  return loadedInterface;
97
98
  }
@@ -1773,6 +1774,9 @@ const conversationPreset = {
1773
1774
  thinkingBudget: {
1774
1775
  type: Number,
1775
1776
  },
1777
+ thinkingLevel: {
1778
+ type: String,
1779
+ },
1776
1780
  effort: {
1777
1781
  type: String,
1778
1782
  },
@@ -2510,6 +2514,7 @@ const transactionSchema = new Schema({
2510
2514
  inputTokens: { type: Number },
2511
2515
  writeTokens: { type: Number },
2512
2516
  readTokens: { type: Number },
2517
+ messageId: { type: String },
2513
2518
  }, {
2514
2519
  timestamps: true,
2515
2520
  });
@@ -2737,6 +2742,7 @@ groupSchema.index({ idOnTheSource: 1, source: 1 }, {
2737
2742
  });
2738
2743
  groupSchema.index({ memberIds: 1 });
2739
2744
 
2745
+ const CANCEL_RATE = 1.15;
2740
2746
  /**
2741
2747
  * Checks if the connected MongoDB deployment supports transactions
2742
2748
  * This requires a MongoDB replica set configuration
@@ -2997,9 +3003,11 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
2997
3003
  try {
2998
3004
  // Add documents to MeiliSearch
2999
3005
  await index.addDocumentsInBatches(formattedDocs);
3000
- // Update MongoDB to mark documents as indexed
3006
+ // Update MongoDB to mark documents as indexed.
3007
+ // { timestamps: false } prevents Mongoose from touching updatedAt, preserving
3008
+ // original conversation/message timestamps (fixes sidebar chronological sort).
3001
3009
  const docsIds = documents.map((doc) => doc._id);
3002
- await this.updateMany({ _id: { $in: docsIds } }, { $set: { _meiliIndex: true } });
3010
+ await this.updateMany({ _id: { $in: docsIds } }, { $set: { _meiliIndex: true } }, { timestamps: false });
3003
3011
  }
3004
3012
  catch (error) {
3005
3013
  logger.error('[processSyncBatch] Error processing batch:', error);
@@ -7010,6 +7018,77 @@ function createShareMethods(mongoose) {
7010
7018
  };
7011
7019
  }
7012
7020
 
7021
+ function createTransactionMethods(mongoose) {
7022
+ async function updateBalance({ user, incrementValue, setValues }) {
7023
+ var _a;
7024
+ const maxRetries = 10;
7025
+ let delay = 50;
7026
+ let lastError = null;
7027
+ const Balance = mongoose.models.Balance;
7028
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
7029
+ try {
7030
+ const currentBalanceDoc = await Balance.findOne({ user }).lean();
7031
+ const currentCredits = (_a = currentBalanceDoc === null || currentBalanceDoc === void 0 ? void 0 : currentBalanceDoc.tokenCredits) !== null && _a !== void 0 ? _a : 0;
7032
+ const newCredits = Math.max(0, currentCredits + incrementValue);
7033
+ const updatePayload = {
7034
+ $set: {
7035
+ tokenCredits: newCredits,
7036
+ ...(setValues !== null && setValues !== void 0 ? setValues : {}),
7037
+ },
7038
+ };
7039
+ if (currentBalanceDoc) {
7040
+ const updatedBalance = await Balance.findOneAndUpdate({ user, tokenCredits: currentCredits }, updatePayload, { new: true }).lean();
7041
+ if (updatedBalance) {
7042
+ return updatedBalance;
7043
+ }
7044
+ lastError = new Error(`Concurrency conflict for user ${user} on attempt ${attempt}.`);
7045
+ }
7046
+ else {
7047
+ try {
7048
+ const updatedBalance = await Balance.findOneAndUpdate({ user }, updatePayload, {
7049
+ upsert: true,
7050
+ new: true,
7051
+ }).lean();
7052
+ if (updatedBalance) {
7053
+ return updatedBalance;
7054
+ }
7055
+ lastError = new Error(`Upsert race condition suspected for user ${user} on attempt ${attempt}.`);
7056
+ }
7057
+ catch (error) {
7058
+ if (error instanceof Error &&
7059
+ 'code' in error &&
7060
+ error.code === 11000) {
7061
+ lastError = error;
7062
+ }
7063
+ else {
7064
+ throw error;
7065
+ }
7066
+ }
7067
+ }
7068
+ }
7069
+ catch (error) {
7070
+ logger$1.error(`[updateBalance] Error during attempt ${attempt} for user ${user}:`, error);
7071
+ lastError = error instanceof Error ? error : new Error(String(error));
7072
+ }
7073
+ if (attempt < maxRetries) {
7074
+ const jitter = Math.random() * delay * 0.5;
7075
+ await new Promise((resolve) => setTimeout(resolve, delay + jitter));
7076
+ delay = Math.min(delay * 2, 2000);
7077
+ }
7078
+ }
7079
+ logger$1.error(`[updateBalance] Failed to update balance for user ${user} after ${maxRetries} attempts.`);
7080
+ throw (lastError !== null && lastError !== void 0 ? lastError : new Error(`Failed to update balance for user ${user} after maximum retries due to persistent conflicts.`));
7081
+ }
7082
+ /** Bypasses document middleware; all computed fields must be pre-calculated before calling. */
7083
+ async function bulkInsertTransactions(docs) {
7084
+ const Transaction = mongoose.models.Transaction;
7085
+ if (docs.length) {
7086
+ await Transaction.insertMany(docs);
7087
+ }
7088
+ }
7089
+ return { updateBalance, bulkInsertTransactions };
7090
+ }
7091
+
7013
7092
  /**
7014
7093
  * Creates all database methods for all collections
7015
7094
  * @param mongoose - Mongoose instance
@@ -7031,8 +7110,9 @@ function createMethods(mongoose) {
7031
7110
  ...createAclEntryMethods(mongoose),
7032
7111
  ...createShareMethods(mongoose),
7033
7112
  ...createPluginAuthMethods(mongoose),
7113
+ ...createTransactionMethods(mongoose),
7034
7114
  };
7035
7115
  }
7036
7116
 
7037
- export { AppService, DEFAULT_REFRESH_TOKEN_EXPIRY, DEFAULT_SESSION_EXPIRY, RoleBits, Action as actionSchema, agentApiKeySchema, agentCategorySchema, agentSchema, agentsConfigSetup, assistantSchema, balanceSchema, bannerSchema, categoriesSchema, conversationTag as conversationTagSchema, convoSchema, createMethods, createModels, decrypt, decryptV2, decryptV3, defaultVertexModels, encrypt, encryptV2, encryptV3, file as fileSchema, getRandomValues, getTransactionSupport, getWebSearchKeys, groupSchema, hashBackupCode, hashToken, keySchema, loadDefaultInterface, loadTurnstileConfig, loadWebSearchConfig, logger$1 as logger, logger as meiliLogger, MemoryEntrySchema as memorySchema, messageSchema, pluginAuthSchema, presetSchema, processModelSpecs, projectSchema, promptGroupSchema, promptSchema, roleSchema, sessionSchema, shareSchema, signPayload, supportsTransactions, tokenSchema, toolCallSchema, transactionSchema, userSchema, validateVertexConfig, vertexConfigSetup, webSearchAuth, webSearchKeys };
7117
+ export { AppService, CANCEL_RATE, DEFAULT_REFRESH_TOKEN_EXPIRY, DEFAULT_SESSION_EXPIRY, RoleBits, Action as actionSchema, agentApiKeySchema, agentCategorySchema, agentSchema, agentsConfigSetup, assistantSchema, balanceSchema, bannerSchema, categoriesSchema, conversationTag as conversationTagSchema, convoSchema, createMethods, createModels, decrypt, decryptV2, decryptV3, defaultVertexModels, encrypt, encryptV2, encryptV3, file as fileSchema, getRandomValues, getTransactionSupport, getWebSearchKeys, groupSchema, hashBackupCode, hashToken, keySchema, loadDefaultInterface, loadTurnstileConfig, loadWebSearchConfig, logger$1 as logger, logger as meiliLogger, MemoryEntrySchema as memorySchema, messageSchema, pluginAuthSchema, presetSchema, processModelSpecs, projectSchema, promptGroupSchema, promptSchema, roleSchema, sessionSchema, shareSchema, signPayload, supportsTransactions, tokenSchema, toolCallSchema, transactionSchema, userSchema, validateVertexConfig, vertexConfigSetup, webSearchAuth, webSearchKeys };
7038
7118
  //# sourceMappingURL=index.es.js.map