@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,101 @@
1
+ import mongoose, { Schema, Document, Types } from 'mongoose';
2
+ import { conversationPreset } from './defaults';
3
+
4
+ // @ts-ignore
5
+ export interface IConversation extends Document {
6
+ conversationId: string;
7
+ title?: string;
8
+ user?: string;
9
+ messages?: Types.ObjectId[];
10
+ agentOptions?: unknown;
11
+ // Fields provided by conversationPreset (adjust types as needed)
12
+ endpoint?: string;
13
+ endpointType?: string;
14
+ model?: string;
15
+ region?: string;
16
+ chatGptLabel?: string;
17
+ examples?: unknown[];
18
+ modelLabel?: string;
19
+ promptPrefix?: string;
20
+ temperature?: number;
21
+ top_p?: number;
22
+ topP?: number;
23
+ topK?: number;
24
+ maxOutputTokens?: number;
25
+ maxTokens?: number;
26
+ presence_penalty?: number;
27
+ frequency_penalty?: number;
28
+ file_ids?: string[];
29
+ resendImages?: boolean;
30
+ promptCache?: boolean;
31
+ thinking?: boolean;
32
+ thinkingBudget?: number;
33
+ system?: string;
34
+ resendFiles?: boolean;
35
+ imageDetail?: string;
36
+ agent_id?: string;
37
+ assistant_id?: string;
38
+ instructions?: string;
39
+ stop?: string[];
40
+ isArchived?: boolean;
41
+ iconURL?: string;
42
+ greeting?: string;
43
+ spec?: string;
44
+ tags?: string[];
45
+ tools?: string[];
46
+ maxContextTokens?: number;
47
+ max_tokens?: number;
48
+ reasoning_effort?: string;
49
+ // Additional fields
50
+ files?: string[];
51
+ expiredAt?: Date;
52
+ createdAt?: Date;
53
+ updatedAt?: Date;
54
+ }
55
+
56
+ const convoSchema: Schema<IConversation> = new Schema(
57
+ {
58
+ conversationId: {
59
+ type: String,
60
+ unique: true,
61
+ required: true,
62
+ index: true,
63
+ meiliIndex: true,
64
+ },
65
+ title: {
66
+ type: String,
67
+ default: 'New Chat',
68
+ meiliIndex: true,
69
+ },
70
+ user: {
71
+ type: String,
72
+ index: true,
73
+ },
74
+ messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
75
+ agentOptions: {
76
+ type: mongoose.Schema.Types.Mixed,
77
+ },
78
+ ...conversationPreset,
79
+ agent_id: {
80
+ type: String,
81
+ },
82
+ tags: {
83
+ type: [String],
84
+ default: [],
85
+ meiliIndex: true,
86
+ },
87
+ files: {
88
+ type: [String],
89
+ },
90
+ expiredAt: {
91
+ type: Date,
92
+ },
93
+ },
94
+ { timestamps: true },
95
+ );
96
+
97
+ convoSchema.index({ expiredAt: 1 }, { expireAfterSeconds: 0 });
98
+ convoSchema.index({ createdAt: 1, updatedAt: 1 });
99
+ convoSchema.index({ conversationId: 1, user: 1 }, { unique: true });
100
+
101
+ export default convoSchema;
@@ -0,0 +1,138 @@
1
+ import { Schema } from 'mongoose';
2
+
3
+ // @ts-ignore
4
+ export const conversationPreset = {
5
+ // endpoint: [azureOpenAI, openAI, anthropic, chatGPTBrowser]
6
+ endpoint: {
7
+ type: String,
8
+ default: null,
9
+ required: true,
10
+ },
11
+ endpointType: {
12
+ type: String,
13
+ },
14
+ // for azureOpenAI, openAI, chatGPTBrowser only
15
+ model: {
16
+ type: String,
17
+ required: false,
18
+ },
19
+ // for bedrock only
20
+ region: {
21
+ type: String,
22
+ required: false,
23
+ },
24
+ // for azureOpenAI, openAI only
25
+ chatGptLabel: {
26
+ type: String,
27
+ required: false,
28
+ },
29
+ // for google only
30
+ examples: { type: [{ type: Schema.Types.Mixed }], default: undefined },
31
+ modelLabel: {
32
+ type: String,
33
+ required: false,
34
+ },
35
+ promptPrefix: {
36
+ type: String,
37
+ required: false,
38
+ },
39
+ temperature: {
40
+ type: Number,
41
+ required: false,
42
+ },
43
+ top_p: {
44
+ type: Number,
45
+ required: false,
46
+ },
47
+ // for google only
48
+ topP: {
49
+ type: Number,
50
+ required: false,
51
+ },
52
+ topK: {
53
+ type: Number,
54
+ required: false,
55
+ },
56
+ maxOutputTokens: {
57
+ type: Number,
58
+ required: false,
59
+ },
60
+ maxTokens: {
61
+ type: Number,
62
+ required: false,
63
+ },
64
+ presence_penalty: {
65
+ type: Number,
66
+ required: false,
67
+ },
68
+ frequency_penalty: {
69
+ type: Number,
70
+ required: false,
71
+ },
72
+ file_ids: { type: [{ type: String }], default: undefined },
73
+ // deprecated
74
+ resendImages: {
75
+ type: Boolean,
76
+ },
77
+ /* Anthropic only */
78
+ promptCache: {
79
+ type: Boolean,
80
+ },
81
+ thinking: {
82
+ type: Boolean,
83
+ },
84
+ thinkingBudget: {
85
+ type: Number,
86
+ },
87
+ system: {
88
+ type: String,
89
+ },
90
+ // files
91
+ resendFiles: {
92
+ type: Boolean,
93
+ },
94
+ imageDetail: {
95
+ type: String,
96
+ },
97
+ /* agents */
98
+ agent_id: {
99
+ type: String,
100
+ },
101
+ /* assistants */
102
+ assistant_id: {
103
+ type: String,
104
+ },
105
+ instructions: {
106
+ type: String,
107
+ },
108
+ stop: { type: [{ type: String }], default: undefined },
109
+ isArchived: {
110
+ type: Boolean,
111
+ default: false,
112
+ },
113
+ /* UI Components */
114
+ iconURL: {
115
+ type: String,
116
+ },
117
+ greeting: {
118
+ type: String,
119
+ },
120
+ spec: {
121
+ type: String,
122
+ },
123
+ tags: {
124
+ type: [String],
125
+ default: [],
126
+ },
127
+ tools: { type: [{ type: String }], default: undefined },
128
+ maxContextTokens: {
129
+ type: Number,
130
+ },
131
+ max_tokens: {
132
+ type: Number,
133
+ },
134
+ /** omni models only */
135
+ reasoning_effort: {
136
+ type: String,
137
+ },
138
+ };
@@ -0,0 +1,107 @@
1
+ import mongoose, { Schema, Document, Types } from 'mongoose';
2
+ import { FileSources } from 'librechat-data-provider';
3
+
4
+ // @ts-ignore
5
+ export interface IMongoFile extends Document {
6
+ user: Types.ObjectId;
7
+ conversationId?: string;
8
+ file_id: string;
9
+ temp_file_id?: string;
10
+ bytes: number;
11
+ filename: string;
12
+ filepath: string;
13
+ object: 'file';
14
+ embedded?: boolean;
15
+ type: string;
16
+ context?: string;
17
+ usage: number;
18
+ source: string;
19
+ model?: string;
20
+ width?: number;
21
+ height?: number;
22
+ metadata?: {
23
+ fileIdentifier?: string;
24
+ };
25
+ expiresAt?: Date;
26
+ createdAt?: Date;
27
+ updatedAt?: Date;
28
+ }
29
+
30
+ const file: Schema<IMongoFile> = new Schema(
31
+ {
32
+ user: {
33
+ type: mongoose.Schema.Types.ObjectId,
34
+ ref: 'User',
35
+ index: true,
36
+ required: true,
37
+ },
38
+ conversationId: {
39
+ type: String,
40
+ ref: 'Conversation',
41
+ index: true,
42
+ },
43
+ file_id: {
44
+ type: String,
45
+ index: true,
46
+ required: true,
47
+ },
48
+ temp_file_id: {
49
+ type: String,
50
+ },
51
+ bytes: {
52
+ type: Number,
53
+ required: true,
54
+ },
55
+ filename: {
56
+ type: String,
57
+ required: true,
58
+ },
59
+ filepath: {
60
+ type: String,
61
+ required: true,
62
+ },
63
+ object: {
64
+ type: String,
65
+ required: true,
66
+ default: 'file',
67
+ },
68
+ embedded: {
69
+ type: Boolean,
70
+ },
71
+ type: {
72
+ type: String,
73
+ required: true,
74
+ },
75
+ context: {
76
+ type: String,
77
+ },
78
+ usage: {
79
+ type: Number,
80
+ required: true,
81
+ default: 0,
82
+ },
83
+ source: {
84
+ type: String,
85
+ default: FileSources.local,
86
+ },
87
+ model: {
88
+ type: String,
89
+ },
90
+ width: Number,
91
+ height: Number,
92
+ metadata: {
93
+ fileIdentifier: String,
94
+ },
95
+ expiresAt: {
96
+ type: Date,
97
+ expires: 3600, // 1 hour in seconds
98
+ },
99
+ },
100
+ {
101
+ timestamps: true,
102
+ },
103
+ );
104
+
105
+ file.index({ createdAt: 1, updatedAt: 1 });
106
+
107
+ export default file;
@@ -0,0 +1,31 @@
1
+ import mongoose, { Schema, Document, Types } from 'mongoose';
2
+
3
+ export interface IKey extends Document {
4
+ userId: Types.ObjectId;
5
+ name: string;
6
+ value: string;
7
+ expiresAt?: Date;
8
+ }
9
+
10
+ const keySchema: Schema<IKey> = new Schema({
11
+ userId: {
12
+ type: mongoose.Schema.Types.ObjectId,
13
+ ref: 'User',
14
+ required: true,
15
+ },
16
+ name: {
17
+ type: String,
18
+ required: true,
19
+ },
20
+ value: {
21
+ type: String,
22
+ required: true,
23
+ },
24
+ expiresAt: {
25
+ type: Date,
26
+ },
27
+ });
28
+
29
+ keySchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
30
+
31
+ export default keySchema;
@@ -0,0 +1,185 @@
1
+ import mongoose, { Schema, Document } from 'mongoose';
2
+
3
+ // @ts-ignore
4
+ export interface IMessage extends Document {
5
+ messageId: string;
6
+ conversationId: string;
7
+ user: string;
8
+ model?: string;
9
+ endpoint?: string;
10
+ conversationSignature?: string;
11
+ clientId?: string;
12
+ invocationId?: number;
13
+ parentMessageId?: string;
14
+ tokenCount?: number;
15
+ summaryTokenCount?: number;
16
+ sender?: string;
17
+ text?: string;
18
+ summary?: string;
19
+ isCreatedByUser: boolean;
20
+ unfinished?: boolean;
21
+ error?: boolean;
22
+ finish_reason?: string;
23
+ _meiliIndex?: boolean;
24
+ files?: unknown[];
25
+ plugin?: {
26
+ latest?: string;
27
+ inputs?: unknown[];
28
+ outputs?: string;
29
+ };
30
+ plugins?: unknown[];
31
+ content?: unknown[];
32
+ thread_id?: string;
33
+ iconURL?: string;
34
+ attachments?: unknown[];
35
+ expiredAt?: Date;
36
+ createdAt?: Date;
37
+ updatedAt?: Date;
38
+ }
39
+
40
+ const messageSchema: Schema<IMessage> = new Schema(
41
+ {
42
+ messageId: {
43
+ type: String,
44
+ unique: true,
45
+ required: true,
46
+ index: true,
47
+ meiliIndex: true,
48
+ },
49
+ conversationId: {
50
+ type: String,
51
+ index: true,
52
+ required: true,
53
+ meiliIndex: true,
54
+ },
55
+ user: {
56
+ type: String,
57
+ index: true,
58
+ required: true,
59
+ default: null,
60
+ },
61
+ model: {
62
+ type: String,
63
+ default: null,
64
+ },
65
+ endpoint: {
66
+ type: String,
67
+ },
68
+ conversationSignature: {
69
+ type: String,
70
+ },
71
+ clientId: {
72
+ type: String,
73
+ },
74
+ invocationId: {
75
+ type: Number,
76
+ },
77
+ parentMessageId: {
78
+ type: String,
79
+ },
80
+ tokenCount: {
81
+ type: Number,
82
+ },
83
+ summaryTokenCount: {
84
+ type: Number,
85
+ },
86
+ sender: {
87
+ type: String,
88
+ meiliIndex: true,
89
+ },
90
+ text: {
91
+ type: String,
92
+ meiliIndex: true,
93
+ },
94
+ summary: {
95
+ type: String,
96
+ },
97
+ isCreatedByUser: {
98
+ type: Boolean,
99
+ required: true,
100
+ default: false,
101
+ },
102
+ unfinished: {
103
+ type: Boolean,
104
+ default: false,
105
+ },
106
+ error: {
107
+ type: Boolean,
108
+ default: false,
109
+ },
110
+ finish_reason: {
111
+ type: String,
112
+ },
113
+ _meiliIndex: {
114
+ type: Boolean,
115
+ required: false,
116
+ select: false,
117
+ default: false,
118
+ },
119
+ files: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
120
+ plugin: {
121
+ type: {
122
+ latest: {
123
+ type: String,
124
+ required: false,
125
+ },
126
+ inputs: {
127
+ type: [mongoose.Schema.Types.Mixed],
128
+ required: false,
129
+ default: undefined,
130
+ },
131
+ outputs: {
132
+ type: String,
133
+ required: false,
134
+ },
135
+ },
136
+ default: undefined,
137
+ },
138
+ plugins: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
139
+ content: {
140
+ type: [{ type: mongoose.Schema.Types.Mixed }],
141
+ default: undefined,
142
+ meiliIndex: true,
143
+ },
144
+ thread_id: {
145
+ type: String,
146
+ },
147
+ /* frontend components */
148
+ iconURL: {
149
+ type: String,
150
+ },
151
+ attachments: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
152
+ /*
153
+ attachments: {
154
+ type: [
155
+ {
156
+ file_id: String,
157
+ filename: String,
158
+ filepath: String,
159
+ expiresAt: Date,
160
+ width: Number,
161
+ height: Number,
162
+ type: String,
163
+ conversationId: String,
164
+ messageId: {
165
+ type: String,
166
+ required: true,
167
+ },
168
+ toolCallId: String,
169
+ },
170
+ ],
171
+ default: undefined,
172
+ },
173
+ */
174
+ expiredAt: {
175
+ type: Date,
176
+ },
177
+ },
178
+ { timestamps: true },
179
+ );
180
+
181
+ messageSchema.index({ expiredAt: 1 }, { expireAfterSeconds: 0 });
182
+ messageSchema.index({ createdAt: 1 });
183
+ messageSchema.index({ messageId: 1, user: 1 }, { unique: true });
184
+
185
+ export default messageSchema;
@@ -0,0 +1,33 @@
1
+ import { Schema, Document } from 'mongoose';
2
+
3
+ export interface IPluginAuth extends Document {
4
+ authField: string;
5
+ value: string;
6
+ userId: string;
7
+ pluginKey?: string;
8
+ createdAt?: Date;
9
+ updatedAt?: Date;
10
+ }
11
+
12
+ const pluginAuthSchema: Schema<IPluginAuth> = new Schema(
13
+ {
14
+ authField: {
15
+ type: String,
16
+ required: true,
17
+ },
18
+ value: {
19
+ type: String,
20
+ required: true,
21
+ },
22
+ userId: {
23
+ type: String,
24
+ required: true,
25
+ },
26
+ pluginKey: {
27
+ type: String,
28
+ },
29
+ },
30
+ { timestamps: true },
31
+ );
32
+
33
+ export default pluginAuthSchema;
@@ -0,0 +1,85 @@
1
+ import mongoose, { Schema, Document } from 'mongoose';
2
+ import { conversationPreset } from './defaults';
3
+
4
+ // @ts-ignore
5
+ export interface IPreset extends Document {
6
+ presetId: string;
7
+ title: string;
8
+ user: string | null;
9
+ defaultPreset?: boolean;
10
+ order?: number;
11
+ // Additional fields from conversationPreset and others will be available via an index signature.
12
+ endpoint?: string;
13
+ endpointType?: string;
14
+ model?: string;
15
+ region?: string;
16
+ chatGptLabel?: string;
17
+ examples?: unknown[];
18
+ modelLabel?: string;
19
+ promptPrefix?: string;
20
+ temperature?: number;
21
+ top_p?: number;
22
+ topP?: number;
23
+ topK?: number;
24
+ maxOutputTokens?: number;
25
+ maxTokens?: number;
26
+ presence_penalty?: number;
27
+ frequency_penalty?: number;
28
+ file_ids?: string[];
29
+ resendImages?: boolean;
30
+ promptCache?: boolean;
31
+ thinking?: boolean;
32
+ thinkingBudget?: number;
33
+ system?: string;
34
+ resendFiles?: boolean;
35
+ imageDetail?: string;
36
+ agent_id?: string;
37
+ assistant_id?: string;
38
+ instructions?: string;
39
+ stop?: string[];
40
+ isArchived?: boolean;
41
+ iconURL?: string;
42
+ greeting?: string;
43
+ spec?: string;
44
+ tags?: string[];
45
+ tools?: string[];
46
+ maxContextTokens?: number;
47
+ max_tokens?: number;
48
+ reasoning_effort?: string;
49
+ // end of additional fields
50
+ agentOptions?: unknown;
51
+ }
52
+
53
+ const presetSchema: Schema<IPreset> = new Schema(
54
+ {
55
+ presetId: {
56
+ type: String,
57
+ unique: true,
58
+ required: true,
59
+ index: true,
60
+ },
61
+ title: {
62
+ type: String,
63
+ default: 'New Chat',
64
+ meiliIndex: true,
65
+ },
66
+ user: {
67
+ type: String,
68
+ default: null,
69
+ },
70
+ defaultPreset: {
71
+ type: Boolean,
72
+ },
73
+ order: {
74
+ type: Number,
75
+ },
76
+ ...conversationPreset,
77
+ agentOptions: {
78
+ type: mongoose.Schema.Types.Mixed,
79
+ default: null,
80
+ },
81
+ },
82
+ { timestamps: true },
83
+ );
84
+
85
+ export default presetSchema;
@@ -0,0 +1,34 @@
1
+ import { Schema, Document, Types } from 'mongoose';
2
+
3
+ export interface IMongoProject extends Document {
4
+ name: string;
5
+ promptGroupIds: Types.ObjectId[];
6
+ agentIds: string[];
7
+ createdAt?: Date;
8
+ updatedAt?: Date;
9
+ }
10
+
11
+ const projectSchema = new Schema<IMongoProject>(
12
+ {
13
+ name: {
14
+ type: String,
15
+ required: true,
16
+ index: true,
17
+ },
18
+ promptGroupIds: {
19
+ type: [Schema.Types.ObjectId],
20
+ ref: 'PromptGroup',
21
+ default: [],
22
+ },
23
+ agentIds: {
24
+ type: [String],
25
+ ref: 'Agent',
26
+ default: [],
27
+ },
28
+ },
29
+ {
30
+ timestamps: true,
31
+ },
32
+ );
33
+
34
+ export default projectSchema;