fix: 修复三个启动相关 Bug

Bug 1: prompt()/confirm() 在 Electron contextIsolation 下不可用
- 新增 prompt-modal.ts 自定义弹窗组件
- 替换 memory-panel.ts、kb-modal.ts、settings-modal.ts、history-modal.ts 中所有 prompt()/confirm() 调用

Bug 2: 日志面板重启后无日志
- log-service.ts 新增 earlyBuffer 缓冲 initLogPanel() 之前的日志
- initLogPanel() 初始化时 flush earlyBuffer 到 DOM
- main.ts 中 initLogPanel() 移至最先初始化

Bug 3: 首次启动输入框可能被禁用
- main.ts init() 中防御性重置 IS_STREAMING/IS_HISTORY_VIEW/toolCallingEnabled 等状态
- catch 块也重置关键状态并初始化日志面板
This commit is contained in:
Metona Dev
2026-04-06 20:11:41 +08:00
parent 70fef8e969
commit c516755a5c
7 changed files with 239 additions and 24 deletions
+3 -2
View File
@@ -10,6 +10,7 @@ import {
} from '../services/rag.js';
import { fileToText, 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 type { VectorCollection, SearchResult } from '../types.js';
@@ -144,7 +145,7 @@ async function refreshCollections(): Promise<void> {
btn.addEventListener('click', async (e) => {
e.stopPropagation();
const id = (btn as HTMLElement).dataset.id!;
if (!confirm('确定删除此知识库集合?所有文档将被清除。')) return;
if (!await showConfirm('确定删除此知识库集合?所有文档将被清除。', '删除知识库')) return;
const vs = getVectorStore();
await vs!.deleteCollection(id);
if (currentColId === id) currentColId = null;
@@ -192,7 +193,7 @@ async function refreshDocList(): Promise<void> {
docListEl.querySelectorAll('.kb-doc-delete').forEach(btn => {
btn.addEventListener('click', async () => {
const docId = (btn as HTMLElement).dataset.docid!;
if (!confirm('确定删除此文档?')) return;
if (!await showConfirm('确定删除此文档?', '删除文档')) return;
await removeDocumentFromKB(currentColId!, docId);
showToast('文档已删除', 'success');
await refreshCollections();