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();
|
2023-06-02 13:45:12 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-08-30 16:39:47 +08:00
|
|
|
let existPannel: vscode.WebviewPanel|vscode.WebviewView|undefined = undefined;
|
|
|
|
|
2023-08-30 16:39:47 +08:00
|
|
|
regInMessage({command: 'regCommandList'});
|
|
|
|
regOutMessage({command: 'regCommandList', result: [{name: '', pattern: '', description: ''}]});
|
|
|
|
export async function regCommandListByDevChatRun(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
|
2023-08-30 16:39:47 +08:00
|
|
|
existPannel = panel;
|
|
|
|
|
2023-08-30 16:39:47 +08:00
|
|
|
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
|
|
|
|
2023-08-30 16:39:47 +08:00
|
|
|
MessageHandler.sendMessage(panel, { command: 'regCommandList', result: commandCovertedList });
|
|
|
|
return;
|
|
|
|
}
|
2023-05-05 21:27:40 +08:00
|
|
|
|
2023-08-30 16:39:47 +08:00
|
|
|
export async function sendCommandListByDevChatRun() {
|
|
|
|
if (existPannel) {
|
|
|
|
regCommandListByDevChatRun({}, existPannel!);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-13 10:08:16 +08:00
|
|
|
export async function updateChatModels() {
|
2023-10-01 17:03:56 +08:00
|
|
|
const modelList = await ApiKeyManager.getValidModels();
|
2023-09-13 10:08:16 +08:00
|
|
|
MessageHandler.sendMessage(existPannel!, { command: 'regModelList', result: modelList });
|
|
|
|
}
|
|
|
|
|