From 963ec5821a17d8050d1d5b8bdc3b5e9b4fcba32f Mon Sep 17 00:00:00 2001 From: qyh15 Date: Tue, 10 Nov 2026 12:19:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(panel):=20=E6=94=B9=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=97=B6=E4=BC=98=E5=85=88=E7=A9=BA=E9=97=B2=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E5=B9=B6=E5=AF=B9=E5=AE=BF=E4=B8=BB=E8=B0=83=E7=94=A8=E5=8A=A0?= =?UTF-8?q?=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- panel/lib/client.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/panel/lib/client.js b/panel/lib/client.js index 120e890..ebd170f 100644 --- a/panel/lib/client.js +++ b/panel/lib/client.js @@ -1286,16 +1286,25 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s return session && typeof session.selectModel === "function" ? session : undefined; }; - /** 改模型时按这个顺序找执行者:部门自己 > 其它会话 > 丞相(只当执行上下文,不投递消息)。 */ + /** 改模型时按这个顺序找执行者:部门自己 > 空闲会话 > 其它会话 > 丞相(只当执行上下文,不投递消息)。 */ const routeCandidates = (preferredSessionId) => { const lead = currentSession(); - const list = []; - if (preferredSessionId) list.push(preferredSessionId); + const busy = []; + const idle = []; try { const snapshot = sessions.list && typeof sessions.list.getSnapshot === "function" ? sessions.list.getSnapshot() : undefined; const ids = (snapshot && snapshot.ids) || []; - for (const id of ids) if (id !== preferredSessionId && id !== lead) list.push(id); + const byId = (snapshot && snapshot.byId) || {}; + for (const id of ids) { + if (id === preferredSessionId || id === lead) continue; + const running = Boolean(byId[id] && byId[id].running); + (running ? busy : idle).push(id); + } } catch (error) { /* 忽略 */ } + const list = []; + if (preferredSessionId) list.push(preferredSessionId); + for (const id of idle) list.push(id); + for (const id of busy) list.push(id); if (lead && list.indexOf(lead) < 0) list.push(lead); return list; }; @@ -1564,9 +1573,11 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s const attempt = (index, lastError) => { if (index >= candidates.length) return Promise.resolve({ ok: false, error: lastError || "没有可执行这条指令的会话" }); const agent = candidates[index]; - return Promise.resolve() - .then(() => commands.execute(agent, line, [])) + // 宿主可能在忙(会话正在跑一轮)时把指令排进队列而不返回,界面就会永远停在「自动保存中…」。 + const call = withDeadline(Promise.resolve().then(() => commands.execute(agent, line, [])), 3000, () => TIMED_OUT); + return call .then((result) => { + if (result === TIMED_OUT) return attempt(index + 1, "宿主正忙,没在 3 秒内回应(模型没改,稍后再试)"); if (result && result.ok === false) { const failure = result.error; const detail = failure @@ -1713,6 +1724,7 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s const EMPTY_SESSIONS = { byId: {}, projectionsBySession: {}, ids: [], phase: "ready" }; + const TIMED_OUT = Symbol("timeout"); /** 给可能永远不 settle 的宿主 Promise 加超时,超时后走 fallback,避免界面卡在「读取中」。 */ function withDeadline(promise, ms, fallback) { return new Promise((resolve) => {