diff --git a/sansheng/client.js b/sansheng/client.js index 310a3a4..02b1cbb 100644 --- a/sansheng/client.js +++ b/sansheng/client.js @@ -369,138 +369,1743 @@ async function request(endpoint, payload, signal) { } var transport_default = request; -// src/client/styles.js -var CSS = ` -.ssw-scope{--ssw-bg:#ffffff;--ssw-side:#f8f9fa;--ssw-rail:#f8fafc;--ssw-card:#ffffff;--ssw-line:#e3e8ef;--ssw-strong:#c7d8f5;--ssw-ink:#0f172a;--ssw-muted:#667085;--ssw-faint:#98a2b3;--ssw-blue:#4263eb;--ssw-wash:#eef2ff;--ssw-frame:#3b82f6;--ssw-wire:#c9d6ea;--ssw-danger:#dc2626;--ssw-ok:#16a34a;box-sizing:border-box;color:var(--ssw-ink);font-family:Inter,"Segoe UI","Microsoft YaHei",sans-serif;font-size:13px;line-height:1.5} -.ssw-scope *,.ssw-scope *::before,.ssw-scope *::after{box-sizing:border-box} -.ssw-scope :where(button){font:inherit;color:inherit;background:transparent;border:0;cursor:pointer} -.ssw-scope button:disabled{cursor:default;opacity:.55} -.ssw-scope :focus-visible{outline:2px solid var(--ssw-blue);outline-offset:2px} -body[data-ds-dark-theme] .ssw-scope,html[data-theme=dark] .ssw-scope,.ssw-scope[data-ssw-theme=dark]{--ssw-bg:#14171c;--ssw-side:#171b21;--ssw-rail:#161a20;--ssw-card:#1e232b;--ssw-line:#2c333d;--ssw-strong:#3b4a63;--ssw-frame:#6ea8ff;--ssw-ink:#e6ebf2;--ssw-muted:#a9b4c2;--ssw-faint:#7b8797;--ssw-blue:#6ea8ff;--ssw-wash:#1d2b40;--ssw-wire:#3a4350;--ssw-danger:#f87171;--ssw-ok:#4ade80} -.ssw-float{position:fixed;right:14px;bottom:70px;z-index:2147483000;width:min(374px,calc(100vw - 28px));max-height:calc(100vh - 96px);display:flex;flex-direction:column;background:#ffffff;border:1px solid #e3e8ef;border-radius:12px;box-shadow:0 18px 50px -12px rgba(16,24,40,.28),0 4px 12px -2px rgba(16,24,40,.12);overflow:hidden} -body[data-ds-dark-theme] .ssw-float,html[data-theme=dark] .ssw-float{background:#161a20;border-color:#2c333d} -.ssw-root{container-type:inline-size;display:flex;flex-direction:column;min-height:0;height:100%;overflow:auto;background:var(--ssw-rail);color:var(--ssw-ink)} -.ssw-head{flex:none;height:52px;display:flex;align-items:center;gap:8px;padding:0 16px;border-bottom:1px solid var(--ssw-line);background:var(--ssw-card)} -.ssw-head svg{width:18px;height:18px;color:var(--ssw-muted)} -.ssw-head-title{font-size:13px;font-weight:600} -.ssw-icon-btn{margin-left:auto;display:inline-flex;align-items:center;justify-content:center;width:30px;height:30px;border-radius:6px;color:var(--ssw-muted)} -.ssw-icon-btn:hover{background:var(--ssw-wash);color:var(--ssw-blue)} -.ssw-project{padding:22px 20px 0} -.ssw-project-line{display:flex;align-items:center;justify-content:space-between;margin-bottom:5px} -.ssw-eyebrow{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:var(--ssw-muted)} -.ssw-eyebrow svg{width:14px;height:14px} -.ssw-count{font-size:10px;color:var(--ssw-faint)} -.ssw-project-title{font-size:21px;font-weight:650;letter-spacing:.5px;margin:4px 0 16px} -.ssw-enable{margin:0 16px 4px;padding:12px;border:1px solid var(--ssw-strong);background:var(--ssw-wash);border-radius:10px} -.ssw-enable-note{margin:0 0 10px;font-size:12px;color:var(--ssw-muted);line-height:1.7} -.ssw-primary{min-height:36px;background:var(--ssw-blue);color:#ffffff;border-radius:7px;padding:8px 13px;font-size:12px;font-weight:500} -.ssw-primary:hover{filter:brightness(1.05)} -.ssw-tree{padding:24px 20px 4px;position:relative} -.ssw-lead{width:168px;margin:0 auto;position:relative} -.ssw-lead::after{content:none} -.ssw-sansheng{position:relative;margin-top:24px} -.ssw-trio{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:9px} -.ssw-seat{position:relative;width:100%;display:flex;flex-direction:column;gap:6px;padding:14px 12px 12px;border:1px solid var(--ssw-line);border-radius:12px;background:var(--ssw-card);text-align:left;min-height:80px;box-shadow:0 1px 2px rgba(16,24,40,.04);transition:border-color .15s,box-shadow .15s,transform .15s} -.ssw-seat:hover{border-color:var(--ssw-blue);transform:translateY(-1px);box-shadow:0 3px 8px rgba(16,24,40,.06)} -.ssw-seat[aria-pressed=true]{border-color:var(--ssw-blue);background:var(--ssw-wash);box-shadow:0 0 0 2px rgba(59,130,246,.12)} -.ssw-lead .ssw-seat{min-height:84px} -.ssw-role-top{display:flex;align-items:center;justify-content:space-between;gap:6px} -.ssw-role-name{font-size:14px;font-weight:600;letter-spacing:2px} -.ssw-role-duty{font-size:11px;color:var(--ssw-muted);line-height:1.5} -.ssw-dot{flex:none;width:6px;height:6px;border-radius:50%;border:1px solid var(--ssw-faint);background:transparent} -.ssw-dot[data-status=bound]{background:var(--ssw-ok);border-color:var(--ssw-ok)} -.ssw-dot[data-status=failed],.ssw-dot[data-status=missing]{background:var(--ssw-danger);border-color:var(--ssw-danger)} -.ssw-dot[data-status=creating]{background:var(--ssw-blue);border-color:var(--ssw-blue)} -.ssw-ministries{position:relative;margin-top:18px} -.ssw-group-label{display:flex;align-items:center;gap:10px;margin:0 2px 8px;font-size:11px;font-weight:600;letter-spacing:.5px;color:var(--ssw-muted)} -.ssw-six{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px} -.ssw-six .ssw-seat{min-height:76px;padding:12px} -.ssw-report{padding:0 20px;margin-top:4px} -.ssw-report-toggle{font-size:12px;color:var(--ssw-blue);padding:7px 2px;font-weight:500} -.ssw-report-list{display:flex;flex-direction:column;gap:8px;margin-top:4px} -.ssw-report-item{border:1px solid var(--ssw-line);border-radius:9px;padding:9px 11px;background:var(--ssw-card)} -.ssw-report-head{display:flex;gap:8px;align-items:baseline} -.ssw-report-head strong{font-size:13px;letter-spacing:1px} -.ssw-report-head span{font-size:10px;color:var(--ssw-muted)} -.ssw-report-model{margin:4px 0 0;font-size:11px;color:var(--ssw-blue);letter-spacing:.2px} -.ssw-report-text{margin:4px 0 0;font-size:12px;line-height:1.7;color:var(--ssw-muted)} -.ssw-current{margin:14px 20px 0;padding:16px;border:1px solid var(--ssw-line);border-radius:11px;background:var(--ssw-card)} -.ssw-current-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:9px} -.ssw-current-name{font-size:13px;font-weight:600} -.ssw-current-label{font-size:10px;color:var(--ssw-faint)} -.ssw-current-text{margin:0;font-size:12px;line-height:1.8;color:var(--ssw-muted)} -.ssw-config{margin:10px 20px 20px;border:1px solid var(--ssw-line);border-radius:10px;background:var(--ssw-card);overflow:hidden} -.ssw-config-toggle{display:flex;align-items:center;gap:8px;width:100%;padding:12px 13px;font-size:12px;color:var(--ssw-ink)} -.ssw-config-toggle svg{width:15px;height:15px;color:var(--ssw-muted)} -.ssw-chevron{margin-left:auto;transition:transform .2s} -.ssw-config-toggle[aria-expanded=true] .ssw-chevron{transform:rotate(180deg)} -.ssw-config-body{padding:0 13px 14px} -.ssw-label{display:block;font-size:11px;color:var(--ssw-muted);margin:12px 0 6px} -.ssw-field{width:100%;border:1px solid var(--ssw-line);background:var(--ssw-bg);color:var(--ssw-ink);border-radius:6px;padding:8px;font-size:12px;line-height:1.5} -.ssw-textarea{resize:vertical;min-height:84px;font-family:inherit} -.ssw-scope-note{margin:10px 0;font-size:10px;line-height:1.6;color:var(--ssw-faint)} -.ssw-save-row{display:flex;align-items:center;gap:10px} -.ssw-save-status{font-size:10px;color:var(--ssw-muted)} -.ssw-notice{margin:12px 16px 16px;font-size:11px;color:var(--ssw-muted)} -.ssw-error{margin:12px 16px 16px;font-size:11px;color:var(--ssw-danger)} -.ssw-loading,.ssw-empty{padding:36px 20px;text-align:center;font-size:12px;color:var(--ssw-muted)} -.ssw-empty .ssw-primary{margin-top:12px} -/* 导航行图标:尺寸/颜色全部跟随宿主导航行,不自己画背景,避免比同类导航项突兀。 */ -.ssw-nav-hit{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;color:inherit;cursor:pointer} -.ssw-nav-hit svg{width:16px;height:16px;flex:none;display:block} -.ssw-hint{margin:6px 0 0;font-size:11px;color:var(--ssw-faint)} -.ssw-current-actions{margin-top:10px;display:flex;gap:8px} -.ssw-inline-bar{flex:none;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:8px 12px;border-bottom:1px solid var(--ssw-line);background:var(--ssw-card);font-size:12px;color:var(--ssw-muted)} -.ssw-link{color:var(--ssw-blue);font-size:12px;padding:2px 4px} -@media (prefers-reduced-motion:reduce){.ssw-scope *{transition:none!important}} -.ssw-tabs{display:flex;gap:6px;margin:0 20px;padding:4px;border:1px solid var(--ssw-line);border-radius:12px;background:var(--ssw-side)} -.ssw-tab{flex:1;display:flex;align-items:center;justify-content:center;gap:6px;padding:7px 6px;border-radius:6px;font-size:12px;color:var(--ssw-muted)} -.ssw-tab.is-active{background:var(--ssw-card);color:var(--ssw-blue);font-weight:600;box-shadow:0 1px 2px rgba(16,24,40,.06)} -.ssw-tab-count{font-size:10px;color:var(--ssw-faint)} -.ssw-page{padding:12px 16px 0} -.ssw-page-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px} -.ssw-page-head strong{font-size:13px} -.ssw-list{display:flex;flex-direction:column;gap:8px} -.ssw-row{border:1px solid var(--ssw-line);border-radius:9px;padding:9px 11px;background:var(--ssw-card)} -.ssw-row-top{display:flex;align-items:center;justify-content:space-between;gap:8px} -.ssw-row-title{font-size:13px} -.ssw-row-meta{margin:4px 0 0;font-size:11px;color:var(--ssw-muted)} -.ssw-row-note{margin:4px 0 0;font-size:10px;color:var(--ssw-faint)} -.ssw-row-result{margin:4px 0 0;font-size:11px;color:var(--ssw-ok);word-break:break-word} -.ssw-row-actions{display:flex;gap:10px;margin-top:6px} -.ssw-link{color:var(--ssw-blue);font-size:12px;padding:2px 2px} -.ssw-link-muted{color:var(--ssw-muted)} -.ssw-badge{font-size:10px;padding:2px 6px;border-radius:999px;background:var(--ssw-wash);color:var(--ssw-blue)} -.ssw-badge[data-status=running]{background:rgba(37,99,235,.12);color:var(--ssw-blue)} -.ssw-badge[data-status=done]{background:rgba(22,163,74,.12);color:var(--ssw-ok)} -.ssw-badge[data-status=cancelled]{background:rgba(107,114,128,.14);color:var(--ssw-muted)} -.ssw-badge[data-status=failed]{background:rgba(220,38,38,.12);color:var(--ssw-danger)} -.ssw-form{margin-bottom:12px;padding:10px;border:1px solid var(--ssw-line);border-radius:9px;background:var(--ssw-side)} -.ssw-empty-line{margin:10px 0;font-size:12px;color:var(--ssw-faint)} -.ssw-project-line{align-items:baseline;margin-bottom:10px} -.ssw-project-title{margin:0} -.ssw-tab-body{height:100%;min-height:0;display:flex;flex-direction:column} -.ssw-tab-body .ssw-root{flex:1;min-height:0} -.ssw-tab-title{font-size:13px} -.ssw-group-label::after{content:"";height:1px;background:var(--ssw-line);flex:1} -.ssw-role-top{width:100%} -.ssw-tab-count{padding:1px 5px;border-radius:5px;background:var(--ssw-rail)} -.ssw-current-name{font-size:15px;letter-spacing:1px} -.ssw-current-label{padding:3px 7px;border-radius:5px;background:var(--ssw-side)} -.ssw-config-toggle:hover{background:var(--ssw-side)} -/* 按工作台本身的宽度适配:宽屏居中,右侧窄栏保持紧凑。 */ -.ssw-root > :is(.ssw-project,.ssw-tree,.ssw-report,.ssw-page){width:100%;max-width:720px;align-self:center;flex-shrink:0} -.ssw-root > :is(.ssw-tabs,.ssw-current,.ssw-config,.ssw-enable,.ssw-notice,.ssw-error){width:calc(100% - 40px);max-width:680px;margin-left:auto;margin-right:auto;flex-shrink:0} -.ssw-enable{margin-top:12px} -@container(max-width:380px){.ssw-root > :is(.ssw-tabs,.ssw-current,.ssw-config,.ssw-enable,.ssw-notice,.ssw-error){width:calc(100% - 24px);margin-left:auto;margin-right:auto} -.ssw-project{padding:16px 12px 0}.ssw-tabs{margin:0 12px}.ssw-tree{padding:20px 12px 4px}.ssw-current{margin:12px 12px 0}.ssw-config{margin:10px 12px 16px}.ssw-report{padding:0 12px}.ssw-trio,.ssw-six{gap:6px}.ssw-seat,.ssw-six .ssw-seat{padding:10px 8px}.ssw-role-duty{font-size:10px}} -/* 窄栏隐藏职责小字,避免被卡片宽度截断 */ -@container (max-width:420px){ - .ssw-role-duty{display:none} - .ssw-seat{min-height:52px;padding:10px 9px;gap:0} - .ssw-six{grid-template-columns:repeat(2,minmax(0,1fr))} - .ssw-six .ssw-seat{min-height:50px;padding:10px 9px} +// src/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 @@ -858,7 +2463,7 @@ function install(ctx) { var native_default = { install }; // src/client/index.js -var import_react = require("react"); +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"; @@ -874,7 +2479,7 @@ function installStyles(doc, tag, text) { return style; } function svgWrap(children, props) { - return (0, import_react.createElement)("svg", { + return (0, import_react2.createElement)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, @@ -888,20 +2493,20 @@ function svgWrap(children, props) { }, children); } var TreeIcon = (props) => svgWrap([ - (0, import_react.createElement)("rect", { key: "a", x: 9, y: 2, width: 6, height: 5, rx: 1 }), - (0, import_react.createElement)("path", { key: "b", d: "M12 7v5M5 16v-4h14v4" }), - (0, import_react.createElement)("rect", { key: "c", x: 2, y: 16, width: 6, height: 5, rx: 1 }), - (0, import_react.createElement)("rect", { key: "d", x: 16, y: 16, width: 6, height: 5, rx: 1 }) + (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_react.createElement)("path", { key: "p", d: "m6 6 12 12M6 18 18 6" })], props); -var FolderIcon = (props) => svgWrap([(0, import_react.createElement)("path", { key: "p", d: "M3 7V5a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v11H3Z" })], props); +var 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_react.createElement)("path", { key: "a", d: "M4 6h16M4 12h16M4 18h16" }), - (0, import_react.createElement)("circle", { key: "b", cx: 9, cy: 6, r: 2 }), - (0, import_react.createElement)("circle", { key: "c", cx: 16, cy: 12, r: 2 }), - (0, import_react.createElement)("circle", { key: "d", cx: 8, cy: 18, r: 2 }) + (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_react.createElement)("svg", { +var ChevronIcon = (props) => (0, import_react2.createElement)("svg", { viewBox: "0 0 24 24", width: 14, height: 14, @@ -912,7 +2517,7 @@ var ChevronIcon = (props) => (0, import_react.createElement)("svg", { strokeLinejoin: "round", className: "ssw-chevron", "aria-hidden": "true" -}, (0, import_react.createElement)("path", { d: "m6 9 6 6 6-6" })); +}, (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"], @@ -927,7 +2532,7 @@ var SEAT_ICON_PATHS = { }; function SeatIcon(props) { const paths = SEAT_ICON_PATHS[props && props.id] ?? SEAT_ICON_PATHS.lead; - return (0, import_react.createElement)("svg", { + return (0, import_react2.createElement)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, @@ -938,7 +2543,7 @@ function SeatIcon(props) { strokeLinejoin: "round", "aria-hidden": "true", className: "ssw-seat-icon" - }, paths.map((d, index) => (0, import_react.createElement)("path", { key: index, d }))); + }, paths.map((d, index) => (0, import_react2.createElement)("path", { key: index, d }))); } function isFn(value) { return typeof value === "function"; @@ -1032,7 +2637,7 @@ function apply(ctx) { if (items.length === 1) return items[0]; return null; } - function seatRecordOf(view, id) { + 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; @@ -1126,10 +2731,10 @@ function apply(ctx) { return true; } function SanshengTabBody() { - return (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {})); + return (0, import_react2.createElement)("div", { className: "ssw-tab-body" }, (0, import_react2.createElement)(SanshengWorkbench, {})); } function SanshengTabTitle() { - return (0, import_react.createElement)("span", { className: "ssw-tab-title" }, "三省六部"); + return (0, import_react2.createElement)("span", { className: "ssw-tab-title" }, "三省六部"); } function registerRightTabType() { try { @@ -1139,10 +2744,10 @@ function apply(ctx) { id: TAB_KIND, title: "三省六部", description: "十席角色与独立会话的当前项目工作台", - icon: (size) => (0, import_react.createElement)(TreeIcon, { width: size, height: size }), + icon: (size) => (0, import_react2.createElement)(TreeIcon, { width: size, height: size }), order: 32, single: true, - component: () => (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {})) + component: () => (0, import_react2.createElement)("div", { className: "ssw-tab-body" }, (0, import_react2.createElement)(SanshengWorkbench, {})) }); return () => { try { @@ -1210,744 +2815,17 @@ function apply(ctx) { const selectedSeatCache = /* @__PURE__ */ new Map(); let lastSelectedSeatId = SEAT_IDS[0]; function SanshengWorkbench(props) { - const onClose = props && props.onClose ? props.onClose : null; - const [phase, setPhase] = (0, import_react.useState)("loading"); - const [error, setError] = (0, import_react.useState)(null); - const [errorRetryable, setErrorRetryable] = (0, import_react.useState)(true); - const [notice, setNotice] = (0, import_react.useState)(null); - const [view, setView] = (0, import_react.useState)(null); - const [models, setModels] = (0, import_react.useState)(null); - const [selectedSeatId, setSelectedSeatId] = (0, import_react.useState)(lastSelectedSeatId); - const [draft, setDraft] = (0, import_react.useState)({}); - const [busy, setBusy] = (0, import_react.useState)(false); - const [configOpen, setConfigOpen] = (0, import_react.useState)(false); - const [reportOpen, setReportOpen] = (0, import_react.useState)(false); - const [memory, setMemory] = (0, import_react.useState)(null); - const [memoryOpen, setMemoryOpen] = (0, import_react.useState)(false); - const [memoryDraft, setMemoryDraft] = (0, import_react.useState)({ goal: "", constraints: "", acceptance: "", decisions: "" }); - const [tab, setTab] = (0, import_react.useState)("court"); - const [tasks, setTasks] = (0, import_react.useState)([]); - const [artifacts, setArtifacts] = (0, import_react.useState)([]); - const [taskFormOpen, setTaskFormOpen] = (0, import_react.useState)(false); - const [taskDraft, setTaskDraft] = (0, import_react.useState)({ title: "", goal: "", ownerSeatId: SEAT_IDS[0] }); - const [summaryBusy, setSummaryBusy] = (0, import_react.useState)(false); - const [artifactFormOpen, setArtifactFormOpen] = (0, import_react.useState)(false); - const [artifactDraft, setArtifactDraft] = (0, import_react.useState)({ title: "", path: "", summary: "" }); - const alive = (0, import_react.useRef)(true); - (0, import_react.useEffect)(() => () => { - alive.current = false; - }, []); - const loadProject = (0, import_react.useCallback)(async () => { - setPhase("loading"); - setError(null); - setErrorRetryable(true); - setNotice(null); - const workspace = currentWorkspace(); - if (!workspace) { - setPhase("no-workspace"); - return; + return (0, import_react2.createElement)(WorkbenchV2, { + onClose: props && props.onClose, + resolveWorkspace: currentWorkspace, + navigateToSession, + openRightTab: tryOpenRightTab, + selectionCache: selectedSeatCache, + getLastSeatId: () => lastSelectedSeatId, + setLastSeatId: (id) => { + lastSelectedSeatId = id; } - 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 (memoryError) { - console.warn("[sansheng] 项目共识加载失败:", memoryError && memoryError.message ? memoryError.message : memoryError); - } - let taskList = []; - let artifactList = []; - try { - taskList = (await request("tasks", { projectId: projectView.project.id })).tasks ?? []; - } catch (taskError) { - console.warn("[sansheng] 任务加载失败:", taskError && taskError.message ? taskError.message : taskError); - } - try { - artifactList = (await request("artifacts", { projectId: projectView.project.id })).artifacts ?? []; - } catch (artifactError) { - console.warn("[sansheng] 成果加载失败:", artifactError && artifactError.message ? artifactError.message : artifactError); - } - if (!alive.current) return; - setView(projectView); - setModels(modelCatalog); - 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"); - } - }, []); - (0, import_react.useEffect)(() => { - void loadProject(); - }, [loadProject]); - const projectIdForSeat = view && view.project ? view.project.id : null; - (0, import_react.useEffect)(() => { - if (!projectIdForSeat) return; - const saved = selectedSeatCache.get(projectIdForSeat); - if (saved && SEAT_IDS.includes(saved)) { - lastSelectedSeatId = saved; - setSelectedSeatId(saved); - } - }, [projectIdForSeat]); - const wb = buildWorkbenchView(view, { selectedSeatId, models, draft }); - const seatById = (0, import_react.useMemo)(() => { - const map = {}; - for (const seat of wb.seats) map[seat.id] = seat; - return map; - }, [wb.seats]); - function pickSeat(id) { - if (!id) return; - if (id !== selectedSeatId) { - setSelectedSeatId(id); - setConfigOpen(false); - } - lastSelectedSeatId = id; - const pid = view && view.project ? view.project.id : null; - if (pid) selectedSeatCache.set(pid, id); - const seat = seatById[id]; - if (seat && seat.status === "missing") setNotice("「" + seat.name + "」的会话已不存在,点下面的「重建会话」可重新建立"); - else if (seat && seat.status !== "bound" && seat.status !== "creating") setNotice("「" + seat.name + "」还没开启,点下面的按钮开启这个部门"); - } - async function openSelectedSeat() { - const projectId = view && view.project ? view.project.id : null; - const seat = seatById[wb.selected.id]; - 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: seat.id }); - if (!alive.current) return; - if (!result || !result.sessionId) throw new Error("宿主没有返回会话"); - navigateToSession(result.sessionId); - setNotice("已切换到" + seat.name + "会话"); - } catch (openError) { - if (!alive.current) return; - 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 rebuildSelectedSeat() { - const projectId = view && view.project ? view.project.id : null; - const seat = seatById[wb.selected.id]; - if (!projectId || !seat) return; - const rec = seatRecordOf(view, seat.id); - const expectedSessionId = rec && rec.sessionId ? rec.sessionId : void 0; - setBusy(true); - setError(null); - setNotice("正在重建「" + seat.name + "」的会话…"); - try { - const next = await request("rebuildSeat", { projectId, seatId: seat.id, expectedSessionId }); - if (!alive.current) return; - setView(next); - setNotice("已重建「" + seat.name + "」的会话;旧会话历史仍保留"); - } catch (rebuildError) { - if (!alive.current) return; - 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); - } - } - function modelFromValue(value) { - const option = findModelOption(wb.selected.modelOptions, value); - if (!option) return null; - return option.reasoningEffort ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } : { provider: option.provider, model: option.model }; - } - async function rememberModel(value) { - const projectId = view && view.project ? view.project.id : null; - if (!projectId || !value) return; - const seatId = selectedSeatId; - 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 } }; - }); - setDraft((prev) => clearDraft(prev, seatId)); - setNotice("已记住「" + wb.selected.name + "」的模型,下次打开继续使用"); - } catch (error2) { - if (alive.current) setNotice(error2 && error2.message ? error2.message : "模型记忆失败"); - } - } - function setModelValue(value) { - setDraft((prev) => updateDraft(prev, selectedSeatId, { modelValue: value })); - void rememberModel(value); - } - function setInstructions(value) { - setDraft((prev) => updateDraft(prev, selectedSeatId, { instructions: value })); - } - async function enableSelectedSeat() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - const seatId = wb.selected.id; - setBusy(true); - setError(null); - setNotice("正在开启「" + wb.selected.name + "」…"); - try { - const next = await request("enableSeat", { projectId, seatId }); - if (!alive.current) return; - setView(next); - setNotice("已开启「" + wb.selected.name + "」的独立会话"); - try { - tryOpenRightTab(); - } catch { - } - } catch (enableError) { - if (alive.current) setError(enableError && enableError.message ? enableError.message : "开启失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function enableSeats() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - setBusy(true); - setError(null); - setNotice("正在启用十席…"); - try { - const next = await request("enable", { projectId }); - if (!alive.current) return; - setView(next); - setNotice("十席已启用(建立独立会话,不自动运行模型)"); - } catch (enableError) { - if (alive.current) setError(enableError && enableError.message ? enableError.message : "启用失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function saveConfig() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - const seatId = wb.selected.id; - const value = wb.selected.modelValue; - if (!value) { - setNotice("请先为当前角色选择模型"); - return; - } - const option = findModelOption(wb.selected.modelOptions, value); - const model = option ? option.reasoningEffort ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } : { provider: option.provider, model: option.model } : null; - setBusy(true); - setError(null); - setNotice("保存中…"); - try { - await request("configure", { projectId, seatId, model, instructions: wb.selected.instructions }); - const next = await request("project", { projectId }); - if (!alive.current) return; - setView(next); - setDraft((prev) => clearDraft(prev, seatId)); - setNotice("已保存"); - } catch (saveError) { - if (alive.current) setError(saveError && saveError.message ? saveError.message : "保存失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function saveMemory() { - const projectId = view && view.project ? view.project.id : null; - 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((line) => line.trim()).filter(Boolean), - acceptance: memoryDraft.acceptance.split("\n").map((line) => line.trim()).filter(Boolean), - decisions: memoryDraft.decisions.split("\n").map((line) => line.trim()).filter(Boolean).map((text) => ({ - type: "user", - status: "active", - text, - sourceRefs: wb.selected.sessionId ? [{ sessionId: wb.selected.sessionId, excerpt: "工作台记录", recordedAt: Date.now() }] : [] - })), - sources: wb.selected.sessionId ? [{ id: "ui-" + Date.now(), sessionId: wb.selected.sessionId, excerpt: "工作台记录", recordedAt: Date.now() }] : [] - }); - 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(projectId) { - try { - const result = await request("tasks", { projectId }); - if (alive.current) setTasks(result.tasks ?? []); - } catch (error2) { - if (alive.current) setNotice(error2 && error2.message ? error2.message : "任务列表刷新失败"); - } - } - async function createTask() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - const title = taskDraft.title.trim(); - if (!title) { - setNotice("任务标题不能为空"); - return; - } - setBusy(true); - setError(null); - try { - await request("taskCreate", { projectId, title, goal: taskDraft.goal, ownerSeatId: taskDraft.ownerSeatId }); - setTaskDraft({ title: "", goal: "", ownerSeatId: taskDraft.ownerSeatId }); - setTaskFormOpen(false); - await reloadTasks(projectId); - setNotice("已存为草稿;点「派工」才会交给部门。"); - } catch (error2) { - if (alive.current) setError(error2 && error2.message ? error2.message : "新建任务失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function dispatchTask(taskId) { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - setBusy(true); - setError(null); - try { - const result = await request("taskDispatch", { projectId, taskId }); - await reloadTasks(projectId); - setNotice(result.delivered ? "已派工到该部门会话。" : "已记录为待执行(当前宿主暂不支持直接发送)。"); - } catch (error2) { - if (alive.current) setError(error2 && error2.message ? error2.message : "派工失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function summarizeByShangshu() { - const projectId = view && view.project ? view.project.id : null; - 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 cancelTask(taskId) { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - setBusy(true); - setError(null); - try { - await request("taskCancel", { projectId, taskId }); - await reloadTasks(projectId); - setNotice("任务已取消。"); - } catch (error2) { - if (alive.current) setError(error2 && error2.message ? error2.message : "取消失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function addArtifact() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - const title = artifactDraft.title.trim(); - if (!title) { - setNotice("成果名称不能为空"); - return; - } - setBusy(true); - setError(null); - try { - const result = await request("artifactAdd", { projectId, title, path: artifactDraft.path, summary: artifactDraft.summary }); - setArtifactDraft({ title: "", path: "", summary: "" }); - setArtifactFormOpen(false); - setArtifacts((list) => [...list, result.artifact]); - setNotice("成果已登记。"); - } catch (error2) { - if (alive.current) setError(error2 && error2.message ? error2.message : "登记成果失败"); - } finally { - if (alive.current) setBusy(false); - } - } - const seatCard = (seat) => (0, import_react.createElement)( - "button", - { - key: seat.id, - type: "button", - className: "ssw-seat", - "aria-pressed": seat.selected ? "true" : "false", - title: seat.name + " · " + seat.duty + "(" + seat.statusLabel + ")", - onClick: () => pickSeat(seat.id) - }, - (0, import_react.createElement)( - "span", - { className: "ssw-role-top" }, - (0, import_react.createElement)("span", { className: "ssw-role-name" }, seat.name), - (0, import_react.createElement)("span", { className: "ssw-dot", "data-status": seat.status, "aria-hidden": "true" }) - ), - (0, import_react.createElement)("span", { className: "ssw-role-duty" }, seat.duty) - ); - const pickList = (ids) => ids.map((id) => seatById[id]).filter(Boolean); - const tree = (0, import_react.createElement)( - "section", - { className: "ssw-tree", "aria-label": "切换角色" }, - (0, import_react.createElement)("div", { className: "ssw-lead" }, pickList(wb.groups.lead).map(seatCard)), - (0, import_react.createElement)( - "div", - { className: "ssw-sansheng" }, - (0, import_react.createElement)("span", { className: "ssw-group-label" }, "三省"), - (0, import_react.createElement)("div", { className: "ssw-trio" }, pickList(wb.groups.sansheng).map(seatCard)) - ), - (0, import_react.createElement)( - "div", - { className: "ssw-ministries" }, - (0, import_react.createElement)("span", { className: "ssw-group-label" }, "六部 · 尚书统筹"), - (0, import_react.createElement)("div", { className: "ssw-six" }, pickList(wb.groups.liubu).map(seatCard)) - ) - ); - const head = (0, import_react.createElement)( - "header", - { className: "ssw-head" }, - (0, import_react.createElement)(TreeIcon), - (0, import_react.createElement)("strong", { className: "ssw-head-title" }, "工作台"), - onClose ? (0, import_react.createElement)("button", { type: "button", className: "ssw-icon-btn", onClick: onClose, "aria-label": "收起工作台" }, (0, import_react.createElement)(CloseIcon)) : null - ); - const projectInfo = (0, import_react.createElement)( - "div", - { className: "ssw-project" }, - (0, import_react.createElement)( - "div", - { className: "ssw-project-line", style: { justifyContent: "flex-end" } }, - (0, import_react.createElement)("span", { className: "ssw-count" }, wb.project.seatCount + " 个角色 · " + wb.project.sessionCount + " 个会话") - ), - (0, import_react.createElement)("div", { className: "ssw-project-title" }, wb.projectTitle || "未命名项目") - ); - const selectedStatus = wb.selected.status; - const detailActions = (0, import_react.createElement)( - "div", - { className: "ssw-current-actions" }, - selectedStatus === "bound" ? (0, import_react.createElement)("button", { - type: "button", - className: "ssw-primary", - disabled: busy, - onClick: openSelectedSeat - }, "开始对话") : selectedStatus === "missing" ? (0, import_react.createElement)("button", { - type: "button", - className: "ssw-primary", - disabled: busy, - onClick: rebuildSelectedSeat - }, "重建会话") : (0, import_react.createElement)("button", { - type: "button", - className: "ssw-primary", - disabled: busy || selectedStatus === "creating", - onClick: enableSelectedSeat - }, selectedStatus === "creating" ? "正在开启…" : "开启「" + wb.selected.name + "」") - ); - const optionEls = wb.selected.modelOptions.map((option) => (0, import_react.createElement)("option", { key: option.value, value: option.value }, option.label)); - if (wb.selected.modelValue && !wb.selected.modelOptions.some((option) => option.value === wb.selected.modelValue)) { - optionEls.push((0, import_react.createElement)("option", { key: "__current__", value: wb.selected.modelValue }, wb.selected.modelLabel)); - } - const config = (0, import_react.createElement)( - "section", - { className: "ssw-config" }, - (0, import_react.createElement)( - "button", - { - type: "button", - className: "ssw-config-toggle", - "aria-expanded": configOpen ? "true" : "false", - onClick: () => setConfigOpen((value) => !value) - }, - (0, import_react.createElement)(GearIcon), - (0, import_react.createElement)("span", null, "配置" + wb.selected.name + (wb.selected.dirty ? " · 未保存" : "")), - (0, import_react.createElement)(ChevronIcon) - ), - configOpen ? (0, import_react.createElement)( - "div", - { className: "ssw-config-body" }, - (0, import_react.createElement)("label", { className: "ssw-label" }, "默认模型(开启该部门时应用)"), - (0, import_react.createElement)( - "select", - { - className: "ssw-field", - value: wb.selected.modelValue, - disabled: busy, - onChange: (event) => setModelValue(event.target.value) - }, - (0, import_react.createElement)("option", { value: "", disabled: true }, UNCHOSEN_MODEL_LABEL), - ...optionEls - ), - (0, import_react.createElement)("label", { className: "ssw-label" }, "角色补充说明"), - (0, import_react.createElement)("textarea", { - className: "ssw-field ssw-textarea", - rows: 4, - value: wb.selected.instructions, - disabled: busy, - placeholder: "补充该角色在当前项目中的工作要求", - onChange: (event) => setInstructions(event.target.value) - }), - (0, import_react.createElement)("p", { className: "ssw-scope-note" }, "这里预配置的模型会在开启该部门或按需派工时应用;丞相派工不选择模型。只影响当前项目当前角色。"), - (0, import_react.createElement)( - "div", - { className: "ssw-save-row" }, - (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", disabled: busy, onClick: saveConfig }, busy ? "保存中…" : "保存配置"), - wb.selected.dirty ? (0, import_react.createElement)("span", { className: "ssw-save-status" }, "有未保存修改") : null - ) - ) : null - ); - const memorySection = (0, import_react.createElement)( - "section", - { className: "ssw-config" }, - (0, import_react.createElement)( - "button", - { - type: "button", - className: "ssw-config-toggle", - "aria-expanded": memoryOpen ? "true" : "false", - onClick: () => setMemoryOpen((value) => !value) - }, - (0, import_react.createElement)(GearIcon), - (0, import_react.createElement)("span", null, "项目共识 v" + (memory?.revision ?? 0) + (memory?.updatedAt ? " · 最近更新" : " · 尚未建立")), - (0, import_react.createElement)(ChevronIcon) - ), - memoryOpen ? (0, import_react.createElement)( - "div", - { className: "ssw-config-body" }, - (0, import_react.createElement)("label", { className: "ssw-label" }, "项目目标"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: memoryDraft.goal, placeholder: "这个项目最终要达成什么", onChange: (event) => setMemoryDraft({ ...memoryDraft, goal: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "硬约束(每行一条,部门必须遵守)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: memoryDraft.constraints, placeholder: "例如:不能改动线上数据", onChange: (event) => setMemoryDraft({ ...memoryDraft, constraints: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "验收标准(每行一条)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: memoryDraft.acceptance, placeholder: "例如:交付前必须跑完回归测试", onChange: (event) => setMemoryDraft({ ...memoryDraft, acceptance: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "新增决定(每行一条,按用户明确要求记录)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 2, value: memoryDraft.decisions, placeholder: "例如:先保证稳定性,再考虑样式", onChange: (event) => setMemoryDraft({ ...memoryDraft, decisions: event.target.value }) }), - (0, import_react.createElement)("p", { className: "ssw-scope-note" }, "保存后版本号会增加;每个部门在下一次模型请求前都会收到这份共识。当前为本地临时存储,后续迁移到 Mnemon Documents。"), - (0, import_react.createElement)("div", { className: "ssw-save-row" }, (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", disabled: busy, onClick: saveMemory }, busy ? "保存中…" : "保存共识")) - ) : null - ); - const report = (0, import_react.createElement)( - "section", - { className: "ssw-report" }, - (0, import_react.createElement)("button", { - type: "button", - className: "ssw-report-toggle", - "aria-expanded": reportOpen ? "true" : "false", - onClick: () => setReportOpen((value) => !value) - }, reportOpen ? "收起角色职责" : "全部角色职责"), - reportOpen ? (0, import_react.createElement)( - "div", - { className: "ssw-report-list" }, - SEAT_IDS.map((id) => { - const rec = seatRecordOf(view, id); - const m = rec && rec.model; - const modelLabel = m && m.model ? m.model + (m.reasoningEffort ? " · " + m.reasoningEffort : "") : "未选择模型"; - return (0, import_react.createElement)( - "div", - { key: id, className: "ssw-report-item", "data-seat": id }, - (0, import_react.createElement)( - "div", - { className: "ssw-report-head" }, - (0, import_react.createElement)("strong", null, SEATS[id].label), - (0, import_react.createElement)("span", null, SEATS[id].duty) - ), - (0, import_react.createElement)("p", { className: "ssw-report-model" }, "模型:" + modelLabel), - (0, import_react.createElement)("p", { className: "ssw-report-text" }, SEATS[id].responsibility) - ); - }) - ) : null - ); - const statusEl = error ? (0, import_react.createElement)("p", { className: "ssw-error", role: "alert" }, error) : notice ? (0, import_react.createElement)("p", { className: "ssw-notice", role: "status" }, notice) : null; - const tabCounts = { court: wb.project.seatCount, tasks: tasks.length, artifacts: artifacts.length }; - const tabBar = (0, import_react.createElement)( - "div", - { className: "ssw-tabs", role: "tablist" }, - [["court", "朝堂"], ["tasks", "任务"], ["artifacts", "成果"]].map(([id, label]) => (0, import_react.createElement)("button", { - key: id, - type: "button", - role: "tab", - "aria-selected": tab === id ? "true" : "false", - className: "ssw-tab" + (tab === id ? " is-active" : ""), - onClick: () => setTab(id) - }, (0, import_react.createElement)("span", null, label), (0, import_react.createElement)("span", { className: "ssw-tab-count" }, String(tabCounts[id] ?? 0)))) - ); - const TASK_STATUS_LABEL = { draft: "草稿", prepared: "待执行", dispatched: "已派工", running: "执行中", done: "已完成", cancelled: "已取消", failed: "失败" }; - const taskRows = tasks.length === 0 ? (0, import_react.createElement)("p", { className: "ssw-empty-line" }, "这个项目还没有任务。点「新建任务」先存一张草稿。") : tasks.map((task) => { - const stale = (memory?.revision ?? 0) > (task.contextRevision ?? 0) && (task.status === "dispatched" || task.status === "prepared" || task.status === "running"); - return (0, import_react.createElement)( - "article", - { key: task.id, className: "ssw-row", "data-task": task.id }, - (0, import_react.createElement)( - "div", - { className: "ssw-row-top" }, - (0, import_react.createElement)("strong", { className: "ssw-row-title" }, task.title), - (0, import_react.createElement)("span", { className: "ssw-badge", "data-status": task.status }, TASK_STATUS_LABEL[task.status] ?? task.status), - stale ? (0, import_react.createElement)("span", { className: "ssw-badge", "data-status": "stale" }, "要求有更新") : null - ), - (0, import_react.createElement)("p", { className: "ssw-row-meta" }, (SEATS[task.ownerSeatId]?.label ?? task.ownerSeatId) + (task.goal ? " · " + task.goal : "") + (task.contextRevision !== void 0 ? " · 共识 v" + task.contextRevision : "")), - task.note ? (0, import_react.createElement)("p", { className: "ssw-row-note" }, task.note) : null, - task.result ? (0, import_react.createElement)("p", { className: "ssw-row-result" }, "结果:" + task.result) : null, - (0, import_react.createElement)( - "div", - { className: "ssw-row-actions" }, - task.status === "draft" || task.status === "prepared" || task.status === "failed" ? (0, import_react.createElement)("button", { type: "button", className: "ssw-link", disabled: busy, onClick: () => dispatchTask(task.id) }, task.status === "prepared" ? "重试派工" : "派工") : null, - task.status !== "done" && task.status !== "cancelled" ? (0, import_react.createElement)("button", { type: "button", className: "ssw-link ssw-link-muted", disabled: busy, onClick: () => cancelTask(task.id) }, "取消") : null - ) - ); }); - const taskView = (0, import_react.createElement)( - "section", - { className: "ssw-page" }, - (0, import_react.createElement)( - "div", - { className: "ssw-page-head" }, - (0, import_react.createElement)("strong", null, "任务 · " + tasks.length), - (0, import_react.createElement)( - "div", - { style: { display: "flex", alignItems: "center", gap: "10px" } }, - (0, import_react.createElement)("button", { type: "button", className: "ssw-link", disabled: busy || summaryBusy || tasks.length === 0, onClick: () => { - void summarizeByShangshu(); - } }, summaryBusy ? "汇总中…" : "尚书汇总"), - (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: () => setTaskFormOpen((value) => !value) }, taskFormOpen ? "收起" : "新建任务") - ) - ), - taskFormOpen ? (0, import_react.createElement)( - "form", - { className: "ssw-form", onSubmit: (event) => { - event.preventDefault(); - void createTask(); - } }, - (0, import_react.createElement)("label", { className: "ssw-label" }, "标题"), - (0, import_react.createElement)("input", { className: "ssw-field", value: taskDraft.title, placeholder: "交给部门做什么", onChange: (event) => setTaskDraft({ ...taskDraft, title: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "目标(可选)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: taskDraft.goal, onChange: (event) => setTaskDraft({ ...taskDraft, goal: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "主责部门"), - (0, import_react.createElement)( - "select", - { className: "ssw-field", value: taskDraft.ownerSeatId, onChange: (event) => setTaskDraft({ ...taskDraft, ownerSeatId: event.target.value }) }, - SEAT_IDS.map((id) => (0, import_react.createElement)("option", { key: id, value: id }, SEATS[id].label)) - ), - (0, import_react.createElement)("div", { className: "ssw-save-row" }, (0, import_react.createElement)("button", { type: "submit", className: "ssw-primary", disabled: busy }, busy ? "保存中…" : "保存草稿")) - ) : null, - (0, import_react.createElement)("div", { className: "ssw-list" }, taskRows) - ); - const artifactRows = artifacts.length === 0 ? (0, import_react.createElement)("p", { className: "ssw-empty-line" }, "这个项目还没有登记成果。") : artifacts.map((item) => (0, import_react.createElement)( - "article", - { key: item.id, className: "ssw-row", "data-artifact": item.id }, - (0, import_react.createElement)("div", { className: "ssw-row-top" }, (0, import_react.createElement)("strong", { className: "ssw-row-title" }, item.title)), - item.summary ? (0, import_react.createElement)("p", { className: "ssw-row-meta" }, item.summary) : null, - item.path ? (0, import_react.createElement)("p", { className: "ssw-row-note" }, item.path) : null - )); - const artifactView = (0, import_react.createElement)( - "section", - { className: "ssw-page" }, - (0, import_react.createElement)( - "div", - { className: "ssw-page-head" }, - (0, import_react.createElement)("strong", null, "成果 · " + artifacts.length), - (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: () => setArtifactFormOpen((value) => !value) }, artifactFormOpen ? "收起" : "登记成果") - ), - artifactFormOpen ? (0, import_react.createElement)( - "form", - { className: "ssw-form", onSubmit: (event) => { - event.preventDefault(); - void addArtifact(); - } }, - (0, import_react.createElement)("label", { className: "ssw-label" }, "成果名称"), - (0, import_react.createElement)("input", { className: "ssw-field", value: artifactDraft.title, onChange: (event) => setArtifactDraft({ ...artifactDraft, title: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "文件路径(可选)"), - (0, import_react.createElement)("input", { className: "ssw-field", value: artifactDraft.path, onChange: (event) => setArtifactDraft({ ...artifactDraft, path: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "说明(可选)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: artifactDraft.summary, onChange: (event) => setArtifactDraft({ ...artifactDraft, summary: event.target.value }) }), - (0, import_react.createElement)("div", { className: "ssw-save-row" }, (0, import_react.createElement)("button", { type: "submit", className: "ssw-primary", disabled: busy }, busy ? "保存中…" : "保存")) - ) : null, - (0, import_react.createElement)("div", { className: "ssw-list" }, artifactRows) - ); - const detail = (0, import_react.createElement)( - "section", - { className: "ssw-current" }, - (0, import_react.createElement)( - "div", - { className: "ssw-current-top" }, - (0, import_react.createElement)("strong", { className: "ssw-current-name" }, wb.selected.name), - (0, import_react.createElement)("span", { className: "ssw-current-label" }, "角色职责 · " + wb.selected.statusLabel) - ), - (0, import_react.createElement)("p", { className: "ssw-current-text" }, wb.selected.responsibility), - detailActions - ); - const courtView = (0, import_react.createElement)(import_react.Fragment, null, tree, detail, config, memorySection); - let body; - if (phase === "loading") body = (0, import_react.createElement)("div", { className: "ssw-loading" }, "正在加载工作台…"); - else if (phase === "no-workspace") body = (0, import_react.createElement)( - "div", - { className: "ssw-empty" }, - (0, import_react.createElement)("p", null, "请先选择项目"), - (0, import_react.createElement)("p", { className: "ssw-hint" }, "在左侧工作区里选中一个项目后再打开三省六部。"), - (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: loadProject }, "重新检查") - ); - else if (phase === "error" && !view) body = (0, import_react.createElement)( - "div", - { className: "ssw-empty" }, - (0, import_react.createElement)("p", { className: "ssw-error" }, error || "加载失败"), - errorRetryable ? (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: loadProject }, "重试") : null - ); - else body = (0, import_react.createElement)( - import_react.Fragment, - null, - projectInfo, - tabBar, - tab === "tasks" ? taskView : tab === "artifacts" ? artifactView : courtView, - statusEl - ); - return (0, import_react.createElement)("div", { className: "ssw-root ssw-scope" }, head, body); } const NAV_PANEL_ID = "sansheng-workbench"; const NAV_ORDER = 32; @@ -1974,7 +2852,7 @@ function apply(ctx) { } function SanshengNavButton(props) { const size = props && typeof props.size === "number" ? props.size : 16; - const [floating, setFloating] = (0, import_react.useState)(false); + const [floating, setFloating] = (0, import_react2.useState)(false); const stop = (event) => { if (event && isFn(event.stopPropagation)) event.stopPropagation(); }; @@ -1989,18 +2867,18 @@ function apply(ctx) { }; let panel = null; if (floating) { - const card = (0, import_react.createElement)( + const card = (0, import_react2.createElement)( "div", { className: "ssw-float", role: "dialog", "aria-label": "三省六部工作台" }, - (0, import_react.createElement)(SanshengWorkbench, { onClose: () => setFloating(false) }) + (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_react.createElement)( - import_react.Fragment, + return (0, import_react2.createElement)( + import_react2.Fragment, null, - (0, import_react.createElement)("span", { + (0, import_react2.createElement)("span", { className: "ssw-nav-hit", role: "presentation", title: "三省六部", @@ -2008,7 +2886,7 @@ function apply(ctx) { onPointerDown: stop, onMouseDown: stop, "aria-expanded": floating ? "true" : "false" - }, (0, import_react.createElement)(TreeIcon, { width: size, height: size })), + }, (0, import_react2.createElement)(TreeIcon, { width: size, height: size })), panel ); } @@ -2023,8 +2901,8 @@ function apply(ctx) { } function SanshengNavFallback() { const hasBetterSidebar = !!get("betterSidebar"); - const [mode, setMode] = (0, import_react.useState)("pending"); - (0, import_react.useEffect)(() => { + const [mode, setMode] = (0, import_react2.useState)("pending"); + (0, import_react2.useEffect)(() => { let opened = false; try { opened = openRightWorkbench(); @@ -2058,7 +2936,7 @@ function apply(ctx) { }, 2600); return void 0; }, []); - (0, import_react.useEffect)(() => { + (0, import_react2.useEffect)(() => { if (mode !== "docked") return; backToChat(); const timer = setTimeout(backToChat, 700); @@ -2066,16 +2944,16 @@ function apply(ctx) { }, [mode]); if (mode === "pending") return null; if (mode === "docked") return null; - return (0, import_react.createElement)( + return (0, import_react2.createElement)( "div", { className: "ssw-tab-body" }, - (0, import_react.createElement)( + (0, import_react2.createElement)( "div", { className: "ssw-inline-bar" }, - (0, import_react.createElement)("span", null, "工作台 · 内嵌模式"), - (0, import_react.createElement)("button", { type: "button", className: "ssw-link", onClick: backToChat }, "返回对话") + (0, import_react2.createElement)("span", null, "工作台 · 内嵌模式"), + (0, import_react2.createElement)("button", { type: "button", className: "ssw-link", onClick: backToChat }, "返回对话") ), - (0, import_react.createElement)(SanshengWorkbench, {}) + (0, import_react2.createElement)(SanshengWorkbench, {}) ); } function registerNavEntry() { diff --git a/sansheng/src/client/index.js b/sansheng/src/client/index.js index c693fd6..09fe8dc 100644 --- a/sansheng/src/client/index.js +++ b/sansheng/src/client/index.js @@ -4,13 +4,7 @@ import { createElement as h, Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react' import { createPortal } from 'react-dom' import { SEAT_IDS, SEATS } from '../shared/roles.js' -import { - buildWorkbenchView, - findModelOption, - updateDraft, - clearDraft, - UNCHOSEN_MODEL_LABEL, -} from './workbench.js' +import { WorkbenchV2 } from './workbench-v2.js' import { request } from './transport.js' import { CSS as WORKBENCH_CSS } from './styles.js' import { install as installNativePanel } from '../native/index.js' @@ -325,641 +319,17 @@ export function apply(ctx) { let lastSelectedSeatId = SEAT_IDS[0] // ---------- 工作台组件 ---------- + // 工作台 v2:视觉与交互按用户提供的设计稿实现,数据全部走真实 host API。 function SanshengWorkbench(props) { - const onClose = props && props.onClose ? props.onClose : null - const [phase, setPhase] = useState('loading') - const [error, setError] = useState(null) - const [errorRetryable, setErrorRetryable] = useState(true) - const [notice, setNotice] = useState(null) - const [view, setView] = useState(null) - const [models, setModels] = useState(null) - const [selectedSeatId, setSelectedSeatId] = useState(lastSelectedSeatId) - const [draft, setDraft] = useState({}) - const [busy, setBusy] = useState(false) - const [configOpen, setConfigOpen] = useState(false) - const [reportOpen, setReportOpen] = useState(false) - const [memory, setMemory] = useState(null) - const [memoryOpen, setMemoryOpen] = useState(false) - const [memoryDraft, setMemoryDraft] = useState({ goal: '', constraints: '', acceptance: '', decisions: '' }) - const [tab, setTab] = useState('court') - const [tasks, setTasks] = useState([]) - const [artifacts, setArtifacts] = useState([]) - const [taskFormOpen, setTaskFormOpen] = useState(false) - const [taskDraft, setTaskDraft] = useState({ title: '', goal: '', ownerSeatId: SEAT_IDS[0] }) - const [summaryBusy, setSummaryBusy] = useState(false) - const [artifactFormOpen, setArtifactFormOpen] = useState(false) - const [artifactDraft, setArtifactDraft] = useState({ title: '', path: '', summary: '' }) - const alive = useRef(true) - - useEffect(() => () => { alive.current = false }, []) - - const loadProject = useCallback(async () => { - setPhase('loading'); setError(null); setErrorRetryable(true); setNotice(null) - const workspace = currentWorkspace() - if (!workspace) { setPhase('no-workspace'); return } - try { - const projectView = await request('open', { - workspaceId: workspace.workspaceId, - name: workspace.name, - path: workspace.path, - }) - let modelCatalog = null - try { modelCatalog = await request('models') } catch (modelError) { - console.warn('[sansheng] 模型目录加载失败:', modelError && modelError.message ? modelError.message : modelError) - } - let memoryData = null - try { memoryData = (await request('memory', { projectId: projectView.project.id })).memory } catch (memoryError) { - console.warn('[sansheng] 项目共识加载失败:', memoryError && memoryError.message ? memoryError.message : memoryError) - } - let taskList = [] - let artifactList = [] - try { taskList = (await request('tasks', { projectId: projectView.project.id })).tasks ?? [] } catch (taskError) { - console.warn('[sansheng] 任务加载失败:', taskError && taskError.message ? taskError.message : taskError) - } - try { artifactList = (await request('artifacts', { projectId: projectView.project.id })).artifacts ?? [] } catch (artifactError) { - console.warn('[sansheng] 成果加载失败:', artifactError && artifactError.message ? artifactError.message : artifactError) - } - if (!alive.current) return - setView(projectView) - setModels(modelCatalog) - 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') - } - }, []) - - useEffect(() => { void loadProject() }, [loadProject]) - const projectIdForSeat = view && view.project ? view.project.id : null - useEffect(() => { - if (!projectIdForSeat) return - const saved = selectedSeatCache.get(projectIdForSeat) - if (saved && SEAT_IDS.includes(saved)) { - lastSelectedSeatId = saved - setSelectedSeatId(saved) - } - }, [projectIdForSeat]) - - const wb = buildWorkbenchView(view, { selectedSeatId, models, draft }) - const seatById = useMemo(() => { - const map = {} - for (const seat of wb.seats) map[seat.id] = seat - return map - }, [wb.seats]) - - // 单击只负责“选中部门”,不切换宿主会话;切换会话会让工作台重挂载、选中项回到丞相。 - function pickSeat(id) { - if (!id) return - if (id !== selectedSeatId) { - setSelectedSeatId(id) - setConfigOpen(false) - } - lastSelectedSeatId = id - const pid = view && view.project ? view.project.id : null - if (pid) selectedSeatCache.set(pid, id) - const seat = seatById[id] - if (seat && seat.status === 'missing') setNotice('「' + seat.name + '」的会话已不存在,点下面的「重建会话」可重新建立') - else if (seat && seat.status !== 'bound' && seat.status !== 'creating') setNotice('「' + seat.name + '」还没开启,点下面的按钮开启这个部门') - } - - // 只有明确点“开始对话”时才进入该部门的宿主会话;先用后端核实原会话存在,绝不新建。 - async function openSelectedSeat() { - const projectId = view && view.project ? view.project.id : null - const seat = seatById[wb.selected.id] - 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: seat.id }) - if (!alive.current) return - if (!result || !result.sessionId) throw new Error('宿主没有返回会话') - navigateToSession(result.sessionId) - setNotice('已切换到' + seat.name + '会话') - } catch (openError) { - if (!alive.current) return - 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) - } - } - - // 只有后端确认旧会话不存在(missing)时,用户才能点这个按钮重建一次。 - async function rebuildSelectedSeat() { - const projectId = view && view.project ? view.project.id : null - const seat = seatById[wb.selected.id] - if (!projectId || !seat) return - const rec = seatRecordOf(view, seat.id) - const expectedSessionId = rec && rec.sessionId ? rec.sessionId : undefined - setBusy(true); setError(null); setNotice('正在重建「' + seat.name + '」的会话…') - try { - const next = await request('rebuildSeat', { projectId, seatId: seat.id, expectedSessionId }) - if (!alive.current) return - setView(next) - setNotice('已重建「' + seat.name + '」的会话;旧会话历史仍保留') - } catch (rebuildError) { - if (!alive.current) return - 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) - } - } - - function modelFromValue(value) { - const option = findModelOption(wb.selected.modelOptions, value) - if (!option) return null - return option.reasoningEffort - ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } - : { provider: option.provider, model: option.model } - } - - // 选模型就记住,不需要再点保存;下次打开或开启该部门时继续使用。 - async function rememberModel(value) { - const projectId = view && view.project ? view.project.id : null - if (!projectId || !value) return - const seatId = selectedSeatId - const model = modelFromValue(value) - if (!model) return - try { - const saved = await request('configure', { projectId, seatId, model }) - if (!alive.current) return - // 保存成功后同步本地项目视图:否则受控 select 仍读旧 view 的 model=null, - // 会显示回「请选择模型」,用户以为选择没生效。 - 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 } } - }) - setDraft(prev => clearDraft(prev, seatId)) - setNotice('已记住「' + wb.selected.name + '」的模型,下次打开继续使用') - } catch (error) { - if (alive.current) setNotice(error && error.message ? error.message : '模型记忆失败') - } - } - - function setModelValue(value) { - setDraft(prev => updateDraft(prev, selectedSeatId, { modelValue: value })) - void rememberModel(value) - } - function setInstructions(value) { - setDraft(prev => updateDraft(prev, selectedSeatId, { instructions: value })) - } - - async function enableSelectedSeat() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - const seatId = wb.selected.id - setBusy(true); setError(null); setNotice('正在开启「' + wb.selected.name + '」…') - try { - const next = await request('enableSeat', { projectId, seatId }) - if (!alive.current) return - setView(next) - setNotice('已开启「' + wb.selected.name + '」的独立会话') - // 开新部门时自动把三省六部工作台面板打开/置前,避免用户以为没反应。 - try { tryOpenRightTab() } catch { /* 打开失败不影响开启结果 */ } - } catch (enableError) { - if (alive.current) setError(enableError && enableError.message ? enableError.message : '开启失败') - } finally { - if (alive.current) setBusy(false) - } - } - - async function enableSeats() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - setBusy(true); setError(null); setNotice('正在启用十席…') - try { - const next = await request('enable', { projectId }) - if (!alive.current) return - setView(next) - setNotice('十席已启用(建立独立会话,不自动运行模型)') - } catch (enableError) { - if (alive.current) setError(enableError && enableError.message ? enableError.message : '启用失败') - } finally { - if (alive.current) setBusy(false) - } - } - - async function saveConfig() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - const seatId = wb.selected.id - const value = wb.selected.modelValue - if (!value) { setNotice('请先为当前角色选择模型'); return } - const option = findModelOption(wb.selected.modelOptions, value) - const model = option - ? (option.reasoningEffort - ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } - : { provider: option.provider, model: option.model }) - : null - setBusy(true); setError(null); setNotice('保存中…') - try { - await request('configure', { projectId, seatId, model, instructions: wb.selected.instructions }) - const next = await request('project', { projectId }) - if (!alive.current) return - setView(next) - setDraft(prev => clearDraft(prev, seatId)) - setNotice('已保存') - } catch (saveError) { - if (alive.current) setError(saveError && saveError.message ? saveError.message : '保存失败') - } finally { - if (alive.current) setBusy(false) - } - } - - async function saveMemory() { - const projectId = view && view.project ? view.project.id : null - 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(line => line.trim()).filter(Boolean), - acceptance: memoryDraft.acceptance.split('\n').map(line => line.trim()).filter(Boolean), - decisions: memoryDraft.decisions.split('\n').map(line => line.trim()).filter(Boolean).map(text => ({ - type: 'user', status: 'active', text, - sourceRefs: wb.selected.sessionId ? [{ sessionId: wb.selected.sessionId, excerpt: '工作台记录', recordedAt: Date.now() }] : [], - })), - sources: wb.selected.sessionId ? [{ id: 'ui-' + Date.now(), sessionId: wb.selected.sessionId, excerpt: '工作台记录', recordedAt: Date.now() }] : [], - }) - 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(projectId) { - try { - const result = await request('tasks', { projectId }) - if (alive.current) setTasks(result.tasks ?? []) - } catch (error) { - if (alive.current) setNotice(error && error.message ? error.message : '任务列表刷新失败') - } - } - - async function createTask() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - const title = taskDraft.title.trim() - if (!title) { setNotice('任务标题不能为空'); return } - setBusy(true); setError(null) - try { - await request('taskCreate', { projectId, title, goal: taskDraft.goal, ownerSeatId: taskDraft.ownerSeatId }) - setTaskDraft({ title: '', goal: '', ownerSeatId: taskDraft.ownerSeatId }) - setTaskFormOpen(false) - await reloadTasks(projectId) - setNotice('已存为草稿;点「派工」才会交给部门。') - } catch (error) { - if (alive.current) setError(error && error.message ? error.message : '新建任务失败') - } finally { if (alive.current) setBusy(false) } - } - - async function dispatchTask(taskId) { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - setBusy(true); setError(null) - try { - const result = await request('taskDispatch', { projectId, taskId }) - await reloadTasks(projectId) - setNotice(result.delivered ? '已派工到该部门会话。' : '已记录为待执行(当前宿主暂不支持直接发送)。') - } catch (error) { - if (alive.current) setError(error && error.message ? error.message : '派工失败') - } finally { if (alive.current) setBusy(false) } - } - - async function summarizeByShangshu() { - const projectId = view && view.project ? view.project.id : null - 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 cancelTask(taskId) { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - setBusy(true); setError(null) - try { - await request('taskCancel', { projectId, taskId }) - await reloadTasks(projectId) - setNotice('任务已取消。') - } catch (error) { - if (alive.current) setError(error && error.message ? error.message : '取消失败') - } finally { if (alive.current) setBusy(false) } - } - - async function addArtifact() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - const title = artifactDraft.title.trim() - if (!title) { setNotice('成果名称不能为空'); return } - setBusy(true); setError(null) - try { - const result = await request('artifactAdd', { projectId, title, path: artifactDraft.path, summary: artifactDraft.summary }) - setArtifactDraft({ title: '', path: '', summary: '' }) - setArtifactFormOpen(false) - setArtifacts(list => [...list, result.artifact]) - setNotice('成果已登记。') - } catch (error) { - if (alive.current) setError(error && error.message ? error.message : '登记成果失败') - } finally { if (alive.current) setBusy(false) } - } - - const seatCard = (seat) => h('button', { - key: seat.id, type: 'button', className: 'ssw-seat', - 'aria-pressed': seat.selected ? 'true' : 'false', - title: seat.name + ' · ' + seat.duty + '(' + seat.statusLabel + ')', - onClick: () => pickSeat(seat.id), - }, - h('span', { className: 'ssw-role-top' }, - h('span', { className: 'ssw-role-name' }, seat.name), - h('span', { className: 'ssw-dot', 'data-status': seat.status, 'aria-hidden': 'true' }), - ), - h('span', { className: 'ssw-role-duty' }, seat.duty), - ) - - const pickList = (ids) => ids.map(id => seatById[id]).filter(Boolean) - const tree = h('section', { className: 'ssw-tree', 'aria-label': '切换角色' }, - h('div', { className: 'ssw-lead' }, pickList(wb.groups.lead).map(seatCard)), - h('div', { className: 'ssw-sansheng' }, - h('span', { className: 'ssw-group-label' }, '三省'), - h('div', { className: 'ssw-trio' }, pickList(wb.groups.sansheng).map(seatCard)), - ), - h('div', { className: 'ssw-ministries' }, - h('span', { className: 'ssw-group-label' }, '六部 · 尚书统筹'), - h('div', { className: 'ssw-six' }, pickList(wb.groups.liubu).map(seatCard)), - ), - ) - - const head = h('header', { className: 'ssw-head' }, - h(TreeIcon), - h('strong', { className: 'ssw-head-title' }, '工作台'), - onClose - ? h('button', { type: 'button', className: 'ssw-icon-btn', onClick: onClose, 'aria-label': '收起工作台' }, h(CloseIcon)) - : null, - ) - - const projectInfo = h('div', { className: 'ssw-project' }, - h('div', { className: 'ssw-project-line', style: { justifyContent: 'flex-end' } }, - h('span', { className: 'ssw-count' }, wb.project.seatCount + ' 个角色 · ' + wb.project.sessionCount + ' 个会话'), - ), - h('div', { className: 'ssw-project-title' }, wb.projectTitle || '未命名项目'), - ) - - const selectedStatus = wb.selected.status - const detailActions = h('div', { className: 'ssw-current-actions' }, - selectedStatus === 'bound' - ? h('button', { - type: 'button', className: 'ssw-primary', disabled: busy, - onClick: openSelectedSeat, - }, '开始对话') - : selectedStatus === 'missing' - ? h('button', { - type: 'button', className: 'ssw-primary', disabled: busy, - onClick: rebuildSelectedSeat, - }, '重建会话') - : h('button', { - type: 'button', className: 'ssw-primary', disabled: busy || selectedStatus === 'creating', - onClick: enableSelectedSeat, - }, selectedStatus === 'creating' ? '正在开启…' : '开启「' + wb.selected.name + '」'), - ) - - const optionEls = wb.selected.modelOptions.map(option => h('option', { key: option.value, value: option.value }, option.label)) - if (wb.selected.modelValue && !wb.selected.modelOptions.some(option => option.value === wb.selected.modelValue)) { - optionEls.push(h('option', { key: '__current__', value: wb.selected.modelValue }, wb.selected.modelLabel)) - } - const config = h('section', { className: 'ssw-config' }, - h('button', { - type: 'button', className: 'ssw-config-toggle', 'aria-expanded': configOpen ? 'true' : 'false', - onClick: () => setConfigOpen(value => !value), - }, - h(GearIcon), - h('span', null, '配置' + wb.selected.name + (wb.selected.dirty ? ' · 未保存' : '')), - h(ChevronIcon), - ), - configOpen - ? h('div', { className: 'ssw-config-body' }, - h('label', { className: 'ssw-label' }, '默认模型(开启该部门时应用)'), - h('select', { - className: 'ssw-field', value: wb.selected.modelValue, disabled: busy, - onChange: event => setModelValue(event.target.value), - }, - h('option', { value: '', disabled: true }, UNCHOSEN_MODEL_LABEL), - ...optionEls, - ), - h('label', { className: 'ssw-label' }, '角色补充说明'), - h('textarea', { - className: 'ssw-field ssw-textarea', rows: 4, value: wb.selected.instructions, disabled: busy, - placeholder: '补充该角色在当前项目中的工作要求', - onChange: event => setInstructions(event.target.value), - }), - h('p', { className: 'ssw-scope-note' }, '这里预配置的模型会在开启该部门或按需派工时应用;丞相派工不选择模型。只影响当前项目当前角色。'), - h('div', { className: 'ssw-save-row' }, - h('button', { type: 'button', className: 'ssw-primary', disabled: busy, onClick: saveConfig }, busy ? '保存中…' : '保存配置'), - wb.selected.dirty ? h('span', { className: 'ssw-save-status' }, '有未保存修改') : null, - ), - ) - : null, - ) - - const memorySection = h('section', { className: 'ssw-config' }, - h('button', { - type: 'button', className: 'ssw-config-toggle', 'aria-expanded': memoryOpen ? 'true' : 'false', - onClick: () => setMemoryOpen(value => !value), - }, - h(GearIcon), - h('span', null, '项目共识 v' + (memory?.revision ?? 0) + (memory?.updatedAt ? ' · 最近更新' : ' · 尚未建立')), - h(ChevronIcon), - ), - memoryOpen - ? h('div', { className: 'ssw-config-body' }, - h('label', { className: 'ssw-label' }, '项目目标'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: memoryDraft.goal, placeholder: '这个项目最终要达成什么', onChange: event => setMemoryDraft({ ...memoryDraft, goal: event.target.value }) }), - h('label', { className: 'ssw-label' }, '硬约束(每行一条,部门必须遵守)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: memoryDraft.constraints, placeholder: '例如:不能改动线上数据', onChange: event => setMemoryDraft({ ...memoryDraft, constraints: event.target.value }) }), - h('label', { className: 'ssw-label' }, '验收标准(每行一条)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: memoryDraft.acceptance, placeholder: '例如:交付前必须跑完回归测试', onChange: event => setMemoryDraft({ ...memoryDraft, acceptance: event.target.value }) }), - h('label', { className: 'ssw-label' }, '新增决定(每行一条,按用户明确要求记录)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 2, value: memoryDraft.decisions, placeholder: '例如:先保证稳定性,再考虑样式', onChange: event => setMemoryDraft({ ...memoryDraft, decisions: event.target.value }) }), - h('p', { className: 'ssw-scope-note' }, '保存后版本号会增加;每个部门在下一次模型请求前都会收到这份共识。当前为本地临时存储,后续迁移到 Mnemon Documents。'), - h('div', { className: 'ssw-save-row' }, h('button', { type: 'button', className: 'ssw-primary', disabled: busy, onClick: saveMemory }, busy ? '保存中…' : '保存共识')), - ) - : null, - ) - - const report = h('section', { className: 'ssw-report' }, - h('button', { - type: 'button', className: 'ssw-report-toggle', 'aria-expanded': reportOpen ? 'true' : 'false', - onClick: () => setReportOpen(value => !value), - }, reportOpen ? '收起角色职责' : '全部角色职责'), - reportOpen - ? h('div', { className: 'ssw-report-list' }, - SEAT_IDS.map(id => { - const rec = seatRecordOf(view, id) - const m = rec && rec.model - const modelLabel = m && m.model ? (m.model + (m.reasoningEffort ? ' · ' + m.reasoningEffort : '')) : '未选择模型' - return h('div', { key: id, className: 'ssw-report-item', 'data-seat': id }, - h('div', { className: 'ssw-report-head' }, - h('strong', null, SEATS[id].label), - h('span', null, SEATS[id].duty), - ), - h('p', { className: 'ssw-report-model' }, '模型:' + modelLabel), - h('p', { className: 'ssw-report-text' }, SEATS[id].responsibility), - ) - }), - ) - : null, - ) - - const statusEl = error - ? h('p', { className: 'ssw-error', role: 'alert' }, error) - : (notice ? h('p', { className: 'ssw-notice', role: 'status' }, notice) : null) - - const tabCounts = { court: wb.project.seatCount, tasks: tasks.length, artifacts: artifacts.length } - const tabBar = h('div', { className: 'ssw-tabs', role: 'tablist' }, - [['court', '朝堂'], ['tasks', '任务'], ['artifacts', '成果']].map(([id, label]) => h('button', { - key: id, type: 'button', role: 'tab', 'aria-selected': tab === id ? 'true' : 'false', - className: 'ssw-tab' + (tab === id ? ' is-active' : ''), onClick: () => setTab(id), - }, h('span', null, label), h('span', { className: 'ssw-tab-count' }, String(tabCounts[id] ?? 0))))) - - const TASK_STATUS_LABEL = { draft: '草稿', prepared: '待执行', dispatched: '已派工', running: '执行中', done: '已完成', cancelled: '已取消', failed: '失败' } - const taskRows = tasks.length === 0 - ? h('p', { className: 'ssw-empty-line' }, '这个项目还没有任务。点「新建任务」先存一张草稿。') - : tasks.map(task => { - const stale = (memory?.revision ?? 0) > (task.contextRevision ?? 0) && (task.status === 'dispatched' || task.status === 'prepared' || task.status === 'running') - return h('article', { key: task.id, className: 'ssw-row', 'data-task': task.id }, - h('div', { className: 'ssw-row-top' }, - h('strong', { className: 'ssw-row-title' }, task.title), - h('span', { className: 'ssw-badge', 'data-status': task.status }, TASK_STATUS_LABEL[task.status] ?? task.status), - stale ? h('span', { className: 'ssw-badge', 'data-status': 'stale' }, '要求有更新') : null), - h('p', { className: 'ssw-row-meta' }, (SEATS[task.ownerSeatId]?.label ?? task.ownerSeatId) + (task.goal ? ' · ' + task.goal : '') + (task.contextRevision !== undefined ? ' · 共识 v' + task.contextRevision : '')), - task.note ? h('p', { className: 'ssw-row-note' }, task.note) : null, - task.result ? h('p', { className: 'ssw-row-result' }, '结果:' + task.result) : null, - h('div', { className: 'ssw-row-actions' }, - (task.status === 'draft' || task.status === 'prepared' || task.status === 'failed') - ? h('button', { type: 'button', className: 'ssw-link', disabled: busy, onClick: () => dispatchTask(task.id) }, task.status === 'prepared' ? '重试派工' : '派工') - : null, - (task.status !== 'done' && task.status !== 'cancelled') - ? h('button', { type: 'button', className: 'ssw-link ssw-link-muted', disabled: busy, onClick: () => cancelTask(task.id) }, '取消') - : null)) - }) - - const taskView = h('section', { className: 'ssw-page' }, - h('div', { className: 'ssw-page-head' }, - h('strong', null, '任务 · ' + tasks.length), - h('div', { style: { display: 'flex', alignItems: 'center', gap: '10px' } }, - h('button', { type: 'button', className: 'ssw-link', disabled: busy || summaryBusy || tasks.length === 0, onClick: () => { void summarizeByShangshu() } }, summaryBusy ? '汇总中…' : '尚书汇总'), - h('button', { type: 'button', className: 'ssw-primary', onClick: () => setTaskFormOpen(value => !value) }, taskFormOpen ? '收起' : '新建任务'))), - taskFormOpen ? h('form', { className: 'ssw-form', onSubmit: event => { event.preventDefault(); void createTask() } }, - h('label', { className: 'ssw-label' }, '标题'), - h('input', { className: 'ssw-field', value: taskDraft.title, placeholder: '交给部门做什么', onChange: event => setTaskDraft({ ...taskDraft, title: event.target.value }) }), - h('label', { className: 'ssw-label' }, '目标(可选)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: taskDraft.goal, onChange: event => setTaskDraft({ ...taskDraft, goal: event.target.value }) }), - h('label', { className: 'ssw-label' }, '主责部门'), - h('select', { className: 'ssw-field', value: taskDraft.ownerSeatId, onChange: event => setTaskDraft({ ...taskDraft, ownerSeatId: event.target.value }) }, - SEAT_IDS.map(id => h('option', { key: id, value: id }, SEATS[id].label))), - h('div', { className: 'ssw-save-row' }, h('button', { type: 'submit', className: 'ssw-primary', disabled: busy }, busy ? '保存中…' : '保存草稿')), - ) : null, - h('div', { className: 'ssw-list' }, taskRows)) - - const artifactRows = artifacts.length === 0 - ? h('p', { className: 'ssw-empty-line' }, '这个项目还没有登记成果。') - : artifacts.map(item => h('article', { key: item.id, className: 'ssw-row', 'data-artifact': item.id }, - h('div', { className: 'ssw-row-top' }, h('strong', { className: 'ssw-row-title' }, item.title)), - item.summary ? h('p', { className: 'ssw-row-meta' }, item.summary) : null, - item.path ? h('p', { className: 'ssw-row-note' }, item.path) : null)) - - const artifactView = h('section', { className: 'ssw-page' }, - h('div', { className: 'ssw-page-head' }, - h('strong', null, '成果 · ' + artifacts.length), - h('button', { type: 'button', className: 'ssw-primary', onClick: () => setArtifactFormOpen(value => !value) }, artifactFormOpen ? '收起' : '登记成果')), - artifactFormOpen ? h('form', { className: 'ssw-form', onSubmit: event => { event.preventDefault(); void addArtifact() } }, - h('label', { className: 'ssw-label' }, '成果名称'), - h('input', { className: 'ssw-field', value: artifactDraft.title, onChange: event => setArtifactDraft({ ...artifactDraft, title: event.target.value }) }), - h('label', { className: 'ssw-label' }, '文件路径(可选)'), - h('input', { className: 'ssw-field', value: artifactDraft.path, onChange: event => setArtifactDraft({ ...artifactDraft, path: event.target.value }) }), - h('label', { className: 'ssw-label' }, '说明(可选)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: artifactDraft.summary, onChange: event => setArtifactDraft({ ...artifactDraft, summary: event.target.value }) }), - h('div', { className: 'ssw-save-row' }, h('button', { type: 'submit', className: 'ssw-primary', disabled: busy }, busy ? '保存中…' : '保存')), - ) : null, - h('div', { className: 'ssw-list' }, artifactRows)) - - const detail = h('section', { className: 'ssw-current' }, - h('div', { className: 'ssw-current-top' }, - h('strong', { className: 'ssw-current-name' }, wb.selected.name), - h('span', { className: 'ssw-current-label' }, '角色职责 · ' + wb.selected.statusLabel), - ), - h('p', { className: 'ssw-current-text' }, wb.selected.responsibility), - detailActions, - ) - const courtView = h(Fragment, null, tree, detail, config, memorySection) - - let body - if (phase === 'loading') body = h('div', { className: 'ssw-loading' }, '正在加载工作台…') - else if (phase === 'no-workspace') body = h('div', { className: 'ssw-empty' }, - h('p', null, '请先选择项目'), - h('p', { className: 'ssw-hint' }, '在左侧工作区里选中一个项目后再打开三省六部。'), - h('button', { type: 'button', className: 'ssw-primary', onClick: loadProject }, '重新检查'), - ) - else if (phase === 'error' && !view) body = h('div', { className: 'ssw-empty' }, - h('p', { className: 'ssw-error' }, error || '加载失败'), - errorRetryable - ? h('button', { type: 'button', className: 'ssw-primary', onClick: loadProject }, '重试') - : null, - ) - else body = h(Fragment, null, projectInfo, tabBar, - tab === 'tasks' ? taskView : tab === 'artifacts' ? artifactView : courtView, statusEl) - - return h('div', { className: 'ssw-root ssw-scope' }, head, body) + return h(WorkbenchV2, { + onClose: props && props.onClose, + resolveWorkspace: currentWorkspace, + navigateToSession, + openRightTab: tryOpenRightTab, + selectionCache: selectedSeatCache, + getLastSeatId: () => lastSelectedSeatId, + setLastSeatId: id => { lastSelectedSeatId = id }, + }) } // ---------- 左侧导航入口 ---------- diff --git a/sansheng/src/client/styles.js b/sansheng/src/client/styles.js index 87c277a..5d2543f 100644 --- a/sansheng/src/client/styles.js +++ b/sansheng/src/client/styles.js @@ -1,136 +1,655 @@ -// 三省六部工作台样式:白蓝主题,自带深色适配。 -// 所有选择器以 .ssw- 前缀隔离,避免污染宿主样式;变量参考 preview/index.html。 -// 不依赖任何构建工具,作为普通字符串导出,由入口注入