@librechat/data-schemas 0.0.13 → 0.0.14

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 CHANGED
@@ -10,11 +10,20 @@ var winston = require('winston');
10
10
  require('winston-daily-rotate-file');
11
11
  var path = require('path');
12
12
  var klona = require('klona');
13
- var traverse = require('traverse');
13
+ var traverseLib = require('traverse');
14
14
  var nanoid = require('nanoid');
15
15
 
16
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
+
18
+ var jwt__default = /*#__PURE__*/_interopDefault(jwt);
19
+ var mongoose__default = /*#__PURE__*/_interopDefault(mongoose);
20
+ var ___default = /*#__PURE__*/_interopDefault(_);
21
+ var winston__default = /*#__PURE__*/_interopDefault(winston);
22
+ var path__default = /*#__PURE__*/_interopDefault(path);
23
+ var traverseLib__default = /*#__PURE__*/_interopDefault(traverseLib);
24
+
16
25
  async function signPayload({ payload, secret, expirationTime, }) {
17
- return jwt.sign(payload, secret, { expiresIn: expirationTime });
26
+ return jwt__default.default.sign(payload, secret, { expiresIn: expirationTime });
18
27
  }
19
28
  async function hashToken(str) {
20
29
  const data = new TextEncoder().encode(str);
@@ -35,7 +44,7 @@ const AuthSchema = new mongoose.Schema({
35
44
  }, { _id: false });
36
45
  const Action = new mongoose.Schema({
37
46
  user: {
38
- type: mongoose.Schema.Types.ObjectId,
47
+ type: mongoose__default.default.Schema.Types.ObjectId,
39
48
  ref: 'User',
40
49
  index: true,
41
50
  required: true,
@@ -489,7 +498,7 @@ convoSchema.index({ conversationId: 1, user: 1 }, { unique: true });
489
498
 
490
499
  const file = new mongoose.Schema({
491
500
  user: {
492
- type: mongoose.Schema.Types.ObjectId,
501
+ type: mongoose__default.default.Schema.Types.ObjectId,
493
502
  ref: 'User',
494
503
  index: true,
495
504
  required: true,
@@ -565,7 +574,7 @@ file.index({ createdAt: 1, updatedAt: 1 });
565
574
 
566
575
  const keySchema = new mongoose.Schema({
567
576
  userId: {
568
- type: mongoose.Schema.Types.ObjectId,
577
+ type: mongoose__default.default.Schema.Types.ObjectId,
569
578
  ref: 'User',
570
579
  required: true,
571
580
  },
@@ -663,7 +672,7 @@ const messageSchema = new mongoose.Schema({
663
672
  required: true,
664
673
  },
665
674
  tag: {
666
- type: mongoose.Schema.Types.Mixed,
675
+ type: mongoose__default.default.Schema.Types.Mixed,
667
676
  required: false,
668
677
  },
669
678
  text: {
@@ -680,7 +689,7 @@ const messageSchema = new mongoose.Schema({
680
689
  select: false,
681
690
  default: false,
682
691
  },
683
- files: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
692
+ files: { type: [{ type: mongoose__default.default.Schema.Types.Mixed }], default: undefined },
684
693
  plugin: {
685
694
  type: {
686
695
  latest: {
@@ -688,7 +697,7 @@ const messageSchema = new mongoose.Schema({
688
697
  required: false,
689
698
  },
690
699
  inputs: {
691
- type: [mongoose.Schema.Types.Mixed],
700
+ type: [mongoose__default.default.Schema.Types.Mixed],
692
701
  required: false,
693
702
  default: undefined,
694
703
  },
@@ -699,9 +708,9 @@ const messageSchema = new mongoose.Schema({
699
708
  },
700
709
  default: undefined,
701
710
  },
702
- plugins: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
711
+ plugins: { type: [{ type: mongoose__default.default.Schema.Types.Mixed }], default: undefined },
703
712
  content: {
704
- type: [{ type: mongoose.Schema.Types.Mixed }],
713
+ type: [{ type: mongoose__default.default.Schema.Types.Mixed }],
705
714
  default: undefined,
706
715
  meiliIndex: true,
707
716
  },
@@ -712,7 +721,7 @@ const messageSchema = new mongoose.Schema({
712
721
  iconURL: {
713
722
  type: String,
714
723
  },
715
- attachments: { type: [{ type: mongoose.Schema.Types.Mixed }], default: undefined },
724
+ attachments: { type: [{ type: mongoose__default.default.Schema.Types.Mixed }], default: undefined },
716
725
  /*
717
726
  attachments: {
718
727
  type: [
@@ -785,7 +794,7 @@ const presetSchema = new mongoose.Schema({
785
794
  },
786
795
  ...conversationPreset,
787
796
  agentOptions: {
788
- type: mongoose.Schema.Types.Mixed,
797
+ type: mongoose__default.default.Schema.Types.Mixed,
789
798
  default: null,
790
799
  },
791
800
  }, { timestamps: true });
@@ -978,7 +987,7 @@ const sessionSchema = new mongoose.Schema({
978
987
  expires: 0,
979
988
  },
980
989
  user: {
981
- type: mongoose.Schema.Types.ObjectId,
990
+ type: mongoose__default.default.Schema.Types.ObjectId,
982
991
  ref: 'User',
983
992
  required: true,
984
993
  },
@@ -997,7 +1006,7 @@ const shareSchema = new mongoose.Schema({
997
1006
  type: String,
998
1007
  index: true,
999
1008
  },
1000
- messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
1009
+ messages: [{ type: mongoose__default.default.Schema.Types.ObjectId, ref: 'Message' }],
1001
1010
  shareId: {
1002
1011
  type: String,
1003
1012
  index: true,
@@ -1057,15 +1066,15 @@ const toolCallSchema = new mongoose.Schema({
1057
1066
  required: true,
1058
1067
  },
1059
1068
  user: {
1060
- type: mongoose.Schema.Types.ObjectId,
1069
+ type: mongoose__default.default.Schema.Types.ObjectId,
1061
1070
  ref: 'User',
1062
1071
  required: true,
1063
1072
  },
1064
1073
  result: {
1065
- type: mongoose.Schema.Types.Mixed,
1074
+ type: mongoose__default.default.Schema.Types.Mixed,
1066
1075
  },
1067
1076
  attachments: {
1068
- type: mongoose.Schema.Types.Mixed,
1077
+ type: mongoose__default.default.Schema.Types.Mixed,
1069
1078
  },
1070
1079
  blockIndex: {
1071
1080
  type: Number,
@@ -1079,7 +1088,7 @@ toolCallSchema.index({ conversationId: 1, user: 1 });
1079
1088
 
1080
1089
  const transactionSchema = new mongoose.Schema({
1081
1090
  user: {
1082
- type: mongoose.Schema.Types.ObjectId,
1091
+ type: mongoose__default.default.Schema.Types.ObjectId,
1083
1092
  ref: 'User',
1084
1093
  index: true,
1085
1094
  required: true,
@@ -1316,18 +1325,18 @@ const getLogDirectory = () => {
1316
1325
  const cwd = process.cwd();
1317
1326
  // Check if we're running from within the api directory
1318
1327
  if (cwd.endsWith('/api') || cwd.endsWith('\\api')) {
1319
- return path.join(cwd, 'logs');
1328
+ return path__default.default.join(cwd, 'logs');
1320
1329
  }
1321
1330
  // Check if api/logs exists relative to current directory (running from project root)
1322
1331
  // We'll just use the path and let the file system create it if needed
1323
- const apiLogsPath = path.join(cwd, 'api', 'logs');
1332
+ const apiLogsPath = path__default.default.join(cwd, 'api', 'logs');
1324
1333
  // For LibreChat project structure, use api/logs
1325
1334
  // For external consumers, they should set LIBRECHAT_LOG_DIR
1326
1335
  if (cwd.includes('LibreChat')) {
1327
1336
  return apiLogsPath;
1328
1337
  }
1329
1338
  // Default to logs directory relative to current working directory
1330
- return path.join(cwd, 'logs');
1339
+ return path__default.default.join(cwd, 'logs');
1331
1340
  };
1332
1341
 
1333
1342
  const logDir$1 = getLogDirectory();
@@ -1344,7 +1353,7 @@ const levels$1 = {
1344
1353
  activity: 6,
1345
1354
  silly: 7,
1346
1355
  };
1347
- winston.addColors({
1356
+ winston__default.default.addColors({
1348
1357
  info: 'green',
1349
1358
  warn: 'italic yellow',
1350
1359
  error: 'red',
@@ -1355,10 +1364,10 @@ const level$1 = () => {
1355
1364
  const isDevelopment = env === 'development';
1356
1365
  return isDevelopment ? 'debug' : 'warn';
1357
1366
  };
1358
- const fileFormat$1 = winston.format.combine(winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.errors({ stack: true }), winston.format.splat());
1367
+ const fileFormat$1 = winston__default.default.format.combine(winston__default.default.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston__default.default.format.errors({ stack: true }), winston__default.default.format.splat());
1359
1368
  const logLevel = useDebugLogging$1 ? 'debug' : 'error';
1360
1369
  const transports$1 = [
1361
- new winston.transports.DailyRotateFile({
1370
+ new winston__default.default.transports.DailyRotateFile({
1362
1371
  level: logLevel,
1363
1372
  filename: `${logDir$1}/meiliSync-%DATE%.log`,
1364
1373
  datePattern: 'YYYY-MM-DD',
@@ -1368,12 +1377,12 @@ const transports$1 = [
1368
1377
  format: fileFormat$1,
1369
1378
  }),
1370
1379
  ];
1371
- const consoleFormat$1 = winston.format.combine(winston.format.colorize({ all: true }), winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`));
1372
- transports$1.push(new winston.transports.Console({
1380
+ const consoleFormat$1 = winston__default.default.format.combine(winston__default.default.format.colorize({ all: true }), winston__default.default.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston__default.default.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`));
1381
+ transports$1.push(new winston__default.default.transports.Console({
1373
1382
  level: 'info',
1374
1383
  format: consoleFormat$1,
1375
1384
  }));
1376
- const logger$1 = winston.createLogger({
1385
+ const logger$1 = winston__default.default.createLogger({
1377
1386
  level: level$1(),
1378
1387
  levels: levels$1,
1379
1388
  transports: transports$1,
@@ -1491,7 +1500,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1491
1500
  .sort({ _id: 1 })
1492
1501
  .batchSize(batchSize)
1493
1502
  .cursor();
1494
- const format = (doc) => _.omitBy(_.pick(doc, attributesToIndex), (v, k) => k.startsWith('$'));
1503
+ const format = (doc) => ___default.default.omitBy(___default.default.pick(doc, attributesToIndex), (v, k) => k.startsWith('$'));
1495
1504
  let documentBatch = [];
1496
1505
  let updateOps = [];
1497
1506
  // Process documents in streaming fashion
@@ -1604,7 +1613,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1604
1613
  const data = await index.search(q, params);
1605
1614
  if (populate) {
1606
1615
  const query = {};
1607
- query[primaryKey] = _.map(data.hits, (hit) => cleanUpPrimaryKeyValue(hit[primaryKey]));
1616
+ query[primaryKey] = ___default.default.map(data.hits, (hit) => cleanUpPrimaryKeyValue(hit[primaryKey]));
1608
1617
  const projection = Object.keys(this.schema.obj).reduce((results, key) => {
1609
1618
  if (!key.startsWith('$')) {
1610
1619
  results[key] = 1;
@@ -1614,7 +1623,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1614
1623
  const hitsFromMongoose = await this.find(query, projection).lean();
1615
1624
  const populatedHits = data.hits.map((hit) => {
1616
1625
  hit[primaryKey];
1617
- const originalHit = _.find(hitsFromMongoose, (item) => {
1626
+ const originalHit = ___default.default.find(hitsFromMongoose, (item) => {
1618
1627
  const typedItem = item;
1619
1628
  return typedItem[primaryKey] === hit[primaryKey];
1620
1629
  });
@@ -1631,7 +1640,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1631
1640
  * Preprocesses the current document for indexing
1632
1641
  */
1633
1642
  preprocessObjectForIndex() {
1634
- const object = _.omitBy(_.pick(this.toJSON(), attributesToIndex), (v, k) => k.startsWith('$'));
1643
+ const object = ___default.default.omitBy(___default.default.pick(this.toJSON(), attributesToIndex), (v, k) => k.startsWith('$'));
1635
1644
  if (object.conversationId &&
1636
1645
  typeof object.conversationId === 'string' &&
1637
1646
  object.conversationId.includes('|')) {
@@ -1679,7 +1688,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1679
1688
  */
1680
1689
  async updateObjectToMeili(next) {
1681
1690
  try {
1682
- const object = _.omitBy(_.pick(this.toJSON(), attributesToIndex), (v, k) => k.startsWith('$'));
1691
+ const object = ___default.default.omitBy(___default.default.pick(this.toJSON(), attributesToIndex), (v, k) => k.startsWith('$'));
1683
1692
  await index.updateDocuments([object]);
1684
1693
  next();
1685
1694
  }
@@ -2250,6 +2259,14 @@ function createUserMethods(mongoose) {
2250
2259
  };
2251
2260
  }
2252
2261
 
2262
+ /**
2263
+ * Wrapper for the traverse module to handle CommonJS imports in ESM context
2264
+ */
2265
+ // @ts-ignore - traverse doesn't have proper ESM exports
2266
+ // Handle both default export and named exports
2267
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2268
+ const traverse = (traverseLib__default.default.default || traverseLib__default.default);
2269
+
2253
2270
  const SPLAT_SYMBOL = Symbol.for('splat');
2254
2271
  const MESSAGE_SYMBOL = Symbol.for('message');
2255
2272
  const CONSOLE_JSON_STRING_LENGTH = parseInt(process.env.CONSOLE_JSON_STRING_LENGTH || '', 10) || 255;
@@ -2294,7 +2311,7 @@ function redactMessage(str, trimLength) {
2294
2311
  * @param info - The log information object.
2295
2312
  * @returns The modified log information object.
2296
2313
  */
2297
- const redactFormat = winston.format((info) => {
2314
+ const redactFormat = winston__default.default.format((info) => {
2298
2315
  if (info.level === 'error') {
2299
2316
  // Type guard to ensure message is a string
2300
2317
  if (typeof info.message === 'string') {
@@ -2345,7 +2362,7 @@ const condenseArray = (item) => {
2345
2362
  * @param options - The options for formatting log messages.
2346
2363
  * @returns The formatted log message.
2347
2364
  */
2348
- const debugTraverse = winston.format.printf(({ level, message, timestamp, ...metadata }) => {
2365
+ const debugTraverse = winston__default.default.format.printf(({ level, message, timestamp, ...metadata }) => {
2349
2366
  if (!message) {
2350
2367
  return `${timestamp} ${level}`;
2351
2368
  }
@@ -2420,7 +2437,7 @@ const debugTraverse = winston.format.printf(({ level, message, timestamp, ...met
2420
2437
  * Truncates long string values in JSON log objects.
2421
2438
  * Prevents outputting extremely long values (e.g., base64, blobs).
2422
2439
  */
2423
- const jsonTruncateFormat = winston.format((info) => {
2440
+ const jsonTruncateFormat = winston__default.default.format((info) => {
2424
2441
  const truncateLongStrings = (str, maxLength) => str.length > maxLength ? str.substring(0, maxLength) + '...' : str;
2425
2442
  const seen = new WeakSet();
2426
2443
  const truncateObject = (obj) => {
@@ -2466,7 +2483,7 @@ const levels = {
2466
2483
  activity: 6,
2467
2484
  silly: 7,
2468
2485
  };
2469
- winston.addColors({
2486
+ winston__default.default.addColors({
2470
2487
  info: 'green',
2471
2488
  warn: 'italic yellow',
2472
2489
  error: 'red',
@@ -2476,9 +2493,9 @@ const level = () => {
2476
2493
  const env = NODE_ENV || 'development';
2477
2494
  return env === 'development' ? 'debug' : 'warn';
2478
2495
  };
2479
- const fileFormat = winston.format.combine(redactFormat(), winston.format.timestamp({ format: () => new Date().toISOString() }), winston.format.errors({ stack: true }), winston.format.splat());
2496
+ const fileFormat = winston__default.default.format.combine(redactFormat(), winston__default.default.format.timestamp({ format: () => new Date().toISOString() }), winston__default.default.format.errors({ stack: true }), winston__default.default.format.splat());
2480
2497
  const transports = [
2481
- new winston.transports.DailyRotateFile({
2498
+ new winston__default.default.transports.DailyRotateFile({
2482
2499
  level: 'error',
2483
2500
  filename: `${logDir}/error-%DATE%.log`,
2484
2501
  datePattern: 'YYYY-MM-DD',
@@ -2489,17 +2506,17 @@ const transports = [
2489
2506
  }),
2490
2507
  ];
2491
2508
  if (useDebugLogging) {
2492
- transports.push(new winston.transports.DailyRotateFile({
2509
+ transports.push(new winston__default.default.transports.DailyRotateFile({
2493
2510
  level: 'debug',
2494
2511
  filename: `${logDir}/debug-%DATE%.log`,
2495
2512
  datePattern: 'YYYY-MM-DD',
2496
2513
  zippedArchive: true,
2497
2514
  maxSize: '20m',
2498
2515
  maxFiles: '14d',
2499
- format: winston.format.combine(fileFormat, debugTraverse),
2516
+ format: winston__default.default.format.combine(fileFormat, debugTraverse),
2500
2517
  }));
2501
2518
  }
2502
- const consoleFormat = winston.format.combine(redactFormat(), winston.format.colorize({ all: true }), winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.printf((info) => {
2519
+ const consoleFormat = winston__default.default.format.combine(redactFormat(), winston__default.default.format.colorize({ all: true }), winston__default.default.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston__default.default.format.printf((info) => {
2503
2520
  const message = `${info.timestamp} ${info.level}: ${info.message}`;
2504
2521
  return info.level.includes('error') ? redactMessage(message) : message;
2505
2522
  }));
@@ -2509,27 +2526,27 @@ if (useDebugConsole) {
2509
2526
  }
2510
2527
  // Add console transport
2511
2528
  if (useDebugConsole) {
2512
- transports.push(new winston.transports.Console({
2529
+ transports.push(new winston__default.default.transports.Console({
2513
2530
  level: consoleLogLevel,
2514
2531
  format: useConsoleJson
2515
- ? winston.format.combine(fileFormat, jsonTruncateFormat(), winston.format.json())
2516
- : winston.format.combine(fileFormat, debugTraverse),
2532
+ ? winston__default.default.format.combine(fileFormat, jsonTruncateFormat(), winston__default.default.format.json())
2533
+ : winston__default.default.format.combine(fileFormat, debugTraverse),
2517
2534
  }));
2518
2535
  }
2519
2536
  else if (useConsoleJson) {
2520
- transports.push(new winston.transports.Console({
2537
+ transports.push(new winston__default.default.transports.Console({
2521
2538
  level: consoleLogLevel,
2522
- format: winston.format.combine(fileFormat, jsonTruncateFormat(), winston.format.json()),
2539
+ format: winston__default.default.format.combine(fileFormat, jsonTruncateFormat(), winston__default.default.format.json()),
2523
2540
  }));
2524
2541
  }
2525
2542
  else {
2526
- transports.push(new winston.transports.Console({
2543
+ transports.push(new winston__default.default.transports.Console({
2527
2544
  level: consoleLogLevel,
2528
2545
  format: consoleFormat,
2529
2546
  }));
2530
2547
  }
2531
2548
  // Create logger
2532
- const logger = winston.createLogger({
2549
+ const logger = winston__default.default.createLogger({
2533
2550
  level: level(),
2534
2551
  levels,
2535
2552
  transports,