Chat相关表现&逻辑分离,新增ChatController

新增情绪机器人逻辑,
新增情绪切换视频逻辑
This commit is contained in:
2025-08-26 19:41:13 +08:00
parent 58bac34580
commit 1507fff7c5
25 changed files with 2763 additions and 6933 deletions
@@ -5,6 +5,7 @@ import { RoleConfigLoader } from "./RoleConfigLoader";
import { ChatHistoryManager } from "../manager/ChatHistoryManager";
import { ApiConfig } from "./ApiConfigLoader";
import { ErrorHandler, ErrorType } from "../utils/ErrorHandler";
import { EmotionAIService } from "./EmotionAIService";
/**
* AI聊天服务类
@@ -123,6 +124,8 @@ export class ChatAIService {
this.currentRoleId = roleId;
// 预创建聊天实例
this.createOrGetChat(roleId);
// 预创建情绪聊天实例
EmotionAIService.Instance.ensureEmotionChatExists(roleId);
}
/**
@@ -186,6 +189,14 @@ export class ChatAIService {
role: "model",
parts: [{ text: response.text }],
});
// 更新情绪状态
try {
await EmotionAIService.Instance.updateEmotionFromChat(roleId, message, response.text);
} catch (emotionError) {
console.warn(`Failed to update emotion for role ${roleId}:`, emotionError);
// 情绪更新失败不影响聊天功能
}
} catch (storageError) {
ErrorHandler.Instance.handleError(
storageError as Error,
@@ -224,6 +235,8 @@ export class ChatAIService {
if (this.chatInstances.has(roleId)) {
this.chatInstances.delete(roleId);
}
// 清除情绪聊天历史
EmotionAIService.Instance.clearEmotionHistory(roleId);
// 清除本地存储的历史
ChatHistoryManager.Instance.clearHistory(roleId);
console.log(`Cleared chat history for role ${roleId}`);
@@ -234,6 +247,8 @@ export class ChatAIService {
*/
public clearAllChatHistory(): void {
this.chatInstances.clear();
// 清除所有情绪聊天历史
EmotionAIService.Instance.clearAllEmotionHistory();
// 清除本地存储的所有历史
ChatHistoryManager.Instance.clearAllHistory();
console.log("Cleared all chat histories");