mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-20 20:20:42 +00:00
- extract the token-config resolution (override gathering + cache lookup + buildTokenConfigMap) into resolveTokenConfigMap in packages/api, leaving the /api controller a thin request-scoped wrapper (CLAUDE.md TS rule) - getConvoKey prefers the user message's real conversationId once the `created` event stamps it, so a new chat's first-response live gauge and totals land under the id TokenUsage subscribes to instead of NEW_CONVO
27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
const { logger } = require('@librechat/data-schemas');
|
|
const { resolveTokenConfigMap } = require('@librechat/api');
|
|
const { getModelsConfig } = require('~/server/controllers/ModelController');
|
|
const { getValueKey, getMultiplier, getCacheMultiplier } = require('~/models');
|
|
|
|
/**
|
|
* Returns server-resolved context windows (and pricing when
|
|
* `interface.contextCost` is enabled) for every configured model. Resolution
|
|
* lives in `@librechat/api`; this controller only supplies request-scoped deps.
|
|
* @param {ServerRequest} req
|
|
* @param {ServerResponse} res
|
|
*/
|
|
async function tokenConfigController(req, res) {
|
|
try {
|
|
const modelsConfig = await getModelsConfig(req);
|
|
const tokenConfigMap = await resolveTokenConfigMap(
|
|
{ appConfig: req.config, modelsConfig, userId: req.user.id },
|
|
{ getValueKey, getMultiplier, getCacheMultiplier },
|
|
);
|
|
res.json(tokenConfigMap);
|
|
} catch (error) {
|
|
logger.error('[tokenConfigController]', error);
|
|
res.status(500).json({ error: 'Failed to resolve token config' });
|
|
}
|
|
}
|
|
|
|
module.exports = tokenConfigController;
|