This commit is contained in:
Artyom Bogachenko 2026-04-04 06:50:00 +02:00 committed by GitHub
commit 16f03a7593
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1311 additions and 57 deletions

View file

@ -109,11 +109,24 @@ router.get('/chat/stream/:streamId', async (req, res) => {
}
};
const onChunk = (event) => {
if (!res.writableEnded) {
if (event.event === 'progress') {
res.write(`event: progress\ndata: ${JSON.stringify(event.data)}\n\n`);
} else {
res.write(`event: message\ndata: ${JSON.stringify(event)}\n\n`);
}
if (typeof res.flush === 'function') {
res.flush();
}
}
};
let result;
if (isResume) {
const { subscription, resumeState, pendingEvents } =
await GenerationJobManager.subscribeWithResume(streamId, writeEvent, onDone, onError);
await GenerationJobManager.subscribeWithResume(streamId, onChunk, onDone, onError);
if (!res.writableEnded) {
if (resumeState) {
@ -139,7 +152,7 @@ router.get('/chat/stream/:streamId', async (req, res) => {
result = subscription;
} else {
result = await GenerationJobManager.subscribe(streamId, writeEvent, onDone, onError);
result = await GenerationJobManager.subscribe(streamId, onChunk, onDone, onError);
}
if (!result) {

View file

@ -8,6 +8,7 @@ const {
} = require('@librechat/agents');
const {
sendEvent,
sendProgress,
MCPOAuthHandler,
isMCPDomainAllowed,
normalizeServerName,
@ -649,6 +650,30 @@ function createToolInstance({
oauthStart,
oauthEnd,
graphTokenResolver: getGraphApiToken,
onProgress: async (progressData) => {
logger.debug(
`[MCP][${serverName}][${toolName}] Sending progress to client:`,
progressData,
);
const eventData = {
progress: progressData.progress,
total: progressData.total,
message: progressData.message,
toolCallId: toolCall.id,
};
try {
if (streamId) {
await GenerationJobManager.emitTransientEvent(streamId, {
event: 'progress',
data: eventData,
});
} else {
sendProgress(res, eventData);
}
} catch (err) {
logger.error(`[MCP][${serverName}][${toolName}] Failed to emit progress:`, err);
}
},
});
if (isAssistantsEndpoint(provider) && Array.isArray(result)) {