mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-27 12:54:09 +01:00
📌 fix: Populate userMessage.files Before First DB Save (#11939)
* fix: populate userMessage.files before first DB save * fix: ESLint error fixed * fix: deduplicate file-population logic and add test coverage Extract `buildMessageFiles` helper into `packages/api/src/utils/message` to replace three near-identical loops in BaseClient and both agent controllers. Fixes set poisoning from undefined file_id entries, moves file population inside the skipSaveUserMessage guard to avoid wasted work, and adds full unit test coverage for the new behavior. * chore: reorder import statements in openIdJwtStrategy.js for consistency --------- Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
parent
13df8ed67c
commit
3a079b980a
6 changed files with 258 additions and 48 deletions
|
|
@ -4,6 +4,7 @@ const { logger } = require('@librechat/data-schemas');
|
|||
const {
|
||||
countTokens,
|
||||
getBalanceConfig,
|
||||
buildMessageFiles,
|
||||
extractFileContext,
|
||||
encodeAndFormatAudios,
|
||||
encodeAndFormatVideos,
|
||||
|
|
@ -670,6 +671,14 @@ class BaseClient {
|
|||
}
|
||||
|
||||
if (!isEdited && !this.skipSaveUserMessage) {
|
||||
const reqFiles = this.options.req?.body?.files;
|
||||
if (reqFiles && Array.isArray(this.options.attachments)) {
|
||||
const files = buildMessageFiles(reqFiles, this.options.attachments);
|
||||
if (files.length > 0) {
|
||||
userMessage.files = files;
|
||||
}
|
||||
delete userMessage.image_urls;
|
||||
}
|
||||
userMessagePromise = this.saveMessageToDatabase(userMessage, saveOptions, user);
|
||||
this.savedMessageIds.add(userMessage.messageId);
|
||||
if (typeof opts?.getReqData === 'function') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue