1759 lines
93 KiB
JavaScript
1759 lines
93 KiB
JavaScript
window.__ModuleLoader__.load({
|
||
id: "dsh-sansheng-liubu-panel",
|
||
factory: (require) => {
|
||
var module = { exports: {} };
|
||
var exports = module.exports;
|
||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||
|
||
const React = require("react");
|
||
const h = React.createElement;
|
||
|
||
// #region 常量与纯函数(与 lib/model.js 保持一致,客户端 bundle 需自包含)
|
||
const PANEL_ID = "sansheng-liubu";
|
||
const SANSENG_TAB_ID = PANEL_ID + "-tab";
|
||
const SANSENG_TAB_KIND = "sansheng";
|
||
|
||
const ROLE_IDS = ["lead", "zhongshu", "menxia", "shangshu", "libu", "hubu", "lipu", "bingbu", "xingbu", "gongbu"];
|
||
const ROLE_LABELS = {
|
||
lead: "丞相",
|
||
zhongshu: "中书省",
|
||
menxia: "门下省",
|
||
shangshu: "尚书省",
|
||
libu: "吏部",
|
||
hubu: "户部",
|
||
lipu: "礼部",
|
||
bingbu: "兵部",
|
||
xingbu: "刑部",
|
||
gongbu: "工部",
|
||
};
|
||
const ROLE_MARKS = {
|
||
lead: "丞",
|
||
zhongshu: "中",
|
||
menxia: "门",
|
||
shangshu: "尚",
|
||
libu: "吏",
|
||
hubu: "户",
|
||
lipu: "礼",
|
||
bingbu: "兵",
|
||
xingbu: "刑",
|
||
gongbu: "工",
|
||
};
|
||
const ROLE_DUTIES = {
|
||
lead: "统筹全局、向用户汇报、最终交付",
|
||
zhongshu: "拟案规划,拆解任务与验收标准",
|
||
menxia: "审议准奏与交付验收,可否决",
|
||
shangshu: "派工调度,合成各部门成果",
|
||
libu: "Agent 与技能维护、成员编制",
|
||
hubu: "数据、表格与计算,可复算结论",
|
||
lipu: "文档、汇报与可视化产出",
|
||
bingbu: "环境运行、调试与部署,掌武库",
|
||
xingbu: "按风险的专项测试与独立验证",
|
||
gongbu: "编码与工程实现",
|
||
};
|
||
const ROW_OF = {
|
||
lead: 0, zhongshu: 1, shangshu: 1, menxia: 1,
|
||
libu: 2, hubu: 2, lipu: 2, bingbu: 2, xingbu: 2, gongbu: 2,
|
||
};
|
||
const COLUMN_OF = {
|
||
zhongshu: 0, shangshu: 1, menxia: 2,
|
||
libu: 0, hubu: 1, lipu: 2, bingbu: 3, xingbu: 4, gongbu: 5,
|
||
};
|
||
const STATUS_LABELS = {
|
||
running: "运行中",
|
||
idle: "空闲",
|
||
inactive: "空闲",
|
||
provisioning: "创建中",
|
||
failed: "失败",
|
||
absent: "未设官",
|
||
};
|
||
const TASK_LABELS = { pending: "待办", in_progress: "执行中", completed: "已完成" };
|
||
const EFFORT_LABELS = { minimal: "极低", low: "低", medium: "中", high: "高", max: "最高", xhigh: "极高" };
|
||
|
||
function roleLabel(role) {
|
||
return ROLE_LABELS[role] || "成员";
|
||
}
|
||
|
||
function roleMark(role) {
|
||
return ROLE_MARKS[role] || "员";
|
||
}
|
||
|
||
function modelLabel(model) {
|
||
if (typeof model === "string") return model;
|
||
if (!model || typeof model !== "object") return "";
|
||
if (typeof model.name === "string") return model.name;
|
||
if (typeof model.model === "string") return model.model;
|
||
if (typeof model.id === "string") return model.id;
|
||
return "";
|
||
}
|
||
|
||
function effortLabel(effort) {
|
||
if (typeof effort !== "string") return "";
|
||
return EFFORT_LABELS[effort] || effort;
|
||
}
|
||
|
||
function shortText(value, limit) {
|
||
const text = String(value === undefined || value === null ? "" : value).replace(/\s+/g, " ").trim();
|
||
const max = limit || 120;
|
||
return text.length <= max ? text : text.slice(0, max - 1) + "…";
|
||
}
|
||
|
||
function arrangeRoster(team) {
|
||
const members = Array.isArray(team && team.members) ? team.members : [];
|
||
const byRole = new Map();
|
||
for (const member of members) {
|
||
if (member && typeof member.name === "string") byRole.set(member.name, member);
|
||
}
|
||
return ROLE_IDS.map((role) => {
|
||
const member = byRole.get(role);
|
||
return {
|
||
role,
|
||
label: ROLE_LABELS[role],
|
||
mark: ROLE_MARKS[role],
|
||
duty: ROLE_DUTIES[role],
|
||
row: ROW_OF[role],
|
||
column: COLUMN_OF[role],
|
||
id: member && member.id,
|
||
member,
|
||
present: member !== undefined,
|
||
};
|
||
});
|
||
}
|
||
|
||
/** 朝堂总览四数:在朝、运行中、在办、已完成;图与侧栏统计共用同一份投影。 */
|
||
function courtStats(seats, buckets, isRunning) {
|
||
let present = 0;
|
||
let runningCount = 0;
|
||
for (const entry of Array.isArray(seats) ? seats : []) {
|
||
if (!entry.present) continue;
|
||
present += 1;
|
||
if (isRunning(entry) === true) runningCount += 1;
|
||
}
|
||
return [
|
||
{ key: "members", label: "在朝成员", value: present, mark: "员" },
|
||
{ key: "running", label: "正在运行", value: runningCount, mark: "运" },
|
||
{ key: "pending", label: "在办任务", value: (buckets && buckets.in_progress ? buckets.in_progress.length : 0) + (buckets && buckets.pending ? buckets.pending.length : 0), mark: "办" },
|
||
{ key: "done", label: "已完成", value: (buckets && buckets.completed ? buckets.completed.length : 0), mark: "成" },
|
||
];
|
||
}
|
||
|
||
/** 当前正在查看的子会话对应哪一席;找不到时保持现有选择。 */
|
||
function childRoleOf(seats, childSessionId) {
|
||
if (!childSessionId) return undefined;
|
||
const match = (Array.isArray(seats) ? seats : []).find((seat) => seat && seat.id === childSessionId);
|
||
return match ? match.role : undefined;
|
||
}
|
||
|
||
/** 原生输入框里的 @ 候选:只列有会话的部门;丞相主会话由当前输入框承载。 */
|
||
function seatMentionOptions(seats) {
|
||
return (Array.isArray(seats) ? seats : [])
|
||
.filter((seat) => seat && seat.role !== "lead" && typeof seat.id === "string" && seat.id.length > 0)
|
||
.map((seat) => ({
|
||
name: seat.label,
|
||
value: seat.id,
|
||
label: seat.label,
|
||
description: seat.duty + " · 选择后进入该部门会话",
|
||
}));
|
||
}
|
||
|
||
function memberStatus(member, running, summaryRunning) {
|
||
if (member === undefined || member === null) return "absent";
|
||
if (member.phase === "failed") return "failed";
|
||
if (member.phase === "provisioning") return "provisioning";
|
||
return running === true || summaryRunning === true ? "running" : "idle";
|
||
}
|
||
|
||
function bucketsOf(tasks) {
|
||
const buckets = { pending: [], in_progress: [], completed: [] };
|
||
for (const task of Array.isArray(tasks) ? tasks : []) {
|
||
const key = task && task.status;
|
||
if (key === "pending" || key === "in_progress" || key === "completed") buckets[key].push(task);
|
||
else buckets.pending.push(task);
|
||
}
|
||
return buckets;
|
||
}
|
||
|
||
/** 归属某部门的任务;ownerName 可能是角色 id 也可能是中文名。 */
|
||
function tasksOfRole(tasks, role) {
|
||
const list = Array.isArray(tasks) ? tasks : Array.isArray(tasks && tasks.tasks) ? tasks.tasks : [];
|
||
return list.filter((task) => task && (task.ownerName === role || task.ownerName === roleLabel(role)));
|
||
}
|
||
|
||
function statusSummary(seat, team, running, summaryRunning) {
|
||
const status = memberStatus(seat && seat.member, running, summaryRunning);
|
||
const owned = seat ? tasksOfRole(team, seat.role) : [];
|
||
const buckets = bucketsOf(owned);
|
||
return {
|
||
status,
|
||
statusLabel: STATUS_LABELS[status] || status,
|
||
owned,
|
||
runningCount: buckets.in_progress.length,
|
||
pendingCount: buckets.pending.length,
|
||
completedCount: buckets.completed.length,
|
||
};
|
||
}
|
||
|
||
function modelOptions(catalog) {
|
||
const options = [];
|
||
const groups = Array.isArray(catalog && catalog.groups) ? catalog.groups : [];
|
||
for (const group of groups) {
|
||
const provider = group && (group.id || group.provider);
|
||
const models = Array.isArray(group && group.models) ? group.models : [];
|
||
for (const model of models) {
|
||
if (!provider || !model || !model.id) continue;
|
||
const efforts = Array.isArray(model.reasoning && model.reasoning.efforts)
|
||
? model.reasoning.efforts.map((effort) => ({ id: effort.id, name: effort.name || effortLabel(effort.id) }))
|
||
: [];
|
||
options.push({
|
||
provider,
|
||
model: model.id,
|
||
rowId: provider + "/" + model.id,
|
||
label: model.name || model.id,
|
||
efforts,
|
||
defaultEffort: model.reasoning && model.reasoning.defaultEffort,
|
||
});
|
||
}
|
||
}
|
||
return options;
|
||
}
|
||
|
||
function findModelOption(options, current) {
|
||
if (!current || !current.provider || !current.model) return undefined;
|
||
return options.find((option) => option.provider === current.provider && option.model === current.model);
|
||
}
|
||
|
||
function modelSwitchPlan(current, next, addressesSubagent) {
|
||
if (addressesSubagent === true) {
|
||
return { ok: false, reason: "子会话不能单独更换模型;请在丞相会话中设置,或新建会话时选择" };
|
||
}
|
||
if (!next || !next.provider || !next.model) return { ok: false, reason: "未选择模型" };
|
||
const effort = next.reasoningEffort === undefined ? undefined : next.reasoningEffort;
|
||
if (current && current.provider === next.provider && current.model === next.model && (current.reasoningEffort || undefined) === effort) {
|
||
return { ok: false, reason: "与当前设置相同" };
|
||
}
|
||
const payload = { provider: next.provider, model: next.model };
|
||
if (effort !== undefined) payload.reasoningEffort = effort;
|
||
return { ok: true, payload };
|
||
}
|
||
|
||
function decreeText(role, text, team) {
|
||
const body = String(text === undefined || text === null ? "" : text).trim();
|
||
if (body === "") return "";
|
||
const active = (Array.isArray(team && team.tasks) ? team.tasks : [])
|
||
.filter((task) => task && task.status === "in_progress")
|
||
.map((task) => task.subject || task.title || task.id)
|
||
.filter(Boolean);
|
||
const context = active.length > 0 ? "\n(当前在办:" + active.join(";") + ")" : "";
|
||
return "【丞相下旨 · " + roleLabel(role) + "】\n" + body + context;
|
||
}
|
||
|
||
/** 从 TextBlock 数组里拼出纯文本(Chat 的 content/root 结构在不同节点上略有差异)。 */
|
||
function textOfBlocks(blocks) {
|
||
if (!Array.isArray(blocks)) return "";
|
||
return blocks
|
||
.filter((block) => block && (block.kind === "text" || block.type === "text"))
|
||
.map((block) => block.text)
|
||
.filter((text) => typeof text === "string")
|
||
.join("\n")
|
||
.trim();
|
||
}
|
||
|
||
/** 按 anchorSeq 排序后取最近一条用户输入与最近一条助手文本。 */
|
||
function lastExchange(nodes) {
|
||
const list = (Array.isArray(nodes) ? nodes : []).filter(Boolean);
|
||
const ordered = list.slice().sort((left, right) => {
|
||
const a = Number(left.anchorSeq ?? 0);
|
||
const b = Number(right.anchorSeq ?? 0);
|
||
return a === b ? 0 : a < b ? -1 : 1;
|
||
});
|
||
let lastUser = "";
|
||
let lastAssistant = "";
|
||
for (const node of ordered) {
|
||
const data = node.data || {};
|
||
if (node.kind === "user") {
|
||
const text = textOfBlocks(data.content);
|
||
if (text !== "") lastUser = shortText(text, 180);
|
||
} else if (node.kind === "assistant" || node.kind === "assistant-step") {
|
||
const text = textOfBlocks(data.blocks) || textOfBlocks(data.root && data.root.blocks) || (typeof data.root === "string" ? data.root : "");
|
||
if (text !== "") lastAssistant = shortText(text, 220);
|
||
}
|
||
}
|
||
return { lastUser, lastAssistant };
|
||
}
|
||
// #endregion
|
||
|
||
/** 由 apply() 建立,向 main 槽条目传递 uiWorkspace(root 槽拿不到会话级服务)。 */
|
||
let WorkspaceContext = null;
|
||
|
||
// #region 样式
|
||
const css = `
|
||
.sl-toggle{appearance:none;border:0;background:0 0;color:var(--dsw-alias-label-tertiary,#8a8f98);font:inherit;font-size:12px;display:inline-flex;align-items:center;gap:6px;padding:3px 7px;border-radius:6px;cursor:pointer;min-height:28px}
|
||
.sl-toggle:hover,.sl-toggle:focus-visible{color:var(--dsw-alias-label-primary,#1f2329);background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.08))}
|
||
.sl-toggle.active{color:var(--dsw-alias-label-primary,#1f2329);background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.12))}
|
||
.sl-toggle-mark{font-size:10px;letter-spacing:.06em;padding:1px 4px;border-radius:4px;border:1px solid currentColor;opacity:.8}
|
||
.sl-toggle-wrap{display:inline-flex;align-items:center;gap:6px;min-width:0}
|
||
.sl-toggle-notice{max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px;line-height:16px;color:var(--dsw-alias-state-error-primary,#dc2626)}
|
||
.sl-root{display:flex;flex-direction:column;height:100%;min-height:0;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#1f2329);font-size:13px;line-height:20px}
|
||
.sl-crash{display:flex;flex-direction:column;gap:8px;margin:24px;padding:18px 20px;border:1px solid #e5484d;border-radius:10px;background:#fff5f5;color:#8b1a1d;font-size:13px;line-height:20px;white-space:normal}
|
||
.sl-crash strong{font-size:14px}
|
||
.sl-crash pre{margin:0;padding:10px 12px;border-radius:6px;background:rgba(127,127,127,.08);font-size:12px;line-height:18px;white-space:pre-wrap;word-break:break-all;overflow:auto;max-height:240px}
|
||
.sl-crash p{margin:0;color:var(--dsw-alias-label-tertiary,#8a8f98);font-size:12px}
|
||
.sl-btn{appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.24));background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.06));color:inherit;font:inherit;font-size:12px;padding:3px 10px;border-radius:7px;cursor:pointer}
|
||
.sl-btn:hover{background:var(--dsw-alias-bg-layer-3,rgba(127,127,127,.12))}
|
||
.sl-btn[disabled]{opacity:.5;cursor:default}
|
||
.sl-btn.primary{background:var(--dsw-alias-state-business-primary,#3b82f6);border-color:transparent;color:#fff}
|
||
.sl-body{flex:1;min-height:0;display:flex}
|
||
.sl-right{width:392px;min-width:300px;max-width:46%;display:flex;flex-direction:column;min-height:0;overflow-y:auto}
|
||
@media (max-width:980px){.sl-body{flex-direction:column}.sl-right{width:auto;max-width:none;border-top:1px solid var(--dsw-alias-border-l1,rgba(127,127,127,.14))}}
|
||
.sl-map{padding:12px 16px 16px;flex:none}
|
||
.sl-stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:8px;padding:14px 16px 0;flex:none}
|
||
.sl-stat{display:flex;align-items:center;gap:7px;padding:8px 9px;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.2));border-radius:10px;background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.05));min-width:0}
|
||
.sl-stat-mark{flex:none;width:20px;height:20px;border-radius:6px;display:inline-flex;align-items:center;justify-content:center;font-size:11px;font-weight:600;background:var(--dsw-alias-bg-layer-3,rgba(127,127,127,.14));color:var(--dsw-alias-label-secondary,#5b616b)}
|
||
.sl-stat-running .sl-stat-mark{background:color-mix(in srgb,#22c55e 18%,transparent);color:#16a34a}
|
||
.sl-stat-done .sl-stat-mark{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#3b82f6) 16%,transparent);color:var(--dsw-alias-state-business-primary,#3b82f6)}
|
||
.sl-stat-body{display:flex;flex-direction:column;min-width:0;line-height:1.15}
|
||
.sl-stat-body b{font-size:17px;font-weight:600;font-variant-numeric:tabular-nums;letter-spacing:.01em}
|
||
.sl-stat-body small{font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8f98);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||
@media (max-width:980px){.sl-stats{padding:12px 14px 0}}
|
||
.sl-node{position:relative;display:flex;flex-direction:column;gap:2px;padding:8px 9px;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.2));border-radius:10px;background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.05));cursor:pointer;text-align:left;color:inherit;font:inherit;min-width:0;transition:border-color .12s,box-shadow .12s,transform .12s}
|
||
.sl-node:hover{transform:translateY(-1px);border-color:var(--dsw-alias-border-l3,rgba(127,127,127,.4))}
|
||
.sl-node[aria-selected="true"]{border-color:color-mix(in srgb,var(--dsw-alias-state-business-primary,#3b82f6) 55%,transparent);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dsw-alias-state-business-primary,#3b82f6) 28%,transparent)}
|
||
.sl-node.is-absent{opacity:.62;border-style:dashed}
|
||
.sl-node-top{display:flex;align-items:center;gap:6px;min-width:0}
|
||
.sl-mark{flex:none;width:20px;height:20px;border-radius:6px;display:inline-flex;align-items:center;justify-content:center;font-size:11px;font-weight:600;background:var(--dsw-alias-bg-layer-3,rgba(127,127,127,.14));color:var(--dsw-alias-label-secondary,#5b616b)}
|
||
.sl-node[aria-selected="true"] .sl-mark{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#3b82f6) 18%,transparent);color:var(--dsw-alias-state-business-primary,#3b82f6)}
|
||
.sl-name{font-weight:600;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||
.sl-dot{width:6px;height:6px;border-radius:50%;flex:none;background:var(--dsw-alias-label-tertiary,#9ca3af)}
|
||
.sl-dot.running{background:#22c55e;box-shadow:0 0 0 2px color-mix(in srgb,#22c55e 20%,transparent)}
|
||
.sl-dot.warning{background:#f59e0b}
|
||
.sl-dot.error{background:#ef4444}
|
||
.sl-dot.absent{background:transparent;border:1px solid var(--dsw-alias-label-tertiary,#9ca3af)}
|
||
.sl-detail{flex:none;border-top:1px solid var(--dsw-alias-border-l1,rgba(127,127,127,.14));padding:12px 16px 16px;display:flex;flex-direction:column;gap:8px}
|
||
.sl-detail-head{display:flex;align-items:center;gap:8px}
|
||
.sl-detail-head strong{font-size:13px}
|
||
.sl-detail-head small{color:var(--dsw-alias-label-tertiary,#8a8f98);font-size:11px}
|
||
.sl-hint{color:var(--dsw-alias-label-tertiary,#8a8f98);font-size:11px;line-height:17px}
|
||
.sl-error{color:var(--dsw-alias-state-error-primary,#dc2626);font-size:11px;line-height:17px}
|
||
.sl-ok{color:#15803d;font-size:11px;line-height:17px}
|
||
.sl-section-title{display:flex;align-items:center;gap:8px;padding:10px 16px 4px;font-size:11px;font-weight:600;letter-spacing:.04em;color:var(--dsw-alias-label-tertiary,#8a8f98);text-transform:uppercase}
|
||
.sl-section-title span{margin-left:auto;font-weight:500;text-transform:none;letter-spacing:0}
|
||
.sl-tash{list-style:none;margin:0;padding:0 16px 10px;display:flex;flex-direction:column;gap:4px}
|
||
.sl-tash li{display:flex;align-items:center;gap:6px;font-size:11px;line-height:17px;color:var(--dsw-alias-label-secondary,#5b616b);min-width:0}
|
||
.sl-tash li b{font-weight:500;color:var(--dsw-alias-label-primary,#1f2329);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0;flex:1}
|
||
.sl-tash li em{font-style:normal;color:var(--dsw-alias-label-tertiary,#8a8f98);flex:none}
|
||
.sl-tab-title{display:flex;align-items:center;gap:6px;min-width:0}
|
||
.sl-tab-mark{width:18px;height:18px;border-radius:5px;display:inline-flex;align-items:center;justify-content:center;font-size:9px;font-weight:600;background:var(--dsw-alias-bg-layer-3,rgba(127,127,127,.14));color:var(--dsw-alias-label-secondary,#5b616b)}
|
||
|
||
/* 2026 court workspace: quiet DSH surfaces, clear hierarchy, one blue accent. */
|
||
.sl-root{--sl-accent:var(--dsw-alias-state-business-primary,#4d6bfe);--sl-card:var(--dsw-alias-bg-layer-1,#fff);--sl-page:var(--dsw-alias-bg-layer-2,#f5f6f8);--sl-line:var(--dsw-alias-border-l1,rgba(127,127,127,.14));background:var(--sl-page);font-size:13px}
|
||
.sl-section-kicker{font-size:9px;line-height:14px;letter-spacing:.13em;color:var(--dsw-alias-label-tertiary,#8a8f98);font-weight:600}
|
||
.sl-state-dot{width:6px;height:6px;border-radius:50%;background:#22c55e;box-shadow:0 0 0 3px color-mix(in srgb,#22c55e 12%,transparent)}
|
||
.sl-body{display:grid;grid-template-columns:minmax(0,1fr) 440px;gap:16px;padding:16px;overflow:hidden;background:var(--sl-page)}
|
||
.sl-right{width:auto;min-width:0;max-width:none;gap:12px;padding:0;overflow-y:auto;overflow-x:hidden;border:0}
|
||
.sl-task-panel,.sl-map,.sl-detail{background:var(--sl-card);border:1px solid var(--sl-line);border-radius:14px;box-shadow:0 1px 2px rgba(15,23,42,.025)}
|
||
.sl-btn{min-height:32px;padding:5px 13px;border-radius:8px;border-color:var(--sl-line);background:var(--sl-card);font-weight:500}
|
||
.sl-btn.primary{background:var(--sl-accent);box-shadow:0 3px 8px color-mix(in srgb,var(--sl-accent) 16%,transparent)}
|
||
.sl-btn.primary:hover{background:color-mix(in srgb,var(--sl-accent) 88%,#172554)}
|
||
.sl-task-panel{flex:1;min-height:180px;padding:16px 18px}
|
||
.sl-section-title{padding:0 0 12px;gap:12px}
|
||
.sl-section-heading{display:flex;flex-direction:column}
|
||
.sl-section-heading h2,.sl-map-head h2{margin:0;font-size:14px;line-height:20px;font-weight:600}
|
||
.sl-section-title .sl-section-count{margin-left:auto;padding:3px 8px;border-radius:6px;background:var(--sl-page);font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-tash{padding:0;gap:6px}
|
||
.sl-tash li{padding:10px 11px;border:1px solid transparent;border-radius:9px;background:var(--sl-page);gap:10px}
|
||
.sl-tash li:hover{border-color:color-mix(in srgb,var(--sl-accent) 20%,transparent)}
|
||
.sl-task-state{width:18px;display:flex;justify-content:center;flex:none}
|
||
.sl-task-copy{display:flex;flex-direction:column;min-width:0;flex:1}
|
||
.sl-task-copy small{font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-tash li .sl-task-owner{padding:2px 7px;border-radius:5px;background:var(--sl-card);color:var(--dsw-alias-label-secondary,#5b616b);font-size:10px}
|
||
.sl-task-empty{min-height:108px;display:flex;align-items:center;justify-content:center;gap:12px;border:1px dashed var(--sl-line);border-radius:10px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-empty-mark{width:30px;height:30px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;background:color-mix(in srgb,#22c55e 9%,transparent);color:#16a34a}
|
||
.sl-task-empty strong{font-size:12px;font-weight:500;color:var(--dsw-alias-label-secondary,#5b616b)}
|
||
.sl-task-empty p{margin:2px 0 0;font-size:10px}
|
||
.sl-stats{grid-template-columns:repeat(4,minmax(0,1fr));gap:8px;padding:0}
|
||
.sl-stat{position:relative;display:block;padding:12px 11px 11px;border-radius:12px;background:var(--sl-card);border-color:var(--sl-line);box-shadow:0 1px 2px rgba(15,23,42,.025)}
|
||
.sl-stat-mark{position:absolute;right:9px;top:9px;width:20px;height:20px;background:var(--sl-page);font-size:10px}
|
||
.sl-stat-body{gap:1px}
|
||
.sl-stat-body b{font-size:22px;line-height:27px;letter-spacing:-.02em}
|
||
.sl-stat-body small{font-size:10px}
|
||
.sl-stat-members .sl-stat-mark{background:color-mix(in srgb,var(--sl-accent) 10%,transparent);color:var(--sl-accent)}
|
||
.sl-stat-pending .sl-stat-mark{background:color-mix(in srgb,#f59e0b 12%,transparent);color:#d97706}
|
||
.sl-map{padding:14px;border-radius:14px}
|
||
.sl-map-head{display:flex;align-items:flex-end;justify-content:space-between;gap:10px;margin-bottom:12px}
|
||
.sl-map-head>span{font-size:9px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-tier-label{display:flex;align-items:center;justify-content:space-between;margin:0 1px 6px;font-size:9px;line-height:14px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-tier-label small{font-size:9px}
|
||
.sl-node:focus-visible{outline:2px solid color-mix(in srgb,var(--sl-accent) 65%,transparent);outline-offset:2px}
|
||
.sl-node{border-color:var(--sl-line);border-radius:10px;background:var(--sl-card);box-shadow:none;transition:border-color .15s,box-shadow .15s,transform .15s,background .15s}
|
||
.sl-node:hover{transform:translateY(-1px);border-color:color-mix(in srgb,var(--sl-accent) 35%,transparent);box-shadow:0 4px 12px rgba(15,23,42,.05)}
|
||
.sl-node[aria-selected="true"]{border-color:color-mix(in srgb,var(--sl-accent) 55%,transparent);background:color-mix(in srgb,var(--sl-accent) 4%,var(--sl-card));box-shadow:0 0 0 2px color-mix(in srgb,var(--sl-accent) 9%,transparent)}
|
||
.sl-node.is-absent{opacity:.55;background:var(--sl-page)}
|
||
.sl-node-top{gap:6px}
|
||
.sl-mark{background:var(--sl-page);color:var(--dsw-alias-label-secondary,#5b616b)}
|
||
.sl-node[aria-selected="true"] .sl-mark{background:color-mix(in srgb,var(--sl-accent) 12%,transparent);color:var(--sl-accent)}
|
||
.sl-name{font-size:11px}
|
||
.sl-detail{border:1px solid var(--sl-line);border-radius:14px;padding:15px;gap:11px;margin-bottom:2px}
|
||
.sl-detail-head{gap:10px;padding-bottom:10px;border-bottom:1px solid var(--sl-line)}
|
||
.sl-detail-mark{width:34px;height:34px;border-radius:10px;display:inline-flex;align-items:center;justify-content:center;background:color-mix(in srgb,var(--sl-accent) 10%,transparent);color:var(--sl-accent);font-size:14px;font-weight:650;flex:none}
|
||
.sl-detail-title{display:flex;flex-direction:column;min-width:0}
|
||
.sl-detail-head strong{font-size:13px;line-height:19px}
|
||
.sl-detail-head small{font-size:10px;line-height:15px}
|
||
.sl-detail-head .sl-btn{font-size:10px;min-height:28px;padding:3px 8px}
|
||
.sl-hint{font-size:10px;line-height:16px}
|
||
.sl-root ::-webkit-scrollbar{width:6px;height:6px}
|
||
.sl-root ::-webkit-scrollbar-thumb{background:var(--dsw-alias-border-l3,rgba(127,127,127,.3));border-radius:10px}
|
||
.sl-root ::-webkit-scrollbar-track{background:transparent}
|
||
@media (max-width:1180px){.sl-body{grid-template-columns:minmax(0,1fr) 400px;gap:12px;padding:12px}}
|
||
@media (max-width:980px){.sl-body{display:flex;flex-direction:column;overflow-y:auto}.sl-right{width:auto;max-width:none;overflow:visible;border:0}.sl-task-panel{min-height:150px}.sl-stats{padding:0}.sl-detail{margin-bottom:0}}
|
||
@media (max-width:620px){.sl-body{padding:9px;gap:10px}.sl-task-panel,.sl-map,.sl-detail{border-radius:11px}.sl-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.sl-map-head>span{display:none}}
|
||
|
||
.sl-compact{padding:0}
|
||
.sl-compact .sl-body{display:flex;flex-direction:column;padding:0;gap:0;overflow:hidden}
|
||
.sl-compact .sl-right{width:auto;max-width:none;min-width:0;border-top:0;flex:1;overflow-y:auto}
|
||
.sl-compact .sl-stats{grid-template-columns:repeat(2,minmax(0,1fr))}
|
||
|
||
/* 2026-11 redesign: department cards are the primary surface. */
|
||
.sl-root{--sl-node-border:color-mix(in srgb,var(--sl-accent) 17%,var(--sl-line));--sl-soft-accent:color-mix(in srgb,var(--sl-accent) 7%,var(--sl-card))}
|
||
.sl-stats{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
|
||
.sl-stat{display:flex;align-items:center;gap:8px;min-height:68px;padding:11px 12px}
|
||
.sl-stat-mark{position:static;inset:auto;margin-left:auto;width:26px;height:26px;border-radius:8px;font-size:11px}
|
||
.sl-stat-body b{font-size:24px;line-height:29px}
|
||
.sl-stat-body small{font-size:10px;line-height:15px}
|
||
.sl-map{padding:15px 14px 14px}
|
||
.sl-map-head{align-items:center;margin-bottom:8px}
|
||
.sl-map-head .sl-section-kicker{display:block;margin-bottom:1px}
|
||
.sl-map-head>span{white-space:nowrap}
|
||
.sl-tier{margin-top:8px}
|
||
.sl-grid{display:grid;gap:10px;min-width:0}
|
||
.sl-grid-1{grid-template-columns:minmax(0,1fr)}
|
||
.sl-grid-1 .sl-node{width:min(232px,100%);margin:0 auto}
|
||
.sl-grid-3,.sl-grid-6{grid-template-columns:repeat(3,minmax(0,1fr))}
|
||
.sl-connector-tri{position:relative;height:19px;margin:0 4px}
|
||
.sl-connector-tri:before{content:"";position:absolute;left:16.667%;right:16.667%;top:7px;height:1px;background:color-mix(in srgb,var(--sl-accent) 22%,var(--sl-line))}
|
||
.sl-connector-tri:after{content:"";position:absolute;left:50%;top:0;width:1px;height:8px;background:color-mix(in srgb,var(--sl-accent) 22%,var(--sl-line))}
|
||
.sl-connector-tri span{position:absolute;top:7px;bottom:0;width:1px;background:color-mix(in srgb,var(--sl-accent) 22%,var(--sl-line))}
|
||
.sl-connector-tri span:nth-child(1){left:16.667%}
|
||
.sl-connector-tri span:nth-child(2){left:50%}
|
||
.sl-connector-tri span:nth-child(3){left:83.333%}
|
||
.sl-stem{width:1px;height:15px;margin:0 auto;background:color-mix(in srgb,var(--sl-accent) 22%,var(--sl-line))}
|
||
.sl-ministry-group{margin-top:0;padding:10px;border:1px solid color-mix(in srgb,var(--sl-accent) 11%,var(--sl-line));border-radius:14px;background:color-mix(in srgb,var(--sl-accent) 3%,var(--sl-page))}
|
||
.sl-group-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;margin:0 2px 9px}
|
||
.sl-group-title{display:block;font-size:11px;line-height:16px;font-weight:600;color:var(--dsw-alias-label-primary,#1f2329)}
|
||
.sl-group-head small{display:block;margin-top:1px;font-size:9px;line-height:14px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-group-count{flex:none;padding:2px 7px;border-radius:5px;background:var(--sl-card);border:1px solid var(--sl-line);font-size:9px;line-height:14px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-ministry-group .sl-node{background:var(--sl-card)}
|
||
.sl-node{min-height:80px;align-items:stretch;justify-content:center;gap:7px;padding:11px 11px 10px;border:1px solid var(--sl-node-border);border-radius:12px;background:var(--sl-card);box-shadow:0 1px 2px rgba(15,23,42,.035)}
|
||
.sl-node:hover{transform:translateY(-1px);border-color:color-mix(in srgb,var(--sl-accent) 42%,var(--sl-line));box-shadow:0 6px 18px rgba(15,23,42,.07)}
|
||
.sl-node:focus-visible{outline:2px solid color-mix(in srgb,var(--sl-accent) 68%,transparent);outline-offset:2px}
|
||
.sl-node[aria-pressed="true"],.sl-node.is-selected{border-color:var(--sl-accent);background:var(--sl-soft-accent);box-shadow:inset 0 0 0 1px var(--sl-accent),0 6px 18px color-mix(in srgb,var(--sl-accent) 12%,transparent)}
|
||
.sl-node.is-absent{border-style:dashed;background:var(--sl-page);opacity:.64}
|
||
.sl-node.status-failed{border-color:color-mix(in srgb,#ef4444 38%,var(--sl-line))}
|
||
.sl-node-check{position:absolute;right:7px;top:7px;width:17px;height:17px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;background:var(--sl-accent);color:#fff;font-size:10px;line-height:17px;font-weight:700}
|
||
.sl-node-top{gap:7px;padding-right:12px}
|
||
.sl-mark{flex:none;width:28px;height:28px;border-radius:8px;background:color-mix(in srgb,var(--sl-accent) 8%,var(--sl-page));color:color-mix(in srgb,var(--sl-accent) 76%,#1f2329);font-size:12px;font-weight:650}
|
||
.sl-node[aria-pressed="true"] .sl-mark{background:var(--sl-accent);color:#fff}
|
||
.sl-name{font-size:13px;line-height:19px;font-weight:650;letter-spacing:.01em}
|
||
.sl-node-status{display:flex;align-items:center;gap:5px;min-width:0;padding-left:35px;font-size:10px;line-height:15px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-detail{padding:15px;gap:12px}
|
||
.sl-detail-head{padding-bottom:11px}
|
||
.sl-detail-title{flex:1}
|
||
.sl-detail-head strong{font-size:15px;line-height:21px}
|
||
.sl-detail-title small{display:block;margin-top:1px;line-height:15px}
|
||
.sl-detail-chip{flex:none;padding:2px 7px;border-radius:5px;background:var(--sl-page);border:1px solid var(--sl-line);font-size:9px;line-height:14px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-detail-status{display:flex;align-items:center;gap:6px;min-width:0;padding:0 1px;font-size:10px;line-height:16px;color:var(--dsw-alias-label-secondary,#5b616b)}
|
||
.sl-detail-status small{margin-left:auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-setting-block{display:flex;flex-direction:column;gap:9px;padding:11px;border:1px solid var(--sl-line);border-radius:11px;background:var(--sl-page)}
|
||
.sl-setting-head{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
||
.sl-setting-head h3{margin:0;font-size:12px;line-height:18px;font-weight:600}
|
||
.sl-setting-head small{font-size:9px;line-height:14px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-model-grid{display:grid;grid-template-columns:minmax(0,1fr) 104px;gap:8px}
|
||
.sl-control{display:flex;flex-direction:column;gap:5px;min-width:0}
|
||
.sl-control>span{font-size:9px;line-height:14px;font-weight:500;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-control select{width:100%;min-width:0;min-height:34px;padding:6px 8px;border:1px solid var(--sl-line);border-radius:8px;background:var(--sl-card);color:inherit;font:inherit;font-size:11px;outline:none}
|
||
.sl-control select:focus-visible{border-color:color-mix(in srgb,var(--sl-accent) 55%,transparent);box-shadow:0 0 0 2px color-mix(in srgb,var(--sl-accent) 8%,transparent)}
|
||
.sl-control select:disabled{opacity:.58}
|
||
.sl-model-foot{display:flex;align-items:center;gap:8px;min-width:0}
|
||
.sl-model-foot .sl-btn{flex:none;min-height:30px;font-size:10px;padding:4px 9px}
|
||
.sl-model-foot small{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:9px;line-height:14px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-model-foot small.is-dirty{color:#b45309}
|
||
.sl-link-button{appearance:none;align-self:flex-start;border:0;background:none;padding:0;color:var(--sl-accent);font:inherit;font-size:10px;line-height:16px;cursor:pointer}
|
||
.sl-conversation-block{display:flex;flex-direction:column;gap:7px}
|
||
.sl-conversation-action{width:100%;min-height:40px;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 13px;border:1px solid transparent;border-radius:10px;background:var(--sl-accent);color:#fff;font:inherit;font-size:12px;line-height:18px;font-weight:600;cursor:pointer;box-shadow:0 4px 12px color-mix(in srgb,var(--sl-accent) 18%,transparent)}
|
||
.sl-conversation-action:hover{background:color-mix(in srgb,var(--sl-accent) 88%,#172554)}
|
||
.sl-conversation-action:focus-visible{outline:2px solid color-mix(in srgb,var(--sl-accent) 60%,transparent);outline-offset:2px}
|
||
.sl-conversation-action:disabled{background:var(--sl-page);color:var(--dsw-alias-label-tertiary,#8a8f98);border-color:var(--sl-line);box-shadow:none;cursor:default}
|
||
.sl-conversation-arrow{font-size:13px;opacity:.82}
|
||
.sl-conversation-hint{margin:0;font-size:10px;line-height:16px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-advanced{border-top:1px solid var(--sl-line);padding-top:9px}
|
||
.sl-advanced summary{display:flex;align-items:center;justify-content:space-between;list-style:none;cursor:pointer;font-size:10px;line-height:16px;font-weight:500;color:var(--dsw-alias-label-secondary,#5b616b)}
|
||
.sl-advanced summary::-webkit-details-marker{display:none}
|
||
.sl-advanced summary:after{content:"+";font-size:12px;line-height:16px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-advanced[open] summary:after{content:"−"}
|
||
.sl-advanced-list{margin:8px 0 0;display:grid;gap:5px;font-size:9px;line-height:15px}
|
||
.sl-advanced-list div{display:flex;gap:8px;min-width:0}
|
||
.sl-advanced-list dt{flex:none;width:58px;color:var(--dsw-alias-label-tertiary,#8a8f98)}
|
||
.sl-advanced-list dd{margin:0;min-width:0;word-break:break-all;color:var(--dsw-alias-label-secondary,#5b616b)}
|
||
@media (max-width:1180px){.sl-grid-6{gap:8px}.sl-node{min-height:76px;padding:10px}}
|
||
@media (max-width:980px){.sl-grid-3,.sl-grid-6{grid-template-columns:repeat(3,minmax(0,1fr))}}
|
||
@media (max-width:620px){.sl-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.sl-grid-3,.sl-grid-6{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}.sl-connector-tri,.sl-stem{display:none}.sl-grid-1 .sl-node{width:100%}.sl-map{padding:13px 11px}.sl-detail{padding:13px}.sl-model-grid{grid-template-columns:minmax(0,1fr) 94px}}
|
||
@media (max-width:420px){.sl-grid-3,.sl-grid-6{grid-template-columns:1fr}}
|
||
.sl-compact .sl-stats{grid-template-columns:repeat(2,minmax(0,1fr))}
|
||
.sl-compact .sl-grid-3,.sl-compact .sl-grid-6{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
|
||
.sl-compact .sl-connector-tri,.sl-compact .sl-stem{display:none}
|
||
.sl-compact .sl-grid-1 .sl-node{width:100%}
|
||
button.sl-stat{appearance:none;width:100%;border:1px solid var(--sl-line);color:inherit;font:inherit;text-align:left;cursor:pointer}
|
||
.sl-stat-pending:hover{border-color:color-mix(in srgb,var(--sl-accent) 34%,var(--sl-line));background:color-mix(in srgb,var(--sl-accent) 3%,var(--sl-card))}
|
||
.sl-stat-pending:focus-visible{outline:2px solid color-mix(in srgb,var(--sl-accent) 60%,transparent);outline-offset:2px}
|
||
button.sl-stat-members:hover{border-color:color-mix(in srgb,var(--sl-accent) 34%,var(--sl-line));background:color-mix(in srgb,var(--sl-accent) 3%,var(--sl-card))}
|
||
button.sl-stat-members:focus-visible{outline:2px solid color-mix(in srgb,var(--sl-accent) 60%,transparent);outline-offset:2px}
|
||
.sl-body.is-court{grid-template-columns:minmax(0,1fr)}
|
||
.sl-body.is-court .sl-right{width:100%;max-width:1100px;margin:0 auto}
|
||
.sl-body.is-court .sl-stats{display:none}
|
||
.sl-body.is-court .sl-map{padding:20px 18px 18px}
|
||
.sl-body.is-court .sl-detail{padding:18px}
|
||
.sl-map-meta{display:flex;align-items:center;gap:9px;flex:none}
|
||
.sl-map-meta>span{font-size:9px;line-height:14px;color:var(--dsw-alias-label-tertiary,#8a8f98);white-space:nowrap}
|
||
@media (max-width:980px){.sl-body.is-court .sl-right{max-width:none}.sl-body.is-court .sl-map{padding:15px 13px}}
|
||
|
||
/* 右侧栏形态:聊天留给 DSH 原生会话,面板只承载朝堂与任务。 */
|
||
.sl-sidebar{background:transparent}
|
||
.sl-side-meta{display:flex;align-items:center;gap:7px;flex:none;min-width:0;padding:11px 3px 8px}
|
||
.sl-side-state{display:inline-flex;align-items:center;gap:6px;flex:none;padding:2px 7px;border:1px solid var(--sl-line);border-radius:999px;background:var(--sl-card);font-size:10px;line-height:15px;color:var(--dsw-alias-label-tertiary,#8a8f98);white-space:nowrap}
|
||
.sl-side-state.is-child{color:var(--sl-accent);border-color:color-mix(in srgb,var(--sl-accent) 22%,transparent);background:color-mix(in srgb,var(--sl-accent) 7%,transparent)}
|
||
.sl-side-state .sl-state-dot{width:6px;height:6px;border-radius:50%;background:#21a36a;box-shadow:0 0 0 3px color-mix(in srgb,#21a36a 12%,transparent)}
|
||
.sl-side-state.is-child .sl-state-dot{background:var(--sl-accent);box-shadow:0 0 0 3px color-mix(in srgb,var(--sl-accent) 12%,transparent)}
|
||
.sl-side-hint{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:right;font-size:9px;line-height:14px;color:var(--dsw-alias-label-caption,#9aa0a6)}
|
||
.sl-side-return{appearance:none;flex:none;padding:3px 7px;border:1px solid var(--sl-line);border-radius:6px;background:var(--sl-card);color:var(--sl-accent);font:inherit;font-size:9px;line-height:14px;cursor:pointer}
|
||
.sl-side-return:hover{background:color-mix(in srgb,var(--sl-accent) 7%,var(--sl-card))}
|
||
.sl-side-return:focus-visible{outline:2px solid color-mix(in srgb,var(--sl-accent) 55%,transparent);outline-offset:1px}
|
||
.sl-body-sidebar{display:flex;min-height:0;padding:0 2px 10px;overflow:hidden;background:transparent}
|
||
.sl-body-sidebar .sl-right{flex:1;width:auto;min-width:0;max-width:none;gap:10px;padding:0 1px 0 0;overflow-y:auto;overflow-x:hidden}
|
||
.sl-side-tabs{position:sticky;top:0;z-index:5;display:flex;align-items:center;gap:3px;flex:none;padding:3px;border:1px solid var(--sl-line);border-radius:10px;background:color-mix(in srgb,var(--sl-card) 94%,transparent);box-shadow:0 2px 8px rgba(15,23,42,.04);backdrop-filter:blur(8px)}
|
||
.sl-side-tab{appearance:none;flex:1;display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:30px;padding:4px 10px;border:0;border-radius:7px;background:transparent;color:var(--dsw-alias-label-secondary,#5b616b);font:inherit;font-size:11px;line-height:16px;font-weight:500;cursor:pointer}
|
||
.sl-side-tab:hover{background:var(--sl-page);color:var(--dsw-alias-label-primary,#1f2329)}
|
||
.sl-side-tab.is-active{background:var(--sl-soft-accent,color-mix(in srgb,var(--sl-accent) 9%,var(--sl-card)));color:var(--sl-accent);font-weight:600;box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--sl-accent) 16%,transparent)}
|
||
.sl-side-tab:focus-visible{outline:2px solid color-mix(in srgb,var(--sl-accent) 60%,transparent);outline-offset:1px}
|
||
.sl-side-tab-count{min-width:17px;padding:0 5px;border-radius:5px;background:color-mix(in srgb,var(--sl-accent) 9%,var(--sl-page));color:var(--sl-accent);font-size:9px;line-height:15px;text-align:center;font-variant-numeric:tabular-nums}
|
||
.sl-sidebar .sl-stats{grid-template-columns:repeat(2,minmax(0,1fr));padding:0;gap:8px}
|
||
.sl-sidebar .sl-stat{padding:9px 10px;border-radius:11px;background:var(--sl-card);box-shadow:0 1px 2px rgba(15,23,42,.02)}
|
||
.sl-sidebar .sl-stat-body b{font-size:18px}
|
||
.sl-side-court{display:flex;flex-direction:column;gap:10px;min-width:0}
|
||
.sl-sidebar .sl-map{padding:14px 13px 15px;border-radius:14px}
|
||
.sl-sidebar .sl-detail{padding:14px;border-radius:14px;gap:10px}
|
||
.sl-sidebar .sl-conversation-action{min-height:36px}
|
||
.sl-side-tasks{flex:none;min-height:0;padding:15px 14px;border-radius:14px}
|
||
.sl-sidebar .sl-task-panel .sl-section-title{padding-bottom:10px}
|
||
@media (max-width:420px){.sl-sidebar .sl-map{padding:12px 10px}.sl-sidebar .sl-detail{padding:12px}.sl-side-tabs{position:static}}
|
||
`;
|
||
const cssId = "dsh-sansheng-liubu-panel/panel.css";
|
||
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(cssId) + "]") === null) {
|
||
const tag = document.createElement("style");
|
||
tag.dataset.plugin = "dsh-sansheng-liubu-panel";
|
||
tag.dataset.pluginCss = cssId;
|
||
tag.textContent = css;
|
||
document.head.appendChild(tag);
|
||
}
|
||
// #endregion
|
||
|
||
// #region 小部件
|
||
function Dot(props) {
|
||
const status = props.status || "inactive";
|
||
const tone = status === "running" ? "running" : status === "failed" ? "error" : status === "provisioning" ? "warning" : status === "absent" ? "absent" : "";
|
||
return h("span", { className: "sl-dot" + (tone ? " " + tone : ""), "aria-hidden": "true" });
|
||
}
|
||
|
||
function SeatCard(props) {
|
||
const { seat, selected, onSelect, status } = props;
|
||
const cls = ["sl-node", "status-" + status];
|
||
if (!seat.present) cls.push("is-absent");
|
||
if (selected) cls.push("is-selected");
|
||
return h("button", {
|
||
type: "button",
|
||
className: cls.join(" "),
|
||
"aria-pressed": selected ? "true" : "false",
|
||
"aria-label": seat.label + "," + (STATUS_LABELS[status] || status),
|
||
"data-role": seat.role,
|
||
title: seat.duty,
|
||
onClick: () => onSelect(seat.role),
|
||
children: [
|
||
selected ? h("span", { className: "sl-node-check", "aria-hidden": "true", children: "✓" }) : null,
|
||
h("span", { className: "sl-node-top" }, [
|
||
h("span", { className: "sl-mark", "aria-hidden": "true", children: seat.mark }),
|
||
h("span", { className: "sl-name", children: seat.label }),
|
||
]),
|
||
h("span", { className: "sl-node-status" }, [
|
||
h(Dot, { status }),
|
||
h("span", { children: STATUS_LABELS[status] || status }),
|
||
]),
|
||
],
|
||
});
|
||
}
|
||
// #endregion
|
||
|
||
// #region 主面板
|
||
function SanshengPanel(props) {
|
||
const host = props.host;
|
||
const tabSessionId = props.sessionId;
|
||
const compact = props.compact === true;
|
||
// 直接订阅宿主服务层 store,不调用 slot 注入的会话级 hook(root 级 main 槽下不可用)。
|
||
const sessions = useStoreSnapshot(host.sessionsStore, EMPTY_SESSIONS) || EMPTY_SESSIONS;
|
||
const statuses = useStoreSnapshot(host.statusStore, undefined);
|
||
const activePanelId = useStoreSnapshot(host.panelStore, {}).activePanelId;
|
||
const projections = sessions.projectionsBySession || {};
|
||
|
||
// main 面板是 root 级槽:拿不到会话级 props,用户正在看哪个会话只能从
|
||
// uiWorkspace 的选中记录(持久化在 dsh.sessions.current)读。
|
||
const selection = useWorkspaceSelection();
|
||
const pickedId = host.getSelectedSession ? host.getSelectedSession() : undefined;
|
||
const focusedSessionId = tabSessionId || pickedId || selection.sessionId;
|
||
const activeAddress = selection.subagentAddress || (focusedSessionId ? subagentAddressOf(sessions, focusedSessionId) : undefined);
|
||
const leadSessionId = (activeAddress && activeAddress.parentSessionId) || focusedSessionId;
|
||
const team = leadSessionId && projections[leadSessionId]
|
||
? projections[leadSessionId].values.agentTeam
|
||
: undefined;
|
||
const seats = React.useMemo(() => arrangeRoster(team), [team]);
|
||
const buckets = React.useMemo(() => bucketsOf(team && team.tasks), [team]);
|
||
|
||
const [selectedRole, setSelectedRole] = React.useState("lead");
|
||
const [sidebarView, setSidebarView] = React.useState("court");
|
||
const seat = seats.find((entry) => entry.role === selectedRole) || seats[0];
|
||
|
||
const runningOf = (id) => {
|
||
if (!id) return undefined;
|
||
const fromStatus = statuses && typeof statuses.get === "function" ? statuses.get(id) : undefined;
|
||
if (fromStatus && typeof fromStatus.running === "boolean") return fromStatus.running;
|
||
const fromList = sessions.byId[id];
|
||
return fromList ? fromList.running : undefined;
|
||
};
|
||
|
||
const seatState = (entry) => {
|
||
const status = memberStatus(entry.member, runningOf(entry.id), undefined);
|
||
const owned = tasksOfRole(team, entry.role);
|
||
const ownBuckets = bucketsOf(owned);
|
||
const running = status === "running";
|
||
const recent = entry.id ? host.recentText(entry.id) : "";
|
||
const model = entry.id ? host.memberModel(entry.id) : "";
|
||
const lastText = recent ? recent : (owned.length > 0 ? owned[owned.length - 1].subject || "" : "");
|
||
return {
|
||
status,
|
||
counts: {
|
||
runningCount: ownBuckets.in_progress.length,
|
||
pendingCount: ownBuckets.pending.length,
|
||
completedCount: ownBuckets.completed.length,
|
||
},
|
||
lastText: shortText(lastText, 40),
|
||
model,
|
||
running,
|
||
};
|
||
};
|
||
|
||
const stats = React.useMemo(
|
||
() => courtStats(seats, buckets, (entry) => memberStatus(entry.member, runningOf(entry.id), undefined) === "running"),
|
||
[seats, buckets, sessions, statuses],
|
||
);
|
||
|
||
const openTaskCount = buckets.in_progress.length + buckets.pending.length;
|
||
const showTasks = () => setSidebarView("tasks");
|
||
const showCourt = () => setSidebarView("court");
|
||
const seatInfo = seat ? seatState(seat) : { status: "absent", counts: {}, lastText: "", model: "" };
|
||
|
||
// —— 图下配置区 ——
|
||
const [catalog, setCatalog] = React.useState({ status: "idle", options: [], error: null, current: undefined, subagent: false });
|
||
const [draftModel, setDraftModel] = React.useState("");
|
||
const [draftEffort, setDraftEffort] = React.useState("");
|
||
const [notice, setNotice] = React.useState(null);
|
||
const [busy, setBusy] = React.useState(false);
|
||
const [catalogRetry, setCatalogRetry] = React.useState(0);
|
||
|
||
const targetId = seat && seat.id ? seat.id : seat && seat.role === "lead" ? leadSessionId : undefined;
|
||
|
||
React.useEffect(() => {
|
||
if (catalog.status === "loading") return undefined;
|
||
if (!targetId) { setCatalog({ status: "idle", options: [], error: null, current: undefined, subagent: false }); return undefined; }
|
||
let alive = true;
|
||
setCatalog((prev) => ({ ...prev, status: "loading", error: null }));
|
||
host.loadCatalog(targetId).then((result) => {
|
||
if (!alive) return;
|
||
setCatalog({ status: "ready", options: result.options, current: result.current, error: result.error, subagent: result.subagent });
|
||
setDraftModel(result.current ? result.current.provider + "/" + result.current.model : "");
|
||
setDraftEffort((result.current && result.current.reasoningEffort) || "");
|
||
}, (error) => {
|
||
if (alive) setCatalog({ status: "error", options: [], error: String(error && error.message || error), current: undefined, subagent: false });
|
||
});
|
||
return () => { alive = false; };
|
||
}, [targetId, catalogRetry]);
|
||
|
||
const presetForSeat = seat && seat.id && sessions.byId[seat.id] && sessions.byId[seat.id].projectionValues
|
||
? sessions.byId[seat.id].projectionValues.agentPreset
|
||
: undefined;
|
||
|
||
const chosenOption = catalog.options.find((option) => option.rowId === draftModel);
|
||
const currentModelValue = catalog.current ? catalog.current.provider + "/" + catalog.current.model : "";
|
||
const currentEffortValue = (catalog.current && catalog.current.reasoningEffort) || "";
|
||
const modelDirty = draftModel !== currentModelValue || draftEffort !== currentEffortValue;
|
||
const canSaveModel = Boolean(chosenOption && seat && seat.id && modelDirty && !catalog.subagent && !busy);
|
||
|
||
const applyModel = () => {
|
||
if (!chosenOption || !seat || !seat.id) return;
|
||
const plan = modelSwitchPlan(catalog.current, {
|
||
provider: chosenOption.provider,
|
||
model: chosenOption.model,
|
||
reasoningEffort: draftEffort || undefined,
|
||
}, catalog.subagent);
|
||
if (!plan.ok) { setNotice({ kind: "error", text: plan.reason }); return; }
|
||
setBusy(true);
|
||
host.selectModel(seat.id, plan.payload).then((result) => {
|
||
setBusy(false);
|
||
if (result.ok) {
|
||
setNotice({ kind: "ok", text: "已切换到 " + chosenOption.label });
|
||
setCatalog((prev) => ({ ...prev, current: plan.payload }));
|
||
} else {
|
||
setNotice({ kind: "error", text: result.error });
|
||
}
|
||
});
|
||
};
|
||
|
||
const activeChildId = activeAddress && activeAddress.childSessionId
|
||
? activeAddress.childSessionId
|
||
: focusedSessionId !== leadSessionId ? focusedSessionId : undefined;
|
||
const activeSeat = seats.find((entry) => entry.id === activeChildId);
|
||
const previousChildRef = React.useRef(null);
|
||
React.useEffect(() => {
|
||
const previousChild = previousChildRef.current;
|
||
previousChildRef.current = activeChildId || null;
|
||
if (activeChildId) {
|
||
const role = childRoleOf(seats, activeChildId);
|
||
if (role) setSelectedRole(role);
|
||
return;
|
||
}
|
||
if (previousChild) setSelectedRole("lead");
|
||
}, [activeChildId, seats]);
|
||
const onTargetConversation = Boolean(targetId && focusedSessionId === targetId);
|
||
const conversationLabel = seat && seat.role === "lead"
|
||
? "返回丞相主会话"
|
||
: "与" + (seat ? seat.label : "该部门") + "对话";
|
||
const conversationHint = seat && seat.role === "lead"
|
||
? "回到统一受理需求的主会话;部门对话不会自动转呈丞相。"
|
||
: "进入该部门自己的 DSH 会话;消息不会自动同步给丞相。";
|
||
|
||
const openSeatConversation = () => {
|
||
if (!targetId) {
|
||
setNotice({ kind: "error", text: "该部门还没有可进入的会话,请先让丞相组建朝班。" });
|
||
return;
|
||
}
|
||
if (!host.openSession(targetId)) {
|
||
setNotice({ kind: "error", text: "打开部门会话失败,请稍后重试。" });
|
||
}
|
||
};
|
||
|
||
const returnToLead = () => {
|
||
const target = leadSessionId || (seat && seat.role === "lead" ? seat.id : undefined);
|
||
if (!target || !host.openSession(target)) {
|
||
setNotice({ kind: "error", text: "还没有丞相主会话,请先打开主对话。" });
|
||
}
|
||
};
|
||
|
||
const seatOf = (role) => seats.find((entry) => entry.role === role);
|
||
const renderSeat = (role) => {
|
||
const entry = seatOf(role);
|
||
if (!entry) return null;
|
||
const info = seatState(entry);
|
||
return h(SeatCard, {
|
||
key: entry.role,
|
||
seat: entry,
|
||
selected: entry.role === selectedRole,
|
||
status: info.status,
|
||
onSelect: (nextRole) => { setSelectedRole(nextRole); setNotice(null); },
|
||
});
|
||
};
|
||
|
||
return h("div", { className: (compact ? "sl-root sl-compact " : "sl-root ") + "sl-sidebar", "data-sansheng-panel": "true", "data-sansheng-compact": compact ? "1" : "0", "data-sansheng-sidebar": "1" }, [
|
||
h("div", { className: "sl-side-meta" }, [
|
||
h("span", { className: "sl-side-state" + (activeChildId ? " is-child" : "") }, [
|
||
h("span", { className: "sl-state-dot", "aria-hidden": "true" }),
|
||
team === undefined
|
||
? "等待组建朝班"
|
||
: activeSeat
|
||
? "正在与" + activeSeat.label + "对话"
|
||
: "朝班协作中",
|
||
]),
|
||
h("span", { className: "sl-side-hint", children: "输入 @ 选择部门" }),
|
||
activeChildId
|
||
? h("button", {
|
||
type: "button",
|
||
className: "sl-side-return",
|
||
onClick: returnToLead,
|
||
children: "返回丞相",
|
||
})
|
||
: null,
|
||
]),
|
||
h("div", { className: "sl-body sl-body-sidebar" }, [
|
||
h("div", { className: "sl-right" }, [
|
||
h("div", { className: "sl-side-tabs", role: "tablist", "aria-label": "朝堂视图" }, [
|
||
h("button", {
|
||
type: "button",
|
||
role: "tab",
|
||
className: "sl-side-tab" + (sidebarView === "court" ? " is-active" : ""),
|
||
"aria-selected": sidebarView === "court",
|
||
"data-side-tab": "court",
|
||
onClick: showCourt,
|
||
children: "朝堂",
|
||
}),
|
||
h("button", {
|
||
type: "button",
|
||
role: "tab",
|
||
className: "sl-side-tab" + (sidebarView === "tasks" ? " is-active" : ""),
|
||
"aria-selected": sidebarView === "tasks",
|
||
"data-side-tab": "tasks",
|
||
onClick: showTasks,
|
||
children: ["任务", h("span", { className: "sl-side-tab-count", children: openTaskCount })],
|
||
}),
|
||
]),
|
||
h("div", { className: "sl-stats", "data-sansheng-stats": "1" }, stats.map((stat) =>
|
||
h(stat.key === "pending" || stat.key === "members" ? "button" : "div", {
|
||
key: stat.key,
|
||
type: stat.key === "pending" || stat.key === "members" ? "button" : undefined,
|
||
onClick: stat.key === "pending" ? showTasks : stat.key === "members" ? showCourt : undefined,
|
||
title: stat.key === "pending" ? "查看任务流转" : stat.key === "members" ? "查看朝堂编制" : undefined,
|
||
className: "sl-stat sl-stat-" + stat.key,
|
||
}, [
|
||
h("span", { className: "sl-stat-mark", "aria-hidden": "true", children: stat.mark }),
|
||
h("span", { className: "sl-stat-body" }, [
|
||
h("b", { children: String(stat.value).padStart(2, "0") }),
|
||
h("small", { children: stat.label }),
|
||
]),
|
||
]))),
|
||
sidebarView === "court"
|
||
? h("div", { className: "sl-side-court" }, [
|
||
h("div", { className: "sl-map" }, [
|
||
h("div", { className: "sl-map-head" }, [
|
||
h("div", {}, [
|
||
h("span", { className: "sl-section-kicker", children: "组织编制" }),
|
||
h("h2", { children: "朝堂编制" }),
|
||
]),
|
||
h("div", { className: "sl-map-meta" }, [
|
||
h("span", { children: "十席 · 按需召集" }),
|
||
]),
|
||
]),
|
||
h("div", { className: "sl-tier" }, [
|
||
h("div", { className: "sl-tier-label" }, [
|
||
h("span", { children: "丞相" }),
|
||
h("small", { children: "统筹 · 分派 · 交付" }),
|
||
]),
|
||
h("div", { className: "sl-grid sl-grid-1", "data-tier": "lead" }, renderSeat("lead")),
|
||
]),
|
||
h("div", { className: "sl-connector-tri", "aria-hidden": "true" }, [
|
||
h("span", { key: "zhongshu" }),
|
||
h("span", { key: "shangshu" }),
|
||
h("span", { key: "menxia" }),
|
||
]),
|
||
h("div", { className: "sl-tier" }, [
|
||
h("div", { className: "sl-tier-label" }, [
|
||
h("span", { children: "三省" }),
|
||
h("small", { children: "拟案 · 执行 · 审议" }),
|
||
]),
|
||
h("div", { className: "sl-grid sl-grid-3", "data-tier": "provinces" }, [
|
||
renderSeat("zhongshu"),
|
||
renderSeat("shangshu"),
|
||
renderSeat("menxia"),
|
||
]),
|
||
]),
|
||
h("div", { className: "sl-stem", "aria-hidden": "true" }),
|
||
h("section", { className: "sl-ministry-group", "data-ministry-group": "1" }, [
|
||
h("div", { className: "sl-group-head" }, [
|
||
h("div", {}, [
|
||
h("span", { className: "sl-group-title", children: "六部 · 尚书省调度" }),
|
||
h("small", { children: "两排同属一级,按需召集" }),
|
||
]),
|
||
h("span", { className: "sl-group-count", children: "6 席" }),
|
||
]),
|
||
h("div", { className: "sl-grid sl-grid-6", "data-tier": "ministries" }, [
|
||
renderSeat("libu"),
|
||
renderSeat("hubu"),
|
||
renderSeat("lipu"),
|
||
renderSeat("bingbu"),
|
||
renderSeat("xingbu"),
|
||
renderSeat("gongbu"),
|
||
]),
|
||
]),
|
||
]),
|
||
h("section", { className: "sl-detail", "data-selected-role": seat ? seat.role : "none" }, [
|
||
h("div", { className: "sl-detail-head" }, [
|
||
h("span", { className: "sl-detail-mark", "aria-hidden": "true", children: seat ? seat.mark : "员" }),
|
||
h("div", { className: "sl-detail-title" }, [
|
||
h("strong", { children: seat ? seat.label : "成员" }),
|
||
h("small", { children: seat ? seat.duty : "" }),
|
||
]),
|
||
h("span", { className: "sl-detail-chip", children: "固定职责" }),
|
||
]),
|
||
h("div", { className: "sl-detail-status" }, [
|
||
h(Dot, { status: seatInfo.status }),
|
||
h("span", { children: STATUS_LABELS[seatInfo.status] || seatInfo.status }),
|
||
seatInfo.lastText ? h("small", { children: shortText(seatInfo.lastText, 46) }) : null,
|
||
]),
|
||
seat && !seat.present ? h("div", { className: "sl-hint", children: "该部门尚未设立。让丞相按流程组建后再进入会话。" }) : null,
|
||
seat && seat.present ? h("div", { className: "sl-setting-block" }, [
|
||
h("div", { className: "sl-setting-head" }, [
|
||
h("h3", { children: "模型设置" }),
|
||
h("small", { children: catalog.subagent ? "子会话跟随丞相" : "只影响该部门" }),
|
||
]),
|
||
catalog.subagent ? h("div", { className: "sl-hint", children: "子会话沿用丞相模型,不能在这里单独切换。" }) : h(React.Fragment, null, [
|
||
h("div", { className: "sl-model-grid" }, [
|
||
h("label", { className: "sl-control" }, [
|
||
h("span", { children: "模型" }),
|
||
h("select", {
|
||
value: draftModel,
|
||
disabled: catalog.status === "loading" || busy,
|
||
"aria-label": "部门模型",
|
||
onChange: (event) => {
|
||
setDraftModel(event.target.value);
|
||
const option = catalog.options.find((entry) => entry.rowId === event.target.value);
|
||
setDraftEffort(option && option.defaultEffort ? option.defaultEffort : "");
|
||
},
|
||
children: [
|
||
h("option", { value: "", children: catalog.status === "loading" ? "读取中…" : "选择模型" }),
|
||
...catalog.options.map((option) => h("option", { key: option.rowId, value: option.rowId, children: option.label })),
|
||
],
|
||
}),
|
||
]),
|
||
h("label", { className: "sl-control" }, [
|
||
h("span", { children: "推理等级" }),
|
||
h("select", {
|
||
value: draftEffort,
|
||
disabled: catalog.status === "loading" || busy || !chosenOption,
|
||
"aria-label": "部门推理等级",
|
||
onChange: (event) => setDraftEffort(event.target.value),
|
||
children: [
|
||
h("option", { value: "", children: "默认" }),
|
||
...(chosenOption ? chosenOption.efforts : []).map((effort) => h("option", { key: effort.id, value: effort.id, children: effort.name })),
|
||
],
|
||
}),
|
||
]),
|
||
]),
|
||
h("div", { className: "sl-model-foot" }, [
|
||
h("button", {
|
||
type: "button",
|
||
className: "sl-btn",
|
||
disabled: !canSaveModel,
|
||
onClick: applyModel,
|
||
children: busy ? "保存中…" : "保存模型设置",
|
||
}),
|
||
h("small", { className: modelDirty ? "is-dirty" : "", children: catalog.subagent ? "子会话沿用丞相模型" : modelDirty ? "有未保存的更改" : "当前:" + (catalog.current ? modelLabel(catalog.current) : "未设置") }),
|
||
]),
|
||
]),
|
||
catalog.error ? h("div", { className: "sl-error", children: catalog.error }) : null,
|
||
catalog.error ? h("button", {
|
||
type: "button",
|
||
className: "sl-link-button",
|
||
onClick: () => setCatalogRetry((value) => value + 1),
|
||
children: "重试读取模型",
|
||
}) : null,
|
||
]) : null,
|
||
h("div", { className: "sl-conversation-block" }, [
|
||
h("button", {
|
||
type: "button",
|
||
className: "sl-conversation-action",
|
||
disabled: !targetId || onTargetConversation,
|
||
"data-conversation-target": seat ? seat.role : "",
|
||
onClick: openSeatConversation,
|
||
children: [
|
||
h("span", { children: onTargetConversation ? (seat && seat.role === "lead" ? "正在丞相主会话" : "正在此部门会话") : conversationLabel }),
|
||
h("span", { className: "sl-conversation-arrow", "aria-hidden": "true", children: "↗" }),
|
||
],
|
||
}),
|
||
h("p", { className: "sl-conversation-hint", children: onTargetConversation ? "你当前就在这个会话中。" : conversationHint }),
|
||
]),
|
||
h("details", { className: "sl-advanced" }, [
|
||
h("summary", { children: "高级信息" }),
|
||
h("dl", { className: "sl-advanced-list" }, [
|
||
h("div", {}, [h("dt", { children: "角色标识" }), h("dd", { children: seat ? seat.role : "未选择" })]),
|
||
h("div", {}, [h("dt", { children: "Agent 预设" }), h("dd", { children: typeof presetForSeat === "string" && presetForSeat ? presetForSeat : "由宿主管理" })]),
|
||
h("div", {}, [h("dt", { children: "会话" }), h("dd", { children: targetId || "尚未建立" })]),
|
||
]),
|
||
]),
|
||
notice ? h("div", { className: notice.kind === "ok" ? "sl-ok" : "sl-error", role: "status", children: notice.text }) : null,
|
||
]),
|
||
])
|
||
: h("section", { className: "sl-task-panel sl-side-tasks", "data-side-tasks": "1" }, [
|
||
h("div", { className: "sl-section-title" }, [
|
||
h("div", { className: "sl-section-heading" }, [
|
||
h("span", { className: "sl-section-kicker", children: "任务队列" }),
|
||
h("h2", { children: "任务流转" }),
|
||
]),
|
||
h("span", { className: "sl-section-count", children: "执行 " + buckets.in_progress.length + " · 待办 " + buckets.pending.length }),
|
||
]),
|
||
h("ul", { className: "sl-tash" }, buckets.in_progress.concat(buckets.pending).slice(0, 8).map((task) => h("li", { key: task.id, title: task.description || "" }, [
|
||
h("span", { className: "sl-task-state" }, [h(Dot, { status: task.status === "in_progress" ? "running" : "provisioning" })]),
|
||
h("div", { className: "sl-task-copy" }, [
|
||
h("b", { children: task.subject || task.title || task.id }),
|
||
h("small", { children: task.status === "in_progress" ? "正在执行" : "等待受理" }),
|
||
]),
|
||
h("em", { className: "sl-task-owner", children: roleLabel(task.ownerName) }),
|
||
]))),
|
||
buckets.in_progress.length + buckets.pending.length === 0
|
||
? h("div", { className: "sl-task-empty" }, [
|
||
h("span", { className: "sl-empty-mark", "aria-hidden": "true", children: "✓" }),
|
||
h("div", {}, [h("strong", { children: "当前没有待办任务" }), h("p", { children: "新任务受理后,会在这里显示执行进度与负责部门。" })]),
|
||
])
|
||
: null,
|
||
]),
|
||
]),
|
||
]),
|
||
]);
|
||
}
|
||
// #endregion
|
||
// #region 宿主适配
|
||
function createHost(ctx) {
|
||
const sessions = ctx.sessions;
|
||
const conversations = new WeakMap();
|
||
let selectedSessionId;
|
||
let lastAction = "尚未操作";
|
||
const note = (text) => { lastAction = text; try { console.log("[三省六部] " + text); } catch (error) { /* 忽略 */ } };
|
||
|
||
/** layout 服务用可选查找:直接读 ctx.layout 会命中 inject 声明守卫。 */
|
||
const layoutService = () => {
|
||
try {
|
||
if (typeof ctx.get === "function") {
|
||
const service = ctx.get("layout");
|
||
if (service) return service;
|
||
}
|
||
} catch (error) { /* 退回直接读 */ }
|
||
try { return ctx.layout; } catch (error) { return undefined; }
|
||
};
|
||
const panelStore = (() => {
|
||
const service = layoutService();
|
||
return service && service.panelInfo ? service.panelInfo : undefined;
|
||
})();
|
||
const sessionsStore = sessions && sessions.list;
|
||
const statusStore = (() => {
|
||
const candidates = [];
|
||
if (sessions && sessions.statuses) candidates.push(sessions.statuses);
|
||
try {
|
||
if (typeof ctx.get === "function") {
|
||
const service = ctx.get("sessionStatus");
|
||
if (service) candidates.push(service);
|
||
}
|
||
} catch (error) { /* 忽略:拿不到时由 byId.running 兜底 */ }
|
||
return candidates.find((item) => item && typeof item.getSnapshot === "function" && typeof item.subscribe === "function");
|
||
})();
|
||
|
||
/** 当前中央面板 id:null 表示正在看会话本体。 */
|
||
const currentPanelId = () => {
|
||
if (!panelStore || typeof panelStore.getSnapshot !== "function") return null;
|
||
try {
|
||
const info = panelStore.getSnapshot();
|
||
return info ? info.activePanelId : null;
|
||
} catch (error) { return null; }
|
||
};
|
||
|
||
const bindingOf = (sessionId) => {
|
||
try { return sessions.binding(sessionId); } catch (error) { return undefined; }
|
||
};
|
||
|
||
const courtState = { pending: false };
|
||
const selectionSnapshot = () => {
|
||
try {
|
||
const store = ctx.uiWorkspace && ctx.uiWorkspace.selection;
|
||
return store && typeof store.getSnapshot === "function" ? (store.getSnapshot() || {}) : {};
|
||
} catch (error) { return {}; }
|
||
};
|
||
|
||
/** 唯一的投递实现:所有入口都走这里,返回结构化结果而不是抛异常。 */
|
||
const deliverPrompt = (sessionId, text) => {
|
||
if (!sessionId) return Promise.resolve({ ok: false, stage: "deliver", errorCode: "no-session", error: "没有可投递的会话" });
|
||
const binding = bindingOf(sessionId);
|
||
if (!binding || !binding.session || typeof binding.session.prompt !== "function") {
|
||
return Promise.resolve({ ok: false, stage: "deliver", sessionId: sessionId, errorCode: "no-session", error: "该会话还没有可用的对话通道" });
|
||
}
|
||
let pending;
|
||
try {
|
||
pending = binding.session.prompt.call(binding.session, [{ type: "text", text: text }], "queue");
|
||
} catch (error) {
|
||
return Promise.resolve({ ok: false, stage: "deliver", sessionId: sessionId, errorCode: "deliver-threw", error: "投递时出错:" + String((error && error.message) || error) });
|
||
}
|
||
return Promise.resolve(pending).then((result) => {
|
||
if (result && result.ok === false) {
|
||
return { ok: false, stage: "deliver", sessionId: sessionId, errorCode: "rejected", error: "宿主拒绝了这条消息:" + (result.error && result.error.message ? result.error.message : "原因未知") };
|
||
}
|
||
return { ok: true, stage: "delivered", sessionId: sessionId, text: text };
|
||
}, (error) => ({ ok: false, stage: "deliver", sessionId: sessionId, errorCode: "deliver-failed", error: "投递失败:" + String((error && error.message) || error) }));
|
||
};
|
||
|
||
/** 会话的对话快照(uiConversation 绑定按会话缓存,重复创建会丢掉已归并的节点)。 */
|
||
const conversationOf = (sessionId) => {
|
||
let service;
|
||
try { service = ctx.uiConversation; } catch (error) { return undefined; }
|
||
if (!service) return undefined;
|
||
const binding = bindingOf(sessionId);
|
||
if (!binding) return undefined;
|
||
let target = conversations.get(binding);
|
||
if (target === undefined) {
|
||
try {
|
||
const conversation = service.binding(binding);
|
||
target = conversation && conversation.target ? conversation.target("chat") : undefined;
|
||
} catch (error) {
|
||
target = undefined;
|
||
}
|
||
conversations.set(binding, target);
|
||
}
|
||
return target;
|
||
};
|
||
|
||
/** 取会话最近一条助手/用户文本:chat 快照的 nodes 是按 key 索引的只读集合。 */
|
||
const recentOf = (sessionId) => {
|
||
const target = conversationOf(sessionId);
|
||
if (!target) return "";
|
||
let snapshot;
|
||
try { snapshot = target.getSnapshot(); } catch (error) { return ""; }
|
||
const nodes = snapshot && snapshot.nodes;
|
||
if (!nodes || typeof nodes.values !== "function") return "";
|
||
const exchange = lastExchange(Array.from(nodes.values()));
|
||
return exchange.lastAssistant || exchange.lastUser;
|
||
};
|
||
|
||
/** 没有选中记录时,退回最近活跃的那个会话(整页版常用)。 */
|
||
const newestSessionId = () => {
|
||
try {
|
||
const list = sessionsStore && typeof sessionsStore.getSnapshot === "function" ? sessionsStore.getSnapshot() : undefined;
|
||
const byId = list && list.byId ? list.byId : {};
|
||
let best;
|
||
for (const key of Object.keys(byId)) {
|
||
const item = byId[key];
|
||
if (!item || item.blank === true) continue;
|
||
const at = typeof item.updatedAt === "number" ? item.updatedAt : Date.parse(item.updatedAt || "");
|
||
const score = Number.isFinite(at) ? at : 0;
|
||
if (!best || score > best.score) best = { id: item.id || key, score };
|
||
}
|
||
return best ? best.id : undefined;
|
||
} catch (error) { return undefined; }
|
||
};
|
||
|
||
/** 主视图当前选中的会话:以 uiWorkspace 的选中记录为准(面板是 root 级槽)。 */
|
||
const currentSession = () => {
|
||
try {
|
||
const saved = ctx.uiWorkspace && ctx.uiWorkspace.selection ? ctx.uiWorkspace.selection.getSnapshot() : undefined;
|
||
if (saved && saved.subagentAddress) return saved.subagentAddress.childSessionId;
|
||
if (saved && saved.sessionId) return saved.sessionId;
|
||
} catch (error) { /* 忽略:退回面板传入的选中 */ }
|
||
return selectedSessionId || newestSessionId();
|
||
};
|
||
|
||
const presetsRemote = () => {
|
||
try {
|
||
const remote = ctx.remote;
|
||
if (!remote) return undefined;
|
||
const presets = remote.agentPresets;
|
||
return presets && typeof presets.list === "function" ? presets : undefined;
|
||
} catch (error) { return undefined; }
|
||
};
|
||
|
||
const modelDirectoryOf = (sessionId) => {
|
||
let service;
|
||
try { service = ctx.modelDirectories || (typeof ctx.get === "function" ? ctx.get("modelDirectories") : undefined); } catch (error) { return undefined; }
|
||
if (!service || typeof service.directoryFor !== "function") return undefined;
|
||
try { return service.directoryFor(sessionId); } catch (error) { return undefined; }
|
||
};
|
||
|
||
const sidebarNav = () => {
|
||
const candidates = [];
|
||
try { if (typeof ctx.get === "function") candidates.push(ctx.get("sidebarRight")); } catch (error) { /* 忽略 */ }
|
||
try { candidates.push(ctx.sidebarRight); } catch (error) { /* 忽略 */ }
|
||
return candidates.find((item) => item && (typeof item.openTabIn === "function" || typeof item.openTab === "function"));
|
||
};
|
||
|
||
const openSanshengTab = (sessionId) => {
|
||
const nav = sidebarNav();
|
||
const target = sessionId || currentSession();
|
||
if (!target) {
|
||
return { ok: false, error: "当前还没有打开任何会话,右侧栏页签是会话级的;先新建或打开一个会话再停靠。" };
|
||
}
|
||
try {
|
||
const service = layoutService();
|
||
if (service && typeof service.selectPanel === "function") service.selectPanel(null);
|
||
} catch (error) { /* 忽略:右栏可能已经可见 */ }
|
||
|
||
const better = betterSidebarOf(ctx);
|
||
if (better && typeof better.openTab === "function") {
|
||
try {
|
||
better.openTab({ type: SANSENG_TAB_ID }, { sessionId: target });
|
||
return { ok: true, text: "朝堂已停靠到右侧栏" };
|
||
} catch (error) { /* 落到宿主原生右侧栏 */ }
|
||
}
|
||
|
||
let opened = false;
|
||
const attempt = (left) => {
|
||
try {
|
||
if (nav && typeof nav.openTabIn === "function") nav.openTabIn(target, SANSENG_TAB_KIND);
|
||
else if (nav && typeof nav.openTab === "function") nav.openTab(SANSENG_TAB_KIND);
|
||
opened = true;
|
||
} catch (error) {
|
||
opened = false;
|
||
}
|
||
if (opened || left <= 0) return;
|
||
setTimeout(() => attempt(left - 1), 60);
|
||
};
|
||
if (nav) attempt(8);
|
||
if (!nav) return { ok: false, error: "当前宿主没有右侧栏服务(sidebarRight),无法停靠到侧栏;整页形式仍可使用。" };
|
||
return { ok: true, text: "朝堂已停靠到右侧栏" };
|
||
};
|
||
|
||
// 会话头开关的失败原因:挂在 host 上,跨重渲染保留,成功后清空。
|
||
let toggleNotice = null;
|
||
const toggleNoticeListeners = new Set();
|
||
const setToggleNotice = (text) => {
|
||
const next = text ? String(text) : null;
|
||
if (next === toggleNotice) return;
|
||
toggleNotice = next;
|
||
for (const listener of Array.from(toggleNoticeListeners)) {
|
||
try { listener(); } catch (error) { /* 忽略:订阅方异常不影响开关 */ }
|
||
}
|
||
};
|
||
const toggleNoticeStore = {
|
||
getSnapshot: () => toggleNotice,
|
||
subscribe(listener) {
|
||
if (typeof listener !== "function") return () => {};
|
||
toggleNoticeListeners.add(listener);
|
||
return () => { toggleNoticeListeners.delete(listener); };
|
||
},
|
||
};
|
||
|
||
return {
|
||
sessionsStore,
|
||
statusStore,
|
||
panelStore,
|
||
getSelectedSession: currentSession,
|
||
setToggleNotice,
|
||
toggleNoticeStore,
|
||
setSelected(sessionId) {
|
||
selectedSessionId = sessionId;
|
||
},
|
||
currentPanelId,
|
||
selectPanel(panelId) {
|
||
const service = layoutService();
|
||
if (!service || typeof service.selectPanel !== "function") return false;
|
||
try { service.selectPanel(panelId); return true; } catch (error) { return false; }
|
||
},
|
||
togglePanel() {
|
||
return this.selectPanel(currentPanelId() === PANEL_ID ? null : PANEL_ID);
|
||
},
|
||
openSanshengTab,
|
||
memberModel(sessionId) {
|
||
const binding = bindingOf(sessionId);
|
||
if (!binding) return "";
|
||
try {
|
||
const face = binding.session.projections.faceOf("modelSelection");
|
||
const snapshot = face.getSnapshot();
|
||
return modelLabel(snapshot && snapshot.next ? snapshot.next.model || snapshot.next : snapshot);
|
||
} catch (error) { return ""; }
|
||
},
|
||
recentText(sessionId) {
|
||
if (!sessionId) return "";
|
||
try { return recentOf(sessionId); } catch (error) { return ""; }
|
||
},
|
||
/** 点「打开主对话」=开一个新对话:建好朝堂会话后把中央切到它,用户可以直接说话。 */
|
||
openConversation() {
|
||
return this.openCourtSession({ formation: false });
|
||
},
|
||
/** 只跳到已有对话(不新建)。 */
|
||
focusConversation() {
|
||
const target = currentSession();
|
||
if (!target) return { ok: false, stage: "focus", errorCode: "no-session", error: "当前还没有任何会话,可以先点「打开主对话」开一个。" };
|
||
try { ctx.uiWorkspace.openSession(target); } catch (error) {
|
||
return { ok: false, stage: "focus", errorCode: "open-failed", error: "打开会话失败:" + String((error && error.message) || error) };
|
||
}
|
||
const service = layoutService();
|
||
if (service && typeof service.selectPanel === "function") {
|
||
try { service.selectPanel(null); } catch (error) { /* 忽略 */ }
|
||
}
|
||
return { ok: true, stage: "focus", sessionId: target };
|
||
},
|
||
openSession(sessionId) {
|
||
let summary;
|
||
try { summary = sessions.list.getSnapshot().byId[sessionId]; } catch (error) { summary = undefined; }
|
||
const address = summary && summary.subagent && summary.subagent.address;
|
||
const parent = address && address.parentSessionId;
|
||
try {
|
||
if (parent && parent !== sessionId) {
|
||
ctx.uiWorkspace.openSession({ parentSessionId: parent, childSessionId: sessionId, mode: "continuable" });
|
||
} else {
|
||
ctx.uiWorkspace.openSession(sessionId);
|
||
}
|
||
} catch (error) {
|
||
return false;
|
||
}
|
||
const service = layoutService();
|
||
if (service && typeof service.selectPanel === "function") {
|
||
try { service.selectPanel(null); } catch (error) { /* 忽略 */ }
|
||
}
|
||
return true;
|
||
},
|
||
loadPresets() {
|
||
const remote = presetsRemote();
|
||
if (!remote) return Promise.resolve({ options: [], error: "当前宿主未提供 Agent 预设接口" });
|
||
const chain = Promise.resolve()
|
||
.then(() => remote.list())
|
||
.then((result) => {
|
||
if (!result || !result.ok) return { options: [], error: result && result.error ? result.error.message : "读取预设失败" };
|
||
const presets = result.value && Array.isArray(result.value.presets) ? result.value.presets : [];
|
||
return { options: presets.map((preset) => ({ id: preset.id, name: preset.name || preset.id })), error: null };
|
||
}, (error) => ({ options: [], error: "读取预设失败:" + String(error && error.message || error) }));
|
||
return withDeadline(chain, 6000, (error) => ({
|
||
options: [],
|
||
error: error ? "读取预设失败:" + String(error && error.message || error) : "读取预设超时:宿主 6 秒没有响应",
|
||
}));
|
||
},
|
||
loadCatalog(sessionId) {
|
||
const directory = modelDirectoryOf(sessionId);
|
||
if (!directory) return Promise.resolve({ options: [], current: undefined, error: "当前宿主未提供模型目录", subagent: false });
|
||
const cached = (message) => {
|
||
try {
|
||
const snapshot = directory.store.getSnapshot();
|
||
return {
|
||
options: modelOptions(snapshot),
|
||
current: snapshot.current,
|
||
error: message,
|
||
subagent: typeof sessions.subagentAddress === "function" ? sessions.subagentAddress(sessionId) !== undefined : false,
|
||
};
|
||
} catch (inner) {
|
||
return { options: [], current: undefined, error: message, subagent: false };
|
||
}
|
||
};
|
||
const chain = Promise.resolve()
|
||
.then(() => directory.load())
|
||
.then(() => {
|
||
const snapshot = directory.store.getSnapshot();
|
||
return {
|
||
options: modelOptions(snapshot),
|
||
current: snapshot.current,
|
||
error: snapshot.error || null,
|
||
subagent: typeof sessions.subagentAddress === "function" ? sessions.subagentAddress(sessionId) !== undefined : false,
|
||
};
|
||
}, (error) => cached(String(error && error.message || error)));
|
||
return withDeadline(chain, 6000, () => cached("读取模型目录超时(显示已知缓存)"));
|
||
},
|
||
selectModel(sessionId, payload) {
|
||
const directory = modelDirectoryOf(sessionId);
|
||
if (!directory) return Promise.resolve({ ok: false, error: "当前宿主未提供模型目录" });
|
||
return Promise.resolve()
|
||
.then(() => directory.select(payload))
|
||
.then(() => {
|
||
const snapshot = directory.store.getSnapshot();
|
||
return snapshot.error ? { ok: false, error: snapshot.error } : { ok: true };
|
||
}, (error) => ({ ok: false, error: String(error && error.message || error) }));
|
||
},
|
||
selectPreset(sessionId, presetId) {
|
||
const remote = presetsRemote();
|
||
if (!remote || typeof remote.select !== "function") return Promise.resolve({ ok: false, error: "当前宿主未提供 Agent 预设接口" });
|
||
return Promise.resolve()
|
||
.then(() => remote.select(sessionId, presetId))
|
||
.then((result) => (result && result.ok ? { ok: true } : { ok: false, error: result && result.error ? result.error.message : "应用预设失败" }),
|
||
(error) => ({ ok: false, error: String(error && error.message || error) }));
|
||
},
|
||
refresh(sessionId) {
|
||
const binding = bindingOf(sessionId);
|
||
if (binding && binding.session && binding.session.projections && typeof binding.session.projections.faceOf === "function") {
|
||
try { binding.session.projections.faceOf("agentPreset").getSnapshot(); } catch (error) { /* 忽略 */ }
|
||
}
|
||
if (typeof sessions.refreshProjections === "function") {
|
||
try { sessions.refreshProjections(sessionId).catch(() => {}); } catch (error) { /* 忽略 */ }
|
||
}
|
||
},
|
||
getLastAction() { return lastAction; },
|
||
sendPrompt(sessionId, text) {
|
||
return deliverPrompt(sessionId, text);
|
||
},
|
||
startFormation() {
|
||
const lead = currentSession();
|
||
if (!lead) return Promise.resolve({ ok: false, stage: "deliver", errorCode: "no-session", error: "没有可用会话" });
|
||
return deliverPrompt(lead, FORMATION_PROMPT).then((result) => (result.ok ? { ok: true, text: "已请丞相组建朝班" } : result));
|
||
},
|
||
|
||
/** 新开一个独立朝堂会话:绝不把旨意或组建指令写进用户当前正在聊的对话。 */
|
||
/** 新开一个独立朝堂会话:绝不把旨意或组建指令写进用户当前正在聊的对话。 */
|
||
openCourtSession(options) {
|
||
const withFormation = !options || options.formation !== false;
|
||
if (courtState.pending) return Promise.resolve({ ok: false, stage: "create", errorCode: "busy", error: "正在创建朝堂会话,请稍候再点" });
|
||
const snapshot = sessionsStore && typeof sessionsStore.getSnapshot === "function" ? sessionsStore.getSnapshot() : undefined;
|
||
const before = new Set(Object.keys((snapshot && snapshot.byId) || {}));
|
||
const beforeCount = before.size;
|
||
const beforeSelection = (selectionSnapshot() || {}).sessionId;
|
||
const ref = currentSession();
|
||
let workspaceId;
|
||
try { workspaceId = ctx.uiWorkspace && ctx.uiWorkspace.currentWorkspaceId; } catch (error) { /* 忽略 */ }
|
||
if (!workspaceId && ref && snapshot && snapshot.byId && snapshot.byId[ref]) workspaceId = snapshot.byId[ref].workspaceId;
|
||
if (!workspaceId && snapshot && snapshot.ids && snapshot.ids.length) {
|
||
const first = snapshot.byId[snapshot.ids[0]];
|
||
if (first && first.workspaceId) workspaceId = first.workspaceId;
|
||
}
|
||
const request = (ws) => {
|
||
note("请求新建会话,工作区=" + String(ws || "自动") + ",现有会话 " + beforeCount + " 个");
|
||
try { return ctx.uiWorkspace.startSession(ws, { agentPreset: "sansheng-liubu" }); } catch (error) {
|
||
console.warn("[三省六部] 新建会话失败:", error);
|
||
return undefined;
|
||
}
|
||
};
|
||
const waitNew = (left) => {
|
||
let now;
|
||
try { now = sessionsStore && typeof sessionsStore.getSnapshot === "function" ? sessionsStore.getSnapshot() : undefined; } catch (error) { now = undefined; }
|
||
const ids = (now && now.ids) || [];
|
||
for (const id of ids) if (!before.has(id)) return Promise.resolve(id);
|
||
const current = (selectionSnapshot() || {}).sessionId;
|
||
if (current && current !== beforeSelection && !before.has(current) && now && now.byId && now.byId[current]) return Promise.resolve(current);
|
||
if (left <= 0) return Promise.resolve(undefined);
|
||
return new Promise((resolve) => setTimeout(() => resolve(waitNew(left - 1)), 200));
|
||
};
|
||
const settle = (result) => {
|
||
courtState.pending = false;
|
||
note("开新朝堂:" + String((result && (result.text || result.error)) || result));
|
||
return result;
|
||
};
|
||
courtState.pending = true;
|
||
request(workspaceId);
|
||
return waitNew(15)
|
||
.then((first) => (first ? first : Promise.resolve().then(() => { request(undefined); return waitNew(30); })))
|
||
.then((sessionId) => {
|
||
if (!sessionId) {
|
||
console.warn("[三省六部] 新会话未创建", { workspaceId: workspaceId, beforeCount: beforeCount });
|
||
return settle({ ok: false, stage: "create", errorCode: "create-timeout", error: "宿主没有创建出新会话(工作区:" + String(workspaceId || "未识别") + ",原有会话 " + beforeCount + " 个)。可用左侧「新会话」手动建一个,并在顶部选「上朝」预设。" });
|
||
}
|
||
selectedSessionId = sessionId;
|
||
try { ctx.uiWorkspace.openSession(sessionId); } catch (error) { /* 忽略 */ }
|
||
const service = layoutService();
|
||
if (service && typeof service.selectPanel === "function") {
|
||
try { service.selectPanel(null); } catch (error) { /* 忽略 */ }
|
||
}
|
||
const shortId = sessionId.slice(0, 8);
|
||
if (!withFormation) {
|
||
return settle({ ok: true, stage: "created", sessionId: sessionId, text: "已开启新对话(" + shortId + "),可以直接说话" });
|
||
}
|
||
return deliverPrompt(sessionId, FORMATION_PROMPT).then((sent) => {
|
||
const short = shortId;
|
||
if (!sent.ok) {
|
||
return settle({ ok: false, stage: "deliver", sessionId: sessionId, errorCode: sent.errorCode, error: "已新开朝堂会话(" + short + "),但组建指令没送达:" + sent.error });
|
||
}
|
||
return settle({ ok: true, stage: "delivered", sessionId: sessionId, text: "已新开独立朝堂会话(" + short + "),丞相开始组建朝班" });
|
||
});
|
||
})
|
||
.catch((error) => settle({ ok: false, stage: "create", errorCode: "unexpected", error: "创建朝堂会话时出错:" + String((error && error.message) || error) }));
|
||
},
|
||
};
|
||
}
|
||
|
||
const FORMATION_PROMPT = [
|
||
"【上朝】按三省六部流程组建朝班:",
|
||
"1. 立即创建 zhongshu(中书省)、menxia(门下省)、shangshu(尚书省)三个成员。",
|
||
"2. 在共享任务板建立“中书拟案 → 门下审议 → 尚书派工”依赖链,写清各任务 writeScopes。",
|
||
"3. 门下准奏后由尚书按职责分派:吏部(Agent 与技能维护)、户部(数据与计算)、礼部(内容与呈现)、兵部(环境运行与部署)、刑部(按风险专项测试)、工部(开发实现);只召集本任务真正用到的部门。",
|
||
"4. 每阶段完成后向我汇报,我确认后再进入下一阶段。",
|
||
].join("\n");
|
||
|
||
|
||
const EMPTY_SESSIONS = { byId: {}, projectionsBySession: {}, ids: [], phase: "ready" };
|
||
|
||
/** 给可能永远不 settle 的宿主 Promise 加超时,超时后走 fallback,避免界面卡在「读取中」。 */
|
||
function withDeadline(promise, ms, fallback) {
|
||
return new Promise((resolve) => {
|
||
let settled = false;
|
||
const timer = setTimeout(() => {
|
||
if (settled) return;
|
||
settled = true;
|
||
try { resolve(fallback()); } catch (error) { resolve(undefined); }
|
||
}, ms);
|
||
Promise.resolve(promise).then((value) => {
|
||
if (settled) return;
|
||
settled = true;
|
||
clearTimeout(timer);
|
||
resolve(value);
|
||
}, (error) => {
|
||
if (settled) return;
|
||
settled = true;
|
||
clearTimeout(timer);
|
||
try { resolve(fallback(error)); } catch (inner) { resolve(undefined); }
|
||
});
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 订阅宿主 store 的快照。main 是 root 级槽,自带的会话级 hook 在 root 作用域下不可靠,
|
||
* 面板改为直接订阅服务层 store:数据与会话页同源,且不依赖 slot 注入的 hook。
|
||
* 用 useState + useEffect + subscribe,而不是 useSyncExternalStore:
|
||
* 宿主 store 的 getSnapshot 不保证每次返回同一引用,避免无限重渲染。
|
||
*/
|
||
function useStoreSnapshot(store, fallback) {
|
||
const read = () => {
|
||
if (!store || typeof store.getSnapshot !== "function") return fallback;
|
||
try { return store.getSnapshot() || fallback; } catch (error) { return fallback; }
|
||
};
|
||
const [snapshot, setSnapshot] = React.useState(read);
|
||
React.useEffect(() => {
|
||
if (!store || typeof store.subscribe !== "function") return undefined;
|
||
try { return store.subscribe(() => setSnapshot(read())); } catch (error) { return undefined; }
|
||
}, [store]);
|
||
return snapshot;
|
||
}
|
||
|
||
/** 面板级错误兜底:任何渲染异常都显示成可见的诊断块,而不是让宿主隔离成空白。 */
|
||
class PanelBoundary extends React.Component {
|
||
constructor(props) {
|
||
super(props);
|
||
this.state = { error: null };
|
||
}
|
||
static getDerivedStateFromError(error) {
|
||
return { error };
|
||
}
|
||
componentDidCatch(error) {
|
||
if (typeof console !== "undefined" && typeof console.error === "function") {
|
||
console.error("[三省六部] 面板渲染失败:", error);
|
||
}
|
||
}
|
||
render() {
|
||
const error = this.state.error;
|
||
if (!error) return this.props.children;
|
||
const message = error && error.message ? error.message : String(error);
|
||
return h("div", { className: "sl-crash", role: "alert" }, [
|
||
h("strong", { children: "三省六部面板渲染失败" }),
|
||
h("pre", { children: message }),
|
||
h("p", { children: "请把上面这段信息发给开发者;界面其余部分不受影响。" }),
|
||
]);
|
||
}
|
||
}
|
||
|
||
/** 主视图选中记录:uiWorkspace 把 {sessionId, subagentAddress} 持久化在 dsh.sessions.current。 */
|
||
function useWorkspaceSelection() {
|
||
const workspace = React.useContext(WorkspaceContext);
|
||
const read = () => {
|
||
if (!workspace || !workspace.selection) return {};
|
||
try { return workspace.selection.getSnapshot() || {}; } catch (error) { return {}; }
|
||
};
|
||
const [selection, setSelection] = React.useState(read);
|
||
React.useEffect(() => {
|
||
if (!workspace || !workspace.selection || typeof workspace.selection.subscribe !== "function") return undefined;
|
||
try { return workspace.selection.subscribe(() => setSelection(read())); } catch (error) { return undefined; }
|
||
}, [workspace]);
|
||
return selection;
|
||
}
|
||
|
||
/** 会话若自身就是被寻址的子代理,返回它的地址;否则 undefined。 */
|
||
function subagentAddressOf(sessions, sessionId) {
|
||
const summary = sessions.byId ? sessions.byId[sessionId] : undefined;
|
||
const direct = summary && summary.subagent && summary.subagent.address;
|
||
if (direct) return direct;
|
||
const bySession = sessions.projectionsBySession || {};
|
||
for (const parentId of Object.keys(bySession)) {
|
||
const parent = bySession[parentId];
|
||
const list = parent && parent.values ? parent.values.subagentCatalog : undefined;
|
||
if (Array.isArray(list) && list.some((entry) => entry && entry.id === sessionId)) {
|
||
return { parentSessionId: parentId, childSessionId: sessionId };
|
||
}
|
||
}
|
||
return undefined;
|
||
}
|
||
|
||
// #region 次要入口(会话头开关 / 侧栏置顶行 / 右侧栏页签)
|
||
/**
|
||
* 会话头入口。openSanshengTab() 失败(没有会话、宿主没有右侧栏服务)时,
|
||
* 0.5.0 会静默回退成 togglePanel(),用户点一下什么也看不到;这里把原因渲染出来,
|
||
* 并把失败原因挂在 host 的 toggleNoticeStore 上,跨重渲染保留。
|
||
*/
|
||
function SanshengToggle(props) {
|
||
const host = props.host;
|
||
const info = useStoreSnapshot(host && host.panelStore, {}) || {};
|
||
const notice = useStoreSnapshot(host && host.toggleNoticeStore, null);
|
||
const open = info.activePanelId === PANEL_ID;
|
||
return h("span", { className: "sl-toggle-wrap" }, [
|
||
h("button", {
|
||
key: "btn",
|
||
type: "button",
|
||
className: "sl-toggle" + (open ? " active" : ""),
|
||
"data-sansheng-toggle": open ? "open" : "closed",
|
||
title: "三省六部:把朝堂停靠到右侧栏,主对话留在中央",
|
||
onClick: () => {
|
||
const result = host.openSanshengTab();
|
||
const failed = Boolean(result && result.ok === false);
|
||
host.setToggleNotice(failed ? result.error : null);
|
||
if (failed) host.togglePanel();
|
||
},
|
||
}, [
|
||
h("span", { key: "mark", className: "sl-toggle-mark", children: "三省" }),
|
||
h("span", { key: "label", children: open ? "收起朝堂" : "三省六部" }),
|
||
]),
|
||
notice ? h("span", {
|
||
key: "notice",
|
||
className: "sl-toggle-notice",
|
||
role: "status",
|
||
title: notice,
|
||
children: notice,
|
||
}) : null,
|
||
]);
|
||
}
|
||
|
||
|
||
function SanshengTabTitle() {
|
||
return h("div", { className: "sl-tab-title", "data-sansheng-tab-title": "1" }, [
|
||
h("span", { key: "mark", className: "sl-tab-mark", children: "三省" }),
|
||
h("span", { key: "label", children: "朝堂" }),
|
||
]);
|
||
}
|
||
|
||
function SanshengTabBody(props) {
|
||
const host = props.host;
|
||
const sessionId = props.sessionId;
|
||
React.useEffect(() => {
|
||
if (sessionId && host.setSelected) host.setSelected(sessionId);
|
||
}, [sessionId]);
|
||
return h(PanelBoundary, null, h(SanshengPanel, { ...props, host, compact: true }));
|
||
}
|
||
|
||
|
||
/** 在原生 composer 注册 @ 部门入口;选择后进入对应子会话,消息仍由宿主输入框发送。 */
|
||
function createSeatMentionSource(ctx, host) {
|
||
const candidates = (session, options) => {
|
||
try {
|
||
const list = ctx.sessions.list.getSnapshot();
|
||
let sessionId = session && session.sessionId;
|
||
if (!sessionId && ctx.uiWorkspace && ctx.uiWorkspace.selection) {
|
||
sessionId = ctx.uiWorkspace.selection.getSnapshot().sessionId;
|
||
}
|
||
let address;
|
||
try { address = ctx.sessions.subagentAddress(sessionId); } catch (error) { address = undefined; }
|
||
if (!address) address = subagentAddressOf(list, sessionId);
|
||
const leadId = (address && address.parentSessionId) || sessionId;
|
||
const team = leadId && list.projectionsBySession && list.projectionsBySession[leadId]
|
||
? list.projectionsBySession[leadId].values.agentTeam
|
||
: undefined;
|
||
const query = String((options && options.query) || "").trim();
|
||
return Promise.resolve(seatMentionOptions(arrangeRoster(team)).filter((item) =>
|
||
query.length === 0 || item.label.indexOf(query) >= 0 || item.description.indexOf(query) >= 0));
|
||
} catch (error) {
|
||
return Promise.resolve([]);
|
||
}
|
||
};
|
||
return {
|
||
trigger: "@",
|
||
name: "sansheng",
|
||
showGroupTitle: false,
|
||
candidates,
|
||
onPick({ candidate }) {
|
||
const sessionId = candidate && candidate.value;
|
||
if (typeof sessionId === "string" && sessionId.length > 0) {
|
||
Promise.resolve().then(() => {
|
||
try { host.openSession(sessionId); } catch (error) { /* 宿主导航失败时保留当前会话 */ }
|
||
});
|
||
}
|
||
return { text: "" };
|
||
},
|
||
codec: {
|
||
clipboardText: (ref) => (ref && ref.label) || "",
|
||
serialize: (ref) => Promise.resolve((ref && ref.label) || ""),
|
||
},
|
||
};
|
||
}
|
||
|
||
function registerSeatMentions(ctx, host) {
|
||
let triggers;
|
||
try { triggers = typeof ctx.get === "function" ? ctx.get("inputTriggers") : undefined; } catch (error) { triggers = undefined; }
|
||
if (!triggers || typeof triggers.registerSource !== "function") return;
|
||
ctx.effect(() => triggers.registerSource(createSeatMentionSource(ctx, host)), "三省六部: @ 部门成员");
|
||
}
|
||
|
||
/** better-sidebar 是可选的:没装时不要写进 inject,否则插件会被 park。 */
|
||
function betterSidebarOf(ctx) {
|
||
const candidates = [];
|
||
try { if (typeof ctx.get === "function") candidates.push(ctx.get("betterSidebar")); } catch (error) { /* 忽略 */ }
|
||
try { candidates.push(ctx.betterSidebar); } catch (error) { /* 忽略 */ }
|
||
return candidates.find((item) => item && typeof item.registerTab === "function");
|
||
}
|
||
// #endregion
|
||
|
||
function apply(ctx) {
|
||
// 会话与输入框全部复用 DSH 原生界面;插件只向右侧栏注册朝堂页签。
|
||
WorkspaceContext = React.createContext(undefined);
|
||
const workspace = ctx.uiWorkspace;
|
||
const host = createHost(ctx);
|
||
registerSeatMentions(ctx, host);
|
||
|
||
ctx.slots.inject("conversation.session.header.actions", () => ctx.slots.register({
|
||
name: "conversation.session.header.actions",
|
||
id: PANEL_ID + ":toggle",
|
||
order: 40,
|
||
}, (props) => h(SanshengToggle, { ...props, host })));
|
||
|
||
// 右侧栏回退:宿主自带 sidebarRight(better-sidebar 存在时不注册,避免两处同名页签)。
|
||
const better = betterSidebarOf(ctx);
|
||
if (better) {
|
||
ctx.effect(() => better.registerTab({
|
||
id: SANSENG_TAB_ID,
|
||
title: "三省六部",
|
||
description: "朝堂成员图、任务与配置;对话本体留在中央",
|
||
order: 5,
|
||
single: true,
|
||
component: (props) => h(PanelBoundary, null, h(SanshengPanel, {
|
||
host,
|
||
sessionId: props && props.scope ? props.scope.sessionId : undefined,
|
||
compact: true,
|
||
})),
|
||
}), "三省六部: better-sidebar 页签");
|
||
} else {
|
||
try {
|
||
ctx.effect(() => {
|
||
try {
|
||
return ctx.sidebarRightTabs.register({
|
||
id: SANSENG_TAB_ID,
|
||
kind: SANSENG_TAB_KIND,
|
||
priority: "builtin",
|
||
title: () => "三省六部",
|
||
});
|
||
} catch (error) {
|
||
if (typeof console !== "undefined" && console.warn) console.warn("[三省六部] 右侧栏 tab 类型注册失败:", error);
|
||
return () => {};
|
||
}
|
||
}, "三省六部: 右侧栏 tab 类型");
|
||
} catch (error) { /* 老宿主没有该服务:会话头部入口和侧栏插槽仍可用 */ }
|
||
}
|
||
|
||
ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({
|
||
name: "sidebar.right.pane.tab",
|
||
key: SANSENG_TAB_ID,
|
||
}, (props) => h(SanshengTabBody, { ...props, host })));
|
||
|
||
ctx.slots.inject("sidebar.right.pane.tab.title", () => ctx.slots.register({
|
||
name: "sidebar.right.pane.tab.title",
|
||
key: SANSENG_TAB_ID,
|
||
}, () => h(SanshengTabTitle, null)));
|
||
}
|
||
|
||
exports.apply = apply;
|
||
exports.inject = ["slots", "sessions", "uiWorkspace", "uiConversation", "modelDirectories", "remote", "remote.agentPresets", "sidebarRightTabs", "sidebarRight"];
|
||
exports.SanshengPanel = SanshengPanel;
|
||
exports.PANEL_ID = PANEL_ID;
|
||
exports.SANSENG_TAB_ID = SANSENG_TAB_ID;
|
||
exports.SANSENG_TAB_KIND = SANSENG_TAB_KIND;
|
||
exports.createHost = createHost;
|
||
exports.__test = {
|
||
PANEL_ID,
|
||
SANSENG_TAB_ID,
|
||
SANSENG_TAB_KIND,
|
||
ROLE_IDS,
|
||
roleLabel,
|
||
roleMark,
|
||
modelLabel,
|
||
effortLabel,
|
||
arrangeRoster,
|
||
courtStats,
|
||
memberStatus,
|
||
tasksOfRole,
|
||
statusSummary,
|
||
modelOptions,
|
||
findModelOption,
|
||
modelSwitchPlan,
|
||
decreeText,
|
||
lastExchange,
|
||
shortText,
|
||
bucketsOf,
|
||
seatMentionOptions,
|
||
childRoleOf,
|
||
createSeatMentionSource,
|
||
};
|
||
return module.exports;
|
||
},
|
||
});
|