LibreChat/api/server/middleware/setHeaders.js
Danny Avila 0e850a5d5f
feat: Implement Resumable Generation Jobs with SSE Support
- Introduced GenerationJobManager to handle resumable LLM generation jobs independently of HTTP connections.
- Added support for subscribing to ongoing generation jobs via SSE, allowing clients to reconnect and receive updates without losing progress.
- Enhanced existing agent controllers and routes to integrate resumable functionality, including job creation, completion, and error handling.
- Updated client-side hooks to manage adaptive SSE streams, switching between standard and resumable modes based on user settings.
- Added UI components and settings for enabling/disabling resumable streams, improving user experience during unstable connections.
2025-12-15 18:48:52 -05:00

17 lines
462 B
JavaScript

function setHeaders(req, res, next) {
// Skip SSE headers for resumable mode - it returns JSON first, then client subscribes separately
if (req.query.resumable === 'true') {
return next();
}
res.writeHead(200, {
Connection: 'keep-alive',
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache, no-transform',
'Access-Control-Allow-Origin': '*',
'X-Accel-Buffering': 'no',
});
next();
}
module.exports = setHeaders;