🔗 fix: File Citation Processing to Use Tool Artifacts

This commit is contained in:
Danny Avila 2025-07-30 19:24:01 -04:00
parent 81b32e400a
commit fc8fd489d6
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
8 changed files with 524 additions and 538 deletions

View file

@ -11,6 +11,7 @@ const {
handleToolCalls,
ChatModelStreamHandler,
} = require('@librechat/agents');
const { processFileCitations } = require('~/server/services/Files/Citations');
const { processCodeOutput } = require('~/server/services/Files/Code/process');
const { loadAuthValues } = require('~/server/services/Tools/credentials');
const { saveBase64Image } = require('~/server/services/Files/process');
@ -238,6 +239,31 @@ function createToolEndCallback({ req, res, artifactPromises }) {
return;
}
if (output.artifact[Tools.file_search]) {
artifactPromises.push(
(async () => {
const user = req.user;
const attachment = await processFileCitations({
user,
metadata,
toolArtifact: output.artifact,
toolCallId: output.tool_call_id,
});
if (!attachment) {
return null;
}
if (!res.headersSent) {
return attachment;
}
res.write(`event: attachment\ndata: ${JSON.stringify(attachment)}\n\n`);
return attachment;
})().catch((error) => {
logger.error('Error processing file citations:', error);
return null;
}),
);
}
if (output.artifact[Tools.web_search]) {
artifactPromises.push(
(async () => {

View file

@ -49,7 +49,6 @@ const BaseClient = require('~/app/clients/BaseClient');
const { getRoleByName } = require('~/models/Role');
const { loadAgent } = require('~/models/Agent');
const { getMCPManager } = require('~/config');
const { processAgentResponse } = require('~/app/clients/agents/processAgentResponse');
const omitTitleOptions = new Set([
'stream',
@ -1036,27 +1035,6 @@ class AgentClient extends BaseClient {
this.artifactPromises.push(...attachments);
}
// Process agent response to capture file references and create attachments
const processedResponse = await processAgentResponse(
{
messageId: this.responseMessageId,
attachments: this.artifactPromises,
},
this.user ?? this.options.req.user?.id,
this.conversationId,
this.contentParts,
this.options.req.user,
);
// Update artifact promises with any new attachments from agent response
if (processedResponse.attachments && processedResponse.attachments.length > 0) {
// Add new attachments to existing artifactPromises
processedResponse.attachments.forEach((attachment) => {
this.artifactPromises.push(Promise.resolve(attachment));
});
}
await this.recordCollectedUsage({ context: 'message' });
} catch (err) {
logger.error(