重设计会话页选择模型弹窗:按平台分组展示、彩色圆点标识、key数量标签、Vision/Thinking能力标签、per-platform锁定逻辑
This commit is contained in:
@@ -1021,8 +1021,32 @@ label.icon-btn { cursor: pointer; }
|
||||
}
|
||||
.modal-close-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
|
||||
.modal .modal-text { font-size: 14px; color: #556; margin-bottom: 12px; white-space: pre-wrap; }
|
||||
.modal .del-dir { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink); margin-bottom: 14px; cursor: pointer; }
|
||||
.modal .del-dir input { width: 16px; height: 16px; padding: 0; margin: 0; flex: none; accent-color: var(--active); }
|
||||
.modal .del-dir { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink); margin-bottom: 14px; cursor: pointer; }
|
||||
.modal .del-dir input { width: 16px; height: 16px; padding: 0; margin: 0; flex: none; accent-color: var(--active); }
|
||||
|
||||
/* 模型选择弹窗(会话页 phase-bar「选择模型」入口) */
|
||||
.msw-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
|
||||
.msw-titles h3 { margin: 0 0 4px 0; font-size: 16px; }
|
||||
.msw-sub { font-size: 13px; color: var(--gray-light); margin: 0; }
|
||||
.msw-list { max-height: 420px; overflow-y: auto; margin: 0 -4px; padding-right: 4px; }
|
||||
.msw-footer { text-align: center; font-size: 13px; color: var(--gray-light); margin-top: 12px; }
|
||||
.msw-group { margin-bottom: 16px; }
|
||||
.msw-group-header { display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 13px; font-weight: 600; color: var(--ink); }
|
||||
.msw-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
|
||||
.msw-group-keys { font-size: 11px; color: var(--gray-light); margin-left: auto; background: var(--surface); border-radius: 10px; padding: 1px 6px; }
|
||||
.msw-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; transition: background 0.15s; }
|
||||
.msw-item:hover:not(.disabled) { background: var(--surface); }
|
||||
.msw-item.disabled { opacity: 0.45; cursor: not-allowed; }
|
||||
.msw-item.selected { background: color-mix(in srgb, var(--active) 8%, transparent); }
|
||||
.msw-radio { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #dde1ea; flex-shrink: 0; display: flex; align-items: center; justify-content: center; transition: border-color 0.15s, background 0.15s; }
|
||||
.msw-item.selected .msw-radio { border-color: var(--active); background: var(--active); }
|
||||
.msw-item.selected .msw-radio::after { content: '✓'; color: #fff; font-size: 11px; font-weight: 700; }
|
||||
.msw-info { flex: 1; min-width: 0; }
|
||||
.msw-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.msw-tags { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
|
||||
.msw-tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; }
|
||||
.msw-tag.vision { background: #dbeafe; color: #1d4ed8; }
|
||||
.msw-tag.thinking { background: #fef3c7; color: #92400e; }
|
||||
|
||||
/* ================= 桌面端布局(≥960px) =================
|
||||
历史侧边栏常驻左侧(由 body.drawer-open 控制展开/折叠,不用遮罩);
|
||||
|
||||
@@ -292,12 +292,17 @@
|
||||
<!-- 已完成/已终止会话:选择模型继续(搬自 index;phase-bar「选择模型」入口) -->
|
||||
<div id="bind-model-modal" class="modal-overlay hidden" onclick="if(event.target===this)closeModelSwitch()">
|
||||
<div class="modal">
|
||||
<button class="modal-close-btn" onclick="closeModelSwitch()">
|
||||
<svg viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
</button>
|
||||
<h3>选择模型继续会话</h3>
|
||||
<p class="empty-tip" style="margin-bottom:10px">为已结束(已完成/已终止)的会话指定一个空闲模型,绑定后继续对话将优先使用该模型。</p>
|
||||
<div class="btn-row" id="bind-model-list" style="flex-direction:column;align-items:stretch;gap:8px;"></div>
|
||||
<div class="msw-header">
|
||||
<div class="msw-titles">
|
||||
<h3>切换模型</h3>
|
||||
<p class="msw-sub">选择一个模型继续当前会话</p>
|
||||
</div>
|
||||
<button class="modal-close-btn" onclick="closeModelSwitch()">
|
||||
<svg viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="msw-list" id="bind-model-list"></div>
|
||||
<div class="msw-footer" id="bind-model-footer"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1056,20 +1061,78 @@
|
||||
async function openModelSwitch() {
|
||||
if (!state.sessionId) return;
|
||||
const list = $('bind-model-list');
|
||||
const footer = $('bind-model-footer');
|
||||
list.innerHTML = '<div class="empty-tip">加载中…</div>';
|
||||
$('bind-model-modal').classList.remove('hidden');
|
||||
try {
|
||||
// 已删除但重启前仍在运行池里的模型不再展示,避免误绑到重启后就消失的模型
|
||||
const rows = ((await req('GET', '/api/models')) || []).filter(m => !SET.deletedModels[m.id]);
|
||||
if (!rows.length) {
|
||||
list.innerHTML = '<div class="empty-tip">还没有配置模型。</div>';
|
||||
footer.textContent = '';
|
||||
return;
|
||||
}
|
||||
list.innerHTML = rows.map(m => m.is_busy
|
||||
? '<button class="ghost-btn" disabled>' + esc(m.display_name || m.id) + ' · 占用中</button>'
|
||||
: '<button class="primary-btn" onclick="bindModel(\'' + esc(m.id) + '\')">' + esc(m.display_name || m.id) + '</button>').join('');
|
||||
// 平台颜色盘(循环使用)
|
||||
const DOT_COLORS = ['#3B82F6','#10B981','#F59E0B','#EF4444','#8B5CF6','#EC4899','#06B6D4','#F97316'];
|
||||
// 按平台分组: platform -> { name, keyCount, models[] }
|
||||
const platMap = new Map();
|
||||
for (const m of rows) {
|
||||
if (!platMap.has(m.platform)) {
|
||||
platMap.set(m.platform, { name: m.platform || '未知平台', keyCount: 0, models: [] });
|
||||
}
|
||||
const g = platMap.get(m.platform);
|
||||
// 统计 key 数(cfg.models 里同平台但不同 key_index 的条目数)
|
||||
// 同时收集该平台的 key_index 集合
|
||||
if (g.keyIndices === undefined) g.keyIndices = new Set();
|
||||
if (m.key_index !== undefined) g.keyIndices.add(m.key_index);
|
||||
// 同 id 的 model 取第一条(cfg.models 同 id 会出现 N 次,N=key 数)
|
||||
if (!g.seenIds) g.seenIds = new Set();
|
||||
if (!g.seenIds.has(m.id)) {
|
||||
g.seenIds.add(m.id);
|
||||
g.models.push(m);
|
||||
}
|
||||
}
|
||||
// 平台是否锁定:该平台下任意模型 is_busy 则整平台锁定
|
||||
let totalAvailable = 0;
|
||||
let totalAll = 0;
|
||||
const groups = [];
|
||||
for (const [platName, g] of platMap) {
|
||||
const isLocked = g.models.some(m => m.is_busy);
|
||||
g.keyCount = g.keyIndices ? g.keyIndices.size : 1;
|
||||
for (const m of g.models) {
|
||||
totalAll++;
|
||||
if (!isLocked && !m.is_busy) totalAvailable++;
|
||||
}
|
||||
groups.push({ platName, isLocked, keyCount: g.keyCount, models: g.models });
|
||||
}
|
||||
list.innerHTML = groups.map((grp, gi) => {
|
||||
const dotColor = DOT_COLORS[gi % DOT_COLORS.length];
|
||||
const itemHtml = grp.models.map(m => {
|
||||
const disabled = m.is_busy || grp.isLocked;
|
||||
return '<div class="msw-item' + (disabled ? ' disabled' : '') + '"' +
|
||||
(disabled ? '' : ' onclick="bindModel(\'' + esc(m.id) + '\')"') + '>' +
|
||||
'<div class="msw-radio"></div>' +
|
||||
'<div class="msw-info">' +
|
||||
'<div class="msw-name">' + esc(m.display_name || m.mid || m.id) + '</div>' +
|
||||
'<div class="msw-tags">' +
|
||||
(m.vision ? '<span class="msw-tag vision">Vision</span>' : '') +
|
||||
'<span class="msw-tag thinking">Thinking</span>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
}).join('');
|
||||
return '<div class="msw-group">' +
|
||||
'<div class="msw-group-header">' +
|
||||
'<span class="msw-dot" style="background:' + dotColor + '"></span>' +
|
||||
'<span>' + esc(grp.platName) + '</span>' +
|
||||
'<span class="msw-group-keys">' + grp.keyCount + ' key' + (grp.keyCount > 1 ? 's' : '') + '</span>' +
|
||||
'</div>' +
|
||||
itemHtml +
|
||||
'</div>';
|
||||
}).join('');
|
||||
footer.textContent = '共 ' + totalAvailable + ' / ' + totalAll + ' 个模型可用';
|
||||
} catch (e) {
|
||||
list.innerHTML = '<div class="empty-tip">读取模型列表失败:' + e.message + '</div>';
|
||||
footer.textContent = '';
|
||||
}
|
||||
}
|
||||
function closeModelSwitch() { $('bind-model-modal').classList.add('hidden'); }
|
||||
|
||||
@@ -771,31 +771,82 @@ const ui = {
|
||||
async openModelSwitch() {
|
||||
if (!state.sessionId) return;
|
||||
const list = $('bind-model-list');
|
||||
const footer = $('bind-model-footer');
|
||||
list.innerHTML = '<div class="empty-tip">加载中…</div>';
|
||||
$('bind-model-modal').classList.remove('hidden');
|
||||
try {
|
||||
const rows = await req('GET', '/api/models');
|
||||
const rows = (await req('GET', '/api/models')) || [];
|
||||
if (!rows.length) {
|
||||
list.innerHTML = '<div class="empty-tip">还没有配置模型。</div>';
|
||||
footer && (footer.textContent = '');
|
||||
return;
|
||||
}
|
||||
list.innerHTML = rows.map(m => m.is_busy
|
||||
? '<button class="ghost-btn" disabled>' + esc(m.display_name || m.id) + ' · 占用中</button>'
|
||||
: '<button class="primary-btn" onclick="ui.bindModel(\'' + esc(m.id) + '\')">' + esc(m.display_name || m.id) + '</button>').join('');
|
||||
const DOT_COLORS = ['#3B82F6','#10B981','#F59E0B','#EF4444','#8B5CF6','#EC4899','#06B6D4','#F97316'];
|
||||
const platMap = new Map();
|
||||
for (const m of rows) {
|
||||
if (!platMap.has(m.platform)) {
|
||||
platMap.set(m.platform, { name: m.platform || '未知平台', keyIndices: new Set(), models: [], seenIds: new Set() });
|
||||
}
|
||||
const g = platMap.get(m.platform);
|
||||
if (m.key_index !== undefined) g.keyIndices.add(m.key_index);
|
||||
if (!g.seenIds.has(m.id)) {
|
||||
g.seenIds.add(m.id);
|
||||
g.models.push(m);
|
||||
}
|
||||
}
|
||||
let totalAvailable = 0, totalAll = 0;
|
||||
const groups = [];
|
||||
let gi = 0;
|
||||
for (const [platName, g] of platMap) {
|
||||
const isLocked = g.models.some(m => m.is_busy);
|
||||
const keyCount = g.keyIndices.size || 1;
|
||||
for (const m of g.models) {
|
||||
totalAll++;
|
||||
if (!isLocked && !m.is_busy) totalAvailable++;
|
||||
}
|
||||
groups.push({ platName, isLocked, keyCount, models: g.models, dotColor: DOT_COLORS[gi % DOT_COLORS.length] });
|
||||
gi++;
|
||||
}
|
||||
list.innerHTML = groups.map(grp => {
|
||||
const itemHtml = grp.models.map(m => {
|
||||
const disabled = m.is_busy || grp.isLocked;
|
||||
return '<div class="msw-item' + (disabled ? ' disabled' : '') + '"' +
|
||||
(disabled ? '' : ' onclick="ui.bindModel(\'' + esc(m.id) + '\')"') + '>' +
|
||||
'<div class="msw-radio"></div>' +
|
||||
'<div class="msw-info">' +
|
||||
'<div class="msw-name">' + esc(m.display_name || m.mid || m.id) + '</div>' +
|
||||
'<div class="msw-tags">' +
|
||||
(m.vision ? '<span class="msw-tag vision">Vision</span>' : '') +
|
||||
'<span class="msw-tag thinking">Thinking</span>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
}).join('');
|
||||
return '<div class="msw-group">' +
|
||||
'<div class="msw-group-header">' +
|
||||
'<span class="msw-dot" style="background:' + grp.dotColor + '"></span>' +
|
||||
'<span>' + esc(grp.platName) + '</span>' +
|
||||
'<span class="msw-group-keys">' + grp.keyCount + ' key' + (grp.keyCount > 1 ? 's' : '') + '</span>' +
|
||||
'</div>' +
|
||||
itemHtml +
|
||||
'</div>';
|
||||
}).join('');
|
||||
footer && (footer.textContent = '共 ' + totalAvailable + ' / ' + totalAll + ' 个模型可用');
|
||||
} catch (e) {
|
||||
list.innerHTML = '<div class="empty-tip">读取模型列表失败:' + e.message + '</div>';
|
||||
footer && (footer.textContent = '');
|
||||
}
|
||||
},
|
||||
closeModelSwitch() { $('bind-model-modal').classList.add('hidden'); },
|
||||
async bindModel(modelId) {
|
||||
if (!state.sessionId) return;
|
||||
const sid = state.sessionId;
|
||||
this.closeModelSwitch();
|
||||
try {
|
||||
await req('POST', '/api/sessions/' + state.sessionId + '/bind', { model_id: modelId });
|
||||
await req('POST', '/api/sessions/' + sid + '/bind', { model_id: modelId });
|
||||
toast('已绑定模型 ' + modelId);
|
||||
this.closeModelSwitch();
|
||||
} catch (e) { toast('绑定失败:' + e.message); }
|
||||
// 无论成败都刷新状态(失败多为并发占用,状态可能已变)
|
||||
try { await renderDetail(await req('GET', '/api/sessions/' + state.sessionId)); } catch (_) {}
|
||||
try { await renderDetail(await req('GET', '/api/sessions/' + sid)); } catch (_) {}
|
||||
},
|
||||
async createSession() {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user