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