dsh-sansheng-liubu/sansheng/client.js

3000 lines
148 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/workbench-v2.js
var import_react = require("react");
var TODAY = () => {
const d = /* @__PURE__ */ new Date();
d.setHours(0, 0, 0, 0);
return d.getTime();
};
var TASK_LABELS = {
draft: "待派发",
dispatched: "已派发",
running: "进行中",
prepared: "待复核",
done: "已完成",
cancelled: "已取消",
failed: "失败"
};
var TASK_TONES = {
draft: "idle",
dispatched: "review",
running: "run",
prepared: "review",
done: "done",
cancelled: "idle",
failed: "fail"
};
var OPEN_STATUS = /* @__PURE__ */ new Set(["dispatched", "running", "prepared"]);
function toneOfSeat(seat) {
if (!seat) return "idle";
if (seat.status === "bound" || seat.status === "creating") return "run";
if (seat.status === "failed" || seat.status === "missing") return "fail";
return "idle";
}
function seatStateText(seat) {
if (!seat) return "待命";
if (seat.status === "bound") return "运行中";
if (seat.status === "creating") return "开启中";
if (seat.status === "missing") return "会话缺失";
if (seat.status === "failed") return "创建失败";
return "待命";
}
function taskTone(status) {
return TASK_TONES[status] || "idle";
}
function taskLabel(status) {
return TASK_LABELS[status] || status || "未知";
}
function pad2(n) {
return String(n).padStart(2, "0");
}
function clockText(ts) {
const n = Number(ts);
if (!Number.isFinite(n) || n <= 0) return "—";
const d = new Date(n);
return pad2(d.getHours()) + ":" + pad2(d.getMinutes());
}
function dateText(ts) {
const n = Number(ts);
if (!Number.isFinite(n) || n <= 0) return "—";
const d = new Date(n);
return d.getMonth() + 1 + "-" + pad2(d.getDate()) + " " + clockText(n);
}
function durationText(ms) {
const n = Number(ms);
if (!Number.isFinite(n) || n <= 0) return "—";
const total = Math.round(n / 1e3);
const sec = total % 60;
const min = Math.floor(total / 60) % 60;
const hour = Math.floor(total / 3600);
if (hour > 0) return hour + "h " + min + "m";
if (min > 0) return min + "m " + pad2(sec) + "s";
return sec + "s";
}
function dateLabel() {
try {
return new Intl.DateTimeFormat("zh-CN", { weekday: "long", year: "numeric", month: "long", day: "numeric" }).format(/* @__PURE__ */ new Date());
} catch {
return "";
}
}
function fileIcon(paths, size) {
return (0, import_react.createElement)(
"svg",
{ viewBox: "0 0 24 24", width: size || 16, height: size || 16, fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" },
paths.map((d, i) => (0, import_react.createElement)("path", { key: i, d }))
);
}
var RefreshIcon = () => fileIcon(["M21 12a9 9 0 1 1-2.64-6.36", "M21 3v6h-6"]);
var ChatIcon = () => fileIcon(["M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"]);
var PlusIcon = () => fileIcon(["M12 5v14", "M5 12h14"]);
var SearchIcon = () => (0, import_react.createElement)("svg", { viewBox: "0 0 24 24", width: 15, height: 15, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true" }, (0, import_react.createElement)("circle", { cx: 11, cy: 11, r: 8 }), (0, import_react.createElement)("path", { d: "m21 21-4.3-4.3" }));
var ArrowIcon = () => fileIcon(["m9 18 6-6-6-6"], 15);
function seatKind(id) {
if (id === "lead") return "总协调";
if (id === "zhongshu") return "方案";
if (id === "menxia") return "审核";
if (id === "shangshu") return "调度";
return "工作";
}
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 fmtModel(rec, options) {
const described = describeModel(rec && rec.model ? rec.model : null, options);
return described.modelLabel;
}
function WorkbenchV2(props) {
const {
onClose,
resolveWorkspace,
navigateToSession,
openRightTab,
selectionCache,
getLastSeatId,
setLastSeatId
} = props || {};
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)(() => {
const saved = typeof getLastSeatId === "function" ? getLastSeatId() : null;
return SEAT_IDS.includes(saved) ? saved : SEAT_IDS[0];
});
const [tab, setTab] = (0, import_react.useState)("overview");
const [seatFilter, setSeatFilter] = (0, import_react.useState)("all");
const [queueFilter, setQueueFilter] = (0, import_react.useState)("all");
const [queueSearch, setQueueSearch] = (0, import_react.useState)("");
const [selectedTask, setSelectedTask] = (0, import_react.useState)(null);
const [taskForm, setTaskForm] = (0, import_react.useState)(null);
const [draft, setDraft] = (0, import_react.useState)({});
const [busy, setBusy] = (0, import_react.useState)(false);
const [summaryBusy, setSummaryBusy] = (0, import_react.useState)(false);
const [memory, setMemory] = (0, import_react.useState)(null);
const [memoryDraft, setMemoryDraft] = (0, import_react.useState)({ goal: "", constraints: "", acceptance: "", decisions: "" });
const [tasks, setTasks] = (0, import_react.useState)([]);
const [artifacts, setArtifacts] = (0, import_react.useState)([]);
const [artifactDraft, setArtifactDraft] = (0, import_react.useState)({ title: "", path: "", summary: "" });
const [artifactFormOpen, setArtifactFormOpen] = (0, import_react.useState)(false);
const [orgCols, setOrgCols] = (0, import_react.useState)(6);
const alive = (0, import_react.useRef)(true);
const orgRef = (0, import_react.useRef)(null);
(0, import_react.useEffect)(() => {
alive.current = true;
return () => {
alive.current = false;
};
}, []);
const loadProject = (0, import_react.useCallback)(async () => {
setPhase("loading");
setError(null);
setErrorRetryable(true);
setNotice(null);
if (typeof resolveWorkspace !== "function") {
setPhase("no-workspace");
return;
}
const workspace = resolveWorkspace();
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 memoryData = null;
try {
memoryData = (await request("memory", { projectId: projectView.project.id })).memory;
} catch {
}
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 {
}
if (!alive.current) return;
setView(projectView);
setModels(modelCatalog);
setMemory(memoryData);
setMemoryDraft({ goal: memoryData?.goal ?? "", constraints: (memoryData?.constraints ?? []).join("\n"), acceptance: (memoryData?.acceptance ?? []).join("\n"), decisions: "" });
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");
}
}, [resolveWorkspace]);
(0, import_react.useEffect)(() => {
void loadProject();
}, [loadProject]);
const projectId = view && view.project ? view.project.id : null;
(0, import_react.useEffect)(() => {
if (!projectId || !selectionCache) return;
const saved = selectionCache.get(projectId);
if (saved && SEAT_IDS.includes(saved)) setSelectedSeatId(saved);
}, [projectId, selectionCache]);
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]);
(0, import_react.useEffect)(() => {
const node = orgRef.current;
if (!node || typeof ResizeObserver === "undefined") return void 0;
const sync = () => {
const w = node.clientWidth || 0;
setOrgCols(w <= 700 ? 2 : w <= 1180 ? 3 : 6);
};
sync();
const observer = new ResizeObserver(sync);
observer.observe(node);
return () => observer.disconnect();
}, [phase, tab]);
function setSeat(id) {
if (!id || id === selectedSeatId) return;
setSelectedSeatId(id);
if (typeof setLastSeatId === "function") setLastSeatId(id);
if (projectId && selectionCache) selectionCache.set(projectId, id);
}
function setModelValue(value) {
setDraft((prev) => updateDraft(prev, selectedSeatId, { modelValue: value }));
void rememberModel(value, selectedSeatId);
}
function setInstructions(value) {
setDraft((prev) => updateDraft(prev, selectedSeatId, { instructions: value }));
}
function modelFromValue(value) {
const option = findModelOption(wb.selected.modelOptions, value);
if (option) {
return option.reasoningEffort ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } : { provider: option.provider, model: option.model };
}
const parts = String(value || "").split("::");
if (parts.length >= 2 && parts[0] && parts[1]) {
return parts[2] ? { provider: parts[0], model: parts[1], reasoningEffort: parts[2] } : { provider: parts[0], model: parts[1] };
}
return null;
}
async function rememberModel(value, seatId) {
if (!projectId || !value || !seatId) return;
const model = modelFromValue(value);
if (!model) return;
try {
const saved = await request("configure", { projectId, seatId, model });
if (!alive.current) return;
setView((prev) => {
if (!prev || !prev.project) return prev;
const seats = Array.isArray(prev.project.seats) ? prev.project.seats.map((seat) => seat && seat.id === seatId ? { ...seat, ...saved && saved.seat ? saved.seat : { model } } : seat) : prev.project.seats;
return { ...prev, revision: (prev.revision ?? 0) + 1, project: { ...prev.project, seats } };
});
setNotice("已记住「" + (SEATS[seatId]?.label ?? seatId) + "」的模型");
} catch (error2) {
if (alive.current) setNotice(error2 && error2.message ? error2.message : "模型记忆失败");
}
}
async function openSeat(seatId) {
const seat = seatById[seatId];
if (!projectId || !seat) return;
if (seat.status === "missing") {
setNotice("「" + seat.name + "」的会话已不存在,点「重建会话」可重新建立");
return;
}
if (seat.status !== "bound") {
setNotice("「" + seat.name + "」还没开启,先点「开启『" + seat.name + "』」");
return;
}
setBusy(true);
setError(null);
try {
const result = await request("openSeat", { projectId, seatId });
if (!alive.current) return;
if (!result || !result.sessionId) throw new Error("宿主没有返回会话");
navigateToSession(result.sessionId);
setNotice("已切换到「" + seat.name + "」会话");
} catch (openError) {
if (alive.current) setError(openError && openError.message ? openError.message : "打开会话失败");
if (openError && openError.code === "sansheng/session-missing") {
try {
const next = await request("project", { projectId });
if (alive.current) setView(next);
} catch {
}
}
} finally {
if (alive.current) setBusy(false);
}
}
async function rebuildSeat(seatId) {
const seat = seatById[seatId];
if (!projectId || !seat) return;
const rec = seatRecordOf(view, seatId);
setBusy(true);
setError(null);
setNotice("正在重建「" + seat.name + "」的会话…");
try {
const next = await request("rebuildSeat", { projectId, seatId, expectedSessionId: rec && rec.sessionId ? rec.sessionId : void 0 });
if (!alive.current) return;
setView(next);
setNotice("已重建「" + seat.name + "」的会话;旧会话历史仍保留");
} catch (rebuildError) {
if (alive.current) setError(rebuildError && rebuildError.message ? rebuildError.message : "重建会话失败");
if (rebuildError && rebuildError.code === "sansheng/session-conflict") {
try {
const next = await request("project", { projectId });
if (alive.current) setView(next);
} catch {
}
}
} finally {
if (alive.current) setBusy(false);
}
}
async function enableSeat(seatId) {
if (!projectId) return;
const seat = seatById[seatId];
setBusy(true);
setError(null);
setNotice("正在开启「" + (seat ? seat.name : seatId) + "」…");
try {
const next = await request("enableSeat", { projectId, seatId });
if (!alive.current) return;
setView(next);
setNotice("已开启「" + (seat ? seat.name : seatId) + "」的独立会话");
try {
if (typeof openRightTab === "function") openRightTab();
} catch {
}
} catch (enableError) {
if (alive.current) setError(enableError && enableError.message ? enableError.message : "开启失败");
} finally {
if (alive.current) setBusy(false);
}
}
async function enableAllSeats() {
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() {
if (!projectId) return;
const seatId = wb.selected.id;
const value = wb.selected.modelValue;
if (!value) {
setNotice("请先为当前角色选择模型");
return;
}
const model = modelFromValue(value);
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 saveMemory() {
if (!projectId) return;
setBusy(true);
setError(null);
setNotice("保存项目共识…");
try {
const result = await request("memoryUpdate", {
projectId,
expectedRevision: memory?.revision ?? 0,
goal: memoryDraft.goal,
constraints: memoryDraft.constraints.split("\n").map((x) => x.trim()).filter(Boolean),
acceptance: memoryDraft.acceptance.split("\n").map((x) => x.trim()).filter(Boolean),
decisions: memoryDraft.decisions.split("\n").map((x) => x.trim()).filter(Boolean).map((text) => ({ type: "user", status: "active", text, sourceRefs: [] })),
sources: []
});
if (!alive.current) return;
setMemory(result.memory);
setMemoryDraft((prev) => ({ ...prev, decisions: "" }));
setNotice("项目共识已保存(v" + result.memory.revision + ")");
} catch (memoryError) {
if (alive.current) setError(memoryError && memoryError.message ? memoryError.message : "保存项目共识失败");
} finally {
if (alive.current) setBusy(false);
}
}
async function reloadTasks() {
if (!projectId) return;
try {
const result = await request("tasks", { projectId });
if (alive.current) setTasks(result.tasks ?? []);
} catch (error2) {
if (alive.current) setNotice(error2 && error2.message ? error2.message : "任务列表刷新失败");
}
}
function openTaskForm(ownerSeatId) {
setTaskForm({ ownerSeatId: ownerSeatId || "gongbu", title: "", goal: "", dispatchNow: true });
}
async function submitTaskForm() {
if (!projectId || !taskForm) return;
const title = taskForm.title.trim();
if (!title) {
setNotice("任务标题不能为空");
return;
}
setBusy(true);
setError(null);
try {
const created = await request("taskCreate", { projectId, title, goal: taskForm.goal, ownerSeatId: taskForm.ownerSeatId });
const task = created && created.task ? created.task : null;
if (taskForm.dispatchNow && task && task.id) {
const delivered = await request("taskDispatch", { projectId, taskId: task.id });
setNotice(delivered && delivered.delivered ? "已派工到「" + (SEATS[taskForm.ownerSeatId]?.label ?? "") + "」会话。" : "任务已记录,但宿主未直接送达。");
} else setNotice("已存为草稿;可在任务详情中点「派工」。");
setTaskForm(null);
await reloadTasks();
} catch (error2) {
if (alive.current) setError(error2 && error2.message ? error2.message : "新建任务失败");
} finally {
if (alive.current) setBusy(false);
}
}
async function dispatchTask(taskId) {
if (!projectId) return;
setBusy(true);
setError(null);
try {
const result = await request("taskDispatch", { projectId, taskId });
await reloadTasks();
setNotice(result && result.delivered ? "已派工到该部门会话。" : "已记录为待执行(当前宿主暂不支持直接发送)。");
} catch (error2) {
if (alive.current) setError(error2 && error2.message ? error2.message : "派工失败");
} finally {
if (alive.current) setBusy(false);
}
}
async function cancelTask(taskId) {
if (!projectId) return;
setBusy(true);
setError(null);
try {
await request("taskCancel", { projectId, taskId });
await reloadTasks();
setNotice("任务已取消。");
} catch (error2) {
if (alive.current) setError(error2 && error2.message ? error2.message : "取消失败");
} finally {
if (alive.current) setBusy(false);
}
}
async function summarizeByShangshu() {
if (!projectId) return;
setSummaryBusy(true);
setError(null);
try {
const result = await request("shangshuSummary", { projectId });
if (!alive.current) return;
if (!result || !result.sessionId) throw new Error("宿主没有返回尚书会话");
setNotice("已请尚书汇总当前任务,正在打开尚书会话…");
navigateToSession(result.sessionId);
} catch (summaryError) {
if (alive.current) setError(summaryError && summaryError.message ? summaryError.message : "尚书汇总请求失败");
} finally {
if (alive.current) setSummaryBusy(false);
}
}
async function addArtifact() {
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 });
setArtifacts((list) => [...list, result.artifact]);
setArtifactDraft({ title: "", path: "", summary: "" });
setArtifactFormOpen(false);
setNotice("成果已登记。");
} catch (error2) {
if (alive.current) setError(error2 && error2.message ? error2.message : "登记成果失败");
} finally {
if (alive.current) setBusy(false);
}
}
const todayStart = TODAY();
const todayTasks = tasks.filter((task) => Number(task.createdAt) >= todayStart);
const todayDone = todayTasks.filter((task) => task.status === "done");
const todayRunning = todayTasks.filter((task) => task.status === "running" || task.status === "dispatched");
const todayDraft = todayTasks.filter((task) => task.status === "draft");
const reviewTasks = tasks.filter((task) => task.ownerSeatId === "menxia" && OPEN_STATUS.has(task.status));
const runningSeats = wb.seats.filter((seat) => seat.status === "bound" || seat.status === "creating").length;
const waitingSeats = wb.seats.filter((seat) => seat.status === "pending").length;
const durations = todayDone.map((task) => Number(task.resultAt) - Number(task.createdAt)).filter((ms) => Number.isFinite(ms) && ms > 0);
const avgMs = durations.length ? durations.reduce((a, b) => a + b, 0) / durations.length : null;
function latestTaskOf(seatId) {
return tasks.filter((task) => task.ownerSeatId === seatId).sort((a, b) => Number(b.updatedAt || b.createdAt || 0) - Number(a.updatedAt || a.createdAt || 0))[0] || null;
}
function tasksOf(seatId) {
return tasks.filter((task) => task.ownerSeatId === seatId).sort((a, b) => Number(b.updatedAt || b.createdAt || 0) - Number(a.updatedAt || a.createdAt || 0));
}
function selectedSeatRecord(id) {
return seatRecordOf(view, id);
}
function modelLabelOf(id) {
return fmtModel(selectedSeatRecord(id), wb.selected.modelOptions);
}
const statusBanner = error ? (0, import_react.createElement)("p", { className: "ssv-banner is-error", role: "alert" }, error) : notice ? (0, import_react.createElement)("p", { className: "ssv-banner is-notice", role: "status" }, notice) : null;
function renderTopbar(title, extra) {
return (0, import_react.createElement)(
"header",
{ className: "topbar" },
(0, import_react.createElement)("h1", null, title),
tab === "overview" ? (0, import_react.createElement)("span", { className: "date" }, dateLabel()) : null,
(0, import_react.createElement)("span", { className: "spacer" }),
...extra || []
);
}
function renderTabs() {
const entries = [
{ id: "overview", label: "总览", icon: ["M3 3h7v9H3z", "M14 3h7v5h-7z", "M14 12h7v9h-7z", "M3 16h7v5H3z"] },
{ id: "queue", label: "派工队列", icon: ["m22 2-7 20-4-9-9-4Z", "M22 2 11 13"] },
{ id: "memory", label: "记忆", icon: ["M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"] },
{ id: "settings", label: "设置", icon: ["M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z", "M12 12a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"] }
];
return (0, import_react.createElement)(
"nav",
{ className: "tabs", "aria-label": "工作台导航" },
entries.map((entry) => (0, import_react.createElement)("a", {
key: entry.id,
href: "#",
className: tab === entry.id ? "on" : "",
"aria-current": tab === entry.id ? "page" : void 0,
onClick: (event) => {
event.preventDefault();
setTab(entry.id);
}
}, fileIcon(entry.icon), entry.label))
);
}
function renderSeatNode(seat) {
const tone = toneOfSeat(seat);
const latest = latestTaskOf(seat.id);
const dim = seatFilter !== "all" && tone !== seatFilter;
return (0, import_react.createElement)(
"div",
{ key: seat.id, className: "node" + (seat.id === selectedSeatId ? " selected" : "") + (dim ? " dim" : ""), "data-seat": seat.id },
(0, import_react.createElement)(
"button",
{ type: "button", className: "node-main", onClick: () => setSeat(seat.id), "aria-pressed": seat.id === selectedSeatId ? "true" : "false" },
(0, import_react.createElement)("span", { className: "node-top" }, (0, import_react.createElement)("span", { className: "node-name" }, seat.name), (0, import_react.createElement)("span", { className: "status " + tone }, (0, import_react.createElement)("i"), seatStateText(seat))),
(0, import_react.createElement)("span", { className: "node-role" }, seat.duty),
(0, import_react.createElement)("span", { className: "node-task" }, (0, import_react.createElement)("span", { className: "t-label" }, "当前任务"), (0, import_react.createElement)("span", { className: "task-text" }, latest ? latest.title : "—")),
(0, import_react.createElement)("span", { className: "node-model" }, "主任模型 ", (0, import_react.createElement)("span", { className: "num" }, modelLabelOf(seat.id)))
),
(0, import_react.createElement)("div", { className: "node-foot" }, (0, import_react.createElement)("span", { className: "elapsed" }, latest ? taskLabel(latest.status) : seat.status === "bound" ? "在线 · 待命" : "未运行 · 待命"))
);
}
function renderOverview() {
const stats = [
(0, import_react.createElement)(
"div",
{ className: "stat", key: "running" },
(0, import_react.createElement)("div", { className: "label" }, "运行中席位"),
(0, import_react.createElement)("div", { className: "big" }, (0, import_react.createElement)("em", null, String(runningSeats)), (0, import_react.createElement)("span", { className: "unit" }, " / " + wb.project.seatCount + " 席")),
(0, import_react.createElement)("div", { className: "foot" }, "待命 ", (0, import_react.createElement)("b", null, String(waitingSeats)), " · 待复核 ", (0, import_react.createElement)("b", null, String(reviewTasks.length)))
),
(0, import_react.createElement)(
"div",
{ className: "stat", key: "today" },
(0, import_react.createElement)("div", { className: "label" }, "今日派工"),
(0, import_react.createElement)("div", { className: "big" }, String(todayTasks.length), " ", (0, import_react.createElement)("span", { className: "unit" }, "条")),
(0, import_react.createElement)("div", { className: "foot" }, "已完成 ", (0, import_react.createElement)("b", null, String(todayDone.length)), " · 进行中 ", (0, import_react.createElement)("b", null, String(todayRunning.length)), " · 待派发 ", (0, import_react.createElement)("b", null, String(todayDraft.length)))
),
(0, import_react.createElement)(
"div",
{ className: "stat", key: "review" },
(0, import_react.createElement)("div", { className: "label" }, "待门下复核"),
(0, import_react.createElement)("div", { className: "big" }, (0, import_react.createElement)("em", null, String(reviewTasks.length)), " ", (0, import_react.createElement)("span", { className: "unit" }, "件")),
(0, import_react.createElement)("div", { className: "foot" }, "两段式:刑部摘录 → 门下定夺")
),
(0, import_react.createElement)(
"div",
{ className: "stat", key: "avg" },
(0, import_react.createElement)("div", { className: "label" }, "今日平均单程耗时"),
(0, import_react.createElement)("div", { className: "big" }, avgMs ? durationText(avgMs) : "—"),
(0, import_react.createElement)("div", { className: "foot" }, todayDone.length ? "按 " + todayDone.length + " 条已完成任务计算" : "今日暂无完成记录")
)
];
const selected = wb.selected;
const selectedLatest = latestTaskOf(selected.id);
const selectedTasks = tasksOf(selected.id);
const selectedToday = todayTasks.filter((task) => task.ownerSeatId === selected.id);
const selectedDone = selectedToday.filter((task) => task.status === "done");
const excerpt = selectedLatest && (selectedLatest.result || selectedLatest.note) || selected.responsibility;
const actionLabel = selected.status === "bound" ? "开始对话" : selected.status === "missing" ? "重建会话" : "开启「" + selected.name + "」";
const action = selected.status === "bound" ? () => openSeat(selected.id) : selected.status === "missing" ? () => rebuildSeat(selected.id) : () => enableSeat(selected.id);
const detail = (0, import_react.createElement)(
"section",
{ className: "card", "aria-label": "席位详情" },
(0, import_react.createElement)("div", { className: "detail-head" }, (0, import_react.createElement)("h3", null, "席位详情"), (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy || selected.status === "creating", onClick: action }, (0, import_react.createElement)(ChatIcon), actionLabel)),
(0, import_react.createElement)("div", { className: "detail-name" }, selected.name),
(0, import_react.createElement)("div", { className: "detail-role" }, selected.duty + " · " + selected.statusLabel),
(0, import_react.createElement)(
"dl",
{ className: "kv" },
(0, import_react.createElement)("dt", null, "主任模型"),
(0, import_react.createElement)("dd", null, selected.modelLabel),
(0, import_react.createElement)("dt", null, "当前任务"),
(0, import_react.createElement)("dd", null, selectedLatest ? selectedLatest.title : "—"),
(0, import_react.createElement)("dt", null, "本日派工"),
(0, import_react.createElement)("dd", null, selectedToday.length + " 条 · 完成 " + selectedDone.length),
(0, import_react.createElement)("dt", null, "最近会话"),
(0, import_react.createElement)("dd", null, selected.sessionId ? "已绑定 · " + selected.sessionId.slice(0, 8) : "尚未建立")
),
(0, import_react.createElement)("div", { className: "excerpt" }, (0, import_react.createElement)("span", { className: "t-label" }, "最近产出摘录"), (0, import_react.createElement)("span", null, excerpt))
);
const workspace = (0, import_react.createElement)(
"section",
{ className: "card", "aria-label": "席位工作区" },
(0, import_react.createElement)("h3", null, "席位工作区 ", (0, import_react.createElement)("span", { className: "seat-tag" }, selected.name), " ", (0, import_react.createElement)("span", { className: "w-kind" }, seatKind(selected.id))),
selected.id === "shangshu" ? (0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: summaryBusy || busy, onClick: summarizeByShangshu }, summaryBusy ? "汇总中…" : "尚书汇总当前任务")) : null,
selected.id === "lead" ? (0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", onClick: () => openTaskForm("lead") }, (0, import_react.createElement)(PlusIcon), "向丞相下达")) : (0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => openTaskForm(selected.id) }, (0, import_react.createElement)(PlusIcon), "新建派工到" + selected.name)),
selectedTasks.length === 0 ? (0, import_react.createElement)("p", { className: "empty-note" }, "该席位还没有任务记录。") : (0, import_react.createElement)("div", { className: "review-list" }, selectedTasks.slice(0, 3).map((task) => (0, import_react.createElement)(
"article",
{ className: "review-card", key: task.id },
(0, import_react.createElement)("div", { className: "rc-head" }, (0, import_react.createElement)("div", { className: "rc-title" }, task.title), (0, import_react.createElement)("span", { className: "rc-status " + taskTone(task.status) }, (0, import_react.createElement)("i"), taskLabel(task.status))),
(0, import_react.createElement)("div", { className: "rc-meta-row" }, (0, import_react.createElement)("span", { className: "rc-from" }, task.id), (0, import_react.createElement)("span", { className: "rc-meta" }, task.dispatchedAt ? "派发 " + dateText(task.dispatchedAt) : "尚未派发")),
(0, import_react.createElement)("div", { className: "rc-excerpt" }, task.goal || task.requirement || "(无任务说明)"),
(0, import_react.createElement)(
"div",
{ className: "rc-actions" },
(0, import_react.createElement)("span", { className: "spacer" }),
(0, import_react.createElement)("button", { type: "button", className: "r-open", onClick: () => setSelectedTask(task) }, "查看详情 →"),
task.status === "draft" ? (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: () => dispatchTask(task.id) }, "派工") : null
)
)))
);
const modelChoices = [];
const seenModels = /* @__PURE__ */ new Set();
for (const option of selected.modelOptions) {
const key = option.provider + "::" + option.model;
if (seenModels.has(key)) continue;
seenModels.add(key);
modelChoices.push({ value: key, label: option.model, provider: option.provider, model: option.model });
}
const valueParts = String(selected.modelValue || "").split("::");
const currentProvider = valueParts[0] || "";
const currentModel = valueParts[1] || "";
const currentModelValue = currentProvider && currentModel ? currentProvider + "::" + currentModel : "";
if (currentModelValue && !seenModels.has(currentModelValue)) {
modelChoices.unshift({ value: currentModelValue, label: currentModel, provider: currentProvider, model: currentModel });
}
const effortChoices = [];
for (const option of selected.modelOptions) {
if (option.provider !== currentProvider || option.model !== currentModel || !option.reasoningEffort) continue;
if (!effortChoices.includes(option.reasoningEffort)) effortChoices.push(option.reasoningEffort);
}
const currentEffort = valueParts[2] || "";
if (currentEffort && !effortChoices.includes(currentEffort)) effortChoices.unshift(currentEffort);
const configCard = (0, import_react.createElement)(
"section",
{ className: "card", "aria-label": "部门配置" },
(0, import_react.createElement)("h3", null, "部门配置 ", (0, import_react.createElement)("span", { className: "seat-tag" }, selected.name)),
(0, import_react.createElement)(
"div",
{ className: "cfg-grid" },
(0, import_react.createElement)("label", { className: "cfg-row" }, "主任模型", (0, import_react.createElement)(
"select",
{ value: currentModelValue, onChange: (event) => setModelValue(event.target.value) },
(0, import_react.createElement)("option", { value: "" }, "请选择模型"),
modelChoices.map((option) => (0, import_react.createElement)("option", { key: option.value, value: option.value }, option.label))
)),
(0, import_react.createElement)("label", { className: "cfg-row" }, "推理等级", (0, import_react.createElement)(
"select",
{
value: currentEffort,
disabled: effortChoices.length === 0,
title: effortChoices.length === 0 ? "当前模型目录未提供可调推理等级" : void 0,
onChange: (event) => setModelValue(event.target.value ? currentProvider + "::" + currentModel + "::" + event.target.value : currentModelValue)
},
effortChoices.length === 0 ? (0, import_react.createElement)("option", { value: "" }, "默认(模型固定)") : [(0, import_react.createElement)("option", { key: "default", value: "" }, "默认"), ...effortChoices.map((effort) => (0, import_react.createElement)("option", { key: effort, value: effort }, effort))]
)),
(0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "角色补充说明", (0, import_react.createElement)("textarea", {
rows: 3,
className: "ssv-textarea",
value: selected.instructions,
placeholder: "仅对该席位追加的补充说明",
onChange: (event) => setInstructions(event.target.value)
}))
),
(0, import_react.createElement)(
"div",
{ className: "cfg-skills" },
(0, import_react.createElement)("span", { className: "t-label" }, "技能绑定"),
(0, import_react.createElement)(
"ul",
{ className: "skill-list" },
(0, import_react.createElement)("li", null, (0, import_react.createElement)("span", { className: "skill-name" }, "真实会话绑定"), (0, import_react.createElement)("span", { className: "skill-state" + (selected.status === "bound" ? " bound" : "") }, (0, import_react.createElement)("i"), selected.status === "bound" ? "已绑定" : "未绑定")),
(0, import_react.createElement)("li", null, (0, import_react.createElement)("span", { className: "skill-name" }, "工作台派工工具"), (0, import_react.createElement)("span", { className: "skill-state" + (selected.status === "bound" ? " bound" : "") }, (0, import_react.createElement)("i"), selected.status === "bound" ? "可用" : "待开启")),
(0, import_react.createElement)("li", null, (0, import_react.createElement)("span", { className: "skill-name" }, "职责"), (0, import_react.createElement)("span", { className: "skill-state bound" }, (0, import_react.createElement)("i"), selected.duty))
)
),
(0, import_react.createElement)(
"div",
{ className: "ws-actions" },
(0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: saveConfig }, busy ? "保存中…" : "保存配置"),
selected.status !== "bound" ? (0, import_react.createElement)("button", { type: "button", className: "btn", disabled: busy, onClick: action }, actionLabel) : null,
(0, import_react.createElement)("button", { type: "button", className: "btn", disabled: busy, onClick: enableAllSeats }, "启用十席")
)
);
return (0, import_react.createElement)(
"div",
{ className: "page" },
renderTopbar("总览", [
(0, import_react.createElement)("button", { type: "button", className: "btn", onClick: loadProject, disabled: phase === "loading" }, (0, import_react.createElement)(RefreshIcon), "刷新状态"),
(0, import_react.createElement)(
"button",
{ type: "button", className: "btn primary btn-cx", onClick: () => {
setSeat("lead");
if (seatById.lead.status === "bound") void openSeat("lead");
else setTab("settings");
} },
(0, import_react.createElement)("span", { className: "cx-name" }, "丞相"),
(0, import_react.createElement)("span", { className: "cx-dot", "aria-hidden": "true" }),
(0, import_react.createElement)("span", { className: "cx-state" }, seatStateText(seatById.lead))
)
]),
(0, import_react.createElement)("section", { className: "stats", "aria-label": "关键指标" }, stats),
(0, import_react.createElement)(
"section",
{ "aria-label": "席位谱系", style: { marginTop: "22px" } },
(0, import_react.createElement)(
"div",
{ className: "panel-head" },
(0, import_react.createElement)("h2", null, "席位谱系"),
(0, import_react.createElement)(
"div",
{ className: "seg", role: "tablist", "aria-label": "按状态筛选席位" },
[["all", "全部"], ["run", "运行中"], ["review", "待复核"], ["idle", "待命"]].map(([id, label]) => (0, import_react.createElement)("button", {
key: id,
type: "button",
className: seatFilter === id ? "on" : "",
role: "tab",
"aria-selected": seatFilter === id ? "true" : "false",
onClick: () => setSeatFilter(id)
}, label))
)
),
(0, import_react.createElement)("div", { id: "orgTree", ref: orgRef }, (0, import_react.createElement)(
"div",
{ className: "org-rows", "data-cols": String(orgCols) },
(0, import_react.createElement)("div", { className: "org-row org-row-3" }, wb.groups.sansheng.map((id) => (0, import_react.createElement)("div", { className: "org-cell", key: id, "data-slot": id }, renderSeatNode(seatById[id])))),
(0, import_react.createElement)(
"div",
{ className: "org-wires org-wires-2", "aria-hidden": "true" },
(0, import_react.createElement)("span", { className: "wire-v", style: { left: "50%", top: 0, height: 11 } }),
(0, import_react.createElement)("span", { className: "wire-h", style: { left: "8.3333%", right: "8.3333%", top: 11 } }),
...[8.3333, 25, 41.6667, 58.3333, 75, 91.6667].map((left, i) => (0, import_react.createElement)("span", { key: i, className: "wire-v w2-b" + (i + 1), style: { left: left + "%", top: 11, height: 11 } }))
),
(0, import_react.createElement)("div", { className: "org-row org-row-6" }, wb.groups.liubu.map((id) => (0, import_react.createElement)("div", { className: "org-cell", key: id, "data-slot": id }, renderSeatNode(seatById[id]))))
))
),
(0, import_react.createElement)("div", { className: "grid" }, (0, import_react.createElement)("div", { className: "detail-col" }, detail, workspace), (0, import_react.createElement)("div", { className: "rail" }, configCard)),
(0, import_react.createElement)("p", { className: "foot-note" }, "数据来自当前项目真实会话 · " + (wb.project.boundCount + " / " + wb.project.seatCount + " 席已启用"))
);
}
function renderQueue() {
const query = queueSearch.trim().toLowerCase();
const filtered = tasks.filter((task) => {
const tone = taskTone(task.status);
if (queueFilter !== "all" && tone !== queueFilter) return false;
if (!query) return true;
const seatName = SEATS[task.ownerSeatId]?.label || task.ownerSeatId || "";
return (task.title + " " + seatName + " " + (task.id || "") + " " + (task.goal || "")).toLowerCase().includes(query);
});
return (0, import_react.createElement)(
"div",
{ className: "page" },
renderTopbar("派工队列", [
(0, import_react.createElement)("button", { type: "button", className: "btn", disabled: summaryBusy || busy, onClick: summarizeByShangshu }, summaryBusy ? "汇总中…" : "尚书汇总"),
(0, import_react.createElement)("button", { type: "button", className: "btn primary", onClick: () => openTaskForm("gongbu") }, (0, import_react.createElement)(PlusIcon), "新建派工"),
(0, import_react.createElement)("label", { className: "search" }, (0, import_react.createElement)(SearchIcon), (0, import_react.createElement)("input", { type: "search", value: queueSearch, placeholder: "筛选派工记录…", "aria-label": "筛选派工队列", onChange: (event) => setQueueSearch(event.target.value) }))
]),
(0, import_react.createElement)(
"div",
{ className: "seg", role: "tablist", "aria-label": "按状态筛选派工", style: { marginTop: "16px", marginLeft: 0 } },
[["all", "全部"], ["run", "进行中"], ["review", "待复核"], ["done", "已完成"], ["fail", "失败"]].map(([id, label]) => (0, import_react.createElement)("button", {
key: id,
type: "button",
className: queueFilter === id ? "on" : "",
"aria-selected": queueFilter === id ? "true" : "false",
onClick: () => setQueueFilter(id)
}, label))
),
(0, import_react.createElement)(
"section",
{ className: "table-card", "aria-label": "派工队列" },
(0, import_react.createElement)("div", { className: "table-scroll" }, (0, import_react.createElement)(
"table",
null,
(0, import_react.createElement)("thead", null, (0, import_react.createElement)("tr", null, ["任务", "承办席位", "模型", "状态", "耗时", "派发时间"].map((label) => (0, import_react.createElement)("th", { key: label, scope: "col" }, label)))),
(0, import_react.createElement)("tbody", null, filtered.map((task) => (0, import_react.createElement)(
"tr",
{ key: task.id, className: "clickable", tabIndex: 0, onClick: () => setSelectedTask(task), onKeyDown: (event) => {
if (event.key === "Enter") setSelectedTask(task);
} },
(0, import_react.createElement)("td", null, (0, import_react.createElement)("span", { className: "task-name" }, task.title), (0, import_react.createElement)("br"), (0, import_react.createElement)("span", { className: "task-id" }, task.id)),
(0, import_react.createElement)("td", null, SEATS[task.ownerSeatId]?.label || task.ownerSeatId || "—"),
(0, import_react.createElement)("td", { className: "num" }, modelLabelOf(task.ownerSeatId)),
(0, import_react.createElement)("td", null, (0, import_react.createElement)("span", { className: "pill " + taskTone(task.status) }, (0, import_react.createElement)("i"), taskLabel(task.status))),
(0, import_react.createElement)("td", { className: "dur" }, task.resultAt && task.createdAt ? durationText(Number(task.resultAt) - Number(task.createdAt)) : "—"),
(0, import_react.createElement)("td", { className: "time" }, task.dispatchedAt ? dateText(task.dispatchedAt) : "—")
)))
)),
filtered.length === 0 ? (0, import_react.createElement)("p", { className: "foot-note" }, "没有匹配的派工记录,换个关键词或状态试试。") : null
)
);
}
function renderMemory() {
const constraints = Array.isArray(memory?.constraints) ? memory.constraints : [];
const acceptance = Array.isArray(memory?.acceptance) ? memory.acceptance : [];
const decisions = Array.isArray(memory?.decisions) ? memory.decisions : [];
const item = (title, meta, body, tone) => (0, import_react.createElement)(
"article",
{ className: "review-card", key: title },
(0, import_react.createElement)("div", { className: "rc-head" }, (0, import_react.createElement)("div", { className: "rc-title" }, title), (0, import_react.createElement)("span", { className: "rc-status " + (tone || "pass") }, (0, import_react.createElement)("i"), "现行")),
(0, import_react.createElement)("div", { className: "rc-meta-row" }, (0, import_react.createElement)("span", { className: "rc-from" }, "项目共识"), (0, import_react.createElement)("span", { className: "rc-meta" }, meta)),
(0, import_react.createElement)("div", { className: "rc-excerpt" }, body || "(暂无)")
);
return (0, import_react.createElement)(
"div",
{ className: "page" },
renderTopbar("记忆", [(0, import_react.createElement)("span", { className: "date" }, (wb.project.name || "项目") + " · 项目共识 v" + (memory?.revision ?? 0))]),
(0, import_react.createElement)(
"div",
{ className: "grid" },
(0, import_react.createElement)(
"div",
{ className: "detail-col" },
(0, import_react.createElement)(
"section",
{ className: "card", "aria-label": "项目共识" },
(0, import_react.createElement)("h3", null, "项目共识 ", (0, import_react.createElement)("span", { className: "seat-tag" }, "v" + (memory?.revision ?? 0))),
(0, import_react.createElement)(
"div",
{ className: "review-list" },
item("项目目标", "goal", memory?.goal || "尚未填写项目目标", "pass"),
item("硬约束", (constraints.length || 0) + " 条", constraints.join(";"), constraints.length ? "pass" : "idle"),
item("验收标准", (acceptance.length || 0) + " 条", acceptance.join(";"), acceptance.length ? "pass" : "idle"),
...decisions.slice(-5).map((decision, index) => item(decision.text || "决定 " + (index + 1), decision.recordedAt ? dateText(decision.recordedAt) : "项目记录", decision.status === "active" ? "现行决定" : "已归档", "pass"))
)
),
(0, import_react.createElement)(
"section",
{ className: "card", "aria-label": "成果" },
(0, import_react.createElement)("h3", null, "成果登记 ", (0, import_react.createElement)("span", { className: "seat-tag" }, String(artifacts.length))),
(0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setArtifactFormOpen(true) }, (0, import_react.createElement)(PlusIcon), "登记成果")),
artifacts.length === 0 ? (0, import_react.createElement)("p", { className: "empty-note" }, "还没有登记成果。") : (0, import_react.createElement)("ul", { className: "skill-list" }, artifacts.slice(0, 8).map((artifact) => (0, import_react.createElement)("li", { key: artifact.id }, (0, import_react.createElement)("span", { className: "skill-name" }, artifact.title), (0, import_react.createElement)("span", { className: "skill-state bound" }, (0, import_react.createElement)("i"), artifact.path || "已登记"))))
)
),
(0, import_react.createElement)(
"div",
{ className: "rail" },
(0, import_react.createElement)(
"section",
{ className: "card", "aria-label": "编辑项目共识" },
(0, import_react.createElement)("h3", null, "编辑项目共识"),
(0, import_react.createElement)(
"div",
{ className: "cfg-grid" },
(0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "项目目标", (0, import_react.createElement)("textarea", { rows: 3, className: "ssv-textarea", value: memoryDraft.goal, placeholder: "这个项目最终要达成什么", onChange: (event) => setMemoryDraft({ ...memoryDraft, goal: event.target.value }) })),
(0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "硬约束(每行一条)", (0, import_react.createElement)("textarea", { rows: 3, className: "ssv-textarea", value: memoryDraft.constraints, placeholder: "例如:不能改动线上数据", onChange: (event) => setMemoryDraft({ ...memoryDraft, constraints: event.target.value }) })),
(0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "验收标准(每行一条)", (0, import_react.createElement)("textarea", { rows: 3, className: "ssv-textarea", value: memoryDraft.acceptance, placeholder: "例如:交付前必须跑完回归测试", onChange: (event) => setMemoryDraft({ ...memoryDraft, acceptance: event.target.value }) })),
(0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "新增决定(每行一条)", (0, import_react.createElement)("textarea", { rows: 2, className: "ssv-textarea", value: memoryDraft.decisions, placeholder: "例如:先保证稳定性,再考虑样式", onChange: (event) => setMemoryDraft({ ...memoryDraft, decisions: event.target.value }) }))
),
(0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: saveMemory }, busy ? "保存中…" : "保存共识"))
)
)
)
);
}
function renderSettings() {
return (0, import_react.createElement)(
"div",
{ className: "page" },
renderTopbar("设置"),
(0, import_react.createElement)(
"div",
{ className: "settings-stack" },
(0, import_react.createElement)(
"section",
{ className: "card", "aria-label": "项目绑定" },
(0, import_react.createElement)("h3", null, "项目绑定"),
(0, import_react.createElement)(
"dl",
{ className: "kv" },
(0, import_react.createElement)("dt", null, "当前项目"),
(0, import_react.createElement)("dd", null, wb.project.name || "未命名项目"),
(0, import_react.createElement)("dt", null, "类型"),
(0, import_react.createElement)("dd", null, "主项目"),
(0, import_react.createElement)("dt", null, "席位"),
(0, import_react.createElement)("dd", null, wb.project.seatCount + " 席"),
(0, import_react.createElement)("dt", null, "工作区"),
(0, import_react.createElement)("dd", null, wb.project.workspaceId || "—")
),
(0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: enableAllSeats }, "启用十席"))
),
(0, import_react.createElement)(
"section",
{ className: "card", "aria-label": "席位开关" },
(0, import_react.createElement)("h3", null, "席位开关"),
(0, import_react.createElement)("ul", { className: "skill-list" }, SEAT_IDS.map((id) => {
const seat = seatById[id];
const online = seat.status === "bound";
return (0, import_react.createElement)(
"li",
{ key: id },
(0, import_react.createElement)("span", { className: "skill-name" }, seat.name + " · " + seat.duty),
(0, import_react.createElement)("span", { className: "skill-state" + (online ? " bound" : "") }, (0, import_react.createElement)("i"), online ? "已上线" : seat.status === "missing" ? "会话缺失" : "未上线"),
(0, import_react.createElement)("button", { type: "button", className: "skill-toggle", disabled: busy, onClick: () => {
if (seat.status === "missing") void rebuildSeat(id);
else if (online) void openSeat(id);
else void enableSeat(id);
} }, seat.status === "missing" ? "重建" : online ? "打开" : "上线")
);
}))
),
(0, import_react.createElement)(
"section",
{ className: "card", "aria-label": "角色职责" },
(0, import_react.createElement)("h3", null, "角色职责"),
(0, import_react.createElement)("ul", { className: "skill-list" }, SEAT_IDS.map((id) => (0, import_react.createElement)(
"li",
{ key: id },
(0, import_react.createElement)("span", { className: "skill-name" }, (0, import_react.createElement)("b", null, SEATS[id].label)),
(0, import_react.createElement)("span", { className: "skill-state bound" }, (0, import_react.createElement)("i"), SEATS[id].duty),
(0, import_react.createElement)("span", { className: "rc-meta" }, modelLabelOf(id))
)))
)
)
);
}
function renderTaskModal() {
if (!taskForm) return null;
const seat = SEATS[taskForm.ownerSeatId];
return (0, import_react.createElement)(
"div",
{ className: "modal-backdrop", onClick: (event) => {
if (event.target === event.currentTarget) setTaskForm(null);
} },
(0, import_react.createElement)(
"div",
{ className: "modal", role: "dialog", "aria-modal": "true", "aria-labelledby": "ssv-task-title" },
(0, import_react.createElement)("div", { className: "modal-head" }, (0, import_react.createElement)("h3", { id: "ssv-task-title" }, taskForm.ownerSeatId === "lead" ? "向丞相下达" : "新建派工"), (0, import_react.createElement)("button", { type: "button", className: "modal-close", "aria-label": "关闭", onClick: () => setTaskForm(null) }, "✕")),
(0, import_react.createElement)("div", { className: "m-from" }, (seat ? seat.label : taskForm.ownerSeatId) + " · " + (seat ? seat.duty : "") + " · " + modelLabelOf(taskForm.ownerSeatId)),
(0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "承办席位"), (0, import_react.createElement)("select", { value: taskForm.ownerSeatId, onChange: (event) => setTaskForm({ ...taskForm, ownerSeatId: event.target.value }), className: "ssv-select" }, SEAT_IDS.map((id) => (0, import_react.createElement)("option", { key: id, value: id }, SEATS[id].label + " · " + SEATS[id].duty)))),
(0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "任务标题"), (0, import_react.createElement)("input", { type: "text", value: taskForm.title, placeholder: "例如:整理本周文献日报要点", onChange: (event) => setTaskForm({ ...taskForm, title: event.target.value }) })),
(0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "任务说明"), (0, import_react.createElement)("textarea", { rows: 4, value: taskForm.goal, placeholder: "把要办的事、背景和期望产出写清楚…", onChange: (event) => setTaskForm({ ...taskForm, goal: event.target.value }) })),
(0, import_react.createElement)("label", { className: "ssv-check" }, (0, import_react.createElement)("input", { type: "checkbox", checked: taskForm.dispatchNow, onChange: (event) => setTaskForm({ ...taskForm, dispatchNow: event.target.checked }) }), " 创建后立即派工到该席位"),
(0, import_react.createElement)("div", { className: "modal-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: submitTaskForm }, busy ? "提交中…" : "提交"), (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setTaskForm(null) }, "取消"))
)
);
}
function renderArtifactModal() {
if (!artifactFormOpen) return null;
return (0, import_react.createElement)(
"div",
{ className: "modal-backdrop", onClick: (event) => {
if (event.target === event.currentTarget) setArtifactFormOpen(false);
} },
(0, import_react.createElement)(
"div",
{ className: "modal", role: "dialog", "aria-modal": "true", "aria-labelledby": "ssv-artifact-title" },
(0, import_react.createElement)("div", { className: "modal-head" }, (0, import_react.createElement)("h3", { id: "ssv-artifact-title" }, "登记成果"), (0, import_react.createElement)("button", { type: "button", className: "modal-close", "aria-label": "关闭", onClick: () => setArtifactFormOpen(false) }, "✕")),
(0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "成果名称"), (0, import_react.createElement)("input", { type: "text", value: artifactDraft.title, placeholder: "例如:竞品分析报告 v1", onChange: (event) => setArtifactDraft({ ...artifactDraft, title: event.target.value }) })),
(0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "文件路径"), (0, import_react.createElement)("input", { type: "text", value: artifactDraft.path, placeholder: "例如:docs/竞品分析.md", onChange: (event) => setArtifactDraft({ ...artifactDraft, path: event.target.value }) })),
(0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "摘要"), (0, import_react.createElement)("textarea", { rows: 3, value: artifactDraft.summary, placeholder: "这份成果解决了什么、在哪里", onChange: (event) => setArtifactDraft({ ...artifactDraft, summary: event.target.value }) })),
(0, import_react.createElement)("div", { className: "modal-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: addArtifact }, busy ? "提交中…" : "登记"), (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setArtifactFormOpen(false) }, "取消"))
)
);
}
function renderTaskDetail() {
if (!selectedTask) return null;
const task = selectedTask;
const seat = SEATS[task.ownerSeatId];
return (0, import_react.createElement)(
"div",
{ className: "modal-backdrop", onClick: (event) => {
if (event.target === event.currentTarget) setSelectedTask(null);
} },
(0, import_react.createElement)(
"div",
{ className: "modal", role: "dialog", "aria-modal": "true" },
(0, import_react.createElement)("div", { className: "modal-head" }, (0, import_react.createElement)("h3", null, task.title), (0, import_react.createElement)("button", { type: "button", className: "modal-close", "aria-label": "关闭", onClick: () => setSelectedTask(null) }, "✕")),
(0, import_react.createElement)("div", { className: "m-from" }, "派工编号:" + (task.id || "—") + " · " + (task.dispatchedAt ? "派发时间 " + dateText(task.dispatchedAt) : "尚未派发")),
(0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "派工说明"), (0, import_react.createElement)("p", null, task.goal || task.requirement || "(无任务说明)")),
(0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "承办与状态"), (0, import_react.createElement)("p", null, "承办席位:" + (seat ? seat.label : task.ownerSeatId) + " · 模型:" + modelLabelOf(task.ownerSeatId) + " · 状态:" + taskLabel(task.status))),
task.result ? (0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "结果"), (0, import_react.createElement)("p", null, task.result)) : null,
(0, import_react.createElement)(
"div",
{ className: "modal-actions" },
task.status === "draft" ? (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: () => {
void dispatchTask(task.id);
setSelectedTask(null);
} }, "派工") : null,
task.status === "draft" || task.status === "dispatched" || task.status === "running" ? (0, import_react.createElement)("button", { type: "button", className: "btn", disabled: busy, onClick: () => {
void cancelTask(task.id);
setSelectedTask(null);
} }, "取消任务") : null,
(0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setSelectedTask(null) }, "关闭")
)
)
);
}
function renderPage() {
if (phase === "loading") return (0, import_react.createElement)("div", { className: "page" }, (0, import_react.createElement)("p", { className: "empty-note" }, "正在载入工作台…"));
if (phase === "no-workspace") return (0, import_react.createElement)("div", { className: "page" }, (0, import_react.createElement)("p", { className: "empty-note" }, "请先在宿主中选择或建立一个项目工作区,再打开三省六部工作台。"));
if (phase === "error" && !view) return (0, import_react.createElement)("div", { className: "page" }, (0, import_react.createElement)("p", { className: "ssv-banner is-error", role: "alert" }, error || "工作台加载失败"), errorRetryable ? (0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", onClick: loadProject }, "重试")) : null);
if (tab === "queue") return renderQueue();
if (tab === "memory") return renderMemory();
if (tab === "settings") return renderSettings();
return renderOverview();
}
return (0, import_react.createElement)(
"div",
{ className: "ssv2 ssw-tab-body" },
(0, import_react.createElement)(
"div",
{ className: "main" },
(0, import_react.createElement)(
"div",
{ className: "panel-top" },
(0, import_react.createElement)("div", { className: "brand" }, (0, import_react.createElement)("span", { className: "seal" }, "三省六部"), (0, import_react.createElement)("span", { className: "sub" }, "DSH 工作台")),
(0, import_react.createElement)(
"button",
{ type: "button", className: "proj", "aria-label": "当前项目", onClick: () => setTab("settings") },
(0, import_react.createElement)("span", { className: "dot" }),
(0, import_react.createElement)("span", null, (0, import_react.createElement)("span", { className: "name" }, wb.project.name || wb.projectTitle || "当前项目"), (0, import_react.createElement)("br"), (0, import_react.createElement)("span", { className: "meta" }, "主项目 · " + wb.project.seatCount + " 席")),
(0, import_react.createElement)("span", { className: "ssv-proj-caret" }, "⌄")
)
),
renderTabs(),
statusBanner,
renderPage()
),
renderTaskModal(),
renderArtifactModal(),
renderTaskDetail()
);
}
// src/client/styles.js
var CSS = `.ssv2{
/* ============ shadcn 式干净后台:平整、利落、高对比 ============
侧边栏 + 统计卡 + 表格的标准后台骨架,全页统一平整处理:
白/浅灰底、1px 细边框、小圆角、无凸凹阴影、无拟物。
钴蓝只给选中态、主按钮与关键数字,其余用中性灰阶分层。 */
& {
color-scheme: light dark;
--bg: #ffffff;
--sidebar-bg: #fafafa;
--panel: #ffffff;
--panel-line: #e4e4e7;
--muted-bg: #f4f4f5;
--ink: #09090b;
--ink-2: #3f3f46;
--muted: #71717a;
--cobalt: #1e40d8;
--cobalt-ink: #17319f;
--cobalt-soft: rgba(30, 64, 216, .08);
--on-accent: #ffffff;
--ok: #2e7d4f;
--warn: #b06a12;
--bad: #b3372c;
--radius-panel: 8px;
--radius-control: 8px;
--font-ui: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
--font-seat: "Noto Serif SC", "Songti SC", serif;
--font-num: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
}
@media (prefers-color-scheme: dark) {
& {
--bg: #09090b;
--sidebar-bg: #0c0c0e;
--panel: #18181b;
--panel-line: #27272a;
--muted-bg: #27272a;
--ink: #fafafa;
--ink-2: #d4d4d8;
--muted: #a1a1aa;
--cobalt: #829cff;
--cobalt-ink: #a9bcff;
--cobalt-soft: rgba(130, 156, 255, .13);
--on-accent: #141a38;
--ok: #5cb582;
--warn: #d99a45;
--bad: #e0705f;
}
}
* { box-sizing: border-box; }
& { height: 100%; }
& {
margin: 0;
background: var(--bg);
color: var(--ink);
font-family: var(--font-ui);
font-size: 14px;
line-height: 1.55;
-webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button, [role="button"], select, summary, input:not([type="checkbox"], [type="radio"]) { min-height: 2.25rem; }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
/* ================= 布局:工作台占满整页(无文件树栏) ================= */
.shell { display: block; min-height: 100vh; }
/* ---------- 面板头部与横向标签页(都在内容区同一平面上) ---------- */
.panel-top { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 9px; }
.brand .seal {
font-family: var(--font-seat); font-weight: 900; font-size: 21px; letter-spacing: .06em;
}
.brand .sub { font-size: 11px; color: var(--muted); letter-spacing: .14em; }
.proj {
margin-left: auto; text-align: left;
display: flex; align-items: center; gap: 10px;
padding: 8px 12px; border-radius: var(--radius-control);
background: var(--panel); border: 1px solid var(--panel-line);
}
.proj:hover { background: var(--muted-bg); }
.proj .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }
.proj .name { font-weight: 700; font-size: 13.5px; }
.proj .meta { font-size: 11.5px; color: var(--muted); }
.proj svg { margin-left: 4px; color: var(--muted); flex: 0 0 auto; }
/* 横向标签页:灰槽轨道 + 白色选中块,与分段控件同一语言 */
.tabs {
margin-top: 18px; display: flex; flex-wrap: wrap; gap: 2px; padding: 3px;
border-radius: var(--radius-control); background: var(--muted-bg);
width: fit-content; max-width: 100%;
}
.tabs a {
display: inline-flex; align-items: center; gap: 8px;
padding: 6px 15px; border-radius: 6px;
color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 13.5px;
min-height: 36px; white-space: nowrap;
}
.tabs a svg { flex: 0 0 auto; opacity: .75; }
.tabs a:hover { color: var(--ink); }
.tabs a.on {
color: var(--cobalt-ink); font-weight: 700;
background: var(--panel); border: 1px solid var(--panel-line); padding: 5px 14px;
}
.tabs a.on svg { opacity: 1; color: var(--cobalt); }
/* ---------- 主区 ---------- */
.main { min-width: 0; padding: 24px 28px 40px; width: 100%; }
/* ---------- 页签页面:一次只显示一页 ---------- */
.page[hidden] { display: none; }
.page > .topbar { margin-top: 20px; }
tbody tr.clickable { cursor: pointer; }
.settings-stack { display: flex; flex-direction: column; gap: 20px; margin-top: 20px; }
.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: .01em; }
.topbar .date { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }
.search {
display: flex; align-items: center; gap: 8px;
border-radius: var(--radius-control); border: 1px solid var(--panel-line); background: var(--panel);
padding: 0 12px; flex: 0 1 250px; min-width: 0;
}
.search:focus-within { border-color: var(--cobalt); }
.search svg { color: var(--muted); flex: 0 0 auto; }
.search input { border: 0; background: none; outline: none; width: 100%; color: var(--ink); font: inherit; font-size: 13.5px; }
.search input::placeholder { color: var(--muted); }
.btn {
display: inline-flex; align-items: center; gap: 7px;
padding: 8px 16px; border-radius: var(--radius-control); font-weight: 500;
background: var(--panel); border: 1px solid var(--panel-line);
white-space: nowrap;
}
.btn:hover { background: var(--muted-bg); }
.btn.primary { background: var(--cobalt); border-color: var(--cobalt); color: var(--on-accent); font-weight: 700; }
.btn.primary:hover { background: var(--cobalt-ink); border-color: var(--cobalt-ink); }
/* 页头主按钮位:丞相(派工经丞相下达,点开即向丞相交代任务) */
.btn-cx { gap: 9px; }
.btn-cx .cx-name { font-family: var(--font-seat); font-weight: 900; font-size: 16px; letter-spacing: .05em; line-height: 1; }
.btn-cx .cx-dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(255,255,255,.22); flex: 0 0 auto; }
.btn-cx .cx-dot.idle { background: #d4d4d8; box-shadow: none; }
.btn-cx .cx-state { font-size: 12px; font-weight: 500; opacity: .88; }
.btn-cx.selected { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--cobalt); }
.ws-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.ws-actions .btn { padding: 7px 16px; }
.modal input[type="text"] {
width: 100%; border: 1px solid var(--panel-line); border-radius: var(--radius-control);
background: var(--panel); color: var(--ink); font: inherit; font-size: 13.5px;
padding: 8px 10px;
}
.modal input[type="text"]:focus { border-color: var(--cobalt); outline: none; }
/* ---------- 统计卡(骨架:平、脆、白) ---------- */
.stats {
display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px;
margin-top: 22px;
}
.stat {
background: var(--panel); border: 1px solid var(--panel-line);
border-radius: var(--radius-panel); padding: 16px 18px 14px;
}
.stat .label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.stat .big { font-family: var(--font-num); font-size: 30px; font-weight: 600; line-height: 1.25; margin-top: 2px; }
.stat .big .unit { font-size: 14px; color: var(--muted); font-weight: 400; }
.stat .big em { font-style: normal; color: var(--cobalt); }
.stat .foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .foot b { color: var(--ink-2); font-weight: 500; }
.spark { display: block; margin-top: 6px; }
/* ---------- 内容网格 ---------- */
.grid {
display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 368px); gap: 20px;
margin-top: 20px; align-items: start;
}
.panel-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { font-size: 16px; margin: 0; font-weight: 700; }
.panel-head .hint { font-size: 12.5px; color: var(--muted); }
/* 分段控件:平底灰槽 + 白色选中块 */
.seg {
margin-left: auto; display: inline-flex; gap: 2px; padding: 3px;
border-radius: var(--radius-control); background: var(--muted-bg);
}
.seg button { padding: 5px 14px; border-radius: 6px; font-size: 13px; color: var(--ink-2); min-height: 32px; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--panel); border: 1px solid var(--panel-line); color: var(--ink); font-weight: 700; padding: 4px 13px; }
/* ---------- 席位谱系:紧凑对齐 · 宽3排 / 中4排 / 窄5排 ----------
三省与六部共用一个整宽块:不再居中定宽 760px(宽屏下两边大片留白),
改为撑满内容区、与上方统计卡和下方表格左右齐平,两排总宽仍相等、上下对齐成块。
所有列宽一律 minmax(0, 1fr):可随容器一路流式收缩。
三省恒为一排:尚书居中,中书、门下贴其两侧;六部宽屏 6 列、中屏 3×2、窄屏 2×3。 */
.org-rows {
--tree-line: #c6c6cd; padding-top: 2px;
--ss-gap: 14px;
--lb-gap: 10px;
max-width: none; margin: 0; width: 100%; min-width: 0;
/* 谱系块自身成为容器:六部排数按本块的实际宽度决定(容器查询),
不再只看视口——外壳/分栏让呈现宽度与视口不一致时,视口断点永远等不到。 */
container-type: inline-size;
container-name: orgtree;
}
@media (prefers-color-scheme: dark) { .org-rows { --tree-line: #3d3d44; } }
.org-row { display: grid; gap: var(--lb-gap); min-width: 0; }
.org-row-1 { grid-template-columns: minmax(0, 1fr); }
.org-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--ss-gap); }
.org-row-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.org-cell { display: flex; justify-content: center; min-width: 0; }
.org-row-1 .node { width: min(248px, 100%); }
.org-row-3 .node { width: 100%; max-width: none; padding: 15px 18px 13px; }
.org-row-3 .node-name { font-size: 24px; }
.org-row-3 .node-role { font-size: 12.5px; }
.org-row-3 .node-task { font-size: 13px; }
.org-row-3 .node-model { font-size: 12.5px; }
.org-row-6 .node { width: 100%; max-width: none; }
/* 六部节点:撑满整宽后每席约 200px+,字号回到正常档,文字不再截断 */
.org-row-6 .node { padding: 12px 14px 11px; }
.org-row-6 .node-top { gap: 4px 6px; flex-wrap: wrap; }
.org-row-6 .node-name { font-size: 20px; }
.org-row-6 .status { font-size: 12px; gap: 5px; }
.org-row-6 .node-role { font-size: 12px; margin-top: 3px; }
.org-row-6 .node-task { font-size: 12.5px; margin-top: 6px; }
.org-row-6 .node-model { font-size: 12px; margin-top: 6px; }
.org-row-6 .node-foot { margin-top: 8px; }
/* 排间连线层:竖线对准每列中心,横线贯通,全部横平竖直;高度收紧到 22px */
.org-wires { position: relative; height: 22px; }
.org-wires .wire-v { position: absolute; width: 1px; background: var(--tree-line); }
.org-wires .wire-h { position: absolute; height: 1px; background: var(--tree-line); }
/* ===== 六部换行:触发依据是谱系块自身的宽度,不是视口 =====
根因(旧版):排数只由 @media (max-width:1080px/640px) 两条视口断点控制。
在应用外壳里,页面呈现宽度(分栏/嵌入)与视口宽并不总是一致,窗口缩到
视口断点之前就停住时,两条断点永远等不到,六张卡只能一味变小、挤在一排。
根治:三路同阈值(按谱系块宽:>1180 一排 6 张;≤1180 → 3×2;≤700 → 2×3)——
① JS ResizeObserver 实测 .org-rows 宽度写入 data-cols(主路,见脚本);
② @container 容器查询(CSS 原生同义路);③ @media 视口断点(兜底,数值已
按主区左右内边距 56px 换算对齐)。三省在任何档位恒为一排。 */
/* 中档:六部 3 列 × 2 排,每排总宽仍与三省排同宽对齐 */
.org-rows[data-cols="3"] { --ss-gap: 10px; --lb-gap: 10px; }
.org-rows[data-cols="3"] .org-row-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.org-rows[data-cols="3"] .org-wires-2 .wire-h { left: 16.6667% !important; right: 16.6667% !important; }
.org-rows[data-cols="3"] .org-wires-2 .w2-b1 { left: 16.6667% !important; }
.org-rows[data-cols="3"] .org-wires-2 .w2-b2 { left: 50% !important; }
.org-rows[data-cols="3"] .org-wires-2 .w2-b3 { left: 83.3333% !important; }
.org-rows[data-cols="3"] .org-wires-2 .w2-b4,
.org-rows[data-cols="3"] .org-wires-2 .w2-b5,
.org-rows[data-cols="3"] .org-wires-2 .w2-b6 { display: none; }
@container orgtree (max-width: 1180px) {
.org-row-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.org-wires-2 .wire-h { left: 16.6667% !important; right: 16.6667% !important; }
.org-wires-2 .w2-b1 { left: 16.6667% !important; }
.org-wires-2 .w2-b2 { left: 50% !important; }
.org-wires-2 .w2-b3 { left: 83.3333% !important; }
.org-wires-2 .w2-b4, .org-wires-2 .w2-b5, .org-wires-2 .w2-b6 { display: none; }
}
@media (max-width: 1240px) {
.org-row-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.org-wires-2 .wire-h { left: 16.6667% !important; right: 16.6667% !important; }
.org-wires-2 .w2-b1 { left: 16.6667% !important; }
.org-wires-2 .w2-b2 { left: 50% !important; }
.org-wires-2 .w2-b3 { left: 83.3333% !important; }
.org-wires-2 .w2-b4, .org-wires-2 .w2-b5, .org-wires-2 .w2-b6 { display: none; }
}
/* 窄档:六部 2 列 × 3 排;三省仍一排;卡片上的「主任模型」行隐藏(配置面板不受影响) */
.org-rows[data-cols="2"] { --ss-gap: 8px; --lb-gap: 8px; }
.org-rows[data-cols="2"] .org-row-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.org-rows[data-cols="2"] .node-model { display: none; }
.org-rows[data-cols="2"] .org-wires-2 .wire-h { left: 25% !important; right: 25% !important; }
.org-rows[data-cols="2"] .org-wires-2 .w2-b1 { left: 25% !important; }
.org-rows[data-cols="2"] .org-wires-2 .w2-b2 { left: 75% !important; }
.org-rows[data-cols="2"] .org-wires-2 .w2-b3,
.org-rows[data-cols="2"] .org-wires-2 .w2-b4,
.org-rows[data-cols="2"] .org-wires-2 .w2-b5,
.org-rows[data-cols="2"] .org-wires-2 .w2-b6 { display: none; }
.org-rows[data-cols="2"] .org-row .node { padding: 9px 9px 8px; }
.org-rows[data-cols="2"] .org-row-3 .node-name { font-size: 18px; }
.org-rows[data-cols="2"] .org-row-6 .node-name { font-size: 17px; }
.org-rows[data-cols="2"] .org-row .status { font-size: 11px; gap: 4px; }
.org-rows[data-cols="2"] .org-row .node-top { gap: 5px; flex-wrap: wrap; }
@container orgtree (max-width: 700px) {
.org-row-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.node-model { display: none; }
.org-wires-2 .wire-h { left: 25% !important; right: 25% !important; }
.org-wires-2 .w2-b1 { left: 25% !important; }
.org-wires-2 .w2-b2 { left: 75% !important; }
.org-wires-2 .w2-b3, .org-wires-2 .w2-b4, .org-wires-2 .w2-b5, .org-wires-2 .w2-b6 { display: none; }
.org-row .node { padding: 9px 9px 8px; }
.org-row-3 .node-name { font-size: 18px; }
.org-row-6 .node-name { font-size: 17px; }
.org-row .status { font-size: 11px; gap: 4px; }
}
@media (max-width: 760px) {
.node-model { display: none !important; }
.org-row-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.org-wires-2 .wire-h { left: 25% !important; right: 25% !important; }
.org-wires-2 .w2-b1 { left: 25% !important; }
.org-wires-2 .w2-b2 { left: 75% !important; }
.org-wires-2 .w2-b3, .org-wires-2 .w2-b4, .org-wires-2 .w2-b5, .org-wires-2 .w2-b6 { display: none; }
.org-row .node { padding: 9px 9px 8px; }
.org-row-3 .node-name { font-size: 18px; }
.org-row-6 .node-name { font-size: 17px; }
.org-row .status { font-size: 11px; gap: 4px; }
.org-row .node-top { gap: 5px; flex-wrap: wrap; }
}
.node {
width: 158px; min-width: 0;
border-radius: var(--radius-panel); background: var(--panel);
border: 1px solid var(--panel-line); padding: 11px 13px 10px;
position: relative; z-index: 1;
}
.node-main { min-width: 0; }
.node-role, .node-task { overflow-wrap: break-word; }
.node-model .num { overflow-wrap: anywhere; }
.node:hover { border-color: var(--muted); }
.node.selected { border-color: var(--cobalt); background: var(--cobalt-soft); }
.node.dim { opacity: .28; }
.node-main { display: block; width: 100%; text-align: left; padding: 0; min-height: 0; }
.node-role, .node-task, .node-model { display: block; }
.node-top { display: flex; align-items: center; gap: 8px; }
.node-name { font-family: var(--font-seat); font-weight: 900; font-size: 21px; line-height: 1.1; letter-spacing: .04em; }
.node.selected .node-name { color: var(--cobalt); }
.node.root { width: min(248px, 100%); }
.node.root .node-name { font-size: 25px; }
@media (max-width: 1400px) {
.node { width: 136px; }
.node.root { width: min(248px, 100%); }
}
.node-role { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.node-task { margin-top: 7px; font-size: 12px; color: var(--ink-2); }
.node-task .t-label { color: var(--muted); font-size: 11px; display: block; }
.node-model { margin-top: 6px; font-size: 11.5px; color: var(--muted); }
.node-model .num { font-size: 11px; }
.node-foot { margin-top: 9px; display: flex; align-items: center; gap: 8px; }
.status { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.status.run i { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,125,79,.16); }
.status.review i { background: var(--warn); box-shadow: 0 0 0 3px rgba(176,106,18,.16); }
.status.idle i { background: var(--muted); }
.elapsed { font-size: 12px; color: var(--muted); }
/* ---------- 节点纵向骨架:内容区撑满,已耗时一行钉在卡底 ---------- */
.node { display: flex; flex-direction: column; }
.node-main { flex: 1 1 auto; display: flex; flex-direction: column; }
.node-foot { margin-top: auto; }
.node-task .task-text { display: block; }
/* ---------- 席位详情头:标题 + 开始对话主按钮 ---------- */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.detail-head h3 { flex: 1; min-width: 0; margin: 0; }
.detail-head .btn { flex: 0 0 auto; padding: 7px 16px; }
/* ---------- 会话弹窗:与该席对话 ---------- */
.chat-log { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.chat-msg {
max-width: 88%; padding: 9px 12px; border-radius: 8px;
font-size: 13.5px; line-height: 1.6; overflow-wrap: anywhere;
}
.chat-msg.seat { background: var(--muted-bg); color: var(--ink-2); align-self: flex-start; }
.chat-msg.me { background: var(--cobalt); color: var(--on-accent); align-self: flex-end; }
.chat-compose { display: flex; gap: 10px; margin-top: 16px; align-items: flex-end; }
.chat-compose textarea {
flex: 1; min-height: 44px; resize: vertical;
border: 1px solid var(--panel-line); border-radius: var(--radius-control);
background: var(--panel); color: var(--ink); font: inherit; font-size: 13.5px;
padding: 8px 10px;
}
.chat-compose textarea:focus { border-color: var(--cobalt); outline: none; }
.chat-compose .btn { flex: 0 0 auto; padding: 8px 18px; }
.chat-card { margin-top: 20px; }
.chat-card .chat-log { margin-top: 0; min-height: 260px; }
.chat-card .m-decided { margin: 12px 0 0; font-size: 13px; color: var(--muted); }
/* ---------- 六部:六张等高卡,每段单行固定高,卡底已耗时齐平 ---------- */
.org-row-6 .node { height: 100%; padding: 12px 14px; }
.org-row-6 .node-top { flex-wrap: nowrap; height: 30px; overflow: hidden; }
.org-row-6 .node-name { flex: 0 0 auto; }
.org-row-6 .status { flex: 0 0 auto; }
.org-row-6 .node-role {
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
height: 20px; line-height: 20px; margin-top: 4px;
}
.org-row-6 .node-task { margin-top: 8px; }
.org-row-6 .node-task .t-label { height: 16px; line-height: 16px; }
.org-row-6 .node-task .task-text {
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
height: 20px; line-height: 20px;
}
.org-row-6 .node-model {
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
height: 20px; line-height: 20px; margin-top: 6px;
}
.org-row-6 .node-foot { margin-top: auto; padding-top: 9px; }
.org-row-6 .elapsed {
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
height: 20px; line-height: 20px; display: block;
}
/* ---------- 右列:详情 + 复核(骨架面板) ---------- */
.rail { display: flex; flex-direction: column; gap: 20px; }
.detail-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.card {
background: var(--panel); border: 1px solid var(--panel-line);
border-radius: var(--radius-panel); padding: 18px;
}
.card h3 { margin: 0 0 4px; font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card h3 .count {
font-family: var(--font-num); font-size: 11.5px; background: var(--cobalt); color: var(--on-accent);
border-radius: 999px; padding: 0 8px; line-height: 19px;
}
.detail-name { font-family: var(--font-seat); font-weight: 900; font-size: 30px; color: var(--cobalt); line-height: 1.15; }
.detail-role { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: 74px 1fr; row-gap: 8px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--ink); }
.kv dd .sub { color: var(--muted); font-size: 12px; }
.excerpt {
margin-top: 14px; border-top: 1px dashed var(--panel-line); padding-top: 12px;
font-size: 13px; color: var(--ink-2);
}
.excerpt .t-label { color: var(--muted); font-size: 11.5px; display: block; margin-bottom: 4px; }
/* ---------- 部门配置面板:平表单 + 圆点文字标状态 ---------- */
.card h3 .seat-tag { color: var(--cobalt); font-family: var(--font-seat); font-weight: 900; font-size: 16px; }
.cfg-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 16px; margin-top: 10px; }
.cfg-row { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.cfg-row select {
border: 1px solid var(--panel-line); border-radius: var(--radius-control);
background: var(--panel); color: var(--ink); font: inherit; font-size: 13.5px;
padding: 7px 10px; width: 100%;
}
.cfg-row select:focus { border-color: var(--cobalt); outline: none; }
.cfg-skills { margin-top: 16px; border-top: 1px dashed var(--panel-line); padding-top: 12px; }
.cfg-skills .t-label { color: var(--muted); font-size: 11.5px; display: block; }
.skill-list { list-style: none; margin: 4px 0 0; padding: 0; }
.skill-list li {
display: flex; align-items: center; gap: 10px;
padding: 8px 0; border-top: 1px solid var(--panel-line); font-size: 13px;
}
.skill-list li:first-child { border-top: 0; padding-top: 4px; }
.skill-list .skill-name { flex: 1; min-width: 0; }
.skill-list .skill-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.skill-list .skill-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.skill-list .skill-state.bound { color: var(--ink); }
.skill-list .skill-state.bound i { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,125,79,.16); }
.skill-toggle {
border: 1px solid var(--panel-line); border-radius: var(--radius-control);
background: var(--panel); padding: 4px 13px; font-size: 12.5px; min-height: 32px; white-space: nowrap;
}
.skill-toggle:hover { background: var(--muted-bg); }
@media (max-width: 640px) { .cfg-grid { grid-template-columns: 1fr; } }
/* ---------- 工作区条目:一条一卡(门下审核 / 中书方案 / 尚书调度共用同一套) ---------- */
.review-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.review-card {
background: var(--panel); border: 1px solid var(--panel-line);
border-radius: var(--radius-panel); padding: 14px 16px 12px;
}
.review-card.decided { opacity: .55; }
.rc-head { display: flex; align-items: center; gap: 10px; }
.rc-title {
flex: 1; min-width: 0; font-weight: 700; font-size: 14.5px; color: var(--ink);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rc-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); white-space: nowrap; flex: 0 0 auto; }
.rc-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 3px rgba(176,106,18,.16); flex: 0 0 auto; }
.rc-status.pass i { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,125,79,.16); }
.rc-status.reject i { background: var(--bad); box-shadow: 0 0 0 3px rgba(179,55,44,.14); }
.rc-status.run i { background: var(--cobalt); box-shadow: 0 0 0 3px var(--cobalt-soft); }
.rc-status.idle i { background: var(--muted); box-shadow: none; }
.rc-meta-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.rc-from {
font-size: 11.5px; font-weight: 500; color: var(--ink-2);
background: var(--muted-bg); border-radius: 999px; padding: 1px 9px; line-height: 19px;
white-space: nowrap;
}
.rc-meta { font-size: 12px; color: var(--muted); }
.rc-excerpt {
margin-top: 10px; background: var(--muted-bg); border-radius: 6px;
padding: 9px 11px; font-size: 12.5px; color: var(--ink-2); line-height: 1.6;
display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.rc-excerpt.expanded { display: block; -webkit-line-clamp: unset; }
/* 定夺后记在卡上的批复理由 / 批语(回传提交席位照此修改) */
.rc-reason {
margin-top: 10px; background: var(--muted-bg); border-radius: 6px;
padding: 8px 11px; font-size: 12.5px; color: var(--ink-2); line-height: 1.6;
overflow-wrap: anywhere;
}
.rc-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.rc-actions .spacer { flex: 1; }
.rc-actions .btn { padding: 5px 14px; font-size: 13px; min-height: 34px; }
.rc-actions .btn.pass { color: var(--cobalt-ink); font-weight: 700; }
.rc-actions .btn:disabled { opacity: .5; cursor: default; }
.rc-actions .btn:disabled:hover { background: var(--panel); }
.r-open {
display: inline-flex; align-items: center; gap: 4px;
font-size: 13px; font-weight: 500; color: var(--cobalt); padding: 5px 6px; min-height: 34px;
}
.r-open:hover { color: var(--cobalt-ink); text-decoration: underline; }
.empty-note { font-size: 13px; color: var(--muted); padding: 10px 0 2px; }
/* ---------- 席位工作区:随选中席位切换内容 ---------- */
.w-kind {
font-size: 11.5px; font-weight: 500; color: var(--cobalt-ink);
background: var(--cobalt-soft); border-radius: 999px; padding: 1px 9px; line-height: 19px;
}
.ws-sec { margin-top: 14px; }
.ws-sec:first-child { margin-top: 6px; }
.ws-sec .t-label { color: var(--muted); font-size: 11.5px; display: block; margin-bottom: 4px; }
.ws-sec p { margin: 0; font-size: 13.5px; color: var(--ink-2); }
/* 方案 / 调度 / 审核条目样式见上方「工作区条目:一条一卡」 */
/* ---------- 右列里的配置面板:字段上下排 ---------- */
.rail .cfg-grid { grid-template-columns: minmax(0, 1fr); }
/* ---------- 复核弹窗:看清待准奏内容再定夺 ---------- */
.modal-backdrop {
position: fixed; inset: 0; z-index: 60;
background: rgba(9, 9, 11, .48);
display: flex; align-items: center; justify-content: center;
padding: 18px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
background: var(--panel); color: var(--ink);
border: 1px solid var(--panel-line); border-radius: 12px;
width: min(580px, 100%); max-height: calc(100vh - 36px); overflow-y: auto;
padding: 20px 22px 18px;
}
.modal-head { display: flex; align-items: flex-start; gap: 12px; }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; flex: 1; min-width: 0; }
.modal-close {
flex: 0 0 auto; width: 32px; height: 32px; min-height: 32px;
border: 1px solid var(--panel-line); border-radius: var(--radius-control);
display: inline-flex; align-items: center; justify-content: center; font-size: 15px;
}
.modal-close:hover { background: var(--muted-bg); }
.modal .m-from { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.modal .m-sec { margin-top: 15px; }
.modal .m-sec .t-label { color: var(--muted); font-size: 11.5px; display: block; margin-bottom: 4px; }
.modal .m-sec p { margin: 0; font-size: 13.5px; color: var(--ink-2); }
.modal .m-doubts { list-style: none; margin: 0; padding: 0; }
.modal .m-doubts li { padding: 6px 0 6px 16px; border-top: 1px solid var(--panel-line); font-size: 13.5px; color: var(--ink-2); position: relative; }
.modal .m-doubts li:first-child { border-top: 0; }
.modal .m-doubts li::before { content: ""; position: absolute; left: 2px; top: 14px; width: 5px; height: 5px; border-radius: 50%; background: var(--warn); }
.modal .m-source {
background: var(--muted-bg); border-radius: var(--radius-panel);
padding: 10px 12px; font-size: 13px; color: var(--ink-2);
}
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { padding: 7px 18px; }
.modal-actions .btn.pass { color: var(--cobalt-ink); font-weight: 700; }
.modal .m-decided { margin-top: 16px; font-size: 13px; color: var(--muted); }
.modal textarea {
width: 100%; border: 1px solid var(--panel-line); border-radius: var(--radius-control);
background: var(--panel); color: var(--ink); font: inherit; font-size: 13.5px;
padding: 8px 10px; resize: vertical; min-height: 64px;
}
.modal textarea:focus { border-color: var(--cobalt); outline: none; }
.modal .m-err { color: var(--bad); font-size: 12.5px; margin: 6px 0 0; }
.modal .m-err[hidden] { display: none; }
/* ---------- 表格(骨架:干脆、高对比、无拟物) ---------- */
.table-card {
margin-top: 20px; background: var(--panel); border: 1px solid var(--panel-line);
border-radius: var(--radius-panel); padding: 18px 18px 8px;
}
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
text-align: left; font-size: 12px; color: var(--muted); font-weight: 500;
padding: 8px 12px; border-bottom: 1px solid var(--panel-line); white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--panel-line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--cobalt-soft); }
td .task-name { font-weight: 500; }
td .task-id { font-family: var(--font-num); font-size: 11.5px; color: var(--muted); }
.pill {
display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500;
border: 1px solid var(--panel-line); border-radius: 999px; padding: 2px 10px; white-space: nowrap;
background: var(--panel);
}
.pill i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.pill.done i { background: var(--ok); }
.pill.run i { background: var(--cobalt); }
.pill.review i { background: var(--warn); }
.pill.fail i { background: var(--bad); }
td.time, td.dur { font-family: var(--font-num); font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.foot-note { margin-top: 16px; font-size: 12px; color: var(--muted); }
/* ---------- 窄屏回落(只保证不横滚;席位排数由谱系自己的断点管) ---------- */
@media (max-width: 1180px) {
.grid { grid-template-columns: 1fr; }
.rail { flex-direction: row; align-items: stretch; }
.rail .card { flex: 1; }
.stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
.proj { margin-left: 0; }
.tabs { width: 100%; }
.tabs a { flex: 1 1 auto; justify-content: center; }
.main { padding: 14px 16px 32px; }
.rail { flex-direction: column; }
.search { width: 100%; order: 5; }
.stats { grid-template-columns: 1fr 1fr; gap: 10px; }
}
@media (max-width: 640px) {
/* 手机上表格收成四列:藏「模型」「耗时」两列,单元格允许换行,不横滚 */
thead th:nth-child(3), tbody td:nth-child(3),
thead th:nth-child(5), tbody td:nth-child(5) { display: none; }
thead th, tbody td { padding-left: 8px; padding-right: 8px; }
thead th { white-space: normal; }
td .task-name, td .task-id { overflow-wrap: anywhere; }
.pill { padding: 2px 7px; font-size: 11.5px; white-space: normal; }
td.time { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
* { transition: none !important; }
}
}
body[data-ds-dark-theme] .ssv2,html[data-theme=dark] .ssv2,.ssv2[data-ssv-theme=dark]{--bg:#09090b;--sidebar-bg:#0c0c0e;--panel:#18181b;--panel-line:#27272a;--muted-bg:#27272a;--ink:#fafafa;--ink-2:#d4d4d8;--muted:#a1a1aa;--cobalt:#829cff;--cobalt-ink:#a9bcff;--cobalt-soft:rgba(130,156,255,.13);--on-accent:#141a38;--ok:#5cb582;--warn:#d99a45;--bad:#e0705f}
/* ---------- 宿主接线:右栏 / 浮动面板 / 内嵌条 ---------- */
.ssw-tab-body{height:100%;min-height:0;display:flex;flex-direction:column;overflow:hidden}
.ssw-tab-title{font-size:12px;font-weight:600}
.ssw-inline-bar{flex:none;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px 14px;background:var(--muted-bg);border-bottom:1px solid var(--panel-line);font-size:12px;color:var(--muted)}
.ssw-link{color:var(--cobalt-ink);font-size:12px;font-weight:500;padding:4px 6px;border-radius:6px}
.ssw-link:hover{background:var(--cobalt-soft)}
.ssw-nav-hit{display:inline-flex;align-items:center;justify-content:center;color:inherit;width:100%;height:100%}
.ssw-float{position:fixed;right:14px;bottom:70px;z-index:2147483000;width:min(760px,calc(100vw - 28px));max-height:calc(100vh - 96px);display:flex;flex-direction:column;background:var(--panel,#fff);border:1px solid var(--panel-line,#e4e4e7);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}
.ssw-float>.ssv2{height:100%;min-height:0;overflow:auto}
/* ---------- 工作台 v2 工具样式 ---------- */
.ssv2{height:100%;min-height:0;overflow:auto;background:var(--bg);color:var(--ink);font-family:var(--font-ui)}
.ssv2 .main{min-height:100%}
.ssv2 .page{min-height:0}
.ssv-banner{margin:12px 0 0;padding:9px 12px;border-radius:8px;font-size:12.5px;line-height:1.5;border:1px solid var(--panel-line);background:var(--muted-bg);color:var(--ink-2)}
.ssv-banner.is-error{color:var(--bad);background:color-mix(in srgb, var(--bad) 8%, var(--panel));border-color:color-mix(in srgb, var(--bad) 24%, var(--panel-line))}
.ssv-banner.is-notice{color:var(--cobalt-ink);background:var(--cobalt-soft);border-color:color-mix(in srgb, var(--cobalt) 20%, var(--panel-line))}
.ssv-textarea{width:100%;box-sizing:border-box;border:1px solid var(--panel-line);border-radius:var(--radius-control);background:var(--panel);color:var(--ink);font:inherit;font-size:13px;line-height:1.55;padding:7px 10px;resize:vertical}
.ssv-textarea:focus{border-color:var(--cobalt);outline:none}
.ssv-select{width:100%;border:1px solid var(--panel-line);border-radius:var(--radius-control);background:var(--panel);color:var(--ink);font:inherit;font-size:13.5px;padding:7px 10px}
.ssv-select:focus{border-color:var(--cobalt);outline:none}
.ssv-check{display:flex;align-items:center;gap:8px;margin-top:12px;font-size:13px;color:var(--ink-2);cursor:pointer}
.ssv-check input{accent-color:var(--cobalt);width:15px;height:15px}
.ssv-proj-caret{font-size:15px;color:var(--muted);margin-left:2px}
.ssv2 .ws-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:12px}
.ssv2 .ws-actions .btn{min-height:34px;padding:5px 12px;font-size:13px}
.ssv2 .skill-list li{gap:8px}
.ssv2 .skill-list .skill-toggle{flex:none}
.ssv2 .card h3 .count{font-family:var(--font-num)}
`;
// 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 && seat.status === "bound" && 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 + "会话" : seat.status === "missing" ? meta.label + "会话缺失,请到 Web 工作台重建" : 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_react2 = 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_react2.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_react2.createElement)("rect", { key: "a", x: 9, y: 2, width: 6, height: 5, rx: 1 }),
(0, import_react2.createElement)("path", { key: "b", d: "M12 7v5M5 16v-4h14v4" }),
(0, import_react2.createElement)("rect", { key: "c", x: 2, y: 16, width: 6, height: 5, rx: 1 }),
(0, import_react2.createElement)("rect", { key: "d", x: 16, y: 16, width: 6, height: 5, rx: 1 })
], props);
var CloseIcon = (props) => svgWrap([(0, import_react2.createElement)("path", { key: "p", d: "m6 6 12 12M6 18 18 6" })], props);
var FolderIcon = (props) => svgWrap([(0, import_react2.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_react2.createElement)("path", { key: "a", d: "M4 6h16M4 12h16M4 18h16" }),
(0, import_react2.createElement)("circle", { key: "b", cx: 9, cy: 6, r: 2 }),
(0, import_react2.createElement)("circle", { key: "c", cx: 16, cy: 12, r: 2 }),
(0, import_react2.createElement)("circle", { key: "d", cx: 8, cy: 18, r: 2 })
], props);
var ChevronIcon = (props) => (0, import_react2.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_react2.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_react2.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_react2.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 seatRecordOf2(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_react2.createElement)("div", { className: "ssw-tab-body" }, (0, import_react2.createElement)(SanshengWorkbench, {}));
}
function SanshengTabTitle() {
return (0, import_react2.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_react2.createElement)(TreeIcon, { width: size, height: size }),
order: 32,
single: true,
component: () => (0, import_react2.createElement)("div", { className: "ssw-tab-body" }, (0, import_react2.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);
}
}
const selectedSeatCache = /* @__PURE__ */ new Map();
let lastSelectedSeatId = SEAT_IDS[0];
function SanshengWorkbench(props) {
return (0, import_react2.createElement)(WorkbenchV2, {
onClose: props && props.onClose,
resolveWorkspace: currentWorkspace,
navigateToSession,
openRightTab: tryOpenRightTab,
selectionCache: selectedSeatCache,
getLastSeatId: () => lastSelectedSeatId,
setLastSeatId: (id) => {
lastSelectedSeatId = id;
}
});
}
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_react2.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_react2.createElement)(
"div",
{ className: "ssw-float", role: "dialog", "aria-label": "三省六部工作台" },
(0, import_react2.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_react2.createElement)(
import_react2.Fragment,
null,
(0, import_react2.createElement)("span", {
className: "ssw-nav-hit",
role: "presentation",
title: "三省六部",
onClick,
onPointerDown: stop,
onMouseDown: stop,
"aria-expanded": floating ? "true" : "false"
}, (0, import_react2.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 hasBetterSidebar = !!get("betterSidebar");
const [mode, setMode] = (0, import_react2.useState)("pending");
(0, import_react2.useEffect)(() => {
let opened = false;
try {
opened = openRightWorkbench();
} catch {
opened = false;
}
if (opened) {
setMode("docked");
backToChat();
return void 0;
}
if (!hasBetterSidebar) {
setMode("inline");
return void 0;
}
backToChat();
let openedLater = false;
for (const delay of [200, 600, 1200, 2e3]) {
setTimeout(() => {
try {
if (!openedLater && openRightWorkbench()) {
openedLater = true;
backToChat();
}
} catch {
}
}, delay);
}
setTimeout(() => {
if (!openedLater) setMode("inline");
}, 2600);
return void 0;
}, []);
(0, import_react2.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_react2.createElement)(
"div",
{ className: "ssw-tab-body" },
(0, import_react2.createElement)(
"div",
{ className: "ssw-inline-bar" },
(0, import_react2.createElement)("span", null, "工作台 · 内嵌模式"),
(0, import_react2.createElement)("button", { type: "button", className: "ssw-link", onClick: backToChat }, "返回对话")
),
(0, import_react2.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' })
},
})