加入助手类型字段
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user