@librechat/data-schemas 0.0.13 → 0.0.15
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 +207 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +207 -43
- package/dist/index.es.js.map +1 -1
- package/dist/types/utils/object-traverse.d.ts +23 -0
- package/package.json +1 -4
package/dist/index.cjs
CHANGED
|
@@ -10,7 +10,6 @@ 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');
|
|
14
13
|
var nanoid = require('nanoid');
|
|
15
14
|
|
|
16
15
|
async function signPayload({ payload, secret, expirationTime, }) {
|
|
@@ -2250,6 +2249,160 @@ function createUserMethods(mongoose) {
|
|
|
2250
2249
|
};
|
|
2251
2250
|
}
|
|
2252
2251
|
|
|
2252
|
+
/**
|
|
2253
|
+
* ESM-native object traversal utility
|
|
2254
|
+
* Simplified implementation focused on the forEach use case
|
|
2255
|
+
*/
|
|
2256
|
+
function isObject(value) {
|
|
2257
|
+
if (value === null || typeof value !== 'object') {
|
|
2258
|
+
return false;
|
|
2259
|
+
}
|
|
2260
|
+
// Treat these built-in types as leaf nodes, not objects to traverse
|
|
2261
|
+
if (value instanceof Date)
|
|
2262
|
+
return false;
|
|
2263
|
+
if (value instanceof RegExp)
|
|
2264
|
+
return false;
|
|
2265
|
+
if (value instanceof Error)
|
|
2266
|
+
return false;
|
|
2267
|
+
if (value instanceof URL)
|
|
2268
|
+
return false;
|
|
2269
|
+
// Check for Buffer (Node.js)
|
|
2270
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value))
|
|
2271
|
+
return false;
|
|
2272
|
+
// Check for TypedArrays and ArrayBuffer
|
|
2273
|
+
if (ArrayBuffer.isView(value))
|
|
2274
|
+
return false;
|
|
2275
|
+
if (value instanceof ArrayBuffer)
|
|
2276
|
+
return false;
|
|
2277
|
+
if (value instanceof SharedArrayBuffer)
|
|
2278
|
+
return false;
|
|
2279
|
+
// Check for other built-in types that shouldn't be traversed
|
|
2280
|
+
if (value instanceof Promise)
|
|
2281
|
+
return false;
|
|
2282
|
+
if (value instanceof WeakMap)
|
|
2283
|
+
return false;
|
|
2284
|
+
if (value instanceof WeakSet)
|
|
2285
|
+
return false;
|
|
2286
|
+
if (value instanceof Map)
|
|
2287
|
+
return false;
|
|
2288
|
+
if (value instanceof Set)
|
|
2289
|
+
return false;
|
|
2290
|
+
// Check if it's a primitive wrapper object
|
|
2291
|
+
const stringTag = Object.prototype.toString.call(value);
|
|
2292
|
+
if (stringTag === '[object Boolean]' ||
|
|
2293
|
+
stringTag === '[object Number]' ||
|
|
2294
|
+
stringTag === '[object String]') {
|
|
2295
|
+
return false;
|
|
2296
|
+
}
|
|
2297
|
+
return true;
|
|
2298
|
+
}
|
|
2299
|
+
// Helper to safely set a property on an object or array
|
|
2300
|
+
function setProperty(obj, key, value) {
|
|
2301
|
+
if (Array.isArray(obj) && typeof key === 'number') {
|
|
2302
|
+
obj[key] = value;
|
|
2303
|
+
}
|
|
2304
|
+
else if (!Array.isArray(obj) && typeof key === 'string') {
|
|
2305
|
+
obj[key] = value;
|
|
2306
|
+
}
|
|
2307
|
+
else if (!Array.isArray(obj) && typeof key === 'number') {
|
|
2308
|
+
// Handle numeric keys on objects
|
|
2309
|
+
obj[key] = value;
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
// Helper to safely delete a property from an object
|
|
2313
|
+
function deleteProperty(obj, key) {
|
|
2314
|
+
if (Array.isArray(obj) && typeof key === 'number') {
|
|
2315
|
+
// For arrays, we should use splice, but this is handled in remove()
|
|
2316
|
+
// This function is only called for non-array deletion
|
|
2317
|
+
return;
|
|
2318
|
+
}
|
|
2319
|
+
if (!Array.isArray(obj)) {
|
|
2320
|
+
delete obj[key];
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
function forEach(obj, callback) {
|
|
2324
|
+
const visited = new WeakSet();
|
|
2325
|
+
function walk(node, path = [], parent) {
|
|
2326
|
+
// Check for circular references
|
|
2327
|
+
let circular = null;
|
|
2328
|
+
if (isObject(node)) {
|
|
2329
|
+
if (visited.has(node)) {
|
|
2330
|
+
// Find the circular reference in the parent chain
|
|
2331
|
+
let p = parent;
|
|
2332
|
+
while (p) {
|
|
2333
|
+
if (p.node === node) {
|
|
2334
|
+
circular = p;
|
|
2335
|
+
break;
|
|
2336
|
+
}
|
|
2337
|
+
p = p.parent;
|
|
2338
|
+
}
|
|
2339
|
+
return; // Skip circular references
|
|
2340
|
+
}
|
|
2341
|
+
visited.add(node);
|
|
2342
|
+
}
|
|
2343
|
+
const key = path.length > 0 ? path[path.length - 1] : undefined;
|
|
2344
|
+
const isRoot = path.length === 0;
|
|
2345
|
+
const level = path.length;
|
|
2346
|
+
// Determine if this is a leaf node
|
|
2347
|
+
const isLeaf = !isObject(node) ||
|
|
2348
|
+
(Array.isArray(node) && node.length === 0) ||
|
|
2349
|
+
Object.keys(node).length === 0;
|
|
2350
|
+
// Create context
|
|
2351
|
+
const context = {
|
|
2352
|
+
node,
|
|
2353
|
+
path: [...path],
|
|
2354
|
+
parent,
|
|
2355
|
+
key,
|
|
2356
|
+
isLeaf,
|
|
2357
|
+
notLeaf: !isLeaf,
|
|
2358
|
+
isRoot,
|
|
2359
|
+
notRoot: !isRoot,
|
|
2360
|
+
level,
|
|
2361
|
+
circular,
|
|
2362
|
+
update(value) {
|
|
2363
|
+
if (!isRoot && parent && key !== undefined && isObject(parent.node)) {
|
|
2364
|
+
setProperty(parent.node, key, value);
|
|
2365
|
+
}
|
|
2366
|
+
this.node = value;
|
|
2367
|
+
},
|
|
2368
|
+
remove() {
|
|
2369
|
+
if (!isRoot && parent && key !== undefined && isObject(parent.node)) {
|
|
2370
|
+
if (Array.isArray(parent.node) && typeof key === 'number') {
|
|
2371
|
+
parent.node.splice(key, 1);
|
|
2372
|
+
}
|
|
2373
|
+
else {
|
|
2374
|
+
deleteProperty(parent.node, key);
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
},
|
|
2378
|
+
};
|
|
2379
|
+
// Call the callback with the context
|
|
2380
|
+
callback.call(context, node);
|
|
2381
|
+
// Traverse children if not circular and is an object
|
|
2382
|
+
if (!circular && isObject(node) && !isLeaf) {
|
|
2383
|
+
if (Array.isArray(node)) {
|
|
2384
|
+
for (let i = 0; i < node.length; i++) {
|
|
2385
|
+
walk(node[i], [...path, i], context);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
else {
|
|
2389
|
+
for (const [childKey, childValue] of Object.entries(node)) {
|
|
2390
|
+
walk(childValue, [...path, childKey], context);
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
walk(obj);
|
|
2396
|
+
}
|
|
2397
|
+
// Main traverse function that returns an object with forEach method
|
|
2398
|
+
function traverse(obj) {
|
|
2399
|
+
return {
|
|
2400
|
+
forEach(callback) {
|
|
2401
|
+
forEach(obj, callback);
|
|
2402
|
+
},
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2253
2406
|
const SPLAT_SYMBOL = Symbol.for('splat');
|
|
2254
2407
|
const MESSAGE_SYMBOL = Symbol.for('message');
|
|
2255
2408
|
const CONSOLE_JSON_STRING_LENGTH = parseInt(process.env.CONSOLE_JSON_STRING_LENGTH || '', 10) || 255;
|
|
@@ -2353,67 +2506,78 @@ const debugTraverse = winston.format.printf(({ level, message, timestamp, ...met
|
|
|
2353
2506
|
if (typeof message !== 'string' || !message.trim) {
|
|
2354
2507
|
return `${timestamp} ${level}: ${JSON.stringify(message)}`;
|
|
2355
2508
|
}
|
|
2356
|
-
|
|
2509
|
+
const msgParts = [
|
|
2510
|
+
`${timestamp} ${level}: ${truncateLongStrings(message.trim(), 150)}`,
|
|
2511
|
+
];
|
|
2357
2512
|
try {
|
|
2358
2513
|
if (level !== 'debug') {
|
|
2359
|
-
return
|
|
2514
|
+
return msgParts[0];
|
|
2360
2515
|
}
|
|
2361
2516
|
if (!metadata) {
|
|
2362
|
-
return
|
|
2517
|
+
return msgParts[0];
|
|
2363
2518
|
}
|
|
2364
2519
|
// Type-safe access to SPLAT_SYMBOL using bracket notation
|
|
2365
2520
|
const metadataRecord = metadata;
|
|
2366
2521
|
const splatArray = metadataRecord[SPLAT_SYMBOL];
|
|
2367
2522
|
const debugValue = Array.isArray(splatArray) ? splatArray[0] : undefined;
|
|
2368
2523
|
if (!debugValue) {
|
|
2369
|
-
return
|
|
2524
|
+
return msgParts[0];
|
|
2370
2525
|
}
|
|
2371
2526
|
if (debugValue && Array.isArray(debugValue)) {
|
|
2372
|
-
|
|
2373
|
-
return
|
|
2527
|
+
msgParts.push(`\n${JSON.stringify(debugValue.map(condenseArray))}`);
|
|
2528
|
+
return msgParts.join('');
|
|
2374
2529
|
}
|
|
2375
2530
|
if (typeof debugValue !== 'object') {
|
|
2376
|
-
|
|
2531
|
+
msgParts.push(` ${debugValue}`);
|
|
2532
|
+
return msgParts.join('');
|
|
2377
2533
|
}
|
|
2378
|
-
|
|
2534
|
+
msgParts.push('\n{');
|
|
2379
2535
|
const copy = klona.klona(metadata);
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
const
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
this.
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2536
|
+
try {
|
|
2537
|
+
const traversal = traverse(copy);
|
|
2538
|
+
traversal.forEach(function (value) {
|
|
2539
|
+
var _a;
|
|
2540
|
+
if (typeof (this === null || this === void 0 ? void 0 : this.key) === 'symbol') {
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2543
|
+
let _parentKey = '';
|
|
2544
|
+
const parent = this.parent;
|
|
2545
|
+
if (typeof (parent === null || parent === void 0 ? void 0 : parent.key) !== 'symbol' && (parent === null || parent === void 0 ? void 0 : parent.key) !== undefined) {
|
|
2546
|
+
_parentKey = String(parent.key);
|
|
2547
|
+
}
|
|
2548
|
+
const parentKey = `${parent && parent.notRoot ? _parentKey + '.' : ''}`;
|
|
2549
|
+
const tabs = `${parent && parent.notRoot ? ' ' : ' '}`;
|
|
2550
|
+
const currentKey = (_a = this === null || this === void 0 ? void 0 : this.key) !== null && _a !== void 0 ? _a : 'unknown';
|
|
2551
|
+
if (this.isLeaf && typeof value === 'string') {
|
|
2552
|
+
const truncatedText = truncateLongStrings(value);
|
|
2553
|
+
msgParts.push(`\n${tabs}${parentKey}${currentKey}: ${JSON.stringify(truncatedText)},`);
|
|
2554
|
+
}
|
|
2555
|
+
else if (this.notLeaf && Array.isArray(value) && value.length > 0) {
|
|
2556
|
+
const currentMessage = `\n${tabs}// ${value.length} ${String(currentKey).replace(/s$/, '')}(s)`;
|
|
2557
|
+
this.update(currentMessage);
|
|
2558
|
+
msgParts.push(currentMessage);
|
|
2559
|
+
const stringifiedArray = value.map(condenseArray);
|
|
2560
|
+
msgParts.push(`\n${tabs}${parentKey}${currentKey}: [${stringifiedArray}],`);
|
|
2561
|
+
}
|
|
2562
|
+
else if (this.isLeaf && typeof value === 'function') {
|
|
2563
|
+
msgParts.push(`\n${tabs}${parentKey}${currentKey}: function,`);
|
|
2564
|
+
}
|
|
2565
|
+
else if (this.isLeaf) {
|
|
2566
|
+
msgParts.push(`\n${tabs}${parentKey}${currentKey}: ${value},`);
|
|
2567
|
+
}
|
|
2568
|
+
});
|
|
2569
|
+
}
|
|
2570
|
+
catch (e) {
|
|
2571
|
+
const errorMessage = e instanceof Error ? e.message : 'Unknown error';
|
|
2572
|
+
msgParts.push(`\n[LOGGER TRAVERSAL ERROR] ${errorMessage}`);
|
|
2573
|
+
}
|
|
2574
|
+
msgParts.push('\n}');
|
|
2575
|
+
return msgParts.join('');
|
|
2413
2576
|
}
|
|
2414
2577
|
catch (e) {
|
|
2415
2578
|
const errorMessage = e instanceof Error ? e.message : 'Unknown error';
|
|
2416
|
-
|
|
2579
|
+
msgParts.push(`\n[LOGGER PARSING ERROR] ${errorMessage}`);
|
|
2580
|
+
return msgParts.join('');
|
|
2417
2581
|
}
|
|
2418
2582
|
});
|
|
2419
2583
|
/**
|