44 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-05-05 21:27:40 +08:00
import * as vscode from 'vscode';
2023-05-09 10:34:33 +08:00
import { MessageHandler } from './messageHandler';
2023-05-10 17:56:56 +08:00
import { regInMessage, regOutMessage } from '../util/reg_messages';
import { stopDevChatBase, sendMessageBase } from './sendMessageBase';
2023-05-10 17:56:56 +08:00
2023-05-05 21:27:40 +08:00
let _lastMessage: any = undefined;
2023-05-10 17:56:56 +08:00
regInMessage({command: 'sendMessage', text: '', hash: undefined});
regOutMessage({ command: 'receiveMessage', text: 'xxxx', hash: 'xxx', user: 'xxx', date: 'xxx'});
regOutMessage({ command: 'receiveMessagePartial', text: 'xxxx', user: 'xxx', date: 'xxx'});
// message: { command: 'sendMessage', text: 'xxx', hash: 'xxx'}
// return message:
// { command: 'receiveMessage', text: 'xxxx', hash: 'xxx', user: 'xxx', date: 'xxx'}
// { command: 'receiveMessagePartial', text: 'xxxx', user: 'xxx', date: 'xxx'}
2023-05-16 14:35:01 +08:00
export async function sendMessage(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
2023-05-23 11:16:48 +08:00
_lastMessage = message;
const responseMessage = await sendMessageBase(message, (data: { command: string, text: string, user: string, date: string}) => {
MessageHandler.sendMessage(panel, data);
});
if (responseMessage) {
MessageHandler.sendMessage(panel, responseMessage);
}
2023-05-05 21:27:40 +08:00
}
2023-05-23 11:16:48 +08:00
// regeneration last message again
regInMessage({command: 'regeneration'});
export async function regeneration(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
// call sendMessage to send last message again
if (_lastMessage) {
sendMessage(_lastMessage, panel);
}
}
2023-05-10 17:56:56 +08:00
regInMessage({command: 'stopDevChat'});
2023-05-16 14:35:01 +08:00
export async function stopDevChat(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
stopDevChatBase(message);
}
2023-05-08 12:09:52 +08:00
2023-05-05 21:27:40 +08:00