fix
This commit is contained in:
@@ -43,6 +43,7 @@ export class ChatAIService {
|
||||
private ai: GoogleGenAI;
|
||||
private chatInstances: Map<number, any> = new Map();
|
||||
private currentRoleId: number | null = null;
|
||||
private shouldShowErrorTips: boolean = true; // 控制是否显示错误提示
|
||||
|
||||
private constructor() {
|
||||
const config = ApiConfig.Instance.getAIConfig();
|
||||
@@ -98,6 +99,14 @@ export class ChatAIService {
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否显示错误提示
|
||||
* @param show 是否显示
|
||||
*/
|
||||
public setShouldShowErrorTips(show: boolean): void {
|
||||
this.shouldShowErrorTips = show;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建或获取指定角色的聊天实例
|
||||
* @param roleId 角色ID
|
||||
@@ -306,7 +315,10 @@ export class ChatAIService {
|
||||
|
||||
return response.text;
|
||||
} else {
|
||||
TipsPanel.show(response.promptFeedback.blockReason);
|
||||
// 只在允许显示错误提示时才显示
|
||||
if (this.shouldShowErrorTips) {
|
||||
TipsPanel.show(response.promptFeedback.blockReason);
|
||||
}
|
||||
const warningMsg = `AI返回了空响应 (角色ID: ${roleId})`;
|
||||
ErrorHandler.Instance.handleError(
|
||||
new Error(warningMsg),
|
||||
@@ -321,7 +333,10 @@ export class ChatAIService {
|
||||
roleId,
|
||||
message: message,
|
||||
});
|
||||
TipsPanel.show("api调用失败,请使用vpn并重新启动");
|
||||
// 只在允许显示错误提示时才显示
|
||||
if (this.shouldShowErrorTips) {
|
||||
TipsPanel.show("api调用失败,请使用vpn并重新启动");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,6 +208,12 @@ export class ChatController {
|
||||
message
|
||||
);
|
||||
|
||||
// 检查View是否仍然绑定,如果已解绑则不处理响应(用户可能已退出Panel)
|
||||
if (!this.callback) {
|
||||
logger.log("ChatController: View已解绑,忽略AI响应");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (response) {
|
||||
// 添加用户消息到模型
|
||||
this.chatModel.addDialog(true, message);
|
||||
@@ -232,7 +238,7 @@ export class ChatController {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
|
||||
ErrorHandler.Instance.handleApiError(
|
||||
error,
|
||||
"ChatController.sendMessage",
|
||||
@@ -241,7 +247,12 @@ export class ChatController {
|
||||
message: message.substring(0, 100) + "...",
|
||||
}
|
||||
);
|
||||
this.handleError(error as Error);
|
||||
// 只有当View仍然绑定时才调用错误处理回调
|
||||
if (this.callback) {
|
||||
this.handleError(error as Error);
|
||||
} else {
|
||||
logger.log("ChatController: View已解绑,不显示错误提示");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user