| import { logger } from '@librechat/data-schemas'; |
| import type { AppConfig } from '@librechat/data-schemas'; |
|
|
| |
| |
| |
| export const DEFAULT_RETENTION_HOURS = 24 * 30; |
|
|
| |
| |
| |
| export const MIN_RETENTION_HOURS = 1; |
|
|
| |
| |
| |
| export const MAX_RETENTION_HOURS = 8760; |
|
|
| |
| |
| |
| |
| |
| export function getTempChatRetentionHours( |
| interfaceConfig?: AppConfig['interfaceConfig'] | null, |
| ): number { |
| let retentionHours = DEFAULT_RETENTION_HOURS; |
|
|
| |
| if (process.env.TEMP_CHAT_RETENTION_HOURS) { |
| const envValue = parseInt(process.env.TEMP_CHAT_RETENTION_HOURS, 10); |
| if (!isNaN(envValue)) { |
| retentionHours = envValue; |
| } else { |
| logger.warn( |
| `Invalid TEMP_CHAT_RETENTION_HOURS environment variable: ${process.env.TEMP_CHAT_RETENTION_HOURS}. Using default: ${DEFAULT_RETENTION_HOURS} hours.`, |
| ); |
| } |
| } |
|
|
| |
| if (interfaceConfig?.temporaryChatRetention !== undefined) { |
| const configValue = interfaceConfig.temporaryChatRetention; |
| if (typeof configValue === 'number' && !isNaN(configValue)) { |
| retentionHours = configValue; |
| } else { |
| logger.warn( |
| `Invalid temporaryChatRetention in config: ${configValue}. Using ${retentionHours} hours.`, |
| ); |
| } |
| } |
|
|
| |
| if (retentionHours < MIN_RETENTION_HOURS) { |
| logger.warn( |
| `Temporary chat retention period ${retentionHours} is below minimum ${MIN_RETENTION_HOURS} hours. Using minimum value.`, |
| ); |
| retentionHours = MIN_RETENTION_HOURS; |
| } else if (retentionHours > MAX_RETENTION_HOURS) { |
| logger.warn( |
| `Temporary chat retention period ${retentionHours} exceeds maximum ${MAX_RETENTION_HOURS} hours. Using maximum value.`, |
| ); |
| retentionHours = MAX_RETENTION_HOURS; |
| } |
|
|
| return retentionHours; |
| } |
|
|
| |
| |
| |
| |
| |
| export function createTempChatExpirationDate(interfaceConfig?: AppConfig['interfaceConfig']): Date { |
| const retentionHours = getTempChatRetentionHours(interfaceConfig); |
| return new Date(Date.now() + retentionHours * 60 * 60 * 1000); |
| } |
|
|