@librechat/data-schemas 0.0.1

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.
@@ -0,0 +1,42 @@
1
+ import { Schema, Document, Types } from 'mongoose';
2
+
3
+ export interface IPrompt extends Document {
4
+ groupId: Types.ObjectId;
5
+ author: Types.ObjectId;
6
+ prompt: string;
7
+ type: 'text' | 'chat';
8
+ createdAt?: Date;
9
+ updatedAt?: Date;
10
+ }
11
+
12
+ const promptSchema: Schema<IPrompt> = new Schema(
13
+ {
14
+ groupId: {
15
+ type: Schema.Types.ObjectId,
16
+ ref: 'PromptGroup',
17
+ required: true,
18
+ index: true,
19
+ },
20
+ author: {
21
+ type: Schema.Types.ObjectId,
22
+ ref: 'User',
23
+ required: true,
24
+ },
25
+ prompt: {
26
+ type: String,
27
+ required: true,
28
+ },
29
+ type: {
30
+ type: String,
31
+ enum: ['text', 'chat'],
32
+ required: true,
33
+ },
34
+ },
35
+ {
36
+ timestamps: true,
37
+ },
38
+ );
39
+
40
+ promptSchema.index({ createdAt: 1, updatedAt: 1 });
41
+
42
+ export default promptSchema;
@@ -0,0 +1,85 @@
1
+ import { Schema, Document, Types } from 'mongoose';
2
+ import { Constants } from 'librechat-data-provider';
3
+
4
+ export interface IPromptGroup {
5
+ name: string;
6
+ numberOfGenerations: number;
7
+ oneliner: string;
8
+ category: string;
9
+ projectIds: Types.ObjectId[];
10
+ productionId: Types.ObjectId;
11
+ author: Types.ObjectId;
12
+ authorName: string;
13
+ command?: string;
14
+ createdAt?: Date;
15
+ updatedAt?: Date;
16
+ }
17
+
18
+ export interface IPromptGroupDocument extends IPromptGroup, Document {}
19
+
20
+ const promptGroupSchema = new Schema<IPromptGroupDocument>(
21
+ {
22
+ name: {
23
+ type: String,
24
+ required: true,
25
+ index: true,
26
+ },
27
+ numberOfGenerations: {
28
+ type: Number,
29
+ default: 0,
30
+ },
31
+ oneliner: {
32
+ type: String,
33
+ default: '',
34
+ },
35
+ category: {
36
+ type: String,
37
+ default: '',
38
+ index: true,
39
+ },
40
+ projectIds: {
41
+ type: [Schema.Types.ObjectId],
42
+ ref: 'Project',
43
+ index: true,
44
+ default: [],
45
+ },
46
+ productionId: {
47
+ type: Schema.Types.ObjectId,
48
+ ref: 'Prompt',
49
+ required: true,
50
+ index: true,
51
+ },
52
+ author: {
53
+ type: Schema.Types.ObjectId,
54
+ ref: 'User',
55
+ required: true,
56
+ index: true,
57
+ },
58
+ authorName: {
59
+ type: String,
60
+ required: true,
61
+ },
62
+ command: {
63
+ type: String,
64
+ index: true,
65
+ validate: {
66
+ validator: function (v: unknown): boolean {
67
+ return v === undefined || v === null || v === '' || /^[a-z0-9-]+$/.test(v);
68
+ },
69
+ message: (props: unknown) =>
70
+ `${props.value} is not a valid command. Only lowercase alphanumeric characters and hyphens are allowed.`,
71
+ },
72
+ maxlength: [
73
+ Constants.COMMANDS_MAX_LENGTH as number,
74
+ `Command cannot be longer than ${Constants.COMMANDS_MAX_LENGTH} characters`,
75
+ ],
76
+ }, // Casting here bypasses the type error for the command field.
77
+ },
78
+ {
79
+ timestamps: true,
80
+ },
81
+ );
82
+
83
+ promptGroupSchema.index({ createdAt: 1, updatedAt: 1 });
84
+
85
+ export default promptGroupSchema;
@@ -0,0 +1,91 @@
1
+ import { Schema, Document } from 'mongoose';
2
+ import { PermissionTypes, Permissions } from 'librechat-data-provider';
3
+
4
+ export interface IRole extends Document {
5
+ name: string;
6
+ [PermissionTypes.BOOKMARKS]?: {
7
+ [Permissions.USE]?: boolean;
8
+ };
9
+ [PermissionTypes.PROMPTS]?: {
10
+ [Permissions.SHARED_GLOBAL]?: boolean;
11
+ [Permissions.USE]?: boolean;
12
+ [Permissions.CREATE]?: boolean;
13
+ };
14
+ [PermissionTypes.AGENTS]?: {
15
+ [Permissions.SHARED_GLOBAL]?: boolean;
16
+ [Permissions.USE]?: boolean;
17
+ [Permissions.CREATE]?: boolean;
18
+ };
19
+ [PermissionTypes.MULTI_CONVO]?: {
20
+ [Permissions.USE]?: boolean;
21
+ };
22
+ [PermissionTypes.TEMPORARY_CHAT]?: {
23
+ [Permissions.USE]?: boolean;
24
+ };
25
+ [PermissionTypes.RUN_CODE]?: {
26
+ [Permissions.USE]?: boolean;
27
+ };
28
+ }
29
+
30
+ const roleSchema: Schema<IRole> = new Schema({
31
+ name: {
32
+ type: String,
33
+ required: true,
34
+ unique: true,
35
+ index: true,
36
+ },
37
+ [PermissionTypes.BOOKMARKS]: {
38
+ [Permissions.USE]: {
39
+ type: Boolean,
40
+ default: true,
41
+ },
42
+ },
43
+ [PermissionTypes.PROMPTS]: {
44
+ [Permissions.SHARED_GLOBAL]: {
45
+ type: Boolean,
46
+ default: false,
47
+ },
48
+ [Permissions.USE]: {
49
+ type: Boolean,
50
+ default: true,
51
+ },
52
+ [Permissions.CREATE]: {
53
+ type: Boolean,
54
+ default: true,
55
+ },
56
+ },
57
+ [PermissionTypes.AGENTS]: {
58
+ [Permissions.SHARED_GLOBAL]: {
59
+ type: Boolean,
60
+ default: false,
61
+ },
62
+ [Permissions.USE]: {
63
+ type: Boolean,
64
+ default: true,
65
+ },
66
+ [Permissions.CREATE]: {
67
+ type: Boolean,
68
+ default: true,
69
+ },
70
+ },
71
+ [PermissionTypes.MULTI_CONVO]: {
72
+ [Permissions.USE]: {
73
+ type: Boolean,
74
+ default: true,
75
+ },
76
+ },
77
+ [PermissionTypes.TEMPORARY_CHAT]: {
78
+ [Permissions.USE]: {
79
+ type: Boolean,
80
+ default: true,
81
+ },
82
+ },
83
+ [PermissionTypes.RUN_CODE]: {
84
+ [Permissions.USE]: {
85
+ type: Boolean,
86
+ default: true,
87
+ },
88
+ },
89
+ });
90
+
91
+ export default roleSchema;
@@ -0,0 +1,26 @@
1
+ import mongoose, { Schema, Document, Types } from 'mongoose';
2
+
3
+ export interface ISession extends Document {
4
+ refreshTokenHash: string;
5
+ expiration: Date;
6
+ user: Types.ObjectId;
7
+ }
8
+
9
+ const sessionSchema: Schema<ISession> = new Schema({
10
+ refreshTokenHash: {
11
+ type: String,
12
+ required: true,
13
+ },
14
+ expiration: {
15
+ type: Date,
16
+ required: true,
17
+ expires: 0,
18
+ },
19
+ user: {
20
+ type: mongoose.Schema.Types.ObjectId,
21
+ ref: 'User',
22
+ required: true,
23
+ },
24
+ });
25
+
26
+ export default sessionSchema;
@@ -0,0 +1,41 @@
1
+ import mongoose, { Schema, Document, Types } from 'mongoose';
2
+
3
+ export interface ISharedLink extends Document {
4
+ conversationId: string;
5
+ title?: string;
6
+ user?: string;
7
+ messages?: Types.ObjectId[];
8
+ shareId?: string;
9
+ isPublic: boolean;
10
+ createdAt?: Date;
11
+ updatedAt?: Date;
12
+ }
13
+
14
+ const shareSchema: Schema<ISharedLink> = new Schema(
15
+ {
16
+ conversationId: {
17
+ type: String,
18
+ required: true,
19
+ },
20
+ title: {
21
+ type: String,
22
+ index: true,
23
+ },
24
+ user: {
25
+ type: String,
26
+ index: true,
27
+ },
28
+ messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
29
+ shareId: {
30
+ type: String,
31
+ index: true,
32
+ },
33
+ isPublic: {
34
+ type: Boolean,
35
+ default: true,
36
+ },
37
+ },
38
+ { timestamps: true },
39
+ );
40
+
41
+ export default shareSchema;
@@ -0,0 +1,50 @@
1
+ import { Schema, Document, Types } from 'mongoose';
2
+
3
+ export interface IToken extends Document {
4
+ userId: Types.ObjectId;
5
+ email?: string;
6
+ type?: string;
7
+ identifier?: string;
8
+ token: string;
9
+ createdAt: Date;
10
+ expiresAt: Date;
11
+ metadata?: Map<string, unknown>;
12
+ }
13
+
14
+ const tokenSchema: Schema<IToken> = new Schema({
15
+ userId: {
16
+ type: Schema.Types.ObjectId,
17
+ required: true,
18
+ ref: 'user',
19
+ },
20
+ email: {
21
+ type: String,
22
+ },
23
+ type: {
24
+ type: String,
25
+ },
26
+ identifier: {
27
+ type: String,
28
+ },
29
+ token: {
30
+ type: String,
31
+ required: true,
32
+ },
33
+ createdAt: {
34
+ type: Date,
35
+ required: true,
36
+ default: Date.now,
37
+ },
38
+ expiresAt: {
39
+ type: Date,
40
+ required: true,
41
+ },
42
+ metadata: {
43
+ type: Map,
44
+ of: Schema.Types.Mixed,
45
+ },
46
+ });
47
+
48
+ tokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
49
+
50
+ export default tokenSchema;
@@ -0,0 +1,55 @@
1
+ import mongoose, { Schema, Document, Types } from 'mongoose';
2
+ import type { TAttachment } from 'librechat-data-provider';
3
+
4
+ export interface IToolCallData extends Document {
5
+ conversationId: string;
6
+ messageId: string;
7
+ toolId: string;
8
+ user: Types.ObjectId;
9
+ result?: unknown;
10
+ attachments?: TAttachment[];
11
+ blockIndex?: number;
12
+ partIndex?: number;
13
+ createdAt?: Date;
14
+ updatedAt?: Date;
15
+ }
16
+
17
+ const toolCallSchema: Schema<IToolCallData> = new Schema(
18
+ {
19
+ conversationId: {
20
+ type: String,
21
+ required: true,
22
+ },
23
+ messageId: {
24
+ type: String,
25
+ required: true,
26
+ },
27
+ toolId: {
28
+ type: String,
29
+ required: true,
30
+ },
31
+ user: {
32
+ type: mongoose.Schema.Types.ObjectId,
33
+ ref: 'User',
34
+ required: true,
35
+ },
36
+ result: {
37
+ type: mongoose.Schema.Types.Mixed,
38
+ },
39
+ attachments: {
40
+ type: mongoose.Schema.Types.Mixed,
41
+ },
42
+ blockIndex: {
43
+ type: Number,
44
+ },
45
+ partIndex: {
46
+ type: Number,
47
+ },
48
+ },
49
+ { timestamps: true },
50
+ );
51
+
52
+ toolCallSchema.index({ messageId: 1, user: 1 });
53
+ toolCallSchema.index({ conversationId: 1, user: 1 });
54
+
55
+ export default toolCallSchema;
@@ -0,0 +1,60 @@
1
+ import mongoose, { Schema, Document, Types } from 'mongoose';
2
+
3
+ // @ts-ignore
4
+ export interface ITransaction extends Document {
5
+ user: Types.ObjectId;
6
+ conversationId?: string;
7
+ tokenType: 'prompt' | 'completion' | 'credits';
8
+ model?: string;
9
+ context?: string;
10
+ valueKey?: string;
11
+ rate?: number;
12
+ rawAmount?: number;
13
+ tokenValue?: number;
14
+ inputTokens?: number;
15
+ writeTokens?: number;
16
+ readTokens?: number;
17
+ createdAt?: Date;
18
+ updatedAt?: Date;
19
+ }
20
+
21
+ const transactionSchema: Schema<ITransaction> = new Schema(
22
+ {
23
+ user: {
24
+ type: mongoose.Schema.Types.ObjectId,
25
+ ref: 'User',
26
+ index: true,
27
+ required: true,
28
+ },
29
+ conversationId: {
30
+ type: String,
31
+ ref: 'Conversation',
32
+ index: true,
33
+ },
34
+ tokenType: {
35
+ type: String,
36
+ enum: ['prompt', 'completion', 'credits'],
37
+ required: true,
38
+ },
39
+ model: {
40
+ type: String,
41
+ },
42
+ context: {
43
+ type: String,
44
+ },
45
+ valueKey: {
46
+ type: String,
47
+ },
48
+ rate: Number,
49
+ rawAmount: Number,
50
+ tokenValue: Number,
51
+ inputTokens: { type: Number },
52
+ writeTokens: { type: Number },
53
+ readTokens: { type: Number },
54
+ },
55
+ {
56
+ timestamps: true,
57
+ },
58
+ );
59
+
60
+ export default transactionSchema;
@@ -0,0 +1,158 @@
1
+ import { Schema, Document } from 'mongoose';
2
+ import { SystemRoles } from 'librechat-data-provider';
3
+
4
+ export interface IUser extends Document {
5
+ name?: string;
6
+ username?: string;
7
+ email: string;
8
+ emailVerified: boolean;
9
+ password?: string;
10
+ avatar?: string;
11
+ provider: string;
12
+ role?: string;
13
+ googleId?: string;
14
+ facebookId?: string;
15
+ openidId?: string;
16
+ ldapId?: string;
17
+ githubId?: string;
18
+ discordId?: string;
19
+ appleId?: string;
20
+ plugins?: unknown[];
21
+ totpSecret?: string;
22
+ backupCodes?: Array<{
23
+ codeHash: string;
24
+ used: boolean;
25
+ usedAt?: Date | null;
26
+ }>;
27
+ refreshToken?: Array<{
28
+ refreshToken: string;
29
+ }>;
30
+ expiresAt?: Date;
31
+ termsAccepted?: boolean;
32
+ createdAt?: Date;
33
+ updatedAt?: Date;
34
+ }
35
+
36
+ // Session sub-schema
37
+ const SessionSchema = new Schema(
38
+ {
39
+ refreshToken: {
40
+ type: String,
41
+ default: '',
42
+ },
43
+ },
44
+ { _id: false },
45
+ );
46
+
47
+ // Backup code sub-schema
48
+ const BackupCodeSchema = new Schema(
49
+ {
50
+ codeHash: { type: String, required: true },
51
+ used: { type: Boolean, default: false },
52
+ usedAt: { type: Date, default: null },
53
+ },
54
+ { _id: false },
55
+ );
56
+
57
+ const User = new Schema<IUser>(
58
+ {
59
+ name: {
60
+ type: String,
61
+ },
62
+ username: {
63
+ type: String,
64
+ lowercase: true,
65
+ default: '',
66
+ },
67
+ email: {
68
+ type: String,
69
+ required: [true, 'can\'t be blank'],
70
+ lowercase: true,
71
+ unique: true,
72
+ match: [/\S+@\S+\.\S+/, 'is invalid'],
73
+ index: true,
74
+ },
75
+ emailVerified: {
76
+ type: Boolean,
77
+ required: true,
78
+ default: false,
79
+ },
80
+ password: {
81
+ type: String,
82
+ trim: true,
83
+ minlength: 8,
84
+ maxlength: 128,
85
+ },
86
+ avatar: {
87
+ type: String,
88
+ required: false,
89
+ },
90
+ provider: {
91
+ type: String,
92
+ required: true,
93
+ default: 'local',
94
+ },
95
+ role: {
96
+ type: String,
97
+ default: SystemRoles.USER,
98
+ },
99
+ googleId: {
100
+ type: String,
101
+ unique: true,
102
+ sparse: true,
103
+ },
104
+ facebookId: {
105
+ type: String,
106
+ unique: true,
107
+ sparse: true,
108
+ },
109
+ openidId: {
110
+ type: String,
111
+ unique: true,
112
+ sparse: true,
113
+ },
114
+ ldapId: {
115
+ type: String,
116
+ unique: true,
117
+ sparse: true,
118
+ },
119
+ githubId: {
120
+ type: String,
121
+ unique: true,
122
+ sparse: true,
123
+ },
124
+ discordId: {
125
+ type: String,
126
+ unique: true,
127
+ sparse: true,
128
+ },
129
+ appleId: {
130
+ type: String,
131
+ unique: true,
132
+ sparse: true,
133
+ },
134
+ plugins: {
135
+ type: Array,
136
+ },
137
+ totpSecret: {
138
+ type: String,
139
+ },
140
+ backupCodes: {
141
+ type: [BackupCodeSchema],
142
+ },
143
+ refreshToken: {
144
+ type: [SessionSchema],
145
+ },
146
+ expiresAt: {
147
+ type: Date,
148
+ expires: 604800, // 7 days in seconds
149
+ },
150
+ termsAccepted: {
151
+ type: Boolean,
152
+ default: false,
153
+ },
154
+ },
155
+ { timestamps: true },
156
+ );
157
+
158
+ export default User;
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationDir": "./dist/types",
5
+ "module": "esnext",
6
+ "noImplicitAny": true,
7
+ "outDir": "./dist",
8
+ "target": "es2015",
9
+ "moduleResolution": "node",
10
+ "lib": ["es2017", "dom", "ES2021.String"],
11
+ "skipLibCheck": true,
12
+ "esModuleInterop": true,
13
+ "strict": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+ "isolatedModules": true,
17
+ "noEmit": false,
18
+ "sourceMap": true,
19
+ "baseUrl": "."
20
+ },
21
+ "ts-node": {
22
+ "experimentalSpecifierResolution": "node",
23
+ "transpileOnly": true,
24
+ "esm": true
25
+ },
26
+ "exclude": ["node_modules", "dist", "types"],
27
+ "include": ["src/**/*", "types/index.d.ts", "types/react-query/index.d.ts"]
28
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "outDir": "./dist/tests",
6
+ "baseUrl": "."
7
+ },
8
+ "include": ["specs/**/*", "src/**/*"],
9
+ "exclude": ["node_modules", "dist"]
10
+ }