diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index 984e1b6..f7d126d 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -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 控制展开/折叠,不用遮罩); diff --git a/app/server/public/index.html b/app/server/public/index.html index eba4e4e..f2a0965 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -292,12 +292,17 @@ @@ -1056,20 +1061,78 @@ async function openModelSwitch() { if (!state.sessionId) return; const list = $('bind-model-list'); + const footer = $('bind-model-footer'); list.innerHTML = '
加载中…
'; $('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 = '
还没有配置模型。
'; + footer.textContent = ''; return; } - list.innerHTML = rows.map(m => m.is_busy - ? '' - : '').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 '
' + + '
' + + '
' + + '
' + esc(m.display_name || m.mid || m.id) + '
' + + '
' + + (m.vision ? 'Vision' : '') + + 'Thinking' + + '
' + + '
' + + '
'; + }).join(''); + return '
' + + '
' + + '' + + '' + esc(grp.platName) + '' + + '' + grp.keyCount + ' key' + (grp.keyCount > 1 ? 's' : '') + '' + + '
' + + itemHtml + + '
'; + }).join(''); + footer.textContent = '共 ' + totalAvailable + ' / ' + totalAll + ' 个模型可用'; } catch (e) { list.innerHTML = '
读取模型列表失败:' + e.message + '
'; + footer.textContent = ''; } } function closeModelSwitch() { $('bind-model-modal').classList.add('hidden'); } diff --git a/app/server/public/js/tasks.js b/app/server/public/js/tasks.js index 099df0c..91a605b 100644 --- a/app/server/public/js/tasks.js +++ b/app/server/public/js/tasks.js @@ -771,31 +771,82 @@ const ui = { async openModelSwitch() { if (!state.sessionId) return; const list = $('bind-model-list'); + const footer = $('bind-model-footer'); list.innerHTML = '
加载中…
'; $('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 = '
还没有配置模型。
'; + footer && (footer.textContent = ''); return; } - list.innerHTML = rows.map(m => m.is_busy - ? '' - : '').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 '
' + + '
' + + '
' + + '
' + esc(m.display_name || m.mid || m.id) + '
' + + '
' + + (m.vision ? 'Vision' : '') + + 'Thinking' + + '
' + + '
' + + '
'; + }).join(''); + return '
' + + '
' + + '' + + '' + esc(grp.platName) + '' + + '' + grp.keyCount + ' key' + (grp.keyCount > 1 ? 's' : '') + '' + + '
' + + itemHtml + + '
'; + }).join(''); + footer && (footer.textContent = '共 ' + totalAvailable + ' / ' + totalAll + ' 个模型可用'); } catch (e) { list.innerHTML = '
读取模型列表失败:' + e.message + '
'; + 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 {