From 24b09281f5cdb159055abae1c01f96674d0a1ff1 Mon Sep 17 00:00:00 2001 From: kicer Date: Tue, 1 Sep 2026 12:49:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E4=BB=BB=E5=8A=A1=E5=8F=AF?= =?UTF-8?q?=E9=80=89=E7=A9=BA=E9=97=B2=E6=A8=A1=E5=9E=8B=EF=BC=9B=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=96=87=E4=BB=B6=E9=9D=A2=E6=9D=BF=E7=82=B9=E5=A4=96?= =?UTF-8?q?=E9=83=A8=E8=87=AA=E5=8A=A8=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/engine.js | 17 +++++++++++++---- app/server/public/css/style.css | 6 ++++++ app/server/public/index.html | 5 +++-- app/server/public/js/app.js | 30 +++++++++++++++++++++++++++--- app/server/routes/sessions.js | 3 ++- 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/app/server/engine.js b/app/server/engine.js index 0cf3f7c..f7da323 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -433,16 +433,25 @@ function sessionContextContent(session) { ].join('\n'); } -function createSession(title) { +function createSession(title, preferModelId) { const id = genTaskId(); const dir = taskDirOf(id); fs.mkdirSync(dir, { recursive: true }); db.prepare( "INSERT INTO sessions (id, title, status, phase, model_id, created_at, updated_at) VALUES (?,?,'queued','planning',NULL,?,?)" ).run(id, title || '', now(), now()); - enqueue(id); - dispatchQueued(); - // 放在 dispatchQueued 之后:若能立即绑到空闲模型,上下文里就能带上模型显示名。 + // 指定了模型且它恰好空闲 → 直接绑定,跳过排队;否则回退到 FIFO 队列 + const prefer = preferModelId + ? db.prepare('SELECT * FROM model_pool WHERE id = ? AND is_busy = 0').get(preferModelId) + : null; + if (prefer) { + bindModel(getSession(id), prefer); + emitStatus(id); + } else { + enqueue(id); + dispatchQueued(); + } + // 放在绑定/派发之后:若能立即绑到空闲模型,上下文里就能带上模型显示名。 const session = getSession(id); saveMessage(id, { role: 'user', name: SESSION_CONTEXT_NAME, content: sessionContextContent(session) }); return session; diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index 44e40a2..091ebfd 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -258,6 +258,12 @@ body { padding: 10px 12px; font-size: 15px; margin-bottom: 10px; outline: none; } .modal input:focus { border-color: #2a5299; } +.modal select { + width: 100%; border: 1px solid #dde; border-radius: 8px; + padding: 10px 12px; font-size: 15px; margin-bottom: 10px; outline: none; + background: #fff; color: #334; appearance: auto; +} +.modal select:focus { border-color: #2a5299; } .modal-close-btn { position: absolute; right: 10px; top: 10px; background: none; border: none; cursor: pointer; color: #99a; diff --git a/app/server/public/index.html b/app/server/public/index.html index a9099a1..dcf18a9 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -39,7 +39,7 @@
-
@@ -90,6 +90,7 @@

新建任务会话

+ @@ -113,6 +114,6 @@ - + diff --git a/app/server/public/js/app.js b/app/server/public/js/app.js index 0e03e60..a88d8c5 100644 --- a/app/server/public/js/app.js +++ b/app/server/public/js/app.js @@ -401,12 +401,26 @@ async function loadFiles() { // ---------- 主逻辑 ---------- const ui = { downloadFile(name) { return downloadFile(name); }, - openCreate() { $('create-modal').classList.remove('hidden'); $('new-title').focus(); }, + async openCreate() { + // 每次打开时刷新一次空闲模型列表 + const sel = $('new-model'); + try { + const rows = await req('GET', '/api/models'); + const free = rows.filter(m => !m.is_busy); + sel.innerHTML = free.length + ? '' + free.map(m => + '').join('') + : ''; + } catch (_) { /* 保留默认选项 */ } + $('create-modal').classList.remove('hidden'); + $('new-title').focus(); + }, closeCreate() { $('create-modal').classList.add('hidden'); }, async createSession() { try { const title = $('new-title').value.trim(); - const s = await req('POST', '/api/sessions', { title }); + const model_id = $('new-model') ? $('new-model').value : ''; + const s = await req('POST', '/api/sessions', { title, model_id }); this.closeCreate(); $('new-title').value = ''; await loadSessions(); @@ -472,7 +486,9 @@ const ui = { scrollBottom(); } catch (e) { toast('发送失败:' + e.message); } }, - toggleFiles() { + toggleFiles(ev) { + // 阻断冒泡,避免开启面板的同一次点击被「点外部自动关闭」监听器立刻关掉 + if (ev) ev.stopPropagation(); state.filePanelOpen = !state.filePanelOpen; $('files-panel').classList.toggle('hidden', !state.filePanelOpen); if (state.filePanelOpen) loadFiles(); @@ -513,6 +529,14 @@ const ui = { logout() { location.href = '/logout'; }, }; +// 文件面板展开时,点击面板以外的区域自动关闭 +document.addEventListener('click', e => { + if (!state.filePanelOpen) return; + if ($('files-panel').contains(e.target)) return; + state.filePanelOpen = false; + $('files-panel').classList.add('hidden'); +}); + // ---------- 登录态:显示当前用户;未启用认证(/api/me 404)则隐藏退出按钮 ---------- async function initAuth() { try { diff --git a/app/server/routes/sessions.js b/app/server/routes/sessions.js index 44d851e..c030c94 100644 --- a/app/server/routes/sessions.js +++ b/app/server/routes/sessions.js @@ -47,7 +47,8 @@ function listTaskFiles(dir) { router.post('/', wrap((req, res) => { const title = (req.body && req.body.title || '').trim(); - const session = engine.createSession(title); + const modelId = (req.body && req.body.model_id || '').trim(); + const session = engine.createSession(title, modelId); res.json(session); }));