@librechat/data-schemas 0.0.12 → 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
@@ -6,15 +6,24 @@ var mongoose = require('mongoose');
6
6
  var librechatDataProvider = require('librechat-data-provider');
7
7
  var _ = require('lodash');
8
8
  var meilisearch = require('meilisearch');
9
- var path = require('path');
10
9
  var winston = require('winston');
11
10
  require('winston-daily-rotate-file');
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,
@@ -1299,7 +1308,38 @@ function createBalanceModel(mongoose) {
1299
1308
  return mongoose.models.Balance || mongoose.model('Balance', balanceSchema);
1300
1309
  }
1301
1310
 
1302
- const logDir$1 = path.join(__dirname, '..', '..', '..', 'api', 'logs');
1311
+ /**
1312
+ * Determine the log directory in a cross-compatible way.
1313
+ * Priority:
1314
+ * 1. LIBRECHAT_LOG_DIR environment variable
1315
+ * 2. If running within LibreChat monorepo (when cwd ends with /api), use api/logs
1316
+ * 3. If api/logs exists relative to cwd, use that (for running from project root)
1317
+ * 4. Otherwise, use logs directory relative to process.cwd()
1318
+ *
1319
+ * This avoids using __dirname which is not available in ESM modules
1320
+ */
1321
+ const getLogDirectory = () => {
1322
+ if (process.env.LIBRECHAT_LOG_DIR) {
1323
+ return process.env.LIBRECHAT_LOG_DIR;
1324
+ }
1325
+ const cwd = process.cwd();
1326
+ // Check if we're running from within the api directory
1327
+ if (cwd.endsWith('/api') || cwd.endsWith('\\api')) {
1328
+ return path__default.default.join(cwd, 'logs');
1329
+ }
1330
+ // Check if api/logs exists relative to current directory (running from project root)
1331
+ // We'll just use the path and let the file system create it if needed
1332
+ const apiLogsPath = path__default.default.join(cwd, 'api', 'logs');
1333
+ // For LibreChat project structure, use api/logs
1334
+ // For external consumers, they should set LIBRECHAT_LOG_DIR
1335
+ if (cwd.includes('LibreChat')) {
1336
+ return apiLogsPath;
1337
+ }
1338
+ // Default to logs directory relative to current working directory
1339
+ return path__default.default.join(cwd, 'logs');
1340
+ };
1341
+
1342
+ const logDir$1 = getLogDirectory();
1303
1343
  const { NODE_ENV: NODE_ENV$1, DEBUG_LOGGING: DEBUG_LOGGING$1 = 'false' } = process.env;
1304
1344
  const useDebugLogging$1 = (typeof DEBUG_LOGGING$1 === 'string' && DEBUG_LOGGING$1.toLowerCase() === 'true') ||
1305
1345
  DEBUG_LOGGING$1 === 'true';
@@ -1313,7 +1353,7 @@ const levels$1 = {
1313
1353
  activity: 6,
1314
1354
  silly: 7,
1315
1355
  };
1316
- winston.addColors({
1356
+ winston__default.default.addColors({
1317
1357
  info: 'green',
1318
1358
  warn: 'italic yellow',
1319
1359
  error: 'red',
@@ -1324,10 +1364,10 @@ const level$1 = () => {
1324
1364
  const isDevelopment = env === 'development';
1325
1365
  return isDevelopment ? 'debug' : 'warn';
1326
1366
  };
1327
- 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());
1328
1368
  const logLevel = useDebugLogging$1 ? 'debug' : 'error';
1329
1369
  const transports$1 = [
1330
- new winston.transports.DailyRotateFile({
1370
+ new winston__default.default.transports.DailyRotateFile({
1331
1371
  level: logLevel,
1332
1372
  filename: `${logDir$1}/meiliSync-%DATE%.log`,
1333
1373
  datePattern: 'YYYY-MM-DD',
@@ -1337,12 +1377,12 @@ const transports$1 = [
1337
1377
  format: fileFormat$1,
1338
1378
  }),
1339
1379
  ];
1340
- 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}`));
1341
- 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({
1342
1382
  level: 'info',
1343
1383
  format: consoleFormat$1,
1344
1384
  }));
1345
- const logger$1 = winston.createLogger({
1385
+ const logger$1 = winston__default.default.createLogger({
1346
1386
  level: level$1(),
1347
1387
  levels: levels$1,
1348
1388
  transports: transports$1,
@@ -1460,7 +1500,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1460
1500
  .sort({ _id: 1 })
1461
1501
  .batchSize(batchSize)
1462
1502
  .cursor();
1463
- 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('$'));
1464
1504
  let documentBatch = [];
1465
1505
  let updateOps = [];
1466
1506
  // Process documents in streaming fashion
@@ -1573,7 +1613,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1573
1613
  const data = await index.search(q, params);
1574
1614
  if (populate) {
1575
1615
  const query = {};
1576
- query[primaryKey] = _.map(data.hits, (hit) => cleanUpPrimaryKeyValue(hit[primaryKey]));
1616
+ query[primaryKey] = ___default.default.map(data.hits, (hit) => cleanUpPrimaryKeyValue(hit[primaryKey]));
1577
1617
  const projection = Object.keys(this.schema.obj).reduce((results, key) => {
1578
1618
  if (!key.startsWith('$')) {
1579
1619
  results[key] = 1;
@@ -1583,7 +1623,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1583
1623
  const hitsFromMongoose = await this.find(query, projection).lean();
1584
1624
  const populatedHits = data.hits.map((hit) => {
1585
1625
  hit[primaryKey];
1586
- const originalHit = _.find(hitsFromMongoose, (item) => {
1626
+ const originalHit = ___default.default.find(hitsFromMongoose, (item) => {
1587
1627
  const typedItem = item;
1588
1628
  return typedItem[primaryKey] === hit[primaryKey];
1589
1629
  });
@@ -1600,7 +1640,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1600
1640
  * Preprocesses the current document for indexing
1601
1641
  */
1602
1642
  preprocessObjectForIndex() {
1603
- 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('$'));
1604
1644
  if (object.conversationId &&
1605
1645
  typeof object.conversationId === 'string' &&
1606
1646
  object.conversationId.includes('|')) {
@@ -1648,7 +1688,7 @@ const createMeiliMongooseModel = ({ index, attributesToIndex, syncOptions, }) =>
1648
1688
  */
1649
1689
  async updateObjectToMeili(next) {
1650
1690
  try {
1651
- 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('$'));
1652
1692
  await index.updateDocuments([object]);
1653
1693
  next();
1654
1694
  }
@@ -2219,6 +2259,14 @@ function createUserMethods(mongoose) {
2219
2259
  };
2220
2260
  }
2221
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
+
2222
2270
  const SPLAT_SYMBOL = Symbol.for('splat');
2223
2271
  const MESSAGE_SYMBOL = Symbol.for('message');
2224
2272
  const CONSOLE_JSON_STRING_LENGTH = parseInt(process.env.CONSOLE_JSON_STRING_LENGTH || '', 10) || 255;
@@ -2263,7 +2311,7 @@ function redactMessage(str, trimLength) {
2263
2311
  * @param info - The log information object.
2264
2312
  * @returns The modified log information object.
2265
2313
  */
2266
- const redactFormat = winston.format((info) => {
2314
+ const redactFormat = winston__default.default.format((info) => {
2267
2315
  if (info.level === 'error') {
2268
2316
  // Type guard to ensure message is a string
2269
2317
  if (typeof info.message === 'string') {
@@ -2314,7 +2362,7 @@ const condenseArray = (item) => {
2314
2362
  * @param options - The options for formatting log messages.
2315
2363
  * @returns The formatted log message.
2316
2364
  */
2317
- const debugTraverse = winston.format.printf(({ level, message, timestamp, ...metadata }) => {
2365
+ const debugTraverse = winston__default.default.format.printf(({ level, message, timestamp, ...metadata }) => {
2318
2366
  if (!message) {
2319
2367
  return `${timestamp} ${level}`;
2320
2368
  }
@@ -2389,7 +2437,7 @@ const debugTraverse = winston.format.printf(({ level, message, timestamp, ...met
2389
2437
  * Truncates long string values in JSON log objects.
2390
2438
  * Prevents outputting extremely long values (e.g., base64, blobs).
2391
2439
  */
2392
- const jsonTruncateFormat = winston.format((info) => {
2440
+ const jsonTruncateFormat = winston__default.default.format((info) => {
2393
2441
  const truncateLongStrings = (str, maxLength) => str.length > maxLength ? str.substring(0, maxLength) + '...' : str;
2394
2442
  const seen = new WeakSet();
2395
2443
  const truncateObject = (obj) => {
@@ -2420,7 +2468,7 @@ const jsonTruncateFormat = winston.format((info) => {
2420
2468
  return truncateObject(info);
2421
2469
  });
2422
2470
 
2423
- const logDir = path.join(__dirname, '..', '..', '..', 'api', 'logs');
2471
+ const logDir = getLogDirectory();
2424
2472
  const { NODE_ENV, DEBUG_LOGGING, CONSOLE_JSON, DEBUG_CONSOLE } = process.env;
2425
2473
  const useConsoleJson = typeof CONSOLE_JSON === 'string' && CONSOLE_JSON.toLowerCase() === 'true';
2426
2474
  const useDebugConsole = typeof DEBUG_CONSOLE === 'string' && DEBUG_CONSOLE.toLowerCase() === 'true';
@@ -2435,7 +2483,7 @@ const levels = {
2435
2483
  activity: 6,
2436
2484
  silly: 7,
2437
2485
  };
2438
- winston.addColors({
2486
+ winston__default.default.addColors({
2439
2487
  info: 'green',
2440
2488
  warn: 'italic yellow',
2441
2489
  error: 'red',
@@ -2445,9 +2493,9 @@ const level = () => {
2445
2493
  const env = NODE_ENV || 'development';
2446
2494
  return env === 'development' ? 'debug' : 'warn';
2447
2495
  };
2448
- 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());
2449
2497
  const transports = [
2450
- new winston.transports.DailyRotateFile({
2498
+ new winston__default.default.transports.DailyRotateFile({
2451
2499
  level: 'error',
2452
2500
  filename: `${logDir}/error-%DATE%.log`,
2453
2501
  datePattern: 'YYYY-MM-DD',
@@ -2458,17 +2506,17 @@ const transports = [
2458
2506
  }),
2459
2507
  ];
2460
2508
  if (useDebugLogging) {
2461
- transports.push(new winston.transports.DailyRotateFile({
2509
+ transports.push(new winston__default.default.transports.DailyRotateFile({
2462
2510
  level: 'debug',
2463
2511
  filename: `${logDir}/debug-%DATE%.log`,
2464
2512
  datePattern: 'YYYY-MM-DD',
2465
2513
  zippedArchive: true,
2466
2514
  maxSize: '20m',
2467
2515
  maxFiles: '14d',
2468
- format: winston.format.combine(fileFormat, debugTraverse),
2516
+ format: winston__default.default.format.combine(fileFormat, debugTraverse),
2469
2517
  }));
2470
2518
  }
2471
- 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) => {
2472
2520
  const message = `${info.timestamp} ${info.level}: ${info.message}`;
2473
2521
  return info.level.includes('error') ? redactMessage(message) : message;
2474
2522
  }));
@@ -2478,27 +2526,27 @@ if (useDebugConsole) {
2478
2526
  }
2479
2527
  // Add console transport
2480
2528
  if (useDebugConsole) {
2481
- transports.push(new winston.transports.Console({
2529
+ transports.push(new winston__default.default.transports.Console({
2482
2530
  level: consoleLogLevel,
2483
2531
  format: useConsoleJson
2484
- ? winston.format.combine(fileFormat, jsonTruncateFormat(), winston.format.json())
2485
- : 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),
2486
2534
  }));
2487
2535
  }
2488
2536
  else if (useConsoleJson) {
2489
- transports.push(new winston.transports.Console({
2537
+ transports.push(new winston__default.default.transports.Console({
2490
2538
  level: consoleLogLevel,
2491
- format: winston.format.combine(fileFormat, jsonTruncateFormat(), winston.format.json()),
2539
+ format: winston__default.default.format.combine(fileFormat, jsonTruncateFormat(), winston__default.default.format.json()),
2492
2540
  }));
2493
2541
  }
2494
2542
  else {
2495
- transports.push(new winston.transports.Console({
2543
+ transports.push(new winston__default.default.transports.Console({
2496
2544
  level: consoleLogLevel,
2497
2545
  format: consoleFormat,
2498
2546
  }));
2499
2547
  }
2500
2548
  // Create logger
2501
- const logger = winston.createLogger({
2549
+ const logger = winston__default.default.createLogger({
2502
2550
  level: level(),
2503
2551
  levels,
2504
2552
  transports,