Get workflows info via client

This commit is contained in:
kagami 2024-07-08 21:18:55 +08:00
parent 8becdb00aa
commit 6eb7f1f408
2 changed files with 68 additions and 16 deletions

View File

@ -1,24 +1,51 @@
import * as vscode from 'vscode';
import { MessageHandler } from './messageHandler';
import { regInMessage, regOutMessage } from '../util/reg_messages';
import { ApiKeyManager } from '../util/apiKey';
import DevChat from '../toolwrapper/devchat';
import * as vscode from "vscode";
import { MessageHandler } from "./messageHandler";
import { regInMessage, regOutMessage } from "../util/reg_messages";
import { DevChatClient } from "../toolwrapper/devchatClient";
import { logger } from "../util/logger";
let existPannel: vscode.WebviewPanel | vscode.WebviewView | undefined =
undefined;
let existPannel: vscode.WebviewPanel|vscode.WebviewView|undefined = undefined;
regInMessage({ command: "regCommandList" });
regOutMessage({
command: "regCommandList",
result: [{ name: "", pattern: "", description: "" }],
});
export async function getWorkflowCommandList(
message: any,
panel: vscode.WebviewPanel | vscode.WebviewView
): Promise<void> {
existPannel = panel;
const dcClient = new DevChatClient();
regInMessage({command: 'regCommandList'});
regOutMessage({command: 'regCommandList', result: [{name: '', pattern: '', description: ''}]});
export async function getWorkflowCommandList(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
existPannel = panel;
// All workflows registered in DevChat
const workflows = await dcClient.getWorkflowList();
logger.channel()?.debug(`\n\n----- workflows: ${JSON.stringify(workflows)}`);
const commandList = await new DevChat().commands();
MessageHandler.sendMessage(panel, { command: 'regCommandList', result: commandList });
return;
// Get recommends from config
const workflowsConfig = await dcClient.getWorkflowConfig();
const recommends = workflowsConfig.recommend?.workflows || [];
logger.channel()?.debug(`\n\n----- recommends: ${JSON.stringify(recommends)}`);
// Filter active workflows and add recommend info
const commandList = workflows
.filter((workflow) => workflow.active)
.map((workflow: any) => ({
...workflow,
recommend: recommends.indexOf(workflow.name),
}));
MessageHandler.sendMessage(panel, {
command: "regCommandList",
result: commandList,
});
return;
}
export async function sendCommandListByDevChatRun() {
if (existPannel) {
await getWorkflowCommandList({}, existPannel!);
}
if (existPannel) {
await getWorkflowCommandList({}, existPannel!);
}
}

View File

@ -141,6 +141,31 @@ export class DevChatClient {
}
}
@timeThis
async getWorkflowList(): Promise<any> {
const response = await this._get("/workflow/list");
logger
.channel()
?.debug(
`getWorkflowList response data: \n${JSON.stringify(
response.data
)}`
);
return response.data;
}
@timeThis
async getWorkflowConfig(): Promise<any> {
const response = await this._get("/workflow/config");
logger
.channel()
?.debug(
`getWorkflowConfig response data: \n${JSON.stringify(
response.data
)}`
);
return response.data;
}
@timeThis
async updateWorkflows(): Promise<void> {