dsh-sansheng-liubu/client.js

1901 lines
83 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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:#f8fafc;--ssw-card:#ffffff;--ssw-line:#e3e8ef;--ssw-strong:#c7d8f5;--ssw-ink:#0f172a;--ssw-muted:#667085;--ssw-faint:#98a2b3;--ssw-blue:#4263eb;--ssw-wash:#eef2ff;--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 :where(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{container-type:inline-size;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:22px 20px 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:21px;font-weight:650;letter-spacing:.5px;margin:4px 0 16px}
.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{min-height:36px;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:24px 20px 4px;position:relative}
.ssw-lead{width:168px;margin:0 auto;position:relative}
.ssw-lead::after{content:none}
.ssw-sansheng{position:relative;margin-top:24px}
.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:14px 12px 12px;border:1px solid var(--ssw-line);border-radius:12px;background:var(--ssw-card);text-align:left;min-height:80px;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{min-height:84px}
.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:11px;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:flex;align-items:center;gap:10px;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:76px;padding:12px}
.ssw-report{padding:0 20px;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:14px 20px 0;padding:16px;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 20px 20px;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)}
.ssw-current-actions{margin-top:10px;display:flex;gap:8px}
.ssw-inline-bar{flex:none;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:8px 12px;border-bottom:1px solid var(--ssw-line);background:var(--ssw-card);font-size:12px;color:var(--ssw-muted)}
.ssw-link{color:var(--ssw-blue);font-size:12px;padding:2px 4px}
@media (prefers-reduced-motion:reduce){.ssw-scope *{transition:none!important}}
.ssw-tabs{display:flex;gap:6px;margin:0 20px;padding:4px;border:1px solid var(--ssw-line);border-radius:12px;background:var(--ssw-side)}
.ssw-tab{flex:1;display:flex;align-items:center;justify-content:center;gap:6px;padding:7px 6px;border-radius:6px;font-size:12px;color:var(--ssw-muted)}
.ssw-tab.is-active{background:var(--ssw-card);color:var(--ssw-blue);font-weight:600;box-shadow:0 1px 2px rgba(16,24,40,.06)}
.ssw-tab-count{font-size:10px;color:var(--ssw-faint)}
.ssw-page{padding:12px 16px 0}
.ssw-page-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px}
.ssw-page-head strong{font-size:13px}
.ssw-list{display:flex;flex-direction:column;gap:8px}
.ssw-row{border:1px solid var(--ssw-line);border-radius:9px;padding:9px 11px;background:var(--ssw-card)}
.ssw-row-top{display:flex;align-items:center;justify-content:space-between;gap:8px}
.ssw-row-title{font-size:13px}
.ssw-row-meta{margin:4px 0 0;font-size:11px;color:var(--ssw-muted)}
.ssw-row-note{margin:4px 0 0;font-size:10px;color:var(--ssw-faint)}
.ssw-row-actions{display:flex;gap:10px;margin-top:6px}
.ssw-link{color:var(--ssw-blue);font-size:12px;padding:2px 2px}
.ssw-link-muted{color:var(--ssw-muted)}
.ssw-badge{font-size:10px;padding:2px 6px;border-radius:999px;background:var(--ssw-wash);color:var(--ssw-blue)}
.ssw-badge[data-status=done]{background:rgba(22,163,74,.12);color:var(--ssw-ok)}
.ssw-badge[data-status=cancelled]{background:rgba(107,114,128,.14);color:var(--ssw-muted)}
.ssw-badge[data-status=failed]{background:rgba(220,38,38,.12);color:var(--ssw-danger)}
.ssw-form{margin-bottom:12px;padding:10px;border:1px solid var(--ssw-line);border-radius:9px;background:var(--ssw-side)}
.ssw-empty-line{margin:10px 0;font-size:12px;color:var(--ssw-faint)}
.ssw-project-line{align-items:baseline;margin-bottom:10px}
.ssw-project-title{margin:0}
.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-group-label::after{content:"";height:1px;background:var(--ssw-line);flex:1}
.ssw-role-top{width:100%}
.ssw-tab-count{padding:1px 5px;border-radius:5px;background:var(--ssw-rail)}
.ssw-current-name{font-size:15px;letter-spacing:1px}
.ssw-current-label{padding:3px 7px;border-radius:5px;background:var(--ssw-side)}
.ssw-config-toggle:hover{background:var(--ssw-side)}
/* 按工作台本身的宽度适配:宽屏居中,右侧窄栏保持紧凑。 */
.ssw-root > :is(.ssw-project,.ssw-tree,.ssw-report,.ssw-page){width:100%;max-width:720px;align-self:center;flex-shrink:0}
.ssw-root > :is(.ssw-tabs,.ssw-current,.ssw-config,.ssw-enable,.ssw-notice,.ssw-error){width:calc(100% - 40px);max-width:680px;margin-left:auto;margin-right:auto;flex-shrink:0}
.ssw-enable{margin-top:12px}
@container(max-width:380px){.ssw-root > :is(.ssw-tabs,.ssw-current,.ssw-config,.ssw-enable,.ssw-notice,.ssw-error){width:calc(100% - 24px);margin-left:auto;margin-right:auto}
.ssw-project{padding:16px 12px 0}.ssw-tabs{margin:0 12px}.ssw-tree{padding:20px 12px 4px}.ssw-current{margin:12px 12px 0}.ssw-config{margin:10px 12px 16px}.ssw-report{padding:0 12px}.ssw-trio,.ssw-six{gap:6px}.ssw-seat,.ssw-six .ssw-seat{padding:10px 8px}.ssw-role-duty{font-size:10px}}
/* 窄栏隐藏职责小字,避免被卡片宽度截断 */
@container (max-width:420px){
.ssw-role-duty{display:none}
.ssw-seat{min-height:52px;padding:10px 9px;gap:0}
.ssw-six{grid-template-columns:repeat(2,minmax(0,1fr))}
.ssw-six .ssw-seat{min-height:50px;padding:10px 9px}
}
`;
// 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" }));
var SEAT_ICON_PATHS = {
lead: ["M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8Z", "M4.5 20c0-3.2 3.4-5 7.5-5s7.5 1.8 7.5 5"],
zhongshu: ["M7 3h7l4 4v14H7z", "M14 3v4h4", "M9.5 12h5", "M9.5 16h5"],
shangshu: ["M4 4h6.5v6.5H4z", "M13.5 4H20v6.5h-6.5z", "M4 13.5h6.5V20H4z", "M13.5 13.5H20V20h-6.5z"],
menxia: ["M12 3l7 3v6c0 4-3 7-7 9-4-2-7-5-7-9V6z", "m9 12 2 2 4-4"],
libu: ["M12 11a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Z", "M5 20c0-3 3-4.5 7-4.5s7 1.5 7 4.5"],
hubu: ["M4 5h16v14H4z", "M4 10h16", "M10 5v14"],
lipu: ["M7 3h10v18H7z", "M10 8h4", "M10 12h4", "M10 16h4"],
bingbu: ["M4 5h16v12H4z", "m8 13 3-6 5 6", "M4 20h16"],
xingbu: ["M6 3h12v18l-6-3-6 3z", "m9 10 2 2 4-4"],
gongbu: ["m8 8-4 4 4 4", "m16 8 4 4-4 4", "M13 5l-2 14"]
};
function SeatIcon(props) {
const paths = SEAT_ICON_PATHS[props && props.id] ?? SEAT_ICON_PATHS.lead;
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",
className: "ssw-seat-icon"
}, paths.map((d, index) => (0, import_react.createElement)("path", { key: index, d })));
}
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 bs = get("betterSidebar");
if (bs && isFn(bs.openTab)) {
try {
const snap = isFn(bs.getSnapshot) ? bs.getSnapshot() : null;
const sessionId = snap && typeof snap === "object" ? snap.sessionId : void 0;
if (!sessionId) return false;
bs.openTab({ type: TAB_KIND, title: "三省六部" });
for (const delay of [200, 600, 1200]) setTimeout(revealRightTab, delay);
return true;
} catch (error) {
console.warn("[sansheng] better-sidebar 打开失败,改用宿主接口:", error && error.message ? error.message : error);
}
}
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();
for (const delay of [150, 500, 1200]) setTimeout(revealRightTab, delay);
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 {
const bs = get("betterSidebar");
if (bs && isFn(bs.registerTab)) {
const dispose = bs.registerTab({
id: TAB_KIND,
title: "三省六部",
description: "十席角色与独立会话的当前项目工作台",
icon: (size) => (0, import_react.createElement)(TreeIcon, { width: size, height: size }),
order: 32,
single: true,
component: () => (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {}))
});
return () => {
try {
if (isFn(dispose)) dispose();
} catch {
}
};
}
} catch (error) {
console.warn("[sansheng] 注册 better-sidebar 标签失败:", error && error.message ? error.message : error);
}
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 [tab, setTab] = (0, import_react.useState)("court");
const [tasks, setTasks] = (0, import_react.useState)([]);
const [artifacts, setArtifacts] = (0, import_react.useState)([]);
const [taskFormOpen, setTaskFormOpen] = (0, import_react.useState)(false);
const [taskDraft, setTaskDraft] = (0, import_react.useState)({ title: "", goal: "", ownerSeatId: SEAT_IDS[0] });
const [artifactFormOpen, setArtifactFormOpen] = (0, import_react.useState)(false);
const [artifactDraft, setArtifactDraft] = (0, import_react.useState)({ title: "", path: "", summary: "" });
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);
}
let taskList = [];
let artifactList = [];
try {
taskList = (await request("tasks", { projectId: projectView.project.id })).tasks ?? [];
} catch (taskError) {
console.warn("[sansheng] 任务加载失败:", taskError && taskError.message ? taskError.message : taskError);
}
try {
artifactList = (await request("artifacts", { projectId: projectView.project.id })).artifacts ?? [];
} catch (artifactError) {
console.warn("[sansheng] 成果加载失败:", artifactError && artifactError.message ? artifactError.message : artifactError);
}
if (!alive.current) return;
setView(projectView);
setModels(modelCatalog);
setTasks(taskList);
setArtifacts(artifactList);
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 (seat && seat.status !== "bound" && seat.status !== "creating") setNotice("「" + seat.name + "」还没开启,点下面的按钮开启这个部门");
}
function openSelectedSeat() {
const seat = seatById[wb.selected.id];
if (!seat) return;
if (seat.status !== "bound") {
setNotice("「" + seat.name + "」还没开启,先点「开启『" + seat.name + "』」");
return;
}
const rec = seatRecordOf(view, seat.id);
if (rec && rec.sessionId) {
navigateToSession(rec.sessionId);
setNotice("已切换到" + seat.name + "会话");
}
}
function setModelValue(value) {
setDraft((prev) => updateDraft(prev, selectedSeatId, { modelValue: value }));
}
function setInstructions(value) {
setDraft((prev) => updateDraft(prev, selectedSeatId, { instructions: value }));
}
async function enableSelectedSeat() {
const projectId = view && view.project ? view.project.id : null;
if (!projectId) return;
const seatId = wb.selected.id;
setBusy(true);
setError(null);
setNotice("正在开启「" + wb.selected.name + "」…");
try {
const next = await request("enableSeat", { projectId, seatId });
if (!alive.current) return;
setView(next);
setNotice("已开启「" + wb.selected.name + "」的独立会话");
try {
tryOpenRightTab();
} catch {
}
} catch (enableError) {
if (alive.current) setError(enableError && enableError.message ? enableError.message : "开启失败");
} finally {
if (alive.current) setBusy(false);
}
}
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);
}
}
async function reloadTasks(projectId) {
try {
const result = await request("tasks", { projectId });
if (alive.current) setTasks(result.tasks ?? []);
} catch (error2) {
if (alive.current) setNotice(error2 && error2.message ? error2.message : "任务列表刷新失败");
}
}
async function createTask() {
const projectId = view && view.project ? view.project.id : null;
if (!projectId) return;
const title = taskDraft.title.trim();
if (!title) {
setNotice("任务标题不能为空");
return;
}
setBusy(true);
setError(null);
try {
await request("taskCreate", { projectId, title, goal: taskDraft.goal, ownerSeatId: taskDraft.ownerSeatId });
setTaskDraft({ title: "", goal: "", ownerSeatId: taskDraft.ownerSeatId });
setTaskFormOpen(false);
await reloadTasks(projectId);
setNotice("已存为草稿;点「派工」才会交给部门。");
} catch (error2) {
if (alive.current) setError(error2 && error2.message ? error2.message : "新建任务失败");
} finally {
if (alive.current) setBusy(false);
}
}
async function dispatchTask(taskId) {
const projectId = view && view.project ? view.project.id : null;
if (!projectId) return;
setBusy(true);
setError(null);
try {
const result = await request("taskDispatch", { projectId, taskId });
await reloadTasks(projectId);
setNotice(result.delivered ? "已派工到该部门会话。" : "已记录为待执行(当前宿主暂不支持直接发送)。");
} catch (error2) {
if (alive.current) setError(error2 && error2.message ? error2.message : "派工失败");
} finally {
if (alive.current) setBusy(false);
}
}
async function cancelTask(taskId) {
const projectId = view && view.project ? view.project.id : null;
if (!projectId) return;
setBusy(true);
setError(null);
try {
await request("taskCancel", { projectId, taskId });
await reloadTasks(projectId);
setNotice("任务已取消。");
} catch (error2) {
if (alive.current) setError(error2 && error2.message ? error2.message : "取消失败");
} finally {
if (alive.current) setBusy(false);
}
}
async function addArtifact() {
const projectId = view && view.project ? view.project.id : null;
if (!projectId) return;
const title = artifactDraft.title.trim();
if (!title) {
setNotice("成果名称不能为空");
return;
}
setBusy(true);
setError(null);
try {
const result = await request("artifactAdd", { projectId, title, path: artifactDraft.path, summary: artifactDraft.summary });
setArtifactDraft({ title: "", path: "", summary: "" });
setArtifactFormOpen(false);
setArtifacts((list) => [...list, result.artifact]);
setNotice("成果已登记。");
} catch (error2) {
if (alive.current) setError(error2 && error2.message ? error2.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", style: { justifyContent: "flex-end" } },
(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 selectedStatus = wb.selected.status;
const detailActions = (0, import_react.createElement)(
"div",
{ className: "ssw-current-actions" },
selectedStatus === "bound" ? (0, import_react.createElement)("button", {
type: "button",
className: "ssw-primary",
disabled: busy,
onClick: openSelectedSeat
}, "开始对话") : (0, import_react.createElement)("button", {
type: "button",
className: "ssw-primary",
disabled: busy || selectedStatus === "creating",
onClick: enableSelectedSeat
}, selectedStatus === "creating" ? "正在开启…" : "开启「" + wb.selected.name + "」")
);
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;
const tabCounts = { court: wb.project.seatCount, tasks: tasks.length, artifacts: artifacts.length };
const tabBar = (0, import_react.createElement)(
"div",
{ className: "ssw-tabs", role: "tablist" },
[["court", "朝堂"], ["tasks", "任务"], ["artifacts", "成果"]].map(([id, label]) => (0, import_react.createElement)("button", {
key: id,
type: "button",
role: "tab",
"aria-selected": tab === id ? "true" : "false",
className: "ssw-tab" + (tab === id ? " is-active" : ""),
onClick: () => setTab(id)
}, (0, import_react.createElement)("span", null, label), (0, import_react.createElement)("span", { className: "ssw-tab-count" }, String(tabCounts[id] ?? 0))))
);
const TASK_STATUS_LABEL = { draft: "草稿", prepared: "待执行", dispatched: "已派工", done: "已完成", cancelled: "已取消", failed: "失败" };
const taskRows = tasks.length === 0 ? (0, import_react.createElement)("p", { className: "ssw-empty-line" }, "这个项目还没有任务。点「新建任务」先存一张草稿。") : tasks.map((task) => (0, import_react.createElement)(
"article",
{ key: task.id, className: "ssw-row", "data-task": task.id },
(0, import_react.createElement)(
"div",
{ className: "ssw-row-top" },
(0, import_react.createElement)("strong", { className: "ssw-row-title" }, task.title),
(0, import_react.createElement)("span", { className: "ssw-badge", "data-status": task.status }, TASK_STATUS_LABEL[task.status] ?? task.status)
),
(0, import_react.createElement)("p", { className: "ssw-row-meta" }, (SEATS[task.ownerSeatId]?.label ?? task.ownerSeatId) + (task.goal ? " · " + task.goal : "")),
task.note ? (0, import_react.createElement)("p", { className: "ssw-row-note" }, task.note) : null,
(0, import_react.createElement)(
"div",
{ className: "ssw-row-actions" },
task.status === "draft" || task.status === "prepared" || task.status === "failed" ? (0, import_react.createElement)("button", { type: "button", className: "ssw-link", disabled: busy, onClick: () => dispatchTask(task.id) }, task.status === "prepared" ? "重试派工" : "派工") : null,
task.status !== "done" && task.status !== "cancelled" ? (0, import_react.createElement)("button", { type: "button", className: "ssw-link ssw-link-muted", disabled: busy, onClick: () => cancelTask(task.id) }, "取消") : null
)
));
const taskView = (0, import_react.createElement)(
"section",
{ className: "ssw-page" },
(0, import_react.createElement)(
"div",
{ className: "ssw-page-head" },
(0, import_react.createElement)("strong", null, "任务 · " + tasks.length),
(0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: () => setTaskFormOpen((value) => !value) }, taskFormOpen ? "收起" : "新建任务")
),
taskFormOpen ? (0, import_react.createElement)(
"form",
{ className: "ssw-form", onSubmit: (event) => {
event.preventDefault();
void createTask();
} },
(0, import_react.createElement)("label", { className: "ssw-label" }, "标题"),
(0, import_react.createElement)("input", { className: "ssw-field", value: taskDraft.title, placeholder: "交给部门做什么", onChange: (event) => setTaskDraft({ ...taskDraft, title: event.target.value }) }),
(0, import_react.createElement)("label", { className: "ssw-label" }, "目标(可选)"),
(0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: taskDraft.goal, onChange: (event) => setTaskDraft({ ...taskDraft, goal: event.target.value }) }),
(0, import_react.createElement)("label", { className: "ssw-label" }, "主责部门"),
(0, import_react.createElement)(
"select",
{ className: "ssw-field", value: taskDraft.ownerSeatId, onChange: (event) => setTaskDraft({ ...taskDraft, ownerSeatId: event.target.value }) },
SEAT_IDS.map((id) => (0, import_react.createElement)("option", { key: id, value: id }, SEATS[id].label))
),
(0, import_react.createElement)("div", { className: "ssw-save-row" }, (0, import_react.createElement)("button", { type: "submit", className: "ssw-primary", disabled: busy }, busy ? "保存中…" : "保存草稿"))
) : null,
(0, import_react.createElement)("div", { className: "ssw-list" }, taskRows)
);
const artifactRows = artifacts.length === 0 ? (0, import_react.createElement)("p", { className: "ssw-empty-line" }, "这个项目还没有登记成果。") : artifacts.map((item) => (0, import_react.createElement)(
"article",
{ key: item.id, className: "ssw-row", "data-artifact": item.id },
(0, import_react.createElement)("div", { className: "ssw-row-top" }, (0, import_react.createElement)("strong", { className: "ssw-row-title" }, item.title)),
item.summary ? (0, import_react.createElement)("p", { className: "ssw-row-meta" }, item.summary) : null,
item.path ? (0, import_react.createElement)("p", { className: "ssw-row-note" }, item.path) : null
));
const artifactView = (0, import_react.createElement)(
"section",
{ className: "ssw-page" },
(0, import_react.createElement)(
"div",
{ className: "ssw-page-head" },
(0, import_react.createElement)("strong", null, "成果 · " + artifacts.length),
(0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: () => setArtifactFormOpen((value) => !value) }, artifactFormOpen ? "收起" : "登记成果")
),
artifactFormOpen ? (0, import_react.createElement)(
"form",
{ className: "ssw-form", onSubmit: (event) => {
event.preventDefault();
void addArtifact();
} },
(0, import_react.createElement)("label", { className: "ssw-label" }, "成果名称"),
(0, import_react.createElement)("input", { className: "ssw-field", value: artifactDraft.title, onChange: (event) => setArtifactDraft({ ...artifactDraft, title: event.target.value }) }),
(0, import_react.createElement)("label", { className: "ssw-label" }, "文件路径(可选)"),
(0, import_react.createElement)("input", { className: "ssw-field", value: artifactDraft.path, onChange: (event) => setArtifactDraft({ ...artifactDraft, path: event.target.value }) }),
(0, import_react.createElement)("label", { className: "ssw-label" }, "说明(可选)"),
(0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: artifactDraft.summary, onChange: (event) => setArtifactDraft({ ...artifactDraft, summary: event.target.value }) }),
(0, import_react.createElement)("div", { className: "ssw-save-row" }, (0, import_react.createElement)("button", { type: "submit", className: "ssw-primary", disabled: busy }, busy ? "保存中…" : "保存"))
) : null,
(0, import_react.createElement)("div", { className: "ssw-list" }, artifactRows)
);
const detail = (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),
detailActions
);
const courtView = (0, import_react.createElement)(import_react.Fragment, null, tree, detail, config);
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,
tabBar,
tab === "tasks" ? taskView : tab === "artifacts" ? artifactView : courtView,
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 stop = (event) => {
if (event && isFn(event.stopPropagation)) event.stopPropagation();
};
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,
onPointerDown: stop,
onMouseDown: stop,
"aria-expanded": floating ? "true" : "false"
}, (0, import_react.createElement)(TreeIcon, { width: size, height: size })),
panel
);
}
function backToChat() {
const layout = get("layout");
if (layout && isFn(layout.selectPanel)) {
try {
layout.selectPanel(null);
} catch {
}
}
}
function SanshengNavFallback() {
const [mode, setMode] = (0, import_react.useState)("pending");
(0, import_react.useEffect)(() => {
const hasBetter = !!get("betterSidebar");
backToChat();
if (!hasBetter) {
const timer = setTimeout(() => {
if (!openRightWorkbench()) setMode("inline");
}, 400);
return () => clearTimeout(timer);
}
for (const delay of [200, 600, 1200, 2e3]) {
setTimeout(() => {
try {
if (openRightWorkbench()) backToChat();
} catch {
}
}, delay);
}
}, []);
(0, import_react.useEffect)(() => {
if (mode !== "docked") return;
backToChat();
const timer = setTimeout(backToChat, 700);
return () => clearTimeout(timer);
}, [mode]);
if (mode === "pending") return null;
if (mode === "docked") return null;
return (0, import_react.createElement)(
"div",
{ className: "ssw-tab-body" },
(0, import_react.createElement)(
"div",
{ className: "ssw-inline-bar" },
(0, import_react.createElement)("span", null, "右侧工作台未能打开,先显示在这里"),
(0, import_react.createElement)("button", { type: "button", className: "ssw-link", onClick: backToChat }, "返回对话")
),
(0, import_react.createElement)(SanshengWorkbench, {})
);
}
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' })
},
})