diff --git a/app/server/db.js b/app/server/db.js index 9b81ada..e7ffdb1 100644 --- a/app/server/db.js +++ b/app/server/db.js @@ -17,6 +17,7 @@ function initDb(dbPath) { phase TEXT NOT NULL DEFAULT 'planning', model_id TEXT, last_model_id TEXT, + assistant_type TEXT DEFAULT 'secretary', created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, completed_at INTEGER, @@ -94,6 +95,11 @@ function initDb(dbPath) { db.exec('ALTER TABLE sessions ADD COLUMN last_model_id TEXT'); db.exec('UPDATE sessions SET last_model_id = model_id WHERE last_model_id IS NULL AND model_id IS NOT NULL'); } + // 迁移:assistant_type 标记会话的 AI 助手类型(secretary=文秘助理 / vision=识图专家), + // 建档时选定,后续不可变更;存量老会话按默认文秘助理回填 + if (!cols.some(c => c.name === 'assistant_type')) { + db.exec("ALTER TABLE sessions ADD COLUMN assistant_type TEXT DEFAULT 'secretary'"); + } return db; } diff --git a/app/server/engine.js b/app/server/engine.js index 45c3c00..06b7320 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -681,13 +681,13 @@ function loadHistoryForModel(sessionId) { .concat(rows.filter(r => r.name !== SESSION_CONTEXT_NAME)); } -function createSession(title, preferModelId) { +function createSession(title, preferModelId, assistantType) { const id = genTaskId(); const dir = taskDirOf(id); fs.mkdirSync(dir, { recursive: true }); db.prepare( - "INSERT INTO sessions (id, title, status, phase, model_id, created_at, updated_at) VALUES (?,?,'queued','planning',NULL,?,?)" - ).run(id, title || '', now(), now()); + "INSERT INTO sessions (id, title, status, phase, model_id, assistant_type, created_at, updated_at) VALUES (?,?,'queued','planning',NULL,?,?,?)" + ).run(id, title || '', assistantType || 'secretary', now(), now()); // 指定了模型且它恰好空闲 → 直接绑定,跳过排队;否则回退到 FIFO 队列 const prefer = preferModelId ? db.prepare('SELECT * FROM model_pool WHERE id = ? AND is_busy = 0').get(preferModelId) diff --git a/app/server/public/index.html b/app/server/public/index.html index 0198f14..1cbd2e5 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -343,16 +343,23 @@ return res.json(); } - // ---------- 模式配置 ---------- + // ---------- 模式配置(新增助手类型时只需在这里加一项,welcome 卡片与顶部 icon 会自动跟随) ---------- const MODES = { - secretary: { label: '文秘助理', hint: '支持文字输入,可起草、润色、整理文书' }, - vision: { label: '识图专家', hint: '支持图片识别输入' }, + secretary: { + label: '文秘助理', hint: '支持文字输入,可起草、润色、整理文书', + icon: '', + }, + vision: { + label: '识图专家', hint: '支持图片识别输入', + icon: '', + }, }; // ---------- 全局状态 ---------- const state = { - view: 'welcome', // welcome | chat - mode: 'secretary', // 模式选择区当前选中 + view: 'welcome', // welcome | chat + mode: 'secretary', // 模式选择区当前选中(仅 welcome 视图可操作) + sessionType: 'secretary', // 当前会话的助手类型(建档时锁定,后续不随模式切换变更) deepThink: false, // 深度思考开关(仅本地视觉状态,无后端参数) sessionId: null, // 当前会话 sessionTitle: '', // 当前会话标题 @@ -385,15 +392,13 @@ function renderHeader() { const c = $('header-center'); if (state.view !== 'chat' || !state.sessionId) { c.innerHTML = ''; return; } - const modeIcons = { - secretary: '', - vision: '', - }; + // 顶部 icon 跟随会话自身的助手类型(而非 welcome 当前选中项) + const modeIcon = (MODES[state.sessionType] && MODES[state.sessionType].icon) || ''; const title = document.createElement('div'); title.className = 'header-title'; title.style.cursor = 'pointer'; title.title = '点击重命名'; - title.innerHTML = (modeIcons[state.mode] || '') + + title.innerHTML = modeIcon + '' + esc(state.sessionTitle || state.sessionId) + ''; title.addEventListener('click', renameSession); // 点标题重命名(同步 index) c.innerHTML = ''; @@ -555,6 +560,7 @@ function renderDetail(detail) { const s = detail.session; state.sessionTitle = (s && s.title) || ''; + state.sessionType = (s && s.assistant_type) || 'secretary'; // 顶部 icon 跟随会话类型 state.status = (s && s.status) || ''; state.toolCards = {}; userPaused = false; @@ -732,6 +738,7 @@ removeTyping(); state.sessionId = null; state.sessionTitle = ''; + state.sessionType = 'secretary'; state.streamEl = null; state.streamText = ''; state.toolCards = {}; @@ -752,6 +759,9 @@ setFilesPanel(false); // 会话切换,收起文件面板防旧列表残留 state.sessionId = id; state.status = ''; + // 先从抽屉列表缓存取会话类型,让顶部 icon 立即正确;详情回来后由 renderDetail 纠正 + const cached = (state.sessions || []).find(x => x.id === id); + state.sessionType = (cached && cached.assistant_type) || 'secretary'; state.streamEl = null; state.streamText = ''; state.toolCards = {}; @@ -772,12 +782,13 @@ } } - // 确保存在当前会话:首条消息自动建档(POST /api/sessions) + // 确保存在当前会话:首条消息自动建档(POST /api/sessions);助手类型此时锁定,后续不可变更 async function ensureSession() { if (state.sessionId) return state.sessionId; - const s = await req('POST', '/api/sessions', { title: '', model_id: '' }); + const s = await req('POST', '/api/sessions', { title: '', model_id: '', assistant_type: state.mode }); state.sessionId = s.id; state.sessionTitle = (s && s.title) || ''; + state.sessionType = (s && s.assistant_type) || state.mode; setView('chat'); renderHeader(); updatePhaseBar(); @@ -791,6 +802,7 @@ setFilesPanel(false); // 新建会话,文件面板随之收起 state.sessionId = null; state.sessionTitle = ''; + state.sessionType = 'secretary'; state.status = ''; state.attachments = []; state.streamEl = null; diff --git a/app/server/routes/sessions.js b/app/server/routes/sessions.js index 9903d24..7b6c1eb 100644 --- a/app/server/routes/sessions.js +++ b/app/server/routes/sessions.js @@ -49,8 +49,10 @@ function listTaskFiles(dir) { router.post('/', wrap((req, res) => { const title = (req.body && req.body.title || '').trim(); const modelId = (req.body && req.body.model_id || '').trim(); - const session = engine.createSession(title, modelId); - log.info('[task] ' + (req.user || '-') + ' 新建任务 ' + session.id + '「' + (session.title || '未命名') + '」model=' + (modelId || '自动')); + // 助手类型建档时锁定,后续不可变更;缺省按文秘助理 + const assistantType = String((req.body && req.body.assistant_type) || 'secretary').trim().slice(0, 32) || 'secretary'; + const session = engine.createSession(title, modelId, assistantType); + log.info('[task] ' + (req.user || '-') + ' 新建任务 ' + session.id + '「' + (session.title || '未命名') + '」model=' + (modelId || '自动') + ' type=' + (session.assistant_type || 'secretary')); res.json(session); }));