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