Merge pull request #3671 from bmen25124/events_type_param New context methods, added type parameter to message events
Signed| @@ -3373,8 +3373,8 @@ class StreamingProcessor { | |||
| 3373 | } | 3373 | } |
| 3374 | 3374 | ||
| 3375 | if (this.type !== 'impersonate') { | 3375 | if (this.type !== 'impersonate') { |
| 3376 | await eventSource.emit(event_types.MESSAGE_RECEIVED, this.messageId); | 3376 | await eventSource.emit(event_types.MESSAGE_RECEIVED, this.messageId, this.type); |
| 3377 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, this.messageId); | 3377 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, this.messageId, this.type); |
| 3378 | } else { | 3378 | } else { |
| 3379 | await eventSource.emit(event_types.IMPERSONATE_READY, text); | 3379 | await eventSource.emit(event_types.IMPERSONATE_READY, text); |
| 3380 | } | 3380 | } |
| @@ -3403,8 +3403,8 @@ class StreamingProcessor { | |||
| 3403 | 3403 | ||
| 3404 | const noEmitTypes = ['swipe', 'impersonate', 'continue']; | 3404 | const noEmitTypes = ['swipe', 'impersonate', 'continue']; |
| 3405 | if (!noEmitTypes.includes(this.type)) { | 3405 | if (!noEmitTypes.includes(this.type)) { |
| 3406 | eventSource.emit(event_types.MESSAGE_RECEIVED, this.messageId); | 3406 | eventSource.emit(event_types.MESSAGE_RECEIVED, this.messageId, this.type); |
| 3407 | eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, this.messageId); | 3407 | eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, this.messageId, this.type); |
| 3408 | } | 3408 | } |
| 3409 | } | 3409 | } |
| 3410 | 3410 | ||
| @@ -6015,9 +6015,9 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | |||
| 6015 | chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); | 6015 | chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); |
| 6016 | } | 6016 | } |
| 6017 | const chat_id = (chat.length - 1); | 6017 | const chat_id = (chat.length - 1); |
| 6018 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id); | 6018 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type); |
| 6019 | addOneMessage(chat[chat_id], { type: 'swipe' }); | 6019 | addOneMessage(chat[chat_id], { type: 'swipe' }); |
| 6020 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id); | 6020 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type); |
| 6021 | } else { | 6021 | } else { |
| 6022 | chat[chat.length - 1]['mes'] = getMessage; | 6022 | chat[chat.length - 1]['mes'] = getMessage; |
| 6023 | } | 6023 | } |
| @@ -6038,9 +6038,9 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | |||
| 6038 | chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); | 6038 | chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); |
| 6039 | } | 6039 | } |
| 6040 | const chat_id = (chat.length - 1); | 6040 | const chat_id = (chat.length - 1); |
| 6041 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id); | 6041 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type); |
| 6042 | addOneMessage(chat[chat_id], { type: 'swipe' }); | 6042 | addOneMessage(chat[chat_id], { type: 'swipe' }); |
| 6043 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id); | 6043 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type); |
| 6044 | } else if (type === 'appendFinal') { | 6044 | } else if (type === 'appendFinal') { |
| 6045 | oldMessage = chat[chat.length - 1]['mes']; | 6045 | oldMessage = chat[chat.length - 1]['mes']; |
| 6046 | console.debug('Trying to appendFinal.'); | 6046 | console.debug('Trying to appendFinal.'); |
| @@ -6058,9 +6058,9 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | |||
| 6058 | chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); | 6058 | chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); |
| 6059 | } | 6059 | } |
| 6060 | const chat_id = (chat.length - 1); | 6060 | const chat_id = (chat.length - 1); |
| 6061 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id); | 6061 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type); |
| 6062 | addOneMessage(chat[chat_id], { type: 'swipe' }); | 6062 | addOneMessage(chat[chat_id], { type: 'swipe' }); |
| 6063 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id); | 6063 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type); |
| 6064 | 6064 | ||
| 6065 | } else { | 6065 | } else { |
| 6066 | console.debug('entering chat update routine for non-swipe post'); | 6066 | console.debug('entering chat update routine for non-swipe post'); |
| @@ -6100,9 +6100,9 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | |||
| 6100 | saveImageToMessage(img, chat[chat.length - 1]); | 6100 | saveImageToMessage(img, chat[chat.length - 1]); |
| 6101 | const chat_id = (chat.length - 1); | 6101 | const chat_id = (chat.length - 1); |
| 6102 | 6102 | ||
| 6103 | !fromStreaming && await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id); | 6103 | !fromStreaming && await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type); |
| 6104 | addOneMessage(chat[chat_id]); | 6104 | addOneMessage(chat[chat_id]); |
| 6105 | !fromStreaming && await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id); | 6105 | !fromStreaming && await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type); |
| 6106 | } | 6106 | } |
| 6107 | 6107 | ||
| 6108 | const item = chat[chat.length - 1]; | 6108 | const item = chat[chat.length - 1]; |
| @@ -6850,8 +6850,8 @@ async function getChatResult() { | |||
| 6850 | 6850 | ||
| 6851 | if (chat.length === 1) { | 6851 | if (chat.length === 1) { |
| 6852 | const chat_id = (chat.length - 1); | 6852 | const chat_id = (chat.length - 1); |
| 6853 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id); | 6853 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, 'first_message'); |
| 6854 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id); | 6854 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, 'first_message'); |
| 6855 | } | 6855 | } |
| 6856 | } | 6856 | } |
| 6857 | 6857 | ||
| @@ -8729,10 +8729,10 @@ async function createOrEditCharacter(e) { | |||
| 8729 | if (shouldRegenerateMessage) { | 8729 | if (shouldRegenerateMessage) { |
| 8730 | chat.splice(0, chat.length, message); | 8730 | chat.splice(0, chat.length, message); |
| 8731 | const messageId = (chat.length - 1); | 8731 | const messageId = (chat.length - 1); |
| 8732 | await eventSource.emit(event_types.MESSAGE_RECEIVED, messageId); | 8732 | await eventSource.emit(event_types.MESSAGE_RECEIVED, messageId, 'first_message'); |
| 8733 | await clearChat(); | 8733 | await clearChat(); |
| 8734 | await printMessages(); | 8734 | await printMessages(); |
| 8735 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, messageId); | 8735 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, messageId, 'first_message'); |
| 8736 | await saveChatConditional(); | 8736 | await saveChatConditional(); |
| 8737 | } | 8737 | } |
| 8738 | } catch (error) { | 8738 | } catch (error) { |
| @@ -3739,9 +3739,9 @@ async function sendMessage(prompt, image, generationType, additionalNegativePref | |||
| 3739 | }; | 3739 | }; |
| 3740 | context.chat.push(message); | 3740 | context.chat.push(message); |
| 3741 | const messageId = context.chat.length - 1; | 3741 | const messageId = context.chat.length - 1; |
| 3742 | await eventSource.emit(event_types.MESSAGE_RECEIVED, messageId); | 3742 | await eventSource.emit(event_types.MESSAGE_RECEIVED, messageId, 'extension'); |
| 3743 | context.addOneMessage(message); | 3743 | context.addOneMessage(message); |
| 3744 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, messageId); | 3744 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, messageId, 'extension'); |
| 3745 | await context.saveChat(); | 3745 | await context.saveChat(); |
| 3746 | } | 3746 | } |
| 3747 | 3747 | ||
| @@ -246,9 +246,9 @@ export async function getGroupChat(groupId, reload = false) { | |||
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | chat.push(mes); | 248 | chat.push(mes); |
| 249 | await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1)); | 249 | await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1), 'first_message'); |
| 250 | addOneMessage(mes); | 250 | addOneMessage(mes); |
| 251 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1)); | 251 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1), 'first_message'); |
| 252 | } | 252 | } |
| 253 | } | 253 | } |
| 254 | await saveGroupChat(groupId, false); | 254 | await saveGroupChat(groupId, false); |
| @@ -3628,14 +3628,14 @@ export async function sendMessageAs(args, text) { | |||
| 3628 | if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) { | 3628 | if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) { |
| 3629 | chat.splice(insertAt, 0, message); | 3629 | chat.splice(insertAt, 0, message); |
| 3630 | await saveChatConditional(); | 3630 | await saveChatConditional(); |
| 3631 | await eventSource.emit(event_types.MESSAGE_RECEIVED, insertAt); | 3631 | await eventSource.emit(event_types.MESSAGE_RECEIVED, insertAt, 'command'); |
| 3632 | await reloadCurrentChat(); | 3632 | await reloadCurrentChat(); |
| 3633 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, insertAt); | 3633 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, insertAt, 'command'); |
| 3634 | } else { | 3634 | } else { |
| 3635 | chat.push(message); | 3635 | chat.push(message); |
| 3636 | await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1)); | 3636 | await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1), 'command'); |
| 3637 | addOneMessage(message); | 3637 | addOneMessage(message); |
| 3638 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1)); | 3638 | await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1), 'command'); |
| 3639 | await saveChatConditional(); | 3639 | await saveChatConditional(); |
| 3640 | } | 3640 | } |
| 3641 | 3641 | ||
| @@ -48,6 +48,7 @@ import { | |||
| 48 | printMessages, | 48 | printMessages, |
| 49 | clearChat, | 49 | clearChat, |
| 50 | unshallowCharacter, | 50 | unshallowCharacter, |
| 51 | deleteLastMessage, | ||
| 51 | } from '../script.js'; | 52 | } from '../script.js'; |
| 52 | import { | 53 | import { |
| 53 | extension_settings, | 54 | extension_settings, |
| @@ -106,6 +107,7 @@ export function getContext() { | |||
| 106 | eventSource, | 107 | eventSource, |
| 107 | eventTypes: event_types, | 108 | eventTypes: event_types, |
| 108 | addOneMessage, | 109 | addOneMessage, |
| 110 | deleteLastMessage, | ||
| 109 | generate: Generate, | 111 | generate: Generate, |
| 110 | sendStreamingRequest, | 112 | sendStreamingRequest, |
| 111 | sendGenerationRequest, | 113 | sendGenerationRequest, |
| @@ -147,6 +149,7 @@ export function getContext() { | |||
| 147 | unregisterFunctionTool: ToolManager.unregisterFunctionTool.bind(ToolManager), | 149 | unregisterFunctionTool: ToolManager.unregisterFunctionTool.bind(ToolManager), |
| 148 | isToolCallingSupported: ToolManager.isToolCallingSupported.bind(ToolManager), | 150 | isToolCallingSupported: ToolManager.isToolCallingSupported.bind(ToolManager), |
| 149 | canPerformToolCalls: ToolManager.canPerformToolCalls.bind(ToolManager), | 151 | canPerformToolCalls: ToolManager.canPerformToolCalls.bind(ToolManager), |
| 152 | ToolManager, | ||
| 150 | registerDebugFunction, | 153 | registerDebugFunction, |
| 151 | /** @deprecated Use renderExtensionTemplateAsync instead. */ | 154 | /** @deprecated Use renderExtensionTemplateAsync instead. */ |
| 152 | renderExtensionTemplate, | 155 | renderExtensionTemplate, |