New context methods, added type parameters to message events

ddb77732f261e79ae4b27a1faf7c479c0e32c4b2

bmen25124 <bmen25124@gmail.com>

5 files changed, +29 -24Ignore whitespace
public/script.js+16 -16
@@ -3373,8 +3373,8 @@ class StreamingProcessor {
33733373 }
33743374
33753375 if (this.type !== 'impersonate') {
33763376 await eventSource.emit(event_types.MESSAGE_RECEIVED, this.messageId, this.type);
33773377 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, this.messageId, this.type);
33783378 } else {
33793379 await eventSource.emit(event_types.IMPERSONATE_READY, text);
33803380 }
@@ -3403,8 +3403,8 @@ class StreamingProcessor {
34033403
34043404 const noEmitTypes = ['swipe', 'impersonate', 'continue'];
34053405 if (!noEmitTypes.includes(this.type)) {
34063406 eventSource.emit(event_types.MESSAGE_RECEIVED, this.messageId, this.type);
34073407 eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, this.messageId, this.type);
34083408 }
34093409 }
34103410
@@ -6015,9 +6015,9 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes,
60156015 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);
60166016 }
60176017 const chat_id = (chat.length - 1);
60186018 await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);
60196019 addOneMessage(chat[chat_id], { type: 'swipe' });
60206020 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);
60216021 } else {
60226022 chat[chat.length - 1]['mes'] = getMessage;
60236023 }
@@ -6038,9 +6038,9 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes,
60386038 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);
60396039 }
60406040 const chat_id = (chat.length - 1);
60416041 await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);
60426042 addOneMessage(chat[chat_id], { type: 'swipe' });
60436043 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);
60446044 } else if (type === 'appendFinal') {
60456045 oldMessage = chat[chat.length - 1]['mes'];
60466046 console.debug('Trying to appendFinal.');
@@ -6058,9 +6058,9 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes,
60586058 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);
60596059 }
60606060 const chat_id = (chat.length - 1);
60616061 await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);
60626062 addOneMessage(chat[chat_id], { type: 'swipe' });
60636063 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);
60646064
60656065 } else {
60666066 console.debug('entering chat update routine for non-swipe post');
@@ -6100,9 +6100,9 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes,
61006100 saveImageToMessage(img, chat[chat.length - 1]);
61016101 const chat_id = (chat.length - 1);
61026102
61036103 !fromStreaming && await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);
61046104 addOneMessage(chat[chat_id]);
61056105 !fromStreaming && await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);
61066106 }
61076107
61086108 const item = chat[chat.length - 1];
@@ -6850,8 +6850,8 @@ async function getChatResult() {
68506850
68516851 if (chat.length === 1) {
68526852 const chat_id = (chat.length - 1);
68536853 await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, 'first_message');
68546854 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, 'first_message');
68556855 }
68566856}
68576857
@@ -8729,10 +8729,10 @@ async function createOrEditCharacter(e) {
87298729 if (shouldRegenerateMessage) {
87308730 chat.splice(0, chat.length, message);
87318731 const messageId = (chat.length - 1);
87328732 await eventSource.emit(event_types.MESSAGE_RECEIVED, messageId, 'first_message');
87338733 await clearChat();
87348734 await printMessages();
87358735 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, messageId, 'first_message');
87368736 await saveChatConditional();
87378737 }
87388738 } catch (error) {
public/scripts/extensions/stable-diffusion/index.js+2 -2
@@ -3739,9 +3739,9 @@ async function sendMessage(prompt, image, generationType, additionalNegativePref
37393739 };
37403740 context.chat.push(message);
37413741 const messageId = context.chat.length - 1;
37423742 await eventSource.emit(event_types.MESSAGE_RECEIVED, messageId, 'stable-diffusion');
37433743 context.addOneMessage(message);
37443744 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, messageId, 'stable-diffusion');
37453745 await context.saveChat();
37463746}
37473747
public/scripts/group-chats.js+2 -2
@@ -246,9 +246,9 @@ export async function getGroupChat(groupId, reload = false) {
246246 }
247247
248248 chat.push(mes);
249249 await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1), 'group_first_message');
250250 addOneMessage(mes);
251251 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1), 'group_first_message');
252252 }
253253 }
254254 await saveGroupChat(groupId, false);
public/scripts/slash-commands.js+4 -4
@@ -3628,14 +3628,14 @@ export async function sendMessageAs(args, text) {
36283628 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
36293629 chat.splice(insertAt, 0, message);
36303630 await saveChatConditional();
36313631 await eventSource.emit(event_types.MESSAGE_RECEIVED, insertAt, 'command');
36323632 await reloadCurrentChat();
36333633 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, insertAt, 'command');
36343634 } else {
36353635 chat.push(message);
36363636 await eventSource.emit(event_types.MESSAGE_RECEIVED, (chat.length - 1), 'command');
36373637 addOneMessage(message);
36383638 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, (chat.length - 1), 'command');
36393639 await saveChatConditional();
36403640 }
36413641
public/scripts/st-context.js+5 -0
@@ -48,6 +48,7 @@ import {
4848 printMessages,
4949 clearChat,
5050 unshallowCharacter,
51+ deleteLastMessage,
5152} from '../script.js';
5253import {
5354 extension_settings,
@@ -106,6 +107,7 @@ export function getContext() {
106107 eventSource,
107108 eventTypes: event_types,
108109 addOneMessage,
110+ deleteLastMessage,
109111 generate: Generate,
110112 sendStreamingRequest,
111113 sendGenerationRequest,
@@ -147,6 +149,9 @@ export function getContext() {
147149 unregisterFunctionTool: ToolManager.unregisterFunctionTool.bind(ToolManager),
148150 isToolCallingSupported: ToolManager.isToolCallingSupported.bind(ToolManager),
149151 canPerformToolCalls: ToolManager.canPerformToolCalls.bind(ToolManager),
152+ registerFunctionToolsOpenAI: ToolManager.registerFunctionToolsOpenAI.bind(ToolManager),
153+ invokeFunctionTools: ToolManager.invokeFunctionTools.bind(ToolManager),
154+ saveFunctionToolInvocations: ToolManager.saveFunctionToolInvocations.bind(ToolManager),
150155 registerDebugFunction,
151156 /** @deprecated Use renderExtensionTemplateAsync instead. */
152157 renderExtensionTemplate,