0.3.5:预设/模型目录读取加 6 秒超时与重试,避免界面卡在读取中

This commit is contained in:
qyh15 2026-11-07 20:39:11 +08:00
parent a44cf39b4a
commit a7d47d5d84
4 changed files with 62 additions and 8 deletions

View File

@ -1,5 +1,5 @@
const PRESET_ID = 'sansheng-liubu'
export const POLICY_VERSION = '0.3.4'
export const POLICY_VERSION = '0.3.5'
/**
* 默认不强制任何 provider/model:宿主未必注册了这些适配器,强行指定会让整轮请求

View File

@ -1,6 +1,6 @@
{
"name": "dsh-sansheng-liubu-mode",
"version": "0.3.4",
"version": "0.3.5",
"private": true,
"description": "上朝:丞相统筹的三省六部多 Agent 模式",
"type": "module",

View File

@ -447,6 +447,7 @@ window.__ModuleLoader__.load({
const [notice, setNotice] = React.useState(null);
const [busy, setBusy] = React.useState(false);
const [decree, setDecree] = React.useState("");
const [catalogRetry, setCatalogRetry] = React.useState(0);
const targetId = seat && seat.id ? seat.id : seat && seat.role === "lead" ? leadSessionId : undefined;
@ -477,7 +478,7 @@ window.__ModuleLoader__.load({
if (alive) setCatalog({ status: "error", options: [], error: String(error && error.message || error), current: undefined, subagent: false });
});
return () => { alive = false; };
}, [targetId]);
}, [targetId, catalogRetry]);
const presetForSeat = seat && seat.id && sessions.byId[seat.id] && sessions.byId[seat.id].projectionValues
? sessions.byId[seat.id].projectionValues.agentPreset
@ -672,6 +673,12 @@ window.__ModuleLoader__.load({
}),
]),
presets.error ? h("div", { className: "sl-error", children: presets.error }) : null,
presets.error ? h("button", {
type: "button",
className: "sl-btn",
onClick: () => setPresets({ status: "idle", options: [], error: null }),
children: "重试读取预设",
}) : null,
]) : null,
seat && seat.present ? h("div", { className: "sl-field" }, [
h("label", { children: "联动模型 · 推理等级" }),
@ -709,6 +716,12 @@ window.__ModuleLoader__.load({
h("span", { className: "sl-hint", children: catalog.subagent ? "子会话沿用丞相模型" : "当前:" + (catalog.current ? modelLabel(catalog.current) : "未设置") }),
]),
catalog.error ? h("div", { className: "sl-error", children: catalog.error }) : null,
catalog.error ? h("button", {
type: "button",
className: "sl-btn",
onClick: () => setCatalogRetry((value) => value + 1),
children: "重试读取模型",
}) : null,
]) : null,
seat && seat.present ? h("div", { className: "sl-field" }, [
h("label", { children: "下旨给" + (seat ? seat.label : "") }),
@ -1001,18 +1014,35 @@ window.__ModuleLoader__.load({
loadPresets() {
const remote = presetsRemote();
if (!remote) return Promise.resolve({ options: [], error: "当前宿主未提供 Agent 预设接口" });
return Promise.resolve()
const chain = Promise.resolve()
.then(() => remote.list())
.then((result) => {
if (!result || !result.ok) return { options: [], error: result && result.error ? result.error.message : "读取预设失败" };
const presets = result.value && Array.isArray(result.value.presets) ? result.value.presets : [];
return { options: presets.map((preset) => ({ id: preset.id, name: preset.name || preset.id })), error: null };
}, (error) => ({ options: [], error: "读取预设失败:" + String(error && error.message || error) }));
return withDeadline(chain, 6000, (error) => ({
options: [],
error: error ? "读取预设失败:" + String(error && error.message || error) : "读取预设超时:宿主 6 秒没有响应",
}));
},
loadCatalog(sessionId) {
const directory = modelDirectoryOf(sessionId);
if (!directory) return Promise.resolve({ options: [], current: undefined, error: "当前宿主未提供模型目录", subagent: false });
return Promise.resolve()
const cached = (message) => {
try {
const snapshot = directory.store.getSnapshot();
return {
options: modelOptions(snapshot),
current: snapshot.current,
error: message,
subagent: typeof sessions.subagentAddress === "function" ? sessions.subagentAddress(sessionId) !== undefined : false,
};
} catch (inner) {
return { options: [], current: undefined, error: message, subagent: false };
}
};
const chain = Promise.resolve()
.then(() => directory.load())
.then(() => {
const snapshot = directory.store.getSnapshot();
@ -1022,7 +1052,8 @@ window.__ModuleLoader__.load({
error: snapshot.error || null,
subagent: typeof sessions.subagentAddress === "function" ? sessions.subagentAddress(sessionId) !== undefined : false,
};
}, (error) => ({ options: [], current: undefined, error: String(error && error.message || error), subagent: false }));
}, (error) => cached(String(error && error.message || error)));
return withDeadline(chain, 6000, () => cached("读取模型目录超时(显示已知缓存)"));
},
selectModel(sessionId, payload) {
const directory = modelDirectoryOf(sessionId);
@ -1159,6 +1190,29 @@ window.__ModuleLoader__.load({
const EMPTY_SESSIONS = { byId: {}, projectionsBySession: {}, ids: [], phase: "ready" };
/** 给可能永远不 settle 的宿主 Promise 加超时,超时后走 fallback,避免界面卡在「读取中」。 */
function withDeadline(promise, ms, fallback) {
return new Promise((resolve) => {
let settled = false;
const timer = setTimeout(() => {
if (settled) return;
settled = true;
try { resolve(fallback()); } catch (error) { resolve(undefined); }
}, ms);
Promise.resolve(promise).then((value) => {
if (settled) return;
settled = true;
clearTimeout(timer);
resolve(value);
}, (error) => {
if (settled) return;
settled = true;
clearTimeout(timer);
try { resolve(fallback(error)); } catch (inner) { resolve(undefined); }
});
});
}
/**
* 订阅宿主 store 的快照。main 是 root 级槽,自带的会话级 hook 在 root 作用域下不可靠,
* 面板改为直接订阅服务层 store:数据与会话页同源,且不依赖 slot 注入的 hook。
@ -1355,7 +1409,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.4" }),
h("span", { key: "hint", className: "sl-main-head-hint", children: "v0.3.5" }),
h("span", { key: "spacer", className: "sl-main-head-spacer" }),
h(DockButton, { key: "dock", host }),
]),

View File

@ -1,6 +1,6 @@
{
"name": "dsh-sansheng-liubu-panel",
"version": "0.3.4",
"version": "0.3.5",
"private": true,
"description": "三省六部 Agent 面板:在 DSH Web GUI 中常驻显示并切换团队 Agent",
"type": "module",