1544 lines
64 KiB
JavaScript
1544 lines
64 KiB
JavaScript
// Generated from src/client by `npm run build` (scripts/build-client.mjs). Do not edit by hand.
|
||
window.__ModuleLoader__.load({
|
||
id: 'dsh-sansheng-liubu',
|
||
factory: (require) => {
|
||
const module = { exports: {} }
|
||
var __defProp = Object.defineProperty;
|
||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||
var __export = (target, all) => {
|
||
for (var name in all)
|
||
__defProp(target, name, { get: all[name], enumerable: true });
|
||
};
|
||
var __copyProps = (to, from, except, desc) => {
|
||
if (from && typeof from === "object" || typeof from === "function") {
|
||
for (let key of __getOwnPropNames(from))
|
||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||
}
|
||
return to;
|
||
};
|
||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||
|
||
// src/client/index.js
|
||
var index_exports = {};
|
||
__export(index_exports, {
|
||
apply: () => apply,
|
||
inject: () => inject
|
||
});
|
||
module.exports = __toCommonJS(index_exports);
|
||
|
||
// src/shared/roles.js
|
||
var SEAT_IDS = Object.freeze([
|
||
"lead",
|
||
"zhongshu",
|
||
"shangshu",
|
||
"menxia",
|
||
"libu",
|
||
"hubu",
|
||
"lipu",
|
||
"bingbu",
|
||
"xingbu",
|
||
"gongbu"
|
||
]);
|
||
var SEATS = Object.freeze({
|
||
lead: {
|
||
id: "lead",
|
||
label: "丞相",
|
||
duty: "接需求 · 协调汇报",
|
||
responsibility: "面向用户承接想法:判断是否需要开工、必要时派给具体部门,并把各部门结果汇总成对用户的一次交付。"
|
||
},
|
||
zhongshu: {
|
||
id: "zhongshu",
|
||
label: "中书",
|
||
duty: "调查 · 澄清 · 规划",
|
||
responsibility: "先把问题问清、把材料看全,再给出可执行的方案与验收标准草案,不直接产出最终交付物。"
|
||
},
|
||
shangshu: {
|
||
id: "shangshu",
|
||
label: "尚书",
|
||
duty: "分工 · 组织交付",
|
||
responsibility: "把已经明确的方案拆成部门分工并组织交付;六部直属于尚书这一同级分组,六部之间不是上下级。"
|
||
},
|
||
menxia: {
|
||
id: "menxia",
|
||
label: "门下",
|
||
duty: "审议 · 整体审核",
|
||
responsibility: "对方案和交付做独立审议,指出风险与不达标处。首版没有门下审核的任务必须如实标注“未审核”。"
|
||
},
|
||
libu: {
|
||
id: "libu",
|
||
label: "吏部",
|
||
duty: "角色 · 技能配置",
|
||
responsibility: "对角色、技能与编制给出建议;职责不含绕过用户授权去改权限或其他项目设置。"
|
||
},
|
||
hubu: {
|
||
id: "hubu",
|
||
label: "户部",
|
||
duty: "数据 · 表格计算",
|
||
responsibility: "处理数据、表格与计算,结论应可复算。"
|
||
},
|
||
lipu: {
|
||
id: "lipu",
|
||
label: "礼部",
|
||
duty: "文档 · 内容呈现",
|
||
responsibility: "负责文档、内容与呈现形式,产出可编辑的源文件。"
|
||
},
|
||
bingbu: {
|
||
id: "bingbu",
|
||
label: "兵部",
|
||
duty: "环境 · 调试部署",
|
||
responsibility: "负责环境、调试与部署;部署/发布等外部副作用仍服从用户授权与宿主审批。"
|
||
},
|
||
xingbu: {
|
||
id: "xingbu",
|
||
label: "刑部",
|
||
duty: "测试 · 风险检查",
|
||
responsibility: "做测试与风险检查,给出可追溯的检查结果,而不是一句“已通过”。"
|
||
},
|
||
gongbu: {
|
||
id: "gongbu",
|
||
label: "工部",
|
||
duty: "代码 · 工程产出",
|
||
responsibility: "负责代码实现与工程产出,交付可编辑源文件与真实检查结果。"
|
||
}
|
||
});
|
||
var SEAT_GROUPS = Object.freeze({
|
||
lead: Object.freeze(["lead"]),
|
||
sansheng: Object.freeze(["zhongshu", "shangshu", "menxia"]),
|
||
liubu: Object.freeze(["libu", "hubu", "lipu", "bingbu", "xingbu", "gongbu"])
|
||
});
|
||
function isSeatId(id) {
|
||
return SEAT_IDS.includes(id);
|
||
}
|
||
function seatOf(id) {
|
||
return SEATS[id];
|
||
}
|
||
function seatLabel(id) {
|
||
return SEATS[id]?.label ?? "";
|
||
}
|
||
function seatBySessionId(projects, sessionId) {
|
||
if (!sessionId || !projects) return void 0;
|
||
for (const project of Object.values(projects)) {
|
||
for (const seatId of SEAT_IDS) {
|
||
if (project?.seats?.[seatId]?.sessionId === sessionId) {
|
||
return { project, seatId, seat: SEATS[seatId] };
|
||
}
|
||
}
|
||
}
|
||
return void 0;
|
||
}
|
||
|
||
// src/client/workbench.js
|
||
var UNCHOSEN_MODEL_LABEL = "请选择模型";
|
||
var SEAT_STATUS_LABELS = Object.freeze({
|
||
pending: "待启用",
|
||
creating: "创建中",
|
||
bound: "已绑定",
|
||
failed: "创建失败",
|
||
missing: "会话缺失"
|
||
});
|
||
var DEFAULT_SEAT_STATUS = "pending";
|
||
function seatStatusLabel(status) {
|
||
if (typeof status !== "string") return "未知状态";
|
||
return SEAT_STATUS_LABELS[status] ?? "未知状态";
|
||
}
|
||
function projectStatusLabel(status) {
|
||
switch (status) {
|
||
case "pending":
|
||
return "待启用";
|
||
case "provisioning":
|
||
return "启用中";
|
||
case "ready":
|
||
return "已启用";
|
||
case "error":
|
||
return "启用失败";
|
||
default:
|
||
return "未知状态";
|
||
}
|
||
}
|
||
function collectModelOptions(models) {
|
||
const out = [];
|
||
const seen = /* @__PURE__ */ new Set();
|
||
const providers = Array.isArray(models?.providers) ? models.providers : [];
|
||
for (const entry of providers) {
|
||
const provider = typeof entry?.provider === "string" ? entry.provider : "";
|
||
if (!provider) continue;
|
||
const list = Array.isArray(entry?.models) ? entry.models : [];
|
||
for (const item of list) {
|
||
const model = typeof item?.model === "string" ? item.model : "";
|
||
if (!model) continue;
|
||
const efforts = Array.isArray(item?.reasoningEffort) ? item.reasoningEffort.filter((e) => typeof e === "string" && e.trim() !== "") : [];
|
||
if (efforts.length > 0) {
|
||
for (const effort of efforts) {
|
||
const value = provider + "::" + model + "::" + effort;
|
||
if (value === "inherit" || seen.has(value)) continue;
|
||
seen.add(value);
|
||
out.push({ value, label: model + " · " + effort, provider, model, reasoningEffort: effort });
|
||
}
|
||
} else {
|
||
const value = provider + "::" + model;
|
||
if (value === "inherit" || seen.has(value)) continue;
|
||
seen.add(value);
|
||
out.push({ value, label: model, provider, model });
|
||
}
|
||
}
|
||
}
|
||
return out;
|
||
}
|
||
function findModelOption(options, modelValue2) {
|
||
if (!Array.isArray(options)) return void 0;
|
||
return options.find((option) => option.value === modelValue2);
|
||
}
|
||
function describeModel(model, options) {
|
||
if (!model || typeof model !== "object" || typeof model.provider !== "string" || typeof model.model !== "string") {
|
||
return { modelValue: "", modelLabel: UNCHOSEN_MODEL_LABEL };
|
||
}
|
||
const effort = typeof model.reasoningEffort === "string" && model.reasoningEffort ? model.reasoningEffort : void 0;
|
||
const match = (Array.isArray(options) ? options : []).find((option) => option.provider === model.provider && option.model === model.model && (option.reasoningEffort ?? void 0) === effort);
|
||
if (match) return { modelValue: match.value, modelLabel: match.label };
|
||
const modelLabel = effort ? model.model + " · " + effort : model.model;
|
||
const modelValue2 = effort ? model.provider + "::" + model.model + "::" + effort : model.provider + "::" + model.model;
|
||
return { modelValue: modelValue2, modelLabel };
|
||
}
|
||
function normalizeSeats(seats) {
|
||
const map = {};
|
||
if (Array.isArray(seats)) {
|
||
for (const seat of seats) {
|
||
if (seat && typeof seat === "object" && typeof seat.id === "string") map[seat.id] = seat;
|
||
}
|
||
} else if (seats && typeof seats === "object") {
|
||
for (const [id, seat] of Object.entries(seats)) {
|
||
if (seat && typeof seat === "object") map[id] = { id, ...seat };
|
||
}
|
||
}
|
||
return map;
|
||
}
|
||
function cloneGroups() {
|
||
const out = {};
|
||
for (const key of Object.keys(SEAT_GROUPS)) out[key] = Array.from(SEAT_GROUPS[key]);
|
||
return out;
|
||
}
|
||
function pickSelectedId(requested) {
|
||
if (typeof requested === "string" && SEAT_IDS.includes(requested)) return requested;
|
||
return SEAT_IDS[0];
|
||
}
|
||
function hasOwn(obj, key) {
|
||
return obj !== null && obj !== void 0 && Object.prototype.hasOwnProperty.call(obj, key);
|
||
}
|
||
function draftOf(draft, seatId) {
|
||
if (!draft || typeof draft !== "object") return {};
|
||
const entry = draft[seatId];
|
||
return entry && typeof entry === "object" ? entry : {};
|
||
}
|
||
function updateDraft(draft, seatId, patch) {
|
||
const base = draft && typeof draft === "object" ? draft : {};
|
||
const previous = base[seatId] && typeof base[seatId] === "object" ? base[seatId] : {};
|
||
return { ...base, [seatId]: { ...previous, ...patch ?? {} } };
|
||
}
|
||
function clearDraft(draft, seatId) {
|
||
if (!draft || typeof draft !== "object" || !hasOwn(draft, seatId)) return draft ?? {};
|
||
const next = { ...draft };
|
||
delete next[seatId];
|
||
return next;
|
||
}
|
||
function buildWorkbenchView(view, ui) {
|
||
const safeView = view && typeof view === "object" ? view : {};
|
||
const project = safeView.project && typeof safeView.project === "object" ? safeView.project : {};
|
||
const status = typeof project.status === "string" ? project.status : "pending";
|
||
const ready = status === "ready";
|
||
const seatMap = normalizeSeats(project.seats);
|
||
const selectedSeatId = pickSelectedId(ui?.selectedSeatId);
|
||
const models = ui?.models ?? null;
|
||
const modelOptions = collectModelOptions(models);
|
||
const draft = ui?.draft ?? null;
|
||
const seats = SEAT_IDS.map((id) => {
|
||
const def = SEATS[id];
|
||
const rec = seatMap[id] ?? {};
|
||
const seatStatus = typeof rec.status === "string" ? rec.status : DEFAULT_SEAT_STATUS;
|
||
return {
|
||
id,
|
||
name: def.label,
|
||
duty: def.duty,
|
||
status: seatStatus,
|
||
statusLabel: seatStatusLabel(seatStatus),
|
||
selected: id === selectedSeatId
|
||
};
|
||
});
|
||
const seatDef = SEATS[selectedSeatId];
|
||
const seatRec = seatMap[selectedSeatId] ?? {};
|
||
const draftEntry = draftOf(draft, selectedSeatId);
|
||
let described;
|
||
if (hasOwn(draftEntry, "modelValue")) {
|
||
const raw = draftEntry.modelValue;
|
||
if (raw === "" || raw === null || raw === void 0) {
|
||
described = { modelValue: "", modelLabel: UNCHOSEN_MODEL_LABEL };
|
||
} else {
|
||
const match = findModelOption(modelOptions, raw);
|
||
described = match ? { modelValue: match.value, modelLabel: match.label } : { modelValue: String(raw), modelLabel: String(raw) };
|
||
}
|
||
} else if (hasOwn(draftEntry, "model")) {
|
||
described = describeModel(draftEntry.model, modelOptions);
|
||
} else {
|
||
described = describeModel(seatRec.model ?? null, modelOptions);
|
||
}
|
||
const instructions = hasOwn(draftEntry, "instructions") ? draftEntry.instructions : typeof seatRec.instructions === "string" ? seatRec.instructions : "";
|
||
const selectedStatus = typeof seatRec.status === "string" ? seatRec.status : DEFAULT_SEAT_STATUS;
|
||
let boundCount = 0;
|
||
let sessionCount = 0;
|
||
for (const id of SEAT_IDS) {
|
||
const rec = seatMap[id];
|
||
if (rec?.status === "bound") boundCount += 1;
|
||
if (rec?.sessionId) sessionCount += 1;
|
||
}
|
||
return {
|
||
projectTitle: typeof project.name === "string" ? project.name : "",
|
||
ready,
|
||
project: {
|
||
id: project.id ?? "",
|
||
name: typeof project.name === "string" ? project.name : "",
|
||
status,
|
||
statusLabel: projectStatusLabel(status),
|
||
workspaceId: project.workspaceId ?? null,
|
||
path: project.path ?? null,
|
||
seatCount: seats.length,
|
||
boundCount,
|
||
sessionCount
|
||
},
|
||
seats,
|
||
groups: cloneGroups(),
|
||
selected: {
|
||
id: selectedSeatId,
|
||
name: seatDef.label,
|
||
duty: seatDef.duty,
|
||
responsibility: seatDef.responsibility,
|
||
status: selectedStatus,
|
||
statusLabel: seatStatusLabel(selectedStatus),
|
||
sessionId: seatRec.sessionId ?? null,
|
||
modelValue: described.modelValue,
|
||
modelLabel: described.modelLabel,
|
||
instructions,
|
||
modelOptions,
|
||
dirty: Object.keys(draftEntry).length > 0
|
||
}
|
||
};
|
||
}
|
||
|
||
// src/client/transport.js
|
||
var ROUTE = "api/sansheng";
|
||
var SanshengRequestError = class extends Error {
|
||
constructor(message, code, retryable = true) {
|
||
super(message);
|
||
this.name = "SanshengRequestError";
|
||
this.code = code || "sansheng/error";
|
||
this.retryable = retryable !== false;
|
||
}
|
||
};
|
||
async function request(endpoint, payload, signal) {
|
||
let response;
|
||
try {
|
||
response = await fetch(ROUTE, {
|
||
method: "POST",
|
||
credentials: "same-origin",
|
||
headers: { "content-type": "application/json" },
|
||
body: JSON.stringify({ endpoint, payload: payload ?? null }),
|
||
signal
|
||
});
|
||
} catch (error) {
|
||
if (error && error.name === "AbortError") throw error;
|
||
const detail = error && error.message ? error.message : String(error);
|
||
throw new SanshengRequestError("无法连接 DSH,请确认它仍在运行(" + detail + ")", "NETWORK");
|
||
}
|
||
if (!response.ok) {
|
||
throw new SanshengRequestError("HTTP " + response.status, "HTTP_" + response.status);
|
||
}
|
||
let result;
|
||
try {
|
||
result = await response.json();
|
||
} catch (error) {
|
||
throw new SanshengRequestError("响应不是合法 JSON", "sansheng/bad-response");
|
||
}
|
||
if (!result || result.ok !== true) {
|
||
const code = result && result.error && result.error.code ? result.error.code : "sansheng/error";
|
||
const message = result && result.error && result.error.message ? result.error.message : "请求失败";
|
||
const retryable = !(result && result.error && result.error.retryable === false);
|
||
throw new SanshengRequestError(message, code, retryable);
|
||
}
|
||
return result.value;
|
||
}
|
||
var transport_default = request;
|
||
|
||
// src/client/styles.js
|
||
var CSS = `
|
||
.ssw-scope{--ssw-bg:#ffffff;--ssw-side:#f8f9fa;--ssw-rail:#f7f9fc;--ssw-card:#ffffff;--ssw-line:#e3e8ef;--ssw-strong:#c7d8f5;--ssw-ink:#0f172a;--ssw-muted:#667085;--ssw-faint:#98a2b3;--ssw-blue:#3b82f6;--ssw-wash:#eff6ff;--ssw-frame:#3b82f6;--ssw-wire:#c9d6ea;--ssw-danger:#dc2626;--ssw-ok:#16a34a;box-sizing:border-box;color:var(--ssw-ink);font-family:Inter,"Segoe UI","Microsoft YaHei",sans-serif;font-size:13px;line-height:1.5}
|
||
.ssw-scope *,.ssw-scope *::before,.ssw-scope *::after{box-sizing:border-box}
|
||
.ssw-scope button{font:inherit;color:inherit;background:transparent;border:0;cursor:pointer}
|
||
.ssw-scope button:disabled{cursor:default;opacity:.55}
|
||
.ssw-scope :focus-visible{outline:2px solid var(--ssw-blue);outline-offset:2px}
|
||
body[data-ds-dark-theme] .ssw-scope,html[data-theme=dark] .ssw-scope,.ssw-scope[data-ssw-theme=dark]{--ssw-bg:#14171c;--ssw-side:#171b21;--ssw-rail:#161a20;--ssw-card:#1e232b;--ssw-line:#2c333d;--ssw-strong:#3b4a63;--ssw-frame:#6ea8ff;--ssw-ink:#e6ebf2;--ssw-muted:#a9b4c2;--ssw-faint:#7b8797;--ssw-blue:#6ea8ff;--ssw-wash:#1d2b40;--ssw-wire:#3a4350;--ssw-danger:#f87171;--ssw-ok:#4ade80}
|
||
.ssw-float{position:fixed;right:14px;bottom:70px;z-index:2147483000;width:min(374px,calc(100vw - 28px));max-height:calc(100vh - 96px);display:flex;flex-direction:column;background:#ffffff;border:1px solid #e3e8ef;border-radius:12px;box-shadow:0 18px 50px -12px rgba(16,24,40,.28),0 4px 12px -2px rgba(16,24,40,.12);overflow:hidden}
|
||
body[data-ds-dark-theme] .ssw-float,html[data-theme=dark] .ssw-float{background:#161a20;border-color:#2c333d}
|
||
.ssw-root{display:flex;flex-direction:column;min-height:0;height:100%;overflow:auto;background:var(--ssw-rail);color:var(--ssw-ink)}
|
||
.ssw-head{flex:none;height:52px;display:flex;align-items:center;gap:8px;padding:0 16px;border-bottom:1px solid var(--ssw-line);background:var(--ssw-card)}
|
||
.ssw-head svg{width:18px;height:18px;color:var(--ssw-muted)}
|
||
.ssw-head-title{font-size:13px;font-weight:600}
|
||
.ssw-icon-btn{margin-left:auto;display:inline-flex;align-items:center;justify-content:center;width:30px;height:30px;border-radius:6px;color:var(--ssw-muted)}
|
||
.ssw-icon-btn:hover{background:var(--ssw-wash);color:var(--ssw-blue)}
|
||
.ssw-project{padding:18px 16px 0}
|
||
.ssw-project-line{display:flex;align-items:center;justify-content:space-between;margin-bottom:5px}
|
||
.ssw-eyebrow{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:var(--ssw-muted)}
|
||
.ssw-eyebrow svg{width:14px;height:14px}
|
||
.ssw-count{font-size:10px;color:var(--ssw-faint)}
|
||
.ssw-project-title{font-size:17px;font-weight:600;letter-spacing:.3px;margin:0 0 14px}
|
||
.ssw-enable{margin:0 16px 4px;padding:12px;border:1px solid var(--ssw-strong);background:var(--ssw-wash);border-radius:10px}
|
||
.ssw-enable-note{margin:0 0 10px;font-size:12px;color:var(--ssw-muted);line-height:1.7}
|
||
.ssw-primary{background:var(--ssw-blue);color:#ffffff;border-radius:7px;padding:8px 13px;font-size:12px;font-weight:500}
|
||
.ssw-primary:hover{filter:brightness(1.05)}
|
||
.ssw-tree{padding:14px 16px 4px;position:relative}
|
||
.ssw-lead{width:150px;margin:0 auto;position:relative}
|
||
.ssw-lead::after{content:none}
|
||
.ssw-sansheng{position:relative;margin-top:22px}
|
||
.ssw-trio{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:9px}
|
||
.ssw-seat{position:relative;width:100%;display:flex;flex-direction:column;gap:6px;padding:10px 9px 8px;border:1.5px solid var(--ssw-frame);border-radius:10px;background:var(--ssw-card);text-align:left;min-height:70px;box-shadow:0 1px 2px rgba(16,24,40,.04);transition:border-color .15s,box-shadow .15s,transform .15s}
|
||
.ssw-seat:hover{border-color:var(--ssw-blue);transform:translateY(-1px);box-shadow:0 3px 8px rgba(16,24,40,.06)}
|
||
.ssw-seat[aria-pressed=true]{border-color:var(--ssw-blue);background:var(--ssw-wash);box-shadow:0 0 0 2px rgba(59,130,246,.12)}
|
||
.ssw-lead .ssw-seat{border-color:var(--ssw-blue)}
|
||
.ssw-role-top{display:flex;align-items:center;justify-content:space-between;gap:6px}
|
||
.ssw-role-name{font-size:14px;font-weight:600;letter-spacing:2px}
|
||
.ssw-role-duty{font-size:10px;color:var(--ssw-muted);line-height:1.5}
|
||
.ssw-dot{flex:none;width:6px;height:6px;border-radius:50%;border:1px solid var(--ssw-faint);background:transparent}
|
||
.ssw-dot[data-status=bound]{background:var(--ssw-ok);border-color:var(--ssw-ok)}
|
||
.ssw-dot[data-status=failed],.ssw-dot[data-status=missing]{background:var(--ssw-danger);border-color:var(--ssw-danger)}
|
||
.ssw-dot[data-status=creating]{background:var(--ssw-blue);border-color:var(--ssw-blue)}
|
||
.ssw-ministries{position:relative;margin-top:18px}
|
||
.ssw-group-label{display:block;margin:0 2px 8px;font-size:11px;font-weight:600;letter-spacing:.5px;color:var(--ssw-muted)}
|
||
.ssw-six{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}
|
||
.ssw-six .ssw-seat{min-height:66px;padding:9px 8px}
|
||
.ssw-report{padding:0 16px;margin-top:4px}
|
||
.ssw-report-toggle{font-size:12px;color:var(--ssw-blue);padding:7px 2px;font-weight:500}
|
||
.ssw-report-list{display:flex;flex-direction:column;gap:8px;margin-top:4px}
|
||
.ssw-report-item{border:1px solid var(--ssw-line);border-radius:9px;padding:9px 11px;background:var(--ssw-card)}
|
||
.ssw-report-head{display:flex;gap:8px;align-items:baseline}
|
||
.ssw-report-head strong{font-size:13px;letter-spacing:1px}
|
||
.ssw-report-head span{font-size:10px;color:var(--ssw-muted)}
|
||
.ssw-report-model{margin:4px 0 0;font-size:11px;color:var(--ssw-blue);letter-spacing:.2px}
|
||
.ssw-report-text{margin:4px 0 0;font-size:12px;line-height:1.7;color:var(--ssw-muted)}
|
||
.ssw-current{margin:16px 16px 0;padding:13px;border:1px solid var(--ssw-line);border-radius:11px;background:var(--ssw-card)}
|
||
.ssw-current-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:9px}
|
||
.ssw-current-name{font-size:13px;font-weight:600}
|
||
.ssw-current-label{font-size:10px;color:var(--ssw-faint)}
|
||
.ssw-current-text{margin:0;font-size:12px;line-height:1.8;color:var(--ssw-muted)}
|
||
.ssw-config{margin:10px 16px 0;border:1px solid var(--ssw-line);border-radius:10px;background:var(--ssw-card);overflow:hidden}
|
||
.ssw-config-toggle{display:flex;align-items:center;gap:8px;width:100%;padding:12px 13px;font-size:12px;color:var(--ssw-ink)}
|
||
.ssw-config-toggle svg{width:15px;height:15px;color:var(--ssw-muted)}
|
||
.ssw-chevron{margin-left:auto;transition:transform .2s}
|
||
.ssw-config-toggle[aria-expanded=true] .ssw-chevron{transform:rotate(180deg)}
|
||
.ssw-config-body{padding:0 13px 14px}
|
||
.ssw-label{display:block;font-size:11px;color:var(--ssw-muted);margin:12px 0 6px}
|
||
.ssw-field{width:100%;border:1px solid var(--ssw-line);background:var(--ssw-bg);color:var(--ssw-ink);border-radius:6px;padding:8px;font-size:12px;line-height:1.5}
|
||
.ssw-textarea{resize:vertical;min-height:84px;font-family:inherit}
|
||
.ssw-scope-note{margin:10px 0;font-size:10px;line-height:1.6;color:var(--ssw-faint)}
|
||
.ssw-save-row{display:flex;align-items:center;gap:10px}
|
||
.ssw-save-status{font-size:10px;color:var(--ssw-muted)}
|
||
.ssw-notice{margin:12px 16px 16px;font-size:11px;color:var(--ssw-muted)}
|
||
.ssw-error{margin:12px 16px 16px;font-size:11px;color:var(--ssw-danger)}
|
||
.ssw-loading,.ssw-empty{padding:36px 20px;text-align:center;font-size:12px;color:var(--ssw-muted)}
|
||
.ssw-empty .ssw-primary{margin-top:12px}
|
||
/* 导航行图标:尺寸/颜色全部跟随宿主导航行,不自己画背景,避免比同类导航项突兀。 */
|
||
.ssw-nav-hit{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;color:inherit;cursor:pointer}
|
||
.ssw-nav-hit svg{width:16px;height:16px;flex:none;display:block}
|
||
.ssw-hint{margin:6px 0 0;font-size:11px;color:var(--ssw-faint)}
|
||
@media (prefers-reduced-motion:reduce){.ssw-scope *{transition:none!important}}
|
||
.ssw-tab-body{height:100%;min-height:0;display:flex;flex-direction:column}
|
||
.ssw-tab-body .ssw-root{flex:1;min-height:0}
|
||
.ssw-tab-title{font-size:13px}
|
||
/* 宿主的 .ssw-scope button{border:0} 会盖掉 .ssw-seat 的边框(选择器更具体),
|
||
导致十张部门卡平时没有框、只有选中时靠背景色看着像有框。这里提高选择器优先级,
|
||
让每张卡始终显示蓝色描边,选中时再加深。 */
|
||
.ssw-scope .ssw-seat{border:2px solid var(--ssw-frame);border-radius:10px;background:var(--ssw-card)}
|
||
.ssw-scope .ssw-lead .ssw-seat{border-color:var(--ssw-blue)}
|
||
.ssw-scope .ssw-six .ssw-seat{border-color:var(--ssw-frame)}
|
||
.ssw-scope .ssw-seat:hover{border-color:var(--ssw-blue)}
|
||
.ssw-scope .ssw-seat[aria-pressed=true]{border-color:var(--ssw-blue);background:var(--ssw-wash);box-shadow:0 0 0 2px rgba(59,130,246,.12)}
|
||
body[data-ds-dark-theme] .ssw-scope .ssw-seat[aria-pressed=true]{box-shadow:0 0 0 2px rgba(110,168,255,.18)}
|
||
`;
|
||
|
||
// src/native/panel.js
|
||
var GROUP_ORDER = ["lead", "sansheng", "liubu"];
|
||
var GROUP_TITLE = { lead: "统领", sansheng: "三省", liubu: "六部" };
|
||
var MAX_OPTIONS = 8;
|
||
var PROJECT_STATUS_TEXT = {
|
||
pending: "待启用",
|
||
provisioning: "启用中",
|
||
ready: "已就绪",
|
||
error: "异常"
|
||
};
|
||
var SEAT_STATUS_TEXT = {
|
||
pending: "待启用",
|
||
creating: "创建中",
|
||
bound: "已绑定",
|
||
failed: "失败",
|
||
missing: "缺失"
|
||
};
|
||
function asText(v) {
|
||
return typeof v === "string" ? v : "";
|
||
}
|
||
function seatRecords(project) {
|
||
const out = {};
|
||
const seats = project ? project.seats : null;
|
||
if (Array.isArray(seats)) {
|
||
for (const s of seats) if (s && SEATS[s.id]) out[s.id] = s;
|
||
} else if (seats && typeof seats === "object") {
|
||
for (const id of SEAT_IDS) if (seats[id]) out[id] = seats[id];
|
||
}
|
||
return out;
|
||
}
|
||
function isBound(seat) {
|
||
return !!seat && typeof seat.sessionId === "string" && seat.sessionId.length > 0;
|
||
}
|
||
function modelValue(model) {
|
||
if (!model || typeof model !== "object") return "";
|
||
if (typeof model.provider !== "string" || typeof model.model !== "string") return "";
|
||
return model.provider + "::" + model.model;
|
||
}
|
||
function flattenModels(models) {
|
||
const opts = [];
|
||
const providers = models && Array.isArray(models.providers) ? models.providers : [];
|
||
for (const p of providers) {
|
||
const pid = asText(p && p.provider);
|
||
if (!pid) continue;
|
||
const list = Array.isArray(p && p.models) ? p.models : [];
|
||
for (const m of list) {
|
||
const mid = typeof m === "string" ? m : asText(m && m.model);
|
||
if (!mid) continue;
|
||
opts.push({ value: pid + "::" + mid, label: pid + " / " + mid });
|
||
if (opts.length >= MAX_OPTIONS - 1) break;
|
||
}
|
||
if (opts.length >= MAX_OPTIONS - 1) break;
|
||
}
|
||
return opts;
|
||
}
|
||
function buildModelSelect(project, seat, models) {
|
||
const real = flattenModels(models);
|
||
const options = [{ value: "", label: "请选择模型" }].concat(real).slice(0, MAX_OPTIONS);
|
||
const want = modelValue(seat && seat.model);
|
||
const value = options.some((o) => o.value === want) ? want : "";
|
||
return {
|
||
type: "select",
|
||
label: "模型",
|
||
value,
|
||
options,
|
||
action: { type: "sansheng/select-model", seatId: seat && seat.id || null, projectId: project && project.id || null }
|
||
};
|
||
}
|
||
function seatButton(project, seat, selectedSeatId) {
|
||
const meta = SEATS[seat.id];
|
||
const selected = seat.id === selectedSeatId;
|
||
return {
|
||
type: "button",
|
||
seatId: seat.id,
|
||
label: meta.label,
|
||
selected,
|
||
variant: selected ? "primary" : "ghost",
|
||
action: { type: "sansheng/select-seat", seatId: seat.id, projectId: project && project.id || null }
|
||
};
|
||
}
|
||
function groupNode(project, records, key, selectedSeatId) {
|
||
const ids = (SEAT_GROUPS[key] || []).filter((id) => records[id] && SEATS[id]);
|
||
if (ids.length === 0) return null;
|
||
const perRow = key === "liubu" ? 3 : ids.length;
|
||
const rows = [];
|
||
for (let i = 0; i < ids.length; i += perRow) {
|
||
const slice = ids.slice(i, i + perRow);
|
||
rows.push({ type: "row", children: slice.map((id) => seatButton(project, records[id], selectedSeatId)) });
|
||
}
|
||
return {
|
||
type: "stack",
|
||
group: key,
|
||
children: [{ type: "text", text: GROUP_TITLE[key] + " · " + ids.length + " 席" }].concat(rows)
|
||
};
|
||
}
|
||
function selectedDetail(project, records, selectedSeatId, models) {
|
||
const seat = selectedSeatId ? records[selectedSeatId] : null;
|
||
if (!seat) {
|
||
return { type: "callout", tone: "info", text: "点击上方角色卡片查看职责、模型与进入会话。" };
|
||
}
|
||
const meta = SEATS[seat.id];
|
||
const bound = isBound(seat);
|
||
const statusLabel = SEAT_STATUS_TEXT[seat.status] || asText(seat.status) || "未知";
|
||
const instructions = asText(seat.instructions).trim() || "(未填写)";
|
||
return {
|
||
type: "stack",
|
||
detail: seat.id,
|
||
children: [
|
||
{ type: "text", text: meta.label + " · " + meta.duty + " · " + statusLabel },
|
||
{ type: "callout", tone: "info", text: "职责:" + meta.responsibility },
|
||
{ type: "text", text: "角色补充说明(只读,请在 Web 端编辑)" },
|
||
{ type: "callout", tone: "warn", text: instructions },
|
||
buildModelSelect(project, seat, models),
|
||
{
|
||
type: "button",
|
||
label: bound ? "进入" + meta.label + "会话" : meta.label + "尚未绑定会话",
|
||
variant: bound ? "primary" : "ghost",
|
||
disabled: !bound,
|
||
action: {
|
||
type: "sansheng/enter-session",
|
||
seatId: seat.id,
|
||
projectId: project && project.id || null,
|
||
sessionId: isBound(seat) ? seat.sessionId : null
|
||
}
|
||
}
|
||
]
|
||
};
|
||
}
|
||
function buildPanelView(input) {
|
||
const { project = null, selectedSeatId = null, models = null } = input || {};
|
||
if (!project || typeof project !== "object") {
|
||
return {
|
||
type: "stack",
|
||
children: [
|
||
{ type: "text", text: "三省六部" },
|
||
{
|
||
type: "callout",
|
||
tone: "warn",
|
||
text: "无法确定当前项目:原生面板作用域不含 workspaceId,且未能由 sessionId 反查到所属项目。请从已启用「三省六部」的项目会话中打开,或在 Web 工作台查看。"
|
||
}
|
||
]
|
||
};
|
||
}
|
||
const records = seatRecords(project);
|
||
const sel = selectedSeatId && records[selectedSeatId] ? selectedSeatId : records.lead ? "lead" : null;
|
||
const ready = project.status === "ready";
|
||
const boundCount = SEAT_IDS.filter((id) => isBound(records[id])).length;
|
||
const children = [
|
||
{ type: "text", text: "三省六部 · " + (asText(project.name) || "未命名项目") },
|
||
{
|
||
type: "callout",
|
||
tone: ready ? "good" : "warn",
|
||
text: (PROJECT_STATUS_TEXT[project.status] || "状态未知") + " · 已绑定 " + boundCount + "/10 席"
|
||
}
|
||
];
|
||
for (const key of GROUP_ORDER) {
|
||
const g = groupNode(project, records, key, sel);
|
||
if (g) children.push(g);
|
||
}
|
||
children.push(selectedDetail(project, records, sel, models));
|
||
return { type: "stack", children };
|
||
}
|
||
var panel_default = buildPanelView;
|
||
|
||
// src/native/index.js
|
||
var PANEL_ID = "sansheng";
|
||
var viewBySession = /* @__PURE__ */ new Map();
|
||
var selectionBySession = /* @__PURE__ */ new Map();
|
||
var modelsBySession = /* @__PURE__ */ new Map();
|
||
function cacheProject(project) {
|
||
if (!project || typeof project !== "object") return;
|
||
const seats = project.seats;
|
||
for (const id of SEAT_IDS) {
|
||
let seat = null;
|
||
if (Array.isArray(seats)) seat = seats.find((s) => s && s.id === id) || null;
|
||
else if (seats && typeof seats === "object") seat = seats[id] || null;
|
||
if (seat && typeof seat.sessionId === "string" && seat.sessionId) {
|
||
viewBySession.set(seat.sessionId, project);
|
||
}
|
||
}
|
||
}
|
||
function resolveProject(native, scope) {
|
||
const sid = scope && typeof scope.sessionId === "string" ? scope.sessionId : null;
|
||
const lookup = native && (native.sansheng || native.sanshengProjects) || null;
|
||
if (lookup && typeof lookup.projectForScope === "function") {
|
||
try {
|
||
const p = lookup.projectForScope(scope);
|
||
if (p) {
|
||
cacheProject(p);
|
||
return p;
|
||
}
|
||
} catch (e) {
|
||
}
|
||
}
|
||
if (lookup && typeof lookup.projectForSession === "function" && sid) {
|
||
try {
|
||
const p = lookup.projectForSession(sid);
|
||
if (p) {
|
||
cacheProject(p);
|
||
return p;
|
||
}
|
||
} catch (e) {
|
||
}
|
||
}
|
||
let workspaceId = null;
|
||
try {
|
||
const sessions = native && native.sessions;
|
||
if (sessions && typeof sessions.binding === "function" && sid) {
|
||
const b = sessions.binding(sid);
|
||
workspaceId = b && (b.workspaceId || b.workspace && b.workspace.id) || null;
|
||
}
|
||
} catch (e) {
|
||
}
|
||
if (lookup && typeof lookup.projectForWorkspace === "function" && workspaceId) {
|
||
try {
|
||
const p = lookup.projectForWorkspace(workspaceId);
|
||
if (p) {
|
||
cacheProject(p);
|
||
return p;
|
||
}
|
||
} catch (e) {
|
||
}
|
||
}
|
||
if (sid && viewBySession.has(sid)) return viewBySession.get(sid);
|
||
return null;
|
||
}
|
||
function makeView(native, scope) {
|
||
const sid = scope && typeof scope.sessionId === "string" ? scope.sessionId : null;
|
||
const project = resolveProject(native, scope);
|
||
const selectedSeatId = sid && selectionBySession.has(sid) ? selectionBySession.get(sid) : null;
|
||
const models = sid && modelsBySession.has(sid) ? modelsBySession.get(sid) : null;
|
||
return buildPanelView({ project, selectedSeatId, models });
|
||
}
|
||
function normalizeAction(event) {
|
||
const a = event && event.action;
|
||
if (a && typeof a === "object") return a;
|
||
const v = event && event.value;
|
||
if (v && typeof v === "object" && typeof v.type === "string") return v;
|
||
if (typeof a === "string") return Object.assign({ type: a }, v && typeof v === "object" ? v : {});
|
||
return null;
|
||
}
|
||
async function handleEvent(native, scope, event) {
|
||
const sid = scope && typeof scope.sessionId === "string" ? scope.sessionId : null;
|
||
const action = normalizeAction(event);
|
||
if (!action || typeof action.type !== "string") return [];
|
||
switch (action.type) {
|
||
case "sansheng/select-seat": {
|
||
if (sid && action.seatId) selectionBySession.set(sid, action.seatId);
|
||
return [{ type: "refresh", id: PANEL_ID }];
|
||
}
|
||
case "sansheng/select-model": {
|
||
if (sid && action.seatId) selectionBySession.set(sid, action.seatId);
|
||
return [{ type: "toast", text: "模型选择在原生面板暂未接持久化,请在 Web 端保存(需真机核验)" }];
|
||
}
|
||
case "sansheng/enter-session": {
|
||
const bridged = native && native.dshGo;
|
||
const open = bridged && (bridged.openSession || bridged.navigate) || native && native.sansheng && native.sansheng.openSession;
|
||
if (typeof open === "function" && action.sessionId) {
|
||
try {
|
||
await open(action.sessionId);
|
||
return [{ type: "toast", text: "已请求打开会话" }];
|
||
} catch (e) {
|
||
}
|
||
}
|
||
return [{ type: "toast", text: "原生 effect 暂不支持会话跳转,请从宿主会话列表进入(需真机核验)" }];
|
||
}
|
||
default:
|
||
return [];
|
||
}
|
||
}
|
||
function makeDataProvider(native, dshGo) {
|
||
return function data(scope, emit) {
|
||
let cancelled = false;
|
||
const run = async () => {
|
||
if (typeof fetch !== "function") return;
|
||
const sid = scope && typeof scope.sessionId === "string" ? scope.sessionId : null;
|
||
if (!sid) return;
|
||
const post = async (endpoint, payload) => {
|
||
const res = await fetch("/api/sansheng", {
|
||
method: "POST",
|
||
credentials: "same-origin",
|
||
headers: { "content-type": "application/json" },
|
||
body: JSON.stringify({ endpoint, payload: payload == null ? null : payload })
|
||
});
|
||
if (!res.ok) throw new Error("HTTP " + res.status);
|
||
const r = await res.json();
|
||
if (!r || r.ok !== true) throw new Error(r && r.error && r.error.message || "request failed");
|
||
return r.value;
|
||
};
|
||
const list = await post("list");
|
||
const projects = list && Array.isArray(list.projects) ? list.projects : [];
|
||
for (const meta of projects) {
|
||
const value = await post("project", { projectId: meta.id });
|
||
const project = value && value.project ? value.project : value;
|
||
cacheProject(project);
|
||
const seats = project && project.seats;
|
||
const found = Array.isArray(seats) ? seats.some((s) => s && s.sessionId === sid) : seats && Object.values(seats).some((s) => s && s.sessionId === sid);
|
||
if (found) {
|
||
if (!cancelled) {
|
||
try {
|
||
emit({ project });
|
||
} catch (e) {
|
||
}
|
||
try {
|
||
if (dshGo && typeof dshGo.refresh === "function") dshGo.refresh(PANEL_ID, scope);
|
||
} catch (e) {
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
};
|
||
run().catch(() => {
|
||
});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
};
|
||
}
|
||
function install(ctx) {
|
||
if (!ctx || typeof ctx.inject !== "function") return () => {
|
||
};
|
||
return ctx.inject(["dshGo", "sessions"], (native) => {
|
||
const dshGo = native && native.dshGo;
|
||
if (!dshGo || typeof dshGo.panel !== "function") return () => {
|
||
};
|
||
const disposers = [];
|
||
try {
|
||
const offPanel = native.dshGo.panel(PANEL_ID, {
|
||
view: (scope, caps) => makeView(native, scope),
|
||
data: makeDataProvider(native, native.dshGo)
|
||
});
|
||
if (typeof offPanel === "function") disposers.push(offPanel);
|
||
} catch (e) {
|
||
}
|
||
if (typeof native.dshGo.on === "function") {
|
||
try {
|
||
const offOn = native.dshGo.on(PANEL_ID, (scope, event) => handleEvent(native, scope, event));
|
||
if (typeof offOn === "function") disposers.push(offOn);
|
||
} catch (e) {
|
||
}
|
||
}
|
||
return () => {
|
||
for (const off of disposers) {
|
||
try {
|
||
off();
|
||
} catch (e) {
|
||
}
|
||
}
|
||
};
|
||
});
|
||
}
|
||
var native_default = { install };
|
||
|
||
// src/client/index.js
|
||
var import_react = require("react");
|
||
var import_react_dom = require("react-dom");
|
||
var inject = ["sessions", "uiWorkspace", "uiConversation", "slots", "theme", "layout"];
|
||
var PLUGIN_ID = "dsh-sansheng";
|
||
var TAB_KIND = "sansheng-workbench";
|
||
var TAB_TYPE_ID = "dsh-sansheng:workbench";
|
||
function installStyles(doc, tag, text) {
|
||
if (!doc || !doc.head) return null;
|
||
const style = doc.createElement("style");
|
||
style.dataset.plugin = PLUGIN_ID;
|
||
style.dataset.sansheng = tag;
|
||
style.textContent = text;
|
||
doc.head.appendChild(style);
|
||
return style;
|
||
}
|
||
function svgWrap(children, props) {
|
||
return (0, import_react.createElement)("svg", {
|
||
viewBox: "0 0 24 24",
|
||
width: 16,
|
||
height: 16,
|
||
fill: "none",
|
||
stroke: "currentColor",
|
||
strokeWidth: 1.6,
|
||
strokeLinecap: "round",
|
||
strokeLinejoin: "round",
|
||
"aria-hidden": "true",
|
||
...props || {}
|
||
}, children);
|
||
}
|
||
var TreeIcon = (props) => svgWrap([
|
||
(0, import_react.createElement)("rect", { key: "a", x: 9, y: 2, width: 6, height: 5, rx: 1 }),
|
||
(0, import_react.createElement)("path", { key: "b", d: "M12 7v5M5 16v-4h14v4" }),
|
||
(0, import_react.createElement)("rect", { key: "c", x: 2, y: 16, width: 6, height: 5, rx: 1 }),
|
||
(0, import_react.createElement)("rect", { key: "d", x: 16, y: 16, width: 6, height: 5, rx: 1 })
|
||
], props);
|
||
var CloseIcon = (props) => svgWrap([(0, import_react.createElement)("path", { key: "p", d: "m6 6 12 12M6 18 18 6" })], props);
|
||
var FolderIcon = (props) => svgWrap([(0, import_react.createElement)("path", { key: "p", d: "M3 7V5a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v11H3Z" })], props);
|
||
var GearIcon = (props) => svgWrap([
|
||
(0, import_react.createElement)("path", { key: "a", d: "M4 6h16M4 12h16M4 18h16" }),
|
||
(0, import_react.createElement)("circle", { key: "b", cx: 9, cy: 6, r: 2 }),
|
||
(0, import_react.createElement)("circle", { key: "c", cx: 16, cy: 12, r: 2 }),
|
||
(0, import_react.createElement)("circle", { key: "d", cx: 8, cy: 18, r: 2 })
|
||
], props);
|
||
var ChevronIcon = (props) => (0, import_react.createElement)("svg", {
|
||
viewBox: "0 0 24 24",
|
||
width: 14,
|
||
height: 14,
|
||
fill: "none",
|
||
stroke: "currentColor",
|
||
strokeWidth: 1.6,
|
||
strokeLinecap: "round",
|
||
strokeLinejoin: "round",
|
||
className: "ssw-chevron",
|
||
"aria-hidden": "true"
|
||
}, (0, import_react.createElement)("path", { d: "m6 9 6 6 6-6" }));
|
||
function isFn(value) {
|
||
return typeof value === "function";
|
||
}
|
||
function safeCall(obj, name) {
|
||
try {
|
||
if (!obj || !isFn(obj[name])) return void 0;
|
||
return obj[name]();
|
||
} catch {
|
||
return void 0;
|
||
}
|
||
}
|
||
function snapshotOf(obj) {
|
||
if (!obj) return void 0;
|
||
if (isFn(obj.getSnapshot)) {
|
||
try {
|
||
return obj.getSnapshot();
|
||
} catch {
|
||
return void 0;
|
||
}
|
||
}
|
||
return obj;
|
||
}
|
||
function apply(ctx) {
|
||
if (typeof document !== "undefined") installStyles(document, "workbench", CSS);
|
||
const get = (name) => {
|
||
try {
|
||
return ctx.get(name);
|
||
} catch {
|
||
return void 0;
|
||
}
|
||
};
|
||
function workspaceItems() {
|
||
const fromWorkspaces = snapshotOf(get("workspaces")?.list)?.items;
|
||
if (Array.isArray(fromWorkspaces)) return fromWorkspaces;
|
||
const fromUi = snapshotOf(get("uiWorkspace")?.workspaces)?.items;
|
||
if (Array.isArray(fromUi)) return fromUi;
|
||
return [];
|
||
}
|
||
function normalizeWorkspace(item) {
|
||
if (!item || typeof item !== "object") return null;
|
||
const workspaceId = item.workspaceId ?? item.id ?? null;
|
||
if (typeof workspaceId !== "string" || !workspaceId) return null;
|
||
return {
|
||
workspaceId,
|
||
name: typeof item.name === "string" ? item.name : typeof item.title === "string" ? item.title : void 0,
|
||
path: typeof item.path === "string" ? item.path : void 0
|
||
};
|
||
}
|
||
function currentSessionId() {
|
||
const snap = snapshotOf(get("sessions")?.list) ?? snapshotOf(get("sessions"));
|
||
if (!snap || typeof snap !== "object") return null;
|
||
for (const key of ["activeId", "currentId", "selectedId"]) {
|
||
if (typeof snap[key] === "string" && snap[key]) return snap[key];
|
||
}
|
||
if (snap.byId && typeof snap.byId === "object") {
|
||
const main = Object.values(snap.byId).find((session) => (session?.retainedBy?.mainView ?? 0) > 0);
|
||
if (main && typeof main.id === "string") return main.id;
|
||
}
|
||
return null;
|
||
}
|
||
function currentWorkspaceId() {
|
||
const candidates = [];
|
||
for (const holder of [get("workspaces"), get("uiWorkspace")]) {
|
||
if (!holder) continue;
|
||
for (const key of ["currentWorkspaceId", "currentId", "activeId"]) {
|
||
if (isFn(holder[key])) candidates.push(safeCall(holder, key));
|
||
else if (typeof holder[key] === "string") candidates.push(holder[key]);
|
||
}
|
||
for (const key of ["current", "active", "selected", "currentWorkspace"]) {
|
||
const value = holder[key];
|
||
const snap = snapshotOf(value);
|
||
if (snap && typeof snap === "object") candidates.push(snap.workspaceId ?? snap.id);
|
||
else if (typeof value === "string") candidates.push(value);
|
||
}
|
||
}
|
||
const sessionId = currentSessionId();
|
||
if (sessionId) {
|
||
const owner = workspaceItems().find((item) => Array.isArray(item.sessionIds) && item.sessionIds.includes(sessionId));
|
||
if (owner) candidates.push(owner.workspaceId ?? owner.id);
|
||
}
|
||
return candidates.find((id) => typeof id === "string" && id) ?? null;
|
||
}
|
||
function currentWorkspace() {
|
||
const items = workspaceItems().map(normalizeWorkspace).filter(Boolean);
|
||
const id = currentWorkspaceId();
|
||
if (id) {
|
||
const hit = items.find((item) => item.workspaceId === id);
|
||
return hit || { workspaceId: id, name: void 0, path: void 0 };
|
||
}
|
||
if (items.length === 1) return items[0];
|
||
return null;
|
||
}
|
||
function seatRecordOf(view, id) {
|
||
const seats = view && view.project ? view.project.seats : null;
|
||
if (Array.isArray(seats)) return seats.find((seat) => seat && seat.id === id) || null;
|
||
if (seats && typeof seats === "object") return seats[id] || null;
|
||
return null;
|
||
}
|
||
function navigateToSession(sessionId) {
|
||
if (!sessionId) return false;
|
||
const attempts = [];
|
||
const ui = get("uiWorkspace");
|
||
if (ui) {
|
||
if (isFn(ui.openSession)) attempts.push(() => ui.openSession(sessionId));
|
||
if (isFn(ui.open)) attempts.push(() => ui.open(sessionId));
|
||
}
|
||
const sessions = get("sessions");
|
||
if (sessions) {
|
||
if (isFn(sessions.open)) attempts.push(() => sessions.open(sessionId));
|
||
if (isFn(sessions.openSession)) attempts.push(() => sessions.openSession(sessionId));
|
||
if (isFn(sessions.select)) attempts.push(() => sessions.select(sessionId));
|
||
}
|
||
for (const name of ["navigation", "navigator", "router"]) {
|
||
const svc = get(name);
|
||
if (!svc) continue;
|
||
if (isFn(svc.openSession)) attempts.push(() => svc.openSession(sessionId));
|
||
if (isFn(svc.navigate)) attempts.push(() => svc.navigate({ sessionId }));
|
||
if (isFn(svc.open)) attempts.push(() => svc.open(sessionId));
|
||
}
|
||
for (const run of attempts) {
|
||
try {
|
||
const result = run();
|
||
if (result && isFn(result.then)) result.catch(() => {
|
||
});
|
||
return true;
|
||
} catch {
|
||
}
|
||
}
|
||
console.warn("[sansheng] 未找到可用的会话导航接口,仅发出 navigate 意图:", sessionId);
|
||
try {
|
||
if (typeof window !== "undefined") {
|
||
window.dispatchEvent(new CustomEvent("sansheng:navigate", { detail: { sessionId } }));
|
||
}
|
||
} catch {
|
||
}
|
||
return false;
|
||
}
|
||
function ensureRightTab() {
|
||
const tabs = get("sidebarRightTabs");
|
||
if (!tabs || !isFn(tabs.get)) return false;
|
||
try {
|
||
return !!(tabs.get(TAB_KIND) || tabs.get(TAB_TYPE_ID));
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
function revealRightTab() {
|
||
const right = get("sidebarRight");
|
||
if (!right) return;
|
||
try {
|
||
const rows = isFn(right.openTabs?.getSnapshot) ? right.openTabs.getSnapshot() : [];
|
||
const row = Array.isArray(rows) ? rows.find((item) => item && item.kind === TAB_KIND) : null;
|
||
if (row && isFn(right.focus)) right.focus(row.tabId);
|
||
if (isFn(right.isExpanded) && !right.isExpanded() && isFn(right.toggleExpanded)) right.toggleExpanded();
|
||
} catch (error) {
|
||
console.warn("[sansheng] 展开右侧栏失败:", error && error.message ? error.message : error);
|
||
}
|
||
}
|
||
function tryOpenRightTab() {
|
||
const right = get("sidebarRight");
|
||
if (!right || !isFn(right.openTab)) return false;
|
||
if (!ensureRightTab()) return false;
|
||
try {
|
||
right.openTab(TAB_KIND);
|
||
} catch (error) {
|
||
console.warn("[sansheng] 打开右侧标签失败,改用浮动面板:", error && error.message ? error.message : error);
|
||
return false;
|
||
}
|
||
revealRightTab();
|
||
try {
|
||
const rows = isFn(right.openTabs?.getSnapshot) ? right.openTabs.getSnapshot() : null;
|
||
if (Array.isArray(rows) && rows.length > 0 && !rows.some((item) => item && item.kind === TAB_KIND)) return false;
|
||
} catch {
|
||
}
|
||
return true;
|
||
}
|
||
function SanshengTabBody() {
|
||
return (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {}));
|
||
}
|
||
function SanshengTabTitle() {
|
||
return (0, import_react.createElement)("span", { className: "ssw-tab-title" }, "三省六部");
|
||
}
|
||
function registerRightTabType() {
|
||
try {
|
||
if (!isFn(ctx.inject)) return;
|
||
ctx.inject(["sidebarRightTabs"], (injected) => {
|
||
const tabs = injected.get("sidebarRightTabs");
|
||
if (!tabs || !isFn(tabs.register)) return;
|
||
let disposeType = null, disposeBody = null, disposeTitle = null;
|
||
try {
|
||
disposeType = tabs.register({ id: TAB_TYPE_ID, kind: TAB_KIND, keepMounted: true, priority: "extension", title: () => "三省六部" });
|
||
disposeBody = ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({
|
||
name: "sidebar.right.pane.tab",
|
||
key: TAB_TYPE_ID,
|
||
inject: (sessionId) => ({ sessionId })
|
||
}, SanshengTabBody));
|
||
disposeTitle = ctx.slots.inject("sidebar.right.pane.tab.title", () => ctx.slots.register({
|
||
name: "sidebar.right.pane.tab.title",
|
||
key: TAB_TYPE_ID,
|
||
inject: (sessionId) => ({ sessionId })
|
||
}, SanshengTabTitle));
|
||
} catch (error) {
|
||
console.warn("[sansheng] 注册右侧标签失败:", error && error.message ? error.message : error);
|
||
try {
|
||
disposeBody && disposeBody();
|
||
} catch {
|
||
}
|
||
try {
|
||
disposeTitle && disposeTitle();
|
||
} catch {
|
||
}
|
||
try {
|
||
disposeType && disposeType();
|
||
} catch {
|
||
}
|
||
return;
|
||
}
|
||
return () => {
|
||
try {
|
||
disposeBody && disposeBody();
|
||
} catch {
|
||
}
|
||
try {
|
||
disposeTitle && disposeTitle();
|
||
} catch {
|
||
}
|
||
try {
|
||
disposeType && disposeType();
|
||
} catch {
|
||
}
|
||
};
|
||
});
|
||
} catch (error) {
|
||
console.warn("[sansheng] 注册右侧标签失败:", error && error.message ? error.message : error);
|
||
}
|
||
}
|
||
function SanshengWorkbench(props) {
|
||
const onClose = props && props.onClose ? props.onClose : null;
|
||
const [phase, setPhase] = (0, import_react.useState)("loading");
|
||
const [error, setError] = (0, import_react.useState)(null);
|
||
const [errorRetryable, setErrorRetryable] = (0, import_react.useState)(true);
|
||
const [notice, setNotice] = (0, import_react.useState)(null);
|
||
const [view, setView] = (0, import_react.useState)(null);
|
||
const [models, setModels] = (0, import_react.useState)(null);
|
||
const [selectedSeatId, setSelectedSeatId] = (0, import_react.useState)(SEAT_IDS[0]);
|
||
const [draft, setDraft] = (0, import_react.useState)({});
|
||
const [busy, setBusy] = (0, import_react.useState)(false);
|
||
const [configOpen, setConfigOpen] = (0, import_react.useState)(false);
|
||
const [reportOpen, setReportOpen] = (0, import_react.useState)(false);
|
||
const alive = (0, import_react.useRef)(true);
|
||
(0, import_react.useEffect)(() => () => {
|
||
alive.current = false;
|
||
}, []);
|
||
const loadProject = (0, import_react.useCallback)(async () => {
|
||
setPhase("loading");
|
||
setError(null);
|
||
setErrorRetryable(true);
|
||
setNotice(null);
|
||
const workspace = currentWorkspace();
|
||
if (!workspace) {
|
||
setPhase("no-workspace");
|
||
return;
|
||
}
|
||
try {
|
||
const projectView = await request("open", {
|
||
workspaceId: workspace.workspaceId,
|
||
name: workspace.name,
|
||
path: workspace.path
|
||
});
|
||
let modelCatalog = null;
|
||
try {
|
||
modelCatalog = await request("models");
|
||
} catch (modelError) {
|
||
console.warn("[sansheng] 模型目录加载失败:", modelError && modelError.message ? modelError.message : modelError);
|
||
}
|
||
if (!alive.current) return;
|
||
setView(projectView);
|
||
setModels(modelCatalog);
|
||
setPhase("ready");
|
||
} catch (loadError) {
|
||
if (!alive.current) return;
|
||
setError(loadError && loadError.message ? loadError.message : "加载失败");
|
||
setErrorRetryable(!(loadError && loadError.retryable === false));
|
||
setPhase("error");
|
||
}
|
||
}, []);
|
||
(0, import_react.useEffect)(() => {
|
||
void loadProject();
|
||
}, [loadProject]);
|
||
const wb = buildWorkbenchView(view, { selectedSeatId, models, draft });
|
||
const seatById = (0, import_react.useMemo)(() => {
|
||
const map = {};
|
||
for (const seat of wb.seats) map[seat.id] = seat;
|
||
return map;
|
||
}, [wb.seats]);
|
||
function pickSeat(id) {
|
||
if (!id) return;
|
||
if (id !== selectedSeatId) {
|
||
setSelectedSeatId(id);
|
||
setConfigOpen(false);
|
||
}
|
||
const seat = seatById[id];
|
||
if (wb.ready && seat && seat.status === "bound") {
|
||
const rec = seatRecordOf(view, id);
|
||
if (rec && rec.sessionId) {
|
||
navigateToSession(rec.sessionId);
|
||
setNotice("已切换到" + seat.name + "会话");
|
||
return;
|
||
}
|
||
}
|
||
if (wb.ready && seat && seat.status !== "bound") setNotice("该席尚未绑定会话,先启用或重试启用");
|
||
}
|
||
function setModelValue(value) {
|
||
setDraft((prev) => updateDraft(prev, selectedSeatId, { modelValue: value }));
|
||
}
|
||
function setInstructions(value) {
|
||
setDraft((prev) => updateDraft(prev, selectedSeatId, { instructions: value }));
|
||
}
|
||
async function enableSeats() {
|
||
const projectId = view && view.project ? view.project.id : null;
|
||
if (!projectId) return;
|
||
setBusy(true);
|
||
setError(null);
|
||
setNotice("正在启用十席…");
|
||
try {
|
||
const next = await request("enable", { projectId });
|
||
if (!alive.current) return;
|
||
setView(next);
|
||
setNotice("十席已启用(建立独立会话,不自动运行模型)");
|
||
} catch (enableError) {
|
||
if (alive.current) setError(enableError && enableError.message ? enableError.message : "启用失败");
|
||
} finally {
|
||
if (alive.current) setBusy(false);
|
||
}
|
||
}
|
||
async function saveConfig() {
|
||
const projectId = view && view.project ? view.project.id : null;
|
||
if (!projectId) return;
|
||
const seatId = wb.selected.id;
|
||
const value = wb.selected.modelValue;
|
||
if (!value) {
|
||
setNotice("请先为当前角色选择模型");
|
||
return;
|
||
}
|
||
const option = findModelOption(wb.selected.modelOptions, value);
|
||
const model = option ? option.reasoningEffort ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } : { provider: option.provider, model: option.model } : null;
|
||
setBusy(true);
|
||
setError(null);
|
||
setNotice("保存中…");
|
||
try {
|
||
await request("configure", { projectId, seatId, model, instructions: wb.selected.instructions });
|
||
const next = await request("project", { projectId });
|
||
if (!alive.current) return;
|
||
setView(next);
|
||
setDraft((prev) => clearDraft(prev, seatId));
|
||
setNotice("已保存");
|
||
} catch (saveError) {
|
||
if (alive.current) setError(saveError && saveError.message ? saveError.message : "保存失败");
|
||
} finally {
|
||
if (alive.current) setBusy(false);
|
||
}
|
||
}
|
||
const seatCard = (seat) => (0, import_react.createElement)(
|
||
"button",
|
||
{
|
||
key: seat.id,
|
||
type: "button",
|
||
className: "ssw-seat",
|
||
"aria-pressed": seat.selected ? "true" : "false",
|
||
title: seat.name + " · " + seat.duty + "(" + seat.statusLabel + ")",
|
||
onClick: () => pickSeat(seat.id)
|
||
},
|
||
(0, import_react.createElement)(
|
||
"span",
|
||
{ className: "ssw-role-top" },
|
||
(0, import_react.createElement)("span", { className: "ssw-role-name" }, seat.name),
|
||
(0, import_react.createElement)("span", { className: "ssw-dot", "data-status": seat.status, "aria-hidden": "true" })
|
||
),
|
||
(0, import_react.createElement)("span", { className: "ssw-role-duty" }, seat.duty)
|
||
);
|
||
const pickList = (ids) => ids.map((id) => seatById[id]).filter(Boolean);
|
||
const tree = (0, import_react.createElement)(
|
||
"section",
|
||
{ className: "ssw-tree", "aria-label": "切换角色" },
|
||
(0, import_react.createElement)("div", { className: "ssw-lead" }, pickList(wb.groups.lead).map(seatCard)),
|
||
(0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-sansheng" },
|
||
(0, import_react.createElement)("span", { className: "ssw-group-label" }, "三省"),
|
||
(0, import_react.createElement)("div", { className: "ssw-trio" }, pickList(wb.groups.sansheng).map(seatCard))
|
||
),
|
||
(0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-ministries" },
|
||
(0, import_react.createElement)("span", { className: "ssw-group-label" }, "六部 · 尚书统筹"),
|
||
(0, import_react.createElement)("div", { className: "ssw-six" }, pickList(wb.groups.liubu).map(seatCard))
|
||
)
|
||
);
|
||
const head = (0, import_react.createElement)(
|
||
"header",
|
||
{ className: "ssw-head" },
|
||
(0, import_react.createElement)(TreeIcon),
|
||
(0, import_react.createElement)("strong", { className: "ssw-head-title" }, "工作台"),
|
||
onClose ? (0, import_react.createElement)("button", { type: "button", className: "ssw-icon-btn", onClick: onClose, "aria-label": "收起工作台" }, (0, import_react.createElement)(CloseIcon)) : null
|
||
);
|
||
const projectInfo = (0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-project" },
|
||
(0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-project-line" },
|
||
(0, import_react.createElement)("span", { className: "ssw-eyebrow" }, (0, import_react.createElement)(FolderIcon), "当前项目"),
|
||
(0, import_react.createElement)("span", { className: "ssw-count" }, wb.project.seatCount + " 个角色 · " + wb.project.sessionCount + " 个会话")
|
||
),
|
||
(0, import_react.createElement)("div", { className: "ssw-project-title" }, wb.projectTitle || "未命名项目")
|
||
);
|
||
const enableBlock = !wb.ready ? (0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-enable" },
|
||
(0, import_react.createElement)("p", { className: "ssw-enable-note" }, "这个项目还没有启用十席。启用会建立十个独立会话,但不会自动运行模型。"),
|
||
(0, import_react.createElement)("button", {
|
||
type: "button",
|
||
className: "ssw-primary",
|
||
disabled: busy,
|
||
onClick: enableSeats
|
||
}, busy ? "正在启用…" : "启用此项目的十席")
|
||
) : null;
|
||
const currentCard = (0, import_react.createElement)(
|
||
"section",
|
||
{ className: "ssw-current" },
|
||
(0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-current-top" },
|
||
(0, import_react.createElement)("strong", { className: "ssw-current-name" }, wb.selected.name),
|
||
(0, import_react.createElement)("span", { className: "ssw-current-label" }, "角色职责 · " + wb.selected.statusLabel)
|
||
),
|
||
(0, import_react.createElement)("p", { className: "ssw-current-text" }, wb.selected.responsibility)
|
||
);
|
||
const optionEls = wb.selected.modelOptions.map((option) => (0, import_react.createElement)("option", { key: option.value, value: option.value }, option.label));
|
||
if (wb.selected.modelValue && !wb.selected.modelOptions.some((option) => option.value === wb.selected.modelValue)) {
|
||
optionEls.push((0, import_react.createElement)("option", { key: "__current__", value: wb.selected.modelValue }, wb.selected.modelLabel));
|
||
}
|
||
const config = (0, import_react.createElement)(
|
||
"section",
|
||
{ className: "ssw-config" },
|
||
(0, import_react.createElement)(
|
||
"button",
|
||
{
|
||
type: "button",
|
||
className: "ssw-config-toggle",
|
||
"aria-expanded": configOpen ? "true" : "false",
|
||
onClick: () => setConfigOpen((value) => !value)
|
||
},
|
||
(0, import_react.createElement)(GearIcon),
|
||
(0, import_react.createElement)("span", null, "配置" + wb.selected.name + (wb.selected.dirty ? " · 未保存" : "")),
|
||
(0, import_react.createElement)(ChevronIcon)
|
||
),
|
||
configOpen ? (0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-config-body" },
|
||
(0, import_react.createElement)("label", { className: "ssw-label" }, "会话模型"),
|
||
(0, import_react.createElement)(
|
||
"select",
|
||
{
|
||
className: "ssw-field",
|
||
value: wb.selected.modelValue,
|
||
disabled: busy,
|
||
onChange: (event) => setModelValue(event.target.value)
|
||
},
|
||
(0, import_react.createElement)("option", { value: "", disabled: true }, UNCHOSEN_MODEL_LABEL),
|
||
...optionEls
|
||
),
|
||
(0, import_react.createElement)("label", { className: "ssw-label" }, "角色补充说明"),
|
||
(0, import_react.createElement)("textarea", {
|
||
className: "ssw-field ssw-textarea",
|
||
rows: 4,
|
||
value: wb.selected.instructions,
|
||
disabled: busy,
|
||
placeholder: "补充该角色在当前项目中的工作要求",
|
||
onChange: (event) => setInstructions(event.target.value)
|
||
}),
|
||
(0, import_react.createElement)("p", { className: "ssw-scope-note" }, "每个角色是独立会话;模型与说明只影响当前项目当前角色,不改变宿主默认模型。"),
|
||
(0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-save-row" },
|
||
(0, import_react.createElement)("button", { type: "button", className: "ssw-primary", disabled: busy, onClick: saveConfig }, busy ? "保存中…" : "保存配置"),
|
||
wb.selected.dirty ? (0, import_react.createElement)("span", { className: "ssw-save-status" }, "有未保存修改") : null
|
||
)
|
||
) : null
|
||
);
|
||
const report = (0, import_react.createElement)(
|
||
"section",
|
||
{ className: "ssw-report" },
|
||
(0, import_react.createElement)("button", {
|
||
type: "button",
|
||
className: "ssw-report-toggle",
|
||
"aria-expanded": reportOpen ? "true" : "false",
|
||
onClick: () => setReportOpen((value) => !value)
|
||
}, reportOpen ? "收起职责汇报" : "全部汇报职责"),
|
||
reportOpen ? (0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-report-list" },
|
||
SEAT_IDS.map((id) => {
|
||
const rec = seatRecordOf(view, id);
|
||
const m = rec && rec.model;
|
||
const modelLabel = m && m.model ? m.model + (m.reasoningEffort ? " · " + m.reasoningEffort : "") : "未选择模型";
|
||
return (0, import_react.createElement)(
|
||
"div",
|
||
{ key: id, className: "ssw-report-item", "data-seat": id },
|
||
(0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-report-head" },
|
||
(0, import_react.createElement)("strong", null, SEATS[id].label),
|
||
(0, import_react.createElement)("span", null, SEATS[id].duty)
|
||
),
|
||
(0, import_react.createElement)("p", { className: "ssw-report-model" }, "模型:" + modelLabel),
|
||
(0, import_react.createElement)("p", { className: "ssw-report-text" }, SEATS[id].responsibility)
|
||
);
|
||
})
|
||
) : null
|
||
);
|
||
const statusEl = error ? (0, import_react.createElement)("p", { className: "ssw-error", role: "alert" }, error) : notice ? (0, import_react.createElement)("p", { className: "ssw-notice", role: "status" }, notice) : null;
|
||
let body;
|
||
if (phase === "loading") body = (0, import_react.createElement)("div", { className: "ssw-loading" }, "正在加载工作台…");
|
||
else if (phase === "no-workspace") body = (0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-empty" },
|
||
(0, import_react.createElement)("p", null, "请先选择项目"),
|
||
(0, import_react.createElement)("p", { className: "ssw-hint" }, "在左侧工作区里选中一个项目后再打开三省六部。"),
|
||
(0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: loadProject }, "重新检查")
|
||
);
|
||
else if (phase === "error" && !view) body = (0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-empty" },
|
||
(0, import_react.createElement)("p", { className: "ssw-error" }, error || "加载失败"),
|
||
errorRetryable ? (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: loadProject }, "重试") : null
|
||
);
|
||
else body = (0, import_react.createElement)(import_react.Fragment, null, projectInfo, enableBlock, tree, report, currentCard, config, statusEl);
|
||
return (0, import_react.createElement)("div", { className: "ssw-root ssw-scope" }, head, body);
|
||
}
|
||
const NAV_PANEL_ID = "sansheng-workbench";
|
||
const NAV_ORDER = 32;
|
||
function openRightWorkbench() {
|
||
return tryOpenRightTab();
|
||
}
|
||
function closeRightWorkbench() {
|
||
const layout = get("layout");
|
||
if (layout && isFn(layout.selectPanel)) {
|
||
try {
|
||
layout.selectPanel(null);
|
||
return;
|
||
} catch {
|
||
}
|
||
}
|
||
const right = get("sidebarRight");
|
||
if (right && isFn(right.closeTab)) {
|
||
try {
|
||
right.closeTab(TAB_KIND);
|
||
return;
|
||
} catch {
|
||
}
|
||
}
|
||
}
|
||
function SanshengNavButton(props) {
|
||
const size = props && typeof props.size === "number" ? props.size : 16;
|
||
const [floating, setFloating] = (0, import_react.useState)(false);
|
||
const onClick = (event) => {
|
||
if (event && isFn(event.stopPropagation)) event.stopPropagation();
|
||
if (event && isFn(event.preventDefault)) event.preventDefault();
|
||
if (openRightWorkbench()) {
|
||
setFloating(false);
|
||
return;
|
||
}
|
||
setFloating((value) => !value);
|
||
};
|
||
let panel = null;
|
||
if (floating) {
|
||
const card = (0, import_react.createElement)(
|
||
"div",
|
||
{ className: "ssw-float", role: "dialog", "aria-label": "三省六部工作台" },
|
||
(0, import_react.createElement)(SanshengWorkbench, { onClose: () => setFloating(false) })
|
||
);
|
||
const canPortal = typeof document !== "undefined" && document.body && isFn(import_react_dom.createPortal);
|
||
panel = canPortal ? (0, import_react_dom.createPortal)(card, document.body) : card;
|
||
}
|
||
return (0, import_react.createElement)(
|
||
import_react.Fragment,
|
||
null,
|
||
(0, import_react.createElement)("span", {
|
||
className: "ssw-nav-hit",
|
||
role: "presentation",
|
||
title: "三省六部",
|
||
onClick,
|
||
"aria-expanded": floating ? "true" : "false"
|
||
}, (0, import_react.createElement)(TreeIcon, { width: size, height: size })),
|
||
panel
|
||
);
|
||
}
|
||
function SanshengNavFallback() {
|
||
const [mode, setMode] = (0, import_react.useState)("pending");
|
||
(0, import_react.useEffect)(() => {
|
||
setMode(openRightWorkbench() ? "docked" : "inline");
|
||
}, []);
|
||
(0, import_react.useEffect)(() => {
|
||
if (mode !== "docked") return;
|
||
const layout = get("layout");
|
||
if (layout && isFn(layout.selectPanel)) {
|
||
try {
|
||
layout.selectPanel(null);
|
||
} catch {
|
||
}
|
||
}
|
||
}, [mode]);
|
||
if (mode !== "inline") return null;
|
||
return (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {
|
||
onClose: () => {
|
||
const layout = get("layout");
|
||
if (layout && isFn(layout.selectPanel)) {
|
||
try {
|
||
layout.selectPanel(null);
|
||
} catch {
|
||
}
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
function registerNavEntry() {
|
||
if (!ctx.slots || !isFn(ctx.slots.inject) || !isFn(ctx.slots.register)) {
|
||
console.warn("[sansheng] 宿主未提供 slots.inject / slots.register,无法注册左侧导航入口");
|
||
return;
|
||
}
|
||
try {
|
||
ctx.slots.inject("main", () => ctx.slots.inject("sidebar.panellist", () => {
|
||
const disposers = [];
|
||
const disposeAll = () => {
|
||
for (const dispose of disposers.splice(0)) {
|
||
try {
|
||
if (isFn(dispose)) dispose();
|
||
} catch {
|
||
}
|
||
}
|
||
};
|
||
try {
|
||
disposers.push(ctx.slots.register({ name: "main", key: NAV_PANEL_ID, inject: () => ({}) }, SanshengNavFallback));
|
||
disposers.push(ctx.slots.register({ name: "sidebar.panellist", id: NAV_PANEL_ID, order: NAV_ORDER, label: () => "三省六部" }, SanshengNavButton));
|
||
} catch (error) {
|
||
disposeAll();
|
||
console.warn("[sansheng] 注册左侧导航入口失败:", error && error.message ? error.message : error);
|
||
return void 0;
|
||
}
|
||
return disposeAll;
|
||
}));
|
||
} catch (error) {
|
||
console.warn("[sansheng] 注册左侧导航入口失败:", error && error.message ? error.message : error);
|
||
}
|
||
}
|
||
registerNavEntry();
|
||
registerRightTabType();
|
||
try {
|
||
install(ctx);
|
||
} catch (error) {
|
||
console.warn("[sansheng] 原生面板注册失败:", error && error.message ? error.message : error);
|
||
}
|
||
}
|
||
return Object.defineProperty({ ...module.exports }, Symbol.toStringTag, { value: 'Module' })
|
||
},
|
||
})
|