From 5732bf5dc2c7ec8bb4199dd62a2fe8525a344fee Mon Sep 17 00:00:00 2001 From: qyh15 Date: Sat, 7 Nov 2026 20:04:27 +0800 Subject: [PATCH] =?UTF-8?q?0.3.3=EF=BC=9A=E6=89=93=E5=BC=80=E4=B8=BB?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=94=B9=E4=B8=BA=E7=9C=9F=E7=9A=84=E6=96=B0?= =?UTF-8?q?=E5=BC=80=E4=B8=80=E4=B8=AA=E6=9C=9D=E5=A0=82=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E5=B9=B6=E5=88=87=E8=BF=87=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- package.json | 2 +- panel/lib/client.js | 57 ++++++++++++++++++++++++++------------- panel/package.json | 2 +- panel/test/client.test.js | 34 +++++++++++++++++++++++ 5 files changed, 75 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 705d096..3fb87e2 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ const PRESET_ID = 'sansheng-liubu' -export const POLICY_VERSION = '0.3.2' +export const POLICY_VERSION = '0.3.3' export const DEFAULT_ROUTES = Object.freeze({ lead: Object.freeze({ provider: 'xiaomi', model: 'mimo-v2.6-pro', reasoningEffort: 'high' }), diff --git a/package.json b/package.json index 0d7b15f..c207f1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-sansheng-liubu-mode", - "version": "0.3.2", + "version": "0.3.3", "private": true, "description": "上朝:丞相统筹的三省六部多 Agent 模式", "type": "module", diff --git a/panel/lib/client.js b/panel/lib/client.js index 629af68..da714bd 100644 --- a/panel/lib/client.js +++ b/panel/lib/client.js @@ -544,8 +544,20 @@ window.__ModuleLoader__.load({ }; const hasAnySession = Array.isArray(sessions.ids) ? sessions.ids.length > 0 : Object.keys(sessions.byId || {}).length > 0; + /** 打开主对话:真的开一个新对话,而不是盲目跳到别处。 */ const openMainConversation = () => { - const result = host.openConversation(); + setBusy(true); + Promise.resolve(host.openConversation()).then((result) => { + setBusy(false); + if (result && result.ok) setNotice({ kind: "ok", text: result.text || "已开启新对话" }); + else setNotice({ kind: "error", text: (result && result.error) || "开启对话失败" }); + }, (error) => { + setBusy(false); + setNotice({ kind: "error", text: "开启对话失败:" + String((error && error.message) || error) }); + }); + }; + const focusLeadConversation = () => { + const result = host.focusConversation(); if (result && result.ok === false) setNotice({ kind: "error", text: result.error }); }; @@ -568,7 +580,7 @@ window.__ModuleLoader__.load({ h("span", { className: "sl-spacer" }), h("button", { type: "button", - onClick: openMainConversation, + onClick: focusLeadConversation, children: "回到丞相对话", }), ]), @@ -576,7 +588,7 @@ window.__ModuleLoader__.load({ h("div", { className: "sl-left" }, [ h("div", { className: "sl-conv" }, [ h("h2", { children: "主对话" }), - h("p", { children: "对话本体由 DSH 的会话面板承载,这里保留朝堂视角:左侧查看丞相最近进展,需要完整上下文时点“回到丞相对话”。" }), + h("p", { children: "对话本体由 DSH 的会话面板承载,点「打开主对话」会新开一个朝堂会话并把中央切过去,直接说话即可。" }), inboxText ? h("div", { className: "sl-quote", "data-last-user": "true", children: inboxText }) : h("div", { className: "sl-quote", children: hasAnySession ? (team === undefined ? "还没有朝班。先在对话里让丞相组建三省六部,成员就会出现在右侧朝堂图上。" : "丞相暂无新的发言。") : "当前实例还没有会话,暂时无法组建朝班。" }), @@ -949,24 +961,22 @@ window.__ModuleLoader__.load({ if (!sessionId) return ""; try { return recentOf(sessionId); } catch (error) { return ""; } }, + /** 点「打开主对话」=开一个新对话:建好朝堂会话后把中央切到它,用户可以直接说话。 */ openConversation() { + return this.openCourtSession({ formation: false }); + }, + /** 只跳到已有对话(不新建)。 */ + focusConversation() { const target = currentSession(); - if (!target) { - return { - ok: false, - error: "当前实例还没有任何会话,没有主对话可打开;「打开主对话」本来只是切回宿主自带的对话视图。", - }; - } - try { - ctx.uiWorkspace.openSession(target); - } catch (error) { - return { ok: false, error: "打开会话失败:" + String(error && error.message || error) }; + if (!target) return { ok: false, stage: "focus", errorCode: "no-session", error: "当前还没有任何会话,可以先点「打开主对话」开一个。" }; + try { ctx.uiWorkspace.openSession(target); } catch (error) { + return { ok: false, stage: "focus", errorCode: "open-failed", error: "打开会话失败:" + String((error && error.message) || error) }; } const service = layoutService(); if (service && typeof service.selectPanel === "function") { try { service.selectPanel(null); } catch (error) { /* 忽略 */ } } - return { ok: true }; + return { ok: true, stage: "focus", sessionId: target }; }, openSession(sessionId) { let summary; @@ -1053,7 +1063,8 @@ window.__ModuleLoader__.load({ /** 新开一个独立朝堂会话:绝不把旨意或组建指令写进用户当前正在聊的对话。 */ /** 新开一个独立朝堂会话:绝不把旨意或组建指令写进用户当前正在聊的对话。 */ - openCourtSession() { + openCourtSession(options) { + const withFormation = !options || options.formation !== false; if (courtState.pending) return Promise.resolve({ ok: false, stage: "create", errorCode: "busy", error: "正在创建朝堂会话,请稍候再点" }); const snapshot = sessionsStore && typeof sessionsStore.getSnapshot === "function" ? sessionsStore.getSnapshot() : undefined; const before = new Set(Object.keys((snapshot && snapshot.byId) || {})); @@ -1098,10 +1109,18 @@ window.__ModuleLoader__.load({ console.warn("[三省六部] 新会话未创建", { workspaceId: workspaceId, beforeCount: beforeCount }); return settle({ ok: false, stage: "create", errorCode: "create-timeout", error: "宿主没有创建出新会话(工作区:" + String(workspaceId || "未识别") + ",原有会话 " + beforeCount + " 个)。可用左侧「新会话」手动建一个,并在顶部选「上朝」预设。" }); } + selectedSessionId = sessionId; + try { ctx.uiWorkspace.openSession(sessionId); } catch (error) { /* 忽略 */ } + const service = layoutService(); + if (service && typeof service.selectPanel === "function") { + try { service.selectPanel(null); } catch (error) { /* 忽略 */ } + } + const shortId = sessionId.slice(0, 8); + if (!withFormation) { + return settle({ ok: true, stage: "created", sessionId: sessionId, text: "已开启新对话(" + shortId + "),可以直接说话" }); + } return deliverPrompt(sessionId, FORMATION_PROMPT).then((sent) => { - selectedSessionId = sessionId; - try { ctx.uiWorkspace.openSession(sessionId); } catch (error) { /* 忽略 */ } - const short = sessionId.slice(0, 8); + const short = shortId; if (!sent.ok) { return settle({ ok: false, stage: "deliver", sessionId: sessionId, errorCode: sent.errorCode, error: "已新开朝堂会话(" + short + "),但组建指令没送达:" + sent.error }); } @@ -1336,7 +1355,7 @@ window.__ModuleLoader__.load({ }, (props) => h("div", { className: "sl-main-shell", "data-sansheng-main": "1" }, [ h("div", { key: "head", className: "sl-main-head" }, [ h("strong", { key: "title", children: "三省六部 · 朝堂" }), - h("span", { key: "hint", className: "sl-main-head-hint", children: "v0.3.2" }), + h("span", { key: "hint", className: "sl-main-head-hint", children: "v0.3.3" }), h("span", { key: "spacer", className: "sl-main-head-spacer" }), h(DockButton, { key: "dock", host }), ]), diff --git a/panel/package.json b/panel/package.json index 990d850..8692219 100644 --- a/panel/package.json +++ b/panel/package.json @@ -1,6 +1,6 @@ { "name": "dsh-sansheng-liubu-panel", - "version": "0.3.2", + "version": "0.3.3", "private": true, "description": "三省六部 Agent 面板:在 DSH Web GUI 中常驻显示并切换团队 Agent", "type": "module", diff --git a/panel/test/client.test.js b/panel/test/client.test.js index 1317d19..a4886f8 100644 --- a/panel/test/client.test.js +++ b/panel/test/client.test.js @@ -423,3 +423,37 @@ test('refuses a second court session request while the first one is pending', as assert.equal(settled.ok, false) assert.equal(settled.errorCode, 'create-timeout') }) + +test('openConversation starts a usable conversation with the 上朝 preset and sends nothing', async () => { + const { exports } = loadPlugin() + const { ctx, prompts, addSession, setStartSession, selections } = mockContext() + const started = [] + setStartSession((workspaceId, options) => { started.push({ workspaceId, options }); addSession('court-2', workspaceId) }) + const host = exports.createHost(ctx) + const result = await host.openConversation() + assert.equal(result.ok, true, JSON.stringify(result)) + assert.equal(result.stage, 'created') + assert.equal(result.sessionId, 'court-2') + assert.equal(started.length, 1) + assert.equal(started[0].options.agentPreset, 'sansheng-liubu', '新对话带上朝预设') + assert.equal(prompts.length, 0, '只开对话,不自动发组建指令') + assert.ok(selections.indexOf('court-2') >= 0, '把中央切到新会话') +}) + +test('focusConversation jumps to the existing session and reports a missing one', () => { + const { exports } = loadPlugin() + const { ctx, selections } = mockContext() + const host = exports.createHost(ctx) + const jumped = host.focusConversation() + assert.equal(jumped.ok, true) + assert.equal(jumped.sessionId, 'lead-1') + assert.ok(selections.indexOf('lead-1') >= 0) + + const empty = mockContext() + empty.ctx.sessions.list = { getSnapshot: () => ({ ids: [], byId: {}, projectionsBySession: {} }) } + empty.ctx.uiWorkspace.selection = { getSnapshot: () => ({}), subscribe: () => () => {} } + const other = exports.createHost(empty.ctx) + const miss = other.focusConversation() + assert.equal(miss.ok, false) + assert.equal(miss.errorCode, 'no-session') +})