mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50: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
ff14cd3b44
commit
1853b4a189
11 changed files with 295 additions and 136 deletions
|
|
@ -177,6 +177,7 @@ class GenerationJobManagerClass {
|
|||
);
|
||||
|
||||
// Create a final event for abort so clients can properly handle UI cleanup
|
||||
const userMessageId = job.metadata.userMessage?.messageId;
|
||||
const abortFinalEvent = {
|
||||
final: true,
|
||||
conversation: {
|
||||
|
|
@ -185,18 +186,23 @@ class GenerationJobManagerClass {
|
|||
title: 'New Chat',
|
||||
requestMessage: job.metadata.userMessage
|
||||
? {
|
||||
messageId: job.metadata.userMessage.messageId,
|
||||
messageId: userMessageId,
|
||||
parentMessageId: job.metadata.userMessage.parentMessageId,
|
||||
conversationId: job.metadata.conversationId,
|
||||
text: job.metadata.userMessage.text ?? '',
|
||||
isCreatedByUser: true,
|
||||
}
|
||||
: null,
|
||||
responseMessage: {
|
||||
messageId:
|
||||
job.metadata.responseMessageId ?? `${job.metadata.userMessage?.messageId ?? 'aborted'}_`,
|
||||
messageId: job.metadata.responseMessageId ?? `${userMessageId ?? 'aborted'}_`,
|
||||
parentMessageId: userMessageId, // Link response to user message
|
||||
conversationId: job.metadata.conversationId,
|
||||
content: job.aggregatedContent ?? [],
|
||||
sender: job.metadata.sender ?? 'AI',
|
||||
unfinished: true,
|
||||
error: true,
|
||||
/** Not an error - the job was intentionally aborted */
|
||||
error: false,
|
||||
isCreatedByUser: false,
|
||||
},
|
||||
aborted: true,
|
||||
} as unknown as ServerSentEvent;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue