mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-25 17:06:24 +00:00
- Stop loading agent/model-spec config server-side (closes the agent-access IDOR and the spec-prompt special-casing). Provider/model/window now come from the client-resolved request (`limits.endpoint`/model — the agent's real provider, not the `agents` endpoint, so the tokenizer is right). Agent/spec/ promptPrefix instructions are uniformly deferred to the full-fidelity follow-up. - Detect summarized branches via the live path's `metadata.summaryUsedTokens` marker (was the wrong `summaryTokenCount` field) and fall back to the summary-aware estimate. - Invalidate the projection query on in-place message edits via a branch content `revision` in the cache key (the tail id is unchanged on edit). Deferred (valid, not a regression): same-window endpoint/model switch keeps a window-matched snapshot — needs endpoint/model persisted on the snapshot, which lands with the fidelity follow-up. Smoke-tested: fits / prunes / summarized→null / no-window→null.
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
const { logger } = require('@librechat/data-schemas');
|
|
const { resolveContextProjection } = require('@librechat/api');
|
|
const db = require('~/models');
|
|
|
|
/**
|
|
* Returns a server-side context-usage projection for the viewed branch + config
|
|
* (agents SDK, no model call) — powers the gauge for snapshot-less branches and
|
|
* after a model/window switch. Resolution lives in `@librechat/api`; this
|
|
* controller only injects request-scoped model accessors.
|
|
* @param {ServerRequest} req
|
|
* @param {ServerResponse} res
|
|
*/
|
|
async function contextProjectionController(req, res) {
|
|
try {
|
|
const params = req.body ?? {};
|
|
if (!params.conversationId || !params.messageId) {
|
|
res.json(null);
|
|
return;
|
|
}
|
|
const projection = await resolveContextProjection(
|
|
{ userId: req.user?.id, getMessages: db.getMessages },
|
|
params,
|
|
);
|
|
res.json(projection ?? null);
|
|
} catch (error) {
|
|
logger.error('[contextProjectionController]', error);
|
|
res.status(500).json({ error: 'Failed to resolve context projection' });
|
|
}
|
|
}
|
|
|
|
module.exports = contextProjectionController;
|