mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 21:01:32 +08:00
feat: emit event on message complete (#5696)
feat: add MESSAGE_COMPLETE event to EventService and emit on message processing completion
This commit is contained in:
parent
d700822505
commit
5bd68b7b5d
@ -5,7 +5,8 @@ export const EventEmitter = new Emittery()
|
||||
export const EVENT_NAMES = {
|
||||
SEND_MESSAGE: 'SEND_MESSAGE',
|
||||
// APPEND_MESSAGE: 'APPEND_MESSAGE',
|
||||
RECEIVE_MESSAGE: 'RECEIVE_MESSAGE',
|
||||
// RECEIVE_MESSAGE: 'RECEIVE_MESSAGE',
|
||||
MESSAGE_COMPLETE: 'MESSAGE_COMPLETE',
|
||||
AI_AUTO_RENAME: 'AI_AUTO_RENAME',
|
||||
CLEAR_MESSAGES: 'CLEAR_MESSAGES',
|
||||
ADD_ASSISTANT: 'ADD_ASSISTANT',
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import db from '@renderer/databases'
|
||||
import { autoRenameTopic } from '@renderer/hooks/useTopic'
|
||||
import { fetchChatCompletion } from '@renderer/services/ApiService'
|
||||
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
||||
import { createStreamProcessor, type StreamProcessorCallbacks } from '@renderer/services/StreamProcessingService'
|
||||
import { estimateMessagesUsage } from '@renderer/services/TokenService'
|
||||
import store from '@renderer/store'
|
||||
@ -598,6 +599,13 @@ const fetchAndProcessAssistantResponseImpl = async (
|
||||
dispatch(newMessagesActions.updateMessage({ topicId, messageId: assistantMsgId, updates: messageErrorUpdate }))
|
||||
|
||||
saveUpdatesToDB(assistantMsgId, topicId, messageErrorUpdate, [])
|
||||
|
||||
EventEmitter.emit(EVENT_NAMES.MESSAGE_COMPLETE, {
|
||||
id: assistantMsgId,
|
||||
topicId,
|
||||
status: isAbortError(error) ? 'pause' : 'error',
|
||||
error: error.message
|
||||
})
|
||||
},
|
||||
onComplete: async (status: AssistantMessageStatus, response?: Response) => {
|
||||
const finalStateOnComplete = getState()
|
||||
@ -641,6 +649,8 @@ const fetchAndProcessAssistantResponseImpl = async (
|
||||
)
|
||||
|
||||
saveUpdatesToDB(assistantMsgId, topicId, messageUpdates, [])
|
||||
|
||||
EventEmitter.emit(EVENT_NAMES.MESSAGE_COMPLETE, { id: assistantMsgId, topicId, status })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user