mirror of
https://github.com/hanzoai/chat.git
synced 2026-09-30 20:51:17 +00:00
The composer hard-requires a handful of read-only bootstrap calls. Switch
exactly those to requireGuestOrJwtAuth and add a guest branch that returns
safe, scoped data — never a DB lookup, never another user's data:
- GET /api/endpoints → ONLY the guest endpoint (Hanzo)
- GET /api/models → ONLY the single guest model
- GET /api/user → ephemeral guest principal (no email)
- GET /api/convos → empty conversation page
- GET /api/user/settings/favorites → []
- GET /api/agents/chat/active → { activeJobIds: [] }
Every mutation and read-by-id route stays JWT-only and rejects guests with
a clean 401 (post jwt-strategy fix). Banner (optionalJwtAuth) now resolves
with no user for guests. Adds controller + full-chain integration tests.
55 lines
1.7 KiB
JavaScript
55 lines
1.7 KiB
JavaScript
const { logger } = require('@librechat/data-schemas');
|
|
const { CacheKeys } = require('librechat-data-provider');
|
|
const { loadDefaultModels, loadConfigModels } = require('~/server/services/Config');
|
|
const { buildGuestModelsConfig } = require('~/server/services/guestConfig');
|
|
const { getLogStores } = require('~/cache');
|
|
|
|
/**
|
|
* @param {ServerRequest} req
|
|
* @returns {Promise<TModelsConfig>} The models config.
|
|
*/
|
|
const getModelsConfig = async (req) => {
|
|
const cache = getLogStores(CacheKeys.CONFIG_STORE);
|
|
let modelsConfig = await cache.get(CacheKeys.MODELS_CONFIG);
|
|
if (!modelsConfig) {
|
|
modelsConfig = await loadModels(req);
|
|
}
|
|
|
|
return modelsConfig;
|
|
};
|
|
|
|
/**
|
|
* Loads the models from the config.
|
|
* @param {ServerRequest} req - The Express request object.
|
|
* @returns {Promise<TModelsConfig>} The models config.
|
|
*/
|
|
async function loadModels(req) {
|
|
const cache = getLogStores(CacheKeys.CONFIG_STORE);
|
|
const cachedModelsConfig = await cache.get(CacheKeys.MODELS_CONFIG);
|
|
if (cachedModelsConfig) {
|
|
return cachedModelsConfig;
|
|
}
|
|
const defaultModelsConfig = await loadDefaultModels(req);
|
|
const customModelsConfig = await loadConfigModels(req);
|
|
|
|
const modelConfig = { ...defaultModelsConfig, ...customModelsConfig };
|
|
|
|
await cache.set(CacheKeys.MODELS_CONFIG, modelConfig);
|
|
return modelConfig;
|
|
}
|
|
|
|
async function modelController(req, res) {
|
|
try {
|
|
if (req.user?.guest === true) {
|
|
return res.send(buildGuestModelsConfig());
|
|
}
|
|
const modelConfig = await loadModels(req);
|
|
res.send(modelConfig);
|
|
} catch (error) {
|
|
logger.error('Error fetching models:', error);
|
|
res.status(500).send({ error: error.message });
|
|
}
|
|
}
|
|
|
|
module.exports = { modelController, loadModels, getModelsConfig };
|