mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-07 19:18:52 +01:00
refactor(data-schemas): introduce new models and types for balance, conversation, message, and session
- Added new model files for Balance, Conversation, Message, and Session, enhancing modularity. - Created corresponding type definitions for IBalance, IConversation, IMessage, and updated existing types. - Refactored index files to export models from their individual files for better organization.
This commit is contained in:
parent
f6ca8caf7e
commit
fa9177180f
14 changed files with 174 additions and 99 deletions
|
|
@ -25,7 +25,6 @@ export { default as assistantSchema } from './schema/assistant';
|
|||
export type { IAssistant } from './schema/assistant';
|
||||
|
||||
export { default as balanceSchema } from './schema/balance';
|
||||
export type { IBalance } from './schema/balance';
|
||||
|
||||
export { default as bannerSchema } from './schema/banner';
|
||||
export type { IBanner } from './schema/banner';
|
||||
|
|
@ -37,7 +36,6 @@ export { default as conversationTagSchema } from './schema/conversationTag';
|
|||
export type { IConversationTag } from './schema/conversationTag';
|
||||
|
||||
export { default as convoSchema } from './schema/convo';
|
||||
export type { IConversation } from './schema/convo';
|
||||
|
||||
export { default as fileSchema } from './schema/file';
|
||||
export type { IMongoFile } from './schema/file';
|
||||
|
|
|
|||
6
packages/data-schemas/src/models/balance.ts
Normal file
6
packages/data-schemas/src/models/balance.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import mongoose from 'mongoose';
|
||||
import balanceSchema from '~/schema/balance';
|
||||
import type * as t from '~/types';
|
||||
|
||||
export const Balance =
|
||||
mongoose.models.Balance || mongoose.model<t.IBalance>('Balance', balanceSchema);
|
||||
17
packages/data-schemas/src/models/convo.ts
Normal file
17
packages/data-schemas/src/models/convo.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import mongoose from 'mongoose';
|
||||
import type * as t from '~/types';
|
||||
import mongoMeili from '~/models/plugins/mongoMeili';
|
||||
import convoSchema from '~/schema/convo';
|
||||
|
||||
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
||||
convoSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_MASTER_KEY,
|
||||
/** Note: Will get created automatically if it doesn't exist already */
|
||||
indexName: 'convos',
|
||||
primaryKey: 'conversationId',
|
||||
});
|
||||
}
|
||||
|
||||
export const Conversation =
|
||||
mongoose.models.Conversation || mongoose.model<t.IConversation>('Conversation', convoSchema);
|
||||
|
|
@ -1,25 +1,7 @@
|
|||
import mongoose from 'mongoose';
|
||||
|
||||
// Import schemas
|
||||
import userSchema from '~/schema/user';
|
||||
import sessionSchema from '~/schema/session';
|
||||
import tokenSchema from '~/schema/token';
|
||||
import balanceSchema from '~/schema/balance';
|
||||
|
||||
// Import types
|
||||
import { IUser, ISession, IToken } from '~/types';
|
||||
import { IBalance } from '~/schema/balance';
|
||||
|
||||
// Create and export model instances
|
||||
export const User = mongoose.model<IUser>('User', userSchema);
|
||||
export const Session = mongoose.model<ISession>('Session', sessionSchema);
|
||||
export const Token = mongoose.model<IToken>('Token', tokenSchema);
|
||||
export const Balance = mongoose.model<IBalance>('Balance', balanceSchema);
|
||||
|
||||
// Default export with all models
|
||||
export default {
|
||||
User,
|
||||
Session,
|
||||
Token,
|
||||
Balance,
|
||||
};
|
||||
// Export models from their individual files
|
||||
export { User } from './user';
|
||||
export { Token } from './token';
|
||||
export { Session } from './session';
|
||||
export { Balance } from './balance';
|
||||
export { Conversation } from './convo';
|
||||
export { Message } from './message';
|
||||
|
|
|
|||
16
packages/data-schemas/src/models/message.ts
Normal file
16
packages/data-schemas/src/models/message.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import mongoose from 'mongoose';
|
||||
import mongoMeili from '~/models/plugins/mongoMeili';
|
||||
import messageSchema from '~/schema/message';
|
||||
import type * as t from '~/types';
|
||||
|
||||
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
||||
messageSchema.plugin(mongoMeili, {
|
||||
host: process.env.MEILI_HOST,
|
||||
apiKey: process.env.MEILI_MASTER_KEY,
|
||||
indexName: 'messages',
|
||||
primaryKey: 'messageId',
|
||||
});
|
||||
}
|
||||
|
||||
export const Message =
|
||||
mongoose.models.Message || mongoose.model<t.IMessage>('Message', messageSchema);
|
||||
6
packages/data-schemas/src/models/session.ts
Normal file
6
packages/data-schemas/src/models/session.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import mongoose from 'mongoose';
|
||||
import sessionSchema from '~/schema/session';
|
||||
import type * as t from '~/types';
|
||||
|
||||
export const Session =
|
||||
mongoose.models.Session || mongoose.model<t.ISession>('Session', sessionSchema);
|
||||
5
packages/data-schemas/src/models/token.ts
Normal file
5
packages/data-schemas/src/models/token.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import mongoose from 'mongoose';
|
||||
import tokenSchema from '~/schema/token';
|
||||
import type * as t from '~/types';
|
||||
|
||||
export const Token = mongoose.models.Token || mongoose.model<t.IToken>('Token', tokenSchema);
|
||||
5
packages/data-schemas/src/models/user.ts
Normal file
5
packages/data-schemas/src/models/user.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import mongoose from 'mongoose';
|
||||
import userSchema from '~/schema/user';
|
||||
import type * as t from '~/types';
|
||||
|
||||
export const User = mongoose.models.User || mongoose.model<t.IUser>('User', userSchema);
|
||||
|
|
@ -1,17 +1,7 @@
|
|||
import { Schema, Document, Types } from 'mongoose';
|
||||
import { Schema } from 'mongoose';
|
||||
import type * as t from '~/types';
|
||||
|
||||
export interface IBalance extends Document {
|
||||
user: Types.ObjectId;
|
||||
tokenCredits: number;
|
||||
// Automatic refill settings
|
||||
autoRefillEnabled: boolean;
|
||||
refillIntervalValue: number;
|
||||
refillIntervalUnit: 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months';
|
||||
lastRefill: Date;
|
||||
refillAmount: number;
|
||||
}
|
||||
|
||||
const balanceSchema = new Schema<IBalance>({
|
||||
const balanceSchema = new Schema<t.IBalance>({
|
||||
user: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'User',
|
||||
|
|
|
|||
|
|
@ -1,57 +1,6 @@
|
|||
import mongoose, { Schema, Document, Types } from 'mongoose';
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
import { conversationPreset } from './defaults';
|
||||
|
||||
// @ts-ignore
|
||||
export interface IConversation extends Document {
|
||||
conversationId: string;
|
||||
title?: string;
|
||||
user?: string;
|
||||
messages?: Types.ObjectId[];
|
||||
agentOptions?: unknown;
|
||||
// Fields provided by conversationPreset (adjust types as needed)
|
||||
endpoint?: string;
|
||||
endpointType?: string;
|
||||
model?: string;
|
||||
region?: string;
|
||||
chatGptLabel?: string;
|
||||
examples?: unknown[];
|
||||
modelLabel?: string;
|
||||
promptPrefix?: string;
|
||||
temperature?: number;
|
||||
top_p?: number;
|
||||
topP?: number;
|
||||
topK?: number;
|
||||
maxOutputTokens?: number;
|
||||
maxTokens?: number;
|
||||
presence_penalty?: number;
|
||||
frequency_penalty?: number;
|
||||
file_ids?: string[];
|
||||
resendImages?: boolean;
|
||||
promptCache?: boolean;
|
||||
thinking?: boolean;
|
||||
thinkingBudget?: number;
|
||||
system?: string;
|
||||
resendFiles?: boolean;
|
||||
imageDetail?: string;
|
||||
agent_id?: string;
|
||||
assistant_id?: string;
|
||||
instructions?: string;
|
||||
stop?: string[];
|
||||
isArchived?: boolean;
|
||||
iconURL?: string;
|
||||
greeting?: string;
|
||||
spec?: string;
|
||||
tags?: string[];
|
||||
tools?: string[];
|
||||
maxContextTokens?: number;
|
||||
max_tokens?: number;
|
||||
reasoning_effort?: string;
|
||||
// Additional fields
|
||||
files?: string[];
|
||||
expiredAt?: Date;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
import { IConversation } from '~/types';
|
||||
|
||||
const convoSchema: Schema<IConversation> = new Schema(
|
||||
{
|
||||
|
|
|
|||
12
packages/data-schemas/src/types/balance.ts
Normal file
12
packages/data-schemas/src/types/balance.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { Document, Types } from 'mongoose';
|
||||
|
||||
export interface IBalance extends Document {
|
||||
user: Types.ObjectId;
|
||||
tokenCredits: number;
|
||||
// Automatic refill settings
|
||||
autoRefillEnabled: boolean;
|
||||
refillIntervalValue: number;
|
||||
refillIntervalUnit: 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months';
|
||||
lastRefill: Date;
|
||||
refillAmount: number;
|
||||
}
|
||||
53
packages/data-schemas/src/types/convo.ts
Normal file
53
packages/data-schemas/src/types/convo.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import type { Document, Types } from 'mongoose';
|
||||
|
||||
// @ts-ignore
|
||||
export interface IConversation extends Document {
|
||||
conversationId: string;
|
||||
title?: string;
|
||||
user?: string;
|
||||
messages?: Types.ObjectId[];
|
||||
agentOptions?: unknown;
|
||||
// Fields provided by conversationPreset (adjust types as needed)
|
||||
endpoint?: string;
|
||||
endpointType?: string;
|
||||
model?: string;
|
||||
region?: string;
|
||||
chatGptLabel?: string;
|
||||
examples?: unknown[];
|
||||
modelLabel?: string;
|
||||
promptPrefix?: string;
|
||||
temperature?: number;
|
||||
top_p?: number;
|
||||
topP?: number;
|
||||
topK?: number;
|
||||
maxOutputTokens?: number;
|
||||
maxTokens?: number;
|
||||
presence_penalty?: number;
|
||||
frequency_penalty?: number;
|
||||
file_ids?: string[];
|
||||
resendImages?: boolean;
|
||||
promptCache?: boolean;
|
||||
thinking?: boolean;
|
||||
thinkingBudget?: number;
|
||||
system?: string;
|
||||
resendFiles?: boolean;
|
||||
imageDetail?: string;
|
||||
agent_id?: string;
|
||||
assistant_id?: string;
|
||||
instructions?: string;
|
||||
stop?: string[];
|
||||
isArchived?: boolean;
|
||||
iconURL?: string;
|
||||
greeting?: string;
|
||||
spec?: string;
|
||||
tags?: string[];
|
||||
tools?: string[];
|
||||
maxContextTokens?: number;
|
||||
max_tokens?: number;
|
||||
reasoning_effort?: string;
|
||||
// Additional fields
|
||||
files?: string[];
|
||||
expiredAt?: Date;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
// User types
|
||||
export * from './user';
|
||||
|
||||
// Session types
|
||||
export * from './session';
|
||||
|
||||
// Token types
|
||||
export * from './token';
|
||||
export * from './convo';
|
||||
export * from './session';
|
||||
export * from './balance';
|
||||
export * from './message';
|
||||
|
|
|
|||
38
packages/data-schemas/src/types/message.ts
Normal file
38
packages/data-schemas/src/types/message.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import type { Document } from 'mongoose';
|
||||
|
||||
// @ts-ignore
|
||||
export interface IMessage extends Document {
|
||||
messageId: string;
|
||||
conversationId: string;
|
||||
user: string;
|
||||
model?: string;
|
||||
endpoint?: string;
|
||||
conversationSignature?: string;
|
||||
clientId?: string;
|
||||
invocationId?: number;
|
||||
parentMessageId?: string;
|
||||
tokenCount?: number;
|
||||
summaryTokenCount?: number;
|
||||
sender?: string;
|
||||
text?: string;
|
||||
summary?: string;
|
||||
isCreatedByUser: boolean;
|
||||
unfinished?: boolean;
|
||||
error?: boolean;
|
||||
finish_reason?: string;
|
||||
_meiliIndex?: boolean;
|
||||
files?: unknown[];
|
||||
plugin?: {
|
||||
latest?: string;
|
||||
inputs?: unknown[];
|
||||
outputs?: string;
|
||||
};
|
||||
plugins?: unknown[];
|
||||
content?: unknown[];
|
||||
thread_id?: string;
|
||||
iconURL?: string;
|
||||
attachments?: unknown[];
|
||||
expiredAt?: Date;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue