diff --git a/CHANGELOG.md b/CHANGELOG.md index e80a6fe..0a2ce0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ # Changelog -> 版本号以 `package.json` 为准(当前 0.7.2)。更早的 0.6.x 条目沿用旧编号,保留作历史。 +> 版本号以 `package.json` 为准(当前 0.8.0)。更早的 0.6.x 条目沿用旧编号,保留作历史。 +## 0.8.0 — 换完即存,不再惊动智能体 + +- 模型和推理等级改成**选完就保存**,去掉「保存模型设置」按钮;脚注直接显示「自动保存 · 当前:…」。 +- 保存改走宿主 `commands/execute` 直接执行 `/dept-model`:不投递提示词、不在对话里留消息、不触发模型轮次,丞相不会因此进入大段推理。 +- 宿主没有这个接口或指令尚未加载时,只在前端报错(「宿主没有执行这条指令」),不会退化成一条普通消息发给智能体。 +- 测试新增两项:确认改模型时**不**调用 `session.prompt`、以及缺接口时的报错;全量 50 项通过。 ## 0.7.2 — 三省与六部之间松一点 - 三省(`.sl-grid-3`)与六部(`.sl-grid-6`)的卡片间距从 8–10px 统一到 12px,三个容器断点(含 ≤620px 的两列布局)一起调,窄侧栏下也不再挤在一起。 diff --git a/package.json b/package.json index 77f0b1d..c06710f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-sansheng-liubu-mode", - "version": "0.7.2", + "version": "0.8.0", "private": true, "description": "上朝:丞相统筹的三省六部多 Agent 模式", "type": "module", diff --git a/panel/lib/client.js b/panel/lib/client.js index b440274..40b5790 100644 --- a/panel/lib/client.js +++ b/panel/lib/client.js @@ -721,17 +721,17 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s const currentModelValue = catalog.current ? catalog.current.provider + "/" + catalog.current.model : ""; const currentEffortValue = (catalog.current && catalog.current.reasoningEffort) || ""; const modelDirty = draftModel !== currentModelValue || draftEffort !== currentEffortValue; - const canSaveModel = Boolean(chosenOption && seat && modelDirty && !busy); - const applyModel = () => { - if (!chosenOption || !seat) return; + const applySelection = (option, effort) => { + if (!option || !seat) return; const plan = modelSwitchPlan(catalog.current, { - provider: chosenOption.provider, - model: chosenOption.model, - reasoningEffort: draftEffort || undefined, + provider: option.provider, + model: option.model, + reasoningEffort: effort || undefined, }, catalog.subagent || !seat.id); - if (!plan.ok) { setNotice({ kind: "error", text: plan.reason }); return; } + if (!plan.ok) return; setBusy(true); + setNotice(null); const request = plan.via === "command" ? host.routeModel(seat.role, plan.payload) : host.selectModel(seat.id, plan.payload); @@ -739,14 +739,12 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s setBusy(false); if (result.ok) { if (plan.via === "command") writeSeatRoute(seat.role, plan.payload); - setNotice({ kind: "ok", text: (plan.via === "command" ? "已把 " + seat.label + " 固定为 " : "已切换到 ") + chosenOption.label }); setCatalog((prev) => ({ ...prev, current: plan.payload, fixed: plan.via === "command" ? true : prev.fixed })); } else { setNotice({ kind: "error", text: result.error }); } }); }; - const activeChildId = activeAddress && activeAddress.childSessionId ? activeAddress.childSessionId : focusedSessionId !== leadSessionId ? focusedSessionId : undefined; @@ -941,10 +939,13 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s disabled: catalog.status === "loading" || busy, "aria-label": "部门模型", onChange: (event) => { - setDraftModel(event.target.value); - const option = catalog.options.find((entry) => entry.rowId === event.target.value); - setDraftEffort(option && option.defaultEffort ? option.defaultEffort : ""); - }, + const value = event.target.value; + const option = catalog.options.find((entry) => entry.rowId === value); + const effort = option && option.defaultEffort ? option.defaultEffort : ""; + setDraftModel(value); + setDraftEffort(effort); + applySelection(option, effort); + }, children: [ h("option", { value: "", children: catalog.status === "loading" ? "读取中…" : "选择模型" }), ...catalog.options.map((option) => h("option", { key: option.rowId, value: option.rowId, children: option.label })), @@ -957,7 +958,11 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s value: draftEffort, disabled: catalog.status === "loading" || busy || !chosenOption, "aria-label": "部门推理等级", - onChange: (event) => setDraftEffort(event.target.value), + onChange: (event) => { + const value = event.target.value; + setDraftEffort(value); + applySelection(chosenOption, value); + }, children: [ h("option", { value: "", children: "默认" }), ...(chosenOption ? chosenOption.efforts : []).map((effort) => h("option", { key: effort.id, value: effort.id, children: effort.name })), @@ -966,22 +971,20 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s ]), ]), h("div", { className: "sl-model-foot" }, [ - h("button", { - type: "button", - className: "sl-btn", - disabled: !canSaveModel, - onClick: applyModel, - children: busy ? "保存中…" : "保存模型设置", - }), - h("small", { className: modelDirty ? "is-dirty" : "", children: modelDirty - ? "有未保存的更改" - : catalog.fixed - ? "该部门固定使用此模型" - : !seat.present - ? "该部门还没召见;保存后在召见时生效" - : catalog.inherited - ? (catalog.unresolved ? "该部门会话未在本页打开,选好保存后直接生效" : "当前:跟随默认(" + modelLabel(catalog.current) + ")") - : "当前:" + (catalog.current ? modelLabel(catalog.current) : "未设置") }), + h("small", { + className: notice && notice.kind === "error" ? "is-dirty" : "", + children: busy || modelDirty + ? "自动保存中…" + : notice && notice.kind === "error" + ? "保存失败,换一次再试" + : catalog.fixed + ? "自动保存 · 该部门固定使用此模型" + : !seat.present + ? "自动保存 · 召见时按此模型开工" + : catalog.inherited + ? "自动保存 · 当前跟随默认(" + modelLabel(catalog.current) + ")" + : "自动保存 · 当前:" + (catalog.current ? modelLabel(catalog.current) : "未设置"), + }), ]), ]), catalog.error ? h("div", { className: "sl-error", children: catalog.error }) : null, @@ -1225,7 +1228,6 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s } return { catalog }; }; - /** 会话 RPC 面:改模型只认 sessionId,不需要该会话在本页登记。 */ const remoteSession = () => { try { @@ -1235,6 +1237,15 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s } catch (error) { return undefined; } }; + /** 指令 RPC 面:直接执行斜杠指令,不经过模型,也不进对话。 */ + const remoteCommands = () => { + try { + const remote = ctx.remote; + const commands = remote && remote.commands; + return commands && typeof commands.execute === "function" ? commands : undefined; + } catch (error) { return undefined; } + }; + const sidebarNav = () => { const candidates = []; try { if (typeof ctx.get === "function") candidates.push(ctx.get("sidebarRight")); } catch (error) { /* 忽略 */ } @@ -1463,15 +1474,22 @@ button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--s }, (error) => ({ ok: false, error: String((error && error.message) || error) })); }, /** 子会话不能直接改模型,改由丞相会话把指令下发给模式插件。 */ + /** 子会话不能直接改模型:用 commands/execute 直接跑指令,全程不碰模型。 */ routeModel(role, payload) { + const commands = remoteCommands(); + if (!commands) return Promise.resolve({ ok: false, error: "当前宿主没有直接执行指令的接口(remote.commands.execute)" }); const lead = currentSession(); if (!lead) return Promise.resolve({ ok: false, error: "没有可下发指令的丞相会话" }); - const text = "/" + DEPT_MODEL_COMMAND + " " + role + " " + payload.provider + " " + payload.model + + const line = "/" + DEPT_MODEL_COMMAND + " " + role + " " + payload.provider + " " + payload.model + (payload.reasoningEffort ? " " + payload.reasoningEffort : ""); - return deliverPrompt(lead, text).then((result) => { - if (result.ok) return { ok: true, text: text }; - return { ok: false, error: result.error || "下发部门模型失败" }; - }); + return Promise.resolve() + .then(() => commands.execute(lead, line, [])) + .then((result) => { + const outcome = result && result.result; + if (outcome && outcome.kind === "success") return { ok: true, text: line }; + const detail = outcome && outcome.kind === "error" ? outcome.text : undefined; + return { ok: false, error: detail || "宿主没有执行这条指令(可能还没有重启)" }; + }, (error) => ({ ok: false, error: String((error && error.message) || error) })); }, selectPreset(sessionId, presetId) { const remote = presetsRemote(); diff --git a/panel/package.json b/panel/package.json index 1911ca7..6a9518f 100644 --- a/panel/package.json +++ b/panel/package.json @@ -1,6 +1,6 @@ { "name": "dsh-sansheng-liubu-panel", - "version": "0.7.2", + "version": "0.8.0", "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 c4bc2d6..7eb045c 100644 --- a/panel/test/client.test.js +++ b/panel/test/client.test.js @@ -138,6 +138,7 @@ function mockContext(prompts = []) { const registrations = [] remote: { agentPresets: { list: async () => ({ ok: true, value: { presets: [] } }), select: async () => ({ ok: true }) }, session: { selectModel: async () => ({ ok: true }) }, + commands: { execute: async () => ({ commandId: 'cmd-1', result: { kind: 'success' } }) }, }, layout: { selectPanel(id) { selections.push(id) } }, get() { return undefined }, @@ -931,8 +932,9 @@ test('正常路径给出全局清单与该会话自己的当前选择', async () assert.deepEqual(result.current, { provider: 'p', model: 'm' }) }) -test('部门是子会话时,改模型改由丞相会话下发 /dept-model', async () => { +test('部门是子会话时,改模型靠宿主直接执行指令,不投递给模型', async () => { const prompts = [] + const executed = [] const { host } = catalogHost({ sessions: { list: () => [], @@ -942,12 +944,36 @@ test('部门是子会话时,改模型改由丞相会话下发 /dept-model', as subagentAddress: () => ({ parentSessionId: 'lead-1', childSessionId: 'gongbu-1' }), refreshProjections: async () => {}, }, + remote: { + agentPresets: { list: async () => ({ ok: true, value: { presets: [] } }), select: async () => ({ ok: true }) }, + session: { selectModel: async () => ({ ok: true }) }, + commands: { + execute: async (agentId, line, attachments) => { + executed.push({ agentId, line, attachments }) + return { commandId: 'cmd-1', result: { kind: 'success', text: '好' } } + }, + }, + }, }) const result = await host.routeModel('gongbu', { provider: 'deepseek', model: 'deepseek-chat', reasoningEffort: 'high' }) assert.equal(result.ok, true) - assert.equal(prompts.length, 1) - assert.equal(prompts[0].sessionId, 'lead-1', '指令投给丞相会话') - assert.equal(prompts[0].parts[0].text, '/dept-model gongbu deepseek deepseek-chat high') + assert.equal(prompts.length, 0, '不能向会话投递提示词,否则会触发模型思考') + assert.equal(executed.length, 1) + assert.equal(executed[0].agentId, 'lead-1') + assert.equal(executed[0].line, '/dept-model gongbu deepseek deepseek-chat high') + assert.equal(executed[0].attachments.length, 0) +}) + +test('宿主没有执行指令的接口时,报错要指明原因', async () => { + const { host } = catalogHost({ + remote: { + agentPresets: { list: async () => ({ ok: true, value: { presets: [] } }), select: async () => ({ ok: true }) }, + session: { selectModel: async () => ({ ok: true }) }, + }, + }) + const result = await host.routeModel('gongbu', { provider: 'deepseek', model: 'deepseek-chat' }) + assert.equal(result.ok, false) + assert.match(result.error, /remote.commands.execute/) }) test('子会话的固定路由从面板记录里读出来当「当前模型」', async () => { diff --git a/scripts/preview.mjs b/scripts/preview.mjs index a01b68c..62ea75d 100644 --- a/scripts/preview.mjs +++ b/scripts/preview.mjs @@ -819,6 +819,9 @@ function createDemoContext(options = {}) { session: { selectModel: async () => ({ ok: true }), }, + commands: { + execute: async (_agentId, line) => ({ commandId: 'preview-command', result: { kind: 'success', text: line } }), + }, }, get: () => undefined, layout: { selectPanel: () => {} },