Delete log via client

This commit is contained in:
kagami 2024-07-08 18:57:15 +08:00
parent 2be88bd9ad
commit 84ef68c500
2 changed files with 48 additions and 8 deletions

View File

@ -1,4 +1,3 @@
// import DevChat, { ChatOptions, ChatResponse } from '../toolwrapper/devchat';
import { logger } from '../util/logger';
import { assertValue } from '../util/check';
import { DevChatClient, ChatRequest, ChatResponse, buildRoleContextsFromFiles, LogData } from '../toolwrapper/devchatClient';
@ -280,9 +279,10 @@ export async function deleteChatMessageBase(message:{'hash': string}): Promise<b
try {
assertValue(!message.hash, 'Message hash is required');
// delete the message by devchat
const bSuccess = await devChat.delete(message.hash);
assertValue(!bSuccess, "Failed to delete message from devchat");
// delete the message by devchatClient
const res = await dcClient.deleteLog(message.hash);
assertValue(!res.success, res.error || "Failed to delete message from devchat client");
return true;
} catch (error: any) {
logger.channel()?.error(`Error: ${error.message}`);

View File

@ -71,6 +71,23 @@ export interface LogInsertRes {
error?: string;
}
export interface LogDeleteRes {
success?: boolean;
error?: string;
}
export interface ShortLog {
hash: string;
parent: string | null;
user: string;
date: string;
request: string;
responses: string[];
context: Array<{
content: string;
role: string;
}>;
}
export async function buildRoleContextsFromFiles(
files: string[] | undefined
@ -249,6 +266,29 @@ export class DevChatClient {
};
return res;
}
@timeThis
async deleteLog(logHash: string): Promise<LogDeleteRes> {
const data = {
workspace: UiUtilWrapper.workspaceFoldersFirstPath(),
hash: logHash,
};
const response = await this._post("/logs/delete", data);
logger
.channel()
?.debug(
`deleteLog response data: ${JSON.stringify(
response.data
)}, ${typeof response.data}}`
);
const res: LogDeleteRes = {
success: response.data["success"],
error: response.data["error"],
};
return res;
}
stopAllRequest(): void {
this.cancelMessage();
// add other requests here if needed