@librechat/data-schemas 0.0.21 → 0.0.23

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
@@ -225,6 +225,7 @@ const agentCategorySchema = new Schema({
225
225
  timestamps: true,
226
226
  });
227
227
  agentCategorySchema.index({ isActive: 1, order: 1 });
228
+ agentCategorySchema.index({ order: 1, label: 1 });
228
229
 
229
230
  const assistantSchema = new Schema({
230
231
  user: {
@@ -535,6 +536,7 @@ const convoSchema = new Schema({
535
536
  user: {
536
537
  type: String,
537
538
  index: true,
539
+ meiliIndex: true,
538
540
  },
539
541
  messages: [{ type: Schema.Types.ObjectId, ref: 'Message' }],
540
542
  agentOptions: {
@@ -675,6 +677,7 @@ const messageSchema = new Schema({
675
677
  index: true,
676
678
  required: true,
677
679
  default: null,
680
+ meiliIndex: true,
678
681
  },
679
682
  model: {
680
683
  type: String,
@@ -2418,6 +2421,16 @@ function mongoMeili(schema, options) {
2418
2421
  logger.error(`[mongoMeili] Error checking index ${indexName}:`, error);
2419
2422
  }
2420
2423
  }
2424
+ // Configure index settings to make 'user' field filterable
2425
+ try {
2426
+ await index.updateSettings({
2427
+ filterableAttributes: ['user'],
2428
+ });
2429
+ logger.debug(`[mongoMeili] Updated index ${indexName} settings to make 'user' filterable`);
2430
+ }
2431
+ catch (settingsError) {
2432
+ logger.error(`[mongoMeili] Error updating index settings for ${indexName}:`, settingsError);
2433
+ }
2421
2434
  })();
2422
2435
  // Collect attributes from the schema that should be indexed
2423
2436
  const attributesToIndex = [
@@ -2426,6 +2439,12 @@ function mongoMeili(schema, options) {
2426
2439
  return schemaValue.meiliIndex ? [...results, key] : results;
2427
2440
  }, []),
2428
2441
  ];
2442
+ // CRITICAL: Always include 'user' field for proper filtering
2443
+ // This ensures existing deployments can filter by user after migration
2444
+ if (schema.obj.user && !attributesToIndex.includes('user')) {
2445
+ attributesToIndex.push('user');
2446
+ logger.debug(`[mongoMeili] Added 'user' field to ${indexName} index attributes`);
2447
+ }
2429
2448
  schema.loadClass(createMeiliMongooseModel({ index, attributesToIndex, syncOptions }));
2430
2449
  // Register Mongoose hooks
2431
2450
  schema.post('save', function (doc, next) {
@@ -3052,13 +3071,27 @@ function createTokenMethods(mongoose) {
3052
3071
  async function deleteTokens(query) {
3053
3072
  try {
3054
3073
  const Token = mongoose.models.Token;
3074
+ const conditions = [];
3075
+ if (query.userId !== undefined) {
3076
+ conditions.push({ userId: query.userId });
3077
+ }
3078
+ if (query.token !== undefined) {
3079
+ conditions.push({ token: query.token });
3080
+ }
3081
+ if (query.email !== undefined) {
3082
+ conditions.push({ email: query.email });
3083
+ }
3084
+ if (query.identifier !== undefined) {
3085
+ conditions.push({ identifier: query.identifier });
3086
+ }
3087
+ /**
3088
+ * If no conditions are specified, throw an error to prevent accidental deletion of all tokens
3089
+ */
3090
+ if (conditions.length === 0) {
3091
+ throw new Error('At least one query parameter must be provided');
3092
+ }
3055
3093
  return await Token.deleteMany({
3056
- $or: [
3057
- { userId: query.userId },
3058
- { token: query.token },
3059
- { email: query.email },
3060
- { identifier: query.identifier },
3061
- ],
3094
+ $or: conditions,
3062
3095
  });
3063
3096
  }
3064
3097
  catch (error) {
@@ -3069,7 +3102,7 @@ function createTokenMethods(mongoose) {
3069
3102
  /**
3070
3103
  * Finds a Token document that matches the provided query.
3071
3104
  */
3072
- async function findToken(query) {
3105
+ async function findToken(query, options) {
3073
3106
  try {
3074
3107
  const Token = mongoose.models.Token;
3075
3108
  const conditions = [];
@@ -3085,9 +3118,7 @@ function createTokenMethods(mongoose) {
3085
3118
  if (query.identifier) {
3086
3119
  conditions.push({ identifier: query.identifier });
3087
3120
  }
3088
- const token = await Token.findOne({
3089
- $and: conditions,
3090
- }).lean();
3121
+ const token = await Token.findOne({ $and: conditions }, null, options).lean();
3091
3122
  return token;
3092
3123
  }
3093
3124
  catch (error) {
@@ -4790,7 +4821,9 @@ function createShareMethods(mongoose) {
4790
4821
  }
4791
4822
  if (search && search.trim()) {
4792
4823
  try {
4793
- const searchResults = await Conversation.meiliSearch(search);
4824
+ const searchResults = await Conversation.meiliSearch(search, {
4825
+ filter: `user = "${user}"`,
4826
+ });
4794
4827
  if (!((_a = searchResults === null || searchResults === void 0 ? void 0 : searchResults.hits) === null || _a === void 0 ? void 0 : _a.length)) {
4795
4828
  return {
4796
4829
  links: [],