Refactor action application and error handling
- Refactored applyAction to include parentHash in the message. - Simplified codeFileApply function by removing redundant error handling. - Enhanced error handling in MessageHandler to include parentHash. - Added condition to regenerate message only if autox is true.
This commit is contained in:
parent
7fe536f9d8
commit
4daca83d6b
@ -15,16 +15,17 @@ function compressText(text: string, maxLength: number): string {
|
||||
}
|
||||
|
||||
|
||||
regInMessage({command: 'applyAction', actionName: '', codeBlock: { type: '', content: '', fileName: ''}});
|
||||
regInMessage({command: 'applyAction', actionName: '', parentHash: '', codeBlock: { type: '', content: '', fileName: ''}});
|
||||
export async function applyAction(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
|
||||
try {
|
||||
const result = await ActionManager.getInstance().applyAction(message.actionName, message.codeBlock);
|
||||
if (message.codeBlock.type === 'command') {
|
||||
const result = await ActionManager.getInstance().applyAction("command_run", { "command": "", "fileName": message.fileName, "content": message.content });
|
||||
|
||||
// send error message to devchat
|
||||
const newMessage = `run command: ${compressText(message.codeBlock.content, 100)}, result: {"exit_code": ${result.exitCode}, stdout: ${compressText(result.stdout, 100)}, stderr: ${compressText(result.stderr, 100)}}. Next step`;
|
||||
MessageHandler.sendMessage(panel, { "command": "sendMessageSystem" });
|
||||
sendMessage({command: 'sendMessage', text: newMessage}, panel);
|
||||
}
|
||||
const commandObj = JSON.parse(message.content)
|
||||
const newMessage = `{"exit_code": ${result.exitCode}, stdout: ${result.stdout}, stderr: ${result.stderr}}`;
|
||||
MessageHandler.sendMessage(panel, { "command": "systemMessage", "text": "waitting command reponse..." });
|
||||
sendMessage({command: 'sendMessage', text: newMessage, parent_hash: message.parentHash}, panel, commandObj.name);
|
||||
|
||||
} catch (error) {
|
||||
logger.channel()?.error('Failed to parse code file content: ' + error);
|
||||
logger.channel()?.show();
|
||||
|
@ -73,22 +73,8 @@ export async function applyCodeFile(text: string, fileName: string): Promise<voi
|
||||
|
||||
regInMessage({command: 'code_file_apply', content: '', fileName: ''});
|
||||
export async function codeFileApply(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
|
||||
// await applyCodeFile(message.content, message.fileName);
|
||||
// return;
|
||||
|
||||
try {
|
||||
const result = await ActionManager.getInstance().applyAction("command_run", { "command": "", "fileName": message.fileName, "content": message.content });
|
||||
|
||||
// send error message to devchat
|
||||
const commandObj = JSON.parse(message.content)
|
||||
const newMessage = `{"exit_code": ${result.exitCode}, stdout: ${result.stdout}, stderr: ${compressText(result.stderr, 100)}}`;
|
||||
MessageHandler.sendMessage(panel, { "command": "sendMessageSystem" });
|
||||
sendMessage({command: 'sendMessage', text: newMessage}, panel, commandObj.name);
|
||||
|
||||
} catch (error) {
|
||||
logger.channel()?.error('Failed to parse code file content: ' + error);
|
||||
logger.channel()?.show();
|
||||
}
|
||||
await applyCodeFile(message.content, message.fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@ import { onApiKey } from './historyMessages';
|
||||
import { ApiKeyManager } from '../util/apiKey';
|
||||
import { regeneration, sendMessage as sendMessageX } from './sendMessage';
|
||||
import { codeFileApply } from './codeFileApply';
|
||||
import { applyAction } from './applyAction';
|
||||
|
||||
let autox = false;
|
||||
|
||||
@ -75,10 +76,12 @@ export class MessageHandler {
|
||||
|
||||
panel.webview.postMessage(message);
|
||||
|
||||
if (message.command === 'receiveMessage' && autox) {
|
||||
if (message.command === 'receiveMessage') {
|
||||
// if message.isError is true, then regenerate message
|
||||
if (message.isError) {
|
||||
regeneration({}, panel);
|
||||
if (autox) {
|
||||
regeneration({}, panel);
|
||||
}
|
||||
} else {
|
||||
// if message.text is ```command\n {xxx} ``` then get xxx
|
||||
const messageText = message.text;
|
||||
@ -101,18 +104,22 @@ export class MessageHandler {
|
||||
return ;
|
||||
}
|
||||
|
||||
codeFileApply({"content": command, "fileName": ""}, panel);
|
||||
applyAction({"content": command, "fileName": "", parentHash: message.hash}, panel);
|
||||
|
||||
} catch (e) {
|
||||
logger.channel()?.error(`parse ${command} error: ${e}`);
|
||||
logger.channel()?.show();
|
||||
|
||||
if (autox) {
|
||||
MessageHandler.sendMessage(panel, { "command": "systemMessage", "text": "continue. 并且确认你在围绕最初的任务在执行相关步骤。" });
|
||||
sendMessageX({command: 'sendMessage', text: "continue"}, panel);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (autox) {
|
||||
MessageHandler.sendMessage(panel, { "command": "systemMessage", "text": "continue. 并且确认你在围绕最初的任务在执行相关步骤。" });
|
||||
sendMessageX({command: 'sendMessage', text: "continue"}, panel);
|
||||
}
|
||||
} else {
|
||||
MessageHandler.sendMessage(panel, { "command": "systemMessage", "text": "continue. 并且确认你在围绕最初的任务在执行相关步骤。" });
|
||||
sendMessageX({command: 'sendMessage', text: "continue"}, panel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user