2025-05-30 22:18:13 -04:00
|
|
|
import { Schema } from 'mongoose';
|
2025-03-07 17:55:44 +01:00
|
|
|
import { conversationPreset } from './defaults';
|
2025-05-30 22:18:13 -04:00
|
|
|
import { IConversation } from '~/types';
|
2025-03-07 17:55:44 +01:00
|
|
|
|
|
|
|
|
const convoSchema: Schema<IConversation> = new Schema(
|
|
|
|
|
{
|
|
|
|
|
conversationId: {
|
|
|
|
|
type: String,
|
|
|
|
|
unique: true,
|
|
|
|
|
required: true,
|
|
|
|
|
index: true,
|
|
|
|
|
meiliIndex: true,
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'New Chat',
|
|
|
|
|
meiliIndex: true,
|
|
|
|
|
},
|
|
|
|
|
user: {
|
|
|
|
|
type: String,
|
|
|
|
|
index: true,
|
|
|
|
|
},
|
2025-05-30 22:18:13 -04:00
|
|
|
messages: [{ type: Schema.Types.ObjectId, ref: 'Message' }],
|
2025-03-07 17:55:44 +01:00
|
|
|
agentOptions: {
|
2025-05-30 22:18:13 -04:00
|
|
|
type: Schema.Types.Mixed,
|
2025-03-07 17:55:44 +01:00
|
|
|
},
|
|
|
|
|
...conversationPreset,
|
|
|
|
|
agent_id: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
tags: {
|
|
|
|
|
type: [String],
|
|
|
|
|
default: [],
|
|
|
|
|
meiliIndex: true,
|
|
|
|
|
},
|
|
|
|
|
files: {
|
|
|
|
|
type: [String],
|
|
|
|
|
},
|
|
|
|
|
expiredAt: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{ timestamps: true },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
convoSchema.index({ expiredAt: 1 }, { expireAfterSeconds: 0 });
|
|
|
|
|
convoSchema.index({ createdAt: 1, updatedAt: 1 });
|
|
|
|
|
convoSchema.index({ conversationId: 1, user: 1 }, { unique: true });
|
|
|
|
|
|
|
|
|
|
export default convoSchema;
|