@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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1143 @@
1
+ 'use strict';
2
+
3
+ var mongoose = require('mongoose');
4
+ var librechatDataProvider = require('librechat-data-provider');
5
+
6
+ // Define the Auth sub-schema with type-safety.
7
+ const AuthSchema = new mongoose.Schema({
8
+ authorization_type: { type: String },
9
+ custom_auth_header: { type: String },
10
+ type: { type: String, enum: ['service_http', 'oauth', 'none'] },
11
+ authorization_content_type: { type: String },
12
+ authorization_url: { type: String },
13
+ client_url: { type: String },
14
+ scope: { type: String },
15
+ token_exchange_method: { type: String, enum: ['default_post', 'basic_auth_header', null] },
16
+ }, { _id: false });
17
+ const Action = new mongoose.Schema({
18
+ user: {
19
+ type: mongoose.Schema.Types.ObjectId,
20
+ ref: 'User',
21
+ index: true,
22
+ required: true,
23
+ },
24
+ action_id: {
25
+ type: String,
26
+ index: true,
27
+ required: true,
28
+ },
29
+ type: {
30
+ type: String,
31
+ default: 'action_prototype',
32
+ },
33
+ settings: mongoose.Schema.Types.Mixed,
34
+ agent_id: String,
35
+ assistant_id: String,
36
+ metadata: {
37
+ api_key: String,
38
+ auth: AuthSchema,
39
+ domain: {
40
+ type: String,
41
+ required: true,
42
+ },
43
+ privacy_policy_url: String,
44
+ raw_spec: String,
45
+ oauth_client_id: String,
46
+ oauth_client_secret: String,
47
+ },
48
+ });
49
+
50
+ const agentSchema = new mongoose.Schema({
51
+ id: {
52
+ type: String,
53
+ index: true,
54
+ unique: true,
55
+ required: true,
56
+ },
57
+ name: {
58
+ type: String,
59
+ },
60
+ description: {
61
+ type: String,
62
+ },
63
+ instructions: {
64
+ type: String,
65
+ },
66
+ avatar: {
67
+ type: {
68
+ filepath: String,
69
+ source: String,
70
+ },
71
+ default: undefined,
72
+ },
73
+ provider: {
74
+ type: String,
75
+ required: true,
76
+ },
77
+ model: {
78
+ type: String,
79
+ required: true,
80
+ },
81
+ model_parameters: {
82
+ type: Object,
83
+ },
84
+ artifacts: {
85
+ type: String,
86
+ },
87
+ access_level: {
88
+ type: Number,
89
+ },
90
+ tools: {
91
+ type: [String],
92
+ default: undefined,
93
+ },
94
+ tool_kwargs: {
95
+ type: [{ type: mongoose.Schema.Types.Mixed }],
96
+ },
97
+ actions: {
98
+ type: [String],
99
+ default: undefined,
100
+ },
101
+ author: {
102
+ type: mongoose.Schema.Types.ObjectId,
103
+ ref: 'User',
104
+ required: true,
105
+ },
106
+ authorName: {
107
+ type: String,
108
+ default: undefined,
109
+ },
110
+ hide_sequential_outputs: {
111
+ type: Boolean,
112
+ },
113
+ end_after_tools: {
114
+ type: Boolean,
115
+ },
116
+ agent_ids: {
117
+ type: [String],
118
+ },
119
+ isCollaborative: {
120
+ type: Boolean,
121
+ default: undefined,
122
+ },
123
+ conversation_starters: {
124
+ type: [String],
125
+ default: [],
126
+ },
127
+ tool_resources: {
128
+ type: mongoose.Schema.Types.Mixed,
129
+ default: {},
130
+ },
131
+ projectIds: {
132
+ type: [mongoose.Schema.Types.ObjectId],
133
+ ref: 'Project',
134
+ index: true,
135
+ },
136
+ }, {
137
+ timestamps: true,
138
+ });
139
+
140
+ const assistantSchema = new mongoose.Schema({
141
+ user: {
142
+ type: mongoose.Schema.Types.ObjectId,
143
+ ref: 'User',
144
+ required: true,
145
+ },
146
+ assistant_id: {
147
+ type: String,
148
+ index: true,
149
+ required: true,
150
+ },
151
+ avatar: {
152
+ type: {
153
+ filepath: String,
154
+ source: String,
155
+ },
156
+ default: undefined,
157
+ },
158
+ conversation_starters: {
159
+ type: [String],
160
+ default: [],
161
+ },
162
+ access_level: {
163
+ type: Number,
164
+ },
165
+ file_ids: { type: [String], default: undefined },
166
+ actions: { type: [String], default: undefined },
167
+ append_current_datetime: {
168
+ type: Boolean,
169
+ default: false,
170
+ },
171
+ }, {
172
+ timestamps: true,
173
+ });
174
+
175
+ const balanceSchema = new mongoose.Schema({
176
+ user: {
177
+ type: mongoose.Schema.Types.ObjectId,
178
+ ref: 'User',
179
+ index: true,
180
+ required: true,
181
+ },
182
+ // 1000 tokenCredits = 1 mill ($0.001 USD)
183
+ tokenCredits: {
184
+ type: Number,
185
+ default: 0,
186
+ },
187
+ });
188
+
189
+ const bannerSchema = new mongoose.Schema({
190
+ bannerId: {
191
+ type: String,
192
+ required: true,
193
+ },
194
+ message: {
195
+ type: String,
196
+ required: true,
197
+ },
198
+ displayFrom: {
199
+ type: Date,
200
+ required: true,
201
+ default: Date.now,
202
+ },
203
+ displayTo: {
204
+ type: Date,
205
+ },
206
+ type: {
207
+ type: String,
208
+ enum: ['banner', 'popup'],
209
+ default: 'banner',
210
+ },
211
+ isPublic: {
212
+ type: Boolean,
213
+ default: false,
214
+ },
215
+ }, { timestamps: true });
216
+
217
+ const categoriesSchema = new mongoose.Schema({
218
+ label: {
219
+ type: String,
220
+ required: true,
221
+ unique: true,
222
+ },
223
+ value: {
224
+ type: String,
225
+ required: true,
226
+ unique: true,
227
+ },
228
+ });
229
+
230
+ const conversationTag = new mongoose.Schema({
231
+ tag: {
232
+ type: String,
233
+ index: true,
234
+ },
235
+ user: {
236
+ type: String,
237
+ index: true,
238
+ },
239
+ description: {
240
+ type: String,
241
+ index: true,
242
+ },
243
+ count: {
244
+ type: Number,
245
+ default: 0,
246
+ },
247
+ position: {
248
+ type: Number,
249
+ default: 0,
250
+ index: true,
251
+ },
252
+ }, { timestamps: true });
253
+ // Create a compound index on tag and user with unique constraint.
254
+ conversationTag.index({ tag: 1, user: 1 }, { unique: true });
255
+
256
+ // @ts-ignore
257
+ const conversationPreset = {
258
+ // endpoint: [azureOpenAI, openAI, anthropic, chatGPTBrowser]
259
+ endpoint: {
260
+ type: String,
261
+ default: null,
262
+ required: true,
263
+ },
264
+ endpointType: {
265
+ type: String,
266
+ },
267
+ // for azureOpenAI, openAI, chatGPTBrowser only
268
+ model: {
269
+ type: String,
270
+ required: false,
271
+ },
272
+ // for bedrock only
273
+ region: {
274
+ type: String,
275
+ required: false,
276
+ },
277
+ // for azureOpenAI, openAI only
278
+ chatGptLabel: {
279
+ type: String,
280
+ required: false,
281
+ },
282
+ // for google only
283
+ examples: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
284
+ modelLabel: {
285
+ type: String,
286
+ required: false,
287
+ },
288
+ promptPrefix: {
289
+ type: String,
290
+ required: false,
291
+ },
292
+ temperature: {
293
+ type: Number,
294
+ required: false,
295
+ },
296
+ top_p: {
297
+ type: Number,
298
+ required: false,
299
+ },
300
+ // for google only
301
+ topP: {
302
+ type: Number,
303
+ required: false,
304
+ },
305
+ topK: {
306
+ type: Number,
307
+ required: false,
308
+ },
309
+ maxOutputTokens: {
310
+ type: Number,
311
+ required: false,
312
+ },
313
+ maxTokens: {
314
+ type: Number,
315
+ required: false,
316
+ },
317
+ presence_penalty: {
318
+ type: Number,
319
+ required: false,
320
+ },
321
+ frequency_penalty: {
322
+ type: Number,
323
+ required: false,
324
+ },
325
+ file_ids: { type: [{ type: String }], default: undefined },
326
+ // deprecated
327
+ resendImages: {
328
+ type: Boolean,
329
+ },
330
+ /* Anthropic only */
331
+ promptCache: {
332
+ type: Boolean,
333
+ },
334
+ thinking: {
335
+ type: Boolean,
336
+ },
337
+ thinkingBudget: {
338
+ type: Number,
339
+ },
340
+ system: {
341
+ type: String,
342
+ },
343
+ // files
344
+ resendFiles: {
345
+ type: Boolean,
346
+ },
347
+ imageDetail: {
348
+ type: String,
349
+ },
350
+ /* agents */
351
+ agent_id: {
352
+ type: String,
353
+ },
354
+ /* assistants */
355
+ assistant_id: {
356
+ type: String,
357
+ },
358
+ instructions: {
359
+ type: String,
360
+ },
361
+ stop: { type: [{ type: String }], default: undefined },
362
+ isArchived: {
363
+ type: Boolean,
364
+ default: false,
365
+ },
366
+ /* UI Components */
367
+ iconURL: {
368
+ type: String,
369
+ },
370
+ greeting: {
371
+ type: String,
372
+ },
373
+ spec: {
374
+ type: String,
375
+ },
376
+ tags: {
377
+ type: [String],
378
+ default: [],
379
+ },
380
+ tools: { type: [{ type: String }], default: undefined },
381
+ maxContextTokens: {
382
+ type: Number,
383
+ },
384
+ max_tokens: {
385
+ type: Number,
386
+ },
387
+ /** omni models only */
388
+ reasoning_effort: {
389
+ type: String,
390
+ },
391
+ };
392
+
393
+ const convoSchema = new mongoose.Schema(Object.assign(Object.assign({ conversationId: {
394
+ type: String,
395
+ unique: true,
396
+ required: true,
397
+ index: true,
398
+ meiliIndex: true,
399
+ }, title: {
400
+ type: String,
401
+ default: 'New Chat',
402
+ meiliIndex: true,
403
+ }, user: {
404
+ type: String,
405
+ index: true,
406
+ }, messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }], agentOptions: {
407
+ type: mongoose.Schema.Types.Mixed,
408
+ } }, conversationPreset), { agent_id: {
409
+ type: String,
410
+ }, tags: {
411
+ type: [String],
412
+ default: [],
413
+ meiliIndex: true,
414
+ }, files: {
415
+ type: [String],
416
+ }, expiredAt: {
417
+ type: Date,
418
+ } }), { timestamps: true });
419
+ convoSchema.index({ expiredAt: 1 }, { expireAfterSeconds: 0 });
420
+ convoSchema.index({ createdAt: 1, updatedAt: 1 });
421
+ convoSchema.index({ conversationId: 1, user: 1 }, { unique: true });
422
+
423
+ const file = new mongoose.Schema({
424
+ user: {
425
+ type: mongoose.Schema.Types.ObjectId,
426
+ ref: 'User',
427
+ index: true,
428
+ required: true,
429
+ },
430
+ conversationId: {
431
+ type: String,
432
+ ref: 'Conversation',
433
+ index: true,
434
+ },
435
+ file_id: {
436
+ type: String,
437
+ index: true,
438
+ required: true,
439
+ },
440
+ temp_file_id: {
441
+ type: String,
442
+ },
443
+ bytes: {
444
+ type: Number,
445
+ required: true,
446
+ },
447
+ filename: {
448
+ type: String,
449
+ required: true,
450
+ },
451
+ filepath: {
452
+ type: String,
453
+ required: true,
454
+ },
455
+ object: {
456
+ type: String,
457
+ required: true,
458
+ default: 'file',
459
+ },
460
+ embedded: {
461
+ type: Boolean,
462
+ },
463
+ type: {
464
+ type: String,
465
+ required: true,
466
+ },
467
+ context: {
468
+ type: String,
469
+ },
470
+ usage: {
471
+ type: Number,
472
+ required: true,
473
+ default: 0,
474
+ },
475
+ source: {
476
+ type: String,
477
+ default: librechatDataProvider.FileSources.local,
478
+ },
479
+ model: {
480
+ type: String,
481
+ },
482
+ width: Number,
483
+ height: Number,
484
+ metadata: {
485
+ fileIdentifier: String,
486
+ },
487
+ expiresAt: {
488
+ type: Date,
489
+ expires: 3600, // 1 hour in seconds
490
+ },
491
+ }, {
492
+ timestamps: true,
493
+ });
494
+ file.index({ createdAt: 1, updatedAt: 1 });
495
+
496
+ const keySchema = new mongoose.Schema({
497
+ userId: {
498
+ type: mongoose.Schema.Types.ObjectId,
499
+ ref: 'User',
500
+ required: true,
501
+ },
502
+ name: {
503
+ type: String,
504
+ required: true,
505
+ },
506
+ value: {
507
+ type: String,
508
+ required: true,
509
+ },
510
+ expiresAt: {
511
+ type: Date,
512
+ },
513
+ });
514
+ keySchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
515
+
516
+ const messageSchema = new mongoose.Schema({
517
+ messageId: {
518
+ type: String,
519
+ unique: true,
520
+ required: true,
521
+ index: true,
522
+ meiliIndex: true,
523
+ },
524
+ conversationId: {
525
+ type: String,
526
+ index: true,
527
+ required: true,
528
+ meiliIndex: true,
529
+ },
530
+ user: {
531
+ type: String,
532
+ index: true,
533
+ required: true,
534
+ default: null,
535
+ },
536
+ model: {
537
+ type: String,
538
+ default: null,
539
+ },
540
+ endpoint: {
541
+ type: String,
542
+ },
543
+ conversationSignature: {
544
+ type: String,
545
+ },
546
+ clientId: {
547
+ type: String,
548
+ },
549
+ invocationId: {
550
+ type: Number,
551
+ },
552
+ parentMessageId: {
553
+ type: String,
554
+ },
555
+ tokenCount: {
556
+ type: Number,
557
+ },
558
+ summaryTokenCount: {
559
+ type: Number,
560
+ },
561
+ sender: {
562
+ type: String,
563
+ meiliIndex: true,
564
+ },
565
+ text: {
566
+ type: String,
567
+ meiliIndex: true,
568
+ },
569
+ summary: {
570
+ type: String,
571
+ },
572
+ isCreatedByUser: {
573
+ type: Boolean,
574
+ required: true,
575
+ default: false,
576
+ },
577
+ unfinished: {
578
+ type: Boolean,
579
+ default: false,
580
+ },
581
+ error: {
582
+ type: Boolean,
583
+ default: false,
584
+ },
585
+ finish_reason: {
586
+ type: String,
587
+ },
588
+ _meiliIndex: {
589
+ type: Boolean,
590
+ required: false,
591
+ select: false,
592
+ default: false,
593
+ },
594
+ files: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
595
+ plugin: {
596
+ type: {
597
+ latest: {
598
+ type: String,
599
+ required: false,
600
+ },
601
+ inputs: {
602
+ type: [mongoose.Schema.Types.Mixed],
603
+ required: false,
604
+ default: undefined,
605
+ },
606
+ outputs: {
607
+ type: String,
608
+ required: false,
609
+ },
610
+ },
611
+ default: undefined,
612
+ },
613
+ plugins: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
614
+ content: {
615
+ type: [{ type: mongoose.Schema.Types.Mixed }],
616
+ default: undefined,
617
+ meiliIndex: true,
618
+ },
619
+ thread_id: {
620
+ type: String,
621
+ },
622
+ /* frontend components */
623
+ iconURL: {
624
+ type: String,
625
+ },
626
+ attachments: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
627
+ /*
628
+ attachments: {
629
+ type: [
630
+ {
631
+ file_id: String,
632
+ filename: String,
633
+ filepath: String,
634
+ expiresAt: Date,
635
+ width: Number,
636
+ height: Number,
637
+ type: String,
638
+ conversationId: String,
639
+ messageId: {
640
+ type: String,
641
+ required: true,
642
+ },
643
+ toolCallId: String,
644
+ },
645
+ ],
646
+ default: undefined,
647
+ },
648
+ */
649
+ expiredAt: {
650
+ type: Date,
651
+ },
652
+ }, { timestamps: true });
653
+ messageSchema.index({ expiredAt: 1 }, { expireAfterSeconds: 0 });
654
+ messageSchema.index({ createdAt: 1 });
655
+ messageSchema.index({ messageId: 1, user: 1 }, { unique: true });
656
+
657
+ const pluginAuthSchema = new mongoose.Schema({
658
+ authField: {
659
+ type: String,
660
+ required: true,
661
+ },
662
+ value: {
663
+ type: String,
664
+ required: true,
665
+ },
666
+ userId: {
667
+ type: String,
668
+ required: true,
669
+ },
670
+ pluginKey: {
671
+ type: String,
672
+ },
673
+ }, { timestamps: true });
674
+
675
+ const presetSchema = new mongoose.Schema(Object.assign(Object.assign({ presetId: {
676
+ type: String,
677
+ unique: true,
678
+ required: true,
679
+ index: true,
680
+ }, title: {
681
+ type: String,
682
+ default: 'New Chat',
683
+ meiliIndex: true,
684
+ }, user: {
685
+ type: String,
686
+ default: null,
687
+ }, defaultPreset: {
688
+ type: Boolean,
689
+ }, order: {
690
+ type: Number,
691
+ } }, conversationPreset), { agentOptions: {
692
+ type: mongoose.Schema.Types.Mixed,
693
+ default: null,
694
+ } }), { timestamps: true });
695
+
696
+ const projectSchema = new mongoose.Schema({
697
+ name: {
698
+ type: String,
699
+ required: true,
700
+ index: true,
701
+ },
702
+ promptGroupIds: {
703
+ type: [mongoose.Schema.Types.ObjectId],
704
+ ref: 'PromptGroup',
705
+ default: [],
706
+ },
707
+ agentIds: {
708
+ type: [String],
709
+ ref: 'Agent',
710
+ default: [],
711
+ },
712
+ }, {
713
+ timestamps: true,
714
+ });
715
+
716
+ const promptSchema = new mongoose.Schema({
717
+ groupId: {
718
+ type: mongoose.Schema.Types.ObjectId,
719
+ ref: 'PromptGroup',
720
+ required: true,
721
+ index: true,
722
+ },
723
+ author: {
724
+ type: mongoose.Schema.Types.ObjectId,
725
+ ref: 'User',
726
+ required: true,
727
+ },
728
+ prompt: {
729
+ type: String,
730
+ required: true,
731
+ },
732
+ type: {
733
+ type: String,
734
+ enum: ['text', 'chat'],
735
+ required: true,
736
+ },
737
+ }, {
738
+ timestamps: true,
739
+ });
740
+ promptSchema.index({ createdAt: 1, updatedAt: 1 });
741
+
742
+ const promptGroupSchema = new mongoose.Schema({
743
+ name: {
744
+ type: String,
745
+ required: true,
746
+ index: true,
747
+ },
748
+ numberOfGenerations: {
749
+ type: Number,
750
+ default: 0,
751
+ },
752
+ oneliner: {
753
+ type: String,
754
+ default: '',
755
+ },
756
+ category: {
757
+ type: String,
758
+ default: '',
759
+ index: true,
760
+ },
761
+ projectIds: {
762
+ type: [mongoose.Schema.Types.ObjectId],
763
+ ref: 'Project',
764
+ index: true,
765
+ default: [],
766
+ },
767
+ productionId: {
768
+ type: mongoose.Schema.Types.ObjectId,
769
+ ref: 'Prompt',
770
+ required: true,
771
+ index: true,
772
+ },
773
+ author: {
774
+ type: mongoose.Schema.Types.ObjectId,
775
+ ref: 'User',
776
+ required: true,
777
+ index: true,
778
+ },
779
+ authorName: {
780
+ type: String,
781
+ required: true,
782
+ },
783
+ command: {
784
+ type: String,
785
+ index: true,
786
+ validate: {
787
+ validator: function (v) {
788
+ return v === undefined || v === null || v === '' || /^[a-z0-9-]+$/.test(v);
789
+ },
790
+ message: (props) => `${props.value} is not a valid command. Only lowercase alphanumeric characters and hyphens are allowed.`,
791
+ },
792
+ maxlength: [
793
+ librechatDataProvider.Constants.COMMANDS_MAX_LENGTH,
794
+ `Command cannot be longer than ${librechatDataProvider.Constants.COMMANDS_MAX_LENGTH} characters`,
795
+ ],
796
+ }, // Casting here bypasses the type error for the command field.
797
+ }, {
798
+ timestamps: true,
799
+ });
800
+ promptGroupSchema.index({ createdAt: 1, updatedAt: 1 });
801
+
802
+ const roleSchema = new mongoose.Schema({
803
+ name: {
804
+ type: String,
805
+ required: true,
806
+ unique: true,
807
+ index: true,
808
+ },
809
+ [librechatDataProvider.PermissionTypes.BOOKMARKS]: {
810
+ [librechatDataProvider.Permissions.USE]: {
811
+ type: Boolean,
812
+ default: true,
813
+ },
814
+ },
815
+ [librechatDataProvider.PermissionTypes.PROMPTS]: {
816
+ [librechatDataProvider.Permissions.SHARED_GLOBAL]: {
817
+ type: Boolean,
818
+ default: false,
819
+ },
820
+ [librechatDataProvider.Permissions.USE]: {
821
+ type: Boolean,
822
+ default: true,
823
+ },
824
+ [librechatDataProvider.Permissions.CREATE]: {
825
+ type: Boolean,
826
+ default: true,
827
+ },
828
+ },
829
+ [librechatDataProvider.PermissionTypes.AGENTS]: {
830
+ [librechatDataProvider.Permissions.SHARED_GLOBAL]: {
831
+ type: Boolean,
832
+ default: false,
833
+ },
834
+ [librechatDataProvider.Permissions.USE]: {
835
+ type: Boolean,
836
+ default: true,
837
+ },
838
+ [librechatDataProvider.Permissions.CREATE]: {
839
+ type: Boolean,
840
+ default: true,
841
+ },
842
+ },
843
+ [librechatDataProvider.PermissionTypes.MULTI_CONVO]: {
844
+ [librechatDataProvider.Permissions.USE]: {
845
+ type: Boolean,
846
+ default: true,
847
+ },
848
+ },
849
+ [librechatDataProvider.PermissionTypes.TEMPORARY_CHAT]: {
850
+ [librechatDataProvider.Permissions.USE]: {
851
+ type: Boolean,
852
+ default: true,
853
+ },
854
+ },
855
+ [librechatDataProvider.PermissionTypes.RUN_CODE]: {
856
+ [librechatDataProvider.Permissions.USE]: {
857
+ type: Boolean,
858
+ default: true,
859
+ },
860
+ },
861
+ });
862
+
863
+ const sessionSchema = new mongoose.Schema({
864
+ refreshTokenHash: {
865
+ type: String,
866
+ required: true,
867
+ },
868
+ expiration: {
869
+ type: Date,
870
+ required: true,
871
+ expires: 0,
872
+ },
873
+ user: {
874
+ type: mongoose.Schema.Types.ObjectId,
875
+ ref: 'User',
876
+ required: true,
877
+ },
878
+ });
879
+
880
+ const shareSchema = new mongoose.Schema({
881
+ conversationId: {
882
+ type: String,
883
+ required: true,
884
+ },
885
+ title: {
886
+ type: String,
887
+ index: true,
888
+ },
889
+ user: {
890
+ type: String,
891
+ index: true,
892
+ },
893
+ messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
894
+ shareId: {
895
+ type: String,
896
+ index: true,
897
+ },
898
+ isPublic: {
899
+ type: Boolean,
900
+ default: true,
901
+ },
902
+ }, { timestamps: true });
903
+
904
+ const tokenSchema = new mongoose.Schema({
905
+ userId: {
906
+ type: mongoose.Schema.Types.ObjectId,
907
+ required: true,
908
+ ref: 'user',
909
+ },
910
+ email: {
911
+ type: String,
912
+ },
913
+ type: {
914
+ type: String,
915
+ },
916
+ identifier: {
917
+ type: String,
918
+ },
919
+ token: {
920
+ type: String,
921
+ required: true,
922
+ },
923
+ createdAt: {
924
+ type: Date,
925
+ required: true,
926
+ default: Date.now,
927
+ },
928
+ expiresAt: {
929
+ type: Date,
930
+ required: true,
931
+ },
932
+ metadata: {
933
+ type: Map,
934
+ of: mongoose.Schema.Types.Mixed,
935
+ },
936
+ });
937
+ tokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
938
+
939
+ const toolCallSchema = new mongoose.Schema({
940
+ conversationId: {
941
+ type: String,
942
+ required: true,
943
+ },
944
+ messageId: {
945
+ type: String,
946
+ required: true,
947
+ },
948
+ toolId: {
949
+ type: String,
950
+ required: true,
951
+ },
952
+ user: {
953
+ type: mongoose.Schema.Types.ObjectId,
954
+ ref: 'User',
955
+ required: true,
956
+ },
957
+ result: {
958
+ type: mongoose.Schema.Types.Mixed,
959
+ },
960
+ attachments: {
961
+ type: mongoose.Schema.Types.Mixed,
962
+ },
963
+ blockIndex: {
964
+ type: Number,
965
+ },
966
+ partIndex: {
967
+ type: Number,
968
+ },
969
+ }, { timestamps: true });
970
+ toolCallSchema.index({ messageId: 1, user: 1 });
971
+ toolCallSchema.index({ conversationId: 1, user: 1 });
972
+
973
+ const transactionSchema = new mongoose.Schema({
974
+ user: {
975
+ type: mongoose.Schema.Types.ObjectId,
976
+ ref: 'User',
977
+ index: true,
978
+ required: true,
979
+ },
980
+ conversationId: {
981
+ type: String,
982
+ ref: 'Conversation',
983
+ index: true,
984
+ },
985
+ tokenType: {
986
+ type: String,
987
+ enum: ['prompt', 'completion', 'credits'],
988
+ required: true,
989
+ },
990
+ model: {
991
+ type: String,
992
+ },
993
+ context: {
994
+ type: String,
995
+ },
996
+ valueKey: {
997
+ type: String,
998
+ },
999
+ rate: Number,
1000
+ rawAmount: Number,
1001
+ tokenValue: Number,
1002
+ inputTokens: { type: Number },
1003
+ writeTokens: { type: Number },
1004
+ readTokens: { type: Number },
1005
+ }, {
1006
+ timestamps: true,
1007
+ });
1008
+
1009
+ // Session sub-schema
1010
+ const SessionSchema = new mongoose.Schema({
1011
+ refreshToken: {
1012
+ type: String,
1013
+ default: '',
1014
+ },
1015
+ }, { _id: false });
1016
+ // Backup code sub-schema
1017
+ const BackupCodeSchema = new mongoose.Schema({
1018
+ codeHash: { type: String, required: true },
1019
+ used: { type: Boolean, default: false },
1020
+ usedAt: { type: Date, default: null },
1021
+ }, { _id: false });
1022
+ const User = new mongoose.Schema({
1023
+ name: {
1024
+ type: String,
1025
+ },
1026
+ username: {
1027
+ type: String,
1028
+ lowercase: true,
1029
+ default: '',
1030
+ },
1031
+ email: {
1032
+ type: String,
1033
+ required: [true, 'can\'t be blank'],
1034
+ lowercase: true,
1035
+ unique: true,
1036
+ match: [/\S+@\S+\.\S+/, 'is invalid'],
1037
+ index: true,
1038
+ },
1039
+ emailVerified: {
1040
+ type: Boolean,
1041
+ required: true,
1042
+ default: false,
1043
+ },
1044
+ password: {
1045
+ type: String,
1046
+ trim: true,
1047
+ minlength: 8,
1048
+ maxlength: 128,
1049
+ },
1050
+ avatar: {
1051
+ type: String,
1052
+ required: false,
1053
+ },
1054
+ provider: {
1055
+ type: String,
1056
+ required: true,
1057
+ default: 'local',
1058
+ },
1059
+ role: {
1060
+ type: String,
1061
+ default: librechatDataProvider.SystemRoles.USER,
1062
+ },
1063
+ googleId: {
1064
+ type: String,
1065
+ unique: true,
1066
+ sparse: true,
1067
+ },
1068
+ facebookId: {
1069
+ type: String,
1070
+ unique: true,
1071
+ sparse: true,
1072
+ },
1073
+ openidId: {
1074
+ type: String,
1075
+ unique: true,
1076
+ sparse: true,
1077
+ },
1078
+ ldapId: {
1079
+ type: String,
1080
+ unique: true,
1081
+ sparse: true,
1082
+ },
1083
+ githubId: {
1084
+ type: String,
1085
+ unique: true,
1086
+ sparse: true,
1087
+ },
1088
+ discordId: {
1089
+ type: String,
1090
+ unique: true,
1091
+ sparse: true,
1092
+ },
1093
+ appleId: {
1094
+ type: String,
1095
+ unique: true,
1096
+ sparse: true,
1097
+ },
1098
+ plugins: {
1099
+ type: Array,
1100
+ },
1101
+ totpSecret: {
1102
+ type: String,
1103
+ },
1104
+ backupCodes: {
1105
+ type: [BackupCodeSchema],
1106
+ },
1107
+ refreshToken: {
1108
+ type: [SessionSchema],
1109
+ },
1110
+ expiresAt: {
1111
+ type: Date,
1112
+ expires: 604800, // 7 days in seconds
1113
+ },
1114
+ termsAccepted: {
1115
+ type: Boolean,
1116
+ default: false,
1117
+ },
1118
+ }, { timestamps: true });
1119
+
1120
+ exports.actionSchema = Action;
1121
+ exports.agentSchema = agentSchema;
1122
+ exports.assistantSchema = assistantSchema;
1123
+ exports.balanceSchema = balanceSchema;
1124
+ exports.bannerSchema = bannerSchema;
1125
+ exports.categoriesSchema = categoriesSchema;
1126
+ exports.conversationTagSchema = conversationTag;
1127
+ exports.convoSchema = convoSchema;
1128
+ exports.fileSchema = file;
1129
+ exports.keySchema = keySchema;
1130
+ exports.messageSchema = messageSchema;
1131
+ exports.pluginAuthSchema = pluginAuthSchema;
1132
+ exports.presetSchema = presetSchema;
1133
+ exports.projectSchema = projectSchema;
1134
+ exports.promptGroupSchema = promptGroupSchema;
1135
+ exports.promptSchema = promptSchema;
1136
+ exports.roleSchema = roleSchema;
1137
+ exports.sessionSchema = sessionSchema;
1138
+ exports.shareSchema = shareSchema;
1139
+ exports.tokenSchema = tokenSchema;
1140
+ exports.toolCallSchema = toolCallSchema;
1141
+ exports.transactionSchema = transactionSchema;
1142
+ exports.userSchema = User;
1143
+ //# sourceMappingURL=index.cjs.map