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