mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-22 02:06:12 +01:00
feat: Refactor prompt and prompt group schemas; move types to separate file feat: Implement paginated access to prompt groups with filtering and public visibility refactor: Add PromptGroups context provider and integrate it into relevant components refactor: Optimize filter change handling and query invalidation in usePromptGroupsNav hook refactor: Simplify context usage in FilterPrompts and GroupSidePanel components
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
import { Schema } from 'mongoose';
|
|
import { Constants } from 'librechat-data-provider';
|
|
import type { IPromptGroupDocument } from '~/types';
|
|
|
|
const promptGroupSchema = new Schema<IPromptGroupDocument>(
|
|
{
|
|
name: {
|
|
type: String,
|
|
required: true,
|
|
index: true,
|
|
},
|
|
numberOfGenerations: {
|
|
type: Number,
|
|
default: 0,
|
|
},
|
|
oneliner: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
category: {
|
|
type: String,
|
|
default: '',
|
|
index: true,
|
|
},
|
|
projectIds: {
|
|
type: [Schema.Types.ObjectId],
|
|
ref: 'Project',
|
|
index: true,
|
|
default: [],
|
|
},
|
|
productionId: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'Prompt',
|
|
required: true,
|
|
index: true,
|
|
},
|
|
author: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'User',
|
|
required: true,
|
|
index: true,
|
|
},
|
|
authorName: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
command: {
|
|
type: String,
|
|
index: true,
|
|
validate: {
|
|
validator: function (v: string | undefined | null): boolean {
|
|
return v === undefined || v === null || v === '' || /^[a-z0-9-]+$/.test(v);
|
|
},
|
|
message: (props: { value?: string } | undefined) =>
|
|
`${props?.value ?? 'Value'} is not a valid command. Only lowercase alphanumeric characters and hyphens are allowed.`,
|
|
},
|
|
maxlength: [
|
|
Constants.COMMANDS_MAX_LENGTH as number,
|
|
`Command cannot be longer than ${Constants.COMMANDS_MAX_LENGTH} characters`,
|
|
],
|
|
}, // Casting here bypasses the type error for the command field.
|
|
},
|
|
{
|
|
timestamps: true,
|
|
},
|
|
);
|
|
|
|
promptGroupSchema.index({ createdAt: 1, updatedAt: 1 });
|
|
|
|
export default promptGroupSchema;
|