refactor: 清理渲染进程全部 58 处 console.log/warn/error
- 所有错误日志统一走 logService(logError/logWarn/logInfo) - 无 logService 的地方补上对应调用 - 纯调试 trace 直接删除(桌面应用看不到 console) - ollama.ts 流式解析错误改为静默跳过(非关键) - 执行日志面板信息量不变
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
import { state, KEYS } from '../state/state.js';
|
||||
import { logError } from '../services/log-service.js';
|
||||
import { marked } from '../utils/marked-config.js';
|
||||
import { escapeHtml, formatTime } from '../utils/utils.js';
|
||||
import type { ChatSession, ChatMessage, ToolCallRecord } from '../types.js';
|
||||
@@ -396,7 +397,7 @@ async function nativeSaveFile(defaultName: string, content: string): Promise<voi
|
||||
if (!filePath) return;
|
||||
const result = await bridge.fs.writeFile(filePath, content, 'utf-8');
|
||||
if (!result.success) {
|
||||
console.error('[ChatArea] 导出失败:', result.error);
|
||||
logError('导出失败', result.error);
|
||||
}
|
||||
} else {
|
||||
// 回退
|
||||
|
||||
@@ -151,7 +151,7 @@ async function handleImagePaths(paths: string[]): Promise<void> {
|
||||
pendingImages.push({ name, base64 });
|
||||
logInfo(`图片已添加: ${name}`, formatSize(binary.length));
|
||||
} catch (err) {
|
||||
console.error('[InputArea] 图片读取失败:', err);
|
||||
logError('图片读取失败', (err as Error).message);
|
||||
appendSystemMessage(`❌ 读取 ${name} 失败`);
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ async function handleTextFilePaths(paths: string[]): Promise<void> {
|
||||
logInfo(`文件已添加: ${name}`, formatSize(size));
|
||||
renderFilePreviews();
|
||||
} catch (err) {
|
||||
console.error('[InputArea] 文件读取失败:', err);
|
||||
logError('文件读取失败', (err as Error).message);
|
||||
appendSystemMessage(`❌ 读取 ${name} 失败`);
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,7 @@ export async function sendMessage(): Promise<void> {
|
||||
appendSystemMessage('🧠 知识库未检索到相关内容,使用通用知识回答', 'rag-status');
|
||||
}
|
||||
} catch (ragErr) {
|
||||
console.error('[RAG] 检索失败:', ragErr);
|
||||
logError('RAG 检索失败', (ragErr as Error).message);
|
||||
appendSystemMessage(`🧠 知识库检索失败: ${(ragErr as Error).message}`, 'rag-status');
|
||||
}
|
||||
}
|
||||
@@ -520,9 +520,9 @@ export async function sendMessage(): Promise<void> {
|
||||
currentSession2.title
|
||||
).then(count => {
|
||||
if (count > 0) {
|
||||
console.log(`[Memory] 自动提取了 ${count} 条记忆`);
|
||||
logInfo(`自动提取了 ${count} 条记忆`);
|
||||
}
|
||||
}).catch(err => console.warn('[Memory] 提取失败:', err));
|
||||
}).catch(err => logError('记忆提取失败', (err as Error).message));
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -728,7 +728,6 @@ async function sendMessageWithAgentLoop(text: string, currentSession: ChatSessio
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('[AgentLoop] 错误:', err);
|
||||
logError('Agent Loop 错误', (err as Error).message);
|
||||
|
||||
if ((err as Error).name === 'AbortError') {
|
||||
@@ -793,6 +792,6 @@ async function saveCurrentSession(): Promise<void> {
|
||||
try {
|
||||
await db.saveSession(currentSession);
|
||||
} catch (err) {
|
||||
console.error('[InputArea] 保存会话失败:', err);
|
||||
logError('保存会话失败', (err as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { formatSize, escapeHtml, truncate } from '../utils/utils.js';
|
||||
import { showToast } from './toast.js';
|
||||
import { showConfirm } from './prompt-modal.js';
|
||||
import { OllamaAPI } from '../api/ollama.js';
|
||||
import { logRAG, logError } from '../services/log-service.js';
|
||||
import { logRAG, logError, logWarn } from '../services/log-service.js';
|
||||
import type { VectorCollection, SearchResult } from '../types.js';
|
||||
|
||||
let kbModalEl: HTMLElement;
|
||||
@@ -85,7 +85,7 @@ export async function performRagRetrieval(query: string): Promise<{ context: str
|
||||
if (!context) return null;
|
||||
return { context, results, ragPrompt: buildRagSystemPrompt(context) };
|
||||
} catch (err) {
|
||||
console.warn('[KB] RAG 检索失败:', err);
|
||||
logWarn('RAG 检索失败', (err as Error).message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -267,10 +267,8 @@ async function handleDocUpload(paths: string[]): Promise<void> {
|
||||
logRAG(`文档上传: ${name}`, `${kbResult.chunkCount} 个分块`);
|
||||
successCount++;
|
||||
} catch (err) {
|
||||
console.error('[KB] 文档处理失败:', err);
|
||||
const fileName = filePath.split(/[/\\]/).pop() || filePath;
|
||||
showToast(`${fileName} 处理失败: ${(err as Error).message}`, 'error');
|
||||
logError(`RAG 文档处理失败: ${fileName}`, (err as Error).message);
|
||||
logError(`RAG 文档处理失败: ${name}`, (err as Error).message);
|
||||
showToast(`${name} 处理失败: ${(err as Error).message}`, 'error');
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
@@ -322,6 +320,6 @@ async function populateEmbedModels(): Promise<void> {
|
||||
select.innerHTML = '<option value="">未检测到嵌入模型,请先 ollama pull</option>';
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[KB] 加载模型列表失败:', err);
|
||||
logWarn('加载嵌入模型列表失败', (err as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,6 @@ export async function loadModels(): Promise<void> {
|
||||
|
||||
filterEmbedModels(data.models);
|
||||
} catch (err) {
|
||||
console.error('[ModelBar] 加载模型失败:', err);
|
||||
logError('加载模型列表失败', (err as Error).message);
|
||||
modelSelectEl.innerHTML = '<option value="">加载失败 - 检查连接</option>';
|
||||
badgeThinkEl.style.display = 'none'; badgeVisionEl.style.display = 'none';
|
||||
@@ -169,7 +168,6 @@ async function checkModelCapability(modelName: string): Promise<void> {
|
||||
logDebug(`能力检测: ${modelName}`, capabilities.join(', '));
|
||||
applyCapability(modelName, caps);
|
||||
} catch (err) {
|
||||
console.warn('[ModelBar] 获取模型能力失败:', err);
|
||||
logWarn(`能力检测失败: ${modelName}`, (err as Error).message);
|
||||
const fallback = { think: false, vision: false, tools: false, completion: true };
|
||||
modelCapabilityCache.set(modelName, fallback);
|
||||
|
||||
@@ -232,7 +232,6 @@ async function exportAllSessions(): Promise<void> {
|
||||
showToast(`已导出 ${sessions.length} 个会话(已加密)`, 'success');
|
||||
logSuccess(`导出完成: ${sessions.length} 个会话`);
|
||||
} catch (err) {
|
||||
console.error('[Settings] 导出失败:', err);
|
||||
showToast(`导出失败: ${(err as Error).message}`, 'error');
|
||||
logError('导出失败', (err as Error).message);
|
||||
}
|
||||
@@ -276,7 +275,6 @@ async function importSessions(filePath: string): Promise<void> {
|
||||
showToast(`导入完成:${result.imported} 个会话${result.skipped > 0 ? `,跳过 ${result.skipped} 个` : ''}`, 'success', 4000);
|
||||
logSuccess(`导入完成: ${result.imported} 个, 跳过 ${result.skipped} 个`);
|
||||
} catch (err) {
|
||||
console.error('[Settings] 导入失败:', err);
|
||||
showToast(`导入失败: ${(err as Error).message}`, 'error');
|
||||
logError('导入失败', (err as Error).message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user