mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 18:00:15 +01:00
⚙️ chore: Resolve Build Warning, Package Cleanup, Robust Temp Chat Time (#9962)
* ⚙️ chore: Resolve Build Warning and `keyvMongo` types * 🔄 chore: Update mongodb version to ^6.14.2 in package.json and package-lock.json * chore: remove @langchain/openai dep * 🔄 refactor: Change log level from warn to debug for missing endpoint config * 🔄 refactor: Improve temp chat expiration date calculation in tests and implementation
This commit is contained in:
parent
c0ed738aed
commit
1b8a0bfaee
12 changed files with 131 additions and 254 deletions
7
packages/api/src/cache/keyvMongo.ts
vendored
7
packages/api/src/cache/keyvMongo.ts
vendored
|
|
@ -1,7 +1,8 @@
|
|||
import mongoose from 'mongoose';
|
||||
import { EventEmitter } from 'events';
|
||||
import { GridFSBucket } from 'mongodb';
|
||||
import { logger } from '@librechat/data-schemas';
|
||||
import { GridFSBucket, type Db, type ReadPreference, type Collection } from 'mongodb';
|
||||
import type { Db, ReadPreference, Collection } from 'mongodb';
|
||||
|
||||
interface KeyvMongoOptions {
|
||||
url?: string;
|
||||
|
|
@ -103,7 +104,7 @@ class KeyvMongoCustom extends EventEmitter {
|
|||
const stream = client.bucket.openDownloadStreamByName(key);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const resp: Buffer[] = [];
|
||||
const resp: Uint8Array[] = [];
|
||||
stream.on('error', () => {
|
||||
resolve(undefined);
|
||||
});
|
||||
|
|
@ -113,7 +114,7 @@ class KeyvMongoCustom extends EventEmitter {
|
|||
resolve(data);
|
||||
});
|
||||
|
||||
stream.on('data', (chunk: Buffer) => {
|
||||
stream.on('data', (chunk: Uint8Array) => {
|
||||
resp.push(chunk);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -92,14 +92,16 @@ describe('tempChatRetention', () => {
|
|||
|
||||
describe('createTempChatExpirationDate', () => {
|
||||
it('should create expiration date with default retention period', () => {
|
||||
const beforeCall = Date.now();
|
||||
const result = createTempChatExpirationDate();
|
||||
const afterCall = Date.now();
|
||||
|
||||
const expectedDate = new Date();
|
||||
expectedDate.setHours(expectedDate.getHours() + DEFAULT_RETENTION_HOURS);
|
||||
const expectedMin = beforeCall + DEFAULT_RETENTION_HOURS * 60 * 60 * 1000;
|
||||
const expectedMax = afterCall + DEFAULT_RETENTION_HOURS * 60 * 60 * 1000;
|
||||
|
||||
// Allow for small time differences in test execution
|
||||
const timeDiff = Math.abs(result.getTime() - expectedDate.getTime());
|
||||
expect(timeDiff).toBeLessThan(1000); // Less than 1 second difference
|
||||
// Result should be between expectedMin and expectedMax
|
||||
expect(result.getTime()).toBeGreaterThanOrEqual(expectedMin);
|
||||
expect(result.getTime()).toBeLessThanOrEqual(expectedMax);
|
||||
});
|
||||
|
||||
it('should create expiration date with custom retention period', () => {
|
||||
|
|
@ -109,14 +111,16 @@ describe('tempChatRetention', () => {
|
|||
},
|
||||
};
|
||||
|
||||
const beforeCall = Date.now();
|
||||
const result = createTempChatExpirationDate(config?.interfaceConfig);
|
||||
const afterCall = Date.now();
|
||||
|
||||
const expectedDate = new Date();
|
||||
expectedDate.setHours(expectedDate.getHours() + 12);
|
||||
const expectedMin = beforeCall + 12 * 60 * 60 * 1000;
|
||||
const expectedMax = afterCall + 12 * 60 * 60 * 1000;
|
||||
|
||||
// Allow for small time differences in test execution
|
||||
const timeDiff = Math.abs(result.getTime() - expectedDate.getTime());
|
||||
expect(timeDiff).toBeLessThan(1000); // Less than 1 second difference
|
||||
// Result should be between expectedMin and expectedMax
|
||||
expect(result.getTime()).toBeGreaterThanOrEqual(expectedMin);
|
||||
expect(result.getTime()).toBeLessThanOrEqual(expectedMax);
|
||||
});
|
||||
|
||||
it('should return a Date object', () => {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,5 @@ export function getTempChatRetentionHours(
|
|||
*/
|
||||
export function createTempChatExpirationDate(interfaceConfig?: AppConfig['interfaceConfig']): Date {
|
||||
const retentionHours = getTempChatRetentionHours(interfaceConfig);
|
||||
const expiredAt = new Date();
|
||||
expiredAt.setHours(expiredAt.getHours() + retentionHours);
|
||||
return expiredAt;
|
||||
return new Date(Date.now() + retentionHours * 60 * 60 * 1000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue