Merge pull request #342 from devchat-ai/fix_command_output_parser
update Command output parser
This commit is contained in:
commit
a571c6cc4c
@ -124,6 +124,14 @@ export class WorkflowRunner {
|
|||||||
if (isStart) {
|
if (isStart) {
|
||||||
contentStr = outputWitchCache.substring(startPos+9, endPos);
|
contentStr = outputWitchCache.substring(startPos+9, endPos);
|
||||||
curPos = endPos+7;
|
curPos = endPos+7;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const contentObj = JSON.parse(contentStr);
|
||||||
|
if (contentObj && contentObj.result) {
|
||||||
|
contentStr = contentObj.result;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
contentStr = outputWitchCache.substring(startPos2, endPos+3);
|
contentStr = outputWitchCache.substring(startPos2, endPos+3);
|
||||||
curPos = endPos+3;
|
curPos = endPos+3;
|
||||||
@ -135,6 +143,17 @@ export class WorkflowRunner {
|
|||||||
return outputResult;
|
return outputResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _parseLastCommandOutput(outputStr: string): string {
|
||||||
|
const startPos = outputStr.lastIndexOf('<<Start>>');
|
||||||
|
const endPos = outputStr.lastIndexOf('<<End>>');
|
||||||
|
|
||||||
|
if (startPos === -1 || endPos === -1 || endPos < startPos) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputStr.substring(startPos+9, endPos);
|
||||||
|
}
|
||||||
|
|
||||||
private async _runCommand(commandWithArgs: string, commandEnvs: any): Promise<[CommandResult | undefined, string]> {
|
private async _runCommand(commandWithArgs: string, commandEnvs: any): Promise<[CommandResult | undefined, string]> {
|
||||||
const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath() || "";
|
const workspaceDir = UiUtilWrapper.workspaceFoldersFirstPath() || "";
|
||||||
let commandOutput = "";
|
let commandOutput = "";
|
||||||
@ -254,7 +273,16 @@ export class WorkflowRunner {
|
|||||||
const [commandResult, commandAnswer] = await this._runCommand(workflowCommand, workflowEnvs);
|
const [commandResult, commandAnswer] = await this._runCommand(workflowCommand, workflowEnvs);
|
||||||
|
|
||||||
if (commandResult && commandResult.exitCode === 0) {
|
if (commandResult && commandResult.exitCode === 0) {
|
||||||
const resultOut = commandAnswer === "" ? "success" : commandAnswer;
|
const lastOutput = this._parseLastCommandOutput(commandResult.stdout);
|
||||||
|
let resultOut = commandAnswer === "" ? "success" : commandAnswer;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const lastOutputObj = JSON.parse(lastOutput);
|
||||||
|
if (lastOutputObj && lastOutputObj.result) {
|
||||||
|
resultOut = lastOutputObj.result;
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
|
|
||||||
let logHash = await insertDevChatLog(message, message.text, resultOut);
|
let logHash = await insertDevChatLog(message, message.text, resultOut);
|
||||||
if (!logHash) {
|
if (!logHash) {
|
||||||
logHash = "";
|
logHash = "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user