会话阶段状态机advising/executing(单会话单问题:先聊清再干活):新建会话与「清空」落advising——resolveProfileName两档化(phase=advising强制命中内置advising组合,否则随模型配置profile,tools_allow只留read_file/fetch/write_file、不带skill故模板无技能清单段,配advising-system.txt:问答判意图引导澄清、每轮至多1-2问防过度追问);唯一出口是任务书正门——runLoopInner工具批跑完后,advising回合内write_file/edit_file成功落任务目录根task.md(argsHitTaskBrief,上传同名与terminal间接创建不算;批量末尾统一切,防父assistant先存档后落库回执成孤儿行被上游拒收)即enterExecuting:全史标archived+插type=task_brief磁盘快照行作执行阶段唯一上下文起点+phase翻转与SSE phase广播,下一迭代重读历史重解profile天然切默认组合、同回合开工(幂等:执行中再改task.md只是普通编辑);回头路只有清空(archiveTaskBrief把旧task.md mv进.task-history/task-<ts>.md防污染新规划,点目录沿用.imgcache隐式约定);压缩对phase中性(压完回原模式,task_brief不豁免存档,漂移可控因压缩本就用户主导);定时投递前强制executing(无人值守不能被顾问话术卡住);db迁移存量phase回填executing零打扰、sessions.profile列废弃不读写;运行期手动切profile全拆(消息级参数/bind的profile分支/setSessionProfile与hasModelProfile/status的model_profiles名单/bind弹窗模式区),头部徽标机位复用为阶段徽标(仅advising显灯泡,SSE phase驱动,转执行toast反馈)
This commit is contained in:
@@ -329,7 +329,7 @@
|
||||
const s = detail.session;
|
||||
state.sessionTitle = (s && s.title) || '';
|
||||
state.sessionType = (s && s.assistant_type) || 'secretary'; // 顶部 icon 跟随会话类型
|
||||
state.profile = (s && s.profile) || ''; // 会话绑定模式(头部徽标/弹窗当前态同源)
|
||||
state.phase = s && s.phase || ''; // 会话阶段(advising/executing):头部徽标与 SSE status/phase 事件同源
|
||||
state.status = (s && s.status) || '';
|
||||
state.schedule = detail.schedule || null; // 定时任务状态条数据(随 updatePhaseBar 一并渲染)
|
||||
state.toolCards = {};
|
||||
|
||||
@@ -157,9 +157,8 @@
|
||||
mode: 'secretary', // 新建会话默认助手类型(欢迎页已去掉模式切换,不再可变)
|
||||
sessionType: 'secretary', // 当前会话的助手类型(建档时锁定,后续不随模式切换变更)
|
||||
deepThink: false, // 深度思考开关(仅本地视觉状态,无后端参数)
|
||||
profile: '', // 当前会话绑定模式(sessions.profile;''=默认随模型;弹窗「模式」区切换)
|
||||
phase: '', // 当前会话阶段(sessions.phase: advising=顾问 / executing=执行;徽标据此渲染)
|
||||
pendingModel: '', // welcome 预选模型(ensureSession 建档时透传 model_id)
|
||||
pendingProfile: '', // welcome 预选模式(ensureSession 建会话后立即 bind)
|
||||
sessionId: null, // 当前会话
|
||||
sessionTitle: '', // 当前会话标题
|
||||
status: '', // 当前会话状态(SSE 更新)
|
||||
@@ -198,29 +197,31 @@
|
||||
updateScrollBottomBtn();
|
||||
}
|
||||
|
||||
// ---------- 会话模式徽标 ----------
|
||||
// 会话绑定 profile 时仅头部标题前显示小图标(抽屉列表不显,避免画蛇添足):''=默认不显示;
|
||||
// 颜色统一 --active(CSS .prof-*),靠形状区分;未知名兑底圆点;tooltip 提示当前模式,不另显文字。
|
||||
const PROFILE_BADGES = {
|
||||
lab: '<svg viewBox="0 0 24 24" class="ic"><path fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" d="M10 2v6.6L4.8 18.5a1.8 1.8 0 0 0 1.6 2.7h11.2a1.8 1.8 0 0 0 1.6-2.7L14 8.6V2"/><line x1="8.5" y1="2" x2="15.5" y2="2"/></svg>',
|
||||
zero: '<svg viewBox="0 0 24 24" class="ic"><circle fill="none" stroke="currentColor" stroke-width="1.8" cx="12" cy="12" r="9"/><line stroke="currentColor" stroke-width="1.8" stroke-linecap="round" x1="8" y1="12" x2="16" y2="12"/></svg>',
|
||||
// ---------- 会话阶段徽标 ----------
|
||||
// 头部标题前小图标:advising(顾问:澄清需求/规划)才显示(tooltip 说明),
|
||||
// executing 是主干状态不显示、减噪。原 profile 模式徽标机位改造而来(手动切换模式已移除)。
|
||||
const PHASE_BADGES = {
|
||||
advising: {
|
||||
label: '顾问模式:澄清需求、规划任务;写定任务书后自动开始执行',
|
||||
icon: '<svg viewBox="0 0 24 24" class="ic" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18h6"/><path d="M10 21h4"/><path d="M12 3a6 6 0 0 0-3.6 10.8c.7.6 1.1 1.4 1.1 2.2h5c0-.8.4-1.6 1.1-2.2A6 6 0 0 0 12 3z"/></svg>',
|
||||
},
|
||||
};
|
||||
function profileBadgeHtml(p) {
|
||||
if (!p) return '';
|
||||
return '<span class="prof-badge prof-' + esc(p) + '" title="当前模式:' + esc(p) + '">' +
|
||||
(PROFILE_BADGES[p] || '<svg viewBox="0 0 24 24" class="ic"><circle cx="12" cy="12" r="4.5" fill="none" stroke="currentColor" stroke-width="2"/></svg>') + '</span>';
|
||||
function phaseBadgeHtml(p) {
|
||||
const b = PHASE_BADGES[p];
|
||||
if (!b) return '';
|
||||
return '<span class="prof-badge phase-' + esc(p) + '" title="' + esc(b.label) + '">' + b.icon + '</span>';
|
||||
}
|
||||
|
||||
function renderHeader() {
|
||||
const c = $('header-center');
|
||||
// welcome(含刚 newChat)一律清空:newChat 会停在 welcome,不重刷会残留旧会话标题
|
||||
if (state.view !== 'chat' || !state.sessionId) { c.innerHTML = ''; return; }
|
||||
// 顶部只显会话模式徽标(助手类型 icon 退位;''=默认不显),颜色按模式区分,tooltip 提示当前模式
|
||||
// 顶部只显会话阶段徽标(advising 才显)+ 标题;助手类型 icon 早已退位
|
||||
const title = document.createElement('div');
|
||||
title.className = 'header-title';
|
||||
title.style.cursor = 'pointer';
|
||||
title.title = '点击重命名';
|
||||
title.innerHTML = profileBadgeHtml(state.profile) +
|
||||
title.innerHTML = phaseBadgeHtml(state.phase) +
|
||||
'<span class="header-title-text">' + esc(state.sessionTitle || state.sessionId) + '</span>';
|
||||
title.addEventListener('click', renameSession); // 点标题重命名(同步 index)
|
||||
c.innerHTML = '';
|
||||
|
||||
@@ -78,9 +78,8 @@
|
||||
state.sessionId = null;
|
||||
state.sessionTitle = '';
|
||||
state.sessionType = 'secretary';
|
||||
state.profile = '';
|
||||
state.phase = '';
|
||||
state.pendingModel = '';
|
||||
state.pendingProfile = '';
|
||||
state.streamEl = null;
|
||||
state.streamText = '';
|
||||
state.toolCards = {};
|
||||
@@ -162,7 +161,7 @@
|
||||
// 先从抽屉列表缓存取会话类型,让顶部 icon 立即正确;详情回来后由 renderDetail 纠正
|
||||
const cached = (state.sessions || []).find(x => x.id === id);
|
||||
state.sessionType = (cached && cached.assistant_type) || 'secretary';
|
||||
state.profile = (cached && cached.profile) || ''; // 先从列表缓存取模式徽标,renderDetail 回来后纠正
|
||||
state.phase = (cached && cached.phase) || ''; // 先从列表缓存取阶段徽标,renderDetail 回来后纠正
|
||||
state.streamEl = null;
|
||||
state.streamText = '';
|
||||
state.streamWrap = null;
|
||||
@@ -191,20 +190,14 @@
|
||||
}
|
||||
|
||||
// 确保存在当前会话:首条消息自动建档(POST /api/sessions);助手类型此时锁定,后续不可变更。
|
||||
// welcome 经弹窗预选的模型/模式在这里兑现:model_id 建档透传,pendingProfile 建完会话立即 bind(早于首条消息)。
|
||||
// welcome 经弹窗预选的模型在这里兑现:model_id 建档透传。
|
||||
async function ensureSession() {
|
||||
if (state.sessionId) return state.sessionId;
|
||||
const s = await req('POST', '/api/sessions', { title: '', model_id: state.pendingModel || '', assistant_type: state.mode });
|
||||
state.sessionId = s.id;
|
||||
state.sessionTitle = (s && s.title) || '';
|
||||
state.sessionType = (s && s.assistant_type) || state.mode;
|
||||
if (state.pendingProfile) {
|
||||
try {
|
||||
await req('POST', '/api/sessions/' + s.id + '/bind', { profile: state.pendingProfile });
|
||||
} catch (e) { toast('模式绑定失败:' + e.message); state.profile = ''; }
|
||||
}
|
||||
state.pendingModel = '';
|
||||
state.pendingProfile = '';
|
||||
setView('chat');
|
||||
renderHeader();
|
||||
updatePhaseBar();
|
||||
@@ -221,9 +214,8 @@
|
||||
state.sessionType = 'secretary';
|
||||
state.status = '';
|
||||
state.schedule = null;
|
||||
state.profile = '';
|
||||
state.phase = '';
|
||||
state.pendingModel = '';
|
||||
state.pendingProfile = '';
|
||||
state.attachments = [];
|
||||
state.streamEl = null;
|
||||
state.streamText = '';
|
||||
@@ -431,7 +423,7 @@
|
||||
} catch (e) { toast((held ? '断开失败:' : '终止失败:') + e.message); }
|
||||
}
|
||||
async function openModelSwitch() {
|
||||
// welcome(无会话)也可开:模型/模式选择记为预选项,ensureSession 建档时兑现。有会话则即点即绑,行为与原逻辑一致。
|
||||
// welcome(无会话)也可开:模型选择记为预选项,ensureSession 建档时兑现。有会话则即点即绑,行为与原逻辑一致。
|
||||
const list = $('bind-model-list');
|
||||
const sub = $('bind-model-sub');
|
||||
list.innerHTML = '<div class="empty-tip">加载中…</div>';
|
||||
@@ -497,58 +489,19 @@
|
||||
} catch (e) {
|
||||
modelsHtml = '<div class="empty-tip">读取模型列表失败:' + e.message + '</div>';
|
||||
}
|
||||
// ---------- 模式行:下拉选中(名单来自 /api/system/status;拉不到 = 整行隐藏,不影响选模型) ----------
|
||||
let profHtml = '';
|
||||
const names = await loadProfileNames();
|
||||
if (names.length) {
|
||||
const cur = state.sessionId ? state.profile : state.pendingProfile;
|
||||
const opts = [''].concat(names).map(p =>
|
||||
'<option value="' + esc(p) + '"' + (p === cur ? ' selected' : '') + '>' + (p ? esc(p) : '默认(随模型配置)') + '</option>').join('');
|
||||
profHtml = '<div class="msw-prof"><span class="msw-prof-label">模式:</span>' +
|
||||
'<select id="bind-prof-select" onchange="chooseProfile(this.value)">' + opts + '</select></div>';
|
||||
}
|
||||
// 空闲数并进顶部提示句(原 footer「共 X 个模型可用」不再单独占行)
|
||||
if (sub) sub.textContent = (state.sessionId ? '选择一个模型继续当前会话' : '选择一个模型用于新会话')
|
||||
+ (avail ? '(共 ' + avail + ' 个空闲)' : '');
|
||||
list.innerHTML = modelsHtml + profHtml;
|
||||
list.innerHTML = modelsHtml;
|
||||
}
|
||||
function closeModelSwitch() { $('bind-model-modal').classList.add('hidden'); }
|
||||
|
||||
// profile 组合名单缓存(组合列表改动需重启才生效,会话级缓存足够);status 拉失败 = 空名单 → 模式区隐藏。
|
||||
let PROFILE_NAMES = null;
|
||||
async function loadProfileNames() {
|
||||
if (PROFILE_NAMES) return PROFILE_NAMES;
|
||||
try {
|
||||
const s = await req('GET', '/api/system/status');
|
||||
PROFILE_NAMES = Array.isArray(s && s.model_profiles) ? s.model_profiles.slice() : [];
|
||||
} catch (_) { PROFILE_NAMES = []; }
|
||||
return PROFILE_NAMES;
|
||||
}
|
||||
|
||||
function choosePendingModel(modelId) { // welcome 无会话:记预选,ensureSession 建档时透传;选完即关窗 + toast,重开弹窗时该行带「预选」标记
|
||||
state.pendingModel = modelId;
|
||||
closeModelSwitch();
|
||||
toast('新会话将用 ' + modelId);
|
||||
}
|
||||
|
||||
async function chooseProfile(name) { // 下拉选中即绑/即预选;无 toast(头部/抽屉徽标即时变化即反馈),失败回退选项并报错
|
||||
if (state.sessionId) {
|
||||
try {
|
||||
await req('POST', '/api/sessions/' + state.sessionId + '/bind', { profile: name });
|
||||
} catch (e) {
|
||||
const sel = $('bind-prof-select');
|
||||
if (sel) sel.value = state.profile; // 失败回退选项,下拉不谎报
|
||||
return toast('切换失败:' + e.message);
|
||||
}
|
||||
state.profile = name;
|
||||
const row = (state.sessions || []).find(x => x.id === state.sessionId); // 只同步本地缓存保数据一致(抽屉不显模式徽标,无需重画)
|
||||
if (row) row.profile = name;
|
||||
} else {
|
||||
state.pendingProfile = name;
|
||||
state.profile = name;
|
||||
}
|
||||
renderHeader(); // 头部徽标即时变化 = 切换成功的反馈
|
||||
}
|
||||
async function bindModel(modelId) {
|
||||
if (!state.sessionId) return;
|
||||
const id = state.sessionId;
|
||||
|
||||
@@ -136,10 +136,19 @@
|
||||
es.addEventListener('status', ev => {
|
||||
const d = JSON.parse(ev.data);
|
||||
state.status = d.status;
|
||||
state.phase = d.phase || '';
|
||||
renderHeader();
|
||||
updatePhaseBar(d);
|
||||
updateScrollBottomBtn(); // 状态切换同步右下角转圈(开始/结束干活)
|
||||
});
|
||||
// 阶段切换(advising↔executing):任务书落地自动转执行时给一句明确反馈;
|
||||
// 回 advising(清空)由发起动作自带反馈,不重复弹。
|
||||
es.addEventListener('phase', ev => {
|
||||
const d = JSON.parse(ev.data);
|
||||
state.phase = d.phase || '';
|
||||
renderHeader();
|
||||
if (state.phase === 'executing') toast('任务书已确认,进入执行模式');
|
||||
});
|
||||
es.addEventListener('assistant_delta', ev => {
|
||||
const d = JSON.parse(ev.data);
|
||||
removeTyping();
|
||||
|
||||
Reference in New Issue
Block a user