0.3.3:打开主对话改为真的新开一个朝堂对话并切过去
This commit is contained in:
parent
f0834f573d
commit
5732bf5dc2
2
index.js
2
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' }),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "dsh-sansheng-liubu-mode",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"private": true,
|
||||
"description": "上朝:丞相统筹的三省六部多 Agent 模式",
|
||||
"type": "module",
|
||||
|
|
|
|||
|
|
@ -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 }),
|
||||
]),
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue