From feb34588ab549fdc037926de14d66fbb738f902a Mon Sep 17 00:00:00 2001 From: kagami Date: Tue, 9 Jul 2024 10:42:43 +0800 Subject: [PATCH] Use the inner get/post method --- src/handler/workflowCommandHandler.ts | 2 -- src/toolwrapper/devchatClient.ts | 17 +++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/handler/workflowCommandHandler.ts b/src/handler/workflowCommandHandler.ts index c786e9e..6147477 100644 --- a/src/handler/workflowCommandHandler.ts +++ b/src/handler/workflowCommandHandler.ts @@ -21,12 +21,10 @@ export async function getWorkflowCommandList( // All workflows registered in DevChat const workflows = await dcClient.getWorkflowList(); - logger.channel()?.debug(`\n\n----- workflows: ${JSON.stringify(workflows)}`); // 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 diff --git a/src/toolwrapper/devchatClient.ts b/src/toolwrapper/devchatClient.ts index c32c9ef..ffa7c80 100644 --- a/src/toolwrapper/devchatClient.ts +++ b/src/toolwrapper/devchatClient.ts @@ -117,7 +117,7 @@ export class DevChatClient { private _cancelMessageToken: CancelTokenSource | null = null; - static readonly logRawDataSizeLimit = 10; //4 * 1024; + static readonly logRawDataSizeLimit = 4 * 1024; // TODO: init devchat client with a port number // TODO: the default 22222 is for dev only, should not be used in production @@ -125,10 +125,10 @@ export class DevChatClient { this.baseURL = `http://localhost:${port}`; } - async _get(path: string): Promise { + async _get(path: string, config?: any): Promise { try { logger.channel()?.debug(`GET request to ${this.baseURL}${path}`); - const response = await axios.get(`${this.baseURL}${path}`); + const response = await axios.get(`${this.baseURL}${path}`, config); return response; } catch (error) { console.error(error); @@ -137,6 +137,7 @@ export class DevChatClient { } async _post(path: string, data: any = undefined): Promise { try { + logger.channel()?.debug(`POST request to ${this.baseURL}${path}`); const response = await axios.post(`${this.baseURL}${path}`, data); return response; } catch (error) { @@ -246,11 +247,11 @@ export class DevChatClient { response.data.on("error", (error) => { logger.channel()?.error("Streaming error:", error); - // TODO: handle error + // TODO: handle error? reject(error); // Reject the promise on error }); } catch (error) { - // TODO: handle error + // TODO: handle error? reject(error); // Reject the promise if the request fails } }); @@ -351,8 +352,8 @@ export class DevChatClient { offset: offset, workspace: UiUtilWrapper.workspaceFoldersFirstPath(), }; - const response = await axios.get( - `${this.baseURL}/topics/${topicRootHash}/logs`, + const response = await this._get( + `/topics/${topicRootHash}/logs`, { params: data, } @@ -375,7 +376,7 @@ export class DevChatClient { offset: offset, workspace: UiUtilWrapper.workspaceFoldersFirstPath(), }; - const response = await axios.get(`${this.baseURL}/topics`, { + const response = await this._get(`/topics`, { params: data, });