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