mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
feat: Enhance Stream Management with Abort Functionality
- Updated the abort endpoint to support aborting ongoing generation streams using either streamId or conversationId. - Introduced a new mutation hook `useAbortStreamMutation` for client-side integration. - Added `useStreamStatus` query to monitor stream status and facilitate resuming conversations. - Enhanced `useChatHelpers` to incorporate abort functionality when stopping generation. - Improved `useResumableSSE` to handle stream errors and token refresh seamlessly. - Updated `useResumeOnLoad` to check for active streams and resume conversations appropriately.
This commit is contained in:
parent
21d0dc1a8c
commit
eba658ef31
11 changed files with 295 additions and 136 deletions
|
|
@ -156,12 +156,27 @@ router.post('/chat/abort', (req, res) => {
|
|||
logger.debug(`[AgentStream] Method: ${req.method}, Path: ${req.path}`);
|
||||
logger.debug(`[AgentStream] Body:`, req.body);
|
||||
|
||||
const { streamId, abortKey } = req.body;
|
||||
const { streamId, conversationId, abortKey } = req.body;
|
||||
|
||||
// Try to find job by streamId first, then by conversationId, then by abortKey
|
||||
let jobStreamId = streamId;
|
||||
let job = jobStreamId ? GenerationJobManager.getJob(jobStreamId) : null;
|
||||
|
||||
if (!job && conversationId) {
|
||||
job = GenerationJobManager.getJobByConversation(conversationId);
|
||||
if (job) {
|
||||
jobStreamId = job.streamId;
|
||||
}
|
||||
}
|
||||
|
||||
if (!job && abortKey) {
|
||||
jobStreamId = abortKey.split(':')[0];
|
||||
job = GenerationJobManager.getJob(jobStreamId);
|
||||
}
|
||||
|
||||
const jobStreamId = streamId || abortKey?.split(':')?.[0];
|
||||
logger.debug(`[AgentStream] Computed jobStreamId: ${jobStreamId}`);
|
||||
|
||||
if (jobStreamId && GenerationJobManager.hasJob(jobStreamId)) {
|
||||
if (job && jobStreamId) {
|
||||
logger.debug(`[AgentStream] Job found, aborting: ${jobStreamId}`);
|
||||
GenerationJobManager.abortJob(jobStreamId);
|
||||
logger.debug(`[AgentStream] Job aborted successfully: ${jobStreamId}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue