feat:搭建本地存储会话历史的框架

- 将会话历史存储在C:\Users\admin\.iccoder文件下
- 在里面又会创建多个文件夹进行存储
This commit is contained in:
Roe-xin
2025-12-15 15:19:36 +08:00
parent ab6d257df2
commit a1a526bb98
6 changed files with 1004 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import {
checkVerilogProject,
checkIverilogAvailable,
} from "./iverilogRunner";
import { ChatHistoryManager } from "./chatHistoryManager";
/**
* 处理用户消息
@ -24,6 +25,10 @@ export async function handleUserMessage(
) {
console.log("收到用户消息:", text);
// 记录用户消息到历史
const historyManager = ChatHistoryManager.getInstance();
await historyManager.addUserMessage(text);
// 检查是否是 VCD 生成命令
if (isVCDGenerationCommand(text)) {
await handleVCDGeneration(panel, extensionPath || "");
@ -44,6 +49,10 @@ export async function handleUserMessage(
// 普通消息处理
console.log("作为普通消息处理");
const reply = getMockReply(text);
// 记录助手回复到历史
await historyManager.addAiMessage(reply);
setTimeout(() => {
panel.webview.postMessage({
command: "receiveMessage",
@ -166,28 +175,36 @@ async function handleFileOperation(
replaceText?: string;
}
) {
const historyManager = ChatHistoryManager.getInstance();
try {
let responseText = "";
switch (operation.type) {
case "create":
await createFile(operation.filePath, operation.content || "");
responseText = `✅ 文件创建成功: ${operation.filePath}`;
panel.webview.postMessage({
command: "receiveMessage",
text: `✅ 文件创建成功: ${operation.filePath}`,
text: responseText,
});
vscode.window.showInformationMessage(
`文件创建成功: ${operation.filePath}`
);
await historyManager.addAiMessage(responseText);
break;
case "delete":
await deleteFile(operation.filePath);
responseText = `✅ 文件删除成功: ${operation.filePath}`;
panel.webview.postMessage({
command: "receiveMessage",
text: `✅ 文件删除成功: ${operation.filePath}`,
text: responseText,
});
vscode.window.showInformationMessage(
`文件删除成功: ${operation.filePath}`
);
await historyManager.addAiMessage(responseText);
break;
case "read":
@ -197,6 +214,7 @@ async function handleFileOperation(
content: content,
filePath: operation.filePath,
});
await historyManager.addAiMessage(`读取文件: ${operation.filePath}`);
break;
case "update":
@ -206,6 +224,7 @@ async function handleFileOperation(
content: currentContent,
filePath: operation.filePath,
});
await historyManager.addAiMessage(`编辑文件: ${operation.filePath}`);
break;
case "rename":
@ -213,13 +232,15 @@ async function handleFileOperation(
throw new Error("缺少新文件名");
}
await renameFile(operation.filePath, operation.newPath);
responseText = `✅ 文件重命名成功: ${operation.filePath}${operation.newPath}`;
panel.webview.postMessage({
command: "receiveMessage",
text: `✅ 文件重命名成功: ${operation.filePath}${operation.newPath}`,
text: responseText,
});
vscode.window.showInformationMessage(
`文件重命名成功: ${operation.filePath}${operation.newPath}`
);
await historyManager.addAiMessage(responseText);
break;
case "replace":
@ -231,13 +252,15 @@ async function handleFileOperation(
operation.searchText,
operation.replaceText
);
responseText = `✅ 文件内容替换成功: ${operation.filePath}`;
panel.webview.postMessage({
command: "receiveMessage",
text: `✅ 文件内容替换成功: ${operation.filePath}`,
text: responseText,
});
vscode.window.showInformationMessage(
`文件内容替换成功: ${operation.filePath}`
);
await historyManager.addAiMessage(responseText);
break;
}
} catch (error) {
@ -247,6 +270,7 @@ async function handleFileOperation(
text: `${errorMsg}`,
});
vscode.window.showErrorMessage(errorMsg);
await historyManager.addAiMessage(`${errorMsg}`);
}
}