LibreChat/packages/data-schemas/src/models/message.ts
Danny Avila dff4fcac00
🔧 fix: Apply Mongoose Plugin at Model Creation (#7749)
* fix: apply mongoMeili when models are created to use main runtime mongoose

* chore: update @librechat/data-schemas version to 0.0.8

* refactor: remove unused useDebounceCodeBlock

* fix: ensure setter function is stable and handle numeric conversion in useDebouncedInput

* refactor: replace useCallback with useMemo for stable debounced function in useDebouncedInput
2025-06-04 23:11:34 -04:00

20 lines
670 B
TypeScript

import type * as t from '~/types';
import mongoMeili from '~/models/plugins/mongoMeili';
import messageSchema from '~/schema/message';
/**
* Creates or returns the Message model using the provided mongoose instance and schema
*/
export function createMessageModel(mongoose: typeof import('mongoose')) {
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
messageSchema.plugin(mongoMeili, {
mongoose,
host: process.env.MEILI_HOST,
apiKey: process.env.MEILI_MASTER_KEY,
indexName: 'messages',
primaryKey: 'messageId',
});
}
return mongoose.models.Message || mongoose.model<t.IMessage>('Message', messageSchema);
}