mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* Style: Infinite Scroll and Group convos by date * Style: Infinite Scroll and Group convos by date- Redesign NavBar * Style: Infinite Scroll and Group convos by date- Redesign NavBar - Clean code * Style: Infinite Scroll and Group convos by date- Redesign NavBar - Redesign NewChat Component * Style: Infinite Scroll and Group convos by date- Redesign NavBar - Redesign NewChat Component * Style: Infinite Scroll and Group convos by date- Redesign NavBar - Redesign NewChat Component * Including OpenRouter and Mistral icon * refactor(Conversations): cleanup use of utility functions and typing * refactor(Nav/NewChat): use localStorage `lastConversationSetup` to determine the endpoint to use, as well as icons -> JSX components, remove use of `endpointSelected` * refactor: remove use of `isFirstToday` * refactor(Nav): remove use of `endpointSelected`, consolidate scrolling logic to its own hook `useNavScrolling`, remove use of recoil `conversation` * refactor: Add spinner to bottom of list, throttle fetching, move query hooks to client workspace * chore: sort by `updatedAt` field * refactor: optimize conversation infinite query, use optimistic updates, add conversation helpers for managing pagination, remove unnecessary operations * feat: gen_title route for generating the title for the conversation * style(Convo): change hover bg-color * refactor: memoize groupedConversations and return as array of tuples, correctly update convos pre/post message stream, only call genTitle if conversation is new, make `addConversation` dynamically either add/update depending if convo exists in pages already, reorganize type definitions * style: rename Header NewChat Button -> HeaderNewChat, add NewChatIcon, closely match main Nav New Chat button to ChatGPT * style(NewChat): add hover bg color * style: cleanup comments, match ChatGPT nav styling, redesign search bar, make part of new chat sticky header, move Nav under same parent as outlet/mobilenav, remove legacy code, search only if searchQuery is not empty * feat: add tests for conversation helpers and ensure no duplicate conversations are ever grouped * style: hover bg-color * feat: alt-click on convo item to open conversation in new tab * chore: send error message when `gen_title` fails --------- Co-authored-by: Walber Cardoso <walbercardoso@gmail.com>
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
const Keyv = require('keyv');
|
|
const { CacheKeys } = require('librechat-data-provider');
|
|
const { logFile, violationFile } = require('./keyvFiles');
|
|
const { math, isEnabled } = require('~/server/utils');
|
|
const keyvRedis = require('./keyvRedis');
|
|
const keyvMongo = require('./keyvMongo');
|
|
|
|
const { BAN_DURATION, USE_REDIS } = process.env ?? {};
|
|
|
|
const duration = math(BAN_DURATION, 7200000);
|
|
|
|
const createViolationInstance = (namespace) => {
|
|
const config = isEnabled(USE_REDIS) ? { store: keyvRedis } : { store: violationFile, namespace };
|
|
return new Keyv(config);
|
|
};
|
|
|
|
// Serve cache from memory so no need to clear it on startup/exit
|
|
const pending_req = isEnabled(USE_REDIS)
|
|
? new Keyv({ store: keyvRedis })
|
|
: new Keyv({ namespace: 'pending_req' });
|
|
|
|
const config = isEnabled(USE_REDIS)
|
|
? new Keyv({ store: keyvRedis })
|
|
: new Keyv({ namespace: CacheKeys.CONFIG_STORE });
|
|
|
|
const tokenConfig = isEnabled(USE_REDIS) // ttl: 30 minutes
|
|
? new Keyv({ store: keyvRedis, ttl: 1800000 })
|
|
: new Keyv({ namespace: CacheKeys.TOKEN_CONFIG, ttl: 1800000 });
|
|
|
|
const genTitle = isEnabled(USE_REDIS) // ttl: 2 minutes
|
|
? new Keyv({ store: keyvRedis, ttl: 120000 })
|
|
: new Keyv({ namespace: CacheKeys.GEN_TITLE, ttl: 120000 });
|
|
|
|
const namespaces = {
|
|
[CacheKeys.CONFIG_STORE]: config,
|
|
pending_req,
|
|
ban: new Keyv({ store: keyvMongo, namespace: 'bans', ttl: duration }),
|
|
general: new Keyv({ store: logFile, namespace: 'violations' }),
|
|
concurrent: createViolationInstance('concurrent'),
|
|
non_browser: createViolationInstance('non_browser'),
|
|
message_limit: createViolationInstance('message_limit'),
|
|
token_balance: createViolationInstance('token_balance'),
|
|
registrations: createViolationInstance('registrations'),
|
|
logins: createViolationInstance('logins'),
|
|
[CacheKeys.TOKEN_CONFIG]: tokenConfig,
|
|
[CacheKeys.GEN_TITLE]: genTitle,
|
|
};
|
|
|
|
/**
|
|
* Returns the keyv cache specified by type.
|
|
* If an invalid type is passed, an error will be thrown.
|
|
*
|
|
* @param {string} key - The key for the namespace to access
|
|
* @returns {Keyv} - If a valid key is passed, returns an object containing the cache store of the specified key.
|
|
* @throws Will throw an error if an invalid key is passed.
|
|
*/
|
|
const getLogStores = (key) => {
|
|
if (!key || !namespaces[key]) {
|
|
throw new Error(`Invalid store key: ${key}`);
|
|
}
|
|
return namespaces[key];
|
|
};
|
|
|
|
module.exports = getLogStores;
|