New context methods, added type parameters to message events

This commit is contained in:
bmen25124
2025-03-12 21:21:23 +03:00
parent 1b02426df1
commit ddb77732f2
5 changed files with 29 additions and 24 deletions

View File

@@ -3739,9 +3739,9 @@ async function sendMessage(prompt, image, generationType, additionalNegativePref
};
context.chat.push(message);
const messageId = context.chat.length - 1;
await eventSource.emit(event_types.MESSAGE_RECEIVED, messageId);
await eventSource.emit(event_types.MESSAGE_RECEIVED, messageId, 'stable-diffusion');
context.addOneMessage(message);
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, messageId);
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, messageId, 'stable-diffusion');
await context.saveChat();
}

View File

@@ -246,9 +246,9 @@ export async function getGroupChat(groupId, reload = false) {
}
chat.push(mes);
await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1));
await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1), 'group_first_message');
addOneMessage(mes);
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1));
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1), 'group_first_message');
}
}
await saveGroupChat(groupId, false);

View File

@@ -3628,14 +3628,14 @@ export async function sendMessageAs(args, text) {
if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
chat.splice(insertAt, 0, message);
await saveChatConditional();
await eventSource.emit(event_types.MESSAGE_RECEIVED, insertAt);
await eventSource.emit(event_types.MESSAGE_RECEIVED, insertAt, 'command');
await reloadCurrentChat();
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, insertAt);
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, insertAt, 'command');
} else {
chat.push(message);
await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1));
await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1), 'command');
addOneMessage(message);
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1));
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1), 'command');
await saveChatConditional();
}

View File

@@ -48,6 +48,7 @@ import {
printMessages,
clearChat,
unshallowCharacter,
deleteLastMessage,
} from '../script.js';
import {
extension_settings,
@@ -106,6 +107,7 @@ export function getContext() {
eventSource,
eventTypes: event_types,
addOneMessage,
deleteLastMessage,
generate: Generate,
sendStreamingRequest,
sendGenerationRequest,
@@ -147,6 +149,9 @@ export function getContext() {
unregisterFunctionTool: ToolManager.unregisterFunctionTool.bind(ToolManager),
isToolCallingSupported: ToolManager.isToolCallingSupported.bind(ToolManager),
canPerformToolCalls: ToolManager.canPerformToolCalls.bind(ToolManager),
registerFunctionToolsOpenAI: ToolManager.registerFunctionToolsOpenAI.bind(ToolManager),
invokeFunctionTools: ToolManager.invokeFunctionTools.bind(ToolManager),
saveFunctionToolInvocations: ToolManager.saveFunctionToolInvocations.bind(ToolManager),
registerDebugFunction,
/** @deprecated Use renderExtensionTemplateAsync instead. */
renderExtensionTemplate,