diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css
index 50edd12..e6e3e2e 100644
--- a/app/server/public/css/style.css
+++ b/app/server/public/css/style.css
@@ -369,9 +369,9 @@ body {
background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px;
box-shadow: 0 1px 4px rgba(30,40,90,0.06);
}
-.model-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
-.model-card-name { font-weight: 600; font-size: 15px; }
-.model-card-state { font-size: 11px; padding: 2px 8px; border-radius: 9px; }
+.model-card-head { display: flex; align-items: baseline; gap: 8px; }
+.model-card-name { font-weight: 600; font-size: 15px; flex-shrink: 0; }
+.model-card-state { font-size: 11px; padding: 2px 8px; border-radius: 9px; flex-shrink: 0; }
.model-card-state.idle { background: #e3f2e6; color: #217a34; }
.model-card-state.busy { background: #fdecea; color: #b3382c; }
/* 配置已加但还没重启进运行池 */
@@ -379,7 +379,34 @@ body {
/* 点模型名打开编辑弹窗 */
.model-card-name { cursor: pointer; }
.model-card-name:active { opacity: 0.55; }
-.model-card-meta { font-size: 12px; color: #888; margin-top: 4px; }
+/* meta(模型 id/会话号)与名字同行,溢出省略 */
+.model-card-meta { font-size: 12px; color: #888; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+
+/* ---- 模型池分组:父级 = 平台名 + 脱敏 Key(余额由 name+key 决定),子级 = 模型;默认折叠 ---- */
+.model-group {
+ background: #fff; border-radius: 12px; margin-bottom: 10px; overflow: hidden;
+ box-shadow: 0 1px 4px rgba(30,40,90,0.06);
+}
+.model-group-head {
+ display: flex; align-items: center; gap: 8px; padding: 12px 14px;
+ cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
+}
+.model-group-head:active { opacity: 0.7; }
+.model-group-caret {
+ width: 15px; height: 15px; flex-shrink: 0;
+ stroke: #7f8db0; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
+ transition: transform 0.15s ease;
+}
+.model-group.open .model-group-caret { transform: rotate(90deg); }
+.model-group-name { font-weight: 600; font-size: 14.5px; }
+.model-group-key {
+ font-size: 11.5px; color: #8a93a6; word-break: break-all;
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
+}
+.model-group-meta { margin-left: auto; flex-shrink: 0; font-size: 12px; color: #888; white-space: nowrap; }
+.model-group-body { padding: 0 10px 10px; border-top: 1px dashed #eef0f5; }
+.model-group-body .model-card { margin: 10px 0 0; background: #fafbfd; border: 1px solid #eef0f5; box-shadow: none; }
+.model-group-empty { font-size: 12px; color: #99a3b8; padding: 12px 4px 2px; text-align: center; }
/* ---- 设置页行 ---- */
/* 设置页顶部用户卡:头像在上,用户名居中,下方等宽双按钮 */
diff --git a/app/server/public/js/models.js b/app/server/public/js/models.js
index d930692..9084455 100644
--- a/app/server/public/js/models.js
+++ b/app/server/public/js/models.js
@@ -3,6 +3,7 @@
// 模型项只有 {id, display_name, vision};id 只需同平台内唯一(内部唯一键 = 平台名/模型id,
// effective.models 的 id 即该键、mid 为原始模型名)。页面 PATCH 用 platforms[i].keys[j].models[k] 嵌套下标定位;
// 新增一律走 append(只动目标数组,脱敏 key 绝不整体回写文件);已有 Key 的 api_key 修改请走配置原文编辑器。
+// 展示层:模型池按「平台名 + 脱敏 Key」分组(余额由二者决定),父级 Key、子级模型,默认折叠。
'use strict';
window.tabModules = window.tabModules || {};
@@ -12,6 +13,7 @@ let cfgModels = []; // 打平后的 effective.models(含 platform_in
let runtimeById = {}; // 运行池状态,按 id 关联
let modelsPendingRestart = false;
let moeIdx = -1; // 当前编辑弹窗对应的打平下标;-1 = 新增
+let expandedGroups = {}; // 模型池分组展开态,key =「pi-ki」;余额由 name+key 决定,分组即 Key 槽位,默认折叠
// api_key 脱敏显示:sk-***1234 样式。后端 GET effective 已脱敏,这里仅兜底(幂等)。
function maskKey(k) {
@@ -32,6 +34,59 @@ function fmtTok(n) {
return v + 'M';
}
+// ---------- 模型池卡片:按「平台 + Key」分组 ----------
+// 余额由 platform.name + key 决定,故父级 = 平台名 · 脱敏 key,子级 = 该 Key 下的模型;默认折叠。
+
+function toggleModelGroup(gk) {
+ const on = !expandedGroups[gk];
+ expandedGroups[gk] = on;
+ const el = $('mgrp-' + gk);
+ if (!el) return;
+ el.classList.toggle('open', on);
+ const body = el.querySelector('.model-group-body');
+ if (body) body.classList.toggle('hidden', !on);
+}
+
+// 单个模型的子卡片;余额是 Key 级概念,统一在分组头显示,模型卡不再重复。
+function modelCardHtml(m) {
+ const run = runtimeById[m.id];
+ // 运行池里没有 = 配置新增但还没重启生效
+ const stateHtml = run
+ ? '' + (run.is_busy ? '占用中' : '空闲') + ''
+ : '待重启';
+ return '
' +
+ '
' +
+ '' + esc(m.display_name || m.mid || m.id) + '' +
+ // 模型 id / 会话号紧跟名字同行,卡片更紧凑
+ '' + esc(m.mid || m.id) +
+ (run && run.is_busy && run.current_session_id ? ' · 会话 ' + esc(run.current_session_id) : '') + '' +
+ stateHtml +
+ '
' +
+ // token 紧凑显示:输入 / 输出
+ '
' + (run ? fmtTok(run.today_prompt) + ' / ' + fmtTok(run.today_completion) : '--') + '
' +
+ '
' + (run ? fmtTok(run.total_prompt) + ' / ' + fmtTok(run.total_completion) : '--') + '
' +
+ '
';
+}
+
+function modelGroupHtml(pi, ki) {
+ const p = cfgPlatforms[pi] || {};
+ const k = (p.keys || [])[ki] || {};
+ const gk = pi + '-' + ki;
+ const models = cfgModels.filter(m => m.platform_index === pi && m.key_index === ki);
+ const open = !!expandedGroups[gk];
+ return '' +
+ '
' +
+ '
' +
+ '
' + esc(p.name || ('平台' + pi)) + '' +
+ '
' + esc(k.api_key ? maskKey(k.api_key) : '无 key') + '' +
+ '
余额 -- · ' + models.length + ' 模型' +
+ '
' +
+ '
' +
+ (models.length ? models.map(modelCardHtml).join('') : '
该 Key 下暂无模型
') +
+ '
' +
+ '
';
+}
+
async function loadModelCards() {
const el = $('model-cards');
if (!el) return;
@@ -45,28 +100,14 @@ async function loadModelCards() {
el.innerHTML = '尚未配置模型,点右上角 + 添加。
';
return;
}
- el.innerHTML = cfgModels.map(m => {
- const run = runtimeById[m.id];
- // 运行池里没有 = 配置新增但还没重启生效
- const stateHtml = run
- ? '' + (run.is_busy ? '占用中' : '空闲') + ''
- : '待重启';
- return '' +
- '
' +
- '' + esc(m.display_name || m.mid || m.id) + '' +
- stateHtml +
- '
' +
- '
' + esc(m.mid || m.id) + ' · 平台 ' + esc(m.platform || '') +
- (run && run.is_busy && run.current_session_id ? ' · 会话 ' + esc(run.current_session_id) : '') + '
' +
- '
--
' +
- // token 紧凑显示:输入 / 输出
- '
' + (run ? fmtTok(run.today_prompt) + ' / ' + fmtTok(run.today_completion) : '--') + '
' +
- '
' + (run ? fmtTok(run.total_prompt) + ' / ' + fmtTok(run.total_completion) : '--') + '
' +
- '
';
- }).join('') +
+ let html = '';
+ cfgPlatforms.forEach((p, pi) => (p.keys || []).forEach((k, ki) => {
+ html += modelGroupHtml(pi, ki);
+ }));
+ el.innerHTML = html +
(modelsPendingRestart
? '已写入 config.yml,到「设置」页重启服务后生效。
'
- : 'token 格式为「输入 / 输出」;余额需对接模型提供方 API,暂未实现;改动写入 config.yml,重启服务后生效。
');
+ : 'token 格式为「输入 / 输出」;余额按平台名+Key 统计,需对接模型提供方 API,暂未实现;改动写入 config.yml,重启服务后生效。
');
} catch (e) {
el.innerHTML = '加载失败:' + esc(e.message) + '
';
}
@@ -213,6 +254,7 @@ window.modelsUI = {
save: saveModelEditor,
del: delModelFromModal,
onTargetChange: onTargetChange,
+ toggleGroup: toggleModelGroup,
};
tabModules.models = {
diff --git a/app/server/public/js/tasks.js b/app/server/public/js/tasks.js
index 83acf78..8af9e85 100644
--- a/app/server/public/js/tasks.js
+++ b/app/server/public/js/tasks.js
@@ -396,8 +396,10 @@ function msgNode(m, cardMap) {
const gray = state.status === 'queued' ? ' gray' : '';
let inner = 'AI' +
(m.model_tag ? ' · ' + esc(m.model_tag) : '') + '
';
- if (m.content) inner += '' + md(m.content) + '
';
- inner += '' + fmtTime(m.created_at) + copyBtnHtml(m.content) + '
';
+ // 纯工具调用的应答为空或仅空白:不渲染空气泡,只保留 AI 头与时间行
+ const hasText = !!(m.content && m.content.trim());
+ if (hasText) inner += '' + md(m.content) + '
';
+ inner += '' + fmtTime(m.created_at) + (hasText ? copyBtnHtml(m.content) : '') + '
';
wrap.innerHTML = inner;
return wrap;
}
@@ -547,36 +549,42 @@ function connectStream() {
es.addEventListener('assistant_delta', ev => {
const d = JSON.parse(ev.data);
removePendingBubble();
+ state.streamText += d.text;
if (!state.streamEl) {
+ // 纯工具调用常见只有空白增量:先不产出空气泡,等有真实文本再建
+ if (!state.streamText.trim()) return;
const wrap = document.createElement('div');
wrap.className = 'msg other';
wrap.innerHTML = 'AI
' +
'';
state.streamEl = wrap.querySelector('.msg-bubble');
- state.streamText = '';
- $('messages').appendChild(wrap);
- }
- state.streamText += d.text;
- state.streamEl.textContent = state.streamText;
- state.streaming = true;
- maybeAutoScroll();
- updateScrollBottomBtn();
+ state.streamText = d.text; // 新一轮首个可见增量:丢弃可能的旧轮残留文本
+ $('messages').appendChild(wrap);
+ }
+ state.streamEl.textContent = state.streamText;
+ state.streaming = true;
+ maybeAutoScroll();
+ updateScrollBottomBtn();
});
es.addEventListener('assistant_message', ev => {
const d = JSON.parse(ev.data);
removePendingBubble();
+ const hasText = !!(d.content && d.content.trim());
if (state.streamEl) {
const bubble = state.streamEl;
- bubble.innerHTML = md(d.content || '');
state.streamEl = null;
state.streamText = '';
- if (d.content) {
+ if (hasText) {
+ bubble.innerHTML = md(d.content);
const timeEl = document.createElement('div');
timeEl.className = 'msg-time';
timeEl.innerHTML = fmtTime(Date.now()) + copyBtnHtml(d.content);
bubble.parentElement.appendChild(timeEl);
+ } else {
+ // 终稿为空/仅空白(纯工具调用):收走已建的气泡,保留 AI 头行(与历史渲染一致)
+ bubble.remove();
}
- } else if (d.content) {
+ } else if (hasText) {
const box = $('messages');
const wrap = document.createElement('div');
wrap.className = 'msg other';