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