57 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-05-05 21:27:40 +08:00
import * as vscode from 'vscode';
import CommandManager from '../command/commandManager';
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';
2023-10-01 17:03:56 +08:00
import { ApiKeyManager } from '../util/apiKey';
2023-05-05 21:27:40 +08:00
2023-05-10 17:56:56 +08:00
regInMessage({command: 'regCommandList'});
regOutMessage({command: 'regCommandList', result: [{name: '', pattern: '', description: ''}]});
2023-05-16 14:35:01 +08:00
export async function regCommandList(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
2023-05-05 21:27:40 +08:00
const commandList = CommandManager.getInstance().getCommandList();
const commandCovertedList = commandList.map(command => {
if (command.args > 0) {
// replace {{prompt}} with {{["",""]}}, count of "" is args
const prompt = Array.from({length: command.args}, () => "");
command.pattern = command.pattern.replace('{{prompt}}', '{{' + JSON.stringify(prompt) + '}}');
}
return command;
});
MessageHandler.sendMessage(panel, { command: 'regCommandList', result: commandCovertedList });
2023-05-05 21:27:40 +08:00
return;
}
let existPannel: vscode.WebviewPanel|vscode.WebviewView|undefined = undefined;
regInMessage({command: 'regCommandList'});
regOutMessage({command: 'regCommandList', result: [{name: '', pattern: '', description: ''}]});
export async function regCommandListByDevChatRun(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
existPannel = panel;
const commandList = await CommandManager.getInstance().getCommandListByDevChatRun();
const commandCovertedList = commandList.map(command => {
if (command.args > 0) {
// replace {{prompt}} with {{["",""]}}, count of "" is args
const prompt = Array.from({length: command.args}, () => "");
command.pattern = command.pattern.replace('{{prompt}}', '{{' + JSON.stringify(prompt) + '}}');
}
return command;
});
2023-05-08 12:09:52 +08:00
MessageHandler.sendMessage(panel, { command: 'regCommandList', result: commandCovertedList });
return;
}
2023-05-05 21:27:40 +08:00
export async function sendCommandListByDevChatRun() {
if (existPannel) {
regCommandListByDevChatRun({}, existPannel!);
}
}
export async function updateChatModels() {
2023-10-01 17:03:56 +08:00
const modelList = await ApiKeyManager.getValidModels();
MessageHandler.sendMessage(existPannel!, { command: 'regModelList', result: modelList });
}