加入助手类型字段
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -343,16 +343,23 @@
|
||||
return res.json();
|
||||
}
|
||||
|
||||
// ---------- 模式配置 ----------
|
||||
// ---------- 模式配置(新增助手类型时只需在这里加一项,welcome 卡片与顶部 icon 会自动跟随) ----------
|
||||
const MODES = {
|
||||
secretary: { label: '文秘助理', hint: '支持文字输入,可起草、润色、整理文书' },
|
||||
vision: { label: '识图专家', hint: '支持图片识别输入' },
|
||||
secretary: {
|
||||
label: '文秘助理', hint: '支持文字输入,可起草、润色、整理文书',
|
||||
icon: '<svg class="header-mode-icon" viewBox="0 0 24 24"><path d="M6 3h12l4 6-10 13L2 9z"></path><polyline points="2 9 22 9"></polyline><polyline points="10 3 8 9 12 22"></polyline><polyline points="14 3 16 9 12 22"></polyline></svg>',
|
||||
},
|
||||
vision: {
|
||||
label: '识图专家', hint: '支持图片识别输入',
|
||||
icon: '<svg class="header-mode-icon" viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2"></rect><circle cx="8.5" cy="8.5" r="1.5"></circle><polyline points="21 15 16 10 5 21"></polyline></svg>',
|
||||
},
|
||||
};
|
||||
|
||||
// ---------- 全局状态 ----------
|
||||
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: '<svg class="header-mode-icon" viewBox="0 0 24 24"><path d="M6 3h12l4 6-10 13L2 9z"></path><polyline points="2 9 22 9"></polyline><polyline points="10 3 8 9 12 22"></polyline><polyline points="14 3 16 9 12 22"></polyline></svg>',
|
||||
vision: '<svg class="header-mode-icon" viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2"></rect><circle cx="8.5" cy="8.5" r="1.5"></circle><polyline points="21 15 16 10 5 21"></polyline></svg>',
|
||||
};
|
||||
// 顶部 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 +
|
||||
'<span class="header-title-text">' + esc(state.sessionTitle || state.sessionId) + '</span>';
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user